blob: 8e45aa9cb7b7fc4f8ce1d9ef82f5a35e3b226c6b [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{
719 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000720 struct snd_soc_codec *codec = rtd->codec;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900721 u32 dai_cfg1;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900722 u32 fs, bypass;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900723
724 /* set DAI source to Left and Right ADC */
Axel Lin40a49712011-10-12 07:16:25 +0800725 snd_soc_write(codec, DA7210_DAI_SRC_SEL,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900726 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
727
728 /* Enable DAI */
Axel Lin40a49712011-10-12 07:16:25 +0800729 snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900730
Axel Lin40a49712011-10-12 07:16:25 +0800731 dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900732
733 switch (params_format(params)) {
734 case SNDRV_PCM_FORMAT_S16_LE:
735 dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
736 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530737 case SNDRV_PCM_FORMAT_S20_3LE:
738 dai_cfg1 |= DA7210_DAI_WORD_S20_3LE;
739 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900740 case SNDRV_PCM_FORMAT_S24_LE:
741 dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
742 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530743 case SNDRV_PCM_FORMAT_S32_LE:
744 dai_cfg1 |= DA7210_DAI_WORD_S32_LE;
745 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900746 default:
747 return -EINVAL;
748 }
749
Axel Lin40a49712011-10-12 07:16:25 +0800750 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900751
Kuninori Morimoto98615452009-12-14 13:21:56 +0900752 switch (params_rate(params)) {
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900753 case 8000:
754 fs = DA7210_PLL_FS_8000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900755 bypass = DA7210_PLL_BYP;
756 break;
757 case 11025:
758 fs = DA7210_PLL_FS_11025;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900759 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900760 break;
761 case 12000:
762 fs = DA7210_PLL_FS_12000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900763 bypass = DA7210_PLL_BYP;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900764 break;
765 case 16000:
766 fs = DA7210_PLL_FS_16000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900767 bypass = DA7210_PLL_BYP;
768 break;
769 case 22050:
770 fs = DA7210_PLL_FS_22050;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900771 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900772 break;
773 case 32000:
774 fs = DA7210_PLL_FS_32000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900775 bypass = DA7210_PLL_BYP;
776 break;
777 case 44100:
778 fs = DA7210_PLL_FS_44100;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900779 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900780 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900781 case 48000:
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900782 fs = DA7210_PLL_FS_48000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900783 bypass = DA7210_PLL_BYP;
784 break;
785 case 88200:
786 fs = DA7210_PLL_FS_88200;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900787 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900788 break;
789 case 96000:
790 fs = DA7210_PLL_FS_96000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900791 bypass = DA7210_PLL_BYP;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900792 break;
793 default:
794 return -EINVAL;
795 }
796
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900797 /* Disable active mode */
798 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
799
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900800 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900801 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
802
803 /* Enable active mode */
804 snd_soc_update_bits(codec, DA7210_STARTUP1,
805 DA7210_SC_MST_EN, DA7210_SC_MST_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900806
807 return 0;
808}
809
810/*
811 * Set DAI mode and Format
812 */
813static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
814{
815 struct snd_soc_codec *codec = codec_dai->codec;
816 u32 dai_cfg1;
817 u32 dai_cfg3;
818
Axel Lin40a49712011-10-12 07:16:25 +0800819 dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
820 dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900821
822 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
823 case SND_SOC_DAIFMT_CBM_CFM:
824 dai_cfg1 |= DA7210_DAI_MODE_MASTER;
825 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530826 case SND_SOC_DAIFMT_CBS_CFS:
827 dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
828 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900829 default:
830 return -EINVAL;
831 }
832
833 /* FIXME
834 *
835 * It support I2S only now
836 */
837 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
838 case SND_SOC_DAIFMT_I2S:
839 dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
840 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530841 case SND_SOC_DAIFMT_LEFT_J:
842 dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J;
843 break;
844 case SND_SOC_DAIFMT_RIGHT_J:
845 dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J;
846 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900847 default:
848 return -EINVAL;
849 }
850
851 /* FIXME
852 *
853 * It support 64bit data transmission only now
854 */
855 dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
856
Axel Lin40a49712011-10-12 07:16:25 +0800857 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
858 snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900859
860 return 0;
861}
862
Ashish Chavan5eda1942011-10-19 14:19:06 +0530863static int da7210_mute(struct snd_soc_dai *dai, int mute)
864{
865 struct snd_soc_codec *codec = dai->codec;
866 u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB;
867
868 if (mute)
869 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4);
870 else
871 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg);
872 return 0;
873}
874
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530875#define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
876 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900877
878/* DAI operations */
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100879static const struct snd_soc_dai_ops da7210_dai_ops = {
Kuninori Morimoto98615452009-12-14 13:21:56 +0900880 .hw_params = da7210_hw_params,
881 .set_fmt = da7210_set_dai_fmt,
Ashish Chavan5eda1942011-10-19 14:19:06 +0530882 .digital_mute = da7210_mute,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900883};
884
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000885static struct snd_soc_dai_driver da7210_dai = {
886 .name = "da7210-hifi",
Kuninori Morimoto98615452009-12-14 13:21:56 +0900887 /* playback capabilities */
888 .playback = {
889 .stream_name = "Playback",
890 .channels_min = 1,
891 .channels_max = 2,
892 .rates = SNDRV_PCM_RATE_8000_96000,
893 .formats = DA7210_FORMATS,
894 },
895 /* capture capabilities */
896 .capture = {
897 .stream_name = "Capture",
898 .channels_min = 1,
899 .channels_max = 2,
900 .rates = SNDRV_PCM_RATE_8000_96000,
901 .formats = DA7210_FORMATS,
902 },
903 .ops = &da7210_dai_ops,
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900904 .symmetric_rates = 1,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900905};
Kuninori Morimoto98615452009-12-14 13:21:56 +0900906
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000907static int da7210_probe(struct snd_soc_codec *codec)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900908{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000909 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
Axel Lin40a49712011-10-12 07:16:25 +0800910 int ret;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900911
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000912 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900913
Ashish Chavan33593b52012-03-08 19:04:56 +0530914 codec->control_data = da7210->regmap;
915 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
Axel Lin40a49712011-10-12 07:16:25 +0800916 if (ret < 0) {
917 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
918 return ret;
919 }
Kuninori Morimoto98615452009-12-14 13:21:56 +0900920
921 /* FIXME
922 *
923 * This driver use fixed value here
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900924 * And below settings expects MCLK = 12.288MHz
925 *
926 * When you select different MCLK, please check...
927 * DA7210_PLL_DIV1 val
928 * DA7210_PLL_DIV2 val
929 * DA7210_PLL_DIV3 val
930 * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
Kuninori Morimoto98615452009-12-14 13:21:56 +0900931 */
932
933 /*
934 * ADC settings
935 */
936
937 /* Enable Left & Right MIC PGA and Mic Bias */
Axel Lin40a49712011-10-12 07:16:25 +0800938 snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
939 snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900940
941 /* Enable Left and Right input PGA */
Axel Lin40a49712011-10-12 07:16:25 +0800942 snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
943 snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900944
945 /* Enable Left and Right ADC */
Axel Lin40a49712011-10-12 07:16:25 +0800946 snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900947
948 /*
949 * DAC settings
950 */
951
952 /* Enable Left and Right DAC */
Axel Lin40a49712011-10-12 07:16:25 +0800953 snd_soc_write(codec, DA7210_DAC_SEL,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900954 DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
955 DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
956
957 /* Enable Left and Right out PGA */
Axel Lin40a49712011-10-12 07:16:25 +0800958 snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
959 snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900960
961 /* Enable Left and Right HeadPhone PGA */
Axel Lin40a49712011-10-12 07:16:25 +0800962 snd_soc_write(codec, DA7210_HP_CFG,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900963 DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
964 DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
965
Ashish Chavan5eda1942011-10-19 14:19:06 +0530966 /* Enable ramp mode for DAC gain update */
967 snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN);
968
Ashish Chavan52082d82011-10-21 19:06:23 +0530969 /*
970 * For DA7210 codec, there are two ways to enable/disable analog IOs
971 * and ADC/DAC,
972 * (1) Using "Enable Bit" of register associated with that IO
973 * (or ADC/DAC)
974 * e.g. Mic Left can be enabled using bit 7 of MIC_L(0x7) reg
975 *
976 * (2) Using "Standby Bit" of STARTUP2 or STARTUP3 register
977 * e.g. Mic left can be put to STANDBY using bit 0 of STARTUP3(0x5)
978 *
979 * Out of these two methods, the one using STANDBY bits is preferred
980 * way to enable/disable individual blocks. This is because STANDBY
981 * registers are part of system controller which allows system power
982 * up/down in a controlled, pop-free manner. Also, as per application
983 * note of DA7210, STANDBY register bits are only effective if a
984 * particular IO (or ADC/DAC) is already enabled using enable/disable
985 * register bits. Keeping these things in mind, current DAPM
986 * implementation manipulates only STANDBY bits.
987 *
988 * Overall implementation can be outlined as below,
989 *
990 * - "Enable bit" of an IO or ADC/DAC is used to enable it in probe()
991 * - "STANDBY bit" is controlled by DAPM
992 */
993
994 /* Enable Line out amplifiers */
995 snd_soc_write(codec, DA7210_OUT1_L, DA7210_OUT1_L_EN);
996 snd_soc_write(codec, DA7210_OUT1_R, DA7210_OUT1_R_EN);
997 snd_soc_write(codec, DA7210_OUT2, DA7210_OUT2_EN |
998 DA7210_OUT2_OUTMIX_L | DA7210_OUT2_OUTMIX_R);
999
Ashish Chavan24b6f262012-01-02 17:35:52 +05301000 /* Enable Aux1 */
1001 snd_soc_write(codec, DA7210_AUX1_L, DA7210_AUX1_L_EN);
1002 snd_soc_write(codec, DA7210_AUX1_R, DA7210_AUX1_R_EN);
1003 /* Enable Aux2 */
1004 snd_soc_write(codec, DA7210_AUX2, DA7210_AUX2_EN);
1005
Kuninori Morimoto98615452009-12-14 13:21:56 +09001006 /* Diable PLL and bypass it */
Axel Lin40a49712011-10-12 07:16:25 +08001007 snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001008
Kuninori Morimoto960b3b42010-03-11 11:37:44 +09001009 /*
1010 * If 48kHz sound came, it use bypass mode,
1011 * and when it is 44.1kHz, it use PLL.
1012 *
1013 * This time, this driver sets PLL always ON
1014 * and controls bypass/PLL mode by switching
1015 * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
1016 * see da7210_hw_params
1017 */
Axel Lin40a49712011-10-12 07:16:25 +08001018 snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
1019 snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
1020 snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
Kuninori Morimoto98615452009-12-14 13:21:56 +09001021 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
Kuninori Morimoto960b3b42010-03-11 11:37:44 +09001022 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
1023
Kuninori Morimoto98615452009-12-14 13:21:56 +09001024 /* Activate all enabled subsystem */
Axel Lin40a49712011-10-12 07:16:25 +08001025 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001026
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001027 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001028
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001029 return 0;
Kuninori Morimoto98615452009-12-14 13:21:56 +09001030}
1031
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001032static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +09001033 .probe = da7210_probe,
Mark Browna6f096f2011-10-14 20:18:49 +01001034
1035 .controls = da7210_snd_controls,
1036 .num_controls = ARRAY_SIZE(da7210_snd_controls),
Ashish Chavan6950c602011-10-21 18:16:08 +05301037
1038 .dapm_widgets = da7210_dapm_widgets,
1039 .num_dapm_widgets = ARRAY_SIZE(da7210_dapm_widgets),
1040 .dapm_routes = da7210_audio_map,
1041 .num_dapm_routes = ARRAY_SIZE(da7210_audio_map),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001042};
1043
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301044#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1045
1046static struct reg_default da7210_regmap_i2c_patch[] = {
1047
1048 /* System controller master disable */
1049 { DA7210_STARTUP1, 0x00 },
1050 /* make sure that DA7210 use bypass mode before start up */
1051 { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP },
1052
1053 /* to unlock */
1054 { DA7210_A_HID_UNLOCK, 0x8B},
1055 { DA7210_A_TEST_UNLOCK, 0xB4},
1056 { DA7210_A_PLL1, 0x01},
1057 { DA7210_A_CP_MODE, 0x7C},
1058 /* to re-lock */
1059 { DA7210_A_HID_UNLOCK, 0x00},
1060 { DA7210_A_TEST_UNLOCK, 0x00},
1061};
1062
1063static const struct regmap_config da7210_regmap_config_i2c = {
Ashish Chavan33593b52012-03-08 19:04:56 +05301064 .reg_bits = 8,
1065 .val_bits = 8,
1066
1067 .reg_defaults = da7210_reg_defaults,
1068 .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
1069 .volatile_reg = da7210_volatile_register,
1070 .readable_reg = da7210_readable_register,
1071 .cache_type = REGCACHE_RBTREE,
1072};
1073
Mark Brown735fe4c2010-01-12 14:13:00 +00001074static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
1075 const struct i2c_device_id *id)
Kuninori Morimoto98615452009-12-14 13:21:56 +09001076{
1077 struct da7210_priv *da7210;
Kuninori Morimoto98615452009-12-14 13:21:56 +09001078 int ret;
1079
Axel Lin306bf6b2011-12-26 20:54:04 +08001080 da7210 = devm_kzalloc(&i2c->dev, sizeof(struct da7210_priv),
1081 GFP_KERNEL);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001082 if (!da7210)
1083 return -ENOMEM;
1084
Kuninori Morimoto98615452009-12-14 13:21:56 +09001085 i2c_set_clientdata(i2c, da7210);
Ashish Chavan33593b52012-03-08 19:04:56 +05301086
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301087 da7210->regmap = regmap_init_i2c(i2c, &da7210_regmap_config_i2c);
Ashish Chavan33593b52012-03-08 19:04:56 +05301088 if (IS_ERR(da7210->regmap)) {
1089 ret = PTR_ERR(da7210->regmap);
1090 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
1091 return ret;
1092 }
Kuninori Morimoto98615452009-12-14 13:21:56 +09001093
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301094 ret = regmap_register_patch(da7210->regmap, da7210_regmap_i2c_patch,
1095 ARRAY_SIZE(da7210_regmap_i2c_patch));
1096 if (ret != 0)
1097 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret);
1098
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001099 ret = snd_soc_register_codec(&i2c->dev,
1100 &soc_codec_dev_da7210, &da7210_dai, 1);
Ashish Chavan33593b52012-03-08 19:04:56 +05301101 if (ret < 0) {
1102 dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
1103 goto err_regmap;
1104 }
1105 return ret;
1106
1107err_regmap:
1108 regmap_exit(da7210->regmap);
1109
Kuninori Morimoto98615452009-12-14 13:21:56 +09001110 return ret;
1111}
1112
Mark Brown735fe4c2010-01-12 14:13:00 +00001113static int __devexit da7210_i2c_remove(struct i2c_client *client)
Kuninori Morimoto98615452009-12-14 13:21:56 +09001114{
Ashish Chavan33593b52012-03-08 19:04:56 +05301115 struct da7210_priv *da7210 = i2c_get_clientdata(client);
1116
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001117 snd_soc_unregister_codec(&client->dev);
Ashish Chavan33593b52012-03-08 19:04:56 +05301118 regmap_exit(da7210->regmap);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001119 return 0;
1120}
1121
1122static const struct i2c_device_id da7210_i2c_id[] = {
1123 { "da7210", 0 },
1124 { }
1125};
1126MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
1127
1128/* I2C codec control layer */
1129static struct i2c_driver da7210_i2c_driver = {
1130 .driver = {
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301131 .name = "da7210",
Kuninori Morimoto98615452009-12-14 13:21:56 +09001132 .owner = THIS_MODULE,
1133 },
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +09001134 .probe = da7210_i2c_probe,
1135 .remove = __devexit_p(da7210_i2c_remove),
1136 .id_table = da7210_i2c_id,
Kuninori Morimoto98615452009-12-14 13:21:56 +09001137};
1138#endif
1139
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301140#if defined(CONFIG_SPI_MASTER)
1141
1142static struct reg_default da7210_regmap_spi_patch[] = {
1143 /* Dummy read to give two pulses over nCS for SPI */
1144 { DA7210_AUX2, 0x00 },
1145 { DA7210_AUX2, 0x00 },
1146
1147 /* System controller master disable */
1148 { DA7210_STARTUP1, 0x00 },
1149 /* make sure that DA7210 use bypass mode before start up */
1150 { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP },
1151
1152 /* to set PAGE1 of SPI register space */
1153 { DA7210_PAGE_CONTROL, 0x80 },
1154 /* to unlock */
1155 { DA7210_A_HID_UNLOCK, 0x8B},
1156 { DA7210_A_TEST_UNLOCK, 0xB4},
1157 { DA7210_A_PLL1, 0x01},
1158 { DA7210_A_CP_MODE, 0x7C},
1159 /* to re-lock */
1160 { DA7210_A_HID_UNLOCK, 0x00},
1161 { DA7210_A_TEST_UNLOCK, 0x00},
1162 /* to set back PAGE0 of SPI register space */
1163 { DA7210_PAGE_CONTROL, 0x00 },
1164};
1165
1166static const struct regmap_config da7210_regmap_config_spi = {
1167 .reg_bits = 8,
1168 .val_bits = 8,
1169 .read_flag_mask = 0x01,
1170 .write_flag_mask = 0x00,
1171
1172 .reg_defaults = da7210_reg_defaults,
1173 .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
1174 .volatile_reg = da7210_volatile_register,
1175 .readable_reg = da7210_readable_register,
1176 .cache_type = REGCACHE_RBTREE,
1177};
1178
1179static int __devinit da7210_spi_probe(struct spi_device *spi)
1180{
1181 struct da7210_priv *da7210;
1182 int ret;
1183
1184 da7210 = devm_kzalloc(&spi->dev, sizeof(struct da7210_priv),
1185 GFP_KERNEL);
1186 if (!da7210)
1187 return -ENOMEM;
1188
1189 spi_set_drvdata(spi, da7210);
1190 da7210->regmap = devm_regmap_init_spi(spi, &da7210_regmap_config_spi);
1191 if (IS_ERR(da7210->regmap)) {
1192 ret = PTR_ERR(da7210->regmap);
1193 dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
1194 return ret;
1195 }
1196
1197 ret = regmap_register_patch(da7210->regmap, da7210_regmap_spi_patch,
1198 ARRAY_SIZE(da7210_regmap_spi_patch));
1199 if (ret != 0)
1200 dev_warn(&spi->dev, "Failed to apply regmap patch: %d\n", ret);
1201
1202 ret = snd_soc_register_codec(&spi->dev,
1203 &soc_codec_dev_da7210, &da7210_dai, 1);
1204 if (ret < 0)
1205 goto err_regmap;
1206
1207 return ret;
1208
1209err_regmap:
1210 regmap_exit(da7210->regmap);
1211
1212 return ret;
1213}
1214
1215static int __devexit da7210_spi_remove(struct spi_device *spi)
1216{
1217 struct da7210_priv *da7210 = spi_get_drvdata(spi);
1218 snd_soc_unregister_codec(&spi->dev);
1219 regmap_exit(da7210->regmap);
1220 return 0;
1221}
1222
1223static struct spi_driver da7210_spi_driver = {
1224 .driver = {
1225 .name = "da7210",
1226 .owner = THIS_MODULE,
1227 },
1228 .probe = da7210_spi_probe,
1229 .remove = __devexit_p(da7210_spi_remove)
1230};
1231#endif
1232
Kuninori Morimoto98615452009-12-14 13:21:56 +09001233static int __init da7210_modinit(void)
1234{
1235 int ret = 0;
1236#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1237 ret = i2c_add_driver(&da7210_i2c_driver);
1238#endif
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301239#if defined(CONFIG_SPI_MASTER)
1240 ret = spi_register_driver(&da7210_spi_driver);
1241 if (ret) {
1242 printk(KERN_ERR "Failed to register da7210 SPI driver: %d\n",
1243 ret);
1244 }
1245#endif
Kuninori Morimoto98615452009-12-14 13:21:56 +09001246 return ret;
1247}
1248module_init(da7210_modinit);
1249
1250static void __exit da7210_exit(void)
1251{
1252#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1253 i2c_del_driver(&da7210_i2c_driver);
1254#endif
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301255#if defined(CONFIG_SPI_MASTER)
1256 spi_unregister_driver(&da7210_spi_driver);
1257#endif
Kuninori Morimoto98615452009-12-14 13:21:56 +09001258}
1259module_exit(da7210_exit);
1260
1261MODULE_DESCRIPTION("ASoC DA7210 driver");
1262MODULE_AUTHOR("David Chen, Kuninori Morimoto");
1263MODULE_LICENSE("GPL");