blob: 867bf1fb182567c5ad99f4ac854a94ba0d6a9a4b [file] [log] [blame]
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001/*
2 * ALSA SoC TLV320AIC3X codec driver
3 *
Vladimir Barinovd6b52032008-09-29 23:14:11 +04004 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
Vladimir Barinov44d0a872007-11-14 17:07:17 +01005 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * Based on sound/soc/codecs/wm8753.c by Liam Girdwood
8 *
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.
12 *
13 * Notes:
14 * The AIC3X is a driver for a low power stereo audio
15 * codecs aic31, aic32, aic33.
16 *
17 * It supports full aic33 codec functionality.
18 * The compatibility with aic32, aic31 is as follows:
19 * aic32 | aic31
20 * ---------------------------------------
21 * MONO_LOUT -> N/A | MONO_LOUT -> N/A
22 * | IN1L -> LINE1L
23 * | IN1R -> LINE1R
24 * | IN2L -> LINE2L
25 * | IN2R -> LINE2R
26 * | MIC3L/R -> N/A
27 * truncated internal functionality in
28 * accordance with documentation
29 * ---------------------------------------
30 *
31 * Hence the machine layer should disable unsupported inputs/outputs by
Liam Girdwooda5302182008-07-07 13:35:17 +010032 * snd_soc_dapm_disable_pin(codec, "MONO_LOUT"), etc.
Vladimir Barinov44d0a872007-11-14 17:07:17 +010033 */
34
35#include <linux/module.h>
36#include <linux/moduleparam.h>
37#include <linux/init.h>
38#include <linux/delay.h>
39#include <linux/pm.h>
40#include <linux/i2c.h>
Jarkko Nikula5193d622010-05-05 13:02:03 +030041#include <linux/gpio.h>
Jarkko Nikula07779fd2010-04-26 15:49:14 +030042#include <linux/regulator/consumer.h>
Vladimir Barinov44d0a872007-11-14 17:07:17 +010043#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090044#include <linux/slab.h>
Vladimir Barinov44d0a872007-11-14 17:07:17 +010045#include <sound/core.h>
46#include <sound/pcm.h>
47#include <sound/pcm_params.h>
48#include <sound/soc.h>
49#include <sound/soc-dapm.h>
50#include <sound/initval.h>
Jarkko Nikula7565fc32009-02-09 14:27:07 +020051#include <sound/tlv.h>
Jarkko Nikula5193d622010-05-05 13:02:03 +030052#include <sound/tlv320aic3x.h>
Vladimir Barinov44d0a872007-11-14 17:07:17 +010053
54#include "tlv320aic3x.h"
55
Jarkko Nikula07779fd2010-04-26 15:49:14 +030056#define AIC3X_NUM_SUPPLIES 4
57static const char *aic3x_supply_names[AIC3X_NUM_SUPPLIES] = {
58 "IOVDD", /* I/O Voltage */
59 "DVDD", /* Digital Core Voltage */
60 "AVDD", /* Analog DAC Voltage */
61 "DRVDD", /* ADC Analog and Output Driver Voltage */
62};
Vladimir Barinov44d0a872007-11-14 17:07:17 +010063
64/* codec private data */
65struct aic3x_priv {
Jarkko Nikula07779fd2010-04-26 15:49:14 +030066 struct regulator_bulk_data supplies[AIC3X_NUM_SUPPLIES];
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000067 enum snd_soc_control_type control_type;
68 struct aic3x_setup_data *setup;
69 void *control_data;
Vladimir Barinov44d0a872007-11-14 17:07:17 +010070 unsigned int sysclk;
71 int master;
Jarkko Nikula5193d622010-05-05 13:02:03 +030072 int gpio_reset;
Vladimir Barinov44d0a872007-11-14 17:07:17 +010073};
74
75/*
76 * AIC3X register cache
77 * We can't read the AIC3X register space when we are
78 * using 2 wire for device control, so we cache them instead.
79 * There is no point in caching the reset register
80 */
81static const u8 aic3x_reg[AIC3X_CACHEREGNUM] = {
82 0x00, 0x00, 0x00, 0x10, /* 0 */
83 0x04, 0x00, 0x00, 0x00, /* 4 */
84 0x00, 0x00, 0x00, 0x01, /* 8 */
85 0x00, 0x00, 0x00, 0x80, /* 12 */
86 0x80, 0xff, 0xff, 0x78, /* 16 */
87 0x78, 0x78, 0x78, 0x78, /* 20 */
88 0x78, 0x00, 0x00, 0xfe, /* 24 */
89 0x00, 0x00, 0xfe, 0x00, /* 28 */
90 0x18, 0x18, 0x00, 0x00, /* 32 */
91 0x00, 0x00, 0x00, 0x00, /* 36 */
92 0x00, 0x00, 0x00, 0x80, /* 40 */
93 0x80, 0x00, 0x00, 0x00, /* 44 */
94 0x00, 0x00, 0x00, 0x04, /* 48 */
95 0x00, 0x00, 0x00, 0x00, /* 52 */
96 0x00, 0x00, 0x04, 0x00, /* 56 */
97 0x00, 0x00, 0x00, 0x00, /* 60 */
98 0x00, 0x04, 0x00, 0x00, /* 64 */
99 0x00, 0x00, 0x00, 0x00, /* 68 */
100 0x04, 0x00, 0x00, 0x00, /* 72 */
101 0x00, 0x00, 0x00, 0x00, /* 76 */
102 0x00, 0x00, 0x00, 0x00, /* 80 */
103 0x00, 0x00, 0x00, 0x00, /* 84 */
104 0x00, 0x00, 0x00, 0x00, /* 88 */
105 0x00, 0x00, 0x00, 0x00, /* 92 */
106 0x00, 0x00, 0x00, 0x00, /* 96 */
107 0x00, 0x00, 0x02, /* 100 */
108};
109
110/*
111 * read aic3x register cache
112 */
113static inline unsigned int aic3x_read_reg_cache(struct snd_soc_codec *codec,
114 unsigned int reg)
115{
116 u8 *cache = codec->reg_cache;
117 if (reg >= AIC3X_CACHEREGNUM)
118 return -1;
119 return cache[reg];
120}
121
122/*
123 * write aic3x register cache
124 */
125static inline void aic3x_write_reg_cache(struct snd_soc_codec *codec,
126 u8 reg, u8 value)
127{
128 u8 *cache = codec->reg_cache;
129 if (reg >= AIC3X_CACHEREGNUM)
130 return;
131 cache[reg] = value;
132}
133
134/*
135 * write to the aic3x register space
136 */
137static int aic3x_write(struct snd_soc_codec *codec, unsigned int reg,
138 unsigned int value)
139{
140 u8 data[2];
141
142 /* data is
143 * D15..D8 aic3x register offset
144 * D7...D0 register data
145 */
146 data[0] = reg & 0xff;
147 data[1] = value & 0xff;
148
149 aic3x_write_reg_cache(codec, data[0], data[1]);
150 if (codec->hw_write(codec->control_data, data, 2) == 2)
151 return 0;
152 else
153 return -EIO;
154}
155
Daniel Mack54e7e612008-04-30 16:20:52 +0200156/*
157 * read from the aic3x register space
158 */
159static int aic3x_read(struct snd_soc_codec *codec, unsigned int reg,
160 u8 *value)
161{
162 *value = reg & 0xff;
Mark Brown5f345342009-07-05 17:35:28 +0100163
164 value[0] = i2c_smbus_read_byte_data(codec->control_data, value[0]);
Daniel Mack54e7e612008-04-30 16:20:52 +0200165
166 aic3x_write_reg_cache(codec, reg, *value);
167 return 0;
168}
169
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100170#define SOC_DAPM_SINGLE_AIC3X(xname, reg, shift, mask, invert) \
171{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
172 .info = snd_soc_info_volsw, \
173 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw_aic3x, \
174 .private_value = SOC_SINGLE_VALUE(reg, shift, mask, invert) }
175
176/*
177 * All input lines are connected when !0xf and disconnected with 0xf bit field,
178 * so we have to use specific dapm_put call for input mixer
179 */
180static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,
181 struct snd_ctl_elem_value *ucontrol)
182{
183 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
Eero Nurkkala4453dba2009-02-06 12:01:04 +0200184 struct soc_mixer_control *mc =
185 (struct soc_mixer_control *)kcontrol->private_value;
186 unsigned int reg = mc->reg;
187 unsigned int shift = mc->shift;
188 int max = mc->max;
189 unsigned int mask = (1 << fls(max)) - 1;
190 unsigned int invert = mc->invert;
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100191 unsigned short val, val_mask;
192 int ret;
193 struct snd_soc_dapm_path *path;
194 int found = 0;
195
196 val = (ucontrol->value.integer.value[0] & mask);
197
198 mask = 0xf;
199 if (val)
200 val = mask;
201
202 if (invert)
203 val = mask - val;
204 val_mask = mask << shift;
205 val = val << shift;
206
207 mutex_lock(&widget->codec->mutex);
208
209 if (snd_soc_test_bits(widget->codec, reg, val_mask, val)) {
210 /* find dapm widget path assoc with kcontrol */
211 list_for_each_entry(path, &widget->codec->dapm_paths, list) {
212 if (path->kcontrol != kcontrol)
213 continue;
214
215 /* found, now check type */
216 found = 1;
217 if (val)
218 /* new connection */
219 path->connect = invert ? 0 : 1;
220 else
221 /* old connection must be powered down */
222 path->connect = invert ? 1 : 0;
223 break;
224 }
225
226 if (found)
Liam Girdwooda5302182008-07-07 13:35:17 +0100227 snd_soc_dapm_sync(widget->codec);
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100228 }
229
230 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
231
232 mutex_unlock(&widget->codec->mutex);
233 return ret;
234}
235
236static const char *aic3x_left_dac_mux[] = { "DAC_L1", "DAC_L3", "DAC_L2" };
237static const char *aic3x_right_dac_mux[] = { "DAC_R1", "DAC_R3", "DAC_R2" };
238static const char *aic3x_left_hpcom_mux[] =
239 { "differential of HPLOUT", "constant VCM", "single-ended" };
240static const char *aic3x_right_hpcom_mux[] =
241 { "differential of HPROUT", "constant VCM", "single-ended",
242 "differential of HPLCOM", "external feedback" };
243static const char *aic3x_linein_mode_mux[] = { "single-ended", "differential" };
Jarkko Nikula4d20f702008-06-27 14:07:57 +0300244static const char *aic3x_adc_hpf[] =
245 { "Disabled", "0.0045xFs", "0.0125xFs", "0.025xFs" };
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100246
247#define LDAC_ENUM 0
248#define RDAC_ENUM 1
249#define LHPCOM_ENUM 2
250#define RHPCOM_ENUM 3
251#define LINE1L_ENUM 4
252#define LINE1R_ENUM 5
253#define LINE2L_ENUM 6
254#define LINE2R_ENUM 7
Jarkko Nikula4d20f702008-06-27 14:07:57 +0300255#define ADC_HPF_ENUM 8
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100256
257static const struct soc_enum aic3x_enum[] = {
258 SOC_ENUM_SINGLE(DAC_LINE_MUX, 6, 3, aic3x_left_dac_mux),
259 SOC_ENUM_SINGLE(DAC_LINE_MUX, 4, 3, aic3x_right_dac_mux),
260 SOC_ENUM_SINGLE(HPLCOM_CFG, 4, 3, aic3x_left_hpcom_mux),
261 SOC_ENUM_SINGLE(HPRCOM_CFG, 3, 5, aic3x_right_hpcom_mux),
262 SOC_ENUM_SINGLE(LINE1L_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux),
263 SOC_ENUM_SINGLE(LINE1R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux),
264 SOC_ENUM_SINGLE(LINE2L_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux),
265 SOC_ENUM_SINGLE(LINE2R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux),
Jarkko Nikula4d20f702008-06-27 14:07:57 +0300266 SOC_ENUM_DOUBLE(AIC3X_CODEC_DFILT_CTRL, 6, 4, 4, aic3x_adc_hpf),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100267};
268
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200269/*
270 * DAC digital volumes. From -63.5 to 0 dB in 0.5 dB steps
271 */
272static DECLARE_TLV_DB_SCALE(dac_tlv, -6350, 50, 0);
273/* ADC PGA gain volumes. From 0 to 59.5 dB in 0.5 dB steps */
274static DECLARE_TLV_DB_SCALE(adc_tlv, 0, 50, 0);
275/*
276 * Output stage volumes. From -78.3 to 0 dB. Muted below -78.3 dB.
277 * Step size is approximately 0.5 dB over most of the scale but increasing
278 * near the very low levels.
279 * Define dB scale so that it is mostly correct for range about -55 to 0 dB
280 * but having increasing dB difference below that (and where it doesn't count
281 * so much). This setting shows -50 dB (actual is -50.3 dB) for register
282 * value 100 and -58.5 dB (actual is -78.3 dB) for register value 117.
283 */
284static DECLARE_TLV_DB_SCALE(output_stage_tlv, -5900, 50, 1);
285
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100286static const struct snd_kcontrol_new aic3x_snd_controls[] = {
287 /* Output */
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200288 SOC_DOUBLE_R_TLV("PCM Playback Volume",
289 LDAC_VOL, RDAC_VOL, 0, 0x7f, 1, dac_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100290
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200291 SOC_DOUBLE_R_TLV("Line DAC Playback Volume",
292 DACL1_2_LLOPM_VOL, DACR1_2_RLOPM_VOL,
293 0, 118, 1, output_stage_tlv),
Daniel Mack28a1d862008-12-05 17:31:00 +0100294 SOC_SINGLE("LineL Playback Switch", LLOPM_CTRL, 3, 0x01, 0),
295 SOC_SINGLE("LineR Playback Switch", RLOPM_CTRL, 3, 0x01, 0),
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200296 SOC_DOUBLE_R_TLV("LineL DAC Playback Volume",
297 DACL1_2_LLOPM_VOL, DACR1_2_LLOPM_VOL,
298 0, 118, 1, output_stage_tlv),
299 SOC_SINGLE_TLV("LineL Left PGA Bypass Playback Volume",
300 PGAL_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
301 SOC_SINGLE_TLV("LineR Right PGA Bypass Playback Volume",
302 PGAR_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
303 SOC_DOUBLE_R_TLV("LineL Line2 Bypass Playback Volume",
304 LINE2L_2_LLOPM_VOL, LINE2R_2_LLOPM_VOL,
305 0, 118, 1, output_stage_tlv),
306 SOC_DOUBLE_R_TLV("LineR Line2 Bypass Playback Volume",
307 LINE2L_2_RLOPM_VOL, LINE2R_2_RLOPM_VOL,
308 0, 118, 1, output_stage_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100309
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200310 SOC_DOUBLE_R_TLV("Mono DAC Playback Volume",
311 DACL1_2_MONOLOPM_VOL, DACR1_2_MONOLOPM_VOL,
312 0, 118, 1, output_stage_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100313 SOC_SINGLE("Mono DAC Playback Switch", MONOLOPM_CTRL, 3, 0x01, 0),
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200314 SOC_DOUBLE_R_TLV("Mono PGA Bypass Playback Volume",
315 PGAL_2_MONOLOPM_VOL, PGAR_2_MONOLOPM_VOL,
316 0, 118, 1, output_stage_tlv),
317 SOC_DOUBLE_R_TLV("Mono Line2 Bypass Playback Volume",
318 LINE2L_2_MONOLOPM_VOL, LINE2R_2_MONOLOPM_VOL,
319 0, 118, 1, output_stage_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100320
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200321 SOC_DOUBLE_R_TLV("HP DAC Playback Volume",
322 DACL1_2_HPLOUT_VOL, DACR1_2_HPROUT_VOL,
323 0, 118, 1, output_stage_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100324 SOC_DOUBLE_R("HP DAC Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3,
325 0x01, 0),
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200326 SOC_DOUBLE_R_TLV("HP Right PGA Bypass Playback Volume",
327 PGAR_2_HPLOUT_VOL, PGAR_2_HPROUT_VOL,
328 0, 118, 1, output_stage_tlv),
329 SOC_SINGLE_TLV("HPL PGA Bypass Playback Volume",
330 PGAL_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
331 SOC_SINGLE_TLV("HPR PGA Bypass Playback Volume",
332 PGAL_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
333 SOC_DOUBLE_R_TLV("HP Line2 Bypass Playback Volume",
334 LINE2L_2_HPLOUT_VOL, LINE2R_2_HPROUT_VOL,
335 0, 118, 1, output_stage_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100336
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200337 SOC_DOUBLE_R_TLV("HPCOM DAC Playback Volume",
338 DACL1_2_HPLCOM_VOL, DACR1_2_HPRCOM_VOL,
339 0, 118, 1, output_stage_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100340 SOC_DOUBLE_R("HPCOM DAC Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3,
341 0x01, 0),
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200342 SOC_SINGLE_TLV("HPLCOM PGA Bypass Playback Volume",
343 PGAL_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
344 SOC_SINGLE_TLV("HPRCOM PGA Bypass Playback Volume",
345 PGAL_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
346 SOC_DOUBLE_R_TLV("HPCOM Line2 Bypass Playback Volume",
347 LINE2L_2_HPLCOM_VOL, LINE2R_2_HPRCOM_VOL,
348 0, 118, 1, output_stage_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100349
350 /*
351 * Note: enable Automatic input Gain Controller with care. It can
352 * adjust PGA to max value when ADC is on and will never go back.
353 */
354 SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0),
355
356 /* Input */
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200357 SOC_DOUBLE_R_TLV("PGA Capture Volume", LADC_VOL, RADC_VOL,
358 0, 119, 0, adc_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100359 SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1),
Jarkko Nikula4d20f702008-06-27 14:07:57 +0300360
361 SOC_ENUM("ADC HPF Cut-off", aic3x_enum[ADC_HPF_ENUM]),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100362};
363
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100364/* Left DAC Mux */
365static const struct snd_kcontrol_new aic3x_left_dac_mux_controls =
366SOC_DAPM_ENUM("Route", aic3x_enum[LDAC_ENUM]);
367
368/* Right DAC Mux */
369static const struct snd_kcontrol_new aic3x_right_dac_mux_controls =
370SOC_DAPM_ENUM("Route", aic3x_enum[RDAC_ENUM]);
371
372/* Left HPCOM Mux */
373static const struct snd_kcontrol_new aic3x_left_hpcom_mux_controls =
374SOC_DAPM_ENUM("Route", aic3x_enum[LHPCOM_ENUM]);
375
376/* Right HPCOM Mux */
377static const struct snd_kcontrol_new aic3x_right_hpcom_mux_controls =
378SOC_DAPM_ENUM("Route", aic3x_enum[RHPCOM_ENUM]);
379
380/* Left DAC_L1 Mixer */
381static const struct snd_kcontrol_new aic3x_left_dac_mixer_controls[] = {
Daniel Mack54f01912008-11-26 17:47:36 +0100382 SOC_DAPM_SINGLE("LineL Switch", DACL1_2_LLOPM_VOL, 7, 1, 0),
383 SOC_DAPM_SINGLE("LineR Switch", DACL1_2_RLOPM_VOL, 7, 1, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100384 SOC_DAPM_SINGLE("Mono Switch", DACL1_2_MONOLOPM_VOL, 7, 1, 0),
385 SOC_DAPM_SINGLE("HP Switch", DACL1_2_HPLOUT_VOL, 7, 1, 0),
386 SOC_DAPM_SINGLE("HPCOM Switch", DACL1_2_HPLCOM_VOL, 7, 1, 0),
387};
388
389/* Right DAC_R1 Mixer */
390static const struct snd_kcontrol_new aic3x_right_dac_mixer_controls[] = {
Daniel Mack54f01912008-11-26 17:47:36 +0100391 SOC_DAPM_SINGLE("LineL Switch", DACR1_2_LLOPM_VOL, 7, 1, 0),
392 SOC_DAPM_SINGLE("LineR Switch", DACR1_2_RLOPM_VOL, 7, 1, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100393 SOC_DAPM_SINGLE("Mono Switch", DACR1_2_MONOLOPM_VOL, 7, 1, 0),
394 SOC_DAPM_SINGLE("HP Switch", DACR1_2_HPROUT_VOL, 7, 1, 0),
395 SOC_DAPM_SINGLE("HPCOM Switch", DACR1_2_HPRCOM_VOL, 7, 1, 0),
396};
397
398/* Left PGA Mixer */
399static const struct snd_kcontrol_new aic3x_left_pga_mixer_controls[] = {
400 SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1),
Daniel Mack54f01912008-11-26 17:47:36 +0100401 SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_LADC_CTRL, 3, 1, 1),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100402 SOC_DAPM_SINGLE_AIC3X("Line2L Switch", LINE2L_2_LADC_CTRL, 3, 1, 1),
403 SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1),
Daniel Mack54f01912008-11-26 17:47:36 +0100404 SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_LADC_CTRL, 0, 1, 1),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100405};
406
407/* Right PGA Mixer */
408static const struct snd_kcontrol_new aic3x_right_pga_mixer_controls[] = {
409 SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1),
Daniel Mack54f01912008-11-26 17:47:36 +0100410 SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_RADC_CTRL, 3, 1, 1),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100411 SOC_DAPM_SINGLE_AIC3X("Line2R Switch", LINE2R_2_RADC_CTRL, 3, 1, 1),
Daniel Mack54f01912008-11-26 17:47:36 +0100412 SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_RADC_CTRL, 4, 1, 1),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100413 SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1),
414};
415
416/* Left Line1 Mux */
417static const struct snd_kcontrol_new aic3x_left_line1_mux_controls =
418SOC_DAPM_ENUM("Route", aic3x_enum[LINE1L_ENUM]);
419
420/* Right Line1 Mux */
421static const struct snd_kcontrol_new aic3x_right_line1_mux_controls =
422SOC_DAPM_ENUM("Route", aic3x_enum[LINE1R_ENUM]);
423
424/* Left Line2 Mux */
425static const struct snd_kcontrol_new aic3x_left_line2_mux_controls =
426SOC_DAPM_ENUM("Route", aic3x_enum[LINE2L_ENUM]);
427
428/* Right Line2 Mux */
429static const struct snd_kcontrol_new aic3x_right_line2_mux_controls =
430SOC_DAPM_ENUM("Route", aic3x_enum[LINE2R_ENUM]);
431
432/* Left PGA Bypass Mixer */
433static const struct snd_kcontrol_new aic3x_left_pga_bp_mixer_controls[] = {
Daniel Mack54f01912008-11-26 17:47:36 +0100434 SOC_DAPM_SINGLE("LineL Switch", PGAL_2_LLOPM_VOL, 7, 1, 0),
435 SOC_DAPM_SINGLE("LineR Switch", PGAL_2_RLOPM_VOL, 7, 1, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100436 SOC_DAPM_SINGLE("Mono Switch", PGAL_2_MONOLOPM_VOL, 7, 1, 0),
Daniel Mack54f01912008-11-26 17:47:36 +0100437 SOC_DAPM_SINGLE("HPL Switch", PGAL_2_HPLOUT_VOL, 7, 1, 0),
438 SOC_DAPM_SINGLE("HPR Switch", PGAL_2_HPROUT_VOL, 7, 1, 0),
439 SOC_DAPM_SINGLE("HPLCOM Switch", PGAL_2_HPLCOM_VOL, 7, 1, 0),
440 SOC_DAPM_SINGLE("HPRCOM Switch", PGAL_2_HPRCOM_VOL, 7, 1, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100441};
442
443/* Right PGA Bypass Mixer */
444static const struct snd_kcontrol_new aic3x_right_pga_bp_mixer_controls[] = {
Daniel Mack54f01912008-11-26 17:47:36 +0100445 SOC_DAPM_SINGLE("LineL Switch", PGAR_2_LLOPM_VOL, 7, 1, 0),
446 SOC_DAPM_SINGLE("LineR Switch", PGAR_2_RLOPM_VOL, 7, 1, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100447 SOC_DAPM_SINGLE("Mono Switch", PGAR_2_MONOLOPM_VOL, 7, 1, 0),
Daniel Mack54f01912008-11-26 17:47:36 +0100448 SOC_DAPM_SINGLE("HPL Switch", PGAR_2_HPLOUT_VOL, 7, 1, 0),
449 SOC_DAPM_SINGLE("HPR Switch", PGAR_2_HPROUT_VOL, 7, 1, 0),
450 SOC_DAPM_SINGLE("HPLCOM Switch", PGAR_2_HPLCOM_VOL, 7, 1, 0),
451 SOC_DAPM_SINGLE("HPRCOM Switch", PGAR_2_HPRCOM_VOL, 7, 1, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100452};
453
454/* Left Line2 Bypass Mixer */
455static const struct snd_kcontrol_new aic3x_left_line2_bp_mixer_controls[] = {
Daniel Mack54f01912008-11-26 17:47:36 +0100456 SOC_DAPM_SINGLE("LineL Switch", LINE2L_2_LLOPM_VOL, 7, 1, 0),
457 SOC_DAPM_SINGLE("LineR Switch", LINE2L_2_RLOPM_VOL, 7, 1, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100458 SOC_DAPM_SINGLE("Mono Switch", LINE2L_2_MONOLOPM_VOL, 7, 1, 0),
459 SOC_DAPM_SINGLE("HP Switch", LINE2L_2_HPLOUT_VOL, 7, 1, 0),
Daniel Mack54f01912008-11-26 17:47:36 +0100460 SOC_DAPM_SINGLE("HPLCOM Switch", LINE2L_2_HPLCOM_VOL, 7, 1, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100461};
462
463/* Right Line2 Bypass Mixer */
464static const struct snd_kcontrol_new aic3x_right_line2_bp_mixer_controls[] = {
Daniel Mack54f01912008-11-26 17:47:36 +0100465 SOC_DAPM_SINGLE("LineL Switch", LINE2R_2_LLOPM_VOL, 7, 1, 0),
466 SOC_DAPM_SINGLE("LineR Switch", LINE2R_2_RLOPM_VOL, 7, 1, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100467 SOC_DAPM_SINGLE("Mono Switch", LINE2R_2_MONOLOPM_VOL, 7, 1, 0),
468 SOC_DAPM_SINGLE("HP Switch", LINE2R_2_HPROUT_VOL, 7, 1, 0),
Daniel Mack54f01912008-11-26 17:47:36 +0100469 SOC_DAPM_SINGLE("HPRCOM Switch", LINE2R_2_HPRCOM_VOL, 7, 1, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100470};
471
472static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
473 /* Left DAC to Left Outputs */
474 SND_SOC_DAPM_DAC("Left DAC", "Left Playback", DAC_PWR, 7, 0),
475 SND_SOC_DAPM_MUX("Left DAC Mux", SND_SOC_NOPM, 0, 0,
476 &aic3x_left_dac_mux_controls),
477 SND_SOC_DAPM_MIXER("Left DAC_L1 Mixer", SND_SOC_NOPM, 0, 0,
478 &aic3x_left_dac_mixer_controls[0],
479 ARRAY_SIZE(aic3x_left_dac_mixer_controls)),
480 SND_SOC_DAPM_MUX("Left HPCOM Mux", SND_SOC_NOPM, 0, 0,
481 &aic3x_left_hpcom_mux_controls),
482 SND_SOC_DAPM_PGA("Left Line Out", LLOPM_CTRL, 0, 0, NULL, 0),
483 SND_SOC_DAPM_PGA("Left HP Out", HPLOUT_CTRL, 0, 0, NULL, 0),
484 SND_SOC_DAPM_PGA("Left HP Com", HPLCOM_CTRL, 0, 0, NULL, 0),
485
486 /* Right DAC to Right Outputs */
487 SND_SOC_DAPM_DAC("Right DAC", "Right Playback", DAC_PWR, 6, 0),
488 SND_SOC_DAPM_MUX("Right DAC Mux", SND_SOC_NOPM, 0, 0,
489 &aic3x_right_dac_mux_controls),
490 SND_SOC_DAPM_MIXER("Right DAC_R1 Mixer", SND_SOC_NOPM, 0, 0,
491 &aic3x_right_dac_mixer_controls[0],
492 ARRAY_SIZE(aic3x_right_dac_mixer_controls)),
493 SND_SOC_DAPM_MUX("Right HPCOM Mux", SND_SOC_NOPM, 0, 0,
494 &aic3x_right_hpcom_mux_controls),
495 SND_SOC_DAPM_PGA("Right Line Out", RLOPM_CTRL, 0, 0, NULL, 0),
496 SND_SOC_DAPM_PGA("Right HP Out", HPROUT_CTRL, 0, 0, NULL, 0),
497 SND_SOC_DAPM_PGA("Right HP Com", HPRCOM_CTRL, 0, 0, NULL, 0),
498
499 /* Mono Output */
500 SND_SOC_DAPM_PGA("Mono Out", MONOLOPM_CTRL, 0, 0, NULL, 0),
501
Daniel Mack54f01912008-11-26 17:47:36 +0100502 /* Inputs to Left ADC */
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100503 SND_SOC_DAPM_ADC("Left ADC", "Left Capture", LINE1L_2_LADC_CTRL, 2, 0),
504 SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0,
505 &aic3x_left_pga_mixer_controls[0],
506 ARRAY_SIZE(aic3x_left_pga_mixer_controls)),
507 SND_SOC_DAPM_MUX("Left Line1L Mux", SND_SOC_NOPM, 0, 0,
508 &aic3x_left_line1_mux_controls),
Daniel Mack54f01912008-11-26 17:47:36 +0100509 SND_SOC_DAPM_MUX("Left Line1R Mux", SND_SOC_NOPM, 0, 0,
510 &aic3x_left_line1_mux_controls),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100511 SND_SOC_DAPM_MUX("Left Line2L Mux", SND_SOC_NOPM, 0, 0,
512 &aic3x_left_line2_mux_controls),
513
Daniel Mack54f01912008-11-26 17:47:36 +0100514 /* Inputs to Right ADC */
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100515 SND_SOC_DAPM_ADC("Right ADC", "Right Capture",
516 LINE1R_2_RADC_CTRL, 2, 0),
517 SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0,
518 &aic3x_right_pga_mixer_controls[0],
519 ARRAY_SIZE(aic3x_right_pga_mixer_controls)),
Daniel Mack54f01912008-11-26 17:47:36 +0100520 SND_SOC_DAPM_MUX("Right Line1L Mux", SND_SOC_NOPM, 0, 0,
521 &aic3x_right_line1_mux_controls),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100522 SND_SOC_DAPM_MUX("Right Line1R Mux", SND_SOC_NOPM, 0, 0,
523 &aic3x_right_line1_mux_controls),
524 SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0,
525 &aic3x_right_line2_mux_controls),
526
Jarkko Nikulaee15ffd2008-06-25 14:58:46 +0300527 /*
528 * Not a real mic bias widget but similar function. This is for dynamic
529 * control of GPIO1 digital mic modulator clock output function when
530 * using digital mic.
531 */
532 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "GPIO1 dmic modclk",
533 AIC3X_GPIO1_REG, 4, 0xf,
534 AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK,
535 AIC3X_GPIO1_FUNC_DISABLED),
536
537 /*
538 * Also similar function like mic bias. Selects digital mic with
539 * configurable oversampling rate instead of ADC converter.
540 */
541 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 128",
542 AIC3X_ASD_INTF_CTRLA, 0, 3, 1, 0),
543 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 64",
544 AIC3X_ASD_INTF_CTRLA, 0, 3, 2, 0),
545 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 32",
546 AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0),
547
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100548 /* Mic Bias */
Jarkko Nikula0bd72a32008-06-25 14:42:08 +0300549 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias 2V",
550 MICBIAS_CTRL, 6, 3, 1, 0),
551 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias 2.5V",
552 MICBIAS_CTRL, 6, 3, 2, 0),
553 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias AVDD",
554 MICBIAS_CTRL, 6, 3, 3, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100555
556 /* Left PGA to Left Output bypass */
557 SND_SOC_DAPM_MIXER("Left PGA Bypass Mixer", SND_SOC_NOPM, 0, 0,
558 &aic3x_left_pga_bp_mixer_controls[0],
559 ARRAY_SIZE(aic3x_left_pga_bp_mixer_controls)),
560
561 /* Right PGA to Right Output bypass */
562 SND_SOC_DAPM_MIXER("Right PGA Bypass Mixer", SND_SOC_NOPM, 0, 0,
563 &aic3x_right_pga_bp_mixer_controls[0],
564 ARRAY_SIZE(aic3x_right_pga_bp_mixer_controls)),
565
566 /* Left Line2 to Left Output bypass */
567 SND_SOC_DAPM_MIXER("Left Line2 Bypass Mixer", SND_SOC_NOPM, 0, 0,
568 &aic3x_left_line2_bp_mixer_controls[0],
569 ARRAY_SIZE(aic3x_left_line2_bp_mixer_controls)),
570
571 /* Right Line2 to Right Output bypass */
572 SND_SOC_DAPM_MIXER("Right Line2 Bypass Mixer", SND_SOC_NOPM, 0, 0,
573 &aic3x_right_line2_bp_mixer_controls[0],
574 ARRAY_SIZE(aic3x_right_line2_bp_mixer_controls)),
575
576 SND_SOC_DAPM_OUTPUT("LLOUT"),
577 SND_SOC_DAPM_OUTPUT("RLOUT"),
578 SND_SOC_DAPM_OUTPUT("MONO_LOUT"),
579 SND_SOC_DAPM_OUTPUT("HPLOUT"),
580 SND_SOC_DAPM_OUTPUT("HPROUT"),
581 SND_SOC_DAPM_OUTPUT("HPLCOM"),
582 SND_SOC_DAPM_OUTPUT("HPRCOM"),
583
584 SND_SOC_DAPM_INPUT("MIC3L"),
585 SND_SOC_DAPM_INPUT("MIC3R"),
586 SND_SOC_DAPM_INPUT("LINE1L"),
587 SND_SOC_DAPM_INPUT("LINE1R"),
588 SND_SOC_DAPM_INPUT("LINE2L"),
589 SND_SOC_DAPM_INPUT("LINE2R"),
590};
591
Mark Brownd0cc0d32008-05-13 14:55:22 +0200592static const struct snd_soc_dapm_route intercon[] = {
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100593 /* Left Output */
594 {"Left DAC Mux", "DAC_L1", "Left DAC"},
595 {"Left DAC Mux", "DAC_L2", "Left DAC"},
596 {"Left DAC Mux", "DAC_L3", "Left DAC"},
597
Daniel Mack54f01912008-11-26 17:47:36 +0100598 {"Left DAC_L1 Mixer", "LineL Switch", "Left DAC Mux"},
599 {"Left DAC_L1 Mixer", "LineR Switch", "Left DAC Mux"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100600 {"Left DAC_L1 Mixer", "Mono Switch", "Left DAC Mux"},
601 {"Left DAC_L1 Mixer", "HP Switch", "Left DAC Mux"},
602 {"Left DAC_L1 Mixer", "HPCOM Switch", "Left DAC Mux"},
603 {"Left Line Out", NULL, "Left DAC Mux"},
604 {"Left HP Out", NULL, "Left DAC Mux"},
605
606 {"Left HPCOM Mux", "differential of HPLOUT", "Left DAC_L1 Mixer"},
607 {"Left HPCOM Mux", "constant VCM", "Left DAC_L1 Mixer"},
608 {"Left HPCOM Mux", "single-ended", "Left DAC_L1 Mixer"},
609
610 {"Left Line Out", NULL, "Left DAC_L1 Mixer"},
611 {"Mono Out", NULL, "Left DAC_L1 Mixer"},
612 {"Left HP Out", NULL, "Left DAC_L1 Mixer"},
613 {"Left HP Com", NULL, "Left HPCOM Mux"},
614
615 {"LLOUT", NULL, "Left Line Out"},
616 {"LLOUT", NULL, "Left Line Out"},
617 {"HPLOUT", NULL, "Left HP Out"},
618 {"HPLCOM", NULL, "Left HP Com"},
619
620 /* Right Output */
621 {"Right DAC Mux", "DAC_R1", "Right DAC"},
622 {"Right DAC Mux", "DAC_R2", "Right DAC"},
623 {"Right DAC Mux", "DAC_R3", "Right DAC"},
624
Daniel Mack54f01912008-11-26 17:47:36 +0100625 {"Right DAC_R1 Mixer", "LineL Switch", "Right DAC Mux"},
626 {"Right DAC_R1 Mixer", "LineR Switch", "Right DAC Mux"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100627 {"Right DAC_R1 Mixer", "Mono Switch", "Right DAC Mux"},
628 {"Right DAC_R1 Mixer", "HP Switch", "Right DAC Mux"},
629 {"Right DAC_R1 Mixer", "HPCOM Switch", "Right DAC Mux"},
630 {"Right Line Out", NULL, "Right DAC Mux"},
631 {"Right HP Out", NULL, "Right DAC Mux"},
632
633 {"Right HPCOM Mux", "differential of HPROUT", "Right DAC_R1 Mixer"},
634 {"Right HPCOM Mux", "constant VCM", "Right DAC_R1 Mixer"},
635 {"Right HPCOM Mux", "single-ended", "Right DAC_R1 Mixer"},
636 {"Right HPCOM Mux", "differential of HPLCOM", "Right DAC_R1 Mixer"},
637 {"Right HPCOM Mux", "external feedback", "Right DAC_R1 Mixer"},
638
639 {"Right Line Out", NULL, "Right DAC_R1 Mixer"},
640 {"Mono Out", NULL, "Right DAC_R1 Mixer"},
641 {"Right HP Out", NULL, "Right DAC_R1 Mixer"},
642 {"Right HP Com", NULL, "Right HPCOM Mux"},
643
644 {"RLOUT", NULL, "Right Line Out"},
645 {"RLOUT", NULL, "Right Line Out"},
646 {"HPROUT", NULL, "Right HP Out"},
647 {"HPRCOM", NULL, "Right HP Com"},
648
649 /* Mono Output */
Jarkko Nikula5b006132008-05-09 15:05:41 +0200650 {"MONO_LOUT", NULL, "Mono Out"},
651 {"MONO_LOUT", NULL, "Mono Out"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100652
653 /* Left Input */
654 {"Left Line1L Mux", "single-ended", "LINE1L"},
655 {"Left Line1L Mux", "differential", "LINE1L"},
656
657 {"Left Line2L Mux", "single-ended", "LINE2L"},
658 {"Left Line2L Mux", "differential", "LINE2L"},
659
660 {"Left PGA Mixer", "Line1L Switch", "Left Line1L Mux"},
Daniel Mack54f01912008-11-26 17:47:36 +0100661 {"Left PGA Mixer", "Line1R Switch", "Left Line1R Mux"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100662 {"Left PGA Mixer", "Line2L Switch", "Left Line2L Mux"},
663 {"Left PGA Mixer", "Mic3L Switch", "MIC3L"},
Daniel Mack54f01912008-11-26 17:47:36 +0100664 {"Left PGA Mixer", "Mic3R Switch", "MIC3R"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100665
666 {"Left ADC", NULL, "Left PGA Mixer"},
Jarkko Nikulaee15ffd2008-06-25 14:58:46 +0300667 {"Left ADC", NULL, "GPIO1 dmic modclk"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100668
669 /* Right Input */
670 {"Right Line1R Mux", "single-ended", "LINE1R"},
671 {"Right Line1R Mux", "differential", "LINE1R"},
672
673 {"Right Line2R Mux", "single-ended", "LINE2R"},
674 {"Right Line2R Mux", "differential", "LINE2R"},
675
Daniel Mack54f01912008-11-26 17:47:36 +0100676 {"Right PGA Mixer", "Line1L Switch", "Right Line1L Mux"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100677 {"Right PGA Mixer", "Line1R Switch", "Right Line1R Mux"},
678 {"Right PGA Mixer", "Line2R Switch", "Right Line2R Mux"},
Daniel Mack54f01912008-11-26 17:47:36 +0100679 {"Right PGA Mixer", "Mic3L Switch", "MIC3L"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100680 {"Right PGA Mixer", "Mic3R Switch", "MIC3R"},
681
682 {"Right ADC", NULL, "Right PGA Mixer"},
Jarkko Nikulaee15ffd2008-06-25 14:58:46 +0300683 {"Right ADC", NULL, "GPIO1 dmic modclk"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100684
685 /* Left PGA Bypass */
Daniel Mack54f01912008-11-26 17:47:36 +0100686 {"Left PGA Bypass Mixer", "LineL Switch", "Left PGA Mixer"},
687 {"Left PGA Bypass Mixer", "LineR Switch", "Left PGA Mixer"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100688 {"Left PGA Bypass Mixer", "Mono Switch", "Left PGA Mixer"},
Daniel Mack54f01912008-11-26 17:47:36 +0100689 {"Left PGA Bypass Mixer", "HPL Switch", "Left PGA Mixer"},
690 {"Left PGA Bypass Mixer", "HPR Switch", "Left PGA Mixer"},
691 {"Left PGA Bypass Mixer", "HPLCOM Switch", "Left PGA Mixer"},
692 {"Left PGA Bypass Mixer", "HPRCOM Switch", "Left PGA Mixer"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100693
694 {"Left HPCOM Mux", "differential of HPLOUT", "Left PGA Bypass Mixer"},
695 {"Left HPCOM Mux", "constant VCM", "Left PGA Bypass Mixer"},
696 {"Left HPCOM Mux", "single-ended", "Left PGA Bypass Mixer"},
697
698 {"Left Line Out", NULL, "Left PGA Bypass Mixer"},
699 {"Mono Out", NULL, "Left PGA Bypass Mixer"},
700 {"Left HP Out", NULL, "Left PGA Bypass Mixer"},
701
702 /* Right PGA Bypass */
Daniel Mack54f01912008-11-26 17:47:36 +0100703 {"Right PGA Bypass Mixer", "LineL Switch", "Right PGA Mixer"},
704 {"Right PGA Bypass Mixer", "LineR Switch", "Right PGA Mixer"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100705 {"Right PGA Bypass Mixer", "Mono Switch", "Right PGA Mixer"},
Daniel Mack54f01912008-11-26 17:47:36 +0100706 {"Right PGA Bypass Mixer", "HPL Switch", "Right PGA Mixer"},
707 {"Right PGA Bypass Mixer", "HPR Switch", "Right PGA Mixer"},
708 {"Right PGA Bypass Mixer", "HPLCOM Switch", "Right PGA Mixer"},
709 {"Right PGA Bypass Mixer", "HPRCOM Switch", "Right PGA Mixer"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100710
711 {"Right HPCOM Mux", "differential of HPROUT", "Right PGA Bypass Mixer"},
712 {"Right HPCOM Mux", "constant VCM", "Right PGA Bypass Mixer"},
713 {"Right HPCOM Mux", "single-ended", "Right PGA Bypass Mixer"},
714 {"Right HPCOM Mux", "differential of HPLCOM", "Right PGA Bypass Mixer"},
715 {"Right HPCOM Mux", "external feedback", "Right PGA Bypass Mixer"},
716
717 {"Right Line Out", NULL, "Right PGA Bypass Mixer"},
718 {"Mono Out", NULL, "Right PGA Bypass Mixer"},
719 {"Right HP Out", NULL, "Right PGA Bypass Mixer"},
720
721 /* Left Line2 Bypass */
Daniel Mack54f01912008-11-26 17:47:36 +0100722 {"Left Line2 Bypass Mixer", "LineL Switch", "Left Line2L Mux"},
723 {"Left Line2 Bypass Mixer", "LineR Switch", "Left Line2L Mux"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100724 {"Left Line2 Bypass Mixer", "Mono Switch", "Left Line2L Mux"},
725 {"Left Line2 Bypass Mixer", "HP Switch", "Left Line2L Mux"},
Daniel Mack54f01912008-11-26 17:47:36 +0100726 {"Left Line2 Bypass Mixer", "HPLCOM Switch", "Left Line2L Mux"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100727
728 {"Left HPCOM Mux", "differential of HPLOUT", "Left Line2 Bypass Mixer"},
729 {"Left HPCOM Mux", "constant VCM", "Left Line2 Bypass Mixer"},
730 {"Left HPCOM Mux", "single-ended", "Left Line2 Bypass Mixer"},
731
732 {"Left Line Out", NULL, "Left Line2 Bypass Mixer"},
733 {"Mono Out", NULL, "Left Line2 Bypass Mixer"},
734 {"Left HP Out", NULL, "Left Line2 Bypass Mixer"},
735
736 /* Right Line2 Bypass */
Daniel Mack54f01912008-11-26 17:47:36 +0100737 {"Right Line2 Bypass Mixer", "LineL Switch", "Right Line2R Mux"},
738 {"Right Line2 Bypass Mixer", "LineR Switch", "Right Line2R Mux"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100739 {"Right Line2 Bypass Mixer", "Mono Switch", "Right Line2R Mux"},
740 {"Right Line2 Bypass Mixer", "HP Switch", "Right Line2R Mux"},
Daniel Mack54f01912008-11-26 17:47:36 +0100741 {"Right Line2 Bypass Mixer", "HPRCOM Switch", "Right Line2R Mux"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100742
743 {"Right HPCOM Mux", "differential of HPROUT", "Right Line2 Bypass Mixer"},
744 {"Right HPCOM Mux", "constant VCM", "Right Line2 Bypass Mixer"},
745 {"Right HPCOM Mux", "single-ended", "Right Line2 Bypass Mixer"},
746 {"Right HPCOM Mux", "differential of HPLCOM", "Right Line2 Bypass Mixer"},
747 {"Right HPCOM Mux", "external feedback", "Right Line2 Bypass Mixer"},
748
749 {"Right Line Out", NULL, "Right Line2 Bypass Mixer"},
750 {"Mono Out", NULL, "Right Line2 Bypass Mixer"},
751 {"Right HP Out", NULL, "Right Line2 Bypass Mixer"},
Jarkko Nikulaee15ffd2008-06-25 14:58:46 +0300752
753 /*
754 * Logical path between digital mic enable and GPIO1 modulator clock
755 * output function
756 */
757 {"GPIO1 dmic modclk", NULL, "DMic Rate 128"},
758 {"GPIO1 dmic modclk", NULL, "DMic Rate 64"},
759 {"GPIO1 dmic modclk", NULL, "DMic Rate 32"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100760};
761
762static int aic3x_add_widgets(struct snd_soc_codec *codec)
763{
Mark Brownd0cc0d32008-05-13 14:55:22 +0200764 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
765 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100766
767 /* set up audio path interconnects */
Mark Brownd0cc0d32008-05-13 14:55:22 +0200768 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100769
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100770 return 0;
771}
772
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100773static int aic3x_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000774 struct snd_pcm_hw_params *params,
775 struct snd_soc_dai *dai)
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100776{
777 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000778 struct snd_soc_codec *codec =rtd->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900779 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200780 int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0;
Peter Meerwald255173b2009-12-14 14:44:56 +0100781 u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1;
782 u16 d, pll_d = 1;
Chaithrika U S06c71282009-07-22 07:45:04 -0400783 u8 reg;
Peter Meerwald255173b2009-12-14 14:44:56 +0100784 int clk;
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100785
786 /* select data word length */
787 data =
788 aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4));
789 switch (params_format(params)) {
790 case SNDRV_PCM_FORMAT_S16_LE:
791 break;
792 case SNDRV_PCM_FORMAT_S20_3LE:
793 data |= (0x01 << 4);
794 break;
795 case SNDRV_PCM_FORMAT_S24_LE:
796 data |= (0x02 << 4);
797 break;
798 case SNDRV_PCM_FORMAT_S32_LE:
799 data |= (0x03 << 4);
800 break;
801 }
802 aic3x_write(codec, AIC3X_ASD_INTF_CTRLB, data);
803
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200804 /* Fsref can be 44100 or 48000 */
805 fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000;
806
807 /* Try to find a value for Q which allows us to bypass the PLL and
808 * generate CODEC_CLK directly. */
809 for (pll_q = 2; pll_q < 18; pll_q++)
810 if (aic3x->sysclk / (128 * pll_q) == fsref) {
811 bypass_pll = 1;
812 break;
813 }
814
815 if (bypass_pll) {
816 pll_q &= 0xf;
817 aic3x_write(codec, AIC3X_PLL_PROGA_REG, pll_q << PLLQ_SHIFT);
818 aic3x_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_CLKDIV);
Chaithrika U S06c71282009-07-22 07:45:04 -0400819 /* disable PLL if it is bypassed */
820 reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG);
821 aic3x_write(codec, AIC3X_PLL_PROGA_REG, reg & ~PLL_ENABLE);
822
823 } else {
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200824 aic3x_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_PLLDIV);
Chaithrika U S06c71282009-07-22 07:45:04 -0400825 /* enable PLL when it is used */
826 reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG);
827 aic3x_write(codec, AIC3X_PLL_PROGA_REG, reg | PLL_ENABLE);
828 }
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200829
830 /* Route Left DAC to left channel input and
831 * right DAC to right channel input */
832 data = (LDAC2LCH | RDAC2RCH);
833 data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000;
834 if (params_rate(params) >= 64000)
835 data |= DUAL_RATE_MODE;
836 aic3x_write(codec, AIC3X_CODEC_DATAPATH_REG, data);
837
838 /* codec sample rate select */
839 data = (fsref * 20) / params_rate(params);
840 if (params_rate(params) < 64000)
841 data /= 2;
842 data /= 5;
843 data -= 2;
844 data |= (data << 4);
845 aic3x_write(codec, AIC3X_SAMPLE_RATE_SEL_REG, data);
846
847 if (bypass_pll)
848 return 0;
849
Peter Meerwald255173b2009-12-14 14:44:56 +0100850 /* Use PLL, compute apropriate setup for j, d, r and p, the closest
851 * one wins the game. Try with d==0 first, next with d!=0.
852 * Constraints for j are according to the datasheet.
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200853 * The sysclk is divided by 1000 to prevent integer overflows.
854 */
Peter Meerwald255173b2009-12-14 14:44:56 +0100855
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200856 codec_clk = (2048 * fsref) / (aic3x->sysclk / 1000);
857
858 for (r = 1; r <= 16; r++)
859 for (p = 1; p <= 8; p++) {
Peter Meerwald255173b2009-12-14 14:44:56 +0100860 for (j = 4; j <= 55; j++) {
861 /* This is actually 1000*((j+(d/10000))*r)/p
862 * The term had to be converted to get
863 * rid of the division by 10000; d = 0 here
864 */
Mark Brown5baf8312010-01-02 13:13:42 +0000865 int tmp_clk = (1000 * j * r) / p;
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200866
Peter Meerwald255173b2009-12-14 14:44:56 +0100867 /* Check whether this values get closer than
868 * the best ones we had before
869 */
Mark Brown5baf8312010-01-02 13:13:42 +0000870 if (abs(codec_clk - tmp_clk) <
Peter Meerwald255173b2009-12-14 14:44:56 +0100871 abs(codec_clk - last_clk)) {
872 pll_j = j; pll_d = 0;
873 pll_r = r; pll_p = p;
Mark Brown5baf8312010-01-02 13:13:42 +0000874 last_clk = tmp_clk;
Peter Meerwald255173b2009-12-14 14:44:56 +0100875 }
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200876
Peter Meerwald255173b2009-12-14 14:44:56 +0100877 /* Early exit for exact matches */
Mark Brown5baf8312010-01-02 13:13:42 +0000878 if (tmp_clk == codec_clk)
Peter Meerwald255173b2009-12-14 14:44:56 +0100879 goto found;
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200880 }
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200881 }
882
Peter Meerwald255173b2009-12-14 14:44:56 +0100883 /* try with d != 0 */
884 for (p = 1; p <= 8; p++) {
885 j = codec_clk * p / 1000;
886
887 if (j < 4 || j > 11)
888 continue;
889
890 /* do not use codec_clk here since we'd loose precision */
891 d = ((2048 * p * fsref) - j * aic3x->sysclk)
892 * 100 / (aic3x->sysclk/100);
893
894 clk = (10000 * j + d) / (10 * p);
895
896 /* check whether this values get closer than the best
897 * ones we had before */
898 if (abs(codec_clk - clk) < abs(codec_clk - last_clk)) {
899 pll_j = j; pll_d = d; pll_r = 1; pll_p = p;
900 last_clk = clk;
901 }
902
903 /* Early exit for exact matches */
904 if (clk == codec_clk)
905 goto found;
906 }
907
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200908 if (last_clk == 0) {
909 printk(KERN_ERR "%s(): unable to setup PLL\n", __func__);
910 return -EINVAL;
911 }
912
Peter Meerwald255173b2009-12-14 14:44:56 +0100913found:
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200914 data = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG);
915 aic3x_write(codec, AIC3X_PLL_PROGA_REG, data | (pll_p << PLLP_SHIFT));
916 aic3x_write(codec, AIC3X_OVRF_STATUS_AND_PLLR_REG, pll_r << PLLR_SHIFT);
917 aic3x_write(codec, AIC3X_PLL_PROGB_REG, pll_j << PLLJ_SHIFT);
918 aic3x_write(codec, AIC3X_PLL_PROGC_REG, (pll_d >> 6) << PLLD_MSB_SHIFT);
919 aic3x_write(codec, AIC3X_PLL_PROGD_REG,
920 (pll_d & 0x3F) << PLLD_LSB_SHIFT);
921
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100922 return 0;
923}
924
Liam Girdwoode550e172008-07-07 16:07:52 +0100925static int aic3x_mute(struct snd_soc_dai *dai, int mute)
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100926{
927 struct snd_soc_codec *codec = dai->codec;
928 u8 ldac_reg = aic3x_read_reg_cache(codec, LDAC_VOL) & ~MUTE_ON;
929 u8 rdac_reg = aic3x_read_reg_cache(codec, RDAC_VOL) & ~MUTE_ON;
930
931 if (mute) {
932 aic3x_write(codec, LDAC_VOL, ldac_reg | MUTE_ON);
933 aic3x_write(codec, RDAC_VOL, rdac_reg | MUTE_ON);
934 } else {
935 aic3x_write(codec, LDAC_VOL, ldac_reg);
936 aic3x_write(codec, RDAC_VOL, rdac_reg);
937 }
938
939 return 0;
940}
941
Liam Girdwoode550e172008-07-07 16:07:52 +0100942static int aic3x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100943 int clk_id, unsigned int freq, int dir)
944{
945 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900946 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100947
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200948 aic3x->sysclk = freq;
949 return 0;
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100950}
951
Liam Girdwoode550e172008-07-07 16:07:52 +0100952static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100953 unsigned int fmt)
954{
955 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900956 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
Jarkko Nikula81971a12008-06-25 14:58:45 +0300957 u8 iface_areg, iface_breg;
Troy Kiskya24f4f62008-12-19 13:05:22 -0700958 int delay = 0;
Jarkko Nikula81971a12008-06-25 14:58:45 +0300959
960 iface_areg = aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLA) & 0x3f;
961 iface_breg = aic3x_read_reg_cache(codec, AIC3X_ASD_INTF_CTRLB) & 0x3f;
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100962
963 /* set master/slave audio interface */
964 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
965 case SND_SOC_DAIFMT_CBM_CFM:
966 aic3x->master = 1;
967 iface_areg |= BIT_CLK_MASTER | WORD_CLK_MASTER;
968 break;
969 case SND_SOC_DAIFMT_CBS_CFS:
970 aic3x->master = 0;
971 break;
972 default:
973 return -EINVAL;
974 }
975
Jarkko Nikula4b7d2832008-10-23 14:27:03 +0300976 /*
977 * match both interface format and signal polarities since they
978 * are fixed
979 */
980 switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK |
981 SND_SOC_DAIFMT_INV_MASK)) {
982 case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF):
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100983 break;
Troy Kiskya24f4f62008-12-19 13:05:22 -0700984 case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF):
985 delay = 1;
Jarkko Nikula4b7d2832008-10-23 14:27:03 +0300986 case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF):
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100987 iface_breg |= (0x01 << 6);
988 break;
Jarkko Nikula4b7d2832008-10-23 14:27:03 +0300989 case (SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_NB_NF):
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100990 iface_breg |= (0x02 << 6);
991 break;
Jarkko Nikula4b7d2832008-10-23 14:27:03 +0300992 case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF):
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100993 iface_breg |= (0x03 << 6);
994 break;
995 default:
996 return -EINVAL;
997 }
998
999 /* set iface */
1000 aic3x_write(codec, AIC3X_ASD_INTF_CTRLA, iface_areg);
1001 aic3x_write(codec, AIC3X_ASD_INTF_CTRLB, iface_breg);
Troy Kiskya24f4f62008-12-19 13:05:22 -07001002 aic3x_write(codec, AIC3X_ASD_INTF_CTRLC, delay);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001003
1004 return 0;
1005}
1006
Mark Brown0be98982008-05-19 12:31:28 +02001007static int aic3x_set_bias_level(struct snd_soc_codec *codec,
1008 enum snd_soc_bias_level level)
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001009{
Mark Brownb2c812e2010-04-14 15:35:19 +09001010 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001011 u8 reg;
1012
Mark Brown0be98982008-05-19 12:31:28 +02001013 switch (level) {
1014 case SND_SOC_BIAS_ON:
Jarkko Nikuladb138022010-04-26 15:49:13 +03001015 break;
1016 case SND_SOC_BIAS_PREPARE:
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001017 if (aic3x->master) {
1018 /* enable pll */
1019 reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG);
1020 aic3x_write(codec, AIC3X_PLL_PROGA_REG,
1021 reg | PLL_ENABLE);
1022 }
1023 break;
Mark Brown0be98982008-05-19 12:31:28 +02001024 case SND_SOC_BIAS_STANDBY:
Jarkko Nikuladb138022010-04-26 15:49:13 +03001025 /* fall through and disable pll */
Mark Brown0be98982008-05-19 12:31:28 +02001026 case SND_SOC_BIAS_OFF:
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001027 if (aic3x->master) {
1028 /* disable pll */
1029 reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG);
1030 aic3x_write(codec, AIC3X_PLL_PROGA_REG,
1031 reg & ~PLL_ENABLE);
1032 }
1033 break;
1034 }
Mark Brown0be98982008-05-19 12:31:28 +02001035 codec->bias_level = level;
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001036
1037 return 0;
1038}
1039
Daniel Mack54e7e612008-04-30 16:20:52 +02001040void aic3x_set_gpio(struct snd_soc_codec *codec, int gpio, int state)
1041{
1042 u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG;
1043 u8 bit = gpio ? 3: 0;
1044 u8 val = aic3x_read_reg_cache(codec, reg) & ~(1 << bit);
1045 aic3x_write(codec, reg, val | (!!state << bit));
1046}
1047EXPORT_SYMBOL_GPL(aic3x_set_gpio);
1048
1049int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio)
1050{
1051 u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG;
1052 u8 val, bit = gpio ? 2: 1;
1053
1054 aic3x_read(codec, reg, &val);
1055 return (val >> bit) & 1;
1056}
1057EXPORT_SYMBOL_GPL(aic3x_get_gpio);
1058
Daniel Mack6f2a9742008-12-03 11:44:17 +01001059void aic3x_set_headset_detection(struct snd_soc_codec *codec, int detect,
1060 int headset_debounce, int button_debounce)
1061{
1062 u8 val;
1063
1064 val = ((detect & AIC3X_HEADSET_DETECT_MASK)
1065 << AIC3X_HEADSET_DETECT_SHIFT) |
1066 ((headset_debounce & AIC3X_HEADSET_DEBOUNCE_MASK)
1067 << AIC3X_HEADSET_DEBOUNCE_SHIFT) |
1068 ((button_debounce & AIC3X_BUTTON_DEBOUNCE_MASK)
1069 << AIC3X_BUTTON_DEBOUNCE_SHIFT);
1070
1071 if (detect & AIC3X_HEADSET_DETECT_MASK)
1072 val |= AIC3X_HEADSET_DETECT_ENABLED;
1073
1074 aic3x_write(codec, AIC3X_HEADSET_DETECT_CTRL_A, val);
1075}
1076EXPORT_SYMBOL_GPL(aic3x_set_headset_detection);
1077
Daniel Mack54e7e612008-04-30 16:20:52 +02001078int aic3x_headset_detected(struct snd_soc_codec *codec)
1079{
1080 u8 val;
Daniel Mack6f2a9742008-12-03 11:44:17 +01001081 aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val);
1082 return (val >> 4) & 1;
Daniel Mack54e7e612008-04-30 16:20:52 +02001083}
1084EXPORT_SYMBOL_GPL(aic3x_headset_detected);
1085
Daniel Mack6f2a9742008-12-03 11:44:17 +01001086int aic3x_button_pressed(struct snd_soc_codec *codec)
1087{
1088 u8 val;
1089 aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val);
1090 return (val >> 5) & 1;
1091}
1092EXPORT_SYMBOL_GPL(aic3x_button_pressed);
1093
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001094#define AIC3X_RATES SNDRV_PCM_RATE_8000_96000
1095#define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1096 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
1097
Eric Miao6335d052009-03-03 09:41:00 +08001098static struct snd_soc_dai_ops aic3x_dai_ops = {
1099 .hw_params = aic3x_hw_params,
1100 .digital_mute = aic3x_mute,
1101 .set_sysclk = aic3x_set_dai_sysclk,
1102 .set_fmt = aic3x_set_dai_fmt,
1103};
1104
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001105static struct snd_soc_dai_driver aic3x_dai = {
1106 .name = "tlv320aic3x-hifi",
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001107 .playback = {
1108 .stream_name = "Playback",
1109 .channels_min = 1,
1110 .channels_max = 2,
1111 .rates = AIC3X_RATES,
1112 .formats = AIC3X_FORMATS,},
1113 .capture = {
1114 .stream_name = "Capture",
1115 .channels_min = 1,
1116 .channels_max = 2,
1117 .rates = AIC3X_RATES,
1118 .formats = AIC3X_FORMATS,},
Eric Miao6335d052009-03-03 09:41:00 +08001119 .ops = &aic3x_dai_ops,
Randolph Chung14017612010-08-19 12:06:17 +01001120 .symmetric_rates = 1,
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001121};
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001122
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001123static int aic3x_suspend(struct snd_soc_codec *codec, pm_message_t state)
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001124{
Mark Brown0be98982008-05-19 12:31:28 +02001125 aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001126
1127 return 0;
1128}
1129
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001130static int aic3x_resume(struct snd_soc_codec *codec)
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001131{
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001132 int i;
1133 u8 data[2];
1134 u8 *cache = codec->reg_cache;
1135
1136 /* Sync reg_cache with the hardware */
1137 for (i = 0; i < ARRAY_SIZE(aic3x_reg); i++) {
1138 data[0] = i;
1139 data[1] = cache[i];
1140 codec->hw_write(codec->control_data, data, 2);
1141 }
1142
Mark Brown29e189c2010-05-07 20:30:00 +01001143 aic3x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001144
1145 return 0;
1146}
1147
1148/*
1149 * initialise the AIC3X driver
1150 * register the mixer and dsp interfaces with the kernel
1151 */
Ben Dookscb3826f2009-08-20 22:50:41 +01001152static int aic3x_init(struct snd_soc_codec *codec)
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001153{
Ben Dookscb3826f2009-08-20 22:50:41 +01001154 int reg;
1155
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001156 aic3x_write(codec, AIC3X_PAGE_SELECT, PAGE0_SELECT);
1157 aic3x_write(codec, AIC3X_RESET, SOFT_RESET);
1158
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001159 /* DAC default volume and mute */
1160 aic3x_write(codec, LDAC_VOL, DEFAULT_VOL | MUTE_ON);
1161 aic3x_write(codec, RDAC_VOL, DEFAULT_VOL | MUTE_ON);
1162
1163 /* DAC to HP default volume and route to Output mixer */
1164 aic3x_write(codec, DACL1_2_HPLOUT_VOL, DEFAULT_VOL | ROUTE_ON);
1165 aic3x_write(codec, DACR1_2_HPROUT_VOL, DEFAULT_VOL | ROUTE_ON);
1166 aic3x_write(codec, DACL1_2_HPLCOM_VOL, DEFAULT_VOL | ROUTE_ON);
1167 aic3x_write(codec, DACR1_2_HPRCOM_VOL, DEFAULT_VOL | ROUTE_ON);
1168 /* DAC to Line Out default volume and route to Output mixer */
1169 aic3x_write(codec, DACL1_2_LLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1170 aic3x_write(codec, DACR1_2_RLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1171 /* DAC to Mono Line Out default volume and route to Output mixer */
1172 aic3x_write(codec, DACL1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1173 aic3x_write(codec, DACR1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1174
1175 /* unmute all outputs */
1176 reg = aic3x_read_reg_cache(codec, LLOPM_CTRL);
1177 aic3x_write(codec, LLOPM_CTRL, reg | UNMUTE);
1178 reg = aic3x_read_reg_cache(codec, RLOPM_CTRL);
1179 aic3x_write(codec, RLOPM_CTRL, reg | UNMUTE);
1180 reg = aic3x_read_reg_cache(codec, MONOLOPM_CTRL);
1181 aic3x_write(codec, MONOLOPM_CTRL, reg | UNMUTE);
1182 reg = aic3x_read_reg_cache(codec, HPLOUT_CTRL);
1183 aic3x_write(codec, HPLOUT_CTRL, reg | UNMUTE);
1184 reg = aic3x_read_reg_cache(codec, HPROUT_CTRL);
1185 aic3x_write(codec, HPROUT_CTRL, reg | UNMUTE);
1186 reg = aic3x_read_reg_cache(codec, HPLCOM_CTRL);
1187 aic3x_write(codec, HPLCOM_CTRL, reg | UNMUTE);
1188 reg = aic3x_read_reg_cache(codec, HPRCOM_CTRL);
1189 aic3x_write(codec, HPRCOM_CTRL, reg | UNMUTE);
1190
1191 /* ADC default volume and unmute */
1192 aic3x_write(codec, LADC_VOL, DEFAULT_GAIN);
1193 aic3x_write(codec, RADC_VOL, DEFAULT_GAIN);
1194 /* By default route Line1 to ADC PGA mixer */
1195 aic3x_write(codec, LINE1L_2_LADC_CTRL, 0x0);
1196 aic3x_write(codec, LINE1R_2_RADC_CTRL, 0x0);
1197
1198 /* PGA to HP Bypass default volume, disconnect from Output Mixer */
1199 aic3x_write(codec, PGAL_2_HPLOUT_VOL, DEFAULT_VOL);
1200 aic3x_write(codec, PGAR_2_HPROUT_VOL, DEFAULT_VOL);
1201 aic3x_write(codec, PGAL_2_HPLCOM_VOL, DEFAULT_VOL);
1202 aic3x_write(codec, PGAR_2_HPRCOM_VOL, DEFAULT_VOL);
1203 /* PGA to Line Out default volume, disconnect from Output Mixer */
1204 aic3x_write(codec, PGAL_2_LLOPM_VOL, DEFAULT_VOL);
1205 aic3x_write(codec, PGAR_2_RLOPM_VOL, DEFAULT_VOL);
1206 /* PGA to Mono Line Out default volume, disconnect from Output Mixer */
1207 aic3x_write(codec, PGAL_2_MONOLOPM_VOL, DEFAULT_VOL);
1208 aic3x_write(codec, PGAR_2_MONOLOPM_VOL, DEFAULT_VOL);
1209
1210 /* Line2 to HP Bypass default volume, disconnect from Output Mixer */
1211 aic3x_write(codec, LINE2L_2_HPLOUT_VOL, DEFAULT_VOL);
1212 aic3x_write(codec, LINE2R_2_HPROUT_VOL, DEFAULT_VOL);
1213 aic3x_write(codec, LINE2L_2_HPLCOM_VOL, DEFAULT_VOL);
1214 aic3x_write(codec, LINE2R_2_HPRCOM_VOL, DEFAULT_VOL);
1215 /* Line2 Line Out default volume, disconnect from Output Mixer */
1216 aic3x_write(codec, LINE2L_2_LLOPM_VOL, DEFAULT_VOL);
1217 aic3x_write(codec, LINE2R_2_RLOPM_VOL, DEFAULT_VOL);
1218 /* Line2 to Mono Out default volume, disconnect from Output Mixer */
1219 aic3x_write(codec, LINE2L_2_MONOLOPM_VOL, DEFAULT_VOL);
1220 aic3x_write(codec, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL);
1221
1222 /* off, with power on */
Mark Brown0be98982008-05-19 12:31:28 +02001223 aic3x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001224
Ben Dookscb3826f2009-08-20 22:50:41 +01001225 return 0;
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001226}
1227
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001228static int aic3x_probe(struct snd_soc_codec *codec)
Ben Dookscb3826f2009-08-20 22:50:41 +01001229{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001230 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
Ben Dookscb3826f2009-08-20 22:50:41 +01001231
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001232 codec->hw_write = (hw_write_t) i2c_master_send;
1233 codec->control_data = aic3x->control_data;
1234
1235 if (aic3x->setup) {
1236 /* setup GPIO functions */
1237 aic3x_write(codec, AIC3X_GPIO1_REG,
1238 (aic3x->setup->gpio_func[0] & 0xf) << 4);
1239 aic3x_write(codec, AIC3X_GPIO2_REG,
1240 (aic3x->setup->gpio_func[1] & 0xf) << 4);
Ben Dookscb3826f2009-08-20 22:50:41 +01001241 }
1242
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001243 aic3x_init(codec);
Ben Dookscb3826f2009-08-20 22:50:41 +01001244
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001245 snd_soc_add_controls(codec, aic3x_snd_controls,
1246 ARRAY_SIZE(aic3x_snd_controls));
Ben Dookscb3826f2009-08-20 22:50:41 +01001247
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001248 aic3x_add_widgets(codec);
Ben Dookscb3826f2009-08-20 22:50:41 +01001249
1250 return 0;
1251}
1252
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001253static int aic3x_remove(struct snd_soc_codec *codec)
Ben Dookscb3826f2009-08-20 22:50:41 +01001254{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001255 aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
Ben Dookscb3826f2009-08-20 22:50:41 +01001256 return 0;
1257}
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001258
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001259static struct snd_soc_codec_driver soc_codec_dev_aic3x = {
1260 .read = aic3x_read_reg_cache,
1261 .write = aic3x_write,
1262 .set_bias_level = aic3x_set_bias_level,
1263 .reg_cache_size = ARRAY_SIZE(aic3x_reg),
1264 .reg_word_size = sizeof(u8),
1265 .reg_cache_default = aic3x_reg,
1266 .probe = aic3x_probe,
1267 .remove = aic3x_remove,
1268 .suspend = aic3x_suspend,
1269 .resume = aic3x_resume,
1270};
1271
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001272#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1273/*
1274 * AIC3X 2 wire address can be up to 4 devices with device addresses
1275 * 0x18, 0x19, 0x1A, 0x1B
1276 */
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001277
1278/*
1279 * If the i2c layer weren't so broken, we could pass this kind of data
1280 * around
1281 */
Jean Delvareba8ed122008-09-22 14:15:53 +02001282static int aic3x_i2c_probe(struct i2c_client *i2c,
1283 const struct i2c_device_id *id)
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001284{
Jarkko Nikula5193d622010-05-05 13:02:03 +03001285 struct aic3x_pdata *pdata = i2c->dev.platform_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001286 struct aic3x_setup_data *setup = pdata->setup;
1287 struct aic3x_priv *aic3x;
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001288 int ret, i;
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001289
Ben Dookscb3826f2009-08-20 22:50:41 +01001290 aic3x = kzalloc(sizeof(struct aic3x_priv), GFP_KERNEL);
1291 if (aic3x == NULL) {
1292 dev_err(&i2c->dev, "failed to create private data\n");
1293 return -ENOMEM;
1294 }
1295
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001296 aic3x->control_data = i2c;
1297 aic3x->setup = setup;
Ben Dookscb3826f2009-08-20 22:50:41 +01001298 i2c_set_clientdata(i2c, aic3x);
1299
Jarkko Nikula5193d622010-05-05 13:02:03 +03001300 aic3x->gpio_reset = -1;
1301 if (pdata && pdata->gpio_reset >= 0) {
1302 ret = gpio_request(pdata->gpio_reset, "tlv320aic3x reset");
1303 if (ret != 0)
1304 goto err_gpio;
1305 aic3x->gpio_reset = pdata->gpio_reset;
1306 gpio_direction_output(aic3x->gpio_reset, 0);
1307 }
1308
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001309 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++)
1310 aic3x->supplies[i].supply = aic3x_supply_names[i];
1311
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001312 ret = regulator_bulk_get(&i2c->dev, ARRAY_SIZE(aic3x->supplies),
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001313 aic3x->supplies);
1314 if (ret != 0) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001315 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001316 goto err_get;
1317 }
1318
1319 ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies),
1320 aic3x->supplies);
1321 if (ret != 0) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001322 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret);
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001323 goto err_enable;
1324 }
1325
Jarkko Nikula5193d622010-05-05 13:02:03 +03001326 if (aic3x->gpio_reset >= 0) {
1327 udelay(1);
1328 gpio_set_value(aic3x->gpio_reset, 1);
1329 }
1330
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001331 ret = snd_soc_register_codec(&i2c->dev,
1332 &soc_codec_dev_aic3x, &aic3x_dai, 1);
1333 if (ret < 0)
1334 goto err_enable;
1335 return ret;
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001336
1337err_enable:
1338 regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
1339err_get:
Jarkko Nikula5193d622010-05-05 13:02:03 +03001340 if (aic3x->gpio_reset >= 0)
1341 gpio_free(aic3x->gpio_reset);
1342err_gpio:
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001343 kfree(aic3x);
1344 return ret;
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001345}
1346
Jean Delvareba8ed122008-09-22 14:15:53 +02001347static int aic3x_i2c_remove(struct i2c_client *client)
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001348{
Ben Dookscb3826f2009-08-20 22:50:41 +01001349 struct aic3x_priv *aic3x = i2c_get_clientdata(client);
1350
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001351 if (aic3x->gpio_reset >= 0) {
1352 gpio_set_value(aic3x->gpio_reset, 0);
1353 gpio_free(aic3x->gpio_reset);
1354 }
1355 regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
1356 regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
1357
1358 snd_soc_unregister_codec(&client->dev);
1359 kfree(i2c_get_clientdata(client));
1360 return 0;
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001361}
1362
Jean Delvareba8ed122008-09-22 14:15:53 +02001363static const struct i2c_device_id aic3x_i2c_id[] = {
1364 { "tlv320aic3x", 0 },
Ben Dookscb3826f2009-08-20 22:50:41 +01001365 { "tlv320aic33", 0 },
Jean Delvareba8ed122008-09-22 14:15:53 +02001366 { }
1367};
1368MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001369
1370/* machine i2c codec control layer */
1371static struct i2c_driver aic3x_i2c_driver = {
1372 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001373 .name = "tlv320aic3x-codec",
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001374 .owner = THIS_MODULE,
1375 },
Ben Dookscb3826f2009-08-20 22:50:41 +01001376 .probe = aic3x_i2c_probe,
Jean Delvareba8ed122008-09-22 14:15:53 +02001377 .remove = aic3x_i2c_remove,
1378 .id_table = aic3x_i2c_id,
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001379};
Daniel Mack54e7e612008-04-30 16:20:52 +02001380
Ben Dookscb3826f2009-08-20 22:50:41 +01001381static inline void aic3x_i2c_init(void)
Jean Delvareba8ed122008-09-22 14:15:53 +02001382{
Jean Delvareba8ed122008-09-22 14:15:53 +02001383 int ret;
1384
1385 ret = i2c_add_driver(&aic3x_i2c_driver);
Ben Dookscb3826f2009-08-20 22:50:41 +01001386 if (ret)
1387 printk(KERN_ERR "%s: error regsitering i2c driver, %d\n",
1388 __func__, ret);
Jean Delvareba8ed122008-09-22 14:15:53 +02001389}
Ben Dookscb3826f2009-08-20 22:50:41 +01001390
1391static inline void aic3x_i2c_exit(void)
1392{
1393 i2c_del_driver(&aic3x_i2c_driver);
1394}
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001395#endif
1396
Takashi Iwaic9b3a402008-12-10 07:47:22 +01001397static int __init aic3x_modinit(void)
Mark Brown64089b82008-12-08 19:17:58 +00001398{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001399 int ret = 0;
1400#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1401 ret = i2c_add_driver(&aic3x_i2c_driver);
1402 if (ret != 0) {
1403 printk(KERN_ERR "Failed to register TLV320AIC3x I2C driver: %d\n",
1404 ret);
1405 }
1406#endif
1407 return ret;
Mark Brown64089b82008-12-08 19:17:58 +00001408}
1409module_init(aic3x_modinit);
1410
1411static void __exit aic3x_exit(void)
1412{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001413#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1414 i2c_del_driver(&aic3x_i2c_driver);
1415#endif
Mark Brown64089b82008-12-08 19:17:58 +00001416}
1417module_exit(aic3x_exit);
1418
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001419MODULE_DESCRIPTION("ASoC TLV320AIC3X codec driver");
1420MODULE_AUTHOR("Vladimir Barinov");
1421MODULE_LICENSE("GPL");