blob: e9ee6a4faa268b0a9b25f6cd8158da55733cc5bb [file] [log] [blame]
Kuninori Morimoto98615452009-12-14 13:21:56 +09001/*
2 * DA7210 ALSA Soc codec driver
3 *
4 * Copyright (c) 2009 Dialog Semiconductor
5 * Written by David Chen <Dajun.chen@diasemi.com>
6 *
7 * Copyright (C) 2009 Renesas Solutions Corp.
8 * Cleanups by Kuninori Morimoto <morimoto.kuninori@renesas.com>
9 *
10 * Tested on SuperH Ecovec24 board with S16/S24 LE in 48KHz using I2S
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 */
17
Kuninori Morimoto98615452009-12-14 13:21:56 +090018#include <linux/delay.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090019#include <linux/i2c.h>
20#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090022#include <sound/pcm.h>
23#include <sound/pcm_params.h>
Liam Girdwoodce6120c2010-11-05 15:53:46 +020024#include <sound/soc.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090025#include <sound/initval.h>
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +090026#include <sound/tlv.h>
Kuninori Morimoto98615452009-12-14 13:21:56 +090027
Kuninori Morimoto98615452009-12-14 13:21:56 +090028/* DA7210 register space */
Ashish Chavande5eaf82011-10-19 14:24:37 +053029#define DA7210_CONTROL 0x01
Kuninori Morimoto98615452009-12-14 13:21:56 +090030#define DA7210_STATUS 0x02
31#define DA7210_STARTUP1 0x03
32#define DA7210_MIC_L 0x07
33#define DA7210_MIC_R 0x08
Ashish Chavande5eaf82011-10-19 14:24:37 +053034#define DA7210_AUX1_L 0x09
35#define DA7210_AUX1_R 0x0A
Ashish Chavan5eda1942011-10-19 14:19:06 +053036#define DA7210_AUX2 0x0B
Ashish Chavande5eaf82011-10-19 14:24:37 +053037#define DA7210_IN_GAIN 0x0C
Kuninori Morimoto98615452009-12-14 13:21:56 +090038#define DA7210_INMIX_L 0x0D
39#define DA7210_INMIX_R 0x0E
40#define DA7210_ADC_HPF 0x0F
41#define DA7210_ADC 0x10
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +053042#define DA7210_ADC_EQ1_2 0X11
43#define DA7210_ADC_EQ3_4 0x12
44#define DA7210_ADC_EQ5 0x13
Kuninori Morimoto98615452009-12-14 13:21:56 +090045#define DA7210_DAC_HPF 0x14
46#define DA7210_DAC_L 0x15
47#define DA7210_DAC_R 0x16
48#define DA7210_DAC_SEL 0x17
Ashish Chavan5eda1942011-10-19 14:19:06 +053049#define DA7210_SOFTMUTE 0x18
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +053050#define DA7210_DAC_EQ1_2 0x19
51#define DA7210_DAC_EQ3_4 0x1A
52#define DA7210_DAC_EQ5 0x1B
Kuninori Morimoto98615452009-12-14 13:21:56 +090053#define DA7210_OUTMIX_L 0x1C
54#define DA7210_OUTMIX_R 0x1D
55#define DA7210_HP_L_VOL 0x21
56#define DA7210_HP_R_VOL 0x22
57#define DA7210_HP_CFG 0x23
Ashish Chavan5eda1942011-10-19 14:19:06 +053058#define DA7210_ZERO_CROSS 0x24
Kuninori Morimoto98615452009-12-14 13:21:56 +090059#define DA7210_DAI_SRC_SEL 0x25
60#define DA7210_DAI_CFG1 0x26
61#define DA7210_DAI_CFG3 0x28
Kuninori Morimoto960b3b42010-03-11 11:37:44 +090062#define DA7210_PLL_DIV1 0x29
63#define DA7210_PLL_DIV2 0x2A
Kuninori Morimoto98615452009-12-14 13:21:56 +090064#define DA7210_PLL_DIV3 0x2B
65#define DA7210_PLL 0x2C
Ashish Chavande5eaf82011-10-19 14:24:37 +053066#define DA7210_ALC_MAX 0x83
67#define DA7210_ALC_MIN 0x84
68#define DA7210_ALC_NOIS 0x85
69#define DA7210_ALC_ATT 0x86
70#define DA7210_ALC_REL 0x87
71#define DA7210_ALC_DEL 0x88
Kuninori Morimoto960b3b42010-03-11 11:37:44 +090072#define DA7210_A_HID_UNLOCK 0x8A
73#define DA7210_A_TEST_UNLOCK 0x8B
74#define DA7210_A_PLL1 0x90
75#define DA7210_A_CP_MODE 0xA7
Kuninori Morimoto98615452009-12-14 13:21:56 +090076
77/* STARTUP1 bit fields */
78#define DA7210_SC_MST_EN (1 << 0)
79
80/* MIC_L bit fields */
81#define DA7210_MICBIAS_EN (1 << 6)
82#define DA7210_MIC_L_EN (1 << 7)
83
84/* MIC_R bit fields */
85#define DA7210_MIC_R_EN (1 << 7)
86
87/* INMIX_L bit fields */
88#define DA7210_IN_L_EN (1 << 7)
89
90/* INMIX_R bit fields */
91#define DA7210_IN_R_EN (1 << 7)
92
Kuninori Morimoto98615452009-12-14 13:21:56 +090093/* ADC bit fields */
Ashish Chavande5eaf82011-10-19 14:24:37 +053094#define DA7210_ADC_ALC_EN (1 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +090095#define DA7210_ADC_L_EN (1 << 3)
96#define DA7210_ADC_R_EN (1 << 7)
97
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +090098/* DAC/ADC HPF fields */
99#define DA7210_VOICE_F0_MASK (0x7 << 4)
100#define DA7210_VOICE_F0_25 (1 << 4)
101#define DA7210_VOICE_EN (1 << 7)
Mark Brownc2151432009-12-16 20:36:37 +0000102
Kuninori Morimoto98615452009-12-14 13:21:56 +0900103/* DAC_SEL bit fields */
104#define DA7210_DAC_L_SRC_DAI_L (4 << 0)
105#define DA7210_DAC_L_EN (1 << 3)
106#define DA7210_DAC_R_SRC_DAI_R (5 << 4)
107#define DA7210_DAC_R_EN (1 << 7)
108
109/* OUTMIX_L bit fields */
110#define DA7210_OUT_L_EN (1 << 7)
111
112/* OUTMIX_R bit fields */
113#define DA7210_OUT_R_EN (1 << 7)
114
115/* HP_CFG bit fields */
116#define DA7210_HP_2CAP_MODE (1 << 1)
117#define DA7210_HP_SENSE_EN (1 << 2)
118#define DA7210_HP_L_EN (1 << 3)
119#define DA7210_HP_MODE (1 << 6)
120#define DA7210_HP_R_EN (1 << 7)
121
122/* DAI_SRC_SEL bit fields */
123#define DA7210_DAI_OUT_L_SRC (6 << 0)
124#define DA7210_DAI_OUT_R_SRC (7 << 4)
125
126/* DAI_CFG1 bit fields */
127#define DA7210_DAI_WORD_S16_LE (0 << 0)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530128#define DA7210_DAI_WORD_S20_3LE (1 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900129#define DA7210_DAI_WORD_S24_LE (2 << 0)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530130#define DA7210_DAI_WORD_S32_LE (3 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900131#define DA7210_DAI_FLEN_64BIT (1 << 2)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530132#define DA7210_DAI_MODE_SLAVE (0 << 7)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900133#define DA7210_DAI_MODE_MASTER (1 << 7)
134
135/* DAI_CFG3 bit fields */
136#define DA7210_DAI_FORMAT_I2SMODE (0 << 0)
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530137#define DA7210_DAI_FORMAT_LEFT_J (1 << 0)
138#define DA7210_DAI_FORMAT_RIGHT_J (2 << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900139#define DA7210_DAI_OE (1 << 3)
140#define DA7210_DAI_EN (1 << 7)
141
142/*PLL_DIV3 bit fields */
143#define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
144#define DA7210_PLL_BYP (1 << 6)
145
146/* PLL bit fields */
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900147#define DA7210_PLL_FS_MASK (0xF << 0)
148#define DA7210_PLL_FS_8000 (0x1 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900149#define DA7210_PLL_FS_11025 (0x2 << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900150#define DA7210_PLL_FS_12000 (0x3 << 0)
151#define DA7210_PLL_FS_16000 (0x5 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900152#define DA7210_PLL_FS_22050 (0x6 << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900153#define DA7210_PLL_FS_24000 (0x7 << 0)
154#define DA7210_PLL_FS_32000 (0x9 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900155#define DA7210_PLL_FS_44100 (0xA << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900156#define DA7210_PLL_FS_48000 (0xB << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900157#define DA7210_PLL_FS_88200 (0xE << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900158#define DA7210_PLL_FS_96000 (0xF << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900159#define DA7210_PLL_EN (0x1 << 7)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900160
Ashish Chavan5eda1942011-10-19 14:19:06 +0530161/* SOFTMUTE bit fields */
162#define DA7210_RAMP_EN (1 << 6)
163
Ashish Chavande5eaf82011-10-19 14:24:37 +0530164/* CONTROL bit fields */
165#define DA7210_NOISE_SUP_EN (1 << 3)
166
167/* IN_GAIN bit fields */
168#define DA7210_INPGA_L_VOL (0x0F << 0)
169#define DA7210_INPGA_R_VOL (0xF0 << 0)
170
171/* ZERO_CROSS bit fields */
172#define DA7210_AUX1_L_ZC (1 << 0)
173#define DA7210_AUX1_R_ZC (1 << 1)
174#define DA7210_HP_L_ZC (1 << 6)
175#define DA7210_HP_R_ZC (1 << 7)
176
177/* AUX1_L bit fields */
178#define DA7210_AUX1_L_VOL (0x3F << 0)
179
180/* AUX1_R bit fields */
181#define DA7210_AUX1_R_VOL (0x3F << 0)
182
183/* Minimum INPGA and AUX1 volume to enable noise suppression */
184#define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */
185#define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */
186
Kuninori Morimoto98615452009-12-14 13:21:56 +0900187#define DA7210_VERSION "0.0.1"
188
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900189/*
190 * Playback Volume
191 *
192 * max : 0x3F (+15.0 dB)
193 * (1.5 dB step)
194 * min : 0x11 (-54.0 dB)
195 * mute : 0x10
196 * reserved : 0x00 - 0x0F
197 *
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900198 * Reserved area are considered as "mute".
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900199 */
Ashish Chavan7a0e67b2011-10-14 16:25:25 +0530200static const unsigned int hp_out_tlv[] = {
201 TLV_DB_RANGE_HEAD(2),
202 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
203 /* -54 dB to +15 dB */
204 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0),
205};
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900206
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530207static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
208static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1);
209
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530210/* ADC and DAC high pass filter f0 value */
211static const char const *da7210_hpf_cutoff_txt[] = {
212 "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi"
213};
214
215static const struct soc_enum da7210_dac_hpf_cutoff =
216 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt);
217
218static const struct soc_enum da7210_adc_hpf_cutoff =
219 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt);
220
221/* ADC and DAC voice (8kHz) high pass cutoff value */
222static const char const *da7210_vf_cutoff_txt[] = {
223 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
224};
225
226static const struct soc_enum da7210_dac_vf_cutoff =
227 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt);
228
229static const struct soc_enum da7210_adc_vf_cutoff =
230 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt);
231
Ashish Chavan5eda1942011-10-19 14:19:06 +0530232static const char *da7210_hp_mode_txt[] = {
233 "Class H", "Class G"
234};
235
236static const struct soc_enum da7210_hp_mode_sel =
237 SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt);
238
Ashish Chavande5eaf82011-10-19 14:24:37 +0530239/* ALC can be enabled only if noise suppression is disabled */
240static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol,
241 struct snd_ctl_elem_value *ucontrol)
242{
243 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
244
245 if (ucontrol->value.integer.value[0]) {
246 /* Check if noise suppression is enabled */
247 if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) {
248 dev_dbg(codec->dev,
249 "Disable noise suppression to enable ALC\n");
250 return -EINVAL;
251 }
252 }
253 /* If all conditions are met or we are actually disabling ALC */
254 return snd_soc_put_volsw(kcontrol, ucontrol);
255}
256
257/* Noise suppression can be enabled only if following conditions are met
258 * ALC disabled
259 * ZC enabled for HP and AUX1 PGA
260 * INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB
261 * AUX1_L_VOL and AUX1_R_VOL >= 6 dB
262 */
263static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol,
264 struct snd_ctl_elem_value *ucontrol)
265{
266 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
267 u8 val;
268
269 if (ucontrol->value.integer.value[0]) {
270 /* Check if ALC is enabled */
271 if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN)
272 goto err;
273
274 /* Check ZC for HP and AUX1 PGA */
275 if ((snd_soc_read(codec, DA7210_ZERO_CROSS) &
276 (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC |
277 DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC |
278 DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC))
279 goto err;
280
281 /* Check INPGA_L_VOL and INPGA_R_VOL */
282 val = snd_soc_read(codec, DA7210_IN_GAIN);
283 if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) ||
284 (((val & DA7210_INPGA_R_VOL) >> 4) <
285 DA7210_INPGA_MIN_VOL_NS))
286 goto err;
287
288 /* Check AUX1_L_VOL and AUX1_R_VOL */
289 if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) <
290 DA7210_AUX1_MIN_VOL_NS) ||
291 ((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) <
292 DA7210_AUX1_MIN_VOL_NS))
293 goto err;
294 }
295 /* If all conditions are met or we are actually disabling Noise sup */
296 return snd_soc_put_volsw(kcontrol, ucontrol);
297
298err:
299 return -EINVAL;
300}
301
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900302static const struct snd_kcontrol_new da7210_snd_controls[] = {
303
304 SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
305 DA7210_HP_L_VOL, DA7210_HP_R_VOL,
306 0, 0x3F, 0, hp_out_tlv),
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530307
308 /* DAC Equalizer controls */
309 SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0),
310 SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1,
311 eq_gain_tlv),
312 SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1,
313 eq_gain_tlv),
314 SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1,
315 eq_gain_tlv),
316 SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1,
317 eq_gain_tlv),
318 SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1,
319 eq_gain_tlv),
320
321 /* ADC Equalizer controls */
322 SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0),
323 SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3,
324 1, adc_eq_master_gain_tlv),
325 SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1,
326 eq_gain_tlv),
327 SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1,
328 eq_gain_tlv),
329 SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1,
330 eq_gain_tlv),
331 SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1,
332 eq_gain_tlv),
333 SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1,
334 eq_gain_tlv),
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530335
336 SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0),
337 SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff),
338 SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0),
339 SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff),
340
341 SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0),
342 SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff),
343 SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0),
344 SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff),
Ashish Chavan5eda1942011-10-19 14:19:06 +0530345
346 /* Mute controls */
347 SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0),
348 SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0),
349 SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0),
350 SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0),
351 SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0),
352
353 /* Zero cross controls */
354 SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0),
355 SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0),
356 SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0),
357 SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0),
358
359 SOC_ENUM("Headphone Class", da7210_hp_mode_sel),
Ashish Chavande5eaf82011-10-19 14:24:37 +0530360
361 /* ALC controls */
362 SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0,
363 snd_soc_get_volsw, da7210_put_alc_sw),
364 SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0),
365 SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0),
366 SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0),
367 SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0),
368 SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0),
369 SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0),
370
371 SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1,
372 0, snd_soc_get_volsw, da7210_put_noise_sup_sw),
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900373};
374
Kuninori Morimoto98615452009-12-14 13:21:56 +0900375/* Codec private data */
376struct da7210_priv {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000377 enum snd_soc_control_type control_type;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900378};
379
Kuninori Morimoto98615452009-12-14 13:21:56 +0900380/*
381 * Register cache
382 */
383static const u8 da7210_reg[] = {
384 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R0 - R7 */
385 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, /* R8 - RF */
386 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x10, 0x54, /* R10 - R17 */
387 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R18 - R1F */
388 0x00, 0x00, 0x00, 0x02, 0x00, 0x76, 0x00, 0x00, /* R20 - R27 */
389 0x04, 0x00, 0x00, 0x30, 0x2A, 0x00, 0x40, 0x00, /* R28 - R2F */
390 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, /* R30 - R37 */
391 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, /* R38 - R3F */
392 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R40 - R4F */
393 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R48 - R4F */
394 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R50 - R57 */
395 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R58 - R5F */
396 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R60 - R67 */
397 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R68 - R6F */
398 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* R70 - R77 */
399 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x54, 0x00, /* R78 - R7F */
400 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, /* R80 - R87 */
401 0x00, /* R88 */
402};
403
Axel Lin40a49712011-10-12 07:16:25 +0800404static int da7210_volatile_register(struct snd_soc_codec *codec,
405 unsigned int reg)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900406{
Axel Lin40a49712011-10-12 07:16:25 +0800407 switch (reg) {
408 case DA7210_STATUS:
409 return 1;
410 default:
411 return 0;
412 }
Kuninori Morimoto98615452009-12-14 13:21:56 +0900413}
Kuninori Morimoto98615452009-12-14 13:21:56 +0900414static int da7210_startup(struct snd_pcm_substream *substream,
415 struct snd_soc_dai *dai)
416{
417 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
418 struct snd_soc_codec *codec = dai->codec;
419
420 if (is_play) {
Kuninori Morimoto98615452009-12-14 13:21:56 +0900421 /* Enable Out */
422 snd_soc_update_bits(codec, DA7210_OUTMIX_L, 0x1F, 0x10);
423 snd_soc_update_bits(codec, DA7210_OUTMIX_R, 0x1F, 0x10);
424
425 } else {
426 /* Volume 7 */
427 snd_soc_update_bits(codec, DA7210_MIC_L, 0x7, 0x7);
428 snd_soc_update_bits(codec, DA7210_MIC_R, 0x7, 0x7);
429
430 /* Enable Mic */
431 snd_soc_update_bits(codec, DA7210_INMIX_L, 0x1F, 0x1);
432 snd_soc_update_bits(codec, DA7210_INMIX_R, 0x1F, 0x1);
433 }
434
435 return 0;
436}
437
438/*
439 * Set PCM DAI word length.
440 */
441static int da7210_hw_params(struct snd_pcm_substream *substream,
442 struct snd_pcm_hw_params *params,
443 struct snd_soc_dai *dai)
444{
445 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000446 struct snd_soc_codec *codec = rtd->codec;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900447 u32 dai_cfg1;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900448 u32 fs, bypass;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900449
450 /* set DAI source to Left and Right ADC */
Axel Lin40a49712011-10-12 07:16:25 +0800451 snd_soc_write(codec, DA7210_DAI_SRC_SEL,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900452 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
453
454 /* Enable DAI */
Axel Lin40a49712011-10-12 07:16:25 +0800455 snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900456
Axel Lin40a49712011-10-12 07:16:25 +0800457 dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900458
459 switch (params_format(params)) {
460 case SNDRV_PCM_FORMAT_S16_LE:
461 dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
462 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530463 case SNDRV_PCM_FORMAT_S20_3LE:
464 dai_cfg1 |= DA7210_DAI_WORD_S20_3LE;
465 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900466 case SNDRV_PCM_FORMAT_S24_LE:
467 dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
468 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530469 case SNDRV_PCM_FORMAT_S32_LE:
470 dai_cfg1 |= DA7210_DAI_WORD_S32_LE;
471 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900472 default:
473 return -EINVAL;
474 }
475
Axel Lin40a49712011-10-12 07:16:25 +0800476 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900477
Kuninori Morimoto98615452009-12-14 13:21:56 +0900478 switch (params_rate(params)) {
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900479 case 8000:
480 fs = DA7210_PLL_FS_8000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900481 bypass = DA7210_PLL_BYP;
482 break;
483 case 11025:
484 fs = DA7210_PLL_FS_11025;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900485 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900486 break;
487 case 12000:
488 fs = DA7210_PLL_FS_12000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900489 bypass = DA7210_PLL_BYP;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900490 break;
491 case 16000:
492 fs = DA7210_PLL_FS_16000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900493 bypass = DA7210_PLL_BYP;
494 break;
495 case 22050:
496 fs = DA7210_PLL_FS_22050;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900497 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900498 break;
499 case 32000:
500 fs = DA7210_PLL_FS_32000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900501 bypass = DA7210_PLL_BYP;
502 break;
503 case 44100:
504 fs = DA7210_PLL_FS_44100;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900505 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900506 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900507 case 48000:
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900508 fs = DA7210_PLL_FS_48000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900509 bypass = DA7210_PLL_BYP;
510 break;
511 case 88200:
512 fs = DA7210_PLL_FS_88200;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900513 bypass = 0;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900514 break;
515 case 96000:
516 fs = DA7210_PLL_FS_96000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900517 bypass = DA7210_PLL_BYP;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900518 break;
519 default:
520 return -EINVAL;
521 }
522
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900523 /* Disable active mode */
524 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
525
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900526 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900527 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
528
529 /* Enable active mode */
530 snd_soc_update_bits(codec, DA7210_STARTUP1,
531 DA7210_SC_MST_EN, DA7210_SC_MST_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900532
533 return 0;
534}
535
536/*
537 * Set DAI mode and Format
538 */
539static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
540{
541 struct snd_soc_codec *codec = codec_dai->codec;
542 u32 dai_cfg1;
543 u32 dai_cfg3;
544
Axel Lin40a49712011-10-12 07:16:25 +0800545 dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
546 dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900547
548 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
549 case SND_SOC_DAIFMT_CBM_CFM:
550 dai_cfg1 |= DA7210_DAI_MODE_MASTER;
551 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530552 case SND_SOC_DAIFMT_CBS_CFS:
553 dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
554 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900555 default:
556 return -EINVAL;
557 }
558
559 /* FIXME
560 *
561 * It support I2S only now
562 */
563 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
564 case SND_SOC_DAIFMT_I2S:
565 dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
566 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530567 case SND_SOC_DAIFMT_LEFT_J:
568 dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J;
569 break;
570 case SND_SOC_DAIFMT_RIGHT_J:
571 dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J;
572 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900573 default:
574 return -EINVAL;
575 }
576
577 /* FIXME
578 *
579 * It support 64bit data transmission only now
580 */
581 dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
582
Axel Lin40a49712011-10-12 07:16:25 +0800583 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
584 snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900585
586 return 0;
587}
588
Ashish Chavan5eda1942011-10-19 14:19:06 +0530589static int da7210_mute(struct snd_soc_dai *dai, int mute)
590{
591 struct snd_soc_codec *codec = dai->codec;
592 u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB;
593
594 if (mute)
595 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4);
596 else
597 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg);
598 return 0;
599}
600
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530601#define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
602 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900603
604/* DAI operations */
605static struct snd_soc_dai_ops da7210_dai_ops = {
606 .startup = da7210_startup,
607 .hw_params = da7210_hw_params,
608 .set_fmt = da7210_set_dai_fmt,
Ashish Chavan5eda1942011-10-19 14:19:06 +0530609 .digital_mute = da7210_mute,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900610};
611
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000612static struct snd_soc_dai_driver da7210_dai = {
613 .name = "da7210-hifi",
Kuninori Morimoto98615452009-12-14 13:21:56 +0900614 /* playback capabilities */
615 .playback = {
616 .stream_name = "Playback",
617 .channels_min = 1,
618 .channels_max = 2,
619 .rates = SNDRV_PCM_RATE_8000_96000,
620 .formats = DA7210_FORMATS,
621 },
622 /* capture capabilities */
623 .capture = {
624 .stream_name = "Capture",
625 .channels_min = 1,
626 .channels_max = 2,
627 .rates = SNDRV_PCM_RATE_8000_96000,
628 .formats = DA7210_FORMATS,
629 },
630 .ops = &da7210_dai_ops,
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900631 .symmetric_rates = 1,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900632};
Kuninori Morimoto98615452009-12-14 13:21:56 +0900633
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000634static int da7210_probe(struct snd_soc_codec *codec)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900635{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000636 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
Axel Lin40a49712011-10-12 07:16:25 +0800637 int ret;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900638
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000639 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900640
Axel Lin40a49712011-10-12 07:16:25 +0800641 ret = snd_soc_codec_set_cache_io(codec, 8, 8, da7210->control_type);
642 if (ret < 0) {
643 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
644 return ret;
645 }
Kuninori Morimoto98615452009-12-14 13:21:56 +0900646
647 /* FIXME
648 *
649 * This driver use fixed value here
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900650 * And below settings expects MCLK = 12.288MHz
651 *
652 * When you select different MCLK, please check...
653 * DA7210_PLL_DIV1 val
654 * DA7210_PLL_DIV2 val
655 * DA7210_PLL_DIV3 val
656 * DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
Kuninori Morimoto98615452009-12-14 13:21:56 +0900657 */
658
659 /*
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900660 * make sure that DA7210 use bypass mode before start up
661 */
Axel Lin40a49712011-10-12 07:16:25 +0800662 snd_soc_write(codec, DA7210_STARTUP1, 0);
663 snd_soc_write(codec, DA7210_PLL_DIV3,
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900664 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
665
666 /*
Kuninori Morimoto98615452009-12-14 13:21:56 +0900667 * ADC settings
668 */
669
670 /* Enable Left & Right MIC PGA and Mic Bias */
Axel Lin40a49712011-10-12 07:16:25 +0800671 snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
672 snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900673
674 /* Enable Left and Right input PGA */
Axel Lin40a49712011-10-12 07:16:25 +0800675 snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
676 snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900677
678 /* Enable Left and Right ADC */
Axel Lin40a49712011-10-12 07:16:25 +0800679 snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900680
681 /*
682 * DAC settings
683 */
684
685 /* Enable Left and Right DAC */
Axel Lin40a49712011-10-12 07:16:25 +0800686 snd_soc_write(codec, DA7210_DAC_SEL,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900687 DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
688 DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
689
690 /* Enable Left and Right out PGA */
Axel Lin40a49712011-10-12 07:16:25 +0800691 snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
692 snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900693
694 /* Enable Left and Right HeadPhone PGA */
Axel Lin40a49712011-10-12 07:16:25 +0800695 snd_soc_write(codec, DA7210_HP_CFG,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900696 DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
697 DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
698
Ashish Chavan5eda1942011-10-19 14:19:06 +0530699 /* Enable ramp mode for DAC gain update */
700 snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN);
701
Kuninori Morimoto98615452009-12-14 13:21:56 +0900702 /* Diable PLL and bypass it */
Axel Lin40a49712011-10-12 07:16:25 +0800703 snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900704
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900705 /*
706 * If 48kHz sound came, it use bypass mode,
707 * and when it is 44.1kHz, it use PLL.
708 *
709 * This time, this driver sets PLL always ON
710 * and controls bypass/PLL mode by switching
711 * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
712 * see da7210_hw_params
713 */
Axel Lin40a49712011-10-12 07:16:25 +0800714 snd_soc_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
715 snd_soc_write(codec, DA7210_PLL_DIV2, 0x99);
716 snd_soc_write(codec, DA7210_PLL_DIV3, 0x0A |
Kuninori Morimoto98615452009-12-14 13:21:56 +0900717 DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900718 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
719
720 /* As suggested by Dialog */
Axel Lin40a49712011-10-12 07:16:25 +0800721 snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x8B); /* unlock */
722 snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0xB4);
723 snd_soc_write(codec, DA7210_A_PLL1, 0x01);
724 snd_soc_write(codec, DA7210_A_CP_MODE, 0x7C);
725 snd_soc_write(codec, DA7210_A_HID_UNLOCK, 0x00); /* re-lock */
726 snd_soc_write(codec, DA7210_A_TEST_UNLOCK, 0x00);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900727
728 /* Activate all enabled subsystem */
Axel Lin40a49712011-10-12 07:16:25 +0800729 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900730
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000731 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900732
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000733 return 0;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900734}
735
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000736static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +0900737 .probe = da7210_probe,
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +0900738 .reg_cache_size = ARRAY_SIZE(da7210_reg),
739 .reg_word_size = sizeof(u8),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000740 .reg_cache_default = da7210_reg,
Axel Lin40a49712011-10-12 07:16:25 +0800741 .volatile_register = da7210_volatile_register,
Mark Browna6f096f2011-10-14 20:18:49 +0100742
743 .controls = da7210_snd_controls,
744 .num_controls = ARRAY_SIZE(da7210_snd_controls),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000745};
746
Kuninori Morimoto98615452009-12-14 13:21:56 +0900747#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
Mark Brown735fe4c2010-01-12 14:13:00 +0000748static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
749 const struct i2c_device_id *id)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900750{
751 struct da7210_priv *da7210;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900752 int ret;
753
754 da7210 = kzalloc(sizeof(struct da7210_priv), GFP_KERNEL);
755 if (!da7210)
756 return -ENOMEM;
757
Kuninori Morimoto98615452009-12-14 13:21:56 +0900758 i2c_set_clientdata(i2c, da7210);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000759 da7210->control_type = SND_SOC_I2C;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900760
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000761 ret = snd_soc_register_codec(&i2c->dev,
762 &soc_codec_dev_da7210, &da7210_dai, 1);
763 if (ret < 0)
Axel Lin085efd22010-07-23 05:53:45 +0000764 kfree(da7210);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900765
766 return ret;
767}
768
Mark Brown735fe4c2010-01-12 14:13:00 +0000769static int __devexit da7210_i2c_remove(struct i2c_client *client)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900770{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000771 snd_soc_unregister_codec(&client->dev);
772 kfree(i2c_get_clientdata(client));
Kuninori Morimoto98615452009-12-14 13:21:56 +0900773 return 0;
774}
775
776static const struct i2c_device_id da7210_i2c_id[] = {
777 { "da7210", 0 },
778 { }
779};
780MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
781
782/* I2C codec control layer */
783static struct i2c_driver da7210_i2c_driver = {
784 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000785 .name = "da7210-codec",
Kuninori Morimoto98615452009-12-14 13:21:56 +0900786 .owner = THIS_MODULE,
787 },
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +0900788 .probe = da7210_i2c_probe,
789 .remove = __devexit_p(da7210_i2c_remove),
790 .id_table = da7210_i2c_id,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900791};
792#endif
793
Kuninori Morimoto98615452009-12-14 13:21:56 +0900794static int __init da7210_modinit(void)
795{
796 int ret = 0;
797#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
798 ret = i2c_add_driver(&da7210_i2c_driver);
799#endif
800 return ret;
801}
802module_init(da7210_modinit);
803
804static void __exit da7210_exit(void)
805{
806#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
807 i2c_del_driver(&da7210_i2c_driver);
808#endif
809}
810module_exit(da7210_exit);
811
812MODULE_DESCRIPTION("ASoC DA7210 driver");
813MODULE_AUTHOR("David Chen, Kuninori Morimoto");
814MODULE_LICENSE("GPL");