blob: 7df3537ebc776e7e79e15ef930bc924908647dc4 [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>
Santosh Mardie15e2302011-11-15 10:39:23 +053017#include <linux/device.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070018#include <linux/printk.h>
19#include <linux/ratelimit.h>
Bradley Rubincb3950a2011-08-18 13:07:26 -070020#include <linux/debugfs.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070021#include <linux/mfd/wcd9310/core.h>
22#include <linux/mfd/wcd9310/registers.h>
Patrick Lai3043fba2011-08-01 14:15:57 -070023#include <linux/mfd/wcd9310/pdata.h>
Santosh Mardie15e2302011-11-15 10:39:23 +053024#include <sound/pcm.h>
25#include <sound/pcm_params.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070026#include <sound/jack.h>
27#include <sound/soc.h>
28#include <sound/soc-dapm.h>
29#include <sound/tlv.h>
30#include <linux/bitops.h>
31#include <linux/delay.h>
32#include "wcd9310.h"
33
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -070034#define WCD9310_RATES (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|\
35 SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_48000)
36
37#define NUM_DECIMATORS 10
38#define NUM_INTERPOLATORS 7
39#define BITS_PER_REG 8
40#define TABLA_RX_DAI_ID 1
41#define TABLA_TX_DAI_ID 2
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -080042#define TABLA_CFILT_FAST_MODE 0x00
43#define TABLA_CFILT_SLOW_MODE 0x40
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -070044
Patrick Lai49efeac2011-11-03 11:01:12 -070045#define TABLA_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | SND_JACK_OC_HPHR)
46
Santosh Mardie15e2302011-11-15 10:39:23 +053047#define TABLA_I2S_MASTER_MODE_MASK 0x08
48
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070049static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
50static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
51static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
52
53enum tabla_bandgap_type {
54 TABLA_BANDGAP_OFF = 0,
55 TABLA_BANDGAP_AUDIO_MODE,
56 TABLA_BANDGAP_MBHC_MODE,
57};
58
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -070059struct mbhc_micbias_regs {
60 u16 cfilt_val;
61 u16 cfilt_ctl;
62 u16 mbhc_reg;
63 u16 int_rbias;
64 u16 ctl_reg;
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -080065 u8 cfilt_sel;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -070066};
67
Ben Romberger1f045a72011-11-04 10:14:57 -070068/* Codec supports 2 IIR filters */
69enum {
70 IIR1 = 0,
71 IIR2,
72 IIR_MAX,
73};
74/* Codec supports 5 bands */
75enum {
76 BAND1 = 0,
77 BAND2,
78 BAND3,
79 BAND4,
80 BAND5,
81 BAND_MAX,
82};
83
Bradley Rubin229c6a52011-07-12 16:18:48 -070084struct tabla_priv {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070085 struct snd_soc_codec *codec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070086 u32 adc_count;
Patrick Lai3043fba2011-08-01 14:15:57 -070087 u32 cfilt1_cnt;
88 u32 cfilt2_cnt;
89 u32 cfilt3_cnt;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -070090 u32 rx_bias_count;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091 enum tabla_bandgap_type bandgap_type;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -070092 bool mclk_enabled;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070093 bool clock_active;
94 bool config_mode_active;
95 bool mbhc_polling_active;
Bhalchandra Gajare9494fa262011-11-10 19:25:59 -080096 bool fake_insert_context;
Bradley Rubincb1e2732011-06-23 16:49:20 -070097 int buttons_pressed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070098
99 struct tabla_mbhc_calibration *calibration;
100
Bradley Rubincb1e2732011-06-23 16:49:20 -0700101 struct snd_soc_jack *headset_jack;
102 struct snd_soc_jack *button_jack;
Bradley Rubin229c6a52011-07-12 16:18:48 -0700103
Patrick Lai3043fba2011-08-01 14:15:57 -0700104 struct tabla_pdata *pdata;
Bradley Rubina7096d02011-08-03 18:29:02 -0700105 u32 anc_slot;
Bradley Rubincb3950a2011-08-18 13:07:26 -0700106
107 bool no_mic_headset_override;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -0700108 /* Delayed work to report long button press */
109 struct delayed_work btn0_dwork;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700110
111 struct mbhc_micbias_regs mbhc_bias_regs;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -0700112 u8 cfilt_k_value;
113 bool mbhc_micbias_switched;
Patrick Lai49efeac2011-11-03 11:01:12 -0700114
Santosh Mardie15e2302011-11-15 10:39:23 +0530115 /*track tabla interface type*/
116 u8 intf_type;
117
Patrick Lai49efeac2011-11-03 11:01:12 -0700118 u32 hph_status; /* track headhpone status */
119 /* define separate work for left and right headphone OCP to avoid
120 * additional checking on which OCP event to report so no locking
121 * to ensure synchronization is required
122 */
123 struct work_struct hphlocp_work; /* reporting left hph ocp off */
124 struct work_struct hphrocp_work; /* reporting right hph ocp off */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700125};
126
Bradley Rubincb3950a2011-08-18 13:07:26 -0700127#ifdef CONFIG_DEBUG_FS
128struct tabla_priv *debug_tabla_priv;
129#endif
130
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131static int tabla_codec_enable_charge_pump(struct snd_soc_dapm_widget *w,
132 struct snd_kcontrol *kcontrol, int event)
133{
134 struct snd_soc_codec *codec = w->codec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700135
136 pr_debug("%s %d\n", __func__, event);
137 switch (event) {
138 case SND_SOC_DAPM_POST_PMU:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700139 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
140 0x01);
141 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x08);
142 usleep_range(200, 200);
143 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x00);
144 break;
145 case SND_SOC_DAPM_PRE_PMD:
146 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10,
147 0x10);
148 usleep_range(20, 20);
149 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x08);
150 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x10);
151 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x00);
152 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
153 0x00);
154 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700155 break;
156 }
157 return 0;
158}
159
Bradley Rubina7096d02011-08-03 18:29:02 -0700160static int tabla_get_anc_slot(struct snd_kcontrol *kcontrol,
161 struct snd_ctl_elem_value *ucontrol)
162{
163 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
164 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
165 ucontrol->value.integer.value[0] = tabla->anc_slot;
166 return 0;
167}
168
169static int tabla_put_anc_slot(struct snd_kcontrol *kcontrol,
170 struct snd_ctl_elem_value *ucontrol)
171{
172 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
173 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
174 tabla->anc_slot = ucontrol->value.integer.value[0];
175 return 0;
176}
177
Kiran Kandid2d86b52011-09-09 17:44:28 -0700178static int tabla_pa_gain_get(struct snd_kcontrol *kcontrol,
179 struct snd_ctl_elem_value *ucontrol)
180{
181 u8 ear_pa_gain;
182 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
183
184 ear_pa_gain = snd_soc_read(codec, TABLA_A_RX_EAR_GAIN);
185
186 ear_pa_gain = ear_pa_gain >> 5;
187
188 if (ear_pa_gain == 0x00) {
189 ucontrol->value.integer.value[0] = 0;
190 } else if (ear_pa_gain == 0x04) {
191 ucontrol->value.integer.value[0] = 1;
192 } else {
193 pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n",
194 __func__, ear_pa_gain);
195 return -EINVAL;
196 }
197
198 pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain);
199
200 return 0;
201}
202
203static int tabla_pa_gain_put(struct snd_kcontrol *kcontrol,
204 struct snd_ctl_elem_value *ucontrol)
205{
206 u8 ear_pa_gain;
207 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
208
209 pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__,
210 ucontrol->value.integer.value[0]);
211
212 switch (ucontrol->value.integer.value[0]) {
213 case 0:
214 ear_pa_gain = 0x00;
215 break;
216 case 1:
217 ear_pa_gain = 0x80;
218 break;
219 default:
220 return -EINVAL;
221 }
222
223 snd_soc_update_bits(codec, TABLA_A_RX_EAR_GAIN, 0xE0, ear_pa_gain);
224 return 0;
225}
226
Ben Romberger1f045a72011-11-04 10:14:57 -0700227static int tabla_get_iir_enable_audio_mixer(
228 struct snd_kcontrol *kcontrol,
229 struct snd_ctl_elem_value *ucontrol)
230{
231 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
232 int iir_idx = ((struct soc_multi_mixer_control *)
233 kcontrol->private_value)->reg;
234 int band_idx = ((struct soc_multi_mixer_control *)
235 kcontrol->private_value)->shift;
236
237 ucontrol->value.integer.value[0] =
238 snd_soc_read(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx)) &
239 (1 << band_idx);
240
241 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
242 iir_idx, band_idx,
243 (uint32_t)ucontrol->value.integer.value[0]);
244 return 0;
245}
246
247static int tabla_put_iir_enable_audio_mixer(
248 struct snd_kcontrol *kcontrol,
249 struct snd_ctl_elem_value *ucontrol)
250{
251 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
252 int iir_idx = ((struct soc_multi_mixer_control *)
253 kcontrol->private_value)->reg;
254 int band_idx = ((struct soc_multi_mixer_control *)
255 kcontrol->private_value)->shift;
256 int value = ucontrol->value.integer.value[0];
257
258 /* Mask first 5 bits, 6-8 are reserved */
259 snd_soc_update_bits(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx),
260 (1 << band_idx), (value << band_idx));
261
262 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
263 iir_idx, band_idx, value);
264 return 0;
265}
266static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
267 int iir_idx, int band_idx,
268 int coeff_idx)
269{
270 /* Address does not automatically update if reading */
271 snd_soc_update_bits(codec,
272 (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
273 0x1F, band_idx * BAND_MAX + coeff_idx);
274
275 /* Mask bits top 2 bits since they are reserved */
276 return ((snd_soc_read(codec,
277 (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 24) |
278 (snd_soc_read(codec,
279 (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx)) << 16) |
280 (snd_soc_read(codec,
281 (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx)) << 8) |
282 (snd_soc_read(codec,
283 (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx)))) &
284 0x3FFFFFFF;
285}
286
287static int tabla_get_iir_band_audio_mixer(
288 struct snd_kcontrol *kcontrol,
289 struct snd_ctl_elem_value *ucontrol)
290{
291 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
292 int iir_idx = ((struct soc_multi_mixer_control *)
293 kcontrol->private_value)->reg;
294 int band_idx = ((struct soc_multi_mixer_control *)
295 kcontrol->private_value)->shift;
296
297 ucontrol->value.integer.value[0] =
298 get_iir_band_coeff(codec, iir_idx, band_idx, 0);
299 ucontrol->value.integer.value[1] =
300 get_iir_band_coeff(codec, iir_idx, band_idx, 1);
301 ucontrol->value.integer.value[2] =
302 get_iir_band_coeff(codec, iir_idx, band_idx, 2);
303 ucontrol->value.integer.value[3] =
304 get_iir_band_coeff(codec, iir_idx, band_idx, 3);
305 ucontrol->value.integer.value[4] =
306 get_iir_band_coeff(codec, iir_idx, band_idx, 4);
307
308 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
309 "%s: IIR #%d band #%d b1 = 0x%x\n"
310 "%s: IIR #%d band #%d b2 = 0x%x\n"
311 "%s: IIR #%d band #%d a1 = 0x%x\n"
312 "%s: IIR #%d band #%d a2 = 0x%x\n",
313 __func__, iir_idx, band_idx,
314 (uint32_t)ucontrol->value.integer.value[0],
315 __func__, iir_idx, band_idx,
316 (uint32_t)ucontrol->value.integer.value[1],
317 __func__, iir_idx, band_idx,
318 (uint32_t)ucontrol->value.integer.value[2],
319 __func__, iir_idx, band_idx,
320 (uint32_t)ucontrol->value.integer.value[3],
321 __func__, iir_idx, band_idx,
322 (uint32_t)ucontrol->value.integer.value[4]);
323 return 0;
324}
325
326static void set_iir_band_coeff(struct snd_soc_codec *codec,
327 int iir_idx, int band_idx,
328 int coeff_idx, uint32_t value)
329{
330 /* Mask top 3 bits, 6-8 are reserved */
331 /* Update address manually each time */
332 snd_soc_update_bits(codec,
333 (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
334 0x1F, band_idx * BAND_MAX + coeff_idx);
335
336 /* Mask top 2 bits, 7-8 are reserved */
337 snd_soc_update_bits(codec,
338 (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
339 0x3F, (value >> 24) & 0x3F);
340
341 /* Isolate 8bits at a time */
342 snd_soc_update_bits(codec,
343 (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx),
344 0xFF, (value >> 16) & 0xFF);
345
346 snd_soc_update_bits(codec,
347 (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx),
348 0xFF, (value >> 8) & 0xFF);
349
350 snd_soc_update_bits(codec,
351 (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx),
352 0xFF, value & 0xFF);
353}
354
355static int tabla_put_iir_band_audio_mixer(
356 struct snd_kcontrol *kcontrol,
357 struct snd_ctl_elem_value *ucontrol)
358{
359 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
360 int iir_idx = ((struct soc_multi_mixer_control *)
361 kcontrol->private_value)->reg;
362 int band_idx = ((struct soc_multi_mixer_control *)
363 kcontrol->private_value)->shift;
364
365 set_iir_band_coeff(codec, iir_idx, band_idx, 0,
366 ucontrol->value.integer.value[0]);
367 set_iir_band_coeff(codec, iir_idx, band_idx, 1,
368 ucontrol->value.integer.value[1]);
369 set_iir_band_coeff(codec, iir_idx, band_idx, 2,
370 ucontrol->value.integer.value[2]);
371 set_iir_band_coeff(codec, iir_idx, band_idx, 3,
372 ucontrol->value.integer.value[3]);
373 set_iir_band_coeff(codec, iir_idx, band_idx, 4,
374 ucontrol->value.integer.value[4]);
375
376 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
377 "%s: IIR #%d band #%d b1 = 0x%x\n"
378 "%s: IIR #%d band #%d b2 = 0x%x\n"
379 "%s: IIR #%d band #%d a1 = 0x%x\n"
380 "%s: IIR #%d band #%d a2 = 0x%x\n",
381 __func__, iir_idx, band_idx,
382 get_iir_band_coeff(codec, iir_idx, band_idx, 0),
383 __func__, iir_idx, band_idx,
384 get_iir_band_coeff(codec, iir_idx, band_idx, 1),
385 __func__, iir_idx, band_idx,
386 get_iir_band_coeff(codec, iir_idx, band_idx, 2),
387 __func__, iir_idx, band_idx,
388 get_iir_band_coeff(codec, iir_idx, band_idx, 3),
389 __func__, iir_idx, band_idx,
390 get_iir_band_coeff(codec, iir_idx, band_idx, 4));
391 return 0;
392}
393
Kiran Kandid2d86b52011-09-09 17:44:28 -0700394static const char *tabla_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"};
395static const struct soc_enum tabla_ear_pa_gain_enum[] = {
396 SOC_ENUM_SINGLE_EXT(2, tabla_ear_pa_gain_text),
397};
398
Santosh Mardi024010f2011-10-18 06:27:21 +0530399/*cut of frequency for high pass filter*/
400static const char *cf_text[] = {
401 "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz"
402};
403
404static const struct soc_enum cf_dec1_enum =
405 SOC_ENUM_SINGLE(TABLA_A_CDC_TX1_MUX_CTL, 4, 3, cf_text);
406
407static const struct soc_enum cf_dec2_enum =
408 SOC_ENUM_SINGLE(TABLA_A_CDC_TX2_MUX_CTL, 4, 3, cf_text);
409
410static const struct soc_enum cf_dec3_enum =
411 SOC_ENUM_SINGLE(TABLA_A_CDC_TX3_MUX_CTL, 4, 3, cf_text);
412
413static const struct soc_enum cf_dec4_enum =
414 SOC_ENUM_SINGLE(TABLA_A_CDC_TX4_MUX_CTL, 4, 3, cf_text);
415
416static const struct soc_enum cf_dec5_enum =
417 SOC_ENUM_SINGLE(TABLA_A_CDC_TX5_MUX_CTL, 4, 3, cf_text);
418
419static const struct soc_enum cf_dec6_enum =
420 SOC_ENUM_SINGLE(TABLA_A_CDC_TX6_MUX_CTL, 4, 3, cf_text);
421
422static const struct soc_enum cf_dec7_enum =
423 SOC_ENUM_SINGLE(TABLA_A_CDC_TX7_MUX_CTL, 4, 3, cf_text);
424
425static const struct soc_enum cf_dec8_enum =
426 SOC_ENUM_SINGLE(TABLA_A_CDC_TX8_MUX_CTL, 4, 3, cf_text);
427
428static const struct soc_enum cf_dec9_enum =
429 SOC_ENUM_SINGLE(TABLA_A_CDC_TX9_MUX_CTL, 4, 3, cf_text);
430
431static const struct soc_enum cf_dec10_enum =
432 SOC_ENUM_SINGLE(TABLA_A_CDC_TX10_MUX_CTL, 4, 3, cf_text);
433
434static const struct soc_enum cf_rxmix1_enum =
435 SOC_ENUM_SINGLE(TABLA_A_CDC_RX1_B4_CTL, 1, 3, cf_text);
436
437static const struct soc_enum cf_rxmix2_enum =
438 SOC_ENUM_SINGLE(TABLA_A_CDC_RX2_B4_CTL, 1, 3, cf_text);
439
440static const struct soc_enum cf_rxmix3_enum =
441 SOC_ENUM_SINGLE(TABLA_A_CDC_RX3_B4_CTL, 1, 3, cf_text);
442
443static const struct soc_enum cf_rxmix4_enum =
444 SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B4_CTL, 1, 3, cf_text);
445
446static const struct soc_enum cf_rxmix5_enum =
447 SOC_ENUM_SINGLE(TABLA_A_CDC_RX5_B4_CTL, 1, 3, cf_text)
448;
449static const struct soc_enum cf_rxmix6_enum =
450 SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B4_CTL, 1, 3, cf_text);
451
452static const struct soc_enum cf_rxmix7_enum =
453 SOC_ENUM_SINGLE(TABLA_A_CDC_RX7_B4_CTL, 1, 3, cf_text);
454
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700455static const struct snd_kcontrol_new tabla_snd_controls[] = {
Kiran Kandid2d86b52011-09-09 17:44:28 -0700456
457 SOC_ENUM_EXT("EAR PA Gain", tabla_ear_pa_gain_enum[0],
458 tabla_pa_gain_get, tabla_pa_gain_put),
459
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700460 SOC_SINGLE_TLV("LINEOUT1 Volume", TABLA_A_RX_LINE_1_GAIN, 0, 12, 1,
461 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700462 SOC_SINGLE_TLV("LINEOUT2 Volume", TABLA_A_RX_LINE_2_GAIN, 0, 12, 1,
463 line_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700464 SOC_SINGLE_TLV("LINEOUT3 Volume", TABLA_A_RX_LINE_3_GAIN, 0, 12, 1,
465 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700466 SOC_SINGLE_TLV("LINEOUT4 Volume", TABLA_A_RX_LINE_4_GAIN, 0, 12, 1,
467 line_gain),
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -0700468 SOC_SINGLE_TLV("LINEOUT5 Volume", TABLA_A_RX_LINE_5_GAIN, 0, 12, 1,
469 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700470
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700471 SOC_SINGLE_TLV("HPHL Volume", TABLA_A_RX_HPH_L_GAIN, 0, 12, 1,
472 line_gain),
473 SOC_SINGLE_TLV("HPHR Volume", TABLA_A_RX_HPH_R_GAIN, 0, 12, 1,
474 line_gain),
475
Bradley Rubin410383f2011-07-22 13:44:23 -0700476 SOC_SINGLE_S8_TLV("RX1 Digital Volume", TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
477 -84, 40, digital_gain),
478 SOC_SINGLE_S8_TLV("RX2 Digital Volume", TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
479 -84, 40, digital_gain),
480 SOC_SINGLE_S8_TLV("RX3 Digital Volume", TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
481 -84, 40, digital_gain),
482 SOC_SINGLE_S8_TLV("RX4 Digital Volume", TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
483 -84, 40, digital_gain),
484 SOC_SINGLE_S8_TLV("RX5 Digital Volume", TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
485 -84, 40, digital_gain),
486 SOC_SINGLE_S8_TLV("RX6 Digital Volume", TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
487 -84, 40, digital_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700488
Bradley Rubin410383f2011-07-22 13:44:23 -0700489 SOC_SINGLE_S8_TLV("DEC1 Volume", TABLA_A_CDC_TX1_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700490 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -0700491 SOC_SINGLE_S8_TLV("DEC2 Volume", TABLA_A_CDC_TX2_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700492 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -0700493 SOC_SINGLE_S8_TLV("DEC3 Volume", TABLA_A_CDC_TX3_VOL_CTL_GAIN, -84, 40,
494 digital_gain),
495 SOC_SINGLE_S8_TLV("DEC4 Volume", TABLA_A_CDC_TX4_VOL_CTL_GAIN, -84, 40,
496 digital_gain),
497 SOC_SINGLE_S8_TLV("DEC5 Volume", TABLA_A_CDC_TX5_VOL_CTL_GAIN, -84, 40,
498 digital_gain),
499 SOC_SINGLE_S8_TLV("DEC6 Volume", TABLA_A_CDC_TX6_VOL_CTL_GAIN, -84, 40,
500 digital_gain),
501 SOC_SINGLE_S8_TLV("DEC7 Volume", TABLA_A_CDC_TX7_VOL_CTL_GAIN, -84, 40,
502 digital_gain),
503 SOC_SINGLE_S8_TLV("DEC8 Volume", TABLA_A_CDC_TX8_VOL_CTL_GAIN, -84, 40,
504 digital_gain),
505 SOC_SINGLE_S8_TLV("DEC9 Volume", TABLA_A_CDC_TX9_VOL_CTL_GAIN, -84, 40,
506 digital_gain),
507 SOC_SINGLE_S8_TLV("DEC10 Volume", TABLA_A_CDC_TX10_VOL_CTL_GAIN, -84,
508 40, digital_gain),
Patrick Lai29006372011-09-28 17:57:42 -0700509 SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TABLA_A_CDC_IIR1_GAIN_B1_CTL, -84,
510 40, digital_gain),
511 SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TABLA_A_CDC_IIR1_GAIN_B2_CTL, -84,
512 40, digital_gain),
513 SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TABLA_A_CDC_IIR1_GAIN_B3_CTL, -84,
514 40, digital_gain),
515 SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TABLA_A_CDC_IIR1_GAIN_B4_CTL, -84,
516 40, digital_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700517 SOC_SINGLE_TLV("ADC1 Volume", TABLA_A_TX_1_2_EN, 5, 3, 0, analog_gain),
518 SOC_SINGLE_TLV("ADC2 Volume", TABLA_A_TX_1_2_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700519 SOC_SINGLE_TLV("ADC3 Volume", TABLA_A_TX_3_4_EN, 5, 3, 0, analog_gain),
520 SOC_SINGLE_TLV("ADC4 Volume", TABLA_A_TX_3_4_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700521 SOC_SINGLE_TLV("ADC5 Volume", TABLA_A_TX_5_6_EN, 5, 3, 0, analog_gain),
522 SOC_SINGLE_TLV("ADC6 Volume", TABLA_A_TX_5_6_EN, 1, 3, 0, analog_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700523
524 SOC_SINGLE("MICBIAS1 CAPLESS Switch", TABLA_A_MICB_1_CTL, 4, 1, 1),
Santosh Mardi680b41e2011-11-22 16:51:16 -0800525 SOC_SINGLE("MICBIAS2 CAPLESS Switch", TABLA_A_MICB_2_CTL, 4, 1, 1),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700526 SOC_SINGLE("MICBIAS3 CAPLESS Switch", TABLA_A_MICB_3_CTL, 4, 1, 1),
527 SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_A_MICB_4_CTL, 4, 1, 1),
Bradley Rubina7096d02011-08-03 18:29:02 -0700528
529 SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 0, 100, tabla_get_anc_slot,
530 tabla_put_anc_slot),
Santosh Mardi024010f2011-10-18 06:27:21 +0530531 SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
532 SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
533 SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
534 SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
535 SOC_ENUM("TX5 HPF cut off", cf_dec5_enum),
536 SOC_ENUM("TX6 HPF cut off", cf_dec6_enum),
537 SOC_ENUM("TX7 HPF cut off", cf_dec7_enum),
538 SOC_ENUM("TX8 HPF cut off", cf_dec8_enum),
539 SOC_ENUM("TX9 HPF cut off", cf_dec9_enum),
540 SOC_ENUM("TX10 HPF cut off", cf_dec10_enum),
541
542 SOC_SINGLE("TX1 HPF Switch", TABLA_A_CDC_TX1_MUX_CTL, 3, 1, 0),
543 SOC_SINGLE("TX2 HPF Switch", TABLA_A_CDC_TX2_MUX_CTL, 3, 1, 0),
544 SOC_SINGLE("TX3 HPF Switch", TABLA_A_CDC_TX3_MUX_CTL, 3, 1, 0),
545 SOC_SINGLE("TX4 HPF Switch", TABLA_A_CDC_TX4_MUX_CTL, 3, 1, 0),
546 SOC_SINGLE("TX5 HPF Switch", TABLA_A_CDC_TX5_MUX_CTL, 3, 1, 0),
547 SOC_SINGLE("TX6 HPF Switch", TABLA_A_CDC_TX6_MUX_CTL, 3, 1, 0),
548 SOC_SINGLE("TX7 HPF Switch", TABLA_A_CDC_TX7_MUX_CTL, 3, 1, 0),
549 SOC_SINGLE("TX8 HPF Switch", TABLA_A_CDC_TX8_MUX_CTL, 3, 1, 0),
550 SOC_SINGLE("TX9 HPF Switch", TABLA_A_CDC_TX9_MUX_CTL, 3, 1, 0),
551 SOC_SINGLE("TX10 HPF Switch", TABLA_A_CDC_TX10_MUX_CTL, 3, 1, 0),
552
553 SOC_SINGLE("RX1 HPF Switch", TABLA_A_CDC_RX1_B5_CTL, 2, 1, 0),
554 SOC_SINGLE("RX2 HPF Switch", TABLA_A_CDC_RX2_B5_CTL, 2, 1, 0),
555 SOC_SINGLE("RX3 HPF Switch", TABLA_A_CDC_RX3_B5_CTL, 2, 1, 0),
556 SOC_SINGLE("RX4 HPF Switch", TABLA_A_CDC_RX4_B5_CTL, 2, 1, 0),
557 SOC_SINGLE("RX5 HPF Switch", TABLA_A_CDC_RX5_B5_CTL, 2, 1, 0),
558 SOC_SINGLE("RX6 HPF Switch", TABLA_A_CDC_RX6_B5_CTL, 2, 1, 0),
559 SOC_SINGLE("RX7 HPF Switch", TABLA_A_CDC_RX7_B5_CTL, 2, 1, 0),
560
561 SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum),
562 SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum),
563 SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum),
564 SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum),
565 SOC_ENUM("RX5 HPF cut off", cf_rxmix5_enum),
566 SOC_ENUM("RX6 HPF cut off", cf_rxmix6_enum),
567 SOC_ENUM("RX7 HPF cut off", cf_rxmix7_enum),
Ben Romberger1f045a72011-11-04 10:14:57 -0700568
569 SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
570 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
571 SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
572 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
573 SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
574 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
575 SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
576 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
577 SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
578 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
579 SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0,
580 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
581 SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0,
582 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
583 SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0,
584 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
585 SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0,
586 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
587 SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0,
588 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
589
590 SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
591 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
592 SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
593 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
594 SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
595 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
596 SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
597 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
598 SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
599 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
600 SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5,
601 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
602 SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5,
603 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
604 SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5,
605 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
606 SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5,
607 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
608 SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5,
609 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700610};
611
612static const char *rx_mix1_text[] = {
613 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
614 "RX5", "RX6", "RX7"
615};
616
Kiran Kandi8b3a8302011-09-27 16:13:28 -0700617static const char *rx_dsm_text[] = {
618 "CIC_OUT", "DSM_INV"
619};
620
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700621static const char *sb_tx1_mux_text[] = {
622 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
623 "DEC1"
624};
625
626static const char *sb_tx5_mux_text[] = {
627 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
628 "DEC5"
629};
630
631static const char *sb_tx6_mux_text[] = {
632 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
633 "DEC6"
634};
635
636static const char const *sb_tx7_to_tx10_mux_text[] = {
637 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
638 "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
639 "DEC9", "DEC10"
640};
641
642static const char *dec1_mux_text[] = {
643 "ZERO", "DMIC1", "ADC6",
644};
645
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700646static const char *dec2_mux_text[] = {
647 "ZERO", "DMIC2", "ADC5",
648};
649
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700650static const char *dec3_mux_text[] = {
651 "ZERO", "DMIC3", "ADC4",
652};
653
654static const char *dec4_mux_text[] = {
655 "ZERO", "DMIC4", "ADC3",
656};
657
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700658static const char *dec5_mux_text[] = {
659 "ZERO", "DMIC5", "ADC2",
660};
661
662static const char *dec6_mux_text[] = {
663 "ZERO", "DMIC6", "ADC1",
664};
665
666static const char const *dec7_mux_text[] = {
667 "ZERO", "DMIC1", "DMIC6", "ADC1", "ADC6", "ANC1_FB", "ANC2_FB",
668};
669
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700670static const char *dec8_mux_text[] = {
671 "ZERO", "DMIC2", "DMIC5", "ADC2", "ADC5",
672};
673
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700674static const char *dec9_mux_text[] = {
675 "ZERO", "DMIC4", "DMIC5", "ADC2", "ADC3", "ADCMB", "ANC1_FB", "ANC2_FB",
676};
677
678static const char *dec10_mux_text[] = {
679 "ZERO", "DMIC3", "DMIC6", "ADC1", "ADC4", "ADCMB", "ANC1_FB", "ANC2_FB",
680};
681
Bradley Rubin229c6a52011-07-12 16:18:48 -0700682static const char const *anc_mux_text[] = {
683 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6", "ADC_MB",
684 "RSVD_1", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", "DMIC6"
685};
686
687static const char const *anc1_fb_mux_text[] = {
688 "ZERO", "EAR_HPH_L", "EAR_LINE_1",
689};
690
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700691static const char *iir1_inp1_text[] = {
692 "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
693 "DEC9", "DEC10", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7"
694};
695
696static const struct soc_enum rx_mix1_inp1_chain_enum =
697 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_mix1_text);
698
Bradley Rubin229c6a52011-07-12 16:18:48 -0700699static const struct soc_enum rx_mix1_inp2_chain_enum =
700 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_mix1_text);
701
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700702static const struct soc_enum rx2_mix1_inp1_chain_enum =
703 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_mix1_text);
704
Bradley Rubin229c6a52011-07-12 16:18:48 -0700705static const struct soc_enum rx2_mix1_inp2_chain_enum =
706 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_mix1_text);
707
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700708static const struct soc_enum rx3_mix1_inp1_chain_enum =
709 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 0, 12, rx_mix1_text);
710
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700711static const struct soc_enum rx3_mix1_inp2_chain_enum =
712 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 4, 12, rx_mix1_text);
713
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700714static const struct soc_enum rx4_mix1_inp1_chain_enum =
715 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 0, 12, rx_mix1_text);
716
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700717static const struct soc_enum rx4_mix1_inp2_chain_enum =
718 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 4, 12, rx_mix1_text);
719
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700720static const struct soc_enum rx5_mix1_inp1_chain_enum =
721 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 0, 12, rx_mix1_text);
722
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700723static const struct soc_enum rx5_mix1_inp2_chain_enum =
724 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 4, 12, rx_mix1_text);
725
726static const struct soc_enum rx6_mix1_inp1_chain_enum =
727 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 0, 12, rx_mix1_text);
728
729static const struct soc_enum rx6_mix1_inp2_chain_enum =
730 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 4, 12, rx_mix1_text);
731
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -0700732static const struct soc_enum rx7_mix1_inp1_chain_enum =
733 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 0, 12, rx_mix1_text);
734
735static const struct soc_enum rx7_mix1_inp2_chain_enum =
736 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 4, 12, rx_mix1_text);
737
Kiran Kandi8b3a8302011-09-27 16:13:28 -0700738static const struct soc_enum rx4_dsm_enum =
739 SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B6_CTL, 4, 2, rx_dsm_text);
740
741static const struct soc_enum rx6_dsm_enum =
742 SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B6_CTL, 4, 2, rx_dsm_text);
743
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700744static const struct soc_enum sb_tx5_mux_enum =
745 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text);
746
747static const struct soc_enum sb_tx6_mux_enum =
748 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0, 9, sb_tx6_mux_text);
749
750static const struct soc_enum sb_tx7_mux_enum =
751 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0, 18,
752 sb_tx7_to_tx10_mux_text);
753
754static const struct soc_enum sb_tx8_mux_enum =
755 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0, 18,
756 sb_tx7_to_tx10_mux_text);
757
758static const struct soc_enum sb_tx1_mux_enum =
759 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text);
760
761static const struct soc_enum dec1_mux_enum =
762 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 0, 3, dec1_mux_text);
763
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700764static const struct soc_enum dec2_mux_enum =
765 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 2, 3, dec2_mux_text);
766
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700767static const struct soc_enum dec3_mux_enum =
768 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 4, 3, dec3_mux_text);
769
770static const struct soc_enum dec4_mux_enum =
771 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 6, 3, dec4_mux_text);
772
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700773static const struct soc_enum dec5_mux_enum =
774 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 0, 3, dec5_mux_text);
775
776static const struct soc_enum dec6_mux_enum =
777 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 2, 3, dec6_mux_text);
778
779static const struct soc_enum dec7_mux_enum =
780 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 4, 7, dec7_mux_text);
781
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700782static const struct soc_enum dec8_mux_enum =
783 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 0, 7, dec8_mux_text);
784
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700785static const struct soc_enum dec9_mux_enum =
786 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 3, 8, dec9_mux_text);
787
788static const struct soc_enum dec10_mux_enum =
789 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B4_CTL, 0, 8, dec10_mux_text);
790
Bradley Rubin229c6a52011-07-12 16:18:48 -0700791static const struct soc_enum anc1_mux_enum =
792 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 0, 16, anc_mux_text);
793
794static const struct soc_enum anc2_mux_enum =
795 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 4, 16, anc_mux_text);
796
797static const struct soc_enum anc1_fb_mux_enum =
798 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text);
799
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700800static const struct soc_enum iir1_inp1_mux_enum =
801 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ1_B1_CTL, 0, 18, iir1_inp1_text);
802
803static const struct snd_kcontrol_new rx_mix1_inp1_mux =
804 SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum);
805
Bradley Rubin229c6a52011-07-12 16:18:48 -0700806static const struct snd_kcontrol_new rx_mix1_inp2_mux =
807 SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum);
808
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700809static const struct snd_kcontrol_new rx2_mix1_inp1_mux =
810 SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum);
811
Bradley Rubin229c6a52011-07-12 16:18:48 -0700812static const struct snd_kcontrol_new rx2_mix1_inp2_mux =
813 SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum);
814
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700815static const struct snd_kcontrol_new rx3_mix1_inp1_mux =
816 SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum);
817
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700818static const struct snd_kcontrol_new rx3_mix1_inp2_mux =
819 SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum);
820
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700821static const struct snd_kcontrol_new rx4_mix1_inp1_mux =
822 SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum);
823
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700824static const struct snd_kcontrol_new rx4_mix1_inp2_mux =
825 SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum);
826
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700827static const struct snd_kcontrol_new rx5_mix1_inp1_mux =
828 SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum);
829
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700830static const struct snd_kcontrol_new rx5_mix1_inp2_mux =
831 SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum);
832
833static const struct snd_kcontrol_new rx6_mix1_inp1_mux =
834 SOC_DAPM_ENUM("RX6 MIX1 INP1 Mux", rx6_mix1_inp1_chain_enum);
835
836static const struct snd_kcontrol_new rx6_mix1_inp2_mux =
837 SOC_DAPM_ENUM("RX6 MIX1 INP2 Mux", rx6_mix1_inp2_chain_enum);
838
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -0700839static const struct snd_kcontrol_new rx7_mix1_inp1_mux =
840 SOC_DAPM_ENUM("RX7 MIX1 INP1 Mux", rx7_mix1_inp1_chain_enum);
841
842static const struct snd_kcontrol_new rx7_mix1_inp2_mux =
843 SOC_DAPM_ENUM("RX7 MIX1 INP2 Mux", rx7_mix1_inp2_chain_enum);
844
Kiran Kandi8b3a8302011-09-27 16:13:28 -0700845static const struct snd_kcontrol_new rx4_dsm_mux =
846 SOC_DAPM_ENUM("RX4 DSM MUX Mux", rx4_dsm_enum);
847
848static const struct snd_kcontrol_new rx6_dsm_mux =
849 SOC_DAPM_ENUM("RX6 DSM MUX Mux", rx6_dsm_enum);
850
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700851static const struct snd_kcontrol_new sb_tx5_mux =
852 SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum);
853
854static const struct snd_kcontrol_new sb_tx6_mux =
855 SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum);
856
857static const struct snd_kcontrol_new sb_tx7_mux =
858 SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum);
859
860static const struct snd_kcontrol_new sb_tx8_mux =
861 SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum);
862
863static const struct snd_kcontrol_new sb_tx1_mux =
864 SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum);
865
866static const struct snd_kcontrol_new dec1_mux =
867 SOC_DAPM_ENUM("DEC1 MUX Mux", dec1_mux_enum);
868
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700869static const struct snd_kcontrol_new dec2_mux =
870 SOC_DAPM_ENUM("DEC2 MUX Mux", dec2_mux_enum);
871
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700872static const struct snd_kcontrol_new dec3_mux =
873 SOC_DAPM_ENUM("DEC3 MUX Mux", dec3_mux_enum);
874
875static const struct snd_kcontrol_new dec4_mux =
876 SOC_DAPM_ENUM("DEC4 MUX Mux", dec4_mux_enum);
877
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700878static const struct snd_kcontrol_new dec5_mux =
879 SOC_DAPM_ENUM("DEC5 MUX Mux", dec5_mux_enum);
880
881static const struct snd_kcontrol_new dec6_mux =
882 SOC_DAPM_ENUM("DEC6 MUX Mux", dec6_mux_enum);
883
884static const struct snd_kcontrol_new dec7_mux =
885 SOC_DAPM_ENUM("DEC7 MUX Mux", dec7_mux_enum);
886
Bradley Rubin229c6a52011-07-12 16:18:48 -0700887static const struct snd_kcontrol_new anc1_mux =
888 SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum);
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700889static const struct snd_kcontrol_new dec8_mux =
890 SOC_DAPM_ENUM("DEC8 MUX Mux", dec8_mux_enum);
891
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700892static const struct snd_kcontrol_new dec9_mux =
893 SOC_DAPM_ENUM("DEC9 MUX Mux", dec9_mux_enum);
894
895static const struct snd_kcontrol_new dec10_mux =
896 SOC_DAPM_ENUM("DEC10 MUX Mux", dec10_mux_enum);
897
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700898static const struct snd_kcontrol_new iir1_inp1_mux =
899 SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum);
900
Bradley Rubin229c6a52011-07-12 16:18:48 -0700901static const struct snd_kcontrol_new anc2_mux =
902 SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700903
Bradley Rubin229c6a52011-07-12 16:18:48 -0700904static const struct snd_kcontrol_new anc1_fb_mux =
905 SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700906
Bradley Rubin229c6a52011-07-12 16:18:48 -0700907static const struct snd_kcontrol_new dac1_switch[] = {
908 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_EAR_EN, 5, 1, 0)
909};
910static const struct snd_kcontrol_new hphl_switch[] = {
911 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_HPH_L_DAC_CTL, 6, 1, 0)
912};
Kiran Kandi8b3a8302011-09-27 16:13:28 -0700913
914static const struct snd_kcontrol_new lineout3_ground_switch =
915 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_3_DAC_CTL, 6, 1, 0);
916
917static const struct snd_kcontrol_new lineout4_ground_switch =
918 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_4_DAC_CTL, 6, 1, 0);
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700919
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700920static void tabla_codec_enable_adc_block(struct snd_soc_codec *codec,
921 int enable)
922{
923 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
924
925 pr_debug("%s %d\n", __func__, enable);
926
927 if (enable) {
928 tabla->adc_count++;
929 snd_soc_update_bits(codec, TABLA_A_TX_COM_BIAS, 0xE0, 0xE0);
930 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x2, 0x2);
931 } else {
932 tabla->adc_count--;
933 if (!tabla->adc_count) {
934 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL,
935 0x2, 0x0);
936 if (!tabla->mbhc_polling_active)
937 snd_soc_update_bits(codec, TABLA_A_TX_COM_BIAS,
938 0xE0, 0x0);
939 }
940 }
941}
942
943static int tabla_codec_enable_adc(struct snd_soc_dapm_widget *w,
944 struct snd_kcontrol *kcontrol, int event)
945{
946 struct snd_soc_codec *codec = w->codec;
947 u16 adc_reg;
948
949 pr_debug("%s %d\n", __func__, event);
950
951 if (w->reg == TABLA_A_TX_1_2_EN)
952 adc_reg = TABLA_A_TX_1_2_TEST_CTL;
953 else if (w->reg == TABLA_A_TX_3_4_EN)
954 adc_reg = TABLA_A_TX_3_4_TEST_CTL;
955 else if (w->reg == TABLA_A_TX_5_6_EN)
956 adc_reg = TABLA_A_TX_5_6_TEST_CTL;
957 else {
958 pr_err("%s: Error, invalid adc register\n", __func__);
959 return -EINVAL;
960 }
961
962 switch (event) {
963 case SND_SOC_DAPM_PRE_PMU:
964 tabla_codec_enable_adc_block(codec, 1);
965 break;
966 case SND_SOC_DAPM_POST_PMU:
967 snd_soc_update_bits(codec, adc_reg, 1 << w->shift,
968 1 << w->shift);
969 usleep_range(1000, 1000);
970 snd_soc_update_bits(codec, adc_reg, 1 << w->shift, 0x00);
971 usleep_range(1000, 1000);
972 break;
973 case SND_SOC_DAPM_POST_PMD:
974 tabla_codec_enable_adc_block(codec, 0);
975 break;
976 }
977 return 0;
978}
979
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700980static int tabla_codec_enable_lineout(struct snd_soc_dapm_widget *w,
981 struct snd_kcontrol *kcontrol, int event)
982{
983 struct snd_soc_codec *codec = w->codec;
984 u16 lineout_gain_reg;
985
Kiran Kandidb0a4b02011-08-23 09:32:09 -0700986 pr_debug("%s %d %s\n", __func__, event, w->name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700987
988 switch (w->shift) {
989 case 0:
990 lineout_gain_reg = TABLA_A_RX_LINE_1_GAIN;
991 break;
992 case 1:
993 lineout_gain_reg = TABLA_A_RX_LINE_2_GAIN;
994 break;
995 case 2:
996 lineout_gain_reg = TABLA_A_RX_LINE_3_GAIN;
997 break;
998 case 3:
999 lineout_gain_reg = TABLA_A_RX_LINE_4_GAIN;
1000 break;
1001 case 4:
1002 lineout_gain_reg = TABLA_A_RX_LINE_5_GAIN;
1003 break;
1004 default:
1005 pr_err("%s: Error, incorrect lineout register value\n",
1006 __func__);
1007 return -EINVAL;
1008 }
1009
1010 switch (event) {
1011 case SND_SOC_DAPM_PRE_PMU:
1012 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40);
1013 break;
1014 case SND_SOC_DAPM_POST_PMU:
Kiran Kandidb0a4b02011-08-23 09:32:09 -07001015 pr_debug("%s: sleeping 40 ms after %s PA turn on\n",
1016 __func__, w->name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001017 usleep_range(40000, 40000);
1018 break;
1019 case SND_SOC_DAPM_POST_PMD:
1020 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00);
1021 break;
1022 }
1023 return 0;
1024}
1025
Kiran Kandicf45f6a2011-07-17 21:10:19 -07001026
1027static int tabla_codec_enable_dmic(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001028 struct snd_kcontrol *kcontrol, int event)
1029{
1030 struct snd_soc_codec *codec = w->codec;
Kiran Kandicf45f6a2011-07-17 21:10:19 -07001031 u16 tx_mux_ctl_reg, tx_dmic_ctl_reg;
1032 u8 dmic_clk_sel, dmic_clk_en;
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07001033 unsigned int dmic;
1034 int ret;
Kiran Kandicf45f6a2011-07-17 21:10:19 -07001035
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07001036 ret = kstrtouint(strpbrk(w->name, "123456"), 10, &dmic);
1037 if (ret < 0) {
1038 pr_err("%s: Invalid DMIC line on the codec\n", __func__);
Kiran Kandicf45f6a2011-07-17 21:10:19 -07001039 return -EINVAL;
1040 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001041
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07001042 switch (dmic) {
1043 case 1:
1044 case 2:
1045 dmic_clk_sel = 0x02;
1046 dmic_clk_en = 0x01;
1047 break;
1048
1049 case 3:
1050 case 4:
1051 dmic_clk_sel = 0x08;
1052 dmic_clk_en = 0x04;
1053 break;
1054
1055 case 5:
1056 case 6:
1057 dmic_clk_sel = 0x20;
1058 dmic_clk_en = 0x10;
1059 break;
1060
1061 default:
1062 pr_err("%s: Invalid DMIC Selection\n", __func__);
1063 return -EINVAL;
1064 }
1065
1066 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (dmic - 1);
1067 tx_dmic_ctl_reg = TABLA_A_CDC_TX1_DMIC_CTL + 8 * (dmic - 1);
1068
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001069 pr_debug("%s %d\n", __func__, event);
Kiran Kandicf45f6a2011-07-17 21:10:19 -07001070
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001071 switch (event) {
1072 case SND_SOC_DAPM_PRE_PMU:
Kiran Kandicf45f6a2011-07-17 21:10:19 -07001073 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, 0x1);
1074
1075 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
1076 dmic_clk_sel, dmic_clk_sel);
1077
1078 snd_soc_update_bits(codec, tx_dmic_ctl_reg, 0x1, 0x1);
1079
1080 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
1081 dmic_clk_en, dmic_clk_en);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001082 break;
1083 case SND_SOC_DAPM_POST_PMD:
Kiran Kandicf45f6a2011-07-17 21:10:19 -07001084 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
1085 dmic_clk_en, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001086 break;
1087 }
1088 return 0;
1089}
1090
Bradley Rubin229c6a52011-07-12 16:18:48 -07001091static int tabla_codec_enable_anc(struct snd_soc_dapm_widget *w,
1092 struct snd_kcontrol *kcontrol, int event)
1093{
1094 struct snd_soc_codec *codec = w->codec;
1095 const char *filename;
1096 const struct firmware *fw;
1097 int i;
1098 int ret;
Bradley Rubina7096d02011-08-03 18:29:02 -07001099 int num_anc_slots;
1100 struct anc_header *anc_head;
Bradley Rubin229c6a52011-07-12 16:18:48 -07001101 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubina7096d02011-08-03 18:29:02 -07001102 u32 anc_writes_size = 0;
1103 int anc_size_remaining;
1104 u32 *anc_ptr;
Bradley Rubin229c6a52011-07-12 16:18:48 -07001105 u16 reg;
1106 u8 mask, val, old_val;
1107
1108 pr_debug("%s %d\n", __func__, event);
1109 switch (event) {
1110 case SND_SOC_DAPM_PRE_PMU:
1111
Bradley Rubin4283a4c2011-07-29 16:18:54 -07001112 filename = "wcd9310/wcd9310_anc.bin";
Bradley Rubin229c6a52011-07-12 16:18:48 -07001113
1114 ret = request_firmware(&fw, filename, codec->dev);
1115 if (ret != 0) {
1116 dev_err(codec->dev, "Failed to acquire ANC data: %d\n",
1117 ret);
1118 return -ENODEV;
1119 }
1120
Bradley Rubina7096d02011-08-03 18:29:02 -07001121 if (fw->size < sizeof(struct anc_header)) {
Bradley Rubin229c6a52011-07-12 16:18:48 -07001122 dev_err(codec->dev, "Not enough data\n");
1123 release_firmware(fw);
1124 return -ENOMEM;
1125 }
1126
1127 /* First number is the number of register writes */
Bradley Rubina7096d02011-08-03 18:29:02 -07001128 anc_head = (struct anc_header *)(fw->data);
1129 anc_ptr = (u32 *)((u32)fw->data + sizeof(struct anc_header));
1130 anc_size_remaining = fw->size - sizeof(struct anc_header);
1131 num_anc_slots = anc_head->num_anc_slots;
Bradley Rubin229c6a52011-07-12 16:18:48 -07001132
Bradley Rubina7096d02011-08-03 18:29:02 -07001133 if (tabla->anc_slot >= num_anc_slots) {
1134 dev_err(codec->dev, "Invalid ANC slot selected\n");
1135 release_firmware(fw);
1136 return -EINVAL;
1137 }
1138
1139 for (i = 0; i < num_anc_slots; i++) {
1140
1141 if (anc_size_remaining < TABLA_PACKED_REG_SIZE) {
1142 dev_err(codec->dev, "Invalid register format\n");
1143 release_firmware(fw);
1144 return -EINVAL;
1145 }
1146 anc_writes_size = (u32)(*anc_ptr);
1147 anc_size_remaining -= sizeof(u32);
1148 anc_ptr += 1;
1149
1150 if (anc_writes_size * TABLA_PACKED_REG_SIZE
1151 > anc_size_remaining) {
1152 dev_err(codec->dev, "Invalid register format\n");
1153 release_firmware(fw);
1154 return -ENOMEM;
1155 }
1156
1157 if (tabla->anc_slot == i)
1158 break;
1159
1160 anc_size_remaining -= (anc_writes_size *
1161 TABLA_PACKED_REG_SIZE);
Bradley Rubin939ff3f2011-08-26 17:19:34 -07001162 anc_ptr += anc_writes_size;
Bradley Rubina7096d02011-08-03 18:29:02 -07001163 }
1164 if (i == num_anc_slots) {
1165 dev_err(codec->dev, "Selected ANC slot not present\n");
Bradley Rubin229c6a52011-07-12 16:18:48 -07001166 release_firmware(fw);
1167 return -ENOMEM;
1168 }
1169
Bradley Rubina7096d02011-08-03 18:29:02 -07001170 for (i = 0; i < anc_writes_size; i++) {
1171 TABLA_CODEC_UNPACK_ENTRY(anc_ptr[i], reg,
Bradley Rubin229c6a52011-07-12 16:18:48 -07001172 mask, val);
1173 old_val = snd_soc_read(codec, reg);
Bradley Rubin4283a4c2011-07-29 16:18:54 -07001174 snd_soc_write(codec, reg, (old_val & ~mask) |
1175 (val & mask));
Bradley Rubin229c6a52011-07-12 16:18:48 -07001176 }
1177 release_firmware(fw);
Bradley Rubin229c6a52011-07-12 16:18:48 -07001178
1179 break;
1180 case SND_SOC_DAPM_POST_PMD:
1181 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0xFF);
1182 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_CLK_EN_CTL, 0);
1183 break;
1184 }
1185 return 0;
1186}
1187
1188
Bradley Rubincb3950a2011-08-18 13:07:26 -07001189static void tabla_codec_disable_button_presses(struct snd_soc_codec *codec)
1190{
1191 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, 0x80);
1192 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0x00);
1193}
1194
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001195static void tabla_codec_start_hs_polling(struct snd_soc_codec *codec)
1196{
Bradley Rubincb3950a2011-08-18 13:07:26 -07001197 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1198
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001199 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001200 tabla_enable_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL);
Bradley Rubincb3950a2011-08-18 13:07:26 -07001201 if (!tabla->no_mic_headset_override) {
1202 tabla_enable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
1203 tabla_enable_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE);
1204 } else {
1205 tabla_codec_disable_button_presses(codec);
1206 }
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001207 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
1208 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
1209 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
1210}
1211
1212static void tabla_codec_pause_hs_polling(struct snd_soc_codec *codec)
1213{
Bradley Rubincb3950a2011-08-18 13:07:26 -07001214 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1215
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001216 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
1217 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL);
Bradley Rubincb3950a2011-08-18 13:07:26 -07001218 if (!tabla->no_mic_headset_override) {
1219 tabla_disable_irq(codec->control_data,
1220 TABLA_IRQ_MBHC_POTENTIAL);
1221 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE);
1222 }
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001223}
1224
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08001225static void tabla_codec_switch_cfilt_mode(struct snd_soc_codec *codec,
1226 int mode)
1227{
1228 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1229 u8 reg_mode_val, cur_mode_val;
1230 bool mbhc_was_polling = false;
1231
1232 if (mode)
1233 reg_mode_val = TABLA_CFILT_FAST_MODE;
1234 else
1235 reg_mode_val = TABLA_CFILT_SLOW_MODE;
1236
1237 cur_mode_val = snd_soc_read(codec,
1238 tabla->mbhc_bias_regs.cfilt_ctl) & 0x40;
1239
1240 if (cur_mode_val != reg_mode_val) {
1241 if (tabla->mbhc_polling_active) {
1242 tabla_codec_pause_hs_polling(codec);
1243 mbhc_was_polling = true;
1244 }
1245 snd_soc_update_bits(codec,
1246 tabla->mbhc_bias_regs.cfilt_ctl, 0x40, reg_mode_val);
1247 if (mbhc_was_polling)
1248 tabla_codec_start_hs_polling(codec);
1249 pr_debug("%s: CFILT mode change (%x to %x)\n", __func__,
1250 cur_mode_val, reg_mode_val);
1251 } else {
1252 pr_debug("%s: CFILT Value is already %x\n",
1253 __func__, cur_mode_val);
1254 }
1255}
1256
1257static void tabla_codec_update_cfilt_usage(struct snd_soc_codec *codec,
1258 u8 cfilt_sel, int inc)
1259{
1260 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1261 u32 *cfilt_cnt_ptr = NULL;
1262 u16 micb_cfilt_reg;
1263
1264 switch (cfilt_sel) {
1265 case TABLA_CFILT1_SEL:
1266 cfilt_cnt_ptr = &tabla->cfilt1_cnt;
1267 micb_cfilt_reg = TABLA_A_MICB_CFILT_1_CTL;
1268 break;
1269 case TABLA_CFILT2_SEL:
1270 cfilt_cnt_ptr = &tabla->cfilt2_cnt;
1271 micb_cfilt_reg = TABLA_A_MICB_CFILT_2_CTL;
1272 break;
1273 case TABLA_CFILT3_SEL:
1274 cfilt_cnt_ptr = &tabla->cfilt3_cnt;
1275 micb_cfilt_reg = TABLA_A_MICB_CFILT_3_CTL;
1276 break;
1277 default:
1278 return; /* should not happen */
1279 }
1280
1281 if (inc) {
1282 if (!(*cfilt_cnt_ptr)++) {
1283 /* Switch CFILT to slow mode if MBHC CFILT being used */
1284 if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel)
1285 tabla_codec_switch_cfilt_mode(codec, 0);
1286
1287 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80);
1288 }
1289 } else {
1290 /* check if count not zero, decrement
1291 * then check if zero, go ahead disable cfilter
1292 */
1293 if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr)) {
1294 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0);
1295
1296 /* Switch CFILT to fast mode if MBHC CFILT being used */
1297 if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel)
1298 tabla_codec_switch_cfilt_mode(codec, 1);
1299 }
1300 }
1301}
1302
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001303static int tabla_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv)
1304{
1305 int rc = -EINVAL;
1306 unsigned min_mv, max_mv;
1307
1308 switch (ldoh_v) {
1309 case TABLA_LDOH_1P95_V:
1310 min_mv = 160;
1311 max_mv = 1800;
1312 break;
1313 case TABLA_LDOH_2P35_V:
1314 min_mv = 200;
1315 max_mv = 2200;
1316 break;
1317 case TABLA_LDOH_2P75_V:
1318 min_mv = 240;
1319 max_mv = 2600;
1320 break;
1321 case TABLA_LDOH_2P85_V:
1322 min_mv = 250;
1323 max_mv = 2700;
1324 break;
1325 default:
1326 goto done;
1327 }
1328
1329 if (cfilt_mv < min_mv || cfilt_mv > max_mv)
1330 goto done;
1331
1332 for (rc = 4; rc <= 44; rc++) {
1333 min_mv = max_mv * (rc) / 44;
1334 if (min_mv >= cfilt_mv) {
1335 rc -= 4;
1336 break;
1337 }
1338 }
1339done:
1340 return rc;
1341}
1342
1343static bool tabla_is_hph_pa_on(struct snd_soc_codec *codec)
1344{
1345 u8 hph_reg_val = 0;
1346 hph_reg_val = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_EN);
1347
1348 return (hph_reg_val & 0x30) ? true : false;
1349}
1350
1351static void tabla_codec_switch_micbias(struct snd_soc_codec *codec,
1352 int vddio_switch)
1353{
1354 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1355 int cfilt_k_val;
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08001356 bool mbhc_was_polling = false;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001357
1358 switch (vddio_switch) {
1359 case 1:
1360 if (tabla->mbhc_polling_active) {
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08001361
1362 tabla_codec_pause_hs_polling(codec);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001363 /* Enable Mic Bias switch to VDDIO */
1364 tabla->cfilt_k_value = snd_soc_read(codec,
1365 tabla->mbhc_bias_regs.cfilt_val);
1366 cfilt_k_val = tabla_find_k_value(
1367 tabla->pdata->micbias.ldoh_v, 1800);
1368 snd_soc_update_bits(codec,
1369 tabla->mbhc_bias_regs.cfilt_val,
1370 0xFC, (cfilt_k_val << 2));
1371
1372 snd_soc_update_bits(codec,
1373 tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x80);
1374 snd_soc_update_bits(codec,
1375 tabla->mbhc_bias_regs.mbhc_reg, 0x10, 0x00);
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08001376 tabla_codec_start_hs_polling(codec);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001377
1378 tabla->mbhc_micbias_switched = true;
1379 pr_debug("%s: Enabled MBHC Mic bias to VDDIO Switch\n",
1380 __func__);
1381 }
1382 break;
1383
1384 case 0:
1385 if (tabla->mbhc_micbias_switched) {
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08001386 if (tabla->mbhc_polling_active) {
1387 tabla_codec_pause_hs_polling(codec);
1388 mbhc_was_polling = true;
1389 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001390 /* Disable Mic Bias switch to VDDIO */
1391 if (tabla->cfilt_k_value != 0)
1392 snd_soc_update_bits(codec,
1393 tabla->mbhc_bias_regs.cfilt_val, 0XFC,
1394 tabla->cfilt_k_value);
1395 snd_soc_update_bits(codec,
1396 tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00);
1397 snd_soc_update_bits(codec,
1398 tabla->mbhc_bias_regs.mbhc_reg, 0x10, 0x00);
1399
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08001400 if (mbhc_was_polling)
1401 tabla_codec_start_hs_polling(codec);
1402
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001403 tabla->mbhc_micbias_switched = false;
1404 pr_debug("%s: Disabled MBHC Mic bias to VDDIO Switch\n",
1405 __func__);
1406 }
1407 break;
1408 }
1409}
1410
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001411static int tabla_codec_enable_micbias(struct snd_soc_dapm_widget *w,
1412 struct snd_kcontrol *kcontrol, int event)
1413{
1414 struct snd_soc_codec *codec = w->codec;
Patrick Lai3043fba2011-08-01 14:15:57 -07001415 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1416 u16 micb_int_reg;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001417 int micb_line;
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001418 u8 cfilt_sel_val = 0;
Bradley Rubin229c6a52011-07-12 16:18:48 -07001419 char *internal1_text = "Internal1";
1420 char *internal2_text = "Internal2";
1421 char *internal3_text = "Internal3";
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001422
1423 pr_debug("%s %d\n", __func__, event);
1424 switch (w->reg) {
1425 case TABLA_A_MICB_1_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001426 micb_int_reg = TABLA_A_MICB_1_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07001427 cfilt_sel_val = tabla->pdata->micbias.bias1_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001428 micb_line = TABLA_MICBIAS1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001429 break;
1430 case TABLA_A_MICB_2_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001431 micb_int_reg = TABLA_A_MICB_2_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07001432 cfilt_sel_val = tabla->pdata->micbias.bias2_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001433 micb_line = TABLA_MICBIAS2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001434 break;
1435 case TABLA_A_MICB_3_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001436 micb_int_reg = TABLA_A_MICB_3_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07001437 cfilt_sel_val = tabla->pdata->micbias.bias3_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001438 micb_line = TABLA_MICBIAS3;
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001439 break;
1440 case TABLA_A_MICB_4_CTL:
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001441 micb_int_reg = TABLA_A_MICB_4_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07001442 cfilt_sel_val = tabla->pdata->micbias.bias4_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001443 micb_line = TABLA_MICBIAS4;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001444 break;
1445 default:
1446 pr_err("%s: Error, invalid micbias register\n", __func__);
1447 return -EINVAL;
1448 }
1449
1450 switch (event) {
1451 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001452 /* Decide whether to switch the micbias for MBHC */
1453 if ((w->reg == tabla->mbhc_bias_regs.ctl_reg)
1454 && tabla->mbhc_micbias_switched)
1455 tabla_codec_switch_micbias(codec, 0);
1456
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001457 snd_soc_update_bits(codec, w->reg, 0x0E, 0x0A);
Patrick Lai3043fba2011-08-01 14:15:57 -07001458 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 1);
Bradley Rubin229c6a52011-07-12 16:18:48 -07001459
1460 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001461 snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0);
Bradley Rubin229c6a52011-07-12 16:18:48 -07001462 else if (strnstr(w->name, internal2_text, 30))
1463 snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C);
1464 else if (strnstr(w->name, internal3_text, 30))
1465 snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3);
1466
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001467 break;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001468 case SND_SOC_DAPM_POST_PMU:
1469 if (tabla->mbhc_polling_active &&
1470 (tabla->calibration->bias == micb_line)) {
1471 tabla_codec_pause_hs_polling(codec);
1472 tabla_codec_start_hs_polling(codec);
1473 }
1474 break;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001475
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001476 case SND_SOC_DAPM_POST_PMD:
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001477
1478 if ((w->reg == tabla->mbhc_bias_regs.ctl_reg)
1479 && tabla_is_hph_pa_on(codec))
1480 tabla_codec_switch_micbias(codec, 1);
1481
Bradley Rubin229c6a52011-07-12 16:18:48 -07001482 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001483 snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00);
Bradley Rubin229c6a52011-07-12 16:18:48 -07001484 else if (strnstr(w->name, internal2_text, 30))
1485 snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00);
1486 else if (strnstr(w->name, internal3_text, 30))
1487 snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0);
1488
Patrick Lai3043fba2011-08-01 14:15:57 -07001489 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001490 break;
1491 }
1492
1493 return 0;
1494}
1495
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001496static int tabla_codec_enable_dec(struct snd_soc_dapm_widget *w,
1497 struct snd_kcontrol *kcontrol, int event)
1498{
1499 struct snd_soc_codec *codec = w->codec;
1500 u16 dec_reset_reg;
1501
1502 pr_debug("%s %d\n", __func__, event);
1503
1504 if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL)
1505 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B1_CTL;
1506 else if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL)
1507 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B2_CTL;
1508 else {
1509 pr_err("%s: Error, incorrect dec\n", __func__);
1510 return -EINVAL;
1511 }
1512
1513 switch (event) {
1514 case SND_SOC_DAPM_PRE_PMU:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001515 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift,
1516 1 << w->shift);
1517 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0);
1518 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001519 }
1520 return 0;
1521}
1522
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001523static int tabla_codec_reset_interpolator(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001524 struct snd_kcontrol *kcontrol, int event)
1525{
1526 struct snd_soc_codec *codec = w->codec;
1527
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001528 pr_debug("%s %d %s\n", __func__, event, w->name);
1529
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001530 switch (event) {
1531 case SND_SOC_DAPM_PRE_PMU:
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001532 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
1533 1 << w->shift, 1 << w->shift);
1534 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
1535 1 << w->shift, 0x0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001536 break;
1537 }
1538 return 0;
1539}
1540
Bradley Rubin229c6a52011-07-12 16:18:48 -07001541static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
1542 struct snd_kcontrol *kcontrol, int event)
1543{
1544 switch (event) {
1545 case SND_SOC_DAPM_POST_PMU:
1546 case SND_SOC_DAPM_POST_PMD:
1547 usleep_range(1000, 1000);
1548 break;
1549 }
1550 return 0;
1551}
1552
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07001553
1554static void tabla_enable_rx_bias(struct snd_soc_codec *codec, u32 enable)
1555{
1556 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1557
1558 if (enable) {
1559 tabla->rx_bias_count++;
1560 if (tabla->rx_bias_count == 1)
1561 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
1562 0x80, 0x80);
1563 } else {
1564 tabla->rx_bias_count--;
1565 if (!tabla->rx_bias_count)
1566 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
1567 0x80, 0x00);
1568 }
1569}
1570
1571static int tabla_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
1572 struct snd_kcontrol *kcontrol, int event)
1573{
1574 struct snd_soc_codec *codec = w->codec;
1575
1576 pr_debug("%s %d\n", __func__, event);
1577
1578 switch (event) {
1579 case SND_SOC_DAPM_PRE_PMU:
1580 tabla_enable_rx_bias(codec, 1);
1581 break;
1582 case SND_SOC_DAPM_POST_PMD:
1583 tabla_enable_rx_bias(codec, 0);
1584 break;
1585 }
1586 return 0;
1587}
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001588static int tabla_hphr_dac_event(struct snd_soc_dapm_widget *w,
1589 struct snd_kcontrol *kcontrol, int event)
1590{
1591 struct snd_soc_codec *codec = w->codec;
1592
1593 pr_debug("%s %s %d\n", __func__, w->name, event);
1594
1595 switch (event) {
1596 case SND_SOC_DAPM_PRE_PMU:
1597 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
1598 break;
1599 case SND_SOC_DAPM_POST_PMD:
1600 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
1601 break;
1602 }
1603 return 0;
1604}
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07001605
Patrick Lai49efeac2011-11-03 11:01:12 -07001606static void hphocp_off_report(struct tabla_priv *tabla,
1607 u32 jack_status, int irq)
1608{
1609 struct snd_soc_codec *codec;
1610
1611 if (tabla) {
1612 pr_info("%s: clear ocp status %x\n", __func__, jack_status);
1613 codec = tabla->codec;
1614 tabla->hph_status &= ~jack_status;
1615 if (tabla->headset_jack)
1616 snd_soc_jack_report(tabla->headset_jack,
1617 tabla->hph_status, TABLA_JACK_MASK);
1618 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
1619 0x00);
1620 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
1621 0x10);
1622 tabla_enable_irq(codec->control_data, irq);
1623 } else {
1624 pr_err("%s: Bad tabla private data\n", __func__);
1625 }
1626}
1627
1628static void hphlocp_off_report(struct work_struct *work)
1629{
1630 struct tabla_priv *tabla = container_of(work, struct tabla_priv,
1631 hphlocp_work);
1632 hphocp_off_report(tabla, SND_JACK_OC_HPHL, TABLA_IRQ_HPH_PA_OCPL_FAULT);
1633}
1634
1635static void hphrocp_off_report(struct work_struct *work)
1636{
1637 struct tabla_priv *tabla = container_of(work, struct tabla_priv,
1638 hphrocp_work);
1639 hphocp_off_report(tabla, SND_JACK_OC_HPHR, TABLA_IRQ_HPH_PA_OCPR_FAULT);
1640}
1641
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07001642static int tabla_hph_pa_event(struct snd_soc_dapm_widget *w,
1643 struct snd_kcontrol *kcontrol, int event)
1644{
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001645 struct snd_soc_codec *codec = w->codec;
1646 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1647 u8 mbhc_micb_ctl_val;
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07001648 pr_debug("%s: event = %d\n", __func__, event);
1649
1650 switch (event) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001651 case SND_SOC_DAPM_PRE_PMU:
1652 mbhc_micb_ctl_val = snd_soc_read(codec,
1653 tabla->mbhc_bias_regs.ctl_reg);
1654
1655 if (!(mbhc_micb_ctl_val & 0x80)
1656 && !tabla->mbhc_micbias_switched)
1657 tabla_codec_switch_micbias(codec, 1);
1658
1659 break;
1660
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07001661 case SND_SOC_DAPM_POST_PMD:
Patrick Lai49efeac2011-11-03 11:01:12 -07001662 /* schedule work is required because at the time HPH PA DAPM
1663 * event callback is called by DAPM framework, CODEC dapm mutex
1664 * would have been locked while snd_soc_jack_report also
1665 * attempts to acquire same lock.
1666 */
1667 if ((tabla->hph_status & SND_JACK_OC_HPHL) &&
1668 strnstr(w->name, "HPHL", 4))
1669 schedule_work(&tabla->hphlocp_work);
1670 else if ((tabla->hph_status & SND_JACK_OC_HPHR) &&
1671 strnstr(w->name, "HPHR", 4))
1672 schedule_work(&tabla->hphrocp_work);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001673 if (tabla->mbhc_micbias_switched)
1674 tabla_codec_switch_micbias(codec, 0);
1675
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07001676 pr_debug("%s: sleep 10 ms after %s PA disable.\n", __func__,
1677 w->name);
1678 usleep_range(10000, 10000);
1679
1680 break;
1681 }
1682 return 0;
1683}
1684
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07001685static void tabla_get_mbhc_micbias_regs(struct snd_soc_codec *codec,
1686 struct mbhc_micbias_regs *micbias_regs)
1687{
1688 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1689 struct tabla_mbhc_calibration *calibration = tabla->calibration;
1690 unsigned int cfilt;
1691
1692 switch (calibration->bias) {
1693 case TABLA_MICBIAS1:
1694 cfilt = tabla->pdata->micbias.bias1_cfilt_sel;
1695 micbias_regs->mbhc_reg = TABLA_A_MICB_1_MBHC;
1696 micbias_regs->int_rbias = TABLA_A_MICB_1_INT_RBIAS;
1697 micbias_regs->ctl_reg = TABLA_A_MICB_1_CTL;
1698 break;
1699 case TABLA_MICBIAS2:
1700 cfilt = tabla->pdata->micbias.bias2_cfilt_sel;
1701 micbias_regs->mbhc_reg = TABLA_A_MICB_2_MBHC;
1702 micbias_regs->int_rbias = TABLA_A_MICB_2_INT_RBIAS;
1703 micbias_regs->ctl_reg = TABLA_A_MICB_2_CTL;
1704 break;
1705 case TABLA_MICBIAS3:
1706 cfilt = tabla->pdata->micbias.bias3_cfilt_sel;
1707 micbias_regs->mbhc_reg = TABLA_A_MICB_3_MBHC;
1708 micbias_regs->int_rbias = TABLA_A_MICB_3_INT_RBIAS;
1709 micbias_regs->ctl_reg = TABLA_A_MICB_3_CTL;
1710 break;
1711 case TABLA_MICBIAS4:
1712 cfilt = tabla->pdata->micbias.bias4_cfilt_sel;
1713 micbias_regs->mbhc_reg = TABLA_A_MICB_4_MBHC;
1714 micbias_regs->int_rbias = TABLA_A_MICB_4_INT_RBIAS;
1715 micbias_regs->ctl_reg = TABLA_A_MICB_4_CTL;
1716 break;
1717 default:
1718 /* Should never reach here */
1719 pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__);
1720 }
1721
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08001722 micbias_regs->cfilt_sel = cfilt;
1723
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07001724 switch (cfilt) {
1725 case TABLA_CFILT1_SEL:
1726 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_1_VAL;
1727 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_1_CTL;
1728 break;
1729 case TABLA_CFILT2_SEL:
1730 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_2_VAL;
1731 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_2_CTL;
1732 break;
1733 case TABLA_CFILT3_SEL:
1734 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_3_VAL;
1735 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_3_CTL;
1736 break;
1737 }
1738}
Santosh Mardie15e2302011-11-15 10:39:23 +05301739static const struct snd_soc_dapm_widget tabla_dapm_i2s_widgets[] = {
1740 SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", TABLA_A_CDC_CLK_RX_I2S_CTL,
1741 4, 0, NULL, 0),
1742 SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", TABLA_A_CDC_CLK_TX_I2S_CTL, 4,
1743 0, NULL, 0),
1744};
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07001745
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001746static int tabla_lineout_dac_event(struct snd_soc_dapm_widget *w,
1747 struct snd_kcontrol *kcontrol, int event)
1748{
1749 struct snd_soc_codec *codec = w->codec;
1750
1751 pr_debug("%s %s %d\n", __func__, w->name, event);
1752
1753 switch (event) {
1754 case SND_SOC_DAPM_PRE_PMU:
1755 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
1756 break;
1757
1758 case SND_SOC_DAPM_POST_PMD:
1759 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
1760 break;
1761 }
1762 return 0;
1763}
1764
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001765static const struct snd_soc_dapm_widget tabla_dapm_widgets[] = {
1766 /*RX stuff */
1767 SND_SOC_DAPM_OUTPUT("EAR"),
1768
Kiran Kandid2d86b52011-09-09 17:44:28 -07001769 SND_SOC_DAPM_PGA("EAR PA", TABLA_A_RX_EAR_EN, 4, 0, NULL, 0),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001770
Bradley Rubin229c6a52011-07-12 16:18:48 -07001771 SND_SOC_DAPM_MIXER("DAC1", TABLA_A_RX_EAR_EN, 6, 0, dac1_switch,
1772 ARRAY_SIZE(dac1_switch)),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001773
Bradley Rubin229c6a52011-07-12 16:18:48 -07001774 SND_SOC_DAPM_AIF_IN("SLIM RX1", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
1775 SND_SOC_DAPM_AIF_IN("SLIM RX2", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
Santosh Mardie15e2302011-11-15 10:39:23 +05301776 SND_SOC_DAPM_AIF_IN("SLIM RX3", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
1777 SND_SOC_DAPM_AIF_IN("SLIM RX4", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001778
1779 /* Headphone */
1780 SND_SOC_DAPM_OUTPUT("HEADPHONE"),
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07001781 SND_SOC_DAPM_PGA_E("HPHL", TABLA_A_RX_HPH_CNP_EN, 5, 0, NULL, 0,
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001782 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
1783 SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001784 SND_SOC_DAPM_MIXER("HPHL DAC", TABLA_A_RX_HPH_L_DAC_CTL, 7, 0,
1785 hphl_switch, ARRAY_SIZE(hphl_switch)),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001786
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07001787 SND_SOC_DAPM_PGA_E("HPHR", TABLA_A_RX_HPH_CNP_EN, 4, 0, NULL, 0,
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07001788 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
1789 SND_SOC_DAPM_POST_PMD),
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001790
1791 SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TABLA_A_RX_HPH_R_DAC_CTL, 7, 0,
1792 tabla_hphr_dac_event,
1793 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001794
1795 /* Speaker */
Kiran Kandidb0a4b02011-08-23 09:32:09 -07001796 SND_SOC_DAPM_OUTPUT("LINEOUT1"),
1797 SND_SOC_DAPM_OUTPUT("LINEOUT2"),
1798 SND_SOC_DAPM_OUTPUT("LINEOUT3"),
1799 SND_SOC_DAPM_OUTPUT("LINEOUT4"),
1800 SND_SOC_DAPM_OUTPUT("LINEOUT5"),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001801
Kiran Kandidb0a4b02011-08-23 09:32:09 -07001802 SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TABLA_A_RX_LINE_CNP_EN, 0, 0, NULL,
1803 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
1804 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1805 SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TABLA_A_RX_LINE_CNP_EN, 1, 0, NULL,
1806 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
1807 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1808 SND_SOC_DAPM_PGA_E("LINEOUT3 PA", TABLA_A_RX_LINE_CNP_EN, 2, 0, NULL,
1809 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
1810 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1811 SND_SOC_DAPM_PGA_E("LINEOUT4 PA", TABLA_A_RX_LINE_CNP_EN, 3, 0, NULL,
1812 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
1813 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1814 SND_SOC_DAPM_PGA_E("LINEOUT5 PA", TABLA_A_RX_LINE_CNP_EN, 4, 0, NULL, 0,
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001815 tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
1816 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001817
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001818 SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TABLA_A_RX_LINE_1_DAC_CTL, 7, 0
1819 , tabla_lineout_dac_event,
1820 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1821 SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TABLA_A_RX_LINE_2_DAC_CTL, 7, 0
1822 , tabla_lineout_dac_event,
1823 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1824 SND_SOC_DAPM_DAC_E("LINEOUT3 DAC", NULL, TABLA_A_RX_LINE_3_DAC_CTL, 7, 0
1825 , tabla_lineout_dac_event,
1826 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1827 SND_SOC_DAPM_SWITCH("LINEOUT3 DAC GROUND", SND_SOC_NOPM, 0, 0,
1828 &lineout3_ground_switch),
1829 SND_SOC_DAPM_DAC_E("LINEOUT4 DAC", NULL, TABLA_A_RX_LINE_4_DAC_CTL, 7, 0
1830 , tabla_lineout_dac_event,
1831 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1832 SND_SOC_DAPM_SWITCH("LINEOUT4 DAC GROUND", SND_SOC_NOPM, 0, 0,
1833 &lineout4_ground_switch),
1834 SND_SOC_DAPM_DAC_E("LINEOUT5 DAC", NULL, TABLA_A_RX_LINE_5_DAC_CTL, 7, 0
1835 , tabla_lineout_dac_event,
1836 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001837
Bradley Rubin229c6a52011-07-12 16:18:48 -07001838 SND_SOC_DAPM_MIXER_E("RX1 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL,
1839 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
1840 SND_SOC_DAPM_MIXER_E("RX2 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL,
1841 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
1842 SND_SOC_DAPM_MIXER_E("RX3 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
1843 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
1844 SND_SOC_DAPM_MIXER_E("RX4 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL,
1845 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
1846 SND_SOC_DAPM_MIXER_E("RX5 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 4, 0, NULL,
1847 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
1848 SND_SOC_DAPM_MIXER_E("RX6 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0, NULL,
1849 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001850 SND_SOC_DAPM_MIXER_E("RX7 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 6, 0, NULL,
1851 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001852
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001853
1854 SND_SOC_DAPM_MUX_E("RX4 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0,
1855 &rx4_dsm_mux, tabla_codec_reset_interpolator,
1856 SND_SOC_DAPM_PRE_PMU),
1857
1858 SND_SOC_DAPM_MUX_E("RX6 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0,
1859 &rx6_dsm_mux, tabla_codec_reset_interpolator,
1860 SND_SOC_DAPM_PRE_PMU),
1861
Bradley Rubin229c6a52011-07-12 16:18:48 -07001862 SND_SOC_DAPM_MIXER("RX1 CHAIN", TABLA_A_CDC_RX1_B6_CTL, 5, 0, NULL, 0),
1863 SND_SOC_DAPM_MIXER("RX2 CHAIN", TABLA_A_CDC_RX2_B6_CTL, 5, 0, NULL, 0),
1864
1865 SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1866 &rx_mix1_inp1_mux),
1867 SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1868 &rx_mix1_inp2_mux),
1869 SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1870 &rx2_mix1_inp1_mux),
1871 SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1872 &rx2_mix1_inp2_mux),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001873 SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1874 &rx3_mix1_inp1_mux),
1875 SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1876 &rx3_mix1_inp2_mux),
1877 SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1878 &rx4_mix1_inp1_mux),
1879 SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1880 &rx4_mix1_inp2_mux),
1881 SND_SOC_DAPM_MUX("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1882 &rx5_mix1_inp1_mux),
1883 SND_SOC_DAPM_MUX("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1884 &rx5_mix1_inp2_mux),
1885 SND_SOC_DAPM_MUX("RX6 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1886 &rx6_mix1_inp1_mux),
1887 SND_SOC_DAPM_MUX("RX6 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1888 &rx6_mix1_inp2_mux),
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001889 SND_SOC_DAPM_MUX("RX7 MIX1 INP1", SND_SOC_NOPM, 0, 0,
1890 &rx7_mix1_inp1_mux),
1891 SND_SOC_DAPM_MUX("RX7 MIX1 INP2", SND_SOC_NOPM, 0, 0,
1892 &rx7_mix1_inp2_mux),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001893
Bradley Rubin229c6a52011-07-12 16:18:48 -07001894 SND_SOC_DAPM_SUPPLY("CP", TABLA_A_CP_EN, 0, 0,
1895 tabla_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU |
1896 SND_SOC_DAPM_PRE_PMD),
1897
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07001898 SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
1899 tabla_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
1900 SND_SOC_DAPM_POST_PMD),
1901
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001902 /* TX */
Bradley Rubin229c6a52011-07-12 16:18:48 -07001903
Bradley Rubine1d08622011-07-20 18:01:35 -07001904 SND_SOC_DAPM_SUPPLY("CDC_CONN", TABLA_A_CDC_CLK_OTHR_CTL, 2, 0, NULL,
1905 0),
1906
Bradley Rubin229c6a52011-07-12 16:18:48 -07001907 SND_SOC_DAPM_SUPPLY("LDO_H", TABLA_A_LDO_H_MODE_1, 7, 0,
1908 tabla_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU),
1909
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001910 SND_SOC_DAPM_INPUT("AMIC1"),
1911 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", TABLA_A_MICB_1_CTL, 7, 0,
1912 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001913 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001914 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", TABLA_A_MICB_1_CTL, 7, 0,
1915 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001916 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001917 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", TABLA_A_MICB_1_CTL, 7, 0,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001918 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001919 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001920 SND_SOC_DAPM_ADC_E("ADC1", NULL, TABLA_A_TX_1_2_EN, 7, 0,
1921 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
1922 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1923
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001924 SND_SOC_DAPM_INPUT("AMIC3"),
1925 SND_SOC_DAPM_ADC_E("ADC3", NULL, TABLA_A_TX_3_4_EN, 7, 0,
1926 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
1927 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1928
1929 SND_SOC_DAPM_INPUT("AMIC4"),
1930 SND_SOC_DAPM_ADC_E("ADC4", NULL, TABLA_A_TX_3_4_EN, 3, 0,
1931 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
1932 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1933
1934 SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", TABLA_A_MICB_4_CTL, 7, 0,
1935 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001936 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001937
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001938 SND_SOC_DAPM_INPUT("AMIC5"),
1939 SND_SOC_DAPM_ADC_E("ADC5", NULL, TABLA_A_TX_5_6_EN, 7, 0,
1940 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
1941
1942 SND_SOC_DAPM_INPUT("AMIC6"),
1943 SND_SOC_DAPM_ADC_E("ADC6", NULL, TABLA_A_TX_5_6_EN, 3, 0,
1944 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
1945
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001946 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 -07001947 &dec1_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001948
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001949 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 -07001950 &dec2_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001951
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001952 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 -07001953 &dec3_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001954
1955 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 -07001956 &dec4_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001957
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001958 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 -07001959 &dec5_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001960
1961 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 -07001962 &dec6_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001963
1964 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 -07001965 &dec7_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001966
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001967 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 -07001968 &dec8_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001969
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001970 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 -07001971 &dec9_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001972
1973 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 -07001974 &dec10_mux, tabla_codec_enable_dec, SND_SOC_DAPM_PRE_PMU),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001975
Bradley Rubin229c6a52011-07-12 16:18:48 -07001976 SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux),
1977 SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux),
1978
1979 SND_SOC_DAPM_MIXER_E("ANC", SND_SOC_NOPM, 0, 0, NULL, 0,
1980 tabla_codec_enable_anc, SND_SOC_DAPM_PRE_PMU |
1981 SND_SOC_DAPM_POST_PMD),
1982
1983 SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux),
1984
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001985 SND_SOC_DAPM_INPUT("AMIC2"),
1986 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", TABLA_A_MICB_2_CTL, 7, 0,
1987 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001988 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001989 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", TABLA_A_MICB_2_CTL, 7, 0,
1990 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001991 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001992 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", TABLA_A_MICB_2_CTL, 7, 0,
1993 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001994 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07001995 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", TABLA_A_MICB_2_CTL, 7, 0,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001996 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07001997 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001998 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", TABLA_A_MICB_3_CTL, 7, 0,
1999 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002000 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07002001 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", TABLA_A_MICB_3_CTL, 7, 0,
2002 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002003 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bradley Rubin229c6a52011-07-12 16:18:48 -07002004 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", TABLA_A_MICB_3_CTL, 7, 0,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002005 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002006 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002007 SND_SOC_DAPM_ADC_E("ADC2", NULL, TABLA_A_TX_1_2_EN, 3, 0,
2008 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
2009 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
2010
2011 SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, 0, 0, &sb_tx1_mux),
2012 SND_SOC_DAPM_AIF_OUT("SLIM TX1", "AIF1 Capture", NULL, SND_SOC_NOPM,
2013 0, 0),
2014
2015 SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, 0, 0, &sb_tx5_mux),
2016 SND_SOC_DAPM_AIF_OUT("SLIM TX5", "AIF1 Capture", NULL, SND_SOC_NOPM,
2017 4, 0),
2018
2019 SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, 0, 0, &sb_tx6_mux),
2020 SND_SOC_DAPM_AIF_OUT("SLIM TX6", "AIF1 Capture", NULL, SND_SOC_NOPM,
2021 5, 0),
2022
2023 SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, 0, 0, &sb_tx7_mux),
2024 SND_SOC_DAPM_AIF_OUT("SLIM TX7", "AIF1 Capture", NULL, SND_SOC_NOPM,
2025 0, 0),
2026
2027 SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, 0, 0, &sb_tx8_mux),
2028 SND_SOC_DAPM_AIF_OUT("SLIM TX8", "AIF1 Capture", NULL, SND_SOC_NOPM,
2029 0, 0),
2030
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002031 /* Digital Mic Inputs */
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002032 SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
2033 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
2034 SND_SOC_DAPM_POST_PMD),
2035
2036 SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
2037 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
2038 SND_SOC_DAPM_POST_PMD),
2039
2040 SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0,
2041 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
2042 SND_SOC_DAPM_POST_PMD),
2043
2044 SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0,
2045 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
2046 SND_SOC_DAPM_POST_PMD),
2047
2048 SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0,
2049 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
2050 SND_SOC_DAPM_POST_PMD),
2051
2052 SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 0,
2053 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
2054 SND_SOC_DAPM_POST_PMD),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002055
2056 /* Sidetone */
2057 SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux),
2058 SND_SOC_DAPM_PGA("IIR1", TABLA_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0),
2059};
2060
Santosh Mardie15e2302011-11-15 10:39:23 +05302061static const struct snd_soc_dapm_route audio_i2s_map[] = {
2062 {"RX_I2S_CLK", NULL, "CDC_CONN"},
2063 {"SLIM RX1", NULL, "RX_I2S_CLK"},
2064 {"SLIM RX2", NULL, "RX_I2S_CLK"},
2065 {"SLIM RX3", NULL, "RX_I2S_CLK"},
2066 {"SLIM RX4", NULL, "RX_I2S_CLK"},
2067
2068 {"SLIM TX7", NULL, "TX_I2S_CLK"},
2069 {"SLIM TX8", NULL, "TX_I2S_CLK"},
2070 {"SLIM TX9", NULL, "TX_I2S_CLK"},
2071 {"SLIM TX10", NULL, "TX_I2S_CLK"},
2072};
2073
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002074static const struct snd_soc_dapm_route audio_map[] = {
2075 /* SLIMBUS Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002076
2077 {"SLIM TX1", NULL, "SLIM TX1 MUX"},
2078 {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"},
2079
2080 {"SLIM TX5", NULL, "SLIM TX5 MUX"},
2081 {"SLIM TX5 MUX", "DEC5", "DEC5 MUX"},
2082
2083 {"SLIM TX6", NULL, "SLIM TX6 MUX"},
2084 {"SLIM TX6 MUX", "DEC6", "DEC6 MUX"},
2085
2086 {"SLIM TX7", NULL, "SLIM TX7 MUX"},
2087 {"SLIM TX7 MUX", "DEC1", "DEC1 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07002088 {"SLIM TX7 MUX", "DEC2", "DEC2 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002089 {"SLIM TX7 MUX", "DEC3", "DEC3 MUX"},
2090 {"SLIM TX7 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002091 {"SLIM TX7 MUX", "DEC5", "DEC5 MUX"},
2092 {"SLIM TX7 MUX", "DEC6", "DEC6 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07002093 {"SLIM TX7 MUX", "DEC7", "DEC7 MUX"},
2094 {"SLIM TX7 MUX", "DEC8", "DEC8 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002095 {"SLIM TX7 MUX", "DEC9", "DEC9 MUX"},
2096 {"SLIM TX7 MUX", "DEC10", "DEC10 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002097
2098 {"SLIM TX8", NULL, "SLIM TX8 MUX"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002099 {"SLIM TX8 MUX", "DEC1", "DEC1 MUX"},
2100 {"SLIM TX8 MUX", "DEC2", "DEC2 MUX"},
2101 {"SLIM TX8 MUX", "DEC3", "DEC3 MUX"},
Bhalchandra Gajare9ec83cd2011-09-23 17:25:07 -07002102 {"SLIM TX8 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002103 {"SLIM TX8 MUX", "DEC5", "DEC5 MUX"},
2104 {"SLIM TX8 MUX", "DEC6", "DEC6 MUX"},
2105
2106 /* Earpiece (RX MIX1) */
2107 {"EAR", NULL, "EAR PA"},
Kiran Kandiac034ac2011-07-29 16:39:08 -07002108 {"EAR PA", NULL, "DAC1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002109 {"DAC1", NULL, "CP"},
2110
2111 {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX1"},
2112 {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX1"},
2113 {"ANC", NULL, "ANC1 FB MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002114
2115 /* Headset (RX MIX1 and RX MIX2) */
2116 {"HEADPHONE", NULL, "HPHL"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002117 {"HEADPHONE", NULL, "HPHR"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002118
2119 {"HPHL", NULL, "HPHL DAC"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002120 {"HPHR", NULL, "HPHR DAC"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002121
2122 {"HPHL DAC", NULL, "CP"},
2123 {"HPHR DAC", NULL, "CP"},
2124
2125 {"ANC", NULL, "ANC1 MUX"},
2126 {"ANC", NULL, "ANC2 MUX"},
2127 {"ANC1 MUX", "ADC1", "ADC1"},
2128 {"ANC1 MUX", "ADC2", "ADC2"},
2129 {"ANC1 MUX", "ADC3", "ADC3"},
2130 {"ANC1 MUX", "ADC4", "ADC4"},
2131 {"ANC2 MUX", "ADC1", "ADC1"},
2132 {"ANC2 MUX", "ADC2", "ADC2"},
2133 {"ANC2 MUX", "ADC3", "ADC3"},
2134 {"ANC2 MUX", "ADC4", "ADC4"},
2135
Bradley Rubine1d08622011-07-20 18:01:35 -07002136 {"ANC", NULL, "CDC_CONN"},
2137
Bradley Rubin229c6a52011-07-12 16:18:48 -07002138 {"DAC1", "Switch", "RX1 CHAIN"},
2139 {"HPHL DAC", "Switch", "RX1 CHAIN"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07002140 {"HPHR DAC", NULL, "RX2 CHAIN"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002141
Kiran Kandidb0a4b02011-08-23 09:32:09 -07002142 {"LINEOUT1", NULL, "LINEOUT1 PA"},
2143 {"LINEOUT2", NULL, "LINEOUT2 PA"},
2144 {"LINEOUT3", NULL, "LINEOUT3 PA"},
2145 {"LINEOUT4", NULL, "LINEOUT4 PA"},
2146 {"LINEOUT5", NULL, "LINEOUT5 PA"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07002147
Kiran Kandidb0a4b02011-08-23 09:32:09 -07002148 {"LINEOUT1 PA", NULL, "LINEOUT1 DAC"},
2149 {"LINEOUT2 PA", NULL, "LINEOUT2 DAC"},
2150 {"LINEOUT3 PA", NULL, "LINEOUT3 DAC"},
2151 {"LINEOUT4 PA", NULL, "LINEOUT4 DAC"},
2152 {"LINEOUT5 PA", NULL, "LINEOUT5 DAC"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07002153
Kiran Kandi8b3a8302011-09-27 16:13:28 -07002154 {"LINEOUT1 DAC", NULL, "RX3 MIX1"},
2155 {"LINEOUT5 DAC", NULL, "RX7 MIX1"},
2156
Bradley Rubin229c6a52011-07-12 16:18:48 -07002157 {"RX1 CHAIN", NULL, "RX1 MIX1"},
2158 {"RX2 CHAIN", NULL, "RX2 MIX1"},
2159 {"RX1 CHAIN", NULL, "ANC"},
2160 {"RX2 CHAIN", NULL, "ANC"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07002161
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002162 {"CP", NULL, "RX_BIAS"},
2163 {"LINEOUT1 DAC", NULL, "RX_BIAS"},
2164 {"LINEOUT2 DAC", NULL, "RX_BIAS"},
2165 {"LINEOUT3 DAC", NULL, "RX_BIAS"},
2166 {"LINEOUT4 DAC", NULL, "RX_BIAS"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07002167 {"LINEOUT5 DAC", NULL, "RX_BIAS"},
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002168
Bradley Rubin229c6a52011-07-12 16:18:48 -07002169 {"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
2170 {"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
2171 {"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
2172 {"RX2 MIX1", NULL, "RX2 MIX1 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07002173 {"RX3 MIX1", NULL, "RX3 MIX1 INP1"},
2174 {"RX3 MIX1", NULL, "RX3 MIX1 INP2"},
2175 {"RX4 MIX1", NULL, "RX4 MIX1 INP1"},
2176 {"RX4 MIX1", NULL, "RX4 MIX1 INP2"},
2177 {"RX5 MIX1", NULL, "RX5 MIX1 INP1"},
2178 {"RX5 MIX1", NULL, "RX5 MIX1 INP2"},
2179 {"RX6 MIX1", NULL, "RX6 MIX1 INP1"},
2180 {"RX6 MIX1", NULL, "RX6 MIX1 INP2"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07002181 {"RX7 MIX1", NULL, "RX7 MIX1 INP1"},
2182 {"RX7 MIX1", NULL, "RX7 MIX1 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07002183
Bradley Rubin229c6a52011-07-12 16:18:48 -07002184 {"RX1 MIX1 INP1", "RX1", "SLIM RX1"},
2185 {"RX1 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302186 {"RX1 MIX1 INP1", "RX3", "SLIM RX3"},
2187 {"RX1 MIX1 INP1", "RX4", "SLIM RX4"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002188 {"RX1 MIX1 INP1", "IIR1", "IIR1"},
2189 {"RX1 MIX1 INP2", "RX1", "SLIM RX1"},
2190 {"RX1 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302191 {"RX1 MIX1 INP2", "RX3", "SLIM RX3"},
2192 {"RX1 MIX1 INP2", "RX4", "SLIM RX4"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002193 {"RX1 MIX1 INP2", "IIR1", "IIR1"},
2194 {"RX2 MIX1 INP1", "RX1", "SLIM RX1"},
2195 {"RX2 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302196 {"RX2 MIX1 INP1", "RX3", "SLIM RX3"},
2197 {"RX2 MIX1 INP1", "RX4", "SLIM RX4"},
Patrick Lai16261e82011-09-30 13:25:52 -07002198 {"RX2 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002199 {"RX2 MIX1 INP2", "RX1", "SLIM RX1"},
2200 {"RX2 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302201 {"RX2 MIX1 INP2", "RX3", "SLIM RX3"},
2202 {"RX2 MIX1 INP2", "RX4", "SLIM RX4"},
Patrick Lai16261e82011-09-30 13:25:52 -07002203 {"RX2 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002204 {"RX3 MIX1 INP1", "RX1", "SLIM RX1"},
2205 {"RX3 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302206 {"RX3 MIX1 INP1", "RX3", "SLIM RX3"},
2207 {"RX3 MIX1 INP1", "RX4", "SLIM RX4"},
Patrick Lai16261e82011-09-30 13:25:52 -07002208 {"RX3 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002209 {"RX3 MIX1 INP2", "RX1", "SLIM RX1"},
2210 {"RX3 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302211 {"RX3 MIX1 INP2", "RX3", "SLIM RX3"},
2212 {"RX3 MIX1 INP2", "RX4", "SLIM RX4"},
Patrick Lai16261e82011-09-30 13:25:52 -07002213 {"RX3 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002214 {"RX4 MIX1 INP1", "RX1", "SLIM RX1"},
2215 {"RX4 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302216 {"RX4 MIX1 INP1", "RX3", "SLIM RX3"},
2217 {"RX4 MIX1 INP1", "RX4", "SLIM RX4"},
Patrick Lai16261e82011-09-30 13:25:52 -07002218 {"RX4 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002219 {"RX4 MIX1 INP2", "RX1", "SLIM RX1"},
2220 {"RX4 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302221 {"RX4 MIX1 INP2", "RX3", "SLIM RX3"},
2222 {"RX4 MIX1 INP2", "RX4", "SLIM RX4"},
Patrick Lai16261e82011-09-30 13:25:52 -07002223 {"RX4 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002224 {"RX5 MIX1 INP1", "RX1", "SLIM RX1"},
2225 {"RX5 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302226 {"RX5 MIX1 INP1", "RX3", "SLIM RX3"},
2227 {"RX5 MIX1 INP1", "RX4", "SLIM RX4"},
Patrick Lai16261e82011-09-30 13:25:52 -07002228 {"RX5 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002229 {"RX5 MIX1 INP2", "RX1", "SLIM RX1"},
2230 {"RX5 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302231 {"RX5 MIX1 INP2", "RX3", "SLIM RX3"},
2232 {"RX5 MIX1 INP2", "RX4", "SLIM RX4"},
Patrick Lai16261e82011-09-30 13:25:52 -07002233 {"RX5 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002234 {"RX6 MIX1 INP1", "RX1", "SLIM RX1"},
2235 {"RX6 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302236 {"RX6 MIX1 INP1", "RX3", "SLIM RX3"},
2237 {"RX6 MIX1 INP1", "RX4", "SLIM RX4"},
Patrick Lai16261e82011-09-30 13:25:52 -07002238 {"RX6 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002239 {"RX6 MIX1 INP2", "RX1", "SLIM RX1"},
2240 {"RX6 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302241 {"RX6 MIX1 INP2", "RX3", "SLIM RX3"},
2242 {"RX6 MIX1 INP2", "RX4", "SLIM RX4"},
Patrick Lai16261e82011-09-30 13:25:52 -07002243 {"RX6 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07002244 {"RX7 MIX1 INP1", "RX1", "SLIM RX1"},
2245 {"RX7 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302246 {"RX7 MIX1 INP1", "RX3", "SLIM RX3"},
2247 {"RX7 MIX1 INP1", "RX4", "SLIM RX4"},
Patrick Lai16261e82011-09-30 13:25:52 -07002248 {"RX7 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07002249 {"RX7 MIX1 INP2", "RX1", "SLIM RX1"},
2250 {"RX7 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05302251 {"RX7 MIX1 INP2", "RX3", "SLIM RX3"},
2252 {"RX7 MIX1 INP2", "RX4", "SLIM RX4"},
Patrick Lai16261e82011-09-30 13:25:52 -07002253 {"RX7 MIX1 INP2", "IIR1", "IIR1"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002254
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002255 /* Decimator Inputs */
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002256 {"DEC1 MUX", "DMIC1", "DMIC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002257 {"DEC1 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07002258 {"DEC1 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002259 {"DEC2 MUX", "DMIC2", "DMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002260 {"DEC2 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07002261 {"DEC2 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002262 {"DEC3 MUX", "DMIC3", "DMIC3"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002263 {"DEC3 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07002264 {"DEC3 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002265 {"DEC4 MUX", "DMIC4", "DMIC4"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002266 {"DEC4 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07002267 {"DEC4 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002268 {"DEC5 MUX", "DMIC5", "DMIC5"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002269 {"DEC5 MUX", "ADC2", "ADC2"},
Bradley Rubine1d08622011-07-20 18:01:35 -07002270 {"DEC5 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002271 {"DEC6 MUX", "DMIC6", "DMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002272 {"DEC6 MUX", "ADC1", "ADC1"},
Bradley Rubine1d08622011-07-20 18:01:35 -07002273 {"DEC6 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002274 {"DEC7 MUX", "DMIC1", "DMIC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002275 {"DEC7 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07002276 {"DEC7 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002277 {"DEC8 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07002278 {"DEC8 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002279 {"DEC9 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07002280 {"DEC9 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002281 {"DEC10 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07002282 {"DEC10 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002283
2284 /* ADC Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002285 {"ADC1", NULL, "AMIC1"},
2286 {"ADC2", NULL, "AMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002287 {"ADC3", NULL, "AMIC3"},
2288 {"ADC4", NULL, "AMIC4"},
2289 {"ADC5", NULL, "AMIC5"},
2290 {"ADC6", NULL, "AMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002291
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002292 {"IIR1", NULL, "IIR1 INP1 MUX"},
Patrick Lai16261e82011-09-30 13:25:52 -07002293 {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"},
2294 {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"},
2295 {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"},
2296 {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"},
2297 {"IIR1 INP1 MUX", "DEC5", "DEC5 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002298 {"IIR1 INP1 MUX", "DEC6", "DEC6 MUX"},
Patrick Lai16261e82011-09-30 13:25:52 -07002299 {"IIR1 INP1 MUX", "DEC7", "DEC7 MUX"},
2300 {"IIR1 INP1 MUX", "DEC8", "DEC8 MUX"},
2301 {"IIR1 INP1 MUX", "DEC9", "DEC9 MUX"},
2302 {"IIR1 INP1 MUX", "DEC10", "DEC10 MUX"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07002303
2304 {"MIC BIAS1 Internal1", NULL, "LDO_H"},
2305 {"MIC BIAS1 Internal2", NULL, "LDO_H"},
2306 {"MIC BIAS1 External", NULL, "LDO_H"},
2307 {"MIC BIAS2 Internal1", NULL, "LDO_H"},
2308 {"MIC BIAS2 Internal2", NULL, "LDO_H"},
2309 {"MIC BIAS2 Internal3", NULL, "LDO_H"},
2310 {"MIC BIAS2 External", NULL, "LDO_H"},
2311 {"MIC BIAS3 Internal1", NULL, "LDO_H"},
2312 {"MIC BIAS3 Internal2", NULL, "LDO_H"},
2313 {"MIC BIAS3 External", NULL, "LDO_H"},
2314 {"MIC BIAS4 External", NULL, "LDO_H"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002315};
2316
Kiran Kandi8b3a8302011-09-27 16:13:28 -07002317static const struct snd_soc_dapm_route tabla_1_x_lineout_2_to_4_map[] = {
2318
2319 {"RX4 DSM MUX", "DSM_INV", "RX3 MIX1"},
2320 {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"},
2321
2322 {"LINEOUT2 DAC", NULL, "RX4 DSM MUX"},
2323
2324 {"LINEOUT3 DAC", NULL, "RX5 MIX1"},
2325 {"LINEOUT3 DAC GROUND", "Switch", "RX3 MIX1"},
2326 {"LINEOUT3 DAC", NULL, "LINEOUT3 DAC GROUND"},
2327
2328 {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"},
2329 {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"},
2330
2331 {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"},
2332 {"LINEOUT4 DAC GROUND", "Switch", "RX4 DSM MUX"},
2333 {"LINEOUT4 DAC", NULL, "LINEOUT4 DAC GROUND"},
2334};
2335
Kiran Kandi7a9fd902011-11-14 13:51:45 -08002336
2337static const struct snd_soc_dapm_route tabla_2_x_lineout_2_to_4_map[] = {
2338
2339 {"RX4 DSM MUX", "DSM_INV", "RX3 MIX1"},
2340 {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"},
2341
2342 {"LINEOUT3 DAC", NULL, "RX4 DSM MUX"},
2343
2344 {"LINEOUT2 DAC", NULL, "RX5 MIX1"},
2345
2346 {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"},
2347 {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"},
2348
2349 {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"},
2350};
2351
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002352static int tabla_readable(struct snd_soc_codec *ssc, unsigned int reg)
2353{
2354 return tabla_reg_readable[reg];
2355}
2356
2357static int tabla_volatile(struct snd_soc_codec *ssc, unsigned int reg)
2358{
2359 /* Registers lower than 0x100 are top level registers which can be
2360 * written by the Tabla core driver.
2361 */
2362
2363 if ((reg >= TABLA_A_CDC_MBHC_EN_CTL) || (reg < 0x100))
2364 return 1;
2365
Ben Romberger1f045a72011-11-04 10:14:57 -07002366 /* IIR Coeff registers are not cacheable */
2367 if ((reg >= TABLA_A_CDC_IIR1_COEF_B1_CTL) &&
2368 (reg <= TABLA_A_CDC_IIR2_COEF_B5_CTL))
2369 return 1;
2370
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002371 return 0;
2372}
2373
2374#define TABLA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
2375static int tabla_write(struct snd_soc_codec *codec, unsigned int reg,
2376 unsigned int value)
2377{
2378 int ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002379
2380 BUG_ON(reg > TABLA_MAX_REGISTER);
2381
2382 if (!tabla_volatile(codec, reg)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002383 ret = snd_soc_cache_write(codec, reg, value);
2384 if (ret != 0)
2385 dev_err(codec->dev, "Cache write to %x failed: %d\n",
2386 reg, ret);
2387 }
2388
2389 return tabla_reg_write(codec->control_data, reg, value);
2390}
2391static unsigned int tabla_read(struct snd_soc_codec *codec,
2392 unsigned int reg)
2393{
2394 unsigned int val;
2395 int ret;
2396
2397 BUG_ON(reg > TABLA_MAX_REGISTER);
2398
2399 if (!tabla_volatile(codec, reg) && tabla_readable(codec, reg) &&
2400 reg < codec->driver->reg_cache_size) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002401 ret = snd_soc_cache_read(codec, reg, &val);
2402 if (ret >= 0) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002403 return val;
2404 } else
2405 dev_err(codec->dev, "Cache read from %x failed: %d\n",
2406 reg, ret);
2407 }
2408
2409 val = tabla_reg_read(codec->control_data, reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002410 return val;
2411}
2412
2413static void tabla_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec)
2414{
2415 snd_soc_write(codec, TABLA_A_BIAS_REF_CTL, 0x1C);
2416 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2417 0x80);
2418 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x04,
2419 0x04);
2420 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01,
2421 0x01);
2422 usleep_range(1000, 1000);
2423 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2424 0x00);
2425}
2426
2427static void tabla_codec_enable_bandgap(struct snd_soc_codec *codec,
2428 enum tabla_bandgap_type choice)
2429{
2430 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2431
2432 /* TODO lock resources accessed by audio streams and threaded
2433 * interrupt handlers
2434 */
2435
2436 pr_debug("%s, choice is %d, current is %d\n", __func__, choice,
2437 tabla->bandgap_type);
2438
2439 if (tabla->bandgap_type == choice)
2440 return;
2441
2442 if ((tabla->bandgap_type == TABLA_BANDGAP_OFF) &&
2443 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
2444 tabla_codec_enable_audio_mode_bandgap(codec);
2445 } else if ((tabla->bandgap_type == TABLA_BANDGAP_AUDIO_MODE) &&
2446 (choice == TABLA_BANDGAP_MBHC_MODE)) {
2447 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x2,
2448 0x2);
2449 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2450 0x80);
2451 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x4,
2452 0x4);
2453 usleep_range(1000, 1000);
2454 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2455 0x00);
2456 } else if ((tabla->bandgap_type == TABLA_BANDGAP_MBHC_MODE) &&
2457 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
2458 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x00);
2459 usleep_range(100, 100);
2460 tabla_codec_enable_audio_mode_bandgap(codec);
2461 } else if (choice == TABLA_BANDGAP_OFF) {
2462 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x00);
2463 } else {
2464 pr_err("%s: Error, Invalid bandgap settings\n", __func__);
2465 }
2466 tabla->bandgap_type = choice;
2467}
2468
2469static int tabla_codec_enable_config_mode(struct snd_soc_codec *codec,
2470 int enable)
2471{
2472 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2473
2474 if (enable) {
2475 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x10, 0);
2476 snd_soc_write(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x17);
2477 usleep_range(5, 5);
2478 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80,
2479 0x80);
2480 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80,
2481 0x80);
2482 usleep_range(10, 10);
2483 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, 0);
2484 usleep_range(20, 20);
2485 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x08);
2486 } else {
2487 snd_soc_update_bits(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x1,
2488 0);
2489 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, 0);
2490 }
2491 tabla->config_mode_active = enable ? true : false;
2492
2493 return 0;
2494}
2495
2496static int tabla_codec_enable_clock_block(struct snd_soc_codec *codec,
2497 int config_mode)
2498{
2499 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2500
2501 pr_debug("%s\n", __func__);
2502
2503 if (config_mode) {
2504 tabla_codec_enable_config_mode(codec, 1);
2505 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x00);
2506 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
2507 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN1, 0x0D);
2508 usleep_range(1000, 1000);
2509 } else
2510 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00);
2511
2512 if (!config_mode && tabla->mbhc_polling_active) {
2513 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
2514 tabla_codec_enable_config_mode(codec, 0);
2515
2516 }
2517
2518 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x05);
2519 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x00);
2520 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x04);
2521 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_MCLK_CTL, 0x01, 0x01);
2522 usleep_range(50, 50);
2523 tabla->clock_active = true;
2524 return 0;
2525}
2526static void tabla_codec_disable_clock_block(struct snd_soc_codec *codec)
2527{
2528 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2529 pr_debug("%s\n", __func__);
2530 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x00);
2531 ndelay(160);
2532 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x02);
2533 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x00);
2534 tabla->clock_active = false;
2535}
2536
Bradley Rubincb1e2732011-06-23 16:49:20 -07002537static void tabla_codec_calibrate_hs_polling(struct snd_soc_codec *codec)
2538{
2539 /* TODO store register values in calibration */
Bhalchandra Gajare30cf4842011-10-17 18:12:52 -07002540 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0x20);
2541 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0xFF);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002542
2543 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B10_CTL, 0xFF);
Bhalchandra Gajare30cf4842011-10-17 18:12:52 -07002544 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B9_CTL, 0x20);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002545
Bhalchandra Gajarefabb8772011-11-10 19:52:01 -08002546 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, 0xF8);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002547 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0xEE);
2548 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, 0xFC);
2549 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, 0xCE);
2550
2551 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL, 3);
2552 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B2_CTL, 9);
2553 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B3_CTL, 30);
2554 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL, 120);
2555 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL, 0x78, 0x58);
2556 snd_soc_write(codec, TABLA_A_CDC_MBHC_B2_CTL, 11);
2557}
2558
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002559static int tabla_startup(struct snd_pcm_substream *substream,
2560 struct snd_soc_dai *dai)
2561{
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002562 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
2563 substream->name, substream->stream);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002564
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002565 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002566}
2567
2568static void tabla_shutdown(struct snd_pcm_substream *substream,
2569 struct snd_soc_dai *dai)
2570{
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002571 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
2572 substream->name, substream->stream);
2573}
2574
2575int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable)
2576{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002577 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2578
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002579 pr_debug("%s() mclk_enable = %u\n", __func__, mclk_enable);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002580
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002581 if (mclk_enable) {
2582 tabla->mclk_enabled = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002583
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002584 if (tabla->mbhc_polling_active && (tabla->mclk_enabled)) {
Bradley Rubincb1e2732011-06-23 16:49:20 -07002585 tabla_codec_pause_hs_polling(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002586 tabla_codec_enable_bandgap(codec,
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002587 TABLA_BANDGAP_AUDIO_MODE);
2588 tabla_codec_enable_clock_block(codec, 0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002589 tabla_codec_calibrate_hs_polling(codec);
2590 tabla_codec_start_hs_polling(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002591 }
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002592 } else {
2593
2594 if (!tabla->mclk_enabled) {
2595 pr_err("Error, MCLK already diabled\n");
2596 return -EINVAL;
2597 }
2598 tabla->mclk_enabled = false;
2599
2600 if (tabla->mbhc_polling_active) {
2601 if (!tabla->mclk_enabled) {
2602 tabla_codec_pause_hs_polling(codec);
2603 tabla_codec_enable_bandgap(codec,
2604 TABLA_BANDGAP_MBHC_MODE);
2605 tabla_enable_rx_bias(codec, 1);
2606 tabla_codec_enable_clock_block(codec, 1);
2607 tabla_codec_calibrate_hs_polling(codec);
2608 tabla_codec_start_hs_polling(codec);
2609 }
2610 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1,
2611 0x05, 0x01);
2612 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002613 }
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002614 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002615}
2616
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002617static int tabla_set_dai_sysclk(struct snd_soc_dai *dai,
2618 int clk_id, unsigned int freq, int dir)
2619{
2620 pr_debug("%s\n", __func__);
2621 return 0;
2622}
2623
2624static int tabla_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2625{
Santosh Mardie15e2302011-11-15 10:39:23 +05302626 u8 val = 0;
2627 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
2628
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002629 pr_debug("%s\n", __func__);
Santosh Mardie15e2302011-11-15 10:39:23 +05302630 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2631 case SND_SOC_DAIFMT_CBS_CFS:
2632 /* CPU is master */
2633 if (tabla->intf_type == TABLA_INTERFACE_TYPE_I2C) {
2634 if (dai->id == TABLA_TX_DAI_ID)
2635 snd_soc_update_bits(dai->codec,
2636 TABLA_A_CDC_CLK_TX_I2S_CTL,
2637 TABLA_I2S_MASTER_MODE_MASK, 0);
2638 else if (dai->id == TABLA_RX_DAI_ID)
2639 snd_soc_update_bits(dai->codec,
2640 TABLA_A_CDC_CLK_RX_I2S_CTL,
2641 TABLA_I2S_MASTER_MODE_MASK, 0);
2642 }
2643 break;
2644 case SND_SOC_DAIFMT_CBM_CFM:
2645 /* CPU is slave */
2646 if (tabla->intf_type == TABLA_INTERFACE_TYPE_I2C) {
2647 val = TABLA_I2S_MASTER_MODE_MASK;
2648 if (dai->id == TABLA_TX_DAI_ID)
2649 snd_soc_update_bits(dai->codec,
2650 TABLA_A_CDC_CLK_TX_I2S_CTL, val, val);
2651 else if (dai->id == TABLA_RX_DAI_ID)
2652 snd_soc_update_bits(dai->codec,
2653 TABLA_A_CDC_CLK_RX_I2S_CTL, val, val);
2654 }
2655 break;
2656 default:
2657 return -EINVAL;
2658 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002659 return 0;
2660}
2661
2662static int tabla_hw_params(struct snd_pcm_substream *substream,
2663 struct snd_pcm_hw_params *params,
2664 struct snd_soc_dai *dai)
2665{
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07002666 struct snd_soc_codec *codec = dai->codec;
Santosh Mardie15e2302011-11-15 10:39:23 +05302667 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
Bhalchandra Gajare038bf3a2011-09-02 15:32:30 -07002668 u8 path, shift;
2669 u16 tx_fs_reg, rx_fs_reg;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07002670 u8 tx_fs_rate, rx_fs_rate, rx_state, tx_state;
2671
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002672 pr_debug("%s: DAI-ID %x\n", __func__, dai->id);
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07002673
2674 switch (params_rate(params)) {
2675 case 8000:
2676 tx_fs_rate = 0x00;
2677 rx_fs_rate = 0x00;
2678 break;
2679 case 16000:
2680 tx_fs_rate = 0x01;
2681 rx_fs_rate = 0x20;
2682 break;
2683 case 32000:
2684 tx_fs_rate = 0x02;
2685 rx_fs_rate = 0x40;
2686 break;
2687 case 48000:
2688 tx_fs_rate = 0x03;
2689 rx_fs_rate = 0x60;
2690 break;
2691 default:
2692 pr_err("%s: Invalid sampling rate %d\n", __func__,
2693 params_rate(params));
2694 return -EINVAL;
2695 }
2696
2697
2698 /**
2699 * If current dai is a tx dai, set sample rate to
2700 * all the txfe paths that are currently not active
2701 */
2702 if (dai->id == TABLA_TX_DAI_ID) {
2703
2704 tx_state = snd_soc_read(codec,
2705 TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL);
2706
2707 for (path = 1, shift = 0;
2708 path <= NUM_DECIMATORS; path++, shift++) {
2709
2710 if (path == BITS_PER_REG + 1) {
2711 shift = 0;
2712 tx_state = snd_soc_read(codec,
2713 TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL);
2714 }
2715
2716 if (!(tx_state & (1 << shift))) {
2717 tx_fs_reg = TABLA_A_CDC_TX1_CLK_FS_CTL
2718 + (BITS_PER_REG*(path-1));
2719 snd_soc_update_bits(codec, tx_fs_reg,
2720 0x03, tx_fs_rate);
2721 }
2722 }
Santosh Mardie15e2302011-11-15 10:39:23 +05302723 if (tabla->intf_type == TABLA_INTERFACE_TYPE_I2C) {
2724 switch (params_format(params)) {
2725 case SNDRV_PCM_FORMAT_S16_LE:
2726 snd_soc_update_bits(codec,
2727 TABLA_A_CDC_CLK_TX_I2S_CTL,
2728 0x20, 0x20);
2729 break;
2730 case SNDRV_PCM_FORMAT_S32_LE:
2731 snd_soc_update_bits(codec,
2732 TABLA_A_CDC_CLK_TX_I2S_CTL,
2733 0x20, 0x00);
2734 break;
2735 default:
2736 pr_err("invalid format\n");
2737 break;
2738 }
2739 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_TX_I2S_CTL,
2740 0x03, tx_fs_rate);
2741 }
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07002742 }
2743
2744 /**
2745 * TODO: Need to handle case where same RX chain takes 2 or more inputs
2746 * with varying sample rates
2747 */
2748
2749 /**
2750 * If current dai is a rx dai, set sample rate to
2751 * all the rx paths that are currently not active
2752 */
2753 if (dai->id == TABLA_RX_DAI_ID) {
2754
2755 rx_state = snd_soc_read(codec,
2756 TABLA_A_CDC_CLK_RX_B1_CTL);
2757
2758 for (path = 1, shift = 0;
2759 path <= NUM_INTERPOLATORS; path++, shift++) {
2760
2761 if (!(rx_state & (1 << shift))) {
2762 rx_fs_reg = TABLA_A_CDC_RX1_B5_CTL
2763 + (BITS_PER_REG*(path-1));
2764 snd_soc_update_bits(codec, rx_fs_reg,
2765 0xE0, rx_fs_rate);
2766 }
2767 }
Santosh Mardie15e2302011-11-15 10:39:23 +05302768 if (tabla->intf_type == TABLA_INTERFACE_TYPE_I2C) {
2769 switch (params_format(params)) {
2770 case SNDRV_PCM_FORMAT_S16_LE:
2771 snd_soc_update_bits(codec,
2772 TABLA_A_CDC_CLK_RX_I2S_CTL,
2773 0x20, 0x20);
2774 break;
2775 case SNDRV_PCM_FORMAT_S32_LE:
2776 snd_soc_update_bits(codec,
2777 TABLA_A_CDC_CLK_RX_I2S_CTL,
2778 0x20, 0x00);
2779 break;
2780 default:
2781 pr_err("invalid format\n");
2782 break;
2783 }
2784 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_I2S_CTL,
2785 0x03, (rx_fs_rate >> 0x05));
2786 }
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07002787 }
2788
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002789 return 0;
2790}
2791
2792static struct snd_soc_dai_ops tabla_dai_ops = {
2793 .startup = tabla_startup,
2794 .shutdown = tabla_shutdown,
2795 .hw_params = tabla_hw_params,
2796 .set_sysclk = tabla_set_dai_sysclk,
2797 .set_fmt = tabla_set_dai_fmt,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002798};
2799
2800static struct snd_soc_dai_driver tabla_dai[] = {
2801 {
2802 .name = "tabla_rx1",
2803 .id = 1,
2804 .playback = {
2805 .stream_name = "AIF1 Playback",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07002806 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002807 .formats = TABLA_FORMATS,
2808 .rate_max = 48000,
2809 .rate_min = 8000,
2810 .channels_min = 1,
2811 .channels_max = 2,
2812 },
2813 .ops = &tabla_dai_ops,
2814 },
2815 {
2816 .name = "tabla_tx1",
2817 .id = 2,
2818 .capture = {
2819 .stream_name = "AIF1 Capture",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07002820 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002821 .formats = TABLA_FORMATS,
2822 .rate_max = 48000,
2823 .rate_min = 8000,
2824 .channels_min = 1,
2825 .channels_max = 2,
2826 },
2827 .ops = &tabla_dai_ops,
2828 },
2829};
Santosh Mardie15e2302011-11-15 10:39:23 +05302830
2831static struct snd_soc_dai_driver tabla_i2s_dai[] = {
2832 {
2833 .name = "tabla_i2s_rx1",
2834 .id = 1,
2835 .playback = {
2836 .stream_name = "AIF1 Playback",
2837 .rates = WCD9310_RATES,
2838 .formats = TABLA_FORMATS,
2839 .rate_max = 48000,
2840 .rate_min = 8000,
2841 .channels_min = 1,
2842 .channels_max = 4,
2843 },
2844 .ops = &tabla_dai_ops,
2845 },
2846 {
2847 .name = "tabla_i2s_tx1",
2848 .id = 2,
2849 .capture = {
2850 .stream_name = "AIF1 Capture",
2851 .rates = WCD9310_RATES,
2852 .formats = TABLA_FORMATS,
2853 .rate_max = 48000,
2854 .rate_min = 8000,
2855 .channels_min = 1,
2856 .channels_max = 4,
2857 },
2858 .ops = &tabla_dai_ops,
2859 },
2860};
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002861static short tabla_codec_read_sta_result(struct snd_soc_codec *codec)
Bradley Rubincb1e2732011-06-23 16:49:20 -07002862{
2863 u8 bias_msb, bias_lsb;
2864 short bias_value;
2865
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002866 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B3_STATUS);
2867 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B2_STATUS);
2868 bias_value = (bias_msb << 8) | bias_lsb;
2869 return bias_value;
2870}
2871
2872static short tabla_codec_read_dce_result(struct snd_soc_codec *codec)
2873{
2874 u8 bias_msb, bias_lsb;
2875 short bias_value;
2876
2877 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B5_STATUS);
2878 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B4_STATUS);
2879 bias_value = (bias_msb << 8) | bias_lsb;
2880 return bias_value;
2881}
2882
2883static short tabla_codec_measure_micbias_voltage(struct snd_soc_codec *codec,
2884 int dce)
2885{
2886 short bias_value;
2887
Bradley Rubincb1e2732011-06-23 16:49:20 -07002888 if (dce) {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002889 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
2890 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
2891 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
2892 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
2893 usleep_range(60000, 60000);
2894 bias_value = tabla_codec_read_dce_result(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002895 } else {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002896 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002897 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
2898 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002899 usleep_range(5000, 5000);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002900 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002901 usleep_range(50, 50);
2902 bias_value = tabla_codec_read_sta_result(codec);
2903 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
2904 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002905 }
2906
Bradley Rubincb1e2732011-06-23 16:49:20 -07002907 pr_debug("read microphone bias value %x\n", bias_value);
2908 return bias_value;
2909}
2910
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07002911static short tabla_codec_setup_hs_polling(struct snd_soc_codec *codec)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002912{
2913 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2914 struct tabla_mbhc_calibration *calibration = tabla->calibration;
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07002915 short bias_value;
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002916 u8 cfilt_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002917
2918 if (!calibration) {
2919 pr_err("Error, no tabla calibration\n");
Bradley Rubincb1e2732011-06-23 16:49:20 -07002920 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002921 }
2922
2923 tabla->mbhc_polling_active = true;
2924
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002925 if (!tabla->mclk_enabled) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002926 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_MBHC_MODE);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002927 tabla_enable_rx_bias(codec, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002928 tabla_codec_enable_clock_block(codec, 1);
2929 }
2930
2931 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x01);
2932
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002933 snd_soc_update_bits(codec, TABLA_A_TX_COM_BIAS, 0xE0, 0xE0);
2934
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002935 /* Make sure CFILT is in fast mode, save current mode */
2936 cfilt_mode = snd_soc_read(codec,
2937 tabla->mbhc_bias_regs.cfilt_ctl);
2938 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl,
2939 0x70, 0x00);
Patrick Lai3043fba2011-08-01 14:15:57 -07002940
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002941 snd_soc_update_bits(codec,
2942 tabla->mbhc_bias_regs.ctl_reg, 0x1F, 0x16);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002943
2944 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002945 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002946
2947 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x80);
2948 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x1F, 0x1C);
2949 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x40, 0x40);
2950
2951 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002952 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
2953 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002954
Bradley Rubincb1e2732011-06-23 16:49:20 -07002955 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x6, 0x6);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002956 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
2957
Bradley Rubincb1e2732011-06-23 16:49:20 -07002958 tabla_codec_calibrate_hs_polling(codec);
2959
2960 bias_value = tabla_codec_measure_micbias_voltage(codec, 0);
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002961 snd_soc_update_bits(codec,
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002962 tabla->mbhc_bias_regs.cfilt_ctl, 0x40, cfilt_mode);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07002963 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07002964
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07002965 return bias_value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002966}
2967
2968static int tabla_codec_enable_hs_detect(struct snd_soc_codec *codec,
2969 int insertion)
2970{
2971 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2972 struct tabla_mbhc_calibration *calibration = tabla->calibration;
2973 int central_bias_enabled = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002974
2975 if (!calibration) {
2976 pr_err("Error, no tabla calibration\n");
2977 return -EINVAL;
2978 }
2979
2980 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0);
2981
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07002982 if (insertion) {
2983 /* Make sure mic bias and Mic line schmitt trigger
2984 * are turned OFF
2985 */
2986 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg,
2987 0x81, 0x01);
2988 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2989 0x90, 0x00);
2990
2991 /* Enable HPH Schmitt Trigger */
2992 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x13);
2993 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x0C,
2994 calibration->hph_current << 2);
2995
2996 /* Turn off HPH PAs during insertion detection to avoid false
2997 * insertion interrupts
2998 */
2999 if (tabla->mbhc_micbias_switched)
3000 tabla_codec_switch_micbias(codec, 0);
3001 snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00);
3002
3003 /* setup for insetion detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003004 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07003005 } else {
3006 /* Make sure the HPH schmitt trigger is OFF */
3007 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x12, 0x00);
3008
3009 /* enable the mic line schmitt trigger */
3010 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x60,
3011 calibration->mic_current << 5);
3012 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
3013 0x80, 0x80);
3014 usleep_range(calibration->mic_pid, calibration->mic_pid);
3015 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
3016 0x10, 0x10);
3017
3018 /* Setup for low power removal detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003019 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0x2);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07003020 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003021
3022 if (snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x4) {
3023 if (!(tabla->clock_active)) {
3024 tabla_codec_enable_config_mode(codec, 1);
3025 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07003026 0x06, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003027 usleep_range(calibration->shutdown_plug_removal,
3028 calibration->shutdown_plug_removal);
3029 tabla_codec_enable_config_mode(codec, 0);
3030 } else
3031 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07003032 0x06, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003033 }
3034
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003035 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.int_rbias, 0x80, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003036
3037 /* If central bandgap disabled */
3038 if (!(snd_soc_read(codec, TABLA_A_PIN_CTL_OE1) & 1)) {
3039 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x3, 0x3);
3040 usleep_range(calibration->bg_fast_settle,
3041 calibration->bg_fast_settle);
3042 central_bias_enabled = 1;
3043 }
3044
3045 /* If LDO_H disabled */
3046 if (snd_soc_read(codec, TABLA_A_PIN_CTL_OE0) & 0x80) {
3047 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x10, 0);
3048 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0x80);
3049 usleep_range(calibration->tldoh, calibration->tldoh);
3050 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0);
3051
3052 if (central_bias_enabled)
3053 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x1, 0);
3054 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003055
3056 snd_soc_update_bits(codec, TABLA_A_MICB_4_MBHC, 0x3, calibration->bias);
3057
3058 tabla_enable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
3059 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0x1);
3060 return 0;
3061}
3062
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07003063static void btn0_lpress_fn(struct work_struct *work)
3064{
3065 struct delayed_work *delayed_work;
3066 struct tabla_priv *tabla;
3067
3068 pr_debug("%s:\n", __func__);
3069
3070 delayed_work = to_delayed_work(work);
3071 tabla = container_of(delayed_work, struct tabla_priv, btn0_dwork);
3072
3073 if (tabla) {
3074 if (tabla->button_jack) {
3075 pr_debug("%s: Reporting long button press event\n",
3076 __func__);
3077 snd_soc_jack_report(tabla->button_jack, SND_JACK_BTN_0,
3078 SND_JACK_BTN_0);
3079 }
3080 } else {
3081 pr_err("%s: Bad tabla private data\n", __func__);
3082 }
3083
3084}
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003085
Bradley Rubincb1e2732011-06-23 16:49:20 -07003086int tabla_hs_detect(struct snd_soc_codec *codec,
3087 struct snd_soc_jack *headset_jack, struct snd_soc_jack *button_jack,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003088 struct tabla_mbhc_calibration *calibration)
3089{
3090 struct tabla_priv *tabla;
Patrick Lai49efeac2011-11-03 11:01:12 -07003091 int rc;
3092
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003093 if (!codec || !calibration) {
3094 pr_err("Error: no codec or calibration\n");
3095 return -EINVAL;
3096 }
3097 tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003098 tabla->headset_jack = headset_jack;
3099 tabla->button_jack = button_jack;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003100 tabla->calibration = calibration;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003101 tabla_get_mbhc_micbias_regs(codec, &tabla->mbhc_bias_regs);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003102
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08003103 /* Put CFILT in fast mode by default */
3104 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl,
3105 0x40, TABLA_CFILT_FAST_MODE);
3106
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07003107 INIT_DELAYED_WORK(&tabla->btn0_dwork, btn0_lpress_fn);
Patrick Lai49efeac2011-11-03 11:01:12 -07003108 INIT_WORK(&tabla->hphlocp_work, hphlocp_off_report);
3109 INIT_WORK(&tabla->hphrocp_work, hphrocp_off_report);
3110 rc = tabla_codec_enable_hs_detect(codec, 1);
3111
3112 if (!IS_ERR_VALUE(rc)) {
3113 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
3114 0x10);
3115 tabla_enable_irq(codec->control_data,
3116 TABLA_IRQ_HPH_PA_OCPL_FAULT);
3117 tabla_enable_irq(codec->control_data,
3118 TABLA_IRQ_HPH_PA_OCPR_FAULT);
3119 }
3120
3121 return rc;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003122}
3123EXPORT_SYMBOL_GPL(tabla_hs_detect);
3124
Bradley Rubincb1e2732011-06-23 16:49:20 -07003125static irqreturn_t tabla_dce_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003126{
3127 struct tabla_priv *priv = data;
3128 struct snd_soc_codec *codec = priv->codec;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07003129 short bias_value;
Bradley Rubincb1e2732011-06-23 16:49:20 -07003130
3131 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL);
3132 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
3133
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07003134 bias_value = tabla_codec_read_dce_result(codec);
Bhalchandra Gajare30cf4842011-10-17 18:12:52 -07003135 pr_debug("%s: button press interrupt, bias value(DCE Read)=%d\n",
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07003136 __func__, bias_value);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07003137
Bhalchandra Gajare30cf4842011-10-17 18:12:52 -07003138 bias_value = tabla_codec_read_sta_result(codec);
3139 pr_debug("%s: button press interrupt, bias value(STA Read)=%d\n",
3140 __func__, bias_value);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07003141 /*
3142 * TODO: If button pressed is not button 0,
3143 * report the button press event immediately.
3144 */
3145 priv->buttons_pressed |= SND_JACK_BTN_0;
Bradley Rubincb1e2732011-06-23 16:49:20 -07003146
Bradley Rubin688c66a2011-08-16 12:25:13 -07003147 msleep(100);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003148
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07003149 schedule_delayed_work(&priv->btn0_dwork, msecs_to_jiffies(400));
3150
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003151 return IRQ_HANDLED;
3152}
3153
Bradley Rubincb1e2732011-06-23 16:49:20 -07003154static irqreturn_t tabla_release_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003155{
3156 struct tabla_priv *priv = data;
3157 struct snd_soc_codec *codec = priv->codec;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07003158 int ret, mic_voltage;
3159
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003160 pr_debug("%s\n", __func__);
3161 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07003162
Bhalchandra Gajare30cf4842011-10-17 18:12:52 -07003163 mic_voltage = tabla_codec_read_dce_result(codec);
3164 pr_debug("%s: Microphone Voltage on release(DCE Read) = %d\n",
3165 __func__, mic_voltage);
3166
Bradley Rubincb1e2732011-06-23 16:49:20 -07003167 if (priv->buttons_pressed & SND_JACK_BTN_0) {
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07003168 ret = cancel_delayed_work(&priv->btn0_dwork);
3169
3170 if (ret == 0) {
3171
3172 pr_debug("%s: Reporting long button release event\n",
3173 __func__);
3174 if (priv->button_jack) {
3175 snd_soc_jack_report(priv->button_jack, 0,
3176 SND_JACK_BTN_0);
3177 }
3178
3179 } else {
3180
3181 mic_voltage =
3182 tabla_codec_measure_micbias_voltage(codec, 0);
Bhalchandra Gajare30cf4842011-10-17 18:12:52 -07003183 pr_debug("%s: Mic Voltage on release(new STA) = %d\n",
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07003184 __func__, mic_voltage);
3185
3186 if (mic_voltage < -2000 || mic_voltage > -670) {
3187 pr_debug("%s: Fake buttton press interrupt\n",
3188 __func__);
3189 } else {
3190
3191 if (priv->button_jack) {
3192 pr_debug("%s:reporting short button press and release\n",
3193 __func__);
3194
3195 snd_soc_jack_report(priv->button_jack,
3196 SND_JACK_BTN_0, SND_JACK_BTN_0);
3197 snd_soc_jack_report(priv->button_jack,
3198 0, SND_JACK_BTN_0);
3199 }
3200 }
3201 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003202
Bradley Rubincb1e2732011-06-23 16:49:20 -07003203 priv->buttons_pressed &= ~SND_JACK_BTN_0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003204 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003205
Bradley Rubin688c66a2011-08-16 12:25:13 -07003206 tabla_codec_start_hs_polling(codec);
3207
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003208 return IRQ_HANDLED;
3209}
3210
Bradley Rubincb1e2732011-06-23 16:49:20 -07003211static void tabla_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec)
3212{
3213 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3214 struct tabla_mbhc_calibration *calibration = tabla->calibration;
Bradley Rubincb1e2732011-06-23 16:49:20 -07003215
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003216 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07003217 tabla_codec_enable_config_mode(codec, 1);
3218
3219 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
3220 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x6, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003221
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003222 snd_soc_update_bits(codec,
3223 tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003224 usleep_range(calibration->shutdown_plug_removal,
3225 calibration->shutdown_plug_removal);
3226
3227 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0xA, 0x8);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003228 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07003229 tabla_codec_enable_config_mode(codec, 0);
3230
3231 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x00);
3232}
3233
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003234static void tabla_codec_shutdown_hs_polling(struct snd_soc_codec *codec)
3235{
3236 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003237
3238 tabla_codec_shutdown_hs_removal_detect(codec);
3239
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003240 if (!tabla->mclk_enabled) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003241 snd_soc_update_bits(codec, TABLA_A_TX_COM_BIAS, 0xE0, 0x00);
3242 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_AUDIO_MODE);
3243 tabla_codec_enable_clock_block(codec, 0);
3244 }
3245
3246 tabla->mbhc_polling_active = false;
3247}
3248
Patrick Lai49efeac2011-11-03 11:01:12 -07003249static irqreturn_t tabla_hphl_ocp_irq(int irq, void *data)
3250{
3251 struct tabla_priv *tabla = data;
3252 struct snd_soc_codec *codec;
3253
3254 pr_info("%s: received HPHL OCP irq\n", __func__);
3255
3256 if (tabla) {
3257 codec = tabla->codec;
3258 tabla_disable_irq(codec->control_data,
3259 TABLA_IRQ_HPH_PA_OCPL_FAULT);
3260 tabla->hph_status |= SND_JACK_OC_HPHL;
3261 if (tabla->headset_jack) {
3262 snd_soc_jack_report(tabla->headset_jack,
3263 tabla->hph_status, TABLA_JACK_MASK);
3264 }
3265 } else {
3266 pr_err("%s: Bad tabla private data\n", __func__);
3267 }
3268
3269 return IRQ_HANDLED;
3270}
3271
3272static irqreturn_t tabla_hphr_ocp_irq(int irq, void *data)
3273{
3274 struct tabla_priv *tabla = data;
3275 struct snd_soc_codec *codec;
3276
3277 pr_info("%s: received HPHR OCP irq\n", __func__);
3278
3279 if (tabla) {
3280 codec = tabla->codec;
3281 tabla_disable_irq(codec->control_data,
3282 TABLA_IRQ_HPH_PA_OCPR_FAULT);
3283 tabla->hph_status |= SND_JACK_OC_HPHR;
3284 if (tabla->headset_jack) {
3285 snd_soc_jack_report(tabla->headset_jack,
3286 tabla->hph_status, TABLA_JACK_MASK);
3287 }
3288 } else {
3289 pr_err("%s: Bad tabla private data\n", __func__);
3290 }
3291
3292 return IRQ_HANDLED;
3293}
3294
Bradley Rubincb1e2732011-06-23 16:49:20 -07003295static irqreturn_t tabla_hs_insert_irq(int irq, void *data)
3296{
3297 struct tabla_priv *priv = data;
3298 struct snd_soc_codec *codec = priv->codec;
Bradley Rubin355611a2011-08-24 14:01:18 -07003299 int ldo_h_on, micb_cfilt_on;
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07003300 short mic_voltage;
3301 short threshold_no_mic = 0xF7F6;
3302 short threshold_fake_insert = 0xFD30;
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07003303 u8 is_removal;
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07003304
Bradley Rubincb1e2732011-06-23 16:49:20 -07003305
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003306 pr_debug("%s\n", __func__);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003307 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07003308 is_removal = snd_soc_read(codec, TABLA_A_CDC_MBHC_INT_CTL) & 0x02;
3309 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x03, 0x00);
3310
3311 /* Turn off both HPH and MIC line schmitt triggers */
3312 snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg,
3313 0x90, 0x00);
3314 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003315
Bhalchandra Gajare9494fa262011-11-10 19:25:59 -08003316 if (priv->fake_insert_context) {
3317 pr_debug("%s: fake context interrupt, reset insertion\n",
3318 __func__);
3319 priv->fake_insert_context = false;
3320 tabla_codec_shutdown_hs_polling(codec);
3321 tabla_codec_enable_hs_detect(codec, 1);
3322 return IRQ_HANDLED;
3323 }
3324
3325
Bradley Rubin355611a2011-08-24 14:01:18 -07003326 ldo_h_on = snd_soc_read(codec, TABLA_A_LDO_H_MODE_1) & 0x80;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003327 micb_cfilt_on = snd_soc_read(codec,
3328 priv->mbhc_bias_regs.cfilt_ctl) & 0x80;
Bradley Rubin355611a2011-08-24 14:01:18 -07003329
3330 if (!ldo_h_on)
3331 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x80, 0x80);
3332 if (!micb_cfilt_on)
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003333 snd_soc_update_bits(codec, priv->mbhc_bias_regs.cfilt_ctl,
3334 0x80, 0x80);
Bradley Rubin355611a2011-08-24 14:01:18 -07003335
Bradley Rubincb1e2732011-06-23 16:49:20 -07003336 usleep_range(priv->calibration->setup_plug_removal_delay,
3337 priv->calibration->setup_plug_removal_delay);
3338
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07003339 if (!ldo_h_on)
3340 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x80, 0x0);
3341 if (!micb_cfilt_on)
3342 snd_soc_update_bits(codec, priv->mbhc_bias_regs.cfilt_ctl,
3343 0x80, 0x0);
3344
3345 if (is_removal) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003346 /*
3347 * If headphone is removed while playback is in progress,
3348 * it is possible that micbias will be switched to VDDIO.
3349 */
3350 if (priv->mbhc_micbias_switched)
3351 tabla_codec_switch_micbias(codec, 0);
Patrick Lai49efeac2011-11-03 11:01:12 -07003352 priv->hph_status &= ~SND_JACK_HEADSET;
Bradley Rubincb1e2732011-06-23 16:49:20 -07003353 if (priv->headset_jack) {
3354 pr_debug("%s: Reporting removal\n", __func__);
Patrick Lai49efeac2011-11-03 11:01:12 -07003355 snd_soc_jack_report(priv->headset_jack,
3356 priv->hph_status, TABLA_JACK_MASK);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003357 }
3358 tabla_codec_shutdown_hs_removal_detect(codec);
3359 tabla_codec_enable_hs_detect(codec, 1);
3360 return IRQ_HANDLED;
3361 }
3362
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07003363 mic_voltage = tabla_codec_setup_hs_polling(codec);
Bradley Rubin355611a2011-08-24 14:01:18 -07003364
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07003365 if (mic_voltage > threshold_fake_insert) {
3366 pr_debug("%s: Fake insertion interrupt, mic_voltage = %x\n",
3367 __func__, mic_voltage);
Bhalchandra Gajare9494fa262011-11-10 19:25:59 -08003368
3369 /* Disable HPH trigger and enable MIC line trigger */
3370 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x12, 0x00);
3371
3372 snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, 0x60,
3373 priv->calibration->mic_current << 5);
3374 snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg,
3375 0x80, 0x80);
3376 usleep_range(priv->calibration->mic_pid,
3377 priv->calibration->mic_pid);
3378 snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg,
3379 0x10, 0x10);
3380
3381 /* Setup for insertion detection */
3382 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0);
3383 priv->fake_insert_context = true;
3384 tabla_enable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
3385 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0x1);
3386
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07003387 } else if (mic_voltage < threshold_no_mic) {
3388 pr_debug("%s: Headphone Detected, mic_voltage = %x\n",
3389 __func__, mic_voltage);
Patrick Lai49efeac2011-11-03 11:01:12 -07003390 priv->hph_status |= SND_JACK_HEADPHONE;
Bradley Rubincb1e2732011-06-23 16:49:20 -07003391 if (priv->headset_jack) {
3392 pr_debug("%s: Reporting insertion %d\n", __func__,
3393 SND_JACK_HEADPHONE);
3394 snd_soc_jack_report(priv->headset_jack,
Patrick Lai49efeac2011-11-03 11:01:12 -07003395 priv->hph_status, TABLA_JACK_MASK);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003396 }
3397 tabla_codec_shutdown_hs_polling(codec);
3398 tabla_codec_enable_hs_detect(codec, 0);
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07003399
3400 } else {
3401 pr_debug("%s: Headset detected, mic_voltage = %x\n",
3402 __func__, mic_voltage);
Patrick Lai49efeac2011-11-03 11:01:12 -07003403 priv->hph_status |= SND_JACK_HEADSET;
Bradley Rubincb1e2732011-06-23 16:49:20 -07003404 if (priv->headset_jack) {
3405 pr_debug("%s: Reporting insertion %d\n", __func__,
3406 SND_JACK_HEADSET);
3407 snd_soc_jack_report(priv->headset_jack,
Patrick Lai49efeac2011-11-03 11:01:12 -07003408 priv->hph_status, TABLA_JACK_MASK);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003409 }
3410 tabla_codec_start_hs_polling(codec);
3411 }
3412
3413 return IRQ_HANDLED;
3414}
3415
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003416static irqreturn_t tabla_hs_remove_irq(int irq, void *data)
3417{
3418 struct tabla_priv *priv = data;
3419 struct snd_soc_codec *codec = priv->codec;
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07003420 short bias_value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003421
3422 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL);
3423 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003424 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003425
3426 usleep_range(priv->calibration->shutdown_plug_removal,
3427 priv->calibration->shutdown_plug_removal);
3428
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07003429 bias_value = tabla_codec_measure_micbias_voltage(codec, 1);
3430 pr_debug("removal interrupt, bias value is %d\n", bias_value);
3431
3432 if (bias_value < -90) {
3433 pr_debug("False alarm, headset not actually removed\n");
3434 tabla_codec_start_hs_polling(codec);
3435 } else {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003436 /*
3437 * If this removal is not false, first check the micbias
3438 * switch status and switch it to LDOH if it is already
3439 * switched to VDDIO.
3440 */
3441 if (priv->mbhc_micbias_switched)
3442 tabla_codec_switch_micbias(codec, 0);
Patrick Lai49efeac2011-11-03 11:01:12 -07003443 priv->hph_status &= ~SND_JACK_HEADSET;
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07003444 if (priv->headset_jack) {
3445 pr_debug("%s: Reporting removal\n", __func__);
3446 snd_soc_jack_report(priv->headset_jack, 0,
Patrick Lai49efeac2011-11-03 11:01:12 -07003447 TABLA_JACK_MASK);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07003448 }
3449 tabla_codec_shutdown_hs_polling(codec);
3450
3451 tabla_codec_enable_hs_detect(codec, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003452 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003453 return IRQ_HANDLED;
3454}
3455
3456static unsigned long slimbus_value;
3457
3458static irqreturn_t tabla_slimbus_irq(int irq, void *data)
3459{
3460 struct tabla_priv *priv = data;
3461 struct snd_soc_codec *codec = priv->codec;
3462 int i, j;
3463 u8 val;
3464
3465 for (i = 0; i < TABLA_SLIM_NUM_PORT_REG; i++) {
3466 slimbus_value = tabla_interface_reg_read(codec->control_data,
3467 TABLA_SLIM_PGD_PORT_INT_STATUS0 + i);
3468 for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) {
3469 val = tabla_interface_reg_read(codec->control_data,
3470 TABLA_SLIM_PGD_PORT_INT_SOURCE0 + i*8 + j);
3471 if (val & 0x1)
3472 pr_err_ratelimited("overflow error on port %x,"
3473 " value %x\n", i*8 + j, val);
3474 if (val & 0x2)
3475 pr_err_ratelimited("underflow error on port %x,"
3476 " value %x\n", i*8 + j, val);
3477 }
3478 tabla_interface_reg_write(codec->control_data,
3479 TABLA_SLIM_PGD_PORT_INT_CLR0 + i, 0xFF);
3480 }
3481
3482 return IRQ_HANDLED;
3483}
3484
Patrick Lai3043fba2011-08-01 14:15:57 -07003485
3486static int tabla_handle_pdata(struct tabla_priv *tabla)
3487{
3488 struct snd_soc_codec *codec = tabla->codec;
3489 struct tabla_pdata *pdata = tabla->pdata;
3490 int k1, k2, k3, rc = 0;
Santosh Mardi22920282011-10-26 02:38:40 +05303491 u8 leg_mode = pdata->amic_settings.legacy_mode;
3492 u8 txfe_bypass = pdata->amic_settings.txfe_enable;
3493 u8 txfe_buff = pdata->amic_settings.txfe_buff;
3494 u8 flag = pdata->amic_settings.use_pdata;
3495 u8 i = 0, j = 0;
3496 u8 val_txfe = 0, value = 0;
Patrick Lai3043fba2011-08-01 14:15:57 -07003497
3498 if (!pdata) {
3499 rc = -ENODEV;
3500 goto done;
3501 }
3502
3503 /* Make sure settings are correct */
3504 if ((pdata->micbias.ldoh_v > TABLA_LDOH_2P85_V) ||
3505 (pdata->micbias.bias1_cfilt_sel > TABLA_CFILT3_SEL) ||
3506 (pdata->micbias.bias2_cfilt_sel > TABLA_CFILT3_SEL) ||
3507 (pdata->micbias.bias3_cfilt_sel > TABLA_CFILT3_SEL) ||
3508 (pdata->micbias.bias4_cfilt_sel > TABLA_CFILT3_SEL)) {
3509 rc = -EINVAL;
3510 goto done;
3511 }
3512
3513 /* figure out k value */
3514 k1 = tabla_find_k_value(pdata->micbias.ldoh_v,
3515 pdata->micbias.cfilt1_mv);
3516 k2 = tabla_find_k_value(pdata->micbias.ldoh_v,
3517 pdata->micbias.cfilt2_mv);
3518 k3 = tabla_find_k_value(pdata->micbias.ldoh_v,
3519 pdata->micbias.cfilt3_mv);
3520
3521 if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) {
3522 rc = -EINVAL;
3523 goto done;
3524 }
3525
3526 /* Set voltage level and always use LDO */
3527 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x0C,
3528 (pdata->micbias.ldoh_v << 2));
3529
3530 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_1_VAL, 0xFC,
3531 (k1 << 2));
3532 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_2_VAL, 0xFC,
3533 (k2 << 2));
3534 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_3_VAL, 0xFC,
3535 (k3 << 2));
3536
3537 snd_soc_update_bits(codec, TABLA_A_MICB_1_CTL, 0x60,
3538 (pdata->micbias.bias1_cfilt_sel << 5));
3539 snd_soc_update_bits(codec, TABLA_A_MICB_2_CTL, 0x60,
3540 (pdata->micbias.bias2_cfilt_sel << 5));
3541 snd_soc_update_bits(codec, TABLA_A_MICB_3_CTL, 0x60,
3542 (pdata->micbias.bias3_cfilt_sel << 5));
3543 snd_soc_update_bits(codec, TABLA_A_MICB_4_CTL, 0x60,
3544 (pdata->micbias.bias4_cfilt_sel << 5));
3545
Santosh Mardi22920282011-10-26 02:38:40 +05303546 for (i = 0; i < 6; j++, i += 2) {
3547 if (flag & (0x01 << i)) {
3548 value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00;
3549 val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00;
3550 val_txfe = val_txfe |
3551 ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00);
3552 snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10,
3553 0x10, value);
3554 snd_soc_update_bits(codec,
3555 TABLA_A_TX_1_2_TEST_EN + j * 10,
3556 0x30, val_txfe);
3557 }
3558 if (flag & (0x01 << (i + 1))) {
3559 value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00;
3560 val_txfe = (txfe_bypass &
3561 (0x01 << (i + 1))) ? 0x02 : 0x00;
3562 val_txfe |= (txfe_buff &
3563 (0x01 << (i + 1))) ? 0x01 : 0x00;
3564 snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10,
3565 0x01, value);
3566 snd_soc_update_bits(codec,
3567 TABLA_A_TX_1_2_TEST_EN + j * 10,
3568 0x03, val_txfe);
3569 }
3570 }
3571 if (flag & 0x40) {
3572 value = (leg_mode & 0x40) ? 0x10 : 0x00;
3573 value = value | ((txfe_bypass & 0x40) ? 0x02 : 0x00);
3574 value = value | ((txfe_buff & 0x40) ? 0x01 : 0x00);
3575 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN,
3576 0x13, value);
3577 }
Patrick Lai49efeac2011-11-03 11:01:12 -07003578
3579 if (pdata->ocp.use_pdata) {
3580 /* not defined in CODEC specification */
3581 if (pdata->ocp.hph_ocp_limit == 1 ||
3582 pdata->ocp.hph_ocp_limit == 5) {
3583 rc = -EINVAL;
3584 goto done;
3585 }
3586 snd_soc_update_bits(codec, TABLA_A_RX_COM_OCP_CTL,
3587 0x0F, pdata->ocp.num_attempts);
3588 snd_soc_write(codec, TABLA_A_RX_COM_OCP_COUNT,
3589 ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time));
3590 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL,
3591 0xE0, (pdata->ocp.hph_ocp_limit << 5));
3592 }
Patrick Lai3043fba2011-08-01 14:15:57 -07003593done:
3594 return rc;
3595}
3596
Kiran Kandi1f6fd722011-08-11 10:36:11 -07003597static const struct tabla_reg_mask_val tabla_1_1_reg_defaults[] = {
3598
3599 /* Tabla 1.1 MICBIAS changes */
3600 TABLA_REG_VAL(TABLA_A_MICB_1_INT_RBIAS, 0x24),
3601 TABLA_REG_VAL(TABLA_A_MICB_2_INT_RBIAS, 0x24),
3602 TABLA_REG_VAL(TABLA_A_MICB_3_INT_RBIAS, 0x24),
3603 TABLA_REG_VAL(TABLA_A_MICB_4_INT_RBIAS, 0x24),
3604
3605 /* Tabla 1.1 HPH changes */
3606 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_PA, 0x57),
3607 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_LDO, 0x56),
3608
3609 /* Tabla 1.1 EAR PA changes */
3610 TABLA_REG_VAL(TABLA_A_RX_EAR_BIAS_PA, 0xA6),
3611 TABLA_REG_VAL(TABLA_A_RX_EAR_GAIN, 0x02),
3612 TABLA_REG_VAL(TABLA_A_RX_EAR_VCM, 0x03),
3613
3614 /* Tabla 1.1 Lineout_5 Changes */
3615 TABLA_REG_VAL(TABLA_A_RX_LINE_5_GAIN, 0x10),
3616
3617 /* Tabla 1.1 RX Changes */
3618 TABLA_REG_VAL(TABLA_A_CDC_RX1_B5_CTL, 0x78),
3619 TABLA_REG_VAL(TABLA_A_CDC_RX2_B5_CTL, 0x78),
3620 TABLA_REG_VAL(TABLA_A_CDC_RX3_B5_CTL, 0x78),
3621 TABLA_REG_VAL(TABLA_A_CDC_RX4_B5_CTL, 0x78),
3622 TABLA_REG_VAL(TABLA_A_CDC_RX5_B5_CTL, 0x78),
3623 TABLA_REG_VAL(TABLA_A_CDC_RX6_B5_CTL, 0x78),
3624 TABLA_REG_VAL(TABLA_A_CDC_RX7_B5_CTL, 0x78),
3625
3626 /* Tabla 1.1 RX1 and RX2 Changes */
3627 TABLA_REG_VAL(TABLA_A_CDC_RX1_B6_CTL, 0xA0),
3628 TABLA_REG_VAL(TABLA_A_CDC_RX2_B6_CTL, 0xA0),
3629
3630 /* Tabla 1.1 RX3 to RX7 Changes */
3631 TABLA_REG_VAL(TABLA_A_CDC_RX3_B6_CTL, 0x80),
3632 TABLA_REG_VAL(TABLA_A_CDC_RX4_B6_CTL, 0x80),
3633 TABLA_REG_VAL(TABLA_A_CDC_RX5_B6_CTL, 0x80),
3634 TABLA_REG_VAL(TABLA_A_CDC_RX6_B6_CTL, 0x80),
3635 TABLA_REG_VAL(TABLA_A_CDC_RX7_B6_CTL, 0x80),
3636
3637 /* Tabla 1.1 CLASSG Changes */
3638 TABLA_REG_VAL(TABLA_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B),
3639};
3640
3641static const struct tabla_reg_mask_val tabla_2_0_reg_defaults[] = {
3642
3643 /* Tabla 2.0 MICBIAS changes */
3644 TABLA_REG_VAL(TABLA_A_MICB_2_MBHC, 0x02),
3645};
3646
3647static void tabla_update_reg_defaults(struct snd_soc_codec *codec)
3648{
3649 u32 i;
3650
3651 for (i = 0; i < ARRAY_SIZE(tabla_1_1_reg_defaults); i++)
3652 snd_soc_write(codec, tabla_1_1_reg_defaults[i].reg,
3653 tabla_1_1_reg_defaults[i].val);
3654
3655 for (i = 0; i < ARRAY_SIZE(tabla_2_0_reg_defaults); i++)
3656 snd_soc_write(codec, tabla_2_0_reg_defaults[i].reg,
3657 tabla_2_0_reg_defaults[i].val);
3658}
3659
3660static const struct tabla_reg_mask_val tabla_codec_reg_init_val[] = {
Patrick Lai49efeac2011-11-03 11:01:12 -07003661 /* Initialize current threshold to 350MA */
3662 {TABLA_A_RX_HPH_OCP_CTL, 0xE0, 0x60},
Kiran Kandi1f6fd722011-08-11 10:36:11 -07003663
Santosh Mardi32171012011-10-28 23:32:06 +05303664 {TABLA_A_QFUSE_CTL, 0xFF, 0x03},
3665
Kiran Kandi1f6fd722011-08-11 10:36:11 -07003666 /* Initialize gain registers to use register gain */
3667 {TABLA_A_RX_HPH_L_GAIN, 0x10, 0x10},
3668 {TABLA_A_RX_HPH_R_GAIN, 0x10, 0x10},
3669 {TABLA_A_RX_LINE_1_GAIN, 0x10, 0x10},
3670 {TABLA_A_RX_LINE_2_GAIN, 0x10, 0x10},
3671 {TABLA_A_RX_LINE_3_GAIN, 0x10, 0x10},
3672 {TABLA_A_RX_LINE_4_GAIN, 0x10, 0x10},
3673
3674 /* Initialize mic biases to differential mode */
3675 {TABLA_A_MICB_1_INT_RBIAS, 0x24, 0x24},
3676 {TABLA_A_MICB_2_INT_RBIAS, 0x24, 0x24},
3677 {TABLA_A_MICB_3_INT_RBIAS, 0x24, 0x24},
3678 {TABLA_A_MICB_4_INT_RBIAS, 0x24, 0x24},
3679
3680 {TABLA_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14},
3681
3682 /* Use 16 bit sample size for TX1 to TX6 */
3683 {TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20},
3684 {TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20},
3685 {TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20},
3686 {TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20},
3687 {TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20},
3688 {TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0x30, 0x20},
3689
3690 /* Use 16 bit sample size for TX7 to TX10 */
3691 {TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0x60, 0x40},
3692 {TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0x60, 0x40},
3693 {TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0x60, 0x40},
3694 {TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0x60, 0x40},
3695
3696 /* Use 16 bit sample size for RX */
3697 {TABLA_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA},
3698 {TABLA_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0xAA},
3699
3700 /*enable HPF filter for TX paths */
3701 {TABLA_A_CDC_TX1_MUX_CTL, 0x8, 0x0},
3702 {TABLA_A_CDC_TX2_MUX_CTL, 0x8, 0x0},
3703 {TABLA_A_CDC_TX3_MUX_CTL, 0x8, 0x0},
3704 {TABLA_A_CDC_TX4_MUX_CTL, 0x8, 0x0},
3705 {TABLA_A_CDC_TX5_MUX_CTL, 0x8, 0x0},
3706 {TABLA_A_CDC_TX6_MUX_CTL, 0x8, 0x0},
3707 {TABLA_A_CDC_TX7_MUX_CTL, 0x8, 0x0},
3708 {TABLA_A_CDC_TX8_MUX_CTL, 0x8, 0x0},
3709 {TABLA_A_CDC_TX9_MUX_CTL, 0x8, 0x0},
3710 {TABLA_A_CDC_TX10_MUX_CTL, 0x8, 0x0},
3711};
3712
3713static void tabla_codec_init_reg(struct snd_soc_codec *codec)
3714{
3715 u32 i;
3716
3717 for (i = 0; i < ARRAY_SIZE(tabla_codec_reg_init_val); i++)
3718 snd_soc_update_bits(codec, tabla_codec_reg_init_val[i].reg,
3719 tabla_codec_reg_init_val[i].mask,
3720 tabla_codec_reg_init_val[i].val);
3721}
3722
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003723static int tabla_codec_probe(struct snd_soc_codec *codec)
3724{
3725 struct tabla *control;
3726 struct tabla_priv *tabla;
3727 struct snd_soc_dapm_context *dapm = &codec->dapm;
3728 int ret = 0;
3729 int i;
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003730 u8 tabla_version;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003731
3732 codec->control_data = dev_get_drvdata(codec->dev->parent);
3733 control = codec->control_data;
3734
3735 tabla = kzalloc(sizeof(struct tabla_priv), GFP_KERNEL);
3736 if (!tabla) {
3737 dev_err(codec->dev, "Failed to allocate private data\n");
3738 return -ENOMEM;
3739 }
3740
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003741 /* Make sure mbhc micbias register addresses are zeroed out */
3742 memset(&tabla->mbhc_bias_regs, 0,
3743 sizeof(struct mbhc_micbias_regs));
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003744 tabla->cfilt_k_value = 0;
3745 tabla->mbhc_micbias_switched = false;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003746
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003747 snd_soc_codec_set_drvdata(codec, tabla);
3748
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003749 tabla->mclk_enabled = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003750 tabla->bandgap_type = TABLA_BANDGAP_OFF;
3751 tabla->clock_active = false;
3752 tabla->config_mode_active = false;
3753 tabla->mbhc_polling_active = false;
Bhalchandra Gajare9494fa262011-11-10 19:25:59 -08003754 tabla->fake_insert_context = false;
Bradley Rubincb3950a2011-08-18 13:07:26 -07003755 tabla->no_mic_headset_override = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003756 tabla->codec = codec;
Patrick Lai3043fba2011-08-01 14:15:57 -07003757 tabla->pdata = dev_get_platdata(codec->dev->parent);
Santosh Mardie15e2302011-11-15 10:39:23 +05303758 tabla->intf_type = tabla_get_intf_type();
Patrick Lai3043fba2011-08-01 14:15:57 -07003759
Santosh Mardi22920282011-10-26 02:38:40 +05303760 tabla_update_reg_defaults(codec);
3761 tabla_codec_init_reg(codec);
Patrick Lai3043fba2011-08-01 14:15:57 -07003762
Santosh Mardi22920282011-10-26 02:38:40 +05303763 ret = tabla_handle_pdata(tabla);
Patrick Lai3043fba2011-08-01 14:15:57 -07003764 if (IS_ERR_VALUE(ret)) {
3765 pr_err("%s: bad pdata\n", __func__);
3766 goto err_pdata;
3767 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003768
3769 /* TODO only enable bandgap when necessary in order to save power */
3770 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_AUDIO_MODE);
3771 tabla_codec_enable_clock_block(codec, 0);
3772
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003773 snd_soc_add_controls(codec, tabla_snd_controls,
3774 ARRAY_SIZE(tabla_snd_controls));
3775 snd_soc_dapm_new_controls(dapm, tabla_dapm_widgets,
3776 ARRAY_SIZE(tabla_dapm_widgets));
Santosh Mardie15e2302011-11-15 10:39:23 +05303777 if (tabla->intf_type == TABLA_INTERFACE_TYPE_I2C) {
3778 snd_soc_dapm_new_controls(dapm, tabla_dapm_i2s_widgets,
3779 ARRAY_SIZE(tabla_dapm_i2s_widgets));
3780 snd_soc_dapm_add_routes(dapm, audio_i2s_map,
3781 ARRAY_SIZE(audio_i2s_map));
3782 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003783 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003784
3785 tabla_version = snd_soc_read(codec, TABLA_A_CHIP_VERSION);
3786 pr_info("%s : Tabla version reg 0x%2x\n", __func__, (u32)tabla_version);
3787
3788 tabla_version &= 0x1F;
3789 pr_info("%s : Tabla version %u\n", __func__, (u32)tabla_version);
3790
Kiran Kandi7a9fd902011-11-14 13:51:45 -08003791 if ((tabla_version == TABLA_VERSION_1_0) ||
3792 (tabla_version == TABLA_VERSION_1_1)) {
3793 snd_soc_dapm_add_routes(dapm, tabla_1_x_lineout_2_to_4_map,
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003794 ARRAY_SIZE(tabla_1_x_lineout_2_to_4_map));
3795
Kiran Kandi7a9fd902011-11-14 13:51:45 -08003796 } else if (tabla_version == TABLA_VERSION_2_0) {
3797 snd_soc_dapm_add_routes(dapm, tabla_2_x_lineout_2_to_4_map,
3798 ARRAY_SIZE(tabla_2_x_lineout_2_to_4_map));
3799 } else {
3800 pr_err("%s : ERROR. Unsupported Tabla version 0x%2x\n",
3801 __func__, (u32)tabla_version);
3802 goto err_pdata;
3803 }
3804
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003805 snd_soc_dapm_sync(dapm);
3806
3807 ret = tabla_request_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION,
3808 tabla_hs_insert_irq, "Headset insert detect", tabla);
3809 if (ret) {
3810 pr_err("%s: Failed to request irq %d\n", __func__,
3811 TABLA_IRQ_MBHC_INSERTION);
3812 goto err_insert_irq;
3813 }
3814 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
3815
3816 ret = tabla_request_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL,
3817 tabla_hs_remove_irq, "Headset remove detect", tabla);
3818 if (ret) {
3819 pr_err("%s: Failed to request irq %d\n", __func__,
3820 TABLA_IRQ_MBHC_REMOVAL);
3821 goto err_remove_irq;
3822 }
3823 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL);
3824
3825 ret = tabla_request_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07003826 tabla_dce_handler, "DC Estimation detect", tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003827 if (ret) {
3828 pr_err("%s: Failed to request irq %d\n", __func__,
3829 TABLA_IRQ_MBHC_POTENTIAL);
3830 goto err_potential_irq;
3831 }
3832 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
3833
Bradley Rubincb1e2732011-06-23 16:49:20 -07003834 ret = tabla_request_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE,
3835 tabla_release_handler, "Button Release detect", tabla);
3836 if (ret) {
3837 pr_err("%s: Failed to request irq %d\n", __func__,
3838 TABLA_IRQ_MBHC_RELEASE);
3839 goto err_release_irq;
3840 }
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003841 tabla_disable_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003842
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003843 ret = tabla_request_irq(codec->control_data, TABLA_IRQ_SLIMBUS,
3844 tabla_slimbus_irq, "SLIMBUS Slave", tabla);
3845 if (ret) {
3846 pr_err("%s: Failed to request irq %d\n", __func__,
3847 TABLA_IRQ_SLIMBUS);
3848 goto err_slimbus_irq;
3849 }
3850
3851 for (i = 0; i < TABLA_SLIM_NUM_PORT_REG; i++)
3852 tabla_interface_reg_write(codec->control_data,
3853 TABLA_SLIM_PGD_PORT_INT_EN0 + i, 0xFF);
3854
Patrick Lai49efeac2011-11-03 11:01:12 -07003855 ret = tabla_request_irq(codec->control_data,
3856 TABLA_IRQ_HPH_PA_OCPL_FAULT, tabla_hphl_ocp_irq,
3857 "HPH_L OCP detect", tabla);
3858 if (ret) {
3859 pr_err("%s: Failed to request irq %d\n", __func__,
3860 TABLA_IRQ_HPH_PA_OCPL_FAULT);
3861 goto err_hphl_ocp_irq;
3862 }
3863
3864 ret = tabla_request_irq(codec->control_data,
3865 TABLA_IRQ_HPH_PA_OCPR_FAULT, tabla_hphr_ocp_irq,
3866 "HPH_R OCP detect", tabla);
3867 if (ret) {
3868 pr_err("%s: Failed to request irq %d\n", __func__,
3869 TABLA_IRQ_HPH_PA_OCPR_FAULT);
3870 goto err_hphr_ocp_irq;
3871 }
3872
Bradley Rubincb3950a2011-08-18 13:07:26 -07003873#ifdef CONFIG_DEBUG_FS
3874 debug_tabla_priv = tabla;
3875#endif
3876
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003877 return ret;
3878
Patrick Lai49efeac2011-11-03 11:01:12 -07003879err_hphr_ocp_irq:
3880 tabla_free_irq(codec->control_data, TABLA_IRQ_HPH_PA_OCPL_FAULT, tabla);
3881err_hphl_ocp_irq:
3882 tabla_free_irq(codec->control_data, TABLA_IRQ_SLIMBUS, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003883err_slimbus_irq:
Bradley Rubincb1e2732011-06-23 16:49:20 -07003884 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, tabla);
3885err_release_irq:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003886 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, tabla);
3887err_potential_irq:
3888 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, tabla);
3889err_remove_irq:
3890 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, tabla);
3891err_insert_irq:
Patrick Lai3043fba2011-08-01 14:15:57 -07003892err_pdata:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003893 kfree(tabla);
3894 return ret;
3895}
3896static int tabla_codec_remove(struct snd_soc_codec *codec)
3897{
3898 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3899 tabla_free_irq(codec->control_data, TABLA_IRQ_SLIMBUS, tabla);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003900 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003901 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, tabla);
3902 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, tabla);
3903 tabla_free_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, tabla);
3904 tabla_codec_disable_clock_block(codec);
3905 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF);
3906 kfree(tabla);
3907 return 0;
3908}
3909static struct snd_soc_codec_driver soc_codec_dev_tabla = {
3910 .probe = tabla_codec_probe,
3911 .remove = tabla_codec_remove,
3912 .read = tabla_read,
3913 .write = tabla_write,
3914
3915 .readable_register = tabla_readable,
3916 .volatile_register = tabla_volatile,
3917
3918 .reg_cache_size = TABLA_CACHE_SIZE,
3919 .reg_cache_default = tabla_reg_defaults,
3920 .reg_word_size = 1,
3921};
Bradley Rubincb3950a2011-08-18 13:07:26 -07003922
3923#ifdef CONFIG_DEBUG_FS
3924static struct dentry *debugfs_poke;
3925
3926static int codec_debug_open(struct inode *inode, struct file *file)
3927{
3928 file->private_data = inode->i_private;
3929 return 0;
3930}
3931
3932static ssize_t codec_debug_write(struct file *filp,
3933 const char __user *ubuf, size_t cnt, loff_t *ppos)
3934{
3935 char lbuf[32];
3936 char *buf;
3937 int rc;
3938
3939 if (cnt > sizeof(lbuf) - 1)
3940 return -EINVAL;
3941
3942 rc = copy_from_user(lbuf, ubuf, cnt);
3943 if (rc)
3944 return -EFAULT;
3945
3946 lbuf[cnt] = '\0';
3947 buf = (char *)lbuf;
3948 debug_tabla_priv->no_mic_headset_override = (*strsep(&buf, " ") == '0')
3949 ? false : true;
3950
3951 return rc;
3952}
3953
3954static const struct file_operations codec_debug_ops = {
3955 .open = codec_debug_open,
3956 .write = codec_debug_write,
3957};
3958#endif
3959
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003960static int __devinit tabla_probe(struct platform_device *pdev)
3961{
Santosh Mardie15e2302011-11-15 10:39:23 +05303962 int ret = 0;
Bradley Rubincb3950a2011-08-18 13:07:26 -07003963#ifdef CONFIG_DEBUG_FS
3964 debugfs_poke = debugfs_create_file("TRRS",
3965 S_IFREG | S_IRUGO, NULL, (void *) "TRRS", &codec_debug_ops);
3966
3967#endif
Santosh Mardie15e2302011-11-15 10:39:23 +05303968 if (tabla_get_intf_type() == TABLA_INTERFACE_TYPE_SLIMBUS)
3969 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla,
3970 tabla_dai, ARRAY_SIZE(tabla_dai));
3971 else if (tabla_get_intf_type() == TABLA_INTERFACE_TYPE_I2C)
3972 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla,
3973 tabla_i2s_dai, ARRAY_SIZE(tabla_i2s_dai));
3974 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003975}
3976static int __devexit tabla_remove(struct platform_device *pdev)
3977{
3978 snd_soc_unregister_codec(&pdev->dev);
Bradley Rubincb3950a2011-08-18 13:07:26 -07003979
3980#ifdef CONFIG_DEBUG_FS
3981 debugfs_remove(debugfs_poke);
3982#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003983 return 0;
3984}
3985static struct platform_driver tabla_codec_driver = {
3986 .probe = tabla_probe,
3987 .remove = tabla_remove,
3988 .driver = {
3989 .name = "tabla_codec",
3990 .owner = THIS_MODULE,
3991 },
3992};
3993
3994static int __init tabla_codec_init(void)
3995{
3996 return platform_driver_register(&tabla_codec_driver);
3997}
3998
3999static void __exit tabla_codec_exit(void)
4000{
4001 platform_driver_unregister(&tabla_codec_driver);
4002}
4003
4004module_init(tabla_codec_init);
4005module_exit(tabla_codec_exit);
4006
4007MODULE_DESCRIPTION("Tabla codec driver");
4008MODULE_VERSION("1.0");
4009MODULE_LICENSE("GPL v2");