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 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
121 /* to power-on/off class-d amp generators/speaker */
122 /* need to write to 'index-46h' register : */
123 /* so write index num (here 0x46) to reg 0x6a */
124 /* and then 0xffff/0 to reg 0x6c */
125 snd_soc_write(codec
, ALC5632_HID_CTRL_INDEX
, 0x46);
128 case SND_SOC_DAPM_PRE_PMU
:
129 snd_soc_write(codec
, ALC5632_HID_CTRL_DATA
, 0xFFFF);
131 case SND_SOC_DAPM_POST_PMD
:
132 snd_soc_write(codec
, ALC5632_HID_CTRL_DATA
, 0);
143 /* -34.5db min scale, 1.5db steps, no mute */
144 static const DECLARE_TLV_DB_SCALE(vol_tlv
, -3450, 150, 0);
145 /* -46.5db min scale, 1.5db steps, no mute */
146 static const DECLARE_TLV_DB_SCALE(hp_tlv
, -4650, 150, 0);
147 /* -16.5db min scale, 1.5db steps, no mute */
148 static const DECLARE_TLV_DB_SCALE(adc_rec_tlv
, -1650, 150, 0);
149 static const unsigned int boost_tlv
[] = {
150 TLV_DB_RANGE_HEAD(2),
151 0, 1, TLV_DB_SCALE_ITEM(0, 2000, 0),
152 1, 3, TLV_DB_SCALE_ITEM(2000, 1000, 0),
154 /* 0db min scale, 6 db steps, no mute */
155 static const DECLARE_TLV_DB_SCALE(dig_tlv
, 0, 600, 0);
156 /* 0db min scalem 0.75db steps, no mute */
157 static const DECLARE_TLV_DB_SCALE(vdac_tlv
, -3525, 75, 0);
159 static const struct snd_kcontrol_new alc5632_vol_snd_controls
[] = {
160 /* left starts at bit 8, right at bit 0 */
161 /* 31 steps (5 bit), -46.5db scale */
162 SOC_DOUBLE_TLV("Speaker Playback Volume",
163 ALC5632_SPK_OUT_VOL
, 8, 0, 31, 1, hp_tlv
),
164 /* bit 15 mutes left, bit 7 right */
165 SOC_DOUBLE("Speaker Playback Switch",
166 ALC5632_SPK_OUT_VOL
, 15, 7, 1, 1),
167 SOC_DOUBLE_TLV("Headphone Playback Volume",
168 ALC5632_HP_OUT_VOL
, 8, 0, 31, 1, hp_tlv
),
169 SOC_DOUBLE("Headphone Playback Switch",
170 ALC5632_HP_OUT_VOL
, 15, 7, 1, 1),
173 static const struct snd_kcontrol_new alc5632_snd_controls
[] = {
174 SOC_DOUBLE_TLV("Auxout Playback Volume",
175 ALC5632_AUX_OUT_VOL
, 8, 0, 31, 1, hp_tlv
),
176 SOC_DOUBLE("Auxout Playback Switch",
177 ALC5632_AUX_OUT_VOL
, 15, 7, 1, 1),
178 SOC_SINGLE_TLV("Voice DAC Playback Volume",
179 ALC5632_VOICE_DAC_VOL
, 0, 63, 0, vdac_tlv
),
180 SOC_SINGLE("Voice DAC Playback Switch",
181 ALC5632_VOICE_DAC_VOL
, 12, 1, 1),
182 SOC_SINGLE_TLV("Phone Playback Volume",
183 ALC5632_PHONE_IN_VOL
, 8, 31, 1, vol_tlv
),
184 SOC_DOUBLE_TLV("LineIn Playback Volume",
185 ALC5632_LINE_IN_VOL
, 8, 0, 31, 1, vol_tlv
),
186 SOC_DOUBLE_TLV("Master Playback Volume",
187 ALC5632_STEREO_DAC_IN_VOL
, 8, 0, 63, 1, vdac_tlv
),
188 SOC_DOUBLE("Master Playback Switch",
189 ALC5632_STEREO_DAC_IN_VOL
, 15, 7, 1, 1),
190 SOC_SINGLE_TLV("Mic1 Playback Volume",
191 ALC5632_MIC_VOL
, 8, 31, 1, vol_tlv
),
192 SOC_SINGLE_TLV("Mic2 Playback Volume",
193 ALC5632_MIC_VOL
, 0, 31, 1, vol_tlv
),
194 SOC_DOUBLE_TLV("Rec Capture Volume",
195 ALC5632_ADC_REC_GAIN
, 8, 0, 31, 0, adc_rec_tlv
),
196 SOC_SINGLE_TLV("Mic 1 Boost Volume",
197 ALC5632_MIC_CTRL
, 10, 3, 0, boost_tlv
),
198 SOC_SINGLE_TLV("Mic 2 Boost Volume",
199 ALC5632_MIC_CTRL
, 8, 3, 0, boost_tlv
),
200 SOC_SINGLE_TLV("DMIC Boost Capture Volume",
201 ALC5632_DIGI_BOOST_CTRL
, 0, 7, 0, dig_tlv
),
202 SOC_SINGLE("DMIC En Capture Switch",
203 ALC5632_DIGI_BOOST_CTRL
, 15, 1, 0),
204 SOC_SINGLE("DMIC PreFilter Capture Switch",
205 ALC5632_DIGI_BOOST_CTRL
, 12, 1, 0),
211 static const struct snd_kcontrol_new alc5632_hp_mixer_controls
[] = {
212 SOC_DAPM_SINGLE("LI2HP Playback Switch", ALC5632_LINE_IN_VOL
, 15, 1, 1),
213 SOC_DAPM_SINGLE("PHONE2HP Playback Switch", ALC5632_PHONE_IN_VOL
, 15, 1, 1),
214 SOC_DAPM_SINGLE("MIC12HP Playback Switch", ALC5632_MIC_ROUTING_CTRL
, 15, 1, 1),
215 SOC_DAPM_SINGLE("MIC22HP Playback Switch", ALC5632_MIC_ROUTING_CTRL
, 11, 1, 1),
216 SOC_DAPM_SINGLE("VOICE2HP Playback Switch", ALC5632_VOICE_DAC_VOL
, 15, 1, 1),
219 static const struct snd_kcontrol_new alc5632_hpl_mixer_controls
[] = {
220 SOC_DAPM_SINGLE("ADC2HP_L Playback Switch", ALC5632_ADC_REC_GAIN
, 15, 1, 1),
221 SOC_DAPM_SINGLE("DACL2HP Playback Switch", ALC5632_MIC_ROUTING_CTRL
, 3, 1, 1),
224 static const struct snd_kcontrol_new alc5632_hpr_mixer_controls
[] = {
225 SOC_DAPM_SINGLE("ADC2HP_R Playback Switch", ALC5632_ADC_REC_GAIN
, 7, 1, 1),
226 SOC_DAPM_SINGLE("DACR2HP Playback Switch", ALC5632_MIC_ROUTING_CTRL
, 2, 1, 1),
229 static const struct snd_kcontrol_new alc5632_mono_mixer_controls
[] = {
230 SOC_DAPM_SINGLE("ADC2MONO_L Playback Switch", ALC5632_ADC_REC_GAIN
, 14, 1, 1),
231 SOC_DAPM_SINGLE("ADC2MONO_R Playback Switch", ALC5632_ADC_REC_GAIN
, 6, 1, 1),
232 SOC_DAPM_SINGLE("LI2MONO Playback Switch", ALC5632_LINE_IN_VOL
, 13, 1, 1),
233 SOC_DAPM_SINGLE("MIC12MONO Playback Switch",
234 ALC5632_MIC_ROUTING_CTRL
, 13, 1, 1),
235 SOC_DAPM_SINGLE("MIC22MONO Playback Switch",
236 ALC5632_MIC_ROUTING_CTRL
, 9, 1, 1),
237 SOC_DAPM_SINGLE("DAC2MONO Playback Switch", ALC5632_MIC_ROUTING_CTRL
, 0, 1, 1),
238 SOC_DAPM_SINGLE("VOICE2MONO Playback Switch", ALC5632_VOICE_DAC_VOL
, 13, 1, 1),
241 static const struct snd_kcontrol_new alc5632_speaker_mixer_controls
[] = {
242 SOC_DAPM_SINGLE("LI2SPK Playback Switch", ALC5632_LINE_IN_VOL
, 14, 1, 1),
243 SOC_DAPM_SINGLE("PHONE2SPK Playback Switch", ALC5632_PHONE_IN_VOL
, 14, 1, 1),
244 SOC_DAPM_SINGLE("MIC12SPK Playback Switch",
245 ALC5632_MIC_ROUTING_CTRL
, 14, 1, 1),
246 SOC_DAPM_SINGLE("MIC22SPK Playback Switch",
247 ALC5632_MIC_ROUTING_CTRL
, 10, 1, 1),
248 SOC_DAPM_SINGLE("DAC2SPK Playback Switch", ALC5632_MIC_ROUTING_CTRL
, 1, 1, 1),
249 SOC_DAPM_SINGLE("VOICE2SPK Playback Switch", ALC5632_VOICE_DAC_VOL
, 14, 1, 1),
252 /* Left Record Mixer */
253 static const struct snd_kcontrol_new alc5632_captureL_mixer_controls
[] = {
254 SOC_DAPM_SINGLE("MIC12REC_L Capture Switch", ALC5632_ADC_REC_MIXER
, 14, 1, 1),
255 SOC_DAPM_SINGLE("MIC22REC_L Capture Switch", ALC5632_ADC_REC_MIXER
, 13, 1, 1),
256 SOC_DAPM_SINGLE("LIL2REC Capture Switch", ALC5632_ADC_REC_MIXER
, 12, 1, 1),
257 SOC_DAPM_SINGLE("PH2REC_L Capture Switch", ALC5632_ADC_REC_MIXER
, 11, 1, 1),
258 SOC_DAPM_SINGLE("HPL2REC Capture Switch", ALC5632_ADC_REC_MIXER
, 10, 1, 1),
259 SOC_DAPM_SINGLE("SPK2REC_L Capture Switch", ALC5632_ADC_REC_MIXER
, 9, 1, 1),
260 SOC_DAPM_SINGLE("MONO2REC_L Capture Switch", ALC5632_ADC_REC_MIXER
, 8, 1, 1),
263 /* Right Record Mixer */
264 static const struct snd_kcontrol_new alc5632_captureR_mixer_controls
[] = {
265 SOC_DAPM_SINGLE("MIC12REC_R Capture Switch", ALC5632_ADC_REC_MIXER
, 6, 1, 1),
266 SOC_DAPM_SINGLE("MIC22REC_R Capture Switch", ALC5632_ADC_REC_MIXER
, 5, 1, 1),
267 SOC_DAPM_SINGLE("LIR2REC Capture Switch", ALC5632_ADC_REC_MIXER
, 4, 1, 1),
268 SOC_DAPM_SINGLE("PH2REC_R Capture Switch", ALC5632_ADC_REC_MIXER
, 3, 1, 1),
269 SOC_DAPM_SINGLE("HPR2REC Capture Switch", ALC5632_ADC_REC_MIXER
, 2, 1, 1),
270 SOC_DAPM_SINGLE("SPK2REC_R Capture Switch", ALC5632_ADC_REC_MIXER
, 1, 1, 1),
271 SOC_DAPM_SINGLE("MONO2REC_R Capture Switch", ALC5632_ADC_REC_MIXER
, 0, 1, 1),
275 static const struct snd_kcontrol_new alc5632_dmicl_mixer_controls
[] = {
276 SOC_DAPM_SINGLE("DMICL2ADC Capture Switch", ALC5632_DIGI_BOOST_CTRL
, 7, 1, 1),
278 static const struct snd_kcontrol_new alc5632_dmicr_mixer_controls
[] = {
279 SOC_DAPM_SINGLE("DMICR2ADC Capture Switch", ALC5632_DIGI_BOOST_CTRL
, 6, 1, 1),
282 static const char * const alc5632_spk_n_sour_sel
[] = {
283 "RN/-R", "RP/+R", "LN/-R", "Mute"};
284 static const char * const alc5632_hpl_out_input_sel
[] = {
285 "Vmid", "HP Left Mix"};
286 static const char * const alc5632_hpr_out_input_sel
[] = {
287 "Vmid", "HP Right Mix"};
288 static const char * const alc5632_spkout_input_sel
[] = {
289 "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
290 static const char * const alc5632_aux_out_input_sel
[] = {
291 "Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"};
292 static const char * const alc5632_adcr_func_sel
[] = {
293 "Stereo ADC", "Voice ADC"};
294 static const char * const alc5632_i2s_out_sel
[] = {
295 "ADC LR", "Voice Stereo Digital"};
297 /* auxout output mux */
298 static SOC_ENUM_SINGLE_DECL(alc5632_aux_out_input_enum
,
299 ALC5632_OUTPUT_MIXER_CTRL
, 6,
300 alc5632_aux_out_input_sel
);
301 static const struct snd_kcontrol_new alc5632_auxout_mux_controls
=
302 SOC_DAPM_ENUM("AuxOut Mux", alc5632_aux_out_input_enum
);
304 /* speaker output mux */
305 static SOC_ENUM_SINGLE_DECL(alc5632_spkout_input_enum
,
306 ALC5632_OUTPUT_MIXER_CTRL
, 10,
307 alc5632_spkout_input_sel
);
308 static const struct snd_kcontrol_new alc5632_spkout_mux_controls
=
309 SOC_DAPM_ENUM("SpeakerOut Mux", alc5632_spkout_input_enum
);
311 /* headphone left output mux */
312 static SOC_ENUM_SINGLE_DECL(alc5632_hpl_out_input_enum
,
313 ALC5632_OUTPUT_MIXER_CTRL
, 9,
314 alc5632_hpl_out_input_sel
);
315 static const struct snd_kcontrol_new alc5632_hpl_out_mux_controls
=
316 SOC_DAPM_ENUM("Left Headphone Mux", alc5632_hpl_out_input_enum
);
318 /* headphone right output mux */
319 static SOC_ENUM_SINGLE_DECL(alc5632_hpr_out_input_enum
,
320 ALC5632_OUTPUT_MIXER_CTRL
, 8,
321 alc5632_hpr_out_input_sel
);
322 static const struct snd_kcontrol_new alc5632_hpr_out_mux_controls
=
323 SOC_DAPM_ENUM("Right Headphone Mux", alc5632_hpr_out_input_enum
);
325 /* speaker output N select */
326 static SOC_ENUM_SINGLE_DECL(alc5632_spk_n_sour_enum
,
327 ALC5632_OUTPUT_MIXER_CTRL
, 14,
328 alc5632_spk_n_sour_sel
);
329 static const struct snd_kcontrol_new alc5632_spkoutn_mux_controls
=
330 SOC_DAPM_ENUM("SpeakerOut N Mux", alc5632_spk_n_sour_enum
);
332 /* speaker amplifier */
333 static const char *alc5632_amp_names
[] = {"AB Amp", "D Amp"};
334 static SOC_ENUM_SINGLE_DECL(alc5632_amp_enum
,
335 ALC5632_OUTPUT_MIXER_CTRL
, 13,
337 static const struct snd_kcontrol_new alc5632_amp_mux_controls
=
338 SOC_DAPM_ENUM("AB-D Amp Mux", alc5632_amp_enum
);
340 /* ADC output select */
341 static SOC_ENUM_SINGLE_DECL(alc5632_adcr_func_enum
,
342 ALC5632_DAC_FUNC_SELECT
, 5,
343 alc5632_adcr_func_sel
);
344 static const struct snd_kcontrol_new alc5632_adcr_func_controls
=
345 SOC_DAPM_ENUM("ADCR Mux", alc5632_adcr_func_enum
);
348 static SOC_ENUM_SINGLE_DECL(alc5632_i2s_out_enum
,
349 ALC5632_I2S_OUT_CTL
, 5,
350 alc5632_i2s_out_sel
);
351 static const struct snd_kcontrol_new alc5632_i2s_out_controls
=
352 SOC_DAPM_ENUM("I2SOut Mux", alc5632_i2s_out_enum
);
354 static const struct snd_soc_dapm_widget alc5632_dapm_widgets
[] = {
356 SND_SOC_DAPM_MUX("AuxOut Mux", SND_SOC_NOPM
, 0, 0,
357 &alc5632_auxout_mux_controls
),
358 SND_SOC_DAPM_MUX("SpeakerOut Mux", SND_SOC_NOPM
, 0, 0,
359 &alc5632_spkout_mux_controls
),
360 SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM
, 0, 0,
361 &alc5632_hpl_out_mux_controls
),
362 SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM
, 0, 0,
363 &alc5632_hpr_out_mux_controls
),
364 SND_SOC_DAPM_MUX("SpeakerOut N Mux", SND_SOC_NOPM
, 0, 0,
365 &alc5632_spkoutn_mux_controls
),
366 SND_SOC_DAPM_MUX("ADCR Mux", SND_SOC_NOPM
, 0, 0,
367 &alc5632_adcr_func_controls
),
368 SND_SOC_DAPM_MUX("I2SOut Mux", ALC5632_PWR_MANAG_ADD1
, 11, 0,
369 &alc5632_i2s_out_controls
),
372 SND_SOC_DAPM_MIXER("HP Mix", SND_SOC_NOPM
, 0, 0,
373 &alc5632_hp_mixer_controls
[0],
374 ARRAY_SIZE(alc5632_hp_mixer_controls
)),
375 SND_SOC_DAPM_MIXER("HPR Mix", ALC5632_PWR_MANAG_ADD2
, 4, 0,
376 &alc5632_hpr_mixer_controls
[0],
377 ARRAY_SIZE(alc5632_hpr_mixer_controls
)),
378 SND_SOC_DAPM_MIXER("HPL Mix", ALC5632_PWR_MANAG_ADD2
, 5, 0,
379 &alc5632_hpl_mixer_controls
[0],
380 ARRAY_SIZE(alc5632_hpl_mixer_controls
)),
381 SND_SOC_DAPM_MIXER("HPOut Mix", SND_SOC_NOPM
, 0, 0, NULL
, 0),
382 SND_SOC_DAPM_MIXER("Mono Mix", ALC5632_PWR_MANAG_ADD2
, 2, 0,
383 &alc5632_mono_mixer_controls
[0],
384 ARRAY_SIZE(alc5632_mono_mixer_controls
)),
385 SND_SOC_DAPM_MIXER("Speaker Mix", ALC5632_PWR_MANAG_ADD2
, 3, 0,
386 &alc5632_speaker_mixer_controls
[0],
387 ARRAY_SIZE(alc5632_speaker_mixer_controls
)),
388 SND_SOC_DAPM_MIXER("DMICL Mix", SND_SOC_NOPM
, 0, 0,
389 &alc5632_dmicl_mixer_controls
[0],
390 ARRAY_SIZE(alc5632_dmicl_mixer_controls
)),
391 SND_SOC_DAPM_MIXER("DMICR Mix", SND_SOC_NOPM
, 0, 0,
392 &alc5632_dmicr_mixer_controls
[0],
393 ARRAY_SIZE(alc5632_dmicr_mixer_controls
)),
396 SND_SOC_DAPM_MIXER("Left Capture Mix", ALC5632_PWR_MANAG_ADD2
, 1, 0,
397 &alc5632_captureL_mixer_controls
[0],
398 ARRAY_SIZE(alc5632_captureL_mixer_controls
)),
399 SND_SOC_DAPM_MIXER("Right Capture Mix", ALC5632_PWR_MANAG_ADD2
, 0, 0,
400 &alc5632_captureR_mixer_controls
[0],
401 ARRAY_SIZE(alc5632_captureR_mixer_controls
)),
403 SND_SOC_DAPM_AIF_IN("AIFRXL", "Left HiFi Playback", 0, SND_SOC_NOPM
, 0, 0),
404 SND_SOC_DAPM_AIF_IN("AIFRXR", "Right HiFi Playback", 0, SND_SOC_NOPM
, 0, 0),
405 SND_SOC_DAPM_AIF_OUT("AIFTXL", "Left HiFi Capture", 0, SND_SOC_NOPM
, 0, 0),
406 SND_SOC_DAPM_AIF_OUT("AIFTXR", "Right HiFi Capture", 0, SND_SOC_NOPM
, 0, 0),
407 SND_SOC_DAPM_AIF_IN("VAIFRX", "Voice Playback", 0, SND_SOC_NOPM
, 0, 0),
408 SND_SOC_DAPM_AIF_OUT("VAIFTX", "Voice Capture", 0, SND_SOC_NOPM
, 0, 0),
410 SND_SOC_DAPM_DAC("Voice DAC", NULL
, ALC5632_PWR_MANAG_ADD2
, 10, 0),
411 SND_SOC_DAPM_DAC("Left DAC", NULL
, ALC5632_PWR_MANAG_ADD2
, 9, 0),
412 SND_SOC_DAPM_DAC("Right DAC", NULL
, ALC5632_PWR_MANAG_ADD2
, 8, 0),
413 SND_SOC_DAPM_ADC("Left ADC", NULL
, ALC5632_PWR_MANAG_ADD2
, 7, 0),
414 SND_SOC_DAPM_ADC("Right ADC", NULL
, ALC5632_PWR_MANAG_ADD2
, 6, 0),
416 SND_SOC_DAPM_MIXER("DAC Left Channel", ALC5632_PWR_MANAG_ADD1
, 15, 0, NULL
, 0),
417 SND_SOC_DAPM_MIXER("DAC Right Channel",
418 ALC5632_PWR_MANAG_ADD1
, 14, 0, NULL
, 0),
419 SND_SOC_DAPM_MIXER("I2S Mix", ALC5632_PWR_MANAG_ADD1
, 11, 0, NULL
, 0),
420 SND_SOC_DAPM_MIXER("Phone Mix", SND_SOC_NOPM
, 0, 0, NULL
, 0),
421 SND_SOC_DAPM_MIXER("Line Mix", SND_SOC_NOPM
, 0, 0, NULL
, 0),
422 SND_SOC_DAPM_MIXER("Voice Mix", SND_SOC_NOPM
, 0, 0, NULL
, 0),
423 SND_SOC_DAPM_MIXER("ADCLR", SND_SOC_NOPM
, 0, 0, NULL
, 0),
425 SND_SOC_DAPM_PGA("Left Headphone", ALC5632_PWR_MANAG_ADD3
, 11, 0, NULL
, 0),
426 SND_SOC_DAPM_PGA("Right Headphone", ALC5632_PWR_MANAG_ADD3
, 10, 0, NULL
, 0),
427 SND_SOC_DAPM_PGA("Left Speaker", ALC5632_PWR_MANAG_ADD3
, 13, 0, NULL
, 0),
428 SND_SOC_DAPM_PGA("Right Speaker", ALC5632_PWR_MANAG_ADD3
, 12, 0, NULL
, 0),
429 SND_SOC_DAPM_PGA("Aux Out", ALC5632_PWR_MANAG_ADD3
, 14, 0, NULL
, 0),
430 SND_SOC_DAPM_PGA("Left LineIn", ALC5632_PWR_MANAG_ADD3
, 7, 0, NULL
, 0),
431 SND_SOC_DAPM_PGA("Right LineIn", ALC5632_PWR_MANAG_ADD3
, 6, 0, NULL
, 0),
432 SND_SOC_DAPM_PGA("Phone", ALC5632_PWR_MANAG_ADD3
, 5, 0, NULL
, 0),
433 SND_SOC_DAPM_PGA("Phone ADMix", ALC5632_PWR_MANAG_ADD3
, 4, 0, NULL
, 0),
434 SND_SOC_DAPM_PGA("MIC1 PGA", ALC5632_PWR_MANAG_ADD3
, 3, 0, NULL
, 0),
435 SND_SOC_DAPM_PGA("MIC2 PGA", ALC5632_PWR_MANAG_ADD3
, 2, 0, NULL
, 0),
436 SND_SOC_DAPM_PGA("MIC1 Pre Amp", ALC5632_PWR_MANAG_ADD3
, 1, 0, NULL
, 0),
437 SND_SOC_DAPM_PGA("MIC2 Pre Amp", ALC5632_PWR_MANAG_ADD3
, 0, 0, NULL
, 0),
438 SND_SOC_DAPM_SUPPLY("MICBIAS1", ALC5632_PWR_MANAG_ADD1
, 3, 0, NULL
, 0),
439 SND_SOC_DAPM_SUPPLY("MICBIAS2", ALC5632_PWR_MANAG_ADD1
, 2, 0, NULL
, 0),
441 SND_SOC_DAPM_PGA_E("D Amp", ALC5632_PWR_MANAG_ADD2
, 14, 0, NULL
, 0,
442 amp_mixer_event
, SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
443 SND_SOC_DAPM_PGA("AB Amp", ALC5632_PWR_MANAG_ADD2
, 15, 0, NULL
, 0),
444 SND_SOC_DAPM_MUX("AB-D Amp Mux", ALC5632_PWR_MANAG_ADD1
, 10, 0,
445 &alc5632_amp_mux_controls
),
447 SND_SOC_DAPM_OUTPUT("AUXOUT"),
448 SND_SOC_DAPM_OUTPUT("HPL"),
449 SND_SOC_DAPM_OUTPUT("HPR"),
450 SND_SOC_DAPM_OUTPUT("SPKOUT"),
451 SND_SOC_DAPM_OUTPUT("SPKOUTN"),
453 SND_SOC_DAPM_INPUT("LINEINL"),
454 SND_SOC_DAPM_INPUT("LINEINR"),
455 SND_SOC_DAPM_INPUT("PHONEP"),
456 SND_SOC_DAPM_INPUT("PHONEN"),
457 SND_SOC_DAPM_INPUT("DMICDAT"),
458 SND_SOC_DAPM_INPUT("MIC1"),
459 SND_SOC_DAPM_INPUT("MIC2"),
460 SND_SOC_DAPM_VMID("Vmid"),
464 static const struct snd_soc_dapm_route alc5632_dapm_routes
[] = {
465 /* Playback streams */
466 {"Left DAC", NULL
, "AIFRXL"},
467 {"Right DAC", NULL
, "AIFRXR"},
469 /* virtual mixer - mixes left & right channels */
470 {"I2S Mix", NULL
, "Left DAC"},
471 {"I2S Mix", NULL
, "Right DAC"},
472 {"Line Mix", NULL
, "Right LineIn"},
473 {"Line Mix", NULL
, "Left LineIn"},
474 {"Phone Mix", NULL
, "Phone"},
475 {"Phone Mix", NULL
, "Phone ADMix"},
476 {"AUXOUT", NULL
, "Aux Out"},
479 {"DAC Right Channel", NULL
, "I2S Mix"},
480 {"DAC Left Channel", NULL
, "I2S Mix"},
483 {"HPL Mix", "ADC2HP_L Playback Switch", "Left Capture Mix"},
484 {"HPL Mix", NULL
, "HP Mix"},
485 {"HPR Mix", "ADC2HP_R Playback Switch", "Right Capture Mix"},
486 {"HPR Mix", NULL
, "HP Mix"},
487 {"HP Mix", "LI2HP Playback Switch", "Line Mix"},
488 {"HP Mix", "PHONE2HP Playback Switch", "Phone Mix"},
489 {"HP Mix", "MIC12HP Playback Switch", "MIC1 PGA"},
490 {"HP Mix", "MIC22HP Playback Switch", "MIC2 PGA"},
491 {"HP Mix", "VOICE2HP Playback Switch", "Voice Mix"},
492 {"HPR Mix", "DACR2HP Playback Switch", "DAC Right Channel"},
493 {"HPL Mix", "DACL2HP Playback Switch", "DAC Left Channel"},
494 {"HPOut Mix", NULL
, "HP Mix"},
495 {"HPOut Mix", NULL
, "HPR Mix"},
496 {"HPOut Mix", NULL
, "HPL Mix"},
499 {"Speaker Mix", "LI2SPK Playback Switch", "Line Mix"},
500 {"Speaker Mix", "PHONE2SPK Playback Switch", "Phone Mix"},
501 {"Speaker Mix", "MIC12SPK Playback Switch", "MIC1 PGA"},
502 {"Speaker Mix", "MIC22SPK Playback Switch", "MIC2 PGA"},
503 {"Speaker Mix", "DAC2SPK Playback Switch", "DAC Left Channel"},
504 {"Speaker Mix", "VOICE2SPK Playback Switch", "Voice Mix"},
507 {"Mono Mix", "ADC2MONO_L Playback Switch", "Left Capture Mix"},
508 {"Mono Mix", "ADC2MONO_R Playback Switch", "Right Capture Mix"},
509 {"Mono Mix", "LI2MONO Playback Switch", "Line Mix"},
510 {"Mono Mix", "MIC12MONO Playback Switch", "MIC1 PGA"},
511 {"Mono Mix", "MIC22MONO Playback Switch", "MIC2 PGA"},
512 {"Mono Mix", "DAC2MONO Playback Switch", "DAC Left Channel"},
513 {"Mono Mix", "VOICE2MONO Playback Switch", "Voice Mix"},
515 /* Left record mixer */
516 {"Left Capture Mix", "LIL2REC Capture Switch", "LINEINL"},
517 {"Left Capture Mix", "PH2REC_L Capture Switch", "PHONEN"},
518 {"Left Capture Mix", "MIC12REC_L Capture Switch", "MIC1 Pre Amp"},
519 {"Left Capture Mix", "MIC22REC_L Capture Switch", "MIC2 Pre Amp"},
520 {"Left Capture Mix", "HPL2REC Capture Switch", "HPL Mix"},
521 {"Left Capture Mix", "SPK2REC_L Capture Switch", "Speaker Mix"},
522 {"Left Capture Mix", "MONO2REC_L Capture Switch", "Mono Mix"},
524 /*Right record mixer */
525 {"Right Capture Mix", "LIR2REC Capture Switch", "LINEINR"},
526 {"Right Capture Mix", "PH2REC_R Capture Switch", "PHONEP"},
527 {"Right Capture Mix", "MIC12REC_R Capture Switch", "MIC1 Pre Amp"},
528 {"Right Capture Mix", "MIC22REC_R Capture Switch", "MIC2 Pre Amp"},
529 {"Right Capture Mix", "HPR2REC Capture Switch", "HPR Mix"},
530 {"Right Capture Mix", "SPK2REC_R Capture Switch", "Speaker Mix"},
531 {"Right Capture Mix", "MONO2REC_R Capture Switch", "Mono Mix"},
533 /* headphone left mux */
534 {"Left Headphone Mux", "HP Left Mix", "HPL Mix"},
535 {"Left Headphone Mux", "Vmid", "Vmid"},
537 /* headphone right mux */
538 {"Right Headphone Mux", "HP Right Mix", "HPR Mix"},
539 {"Right Headphone Mux", "Vmid", "Vmid"},
541 /* speaker out mux */
542 {"SpeakerOut Mux", "Vmid", "Vmid"},
543 {"SpeakerOut Mux", "HPOut Mix", "HPOut Mix"},
544 {"SpeakerOut Mux", "Speaker Mix", "Speaker Mix"},
545 {"SpeakerOut Mux", "Mono Mix", "Mono Mix"},
547 /* Mono/Aux Out mux */
548 {"AuxOut Mux", "Vmid", "Vmid"},
549 {"AuxOut Mux", "HPOut Mix", "HPOut Mix"},
550 {"AuxOut Mux", "Speaker Mix", "Speaker Mix"},
551 {"AuxOut Mux", "Mono Mix", "Mono Mix"},
554 {"HPL", NULL
, "Left Headphone"},
555 {"Left Headphone", NULL
, "Left Headphone Mux"},
556 {"HPR", NULL
, "Right Headphone"},
557 {"Right Headphone", NULL
, "Right Headphone Mux"},
558 {"Aux Out", NULL
, "AuxOut Mux"},
561 {"Left LineIn", NULL
, "LINEINL"},
562 {"Right LineIn", NULL
, "LINEINR"},
563 {"Phone", NULL
, "PHONEP"},
564 {"MIC1 Pre Amp", NULL
, "MIC1"},
565 {"MIC2 Pre Amp", NULL
, "MIC2"},
566 {"MIC1 PGA", NULL
, "MIC1 Pre Amp"},
567 {"MIC2 PGA", NULL
, "MIC2 Pre Amp"},
570 {"Left ADC", NULL
, "Left Capture Mix"},
571 {"DMICL Mix", "DMICL2ADC Capture Switch", "DMICDAT"},
572 {"Left ADC", NULL
, "DMICL Mix"},
573 {"ADCLR", NULL
, "Left ADC"},
576 {"Right ADC", NULL
, "Right Capture Mix"},
577 {"DMICR Mix", "DMICR2ADC Capture Switch", "DMICDAT"},
578 {"Right ADC", NULL
, "DMICR Mix"},
579 {"ADCR Mux", "Stereo ADC", "Right ADC"},
580 {"ADCR Mux", "Voice ADC", "Right ADC"},
581 {"ADCLR", NULL
, "ADCR Mux"},
582 {"VAIFTX", NULL
, "ADCR Mux"},
584 /* Digital I2S out */
585 {"I2SOut Mux", "ADC LR", "ADCLR"},
586 {"I2SOut Mux", "Voice Stereo Digital", "VAIFRX"},
587 {"AIFTXL", NULL
, "I2SOut Mux"},
588 {"AIFTXR", NULL
, "I2SOut Mux"},
591 {"Voice DAC", NULL
, "VAIFRX"},
592 {"Voice Mix", NULL
, "Voice DAC"},
595 {"SpeakerOut N Mux", "RN/-R", "Left Speaker"},
596 {"SpeakerOut N Mux", "RP/+R", "Left Speaker"},
597 {"SpeakerOut N Mux", "LN/-R", "Left Speaker"},
598 {"SpeakerOut N Mux", "Mute", "Vmid"},
600 {"SpeakerOut N Mux", "RN/-R", "Right Speaker"},
601 {"SpeakerOut N Mux", "RP/+R", "Right Speaker"},
602 {"SpeakerOut N Mux", "LN/-R", "Right Speaker"},
603 {"SpeakerOut N Mux", "Mute", "Vmid"},
605 {"AB Amp", NULL
, "SpeakerOut Mux"},
606 {"D Amp", NULL
, "SpeakerOut Mux"},
607 {"AB-D Amp Mux", "AB Amp", "AB Amp"},
608 {"AB-D Amp Mux", "D Amp", "D Amp"},
609 {"Left Speaker", NULL
, "AB-D Amp Mux"},
610 {"Right Speaker", NULL
, "AB-D Amp Mux"},
612 {"SPKOUT", NULL
, "Left Speaker"},
613 {"SPKOUT", NULL
, "Right Speaker"},
615 {"SPKOUTN", NULL
, "SpeakerOut N Mux"},
626 /* Note : pll code from original alc5632 driver. Not sure of how good it is */
627 /* useful only for master mode */
628 static const struct _pll_div codec_master_pll_div
[] = {
630 { 2048000, 8192000, 0x0ea0},
631 { 3686400, 8192000, 0x4e27},
632 { 12000000, 8192000, 0x456b},
633 { 13000000, 8192000, 0x495f},
634 { 13100000, 8192000, 0x0320},
635 { 2048000, 11289600, 0xf637},
636 { 3686400, 11289600, 0x2f22},
637 { 12000000, 11289600, 0x3e2f},
638 { 13000000, 11289600, 0x4d5b},
639 { 13100000, 11289600, 0x363b},
640 { 2048000, 16384000, 0x1ea0},
641 { 3686400, 16384000, 0x9e27},
642 { 12000000, 16384000, 0x452b},
643 { 13000000, 16384000, 0x542f},
644 { 13100000, 16384000, 0x03a0},
645 { 2048000, 16934400, 0xe625},
646 { 3686400, 16934400, 0x9126},
647 { 12000000, 16934400, 0x4d2c},
648 { 13000000, 16934400, 0x742f},
649 { 13100000, 16934400, 0x3c27},
650 { 2048000, 22579200, 0x2aa0},
651 { 3686400, 22579200, 0x2f20},
652 { 12000000, 22579200, 0x7e2f},
653 { 13000000, 22579200, 0x742f},
654 { 13100000, 22579200, 0x3c27},
655 { 2048000, 24576000, 0x2ea0},
656 { 3686400, 24576000, 0xee27},
657 { 12000000, 24576000, 0x2915},
658 { 13000000, 24576000, 0x772e},
659 { 13100000, 24576000, 0x0d20},
662 /* FOUT = MCLK*(N+2)/((M+2)*(K+2))
663 N: bit 15:8 (div 2 .. div 257)
665 M: bit 3:0 (div 2 .. div 17)
667 same as for 5623 - thanks!
670 static const struct _pll_div codec_slave_pll_div
[] = {
672 { 1024000, 16384000, 0x3ea0},
673 { 1411200, 22579200, 0x3ea0},
674 { 1536000, 24576000, 0x3ea0},
675 { 2048000, 16384000, 0x1ea0},
676 { 2822400, 22579200, 0x1ea0},
677 { 3072000, 24576000, 0x1ea0},
681 static int alc5632_set_dai_pll(struct snd_soc_dai
*codec_dai
, int pll_id
,
682 int source
, unsigned int freq_in
, unsigned int freq_out
)
685 struct snd_soc_codec
*codec
= codec_dai
->codec
;
686 int gbl_clk
= 0, pll_div
= 0;
689 if (pll_id
< ALC5632_PLL_FR_MCLK
|| pll_id
> ALC5632_PLL_FR_VBCLK
)
692 /* Disable PLL power */
693 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
694 ALC5632_PWR_ADD2_PLL1
,
696 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
697 ALC5632_PWR_ADD2_PLL2
,
700 /* pll is not used in slave mode */
701 reg
= snd_soc_read(codec
, ALC5632_DAI_CONTROL
);
702 if (reg
& ALC5632_DAI_SDP_SLAVE_MODE
)
705 if (!freq_in
|| !freq_out
)
709 case ALC5632_PLL_FR_MCLK
:
710 for (i
= 0; i
< ARRAY_SIZE(codec_master_pll_div
); i
++) {
711 if (codec_master_pll_div
[i
].pll_in
== freq_in
712 && codec_master_pll_div
[i
].pll_out
== freq_out
) {
713 /* PLL source from MCLK */
714 pll_div
= codec_master_pll_div
[i
].regvalue
;
719 case ALC5632_PLL_FR_BCLK
:
720 for (i
= 0; i
< ARRAY_SIZE(codec_slave_pll_div
); i
++) {
721 if (codec_slave_pll_div
[i
].pll_in
== freq_in
722 && codec_slave_pll_div
[i
].pll_out
== freq_out
) {
723 /* PLL source from Bitclk */
724 gbl_clk
= ALC5632_PLL_FR_BCLK
;
725 pll_div
= codec_slave_pll_div
[i
].regvalue
;
730 case ALC5632_PLL_FR_VBCLK
:
731 for (i
= 0; i
< ARRAY_SIZE(codec_slave_pll_div
); i
++) {
732 if (codec_slave_pll_div
[i
].pll_in
== freq_in
733 && codec_slave_pll_div
[i
].pll_out
== freq_out
) {
734 /* PLL source from voice clock */
735 gbl_clk
= ALC5632_PLL_FR_VBCLK
;
736 pll_div
= codec_slave_pll_div
[i
].regvalue
;
748 /* choose MCLK/BCLK/VBCLK */
749 snd_soc_write(codec
, ALC5632_GPCR2
, gbl_clk
);
750 /* choose PLL1 clock rate */
751 snd_soc_write(codec
, ALC5632_PLL1_CTRL
, pll_div
);
753 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
754 ALC5632_PWR_ADD2_PLL1
,
755 ALC5632_PWR_ADD2_PLL1
);
757 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
758 ALC5632_PWR_ADD2_PLL2
,
759 ALC5632_PWR_ADD2_PLL2
);
760 /* use PLL1 as main SYSCLK */
761 snd_soc_update_bits(codec
, ALC5632_GPCR1
,
762 ALC5632_GPCR1_CLK_SYS_SRC_SEL_PLL1
,
763 ALC5632_GPCR1_CLK_SYS_SRC_SEL_PLL1
);
773 /* codec hifi mclk (after PLL) clock divider coefficients */
774 /* values inspired from column BCLK=32Fs of Appendix A table */
775 static const struct _coeff_div coeff_div
[] = {
779 static int get_coeff(struct snd_soc_codec
*codec
, int rate
)
781 struct alc5632_priv
*alc5632
= snd_soc_codec_get_drvdata(codec
);
784 for (i
= 0; i
< ARRAY_SIZE(coeff_div
); i
++) {
785 if (coeff_div
[i
].fs
* rate
== alc5632
->sysclk
)
792 * Clock after PLL and dividers
794 static int alc5632_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
795 int clk_id
, unsigned int freq
, int dir
)
797 struct snd_soc_codec
*codec
= codec_dai
->codec
;
798 struct alc5632_priv
*alc5632
= snd_soc_codec_get_drvdata(codec
);
810 alc5632
->sysclk
= freq
;
816 static int alc5632_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
819 struct snd_soc_codec
*codec
= codec_dai
->codec
;
822 /* set master/slave audio interface */
823 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
824 case SND_SOC_DAIFMT_CBM_CFM
:
825 iface
= ALC5632_DAI_SDP_MASTER_MODE
;
827 case SND_SOC_DAIFMT_CBS_CFS
:
828 iface
= ALC5632_DAI_SDP_SLAVE_MODE
;
834 /* interface format */
835 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
836 case SND_SOC_DAIFMT_I2S
:
837 iface
|= ALC5632_DAI_I2S_DF_I2S
;
839 case SND_SOC_DAIFMT_LEFT_J
:
840 iface
|= ALC5632_DAI_I2S_DF_LEFT
;
842 case SND_SOC_DAIFMT_DSP_A
:
843 iface
|= ALC5632_DAI_I2S_DF_PCM_A
;
845 case SND_SOC_DAIFMT_DSP_B
:
846 iface
|= ALC5632_DAI_I2S_DF_PCM_B
;
852 /* clock inversion */
853 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
854 case SND_SOC_DAIFMT_NB_NF
:
856 case SND_SOC_DAIFMT_IB_IF
:
857 iface
|= ALC5632_DAI_MAIN_I2S_BCLK_POL_CTRL
;
859 case SND_SOC_DAIFMT_IB_NF
:
860 iface
|= ALC5632_DAI_MAIN_I2S_BCLK_POL_CTRL
;
862 case SND_SOC_DAIFMT_NB_IF
:
868 return snd_soc_write(codec
, ALC5632_DAI_CONTROL
, iface
);
871 static int alc5632_pcm_hw_params(struct snd_pcm_substream
*substream
,
872 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
874 struct snd_soc_codec
*codec
= dai
->codec
;
878 iface
= snd_soc_read(codec
, ALC5632_DAI_CONTROL
);
879 iface
&= ~ALC5632_DAI_I2S_DL_MASK
;
882 switch (params_width(params
)) {
884 iface
|= ALC5632_DAI_I2S_DL_16
;
887 iface
|= ALC5632_DAI_I2S_DL_20
;
890 iface
|= ALC5632_DAI_I2S_DL_24
;
896 /* set iface & srate */
897 snd_soc_write(codec
, ALC5632_DAI_CONTROL
, iface
);
898 rate
= params_rate(params
);
899 coeff
= get_coeff(codec
, rate
);
903 coeff
= coeff_div
[coeff
].regvalue
;
904 snd_soc_write(codec
, ALC5632_DAC_CLK_CTRL1
, coeff
);
909 static int alc5632_mute(struct snd_soc_dai
*dai
, int mute
)
911 struct snd_soc_codec
*codec
= dai
->codec
;
912 u16 hp_mute
= ALC5632_MISC_HP_DEPOP_MUTE_L
913 |ALC5632_MISC_HP_DEPOP_MUTE_R
;
914 u16 mute_reg
= snd_soc_read(codec
, ALC5632_MISC_CTRL
) & ~hp_mute
;
919 return snd_soc_write(codec
, ALC5632_MISC_CTRL
, mute_reg
);
922 #define ALC5632_ADD2_POWER_EN (ALC5632_PWR_ADD2_VREF)
924 #define ALC5632_ADD3_POWER_EN (ALC5632_PWR_ADD3_MIC1_BOOST_AD)
926 #define ALC5632_ADD1_POWER_EN \
927 (ALC5632_PWR_ADD1_DAC_REF \
928 | ALC5632_PWR_ADD1_SOFTGEN_EN \
929 | ALC5632_PWR_ADD1_HP_OUT_AMP \
930 | ALC5632_PWR_ADD1_HP_OUT_ENH_AMP \
931 | ALC5632_PWR_ADD1_MAIN_BIAS)
933 static void enable_power_depop(struct snd_soc_codec
*codec
)
935 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD1
,
936 ALC5632_PWR_ADD1_SOFTGEN_EN
,
937 ALC5632_PWR_ADD1_SOFTGEN_EN
);
939 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD3
,
940 ALC5632_ADD3_POWER_EN
,
941 ALC5632_ADD3_POWER_EN
);
943 snd_soc_update_bits(codec
, ALC5632_MISC_CTRL
,
944 ALC5632_MISC_HP_DEPOP_MODE2_EN
,
945 ALC5632_MISC_HP_DEPOP_MODE2_EN
);
947 /* "normal" mode: 0 @ 26 */
948 /* set all PR0-7 mixers to 0 */
949 snd_soc_update_bits(codec
, ALC5632_PWR_DOWN_CTRL_STATUS
,
950 ALC5632_PWR_DOWN_CTRL_STATUS_MASK
,
955 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
956 ALC5632_ADD2_POWER_EN
,
957 ALC5632_ADD2_POWER_EN
);
959 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD1
,
960 ALC5632_ADD1_POWER_EN
,
961 ALC5632_ADD1_POWER_EN
);
963 /* disable HP Depop2 */
964 snd_soc_update_bits(codec
, ALC5632_MISC_CTRL
,
965 ALC5632_MISC_HP_DEPOP_MODE2_EN
,
970 static int alc5632_set_bias_level(struct snd_soc_codec
*codec
,
971 enum snd_soc_bias_level level
)
974 case SND_SOC_BIAS_ON
:
975 enable_power_depop(codec
);
977 case SND_SOC_BIAS_PREPARE
:
979 case SND_SOC_BIAS_STANDBY
:
980 /* everything off except vref/vmid, */
981 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD1
,
982 ALC5632_PWR_MANAG_ADD1_MASK
,
983 ALC5632_PWR_ADD1_MAIN_BIAS
);
984 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
985 ALC5632_PWR_MANAG_ADD2_MASK
,
986 ALC5632_PWR_ADD2_VREF
);
987 /* "normal" mode: 0 @ 26 */
988 snd_soc_update_bits(codec
, ALC5632_PWR_DOWN_CTRL_STATUS
,
989 ALC5632_PWR_DOWN_CTRL_STATUS_MASK
,
990 0xffff ^ (ALC5632_PWR_VREF_PR3
991 | ALC5632_PWR_VREF_PR2
));
993 case SND_SOC_BIAS_OFF
:
994 /* everything off, dac mute, inactive */
995 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD2
,
996 ALC5632_PWR_MANAG_ADD2_MASK
, 0);
997 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD3
,
998 ALC5632_PWR_MANAG_ADD3_MASK
, 0);
999 snd_soc_update_bits(codec
, ALC5632_PWR_MANAG_ADD1
,
1000 ALC5632_PWR_MANAG_ADD1_MASK
, 0);
1006 #define ALC5632_FORMATS (SNDRV_PCM_FMTBIT_S16_LE \
1007 | SNDRV_PCM_FMTBIT_S24_LE \
1008 | SNDRV_PCM_FMTBIT_S32_LE)
1010 static const struct snd_soc_dai_ops alc5632_dai_ops
= {
1011 .hw_params
= alc5632_pcm_hw_params
,
1012 .digital_mute
= alc5632_mute
,
1013 .set_fmt
= alc5632_set_dai_fmt
,
1014 .set_sysclk
= alc5632_set_dai_sysclk
,
1015 .set_pll
= alc5632_set_dai_pll
,
1018 static struct snd_soc_dai_driver alc5632_dai
= {
1019 .name
= "alc5632-hifi",
1021 .stream_name
= "HiFi Playback",
1026 .rates
= SNDRV_PCM_RATE_8000_48000
,
1027 .formats
= ALC5632_FORMATS
,},
1029 .stream_name
= "HiFi Capture",
1034 .rates
= SNDRV_PCM_RATE_8000_48000
,
1035 .formats
= ALC5632_FORMATS
,},
1037 .ops
= &alc5632_dai_ops
,
1038 .symmetric_rates
= 1,
1042 static int alc5632_resume(struct snd_soc_codec
*codec
)
1044 struct alc5632_priv
*alc5632
= snd_soc_codec_get_drvdata(codec
);
1046 regcache_sync(alc5632
->regmap
);
1051 #define alc5632_resume NULL
1054 static int alc5632_probe(struct snd_soc_codec
*codec
)
1056 struct alc5632_priv
*alc5632
= snd_soc_codec_get_drvdata(codec
);
1058 switch (alc5632
->id
) {
1060 snd_soc_add_codec_controls(codec
, alc5632_vol_snd_controls
,
1061 ARRAY_SIZE(alc5632_vol_snd_controls
));
1070 static const struct snd_soc_codec_driver soc_codec_device_alc5632
= {
1071 .probe
= alc5632_probe
,
1072 .resume
= alc5632_resume
,
1073 .set_bias_level
= alc5632_set_bias_level
,
1074 .suspend_bias_off
= true,
1076 .controls
= alc5632_snd_controls
,
1077 .num_controls
= ARRAY_SIZE(alc5632_snd_controls
),
1078 .dapm_widgets
= alc5632_dapm_widgets
,
1079 .num_dapm_widgets
= ARRAY_SIZE(alc5632_dapm_widgets
),
1080 .dapm_routes
= alc5632_dapm_routes
,
1081 .num_dapm_routes
= ARRAY_SIZE(alc5632_dapm_routes
),
1084 static const struct regmap_config alc5632_regmap
= {
1088 .max_register
= ALC5632_MAX_REGISTER
,
1089 .reg_defaults
= alc5632_reg_defaults
,
1090 .num_reg_defaults
= ARRAY_SIZE(alc5632_reg_defaults
),
1091 .volatile_reg
= alc5632_volatile_register
,
1092 .cache_type
= REGCACHE_RBTREE
,
1096 * alc5632 2 wire address is determined by A1 pin
1097 * state during powerup.
1101 static int alc5632_i2c_probe(struct i2c_client
*client
,
1102 const struct i2c_device_id
*id
)
1104 struct alc5632_priv
*alc5632
;
1105 int ret
, ret1
, ret2
;
1106 unsigned int vid1
, vid2
;
1108 alc5632
= devm_kzalloc(&client
->dev
,
1109 sizeof(struct alc5632_priv
), GFP_KERNEL
);
1110 if (alc5632
== NULL
)
1113 i2c_set_clientdata(client
, alc5632
);
1115 alc5632
->regmap
= devm_regmap_init_i2c(client
, &alc5632_regmap
);
1116 if (IS_ERR(alc5632
->regmap
)) {
1117 ret
= PTR_ERR(alc5632
->regmap
);
1118 dev_err(&client
->dev
, "regmap_init() failed: %d\n", ret
);
1122 ret1
= regmap_read(alc5632
->regmap
, ALC5632_VENDOR_ID1
, &vid1
);
1123 ret2
= regmap_read(alc5632
->regmap
, ALC5632_VENDOR_ID2
, &vid2
);
1124 if (ret1
!= 0 || ret2
!= 0) {
1125 dev_err(&client
->dev
,
1126 "Failed to read chip ID: ret1=%d, ret2=%d\n", ret1
, ret2
);
1132 if ((vid1
!= 0x10EC) || (vid2
!= id
->driver_data
)) {
1133 dev_err(&client
->dev
,
1134 "Device is not a ALC5632: VID1=0x%x, VID2=0x%x\n", vid1
, vid2
);
1138 ret
= alc5632_reset(alc5632
->regmap
);
1140 dev_err(&client
->dev
, "Failed to issue reset\n");
1145 switch (alc5632
->id
) {
1147 alc5632_dai
.name
= "alc5632-hifi";
1153 ret
= snd_soc_register_codec(&client
->dev
,
1154 &soc_codec_device_alc5632
, &alc5632_dai
, 1);
1157 dev_err(&client
->dev
, "Failed to register codec: %d\n", ret
);
1164 static int alc5632_i2c_remove(struct i2c_client
*client
)
1166 snd_soc_unregister_codec(&client
->dev
);
1170 static const struct i2c_device_id alc5632_i2c_table
[] = {
1174 MODULE_DEVICE_TABLE(i2c
, alc5632_i2c_table
);
1176 static const struct of_device_id alc5632_of_match
[] = {
1177 { .compatible
= "realtek,alc5632", },
1180 MODULE_DEVICE_TABLE(of
, alc5632_of_match
);
1182 /* i2c codec control layer */
1183 static struct i2c_driver alc5632_i2c_driver
= {
1186 .owner
= THIS_MODULE
,
1187 .of_match_table
= of_match_ptr(alc5632_of_match
),
1189 .probe
= alc5632_i2c_probe
,
1190 .remove
= alc5632_i2c_remove
,
1191 .id_table
= alc5632_i2c_table
,
1194 module_i2c_driver(alc5632_i2c_driver
);
1196 MODULE_DESCRIPTION("ASoC ALC5632 driver");
1197 MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>");
1198 MODULE_LICENSE("GPL");