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_MIC_L 0x07
33 #define DA7210_MIC_R 0x08
34 #define DA7210_AUX1_L 0x09
35 #define DA7210_AUX1_R 0x0A
36 #define DA7210_AUX2 0x0B
37 #define DA7210_IN_GAIN 0x0C
38 #define DA7210_INMIX_L 0x0D
39 #define DA7210_INMIX_R 0x0E
40 #define DA7210_ADC_HPF 0x0F
41 #define DA7210_ADC 0x10
42 #define DA7210_ADC_EQ1_2 0X11
43 #define DA7210_ADC_EQ3_4 0x12
44 #define DA7210_ADC_EQ5 0x13
45 #define DA7210_DAC_HPF 0x14
46 #define DA7210_DAC_L 0x15
47 #define DA7210_DAC_R 0x16
48 #define DA7210_DAC_SEL 0x17
49 #define DA7210_SOFTMUTE 0x18
50 #define DA7210_DAC_EQ1_2 0x19
51 #define DA7210_DAC_EQ3_4 0x1A
52 #define DA7210_DAC_EQ5 0x1B
53 #define DA7210_OUTMIX_L 0x1C
54 #define DA7210_OUTMIX_R 0x1D
55 #define DA7210_HP_L_VOL 0x21
56 #define DA7210_HP_R_VOL 0x22
57 #define DA7210_HP_CFG 0x23
58 #define DA7210_ZERO_CROSS 0x24
59 #define DA7210_DAI_SRC_SEL 0x25
60 #define DA7210_DAI_CFG1 0x26
61 #define DA7210_DAI_CFG3 0x28
62 #define DA7210_PLL_DIV1 0x29
63 #define DA7210_PLL_DIV2 0x2A
64 #define DA7210_PLL_DIV3 0x2B
65 #define DA7210_PLL 0x2C
66 #define DA7210_ALC_MAX 0x83
67 #define DA7210_ALC_MIN 0x84
68 #define DA7210_ALC_NOIS 0x85
69 #define DA7210_ALC_ATT 0x86
70 #define DA7210_ALC_REL 0x87
71 #define DA7210_ALC_DEL 0x88
72 #define DA7210_A_HID_UNLOCK 0x8A
73 #define DA7210_A_TEST_UNLOCK 0x8B
74 #define DA7210_A_PLL1 0x90
75 #define DA7210_A_CP_MODE 0xA7
77 /* STARTUP1 bit fields */
78 #define DA7210_SC_MST_EN (1 << 0)
80 /* MIC_L bit fields */
81 #define DA7210_MICBIAS_EN (1 << 6)
82 #define DA7210_MIC_L_EN (1 << 7)
84 /* MIC_R bit fields */
85 #define DA7210_MIC_R_EN (1 << 7)
87 /* INMIX_L bit fields */
88 #define DA7210_IN_L_EN (1 << 7)
90 /* INMIX_R bit fields */
91 #define DA7210_IN_R_EN (1 << 7)
94 #define DA7210_ADC_ALC_EN (1 << 0)
95 #define DA7210_ADC_L_EN (1 << 3)
96 #define DA7210_ADC_R_EN (1 << 7)
98 /* DAC/ADC HPF fields */
99 #define DA7210_VOICE_F0_MASK (0x7 << 4)
100 #define DA7210_VOICE_F0_25 (1 << 4)
101 #define DA7210_VOICE_EN (1 << 7)
103 /* DAC_SEL bit fields */
104 #define DA7210_DAC_L_SRC_DAI_L (4 << 0)
105 #define DA7210_DAC_L_EN (1 << 3)
106 #define DA7210_DAC_R_SRC_DAI_R (5 << 4)
107 #define DA7210_DAC_R_EN (1 << 7)
109 /* OUTMIX_L bit fields */
110 #define DA7210_OUT_L_EN (1 << 7)
112 /* OUTMIX_R bit fields */
113 #define DA7210_OUT_R_EN (1 << 7)
115 /* HP_CFG bit fields */
116 #define DA7210_HP_2CAP_MODE (1 << 1)
117 #define DA7210_HP_SENSE_EN (1 << 2)
118 #define DA7210_HP_L_EN (1 << 3)
119 #define DA7210_HP_MODE (1 << 6)
120 #define DA7210_HP_R_EN (1 << 7)
122 /* DAI_SRC_SEL bit fields */
123 #define DA7210_DAI_OUT_L_SRC (6 << 0)
124 #define DA7210_DAI_OUT_R_SRC (7 << 4)
126 /* DAI_CFG1 bit fields */
127 #define DA7210_DAI_WORD_S16_LE (0 << 0)
128 #define DA7210_DAI_WORD_S20_3LE (1 << 0)
129 #define DA7210_DAI_WORD_S24_LE (2 << 0)
130 #define DA7210_DAI_WORD_S32_LE (3 << 0)
131 #define DA7210_DAI_FLEN_64BIT (1 << 2)
132 #define DA7210_DAI_MODE_SLAVE (0 << 7)
133 #define DA7210_DAI_MODE_MASTER (1 << 7)
135 /* DAI_CFG3 bit fields */
136 #define DA7210_DAI_FORMAT_I2SMODE (0 << 0)
137 #define DA7210_DAI_FORMAT_LEFT_J (1 << 0)
138 #define DA7210_DAI_FORMAT_RIGHT_J (2 << 0)
139 #define DA7210_DAI_OE (1 << 3)
140 #define DA7210_DAI_EN (1 << 7)
142 /*PLL_DIV3 bit fields */
143 #define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
144 #define DA7210_PLL_BYP (1 << 6)
147 #define DA7210_PLL_FS_MASK (0xF << 0)
148 #define DA7210_PLL_FS_8000 (0x1 << 0)
149 #define DA7210_PLL_FS_11025 (0x2 << 0)
150 #define DA7210_PLL_FS_12000 (0x3 << 0)
151 #define DA7210_PLL_FS_16000 (0x5 << 0)
152 #define DA7210_PLL_FS_22050 (0x6 << 0)
153 #define DA7210_PLL_FS_24000 (0x7 << 0)
154 #define DA7210_PLL_FS_32000 (0x9 << 0)
155 #define DA7210_PLL_FS_44100 (0xA << 0)
156 #define DA7210_PLL_FS_48000 (0xB << 0)
157 #define DA7210_PLL_FS_88200 (0xE << 0)
158 #define DA7210_PLL_FS_96000 (0xF << 0)
159 #define DA7210_PLL_EN (0x1 << 7)
161 /* SOFTMUTE bit fields */
162 #define DA7210_RAMP_EN (1 << 6)
164 /* CONTROL bit fields */
165 #define DA7210_NOISE_SUP_EN (1 << 3)
167 /* IN_GAIN bit fields */
168 #define DA7210_INPGA_L_VOL (0x0F << 0)
169 #define DA7210_INPGA_R_VOL (0xF0 << 0)
171 /* ZERO_CROSS bit fields */
172 #define DA7210_AUX1_L_ZC (1 << 0)
173 #define DA7210_AUX1_R_ZC (1 << 1)
174 #define DA7210_HP_L_ZC (1 << 6)
175 #define DA7210_HP_R_ZC (1 << 7)
177 /* AUX1_L bit fields */
178 #define DA7210_AUX1_L_VOL (0x3F << 0)
180 /* AUX1_R bit fields */
181 #define DA7210_AUX1_R_VOL (0x3F << 0)
183 /* Minimum INPGA and AUX1 volume to enable noise suppression */
184 #define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */
185 #define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */
187 #define DA7210_VERSION "0.0.1"
192 * max : 0x3F (+15.0 dB)
194 * min : 0x11 (-54.0 dB)
196 * reserved : 0x00 - 0x0F
198 * Reserved area are considered as "mute".
200 static const unsigned int hp_out_tlv[] = {
201 TLV_DB_RANGE_HEAD(2),
202 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
203 /* -54 dB to +15 dB */
204 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0),
207 static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
208 static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1);
210 /* ADC and DAC high pass filter f0 value */
211 static const char const *da7210_hpf_cutoff_txt[] = {
212 "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi"
215 static const struct soc_enum da7210_dac_hpf_cutoff =
216 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt);
218 static const struct soc_enum da7210_adc_hpf_cutoff =
219 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt);
221 /* ADC and DAC voice (8kHz) high pass cutoff value */
222 static const char const *da7210_vf_cutoff_txt[] = {
223 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
226 static const struct soc_enum da7210_dac_vf_cutoff =
227 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt);
229 static const struct soc_enum da7210_adc_vf_cutoff =
230 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt);
232 static const char *da7210_hp_mode_txt[] = {
236 static const struct soc_enum da7210_hp_mode_sel =
237 SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt);
239 /* ALC can be enabled only if noise suppression is disabled */
240 static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol,
241 struct snd_ctl_elem_value *ucontrol)
243 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
245 if (ucontrol->value.integer.value[0]) {
246 /* Check if noise suppression is enabled */
247 if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) {
249 "Disable noise suppression to enable ALC\n");
253 /* If all conditions are met or we are actually disabling ALC */
254 return snd_soc_put_volsw(kcontrol, ucontrol);
257 /* Noise suppression can be enabled only if following conditions are met
259 * ZC enabled for HP and AUX1 PGA
260 * INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB
261 * AUX1_L_VOL and AUX1_R_VOL >= 6 dB
263 static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol,
264 struct snd_ctl_elem_value *ucontrol)
266 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
269 if (ucontrol->value.integer.value[0]) {
270 /* Check if ALC is enabled */
271 if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN)
274 /* Check ZC for HP and AUX1 PGA */
275 if ((snd_soc_read(codec, DA7210_ZERO_CROSS) &
276 (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC |
277 DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC |
278 DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC))
281 /* Check INPGA_L_VOL and INPGA_R_VOL */
282 val = snd_soc_read(codec, DA7210_IN_GAIN);
283 if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) ||
284 (((val & DA7210_INPGA_R_VOL) >> 4) <
285 DA7210_INPGA_MIN_VOL_NS))
288 /* Check AUX1_L_VOL and AUX1_R_VOL */
289 if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) <
290 DA7210_AUX1_MIN_VOL_NS) ||
291 ((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) <
292 DA7210_AUX1_MIN_VOL_NS))
295 /* If all conditions are met or we are actually disabling Noise sup */
296 return snd_soc_put_volsw(kcontrol, ucontrol);
302 static const struct snd_kcontrol_new da7210_snd_controls[] = {
304 SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
305 DA7210_HP_L_VOL, DA7210_HP_R_VOL,
306 0, 0x3F, 0, hp_out_tlv),
308 /* DAC Equalizer controls */
309 SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0),
310 SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1,
312 SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1,
314 SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1,
316 SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1,
318 SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1,
321 /* ADC Equalizer controls */
322 SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0),
323 SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3,
324 1, adc_eq_master_gain_tlv),
325 SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1,
327 SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1,
329 SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1,
331 SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1,
333 SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1,
336 SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0),
337 SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff),
338 SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0),
339 SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff),
341 SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0),
342 SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff),
343 SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0),
344 SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff),
347 SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0),
348 SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0),
349 SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0),
350 SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0),
351 SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0),
353 /* Zero cross controls */
354 SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0),
355 SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0),
356 SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0),
357 SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0),
359 SOC_ENUM("Headphone Class", da7210_hp_mode_sel),
362 SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0,
363 snd_soc_get_volsw, da7210_put_alc_sw),
364 SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0),
365 SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0),
366 SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0),
367 SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0),
368 SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0),
369 SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0),
371 SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1,
372 0, snd_soc_get_volsw, da7210_put_noise_sup_sw),
375 /* Codec private data */
377 enum snd_soc_control_type control_type;
383 static const u8 da7210_reg[] = {
384 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R0 - R7 */
385 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, /* R8 - RF */
386 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x54, /* R10 - R17 */
387 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R18 - R1F */
388 0x00, 0x00, 0x00, 0x02, 0x00, 0x76, 0x00, 0x00, /* R20 - R27 */
389 0x04, 0x00, 0x00, 0x30, 0x2A, 0x00, 0x40, 0x00, /* R28 - R2F */
390 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, /* R30 - R37 */
391 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, /* R38 - R3F */
392 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R40 - R4F */
393 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R48 - R4F */
394 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R50 - R57 */
395 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R58 - R5F */
396 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R60 - R67 */
397 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R68 - R6F */
398 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R70 - R77 */
399 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x54, 0x00, /* R78 - R7F */
400 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, /* R80 - R87 */
404 static int da7210_volatile_register(struct snd_soc_codec *codec,
414 static int da7210_startup(struct snd_pcm_substream *substream,
415 struct snd_soc_dai *dai)
417 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
418 struct snd_soc_codec *codec = dai->codec;
422 snd_soc_update_bits(codec, DA7210_OUTMIX_L, 0x1F, 0x10);
423 snd_soc_update_bits(codec, DA7210_OUTMIX_R, 0x1F, 0x10);
427 snd_soc_update_bits(codec, DA7210_MIC_L, 0x7, 0x7);
428 snd_soc_update_bits(codec, DA7210_MIC_R, 0x7, 0x7);
431 snd_soc_update_bits(codec, DA7210_INMIX_L, 0x1F, 0x1);
432 snd_soc_update_bits(codec, DA7210_INMIX_R, 0x1F, 0x1);
439 * Set PCM DAI word length.
441 static int da7210_hw_params(struct snd_pcm_substream *substream,
442 struct snd_pcm_hw_params *params,
443 struct snd_soc_dai *dai)
445 struct snd_soc_pcm_runtime *rtd = substream->private_data;
446 struct snd_soc_codec *codec = rtd->codec;
450 /* set DAI source to Left and Right ADC */
451 snd_soc_write(codec, DA7210_DAI_SRC_SEL,
452 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
455 snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
457 dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
459 switch (params_format(params)) {
460 case SNDRV_PCM_FORMAT_S16_LE:
461 dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
463 case SNDRV_PCM_FORMAT_S20_3LE:
464 dai_cfg1 |= DA7210_DAI_WORD_S20_3LE;
466 case SNDRV_PCM_FORMAT_S24_LE:
467 dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
469 case SNDRV_PCM_FORMAT_S32_LE:
470 dai_cfg1 |= DA7210_DAI_WORD_S32_LE;
476 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
478 switch (params_rate(params)) {
480 fs = DA7210_PLL_FS_8000;
481 bypass = DA7210_PLL_BYP;
484 fs = DA7210_PLL_FS_11025;
488 fs = DA7210_PLL_FS_12000;
489 bypass = DA7210_PLL_BYP;
492 fs = DA7210_PLL_FS_16000;
493 bypass = DA7210_PLL_BYP;
496 fs = DA7210_PLL_FS_22050;
500 fs = DA7210_PLL_FS_32000;
501 bypass = DA7210_PLL_BYP;
504 fs = DA7210_PLL_FS_44100;
508 fs = DA7210_PLL_FS_48000;
509 bypass = DA7210_PLL_BYP;
512 fs = DA7210_PLL_FS_88200;
516 fs = DA7210_PLL_FS_96000;
517 bypass = DA7210_PLL_BYP;
523 /* Disable active mode */
524 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
526 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
527 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
529 /* Enable active mode */
530 snd_soc_update_bits(codec, DA7210_STARTUP1,
531 DA7210_SC_MST_EN, DA7210_SC_MST_EN);
537 * Set DAI mode and Format
539 static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
541 struct snd_soc_codec *codec = codec_dai->codec;
545 dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
546 dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
548 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
549 case SND_SOC_DAIFMT_CBM_CFM:
550 dai_cfg1 |= DA7210_DAI_MODE_MASTER;
552 case SND_SOC_DAIFMT_CBS_CFS:
553 dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
561 * It support I2S only now
563 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
564 case SND_SOC_DAIFMT_I2S:
565 dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
567 case SND_SOC_DAIFMT_LEFT_J:
568 dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J;
570 case SND_SOC_DAIFMT_RIGHT_J:
571 dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J;
579 * It support 64bit data transmission only now
581 dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
583 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
584 snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
589 static int da7210_mute(struct snd_soc_dai *dai, int mute)
591 struct snd_soc_codec *codec = dai->codec;
592 u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB;
595 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4);
597 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg);
601 #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
602 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
605 static struct snd_soc_dai_ops da7210_dai_ops = {
606 .startup = da7210_startup,
607 .hw_params = da7210_hw_params,
608 .set_fmt = da7210_set_dai_fmt,
609 .digital_mute = da7210_mute,
612 static struct snd_soc_dai_driver da7210_dai = {
613 .name = "da7210-hifi",
614 /* playback capabilities */
616 .stream_name = "Playback",
619 .rates = SNDRV_PCM_RATE_8000_96000,
620 .formats = DA7210_FORMATS,
622 /* capture capabilities */
624 .stream_name = "Capture",
627 .rates = SNDRV_PCM_RATE_8000_96000,
628 .formats = DA7210_FORMATS,
630 .ops = &da7210_dai_ops,
631 .symmetric_rates = 1,
634 static int da7210_probe(struct snd_soc_codec *codec)
636 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
639 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
641 ret = snd_soc_codec_set_cache_io(codec, 8, 8, da7210->control_type);
643 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
649 * This driver use fixed value here
650 * And below settings expects MCLK = 12.288MHz
652 * When you select different MCLK, please check...
653 * DA7210_PLL_DIV1 val
654 * DA7210_PLL_DIV2 val
655 * DA7210_PLL_DIV3 val
656 * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
660 * make sure that DA7210 use bypass mode before start up
662 snd_soc_write(codec, DA7210_STARTUP1, 0);
663 snd_soc_write(codec, DA7210_PLL_DIV3,
664 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
670 /* Enable Left & Right MIC PGA and Mic Bias */
671 snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
672 snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
674 /* Enable Left and Right input PGA */
675 snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
676 snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
678 /* Enable Left and Right ADC */
679 snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
685 /* Enable Left and Right DAC */
686 snd_soc_write(codec, DA7210_DAC_SEL,
687 DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
688 DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
690 /* Enable Left and Right out PGA */
691 snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
692 snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
694 /* Enable Left and Right HeadPhone PGA */
695 snd_soc_write(codec, DA7210_HP_CFG,
696 DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
697 DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
699 /* Enable ramp mode for DAC gain update */
700 snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN);
702 /* Diable PLL and bypass it */
703 snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
706 * If 48kHz sound came, it use bypass mode,
707 * and when it is 44.1kHz, it use PLL.
709 * This time, this driver sets PLL always ON
710 * and controls bypass/PLL mode by switching
711 * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
712 * see da7210_hw_params
714 snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
715 snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
716 snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
717 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
718 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
720 /* As suggested by Dialog */
721 snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */
722 snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0xB4);
723 snd_soc_write(codec, DA7210_A_PLL1, 0x01);
724 snd_soc_write(codec, DA7210_A_CP_MODE, 0x7C);
725 snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */
726 snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0x00);
728 /* Activate all enabled subsystem */
729 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
731 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
736 static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
737 .probe = da7210_probe,
738 .reg_cache_size = ARRAY_SIZE(da7210_reg),
739 .reg_word_size = sizeof(u8),
740 .reg_cache_default = da7210_reg,
741 .volatile_register = da7210_volatile_register,
743 .controls = da7210_snd_controls,
744 .num_controls = ARRAY_SIZE(da7210_snd_controls),
747 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
748 static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
749 const struct i2c_device_id *id)
751 struct da7210_priv *da7210;
754 da7210 = kzalloc(sizeof(struct da7210_priv), GFP_KERNEL);
758 i2c_set_clientdata(i2c, da7210);
759 da7210->control_type = SND_SOC_I2C;
761 ret = snd_soc_register_codec(&i2c->dev,
762 &soc_codec_dev_da7210, &da7210_dai, 1);
769 static int __devexit da7210_i2c_remove(struct i2c_client *client)
771 snd_soc_unregister_codec(&client->dev);
772 kfree(i2c_get_clientdata(client));
776 static const struct i2c_device_id da7210_i2c_id[] = {
780 MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
782 /* I2C codec control layer */
783 static struct i2c_driver da7210_i2c_driver = {
785 .name = "da7210-codec",
786 .owner = THIS_MODULE,
788 .probe = da7210_i2c_probe,
789 .remove = __devexit_p(da7210_i2c_remove),
790 .id_table = da7210_i2c_id,
794 static int __init da7210_modinit(void)
797 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
798 ret = i2c_add_driver(&da7210_i2c_driver);
802 module_init(da7210_modinit);
804 static void __exit da7210_exit(void)
806 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
807 i2c_del_driver(&da7210_i2c_driver);
810 module_exit(da7210_exit);
812 MODULE_DESCRIPTION("ASoC DA7210 driver");
813 MODULE_AUTHOR("David Chen, Kuninori Morimoto");
814 MODULE_LICENSE("GPL");