blob: f92d1f7777571ecdeb5b2833cbefef2fcdd60e36 [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 */
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530151#define DA7210_PLL_DIV_L_MASK (0xF << 0)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900152#define DA7210_MCLK_RANGE_10_20_MHZ (1 << 4)
153#define DA7210_PLL_BYP (1 << 6)
154
155/* PLL bit fields */
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900156#define DA7210_PLL_FS_MASK (0xF << 0)
157#define DA7210_PLL_FS_8000 (0x1 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900158#define DA7210_PLL_FS_11025 (0x2 << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900159#define DA7210_PLL_FS_12000 (0x3 << 0)
160#define DA7210_PLL_FS_16000 (0x5 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900161#define DA7210_PLL_FS_22050 (0x6 << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900162#define DA7210_PLL_FS_24000 (0x7 << 0)
163#define DA7210_PLL_FS_32000 (0x9 << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900164#define DA7210_PLL_FS_44100 (0xA << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900165#define DA7210_PLL_FS_48000 (0xB << 0)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900166#define DA7210_PLL_FS_88200 (0xE << 0)
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900167#define DA7210_PLL_FS_96000 (0xF << 0)
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530168#define DA7210_MCLK_DET_EN (0x1 << 5)
169#define DA7210_MCLK_SRM_EN (0x1 << 6)
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900170#define DA7210_PLL_EN (0x1 << 7)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900171
Ashish Chavan5eda1942011-10-19 14:19:06 +0530172/* SOFTMUTE bit fields */
173#define DA7210_RAMP_EN (1 << 6)
174
Ashish Chavande5eaf82011-10-19 14:24:37 +0530175/* CONTROL bit fields */
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530176#define DA7210_REG_EN (1 << 0)
177#define DA7210_BIAS_EN (1 << 2)
Ashish Chavande5eaf82011-10-19 14:24:37 +0530178#define DA7210_NOISE_SUP_EN (1 << 3)
179
180/* IN_GAIN bit fields */
181#define DA7210_INPGA_L_VOL (0x0F << 0)
182#define DA7210_INPGA_R_VOL (0xF0 << 0)
183
184/* ZERO_CROSS bit fields */
185#define DA7210_AUX1_L_ZC (1 << 0)
186#define DA7210_AUX1_R_ZC (1 << 1)
187#define DA7210_HP_L_ZC (1 << 6)
188#define DA7210_HP_R_ZC (1 << 7)
189
190/* AUX1_L bit fields */
191#define DA7210_AUX1_L_VOL (0x3F << 0)
Ashish Chavan24b6f262012-01-02 17:35:52 +0530192#define DA7210_AUX1_L_EN (1 << 7)
Ashish Chavande5eaf82011-10-19 14:24:37 +0530193
194/* AUX1_R bit fields */
195#define DA7210_AUX1_R_VOL (0x3F << 0)
Ashish Chavan24b6f262012-01-02 17:35:52 +0530196#define DA7210_AUX1_R_EN (1 << 7)
197
198/* AUX2 bit fields */
199#define DA7210_AUX2_EN (1 << 3)
Ashish Chavande5eaf82011-10-19 14:24:37 +0530200
201/* Minimum INPGA and AUX1 volume to enable noise suppression */
202#define DA7210_INPGA_MIN_VOL_NS 0x0A /* 10.5dB */
203#define DA7210_AUX1_MIN_VOL_NS 0x35 /* 6dB */
204
Ashish Chavan52082d82011-10-21 19:06:23 +0530205/* OUT1_L bit fields */
206#define DA7210_OUT1_L_EN (1 << 7)
207
208/* OUT1_R bit fields */
209#define DA7210_OUT1_R_EN (1 << 7)
210
211/* OUT2 bit fields */
212#define DA7210_OUT2_OUTMIX_R (1 << 5)
213#define DA7210_OUT2_OUTMIX_L (1 << 6)
214#define DA7210_OUT2_EN (1 << 7)
215
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530216struct pll_div {
217 int fref;
218 int fout;
219 u8 div1;
220 u8 div2;
221 u8 div3;
222 u8 mode; /* 0 = slave, 1 = master */
223};
224
225/* PLL dividers table */
226static const struct pll_div da7210_pll_div[] = {
227 /* for MASTER mode, fs = 44.1Khz */
228 { 12000000, 2822400, 0xE8, 0x6C, 0x2, 1}, /* MCLK=12Mhz */
229 { 13000000, 2822400, 0xDF, 0x28, 0xC, 1}, /* MCLK=13Mhz */
230 { 13500000, 2822400, 0xDB, 0x0A, 0xD, 1}, /* MCLK=13.5Mhz */
231 { 14400000, 2822400, 0xD4, 0x5A, 0x2, 1}, /* MCLK=14.4Mhz */
232 { 19200000, 2822400, 0xBB, 0x43, 0x9, 1}, /* MCLK=19.2Mhz */
233 { 19680000, 2822400, 0xB9, 0x6D, 0xA, 1}, /* MCLK=19.68Mhz */
234 { 19800000, 2822400, 0xB8, 0xFB, 0xB, 1}, /* MCLK=19.8Mhz */
235 /* for MASTER mode, fs = 48Khz */
236 { 12000000, 3072000, 0xF3, 0x12, 0x7, 1}, /* MCLK=12Mhz */
237 { 13000000, 3072000, 0xE8, 0xFD, 0x5, 1}, /* MCLK=13Mhz */
238 { 13500000, 3072000, 0xE4, 0x82, 0x3, 1}, /* MCLK=13.5Mhz */
239 { 14400000, 3072000, 0xDD, 0x3A, 0x0, 1}, /* MCLK=14.4Mhz */
240 { 19200000, 3072000, 0xC1, 0xEB, 0x8, 1}, /* MCLK=19.2Mhz */
241 { 19680000, 3072000, 0xBF, 0xEC, 0x0, 1}, /* MCLK=19.68Mhz */
242 { 19800000, 3072000, 0xBF, 0x70, 0x0, 1}, /* MCLK=19.8Mhz */
243 /* for SLAVE mode with SRM */
244 { 12000000, 2822400, 0xED, 0xBF, 0x5, 0}, /* MCLK=12Mhz */
245 { 13000000, 2822400, 0xE4, 0x13, 0x0, 0}, /* MCLK=13Mhz */
246 { 13500000, 2822400, 0xDF, 0xC6, 0x8, 0}, /* MCLK=13.5Mhz */
247 { 14400000, 2822400, 0xD8, 0xCA, 0x1, 0}, /* MCLK=14.4Mhz */
248 { 19200000, 2822400, 0xBE, 0x97, 0x9, 0}, /* MCLK=19.2Mhz */
249 { 19680000, 2822400, 0xBC, 0xAC, 0xD, 0}, /* MCLK=19.68Mhz */
250 { 19800000, 2822400, 0xBC, 0x35, 0xE, 0}, /* MCLK=19.8Mhz */
251};
252
253enum clk_src {
254 DA7210_CLKSRC_MCLK
255};
256
Kuninori Morimoto98615452009-12-14 13:21:56 +0900257#define DA7210_VERSION "0.0.1"
258
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900259/*
260 * Playback Volume
261 *
262 * max : 0x3F (+15.0 dB)
263 * (1.5 dB step)
264 * min : 0x11 (-54.0 dB)
265 * mute : 0x10
266 * reserved : 0x00 - 0x0F
267 *
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900268 * Reserved area are considered as "mute".
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900269 */
Ashish Chavan7a0e67b2011-10-14 16:25:25 +0530270static const unsigned int hp_out_tlv[] = {
271 TLV_DB_RANGE_HEAD(2),
272 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
273 /* -54 dB to +15 dB */
274 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0),
275};
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900276
Ashish Chavan52082d82011-10-21 19:06:23 +0530277static const unsigned int lineout_vol_tlv[] = {
278 TLV_DB_RANGE_HEAD(2),
279 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
280 /* -54dB to 15dB */
281 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0)
282};
283
284static const unsigned int mono_vol_tlv[] = {
285 TLV_DB_RANGE_HEAD(2),
286 0x0, 0x2, TLV_DB_SCALE_ITEM(-1800, 0, 1),
287 /* -18dB to 6dB */
288 0x3, 0x7, TLV_DB_SCALE_ITEM(-1800, 600, 0)
289};
290
Ashish Chavan24b6f262012-01-02 17:35:52 +0530291static const unsigned int aux1_vol_tlv[] = {
292 TLV_DB_RANGE_HEAD(2),
293 0x0, 0x10, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
294 /* -48dB to 21dB */
295 0x11, 0x3f, TLV_DB_SCALE_ITEM(-4800, 150, 0)
296};
297
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530298static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
299static const DECLARE_TLV_DB_SCALE(adc_eq_master_gain_tlv, -1800, 600, 1);
Ashish Chavan52082d82011-10-21 19:06:23 +0530300static const DECLARE_TLV_DB_SCALE(dac_gain_tlv, -7725, 75, 0);
Ashish Chavan24b6f262012-01-02 17:35:52 +0530301static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, -600, 600, 0);
302static const DECLARE_TLV_DB_SCALE(aux2_vol_tlv, -600, 600, 0);
303static const DECLARE_TLV_DB_SCALE(inpga_gain_tlv, -450, 150, 0);
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530304
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530305/* ADC and DAC high pass filter f0 value */
Mark Brownf4034142011-11-09 23:15:26 +0000306static const char * const da7210_hpf_cutoff_txt[] = {
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530307 "Fs/8192*pi", "Fs/4096*pi", "Fs/2048*pi", "Fs/1024*pi"
308};
309
310static const struct soc_enum da7210_dac_hpf_cutoff =
311 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 0, 4, da7210_hpf_cutoff_txt);
312
313static const struct soc_enum da7210_adc_hpf_cutoff =
314 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 0, 4, da7210_hpf_cutoff_txt);
315
316/* ADC and DAC voice (8kHz) high pass cutoff value */
Mark Brownf4034142011-11-09 23:15:26 +0000317static const char * const da7210_vf_cutoff_txt[] = {
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530318 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
319};
320
321static const struct soc_enum da7210_dac_vf_cutoff =
322 SOC_ENUM_SINGLE(DA7210_DAC_HPF, 4, 8, da7210_vf_cutoff_txt);
323
324static const struct soc_enum da7210_adc_vf_cutoff =
325 SOC_ENUM_SINGLE(DA7210_ADC_HPF, 4, 8, da7210_vf_cutoff_txt);
326
Ashish Chavan5eda1942011-10-19 14:19:06 +0530327static const char *da7210_hp_mode_txt[] = {
328 "Class H", "Class G"
329};
330
331static const struct soc_enum da7210_hp_mode_sel =
332 SOC_ENUM_SINGLE(DA7210_HP_CFG, 0, 2, da7210_hp_mode_txt);
333
Ashish Chavande5eaf82011-10-19 14:24:37 +0530334/* ALC can be enabled only if noise suppression is disabled */
335static int da7210_put_alc_sw(struct snd_kcontrol *kcontrol,
336 struct snd_ctl_elem_value *ucontrol)
337{
338 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
339
340 if (ucontrol->value.integer.value[0]) {
341 /* Check if noise suppression is enabled */
342 if (snd_soc_read(codec, DA7210_CONTROL) & DA7210_NOISE_SUP_EN) {
343 dev_dbg(codec->dev,
344 "Disable noise suppression to enable ALC\n");
345 return -EINVAL;
346 }
347 }
348 /* If all conditions are met or we are actually disabling ALC */
349 return snd_soc_put_volsw(kcontrol, ucontrol);
350}
351
352/* Noise suppression can be enabled only if following conditions are met
353 * ALC disabled
354 * ZC enabled for HP and AUX1 PGA
355 * INPGA_L_VOL and INPGA_R_VOL >= 10.5 dB
356 * AUX1_L_VOL and AUX1_R_VOL >= 6 dB
357 */
358static int da7210_put_noise_sup_sw(struct snd_kcontrol *kcontrol,
359 struct snd_ctl_elem_value *ucontrol)
360{
361 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
362 u8 val;
363
364 if (ucontrol->value.integer.value[0]) {
365 /* Check if ALC is enabled */
366 if (snd_soc_read(codec, DA7210_ADC) & DA7210_ADC_ALC_EN)
367 goto err;
368
369 /* Check ZC for HP and AUX1 PGA */
370 if ((snd_soc_read(codec, DA7210_ZERO_CROSS) &
371 (DA7210_AUX1_L_ZC | DA7210_AUX1_R_ZC | DA7210_HP_L_ZC |
372 DA7210_HP_R_ZC)) != (DA7210_AUX1_L_ZC |
373 DA7210_AUX1_R_ZC | DA7210_HP_L_ZC | DA7210_HP_R_ZC))
374 goto err;
375
376 /* Check INPGA_L_VOL and INPGA_R_VOL */
377 val = snd_soc_read(codec, DA7210_IN_GAIN);
378 if (((val & DA7210_INPGA_L_VOL) < DA7210_INPGA_MIN_VOL_NS) ||
379 (((val & DA7210_INPGA_R_VOL) >> 4) <
380 DA7210_INPGA_MIN_VOL_NS))
381 goto err;
382
383 /* Check AUX1_L_VOL and AUX1_R_VOL */
384 if (((snd_soc_read(codec, DA7210_AUX1_L) & DA7210_AUX1_L_VOL) <
385 DA7210_AUX1_MIN_VOL_NS) ||
386 ((snd_soc_read(codec, DA7210_AUX1_R) & DA7210_AUX1_R_VOL) <
387 DA7210_AUX1_MIN_VOL_NS))
388 goto err;
389 }
390 /* If all conditions are met or we are actually disabling Noise sup */
391 return snd_soc_put_volsw(kcontrol, ucontrol);
392
393err:
394 return -EINVAL;
395}
396
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900397static const struct snd_kcontrol_new da7210_snd_controls[] = {
398
399 SOC_DOUBLE_R_TLV("HeadPhone Playback Volume",
400 DA7210_HP_L_VOL, DA7210_HP_R_VOL,
401 0, 0x3F, 0, hp_out_tlv),
Ashish Chavan52082d82011-10-21 19:06:23 +0530402 SOC_DOUBLE_R_TLV("Digital Playback Volume",
403 DA7210_DAC_L, DA7210_DAC_R,
404 0, 0x77, 1, dac_gain_tlv),
405 SOC_DOUBLE_R_TLV("Lineout Playback Volume",
406 DA7210_OUT1_L, DA7210_OUT1_R,
407 0, 0x3f, 0, lineout_vol_tlv),
408 SOC_SINGLE_TLV("Mono Playback Volume", DA7210_OUT2, 0, 0x7, 0,
409 mono_vol_tlv),
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530410
Ashish Chavan24b6f262012-01-02 17:35:52 +0530411 SOC_DOUBLE_R_TLV("Mic Capture Volume",
412 DA7210_MIC_L, DA7210_MIC_R,
413 0, 0x5, 0, mic_vol_tlv),
414 SOC_DOUBLE_R_TLV("Aux1 Capture Volume",
415 DA7210_AUX1_L, DA7210_AUX1_R,
416 0, 0x3f, 0, aux1_vol_tlv),
417 SOC_SINGLE_TLV("Aux2 Capture Volume", DA7210_AUX2, 0, 0x3, 0,
418 aux2_vol_tlv),
419 SOC_DOUBLE_TLV("In PGA Capture Volume", DA7210_IN_GAIN, 0, 4, 0xF, 0,
420 inpga_gain_tlv),
421
Ashish Chavan0ee6e9e2011-10-15 14:47:56 +0530422 /* DAC Equalizer controls */
423 SOC_SINGLE("DAC EQ Switch", DA7210_DAC_EQ5, 7, 1, 0),
424 SOC_SINGLE_TLV("DAC EQ1 Volume", DA7210_DAC_EQ1_2, 0, 0xf, 1,
425 eq_gain_tlv),
426 SOC_SINGLE_TLV("DAC EQ2 Volume", DA7210_DAC_EQ1_2, 4, 0xf, 1,
427 eq_gain_tlv),
428 SOC_SINGLE_TLV("DAC EQ3 Volume", DA7210_DAC_EQ3_4, 0, 0xf, 1,
429 eq_gain_tlv),
430 SOC_SINGLE_TLV("DAC EQ4 Volume", DA7210_DAC_EQ3_4, 4, 0xf, 1,
431 eq_gain_tlv),
432 SOC_SINGLE_TLV("DAC EQ5 Volume", DA7210_DAC_EQ5, 0, 0xf, 1,
433 eq_gain_tlv),
434
435 /* ADC Equalizer controls */
436 SOC_SINGLE("ADC EQ Switch", DA7210_ADC_EQ5, 7, 1, 0),
437 SOC_SINGLE_TLV("ADC EQ Master Volume", DA7210_ADC_EQ5, 4, 0x3,
438 1, adc_eq_master_gain_tlv),
439 SOC_SINGLE_TLV("ADC EQ1 Volume", DA7210_ADC_EQ1_2, 0, 0xf, 1,
440 eq_gain_tlv),
441 SOC_SINGLE_TLV("ADC EQ2 Volume", DA7210_ADC_EQ1_2, 4, 0xf, 1,
442 eq_gain_tlv),
443 SOC_SINGLE_TLV("ADC EQ3 Volume", DA7210_ADC_EQ3_4, 0, 0xf, 1,
444 eq_gain_tlv),
445 SOC_SINGLE_TLV("ADC EQ4 Volume", DA7210_ADC_EQ3_4, 4, 0xf, 1,
446 eq_gain_tlv),
447 SOC_SINGLE_TLV("ADC EQ5 Volume", DA7210_ADC_EQ5, 0, 0xf, 1,
448 eq_gain_tlv),
Ashish Chavan4ced2b92011-10-15 14:50:06 +0530449
450 SOC_SINGLE("DAC HPF Switch", DA7210_DAC_HPF, 3, 1, 0),
451 SOC_ENUM("DAC HPF Cutoff", da7210_dac_hpf_cutoff),
452 SOC_SINGLE("DAC Voice Mode Switch", DA7210_DAC_HPF, 7, 1, 0),
453 SOC_ENUM("DAC Voice Cutoff", da7210_dac_vf_cutoff),
454
455 SOC_SINGLE("ADC HPF Switch", DA7210_ADC_HPF, 3, 1, 0),
456 SOC_ENUM("ADC HPF Cutoff", da7210_adc_hpf_cutoff),
457 SOC_SINGLE("ADC Voice Mode Switch", DA7210_ADC_HPF, 7, 1, 0),
458 SOC_ENUM("ADC Voice Cutoff", da7210_adc_vf_cutoff),
Ashish Chavan5eda1942011-10-19 14:19:06 +0530459
460 /* Mute controls */
461 SOC_DOUBLE_R("Mic Capture Switch", DA7210_MIC_L, DA7210_MIC_R, 3, 1, 0),
462 SOC_SINGLE("Aux2 Capture Switch", DA7210_AUX2, 2, 1, 0),
463 SOC_DOUBLE("ADC Capture Switch", DA7210_ADC, 2, 6, 1, 0),
464 SOC_SINGLE("Digital Soft Mute Switch", DA7210_SOFTMUTE, 7, 1, 0),
465 SOC_SINGLE("Digital Soft Mute Rate", DA7210_SOFTMUTE, 0, 0x7, 0),
466
467 /* Zero cross controls */
468 SOC_DOUBLE("Aux1 ZC Switch", DA7210_ZERO_CROSS, 0, 1, 1, 0),
469 SOC_DOUBLE("In PGA ZC Switch", DA7210_ZERO_CROSS, 2, 3, 1, 0),
470 SOC_DOUBLE("Lineout ZC Switch", DA7210_ZERO_CROSS, 4, 5, 1, 0),
471 SOC_DOUBLE("Headphone ZC Switch", DA7210_ZERO_CROSS, 6, 7, 1, 0),
472
473 SOC_ENUM("Headphone Class", da7210_hp_mode_sel),
Ashish Chavande5eaf82011-10-19 14:24:37 +0530474
475 /* ALC controls */
476 SOC_SINGLE_EXT("ALC Enable Switch", DA7210_ADC, 0, 1, 0,
477 snd_soc_get_volsw, da7210_put_alc_sw),
478 SOC_SINGLE("ALC Capture Max Volume", DA7210_ALC_MAX, 0, 0x3F, 0),
479 SOC_SINGLE("ALC Capture Min Volume", DA7210_ALC_MIN, 0, 0x3F, 0),
480 SOC_SINGLE("ALC Capture Noise Volume", DA7210_ALC_NOIS, 0, 0x3F, 0),
481 SOC_SINGLE("ALC Capture Attack Rate", DA7210_ALC_ATT, 0, 0xFF, 0),
482 SOC_SINGLE("ALC Capture Release Rate", DA7210_ALC_REL, 0, 0xFF, 0),
483 SOC_SINGLE("ALC Capture Release Delay", DA7210_ALC_DEL, 0, 0xFF, 0),
484
485 SOC_SINGLE_EXT("Noise Suppression Enable Switch", DA7210_CONTROL, 3, 1,
486 0, snd_soc_get_volsw, da7210_put_noise_sup_sw),
Kuninori Morimotoa7e7cd52010-07-21 14:12:16 +0900487};
488
Ashish Chavan6950c602011-10-21 18:16:08 +0530489/*
490 * DAPM Controls
491 *
492 * Current DAPM implementation covers almost all codec components e.g. IOs,
493 * mixers, PGAs,ADC and DAC.
494 */
495/* In Mixer Left */
496static const struct snd_kcontrol_new da7210_dapm_inmixl_controls[] = {
497 SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_L, 0, 1, 0),
498 SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_L, 1, 1, 0),
Ashish Chavan24b6f262012-01-02 17:35:52 +0530499 SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_INMIX_L, 2, 1, 0),
500 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_L, 3, 1, 0),
501 SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_INMIX_L, 4, 1, 0),
Ashish Chavan6950c602011-10-21 18:16:08 +0530502};
503
504/* In Mixer Right */
505static const struct snd_kcontrol_new da7210_dapm_inmixr_controls[] = {
506 SOC_DAPM_SINGLE("Mic Right Switch", DA7210_INMIX_R, 0, 1, 0),
507 SOC_DAPM_SINGLE("Mic Left Switch", DA7210_INMIX_R, 1, 1, 0),
Ashish Chavan24b6f262012-01-02 17:35:52 +0530508 SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_INMIX_R, 2, 1, 0),
509 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_INMIX_R, 3, 1, 0),
510 SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_INMIX_R, 4, 1, 0),
Ashish Chavan6950c602011-10-21 18:16:08 +0530511};
512
513/* Out Mixer Left */
514static const struct snd_kcontrol_new da7210_dapm_outmixl_controls[] = {
Ashish Chavan24b6f262012-01-02 17:35:52 +0530515 SOC_DAPM_SINGLE("Aux1 Left Switch", DA7210_OUTMIX_L, 0, 1, 0),
516 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_L, 1, 1, 0),
517 SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_L, 2, 1, 0),
518 SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_L, 3, 1, 0),
Ashish Chavan6950c602011-10-21 18:16:08 +0530519 SOC_DAPM_SINGLE("DAC Left Switch", DA7210_OUTMIX_L, 4, 1, 0),
520};
521
522/* Out Mixer Right */
523static const struct snd_kcontrol_new da7210_dapm_outmixr_controls[] = {
Ashish Chavan24b6f262012-01-02 17:35:52 +0530524 SOC_DAPM_SINGLE("Aux1 Right Switch", DA7210_OUTMIX_R, 0, 1, 0),
525 SOC_DAPM_SINGLE("Aux2 Switch", DA7210_OUTMIX_R, 1, 1, 0),
526 SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUTMIX_R, 2, 1, 0),
527 SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUTMIX_R, 3, 1, 0),
Ashish Chavan6950c602011-10-21 18:16:08 +0530528 SOC_DAPM_SINGLE("DAC Right Switch", DA7210_OUTMIX_R, 4, 1, 0),
529};
530
Ashish Chavan52082d82011-10-21 19:06:23 +0530531/* Mono Mixer */
532static const struct snd_kcontrol_new da7210_dapm_monomix_controls[] = {
Ashish Chavan24b6f262012-01-02 17:35:52 +0530533 SOC_DAPM_SINGLE("INPGA Right Switch", DA7210_OUT2, 3, 1, 0),
534 SOC_DAPM_SINGLE("INPGA Left Switch", DA7210_OUT2, 4, 1, 0),
Ashish Chavan52082d82011-10-21 19:06:23 +0530535 SOC_DAPM_SINGLE("Outmix Right Switch", DA7210_OUT2, 5, 1, 0),
536 SOC_DAPM_SINGLE("Outmix Left Switch", DA7210_OUT2, 6, 1, 0),
537};
538
Ashish Chavan6950c602011-10-21 18:16:08 +0530539/* DAPM widgets */
540static const struct snd_soc_dapm_widget da7210_dapm_widgets[] = {
541 /* Input Side */
542 /* Input Lines */
543 SND_SOC_DAPM_INPUT("MICL"),
544 SND_SOC_DAPM_INPUT("MICR"),
Ashish Chavan24b6f262012-01-02 17:35:52 +0530545 SND_SOC_DAPM_INPUT("AUX1L"),
546 SND_SOC_DAPM_INPUT("AUX1R"),
547 SND_SOC_DAPM_INPUT("AUX2"),
Ashish Chavan6950c602011-10-21 18:16:08 +0530548
549 /* Input PGAs */
550 SND_SOC_DAPM_PGA("Mic Left", DA7210_STARTUP3, 0, 1, NULL, 0),
551 SND_SOC_DAPM_PGA("Mic Right", DA7210_STARTUP3, 1, 1, NULL, 0),
Ashish Chavan24b6f262012-01-02 17:35:52 +0530552 SND_SOC_DAPM_PGA("Aux1 Left", DA7210_STARTUP3, 2, 1, NULL, 0),
553 SND_SOC_DAPM_PGA("Aux1 Right", DA7210_STARTUP3, 3, 1, NULL, 0),
554 SND_SOC_DAPM_PGA("Aux2 Mono", DA7210_STARTUP3, 4, 1, NULL, 0),
Ashish Chavan6950c602011-10-21 18:16:08 +0530555
556 SND_SOC_DAPM_PGA("INPGA Left", DA7210_INMIX_L, 7, 0, NULL, 0),
557 SND_SOC_DAPM_PGA("INPGA Right", DA7210_INMIX_R, 7, 0, NULL, 0),
558
Ashish Chavan24b6f262012-01-02 17:35:52 +0530559 /* MICBIAS */
560 SND_SOC_DAPM_SUPPLY("Mic Bias", DA7210_MIC_L, 6, 0, NULL, 0),
561
Ashish Chavan6950c602011-10-21 18:16:08 +0530562 /* Input Mixers */
563 SND_SOC_DAPM_MIXER("In Mixer Left", SND_SOC_NOPM, 0, 0,
564 &da7210_dapm_inmixl_controls[0],
565 ARRAY_SIZE(da7210_dapm_inmixl_controls)),
566
567 SND_SOC_DAPM_MIXER("In Mixer Right", SND_SOC_NOPM, 0, 0,
568 &da7210_dapm_inmixr_controls[0],
569 ARRAY_SIZE(da7210_dapm_inmixr_controls)),
570
571 /* ADCs */
572 SND_SOC_DAPM_ADC("ADC Left", "Capture", DA7210_STARTUP3, 5, 1),
573 SND_SOC_DAPM_ADC("ADC Right", "Capture", DA7210_STARTUP3, 6, 1),
574
575 /* Output Side */
576 /* DACs */
577 SND_SOC_DAPM_DAC("DAC Left", "Playback", DA7210_STARTUP2, 5, 1),
578 SND_SOC_DAPM_DAC("DAC Right", "Playback", DA7210_STARTUP2, 6, 1),
579
580 /* Output Mixers */
581 SND_SOC_DAPM_MIXER("Out Mixer Left", SND_SOC_NOPM, 0, 0,
582 &da7210_dapm_outmixl_controls[0],
583 ARRAY_SIZE(da7210_dapm_outmixl_controls)),
584
585 SND_SOC_DAPM_MIXER("Out Mixer Right", SND_SOC_NOPM, 0, 0,
586 &da7210_dapm_outmixr_controls[0],
587 ARRAY_SIZE(da7210_dapm_outmixr_controls)),
588
Ashish Chavan52082d82011-10-21 19:06:23 +0530589 SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0,
590 &da7210_dapm_monomix_controls[0],
591 ARRAY_SIZE(da7210_dapm_monomix_controls)),
592
Ashish Chavan6950c602011-10-21 18:16:08 +0530593 /* Output PGAs */
594 SND_SOC_DAPM_PGA("OUTPGA Left Enable", DA7210_OUTMIX_L, 7, 0, NULL, 0),
595 SND_SOC_DAPM_PGA("OUTPGA Right Enable", DA7210_OUTMIX_R, 7, 0, NULL, 0),
596
Ashish Chavan52082d82011-10-21 19:06:23 +0530597 SND_SOC_DAPM_PGA("Out1 Left", DA7210_STARTUP2, 0, 1, NULL, 0),
598 SND_SOC_DAPM_PGA("Out1 Right", DA7210_STARTUP2, 1, 1, NULL, 0),
599 SND_SOC_DAPM_PGA("Out2 Mono", DA7210_STARTUP2, 2, 1, NULL, 0),
Ashish Chavan6950c602011-10-21 18:16:08 +0530600 SND_SOC_DAPM_PGA("Headphone Left", DA7210_STARTUP2, 3, 1, NULL, 0),
601 SND_SOC_DAPM_PGA("Headphone Right", DA7210_STARTUP2, 4, 1, NULL, 0),
602
603 /* Output Lines */
Ashish Chavan52082d82011-10-21 19:06:23 +0530604 SND_SOC_DAPM_OUTPUT("OUT1L"),
605 SND_SOC_DAPM_OUTPUT("OUT1R"),
Ashish Chavan6950c602011-10-21 18:16:08 +0530606 SND_SOC_DAPM_OUTPUT("HPL"),
607 SND_SOC_DAPM_OUTPUT("HPR"),
Ashish Chavan52082d82011-10-21 19:06:23 +0530608 SND_SOC_DAPM_OUTPUT("OUT2"),
Ashish Chavan6950c602011-10-21 18:16:08 +0530609};
610
611/* DAPM audio route definition */
612static const struct snd_soc_dapm_route da7210_audio_map[] = {
613 /* Dest Connecting Widget source */
614 /* Input path */
615 {"Mic Left", NULL, "MICL"},
616 {"Mic Right", NULL, "MICR"},
Ashish Chavan24b6f262012-01-02 17:35:52 +0530617 {"Aux1 Left", NULL, "AUX1L"},
618 {"Aux1 Right", NULL, "AUX1R"},
619 {"Aux2 Mono", NULL, "AUX2"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530620
621 {"In Mixer Left", "Mic Left Switch", "Mic Left"},
622 {"In Mixer Left", "Mic Right Switch", "Mic Right"},
Ashish Chavan24b6f262012-01-02 17:35:52 +0530623 {"In Mixer Left", "Aux1 Left Switch", "Aux1 Left"},
624 {"In Mixer Left", "Aux2 Switch", "Aux2 Mono"},
625 {"In Mixer Left", "Outmix Left Switch", "Out Mixer Left"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530626
627 {"In Mixer Right", "Mic Right Switch", "Mic Right"},
628 {"In Mixer Right", "Mic Left Switch", "Mic Left"},
Ashish Chavan24b6f262012-01-02 17:35:52 +0530629 {"In Mixer Right", "Aux1 Right Switch", "Aux1 Right"},
630 {"In Mixer Right", "Aux2 Switch", "Aux2 Mono"},
631 {"In Mixer Right", "Outmix Right Switch", "Out Mixer Right"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530632
633 {"INPGA Left", NULL, "In Mixer Left"},
634 {"ADC Left", NULL, "INPGA Left"},
635
636 {"INPGA Right", NULL, "In Mixer Right"},
637 {"ADC Right", NULL, "INPGA Right"},
638
639 /* Output path */
Ashish Chavan24b6f262012-01-02 17:35:52 +0530640 {"Out Mixer Left", "Aux1 Left Switch", "Aux1 Left"},
641 {"Out Mixer Left", "Aux2 Switch", "Aux2 Mono"},
642 {"Out Mixer Left", "INPGA Left Switch", "INPGA Left"},
643 {"Out Mixer Left", "INPGA Right Switch", "INPGA Right"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530644 {"Out Mixer Left", "DAC Left Switch", "DAC Left"},
Ashish Chavan24b6f262012-01-02 17:35:52 +0530645
646 {"Out Mixer Right", "Aux1 Right Switch", "Aux1 Right"},
647 {"Out Mixer Right", "Aux2 Switch", "Aux2 Mono"},
648 {"Out Mixer Right", "INPGA Right Switch", "INPGA Right"},
649 {"Out Mixer Right", "INPGA Left Switch", "INPGA Left"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530650 {"Out Mixer Right", "DAC Right Switch", "DAC Right"},
651
Ashish Chavan24b6f262012-01-02 17:35:52 +0530652 {"Mono Mixer", "INPGA Right Switch", "INPGA Right"},
653 {"Mono Mixer", "INPGA Left Switch", "INPGA Left"},
Ashish Chavan52082d82011-10-21 19:06:23 +0530654 {"Mono Mixer", "Outmix Right Switch", "Out Mixer Right"},
655 {"Mono Mixer", "Outmix Left Switch", "Out Mixer Left"},
656
Ashish Chavan6950c602011-10-21 18:16:08 +0530657 {"OUTPGA Left Enable", NULL, "Out Mixer Left"},
658 {"OUTPGA Right Enable", NULL, "Out Mixer Right"},
659
Ashish Chavan52082d82011-10-21 19:06:23 +0530660 {"Out1 Left", NULL, "OUTPGA Left Enable"},
661 {"OUT1L", NULL, "Out1 Left"},
662
663 {"Out1 Right", NULL, "OUTPGA Right Enable"},
664 {"OUT1R", NULL, "Out1 Right"},
665
Ashish Chavan6950c602011-10-21 18:16:08 +0530666 {"Headphone Left", NULL, "OUTPGA Left Enable"},
667 {"HPL", NULL, "Headphone Left"},
668
669 {"Headphone Right", NULL, "OUTPGA Right Enable"},
670 {"HPR", NULL, "Headphone Right"},
Ashish Chavan52082d82011-10-21 19:06:23 +0530671
672 {"Out2 Mono", NULL, "Mono Mixer"},
673 {"OUT2", NULL, "Out2 Mono"},
Ashish Chavan6950c602011-10-21 18:16:08 +0530674};
675
Kuninori Morimoto98615452009-12-14 13:21:56 +0900676/* Codec private data */
677struct da7210_priv {
Ashish Chavan33593b52012-03-08 19:04:56 +0530678 struct regmap *regmap;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530679 unsigned int mclk_rate;
680 int master;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900681};
682
Ashish Chavan33593b52012-03-08 19:04:56 +0530683static struct reg_default da7210_reg_defaults[] = {
Ashish Chavanaa0e25c2012-03-29 19:06:29 +0530684 { 0x00, 0x00 },
Ashish Chavan33593b52012-03-08 19:04:56 +0530685 { 0x01, 0x11 },
Ashish Chavan33593b52012-03-08 19:04:56 +0530686 { 0x03, 0x00 },
687 { 0x04, 0x00 },
688 { 0x05, 0x00 },
689 { 0x06, 0x00 },
690 { 0x07, 0x00 },
691 { 0x08, 0x00 },
692 { 0x09, 0x00 },
693 { 0x0a, 0x00 },
694 { 0x0b, 0x00 },
695 { 0x0c, 0x00 },
696 { 0x0d, 0x00 },
697 { 0x0e, 0x00 },
698 { 0x0f, 0x08 },
699 { 0x10, 0x00 },
700 { 0x11, 0x00 },
701 { 0x12, 0x00 },
702 { 0x13, 0x00 },
703 { 0x14, 0x08 },
704 { 0x15, 0x10 },
705 { 0x16, 0x10 },
706 { 0x17, 0x54 },
707 { 0x18, 0x40 },
708 { 0x19, 0x00 },
709 { 0x1a, 0x00 },
710 { 0x1b, 0x00 },
711 { 0x1c, 0x00 },
712 { 0x1d, 0x00 },
713 { 0x1e, 0x00 },
714 { 0x1f, 0x00 },
715 { 0x20, 0x00 },
716 { 0x21, 0x00 },
717 { 0x22, 0x00 },
718 { 0x23, 0x02 },
719 { 0x24, 0x00 },
720 { 0x25, 0x76 },
721 { 0x26, 0x00 },
722 { 0x27, 0x00 },
723 { 0x28, 0x04 },
724 { 0x29, 0x00 },
725 { 0x2a, 0x00 },
726 { 0x2b, 0x30 },
727 { 0x2c, 0x2A },
Ashish Chavan33593b52012-03-08 19:04:56 +0530728 { 0x83, 0x00 },
729 { 0x84, 0x00 },
730 { 0x85, 0x00 },
731 { 0x86, 0x00 },
732 { 0x87, 0x00 },
733 { 0x88, 0x00 },
Kuninori Morimoto98615452009-12-14 13:21:56 +0900734};
735
Ashish Chavan33593b52012-03-08 19:04:56 +0530736static bool da7210_readable_register(struct device *dev, unsigned int reg)
737{
738 switch (reg) {
739 case DA7210_A_HID_UNLOCK:
740 case DA7210_A_TEST_UNLOCK:
741 case DA7210_A_PLL1:
742 case DA7210_A_CP_MODE:
743 return false;
744 default:
745 return true;
746 }
747}
748
749static bool da7210_volatile_register(struct device *dev,
Axel Lin40a49712011-10-12 07:16:25 +0800750 unsigned int reg)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900751{
Axel Lin40a49712011-10-12 07:16:25 +0800752 switch (reg) {
753 case DA7210_STATUS:
Ashish Chavan33593b52012-03-08 19:04:56 +0530754 return true;
Axel Lin40a49712011-10-12 07:16:25 +0800755 default:
Ashish Chavan33593b52012-03-08 19:04:56 +0530756 return false;
Axel Lin40a49712011-10-12 07:16:25 +0800757 }
Kuninori Morimoto98615452009-12-14 13:21:56 +0900758}
Kuninori Morimoto98615452009-12-14 13:21:56 +0900759
760/*
761 * Set PCM DAI word length.
762 */
763static int da7210_hw_params(struct snd_pcm_substream *substream,
764 struct snd_pcm_hw_params *params,
765 struct snd_soc_dai *dai)
766{
Mark Browne6968a12012-04-04 15:58:16 +0100767 struct snd_soc_codec *codec = dai->codec;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530768 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900769 u32 dai_cfg1;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530770 u32 fs, sysclk;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900771
772 /* set DAI source to Left and Right ADC */
Axel Lin40a49712011-10-12 07:16:25 +0800773 snd_soc_write(codec, DA7210_DAI_SRC_SEL,
Kuninori Morimoto98615452009-12-14 13:21:56 +0900774 DA7210_DAI_OUT_R_SRC | DA7210_DAI_OUT_L_SRC);
775
776 /* Enable DAI */
Axel Lin40a49712011-10-12 07:16:25 +0800777 snd_soc_write(codec, DA7210_DAI_CFG3, DA7210_DAI_OE | DA7210_DAI_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900778
Axel Lin40a49712011-10-12 07:16:25 +0800779 dai_cfg1 = 0xFC & snd_soc_read(codec, DA7210_DAI_CFG1);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900780
781 switch (params_format(params)) {
782 case SNDRV_PCM_FORMAT_S16_LE:
783 dai_cfg1 |= DA7210_DAI_WORD_S16_LE;
784 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530785 case SNDRV_PCM_FORMAT_S20_3LE:
786 dai_cfg1 |= DA7210_DAI_WORD_S20_3LE;
787 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900788 case SNDRV_PCM_FORMAT_S24_LE:
789 dai_cfg1 |= DA7210_DAI_WORD_S24_LE;
790 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530791 case SNDRV_PCM_FORMAT_S32_LE:
792 dai_cfg1 |= DA7210_DAI_WORD_S32_LE;
793 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900794 default:
795 return -EINVAL;
796 }
797
Axel Lin40a49712011-10-12 07:16:25 +0800798 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900799
Kuninori Morimoto98615452009-12-14 13:21:56 +0900800 switch (params_rate(params)) {
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900801 case 8000:
802 fs = DA7210_PLL_FS_8000;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530803 sysclk = 3072000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900804 break;
805 case 11025:
806 fs = DA7210_PLL_FS_11025;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530807 sysclk = 2822400;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900808 break;
809 case 12000:
810 fs = DA7210_PLL_FS_12000;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530811 sysclk = 3072000;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900812 break;
813 case 16000:
814 fs = DA7210_PLL_FS_16000;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530815 sysclk = 3072000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900816 break;
817 case 22050:
818 fs = DA7210_PLL_FS_22050;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530819 sysclk = 2822400;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900820 break;
821 case 32000:
822 fs = DA7210_PLL_FS_32000;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530823 sysclk = 3072000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900824 break;
825 case 44100:
826 fs = DA7210_PLL_FS_44100;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530827 sysclk = 2822400;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900828 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900829 case 48000:
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900830 fs = DA7210_PLL_FS_48000;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530831 sysclk = 3072000;
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900832 break;
833 case 88200:
834 fs = DA7210_PLL_FS_88200;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530835 sysclk = 2822400;
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900836 break;
837 case 96000:
838 fs = DA7210_PLL_FS_96000;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530839 sysclk = 3072000;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900840 break;
841 default:
842 return -EINVAL;
843 }
844
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900845 /* Disable active mode */
846 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
847
Kuninori Morimoto3a9d6202010-03-01 10:10:43 +0900848 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900849
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530850 if (da7210->mclk_rate && (da7210->mclk_rate != sysclk)) {
851 /* PLL mode, disable PLL bypass */
852 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, 0);
853 } else {
854 /* PLL bypass mode, enable PLL bypass */
855 snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP,
856 DA7210_PLL_BYP);
857 }
Kuninori Morimoto960b3b42010-03-11 11:37:44 +0900858 /* Enable active mode */
859 snd_soc_update_bits(codec, DA7210_STARTUP1,
860 DA7210_SC_MST_EN, DA7210_SC_MST_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900861
862 return 0;
863}
864
865/*
866 * Set DAI mode and Format
867 */
868static int da7210_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
869{
870 struct snd_soc_codec *codec = codec_dai->codec;
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530871 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900872 u32 dai_cfg1;
873 u32 dai_cfg3;
874
Axel Lin40a49712011-10-12 07:16:25 +0800875 dai_cfg1 = 0x7f & snd_soc_read(codec, DA7210_DAI_CFG1);
876 dai_cfg3 = 0xfc & snd_soc_read(codec, DA7210_DAI_CFG3);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900877
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530878 if ((snd_soc_read(codec, DA7210_PLL) & DA7210_PLL_EN) &&
879 (!(snd_soc_read(codec, DA7210_PLL_DIV3) & DA7210_PLL_BYP)))
880 return -EINVAL;
881
Kuninori Morimoto98615452009-12-14 13:21:56 +0900882 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
883 case SND_SOC_DAIFMT_CBM_CFM:
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530884 da7210->master = 1;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900885 dai_cfg1 |= DA7210_DAI_MODE_MASTER;
886 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530887 case SND_SOC_DAIFMT_CBS_CFS:
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530888 da7210->master = 0;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530889 dai_cfg1 |= DA7210_DAI_MODE_SLAVE;
890 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900891 default:
892 return -EINVAL;
893 }
894
895 /* FIXME
896 *
897 * It support I2S only now
898 */
899 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
900 case SND_SOC_DAIFMT_I2S:
901 dai_cfg3 |= DA7210_DAI_FORMAT_I2SMODE;
902 break;
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530903 case SND_SOC_DAIFMT_LEFT_J:
904 dai_cfg3 |= DA7210_DAI_FORMAT_LEFT_J;
905 break;
906 case SND_SOC_DAIFMT_RIGHT_J:
907 dai_cfg3 |= DA7210_DAI_FORMAT_RIGHT_J;
908 break;
Kuninori Morimoto98615452009-12-14 13:21:56 +0900909 default:
910 return -EINVAL;
911 }
912
913 /* FIXME
914 *
915 * It support 64bit data transmission only now
916 */
917 dai_cfg1 |= DA7210_DAI_FLEN_64BIT;
918
Axel Lin40a49712011-10-12 07:16:25 +0800919 snd_soc_write(codec, DA7210_DAI_CFG1, dai_cfg1);
920 snd_soc_write(codec, DA7210_DAI_CFG3, dai_cfg3);
Kuninori Morimoto98615452009-12-14 13:21:56 +0900921
922 return 0;
923}
924
Ashish Chavan5eda1942011-10-19 14:19:06 +0530925static int da7210_mute(struct snd_soc_dai *dai, int mute)
926{
927 struct snd_soc_codec *codec = dai->codec;
928 u8 mute_reg = snd_soc_read(codec, DA7210_DAC_HPF) & 0xFB;
929
930 if (mute)
931 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg | 0x4);
932 else
933 snd_soc_write(codec, DA7210_DAC_HPF, mute_reg);
934 return 0;
935}
936
Ashish Chavan0f8ea582011-10-12 20:33:21 +0530937#define DA7210_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
938 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
Kuninori Morimoto98615452009-12-14 13:21:56 +0900939
Ashish Chavan570aa7b2012-04-17 18:04:06 +0530940static int da7210_set_dai_sysclk(struct snd_soc_dai *codec_dai,
941 int clk_id, unsigned int freq, int dir)
942{
943 struct snd_soc_codec *codec = codec_dai->codec;
944 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
945
946 switch (clk_id) {
947 case DA7210_CLKSRC_MCLK:
948 switch (freq) {
949 case 12000000:
950 case 13000000:
951 case 13500000:
952 case 14400000:
953 case 19200000:
954 case 19680000:
955 case 19800000:
956 da7210->mclk_rate = freq;
957 return 0;
958 default:
959 dev_err(codec_dai->dev, "Unsupported MCLK value %d\n",
960 freq);
961 return -EINVAL;
962 }
963 break;
964 default:
965 dev_err(codec_dai->dev, "Unknown clock source %d\n", clk_id);
966 return -EINVAL;
967 }
968}
969
970/**
971 * da7210_set_dai_pll :Configure the codec PLL
972 * @param codec_dai : pointer to codec DAI
973 * @param pll_id : da7210 has only one pll, so pll_id is always zero
974 * @param fref : MCLK frequency, should be < 20MHz
975 * @param fout : FsDM value, Refer page 44 & 45 of datasheet
976 * @return int : Zero for success, negative error code for error
977 *
978 * Note: Supported PLL input frequencies are 12MHz, 13MHz, 13.5MHz, 14.4MHz,
979 * 19.2MHz, 19.6MHz and 19.8MHz
980 */
981static int da7210_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
982 int source, unsigned int fref, unsigned int fout)
983{
984 struct snd_soc_codec *codec = codec_dai->codec;
985 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
986
987 u8 pll_div1, pll_div2, pll_div3, cnt;
988
989 /* In slave mode, there is only one set of divisors */
990 if (!da7210->master)
991 fout = 2822400;
992
993 /* Search pll div array for correct divisors */
994 for (cnt = 0; cnt < ARRAY_SIZE(da7210_pll_div); cnt++) {
Ashish Chavanc4b14e72012-04-17 21:07:44 +0530995 /* check fref, mode and fout */
996 if ((fref == da7210_pll_div[cnt].fref) &&
997 (da7210->master == da7210_pll_div[cnt].mode) &&
998 (fout == da7210_pll_div[cnt].fout)) {
999 /* all match, pick up divisors */
1000 pll_div1 = da7210_pll_div[cnt].div1;
1001 pll_div2 = da7210_pll_div[cnt].div2;
1002 pll_div3 = da7210_pll_div[cnt].div3;
1003 break;
Ashish Chavan570aa7b2012-04-17 18:04:06 +05301004 }
1005 }
1006 if (cnt >= ARRAY_SIZE(da7210_pll_div))
1007 goto err;
1008
1009 /* Disable active mode */
1010 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
1011 /* Write PLL dividers */
1012 snd_soc_write(codec, DA7210_PLL_DIV1, pll_div1);
1013 snd_soc_write(codec, DA7210_PLL_DIV2, pll_div2);
1014 snd_soc_update_bits(codec, DA7210_PLL_DIV3,
1015 DA7210_PLL_DIV_L_MASK, pll_div3);
1016
1017 if (da7210->master) {
1018 /* In master mode, no need to enable SRM */
1019 snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN,
1020 DA7210_PLL_EN);
1021 } else {
1022 /* In slave mode, enable SRM and PLL */
1023 snd_soc_update_bits(codec, DA7210_PLL,
1024 (DA7210_PLL_EN | DA7210_MCLK_SRM_EN |
1025 DA7210_MCLK_DET_EN),
1026 (DA7210_PLL_EN | DA7210_MCLK_SRM_EN |
1027 DA7210_MCLK_DET_EN));
1028 }
1029 /* Enable active mode */
1030 snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN,
1031 DA7210_SC_MST_EN);
1032 return 0;
1033err:
1034 dev_err(codec_dai->dev, "Unsupported PLL input frequency %d\n", fref);
1035 return -EINVAL;
1036}
1037
Kuninori Morimoto98615452009-12-14 13:21:56 +09001038/* DAI operations */
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001039static const struct snd_soc_dai_ops da7210_dai_ops = {
Kuninori Morimoto98615452009-12-14 13:21:56 +09001040 .hw_params = da7210_hw_params,
1041 .set_fmt = da7210_set_dai_fmt,
Ashish Chavan570aa7b2012-04-17 18:04:06 +05301042 .set_sysclk = da7210_set_dai_sysclk,
1043 .set_pll = da7210_set_dai_pll,
Ashish Chavan5eda1942011-10-19 14:19:06 +05301044 .digital_mute = da7210_mute,
Kuninori Morimoto98615452009-12-14 13:21:56 +09001045};
1046
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001047static struct snd_soc_dai_driver da7210_dai = {
1048 .name = "da7210-hifi",
Kuninori Morimoto98615452009-12-14 13:21:56 +09001049 /* playback capabilities */
1050 .playback = {
1051 .stream_name = "Playback",
1052 .channels_min = 1,
1053 .channels_max = 2,
1054 .rates = SNDRV_PCM_RATE_8000_96000,
1055 .formats = DA7210_FORMATS,
1056 },
1057 /* capture capabilities */
1058 .capture = {
1059 .stream_name = "Capture",
1060 .channels_min = 1,
1061 .channels_max = 2,
1062 .rates = SNDRV_PCM_RATE_8000_96000,
1063 .formats = DA7210_FORMATS,
1064 },
1065 .ops = &da7210_dai_ops,
Kuninori Morimoto960b3b42010-03-11 11:37:44 +09001066 .symmetric_rates = 1,
Kuninori Morimoto98615452009-12-14 13:21:56 +09001067};
Kuninori Morimoto98615452009-12-14 13:21:56 +09001068
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001069static int da7210_probe(struct snd_soc_codec *codec)
Kuninori Morimoto98615452009-12-14 13:21:56 +09001070{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001071 struct da7210_priv *da7210 = snd_soc_codec_get_drvdata(codec);
Axel Lin40a49712011-10-12 07:16:25 +08001072 int ret;
Kuninori Morimoto98615452009-12-14 13:21:56 +09001073
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001074 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001075
Ashish Chavan33593b52012-03-08 19:04:56 +05301076 codec->control_data = da7210->regmap;
1077 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
Axel Lin40a49712011-10-12 07:16:25 +08001078 if (ret < 0) {
1079 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1080 return ret;
1081 }
Kuninori Morimoto98615452009-12-14 13:21:56 +09001082
Ashish Chavan570aa7b2012-04-17 18:04:06 +05301083 da7210->mclk_rate = 0; /* This will be set from set_sysclk() */
1084 da7210->master = 0; /* This will be set from set_fmt() */
1085
1086 /* Enable internal regulator & bias current */
1087 snd_soc_write(codec, DA7210_CONTROL, DA7210_REG_EN | DA7210_BIAS_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001088
1089 /*
1090 * ADC settings
1091 */
1092
1093 /* Enable Left & Right MIC PGA and Mic Bias */
Axel Lin40a49712011-10-12 07:16:25 +08001094 snd_soc_write(codec, DA7210_MIC_L, DA7210_MIC_L_EN | DA7210_MICBIAS_EN);
1095 snd_soc_write(codec, DA7210_MIC_R, DA7210_MIC_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001096
1097 /* Enable Left and Right input PGA */
Axel Lin40a49712011-10-12 07:16:25 +08001098 snd_soc_write(codec, DA7210_INMIX_L, DA7210_IN_L_EN);
1099 snd_soc_write(codec, DA7210_INMIX_R, DA7210_IN_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001100
1101 /* Enable Left and Right ADC */
Axel Lin40a49712011-10-12 07:16:25 +08001102 snd_soc_write(codec, DA7210_ADC, DA7210_ADC_L_EN | DA7210_ADC_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001103
1104 /*
1105 * DAC settings
1106 */
1107
1108 /* Enable Left and Right DAC */
Axel Lin40a49712011-10-12 07:16:25 +08001109 snd_soc_write(codec, DA7210_DAC_SEL,
Kuninori Morimoto98615452009-12-14 13:21:56 +09001110 DA7210_DAC_L_SRC_DAI_L | DA7210_DAC_L_EN |
1111 DA7210_DAC_R_SRC_DAI_R | DA7210_DAC_R_EN);
1112
1113 /* Enable Left and Right out PGA */
Axel Lin40a49712011-10-12 07:16:25 +08001114 snd_soc_write(codec, DA7210_OUTMIX_L, DA7210_OUT_L_EN);
1115 snd_soc_write(codec, DA7210_OUTMIX_R, DA7210_OUT_R_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001116
1117 /* Enable Left and Right HeadPhone PGA */
Axel Lin40a49712011-10-12 07:16:25 +08001118 snd_soc_write(codec, DA7210_HP_CFG,
Kuninori Morimoto98615452009-12-14 13:21:56 +09001119 DA7210_HP_2CAP_MODE | DA7210_HP_SENSE_EN |
1120 DA7210_HP_L_EN | DA7210_HP_MODE | DA7210_HP_R_EN);
1121
Ashish Chavan5eda1942011-10-19 14:19:06 +05301122 /* Enable ramp mode for DAC gain update */
1123 snd_soc_write(codec, DA7210_SOFTMUTE, DA7210_RAMP_EN);
1124
Ashish Chavan52082d82011-10-21 19:06:23 +05301125 /*
1126 * For DA7210 codec, there are two ways to enable/disable analog IOs
1127 * and ADC/DAC,
1128 * (1) Using "Enable Bit" of register associated with that IO
1129 * (or ADC/DAC)
1130 * e.g. Mic Left can be enabled using bit 7 of MIC_L(0x7) reg
1131 *
1132 * (2) Using "Standby Bit" of STARTUP2 or STARTUP3 register
1133 * e.g. Mic left can be put to STANDBY using bit 0 of STARTUP3(0x5)
1134 *
1135 * Out of these two methods, the one using STANDBY bits is preferred
1136 * way to enable/disable individual blocks. This is because STANDBY
1137 * registers are part of system controller which allows system power
1138 * up/down in a controlled, pop-free manner. Also, as per application
1139 * note of DA7210, STANDBY register bits are only effective if a
1140 * particular IO (or ADC/DAC) is already enabled using enable/disable
1141 * register bits. Keeping these things in mind, current DAPM
1142 * implementation manipulates only STANDBY bits.
1143 *
1144 * Overall implementation can be outlined as below,
1145 *
1146 * - "Enable bit" of an IO or ADC/DAC is used to enable it in probe()
1147 * - "STANDBY bit" is controlled by DAPM
1148 */
1149
1150 /* Enable Line out amplifiers */
1151 snd_soc_write(codec, DA7210_OUT1_L, DA7210_OUT1_L_EN);
1152 snd_soc_write(codec, DA7210_OUT1_R, DA7210_OUT1_R_EN);
1153 snd_soc_write(codec, DA7210_OUT2, DA7210_OUT2_EN |
1154 DA7210_OUT2_OUTMIX_L | DA7210_OUT2_OUTMIX_R);
1155
Ashish Chavan24b6f262012-01-02 17:35:52 +05301156 /* Enable Aux1 */
1157 snd_soc_write(codec, DA7210_AUX1_L, DA7210_AUX1_L_EN);
1158 snd_soc_write(codec, DA7210_AUX1_R, DA7210_AUX1_R_EN);
1159 /* Enable Aux2 */
1160 snd_soc_write(codec, DA7210_AUX2, DA7210_AUX2_EN);
1161
Ashish Chavan570aa7b2012-04-17 18:04:06 +05301162 /* Set PLL Master clock range 10-20 MHz */
1163 snd_soc_write(codec, DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ);
1164
Kuninori Morimoto98615452009-12-14 13:21:56 +09001165 /* Diable PLL and bypass it */
Axel Lin40a49712011-10-12 07:16:25 +08001166 snd_soc_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001167
Kuninori Morimoto98615452009-12-14 13:21:56 +09001168 /* Activate all enabled subsystem */
Axel Lin40a49712011-10-12 07:16:25 +08001169 snd_soc_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001170
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001171 dev_info(codec->dev, "DA7210 Audio Codec %s\n", DA7210_VERSION);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001172
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001173 return 0;
Kuninori Morimoto98615452009-12-14 13:21:56 +09001174}
1175
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001176static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +09001177 .probe = da7210_probe,
Mark Browna6f096f2011-10-14 20:18:49 +01001178
1179 .controls = da7210_snd_controls,
1180 .num_controls = ARRAY_SIZE(da7210_snd_controls),
Ashish Chavan6950c602011-10-21 18:16:08 +05301181
1182 .dapm_widgets = da7210_dapm_widgets,
1183 .num_dapm_widgets = ARRAY_SIZE(da7210_dapm_widgets),
1184 .dapm_routes = da7210_audio_map,
1185 .num_dapm_routes = ARRAY_SIZE(da7210_audio_map),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001186};
1187
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301188#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1189
1190static struct reg_default da7210_regmap_i2c_patch[] = {
1191
1192 /* System controller master disable */
1193 { DA7210_STARTUP1, 0x00 },
1194 /* make sure that DA7210 use bypass mode before start up */
1195 { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP },
1196
1197 /* to unlock */
1198 { DA7210_A_HID_UNLOCK, 0x8B},
1199 { DA7210_A_TEST_UNLOCK, 0xB4},
1200 { DA7210_A_PLL1, 0x01},
1201 { DA7210_A_CP_MODE, 0x7C},
1202 /* to re-lock */
1203 { DA7210_A_HID_UNLOCK, 0x00},
1204 { DA7210_A_TEST_UNLOCK, 0x00},
1205};
1206
1207static const struct regmap_config da7210_regmap_config_i2c = {
Ashish Chavan33593b52012-03-08 19:04:56 +05301208 .reg_bits = 8,
1209 .val_bits = 8,
1210
1211 .reg_defaults = da7210_reg_defaults,
1212 .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
1213 .volatile_reg = da7210_volatile_register,
1214 .readable_reg = da7210_readable_register,
1215 .cache_type = REGCACHE_RBTREE,
1216};
1217
Mark Brown735fe4c2010-01-12 14:13:00 +00001218static int __devinit da7210_i2c_probe(struct i2c_client *i2c,
1219 const struct i2c_device_id *id)
Kuninori Morimoto98615452009-12-14 13:21:56 +09001220{
1221 struct da7210_priv *da7210;
Kuninori Morimoto98615452009-12-14 13:21:56 +09001222 int ret;
1223
Axel Lin306bf6b2011-12-26 20:54:04 +08001224 da7210 = devm_kzalloc(&i2c->dev, sizeof(struct da7210_priv),
1225 GFP_KERNEL);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001226 if (!da7210)
1227 return -ENOMEM;
1228
Kuninori Morimoto98615452009-12-14 13:21:56 +09001229 i2c_set_clientdata(i2c, da7210);
Ashish Chavan33593b52012-03-08 19:04:56 +05301230
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301231 da7210->regmap = regmap_init_i2c(i2c, &da7210_regmap_config_i2c);
Ashish Chavan33593b52012-03-08 19:04:56 +05301232 if (IS_ERR(da7210->regmap)) {
1233 ret = PTR_ERR(da7210->regmap);
1234 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
1235 return ret;
1236 }
Kuninori Morimoto98615452009-12-14 13:21:56 +09001237
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301238 ret = regmap_register_patch(da7210->regmap, da7210_regmap_i2c_patch,
1239 ARRAY_SIZE(da7210_regmap_i2c_patch));
1240 if (ret != 0)
1241 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret);
1242
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001243 ret = snd_soc_register_codec(&i2c->dev,
1244 &soc_codec_dev_da7210, &da7210_dai, 1);
Ashish Chavan33593b52012-03-08 19:04:56 +05301245 if (ret < 0) {
1246 dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
1247 goto err_regmap;
1248 }
1249 return ret;
1250
1251err_regmap:
1252 regmap_exit(da7210->regmap);
1253
Kuninori Morimoto98615452009-12-14 13:21:56 +09001254 return ret;
1255}
1256
Mark Brown735fe4c2010-01-12 14:13:00 +00001257static int __devexit da7210_i2c_remove(struct i2c_client *client)
Kuninori Morimoto98615452009-12-14 13:21:56 +09001258{
Ashish Chavan33593b52012-03-08 19:04:56 +05301259 struct da7210_priv *da7210 = i2c_get_clientdata(client);
1260
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001261 snd_soc_unregister_codec(&client->dev);
Ashish Chavan33593b52012-03-08 19:04:56 +05301262 regmap_exit(da7210->regmap);
Kuninori Morimoto98615452009-12-14 13:21:56 +09001263 return 0;
1264}
1265
1266static const struct i2c_device_id da7210_i2c_id[] = {
1267 { "da7210", 0 },
1268 { }
1269};
1270MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
1271
1272/* I2C codec control layer */
1273static struct i2c_driver da7210_i2c_driver = {
1274 .driver = {
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301275 .name = "da7210",
Kuninori Morimoto98615452009-12-14 13:21:56 +09001276 .owner = THIS_MODULE,
1277 },
Kuninori Morimoto4c62ed92010-09-16 13:07:06 +09001278 .probe = da7210_i2c_probe,
1279 .remove = __devexit_p(da7210_i2c_remove),
1280 .id_table = da7210_i2c_id,
Kuninori Morimoto98615452009-12-14 13:21:56 +09001281};
1282#endif
1283
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301284#if defined(CONFIG_SPI_MASTER)
1285
1286static struct reg_default da7210_regmap_spi_patch[] = {
1287 /* Dummy read to give two pulses over nCS for SPI */
1288 { DA7210_AUX2, 0x00 },
1289 { DA7210_AUX2, 0x00 },
1290
1291 /* System controller master disable */
1292 { DA7210_STARTUP1, 0x00 },
1293 /* make sure that DA7210 use bypass mode before start up */
1294 { DA7210_PLL_DIV3, DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP },
1295
1296 /* to set PAGE1 of SPI register space */
1297 { DA7210_PAGE_CONTROL, 0x80 },
1298 /* to unlock */
1299 { DA7210_A_HID_UNLOCK, 0x8B},
1300 { DA7210_A_TEST_UNLOCK, 0xB4},
1301 { DA7210_A_PLL1, 0x01},
1302 { DA7210_A_CP_MODE, 0x7C},
1303 /* to re-lock */
1304 { DA7210_A_HID_UNLOCK, 0x00},
1305 { DA7210_A_TEST_UNLOCK, 0x00},
1306 /* to set back PAGE0 of SPI register space */
1307 { DA7210_PAGE_CONTROL, 0x00 },
1308};
1309
1310static const struct regmap_config da7210_regmap_config_spi = {
1311 .reg_bits = 8,
1312 .val_bits = 8,
1313 .read_flag_mask = 0x01,
1314 .write_flag_mask = 0x00,
1315
1316 .reg_defaults = da7210_reg_defaults,
1317 .num_reg_defaults = ARRAY_SIZE(da7210_reg_defaults),
1318 .volatile_reg = da7210_volatile_register,
1319 .readable_reg = da7210_readable_register,
1320 .cache_type = REGCACHE_RBTREE,
1321};
1322
1323static int __devinit da7210_spi_probe(struct spi_device *spi)
1324{
1325 struct da7210_priv *da7210;
1326 int ret;
1327
1328 da7210 = devm_kzalloc(&spi->dev, sizeof(struct da7210_priv),
1329 GFP_KERNEL);
1330 if (!da7210)
1331 return -ENOMEM;
1332
1333 spi_set_drvdata(spi, da7210);
1334 da7210->regmap = devm_regmap_init_spi(spi, &da7210_regmap_config_spi);
1335 if (IS_ERR(da7210->regmap)) {
1336 ret = PTR_ERR(da7210->regmap);
1337 dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
1338 return ret;
1339 }
1340
1341 ret = regmap_register_patch(da7210->regmap, da7210_regmap_spi_patch,
1342 ARRAY_SIZE(da7210_regmap_spi_patch));
1343 if (ret != 0)
1344 dev_warn(&spi->dev, "Failed to apply regmap patch: %d\n", ret);
1345
1346 ret = snd_soc_register_codec(&spi->dev,
1347 &soc_codec_dev_da7210, &da7210_dai, 1);
1348 if (ret < 0)
1349 goto err_regmap;
1350
1351 return ret;
1352
1353err_regmap:
1354 regmap_exit(da7210->regmap);
1355
1356 return ret;
1357}
1358
1359static int __devexit da7210_spi_remove(struct spi_device *spi)
1360{
1361 struct da7210_priv *da7210 = spi_get_drvdata(spi);
1362 snd_soc_unregister_codec(&spi->dev);
1363 regmap_exit(da7210->regmap);
1364 return 0;
1365}
1366
1367static struct spi_driver da7210_spi_driver = {
1368 .driver = {
1369 .name = "da7210",
1370 .owner = THIS_MODULE,
1371 },
1372 .probe = da7210_spi_probe,
1373 .remove = __devexit_p(da7210_spi_remove)
1374};
1375#endif
1376
Kuninori Morimoto98615452009-12-14 13:21:56 +09001377static int __init da7210_modinit(void)
1378{
1379 int ret = 0;
1380#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1381 ret = i2c_add_driver(&da7210_i2c_driver);
1382#endif
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301383#if defined(CONFIG_SPI_MASTER)
1384 ret = spi_register_driver(&da7210_spi_driver);
1385 if (ret) {
1386 printk(KERN_ERR "Failed to register da7210 SPI driver: %d\n",
1387 ret);
1388 }
1389#endif
Kuninori Morimoto98615452009-12-14 13:21:56 +09001390 return ret;
1391}
1392module_init(da7210_modinit);
1393
1394static void __exit da7210_exit(void)
1395{
1396#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1397 i2c_del_driver(&da7210_i2c_driver);
1398#endif
Ashish Chavanaa0e25c2012-03-29 19:06:29 +05301399#if defined(CONFIG_SPI_MASTER)
1400 spi_unregister_driver(&da7210_spi_driver);
1401#endif
Kuninori Morimoto98615452009-12-14 13:21:56 +09001402}
1403module_exit(da7210_exit);
1404
1405MODULE_DESCRIPTION("ASoC DA7210 driver");
1406MODULE_AUTHOR("David Chen, Kuninori Morimoto");
1407MODULE_LICENSE("GPL");