2 * ALSA SoC TLV320AIC3X codec driver
4 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
7 * Based on sound/soc/codecs/wm8753.c by Liam Girdwood
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 AIC3X is a driver for a low power stereo audio
15 * codecs aic31, aic32, aic33.
17 * It supports full aic33 codec functionality.
18 * The compatibility with aic32, aic31 is as follows:
20 * ---------------------------------------
21 * MONO_LOUT -> N/A | MONO_LOUT -> N/A
27 * truncated internal functionality in
28 * accordance with documentation
29 * ---------------------------------------
31 * Hence the machine layer should disable unsupported inputs/outputs by
32 * snd_soc_dapm_disable_pin(codec, "MONO_LOUT"), etc.
35 #include <linux/module.h>
36 #include <linux/moduleparam.h>
37 #include <linux/init.h>
38 #include <linux/delay.h>
40 #include <linux/i2c.h>
41 #include <linux/platform_device.h>
42 #include <sound/core.h>
43 #include <sound/pcm.h>
44 #include <sound/pcm_params.h>
45 #include <sound/soc.h>
46 #include <sound/soc-dapm.h>
47 #include <sound/initval.h>
48 #include <sound/tlv.h>
49 #include <sound/hwdep.h>
51 #include "tlv320aic3x.h"
53 #define AIC3X_VERSION "0.2"
55 static int hp_dac_lim = 9;
56 module_param(hp_dac_lim, int, 0);
58 struct aic3x_dacfilter_t {
59 struct aic3x_iir_coeffs coeffs;
63 .N0 = 27619, .N1 = -27034, .N2 = 26461, .D1 = 32131, .D2 = -31506,
64 .N3 = 27619, .N4 = -27034, .N5 = 26461, .D4 = 32131, .D5 = -31506,
69 /* codec private data */
74 struct snd_hwdep *hwdep;
75 struct aic3x_dacfilter_t dacfilter;
79 * AIC3X register cache
80 * We can't read the AIC3X register space when we are
81 * using 2 wire for device control, so we cache them instead.
82 * There is no point in caching the reset register
84 static const u8 aic3x_reg[AIC3X_CACHEREGNUM] = {
85 0x00, 0x00, 0x00, 0x10, /* 0 */
86 0x04, 0x00, 0x00, 0x00, /* 4 */
87 0x00, 0x00, 0x00, 0x01, /* 8 */
88 0x00, 0x00, 0x00, 0x80, /* 12 */
89 0x80, 0xff, 0xff, 0x78, /* 16 */
90 0x78, 0x78, 0x78, 0x78, /* 20 */
91 0x78, 0x00, 0x00, 0xfe, /* 24 */
92 0x00, 0x00, 0xfe, 0x00, /* 28 */
93 0x00, 0x00, 0x00, 0x00, /* 32 */
94 0x00, 0x00, 0x00, 0x00, /* 36 */
95 0x00, 0x00, 0x00, 0x80, /* 40 */
96 0x80, 0x00, 0x00, 0x00, /* 44 */
97 0x00, 0x00, 0x00, 0x04, /* 48 */
98 0x00, 0x00, 0x00, 0x00, /* 52 */
99 0x00, 0x00, 0x04, 0x00, /* 56 */
100 0x00, 0x00, 0x00, 0x00, /* 60 */
101 0x00, 0x04, 0x00, 0x00, /* 64 */
102 0x00, 0x00, 0x00, 0x00, /* 68 */
103 0x04, 0x00, 0x00, 0x00, /* 72 */
104 0x00, 0x00, 0x00, 0x00, /* 76 */
105 0x00, 0x00, 0x00, 0x00, /* 80 */
106 0x00, 0x00, 0x00, 0x00, /* 84 */
107 0x00, 0x00, 0x00, 0x00, /* 88 */
108 0x00, 0x00, 0x00, 0x00, /* 92 */
109 0x00, 0x00, 0x00, 0x00, /* 96 */
110 0x00, 0x00, 0x02, 0x00, /* 100 */
111 0x00, 0x00, 0x00, 0x00, /* 104 */
112 0x00, 0x00, 0x00, 0x00, /* 108 */
113 0x00, 0x00, 0x00, 0x00, /* 112 */
114 0x00, 0x00, 0x00, 0x00, /* 116 */
115 0x00, 0x00, 0x00, 0x00, /* 120 */
116 0x00, 0x00, 0x00, 0x00, /* 124 */
117 0x01, 0x6b, 0xe3, 0x96, /* 128 */
118 0x66, 0x67, 0x5d, 0x6b, /* 132 */
119 0xe3, 0x96, 0x66, 0x67, /* 136 */
120 0x5d, 0x7d, 0x83, 0x84, /* 140 */
121 0xee, 0x7d, 0x83, 0x84, /* 144 */
122 0xee, 0x39, 0x55, 0xf3, /* 148 */
123 0x2d, 0x53, 0x7e, 0x6b, /* 152 */
124 0xe3, 0x96, 0x66, 0x67, /* 156 */
125 0x5d, 0x6b, 0xe3, 0x96, /* 160 */
126 0x66, 0x67, 0x5d, 0x7d, /* 164 */
127 0x83, 0x84, 0xee, 0x7d, /* 168 */
128 0x83, 0x84, 0xee, 0x39, /* 172 */
129 0x55, 0xf3, 0x2d, 0x53, /* 176 */
130 0x7e, 0x7f, 0xff, 0x00, /* 180 */
131 0x00, 0x00, 0x00, 0x00, /* 184 */
132 0x00, 0x00, 0x00, 0x00, /* 188 */
133 0x00, 0x39, 0x55, 0xf3, /* 192 */
134 0x2d, 0x53, 0x7e, 0x39, /* 196 */
135 0x55, 0xf3, 0x2d, 0x53, /* 200 */
140 * read aic3x register cache
142 static inline unsigned int aic3x_read_reg_cache(struct snd_soc_codec *codec,
145 u8 *cache = codec->reg_cache;
146 if (reg >= AIC3X_CACHEREGNUM)
151 static inline int aic3x_read_coeff_reg_cache
152 (struct snd_soc_codec *codec, unsigned int msbreg)
155 val = aic3x_read_reg_cache(codec, msbreg) << 8;
156 val |= aic3x_read_reg_cache(codec, msbreg+1);
157 if(val > 32767) val -= 65536;
162 * write aic3x register cache
164 static inline void aic3x_write_reg_cache(struct snd_soc_codec *codec,
167 u8 *cache = codec->reg_cache;
168 if (reg >= AIC3X_CACHEREGNUM)
174 * write to the aic3x register space
176 static int aic3x_write(struct snd_soc_codec *codec,
177 unsigned int reg, unsigned int value)
179 static char curpage = -1;
180 u8 data[2], page = 0;
182 /*mutex_lock(&codec->mutex);*/
188 //printk("MNZ: aic3x_write(reg = %i, val = 0x%x, page = %i)\n",
190 if(reg && curpage != page){
193 if (codec->hw_write(codec->control_data, data, 2) != 2){
194 /*mutex_unlock(&codec->mutex);*/
203 * D15..D8 aic3x register offset
204 * D7...D0 register data
209 if (codec->hw_write(codec->control_data, data, 2) == 2){
210 aic3x_write_reg_cache(codec, data[0] + page * 128, data[1]);
211 if(!reg) curpage = value; /* for reg = 0, ie, page setting */
212 /*mutex_unlock(&codec->mutex);*/
215 /*mutex_unlock(&codec->mutex);*/
222 /* Convert a value to 2s compliment and write to registers */
223 static int aic3x_write_coeff(struct snd_soc_codec *codec,
224 u8 msbreg, int value)
229 outp = 65536 + value;
233 aic3x_write(codec, msbreg, outp >> 8);
234 aic3x_write(codec, msbreg+1, outp);
241 * read from the aic3x register space
243 static int aic3x_read(struct snd_soc_codec *codec, unsigned int reg,
248 /* No read access is recommended if the chip is reset after use */
249 printk(KERN_ERR "%s(): Values are may be incorrect!\n", __func__);
251 if (codec->hw_read(codec->control_data, value, 1) != 1)
254 aic3x_write_reg_cache(codec, reg, *value);
258 static int aic3x_sync_hw(struct snd_soc_codec *codec)
260 u8 *cache = codec->reg_cache;
264 aic3x_write(codec, AIC3X_PAGE_SELECT, 1);
265 /*mutex_lock(&codec->mutex);*/
266 for (i = 1; i < AIC3X_PAGE1REGNUM; i++) {
268 data[1] = cache[i+128];
269 codec->hw_write(codec->control_data, data, 2);
271 /*mutex_unlock(&codec->mutex);*/
273 /* We do not rewrite page select nor reset again */
274 aic3x_write(codec, AIC3X_PAGE_SELECT, 0);
275 /*mutex_lock(&codec->mutex);*/
276 for (i = 2; i < AIC3X_PAGE0REGNUM; i++) {
279 codec->hw_write(codec->control_data, data, 2);
281 /*mutex_unlock(&codec->mutex);*/
287 * Reset for getting low power consumption after bypass paths
289 static void aic3x_reset(struct snd_soc_codec *codec)
291 aic3x_write(codec, AIC3X_RESET, SOFT_RESET);
292 aic3x_sync_hw(codec);
295 #define SOC_DAPM_SINGLE_AIC3X(xname, reg, shift, mask, invert) \
296 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
297 .info = snd_soc_info_volsw, \
298 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw_aic3x, \
299 .private_value = SOC_SINGLE_VALUE(reg, shift, mask, invert) }
302 * All input lines are connected when !0xf and disconnected with 0xf bit field,
303 * so we have to use specific dapm_put call for input mixer
305 static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,
306 struct snd_ctl_elem_value *ucontrol)
308 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
309 struct soc_mixer_control *mc =
310 (struct soc_mixer_control *)kcontrol->private_value;
311 unsigned int reg = mc->reg;
312 unsigned int shift = mc->shift;
314 unsigned int mask = (1 << fls(max)) - 1;
315 unsigned int invert = mc->invert;
316 unsigned short val, val_mask;
318 struct snd_soc_dapm_path *path;
321 val = (ucontrol->value.integer.value[0] & mask);
329 val_mask = mask << shift;
332 mutex_lock(&widget->codec->mutex);
334 if (snd_soc_test_bits(widget->codec, reg, val_mask, val)) {
335 /* find dapm widget path assoc with kcontrol */
336 list_for_each_entry(path, &widget->codec->dapm_paths, list) {
337 if (path->kcontrol != kcontrol)
340 /* found, now check type */
344 path->connect = invert ? 0 : 1;
346 /* old connection must be powered down */
347 path->connect = invert ? 1 : 0;
352 snd_soc_dapm_sync(widget->codec);
355 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
357 mutex_unlock(&widget->codec->mutex);
361 static const char *aic3x_left_dac_mux[] = { "DAC_L1", "DAC_L3", "DAC_L2" };
362 static const char *aic3x_right_dac_mux[] = { "DAC_R1", "DAC_R3", "DAC_R2" };
363 static const char *aic3x_left_hpcom_mux[] =
364 { "differential of HPLOUT", "constant VCM", "single-ended" };
365 static const char *aic3x_right_hpcom_mux[] =
366 { "differential of HPROUT", "constant VCM", "single-ended",
367 "differential of HPLCOM", "external feedback" };
368 static const char *aic3x_linein_mode_mux[] = { "single-ended", "differential" };
369 static const char *aic3x_adc_hpf[] =
370 { "Disabled", "0.0045xFs", "0.0125xFs", "0.025xFs" };
371 static const char *aic3x_dac_filt[] =
372 { "Off", "Bass/Treble", "Custom" };
376 #define LHPCOM_ENUM 2
377 #define RHPCOM_ENUM 3
378 #define LINE1L_ENUM 4
379 #define LINE1R_ENUM 5
380 #define LINE2L_ENUM 6
381 #define LINE2R_ENUM 7
382 #define ADC_HPF_ENUM 8
383 #define DAC_FILT_ENUM 9
385 static const struct soc_enum aic3x_enum[] = {
386 SOC_ENUM_SINGLE(DAC_LINE_MUX, 6, 3, aic3x_left_dac_mux),
387 SOC_ENUM_SINGLE(DAC_LINE_MUX, 4, 3, aic3x_right_dac_mux),
388 SOC_ENUM_SINGLE(HPLCOM_CFG, 4, 3, aic3x_left_hpcom_mux),
389 SOC_ENUM_SINGLE(HPRCOM_CFG, 3, 5, aic3x_right_hpcom_mux),
390 SOC_ENUM_SINGLE(LINE1L_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux),
391 SOC_ENUM_SINGLE(LINE1R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux),
392 SOC_ENUM_SINGLE(LINE2L_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux),
393 SOC_ENUM_SINGLE(LINE2R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux),
394 SOC_ENUM_DOUBLE(AIC3X_CODEC_DFILT_CTRL, 6, 4, 4, aic3x_adc_hpf),
395 SOC_ENUM_DOUBLE(AIC3X_CODEC_DFILT_CTRL, 1, 3, 3, aic3x_dac_filt),
399 * DAC digital volumes. From -63.5 to 0 dB in 0.5 dB steps
401 static DECLARE_TLV_DB_SCALE(dac_tlv, -6350, 50, 0);
402 /* ADC PGA gain volumes. From 0 to 59.5 dB in 0.5 dB steps */
403 static DECLARE_TLV_DB_SCALE(adc_tlv, 0, 50, 0);
404 /* HP DAC Output gain values. From 0 to 9.0 dB in 1 dB steps */
405 static DECLARE_TLV_DB_SCALE(hpout_tlv, 0, 100, 0);
407 * Output stage volumes. From -78.3 to 0 dB. Muted below -78.3 dB.
408 * Step size is approximately 0.5 dB over most of the scale but increasing
409 * near the very low levels.
410 * Define dB scale so that it is mostly correct for range about -55 to 0 dB
411 * but having increasing dB difference below that (and where it doesn't count
412 * so much). This setting shows -50 dB (actual is -50.3 dB) for register
413 * value 100 and -58.5 dB (actual is -78.3 dB) for register value 117.
415 static DECLARE_TLV_DB_SCALE(output_stage_tlv, -5900, 50, 1);
417 #define SOC_DOUBLE_R_TLV_TLV320ALC3X(xname, reg_left, reg_right, xshift, xmax,\
418 xinvert, tlv_array) \
419 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
420 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
421 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
422 .tlv.p = (tlv_array), \
423 .info = tlv320alc3x_info_volsw, \
424 .get = snd_soc_get_volsw_2r,\
425 .put = snd_soc_put_volsw_2r,\
426 .private_value = (unsigned long)&(struct soc_mixer_control) \
427 {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
428 .max = xmax, .invert = xinvert} }
430 static int tlv320alc3x_info_volsw(struct snd_kcontrol *kcontrol,
431 struct snd_ctl_elem_info *uinfo)
433 struct soc_mixer_control *mc =
434 (struct soc_mixer_control *)kcontrol->private_value;
437 if (hp_dac_lim != max && hp_dac_lim >= 2 && hp_dac_lim <= 9)
441 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
443 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
446 uinfo->value.integer.min = 0;
447 uinfo->value.integer.max = max;
451 /* DAC and De-emphasis Filter Functions */
452 int aic3x_deemph_set_coeffs(struct snd_soc_codec *codec,
453 int N0, int N1, int D1){
454 printk("MNZ: setting deemph coeffs\n");
455 snd_soc_update_bits(codec, AIC3X_CODEC_DFILT_CTRL, DEEMPH_ON, 0);
457 aic3x_write_coeff(codec, DEEMPH_LEFT_N0, N0);
458 aic3x_write_coeff(codec, DEEMPH_LEFT_N1, N1);
459 aic3x_write_coeff(codec, DEEMPH_LEFT_D1, D1);
460 aic3x_write_coeff(codec, DEEMPH_RIGHT_N0, N0);
461 aic3x_write_coeff(codec, DEEMPH_RIGHT_N1, N1);
462 aic3x_write_coeff(codec, DEEMPH_RIGHT_D1, D1);
466 EXPORT_SYMBOL_GPL(aic3x_deemph_set_coeffs);
468 int aic3x_deemph_set_state(struct snd_soc_codec *codec, int state){
469 printk("MNZ: Setting De-Emph filter: %i\n", state);
470 if(state) state = DEEMPH_ON;
472 return snd_soc_update_bits(codec, AIC3X_CODEC_DFILT_CTRL,
475 EXPORT_SYMBOL_GPL(aic3x_deemph_set_state);
477 static int aic3x_dacfilter_write_coeffs
478 (struct snd_soc_codec *codec, struct aic3x_iir_coeffs *coeffs)
480 printk("MNZ: dacfilter_write_coeffs\n");
481 snd_soc_update_bits(codec, AIC3X_CODEC_DFILT_CTRL, EFFECTS_ON, 0);
482 aic3x_write_coeff(codec, EFFECTS_LEFT_N0, coeffs->N0);
483 aic3x_write_coeff(codec, EFFECTS_LEFT_N1, coeffs->N1);
484 aic3x_write_coeff(codec, EFFECTS_LEFT_N2, coeffs->N2);
485 aic3x_write_coeff(codec, EFFECTS_LEFT_D1, coeffs->D1);
486 aic3x_write_coeff(codec, EFFECTS_LEFT_D2, coeffs->D2);
487 aic3x_write_coeff(codec, EFFECTS_LEFT_N3, coeffs->N3);
488 aic3x_write_coeff(codec, EFFECTS_LEFT_N4, coeffs->N4);
489 aic3x_write_coeff(codec, EFFECTS_LEFT_N5, coeffs->N5);
490 aic3x_write_coeff(codec, EFFECTS_LEFT_D4, coeffs->D4);
491 aic3x_write_coeff(codec, EFFECTS_LEFT_D5, coeffs->D5);
493 aic3x_write_coeff(codec, EFFECTS_RIGHT_N0, coeffs->N0);
494 aic3x_write_coeff(codec, EFFECTS_RIGHT_N1, coeffs->N1);
495 aic3x_write_coeff(codec, EFFECTS_RIGHT_N2, coeffs->N2);
496 aic3x_write_coeff(codec, EFFECTS_RIGHT_D1, coeffs->D1);
497 aic3x_write_coeff(codec, EFFECTS_RIGHT_D2, coeffs->D2);
498 aic3x_write_coeff(codec, EFFECTS_RIGHT_N3, coeffs->N3);
499 aic3x_write_coeff(codec, EFFECTS_RIGHT_N4, coeffs->N4);
500 aic3x_write_coeff(codec, EFFECTS_RIGHT_N5, coeffs->N5);
501 aic3x_write_coeff(codec, EFFECTS_RIGHT_D4, coeffs->D4);
502 aic3x_write_coeff(codec, EFFECTS_RIGHT_D5, coeffs->D5);
507 int aic3x_dacfilter_set_coeffs
508 (struct snd_soc_codec *codec, struct aic3x_iir_coeffs *coeffs)
510 struct aic3x_priv *aic3x = codec->private_data;
511 memcpy((void*)&aic3x->dacfilter.coeffs, (void*)coeffs,
512 sizeof(struct aic3x_iir_coeffs));
515 EXPORT_SYMBOL_GPL(aic3x_dacfilter_set_coeffs);
517 int aic3x_dacfilter_set_state(struct snd_soc_codec *codec, int state)
519 struct aic3x_priv *aic3x = codec->private_data;
521 if(aic3x->dacfilter.state == state) return 0;
523 aic3x->dacfilter.state = state;
526 snd_soc_update_bits(codec, AIC3X_CODEC_DFILT_CTRL,
528 else if(state == 1) {}
529 /* FIXME MNZ. Set preset from current chosen preset */
530 else if (state == 2){
531 aic3x_dacfilter_write_coeffs(codec, &aic3x->dacfilter.coeffs);
532 snd_soc_update_bits(codec, AIC3X_CODEC_DFILT_CTRL,
533 EFFECTS_ON, EFFECTS_ON);
538 EXPORT_SYMBOL_GPL(aic3x_dacfilter_set_state);
540 /* DAC Filter hwdep device callbacks */
542 static int snd_hwdep_dacfilter_open_aic3x(struct snd_hwdep *hw,
548 static int snd_hwdep_dacfilter_ioctl_aic3x(struct snd_hwdep *hw,
549 struct file *file, unsigned int cmd, unsigned long arg)
551 /* Only IOCTL command is for enabling/disabling filter, cmd = 1
552 * arg = 0 to disable, 1 to enable and set to bass/treble,
553 * 2 to enable and set to custom coeffs
555 struct snd_soc_codec *codec = hw->private_data;
556 if (cmd != 1) return -EINVAL;
557 return aic3x_dacfilter_set_state(codec, *((int*)arg));
561 static long snd_hwdep_dacfilter_read_aic3x(struct snd_hwdep *hw,
562 char __user *buf, long count, loff_t *offset)
564 struct aic3x_priv *aic3x =
565 ((struct snd_soc_codec*)hw->private_data)->private_data;
566 if(count != sizeof(struct aic3x_iir_coeffs)) return -EINVAL;
567 memcpy((void*)buf, (void*)&aic3x->dacfilter.coeffs, count);
571 static long snd_hwdep_dacfilter_write_aic3x(struct snd_hwdep *hw,
572 const char __user *buf, long count, loff_t *offset)
574 struct snd_soc_codec *codec = hw->private_data;
575 if(count != sizeof(struct aic3x_iir_coeffs)) return -EINVAL;
577 ((struct aic3x_priv*)codec->private_data)->dacfilter.state = 2;
579 return aic3x_dacfilter_set_coeffs(codec,
580 (struct aic3x_iir_coeffs*)buf);
583 /* DAC filter and 3D depth ALSA controls callbacks */
585 static int snd_soc_get_dacfilter_aic3x(struct snd_kcontrol *kcontrol,
586 struct snd_ctl_elem_value *ucontrol)
588 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
589 ucontrol->value.enumerated.item[0] =
590 ((struct aic3x_priv*)codec->private_data)->dacfilter.state;
594 static int snd_soc_put_dacfilter_aic3x(struct snd_kcontrol *kcontrol,
595 struct snd_ctl_elem_value *ucontrol)
597 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
598 if (ucontrol->value.enumerated.item[0] > 2)
600 aic3x_dacfilter_set_state(codec, ucontrol->value.enumerated.item[0]);
604 static int snd_soc_get_3d_attenuation_aic3x
605 (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
607 int val = aic3x_read_coeff_reg_cache
608 (snd_kcontrol_chip(kcontrol), EFFECTS_3DATTEN);
609 val = ((val*100)/65530) + 50;
610 ucontrol->value.integer.value[0] = val;
614 static int snd_soc_put_3d_attenuation_aic3x
615 (struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
617 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
618 int val = ucontrol->value.integer.value[0];
619 if(val > 100 || val < 0) return -EINVAL;
622 snd_soc_update_bits(codec, AIC3X_ASD_INTF_CTRLA,
623 EFFECTS_3D_ON, EFFECTS_3D_ON);
624 val = ((val - 50) * 65535) / 100 ;
626 snd_soc_update_bits(codec, AIC3X_ASD_INTF_CTRLA,
631 aic3x_write_coeff(codec, EFFECTS_3DATTEN, val);
636 static const struct snd_kcontrol_new aic3x_snd_controls[] = {
638 SOC_DOUBLE_R_TLV("PCM Playback Volume",
639 LDAC_VOL, RDAC_VOL, 0, 0x7f, 1, dac_tlv),
641 SOC_DOUBLE_R_TLV("Line DAC Playback Volume",
642 DACL1_2_LLOPM_VOL, DACR1_2_RLOPM_VOL,
643 0, 118, 1, output_stage_tlv),
644 SOC_DOUBLE_R("Line DAC Playback Switch", LLOPM_CTRL, RLOPM_CTRL, 3,
646 SOC_DOUBLE_R_TLV("Line PGA Bypass Playback Volume",
647 PGAL_2_LLOPM_VOL, PGAR_2_RLOPM_VOL,
648 0, 118, 1, output_stage_tlv),
649 SOC_DOUBLE_R_TLV("Line Line2 Bypass Playback Volume",
650 LINE2L_2_LLOPM_VOL, LINE2R_2_RLOPM_VOL,
651 0, 118, 1, output_stage_tlv),
653 SOC_DOUBLE_R_TLV("Mono DAC Playback Volume",
654 DACL1_2_MONOLOPM_VOL, DACR1_2_MONOLOPM_VOL,
655 0, 118, 1, output_stage_tlv),
656 SOC_SINGLE("Mono DAC Playback Switch", MONOLOPM_CTRL, 3, 0x01, 0),
657 SOC_DOUBLE_R_TLV("Mono PGA Bypass Playback Volume",
658 PGAL_2_MONOLOPM_VOL, PGAR_2_MONOLOPM_VOL,
659 0, 118, 1, output_stage_tlv),
660 SOC_DOUBLE_R_TLV("Mono Line2 Bypass Playback Volume",
661 LINE2L_2_MONOLOPM_VOL, LINE2R_2_MONOLOPM_VOL,
662 0, 118, 1, output_stage_tlv),
664 SOC_DOUBLE_R_TLV("HP DAC Playback Volume",
665 DACL1_2_HPLOUT_VOL, DACR1_2_HPROUT_VOL,
666 0, 118, 1, output_stage_tlv),
667 SOC_DOUBLE_R("HP DAC Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3,
669 SOC_DOUBLE_R_TLV_TLV320ALC3X("HP DAC Output Volume", HPLOUT_CTRL,
670 HPROUT_CTRL, 4, 9, 0, hpout_tlv),
671 SOC_DOUBLE_R_TLV("HP PGA Bypass Playback Volume",
672 PGAL_2_HPLOUT_VOL, PGAR_2_HPROUT_VOL,
673 0, 118, 1, output_stage_tlv),
674 SOC_DOUBLE_R_TLV("HP Line2 Bypass Playback Volume",
675 LINE2L_2_HPLOUT_VOL, LINE2R_2_HPROUT_VOL,
676 0, 118, 1, output_stage_tlv),
678 SOC_DOUBLE_R_TLV("HPCOM DAC Playback Volume",
679 DACL1_2_HPLCOM_VOL, DACR1_2_HPRCOM_VOL,
680 0, 118, 1, output_stage_tlv),
681 SOC_DOUBLE_R("HPCOM DAC Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3,
683 SOC_DOUBLE_R_TLV_TLV320ALC3X("HPCOM DAC Output Volume", HPLCOM_CTRL,
684 HPRCOM_CTRL, 4, 9, 0, hpout_tlv),
685 SOC_DOUBLE_R_TLV("HPCOM PGA Bypass Playback Volume",
686 PGAL_2_HPLCOM_VOL, PGAR_2_HPRCOM_VOL,
687 0, 118, 1, output_stage_tlv),
688 SOC_DOUBLE_R_TLV("HPCOM Line2 Bypass Playback Volume",
689 LINE2L_2_HPLCOM_VOL, LINE2R_2_HPRCOM_VOL,
690 0, 118, 1, output_stage_tlv),
693 * Note: enable Automatic input Gain Controller with care. It can
694 * adjust PGA to max value when ADC is on and will never go back.
696 SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0),
699 SOC_DOUBLE_R_TLV("PGA Capture Volume", LADC_VOL, RADC_VOL,
701 SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1),
703 SOC_ENUM("ADC HPF Cut-off", aic3x_enum[ADC_HPF_ENUM]),
705 SOC_ENUM_EXT("Hardware EQ", aic3x_enum[DAC_FILT_ENUM],
706 snd_soc_get_dacfilter_aic3x, snd_soc_put_dacfilter_aic3x),
708 SOC_SINGLE_EXT("3D Control - Depth", EFFECTS_3DATTEN, 0, 100, 0,
709 snd_soc_get_3d_attenuation_aic3x, snd_soc_put_3d_attenuation_aic3x),
712 /* add non dapm controls */
713 static int aic3x_add_controls(struct snd_soc_codec *codec)
717 for (i = 0; i < ARRAY_SIZE(aic3x_snd_controls); i++) {
718 err = snd_ctl_add(codec->card,
719 snd_soc_cnew(&aic3x_snd_controls[i],
728 static int reset_after_bypass(struct snd_soc_dapm_widget *w,
729 struct snd_kcontrol *kcontrol, int event)
731 struct aic3x_priv *aic3x = w->codec->private_data;
732 struct soc_mixer_control *mc = NULL;
733 unsigned int reg = 0;
736 mc = (struct soc_mixer_control *)kcontrol->private_value;
740 if (reg == PGAL_2_LLOPM_VOL || reg == PGAR_2_RLOPM_VOL ||
741 reg == PGAL_2_HPLOUT_VOL || reg == PGAR_2_HPROUT_VOL) {
742 if (w->value & 0x80) {
743 /* Prepare reset on the chip */
744 if (reg == PGAL_2_LLOPM_VOL)
745 aic3x->prepare_reset |= 0x01;
746 else if (reg == PGAR_2_RLOPM_VOL)
747 aic3x->prepare_reset |= 0x02;
748 else if (reg == PGAL_2_HPLOUT_VOL)
749 aic3x->prepare_reset |= 0x04;
750 else if (reg == PGAR_2_HPROUT_VOL)
751 aic3x->prepare_reset |= 0x08;
753 if (aic3x->prepare_reset) {
754 if (reg == PGAL_2_LLOPM_VOL)
755 aic3x->prepare_reset &= ~0x01;
756 else if (reg == PGAR_2_RLOPM_VOL)
757 aic3x->prepare_reset &= ~0x02;
758 else if (reg == PGAL_2_HPLOUT_VOL)
759 aic3x->prepare_reset &= ~0x04;
760 else if (reg == PGAR_2_HPROUT_VOL)
761 aic3x->prepare_reset &= ~0x08;
763 * Controls may have now been turned off,
764 * once they were on, so schedule or
765 * issue a reset on the chip.
767 if (!aic3x->prepare_reset) {
768 if (!((w->codec->bias_level ==
770 (w->codec->bias_level ==
771 SND_SOC_BIAS_PREPARE)))
772 aic3x_reset(w->codec);
782 static const struct snd_kcontrol_new aic3x_left_dac_mux_controls =
783 SOC_DAPM_ENUM("Route", aic3x_enum[LDAC_ENUM]);
786 static const struct snd_kcontrol_new aic3x_right_dac_mux_controls =
787 SOC_DAPM_ENUM("Route", aic3x_enum[RDAC_ENUM]);
790 static const struct snd_kcontrol_new aic3x_left_hpcom_mux_controls =
791 SOC_DAPM_ENUM("Route", aic3x_enum[LHPCOM_ENUM]);
793 /* Right HPCOM Mux */
794 static const struct snd_kcontrol_new aic3x_right_hpcom_mux_controls =
795 SOC_DAPM_ENUM("Route", aic3x_enum[RHPCOM_ENUM]);
797 /* Left DAC_L1 Mixer */
798 static const struct snd_kcontrol_new aic3x_left_dac_mixer_controls[] = {
799 SOC_DAPM_SINGLE("Line Switch", DACL1_2_LLOPM_VOL, 7, 1, 0),
800 SOC_DAPM_SINGLE("Mono Switch", DACL1_2_MONOLOPM_VOL, 7, 1, 0),
801 SOC_DAPM_SINGLE("HP Switch", DACL1_2_HPLOUT_VOL, 7, 1, 0),
802 SOC_DAPM_SINGLE("HPCOM Switch", DACL1_2_HPLCOM_VOL, 7, 1, 0),
805 /* Right DAC_R1 Mixer */
806 static const struct snd_kcontrol_new aic3x_right_dac_mixer_controls[] = {
807 SOC_DAPM_SINGLE("Line Switch", DACR1_2_RLOPM_VOL, 7, 1, 0),
808 SOC_DAPM_SINGLE("Mono Switch", DACR1_2_MONOLOPM_VOL, 7, 1, 0),
809 SOC_DAPM_SINGLE("HP Switch", DACR1_2_HPROUT_VOL, 7, 1, 0),
810 SOC_DAPM_SINGLE("HPCOM Switch", DACR1_2_HPRCOM_VOL, 7, 1, 0),
814 static const struct snd_kcontrol_new aic3x_left_pga_mixer_controls[] = {
815 SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1),
816 SOC_DAPM_SINGLE_AIC3X("Line2L Switch", LINE2L_2_LADC_CTRL, 3, 1, 1),
817 SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1),
820 /* Right PGA Mixer */
821 static const struct snd_kcontrol_new aic3x_right_pga_mixer_controls[] = {
822 SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1),
823 SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_RADC_CTRL, 3, 1, 1),
824 SOC_DAPM_SINGLE_AIC3X("Line2R Switch", LINE2R_2_RADC_CTRL, 3, 1, 1),
825 SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1),
829 static const struct snd_kcontrol_new aic3x_left_line1_mux_controls =
830 SOC_DAPM_ENUM("Route", aic3x_enum[LINE1L_ENUM]);
832 /* Right Line1 Mux */
833 static const struct snd_kcontrol_new aic3x_right_line1_mux_controls =
834 SOC_DAPM_ENUM("Route", aic3x_enum[LINE1R_ENUM]);
837 static const struct snd_kcontrol_new aic3x_left_line2_mux_controls =
838 SOC_DAPM_ENUM("Route", aic3x_enum[LINE2L_ENUM]);
840 /* Right Line2 Mux */
841 static const struct snd_kcontrol_new aic3x_right_line2_mux_controls =
842 SOC_DAPM_ENUM("Route", aic3x_enum[LINE2R_ENUM]);
844 /* Left PGA Bypass Mixer */
845 static const struct snd_kcontrol_new aic3x_left_pga_bp_mixer_controls[] = {
846 SOC_DAPM_SINGLE("Line Switch", PGAL_2_LLOPM_VOL, 7, 1, 0),
847 SOC_DAPM_SINGLE("Mono Switch", PGAL_2_MONOLOPM_VOL, 7, 1, 0),
848 SOC_DAPM_SINGLE("HP Switch", PGAL_2_HPLOUT_VOL, 7, 1, 0),
849 SOC_DAPM_SINGLE("HPCOM Switch", PGAL_2_HPLCOM_VOL, 7, 1, 0),
852 /* Right PGA Bypass Mixer */
853 static const struct snd_kcontrol_new aic3x_right_pga_bp_mixer_controls[] = {
854 SOC_DAPM_SINGLE("Line Switch", PGAR_2_RLOPM_VOL, 7, 1, 0),
855 SOC_DAPM_SINGLE("Mono Switch", PGAR_2_MONOLOPM_VOL, 7, 1, 0),
856 SOC_DAPM_SINGLE("HP Switch", PGAR_2_HPROUT_VOL, 7, 1, 0),
857 SOC_DAPM_SINGLE("HPCOM Switch", PGAR_2_HPRCOM_VOL, 7, 1, 0),
860 /* Left Line2 Bypass Mixer */
861 static const struct snd_kcontrol_new aic3x_left_line2_bp_mixer_controls[] = {
862 SOC_DAPM_SINGLE("Line Switch", LINE2L_2_LLOPM_VOL, 7, 1, 0),
863 SOC_DAPM_SINGLE("Mono Switch", LINE2L_2_MONOLOPM_VOL, 7, 1, 0),
864 SOC_DAPM_SINGLE("HP Switch", LINE2L_2_HPLOUT_VOL, 7, 1, 0),
865 SOC_DAPM_SINGLE("HPCOM Switch", LINE2L_2_HPLCOM_VOL, 7, 1, 0),
868 /* Right Line2 Bypass Mixer */
869 static const struct snd_kcontrol_new aic3x_right_line2_bp_mixer_controls[] = {
870 SOC_DAPM_SINGLE("Line Switch", LINE2R_2_RLOPM_VOL, 7, 1, 0),
871 SOC_DAPM_SINGLE("Mono Switch", LINE2R_2_MONOLOPM_VOL, 7, 1, 0),
872 SOC_DAPM_SINGLE("HP Switch", LINE2R_2_HPROUT_VOL, 7, 1, 0),
873 SOC_DAPM_SINGLE("HPCOM Switch", LINE2R_2_HPRCOM_VOL, 7, 1, 0),
876 static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
877 /* Left DAC to Left Outputs */
878 SND_SOC_DAPM_DAC("Left DAC", "Left Playback", DAC_PWR, 7, 0),
879 SND_SOC_DAPM_MUX("Left DAC Mux", SND_SOC_NOPM, 0, 0,
880 &aic3x_left_dac_mux_controls),
881 SND_SOC_DAPM_MIXER("Left DAC_L1 Mixer", SND_SOC_NOPM, 0, 0,
882 &aic3x_left_dac_mixer_controls[0],
883 ARRAY_SIZE(aic3x_left_dac_mixer_controls)),
884 SND_SOC_DAPM_MUX("Left HPCOM Mux", SND_SOC_NOPM, 0, 0,
885 &aic3x_left_hpcom_mux_controls),
886 SND_SOC_DAPM_PGA("Left Line Out", LLOPM_CTRL, 0, 0, NULL, 0),
887 SND_SOC_DAPM_PGA("Left HP Out", HPLOUT_CTRL, 0, 0, NULL, 0),
888 SND_SOC_DAPM_PGA("Left HP Com", HPLCOM_CTRL, 0, 0, NULL, 0),
890 /* Right DAC to Right Outputs */
891 SND_SOC_DAPM_DAC("Right DAC", "Right Playback", DAC_PWR, 6, 0),
892 SND_SOC_DAPM_MUX("Right DAC Mux", SND_SOC_NOPM, 0, 0,
893 &aic3x_right_dac_mux_controls),
894 SND_SOC_DAPM_MIXER("Right DAC_R1 Mixer", SND_SOC_NOPM, 0, 0,
895 &aic3x_right_dac_mixer_controls[0],
896 ARRAY_SIZE(aic3x_right_dac_mixer_controls)),
897 SND_SOC_DAPM_MUX("Right HPCOM Mux", SND_SOC_NOPM, 0, 0,
898 &aic3x_right_hpcom_mux_controls),
899 SND_SOC_DAPM_PGA("Right Line Out", RLOPM_CTRL, 0, 0, NULL, 0),
900 SND_SOC_DAPM_PGA("Right HP Out", HPROUT_CTRL, 0, 0, NULL, 0),
901 SND_SOC_DAPM_PGA("Right HP Com", HPRCOM_CTRL, 0, 0, NULL, 0),
904 SND_SOC_DAPM_PGA("Mono Out", MONOLOPM_CTRL, 0, 0, NULL, 0),
906 /* Left Inputs to Left ADC */
907 SND_SOC_DAPM_ADC("Left ADC", "Left Capture", LINE1L_2_LADC_CTRL, 2, 0),
908 SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0,
909 &aic3x_left_pga_mixer_controls[0],
910 ARRAY_SIZE(aic3x_left_pga_mixer_controls)),
911 SND_SOC_DAPM_MUX("Left Line1L Mux", SND_SOC_NOPM, 0, 0,
912 &aic3x_left_line1_mux_controls),
913 SND_SOC_DAPM_MUX("Left Line2L Mux", SND_SOC_NOPM, 0, 0,
914 &aic3x_left_line2_mux_controls),
916 /* Right Inputs to Right ADC */
917 SND_SOC_DAPM_ADC("Right ADC", "Right Capture",
918 LINE1R_2_RADC_CTRL, 2, 0),
919 SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0,
920 &aic3x_right_pga_mixer_controls[0],
921 ARRAY_SIZE(aic3x_right_pga_mixer_controls)),
922 SND_SOC_DAPM_MUX("Right Line1L Mux", SND_SOC_NOPM, 0, 0,
923 &aic3x_right_line1_mux_controls),
924 SND_SOC_DAPM_MUX("Right Line1R Mux", SND_SOC_NOPM, 0, 0,
925 &aic3x_right_line1_mux_controls),
926 SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0,
927 &aic3x_right_line2_mux_controls),
930 * Not a real mic bias widget but similar function. This is for dynamic
931 * control of GPIO1 digital mic modulator clock output function when
934 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "GPIO1 dmic modclk",
935 AIC3X_GPIO1_REG, 4, 0xf,
936 AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK,
937 AIC3X_GPIO1_FUNC_DISABLED),
940 * Also similar function like mic bias. Selects digital mic with
941 * configurable oversampling rate instead of ADC converter.
943 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 128",
944 AIC3X_ASD_INTF_CTRLA, 0, 3, 1, 0),
945 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 64",
946 AIC3X_ASD_INTF_CTRLA, 0, 3, 2, 0),
947 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 32",
948 AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0),
951 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias 2V",
952 MICBIAS_CTRL, 6, 3, 1, 0),
953 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias 2.5V",
954 MICBIAS_CTRL, 6, 3, 2, 0),
955 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias AVDD",
956 MICBIAS_CTRL, 6, 3, 3, 0),
958 /* Left PGA to Left Output bypass */
959 SND_SOC_DAPM_MIXER_E("Left PGA Bypass Mixer", SND_SOC_NOPM, 0, 0,
960 &aic3x_left_pga_bp_mixer_controls[0],
961 ARRAY_SIZE(aic3x_left_pga_bp_mixer_controls),
962 reset_after_bypass, SND_SOC_DAPM_POST_REG),
964 /* Right PGA to Right Output bypass */
965 SND_SOC_DAPM_MIXER_E("Right PGA Bypass Mixer", SND_SOC_NOPM, 0, 0,
966 &aic3x_right_pga_bp_mixer_controls[0],
967 ARRAY_SIZE(aic3x_right_pga_bp_mixer_controls),
968 reset_after_bypass, SND_SOC_DAPM_POST_REG),
970 /* Left Line2 to Left Output bypass */
971 SND_SOC_DAPM_MIXER("Left Line2 Bypass Mixer", SND_SOC_NOPM, 0, 0,
972 &aic3x_left_line2_bp_mixer_controls[0],
973 ARRAY_SIZE(aic3x_left_line2_bp_mixer_controls)),
975 /* Right Line2 to Right Output bypass */
976 SND_SOC_DAPM_MIXER("Right Line2 Bypass Mixer", SND_SOC_NOPM, 0, 0,
977 &aic3x_right_line2_bp_mixer_controls[0],
978 ARRAY_SIZE(aic3x_right_line2_bp_mixer_controls)),
980 SND_SOC_DAPM_OUTPUT("LLOUT"),
981 SND_SOC_DAPM_OUTPUT("RLOUT"),
982 SND_SOC_DAPM_OUTPUT("MONO_LOUT"),
983 SND_SOC_DAPM_OUTPUT("HPLOUT"),
984 SND_SOC_DAPM_OUTPUT("HPROUT"),
985 SND_SOC_DAPM_OUTPUT("HPLCOM"),
986 SND_SOC_DAPM_OUTPUT("HPRCOM"),
988 SND_SOC_DAPM_INPUT("MIC3L"),
989 SND_SOC_DAPM_INPUT("MIC3R"),
990 SND_SOC_DAPM_INPUT("LINE1L"),
991 SND_SOC_DAPM_INPUT("LINE1R"),
992 SND_SOC_DAPM_INPUT("LINE2L"),
993 SND_SOC_DAPM_INPUT("LINE2R"),
996 static const struct snd_soc_dapm_route intercon[] = {
998 {"Left DAC Mux", "DAC_L1", "Left DAC"},
999 {"Left DAC Mux", "DAC_L2", "Left DAC"},
1000 {"Left DAC Mux", "DAC_L3", "Left DAC"},
1002 {"Left DAC_L1 Mixer", "Line Switch", "Left DAC Mux"},
1003 {"Left DAC_L1 Mixer", "Mono Switch", "Left DAC Mux"},
1004 {"Left DAC_L1 Mixer", "HP Switch", "Left DAC Mux"},
1005 {"Left DAC_L1 Mixer", "HPCOM Switch", "Left DAC Mux"},
1006 {"Left Line Out", NULL, "Left DAC Mux"},
1007 {"Left HP Out", NULL, "Left DAC Mux"},
1009 {"Left HPCOM Mux", "differential of HPLOUT", "Left DAC_L1 Mixer"},
1010 {"Left HPCOM Mux", "constant VCM", "Left DAC_L1 Mixer"},
1011 {"Left HPCOM Mux", "single-ended", "Left DAC_L1 Mixer"},
1013 {"Left Line Out", NULL, "Left DAC_L1 Mixer"},
1014 {"Mono Out", NULL, "Left DAC_L1 Mixer"},
1015 {"Left HP Out", NULL, "Left DAC_L1 Mixer"},
1016 {"Left HP Com", NULL, "Left HPCOM Mux"},
1018 {"LLOUT", NULL, "Left Line Out"},
1019 {"LLOUT", NULL, "Left Line Out"},
1020 {"HPLOUT", NULL, "Left HP Out"},
1021 {"HPLCOM", NULL, "Left HP Com"},
1024 {"Right DAC Mux", "DAC_R1", "Right DAC"},
1025 {"Right DAC Mux", "DAC_R2", "Right DAC"},
1026 {"Right DAC Mux", "DAC_R3", "Right DAC"},
1028 {"Right DAC_R1 Mixer", "Line Switch", "Right DAC Mux"},
1029 {"Right DAC_R1 Mixer", "Mono Switch", "Right DAC Mux"},
1030 {"Right DAC_R1 Mixer", "HP Switch", "Right DAC Mux"},
1031 {"Right DAC_R1 Mixer", "HPCOM Switch", "Right DAC Mux"},
1032 {"Right Line Out", NULL, "Right DAC Mux"},
1033 {"Right HP Out", NULL, "Right DAC Mux"},
1035 {"Right HPCOM Mux", "differential of HPROUT", "Right DAC_R1 Mixer"},
1036 {"Right HPCOM Mux", "constant VCM", "Right DAC_R1 Mixer"},
1037 {"Right HPCOM Mux", "single-ended", "Right DAC_R1 Mixer"},
1038 {"Right HPCOM Mux", "differential of HPLCOM", "Right DAC_R1 Mixer"},
1039 {"Right HPCOM Mux", "external feedback", "Right DAC_R1 Mixer"},
1041 {"Right Line Out", NULL, "Right DAC_R1 Mixer"},
1042 {"Mono Out", NULL, "Right DAC_R1 Mixer"},
1043 {"Right HP Out", NULL, "Right DAC_R1 Mixer"},
1044 {"Right HP Com", NULL, "Right HPCOM Mux"},
1046 {"RLOUT", NULL, "Right Line Out"},
1047 {"RLOUT", NULL, "Right Line Out"},
1048 {"HPROUT", NULL, "Right HP Out"},
1049 {"HPRCOM", NULL, "Right HP Com"},
1052 {"MONO_LOUT", NULL, "Mono Out"},
1053 {"MONO_LOUT", NULL, "Mono Out"},
1056 {"Left Line1L Mux", "single-ended", "LINE1L"},
1057 {"Left Line1L Mux", "differential", "LINE1L"},
1059 {"Left Line2L Mux", "single-ended", "LINE2L"},
1060 {"Left Line2L Mux", "differential", "LINE2L"},
1062 {"Left PGA Mixer", "Line1L Switch", "Left Line1L Mux"},
1063 {"Left PGA Mixer", "Line2L Switch", "Left Line2L Mux"},
1064 {"Left PGA Mixer", "Mic3L Switch", "MIC3L"},
1066 {"Left ADC", NULL, "Left PGA Mixer"},
1067 {"Left ADC", NULL, "GPIO1 dmic modclk"},
1070 {"Right Line1L Mux", "single-ended", "LINE1L"},
1071 {"Right Line1L Mux", "differential", "LINE1L"},
1073 {"Right Line1R Mux", "single-ended", "LINE1R"},
1074 {"Right Line1R Mux", "differential", "LINE1R"},
1076 {"Right Line2R Mux", "single-ended", "LINE2R"},
1077 {"Right Line2R Mux", "differential", "LINE2R"},
1079 {"Right PGA Mixer", "Line1L Switch", "Right Line1L Mux"},
1080 {"Right PGA Mixer", "Line1R Switch", "Right Line1R Mux"},
1081 {"Right PGA Mixer", "Line2R Switch", "Right Line2R Mux"},
1082 {"Right PGA Mixer", "Mic3R Switch", "MIC3R"},
1084 {"Right ADC", NULL, "Right PGA Mixer"},
1085 {"Right ADC", NULL, "GPIO1 dmic modclk"},
1087 /* Left PGA Bypass */
1088 {"Left PGA Bypass Mixer", "Line Switch", "Left PGA Mixer"},
1089 {"Left PGA Bypass Mixer", "Mono Switch", "Left PGA Mixer"},
1090 {"Left PGA Bypass Mixer", "HP Switch", "Left PGA Mixer"},
1091 {"Left PGA Bypass Mixer", "HPCOM Switch", "Left PGA Mixer"},
1093 {"Left HPCOM Mux", "differential of HPLOUT", "Left PGA Bypass Mixer"},
1094 {"Left HPCOM Mux", "constant VCM", "Left PGA Bypass Mixer"},
1095 {"Left HPCOM Mux", "single-ended", "Left PGA Bypass Mixer"},
1097 {"Left Line Out", NULL, "Left PGA Bypass Mixer"},
1098 {"Mono Out", NULL, "Left PGA Bypass Mixer"},
1099 {"Left HP Out", NULL, "Left PGA Bypass Mixer"},
1101 /* Right PGA Bypass */
1102 {"Right PGA Bypass Mixer", "Line Switch", "Right PGA Mixer"},
1103 {"Right PGA Bypass Mixer", "Mono Switch", "Right PGA Mixer"},
1104 {"Right PGA Bypass Mixer", "HP Switch", "Right PGA Mixer"},
1105 {"Right PGA Bypass Mixer", "HPCOM Switch", "Right PGA Mixer"},
1107 {"Right HPCOM Mux", "differential of HPROUT", "Right PGA Bypass Mixer"},
1108 {"Right HPCOM Mux", "constant VCM", "Right PGA Bypass Mixer"},
1109 {"Right HPCOM Mux", "single-ended", "Right PGA Bypass Mixer"},
1110 {"Right HPCOM Mux", "differential of HPLCOM", "Right PGA Bypass Mixer"},
1111 {"Right HPCOM Mux", "external feedback", "Right PGA Bypass Mixer"},
1113 {"Right Line Out", NULL, "Right PGA Bypass Mixer"},
1114 {"Mono Out", NULL, "Right PGA Bypass Mixer"},
1115 {"Right HP Out", NULL, "Right PGA Bypass Mixer"},
1117 /* Left Line2 Bypass */
1118 {"Left Line2 Bypass Mixer", "Line Switch", "Left Line2L Mux"},
1119 {"Left Line2 Bypass Mixer", "Mono Switch", "Left Line2L Mux"},
1120 {"Left Line2 Bypass Mixer", "HP Switch", "Left Line2L Mux"},
1121 {"Left Line2 Bypass Mixer", "HPCOM Switch", "Left Line2L Mux"},
1123 {"Left HPCOM Mux", "differential of HPLOUT", "Left Line2 Bypass Mixer"},
1124 {"Left HPCOM Mux", "constant VCM", "Left Line2 Bypass Mixer"},
1125 {"Left HPCOM Mux", "single-ended", "Left Line2 Bypass Mixer"},
1127 {"Left Line Out", NULL, "Left Line2 Bypass Mixer"},
1128 {"Mono Out", NULL, "Left Line2 Bypass Mixer"},
1129 {"Left HP Out", NULL, "Left Line2 Bypass Mixer"},
1131 /* Right Line2 Bypass */
1132 {"Right Line2 Bypass Mixer", "Line Switch", "Right Line2R Mux"},
1133 {"Right Line2 Bypass Mixer", "Mono Switch", "Right Line2R Mux"},
1134 {"Right Line2 Bypass Mixer", "HP Switch", "Right Line2R Mux"},
1135 {"Right Line2 Bypass Mixer", "HPCOM Switch", "Right Line2R Mux"},
1137 {"Right HPCOM Mux", "differential of HPROUT", "Right Line2 Bypass Mixer"},
1138 {"Right HPCOM Mux", "constant VCM", "Right Line2 Bypass Mixer"},
1139 {"Right HPCOM Mux", "single-ended", "Right Line2 Bypass Mixer"},
1140 {"Right HPCOM Mux", "differential of HPLCOM", "Right Line2 Bypass Mixer"},
1141 {"Right HPCOM Mux", "external feedback", "Right Line2 Bypass Mixer"},
1143 {"Right Line Out", NULL, "Right Line2 Bypass Mixer"},
1144 {"Mono Out", NULL, "Right Line2 Bypass Mixer"},
1145 {"Right HP Out", NULL, "Right Line2 Bypass Mixer"},
1148 * Logical path between digital mic enable and GPIO1 modulator clock
1151 {"GPIO1 dmic modclk", NULL, "DMic Rate 128"},
1152 {"GPIO1 dmic modclk", NULL, "DMic Rate 64"},
1153 {"GPIO1 dmic modclk", NULL, "DMic Rate 32"},
1156 static int aic3x_add_widgets(struct snd_soc_codec *codec)
1158 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
1159 ARRAY_SIZE(aic3x_dapm_widgets));
1161 /* set up audio path interconnects */
1162 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
1164 snd_soc_dapm_new_widgets(codec);
1168 static int aic3x_hw_params(struct snd_pcm_substream *substream,
1169 struct snd_pcm_hw_params *params)
1171 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1172 struct snd_soc_device *socdev = rtd->socdev;
1173 struct snd_soc_codec *codec = socdev->codec;
1174 struct aic3x_priv *aic3x = codec->private_data;
1175 int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0;
1176 u8 data, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1;
1179 /* select data word length */
1181 aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4));
1182 switch (params_format(params)) {
1183 case SNDRV_PCM_FORMAT_S16_LE:
1185 case SNDRV_PCM_FORMAT_S20_3LE:
1186 data |= (0x01 << 4);
1188 case SNDRV_PCM_FORMAT_S24_LE:
1189 data |= (0x02 << 4);
1191 case SNDRV_PCM_FORMAT_S32_LE:
1192 data |= (0x03 << 4);
1195 aic3x_write(codec, AIC3X_ASD_INTF_CTRLB, data);
1197 /* Fsref can be 44100 or 48000 */
1198 fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000;
1200 /* Try to find a value for Q which allows us to bypass the PLL and
1201 * generate CODEC_CLK directly. */
1202 for (pll_q = 2; pll_q < 18; pll_q++)
1203 if (aic3x->sysclk / (128 * pll_q) == fsref) {
1210 aic3x_write(codec, AIC3X_PLL_PROGA_REG, pll_q << PLLQ_SHIFT);
1211 aic3x_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_CLKDIV);
1213 aic3x_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_PLLDIV);
1215 /* Route Left DAC to left channel input and
1216 * right DAC to right channel input */
1217 data = (LDAC2LCH | RDAC2RCH);
1218 data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000;
1219 if (params_rate(params) >= 64000)
1220 data |= DUAL_RATE_MODE;
1221 aic3x_write(codec, AIC3X_CODEC_DATAPATH_REG, data);
1223 /* codec sample rate select */
1224 data = (fsref * 20) / params_rate(params);
1225 if (params_rate(params) < 64000)
1229 data |= (data << 4);
1230 aic3x_write(codec, AIC3X_SAMPLE_RATE_SEL_REG, data);
1236 * find an apropriate setup for j, d, r and p by iterating over
1237 * p and r - j and d are calculated for each fraction.
1238 * Up to 128 values are probed, the closest one wins the game.
1239 * The sysclk is divided by 1000 to prevent integer overflows.
1241 codec_clk = (2048 * fsref) / (aic3x->sysclk / 1000);
1243 for (r = 1; r <= 16; r++)
1244 for (p = 1; p <= 8; p++) {
1245 int clk, tmp = (codec_clk * pll_r * 10) / pll_p;
1247 u16 d = tmp % 10000;
1252 if (d != 0 && aic3x->sysclk < 10000000)
1255 /* This is actually 1000 * ((j + (d/10000)) * r) / p
1256 * The term had to be converted to get rid of the
1257 * division by 10000 */
1258 clk = ((10000 * j * r) + (d * r)) / (10 * p);
1260 /* check whether this values get closer than the best
1261 * ones we had before */
1262 if (abs(codec_clk - clk) < abs(codec_clk - last_clk)) {
1263 pll_j = j; pll_d = d; pll_r = r; pll_p = p;
1267 /* Early exit for exact matches */
1268 if (clk == codec_clk)
1272 if (last_clk == 0) {
1273 printk(KERN_ERR "%s(): unable to setup PLL\n", __func__);
1277 data = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG);
1278 aic3x_write(codec, AIC3X_PLL_PROGA_REG, data | (pll_p << PLLP_SHIFT));
1279 aic3x_write(codec, AIC3X_OVRF_STATUS_AND_PLLR_REG, pll_r << PLLR_SHIFT);
1280 aic3x_write(codec, AIC3X_PLL_PROGB_REG, pll_j << PLLJ_SHIFT);
1281 aic3x_write(codec, AIC3X_PLL_PROGC_REG, (pll_d >> 6) << PLLD_MSB_SHIFT);
1282 aic3x_write(codec, AIC3X_PLL_PROGD_REG,
1283 (pll_d & 0x3F) << PLLD_LSB_SHIFT);
1288 static int aic3x_mute(struct snd_soc_dai *dai, int mute)
1290 struct snd_soc_codec *codec = dai->codec;
1291 u8 ldac_reg = aic3x_read_reg_cache(codec, LDAC_VOL) & ~MUTE_ON;
1292 u8 rdac_reg = aic3x_read_reg_cache(codec, RDAC_VOL) & ~MUTE_ON;
1295 aic3x_write(codec, LDAC_VOL, ldac_reg | MUTE_ON);
1296 aic3x_write(codec, RDAC_VOL, rdac_reg | MUTE_ON);
1298 aic3x_write(codec, LDAC_VOL, ldac_reg);
1299 aic3x_write(codec, RDAC_VOL, rdac_reg);
1305 static int aic3x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
1306 int clk_id, unsigned int freq, int dir)
1308 struct snd_soc_codec *codec = codec_dai->codec;
1309 struct aic3x_priv *aic3x = codec->private_data;
1311 aic3x->sysclk = freq;
1315 static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
1318 struct snd_soc_codec *codec = codec_dai->codec;
1319 struct aic3x_priv *aic3x = codec->private_data;
1320 u8 iface_areg, iface_breg;
1323 iface_areg = aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLA) & 0x3f;
1324 iface_breg = aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLB) & 0x3f;
1326 /* set master/slave audio interface */
1327 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1328 case SND_SOC_DAIFMT_CBM_CFM:
1330 iface_areg |= BIT_CLK_MASTER | WORD_CLK_MASTER;
1332 case SND_SOC_DAIFMT_CBS_CFS:
1340 * match both interface format and signal polarities since they
1343 switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK |
1344 SND_SOC_DAIFMT_INV_MASK)) {
1345 case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF):
1347 case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF):
1349 case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF):
1350 iface_breg |= (0x01 << 6);
1352 case (SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_NB_NF):
1353 iface_breg |= (0x02 << 6);
1355 case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF):
1356 iface_breg |= (0x03 << 6);
1363 aic3x_write(codec, AIC3X_ASD_INTF_CTRLA, iface_areg);
1364 aic3x_write(codec, AIC3X_ASD_INTF_CTRLB, iface_breg);
1365 aic3x_write(codec, AIC3X_ASD_INTF_CTRLC, delay);
1370 static int aic3x_set_bias_level(struct snd_soc_codec *codec,
1371 enum snd_soc_bias_level level)
1373 struct aic3x_priv *aic3x = codec->private_data;
1377 case SND_SOC_BIAS_ON:
1378 /* all power is driven by DAPM system */
1379 if (aic3x->master) {
1381 reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG);
1382 aic3x_write(codec, AIC3X_PLL_PROGA_REG,
1385 * ensure that bit and word clocks are running also if
1386 * DAC and ADC are shutdown
1388 reg = aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLA);
1389 aic3x_write(codec, AIC3X_ASD_INTF_CTRLA, reg | 0x10);
1392 case SND_SOC_BIAS_PREPARE:
1394 case SND_SOC_BIAS_STANDBY:
1396 * all power is driven by DAPM system,
1397 * so output power is safe if bypass was set
1399 if (aic3x->master) {
1400 reg = aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLA);
1401 aic3x_write(codec, AIC3X_ASD_INTF_CTRLA, reg & ~0x10);
1403 reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG);
1404 aic3x_write(codec, AIC3X_PLL_PROGA_REG,
1407 /* Reset cannot be issued, if bypass paths are in use */
1408 if (!aic3x->prepare_reset)
1411 case SND_SOC_BIAS_OFF:
1412 /* force all power off */
1413 reg = aic3x_read_reg_cache(codec, LINE1L_2_LADC_CTRL);
1414 aic3x_write(codec, LINE1L_2_LADC_CTRL, reg & ~LADC_PWR_ON);
1415 reg = aic3x_read_reg_cache(codec, LINE1R_2_RADC_CTRL);
1416 aic3x_write(codec, LINE1R_2_RADC_CTRL, reg & ~RADC_PWR_ON);
1418 reg = aic3x_read_reg_cache(codec, DAC_PWR);
1419 aic3x_write(codec, DAC_PWR, reg & ~(LDAC_PWR_ON | RDAC_PWR_ON));
1421 reg = aic3x_read_reg_cache(codec, HPLOUT_CTRL);
1422 aic3x_write(codec, HPLOUT_CTRL, reg & ~HPLOUT_PWR_ON);
1423 reg = aic3x_read_reg_cache(codec, HPROUT_CTRL);
1424 aic3x_write(codec, HPROUT_CTRL, reg & ~HPROUT_PWR_ON);
1426 reg = aic3x_read_reg_cache(codec, HPLCOM_CTRL);
1427 aic3x_write(codec, HPLCOM_CTRL, reg & ~HPLCOM_PWR_ON);
1428 reg = aic3x_read_reg_cache(codec, HPRCOM_CTRL);
1429 aic3x_write(codec, HPRCOM_CTRL, reg & ~HPRCOM_PWR_ON);
1431 reg = aic3x_read_reg_cache(codec, MONOLOPM_CTRL);
1432 aic3x_write(codec, MONOLOPM_CTRL, reg & ~MONOLOPM_PWR_ON);
1434 reg = aic3x_read_reg_cache(codec, LLOPM_CTRL);
1435 aic3x_write(codec, LLOPM_CTRL, reg & ~LLOPM_PWR_ON);
1436 reg = aic3x_read_reg_cache(codec, RLOPM_CTRL);
1437 aic3x_write(codec, RLOPM_CTRL, reg & ~RLOPM_PWR_ON);
1439 if (aic3x->master) {
1440 reg = aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLA);
1441 aic3x_write(codec, AIC3X_ASD_INTF_CTRLA, reg & ~0x10);
1443 reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG);
1444 aic3x_write(codec, AIC3X_PLL_PROGA_REG,
1449 codec->bias_level = level;
1454 void aic3x_set_gpio(struct snd_soc_codec *codec, int gpio, int state)
1456 u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG;
1457 u8 bit = gpio ? 3: 0;
1458 u8 val = aic3x_read_reg_cache(codec, reg) & ~(1 << bit);
1459 aic3x_write(codec, reg, val | (!!state << bit));
1461 EXPORT_SYMBOL_GPL(aic3x_set_gpio);
1463 int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio)
1465 u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG;
1466 u8 val, bit = gpio ? 2: 1;
1468 aic3x_read(codec, reg, &val);
1469 return (val >> bit) & 1;
1471 EXPORT_SYMBOL_GPL(aic3x_get_gpio);
1473 int aic3x_headset_detected(struct snd_soc_codec *codec)
1476 aic3x_read(codec, AIC3X_RT_IRQ_FLAGS_REG, &val);
1477 return (val >> 2) & 1;
1479 EXPORT_SYMBOL_GPL(aic3x_headset_detected);
1481 #define AIC3X_RATES SNDRV_PCM_RATE_8000_96000
1482 #define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1483 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
1485 struct snd_soc_dai aic3x_dai = {
1486 .name = "tlv320aic3x",
1488 .stream_name = "Playback",
1491 .rates = AIC3X_RATES,
1492 .formats = AIC3X_FORMATS,},
1494 .stream_name = "Capture",
1497 .rates = AIC3X_RATES,
1498 .formats = AIC3X_FORMATS,},
1500 .hw_params = aic3x_hw_params,
1503 .digital_mute = aic3x_mute,
1504 .set_sysclk = aic3x_set_dai_sysclk,
1505 .set_fmt = aic3x_set_dai_fmt,
1508 EXPORT_SYMBOL_GPL(aic3x_dai);
1510 static int aic3x_suspend(struct platform_device *pdev, pm_message_t state)
1512 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1513 struct snd_soc_codec *codec = socdev->codec;
1515 aic3x_write(codec, AIC3X_RESET, SOFT_RESET);
1520 static int aic3x_resume(struct platform_device *pdev)
1522 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1523 aic3x_sync_hw(socdev->codec);
1524 aic3x_set_bias_level(socdev->codec,
1525 socdev->codec->suspend_bias_level);
1531 * initialise the AIC3X driver
1532 * register the mixer and dsp interfaces with the kernel
1534 static int aic3x_init(struct snd_soc_device *socdev)
1536 struct snd_soc_codec *codec = socdev->codec;
1537 struct aic3x_setup_data *setup = socdev->codec_data;
1538 struct snd_hwdep *hwdep;
1539 char hwdepid[] = "IIR Filter";
1542 printk("MNZ: BEGIN aic3x_init\n");
1543 codec->name = "tlv320aic3x";
1544 codec->owner = THIS_MODULE;
1545 codec->read = aic3x_read_reg_cache;
1546 codec->write = aic3x_write;
1547 codec->set_bias_level = aic3x_set_bias_level;
1548 codec->dai = &aic3x_dai;
1550 codec->reg_cache_size = ARRAY_SIZE(aic3x_reg);
1551 codec->reg_cache = kmemdup(aic3x_reg, sizeof(aic3x_reg), GFP_KERNEL);
1552 if (codec->reg_cache == NULL)
1555 aic3x_write(codec, AIC3X_PAGE_SELECT, PAGE0_SELECT);
1556 aic3x_write(codec, AIC3X_RESET, SOFT_RESET);
1559 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
1561 printk(KERN_ERR "aic3x: failed to create pcms\n");
1565 /* DAC default volume and mute */
1566 aic3x_write(codec, LDAC_VOL, DEFAULT_VOL | MUTE_ON);
1567 aic3x_write(codec, RDAC_VOL, DEFAULT_VOL | MUTE_ON);
1569 /* DAC to HP default volume and route to Output mixer */
1570 aic3x_write(codec, DACL1_2_HPLOUT_VOL, DEFAULT_VOL | ROUTE_ON);
1571 aic3x_write(codec, DACR1_2_HPROUT_VOL, DEFAULT_VOL | ROUTE_ON);
1572 aic3x_write(codec, DACL1_2_HPLCOM_VOL, DEFAULT_VOL | ROUTE_ON);
1573 aic3x_write(codec, DACR1_2_HPRCOM_VOL, DEFAULT_VOL | ROUTE_ON);
1574 /* DAC to Line Out default volume and route to Output mixer */
1575 aic3x_write(codec, DACL1_2_LLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1576 aic3x_write(codec, DACR1_2_RLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1577 /* DAC to Mono Line Out default volume and route to Output mixer */
1578 aic3x_write(codec, DACL1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1579 aic3x_write(codec, DACR1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1581 /* unmute all outputs */
1582 reg = aic3x_read_reg_cache(codec, LLOPM_CTRL);
1583 aic3x_write(codec, LLOPM_CTRL, reg | UNMUTE);
1584 reg = aic3x_read_reg_cache(codec, RLOPM_CTRL);
1585 aic3x_write(codec, RLOPM_CTRL, reg | UNMUTE);
1586 reg = aic3x_read_reg_cache(codec, MONOLOPM_CTRL);
1587 aic3x_write(codec, MONOLOPM_CTRL, reg | UNMUTE);
1588 reg = aic3x_read_reg_cache(codec, HPLOUT_CTRL);
1589 aic3x_write(codec, HPLOUT_CTRL, reg | UNMUTE);
1590 reg = aic3x_read_reg_cache(codec, HPROUT_CTRL);
1591 aic3x_write(codec, HPROUT_CTRL, reg | UNMUTE);
1592 reg = aic3x_read_reg_cache(codec, HPLCOM_CTRL);
1593 aic3x_write(codec, HPLCOM_CTRL, reg | UNMUTE);
1594 reg = aic3x_read_reg_cache(codec, HPRCOM_CTRL);
1595 aic3x_write(codec, HPRCOM_CTRL, reg | UNMUTE);
1597 /* ADC default volume and unmute */
1598 aic3x_write(codec, LADC_VOL, DEFAULT_GAIN);
1599 aic3x_write(codec, RADC_VOL, DEFAULT_GAIN);
1600 /* By default route Line1 to ADC PGA mixer */
1601 aic3x_write(codec, LINE1L_2_LADC_CTRL, 0x0);
1602 aic3x_write(codec, LINE1R_2_RADC_CTRL, 0x0);
1604 /* PGA to HP Bypass default volume, disconnect from Output Mixer */
1605 aic3x_write(codec, PGAL_2_HPLOUT_VOL, DEFAULT_VOL);
1606 aic3x_write(codec, PGAR_2_HPROUT_VOL, DEFAULT_VOL);
1607 aic3x_write(codec, PGAL_2_HPLCOM_VOL, DEFAULT_VOL);
1608 aic3x_write(codec, PGAR_2_HPRCOM_VOL, DEFAULT_VOL);
1609 /* PGA to Line Out default volume, disconnect from Output Mixer */
1610 aic3x_write(codec, PGAL_2_LLOPM_VOL, DEFAULT_VOL);
1611 aic3x_write(codec, PGAR_2_RLOPM_VOL, DEFAULT_VOL);
1612 /* PGA to Mono Line Out default volume, disconnect from Output Mixer */
1613 aic3x_write(codec, PGAL_2_MONOLOPM_VOL, DEFAULT_VOL);
1614 aic3x_write(codec, PGAR_2_MONOLOPM_VOL, DEFAULT_VOL);
1616 /* Line2 to HP Bypass default volume, disconnect from Output Mixer */
1617 aic3x_write(codec, LINE2L_2_HPLOUT_VOL, DEFAULT_VOL);
1618 aic3x_write(codec, LINE2R_2_HPROUT_VOL, DEFAULT_VOL);
1619 aic3x_write(codec, LINE2L_2_HPLCOM_VOL, DEFAULT_VOL);
1620 aic3x_write(codec, LINE2R_2_HPRCOM_VOL, DEFAULT_VOL);
1621 /* Line2 Line Out default volume, disconnect from Output Mixer */
1622 aic3x_write(codec, LINE2L_2_LLOPM_VOL, DEFAULT_VOL);
1623 aic3x_write(codec, LINE2R_2_RLOPM_VOL, DEFAULT_VOL);
1624 /* Line2 to Mono Out default volume, disconnect from Output Mixer */
1625 aic3x_write(codec, LINE2L_2_MONOLOPM_VOL, DEFAULT_VOL);
1626 aic3x_write(codec, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL);
1628 /* off, with power on */
1629 aic3x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1631 /* setup GPIO functions */
1632 aic3x_write(codec, AIC3X_GPIO1_REG, (setup->gpio_func[0] & 0xf) << 4);
1633 aic3x_write(codec, AIC3X_GPIO2_REG, (setup->gpio_func[1] & 0xf) << 4);
1635 aic3x_add_controls(codec);
1636 aic3x_add_widgets(codec);
1638 if(snd_hwdep_new(codec->card, hwdepid, 0, &hwdep) == 0){
1639 hwdep->private_data = codec;
1640 sprintf(hwdep->name, hwdepid);
1641 hwdep->ops.open = snd_hwdep_dacfilter_open_aic3x;
1642 hwdep->ops.ioctl = snd_hwdep_dacfilter_ioctl_aic3x;
1643 hwdep->ops.read = snd_hwdep_dacfilter_read_aic3x;
1644 hwdep->ops.write = snd_hwdep_dacfilter_write_aic3x;
1645 ((struct aic3x_priv*)codec->private_data)->hwdep = hwdep;
1648 ret = snd_soc_register_card(socdev);
1651 printk(KERN_ERR "aic3x: failed to register card\n");
1655 /* Set some defaults for coefficients */
1656 aic3x_write_coeff(codec, EFFECTS_3DATTEN, -32768);
1657 printk("MNZ: END aic3x_init\n");
1662 snd_soc_free_pcms(socdev);
1663 snd_soc_dapm_free(socdev);
1665 kfree(codec->reg_cache);
1669 static struct snd_soc_device *aic3x_socdev;
1671 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1673 * AIC3X 2 wire address can be up to 4 devices with device addresses
1674 * 0x18, 0x19, 0x1A, 0x1B
1678 * If the i2c layer weren't so broken, we could pass this kind of data
1681 static int aic3x_i2c_probe(struct i2c_client *i2c,
1682 const struct i2c_device_id *id)
1684 struct snd_soc_device *socdev = aic3x_socdev;
1685 struct snd_soc_codec *codec = socdev->codec;
1688 i2c_set_clientdata(i2c, codec);
1689 codec->control_data = i2c;
1691 ret = aic3x_init(socdev);
1693 printk(KERN_ERR "aic3x: failed to initialise AIC3X\n");
1697 static int aic3x_i2c_remove(struct i2c_client *client)
1699 struct snd_soc_codec *codec = i2c_get_clientdata(client);
1700 kfree(codec->reg_cache);
1704 static const struct i2c_device_id aic3x_i2c_id[] = {
1705 { "tlv320aic3x", 0 },
1708 MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id);
1710 /* machine i2c codec control layer */
1711 static struct i2c_driver aic3x_i2c_driver = {
1713 .name = "aic3x I2C Codec",
1714 .owner = THIS_MODULE,
1716 .probe = aic3x_i2c_probe,
1717 .remove = aic3x_i2c_remove,
1718 .id_table = aic3x_i2c_id,
1721 static int aic3x_i2c_read(struct i2c_client *client, u8 *value, int len)
1723 value[0] = i2c_smbus_read_byte_data(client, value[0]);
1727 static int aic3x_add_i2c_device(struct platform_device *pdev,
1728 const struct aic3x_setup_data *setup)
1730 struct i2c_board_info info;
1731 struct i2c_adapter *adapter;
1732 struct i2c_client *client;
1735 ret = i2c_add_driver(&aic3x_i2c_driver);
1737 dev_err(&pdev->dev, "can't add i2c driver\n");
1741 memset(&info, 0, sizeof(struct i2c_board_info));
1742 info.addr = setup->i2c_address;
1743 strlcpy(info.type, "tlv320aic3x", I2C_NAME_SIZE);
1745 adapter = i2c_get_adapter(setup->i2c_bus);
1747 dev_err(&pdev->dev, "can't get i2c adapter %d\n",
1752 client = i2c_new_device(adapter, &info);
1753 i2c_put_adapter(adapter);
1755 dev_err(&pdev->dev, "can't add i2c device at 0x%x\n",
1756 (unsigned int)info.addr);
1763 i2c_del_driver(&aic3x_i2c_driver);
1768 static int aic3x_probe(struct platform_device *pdev)
1770 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1771 struct aic3x_setup_data *setup;
1772 struct snd_soc_codec *codec;
1773 struct aic3x_priv *aic3x;
1776 printk(KERN_INFO "AIC3X Audio Codec %s\n", AIC3X_VERSION);
1778 setup = socdev->codec_data;
1779 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
1783 aic3x = kzalloc(sizeof(struct aic3x_priv), GFP_KERNEL);
1784 memcpy(&aic3x->dacfilter, &aic3x_dacfilter, sizeof(aic3x_dacfilter));
1786 if (aic3x == NULL) {
1791 codec->private_data = aic3x;
1792 socdev->codec = codec;
1793 mutex_init(&codec->mutex);
1794 INIT_LIST_HEAD(&codec->dapm_widgets);
1795 INIT_LIST_HEAD(&codec->dapm_paths);
1797 aic3x_socdev = socdev;
1798 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1799 if (setup->i2c_address) {
1800 codec->hw_write = (hw_write_t) i2c_master_send;
1801 codec->hw_read = (hw_read_t) aic3x_i2c_read;
1802 ret = aic3x_add_i2c_device(pdev, setup);
1805 /* Add other interfaces here */
1809 kfree(codec->private_data);
1815 static int aic3x_remove(struct platform_device *pdev)
1817 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1818 struct snd_soc_codec *codec = socdev->codec;
1820 /* power down chip */
1821 if (codec->control_data)
1822 aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
1824 snd_soc_free_pcms(socdev);
1825 snd_soc_dapm_free(socdev);
1826 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1827 if (codec->control_data)
1828 i2c_unregister_device(codec->control_data);
1829 i2c_del_driver(&aic3x_i2c_driver);
1831 kfree(codec->private_data);
1837 struct snd_soc_codec_device soc_codec_dev_aic3x = {
1838 .probe = aic3x_probe,
1839 .remove = aic3x_remove,
1840 .suspend = aic3x_suspend,
1841 .resume = aic3x_resume,
1843 EXPORT_SYMBOL_GPL(soc_codec_dev_aic3x);
1845 MODULE_DESCRIPTION("ASoC TLV320AIC3X codec driver");
1846 MODULE_AUTHOR("Vladimir Barinov");
1847 MODULE_LICENSE("GPL");