blob: 5dfdf6e7a39aa54038695ed3d1df57c7bac14880 [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>
Ashish Chavanaa0e25c2012-03-29 19:06:29 +053020#include <linux/spi/spi.h>
Ashish Chavan33593b52012-03-08 19:04:56 +053021#include <linux/regmap.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040023#include <linux/module.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090024#include <sound/pcm.h>
25#include <sound/pcm_params.h>
Liam Girdwoodce6120c2010-11-05 15:53:46 +020026#include <sound/soc.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090027#include <sound/initval.h>
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +090028#include <sound/tlv.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090029
Kuninori Morimoto98615452009-12-14 13:21:56 +090030/* DA7210 register space */
Ashish Chavanaa0e25c2012-03-29 19:06:29 +053031#define DA7210_PAGE_CONTROL 0x00
Ashish Chavande5eaf82011-10-19 14:24:37 +053032#define DA7210_CONTROL 0x01
Kuninori Morimoto98615452009-12-14 13:21:56 +090033#define DA7210_STATUS 0x02
34#define DA7210_STARTUP1 0x03
Ashish Chavan6950c602011-10-21 18:16:08 +053035#define DA7210_STARTUP2 0x04
36#define DA7210_STARTUP3 0x05
Kuninori Morimoto98615452009-12-14 13:21:56 +090037#define DA7210_MIC_L 0x07
38#define DA7210_MIC_R 0x08
Ashish Chavande5eaf82011-10-19 14:24:37 +053039#define DA7210_AUX1_L 0x09
40#define DA7210_AUX1_R 0x0A
Ashish Chavan5eda1942011-10-19 14:19:06 +053041#define DA7210_AUX2 0x0B
Ashish Chavande5eaf82011-10-19 14:24:37 +053042#define DA7210_IN_GAIN 0x0C
Kuninori Morimoto98615452009-12-14 13:21:56 +090043#define DA7210_INMIX_L 0x0D
44#define DA7210_INMIX_R 0x0E
45#define DA7210_ADC_HPF 0x0F
46#define DA7210_ADC 0x10
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +053047#define DA7210_ADC_EQ1_2 0X11
48#define DA7210_ADC_EQ3_4 0x12
49#define DA7210_ADC_EQ5 0x13
Kuninori Morimoto98615452009-12-14 13:21:56 +090050#define DA7210_DAC_HPF 0x14
51#define DA7210_DAC_L 0x15
52#define DA7210_DAC_R 0x16
53#define DA7210_DAC_SEL 0x17
Ashish Chavan5eda1942011-10-19 14:19:06 +053054#define DA7210_SOFTMUTE 0x18
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +053055#define DA7210_DAC_EQ1_2 0x19
56#define DA7210_DAC_EQ3_4 0x1A
57#define DA7210_DAC_EQ5 0x1B
Kuninori Morimoto98615452009-12-14 13:21:56 +090058#define DA7210_OUTMIX_L 0x1C
59#define DA7210_OUTMIX_R 0x1D
Ashish Chavan52082d82011-10-21 19:06:23 +053060#define DA7210_OUT1_L 0x1E
61#define DA7210_OUT1_R 0x1F
62#define DA7210_OUT2 0x20
Kuninori Morimoto98615452009-12-14 13:21:56 +090063#define DA7210_HP_L_VOL 0x21
64#define DA7210_HP_R_VOL 0x22
65#define DA7210_HP_CFG 0x23
Ashish Chavan5eda1942011-10-19 14:19:06 +053066#define DA7210_ZERO_CROSS 0x24
Kuninori Morimoto98615452009-12-14 13:21:56 +090067#define DA7210_DAI_SRC_SEL 0x25
68#define DA7210_DAI_CFG1 0x26
69#define DA7210_DAI_CFG3 0x28
Kuninori Morimoto960b3b42010-03-11 11:37:44 +090070#define DA7210_PLL_DIV1 0x29
71#define DA7210_PLL_DIV2 0x2A
Kuninori Morimoto98615452009-12-14 13:21:56 +090072#define DA7210_PLL_DIV3 0x2B
73#define DA7210_PLL 0x2C
Ashish Chavande5eaf82011-10-19 14:24:37 +053074#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
Kuninori Morimoto960b3b42010-03-11 11:37:44 +090080#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
Kuninori Morimoto98615452009-12-14 13:21:56 +090084
85/* STARTUP1 bit fields */
86#define DA7210_SC_MST_EN (1 << 0)
87
88/* MIC_L bit fields */
89#define DA7210_MICBIAS_EN (1 << 6)
90#define DA7210_MIC_L_EN (1 << 7)
91
92/* MIC_R bit fields */
93#define DA7210_MIC_R_EN (1 << 7)
94
95/* INMIX_L bit fields */
96#define DA7210_IN_L_EN (1 << 7)
97
98/* INMIX_R bit fields */
99#define DA7210_IN_R_EN (1 << 7)
100
Kuninori Morimoto98615452009-12-14 13:21:56 +0900101/* ADC bit fields */
Ashish Chavande5eaf82011-10-19 14:24:37 +0530102#define DA7210_ADC_ALC_EN (1 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900103#define DA7210_ADC_L_EN (1 << 3)
104#define DA7210_ADC_R_EN (1 << 7)
105
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900106/* 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)
Mark Brownc2151432009-12-16 20:36:37 +0000110
Kuninori Morimoto98615452009-12-14 13:21:56 +0900111/* 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)
116
117/* OUTMIX_L bit fields */
118#define DA7210_OUT_L_EN (1 << 7)
119
120/* OUTMIX_R bit fields */
121#define DA7210_OUT_R_EN (1 << 7)
122
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)
129
130/* DAI_SRC_SEL bit fields */
131#define DA7210_DAI_OUT_L_SRC (6 << 0)
132#define DA7210_DAI_OUT_R_SRC (7 << 4)
133
134/* DAI_CFG1 bit fields */
135#define DA7210_DAI_WORD_S16_LE (0 << 0)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530136#define DA7210_DAI_WORD_S20_3LE (1 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900137#define DA7210_DAI_WORD_S24_LE (2 << 0)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530138#define DA7210_DAI_WORD_S32_LE (3 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900139#define DA7210_DAI_FLEN_64BIT (1 << 2)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530140#define DA7210_DAI_MODE_SLAVE (0 << 7)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900141#define DA7210_DAI_MODE_MASTER (1 << 7)
142
143/* DAI_CFG3 bit fields */
144#define DA7210_DAI_FORMAT_I2SMODE (0 << 0)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530145#define DA7210_DAI_FORMAT_LEFT_J (1 << 0)
146#define DA7210_DAI_FORMAT_RIGHT_J (2 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900147#define DA7210_DAI_OE (1 << 3)
148#define DA7210_DAI_EN (1 << 7)
149
150/*PLL_DIV3 bit fields */
151#define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
152#define DA7210_PLL_BYP (1 << 6)
153
154/* PLL bit fields */
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900155#define DA7210_PLL_FS_MASK (0xF << 0)
156#define DA7210_PLL_FS_8000 (0x1 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900157#define DA7210_PLL_FS_11025 (0x2 << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900158#define DA7210_PLL_FS_12000 (0x3 << 0)
159#define DA7210_PLL_FS_16000 (0x5 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900160#define DA7210_PLL_FS_22050 (0x6 << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900161#define DA7210_PLL_FS_24000 (0x7 << 0)
162#define DA7210_PLL_FS_32000 (0x9 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900163#define DA7210_PLL_FS_44100 (0xA << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900164#define DA7210_PLL_FS_48000 (0xB << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900165#define DA7210_PLL_FS_88200 (0xE << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900166#define DA7210_PLL_FS_96000 (0xF << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900167#define DA7210_PLL_EN (0x1 << 7)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900168
Ashish Chavan5eda1942011-10-19 14:19:06 +0530169/* SOFTMUTE bit fields */
170#define DA7210_RAMP_EN (1 << 6)
171
Ashish Chavande5eaf82011-10-19 14:24:37 +0530172/* CONTROL bit fields */
173#define DA7210_NOISE_SUP_EN (1 << 3)
174
175/* IN_GAIN bit fields */
176#define DA7210_INPGA_L_VOL (0x0F << 0)
177#define DA7210_INPGA_R_VOL (0xF0 << 0)
178
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)
184
185/* AUX1_L bit fields */
186#define DA7210_AUX1_L_VOL (0x3F << 0)
Ashish Chavan24b6f262012-01-02 17:35:52 +0530187#define DA7210_AUX1_L_EN (1 << 7)
Ashish Chavande5eaf82011-10-19 14:24:37 +0530188
189/* AUX1_R bit fields */
190#define DA7210_AUX1_R_VOL (0x3F << 0)
Ashish Chavan24b6f262012-01-02 17:35:52 +0530191#define DA7210_AUX1_R_EN (1 << 7)
192
193/* AUX2 bit fields */
194#define DA7210_AUX2_EN (1 << 3)
Ashish Chavande5eaf82011-10-19 14:24:37 +0530195
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 */
199
Ashish Chavan52082d82011-10-21 19:06:23 +0530200/* OUT1_L bit fields */
201#define DA7210_OUT1_L_EN (1 << 7)
202
203/* OUT1_R bit fields */
204#define DA7210_OUT1_R_EN (1 << 7)
205
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)
210
Kuninori Morimoto98615452009-12-14 13:21:56 +0900211#define DA7210_VERSION "0.0.1"
212
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900213/*
214 * Playback Volume
215 *
216 * max : 0x3F (+15.0 dB)
217 * (1.5 dB step)
218 * min : 0x11 (-54.0 dB)
219 * mute : 0x10
220 * reserved : 0x00 - 0x0F
221 *
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900222 * Reserved area are considered as "mute".
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900223 */
Ashish Chavan7a0e67b2011-10-14 16:25:25 +0530224static 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),
229};
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900230
Ashish Chavan52082d82011-10-21 19:06:23 +0530231static 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),
234 /* -54dB to 15dB */
235 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0)
236};
237
238static const unsigned int mono_vol_tlv[] = {
239 TLV_DB_RANGE_HEAD(2),
240 0x0, 0x2, TLV_DB_SCALE_ITEM(-1800, 0, 1),
241 /* -18dB to 6dB */
242 0x3, 0x7, TLV_DB_SCALE_ITEM(-1800, 600, 0)
243};
244
Ashish Chavan24b6f262012-01-02 17:35:52 +0530245static 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),
248 /* -48dB to 21dB */
249 0x11, 0x3f, TLV_DB_SCALE_ITEM(-4800, 150, 0)
250};
251
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530252static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
253static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1);
Ashish Chavan52082d82011-10-21 19:06:23 +0530254static const DECLARE_TLV_DB_SCALE(dac_gain_tlv, -7725, 75, 0);
Ashish Chavan24b6f262012-01-02 17:35:52 +0530255static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, -600, 600, 0);
256static const DECLARE_TLV_DB_SCALE(aux2_vol_tlv, -600, 600, 0);
257static const DECLARE_TLV_DB_SCALE(inpga_gain_tlv, -450, 150, 0);
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530258
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530259/* ADC and DAC high pass filter f0 value */
Mark Brownf4034142011-11-09 23:15:26 +0000260static const char * const da7210_hpf_cutoff_txt[] = {
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530261 "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi"
262};
263
264static const struct soc_enum da7210_dac_hpf_cutoff =
265 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt);
266
267static const struct soc_enum da7210_adc_hpf_cutoff =
268 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt);
269
270/* ADC and DAC voice (8kHz) high pass cutoff value */
Mark Brownf4034142011-11-09 23:15:26 +0000271static const char * const da7210_vf_cutoff_txt[] = {
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530272 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
273};
274
275static const struct soc_enum da7210_dac_vf_cutoff =
276 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt);
277
278static const struct soc_enum da7210_adc_vf_cutoff =
279 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt);
280
Ashish Chavan5eda1942011-10-19 14:19:06 +0530281static const char *da7210_hp_mode_txt[] = {
282 "Class H", "Class G"
283};
284
285static const struct soc_enum da7210_hp_mode_sel =
286 SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt);
287
Ashish Chavande5eaf82011-10-19 14:24:37 +0530288/* ALC can be enabled only if noise suppression is disabled */
289static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol,
290 struct snd_ctl_elem_value *ucontrol)
291{
292 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
293
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) {
297 dev_dbg(codec->dev,
298 "Disable noise suppression to enable ALC\n");
299 return -EINVAL;
300 }
301 }
302 /* If all conditions are met or we are actually disabling ALC */
303 return snd_soc_put_volsw(kcontrol, ucontrol);
304}
305
306/* Noise suppression can be enabled only if following conditions are met
307 * ALC disabled
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
311 */
312static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol,
313 struct snd_ctl_elem_value *ucontrol)
314{
315 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
316 u8 val;
317
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)
321 goto err;
322
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))
328 goto err;
329
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))
335 goto err;
336
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))
342 goto err;
343 }
344 /* If all conditions are met or we are actually disabling Noise sup */
345 return snd_soc_put_volsw(kcontrol, ucontrol);
346
347err:
348 return -EINVAL;
349}
350
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900351static const struct snd_kcontrol_new da7210_snd_controls[] = {
352
353 SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
354 DA7210_HP_L_VOL, DA7210_HP_R_VOL,
355 0, 0x3F, 0, hp_out_tlv),
Ashish Chavan52082d82011-10-21 19:06:23 +0530356 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,
363 mono_vol_tlv),
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530364
Ashish Chavan24b6f262012-01-02 17:35:52 +0530365 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,
372 aux2_vol_tlv),
373 SOC_DOUBLE_TLV("In PGA Capture Volume", DA7210_IN_GAIN, 0, 4, 0xF, 0,
374 inpga_gain_tlv),
375
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530376 /* 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,
379 eq_gain_tlv),
380 SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1,
381 eq_gain_tlv),
382 SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1,
383 eq_gain_tlv),
384 SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1,
385 eq_gain_tlv),
386 SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1,
387 eq_gain_tlv),
388
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,
394 eq_gain_tlv),
395 SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1,
396 eq_gain_tlv),
397 SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1,
398 eq_gain_tlv),
399 SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1,
400 eq_gain_tlv),
401 SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1,
402 eq_gain_tlv),
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530403
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),
408
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),
Ashish Chavan5eda1942011-10-19 14:19:06 +0530413
414 /* Mute controls */
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),
420
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),
426
427 SOC_ENUM("Headphone Class", da7210_hp_mode_sel),
Ashish Chavande5eaf82011-10-19 14:24:37 +0530428
429 /* ALC controls */
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),
438
439 SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1,
440 0, snd_soc_get_volsw, da7210_put_noise_sup_sw),
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900441};
442
Ashish Chavan6950c602011-10-21 18:16:08 +0530443/*
444 * DAPM Controls
445 *
446 * Current DAPM implementation covers almost all codec components e.g. IOs,
447 * mixers, PGAs,ADC and DAC.
448 */
449/* In Mixer Left */
450static 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),
Ashish Chavan24b6f262012-01-02 17:35:52 +0530453 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),
Ashish Chavan6950c602011-10-21 18:16:08 +0530456};
457
458/* In Mixer Right */
459static 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),
Ashish Chavan24b6f262012-01-02 17:35:52 +0530462 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),
Ashish Chavan6950c602011-10-21 18:16:08 +0530465};
466
467/* Out Mixer Left */
468static const struct snd_kcontrol_new da7210_dapm_outmixl_controls[] = {
Ashish Chavan24b6f262012-01-02 17:35:52 +0530469 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),
Ashish Chavan6950c602011-10-21 18:16:08 +0530473 SOC_DAPM_SINGLE("DAC Left Switch", DA7210_OUTMIX_L, 4, 1, 0),
474};
475
476/* Out Mixer Right */
477static const struct snd_kcontrol_new da7210_dapm_outmixr_controls[] = {
Ashish Chavan24b6f262012-01-02 17:35:52 +0530478 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),
Ashish Chavan6950c602011-10-21 18:16:08 +0530482 SOC_DAPM_SINGLE("DAC Right Switch", DA7210_OUTMIX_R, 4, 1, 0),
483};
484
Ashish Chavan52082d82011-10-21 19:06:23 +0530485/* Mono Mixer */
486static const struct snd_kcontrol_new da7210_dapm_monomix_controls[] = {
Ashish Chavan24b6f262012-01-02 17:35:52 +0530487 SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUT2, 3, 1, 0),
488 SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUT2, 4, 1, 0),
Ashish Chavan52082d82011-10-21 19:06:23 +0530489 SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_OUT2, 5, 1, 0),
490 SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_OUT2, 6, 1, 0),
491};
492
Ashish Chavan6950c602011-10-21 18:16:08 +0530493/* DAPM widgets */
494static const struct snd_soc_dapm_widget da7210_dapm_widgets[] = {
495 /* Input Side */
496 /* Input Lines */
497 SND_SOC_DAPM_INPUT("MICL"),
498 SND_SOC_DAPM_INPUT("MICR"),
Ashish Chavan24b6f262012-01-02 17:35:52 +0530499 SND_SOC_DAPM_INPUT("AUX1L"),
500 SND_SOC_DAPM_INPUT("AUX1R"),
501 SND_SOC_DAPM_INPUT("AUX2"),
Ashish Chavan6950c602011-10-21 18:16:08 +0530502
503 /* Input PGAs */
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),
Ashish Chavan24b6f262012-01-02 17:35:52 +0530506 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),
Ashish Chavan6950c602011-10-21 18:16:08 +0530509
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),
512
Ashish Chavan24b6f262012-01-02 17:35:52 +0530513 /* MICBIAS */
514 SND_SOC_DAPM_SUPPLY("Mic Bias", DA7210_MIC_L, 6, 0, NULL, 0),
515
Ashish Chavan6950c602011-10-21 18:16:08 +0530516 /* Input Mixers */
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)),
520
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)),
524
525 /* ADCs */
526 SND_SOC_DAPM_ADC("ADC Left", "Capture", DA7210_STARTUP3, 5, 1),
527 SND_SOC_DAPM_ADC("ADC Right", "Capture", DA7210_STARTUP3, 6, 1),
528
529 /* Output Side */
530 /* DACs */
531 SND_SOC_DAPM_DAC("DAC Left", "Playback", DA7210_STARTUP2, 5, 1),
532 SND_SOC_DAPM_DAC("DAC Right", "Playback", DA7210_STARTUP2, 6, 1),
533
534 /* Output Mixers */
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)),
538
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)),
542
Ashish Chavan52082d82011-10-21 19:06:23 +0530543 SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0,
544 &da7210_dapm_monomix_controls[0],
545 ARRAY_SIZE(da7210_dapm_monomix_controls)),
546
Ashish Chavan6950c602011-10-21 18:16:08 +0530547 /* Output PGAs */
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),
550
Ashish Chavan52082d82011-10-21 19:06:23 +0530551 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),
Ashish Chavan6950c602011-10-21 18:16:08 +0530554 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),
556
557 /* Output Lines */
Ashish Chavan52082d82011-10-21 19:06:23 +0530558 SND_SOC_DAPM_OUTPUT("OUT1L"),
559 SND_SOC_DAPM_OUTPUT("OUT1R"),
Ashish Chavan6950c602011-10-21 18:16:08 +0530560 SND_SOC_DAPM_OUTPUT("HPL"),
561 SND_SOC_DAPM_OUTPUT("HPR"),
Ashish Chavan52082d82011-10-21 19:06:23 +0530562 SND_SOC_DAPM_OUTPUT("OUT2"),
Ashish Chavan6950c602011-10-21 18:16:08 +0530563};
564
565/* DAPM audio route definition */
566static const struct snd_soc_dapm_route da7210_audio_map[] = {
567 /* Dest Connecting Widget source */
568 /* Input path */
569 {"Mic Left", NULL, "MICL"},
570 {"Mic Right", NULL, "MICR"},
Ashish Chavan24b6f262012-01-02 17:35:52 +0530571 {"Aux1 Left", NULL, "AUX1L"},
572 {"Aux1 Right", NULL, "AUX1R"},
573 {"Aux2 Mono", NULL, "AUX2"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530574
575 {"In Mixer Left", "Mic Left Switch", "Mic Left"},
576 {"In Mixer Left", "Mic Right Switch", "Mic Right"},
Ashish Chavan24b6f262012-01-02 17:35:52 +0530577 {"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"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530580
581 {"In Mixer Right", "Mic Right Switch", "Mic Right"},
582 {"In Mixer Right", "Mic Left Switch", "Mic Left"},
Ashish Chavan24b6f262012-01-02 17:35:52 +0530583 {"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"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530586
587 {"INPGA Left", NULL, "In Mixer Left"},
588 {"ADC Left", NULL, "INPGA Left"},
589
590 {"INPGA Right", NULL, "In Mixer Right"},
591 {"ADC Right", NULL, "INPGA Right"},
592
593 /* Output path */
Ashish Chavan24b6f262012-01-02 17:35:52 +0530594 {"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"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530598 {"Out Mixer Left", "DAC Left Switch", "DAC Left"},
Ashish Chavan24b6f262012-01-02 17:35:52 +0530599
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"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530604 {"Out Mixer Right", "DAC Right Switch", "DAC Right"},
605
Ashish Chavan24b6f262012-01-02 17:35:52 +0530606 {"Mono Mixer", "INPGA Right Switch", "INPGA Right"},
607 {"Mono Mixer", "INPGA Left Switch", "INPGA Left"},
Ashish Chavan52082d82011-10-21 19:06:23 +0530608 {"Mono Mixer", "Outmix Right Switch", "Out Mixer Right"},
609 {"Mono Mixer", "Outmix Left Switch", "Out Mixer Left"},
610
Ashish Chavan6950c602011-10-21 18:16:08 +0530611 {"OUTPGA Left Enable", NULL, "Out Mixer Left"},
612 {"OUTPGA Right Enable", NULL, "Out Mixer Right"},
613
Ashish Chavan52082d82011-10-21 19:06:23 +0530614 {"Out1 Left", NULL, "OUTPGA Left Enable"},
615 {"OUT1L", NULL, "Out1 Left"},
616
617 {"Out1 Right", NULL, "OUTPGA Right Enable"},
618 {"OUT1R", NULL, "Out1 Right"},
619
Ashish Chavan6950c602011-10-21 18:16:08 +0530620 {"Headphone Left", NULL, "OUTPGA Left Enable"},
621 {"HPL", NULL, "Headphone Left"},
622
623 {"Headphone Right", NULL, "OUTPGA Right Enable"},
624 {"HPR", NULL, "Headphone Right"},
Ashish Chavan52082d82011-10-21 19:06:23 +0530625
626 {"Out2 Mono", NULL, "Mono Mixer"},
627 {"OUT2", NULL, "Out2 Mono"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530628};
629
Kuninori Morimoto98615452009-12-14 13:21:56 +0900630/* Codec private data */
631struct da7210_priv {
Ashish Chavan33593b52012-03-08 19:04:56 +0530632 struct regmap *regmap;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900633};
634
Ashish Chavan33593b52012-03-08 19:04:56 +0530635static struct reg_default da7210_reg_defaults[] = {
Ashish Chavanaa0e25c2012-03-29 19:06:29 +0530636 { 0x00, 0x00 },
Ashish Chavan33593b52012-03-08 19:04:56 +0530637 { 0x01, 0x11 },
Ashish Chavan33593b52012-03-08 19:04:56 +0530638 { 0x03, 0x00 },
639 { 0x04, 0x00 },
640 { 0x05, 0x00 },
641 { 0x06, 0x00 },
642 { 0x07, 0x00 },
643 { 0x08, 0x00 },
644 { 0x09, 0x00 },
645 { 0x0a, 0x00 },
646 { 0x0b, 0x00 },
647 { 0x0c, 0x00 },
648 { 0x0d, 0x00 },
649 { 0x0e, 0x00 },
650 { 0x0f, 0x08 },
651 { 0x10, 0x00 },
652 { 0x11, 0x00 },
653 { 0x12, 0x00 },
654 { 0x13, 0x00 },
655 { 0x14, 0x08 },
656 { 0x15, 0x10 },
657 { 0x16, 0x10 },
658 { 0x17, 0x54 },
659 { 0x18, 0x40 },
660 { 0x19, 0x00 },
661 { 0x1a, 0x00 },
662 { 0x1b, 0x00 },
663 { 0x1c, 0x00 },
664 { 0x1d, 0x00 },
665 { 0x1e, 0x00 },
666 { 0x1f, 0x00 },
667 { 0x20, 0x00 },
668 { 0x21, 0x00 },
669 { 0x22, 0x00 },
670 { 0x23, 0x02 },
671 { 0x24, 0x00 },
672 { 0x25, 0x76 },
673 { 0x26, 0x00 },
674 { 0x27, 0x00 },
675 { 0x28, 0x04 },
676 { 0x29, 0x00 },
677 { 0x2a, 0x00 },
678 { 0x2b, 0x30 },
679 { 0x2c, 0x2A },
Ashish Chavan33593b52012-03-08 19:04:56 +0530680 { 0x83, 0x00 },
681 { 0x84, 0x00 },
682 { 0x85, 0x00 },
683 { 0x86, 0x00 },
684 { 0x87, 0x00 },
685 { 0x88, 0x00 },
Kuninori Morimoto98615452009-12-14 13:21:56 +0900686};
687
Ashish Chavan33593b52012-03-08 19:04:56 +0530688static bool da7210_readable_register(struct device *dev, unsigned int reg)
689{
690 switch (reg) {
691 case DA7210_A_HID_UNLOCK:
692 case DA7210_A_TEST_UNLOCK:
693 case DA7210_A_PLL1:
694 case DA7210_A_CP_MODE:
695 return false;
696 default:
697 return true;
698 }
699}
700
701static bool da7210_volatile_register(struct device *dev,
Axel Lin40a49712011-10-12 07:16:25 +0800702 unsigned int reg)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900703{
Axel Lin40a49712011-10-12 07:16:25 +0800704 switch (reg) {
705 case DA7210_STATUS:
Ashish Chavan33593b52012-03-08 19:04:56 +0530706 return true;
Axel Lin40a49712011-10-12 07:16:25 +0800707 default:
Ashish Chavan33593b52012-03-08 19:04:56 +0530708 return false;
Axel Lin40a49712011-10-12 07:16:25 +0800709 }
Kuninori Morimoto98615452009-12-14 13:21:56 +0900710}
Kuninori Morimoto98615452009-12-14 13:21:56 +0900711
712/*
713 * Set PCM DAI word length.
714 */
715static int da7210_hw_params(struct snd_pcm_substream *substream,
716 struct snd_pcm_hw_params *params,
717 struct snd_soc_dai *dai)
718{
Mark Browne6968a12012-04-04 15:58:16 +0100719 struct snd_soc_codec *codec = dai->codec;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900720 u32 dai_cfg1;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900721 u32 fs, bypass;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900722
723 /* set DAI source to Left and Right ADC */
Axel Lin40a49712011-10-12 07:16:25 +0800724 snd_soc_write(codec, DA7210_DAI_SRC_SEL,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900725 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
726
727 /* Enable DAI */
Axel Lin40a49712011-10-12 07:16:25 +0800728 snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900729
Axel Lin40a49712011-10-12 07:16:25 +0800730 dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900731
732 switch (params_format(params)) {
733 case SNDRV_PCM_FORMAT_S16_LE:
734 dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
735 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530736 case SNDRV_PCM_FORMAT_S20_3LE:
737 dai_cfg1 |= DA7210_DAI_WORD_S20_3LE;
738 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900739 case SNDRV_PCM_FORMAT_S24_LE:
740 dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
741 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530742 case SNDRV_PCM_FORMAT_S32_LE:
743 dai_cfg1 |= DA7210_DAI_WORD_S32_LE;
744 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900745 default:
746 return -EINVAL;
747 }
748
Axel Lin40a49712011-10-12 07:16:25 +0800749 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900750
Kuninori Morimoto98615452009-12-14 13:21:56 +0900751 switch (params_rate(params)) {
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900752 case 8000:
753 fs = DA7210_PLL_FS_8000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900754 bypass = DA7210_PLL_BYP;
755 break;
756 case 11025:
757 fs = DA7210_PLL_FS_11025;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900758 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900759 break;
760 case 12000:
761 fs = DA7210_PLL_FS_12000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900762 bypass = DA7210_PLL_BYP;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900763 break;
764 case 16000:
765 fs = DA7210_PLL_FS_16000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900766 bypass = DA7210_PLL_BYP;
767 break;
768 case 22050:
769 fs = DA7210_PLL_FS_22050;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900770 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900771 break;
772 case 32000:
773 fs = DA7210_PLL_FS_32000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900774 bypass = DA7210_PLL_BYP;
775 break;
776 case 44100:
777 fs = DA7210_PLL_FS_44100;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900778 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900779 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900780 case 48000:
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900781 fs = DA7210_PLL_FS_48000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900782 bypass = DA7210_PLL_BYP;
783 break;
784 case 88200:
785 fs = DA7210_PLL_FS_88200;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900786 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900787 break;
788 case 96000:
789 fs = DA7210_PLL_FS_96000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900790 bypass = DA7210_PLL_BYP;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900791 break;
792 default:
793 return -EINVAL;
794 }
795
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900796 /* Disable active mode */
797 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
798
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900799 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900800 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
801
802 /* Enable active mode */
803 snd_soc_update_bits(codec, DA7210_STARTUP1,
804 DA7210_SC_MST_EN, DA7210_SC_MST_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900805
806 return 0;
807}
808
809/*
810 * Set DAI mode and Format
811 */
812static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
813{
814 struct snd_soc_codec *codec = codec_dai->codec;
815 u32 dai_cfg1;
816 u32 dai_cfg3;
817
Axel Lin40a49712011-10-12 07:16:25 +0800818 dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
819 dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900820
821 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
822 case SND_SOC_DAIFMT_CBM_CFM:
823 dai_cfg1 |= DA7210_DAI_MODE_MASTER;
824 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530825 case SND_SOC_DAIFMT_CBS_CFS:
826 dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
827 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900828 default:
829 return -EINVAL;
830 }
831
832 /* FIXME
833 *
834 * It support I2S only now
835 */
836 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
837 case SND_SOC_DAIFMT_I2S:
838 dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
839 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530840 case SND_SOC_DAIFMT_LEFT_J:
841 dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J;
842 break;
843 case SND_SOC_DAIFMT_RIGHT_J:
844 dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J;
845 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900846 default:
847 return -EINVAL;
848 }
849
850 /* FIXME
851 *
852 * It support 64bit data transmission only now
853 */
854 dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
855
Axel Lin40a49712011-10-12 07:16:25 +0800856 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
857 snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900858
859 return 0;
860}
861
Ashish Chavan5eda1942011-10-19 14:19:06 +0530862static int da7210_mute(struct snd_soc_dai *dai, int mute)
863{
864 struct snd_soc_codec *codec = dai->codec;
865 u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB;
866
867 if (mute)
868 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4);
869 else
870 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg);
871 return 0;
872}
873
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530874#define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
875 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900876
877/* DAI operations */
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100878static const struct snd_soc_dai_ops da7210_dai_ops = {
Kuninori Morimoto98615452009-12-14 13:21:56 +0900879 .hw_params = da7210_hw_params,
880 .set_fmt = da7210_set_dai_fmt,
Ashish Chavan5eda1942011-10-19 14:19:06 +0530881 .digital_mute = da7210_mute,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900882};
883
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000884static struct snd_soc_dai_driver da7210_dai = {
885 .name = "da7210-hifi",
Kuninori Morimoto98615452009-12-14 13:21:56 +0900886 /* playback capabilities */
887 .playback = {
888 .stream_name = "Playback",
889 .channels_min = 1,
890 .channels_max = 2,
891 .rates = SNDRV_PCM_RATE_8000_96000,
892 .formats = DA7210_FORMATS,
893 },
894 /* capture capabilities */
895 .capture = {
896 .stream_name = "Capture",
897 .channels_min = 1,
898 .channels_max = 2,
899 .rates = SNDRV_PCM_RATE_8000_96000,
900 .formats = DA7210_FORMATS,
901 },
902 .ops = &da7210_dai_ops,
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900903 .symmetric_rates = 1,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900904};
Kuninori Morimoto98615452009-12-14 13:21:56 +0900905
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000906static int da7210_probe(struct snd_soc_codec *codec)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900907{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000908 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
Axel Lin40a49712011-10-12 07:16:25 +0800909 int ret;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900910
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000911 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900912
Ashish Chavan33593b52012-03-08 19:04:56 +0530913 codec->control_data = da7210->regmap;
914 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
Axel Lin40a49712011-10-12 07:16:25 +0800915 if (ret < 0) {
916 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
917 return ret;
918 }
Kuninori Morimoto98615452009-12-14 13:21:56 +0900919
920 /* FIXME
921 *
922 * This driver use fixed value here
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900923 * And below settings expects MCLK = 12.288MHz
924 *
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
Kuninori Morimoto98615452009-12-14 13:21:56 +0900930 */
931
932 /*
933 * ADC settings
934 */
935
936 /* Enable Left & Right MIC PGA and Mic Bias */
Axel Lin40a49712011-10-12 07:16:25 +0800937 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);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900939
940 /* Enable Left and Right input PGA */
Axel Lin40a49712011-10-12 07:16:25 +0800941 snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
942 snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900943
944 /* Enable Left and Right ADC */
Axel Lin40a49712011-10-12 07:16:25 +0800945 snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900946
947 /*
948 * DAC settings
949 */
950
951 /* Enable Left and Right DAC */
Axel Lin40a49712011-10-12 07:16:25 +0800952 snd_soc_write(codec, DA7210_DAC_SEL,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900953 DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
954 DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
955
956 /* Enable Left and Right out PGA */
Axel Lin40a49712011-10-12 07:16:25 +0800957 snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
958 snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900959
960 /* Enable Left and Right HeadPhone PGA */
Axel Lin40a49712011-10-12 07:16:25 +0800961 snd_soc_write(codec, DA7210_HP_CFG,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900962 DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
963 DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
964
Ashish Chavan5eda1942011-10-19 14:19:06 +0530965 /* Enable ramp mode for DAC gain update */
966 snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN);
967
Ashish Chavan52082d82011-10-21 19:06:23 +0530968 /*
969 * For DA7210 codec, there are two ways to enable/disable analog IOs
970 * and ADC/DAC,
971 * (1) Using "Enable Bit" of register associated with that IO
972 * (or ADC/DAC)
973 * e.g. Mic Left can be enabled using bit 7 of MIC_L(0x7) reg
974 *
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)
977 *
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.
986 *
987 * Overall implementation can be outlined as below,
988 *
989 * - "Enable bit" of an IO or ADC/DAC is used to enable it in probe()
990 * - "STANDBY bit" is controlled by DAPM
991 */
992
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);
998
Ashish Chavan24b6f262012-01-02 17:35:52 +0530999 /* Enable Aux1 */
1000 snd_soc_write(codec, DA7210_AUX1_L, DA7210_AUX1_L_EN);
1001 snd_soc_write(codec, DA7210_AUX1_R, DA7210_AUX1_R_EN);
1002 /* Enable Aux2 */
1003 snd_soc_write(codec, DA7210_AUX2, DA7210_AUX2_EN);
1004
Kuninori Morimoto98615452009-12-14 13:21:56 +09001005 /* Diable PLL and bypass it */
Axel Lin40a49712011-10-12 07:16:25 +08001006 snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001007
Kuninori Morimoto960b3b42010-03-11 11:37:44 +09001008 /*
1009 * If 48kHz sound came, it use bypass mode,
1010 * and when it is 44.1kHz, it use PLL.
1011 *
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
1016 */
Axel Lin40a49712011-10-12 07:16:25 +08001017 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 |
Kuninori Morimoto98615452009-12-14 13:21:56 +09001020 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
Kuninori Morimoto960b3b42010-03-11 11:37:44 +09001021 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
1022
Kuninori Morimoto98615452009-12-14 13:21:56 +09001023 /* Activate all enabled subsystem */
Axel Lin40a49712011-10-12 07:16:25 +08001024 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001025
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001026 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001027
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001028 return 0;
Kuninori Morimoto98615452009-12-14 13:21:56 +09001029}
1030
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001031static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +09001032 .probe = da7210_probe,
Mark Browna6f096f2011-10-14 20:18:49 +01001033
1034 .controls = da7210_snd_controls,
1035 .num_controls = ARRAY_SIZE(da7210_snd_controls),
Ashish Chavan6950c602011-10-21 18:16:08 +05301036
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),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001041};
1042
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301043#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1044
1045static struct reg_default da7210_regmap_i2c_patch[] = {
1046
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 },
1051
1052 /* to unlock */
1053 { DA7210_A_HID_UNLOCK, 0x8B},
1054 { DA7210_A_TEST_UNLOCK, 0xB4},
1055 { DA7210_A_PLL1, 0x01},
1056 { DA7210_A_CP_MODE, 0x7C},
1057 /* to re-lock */
1058 { DA7210_A_HID_UNLOCK, 0x00},
1059 { DA7210_A_TEST_UNLOCK, 0x00},
1060};
1061
1062static const struct regmap_config da7210_regmap_config_i2c = {
Ashish Chavan33593b52012-03-08 19:04:56 +05301063 .reg_bits = 8,
1064 .val_bits = 8,
1065
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,
1071};
1072
Mark Brown735fe4c2010-01-12 14:13:00 +00001073static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
1074 const struct i2c_device_id *id)
Kuninori Morimoto98615452009-12-14 13:21:56 +09001075{
1076 struct da7210_priv *da7210;
Kuninori Morimoto98615452009-12-14 13:21:56 +09001077 int ret;
1078
Axel Lin306bf6b2011-12-26 20:54:04 +08001079 da7210 = devm_kzalloc(&i2c->dev, sizeof(struct da7210_priv),
1080 GFP_KERNEL);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001081 if (!da7210)
1082 return -ENOMEM;
1083
Kuninori Morimoto98615452009-12-14 13:21:56 +09001084 i2c_set_clientdata(i2c, da7210);
Ashish Chavan33593b52012-03-08 19:04:56 +05301085
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301086 da7210->regmap = regmap_init_i2c(i2c, &da7210_regmap_config_i2c);
Ashish Chavan33593b52012-03-08 19:04:56 +05301087 if (IS_ERR(da7210->regmap)) {
1088 ret = PTR_ERR(da7210->regmap);
1089 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
1090 return ret;
1091 }
Kuninori Morimoto98615452009-12-14 13:21:56 +09001092
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301093 ret = regmap_register_patch(da7210->regmap, da7210_regmap_i2c_patch,
1094 ARRAY_SIZE(da7210_regmap_i2c_patch));
1095 if (ret != 0)
1096 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret);
1097
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001098 ret = snd_soc_register_codec(&i2c->dev,
1099 &soc_codec_dev_da7210, &da7210_dai, 1);
Ashish Chavan33593b52012-03-08 19:04:56 +05301100 if (ret < 0) {
1101 dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
1102 goto err_regmap;
1103 }
1104 return ret;
1105
1106err_regmap:
1107 regmap_exit(da7210->regmap);
1108
Kuninori Morimoto98615452009-12-14 13:21:56 +09001109 return ret;
1110}
1111
Mark Brown735fe4c2010-01-12 14:13:00 +00001112static int __devexit da7210_i2c_remove(struct i2c_client *client)
Kuninori Morimoto98615452009-12-14 13:21:56 +09001113{
Ashish Chavan33593b52012-03-08 19:04:56 +05301114 struct da7210_priv *da7210 = i2c_get_clientdata(client);
1115
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001116 snd_soc_unregister_codec(&client->dev);
Ashish Chavan33593b52012-03-08 19:04:56 +05301117 regmap_exit(da7210->regmap);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001118 return 0;
1119}
1120
1121static const struct i2c_device_id da7210_i2c_id[] = {
1122 { "da7210", 0 },
1123 { }
1124};
1125MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
1126
1127/* I2C codec control layer */
1128static struct i2c_driver da7210_i2c_driver = {
1129 .driver = {
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301130 .name = "da7210",
Kuninori Morimoto98615452009-12-14 13:21:56 +09001131 .owner = THIS_MODULE,
1132 },
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +09001133 .probe = da7210_i2c_probe,
1134 .remove = __devexit_p(da7210_i2c_remove),
1135 .id_table = da7210_i2c_id,
Kuninori Morimoto98615452009-12-14 13:21:56 +09001136};
1137#endif
1138
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301139#if defined(CONFIG_SPI_MASTER)
1140
1141static 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 },
1145
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 },
1150
1151 /* to set PAGE1 of SPI register space */
1152 { DA7210_PAGE_CONTROL, 0x80 },
1153 /* to unlock */
1154 { DA7210_A_HID_UNLOCK, 0x8B},
1155 { DA7210_A_TEST_UNLOCK, 0xB4},
1156 { DA7210_A_PLL1, 0x01},
1157 { DA7210_A_CP_MODE, 0x7C},
1158 /* to re-lock */
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 },
1163};
1164
1165static const struct regmap_config da7210_regmap_config_spi = {
1166 .reg_bits = 8,
1167 .val_bits = 8,
1168 .read_flag_mask = 0x01,
1169 .write_flag_mask = 0x00,
1170
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,
1176};
1177
1178static int __devinit da7210_spi_probe(struct spi_device *spi)
1179{
1180 struct da7210_priv *da7210;
1181 int ret;
1182
1183 da7210 = devm_kzalloc(&spi->dev, sizeof(struct da7210_priv),
1184 GFP_KERNEL);
1185 if (!da7210)
1186 return -ENOMEM;
1187
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);
1193 return ret;
1194 }
1195
1196 ret = regmap_register_patch(da7210->regmap, da7210_regmap_spi_patch,
1197 ARRAY_SIZE(da7210_regmap_spi_patch));
1198 if (ret != 0)
1199 dev_warn(&spi->dev, "Failed to apply regmap patch: %d\n", ret);
1200
1201 ret = snd_soc_register_codec(&spi->dev,
1202 &soc_codec_dev_da7210, &da7210_dai, 1);
1203 if (ret < 0)
1204 goto err_regmap;
1205
1206 return ret;
1207
1208err_regmap:
1209 regmap_exit(da7210->regmap);
1210
1211 return ret;
1212}
1213
1214static int __devexit da7210_spi_remove(struct spi_device *spi)
1215{
1216 struct da7210_priv *da7210 = spi_get_drvdata(spi);
1217 snd_soc_unregister_codec(&spi->dev);
1218 regmap_exit(da7210->regmap);
1219 return 0;
1220}
1221
1222static struct spi_driver da7210_spi_driver = {
1223 .driver = {
1224 .name = "da7210",
1225 .owner = THIS_MODULE,
1226 },
1227 .probe = da7210_spi_probe,
1228 .remove = __devexit_p(da7210_spi_remove)
1229};
1230#endif
1231
Kuninori Morimoto98615452009-12-14 13:21:56 +09001232static int __init da7210_modinit(void)
1233{
1234 int ret = 0;
1235#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1236 ret = i2c_add_driver(&da7210_i2c_driver);
1237#endif
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301238#if defined(CONFIG_SPI_MASTER)
1239 ret = spi_register_driver(&da7210_spi_driver);
1240 if (ret) {
1241 printk(KERN_ERR "Failed to register da7210 SPI driver: %d\n",
1242 ret);
1243 }
1244#endif
Kuninori Morimoto98615452009-12-14 13:21:56 +09001245 return ret;
1246}
1247module_init(da7210_modinit);
1248
1249static void __exit da7210_exit(void)
1250{
1251#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1252 i2c_del_driver(&da7210_i2c_driver);
1253#endif
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301254#if defined(CONFIG_SPI_MASTER)
1255 spi_unregister_driver(&da7210_spi_driver);
1256#endif
Kuninori Morimoto98615452009-12-14 13:21:56 +09001257}
1258module_exit(da7210_exit);
1259
1260MODULE_DESCRIPTION("ASoC DA7210 driver");
1261MODULE_AUTHOR("David Chen, Kuninori Morimoto");
1262MODULE_LICENSE("GPL");