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/platform_device.h>
21 #include <linux/slab.h>
22 #include <sound/pcm.h>
23 #include <sound/pcm_params.h>
24 #include <sound/soc.h>
25 #include <sound/initval.h>
26 #include <sound/tlv.h>
28 /* DA7210 register space */
29 #define DA7210_CONTROL 0x01
30 #define DA7210_STATUS 0x02
31 #define DA7210_STARTUP1 0x03
32 #define DA7210_STARTUP2 0x04
33 #define DA7210_STARTUP3 0x05
34 #define DA7210_MIC_L 0x07
35 #define DA7210_MIC_R 0x08
36 #define DA7210_AUX1_L 0x09
37 #define DA7210_AUX1_R 0x0A
38 #define DA7210_AUX2 0x0B
39 #define DA7210_IN_GAIN 0x0C
40 #define DA7210_INMIX_L 0x0D
41 #define DA7210_INMIX_R 0x0E
42 #define DA7210_ADC_HPF 0x0F
43 #define DA7210_ADC 0x10
44 #define DA7210_ADC_EQ1_2 0X11
45 #define DA7210_ADC_EQ3_4 0x12
46 #define DA7210_ADC_EQ5 0x13
47 #define DA7210_DAC_HPF 0x14
48 #define DA7210_DAC_L 0x15
49 #define DA7210_DAC_R 0x16
50 #define DA7210_DAC_SEL 0x17
51 #define DA7210_SOFTMUTE 0x18
52 #define DA7210_DAC_EQ1_2 0x19
53 #define DA7210_DAC_EQ3_4 0x1A
54 #define DA7210_DAC_EQ5 0x1B
55 #define DA7210_OUTMIX_L 0x1C
56 #define DA7210_OUTMIX_R 0x1D
57 #define DA7210_HP_L_VOL 0x21
58 #define DA7210_HP_R_VOL 0x22
59 #define DA7210_HP_CFG 0x23
60 #define DA7210_ZERO_CROSS 0x24
61 #define DA7210_DAI_SRC_SEL 0x25
62 #define DA7210_DAI_CFG1 0x26
63 #define DA7210_DAI_CFG3 0x28
64 #define DA7210_PLL_DIV1 0x29
65 #define DA7210_PLL_DIV2 0x2A
66 #define DA7210_PLL_DIV3 0x2B
67 #define DA7210_PLL 0x2C
68 #define DA7210_ALC_MAX 0x83
69 #define DA7210_ALC_MIN 0x84
70 #define DA7210_ALC_NOIS 0x85
71 #define DA7210_ALC_ATT 0x86
72 #define DA7210_ALC_REL 0x87
73 #define DA7210_ALC_DEL 0x88
74 #define DA7210_A_HID_UNLOCK 0x8A
75 #define DA7210_A_TEST_UNLOCK 0x8B
76 #define DA7210_A_PLL1 0x90
77 #define DA7210_A_CP_MODE 0xA7
79 /* STARTUP1 bit fields */
80 #define DA7210_SC_MST_EN (1 << 0)
82 /* MIC_L bit fields */
83 #define DA7210_MICBIAS_EN (1 << 6)
84 #define DA7210_MIC_L_EN (1 << 7)
86 /* MIC_R bit fields */
87 #define DA7210_MIC_R_EN (1 << 7)
89 /* INMIX_L bit fields */
90 #define DA7210_IN_L_EN (1 << 7)
92 /* INMIX_R bit fields */
93 #define DA7210_IN_R_EN (1 << 7)
96 #define DA7210_ADC_ALC_EN (1 << 0)
97 #define DA7210_ADC_L_EN (1 << 3)
98 #define DA7210_ADC_R_EN (1 << 7)
100 /* DAC/ADC HPF fields */
101 #define DA7210_VOICE_F0_MASK (0x7 << 4)
102 #define DA7210_VOICE_F0_25 (1 << 4)
103 #define DA7210_VOICE_EN (1 << 7)
105 /* DAC_SEL bit fields */
106 #define DA7210_DAC_L_SRC_DAI_L (4 << 0)
107 #define DA7210_DAC_L_EN (1 << 3)
108 #define DA7210_DAC_R_SRC_DAI_R (5 << 4)
109 #define DA7210_DAC_R_EN (1 << 7)
111 /* OUTMIX_L bit fields */
112 #define DA7210_OUT_L_EN (1 << 7)
114 /* OUTMIX_R bit fields */
115 #define DA7210_OUT_R_EN (1 << 7)
117 /* HP_CFG bit fields */
118 #define DA7210_HP_2CAP_MODE (1 << 1)
119 #define DA7210_HP_SENSE_EN (1 << 2)
120 #define DA7210_HP_L_EN (1 << 3)
121 #define DA7210_HP_MODE (1 << 6)
122 #define DA7210_HP_R_EN (1 << 7)
124 /* DAI_SRC_SEL bit fields */
125 #define DA7210_DAI_OUT_L_SRC (6 << 0)
126 #define DA7210_DAI_OUT_R_SRC (7 << 4)
128 /* DAI_CFG1 bit fields */
129 #define DA7210_DAI_WORD_S16_LE (0 << 0)
130 #define DA7210_DAI_WORD_S20_3LE (1 << 0)
131 #define DA7210_DAI_WORD_S24_LE (2 << 0)
132 #define DA7210_DAI_WORD_S32_LE (3 << 0)
133 #define DA7210_DAI_FLEN_64BIT (1 << 2)
134 #define DA7210_DAI_MODE_SLAVE (0 << 7)
135 #define DA7210_DAI_MODE_MASTER (1 << 7)
137 /* DAI_CFG3 bit fields */
138 #define DA7210_DAI_FORMAT_I2SMODE (0 << 0)
139 #define DA7210_DAI_FORMAT_LEFT_J (1 << 0)
140 #define DA7210_DAI_FORMAT_RIGHT_J (2 << 0)
141 #define DA7210_DAI_OE (1 << 3)
142 #define DA7210_DAI_EN (1 << 7)
144 /*PLL_DIV3 bit fields */
145 #define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
146 #define DA7210_PLL_BYP (1 << 6)
149 #define DA7210_PLL_FS_MASK (0xF << 0)
150 #define DA7210_PLL_FS_8000 (0x1 << 0)
151 #define DA7210_PLL_FS_11025 (0x2 << 0)
152 #define DA7210_PLL_FS_12000 (0x3 << 0)
153 #define DA7210_PLL_FS_16000 (0x5 << 0)
154 #define DA7210_PLL_FS_22050 (0x6 << 0)
155 #define DA7210_PLL_FS_24000 (0x7 << 0)
156 #define DA7210_PLL_FS_32000 (0x9 << 0)
157 #define DA7210_PLL_FS_44100 (0xA << 0)
158 #define DA7210_PLL_FS_48000 (0xB << 0)
159 #define DA7210_PLL_FS_88200 (0xE << 0)
160 #define DA7210_PLL_FS_96000 (0xF << 0)
161 #define DA7210_PLL_EN (0x1 << 7)
163 /* SOFTMUTE bit fields */
164 #define DA7210_RAMP_EN (1 << 6)
166 /* CONTROL bit fields */
167 #define DA7210_NOISE_SUP_EN (1 << 3)
169 /* IN_GAIN bit fields */
170 #define DA7210_INPGA_L_VOL (0x0F << 0)
171 #define DA7210_INPGA_R_VOL (0xF0 << 0)
173 /* ZERO_CROSS bit fields */
174 #define DA7210_AUX1_L_ZC (1 << 0)
175 #define DA7210_AUX1_R_ZC (1 << 1)
176 #define DA7210_HP_L_ZC (1 << 6)
177 #define DA7210_HP_R_ZC (1 << 7)
179 /* AUX1_L bit fields */
180 #define DA7210_AUX1_L_VOL (0x3F << 0)
182 /* AUX1_R bit fields */
183 #define DA7210_AUX1_R_VOL (0x3F << 0)
185 /* Minimum INPGA and AUX1 volume to enable noise suppression */
186 #define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */
187 #define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */
189 #define DA7210_VERSION "0.0.1"
194 * max : 0x3F (+15.0 dB)
196 * min : 0x11 (-54.0 dB)
198 * reserved : 0x00 - 0x0F
200 * Reserved area are considered as "mute".
202 static const unsigned int hp_out_tlv[] = {
203 TLV_DB_RANGE_HEAD(2),
204 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
205 /* -54 dB to +15 dB */
206 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0),
209 static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
210 static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1);
212 /* ADC and DAC high pass filter f0 value */
213 static const char const *da7210_hpf_cutoff_txt[] = {
214 "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi"
217 static const struct soc_enum da7210_dac_hpf_cutoff =
218 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt);
220 static const struct soc_enum da7210_adc_hpf_cutoff =
221 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt);
223 /* ADC and DAC voice (8kHz) high pass cutoff value */
224 static const char const *da7210_vf_cutoff_txt[] = {
225 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
228 static const struct soc_enum da7210_dac_vf_cutoff =
229 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt);
231 static const struct soc_enum da7210_adc_vf_cutoff =
232 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt);
234 static const char *da7210_hp_mode_txt[] = {
238 static const struct soc_enum da7210_hp_mode_sel =
239 SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt);
241 /* ALC can be enabled only if noise suppression is disabled */
242 static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol,
243 struct snd_ctl_elem_value *ucontrol)
245 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
247 if (ucontrol->value.integer.value[0]) {
248 /* Check if noise suppression is enabled */
249 if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) {
251 "Disable noise suppression to enable ALC\n");
255 /* If all conditions are met or we are actually disabling ALC */
256 return snd_soc_put_volsw(kcontrol, ucontrol);
259 /* Noise suppression can be enabled only if following conditions are met
261 * ZC enabled for HP and AUX1 PGA
262 * INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB
263 * AUX1_L_VOL and AUX1_R_VOL >= 6 dB
265 static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol,
266 struct snd_ctl_elem_value *ucontrol)
268 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
271 if (ucontrol->value.integer.value[0]) {
272 /* Check if ALC is enabled */
273 if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN)
276 /* Check ZC for HP and AUX1 PGA */
277 if ((snd_soc_read(codec, DA7210_ZERO_CROSS) &
278 (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC |
279 DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC |
280 DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC))
283 /* Check INPGA_L_VOL and INPGA_R_VOL */
284 val = snd_soc_read(codec, DA7210_IN_GAIN);
285 if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) ||
286 (((val & DA7210_INPGA_R_VOL) >> 4) <
287 DA7210_INPGA_MIN_VOL_NS))
290 /* Check AUX1_L_VOL and AUX1_R_VOL */
291 if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) <
292 DA7210_AUX1_MIN_VOL_NS) ||
293 ((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) <
294 DA7210_AUX1_MIN_VOL_NS))
297 /* If all conditions are met or we are actually disabling Noise sup */
298 return snd_soc_put_volsw(kcontrol, ucontrol);
304 static const struct snd_kcontrol_new da7210_snd_controls[] = {
306 SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
307 DA7210_HP_L_VOL, DA7210_HP_R_VOL,
308 0, 0x3F, 0, hp_out_tlv),
310 /* DAC Equalizer controls */
311 SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0),
312 SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1,
314 SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1,
316 SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1,
318 SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1,
320 SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1,
323 /* ADC Equalizer controls */
324 SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0),
325 SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3,
326 1, adc_eq_master_gain_tlv),
327 SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1,
329 SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1,
331 SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1,
333 SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1,
335 SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1,
338 SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0),
339 SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff),
340 SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0),
341 SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff),
343 SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0),
344 SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff),
345 SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0),
346 SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff),
349 SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0),
350 SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0),
351 SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0),
352 SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0),
353 SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0),
355 /* Zero cross controls */
356 SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0),
357 SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0),
358 SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0),
359 SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0),
361 SOC_ENUM("Headphone Class", da7210_hp_mode_sel),
364 SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0,
365 snd_soc_get_volsw, da7210_put_alc_sw),
366 SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0),
367 SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0),
368 SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0),
369 SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0),
370 SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0),
371 SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0),
373 SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1,
374 0, snd_soc_get_volsw, da7210_put_noise_sup_sw),
380 * Current DAPM implementation covers almost all codec components e.g. IOs,
381 * mixers, PGAs,ADC and DAC.
384 static const struct snd_kcontrol_new da7210_dapm_inmixl_controls[] = {
385 SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_L, 0, 1, 0),
386 SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_L, 1, 1, 0),
390 static const struct snd_kcontrol_new da7210_dapm_inmixr_controls[] = {
391 SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_R, 0, 1, 0),
392 SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_R, 1, 1, 0),
396 static const struct snd_kcontrol_new da7210_dapm_outmixl_controls[] = {
397 SOC_DAPM_SINGLE("DAC Left Switch", DA7210_OUTMIX_L, 4, 1, 0),
400 /* Out Mixer Right */
401 static const struct snd_kcontrol_new da7210_dapm_outmixr_controls[] = {
402 SOC_DAPM_SINGLE("DAC Right Switch", DA7210_OUTMIX_R, 4, 1, 0),
406 static const struct snd_soc_dapm_widget da7210_dapm_widgets[] = {
409 SND_SOC_DAPM_INPUT("MICL"),
410 SND_SOC_DAPM_INPUT("MICR"),
413 SND_SOC_DAPM_PGA("Mic Left", DA7210_STARTUP3, 0, 1, NULL, 0),
414 SND_SOC_DAPM_PGA("Mic Right", DA7210_STARTUP3, 1, 1, NULL, 0),
416 SND_SOC_DAPM_PGA("INPGA Left", DA7210_INMIX_L, 7, 0, NULL, 0),
417 SND_SOC_DAPM_PGA("INPGA Right", DA7210_INMIX_R, 7, 0, NULL, 0),
420 SND_SOC_DAPM_MIXER("In Mixer Left", SND_SOC_NOPM, 0, 0,
421 &da7210_dapm_inmixl_controls[0],
422 ARRAY_SIZE(da7210_dapm_inmixl_controls)),
424 SND_SOC_DAPM_MIXER("In Mixer Right", SND_SOC_NOPM, 0, 0,
425 &da7210_dapm_inmixr_controls[0],
426 ARRAY_SIZE(da7210_dapm_inmixr_controls)),
429 SND_SOC_DAPM_ADC("ADC Left", "Capture", DA7210_STARTUP3, 5, 1),
430 SND_SOC_DAPM_ADC("ADC Right", "Capture", DA7210_STARTUP3, 6, 1),
434 SND_SOC_DAPM_DAC("DAC Left", "Playback", DA7210_STARTUP2, 5, 1),
435 SND_SOC_DAPM_DAC("DAC Right", "Playback", DA7210_STARTUP2, 6, 1),
438 SND_SOC_DAPM_MIXER("Out Mixer Left", SND_SOC_NOPM, 0, 0,
439 &da7210_dapm_outmixl_controls[0],
440 ARRAY_SIZE(da7210_dapm_outmixl_controls)),
442 SND_SOC_DAPM_MIXER("Out Mixer Right", SND_SOC_NOPM, 0, 0,
443 &da7210_dapm_outmixr_controls[0],
444 ARRAY_SIZE(da7210_dapm_outmixr_controls)),
447 SND_SOC_DAPM_PGA("OUTPGA Left Enable", DA7210_OUTMIX_L, 7, 0, NULL, 0),
448 SND_SOC_DAPM_PGA("OUTPGA Right Enable", DA7210_OUTMIX_R, 7, 0, NULL, 0),
450 SND_SOC_DAPM_PGA("Headphone Left", DA7210_STARTUP2, 3, 1, NULL, 0),
451 SND_SOC_DAPM_PGA("Headphone Right", DA7210_STARTUP2, 4, 1, NULL, 0),
454 SND_SOC_DAPM_OUTPUT("HPL"),
455 SND_SOC_DAPM_OUTPUT("HPR"),
458 /* DAPM audio route definition */
459 static const struct snd_soc_dapm_route da7210_audio_map[] = {
460 /* Dest Connecting Widget source */
462 {"Mic Left", NULL, "MICL"},
463 {"Mic Right", NULL, "MICR"},
465 {"In Mixer Left", "Mic Left Switch", "Mic Left"},
466 {"In Mixer Left", "Mic Right Switch", "Mic Right"},
468 {"In Mixer Right", "Mic Right Switch", "Mic Right"},
469 {"In Mixer Right", "Mic Left Switch", "Mic Left"},
471 {"INPGA Left", NULL, "In Mixer Left"},
472 {"ADC Left", NULL, "INPGA Left"},
474 {"INPGA Right", NULL, "In Mixer Right"},
475 {"ADC Right", NULL, "INPGA Right"},
478 {"Out Mixer Left", "DAC Left Switch", "DAC Left"},
479 {"Out Mixer Right", "DAC Right Switch", "DAC Right"},
481 {"OUTPGA Left Enable", NULL, "Out Mixer Left"},
482 {"OUTPGA Right Enable", NULL, "Out Mixer Right"},
484 {"Headphone Left", NULL, "OUTPGA Left Enable"},
485 {"HPL", NULL, "Headphone Left"},
487 {"Headphone Right", NULL, "OUTPGA Right Enable"},
488 {"HPR", NULL, "Headphone Right"},
491 /* Codec private data */
493 enum snd_soc_control_type control_type;
499 static const u8 da7210_reg[] = {
500 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R0 - R7 */
501 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, /* R8 - RF */
502 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x54, /* R10 - R17 */
503 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R18 - R1F */
504 0x00, 0x00, 0x00, 0x02, 0x00, 0x76, 0x00, 0x00, /* R20 - R27 */
505 0x04, 0x00, 0x00, 0x30, 0x2A, 0x00, 0x40, 0x00, /* R28 - R2F */
506 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, /* R30 - R37 */
507 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, /* R38 - R3F */
508 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R40 - R4F */
509 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R48 - R4F */
510 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R50 - R57 */
511 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R58 - R5F */
512 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R60 - R67 */
513 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R68 - R6F */
514 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R70 - R77 */
515 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x54, 0x00, /* R78 - R7F */
516 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, /* R80 - R87 */
520 static int da7210_volatile_register(struct snd_soc_codec *codec,
532 * Set PCM DAI word length.
534 static int da7210_hw_params(struct snd_pcm_substream *substream,
535 struct snd_pcm_hw_params *params,
536 struct snd_soc_dai *dai)
538 struct snd_soc_pcm_runtime *rtd = substream->private_data;
539 struct snd_soc_codec *codec = rtd->codec;
543 /* set DAI source to Left and Right ADC */
544 snd_soc_write(codec, DA7210_DAI_SRC_SEL,
545 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
548 snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
550 dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
552 switch (params_format(params)) {
553 case SNDRV_PCM_FORMAT_S16_LE:
554 dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
556 case SNDRV_PCM_FORMAT_S20_3LE:
557 dai_cfg1 |= DA7210_DAI_WORD_S20_3LE;
559 case SNDRV_PCM_FORMAT_S24_LE:
560 dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
562 case SNDRV_PCM_FORMAT_S32_LE:
563 dai_cfg1 |= DA7210_DAI_WORD_S32_LE;
569 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
571 switch (params_rate(params)) {
573 fs = DA7210_PLL_FS_8000;
574 bypass = DA7210_PLL_BYP;
577 fs = DA7210_PLL_FS_11025;
581 fs = DA7210_PLL_FS_12000;
582 bypass = DA7210_PLL_BYP;
585 fs = DA7210_PLL_FS_16000;
586 bypass = DA7210_PLL_BYP;
589 fs = DA7210_PLL_FS_22050;
593 fs = DA7210_PLL_FS_32000;
594 bypass = DA7210_PLL_BYP;
597 fs = DA7210_PLL_FS_44100;
601 fs = DA7210_PLL_FS_48000;
602 bypass = DA7210_PLL_BYP;
605 fs = DA7210_PLL_FS_88200;
609 fs = DA7210_PLL_FS_96000;
610 bypass = DA7210_PLL_BYP;
616 /* Disable active mode */
617 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
619 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
620 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
622 /* Enable active mode */
623 snd_soc_update_bits(codec, DA7210_STARTUP1,
624 DA7210_SC_MST_EN, DA7210_SC_MST_EN);
630 * Set DAI mode and Format
632 static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
634 struct snd_soc_codec *codec = codec_dai->codec;
638 dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
639 dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
641 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
642 case SND_SOC_DAIFMT_CBM_CFM:
643 dai_cfg1 |= DA7210_DAI_MODE_MASTER;
645 case SND_SOC_DAIFMT_CBS_CFS:
646 dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
654 * It support I2S only now
656 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
657 case SND_SOC_DAIFMT_I2S:
658 dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
660 case SND_SOC_DAIFMT_LEFT_J:
661 dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J;
663 case SND_SOC_DAIFMT_RIGHT_J:
664 dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J;
672 * It support 64bit data transmission only now
674 dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
676 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
677 snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
682 static int da7210_mute(struct snd_soc_dai *dai, int mute)
684 struct snd_soc_codec *codec = dai->codec;
685 u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB;
688 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4);
690 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg);
694 #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
695 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
698 static struct snd_soc_dai_ops da7210_dai_ops = {
699 .hw_params = da7210_hw_params,
700 .set_fmt = da7210_set_dai_fmt,
701 .digital_mute = da7210_mute,
704 static struct snd_soc_dai_driver da7210_dai = {
705 .name = "da7210-hifi",
706 /* playback capabilities */
708 .stream_name = "Playback",
711 .rates = SNDRV_PCM_RATE_8000_96000,
712 .formats = DA7210_FORMATS,
714 /* capture capabilities */
716 .stream_name = "Capture",
719 .rates = SNDRV_PCM_RATE_8000_96000,
720 .formats = DA7210_FORMATS,
722 .ops = &da7210_dai_ops,
723 .symmetric_rates = 1,
726 static int da7210_probe(struct snd_soc_codec *codec)
728 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
731 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
733 ret = snd_soc_codec_set_cache_io(codec, 8, 8, da7210->control_type);
735 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
741 * This driver use fixed value here
742 * And below settings expects MCLK = 12.288MHz
744 * When you select different MCLK, please check...
745 * DA7210_PLL_DIV1 val
746 * DA7210_PLL_DIV2 val
747 * DA7210_PLL_DIV3 val
748 * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
752 * make sure that DA7210 use bypass mode before start up
754 snd_soc_write(codec, DA7210_STARTUP1, 0);
755 snd_soc_write(codec, DA7210_PLL_DIV3,
756 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
762 /* Enable Left & Right MIC PGA and Mic Bias */
763 snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
764 snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
766 /* Enable Left and Right input PGA */
767 snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
768 snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
770 /* Enable Left and Right ADC */
771 snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
777 /* Enable Left and Right DAC */
778 snd_soc_write(codec, DA7210_DAC_SEL,
779 DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
780 DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
782 /* Enable Left and Right out PGA */
783 snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
784 snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
786 /* Enable Left and Right HeadPhone PGA */
787 snd_soc_write(codec, DA7210_HP_CFG,
788 DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
789 DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
791 /* Enable ramp mode for DAC gain update */
792 snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN);
794 /* Diable PLL and bypass it */
795 snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
798 * If 48kHz sound came, it use bypass mode,
799 * and when it is 44.1kHz, it use PLL.
801 * This time, this driver sets PLL always ON
802 * and controls bypass/PLL mode by switching
803 * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
804 * see da7210_hw_params
806 snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
807 snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
808 snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
809 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
810 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
812 /* As suggested by Dialog */
813 snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */
814 snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0xB4);
815 snd_soc_write(codec, DA7210_A_PLL1, 0x01);
816 snd_soc_write(codec, DA7210_A_CP_MODE, 0x7C);
817 snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */
818 snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0x00);
820 /* Activate all enabled subsystem */
821 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
823 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
828 static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
829 .probe = da7210_probe,
830 .reg_cache_size = ARRAY_SIZE(da7210_reg),
831 .reg_word_size = sizeof(u8),
832 .reg_cache_default = da7210_reg,
833 .volatile_register = da7210_volatile_register,
835 .controls = da7210_snd_controls,
836 .num_controls = ARRAY_SIZE(da7210_snd_controls),
838 .dapm_widgets = da7210_dapm_widgets,
839 .num_dapm_widgets = ARRAY_SIZE(da7210_dapm_widgets),
840 .dapm_routes = da7210_audio_map,
841 .num_dapm_routes = ARRAY_SIZE(da7210_audio_map),
844 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
845 static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
846 const struct i2c_device_id *id)
848 struct da7210_priv *da7210;
851 da7210 = kzalloc(sizeof(struct da7210_priv), GFP_KERNEL);
855 i2c_set_clientdata(i2c, da7210);
856 da7210->control_type = SND_SOC_I2C;
858 ret = snd_soc_register_codec(&i2c->dev,
859 &soc_codec_dev_da7210, &da7210_dai, 1);
866 static int __devexit da7210_i2c_remove(struct i2c_client *client)
868 snd_soc_unregister_codec(&client->dev);
869 kfree(i2c_get_clientdata(client));
873 static const struct i2c_device_id da7210_i2c_id[] = {
877 MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
879 /* I2C codec control layer */
880 static struct i2c_driver da7210_i2c_driver = {
882 .name = "da7210-codec",
883 .owner = THIS_MODULE,
885 .probe = da7210_i2c_probe,
886 .remove = __devexit_p(da7210_i2c_remove),
887 .id_table = da7210_i2c_id,
891 static int __init da7210_modinit(void)
894 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
895 ret = i2c_add_driver(&da7210_i2c_driver);
899 module_init(da7210_modinit);
901 static void __exit da7210_exit(void)
903 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
904 i2c_del_driver(&da7210_i2c_driver);
907 module_exit(da7210_exit);
909 MODULE_DESCRIPTION("ASoC DA7210 driver");
910 MODULE_AUTHOR("David Chen, Kuninori Morimoto");
911 MODULE_LICENSE("GPL");