blob: 86e5a5868c3cf59b9c63042647a4f62bf594aa26 [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
Randolph Chung6184f102010-08-20 12:47:53 +080015 * codecs aic31, aic32, aic33, aic3007.
Vladimir Barinov44d0a872007-11-14 17:07:17 +010016 *
17 * It supports full aic33 codec functionality.
Randolph Chung6184f102010-08-20 12:47:53 +080018 * The compatibility with aic32, aic31 and aic3007 is as follows:
19 * aic32/aic3007 | aic31
Vladimir Barinov44d0a872007-11-14 17:07:17 +010020 * ---------------------------------------
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;
Randolph Chung6184f102010-08-20 12:47:53 +080073#define AIC3X_MODEL_3X 0
74#define AIC3X_MODEL_33 1
75#define AIC3X_MODEL_3007 2
76 u16 model;
Vladimir Barinov44d0a872007-11-14 17:07:17 +010077};
78
79/*
80 * AIC3X register cache
81 * We can't read the AIC3X register space when we are
82 * using 2 wire for device control, so we cache them instead.
83 * There is no point in caching the reset register
84 */
85static const u8 aic3x_reg[AIC3X_CACHEREGNUM] = {
86 0x00, 0x00, 0x00, 0x10, /* 0 */
87 0x04, 0x00, 0x00, 0x00, /* 4 */
88 0x00, 0x00, 0x00, 0x01, /* 8 */
89 0x00, 0x00, 0x00, 0x80, /* 12 */
90 0x80, 0xff, 0xff, 0x78, /* 16 */
91 0x78, 0x78, 0x78, 0x78, /* 20 */
92 0x78, 0x00, 0x00, 0xfe, /* 24 */
93 0x00, 0x00, 0xfe, 0x00, /* 28 */
94 0x18, 0x18, 0x00, 0x00, /* 32 */
95 0x00, 0x00, 0x00, 0x00, /* 36 */
96 0x00, 0x00, 0x00, 0x80, /* 40 */
97 0x80, 0x00, 0x00, 0x00, /* 44 */
98 0x00, 0x00, 0x00, 0x04, /* 48 */
99 0x00, 0x00, 0x00, 0x00, /* 52 */
100 0x00, 0x00, 0x04, 0x00, /* 56 */
101 0x00, 0x00, 0x00, 0x00, /* 60 */
102 0x00, 0x04, 0x00, 0x00, /* 64 */
103 0x00, 0x00, 0x00, 0x00, /* 68 */
104 0x04, 0x00, 0x00, 0x00, /* 72 */
105 0x00, 0x00, 0x00, 0x00, /* 76 */
106 0x00, 0x00, 0x00, 0x00, /* 80 */
107 0x00, 0x00, 0x00, 0x00, /* 84 */
108 0x00, 0x00, 0x00, 0x00, /* 88 */
109 0x00, 0x00, 0x00, 0x00, /* 92 */
110 0x00, 0x00, 0x00, 0x00, /* 96 */
111 0x00, 0x00, 0x02, /* 100 */
112};
113
114/*
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100115 * write aic3x register cache
116 */
117static inline void aic3x_write_reg_cache(struct snd_soc_codec *codec,
118 u8 reg, u8 value)
119{
120 u8 *cache = codec->reg_cache;
121 if (reg >= AIC3X_CACHEREGNUM)
122 return;
123 cache[reg] = value;
124}
125
126/*
Daniel Mack54e7e612008-04-30 16:20:52 +0200127 * read from the aic3x register space
128 */
129static int aic3x_read(struct snd_soc_codec *codec, unsigned int reg,
130 u8 *value)
131{
132 *value = reg & 0xff;
Mark Brown5f345342009-07-05 17:35:28 +0100133
134 value[0] = i2c_smbus_read_byte_data(codec->control_data, value[0]);
Daniel Mack54e7e612008-04-30 16:20:52 +0200135
136 aic3x_write_reg_cache(codec, reg, *value);
137 return 0;
138}
139
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100140#define SOC_DAPM_SINGLE_AIC3X(xname, reg, shift, mask, invert) \
141{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
142 .info = snd_soc_info_volsw, \
143 .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw_aic3x, \
144 .private_value = SOC_SINGLE_VALUE(reg, shift, mask, invert) }
145
146/*
147 * All input lines are connected when !0xf and disconnected with 0xf bit field,
148 * so we have to use specific dapm_put call for input mixer
149 */
150static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,
151 struct snd_ctl_elem_value *ucontrol)
152{
153 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
Eero Nurkkala4453dba2009-02-06 12:01:04 +0200154 struct soc_mixer_control *mc =
155 (struct soc_mixer_control *)kcontrol->private_value;
156 unsigned int reg = mc->reg;
157 unsigned int shift = mc->shift;
158 int max = mc->max;
159 unsigned int mask = (1 << fls(max)) - 1;
160 unsigned int invert = mc->invert;
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100161 unsigned short val, val_mask;
162 int ret;
163 struct snd_soc_dapm_path *path;
164 int found = 0;
165
166 val = (ucontrol->value.integer.value[0] & mask);
167
168 mask = 0xf;
169 if (val)
170 val = mask;
171
172 if (invert)
173 val = mask - val;
174 val_mask = mask << shift;
175 val = val << shift;
176
177 mutex_lock(&widget->codec->mutex);
178
179 if (snd_soc_test_bits(widget->codec, reg, val_mask, val)) {
180 /* find dapm widget path assoc with kcontrol */
181 list_for_each_entry(path, &widget->codec->dapm_paths, list) {
182 if (path->kcontrol != kcontrol)
183 continue;
184
185 /* found, now check type */
186 found = 1;
187 if (val)
188 /* new connection */
189 path->connect = invert ? 0 : 1;
190 else
191 /* old connection must be powered down */
192 path->connect = invert ? 1 : 0;
193 break;
194 }
195
196 if (found)
Liam Girdwooda5302182008-07-07 13:35:17 +0100197 snd_soc_dapm_sync(widget->codec);
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100198 }
199
200 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
201
202 mutex_unlock(&widget->codec->mutex);
203 return ret;
204}
205
206static const char *aic3x_left_dac_mux[] = { "DAC_L1", "DAC_L3", "DAC_L2" };
207static const char *aic3x_right_dac_mux[] = { "DAC_R1", "DAC_R3", "DAC_R2" };
208static const char *aic3x_left_hpcom_mux[] =
209 { "differential of HPLOUT", "constant VCM", "single-ended" };
210static const char *aic3x_right_hpcom_mux[] =
211 { "differential of HPROUT", "constant VCM", "single-ended",
212 "differential of HPLCOM", "external feedback" };
213static const char *aic3x_linein_mode_mux[] = { "single-ended", "differential" };
Jarkko Nikula4d20f702008-06-27 14:07:57 +0300214static const char *aic3x_adc_hpf[] =
215 { "Disabled", "0.0045xFs", "0.0125xFs", "0.025xFs" };
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100216
217#define LDAC_ENUM 0
218#define RDAC_ENUM 1
219#define LHPCOM_ENUM 2
220#define RHPCOM_ENUM 3
221#define LINE1L_ENUM 4
222#define LINE1R_ENUM 5
223#define LINE2L_ENUM 6
224#define LINE2R_ENUM 7
Jarkko Nikula4d20f702008-06-27 14:07:57 +0300225#define ADC_HPF_ENUM 8
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100226
227static const struct soc_enum aic3x_enum[] = {
228 SOC_ENUM_SINGLE(DAC_LINE_MUX, 6, 3, aic3x_left_dac_mux),
229 SOC_ENUM_SINGLE(DAC_LINE_MUX, 4, 3, aic3x_right_dac_mux),
230 SOC_ENUM_SINGLE(HPLCOM_CFG, 4, 3, aic3x_left_hpcom_mux),
231 SOC_ENUM_SINGLE(HPRCOM_CFG, 3, 5, aic3x_right_hpcom_mux),
232 SOC_ENUM_SINGLE(LINE1L_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux),
233 SOC_ENUM_SINGLE(LINE1R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux),
234 SOC_ENUM_SINGLE(LINE2L_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux),
235 SOC_ENUM_SINGLE(LINE2R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux),
Jarkko Nikula4d20f702008-06-27 14:07:57 +0300236 SOC_ENUM_DOUBLE(AIC3X_CODEC_DFILT_CTRL, 6, 4, 4, aic3x_adc_hpf),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100237};
238
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200239/*
240 * DAC digital volumes. From -63.5 to 0 dB in 0.5 dB steps
241 */
242static DECLARE_TLV_DB_SCALE(dac_tlv, -6350, 50, 0);
243/* ADC PGA gain volumes. From 0 to 59.5 dB in 0.5 dB steps */
244static DECLARE_TLV_DB_SCALE(adc_tlv, 0, 50, 0);
245/*
246 * Output stage volumes. From -78.3 to 0 dB. Muted below -78.3 dB.
247 * Step size is approximately 0.5 dB over most of the scale but increasing
248 * near the very low levels.
249 * Define dB scale so that it is mostly correct for range about -55 to 0 dB
250 * but having increasing dB difference below that (and where it doesn't count
251 * so much). This setting shows -50 dB (actual is -50.3 dB) for register
252 * value 100 and -58.5 dB (actual is -78.3 dB) for register value 117.
253 */
254static DECLARE_TLV_DB_SCALE(output_stage_tlv, -5900, 50, 1);
255
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100256static const struct snd_kcontrol_new aic3x_snd_controls[] = {
257 /* Output */
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200258 SOC_DOUBLE_R_TLV("PCM Playback Volume",
259 LDAC_VOL, RDAC_VOL, 0, 0x7f, 1, dac_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100260
Jarkko Nikula098b1712010-08-27 16:56:50 +0300261 /*
262 * Output controls that map to output mixer switches. Note these are
263 * only for swapped L-to-R and R-to-L routes. See below stereo controls
264 * for direct L-to-L and R-to-R routes.
265 */
266 SOC_SINGLE_TLV("Left Line Mixer Line2R Bypass Volume",
267 LINE2R_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
268 SOC_SINGLE_TLV("Left Line Mixer PGAR Bypass Volume",
269 PGAR_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
270 SOC_SINGLE_TLV("Left Line Mixer DACR1 Playback Volume",
271 DACR1_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
272
273 SOC_SINGLE_TLV("Right Line Mixer Line2L Bypass Volume",
274 LINE2L_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
275 SOC_SINGLE_TLV("Right Line Mixer PGAL Bypass Volume",
276 PGAL_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
277 SOC_SINGLE_TLV("Right Line Mixer DACL1 Playback Volume",
278 DACL1_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
279
280 SOC_SINGLE_TLV("Left HP Mixer Line2R Bypass Volume",
281 LINE2R_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
282 SOC_SINGLE_TLV("Left HP Mixer PGAR Bypass Volume",
283 PGAR_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
284 SOC_SINGLE_TLV("Left HP Mixer DACR1 Playback Volume",
285 DACR1_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
286
287 SOC_SINGLE_TLV("Right HP Mixer Line2L Bypass Volume",
288 LINE2L_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
289 SOC_SINGLE_TLV("Right HP Mixer PGAL Bypass Volume",
290 PGAL_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
291 SOC_SINGLE_TLV("Right HP Mixer DACL1 Playback Volume",
292 DACL1_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
293
294 SOC_SINGLE_TLV("Left HPCOM Mixer Line2R Bypass Volume",
295 LINE2R_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
296 SOC_SINGLE_TLV("Left HPCOM Mixer PGAR Bypass Volume",
297 PGAR_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
298 SOC_SINGLE_TLV("Left HPCOM Mixer DACR1 Playback Volume",
299 DACR1_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
300
301 SOC_SINGLE_TLV("Right HPCOM Mixer Line2L Bypass Volume",
302 LINE2L_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
303 SOC_SINGLE_TLV("Right HPCOM Mixer PGAL Bypass Volume",
304 PGAL_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
305 SOC_SINGLE_TLV("Right HPCOM Mixer DACL1 Playback Volume",
306 DACL1_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
307
308 /* Stereo output controls for direct L-to-L and R-to-R routes */
309 SOC_DOUBLE_R_TLV("Line Line2 Bypass Volume",
310 LINE2L_2_LLOPM_VOL, LINE2R_2_RLOPM_VOL,
311 0, 118, 1, output_stage_tlv),
312 SOC_DOUBLE_R_TLV("Line PGA Bypass Volume",
313 PGAL_2_LLOPM_VOL, PGAR_2_RLOPM_VOL,
314 0, 118, 1, output_stage_tlv),
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200315 SOC_DOUBLE_R_TLV("Line DAC Playback Volume",
316 DACL1_2_LLOPM_VOL, DACR1_2_RLOPM_VOL,
317 0, 118, 1, output_stage_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100318
Jarkko Nikula098b1712010-08-27 16:56:50 +0300319 SOC_DOUBLE_R_TLV("Mono Line2 Bypass Volume",
320 LINE2L_2_MONOLOPM_VOL, LINE2R_2_MONOLOPM_VOL,
321 0, 118, 1, output_stage_tlv),
322 SOC_DOUBLE_R_TLV("Mono PGA Bypass Volume",
323 PGAL_2_MONOLOPM_VOL, PGAR_2_MONOLOPM_VOL,
324 0, 118, 1, output_stage_tlv),
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200325 SOC_DOUBLE_R_TLV("Mono DAC Playback Volume",
326 DACL1_2_MONOLOPM_VOL, DACR1_2_MONOLOPM_VOL,
327 0, 118, 1, output_stage_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100328
Jarkko Nikula098b1712010-08-27 16:56:50 +0300329 SOC_DOUBLE_R_TLV("HP Line2 Bypass Volume",
330 LINE2L_2_HPLOUT_VOL, LINE2R_2_HPROUT_VOL,
331 0, 118, 1, output_stage_tlv),
332 SOC_DOUBLE_R_TLV("HP PGA Bypass Volume",
333 PGAL_2_HPLOUT_VOL, PGAR_2_HPROUT_VOL,
334 0, 118, 1, output_stage_tlv),
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200335 SOC_DOUBLE_R_TLV("HP DAC Playback Volume",
336 DACL1_2_HPLOUT_VOL, DACR1_2_HPROUT_VOL,
337 0, 118, 1, output_stage_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100338
Jarkko Nikula098b1712010-08-27 16:56:50 +0300339 SOC_DOUBLE_R_TLV("HPCOM Line2 Bypass Volume",
340 LINE2L_2_HPLCOM_VOL, LINE2R_2_HPRCOM_VOL,
341 0, 118, 1, output_stage_tlv),
342 SOC_DOUBLE_R_TLV("HPCOM PGA Bypass Volume",
343 PGAL_2_HPLCOM_VOL, PGAR_2_HPRCOM_VOL,
344 0, 118, 1, output_stage_tlv),
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200345 SOC_DOUBLE_R_TLV("HPCOM DAC Playback Volume",
346 DACL1_2_HPLCOM_VOL, DACR1_2_HPRCOM_VOL,
347 0, 118, 1, output_stage_tlv),
Jarkko Nikula098b1712010-08-27 16:56:50 +0300348
349 /* Output pin mute controls */
350 SOC_DOUBLE_R("Line Playback Switch", LLOPM_CTRL, RLOPM_CTRL, 3,
351 0x01, 0),
352 SOC_SINGLE("Mono Playback Switch", MONOLOPM_CTRL, 3, 0x01, 0),
353 SOC_DOUBLE_R("HP Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3,
354 0x01, 0),
Jarkko Nikulaf9bc0292010-08-27 16:56:47 +0300355 SOC_DOUBLE_R("HPCOM Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3,
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100356 0x01, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100357
358 /*
359 * Note: enable Automatic input Gain Controller with care. It can
360 * adjust PGA to max value when ADC is on and will never go back.
361 */
362 SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0),
363
364 /* Input */
Jarkko Nikula7565fc32009-02-09 14:27:07 +0200365 SOC_DOUBLE_R_TLV("PGA Capture Volume", LADC_VOL, RADC_VOL,
366 0, 119, 0, adc_tlv),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100367 SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1),
Jarkko Nikula4d20f702008-06-27 14:07:57 +0300368
369 SOC_ENUM("ADC HPF Cut-off", aic3x_enum[ADC_HPF_ENUM]),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100370};
371
Randolph Chung6184f102010-08-20 12:47:53 +0800372/*
373 * Class-D amplifier gain. From 0 to 18 dB in 6 dB steps
374 */
375static DECLARE_TLV_DB_SCALE(classd_amp_tlv, 0, 600, 0);
376
377static const struct snd_kcontrol_new aic3x_classd_amp_gain_ctrl =
378 SOC_DOUBLE_TLV("Class-D Amplifier Gain", CLASSD_CTRL, 6, 4, 3, 0, classd_amp_tlv);
379
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100380/* Left DAC Mux */
381static const struct snd_kcontrol_new aic3x_left_dac_mux_controls =
382SOC_DAPM_ENUM("Route", aic3x_enum[LDAC_ENUM]);
383
384/* Right DAC Mux */
385static const struct snd_kcontrol_new aic3x_right_dac_mux_controls =
386SOC_DAPM_ENUM("Route", aic3x_enum[RDAC_ENUM]);
387
388/* Left HPCOM Mux */
389static const struct snd_kcontrol_new aic3x_left_hpcom_mux_controls =
390SOC_DAPM_ENUM("Route", aic3x_enum[LHPCOM_ENUM]);
391
392/* Right HPCOM Mux */
393static const struct snd_kcontrol_new aic3x_right_hpcom_mux_controls =
394SOC_DAPM_ENUM("Route", aic3x_enum[RHPCOM_ENUM]);
395
Jarkko Nikulac3b79e02010-08-27 16:56:49 +0300396/* Left Line Mixer */
397static const struct snd_kcontrol_new aic3x_left_line_mixer_controls[] = {
398 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_LLOPM_VOL, 7, 1, 0),
399 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_LLOPM_VOL, 7, 1, 0),
400 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_LLOPM_VOL, 7, 1, 0),
401 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_LLOPM_VOL, 7, 1, 0),
402 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_LLOPM_VOL, 7, 1, 0),
403 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_LLOPM_VOL, 7, 1, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100404};
405
Jarkko Nikulac3b79e02010-08-27 16:56:49 +0300406/* Right Line Mixer */
407static const struct snd_kcontrol_new aic3x_right_line_mixer_controls[] = {
408 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_RLOPM_VOL, 7, 1, 0),
409 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_RLOPM_VOL, 7, 1, 0),
410 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_RLOPM_VOL, 7, 1, 0),
411 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_RLOPM_VOL, 7, 1, 0),
412 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_RLOPM_VOL, 7, 1, 0),
413 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_RLOPM_VOL, 7, 1, 0),
414};
415
416/* Mono Mixer */
417static const struct snd_kcontrol_new aic3x_mono_mixer_controls[] = {
418 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_MONOLOPM_VOL, 7, 1, 0),
419 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_MONOLOPM_VOL, 7, 1, 0),
420 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_MONOLOPM_VOL, 7, 1, 0),
421 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_MONOLOPM_VOL, 7, 1, 0),
422 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_MONOLOPM_VOL, 7, 1, 0),
423 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_MONOLOPM_VOL, 7, 1, 0),
424};
425
426/* Left HP Mixer */
427static const struct snd_kcontrol_new aic3x_left_hp_mixer_controls[] = {
428 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLOUT_VOL, 7, 1, 0),
429 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLOUT_VOL, 7, 1, 0),
430 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLOUT_VOL, 7, 1, 0),
431 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLOUT_VOL, 7, 1, 0),
432 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLOUT_VOL, 7, 1, 0),
433 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLOUT_VOL, 7, 1, 0),
434};
435
436/* Right HP Mixer */
437static const struct snd_kcontrol_new aic3x_right_hp_mixer_controls[] = {
438 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPROUT_VOL, 7, 1, 0),
439 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPROUT_VOL, 7, 1, 0),
440 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPROUT_VOL, 7, 1, 0),
441 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPROUT_VOL, 7, 1, 0),
442 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPROUT_VOL, 7, 1, 0),
443 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPROUT_VOL, 7, 1, 0),
444};
445
446/* Left HPCOM Mixer */
447static const struct snd_kcontrol_new aic3x_left_hpcom_mixer_controls[] = {
448 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLCOM_VOL, 7, 1, 0),
449 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLCOM_VOL, 7, 1, 0),
450 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLCOM_VOL, 7, 1, 0),
451 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLCOM_VOL, 7, 1, 0),
452 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLCOM_VOL, 7, 1, 0),
453 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLCOM_VOL, 7, 1, 0),
454};
455
456/* Right HPCOM Mixer */
457static const struct snd_kcontrol_new aic3x_right_hpcom_mixer_controls[] = {
458 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPRCOM_VOL, 7, 1, 0),
459 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPRCOM_VOL, 7, 1, 0),
460 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPRCOM_VOL, 7, 1, 0),
461 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPRCOM_VOL, 7, 1, 0),
462 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPRCOM_VOL, 7, 1, 0),
463 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPRCOM_VOL, 7, 1, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100464};
465
466/* Left PGA Mixer */
467static const struct snd_kcontrol_new aic3x_left_pga_mixer_controls[] = {
468 SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1),
Daniel Mack54f01912008-11-26 17:47:36 +0100469 SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_LADC_CTRL, 3, 1, 1),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100470 SOC_DAPM_SINGLE_AIC3X("Line2L Switch", LINE2L_2_LADC_CTRL, 3, 1, 1),
471 SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1),
Daniel Mack54f01912008-11-26 17:47:36 +0100472 SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_LADC_CTRL, 0, 1, 1),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100473};
474
475/* Right PGA Mixer */
476static const struct snd_kcontrol_new aic3x_right_pga_mixer_controls[] = {
477 SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1),
Daniel Mack54f01912008-11-26 17:47:36 +0100478 SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_RADC_CTRL, 3, 1, 1),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100479 SOC_DAPM_SINGLE_AIC3X("Line2R Switch", LINE2R_2_RADC_CTRL, 3, 1, 1),
Daniel Mack54f01912008-11-26 17:47:36 +0100480 SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_RADC_CTRL, 4, 1, 1),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100481 SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1),
482};
483
484/* Left Line1 Mux */
485static const struct snd_kcontrol_new aic3x_left_line1_mux_controls =
486SOC_DAPM_ENUM("Route", aic3x_enum[LINE1L_ENUM]);
487
488/* Right Line1 Mux */
489static const struct snd_kcontrol_new aic3x_right_line1_mux_controls =
490SOC_DAPM_ENUM("Route", aic3x_enum[LINE1R_ENUM]);
491
492/* Left Line2 Mux */
493static const struct snd_kcontrol_new aic3x_left_line2_mux_controls =
494SOC_DAPM_ENUM("Route", aic3x_enum[LINE2L_ENUM]);
495
496/* Right Line2 Mux */
497static const struct snd_kcontrol_new aic3x_right_line2_mux_controls =
498SOC_DAPM_ENUM("Route", aic3x_enum[LINE2R_ENUM]);
499
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100500static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
501 /* Left DAC to Left Outputs */
502 SND_SOC_DAPM_DAC("Left DAC", "Left Playback", DAC_PWR, 7, 0),
503 SND_SOC_DAPM_MUX("Left DAC Mux", SND_SOC_NOPM, 0, 0,
504 &aic3x_left_dac_mux_controls),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100505 SND_SOC_DAPM_MUX("Left HPCOM Mux", SND_SOC_NOPM, 0, 0,
506 &aic3x_left_hpcom_mux_controls),
507 SND_SOC_DAPM_PGA("Left Line Out", LLOPM_CTRL, 0, 0, NULL, 0),
508 SND_SOC_DAPM_PGA("Left HP Out", HPLOUT_CTRL, 0, 0, NULL, 0),
509 SND_SOC_DAPM_PGA("Left HP Com", HPLCOM_CTRL, 0, 0, NULL, 0),
510
511 /* Right DAC to Right Outputs */
512 SND_SOC_DAPM_DAC("Right DAC", "Right Playback", DAC_PWR, 6, 0),
513 SND_SOC_DAPM_MUX("Right DAC Mux", SND_SOC_NOPM, 0, 0,
514 &aic3x_right_dac_mux_controls),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100515 SND_SOC_DAPM_MUX("Right HPCOM Mux", SND_SOC_NOPM, 0, 0,
516 &aic3x_right_hpcom_mux_controls),
517 SND_SOC_DAPM_PGA("Right Line Out", RLOPM_CTRL, 0, 0, NULL, 0),
518 SND_SOC_DAPM_PGA("Right HP Out", HPROUT_CTRL, 0, 0, NULL, 0),
519 SND_SOC_DAPM_PGA("Right HP Com", HPRCOM_CTRL, 0, 0, NULL, 0),
520
521 /* Mono Output */
522 SND_SOC_DAPM_PGA("Mono Out", MONOLOPM_CTRL, 0, 0, NULL, 0),
523
Daniel Mack54f01912008-11-26 17:47:36 +0100524 /* Inputs to Left ADC */
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100525 SND_SOC_DAPM_ADC("Left ADC", "Left Capture", LINE1L_2_LADC_CTRL, 2, 0),
526 SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0,
527 &aic3x_left_pga_mixer_controls[0],
528 ARRAY_SIZE(aic3x_left_pga_mixer_controls)),
529 SND_SOC_DAPM_MUX("Left Line1L Mux", SND_SOC_NOPM, 0, 0,
530 &aic3x_left_line1_mux_controls),
Daniel Mack54f01912008-11-26 17:47:36 +0100531 SND_SOC_DAPM_MUX("Left Line1R Mux", SND_SOC_NOPM, 0, 0,
532 &aic3x_left_line1_mux_controls),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100533 SND_SOC_DAPM_MUX("Left Line2L Mux", SND_SOC_NOPM, 0, 0,
534 &aic3x_left_line2_mux_controls),
535
Daniel Mack54f01912008-11-26 17:47:36 +0100536 /* Inputs to Right ADC */
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100537 SND_SOC_DAPM_ADC("Right ADC", "Right Capture",
538 LINE1R_2_RADC_CTRL, 2, 0),
539 SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0,
540 &aic3x_right_pga_mixer_controls[0],
541 ARRAY_SIZE(aic3x_right_pga_mixer_controls)),
Daniel Mack54f01912008-11-26 17:47:36 +0100542 SND_SOC_DAPM_MUX("Right Line1L Mux", SND_SOC_NOPM, 0, 0,
543 &aic3x_right_line1_mux_controls),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100544 SND_SOC_DAPM_MUX("Right Line1R Mux", SND_SOC_NOPM, 0, 0,
545 &aic3x_right_line1_mux_controls),
546 SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0,
547 &aic3x_right_line2_mux_controls),
548
Jarkko Nikulaee15ffd2008-06-25 14:58:46 +0300549 /*
550 * Not a real mic bias widget but similar function. This is for dynamic
551 * control of GPIO1 digital mic modulator clock output function when
552 * using digital mic.
553 */
554 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "GPIO1 dmic modclk",
555 AIC3X_GPIO1_REG, 4, 0xf,
556 AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK,
557 AIC3X_GPIO1_FUNC_DISABLED),
558
559 /*
560 * Also similar function like mic bias. Selects digital mic with
561 * configurable oversampling rate instead of ADC converter.
562 */
563 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 128",
564 AIC3X_ASD_INTF_CTRLA, 0, 3, 1, 0),
565 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 64",
566 AIC3X_ASD_INTF_CTRLA, 0, 3, 2, 0),
567 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 32",
568 AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0),
569
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100570 /* Mic Bias */
Jarkko Nikula0bd72a32008-06-25 14:42:08 +0300571 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias 2V",
572 MICBIAS_CTRL, 6, 3, 1, 0),
573 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias 2.5V",
574 MICBIAS_CTRL, 6, 3, 2, 0),
575 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias AVDD",
576 MICBIAS_CTRL, 6, 3, 3, 0),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100577
Jarkko Nikulac3b79e02010-08-27 16:56:49 +0300578 /* Output mixers */
579 SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0,
580 &aic3x_left_line_mixer_controls[0],
581 ARRAY_SIZE(aic3x_left_line_mixer_controls)),
582 SND_SOC_DAPM_MIXER("Right Line Mixer", SND_SOC_NOPM, 0, 0,
583 &aic3x_right_line_mixer_controls[0],
584 ARRAY_SIZE(aic3x_right_line_mixer_controls)),
585 SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0,
586 &aic3x_mono_mixer_controls[0],
587 ARRAY_SIZE(aic3x_mono_mixer_controls)),
588 SND_SOC_DAPM_MIXER("Left HP Mixer", SND_SOC_NOPM, 0, 0,
589 &aic3x_left_hp_mixer_controls[0],
590 ARRAY_SIZE(aic3x_left_hp_mixer_controls)),
591 SND_SOC_DAPM_MIXER("Right HP Mixer", SND_SOC_NOPM, 0, 0,
592 &aic3x_right_hp_mixer_controls[0],
593 ARRAY_SIZE(aic3x_right_hp_mixer_controls)),
594 SND_SOC_DAPM_MIXER("Left HPCOM Mixer", SND_SOC_NOPM, 0, 0,
595 &aic3x_left_hpcom_mixer_controls[0],
596 ARRAY_SIZE(aic3x_left_hpcom_mixer_controls)),
597 SND_SOC_DAPM_MIXER("Right HPCOM Mixer", SND_SOC_NOPM, 0, 0,
598 &aic3x_right_hpcom_mixer_controls[0],
599 ARRAY_SIZE(aic3x_right_hpcom_mixer_controls)),
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100600
601 SND_SOC_DAPM_OUTPUT("LLOUT"),
602 SND_SOC_DAPM_OUTPUT("RLOUT"),
603 SND_SOC_DAPM_OUTPUT("MONO_LOUT"),
604 SND_SOC_DAPM_OUTPUT("HPLOUT"),
605 SND_SOC_DAPM_OUTPUT("HPROUT"),
606 SND_SOC_DAPM_OUTPUT("HPLCOM"),
607 SND_SOC_DAPM_OUTPUT("HPRCOM"),
608
609 SND_SOC_DAPM_INPUT("MIC3L"),
610 SND_SOC_DAPM_INPUT("MIC3R"),
611 SND_SOC_DAPM_INPUT("LINE1L"),
612 SND_SOC_DAPM_INPUT("LINE1R"),
613 SND_SOC_DAPM_INPUT("LINE2L"),
614 SND_SOC_DAPM_INPUT("LINE2R"),
615};
616
Randolph Chung6184f102010-08-20 12:47:53 +0800617static const struct snd_soc_dapm_widget aic3007_dapm_widgets[] = {
618 /* Class-D outputs */
619 SND_SOC_DAPM_PGA("Left Class-D Out", CLASSD_CTRL, 3, 0, NULL, 0),
620 SND_SOC_DAPM_PGA("Right Class-D Out", CLASSD_CTRL, 2, 0, NULL, 0),
621
622 SND_SOC_DAPM_OUTPUT("SPOP"),
623 SND_SOC_DAPM_OUTPUT("SPOM"),
624};
625
Mark Brownd0cc0d32008-05-13 14:55:22 +0200626static const struct snd_soc_dapm_route intercon[] = {
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100627 /* Left Input */
628 {"Left Line1L Mux", "single-ended", "LINE1L"},
629 {"Left Line1L Mux", "differential", "LINE1L"},
630
631 {"Left Line2L Mux", "single-ended", "LINE2L"},
632 {"Left Line2L Mux", "differential", "LINE2L"},
633
634 {"Left PGA Mixer", "Line1L Switch", "Left Line1L Mux"},
Daniel Mack54f01912008-11-26 17:47:36 +0100635 {"Left PGA Mixer", "Line1R Switch", "Left Line1R Mux"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100636 {"Left PGA Mixer", "Line2L Switch", "Left Line2L Mux"},
637 {"Left PGA Mixer", "Mic3L Switch", "MIC3L"},
Daniel Mack54f01912008-11-26 17:47:36 +0100638 {"Left PGA Mixer", "Mic3R Switch", "MIC3R"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100639
640 {"Left ADC", NULL, "Left PGA Mixer"},
Jarkko Nikulaee15ffd2008-06-25 14:58:46 +0300641 {"Left ADC", NULL, "GPIO1 dmic modclk"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100642
643 /* Right Input */
644 {"Right Line1R Mux", "single-ended", "LINE1R"},
645 {"Right Line1R Mux", "differential", "LINE1R"},
646
647 {"Right Line2R Mux", "single-ended", "LINE2R"},
648 {"Right Line2R Mux", "differential", "LINE2R"},
649
Daniel Mack54f01912008-11-26 17:47:36 +0100650 {"Right PGA Mixer", "Line1L Switch", "Right Line1L Mux"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100651 {"Right PGA Mixer", "Line1R Switch", "Right Line1R Mux"},
652 {"Right PGA Mixer", "Line2R Switch", "Right Line2R Mux"},
Daniel Mack54f01912008-11-26 17:47:36 +0100653 {"Right PGA Mixer", "Mic3L Switch", "MIC3L"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100654 {"Right PGA Mixer", "Mic3R Switch", "MIC3R"},
655
656 {"Right ADC", NULL, "Right PGA Mixer"},
Jarkko Nikulaee15ffd2008-06-25 14:58:46 +0300657 {"Right ADC", NULL, "GPIO1 dmic modclk"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100658
Jarkko Nikulaee15ffd2008-06-25 14:58:46 +0300659 /*
660 * Logical path between digital mic enable and GPIO1 modulator clock
661 * output function
662 */
663 {"GPIO1 dmic modclk", NULL, "DMic Rate 128"},
664 {"GPIO1 dmic modclk", NULL, "DMic Rate 64"},
665 {"GPIO1 dmic modclk", NULL, "DMic Rate 32"},
Jarkko Nikulac3b79e02010-08-27 16:56:49 +0300666
667 /* Left DAC Output */
668 {"Left DAC Mux", "DAC_L1", "Left DAC"},
669 {"Left DAC Mux", "DAC_L2", "Left DAC"},
670 {"Left DAC Mux", "DAC_L3", "Left DAC"},
671
672 /* Right DAC Output */
673 {"Right DAC Mux", "DAC_R1", "Right DAC"},
674 {"Right DAC Mux", "DAC_R2", "Right DAC"},
675 {"Right DAC Mux", "DAC_R3", "Right DAC"},
676
677 /* Left Line Output */
678 {"Left Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
679 {"Left Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
680 {"Left Line Mixer", "DACL1 Switch", "Left DAC Mux"},
681 {"Left Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
682 {"Left Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
683 {"Left Line Mixer", "DACR1 Switch", "Right DAC Mux"},
684
685 {"Left Line Out", NULL, "Left Line Mixer"},
686 {"Left Line Out", NULL, "Left DAC Mux"},
687 {"LLOUT", NULL, "Left Line Out"},
688
689 /* Right Line Output */
690 {"Right Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
691 {"Right Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
692 {"Right Line Mixer", "DACL1 Switch", "Left DAC Mux"},
693 {"Right Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
694 {"Right Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
695 {"Right Line Mixer", "DACR1 Switch", "Right DAC Mux"},
696
697 {"Right Line Out", NULL, "Right Line Mixer"},
698 {"Right Line Out", NULL, "Right DAC Mux"},
699 {"RLOUT", NULL, "Right Line Out"},
700
701 /* Mono Output */
702 {"Mono Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
703 {"Mono Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
704 {"Mono Mixer", "DACL1 Switch", "Left DAC Mux"},
705 {"Mono Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
706 {"Mono Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
707 {"Mono Mixer", "DACR1 Switch", "Right DAC Mux"},
708
709 {"Mono Out", NULL, "Mono Mixer"},
710 {"MONO_LOUT", NULL, "Mono Out"},
711
712 /* Left HP Output */
713 {"Left HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
714 {"Left HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
715 {"Left HP Mixer", "DACL1 Switch", "Left DAC Mux"},
716 {"Left HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
717 {"Left HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
718 {"Left HP Mixer", "DACR1 Switch", "Right DAC Mux"},
719
720 {"Left HP Out", NULL, "Left HP Mixer"},
721 {"Left HP Out", NULL, "Left DAC Mux"},
722 {"HPLOUT", NULL, "Left HP Out"},
723
724 /* Right HP Output */
725 {"Right HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
726 {"Right HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
727 {"Right HP Mixer", "DACL1 Switch", "Left DAC Mux"},
728 {"Right HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
729 {"Right HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
730 {"Right HP Mixer", "DACR1 Switch", "Right DAC Mux"},
731
732 {"Right HP Out", NULL, "Right HP Mixer"},
733 {"Right HP Out", NULL, "Right DAC Mux"},
734 {"HPROUT", NULL, "Right HP Out"},
735
736 /* Left HPCOM Output */
737 {"Left HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
738 {"Left HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
739 {"Left HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"},
740 {"Left HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
741 {"Left HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
742 {"Left HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"},
743
744 {"Left HPCOM Mux", "differential of HPLOUT", "Left HP Mixer"},
745 {"Left HPCOM Mux", "constant VCM", "Left HPCOM Mixer"},
746 {"Left HPCOM Mux", "single-ended", "Left HPCOM Mixer"},
747 {"Left HP Com", NULL, "Left HPCOM Mux"},
748 {"HPLCOM", NULL, "Left HP Com"},
749
750 /* Right HPCOM Output */
751 {"Right HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
752 {"Right HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
753 {"Right HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"},
754 {"Right HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
755 {"Right HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
756 {"Right HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"},
757
758 {"Right HPCOM Mux", "differential of HPROUT", "Right HP Mixer"},
759 {"Right HPCOM Mux", "constant VCM", "Right HPCOM Mixer"},
760 {"Right HPCOM Mux", "single-ended", "Right HPCOM Mixer"},
761 {"Right HPCOM Mux", "differential of HPLCOM", "Left HPCOM Mixer"},
762 {"Right HPCOM Mux", "external feedback", "Right HPCOM Mixer"},
763 {"Right HP Com", NULL, "Right HPCOM Mux"},
764 {"HPRCOM", NULL, "Right HP Com"},
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100765};
766
Randolph Chung6184f102010-08-20 12:47:53 +0800767static const struct snd_soc_dapm_route intercon_3007[] = {
768 /* Class-D outputs */
769 {"Left Class-D Out", NULL, "Left Line Out"},
770 {"Right Class-D Out", NULL, "Left Line Out"},
771 {"SPOP", NULL, "Left Class-D Out"},
772 {"SPOM", NULL, "Right Class-D Out"},
773};
774
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100775static int aic3x_add_widgets(struct snd_soc_codec *codec)
776{
Randolph Chung6184f102010-08-20 12:47:53 +0800777 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
778
Mark Brownd0cc0d32008-05-13 14:55:22 +0200779 snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets,
780 ARRAY_SIZE(aic3x_dapm_widgets));
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100781
782 /* set up audio path interconnects */
Mark Brownd0cc0d32008-05-13 14:55:22 +0200783 snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100784
Randolph Chung6184f102010-08-20 12:47:53 +0800785 if (aic3x->model == AIC3X_MODEL_3007) {
786 snd_soc_dapm_new_controls(codec, aic3007_dapm_widgets,
787 ARRAY_SIZE(aic3007_dapm_widgets));
788 snd_soc_dapm_add_routes(codec, intercon_3007, ARRAY_SIZE(intercon_3007));
789 }
790
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100791 return 0;
792}
793
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100794static int aic3x_hw_params(struct snd_pcm_substream *substream,
Mark Browndee89c42008-11-18 22:11:38 +0000795 struct snd_pcm_hw_params *params,
796 struct snd_soc_dai *dai)
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100797{
798 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000799 struct snd_soc_codec *codec =rtd->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900800 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200801 int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0;
Peter Meerwald255173b2009-12-14 14:44:56 +0100802 u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1;
803 u16 d, pll_d = 1;
Chaithrika U S06c71282009-07-22 07:45:04 -0400804 u8 reg;
Peter Meerwald255173b2009-12-14 14:44:56 +0100805 int clk;
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100806
807 /* select data word length */
Jarkko Nikulae18eca42010-09-14 14:54:47 +0300808 data = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4));
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100809 switch (params_format(params)) {
810 case SNDRV_PCM_FORMAT_S16_LE:
811 break;
812 case SNDRV_PCM_FORMAT_S20_3LE:
813 data |= (0x01 << 4);
814 break;
815 case SNDRV_PCM_FORMAT_S24_LE:
816 data |= (0x02 << 4);
817 break;
818 case SNDRV_PCM_FORMAT_S32_LE:
819 data |= (0x03 << 4);
820 break;
821 }
Jarkko Nikulae18eca42010-09-14 14:54:47 +0300822 snd_soc_write(codec, AIC3X_ASD_INTF_CTRLB, data);
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100823
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200824 /* Fsref can be 44100 or 48000 */
825 fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000;
826
827 /* Try to find a value for Q which allows us to bypass the PLL and
828 * generate CODEC_CLK directly. */
829 for (pll_q = 2; pll_q < 18; pll_q++)
830 if (aic3x->sysclk / (128 * pll_q) == fsref) {
831 bypass_pll = 1;
832 break;
833 }
834
835 if (bypass_pll) {
836 pll_q &= 0xf;
Jarkko Nikulae18eca42010-09-14 14:54:47 +0300837 snd_soc_write(codec, AIC3X_PLL_PROGA_REG, pll_q << PLLQ_SHIFT);
838 snd_soc_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_CLKDIV);
Chaithrika U S06c71282009-07-22 07:45:04 -0400839 /* disable PLL if it is bypassed */
Jarkko Nikulae18eca42010-09-14 14:54:47 +0300840 reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
841 snd_soc_write(codec, AIC3X_PLL_PROGA_REG, reg & ~PLL_ENABLE);
Chaithrika U S06c71282009-07-22 07:45:04 -0400842
843 } else {
Jarkko Nikulae18eca42010-09-14 14:54:47 +0300844 snd_soc_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_PLLDIV);
Chaithrika U S06c71282009-07-22 07:45:04 -0400845 /* enable PLL when it is used */
Jarkko Nikulae18eca42010-09-14 14:54:47 +0300846 reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
847 snd_soc_write(codec, AIC3X_PLL_PROGA_REG, reg | PLL_ENABLE);
Chaithrika U S06c71282009-07-22 07:45:04 -0400848 }
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200849
850 /* Route Left DAC to left channel input and
851 * right DAC to right channel input */
852 data = (LDAC2LCH | RDAC2RCH);
853 data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000;
854 if (params_rate(params) >= 64000)
855 data |= DUAL_RATE_MODE;
Jarkko Nikulae18eca42010-09-14 14:54:47 +0300856 snd_soc_write(codec, AIC3X_CODEC_DATAPATH_REG, data);
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200857
858 /* codec sample rate select */
859 data = (fsref * 20) / params_rate(params);
860 if (params_rate(params) < 64000)
861 data /= 2;
862 data /= 5;
863 data -= 2;
864 data |= (data << 4);
Jarkko Nikulae18eca42010-09-14 14:54:47 +0300865 snd_soc_write(codec, AIC3X_SAMPLE_RATE_SEL_REG, data);
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200866
867 if (bypass_pll)
868 return 0;
869
Peter Meerwald255173b2009-12-14 14:44:56 +0100870 /* Use PLL, compute apropriate setup for j, d, r and p, the closest
871 * one wins the game. Try with d==0 first, next with d!=0.
872 * Constraints for j are according to the datasheet.
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200873 * The sysclk is divided by 1000 to prevent integer overflows.
874 */
Peter Meerwald255173b2009-12-14 14:44:56 +0100875
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200876 codec_clk = (2048 * fsref) / (aic3x->sysclk / 1000);
877
878 for (r = 1; r <= 16; r++)
879 for (p = 1; p <= 8; p++) {
Peter Meerwald255173b2009-12-14 14:44:56 +0100880 for (j = 4; j <= 55; j++) {
881 /* This is actually 1000*((j+(d/10000))*r)/p
882 * The term had to be converted to get
883 * rid of the division by 10000; d = 0 here
884 */
Mark Brown5baf8312010-01-02 13:13:42 +0000885 int tmp_clk = (1000 * j * r) / p;
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200886
Peter Meerwald255173b2009-12-14 14:44:56 +0100887 /* Check whether this values get closer than
888 * the best ones we had before
889 */
Mark Brown5baf8312010-01-02 13:13:42 +0000890 if (abs(codec_clk - tmp_clk) <
Peter Meerwald255173b2009-12-14 14:44:56 +0100891 abs(codec_clk - last_clk)) {
892 pll_j = j; pll_d = 0;
893 pll_r = r; pll_p = p;
Mark Brown5baf8312010-01-02 13:13:42 +0000894 last_clk = tmp_clk;
Peter Meerwald255173b2009-12-14 14:44:56 +0100895 }
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200896
Peter Meerwald255173b2009-12-14 14:44:56 +0100897 /* Early exit for exact matches */
Mark Brown5baf8312010-01-02 13:13:42 +0000898 if (tmp_clk == codec_clk)
Peter Meerwald255173b2009-12-14 14:44:56 +0100899 goto found;
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200900 }
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200901 }
902
Peter Meerwald255173b2009-12-14 14:44:56 +0100903 /* try with d != 0 */
904 for (p = 1; p <= 8; p++) {
905 j = codec_clk * p / 1000;
906
907 if (j < 4 || j > 11)
908 continue;
909
910 /* do not use codec_clk here since we'd loose precision */
911 d = ((2048 * p * fsref) - j * aic3x->sysclk)
912 * 100 / (aic3x->sysclk/100);
913
914 clk = (10000 * j + d) / (10 * p);
915
916 /* check whether this values get closer than the best
917 * ones we had before */
918 if (abs(codec_clk - clk) < abs(codec_clk - last_clk)) {
919 pll_j = j; pll_d = d; pll_r = 1; pll_p = p;
920 last_clk = clk;
921 }
922
923 /* Early exit for exact matches */
924 if (clk == codec_clk)
925 goto found;
926 }
927
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200928 if (last_clk == 0) {
929 printk(KERN_ERR "%s(): unable to setup PLL\n", __func__);
930 return -EINVAL;
931 }
932
Peter Meerwald255173b2009-12-14 14:44:56 +0100933found:
Jarkko Nikulae18eca42010-09-14 14:54:47 +0300934 data = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
935 snd_soc_write(codec, AIC3X_PLL_PROGA_REG,
936 data | (pll_p << PLLP_SHIFT));
937 snd_soc_write(codec, AIC3X_OVRF_STATUS_AND_PLLR_REG,
938 pll_r << PLLR_SHIFT);
939 snd_soc_write(codec, AIC3X_PLL_PROGB_REG, pll_j << PLLJ_SHIFT);
940 snd_soc_write(codec, AIC3X_PLL_PROGC_REG,
941 (pll_d >> 6) << PLLD_MSB_SHIFT);
942 snd_soc_write(codec, AIC3X_PLL_PROGD_REG,
943 (pll_d & 0x3F) << PLLD_LSB_SHIFT);
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200944
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100945 return 0;
946}
947
Liam Girdwoode550e172008-07-07 16:07:52 +0100948static int aic3x_mute(struct snd_soc_dai *dai, int mute)
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100949{
950 struct snd_soc_codec *codec = dai->codec;
Jarkko Nikulae18eca42010-09-14 14:54:47 +0300951 u8 ldac_reg = snd_soc_read(codec, LDAC_VOL) & ~MUTE_ON;
952 u8 rdac_reg = snd_soc_read(codec, RDAC_VOL) & ~MUTE_ON;
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100953
954 if (mute) {
Jarkko Nikulae18eca42010-09-14 14:54:47 +0300955 snd_soc_write(codec, LDAC_VOL, ldac_reg | MUTE_ON);
956 snd_soc_write(codec, RDAC_VOL, rdac_reg | MUTE_ON);
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100957 } else {
Jarkko Nikulae18eca42010-09-14 14:54:47 +0300958 snd_soc_write(codec, LDAC_VOL, ldac_reg);
959 snd_soc_write(codec, RDAC_VOL, rdac_reg);
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100960 }
961
962 return 0;
963}
964
Liam Girdwoode550e172008-07-07 16:07:52 +0100965static int aic3x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100966 int clk_id, unsigned int freq, int dir)
967{
968 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900969 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100970
Daniel Mack4f9c16c2008-04-30 16:20:19 +0200971 aic3x->sysclk = freq;
972 return 0;
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100973}
974
Liam Girdwoode550e172008-07-07 16:07:52 +0100975static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100976 unsigned int fmt)
977{
978 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +0900979 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
Jarkko Nikula81971a12008-06-25 14:58:45 +0300980 u8 iface_areg, iface_breg;
Troy Kiskya24f4f62008-12-19 13:05:22 -0700981 int delay = 0;
Jarkko Nikula81971a12008-06-25 14:58:45 +0300982
Jarkko Nikulae18eca42010-09-14 14:54:47 +0300983 iface_areg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLA) & 0x3f;
984 iface_breg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLB) & 0x3f;
Vladimir Barinov44d0a872007-11-14 17:07:17 +0100985
986 /* set master/slave audio interface */
987 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
988 case SND_SOC_DAIFMT_CBM_CFM:
989 aic3x->master = 1;
990 iface_areg |= BIT_CLK_MASTER | WORD_CLK_MASTER;
991 break;
992 case SND_SOC_DAIFMT_CBS_CFS:
993 aic3x->master = 0;
994 break;
995 default:
996 return -EINVAL;
997 }
998
Jarkko Nikula4b7d2832008-10-23 14:27:03 +0300999 /*
1000 * match both interface format and signal polarities since they
1001 * are fixed
1002 */
1003 switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK |
1004 SND_SOC_DAIFMT_INV_MASK)) {
1005 case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF):
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001006 break;
Troy Kiskya24f4f62008-12-19 13:05:22 -07001007 case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF):
1008 delay = 1;
Jarkko Nikula4b7d2832008-10-23 14:27:03 +03001009 case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF):
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001010 iface_breg |= (0x01 << 6);
1011 break;
Jarkko Nikula4b7d2832008-10-23 14:27:03 +03001012 case (SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_NB_NF):
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001013 iface_breg |= (0x02 << 6);
1014 break;
Jarkko Nikula4b7d2832008-10-23 14:27:03 +03001015 case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF):
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001016 iface_breg |= (0x03 << 6);
1017 break;
1018 default:
1019 return -EINVAL;
1020 }
1021
1022 /* set iface */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001023 snd_soc_write(codec, AIC3X_ASD_INTF_CTRLA, iface_areg);
1024 snd_soc_write(codec, AIC3X_ASD_INTF_CTRLB, iface_breg);
1025 snd_soc_write(codec, AIC3X_ASD_INTF_CTRLC, delay);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001026
1027 return 0;
1028}
1029
Mark Brown0be98982008-05-19 12:31:28 +02001030static int aic3x_set_bias_level(struct snd_soc_codec *codec,
1031 enum snd_soc_bias_level level)
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001032{
Mark Brownb2c812e2010-04-14 15:35:19 +09001033 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001034 u8 reg;
1035
Mark Brown0be98982008-05-19 12:31:28 +02001036 switch (level) {
1037 case SND_SOC_BIAS_ON:
Jarkko Nikuladb138022010-04-26 15:49:13 +03001038 break;
1039 case SND_SOC_BIAS_PREPARE:
Jarkko Nikulac23fd752010-09-10 14:23:29 +03001040 if (codec->bias_level == SND_SOC_BIAS_STANDBY &&
1041 aic3x->master) {
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001042 /* enable pll */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001043 reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
1044 snd_soc_write(codec, AIC3X_PLL_PROGA_REG,
1045 reg | PLL_ENABLE);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001046 }
1047 break;
Mark Brown0be98982008-05-19 12:31:28 +02001048 case SND_SOC_BIAS_STANDBY:
Jarkko Nikulac23fd752010-09-10 14:23:29 +03001049 if (codec->bias_level == SND_SOC_BIAS_PREPARE &&
1050 aic3x->master) {
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001051 /* disable pll */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001052 reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
1053 snd_soc_write(codec, AIC3X_PLL_PROGA_REG,
1054 reg & ~PLL_ENABLE);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001055 }
1056 break;
Jarkko Nikulac23fd752010-09-10 14:23:29 +03001057 case SND_SOC_BIAS_OFF:
1058 break;
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001059 }
Mark Brown0be98982008-05-19 12:31:28 +02001060 codec->bias_level = level;
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001061
1062 return 0;
1063}
1064
Daniel Mack54e7e612008-04-30 16:20:52 +02001065void aic3x_set_gpio(struct snd_soc_codec *codec, int gpio, int state)
1066{
1067 u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG;
1068 u8 bit = gpio ? 3: 0;
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001069 u8 val = snd_soc_read(codec, reg) & ~(1 << bit);
1070 snd_soc_write(codec, reg, val | (!!state << bit));
Daniel Mack54e7e612008-04-30 16:20:52 +02001071}
1072EXPORT_SYMBOL_GPL(aic3x_set_gpio);
1073
1074int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio)
1075{
1076 u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG;
1077 u8 val, bit = gpio ? 2: 1;
1078
1079 aic3x_read(codec, reg, &val);
1080 return (val >> bit) & 1;
1081}
1082EXPORT_SYMBOL_GPL(aic3x_get_gpio);
1083
Daniel Mack6f2a9742008-12-03 11:44:17 +01001084void aic3x_set_headset_detection(struct snd_soc_codec *codec, int detect,
1085 int headset_debounce, int button_debounce)
1086{
1087 u8 val;
1088
1089 val = ((detect & AIC3X_HEADSET_DETECT_MASK)
1090 << AIC3X_HEADSET_DETECT_SHIFT) |
1091 ((headset_debounce & AIC3X_HEADSET_DEBOUNCE_MASK)
1092 << AIC3X_HEADSET_DEBOUNCE_SHIFT) |
1093 ((button_debounce & AIC3X_BUTTON_DEBOUNCE_MASK)
1094 << AIC3X_BUTTON_DEBOUNCE_SHIFT);
1095
1096 if (detect & AIC3X_HEADSET_DETECT_MASK)
1097 val |= AIC3X_HEADSET_DETECT_ENABLED;
1098
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001099 snd_soc_write(codec, AIC3X_HEADSET_DETECT_CTRL_A, val);
Daniel Mack6f2a9742008-12-03 11:44:17 +01001100}
1101EXPORT_SYMBOL_GPL(aic3x_set_headset_detection);
1102
Daniel Mack54e7e612008-04-30 16:20:52 +02001103int aic3x_headset_detected(struct snd_soc_codec *codec)
1104{
1105 u8 val;
Daniel Mack6f2a9742008-12-03 11:44:17 +01001106 aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val);
1107 return (val >> 4) & 1;
Daniel Mack54e7e612008-04-30 16:20:52 +02001108}
1109EXPORT_SYMBOL_GPL(aic3x_headset_detected);
1110
Daniel Mack6f2a9742008-12-03 11:44:17 +01001111int aic3x_button_pressed(struct snd_soc_codec *codec)
1112{
1113 u8 val;
1114 aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val);
1115 return (val >> 5) & 1;
1116}
1117EXPORT_SYMBOL_GPL(aic3x_button_pressed);
1118
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001119#define AIC3X_RATES SNDRV_PCM_RATE_8000_96000
1120#define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1121 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
1122
Eric Miao6335d052009-03-03 09:41:00 +08001123static struct snd_soc_dai_ops aic3x_dai_ops = {
1124 .hw_params = aic3x_hw_params,
1125 .digital_mute = aic3x_mute,
1126 .set_sysclk = aic3x_set_dai_sysclk,
1127 .set_fmt = aic3x_set_dai_fmt,
1128};
1129
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001130static struct snd_soc_dai_driver aic3x_dai = {
1131 .name = "tlv320aic3x-hifi",
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001132 .playback = {
1133 .stream_name = "Playback",
1134 .channels_min = 1,
1135 .channels_max = 2,
1136 .rates = AIC3X_RATES,
1137 .formats = AIC3X_FORMATS,},
1138 .capture = {
1139 .stream_name = "Capture",
1140 .channels_min = 1,
1141 .channels_max = 2,
1142 .rates = AIC3X_RATES,
1143 .formats = AIC3X_FORMATS,},
Eric Miao6335d052009-03-03 09:41:00 +08001144 .ops = &aic3x_dai_ops,
Randolph Chung14017612010-08-19 12:06:17 +01001145 .symmetric_rates = 1,
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001146};
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001147
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001148static int aic3x_suspend(struct snd_soc_codec *codec, pm_message_t state)
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001149{
Mark Brown0be98982008-05-19 12:31:28 +02001150 aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001151
1152 return 0;
1153}
1154
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001155static int aic3x_resume(struct snd_soc_codec *codec)
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001156{
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001157 int i;
1158 u8 data[2];
1159 u8 *cache = codec->reg_cache;
1160
1161 /* Sync reg_cache with the hardware */
1162 for (i = 0; i < ARRAY_SIZE(aic3x_reg); i++) {
1163 data[0] = i;
1164 data[1] = cache[i];
1165 codec->hw_write(codec->control_data, data, 2);
1166 }
1167
Mark Brown29e189c2010-05-07 20:30:00 +01001168 aic3x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001169
1170 return 0;
1171}
1172
1173/*
1174 * initialise the AIC3X driver
1175 * register the mixer and dsp interfaces with the kernel
1176 */
Ben Dookscb3826f2009-08-20 22:50:41 +01001177static int aic3x_init(struct snd_soc_codec *codec)
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001178{
Randolph Chung6184f102010-08-20 12:47:53 +08001179 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
Ben Dookscb3826f2009-08-20 22:50:41 +01001180 int reg;
1181
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001182 snd_soc_write(codec, AIC3X_PAGE_SELECT, PAGE0_SELECT);
1183 snd_soc_write(codec, AIC3X_RESET, SOFT_RESET);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001184
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001185 /* DAC default volume and mute */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001186 snd_soc_write(codec, LDAC_VOL, DEFAULT_VOL | MUTE_ON);
1187 snd_soc_write(codec, RDAC_VOL, DEFAULT_VOL | MUTE_ON);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001188
1189 /* DAC to HP default volume and route to Output mixer */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001190 snd_soc_write(codec, DACL1_2_HPLOUT_VOL, DEFAULT_VOL | ROUTE_ON);
1191 snd_soc_write(codec, DACR1_2_HPROUT_VOL, DEFAULT_VOL | ROUTE_ON);
1192 snd_soc_write(codec, DACL1_2_HPLCOM_VOL, DEFAULT_VOL | ROUTE_ON);
1193 snd_soc_write(codec, DACR1_2_HPRCOM_VOL, DEFAULT_VOL | ROUTE_ON);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001194 /* DAC to Line Out default volume and route to Output mixer */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001195 snd_soc_write(codec, DACL1_2_LLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1196 snd_soc_write(codec, DACR1_2_RLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001197 /* DAC to Mono Line Out default volume and route to Output mixer */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001198 snd_soc_write(codec, DACL1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1199 snd_soc_write(codec, DACR1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001200
1201 /* unmute all outputs */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001202 reg = snd_soc_read(codec, LLOPM_CTRL);
1203 snd_soc_write(codec, LLOPM_CTRL, reg | UNMUTE);
1204 reg = snd_soc_read(codec, RLOPM_CTRL);
1205 snd_soc_write(codec, RLOPM_CTRL, reg | UNMUTE);
1206 reg = snd_soc_read(codec, MONOLOPM_CTRL);
1207 snd_soc_write(codec, MONOLOPM_CTRL, reg | UNMUTE);
1208 reg = snd_soc_read(codec, HPLOUT_CTRL);
1209 snd_soc_write(codec, HPLOUT_CTRL, reg | UNMUTE);
1210 reg = snd_soc_read(codec, HPROUT_CTRL);
1211 snd_soc_write(codec, HPROUT_CTRL, reg | UNMUTE);
1212 reg = snd_soc_read(codec, HPLCOM_CTRL);
1213 snd_soc_write(codec, HPLCOM_CTRL, reg | UNMUTE);
1214 reg = snd_soc_read(codec, HPRCOM_CTRL);
1215 snd_soc_write(codec, HPRCOM_CTRL, reg | UNMUTE);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001216
1217 /* ADC default volume and unmute */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001218 snd_soc_write(codec, LADC_VOL, DEFAULT_GAIN);
1219 snd_soc_write(codec, RADC_VOL, DEFAULT_GAIN);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001220 /* By default route Line1 to ADC PGA mixer */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001221 snd_soc_write(codec, LINE1L_2_LADC_CTRL, 0x0);
1222 snd_soc_write(codec, LINE1R_2_RADC_CTRL, 0x0);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001223
1224 /* PGA to HP Bypass default volume, disconnect from Output Mixer */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001225 snd_soc_write(codec, PGAL_2_HPLOUT_VOL, DEFAULT_VOL);
1226 snd_soc_write(codec, PGAR_2_HPROUT_VOL, DEFAULT_VOL);
1227 snd_soc_write(codec, PGAL_2_HPLCOM_VOL, DEFAULT_VOL);
1228 snd_soc_write(codec, PGAR_2_HPRCOM_VOL, DEFAULT_VOL);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001229 /* PGA to Line Out default volume, disconnect from Output Mixer */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001230 snd_soc_write(codec, PGAL_2_LLOPM_VOL, DEFAULT_VOL);
1231 snd_soc_write(codec, PGAR_2_RLOPM_VOL, DEFAULT_VOL);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001232 /* PGA to Mono Line Out default volume, disconnect from Output Mixer */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001233 snd_soc_write(codec, PGAL_2_MONOLOPM_VOL, DEFAULT_VOL);
1234 snd_soc_write(codec, PGAR_2_MONOLOPM_VOL, DEFAULT_VOL);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001235
1236 /* Line2 to HP Bypass default volume, disconnect from Output Mixer */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001237 snd_soc_write(codec, LINE2L_2_HPLOUT_VOL, DEFAULT_VOL);
1238 snd_soc_write(codec, LINE2R_2_HPROUT_VOL, DEFAULT_VOL);
1239 snd_soc_write(codec, LINE2L_2_HPLCOM_VOL, DEFAULT_VOL);
1240 snd_soc_write(codec, LINE2R_2_HPRCOM_VOL, DEFAULT_VOL);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001241 /* Line2 Line Out default volume, disconnect from Output Mixer */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001242 snd_soc_write(codec, LINE2L_2_LLOPM_VOL, DEFAULT_VOL);
1243 snd_soc_write(codec, LINE2R_2_RLOPM_VOL, DEFAULT_VOL);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001244 /* Line2 to Mono Out default volume, disconnect from Output Mixer */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001245 snd_soc_write(codec, LINE2L_2_MONOLOPM_VOL, DEFAULT_VOL);
1246 snd_soc_write(codec, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001247
Randolph Chung6184f102010-08-20 12:47:53 +08001248 if (aic3x->model == AIC3X_MODEL_3007) {
1249 /* Class-D speaker driver init; datasheet p. 46 */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001250 snd_soc_write(codec, AIC3X_PAGE_SELECT, 0x0D);
1251 snd_soc_write(codec, 0xD, 0x0D);
1252 snd_soc_write(codec, 0x8, 0x5C);
1253 snd_soc_write(codec, 0x8, 0x5D);
1254 snd_soc_write(codec, 0x8, 0x5C);
1255 snd_soc_write(codec, AIC3X_PAGE_SELECT, 0x00);
1256 snd_soc_write(codec, CLASSD_CTRL, 0);
Randolph Chung6184f102010-08-20 12:47:53 +08001257 }
1258
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001259 /* off, with power on */
Mark Brown0be98982008-05-19 12:31:28 +02001260 aic3x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001261
Ben Dookscb3826f2009-08-20 22:50:41 +01001262 return 0;
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001263}
1264
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001265static int aic3x_probe(struct snd_soc_codec *codec)
Ben Dookscb3826f2009-08-20 22:50:41 +01001266{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001267 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
Jarkko Nikulaa84a4412010-09-14 14:54:48 +03001268 int ret;
Ben Dookscb3826f2009-08-20 22:50:41 +01001269
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001270 codec->control_data = aic3x->control_data;
1271
Jarkko Nikulaa84a4412010-09-14 14:54:48 +03001272 ret = snd_soc_codec_set_cache_io(codec, 8, 8, aic3x->control_type);
1273 if (ret != 0) {
1274 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
1275 return ret;
1276 }
1277
Jarkko Nikula37b47652010-08-23 10:38:40 +03001278 aic3x_init(codec);
1279
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001280 if (aic3x->setup) {
1281 /* setup GPIO functions */
Jarkko Nikulae18eca42010-09-14 14:54:47 +03001282 snd_soc_write(codec, AIC3X_GPIO1_REG,
1283 (aic3x->setup->gpio_func[0] & 0xf) << 4);
1284 snd_soc_write(codec, AIC3X_GPIO2_REG,
1285 (aic3x->setup->gpio_func[1] & 0xf) << 4);
Ben Dookscb3826f2009-08-20 22:50:41 +01001286 }
1287
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001288 snd_soc_add_controls(codec, aic3x_snd_controls,
1289 ARRAY_SIZE(aic3x_snd_controls));
Randolph Chung6184f102010-08-20 12:47:53 +08001290 if (aic3x->model == AIC3X_MODEL_3007)
1291 snd_soc_add_controls(codec, &aic3x_classd_amp_gain_ctrl, 1);
Ben Dookscb3826f2009-08-20 22:50:41 +01001292
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001293 aic3x_add_widgets(codec);
Ben Dookscb3826f2009-08-20 22:50:41 +01001294
1295 return 0;
1296}
1297
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001298static int aic3x_remove(struct snd_soc_codec *codec)
Ben Dookscb3826f2009-08-20 22:50:41 +01001299{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001300 aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
Ben Dookscb3826f2009-08-20 22:50:41 +01001301 return 0;
1302}
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001303
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001304static struct snd_soc_codec_driver soc_codec_dev_aic3x = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001305 .set_bias_level = aic3x_set_bias_level,
1306 .reg_cache_size = ARRAY_SIZE(aic3x_reg),
1307 .reg_word_size = sizeof(u8),
1308 .reg_cache_default = aic3x_reg,
1309 .probe = aic3x_probe,
1310 .remove = aic3x_remove,
1311 .suspend = aic3x_suspend,
1312 .resume = aic3x_resume,
1313};
1314
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001315#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1316/*
1317 * AIC3X 2 wire address can be up to 4 devices with device addresses
1318 * 0x18, 0x19, 0x1A, 0x1B
1319 */
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001320
Randolph Chung6184f102010-08-20 12:47:53 +08001321static const struct i2c_device_id aic3x_i2c_id[] = {
1322 [AIC3X_MODEL_3X] = { "tlv320aic3x", 0 },
1323 [AIC3X_MODEL_33] = { "tlv320aic33", 0 },
1324 [AIC3X_MODEL_3007] = { "tlv320aic3007", 0 },
1325 { }
1326};
1327MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id);
1328
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001329/*
1330 * If the i2c layer weren't so broken, we could pass this kind of data
1331 * around
1332 */
Jean Delvareba8ed122008-09-22 14:15:53 +02001333static int aic3x_i2c_probe(struct i2c_client *i2c,
1334 const struct i2c_device_id *id)
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001335{
Jarkko Nikula5193d622010-05-05 13:02:03 +03001336 struct aic3x_pdata *pdata = i2c->dev.platform_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001337 struct aic3x_priv *aic3x;
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001338 int ret, i;
Randolph Chung6184f102010-08-20 12:47:53 +08001339 const struct i2c_device_id *tbl;
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001340
Ben Dookscb3826f2009-08-20 22:50:41 +01001341 aic3x = kzalloc(sizeof(struct aic3x_priv), GFP_KERNEL);
1342 if (aic3x == NULL) {
1343 dev_err(&i2c->dev, "failed to create private data\n");
1344 return -ENOMEM;
1345 }
1346
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001347 aic3x->control_data = i2c;
Jarkko Nikulaa84a4412010-09-14 14:54:48 +03001348 aic3x->control_type = SND_SOC_I2C;
1349
Ben Dookscb3826f2009-08-20 22:50:41 +01001350 i2c_set_clientdata(i2c, aic3x);
Jarkko Nikulac7763572010-09-05 19:10:22 +03001351 if (pdata) {
1352 aic3x->gpio_reset = pdata->gpio_reset;
1353 aic3x->setup = pdata->setup;
1354 } else {
1355 aic3x->gpio_reset = -1;
1356 }
Ben Dookscb3826f2009-08-20 22:50:41 +01001357
Jarkko Nikulac7763572010-09-05 19:10:22 +03001358 if (aic3x->gpio_reset >= 0) {
1359 ret = gpio_request(aic3x->gpio_reset, "tlv320aic3x reset");
Jarkko Nikula5193d622010-05-05 13:02:03 +03001360 if (ret != 0)
1361 goto err_gpio;
Jarkko Nikula5193d622010-05-05 13:02:03 +03001362 gpio_direction_output(aic3x->gpio_reset, 0);
1363 }
1364
Randolph Chung6184f102010-08-20 12:47:53 +08001365 for (tbl = aic3x_i2c_id; tbl->name[0]; tbl++) {
1366 if (!strcmp(tbl->name, id->name))
1367 break;
1368 }
1369 aic3x->model = tbl - aic3x_i2c_id;
1370
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001371 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++)
1372 aic3x->supplies[i].supply = aic3x_supply_names[i];
1373
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001374 ret = regulator_bulk_get(&i2c->dev, ARRAY_SIZE(aic3x->supplies),
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001375 aic3x->supplies);
1376 if (ret != 0) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001377 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001378 goto err_get;
1379 }
1380
1381 ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies),
1382 aic3x->supplies);
1383 if (ret != 0) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001384 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret);
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001385 goto err_enable;
1386 }
1387
Jarkko Nikula5193d622010-05-05 13:02:03 +03001388 if (aic3x->gpio_reset >= 0) {
1389 udelay(1);
1390 gpio_set_value(aic3x->gpio_reset, 1);
1391 }
1392
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001393 ret = snd_soc_register_codec(&i2c->dev,
1394 &soc_codec_dev_aic3x, &aic3x_dai, 1);
1395 if (ret < 0)
1396 goto err_enable;
1397 return ret;
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001398
1399err_enable:
1400 regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
1401err_get:
Jarkko Nikula5193d622010-05-05 13:02:03 +03001402 if (aic3x->gpio_reset >= 0)
1403 gpio_free(aic3x->gpio_reset);
1404err_gpio:
Jarkko Nikula07779fd2010-04-26 15:49:14 +03001405 kfree(aic3x);
1406 return ret;
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001407}
1408
Jean Delvareba8ed122008-09-22 14:15:53 +02001409static int aic3x_i2c_remove(struct i2c_client *client)
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001410{
Ben Dookscb3826f2009-08-20 22:50:41 +01001411 struct aic3x_priv *aic3x = i2c_get_clientdata(client);
1412
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001413 if (aic3x->gpio_reset >= 0) {
1414 gpio_set_value(aic3x->gpio_reset, 0);
1415 gpio_free(aic3x->gpio_reset);
1416 }
1417 regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
1418 regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
1419
1420 snd_soc_unregister_codec(&client->dev);
1421 kfree(i2c_get_clientdata(client));
1422 return 0;
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001423}
1424
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001425/* machine i2c codec control layer */
1426static struct i2c_driver aic3x_i2c_driver = {
1427 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001428 .name = "tlv320aic3x-codec",
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001429 .owner = THIS_MODULE,
1430 },
Ben Dookscb3826f2009-08-20 22:50:41 +01001431 .probe = aic3x_i2c_probe,
Jean Delvareba8ed122008-09-22 14:15:53 +02001432 .remove = aic3x_i2c_remove,
1433 .id_table = aic3x_i2c_id,
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001434};
Daniel Mack54e7e612008-04-30 16:20:52 +02001435
Ben Dookscb3826f2009-08-20 22:50:41 +01001436static inline void aic3x_i2c_init(void)
Jean Delvareba8ed122008-09-22 14:15:53 +02001437{
Jean Delvareba8ed122008-09-22 14:15:53 +02001438 int ret;
1439
1440 ret = i2c_add_driver(&aic3x_i2c_driver);
Ben Dookscb3826f2009-08-20 22:50:41 +01001441 if (ret)
1442 printk(KERN_ERR "%s: error regsitering i2c driver, %d\n",
1443 __func__, ret);
Jean Delvareba8ed122008-09-22 14:15:53 +02001444}
Ben Dookscb3826f2009-08-20 22:50:41 +01001445
1446static inline void aic3x_i2c_exit(void)
1447{
1448 i2c_del_driver(&aic3x_i2c_driver);
1449}
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001450#endif
1451
Takashi Iwaic9b3a402008-12-10 07:47:22 +01001452static int __init aic3x_modinit(void)
Mark Brown64089b82008-12-08 19:17:58 +00001453{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001454 int ret = 0;
1455#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1456 ret = i2c_add_driver(&aic3x_i2c_driver);
1457 if (ret != 0) {
1458 printk(KERN_ERR "Failed to register TLV320AIC3x I2C driver: %d\n",
1459 ret);
1460 }
1461#endif
1462 return ret;
Mark Brown64089b82008-12-08 19:17:58 +00001463}
1464module_init(aic3x_modinit);
1465
1466static void __exit aic3x_exit(void)
1467{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001468#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1469 i2c_del_driver(&aic3x_i2c_driver);
1470#endif
Mark Brown64089b82008-12-08 19:17:58 +00001471}
1472module_exit(aic3x_exit);
1473
Vladimir Barinov44d0a872007-11-14 17:07:17 +01001474MODULE_DESCRIPTION("ASoC TLV320AIC3X codec driver");
1475MODULE_AUTHOR("Vladimir Barinov");
1476MODULE_LICENSE("GPL");