Commit | Line | Data |
---|---|---|
98615454 KM |
1 | /* |
2 | * DA7210 ALSA Soc codec driver | |
3 | * | |
4 | * Copyright (c) 2009 Dialog Semiconductor | |
5 | * Written by David Chen <Dajun.chen@diasemi.com> | |
6 | * | |
7 | * Copyright (C) 2009 Renesas Solutions Corp. | |
8 | * Cleanups by Kuninori Morimoto <morimoto.kuninori@renesas.com> | |
9 | * | |
10 | * Tested on SuperH Ecovec24 board with S16/S24 LE in 48KHz using I2S | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or modify it | |
13 | * under the terms of the GNU General Public License as published by the | |
14 | * Free Software Foundation; either version 2 of the License, or (at your | |
15 | * option) any later version. | |
16 | */ | |
17 | ||
98615454 | 18 | #include <linux/delay.h> |
98615454 | 19 | #include <linux/i2c.h> |
33593b52 | 20 | #include <linux/regmap.h> |
5a0e3ad6 | 21 | #include <linux/slab.h> |
da155d5b | 22 | #include <linux/module.h> |
98615454 KM |
23 | #include <sound/pcm.h> |
24 | #include <sound/pcm_params.h> | |
ce6120cc | 25 | #include <sound/soc.h> |
98615454 | 26 | #include <sound/initval.h> |
a7e7cd5b | 27 | #include <sound/tlv.h> |
98615454 | 28 | |
98615454 | 29 | /* DA7210 register space */ |
de5eaf84 | 30 | #define DA7210_CONTROL 0x01 |
98615454 KM |
31 | #define DA7210_STATUS 0x02 |
32 | #define DA7210_STARTUP1 0x03 | |
6950c60d AC |
33 | #define DA7210_STARTUP2 0x04 |
34 | #define DA7210_STARTUP3 0x05 | |
98615454 KM |
35 | #define DA7210_MIC_L 0x07 |
36 | #define DA7210_MIC_R 0x08 | |
de5eaf84 AC |
37 | #define DA7210_AUX1_L 0x09 |
38 | #define DA7210_AUX1_R 0x0A | |
5eda1949 | 39 | #define DA7210_AUX2 0x0B |
de5eaf84 | 40 | #define DA7210_IN_GAIN 0x0C |
98615454 KM |
41 | #define DA7210_INMIX_L 0x0D |
42 | #define DA7210_INMIX_R 0x0E | |
43 | #define DA7210_ADC_HPF 0x0F | |
44 | #define DA7210_ADC 0x10 | |
0ee6e9e7 AC |
45 | #define DA7210_ADC_EQ1_2 0X11 |
46 | #define DA7210_ADC_EQ3_4 0x12 | |
47 | #define DA7210_ADC_EQ5 0x13 | |
98615454 KM |
48 | #define DA7210_DAC_HPF 0x14 |
49 | #define DA7210_DAC_L 0x15 | |
50 | #define DA7210_DAC_R 0x16 | |
51 | #define DA7210_DAC_SEL 0x17 | |
5eda1949 | 52 | #define DA7210_SOFTMUTE 0x18 |
0ee6e9e7 AC |
53 | #define DA7210_DAC_EQ1_2 0x19 |
54 | #define DA7210_DAC_EQ3_4 0x1A | |
55 | #define DA7210_DAC_EQ5 0x1B | |
98615454 KM |
56 | #define DA7210_OUTMIX_L 0x1C |
57 | #define DA7210_OUTMIX_R 0x1D | |
52082d8f AC |
58 | #define DA7210_OUT1_L 0x1E |
59 | #define DA7210_OUT1_R 0x1F | |
60 | #define DA7210_OUT2 0x20 | |
98615454 KM |
61 | #define DA7210_HP_L_VOL 0x21 |
62 | #define DA7210_HP_R_VOL 0x22 | |
63 | #define DA7210_HP_CFG 0x23 | |
5eda1949 | 64 | #define DA7210_ZERO_CROSS 0x24 |
98615454 KM |
65 | #define DA7210_DAI_SRC_SEL 0x25 |
66 | #define DA7210_DAI_CFG1 0x26 | |
67 | #define DA7210_DAI_CFG3 0x28 | |
960b3b4b KM |
68 | #define DA7210_PLL_DIV1 0x29 |
69 | #define DA7210_PLL_DIV2 0x2A | |
98615454 KM |
70 | #define DA7210_PLL_DIV3 0x2B |
71 | #define DA7210_PLL 0x2C | |
de5eaf84 AC |
72 | #define DA7210_ALC_MAX 0x83 |
73 | #define DA7210_ALC_MIN 0x84 | |
74 | #define DA7210_ALC_NOIS 0x85 | |
75 | #define DA7210_ALC_ATT 0x86 | |
76 | #define DA7210_ALC_REL 0x87 | |
77 | #define DA7210_ALC_DEL 0x88 | |
960b3b4b KM |
78 | #define DA7210_A_HID_UNLOCK 0x8A |
79 | #define DA7210_A_TEST_UNLOCK 0x8B | |
80 | #define DA7210_A_PLL1 0x90 | |
81 | #define DA7210_A_CP_MODE 0xA7 | |
98615454 KM |
82 | |
83 | /* STARTUP1 bit fields */ | |
84 | #define DA7210_SC_MST_EN (1 << 0) | |
85 | ||
86 | /* MIC_L bit fields */ | |
87 | #define DA7210_MICBIAS_EN (1 << 6) | |
88 | #define DA7210_MIC_L_EN (1 << 7) | |
89 | ||
90 | /* MIC_R bit fields */ | |
91 | #define DA7210_MIC_R_EN (1 << 7) | |
92 | ||
93 | /* INMIX_L bit fields */ | |
94 | #define DA7210_IN_L_EN (1 << 7) | |
95 | ||
96 | /* INMIX_R bit fields */ | |
97 | #define DA7210_IN_R_EN (1 << 7) | |
98 | ||
98615454 | 99 | /* ADC bit fields */ |
de5eaf84 | 100 | #define DA7210_ADC_ALC_EN (1 << 0) |
98615454 KM |
101 | #define DA7210_ADC_L_EN (1 << 3) |
102 | #define DA7210_ADC_R_EN (1 << 7) | |
103 | ||
3a9d6202 KM |
104 | /* DAC/ADC HPF fields */ |
105 | #define DA7210_VOICE_F0_MASK (0x7 << 4) | |
106 | #define DA7210_VOICE_F0_25 (1 << 4) | |
107 | #define DA7210_VOICE_EN (1 << 7) | |
c2151433 | 108 | |
98615454 KM |
109 | /* DAC_SEL bit fields */ |
110 | #define DA7210_DAC_L_SRC_DAI_L (4 << 0) | |
111 | #define DA7210_DAC_L_EN (1 << 3) | |
112 | #define DA7210_DAC_R_SRC_DAI_R (5 << 4) | |
113 | #define DA7210_DAC_R_EN (1 << 7) | |
114 | ||
115 | /* OUTMIX_L bit fields */ | |
116 | #define DA7210_OUT_L_EN (1 << 7) | |
117 | ||
118 | /* OUTMIX_R bit fields */ | |
119 | #define DA7210_OUT_R_EN (1 << 7) | |
120 | ||
121 | /* HP_CFG bit fields */ | |
122 | #define DA7210_HP_2CAP_MODE (1 << 1) | |
123 | #define DA7210_HP_SENSE_EN (1 << 2) | |
124 | #define DA7210_HP_L_EN (1 << 3) | |
125 | #define DA7210_HP_MODE (1 << 6) | |
126 | #define DA7210_HP_R_EN (1 << 7) | |
127 | ||
128 | /* DAI_SRC_SEL bit fields */ | |
129 | #define DA7210_DAI_OUT_L_SRC (6 << 0) | |
130 | #define DA7210_DAI_OUT_R_SRC (7 << 4) | |
131 | ||
132 | /* DAI_CFG1 bit fields */ | |
133 | #define DA7210_DAI_WORD_S16_LE (0 << 0) | |
0f8ea586 | 134 | #define DA7210_DAI_WORD_S20_3LE (1 << 0) |
98615454 | 135 | #define DA7210_DAI_WORD_S24_LE (2 << 0) |
0f8ea586 | 136 | #define DA7210_DAI_WORD_S32_LE (3 << 0) |
98615454 | 137 | #define DA7210_DAI_FLEN_64BIT (1 << 2) |
0f8ea586 | 138 | #define DA7210_DAI_MODE_SLAVE (0 << 7) |
98615454 KM |
139 | #define DA7210_DAI_MODE_MASTER (1 << 7) |
140 | ||
141 | /* DAI_CFG3 bit fields */ | |
142 | #define DA7210_DAI_FORMAT_I2SMODE (0 << 0) | |
0f8ea586 AC |
143 | #define DA7210_DAI_FORMAT_LEFT_J (1 << 0) |
144 | #define DA7210_DAI_FORMAT_RIGHT_J (2 << 0) | |
98615454 KM |
145 | #define DA7210_DAI_OE (1 << 3) |
146 | #define DA7210_DAI_EN (1 << 7) | |
147 | ||
148 | /*PLL_DIV3 bit fields */ | |
149 | #define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4) | |
150 | #define DA7210_PLL_BYP (1 << 6) | |
151 | ||
152 | /* PLL bit fields */ | |
3a9d6202 KM |
153 | #define DA7210_PLL_FS_MASK (0xF << 0) |
154 | #define DA7210_PLL_FS_8000 (0x1 << 0) | |
960b3b4b | 155 | #define DA7210_PLL_FS_11025 (0x2 << 0) |
3a9d6202 KM |
156 | #define DA7210_PLL_FS_12000 (0x3 << 0) |
157 | #define DA7210_PLL_FS_16000 (0x5 << 0) | |
960b3b4b | 158 | #define DA7210_PLL_FS_22050 (0x6 << 0) |
3a9d6202 KM |
159 | #define DA7210_PLL_FS_24000 (0x7 << 0) |
160 | #define DA7210_PLL_FS_32000 (0x9 << 0) | |
960b3b4b | 161 | #define DA7210_PLL_FS_44100 (0xA << 0) |
3a9d6202 | 162 | #define DA7210_PLL_FS_48000 (0xB << 0) |
960b3b4b | 163 | #define DA7210_PLL_FS_88200 (0xE << 0) |
3a9d6202 | 164 | #define DA7210_PLL_FS_96000 (0xF << 0) |
960b3b4b | 165 | #define DA7210_PLL_EN (0x1 << 7) |
98615454 | 166 | |
5eda1949 AC |
167 | /* SOFTMUTE bit fields */ |
168 | #define DA7210_RAMP_EN (1 << 6) | |
169 | ||
de5eaf84 AC |
170 | /* CONTROL bit fields */ |
171 | #define DA7210_NOISE_SUP_EN (1 << 3) | |
172 | ||
173 | /* IN_GAIN bit fields */ | |
174 | #define DA7210_INPGA_L_VOL (0x0F << 0) | |
175 | #define DA7210_INPGA_R_VOL (0xF0 << 0) | |
176 | ||
177 | /* ZERO_CROSS bit fields */ | |
178 | #define DA7210_AUX1_L_ZC (1 << 0) | |
179 | #define DA7210_AUX1_R_ZC (1 << 1) | |
180 | #define DA7210_HP_L_ZC (1 << 6) | |
181 | #define DA7210_HP_R_ZC (1 << 7) | |
182 | ||
183 | /* AUX1_L bit fields */ | |
184 | #define DA7210_AUX1_L_VOL (0x3F << 0) | |
24b6f263 | 185 | #define DA7210_AUX1_L_EN (1 << 7) |
de5eaf84 AC |
186 | |
187 | /* AUX1_R bit fields */ | |
188 | #define DA7210_AUX1_R_VOL (0x3F << 0) | |
24b6f263 AC |
189 | #define DA7210_AUX1_R_EN (1 << 7) |
190 | ||
191 | /* AUX2 bit fields */ | |
192 | #define DA7210_AUX2_EN (1 << 3) | |
de5eaf84 AC |
193 | |
194 | /* Minimum INPGA and AUX1 volume to enable noise suppression */ | |
195 | #define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */ | |
196 | #define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */ | |
197 | ||
52082d8f AC |
198 | /* OUT1_L bit fields */ |
199 | #define DA7210_OUT1_L_EN (1 << 7) | |
200 | ||
201 | /* OUT1_R bit fields */ | |
202 | #define DA7210_OUT1_R_EN (1 << 7) | |
203 | ||
204 | /* OUT2 bit fields */ | |
205 | #define DA7210_OUT2_OUTMIX_R (1 << 5) | |
206 | #define DA7210_OUT2_OUTMIX_L (1 << 6) | |
207 | #define DA7210_OUT2_EN (1 << 7) | |
208 | ||
98615454 KM |
209 | #define DA7210_VERSION "0.0.1" |
210 | ||
a7e7cd5b KM |
211 | /* |
212 | * Playback Volume | |
213 | * | |
214 | * max : 0x3F (+15.0 dB) | |
215 | * (1.5 dB step) | |
216 | * min : 0x11 (-54.0 dB) | |
217 | * mute : 0x10 | |
218 | * reserved : 0x00 - 0x0F | |
219 | * | |
a7e7cd5b | 220 | * Reserved area are considered as "mute". |
a7e7cd5b | 221 | */ |
7a0e67b6 AC |
222 | static const unsigned int hp_out_tlv[] = { |
223 | TLV_DB_RANGE_HEAD(2), | |
224 | 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1), | |
225 | /* -54 dB to +15 dB */ | |
226 | 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0), | |
227 | }; | |
a7e7cd5b | 228 | |
52082d8f AC |
229 | static const unsigned int lineout_vol_tlv[] = { |
230 | TLV_DB_RANGE_HEAD(2), | |
231 | 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1), | |
232 | /* -54dB to 15dB */ | |
233 | 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0) | |
234 | }; | |
235 | ||
236 | static const unsigned int mono_vol_tlv[] = { | |
237 | TLV_DB_RANGE_HEAD(2), | |
238 | 0x0, 0x2, TLV_DB_SCALE_ITEM(-1800, 0, 1), | |
239 | /* -18dB to 6dB */ | |
240 | 0x3, 0x7, TLV_DB_SCALE_ITEM(-1800, 600, 0) | |
241 | }; | |
242 | ||
24b6f263 AC |
243 | static const unsigned int aux1_vol_tlv[] = { |
244 | TLV_DB_RANGE_HEAD(2), | |
245 | 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1), | |
246 | /* -48dB to 21dB */ | |
247 | 0x11, 0x3f, TLV_DB_SCALE_ITEM(-4800, 150, 0) | |
248 | }; | |
249 | ||
0ee6e9e7 AC |
250 | static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0); |
251 | static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1); | |
52082d8f | 252 | static const DECLARE_TLV_DB_SCALE(dac_gain_tlv, -7725, 75, 0); |
24b6f263 AC |
253 | static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, -600, 600, 0); |
254 | static const DECLARE_TLV_DB_SCALE(aux2_vol_tlv, -600, 600, 0); | |
255 | static const DECLARE_TLV_DB_SCALE(inpga_gain_tlv, -450, 150, 0); | |
0ee6e9e7 | 256 | |
4ced2b96 | 257 | /* ADC and DAC high pass filter f0 value */ |
f4034147 | 258 | static const char * const da7210_hpf_cutoff_txt[] = { |
4ced2b96 AC |
259 | "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi" |
260 | }; | |
261 | ||
262 | static const struct soc_enum da7210_dac_hpf_cutoff = | |
263 | SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt); | |
264 | ||
265 | static const struct soc_enum da7210_adc_hpf_cutoff = | |
266 | SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt); | |
267 | ||
268 | /* ADC and DAC voice (8kHz) high pass cutoff value */ | |
f4034147 | 269 | static const char * const da7210_vf_cutoff_txt[] = { |
4ced2b96 AC |
270 | "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz" |
271 | }; | |
272 | ||
273 | static const struct soc_enum da7210_dac_vf_cutoff = | |
274 | SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt); | |
275 | ||
276 | static const struct soc_enum da7210_adc_vf_cutoff = | |
277 | SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt); | |
278 | ||
5eda1949 AC |
279 | static const char *da7210_hp_mode_txt[] = { |
280 | "Class H", "Class G" | |
281 | }; | |
282 | ||
283 | static const struct soc_enum da7210_hp_mode_sel = | |
284 | SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt); | |
285 | ||
de5eaf84 AC |
286 | /* ALC can be enabled only if noise suppression is disabled */ |
287 | static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol, | |
288 | struct snd_ctl_elem_value *ucontrol) | |
289 | { | |
290 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | |
291 | ||
292 | if (ucontrol->value.integer.value[0]) { | |
293 | /* Check if noise suppression is enabled */ | |
294 | if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) { | |
295 | dev_dbg(codec->dev, | |
296 | "Disable noise suppression to enable ALC\n"); | |
297 | return -EINVAL; | |
298 | } | |
299 | } | |
300 | /* If all conditions are met or we are actually disabling ALC */ | |
301 | return snd_soc_put_volsw(kcontrol, ucontrol); | |
302 | } | |
303 | ||
304 | /* Noise suppression can be enabled only if following conditions are met | |
305 | * ALC disabled | |
306 | * ZC enabled for HP and AUX1 PGA | |
307 | * INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB | |
308 | * AUX1_L_VOL and AUX1_R_VOL >= 6 dB | |
309 | */ | |
310 | static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol, | |
311 | struct snd_ctl_elem_value *ucontrol) | |
312 | { | |
313 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | |
314 | u8 val; | |
315 | ||
316 | if (ucontrol->value.integer.value[0]) { | |
317 | /* Check if ALC is enabled */ | |
318 | if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN) | |
319 | goto err; | |
320 | ||
321 | /* Check ZC for HP and AUX1 PGA */ | |
322 | if ((snd_soc_read(codec, DA7210_ZERO_CROSS) & | |
323 | (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | | |
324 | DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC | | |
325 | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC)) | |
326 | goto err; | |
327 | ||
328 | /* Check INPGA_L_VOL and INPGA_R_VOL */ | |
329 | val = snd_soc_read(codec, DA7210_IN_GAIN); | |
330 | if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) || | |
331 | (((val & DA7210_INPGA_R_VOL) >> 4) < | |
332 | DA7210_INPGA_MIN_VOL_NS)) | |
333 | goto err; | |
334 | ||
335 | /* Check AUX1_L_VOL and AUX1_R_VOL */ | |
336 | if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) < | |
337 | DA7210_AUX1_MIN_VOL_NS) || | |
338 | ((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) < | |
339 | DA7210_AUX1_MIN_VOL_NS)) | |
340 | goto err; | |
341 | } | |
342 | /* If all conditions are met or we are actually disabling Noise sup */ | |
343 | return snd_soc_put_volsw(kcontrol, ucontrol); | |
344 | ||
345 | err: | |
346 | return -EINVAL; | |
347 | } | |
348 | ||
a7e7cd5b KM |
349 | static const struct snd_kcontrol_new da7210_snd_controls[] = { |
350 | ||
351 | SOC_DOUBLE_R_TLV("HeadPhone Playback Volume", | |
352 | DA7210_HP_L_VOL, DA7210_HP_R_VOL, | |
353 | 0, 0x3F, 0, hp_out_tlv), | |
52082d8f AC |
354 | SOC_DOUBLE_R_TLV("Digital Playback Volume", |
355 | DA7210_DAC_L, DA7210_DAC_R, | |
356 | 0, 0x77, 1, dac_gain_tlv), | |
357 | SOC_DOUBLE_R_TLV("Lineout Playback Volume", | |
358 | DA7210_OUT1_L, DA7210_OUT1_R, | |
359 | 0, 0x3f, 0, lineout_vol_tlv), | |
360 | SOC_SINGLE_TLV("Mono Playback Volume", DA7210_OUT2, 0, 0x7, 0, | |
361 | mono_vol_tlv), | |
0ee6e9e7 | 362 | |
24b6f263 AC |
363 | SOC_DOUBLE_R_TLV("Mic Capture Volume", |
364 | DA7210_MIC_L, DA7210_MIC_R, | |
365 | 0, 0x5, 0, mic_vol_tlv), | |
366 | SOC_DOUBLE_R_TLV("Aux1 Capture Volume", | |
367 | DA7210_AUX1_L, DA7210_AUX1_R, | |
368 | 0, 0x3f, 0, aux1_vol_tlv), | |
369 | SOC_SINGLE_TLV("Aux2 Capture Volume", DA7210_AUX2, 0, 0x3, 0, | |
370 | aux2_vol_tlv), | |
371 | SOC_DOUBLE_TLV("In PGA Capture Volume", DA7210_IN_GAIN, 0, 4, 0xF, 0, | |
372 | inpga_gain_tlv), | |
373 | ||
0ee6e9e7 AC |
374 | /* DAC Equalizer controls */ |
375 | SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0), | |
376 | SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1, | |
377 | eq_gain_tlv), | |
378 | SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1, | |
379 | eq_gain_tlv), | |
380 | SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1, | |
381 | eq_gain_tlv), | |
382 | SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1, | |
383 | eq_gain_tlv), | |
384 | SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1, | |
385 | eq_gain_tlv), | |
386 | ||
387 | /* ADC Equalizer controls */ | |
388 | SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0), | |
389 | SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3, | |
390 | 1, adc_eq_master_gain_tlv), | |
391 | SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1, | |
392 | eq_gain_tlv), | |
393 | SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1, | |
394 | eq_gain_tlv), | |
395 | SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1, | |
396 | eq_gain_tlv), | |
397 | SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1, | |
398 | eq_gain_tlv), | |
399 | SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1, | |
400 | eq_gain_tlv), | |
4ced2b96 AC |
401 | |
402 | SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0), | |
403 | SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff), | |
404 | SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0), | |
405 | SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff), | |
406 | ||
407 | SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0), | |
408 | SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff), | |
409 | SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0), | |
410 | SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff), | |
5eda1949 AC |
411 | |
412 | /* Mute controls */ | |
413 | SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0), | |
414 | SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0), | |
415 | SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0), | |
416 | SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0), | |
417 | SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0), | |
418 | ||
419 | /* Zero cross controls */ | |
420 | SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0), | |
421 | SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0), | |
422 | SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0), | |
423 | SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0), | |
424 | ||
425 | SOC_ENUM("Headphone Class", da7210_hp_mode_sel), | |
de5eaf84 AC |
426 | |
427 | /* ALC controls */ | |
428 | SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0, | |
429 | snd_soc_get_volsw, da7210_put_alc_sw), | |
430 | SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0), | |
431 | SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0), | |
432 | SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0), | |
433 | SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0), | |
434 | SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0), | |
435 | SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0), | |
436 | ||
437 | SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1, | |
438 | 0, snd_soc_get_volsw, da7210_put_noise_sup_sw), | |
a7e7cd5b KM |
439 | }; |
440 | ||
6950c60d AC |
441 | /* |
442 | * DAPM Controls | |
443 | * | |
444 | * Current DAPM implementation covers almost all codec components e.g. IOs, | |
445 | * mixers, PGAs,ADC and DAC. | |
446 | */ | |
447 | /* In Mixer Left */ | |
448 | static const struct snd_kcontrol_new da7210_dapm_inmixl_controls[] = { | |
449 | SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_L, 0, 1, 0), | |
450 | SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_L, 1, 1, 0), | |
24b6f263 AC |
451 | SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_INMIX_L, 2, 1, 0), |
452 | SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_L, 3, 1, 0), | |
453 | SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_INMIX_L, 4, 1, 0), | |
6950c60d AC |
454 | }; |
455 | ||
456 | /* In Mixer Right */ | |
457 | static const struct snd_kcontrol_new da7210_dapm_inmixr_controls[] = { | |
458 | SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_R, 0, 1, 0), | |
459 | SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_R, 1, 1, 0), | |
24b6f263 AC |
460 | SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_INMIX_R, 2, 1, 0), |
461 | SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_R, 3, 1, 0), | |
462 | SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_INMIX_R, 4, 1, 0), | |
6950c60d AC |
463 | }; |
464 | ||
465 | /* Out Mixer Left */ | |
466 | static const struct snd_kcontrol_new da7210_dapm_outmixl_controls[] = { | |
24b6f263 AC |
467 | SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_OUTMIX_L, 0, 1, 0), |
468 | SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_L, 1, 1, 0), | |
469 | SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_L, 2, 1, 0), | |
470 | SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_L, 3, 1, 0), | |
6950c60d AC |
471 | SOC_DAPM_SINGLE("DAC Left Switch", DA7210_OUTMIX_L, 4, 1, 0), |
472 | }; | |
473 | ||
474 | /* Out Mixer Right */ | |
475 | static const struct snd_kcontrol_new da7210_dapm_outmixr_controls[] = { | |
24b6f263 AC |
476 | SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_OUTMIX_R, 0, 1, 0), |
477 | SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_R, 1, 1, 0), | |
478 | SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_R, 2, 1, 0), | |
479 | SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_R, 3, 1, 0), | |
6950c60d AC |
480 | SOC_DAPM_SINGLE("DAC Right Switch", DA7210_OUTMIX_R, 4, 1, 0), |
481 | }; | |
482 | ||
52082d8f AC |
483 | /* Mono Mixer */ |
484 | static const struct snd_kcontrol_new da7210_dapm_monomix_controls[] = { | |
24b6f263 AC |
485 | SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUT2, 3, 1, 0), |
486 | SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUT2, 4, 1, 0), | |
52082d8f AC |
487 | SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_OUT2, 5, 1, 0), |
488 | SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_OUT2, 6, 1, 0), | |
489 | }; | |
490 | ||
6950c60d AC |
491 | /* DAPM widgets */ |
492 | static const struct snd_soc_dapm_widget da7210_dapm_widgets[] = { | |
493 | /* Input Side */ | |
494 | /* Input Lines */ | |
495 | SND_SOC_DAPM_INPUT("MICL"), | |
496 | SND_SOC_DAPM_INPUT("MICR"), | |
24b6f263 AC |
497 | SND_SOC_DAPM_INPUT("AUX1L"), |
498 | SND_SOC_DAPM_INPUT("AUX1R"), | |
499 | SND_SOC_DAPM_INPUT("AUX2"), | |
6950c60d AC |
500 | |
501 | /* Input PGAs */ | |
502 | SND_SOC_DAPM_PGA("Mic Left", DA7210_STARTUP3, 0, 1, NULL, 0), | |
503 | SND_SOC_DAPM_PGA("Mic Right", DA7210_STARTUP3, 1, 1, NULL, 0), | |
24b6f263 AC |
504 | SND_SOC_DAPM_PGA("Aux1 Left", DA7210_STARTUP3, 2, 1, NULL, 0), |
505 | SND_SOC_DAPM_PGA("Aux1 Right", DA7210_STARTUP3, 3, 1, NULL, 0), | |
506 | SND_SOC_DAPM_PGA("Aux2 Mono", DA7210_STARTUP3, 4, 1, NULL, 0), | |
6950c60d AC |
507 | |
508 | SND_SOC_DAPM_PGA("INPGA Left", DA7210_INMIX_L, 7, 0, NULL, 0), | |
509 | SND_SOC_DAPM_PGA("INPGA Right", DA7210_INMIX_R, 7, 0, NULL, 0), | |
510 | ||
24b6f263 AC |
511 | /* MICBIAS */ |
512 | SND_SOC_DAPM_SUPPLY("Mic Bias", DA7210_MIC_L, 6, 0, NULL, 0), | |
513 | ||
6950c60d AC |
514 | /* Input Mixers */ |
515 | SND_SOC_DAPM_MIXER("In Mixer Left", SND_SOC_NOPM, 0, 0, | |
516 | &da7210_dapm_inmixl_controls[0], | |
517 | ARRAY_SIZE(da7210_dapm_inmixl_controls)), | |
518 | ||
519 | SND_SOC_DAPM_MIXER("In Mixer Right", SND_SOC_NOPM, 0, 0, | |
520 | &da7210_dapm_inmixr_controls[0], | |
521 | ARRAY_SIZE(da7210_dapm_inmixr_controls)), | |
522 | ||
523 | /* ADCs */ | |
524 | SND_SOC_DAPM_ADC("ADC Left", "Capture", DA7210_STARTUP3, 5, 1), | |
525 | SND_SOC_DAPM_ADC("ADC Right", "Capture", DA7210_STARTUP3, 6, 1), | |
526 | ||
527 | /* Output Side */ | |
528 | /* DACs */ | |
529 | SND_SOC_DAPM_DAC("DAC Left", "Playback", DA7210_STARTUP2, 5, 1), | |
530 | SND_SOC_DAPM_DAC("DAC Right", "Playback", DA7210_STARTUP2, 6, 1), | |
531 | ||
532 | /* Output Mixers */ | |
533 | SND_SOC_DAPM_MIXER("Out Mixer Left", SND_SOC_NOPM, 0, 0, | |
534 | &da7210_dapm_outmixl_controls[0], | |
535 | ARRAY_SIZE(da7210_dapm_outmixl_controls)), | |
536 | ||
537 | SND_SOC_DAPM_MIXER("Out Mixer Right", SND_SOC_NOPM, 0, 0, | |
538 | &da7210_dapm_outmixr_controls[0], | |
539 | ARRAY_SIZE(da7210_dapm_outmixr_controls)), | |
540 | ||
52082d8f AC |
541 | SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, |
542 | &da7210_dapm_monomix_controls[0], | |
543 | ARRAY_SIZE(da7210_dapm_monomix_controls)), | |
544 | ||
6950c60d AC |
545 | /* Output PGAs */ |
546 | SND_SOC_DAPM_PGA("OUTPGA Left Enable", DA7210_OUTMIX_L, 7, 0, NULL, 0), | |
547 | SND_SOC_DAPM_PGA("OUTPGA Right Enable", DA7210_OUTMIX_R, 7, 0, NULL, 0), | |
548 | ||
52082d8f AC |
549 | SND_SOC_DAPM_PGA("Out1 Left", DA7210_STARTUP2, 0, 1, NULL, 0), |
550 | SND_SOC_DAPM_PGA("Out1 Right", DA7210_STARTUP2, 1, 1, NULL, 0), | |
551 | SND_SOC_DAPM_PGA("Out2 Mono", DA7210_STARTUP2, 2, 1, NULL, 0), | |
6950c60d AC |
552 | SND_SOC_DAPM_PGA("Headphone Left", DA7210_STARTUP2, 3, 1, NULL, 0), |
553 | SND_SOC_DAPM_PGA("Headphone Right", DA7210_STARTUP2, 4, 1, NULL, 0), | |
554 | ||
555 | /* Output Lines */ | |
52082d8f AC |
556 | SND_SOC_DAPM_OUTPUT("OUT1L"), |
557 | SND_SOC_DAPM_OUTPUT("OUT1R"), | |
6950c60d AC |
558 | SND_SOC_DAPM_OUTPUT("HPL"), |
559 | SND_SOC_DAPM_OUTPUT("HPR"), | |
52082d8f | 560 | SND_SOC_DAPM_OUTPUT("OUT2"), |
6950c60d AC |
561 | }; |
562 | ||
563 | /* DAPM audio route definition */ | |
564 | static const struct snd_soc_dapm_route da7210_audio_map[] = { | |
565 | /* Dest Connecting Widget source */ | |
566 | /* Input path */ | |
567 | {"Mic Left", NULL, "MICL"}, | |
568 | {"Mic Right", NULL, "MICR"}, | |
24b6f263 AC |
569 | {"Aux1 Left", NULL, "AUX1L"}, |
570 | {"Aux1 Right", NULL, "AUX1R"}, | |
571 | {"Aux2 Mono", NULL, "AUX2"}, | |
6950c60d AC |
572 | |
573 | {"In Mixer Left", "Mic Left Switch", "Mic Left"}, | |
574 | {"In Mixer Left", "Mic Right Switch", "Mic Right"}, | |
24b6f263 AC |
575 | {"In Mixer Left", "Aux1 Left Switch", "Aux1 Left"}, |
576 | {"In Mixer Left", "Aux2 Switch", "Aux2 Mono"}, | |
577 | {"In Mixer Left", "Outmix Left Switch", "Out Mixer Left"}, | |
6950c60d AC |
578 | |
579 | {"In Mixer Right", "Mic Right Switch", "Mic Right"}, | |
580 | {"In Mixer Right", "Mic Left Switch", "Mic Left"}, | |
24b6f263 AC |
581 | {"In Mixer Right", "Aux1 Right Switch", "Aux1 Right"}, |
582 | {"In Mixer Right", "Aux2 Switch", "Aux2 Mono"}, | |
583 | {"In Mixer Right", "Outmix Right Switch", "Out Mixer Right"}, | |
6950c60d AC |
584 | |
585 | {"INPGA Left", NULL, "In Mixer Left"}, | |
586 | {"ADC Left", NULL, "INPGA Left"}, | |
587 | ||
588 | {"INPGA Right", NULL, "In Mixer Right"}, | |
589 | {"ADC Right", NULL, "INPGA Right"}, | |
590 | ||
591 | /* Output path */ | |
24b6f263 AC |
592 | {"Out Mixer Left", "Aux1 Left Switch", "Aux1 Left"}, |
593 | {"Out Mixer Left", "Aux2 Switch", "Aux2 Mono"}, | |
594 | {"Out Mixer Left", "INPGA Left Switch", "INPGA Left"}, | |
595 | {"Out Mixer Left", "INPGA Right Switch", "INPGA Right"}, | |
6950c60d | 596 | {"Out Mixer Left", "DAC Left Switch", "DAC Left"}, |
24b6f263 AC |
597 | |
598 | {"Out Mixer Right", "Aux1 Right Switch", "Aux1 Right"}, | |
599 | {"Out Mixer Right", "Aux2 Switch", "Aux2 Mono"}, | |
600 | {"Out Mixer Right", "INPGA Right Switch", "INPGA Right"}, | |
601 | {"Out Mixer Right", "INPGA Left Switch", "INPGA Left"}, | |
6950c60d AC |
602 | {"Out Mixer Right", "DAC Right Switch", "DAC Right"}, |
603 | ||
24b6f263 AC |
604 | {"Mono Mixer", "INPGA Right Switch", "INPGA Right"}, |
605 | {"Mono Mixer", "INPGA Left Switch", "INPGA Left"}, | |
52082d8f AC |
606 | {"Mono Mixer", "Outmix Right Switch", "Out Mixer Right"}, |
607 | {"Mono Mixer", "Outmix Left Switch", "Out Mixer Left"}, | |
608 | ||
6950c60d AC |
609 | {"OUTPGA Left Enable", NULL, "Out Mixer Left"}, |
610 | {"OUTPGA Right Enable", NULL, "Out Mixer Right"}, | |
611 | ||
52082d8f AC |
612 | {"Out1 Left", NULL, "OUTPGA Left Enable"}, |
613 | {"OUT1L", NULL, "Out1 Left"}, | |
614 | ||
615 | {"Out1 Right", NULL, "OUTPGA Right Enable"}, | |
616 | {"OUT1R", NULL, "Out1 Right"}, | |
617 | ||
6950c60d AC |
618 | {"Headphone Left", NULL, "OUTPGA Left Enable"}, |
619 | {"HPL", NULL, "Headphone Left"}, | |
620 | ||
621 | {"Headphone Right", NULL, "OUTPGA Right Enable"}, | |
622 | {"HPR", NULL, "Headphone Right"}, | |
52082d8f AC |
623 | |
624 | {"Out2 Mono", NULL, "Mono Mixer"}, | |
625 | {"OUT2", NULL, "Out2 Mono"}, | |
6950c60d AC |
626 | }; |
627 | ||
98615454 KM |
628 | /* Codec private data */ |
629 | struct da7210_priv { | |
33593b52 | 630 | struct regmap *regmap; |
98615454 KM |
631 | }; |
632 | ||
33593b52 | 633 | static struct reg_default da7210_reg_defaults[] = { |
33593b52 | 634 | { 0x01, 0x11 }, |
33593b52 AC |
635 | { 0x03, 0x00 }, |
636 | { 0x04, 0x00 }, | |
637 | { 0x05, 0x00 }, | |
638 | { 0x06, 0x00 }, | |
639 | { 0x07, 0x00 }, | |
640 | { 0x08, 0x00 }, | |
641 | { 0x09, 0x00 }, | |
642 | { 0x0a, 0x00 }, | |
643 | { 0x0b, 0x00 }, | |
644 | { 0x0c, 0x00 }, | |
645 | { 0x0d, 0x00 }, | |
646 | { 0x0e, 0x00 }, | |
647 | { 0x0f, 0x08 }, | |
648 | { 0x10, 0x00 }, | |
649 | { 0x11, 0x00 }, | |
650 | { 0x12, 0x00 }, | |
651 | { 0x13, 0x00 }, | |
652 | { 0x14, 0x08 }, | |
653 | { 0x15, 0x10 }, | |
654 | { 0x16, 0x10 }, | |
655 | { 0x17, 0x54 }, | |
656 | { 0x18, 0x40 }, | |
657 | { 0x19, 0x00 }, | |
658 | { 0x1a, 0x00 }, | |
659 | { 0x1b, 0x00 }, | |
660 | { 0x1c, 0x00 }, | |
661 | { 0x1d, 0x00 }, | |
662 | { 0x1e, 0x00 }, | |
663 | { 0x1f, 0x00 }, | |
664 | { 0x20, 0x00 }, | |
665 | { 0x21, 0x00 }, | |
666 | { 0x22, 0x00 }, | |
667 | { 0x23, 0x02 }, | |
668 | { 0x24, 0x00 }, | |
669 | { 0x25, 0x76 }, | |
670 | { 0x26, 0x00 }, | |
671 | { 0x27, 0x00 }, | |
672 | { 0x28, 0x04 }, | |
673 | { 0x29, 0x00 }, | |
674 | { 0x2a, 0x00 }, | |
675 | { 0x2b, 0x30 }, | |
676 | { 0x2c, 0x2A }, | |
33593b52 AC |
677 | { 0x83, 0x00 }, |
678 | { 0x84, 0x00 }, | |
679 | { 0x85, 0x00 }, | |
680 | { 0x86, 0x00 }, | |
681 | { 0x87, 0x00 }, | |
682 | { 0x88, 0x00 }, | |
98615454 KM |
683 | }; |
684 | ||
33593b52 AC |
685 | static bool da7210_readable_register(struct device *dev, unsigned int reg) |
686 | { | |
687 | switch (reg) { | |
688 | case DA7210_A_HID_UNLOCK: | |
689 | case DA7210_A_TEST_UNLOCK: | |
690 | case DA7210_A_PLL1: | |
691 | case DA7210_A_CP_MODE: | |
692 | return false; | |
693 | default: | |
694 | return true; | |
695 | } | |
696 | } | |
697 | ||
698 | static bool da7210_volatile_register(struct device *dev, | |
40a49710 | 699 | unsigned int reg) |
98615454 | 700 | { |
40a49710 AL |
701 | switch (reg) { |
702 | case DA7210_STATUS: | |
33593b52 | 703 | return true; |
40a49710 | 704 | default: |
33593b52 | 705 | return false; |
40a49710 | 706 | } |
98615454 | 707 | } |
98615454 KM |
708 | |
709 | /* | |
710 | * Set PCM DAI word length. | |
711 | */ | |
712 | static int da7210_hw_params(struct snd_pcm_substream *substream, | |
713 | struct snd_pcm_hw_params *params, | |
714 | struct snd_soc_dai *dai) | |
715 | { | |
716 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
f0fba2ad | 717 | struct snd_soc_codec *codec = rtd->codec; |
98615454 | 718 | u32 dai_cfg1; |
960b3b4b | 719 | u32 fs, bypass; |
98615454 KM |
720 | |
721 | /* set DAI source to Left and Right ADC */ | |
40a49710 | 722 | snd_soc_write(codec, DA7210_DAI_SRC_SEL, |
98615454 KM |
723 | DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC); |
724 | ||
725 | /* Enable DAI */ | |
40a49710 | 726 | snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN); |
98615454 | 727 | |
40a49710 | 728 | dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1); |
98615454 KM |
729 | |
730 | switch (params_format(params)) { | |
731 | case SNDRV_PCM_FORMAT_S16_LE: | |
732 | dai_cfg1 |= DA7210_DAI_WORD_S16_LE; | |
733 | break; | |
0f8ea586 AC |
734 | case SNDRV_PCM_FORMAT_S20_3LE: |
735 | dai_cfg1 |= DA7210_DAI_WORD_S20_3LE; | |
736 | break; | |
98615454 KM |
737 | case SNDRV_PCM_FORMAT_S24_LE: |
738 | dai_cfg1 |= DA7210_DAI_WORD_S24_LE; | |
739 | break; | |
0f8ea586 AC |
740 | case SNDRV_PCM_FORMAT_S32_LE: |
741 | dai_cfg1 |= DA7210_DAI_WORD_S32_LE; | |
742 | break; | |
98615454 KM |
743 | default: |
744 | return -EINVAL; | |
745 | } | |
746 | ||
40a49710 | 747 | snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1); |
98615454 | 748 | |
98615454 | 749 | switch (params_rate(params)) { |
3a9d6202 KM |
750 | case 8000: |
751 | fs = DA7210_PLL_FS_8000; | |
960b3b4b KM |
752 | bypass = DA7210_PLL_BYP; |
753 | break; | |
754 | case 11025: | |
755 | fs = DA7210_PLL_FS_11025; | |
960b3b4b | 756 | bypass = 0; |
3a9d6202 KM |
757 | break; |
758 | case 12000: | |
759 | fs = DA7210_PLL_FS_12000; | |
960b3b4b | 760 | bypass = DA7210_PLL_BYP; |
3a9d6202 KM |
761 | break; |
762 | case 16000: | |
763 | fs = DA7210_PLL_FS_16000; | |
960b3b4b KM |
764 | bypass = DA7210_PLL_BYP; |
765 | break; | |
766 | case 22050: | |
767 | fs = DA7210_PLL_FS_22050; | |
960b3b4b | 768 | bypass = 0; |
3a9d6202 KM |
769 | break; |
770 | case 32000: | |
771 | fs = DA7210_PLL_FS_32000; | |
960b3b4b KM |
772 | bypass = DA7210_PLL_BYP; |
773 | break; | |
774 | case 44100: | |
775 | fs = DA7210_PLL_FS_44100; | |
960b3b4b | 776 | bypass = 0; |
3a9d6202 | 777 | break; |
98615454 | 778 | case 48000: |
3a9d6202 | 779 | fs = DA7210_PLL_FS_48000; |
960b3b4b KM |
780 | bypass = DA7210_PLL_BYP; |
781 | break; | |
782 | case 88200: | |
783 | fs = DA7210_PLL_FS_88200; | |
960b3b4b | 784 | bypass = 0; |
3a9d6202 KM |
785 | break; |
786 | case 96000: | |
787 | fs = DA7210_PLL_FS_96000; | |
960b3b4b | 788 | bypass = DA7210_PLL_BYP; |
98615454 KM |
789 | break; |
790 | default: | |
791 | return -EINVAL; | |
792 | } | |
793 | ||
960b3b4b KM |
794 | /* Disable active mode */ |
795 | snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0); | |
796 | ||
3a9d6202 | 797 | snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs); |
960b3b4b KM |
798 | snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass); |
799 | ||
800 | /* Enable active mode */ | |
801 | snd_soc_update_bits(codec, DA7210_STARTUP1, | |
802 | DA7210_SC_MST_EN, DA7210_SC_MST_EN); | |
98615454 KM |
803 | |
804 | return 0; | |
805 | } | |
806 | ||
807 | /* | |
808 | * Set DAI mode and Format | |
809 | */ | |
810 | static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt) | |
811 | { | |
812 | struct snd_soc_codec *codec = codec_dai->codec; | |
813 | u32 dai_cfg1; | |
814 | u32 dai_cfg3; | |
815 | ||
40a49710 AL |
816 | dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1); |
817 | dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3); | |
98615454 KM |
818 | |
819 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { | |
820 | case SND_SOC_DAIFMT_CBM_CFM: | |
821 | dai_cfg1 |= DA7210_DAI_MODE_MASTER; | |
822 | break; | |
0f8ea586 AC |
823 | case SND_SOC_DAIFMT_CBS_CFS: |
824 | dai_cfg1 |= DA7210_DAI_MODE_SLAVE; | |
825 | break; | |
98615454 KM |
826 | default: |
827 | return -EINVAL; | |
828 | } | |
829 | ||
830 | /* FIXME | |
831 | * | |
832 | * It support I2S only now | |
833 | */ | |
834 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | |
835 | case SND_SOC_DAIFMT_I2S: | |
836 | dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE; | |
837 | break; | |
0f8ea586 AC |
838 | case SND_SOC_DAIFMT_LEFT_J: |
839 | dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J; | |
840 | break; | |
841 | case SND_SOC_DAIFMT_RIGHT_J: | |
842 | dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J; | |
843 | break; | |
98615454 KM |
844 | default: |
845 | return -EINVAL; | |
846 | } | |
847 | ||
848 | /* FIXME | |
849 | * | |
850 | * It support 64bit data transmission only now | |
851 | */ | |
852 | dai_cfg1 |= DA7210_DAI_FLEN_64BIT; | |
853 | ||
40a49710 AL |
854 | snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1); |
855 | snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3); | |
98615454 KM |
856 | |
857 | return 0; | |
858 | } | |
859 | ||
5eda1949 AC |
860 | static int da7210_mute(struct snd_soc_dai *dai, int mute) |
861 | { | |
862 | struct snd_soc_codec *codec = dai->codec; | |
863 | u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB; | |
864 | ||
865 | if (mute) | |
866 | snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4); | |
867 | else | |
868 | snd_soc_write(codec, DA7210_DAC_HPF, mute_reg); | |
869 | return 0; | |
870 | } | |
871 | ||
0f8ea586 AC |
872 | #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
873 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) | |
98615454 KM |
874 | |
875 | /* DAI operations */ | |
85e7652d | 876 | static const struct snd_soc_dai_ops da7210_dai_ops = { |
98615454 KM |
877 | .hw_params = da7210_hw_params, |
878 | .set_fmt = da7210_set_dai_fmt, | |
5eda1949 | 879 | .digital_mute = da7210_mute, |
98615454 KM |
880 | }; |
881 | ||
f0fba2ad LG |
882 | static struct snd_soc_dai_driver da7210_dai = { |
883 | .name = "da7210-hifi", | |
98615454 KM |
884 | /* playback capabilities */ |
885 | .playback = { | |
886 | .stream_name = "Playback", | |
887 | .channels_min = 1, | |
888 | .channels_max = 2, | |
889 | .rates = SNDRV_PCM_RATE_8000_96000, | |
890 | .formats = DA7210_FORMATS, | |
891 | }, | |
892 | /* capture capabilities */ | |
893 | .capture = { | |
894 | .stream_name = "Capture", | |
895 | .channels_min = 1, | |
896 | .channels_max = 2, | |
897 | .rates = SNDRV_PCM_RATE_8000_96000, | |
898 | .formats = DA7210_FORMATS, | |
899 | }, | |
900 | .ops = &da7210_dai_ops, | |
960b3b4b | 901 | .symmetric_rates = 1, |
98615454 | 902 | }; |
98615454 | 903 | |
f0fba2ad | 904 | static int da7210_probe(struct snd_soc_codec *codec) |
98615454 | 905 | { |
f0fba2ad | 906 | struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec); |
40a49710 | 907 | int ret; |
98615454 | 908 | |
f0fba2ad | 909 | dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); |
98615454 | 910 | |
33593b52 AC |
911 | codec->control_data = da7210->regmap; |
912 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP); | |
40a49710 AL |
913 | if (ret < 0) { |
914 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); | |
915 | return ret; | |
916 | } | |
98615454 KM |
917 | |
918 | /* FIXME | |
919 | * | |
920 | * This driver use fixed value here | |
960b3b4b KM |
921 | * And below settings expects MCLK = 12.288MHz |
922 | * | |
923 | * When you select different MCLK, please check... | |
924 | * DA7210_PLL_DIV1 val | |
925 | * DA7210_PLL_DIV2 val | |
926 | * DA7210_PLL_DIV3 val | |
927 | * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx | |
98615454 KM |
928 | */ |
929 | ||
960b3b4b KM |
930 | /* |
931 | * make sure that DA7210 use bypass mode before start up | |
98615454 | 932 | */ |
40a49710 AL |
933 | snd_soc_write(codec, DA7210_STARTUP1, 0); |
934 | snd_soc_write(codec, DA7210_PLL_DIV3, | |
960b3b4b | 935 | DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); |
98615454 KM |
936 | |
937 | /* | |
938 | * ADC settings | |
939 | */ | |
940 | ||
941 | /* Enable Left & Right MIC PGA and Mic Bias */ | |
40a49710 AL |
942 | snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN); |
943 | snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN); | |
98615454 KM |
944 | |
945 | /* Enable Left and Right input PGA */ | |
40a49710 AL |
946 | snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN); |
947 | snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN); | |
98615454 KM |
948 | |
949 | /* Enable Left and Right ADC */ | |
40a49710 | 950 | snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN); |
98615454 KM |
951 | |
952 | /* | |
953 | * DAC settings | |
954 | */ | |
955 | ||
956 | /* Enable Left and Right DAC */ | |
40a49710 | 957 | snd_soc_write(codec, DA7210_DAC_SEL, |
98615454 KM |
958 | DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN | |
959 | DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN); | |
960 | ||
961 | /* Enable Left and Right out PGA */ | |
40a49710 AL |
962 | snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN); |
963 | snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN); | |
98615454 KM |
964 | |
965 | /* Enable Left and Right HeadPhone PGA */ | |
40a49710 | 966 | snd_soc_write(codec, DA7210_HP_CFG, |
98615454 KM |
967 | DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN | |
968 | DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN); | |
969 | ||
5eda1949 AC |
970 | /* Enable ramp mode for DAC gain update */ |
971 | snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN); | |
972 | ||
52082d8f AC |
973 | /* |
974 | * For DA7210 codec, there are two ways to enable/disable analog IOs | |
975 | * and ADC/DAC, | |
976 | * (1) Using "Enable Bit" of register associated with that IO | |
977 | * (or ADC/DAC) | |
978 | * e.g. Mic Left can be enabled using bit 7 of MIC_L(0x7) reg | |
979 | * | |
980 | * (2) Using "Standby Bit" of STARTUP2 or STARTUP3 register | |
981 | * e.g. Mic left can be put to STANDBY using bit 0 of STARTUP3(0x5) | |
982 | * | |
983 | * Out of these two methods, the one using STANDBY bits is preferred | |
984 | * way to enable/disable individual blocks. This is because STANDBY | |
985 | * registers are part of system controller which allows system power | |
986 | * up/down in a controlled, pop-free manner. Also, as per application | |
987 | * note of DA7210, STANDBY register bits are only effective if a | |
988 | * particular IO (or ADC/DAC) is already enabled using enable/disable | |
989 | * register bits. Keeping these things in mind, current DAPM | |
990 | * implementation manipulates only STANDBY bits. | |
991 | * | |
992 | * Overall implementation can be outlined as below, | |
993 | * | |
994 | * - "Enable bit" of an IO or ADC/DAC is used to enable it in probe() | |
995 | * - "STANDBY bit" is controlled by DAPM | |
996 | */ | |
997 | ||
998 | /* Enable Line out amplifiers */ | |
999 | snd_soc_write(codec, DA7210_OUT1_L, DA7210_OUT1_L_EN); | |
1000 | snd_soc_write(codec, DA7210_OUT1_R, DA7210_OUT1_R_EN); | |
1001 | snd_soc_write(codec, DA7210_OUT2, DA7210_OUT2_EN | | |
1002 | DA7210_OUT2_OUTMIX_L | DA7210_OUT2_OUTMIX_R); | |
1003 | ||
24b6f263 AC |
1004 | /* Enable Aux1 */ |
1005 | snd_soc_write(codec, DA7210_AUX1_L, DA7210_AUX1_L_EN); | |
1006 | snd_soc_write(codec, DA7210_AUX1_R, DA7210_AUX1_R_EN); | |
1007 | /* Enable Aux2 */ | |
1008 | snd_soc_write(codec, DA7210_AUX2, DA7210_AUX2_EN); | |
1009 | ||
98615454 | 1010 | /* Diable PLL and bypass it */ |
40a49710 | 1011 | snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000); |
98615454 | 1012 | |
960b3b4b KM |
1013 | /* |
1014 | * If 48kHz sound came, it use bypass mode, | |
1015 | * and when it is 44.1kHz, it use PLL. | |
1016 | * | |
1017 | * This time, this driver sets PLL always ON | |
1018 | * and controls bypass/PLL mode by switching | |
1019 | * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit. | |
1020 | * see da7210_hw_params | |
1021 | */ | |
40a49710 AL |
1022 | snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */ |
1023 | snd_soc_write(codec, DA7210_PLL_DIV2, 0x99); | |
1024 | snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A | | |
98615454 | 1025 | DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP); |
960b3b4b KM |
1026 | snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN); |
1027 | ||
1028 | /* As suggested by Dialog */ | |
33593b52 AC |
1029 | /* unlock */ |
1030 | regmap_write(da7210->regmap, DA7210_A_HID_UNLOCK, 0x8B); | |
1031 | regmap_write(da7210->regmap, DA7210_A_TEST_UNLOCK, 0xB4); | |
1032 | regmap_write(da7210->regmap, DA7210_A_PLL1, 0x01); | |
1033 | regmap_write(da7210->regmap, DA7210_A_CP_MODE, 0x7C); | |
1034 | /* re-lock */ | |
1035 | regmap_write(da7210->regmap, DA7210_A_HID_UNLOCK, 0x00); | |
1036 | regmap_write(da7210->regmap, DA7210_A_TEST_UNLOCK, 0x00); | |
98615454 KM |
1037 | |
1038 | /* Activate all enabled subsystem */ | |
40a49710 | 1039 | snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN); |
98615454 | 1040 | |
f0fba2ad | 1041 | dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION); |
98615454 | 1042 | |
f0fba2ad | 1043 | return 0; |
98615454 KM |
1044 | } |
1045 | ||
f0fba2ad | 1046 | static struct snd_soc_codec_driver soc_codec_dev_da7210 = { |
4c62ed9b | 1047 | .probe = da7210_probe, |
a6f096f3 MB |
1048 | |
1049 | .controls = da7210_snd_controls, | |
1050 | .num_controls = ARRAY_SIZE(da7210_snd_controls), | |
6950c60d AC |
1051 | |
1052 | .dapm_widgets = da7210_dapm_widgets, | |
1053 | .num_dapm_widgets = ARRAY_SIZE(da7210_dapm_widgets), | |
1054 | .dapm_routes = da7210_audio_map, | |
1055 | .num_dapm_routes = ARRAY_SIZE(da7210_audio_map), | |
f0fba2ad LG |
1056 | }; |
1057 | ||
33593b52 AC |
1058 | static struct regmap_config da7210_regmap = { |
1059 | .reg_bits = 8, | |
1060 | .val_bits = 8, | |
1061 | ||
1062 | .reg_defaults = da7210_reg_defaults, | |
1063 | .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults), | |
1064 | .volatile_reg = da7210_volatile_register, | |
1065 | .readable_reg = da7210_readable_register, | |
1066 | .cache_type = REGCACHE_RBTREE, | |
1067 | }; | |
1068 | ||
98615454 | 1069 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
735fe4cf MB |
1070 | static int __devinit da7210_i2c_probe(struct i2c_client *i2c, |
1071 | const struct i2c_device_id *id) | |
98615454 KM |
1072 | { |
1073 | struct da7210_priv *da7210; | |
98615454 KM |
1074 | int ret; |
1075 | ||
306bf6b1 AL |
1076 | da7210 = devm_kzalloc(&i2c->dev, sizeof(struct da7210_priv), |
1077 | GFP_KERNEL); | |
98615454 KM |
1078 | if (!da7210) |
1079 | return -ENOMEM; | |
1080 | ||
98615454 | 1081 | i2c_set_clientdata(i2c, da7210); |
33593b52 AC |
1082 | |
1083 | da7210->regmap = regmap_init_i2c(i2c, &da7210_regmap); | |
1084 | if (IS_ERR(da7210->regmap)) { | |
1085 | ret = PTR_ERR(da7210->regmap); | |
1086 | dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret); | |
1087 | return ret; | |
1088 | } | |
98615454 | 1089 | |
f0fba2ad LG |
1090 | ret = snd_soc_register_codec(&i2c->dev, |
1091 | &soc_codec_dev_da7210, &da7210_dai, 1); | |
33593b52 AC |
1092 | if (ret < 0) { |
1093 | dev_err(&i2c->dev, "Failed to register codec: %d\n", ret); | |
1094 | goto err_regmap; | |
1095 | } | |
1096 | return ret; | |
1097 | ||
1098 | err_regmap: | |
1099 | regmap_exit(da7210->regmap); | |
1100 | ||
98615454 KM |
1101 | return ret; |
1102 | } | |
1103 | ||
735fe4cf | 1104 | static int __devexit da7210_i2c_remove(struct i2c_client *client) |
98615454 | 1105 | { |
33593b52 AC |
1106 | struct da7210_priv *da7210 = i2c_get_clientdata(client); |
1107 | ||
f0fba2ad | 1108 | snd_soc_unregister_codec(&client->dev); |
33593b52 | 1109 | regmap_exit(da7210->regmap); |
98615454 KM |
1110 | return 0; |
1111 | } | |
1112 | ||
1113 | static const struct i2c_device_id da7210_i2c_id[] = { | |
1114 | { "da7210", 0 }, | |
1115 | { } | |
1116 | }; | |
1117 | MODULE_DEVICE_TABLE(i2c, da7210_i2c_id); | |
1118 | ||
1119 | /* I2C codec control layer */ | |
1120 | static struct i2c_driver da7210_i2c_driver = { | |
1121 | .driver = { | |
f0fba2ad | 1122 | .name = "da7210-codec", |
98615454 KM |
1123 | .owner = THIS_MODULE, |
1124 | }, | |
4c62ed9b KM |
1125 | .probe = da7210_i2c_probe, |
1126 | .remove = __devexit_p(da7210_i2c_remove), | |
1127 | .id_table = da7210_i2c_id, | |
98615454 KM |
1128 | }; |
1129 | #endif | |
1130 | ||
98615454 KM |
1131 | static int __init da7210_modinit(void) |
1132 | { | |
1133 | int ret = 0; | |
1134 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | |
1135 | ret = i2c_add_driver(&da7210_i2c_driver); | |
1136 | #endif | |
1137 | return ret; | |
1138 | } | |
1139 | module_init(da7210_modinit); | |
1140 | ||
1141 | static void __exit da7210_exit(void) | |
1142 | { | |
1143 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) | |
1144 | i2c_del_driver(&da7210_i2c_driver); | |
1145 | #endif | |
1146 | } | |
1147 | module_exit(da7210_exit); | |
1148 | ||
1149 | MODULE_DESCRIPTION("ASoC DA7210 driver"); | |
1150 | MODULE_AUTHOR("David Chen, Kuninori Morimoto"); | |
1151 | MODULE_LICENSE("GPL"); |