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_MCLK_RANGE_10_20_MHZ (1 << 4)
152 #define DA7210_PLL_BYP (1 << 6)
155 #define DA7210_PLL_FS_MASK (0xF << 0)
156 #define DA7210_PLL_FS_8000 (0x1 << 0)
157 #define DA7210_PLL_FS_11025 (0x2 << 0)
158 #define DA7210_PLL_FS_12000 (0x3 << 0)
159 #define DA7210_PLL_FS_16000 (0x5 << 0)
160 #define DA7210_PLL_FS_22050 (0x6 << 0)
161 #define DA7210_PLL_FS_24000 (0x7 << 0)
162 #define DA7210_PLL_FS_32000 (0x9 << 0)
163 #define DA7210_PLL_FS_44100 (0xA << 0)
164 #define DA7210_PLL_FS_48000 (0xB << 0)
165 #define DA7210_PLL_FS_88200 (0xE << 0)
166 #define DA7210_PLL_FS_96000 (0xF << 0)
167 #define DA7210_PLL_EN (0x1 << 7)
169 /* SOFTMUTE bit fields */
170 #define DA7210_RAMP_EN (1 << 6)
172 /* CONTROL bit fields */
173 #define DA7210_NOISE_SUP_EN (1 << 3)
175 /* IN_GAIN bit fields */
176 #define DA7210_INPGA_L_VOL (0x0F << 0)
177 #define DA7210_INPGA_R_VOL (0xF0 << 0)
179 /* ZERO_CROSS bit fields */
180 #define DA7210_AUX1_L_ZC (1 << 0)
181 #define DA7210_AUX1_R_ZC (1 << 1)
182 #define DA7210_HP_L_ZC (1 << 6)
183 #define DA7210_HP_R_ZC (1 << 7)
185 /* AUX1_L bit fields */
186 #define DA7210_AUX1_L_VOL (0x3F << 0)
187 #define DA7210_AUX1_L_EN (1 << 7)
189 /* AUX1_R bit fields */
190 #define DA7210_AUX1_R_VOL (0x3F << 0)
191 #define DA7210_AUX1_R_EN (1 << 7)
193 /* AUX2 bit fields */
194 #define DA7210_AUX2_EN (1 << 3)
196 /* Minimum INPGA and AUX1 volume to enable noise suppression */
197 #define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */
198 #define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */
200 /* OUT1_L bit fields */
201 #define DA7210_OUT1_L_EN (1 << 7)
203 /* OUT1_R bit fields */
204 #define DA7210_OUT1_R_EN (1 << 7)
206 /* OUT2 bit fields */
207 #define DA7210_OUT2_OUTMIX_R (1 << 5)
208 #define DA7210_OUT2_OUTMIX_L (1 << 6)
209 #define DA7210_OUT2_EN (1 << 7)
211 #define DA7210_VERSION "0.0.1"
216 * max : 0x3F (+15.0 dB)
218 * min : 0x11 (-54.0 dB)
220 * reserved : 0x00 - 0x0F
222 * Reserved area are considered as "mute".
224 static const unsigned int hp_out_tlv[] = {
225 TLV_DB_RANGE_HEAD(2),
226 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
227 /* -54 dB to +15 dB */
228 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0),
231 static const unsigned int lineout_vol_tlv[] = {
232 TLV_DB_RANGE_HEAD(2),
233 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
235 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0)
238 static const unsigned int mono_vol_tlv[] = {
239 TLV_DB_RANGE_HEAD(2),
240 0x0, 0x2, TLV_DB_SCALE_ITEM(-1800, 0, 1),
242 0x3, 0x7, TLV_DB_SCALE_ITEM(-1800, 600, 0)
245 static const unsigned int aux1_vol_tlv[] = {
246 TLV_DB_RANGE_HEAD(2),
247 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
249 0x11, 0x3f, TLV_DB_SCALE_ITEM(-4800, 150, 0)
252 static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
253 static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1);
254 static const DECLARE_TLV_DB_SCALE(dac_gain_tlv, -7725, 75, 0);
255 static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, -600, 600, 0);
256 static const DECLARE_TLV_DB_SCALE(aux2_vol_tlv, -600, 600, 0);
257 static const DECLARE_TLV_DB_SCALE(inpga_gain_tlv, -450, 150, 0);
259 /* ADC and DAC high pass filter f0 value */
260 static const char * const da7210_hpf_cutoff_txt[] = {
261 "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi"
264 static const struct soc_enum da7210_dac_hpf_cutoff =
265 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt);
267 static const struct soc_enum da7210_adc_hpf_cutoff =
268 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt);
270 /* ADC and DAC voice (8kHz) high pass cutoff value */
271 static const char * const da7210_vf_cutoff_txt[] = {
272 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
275 static const struct soc_enum da7210_dac_vf_cutoff =
276 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt);
278 static const struct soc_enum da7210_adc_vf_cutoff =
279 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt);
281 static const char *da7210_hp_mode_txt[] = {
285 static const struct soc_enum da7210_hp_mode_sel =
286 SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt);
288 /* ALC can be enabled only if noise suppression is disabled */
289 static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol,
290 struct snd_ctl_elem_value *ucontrol)
292 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
294 if (ucontrol->value.integer.value[0]) {
295 /* Check if noise suppression is enabled */
296 if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) {
298 "Disable noise suppression to enable ALC\n");
302 /* If all conditions are met or we are actually disabling ALC */
303 return snd_soc_put_volsw(kcontrol, ucontrol);
306 /* Noise suppression can be enabled only if following conditions are met
308 * ZC enabled for HP and AUX1 PGA
309 * INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB
310 * AUX1_L_VOL and AUX1_R_VOL >= 6 dB
312 static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol,
313 struct snd_ctl_elem_value *ucontrol)
315 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
318 if (ucontrol->value.integer.value[0]) {
319 /* Check if ALC is enabled */
320 if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN)
323 /* Check ZC for HP and AUX1 PGA */
324 if ((snd_soc_read(codec, DA7210_ZERO_CROSS) &
325 (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC |
326 DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC |
327 DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC))
330 /* Check INPGA_L_VOL and INPGA_R_VOL */
331 val = snd_soc_read(codec, DA7210_IN_GAIN);
332 if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) ||
333 (((val & DA7210_INPGA_R_VOL) >> 4) <
334 DA7210_INPGA_MIN_VOL_NS))
337 /* Check AUX1_L_VOL and AUX1_R_VOL */
338 if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) <
339 DA7210_AUX1_MIN_VOL_NS) ||
340 ((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) <
341 DA7210_AUX1_MIN_VOL_NS))
344 /* If all conditions are met or we are actually disabling Noise sup */
345 return snd_soc_put_volsw(kcontrol, ucontrol);
351 static const struct snd_kcontrol_new da7210_snd_controls[] = {
353 SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
354 DA7210_HP_L_VOL, DA7210_HP_R_VOL,
355 0, 0x3F, 0, hp_out_tlv),
356 SOC_DOUBLE_R_TLV("Digital Playback Volume",
357 DA7210_DAC_L, DA7210_DAC_R,
358 0, 0x77, 1, dac_gain_tlv),
359 SOC_DOUBLE_R_TLV("Lineout Playback Volume",
360 DA7210_OUT1_L, DA7210_OUT1_R,
361 0, 0x3f, 0, lineout_vol_tlv),
362 SOC_SINGLE_TLV("Mono Playback Volume", DA7210_OUT2, 0, 0x7, 0,
365 SOC_DOUBLE_R_TLV("Mic Capture Volume",
366 DA7210_MIC_L, DA7210_MIC_R,
367 0, 0x5, 0, mic_vol_tlv),
368 SOC_DOUBLE_R_TLV("Aux1 Capture Volume",
369 DA7210_AUX1_L, DA7210_AUX1_R,
370 0, 0x3f, 0, aux1_vol_tlv),
371 SOC_SINGLE_TLV("Aux2 Capture Volume", DA7210_AUX2, 0, 0x3, 0,
373 SOC_DOUBLE_TLV("In PGA Capture Volume", DA7210_IN_GAIN, 0, 4, 0xF, 0,
376 /* DAC Equalizer controls */
377 SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0),
378 SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1,
380 SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1,
382 SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1,
384 SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1,
386 SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1,
389 /* ADC Equalizer controls */
390 SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0),
391 SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3,
392 1, adc_eq_master_gain_tlv),
393 SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1,
395 SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1,
397 SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1,
399 SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1,
401 SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1,
404 SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0),
405 SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff),
406 SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0),
407 SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff),
409 SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0),
410 SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff),
411 SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0),
412 SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff),
415 SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0),
416 SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0),
417 SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0),
418 SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0),
419 SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0),
421 /* Zero cross controls */
422 SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0),
423 SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0),
424 SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0),
425 SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0),
427 SOC_ENUM("Headphone Class", da7210_hp_mode_sel),
430 SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0,
431 snd_soc_get_volsw, da7210_put_alc_sw),
432 SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0),
433 SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0),
434 SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0),
435 SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0),
436 SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0),
437 SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0),
439 SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1,
440 0, snd_soc_get_volsw, da7210_put_noise_sup_sw),
446 * Current DAPM implementation covers almost all codec components e.g. IOs,
447 * mixers, PGAs,ADC and DAC.
450 static const struct snd_kcontrol_new da7210_dapm_inmixl_controls[] = {
451 SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_L, 0, 1, 0),
452 SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_L, 1, 1, 0),
453 SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_INMIX_L, 2, 1, 0),
454 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_L, 3, 1, 0),
455 SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_INMIX_L, 4, 1, 0),
459 static const struct snd_kcontrol_new da7210_dapm_inmixr_controls[] = {
460 SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_R, 0, 1, 0),
461 SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_R, 1, 1, 0),
462 SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_INMIX_R, 2, 1, 0),
463 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_R, 3, 1, 0),
464 SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_INMIX_R, 4, 1, 0),
468 static const struct snd_kcontrol_new da7210_dapm_outmixl_controls[] = {
469 SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_OUTMIX_L, 0, 1, 0),
470 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_L, 1, 1, 0),
471 SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_L, 2, 1, 0),
472 SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_L, 3, 1, 0),
473 SOC_DAPM_SINGLE("DAC Left Switch", DA7210_OUTMIX_L, 4, 1, 0),
476 /* Out Mixer Right */
477 static const struct snd_kcontrol_new da7210_dapm_outmixr_controls[] = {
478 SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_OUTMIX_R, 0, 1, 0),
479 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_R, 1, 1, 0),
480 SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_R, 2, 1, 0),
481 SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_R, 3, 1, 0),
482 SOC_DAPM_SINGLE("DAC Right Switch", DA7210_OUTMIX_R, 4, 1, 0),
486 static const struct snd_kcontrol_new da7210_dapm_monomix_controls[] = {
487 SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUT2, 3, 1, 0),
488 SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUT2, 4, 1, 0),
489 SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_OUT2, 5, 1, 0),
490 SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_OUT2, 6, 1, 0),
494 static const struct snd_soc_dapm_widget da7210_dapm_widgets[] = {
497 SND_SOC_DAPM_INPUT("MICL"),
498 SND_SOC_DAPM_INPUT("MICR"),
499 SND_SOC_DAPM_INPUT("AUX1L"),
500 SND_SOC_DAPM_INPUT("AUX1R"),
501 SND_SOC_DAPM_INPUT("AUX2"),
504 SND_SOC_DAPM_PGA("Mic Left", DA7210_STARTUP3, 0, 1, NULL, 0),
505 SND_SOC_DAPM_PGA("Mic Right", DA7210_STARTUP3, 1, 1, NULL, 0),
506 SND_SOC_DAPM_PGA("Aux1 Left", DA7210_STARTUP3, 2, 1, NULL, 0),
507 SND_SOC_DAPM_PGA("Aux1 Right", DA7210_STARTUP3, 3, 1, NULL, 0),
508 SND_SOC_DAPM_PGA("Aux2 Mono", DA7210_STARTUP3, 4, 1, NULL, 0),
510 SND_SOC_DAPM_PGA("INPGA Left", DA7210_INMIX_L, 7, 0, NULL, 0),
511 SND_SOC_DAPM_PGA("INPGA Right", DA7210_INMIX_R, 7, 0, NULL, 0),
514 SND_SOC_DAPM_SUPPLY("Mic Bias", DA7210_MIC_L, 6, 0, NULL, 0),
517 SND_SOC_DAPM_MIXER("In Mixer Left", SND_SOC_NOPM, 0, 0,
518 &da7210_dapm_inmixl_controls[0],
519 ARRAY_SIZE(da7210_dapm_inmixl_controls)),
521 SND_SOC_DAPM_MIXER("In Mixer Right", SND_SOC_NOPM, 0, 0,
522 &da7210_dapm_inmixr_controls[0],
523 ARRAY_SIZE(da7210_dapm_inmixr_controls)),
526 SND_SOC_DAPM_ADC("ADC Left", "Capture", DA7210_STARTUP3, 5, 1),
527 SND_SOC_DAPM_ADC("ADC Right", "Capture", DA7210_STARTUP3, 6, 1),
531 SND_SOC_DAPM_DAC("DAC Left", "Playback", DA7210_STARTUP2, 5, 1),
532 SND_SOC_DAPM_DAC("DAC Right", "Playback", DA7210_STARTUP2, 6, 1),
535 SND_SOC_DAPM_MIXER("Out Mixer Left", SND_SOC_NOPM, 0, 0,
536 &da7210_dapm_outmixl_controls[0],
537 ARRAY_SIZE(da7210_dapm_outmixl_controls)),
539 SND_SOC_DAPM_MIXER("Out Mixer Right", SND_SOC_NOPM, 0, 0,
540 &da7210_dapm_outmixr_controls[0],
541 ARRAY_SIZE(da7210_dapm_outmixr_controls)),
543 SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0,
544 &da7210_dapm_monomix_controls[0],
545 ARRAY_SIZE(da7210_dapm_monomix_controls)),
548 SND_SOC_DAPM_PGA("OUTPGA Left Enable", DA7210_OUTMIX_L, 7, 0, NULL, 0),
549 SND_SOC_DAPM_PGA("OUTPGA Right Enable", DA7210_OUTMIX_R, 7, 0, NULL, 0),
551 SND_SOC_DAPM_PGA("Out1 Left", DA7210_STARTUP2, 0, 1, NULL, 0),
552 SND_SOC_DAPM_PGA("Out1 Right", DA7210_STARTUP2, 1, 1, NULL, 0),
553 SND_SOC_DAPM_PGA("Out2 Mono", DA7210_STARTUP2, 2, 1, NULL, 0),
554 SND_SOC_DAPM_PGA("Headphone Left", DA7210_STARTUP2, 3, 1, NULL, 0),
555 SND_SOC_DAPM_PGA("Headphone Right", DA7210_STARTUP2, 4, 1, NULL, 0),
558 SND_SOC_DAPM_OUTPUT("OUT1L"),
559 SND_SOC_DAPM_OUTPUT("OUT1R"),
560 SND_SOC_DAPM_OUTPUT("HPL"),
561 SND_SOC_DAPM_OUTPUT("HPR"),
562 SND_SOC_DAPM_OUTPUT("OUT2"),
565 /* DAPM audio route definition */
566 static const struct snd_soc_dapm_route da7210_audio_map[] = {
567 /* Dest Connecting Widget source */
569 {"Mic Left", NULL, "MICL"},
570 {"Mic Right", NULL, "MICR"},
571 {"Aux1 Left", NULL, "AUX1L"},
572 {"Aux1 Right", NULL, "AUX1R"},
573 {"Aux2 Mono", NULL, "AUX2"},
575 {"In Mixer Left", "Mic Left Switch", "Mic Left"},
576 {"In Mixer Left", "Mic Right Switch", "Mic Right"},
577 {"In Mixer Left", "Aux1 Left Switch", "Aux1 Left"},
578 {"In Mixer Left", "Aux2 Switch", "Aux2 Mono"},
579 {"In Mixer Left", "Outmix Left Switch", "Out Mixer Left"},
581 {"In Mixer Right", "Mic Right Switch", "Mic Right"},
582 {"In Mixer Right", "Mic Left Switch", "Mic Left"},
583 {"In Mixer Right", "Aux1 Right Switch", "Aux1 Right"},
584 {"In Mixer Right", "Aux2 Switch", "Aux2 Mono"},
585 {"In Mixer Right", "Outmix Right Switch", "Out Mixer Right"},
587 {"INPGA Left", NULL, "In Mixer Left"},
588 {"ADC Left", NULL, "INPGA Left"},
590 {"INPGA Right", NULL, "In Mixer Right"},
591 {"ADC Right", NULL, "INPGA Right"},
594 {"Out Mixer Left", "Aux1 Left Switch", "Aux1 Left"},
595 {"Out Mixer Left", "Aux2 Switch", "Aux2 Mono"},
596 {"Out Mixer Left", "INPGA Left Switch", "INPGA Left"},
597 {"Out Mixer Left", "INPGA Right Switch", "INPGA Right"},
598 {"Out Mixer Left", "DAC Left Switch", "DAC Left"},
600 {"Out Mixer Right", "Aux1 Right Switch", "Aux1 Right"},
601 {"Out Mixer Right", "Aux2 Switch", "Aux2 Mono"},
602 {"Out Mixer Right", "INPGA Right Switch", "INPGA Right"},
603 {"Out Mixer Right", "INPGA Left Switch", "INPGA Left"},
604 {"Out Mixer Right", "DAC Right Switch", "DAC Right"},
606 {"Mono Mixer", "INPGA Right Switch", "INPGA Right"},
607 {"Mono Mixer", "INPGA Left Switch", "INPGA Left"},
608 {"Mono Mixer", "Outmix Right Switch", "Out Mixer Right"},
609 {"Mono Mixer", "Outmix Left Switch", "Out Mixer Left"},
611 {"OUTPGA Left Enable", NULL, "Out Mixer Left"},
612 {"OUTPGA Right Enable", NULL, "Out Mixer Right"},
614 {"Out1 Left", NULL, "OUTPGA Left Enable"},
615 {"OUT1L", NULL, "Out1 Left"},
617 {"Out1 Right", NULL, "OUTPGA Right Enable"},
618 {"OUT1R", NULL, "Out1 Right"},
620 {"Headphone Left", NULL, "OUTPGA Left Enable"},
621 {"HPL", NULL, "Headphone Left"},
623 {"Headphone Right", NULL, "OUTPGA Right Enable"},
624 {"HPR", NULL, "Headphone Right"},
626 {"Out2 Mono", NULL, "Mono Mixer"},
627 {"OUT2", NULL, "Out2 Mono"},
630 /* Codec private data */
632 struct regmap *regmap;
635 static struct reg_default da7210_reg_defaults[] = {
688 static bool da7210_readable_register(struct device *dev, unsigned int reg)
691 case DA7210_A_HID_UNLOCK:
692 case DA7210_A_TEST_UNLOCK:
694 case DA7210_A_CP_MODE:
701 static bool da7210_volatile_register(struct device *dev,
713 * Set PCM DAI word length.
715 static int da7210_hw_params(struct snd_pcm_substream *substream,
716 struct snd_pcm_hw_params *params,
717 struct snd_soc_dai *dai)
719 struct snd_soc_codec *codec = dai->codec;
723 /* set DAI source to Left and Right ADC */
724 snd_soc_write(codec, DA7210_DAI_SRC_SEL,
725 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
728 snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
730 dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
732 switch (params_format(params)) {
733 case SNDRV_PCM_FORMAT_S16_LE:
734 dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
736 case SNDRV_PCM_FORMAT_S20_3LE:
737 dai_cfg1 |= DA7210_DAI_WORD_S20_3LE;
739 case SNDRV_PCM_FORMAT_S24_LE:
740 dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
742 case SNDRV_PCM_FORMAT_S32_LE:
743 dai_cfg1 |= DA7210_DAI_WORD_S32_LE;
749 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
751 switch (params_rate(params)) {
753 fs = DA7210_PLL_FS_8000;
754 bypass = DA7210_PLL_BYP;
757 fs = DA7210_PLL_FS_11025;
761 fs = DA7210_PLL_FS_12000;
762 bypass = DA7210_PLL_BYP;
765 fs = DA7210_PLL_FS_16000;
766 bypass = DA7210_PLL_BYP;
769 fs = DA7210_PLL_FS_22050;
773 fs = DA7210_PLL_FS_32000;
774 bypass = DA7210_PLL_BYP;
777 fs = DA7210_PLL_FS_44100;
781 fs = DA7210_PLL_FS_48000;
782 bypass = DA7210_PLL_BYP;
785 fs = DA7210_PLL_FS_88200;
789 fs = DA7210_PLL_FS_96000;
790 bypass = DA7210_PLL_BYP;
796 /* Disable active mode */
797 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
799 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
800 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
802 /* Enable active mode */
803 snd_soc_update_bits(codec, DA7210_STARTUP1,
804 DA7210_SC_MST_EN, DA7210_SC_MST_EN);
810 * Set DAI mode and Format
812 static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
814 struct snd_soc_codec *codec = codec_dai->codec;
818 dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
819 dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
821 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
822 case SND_SOC_DAIFMT_CBM_CFM:
823 dai_cfg1 |= DA7210_DAI_MODE_MASTER;
825 case SND_SOC_DAIFMT_CBS_CFS:
826 dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
834 * It support I2S only now
836 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
837 case SND_SOC_DAIFMT_I2S:
838 dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
840 case SND_SOC_DAIFMT_LEFT_J:
841 dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J;
843 case SND_SOC_DAIFMT_RIGHT_J:
844 dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J;
852 * It support 64bit data transmission only now
854 dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
856 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
857 snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
862 static int da7210_mute(struct snd_soc_dai *dai, int mute)
864 struct snd_soc_codec *codec = dai->codec;
865 u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB;
868 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4);
870 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg);
874 #define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
875 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
878 static const struct snd_soc_dai_ops da7210_dai_ops = {
879 .hw_params = da7210_hw_params,
880 .set_fmt = da7210_set_dai_fmt,
881 .digital_mute = da7210_mute,
884 static struct snd_soc_dai_driver da7210_dai = {
885 .name = "da7210-hifi",
886 /* playback capabilities */
888 .stream_name = "Playback",
891 .rates = SNDRV_PCM_RATE_8000_96000,
892 .formats = DA7210_FORMATS,
894 /* capture capabilities */
896 .stream_name = "Capture",
899 .rates = SNDRV_PCM_RATE_8000_96000,
900 .formats = DA7210_FORMATS,
902 .ops = &da7210_dai_ops,
903 .symmetric_rates = 1,
906 static int da7210_probe(struct snd_soc_codec *codec)
908 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
911 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
913 codec->control_data = da7210->regmap;
914 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
916 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
922 * This driver use fixed value here
923 * And below settings expects MCLK = 12.288MHz
925 * When you select different MCLK, please check...
926 * DA7210_PLL_DIV1 val
927 * DA7210_PLL_DIV2 val
928 * DA7210_PLL_DIV3 val
929 * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
936 /* Enable Left & Right MIC PGA and Mic Bias */
937 snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
938 snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
940 /* Enable Left and Right input PGA */
941 snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
942 snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
944 /* Enable Left and Right ADC */
945 snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
951 /* Enable Left and Right DAC */
952 snd_soc_write(codec, DA7210_DAC_SEL,
953 DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
954 DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
956 /* Enable Left and Right out PGA */
957 snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
958 snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
960 /* Enable Left and Right HeadPhone PGA */
961 snd_soc_write(codec, DA7210_HP_CFG,
962 DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
963 DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
965 /* Enable ramp mode for DAC gain update */
966 snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN);
969 * For DA7210 codec, there are two ways to enable/disable analog IOs
971 * (1) Using "Enable Bit" of register associated with that IO
973 * e.g. Mic Left can be enabled using bit 7 of MIC_L(0x7) reg
975 * (2) Using "Standby Bit" of STARTUP2 or STARTUP3 register
976 * e.g. Mic left can be put to STANDBY using bit 0 of STARTUP3(0x5)
978 * Out of these two methods, the one using STANDBY bits is preferred
979 * way to enable/disable individual blocks. This is because STANDBY
980 * registers are part of system controller which allows system power
981 * up/down in a controlled, pop-free manner. Also, as per application
982 * note of DA7210, STANDBY register bits are only effective if a
983 * particular IO (or ADC/DAC) is already enabled using enable/disable
984 * register bits. Keeping these things in mind, current DAPM
985 * implementation manipulates only STANDBY bits.
987 * Overall implementation can be outlined as below,
989 * - "Enable bit" of an IO or ADC/DAC is used to enable it in probe()
990 * - "STANDBY bit" is controlled by DAPM
993 /* Enable Line out amplifiers */
994 snd_soc_write(codec, DA7210_OUT1_L, DA7210_OUT1_L_EN);
995 snd_soc_write(codec, DA7210_OUT1_R, DA7210_OUT1_R_EN);
996 snd_soc_write(codec, DA7210_OUT2, DA7210_OUT2_EN |
997 DA7210_OUT2_OUTMIX_L | DA7210_OUT2_OUTMIX_R);
1000 snd_soc_write(codec, DA7210_AUX1_L, DA7210_AUX1_L_EN);
1001 snd_soc_write(codec, DA7210_AUX1_R, DA7210_AUX1_R_EN);
1003 snd_soc_write(codec, DA7210_AUX2, DA7210_AUX2_EN);
1005 /* Diable PLL and bypass it */
1006 snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
1009 * If 48kHz sound came, it use bypass mode,
1010 * and when it is 44.1kHz, it use PLL.
1012 * This time, this driver sets PLL always ON
1013 * and controls bypass/PLL mode by switching
1014 * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
1015 * see da7210_hw_params
1017 snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
1018 snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
1019 snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
1020 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
1021 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
1023 /* Activate all enabled subsystem */
1024 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
1026 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
1031 static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
1032 .probe = da7210_probe,
1034 .controls = da7210_snd_controls,
1035 .num_controls = ARRAY_SIZE(da7210_snd_controls),
1037 .dapm_widgets = da7210_dapm_widgets,
1038 .num_dapm_widgets = ARRAY_SIZE(da7210_dapm_widgets),
1039 .dapm_routes = da7210_audio_map,
1040 .num_dapm_routes = ARRAY_SIZE(da7210_audio_map),
1043 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1045 static struct reg_default da7210_regmap_i2c_patch[] = {
1047 /* System controller master disable */
1048 { DA7210_STARTUP1, 0x00 },
1049 /* make sure that DA7210 use bypass mode before start up */
1050 { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP },
1053 { DA7210_A_HID_UNLOCK, 0x8B},
1054 { DA7210_A_TEST_UNLOCK, 0xB4},
1055 { DA7210_A_PLL1, 0x01},
1056 { DA7210_A_CP_MODE, 0x7C},
1058 { DA7210_A_HID_UNLOCK, 0x00},
1059 { DA7210_A_TEST_UNLOCK, 0x00},
1062 static const struct regmap_config da7210_regmap_config_i2c = {
1066 .reg_defaults = da7210_reg_defaults,
1067 .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
1068 .volatile_reg = da7210_volatile_register,
1069 .readable_reg = da7210_readable_register,
1070 .cache_type = REGCACHE_RBTREE,
1073 static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
1074 const struct i2c_device_id *id)
1076 struct da7210_priv *da7210;
1079 da7210 = devm_kzalloc(&i2c->dev, sizeof(struct da7210_priv),
1084 i2c_set_clientdata(i2c, da7210);
1086 da7210->regmap = regmap_init_i2c(i2c, &da7210_regmap_config_i2c);
1087 if (IS_ERR(da7210->regmap)) {
1088 ret = PTR_ERR(da7210->regmap);
1089 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
1093 ret = regmap_register_patch(da7210->regmap, da7210_regmap_i2c_patch,
1094 ARRAY_SIZE(da7210_regmap_i2c_patch));
1096 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret);
1098 ret = snd_soc_register_codec(&i2c->dev,
1099 &soc_codec_dev_da7210, &da7210_dai, 1);
1101 dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
1107 regmap_exit(da7210->regmap);
1112 static int __devexit da7210_i2c_remove(struct i2c_client *client)
1114 struct da7210_priv *da7210 = i2c_get_clientdata(client);
1116 snd_soc_unregister_codec(&client->dev);
1117 regmap_exit(da7210->regmap);
1121 static const struct i2c_device_id da7210_i2c_id[] = {
1125 MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
1127 /* I2C codec control layer */
1128 static struct i2c_driver da7210_i2c_driver = {
1131 .owner = THIS_MODULE,
1133 .probe = da7210_i2c_probe,
1134 .remove = __devexit_p(da7210_i2c_remove),
1135 .id_table = da7210_i2c_id,
1139 #if defined(CONFIG_SPI_MASTER)
1141 static struct reg_default da7210_regmap_spi_patch[] = {
1142 /* Dummy read to give two pulses over nCS for SPI */
1143 { DA7210_AUX2, 0x00 },
1144 { DA7210_AUX2, 0x00 },
1146 /* System controller master disable */
1147 { DA7210_STARTUP1, 0x00 },
1148 /* make sure that DA7210 use bypass mode before start up */
1149 { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP },
1151 /* to set PAGE1 of SPI register space */
1152 { DA7210_PAGE_CONTROL, 0x80 },
1154 { DA7210_A_HID_UNLOCK, 0x8B},
1155 { DA7210_A_TEST_UNLOCK, 0xB4},
1156 { DA7210_A_PLL1, 0x01},
1157 { DA7210_A_CP_MODE, 0x7C},
1159 { DA7210_A_HID_UNLOCK, 0x00},
1160 { DA7210_A_TEST_UNLOCK, 0x00},
1161 /* to set back PAGE0 of SPI register space */
1162 { DA7210_PAGE_CONTROL, 0x00 },
1165 static const struct regmap_config da7210_regmap_config_spi = {
1168 .read_flag_mask = 0x01,
1169 .write_flag_mask = 0x00,
1171 .reg_defaults = da7210_reg_defaults,
1172 .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
1173 .volatile_reg = da7210_volatile_register,
1174 .readable_reg = da7210_readable_register,
1175 .cache_type = REGCACHE_RBTREE,
1178 static int __devinit da7210_spi_probe(struct spi_device *spi)
1180 struct da7210_priv *da7210;
1183 da7210 = devm_kzalloc(&spi->dev, sizeof(struct da7210_priv),
1188 spi_set_drvdata(spi, da7210);
1189 da7210->regmap = devm_regmap_init_spi(spi, &da7210_regmap_config_spi);
1190 if (IS_ERR(da7210->regmap)) {
1191 ret = PTR_ERR(da7210->regmap);
1192 dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
1196 ret = regmap_register_patch(da7210->regmap, da7210_regmap_spi_patch,
1197 ARRAY_SIZE(da7210_regmap_spi_patch));
1199 dev_warn(&spi->dev, "Failed to apply regmap patch: %d\n", ret);
1201 ret = snd_soc_register_codec(&spi->dev,
1202 &soc_codec_dev_da7210, &da7210_dai, 1);
1209 regmap_exit(da7210->regmap);
1214 static int __devexit da7210_spi_remove(struct spi_device *spi)
1216 struct da7210_priv *da7210 = spi_get_drvdata(spi);
1217 snd_soc_unregister_codec(&spi->dev);
1218 regmap_exit(da7210->regmap);
1222 static struct spi_driver da7210_spi_driver = {
1225 .owner = THIS_MODULE,
1227 .probe = da7210_spi_probe,
1228 .remove = __devexit_p(da7210_spi_remove)
1232 static int __init da7210_modinit(void)
1235 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1236 ret = i2c_add_driver(&da7210_i2c_driver);
1238 #if defined(CONFIG_SPI_MASTER)
1239 ret = spi_register_driver(&da7210_spi_driver);
1241 printk(KERN_ERR "Failed to register da7210 SPI driver: %d\n",
1247 module_init(da7210_modinit);
1249 static void __exit da7210_exit(void)
1251 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1252 i2c_del_driver(&da7210_i2c_driver);
1254 #if defined(CONFIG_SPI_MASTER)
1255 spi_unregister_driver(&da7210_spi_driver);
1258 module_exit(da7210_exit);
1260 MODULE_DESCRIPTION("ASoC DA7210 driver");
1261 MODULE_AUTHOR("David Chen, Kuninori Morimoto");
1262 MODULE_LICENSE("GPL");