2 * alc5632.c -- ALC5632 ALSA SoC Audio Codec
4 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
6 * Authors: Leon Romanovsky <leon@leon.nu>
7 * Andrey Danin <danindrey@mail.ru>
8 * Ilya Petrov <ilya.muromec@gmail.com>
9 * Marc Dietrich <marvin24@gmx.de>
11 * Based on alc5623.c by Arnaud Patard
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * 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 <linux/regmap.h>
26 #include <sound/core.h>
27 #include <sound/pcm.h>
28 #include <sound/pcm_params.h>
29 #include <sound/tlv.h>
30 #include <sound/soc.h>
31 #include <sound/initval.h>
36 * ALC5632 register cache
38 static struct reg_default alc5632_reg_defaults
[] = {
39 { 2, 0x8080 }, /* R2 - Speaker Output Volume */
40 { 4, 0x8080 }, /* R4 - Headphone Output Volume */
41 { 6, 0x8080 }, /* R6 - AUXOUT Volume */
42 { 8, 0xC800 }, /* R8 - Phone Input */
43 { 10, 0xE808 }, /* R10 - LINE_IN Volume */
44 { 12, 0x1010 }, /* R12 - STEREO DAC Input Volume */
45 { 14, 0x0808 }, /* R14 - MIC Input Volume */
46 { 16, 0xEE0F }, /* R16 - Stereo DAC and MIC Routing Control */
47 { 18, 0xCBCB }, /* R18 - ADC Record Gain */
48 { 20, 0x7F7F }, /* R20 - ADC Record Mixer Control */
49 { 24, 0xE010 }, /* R24 - Voice DAC Volume */
50 { 28, 0x8008 }, /* R28 - Output Mixer Control */
51 { 34, 0x0000 }, /* R34 - Microphone Control */
52 { 36, 0x00C0 }, /* R36 - Codec Digital MIC/Digital Boost
54 { 46, 0x0000 }, /* R46 - Stereo DAC/Voice DAC/Stereo ADC
56 { 52, 0x8000 }, /* R52 - Main Serial Data Port Control
58 { 54, 0x0000 }, /* R54 - Extend Serial Data Port Control
60 { 58, 0x0000 }, /* R58 - Power Management Addition 1 */
61 { 60, 0x0000 }, /* R60 - Power Management Addition 2 */
62 { 62, 0x8000 }, /* R62 - Power Management Addition 3 */
63 { 64, 0x0C0A }, /* R64 - General Purpose Control Register 1 */
64 { 66, 0x0000 }, /* R66 - General Purpose Control Register 2 */
65 { 68, 0x0000 }, /* R68 - PLL1 Control */
66 { 70, 0x0000 }, /* R70 - PLL2 Control */
67 { 76, 0xBE3E }, /* R76 - GPIO Pin Configuration */
68 { 78, 0xBE3E }, /* R78 - GPIO Pin Polarity */
69 { 80, 0x0000 }, /* R80 - GPIO Pin Sticky */
70 { 82, 0x0000 }, /* R82 - GPIO Pin Wake Up */
71 { 86, 0x0000 }, /* R86 - Pin Sharing */
72 { 90, 0x0009 }, /* R90 - Soft Volume Control Setting */
73 { 92, 0x0000 }, /* R92 - GPIO_Output Pin Control */
74 { 94, 0x3000 }, /* R94 - MISC Control */
75 { 96, 0x3075 }, /* R96 - Stereo DAC Clock Control_1 */
76 { 98, 0x1010 }, /* R98 - Stereo DAC Clock Control_2 */
77 { 100, 0x3110 }, /* R100 - VoDAC_PCM Clock Control_1 */
78 { 104, 0x0553 }, /* R104 - Pseudo Stereo and Spatial Effect
80 { 106, 0x0000 }, /* R106 - Private Register Address */
83 /* codec private data */
85 struct regmap
*regmap
;
90 static bool alc5632_volatile_register(struct device
*dev
,
95 case ALC5632_PWR_DOWN_CTRL_STATUS
:
96 case ALC5632_GPIO_PIN_STATUS
:
97 case ALC5632_OVER_CURR_STATUS
:
98 case ALC5632_HID_CTRL_DATA
:
100 case ALC5632_VENDOR_ID1
:
101 case ALC5632_VENDOR_ID2
:
111 static inline int alc5632_reset(struct regmap
*map
)
113 return regmap_write(map
, ALC5632_RESET
, 0x59B4);
116 static int amp_mixer_event(struct snd_soc_dapm_widget
*w
,
117 struct snd_kcontrol
*kcontrol
, int event
)
119 /* to power-on/off class-d amp generators/speaker */
120 /* need to write to 'index-46h' register : */
121 /* so write index num (here 0x46) to reg 0x6a */
122 /* and then 0xffff/0 to reg 0x6c */
123 snd_soc_write(w
->codec
, ALC5632_HID_CTRL_INDEX
, 0x46);
126 case SND_SOC_DAPM_PRE_PMU
:
127 snd_soc_write(w
->codec
, ALC5632_HID_CTRL_DATA
, 0xFFFF);
129 case SND_SOC_DAPM_POST_PMD
:
130 snd_soc_write(w
->codec
, ALC5632_HID_CTRL_DATA
, 0);
141 /* -34.5db min scale, 1.5db steps, no mute */
142 static const DECLARE_TLV_DB_SCALE(vol_tlv
, -3450, 150, 0);
143 /* -46.5db min scale, 1.5db steps, no mute */
144 static const DECLARE_TLV_DB_SCALE(hp_tlv
, -4650, 150, 0);
145 /* -16.5db min scale, 1.5db steps, no mute */
146 static const DECLARE_TLV_DB_SCALE(adc_rec_tlv
, -1650, 150, 0);
147 static const unsigned int boost_tlv
[] = {
148 TLV_DB_RANGE_HEAD(3),
149 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
150 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
151 2, 2, TLV_DB_SCALE_ITEM(3000, 0, 0),
153 /* 0db min scale, 6 db steps, no mute */
154 static const DECLARE_TLV_DB_SCALE(dig_tlv
, 0, 600, 0);
155 /* 0db min scalem 0.75db steps, no mute */
156 static const DECLARE_TLV_DB_SCALE(vdac_tlv
, -3525, 075, 0);
158 static const struct snd_kcontrol_new alc5632_vol_snd_controls
[] = {
159 /* left starts at bit 8, right at bit 0 */
160 /* 31 steps (5 bit), -46.5db scale */
161 SOC_DOUBLE_TLV("Speaker Playback Volume",
162 ALC5632_SPK_OUT_VOL
, 8, 0, 31, 1, hp_tlv
),
163 /* bit 15 mutes left, bit 7 right */
164 SOC_DOUBLE("Speaker Playback Switch",
165 ALC5632_SPK_OUT_VOL
, 15, 7, 1, 1),
166 SOC_DOUBLE_TLV("Headphone Playback Volume",
167 ALC5632_HP_OUT_VOL
, 8, 0, 31, 1, hp_tlv
),
168 SOC_DOUBLE("Headphone Playback Switch",
169 ALC5632_HP_OUT_VOL
, 15, 7, 1, 1),
172 static const struct snd_kcontrol_new alc5632_snd_controls
[] = {
173 SOC_DOUBLE_TLV("Auxout Playback Volume",
174 ALC5632_AUX_OUT_VOL
, 8, 0, 31, 1, hp_tlv
),
175 SOC_DOUBLE("Auxout Playback Switch",
176 ALC5632_AUX_OUT_VOL
, 15, 7, 1, 1),
177 SOC_SINGLE_TLV("Voice DAC Playback Volume",
178 ALC5632_VOICE_DAC_VOL
, 0, 63, 0, vdac_tlv
),
179 SOC_SINGLE_TLV("Phone Capture Volume",
180 ALC5632_PHONE_IN_VOL
, 8, 31, 1, vol_tlv
),
181 SOC_DOUBLE_TLV("LineIn Capture Volume",
182 ALC5632_LINE_IN_VOL
, 8, 0, 31, 1, vol_tlv
),
183 SOC_DOUBLE_TLV("Master Playback Volume",
184 ALC5632_STEREO_DAC_IN_VOL
, 8, 0, 63, 1, vdac_tlv
),
185 SOC_DOUBLE("Master Playback Switch",
186 ALC5632_STEREO_DAC_IN_VOL
, 15, 7, 1, 1),
187 SOC_SINGLE_TLV("Mic1 Capture Volume",
188 ALC5632_MIC_VOL
, 8, 31, 1, vol_tlv
),
189 SOC_SINGLE_TLV("Mic2 Capture Volume",
190 ALC5632_MIC_VOL
, 0, 31, 1, vol_tlv
),
191 SOC_DOUBLE_TLV("Rec Capture Volume",
192 ALC5632_ADC_REC_GAIN
, 8, 0, 31, 0, adc_rec_tlv
),
193 SOC_SINGLE_TLV("Mic 1 Boost Volume",
194 ALC5632_MIC_CTRL
, 10, 2, 0, boost_tlv
),
195 SOC_SINGLE_TLV("Mic 2 Boost Volume",
196 ALC5632_MIC_CTRL
, 8, 2, 0, boost_tlv
),
197 SOC_SINGLE_TLV("Digital Boost Volume",
198 ALC5632_DIGI_BOOST_CTRL
, 0, 7, 0, dig_tlv
),
204 static const struct snd_kcontrol_new alc5632_hp_mixer_controls
[] = {
205 SOC_DAPM_SINGLE("LI2HP Playback Switch", ALC5632_LINE_IN_VOL
, 15, 1, 1),
206 SOC_DAPM_SINGLE("PHONE2HP Playback Switch", ALC5632_PHONE_IN_VOL
, 15, 1, 1),
207 SOC_DAPM_SINGLE("MIC12HP Playback Switch", ALC5632_MIC_ROUTING_CTRL
, 15, 1, 1),
208 SOC_DAPM_SINGLE("MIC22HP Playback Switch", ALC5632_MIC_ROUTING_CTRL
, 11, 1, 1),
209 SOC_DAPM_SINGLE("VOICE2HP Playback Switch", ALC5632_VOICE_DAC_VOL
, 15, 1, 1),
212 static const struct snd_kcontrol_new alc5632_hpl_mixer_controls
[] = {
213 SOC_DAPM_SINGLE("ADC2HP_L Playback Switch", ALC5632_ADC_REC_GAIN
, 15, 1, 1),
214 SOC_DAPM_SINGLE("DACL2HP Playback Switch", ALC5632_MIC_ROUTING_CTRL
, 3, 1, 1),
217 static const struct snd_kcontrol_new alc5632_hpr_mixer_controls
[] = {
218 SOC_DAPM_SINGLE("ADC2HP_R Playback Switch", ALC5632_ADC_REC_GAIN
, 7, 1, 1),
219 SOC_DAPM_SINGLE("DACR2HP Playback Switch", ALC5632_MIC_ROUTING_CTRL
, 2, 1, 1),
222 static const struct snd_kcontrol_new alc5632_mono_mixer_controls
[] = {
223 SOC_DAPM_SINGLE("ADC2MONO_L Playback Switch", ALC5632_ADC_REC_GAIN
, 14, 1, 1),
224 SOC_DAPM_SINGLE("ADC2MONO_R Playback Switch", ALC5632_ADC_REC_GAIN
, 6, 1, 1),
225 SOC_DAPM_SINGLE("LI2MONO Playback Switch", ALC5632_LINE_IN_VOL
, 13, 1, 1),
226 SOC_DAPM_SINGLE("MIC12MONO Playback Switch",
227 ALC5632_MIC_ROUTING_CTRL
, 13, 1, 1),
228 SOC_DAPM_SINGLE("MIC22MONO Playback Switch",
229 ALC5632_MIC_ROUTING_CTRL
, 9, 1, 1),
230 SOC_DAPM_SINGLE("DAC2MONO Playback Switch", ALC5632_MIC_ROUTING_CTRL
, 0, 1, 1),
231 SOC_DAPM_SINGLE("VOICE2MONO Playback Switch", ALC5632_VOICE_DAC_VOL
, 13, 1, 1),
234 static const struct snd_kcontrol_new alc5632_speaker_mixer_controls
[] = {
235 SOC_DAPM_SINGLE("LI2SPK Playback Switch", ALC5632_LINE_IN_VOL
, 14, 1, 1),
236 SOC_DAPM_SINGLE("PHONE2SPK Playback Switch", ALC5632_PHONE_IN_VOL
, 14, 1, 1),
237 SOC_DAPM_SINGLE("MIC12SPK Playback Switch",
238 ALC5632_MIC_ROUTING_CTRL
, 14, 1, 1),
239 SOC_DAPM_SINGLE("MIC22SPK Playback Switch",
240 ALC5632_MIC_ROUTING_CTRL
, 10, 1, 1),
241 SOC_DAPM_SINGLE("DAC2SPK Playback Switch", ALC5632_MIC_ROUTING_CTRL
, 1, 1, 1),
242 SOC_DAPM_SINGLE("VOICE2SPK Playback Switch", ALC5632_VOICE_DAC_VOL
, 14, 1, 1),
245 /* Left Record Mixer */
246 static const struct snd_kcontrol_new alc5632_captureL_mixer_controls
[] = {
247 SOC_DAPM_SINGLE("Mic1 Capture Switch", ALC5632_ADC_REC_MIXER
, 14, 1, 1),
248 SOC_DAPM_SINGLE("Mic2 Capture Switch", ALC5632_ADC_REC_MIXER
, 13, 1, 1),
249 SOC_DAPM_SINGLE("LineInL Capture Switch", ALC5632_ADC_REC_MIXER
, 12, 1, 1),
250 SOC_DAPM_SINGLE("Left Phone Capture Switch", ALC5632_ADC_REC_MIXER
, 11, 1, 1),
251 SOC_DAPM_SINGLE("HPMixerL Capture Switch", ALC5632_ADC_REC_MIXER
, 10, 1, 1),
252 SOC_DAPM_SINGLE("SPKMixer Capture Switch", ALC5632_ADC_REC_MIXER
, 9, 1, 1),
253 SOC_DAPM_SINGLE("MonoMixer Capture Switch", ALC5632_ADC_REC_MIXER
, 8, 1, 1),
256 /* Right Record Mixer */
257 static const struct snd_kcontrol_new alc5632_captureR_mixer_controls
[] = {
258 SOC_DAPM_SINGLE("Mic1 Capture Switch", ALC5632_ADC_REC_MIXER
, 6, 1, 1),
259 SOC_DAPM_SINGLE("Mic2 Capture Switch", ALC5632_ADC_REC_MIXER
, 5, 1, 1),
260 SOC_DAPM_SINGLE("LineInR Capture Switch", ALC5632_ADC_REC_MIXER
, 4, 1, 1),
261 SOC_DAPM_SINGLE("Right Phone Capture Switch", ALC5632_ADC_REC_MIXER
, 3, 1, 1),
262 SOC_DAPM_SINGLE("HPMixerR Capture Switch", ALC5632_ADC_REC_MIXER
, 2, 1, 1),
263 SOC_DAPM_SINGLE("SPKMixer Capture Switch", ALC5632_ADC_REC_MIXER
, 1, 1, 1),
264 SOC_DAPM_SINGLE("MonoMixer Capture Switch", ALC5632_ADC_REC_MIXER
, 0, 1, 1),
267 static const char *alc5632_spk_n_sour_sel
[] = {
268 "RN/-R", "RP/+R", "LN/-R", "Mute"};
269 static const char *alc5632_hpl_out_input_sel
[] = {
270 "Vmid", "HP Left Mix"};
271 static const char *alc5632_hpr_out_input_sel
[] = {
272 "Vmid", "HP Right Mix"};
273 static const char *alc5632_spkout_input_sel
[] = {
274 "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
275 static const char *alc5632_aux_out_input_sel
[] = {
276 "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
278 /* auxout output mux */
279 static const struct soc_enum alc5632_aux_out_input_enum
=
280 SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL
, 6, 4, alc5632_aux_out_input_sel
);
281 static const struct snd_kcontrol_new alc5632_auxout_mux_controls
=
282 SOC_DAPM_ENUM("AuxOut Mux", alc5632_aux_out_input_enum
);
284 /* speaker output mux */
285 static const struct soc_enum alc5632_spkout_input_enum
=
286 SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL
, 10, 4, alc5632_spkout_input_sel
);
287 static const struct snd_kcontrol_new alc5632_spkout_mux_controls
=
288 SOC_DAPM_ENUM("SpeakerOut Mux", alc5632_spkout_input_enum
);
290 /* headphone left output mux */
291 static const struct soc_enum alc5632_hpl_out_input_enum
=
292 SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL
, 9, 2, alc5632_hpl_out_input_sel
);
293 static const struct snd_kcontrol_new alc5632_hpl_out_mux_controls
=
294 SOC_DAPM_ENUM("Left Headphone Mux", alc5632_hpl_out_input_enum
);
296 /* headphone right output mux */
297 static const struct soc_enum alc5632_hpr_out_input_enum
=
298 SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL
, 8, 2, alc5632_hpr_out_input_sel
);
299 static const struct snd_kcontrol_new alc5632_hpr_out_mux_controls
=
300 SOC_DAPM_ENUM("Right Headphone Mux", alc5632_hpr_out_input_enum
);
302 /* speaker output N select */
303 static const struct soc_enum alc5632_spk_n_sour_enum
=
304 SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL
, 14, 4, alc5632_spk_n_sour_sel
);
305 static const struct snd_kcontrol_new alc5632_spkoutn_mux_controls
=
306 SOC_DAPM_ENUM("SpeakerOut N Mux", alc5632_spk_n_sour_enum
);
308 /* speaker amplifier */
309 static const char *alc5632_amp_names
[] = {"AB Amp", "D Amp"};
310 static const struct soc_enum alc5632_amp_enum
=
311 SOC_ENUM_SINGLE(ALC5632_OUTPUT_MIXER_CTRL
, 13, 2, alc5632_amp_names
);
312 static const struct snd_kcontrol_new alc5632_amp_mux_controls
=
313 SOC_DAPM_ENUM("AB-D Amp Mux", alc5632_amp_enum
);
316 static const struct snd_soc_dapm_widget alc5632_dapm_widgets
[] = {
318 SND_SOC_DAPM_MUX("AuxOut Mux", SND_SOC_NOPM
, 0, 0,
319 &alc5632_auxout_mux_controls
),
320 SND_SOC_DAPM_MUX("SpeakerOut Mux", SND_SOC_NOPM
, 0, 0,
321 &alc5632_spkout_mux_controls
),
322 SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM
, 0, 0,
323 &alc5632_hpl_out_mux_controls
),
324 SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM
, 0, 0,
325 &alc5632_hpr_out_mux_controls
),
326 SND_SOC_DAPM_MUX("SpeakerOut N Mux", SND_SOC_NOPM
, 0, 0,
327 &alc5632_spkoutn_mux_controls
),
330 SND_SOC_DAPM_MIXER("HP Mix", SND_SOC_NOPM
, 0, 0,
331 &alc5632_hp_mixer_controls
[0],
332 ARRAY_SIZE(alc5632_hp_mixer_controls
)),
333 SND_SOC_DAPM_MIXER("HPR Mix", ALC5632_PWR_MANAG_ADD2
, 4, 0,
334 &alc5632_hpr_mixer_controls
[0],
335 ARRAY_SIZE(alc5632_hpr_mixer_controls
)),
336 SND_SOC_DAPM_MIXER("HPL Mix", ALC5632_PWR_MANAG_ADD2
, 5, 0,
337 &alc5632_hpl_mixer_controls
[0],
338 ARRAY_SIZE(alc5632_hpl_mixer_controls
)),
339 SND_SOC_DAPM_MIXER("HPOut Mix", SND_SOC_NOPM
, 0, 0, NULL
, 0),
340 SND_SOC_DAPM_MIXER("Mono Mix", ALC5632_PWR_MANAG_ADD2
, 2, 0,
341 &alc5632_mono_mixer_controls
[0],
342 ARRAY_SIZE(alc5632_mono_mixer_controls
)),
343 SND_SOC_DAPM_MIXER("Speaker Mix", ALC5632_PWR_MANAG_ADD2
, 3, 0,
344 &alc5632_speaker_mixer_controls
[0],
345 ARRAY_SIZE(alc5632_speaker_mixer_controls
)),
348 SND_SOC_DAPM_MIXER("Left Capture Mix", ALC5632_PWR_MANAG_ADD2
, 1, 0,
349 &alc5632_captureL_mixer_controls
[0],
350 ARRAY_SIZE(alc5632_captureL_mixer_controls
)),
351 SND_SOC_DAPM_MIXER("Right Capture Mix", ALC5632_PWR_MANAG_ADD2
, 0, 0,
352 &alc5632_captureR_mixer_controls
[0],
353 ARRAY_SIZE(alc5632_captureR_mixer_controls
)),
355 SND_SOC_DAPM_DAC("Left DAC", "HiFi Playback",
356 ALC5632_PWR_MANAG_ADD2
, 9, 0),
357 SND_SOC_DAPM_DAC("Right DAC", "HiFi Playback",
358 ALC5632_PWR_MANAG_ADD2
, 8, 0),
359 SND_SOC_DAPM_MIXER("DAC Left Channel", ALC5632_PWR_MANAG_ADD1
, 15, 0, NULL
, 0),
360 SND_SOC_DAPM_MIXER("DAC Right Channel",
361 ALC5632_PWR_MANAG_ADD1
, 14, 0, NULL
, 0),
362 SND_SOC_DAPM_MIXER("I2S Mix", ALC5632_PWR_MANAG_ADD1
, 11, 0, NULL
, 0),
363 SND_SOC_DAPM_MIXER("Phone Mix", SND_SOC_NOPM
, 0, 0, NULL
, 0),
364 SND_SOC_DAPM_MIXER("Line Mix", SND_SOC_NOPM
, 0, 0, NULL
, 0),
365 SND_SOC_DAPM_ADC("Left ADC", "HiFi Capture",
366 ALC5632_PWR_MANAG_ADD2
, 7, 0),
367 SND_SOC_DAPM_ADC("Right ADC", "HiFi Capture",
368 ALC5632_PWR_MANAG_ADD2
, 6, 0),
369 SND_SOC_DAPM_PGA("Left Headphone", ALC5632_PWR_MANAG_ADD3
, 11, 0, NULL
, 0),
370 SND_SOC_DAPM_PGA("Right Headphone", ALC5632_PWR_MANAG_ADD3
, 10, 0, NULL
, 0),
371 SND_SOC_DAPM_PGA("Left Speaker", ALC5632_PWR_MANAG_ADD3
, 13, 0, NULL
, 0),
372 SND_SOC_DAPM_PGA("Right Speaker", ALC5632_PWR_MANAG_ADD3
, 12, 0, NULL
, 0),
373 SND_SOC_DAPM_PGA("Aux Out", ALC5632_PWR_MANAG_ADD3
, 14, 0, NULL
, 0),
374 SND_SOC_DAPM_PGA("Left LineIn", ALC5632_PWR_MANAG_ADD3
, 7, 0, NULL
, 0),
375 SND_SOC_DAPM_PGA("Right LineIn", ALC5632_PWR_MANAG_ADD3
, 6, 0, NULL
, 0),
376 SND_SOC_DAPM_PGA("Phone", ALC5632_PWR_MANAG_ADD3
, 5, 0, NULL
, 0),
377 SND_SOC_DAPM_PGA("Phone ADMix", ALC5632_PWR_MANAG_ADD3
, 4, 0, NULL
, 0),
378 SND_SOC_DAPM_PGA("MIC1 PGA", ALC5632_PWR_MANAG_ADD3
, 3, 0, NULL
, 0),
379 SND_SOC_DAPM_PGA("MIC2 PGA", ALC5632_PWR_MANAG_ADD3
, 2, 0, NULL
, 0),
380 SND_SOC_DAPM_PGA("MIC1 Pre Amp", ALC5632_PWR_MANAG_ADD3
, 1, 0, NULL
, 0),
381 SND_SOC_DAPM_PGA("MIC2 Pre Amp", ALC5632_PWR_MANAG_ADD3
, 0, 0, NULL
, 0),
382 SND_SOC_DAPM_SUPPLY("MICBIAS1", ALC5632_PWR_MANAG_ADD1
, 3, 0, NULL
, 0),
383 SND_SOC_DAPM_SUPPLY("MICBIAS2", ALC5632_PWR_MANAG_ADD1
, 2, 0, NULL
, 0),
385 SND_SOC_DAPM_PGA_E("D Amp", ALC5632_PWR_MANAG_ADD2
, 14, 0, NULL
, 0,
386 amp_mixer_event
, SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
387 SND_SOC_DAPM_PGA("AB Amp", ALC5632_PWR_MANAG_ADD2
, 15, 0, NULL
, 0),
388 SND_SOC_DAPM_MUX("AB-D Amp Mux", ALC5632_PWR_MANAG_ADD1
, 10, 0,
389 &alc5632_amp_mux_controls
),
391 SND_SOC_DAPM_OUTPUT("AUXOUT"),
392 SND_SOC_DAPM_OUTPUT("HPL"),
393 SND_SOC_DAPM_OUTPUT("HPR"),
394 SND_SOC_DAPM_OUTPUT("SPKOUT"),
395 SND_SOC_DAPM_OUTPUT("SPKOUTN"),
396 SND_SOC_DAPM_INPUT("LINEINL"),
397 SND_SOC_DAPM_INPUT("LINEINR"),
398 SND_SOC_DAPM_INPUT("PHONEP"),
399 SND_SOC_DAPM_INPUT("PHONEN"),
400 SND_SOC_DAPM_INPUT("MIC1"),
401 SND_SOC_DAPM_INPUT("MIC2"),
402 SND_SOC_DAPM_VMID("Vmid"),
406 static const struct snd_soc_dapm_route alc5632_dapm_routes
[] = {
407 /* virtual mixer - mixes left & right channels */
408 {"I2S Mix", NULL
, "Left DAC"},
409 {"I2S Mix", NULL
, "Right DAC"},
410 {"Line Mix", NULL
, "Right LineIn"},
411 {"Line Mix", NULL
, "Left LineIn"},
412 {"Phone Mix", NULL
, "Phone"},
413 {"Phone Mix", NULL
, "Phone ADMix"},
414 {"AUXOUT", NULL
, "Aux Out"},
417 {"DAC Right Channel", NULL
, "I2S Mix"},
418 {"DAC Left Channel", NULL
, "I2S Mix"},
421 {"HPL Mix", "ADC2HP_L Playback Switch", "Left Capture Mix"},
422 {"HPL Mix", NULL
, "HP Mix"},
423 {"HPR Mix", "ADC2HP_R Playback Switch", "Right Capture Mix"},
424 {"HPR Mix", NULL
, "HP Mix"},
425 {"HP Mix", "LI2HP Playback Switch", "Line Mix"},
426 {"HP Mix", "PHONE2HP Playback Switch", "Phone Mix"},
427 {"HP Mix", "MIC12HP Playback Switch", "MIC1 PGA"},
428 {"HP Mix", "MIC22HP Playback Switch", "MIC2 PGA"},
430 {"HPR Mix", "DACR2HP Playback Switch", "DAC Right Channel"},
431 {"HPL Mix", "DACL2HP Playback Switch", "DAC Left Channel"},
434 {"Speaker Mix", "LI2SPK Playback Switch", "Line Mix"},
435 {"Speaker Mix", "PHONE2SPK Playback Switch", "Phone Mix"},
436 {"Speaker Mix", "MIC12SPK Playback Switch", "MIC1 PGA"},
437 {"Speaker Mix", "MIC22SPK Playback Switch", "MIC2 PGA"},
438 {"Speaker Mix", "DAC2SPK Playback Switch", "DAC Left Channel"},
443 {"Mono Mix", "ADC2MONO_L Playback Switch", "Left Capture Mix"},
444 {"Mono Mix", "ADC2MONO_R Playback Switch", "Right Capture Mix"},
445 {"Mono Mix", "LI2MONO Playback Switch", "Line Mix"},
446 {"Mono Mix", "VOICE2MONO Playback Switch", "Phone Mix"},
447 {"Mono Mix", "MIC12MONO Playback Switch", "MIC1 PGA"},
448 {"Mono Mix", "MIC22MONO Playback Switch", "MIC2 PGA"},
449 {"Mono Mix", "DAC2MONO Playback Switch", "DAC Left Channel"},
451 /* Left record mixer */
452 {"Left Capture Mix", "LineInL Capture Switch", "LINEINL"},
453 {"Left Capture Mix", "Left Phone Capture Switch", "PHONEN"},
454 {"Left Capture Mix", "Mic1 Capture Switch", "MIC1 Pre Amp"},
455 {"Left Capture Mix", "Mic2 Capture Switch", "MIC2 Pre Amp"},
456 {"Left Capture Mix", "HPMixerL Capture Switch", "HPL Mix"},
457 {"Left Capture Mix", "SPKMixer Capture Switch", "Speaker Mix"},
458 {"Left Capture Mix", "MonoMixer Capture Switch", "Mono Mix"},
460 /*Right record mixer */
461 {"Right Capture Mix", "LineInR Capture Switch", "LINEINR"},
462 {"Right Capture Mix", "Right Phone Capture Switch", "PHONEP"},
463 {"Right Capture Mix", "Mic1 Capture Switch", "MIC1 Pre Amp"},
464 {"Right Capture Mix", "Mic2 Capture Switch", "MIC2 Pre Amp"},
465 {"Right Capture Mix", "HPMixerR Capture Switch", "HPR Mix"},
466 {"Right Capture Mix", "SPKMixer Capture Switch", "Speaker Mix"},
467 {"Right Capture Mix", "MonoMixer Capture Switch", "Mono Mix"},
469 /* headphone left mux */
470 {"Left Headphone Mux", "HP Left Mix", "HPL Mix"},
471 {"Left Headphone Mux", "Vmid", "Vmid"},
473 /* headphone right mux */
474 {"Right Headphone Mux", "HP Right Mix", "HPR Mix"},
475 {"Right Headphone Mux", "Vmid", "Vmid"},
477 /* speaker out mux */
478 {"SpeakerOut Mux", "Vmid", "Vmid"},
479 {"SpeakerOut Mux", "HPOut Mix", "HPOut Mix"},
480 {"SpeakerOut Mux", "Speaker Mix", "Speaker Mix"},
481 {"SpeakerOut Mux", "Mono Mix", "Mono Mix"},
483 /* Mono/Aux Out mux */
484 {"AuxOut Mux", "Vmid", "Vmid"},
485 {"AuxOut Mux", "HPOut Mix", "HPOut Mix"},
486 {"AuxOut Mux", "Speaker Mix", "Speaker Mix"},
487 {"AuxOut Mux", "Mono Mix", "Mono Mix"},
490 {"HPL", NULL
, "Left Headphone"},
491 {"Left Headphone", NULL
, "Left Headphone Mux"},
492 {"HPR", NULL
, "Right Headphone"},
493 {"Right Headphone", NULL
, "Right Headphone Mux"},
494 {"Aux Out", NULL
, "AuxOut Mux"},
497 {"Left LineIn", NULL
, "LINEINL"},
498 {"Right LineIn", NULL
, "LINEINR"},
499 {"Phone", NULL
, "PHONEP"},
500 {"MIC1 Pre Amp", NULL
, "MIC1"},
501 {"MIC2 Pre Amp", NULL
, "MIC2"},
502 {"MIC1 PGA", NULL
, "MIC1 Pre Amp"},
503 {"MIC2 PGA", NULL
, "MIC2 Pre Amp"},
506 {"Left ADC", NULL
, "Left Capture Mix"},
509 {"Right ADC", NULL
, "Right Capture Mix"},
511 {"SpeakerOut N Mux", "RN/-R", "Left Speaker"},
512 {"SpeakerOut N Mux", "RP/+R", "Left Speaker"},
513 {"SpeakerOut N Mux", "LN/-R", "Left Speaker"},
514 {"SpeakerOut N Mux", "Mute", "Vmid"},
516 {"SpeakerOut N Mux", "RN/-R", "Right Speaker"},
517 {"SpeakerOut N Mux", "RP/+R", "Right Speaker"},
518 {"SpeakerOut N Mux", "LN/-R", "Right Speaker"},
519 {"SpeakerOut N Mux", "Mute", "Vmid"},
521 {"AB Amp", NULL
, "SpeakerOut Mux"},
522 {"D Amp", NULL
, "SpeakerOut Mux"},
523 {"AB-D Amp Mux", "AB Amp", "AB Amp"},
524 {"AB-D Amp Mux", "D Amp", "D Amp"},
525 {"Left Speaker", NULL
, "AB-D Amp Mux"},
526 {"Right Speaker", NULL
, "AB-D Amp Mux"},
528 {"SPKOUT", NULL
, "Left Speaker"},
529 {"SPKOUT", NULL
, "Right Speaker"},
531 {"SPKOUTN", NULL
, "SpeakerOut N Mux"},
542 /* Note : pll code from original alc5632 driver. Not sure of how good it is */
543 /* usefull only for master mode */
544 static const struct _pll_div codec_master_pll_div
[] = {
546 { 2048000, 8192000, 0x0ea0},
547 { 3686400, 8192000, 0x4e27},
548 { 12000000, 8192000, 0x456b},
549 { 13000000, 8192000, 0x495f},
550 { 13100000, 8192000, 0x0320},
551 { 2048000, 11289600, 0xf637},
552 { 3686400, 11289600, 0x2f22},
553 { 12000000, 11289600, 0x3e2f},
554 { 13000000, 11289600, 0x4d5b},
555 { 13100000, 11289600, 0x363b},
556 { 2048000, 16384000, 0x1ea0},
557 { 3686400, 16384000, 0x9e27},
558 { 12000000, 16384000, 0x452b},
559 { 13000000, 16384000, 0x542f},
560 { 13100000, 16384000, 0x03a0},
561 { 2048000, 16934400, 0xe625},
562 { 3686400, 16934400, 0x9126},
563 { 12000000, 16934400, 0x4d2c},
564 { 13000000, 16934400, 0x742f},
565 { 13100000, 16934400, 0x3c27},
566 { 2048000, 22579200, 0x2aa0},
567 { 3686400, 22579200, 0x2f20},
568 { 12000000, 22579200, 0x7e2f},
569 { 13000000, 22579200, 0x742f},
570 { 13100000, 22579200, 0x3c27},
571 { 2048000, 24576000, 0x2ea0},
572 { 3686400, 24576000, 0xee27},
573 { 12000000, 24576000, 0x2915},
574 { 13000000, 24576000, 0x772e},
575 { 13100000, 24576000, 0x0d20},
578 /* FOUT = MCLK*(N+2)/((M+2)*(K+2))
579 N: bit 15:8 (div 2 .. div 257)
581 M: bit 3:0 (div 2 .. div 17)
583 same as for 5623 - thanks!
586 static const struct _pll_div codec_slave_pll_div
[] = {
588 { 1024000, 16384000, 0x3ea0},
589 { 1411200, 22579200, 0x3ea0},
590 { 1536000, 24576000, 0x3ea0},
591 { 2048000, 16384000, 0x1ea0},
592 { 2822400, 22579200, 0x1ea0},
593 { 3072000, 24576000, 0x1ea0},
597 static int alc5632_set_dai_pll(struct snd_soc_dai
*codec_dai
, int pll_id
,
598 int source
, unsigned int freq_in
, unsigned int freq_out
)
601 struct snd_soc_codec
*codec
= codec_dai
->codec
;
602 int gbl_clk
= 0, pll_div
= 0;
605 if (pll_id
< ALC5632_PLL_FR_MCLK
|| pll_id
> ALC5632_PLL_FR_VBCLK
)
608 /* Disable PLL power */
609 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
610 ALC5632_PWR_ADD2_PLL1
,
612 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
613 ALC5632_PWR_ADD2_PLL2
,
616 /* pll is not used in slave mode */
617 reg
= snd_soc_read(codec
, ALC5632_DAI_CONTROL
);
618 if (reg
& ALC5632_DAI_SDP_SLAVE_MODE
)
621 if (!freq_in
|| !freq_out
)
625 case ALC5632_PLL_FR_MCLK
:
626 for (i
= 0; i
< ARRAY_SIZE(codec_master_pll_div
); i
++) {
627 if (codec_master_pll_div
[i
].pll_in
== freq_in
628 && codec_master_pll_div
[i
].pll_out
== freq_out
) {
629 /* PLL source from MCLK */
630 pll_div
= codec_master_pll_div
[i
].regvalue
;
635 case ALC5632_PLL_FR_BCLK
:
636 for (i
= 0; i
< ARRAY_SIZE(codec_slave_pll_div
); i
++) {
637 if (codec_slave_pll_div
[i
].pll_in
== freq_in
638 && codec_slave_pll_div
[i
].pll_out
== freq_out
) {
639 /* PLL source from Bitclk */
640 gbl_clk
= ALC5632_PLL_FR_BCLK
;
641 pll_div
= codec_slave_pll_div
[i
].regvalue
;
646 case ALC5632_PLL_FR_VBCLK
:
647 for (i
= 0; i
< ARRAY_SIZE(codec_slave_pll_div
); i
++) {
648 if (codec_slave_pll_div
[i
].pll_in
== freq_in
649 && codec_slave_pll_div
[i
].pll_out
== freq_out
) {
650 /* PLL source from voice clock */
651 gbl_clk
= ALC5632_PLL_FR_VBCLK
;
652 pll_div
= codec_slave_pll_div
[i
].regvalue
;
664 /* choose MCLK/BCLK/VBCLK */
665 snd_soc_write(codec
, ALC5632_GPCR2
, gbl_clk
);
666 /* choose PLL1 clock rate */
667 snd_soc_write(codec
, ALC5632_PLL1_CTRL
, pll_div
);
669 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
670 ALC5632_PWR_ADD2_PLL1
,
671 ALC5632_PWR_ADD2_PLL1
);
673 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
674 ALC5632_PWR_ADD2_PLL2
,
675 ALC5632_PWR_ADD2_PLL2
);
676 /* use PLL1 as main SYSCLK */
677 snd_soc_update_bits(codec
, ALC5632_GPCR1
,
678 ALC5632_GPCR1_CLK_SYS_SRC_SEL_PLL1
,
679 ALC5632_GPCR1_CLK_SYS_SRC_SEL_PLL1
);
689 /* codec hifi mclk (after PLL) clock divider coefficients */
690 /* values inspired from column BCLK=32Fs of Appendix A table */
691 static const struct _coeff_div coeff_div
[] = {
695 static int get_coeff(struct snd_soc_codec
*codec
, int rate
)
697 struct alc5632_priv
*alc5632
= snd_soc_codec_get_drvdata(codec
);
700 for (i
= 0; i
< ARRAY_SIZE(coeff_div
); i
++) {
701 if (coeff_div
[i
].fs
* rate
== alc5632
->sysclk
)
708 * Clock after PLL and dividers
710 static int alc5632_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
711 int clk_id
, unsigned int freq
, int dir
)
713 struct snd_soc_codec
*codec
= codec_dai
->codec
;
714 struct alc5632_priv
*alc5632
= snd_soc_codec_get_drvdata(codec
);
725 alc5632
->sysclk
= freq
;
731 static int alc5632_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
734 struct snd_soc_codec
*codec
= codec_dai
->codec
;
737 /* set master/slave audio interface */
738 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
739 case SND_SOC_DAIFMT_CBM_CFM
:
740 iface
= ALC5632_DAI_SDP_MASTER_MODE
;
742 case SND_SOC_DAIFMT_CBS_CFS
:
743 iface
= ALC5632_DAI_SDP_SLAVE_MODE
;
749 /* interface format */
750 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
751 case SND_SOC_DAIFMT_I2S
:
752 iface
|= ALC5632_DAI_I2S_DF_I2S
;
754 case SND_SOC_DAIFMT_LEFT_J
:
755 iface
|= ALC5632_DAI_I2S_DF_LEFT
;
757 case SND_SOC_DAIFMT_DSP_A
:
758 iface
|= ALC5632_DAI_I2S_DF_PCM_A
;
760 case SND_SOC_DAIFMT_DSP_B
:
761 iface
|= ALC5632_DAI_I2S_DF_PCM_B
;
767 /* clock inversion */
768 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
769 case SND_SOC_DAIFMT_NB_NF
:
771 case SND_SOC_DAIFMT_IB_IF
:
772 iface
|= ALC5632_DAI_MAIN_I2S_BCLK_POL_CTRL
;
774 case SND_SOC_DAIFMT_IB_NF
:
775 iface
|= ALC5632_DAI_MAIN_I2S_BCLK_POL_CTRL
;
777 case SND_SOC_DAIFMT_NB_IF
:
783 return snd_soc_write(codec
, ALC5632_DAI_CONTROL
, iface
);
786 static int alc5632_pcm_hw_params(struct snd_pcm_substream
*substream
,
787 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
789 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
790 struct snd_soc_codec
*codec
= rtd
->codec
;
794 iface
= snd_soc_read(codec
, ALC5632_DAI_CONTROL
);
795 iface
&= ~ALC5632_DAI_I2S_DL_MASK
;
798 switch (params_format(params
)) {
799 case SNDRV_PCM_FORMAT_S16_LE
:
800 iface
|= ALC5632_DAI_I2S_DL_16
;
802 case SNDRV_PCM_FORMAT_S20_3LE
:
803 iface
|= ALC5632_DAI_I2S_DL_20
;
805 case SNDRV_PCM_FORMAT_S24_LE
:
806 iface
|= ALC5632_DAI_I2S_DL_24
;
812 /* set iface & srate */
813 snd_soc_write(codec
, ALC5632_DAI_CONTROL
, iface
);
814 rate
= params_rate(params
);
815 coeff
= get_coeff(codec
, rate
);
819 coeff
= coeff_div
[coeff
].regvalue
;
820 snd_soc_write(codec
, ALC5632_DAC_CLK_CTRL1
, coeff
);
825 static int alc5632_mute(struct snd_soc_dai
*dai
, int mute
)
827 struct snd_soc_codec
*codec
= dai
->codec
;
828 u16 hp_mute
= ALC5632_MISC_HP_DEPOP_MUTE_L
829 |ALC5632_MISC_HP_DEPOP_MUTE_R
;
830 u16 mute_reg
= snd_soc_read(codec
, ALC5632_MISC_CTRL
) & ~hp_mute
;
835 return snd_soc_write(codec
, ALC5632_MISC_CTRL
, mute_reg
);
838 #define ALC5632_ADD2_POWER_EN (ALC5632_PWR_ADD2_VREF)
840 #define ALC5632_ADD3_POWER_EN (ALC5632_PWR_ADD3_MIC1_BOOST_AD)
842 #define ALC5632_ADD1_POWER_EN \
843 (ALC5632_PWR_ADD1_DAC_REF \
844 | ALC5632_PWR_ADD1_SOFTGEN_EN \
845 | ALC5632_PWR_ADD1_HP_OUT_AMP \
846 | ALC5632_PWR_ADD1_HP_OUT_ENH_AMP \
847 | ALC5632_PWR_ADD1_MAIN_BIAS)
849 static void enable_power_depop(struct snd_soc_codec
*codec
)
851 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD1
,
852 ALC5632_PWR_ADD1_SOFTGEN_EN
,
853 ALC5632_PWR_ADD1_SOFTGEN_EN
);
855 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD3
,
856 ALC5632_ADD3_POWER_EN
,
857 ALC5632_ADD3_POWER_EN
);
859 snd_soc_update_bits(codec
, ALC5632_MISC_CTRL
,
860 ALC5632_MISC_HP_DEPOP_MODE2_EN
,
861 ALC5632_MISC_HP_DEPOP_MODE2_EN
);
863 /* "normal" mode: 0 @ 26 */
864 /* set all PR0-7 mixers to 0 */
865 snd_soc_update_bits(codec
, ALC5632_PWR_DOWN_CTRL_STATUS
,
866 ALC5632_PWR_DOWN_CTRL_STATUS_MASK
,
871 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
872 ALC5632_ADD2_POWER_EN
,
873 ALC5632_ADD2_POWER_EN
);
875 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD1
,
876 ALC5632_ADD1_POWER_EN
,
877 ALC5632_ADD1_POWER_EN
);
879 /* disable HP Depop2 */
880 snd_soc_update_bits(codec
, ALC5632_MISC_CTRL
,
881 ALC5632_MISC_HP_DEPOP_MODE2_EN
,
886 static int alc5632_set_bias_level(struct snd_soc_codec
*codec
,
887 enum snd_soc_bias_level level
)
890 case SND_SOC_BIAS_ON
:
891 enable_power_depop(codec
);
893 case SND_SOC_BIAS_PREPARE
:
895 case SND_SOC_BIAS_STANDBY
:
896 /* everything off except vref/vmid, */
897 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD1
,
898 ALC5632_PWR_MANAG_ADD1_MASK
,
899 ALC5632_PWR_ADD1_MAIN_BIAS
);
900 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
901 ALC5632_PWR_MANAG_ADD2_MASK
,
902 ALC5632_PWR_ADD2_VREF
);
903 /* "normal" mode: 0 @ 26 */
904 snd_soc_update_bits(codec
, ALC5632_PWR_DOWN_CTRL_STATUS
,
905 ALC5632_PWR_DOWN_CTRL_STATUS_MASK
,
906 0xffff ^ (ALC5632_PWR_VREF_PR3
907 | ALC5632_PWR_VREF_PR2
));
909 case SND_SOC_BIAS_OFF
:
910 /* everything off, dac mute, inactive */
911 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
912 ALC5632_PWR_MANAG_ADD2_MASK
, 0);
913 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD3
,
914 ALC5632_PWR_MANAG_ADD3_MASK
, 0);
915 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD1
,
916 ALC5632_PWR_MANAG_ADD1_MASK
, 0);
919 codec
->dapm
.bias_level
= level
;
923 #define ALC5632_FORMATS (SNDRV_PCM_FMTBIT_S16_LE \
924 | SNDRV_PCM_FMTBIT_S24_LE \
925 | SNDRV_PCM_FMTBIT_S32_LE)
927 static const struct snd_soc_dai_ops alc5632_dai_ops
= {
928 .hw_params
= alc5632_pcm_hw_params
,
929 .digital_mute
= alc5632_mute
,
930 .set_fmt
= alc5632_set_dai_fmt
,
931 .set_sysclk
= alc5632_set_dai_sysclk
,
932 .set_pll
= alc5632_set_dai_pll
,
935 static struct snd_soc_dai_driver alc5632_dai
= {
936 .name
= "alc5632-hifi",
938 .stream_name
= "HiFi Playback",
943 .rates
= SNDRV_PCM_RATE_8000_48000
,
944 .formats
= ALC5632_FORMATS
,},
946 .stream_name
= "HiFi Capture",
951 .rates
= SNDRV_PCM_RATE_8000_48000
,
952 .formats
= ALC5632_FORMATS
,},
954 .ops
= &alc5632_dai_ops
,
955 .symmetric_rates
= 1,
959 static int alc5632_suspend(struct snd_soc_codec
*codec
)
961 alc5632_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
965 static int alc5632_resume(struct snd_soc_codec
*codec
)
967 struct alc5632_priv
*alc5632
= snd_soc_codec_get_drvdata(codec
);
969 regcache_sync(alc5632
->regmap
);
971 alc5632_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
975 #define alc5632_suspend NULL
976 #define alc5632_resume NULL
979 static int alc5632_probe(struct snd_soc_codec
*codec
)
981 struct alc5632_priv
*alc5632
= snd_soc_codec_get_drvdata(codec
);
984 codec
->control_data
= alc5632
->regmap
;
986 ret
= snd_soc_codec_set_cache_io(codec
, 8, 16, SND_SOC_REGMAP
);
988 dev_err(codec
->dev
, "Failed to set cache I/O: %d\n", ret
);
992 /* power on device */
993 alc5632_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
995 switch (alc5632
->id
) {
997 snd_soc_add_controls(codec
, alc5632_vol_snd_controls
,
998 ARRAY_SIZE(alc5632_vol_snd_controls
));
1007 /* power down chip */
1008 static int alc5632_remove(struct snd_soc_codec
*codec
)
1010 alc5632_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
1014 static struct snd_soc_codec_driver soc_codec_device_alc5632
= {
1015 .probe
= alc5632_probe
,
1016 .remove
= alc5632_remove
,
1017 .suspend
= alc5632_suspend
,
1018 .resume
= alc5632_resume
,
1019 .set_bias_level
= alc5632_set_bias_level
,
1020 .controls
= alc5632_snd_controls
,
1021 .num_controls
= ARRAY_SIZE(alc5632_snd_controls
),
1022 .dapm_widgets
= alc5632_dapm_widgets
,
1023 .num_dapm_widgets
= ARRAY_SIZE(alc5632_dapm_widgets
),
1024 .dapm_routes
= alc5632_dapm_routes
,
1025 .num_dapm_routes
= ARRAY_SIZE(alc5632_dapm_routes
),
1028 static struct regmap_config alc5632_regmap
= {
1032 .max_register
= ALC5632_MAX_REGISTER
,
1033 .reg_defaults
= alc5632_reg_defaults
,
1034 .num_reg_defaults
= ARRAY_SIZE(alc5632_reg_defaults
),
1035 .volatile_reg
= alc5632_volatile_register
,
1036 .cache_type
= REGCACHE_RBTREE
,
1040 * alc5632 2 wire address is determined by A1 pin
1041 * state during powerup.
1045 static __devinit
int alc5632_i2c_probe(struct i2c_client
*client
,
1046 const struct i2c_device_id
*id
)
1048 struct alc5632_priv
*alc5632
;
1049 int ret
, ret1
, ret2
;
1050 unsigned int vid1
, vid2
;
1052 alc5632
= devm_kzalloc(&client
->dev
,
1053 sizeof(struct alc5632_priv
), GFP_KERNEL
);
1054 if (alc5632
== NULL
)
1057 i2c_set_clientdata(client
, alc5632
);
1059 alc5632
->regmap
= regmap_init_i2c(client
, &alc5632_regmap
);
1060 if (IS_ERR(alc5632
->regmap
)) {
1061 ret
= PTR_ERR(alc5632
->regmap
);
1062 dev_err(&client
->dev
, "regmap_init() failed: %d\n", ret
);
1066 ret1
= regmap_read(alc5632
->regmap
, ALC5632_VENDOR_ID1
, &vid1
);
1067 ret2
= regmap_read(alc5632
->regmap
, ALC5632_VENDOR_ID2
, &vid2
);
1068 if (ret1
!= 0 || ret2
!= 0) {
1069 dev_err(&client
->dev
,
1070 "Failed to read chip ID: ret1=%d, ret2=%d\n", ret1
, ret2
);
1071 regmap_exit(alc5632
->regmap
);
1077 if ((vid1
!= 0x10EC) || (vid2
!= id
->driver_data
)) {
1078 dev_err(&client
->dev
,
1079 "Device is not a ALC5632: VID1=0x%x, VID2=0x%x\n", vid1
, vid2
);
1080 regmap_exit(alc5632
->regmap
);
1084 ret
= alc5632_reset(alc5632
->regmap
);
1086 dev_err(&client
->dev
, "Failed to issue reset\n");
1087 regmap_exit(alc5632
->regmap
);
1092 switch (alc5632
->id
) {
1094 alc5632_dai
.name
= "alc5632-hifi";
1100 ret
= snd_soc_register_codec(&client
->dev
,
1101 &soc_codec_device_alc5632
, &alc5632_dai
, 1);
1104 dev_err(&client
->dev
, "Failed to register codec: %d\n", ret
);
1105 regmap_exit(alc5632
->regmap
);
1112 static int alc5632_i2c_remove(struct i2c_client
*client
)
1114 struct alc5632_priv
*alc5632
= i2c_get_clientdata(client
);
1115 snd_soc_unregister_codec(&client
->dev
);
1116 regmap_exit(alc5632
->regmap
);
1120 static const struct i2c_device_id alc5632_i2c_table
[] = {
1124 MODULE_DEVICE_TABLE(i2c
, alc5632_i2c_table
);
1126 /* i2c codec control layer */
1127 static struct i2c_driver alc5632_i2c_driver
= {
1130 .owner
= THIS_MODULE
,
1132 .probe
= alc5632_i2c_probe
,
1133 .remove
= __devexit_p(alc5632_i2c_remove
),
1134 .id_table
= alc5632_i2c_table
,
1137 static int __init
alc5632_modinit(void)
1141 ret
= i2c_add_driver(&alc5632_i2c_driver
);
1143 printk(KERN_ERR
"%s: can't add i2c driver", __func__
);
1149 module_init(alc5632_modinit
);
1151 static void __exit
alc5632_modexit(void)
1153 i2c_del_driver(&alc5632_i2c_driver
);
1155 module_exit(alc5632_modexit
);
1157 MODULE_DESCRIPTION("ASoC ALC5632 driver");
1158 MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>");
1159 MODULE_LICENSE("GPL");