2 * alc5623.c -- alc562[123] ALSA Soc Audio driver
4 * Copyright 2008 Realtek Microelectronics
5 * Author: flove <flove@realtek.com> Ethan <eku@marvell.com>
7 * Copyright 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/delay.h>
23 #include <linux/i2c.h>
24 #include <linux/slab.h>
25 #include <sound/core.h>
26 #include <sound/pcm.h>
27 #include <sound/pcm_params.h>
28 #include <sound/tlv.h>
29 #include <sound/soc.h>
30 #include <sound/initval.h>
31 #include <sound/alc5623.h>
35 static int caps_charge
= 2000;
36 module_param(caps_charge
, int, 0);
37 MODULE_PARM_DESC(caps_charge
, "ALC5623 cap charge time (msecs)");
39 /* codec private data */
41 enum snd_soc_control_type control_type
;
44 u16 reg_cache
[ALC5623_VENDOR_ID2
+2];
45 unsigned int add_ctrl
;
46 unsigned int jack_det_ctrl
;
49 static void alc5623_fill_cache(struct snd_soc_codec
*codec
)
51 int i
, step
= codec
->driver
->reg_cache_step
;
52 u16
*cache
= codec
->reg_cache
;
54 /* not really efficient ... */
55 codec
->cache_bypass
= 1;
56 for (i
= 0 ; i
< codec
->driver
->reg_cache_size
; i
+= step
)
57 cache
[i
] = snd_soc_read(codec
, i
);
58 codec
->cache_bypass
= 0;
61 static inline int alc5623_reset(struct snd_soc_codec
*codec
)
63 return snd_soc_write(codec
, ALC5623_RESET
, 0);
66 static int amp_mixer_event(struct snd_soc_dapm_widget
*w
,
67 struct snd_kcontrol
*kcontrol
, int event
)
69 /* to power-on/off class-d amp generators/speaker */
70 /* need to write to 'index-46h' register : */
71 /* so write index num (here 0x46) to reg 0x6a */
72 /* and then 0xffff/0 to reg 0x6c */
73 snd_soc_write(w
->codec
, ALC5623_HID_CTRL_INDEX
, 0x46);
76 case SND_SOC_DAPM_PRE_PMU
:
77 snd_soc_write(w
->codec
, ALC5623_HID_CTRL_DATA
, 0xFFFF);
79 case SND_SOC_DAPM_POST_PMD
:
80 snd_soc_write(w
->codec
, ALC5623_HID_CTRL_DATA
, 0);
91 static const DECLARE_TLV_DB_SCALE(vol_tlv
, -3450, 150, 0);
92 static const DECLARE_TLV_DB_SCALE(hp_tlv
, -4650, 150, 0);
93 static const DECLARE_TLV_DB_SCALE(adc_rec_tlv
, -1650, 150, 0);
94 static const unsigned int boost_tlv
[] = {
96 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
97 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
98 2, 2, TLV_DB_SCALE_ITEM(3000, 0, 0),
100 static const DECLARE_TLV_DB_SCALE(dig_tlv
, 0, 600, 0);
102 static const struct snd_kcontrol_new alc5621_vol_snd_controls
[] = {
103 SOC_DOUBLE_TLV("Speaker Playback Volume",
104 ALC5623_SPK_OUT_VOL
, 8, 0, 31, 1, hp_tlv
),
105 SOC_DOUBLE("Speaker Playback Switch",
106 ALC5623_SPK_OUT_VOL
, 15, 7, 1, 1),
107 SOC_DOUBLE_TLV("Headphone Playback Volume",
108 ALC5623_HP_OUT_VOL
, 8, 0, 31, 1, hp_tlv
),
109 SOC_DOUBLE("Headphone Playback Switch",
110 ALC5623_HP_OUT_VOL
, 15, 7, 1, 1),
113 static const struct snd_kcontrol_new alc5622_vol_snd_controls
[] = {
114 SOC_DOUBLE_TLV("Speaker Playback Volume",
115 ALC5623_SPK_OUT_VOL
, 8, 0, 31, 1, hp_tlv
),
116 SOC_DOUBLE("Speaker Playback Switch",
117 ALC5623_SPK_OUT_VOL
, 15, 7, 1, 1),
118 SOC_DOUBLE_TLV("Line Playback Volume",
119 ALC5623_HP_OUT_VOL
, 8, 0, 31, 1, hp_tlv
),
120 SOC_DOUBLE("Line Playback Switch",
121 ALC5623_HP_OUT_VOL
, 15, 7, 1, 1),
124 static const struct snd_kcontrol_new alc5623_vol_snd_controls
[] = {
125 SOC_DOUBLE_TLV("Line Playback Volume",
126 ALC5623_SPK_OUT_VOL
, 8, 0, 31, 1, hp_tlv
),
127 SOC_DOUBLE("Line Playback Switch",
128 ALC5623_SPK_OUT_VOL
, 15, 7, 1, 1),
129 SOC_DOUBLE_TLV("Headphone Playback Volume",
130 ALC5623_HP_OUT_VOL
, 8, 0, 31, 1, hp_tlv
),
131 SOC_DOUBLE("Headphone Playback Switch",
132 ALC5623_HP_OUT_VOL
, 15, 7, 1, 1),
135 static const struct snd_kcontrol_new alc5623_snd_controls
[] = {
136 SOC_DOUBLE_TLV("Auxout Playback Volume",
137 ALC5623_MONO_AUX_OUT_VOL
, 8, 0, 31, 1, hp_tlv
),
138 SOC_DOUBLE("Auxout Playback Switch",
139 ALC5623_MONO_AUX_OUT_VOL
, 15, 7, 1, 1),
140 SOC_DOUBLE_TLV("PCM Playback Volume",
141 ALC5623_STEREO_DAC_VOL
, 8, 0, 31, 1, vol_tlv
),
142 SOC_DOUBLE_TLV("AuxI Capture Volume",
143 ALC5623_AUXIN_VOL
, 8, 0, 31, 1, vol_tlv
),
144 SOC_DOUBLE_TLV("LineIn Capture Volume",
145 ALC5623_LINE_IN_VOL
, 8, 0, 31, 1, vol_tlv
),
146 SOC_SINGLE_TLV("Mic1 Capture Volume",
147 ALC5623_MIC_VOL
, 8, 31, 1, vol_tlv
),
148 SOC_SINGLE_TLV("Mic2 Capture Volume",
149 ALC5623_MIC_VOL
, 0, 31, 1, vol_tlv
),
150 SOC_DOUBLE_TLV("Rec Capture Volume",
151 ALC5623_ADC_REC_GAIN
, 7, 0, 31, 0, adc_rec_tlv
),
152 SOC_SINGLE_TLV("Mic 1 Boost Volume",
153 ALC5623_MIC_CTRL
, 10, 2, 0, boost_tlv
),
154 SOC_SINGLE_TLV("Mic 2 Boost Volume",
155 ALC5623_MIC_CTRL
, 8, 2, 0, boost_tlv
),
156 SOC_SINGLE_TLV("Digital Boost Volume",
157 ALC5623_ADD_CTRL_REG
, 4, 3, 0, dig_tlv
),
163 static const struct snd_kcontrol_new alc5623_hp_mixer_controls
[] = {
164 SOC_DAPM_SINGLE("LI2HP Playback Switch", ALC5623_LINE_IN_VOL
, 15, 1, 1),
165 SOC_DAPM_SINGLE("AUXI2HP Playback Switch", ALC5623_AUXIN_VOL
, 15, 1, 1),
166 SOC_DAPM_SINGLE("MIC12HP Playback Switch", ALC5623_MIC_ROUTING_CTRL
, 15, 1, 1),
167 SOC_DAPM_SINGLE("MIC22HP Playback Switch", ALC5623_MIC_ROUTING_CTRL
, 7, 1, 1),
168 SOC_DAPM_SINGLE("DAC2HP Playback Switch", ALC5623_STEREO_DAC_VOL
, 15, 1, 1),
171 static const struct snd_kcontrol_new alc5623_hpl_mixer_controls
[] = {
172 SOC_DAPM_SINGLE("ADC2HP_L Playback Switch", ALC5623_ADC_REC_GAIN
, 15, 1, 1),
175 static const struct snd_kcontrol_new alc5623_hpr_mixer_controls
[] = {
176 SOC_DAPM_SINGLE("ADC2HP_R Playback Switch", ALC5623_ADC_REC_GAIN
, 14, 1, 1),
179 static const struct snd_kcontrol_new alc5623_mono_mixer_controls
[] = {
180 SOC_DAPM_SINGLE("ADC2MONO_L Playback Switch", ALC5623_ADC_REC_GAIN
, 13, 1, 1),
181 SOC_DAPM_SINGLE("ADC2MONO_R Playback Switch", ALC5623_ADC_REC_GAIN
, 12, 1, 1),
182 SOC_DAPM_SINGLE("LI2MONO Playback Switch", ALC5623_LINE_IN_VOL
, 13, 1, 1),
183 SOC_DAPM_SINGLE("AUXI2MONO Playback Switch", ALC5623_AUXIN_VOL
, 13, 1, 1),
184 SOC_DAPM_SINGLE("MIC12MONO Playback Switch", ALC5623_MIC_ROUTING_CTRL
, 13, 1, 1),
185 SOC_DAPM_SINGLE("MIC22MONO Playback Switch", ALC5623_MIC_ROUTING_CTRL
, 5, 1, 1),
186 SOC_DAPM_SINGLE("DAC2MONO Playback Switch", ALC5623_STEREO_DAC_VOL
, 13, 1, 1),
189 static const struct snd_kcontrol_new alc5623_speaker_mixer_controls
[] = {
190 SOC_DAPM_SINGLE("LI2SPK Playback Switch", ALC5623_LINE_IN_VOL
, 14, 1, 1),
191 SOC_DAPM_SINGLE("AUXI2SPK Playback Switch", ALC5623_AUXIN_VOL
, 14, 1, 1),
192 SOC_DAPM_SINGLE("MIC12SPK Playback Switch", ALC5623_MIC_ROUTING_CTRL
, 14, 1, 1),
193 SOC_DAPM_SINGLE("MIC22SPK Playback Switch", ALC5623_MIC_ROUTING_CTRL
, 6, 1, 1),
194 SOC_DAPM_SINGLE("DAC2SPK Playback Switch", ALC5623_STEREO_DAC_VOL
, 14, 1, 1),
197 /* Left Record Mixer */
198 static const struct snd_kcontrol_new alc5623_captureL_mixer_controls
[] = {
199 SOC_DAPM_SINGLE("Mic1 Capture Switch", ALC5623_ADC_REC_MIXER
, 14, 1, 1),
200 SOC_DAPM_SINGLE("Mic2 Capture Switch", ALC5623_ADC_REC_MIXER
, 13, 1, 1),
201 SOC_DAPM_SINGLE("LineInL Capture Switch", ALC5623_ADC_REC_MIXER
, 12, 1, 1),
202 SOC_DAPM_SINGLE("Left AuxI Capture Switch", ALC5623_ADC_REC_MIXER
, 11, 1, 1),
203 SOC_DAPM_SINGLE("HPMixerL Capture Switch", ALC5623_ADC_REC_MIXER
, 10, 1, 1),
204 SOC_DAPM_SINGLE("SPKMixer Capture Switch", ALC5623_ADC_REC_MIXER
, 9, 1, 1),
205 SOC_DAPM_SINGLE("MonoMixer Capture Switch", ALC5623_ADC_REC_MIXER
, 8, 1, 1),
208 /* Right Record Mixer */
209 static const struct snd_kcontrol_new alc5623_captureR_mixer_controls
[] = {
210 SOC_DAPM_SINGLE("Mic1 Capture Switch", ALC5623_ADC_REC_MIXER
, 6, 1, 1),
211 SOC_DAPM_SINGLE("Mic2 Capture Switch", ALC5623_ADC_REC_MIXER
, 5, 1, 1),
212 SOC_DAPM_SINGLE("LineInR Capture Switch", ALC5623_ADC_REC_MIXER
, 4, 1, 1),
213 SOC_DAPM_SINGLE("Right AuxI Capture Switch", ALC5623_ADC_REC_MIXER
, 3, 1, 1),
214 SOC_DAPM_SINGLE("HPMixerR Capture Switch", ALC5623_ADC_REC_MIXER
, 2, 1, 1),
215 SOC_DAPM_SINGLE("SPKMixer Capture Switch", ALC5623_ADC_REC_MIXER
, 1, 1, 1),
216 SOC_DAPM_SINGLE("MonoMixer Capture Switch", ALC5623_ADC_REC_MIXER
, 0, 1, 1),
219 static const char *alc5623_spk_n_sour_sel
[] = {
220 "RN/-R", "RP/+R", "LN/-R", "Vmid" };
221 static const char *alc5623_hpl_out_input_sel
[] = {
222 "Vmid", "HP Left Mix"};
223 static const char *alc5623_hpr_out_input_sel
[] = {
224 "Vmid", "HP Right Mix"};
225 static const char *alc5623_spkout_input_sel
[] = {
226 "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
227 static const char *alc5623_aux_out_input_sel
[] = {
228 "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
230 /* auxout output mux */
231 static const struct soc_enum alc5623_aux_out_input_enum
=
232 SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL
, 6, 4, alc5623_aux_out_input_sel
);
233 static const struct snd_kcontrol_new alc5623_auxout_mux_controls
=
234 SOC_DAPM_ENUM("Route", alc5623_aux_out_input_enum
);
236 /* speaker output mux */
237 static const struct soc_enum alc5623_spkout_input_enum
=
238 SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL
, 10, 4, alc5623_spkout_input_sel
);
239 static const struct snd_kcontrol_new alc5623_spkout_mux_controls
=
240 SOC_DAPM_ENUM("Route", alc5623_spkout_input_enum
);
242 /* headphone left output mux */
243 static const struct soc_enum alc5623_hpl_out_input_enum
=
244 SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL
, 9, 2, alc5623_hpl_out_input_sel
);
245 static const struct snd_kcontrol_new alc5623_hpl_out_mux_controls
=
246 SOC_DAPM_ENUM("Route", alc5623_hpl_out_input_enum
);
248 /* headphone right output mux */
249 static const struct soc_enum alc5623_hpr_out_input_enum
=
250 SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL
, 8, 2, alc5623_hpr_out_input_sel
);
251 static const struct snd_kcontrol_new alc5623_hpr_out_mux_controls
=
252 SOC_DAPM_ENUM("Route", alc5623_hpr_out_input_enum
);
254 /* speaker output N select */
255 static const struct soc_enum alc5623_spk_n_sour_enum
=
256 SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL
, 14, 4, alc5623_spk_n_sour_sel
);
257 static const struct snd_kcontrol_new alc5623_spkoutn_mux_controls
=
258 SOC_DAPM_ENUM("Route", alc5623_spk_n_sour_enum
);
260 static const struct snd_soc_dapm_widget alc5623_dapm_widgets
[] = {
262 SND_SOC_DAPM_MUX("AuxOut Mux", SND_SOC_NOPM
, 0, 0,
263 &alc5623_auxout_mux_controls
),
264 SND_SOC_DAPM_MUX("SpeakerOut Mux", SND_SOC_NOPM
, 0, 0,
265 &alc5623_spkout_mux_controls
),
266 SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM
, 0, 0,
267 &alc5623_hpl_out_mux_controls
),
268 SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM
, 0, 0,
269 &alc5623_hpr_out_mux_controls
),
270 SND_SOC_DAPM_MUX("SpeakerOut N Mux", SND_SOC_NOPM
, 0, 0,
271 &alc5623_spkoutn_mux_controls
),
274 SND_SOC_DAPM_MIXER("HP Mix", SND_SOC_NOPM
, 0, 0,
275 &alc5623_hp_mixer_controls
[0],
276 ARRAY_SIZE(alc5623_hp_mixer_controls
)),
277 SND_SOC_DAPM_MIXER("HPR Mix", ALC5623_PWR_MANAG_ADD2
, 4, 0,
278 &alc5623_hpr_mixer_controls
[0],
279 ARRAY_SIZE(alc5623_hpr_mixer_controls
)),
280 SND_SOC_DAPM_MIXER("HPL Mix", ALC5623_PWR_MANAG_ADD2
, 5, 0,
281 &alc5623_hpl_mixer_controls
[0],
282 ARRAY_SIZE(alc5623_hpl_mixer_controls
)),
283 SND_SOC_DAPM_MIXER("HPOut Mix", SND_SOC_NOPM
, 0, 0, NULL
, 0),
284 SND_SOC_DAPM_MIXER("Mono Mix", ALC5623_PWR_MANAG_ADD2
, 2, 0,
285 &alc5623_mono_mixer_controls
[0],
286 ARRAY_SIZE(alc5623_mono_mixer_controls
)),
287 SND_SOC_DAPM_MIXER("Speaker Mix", ALC5623_PWR_MANAG_ADD2
, 3, 0,
288 &alc5623_speaker_mixer_controls
[0],
289 ARRAY_SIZE(alc5623_speaker_mixer_controls
)),
292 SND_SOC_DAPM_MIXER("Left Capture Mix", ALC5623_PWR_MANAG_ADD2
, 1, 0,
293 &alc5623_captureL_mixer_controls
[0],
294 ARRAY_SIZE(alc5623_captureL_mixer_controls
)),
295 SND_SOC_DAPM_MIXER("Right Capture Mix", ALC5623_PWR_MANAG_ADD2
, 0, 0,
296 &alc5623_captureR_mixer_controls
[0],
297 ARRAY_SIZE(alc5623_captureR_mixer_controls
)),
299 SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback",
300 ALC5623_PWR_MANAG_ADD2
, 9, 0),
301 SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback",
302 ALC5623_PWR_MANAG_ADD2
, 8, 0),
303 SND_SOC_DAPM_MIXER("I2S Mix", ALC5623_PWR_MANAG_ADD1
, 15, 0, NULL
, 0),
304 SND_SOC_DAPM_MIXER("AuxI Mix", SND_SOC_NOPM
, 0, 0, NULL
, 0),
305 SND_SOC_DAPM_MIXER("Line Mix", SND_SOC_NOPM
, 0, 0, NULL
, 0),
306 SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture",
307 ALC5623_PWR_MANAG_ADD2
, 7, 0),
308 SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture",
309 ALC5623_PWR_MANAG_ADD2
, 6, 0),
310 SND_SOC_DAPM_PGA("Left Headphone", ALC5623_PWR_MANAG_ADD3
, 10, 0, NULL
, 0),
311 SND_SOC_DAPM_PGA("Right Headphone", ALC5623_PWR_MANAG_ADD3
, 9, 0, NULL
, 0),
312 SND_SOC_DAPM_PGA("SpeakerOut", ALC5623_PWR_MANAG_ADD3
, 12, 0, NULL
, 0),
313 SND_SOC_DAPM_PGA("Left AuxOut", ALC5623_PWR_MANAG_ADD3
, 14, 0, NULL
, 0),
314 SND_SOC_DAPM_PGA("Right AuxOut", ALC5623_PWR_MANAG_ADD3
, 13, 0, NULL
, 0),
315 SND_SOC_DAPM_PGA("Left LineIn", ALC5623_PWR_MANAG_ADD3
, 7, 0, NULL
, 0),
316 SND_SOC_DAPM_PGA("Right LineIn", ALC5623_PWR_MANAG_ADD3
, 6, 0, NULL
, 0),
317 SND_SOC_DAPM_PGA("Left AuxI", ALC5623_PWR_MANAG_ADD3
, 5, 0, NULL
, 0),
318 SND_SOC_DAPM_PGA("Right AuxI", ALC5623_PWR_MANAG_ADD3
, 4, 0, NULL
, 0),
319 SND_SOC_DAPM_PGA("MIC1 PGA", ALC5623_PWR_MANAG_ADD3
, 3, 0, NULL
, 0),
320 SND_SOC_DAPM_PGA("MIC2 PGA", ALC5623_PWR_MANAG_ADD3
, 2, 0, NULL
, 0),
321 SND_SOC_DAPM_PGA("MIC1 Pre Amp", ALC5623_PWR_MANAG_ADD3
, 1, 0, NULL
, 0),
322 SND_SOC_DAPM_PGA("MIC2 Pre Amp", ALC5623_PWR_MANAG_ADD3
, 0, 0, NULL
, 0),
323 SND_SOC_DAPM_MICBIAS("Mic Bias1", ALC5623_PWR_MANAG_ADD1
, 11, 0),
325 SND_SOC_DAPM_OUTPUT("AUXOUTL"),
326 SND_SOC_DAPM_OUTPUT("AUXOUTR"),
327 SND_SOC_DAPM_OUTPUT("HPL"),
328 SND_SOC_DAPM_OUTPUT("HPR"),
329 SND_SOC_DAPM_OUTPUT("SPKOUT"),
330 SND_SOC_DAPM_OUTPUT("SPKOUTN"),
331 SND_SOC_DAPM_INPUT("LINEINL"),
332 SND_SOC_DAPM_INPUT("LINEINR"),
333 SND_SOC_DAPM_INPUT("AUXINL"),
334 SND_SOC_DAPM_INPUT("AUXINR"),
335 SND_SOC_DAPM_INPUT("MIC1"),
336 SND_SOC_DAPM_INPUT("MIC2"),
337 SND_SOC_DAPM_VMID("Vmid"),
340 static const char *alc5623_amp_names
[] = {"AB Amp", "D Amp"};
341 static const struct soc_enum alc5623_amp_enum
=
342 SOC_ENUM_SINGLE(ALC5623_OUTPUT_MIXER_CTRL
, 13, 2, alc5623_amp_names
);
343 static const struct snd_kcontrol_new alc5623_amp_mux_controls
=
344 SOC_DAPM_ENUM("Route", alc5623_amp_enum
);
346 static const struct snd_soc_dapm_widget alc5623_dapm_amp_widgets
[] = {
347 SND_SOC_DAPM_PGA_E("D Amp", ALC5623_PWR_MANAG_ADD2
, 14, 0, NULL
, 0,
348 amp_mixer_event
, SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
349 SND_SOC_DAPM_PGA("AB Amp", ALC5623_PWR_MANAG_ADD2
, 15, 0, NULL
, 0),
350 SND_SOC_DAPM_MUX("AB-D Amp Mux", SND_SOC_NOPM
, 0, 0,
351 &alc5623_amp_mux_controls
),
354 static const struct snd_soc_dapm_route intercon
[] = {
355 /* virtual mixer - mixes left & right channels */
356 {"I2S Mix", NULL
, "Left DAC"},
357 {"I2S Mix", NULL
, "Right DAC"},
358 {"Line Mix", NULL
, "Right LineIn"},
359 {"Line Mix", NULL
, "Left LineIn"},
360 {"AuxI Mix", NULL
, "Left AuxI"},
361 {"AuxI Mix", NULL
, "Right AuxI"},
362 {"AUXOUTL", NULL
, "Left AuxOut"},
363 {"AUXOUTR", NULL
, "Right AuxOut"},
366 {"HPL Mix", "ADC2HP_L Playback Switch", "Left Capture Mix"},
367 {"HPL Mix", NULL
, "HP Mix"},
368 {"HPR Mix", "ADC2HP_R Playback Switch", "Right Capture Mix"},
369 {"HPR Mix", NULL
, "HP Mix"},
370 {"HP Mix", "LI2HP Playback Switch", "Line Mix"},
371 {"HP Mix", "AUXI2HP Playback Switch", "AuxI Mix"},
372 {"HP Mix", "MIC12HP Playback Switch", "MIC1 PGA"},
373 {"HP Mix", "MIC22HP Playback Switch", "MIC2 PGA"},
374 {"HP Mix", "DAC2HP Playback Switch", "I2S Mix"},
377 {"Speaker Mix", "LI2SPK Playback Switch", "Line Mix"},
378 {"Speaker Mix", "AUXI2SPK Playback Switch", "AuxI Mix"},
379 {"Speaker Mix", "MIC12SPK Playback Switch", "MIC1 PGA"},
380 {"Speaker Mix", "MIC22SPK Playback Switch", "MIC2 PGA"},
381 {"Speaker Mix", "DAC2SPK Playback Switch", "I2S Mix"},
384 {"Mono Mix", "ADC2MONO_L Playback Switch", "Left Capture Mix"},
385 {"Mono Mix", "ADC2MONO_R Playback Switch", "Right Capture Mix"},
386 {"Mono Mix", "LI2MONO Playback Switch", "Line Mix"},
387 {"Mono Mix", "AUXI2MONO Playback Switch", "AuxI Mix"},
388 {"Mono Mix", "MIC12MONO Playback Switch", "MIC1 PGA"},
389 {"Mono Mix", "MIC22MONO Playback Switch", "MIC2 PGA"},
390 {"Mono Mix", "DAC2MONO Playback Switch", "I2S Mix"},
392 /* Left record mixer */
393 {"Left Capture Mix", "LineInL Capture Switch", "LINEINL"},
394 {"Left Capture Mix", "Left AuxI Capture Switch", "AUXINL"},
395 {"Left Capture Mix", "Mic1 Capture Switch", "MIC1 Pre Amp"},
396 {"Left Capture Mix", "Mic2 Capture Switch", "MIC2 Pre Amp"},
397 {"Left Capture Mix", "HPMixerL Capture Switch", "HPL Mix"},
398 {"Left Capture Mix", "SPKMixer Capture Switch", "Speaker Mix"},
399 {"Left Capture Mix", "MonoMixer Capture Switch", "Mono Mix"},
401 /*Right record mixer */
402 {"Right Capture Mix", "LineInR Capture Switch", "LINEINR"},
403 {"Right Capture Mix", "Right AuxI Capture Switch", "AUXINR"},
404 {"Right Capture Mix", "Mic1 Capture Switch", "MIC1 Pre Amp"},
405 {"Right Capture Mix", "Mic2 Capture Switch", "MIC2 Pre Amp"},
406 {"Right Capture Mix", "HPMixerR Capture Switch", "HPR Mix"},
407 {"Right Capture Mix", "SPKMixer Capture Switch", "Speaker Mix"},
408 {"Right Capture Mix", "MonoMixer Capture Switch", "Mono Mix"},
410 /* headphone left mux */
411 {"Left Headphone Mux", "HP Left Mix", "HPL Mix"},
412 {"Left Headphone Mux", "Vmid", "Vmid"},
414 /* headphone right mux */
415 {"Right Headphone Mux", "HP Right Mix", "HPR Mix"},
416 {"Right Headphone Mux", "Vmid", "Vmid"},
418 /* speaker out mux */
419 {"SpeakerOut Mux", "Vmid", "Vmid"},
420 {"SpeakerOut Mux", "HPOut Mix", "HPOut Mix"},
421 {"SpeakerOut Mux", "Speaker Mix", "Speaker Mix"},
422 {"SpeakerOut Mux", "Mono Mix", "Mono Mix"},
424 /* Mono/Aux Out mux */
425 {"AuxOut Mux", "Vmid", "Vmid"},
426 {"AuxOut Mux", "HPOut Mix", "HPOut Mix"},
427 {"AuxOut Mux", "Speaker Mix", "Speaker Mix"},
428 {"AuxOut Mux", "Mono Mix", "Mono Mix"},
431 {"HPL", NULL
, "Left Headphone"},
432 {"Left Headphone", NULL
, "Left Headphone Mux"},
433 {"HPR", NULL
, "Right Headphone"},
434 {"Right Headphone", NULL
, "Right Headphone Mux"},
435 {"Left AuxOut", NULL
, "AuxOut Mux"},
436 {"Right AuxOut", NULL
, "AuxOut Mux"},
439 {"Left LineIn", NULL
, "LINEINL"},
440 {"Right LineIn", NULL
, "LINEINR"},
441 {"Left AuxI", NULL
, "AUXINL"},
442 {"Right AuxI", NULL
, "AUXINR"},
443 {"MIC1 Pre Amp", NULL
, "MIC1"},
444 {"MIC2 Pre Amp", NULL
, "MIC2"},
445 {"MIC1 PGA", NULL
, "MIC1 Pre Amp"},
446 {"MIC2 PGA", NULL
, "MIC2 Pre Amp"},
449 {"Left ADC", NULL
, "Left Capture Mix"},
452 {"Right ADC", NULL
, "Right Capture Mix"},
454 {"SpeakerOut N Mux", "RN/-R", "SpeakerOut"},
455 {"SpeakerOut N Mux", "RP/+R", "SpeakerOut"},
456 {"SpeakerOut N Mux", "LN/-R", "SpeakerOut"},
457 {"SpeakerOut N Mux", "Vmid", "Vmid"},
459 {"SPKOUT", NULL
, "SpeakerOut"},
460 {"SPKOUTN", NULL
, "SpeakerOut N Mux"},
463 static const struct snd_soc_dapm_route intercon_spk
[] = {
464 {"SpeakerOut", NULL
, "SpeakerOut Mux"},
467 static const struct snd_soc_dapm_route intercon_amp_spk
[] = {
468 {"AB Amp", NULL
, "SpeakerOut Mux"},
469 {"D Amp", NULL
, "SpeakerOut Mux"},
470 {"AB-D Amp Mux", "AB Amp", "AB Amp"},
471 {"AB-D Amp Mux", "D Amp", "D Amp"},
472 {"SpeakerOut", NULL
, "AB-D Amp Mux"},
482 /* Note : pll code from original alc5623 driver. Not sure of how good it is */
483 /* useful only for master mode */
484 static const struct _pll_div codec_master_pll_div
[] = {
486 { 2048000, 8192000, 0x0ea0},
487 { 3686400, 8192000, 0x4e27},
488 { 12000000, 8192000, 0x456b},
489 { 13000000, 8192000, 0x495f},
490 { 13100000, 8192000, 0x0320},
491 { 2048000, 11289600, 0xf637},
492 { 3686400, 11289600, 0x2f22},
493 { 12000000, 11289600, 0x3e2f},
494 { 13000000, 11289600, 0x4d5b},
495 { 13100000, 11289600, 0x363b},
496 { 2048000, 16384000, 0x1ea0},
497 { 3686400, 16384000, 0x9e27},
498 { 12000000, 16384000, 0x452b},
499 { 13000000, 16384000, 0x542f},
500 { 13100000, 16384000, 0x03a0},
501 { 2048000, 16934400, 0xe625},
502 { 3686400, 16934400, 0x9126},
503 { 12000000, 16934400, 0x4d2c},
504 { 13000000, 16934400, 0x742f},
505 { 13100000, 16934400, 0x3c27},
506 { 2048000, 22579200, 0x2aa0},
507 { 3686400, 22579200, 0x2f20},
508 { 12000000, 22579200, 0x7e2f},
509 { 13000000, 22579200, 0x742f},
510 { 13100000, 22579200, 0x3c27},
511 { 2048000, 24576000, 0x2ea0},
512 { 3686400, 24576000, 0xee27},
513 { 12000000, 24576000, 0x2915},
514 { 13000000, 24576000, 0x772e},
515 { 13100000, 24576000, 0x0d20},
518 static const struct _pll_div codec_slave_pll_div
[] = {
520 { 1024000, 16384000, 0x3ea0},
521 { 1411200, 22579200, 0x3ea0},
522 { 1536000, 24576000, 0x3ea0},
523 { 2048000, 16384000, 0x1ea0},
524 { 2822400, 22579200, 0x1ea0},
525 { 3072000, 24576000, 0x1ea0},
529 static int alc5623_set_dai_pll(struct snd_soc_dai
*codec_dai
, int pll_id
,
530 int source
, unsigned int freq_in
, unsigned int freq_out
)
533 struct snd_soc_codec
*codec
= codec_dai
->codec
;
534 int gbl_clk
= 0, pll_div
= 0;
537 if (pll_id
< ALC5623_PLL_FR_MCLK
|| pll_id
> ALC5623_PLL_FR_BCK
)
540 /* Disable PLL power */
541 snd_soc_update_bits(codec
, ALC5623_PWR_MANAG_ADD2
,
542 ALC5623_PWR_ADD2_PLL
,
545 /* pll is not used in slave mode */
546 reg
= snd_soc_read(codec
, ALC5623_DAI_CONTROL
);
547 if (reg
& ALC5623_DAI_SDP_SLAVE_MODE
)
550 if (!freq_in
|| !freq_out
)
554 case ALC5623_PLL_FR_MCLK
:
555 for (i
= 0; i
< ARRAY_SIZE(codec_master_pll_div
); i
++) {
556 if (codec_master_pll_div
[i
].pll_in
== freq_in
557 && codec_master_pll_div
[i
].pll_out
== freq_out
) {
558 /* PLL source from MCLK */
559 pll_div
= codec_master_pll_div
[i
].regvalue
;
564 case ALC5623_PLL_FR_BCK
:
565 for (i
= 0; i
< ARRAY_SIZE(codec_slave_pll_div
); i
++) {
566 if (codec_slave_pll_div
[i
].pll_in
== freq_in
567 && codec_slave_pll_div
[i
].pll_out
== freq_out
) {
568 /* PLL source from Bitclk */
569 gbl_clk
= ALC5623_GBL_CLK_PLL_SOUR_SEL_BITCLK
;
570 pll_div
= codec_slave_pll_div
[i
].regvalue
;
582 snd_soc_write(codec
, ALC5623_GLOBAL_CLK_CTRL_REG
, gbl_clk
);
583 snd_soc_write(codec
, ALC5623_PLL_CTRL
, pll_div
);
584 snd_soc_update_bits(codec
, ALC5623_PWR_MANAG_ADD2
,
585 ALC5623_PWR_ADD2_PLL
,
586 ALC5623_PWR_ADD2_PLL
);
587 gbl_clk
|= ALC5623_GBL_CLK_SYS_SOUR_SEL_PLL
;
588 snd_soc_write(codec
, ALC5623_GLOBAL_CLK_CTRL_REG
, gbl_clk
);
598 /* codec hifi mclk (after PLL) clock divider coefficients */
599 /* values inspired from column BCLK=32Fs of Appendix A table */
600 static const struct _coeff_div coeff_div
[] = {
611 static int get_coeff(struct snd_soc_codec
*codec
, int rate
)
613 struct alc5623_priv
*alc5623
= snd_soc_codec_get_drvdata(codec
);
616 for (i
= 0; i
< ARRAY_SIZE(coeff_div
); i
++) {
617 if (coeff_div
[i
].fs
* rate
== alc5623
->sysclk
)
624 * Clock after PLL and dividers
626 static int alc5623_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
627 int clk_id
, unsigned int freq
, int dir
)
629 struct snd_soc_codec
*codec
= codec_dai
->codec
;
630 struct alc5623_priv
*alc5623
= snd_soc_codec_get_drvdata(codec
);
641 alc5623
->sysclk
= freq
;
647 static int alc5623_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
650 struct snd_soc_codec
*codec
= codec_dai
->codec
;
653 /* set master/slave audio interface */
654 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
655 case SND_SOC_DAIFMT_CBM_CFM
:
656 iface
= ALC5623_DAI_SDP_MASTER_MODE
;
658 case SND_SOC_DAIFMT_CBS_CFS
:
659 iface
= ALC5623_DAI_SDP_SLAVE_MODE
;
665 /* interface format */
666 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
667 case SND_SOC_DAIFMT_I2S
:
668 iface
|= ALC5623_DAI_I2S_DF_I2S
;
670 case SND_SOC_DAIFMT_RIGHT_J
:
671 iface
|= ALC5623_DAI_I2S_DF_RIGHT
;
673 case SND_SOC_DAIFMT_LEFT_J
:
674 iface
|= ALC5623_DAI_I2S_DF_LEFT
;
676 case SND_SOC_DAIFMT_DSP_A
:
677 iface
|= ALC5623_DAI_I2S_DF_PCM
;
679 case SND_SOC_DAIFMT_DSP_B
:
680 iface
|= ALC5623_DAI_I2S_DF_PCM
| ALC5623_DAI_I2S_PCM_MODE
;
686 /* clock inversion */
687 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
688 case SND_SOC_DAIFMT_NB_NF
:
690 case SND_SOC_DAIFMT_IB_IF
:
691 iface
|= ALC5623_DAI_MAIN_I2S_BCLK_POL_CTRL
;
693 case SND_SOC_DAIFMT_IB_NF
:
694 iface
|= ALC5623_DAI_MAIN_I2S_BCLK_POL_CTRL
;
696 case SND_SOC_DAIFMT_NB_IF
:
702 return snd_soc_write(codec
, ALC5623_DAI_CONTROL
, iface
);
705 static int alc5623_pcm_hw_params(struct snd_pcm_substream
*substream
,
706 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
708 struct snd_soc_codec
*codec
= dai
->codec
;
709 struct alc5623_priv
*alc5623
= snd_soc_codec_get_drvdata(codec
);
713 iface
= snd_soc_read(codec
, ALC5623_DAI_CONTROL
);
714 iface
&= ~ALC5623_DAI_I2S_DL_MASK
;
717 switch (params_format(params
)) {
718 case SNDRV_PCM_FORMAT_S16_LE
:
719 iface
|= ALC5623_DAI_I2S_DL_16
;
721 case SNDRV_PCM_FORMAT_S20_3LE
:
722 iface
|= ALC5623_DAI_I2S_DL_20
;
724 case SNDRV_PCM_FORMAT_S24_LE
:
725 iface
|= ALC5623_DAI_I2S_DL_24
;
727 case SNDRV_PCM_FORMAT_S32_LE
:
728 iface
|= ALC5623_DAI_I2S_DL_32
;
734 /* set iface & srate */
735 snd_soc_write(codec
, ALC5623_DAI_CONTROL
, iface
);
736 rate
= params_rate(params
);
737 coeff
= get_coeff(codec
, rate
);
741 coeff
= coeff_div
[coeff
].regvalue
;
742 dev_dbg(codec
->dev
, "%s: sysclk=%d,rate=%d,coeff=0x%04x\n",
743 __func__
, alc5623
->sysclk
, rate
, coeff
);
744 snd_soc_write(codec
, ALC5623_STEREO_AD_DA_CLK_CTRL
, coeff
);
749 static int alc5623_mute(struct snd_soc_dai
*dai
, int mute
)
751 struct snd_soc_codec
*codec
= dai
->codec
;
752 u16 hp_mute
= ALC5623_MISC_M_DAC_L_INPUT
| ALC5623_MISC_M_DAC_R_INPUT
;
753 u16 mute_reg
= snd_soc_read(codec
, ALC5623_MISC_CTRL
) & ~hp_mute
;
758 return snd_soc_write(codec
, ALC5623_MISC_CTRL
, mute_reg
);
761 #define ALC5623_ADD2_POWER_EN (ALC5623_PWR_ADD2_VREF \
762 | ALC5623_PWR_ADD2_DAC_REF_CIR)
764 #define ALC5623_ADD3_POWER_EN (ALC5623_PWR_ADD3_MAIN_BIAS \
765 | ALC5623_PWR_ADD3_MIC1_BOOST_AD)
767 #define ALC5623_ADD1_POWER_EN \
768 (ALC5623_PWR_ADD1_SHORT_CURR_DET_EN | ALC5623_PWR_ADD1_SOFTGEN_EN \
769 | ALC5623_PWR_ADD1_DEPOP_BUF_HP | ALC5623_PWR_ADD1_HP_OUT_AMP \
770 | ALC5623_PWR_ADD1_HP_OUT_ENH_AMP)
772 #define ALC5623_ADD1_POWER_EN_5622 \
773 (ALC5623_PWR_ADD1_SHORT_CURR_DET_EN \
774 | ALC5623_PWR_ADD1_HP_OUT_AMP)
776 static void enable_power_depop(struct snd_soc_codec
*codec
)
778 struct alc5623_priv
*alc5623
= snd_soc_codec_get_drvdata(codec
);
780 snd_soc_update_bits(codec
, ALC5623_PWR_MANAG_ADD1
,
781 ALC5623_PWR_ADD1_SOFTGEN_EN
,
782 ALC5623_PWR_ADD1_SOFTGEN_EN
);
784 snd_soc_write(codec
, ALC5623_PWR_MANAG_ADD3
, ALC5623_ADD3_POWER_EN
);
786 snd_soc_update_bits(codec
, ALC5623_MISC_CTRL
,
787 ALC5623_MISC_HP_DEPOP_MODE2_EN
,
788 ALC5623_MISC_HP_DEPOP_MODE2_EN
);
792 snd_soc_write(codec
, ALC5623_PWR_MANAG_ADD2
, ALC5623_ADD2_POWER_EN
);
794 /* avoid writing '1' into 5622 reserved bits */
795 if (alc5623
->id
== 0x22)
796 snd_soc_write(codec
, ALC5623_PWR_MANAG_ADD1
,
797 ALC5623_ADD1_POWER_EN_5622
);
799 snd_soc_write(codec
, ALC5623_PWR_MANAG_ADD1
,
800 ALC5623_ADD1_POWER_EN
);
802 /* disable HP Depop2 */
803 snd_soc_update_bits(codec
, ALC5623_MISC_CTRL
,
804 ALC5623_MISC_HP_DEPOP_MODE2_EN
,
809 static int alc5623_set_bias_level(struct snd_soc_codec
*codec
,
810 enum snd_soc_bias_level level
)
813 case SND_SOC_BIAS_ON
:
814 enable_power_depop(codec
);
816 case SND_SOC_BIAS_PREPARE
:
818 case SND_SOC_BIAS_STANDBY
:
819 /* everything off except vref/vmid, */
820 snd_soc_write(codec
, ALC5623_PWR_MANAG_ADD2
,
821 ALC5623_PWR_ADD2_VREF
);
822 snd_soc_write(codec
, ALC5623_PWR_MANAG_ADD3
,
823 ALC5623_PWR_ADD3_MAIN_BIAS
);
825 case SND_SOC_BIAS_OFF
:
826 /* everything off, dac mute, inactive */
827 snd_soc_write(codec
, ALC5623_PWR_MANAG_ADD2
, 0);
828 snd_soc_write(codec
, ALC5623_PWR_MANAG_ADD3
, 0);
829 snd_soc_write(codec
, ALC5623_PWR_MANAG_ADD1
, 0);
832 codec
->dapm
.bias_level
= level
;
836 #define ALC5623_FORMATS (SNDRV_PCM_FMTBIT_S16_LE \
837 | SNDRV_PCM_FMTBIT_S24_LE \
838 | SNDRV_PCM_FMTBIT_S32_LE)
840 static const struct snd_soc_dai_ops alc5623_dai_ops
= {
841 .hw_params
= alc5623_pcm_hw_params
,
842 .digital_mute
= alc5623_mute
,
843 .set_fmt
= alc5623_set_dai_fmt
,
844 .set_sysclk
= alc5623_set_dai_sysclk
,
845 .set_pll
= alc5623_set_dai_pll
,
848 static struct snd_soc_dai_driver alc5623_dai
= {
849 .name
= "alc5623-hifi",
851 .stream_name
= "Playback",
856 .rates
= SNDRV_PCM_RATE_8000_48000
,
857 .formats
= ALC5623_FORMATS
,},
859 .stream_name
= "Capture",
864 .rates
= SNDRV_PCM_RATE_8000_48000
,
865 .formats
= ALC5623_FORMATS
,},
867 .ops
= &alc5623_dai_ops
,
870 static int alc5623_suspend(struct snd_soc_codec
*codec
)
872 alc5623_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
876 static int alc5623_resume(struct snd_soc_codec
*codec
)
878 int i
, step
= codec
->driver
->reg_cache_step
;
879 u16
*cache
= codec
->reg_cache
;
881 /* Sync reg_cache with the hardware */
882 for (i
= 2 ; i
< codec
->driver
->reg_cache_size
; i
+= step
)
883 snd_soc_write(codec
, i
, cache
[i
]);
885 alc5623_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
887 /* charge alc5623 caps */
888 if (codec
->dapm
.suspend_bias_level
== SND_SOC_BIAS_ON
) {
889 alc5623_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
890 codec
->dapm
.bias_level
= SND_SOC_BIAS_ON
;
891 alc5623_set_bias_level(codec
, codec
->dapm
.bias_level
);
897 static int alc5623_probe(struct snd_soc_codec
*codec
)
899 struct alc5623_priv
*alc5623
= snd_soc_codec_get_drvdata(codec
);
900 struct snd_soc_dapm_context
*dapm
= &codec
->dapm
;
903 ret
= snd_soc_codec_set_cache_io(codec
, 8, 16, alc5623
->control_type
);
905 dev_err(codec
->dev
, "Failed to set cache I/O: %d\n", ret
);
909 alc5623_reset(codec
);
910 alc5623_fill_cache(codec
);
912 /* power on device */
913 alc5623_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
915 if (alc5623
->add_ctrl
) {
916 snd_soc_write(codec
, ALC5623_ADD_CTRL_REG
,
920 if (alc5623
->jack_det_ctrl
) {
921 snd_soc_write(codec
, ALC5623_JACK_DET_CTRL
,
922 alc5623
->jack_det_ctrl
);
925 switch (alc5623
->id
) {
927 snd_soc_add_codec_controls(codec
, alc5621_vol_snd_controls
,
928 ARRAY_SIZE(alc5621_vol_snd_controls
));
931 snd_soc_add_codec_controls(codec
, alc5622_vol_snd_controls
,
932 ARRAY_SIZE(alc5622_vol_snd_controls
));
935 snd_soc_add_codec_controls(codec
, alc5623_vol_snd_controls
,
936 ARRAY_SIZE(alc5623_vol_snd_controls
));
942 snd_soc_add_codec_controls(codec
, alc5623_snd_controls
,
943 ARRAY_SIZE(alc5623_snd_controls
));
945 snd_soc_dapm_new_controls(dapm
, alc5623_dapm_widgets
,
946 ARRAY_SIZE(alc5623_dapm_widgets
));
948 /* set up audio path interconnects */
949 snd_soc_dapm_add_routes(dapm
, intercon
, ARRAY_SIZE(intercon
));
951 switch (alc5623
->id
) {
954 snd_soc_dapm_new_controls(dapm
, alc5623_dapm_amp_widgets
,
955 ARRAY_SIZE(alc5623_dapm_amp_widgets
));
956 snd_soc_dapm_add_routes(dapm
, intercon_amp_spk
,
957 ARRAY_SIZE(intercon_amp_spk
));
960 snd_soc_dapm_add_routes(dapm
, intercon_spk
,
961 ARRAY_SIZE(intercon_spk
));
970 /* power down chip */
971 static int alc5623_remove(struct snd_soc_codec
*codec
)
973 alc5623_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
977 static struct snd_soc_codec_driver soc_codec_device_alc5623
= {
978 .probe
= alc5623_probe
,
979 .remove
= alc5623_remove
,
980 .suspend
= alc5623_suspend
,
981 .resume
= alc5623_resume
,
982 .set_bias_level
= alc5623_set_bias_level
,
983 .reg_cache_size
= ALC5623_VENDOR_ID2
+2,
984 .reg_word_size
= sizeof(u16
),
989 * ALC5623 2 wire address is determined by A1 pin
990 * state during powerup.
994 static __devinit
int alc5623_i2c_probe(struct i2c_client
*client
,
995 const struct i2c_device_id
*id
)
997 struct alc5623_platform_data
*pdata
;
998 struct alc5623_priv
*alc5623
;
1001 vid1
= i2c_smbus_read_word_data(client
, ALC5623_VENDOR_ID1
);
1003 dev_err(&client
->dev
, "failed to read I2C\n");
1006 vid1
= ((vid1
& 0xff) << 8) | (vid1
>> 8);
1008 vid2
= i2c_smbus_read_byte_data(client
, ALC5623_VENDOR_ID2
);
1010 dev_err(&client
->dev
, "failed to read I2C\n");
1014 if ((vid1
!= 0x10ec) || (vid2
!= id
->driver_data
)) {
1015 dev_err(&client
->dev
, "unknown or wrong codec\n");
1016 dev_err(&client
->dev
, "Expected %x:%lx, got %x:%x\n",
1017 0x10ec, id
->driver_data
,
1022 dev_dbg(&client
->dev
, "Found codec id : alc56%02x\n", vid2
);
1024 alc5623
= devm_kzalloc(&client
->dev
, sizeof(struct alc5623_priv
),
1026 if (alc5623
== NULL
)
1029 pdata
= client
->dev
.platform_data
;
1031 alc5623
->add_ctrl
= pdata
->add_ctrl
;
1032 alc5623
->jack_det_ctrl
= pdata
->jack_det_ctrl
;
1036 switch (alc5623
->id
) {
1038 alc5623_dai
.name
= "alc5621-hifi";
1041 alc5623_dai
.name
= "alc5622-hifi";
1044 alc5623_dai
.name
= "alc5623-hifi";
1050 i2c_set_clientdata(client
, alc5623
);
1051 alc5623
->control_type
= SND_SOC_I2C
;
1053 ret
= snd_soc_register_codec(&client
->dev
,
1054 &soc_codec_device_alc5623
, &alc5623_dai
, 1);
1056 dev_err(&client
->dev
, "Failed to register codec: %d\n", ret
);
1061 static __devexit
int alc5623_i2c_remove(struct i2c_client
*client
)
1063 snd_soc_unregister_codec(&client
->dev
);
1067 static const struct i2c_device_id alc5623_i2c_table
[] = {
1073 MODULE_DEVICE_TABLE(i2c
, alc5623_i2c_table
);
1075 /* i2c codec control layer */
1076 static struct i2c_driver alc5623_i2c_driver
= {
1078 .name
= "alc562x-codec",
1079 .owner
= THIS_MODULE
,
1081 .probe
= alc5623_i2c_probe
,
1082 .remove
= __devexit_p(alc5623_i2c_remove
),
1083 .id_table
= alc5623_i2c_table
,
1086 module_i2c_driver(alc5623_i2c_driver
);
1088 MODULE_DESCRIPTION("ASoC alc5621/2/3 driver");
1089 MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
1090 MODULE_LICENSE("GPL");