2 * DA7210 ALSA Soc codec driver
4 * Copyright (c) 2009 Dialog Semiconductor
5 * Written by David Chen <Dajun.chen@diasemi.com>
7 * Copyright (C) 2009 Renesas Solutions Corp.
8 * Cleanups by Kuninori Morimoto <morimoto.kuninori@renesas.com>
10 * Tested on SuperH Ecovec24 board with S16/S24 LE in 48KHz using I2S
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.
18 #include <linux/delay.h>
19 #include <linux/i2c.h>
20 #include <linux/spi/spi.h>
21 #include <linux/regmap.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
24 #include <sound/pcm.h>
25 #include <sound/pcm_params.h>
26 #include <sound/soc.h>
27 #include <sound/initval.h>
28 #include <sound/tlv.h>
30 /* DA7210 register space */
31 #define DA7210_PAGE_CONTROL 0x00
32 #define DA7210_CONTROL 0x01
33 #define DA7210_STATUS 0x02
34 #define DA7210_STARTUP1 0x03
35 #define DA7210_STARTUP2 0x04
36 #define DA7210_STARTUP3 0x05
37 #define DA7210_MIC_L 0x07
38 #define DA7210_MIC_R 0x08
39 #define DA7210_AUX1_L 0x09
40 #define DA7210_AUX1_R 0x0A
41 #define DA7210_AUX2 0x0B
42 #define DA7210_IN_GAIN 0x0C
43 #define DA7210_INMIX_L 0x0D
44 #define DA7210_INMIX_R 0x0E
45 #define DA7210_ADC_HPF 0x0F
46 #define DA7210_ADC 0x10
47 #define DA7210_ADC_EQ1_2 0X11
48 #define DA7210_ADC_EQ3_4 0x12
49 #define DA7210_ADC_EQ5 0x13
50 #define DA7210_DAC_HPF 0x14
51 #define DA7210_DAC_L 0x15
52 #define DA7210_DAC_R 0x16
53 #define DA7210_DAC_SEL 0x17
54 #define DA7210_SOFTMUTE 0x18
55 #define DA7210_DAC_EQ1_2 0x19
56 #define DA7210_DAC_EQ3_4 0x1A
57 #define DA7210_DAC_EQ5 0x1B
58 #define DA7210_OUTMIX_L 0x1C
59 #define DA7210_OUTMIX_R 0x1D
60 #define DA7210_OUT1_L 0x1E
61 #define DA7210_OUT1_R 0x1F
62 #define DA7210_OUT2 0x20
63 #define DA7210_HP_L_VOL 0x21
64 #define DA7210_HP_R_VOL 0x22
65 #define DA7210_HP_CFG 0x23
66 #define DA7210_ZERO_CROSS 0x24
67 #define DA7210_DAI_SRC_SEL 0x25
68 #define DA7210_DAI_CFG1 0x26
69 #define DA7210_DAI_CFG3 0x28
70 #define DA7210_PLL_DIV1 0x29
71 #define DA7210_PLL_DIV2 0x2A
72 #define DA7210_PLL_DIV3 0x2B
73 #define DA7210_PLL 0x2C
74 #define DA7210_ALC_MAX 0x83
75 #define DA7210_ALC_MIN 0x84
76 #define DA7210_ALC_NOIS 0x85
77 #define DA7210_ALC_ATT 0x86
78 #define DA7210_ALC_REL 0x87
79 #define DA7210_ALC_DEL 0x88
80 #define DA7210_A_HID_UNLOCK 0x8A
81 #define DA7210_A_TEST_UNLOCK 0x8B
82 #define DA7210_A_PLL1 0x90
83 #define DA7210_A_CP_MODE 0xA7
85 /* STARTUP1 bit fields */
86 #define DA7210_SC_MST_EN (1 << 0)
88 /* MIC_L bit fields */
89 #define DA7210_MICBIAS_EN (1 << 6)
90 #define DA7210_MIC_L_EN (1 << 7)
92 /* MIC_R bit fields */
93 #define DA7210_MIC_R_EN (1 << 7)
95 /* INMIX_L bit fields */
96 #define DA7210_IN_L_EN (1 << 7)
98 /* INMIX_R bit fields */
99 #define DA7210_IN_R_EN (1 << 7)
102 #define DA7210_ADC_ALC_EN (1 << 0)
103 #define DA7210_ADC_L_EN (1 << 3)
104 #define DA7210_ADC_R_EN (1 << 7)
106 /* DAC/ADC HPF fields */
107 #define DA7210_VOICE_F0_MASK (0x7 << 4)
108 #define DA7210_VOICE_F0_25 (1 << 4)
109 #define DA7210_VOICE_EN (1 << 7)
111 /* DAC_SEL bit fields */
112 #define DA7210_DAC_L_SRC_DAI_L (4 << 0)
113 #define DA7210_DAC_L_EN (1 << 3)
114 #define DA7210_DAC_R_SRC_DAI_R (5 << 4)
115 #define DA7210_DAC_R_EN (1 << 7)
117 /* OUTMIX_L bit fields */
118 #define DA7210_OUT_L_EN (1 << 7)
120 /* OUTMIX_R bit fields */
121 #define DA7210_OUT_R_EN (1 << 7)
123 /* HP_CFG bit fields */
124 #define DA7210_HP_2CAP_MODE (1 << 1)
125 #define DA7210_HP_SENSE_EN (1 << 2)
126 #define DA7210_HP_L_EN (1 << 3)
127 #define DA7210_HP_MODE (1 << 6)
128 #define DA7210_HP_R_EN (1 << 7)
130 /* DAI_SRC_SEL bit fields */
131 #define DA7210_DAI_OUT_L_SRC (6 << 0)
132 #define DA7210_DAI_OUT_R_SRC (7 << 4)
134 /* DAI_CFG1 bit fields */
135 #define DA7210_DAI_WORD_S16_LE (0 << 0)
136 #define DA7210_DAI_WORD_S20_3LE (1 << 0)
137 #define DA7210_DAI_WORD_S24_LE (2 << 0)
138 #define DA7210_DAI_WORD_S32_LE (3 << 0)
139 #define DA7210_DAI_FLEN_64BIT (1 << 2)
140 #define DA7210_DAI_MODE_SLAVE (0 << 7)
141 #define DA7210_DAI_MODE_MASTER (1 << 7)
143 /* DAI_CFG3 bit fields */
144 #define DA7210_DAI_FORMAT_I2SMODE (0 << 0)
145 #define DA7210_DAI_FORMAT_LEFT_J (1 << 0)
146 #define DA7210_DAI_FORMAT_RIGHT_J (2 << 0)
147 #define DA7210_DAI_OE (1 << 3)
148 #define DA7210_DAI_EN (1 << 7)
150 /*PLL_DIV3 bit fields */
151 #define DA7210_PLL_DIV_L_MASK (0xF << 0)
152 #define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
153 #define DA7210_PLL_BYP (1 << 6)
156 #define DA7210_PLL_FS_MASK (0xF << 0)
157 #define DA7210_PLL_FS_8000 (0x1 << 0)
158 #define DA7210_PLL_FS_11025 (0x2 << 0)
159 #define DA7210_PLL_FS_12000 (0x3 << 0)
160 #define DA7210_PLL_FS_16000 (0x5 << 0)
161 #define DA7210_PLL_FS_22050 (0x6 << 0)
162 #define DA7210_PLL_FS_24000 (0x7 << 0)
163 #define DA7210_PLL_FS_32000 (0x9 << 0)
164 #define DA7210_PLL_FS_44100 (0xA << 0)
165 #define DA7210_PLL_FS_48000 (0xB << 0)
166 #define DA7210_PLL_FS_88200 (0xE << 0)
167 #define DA7210_PLL_FS_96000 (0xF << 0)
168 #define DA7210_MCLK_DET_EN (0x1 << 5)
169 #define DA7210_MCLK_SRM_EN (0x1 << 6)
170 #define DA7210_PLL_EN (0x1 << 7)
172 /* SOFTMUTE bit fields */
173 #define DA7210_RAMP_EN (1 << 6)
175 /* CONTROL bit fields */
176 #define DA7210_REG_EN (1 << 0)
177 #define DA7210_BIAS_EN (1 << 2)
178 #define DA7210_NOISE_SUP_EN (1 << 3)
180 /* IN_GAIN bit fields */
181 #define DA7210_INPGA_L_VOL (0x0F << 0)
182 #define DA7210_INPGA_R_VOL (0xF0 << 0)
184 /* ZERO_CROSS bit fields */
185 #define DA7210_AUX1_L_ZC (1 << 0)
186 #define DA7210_AUX1_R_ZC (1 << 1)
187 #define DA7210_HP_L_ZC (1 << 6)
188 #define DA7210_HP_R_ZC (1 << 7)
190 /* AUX1_L bit fields */
191 #define DA7210_AUX1_L_VOL (0x3F << 0)
192 #define DA7210_AUX1_L_EN (1 << 7)
194 /* AUX1_R bit fields */
195 #define DA7210_AUX1_R_VOL (0x3F << 0)
196 #define DA7210_AUX1_R_EN (1 << 7)
198 /* AUX2 bit fields */
199 #define DA7210_AUX2_EN (1 << 3)
201 /* Minimum INPGA and AUX1 volume to enable noise suppression */
202 #define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */
203 #define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */
205 /* OUT1_L bit fields */
206 #define DA7210_OUT1_L_EN (1 << 7)
208 /* OUT1_R bit fields */
209 #define DA7210_OUT1_R_EN (1 << 7)
211 /* OUT2 bit fields */
212 #define DA7210_OUT2_OUTMIX_R (1 << 5)
213 #define DA7210_OUT2_OUTMIX_L (1 << 6)
214 #define DA7210_OUT2_EN (1 << 7)
222 u8 mode
; /* 0 = slave, 1 = master */
225 /* PLL dividers table */
226 static const struct pll_div da7210_pll_div
[] = {
227 /* for MASTER mode, fs = 44.1Khz */
228 { 12000000, 2822400, 0xE8, 0x6C, 0x2, 1}, /* MCLK=12Mhz */
229 { 13000000, 2822400, 0xDF, 0x28, 0xC, 1}, /* MCLK=13Mhz */
230 { 13500000, 2822400, 0xDB, 0x0A, 0xD, 1}, /* MCLK=13.5Mhz */
231 { 14400000, 2822400, 0xD4, 0x5A, 0x2, 1}, /* MCLK=14.4Mhz */
232 { 19200000, 2822400, 0xBB, 0x43, 0x9, 1}, /* MCLK=19.2Mhz */
233 { 19680000, 2822400, 0xB9, 0x6D, 0xA, 1}, /* MCLK=19.68Mhz */
234 { 19800000, 2822400, 0xB8, 0xFB, 0xB, 1}, /* MCLK=19.8Mhz */
235 /* for MASTER mode, fs = 48Khz */
236 { 12000000, 3072000, 0xF3, 0x12, 0x7, 1}, /* MCLK=12Mhz */
237 { 13000000, 3072000, 0xE8, 0xFD, 0x5, 1}, /* MCLK=13Mhz */
238 { 13500000, 3072000, 0xE4, 0x82, 0x3, 1}, /* MCLK=13.5Mhz */
239 { 14400000, 3072000, 0xDD, 0x3A, 0x0, 1}, /* MCLK=14.4Mhz */
240 { 19200000, 3072000, 0xC1, 0xEB, 0x8, 1}, /* MCLK=19.2Mhz */
241 { 19680000, 3072000, 0xBF, 0xEC, 0x0, 1}, /* MCLK=19.68Mhz */
242 { 19800000, 3072000, 0xBF, 0x70, 0x0, 1}, /* MCLK=19.8Mhz */
243 /* for SLAVE mode with SRM */
244 { 12000000, 2822400, 0xED, 0xBF, 0x5, 0}, /* MCLK=12Mhz */
245 { 13000000, 2822400, 0xE4, 0x13, 0x0, 0}, /* MCLK=13Mhz */
246 { 13500000, 2822400, 0xDF, 0xC6, 0x8, 0}, /* MCLK=13.5Mhz */
247 { 14400000, 2822400, 0xD8, 0xCA, 0x1, 0}, /* MCLK=14.4Mhz */
248 { 19200000, 2822400, 0xBE, 0x97, 0x9, 0}, /* MCLK=19.2Mhz */
249 { 19680000, 2822400, 0xBC, 0xAC, 0xD, 0}, /* MCLK=19.68Mhz */
250 { 19800000, 2822400, 0xBC, 0x35, 0xE, 0}, /* MCLK=19.8Mhz */
257 #define DA7210_VERSION "0.0.1"
262 * max : 0x3F (+15.0 dB)
264 * min : 0x11 (-54.0 dB)
266 * reserved : 0x00 - 0x0F
268 * Reserved area are considered as "mute".
270 static const DECLARE_TLV_DB_RANGE(hp_out_tlv
,
271 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE
, 0, 1),
272 /* -54 dB to +15 dB */
273 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0)
276 static const DECLARE_TLV_DB_RANGE(lineout_vol_tlv
,
277 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE
, 0, 1),
279 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0)
282 static const DECLARE_TLV_DB_RANGE(mono_vol_tlv
,
283 0x0, 0x2, TLV_DB_SCALE_ITEM(-1800, 0, 1),
285 0x3, 0x7, TLV_DB_SCALE_ITEM(-1800, 600, 0)
288 static const DECLARE_TLV_DB_RANGE(aux1_vol_tlv
,
289 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE
, 0, 1),
291 0x11, 0x3f, TLV_DB_SCALE_ITEM(-4800, 150, 0)
294 static const DECLARE_TLV_DB_SCALE(eq_gain_tlv
, -1050, 150, 0);
295 static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv
, -1800, 600, 1);
296 static const DECLARE_TLV_DB_SCALE(dac_gain_tlv
, -7725, 75, 0);
297 static const DECLARE_TLV_DB_SCALE(mic_vol_tlv
, -600, 600, 0);
298 static const DECLARE_TLV_DB_SCALE(aux2_vol_tlv
, -600, 600, 0);
299 static const DECLARE_TLV_DB_SCALE(inpga_gain_tlv
, -450, 150, 0);
301 /* ADC and DAC high pass filter f0 value */
302 static const char * const da7210_hpf_cutoff_txt
[] = {
303 "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi"
306 static SOC_ENUM_SINGLE_DECL(da7210_dac_hpf_cutoff
,
307 DA7210_DAC_HPF
, 0, da7210_hpf_cutoff_txt
);
309 static SOC_ENUM_SINGLE_DECL(da7210_adc_hpf_cutoff
,
310 DA7210_ADC_HPF
, 0, da7210_hpf_cutoff_txt
);
312 /* ADC and DAC voice (8kHz) high pass cutoff value */
313 static const char * const da7210_vf_cutoff_txt
[] = {
314 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
317 static SOC_ENUM_SINGLE_DECL(da7210_dac_vf_cutoff
,
318 DA7210_DAC_HPF
, 4, da7210_vf_cutoff_txt
);
320 static SOC_ENUM_SINGLE_DECL(da7210_adc_vf_cutoff
,
321 DA7210_ADC_HPF
, 4, da7210_vf_cutoff_txt
);
323 static const char *da7210_hp_mode_txt
[] = {
327 static SOC_ENUM_SINGLE_DECL(da7210_hp_mode_sel
,
328 DA7210_HP_CFG
, 0, da7210_hp_mode_txt
);
330 /* ALC can be enabled only if noise suppression is disabled */
331 static int da7210_put_alc_sw(struct snd_kcontrol
*kcontrol
,
332 struct snd_ctl_elem_value
*ucontrol
)
334 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kcontrol
);
336 if (ucontrol
->value
.integer
.value
[0]) {
337 /* Check if noise suppression is enabled */
338 if (snd_soc_component_read32(component
, DA7210_CONTROL
) & DA7210_NOISE_SUP_EN
) {
339 dev_dbg(component
->dev
,
340 "Disable noise suppression to enable ALC\n");
344 /* If all conditions are met or we are actually disabling ALC */
345 return snd_soc_put_volsw(kcontrol
, ucontrol
);
348 /* Noise suppression can be enabled only if following conditions are met
350 * ZC enabled for HP and AUX1 PGA
351 * INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB
352 * AUX1_L_VOL and AUX1_R_VOL >= 6 dB
354 static int da7210_put_noise_sup_sw(struct snd_kcontrol
*kcontrol
,
355 struct snd_ctl_elem_value
*ucontrol
)
357 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kcontrol
);
360 if (ucontrol
->value
.integer
.value
[0]) {
361 /* Check if ALC is enabled */
362 if (snd_soc_component_read32(component
, DA7210_ADC
) & DA7210_ADC_ALC_EN
)
365 /* Check ZC for HP and AUX1 PGA */
366 if ((snd_soc_component_read32(component
, DA7210_ZERO_CROSS
) &
367 (DA7210_AUX1_L_ZC
| DA7210_AUX1_R_ZC
| DA7210_HP_L_ZC
|
368 DA7210_HP_R_ZC
)) != (DA7210_AUX1_L_ZC
|
369 DA7210_AUX1_R_ZC
| DA7210_HP_L_ZC
| DA7210_HP_R_ZC
))
372 /* Check INPGA_L_VOL and INPGA_R_VOL */
373 val
= snd_soc_component_read32(component
, DA7210_IN_GAIN
);
374 if (((val
& DA7210_INPGA_L_VOL
) < DA7210_INPGA_MIN_VOL_NS
) ||
375 (((val
& DA7210_INPGA_R_VOL
) >> 4) <
376 DA7210_INPGA_MIN_VOL_NS
))
379 /* Check AUX1_L_VOL and AUX1_R_VOL */
380 if (((snd_soc_component_read32(component
, DA7210_AUX1_L
) & DA7210_AUX1_L_VOL
) <
381 DA7210_AUX1_MIN_VOL_NS
) ||
382 ((snd_soc_component_read32(component
, DA7210_AUX1_R
) & DA7210_AUX1_R_VOL
) <
383 DA7210_AUX1_MIN_VOL_NS
))
386 /* If all conditions are met or we are actually disabling Noise sup */
387 return snd_soc_put_volsw(kcontrol
, ucontrol
);
393 static const struct snd_kcontrol_new da7210_snd_controls
[] = {
395 SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
396 DA7210_HP_L_VOL
, DA7210_HP_R_VOL
,
397 0, 0x3F, 0, hp_out_tlv
),
398 SOC_DOUBLE_R_TLV("Digital Playback Volume",
399 DA7210_DAC_L
, DA7210_DAC_R
,
400 0, 0x77, 1, dac_gain_tlv
),
401 SOC_DOUBLE_R_TLV("Lineout Playback Volume",
402 DA7210_OUT1_L
, DA7210_OUT1_R
,
403 0, 0x3f, 0, lineout_vol_tlv
),
404 SOC_SINGLE_TLV("Mono Playback Volume", DA7210_OUT2
, 0, 0x7, 0,
407 SOC_DOUBLE_R_TLV("Mic Capture Volume",
408 DA7210_MIC_L
, DA7210_MIC_R
,
409 0, 0x5, 0, mic_vol_tlv
),
410 SOC_DOUBLE_R_TLV("Aux1 Capture Volume",
411 DA7210_AUX1_L
, DA7210_AUX1_R
,
412 0, 0x3f, 0, aux1_vol_tlv
),
413 SOC_SINGLE_TLV("Aux2 Capture Volume", DA7210_AUX2
, 0, 0x3, 0,
415 SOC_DOUBLE_TLV("In PGA Capture Volume", DA7210_IN_GAIN
, 0, 4, 0xF, 0,
418 /* DAC Equalizer controls */
419 SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5
, 7, 1, 0),
420 SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2
, 0, 0xf, 1,
422 SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2
, 4, 0xf, 1,
424 SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4
, 0, 0xf, 1,
426 SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4
, 4, 0xf, 1,
428 SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5
, 0, 0xf, 1,
431 /* ADC Equalizer controls */
432 SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5
, 7, 1, 0),
433 SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5
, 4, 0x3,
434 1, adc_eq_master_gain_tlv
),
435 SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2
, 0, 0xf, 1,
437 SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2
, 4, 0xf, 1,
439 SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4
, 0, 0xf, 1,
441 SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4
, 4, 0xf, 1,
443 SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5
, 0, 0xf, 1,
446 SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF
, 3, 1, 0),
447 SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff
),
448 SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF
, 7, 1, 0),
449 SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff
),
451 SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF
, 3, 1, 0),
452 SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff
),
453 SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF
, 7, 1, 0),
454 SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff
),
457 SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L
, DA7210_MIC_R
, 3, 1, 0),
458 SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2
, 2, 1, 0),
459 SOC_DOUBLE("ADC Capture Switch", DA7210_ADC
, 2, 6, 1, 0),
460 SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE
, 7, 1, 0),
461 SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE
, 0, 0x7, 0),
463 /* Zero cross controls */
464 SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS
, 0, 1, 1, 0),
465 SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS
, 2, 3, 1, 0),
466 SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS
, 4, 5, 1, 0),
467 SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS
, 6, 7, 1, 0),
469 SOC_ENUM("Headphone Class", da7210_hp_mode_sel
),
472 SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC
, 0, 1, 0,
473 snd_soc_get_volsw
, da7210_put_alc_sw
),
474 SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX
, 0, 0x3F, 0),
475 SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN
, 0, 0x3F, 0),
476 SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS
, 0, 0x3F, 0),
477 SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT
, 0, 0xFF, 0),
478 SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL
, 0, 0xFF, 0),
479 SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL
, 0, 0xFF, 0),
481 SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL
, 3, 1,
482 0, snd_soc_get_volsw
, da7210_put_noise_sup_sw
),
488 * Current DAPM implementation covers almost all codec components e.g. IOs,
489 * mixers, PGAs,ADC and DAC.
492 static const struct snd_kcontrol_new da7210_dapm_inmixl_controls
[] = {
493 SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_L
, 0, 1, 0),
494 SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_L
, 1, 1, 0),
495 SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_INMIX_L
, 2, 1, 0),
496 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_L
, 3, 1, 0),
497 SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_INMIX_L
, 4, 1, 0),
501 static const struct snd_kcontrol_new da7210_dapm_inmixr_controls
[] = {
502 SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_R
, 0, 1, 0),
503 SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_R
, 1, 1, 0),
504 SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_INMIX_R
, 2, 1, 0),
505 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_R
, 3, 1, 0),
506 SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_INMIX_R
, 4, 1, 0),
510 static const struct snd_kcontrol_new da7210_dapm_outmixl_controls
[] = {
511 SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_OUTMIX_L
, 0, 1, 0),
512 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_L
, 1, 1, 0),
513 SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_L
, 2, 1, 0),
514 SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_L
, 3, 1, 0),
515 SOC_DAPM_SINGLE("DAC Left Switch", DA7210_OUTMIX_L
, 4, 1, 0),
518 /* Out Mixer Right */
519 static const struct snd_kcontrol_new da7210_dapm_outmixr_controls
[] = {
520 SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_OUTMIX_R
, 0, 1, 0),
521 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_R
, 1, 1, 0),
522 SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_R
, 2, 1, 0),
523 SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_R
, 3, 1, 0),
524 SOC_DAPM_SINGLE("DAC Right Switch", DA7210_OUTMIX_R
, 4, 1, 0),
528 static const struct snd_kcontrol_new da7210_dapm_monomix_controls
[] = {
529 SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUT2
, 3, 1, 0),
530 SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUT2
, 4, 1, 0),
531 SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_OUT2
, 5, 1, 0),
532 SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_OUT2
, 6, 1, 0),
536 static const struct snd_soc_dapm_widget da7210_dapm_widgets
[] = {
539 SND_SOC_DAPM_INPUT("MICL"),
540 SND_SOC_DAPM_INPUT("MICR"),
541 SND_SOC_DAPM_INPUT("AUX1L"),
542 SND_SOC_DAPM_INPUT("AUX1R"),
543 SND_SOC_DAPM_INPUT("AUX2"),
546 SND_SOC_DAPM_PGA("Mic Left", DA7210_STARTUP3
, 0, 1, NULL
, 0),
547 SND_SOC_DAPM_PGA("Mic Right", DA7210_STARTUP3
, 1, 1, NULL
, 0),
548 SND_SOC_DAPM_PGA("Aux1 Left", DA7210_STARTUP3
, 2, 1, NULL
, 0),
549 SND_SOC_DAPM_PGA("Aux1 Right", DA7210_STARTUP3
, 3, 1, NULL
, 0),
550 SND_SOC_DAPM_PGA("Aux2 Mono", DA7210_STARTUP3
, 4, 1, NULL
, 0),
552 SND_SOC_DAPM_PGA("INPGA Left", DA7210_INMIX_L
, 7, 0, NULL
, 0),
553 SND_SOC_DAPM_PGA("INPGA Right", DA7210_INMIX_R
, 7, 0, NULL
, 0),
556 SND_SOC_DAPM_SUPPLY("Mic Bias", DA7210_MIC_L
, 6, 0, NULL
, 0),
559 SND_SOC_DAPM_MIXER("In Mixer Left", SND_SOC_NOPM
, 0, 0,
560 &da7210_dapm_inmixl_controls
[0],
561 ARRAY_SIZE(da7210_dapm_inmixl_controls
)),
563 SND_SOC_DAPM_MIXER("In Mixer Right", SND_SOC_NOPM
, 0, 0,
564 &da7210_dapm_inmixr_controls
[0],
565 ARRAY_SIZE(da7210_dapm_inmixr_controls
)),
568 SND_SOC_DAPM_ADC("ADC Left", "Capture", DA7210_STARTUP3
, 5, 1),
569 SND_SOC_DAPM_ADC("ADC Right", "Capture", DA7210_STARTUP3
, 6, 1),
573 SND_SOC_DAPM_DAC("DAC Left", "Playback", DA7210_STARTUP2
, 5, 1),
574 SND_SOC_DAPM_DAC("DAC Right", "Playback", DA7210_STARTUP2
, 6, 1),
577 SND_SOC_DAPM_MIXER("Out Mixer Left", SND_SOC_NOPM
, 0, 0,
578 &da7210_dapm_outmixl_controls
[0],
579 ARRAY_SIZE(da7210_dapm_outmixl_controls
)),
581 SND_SOC_DAPM_MIXER("Out Mixer Right", SND_SOC_NOPM
, 0, 0,
582 &da7210_dapm_outmixr_controls
[0],
583 ARRAY_SIZE(da7210_dapm_outmixr_controls
)),
585 SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM
, 0, 0,
586 &da7210_dapm_monomix_controls
[0],
587 ARRAY_SIZE(da7210_dapm_monomix_controls
)),
590 SND_SOC_DAPM_PGA("OUTPGA Left Enable", DA7210_OUTMIX_L
, 7, 0, NULL
, 0),
591 SND_SOC_DAPM_PGA("OUTPGA Right Enable", DA7210_OUTMIX_R
, 7, 0, NULL
, 0),
593 SND_SOC_DAPM_PGA("Out1 Left", DA7210_STARTUP2
, 0, 1, NULL
, 0),
594 SND_SOC_DAPM_PGA("Out1 Right", DA7210_STARTUP2
, 1, 1, NULL
, 0),
595 SND_SOC_DAPM_PGA("Out2 Mono", DA7210_STARTUP2
, 2, 1, NULL
, 0),
596 SND_SOC_DAPM_PGA("Headphone Left", DA7210_STARTUP2
, 3, 1, NULL
, 0),
597 SND_SOC_DAPM_PGA("Headphone Right", DA7210_STARTUP2
, 4, 1, NULL
, 0),
600 SND_SOC_DAPM_OUTPUT("OUT1L"),
601 SND_SOC_DAPM_OUTPUT("OUT1R"),
602 SND_SOC_DAPM_OUTPUT("HPL"),
603 SND_SOC_DAPM_OUTPUT("HPR"),
604 SND_SOC_DAPM_OUTPUT("OUT2"),
607 /* DAPM audio route definition */
608 static const struct snd_soc_dapm_route da7210_audio_map
[] = {
609 /* Dest Connecting Widget source */
611 {"Mic Left", NULL
, "MICL"},
612 {"Mic Right", NULL
, "MICR"},
613 {"Aux1 Left", NULL
, "AUX1L"},
614 {"Aux1 Right", NULL
, "AUX1R"},
615 {"Aux2 Mono", NULL
, "AUX2"},
617 {"In Mixer Left", "Mic Left Switch", "Mic Left"},
618 {"In Mixer Left", "Mic Right Switch", "Mic Right"},
619 {"In Mixer Left", "Aux1 Left Switch", "Aux1 Left"},
620 {"In Mixer Left", "Aux2 Switch", "Aux2 Mono"},
621 {"In Mixer Left", "Outmix Left Switch", "Out Mixer Left"},
623 {"In Mixer Right", "Mic Right Switch", "Mic Right"},
624 {"In Mixer Right", "Mic Left Switch", "Mic Left"},
625 {"In Mixer Right", "Aux1 Right Switch", "Aux1 Right"},
626 {"In Mixer Right", "Aux2 Switch", "Aux2 Mono"},
627 {"In Mixer Right", "Outmix Right Switch", "Out Mixer Right"},
629 {"INPGA Left", NULL
, "In Mixer Left"},
630 {"ADC Left", NULL
, "INPGA Left"},
632 {"INPGA Right", NULL
, "In Mixer Right"},
633 {"ADC Right", NULL
, "INPGA Right"},
636 {"Out Mixer Left", "Aux1 Left Switch", "Aux1 Left"},
637 {"Out Mixer Left", "Aux2 Switch", "Aux2 Mono"},
638 {"Out Mixer Left", "INPGA Left Switch", "INPGA Left"},
639 {"Out Mixer Left", "INPGA Right Switch", "INPGA Right"},
640 {"Out Mixer Left", "DAC Left Switch", "DAC Left"},
642 {"Out Mixer Right", "Aux1 Right Switch", "Aux1 Right"},
643 {"Out Mixer Right", "Aux2 Switch", "Aux2 Mono"},
644 {"Out Mixer Right", "INPGA Right Switch", "INPGA Right"},
645 {"Out Mixer Right", "INPGA Left Switch", "INPGA Left"},
646 {"Out Mixer Right", "DAC Right Switch", "DAC Right"},
648 {"Mono Mixer", "INPGA Right Switch", "INPGA Right"},
649 {"Mono Mixer", "INPGA Left Switch", "INPGA Left"},
650 {"Mono Mixer", "Outmix Right Switch", "Out Mixer Right"},
651 {"Mono Mixer", "Outmix Left Switch", "Out Mixer Left"},
653 {"OUTPGA Left Enable", NULL
, "Out Mixer Left"},
654 {"OUTPGA Right Enable", NULL
, "Out Mixer Right"},
656 {"Out1 Left", NULL
, "OUTPGA Left Enable"},
657 {"OUT1L", NULL
, "Out1 Left"},
659 {"Out1 Right", NULL
, "OUTPGA Right Enable"},
660 {"OUT1R", NULL
, "Out1 Right"},
662 {"Headphone Left", NULL
, "OUTPGA Left Enable"},
663 {"HPL", NULL
, "Headphone Left"},
665 {"Headphone Right", NULL
, "OUTPGA Right Enable"},
666 {"HPR", NULL
, "Headphone Right"},
668 {"Out2 Mono", NULL
, "Mono Mixer"},
669 {"OUT2", NULL
, "Out2 Mono"},
672 /* Codec private data */
674 struct regmap
*regmap
;
675 unsigned int mclk_rate
;
679 static const struct reg_default da7210_reg_defaults
[] = {
732 static bool da7210_readable_register(struct device
*dev
, unsigned int reg
)
735 case DA7210_A_HID_UNLOCK
:
736 case DA7210_A_TEST_UNLOCK
:
738 case DA7210_A_CP_MODE
:
745 static bool da7210_volatile_register(struct device
*dev
,
757 * Set PCM DAI word length.
759 static int da7210_hw_params(struct snd_pcm_substream
*substream
,
760 struct snd_pcm_hw_params
*params
,
761 struct snd_soc_dai
*dai
)
763 struct snd_soc_component
*component
= dai
->component
;
764 struct da7210_priv
*da7210
= snd_soc_component_get_drvdata(component
);
768 /* set DAI source to Left and Right ADC */
769 snd_soc_component_write(component
, DA7210_DAI_SRC_SEL
,
770 DA7210_DAI_OUT_R_SRC
| DA7210_DAI_OUT_L_SRC
);
773 snd_soc_component_write(component
, DA7210_DAI_CFG3
, DA7210_DAI_OE
| DA7210_DAI_EN
);
775 dai_cfg1
= 0xFC & snd_soc_component_read32(component
, DA7210_DAI_CFG1
);
777 switch (params_width(params
)) {
779 dai_cfg1
|= DA7210_DAI_WORD_S16_LE
;
782 dai_cfg1
|= DA7210_DAI_WORD_S20_3LE
;
785 dai_cfg1
|= DA7210_DAI_WORD_S24_LE
;
788 dai_cfg1
|= DA7210_DAI_WORD_S32_LE
;
794 snd_soc_component_write(component
, DA7210_DAI_CFG1
, dai_cfg1
);
796 switch (params_rate(params
)) {
798 fs
= DA7210_PLL_FS_8000
;
802 fs
= DA7210_PLL_FS_11025
;
806 fs
= DA7210_PLL_FS_12000
;
810 fs
= DA7210_PLL_FS_16000
;
814 fs
= DA7210_PLL_FS_22050
;
818 fs
= DA7210_PLL_FS_32000
;
822 fs
= DA7210_PLL_FS_44100
;
826 fs
= DA7210_PLL_FS_48000
;
830 fs
= DA7210_PLL_FS_88200
;
834 fs
= DA7210_PLL_FS_96000
;
841 /* Disable active mode */
842 snd_soc_component_update_bits(component
, DA7210_STARTUP1
, DA7210_SC_MST_EN
, 0);
844 snd_soc_component_update_bits(component
, DA7210_PLL
, DA7210_PLL_FS_MASK
, fs
);
846 if (da7210
->mclk_rate
&& (da7210
->mclk_rate
!= sysclk
)) {
847 /* PLL mode, disable PLL bypass */
848 snd_soc_component_update_bits(component
, DA7210_PLL_DIV3
, DA7210_PLL_BYP
, 0);
850 if (!da7210
->master
) {
851 /* PLL slave mode, also enable SRM */
852 snd_soc_component_update_bits(component
, DA7210_PLL
,
853 (DA7210_MCLK_SRM_EN
|
855 (DA7210_MCLK_SRM_EN
|
856 DA7210_MCLK_DET_EN
));
859 /* PLL bypass mode, enable PLL bypass and Auto Detection */
860 snd_soc_component_update_bits(component
, DA7210_PLL
, DA7210_MCLK_DET_EN
,
862 snd_soc_component_update_bits(component
, DA7210_PLL_DIV3
, DA7210_PLL_BYP
,
865 /* Enable active mode */
866 snd_soc_component_update_bits(component
, DA7210_STARTUP1
,
867 DA7210_SC_MST_EN
, DA7210_SC_MST_EN
);
873 * Set DAI mode and Format
875 static int da7210_set_dai_fmt(struct snd_soc_dai
*codec_dai
, u32 fmt
)
877 struct snd_soc_component
*component
= codec_dai
->component
;
878 struct da7210_priv
*da7210
= snd_soc_component_get_drvdata(component
);
882 dai_cfg1
= 0x7f & snd_soc_component_read32(component
, DA7210_DAI_CFG1
);
883 dai_cfg3
= 0xfc & snd_soc_component_read32(component
, DA7210_DAI_CFG3
);
885 if ((snd_soc_component_read32(component
, DA7210_PLL
) & DA7210_PLL_EN
) &&
886 (!(snd_soc_component_read32(component
, DA7210_PLL_DIV3
) & DA7210_PLL_BYP
)))
889 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
890 case SND_SOC_DAIFMT_CBM_CFM
:
892 dai_cfg1
|= DA7210_DAI_MODE_MASTER
;
894 case SND_SOC_DAIFMT_CBS_CFS
:
896 dai_cfg1
|= DA7210_DAI_MODE_SLAVE
;
904 * It support I2S only now
906 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
907 case SND_SOC_DAIFMT_I2S
:
908 dai_cfg3
|= DA7210_DAI_FORMAT_I2SMODE
;
910 case SND_SOC_DAIFMT_LEFT_J
:
911 dai_cfg3
|= DA7210_DAI_FORMAT_LEFT_J
;
913 case SND_SOC_DAIFMT_RIGHT_J
:
914 dai_cfg3
|= DA7210_DAI_FORMAT_RIGHT_J
;
922 * It support 64bit data transmission only now
924 dai_cfg1
|= DA7210_DAI_FLEN_64BIT
;
926 snd_soc_component_write(component
, DA7210_DAI_CFG1
, dai_cfg1
);
927 snd_soc_component_write(component
, DA7210_DAI_CFG3
, dai_cfg3
);
932 static int da7210_mute(struct snd_soc_dai
*dai
, int mute
)
934 struct snd_soc_component
*component
= dai
->component
;
935 u8 mute_reg
= snd_soc_component_read32(component
, DA7210_DAC_HPF
) & 0xFB;
938 snd_soc_component_write(component
, DA7210_DAC_HPF
, mute_reg
| 0x4);
940 snd_soc_component_write(component
, DA7210_DAC_HPF
, mute_reg
);
944 #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
945 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
947 static int da7210_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
948 int clk_id
, unsigned int freq
, int dir
)
950 struct snd_soc_component
*component
= codec_dai
->component
;
951 struct da7210_priv
*da7210
= snd_soc_component_get_drvdata(component
);
954 case DA7210_CLKSRC_MCLK
:
963 da7210
->mclk_rate
= freq
;
966 dev_err(codec_dai
->dev
, "Unsupported MCLK value %d\n",
972 dev_err(codec_dai
->dev
, "Unknown clock source %d\n", clk_id
);
978 * da7210_set_dai_pll :Configure the codec PLL
979 * @param codec_dai : pointer to codec DAI
980 * @param pll_id : da7210 has only one pll, so pll_id is always zero
981 * @param fref : MCLK frequency, should be < 20MHz
982 * @param fout : FsDM value, Refer page 44 & 45 of datasheet
983 * @return int : Zero for success, negative error code for error
985 * Note: Supported PLL input frequencies are 12MHz, 13MHz, 13.5MHz, 14.4MHz,
986 * 19.2MHz, 19.6MHz and 19.8MHz
988 static int da7210_set_dai_pll(struct snd_soc_dai
*codec_dai
, int pll_id
,
989 int source
, unsigned int fref
, unsigned int fout
)
991 struct snd_soc_component
*component
= codec_dai
->component
;
992 struct da7210_priv
*da7210
= snd_soc_component_get_drvdata(component
);
994 u8 pll_div1
, pll_div2
, pll_div3
, cnt
;
996 /* In slave mode, there is only one set of divisors */
1000 /* Search pll div array for correct divisors */
1001 for (cnt
= 0; cnt
< ARRAY_SIZE(da7210_pll_div
); cnt
++) {
1002 /* check fref, mode and fout */
1003 if ((fref
== da7210_pll_div
[cnt
].fref
) &&
1004 (da7210
->master
== da7210_pll_div
[cnt
].mode
) &&
1005 (fout
== da7210_pll_div
[cnt
].fout
)) {
1006 /* all match, pick up divisors */
1007 pll_div1
= da7210_pll_div
[cnt
].div1
;
1008 pll_div2
= da7210_pll_div
[cnt
].div2
;
1009 pll_div3
= da7210_pll_div
[cnt
].div3
;
1013 if (cnt
>= ARRAY_SIZE(da7210_pll_div
))
1016 /* Disable active mode */
1017 snd_soc_component_update_bits(component
, DA7210_STARTUP1
, DA7210_SC_MST_EN
, 0);
1018 /* Write PLL dividers */
1019 snd_soc_component_write(component
, DA7210_PLL_DIV1
, pll_div1
);
1020 snd_soc_component_write(component
, DA7210_PLL_DIV2
, pll_div2
);
1021 snd_soc_component_update_bits(component
, DA7210_PLL_DIV3
,
1022 DA7210_PLL_DIV_L_MASK
, pll_div3
);
1025 snd_soc_component_update_bits(component
, DA7210_PLL
, DA7210_PLL_EN
, DA7210_PLL_EN
);
1027 /* Enable active mode */
1028 snd_soc_component_update_bits(component
, DA7210_STARTUP1
, DA7210_SC_MST_EN
,
1032 dev_err(codec_dai
->dev
, "Unsupported PLL input frequency %d\n", fref
);
1036 /* DAI operations */
1037 static const struct snd_soc_dai_ops da7210_dai_ops
= {
1038 .hw_params
= da7210_hw_params
,
1039 .set_fmt
= da7210_set_dai_fmt
,
1040 .set_sysclk
= da7210_set_dai_sysclk
,
1041 .set_pll
= da7210_set_dai_pll
,
1042 .digital_mute
= da7210_mute
,
1045 static struct snd_soc_dai_driver da7210_dai
= {
1046 .name
= "da7210-hifi",
1047 /* playback capabilities */
1049 .stream_name
= "Playback",
1052 .rates
= SNDRV_PCM_RATE_8000_96000
,
1053 .formats
= DA7210_FORMATS
,
1055 /* capture capabilities */
1057 .stream_name
= "Capture",
1060 .rates
= SNDRV_PCM_RATE_8000_96000
,
1061 .formats
= DA7210_FORMATS
,
1063 .ops
= &da7210_dai_ops
,
1064 .symmetric_rates
= 1,
1067 static int da7210_probe(struct snd_soc_component
*component
)
1069 struct da7210_priv
*da7210
= snd_soc_component_get_drvdata(component
);
1071 dev_info(component
->dev
, "DA7210 Audio Codec %s\n", DA7210_VERSION
);
1073 da7210
->mclk_rate
= 0; /* This will be set from set_sysclk() */
1074 da7210
->master
= 0; /* This will be set from set_fmt() */
1076 /* Enable internal regulator & bias current */
1077 snd_soc_component_write(component
, DA7210_CONTROL
, DA7210_REG_EN
| DA7210_BIAS_EN
);
1083 /* Enable Left & Right MIC PGA and Mic Bias */
1084 snd_soc_component_write(component
, DA7210_MIC_L
, DA7210_MIC_L_EN
| DA7210_MICBIAS_EN
);
1085 snd_soc_component_write(component
, DA7210_MIC_R
, DA7210_MIC_R_EN
);
1087 /* Enable Left and Right input PGA */
1088 snd_soc_component_write(component
, DA7210_INMIX_L
, DA7210_IN_L_EN
);
1089 snd_soc_component_write(component
, DA7210_INMIX_R
, DA7210_IN_R_EN
);
1091 /* Enable Left and Right ADC */
1092 snd_soc_component_write(component
, DA7210_ADC
, DA7210_ADC_L_EN
| DA7210_ADC_R_EN
);
1098 /* Enable Left and Right DAC */
1099 snd_soc_component_write(component
, DA7210_DAC_SEL
,
1100 DA7210_DAC_L_SRC_DAI_L
| DA7210_DAC_L_EN
|
1101 DA7210_DAC_R_SRC_DAI_R
| DA7210_DAC_R_EN
);
1103 /* Enable Left and Right out PGA */
1104 snd_soc_component_write(component
, DA7210_OUTMIX_L
, DA7210_OUT_L_EN
);
1105 snd_soc_component_write(component
, DA7210_OUTMIX_R
, DA7210_OUT_R_EN
);
1107 /* Enable Left and Right HeadPhone PGA */
1108 snd_soc_component_write(component
, DA7210_HP_CFG
,
1109 DA7210_HP_2CAP_MODE
| DA7210_HP_SENSE_EN
|
1110 DA7210_HP_L_EN
| DA7210_HP_MODE
| DA7210_HP_R_EN
);
1112 /* Enable ramp mode for DAC gain update */
1113 snd_soc_component_write(component
, DA7210_SOFTMUTE
, DA7210_RAMP_EN
);
1116 * For DA7210 codec, there are two ways to enable/disable analog IOs
1118 * (1) Using "Enable Bit" of register associated with that IO
1120 * e.g. Mic Left can be enabled using bit 7 of MIC_L(0x7) reg
1122 * (2) Using "Standby Bit" of STARTUP2 or STARTUP3 register
1123 * e.g. Mic left can be put to STANDBY using bit 0 of STARTUP3(0x5)
1125 * Out of these two methods, the one using STANDBY bits is preferred
1126 * way to enable/disable individual blocks. This is because STANDBY
1127 * registers are part of system controller which allows system power
1128 * up/down in a controlled, pop-free manner. Also, as per application
1129 * note of DA7210, STANDBY register bits are only effective if a
1130 * particular IO (or ADC/DAC) is already enabled using enable/disable
1131 * register bits. Keeping these things in mind, current DAPM
1132 * implementation manipulates only STANDBY bits.
1134 * Overall implementation can be outlined as below,
1136 * - "Enable bit" of an IO or ADC/DAC is used to enable it in probe()
1137 * - "STANDBY bit" is controlled by DAPM
1140 /* Enable Line out amplifiers */
1141 snd_soc_component_write(component
, DA7210_OUT1_L
, DA7210_OUT1_L_EN
);
1142 snd_soc_component_write(component
, DA7210_OUT1_R
, DA7210_OUT1_R_EN
);
1143 snd_soc_component_write(component
, DA7210_OUT2
, DA7210_OUT2_EN
|
1144 DA7210_OUT2_OUTMIX_L
| DA7210_OUT2_OUTMIX_R
);
1147 snd_soc_component_write(component
, DA7210_AUX1_L
, DA7210_AUX1_L_EN
);
1148 snd_soc_component_write(component
, DA7210_AUX1_R
, DA7210_AUX1_R_EN
);
1150 snd_soc_component_write(component
, DA7210_AUX2
, DA7210_AUX2_EN
);
1152 /* Set PLL Master clock range 10-20 MHz, enable PLL bypass */
1153 snd_soc_component_write(component
, DA7210_PLL_DIV3
, DA7210_MCLK_RANGE_10_20_MHZ
|
1156 /* Diable PLL and bypass it */
1157 snd_soc_component_write(component
, DA7210_PLL
, DA7210_PLL_FS_48000
);
1159 /* Activate all enabled subsystem */
1160 snd_soc_component_write(component
, DA7210_STARTUP1
, DA7210_SC_MST_EN
);
1162 dev_info(component
->dev
, "DA7210 Audio Codec %s\n", DA7210_VERSION
);
1167 static const struct snd_soc_component_driver soc_component_dev_da7210
= {
1168 .probe
= da7210_probe
,
1169 .controls
= da7210_snd_controls
,
1170 .num_controls
= ARRAY_SIZE(da7210_snd_controls
),
1171 .dapm_widgets
= da7210_dapm_widgets
,
1172 .num_dapm_widgets
= ARRAY_SIZE(da7210_dapm_widgets
),
1173 .dapm_routes
= da7210_audio_map
,
1174 .num_dapm_routes
= ARRAY_SIZE(da7210_audio_map
),
1176 .use_pmdown_time
= 1,
1178 .non_legacy_dai_naming
= 1,
1181 #if IS_ENABLED(CONFIG_I2C)
1183 static const struct reg_sequence da7210_regmap_i2c_patch
[] = {
1185 /* System controller master disable */
1186 { DA7210_STARTUP1
, 0x00 },
1187 /* Set PLL Master clock range 10-20 MHz */
1188 { DA7210_PLL_DIV3
, DA7210_MCLK_RANGE_10_20_MHZ
},
1191 { DA7210_A_HID_UNLOCK
, 0x8B},
1192 { DA7210_A_TEST_UNLOCK
, 0xB4},
1193 { DA7210_A_PLL1
, 0x01},
1194 { DA7210_A_CP_MODE
, 0x7C},
1196 { DA7210_A_HID_UNLOCK
, 0x00},
1197 { DA7210_A_TEST_UNLOCK
, 0x00},
1200 static const struct regmap_config da7210_regmap_config_i2c
= {
1204 .reg_defaults
= da7210_reg_defaults
,
1205 .num_reg_defaults
= ARRAY_SIZE(da7210_reg_defaults
),
1206 .volatile_reg
= da7210_volatile_register
,
1207 .readable_reg
= da7210_readable_register
,
1208 .cache_type
= REGCACHE_RBTREE
,
1211 static int da7210_i2c_probe(struct i2c_client
*i2c
,
1212 const struct i2c_device_id
*id
)
1214 struct da7210_priv
*da7210
;
1217 da7210
= devm_kzalloc(&i2c
->dev
, sizeof(struct da7210_priv
),
1222 i2c_set_clientdata(i2c
, da7210
);
1224 da7210
->regmap
= devm_regmap_init_i2c(i2c
, &da7210_regmap_config_i2c
);
1225 if (IS_ERR(da7210
->regmap
)) {
1226 ret
= PTR_ERR(da7210
->regmap
);
1227 dev_err(&i2c
->dev
, "regmap_init() failed: %d\n", ret
);
1231 ret
= regmap_register_patch(da7210
->regmap
, da7210_regmap_i2c_patch
,
1232 ARRAY_SIZE(da7210_regmap_i2c_patch
));
1234 dev_warn(&i2c
->dev
, "Failed to apply regmap patch: %d\n", ret
);
1236 ret
= devm_snd_soc_register_component(&i2c
->dev
,
1237 &soc_component_dev_da7210
, &da7210_dai
, 1);
1239 dev_err(&i2c
->dev
, "Failed to register component: %d\n", ret
);
1244 static const struct i2c_device_id da7210_i2c_id
[] = {
1248 MODULE_DEVICE_TABLE(i2c
, da7210_i2c_id
);
1250 /* I2C codec control layer */
1251 static struct i2c_driver da7210_i2c_driver
= {
1255 .probe
= da7210_i2c_probe
,
1256 .id_table
= da7210_i2c_id
,
1260 #if defined(CONFIG_SPI_MASTER)
1262 static const struct reg_sequence da7210_regmap_spi_patch
[] = {
1263 /* Dummy read to give two pulses over nCS for SPI */
1264 { DA7210_AUX2
, 0x00 },
1265 { DA7210_AUX2
, 0x00 },
1267 /* System controller master disable */
1268 { DA7210_STARTUP1
, 0x00 },
1269 /* Set PLL Master clock range 10-20 MHz */
1270 { DA7210_PLL_DIV3
, DA7210_MCLK_RANGE_10_20_MHZ
},
1272 /* to set PAGE1 of SPI register space */
1273 { DA7210_PAGE_CONTROL
, 0x80 },
1275 { DA7210_A_HID_UNLOCK
, 0x8B},
1276 { DA7210_A_TEST_UNLOCK
, 0xB4},
1277 { DA7210_A_PLL1
, 0x01},
1278 { DA7210_A_CP_MODE
, 0x7C},
1280 { DA7210_A_HID_UNLOCK
, 0x00},
1281 { DA7210_A_TEST_UNLOCK
, 0x00},
1282 /* to set back PAGE0 of SPI register space */
1283 { DA7210_PAGE_CONTROL
, 0x00 },
1286 static const struct regmap_config da7210_regmap_config_spi
= {
1289 .read_flag_mask
= 0x01,
1290 .write_flag_mask
= 0x00,
1292 .reg_defaults
= da7210_reg_defaults
,
1293 .num_reg_defaults
= ARRAY_SIZE(da7210_reg_defaults
),
1294 .volatile_reg
= da7210_volatile_register
,
1295 .readable_reg
= da7210_readable_register
,
1296 .cache_type
= REGCACHE_RBTREE
,
1299 static int da7210_spi_probe(struct spi_device
*spi
)
1301 struct da7210_priv
*da7210
;
1304 da7210
= devm_kzalloc(&spi
->dev
, sizeof(struct da7210_priv
),
1309 spi_set_drvdata(spi
, da7210
);
1310 da7210
->regmap
= devm_regmap_init_spi(spi
, &da7210_regmap_config_spi
);
1311 if (IS_ERR(da7210
->regmap
)) {
1312 ret
= PTR_ERR(da7210
->regmap
);
1313 dev_err(&spi
->dev
, "Failed to register regmap: %d\n", ret
);
1317 ret
= regmap_register_patch(da7210
->regmap
, da7210_regmap_spi_patch
,
1318 ARRAY_SIZE(da7210_regmap_spi_patch
));
1320 dev_warn(&spi
->dev
, "Failed to apply regmap patch: %d\n", ret
);
1322 ret
= devm_snd_soc_register_component(&spi
->dev
,
1323 &soc_component_dev_da7210
, &da7210_dai
, 1);
1328 static struct spi_driver da7210_spi_driver
= {
1332 .probe
= da7210_spi_probe
,
1336 static int __init
da7210_modinit(void)
1339 #if IS_ENABLED(CONFIG_I2C)
1340 ret
= i2c_add_driver(&da7210_i2c_driver
);
1342 #if defined(CONFIG_SPI_MASTER)
1343 ret
= spi_register_driver(&da7210_spi_driver
);
1345 printk(KERN_ERR
"Failed to register da7210 SPI driver: %d\n",
1351 module_init(da7210_modinit
);
1353 static void __exit
da7210_exit(void)
1355 #if IS_ENABLED(CONFIG_I2C)
1356 i2c_del_driver(&da7210_i2c_driver
);
1358 #if defined(CONFIG_SPI_MASTER)
1359 spi_unregister_driver(&da7210_spi_driver
);
1362 module_exit(da7210_exit
);
1364 MODULE_DESCRIPTION("ASoC DA7210 driver");
1365 MODULE_AUTHOR("David Chen, Kuninori Morimoto");
1366 MODULE_LICENSE("GPL");