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