blob: 27c44547b829a9fc104b15518121de13cd17eb37 [file] [log] [blame]
Ashish Chavan9911f7f2012-09-21 20:16:17 +05301/*
2 * DA9055 ALSA Soc codec driver
3 *
4 * Copyright (c) 2012 Dialog Semiconductor
5 *
6 * Tested on (Samsung SMDK6410 board + DA9055 EVB) using I2S and I2C
7 * Written by David Chen <david.chen@diasemi.com> and
8 * Ashish Chavan <ashish.chavan@kpitcummins.com>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 */
15
16#include <linux/delay.h>
17#include <linux/i2c.h>
18#include <linux/regmap.h>
19#include <linux/slab.h>
20#include <linux/module.h>
21#include <sound/pcm.h>
22#include <sound/pcm_params.h>
23#include <sound/soc.h>
24#include <sound/initval.h>
25#include <sound/tlv.h>
26#include <sound/da9055.h>
27
28/* DA9055 register space */
29
30/* Status Registers */
31#define DA9055_STATUS1 0x02
32#define DA9055_PLL_STATUS 0x03
33#define DA9055_AUX_L_GAIN_STATUS 0x04
34#define DA9055_AUX_R_GAIN_STATUS 0x05
35#define DA9055_MIC_L_GAIN_STATUS 0x06
36#define DA9055_MIC_R_GAIN_STATUS 0x07
37#define DA9055_MIXIN_L_GAIN_STATUS 0x08
38#define DA9055_MIXIN_R_GAIN_STATUS 0x09
39#define DA9055_ADC_L_GAIN_STATUS 0x0A
40#define DA9055_ADC_R_GAIN_STATUS 0x0B
41#define DA9055_DAC_L_GAIN_STATUS 0x0C
42#define DA9055_DAC_R_GAIN_STATUS 0x0D
43#define DA9055_HP_L_GAIN_STATUS 0x0E
44#define DA9055_HP_R_GAIN_STATUS 0x0F
45#define DA9055_LINE_GAIN_STATUS 0x10
46
47/* System Initialisation Registers */
48#define DA9055_CIF_CTRL 0x20
49#define DA9055_DIG_ROUTING_AIF 0X21
50#define DA9055_SR 0x22
51#define DA9055_REFERENCES 0x23
52#define DA9055_PLL_FRAC_TOP 0x24
53#define DA9055_PLL_FRAC_BOT 0x25
54#define DA9055_PLL_INTEGER 0x26
55#define DA9055_PLL_CTRL 0x27
56#define DA9055_AIF_CLK_MODE 0x28
57#define DA9055_AIF_CTRL 0x29
58#define DA9055_DIG_ROUTING_DAC 0x2A
59#define DA9055_ALC_CTRL1 0x2B
60
61/* Input - Gain, Select and Filter Registers */
62#define DA9055_AUX_L_GAIN 0x30
63#define DA9055_AUX_R_GAIN 0x31
64#define DA9055_MIXIN_L_SELECT 0x32
65#define DA9055_MIXIN_R_SELECT 0x33
66#define DA9055_MIXIN_L_GAIN 0x34
67#define DA9055_MIXIN_R_GAIN 0x35
68#define DA9055_ADC_L_GAIN 0x36
69#define DA9055_ADC_R_GAIN 0x37
70#define DA9055_ADC_FILTERS1 0x38
71#define DA9055_MIC_L_GAIN 0x39
72#define DA9055_MIC_R_GAIN 0x3A
73
74/* Output - Gain, Select and Filter Registers */
75#define DA9055_DAC_FILTERS5 0x40
76#define DA9055_DAC_FILTERS2 0x41
77#define DA9055_DAC_FILTERS3 0x42
78#define DA9055_DAC_FILTERS4 0x43
79#define DA9055_DAC_FILTERS1 0x44
80#define DA9055_DAC_L_GAIN 0x45
81#define DA9055_DAC_R_GAIN 0x46
82#define DA9055_CP_CTRL 0x47
83#define DA9055_HP_L_GAIN 0x48
84#define DA9055_HP_R_GAIN 0x49
85#define DA9055_LINE_GAIN 0x4A
86#define DA9055_MIXOUT_L_SELECT 0x4B
87#define DA9055_MIXOUT_R_SELECT 0x4C
88
89/* System Controller Registers */
90#define DA9055_SYSTEM_MODES_INPUT 0x50
91#define DA9055_SYSTEM_MODES_OUTPUT 0x51
92
93/* Control Registers */
94#define DA9055_AUX_L_CTRL 0x60
95#define DA9055_AUX_R_CTRL 0x61
96#define DA9055_MIC_BIAS_CTRL 0x62
97#define DA9055_MIC_L_CTRL 0x63
98#define DA9055_MIC_R_CTRL 0x64
99#define DA9055_MIXIN_L_CTRL 0x65
100#define DA9055_MIXIN_R_CTRL 0x66
101#define DA9055_ADC_L_CTRL 0x67
102#define DA9055_ADC_R_CTRL 0x68
103#define DA9055_DAC_L_CTRL 0x69
104#define DA9055_DAC_R_CTRL 0x6A
105#define DA9055_HP_L_CTRL 0x6B
106#define DA9055_HP_R_CTRL 0x6C
107#define DA9055_LINE_CTRL 0x6D
108#define DA9055_MIXOUT_L_CTRL 0x6E
109#define DA9055_MIXOUT_R_CTRL 0x6F
110
111/* Configuration Registers */
112#define DA9055_LDO_CTRL 0x90
113#define DA9055_IO_CTRL 0x91
114#define DA9055_GAIN_RAMP_CTRL 0x92
115#define DA9055_MIC_CONFIG 0x93
116#define DA9055_PC_COUNT 0x94
117#define DA9055_CP_VOL_THRESHOLD1 0x95
118#define DA9055_CP_DELAY 0x96
119#define DA9055_CP_DETECTOR 0x97
120#define DA9055_AIF_OFFSET 0x98
121#define DA9055_DIG_CTRL 0x99
122#define DA9055_ALC_CTRL2 0x9A
123#define DA9055_ALC_CTRL3 0x9B
124#define DA9055_ALC_NOISE 0x9C
125#define DA9055_ALC_TARGET_MIN 0x9D
126#define DA9055_ALC_TARGET_MAX 0x9E
127#define DA9055_ALC_GAIN_LIMITS 0x9F
128#define DA9055_ALC_ANA_GAIN_LIMITS 0xA0
129#define DA9055_ALC_ANTICLIP_CTRL 0xA1
130#define DA9055_ALC_ANTICLIP_LEVEL 0xA2
131#define DA9055_ALC_OFFSET_OP2M_L 0xA6
132#define DA9055_ALC_OFFSET_OP2U_L 0xA7
133#define DA9055_ALC_OFFSET_OP2M_R 0xAB
134#define DA9055_ALC_OFFSET_OP2U_R 0xAC
135#define DA9055_ALC_CIC_OP_LVL_CTRL 0xAD
136#define DA9055_ALC_CIC_OP_LVL_DATA 0xAE
137#define DA9055_DAC_NG_SETUP_TIME 0xAF
138#define DA9055_DAC_NG_OFF_THRESHOLD 0xB0
139#define DA9055_DAC_NG_ON_THRESHOLD 0xB1
140#define DA9055_DAC_NG_CTRL 0xB2
141
142/* SR bit fields */
143#define DA9055_SR_8000 (0x1 << 0)
144#define DA9055_SR_11025 (0x2 << 0)
145#define DA9055_SR_12000 (0x3 << 0)
146#define DA9055_SR_16000 (0x5 << 0)
147#define DA9055_SR_22050 (0x6 << 0)
148#define DA9055_SR_24000 (0x7 << 0)
149#define DA9055_SR_32000 (0x9 << 0)
150#define DA9055_SR_44100 (0xA << 0)
151#define DA9055_SR_48000 (0xB << 0)
152#define DA9055_SR_88200 (0xE << 0)
153#define DA9055_SR_96000 (0xF << 0)
154
155/* REFERENCES bit fields */
156#define DA9055_BIAS_EN (1 << 3)
157#define DA9055_VMID_EN (1 << 7)
158
159/* PLL_CTRL bit fields */
160#define DA9055_PLL_INDIV_10_20_MHZ (1 << 2)
161#define DA9055_PLL_SRM_EN (1 << 6)
162#define DA9055_PLL_EN (1 << 7)
163
164/* AIF_CLK_MODE bit fields */
165#define DA9055_AIF_BCLKS_PER_WCLK_32 (0 << 0)
166#define DA9055_AIF_BCLKS_PER_WCLK_64 (1 << 0)
167#define DA9055_AIF_BCLKS_PER_WCLK_128 (2 << 0)
168#define DA9055_AIF_BCLKS_PER_WCLK_256 (3 << 0)
169#define DA9055_AIF_CLK_EN_SLAVE_MODE (0 << 7)
170#define DA9055_AIF_CLK_EN_MASTER_MODE (1 << 7)
171
172/* AIF_CTRL bit fields */
173#define DA9055_AIF_FORMAT_I2S_MODE (0 << 0)
174#define DA9055_AIF_FORMAT_LEFT_J (1 << 0)
175#define DA9055_AIF_FORMAT_RIGHT_J (2 << 0)
Ashish Chavan5e82aaa2012-10-11 13:44:39 +0530176#define DA9055_AIF_FORMAT_DSP (3 << 0)
Ashish Chavan9911f7f2012-09-21 20:16:17 +0530177#define DA9055_AIF_WORD_S16_LE (0 << 2)
178#define DA9055_AIF_WORD_S20_3LE (1 << 2)
179#define DA9055_AIF_WORD_S24_LE (2 << 2)
180#define DA9055_AIF_WORD_S32_LE (3 << 2)
181
182/* MIXIN_L_CTRL bit fields */
183#define DA9055_MIXIN_L_MIX_EN (1 << 3)
184
185/* MIXIN_R_CTRL bit fields */
186#define DA9055_MIXIN_R_MIX_EN (1 << 3)
187
188/* ADC_L_CTRL bit fields */
189#define DA9055_ADC_L_EN (1 << 7)
190
191/* ADC_R_CTRL bit fields */
192#define DA9055_ADC_R_EN (1 << 7)
193
194/* DAC_L_CTRL bit fields */
195#define DA9055_DAC_L_MUTE_EN (1 << 6)
196
197/* DAC_R_CTRL bit fields */
198#define DA9055_DAC_R_MUTE_EN (1 << 6)
199
200/* HP_L_CTRL bit fields */
201#define DA9055_HP_L_AMP_OE (1 << 3)
202
203/* HP_R_CTRL bit fields */
204#define DA9055_HP_R_AMP_OE (1 << 3)
205
206/* LINE_CTRL bit fields */
207#define DA9055_LINE_AMP_OE (1 << 3)
208
209/* MIXOUT_L_CTRL bit fields */
210#define DA9055_MIXOUT_L_MIX_EN (1 << 3)
211
212/* MIXOUT_R_CTRL bit fields */
213#define DA9055_MIXOUT_R_MIX_EN (1 << 3)
214
215/* MIC bias select bit fields */
216#define DA9055_MICBIAS2_EN (1 << 6)
217
218/* ALC_CIC_OP_LEVEL_CTRL bit fields */
219#define DA9055_ALC_DATA_MIDDLE (2 << 0)
220#define DA9055_ALC_DATA_TOP (3 << 0)
221#define DA9055_ALC_CIC_OP_CHANNEL_LEFT (0 << 7)
222#define DA9055_ALC_CIC_OP_CHANNEL_RIGHT (1 << 7)
223
224#define DA9055_AIF_BCLK_MASK (3 << 0)
225#define DA9055_AIF_CLK_MODE_MASK (1 << 7)
226#define DA9055_AIF_FORMAT_MASK (3 << 0)
227#define DA9055_AIF_WORD_LENGTH_MASK (3 << 2)
228#define DA9055_GAIN_RAMPING_EN (1 << 5)
229#define DA9055_MICBIAS_LEVEL_MASK (3 << 4)
230
231#define DA9055_ALC_OFFSET_15_8 0x00FF00
232#define DA9055_ALC_OFFSET_17_16 0x030000
233#define DA9055_ALC_AVG_ITERATIONS 5
234
235struct pll_div {
236 int fref;
237 int fout;
238 u8 frac_top;
239 u8 frac_bot;
240 u8 integer;
241 u8 mode; /* 0 = slave, 1 = master */
242};
243
244/* PLL divisor table */
245static const struct pll_div da9055_pll_div[] = {
246 /* for MASTER mode, fs = 44.1Khz and its harmonics */
247 {11289600, 2822400, 0x00, 0x00, 0x20, 1}, /* MCLK=11.2896Mhz */
248 {12000000, 2822400, 0x03, 0x61, 0x1E, 1}, /* MCLK=12Mhz */
249 {12288000, 2822400, 0x0C, 0xCC, 0x1D, 1}, /* MCLK=12.288Mhz */
250 {13000000, 2822400, 0x19, 0x45, 0x1B, 1}, /* MCLK=13Mhz */
251 {13500000, 2822400, 0x18, 0x56, 0x1A, 1}, /* MCLK=13.5Mhz */
252 {14400000, 2822400, 0x02, 0xD0, 0x19, 1}, /* MCLK=14.4Mhz */
253 {19200000, 2822400, 0x1A, 0x1C, 0x12, 1}, /* MCLK=19.2Mhz */
254 {19680000, 2822400, 0x0B, 0x6D, 0x12, 1}, /* MCLK=19.68Mhz */
255 {19800000, 2822400, 0x07, 0xDD, 0x12, 1}, /* MCLK=19.8Mhz */
256 /* for MASTER mode, fs = 48Khz and its harmonics */
257 {11289600, 3072000, 0x1A, 0x8E, 0x22, 1}, /* MCLK=11.2896Mhz */
258 {12000000, 3072000, 0x18, 0x93, 0x20, 1}, /* MCLK=12Mhz */
259 {12288000, 3072000, 0x00, 0x00, 0x20, 1}, /* MCLK=12.288Mhz */
260 {13000000, 3072000, 0x07, 0xEA, 0x1E, 1}, /* MCLK=13Mhz */
261 {13500000, 3072000, 0x04, 0x11, 0x1D, 1}, /* MCLK=13.5Mhz */
262 {14400000, 3072000, 0x09, 0xD0, 0x1B, 1}, /* MCLK=14.4Mhz */
263 {19200000, 3072000, 0x0F, 0x5C, 0x14, 1}, /* MCLK=19.2Mhz */
264 {19680000, 3072000, 0x1F, 0x60, 0x13, 1}, /* MCLK=19.68Mhz */
265 {19800000, 3072000, 0x1B, 0x80, 0x13, 1}, /* MCLK=19.8Mhz */
266 /* for SLAVE mode with SRM */
267 {11289600, 2822400, 0x0D, 0x47, 0x21, 0}, /* MCLK=11.2896Mhz */
268 {12000000, 2822400, 0x0D, 0xFA, 0x1F, 0}, /* MCLK=12Mhz */
269 {12288000, 2822400, 0x16, 0x66, 0x1E, 0}, /* MCLK=12.288Mhz */
270 {13000000, 2822400, 0x00, 0x98, 0x1D, 0}, /* MCLK=13Mhz */
271 {13500000, 2822400, 0x1E, 0x33, 0x1B, 0}, /* MCLK=13.5Mhz */
272 {14400000, 2822400, 0x06, 0x50, 0x1A, 0}, /* MCLK=14.4Mhz */
273 {19200000, 2822400, 0x14, 0xBC, 0x13, 0}, /* MCLK=19.2Mhz */
274 {19680000, 2822400, 0x05, 0x66, 0x13, 0}, /* MCLK=19.68Mhz */
275 {19800000, 2822400, 0x01, 0xAE, 0x13, 0}, /* MCLK=19.8Mhz */
276};
277
278enum clk_src {
279 DA9055_CLKSRC_MCLK
280};
281
282/* Gain and Volume */
283
284static const unsigned int aux_vol_tlv[] = {
285 TLV_DB_RANGE_HEAD(2),
286 0x0, 0x10, TLV_DB_SCALE_ITEM(-5400, 0, 0),
287 /* -54dB to 15dB */
288 0x11, 0x3f, TLV_DB_SCALE_ITEM(-5400, 150, 0)
289};
290
291static const unsigned int digital_gain_tlv[] = {
292 TLV_DB_RANGE_HEAD(2),
293 0x0, 0x07, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
294 /* -78dB to 12dB */
295 0x08, 0x7f, TLV_DB_SCALE_ITEM(-7800, 75, 0)
296};
297
298static const unsigned int alc_analog_gain_tlv[] = {
299 TLV_DB_RANGE_HEAD(2),
300 0x0, 0x0, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
301 /* 0dB to 36dB */
302 0x01, 0x07, TLV_DB_SCALE_ITEM(0, 600, 0)
303};
304
305static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, -600, 600, 0);
306static const DECLARE_TLV_DB_SCALE(mixin_gain_tlv, -450, 150, 0);
307static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
308static const DECLARE_TLV_DB_SCALE(hp_vol_tlv, -5700, 100, 0);
309static const DECLARE_TLV_DB_SCALE(lineout_vol_tlv, -4800, 100, 0);
310static const DECLARE_TLV_DB_SCALE(alc_threshold_tlv, -9450, 150, 0);
311static const DECLARE_TLV_DB_SCALE(alc_gain_tlv, 0, 600, 0);
312
313/* ADC and DAC high pass filter cutoff value */
314static const char * const da9055_hpf_cutoff_txt[] = {
315 "Fs/24000", "Fs/12000", "Fs/6000", "Fs/3000"
316};
317
318static const struct soc_enum da9055_dac_hpf_cutoff =
319 SOC_ENUM_SINGLE(DA9055_DAC_FILTERS1, 4, 4, da9055_hpf_cutoff_txt);
320
321static const struct soc_enum da9055_adc_hpf_cutoff =
322 SOC_ENUM_SINGLE(DA9055_ADC_FILTERS1, 4, 4, da9055_hpf_cutoff_txt);
323
324/* ADC and DAC voice mode (8kHz) high pass cutoff value */
325static const char * const da9055_vf_cutoff_txt[] = {
326 "2.5Hz", "25Hz", "50Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
327};
328
329static const struct soc_enum da9055_dac_vf_cutoff =
330 SOC_ENUM_SINGLE(DA9055_DAC_FILTERS1, 0, 8, da9055_vf_cutoff_txt);
331
332static const struct soc_enum da9055_adc_vf_cutoff =
333 SOC_ENUM_SINGLE(DA9055_ADC_FILTERS1, 0, 8, da9055_vf_cutoff_txt);
334
335/* Gain ramping rate value */
336static const char * const da9055_gain_ramping_txt[] = {
337 "nominal rate", "nominal rate * 4", "nominal rate * 8",
338 "nominal rate / 8"
339};
340
341static const struct soc_enum da9055_gain_ramping_rate =
342 SOC_ENUM_SINGLE(DA9055_GAIN_RAMP_CTRL, 0, 4, da9055_gain_ramping_txt);
343
344/* DAC noise gate setup time value */
345static const char * const da9055_dac_ng_setup_time_txt[] = {
346 "256 samples", "512 samples", "1024 samples", "2048 samples"
347};
348
349static const struct soc_enum da9055_dac_ng_setup_time =
350 SOC_ENUM_SINGLE(DA9055_DAC_NG_SETUP_TIME, 0, 4,
351 da9055_dac_ng_setup_time_txt);
352
353/* DAC noise gate rampup rate value */
354static const char * const da9055_dac_ng_rampup_txt[] = {
355 "0.02 ms/dB", "0.16 ms/dB"
356};
357
358static const struct soc_enum da9055_dac_ng_rampup_rate =
359 SOC_ENUM_SINGLE(DA9055_DAC_NG_SETUP_TIME, 2, 2,
360 da9055_dac_ng_rampup_txt);
361
362/* DAC noise gate rampdown rate value */
363static const char * const da9055_dac_ng_rampdown_txt[] = {
364 "0.64 ms/dB", "20.48 ms/dB"
365};
366
367static const struct soc_enum da9055_dac_ng_rampdown_rate =
368 SOC_ENUM_SINGLE(DA9055_DAC_NG_SETUP_TIME, 3, 2,
369 da9055_dac_ng_rampdown_txt);
370
371/* DAC soft mute rate value */
372static const char * const da9055_dac_soft_mute_rate_txt[] = {
373 "1", "2", "4", "8", "16", "32", "64"
374};
375
376static const struct soc_enum da9055_dac_soft_mute_rate =
377 SOC_ENUM_SINGLE(DA9055_DAC_FILTERS5, 4, 7,
378 da9055_dac_soft_mute_rate_txt);
379
380/* DAC routing select */
381static const char * const da9055_dac_src_txt[] = {
382 "ADC output left", "ADC output right", "AIF input left",
383 "AIF input right"
384};
385
386static const struct soc_enum da9055_dac_l_src =
387 SOC_ENUM_SINGLE(DA9055_DIG_ROUTING_DAC, 0, 4, da9055_dac_src_txt);
388
389static const struct soc_enum da9055_dac_r_src =
390 SOC_ENUM_SINGLE(DA9055_DIG_ROUTING_DAC, 4, 4, da9055_dac_src_txt);
391
392/* MIC PGA Left source select */
393static const char * const da9055_mic_l_src_txt[] = {
394 "MIC1_P_N", "MIC1_P", "MIC1_N", "MIC2_L"
395};
396
397static const struct soc_enum da9055_mic_l_src =
398 SOC_ENUM_SINGLE(DA9055_MIXIN_L_SELECT, 4, 4, da9055_mic_l_src_txt);
399
400/* MIC PGA Right source select */
401static const char * const da9055_mic_r_src_txt[] = {
402 "MIC2_R_L", "MIC2_R", "MIC2_L"
403};
404
405static const struct soc_enum da9055_mic_r_src =
406 SOC_ENUM_SINGLE(DA9055_MIXIN_R_SELECT, 4, 3, da9055_mic_r_src_txt);
407
408/* ALC Input Signal Tracking rate select */
409static const char * const da9055_signal_tracking_rate_txt[] = {
410 "1/4", "1/16", "1/256", "1/65536"
411};
412
413static const struct soc_enum da9055_integ_attack_rate =
414 SOC_ENUM_SINGLE(DA9055_ALC_CTRL3, 4, 4,
415 da9055_signal_tracking_rate_txt);
416
417static const struct soc_enum da9055_integ_release_rate =
418 SOC_ENUM_SINGLE(DA9055_ALC_CTRL3, 6, 4,
419 da9055_signal_tracking_rate_txt);
420
421/* ALC Attack Rate select */
422static const char * const da9055_attack_rate_txt[] = {
423 "44/fs", "88/fs", "176/fs", "352/fs", "704/fs", "1408/fs", "2816/fs",
424 "5632/fs", "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs"
425};
426
427static const struct soc_enum da9055_attack_rate =
428 SOC_ENUM_SINGLE(DA9055_ALC_CTRL2, 0, 13, da9055_attack_rate_txt);
429
430/* ALC Release Rate select */
431static const char * const da9055_release_rate_txt[] = {
432 "176/fs", "352/fs", "704/fs", "1408/fs", "2816/fs", "5632/fs",
433 "11264/fs", "22528/fs", "45056/fs", "90112/fs", "180224/fs"
434};
435
436static const struct soc_enum da9055_release_rate =
437 SOC_ENUM_SINGLE(DA9055_ALC_CTRL2, 4, 11, da9055_release_rate_txt);
438
439/* ALC Hold Time select */
440static const char * const da9055_hold_time_txt[] = {
441 "62/fs", "124/fs", "248/fs", "496/fs", "992/fs", "1984/fs", "3968/fs",
442 "7936/fs", "15872/fs", "31744/fs", "63488/fs", "126976/fs",
443 "253952/fs", "507904/fs", "1015808/fs", "2031616/fs"
444};
445
446static const struct soc_enum da9055_hold_time =
447 SOC_ENUM_SINGLE(DA9055_ALC_CTRL3, 0, 16, da9055_hold_time_txt);
448
449static int da9055_get_alc_data(struct snd_soc_codec *codec, u8 reg_val)
450{
451 int mid_data, top_data;
452 int sum = 0;
453 u8 iteration;
454
455 for (iteration = 0; iteration < DA9055_ALC_AVG_ITERATIONS;
456 iteration++) {
457 /* Select the left or right channel and capture data */
458 snd_soc_write(codec, DA9055_ALC_CIC_OP_LVL_CTRL, reg_val);
459
460 /* Select middle 8 bits for read back from data register */
461 snd_soc_write(codec, DA9055_ALC_CIC_OP_LVL_CTRL,
462 reg_val | DA9055_ALC_DATA_MIDDLE);
463 mid_data = snd_soc_read(codec, DA9055_ALC_CIC_OP_LVL_DATA);
464
465 /* Select top 8 bits for read back from data register */
466 snd_soc_write(codec, DA9055_ALC_CIC_OP_LVL_CTRL,
467 reg_val | DA9055_ALC_DATA_TOP);
468 top_data = snd_soc_read(codec, DA9055_ALC_CIC_OP_LVL_DATA);
469
470 sum += ((mid_data << 8) | (top_data << 16));
471 }
472
473 return sum / DA9055_ALC_AVG_ITERATIONS;
474}
475
476static int da9055_put_alc_sw(struct snd_kcontrol *kcontrol,
477 struct snd_ctl_elem_value *ucontrol)
478{
479 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
480 u8 reg_val, adc_left, adc_right;
481 int avg_left_data, avg_right_data, offset_l, offset_r;
482
483 if (ucontrol->value.integer.value[0]) {
484 /*
485 * While enabling ALC (or ALC sync mode), calibration of the DC
486 * offsets must be done first
487 */
488
489 /* Save current values from ADC control registers */
490 adc_left = snd_soc_read(codec, DA9055_ADC_L_CTRL);
491 adc_right = snd_soc_read(codec, DA9055_ADC_R_CTRL);
492
493 /* Enable ADC Left and Right */
494 snd_soc_update_bits(codec, DA9055_ADC_L_CTRL,
495 DA9055_ADC_L_EN, DA9055_ADC_L_EN);
496 snd_soc_update_bits(codec, DA9055_ADC_R_CTRL,
497 DA9055_ADC_R_EN, DA9055_ADC_R_EN);
498
499 /* Calculate average for Left and Right data */
500 /* Left Data */
501 avg_left_data = da9055_get_alc_data(codec,
502 DA9055_ALC_CIC_OP_CHANNEL_LEFT);
503 /* Right Data */
504 avg_right_data = da9055_get_alc_data(codec,
505 DA9055_ALC_CIC_OP_CHANNEL_RIGHT);
506
507 /* Calculate DC offset */
508 offset_l = -avg_left_data;
509 offset_r = -avg_right_data;
510
511 reg_val = (offset_l & DA9055_ALC_OFFSET_15_8) >> 8;
512 snd_soc_write(codec, DA9055_ALC_OFFSET_OP2M_L, reg_val);
513 reg_val = (offset_l & DA9055_ALC_OFFSET_17_16) >> 16;
514 snd_soc_write(codec, DA9055_ALC_OFFSET_OP2U_L, reg_val);
515
516 reg_val = (offset_r & DA9055_ALC_OFFSET_15_8) >> 8;
517 snd_soc_write(codec, DA9055_ALC_OFFSET_OP2M_R, reg_val);
518 reg_val = (offset_r & DA9055_ALC_OFFSET_17_16) >> 16;
519 snd_soc_write(codec, DA9055_ALC_OFFSET_OP2U_R, reg_val);
520
521 /* Restore original values of ADC control registers */
522 snd_soc_write(codec, DA9055_ADC_L_CTRL, adc_left);
523 snd_soc_write(codec, DA9055_ADC_R_CTRL, adc_right);
524 }
525
526 return snd_soc_put_volsw(kcontrol, ucontrol);
527}
528
529static const struct snd_kcontrol_new da9055_snd_controls[] = {
530
531 /* Volume controls */
532 SOC_DOUBLE_R_TLV("Mic Volume",
533 DA9055_MIC_L_GAIN, DA9055_MIC_R_GAIN,
534 0, 0x7, 0, mic_vol_tlv),
535 SOC_DOUBLE_R_TLV("Aux Volume",
536 DA9055_AUX_L_GAIN, DA9055_AUX_R_GAIN,
537 0, 0x3f, 0, aux_vol_tlv),
538 SOC_DOUBLE_R_TLV("Mixin PGA Volume",
539 DA9055_MIXIN_L_GAIN, DA9055_MIXIN_R_GAIN,
540 0, 0xf, 0, mixin_gain_tlv),
541 SOC_DOUBLE_R_TLV("ADC Volume",
542 DA9055_ADC_L_GAIN, DA9055_ADC_R_GAIN,
543 0, 0x7f, 0, digital_gain_tlv),
544
545 SOC_DOUBLE_R_TLV("DAC Volume",
546 DA9055_DAC_L_GAIN, DA9055_DAC_R_GAIN,
547 0, 0x7f, 0, digital_gain_tlv),
548 SOC_DOUBLE_R_TLV("Headphone Volume",
549 DA9055_HP_L_GAIN, DA9055_HP_R_GAIN,
550 0, 0x3f, 0, hp_vol_tlv),
551 SOC_SINGLE_TLV("Lineout Volume", DA9055_LINE_GAIN, 0, 0x3f, 0,
552 lineout_vol_tlv),
553
554 /* DAC Equalizer controls */
555 SOC_SINGLE("DAC EQ Switch", DA9055_DAC_FILTERS4, 7, 1, 0),
556 SOC_SINGLE_TLV("DAC EQ1 Volume", DA9055_DAC_FILTERS2, 0, 0xf, 0,
557 eq_gain_tlv),
558 SOC_SINGLE_TLV("DAC EQ2 Volume", DA9055_DAC_FILTERS2, 4, 0xf, 0,
559 eq_gain_tlv),
560 SOC_SINGLE_TLV("DAC EQ3 Volume", DA9055_DAC_FILTERS3, 0, 0xf, 0,
561 eq_gain_tlv),
562 SOC_SINGLE_TLV("DAC EQ4 Volume", DA9055_DAC_FILTERS3, 4, 0xf, 0,
563 eq_gain_tlv),
564 SOC_SINGLE_TLV("DAC EQ5 Volume", DA9055_DAC_FILTERS4, 0, 0xf, 0,
565 eq_gain_tlv),
566
567 /* High Pass Filter and Voice Mode controls */
568 SOC_SINGLE("ADC HPF Switch", DA9055_ADC_FILTERS1, 7, 1, 0),
569 SOC_ENUM("ADC HPF Cutoff", da9055_adc_hpf_cutoff),
570 SOC_SINGLE("ADC Voice Mode Switch", DA9055_ADC_FILTERS1, 3, 1, 0),
571 SOC_ENUM("ADC Voice Cutoff", da9055_adc_vf_cutoff),
572
573 SOC_SINGLE("DAC HPF Switch", DA9055_DAC_FILTERS1, 7, 1, 0),
574 SOC_ENUM("DAC HPF Cutoff", da9055_dac_hpf_cutoff),
575 SOC_SINGLE("DAC Voice Mode Switch", DA9055_DAC_FILTERS1, 3, 1, 0),
576 SOC_ENUM("DAC Voice Cutoff", da9055_dac_vf_cutoff),
577
578 /* Mute controls */
579 SOC_DOUBLE_R("Mic Switch", DA9055_MIC_L_CTRL,
580 DA9055_MIC_R_CTRL, 6, 1, 0),
581 SOC_DOUBLE_R("Aux Switch", DA9055_AUX_L_CTRL,
582 DA9055_AUX_R_CTRL, 6, 1, 0),
583 SOC_DOUBLE_R("Mixin PGA Switch", DA9055_MIXIN_L_CTRL,
584 DA9055_MIXIN_R_CTRL, 6, 1, 0),
585 SOC_DOUBLE_R("ADC Switch", DA9055_ADC_L_CTRL,
586 DA9055_ADC_R_CTRL, 6, 1, 0),
587 SOC_DOUBLE_R("Headphone Switch", DA9055_HP_L_CTRL,
588 DA9055_HP_R_CTRL, 6, 1, 0),
589 SOC_SINGLE("Lineout Switch", DA9055_LINE_CTRL, 6, 1, 0),
590 SOC_SINGLE("DAC Soft Mute Switch", DA9055_DAC_FILTERS5, 7, 1, 0),
591 SOC_ENUM("DAC Soft Mute Rate", da9055_dac_soft_mute_rate),
592
593 /* Zero Cross controls */
594 SOC_DOUBLE_R("Aux ZC Switch", DA9055_AUX_L_CTRL,
595 DA9055_AUX_R_CTRL, 4, 1, 0),
596 SOC_DOUBLE_R("Mixin PGA ZC Switch", DA9055_MIXIN_L_CTRL,
597 DA9055_MIXIN_R_CTRL, 4, 1, 0),
598 SOC_DOUBLE_R("Headphone ZC Switch", DA9055_HP_L_CTRL,
599 DA9055_HP_R_CTRL, 4, 1, 0),
600 SOC_SINGLE("Lineout ZC Switch", DA9055_LINE_CTRL, 4, 1, 0),
601
602 /* Gain Ramping controls */
603 SOC_DOUBLE_R("Aux Gain Ramping Switch", DA9055_AUX_L_CTRL,
604 DA9055_AUX_R_CTRL, 5, 1, 0),
605 SOC_DOUBLE_R("Mixin Gain Ramping Switch", DA9055_MIXIN_L_CTRL,
606 DA9055_MIXIN_R_CTRL, 5, 1, 0),
607 SOC_DOUBLE_R("ADC Gain Ramping Switch", DA9055_ADC_L_CTRL,
608 DA9055_ADC_R_CTRL, 5, 1, 0),
609 SOC_DOUBLE_R("DAC Gain Ramping Switch", DA9055_DAC_L_CTRL,
610 DA9055_DAC_R_CTRL, 5, 1, 0),
611 SOC_DOUBLE_R("Headphone Gain Ramping Switch", DA9055_HP_L_CTRL,
612 DA9055_HP_R_CTRL, 5, 1, 0),
613 SOC_SINGLE("Lineout Gain Ramping Switch", DA9055_LINE_CTRL, 5, 1, 0),
614 SOC_ENUM("Gain Ramping Rate", da9055_gain_ramping_rate),
615
616 /* DAC Noise Gate controls */
617 SOC_SINGLE("DAC NG Switch", DA9055_DAC_NG_CTRL, 7, 1, 0),
618 SOC_SINGLE("DAC NG ON Threshold", DA9055_DAC_NG_ON_THRESHOLD,
619 0, 0x7, 0),
620 SOC_SINGLE("DAC NG OFF Threshold", DA9055_DAC_NG_OFF_THRESHOLD,
621 0, 0x7, 0),
622 SOC_ENUM("DAC NG Setup Time", da9055_dac_ng_setup_time),
623 SOC_ENUM("DAC NG Rampup Rate", da9055_dac_ng_rampup_rate),
624 SOC_ENUM("DAC NG Rampdown Rate", da9055_dac_ng_rampdown_rate),
625
626 /* DAC Invertion control */
627 SOC_SINGLE("DAC Left Invert", DA9055_DIG_CTRL, 3, 1, 0),
628 SOC_SINGLE("DAC Right Invert", DA9055_DIG_CTRL, 7, 1, 0),
629
630 /* DMIC controls */
631 SOC_DOUBLE_R("DMIC Switch", DA9055_MIXIN_L_SELECT,
632 DA9055_MIXIN_R_SELECT, 7, 1, 0),
633
634 /* ALC Controls */
635 SOC_DOUBLE_EXT("ALC Switch", DA9055_ALC_CTRL1, 3, 7, 1, 0,
636 snd_soc_get_volsw, da9055_put_alc_sw),
637 SOC_SINGLE_EXT("ALC Sync Mode Switch", DA9055_ALC_CTRL1, 1, 1, 0,
638 snd_soc_get_volsw, da9055_put_alc_sw),
639 SOC_SINGLE("ALC Offset Switch", DA9055_ALC_CTRL1, 0, 1, 0),
640 SOC_SINGLE("ALC Anticlip Mode Switch", DA9055_ALC_ANTICLIP_CTRL,
641 7, 1, 0),
642 SOC_SINGLE("ALC Anticlip Level", DA9055_ALC_ANTICLIP_LEVEL,
643 0, 0x7f, 0),
644 SOC_SINGLE_TLV("ALC Min Threshold Volume", DA9055_ALC_TARGET_MIN,
645 0, 0x3f, 1, alc_threshold_tlv),
646 SOC_SINGLE_TLV("ALC Max Threshold Volume", DA9055_ALC_TARGET_MAX,
647 0, 0x3f, 1, alc_threshold_tlv),
648 SOC_SINGLE_TLV("ALC Noise Threshold Volume", DA9055_ALC_NOISE,
649 0, 0x3f, 1, alc_threshold_tlv),
650 SOC_SINGLE_TLV("ALC Max Gain Volume", DA9055_ALC_GAIN_LIMITS,
651 4, 0xf, 0, alc_gain_tlv),
652 SOC_SINGLE_TLV("ALC Max Attenuation Volume", DA9055_ALC_GAIN_LIMITS,
653 0, 0xf, 0, alc_gain_tlv),
654 SOC_SINGLE_TLV("ALC Min Analog Gain Volume",
655 DA9055_ALC_ANA_GAIN_LIMITS,
656 0, 0x7, 0, alc_analog_gain_tlv),
657 SOC_SINGLE_TLV("ALC Max Analog Gain Volume",
658 DA9055_ALC_ANA_GAIN_LIMITS,
659 4, 0x7, 0, alc_analog_gain_tlv),
660 SOC_ENUM("ALC Attack Rate", da9055_attack_rate),
661 SOC_ENUM("ALC Release Rate", da9055_release_rate),
662 SOC_ENUM("ALC Hold Time", da9055_hold_time),
663 /*
664 * Rate at which input signal envelope is tracked as the signal gets
665 * larger
666 */
667 SOC_ENUM("ALC Integ Attack Rate", da9055_integ_attack_rate),
668 /*
669 * Rate at which input signal envelope is tracked as the signal gets
670 * smaller
671 */
672 SOC_ENUM("ALC Integ Release Rate", da9055_integ_release_rate),
673};
674
675/* DAPM Controls */
676
677/* Mic PGA Left Source */
678static const struct snd_kcontrol_new da9055_mic_l_mux_controls =
679SOC_DAPM_ENUM("Route", da9055_mic_l_src);
680
681/* Mic PGA Right Source */
682static const struct snd_kcontrol_new da9055_mic_r_mux_controls =
683SOC_DAPM_ENUM("Route", da9055_mic_r_src);
684
685/* In Mixer Left */
686static const struct snd_kcontrol_new da9055_dapm_mixinl_controls[] = {
687 SOC_DAPM_SINGLE("Aux Left Switch", DA9055_MIXIN_L_SELECT, 0, 1, 0),
688 SOC_DAPM_SINGLE("Mic Left Switch", DA9055_MIXIN_L_SELECT, 1, 1, 0),
689 SOC_DAPM_SINGLE("Mic Right Switch", DA9055_MIXIN_L_SELECT, 2, 1, 0),
690};
691
692/* In Mixer Right */
693static const struct snd_kcontrol_new da9055_dapm_mixinr_controls[] = {
694 SOC_DAPM_SINGLE("Aux Right Switch", DA9055_MIXIN_R_SELECT, 0, 1, 0),
695 SOC_DAPM_SINGLE("Mic Right Switch", DA9055_MIXIN_R_SELECT, 1, 1, 0),
696 SOC_DAPM_SINGLE("Mic Left Switch", DA9055_MIXIN_R_SELECT, 2, 1, 0),
697 SOC_DAPM_SINGLE("Mixin Left Switch", DA9055_MIXIN_R_SELECT, 3, 1, 0),
698};
699
700/* DAC Left Source */
701static const struct snd_kcontrol_new da9055_dac_l_mux_controls =
702SOC_DAPM_ENUM("Route", da9055_dac_l_src);
703
704/* DAC Right Source */
705static const struct snd_kcontrol_new da9055_dac_r_mux_controls =
706SOC_DAPM_ENUM("Route", da9055_dac_r_src);
707
708/* Out Mixer Left */
709static const struct snd_kcontrol_new da9055_dapm_mixoutl_controls[] = {
710 SOC_DAPM_SINGLE("Aux Left Switch", DA9055_MIXOUT_L_SELECT, 0, 1, 0),
711 SOC_DAPM_SINGLE("Mixin Left Switch", DA9055_MIXOUT_L_SELECT, 1, 1, 0),
712 SOC_DAPM_SINGLE("Mixin Right Switch", DA9055_MIXOUT_L_SELECT, 2, 1, 0),
713 SOC_DAPM_SINGLE("DAC Left Switch", DA9055_MIXOUT_L_SELECT, 3, 1, 0),
714 SOC_DAPM_SINGLE("Aux Left Invert Switch", DA9055_MIXOUT_L_SELECT,
715 4, 1, 0),
716 SOC_DAPM_SINGLE("Mixin Left Invert Switch", DA9055_MIXOUT_L_SELECT,
717 5, 1, 0),
718 SOC_DAPM_SINGLE("Mixin Right Invert Switch", DA9055_MIXOUT_L_SELECT,
719 6, 1, 0),
720};
721
722/* Out Mixer Right */
723static const struct snd_kcontrol_new da9055_dapm_mixoutr_controls[] = {
724 SOC_DAPM_SINGLE("Aux Right Switch", DA9055_MIXOUT_R_SELECT, 0, 1, 0),
725 SOC_DAPM_SINGLE("Mixin Right Switch", DA9055_MIXOUT_R_SELECT, 1, 1, 0),
726 SOC_DAPM_SINGLE("Mixin Left Switch", DA9055_MIXOUT_R_SELECT, 2, 1, 0),
727 SOC_DAPM_SINGLE("DAC Right Switch", DA9055_MIXOUT_R_SELECT, 3, 1, 0),
728 SOC_DAPM_SINGLE("Aux Right Invert Switch", DA9055_MIXOUT_R_SELECT,
729 4, 1, 0),
730 SOC_DAPM_SINGLE("Mixin Right Invert Switch", DA9055_MIXOUT_R_SELECT,
731 5, 1, 0),
732 SOC_DAPM_SINGLE("Mixin Left Invert Switch", DA9055_MIXOUT_R_SELECT,
733 6, 1, 0),
734};
735
736/* DAPM widgets */
737static const struct snd_soc_dapm_widget da9055_dapm_widgets[] = {
738 /* Input Side */
739
740 /* Input Lines */
741 SND_SOC_DAPM_INPUT("MIC1"),
742 SND_SOC_DAPM_INPUT("MIC2"),
743 SND_SOC_DAPM_INPUT("AUXL"),
744 SND_SOC_DAPM_INPUT("AUXR"),
745
746 /* MUXs for Mic PGA source selection */
747 SND_SOC_DAPM_MUX("Mic Left Source", SND_SOC_NOPM, 0, 0,
748 &da9055_mic_l_mux_controls),
749 SND_SOC_DAPM_MUX("Mic Right Source", SND_SOC_NOPM, 0, 0,
750 &da9055_mic_r_mux_controls),
751
752 /* Input PGAs */
753 SND_SOC_DAPM_PGA("Mic Left", DA9055_MIC_L_CTRL, 7, 0, NULL, 0),
754 SND_SOC_DAPM_PGA("Mic Right", DA9055_MIC_R_CTRL, 7, 0, NULL, 0),
755 SND_SOC_DAPM_PGA("Aux Left", DA9055_AUX_L_CTRL, 7, 0, NULL, 0),
756 SND_SOC_DAPM_PGA("Aux Right", DA9055_AUX_R_CTRL, 7, 0, NULL, 0),
757 SND_SOC_DAPM_PGA("MIXIN Left", DA9055_MIXIN_L_CTRL, 7, 0, NULL, 0),
758 SND_SOC_DAPM_PGA("MIXIN Right", DA9055_MIXIN_R_CTRL, 7, 0, NULL, 0),
759
760 SND_SOC_DAPM_SUPPLY("Mic Bias", DA9055_MIC_BIAS_CTRL, 7, 0, NULL, 0),
761 SND_SOC_DAPM_SUPPLY("AIF", DA9055_AIF_CTRL, 7, 0, NULL, 0),
762 SND_SOC_DAPM_SUPPLY("Charge Pump", DA9055_CP_CTRL, 7, 0, NULL, 0),
763
764 /* Input Mixers */
765 SND_SOC_DAPM_MIXER("In Mixer Left", SND_SOC_NOPM, 0, 0,
766 &da9055_dapm_mixinl_controls[0],
767 ARRAY_SIZE(da9055_dapm_mixinl_controls)),
768 SND_SOC_DAPM_MIXER("In Mixer Right", SND_SOC_NOPM, 0, 0,
769 &da9055_dapm_mixinr_controls[0],
770 ARRAY_SIZE(da9055_dapm_mixinr_controls)),
771
772 /* ADCs */
773 SND_SOC_DAPM_ADC("ADC Left", "Capture", DA9055_ADC_L_CTRL, 7, 0),
774 SND_SOC_DAPM_ADC("ADC Right", "Capture", DA9055_ADC_R_CTRL, 7, 0),
775
776 /* Output Side */
777
778 /* MUXs for DAC source selection */
779 SND_SOC_DAPM_MUX("DAC Left Source", SND_SOC_NOPM, 0, 0,
780 &da9055_dac_l_mux_controls),
781 SND_SOC_DAPM_MUX("DAC Right Source", SND_SOC_NOPM, 0, 0,
782 &da9055_dac_r_mux_controls),
783
784 /* AIF input */
785 SND_SOC_DAPM_AIF_IN("AIFIN Left", "Playback", 0, SND_SOC_NOPM, 0, 0),
786 SND_SOC_DAPM_AIF_IN("AIFIN Right", "Playback", 0, SND_SOC_NOPM, 0, 0),
787
788 /* DACs */
789 SND_SOC_DAPM_DAC("DAC Left", "Playback", DA9055_DAC_L_CTRL, 7, 0),
790 SND_SOC_DAPM_DAC("DAC Right", "Playback", DA9055_DAC_R_CTRL, 7, 0),
791
792 /* Output Mixers */
793 SND_SOC_DAPM_MIXER("Out Mixer Left", SND_SOC_NOPM, 0, 0,
794 &da9055_dapm_mixoutl_controls[0],
795 ARRAY_SIZE(da9055_dapm_mixoutl_controls)),
796 SND_SOC_DAPM_MIXER("Out Mixer Right", SND_SOC_NOPM, 0, 0,
797 &da9055_dapm_mixoutr_controls[0],
798 ARRAY_SIZE(da9055_dapm_mixoutr_controls)),
799
800 /* Output PGAs */
801 SND_SOC_DAPM_PGA("MIXOUT Left", DA9055_MIXOUT_L_CTRL, 7, 0, NULL, 0),
802 SND_SOC_DAPM_PGA("MIXOUT Right", DA9055_MIXOUT_R_CTRL, 7, 0, NULL, 0),
803 SND_SOC_DAPM_PGA("Lineout", DA9055_LINE_CTRL, 7, 0, NULL, 0),
804 SND_SOC_DAPM_PGA("Headphone Left", DA9055_HP_L_CTRL, 7, 0, NULL, 0),
805 SND_SOC_DAPM_PGA("Headphone Right", DA9055_HP_R_CTRL, 7, 0, NULL, 0),
806
807 /* Output Lines */
808 SND_SOC_DAPM_OUTPUT("HPL"),
809 SND_SOC_DAPM_OUTPUT("HPR"),
810 SND_SOC_DAPM_OUTPUT("LINE"),
811};
812
813/* DAPM audio route definition */
814static const struct snd_soc_dapm_route da9055_audio_map[] = {
815 /* Dest Connecting Widget source */
816
817 /* Input path */
818 {"Mic Left Source", "MIC1_P_N", "MIC1"},
819 {"Mic Left Source", "MIC1_P", "MIC1"},
820 {"Mic Left Source", "MIC1_N", "MIC1"},
821 {"Mic Left Source", "MIC2_L", "MIC2"},
822
823 {"Mic Right Source", "MIC2_R_L", "MIC2"},
824 {"Mic Right Source", "MIC2_R", "MIC2"},
825 {"Mic Right Source", "MIC2_L", "MIC2"},
826
827 {"Mic Left", NULL, "Mic Left Source"},
828 {"Mic Right", NULL, "Mic Right Source"},
829
830 {"Aux Left", NULL, "AUXL"},
831 {"Aux Right", NULL, "AUXR"},
832
833 {"In Mixer Left", "Mic Left Switch", "Mic Left"},
834 {"In Mixer Left", "Mic Right Switch", "Mic Right"},
835 {"In Mixer Left", "Aux Left Switch", "Aux Left"},
836
837 {"In Mixer Right", "Mic Right Switch", "Mic Right"},
838 {"In Mixer Right", "Mic Left Switch", "Mic Left"},
839 {"In Mixer Right", "Aux Right Switch", "Aux Right"},
840 {"In Mixer Right", "Mixin Left Switch", "MIXIN Left"},
841
842 {"MIXIN Left", NULL, "In Mixer Left"},
843 {"ADC Left", NULL, "MIXIN Left"},
844
845 {"MIXIN Right", NULL, "In Mixer Right"},
846 {"ADC Right", NULL, "MIXIN Right"},
847
848 {"ADC Left", NULL, "AIF"},
849 {"ADC Right", NULL, "AIF"},
850
851 /* Output path */
852 {"AIFIN Left", NULL, "AIF"},
853 {"AIFIN Right", NULL, "AIF"},
854
855 {"DAC Left Source", "ADC output left", "ADC Left"},
856 {"DAC Left Source", "ADC output right", "ADC Right"},
857 {"DAC Left Source", "AIF input left", "AIFIN Left"},
858 {"DAC Left Source", "AIF input right", "AIFIN Right"},
859
860 {"DAC Right Source", "ADC output left", "ADC Left"},
861 {"DAC Right Source", "ADC output right", "ADC Right"},
862 {"DAC Right Source", "AIF input left", "AIFIN Left"},
863 {"DAC Right Source", "AIF input right", "AIFIN Right"},
864
865 {"DAC Left", NULL, "DAC Left Source"},
866 {"DAC Right", NULL, "DAC Right Source"},
867
868 {"Out Mixer Left", "Aux Left Switch", "Aux Left"},
869 {"Out Mixer Left", "Mixin Left Switch", "MIXIN Left"},
870 {"Out Mixer Left", "Mixin Right Switch", "MIXIN Right"},
871 {"Out Mixer Left", "Aux Left Invert Switch", "Aux Left"},
872 {"Out Mixer Left", "Mixin Left Invert Switch", "MIXIN Left"},
873 {"Out Mixer Left", "Mixin Right Invert Switch", "MIXIN Right"},
874 {"Out Mixer Left", "DAC Left Switch", "DAC Left"},
875
876 {"Out Mixer Right", "Aux Right Switch", "Aux Right"},
877 {"Out Mixer Right", "Mixin Right Switch", "MIXIN Right"},
878 {"Out Mixer Right", "Mixin Left Switch", "MIXIN Left"},
879 {"Out Mixer Right", "Aux Right Invert Switch", "Aux Right"},
880 {"Out Mixer Right", "Mixin Right Invert Switch", "MIXIN Right"},
881 {"Out Mixer Right", "Mixin Left Invert Switch", "MIXIN Left"},
882 {"Out Mixer Right", "DAC Right Switch", "DAC Right"},
883
884 {"MIXOUT Left", NULL, "Out Mixer Left"},
885 {"Headphone Left", NULL, "MIXOUT Left"},
886 {"Headphone Left", NULL, "Charge Pump"},
887 {"HPL", NULL, "Headphone Left"},
888
889 {"MIXOUT Right", NULL, "Out Mixer Right"},
890 {"Headphone Right", NULL, "MIXOUT Right"},
891 {"Headphone Right", NULL, "Charge Pump"},
892 {"HPR", NULL, "Headphone Right"},
893
894 {"MIXOUT Right", NULL, "Out Mixer Right"},
895 {"Lineout", NULL, "MIXOUT Right"},
896 {"LINE", NULL, "Lineout"},
897};
898
899/* Codec private data */
900struct da9055_priv {
901 struct regmap *regmap;
902 unsigned int mclk_rate;
903 int master;
904 struct da9055_platform_data *pdata;
905};
906
907static struct reg_default da9055_reg_defaults[] = {
908 { 0x21, 0x10 },
909 { 0x22, 0x0A },
910 { 0x23, 0x00 },
911 { 0x24, 0x00 },
912 { 0x25, 0x00 },
913 { 0x26, 0x00 },
914 { 0x27, 0x0C },
915 { 0x28, 0x01 },
916 { 0x29, 0x08 },
917 { 0x2A, 0x32 },
918 { 0x2B, 0x00 },
919 { 0x30, 0x35 },
920 { 0x31, 0x35 },
921 { 0x32, 0x00 },
922 { 0x33, 0x00 },
923 { 0x34, 0x03 },
924 { 0x35, 0x03 },
925 { 0x36, 0x6F },
926 { 0x37, 0x6F },
927 { 0x38, 0x80 },
928 { 0x39, 0x01 },
929 { 0x3A, 0x01 },
930 { 0x40, 0x00 },
931 { 0x41, 0x88 },
932 { 0x42, 0x88 },
933 { 0x43, 0x08 },
934 { 0x44, 0x80 },
935 { 0x45, 0x6F },
936 { 0x46, 0x6F },
937 { 0x47, 0x61 },
938 { 0x48, 0x35 },
939 { 0x49, 0x35 },
940 { 0x4A, 0x35 },
941 { 0x4B, 0x00 },
942 { 0x4C, 0x00 },
943 { 0x60, 0x44 },
944 { 0x61, 0x44 },
945 { 0x62, 0x00 },
946 { 0x63, 0x40 },
947 { 0x64, 0x40 },
948 { 0x65, 0x40 },
949 { 0x66, 0x40 },
950 { 0x67, 0x40 },
951 { 0x68, 0x40 },
952 { 0x69, 0x48 },
953 { 0x6A, 0x40 },
954 { 0x6B, 0x41 },
955 { 0x6C, 0x40 },
956 { 0x6D, 0x40 },
957 { 0x6E, 0x10 },
958 { 0x6F, 0x10 },
959 { 0x90, 0x80 },
960 { 0x92, 0x02 },
961 { 0x93, 0x00 },
962 { 0x99, 0x00 },
963 { 0x9A, 0x00 },
964 { 0x9B, 0x00 },
965 { 0x9C, 0x3F },
966 { 0x9D, 0x00 },
967 { 0x9E, 0x3F },
968 { 0x9F, 0xFF },
969 { 0xA0, 0x71 },
970 { 0xA1, 0x00 },
971 { 0xA2, 0x00 },
972 { 0xA6, 0x00 },
973 { 0xA7, 0x00 },
974 { 0xAB, 0x00 },
975 { 0xAC, 0x00 },
976 { 0xAD, 0x00 },
977 { 0xAF, 0x08 },
978 { 0xB0, 0x00 },
979 { 0xB1, 0x00 },
980 { 0xB2, 0x00 },
981};
982
983static bool da9055_volatile_register(struct device *dev,
984 unsigned int reg)
985{
986 switch (reg) {
987 case DA9055_STATUS1:
988 case DA9055_PLL_STATUS:
989 case DA9055_AUX_L_GAIN_STATUS:
990 case DA9055_AUX_R_GAIN_STATUS:
991 case DA9055_MIC_L_GAIN_STATUS:
992 case DA9055_MIC_R_GAIN_STATUS:
993 case DA9055_MIXIN_L_GAIN_STATUS:
994 case DA9055_MIXIN_R_GAIN_STATUS:
995 case DA9055_ADC_L_GAIN_STATUS:
996 case DA9055_ADC_R_GAIN_STATUS:
997 case DA9055_DAC_L_GAIN_STATUS:
998 case DA9055_DAC_R_GAIN_STATUS:
999 case DA9055_HP_L_GAIN_STATUS:
1000 case DA9055_HP_R_GAIN_STATUS:
1001 case DA9055_LINE_GAIN_STATUS:
1002 case DA9055_ALC_CIC_OP_LVL_DATA:
1003 return 1;
1004 default:
1005 return 0;
1006 }
1007}
1008
1009/* Set DAI word length */
1010static int da9055_hw_params(struct snd_pcm_substream *substream,
1011 struct snd_pcm_hw_params *params,
1012 struct snd_soc_dai *dai)
1013{
1014 struct snd_soc_codec *codec = dai->codec;
1015 struct da9055_priv *da9055 = snd_soc_codec_get_drvdata(codec);
1016 u8 aif_ctrl, fs;
1017 u32 sysclk;
1018
1019 switch (params_format(params)) {
1020 case SNDRV_PCM_FORMAT_S16_LE:
1021 aif_ctrl = DA9055_AIF_WORD_S16_LE;
1022 break;
1023 case SNDRV_PCM_FORMAT_S20_3LE:
1024 aif_ctrl = DA9055_AIF_WORD_S20_3LE;
1025 break;
1026 case SNDRV_PCM_FORMAT_S24_LE:
1027 aif_ctrl = DA9055_AIF_WORD_S24_LE;
1028 break;
1029 case SNDRV_PCM_FORMAT_S32_LE:
1030 aif_ctrl = DA9055_AIF_WORD_S32_LE;
1031 break;
1032 default:
1033 return -EINVAL;
1034 }
1035
1036 /* Set AIF format */
1037 snd_soc_update_bits(codec, DA9055_AIF_CTRL, DA9055_AIF_WORD_LENGTH_MASK,
1038 aif_ctrl);
1039
1040 switch (params_rate(params)) {
1041 case 8000:
1042 fs = DA9055_SR_8000;
1043 sysclk = 3072000;
1044 break;
1045 case 11025:
1046 fs = DA9055_SR_11025;
1047 sysclk = 2822400;
1048 break;
1049 case 12000:
1050 fs = DA9055_SR_12000;
1051 sysclk = 3072000;
1052 break;
1053 case 16000:
1054 fs = DA9055_SR_16000;
1055 sysclk = 3072000;
1056 break;
1057 case 22050:
1058 fs = DA9055_SR_22050;
1059 sysclk = 2822400;
1060 break;
1061 case 32000:
1062 fs = DA9055_SR_32000;
1063 sysclk = 3072000;
1064 break;
1065 case 44100:
1066 fs = DA9055_SR_44100;
1067 sysclk = 2822400;
1068 break;
1069 case 48000:
1070 fs = DA9055_SR_48000;
1071 sysclk = 3072000;
1072 break;
1073 case 88200:
1074 fs = DA9055_SR_88200;
1075 sysclk = 2822400;
1076 break;
1077 case 96000:
1078 fs = DA9055_SR_96000;
1079 sysclk = 3072000;
1080 break;
1081 default:
1082 return -EINVAL;
1083 }
1084
1085 if (da9055->mclk_rate) {
1086 /* PLL Mode, Write actual FS */
1087 snd_soc_write(codec, DA9055_SR, fs);
1088 } else {
1089 /*
1090 * Non-PLL Mode
1091 * When PLL is bypassed, chip assumes constant MCLK of
1092 * 12.288MHz and uses sample rate value to divide this MCLK
1093 * to derive its sys clk. As sys clk has to be 256 * Fs, we
1094 * need to write constant sample rate i.e. 48KHz.
1095 */
1096 snd_soc_write(codec, DA9055_SR, DA9055_SR_48000);
1097 }
1098
1099 if (da9055->mclk_rate && (da9055->mclk_rate != sysclk)) {
1100 /* PLL Mode */
1101 if (!da9055->master) {
1102 /* PLL slave mode, enable PLL and also SRM */
1103 snd_soc_update_bits(codec, DA9055_PLL_CTRL,
1104 DA9055_PLL_EN | DA9055_PLL_SRM_EN,
1105 DA9055_PLL_EN | DA9055_PLL_SRM_EN);
1106 } else {
1107 /* PLL master mode, only enable PLL */
1108 snd_soc_update_bits(codec, DA9055_PLL_CTRL,
1109 DA9055_PLL_EN, DA9055_PLL_EN);
1110 }
1111 } else {
1112 /* Non PLL Mode, disable PLL */
1113 snd_soc_update_bits(codec, DA9055_PLL_CTRL, DA9055_PLL_EN, 0);
1114 }
1115
1116 return 0;
1117}
1118
1119/* Set DAI mode and Format */
1120static int da9055_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1121{
1122 struct snd_soc_codec *codec = codec_dai->codec;
1123 struct da9055_priv *da9055 = snd_soc_codec_get_drvdata(codec);
1124 u8 aif_clk_mode, aif_ctrl, mode;
1125
1126 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1127 case SND_SOC_DAIFMT_CBM_CFM:
1128 /* DA9055 in I2S Master Mode */
1129 mode = 1;
1130 aif_clk_mode = DA9055_AIF_CLK_EN_MASTER_MODE;
1131 break;
1132 case SND_SOC_DAIFMT_CBS_CFS:
1133 /* DA9055 in I2S Slave Mode */
1134 mode = 0;
1135 aif_clk_mode = DA9055_AIF_CLK_EN_SLAVE_MODE;
1136 break;
1137 default:
1138 return -EINVAL;
1139 }
1140
1141 /* Don't allow change of mode if PLL is enabled */
1142 if ((snd_soc_read(codec, DA9055_PLL_CTRL) & DA9055_PLL_EN) &&
1143 (da9055->master != mode))
1144 return -EINVAL;
1145
1146 da9055->master = mode;
1147
1148 /* Only I2S is supported */
1149 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1150 case SND_SOC_DAIFMT_I2S:
1151 aif_ctrl = DA9055_AIF_FORMAT_I2S_MODE;
1152 break;
1153 case SND_SOC_DAIFMT_LEFT_J:
1154 aif_ctrl = DA9055_AIF_FORMAT_LEFT_J;
1155 break;
1156 case SND_SOC_DAIFMT_RIGHT_J:
1157 aif_ctrl = DA9055_AIF_FORMAT_RIGHT_J;
1158 break;
Ashish Chavan5e82aaa2012-10-11 13:44:39 +05301159 case SND_SOC_DAIFMT_DSP_A:
1160 aif_ctrl = DA9055_AIF_FORMAT_DSP;
1161 break;
Ashish Chavan9911f7f2012-09-21 20:16:17 +05301162 default:
1163 return -EINVAL;
1164 }
1165
1166 /* By default only 32 BCLK per WCLK is supported */
1167 aif_clk_mode |= DA9055_AIF_BCLKS_PER_WCLK_32;
1168
1169 snd_soc_update_bits(codec, DA9055_AIF_CLK_MODE,
1170 (DA9055_AIF_CLK_MODE_MASK | DA9055_AIF_BCLK_MASK),
1171 aif_clk_mode);
1172 snd_soc_update_bits(codec, DA9055_AIF_CTRL, DA9055_AIF_FORMAT_MASK,
1173 aif_ctrl);
1174 return 0;
1175}
1176
1177static int da9055_mute(struct snd_soc_dai *dai, int mute)
1178{
1179 struct snd_soc_codec *codec = dai->codec;
1180
1181 if (mute) {
1182 snd_soc_update_bits(codec, DA9055_DAC_L_CTRL,
1183 DA9055_DAC_L_MUTE_EN, DA9055_DAC_L_MUTE_EN);
1184 snd_soc_update_bits(codec, DA9055_DAC_R_CTRL,
1185 DA9055_DAC_R_MUTE_EN, DA9055_DAC_R_MUTE_EN);
1186 } else {
1187 snd_soc_update_bits(codec, DA9055_DAC_L_CTRL,
1188 DA9055_DAC_L_MUTE_EN, 0);
1189 snd_soc_update_bits(codec, DA9055_DAC_R_CTRL,
1190 DA9055_DAC_R_MUTE_EN, 0);
1191 }
1192
1193 return 0;
1194}
1195
1196#define DA9055_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1197 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
1198
1199static int da9055_set_dai_sysclk(struct snd_soc_dai *codec_dai,
1200 int clk_id, unsigned int freq, int dir)
1201{
1202 struct snd_soc_codec *codec = codec_dai->codec;
1203 struct da9055_priv *da9055 = snd_soc_codec_get_drvdata(codec);
1204
1205 switch (clk_id) {
1206 case DA9055_CLKSRC_MCLK:
1207 switch (freq) {
1208 case 11289600:
1209 case 12000000:
1210 case 12288000:
1211 case 13000000:
1212 case 13500000:
1213 case 14400000:
1214 case 19200000:
1215 case 19680000:
1216 case 19800000:
1217 da9055->mclk_rate = freq;
1218 return 0;
1219 default:
1220 dev_err(codec_dai->dev, "Unsupported MCLK value %d\n",
1221 freq);
1222 return -EINVAL;
1223 }
1224 break;
1225 default:
1226 dev_err(codec_dai->dev, "Unknown clock source %d\n", clk_id);
1227 return -EINVAL;
1228 }
1229}
1230
1231/*
1232 * da9055_set_dai_pll : Configure the codec PLL
1233 * @param codec_dai : Pointer to codec DAI
1234 * @param pll_id : da9055 has only one pll, so pll_id is always zero
1235 * @param fref : Input MCLK frequency
1236 * @param fout : FsDM value
1237 * @return int : Zero for success, negative error code for error
1238 *
1239 * Note: Supported PLL input frequencies are 11.2896MHz, 12MHz, 12.288MHz,
1240 * 13MHz, 13.5MHz, 14.4MHz, 19.2MHz, 19.6MHz and 19.8MHz
1241 */
1242static int da9055_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
1243 int source, unsigned int fref, unsigned int fout)
1244{
1245 struct snd_soc_codec *codec = codec_dai->codec;
1246 struct da9055_priv *da9055 = snd_soc_codec_get_drvdata(codec);
1247
1248 u8 pll_frac_top, pll_frac_bot, pll_integer, cnt;
1249
1250 /* Disable PLL before setting the divisors */
1251 snd_soc_update_bits(codec, DA9055_PLL_CTRL, DA9055_PLL_EN, 0);
1252
1253 /* In slave mode, there is only one set of divisors */
1254 if (!da9055->master && (fout != 2822400))
1255 goto pll_err;
1256
1257 /* Search pll div array for correct divisors */
1258 for (cnt = 0; cnt < ARRAY_SIZE(da9055_pll_div); cnt++) {
1259 /* Check fref, mode and fout */
1260 if ((fref == da9055_pll_div[cnt].fref) &&
1261 (da9055->master == da9055_pll_div[cnt].mode) &&
1262 (fout == da9055_pll_div[cnt].fout)) {
1263 /* All match, pick up divisors */
1264 pll_frac_top = da9055_pll_div[cnt].frac_top;
1265 pll_frac_bot = da9055_pll_div[cnt].frac_bot;
1266 pll_integer = da9055_pll_div[cnt].integer;
1267 break;
1268 }
1269 }
1270 if (cnt >= ARRAY_SIZE(da9055_pll_div))
1271 goto pll_err;
1272
1273 /* Write PLL dividers */
1274 snd_soc_write(codec, DA9055_PLL_FRAC_TOP, pll_frac_top);
1275 snd_soc_write(codec, DA9055_PLL_FRAC_BOT, pll_frac_bot);
1276 snd_soc_write(codec, DA9055_PLL_INTEGER, pll_integer);
1277
1278 return 0;
1279pll_err:
1280 dev_err(codec_dai->dev, "Error in setting up PLL\n");
1281 return -EINVAL;
1282}
1283
1284/* DAI operations */
1285static const struct snd_soc_dai_ops da9055_dai_ops = {
1286 .hw_params = da9055_hw_params,
1287 .set_fmt = da9055_set_dai_fmt,
1288 .set_sysclk = da9055_set_dai_sysclk,
1289 .set_pll = da9055_set_dai_pll,
1290 .digital_mute = da9055_mute,
1291};
1292
1293static struct snd_soc_dai_driver da9055_dai = {
1294 .name = "da9055-hifi",
1295 /* Playback Capabilities */
1296 .playback = {
1297 .stream_name = "Playback",
1298 .channels_min = 1,
1299 .channels_max = 2,
1300 .rates = SNDRV_PCM_RATE_8000_96000,
1301 .formats = DA9055_FORMATS,
1302 },
1303 /* Capture Capabilities */
1304 .capture = {
1305 .stream_name = "Capture",
1306 .channels_min = 1,
1307 .channels_max = 2,
1308 .rates = SNDRV_PCM_RATE_8000_96000,
1309 .formats = DA9055_FORMATS,
1310 },
1311 .ops = &da9055_dai_ops,
1312 .symmetric_rates = 1,
1313};
1314
1315static int da9055_set_bias_level(struct snd_soc_codec *codec,
1316 enum snd_soc_bias_level level)
1317{
1318 switch (level) {
1319 case SND_SOC_BIAS_ON:
1320 case SND_SOC_BIAS_PREPARE:
1321 break;
1322 case SND_SOC_BIAS_STANDBY:
1323 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
1324 /* Enable VMID reference & master bias */
1325 snd_soc_update_bits(codec, DA9055_REFERENCES,
1326 DA9055_VMID_EN | DA9055_BIAS_EN,
1327 DA9055_VMID_EN | DA9055_BIAS_EN);
1328 }
1329 break;
1330 case SND_SOC_BIAS_OFF:
1331 /* Disable VMID reference & master bias */
1332 snd_soc_update_bits(codec, DA9055_REFERENCES,
1333 DA9055_VMID_EN | DA9055_BIAS_EN, 0);
1334 break;
1335 }
1336 codec->dapm.bias_level = level;
1337 return 0;
1338}
1339
1340static int da9055_probe(struct snd_soc_codec *codec)
1341{
1342 int ret;
1343 struct da9055_priv *da9055 = snd_soc_codec_get_drvdata(codec);
1344
1345 codec->control_data = da9055->regmap;
1346 ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
1347 if (ret < 0) {
1348 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1349 return ret;
1350 }
1351
1352 /* Enable all Gain Ramps */
1353 snd_soc_update_bits(codec, DA9055_AUX_L_CTRL,
1354 DA9055_GAIN_RAMPING_EN, DA9055_GAIN_RAMPING_EN);
1355 snd_soc_update_bits(codec, DA9055_AUX_R_CTRL,
1356 DA9055_GAIN_RAMPING_EN, DA9055_GAIN_RAMPING_EN);
1357 snd_soc_update_bits(codec, DA9055_MIXIN_L_CTRL,
1358 DA9055_GAIN_RAMPING_EN, DA9055_GAIN_RAMPING_EN);
1359 snd_soc_update_bits(codec, DA9055_MIXIN_R_CTRL,
1360 DA9055_GAIN_RAMPING_EN, DA9055_GAIN_RAMPING_EN);
1361 snd_soc_update_bits(codec, DA9055_ADC_L_CTRL,
1362 DA9055_GAIN_RAMPING_EN, DA9055_GAIN_RAMPING_EN);
1363 snd_soc_update_bits(codec, DA9055_ADC_R_CTRL,
1364 DA9055_GAIN_RAMPING_EN, DA9055_GAIN_RAMPING_EN);
1365 snd_soc_update_bits(codec, DA9055_DAC_L_CTRL,
1366 DA9055_GAIN_RAMPING_EN, DA9055_GAIN_RAMPING_EN);
1367 snd_soc_update_bits(codec, DA9055_DAC_R_CTRL,
1368 DA9055_GAIN_RAMPING_EN, DA9055_GAIN_RAMPING_EN);
1369 snd_soc_update_bits(codec, DA9055_HP_L_CTRL,
1370 DA9055_GAIN_RAMPING_EN, DA9055_GAIN_RAMPING_EN);
1371 snd_soc_update_bits(codec, DA9055_HP_R_CTRL,
1372 DA9055_GAIN_RAMPING_EN, DA9055_GAIN_RAMPING_EN);
1373 snd_soc_update_bits(codec, DA9055_LINE_CTRL,
1374 DA9055_GAIN_RAMPING_EN, DA9055_GAIN_RAMPING_EN);
1375
1376 /*
1377 * There are two separate control bits for input and output mixers as
1378 * well as headphone and line outs.
1379 * One to enable corresponding amplifier and other to enable its
1380 * output. As amplifier bits are related to power control, they are
1381 * being managed by DAPM while other (non power related) bits are
1382 * enabled here
1383 */
1384 snd_soc_update_bits(codec, DA9055_MIXIN_L_CTRL,
1385 DA9055_MIXIN_L_MIX_EN, DA9055_MIXIN_L_MIX_EN);
1386 snd_soc_update_bits(codec, DA9055_MIXIN_R_CTRL,
1387 DA9055_MIXIN_R_MIX_EN, DA9055_MIXIN_R_MIX_EN);
1388
1389 snd_soc_update_bits(codec, DA9055_MIXOUT_L_CTRL,
1390 DA9055_MIXOUT_L_MIX_EN, DA9055_MIXOUT_L_MIX_EN);
1391 snd_soc_update_bits(codec, DA9055_MIXOUT_R_CTRL,
1392 DA9055_MIXOUT_R_MIX_EN, DA9055_MIXOUT_R_MIX_EN);
1393
1394 snd_soc_update_bits(codec, DA9055_HP_L_CTRL,
1395 DA9055_HP_L_AMP_OE, DA9055_HP_L_AMP_OE);
1396 snd_soc_update_bits(codec, DA9055_HP_R_CTRL,
1397 DA9055_HP_R_AMP_OE, DA9055_HP_R_AMP_OE);
1398
1399 snd_soc_update_bits(codec, DA9055_LINE_CTRL,
1400 DA9055_LINE_AMP_OE, DA9055_LINE_AMP_OE);
1401
1402 /* Set this as per your system configuration */
1403 snd_soc_write(codec, DA9055_PLL_CTRL, DA9055_PLL_INDIV_10_20_MHZ);
1404
1405 /* Set platform data values */
1406 if (da9055->pdata) {
1407 /* set mic bias source */
1408 if (da9055->pdata->micbias_source) {
1409 snd_soc_update_bits(codec, DA9055_MIXIN_R_SELECT,
1410 DA9055_MICBIAS2_EN,
1411 DA9055_MICBIAS2_EN);
1412 } else {
1413 snd_soc_update_bits(codec, DA9055_MIXIN_R_SELECT,
1414 DA9055_MICBIAS2_EN, 0);
1415 }
1416 /* set mic bias voltage */
1417 switch (da9055->pdata->micbias) {
1418 case DA9055_MICBIAS_2_2V:
1419 case DA9055_MICBIAS_2_1V:
1420 case DA9055_MICBIAS_1_8V:
1421 case DA9055_MICBIAS_1_6V:
1422 snd_soc_update_bits(codec, DA9055_MIC_CONFIG,
1423 DA9055_MICBIAS_LEVEL_MASK,
1424 (da9055->pdata->micbias) << 4);
1425 break;
1426 }
1427 }
1428 return 0;
1429}
1430
1431static struct snd_soc_codec_driver soc_codec_dev_da9055 = {
1432 .probe = da9055_probe,
1433 .set_bias_level = da9055_set_bias_level,
1434
1435 .controls = da9055_snd_controls,
1436 .num_controls = ARRAY_SIZE(da9055_snd_controls),
1437
1438 .dapm_widgets = da9055_dapm_widgets,
1439 .num_dapm_widgets = ARRAY_SIZE(da9055_dapm_widgets),
1440 .dapm_routes = da9055_audio_map,
1441 .num_dapm_routes = ARRAY_SIZE(da9055_audio_map),
1442};
1443
1444static const struct regmap_config da9055_regmap_config = {
1445 .reg_bits = 8,
1446 .val_bits = 8,
1447
1448 .reg_defaults = da9055_reg_defaults,
1449 .num_reg_defaults = ARRAY_SIZE(da9055_reg_defaults),
1450 .volatile_reg = da9055_volatile_register,
1451 .cache_type = REGCACHE_RBTREE,
1452};
1453
1454static int __devinit da9055_i2c_probe(struct i2c_client *i2c,
1455 const struct i2c_device_id *id)
1456{
1457 struct da9055_priv *da9055;
1458 struct da9055_platform_data *pdata = dev_get_platdata(&i2c->dev);
1459 int ret;
1460
1461 da9055 = devm_kzalloc(&i2c->dev, sizeof(struct da9055_priv),
1462 GFP_KERNEL);
1463 if (!da9055)
1464 return -ENOMEM;
1465
1466 if (pdata)
1467 da9055->pdata = pdata;
1468
1469 i2c_set_clientdata(i2c, da9055);
1470
1471 da9055->regmap = devm_regmap_init_i2c(i2c, &da9055_regmap_config);
1472 if (IS_ERR(da9055->regmap)) {
1473 ret = PTR_ERR(da9055->regmap);
1474 dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
1475 return ret;
1476 }
1477
1478 ret = snd_soc_register_codec(&i2c->dev,
1479 &soc_codec_dev_da9055, &da9055_dai, 1);
1480 if (ret < 0) {
1481 dev_err(&i2c->dev, "Failed to register da9055 codec: %d\n",
1482 ret);
1483 }
1484 return ret;
1485}
1486
1487static int __devexit da9055_remove(struct i2c_client *client)
1488{
1489 snd_soc_unregister_codec(&client->dev);
1490 return 0;
1491}
1492
1493static const struct i2c_device_id da9055_i2c_id[] = {
1494 { "da9055", 0 },
1495 { }
1496};
1497MODULE_DEVICE_TABLE(i2c, da9055_i2c_id);
1498
1499/* I2C codec control layer */
1500static struct i2c_driver da9055_i2c_driver = {
1501 .driver = {
1502 .name = "da9055",
1503 .owner = THIS_MODULE,
1504 },
1505 .probe = da9055_i2c_probe,
1506 .remove = __devexit_p(da9055_remove),
1507 .id_table = da9055_i2c_id,
1508};
1509
1510module_i2c_driver(da9055_i2c_driver);
1511
1512MODULE_DESCRIPTION("ASoC DA9055 Codec driver");
1513MODULE_AUTHOR("David Chen, Ashish Chavan");
1514MODULE_LICENSE("GPL");