2 * ALSA SoC TLV320AIC23 codec driver
4 * Author: Arun KS, <arunks@mistralsolutions.com>
5 * Copyright: (C) 2008 Mistral Solutions Pvt Ltd.,
7 * Based on sound/soc/codecs/wm8731.c by Richard Purdie
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 * The AIC23 is a driver for a low power stereo audio
17 * The machine layer should disable unsupported inputs/outputs by
18 * snd_soc_dapm_disable_pin(codec, "LHPOUT"), etc.
21 #include <linux/module.h>
22 #include <linux/moduleparam.h>
23 #include <linux/init.h>
24 #include <linux/delay.h>
26 #include <linux/i2c.h>
27 #include <linux/platform_device.h>
28 #include <linux/slab.h>
29 #include <sound/core.h>
30 #include <sound/pcm.h>
31 #include <sound/pcm_params.h>
32 #include <sound/soc.h>
33 #include <sound/soc-dapm.h>
34 #include <sound/tlv.h>
35 #include <sound/initval.h>
37 #include "tlv320aic23.h"
39 #define AIC23_VERSION "0.1"
42 * AIC23 register cache
44 static const u16 tlv320aic23_reg
[] = {
45 0x0097, 0x0097, 0x00F9, 0x00F9, /* 0 */
46 0x001A, 0x0004, 0x0007, 0x0001, /* 4 */
47 0x0020, 0x0000, 0x0000, 0x0000, /* 8 */
48 0x0000, 0x0000, 0x0000, 0x0000, /* 12 */
52 * read tlv320aic23 register cache
54 static inline unsigned int tlv320aic23_read_reg_cache(struct snd_soc_codec
55 *codec
, unsigned int reg
)
57 u16
*cache
= codec
->reg_cache
;
58 if (reg
>= ARRAY_SIZE(tlv320aic23_reg
))
64 * write tlv320aic23 register cache
66 static inline void tlv320aic23_write_reg_cache(struct snd_soc_codec
*codec
,
69 u16
*cache
= codec
->reg_cache
;
70 if (reg
>= ARRAY_SIZE(tlv320aic23_reg
))
76 * write to the tlv320aic23 register space
78 static int tlv320aic23_write(struct snd_soc_codec
*codec
, unsigned int reg
,
84 /* TLV320AIC23 has 7 bit address and 9 bits of data
85 * so we need to switch one data bit into reg and rest
89 if (reg
> 9 && reg
!= 15) {
90 printk(KERN_WARNING
"%s Invalid register R%u\n", __func__
, reg
);
94 data
[0] = (reg
<< 1) | (value
>> 8 & 0x01);
95 data
[1] = value
& 0xff;
97 tlv320aic23_write_reg_cache(codec
, reg
, value
);
99 if (codec
->hw_write(codec
->control_data
, data
, 2) == 2)
102 printk(KERN_ERR
"%s cannot write %03x to register R%u\n", __func__
,
108 static const char *rec_src_text
[] = { "Line", "Mic" };
109 static const char *deemph_text
[] = {"None", "32Khz", "44.1Khz", "48Khz"};
111 static const struct soc_enum rec_src_enum
=
112 SOC_ENUM_SINGLE(TLV320AIC23_ANLG
, 2, 2, rec_src_text
);
114 static const struct snd_kcontrol_new tlv320aic23_rec_src_mux_controls
=
115 SOC_DAPM_ENUM("Input Select", rec_src_enum
);
117 static const struct soc_enum tlv320aic23_rec_src
=
118 SOC_ENUM_SINGLE(TLV320AIC23_ANLG
, 2, 2, rec_src_text
);
119 static const struct soc_enum tlv320aic23_deemph
=
120 SOC_ENUM_SINGLE(TLV320AIC23_DIGT
, 1, 4, deemph_text
);
122 static const DECLARE_TLV_DB_SCALE(out_gain_tlv
, -12100, 100, 0);
123 static const DECLARE_TLV_DB_SCALE(input_gain_tlv
, -1725, 75, 0);
124 static const DECLARE_TLV_DB_SCALE(sidetone_vol_tlv
, -1800, 300, 0);
126 static int snd_soc_tlv320aic23_put_volsw(struct snd_kcontrol
*kcontrol
,
127 struct snd_ctl_elem_value
*ucontrol
)
129 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
132 val
= (ucontrol
->value
.integer
.value
[0] & 0x07);
134 /* linear conversion to userspace
141 val
= (val
>= 4) ? 4 : (3 - val
);
143 reg
= tlv320aic23_read_reg_cache(codec
, TLV320AIC23_ANLG
) & (~0x1C0);
144 tlv320aic23_write(codec
, TLV320AIC23_ANLG
, reg
| (val
<< 6));
149 static int snd_soc_tlv320aic23_get_volsw(struct snd_kcontrol
*kcontrol
,
150 struct snd_ctl_elem_value
*ucontrol
)
152 struct snd_soc_codec
*codec
= snd_kcontrol_chip(kcontrol
);
155 val
= tlv320aic23_read_reg_cache(codec
, TLV320AIC23_ANLG
) & (0x1C0);
157 val
= (val
>= 4) ? 4 : (3 - val
);
158 ucontrol
->value
.integer
.value
[0] = val
;
163 #define SOC_TLV320AIC23_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
164 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
165 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
166 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
167 .tlv.p = (tlv_array), \
168 .info = snd_soc_info_volsw, .get = snd_soc_tlv320aic23_get_volsw,\
169 .put = snd_soc_tlv320aic23_put_volsw, \
170 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
172 static const struct snd_kcontrol_new tlv320aic23_snd_controls
[] = {
173 SOC_DOUBLE_R_TLV("Digital Playback Volume", TLV320AIC23_LCHNVOL
,
174 TLV320AIC23_RCHNVOL
, 0, 127, 0, out_gain_tlv
),
175 SOC_SINGLE("Digital Playback Switch", TLV320AIC23_DIGT
, 3, 1, 1),
176 SOC_DOUBLE_R("Line Input Switch", TLV320AIC23_LINVOL
,
177 TLV320AIC23_RINVOL
, 7, 1, 0),
178 SOC_DOUBLE_R_TLV("Line Input Volume", TLV320AIC23_LINVOL
,
179 TLV320AIC23_RINVOL
, 0, 31, 0, input_gain_tlv
),
180 SOC_SINGLE("Mic Input Switch", TLV320AIC23_ANLG
, 1, 1, 1),
181 SOC_SINGLE("Mic Booster Switch", TLV320AIC23_ANLG
, 0, 1, 0),
182 SOC_TLV320AIC23_SINGLE_TLV("Sidetone Volume", TLV320AIC23_ANLG
,
183 6, 4, 0, sidetone_vol_tlv
),
184 SOC_ENUM("Playback De-emphasis", tlv320aic23_deemph
),
187 /* PGA Mixer controls for Line and Mic switch */
188 static const struct snd_kcontrol_new tlv320aic23_output_mixer_controls
[] = {
189 SOC_DAPM_SINGLE("Line Bypass Switch", TLV320AIC23_ANLG
, 3, 1, 0),
190 SOC_DAPM_SINGLE("Mic Sidetone Switch", TLV320AIC23_ANLG
, 5, 1, 0),
191 SOC_DAPM_SINGLE("Playback Switch", TLV320AIC23_ANLG
, 4, 1, 0),
194 static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets
[] = {
195 SND_SOC_DAPM_DAC("DAC", "Playback", TLV320AIC23_PWR
, 3, 1),
196 SND_SOC_DAPM_ADC("ADC", "Capture", TLV320AIC23_PWR
, 2, 1),
197 SND_SOC_DAPM_MUX("Capture Source", SND_SOC_NOPM
, 0, 0,
198 &tlv320aic23_rec_src_mux_controls
),
199 SND_SOC_DAPM_MIXER("Output Mixer", TLV320AIC23_PWR
, 4, 1,
200 &tlv320aic23_output_mixer_controls
[0],
201 ARRAY_SIZE(tlv320aic23_output_mixer_controls
)),
202 SND_SOC_DAPM_PGA("Line Input", TLV320AIC23_PWR
, 0, 1, NULL
, 0),
203 SND_SOC_DAPM_PGA("Mic Input", TLV320AIC23_PWR
, 1, 1, NULL
, 0),
205 SND_SOC_DAPM_OUTPUT("LHPOUT"),
206 SND_SOC_DAPM_OUTPUT("RHPOUT"),
207 SND_SOC_DAPM_OUTPUT("LOUT"),
208 SND_SOC_DAPM_OUTPUT("ROUT"),
210 SND_SOC_DAPM_INPUT("LLINEIN"),
211 SND_SOC_DAPM_INPUT("RLINEIN"),
213 SND_SOC_DAPM_INPUT("MICIN"),
216 static const struct snd_soc_dapm_route intercon
[] = {
218 {"Output Mixer", "Line Bypass Switch", "Line Input"},
219 {"Output Mixer", "Playback Switch", "DAC"},
220 {"Output Mixer", "Mic Sidetone Switch", "Mic Input"},
223 {"RHPOUT", NULL
, "Output Mixer"},
224 {"LHPOUT", NULL
, "Output Mixer"},
225 {"LOUT", NULL
, "Output Mixer"},
226 {"ROUT", NULL
, "Output Mixer"},
229 {"Line Input", "NULL", "LLINEIN"},
230 {"Line Input", "NULL", "RLINEIN"},
232 {"Mic Input", "NULL", "MICIN"},
235 {"Capture Source", "Line", "Line Input"},
236 {"Capture Source", "Mic", "Mic Input"},
237 {"ADC", NULL
, "Capture Source"},
241 /* AIC23 driver data */
243 struct snd_soc_codec codec
;
250 * Common Crystals used
251 * 11.2896 Mhz /128 = *88.2k /192 = 58.8k
252 * 12.0000 Mhz /125 = *96k /136 = 88.235K
253 * 12.2880 Mhz /128 = *96k /192 = 64k
254 * 16.9344 Mhz /128 = 132.3k /192 = *88.2k
255 * 18.4320 Mhz /128 = 144k /192 = *96k
259 * Normal BOSR 0-256/2 = 128, 1-384/2 = 192
260 * USB BOSR 0-250/2 = 125, 1-272/2 = 136
262 static const int bosr_usb_divisor_table
[] = {
265 #define LOWER_GROUP ((1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<6) | (1<<7))
266 #define UPPER_GROUP ((1<<8) | (1<<9) | (1<<10) | (1<<11) | (1<<15))
267 static const unsigned short sr_valid_mask
[] = {
268 LOWER_GROUP
|UPPER_GROUP
, /* Normal, bosr - 0*/
269 LOWER_GROUP
, /* Usb, bosr - 0*/
270 LOWER_GROUP
|UPPER_GROUP
, /* Normal, bosr - 1*/
271 UPPER_GROUP
, /* Usb, bosr - 1*/
274 * Every divisor is a factor of 11*12
276 #define SR_MULT (11*12)
277 #define A(x) (SR_MULT/x)
278 static const unsigned char sr_adc_mult_table
[] = {
279 A(2), A(2), A(12), A(12), 0, 0, A(3), A(1),
280 A(2), A(2), A(11), A(11), 0, 0, 0, A(1)
282 static const unsigned char sr_dac_mult_table
[] = {
283 A(2), A(12), A(2), A(12), 0, 0, A(3), A(1),
284 A(2), A(11), A(2), A(11), 0, 0, 0, A(1)
287 static unsigned get_score(int adc
, int adc_l
, int adc_h
, int need_adc
,
288 int dac
, int dac_l
, int dac_h
, int need_dac
)
290 if ((adc
>= adc_l
) && (adc
<= adc_h
) &&
291 (dac
>= dac_l
) && (dac
<= dac_h
)) {
292 int diff_adc
= need_adc
- adc
;
293 int diff_dac
= need_dac
- dac
;
294 return abs(diff_adc
) + abs(diff_dac
);
299 static int find_rate(int mclk
, u32 need_adc
, u32 need_dac
)
305 unsigned best_score
= UINT_MAX
;
306 int adc_l
, adc_h
, dac_l
, dac_h
;
311 * rates given are +/- 1/32
313 adc_l
= need_adc
- (need_adc
>> 5);
314 adc_h
= need_adc
+ (need_adc
>> 5);
315 dac_l
= need_dac
- (need_dac
>> 5);
316 dac_h
= need_dac
+ (need_dac
>> 5);
317 for (i
= 0; i
< ARRAY_SIZE(bosr_usb_divisor_table
); i
++) {
318 int base
= mclk
/ bosr_usb_divisor_table
[i
];
319 int mask
= sr_valid_mask
[i
];
320 for (j
= 0; j
< ARRAY_SIZE(sr_adc_mult_table
);
327 adc
= base
* sr_adc_mult_table
[j
];
328 dac
= base
* sr_dac_mult_table
[j
];
329 score
= get_score(adc
, adc_l
, adc_h
, need_adc
,
330 dac
, dac_l
, dac_h
, need_dac
);
331 if (best_score
> score
) {
337 score
= get_score((adc
>> 1), adc_l
, adc_h
, need_adc
,
338 (dac
>> 1), dac_l
, dac_h
, need_dac
);
339 /* prefer to have a /2 */
340 if ((score
!= UINT_MAX
) && (best_score
>= score
)) {
348 return (best_j
<< 2) | best_i
| (best_div
<< TLV320AIC23_CLKIN_SHIFT
);
352 static void get_current_sample_rates(struct snd_soc_codec
*codec
, int mclk
,
353 u32
*sample_rate_adc
, u32
*sample_rate_dac
)
355 int src
= tlv320aic23_read_reg_cache(codec
, TLV320AIC23_SRATE
);
356 int sr
= (src
>> 2) & 0x0f;
357 int val
= (mclk
/ bosr_usb_divisor_table
[src
& 3]);
358 int adc
= (val
* sr_adc_mult_table
[sr
]) / SR_MULT
;
359 int dac
= (val
* sr_dac_mult_table
[sr
]) / SR_MULT
;
360 if (src
& TLV320AIC23_CLKIN_HALF
) {
364 *sample_rate_adc
= adc
;
365 *sample_rate_dac
= dac
;
369 static int set_sample_rate_control(struct snd_soc_codec
*codec
, int mclk
,
370 u32 sample_rate_adc
, u32 sample_rate_dac
)
372 /* Search for the right sample rate */
373 int data
= find_rate(mclk
, sample_rate_adc
, sample_rate_dac
);
375 printk(KERN_ERR
"%s:Invalid rate %u,%u requested\n",
376 __func__
, sample_rate_adc
, sample_rate_dac
);
379 tlv320aic23_write(codec
, TLV320AIC23_SRATE
, data
);
383 get_current_sample_rates(codec
, mclk
, &adc
, &dac
);
384 printk(KERN_DEBUG
"actual samplerate = %u,%u reg=%x\n",
391 static int tlv320aic23_add_widgets(struct snd_soc_codec
*codec
)
393 snd_soc_dapm_new_controls(codec
, tlv320aic23_dapm_widgets
,
394 ARRAY_SIZE(tlv320aic23_dapm_widgets
));
396 /* set up audio path interconnects */
397 snd_soc_dapm_add_routes(codec
, intercon
, ARRAY_SIZE(intercon
));
402 static int tlv320aic23_hw_params(struct snd_pcm_substream
*substream
,
403 struct snd_pcm_hw_params
*params
,
404 struct snd_soc_dai
*dai
)
406 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
407 struct snd_soc_device
*socdev
= rtd
->socdev
;
408 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
411 struct aic23
*aic23
= container_of(codec
, struct aic23
, codec
);
412 u32 sample_rate_adc
= aic23
->requested_adc
;
413 u32 sample_rate_dac
= aic23
->requested_dac
;
414 u32 sample_rate
= params_rate(params
);
416 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
417 aic23
->requested_dac
= sample_rate_dac
= sample_rate
;
418 if (!sample_rate_adc
)
419 sample_rate_adc
= sample_rate
;
421 aic23
->requested_adc
= sample_rate_adc
= sample_rate
;
422 if (!sample_rate_dac
)
423 sample_rate_dac
= sample_rate
;
425 ret
= set_sample_rate_control(codec
, aic23
->mclk
, sample_rate_adc
,
431 tlv320aic23_read_reg_cache(codec
,
432 TLV320AIC23_DIGT_FMT
) & ~(0x03 << 2);
433 switch (params_format(params
)) {
434 case SNDRV_PCM_FORMAT_S16_LE
:
436 case SNDRV_PCM_FORMAT_S20_3LE
:
437 iface_reg
|= (0x01 << 2);
439 case SNDRV_PCM_FORMAT_S24_LE
:
440 iface_reg
|= (0x02 << 2);
442 case SNDRV_PCM_FORMAT_S32_LE
:
443 iface_reg
|= (0x03 << 2);
446 tlv320aic23_write(codec
, TLV320AIC23_DIGT_FMT
, iface_reg
);
451 static int tlv320aic23_pcm_prepare(struct snd_pcm_substream
*substream
,
452 struct snd_soc_dai
*dai
)
454 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
455 struct snd_soc_device
*socdev
= rtd
->socdev
;
456 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
459 tlv320aic23_write(codec
, TLV320AIC23_ACTIVE
, 0x0001);
464 static void tlv320aic23_shutdown(struct snd_pcm_substream
*substream
,
465 struct snd_soc_dai
*dai
)
467 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
468 struct snd_soc_device
*socdev
= rtd
->socdev
;
469 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
470 struct aic23
*aic23
= container_of(codec
, struct aic23
, codec
);
473 if (!codec
->active
) {
475 tlv320aic23_write(codec
, TLV320AIC23_ACTIVE
, 0x0);
477 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
478 aic23
->requested_dac
= 0;
480 aic23
->requested_adc
= 0;
483 static int tlv320aic23_mute(struct snd_soc_dai
*dai
, int mute
)
485 struct snd_soc_codec
*codec
= dai
->codec
;
488 reg
= tlv320aic23_read_reg_cache(codec
, TLV320AIC23_DIGT
);
490 reg
|= TLV320AIC23_DACM_MUTE
;
493 reg
&= ~TLV320AIC23_DACM_MUTE
;
495 tlv320aic23_write(codec
, TLV320AIC23_DIGT
, reg
);
500 static int tlv320aic23_set_dai_fmt(struct snd_soc_dai
*codec_dai
,
503 struct snd_soc_codec
*codec
= codec_dai
->codec
;
507 tlv320aic23_read_reg_cache(codec
, TLV320AIC23_DIGT_FMT
) & (~0x03);
509 /* set master/slave audio interface */
510 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
511 case SND_SOC_DAIFMT_CBM_CFM
:
512 iface_reg
|= TLV320AIC23_MS_MASTER
;
514 case SND_SOC_DAIFMT_CBS_CFS
:
521 /* interface format */
522 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
523 case SND_SOC_DAIFMT_I2S
:
524 iface_reg
|= TLV320AIC23_FOR_I2S
;
526 case SND_SOC_DAIFMT_DSP_A
:
527 iface_reg
|= TLV320AIC23_LRP_ON
;
528 case SND_SOC_DAIFMT_DSP_B
:
529 iface_reg
|= TLV320AIC23_FOR_DSP
;
531 case SND_SOC_DAIFMT_RIGHT_J
:
533 case SND_SOC_DAIFMT_LEFT_J
:
534 iface_reg
|= TLV320AIC23_FOR_LJUST
;
541 tlv320aic23_write(codec
, TLV320AIC23_DIGT_FMT
, iface_reg
);
546 static int tlv320aic23_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
547 int clk_id
, unsigned int freq
, int dir
)
549 struct snd_soc_codec
*codec
= codec_dai
->codec
;
550 struct aic23
*aic23
= container_of(codec
, struct aic23
, codec
);
555 static int tlv320aic23_set_bias_level(struct snd_soc_codec
*codec
,
556 enum snd_soc_bias_level level
)
558 u16 reg
= tlv320aic23_read_reg_cache(codec
, TLV320AIC23_PWR
) & 0xff7f;
561 case SND_SOC_BIAS_ON
:
562 /* vref/mid, osc on, dac unmute */
563 tlv320aic23_write(codec
, TLV320AIC23_PWR
, reg
);
565 case SND_SOC_BIAS_PREPARE
:
567 case SND_SOC_BIAS_STANDBY
:
568 /* everything off except vref/vmid, */
569 tlv320aic23_write(codec
, TLV320AIC23_PWR
, reg
| 0x0040);
571 case SND_SOC_BIAS_OFF
:
572 /* everything off, dac mute, inactive */
573 tlv320aic23_write(codec
, TLV320AIC23_ACTIVE
, 0x0);
574 tlv320aic23_write(codec
, TLV320AIC23_PWR
, 0xffff);
577 codec
->bias_level
= level
;
581 #define AIC23_RATES SNDRV_PCM_RATE_8000_96000
582 #define AIC23_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
583 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
585 static struct snd_soc_dai_ops tlv320aic23_dai_ops
= {
586 .prepare
= tlv320aic23_pcm_prepare
,
587 .hw_params
= tlv320aic23_hw_params
,
588 .shutdown
= tlv320aic23_shutdown
,
589 .digital_mute
= tlv320aic23_mute
,
590 .set_fmt
= tlv320aic23_set_dai_fmt
,
591 .set_sysclk
= tlv320aic23_set_dai_sysclk
,
594 struct snd_soc_dai tlv320aic23_dai
= {
595 .name
= "tlv320aic23",
597 .stream_name
= "Playback",
600 .rates
= AIC23_RATES
,
601 .formats
= AIC23_FORMATS
,},
603 .stream_name
= "Capture",
606 .rates
= AIC23_RATES
,
607 .formats
= AIC23_FORMATS
,},
608 .ops
= &tlv320aic23_dai_ops
,
610 EXPORT_SYMBOL_GPL(tlv320aic23_dai
);
612 static int tlv320aic23_suspend(struct platform_device
*pdev
,
615 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
616 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
618 tlv320aic23_write(codec
, TLV320AIC23_ACTIVE
, 0x0);
619 tlv320aic23_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
624 static int tlv320aic23_resume(struct platform_device
*pdev
)
626 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
627 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
630 /* Sync reg_cache with the hardware */
631 for (reg
= 0; reg
<= TLV320AIC23_ACTIVE
; reg
++) {
632 u16 val
= tlv320aic23_read_reg_cache(codec
, reg
);
633 tlv320aic23_write(codec
, reg
, val
);
636 tlv320aic23_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
642 * initialise the AIC23 driver
643 * register the mixer and dsp interfaces with the kernel
645 static int tlv320aic23_init(struct snd_soc_device
*socdev
)
647 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
651 codec
->name
= "tlv320aic23";
652 codec
->owner
= THIS_MODULE
;
653 codec
->read
= tlv320aic23_read_reg_cache
;
654 codec
->write
= tlv320aic23_write
;
655 codec
->set_bias_level
= tlv320aic23_set_bias_level
;
656 codec
->dai
= &tlv320aic23_dai
;
658 codec
->reg_cache_size
= ARRAY_SIZE(tlv320aic23_reg
);
660 kmemdup(tlv320aic23_reg
, sizeof(tlv320aic23_reg
), GFP_KERNEL
);
661 if (codec
->reg_cache
== NULL
)
665 tlv320aic23_write(codec
, TLV320AIC23_RESET
, 0);
668 ret
= snd_soc_new_pcms(socdev
, SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
);
670 printk(KERN_ERR
"tlv320aic23: failed to create pcms\n");
674 /* power on device */
675 tlv320aic23_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
677 tlv320aic23_write(codec
, TLV320AIC23_DIGT
, TLV320AIC23_DEEMP_44K
);
680 reg
= tlv320aic23_read_reg_cache(codec
, TLV320AIC23_LINVOL
);
681 tlv320aic23_write(codec
, TLV320AIC23_LINVOL
,
682 (reg
& (~TLV320AIC23_LIM_MUTED
)) |
683 (TLV320AIC23_LRS_ENABLED
));
685 reg
= tlv320aic23_read_reg_cache(codec
, TLV320AIC23_RINVOL
);
686 tlv320aic23_write(codec
, TLV320AIC23_RINVOL
,
687 (reg
& (~TLV320AIC23_LIM_MUTED
)) |
688 TLV320AIC23_LRS_ENABLED
);
690 reg
= tlv320aic23_read_reg_cache(codec
, TLV320AIC23_ANLG
);
691 tlv320aic23_write(codec
, TLV320AIC23_ANLG
,
692 (reg
) & (~TLV320AIC23_BYPASS_ON
) &
693 (~TLV320AIC23_MICM_MUTED
));
695 /* Default output volume */
696 tlv320aic23_write(codec
, TLV320AIC23_LCHNVOL
,
697 TLV320AIC23_DEFAULT_OUT_VOL
&
698 TLV320AIC23_OUT_VOL_MASK
);
699 tlv320aic23_write(codec
, TLV320AIC23_RCHNVOL
,
700 TLV320AIC23_DEFAULT_OUT_VOL
&
701 TLV320AIC23_OUT_VOL_MASK
);
703 tlv320aic23_write(codec
, TLV320AIC23_ACTIVE
, 0x1);
705 snd_soc_add_controls(codec
, tlv320aic23_snd_controls
,
706 ARRAY_SIZE(tlv320aic23_snd_controls
));
707 tlv320aic23_add_widgets(codec
);
712 kfree(codec
->reg_cache
);
715 static struct snd_soc_device
*tlv320aic23_socdev
;
717 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
719 * If the i2c layer weren't so broken, we could pass this kind of data
722 static int tlv320aic23_codec_probe(struct i2c_client
*i2c
,
723 const struct i2c_device_id
*i2c_id
)
725 struct snd_soc_device
*socdev
= tlv320aic23_socdev
;
726 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
729 if (!i2c_check_functionality(i2c
->adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
732 i2c_set_clientdata(i2c
, codec
);
733 codec
->control_data
= i2c
;
735 ret
= tlv320aic23_init(socdev
);
737 printk(KERN_ERR
"tlv320aic23: failed to initialise AIC23\n");
747 static int __exit
tlv320aic23_i2c_remove(struct i2c_client
*i2c
)
749 put_device(&i2c
->dev
);
753 static const struct i2c_device_id tlv320aic23_id
[] = {
758 MODULE_DEVICE_TABLE(i2c
, tlv320aic23_id
);
760 static struct i2c_driver tlv320aic23_i2c_driver
= {
762 .name
= "tlv320aic23",
764 .probe
= tlv320aic23_codec_probe
,
765 .remove
= __exit_p(tlv320aic23_i2c_remove
),
766 .id_table
= tlv320aic23_id
,
771 static int tlv320aic23_probe(struct platform_device
*pdev
)
773 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
774 struct snd_soc_codec
*codec
;
778 printk(KERN_INFO
"AIC23 Audio Codec %s\n", AIC23_VERSION
);
780 aic23
= kzalloc(sizeof(struct aic23
), GFP_KERNEL
);
783 codec
= &aic23
->codec
;
784 socdev
->card
->codec
= codec
;
785 mutex_init(&codec
->mutex
);
786 INIT_LIST_HEAD(&codec
->dapm_widgets
);
787 INIT_LIST_HEAD(&codec
->dapm_paths
);
789 tlv320aic23_socdev
= socdev
;
790 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
791 codec
->hw_write
= (hw_write_t
) i2c_master_send
;
792 codec
->hw_read
= NULL
;
793 ret
= i2c_add_driver(&tlv320aic23_i2c_driver
);
795 printk(KERN_ERR
"can't add i2c driver");
800 static int tlv320aic23_remove(struct platform_device
*pdev
)
802 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
803 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
804 struct aic23
*aic23
= container_of(codec
, struct aic23
, codec
);
806 if (codec
->control_data
)
807 tlv320aic23_set_bias_level(codec
, SND_SOC_BIAS_OFF
);
809 snd_soc_free_pcms(socdev
);
810 snd_soc_dapm_free(socdev
);
811 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
812 i2c_del_driver(&tlv320aic23_i2c_driver
);
814 kfree(codec
->reg_cache
);
819 struct snd_soc_codec_device soc_codec_dev_tlv320aic23
= {
820 .probe
= tlv320aic23_probe
,
821 .remove
= tlv320aic23_remove
,
822 .suspend
= tlv320aic23_suspend
,
823 .resume
= tlv320aic23_resume
,
825 EXPORT_SYMBOL_GPL(soc_codec_dev_tlv320aic23
);
827 static int __init
tlv320aic23_modinit(void)
829 return snd_soc_register_dai(&tlv320aic23_dai
);
831 module_init(tlv320aic23_modinit
);
833 static void __exit
tlv320aic23_exit(void)
835 snd_soc_unregister_dai(&tlv320aic23_dai
);
837 module_exit(tlv320aic23_exit
);
839 MODULE_DESCRIPTION("ASoC TLV320AIC23 codec driver");
840 MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
841 MODULE_LICENSE("GPL");