blob: 0c23f19dfca2897e2f6401c62dc0eecc45e76fd1 [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 Chavan33593b52012-03-08 19:04:56 +053020#include <linux/regmap.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040022#include <linux/module.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090023#include <sound/pcm.h>
24#include <sound/pcm_params.h>
Liam Girdwoodce6120c2010-11-05 15:53:46 +020025#include <sound/soc.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090026#include <sound/initval.h>
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +090027#include <sound/tlv.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090028
Kuninori Morimoto98615452009-12-14 13:21:56 +090029/* DA7210 register space */
Ashish Chavande5eaf82011-10-19 14:24:37 +053030#define DA7210_CONTROL 0x01
Kuninori Morimoto98615452009-12-14 13:21:56 +090031#define DA7210_STATUS 0x02
32#define DA7210_STARTUP1 0x03
Ashish Chavan6950c602011-10-21 18:16:08 +053033#define DA7210_STARTUP2 0x04
34#define DA7210_STARTUP3 0x05
Kuninori Morimoto98615452009-12-14 13:21:56 +090035#define DA7210_MIC_L 0x07
36#define DA7210_MIC_R 0x08
Ashish Chavande5eaf82011-10-19 14:24:37 +053037#define DA7210_AUX1_L 0x09
38#define DA7210_AUX1_R 0x0A
Ashish Chavan5eda1942011-10-19 14:19:06 +053039#define DA7210_AUX2 0x0B
Ashish Chavande5eaf82011-10-19 14:24:37 +053040#define DA7210_IN_GAIN 0x0C
Kuninori Morimoto98615452009-12-14 13:21:56 +090041#define DA7210_INMIX_L 0x0D
42#define DA7210_INMIX_R 0x0E
43#define DA7210_ADC_HPF 0x0F
44#define DA7210_ADC 0x10
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +053045#define DA7210_ADC_EQ1_2 0X11
46#define DA7210_ADC_EQ3_4 0x12
47#define DA7210_ADC_EQ5 0x13
Kuninori Morimoto98615452009-12-14 13:21:56 +090048#define DA7210_DAC_HPF 0x14
49#define DA7210_DAC_L 0x15
50#define DA7210_DAC_R 0x16
51#define DA7210_DAC_SEL 0x17
Ashish Chavan5eda1942011-10-19 14:19:06 +053052#define DA7210_SOFTMUTE 0x18
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +053053#define DA7210_DAC_EQ1_2 0x19
54#define DA7210_DAC_EQ3_4 0x1A
55#define DA7210_DAC_EQ5 0x1B
Kuninori Morimoto98615452009-12-14 13:21:56 +090056#define DA7210_OUTMIX_L 0x1C
57#define DA7210_OUTMIX_R 0x1D
Ashish Chavan52082d82011-10-21 19:06:23 +053058#define DA7210_OUT1_L 0x1E
59#define DA7210_OUT1_R 0x1F
60#define DA7210_OUT2 0x20
Kuninori Morimoto98615452009-12-14 13:21:56 +090061#define DA7210_HP_L_VOL 0x21
62#define DA7210_HP_R_VOL 0x22
63#define DA7210_HP_CFG 0x23
Ashish Chavan5eda1942011-10-19 14:19:06 +053064#define DA7210_ZERO_CROSS 0x24
Kuninori Morimoto98615452009-12-14 13:21:56 +090065#define DA7210_DAI_SRC_SEL 0x25
66#define DA7210_DAI_CFG1 0x26
67#define DA7210_DAI_CFG3 0x28
Kuninori Morimoto960b3b42010-03-11 11:37:44 +090068#define DA7210_PLL_DIV1 0x29
69#define DA7210_PLL_DIV2 0x2A
Kuninori Morimoto98615452009-12-14 13:21:56 +090070#define DA7210_PLL_DIV3 0x2B
71#define DA7210_PLL 0x2C
Ashish Chavande5eaf82011-10-19 14:24:37 +053072#define DA7210_ALC_MAX 0x83
73#define DA7210_ALC_MIN 0x84
74#define DA7210_ALC_NOIS 0x85
75#define DA7210_ALC_ATT 0x86
76#define DA7210_ALC_REL 0x87
77#define DA7210_ALC_DEL 0x88
Kuninori Morimoto960b3b42010-03-11 11:37:44 +090078#define DA7210_A_HID_UNLOCK 0x8A
79#define DA7210_A_TEST_UNLOCK 0x8B
80#define DA7210_A_PLL1 0x90
81#define DA7210_A_CP_MODE 0xA7
Kuninori Morimoto98615452009-12-14 13:21:56 +090082
83/* STARTUP1 bit fields */
84#define DA7210_SC_MST_EN (1 << 0)
85
86/* MIC_L bit fields */
87#define DA7210_MICBIAS_EN (1 << 6)
88#define DA7210_MIC_L_EN (1 << 7)
89
90/* MIC_R bit fields */
91#define DA7210_MIC_R_EN (1 << 7)
92
93/* INMIX_L bit fields */
94#define DA7210_IN_L_EN (1 << 7)
95
96/* INMIX_R bit fields */
97#define DA7210_IN_R_EN (1 << 7)
98
Kuninori Morimoto98615452009-12-14 13:21:56 +090099/* ADC bit fields */
Ashish Chavande5eaf82011-10-19 14:24:37 +0530100#define DA7210_ADC_ALC_EN (1 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900101#define DA7210_ADC_L_EN (1 << 3)
102#define DA7210_ADC_R_EN (1 << 7)
103
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900104/* DAC/ADC HPF fields */
105#define DA7210_VOICE_F0_MASK (0x7 << 4)
106#define DA7210_VOICE_F0_25 (1 << 4)
107#define DA7210_VOICE_EN (1 << 7)
Mark Brownc2151432009-12-16 20:36:37 +0000108
Kuninori Morimoto98615452009-12-14 13:21:56 +0900109/* DAC_SEL bit fields */
110#define DA7210_DAC_L_SRC_DAI_L (4 << 0)
111#define DA7210_DAC_L_EN (1 << 3)
112#define DA7210_DAC_R_SRC_DAI_R (5 << 4)
113#define DA7210_DAC_R_EN (1 << 7)
114
115/* OUTMIX_L bit fields */
116#define DA7210_OUT_L_EN (1 << 7)
117
118/* OUTMIX_R bit fields */
119#define DA7210_OUT_R_EN (1 << 7)
120
121/* HP_CFG bit fields */
122#define DA7210_HP_2CAP_MODE (1 << 1)
123#define DA7210_HP_SENSE_EN (1 << 2)
124#define DA7210_HP_L_EN (1 << 3)
125#define DA7210_HP_MODE (1 << 6)
126#define DA7210_HP_R_EN (1 << 7)
127
128/* DAI_SRC_SEL bit fields */
129#define DA7210_DAI_OUT_L_SRC (6 << 0)
130#define DA7210_DAI_OUT_R_SRC (7 << 4)
131
132/* DAI_CFG1 bit fields */
133#define DA7210_DAI_WORD_S16_LE (0 << 0)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530134#define DA7210_DAI_WORD_S20_3LE (1 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900135#define DA7210_DAI_WORD_S24_LE (2 << 0)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530136#define DA7210_DAI_WORD_S32_LE (3 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900137#define DA7210_DAI_FLEN_64BIT (1 << 2)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530138#define DA7210_DAI_MODE_SLAVE (0 << 7)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900139#define DA7210_DAI_MODE_MASTER (1 << 7)
140
141/* DAI_CFG3 bit fields */
142#define DA7210_DAI_FORMAT_I2SMODE (0 << 0)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530143#define DA7210_DAI_FORMAT_LEFT_J (1 << 0)
144#define DA7210_DAI_FORMAT_RIGHT_J (2 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900145#define DA7210_DAI_OE (1 << 3)
146#define DA7210_DAI_EN (1 << 7)
147
148/*PLL_DIV3 bit fields */
149#define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
150#define DA7210_PLL_BYP (1 << 6)
151
152/* PLL bit fields */
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900153#define DA7210_PLL_FS_MASK (0xF << 0)
154#define DA7210_PLL_FS_8000 (0x1 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900155#define DA7210_PLL_FS_11025 (0x2 << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900156#define DA7210_PLL_FS_12000 (0x3 << 0)
157#define DA7210_PLL_FS_16000 (0x5 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900158#define DA7210_PLL_FS_22050 (0x6 << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900159#define DA7210_PLL_FS_24000 (0x7 << 0)
160#define DA7210_PLL_FS_32000 (0x9 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900161#define DA7210_PLL_FS_44100 (0xA << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900162#define DA7210_PLL_FS_48000 (0xB << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900163#define DA7210_PLL_FS_88200 (0xE << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900164#define DA7210_PLL_FS_96000 (0xF << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900165#define DA7210_PLL_EN (0x1 << 7)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900166
Ashish Chavan5eda1942011-10-19 14:19:06 +0530167/* SOFTMUTE bit fields */
168#define DA7210_RAMP_EN (1 << 6)
169
Ashish Chavande5eaf82011-10-19 14:24:37 +0530170/* CONTROL bit fields */
171#define DA7210_NOISE_SUP_EN (1 << 3)
172
173/* IN_GAIN bit fields */
174#define DA7210_INPGA_L_VOL (0x0F << 0)
175#define DA7210_INPGA_R_VOL (0xF0 << 0)
176
177/* ZERO_CROSS bit fields */
178#define DA7210_AUX1_L_ZC (1 << 0)
179#define DA7210_AUX1_R_ZC (1 << 1)
180#define DA7210_HP_L_ZC (1 << 6)
181#define DA7210_HP_R_ZC (1 << 7)
182
183/* AUX1_L bit fields */
184#define DA7210_AUX1_L_VOL (0x3F << 0)
Ashish Chavan24b6f262012-01-02 17:35:52 +0530185#define DA7210_AUX1_L_EN (1 << 7)
Ashish Chavande5eaf82011-10-19 14:24:37 +0530186
187/* AUX1_R bit fields */
188#define DA7210_AUX1_R_VOL (0x3F << 0)
Ashish Chavan24b6f262012-01-02 17:35:52 +0530189#define DA7210_AUX1_R_EN (1 << 7)
190
191/* AUX2 bit fields */
192#define DA7210_AUX2_EN (1 << 3)
Ashish Chavande5eaf82011-10-19 14:24:37 +0530193
194/* Minimum INPGA and AUX1 volume to enable noise suppression */
195#define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */
196#define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */
197
Ashish Chavan52082d82011-10-21 19:06:23 +0530198/* OUT1_L bit fields */
199#define DA7210_OUT1_L_EN (1 << 7)
200
201/* OUT1_R bit fields */
202#define DA7210_OUT1_R_EN (1 << 7)
203
204/* OUT2 bit fields */
205#define DA7210_OUT2_OUTMIX_R (1 << 5)
206#define DA7210_OUT2_OUTMIX_L (1 << 6)
207#define DA7210_OUT2_EN (1 << 7)
208
Kuninori Morimoto98615452009-12-14 13:21:56 +0900209#define DA7210_VERSION "0.0.1"
210
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900211/*
212 * Playback Volume
213 *
214 * max : 0x3F (+15.0 dB)
215 * (1.5 dB step)
216 * min : 0x11 (-54.0 dB)
217 * mute : 0x10
218 * reserved : 0x00 - 0x0F
219 *
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900220 * Reserved area are considered as "mute".
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900221 */
Ashish Chavan7a0e67b2011-10-14 16:25:25 +0530222static const unsigned int hp_out_tlv[] = {
223 TLV_DB_RANGE_HEAD(2),
224 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
225 /* -54 dB to +15 dB */
226 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0),
227};
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900228
Ashish Chavan52082d82011-10-21 19:06:23 +0530229static const unsigned int lineout_vol_tlv[] = {
230 TLV_DB_RANGE_HEAD(2),
231 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
232 /* -54dB to 15dB */
233 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0)
234};
235
236static const unsigned int mono_vol_tlv[] = {
237 TLV_DB_RANGE_HEAD(2),
238 0x0, 0x2, TLV_DB_SCALE_ITEM(-1800, 0, 1),
239 /* -18dB to 6dB */
240 0x3, 0x7, TLV_DB_SCALE_ITEM(-1800, 600, 0)
241};
242
Ashish Chavan24b6f262012-01-02 17:35:52 +0530243static const unsigned int aux1_vol_tlv[] = {
244 TLV_DB_RANGE_HEAD(2),
245 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
246 /* -48dB to 21dB */
247 0x11, 0x3f, TLV_DB_SCALE_ITEM(-4800, 150, 0)
248};
249
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530250static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
251static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1);
Ashish Chavan52082d82011-10-21 19:06:23 +0530252static const DECLARE_TLV_DB_SCALE(dac_gain_tlv, -7725, 75, 0);
Ashish Chavan24b6f262012-01-02 17:35:52 +0530253static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, -600, 600, 0);
254static const DECLARE_TLV_DB_SCALE(aux2_vol_tlv, -600, 600, 0);
255static const DECLARE_TLV_DB_SCALE(inpga_gain_tlv, -450, 150, 0);
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530256
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530257/* ADC and DAC high pass filter f0 value */
Mark Brownf4034142011-11-09 23:15:26 +0000258static const char * const da7210_hpf_cutoff_txt[] = {
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530259 "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi"
260};
261
262static const struct soc_enum da7210_dac_hpf_cutoff =
263 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt);
264
265static const struct soc_enum da7210_adc_hpf_cutoff =
266 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt);
267
268/* ADC and DAC voice (8kHz) high pass cutoff value */
Mark Brownf4034142011-11-09 23:15:26 +0000269static const char * const da7210_vf_cutoff_txt[] = {
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530270 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
271};
272
273static const struct soc_enum da7210_dac_vf_cutoff =
274 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt);
275
276static const struct soc_enum da7210_adc_vf_cutoff =
277 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt);
278
Ashish Chavan5eda1942011-10-19 14:19:06 +0530279static const char *da7210_hp_mode_txt[] = {
280 "Class H", "Class G"
281};
282
283static const struct soc_enum da7210_hp_mode_sel =
284 SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt);
285
Ashish Chavande5eaf82011-10-19 14:24:37 +0530286/* ALC can be enabled only if noise suppression is disabled */
287static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol,
288 struct snd_ctl_elem_value *ucontrol)
289{
290 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
291
292 if (ucontrol->value.integer.value[0]) {
293 /* Check if noise suppression is enabled */
294 if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) {
295 dev_dbg(codec->dev,
296 "Disable noise suppression to enable ALC\n");
297 return -EINVAL;
298 }
299 }
300 /* If all conditions are met or we are actually disabling ALC */
301 return snd_soc_put_volsw(kcontrol, ucontrol);
302}
303
304/* Noise suppression can be enabled only if following conditions are met
305 * ALC disabled
306 * ZC enabled for HP and AUX1 PGA
307 * INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB
308 * AUX1_L_VOL and AUX1_R_VOL >= 6 dB
309 */
310static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol,
311 struct snd_ctl_elem_value *ucontrol)
312{
313 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
314 u8 val;
315
316 if (ucontrol->value.integer.value[0]) {
317 /* Check if ALC is enabled */
318 if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN)
319 goto err;
320
321 /* Check ZC for HP and AUX1 PGA */
322 if ((snd_soc_read(codec, DA7210_ZERO_CROSS) &
323 (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC |
324 DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC |
325 DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC))
326 goto err;
327
328 /* Check INPGA_L_VOL and INPGA_R_VOL */
329 val = snd_soc_read(codec, DA7210_IN_GAIN);
330 if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) ||
331 (((val & DA7210_INPGA_R_VOL) >> 4) <
332 DA7210_INPGA_MIN_VOL_NS))
333 goto err;
334
335 /* Check AUX1_L_VOL and AUX1_R_VOL */
336 if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) <
337 DA7210_AUX1_MIN_VOL_NS) ||
338 ((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) <
339 DA7210_AUX1_MIN_VOL_NS))
340 goto err;
341 }
342 /* If all conditions are met or we are actually disabling Noise sup */
343 return snd_soc_put_volsw(kcontrol, ucontrol);
344
345err:
346 return -EINVAL;
347}
348
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900349static const struct snd_kcontrol_new da7210_snd_controls[] = {
350
351 SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
352 DA7210_HP_L_VOL, DA7210_HP_R_VOL,
353 0, 0x3F, 0, hp_out_tlv),
Ashish Chavan52082d82011-10-21 19:06:23 +0530354 SOC_DOUBLE_R_TLV("Digital Playback Volume",
355 DA7210_DAC_L, DA7210_DAC_R,
356 0, 0x77, 1, dac_gain_tlv),
357 SOC_DOUBLE_R_TLV("Lineout Playback Volume",
358 DA7210_OUT1_L, DA7210_OUT1_R,
359 0, 0x3f, 0, lineout_vol_tlv),
360 SOC_SINGLE_TLV("Mono Playback Volume", DA7210_OUT2, 0, 0x7, 0,
361 mono_vol_tlv),
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530362
Ashish Chavan24b6f262012-01-02 17:35:52 +0530363 SOC_DOUBLE_R_TLV("Mic Capture Volume",
364 DA7210_MIC_L, DA7210_MIC_R,
365 0, 0x5, 0, mic_vol_tlv),
366 SOC_DOUBLE_R_TLV("Aux1 Capture Volume",
367 DA7210_AUX1_L, DA7210_AUX1_R,
368 0, 0x3f, 0, aux1_vol_tlv),
369 SOC_SINGLE_TLV("Aux2 Capture Volume", DA7210_AUX2, 0, 0x3, 0,
370 aux2_vol_tlv),
371 SOC_DOUBLE_TLV("In PGA Capture Volume", DA7210_IN_GAIN, 0, 4, 0xF, 0,
372 inpga_gain_tlv),
373
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530374 /* DAC Equalizer controls */
375 SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0),
376 SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1,
377 eq_gain_tlv),
378 SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1,
379 eq_gain_tlv),
380 SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1,
381 eq_gain_tlv),
382 SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1,
383 eq_gain_tlv),
384 SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1,
385 eq_gain_tlv),
386
387 /* ADC Equalizer controls */
388 SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0),
389 SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3,
390 1, adc_eq_master_gain_tlv),
391 SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1,
392 eq_gain_tlv),
393 SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1,
394 eq_gain_tlv),
395 SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1,
396 eq_gain_tlv),
397 SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1,
398 eq_gain_tlv),
399 SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1,
400 eq_gain_tlv),
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530401
402 SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0),
403 SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff),
404 SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0),
405 SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff),
406
407 SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0),
408 SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff),
409 SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0),
410 SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff),
Ashish Chavan5eda1942011-10-19 14:19:06 +0530411
412 /* Mute controls */
413 SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0),
414 SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0),
415 SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0),
416 SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0),
417 SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0),
418
419 /* Zero cross controls */
420 SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0),
421 SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0),
422 SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0),
423 SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0),
424
425 SOC_ENUM("Headphone Class", da7210_hp_mode_sel),
Ashish Chavande5eaf82011-10-19 14:24:37 +0530426
427 /* ALC controls */
428 SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0,
429 snd_soc_get_volsw, da7210_put_alc_sw),
430 SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0),
431 SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0),
432 SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0),
433 SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0),
434 SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0),
435 SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0),
436
437 SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1,
438 0, snd_soc_get_volsw, da7210_put_noise_sup_sw),
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900439};
440
Ashish Chavan6950c602011-10-21 18:16:08 +0530441/*
442 * DAPM Controls
443 *
444 * Current DAPM implementation covers almost all codec components e.g. IOs,
445 * mixers, PGAs,ADC and DAC.
446 */
447/* In Mixer Left */
448static const struct snd_kcontrol_new da7210_dapm_inmixl_controls[] = {
449 SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_L, 0, 1, 0),
450 SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_L, 1, 1, 0),
Ashish Chavan24b6f262012-01-02 17:35:52 +0530451 SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_INMIX_L, 2, 1, 0),
452 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_L, 3, 1, 0),
453 SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_INMIX_L, 4, 1, 0),
Ashish Chavan6950c602011-10-21 18:16:08 +0530454};
455
456/* In Mixer Right */
457static const struct snd_kcontrol_new da7210_dapm_inmixr_controls[] = {
458 SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_R, 0, 1, 0),
459 SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_R, 1, 1, 0),
Ashish Chavan24b6f262012-01-02 17:35:52 +0530460 SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_INMIX_R, 2, 1, 0),
461 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_R, 3, 1, 0),
462 SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_INMIX_R, 4, 1, 0),
Ashish Chavan6950c602011-10-21 18:16:08 +0530463};
464
465/* Out Mixer Left */
466static const struct snd_kcontrol_new da7210_dapm_outmixl_controls[] = {
Ashish Chavan24b6f262012-01-02 17:35:52 +0530467 SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_OUTMIX_L, 0, 1, 0),
468 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_L, 1, 1, 0),
469 SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_L, 2, 1, 0),
470 SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_L, 3, 1, 0),
Ashish Chavan6950c602011-10-21 18:16:08 +0530471 SOC_DAPM_SINGLE("DAC Left Switch", DA7210_OUTMIX_L, 4, 1, 0),
472};
473
474/* Out Mixer Right */
475static const struct snd_kcontrol_new da7210_dapm_outmixr_controls[] = {
Ashish Chavan24b6f262012-01-02 17:35:52 +0530476 SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_OUTMIX_R, 0, 1, 0),
477 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_R, 1, 1, 0),
478 SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_R, 2, 1, 0),
479 SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_R, 3, 1, 0),
Ashish Chavan6950c602011-10-21 18:16:08 +0530480 SOC_DAPM_SINGLE("DAC Right Switch", DA7210_OUTMIX_R, 4, 1, 0),
481};
482
Ashish Chavan52082d82011-10-21 19:06:23 +0530483/* Mono Mixer */
484static const struct snd_kcontrol_new da7210_dapm_monomix_controls[] = {
Ashish Chavan24b6f262012-01-02 17:35:52 +0530485 SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUT2, 3, 1, 0),
486 SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUT2, 4, 1, 0),
Ashish Chavan52082d82011-10-21 19:06:23 +0530487 SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_OUT2, 5, 1, 0),
488 SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_OUT2, 6, 1, 0),
489};
490
Ashish Chavan6950c602011-10-21 18:16:08 +0530491/* DAPM widgets */
492static const struct snd_soc_dapm_widget da7210_dapm_widgets[] = {
493 /* Input Side */
494 /* Input Lines */
495 SND_SOC_DAPM_INPUT("MICL"),
496 SND_SOC_DAPM_INPUT("MICR"),
Ashish Chavan24b6f262012-01-02 17:35:52 +0530497 SND_SOC_DAPM_INPUT("AUX1L"),
498 SND_SOC_DAPM_INPUT("AUX1R"),
499 SND_SOC_DAPM_INPUT("AUX2"),
Ashish Chavan6950c602011-10-21 18:16:08 +0530500
501 /* Input PGAs */
502 SND_SOC_DAPM_PGA("Mic Left", DA7210_STARTUP3, 0, 1, NULL, 0),
503 SND_SOC_DAPM_PGA("Mic Right", DA7210_STARTUP3, 1, 1, NULL, 0),
Ashish Chavan24b6f262012-01-02 17:35:52 +0530504 SND_SOC_DAPM_PGA("Aux1 Left", DA7210_STARTUP3, 2, 1, NULL, 0),
505 SND_SOC_DAPM_PGA("Aux1 Right", DA7210_STARTUP3, 3, 1, NULL, 0),
506 SND_SOC_DAPM_PGA("Aux2 Mono", DA7210_STARTUP3, 4, 1, NULL, 0),
Ashish Chavan6950c602011-10-21 18:16:08 +0530507
508 SND_SOC_DAPM_PGA("INPGA Left", DA7210_INMIX_L, 7, 0, NULL, 0),
509 SND_SOC_DAPM_PGA("INPGA Right", DA7210_INMIX_R, 7, 0, NULL, 0),
510
Ashish Chavan24b6f262012-01-02 17:35:52 +0530511 /* MICBIAS */
512 SND_SOC_DAPM_SUPPLY("Mic Bias", DA7210_MIC_L, 6, 0, NULL, 0),
513
Ashish Chavan6950c602011-10-21 18:16:08 +0530514 /* Input Mixers */
515 SND_SOC_DAPM_MIXER("In Mixer Left", SND_SOC_NOPM, 0, 0,
516 &da7210_dapm_inmixl_controls[0],
517 ARRAY_SIZE(da7210_dapm_inmixl_controls)),
518
519 SND_SOC_DAPM_MIXER("In Mixer Right", SND_SOC_NOPM, 0, 0,
520 &da7210_dapm_inmixr_controls[0],
521 ARRAY_SIZE(da7210_dapm_inmixr_controls)),
522
523 /* ADCs */
524 SND_SOC_DAPM_ADC("ADC Left", "Capture", DA7210_STARTUP3, 5, 1),
525 SND_SOC_DAPM_ADC("ADC Right", "Capture", DA7210_STARTUP3, 6, 1),
526
527 /* Output Side */
528 /* DACs */
529 SND_SOC_DAPM_DAC("DAC Left", "Playback", DA7210_STARTUP2, 5, 1),
530 SND_SOC_DAPM_DAC("DAC Right", "Playback", DA7210_STARTUP2, 6, 1),
531
532 /* Output Mixers */
533 SND_SOC_DAPM_MIXER("Out Mixer Left", SND_SOC_NOPM, 0, 0,
534 &da7210_dapm_outmixl_controls[0],
535 ARRAY_SIZE(da7210_dapm_outmixl_controls)),
536
537 SND_SOC_DAPM_MIXER("Out Mixer Right", SND_SOC_NOPM, 0, 0,
538 &da7210_dapm_outmixr_controls[0],
539 ARRAY_SIZE(da7210_dapm_outmixr_controls)),
540
Ashish Chavan52082d82011-10-21 19:06:23 +0530541 SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0,
542 &da7210_dapm_monomix_controls[0],
543 ARRAY_SIZE(da7210_dapm_monomix_controls)),
544
Ashish Chavan6950c602011-10-21 18:16:08 +0530545 /* Output PGAs */
546 SND_SOC_DAPM_PGA("OUTPGA Left Enable", DA7210_OUTMIX_L, 7, 0, NULL, 0),
547 SND_SOC_DAPM_PGA("OUTPGA Right Enable", DA7210_OUTMIX_R, 7, 0, NULL, 0),
548
Ashish Chavan52082d82011-10-21 19:06:23 +0530549 SND_SOC_DAPM_PGA("Out1 Left", DA7210_STARTUP2, 0, 1, NULL, 0),
550 SND_SOC_DAPM_PGA("Out1 Right", DA7210_STARTUP2, 1, 1, NULL, 0),
551 SND_SOC_DAPM_PGA("Out2 Mono", DA7210_STARTUP2, 2, 1, NULL, 0),
Ashish Chavan6950c602011-10-21 18:16:08 +0530552 SND_SOC_DAPM_PGA("Headphone Left", DA7210_STARTUP2, 3, 1, NULL, 0),
553 SND_SOC_DAPM_PGA("Headphone Right", DA7210_STARTUP2, 4, 1, NULL, 0),
554
555 /* Output Lines */
Ashish Chavan52082d82011-10-21 19:06:23 +0530556 SND_SOC_DAPM_OUTPUT("OUT1L"),
557 SND_SOC_DAPM_OUTPUT("OUT1R"),
Ashish Chavan6950c602011-10-21 18:16:08 +0530558 SND_SOC_DAPM_OUTPUT("HPL"),
559 SND_SOC_DAPM_OUTPUT("HPR"),
Ashish Chavan52082d82011-10-21 19:06:23 +0530560 SND_SOC_DAPM_OUTPUT("OUT2"),
Ashish Chavan6950c602011-10-21 18:16:08 +0530561};
562
563/* DAPM audio route definition */
564static const struct snd_soc_dapm_route da7210_audio_map[] = {
565 /* Dest Connecting Widget source */
566 /* Input path */
567 {"Mic Left", NULL, "MICL"},
568 {"Mic Right", NULL, "MICR"},
Ashish Chavan24b6f262012-01-02 17:35:52 +0530569 {"Aux1 Left", NULL, "AUX1L"},
570 {"Aux1 Right", NULL, "AUX1R"},
571 {"Aux2 Mono", NULL, "AUX2"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530572
573 {"In Mixer Left", "Mic Left Switch", "Mic Left"},
574 {"In Mixer Left", "Mic Right Switch", "Mic Right"},
Ashish Chavan24b6f262012-01-02 17:35:52 +0530575 {"In Mixer Left", "Aux1 Left Switch", "Aux1 Left"},
576 {"In Mixer Left", "Aux2 Switch", "Aux2 Mono"},
577 {"In Mixer Left", "Outmix Left Switch", "Out Mixer Left"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530578
579 {"In Mixer Right", "Mic Right Switch", "Mic Right"},
580 {"In Mixer Right", "Mic Left Switch", "Mic Left"},
Ashish Chavan24b6f262012-01-02 17:35:52 +0530581 {"In Mixer Right", "Aux1 Right Switch", "Aux1 Right"},
582 {"In Mixer Right", "Aux2 Switch", "Aux2 Mono"},
583 {"In Mixer Right", "Outmix Right Switch", "Out Mixer Right"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530584
585 {"INPGA Left", NULL, "In Mixer Left"},
586 {"ADC Left", NULL, "INPGA Left"},
587
588 {"INPGA Right", NULL, "In Mixer Right"},
589 {"ADC Right", NULL, "INPGA Right"},
590
591 /* Output path */
Ashish Chavan24b6f262012-01-02 17:35:52 +0530592 {"Out Mixer Left", "Aux1 Left Switch", "Aux1 Left"},
593 {"Out Mixer Left", "Aux2 Switch", "Aux2 Mono"},
594 {"Out Mixer Left", "INPGA Left Switch", "INPGA Left"},
595 {"Out Mixer Left", "INPGA Right Switch", "INPGA Right"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530596 {"Out Mixer Left", "DAC Left Switch", "DAC Left"},
Ashish Chavan24b6f262012-01-02 17:35:52 +0530597
598 {"Out Mixer Right", "Aux1 Right Switch", "Aux1 Right"},
599 {"Out Mixer Right", "Aux2 Switch", "Aux2 Mono"},
600 {"Out Mixer Right", "INPGA Right Switch", "INPGA Right"},
601 {"Out Mixer Right", "INPGA Left Switch", "INPGA Left"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530602 {"Out Mixer Right", "DAC Right Switch", "DAC Right"},
603
Ashish Chavan24b6f262012-01-02 17:35:52 +0530604 {"Mono Mixer", "INPGA Right Switch", "INPGA Right"},
605 {"Mono Mixer", "INPGA Left Switch", "INPGA Left"},
Ashish Chavan52082d82011-10-21 19:06:23 +0530606 {"Mono Mixer", "Outmix Right Switch", "Out Mixer Right"},
607 {"Mono Mixer", "Outmix Left Switch", "Out Mixer Left"},
608
Ashish Chavan6950c602011-10-21 18:16:08 +0530609 {"OUTPGA Left Enable", NULL, "Out Mixer Left"},
610 {"OUTPGA Right Enable", NULL, "Out Mixer Right"},
611
Ashish Chavan52082d82011-10-21 19:06:23 +0530612 {"Out1 Left", NULL, "OUTPGA Left Enable"},
613 {"OUT1L", NULL, "Out1 Left"},
614
615 {"Out1 Right", NULL, "OUTPGA Right Enable"},
616 {"OUT1R", NULL, "Out1 Right"},
617
Ashish Chavan6950c602011-10-21 18:16:08 +0530618 {"Headphone Left", NULL, "OUTPGA Left Enable"},
619 {"HPL", NULL, "Headphone Left"},
620
621 {"Headphone Right", NULL, "OUTPGA Right Enable"},
622 {"HPR", NULL, "Headphone Right"},
Ashish Chavan52082d82011-10-21 19:06:23 +0530623
624 {"Out2 Mono", NULL, "Mono Mixer"},
625 {"OUT2", NULL, "Out2 Mono"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530626};
627
Kuninori Morimoto98615452009-12-14 13:21:56 +0900628/* Codec private data */
629struct da7210_priv {
Ashish Chavan33593b52012-03-08 19:04:56 +0530630 struct regmap *regmap;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900631};
632
Ashish Chavan33593b52012-03-08 19:04:56 +0530633static struct reg_default da7210_reg_defaults[] = {
634 { 0x00, 0x00 },
635 { 0x01, 0x11 },
636 { 0x02, 0x00 },
637 { 0x03, 0x00 },
638 { 0x04, 0x00 },
639 { 0x05, 0x00 },
640 { 0x06, 0x00 },
641 { 0x07, 0x00 },
642 { 0x08, 0x00 },
643 { 0x09, 0x00 },
644 { 0x0a, 0x00 },
645 { 0x0b, 0x00 },
646 { 0x0c, 0x00 },
647 { 0x0d, 0x00 },
648 { 0x0e, 0x00 },
649 { 0x0f, 0x08 },
650 { 0x10, 0x00 },
651 { 0x11, 0x00 },
652 { 0x12, 0x00 },
653 { 0x13, 0x00 },
654 { 0x14, 0x08 },
655 { 0x15, 0x10 },
656 { 0x16, 0x10 },
657 { 0x17, 0x54 },
658 { 0x18, 0x40 },
659 { 0x19, 0x00 },
660 { 0x1a, 0x00 },
661 { 0x1b, 0x00 },
662 { 0x1c, 0x00 },
663 { 0x1d, 0x00 },
664 { 0x1e, 0x00 },
665 { 0x1f, 0x00 },
666 { 0x20, 0x00 },
667 { 0x21, 0x00 },
668 { 0x22, 0x00 },
669 { 0x23, 0x02 },
670 { 0x24, 0x00 },
671 { 0x25, 0x76 },
672 { 0x26, 0x00 },
673 { 0x27, 0x00 },
674 { 0x28, 0x04 },
675 { 0x29, 0x00 },
676 { 0x2a, 0x00 },
677 { 0x2b, 0x30 },
678 { 0x2c, 0x2A },
679 { 0x2d, 0x00 },
680 { 0x2e, 0x40 },
681 { 0x2f, 0x00 },
682 { 0x30, 0x40 },
683 { 0x31, 0x00 },
684 { 0x32, 0x40 },
685 { 0x33, 0x00 },
686 { 0x34, 0x40 },
687 { 0x35, 0x00 },
688 { 0x36, 0x40 },
689 { 0x37, 0x00 },
690 { 0x38, 0x40 },
691 { 0x39, 0x00 },
692 { 0x3a, 0x40 },
693 { 0x3b, 0x00 },
694 { 0x3c, 0x40 },
695 { 0x3d, 0x00 },
696 { 0x3e, 0x00 },
697 { 0x3f, 0x00 },
698 { 0x40, 0x00 },
699 { 0x41, 0x00 },
700 { 0x42, 0x00 },
701 { 0x43, 0x00 },
702 { 0x44, 0x00 },
703 { 0x45, 0x00 },
704 { 0x46, 0x00 },
705 { 0x47, 0x00 },
706 { 0x48, 0x00 },
707 { 0x49, 0x00 },
708 { 0x4a, 0x00 },
709 { 0x4b, 0x00 },
710 { 0x4c, 0x00 },
711 { 0x4d, 0x00 },
712 { 0x4e, 0x00 },
713 { 0x4f, 0x00 },
714 { 0x50, 0x00 },
715 { 0x51, 0x00 },
716 { 0x52, 0x00 },
717 { 0x53, 0x00 },
718 { 0x54, 0x00 },
719 { 0x55, 0x00 },
720 { 0x56, 0x00 },
721 { 0x57, 0x00 },
722 { 0x58, 0x00 },
723 { 0x59, 0x00 },
724 { 0x5a, 0x00 },
725 { 0x5b, 0x00 },
726 { 0x5c, 0x00 },
727 { 0x5d, 0x00 },
728 { 0x5e, 0x00 },
729 { 0x5f, 0x00 },
730 { 0x60, 0x00 },
731 { 0x61, 0x00 },
732 { 0x62, 0x00 },
733 { 0x63, 0x00 },
734 { 0x64, 0x00 },
735 { 0x65, 0x00 },
736 { 0x66, 0x00 },
737 { 0x67, 0x00 },
738 { 0x68, 0x00 },
739 { 0x69, 0x00 },
740 { 0x6a, 0x00 },
741 { 0x6b, 0x00 },
742 { 0x6c, 0x00 },
743 { 0x6d, 0x00 },
744 { 0x6e, 0x00 },
745 { 0x6f, 0x00 },
746 { 0x70, 0x00 },
747 { 0x71, 0x00 },
748 { 0x72, 0x00 },
749 { 0x73, 0x00 },
750 { 0x74, 0x00 },
751 { 0x75, 0x00 },
752 { 0x76, 0x00 },
753 { 0x77, 0x00 },
754 { 0x78, 0x00 },
755 { 0x79, 0x00 },
756 { 0x7a, 0x00 },
757 { 0x7b, 0x00 },
758 { 0x7c, 0x00 },
759 { 0x7d, 0x54 },
760 { 0x7e, 0x54 },
761 { 0x7f, 0x00 },
762 { 0x80, 0x00 },
763 { 0x81, 0x00 },
764 { 0x82, 0x2c },
765 { 0x83, 0x00 },
766 { 0x84, 0x00 },
767 { 0x85, 0x00 },
768 { 0x86, 0x00 },
769 { 0x87, 0x00 },
770 { 0x88, 0x00 },
Kuninori Morimoto98615452009-12-14 13:21:56 +0900771};
772
Ashish Chavan33593b52012-03-08 19:04:56 +0530773static bool da7210_readable_register(struct device *dev, unsigned int reg)
774{
775 switch (reg) {
776 case DA7210_A_HID_UNLOCK:
777 case DA7210_A_TEST_UNLOCK:
778 case DA7210_A_PLL1:
779 case DA7210_A_CP_MODE:
780 return false;
781 default:
782 return true;
783 }
784}
785
786static bool da7210_volatile_register(struct device *dev,
Axel Lin40a49712011-10-12 07:16:25 +0800787 unsigned int reg)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900788{
Axel Lin40a49712011-10-12 07:16:25 +0800789 switch (reg) {
790 case DA7210_STATUS:
Ashish Chavan33593b52012-03-08 19:04:56 +0530791 return true;
Axel Lin40a49712011-10-12 07:16:25 +0800792 default:
Ashish Chavan33593b52012-03-08 19:04:56 +0530793 return false;
Axel Lin40a49712011-10-12 07:16:25 +0800794 }
Kuninori Morimoto98615452009-12-14 13:21:56 +0900795}
Kuninori Morimoto98615452009-12-14 13:21:56 +0900796
797/*
798 * Set PCM DAI word length.
799 */
800static int da7210_hw_params(struct snd_pcm_substream *substream,
801 struct snd_pcm_hw_params *params,
802 struct snd_soc_dai *dai)
803{
804 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000805 struct snd_soc_codec *codec = rtd->codec;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900806 u32 dai_cfg1;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900807 u32 fs, bypass;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900808
809 /* set DAI source to Left and Right ADC */
Axel Lin40a49712011-10-12 07:16:25 +0800810 snd_soc_write(codec, DA7210_DAI_SRC_SEL,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900811 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
812
813 /* Enable DAI */
Axel Lin40a49712011-10-12 07:16:25 +0800814 snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900815
Axel Lin40a49712011-10-12 07:16:25 +0800816 dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900817
818 switch (params_format(params)) {
819 case SNDRV_PCM_FORMAT_S16_LE:
820 dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
821 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530822 case SNDRV_PCM_FORMAT_S20_3LE:
823 dai_cfg1 |= DA7210_DAI_WORD_S20_3LE;
824 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900825 case SNDRV_PCM_FORMAT_S24_LE:
826 dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
827 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530828 case SNDRV_PCM_FORMAT_S32_LE:
829 dai_cfg1 |= DA7210_DAI_WORD_S32_LE;
830 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900831 default:
832 return -EINVAL;
833 }
834
Axel Lin40a49712011-10-12 07:16:25 +0800835 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900836
Kuninori Morimoto98615452009-12-14 13:21:56 +0900837 switch (params_rate(params)) {
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900838 case 8000:
839 fs = DA7210_PLL_FS_8000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900840 bypass = DA7210_PLL_BYP;
841 break;
842 case 11025:
843 fs = DA7210_PLL_FS_11025;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900844 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900845 break;
846 case 12000:
847 fs = DA7210_PLL_FS_12000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900848 bypass = DA7210_PLL_BYP;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900849 break;
850 case 16000:
851 fs = DA7210_PLL_FS_16000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900852 bypass = DA7210_PLL_BYP;
853 break;
854 case 22050:
855 fs = DA7210_PLL_FS_22050;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900856 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900857 break;
858 case 32000:
859 fs = DA7210_PLL_FS_32000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900860 bypass = DA7210_PLL_BYP;
861 break;
862 case 44100:
863 fs = DA7210_PLL_FS_44100;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900864 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900865 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900866 case 48000:
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900867 fs = DA7210_PLL_FS_48000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900868 bypass = DA7210_PLL_BYP;
869 break;
870 case 88200:
871 fs = DA7210_PLL_FS_88200;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900872 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900873 break;
874 case 96000:
875 fs = DA7210_PLL_FS_96000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900876 bypass = DA7210_PLL_BYP;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900877 break;
878 default:
879 return -EINVAL;
880 }
881
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900882 /* Disable active mode */
883 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
884
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900885 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900886 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
887
888 /* Enable active mode */
889 snd_soc_update_bits(codec, DA7210_STARTUP1,
890 DA7210_SC_MST_EN, DA7210_SC_MST_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900891
892 return 0;
893}
894
895/*
896 * Set DAI mode and Format
897 */
898static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
899{
900 struct snd_soc_codec *codec = codec_dai->codec;
901 u32 dai_cfg1;
902 u32 dai_cfg3;
903
Axel Lin40a49712011-10-12 07:16:25 +0800904 dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
905 dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900906
907 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
908 case SND_SOC_DAIFMT_CBM_CFM:
909 dai_cfg1 |= DA7210_DAI_MODE_MASTER;
910 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530911 case SND_SOC_DAIFMT_CBS_CFS:
912 dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
913 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900914 default:
915 return -EINVAL;
916 }
917
918 /* FIXME
919 *
920 * It support I2S only now
921 */
922 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
923 case SND_SOC_DAIFMT_I2S:
924 dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
925 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530926 case SND_SOC_DAIFMT_LEFT_J:
927 dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J;
928 break;
929 case SND_SOC_DAIFMT_RIGHT_J:
930 dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J;
931 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900932 default:
933 return -EINVAL;
934 }
935
936 /* FIXME
937 *
938 * It support 64bit data transmission only now
939 */
940 dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
941
Axel Lin40a49712011-10-12 07:16:25 +0800942 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
943 snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900944
945 return 0;
946}
947
Ashish Chavan5eda1942011-10-19 14:19:06 +0530948static int da7210_mute(struct snd_soc_dai *dai, int mute)
949{
950 struct snd_soc_codec *codec = dai->codec;
951 u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB;
952
953 if (mute)
954 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4);
955 else
956 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg);
957 return 0;
958}
959
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530960#define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
961 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900962
963/* DAI operations */
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100964static const struct snd_soc_dai_ops da7210_dai_ops = {
Kuninori Morimoto98615452009-12-14 13:21:56 +0900965 .hw_params = da7210_hw_params,
966 .set_fmt = da7210_set_dai_fmt,
Ashish Chavan5eda1942011-10-19 14:19:06 +0530967 .digital_mute = da7210_mute,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900968};
969
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000970static struct snd_soc_dai_driver da7210_dai = {
971 .name = "da7210-hifi",
Kuninori Morimoto98615452009-12-14 13:21:56 +0900972 /* playback capabilities */
973 .playback = {
974 .stream_name = "Playback",
975 .channels_min = 1,
976 .channels_max = 2,
977 .rates = SNDRV_PCM_RATE_8000_96000,
978 .formats = DA7210_FORMATS,
979 },
980 /* capture capabilities */
981 .capture = {
982 .stream_name = "Capture",
983 .channels_min = 1,
984 .channels_max = 2,
985 .rates = SNDRV_PCM_RATE_8000_96000,
986 .formats = DA7210_FORMATS,
987 },
988 .ops = &da7210_dai_ops,
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900989 .symmetric_rates = 1,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900990};
Kuninori Morimoto98615452009-12-14 13:21:56 +0900991
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000992static int da7210_probe(struct snd_soc_codec *codec)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900993{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000994 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
Axel Lin40a49712011-10-12 07:16:25 +0800995 int ret;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900996
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000997 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900998
Ashish Chavan33593b52012-03-08 19:04:56 +0530999 codec->control_data = da7210->regmap;
1000 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
Axel Lin40a49712011-10-12 07:16:25 +08001001 if (ret < 0) {
1002 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1003 return ret;
1004 }
Kuninori Morimoto98615452009-12-14 13:21:56 +09001005
1006 /* FIXME
1007 *
1008 * This driver use fixed value here
Kuninori Morimoto960b3b42010-03-11 11:37:44 +09001009 * And below settings expects MCLK = 12.288MHz
1010 *
1011 * When you select different MCLK, please check...
1012 * DA7210_PLL_DIV1 val
1013 * DA7210_PLL_DIV2 val
1014 * DA7210_PLL_DIV3 val
1015 * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
Kuninori Morimoto98615452009-12-14 13:21:56 +09001016 */
1017
1018 /*
Kuninori Morimoto960b3b42010-03-11 11:37:44 +09001019 * make sure that DA7210 use bypass mode before start up
1020 */
Axel Lin40a49712011-10-12 07:16:25 +08001021 snd_soc_write(codec, DA7210_STARTUP1, 0);
1022 snd_soc_write(codec, DA7210_PLL_DIV3,
Kuninori Morimoto960b3b42010-03-11 11:37:44 +09001023 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
1024
1025 /*
Kuninori Morimoto98615452009-12-14 13:21:56 +09001026 * ADC settings
1027 */
1028
1029 /* Enable Left & Right MIC PGA and Mic Bias */
Axel Lin40a49712011-10-12 07:16:25 +08001030 snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
1031 snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001032
1033 /* Enable Left and Right input PGA */
Axel Lin40a49712011-10-12 07:16:25 +08001034 snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
1035 snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001036
1037 /* Enable Left and Right ADC */
Axel Lin40a49712011-10-12 07:16:25 +08001038 snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001039
1040 /*
1041 * DAC settings
1042 */
1043
1044 /* Enable Left and Right DAC */
Axel Lin40a49712011-10-12 07:16:25 +08001045 snd_soc_write(codec, DA7210_DAC_SEL,
Kuninori Morimoto98615452009-12-14 13:21:56 +09001046 DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
1047 DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
1048
1049 /* Enable Left and Right out PGA */
Axel Lin40a49712011-10-12 07:16:25 +08001050 snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
1051 snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001052
1053 /* Enable Left and Right HeadPhone PGA */
Axel Lin40a49712011-10-12 07:16:25 +08001054 snd_soc_write(codec, DA7210_HP_CFG,
Kuninori Morimoto98615452009-12-14 13:21:56 +09001055 DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
1056 DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
1057
Ashish Chavan5eda1942011-10-19 14:19:06 +05301058 /* Enable ramp mode for DAC gain update */
1059 snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN);
1060
Ashish Chavan52082d82011-10-21 19:06:23 +05301061 /*
1062 * For DA7210 codec, there are two ways to enable/disable analog IOs
1063 * and ADC/DAC,
1064 * (1) Using "Enable Bit" of register associated with that IO
1065 * (or ADC/DAC)
1066 * e.g. Mic Left can be enabled using bit 7 of MIC_L(0x7) reg
1067 *
1068 * (2) Using "Standby Bit" of STARTUP2 or STARTUP3 register
1069 * e.g. Mic left can be put to STANDBY using bit 0 of STARTUP3(0x5)
1070 *
1071 * Out of these two methods, the one using STANDBY bits is preferred
1072 * way to enable/disable individual blocks. This is because STANDBY
1073 * registers are part of system controller which allows system power
1074 * up/down in a controlled, pop-free manner. Also, as per application
1075 * note of DA7210, STANDBY register bits are only effective if a
1076 * particular IO (or ADC/DAC) is already enabled using enable/disable
1077 * register bits. Keeping these things in mind, current DAPM
1078 * implementation manipulates only STANDBY bits.
1079 *
1080 * Overall implementation can be outlined as below,
1081 *
1082 * - "Enable bit" of an IO or ADC/DAC is used to enable it in probe()
1083 * - "STANDBY bit" is controlled by DAPM
1084 */
1085
1086 /* Enable Line out amplifiers */
1087 snd_soc_write(codec, DA7210_OUT1_L, DA7210_OUT1_L_EN);
1088 snd_soc_write(codec, DA7210_OUT1_R, DA7210_OUT1_R_EN);
1089 snd_soc_write(codec, DA7210_OUT2, DA7210_OUT2_EN |
1090 DA7210_OUT2_OUTMIX_L | DA7210_OUT2_OUTMIX_R);
1091
Ashish Chavan24b6f262012-01-02 17:35:52 +05301092 /* Enable Aux1 */
1093 snd_soc_write(codec, DA7210_AUX1_L, DA7210_AUX1_L_EN);
1094 snd_soc_write(codec, DA7210_AUX1_R, DA7210_AUX1_R_EN);
1095 /* Enable Aux2 */
1096 snd_soc_write(codec, DA7210_AUX2, DA7210_AUX2_EN);
1097
Kuninori Morimoto98615452009-12-14 13:21:56 +09001098 /* Diable PLL and bypass it */
Axel Lin40a49712011-10-12 07:16:25 +08001099 snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001100
Kuninori Morimoto960b3b42010-03-11 11:37:44 +09001101 /*
1102 * If 48kHz sound came, it use bypass mode,
1103 * and when it is 44.1kHz, it use PLL.
1104 *
1105 * This time, this driver sets PLL always ON
1106 * and controls bypass/PLL mode by switching
1107 * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
1108 * see da7210_hw_params
1109 */
Axel Lin40a49712011-10-12 07:16:25 +08001110 snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
1111 snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
1112 snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
Kuninori Morimoto98615452009-12-14 13:21:56 +09001113 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
Kuninori Morimoto960b3b42010-03-11 11:37:44 +09001114 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
1115
1116 /* As suggested by Dialog */
Ashish Chavan33593b52012-03-08 19:04:56 +05301117 /* unlock */
1118 regmap_write(da7210->regmap, DA7210_A_HID_UNLOCK, 0x8B);
1119 regmap_write(da7210->regmap, DA7210_A_TEST_UNLOCK, 0xB4);
1120 regmap_write(da7210->regmap, DA7210_A_PLL1, 0x01);
1121 regmap_write(da7210->regmap, DA7210_A_CP_MODE, 0x7C);
1122 /* re-lock */
1123 regmap_write(da7210->regmap, DA7210_A_HID_UNLOCK, 0x00);
1124 regmap_write(da7210->regmap, DA7210_A_TEST_UNLOCK, 0x00);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001125
1126 /* Activate all enabled subsystem */
Axel Lin40a49712011-10-12 07:16:25 +08001127 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001128
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001129 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001130
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001131 return 0;
Kuninori Morimoto98615452009-12-14 13:21:56 +09001132}
1133
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001134static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +09001135 .probe = da7210_probe,
Mark Browna6f096f2011-10-14 20:18:49 +01001136
1137 .controls = da7210_snd_controls,
1138 .num_controls = ARRAY_SIZE(da7210_snd_controls),
Ashish Chavan6950c602011-10-21 18:16:08 +05301139
1140 .dapm_widgets = da7210_dapm_widgets,
1141 .num_dapm_widgets = ARRAY_SIZE(da7210_dapm_widgets),
1142 .dapm_routes = da7210_audio_map,
1143 .num_dapm_routes = ARRAY_SIZE(da7210_audio_map),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001144};
1145
Ashish Chavan33593b52012-03-08 19:04:56 +05301146static struct regmap_config da7210_regmap = {
1147 .reg_bits = 8,
1148 .val_bits = 8,
1149
1150 .reg_defaults = da7210_reg_defaults,
1151 .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
1152 .volatile_reg = da7210_volatile_register,
1153 .readable_reg = da7210_readable_register,
1154 .cache_type = REGCACHE_RBTREE,
1155};
1156
Kuninori Morimoto98615452009-12-14 13:21:56 +09001157#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
Mark Brown735fe4c2010-01-12 14:13:00 +00001158static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
1159 const struct i2c_device_id *id)
Kuninori Morimoto98615452009-12-14 13:21:56 +09001160{
1161 struct da7210_priv *da7210;
Kuninori Morimoto98615452009-12-14 13:21:56 +09001162 int ret;
1163
Axel Lin306bf6b2011-12-26 20:54:04 +08001164 da7210 = devm_kzalloc(&i2c->dev, sizeof(struct da7210_priv),
1165 GFP_KERNEL);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001166 if (!da7210)
1167 return -ENOMEM;
1168
Kuninori Morimoto98615452009-12-14 13:21:56 +09001169 i2c_set_clientdata(i2c, da7210);
Ashish Chavan33593b52012-03-08 19:04:56 +05301170
1171 da7210->regmap = regmap_init_i2c(i2c, &da7210_regmap);
1172 if (IS_ERR(da7210->regmap)) {
1173 ret = PTR_ERR(da7210->regmap);
1174 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
1175 return ret;
1176 }
Kuninori Morimoto98615452009-12-14 13:21:56 +09001177
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001178 ret = snd_soc_register_codec(&i2c->dev,
1179 &soc_codec_dev_da7210, &da7210_dai, 1);
Ashish Chavan33593b52012-03-08 19:04:56 +05301180 if (ret < 0) {
1181 dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
1182 goto err_regmap;
1183 }
1184 return ret;
1185
1186err_regmap:
1187 regmap_exit(da7210->regmap);
1188
Kuninori Morimoto98615452009-12-14 13:21:56 +09001189 return ret;
1190}
1191
Mark Brown735fe4c2010-01-12 14:13:00 +00001192static int __devexit da7210_i2c_remove(struct i2c_client *client)
Kuninori Morimoto98615452009-12-14 13:21:56 +09001193{
Ashish Chavan33593b52012-03-08 19:04:56 +05301194 struct da7210_priv *da7210 = i2c_get_clientdata(client);
1195
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001196 snd_soc_unregister_codec(&client->dev);
Ashish Chavan33593b52012-03-08 19:04:56 +05301197 regmap_exit(da7210->regmap);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001198 return 0;
1199}
1200
1201static const struct i2c_device_id da7210_i2c_id[] = {
1202 { "da7210", 0 },
1203 { }
1204};
1205MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
1206
1207/* I2C codec control layer */
1208static struct i2c_driver da7210_i2c_driver = {
1209 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001210 .name = "da7210-codec",
Kuninori Morimoto98615452009-12-14 13:21:56 +09001211 .owner = THIS_MODULE,
1212 },
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +09001213 .probe = da7210_i2c_probe,
1214 .remove = __devexit_p(da7210_i2c_remove),
1215 .id_table = da7210_i2c_id,
Kuninori Morimoto98615452009-12-14 13:21:56 +09001216};
1217#endif
1218
Kuninori Morimoto98615452009-12-14 13:21:56 +09001219static int __init da7210_modinit(void)
1220{
1221 int ret = 0;
1222#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1223 ret = i2c_add_driver(&da7210_i2c_driver);
1224#endif
1225 return ret;
1226}
1227module_init(da7210_modinit);
1228
1229static void __exit da7210_exit(void)
1230{
1231#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1232 i2c_del_driver(&da7210_i2c_driver);
1233#endif
1234}
1235module_exit(da7210_exit);
1236
1237MODULE_DESCRIPTION("ASoC DA7210 driver");
1238MODULE_AUTHOR("David Chen, Kuninori Morimoto");
1239MODULE_LICENSE("GPL");