blob: 649f219c2b9ecfdca1989106f686a4a3e732242e [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12#include <linux/module.h>
13#include <linux/init.h>
Bradley Rubin229c6a52011-07-12 16:18:48 -070014#include <linux/firmware.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070015#include <linux/slab.h>
16#include <linux/platform_device.h>
17#include <linux/printk.h>
18#include <linux/ratelimit.h>
Bradley Rubincb3950a2011-08-18 13:07:26 -070019#include <linux/debugfs.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070020#include <linux/mfd/wcd9310/core.h>
21#include <linux/mfd/wcd9310/registers.h>
Patrick Lai3043fba2011-08-01 14:15:57 -070022#include <linux/mfd/wcd9310/pdata.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070023#include <sound/jack.h>
24#include <sound/soc.h>
25#include <sound/soc-dapm.h>
26#include <sound/tlv.h>
27#include <linux/bitops.h>
28#include <linux/delay.h>
29#include "wcd9310.h"
30
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -070031#define WCD9310_RATES (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|\
32 SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_48000)
33
34#define NUM_DECIMATORS 10
35#define NUM_INTERPOLATORS 7
36#define BITS_PER_REG 8
37#define TABLA_RX_DAI_ID 1
38#define TABLA_TX_DAI_ID 2
39
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070040static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
41static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
42static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
43
44enum tabla_bandgap_type {
45 TABLA_BANDGAP_OFF = 0,
46 TABLA_BANDGAP_AUDIO_MODE,
47 TABLA_BANDGAP_MBHC_MODE,
48};
49
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -070050struct mbhc_micbias_regs {
51 u16 cfilt_val;
52 u16 cfilt_ctl;
53 u16 mbhc_reg;
54 u16 int_rbias;
55 u16 ctl_reg;
56};
57
Bradley Rubin229c6a52011-07-12 16:18:48 -070058struct tabla_priv {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059 struct snd_soc_codec *codec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060 u32 adc_count;
Patrick Lai3043fba2011-08-01 14:15:57 -070061 u32 cfilt1_cnt;
62 u32 cfilt2_cnt;
63 u32 cfilt3_cnt;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -070064 u32 rx_bias_count;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070065 enum tabla_bandgap_type bandgap_type;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -070066 bool mclk_enabled;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070067 bool clock_active;
68 bool config_mode_active;
69 bool mbhc_polling_active;
Bradley Rubincb1e2732011-06-23 16:49:20 -070070 int buttons_pressed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070071
72 struct tabla_mbhc_calibration *calibration;
73
Bradley Rubincb1e2732011-06-23 16:49:20 -070074 struct snd_soc_jack *headset_jack;
75 struct snd_soc_jack *button_jack;
Bradley Rubin229c6a52011-07-12 16:18:48 -070076
Patrick Lai3043fba2011-08-01 14:15:57 -070077 struct tabla_pdata *pdata;
Bradley Rubina7096d02011-08-03 18:29:02 -070078 u32 anc_slot;
Bradley Rubincb3950a2011-08-18 13:07:26 -070079
80 bool no_mic_headset_override;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -070081 /* Delayed work to report long button press */
82 struct delayed_work btn0_dwork;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -070083
84 struct mbhc_micbias_regs mbhc_bias_regs;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -070085 u8 cfilt_k_value;
86 bool mbhc_micbias_switched;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070087};
88
Bradley Rubincb3950a2011-08-18 13:07:26 -070089#ifdef CONFIG_DEBUG_FS
90struct tabla_priv *debug_tabla_priv;
91#endif
92
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070093static int tabla_codec_enable_charge_pump(struct snd_soc_dapm_widget *w,
94 struct snd_kcontrol *kcontrol, int event)
95{
96 struct snd_soc_codec *codec = w->codec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070097
98 pr_debug("%s %d\n", __func__, event);
99 switch (event) {
100 case SND_SOC_DAPM_POST_PMU:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700101 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
102 0x01);
103 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x08);
104 usleep_range(200, 200);
105 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x00);
106 break;
107 case SND_SOC_DAPM_PRE_PMD:
108 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10,
109 0x10);
110 usleep_range(20, 20);
111 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x08);
112 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x10);
113 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x00);
114 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
115 0x00);
116 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700117 break;
118 }
119 return 0;
120}
121
Bradley Rubina7096d02011-08-03 18:29:02 -0700122static int tabla_get_anc_slot(struct snd_kcontrol *kcontrol,
123 struct snd_ctl_elem_value *ucontrol)
124{
125 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
126 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
127 ucontrol->value.integer.value[0] = tabla->anc_slot;
128 return 0;
129}
130
131static int tabla_put_anc_slot(struct snd_kcontrol *kcontrol,
132 struct snd_ctl_elem_value *ucontrol)
133{
134 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
135 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
136 tabla->anc_slot = ucontrol->value.integer.value[0];
137 return 0;
138}
139
Kiran Kandid2d86b52011-09-09 17:44:28 -0700140static int tabla_pa_gain_get(struct snd_kcontrol *kcontrol,
141 struct snd_ctl_elem_value *ucontrol)
142{
143 u8 ear_pa_gain;
144 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
145
146 ear_pa_gain = snd_soc_read(codec, TABLA_A_RX_EAR_GAIN);
147
148 ear_pa_gain = ear_pa_gain >> 5;
149
150 if (ear_pa_gain == 0x00) {
151 ucontrol->value.integer.value[0] = 0;
152 } else if (ear_pa_gain == 0x04) {
153 ucontrol->value.integer.value[0] = 1;
154 } else {
155 pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n",
156 __func__, ear_pa_gain);
157 return -EINVAL;
158 }
159
160 pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain);
161
162 return 0;
163}
164
165static int tabla_pa_gain_put(struct snd_kcontrol *kcontrol,
166 struct snd_ctl_elem_value *ucontrol)
167{
168 u8 ear_pa_gain;
169 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
170
171 pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__,
172 ucontrol->value.integer.value[0]);
173
174 switch (ucontrol->value.integer.value[0]) {
175 case 0:
176 ear_pa_gain = 0x00;
177 break;
178 case 1:
179 ear_pa_gain = 0x80;
180 break;
181 default:
182 return -EINVAL;
183 }
184
185 snd_soc_update_bits(codec, TABLA_A_RX_EAR_GAIN, 0xE0, ear_pa_gain);
186 return 0;
187}
188
189static const char *tabla_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"};
190static const struct soc_enum tabla_ear_pa_gain_enum[] = {
191 SOC_ENUM_SINGLE_EXT(2, tabla_ear_pa_gain_text),
192};
193
Santosh Mardi024010f2011-10-18 06:27:21 +0530194/*cut of frequency for high pass filter*/
195static const char *cf_text[] = {
196 "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz"
197};
198
199static const struct soc_enum cf_dec1_enum =
200 SOC_ENUM_SINGLE(TABLA_A_CDC_TX1_MUX_CTL, 4, 3, cf_text);
201
202static const struct soc_enum cf_dec2_enum =
203 SOC_ENUM_SINGLE(TABLA_A_CDC_TX2_MUX_CTL, 4, 3, cf_text);
204
205static const struct soc_enum cf_dec3_enum =
206 SOC_ENUM_SINGLE(TABLA_A_CDC_TX3_MUX_CTL, 4, 3, cf_text);
207
208static const struct soc_enum cf_dec4_enum =
209 SOC_ENUM_SINGLE(TABLA_A_CDC_TX4_MUX_CTL, 4, 3, cf_text);
210
211static const struct soc_enum cf_dec5_enum =
212 SOC_ENUM_SINGLE(TABLA_A_CDC_TX5_MUX_CTL, 4, 3, cf_text);
213
214static const struct soc_enum cf_dec6_enum =
215 SOC_ENUM_SINGLE(TABLA_A_CDC_TX6_MUX_CTL, 4, 3, cf_text);
216
217static const struct soc_enum cf_dec7_enum =
218 SOC_ENUM_SINGLE(TABLA_A_CDC_TX7_MUX_CTL, 4, 3, cf_text);
219
220static const struct soc_enum cf_dec8_enum =
221 SOC_ENUM_SINGLE(TABLA_A_CDC_TX8_MUX_CTL, 4, 3, cf_text);
222
223static const struct soc_enum cf_dec9_enum =
224 SOC_ENUM_SINGLE(TABLA_A_CDC_TX9_MUX_CTL, 4, 3, cf_text);
225
226static const struct soc_enum cf_dec10_enum =
227 SOC_ENUM_SINGLE(TABLA_A_CDC_TX10_MUX_CTL, 4, 3, cf_text);
228
229static const struct soc_enum cf_rxmix1_enum =
230 SOC_ENUM_SINGLE(TABLA_A_CDC_RX1_B4_CTL, 1, 3, cf_text);
231
232static const struct soc_enum cf_rxmix2_enum =
233 SOC_ENUM_SINGLE(TABLA_A_CDC_RX2_B4_CTL, 1, 3, cf_text);
234
235static const struct soc_enum cf_rxmix3_enum =
236 SOC_ENUM_SINGLE(TABLA_A_CDC_RX3_B4_CTL, 1, 3, cf_text);
237
238static const struct soc_enum cf_rxmix4_enum =
239 SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B4_CTL, 1, 3, cf_text);
240
241static const struct soc_enum cf_rxmix5_enum =
242 SOC_ENUM_SINGLE(TABLA_A_CDC_RX5_B4_CTL, 1, 3, cf_text)
243;
244static const struct soc_enum cf_rxmix6_enum =
245 SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B4_CTL, 1, 3, cf_text);
246
247static const struct soc_enum cf_rxmix7_enum =
248 SOC_ENUM_SINGLE(TABLA_A_CDC_RX7_B4_CTL, 1, 3, cf_text);
249
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700250static const struct snd_kcontrol_new tabla_snd_controls[] = {
Kiran Kandid2d86b52011-09-09 17:44:28 -0700251
252 SOC_ENUM_EXT("EAR PA Gain", tabla_ear_pa_gain_enum[0],
253 tabla_pa_gain_get, tabla_pa_gain_put),
254
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700255 SOC_SINGLE_TLV("LINEOUT1 Volume", TABLA_A_RX_LINE_1_GAIN, 0, 12, 1,
256 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700257 SOC_SINGLE_TLV("LINEOUT2 Volume", TABLA_A_RX_LINE_2_GAIN, 0, 12, 1,
258 line_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700259 SOC_SINGLE_TLV("LINEOUT3 Volume", TABLA_A_RX_LINE_3_GAIN, 0, 12, 1,
260 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700261 SOC_SINGLE_TLV("LINEOUT4 Volume", TABLA_A_RX_LINE_4_GAIN, 0, 12, 1,
262 line_gain),
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -0700263 SOC_SINGLE_TLV("LINEOUT5 Volume", TABLA_A_RX_LINE_5_GAIN, 0, 12, 1,
264 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700265
266 SOC_SINGLE("RX1 CHAIN INVERT Switch", TABLA_A_CDC_RX1_B6_CTL, 4, 1, 0),
267 SOC_SINGLE("RX2 CHAIN INVERT Switch", TABLA_A_CDC_RX2_B6_CTL, 4, 1, 0),
268 SOC_SINGLE("RX3 CHAIN INVERT Switch", TABLA_A_CDC_RX3_B6_CTL, 4, 1, 0),
269 SOC_SINGLE("RX4 CHAIN INVERT Switch", TABLA_A_CDC_RX4_B6_CTL, 4, 1, 0),
270 SOC_SINGLE("RX5 CHAIN INVERT Switch", TABLA_A_CDC_RX5_B6_CTL, 4, 1, 0),
271 SOC_SINGLE("RX6 CHAIN INVERT Switch", TABLA_A_CDC_RX6_B6_CTL, 4, 1, 0),
272
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700273 SOC_SINGLE_TLV("HPHL Volume", TABLA_A_RX_HPH_L_GAIN, 0, 12, 1,
274 line_gain),
275 SOC_SINGLE_TLV("HPHR Volume", TABLA_A_RX_HPH_R_GAIN, 0, 12, 1,
276 line_gain),
277
Bradley Rubin410383f2011-07-22 13:44:23 -0700278 SOC_SINGLE_S8_TLV("RX1 Digital Volume", TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
279 -84, 40, digital_gain),
280 SOC_SINGLE_S8_TLV("RX2 Digital Volume", TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
281 -84, 40, digital_gain),
282 SOC_SINGLE_S8_TLV("RX3 Digital Volume", TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
283 -84, 40, digital_gain),
284 SOC_SINGLE_S8_TLV("RX4 Digital Volume", TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
285 -84, 40, digital_gain),
286 SOC_SINGLE_S8_TLV("RX5 Digital Volume", TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
287 -84, 40, digital_gain),
288 SOC_SINGLE_S8_TLV("RX6 Digital Volume", TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
289 -84, 40, digital_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700290
Bradley Rubin410383f2011-07-22 13:44:23 -0700291 SOC_SINGLE_S8_TLV("DEC1 Volume", TABLA_A_CDC_TX1_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700292 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -0700293 SOC_SINGLE_S8_TLV("DEC2 Volume", TABLA_A_CDC_TX2_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700294 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -0700295 SOC_SINGLE_S8_TLV("DEC3 Volume", TABLA_A_CDC_TX3_VOL_CTL_GAIN, -84, 40,
296 digital_gain),
297 SOC_SINGLE_S8_TLV("DEC4 Volume", TABLA_A_CDC_TX4_VOL_CTL_GAIN, -84, 40,
298 digital_gain),
299 SOC_SINGLE_S8_TLV("DEC5 Volume", TABLA_A_CDC_TX5_VOL_CTL_GAIN, -84, 40,
300 digital_gain),
301 SOC_SINGLE_S8_TLV("DEC6 Volume", TABLA_A_CDC_TX6_VOL_CTL_GAIN, -84, 40,
302 digital_gain),
303 SOC_SINGLE_S8_TLV("DEC7 Volume", TABLA_A_CDC_TX7_VOL_CTL_GAIN, -84, 40,
304 digital_gain),
305 SOC_SINGLE_S8_TLV("DEC8 Volume", TABLA_A_CDC_TX8_VOL_CTL_GAIN, -84, 40,
306 digital_gain),
307 SOC_SINGLE_S8_TLV("DEC9 Volume", TABLA_A_CDC_TX9_VOL_CTL_GAIN, -84, 40,
308 digital_gain),
309 SOC_SINGLE_S8_TLV("DEC10 Volume", TABLA_A_CDC_TX10_VOL_CTL_GAIN, -84,
310 40, digital_gain),
Patrick Lai29006372011-09-28 17:57:42 -0700311 SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TABLA_A_CDC_IIR1_GAIN_B1_CTL, -84,
312 40, digital_gain),
313 SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TABLA_A_CDC_IIR1_GAIN_B2_CTL, -84,
314 40, digital_gain),
315 SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TABLA_A_CDC_IIR1_GAIN_B3_CTL, -84,
316 40, digital_gain),
317 SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TABLA_A_CDC_IIR1_GAIN_B4_CTL, -84,
318 40, digital_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700319 SOC_SINGLE_TLV("ADC1 Volume", TABLA_A_TX_1_2_EN, 5, 3, 0, analog_gain),
320 SOC_SINGLE_TLV("ADC2 Volume", TABLA_A_TX_1_2_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700321 SOC_SINGLE_TLV("ADC3 Volume", TABLA_A_TX_3_4_EN, 5, 3, 0, analog_gain),
322 SOC_SINGLE_TLV("ADC4 Volume", TABLA_A_TX_3_4_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700323 SOC_SINGLE_TLV("ADC5 Volume", TABLA_A_TX_5_6_EN, 5, 3, 0, analog_gain),
324 SOC_SINGLE_TLV("ADC6 Volume", TABLA_A_TX_5_6_EN, 1, 3, 0, analog_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700325
326 SOC_SINGLE("MICBIAS1 CAPLESS Switch", TABLA_A_MICB_1_CTL, 4, 1, 1),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700327 SOC_SINGLE("MICBIAS3 CAPLESS Switch", TABLA_A_MICB_3_CTL, 4, 1, 1),
328 SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_A_MICB_4_CTL, 4, 1, 1),
Bradley Rubina7096d02011-08-03 18:29:02 -0700329
330 SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 0, 100, tabla_get_anc_slot,
331 tabla_put_anc_slot),
Santosh Mardi024010f2011-10-18 06:27:21 +0530332 SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
333 SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
334 SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
335 SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
336 SOC_ENUM("TX5 HPF cut off", cf_dec5_enum),
337 SOC_ENUM("TX6 HPF cut off", cf_dec6_enum),
338 SOC_ENUM("TX7 HPF cut off", cf_dec7_enum),
339 SOC_ENUM("TX8 HPF cut off", cf_dec8_enum),
340 SOC_ENUM("TX9 HPF cut off", cf_dec9_enum),
341 SOC_ENUM("TX10 HPF cut off", cf_dec10_enum),
342
343 SOC_SINGLE("TX1 HPF Switch", TABLA_A_CDC_TX1_MUX_CTL, 3, 1, 0),
344 SOC_SINGLE("TX2 HPF Switch", TABLA_A_CDC_TX2_MUX_CTL, 3, 1, 0),
345 SOC_SINGLE("TX3 HPF Switch", TABLA_A_CDC_TX3_MUX_CTL, 3, 1, 0),
346 SOC_SINGLE("TX4 HPF Switch", TABLA_A_CDC_TX4_MUX_CTL, 3, 1, 0),
347 SOC_SINGLE("TX5 HPF Switch", TABLA_A_CDC_TX5_MUX_CTL, 3, 1, 0),
348 SOC_SINGLE("TX6 HPF Switch", TABLA_A_CDC_TX6_MUX_CTL, 3, 1, 0),
349 SOC_SINGLE("TX7 HPF Switch", TABLA_A_CDC_TX7_MUX_CTL, 3, 1, 0),
350 SOC_SINGLE("TX8 HPF Switch", TABLA_A_CDC_TX8_MUX_CTL, 3, 1, 0),
351 SOC_SINGLE("TX9 HPF Switch", TABLA_A_CDC_TX9_MUX_CTL, 3, 1, 0),
352 SOC_SINGLE("TX10 HPF Switch", TABLA_A_CDC_TX10_MUX_CTL, 3, 1, 0),
353
354 SOC_SINGLE("RX1 HPF Switch", TABLA_A_CDC_RX1_B5_CTL, 2, 1, 0),
355 SOC_SINGLE("RX2 HPF Switch", TABLA_A_CDC_RX2_B5_CTL, 2, 1, 0),
356 SOC_SINGLE("RX3 HPF Switch", TABLA_A_CDC_RX3_B5_CTL, 2, 1, 0),
357 SOC_SINGLE("RX4 HPF Switch", TABLA_A_CDC_RX4_B5_CTL, 2, 1, 0),
358 SOC_SINGLE("RX5 HPF Switch", TABLA_A_CDC_RX5_B5_CTL, 2, 1, 0),
359 SOC_SINGLE("RX6 HPF Switch", TABLA_A_CDC_RX6_B5_CTL, 2, 1, 0),
360 SOC_SINGLE("RX7 HPF Switch", TABLA_A_CDC_RX7_B5_CTL, 2, 1, 0),
361
362 SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum),
363 SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum),
364 SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum),
365 SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum),
366 SOC_ENUM("RX5 HPF cut off", cf_rxmix5_enum),
367 SOC_ENUM("RX6 HPF cut off", cf_rxmix6_enum),
368 SOC_ENUM("RX7 HPF cut off", cf_rxmix7_enum),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700369};
370
371static const char *rx_mix1_text[] = {
372 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
373 "RX5", "RX6", "RX7"
374};
375
376static const char *sb_tx1_mux_text[] = {
377 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
378 "DEC1"
379};
380
381static const char *sb_tx5_mux_text[] = {
382 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
383 "DEC5"
384};
385
386static const char *sb_tx6_mux_text[] = {
387 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
388 "DEC6"
389};
390
391static const char const *sb_tx7_to_tx10_mux_text[] = {
392 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
393 "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
394 "DEC9", "DEC10"
395};
396
397static const char *dec1_mux_text[] = {
398 "ZERO", "DMIC1", "ADC6",
399};
400
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700401static const char *dec2_mux_text[] = {
402 "ZERO", "DMIC2", "ADC5",
403};
404
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700405static const char *dec3_mux_text[] = {
406 "ZERO", "DMIC3", "ADC4",
407};
408
409static const char *dec4_mux_text[] = {
410 "ZERO", "DMIC4", "ADC3",
411};
412
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700413static const char *dec5_mux_text[] = {
414 "ZERO", "DMIC5", "ADC2",
415};
416
417static const char *dec6_mux_text[] = {
418 "ZERO", "DMIC6", "ADC1",
419};
420
421static const char const *dec7_mux_text[] = {
422 "ZERO", "DMIC1", "DMIC6", "ADC1", "ADC6", "ANC1_FB", "ANC2_FB",
423};
424
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700425static const char *dec8_mux_text[] = {
426 "ZERO", "DMIC2", "DMIC5", "ADC2", "ADC5",
427};
428
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700429static const char *dec9_mux_text[] = {
430 "ZERO", "DMIC4", "DMIC5", "ADC2", "ADC3", "ADCMB", "ANC1_FB", "ANC2_FB",
431};
432
433static const char *dec10_mux_text[] = {
434 "ZERO", "DMIC3", "DMIC6", "ADC1", "ADC4", "ADCMB", "ANC1_FB", "ANC2_FB",
435};
436
Bradley Rubin229c6a52011-07-12 16:18:48 -0700437static const char const *anc_mux_text[] = {
438 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6", "ADC_MB",
439 "RSVD_1", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", "DMIC6"
440};
441
442static const char const *anc1_fb_mux_text[] = {
443 "ZERO", "EAR_HPH_L", "EAR_LINE_1",
444};
445
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700446static const char *iir1_inp1_text[] = {
447 "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
448 "DEC9", "DEC10", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7"
449};
450
451static const struct soc_enum rx_mix1_inp1_chain_enum =
452 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_mix1_text);
453
Bradley Rubin229c6a52011-07-12 16:18:48 -0700454static const struct soc_enum rx_mix1_inp2_chain_enum =
455 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_mix1_text);
456
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700457static const struct soc_enum rx2_mix1_inp1_chain_enum =
458 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_mix1_text);
459
Bradley Rubin229c6a52011-07-12 16:18:48 -0700460static const struct soc_enum rx2_mix1_inp2_chain_enum =
461 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_mix1_text);
462
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700463static const struct soc_enum rx3_mix1_inp1_chain_enum =
464 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 0, 12, rx_mix1_text);
465
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700466static const struct soc_enum rx3_mix1_inp2_chain_enum =
467 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 4, 12, rx_mix1_text);
468
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700469static const struct soc_enum rx4_mix1_inp1_chain_enum =
470 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 0, 12, rx_mix1_text);
471
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700472static const struct soc_enum rx4_mix1_inp2_chain_enum =
473 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 4, 12, rx_mix1_text);
474
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700475static const struct soc_enum rx5_mix1_inp1_chain_enum =
476 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 0, 12, rx_mix1_text);
477
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700478static const struct soc_enum rx5_mix1_inp2_chain_enum =
479 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 4, 12, rx_mix1_text);
480
481static const struct soc_enum rx6_mix1_inp1_chain_enum =
482 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 0, 12, rx_mix1_text);
483
484static const struct soc_enum rx6_mix1_inp2_chain_enum =
485 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 4, 12, rx_mix1_text);
486
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -0700487static const struct soc_enum rx7_mix1_inp1_chain_enum =
488 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 0, 12, rx_mix1_text);
489
490static const struct soc_enum rx7_mix1_inp2_chain_enum =
491 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 4, 12, rx_mix1_text);
492
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700493static const struct soc_enum sb_tx5_mux_enum =
494 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text);
495
496static const struct soc_enum sb_tx6_mux_enum =
497 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0, 9, sb_tx6_mux_text);
498
499static const struct soc_enum sb_tx7_mux_enum =
500 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0, 18,
501 sb_tx7_to_tx10_mux_text);
502
503static const struct soc_enum sb_tx8_mux_enum =
504 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0, 18,
505 sb_tx7_to_tx10_mux_text);
506
507static const struct soc_enum sb_tx1_mux_enum =
508 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text);
509
510static const struct soc_enum dec1_mux_enum =
511 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 0, 3, dec1_mux_text);
512
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700513static const struct soc_enum dec2_mux_enum =
514 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 2, 3, dec2_mux_text);
515
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700516static const struct soc_enum dec3_mux_enum =
517 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 4, 3, dec3_mux_text);
518
519static const struct soc_enum dec4_mux_enum =
520 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 6, 3, dec4_mux_text);
521
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700522static const struct soc_enum dec5_mux_enum =
523 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 0, 3, dec5_mux_text);
524
525static const struct soc_enum dec6_mux_enum =
526 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 2, 3, dec6_mux_text);
527
528static const struct soc_enum dec7_mux_enum =
529 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 4, 7, dec7_mux_text);
530
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700531static const struct soc_enum dec8_mux_enum =
532 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 0, 7, dec8_mux_text);
533
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700534static const struct soc_enum dec9_mux_enum =
535 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 3, 8, dec9_mux_text);
536
537static const struct soc_enum dec10_mux_enum =
538 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B4_CTL, 0, 8, dec10_mux_text);
539
Bradley Rubin229c6a52011-07-12 16:18:48 -0700540static const struct soc_enum anc1_mux_enum =
541 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 0, 16, anc_mux_text);
542
543static const struct soc_enum anc2_mux_enum =
544 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 4, 16, anc_mux_text);
545
546static const struct soc_enum anc1_fb_mux_enum =
547 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text);
548
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700549static const struct soc_enum iir1_inp1_mux_enum =
550 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ1_B1_CTL, 0, 18, iir1_inp1_text);
551
552static const struct snd_kcontrol_new rx_mix1_inp1_mux =
553 SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum);
554
Bradley Rubin229c6a52011-07-12 16:18:48 -0700555static const struct snd_kcontrol_new rx_mix1_inp2_mux =
556 SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum);
557
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700558static const struct snd_kcontrol_new rx2_mix1_inp1_mux =
559 SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum);
560
Bradley Rubin229c6a52011-07-12 16:18:48 -0700561static const struct snd_kcontrol_new rx2_mix1_inp2_mux =
562 SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum);
563
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700564static const struct snd_kcontrol_new rx3_mix1_inp1_mux =
565 SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum);
566
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700567static const struct snd_kcontrol_new rx3_mix1_inp2_mux =
568 SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum);
569
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700570static const struct snd_kcontrol_new rx4_mix1_inp1_mux =
571 SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum);
572
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700573static const struct snd_kcontrol_new rx4_mix1_inp2_mux =
574 SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum);
575
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700576static const struct snd_kcontrol_new rx5_mix1_inp1_mux =
577 SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum);
578
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700579static const struct snd_kcontrol_new rx5_mix1_inp2_mux =
580 SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum);
581
582static const struct snd_kcontrol_new rx6_mix1_inp1_mux =
583 SOC_DAPM_ENUM("RX6 MIX1 INP1 Mux", rx6_mix1_inp1_chain_enum);
584
585static const struct snd_kcontrol_new rx6_mix1_inp2_mux =
586 SOC_DAPM_ENUM("RX6 MIX1 INP2 Mux", rx6_mix1_inp2_chain_enum);
587
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -0700588static const struct snd_kcontrol_new rx7_mix1_inp1_mux =
589 SOC_DAPM_ENUM("RX7 MIX1 INP1 Mux", rx7_mix1_inp1_chain_enum);
590
591static const struct snd_kcontrol_new rx7_mix1_inp2_mux =
592 SOC_DAPM_ENUM("RX7 MIX1 INP2 Mux", rx7_mix1_inp2_chain_enum);
593
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700594static const struct snd_kcontrol_new sb_tx5_mux =
595 SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum);
596
597static const struct snd_kcontrol_new sb_tx6_mux =
598 SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum);
599
600static const struct snd_kcontrol_new sb_tx7_mux =
601 SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum);
602
603static const struct snd_kcontrol_new sb_tx8_mux =
604 SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum);
605
606static const struct snd_kcontrol_new sb_tx1_mux =
607 SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum);
608
609static const struct snd_kcontrol_new dec1_mux =
610 SOC_DAPM_ENUM("DEC1 MUX Mux", dec1_mux_enum);
611
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700612static const struct snd_kcontrol_new dec2_mux =
613 SOC_DAPM_ENUM("DEC2 MUX Mux", dec2_mux_enum);
614
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700615static const struct snd_kcontrol_new dec3_mux =
616 SOC_DAPM_ENUM("DEC3 MUX Mux", dec3_mux_enum);
617
618static const struct snd_kcontrol_new dec4_mux =
619 SOC_DAPM_ENUM("DEC4 MUX Mux", dec4_mux_enum);
620
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700621static const struct snd_kcontrol_new dec5_mux =
622 SOC_DAPM_ENUM("DEC5 MUX Mux", dec5_mux_enum);
623
624static const struct snd_kcontrol_new dec6_mux =
625 SOC_DAPM_ENUM("DEC6 MUX Mux", dec6_mux_enum);
626
627static const struct snd_kcontrol_new dec7_mux =
628 SOC_DAPM_ENUM("DEC7 MUX Mux", dec7_mux_enum);
629
Bradley Rubin229c6a52011-07-12 16:18:48 -0700630static const struct snd_kcontrol_new anc1_mux =
631 SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum);
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700632static const struct snd_kcontrol_new dec8_mux =
633 SOC_DAPM_ENUM("DEC8 MUX Mux", dec8_mux_enum);
634
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700635static const struct snd_kcontrol_new dec9_mux =
636 SOC_DAPM_ENUM("DEC9 MUX Mux", dec9_mux_enum);
637
638static const struct snd_kcontrol_new dec10_mux =
639 SOC_DAPM_ENUM("DEC10 MUX Mux", dec10_mux_enum);
640
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700641static const struct snd_kcontrol_new iir1_inp1_mux =
642 SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum);
643
Bradley Rubin229c6a52011-07-12 16:18:48 -0700644static const struct snd_kcontrol_new anc2_mux =
645 SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700646
Bradley Rubin229c6a52011-07-12 16:18:48 -0700647static const struct snd_kcontrol_new anc1_fb_mux =
648 SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700649
Bradley Rubin229c6a52011-07-12 16:18:48 -0700650static const struct snd_kcontrol_new dac1_switch[] = {
651 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_EAR_EN, 5, 1, 0)
652};
653static const struct snd_kcontrol_new hphl_switch[] = {
654 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_HPH_L_DAC_CTL, 6, 1, 0)
655};
656static const struct snd_kcontrol_new hphr_switch[] = {
657 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_HPH_R_DAC_CTL, 6, 1, 0)
658};
659static const struct snd_kcontrol_new lineout1_switch[] = {
660 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_1_DAC_CTL, 6, 1, 0)
661};
662static const struct snd_kcontrol_new lineout2_switch[] = {
663 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_2_DAC_CTL, 6, 1, 0)
664};
665static const struct snd_kcontrol_new lineout3_switch[] = {
666 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_3_DAC_CTL, 6, 1, 0)
667};
668static const struct snd_kcontrol_new lineout4_switch[] = {
669 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_4_DAC_CTL, 6, 1, 0)
670};
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -0700671static const struct snd_kcontrol_new lineout5_switch[] = {
672 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_5_DAC_CTL, 6, 1, 0)
673};
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700674
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700675static void tabla_codec_enable_adc_block(struct snd_soc_codec *codec,
676 int enable)
677{
678 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
679
680 pr_debug("%s %d\n", __func__, enable);
681
682 if (enable) {
683 tabla->adc_count++;
684 snd_soc_update_bits(codec, TABLA_A_TX_COM_BIAS, 0xE0, 0xE0);
685 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x2, 0x2);
686 } else {
687 tabla->adc_count--;
688 if (!tabla->adc_count) {
689 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL,
690 0x2, 0x0);
691 if (!tabla->mbhc_polling_active)
692 snd_soc_update_bits(codec, TABLA_A_TX_COM_BIAS,
693 0xE0, 0x0);
694 }
695 }
696}
697
698static int tabla_codec_enable_adc(struct snd_soc_dapm_widget *w,
699 struct snd_kcontrol *kcontrol, int event)
700{
701 struct snd_soc_codec *codec = w->codec;
702 u16 adc_reg;
703
704 pr_debug("%s %d\n", __func__, event);
705
706 if (w->reg == TABLA_A_TX_1_2_EN)
707 adc_reg = TABLA_A_TX_1_2_TEST_CTL;
708 else if (w->reg == TABLA_A_TX_3_4_EN)
709 adc_reg = TABLA_A_TX_3_4_TEST_CTL;
710 else if (w->reg == TABLA_A_TX_5_6_EN)
711 adc_reg = TABLA_A_TX_5_6_TEST_CTL;
712 else {
713 pr_err("%s: Error, invalid adc register\n", __func__);
714 return -EINVAL;
715 }
716
717 switch (event) {
718 case SND_SOC_DAPM_PRE_PMU:
719 tabla_codec_enable_adc_block(codec, 1);
720 break;
721 case SND_SOC_DAPM_POST_PMU:
722 snd_soc_update_bits(codec, adc_reg, 1 << w->shift,
723 1 << w->shift);
724 usleep_range(1000, 1000);
725 snd_soc_update_bits(codec, adc_reg, 1 << w->shift, 0x00);
726 usleep_range(1000, 1000);
727 break;
728 case SND_SOC_DAPM_POST_PMD:
729 tabla_codec_enable_adc_block(codec, 0);
730 break;
731 }
732 return 0;
733}
734
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700735static int tabla_codec_enable_lineout(struct snd_soc_dapm_widget *w,
736 struct snd_kcontrol *kcontrol, int event)
737{
738 struct snd_soc_codec *codec = w->codec;
739 u16 lineout_gain_reg;
740
Kiran Kandidb0a4b02011-08-23 09:32:09 -0700741 pr_debug("%s %d %s\n", __func__, event, w->name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700742
743 switch (w->shift) {
744 case 0:
745 lineout_gain_reg = TABLA_A_RX_LINE_1_GAIN;
746 break;
747 case 1:
748 lineout_gain_reg = TABLA_A_RX_LINE_2_GAIN;
749 break;
750 case 2:
751 lineout_gain_reg = TABLA_A_RX_LINE_3_GAIN;
752 break;
753 case 3:
754 lineout_gain_reg = TABLA_A_RX_LINE_4_GAIN;
755 break;
756 case 4:
757 lineout_gain_reg = TABLA_A_RX_LINE_5_GAIN;
758 break;
759 default:
760 pr_err("%s: Error, incorrect lineout register value\n",
761 __func__);
762 return -EINVAL;
763 }
764
765 switch (event) {
766 case SND_SOC_DAPM_PRE_PMU:
767 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40);
768 break;
769 case SND_SOC_DAPM_POST_PMU:
Kiran Kandidb0a4b02011-08-23 09:32:09 -0700770 pr_debug("%s: sleeping 40 ms after %s PA turn on\n",
771 __func__, w->name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700772 usleep_range(40000, 40000);
773 break;
774 case SND_SOC_DAPM_POST_PMD:
775 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00);
776 break;
777 }
778 return 0;
779}
780
Kiran Kandicf45f6a2011-07-17 21:10:19 -0700781
782static int tabla_codec_enable_dmic(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700783 struct snd_kcontrol *kcontrol, int event)
784{
785 struct snd_soc_codec *codec = w->codec;
Kiran Kandicf45f6a2011-07-17 21:10:19 -0700786 u16 tx_mux_ctl_reg, tx_dmic_ctl_reg;
787 u8 dmic_clk_sel, dmic_clk_en;
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -0700788 unsigned int dmic;
789 int ret;
Kiran Kandicf45f6a2011-07-17 21:10:19 -0700790
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -0700791 ret = kstrtouint(strpbrk(w->name, "123456"), 10, &dmic);
792 if (ret < 0) {
793 pr_err("%s: Invalid DMIC line on the codec\n", __func__);
Kiran Kandicf45f6a2011-07-17 21:10:19 -0700794 return -EINVAL;
795 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700796
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -0700797 switch (dmic) {
798 case 1:
799 case 2:
800 dmic_clk_sel = 0x02;
801 dmic_clk_en = 0x01;
802 break;
803
804 case 3:
805 case 4:
806 dmic_clk_sel = 0x08;
807 dmic_clk_en = 0x04;
808 break;
809
810 case 5:
811 case 6:
812 dmic_clk_sel = 0x20;
813 dmic_clk_en = 0x10;
814 break;
815
816 default:
817 pr_err("%s: Invalid DMIC Selection\n", __func__);
818 return -EINVAL;
819 }
820
821 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (dmic - 1);
822 tx_dmic_ctl_reg = TABLA_A_CDC_TX1_DMIC_CTL + 8 * (dmic - 1);
823
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700824 pr_debug("%s %d\n", __func__, event);
Kiran Kandicf45f6a2011-07-17 21:10:19 -0700825
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700826 switch (event) {
827 case SND_SOC_DAPM_PRE_PMU:
Kiran Kandicf45f6a2011-07-17 21:10:19 -0700828 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, 0x1);
829
830 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
831 dmic_clk_sel, dmic_clk_sel);
832
833 snd_soc_update_bits(codec, tx_dmic_ctl_reg, 0x1, 0x1);
834
835 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
836 dmic_clk_en, dmic_clk_en);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700837 break;
838 case SND_SOC_DAPM_POST_PMD:
Kiran Kandicf45f6a2011-07-17 21:10:19 -0700839 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
840 dmic_clk_en, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700841 break;
842 }
843 return 0;
844}
845
Bradley Rubin229c6a52011-07-12 16:18:48 -0700846static int tabla_codec_enable_anc(struct snd_soc_dapm_widget *w,
847 struct snd_kcontrol *kcontrol, int event)
848{
849 struct snd_soc_codec *codec = w->codec;
850 const char *filename;
851 const struct firmware *fw;
852 int i;
853 int ret;
Bradley Rubina7096d02011-08-03 18:29:02 -0700854 int num_anc_slots;
855 struct anc_header *anc_head;
Bradley Rubin229c6a52011-07-12 16:18:48 -0700856 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubina7096d02011-08-03 18:29:02 -0700857 u32 anc_writes_size = 0;
858 int anc_size_remaining;
859 u32 *anc_ptr;
Bradley Rubin229c6a52011-07-12 16:18:48 -0700860 u16 reg;
861 u8 mask, val, old_val;
862
863 pr_debug("%s %d\n", __func__, event);
864 switch (event) {
865 case SND_SOC_DAPM_PRE_PMU:
866
Bradley Rubin4283a4c2011-07-29 16:18:54 -0700867 filename = "wcd9310/wcd9310_anc.bin";
Bradley Rubin229c6a52011-07-12 16:18:48 -0700868
869 ret = request_firmware(&fw, filename, codec->dev);
870 if (ret != 0) {
871 dev_err(codec->dev, "Failed to acquire ANC data: %d\n",
872 ret);
873 return -ENODEV;
874 }
875
Bradley Rubina7096d02011-08-03 18:29:02 -0700876 if (fw->size < sizeof(struct anc_header)) {
Bradley Rubin229c6a52011-07-12 16:18:48 -0700877 dev_err(codec->dev, "Not enough data\n");
878 release_firmware(fw);
879 return -ENOMEM;
880 }
881
882 /* First number is the number of register writes */
Bradley Rubina7096d02011-08-03 18:29:02 -0700883 anc_head = (struct anc_header *)(fw->data);
884 anc_ptr = (u32 *)((u32)fw->data + sizeof(struct anc_header));
885 anc_size_remaining = fw->size - sizeof(struct anc_header);
886 num_anc_slots = anc_head->num_anc_slots;
Bradley Rubin229c6a52011-07-12 16:18:48 -0700887
Bradley Rubina7096d02011-08-03 18:29:02 -0700888 if (tabla->anc_slot >= num_anc_slots) {
889 dev_err(codec->dev, "Invalid ANC slot selected\n");
890 release_firmware(fw);
891 return -EINVAL;
892 }
893
894 for (i = 0; i < num_anc_slots; i++) {
895
896 if (anc_size_remaining < TABLA_PACKED_REG_SIZE) {
897 dev_err(codec->dev, "Invalid register format\n");
898 release_firmware(fw);
899 return -EINVAL;
900 }
901 anc_writes_size = (u32)(*anc_ptr);
902 anc_size_remaining -= sizeof(u32);
903 anc_ptr += 1;
904
905 if (anc_writes_size * TABLA_PACKED_REG_SIZE
906 > anc_size_remaining) {
907 dev_err(codec->dev, "Invalid register format\n");
908 release_firmware(fw);
909 return -ENOMEM;
910 }
911
912 if (tabla->anc_slot == i)
913 break;
914
915 anc_size_remaining -= (anc_writes_size *
916 TABLA_PACKED_REG_SIZE);
Bradley Rubin939ff3f2011-08-26 17:19:34 -0700917 anc_ptr += anc_writes_size;
Bradley Rubina7096d02011-08-03 18:29:02 -0700918 }
919 if (i == num_anc_slots) {
920 dev_err(codec->dev, "Selected ANC slot not present\n");
Bradley Rubin229c6a52011-07-12 16:18:48 -0700921 release_firmware(fw);
922 return -ENOMEM;
923 }
924
Bradley Rubina7096d02011-08-03 18:29:02 -0700925 for (i = 0; i < anc_writes_size; i++) {
926 TABLA_CODEC_UNPACK_ENTRY(anc_ptr[i], reg,
Bradley Rubin229c6a52011-07-12 16:18:48 -0700927 mask, val);
928 old_val = snd_soc_read(codec, reg);
Bradley Rubin4283a4c2011-07-29 16:18:54 -0700929 snd_soc_write(codec, reg, (old_val & ~mask) |
930 (val & mask));
Bradley Rubin229c6a52011-07-12 16:18:48 -0700931 }
932 release_firmware(fw);
Bradley Rubin229c6a52011-07-12 16:18:48 -0700933
934 break;
935 case SND_SOC_DAPM_POST_PMD:
936 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0xFF);
937 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_CLK_EN_CTL, 0);
938 break;
939 }
940 return 0;
941}
942
Patrick Lai3043fba2011-08-01 14:15:57 -0700943static void tabla_codec_update_cfilt_usage(struct snd_soc_codec *codec,
944 u8 cfilt_sel, int inc)
945{
946 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
947 u32 *cfilt_cnt_ptr = NULL;
948 u16 micb_cfilt_reg;
949
950 switch (cfilt_sel) {
951 case TABLA_CFILT1_SEL:
952 cfilt_cnt_ptr = &tabla->cfilt1_cnt;
953 micb_cfilt_reg = TABLA_A_MICB_CFILT_1_CTL;
954 break;
955 case TABLA_CFILT2_SEL:
956 cfilt_cnt_ptr = &tabla->cfilt2_cnt;
957 micb_cfilt_reg = TABLA_A_MICB_CFILT_2_CTL;
958 break;
959 case TABLA_CFILT3_SEL:
960 cfilt_cnt_ptr = &tabla->cfilt3_cnt;
961 micb_cfilt_reg = TABLA_A_MICB_CFILT_3_CTL;
962 break;
963 default:
964 return; /* should not happen */
965 }
966
967 if (inc) {
968 if (!(*cfilt_cnt_ptr)++)
969 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80);
970 } else {
971 /* check if count not zero, decrement
972 * then check if zero, go ahead disable cfilter
973 */
974 if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr))
975 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0);
976 }
977}
Bradley Rubin229c6a52011-07-12 16:18:48 -0700978
Bradley Rubincb3950a2011-08-18 13:07:26 -0700979static void tabla_codec_disable_button_presses(struct snd_soc_codec *codec)
980{
981 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, 0x80);
982 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0x00);
983}
984
Bradley Rubin4d09cf42011-08-17 17:59:16 -0700985static void tabla_codec_start_hs_polling(struct snd_soc_codec *codec)
986{
Bradley Rubincb3950a2011-08-18 13:07:26 -0700987 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
988
Bradley Rubin4d09cf42011-08-17 17:59:16 -0700989 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Bradley Rubin4d09cf42011-08-17 17:59:16 -0700990 tabla_enable_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL);
Bradley Rubincb3950a2011-08-18 13:07:26 -0700991 if (!tabla->no_mic_headset_override) {
992 tabla_enable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
993 tabla_enable_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE);
994 } else {
995 tabla_codec_disable_button_presses(codec);
996 }
Bradley Rubin4d09cf42011-08-17 17:59:16 -0700997 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
998 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
999 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
1000}
1001
1002static void tabla_codec_pause_hs_polling(struct snd_soc_codec *codec)
1003{
Bradley Rubincb3950a2011-08-18 13:07:26 -07001004 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1005
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001006 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
1007 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL);
Bradley Rubincb3950a2011-08-18 13:07:26 -07001008 if (!tabla->no_mic_headset_override) {
1009 tabla_disable_irq(codec->control_data,
1010 TABLA_IRQ_MBHC_POTENTIAL);
1011 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE);
1012 }
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001013}
1014
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001015static int tabla_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv)
1016{
1017 int rc = -EINVAL;
1018 unsigned min_mv, max_mv;
1019
1020 switch (ldoh_v) {
1021 case TABLA_LDOH_1P95_V:
1022 min_mv = 160;
1023 max_mv = 1800;
1024 break;
1025 case TABLA_LDOH_2P35_V:
1026 min_mv = 200;
1027 max_mv = 2200;
1028 break;
1029 case TABLA_LDOH_2P75_V:
1030 min_mv = 240;
1031 max_mv = 2600;
1032 break;
1033 case TABLA_LDOH_2P85_V:
1034 min_mv = 250;
1035 max_mv = 2700;
1036 break;
1037 default:
1038 goto done;
1039 }
1040
1041 if (cfilt_mv < min_mv || cfilt_mv > max_mv)
1042 goto done;
1043
1044 for (rc = 4; rc <= 44; rc++) {
1045 min_mv = max_mv * (rc) / 44;
1046 if (min_mv >= cfilt_mv) {
1047 rc -= 4;
1048 break;
1049 }
1050 }
1051done:
1052 return rc;
1053}
1054
1055static bool tabla_is_hph_pa_on(struct snd_soc_codec *codec)
1056{
1057 u8 hph_reg_val = 0;
1058 hph_reg_val = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_EN);
1059
1060 return (hph_reg_val & 0x30) ? true : false;
1061}
1062
1063static void tabla_codec_switch_micbias(struct snd_soc_codec *codec,
1064 int vddio_switch)
1065{
1066 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1067 int cfilt_k_val;
1068
1069 switch (vddio_switch) {
1070 case 1:
1071 if (tabla->mbhc_polling_active) {
1072 /* Enable Mic Bias switch to VDDIO */
1073 tabla->cfilt_k_value = snd_soc_read(codec,
1074 tabla->mbhc_bias_regs.cfilt_val);
1075 cfilt_k_val = tabla_find_k_value(
1076 tabla->pdata->micbias.ldoh_v, 1800);
1077 snd_soc_update_bits(codec,
1078 tabla->mbhc_bias_regs.cfilt_val,
1079 0xFC, (cfilt_k_val << 2));
1080
1081 snd_soc_update_bits(codec,
1082 tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x80);
1083 snd_soc_update_bits(codec,
1084 tabla->mbhc_bias_regs.mbhc_reg, 0x10, 0x00);
1085
1086 tabla->mbhc_micbias_switched = true;
1087 pr_debug("%s: Enabled MBHC Mic bias to VDDIO Switch\n",
1088 __func__);
1089 }
1090 break;
1091
1092 case 0:
1093 if (tabla->mbhc_micbias_switched) {
1094 /* Disable Mic Bias switch to VDDIO */
1095 if (tabla->cfilt_k_value != 0)
1096 snd_soc_update_bits(codec,
1097 tabla->mbhc_bias_regs.cfilt_val, 0XFC,
1098 tabla->cfilt_k_value);
1099 snd_soc_update_bits(codec,
1100 tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00);
1101 snd_soc_update_bits(codec,
1102 tabla->mbhc_bias_regs.mbhc_reg, 0x10, 0x00);
1103
1104 tabla->mbhc_micbias_switched = false;
1105 pr_debug("%s: Disabled MBHC Mic bias to VDDIO Switch\n",
1106 __func__);
1107 }
1108 break;
1109 }
1110}
1111
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001112static int tabla_codec_enable_micbias(struct snd_soc_dapm_widget *w,
1113 struct snd_kcontrol *kcontrol, int event)
1114{
1115 struct snd_soc_codec *codec = w->codec;
Patrick Lai3043fba2011-08-01 14:15:57 -07001116 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1117 u16 micb_int_reg;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001118 int micb_line;
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001119 u8 cfilt_sel_val = 0;
Bradley Rubin229c6a52011-07-12 16:18:48 -07001120 char *internal1_text = "Internal1";
1121 char *internal2_text = "Internal2";
1122 char *internal3_text = "Internal3";
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001123
1124 pr_debug("%s %d\n", __func__, event);
1125 switch (w->reg) {
1126 case TABLA_A_MICB_1_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001127 micb_int_reg = TABLA_A_MICB_1_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07001128 cfilt_sel_val = tabla->pdata->micbias.bias1_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001129 micb_line = TABLA_MICBIAS1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001130 break;
1131 case TABLA_A_MICB_2_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001132 micb_int_reg = TABLA_A_MICB_2_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07001133 cfilt_sel_val = tabla->pdata->micbias.bias2_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001134 micb_line = TABLA_MICBIAS2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001135 break;
1136 case TABLA_A_MICB_3_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001137 micb_int_reg = TABLA_A_MICB_3_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07001138 cfilt_sel_val = tabla->pdata->micbias.bias3_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001139 micb_line = TABLA_MICBIAS3;
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001140 break;
1141 case TABLA_A_MICB_4_CTL:
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001142 micb_int_reg = TABLA_A_MICB_4_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07001143 cfilt_sel_val = tabla->pdata->micbias.bias4_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001144 micb_line = TABLA_MICBIAS4;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001145 break;
1146 default:
1147 pr_err("%s: Error, invalid micbias register\n", __func__);
1148 return -EINVAL;
1149 }
1150
1151 switch (event) {
1152 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001153 /* Decide whether to switch the micbias for MBHC */
1154 if ((w->reg == tabla->mbhc_bias_regs.ctl_reg)
1155 && tabla->mbhc_micbias_switched)
1156 tabla_codec_switch_micbias(codec, 0);
1157
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001158 snd_soc_update_bits(codec, w->reg, 0x0E, 0x0A);
Patrick Lai3043fba2011-08-01 14:15:57 -07001159 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 1);
Bradley Rubin229c6a52011-07-12 16:18:48 -07001160
1161 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001162 snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0);
Bradley Rubin229c6a52011-07-12 16:18:48 -07001163 else if (strnstr(w->name, internal2_text, 30))
1164 snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C);
1165 else if (strnstr(w->name, internal3_text, 30))
1166 snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3);
1167
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001168 break;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001169 case SND_SOC_DAPM_POST_PMU:
1170 if (tabla->mbhc_polling_active &&
1171 (tabla->calibration->bias == micb_line)) {
1172 tabla_codec_pause_hs_polling(codec);
1173 tabla_codec_start_hs_polling(codec);
1174 }
1175 break;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001176
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001177 case SND_SOC_DAPM_POST_PMD:
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001178
1179 if ((w->reg == tabla->mbhc_bias_regs.ctl_reg)
1180 && tabla_is_hph_pa_on(codec))
1181 tabla_codec_switch_micbias(codec, 1);
1182
Bradley Rubin229c6a52011-07-12 16:18:48 -07001183 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001184 snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00);
Bradley Rubin229c6a52011-07-12 16:18:48 -07001185 else if (strnstr(w->name, internal2_text, 30))
1186 snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00);
1187 else if (strnstr(w->name, internal3_text, 30))
1188 snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0);
1189
Patrick Lai3043fba2011-08-01 14:15:57 -07001190 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001191 break;
1192 }
1193
1194 return 0;
1195}
1196
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001197static int tabla_codec_enable_dec(struct snd_soc_dapm_widget *w,
1198 struct snd_kcontrol *kcontrol, int event)
1199{
1200 struct snd_soc_codec *codec = w->codec;
1201 u16 dec_reset_reg;
1202
1203 pr_debug("%s %d\n", __func__, event);
1204
1205 if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL)
1206 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B1_CTL;
1207 else if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL)
1208 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B2_CTL;
1209 else {
1210 pr_err("%s: Error, incorrect dec\n", __func__);
1211 return -EINVAL;
1212 }
1213
1214 switch (event) {
1215 case SND_SOC_DAPM_PRE_PMU:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001216 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift,
1217 1 << w->shift);
1218 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0);
1219 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001220 }
1221 return 0;
1222}
1223
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001224static int tabla_codec_reset_interpolator(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001225 struct snd_kcontrol *kcontrol, int event)
1226{
1227 struct snd_soc_codec *codec = w->codec;
1228
1229 switch (event) {
1230 case SND_SOC_DAPM_PRE_PMU:
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001231 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
1232 1 << w->shift, 1 << w->shift);
1233 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
1234 1 << w->shift, 0x0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001235 break;
1236 }
1237 return 0;
1238}
1239
Bradley Rubin229c6a52011-07-12 16:18:48 -07001240static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
1241 struct snd_kcontrol *kcontrol, int event)
1242{
1243 switch (event) {
1244 case SND_SOC_DAPM_POST_PMU:
1245 case SND_SOC_DAPM_POST_PMD:
1246 usleep_range(1000, 1000);
1247 break;
1248 }
1249 return 0;
1250}
1251
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07001252
1253static void tabla_enable_rx_bias(struct snd_soc_codec *codec, u32 enable)
1254{
1255 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1256
1257 if (enable) {
1258 tabla->rx_bias_count++;
1259 if (tabla->rx_bias_count == 1)
1260 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
1261 0x80, 0x80);
1262 } else {
1263 tabla->rx_bias_count--;
1264 if (!tabla->rx_bias_count)
1265 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
1266 0x80, 0x00);
1267 }
1268}
1269
1270static int tabla_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
1271 struct snd_kcontrol *kcontrol, int event)
1272{
1273 struct snd_soc_codec *codec = w->codec;
1274
1275 pr_debug("%s %d\n", __func__, event);
1276
1277 switch (event) {
1278 case SND_SOC_DAPM_PRE_PMU:
1279 tabla_enable_rx_bias(codec, 1);
1280 break;
1281 case SND_SOC_DAPM_POST_PMD:
1282 tabla_enable_rx_bias(codec, 0);
1283 break;
1284 }
1285 return 0;
1286}
1287
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07001288static int tabla_hph_pa_event(struct snd_soc_dapm_widget *w,
1289 struct snd_kcontrol *kcontrol, int event)
1290{
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001291 struct snd_soc_codec *codec = w->codec;
1292 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1293 u8 mbhc_micb_ctl_val;
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07001294 pr_debug("%s: event = %d\n", __func__, event);
1295
1296 switch (event) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001297 case SND_SOC_DAPM_PRE_PMU:
1298 mbhc_micb_ctl_val = snd_soc_read(codec,
1299 tabla->mbhc_bias_regs.ctl_reg);
1300
1301 if (!(mbhc_micb_ctl_val & 0x80)
1302 && !tabla->mbhc_micbias_switched)
1303 tabla_codec_switch_micbias(codec, 1);
1304
1305 break;
1306
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07001307 case SND_SOC_DAPM_POST_PMD:
1308
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001309 if (tabla->mbhc_micbias_switched)
1310 tabla_codec_switch_micbias(codec, 0);
1311
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07001312 pr_debug("%s: sleep 10 ms after %s PA disable.\n", __func__,
1313 w->name);
1314 usleep_range(10000, 10000);
1315
1316 break;
1317 }
1318 return 0;
1319}
1320
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07001321static void tabla_get_mbhc_micbias_regs(struct snd_soc_codec *codec,
1322 struct mbhc_micbias_regs *micbias_regs)
1323{
1324 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1325 struct tabla_mbhc_calibration *calibration = tabla->calibration;
1326 unsigned int cfilt;
1327
1328 switch (calibration->bias) {
1329 case TABLA_MICBIAS1:
1330 cfilt = tabla->pdata->micbias.bias1_cfilt_sel;
1331 micbias_regs->mbhc_reg = TABLA_A_MICB_1_MBHC;
1332 micbias_regs->int_rbias = TABLA_A_MICB_1_INT_RBIAS;
1333 micbias_regs->ctl_reg = TABLA_A_MICB_1_CTL;
1334 break;
1335 case TABLA_MICBIAS2:
1336 cfilt = tabla->pdata->micbias.bias2_cfilt_sel;
1337 micbias_regs->mbhc_reg = TABLA_A_MICB_2_MBHC;
1338 micbias_regs->int_rbias = TABLA_A_MICB_2_INT_RBIAS;
1339 micbias_regs->ctl_reg = TABLA_A_MICB_2_CTL;
1340 break;
1341 case TABLA_MICBIAS3:
1342 cfilt = tabla->pdata->micbias.bias3_cfilt_sel;
1343 micbias_regs->mbhc_reg = TABLA_A_MICB_3_MBHC;
1344 micbias_regs->int_rbias = TABLA_A_MICB_3_INT_RBIAS;
1345 micbias_regs->ctl_reg = TABLA_A_MICB_3_CTL;
1346 break;
1347 case TABLA_MICBIAS4:
1348 cfilt = tabla->pdata->micbias.bias4_cfilt_sel;
1349 micbias_regs->mbhc_reg = TABLA_A_MICB_4_MBHC;
1350 micbias_regs->int_rbias = TABLA_A_MICB_4_INT_RBIAS;
1351 micbias_regs->ctl_reg = TABLA_A_MICB_4_CTL;
1352 break;
1353 default:
1354 /* Should never reach here */
1355 pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__);
1356 }
1357
1358 switch (cfilt) {
1359 case TABLA_CFILT1_SEL:
1360 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_1_VAL;
1361 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_1_CTL;
1362 break;
1363 case TABLA_CFILT2_SEL:
1364 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_2_VAL;
1365 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_2_CTL;
1366 break;
1367 case TABLA_CFILT3_SEL:
1368 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_3_VAL;
1369 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_3_CTL;
1370 break;
1371 }
1372}
1373
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001374static const struct snd_soc_dapm_widget tabla_dapm_widgets[] = {
1375 /*RX stuff */
1376 SND_SOC_DAPM_OUTPUT("EAR"),
1377
Kiran Kandid2d86b52011-09-09 17:44:28 -07001378 SND_SOC_DAPM_PGA("EAR PA", TABLA_A_RX_EAR_EN, 4, 0, NULL, 0),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001379
Bradley Rubin229c6a52011-07-12 16:18:48 -07001380 SND_SOC_DAPM_MIXER("DAC1", TABLA_A_RX_EAR_EN, 6, 0, dac1_switch,
1381 ARRAY_SIZE(dac1_switch)),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001382
Bradley Rubin229c6a52011-07-12 16:18:48 -07001383 SND_SOC_DAPM_AIF_IN("SLIM RX1", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
1384 SND_SOC_DAPM_AIF_IN("SLIM RX2", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001385
1386 /* Headphone */
1387 SND_SOC_DAPM_OUTPUT("HEADPHONE"),
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07001388 SND_SOC_DAPM_PGA_E("HPHL", TABLA_A_RX_HPH_CNP_EN, 5, 0, NULL, 0,
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001389 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
1390 SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001391 SND_SOC_DAPM_MIXER("HPHL DAC", TABLA_A_RX_HPH_L_DAC_CTL, 7, 0,
1392 hphl_switch, ARRAY_SIZE(hphl_switch)),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001393
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07001394 SND_SOC_DAPM_PGA_E("HPHR", TABLA_A_RX_HPH_CNP_EN, 4, 0, NULL, 0,
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001395 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
1396 SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001397 SND_SOC_DAPM_MIXER("HPHR DAC", TABLA_A_RX_HPH_R_DAC_CTL, 7, 0,
1398 hphr_switch, ARRAY_SIZE(hphr_switch)),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001399
1400 /* Speaker */
Kiran Kandidb0a4b02011-08-23 09:32:09 -07001401 SND_SOC_DAPM_OUTPUT("LINEOUT1"),
1402 SND_SOC_DAPM_OUTPUT("LINEOUT2"),
1403 SND_SOC_DAPM_OUTPUT("LINEOUT3"),
1404 SND_SOC_DAPM_OUTPUT("LINEOUT4"),
1405 SND_SOC_DAPM_OUTPUT("LINEOUT5"),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001406
Kiran Kandidb0a4b02011-08-23 09:32:09 -07001407 SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TABLA_A_RX_LINE_CNP_EN, 0, 0, NULL,
1408 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
1409 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1410 SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TABLA_A_RX_LINE_CNP_EN, 1, 0, NULL,
1411 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
1412 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1413 SND_SOC_DAPM_PGA_E("LINEOUT3 PA", TABLA_A_RX_LINE_CNP_EN, 2, 0, NULL,
1414 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
1415 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1416 SND_SOC_DAPM_PGA_E("LINEOUT4 PA", TABLA_A_RX_LINE_CNP_EN, 3, 0, NULL,
1417 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
1418 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1419 SND_SOC_DAPM_PGA_E("LINEOUT5 PA", TABLA_A_RX_LINE_CNP_EN, 4, 0, NULL, 0,
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001420 tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
1421 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001422
Bradley Rubin229c6a52011-07-12 16:18:48 -07001423 SND_SOC_DAPM_MIXER("LINEOUT1 DAC", TABLA_A_RX_LINE_1_DAC_CTL, 7, 0,
1424 lineout1_switch, ARRAY_SIZE(lineout1_switch)),
1425 SND_SOC_DAPM_MIXER("LINEOUT2 DAC", TABLA_A_RX_LINE_2_DAC_CTL, 7, 0,
1426 lineout2_switch, ARRAY_SIZE(lineout2_switch)),
1427 SND_SOC_DAPM_MIXER("LINEOUT3 DAC", TABLA_A_RX_LINE_3_DAC_CTL, 7, 0,
1428 lineout3_switch, ARRAY_SIZE(lineout3_switch)),
1429 SND_SOC_DAPM_MIXER("LINEOUT4 DAC", TABLA_A_RX_LINE_4_DAC_CTL, 7, 0,
1430 lineout4_switch, ARRAY_SIZE(lineout4_switch)),
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001431 SND_SOC_DAPM_MIXER("LINEOUT5 DAC", TABLA_A_RX_LINE_5_DAC_CTL, 7, 0,
1432 lineout5_switch, ARRAY_SIZE(lineout5_switch)),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001433
Bradley Rubin229c6a52011-07-12 16:18:48 -07001434 SND_SOC_DAPM_MIXER_E("RX1 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL,
1435 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
1436 SND_SOC_DAPM_MIXER_E("RX2 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL,
1437 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
1438 SND_SOC_DAPM_MIXER_E("RX3 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
1439 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
1440 SND_SOC_DAPM_MIXER_E("RX4 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL,
1441 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
1442 SND_SOC_DAPM_MIXER_E("RX5 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 4, 0, NULL,
1443 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
1444 SND_SOC_DAPM_MIXER_E("RX6 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0, NULL,
1445 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001446 SND_SOC_DAPM_MIXER_E("RX7 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 6, 0, NULL,
1447 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001448
Bradley Rubin229c6a52011-07-12 16:18:48 -07001449 SND_SOC_DAPM_MIXER("RX1 CHAIN", TABLA_A_CDC_RX1_B6_CTL, 5, 0, NULL, 0),
1450 SND_SOC_DAPM_MIXER("RX2 CHAIN", TABLA_A_CDC_RX2_B6_CTL, 5, 0, NULL, 0),
1451
1452 SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1453 &rx_mix1_inp1_mux),
1454 SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1455 &rx_mix1_inp2_mux),
1456 SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1457 &rx2_mix1_inp1_mux),
1458 SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1459 &rx2_mix1_inp2_mux),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001460 SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1461 &rx3_mix1_inp1_mux),
1462 SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1463 &rx3_mix1_inp2_mux),
1464 SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1465 &rx4_mix1_inp1_mux),
1466 SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1467 &rx4_mix1_inp2_mux),
1468 SND_SOC_DAPM_MUX("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1469 &rx5_mix1_inp1_mux),
1470 SND_SOC_DAPM_MUX("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1471 &rx5_mix1_inp2_mux),
1472 SND_SOC_DAPM_MUX("RX6 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1473 &rx6_mix1_inp1_mux),
1474 SND_SOC_DAPM_MUX("RX6 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1475 &rx6_mix1_inp2_mux),
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001476 SND_SOC_DAPM_MUX("RX7 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1477 &rx7_mix1_inp1_mux),
1478 SND_SOC_DAPM_MUX("RX7 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1479 &rx7_mix1_inp2_mux),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001480
Bradley Rubin229c6a52011-07-12 16:18:48 -07001481 SND_SOC_DAPM_SUPPLY("CP", TABLA_A_CP_EN, 0, 0,
1482 tabla_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU |
1483 SND_SOC_DAPM_PRE_PMD),
1484
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07001485 SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
1486 tabla_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
1487 SND_SOC_DAPM_POST_PMD),
1488
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001489 /* TX */
Bradley Rubin229c6a52011-07-12 16:18:48 -07001490
Bradley Rubine1d08622011-07-20 18:01:35 -07001491 SND_SOC_DAPM_SUPPLY("CDC_CONN", TABLA_A_CDC_CLK_OTHR_CTL, 2, 0, NULL,
1492 0),
1493
Bradley Rubin229c6a52011-07-12 16:18:48 -07001494 SND_SOC_DAPM_SUPPLY("LDO_H", TABLA_A_LDO_H_MODE_1, 7, 0,
1495 tabla_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU),
1496
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001497 SND_SOC_DAPM_INPUT("AMIC1"),
1498 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", TABLA_A_MICB_1_CTL, 7, 0,
1499 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001500 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001501 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", TABLA_A_MICB_1_CTL, 7, 0,
1502 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001503 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001504 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", TABLA_A_MICB_1_CTL, 7, 0,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001505 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001506 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001507 SND_SOC_DAPM_ADC_E("ADC1", NULL, TABLA_A_TX_1_2_EN, 7, 0,
1508 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
1509 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1510
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001511 SND_SOC_DAPM_INPUT("AMIC3"),
1512 SND_SOC_DAPM_ADC_E("ADC3", NULL, TABLA_A_TX_3_4_EN, 7, 0,
1513 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
1514 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1515
1516 SND_SOC_DAPM_INPUT("AMIC4"),
1517 SND_SOC_DAPM_ADC_E("ADC4", NULL, TABLA_A_TX_3_4_EN, 3, 0,
1518 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
1519 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1520
1521 SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", TABLA_A_MICB_4_CTL, 7, 0,
1522 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001523 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001524
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001525 SND_SOC_DAPM_INPUT("AMIC5"),
1526 SND_SOC_DAPM_ADC_E("ADC5", NULL, TABLA_A_TX_5_6_EN, 7, 0,
1527 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
1528
1529 SND_SOC_DAPM_INPUT("AMIC6"),
1530 SND_SOC_DAPM_ADC_E("ADC6", NULL, TABLA_A_TX_5_6_EN, 3, 0,
1531 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
1532
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001533 SND_SOC_DAPM_MUX_E("DEC1 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0, 0,
Bradley Rubine1d08622011-07-20 18:01:35 -07001534 &dec1_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001535
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001536 SND_SOC_DAPM_MUX_E("DEC2 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 1, 0,
Bradley Rubine1d08622011-07-20 18:01:35 -07001537 &dec2_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001538
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001539 SND_SOC_DAPM_MUX_E("DEC3 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 2, 0,
Bradley Rubine1d08622011-07-20 18:01:35 -07001540 &dec3_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001541
1542 SND_SOC_DAPM_MUX_E("DEC4 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 3, 0,
Bradley Rubine1d08622011-07-20 18:01:35 -07001543 &dec4_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001544
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001545 SND_SOC_DAPM_MUX_E("DEC5 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 4, 0,
Bradley Rubine1d08622011-07-20 18:01:35 -07001546 &dec5_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001547
1548 SND_SOC_DAPM_MUX_E("DEC6 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 5, 0,
Bradley Rubine1d08622011-07-20 18:01:35 -07001549 &dec6_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001550
1551 SND_SOC_DAPM_MUX_E("DEC7 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 6, 0,
Bradley Rubine1d08622011-07-20 18:01:35 -07001552 &dec7_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001553
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001554 SND_SOC_DAPM_MUX_E("DEC8 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 7, 0,
Bradley Rubine1d08622011-07-20 18:01:35 -07001555 &dec8_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001556
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001557 SND_SOC_DAPM_MUX_E("DEC9 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL, 0, 0,
Bradley Rubine1d08622011-07-20 18:01:35 -07001558 &dec9_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001559
1560 SND_SOC_DAPM_MUX_E("DEC10 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL, 1, 0,
Bradley Rubine1d08622011-07-20 18:01:35 -07001561 &dec10_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001562
Bradley Rubin229c6a52011-07-12 16:18:48 -07001563 SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux),
1564 SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux),
1565
1566 SND_SOC_DAPM_MIXER_E("ANC", SND_SOC_NOPM, 0, 0, NULL, 0,
1567 tabla_codec_enable_anc, SND_SOC_DAPM_PRE_PMU |
1568 SND_SOC_DAPM_POST_PMD),
1569
1570 SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux),
1571
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001572 SND_SOC_DAPM_INPUT("AMIC2"),
1573 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", TABLA_A_MICB_2_CTL, 7, 0,
1574 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001575 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001576 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", TABLA_A_MICB_2_CTL, 7, 0,
1577 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001578 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001579 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", TABLA_A_MICB_2_CTL, 7, 0,
1580 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001581 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001582 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", TABLA_A_MICB_2_CTL, 7, 0,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001583 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001584 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001585 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", TABLA_A_MICB_3_CTL, 7, 0,
1586 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001587 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001588 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", TABLA_A_MICB_3_CTL, 7, 0,
1589 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001590 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001591 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", TABLA_A_MICB_3_CTL, 7, 0,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001592 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001593 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001594 SND_SOC_DAPM_ADC_E("ADC2", NULL, TABLA_A_TX_1_2_EN, 3, 0,
1595 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
1596 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1597
1598 SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, 0, 0, &sb_tx1_mux),
1599 SND_SOC_DAPM_AIF_OUT("SLIM TX1", "AIF1 Capture", NULL, SND_SOC_NOPM,
1600 0, 0),
1601
1602 SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, 0, 0, &sb_tx5_mux),
1603 SND_SOC_DAPM_AIF_OUT("SLIM TX5", "AIF1 Capture", NULL, SND_SOC_NOPM,
1604 4, 0),
1605
1606 SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, 0, 0, &sb_tx6_mux),
1607 SND_SOC_DAPM_AIF_OUT("SLIM TX6", "AIF1 Capture", NULL, SND_SOC_NOPM,
1608 5, 0),
1609
1610 SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, 0, 0, &sb_tx7_mux),
1611 SND_SOC_DAPM_AIF_OUT("SLIM TX7", "AIF1 Capture", NULL, SND_SOC_NOPM,
1612 0, 0),
1613
1614 SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, 0, 0, &sb_tx8_mux),
1615 SND_SOC_DAPM_AIF_OUT("SLIM TX8", "AIF1 Capture", NULL, SND_SOC_NOPM,
1616 0, 0),
1617
Kiran Kandicf45f6a2011-07-17 21:10:19 -07001618 /* Digital Mic Inputs */
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07001619 SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
1620 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1621 SND_SOC_DAPM_POST_PMD),
1622
1623 SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
1624 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1625 SND_SOC_DAPM_POST_PMD),
1626
1627 SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0,
1628 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1629 SND_SOC_DAPM_POST_PMD),
1630
1631 SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0,
1632 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1633 SND_SOC_DAPM_POST_PMD),
1634
1635 SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0,
1636 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1637 SND_SOC_DAPM_POST_PMD),
1638
1639 SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 0,
1640 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
1641 SND_SOC_DAPM_POST_PMD),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001642
1643 /* Sidetone */
1644 SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux),
1645 SND_SOC_DAPM_PGA("IIR1", TABLA_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0),
1646};
1647
1648static const struct snd_soc_dapm_route audio_map[] = {
1649 /* SLIMBUS Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001650
1651 {"SLIM TX1", NULL, "SLIM TX1 MUX"},
1652 {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"},
1653
1654 {"SLIM TX5", NULL, "SLIM TX5 MUX"},
1655 {"SLIM TX5 MUX", "DEC5", "DEC5 MUX"},
1656
1657 {"SLIM TX6", NULL, "SLIM TX6 MUX"},
1658 {"SLIM TX6 MUX", "DEC6", "DEC6 MUX"},
1659
1660 {"SLIM TX7", NULL, "SLIM TX7 MUX"},
1661 {"SLIM TX7 MUX", "DEC1", "DEC1 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001662 {"SLIM TX7 MUX", "DEC2", "DEC2 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001663 {"SLIM TX7 MUX", "DEC3", "DEC3 MUX"},
1664 {"SLIM TX7 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001665 {"SLIM TX7 MUX", "DEC5", "DEC5 MUX"},
1666 {"SLIM TX7 MUX", "DEC6", "DEC6 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001667 {"SLIM TX7 MUX", "DEC7", "DEC7 MUX"},
1668 {"SLIM TX7 MUX", "DEC8", "DEC8 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001669 {"SLIM TX7 MUX", "DEC9", "DEC9 MUX"},
1670 {"SLIM TX7 MUX", "DEC10", "DEC10 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001671
1672 {"SLIM TX8", NULL, "SLIM TX8 MUX"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07001673 {"SLIM TX8 MUX", "DEC1", "DEC1 MUX"},
1674 {"SLIM TX8 MUX", "DEC2", "DEC2 MUX"},
1675 {"SLIM TX8 MUX", "DEC3", "DEC3 MUX"},
Bhalchandra Gajare9ec83cd2011-09-23 17:25:07 -07001676 {"SLIM TX8 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001677 {"SLIM TX8 MUX", "DEC5", "DEC5 MUX"},
1678 {"SLIM TX8 MUX", "DEC6", "DEC6 MUX"},
1679
1680 /* Earpiece (RX MIX1) */
1681 {"EAR", NULL, "EAR PA"},
Kiran Kandiac034ac2011-07-29 16:39:08 -07001682 {"EAR PA", NULL, "DAC1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07001683 {"DAC1", NULL, "CP"},
1684
1685 {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX1"},
1686 {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX1"},
1687 {"ANC", NULL, "ANC1 FB MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001688
1689 /* Headset (RX MIX1 and RX MIX2) */
1690 {"HEADPHONE", NULL, "HPHL"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001691 {"HEADPHONE", NULL, "HPHR"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07001692
1693 {"HPHL", NULL, "HPHL DAC"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001694 {"HPHR", NULL, "HPHR DAC"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07001695
1696 {"HPHL DAC", NULL, "CP"},
1697 {"HPHR DAC", NULL, "CP"},
1698
1699 {"ANC", NULL, "ANC1 MUX"},
1700 {"ANC", NULL, "ANC2 MUX"},
1701 {"ANC1 MUX", "ADC1", "ADC1"},
1702 {"ANC1 MUX", "ADC2", "ADC2"},
1703 {"ANC1 MUX", "ADC3", "ADC3"},
1704 {"ANC1 MUX", "ADC4", "ADC4"},
1705 {"ANC2 MUX", "ADC1", "ADC1"},
1706 {"ANC2 MUX", "ADC2", "ADC2"},
1707 {"ANC2 MUX", "ADC3", "ADC3"},
1708 {"ANC2 MUX", "ADC4", "ADC4"},
1709
Bradley Rubine1d08622011-07-20 18:01:35 -07001710 {"ANC", NULL, "CDC_CONN"},
1711
Bradley Rubin229c6a52011-07-12 16:18:48 -07001712 {"DAC1", "Switch", "RX1 CHAIN"},
1713 {"HPHL DAC", "Switch", "RX1 CHAIN"},
1714 {"HPHR DAC", "Switch", "RX2 CHAIN"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001715
Kiran Kandidb0a4b02011-08-23 09:32:09 -07001716 {"LINEOUT1", NULL, "LINEOUT1 PA"},
1717 {"LINEOUT2", NULL, "LINEOUT2 PA"},
1718 {"LINEOUT3", NULL, "LINEOUT3 PA"},
1719 {"LINEOUT4", NULL, "LINEOUT4 PA"},
1720 {"LINEOUT5", NULL, "LINEOUT5 PA"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001721
Kiran Kandidb0a4b02011-08-23 09:32:09 -07001722 {"LINEOUT1 PA", NULL, "LINEOUT1 DAC"},
1723 {"LINEOUT2 PA", NULL, "LINEOUT2 DAC"},
1724 {"LINEOUT3 PA", NULL, "LINEOUT3 DAC"},
1725 {"LINEOUT4 PA", NULL, "LINEOUT4 DAC"},
1726 {"LINEOUT5 PA", NULL, "LINEOUT5 DAC"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001727
Bradley Rubin229c6a52011-07-12 16:18:48 -07001728 {"RX1 CHAIN", NULL, "RX1 MIX1"},
1729 {"RX2 CHAIN", NULL, "RX2 MIX1"},
1730 {"RX1 CHAIN", NULL, "ANC"},
1731 {"RX2 CHAIN", NULL, "ANC"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001732 {"LINEOUT1 DAC", "Switch", "RX3 MIX1"},
1733 {"LINEOUT2 DAC", "Switch", "RX4 MIX1"},
Kiran Kandied246a92011-08-12 14:03:44 -07001734 {"LINEOUT3 DAC", "Switch", "RX3 MIX1"},
1735 {"LINEOUT4 DAC", "Switch", "RX4 MIX1"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001736 {"LINEOUT5 DAC", "Switch", "RX7 MIX1"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001737
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07001738 {"CP", NULL, "RX_BIAS"},
1739 {"LINEOUT1 DAC", NULL, "RX_BIAS"},
1740 {"LINEOUT2 DAC", NULL, "RX_BIAS"},
1741 {"LINEOUT3 DAC", NULL, "RX_BIAS"},
1742 {"LINEOUT4 DAC", NULL, "RX_BIAS"},
1743
Bradley Rubin229c6a52011-07-12 16:18:48 -07001744 {"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
1745 {"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
1746 {"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
1747 {"RX2 MIX1", NULL, "RX2 MIX1 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001748 {"RX3 MIX1", NULL, "RX3 MIX1 INP1"},
1749 {"RX3 MIX1", NULL, "RX3 MIX1 INP2"},
1750 {"RX4 MIX1", NULL, "RX4 MIX1 INP1"},
1751 {"RX4 MIX1", NULL, "RX4 MIX1 INP2"},
1752 {"RX5 MIX1", NULL, "RX5 MIX1 INP1"},
1753 {"RX5 MIX1", NULL, "RX5 MIX1 INP2"},
1754 {"RX6 MIX1", NULL, "RX6 MIX1 INP1"},
1755 {"RX6 MIX1", NULL, "RX6 MIX1 INP2"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001756 {"RX7 MIX1", NULL, "RX7 MIX1 INP1"},
1757 {"RX7 MIX1", NULL, "RX7 MIX1 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001758
Bradley Rubin229c6a52011-07-12 16:18:48 -07001759 {"RX1 MIX1 INP1", "RX1", "SLIM RX1"},
1760 {"RX1 MIX1 INP1", "RX2", "SLIM RX2"},
1761 {"RX1 MIX1 INP1", "IIR1", "IIR1"},
1762 {"RX1 MIX1 INP2", "RX1", "SLIM RX1"},
1763 {"RX1 MIX1 INP2", "RX2", "SLIM RX2"},
1764 {"RX1 MIX1 INP2", "IIR1", "IIR1"},
1765 {"RX2 MIX1 INP1", "RX1", "SLIM RX1"},
1766 {"RX2 MIX1 INP1", "RX2", "SLIM RX2"},
1767 {"RX2 MIX1 INP2", "RX1", "SLIM RX1"},
1768 {"RX2 MIX1 INP2", "RX2", "SLIM RX2"},
1769 {"RX3 MIX1 INP1", "RX1", "SLIM RX1"},
1770 {"RX3 MIX1 INP1", "RX2", "SLIM RX2"},
1771 {"RX3 MIX1 INP2", "RX1", "SLIM RX1"},
1772 {"RX3 MIX1 INP2", "RX2", "SLIM RX2"},
1773 {"RX4 MIX1 INP1", "RX1", "SLIM RX1"},
1774 {"RX4 MIX1 INP1", "RX2", "SLIM RX2"},
1775 {"RX4 MIX1 INP2", "RX1", "SLIM RX1"},
1776 {"RX4 MIX1 INP2", "RX2", "SLIM RX2"},
1777 {"RX5 MIX1 INP1", "RX1", "SLIM RX1"},
1778 {"RX5 MIX1 INP1", "RX2", "SLIM RX2"},
1779 {"RX5 MIX1 INP2", "RX1", "SLIM RX1"},
1780 {"RX5 MIX1 INP2", "RX2", "SLIM RX2"},
1781 {"RX6 MIX1 INP1", "RX1", "SLIM RX1"},
1782 {"RX6 MIX1 INP1", "RX2", "SLIM RX2"},
1783 {"RX6 MIX1 INP2", "RX1", "SLIM RX1"},
1784 {"RX6 MIX1 INP2", "RX2", "SLIM RX2"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001785 {"RX7 MIX1 INP1", "RX1", "SLIM RX1"},
1786 {"RX7 MIX1 INP1", "RX2", "SLIM RX2"},
1787 {"RX7 MIX1 INP2", "RX1", "SLIM RX1"},
1788 {"RX7 MIX1 INP2", "RX2", "SLIM RX2"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001789
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001790 /* Decimator Inputs */
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001791 {"DEC1 MUX", "DMIC1", "DMIC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07001792 {"DEC1 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07001793 {"DEC1 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07001794 {"DEC2 MUX", "DMIC2", "DMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001795 {"DEC2 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07001796 {"DEC2 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07001797 {"DEC3 MUX", "DMIC3", "DMIC3"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001798 {"DEC3 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07001799 {"DEC3 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07001800 {"DEC4 MUX", "DMIC4", "DMIC4"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001801 {"DEC4 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07001802 {"DEC4 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07001803 {"DEC5 MUX", "DMIC5", "DMIC5"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001804 {"DEC5 MUX", "ADC2", "ADC2"},
Bradley Rubine1d08622011-07-20 18:01:35 -07001805 {"DEC5 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07001806 {"DEC6 MUX", "DMIC6", "DMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001807 {"DEC6 MUX", "ADC1", "ADC1"},
Bradley Rubine1d08622011-07-20 18:01:35 -07001808 {"DEC6 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001809 {"DEC7 MUX", "DMIC1", "DMIC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07001810 {"DEC7 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07001811 {"DEC7 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001812 {"DEC8 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07001813 {"DEC8 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001814 {"DEC9 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07001815 {"DEC9 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001816 {"DEC10 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07001817 {"DEC10 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001818
1819 /* ADC Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001820 {"ADC1", NULL, "AMIC1"},
1821 {"ADC2", NULL, "AMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001822 {"ADC3", NULL, "AMIC3"},
1823 {"ADC4", NULL, "AMIC4"},
1824 {"ADC5", NULL, "AMIC5"},
1825 {"ADC6", NULL, "AMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001826
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001827 {"IIR1", NULL, "IIR1 INP1 MUX"},
1828 {"IIR1 INP1 MUX", "DEC6", "DEC6 MUX"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07001829
1830 {"MIC BIAS1 Internal1", NULL, "LDO_H"},
1831 {"MIC BIAS1 Internal2", NULL, "LDO_H"},
1832 {"MIC BIAS1 External", NULL, "LDO_H"},
1833 {"MIC BIAS2 Internal1", NULL, "LDO_H"},
1834 {"MIC BIAS2 Internal2", NULL, "LDO_H"},
1835 {"MIC BIAS2 Internal3", NULL, "LDO_H"},
1836 {"MIC BIAS2 External", NULL, "LDO_H"},
1837 {"MIC BIAS3 Internal1", NULL, "LDO_H"},
1838 {"MIC BIAS3 Internal2", NULL, "LDO_H"},
1839 {"MIC BIAS3 External", NULL, "LDO_H"},
1840 {"MIC BIAS4 External", NULL, "LDO_H"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001841};
1842
1843static int tabla_readable(struct snd_soc_codec *ssc, unsigned int reg)
1844{
1845 return tabla_reg_readable[reg];
1846}
1847
1848static int tabla_volatile(struct snd_soc_codec *ssc, unsigned int reg)
1849{
1850 /* Registers lower than 0x100 are top level registers which can be
1851 * written by the Tabla core driver.
1852 */
1853
1854 if ((reg >= TABLA_A_CDC_MBHC_EN_CTL) || (reg < 0x100))
1855 return 1;
1856
1857 return 0;
1858}
1859
1860#define TABLA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
1861static int tabla_write(struct snd_soc_codec *codec, unsigned int reg,
1862 unsigned int value)
1863{
1864 int ret;
1865 pr_debug("%s: write reg %x val %x\n", __func__, reg, value);
1866
1867 BUG_ON(reg > TABLA_MAX_REGISTER);
1868
1869 if (!tabla_volatile(codec, reg)) {
1870 pr_debug("writing to cache\n");
1871 ret = snd_soc_cache_write(codec, reg, value);
1872 if (ret != 0)
1873 dev_err(codec->dev, "Cache write to %x failed: %d\n",
1874 reg, ret);
1875 }
1876
1877 return tabla_reg_write(codec->control_data, reg, value);
1878}
1879static unsigned int tabla_read(struct snd_soc_codec *codec,
1880 unsigned int reg)
1881{
1882 unsigned int val;
1883 int ret;
1884
1885 BUG_ON(reg > TABLA_MAX_REGISTER);
1886
1887 if (!tabla_volatile(codec, reg) && tabla_readable(codec, reg) &&
1888 reg < codec->driver->reg_cache_size) {
1889 pr_debug("reading from cache\n");
1890 ret = snd_soc_cache_read(codec, reg, &val);
1891 if (ret >= 0) {
Bradley Rubin229c6a52011-07-12 16:18:48 -07001892 pr_debug("register %x, value %x\n", reg, val);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001893 return val;
1894 } else
1895 dev_err(codec->dev, "Cache read from %x failed: %d\n",
1896 reg, ret);
1897 }
1898
1899 val = tabla_reg_read(codec->control_data, reg);
1900 pr_debug("%s: read reg %x val %x\n", __func__, reg, val);
1901 return val;
1902}
1903
1904static void tabla_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec)
1905{
1906 snd_soc_write(codec, TABLA_A_BIAS_REF_CTL, 0x1C);
1907 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
1908 0x80);
1909 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x04,
1910 0x04);
1911 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01,
1912 0x01);
1913 usleep_range(1000, 1000);
1914 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
1915 0x00);
1916}
1917
1918static void tabla_codec_enable_bandgap(struct snd_soc_codec *codec,
1919 enum tabla_bandgap_type choice)
1920{
1921 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1922
1923 /* TODO lock resources accessed by audio streams and threaded
1924 * interrupt handlers
1925 */
1926
1927 pr_debug("%s, choice is %d, current is %d\n", __func__, choice,
1928 tabla->bandgap_type);
1929
1930 if (tabla->bandgap_type == choice)
1931 return;
1932
1933 if ((tabla->bandgap_type == TABLA_BANDGAP_OFF) &&
1934 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
1935 tabla_codec_enable_audio_mode_bandgap(codec);
1936 } else if ((tabla->bandgap_type == TABLA_BANDGAP_AUDIO_MODE) &&
1937 (choice == TABLA_BANDGAP_MBHC_MODE)) {
1938 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x2,
1939 0x2);
1940 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
1941 0x80);
1942 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x4,
1943 0x4);
1944 usleep_range(1000, 1000);
1945 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
1946 0x00);
1947 } else if ((tabla->bandgap_type == TABLA_BANDGAP_MBHC_MODE) &&
1948 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
1949 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x00);
1950 usleep_range(100, 100);
1951 tabla_codec_enable_audio_mode_bandgap(codec);
1952 } else if (choice == TABLA_BANDGAP_OFF) {
1953 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x00);
1954 } else {
1955 pr_err("%s: Error, Invalid bandgap settings\n", __func__);
1956 }
1957 tabla->bandgap_type = choice;
1958}
1959
1960static int tabla_codec_enable_config_mode(struct snd_soc_codec *codec,
1961 int enable)
1962{
1963 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1964
1965 if (enable) {
1966 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x10, 0);
1967 snd_soc_write(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x17);
1968 usleep_range(5, 5);
1969 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80,
1970 0x80);
1971 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80,
1972 0x80);
1973 usleep_range(10, 10);
1974 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, 0);
1975 usleep_range(20, 20);
1976 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x08);
1977 } else {
1978 snd_soc_update_bits(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x1,
1979 0);
1980 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, 0);
1981 }
1982 tabla->config_mode_active = enable ? true : false;
1983
1984 return 0;
1985}
1986
1987static int tabla_codec_enable_clock_block(struct snd_soc_codec *codec,
1988 int config_mode)
1989{
1990 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1991
1992 pr_debug("%s\n", __func__);
1993
1994 if (config_mode) {
1995 tabla_codec_enable_config_mode(codec, 1);
1996 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x00);
1997 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
1998 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN1, 0x0D);
1999 usleep_range(1000, 1000);
2000 } else
2001 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00);
2002
2003 if (!config_mode && tabla->mbhc_polling_active) {
2004 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
2005 tabla_codec_enable_config_mode(codec, 0);
2006
2007 }
2008
2009 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x05);
2010 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x00);
2011 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x04);
2012 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_MCLK_CTL, 0x01, 0x01);
2013 usleep_range(50, 50);
2014 tabla->clock_active = true;
2015 return 0;
2016}
2017static void tabla_codec_disable_clock_block(struct snd_soc_codec *codec)
2018{
2019 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2020 pr_debug("%s\n", __func__);
2021 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x00);
2022 ndelay(160);
2023 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x02);
2024 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x00);
2025 tabla->clock_active = false;
2026}
2027
Bradley Rubincb1e2732011-06-23 16:49:20 -07002028static void tabla_codec_calibrate_hs_polling(struct snd_soc_codec *codec)
2029{
2030 /* TODO store register values in calibration */
Bhalchandra Gajare30cf4842011-10-17 18:12:52 -07002031 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0x20);
2032 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0xFF);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002033
2034 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B10_CTL, 0xFF);
Bhalchandra Gajare30cf4842011-10-17 18:12:52 -07002035 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B9_CTL, 0x20);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002036
2037 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, 0x08);
2038 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0xEE);
2039 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, 0xFC);
2040 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, 0xCE);
2041
2042 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL, 3);
2043 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B2_CTL, 9);
2044 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B3_CTL, 30);
2045 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL, 120);
2046 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL, 0x78, 0x58);
2047 snd_soc_write(codec, TABLA_A_CDC_MBHC_B2_CTL, 11);
2048}
2049
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002050static int tabla_startup(struct snd_pcm_substream *substream,
2051 struct snd_soc_dai *dai)
2052{
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002053 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
2054 substream->name, substream->stream);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002055
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002056 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002057}
2058
2059static void tabla_shutdown(struct snd_pcm_substream *substream,
2060 struct snd_soc_dai *dai)
2061{
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002062 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
2063 substream->name, substream->stream);
2064}
2065
2066int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable)
2067{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002068 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2069
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002070 pr_debug("%s() mclk_enable = %u\n", __func__, mclk_enable);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002071
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002072 if (mclk_enable) {
2073 tabla->mclk_enabled = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002074
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002075 if (tabla->mbhc_polling_active && (tabla->mclk_enabled)) {
Bradley Rubincb1e2732011-06-23 16:49:20 -07002076 tabla_codec_pause_hs_polling(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002077 tabla_codec_enable_bandgap(codec,
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002078 TABLA_BANDGAP_AUDIO_MODE);
2079 tabla_codec_enable_clock_block(codec, 0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002080 tabla_codec_calibrate_hs_polling(codec);
2081 tabla_codec_start_hs_polling(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002082 }
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002083 } else {
2084
2085 if (!tabla->mclk_enabled) {
2086 pr_err("Error, MCLK already diabled\n");
2087 return -EINVAL;
2088 }
2089 tabla->mclk_enabled = false;
2090
2091 if (tabla->mbhc_polling_active) {
2092 if (!tabla->mclk_enabled) {
2093 tabla_codec_pause_hs_polling(codec);
2094 tabla_codec_enable_bandgap(codec,
2095 TABLA_BANDGAP_MBHC_MODE);
2096 tabla_enable_rx_bias(codec, 1);
2097 tabla_codec_enable_clock_block(codec, 1);
2098 tabla_codec_calibrate_hs_polling(codec);
2099 tabla_codec_start_hs_polling(codec);
2100 }
2101 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1,
2102 0x05, 0x01);
2103 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002104 }
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002105 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002106}
2107
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002108static int tabla_set_dai_sysclk(struct snd_soc_dai *dai,
2109 int clk_id, unsigned int freq, int dir)
2110{
2111 pr_debug("%s\n", __func__);
2112 return 0;
2113}
2114
2115static int tabla_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2116{
2117 pr_debug("%s\n", __func__);
2118 return 0;
2119}
2120
2121static int tabla_hw_params(struct snd_pcm_substream *substream,
2122 struct snd_pcm_hw_params *params,
2123 struct snd_soc_dai *dai)
2124{
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07002125 struct snd_soc_codec *codec = dai->codec;
Bhalchandra Gajare038bf3a2011-09-02 15:32:30 -07002126 u8 path, shift;
2127 u16 tx_fs_reg, rx_fs_reg;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07002128 u8 tx_fs_rate, rx_fs_rate, rx_state, tx_state;
2129
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002130 pr_debug("%s: DAI-ID %x\n", __func__, dai->id);
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07002131
2132 switch (params_rate(params)) {
2133 case 8000:
2134 tx_fs_rate = 0x00;
2135 rx_fs_rate = 0x00;
2136 break;
2137 case 16000:
2138 tx_fs_rate = 0x01;
2139 rx_fs_rate = 0x20;
2140 break;
2141 case 32000:
2142 tx_fs_rate = 0x02;
2143 rx_fs_rate = 0x40;
2144 break;
2145 case 48000:
2146 tx_fs_rate = 0x03;
2147 rx_fs_rate = 0x60;
2148 break;
2149 default:
2150 pr_err("%s: Invalid sampling rate %d\n", __func__,
2151 params_rate(params));
2152 return -EINVAL;
2153 }
2154
2155
2156 /**
2157 * If current dai is a tx dai, set sample rate to
2158 * all the txfe paths that are currently not active
2159 */
2160 if (dai->id == TABLA_TX_DAI_ID) {
2161
2162 tx_state = snd_soc_read(codec,
2163 TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL);
2164
2165 for (path = 1, shift = 0;
2166 path <= NUM_DECIMATORS; path++, shift++) {
2167
2168 if (path == BITS_PER_REG + 1) {
2169 shift = 0;
2170 tx_state = snd_soc_read(codec,
2171 TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL);
2172 }
2173
2174 if (!(tx_state & (1 << shift))) {
2175 tx_fs_reg = TABLA_A_CDC_TX1_CLK_FS_CTL
2176 + (BITS_PER_REG*(path-1));
2177 snd_soc_update_bits(codec, tx_fs_reg,
2178 0x03, tx_fs_rate);
2179 }
2180 }
2181 }
2182
2183 /**
2184 * TODO: Need to handle case where same RX chain takes 2 or more inputs
2185 * with varying sample rates
2186 */
2187
2188 /**
2189 * If current dai is a rx dai, set sample rate to
2190 * all the rx paths that are currently not active
2191 */
2192 if (dai->id == TABLA_RX_DAI_ID) {
2193
2194 rx_state = snd_soc_read(codec,
2195 TABLA_A_CDC_CLK_RX_B1_CTL);
2196
2197 for (path = 1, shift = 0;
2198 path <= NUM_INTERPOLATORS; path++, shift++) {
2199
2200 if (!(rx_state & (1 << shift))) {
2201 rx_fs_reg = TABLA_A_CDC_RX1_B5_CTL
2202 + (BITS_PER_REG*(path-1));
2203 snd_soc_update_bits(codec, rx_fs_reg,
2204 0xE0, rx_fs_rate);
2205 }
2206 }
2207 }
2208
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002209 return 0;
2210}
2211
2212static struct snd_soc_dai_ops tabla_dai_ops = {
2213 .startup = tabla_startup,
2214 .shutdown = tabla_shutdown,
2215 .hw_params = tabla_hw_params,
2216 .set_sysclk = tabla_set_dai_sysclk,
2217 .set_fmt = tabla_set_dai_fmt,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002218};
2219
2220static struct snd_soc_dai_driver tabla_dai[] = {
2221 {
2222 .name = "tabla_rx1",
2223 .id = 1,
2224 .playback = {
2225 .stream_name = "AIF1 Playback",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07002226 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002227 .formats = TABLA_FORMATS,
2228 .rate_max = 48000,
2229 .rate_min = 8000,
2230 .channels_min = 1,
2231 .channels_max = 2,
2232 },
2233 .ops = &tabla_dai_ops,
2234 },
2235 {
2236 .name = "tabla_tx1",
2237 .id = 2,
2238 .capture = {
2239 .stream_name = "AIF1 Capture",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07002240 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002241 .formats = TABLA_FORMATS,
2242 .rate_max = 48000,
2243 .rate_min = 8000,
2244 .channels_min = 1,
2245 .channels_max = 2,
2246 },
2247 .ops = &tabla_dai_ops,
2248 },
2249};
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002250static short tabla_codec_read_sta_result(struct snd_soc_codec *codec)
Bradley Rubincb1e2732011-06-23 16:49:20 -07002251{
2252 u8 bias_msb, bias_lsb;
2253 short bias_value;
2254
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002255 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B3_STATUS);
2256 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B2_STATUS);
2257 bias_value = (bias_msb << 8) | bias_lsb;
2258 return bias_value;
2259}
2260
2261static short tabla_codec_read_dce_result(struct snd_soc_codec *codec)
2262{
2263 u8 bias_msb, bias_lsb;
2264 short bias_value;
2265
2266 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B5_STATUS);
2267 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B4_STATUS);
2268 bias_value = (bias_msb << 8) | bias_lsb;
2269 return bias_value;
2270}
2271
2272static short tabla_codec_measure_micbias_voltage(struct snd_soc_codec *codec,
2273 int dce)
2274{
2275 short bias_value;
2276
Bradley Rubincb1e2732011-06-23 16:49:20 -07002277 if (dce) {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002278 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
2279 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
2280 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
2281 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
2282 usleep_range(60000, 60000);
2283 bias_value = tabla_codec_read_dce_result(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002284 } else {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002285 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002286 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
2287 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002288 usleep_range(5000, 5000);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002289 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002290 usleep_range(50, 50);
2291 bias_value = tabla_codec_read_sta_result(codec);
2292 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
2293 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002294 }
2295
Bradley Rubincb1e2732011-06-23 16:49:20 -07002296 pr_debug("read microphone bias value %x\n", bias_value);
2297 return bias_value;
2298}
2299
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07002300static short tabla_codec_setup_hs_polling(struct snd_soc_codec *codec)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002301{
2302 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2303 struct tabla_mbhc_calibration *calibration = tabla->calibration;
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07002304 short bias_value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002305
2306 if (!calibration) {
2307 pr_err("Error, no tabla calibration\n");
Bradley Rubincb1e2732011-06-23 16:49:20 -07002308 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002309 }
2310
2311 tabla->mbhc_polling_active = true;
2312
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002313 if (!tabla->mclk_enabled) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002314 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_MBHC_MODE);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002315 tabla_enable_rx_bias(codec, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002316 tabla_codec_enable_clock_block(codec, 1);
2317 }
2318
2319 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x01);
2320
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002321 snd_soc_update_bits(codec, TABLA_A_TX_COM_BIAS, 0xE0, 0xE0);
2322
Patrick Lai3043fba2011-08-01 14:15:57 -07002323
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002324 snd_soc_update_bits(codec,
2325 tabla->mbhc_bias_regs.cfilt_ctl, 0x70, 0x00);
Patrick Lai3043fba2011-08-01 14:15:57 -07002326
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002327 snd_soc_update_bits(codec,
2328 tabla->mbhc_bias_regs.ctl_reg, 0x1F, 0x16);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002329
2330 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002331 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002332
2333 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x80);
2334 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x1F, 0x1C);
2335 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x40, 0x40);
2336
2337 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002338 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
2339 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002340
Bradley Rubincb1e2732011-06-23 16:49:20 -07002341 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x6, 0x6);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002342 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
2343
Bradley Rubincb1e2732011-06-23 16:49:20 -07002344 tabla_codec_calibrate_hs_polling(codec);
2345
2346 bias_value = tabla_codec_measure_micbias_voltage(codec, 0);
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002347 snd_soc_update_bits(codec,
2348 tabla->mbhc_bias_regs.cfilt_ctl, 0x40, 0x40);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002349 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002350
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07002351 return bias_value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002352}
2353
2354static int tabla_codec_enable_hs_detect(struct snd_soc_codec *codec,
2355 int insertion)
2356{
2357 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2358 struct tabla_mbhc_calibration *calibration = tabla->calibration;
2359 int central_bias_enabled = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002360
2361 if (!calibration) {
2362 pr_err("Error, no tabla calibration\n");
2363 return -EINVAL;
2364 }
2365
2366 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0);
2367
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07002368 if (insertion) {
2369 /* Make sure mic bias and Mic line schmitt trigger
2370 * are turned OFF
2371 */
2372 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg,
2373 0x81, 0x01);
2374 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2375 0x90, 0x00);
2376
2377 /* Enable HPH Schmitt Trigger */
2378 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x13);
2379 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x0C,
2380 calibration->hph_current << 2);
2381
2382 /* Turn off HPH PAs during insertion detection to avoid false
2383 * insertion interrupts
2384 */
2385 if (tabla->mbhc_micbias_switched)
2386 tabla_codec_switch_micbias(codec, 0);
2387 snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00);
2388
2389 /* setup for insetion detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002390 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07002391 } else {
2392 /* Make sure the HPH schmitt trigger is OFF */
2393 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x12, 0x00);
2394
2395 /* enable the mic line schmitt trigger */
2396 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x60,
2397 calibration->mic_current << 5);
2398 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2399 0x80, 0x80);
2400 usleep_range(calibration->mic_pid, calibration->mic_pid);
2401 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2402 0x10, 0x10);
2403
2404 /* Setup for low power removal detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002405 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0x2);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07002406 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002407
2408 if (snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x4) {
2409 if (!(tabla->clock_active)) {
2410 tabla_codec_enable_config_mode(codec, 1);
2411 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07002412 0x06, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002413 usleep_range(calibration->shutdown_plug_removal,
2414 calibration->shutdown_plug_removal);
2415 tabla_codec_enable_config_mode(codec, 0);
2416 } else
2417 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07002418 0x06, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002419 }
2420
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002421 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.int_rbias, 0x80, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002422
2423 /* If central bandgap disabled */
2424 if (!(snd_soc_read(codec, TABLA_A_PIN_CTL_OE1) & 1)) {
2425 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x3, 0x3);
2426 usleep_range(calibration->bg_fast_settle,
2427 calibration->bg_fast_settle);
2428 central_bias_enabled = 1;
2429 }
2430
2431 /* If LDO_H disabled */
2432 if (snd_soc_read(codec, TABLA_A_PIN_CTL_OE0) & 0x80) {
2433 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x10, 0);
2434 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0x80);
2435 usleep_range(calibration->tldoh, calibration->tldoh);
2436 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0);
2437
2438 if (central_bias_enabled)
2439 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x1, 0);
2440 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002441
2442 snd_soc_update_bits(codec, TABLA_A_MICB_4_MBHC, 0x3, calibration->bias);
2443
2444 tabla_enable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
2445 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0x1);
2446 return 0;
2447}
2448
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07002449static void btn0_lpress_fn(struct work_struct *work)
2450{
2451 struct delayed_work *delayed_work;
2452 struct tabla_priv *tabla;
2453
2454 pr_debug("%s:\n", __func__);
2455
2456 delayed_work = to_delayed_work(work);
2457 tabla = container_of(delayed_work, struct tabla_priv, btn0_dwork);
2458
2459 if (tabla) {
2460 if (tabla->button_jack) {
2461 pr_debug("%s: Reporting long button press event\n",
2462 __func__);
2463 snd_soc_jack_report(tabla->button_jack, SND_JACK_BTN_0,
2464 SND_JACK_BTN_0);
2465 }
2466 } else {
2467 pr_err("%s: Bad tabla private data\n", __func__);
2468 }
2469
2470}
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002471
Bradley Rubincb1e2732011-06-23 16:49:20 -07002472int tabla_hs_detect(struct snd_soc_codec *codec,
2473 struct snd_soc_jack *headset_jack, struct snd_soc_jack *button_jack,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002474 struct tabla_mbhc_calibration *calibration)
2475{
2476 struct tabla_priv *tabla;
2477 if (!codec || !calibration) {
2478 pr_err("Error: no codec or calibration\n");
2479 return -EINVAL;
2480 }
2481 tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002482 tabla->headset_jack = headset_jack;
2483 tabla->button_jack = button_jack;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002484 tabla->calibration = calibration;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002485 tabla_get_mbhc_micbias_regs(codec, &tabla->mbhc_bias_regs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002486
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07002487 INIT_DELAYED_WORK(&tabla->btn0_dwork, btn0_lpress_fn);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002488 return tabla_codec_enable_hs_detect(codec, 1);
2489}
2490EXPORT_SYMBOL_GPL(tabla_hs_detect);
2491
Bradley Rubincb1e2732011-06-23 16:49:20 -07002492static irqreturn_t tabla_dce_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002493{
2494 struct tabla_priv *priv = data;
2495 struct snd_soc_codec *codec = priv->codec;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07002496 short bias_value;
Bradley Rubincb1e2732011-06-23 16:49:20 -07002497
2498 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL);
2499 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
2500
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002501 bias_value = tabla_codec_read_dce_result(codec);
Bhalchandra Gajare30cf4842011-10-17 18:12:52 -07002502 pr_debug("%s: button press interrupt, bias value(DCE Read)=%d\n",
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07002503 __func__, bias_value);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002504
Bhalchandra Gajare30cf4842011-10-17 18:12:52 -07002505 bias_value = tabla_codec_read_sta_result(codec);
2506 pr_debug("%s: button press interrupt, bias value(STA Read)=%d\n",
2507 __func__, bias_value);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07002508 /*
2509 * TODO: If button pressed is not button 0,
2510 * report the button press event immediately.
2511 */
2512 priv->buttons_pressed |= SND_JACK_BTN_0;
Bradley Rubincb1e2732011-06-23 16:49:20 -07002513
Bradley Rubin688c66a2011-08-16 12:25:13 -07002514 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, 0x09);
2515 msleep(100);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002516
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07002517 schedule_delayed_work(&priv->btn0_dwork, msecs_to_jiffies(400));
2518
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002519 return IRQ_HANDLED;
2520}
2521
Bradley Rubincb1e2732011-06-23 16:49:20 -07002522static irqreturn_t tabla_release_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002523{
2524 struct tabla_priv *priv = data;
2525 struct snd_soc_codec *codec = priv->codec;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07002526 int ret, mic_voltage;
2527
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002528 pr_debug("%s\n", __func__);
2529 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07002530
Bhalchandra Gajare30cf4842011-10-17 18:12:52 -07002531 mic_voltage = tabla_codec_read_dce_result(codec);
2532 pr_debug("%s: Microphone Voltage on release(DCE Read) = %d\n",
2533 __func__, mic_voltage);
2534
Bradley Rubincb1e2732011-06-23 16:49:20 -07002535 if (priv->buttons_pressed & SND_JACK_BTN_0) {
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07002536 ret = cancel_delayed_work(&priv->btn0_dwork);
2537
2538 if (ret == 0) {
2539
2540 pr_debug("%s: Reporting long button release event\n",
2541 __func__);
2542 if (priv->button_jack) {
2543 snd_soc_jack_report(priv->button_jack, 0,
2544 SND_JACK_BTN_0);
2545 }
2546
2547 } else {
2548
2549 mic_voltage =
2550 tabla_codec_measure_micbias_voltage(codec, 0);
Bhalchandra Gajare30cf4842011-10-17 18:12:52 -07002551 pr_debug("%s: Mic Voltage on release(new STA) = %d\n",
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07002552 __func__, mic_voltage);
2553
2554 if (mic_voltage < -2000 || mic_voltage > -670) {
2555 pr_debug("%s: Fake buttton press interrupt\n",
2556 __func__);
2557 } else {
2558
2559 if (priv->button_jack) {
2560 pr_debug("%s:reporting short button press and release\n",
2561 __func__);
2562
2563 snd_soc_jack_report(priv->button_jack,
2564 SND_JACK_BTN_0, SND_JACK_BTN_0);
2565 snd_soc_jack_report(priv->button_jack,
2566 0, SND_JACK_BTN_0);
2567 }
2568 }
2569 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002570
Bradley Rubincb1e2732011-06-23 16:49:20 -07002571 priv->buttons_pressed &= ~SND_JACK_BTN_0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002572 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002573
Bradley Rubin688c66a2011-08-16 12:25:13 -07002574 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, 0x08);
2575 tabla_codec_start_hs_polling(codec);
2576
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002577 return IRQ_HANDLED;
2578}
2579
Bradley Rubincb1e2732011-06-23 16:49:20 -07002580static void tabla_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec)
2581{
2582 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2583 struct tabla_mbhc_calibration *calibration = tabla->calibration;
Bradley Rubincb1e2732011-06-23 16:49:20 -07002584
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002585 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07002586 tabla_codec_enable_config_mode(codec, 1);
2587
2588 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
2589 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x6, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002590
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002591 snd_soc_update_bits(codec,
2592 tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002593 usleep_range(calibration->shutdown_plug_removal,
2594 calibration->shutdown_plug_removal);
2595
2596 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0xA, 0x8);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002597 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07002598 tabla_codec_enable_config_mode(codec, 0);
2599
2600 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x00);
2601}
2602
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002603static void tabla_codec_shutdown_hs_polling(struct snd_soc_codec *codec)
2604{
2605 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002606
2607 tabla_codec_shutdown_hs_removal_detect(codec);
2608
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002609 if (!tabla->mclk_enabled) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002610 snd_soc_update_bits(codec, TABLA_A_TX_COM_BIAS, 0xE0, 0x00);
2611 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_AUDIO_MODE);
2612 tabla_codec_enable_clock_block(codec, 0);
2613 }
2614
2615 tabla->mbhc_polling_active = false;
2616}
2617
Bradley Rubincb1e2732011-06-23 16:49:20 -07002618static irqreturn_t tabla_hs_insert_irq(int irq, void *data)
2619{
2620 struct tabla_priv *priv = data;
2621 struct snd_soc_codec *codec = priv->codec;
Bradley Rubin355611a2011-08-24 14:01:18 -07002622 int ldo_h_on, micb_cfilt_on;
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07002623 short mic_voltage;
2624 short threshold_no_mic = 0xF7F6;
2625 short threshold_fake_insert = 0xFD30;
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07002626 u8 is_removal;
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07002627
Bradley Rubincb1e2732011-06-23 16:49:20 -07002628
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002629 pr_debug("%s\n", __func__);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002630 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07002631 is_removal = snd_soc_read(codec, TABLA_A_CDC_MBHC_INT_CTL) & 0x02;
2632 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x03, 0x00);
2633
2634 /* Turn off both HPH and MIC line schmitt triggers */
2635 snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg,
2636 0x90, 0x00);
2637 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002638
Bradley Rubin355611a2011-08-24 14:01:18 -07002639 ldo_h_on = snd_soc_read(codec, TABLA_A_LDO_H_MODE_1) & 0x80;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002640 micb_cfilt_on = snd_soc_read(codec,
2641 priv->mbhc_bias_regs.cfilt_ctl) & 0x80;
Bradley Rubin355611a2011-08-24 14:01:18 -07002642
2643 if (!ldo_h_on)
2644 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x80, 0x80);
2645 if (!micb_cfilt_on)
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002646 snd_soc_update_bits(codec, priv->mbhc_bias_regs.cfilt_ctl,
2647 0x80, 0x80);
Bradley Rubin355611a2011-08-24 14:01:18 -07002648
Bradley Rubincb1e2732011-06-23 16:49:20 -07002649 usleep_range(priv->calibration->setup_plug_removal_delay,
2650 priv->calibration->setup_plug_removal_delay);
2651
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07002652 if (!ldo_h_on)
2653 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x80, 0x0);
2654 if (!micb_cfilt_on)
2655 snd_soc_update_bits(codec, priv->mbhc_bias_regs.cfilt_ctl,
2656 0x80, 0x0);
2657
2658 if (is_removal) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002659 /*
2660 * If headphone is removed while playback is in progress,
2661 * it is possible that micbias will be switched to VDDIO.
2662 */
2663 if (priv->mbhc_micbias_switched)
2664 tabla_codec_switch_micbias(codec, 0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002665 if (priv->headset_jack) {
2666 pr_debug("%s: Reporting removal\n", __func__);
2667 snd_soc_jack_report(priv->headset_jack, 0,
2668 SND_JACK_HEADSET);
2669 }
2670 tabla_codec_shutdown_hs_removal_detect(codec);
2671 tabla_codec_enable_hs_detect(codec, 1);
2672 return IRQ_HANDLED;
2673 }
2674
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07002675 mic_voltage = tabla_codec_setup_hs_polling(codec);
Bradley Rubin355611a2011-08-24 14:01:18 -07002676
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07002677 if (mic_voltage > threshold_fake_insert) {
2678 pr_debug("%s: Fake insertion interrupt, mic_voltage = %x\n",
2679 __func__, mic_voltage);
2680 tabla_codec_enable_hs_detect(codec, 1);
2681 } else if (mic_voltage < threshold_no_mic) {
2682 pr_debug("%s: Headphone Detected, mic_voltage = %x\n",
2683 __func__, mic_voltage);
2684
Bradley Rubincb1e2732011-06-23 16:49:20 -07002685 if (priv->headset_jack) {
2686 pr_debug("%s: Reporting insertion %d\n", __func__,
2687 SND_JACK_HEADPHONE);
2688 snd_soc_jack_report(priv->headset_jack,
2689 SND_JACK_HEADPHONE, SND_JACK_HEADSET);
2690 }
2691 tabla_codec_shutdown_hs_polling(codec);
2692 tabla_codec_enable_hs_detect(codec, 0);
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07002693
2694 } else {
2695 pr_debug("%s: Headset detected, mic_voltage = %x\n",
2696 __func__, mic_voltage);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002697 if (priv->headset_jack) {
2698 pr_debug("%s: Reporting insertion %d\n", __func__,
2699 SND_JACK_HEADSET);
2700 snd_soc_jack_report(priv->headset_jack,
2701 SND_JACK_HEADSET, SND_JACK_HEADSET);
2702 }
2703 tabla_codec_start_hs_polling(codec);
2704 }
2705
2706 return IRQ_HANDLED;
2707}
2708
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002709static irqreturn_t tabla_hs_remove_irq(int irq, void *data)
2710{
2711 struct tabla_priv *priv = data;
2712 struct snd_soc_codec *codec = priv->codec;
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002713 short bias_value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002714
2715 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL);
2716 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002717 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002718
2719 usleep_range(priv->calibration->shutdown_plug_removal,
2720 priv->calibration->shutdown_plug_removal);
2721
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002722 bias_value = tabla_codec_measure_micbias_voltage(codec, 1);
2723 pr_debug("removal interrupt, bias value is %d\n", bias_value);
2724
2725 if (bias_value < -90) {
2726 pr_debug("False alarm, headset not actually removed\n");
2727 tabla_codec_start_hs_polling(codec);
2728 } else {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002729 /*
2730 * If this removal is not false, first check the micbias
2731 * switch status and switch it to LDOH if it is already
2732 * switched to VDDIO.
2733 */
2734 if (priv->mbhc_micbias_switched)
2735 tabla_codec_switch_micbias(codec, 0);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002736 if (priv->headset_jack) {
2737 pr_debug("%s: Reporting removal\n", __func__);
2738 snd_soc_jack_report(priv->headset_jack, 0,
2739 SND_JACK_HEADSET);
2740 }
2741 tabla_codec_shutdown_hs_polling(codec);
2742
2743 tabla_codec_enable_hs_detect(codec, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002744 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002745 return IRQ_HANDLED;
2746}
2747
2748static unsigned long slimbus_value;
2749
2750static irqreturn_t tabla_slimbus_irq(int irq, void *data)
2751{
2752 struct tabla_priv *priv = data;
2753 struct snd_soc_codec *codec = priv->codec;
2754 int i, j;
2755 u8 val;
2756
2757 for (i = 0; i < TABLA_SLIM_NUM_PORT_REG; i++) {
2758 slimbus_value = tabla_interface_reg_read(codec->control_data,
2759 TABLA_SLIM_PGD_PORT_INT_STATUS0 + i);
2760 for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) {
2761 val = tabla_interface_reg_read(codec->control_data,
2762 TABLA_SLIM_PGD_PORT_INT_SOURCE0 + i*8 + j);
2763 if (val & 0x1)
2764 pr_err_ratelimited("overflow error on port %x,"
2765 " value %x\n", i*8 + j, val);
2766 if (val & 0x2)
2767 pr_err_ratelimited("underflow error on port %x,"
2768 " value %x\n", i*8 + j, val);
2769 }
2770 tabla_interface_reg_write(codec->control_data,
2771 TABLA_SLIM_PGD_PORT_INT_CLR0 + i, 0xFF);
2772 }
2773
2774 return IRQ_HANDLED;
2775}
2776
Patrick Lai3043fba2011-08-01 14:15:57 -07002777
2778static int tabla_handle_pdata(struct tabla_priv *tabla)
2779{
2780 struct snd_soc_codec *codec = tabla->codec;
2781 struct tabla_pdata *pdata = tabla->pdata;
2782 int k1, k2, k3, rc = 0;
2783
2784 if (!pdata) {
2785 rc = -ENODEV;
2786 goto done;
2787 }
2788
2789 /* Make sure settings are correct */
2790 if ((pdata->micbias.ldoh_v > TABLA_LDOH_2P85_V) ||
2791 (pdata->micbias.bias1_cfilt_sel > TABLA_CFILT3_SEL) ||
2792 (pdata->micbias.bias2_cfilt_sel > TABLA_CFILT3_SEL) ||
2793 (pdata->micbias.bias3_cfilt_sel > TABLA_CFILT3_SEL) ||
2794 (pdata->micbias.bias4_cfilt_sel > TABLA_CFILT3_SEL)) {
2795 rc = -EINVAL;
2796 goto done;
2797 }
2798
2799 /* figure out k value */
2800 k1 = tabla_find_k_value(pdata->micbias.ldoh_v,
2801 pdata->micbias.cfilt1_mv);
2802 k2 = tabla_find_k_value(pdata->micbias.ldoh_v,
2803 pdata->micbias.cfilt2_mv);
2804 k3 = tabla_find_k_value(pdata->micbias.ldoh_v,
2805 pdata->micbias.cfilt3_mv);
2806
2807 if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) {
2808 rc = -EINVAL;
2809 goto done;
2810 }
2811
2812 /* Set voltage level and always use LDO */
2813 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x0C,
2814 (pdata->micbias.ldoh_v << 2));
2815
2816 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_1_VAL, 0xFC,
2817 (k1 << 2));
2818 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_2_VAL, 0xFC,
2819 (k2 << 2));
2820 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_3_VAL, 0xFC,
2821 (k3 << 2));
2822
2823 snd_soc_update_bits(codec, TABLA_A_MICB_1_CTL, 0x60,
2824 (pdata->micbias.bias1_cfilt_sel << 5));
2825 snd_soc_update_bits(codec, TABLA_A_MICB_2_CTL, 0x60,
2826 (pdata->micbias.bias2_cfilt_sel << 5));
2827 snd_soc_update_bits(codec, TABLA_A_MICB_3_CTL, 0x60,
2828 (pdata->micbias.bias3_cfilt_sel << 5));
2829 snd_soc_update_bits(codec, TABLA_A_MICB_4_CTL, 0x60,
2830 (pdata->micbias.bias4_cfilt_sel << 5));
2831
2832done:
2833 return rc;
2834}
2835
Kiran Kandi1f6fd722011-08-11 10:36:11 -07002836static const struct tabla_reg_mask_val tabla_1_1_reg_defaults[] = {
2837
2838 /* Tabla 1.1 MICBIAS changes */
2839 TABLA_REG_VAL(TABLA_A_MICB_1_INT_RBIAS, 0x24),
2840 TABLA_REG_VAL(TABLA_A_MICB_2_INT_RBIAS, 0x24),
2841 TABLA_REG_VAL(TABLA_A_MICB_3_INT_RBIAS, 0x24),
2842 TABLA_REG_VAL(TABLA_A_MICB_4_INT_RBIAS, 0x24),
2843
2844 /* Tabla 1.1 HPH changes */
2845 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_PA, 0x57),
2846 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_LDO, 0x56),
2847
2848 /* Tabla 1.1 EAR PA changes */
2849 TABLA_REG_VAL(TABLA_A_RX_EAR_BIAS_PA, 0xA6),
2850 TABLA_REG_VAL(TABLA_A_RX_EAR_GAIN, 0x02),
2851 TABLA_REG_VAL(TABLA_A_RX_EAR_VCM, 0x03),
2852
2853 /* Tabla 1.1 Lineout_5 Changes */
2854 TABLA_REG_VAL(TABLA_A_RX_LINE_5_GAIN, 0x10),
2855
2856 /* Tabla 1.1 RX Changes */
2857 TABLA_REG_VAL(TABLA_A_CDC_RX1_B5_CTL, 0x78),
2858 TABLA_REG_VAL(TABLA_A_CDC_RX2_B5_CTL, 0x78),
2859 TABLA_REG_VAL(TABLA_A_CDC_RX3_B5_CTL, 0x78),
2860 TABLA_REG_VAL(TABLA_A_CDC_RX4_B5_CTL, 0x78),
2861 TABLA_REG_VAL(TABLA_A_CDC_RX5_B5_CTL, 0x78),
2862 TABLA_REG_VAL(TABLA_A_CDC_RX6_B5_CTL, 0x78),
2863 TABLA_REG_VAL(TABLA_A_CDC_RX7_B5_CTL, 0x78),
2864
2865 /* Tabla 1.1 RX1 and RX2 Changes */
2866 TABLA_REG_VAL(TABLA_A_CDC_RX1_B6_CTL, 0xA0),
2867 TABLA_REG_VAL(TABLA_A_CDC_RX2_B6_CTL, 0xA0),
2868
2869 /* Tabla 1.1 RX3 to RX7 Changes */
2870 TABLA_REG_VAL(TABLA_A_CDC_RX3_B6_CTL, 0x80),
2871 TABLA_REG_VAL(TABLA_A_CDC_RX4_B6_CTL, 0x80),
2872 TABLA_REG_VAL(TABLA_A_CDC_RX5_B6_CTL, 0x80),
2873 TABLA_REG_VAL(TABLA_A_CDC_RX6_B6_CTL, 0x80),
2874 TABLA_REG_VAL(TABLA_A_CDC_RX7_B6_CTL, 0x80),
2875
2876 /* Tabla 1.1 CLASSG Changes */
2877 TABLA_REG_VAL(TABLA_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B),
2878};
2879
2880static const struct tabla_reg_mask_val tabla_2_0_reg_defaults[] = {
2881
2882 /* Tabla 2.0 MICBIAS changes */
2883 TABLA_REG_VAL(TABLA_A_MICB_2_MBHC, 0x02),
2884};
2885
2886static void tabla_update_reg_defaults(struct snd_soc_codec *codec)
2887{
2888 u32 i;
2889
2890 for (i = 0; i < ARRAY_SIZE(tabla_1_1_reg_defaults); i++)
2891 snd_soc_write(codec, tabla_1_1_reg_defaults[i].reg,
2892 tabla_1_1_reg_defaults[i].val);
2893
2894 for (i = 0; i < ARRAY_SIZE(tabla_2_0_reg_defaults); i++)
2895 snd_soc_write(codec, tabla_2_0_reg_defaults[i].reg,
2896 tabla_2_0_reg_defaults[i].val);
2897}
2898
2899static const struct tabla_reg_mask_val tabla_codec_reg_init_val[] = {
2900
2901 /* Initialize gain registers to use register gain */
2902 {TABLA_A_RX_HPH_L_GAIN, 0x10, 0x10},
2903 {TABLA_A_RX_HPH_R_GAIN, 0x10, 0x10},
2904 {TABLA_A_RX_LINE_1_GAIN, 0x10, 0x10},
2905 {TABLA_A_RX_LINE_2_GAIN, 0x10, 0x10},
2906 {TABLA_A_RX_LINE_3_GAIN, 0x10, 0x10},
2907 {TABLA_A_RX_LINE_4_GAIN, 0x10, 0x10},
2908
2909 /* Initialize mic biases to differential mode */
2910 {TABLA_A_MICB_1_INT_RBIAS, 0x24, 0x24},
2911 {TABLA_A_MICB_2_INT_RBIAS, 0x24, 0x24},
2912 {TABLA_A_MICB_3_INT_RBIAS, 0x24, 0x24},
2913 {TABLA_A_MICB_4_INT_RBIAS, 0x24, 0x24},
2914
2915 {TABLA_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14},
2916
2917 /* Use 16 bit sample size for TX1 to TX6 */
2918 {TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20},
2919 {TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20},
2920 {TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20},
2921 {TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20},
2922 {TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20},
2923 {TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0x30, 0x20},
2924
2925 /* Use 16 bit sample size for TX7 to TX10 */
2926 {TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0x60, 0x40},
2927 {TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0x60, 0x40},
2928 {TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0x60, 0x40},
2929 {TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0x60, 0x40},
2930
2931 /* Use 16 bit sample size for RX */
2932 {TABLA_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA},
2933 {TABLA_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0xAA},
2934
2935 /*enable HPF filter for TX paths */
2936 {TABLA_A_CDC_TX1_MUX_CTL, 0x8, 0x0},
2937 {TABLA_A_CDC_TX2_MUX_CTL, 0x8, 0x0},
2938 {TABLA_A_CDC_TX3_MUX_CTL, 0x8, 0x0},
2939 {TABLA_A_CDC_TX4_MUX_CTL, 0x8, 0x0},
2940 {TABLA_A_CDC_TX5_MUX_CTL, 0x8, 0x0},
2941 {TABLA_A_CDC_TX6_MUX_CTL, 0x8, 0x0},
2942 {TABLA_A_CDC_TX7_MUX_CTL, 0x8, 0x0},
2943 {TABLA_A_CDC_TX8_MUX_CTL, 0x8, 0x0},
2944 {TABLA_A_CDC_TX9_MUX_CTL, 0x8, 0x0},
2945 {TABLA_A_CDC_TX10_MUX_CTL, 0x8, 0x0},
2946};
2947
2948static void tabla_codec_init_reg(struct snd_soc_codec *codec)
2949{
2950 u32 i;
2951
2952 for (i = 0; i < ARRAY_SIZE(tabla_codec_reg_init_val); i++)
2953 snd_soc_update_bits(codec, tabla_codec_reg_init_val[i].reg,
2954 tabla_codec_reg_init_val[i].mask,
2955 tabla_codec_reg_init_val[i].val);
2956}
2957
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002958static int tabla_codec_probe(struct snd_soc_codec *codec)
2959{
2960 struct tabla *control;
2961 struct tabla_priv *tabla;
2962 struct snd_soc_dapm_context *dapm = &codec->dapm;
2963 int ret = 0;
2964 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002965
2966 codec->control_data = dev_get_drvdata(codec->dev->parent);
2967 control = codec->control_data;
2968
2969 tabla = kzalloc(sizeof(struct tabla_priv), GFP_KERNEL);
2970 if (!tabla) {
2971 dev_err(codec->dev, "Failed to allocate private data\n");
2972 return -ENOMEM;
2973 }
2974
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002975 /* Make sure mbhc micbias register addresses are zeroed out */
2976 memset(&tabla->mbhc_bias_regs, 0,
2977 sizeof(struct mbhc_micbias_regs));
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002978 tabla->cfilt_k_value = 0;
2979 tabla->mbhc_micbias_switched = false;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002980
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002981 snd_soc_codec_set_drvdata(codec, tabla);
2982
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002983 tabla->mclk_enabled = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002984 tabla->bandgap_type = TABLA_BANDGAP_OFF;
2985 tabla->clock_active = false;
2986 tabla->config_mode_active = false;
2987 tabla->mbhc_polling_active = false;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002988 tabla->no_mic_headset_override = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002989 tabla->codec = codec;
Patrick Lai3043fba2011-08-01 14:15:57 -07002990 tabla->pdata = dev_get_platdata(codec->dev->parent);
2991
2992 ret = tabla_handle_pdata(tabla);
2993
2994 if (IS_ERR_VALUE(ret)) {
2995 pr_err("%s: bad pdata\n", __func__);
2996 goto err_pdata;
2997 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002998
Kiran Kandi1f6fd722011-08-11 10:36:11 -07002999 tabla_update_reg_defaults(codec);
3000 tabla_codec_init_reg(codec);
3001
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003002 /* TODO only enable bandgap when necessary in order to save power */
3003 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_AUDIO_MODE);
3004 tabla_codec_enable_clock_block(codec, 0);
3005
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003006 snd_soc_add_controls(codec, tabla_snd_controls,
3007 ARRAY_SIZE(tabla_snd_controls));
3008 snd_soc_dapm_new_controls(dapm, tabla_dapm_widgets,
3009 ARRAY_SIZE(tabla_dapm_widgets));
3010 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
3011 snd_soc_dapm_sync(dapm);
3012
3013 ret = tabla_request_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION,
3014 tabla_hs_insert_irq, "Headset insert detect", tabla);
3015 if (ret) {
3016 pr_err("%s: Failed to request irq %d\n", __func__,
3017 TABLA_IRQ_MBHC_INSERTION);
3018 goto err_insert_irq;
3019 }
3020 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
3021
3022 ret = tabla_request_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL,
3023 tabla_hs_remove_irq, "Headset remove detect", tabla);
3024 if (ret) {
3025 pr_err("%s: Failed to request irq %d\n", __func__,
3026 TABLA_IRQ_MBHC_REMOVAL);
3027 goto err_remove_irq;
3028 }
3029 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL);
3030
3031 ret = tabla_request_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07003032 tabla_dce_handler, "DC Estimation detect", tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003033 if (ret) {
3034 pr_err("%s: Failed to request irq %d\n", __func__,
3035 TABLA_IRQ_MBHC_POTENTIAL);
3036 goto err_potential_irq;
3037 }
3038 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
3039
Bradley Rubincb1e2732011-06-23 16:49:20 -07003040 ret = tabla_request_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE,
3041 tabla_release_handler, "Button Release detect", tabla);
3042 if (ret) {
3043 pr_err("%s: Failed to request irq %d\n", __func__,
3044 TABLA_IRQ_MBHC_RELEASE);
3045 goto err_release_irq;
3046 }
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003047 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003048
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003049 ret = tabla_request_irq(codec->control_data, TABLA_IRQ_SLIMBUS,
3050 tabla_slimbus_irq, "SLIMBUS Slave", tabla);
3051 if (ret) {
3052 pr_err("%s: Failed to request irq %d\n", __func__,
3053 TABLA_IRQ_SLIMBUS);
3054 goto err_slimbus_irq;
3055 }
3056
3057 for (i = 0; i < TABLA_SLIM_NUM_PORT_REG; i++)
3058 tabla_interface_reg_write(codec->control_data,
3059 TABLA_SLIM_PGD_PORT_INT_EN0 + i, 0xFF);
3060
Bradley Rubincb3950a2011-08-18 13:07:26 -07003061#ifdef CONFIG_DEBUG_FS
3062 debug_tabla_priv = tabla;
3063#endif
3064
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003065 return ret;
3066
3067err_slimbus_irq:
Bradley Rubincb1e2732011-06-23 16:49:20 -07003068 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, tabla);
3069err_release_irq:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003070 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, tabla);
3071err_potential_irq:
3072 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, tabla);
3073err_remove_irq:
3074 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, tabla);
3075err_insert_irq:
Patrick Lai3043fba2011-08-01 14:15:57 -07003076err_pdata:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003077 kfree(tabla);
3078 return ret;
3079}
3080static int tabla_codec_remove(struct snd_soc_codec *codec)
3081{
3082 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3083 tabla_free_irq(codec->control_data, TABLA_IRQ_SLIMBUS, tabla);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003084 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003085 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, tabla);
3086 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, tabla);
3087 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, tabla);
3088 tabla_codec_disable_clock_block(codec);
3089 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF);
3090 kfree(tabla);
3091 return 0;
3092}
3093static struct snd_soc_codec_driver soc_codec_dev_tabla = {
3094 .probe = tabla_codec_probe,
3095 .remove = tabla_codec_remove,
3096 .read = tabla_read,
3097 .write = tabla_write,
3098
3099 .readable_register = tabla_readable,
3100 .volatile_register = tabla_volatile,
3101
3102 .reg_cache_size = TABLA_CACHE_SIZE,
3103 .reg_cache_default = tabla_reg_defaults,
3104 .reg_word_size = 1,
3105};
Bradley Rubincb3950a2011-08-18 13:07:26 -07003106
3107#ifdef CONFIG_DEBUG_FS
3108static struct dentry *debugfs_poke;
3109
3110static int codec_debug_open(struct inode *inode, struct file *file)
3111{
3112 file->private_data = inode->i_private;
3113 return 0;
3114}
3115
3116static ssize_t codec_debug_write(struct file *filp,
3117 const char __user *ubuf, size_t cnt, loff_t *ppos)
3118{
3119 char lbuf[32];
3120 char *buf;
3121 int rc;
3122
3123 if (cnt > sizeof(lbuf) - 1)
3124 return -EINVAL;
3125
3126 rc = copy_from_user(lbuf, ubuf, cnt);
3127 if (rc)
3128 return -EFAULT;
3129
3130 lbuf[cnt] = '\0';
3131 buf = (char *)lbuf;
3132 debug_tabla_priv->no_mic_headset_override = (*strsep(&buf, " ") == '0')
3133 ? false : true;
3134
3135 return rc;
3136}
3137
3138static const struct file_operations codec_debug_ops = {
3139 .open = codec_debug_open,
3140 .write = codec_debug_write,
3141};
3142#endif
3143
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003144static int __devinit tabla_probe(struct platform_device *pdev)
3145{
Bradley Rubincb3950a2011-08-18 13:07:26 -07003146#ifdef CONFIG_DEBUG_FS
3147 debugfs_poke = debugfs_create_file("TRRS",
3148 S_IFREG | S_IRUGO, NULL, (void *) "TRRS", &codec_debug_ops);
3149
3150#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003151 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla,
3152 tabla_dai, ARRAY_SIZE(tabla_dai));
3153}
3154static int __devexit tabla_remove(struct platform_device *pdev)
3155{
3156 snd_soc_unregister_codec(&pdev->dev);
Bradley Rubincb3950a2011-08-18 13:07:26 -07003157
3158#ifdef CONFIG_DEBUG_FS
3159 debugfs_remove(debugfs_poke);
3160#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003161 return 0;
3162}
3163static struct platform_driver tabla_codec_driver = {
3164 .probe = tabla_probe,
3165 .remove = tabla_remove,
3166 .driver = {
3167 .name = "tabla_codec",
3168 .owner = THIS_MODULE,
3169 },
3170};
3171
3172static int __init tabla_codec_init(void)
3173{
3174 return platform_driver_register(&tabla_codec_driver);
3175}
3176
3177static void __exit tabla_codec_exit(void)
3178{
3179 platform_driver_unregister(&tabla_codec_driver);
3180}
3181
3182module_init(tabla_codec_init);
3183module_exit(tabla_codec_exit);
3184
3185MODULE_DESCRIPTION("Tabla codec driver");
3186MODULE_VERSION("1.0");
3187MODULE_LICENSE("GPL v2");