blob: 7a4b952a05eb210c53ec7ff5cc6062b3a0ba3216 [file] [log] [blame]
Kuninori Morimoto98615452009-12-14 13:21:56 +09001/*
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
Kuninori Morimoto98615452009-12-14 13:21:56 +090018#include <linux/delay.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090019#include <linux/i2c.h>
20#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090022#include <sound/pcm.h>
23#include <sound/pcm_params.h>
Liam Girdwoodce6120c2010-11-05 15:53:46 +020024#include <sound/soc.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090025#include <sound/initval.h>
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +090026#include <sound/tlv.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090027
Kuninori Morimoto98615452009-12-14 13:21:56 +090028/* DA7210 register space */
Ashish Chavande5eaf82011-10-19 14:24:37 +053029#define DA7210_CONTROL 0x01
Kuninori Morimoto98615452009-12-14 13:21:56 +090030#define DA7210_STATUS 0x02
31#define DA7210_STARTUP1 0x03
Ashish Chavan6950c602011-10-21 18:16:08 +053032#define DA7210_STARTUP2 0x04
33#define DA7210_STARTUP3 0x05
Kuninori Morimoto98615452009-12-14 13:21:56 +090034#define DA7210_MIC_L 0x07
35#define DA7210_MIC_R 0x08
Ashish Chavande5eaf82011-10-19 14:24:37 +053036#define DA7210_AUX1_L 0x09
37#define DA7210_AUX1_R 0x0A
Ashish Chavan5eda1942011-10-19 14:19:06 +053038#define DA7210_AUX2 0x0B
Ashish Chavande5eaf82011-10-19 14:24:37 +053039#define DA7210_IN_GAIN 0x0C
Kuninori Morimoto98615452009-12-14 13:21:56 +090040#define DA7210_INMIX_L 0x0D
41#define DA7210_INMIX_R 0x0E
42#define DA7210_ADC_HPF 0x0F
43#define DA7210_ADC 0x10
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +053044#define DA7210_ADC_EQ1_2 0X11
45#define DA7210_ADC_EQ3_4 0x12
46#define DA7210_ADC_EQ5 0x13
Kuninori Morimoto98615452009-12-14 13:21:56 +090047#define DA7210_DAC_HPF 0x14
48#define DA7210_DAC_L 0x15
49#define DA7210_DAC_R 0x16
50#define DA7210_DAC_SEL 0x17
Ashish Chavan5eda1942011-10-19 14:19:06 +053051#define DA7210_SOFTMUTE 0x18
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +053052#define DA7210_DAC_EQ1_2 0x19
53#define DA7210_DAC_EQ3_4 0x1A
54#define DA7210_DAC_EQ5 0x1B
Kuninori Morimoto98615452009-12-14 13:21:56 +090055#define DA7210_OUTMIX_L 0x1C
56#define DA7210_OUTMIX_R 0x1D
57#define DA7210_HP_L_VOL 0x21
58#define DA7210_HP_R_VOL 0x22
59#define DA7210_HP_CFG 0x23
Ashish Chavan5eda1942011-10-19 14:19:06 +053060#define DA7210_ZERO_CROSS 0x24
Kuninori Morimoto98615452009-12-14 13:21:56 +090061#define DA7210_DAI_SRC_SEL 0x25
62#define DA7210_DAI_CFG1 0x26
63#define DA7210_DAI_CFG3 0x28
Kuninori Morimoto960b3b42010-03-11 11:37:44 +090064#define DA7210_PLL_DIV1 0x29
65#define DA7210_PLL_DIV2 0x2A
Kuninori Morimoto98615452009-12-14 13:21:56 +090066#define DA7210_PLL_DIV3 0x2B
67#define DA7210_PLL 0x2C
Ashish Chavande5eaf82011-10-19 14:24:37 +053068#define DA7210_ALC_MAX 0x83
69#define DA7210_ALC_MIN 0x84
70#define DA7210_ALC_NOIS 0x85
71#define DA7210_ALC_ATT 0x86
72#define DA7210_ALC_REL 0x87
73#define DA7210_ALC_DEL 0x88
Kuninori Morimoto960b3b42010-03-11 11:37:44 +090074#define DA7210_A_HID_UNLOCK 0x8A
75#define DA7210_A_TEST_UNLOCK 0x8B
76#define DA7210_A_PLL1 0x90
77#define DA7210_A_CP_MODE 0xA7
Kuninori Morimoto98615452009-12-14 13:21:56 +090078
79/* STARTUP1 bit fields */
80#define DA7210_SC_MST_EN (1 << 0)
81
82/* MIC_L bit fields */
83#define DA7210_MICBIAS_EN (1 << 6)
84#define DA7210_MIC_L_EN (1 << 7)
85
86/* MIC_R bit fields */
87#define DA7210_MIC_R_EN (1 << 7)
88
89/* INMIX_L bit fields */
90#define DA7210_IN_L_EN (1 << 7)
91
92/* INMIX_R bit fields */
93#define DA7210_IN_R_EN (1 << 7)
94
Kuninori Morimoto98615452009-12-14 13:21:56 +090095/* ADC bit fields */
Ashish Chavande5eaf82011-10-19 14:24:37 +053096#define DA7210_ADC_ALC_EN (1 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +090097#define DA7210_ADC_L_EN (1 << 3)
98#define DA7210_ADC_R_EN (1 << 7)
99
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900100/* DAC/ADC HPF fields */
101#define DA7210_VOICE_F0_MASK (0x7 << 4)
102#define DA7210_VOICE_F0_25 (1 << 4)
103#define DA7210_VOICE_EN (1 << 7)
Mark Brownc2151432009-12-16 20:36:37 +0000104
Kuninori Morimoto98615452009-12-14 13:21:56 +0900105/* DAC_SEL bit fields */
106#define DA7210_DAC_L_SRC_DAI_L (4 << 0)
107#define DA7210_DAC_L_EN (1 << 3)
108#define DA7210_DAC_R_SRC_DAI_R (5 << 4)
109#define DA7210_DAC_R_EN (1 << 7)
110
111/* OUTMIX_L bit fields */
112#define DA7210_OUT_L_EN (1 << 7)
113
114/* OUTMIX_R bit fields */
115#define DA7210_OUT_R_EN (1 << 7)
116
117/* HP_CFG bit fields */
118#define DA7210_HP_2CAP_MODE (1 << 1)
119#define DA7210_HP_SENSE_EN (1 << 2)
120#define DA7210_HP_L_EN (1 << 3)
121#define DA7210_HP_MODE (1 << 6)
122#define DA7210_HP_R_EN (1 << 7)
123
124/* DAI_SRC_SEL bit fields */
125#define DA7210_DAI_OUT_L_SRC (6 << 0)
126#define DA7210_DAI_OUT_R_SRC (7 << 4)
127
128/* DAI_CFG1 bit fields */
129#define DA7210_DAI_WORD_S16_LE (0 << 0)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530130#define DA7210_DAI_WORD_S20_3LE (1 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900131#define DA7210_DAI_WORD_S24_LE (2 << 0)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530132#define DA7210_DAI_WORD_S32_LE (3 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900133#define DA7210_DAI_FLEN_64BIT (1 << 2)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530134#define DA7210_DAI_MODE_SLAVE (0 << 7)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900135#define DA7210_DAI_MODE_MASTER (1 << 7)
136
137/* DAI_CFG3 bit fields */
138#define DA7210_DAI_FORMAT_I2SMODE (0 << 0)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530139#define DA7210_DAI_FORMAT_LEFT_J (1 << 0)
140#define DA7210_DAI_FORMAT_RIGHT_J (2 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900141#define DA7210_DAI_OE (1 << 3)
142#define DA7210_DAI_EN (1 << 7)
143
144/*PLL_DIV3 bit fields */
145#define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
146#define DA7210_PLL_BYP (1 << 6)
147
148/* PLL bit fields */
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900149#define DA7210_PLL_FS_MASK (0xF << 0)
150#define DA7210_PLL_FS_8000 (0x1 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900151#define DA7210_PLL_FS_11025 (0x2 << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900152#define DA7210_PLL_FS_12000 (0x3 << 0)
153#define DA7210_PLL_FS_16000 (0x5 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900154#define DA7210_PLL_FS_22050 (0x6 << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900155#define DA7210_PLL_FS_24000 (0x7 << 0)
156#define DA7210_PLL_FS_32000 (0x9 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900157#define DA7210_PLL_FS_44100 (0xA << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900158#define DA7210_PLL_FS_48000 (0xB << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900159#define DA7210_PLL_FS_88200 (0xE << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900160#define DA7210_PLL_FS_96000 (0xF << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900161#define DA7210_PLL_EN (0x1 << 7)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900162
Ashish Chavan5eda1942011-10-19 14:19:06 +0530163/* SOFTMUTE bit fields */
164#define DA7210_RAMP_EN (1 << 6)
165
Ashish Chavande5eaf82011-10-19 14:24:37 +0530166/* CONTROL bit fields */
167#define DA7210_NOISE_SUP_EN (1 << 3)
168
169/* IN_GAIN bit fields */
170#define DA7210_INPGA_L_VOL (0x0F << 0)
171#define DA7210_INPGA_R_VOL (0xF0 << 0)
172
173/* ZERO_CROSS bit fields */
174#define DA7210_AUX1_L_ZC (1 << 0)
175#define DA7210_AUX1_R_ZC (1 << 1)
176#define DA7210_HP_L_ZC (1 << 6)
177#define DA7210_HP_R_ZC (1 << 7)
178
179/* AUX1_L bit fields */
180#define DA7210_AUX1_L_VOL (0x3F << 0)
181
182/* AUX1_R bit fields */
183#define DA7210_AUX1_R_VOL (0x3F << 0)
184
185/* Minimum INPGA and AUX1 volume to enable noise suppression */
186#define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */
187#define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */
188
Kuninori Morimoto98615452009-12-14 13:21:56 +0900189#define DA7210_VERSION "0.0.1"
190
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900191/*
192 * Playback Volume
193 *
194 * max : 0x3F (+15.0 dB)
195 * (1.5 dB step)
196 * min : 0x11 (-54.0 dB)
197 * mute : 0x10
198 * reserved : 0x00 - 0x0F
199 *
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900200 * Reserved area are considered as "mute".
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900201 */
Ashish Chavan7a0e67b2011-10-14 16:25:25 +0530202static const unsigned int hp_out_tlv[] = {
203 TLV_DB_RANGE_HEAD(2),
204 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
205 /* -54 dB to +15 dB */
206 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0),
207};
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900208
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530209static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
210static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1);
211
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530212/* ADC and DAC high pass filter f0 value */
213static const char const *da7210_hpf_cutoff_txt[] = {
214 "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi"
215};
216
217static const struct soc_enum da7210_dac_hpf_cutoff =
218 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt);
219
220static const struct soc_enum da7210_adc_hpf_cutoff =
221 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt);
222
223/* ADC and DAC voice (8kHz) high pass cutoff value */
224static const char const *da7210_vf_cutoff_txt[] = {
225 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
226};
227
228static const struct soc_enum da7210_dac_vf_cutoff =
229 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt);
230
231static const struct soc_enum da7210_adc_vf_cutoff =
232 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt);
233
Ashish Chavan5eda1942011-10-19 14:19:06 +0530234static const char *da7210_hp_mode_txt[] = {
235 "Class H", "Class G"
236};
237
238static const struct soc_enum da7210_hp_mode_sel =
239 SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt);
240
Ashish Chavande5eaf82011-10-19 14:24:37 +0530241/* ALC can be enabled only if noise suppression is disabled */
242static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol,
243 struct snd_ctl_elem_value *ucontrol)
244{
245 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
246
247 if (ucontrol->value.integer.value[0]) {
248 /* Check if noise suppression is enabled */
249 if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) {
250 dev_dbg(codec->dev,
251 "Disable noise suppression to enable ALC\n");
252 return -EINVAL;
253 }
254 }
255 /* If all conditions are met or we are actually disabling ALC */
256 return snd_soc_put_volsw(kcontrol, ucontrol);
257}
258
259/* Noise suppression can be enabled only if following conditions are met
260 * ALC disabled
261 * ZC enabled for HP and AUX1 PGA
262 * INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB
263 * AUX1_L_VOL and AUX1_R_VOL >= 6 dB
264 */
265static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol,
266 struct snd_ctl_elem_value *ucontrol)
267{
268 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
269 u8 val;
270
271 if (ucontrol->value.integer.value[0]) {
272 /* Check if ALC is enabled */
273 if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN)
274 goto err;
275
276 /* Check ZC for HP and AUX1 PGA */
277 if ((snd_soc_read(codec, DA7210_ZERO_CROSS) &
278 (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC |
279 DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC |
280 DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC))
281 goto err;
282
283 /* Check INPGA_L_VOL and INPGA_R_VOL */
284 val = snd_soc_read(codec, DA7210_IN_GAIN);
285 if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) ||
286 (((val & DA7210_INPGA_R_VOL) >> 4) <
287 DA7210_INPGA_MIN_VOL_NS))
288 goto err;
289
290 /* Check AUX1_L_VOL and AUX1_R_VOL */
291 if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) <
292 DA7210_AUX1_MIN_VOL_NS) ||
293 ((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) <
294 DA7210_AUX1_MIN_VOL_NS))
295 goto err;
296 }
297 /* If all conditions are met or we are actually disabling Noise sup */
298 return snd_soc_put_volsw(kcontrol, ucontrol);
299
300err:
301 return -EINVAL;
302}
303
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900304static const struct snd_kcontrol_new da7210_snd_controls[] = {
305
306 SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
307 DA7210_HP_L_VOL, DA7210_HP_R_VOL,
308 0, 0x3F, 0, hp_out_tlv),
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530309
310 /* DAC Equalizer controls */
311 SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0),
312 SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1,
313 eq_gain_tlv),
314 SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1,
315 eq_gain_tlv),
316 SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1,
317 eq_gain_tlv),
318 SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1,
319 eq_gain_tlv),
320 SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1,
321 eq_gain_tlv),
322
323 /* ADC Equalizer controls */
324 SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0),
325 SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3,
326 1, adc_eq_master_gain_tlv),
327 SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1,
328 eq_gain_tlv),
329 SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1,
330 eq_gain_tlv),
331 SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1,
332 eq_gain_tlv),
333 SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1,
334 eq_gain_tlv),
335 SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1,
336 eq_gain_tlv),
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530337
338 SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0),
339 SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff),
340 SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0),
341 SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff),
342
343 SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0),
344 SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff),
345 SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0),
346 SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff),
Ashish Chavan5eda1942011-10-19 14:19:06 +0530347
348 /* Mute controls */
349 SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0),
350 SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0),
351 SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0),
352 SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0),
353 SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0),
354
355 /* Zero cross controls */
356 SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0),
357 SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0),
358 SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0),
359 SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0),
360
361 SOC_ENUM("Headphone Class", da7210_hp_mode_sel),
Ashish Chavande5eaf82011-10-19 14:24:37 +0530362
363 /* ALC controls */
364 SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0,
365 snd_soc_get_volsw, da7210_put_alc_sw),
366 SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0),
367 SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0),
368 SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0),
369 SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0),
370 SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0),
371 SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0),
372
373 SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1,
374 0, snd_soc_get_volsw, da7210_put_noise_sup_sw),
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900375};
376
Ashish Chavan6950c602011-10-21 18:16:08 +0530377/*
378 * DAPM Controls
379 *
380 * Current DAPM implementation covers almost all codec components e.g. IOs,
381 * mixers, PGAs,ADC and DAC.
382 */
383/* In Mixer Left */
384static const struct snd_kcontrol_new da7210_dapm_inmixl_controls[] = {
385 SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_L, 0, 1, 0),
386 SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_L, 1, 1, 0),
387};
388
389/* In Mixer Right */
390static const struct snd_kcontrol_new da7210_dapm_inmixr_controls[] = {
391 SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_R, 0, 1, 0),
392 SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_R, 1, 1, 0),
393};
394
395/* Out Mixer Left */
396static const struct snd_kcontrol_new da7210_dapm_outmixl_controls[] = {
397 SOC_DAPM_SINGLE("DAC Left Switch", DA7210_OUTMIX_L, 4, 1, 0),
398};
399
400/* Out Mixer Right */
401static const struct snd_kcontrol_new da7210_dapm_outmixr_controls[] = {
402 SOC_DAPM_SINGLE("DAC Right Switch", DA7210_OUTMIX_R, 4, 1, 0),
403};
404
405/* DAPM widgets */
406static const struct snd_soc_dapm_widget da7210_dapm_widgets[] = {
407 /* Input Side */
408 /* Input Lines */
409 SND_SOC_DAPM_INPUT("MICL"),
410 SND_SOC_DAPM_INPUT("MICR"),
411
412 /* Input PGAs */
413 SND_SOC_DAPM_PGA("Mic Left", DA7210_STARTUP3, 0, 1, NULL, 0),
414 SND_SOC_DAPM_PGA("Mic Right", DA7210_STARTUP3, 1, 1, NULL, 0),
415
416 SND_SOC_DAPM_PGA("INPGA Left", DA7210_INMIX_L, 7, 0, NULL, 0),
417 SND_SOC_DAPM_PGA("INPGA Right", DA7210_INMIX_R, 7, 0, NULL, 0),
418
419 /* Input Mixers */
420 SND_SOC_DAPM_MIXER("In Mixer Left", SND_SOC_NOPM, 0, 0,
421 &da7210_dapm_inmixl_controls[0],
422 ARRAY_SIZE(da7210_dapm_inmixl_controls)),
423
424 SND_SOC_DAPM_MIXER("In Mixer Right", SND_SOC_NOPM, 0, 0,
425 &da7210_dapm_inmixr_controls[0],
426 ARRAY_SIZE(da7210_dapm_inmixr_controls)),
427
428 /* ADCs */
429 SND_SOC_DAPM_ADC("ADC Left", "Capture", DA7210_STARTUP3, 5, 1),
430 SND_SOC_DAPM_ADC("ADC Right", "Capture", DA7210_STARTUP3, 6, 1),
431
432 /* Output Side */
433 /* DACs */
434 SND_SOC_DAPM_DAC("DAC Left", "Playback", DA7210_STARTUP2, 5, 1),
435 SND_SOC_DAPM_DAC("DAC Right", "Playback", DA7210_STARTUP2, 6, 1),
436
437 /* Output Mixers */
438 SND_SOC_DAPM_MIXER("Out Mixer Left", SND_SOC_NOPM, 0, 0,
439 &da7210_dapm_outmixl_controls[0],
440 ARRAY_SIZE(da7210_dapm_outmixl_controls)),
441
442 SND_SOC_DAPM_MIXER("Out Mixer Right", SND_SOC_NOPM, 0, 0,
443 &da7210_dapm_outmixr_controls[0],
444 ARRAY_SIZE(da7210_dapm_outmixr_controls)),
445
446 /* Output PGAs */
447 SND_SOC_DAPM_PGA("OUTPGA Left Enable", DA7210_OUTMIX_L, 7, 0, NULL, 0),
448 SND_SOC_DAPM_PGA("OUTPGA Right Enable", DA7210_OUTMIX_R, 7, 0, NULL, 0),
449
450 SND_SOC_DAPM_PGA("Headphone Left", DA7210_STARTUP2, 3, 1, NULL, 0),
451 SND_SOC_DAPM_PGA("Headphone Right", DA7210_STARTUP2, 4, 1, NULL, 0),
452
453 /* Output Lines */
454 SND_SOC_DAPM_OUTPUT("HPL"),
455 SND_SOC_DAPM_OUTPUT("HPR"),
456};
457
458/* DAPM audio route definition */
459static const struct snd_soc_dapm_route da7210_audio_map[] = {
460 /* Dest Connecting Widget source */
461 /* Input path */
462 {"Mic Left", NULL, "MICL"},
463 {"Mic Right", NULL, "MICR"},
464
465 {"In Mixer Left", "Mic Left Switch", "Mic Left"},
466 {"In Mixer Left", "Mic Right Switch", "Mic Right"},
467
468 {"In Mixer Right", "Mic Right Switch", "Mic Right"},
469 {"In Mixer Right", "Mic Left Switch", "Mic Left"},
470
471 {"INPGA Left", NULL, "In Mixer Left"},
472 {"ADC Left", NULL, "INPGA Left"},
473
474 {"INPGA Right", NULL, "In Mixer Right"},
475 {"ADC Right", NULL, "INPGA Right"},
476
477 /* Output path */
478 {"Out Mixer Left", "DAC Left Switch", "DAC Left"},
479 {"Out Mixer Right", "DAC Right Switch", "DAC Right"},
480
481 {"OUTPGA Left Enable", NULL, "Out Mixer Left"},
482 {"OUTPGA Right Enable", NULL, "Out Mixer Right"},
483
484 {"Headphone Left", NULL, "OUTPGA Left Enable"},
485 {"HPL", NULL, "Headphone Left"},
486
487 {"Headphone Right", NULL, "OUTPGA Right Enable"},
488 {"HPR", NULL, "Headphone Right"},
489};
490
Kuninori Morimoto98615452009-12-14 13:21:56 +0900491/* Codec private data */
492struct da7210_priv {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000493 enum snd_soc_control_type control_type;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900494};
495
Kuninori Morimoto98615452009-12-14 13:21:56 +0900496/*
497 * Register cache
498 */
499static const u8 da7210_reg[] = {
500 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R0 - R7 */
501 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, /* R8 - RF */
502 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x54, /* R10 - R17 */
503 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R18 - R1F */
504 0x00, 0x00, 0x00, 0x02, 0x00, 0x76, 0x00, 0x00, /* R20 - R27 */
505 0x04, 0x00, 0x00, 0x30, 0x2A, 0x00, 0x40, 0x00, /* R28 - R2F */
506 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, /* R30 - R37 */
507 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, /* R38 - R3F */
508 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R40 - R4F */
509 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R48 - R4F */
510 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R50 - R57 */
511 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R58 - R5F */
512 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R60 - R67 */
513 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R68 - R6F */
514 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R70 - R77 */
515 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x54, 0x00, /* R78 - R7F */
516 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, /* R80 - R87 */
517 0x00, /* R88 */
518};
519
Axel Lin40a49712011-10-12 07:16:25 +0800520static int da7210_volatile_register(struct snd_soc_codec *codec,
521 unsigned int reg)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900522{
Axel Lin40a49712011-10-12 07:16:25 +0800523 switch (reg) {
524 case DA7210_STATUS:
525 return 1;
526 default:
527 return 0;
528 }
Kuninori Morimoto98615452009-12-14 13:21:56 +0900529}
Kuninori Morimoto98615452009-12-14 13:21:56 +0900530
531/*
532 * Set PCM DAI word length.
533 */
534static int da7210_hw_params(struct snd_pcm_substream *substream,
535 struct snd_pcm_hw_params *params,
536 struct snd_soc_dai *dai)
537{
538 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000539 struct snd_soc_codec *codec = rtd->codec;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900540 u32 dai_cfg1;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900541 u32 fs, bypass;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900542
543 /* set DAI source to Left and Right ADC */
Axel Lin40a49712011-10-12 07:16:25 +0800544 snd_soc_write(codec, DA7210_DAI_SRC_SEL,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900545 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
546
547 /* Enable DAI */
Axel Lin40a49712011-10-12 07:16:25 +0800548 snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900549
Axel Lin40a49712011-10-12 07:16:25 +0800550 dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900551
552 switch (params_format(params)) {
553 case SNDRV_PCM_FORMAT_S16_LE:
554 dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
555 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530556 case SNDRV_PCM_FORMAT_S20_3LE:
557 dai_cfg1 |= DA7210_DAI_WORD_S20_3LE;
558 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900559 case SNDRV_PCM_FORMAT_S24_LE:
560 dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
561 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530562 case SNDRV_PCM_FORMAT_S32_LE:
563 dai_cfg1 |= DA7210_DAI_WORD_S32_LE;
564 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900565 default:
566 return -EINVAL;
567 }
568
Axel Lin40a49712011-10-12 07:16:25 +0800569 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900570
Kuninori Morimoto98615452009-12-14 13:21:56 +0900571 switch (params_rate(params)) {
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900572 case 8000:
573 fs = DA7210_PLL_FS_8000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900574 bypass = DA7210_PLL_BYP;
575 break;
576 case 11025:
577 fs = DA7210_PLL_FS_11025;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900578 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900579 break;
580 case 12000:
581 fs = DA7210_PLL_FS_12000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900582 bypass = DA7210_PLL_BYP;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900583 break;
584 case 16000:
585 fs = DA7210_PLL_FS_16000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900586 bypass = DA7210_PLL_BYP;
587 break;
588 case 22050:
589 fs = DA7210_PLL_FS_22050;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900590 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900591 break;
592 case 32000:
593 fs = DA7210_PLL_FS_32000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900594 bypass = DA7210_PLL_BYP;
595 break;
596 case 44100:
597 fs = DA7210_PLL_FS_44100;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900598 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900599 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900600 case 48000:
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900601 fs = DA7210_PLL_FS_48000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900602 bypass = DA7210_PLL_BYP;
603 break;
604 case 88200:
605 fs = DA7210_PLL_FS_88200;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900606 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900607 break;
608 case 96000:
609 fs = DA7210_PLL_FS_96000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900610 bypass = DA7210_PLL_BYP;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900611 break;
612 default:
613 return -EINVAL;
614 }
615
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900616 /* Disable active mode */
617 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
618
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900619 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900620 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
621
622 /* Enable active mode */
623 snd_soc_update_bits(codec, DA7210_STARTUP1,
624 DA7210_SC_MST_EN, DA7210_SC_MST_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900625
626 return 0;
627}
628
629/*
630 * Set DAI mode and Format
631 */
632static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
633{
634 struct snd_soc_codec *codec = codec_dai->codec;
635 u32 dai_cfg1;
636 u32 dai_cfg3;
637
Axel Lin40a49712011-10-12 07:16:25 +0800638 dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
639 dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900640
641 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
642 case SND_SOC_DAIFMT_CBM_CFM:
643 dai_cfg1 |= DA7210_DAI_MODE_MASTER;
644 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530645 case SND_SOC_DAIFMT_CBS_CFS:
646 dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
647 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900648 default:
649 return -EINVAL;
650 }
651
652 /* FIXME
653 *
654 * It support I2S only now
655 */
656 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
657 case SND_SOC_DAIFMT_I2S:
658 dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
659 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530660 case SND_SOC_DAIFMT_LEFT_J:
661 dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J;
662 break;
663 case SND_SOC_DAIFMT_RIGHT_J:
664 dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J;
665 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900666 default:
667 return -EINVAL;
668 }
669
670 /* FIXME
671 *
672 * It support 64bit data transmission only now
673 */
674 dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
675
Axel Lin40a49712011-10-12 07:16:25 +0800676 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
677 snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900678
679 return 0;
680}
681
Ashish Chavan5eda1942011-10-19 14:19:06 +0530682static int da7210_mute(struct snd_soc_dai *dai, int mute)
683{
684 struct snd_soc_codec *codec = dai->codec;
685 u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB;
686
687 if (mute)
688 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4);
689 else
690 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg);
691 return 0;
692}
693
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530694#define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
695 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900696
697/* DAI operations */
698static struct snd_soc_dai_ops da7210_dai_ops = {
Kuninori Morimoto98615452009-12-14 13:21:56 +0900699 .hw_params = da7210_hw_params,
700 .set_fmt = da7210_set_dai_fmt,
Ashish Chavan5eda1942011-10-19 14:19:06 +0530701 .digital_mute = da7210_mute,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900702};
703
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000704static struct snd_soc_dai_driver da7210_dai = {
705 .name = "da7210-hifi",
Kuninori Morimoto98615452009-12-14 13:21:56 +0900706 /* playback capabilities */
707 .playback = {
708 .stream_name = "Playback",
709 .channels_min = 1,
710 .channels_max = 2,
711 .rates = SNDRV_PCM_RATE_8000_96000,
712 .formats = DA7210_FORMATS,
713 },
714 /* capture capabilities */
715 .capture = {
716 .stream_name = "Capture",
717 .channels_min = 1,
718 .channels_max = 2,
719 .rates = SNDRV_PCM_RATE_8000_96000,
720 .formats = DA7210_FORMATS,
721 },
722 .ops = &da7210_dai_ops,
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900723 .symmetric_rates = 1,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900724};
Kuninori Morimoto98615452009-12-14 13:21:56 +0900725
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000726static int da7210_probe(struct snd_soc_codec *codec)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900727{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000728 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
Axel Lin40a49712011-10-12 07:16:25 +0800729 int ret;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900730
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000731 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900732
Axel Lin40a49712011-10-12 07:16:25 +0800733 ret = snd_soc_codec_set_cache_io(codec, 8, 8, da7210->control_type);
734 if (ret < 0) {
735 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
736 return ret;
737 }
Kuninori Morimoto98615452009-12-14 13:21:56 +0900738
739 /* FIXME
740 *
741 * This driver use fixed value here
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900742 * And below settings expects MCLK = 12.288MHz
743 *
744 * When you select different MCLK, please check...
745 * DA7210_PLL_DIV1 val
746 * DA7210_PLL_DIV2 val
747 * DA7210_PLL_DIV3 val
748 * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
Kuninori Morimoto98615452009-12-14 13:21:56 +0900749 */
750
751 /*
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900752 * make sure that DA7210 use bypass mode before start up
753 */
Axel Lin40a49712011-10-12 07:16:25 +0800754 snd_soc_write(codec, DA7210_STARTUP1, 0);
755 snd_soc_write(codec, DA7210_PLL_DIV3,
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900756 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
757
758 /*
Kuninori Morimoto98615452009-12-14 13:21:56 +0900759 * ADC settings
760 */
761
762 /* Enable Left & Right MIC PGA and Mic Bias */
Axel Lin40a49712011-10-12 07:16:25 +0800763 snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
764 snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900765
766 /* Enable Left and Right input PGA */
Axel Lin40a49712011-10-12 07:16:25 +0800767 snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
768 snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900769
770 /* Enable Left and Right ADC */
Axel Lin40a49712011-10-12 07:16:25 +0800771 snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900772
773 /*
774 * DAC settings
775 */
776
777 /* Enable Left and Right DAC */
Axel Lin40a49712011-10-12 07:16:25 +0800778 snd_soc_write(codec, DA7210_DAC_SEL,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900779 DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
780 DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
781
782 /* Enable Left and Right out PGA */
Axel Lin40a49712011-10-12 07:16:25 +0800783 snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
784 snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900785
786 /* Enable Left and Right HeadPhone PGA */
Axel Lin40a49712011-10-12 07:16:25 +0800787 snd_soc_write(codec, DA7210_HP_CFG,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900788 DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
789 DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
790
Ashish Chavan5eda1942011-10-19 14:19:06 +0530791 /* Enable ramp mode for DAC gain update */
792 snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN);
793
Kuninori Morimoto98615452009-12-14 13:21:56 +0900794 /* Diable PLL and bypass it */
Axel Lin40a49712011-10-12 07:16:25 +0800795 snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900796
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900797 /*
798 * If 48kHz sound came, it use bypass mode,
799 * and when it is 44.1kHz, it use PLL.
800 *
801 * This time, this driver sets PLL always ON
802 * and controls bypass/PLL mode by switching
803 * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
804 * see da7210_hw_params
805 */
Axel Lin40a49712011-10-12 07:16:25 +0800806 snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
807 snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
808 snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
Kuninori Morimoto98615452009-12-14 13:21:56 +0900809 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900810 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
811
812 /* As suggested by Dialog */
Axel Lin40a49712011-10-12 07:16:25 +0800813 snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */
814 snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0xB4);
815 snd_soc_write(codec, DA7210_A_PLL1, 0x01);
816 snd_soc_write(codec, DA7210_A_CP_MODE, 0x7C);
817 snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */
818 snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0x00);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900819
820 /* Activate all enabled subsystem */
Axel Lin40a49712011-10-12 07:16:25 +0800821 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900822
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000823 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900824
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000825 return 0;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900826}
827
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000828static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +0900829 .probe = da7210_probe,
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +0900830 .reg_cache_size = ARRAY_SIZE(da7210_reg),
831 .reg_word_size = sizeof(u8),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000832 .reg_cache_default = da7210_reg,
Axel Lin40a49712011-10-12 07:16:25 +0800833 .volatile_register = da7210_volatile_register,
Mark Browna6f096f2011-10-14 20:18:49 +0100834
835 .controls = da7210_snd_controls,
836 .num_controls = ARRAY_SIZE(da7210_snd_controls),
Ashish Chavan6950c602011-10-21 18:16:08 +0530837
838 .dapm_widgets = da7210_dapm_widgets,
839 .num_dapm_widgets = ARRAY_SIZE(da7210_dapm_widgets),
840 .dapm_routes = da7210_audio_map,
841 .num_dapm_routes = ARRAY_SIZE(da7210_audio_map),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000842};
843
Kuninori Morimoto98615452009-12-14 13:21:56 +0900844#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
Mark Brown735fe4c2010-01-12 14:13:00 +0000845static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
846 const struct i2c_device_id *id)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900847{
848 struct da7210_priv *da7210;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900849 int ret;
850
851 da7210 = kzalloc(sizeof(struct da7210_priv), GFP_KERNEL);
852 if (!da7210)
853 return -ENOMEM;
854
Kuninori Morimoto98615452009-12-14 13:21:56 +0900855 i2c_set_clientdata(i2c, da7210);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000856 da7210->control_type = SND_SOC_I2C;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900857
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000858 ret = snd_soc_register_codec(&i2c->dev,
859 &soc_codec_dev_da7210, &da7210_dai, 1);
860 if (ret < 0)
Axel Lin085efd22010-07-23 05:53:45 +0000861 kfree(da7210);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900862
863 return ret;
864}
865
Mark Brown735fe4c2010-01-12 14:13:00 +0000866static int __devexit da7210_i2c_remove(struct i2c_client *client)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900867{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000868 snd_soc_unregister_codec(&client->dev);
869 kfree(i2c_get_clientdata(client));
Kuninori Morimoto98615452009-12-14 13:21:56 +0900870 return 0;
871}
872
873static const struct i2c_device_id da7210_i2c_id[] = {
874 { "da7210", 0 },
875 { }
876};
877MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
878
879/* I2C codec control layer */
880static struct i2c_driver da7210_i2c_driver = {
881 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000882 .name = "da7210-codec",
Kuninori Morimoto98615452009-12-14 13:21:56 +0900883 .owner = THIS_MODULE,
884 },
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +0900885 .probe = da7210_i2c_probe,
886 .remove = __devexit_p(da7210_i2c_remove),
887 .id_table = da7210_i2c_id,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900888};
889#endif
890
Kuninori Morimoto98615452009-12-14 13:21:56 +0900891static int __init da7210_modinit(void)
892{
893 int ret = 0;
894#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
895 ret = i2c_add_driver(&da7210_i2c_driver);
896#endif
897 return ret;
898}
899module_init(da7210_modinit);
900
901static void __exit da7210_exit(void)
902{
903#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
904 i2c_del_driver(&da7210_i2c_driver);
905#endif
906}
907module_exit(da7210_exit);
908
909MODULE_DESCRIPTION("ASoC DA7210 driver");
910MODULE_AUTHOR("David Chen, Kuninori Morimoto");
911MODULE_LICENSE("GPL");