blob: a2b879742d10d602cf29bb0178509c402f72517f [file] [log] [blame]
Kiran Kandi3426e512011-09-13 22:50:10 -07001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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>
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +053021#include <linux/mfd/wcd9xxx/core.h>
22#include <linux/mfd/wcd9xxx/wcd9xxx_registers.h>
23#include <linux/mfd/wcd9xxx/wcd9310_registers.h>
24#include <linux/mfd/wcd9xxx/pdata.h>
Santosh Mardie15e2302011-11-15 10:39:23 +053025#include <sound/pcm.h>
26#include <sound/pcm_params.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070027#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>
Kuirong Wanga545e722012-02-06 19:12:54 -080032#include <linux/pm_runtime.h>
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -070033#include <linux/kernel.h>
34#include <linux/gpio.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035#include "wcd9310.h"
36
Kiran Kandi1e6371d2012-03-29 11:48:57 -070037#define WCD9310_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
38 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
39 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
40
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -070041
42#define NUM_DECIMATORS 10
43#define NUM_INTERPOLATORS 7
44#define BITS_PER_REG 8
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -080045#define TABLA_CFILT_FAST_MODE 0x00
46#define TABLA_CFILT_SLOW_MODE 0x40
Patrick Lai64b43262011-12-06 17:29:15 -080047#define MBHC_FW_READ_ATTEMPTS 15
48#define MBHC_FW_READ_TIMEOUT 2000000
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -070049
Joonwoo Park03324832012-03-19 19:36:16 -070050enum {
51 MBHC_USE_HPHL_TRIGGER = 1,
52 MBHC_USE_MB_TRIGGER = 2
53};
54
55#define MBHC_NUM_DCE_PLUG_DETECT 3
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -070056#define NUM_ATTEMPTS_INSERT_DETECT 25
57#define NUM_ATTEMPTS_TO_REPORT 5
Joonwoo Park03324832012-03-19 19:36:16 -070058
Patrick Lai49efeac2011-11-03 11:01:12 -070059#define TABLA_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | SND_JACK_OC_HPHR)
60
Santosh Mardie15e2302011-11-15 10:39:23 +053061#define TABLA_I2S_MASTER_MODE_MASK 0x08
62
Patrick Laic7cae882011-11-18 11:52:49 -080063#define TABLA_OCP_ATTEMPT 1
64
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -080065#define AIF1_PB 1
66#define AIF1_CAP 2
Neema Shettyd3a89262012-02-16 10:23:50 -080067#define AIF2_PB 3
Kiran Kandi1e6371d2012-03-29 11:48:57 -070068#define AIF2_CAP 4
69
70#define NUM_CODEC_DAIS 4
Kuirong Wang0f8ade32012-02-27 16:29:45 -080071#define TABLA_COMP_DIGITAL_GAIN_OFFSET 3
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -080072
73struct tabla_codec_dai_data {
74 u32 rate;
75 u32 *ch_num;
76 u32 ch_act;
77 u32 ch_tot;
78};
79
Joonwoo Park0976d012011-12-22 11:48:18 -080080#define TABLA_MCLK_RATE_12288KHZ 12288000
81#define TABLA_MCLK_RATE_9600KHZ 9600000
82
Joonwoo Parkf4267c22012-01-10 13:25:24 -080083#define TABLA_FAKE_INS_THRESHOLD_MS 2500
Joonwoo Park6b9b03f2012-01-23 18:48:54 -080084#define TABLA_FAKE_REMOVAL_MIN_PERIOD_MS 50
Joonwoo Parkf4267c22012-01-10 13:25:24 -080085
Joonwoo Park03324832012-03-19 19:36:16 -070086#define TABLA_MBHC_BUTTON_MIN 0x8000
87
Joonwoo Park03324832012-03-19 19:36:16 -070088#define TABLA_MBHC_FAKE_INSERT_LOW 10
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -070089#define TABLA_MBHC_FAKE_INSERT_HIGH 80
90#define TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO 150
Joonwoo Park03324832012-03-19 19:36:16 -070091
92#define TABLA_MBHC_STATUS_REL_DETECTION 0x0C
93
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -070094#define TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS 200
95
Joonwoo Parkcf473b42012-03-29 19:48:16 -070096#define TABLA_MBHC_FAKE_INS_DELTA_MV 200
97#define TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV 300
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -070098
99#define TABLA_HS_DETECT_PLUG_TIME_MS (5 * 1000)
100#define TABLA_HS_DETECT_PLUG_INERVAL_MS 100
101
102#define TABLA_GPIO_IRQ_DEBOUNCE_TIME_US 5000
103
104#define TABLA_ACQUIRE_LOCK(x) do { mutex_lock(&x); } while (0)
105#define TABLA_RELEASE_LOCK(x) do { mutex_unlock(&x); } while (0)
106
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700107static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
108static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
109static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800110static struct snd_soc_dai_driver tabla_dai[];
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -0800111static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700112
113enum tabla_bandgap_type {
114 TABLA_BANDGAP_OFF = 0,
115 TABLA_BANDGAP_AUDIO_MODE,
116 TABLA_BANDGAP_MBHC_MODE,
117};
118
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700119struct mbhc_micbias_regs {
120 u16 cfilt_val;
121 u16 cfilt_ctl;
122 u16 mbhc_reg;
123 u16 int_rbias;
124 u16 ctl_reg;
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -0800125 u8 cfilt_sel;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700126};
127
Ben Romberger1f045a72011-11-04 10:14:57 -0700128/* Codec supports 2 IIR filters */
129enum {
130 IIR1 = 0,
131 IIR2,
132 IIR_MAX,
133};
134/* Codec supports 5 bands */
135enum {
136 BAND1 = 0,
137 BAND2,
138 BAND3,
139 BAND4,
140 BAND5,
141 BAND_MAX,
142};
143
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800144enum {
145 COMPANDER_1 = 0,
146 COMPANDER_2,
147 COMPANDER_MAX,
148};
149
150enum {
151 COMPANDER_FS_8KHZ = 0,
152 COMPANDER_FS_16KHZ,
153 COMPANDER_FS_32KHZ,
154 COMPANDER_FS_48KHZ,
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700155 COMPANDER_FS_96KHZ,
156 COMPANDER_FS_192KHZ,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800157 COMPANDER_FS_MAX,
158};
159
Joonwoo Parka9444452011-12-08 18:48:27 -0800160/* Flags to track of PA and DAC state.
161 * PA and DAC should be tracked separately as AUXPGA loopback requires
162 * only PA to be turned on without DAC being on. */
163enum tabla_priv_ack_flags {
164 TABLA_HPHL_PA_OFF_ACK = 0,
165 TABLA_HPHR_PA_OFF_ACK,
166 TABLA_HPHL_DAC_OFF_ACK,
167 TABLA_HPHR_DAC_OFF_ACK
168};
169
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800170
171struct comp_sample_dependent_params {
172 u32 peak_det_timeout;
173 u32 rms_meter_div_fact;
174 u32 rms_meter_resamp_fact;
175};
176
Joonwoo Park0976d012011-12-22 11:48:18 -0800177/* Data used by MBHC */
178struct mbhc_internal_cal_data {
179 u16 dce_z;
180 u16 dce_mb;
181 u16 sta_z;
182 u16 sta_mb;
Joonwoo Park433149a2012-01-11 09:53:54 -0800183 u32 t_sta_dce;
Joonwoo Park0976d012011-12-22 11:48:18 -0800184 u32 t_dce;
185 u32 t_sta;
186 u32 micb_mv;
187 u16 v_ins_hu;
188 u16 v_ins_h;
189 u16 v_b1_hu;
190 u16 v_b1_h;
191 u16 v_b1_huc;
192 u16 v_brh;
193 u16 v_brl;
194 u16 v_no_mic;
Joonwoo Park0976d012011-12-22 11:48:18 -0800195 u8 npoll;
196 u8 nbounce_wait;
Joonwoo Parkcf473b42012-03-29 19:48:16 -0700197 s16 adj_v_hs_max;
198 u16 adj_v_ins_hu;
199 u16 adj_v_ins_h;
200 s16 v_inval_ins_low;
201 s16 v_inval_ins_high;
Joonwoo Park0976d012011-12-22 11:48:18 -0800202};
203
Joonwoo Park6c1ebb62012-01-16 19:08:43 -0800204struct tabla_reg_address {
205 u16 micb_4_ctl;
206 u16 micb_4_int_rbias;
207 u16 micb_4_mbhc;
208};
209
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700210enum tabla_mbhc_plug_type {
Joonwoo Park41956722012-04-18 13:13:07 -0700211 PLUG_TYPE_INVALID = -1,
212 PLUG_TYPE_NONE,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700213 PLUG_TYPE_HEADSET,
214 PLUG_TYPE_HEADPHONE,
215 PLUG_TYPE_HIGH_HPH,
216};
217
218enum tabla_mbhc_state {
219 MBHC_STATE_NONE = -1,
220 MBHC_STATE_POTENTIAL,
221 MBHC_STATE_POTENTIAL_RECOVERY,
222 MBHC_STATE_RELEASE,
223};
224
Kiran Kandid8cf5212012-03-02 15:34:53 -0800225struct hpf_work {
226 struct tabla_priv *tabla;
227 u32 decimator;
228 u8 tx_hpf_cut_of_freq;
229 struct delayed_work dwork;
230};
231
232static struct hpf_work tx_hpf_work[NUM_DECIMATORS];
233
Bradley Rubin229c6a52011-07-12 16:18:48 -0700234struct tabla_priv {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700235 struct snd_soc_codec *codec;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -0800236 struct tabla_reg_address reg_addr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700237 u32 adc_count;
Patrick Lai3043fba2011-08-01 14:15:57 -0700238 u32 cfilt1_cnt;
239 u32 cfilt2_cnt;
240 u32 cfilt3_cnt;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -0700241 u32 rx_bias_count;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700242 enum tabla_bandgap_type bandgap_type;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -0700243 bool mclk_enabled;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700244 bool clock_active;
245 bool config_mode_active;
246 bool mbhc_polling_active;
Joonwoo Parkf4267c22012-01-10 13:25:24 -0800247 unsigned long mbhc_fake_ins_start;
Bradley Rubincb1e2732011-06-23 16:49:20 -0700248 int buttons_pressed;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700249 enum tabla_mbhc_state mbhc_state;
250 struct tabla_mbhc_config mbhc_cfg;
Joonwoo Park0976d012011-12-22 11:48:18 -0800251 struct mbhc_internal_cal_data mbhc_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700252
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530253 struct wcd9xxx_pdata *pdata;
Bradley Rubina7096d02011-08-03 18:29:02 -0700254 u32 anc_slot;
Bradley Rubincb3950a2011-08-18 13:07:26 -0700255
256 bool no_mic_headset_override;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -0700257 /* Delayed work to report long button press */
Joonwoo Park03324832012-03-19 19:36:16 -0700258 struct delayed_work mbhc_btn_dwork;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700259
260 struct mbhc_micbias_regs mbhc_bias_regs;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -0700261 bool mbhc_micbias_switched;
Patrick Lai49efeac2011-11-03 11:01:12 -0700262
Joonwoo Parka9444452011-12-08 18:48:27 -0800263 /* track PA/DAC state */
264 unsigned long hph_pa_dac_state;
265
Santosh Mardie15e2302011-11-15 10:39:23 +0530266 /*track tabla interface type*/
267 u8 intf_type;
268
Patrick Lai49efeac2011-11-03 11:01:12 -0700269 u32 hph_status; /* track headhpone status */
270 /* define separate work for left and right headphone OCP to avoid
271 * additional checking on which OCP event to report so no locking
272 * to ensure synchronization is required
273 */
274 struct work_struct hphlocp_work; /* reporting left hph ocp off */
275 struct work_struct hphrocp_work; /* reporting right hph ocp off */
Joonwoo Park8b1f0982011-12-08 17:12:45 -0800276
Patrick Laic7cae882011-11-18 11:52:49 -0800277 u8 hphlocp_cnt; /* headphone left ocp retry */
278 u8 hphrocp_cnt; /* headphone right ocp retry */
Joonwoo Park0976d012011-12-22 11:48:18 -0800279
Patrick Lai64b43262011-12-06 17:29:15 -0800280 /* Work to perform MBHC Firmware Read */
281 struct delayed_work mbhc_firmware_dwork;
282 const struct firmware *mbhc_fw;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800283
284 /* num of slim ports required */
285 struct tabla_codec_dai_data dai[NUM_CODEC_DAIS];
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800286
287 /*compander*/
288 int comp_enabled[COMPANDER_MAX];
289 u32 comp_fs[COMPANDER_MAX];
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -0800290
291 /* Maintain the status of AUX PGA */
292 int aux_pga_cnt;
293 u8 aux_l_gain;
294 u8 aux_r_gain;
Joonwoo Park03324832012-03-19 19:36:16 -0700295
Joonwoo Park03324832012-03-19 19:36:16 -0700296 struct delayed_work mbhc_insert_dwork;
297 unsigned long mbhc_last_resume; /* in jiffies */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700298
299 u8 current_plug;
300 struct work_struct hs_correct_plug_work;
301 bool hs_detect_work_stop;
302 bool hs_polling_irq_prepared;
303 bool lpi_enabled; /* low power insertion detection */
304 bool in_gpio_handler;
305 /* Currently, only used for mbhc purpose, to protect
306 * concurrent execution of mbhc threaded irq handlers and
307 * kill race between DAPM and MBHC.But can serve as a
308 * general lock to protect codec resource
309 */
310 struct mutex codec_resource_lock;
311
Bradley Rubincb3950a2011-08-18 13:07:26 -0700312#ifdef CONFIG_DEBUG_FS
Joonwoo Park179b9ec2012-03-26 10:56:20 -0700313 struct dentry *debugfs_poke;
314 struct dentry *debugfs_mbhc;
Bradley Rubincb3950a2011-08-18 13:07:26 -0700315#endif
Joonwoo Park179b9ec2012-03-26 10:56:20 -0700316};
317
Bradley Rubincb3950a2011-08-18 13:07:26 -0700318
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800319static const u32 comp_shift[] = {
320 0,
321 2,
322};
323
324static const int comp_rx_path[] = {
325 COMPANDER_1,
326 COMPANDER_1,
327 COMPANDER_2,
328 COMPANDER_2,
329 COMPANDER_2,
330 COMPANDER_2,
331 COMPANDER_MAX,
332};
333
334static const struct comp_sample_dependent_params comp_samp_params[] = {
335 {
336 .peak_det_timeout = 0x2,
337 .rms_meter_div_fact = 0x8 << 4,
338 .rms_meter_resamp_fact = 0x21,
339 },
340 {
341 .peak_det_timeout = 0x3,
342 .rms_meter_div_fact = 0x9 << 4,
343 .rms_meter_resamp_fact = 0x28,
344 },
345
346 {
347 .peak_det_timeout = 0x5,
348 .rms_meter_div_fact = 0xB << 4,
349 .rms_meter_resamp_fact = 0x28,
350 },
351
352 {
353 .peak_det_timeout = 0x5,
354 .rms_meter_div_fact = 0xB << 4,
355 .rms_meter_resamp_fact = 0x28,
356 },
357};
358
Kuirong Wange9c8a222012-03-28 16:24:09 -0700359static unsigned short rx_digital_gain_reg[] = {
360 TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
361 TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
362 TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
363 TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
364 TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
365 TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
366 TABLA_A_CDC_RX7_VOL_CTL_B2_CTL,
367};
368
369
370static unsigned short tx_digital_gain_reg[] = {
371 TABLA_A_CDC_TX1_VOL_CTL_GAIN,
372 TABLA_A_CDC_TX2_VOL_CTL_GAIN,
373 TABLA_A_CDC_TX3_VOL_CTL_GAIN,
374 TABLA_A_CDC_TX4_VOL_CTL_GAIN,
375 TABLA_A_CDC_TX5_VOL_CTL_GAIN,
376 TABLA_A_CDC_TX6_VOL_CTL_GAIN,
377 TABLA_A_CDC_TX7_VOL_CTL_GAIN,
378 TABLA_A_CDC_TX8_VOL_CTL_GAIN,
379 TABLA_A_CDC_TX9_VOL_CTL_GAIN,
380 TABLA_A_CDC_TX10_VOL_CTL_GAIN,
381};
382
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700383static int tabla_codec_enable_charge_pump(struct snd_soc_dapm_widget *w,
384 struct snd_kcontrol *kcontrol, int event)
385{
386 struct snd_soc_codec *codec = w->codec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700387
388 pr_debug("%s %d\n", __func__, event);
389 switch (event) {
390 case SND_SOC_DAPM_POST_PMU:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700391 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
392 0x01);
393 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x08);
394 usleep_range(200, 200);
395 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x00);
396 break;
397 case SND_SOC_DAPM_PRE_PMD:
398 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10,
399 0x10);
400 usleep_range(20, 20);
401 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x08);
402 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x10);
403 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x00);
404 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
405 0x00);
406 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700407 break;
408 }
409 return 0;
410}
411
Bradley Rubina7096d02011-08-03 18:29:02 -0700412static int tabla_get_anc_slot(struct snd_kcontrol *kcontrol,
413 struct snd_ctl_elem_value *ucontrol)
414{
415 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
416 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
417 ucontrol->value.integer.value[0] = tabla->anc_slot;
418 return 0;
419}
420
421static int tabla_put_anc_slot(struct snd_kcontrol *kcontrol,
422 struct snd_ctl_elem_value *ucontrol)
423{
424 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
425 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
426 tabla->anc_slot = ucontrol->value.integer.value[0];
427 return 0;
428}
429
Kiran Kandid2d86b52011-09-09 17:44:28 -0700430static int tabla_pa_gain_get(struct snd_kcontrol *kcontrol,
431 struct snd_ctl_elem_value *ucontrol)
432{
433 u8 ear_pa_gain;
434 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
435
436 ear_pa_gain = snd_soc_read(codec, TABLA_A_RX_EAR_GAIN);
437
438 ear_pa_gain = ear_pa_gain >> 5;
439
440 if (ear_pa_gain == 0x00) {
441 ucontrol->value.integer.value[0] = 0;
442 } else if (ear_pa_gain == 0x04) {
443 ucontrol->value.integer.value[0] = 1;
444 } else {
445 pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n",
446 __func__, ear_pa_gain);
447 return -EINVAL;
448 }
449
450 pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain);
451
452 return 0;
453}
454
455static int tabla_pa_gain_put(struct snd_kcontrol *kcontrol,
456 struct snd_ctl_elem_value *ucontrol)
457{
458 u8 ear_pa_gain;
459 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
460
461 pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__,
462 ucontrol->value.integer.value[0]);
463
464 switch (ucontrol->value.integer.value[0]) {
465 case 0:
466 ear_pa_gain = 0x00;
467 break;
468 case 1:
469 ear_pa_gain = 0x80;
470 break;
471 default:
472 return -EINVAL;
473 }
474
475 snd_soc_update_bits(codec, TABLA_A_RX_EAR_GAIN, 0xE0, ear_pa_gain);
476 return 0;
477}
478
Ben Romberger1f045a72011-11-04 10:14:57 -0700479static int tabla_get_iir_enable_audio_mixer(
480 struct snd_kcontrol *kcontrol,
481 struct snd_ctl_elem_value *ucontrol)
482{
483 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
484 int iir_idx = ((struct soc_multi_mixer_control *)
485 kcontrol->private_value)->reg;
486 int band_idx = ((struct soc_multi_mixer_control *)
487 kcontrol->private_value)->shift;
488
489 ucontrol->value.integer.value[0] =
490 snd_soc_read(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx)) &
491 (1 << band_idx);
492
493 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
494 iir_idx, band_idx,
495 (uint32_t)ucontrol->value.integer.value[0]);
496 return 0;
497}
498
499static int tabla_put_iir_enable_audio_mixer(
500 struct snd_kcontrol *kcontrol,
501 struct snd_ctl_elem_value *ucontrol)
502{
503 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
504 int iir_idx = ((struct soc_multi_mixer_control *)
505 kcontrol->private_value)->reg;
506 int band_idx = ((struct soc_multi_mixer_control *)
507 kcontrol->private_value)->shift;
508 int value = ucontrol->value.integer.value[0];
509
510 /* Mask first 5 bits, 6-8 are reserved */
511 snd_soc_update_bits(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx),
512 (1 << band_idx), (value << band_idx));
513
514 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
515 iir_idx, band_idx, value);
516 return 0;
517}
518static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
519 int iir_idx, int band_idx,
520 int coeff_idx)
521{
522 /* Address does not automatically update if reading */
Ben Romberger0915aae2012-02-06 23:32:43 -0800523 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700524 (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800525 (band_idx * BAND_MAX + coeff_idx) & 0x1F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700526
527 /* Mask bits top 2 bits since they are reserved */
528 return ((snd_soc_read(codec,
529 (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 24) |
530 (snd_soc_read(codec,
531 (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx)) << 16) |
532 (snd_soc_read(codec,
533 (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx)) << 8) |
534 (snd_soc_read(codec,
535 (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx)))) &
536 0x3FFFFFFF;
537}
538
539static int tabla_get_iir_band_audio_mixer(
540 struct snd_kcontrol *kcontrol,
541 struct snd_ctl_elem_value *ucontrol)
542{
543 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
544 int iir_idx = ((struct soc_multi_mixer_control *)
545 kcontrol->private_value)->reg;
546 int band_idx = ((struct soc_multi_mixer_control *)
547 kcontrol->private_value)->shift;
548
549 ucontrol->value.integer.value[0] =
550 get_iir_band_coeff(codec, iir_idx, band_idx, 0);
551 ucontrol->value.integer.value[1] =
552 get_iir_band_coeff(codec, iir_idx, band_idx, 1);
553 ucontrol->value.integer.value[2] =
554 get_iir_band_coeff(codec, iir_idx, band_idx, 2);
555 ucontrol->value.integer.value[3] =
556 get_iir_band_coeff(codec, iir_idx, band_idx, 3);
557 ucontrol->value.integer.value[4] =
558 get_iir_band_coeff(codec, iir_idx, band_idx, 4);
559
560 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
561 "%s: IIR #%d band #%d b1 = 0x%x\n"
562 "%s: IIR #%d band #%d b2 = 0x%x\n"
563 "%s: IIR #%d band #%d a1 = 0x%x\n"
564 "%s: IIR #%d band #%d a2 = 0x%x\n",
565 __func__, iir_idx, band_idx,
566 (uint32_t)ucontrol->value.integer.value[0],
567 __func__, iir_idx, band_idx,
568 (uint32_t)ucontrol->value.integer.value[1],
569 __func__, iir_idx, band_idx,
570 (uint32_t)ucontrol->value.integer.value[2],
571 __func__, iir_idx, band_idx,
572 (uint32_t)ucontrol->value.integer.value[3],
573 __func__, iir_idx, band_idx,
574 (uint32_t)ucontrol->value.integer.value[4]);
575 return 0;
576}
577
578static void set_iir_band_coeff(struct snd_soc_codec *codec,
579 int iir_idx, int band_idx,
580 int coeff_idx, uint32_t value)
581{
582 /* Mask top 3 bits, 6-8 are reserved */
583 /* Update address manually each time */
Ben Romberger0915aae2012-02-06 23:32:43 -0800584 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700585 (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800586 (band_idx * BAND_MAX + coeff_idx) & 0x1F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700587
588 /* Mask top 2 bits, 7-8 are reserved */
Ben Romberger0915aae2012-02-06 23:32:43 -0800589 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700590 (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800591 (value >> 24) & 0x3F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700592
593 /* Isolate 8bits at a time */
Ben Romberger0915aae2012-02-06 23:32:43 -0800594 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700595 (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800596 (value >> 16) & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700597
Ben Romberger0915aae2012-02-06 23:32:43 -0800598 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700599 (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800600 (value >> 8) & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700601
Ben Romberger0915aae2012-02-06 23:32:43 -0800602 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700603 (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800604 value & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700605}
606
607static int tabla_put_iir_band_audio_mixer(
608 struct snd_kcontrol *kcontrol,
609 struct snd_ctl_elem_value *ucontrol)
610{
611 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
612 int iir_idx = ((struct soc_multi_mixer_control *)
613 kcontrol->private_value)->reg;
614 int band_idx = ((struct soc_multi_mixer_control *)
615 kcontrol->private_value)->shift;
616
617 set_iir_band_coeff(codec, iir_idx, band_idx, 0,
618 ucontrol->value.integer.value[0]);
619 set_iir_band_coeff(codec, iir_idx, band_idx, 1,
620 ucontrol->value.integer.value[1]);
621 set_iir_band_coeff(codec, iir_idx, band_idx, 2,
622 ucontrol->value.integer.value[2]);
623 set_iir_band_coeff(codec, iir_idx, band_idx, 3,
624 ucontrol->value.integer.value[3]);
625 set_iir_band_coeff(codec, iir_idx, band_idx, 4,
626 ucontrol->value.integer.value[4]);
627
628 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
629 "%s: IIR #%d band #%d b1 = 0x%x\n"
630 "%s: IIR #%d band #%d b2 = 0x%x\n"
631 "%s: IIR #%d band #%d a1 = 0x%x\n"
632 "%s: IIR #%d band #%d a2 = 0x%x\n",
633 __func__, iir_idx, band_idx,
634 get_iir_band_coeff(codec, iir_idx, band_idx, 0),
635 __func__, iir_idx, band_idx,
636 get_iir_band_coeff(codec, iir_idx, band_idx, 1),
637 __func__, iir_idx, band_idx,
638 get_iir_band_coeff(codec, iir_idx, band_idx, 2),
639 __func__, iir_idx, band_idx,
640 get_iir_band_coeff(codec, iir_idx, band_idx, 3),
641 __func__, iir_idx, band_idx,
642 get_iir_band_coeff(codec, iir_idx, band_idx, 4));
643 return 0;
644}
645
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800646static int tabla_compander_gain_offset(
647 struct snd_soc_codec *codec, u32 enable,
648 unsigned int reg, int mask, int event)
649{
650 int pa_mode = snd_soc_read(codec, reg) & mask;
651 int gain_offset = 0;
652 /* if PMU && enable is 1-> offset is 3
653 * if PMU && enable is 0-> offset is 0
654 * if PMD && pa_mode is PA -> offset is 0: PMU compander is off
655 * if PMD && pa_mode is comp -> offset is -3: PMU compander is on.
656 */
657
658 if (SND_SOC_DAPM_EVENT_ON(event) && (enable != 0))
659 gain_offset = TABLA_COMP_DIGITAL_GAIN_OFFSET;
660 if (SND_SOC_DAPM_EVENT_OFF(event) && (pa_mode == 0))
661 gain_offset = -TABLA_COMP_DIGITAL_GAIN_OFFSET;
662 return gain_offset;
663}
664
665
666static int tabla_config_gain_compander(
667 struct snd_soc_codec *codec,
668 u32 compander, u32 enable, int event)
669{
670 int value = 0;
671 int mask = 1 << 4;
672 int gain = 0;
673 int gain_offset;
674 if (compander >= COMPANDER_MAX) {
675 pr_err("%s: Error, invalid compander channel\n", __func__);
676 return -EINVAL;
677 }
678
679 if ((enable == 0) || SND_SOC_DAPM_EVENT_OFF(event))
680 value = 1 << 4;
681
682 if (compander == COMPANDER_1) {
683 gain_offset = tabla_compander_gain_offset(codec, enable,
684 TABLA_A_RX_HPH_L_GAIN, mask, event);
685 snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_GAIN, mask, value);
686 gain = snd_soc_read(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL);
687 snd_soc_update_bits(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
688 0xFF, gain - gain_offset);
689 gain_offset = tabla_compander_gain_offset(codec, enable,
690 TABLA_A_RX_HPH_R_GAIN, mask, event);
691 snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_GAIN, mask, value);
692 gain = snd_soc_read(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL);
693 snd_soc_update_bits(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
694 0xFF, gain - gain_offset);
695 } else if (compander == COMPANDER_2) {
696 gain_offset = tabla_compander_gain_offset(codec, enable,
697 TABLA_A_RX_LINE_1_GAIN, mask, event);
698 snd_soc_update_bits(codec, TABLA_A_RX_LINE_1_GAIN, mask, value);
699 gain = snd_soc_read(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL);
700 snd_soc_update_bits(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
701 0xFF, gain - gain_offset);
702 gain_offset = tabla_compander_gain_offset(codec, enable,
703 TABLA_A_RX_LINE_3_GAIN, mask, event);
704 snd_soc_update_bits(codec, TABLA_A_RX_LINE_3_GAIN, mask, value);
705 gain = snd_soc_read(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL);
706 snd_soc_update_bits(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
707 0xFF, gain - gain_offset);
708 gain_offset = tabla_compander_gain_offset(codec, enable,
709 TABLA_A_RX_LINE_2_GAIN, mask, event);
710 snd_soc_update_bits(codec, TABLA_A_RX_LINE_2_GAIN, mask, value);
711 gain = snd_soc_read(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL);
712 snd_soc_update_bits(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
713 0xFF, gain - gain_offset);
714 gain_offset = tabla_compander_gain_offset(codec, enable,
715 TABLA_A_RX_LINE_4_GAIN, mask, event);
716 snd_soc_update_bits(codec, TABLA_A_RX_LINE_4_GAIN, mask, value);
717 gain = snd_soc_read(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL);
718 snd_soc_update_bits(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
719 0xFF, gain - gain_offset);
720 }
721 return 0;
722}
723static int tabla_get_compander(struct snd_kcontrol *kcontrol,
724 struct snd_ctl_elem_value *ucontrol)
725{
726
727 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
728 int comp = ((struct soc_multi_mixer_control *)
729 kcontrol->private_value)->max;
730 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
731
732 ucontrol->value.integer.value[0] = tabla->comp_enabled[comp];
733
734 return 0;
735}
736
737static int tabla_set_compander(struct snd_kcontrol *kcontrol,
738 struct snd_ctl_elem_value *ucontrol)
739{
740 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
741 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
742 int comp = ((struct soc_multi_mixer_control *)
743 kcontrol->private_value)->max;
744 int value = ucontrol->value.integer.value[0];
745
746 if (value == tabla->comp_enabled[comp]) {
747 pr_debug("%s: compander #%d enable %d no change\n",
748 __func__, comp, value);
749 return 0;
750 }
751 tabla->comp_enabled[comp] = value;
752 return 0;
753}
754
755
756static int tabla_config_compander(struct snd_soc_dapm_widget *w,
757 struct snd_kcontrol *kcontrol,
758 int event)
759{
760 struct snd_soc_codec *codec = w->codec;
761 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
762 u32 rate = tabla->comp_fs[w->shift];
763
764 switch (event) {
765 case SND_SOC_DAPM_PRE_PMU:
766 if (tabla->comp_enabled[w->shift] != 0) {
767 /* Enable both L/R compander clocks */
768 snd_soc_update_bits(codec,
769 TABLA_A_CDC_CLK_RX_B2_CTL,
770 0x03 << comp_shift[w->shift],
771 0x03 << comp_shift[w->shift]);
772 /* Clar the HALT for the compander*/
773 snd_soc_update_bits(codec,
774 TABLA_A_CDC_COMP1_B1_CTL +
775 w->shift * 8, 1 << 2, 0);
776 /* Toggle compander reset bits*/
777 snd_soc_update_bits(codec,
778 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
779 0x03 << comp_shift[w->shift],
780 0x03 << comp_shift[w->shift]);
781 snd_soc_update_bits(codec,
782 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
783 0x03 << comp_shift[w->shift], 0);
784 tabla_config_gain_compander(codec, w->shift, 1, event);
785 /* Update the RMS meter resampling*/
786 snd_soc_update_bits(codec,
787 TABLA_A_CDC_COMP1_B3_CTL +
788 w->shift * 8, 0xFF, 0x01);
789 /* Wait for 1ms*/
790 usleep_range(1000, 1000);
791 }
792 break;
793 case SND_SOC_DAPM_POST_PMU:
794 /* Set sample rate dependent paramater*/
795 if (tabla->comp_enabled[w->shift] != 0) {
796 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_FS_CFG +
797 w->shift * 8, 0x03, rate);
798 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL +
799 w->shift * 8, 0x0F,
800 comp_samp_params[rate].peak_det_timeout);
801 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL +
802 w->shift * 8, 0xF0,
803 comp_samp_params[rate].rms_meter_div_fact);
804 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B3_CTL +
805 w->shift * 8, 0xFF,
806 comp_samp_params[rate].rms_meter_resamp_fact);
807 /* Compander enable -> 0x370/0x378*/
808 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
809 w->shift * 8, 0x03, 0x03);
810 }
811 break;
812 case SND_SOC_DAPM_PRE_PMD:
813 /* Halt the compander*/
814 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
815 w->shift * 8, 1 << 2, 1 << 2);
816 break;
817 case SND_SOC_DAPM_POST_PMD:
818 /* Restore the gain */
819 tabla_config_gain_compander(codec, w->shift,
820 tabla->comp_enabled[w->shift], event);
821 /* Disable the compander*/
822 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
823 w->shift * 8, 0x03, 0x00);
824 /* Turn off the clock for compander in pair*/
825 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_B2_CTL,
826 0x03 << comp_shift[w->shift], 0);
827 break;
828 }
829 return 0;
830}
831
Kiran Kandid2d86b52011-09-09 17:44:28 -0700832static const char *tabla_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"};
833static const struct soc_enum tabla_ear_pa_gain_enum[] = {
834 SOC_ENUM_SINGLE_EXT(2, tabla_ear_pa_gain_text),
835};
836
Santosh Mardi024010f2011-10-18 06:27:21 +0530837/*cut of frequency for high pass filter*/
838static const char *cf_text[] = {
839 "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz"
840};
841
842static const struct soc_enum cf_dec1_enum =
843 SOC_ENUM_SINGLE(TABLA_A_CDC_TX1_MUX_CTL, 4, 3, cf_text);
844
845static const struct soc_enum cf_dec2_enum =
846 SOC_ENUM_SINGLE(TABLA_A_CDC_TX2_MUX_CTL, 4, 3, cf_text);
847
848static const struct soc_enum cf_dec3_enum =
849 SOC_ENUM_SINGLE(TABLA_A_CDC_TX3_MUX_CTL, 4, 3, cf_text);
850
851static const struct soc_enum cf_dec4_enum =
852 SOC_ENUM_SINGLE(TABLA_A_CDC_TX4_MUX_CTL, 4, 3, cf_text);
853
854static const struct soc_enum cf_dec5_enum =
855 SOC_ENUM_SINGLE(TABLA_A_CDC_TX5_MUX_CTL, 4, 3, cf_text);
856
857static const struct soc_enum cf_dec6_enum =
858 SOC_ENUM_SINGLE(TABLA_A_CDC_TX6_MUX_CTL, 4, 3, cf_text);
859
860static const struct soc_enum cf_dec7_enum =
861 SOC_ENUM_SINGLE(TABLA_A_CDC_TX7_MUX_CTL, 4, 3, cf_text);
862
863static const struct soc_enum cf_dec8_enum =
864 SOC_ENUM_SINGLE(TABLA_A_CDC_TX8_MUX_CTL, 4, 3, cf_text);
865
866static const struct soc_enum cf_dec9_enum =
867 SOC_ENUM_SINGLE(TABLA_A_CDC_TX9_MUX_CTL, 4, 3, cf_text);
868
869static const struct soc_enum cf_dec10_enum =
870 SOC_ENUM_SINGLE(TABLA_A_CDC_TX10_MUX_CTL, 4, 3, cf_text);
871
872static const struct soc_enum cf_rxmix1_enum =
873 SOC_ENUM_SINGLE(TABLA_A_CDC_RX1_B4_CTL, 1, 3, cf_text);
874
875static const struct soc_enum cf_rxmix2_enum =
876 SOC_ENUM_SINGLE(TABLA_A_CDC_RX2_B4_CTL, 1, 3, cf_text);
877
878static const struct soc_enum cf_rxmix3_enum =
879 SOC_ENUM_SINGLE(TABLA_A_CDC_RX3_B4_CTL, 1, 3, cf_text);
880
881static const struct soc_enum cf_rxmix4_enum =
882 SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B4_CTL, 1, 3, cf_text);
883
884static const struct soc_enum cf_rxmix5_enum =
885 SOC_ENUM_SINGLE(TABLA_A_CDC_RX5_B4_CTL, 1, 3, cf_text)
886;
887static const struct soc_enum cf_rxmix6_enum =
888 SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B4_CTL, 1, 3, cf_text);
889
890static const struct soc_enum cf_rxmix7_enum =
891 SOC_ENUM_SINGLE(TABLA_A_CDC_RX7_B4_CTL, 1, 3, cf_text);
892
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700893static const struct snd_kcontrol_new tabla_snd_controls[] = {
Kiran Kandid2d86b52011-09-09 17:44:28 -0700894
895 SOC_ENUM_EXT("EAR PA Gain", tabla_ear_pa_gain_enum[0],
896 tabla_pa_gain_get, tabla_pa_gain_put),
897
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700898 SOC_SINGLE_TLV("LINEOUT1 Volume", TABLA_A_RX_LINE_1_GAIN, 0, 12, 1,
899 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700900 SOC_SINGLE_TLV("LINEOUT2 Volume", TABLA_A_RX_LINE_2_GAIN, 0, 12, 1,
901 line_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700902 SOC_SINGLE_TLV("LINEOUT3 Volume", TABLA_A_RX_LINE_3_GAIN, 0, 12, 1,
903 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700904 SOC_SINGLE_TLV("LINEOUT4 Volume", TABLA_A_RX_LINE_4_GAIN, 0, 12, 1,
905 line_gain),
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -0700906 SOC_SINGLE_TLV("LINEOUT5 Volume", TABLA_A_RX_LINE_5_GAIN, 0, 12, 1,
907 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700908
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700909 SOC_SINGLE_TLV("HPHL Volume", TABLA_A_RX_HPH_L_GAIN, 0, 12, 1,
910 line_gain),
911 SOC_SINGLE_TLV("HPHR Volume", TABLA_A_RX_HPH_R_GAIN, 0, 12, 1,
912 line_gain),
913
Bradley Rubin410383f2011-07-22 13:44:23 -0700914 SOC_SINGLE_S8_TLV("RX1 Digital Volume", TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
915 -84, 40, digital_gain),
916 SOC_SINGLE_S8_TLV("RX2 Digital Volume", TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
917 -84, 40, digital_gain),
918 SOC_SINGLE_S8_TLV("RX3 Digital Volume", TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
919 -84, 40, digital_gain),
920 SOC_SINGLE_S8_TLV("RX4 Digital Volume", TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
921 -84, 40, digital_gain),
922 SOC_SINGLE_S8_TLV("RX5 Digital Volume", TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
923 -84, 40, digital_gain),
924 SOC_SINGLE_S8_TLV("RX6 Digital Volume", TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
925 -84, 40, digital_gain),
Neema Shettyd3a89262012-02-16 10:23:50 -0800926 SOC_SINGLE_S8_TLV("RX7 Digital Volume", TABLA_A_CDC_RX7_VOL_CTL_B2_CTL,
927 -84, 40, digital_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700928
Bradley Rubin410383f2011-07-22 13:44:23 -0700929 SOC_SINGLE_S8_TLV("DEC1 Volume", TABLA_A_CDC_TX1_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700930 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -0700931 SOC_SINGLE_S8_TLV("DEC2 Volume", TABLA_A_CDC_TX2_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700932 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -0700933 SOC_SINGLE_S8_TLV("DEC3 Volume", TABLA_A_CDC_TX3_VOL_CTL_GAIN, -84, 40,
934 digital_gain),
935 SOC_SINGLE_S8_TLV("DEC4 Volume", TABLA_A_CDC_TX4_VOL_CTL_GAIN, -84, 40,
936 digital_gain),
937 SOC_SINGLE_S8_TLV("DEC5 Volume", TABLA_A_CDC_TX5_VOL_CTL_GAIN, -84, 40,
938 digital_gain),
939 SOC_SINGLE_S8_TLV("DEC6 Volume", TABLA_A_CDC_TX6_VOL_CTL_GAIN, -84, 40,
940 digital_gain),
941 SOC_SINGLE_S8_TLV("DEC7 Volume", TABLA_A_CDC_TX7_VOL_CTL_GAIN, -84, 40,
942 digital_gain),
943 SOC_SINGLE_S8_TLV("DEC8 Volume", TABLA_A_CDC_TX8_VOL_CTL_GAIN, -84, 40,
944 digital_gain),
945 SOC_SINGLE_S8_TLV("DEC9 Volume", TABLA_A_CDC_TX9_VOL_CTL_GAIN, -84, 40,
946 digital_gain),
947 SOC_SINGLE_S8_TLV("DEC10 Volume", TABLA_A_CDC_TX10_VOL_CTL_GAIN, -84,
948 40, digital_gain),
Patrick Lai29006372011-09-28 17:57:42 -0700949 SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TABLA_A_CDC_IIR1_GAIN_B1_CTL, -84,
950 40, digital_gain),
951 SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TABLA_A_CDC_IIR1_GAIN_B2_CTL, -84,
952 40, digital_gain),
953 SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TABLA_A_CDC_IIR1_GAIN_B3_CTL, -84,
954 40, digital_gain),
955 SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TABLA_A_CDC_IIR1_GAIN_B4_CTL, -84,
956 40, digital_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700957 SOC_SINGLE_TLV("ADC1 Volume", TABLA_A_TX_1_2_EN, 5, 3, 0, analog_gain),
958 SOC_SINGLE_TLV("ADC2 Volume", TABLA_A_TX_1_2_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700959 SOC_SINGLE_TLV("ADC3 Volume", TABLA_A_TX_3_4_EN, 5, 3, 0, analog_gain),
960 SOC_SINGLE_TLV("ADC4 Volume", TABLA_A_TX_3_4_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700961 SOC_SINGLE_TLV("ADC5 Volume", TABLA_A_TX_5_6_EN, 5, 3, 0, analog_gain),
962 SOC_SINGLE_TLV("ADC6 Volume", TABLA_A_TX_5_6_EN, 1, 3, 0, analog_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700963
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -0800964 SOC_SINGLE_TLV("AUX_PGA_LEFT Volume", TABLA_A_AUX_L_GAIN, 0, 39, 0,
965 aux_pga_gain),
966 SOC_SINGLE_TLV("AUX_PGA_RIGHT Volume", TABLA_A_AUX_R_GAIN, 0, 39, 0,
967 aux_pga_gain),
968
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700969 SOC_SINGLE("MICBIAS1 CAPLESS Switch", TABLA_A_MICB_1_CTL, 4, 1, 1),
Santosh Mardi680b41e2011-11-22 16:51:16 -0800970 SOC_SINGLE("MICBIAS2 CAPLESS Switch", TABLA_A_MICB_2_CTL, 4, 1, 1),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700971 SOC_SINGLE("MICBIAS3 CAPLESS Switch", TABLA_A_MICB_3_CTL, 4, 1, 1),
Bradley Rubina7096d02011-08-03 18:29:02 -0700972
973 SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 0, 100, tabla_get_anc_slot,
974 tabla_put_anc_slot),
Santosh Mardi024010f2011-10-18 06:27:21 +0530975 SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
976 SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
977 SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
978 SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
979 SOC_ENUM("TX5 HPF cut off", cf_dec5_enum),
980 SOC_ENUM("TX6 HPF cut off", cf_dec6_enum),
981 SOC_ENUM("TX7 HPF cut off", cf_dec7_enum),
982 SOC_ENUM("TX8 HPF cut off", cf_dec8_enum),
983 SOC_ENUM("TX9 HPF cut off", cf_dec9_enum),
984 SOC_ENUM("TX10 HPF cut off", cf_dec10_enum),
985
986 SOC_SINGLE("TX1 HPF Switch", TABLA_A_CDC_TX1_MUX_CTL, 3, 1, 0),
987 SOC_SINGLE("TX2 HPF Switch", TABLA_A_CDC_TX2_MUX_CTL, 3, 1, 0),
988 SOC_SINGLE("TX3 HPF Switch", TABLA_A_CDC_TX3_MUX_CTL, 3, 1, 0),
989 SOC_SINGLE("TX4 HPF Switch", TABLA_A_CDC_TX4_MUX_CTL, 3, 1, 0),
990 SOC_SINGLE("TX5 HPF Switch", TABLA_A_CDC_TX5_MUX_CTL, 3, 1, 0),
991 SOC_SINGLE("TX6 HPF Switch", TABLA_A_CDC_TX6_MUX_CTL, 3, 1, 0),
992 SOC_SINGLE("TX7 HPF Switch", TABLA_A_CDC_TX7_MUX_CTL, 3, 1, 0),
993 SOC_SINGLE("TX8 HPF Switch", TABLA_A_CDC_TX8_MUX_CTL, 3, 1, 0),
994 SOC_SINGLE("TX9 HPF Switch", TABLA_A_CDC_TX9_MUX_CTL, 3, 1, 0),
995 SOC_SINGLE("TX10 HPF Switch", TABLA_A_CDC_TX10_MUX_CTL, 3, 1, 0),
996
997 SOC_SINGLE("RX1 HPF Switch", TABLA_A_CDC_RX1_B5_CTL, 2, 1, 0),
998 SOC_SINGLE("RX2 HPF Switch", TABLA_A_CDC_RX2_B5_CTL, 2, 1, 0),
999 SOC_SINGLE("RX3 HPF Switch", TABLA_A_CDC_RX3_B5_CTL, 2, 1, 0),
1000 SOC_SINGLE("RX4 HPF Switch", TABLA_A_CDC_RX4_B5_CTL, 2, 1, 0),
1001 SOC_SINGLE("RX5 HPF Switch", TABLA_A_CDC_RX5_B5_CTL, 2, 1, 0),
1002 SOC_SINGLE("RX6 HPF Switch", TABLA_A_CDC_RX6_B5_CTL, 2, 1, 0),
1003 SOC_SINGLE("RX7 HPF Switch", TABLA_A_CDC_RX7_B5_CTL, 2, 1, 0),
1004
1005 SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum),
1006 SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum),
1007 SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum),
1008 SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum),
1009 SOC_ENUM("RX5 HPF cut off", cf_rxmix5_enum),
1010 SOC_ENUM("RX6 HPF cut off", cf_rxmix6_enum),
1011 SOC_ENUM("RX7 HPF cut off", cf_rxmix7_enum),
Ben Romberger1f045a72011-11-04 10:14:57 -07001012
1013 SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
1014 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1015 SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
1016 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1017 SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
1018 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1019 SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
1020 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1021 SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
1022 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1023 SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0,
1024 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1025 SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0,
1026 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1027 SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0,
1028 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1029 SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0,
1030 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1031 SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0,
1032 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1033
1034 SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
1035 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1036 SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
1037 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1038 SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
1039 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1040 SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
1041 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1042 SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
1043 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1044 SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5,
1045 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1046 SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5,
1047 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1048 SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5,
1049 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1050 SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5,
1051 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1052 SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5,
1053 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001054 SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, 1, COMPANDER_1, 0,
1055 tabla_get_compander, tabla_set_compander),
1056 SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, 0, COMPANDER_2, 0,
1057 tabla_get_compander, tabla_set_compander),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001058};
1059
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08001060static const struct snd_kcontrol_new tabla_1_x_snd_controls[] = {
1061 SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_1_A_MICB_4_CTL, 4, 1, 1),
1062};
1063
1064static const struct snd_kcontrol_new tabla_2_higher_snd_controls[] = {
1065 SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_2_A_MICB_4_CTL, 4, 1, 1),
1066};
1067
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001068static const char *rx_mix1_text[] = {
1069 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
1070 "RX5", "RX6", "RX7"
1071};
1072
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001073static const char *rx_mix2_text[] = {
1074 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2"
1075};
1076
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001077static const char *rx_dsm_text[] = {
1078 "CIC_OUT", "DSM_INV"
1079};
1080
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001081static const char *sb_tx1_mux_text[] = {
1082 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1083 "DEC1"
1084};
1085
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001086static const char *sb_tx2_mux_text[] = {
1087 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1088 "DEC2"
1089};
1090
1091static const char *sb_tx3_mux_text[] = {
1092 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1093 "DEC3"
1094};
1095
1096static const char *sb_tx4_mux_text[] = {
1097 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1098 "DEC4"
1099};
1100
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001101static const char *sb_tx5_mux_text[] = {
1102 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1103 "DEC5"
1104};
1105
1106static const char *sb_tx6_mux_text[] = {
1107 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1108 "DEC6"
1109};
1110
1111static const char const *sb_tx7_to_tx10_mux_text[] = {
1112 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1113 "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
1114 "DEC9", "DEC10"
1115};
1116
1117static const char *dec1_mux_text[] = {
1118 "ZERO", "DMIC1", "ADC6",
1119};
1120
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001121static const char *dec2_mux_text[] = {
1122 "ZERO", "DMIC2", "ADC5",
1123};
1124
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001125static const char *dec3_mux_text[] = {
1126 "ZERO", "DMIC3", "ADC4",
1127};
1128
1129static const char *dec4_mux_text[] = {
1130 "ZERO", "DMIC4", "ADC3",
1131};
1132
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001133static const char *dec5_mux_text[] = {
1134 "ZERO", "DMIC5", "ADC2",
1135};
1136
1137static const char *dec6_mux_text[] = {
1138 "ZERO", "DMIC6", "ADC1",
1139};
1140
1141static const char const *dec7_mux_text[] = {
1142 "ZERO", "DMIC1", "DMIC6", "ADC1", "ADC6", "ANC1_FB", "ANC2_FB",
1143};
1144
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001145static const char *dec8_mux_text[] = {
1146 "ZERO", "DMIC2", "DMIC5", "ADC2", "ADC5",
1147};
1148
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001149static const char *dec9_mux_text[] = {
1150 "ZERO", "DMIC4", "DMIC5", "ADC2", "ADC3", "ADCMB", "ANC1_FB", "ANC2_FB",
1151};
1152
1153static const char *dec10_mux_text[] = {
1154 "ZERO", "DMIC3", "DMIC6", "ADC1", "ADC4", "ADCMB", "ANC1_FB", "ANC2_FB",
1155};
1156
Bradley Rubin229c6a52011-07-12 16:18:48 -07001157static const char const *anc_mux_text[] = {
1158 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6", "ADC_MB",
1159 "RSVD_1", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", "DMIC6"
1160};
1161
1162static const char const *anc1_fb_mux_text[] = {
1163 "ZERO", "EAR_HPH_L", "EAR_LINE_1",
1164};
1165
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001166static const char *iir1_inp1_text[] = {
1167 "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
1168 "DEC9", "DEC10", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7"
1169};
1170
1171static const struct soc_enum rx_mix1_inp1_chain_enum =
1172 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_mix1_text);
1173
Bradley Rubin229c6a52011-07-12 16:18:48 -07001174static const struct soc_enum rx_mix1_inp2_chain_enum =
1175 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_mix1_text);
1176
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001177static const struct soc_enum rx2_mix1_inp1_chain_enum =
1178 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_mix1_text);
1179
Bradley Rubin229c6a52011-07-12 16:18:48 -07001180static const struct soc_enum rx2_mix1_inp2_chain_enum =
1181 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_mix1_text);
1182
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001183static const struct soc_enum rx3_mix1_inp1_chain_enum =
1184 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 0, 12, rx_mix1_text);
1185
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001186static const struct soc_enum rx3_mix1_inp2_chain_enum =
1187 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 4, 12, rx_mix1_text);
1188
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001189static const struct soc_enum rx4_mix1_inp1_chain_enum =
1190 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 0, 12, rx_mix1_text);
1191
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001192static const struct soc_enum rx4_mix1_inp2_chain_enum =
1193 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 4, 12, rx_mix1_text);
1194
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001195static const struct soc_enum rx5_mix1_inp1_chain_enum =
1196 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 0, 12, rx_mix1_text);
1197
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001198static const struct soc_enum rx5_mix1_inp2_chain_enum =
1199 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 4, 12, rx_mix1_text);
1200
1201static const struct soc_enum rx6_mix1_inp1_chain_enum =
1202 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 0, 12, rx_mix1_text);
1203
1204static const struct soc_enum rx6_mix1_inp2_chain_enum =
1205 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 4, 12, rx_mix1_text);
1206
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001207static const struct soc_enum rx7_mix1_inp1_chain_enum =
1208 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 0, 12, rx_mix1_text);
1209
1210static const struct soc_enum rx7_mix1_inp2_chain_enum =
1211 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 4, 12, rx_mix1_text);
1212
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001213static const struct soc_enum rx1_mix2_inp1_chain_enum =
1214 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text);
1215
1216static const struct soc_enum rx1_mix2_inp2_chain_enum =
1217 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text);
1218
1219static const struct soc_enum rx2_mix2_inp1_chain_enum =
1220 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text);
1221
1222static const struct soc_enum rx2_mix2_inp2_chain_enum =
1223 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text);
1224
1225static const struct soc_enum rx3_mix2_inp1_chain_enum =
1226 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 0, 5, rx_mix2_text);
1227
1228static const struct soc_enum rx3_mix2_inp2_chain_enum =
1229 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 3, 5, rx_mix2_text);
1230
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001231static const struct soc_enum rx4_dsm_enum =
1232 SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B6_CTL, 4, 2, rx_dsm_text);
1233
1234static const struct soc_enum rx6_dsm_enum =
1235 SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B6_CTL, 4, 2, rx_dsm_text);
1236
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001237static const struct soc_enum sb_tx1_mux_enum =
1238 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text);
1239
1240static const struct soc_enum sb_tx2_mux_enum =
1241 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0, 9, sb_tx2_mux_text);
1242
1243static const struct soc_enum sb_tx3_mux_enum =
1244 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0, 9, sb_tx3_mux_text);
1245
1246static const struct soc_enum sb_tx4_mux_enum =
1247 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0, 9, sb_tx4_mux_text);
1248
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001249static const struct soc_enum sb_tx5_mux_enum =
1250 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text);
1251
1252static const struct soc_enum sb_tx6_mux_enum =
1253 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0, 9, sb_tx6_mux_text);
1254
1255static const struct soc_enum sb_tx7_mux_enum =
1256 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0, 18,
1257 sb_tx7_to_tx10_mux_text);
1258
1259static const struct soc_enum sb_tx8_mux_enum =
1260 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0, 18,
1261 sb_tx7_to_tx10_mux_text);
1262
Kiran Kandi3426e512011-09-13 22:50:10 -07001263static const struct soc_enum sb_tx9_mux_enum =
1264 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0, 18,
1265 sb_tx7_to_tx10_mux_text);
1266
1267static const struct soc_enum sb_tx10_mux_enum =
1268 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0, 18,
1269 sb_tx7_to_tx10_mux_text);
1270
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001271static const struct soc_enum dec1_mux_enum =
1272 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 0, 3, dec1_mux_text);
1273
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001274static const struct soc_enum dec2_mux_enum =
1275 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 2, 3, dec2_mux_text);
1276
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001277static const struct soc_enum dec3_mux_enum =
1278 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 4, 3, dec3_mux_text);
1279
1280static const struct soc_enum dec4_mux_enum =
1281 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 6, 3, dec4_mux_text);
1282
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001283static const struct soc_enum dec5_mux_enum =
1284 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 0, 3, dec5_mux_text);
1285
1286static const struct soc_enum dec6_mux_enum =
1287 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 2, 3, dec6_mux_text);
1288
1289static const struct soc_enum dec7_mux_enum =
1290 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 4, 7, dec7_mux_text);
1291
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001292static const struct soc_enum dec8_mux_enum =
1293 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 0, 7, dec8_mux_text);
1294
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001295static const struct soc_enum dec9_mux_enum =
1296 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 3, 8, dec9_mux_text);
1297
1298static const struct soc_enum dec10_mux_enum =
1299 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B4_CTL, 0, 8, dec10_mux_text);
1300
Bradley Rubin229c6a52011-07-12 16:18:48 -07001301static const struct soc_enum anc1_mux_enum =
1302 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 0, 16, anc_mux_text);
1303
1304static const struct soc_enum anc2_mux_enum =
1305 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 4, 16, anc_mux_text);
1306
1307static const struct soc_enum anc1_fb_mux_enum =
1308 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text);
1309
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001310static const struct soc_enum iir1_inp1_mux_enum =
1311 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ1_B1_CTL, 0, 18, iir1_inp1_text);
1312
1313static const struct snd_kcontrol_new rx_mix1_inp1_mux =
1314 SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum);
1315
Bradley Rubin229c6a52011-07-12 16:18:48 -07001316static const struct snd_kcontrol_new rx_mix1_inp2_mux =
1317 SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum);
1318
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001319static const struct snd_kcontrol_new rx2_mix1_inp1_mux =
1320 SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum);
1321
Bradley Rubin229c6a52011-07-12 16:18:48 -07001322static const struct snd_kcontrol_new rx2_mix1_inp2_mux =
1323 SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum);
1324
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001325static const struct snd_kcontrol_new rx3_mix1_inp1_mux =
1326 SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum);
1327
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001328static const struct snd_kcontrol_new rx3_mix1_inp2_mux =
1329 SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum);
1330
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001331static const struct snd_kcontrol_new rx4_mix1_inp1_mux =
1332 SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum);
1333
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001334static const struct snd_kcontrol_new rx4_mix1_inp2_mux =
1335 SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum);
1336
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001337static const struct snd_kcontrol_new rx5_mix1_inp1_mux =
1338 SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum);
1339
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001340static const struct snd_kcontrol_new rx5_mix1_inp2_mux =
1341 SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum);
1342
1343static const struct snd_kcontrol_new rx6_mix1_inp1_mux =
1344 SOC_DAPM_ENUM("RX6 MIX1 INP1 Mux", rx6_mix1_inp1_chain_enum);
1345
1346static const struct snd_kcontrol_new rx6_mix1_inp2_mux =
1347 SOC_DAPM_ENUM("RX6 MIX1 INP2 Mux", rx6_mix1_inp2_chain_enum);
1348
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001349static const struct snd_kcontrol_new rx7_mix1_inp1_mux =
1350 SOC_DAPM_ENUM("RX7 MIX1 INP1 Mux", rx7_mix1_inp1_chain_enum);
1351
1352static const struct snd_kcontrol_new rx7_mix1_inp2_mux =
1353 SOC_DAPM_ENUM("RX7 MIX1 INP2 Mux", rx7_mix1_inp2_chain_enum);
1354
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001355static const struct snd_kcontrol_new rx1_mix2_inp1_mux =
1356 SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum);
1357
1358static const struct snd_kcontrol_new rx1_mix2_inp2_mux =
1359 SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum);
1360
1361static const struct snd_kcontrol_new rx2_mix2_inp1_mux =
1362 SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum);
1363
1364static const struct snd_kcontrol_new rx2_mix2_inp2_mux =
1365 SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum);
1366
1367static const struct snd_kcontrol_new rx3_mix2_inp1_mux =
1368 SOC_DAPM_ENUM("RX3 MIX2 INP1 Mux", rx3_mix2_inp1_chain_enum);
1369
1370static const struct snd_kcontrol_new rx3_mix2_inp2_mux =
1371 SOC_DAPM_ENUM("RX3 MIX2 INP2 Mux", rx3_mix2_inp2_chain_enum);
1372
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001373static const struct snd_kcontrol_new rx4_dsm_mux =
1374 SOC_DAPM_ENUM("RX4 DSM MUX Mux", rx4_dsm_enum);
1375
1376static const struct snd_kcontrol_new rx6_dsm_mux =
1377 SOC_DAPM_ENUM("RX6 DSM MUX Mux", rx6_dsm_enum);
1378
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001379static const struct snd_kcontrol_new sb_tx1_mux =
1380 SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum);
1381
1382static const struct snd_kcontrol_new sb_tx2_mux =
1383 SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum);
1384
1385static const struct snd_kcontrol_new sb_tx3_mux =
1386 SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum);
1387
1388static const struct snd_kcontrol_new sb_tx4_mux =
1389 SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum);
1390
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001391static const struct snd_kcontrol_new sb_tx5_mux =
1392 SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum);
1393
1394static const struct snd_kcontrol_new sb_tx6_mux =
1395 SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum);
1396
1397static const struct snd_kcontrol_new sb_tx7_mux =
1398 SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum);
1399
1400static const struct snd_kcontrol_new sb_tx8_mux =
1401 SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum);
1402
Kiran Kandi3426e512011-09-13 22:50:10 -07001403static const struct snd_kcontrol_new sb_tx9_mux =
1404 SOC_DAPM_ENUM("SLIM TX9 MUX Mux", sb_tx9_mux_enum);
1405
1406static const struct snd_kcontrol_new sb_tx10_mux =
1407 SOC_DAPM_ENUM("SLIM TX10 MUX Mux", sb_tx10_mux_enum);
1408
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001409
Kiran Kandi59a96b12012-01-16 02:20:03 -08001410static int wcd9310_put_dec_enum(struct snd_kcontrol *kcontrol,
1411 struct snd_ctl_elem_value *ucontrol)
1412{
1413 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1414 struct snd_soc_dapm_widget *w = wlist->widgets[0];
1415 struct snd_soc_codec *codec = w->codec;
1416 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1417 unsigned int dec_mux, decimator;
1418 char *dec_name = NULL;
1419 char *widget_name = NULL;
1420 char *temp;
1421 u16 tx_mux_ctl_reg;
1422 u8 adc_dmic_sel = 0x0;
1423 int ret = 0;
1424
1425 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1426 return -EINVAL;
1427
1428 dec_mux = ucontrol->value.enumerated.item[0];
1429
1430 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
1431 if (!widget_name)
1432 return -ENOMEM;
1433 temp = widget_name;
1434
1435 dec_name = strsep(&widget_name, " ");
1436 widget_name = temp;
1437 if (!dec_name) {
1438 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
1439 ret = -EINVAL;
1440 goto out;
1441 }
1442
1443 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
1444 if (ret < 0) {
1445 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
1446 ret = -EINVAL;
1447 goto out;
1448 }
1449
1450 dev_dbg(w->dapm->dev, "%s(): widget = %s dec_name = %s decimator = %u"
1451 " dec_mux = %u\n", __func__, w->name, dec_name, decimator,
1452 dec_mux);
1453
1454
1455 switch (decimator) {
1456 case 1:
1457 case 2:
1458 case 3:
1459 case 4:
1460 case 5:
1461 case 6:
1462 if (dec_mux == 1)
1463 adc_dmic_sel = 0x1;
1464 else
1465 adc_dmic_sel = 0x0;
1466 break;
1467 case 7:
1468 case 8:
1469 case 9:
1470 case 10:
1471 if ((dec_mux == 1) || (dec_mux == 2))
1472 adc_dmic_sel = 0x1;
1473 else
1474 adc_dmic_sel = 0x0;
1475 break;
1476 default:
1477 pr_err("%s: Invalid Decimator = %u\n", __func__, decimator);
1478 ret = -EINVAL;
1479 goto out;
1480 }
1481
1482 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
1483
1484 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel);
1485
1486 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1487
1488out:
1489 kfree(widget_name);
1490 return ret;
1491}
1492
1493#define WCD9310_DEC_ENUM(xname, xenum) \
1494{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1495 .info = snd_soc_info_enum_double, \
1496 .get = snd_soc_dapm_get_enum_double, \
1497 .put = wcd9310_put_dec_enum, \
1498 .private_value = (unsigned long)&xenum }
1499
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001500static const struct snd_kcontrol_new dec1_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001501 WCD9310_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001502
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001503static const struct snd_kcontrol_new dec2_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001504 WCD9310_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum);
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001505
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001506static const struct snd_kcontrol_new dec3_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001507 WCD9310_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001508
1509static const struct snd_kcontrol_new dec4_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001510 WCD9310_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001511
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001512static const struct snd_kcontrol_new dec5_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001513 WCD9310_DEC_ENUM("DEC5 MUX Mux", dec5_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001514
1515static const struct snd_kcontrol_new dec6_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001516 WCD9310_DEC_ENUM("DEC6 MUX Mux", dec6_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001517
1518static const struct snd_kcontrol_new dec7_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001519 WCD9310_DEC_ENUM("DEC7 MUX Mux", dec7_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001520
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001521static const struct snd_kcontrol_new dec8_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001522 WCD9310_DEC_ENUM("DEC8 MUX Mux", dec8_mux_enum);
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001523
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001524static const struct snd_kcontrol_new dec9_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001525 WCD9310_DEC_ENUM("DEC9 MUX Mux", dec9_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001526
1527static const struct snd_kcontrol_new dec10_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001528 WCD9310_DEC_ENUM("DEC10 MUX Mux", dec10_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001529
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001530static const struct snd_kcontrol_new iir1_inp1_mux =
1531 SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum);
1532
Kiran Kandi59a96b12012-01-16 02:20:03 -08001533static const struct snd_kcontrol_new anc1_mux =
1534 SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum);
1535
Bradley Rubin229c6a52011-07-12 16:18:48 -07001536static const struct snd_kcontrol_new anc2_mux =
1537 SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001538
Bradley Rubin229c6a52011-07-12 16:18:48 -07001539static const struct snd_kcontrol_new anc1_fb_mux =
1540 SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001541
Bradley Rubin229c6a52011-07-12 16:18:48 -07001542static const struct snd_kcontrol_new dac1_switch[] = {
1543 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_EAR_EN, 5, 1, 0)
1544};
1545static const struct snd_kcontrol_new hphl_switch[] = {
1546 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_HPH_L_DAC_CTL, 6, 1, 0)
1547};
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001548
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001549static const struct snd_kcontrol_new hphl_pa_mix[] = {
1550 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1551 7, 1, 0),
1552 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1553 7, 1, 0),
1554 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1555 TABLA_A_AUX_L_PA_CONN_INV, 7, 1, 0),
1556 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1557 TABLA_A_AUX_R_PA_CONN_INV, 7, 1, 0),
1558};
1559
1560static const struct snd_kcontrol_new hphr_pa_mix[] = {
1561 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1562 6, 1, 0),
1563 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1564 6, 1, 0),
1565 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1566 TABLA_A_AUX_L_PA_CONN_INV, 6, 1, 0),
1567 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1568 TABLA_A_AUX_R_PA_CONN_INV, 6, 1, 0),
1569};
1570
1571static const struct snd_kcontrol_new lineout1_pa_mix[] = {
1572 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1573 5, 1, 0),
1574 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1575 5, 1, 0),
1576 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1577 TABLA_A_AUX_L_PA_CONN_INV, 5, 1, 0),
1578 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1579 TABLA_A_AUX_R_PA_CONN_INV, 5, 1, 0),
1580};
1581
1582static const struct snd_kcontrol_new lineout2_pa_mix[] = {
1583 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1584 4, 1, 0),
1585 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1586 4, 1, 0),
1587 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1588 TABLA_A_AUX_L_PA_CONN_INV, 4, 1, 0),
1589 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1590 TABLA_A_AUX_R_PA_CONN_INV, 4, 1, 0),
1591};
1592
1593static const struct snd_kcontrol_new lineout3_pa_mix[] = {
1594 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1595 3, 1, 0),
1596 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1597 3, 1, 0),
1598 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1599 TABLA_A_AUX_L_PA_CONN_INV, 3, 1, 0),
1600 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1601 TABLA_A_AUX_R_PA_CONN_INV, 3, 1, 0),
1602};
1603
1604static const struct snd_kcontrol_new lineout4_pa_mix[] = {
1605 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1606 2, 1, 0),
1607 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1608 2, 1, 0),
1609 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1610 TABLA_A_AUX_L_PA_CONN_INV, 2, 1, 0),
1611 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1612 TABLA_A_AUX_R_PA_CONN_INV, 2, 1, 0),
1613};
1614
1615static const struct snd_kcontrol_new lineout5_pa_mix[] = {
1616 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1617 1, 1, 0),
1618 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1619 1, 1, 0),
1620 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1621 TABLA_A_AUX_L_PA_CONN_INV, 1, 1, 0),
1622 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1623 TABLA_A_AUX_R_PA_CONN_INV, 1, 1, 0),
1624};
1625
1626static const struct snd_kcontrol_new ear_pa_mix[] = {
1627 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1628 0, 1, 0),
1629 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1630 0, 1, 0),
1631 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1632 TABLA_A_AUX_L_PA_CONN_INV, 0, 1, 0),
1633 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1634 TABLA_A_AUX_R_PA_CONN_INV, 0, 1, 0),
1635};
1636
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001637static const struct snd_kcontrol_new lineout3_ground_switch =
1638 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_3_DAC_CTL, 6, 1, 0);
1639
1640static const struct snd_kcontrol_new lineout4_ground_switch =
1641 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_4_DAC_CTL, 6, 1, 0);
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001642
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001643static void tabla_codec_enable_adc_block(struct snd_soc_codec *codec,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001644 int enable)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001645{
1646 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1647
1648 pr_debug("%s %d\n", __func__, enable);
1649
1650 if (enable) {
1651 tabla->adc_count++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001652 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x2, 0x2);
1653 } else {
1654 tabla->adc_count--;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001655 if (!tabla->adc_count)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001656 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL,
Joonwoo Park03324832012-03-19 19:36:16 -07001657 0x2, 0x0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001658 }
1659}
1660
1661static int tabla_codec_enable_adc(struct snd_soc_dapm_widget *w,
1662 struct snd_kcontrol *kcontrol, int event)
1663{
1664 struct snd_soc_codec *codec = w->codec;
1665 u16 adc_reg;
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08001666 u8 init_bit_shift;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001667
1668 pr_debug("%s %d\n", __func__, event);
1669
1670 if (w->reg == TABLA_A_TX_1_2_EN)
1671 adc_reg = TABLA_A_TX_1_2_TEST_CTL;
1672 else if (w->reg == TABLA_A_TX_3_4_EN)
1673 adc_reg = TABLA_A_TX_3_4_TEST_CTL;
1674 else if (w->reg == TABLA_A_TX_5_6_EN)
1675 adc_reg = TABLA_A_TX_5_6_TEST_CTL;
1676 else {
1677 pr_err("%s: Error, invalid adc register\n", __func__);
1678 return -EINVAL;
1679 }
1680
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08001681 if (w->shift == 3)
1682 init_bit_shift = 6;
1683 else if (w->shift == 7)
1684 init_bit_shift = 7;
1685 else {
1686 pr_err("%s: Error, invalid init bit postion adc register\n",
1687 __func__);
1688 return -EINVAL;
1689 }
1690
1691
1692
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001693 switch (event) {
1694 case SND_SOC_DAPM_PRE_PMU:
1695 tabla_codec_enable_adc_block(codec, 1);
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08001696 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift,
1697 1 << init_bit_shift);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001698 break;
1699 case SND_SOC_DAPM_POST_PMU:
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08001700
1701 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00);
1702
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001703 break;
1704 case SND_SOC_DAPM_POST_PMD:
1705 tabla_codec_enable_adc_block(codec, 0);
1706 break;
1707 }
1708 return 0;
1709}
1710
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001711static void tabla_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec)
1712{
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001713 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
1714 0x80);
1715 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x04,
1716 0x04);
1717 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01,
1718 0x01);
1719 usleep_range(1000, 1000);
1720 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
1721 0x00);
1722}
1723
1724static void tabla_codec_enable_bandgap(struct snd_soc_codec *codec,
1725 enum tabla_bandgap_type choice)
1726{
1727 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1728
1729 /* TODO lock resources accessed by audio streams and threaded
1730 * interrupt handlers
1731 */
1732
1733 pr_debug("%s, choice is %d, current is %d\n", __func__, choice,
1734 tabla->bandgap_type);
1735
1736 if (tabla->bandgap_type == choice)
1737 return;
1738
1739 if ((tabla->bandgap_type == TABLA_BANDGAP_OFF) &&
1740 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
1741 tabla_codec_enable_audio_mode_bandgap(codec);
1742 } else if (choice == TABLA_BANDGAP_MBHC_MODE) {
1743 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x2,
1744 0x2);
1745 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
1746 0x80);
1747 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x4,
1748 0x4);
1749 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01,
1750 0x01);
1751 usleep_range(1000, 1000);
1752 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
1753 0x00);
1754 } else if ((tabla->bandgap_type == TABLA_BANDGAP_MBHC_MODE) &&
1755 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
1756 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x00);
1757 usleep_range(100, 100);
1758 tabla_codec_enable_audio_mode_bandgap(codec);
1759 } else if (choice == TABLA_BANDGAP_OFF) {
1760 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x00);
1761 } else {
1762 pr_err("%s: Error, Invalid bandgap settings\n", __func__);
1763 }
1764 tabla->bandgap_type = choice;
1765}
1766
1767static void tabla_codec_disable_clock_block(struct snd_soc_codec *codec)
1768{
1769 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1770 pr_debug("%s\n", __func__);
1771 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x00);
1772 ndelay(160);
1773 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x02);
1774 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x00);
1775 tabla->clock_active = false;
1776}
1777
1778static int tabla_codec_mclk_index(const struct tabla_priv *tabla)
1779{
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001780 if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001781 return 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001782 else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001783 return 1;
1784 else {
1785 BUG_ON(1);
1786 return -EINVAL;
1787 }
1788}
1789
1790static void tabla_enable_rx_bias(struct snd_soc_codec *codec, u32 enable)
1791{
1792 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1793
1794 if (enable) {
1795 tabla->rx_bias_count++;
1796 if (tabla->rx_bias_count == 1)
1797 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
1798 0x80, 0x80);
1799 } else {
1800 tabla->rx_bias_count--;
1801 if (!tabla->rx_bias_count)
1802 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
1803 0x80, 0x00);
1804 }
1805}
1806
1807static int tabla_codec_enable_config_mode(struct snd_soc_codec *codec,
1808 int enable)
1809{
1810 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1811
1812 pr_debug("%s: enable = %d\n", __func__, enable);
1813 if (enable) {
1814 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x10, 0);
1815 snd_soc_write(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x17);
1816 usleep_range(5, 5);
1817 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80,
1818 0x80);
1819 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80,
1820 0x80);
1821 usleep_range(10, 10);
1822 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, 0);
1823 usleep_range(20, 20);
1824 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x08);
1825 } else {
1826 snd_soc_update_bits(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x1,
1827 0);
1828 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, 0);
1829 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00);
1830 }
1831 tabla->config_mode_active = enable ? true : false;
1832
1833 return 0;
1834}
1835
1836static int tabla_codec_enable_clock_block(struct snd_soc_codec *codec,
1837 int config_mode)
1838{
1839 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1840
1841 pr_debug("%s: config_mode = %d\n", __func__, config_mode);
1842
1843 if (config_mode) {
1844 tabla_codec_enable_config_mode(codec, 1);
1845 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x00);
1846 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
1847 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN1, 0x0D);
1848 usleep_range(1000, 1000);
1849 } else
1850 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00);
1851
1852 if (!config_mode && tabla->mbhc_polling_active) {
1853 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
1854 tabla_codec_enable_config_mode(codec, 0);
1855
1856 }
1857
1858 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x05);
1859 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x00);
1860 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x04);
1861 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_MCLK_CTL, 0x01, 0x01);
1862 usleep_range(50, 50);
1863 tabla->clock_active = true;
1864 return 0;
1865}
1866
1867static int tabla_codec_enable_aux_pga(struct snd_soc_dapm_widget *w,
1868 struct snd_kcontrol *kcontrol, int event)
1869{
1870 struct snd_soc_codec *codec = w->codec;
1871 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1872
1873 pr_debug("%s: %d\n", __func__, event);
1874
1875 switch (event) {
1876 case SND_SOC_DAPM_PRE_PMU:
1877 tabla_codec_enable_bandgap(codec,
1878 TABLA_BANDGAP_AUDIO_MODE);
1879 tabla_enable_rx_bias(codec, 1);
1880
1881 snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL,
1882 0x08, 0x08);
1883 /* Enable Zero Cross detect for AUX PGA channel
1884 * and set the initial AUX PGA gain to NEG_0P0_DB
1885 * to avoid glitches.
1886 */
1887 if (w->reg == TABLA_A_AUX_L_EN) {
1888 snd_soc_update_bits(codec, TABLA_A_AUX_L_EN,
1889 0x20, 0x20);
1890 tabla->aux_l_gain = snd_soc_read(codec,
1891 TABLA_A_AUX_L_GAIN);
1892 snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F);
1893 } else {
1894 snd_soc_update_bits(codec, TABLA_A_AUX_R_EN,
1895 0x20, 0x20);
1896 tabla->aux_r_gain = snd_soc_read(codec,
1897 TABLA_A_AUX_R_GAIN);
1898 snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F);
1899 }
1900 if (tabla->aux_pga_cnt++ == 1
1901 && !tabla->mclk_enabled) {
1902 tabla_codec_enable_clock_block(codec, 1);
1903 pr_debug("AUX PGA enabled RC osc\n");
1904 }
1905 break;
1906
1907 case SND_SOC_DAPM_POST_PMU:
1908 if (w->reg == TABLA_A_AUX_L_EN)
1909 snd_soc_write(codec, TABLA_A_AUX_L_GAIN,
1910 tabla->aux_l_gain);
1911 else
1912 snd_soc_write(codec, TABLA_A_AUX_R_GAIN,
1913 tabla->aux_r_gain);
1914 break;
1915
1916 case SND_SOC_DAPM_PRE_PMD:
1917 /* Mute AUX PGA channel in use before disabling AUX PGA */
1918 if (w->reg == TABLA_A_AUX_L_EN) {
1919 tabla->aux_l_gain = snd_soc_read(codec,
1920 TABLA_A_AUX_L_GAIN);
1921 snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F);
1922 } else {
1923 tabla->aux_r_gain = snd_soc_read(codec,
1924 TABLA_A_AUX_R_GAIN);
1925 snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F);
1926 }
1927 break;
1928
1929 case SND_SOC_DAPM_POST_PMD:
1930 tabla_enable_rx_bias(codec, 0);
1931
1932 snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL,
1933 0x08, 0x00);
1934 if (w->reg == TABLA_A_AUX_L_EN) {
1935 snd_soc_write(codec, TABLA_A_AUX_L_GAIN,
1936 tabla->aux_l_gain);
1937 snd_soc_update_bits(codec, TABLA_A_AUX_L_EN,
1938 0x20, 0x00);
1939 } else {
1940 snd_soc_write(codec, TABLA_A_AUX_R_GAIN,
1941 tabla->aux_r_gain);
1942 snd_soc_update_bits(codec, TABLA_A_AUX_R_EN,
1943 0x20, 0x00);
1944 }
1945
1946 if (tabla->aux_pga_cnt-- == 0) {
1947 if (tabla->mbhc_polling_active)
1948 tabla_codec_enable_bandgap(codec,
1949 TABLA_BANDGAP_MBHC_MODE);
1950 else
1951 tabla_codec_enable_bandgap(codec,
1952 TABLA_BANDGAP_OFF);
1953
1954 if (!tabla->mclk_enabled &&
1955 !tabla->mbhc_polling_active) {
1956 tabla_codec_enable_clock_block(codec, 0);
1957 }
1958 }
1959 break;
1960 }
1961 return 0;
1962}
1963
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001964static int tabla_codec_enable_lineout(struct snd_soc_dapm_widget *w,
1965 struct snd_kcontrol *kcontrol, int event)
1966{
1967 struct snd_soc_codec *codec = w->codec;
1968 u16 lineout_gain_reg;
1969
Kiran Kandidb0a4b02011-08-23 09:32:09 -07001970 pr_debug("%s %d %s\n", __func__, event, w->name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001971
1972 switch (w->shift) {
1973 case 0:
1974 lineout_gain_reg = TABLA_A_RX_LINE_1_GAIN;
1975 break;
1976 case 1:
1977 lineout_gain_reg = TABLA_A_RX_LINE_2_GAIN;
1978 break;
1979 case 2:
1980 lineout_gain_reg = TABLA_A_RX_LINE_3_GAIN;
1981 break;
1982 case 3:
1983 lineout_gain_reg = TABLA_A_RX_LINE_4_GAIN;
1984 break;
1985 case 4:
1986 lineout_gain_reg = TABLA_A_RX_LINE_5_GAIN;
1987 break;
1988 default:
1989 pr_err("%s: Error, incorrect lineout register value\n",
1990 __func__);
1991 return -EINVAL;
1992 }
1993
1994 switch (event) {
1995 case SND_SOC_DAPM_PRE_PMU:
1996 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40);
1997 break;
1998 case SND_SOC_DAPM_POST_PMU:
Krishnankutty Kolathappilly31169f42011-11-17 10:33:11 -08001999 pr_debug("%s: sleeping 16 ms after %s PA turn on\n",
Kiran Kandidb0a4b02011-08-23 09:32:09 -07002000 __func__, w->name);
Krishnankutty Kolathappilly31169f42011-11-17 10:33:11 -08002001 usleep_range(16000, 16000);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002002 break;
2003 case SND_SOC_DAPM_POST_PMD:
2004 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00);
2005 break;
2006 }
2007 return 0;
2008}
2009
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002010
2011static int tabla_codec_enable_dmic(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002012 struct snd_kcontrol *kcontrol, int event)
2013{
2014 struct snd_soc_codec *codec = w->codec;
Kiran Kandi59a96b12012-01-16 02:20:03 -08002015 u16 tx_dmic_ctl_reg;
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002016 u8 dmic_clk_sel, dmic_clk_en;
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002017 unsigned int dmic;
2018 int ret;
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002019
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002020 ret = kstrtouint(strpbrk(w->name, "123456"), 10, &dmic);
2021 if (ret < 0) {
2022 pr_err("%s: Invalid DMIC line on the codec\n", __func__);
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002023 return -EINVAL;
2024 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002025
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002026 switch (dmic) {
2027 case 1:
2028 case 2:
2029 dmic_clk_sel = 0x02;
2030 dmic_clk_en = 0x01;
2031 break;
2032
2033 case 3:
2034 case 4:
2035 dmic_clk_sel = 0x08;
2036 dmic_clk_en = 0x04;
2037 break;
2038
2039 case 5:
2040 case 6:
2041 dmic_clk_sel = 0x20;
2042 dmic_clk_en = 0x10;
2043 break;
2044
2045 default:
2046 pr_err("%s: Invalid DMIC Selection\n", __func__);
2047 return -EINVAL;
2048 }
2049
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002050 tx_dmic_ctl_reg = TABLA_A_CDC_TX1_DMIC_CTL + 8 * (dmic - 1);
2051
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002052 pr_debug("%s %d\n", __func__, event);
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002053
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002054 switch (event) {
2055 case SND_SOC_DAPM_PRE_PMU:
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002056
2057 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
2058 dmic_clk_sel, dmic_clk_sel);
2059
2060 snd_soc_update_bits(codec, tx_dmic_ctl_reg, 0x1, 0x1);
2061
2062 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
2063 dmic_clk_en, dmic_clk_en);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002064 break;
2065 case SND_SOC_DAPM_POST_PMD:
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002066 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
2067 dmic_clk_en, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002068 break;
2069 }
2070 return 0;
2071}
2072
Bradley Rubin229c6a52011-07-12 16:18:48 -07002073static int tabla_codec_enable_anc(struct snd_soc_dapm_widget *w,
2074 struct snd_kcontrol *kcontrol, int event)
2075{
2076 struct snd_soc_codec *codec = w->codec;
2077 const char *filename;
2078 const struct firmware *fw;
2079 int i;
2080 int ret;
Bradley Rubina7096d02011-08-03 18:29:02 -07002081 int num_anc_slots;
2082 struct anc_header *anc_head;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002083 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubina7096d02011-08-03 18:29:02 -07002084 u32 anc_writes_size = 0;
2085 int anc_size_remaining;
2086 u32 *anc_ptr;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002087 u16 reg;
2088 u8 mask, val, old_val;
2089
2090 pr_debug("%s %d\n", __func__, event);
2091 switch (event) {
2092 case SND_SOC_DAPM_PRE_PMU:
2093
Bradley Rubin4283a4c2011-07-29 16:18:54 -07002094 filename = "wcd9310/wcd9310_anc.bin";
Bradley Rubin229c6a52011-07-12 16:18:48 -07002095
2096 ret = request_firmware(&fw, filename, codec->dev);
2097 if (ret != 0) {
2098 dev_err(codec->dev, "Failed to acquire ANC data: %d\n",
2099 ret);
2100 return -ENODEV;
2101 }
2102
Bradley Rubina7096d02011-08-03 18:29:02 -07002103 if (fw->size < sizeof(struct anc_header)) {
Bradley Rubin229c6a52011-07-12 16:18:48 -07002104 dev_err(codec->dev, "Not enough data\n");
2105 release_firmware(fw);
2106 return -ENOMEM;
2107 }
2108
2109 /* First number is the number of register writes */
Bradley Rubina7096d02011-08-03 18:29:02 -07002110 anc_head = (struct anc_header *)(fw->data);
2111 anc_ptr = (u32 *)((u32)fw->data + sizeof(struct anc_header));
2112 anc_size_remaining = fw->size - sizeof(struct anc_header);
2113 num_anc_slots = anc_head->num_anc_slots;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002114
Bradley Rubina7096d02011-08-03 18:29:02 -07002115 if (tabla->anc_slot >= num_anc_slots) {
2116 dev_err(codec->dev, "Invalid ANC slot selected\n");
2117 release_firmware(fw);
2118 return -EINVAL;
2119 }
2120
2121 for (i = 0; i < num_anc_slots; i++) {
2122
2123 if (anc_size_remaining < TABLA_PACKED_REG_SIZE) {
2124 dev_err(codec->dev, "Invalid register format\n");
2125 release_firmware(fw);
2126 return -EINVAL;
2127 }
2128 anc_writes_size = (u32)(*anc_ptr);
2129 anc_size_remaining -= sizeof(u32);
2130 anc_ptr += 1;
2131
2132 if (anc_writes_size * TABLA_PACKED_REG_SIZE
2133 > anc_size_remaining) {
2134 dev_err(codec->dev, "Invalid register format\n");
2135 release_firmware(fw);
2136 return -ENOMEM;
2137 }
2138
2139 if (tabla->anc_slot == i)
2140 break;
2141
2142 anc_size_remaining -= (anc_writes_size *
2143 TABLA_PACKED_REG_SIZE);
Bradley Rubin939ff3f2011-08-26 17:19:34 -07002144 anc_ptr += anc_writes_size;
Bradley Rubina7096d02011-08-03 18:29:02 -07002145 }
2146 if (i == num_anc_slots) {
2147 dev_err(codec->dev, "Selected ANC slot not present\n");
Bradley Rubin229c6a52011-07-12 16:18:48 -07002148 release_firmware(fw);
2149 return -ENOMEM;
2150 }
2151
Bradley Rubina7096d02011-08-03 18:29:02 -07002152 for (i = 0; i < anc_writes_size; i++) {
2153 TABLA_CODEC_UNPACK_ENTRY(anc_ptr[i], reg,
Bradley Rubin229c6a52011-07-12 16:18:48 -07002154 mask, val);
2155 old_val = snd_soc_read(codec, reg);
Bradley Rubin4283a4c2011-07-29 16:18:54 -07002156 snd_soc_write(codec, reg, (old_val & ~mask) |
2157 (val & mask));
Bradley Rubin229c6a52011-07-12 16:18:48 -07002158 }
2159 release_firmware(fw);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002160
2161 break;
2162 case SND_SOC_DAPM_POST_PMD:
2163 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0xFF);
2164 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_CLK_EN_CTL, 0);
2165 break;
2166 }
2167 return 0;
2168}
2169
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002170/* called under codec_resource_lock acquisition */
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002171static void tabla_codec_start_hs_polling(struct snd_soc_codec *codec)
2172{
Bradley Rubincb3950a2011-08-18 13:07:26 -07002173 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07002174 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
2175 int mbhc_state = tabla->mbhc_state;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002176
Joonwoo Park03324832012-03-19 19:36:16 -07002177 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002178 if (!tabla->mbhc_polling_active) {
2179 pr_debug("Polling is not active, do not start polling\n");
2180 return;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002181 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002182 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Joonwoo Park03324832012-03-19 19:36:16 -07002183
2184 if (!tabla->no_mic_headset_override) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002185 if (mbhc_state == MBHC_STATE_POTENTIAL) {
2186 pr_debug("%s recovering MBHC state macine\n", __func__);
2187 tabla->mbhc_state = MBHC_STATE_POTENTIAL_RECOVERY;
Joonwoo Park03324832012-03-19 19:36:16 -07002188 /* set to max button press threshold */
2189 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
2190 0x7F);
2191 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
2192 0xFF);
2193 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL,
2194 (TABLA_IS_1_X(tabla_core->version) ?
2195 0x07 : 0x7F));
2196 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL,
2197 0xFF);
2198 /* set to max */
2199 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL,
2200 0x7F);
2201 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL,
2202 0xFF);
2203 }
2204 }
2205
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002206 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
2207 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
2208 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
Joonwoo Park03324832012-03-19 19:36:16 -07002209 pr_debug("%s: leave\n", __func__);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002210}
2211
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002212/* called under codec_resource_lock acquisition */
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002213static void tabla_codec_pause_hs_polling(struct snd_soc_codec *codec)
2214{
Bradley Rubincb3950a2011-08-18 13:07:26 -07002215 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2216
Joonwoo Park03324832012-03-19 19:36:16 -07002217 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002218 if (!tabla->mbhc_polling_active) {
2219 pr_debug("polling not active, nothing to pause\n");
2220 return;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002221 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002222
2223 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
Joonwoo Park03324832012-03-19 19:36:16 -07002224 pr_debug("%s: leave\n", __func__);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002225}
2226
Joonwoo Park03324832012-03-19 19:36:16 -07002227static void tabla_codec_switch_cfilt_mode(struct snd_soc_codec *codec, int mode)
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002228{
2229 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2230 u8 reg_mode_val, cur_mode_val;
2231 bool mbhc_was_polling = false;
2232
2233 if (mode)
2234 reg_mode_val = TABLA_CFILT_FAST_MODE;
2235 else
2236 reg_mode_val = TABLA_CFILT_SLOW_MODE;
2237
2238 cur_mode_val = snd_soc_read(codec,
2239 tabla->mbhc_bias_regs.cfilt_ctl) & 0x40;
2240
2241 if (cur_mode_val != reg_mode_val) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002242 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002243 if (tabla->mbhc_polling_active) {
2244 tabla_codec_pause_hs_polling(codec);
2245 mbhc_was_polling = true;
2246 }
2247 snd_soc_update_bits(codec,
2248 tabla->mbhc_bias_regs.cfilt_ctl, 0x40, reg_mode_val);
2249 if (mbhc_was_polling)
2250 tabla_codec_start_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002251 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002252 pr_debug("%s: CFILT mode change (%x to %x)\n", __func__,
2253 cur_mode_val, reg_mode_val);
2254 } else {
2255 pr_debug("%s: CFILT Value is already %x\n",
2256 __func__, cur_mode_val);
2257 }
2258}
2259
2260static void tabla_codec_update_cfilt_usage(struct snd_soc_codec *codec,
2261 u8 cfilt_sel, int inc)
2262{
2263 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2264 u32 *cfilt_cnt_ptr = NULL;
2265 u16 micb_cfilt_reg;
2266
2267 switch (cfilt_sel) {
2268 case TABLA_CFILT1_SEL:
2269 cfilt_cnt_ptr = &tabla->cfilt1_cnt;
2270 micb_cfilt_reg = TABLA_A_MICB_CFILT_1_CTL;
2271 break;
2272 case TABLA_CFILT2_SEL:
2273 cfilt_cnt_ptr = &tabla->cfilt2_cnt;
2274 micb_cfilt_reg = TABLA_A_MICB_CFILT_2_CTL;
2275 break;
2276 case TABLA_CFILT3_SEL:
2277 cfilt_cnt_ptr = &tabla->cfilt3_cnt;
2278 micb_cfilt_reg = TABLA_A_MICB_CFILT_3_CTL;
2279 break;
2280 default:
2281 return; /* should not happen */
2282 }
2283
2284 if (inc) {
2285 if (!(*cfilt_cnt_ptr)++) {
2286 /* Switch CFILT to slow mode if MBHC CFILT being used */
2287 if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel)
2288 tabla_codec_switch_cfilt_mode(codec, 0);
2289
2290 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80);
2291 }
2292 } else {
2293 /* check if count not zero, decrement
2294 * then check if zero, go ahead disable cfilter
2295 */
2296 if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr)) {
2297 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0);
2298
2299 /* Switch CFILT to fast mode if MBHC CFILT being used */
2300 if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel)
2301 tabla_codec_switch_cfilt_mode(codec, 1);
2302 }
2303 }
2304}
2305
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002306static int tabla_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv)
2307{
2308 int rc = -EINVAL;
2309 unsigned min_mv, max_mv;
2310
2311 switch (ldoh_v) {
2312 case TABLA_LDOH_1P95_V:
2313 min_mv = 160;
2314 max_mv = 1800;
2315 break;
2316 case TABLA_LDOH_2P35_V:
2317 min_mv = 200;
2318 max_mv = 2200;
2319 break;
2320 case TABLA_LDOH_2P75_V:
2321 min_mv = 240;
2322 max_mv = 2600;
2323 break;
2324 case TABLA_LDOH_2P85_V:
2325 min_mv = 250;
2326 max_mv = 2700;
2327 break;
2328 default:
2329 goto done;
2330 }
2331
2332 if (cfilt_mv < min_mv || cfilt_mv > max_mv)
2333 goto done;
2334
2335 for (rc = 4; rc <= 44; rc++) {
2336 min_mv = max_mv * (rc) / 44;
2337 if (min_mv >= cfilt_mv) {
2338 rc -= 4;
2339 break;
2340 }
2341 }
2342done:
2343 return rc;
2344}
2345
2346static bool tabla_is_hph_pa_on(struct snd_soc_codec *codec)
2347{
2348 u8 hph_reg_val = 0;
2349 hph_reg_val = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_EN);
2350
2351 return (hph_reg_val & 0x30) ? true : false;
2352}
2353
Joonwoo Parka9444452011-12-08 18:48:27 -08002354static bool tabla_is_hph_dac_on(struct snd_soc_codec *codec, int left)
2355{
2356 u8 hph_reg_val = 0;
2357 if (left)
2358 hph_reg_val = snd_soc_read(codec,
2359 TABLA_A_RX_HPH_L_DAC_CTL);
2360 else
2361 hph_reg_val = snd_soc_read(codec,
2362 TABLA_A_RX_HPH_R_DAC_CTL);
2363
2364 return (hph_reg_val & 0xC0) ? true : false;
2365}
2366
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002367static void tabla_turn_onoff_override(struct snd_soc_codec *codec, bool on)
2368{
2369 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, on << 2);
2370}
2371
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002372/* called under codec_resource_lock acquisition */
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002373static void tabla_codec_drive_v_to_micbias(struct snd_soc_codec *codec,
2374 int usec)
2375{
2376 int cfilt_k_val;
2377 bool set = true;
2378 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2379
2380 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
2381 tabla->mbhc_micbias_switched) {
2382 pr_debug("%s: set mic V to micbias V\n", __func__);
2383 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
2384 tabla_turn_onoff_override(codec, true);
2385 while (1) {
2386 cfilt_k_val = tabla_find_k_value(
2387 tabla->pdata->micbias.ldoh_v,
2388 set ? tabla->mbhc_data.micb_mv :
2389 VDDIO_MICBIAS_MV);
2390 snd_soc_update_bits(codec,
2391 tabla->mbhc_bias_regs.cfilt_val,
2392 0xFC, (cfilt_k_val << 2));
2393 if (!set)
2394 break;
2395 usleep_range(usec, usec);
2396 set = false;
2397 }
2398 tabla_turn_onoff_override(codec, false);
2399 }
2400}
2401
2402/* called under codec_resource_lock acquisition */
2403static void __tabla_codec_switch_micbias(struct snd_soc_codec *codec,
2404 int vddio_switch, bool restartpolling,
2405 bool checkpolling)
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002406{
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002407 int cfilt_k_val;
Joonwoo Park41956722012-04-18 13:13:07 -07002408 bool override;
2409 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002410
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002411 if (vddio_switch && !tabla->mbhc_micbias_switched &&
2412 (!checkpolling || tabla->mbhc_polling_active)) {
2413 if (restartpolling)
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08002414 tabla_codec_pause_hs_polling(codec);
Joonwoo Park41956722012-04-18 13:13:07 -07002415 override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04;
2416 if (!override)
2417 tabla_turn_onoff_override(codec, true);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002418 /* Adjust threshold if Mic Bias voltage changes */
2419 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002420 cfilt_k_val = tabla_find_k_value(
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002421 tabla->pdata->micbias.ldoh_v,
2422 VDDIO_MICBIAS_MV);
2423 usleep_range(10000, 10000);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002424 snd_soc_update_bits(codec,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002425 tabla->mbhc_bias_regs.cfilt_val,
2426 0xFC, (cfilt_k_val << 2));
2427 usleep_range(10000, 10000);
2428 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
2429 tabla->mbhc_data.adj_v_ins_hu & 0xFF);
2430 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
2431 (tabla->mbhc_data.adj_v_ins_hu >> 8) &
2432 0xFF);
2433 pr_debug("%s: Programmed MBHC thresholds to VDDIO\n",
2434 __func__);
2435 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002436
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002437 /* enable MIC BIAS Switch to VDDIO */
2438 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2439 0x80, 0x80);
2440 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2441 0x10, 0x00);
Joonwoo Park41956722012-04-18 13:13:07 -07002442 if (!override)
2443 tabla_turn_onoff_override(codec, false);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002444 if (restartpolling)
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08002445 tabla_codec_start_hs_polling(codec);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002446
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002447 tabla->mbhc_micbias_switched = true;
2448 pr_debug("%s: VDDIO switch enabled\n", __func__);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002449
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002450 } else if (!vddio_switch && tabla->mbhc_micbias_switched) {
2451 if ((!checkpolling || tabla->mbhc_polling_active) &&
2452 restartpolling)
2453 tabla_codec_pause_hs_polling(codec);
2454 /* Reprogram thresholds */
2455 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
2456 cfilt_k_val = tabla_find_k_value(
2457 tabla->pdata->micbias.ldoh_v,
2458 tabla->mbhc_data.micb_mv);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002459 snd_soc_update_bits(codec,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002460 tabla->mbhc_bias_regs.cfilt_val,
2461 0xFC, (cfilt_k_val << 2));
2462 usleep_range(10000, 10000);
2463 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
2464 tabla->mbhc_data.v_ins_hu & 0xFF);
2465 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
2466 (tabla->mbhc_data.v_ins_hu >> 8) & 0xFF);
2467 pr_debug("%s: Programmed MBHC thresholds to MICBIAS\n",
2468 __func__);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002469 }
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002470
2471 /* Disable MIC BIAS Switch to VDDIO */
2472 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2473 0x80, 0x00);
2474 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2475 0x10, 0x00);
2476
2477 if ((!checkpolling || tabla->mbhc_polling_active) &&
2478 restartpolling)
2479 tabla_codec_start_hs_polling(codec);
2480
2481 tabla->mbhc_micbias_switched = false;
2482 pr_debug("%s: VDDIO switch disabled\n", __func__);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002483 }
2484}
2485
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002486static void tabla_codec_switch_micbias(struct snd_soc_codec *codec,
2487 int vddio_switch)
2488{
2489 return __tabla_codec_switch_micbias(codec, vddio_switch, true, true);
2490}
2491
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002492static int tabla_codec_enable_micbias(struct snd_soc_dapm_widget *w,
2493 struct snd_kcontrol *kcontrol, int event)
2494{
2495 struct snd_soc_codec *codec = w->codec;
Patrick Lai3043fba2011-08-01 14:15:57 -07002496 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2497 u16 micb_int_reg;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002498 int micb_line;
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002499 u8 cfilt_sel_val = 0;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002500 char *internal1_text = "Internal1";
2501 char *internal2_text = "Internal2";
2502 char *internal3_text = "Internal3";
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002503
2504 pr_debug("%s %d\n", __func__, event);
2505 switch (w->reg) {
2506 case TABLA_A_MICB_1_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002507 micb_int_reg = TABLA_A_MICB_1_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07002508 cfilt_sel_val = tabla->pdata->micbias.bias1_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002509 micb_line = TABLA_MICBIAS1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002510 break;
2511 case TABLA_A_MICB_2_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002512 micb_int_reg = TABLA_A_MICB_2_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07002513 cfilt_sel_val = tabla->pdata->micbias.bias2_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002514 micb_line = TABLA_MICBIAS2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002515 break;
2516 case TABLA_A_MICB_3_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002517 micb_int_reg = TABLA_A_MICB_3_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07002518 cfilt_sel_val = tabla->pdata->micbias.bias3_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002519 micb_line = TABLA_MICBIAS3;
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002520 break;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08002521 case TABLA_1_A_MICB_4_CTL:
2522 case TABLA_2_A_MICB_4_CTL:
2523 micb_int_reg = tabla->reg_addr.micb_4_int_rbias;
Patrick Lai3043fba2011-08-01 14:15:57 -07002524 cfilt_sel_val = tabla->pdata->micbias.bias4_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002525 micb_line = TABLA_MICBIAS4;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002526 break;
2527 default:
2528 pr_err("%s: Error, invalid micbias register\n", __func__);
2529 return -EINVAL;
2530 }
2531
2532 switch (event) {
2533 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002534 /* Decide whether to switch the micbias for MBHC */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002535 if (w->reg == tabla->mbhc_bias_regs.ctl_reg) {
2536 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002537 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002538 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
2539 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002540
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002541 snd_soc_update_bits(codec, w->reg, 0x0E, 0x0A);
Patrick Lai3043fba2011-08-01 14:15:57 -07002542 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 1);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002543
2544 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002545 snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002546 else if (strnstr(w->name, internal2_text, 30))
2547 snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C);
2548 else if (strnstr(w->name, internal3_text, 30))
2549 snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3);
2550
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002551 break;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002552 case SND_SOC_DAPM_POST_PMU:
Kiran Kandid8cf5212012-03-02 15:34:53 -08002553
2554 usleep_range(20000, 20000);
2555
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002556 if (tabla->mbhc_polling_active &&
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002557 tabla->mbhc_cfg.micbias == micb_line) {
2558 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002559 tabla_codec_pause_hs_polling(codec);
2560 tabla_codec_start_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002561 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002562 }
2563 break;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002564
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002565 case SND_SOC_DAPM_POST_PMD:
Joonwoo Park03324832012-03-19 19:36:16 -07002566 if ((w->reg == tabla->mbhc_bias_regs.ctl_reg) &&
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002567 tabla_is_hph_pa_on(codec)) {
2568 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002569 tabla_codec_switch_micbias(codec, 1);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002570 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
2571 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002572
Bradley Rubin229c6a52011-07-12 16:18:48 -07002573 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002574 snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002575 else if (strnstr(w->name, internal2_text, 30))
2576 snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00);
2577 else if (strnstr(w->name, internal3_text, 30))
2578 snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0);
2579
Patrick Lai3043fba2011-08-01 14:15:57 -07002580 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002581 break;
2582 }
2583
2584 return 0;
2585}
2586
Kiran Kandid8cf5212012-03-02 15:34:53 -08002587
2588static void tx_hpf_corner_freq_callback(struct work_struct *work)
2589{
2590 struct delayed_work *hpf_delayed_work;
2591 struct hpf_work *hpf_work;
2592 struct tabla_priv *tabla;
2593 struct snd_soc_codec *codec;
2594 u16 tx_mux_ctl_reg;
2595 u8 hpf_cut_of_freq;
2596
2597 hpf_delayed_work = to_delayed_work(work);
2598 hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
2599 tabla = hpf_work->tabla;
2600 codec = hpf_work->tabla->codec;
2601 hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq;
2602
2603 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL +
2604 (hpf_work->decimator - 1) * 8;
2605
2606 pr_debug("%s(): decimator %u hpf_cut_of_freq 0x%x\n", __func__,
2607 hpf_work->decimator, (unsigned int)hpf_cut_of_freq);
2608
2609 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4);
2610}
2611
2612#define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30
2613#define CF_MIN_3DB_4HZ 0x0
2614#define CF_MIN_3DB_75HZ 0x1
2615#define CF_MIN_3DB_150HZ 0x2
2616
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002617static int tabla_codec_enable_dec(struct snd_soc_dapm_widget *w,
2618 struct snd_kcontrol *kcontrol, int event)
2619{
2620 struct snd_soc_codec *codec = w->codec;
Kiran Kandid8cf5212012-03-02 15:34:53 -08002621 unsigned int decimator;
2622 char *dec_name = NULL;
2623 char *widget_name = NULL;
2624 char *temp;
2625 int ret = 0;
2626 u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg;
2627 u8 dec_hpf_cut_of_freq;
Kuirong Wange9c8a222012-03-28 16:24:09 -07002628 int offset;
2629
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002630
2631 pr_debug("%s %d\n", __func__, event);
2632
Kiran Kandid8cf5212012-03-02 15:34:53 -08002633 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
2634 if (!widget_name)
2635 return -ENOMEM;
2636 temp = widget_name;
2637
2638 dec_name = strsep(&widget_name, " ");
2639 widget_name = temp;
2640 if (!dec_name) {
2641 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
2642 ret = -EINVAL;
2643 goto out;
2644 }
2645
2646 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
2647 if (ret < 0) {
2648 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
2649 ret = -EINVAL;
2650 goto out;
2651 }
2652
2653 pr_debug("%s(): widget = %s dec_name = %s decimator = %u\n", __func__,
2654 w->name, dec_name, decimator);
2655
Kuirong Wange9c8a222012-03-28 16:24:09 -07002656 if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002657 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B1_CTL;
Kuirong Wange9c8a222012-03-28 16:24:09 -07002658 offset = 0;
2659 } else if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002660 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B2_CTL;
Kuirong Wange9c8a222012-03-28 16:24:09 -07002661 offset = 8;
2662 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002663 pr_err("%s: Error, incorrect dec\n", __func__);
2664 return -EINVAL;
2665 }
2666
Kiran Kandid8cf5212012-03-02 15:34:53 -08002667 tx_vol_ctl_reg = TABLA_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator -1);
2668 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
2669
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002670 switch (event) {
2671 case SND_SOC_DAPM_PRE_PMU:
Kiran Kandid8cf5212012-03-02 15:34:53 -08002672
2673 // Enableable TX digital mute */
2674 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
2675
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002676 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift,
2677 1 << w->shift);
2678 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0);
Kiran Kandid8cf5212012-03-02 15:34:53 -08002679
2680 dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg);
2681
2682 dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4;
2683
2684 tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq =
2685 dec_hpf_cut_of_freq;
2686
2687 if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) {
2688
2689 /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */
2690 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
2691 CF_MIN_3DB_150HZ << 4);
2692 }
2693
2694 /* enable HPF */
2695 snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00);
2696
2697 break;
2698
2699 case SND_SOC_DAPM_POST_PMU:
2700
2701 /* Disable TX digital mute */
2702 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00);
2703
2704 if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq !=
2705 CF_MIN_3DB_150HZ) {
2706
2707 schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork,
2708 msecs_to_jiffies(300));
2709 }
Kuirong Wange9c8a222012-03-28 16:24:09 -07002710 /* apply the digital gain after the decimator is enabled*/
2711 if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
2712 snd_soc_write(codec,
2713 tx_digital_gain_reg[w->shift + offset],
2714 snd_soc_read(codec,
2715 tx_digital_gain_reg[w->shift + offset])
2716 );
2717
Kiran Kandid8cf5212012-03-02 15:34:53 -08002718 break;
2719
2720 case SND_SOC_DAPM_PRE_PMD:
2721
2722 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
2723 cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork);
2724 break;
2725
2726 case SND_SOC_DAPM_POST_PMD:
2727
2728 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08);
2729 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
2730 (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4);
2731
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002732 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002733 }
Kiran Kandid8cf5212012-03-02 15:34:53 -08002734out:
2735 kfree(widget_name);
2736 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002737}
2738
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07002739static int tabla_codec_reset_interpolator(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002740 struct snd_kcontrol *kcontrol, int event)
2741{
2742 struct snd_soc_codec *codec = w->codec;
2743
Kiran Kandi8b3a8302011-09-27 16:13:28 -07002744 pr_debug("%s %d %s\n", __func__, event, w->name);
2745
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002746 switch (event) {
2747 case SND_SOC_DAPM_PRE_PMU:
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07002748 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
2749 1 << w->shift, 1 << w->shift);
2750 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
2751 1 << w->shift, 0x0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002752 break;
Kuirong Wange9c8a222012-03-28 16:24:09 -07002753 case SND_SOC_DAPM_POST_PMU:
2754 /* apply the digital gain after the interpolator is enabled*/
2755 if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
2756 snd_soc_write(codec,
2757 rx_digital_gain_reg[w->shift],
2758 snd_soc_read(codec,
2759 rx_digital_gain_reg[w->shift])
2760 );
2761 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002762 }
2763 return 0;
2764}
2765
Bradley Rubin229c6a52011-07-12 16:18:48 -07002766static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
2767 struct snd_kcontrol *kcontrol, int event)
2768{
2769 switch (event) {
2770 case SND_SOC_DAPM_POST_PMU:
2771 case SND_SOC_DAPM_POST_PMD:
2772 usleep_range(1000, 1000);
2773 break;
2774 }
2775 return 0;
2776}
2777
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002778static int tabla_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
2779 struct snd_kcontrol *kcontrol, int event)
2780{
2781 struct snd_soc_codec *codec = w->codec;
2782
2783 pr_debug("%s %d\n", __func__, event);
2784
2785 switch (event) {
2786 case SND_SOC_DAPM_PRE_PMU:
2787 tabla_enable_rx_bias(codec, 1);
2788 break;
2789 case SND_SOC_DAPM_POST_PMD:
2790 tabla_enable_rx_bias(codec, 0);
2791 break;
2792 }
2793 return 0;
2794}
Kiran Kandi8b3a8302011-09-27 16:13:28 -07002795static int tabla_hphr_dac_event(struct snd_soc_dapm_widget *w,
2796 struct snd_kcontrol *kcontrol, int event)
2797{
2798 struct snd_soc_codec *codec = w->codec;
2799
2800 pr_debug("%s %s %d\n", __func__, w->name, event);
2801
2802 switch (event) {
2803 case SND_SOC_DAPM_PRE_PMU:
2804 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
2805 break;
2806 case SND_SOC_DAPM_POST_PMD:
2807 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
2808 break;
2809 }
2810 return 0;
2811}
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002812
Joonwoo Park8b1f0982011-12-08 17:12:45 -08002813static void tabla_snd_soc_jack_report(struct tabla_priv *tabla,
2814 struct snd_soc_jack *jack, int status,
2815 int mask)
2816{
2817 /* XXX: wake_lock_timeout()? */
Joonwoo Park03324832012-03-19 19:36:16 -07002818 snd_soc_jack_report_no_dapm(jack, status, mask);
Joonwoo Park8b1f0982011-12-08 17:12:45 -08002819}
2820
Patrick Lai49efeac2011-11-03 11:01:12 -07002821static void hphocp_off_report(struct tabla_priv *tabla,
2822 u32 jack_status, int irq)
2823{
2824 struct snd_soc_codec *codec;
Joonwoo Park03324832012-03-19 19:36:16 -07002825 if (!tabla) {
2826 pr_err("%s: Bad tabla private data\n", __func__);
2827 return;
2828 }
Patrick Lai49efeac2011-11-03 11:01:12 -07002829
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002830 pr_debug("%s: clear ocp status %x\n", __func__, jack_status);
Joonwoo Park03324832012-03-19 19:36:16 -07002831 codec = tabla->codec;
2832 if (tabla->hph_status & jack_status) {
Patrick Lai49efeac2011-11-03 11:01:12 -07002833 tabla->hph_status &= ~jack_status;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002834 if (tabla->mbhc_cfg.headset_jack)
2835 tabla_snd_soc_jack_report(tabla,
2836 tabla->mbhc_cfg.headset_jack,
Joonwoo Park8b1f0982011-12-08 17:12:45 -08002837 tabla->hph_status,
2838 TABLA_JACK_MASK);
Joonwoo Park0976d012011-12-22 11:48:18 -08002839 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x00);
2840 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10);
Patrick Laic7cae882011-11-18 11:52:49 -08002841 /* reset retry counter as PA is turned off signifying
2842 * start of new OCP detection session
2843 */
2844 if (TABLA_IRQ_HPH_PA_OCPL_FAULT)
2845 tabla->hphlocp_cnt = 0;
2846 else
2847 tabla->hphrocp_cnt = 0;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05302848 wcd9xxx_enable_irq(codec->control_data, irq);
Patrick Lai49efeac2011-11-03 11:01:12 -07002849 }
2850}
2851
2852static void hphlocp_off_report(struct work_struct *work)
2853{
2854 struct tabla_priv *tabla = container_of(work, struct tabla_priv,
2855 hphlocp_work);
2856 hphocp_off_report(tabla, SND_JACK_OC_HPHL, TABLA_IRQ_HPH_PA_OCPL_FAULT);
2857}
2858
2859static void hphrocp_off_report(struct work_struct *work)
2860{
2861 struct tabla_priv *tabla = container_of(work, struct tabla_priv,
2862 hphrocp_work);
2863 hphocp_off_report(tabla, SND_JACK_OC_HPHR, TABLA_IRQ_HPH_PA_OCPR_FAULT);
2864}
2865
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07002866static int tabla_hph_pa_event(struct snd_soc_dapm_widget *w,
2867 struct snd_kcontrol *kcontrol, int event)
2868{
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002869 struct snd_soc_codec *codec = w->codec;
2870 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2871 u8 mbhc_micb_ctl_val;
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07002872 pr_debug("%s: event = %d\n", __func__, event);
2873
2874 switch (event) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002875 case SND_SOC_DAPM_PRE_PMU:
2876 mbhc_micb_ctl_val = snd_soc_read(codec,
2877 tabla->mbhc_bias_regs.ctl_reg);
2878
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002879 if (!(mbhc_micb_ctl_val & 0x80)) {
2880 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002881 tabla_codec_switch_micbias(codec, 1);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002882 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
2883 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002884 break;
2885
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07002886 case SND_SOC_DAPM_POST_PMD:
Patrick Lai49efeac2011-11-03 11:01:12 -07002887 /* schedule work is required because at the time HPH PA DAPM
2888 * event callback is called by DAPM framework, CODEC dapm mutex
2889 * would have been locked while snd_soc_jack_report also
2890 * attempts to acquire same lock.
2891 */
Joonwoo Parka9444452011-12-08 18:48:27 -08002892 if (w->shift == 5) {
2893 clear_bit(TABLA_HPHL_PA_OFF_ACK,
2894 &tabla->hph_pa_dac_state);
2895 clear_bit(TABLA_HPHL_DAC_OFF_ACK,
2896 &tabla->hph_pa_dac_state);
2897 if (tabla->hph_status & SND_JACK_OC_HPHL)
2898 schedule_work(&tabla->hphlocp_work);
2899 } else if (w->shift == 4) {
2900 clear_bit(TABLA_HPHR_PA_OFF_ACK,
2901 &tabla->hph_pa_dac_state);
2902 clear_bit(TABLA_HPHR_DAC_OFF_ACK,
2903 &tabla->hph_pa_dac_state);
2904 if (tabla->hph_status & SND_JACK_OC_HPHR)
2905 schedule_work(&tabla->hphrocp_work);
2906 }
2907
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002908 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Joonwoo Park03324832012-03-19 19:36:16 -07002909 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002910 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002911
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07002912 pr_debug("%s: sleep 10 ms after %s PA disable.\n", __func__,
2913 w->name);
2914 usleep_range(10000, 10000);
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07002915 break;
2916 }
2917 return 0;
2918}
2919
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002920static void tabla_get_mbhc_micbias_regs(struct snd_soc_codec *codec,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08002921 struct mbhc_micbias_regs *micbias_regs)
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002922{
2923 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002924 unsigned int cfilt;
2925
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002926 switch (tabla->mbhc_cfg.micbias) {
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002927 case TABLA_MICBIAS1:
2928 cfilt = tabla->pdata->micbias.bias1_cfilt_sel;
2929 micbias_regs->mbhc_reg = TABLA_A_MICB_1_MBHC;
2930 micbias_regs->int_rbias = TABLA_A_MICB_1_INT_RBIAS;
2931 micbias_regs->ctl_reg = TABLA_A_MICB_1_CTL;
2932 break;
2933 case TABLA_MICBIAS2:
2934 cfilt = tabla->pdata->micbias.bias2_cfilt_sel;
2935 micbias_regs->mbhc_reg = TABLA_A_MICB_2_MBHC;
2936 micbias_regs->int_rbias = TABLA_A_MICB_2_INT_RBIAS;
2937 micbias_regs->ctl_reg = TABLA_A_MICB_2_CTL;
2938 break;
2939 case TABLA_MICBIAS3:
2940 cfilt = tabla->pdata->micbias.bias3_cfilt_sel;
2941 micbias_regs->mbhc_reg = TABLA_A_MICB_3_MBHC;
2942 micbias_regs->int_rbias = TABLA_A_MICB_3_INT_RBIAS;
2943 micbias_regs->ctl_reg = TABLA_A_MICB_3_CTL;
2944 break;
2945 case TABLA_MICBIAS4:
2946 cfilt = tabla->pdata->micbias.bias4_cfilt_sel;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08002947 micbias_regs->mbhc_reg = tabla->reg_addr.micb_4_mbhc;
2948 micbias_regs->int_rbias = tabla->reg_addr.micb_4_int_rbias;
2949 micbias_regs->ctl_reg = tabla->reg_addr.micb_4_ctl;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002950 break;
2951 default:
2952 /* Should never reach here */
2953 pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__);
Jordan Crouse239d8412011-11-23 11:47:02 -07002954 return;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002955 }
2956
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002957 micbias_regs->cfilt_sel = cfilt;
2958
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002959 switch (cfilt) {
2960 case TABLA_CFILT1_SEL:
2961 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_1_VAL;
2962 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_1_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08002963 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt1_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002964 break;
2965 case TABLA_CFILT2_SEL:
2966 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_2_VAL;
2967 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_2_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08002968 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt2_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002969 break;
2970 case TABLA_CFILT3_SEL:
2971 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_3_VAL;
2972 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_3_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08002973 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt3_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002974 break;
2975 }
2976}
Santosh Mardie15e2302011-11-15 10:39:23 +05302977static const struct snd_soc_dapm_widget tabla_dapm_i2s_widgets[] = {
2978 SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", TABLA_A_CDC_CLK_RX_I2S_CTL,
2979 4, 0, NULL, 0),
2980 SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", TABLA_A_CDC_CLK_TX_I2S_CTL, 4,
2981 0, NULL, 0),
2982};
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002983
Kiran Kandi8b3a8302011-09-27 16:13:28 -07002984static int tabla_lineout_dac_event(struct snd_soc_dapm_widget *w,
2985 struct snd_kcontrol *kcontrol, int event)
2986{
2987 struct snd_soc_codec *codec = w->codec;
2988
2989 pr_debug("%s %s %d\n", __func__, w->name, event);
2990
2991 switch (event) {
2992 case SND_SOC_DAPM_PRE_PMU:
2993 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
2994 break;
2995
2996 case SND_SOC_DAPM_POST_PMD:
2997 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
2998 break;
2999 }
3000 return 0;
3001}
3002
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003003static const struct snd_soc_dapm_widget tabla_1_x_dapm_widgets[] = {
3004 SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", TABLA_1_A_MICB_4_CTL, 7,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303005 0, tabla_codec_enable_micbias,
3006 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3007 SND_SOC_DAPM_POST_PMD),
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003008};
3009
3010static const struct snd_soc_dapm_widget tabla_2_higher_dapm_widgets[] = {
3011 SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", TABLA_2_A_MICB_4_CTL, 7,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303012 0, tabla_codec_enable_micbias,
3013 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3014 SND_SOC_DAPM_POST_PMD),
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003015};
3016
Santosh Mardie15e2302011-11-15 10:39:23 +05303017static const struct snd_soc_dapm_route audio_i2s_map[] = {
3018 {"RX_I2S_CLK", NULL, "CDC_CONN"},
3019 {"SLIM RX1", NULL, "RX_I2S_CLK"},
3020 {"SLIM RX2", NULL, "RX_I2S_CLK"},
3021 {"SLIM RX3", NULL, "RX_I2S_CLK"},
3022 {"SLIM RX4", NULL, "RX_I2S_CLK"},
3023
3024 {"SLIM TX7", NULL, "TX_I2S_CLK"},
3025 {"SLIM TX8", NULL, "TX_I2S_CLK"},
3026 {"SLIM TX9", NULL, "TX_I2S_CLK"},
3027 {"SLIM TX10", NULL, "TX_I2S_CLK"},
3028};
3029
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003030static const struct snd_soc_dapm_route audio_map[] = {
3031 /* SLIMBUS Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003032
3033 {"SLIM TX1", NULL, "SLIM TX1 MUX"},
3034 {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"},
3035
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003036 {"SLIM TX2", NULL, "SLIM TX2 MUX"},
3037 {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"},
3038
3039 {"SLIM TX3", NULL, "SLIM TX3 MUX"},
3040 {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"},
3041
3042 {"SLIM TX4", NULL, "SLIM TX4 MUX"},
3043 {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"},
3044
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003045 {"SLIM TX5", NULL, "SLIM TX5 MUX"},
3046 {"SLIM TX5 MUX", "DEC5", "DEC5 MUX"},
3047
3048 {"SLIM TX6", NULL, "SLIM TX6 MUX"},
3049 {"SLIM TX6 MUX", "DEC6", "DEC6 MUX"},
3050
3051 {"SLIM TX7", NULL, "SLIM TX7 MUX"},
3052 {"SLIM TX7 MUX", "DEC1", "DEC1 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07003053 {"SLIM TX7 MUX", "DEC2", "DEC2 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003054 {"SLIM TX7 MUX", "DEC3", "DEC3 MUX"},
3055 {"SLIM TX7 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003056 {"SLIM TX7 MUX", "DEC5", "DEC5 MUX"},
3057 {"SLIM TX7 MUX", "DEC6", "DEC6 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07003058 {"SLIM TX7 MUX", "DEC7", "DEC7 MUX"},
3059 {"SLIM TX7 MUX", "DEC8", "DEC8 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003060 {"SLIM TX7 MUX", "DEC9", "DEC9 MUX"},
3061 {"SLIM TX7 MUX", "DEC10", "DEC10 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003062
3063 {"SLIM TX8", NULL, "SLIM TX8 MUX"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003064 {"SLIM TX8 MUX", "DEC1", "DEC1 MUX"},
3065 {"SLIM TX8 MUX", "DEC2", "DEC2 MUX"},
3066 {"SLIM TX8 MUX", "DEC3", "DEC3 MUX"},
Bhalchandra Gajare9ec83cd2011-09-23 17:25:07 -07003067 {"SLIM TX8 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003068 {"SLIM TX8 MUX", "DEC5", "DEC5 MUX"},
3069 {"SLIM TX8 MUX", "DEC6", "DEC6 MUX"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003070 {"SLIM TX8 MUX", "DEC7", "DEC7 MUX"},
3071 {"SLIM TX8 MUX", "DEC8", "DEC8 MUX"},
3072 {"SLIM TX8 MUX", "DEC9", "DEC9 MUX"},
3073 {"SLIM TX8 MUX", "DEC10", "DEC10 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003074
Kiran Kandi3426e512011-09-13 22:50:10 -07003075 {"SLIM TX9", NULL, "SLIM TX9 MUX"},
3076 {"SLIM TX9 MUX", "DEC1", "DEC1 MUX"},
3077 {"SLIM TX9 MUX", "DEC2", "DEC2 MUX"},
3078 {"SLIM TX9 MUX", "DEC3", "DEC3 MUX"},
3079 {"SLIM TX9 MUX", "DEC4", "DEC4 MUX"},
3080 {"SLIM TX9 MUX", "DEC5", "DEC5 MUX"},
3081 {"SLIM TX9 MUX", "DEC6", "DEC6 MUX"},
3082 {"SLIM TX9 MUX", "DEC7", "DEC7 MUX"},
3083 {"SLIM TX9 MUX", "DEC8", "DEC8 MUX"},
3084 {"SLIM TX9 MUX", "DEC9", "DEC9 MUX"},
3085 {"SLIM TX9 MUX", "DEC10", "DEC10 MUX"},
3086
3087 {"SLIM TX10", NULL, "SLIM TX10 MUX"},
3088 {"SLIM TX10 MUX", "DEC1", "DEC1 MUX"},
3089 {"SLIM TX10 MUX", "DEC2", "DEC2 MUX"},
3090 {"SLIM TX10 MUX", "DEC3", "DEC3 MUX"},
3091 {"SLIM TX10 MUX", "DEC4", "DEC4 MUX"},
3092 {"SLIM TX10 MUX", "DEC5", "DEC5 MUX"},
3093 {"SLIM TX10 MUX", "DEC6", "DEC6 MUX"},
3094 {"SLIM TX10 MUX", "DEC7", "DEC7 MUX"},
3095 {"SLIM TX10 MUX", "DEC8", "DEC8 MUX"},
3096 {"SLIM TX10 MUX", "DEC9", "DEC9 MUX"},
3097 {"SLIM TX10 MUX", "DEC10", "DEC10 MUX"},
3098
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003099 /* Earpiece (RX MIX1) */
3100 {"EAR", NULL, "EAR PA"},
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003101 {"EAR PA", NULL, "EAR_PA_MIXER"},
3102 {"EAR_PA_MIXER", NULL, "DAC1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003103 {"DAC1", NULL, "CP"},
3104
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003105 {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"},
3106 {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003107 {"ANC", NULL, "ANC1 FB MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003108
3109 /* Headset (RX MIX1 and RX MIX2) */
3110 {"HEADPHONE", NULL, "HPHL"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003111 {"HEADPHONE", NULL, "HPHR"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003112
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003113 {"HPHL", NULL, "HPHL_PA_MIXER"},
3114 {"HPHL_PA_MIXER", NULL, "HPHL DAC"},
3115
3116 {"HPHR", NULL, "HPHR_PA_MIXER"},
3117 {"HPHR_PA_MIXER", NULL, "HPHR DAC"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003118
3119 {"HPHL DAC", NULL, "CP"},
3120 {"HPHR DAC", NULL, "CP"},
3121
3122 {"ANC", NULL, "ANC1 MUX"},
3123 {"ANC", NULL, "ANC2 MUX"},
3124 {"ANC1 MUX", "ADC1", "ADC1"},
3125 {"ANC1 MUX", "ADC2", "ADC2"},
3126 {"ANC1 MUX", "ADC3", "ADC3"},
3127 {"ANC1 MUX", "ADC4", "ADC4"},
3128 {"ANC2 MUX", "ADC1", "ADC1"},
3129 {"ANC2 MUX", "ADC2", "ADC2"},
3130 {"ANC2 MUX", "ADC3", "ADC3"},
3131 {"ANC2 MUX", "ADC4", "ADC4"},
3132
Bradley Rubine1d08622011-07-20 18:01:35 -07003133 {"ANC", NULL, "CDC_CONN"},
3134
Bradley Rubin229c6a52011-07-12 16:18:48 -07003135 {"DAC1", "Switch", "RX1 CHAIN"},
3136 {"HPHL DAC", "Switch", "RX1 CHAIN"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003137 {"HPHR DAC", NULL, "RX2 CHAIN"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003138
Kiran Kandidb0a4b02011-08-23 09:32:09 -07003139 {"LINEOUT1", NULL, "LINEOUT1 PA"},
3140 {"LINEOUT2", NULL, "LINEOUT2 PA"},
3141 {"LINEOUT3", NULL, "LINEOUT3 PA"},
3142 {"LINEOUT4", NULL, "LINEOUT4 PA"},
3143 {"LINEOUT5", NULL, "LINEOUT5 PA"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003144
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003145 {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"},
3146 {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"},
3147 {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"},
3148 {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"},
3149 {"LINEOUT3 PA", NULL, "LINEOUT3_PA_MIXER"},
3150 {"LINEOUT3_PA_MIXER", NULL, "LINEOUT3 DAC"},
3151 {"LINEOUT4 PA", NULL, "LINEOUT4_PA_MIXER"},
3152 {"LINEOUT4_PA_MIXER", NULL, "LINEOUT4 DAC"},
3153 {"LINEOUT5 PA", NULL, "LINEOUT5_PA_MIXER"},
3154 {"LINEOUT5_PA_MIXER", NULL, "LINEOUT5 DAC"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003155
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003156 {"LINEOUT1 DAC", NULL, "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003157 {"LINEOUT5 DAC", NULL, "RX7 MIX1"},
3158
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003159 {"RX1 CHAIN", NULL, "RX1 MIX2"},
3160 {"RX2 CHAIN", NULL, "RX2 MIX2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003161 {"RX1 CHAIN", NULL, "ANC"},
3162 {"RX2 CHAIN", NULL, "ANC"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003163
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003164 {"CP", NULL, "RX_BIAS"},
3165 {"LINEOUT1 DAC", NULL, "RX_BIAS"},
3166 {"LINEOUT2 DAC", NULL, "RX_BIAS"},
3167 {"LINEOUT3 DAC", NULL, "RX_BIAS"},
3168 {"LINEOUT4 DAC", NULL, "RX_BIAS"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003169 {"LINEOUT5 DAC", NULL, "RX_BIAS"},
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003170
Kuirong Wang0f8ade32012-02-27 16:29:45 -08003171 {"RX1 MIX1", NULL, "COMP1_CLK"},
3172 {"RX2 MIX1", NULL, "COMP1_CLK"},
3173 {"RX3 MIX1", NULL, "COMP2_CLK"},
3174 {"RX5 MIX1", NULL, "COMP2_CLK"},
3175
3176
Bradley Rubin229c6a52011-07-12 16:18:48 -07003177 {"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
3178 {"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
3179 {"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
3180 {"RX2 MIX1", NULL, "RX2 MIX1 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003181 {"RX3 MIX1", NULL, "RX3 MIX1 INP1"},
3182 {"RX3 MIX1", NULL, "RX3 MIX1 INP2"},
3183 {"RX4 MIX1", NULL, "RX4 MIX1 INP1"},
3184 {"RX4 MIX1", NULL, "RX4 MIX1 INP2"},
3185 {"RX5 MIX1", NULL, "RX5 MIX1 INP1"},
3186 {"RX5 MIX1", NULL, "RX5 MIX1 INP2"},
3187 {"RX6 MIX1", NULL, "RX6 MIX1 INP1"},
3188 {"RX6 MIX1", NULL, "RX6 MIX1 INP2"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07003189 {"RX7 MIX1", NULL, "RX7 MIX1 INP1"},
3190 {"RX7 MIX1", NULL, "RX7 MIX1 INP2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003191 {"RX1 MIX2", NULL, "RX1 MIX1"},
3192 {"RX1 MIX2", NULL, "RX1 MIX2 INP1"},
3193 {"RX1 MIX2", NULL, "RX1 MIX2 INP2"},
3194 {"RX2 MIX2", NULL, "RX2 MIX1"},
3195 {"RX2 MIX2", NULL, "RX2 MIX2 INP1"},
3196 {"RX2 MIX2", NULL, "RX2 MIX2 INP2"},
3197 {"RX3 MIX2", NULL, "RX3 MIX1"},
3198 {"RX3 MIX2", NULL, "RX3 MIX2 INP1"},
3199 {"RX3 MIX2", NULL, "RX3 MIX2 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003200
Bradley Rubin229c6a52011-07-12 16:18:48 -07003201 {"RX1 MIX1 INP1", "RX1", "SLIM RX1"},
3202 {"RX1 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303203 {"RX1 MIX1 INP1", "RX3", "SLIM RX3"},
3204 {"RX1 MIX1 INP1", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003205 {"RX1 MIX1 INP1", "RX6", "SLIM RX6"},
3206 {"RX1 MIX1 INP1", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003207 {"RX1 MIX1 INP1", "IIR1", "IIR1"},
3208 {"RX1 MIX1 INP2", "RX1", "SLIM RX1"},
3209 {"RX1 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303210 {"RX1 MIX1 INP2", "RX3", "SLIM RX3"},
3211 {"RX1 MIX1 INP2", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003212 {"RX1 MIX1 INP2", "RX6", "SLIM RX6"},
3213 {"RX1 MIX1 INP2", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003214 {"RX1 MIX1 INP2", "IIR1", "IIR1"},
3215 {"RX2 MIX1 INP1", "RX1", "SLIM RX1"},
3216 {"RX2 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303217 {"RX2 MIX1 INP1", "RX3", "SLIM RX3"},
3218 {"RX2 MIX1 INP1", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003219 {"RX2 MIX1 INP1", "RX6", "SLIM RX6"},
3220 {"RX2 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003221 {"RX2 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003222 {"RX2 MIX1 INP2", "RX1", "SLIM RX1"},
3223 {"RX2 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303224 {"RX2 MIX1 INP2", "RX3", "SLIM RX3"},
3225 {"RX2 MIX1 INP2", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003226 {"RX2 MIX1 INP2", "RX6", "SLIM RX6"},
3227 {"RX2 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003228 {"RX2 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003229 {"RX3 MIX1 INP1", "RX1", "SLIM RX1"},
3230 {"RX3 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303231 {"RX3 MIX1 INP1", "RX3", "SLIM RX3"},
3232 {"RX3 MIX1 INP1", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003233 {"RX3 MIX1 INP1", "RX6", "SLIM RX6"},
3234 {"RX3 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003235 {"RX3 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003236 {"RX3 MIX1 INP2", "RX1", "SLIM RX1"},
3237 {"RX3 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303238 {"RX3 MIX1 INP2", "RX3", "SLIM RX3"},
3239 {"RX3 MIX1 INP2", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003240 {"RX3 MIX1 INP2", "RX6", "SLIM RX6"},
3241 {"RX3 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003242 {"RX3 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003243 {"RX4 MIX1 INP1", "RX1", "SLIM RX1"},
3244 {"RX4 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303245 {"RX4 MIX1 INP1", "RX3", "SLIM RX3"},
3246 {"RX4 MIX1 INP1", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003247 {"RX4 MIX1 INP1", "RX6", "SLIM RX6"},
3248 {"RX4 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003249 {"RX4 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003250 {"RX4 MIX1 INP2", "RX1", "SLIM RX1"},
3251 {"RX4 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303252 {"RX4 MIX1 INP2", "RX3", "SLIM RX3"},
3253 {"RX4 MIX1 INP2", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003254 {"RX4 MIX1 INP2", "RX6", "SLIM RX6"},
3255 {"RX4 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003256 {"RX4 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003257 {"RX5 MIX1 INP1", "RX1", "SLIM RX1"},
3258 {"RX5 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303259 {"RX5 MIX1 INP1", "RX3", "SLIM RX3"},
3260 {"RX5 MIX1 INP1", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003261 {"RX5 MIX1 INP1", "RX6", "SLIM RX6"},
3262 {"RX5 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003263 {"RX5 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003264 {"RX5 MIX1 INP2", "RX1", "SLIM RX1"},
3265 {"RX5 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303266 {"RX5 MIX1 INP2", "RX3", "SLIM RX3"},
3267 {"RX5 MIX1 INP2", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003268 {"RX5 MIX1 INP2", "RX6", "SLIM RX6"},
3269 {"RX5 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003270 {"RX5 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003271 {"RX6 MIX1 INP1", "RX1", "SLIM RX1"},
3272 {"RX6 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303273 {"RX6 MIX1 INP1", "RX3", "SLIM RX3"},
3274 {"RX6 MIX1 INP1", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003275 {"RX6 MIX1 INP1", "RX6", "SLIM RX6"},
3276 {"RX6 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003277 {"RX6 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003278 {"RX6 MIX1 INP2", "RX1", "SLIM RX1"},
3279 {"RX6 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303280 {"RX6 MIX1 INP2", "RX3", "SLIM RX3"},
3281 {"RX6 MIX1 INP2", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003282 {"RX6 MIX1 INP2", "RX6", "SLIM RX6"},
3283 {"RX6 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003284 {"RX6 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07003285 {"RX7 MIX1 INP1", "RX1", "SLIM RX1"},
3286 {"RX7 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303287 {"RX7 MIX1 INP1", "RX3", "SLIM RX3"},
3288 {"RX7 MIX1 INP1", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003289 {"RX7 MIX1 INP1", "RX6", "SLIM RX6"},
3290 {"RX7 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003291 {"RX7 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07003292 {"RX7 MIX1 INP2", "RX1", "SLIM RX1"},
3293 {"RX7 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303294 {"RX7 MIX1 INP2", "RX3", "SLIM RX3"},
3295 {"RX7 MIX1 INP2", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003296 {"RX7 MIX1 INP2", "RX6", "SLIM RX6"},
3297 {"RX7 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003298 {"RX7 MIX1 INP2", "IIR1", "IIR1"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003299 {"RX1 MIX2 INP1", "IIR1", "IIR1"},
3300 {"RX1 MIX2 INP2", "IIR1", "IIR1"},
3301 {"RX2 MIX2 INP1", "IIR1", "IIR1"},
3302 {"RX2 MIX2 INP2", "IIR1", "IIR1"},
3303 {"RX3 MIX2 INP1", "IIR1", "IIR1"},
3304 {"RX3 MIX2 INP2", "IIR1", "IIR1"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003305
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003306 /* Decimator Inputs */
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003307 {"DEC1 MUX", "DMIC1", "DMIC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003308 {"DEC1 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003309 {"DEC1 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003310 {"DEC2 MUX", "DMIC2", "DMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003311 {"DEC2 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003312 {"DEC2 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003313 {"DEC3 MUX", "DMIC3", "DMIC3"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003314 {"DEC3 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003315 {"DEC3 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07003316 {"DEC4 MUX", "DMIC4", "DMIC4"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003317 {"DEC4 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003318 {"DEC4 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07003319 {"DEC5 MUX", "DMIC5", "DMIC5"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003320 {"DEC5 MUX", "ADC2", "ADC2"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003321 {"DEC5 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07003322 {"DEC6 MUX", "DMIC6", "DMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003323 {"DEC6 MUX", "ADC1", "ADC1"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003324 {"DEC6 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003325 {"DEC7 MUX", "DMIC1", "DMIC1"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003326 {"DEC7 MUX", "DMIC6", "DMIC6"},
3327 {"DEC7 MUX", "ADC1", "ADC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003328 {"DEC7 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003329 {"DEC7 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003330 {"DEC8 MUX", "DMIC2", "DMIC2"},
3331 {"DEC8 MUX", "DMIC5", "DMIC5"},
3332 {"DEC8 MUX", "ADC2", "ADC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003333 {"DEC8 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003334 {"DEC8 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003335 {"DEC9 MUX", "DMIC4", "DMIC4"},
3336 {"DEC9 MUX", "DMIC5", "DMIC5"},
3337 {"DEC9 MUX", "ADC2", "ADC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003338 {"DEC9 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003339 {"DEC9 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003340 {"DEC10 MUX", "DMIC3", "DMIC3"},
3341 {"DEC10 MUX", "DMIC6", "DMIC6"},
3342 {"DEC10 MUX", "ADC1", "ADC1"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003343 {"DEC10 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003344 {"DEC10 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003345
3346 /* ADC Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003347 {"ADC1", NULL, "AMIC1"},
3348 {"ADC2", NULL, "AMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003349 {"ADC3", NULL, "AMIC3"},
3350 {"ADC4", NULL, "AMIC4"},
3351 {"ADC5", NULL, "AMIC5"},
3352 {"ADC6", NULL, "AMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003353
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003354 /* AUX PGA Connections */
3355 {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3356 {"HPHL_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3357 {"HPHL_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3358 {"HPHL_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3359 {"HPHR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3360 {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3361 {"HPHR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3362 {"HPHR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3363 {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3364 {"LINEOUT1_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3365 {"LINEOUT1_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3366 {"LINEOUT1_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3367 {"LINEOUT2_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3368 {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3369 {"LINEOUT2_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3370 {"LINEOUT2_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3371 {"LINEOUT3_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3372 {"LINEOUT3_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3373 {"LINEOUT3_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3374 {"LINEOUT3_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3375 {"LINEOUT4_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3376 {"LINEOUT4_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3377 {"LINEOUT4_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3378 {"LINEOUT4_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3379 {"LINEOUT5_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3380 {"LINEOUT5_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3381 {"LINEOUT5_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3382 {"LINEOUT5_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3383 {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3384 {"EAR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3385 {"EAR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3386 {"EAR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3387 {"AUX_PGA_Left", NULL, "AMIC5"},
3388 {"AUX_PGA_Right", NULL, "AMIC6"},
3389
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003390 {"IIR1", NULL, "IIR1 INP1 MUX"},
Patrick Lai16261e82011-09-30 13:25:52 -07003391 {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"},
3392 {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"},
3393 {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"},
3394 {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"},
3395 {"IIR1 INP1 MUX", "DEC5", "DEC5 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003396 {"IIR1 INP1 MUX", "DEC6", "DEC6 MUX"},
Patrick Lai16261e82011-09-30 13:25:52 -07003397 {"IIR1 INP1 MUX", "DEC7", "DEC7 MUX"},
3398 {"IIR1 INP1 MUX", "DEC8", "DEC8 MUX"},
3399 {"IIR1 INP1 MUX", "DEC9", "DEC9 MUX"},
3400 {"IIR1 INP1 MUX", "DEC10", "DEC10 MUX"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003401
3402 {"MIC BIAS1 Internal1", NULL, "LDO_H"},
3403 {"MIC BIAS1 Internal2", NULL, "LDO_H"},
3404 {"MIC BIAS1 External", NULL, "LDO_H"},
3405 {"MIC BIAS2 Internal1", NULL, "LDO_H"},
3406 {"MIC BIAS2 Internal2", NULL, "LDO_H"},
3407 {"MIC BIAS2 Internal3", NULL, "LDO_H"},
3408 {"MIC BIAS2 External", NULL, "LDO_H"},
3409 {"MIC BIAS3 Internal1", NULL, "LDO_H"},
3410 {"MIC BIAS3 Internal2", NULL, "LDO_H"},
3411 {"MIC BIAS3 External", NULL, "LDO_H"},
3412 {"MIC BIAS4 External", NULL, "LDO_H"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003413};
3414
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003415static const struct snd_soc_dapm_route tabla_1_x_lineout_2_to_4_map[] = {
3416
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003417 {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003418 {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"},
3419
3420 {"LINEOUT2 DAC", NULL, "RX4 DSM MUX"},
3421
3422 {"LINEOUT3 DAC", NULL, "RX5 MIX1"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003423 {"LINEOUT3 DAC GROUND", "Switch", "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003424 {"LINEOUT3 DAC", NULL, "LINEOUT3 DAC GROUND"},
3425
3426 {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"},
3427 {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"},
3428
3429 {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"},
3430 {"LINEOUT4 DAC GROUND", "Switch", "RX4 DSM MUX"},
3431 {"LINEOUT4 DAC", NULL, "LINEOUT4 DAC GROUND"},
3432};
3433
Kiran Kandi7a9fd902011-11-14 13:51:45 -08003434
3435static const struct snd_soc_dapm_route tabla_2_x_lineout_2_to_4_map[] = {
3436
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003437 {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"},
Kiran Kandi7a9fd902011-11-14 13:51:45 -08003438 {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"},
3439
3440 {"LINEOUT3 DAC", NULL, "RX4 DSM MUX"},
3441
3442 {"LINEOUT2 DAC", NULL, "RX5 MIX1"},
3443
3444 {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"},
3445 {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"},
3446
3447 {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"},
3448};
3449
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003450static int tabla_readable(struct snd_soc_codec *ssc, unsigned int reg)
3451{
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003452 int i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303453 struct wcd9xxx *tabla_core = dev_get_drvdata(ssc->dev->parent);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003454
3455 if (TABLA_IS_1_X(tabla_core->version)) {
3456 for (i = 0; i < ARRAY_SIZE(tabla_1_reg_readable); i++) {
3457 if (tabla_1_reg_readable[i] == reg)
3458 return 1;
3459 }
3460 } else {
3461 for (i = 0; i < ARRAY_SIZE(tabla_2_reg_readable); i++) {
3462 if (tabla_2_reg_readable[i] == reg)
3463 return 1;
3464 }
3465 }
3466
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003467 return tabla_reg_readable[reg];
3468}
Kuirong Wange9c8a222012-03-28 16:24:09 -07003469static bool tabla_is_digital_gain_register(unsigned int reg)
3470{
3471 bool rtn = false;
3472 switch (reg) {
3473 case TABLA_A_CDC_RX1_VOL_CTL_B2_CTL:
3474 case TABLA_A_CDC_RX2_VOL_CTL_B2_CTL:
3475 case TABLA_A_CDC_RX3_VOL_CTL_B2_CTL:
3476 case TABLA_A_CDC_RX4_VOL_CTL_B2_CTL:
3477 case TABLA_A_CDC_RX5_VOL_CTL_B2_CTL:
3478 case TABLA_A_CDC_RX6_VOL_CTL_B2_CTL:
3479 case TABLA_A_CDC_RX7_VOL_CTL_B2_CTL:
3480 case TABLA_A_CDC_TX1_VOL_CTL_GAIN:
3481 case TABLA_A_CDC_TX2_VOL_CTL_GAIN:
3482 case TABLA_A_CDC_TX3_VOL_CTL_GAIN:
3483 case TABLA_A_CDC_TX4_VOL_CTL_GAIN:
3484 case TABLA_A_CDC_TX5_VOL_CTL_GAIN:
3485 case TABLA_A_CDC_TX6_VOL_CTL_GAIN:
3486 case TABLA_A_CDC_TX7_VOL_CTL_GAIN:
3487 case TABLA_A_CDC_TX8_VOL_CTL_GAIN:
3488 case TABLA_A_CDC_TX9_VOL_CTL_GAIN:
3489 case TABLA_A_CDC_TX10_VOL_CTL_GAIN:
3490 rtn = true;
3491 break;
3492 default:
3493 break;
3494 }
3495 return rtn;
3496}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003497static int tabla_volatile(struct snd_soc_codec *ssc, unsigned int reg)
3498{
3499 /* Registers lower than 0x100 are top level registers which can be
3500 * written by the Tabla core driver.
3501 */
3502
3503 if ((reg >= TABLA_A_CDC_MBHC_EN_CTL) || (reg < 0x100))
3504 return 1;
3505
Ben Romberger1f045a72011-11-04 10:14:57 -07003506 /* IIR Coeff registers are not cacheable */
3507 if ((reg >= TABLA_A_CDC_IIR1_COEF_B1_CTL) &&
3508 (reg <= TABLA_A_CDC_IIR2_COEF_B5_CTL))
3509 return 1;
3510
Kuirong Wange9c8a222012-03-28 16:24:09 -07003511 /* Digital gain register is not cacheable so we have to write
3512 * the setting even it is the same
3513 */
3514 if (tabla_is_digital_gain_register(reg))
3515 return 1;
3516
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003517 return 0;
3518}
3519
3520#define TABLA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
3521static int tabla_write(struct snd_soc_codec *codec, unsigned int reg,
3522 unsigned int value)
3523{
3524 int ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003525 BUG_ON(reg > TABLA_MAX_REGISTER);
3526
3527 if (!tabla_volatile(codec, reg)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003528 ret = snd_soc_cache_write(codec, reg, value);
3529 if (ret != 0)
3530 dev_err(codec->dev, "Cache write to %x failed: %d\n",
3531 reg, ret);
3532 }
3533
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303534 return wcd9xxx_reg_write(codec->control_data, reg, value);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003535}
3536static unsigned int tabla_read(struct snd_soc_codec *codec,
3537 unsigned int reg)
3538{
3539 unsigned int val;
3540 int ret;
3541
3542 BUG_ON(reg > TABLA_MAX_REGISTER);
3543
3544 if (!tabla_volatile(codec, reg) && tabla_readable(codec, reg) &&
3545 reg < codec->driver->reg_cache_size) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003546 ret = snd_soc_cache_read(codec, reg, &val);
3547 if (ret >= 0) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003548 return val;
3549 } else
3550 dev_err(codec->dev, "Cache read from %x failed: %d\n",
3551 reg, ret);
3552 }
3553
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303554 val = wcd9xxx_reg_read(codec->control_data, reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003555 return val;
3556}
3557
Joonwoo Parkcf473b42012-03-29 19:48:16 -07003558static s16 tabla_get_current_v_ins(struct tabla_priv *tabla, bool hu)
3559{
3560 s16 v_ins;
3561 if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) &&
3562 tabla->mbhc_micbias_switched)
3563 v_ins = hu ? (s16)tabla->mbhc_data.adj_v_ins_hu :
3564 (s16)tabla->mbhc_data.adj_v_ins_h;
3565 else
3566 v_ins = hu ? (s16)tabla->mbhc_data.v_ins_hu :
3567 (s16)tabla->mbhc_data.v_ins_h;
3568 return v_ins;
3569}
3570
3571static s16 tabla_get_current_v_hs_max(struct tabla_priv *tabla)
3572{
3573 s16 v_hs_max;
3574 struct tabla_mbhc_plug_type_cfg *plug_type;
3575
3576 plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
3577 if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) &&
3578 tabla->mbhc_micbias_switched)
3579 v_hs_max = tabla->mbhc_data.adj_v_hs_max;
3580 else
3581 v_hs_max = plug_type->v_hs_max;
3582 return v_hs_max;
3583}
3584
Bradley Rubincb1e2732011-06-23 16:49:20 -07003585static void tabla_codec_calibrate_hs_polling(struct snd_soc_codec *codec)
3586{
Joonwoo Parkc0672392012-01-11 11:03:14 -08003587 u8 *n_ready, *n_cic;
Joonwoo Park0976d012011-12-22 11:48:18 -08003588 struct tabla_mbhc_btn_detect_cfg *btn_det;
3589 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07003590 const s16 v_ins_hu = tabla_get_current_v_ins(tabla, true);
3591
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003592 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003593
Joonwoo Park0976d012011-12-22 11:48:18 -08003594 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07003595 v_ins_hu & 0xFF);
Joonwoo Park0976d012011-12-22 11:48:18 -08003596 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07003597 (v_ins_hu >> 8) & 0xFF);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003598
Joonwoo Park0976d012011-12-22 11:48:18 -08003599 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL,
3600 tabla->mbhc_data.v_b1_hu & 0xFF);
3601 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL,
3602 (tabla->mbhc_data.v_b1_hu >> 8) & 0xFF);
3603
3604 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL,
3605 tabla->mbhc_data.v_b1_h & 0xFF);
3606 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL,
3607 (tabla->mbhc_data.v_b1_h >> 8) & 0xFF);
3608
3609 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B9_CTL,
3610 tabla->mbhc_data.v_brh & 0xFF);
3611 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B10_CTL,
3612 (tabla->mbhc_data.v_brh >> 8) & 0xFF);
3613
3614 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B11_CTL,
3615 tabla->mbhc_data.v_brl & 0xFF);
3616 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B12_CTL,
3617 (tabla->mbhc_data.v_brl >> 8) & 0xFF);
3618
Joonwoo Parkc0672392012-01-11 11:03:14 -08003619 n_ready = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_READY);
Joonwoo Park0976d012011-12-22 11:48:18 -08003620 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL,
Joonwoo Parkc0672392012-01-11 11:03:14 -08003621 n_ready[tabla_codec_mclk_index(tabla)]);
Joonwoo Park0976d012011-12-22 11:48:18 -08003622 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B2_CTL,
3623 tabla->mbhc_data.npoll);
3624 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B3_CTL,
3625 tabla->mbhc_data.nbounce_wait);
Joonwoo Park0976d012011-12-22 11:48:18 -08003626 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
Joonwoo Park107edf02012-01-11 11:42:24 -08003627 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL,
3628 n_cic[tabla_codec_mclk_index(tabla)]);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003629}
3630
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003631static int tabla_startup(struct snd_pcm_substream *substream,
3632 struct snd_soc_dai *dai)
3633{
Kuirong Wanga545e722012-02-06 19:12:54 -08003634 struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003635 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
3636 substream->name, substream->stream);
Kuirong Wanga545e722012-02-06 19:12:54 -08003637 if ((tabla_core != NULL) &&
3638 (tabla_core->dev != NULL) &&
3639 (tabla_core->dev->parent != NULL))
3640 pm_runtime_get_sync(tabla_core->dev->parent);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003641
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003642 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003643}
3644
3645static void tabla_shutdown(struct snd_pcm_substream *substream,
3646 struct snd_soc_dai *dai)
3647{
Kuirong Wanga545e722012-02-06 19:12:54 -08003648 struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003649 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
3650 substream->name, substream->stream);
Kuirong Wanga545e722012-02-06 19:12:54 -08003651 if ((tabla_core != NULL) &&
3652 (tabla_core->dev != NULL) &&
3653 (tabla_core->dev->parent != NULL)) {
3654 pm_runtime_mark_last_busy(tabla_core->dev->parent);
3655 pm_runtime_put(tabla_core->dev->parent);
3656 }
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003657}
3658
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003659int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, bool dapm)
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003660{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003661 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3662
Joonwoo Parkcf473b42012-03-29 19:48:16 -07003663 pr_debug("%s: mclk_enable = %u, dapm = %d\n", __func__, mclk_enable,
3664 dapm);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003665 if (dapm)
3666 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003667 if (mclk_enable) {
3668 tabla->mclk_enabled = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003669
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003670 if (tabla->mbhc_polling_active && (tabla->mclk_enabled)) {
Bradley Rubincb1e2732011-06-23 16:49:20 -07003671 tabla_codec_pause_hs_polling(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003672 tabla_codec_enable_bandgap(codec,
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003673 TABLA_BANDGAP_AUDIO_MODE);
3674 tabla_codec_enable_clock_block(codec, 0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003675 tabla_codec_calibrate_hs_polling(codec);
3676 tabla_codec_start_hs_polling(codec);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05303677 } else {
3678 tabla_codec_enable_bandgap(codec,
3679 TABLA_BANDGAP_AUDIO_MODE);
3680 tabla_codec_enable_clock_block(codec, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003681 }
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003682 } else {
3683
3684 if (!tabla->mclk_enabled) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003685 if (dapm)
3686 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003687 pr_err("Error, MCLK already diabled\n");
3688 return -EINVAL;
3689 }
3690 tabla->mclk_enabled = false;
3691
3692 if (tabla->mbhc_polling_active) {
3693 if (!tabla->mclk_enabled) {
3694 tabla_codec_pause_hs_polling(codec);
3695 tabla_codec_enable_bandgap(codec,
3696 TABLA_BANDGAP_MBHC_MODE);
3697 tabla_enable_rx_bias(codec, 1);
3698 tabla_codec_enable_clock_block(codec, 1);
3699 tabla_codec_calibrate_hs_polling(codec);
3700 tabla_codec_start_hs_polling(codec);
3701 }
3702 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1,
3703 0x05, 0x01);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05303704 } else {
3705 tabla_codec_disable_clock_block(codec);
3706 tabla_codec_enable_bandgap(codec,
3707 TABLA_BANDGAP_OFF);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003708 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003709 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003710 if (dapm)
3711 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003712 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003713}
3714
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003715static int tabla_set_dai_sysclk(struct snd_soc_dai *dai,
3716 int clk_id, unsigned int freq, int dir)
3717{
3718 pr_debug("%s\n", __func__);
3719 return 0;
3720}
3721
3722static int tabla_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3723{
Santosh Mardie15e2302011-11-15 10:39:23 +05303724 u8 val = 0;
3725 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
3726
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003727 pr_debug("%s\n", __func__);
Santosh Mardie15e2302011-11-15 10:39:23 +05303728 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
3729 case SND_SOC_DAIFMT_CBS_CFS:
3730 /* CPU is master */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303731 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003732 if (dai->id == AIF1_CAP)
Santosh Mardie15e2302011-11-15 10:39:23 +05303733 snd_soc_update_bits(dai->codec,
3734 TABLA_A_CDC_CLK_TX_I2S_CTL,
3735 TABLA_I2S_MASTER_MODE_MASK, 0);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003736 else if (dai->id == AIF1_PB)
Santosh Mardie15e2302011-11-15 10:39:23 +05303737 snd_soc_update_bits(dai->codec,
3738 TABLA_A_CDC_CLK_RX_I2S_CTL,
3739 TABLA_I2S_MASTER_MODE_MASK, 0);
3740 }
3741 break;
3742 case SND_SOC_DAIFMT_CBM_CFM:
3743 /* CPU is slave */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303744 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05303745 val = TABLA_I2S_MASTER_MODE_MASK;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003746 if (dai->id == AIF1_CAP)
Santosh Mardie15e2302011-11-15 10:39:23 +05303747 snd_soc_update_bits(dai->codec,
3748 TABLA_A_CDC_CLK_TX_I2S_CTL, val, val);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003749 else if (dai->id == AIF1_PB)
Santosh Mardie15e2302011-11-15 10:39:23 +05303750 snd_soc_update_bits(dai->codec,
3751 TABLA_A_CDC_CLK_RX_I2S_CTL, val, val);
3752 }
3753 break;
3754 default:
3755 return -EINVAL;
3756 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003757 return 0;
3758}
3759
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003760static int tabla_set_channel_map(struct snd_soc_dai *dai,
3761 unsigned int tx_num, unsigned int *tx_slot,
3762 unsigned int rx_num, unsigned int *rx_slot)
3763
3764{
3765 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
3766 u32 i = 0;
3767 if (!tx_slot && !rx_slot) {
3768 pr_err("%s: Invalid\n", __func__);
3769 return -EINVAL;
3770 }
3771 pr_debug("%s: DAI-ID %x %d %d\n", __func__, dai->id, tx_num, rx_num);
3772
Neema Shettyd3a89262012-02-16 10:23:50 -08003773 if (dai->id == AIF1_PB || dai->id == AIF2_PB) {
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003774 for (i = 0; i < rx_num; i++) {
3775 tabla->dai[dai->id - 1].ch_num[i] = rx_slot[i];
3776 tabla->dai[dai->id - 1].ch_act = 0;
3777 tabla->dai[dai->id - 1].ch_tot = rx_num;
3778 }
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003779 } else if (dai->id == AIF1_CAP || dai->id == AIF2_CAP) {
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003780 for (i = 0; i < tx_num; i++) {
3781 tabla->dai[dai->id - 1].ch_num[i] = tx_slot[i];
3782 tabla->dai[dai->id - 1].ch_act = 0;
3783 tabla->dai[dai->id - 1].ch_tot = tx_num;
3784 }
3785 }
3786 return 0;
3787}
3788
3789static int tabla_get_channel_map(struct snd_soc_dai *dai,
3790 unsigned int *tx_num, unsigned int *tx_slot,
3791 unsigned int *rx_num, unsigned int *rx_slot)
3792
3793{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303794 struct wcd9xxx *tabla = dev_get_drvdata(dai->codec->control_data);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003795
3796 u32 cnt = 0;
3797 u32 tx_ch[SLIM_MAX_TX_PORTS];
3798 u32 rx_ch[SLIM_MAX_RX_PORTS];
3799
3800 if (!rx_slot && !tx_slot) {
3801 pr_err("%s: Invalid\n", __func__);
3802 return -EINVAL;
3803 }
3804 pr_debug("%s: DAI-ID %x\n", __func__, dai->id);
3805 /* for virtual port, codec driver needs to do
3806 * housekeeping, for now should be ok
3807 */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303808 wcd9xxx_get_channel(tabla, rx_ch, tx_ch);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003809 if (dai->id == AIF1_PB) {
3810 *rx_num = tabla_dai[dai->id - 1].playback.channels_max;
3811 while (cnt < *rx_num) {
3812 rx_slot[cnt] = rx_ch[cnt];
3813 cnt++;
3814 }
3815 } else if (dai->id == AIF1_CAP) {
3816 *tx_num = tabla_dai[dai->id - 1].capture.channels_max;
3817 while (cnt < *tx_num) {
3818 tx_slot[cnt] = tx_ch[6 + cnt];
3819 cnt++;
3820 }
Neema Shettyd3a89262012-02-16 10:23:50 -08003821 } else if (dai->id == AIF2_PB) {
3822 *rx_num = tabla_dai[dai->id - 1].playback.channels_max;
3823 while (cnt < *rx_num) {
3824 rx_slot[cnt] = rx_ch[5 + cnt];
3825 cnt++;
3826 }
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003827 } else if (dai->id == AIF2_CAP) {
3828 *tx_num = tabla_dai[dai->id - 1].capture.channels_max;
3829 tx_slot[0] = tx_ch[cnt];
3830 tx_slot[1] = tx_ch[1 + cnt];
3831 tx_slot[2] = tx_ch[3 + cnt];
3832 tx_slot[3] = tx_ch[5 + cnt];
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003833 }
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003834
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003835 return 0;
3836}
3837
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003838static int tabla_hw_params(struct snd_pcm_substream *substream,
3839 struct snd_pcm_hw_params *params,
3840 struct snd_soc_dai *dai)
3841{
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003842 struct snd_soc_codec *codec = dai->codec;
Santosh Mardie15e2302011-11-15 10:39:23 +05303843 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
Bhalchandra Gajare038bf3a2011-09-02 15:32:30 -07003844 u8 path, shift;
3845 u16 tx_fs_reg, rx_fs_reg;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003846 u8 tx_fs_rate, rx_fs_rate, rx_state, tx_state;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08003847 u32 compander_fs;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003848
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003849 pr_debug("%s: DAI-ID %x rate %d\n", __func__, dai->id,
3850 params_rate(params));
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003851
3852 switch (params_rate(params)) {
3853 case 8000:
3854 tx_fs_rate = 0x00;
3855 rx_fs_rate = 0x00;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08003856 compander_fs = COMPANDER_FS_8KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003857 break;
3858 case 16000:
3859 tx_fs_rate = 0x01;
3860 rx_fs_rate = 0x20;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08003861 compander_fs = COMPANDER_FS_16KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003862 break;
3863 case 32000:
3864 tx_fs_rate = 0x02;
3865 rx_fs_rate = 0x40;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08003866 compander_fs = COMPANDER_FS_32KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003867 break;
3868 case 48000:
3869 tx_fs_rate = 0x03;
3870 rx_fs_rate = 0x60;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08003871 compander_fs = COMPANDER_FS_48KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003872 break;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003873 case 96000:
3874 tx_fs_rate = 0x04;
3875 rx_fs_rate = 0x80;
3876 compander_fs = COMPANDER_FS_96KHZ;
3877 break;
3878 case 192000:
3879 tx_fs_rate = 0x05;
3880 rx_fs_rate = 0xA0;
3881 compander_fs = COMPANDER_FS_192KHZ;
3882 break;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003883 default:
3884 pr_err("%s: Invalid sampling rate %d\n", __func__,
3885 params_rate(params));
3886 return -EINVAL;
3887 }
3888
3889
3890 /**
3891 * If current dai is a tx dai, set sample rate to
3892 * all the txfe paths that are currently not active
3893 */
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003894 if ((dai->id == AIF1_CAP) || (dai->id == AIF2_CAP)) {
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003895
3896 tx_state = snd_soc_read(codec,
3897 TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL);
3898
3899 for (path = 1, shift = 0;
3900 path <= NUM_DECIMATORS; path++, shift++) {
3901
3902 if (path == BITS_PER_REG + 1) {
3903 shift = 0;
3904 tx_state = snd_soc_read(codec,
3905 TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL);
3906 }
3907
3908 if (!(tx_state & (1 << shift))) {
3909 tx_fs_reg = TABLA_A_CDC_TX1_CLK_FS_CTL
3910 + (BITS_PER_REG*(path-1));
3911 snd_soc_update_bits(codec, tx_fs_reg,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003912 0x07, tx_fs_rate);
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003913 }
3914 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303915 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05303916 switch (params_format(params)) {
3917 case SNDRV_PCM_FORMAT_S16_LE:
3918 snd_soc_update_bits(codec,
3919 TABLA_A_CDC_CLK_TX_I2S_CTL,
3920 0x20, 0x20);
3921 break;
3922 case SNDRV_PCM_FORMAT_S32_LE:
3923 snd_soc_update_bits(codec,
3924 TABLA_A_CDC_CLK_TX_I2S_CTL,
3925 0x20, 0x00);
3926 break;
3927 default:
3928 pr_err("invalid format\n");
3929 break;
3930 }
3931 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_TX_I2S_CTL,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003932 0x07, tx_fs_rate);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003933 } else {
3934 tabla->dai[dai->id - 1].rate = params_rate(params);
Santosh Mardie15e2302011-11-15 10:39:23 +05303935 }
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003936 }
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003937 /**
3938 * TODO: Need to handle case where same RX chain takes 2 or more inputs
3939 * with varying sample rates
3940 */
3941
3942 /**
3943 * If current dai is a rx dai, set sample rate to
3944 * all the rx paths that are currently not active
3945 */
Neema Shettyd3a89262012-02-16 10:23:50 -08003946 if (dai->id == AIF1_PB || dai->id == AIF2_PB) {
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003947
3948 rx_state = snd_soc_read(codec,
3949 TABLA_A_CDC_CLK_RX_B1_CTL);
3950
3951 for (path = 1, shift = 0;
3952 path <= NUM_INTERPOLATORS; path++, shift++) {
3953
3954 if (!(rx_state & (1 << shift))) {
3955 rx_fs_reg = TABLA_A_CDC_RX1_B5_CTL
3956 + (BITS_PER_REG*(path-1));
3957 snd_soc_update_bits(codec, rx_fs_reg,
3958 0xE0, rx_fs_rate);
Kuirong Wang0f8ade32012-02-27 16:29:45 -08003959 if (comp_rx_path[shift] < COMPANDER_MAX)
3960 tabla->comp_fs[comp_rx_path[shift]]
3961 = compander_fs;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003962 }
3963 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303964 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05303965 switch (params_format(params)) {
3966 case SNDRV_PCM_FORMAT_S16_LE:
3967 snd_soc_update_bits(codec,
3968 TABLA_A_CDC_CLK_RX_I2S_CTL,
3969 0x20, 0x20);
3970 break;
3971 case SNDRV_PCM_FORMAT_S32_LE:
3972 snd_soc_update_bits(codec,
3973 TABLA_A_CDC_CLK_RX_I2S_CTL,
3974 0x20, 0x00);
3975 break;
3976 default:
3977 pr_err("invalid format\n");
3978 break;
3979 }
3980 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_I2S_CTL,
3981 0x03, (rx_fs_rate >> 0x05));
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003982 } else {
3983 tabla->dai[dai->id - 1].rate = params_rate(params);
Santosh Mardie15e2302011-11-15 10:39:23 +05303984 }
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07003985 }
3986
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003987 return 0;
3988}
3989
3990static struct snd_soc_dai_ops tabla_dai_ops = {
3991 .startup = tabla_startup,
3992 .shutdown = tabla_shutdown,
3993 .hw_params = tabla_hw_params,
3994 .set_sysclk = tabla_set_dai_sysclk,
3995 .set_fmt = tabla_set_dai_fmt,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003996 .set_channel_map = tabla_set_channel_map,
3997 .get_channel_map = tabla_get_channel_map,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003998};
3999
4000static struct snd_soc_dai_driver tabla_dai[] = {
4001 {
4002 .name = "tabla_rx1",
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004003 .id = AIF1_PB,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004004 .playback = {
4005 .stream_name = "AIF1 Playback",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004006 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004007 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004008 .rate_max = 192000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004009 .rate_min = 8000,
4010 .channels_min = 1,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004011 .channels_max = 2,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004012 },
4013 .ops = &tabla_dai_ops,
4014 },
4015 {
4016 .name = "tabla_tx1",
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004017 .id = AIF1_CAP,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004018 .capture = {
4019 .stream_name = "AIF1 Capture",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004020 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004021 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004022 .rate_max = 192000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004023 .rate_min = 8000,
4024 .channels_min = 1,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004025 .channels_max = 4,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004026 },
4027 .ops = &tabla_dai_ops,
4028 },
Neema Shettyd3a89262012-02-16 10:23:50 -08004029 {
4030 .name = "tabla_rx2",
4031 .id = AIF2_PB,
4032 .playback = {
4033 .stream_name = "AIF2 Playback",
4034 .rates = WCD9310_RATES,
4035 .formats = TABLA_FORMATS,
4036 .rate_min = 8000,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004037 .rate_max = 192000,
Neema Shettyd3a89262012-02-16 10:23:50 -08004038 .channels_min = 1,
4039 .channels_max = 2,
4040 },
4041 .ops = &tabla_dai_ops,
4042 },
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004043 {
4044 .name = "tabla_tx2",
4045 .id = AIF2_CAP,
4046 .capture = {
4047 .stream_name = "AIF2 Capture",
4048 .rates = WCD9310_RATES,
4049 .formats = TABLA_FORMATS,
4050 .rate_max = 192000,
4051 .rate_min = 8000,
4052 .channels_min = 1,
4053 .channels_max = 4,
4054 },
4055 .ops = &tabla_dai_ops,
4056 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004057};
Santosh Mardie15e2302011-11-15 10:39:23 +05304058
4059static struct snd_soc_dai_driver tabla_i2s_dai[] = {
4060 {
4061 .name = "tabla_i2s_rx1",
4062 .id = 1,
4063 .playback = {
4064 .stream_name = "AIF1 Playback",
4065 .rates = WCD9310_RATES,
4066 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004067 .rate_max = 192000,
Santosh Mardie15e2302011-11-15 10:39:23 +05304068 .rate_min = 8000,
4069 .channels_min = 1,
4070 .channels_max = 4,
4071 },
4072 .ops = &tabla_dai_ops,
4073 },
4074 {
4075 .name = "tabla_i2s_tx1",
4076 .id = 2,
4077 .capture = {
4078 .stream_name = "AIF1 Capture",
4079 .rates = WCD9310_RATES,
4080 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004081 .rate_max = 192000,
Santosh Mardie15e2302011-11-15 10:39:23 +05304082 .rate_min = 8000,
4083 .channels_min = 1,
4084 .channels_max = 4,
4085 },
4086 .ops = &tabla_dai_ops,
4087 },
4088};
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004089
4090static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
4091 struct snd_kcontrol *kcontrol, int event)
4092{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304093 struct wcd9xxx *tabla;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004094 struct snd_soc_codec *codec = w->codec;
4095 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
4096 u32 j = 0;
4097 u32 ret = 0;
4098 codec->control_data = dev_get_drvdata(codec->dev->parent);
4099 tabla = codec->control_data;
4100 /* Execute the callback only if interface type is slimbus */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304101 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004102 return 0;
4103 switch (event) {
4104 case SND_SOC_DAPM_POST_PMU:
4105 for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) {
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004106 if ((tabla_dai[j].id == AIF1_CAP) ||
4107 (tabla_dai[j].id == AIF2_CAP))
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004108 continue;
4109 if (!strncmp(w->sname,
4110 tabla_dai[j].playback.stream_name, 13)) {
4111 ++tabla_p->dai[j].ch_act;
4112 break;
4113 }
4114 }
4115 if (tabla_p->dai[j].ch_act == tabla_p->dai[j].ch_tot)
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304116 ret = wcd9xxx_cfg_slim_sch_rx(tabla,
4117 tabla_p->dai[j].ch_num,
4118 tabla_p->dai[j].ch_tot,
4119 tabla_p->dai[j].rate);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004120 break;
4121 case SND_SOC_DAPM_POST_PMD:
4122 for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) {
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004123 if ((tabla_dai[j].id == AIF1_CAP) ||
4124 (tabla_dai[j].id == AIF2_CAP))
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004125 continue;
4126 if (!strncmp(w->sname,
4127 tabla_dai[j].playback.stream_name, 13)) {
4128 --tabla_p->dai[j].ch_act;
4129 break;
4130 }
4131 }
4132 if (!tabla_p->dai[j].ch_act) {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304133 ret = wcd9xxx_close_slim_sch_rx(tabla,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004134 tabla_p->dai[j].ch_num,
4135 tabla_p->dai[j].ch_tot);
Bharath Ramachandramurthyda6fa7a2012-03-30 14:35:32 -07004136 usleep_range(5000, 5000);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004137 tabla_p->dai[j].rate = 0;
4138 memset(tabla_p->dai[j].ch_num, 0, (sizeof(u32)*
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304139 tabla_p->dai[j].ch_tot));
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004140 tabla_p->dai[j].ch_tot = 0;
4141 }
4142 }
4143 return ret;
4144}
4145
4146static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
4147 struct snd_kcontrol *kcontrol, int event)
4148{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304149 struct wcd9xxx *tabla;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004150 struct snd_soc_codec *codec = w->codec;
4151 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
4152 /* index to the DAI ID, for now hardcoding */
4153 u32 j = 0;
4154 u32 ret = 0;
4155
4156 codec->control_data = dev_get_drvdata(codec->dev->parent);
4157 tabla = codec->control_data;
4158
4159 /* Execute the callback only if interface type is slimbus */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304160 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004161 return 0;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004162
4163 pr_debug("%s(): %s %d\n", __func__, w->name, event);
4164
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004165 switch (event) {
4166 case SND_SOC_DAPM_POST_PMU:
4167 for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) {
Neema Shettyd3a89262012-02-16 10:23:50 -08004168 if (tabla_dai[j].id == AIF1_PB ||
4169 tabla_dai[j].id == AIF2_PB)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004170 continue;
4171 if (!strncmp(w->sname,
4172 tabla_dai[j].capture.stream_name, 13)) {
4173 ++tabla_p->dai[j].ch_act;
4174 break;
4175 }
4176 }
4177 if (tabla_p->dai[j].ch_act == tabla_p->dai[j].ch_tot)
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304178 ret = wcd9xxx_cfg_slim_sch_tx(tabla,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004179 tabla_p->dai[j].ch_num,
4180 tabla_p->dai[j].ch_tot,
4181 tabla_p->dai[j].rate);
4182 break;
4183 case SND_SOC_DAPM_POST_PMD:
4184 for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) {
Neema Shettyd3a89262012-02-16 10:23:50 -08004185 if (tabla_dai[j].id == AIF1_PB ||
4186 tabla_dai[j].id == AIF2_PB)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004187 continue;
4188 if (!strncmp(w->sname,
4189 tabla_dai[j].capture.stream_name, 13)) {
4190 --tabla_p->dai[j].ch_act;
4191 break;
4192 }
4193 }
4194 if (!tabla_p->dai[j].ch_act) {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304195 ret = wcd9xxx_close_slim_sch_tx(tabla,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004196 tabla_p->dai[j].ch_num,
4197 tabla_p->dai[j].ch_tot);
4198 tabla_p->dai[j].rate = 0;
4199 memset(tabla_p->dai[j].ch_num, 0, (sizeof(u32)*
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304200 tabla_p->dai[j].ch_tot));
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004201 tabla_p->dai[j].ch_tot = 0;
4202 }
4203 }
4204 return ret;
4205}
4206
4207/* Todo: Have seperate dapm widgets for I2S and Slimbus.
4208 * Might Need to have callbacks registered only for slimbus
4209 */
4210static const struct snd_soc_dapm_widget tabla_dapm_widgets[] = {
4211 /*RX stuff */
4212 SND_SOC_DAPM_OUTPUT("EAR"),
4213
4214 SND_SOC_DAPM_PGA("EAR PA", TABLA_A_RX_EAR_EN, 4, 0, NULL, 0),
4215
4216 SND_SOC_DAPM_MIXER("DAC1", TABLA_A_RX_EAR_EN, 6, 0, dac1_switch,
4217 ARRAY_SIZE(dac1_switch)),
4218
4219 SND_SOC_DAPM_AIF_IN_E("SLIM RX1", "AIF1 Playback", 0, SND_SOC_NOPM, 0,
4220 0, tabla_codec_enable_slimrx,
4221 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4222 SND_SOC_DAPM_AIF_IN_E("SLIM RX2", "AIF1 Playback", 0, SND_SOC_NOPM, 0,
4223 0, tabla_codec_enable_slimrx,
4224 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4225
4226 SND_SOC_DAPM_AIF_IN("SLIM RX3", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
4227 SND_SOC_DAPM_AIF_IN("SLIM RX4", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
4228
Neema Shettyd3a89262012-02-16 10:23:50 -08004229 SND_SOC_DAPM_AIF_IN_E("SLIM RX6", "AIF2 Playback", 0, SND_SOC_NOPM, 0,
4230 0, tabla_codec_enable_slimrx,
4231 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4232 SND_SOC_DAPM_AIF_IN_E("SLIM RX7", "AIF2 Playback", 0, SND_SOC_NOPM, 0,
4233 0, tabla_codec_enable_slimrx,
4234 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4235
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004236 /* Headphone */
4237 SND_SOC_DAPM_OUTPUT("HEADPHONE"),
4238 SND_SOC_DAPM_PGA_E("HPHL", TABLA_A_RX_HPH_CNP_EN, 5, 0, NULL, 0,
4239 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
4240 SND_SOC_DAPM_POST_PMD),
4241 SND_SOC_DAPM_MIXER("HPHL DAC", TABLA_A_RX_HPH_L_DAC_CTL, 7, 0,
4242 hphl_switch, ARRAY_SIZE(hphl_switch)),
4243
4244 SND_SOC_DAPM_PGA_E("HPHR", TABLA_A_RX_HPH_CNP_EN, 4, 0, NULL, 0,
4245 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
4246 SND_SOC_DAPM_POST_PMD),
4247
4248 SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TABLA_A_RX_HPH_R_DAC_CTL, 7, 0,
4249 tabla_hphr_dac_event,
4250 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4251
4252 /* Speaker */
4253 SND_SOC_DAPM_OUTPUT("LINEOUT1"),
4254 SND_SOC_DAPM_OUTPUT("LINEOUT2"),
4255 SND_SOC_DAPM_OUTPUT("LINEOUT3"),
4256 SND_SOC_DAPM_OUTPUT("LINEOUT4"),
4257 SND_SOC_DAPM_OUTPUT("LINEOUT5"),
4258
4259 SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TABLA_A_RX_LINE_CNP_EN, 0, 0, NULL,
4260 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4261 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4262 SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TABLA_A_RX_LINE_CNP_EN, 1, 0, NULL,
4263 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4264 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4265 SND_SOC_DAPM_PGA_E("LINEOUT3 PA", TABLA_A_RX_LINE_CNP_EN, 2, 0, NULL,
4266 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4267 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4268 SND_SOC_DAPM_PGA_E("LINEOUT4 PA", TABLA_A_RX_LINE_CNP_EN, 3, 0, NULL,
4269 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4270 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4271 SND_SOC_DAPM_PGA_E("LINEOUT5 PA", TABLA_A_RX_LINE_CNP_EN, 4, 0, NULL, 0,
4272 tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4273 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4274
4275 SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TABLA_A_RX_LINE_1_DAC_CTL, 7, 0
4276 , tabla_lineout_dac_event,
4277 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4278 SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TABLA_A_RX_LINE_2_DAC_CTL, 7, 0
4279 , tabla_lineout_dac_event,
4280 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4281 SND_SOC_DAPM_DAC_E("LINEOUT3 DAC", NULL, TABLA_A_RX_LINE_3_DAC_CTL, 7, 0
4282 , tabla_lineout_dac_event,
4283 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4284 SND_SOC_DAPM_SWITCH("LINEOUT3 DAC GROUND", SND_SOC_NOPM, 0, 0,
4285 &lineout3_ground_switch),
4286 SND_SOC_DAPM_DAC_E("LINEOUT4 DAC", NULL, TABLA_A_RX_LINE_4_DAC_CTL, 7, 0
4287 , tabla_lineout_dac_event,
4288 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4289 SND_SOC_DAPM_SWITCH("LINEOUT4 DAC GROUND", SND_SOC_NOPM, 0, 0,
4290 &lineout4_ground_switch),
4291 SND_SOC_DAPM_DAC_E("LINEOUT5 DAC", NULL, TABLA_A_RX_LINE_5_DAC_CTL, 7, 0
4292 , tabla_lineout_dac_event,
4293 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4294
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004295 SND_SOC_DAPM_MIXER_E("RX1 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004296 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4297 SND_SOC_DAPM_POST_PMU),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004298 SND_SOC_DAPM_MIXER_E("RX2 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004299 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4300 SND_SOC_DAPM_POST_PMU),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004301 SND_SOC_DAPM_MIXER_E("RX3 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004302 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4303 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004304 SND_SOC_DAPM_MIXER_E("RX4 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004305 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4306 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004307 SND_SOC_DAPM_MIXER_E("RX5 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 4, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004308 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4309 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004310 SND_SOC_DAPM_MIXER_E("RX6 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004311 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4312 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004313 SND_SOC_DAPM_MIXER_E("RX7 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 6, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004314 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4315 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004316
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004317 SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4318 SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4319 SND_SOC_DAPM_MIXER("RX3 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4320
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004321 SND_SOC_DAPM_MUX_E("RX4 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0,
4322 &rx4_dsm_mux, tabla_codec_reset_interpolator,
4323 SND_SOC_DAPM_PRE_PMU),
4324
4325 SND_SOC_DAPM_MUX_E("RX6 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0,
4326 &rx6_dsm_mux, tabla_codec_reset_interpolator,
4327 SND_SOC_DAPM_PRE_PMU),
4328
4329 SND_SOC_DAPM_MIXER("RX1 CHAIN", TABLA_A_CDC_RX1_B6_CTL, 5, 0, NULL, 0),
4330 SND_SOC_DAPM_MIXER("RX2 CHAIN", TABLA_A_CDC_RX2_B6_CTL, 5, 0, NULL, 0),
4331
4332 SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4333 &rx_mix1_inp1_mux),
4334 SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4335 &rx_mix1_inp2_mux),
4336 SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4337 &rx2_mix1_inp1_mux),
4338 SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4339 &rx2_mix1_inp2_mux),
4340 SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4341 &rx3_mix1_inp1_mux),
4342 SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4343 &rx3_mix1_inp2_mux),
4344 SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4345 &rx4_mix1_inp1_mux),
4346 SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4347 &rx4_mix1_inp2_mux),
4348 SND_SOC_DAPM_MUX("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4349 &rx5_mix1_inp1_mux),
4350 SND_SOC_DAPM_MUX("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4351 &rx5_mix1_inp2_mux),
4352 SND_SOC_DAPM_MUX("RX6 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4353 &rx6_mix1_inp1_mux),
4354 SND_SOC_DAPM_MUX("RX6 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4355 &rx6_mix1_inp2_mux),
4356 SND_SOC_DAPM_MUX("RX7 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4357 &rx7_mix1_inp1_mux),
4358 SND_SOC_DAPM_MUX("RX7 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4359 &rx7_mix1_inp2_mux),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004360 SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0,
4361 &rx1_mix2_inp1_mux),
4362 SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0,
4363 &rx1_mix2_inp2_mux),
4364 SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0,
4365 &rx2_mix2_inp1_mux),
4366 SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0,
4367 &rx2_mix2_inp2_mux),
4368 SND_SOC_DAPM_MUX("RX3 MIX2 INP1", SND_SOC_NOPM, 0, 0,
4369 &rx3_mix2_inp1_mux),
4370 SND_SOC_DAPM_MUX("RX3 MIX2 INP2", SND_SOC_NOPM, 0, 0,
4371 &rx3_mix2_inp2_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004372
4373 SND_SOC_DAPM_SUPPLY("CP", TABLA_A_CP_EN, 0, 0,
4374 tabla_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU |
4375 SND_SOC_DAPM_PRE_PMD),
4376
4377 SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
4378 tabla_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
4379 SND_SOC_DAPM_POST_PMD),
4380
4381 /* TX */
4382
4383 SND_SOC_DAPM_SUPPLY("CDC_CONN", TABLA_A_CDC_CLK_OTHR_CTL, 2, 0, NULL,
4384 0),
4385
4386 SND_SOC_DAPM_SUPPLY("LDO_H", TABLA_A_LDO_H_MODE_1, 7, 0,
4387 tabla_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU),
4388
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004389 SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 0, 0,
4390 tabla_config_compander, SND_SOC_DAPM_PRE_PMU |
4391 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
4392 SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 1, 0,
4393 tabla_config_compander, SND_SOC_DAPM_PRE_PMU |
4394 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
4395
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004396 SND_SOC_DAPM_INPUT("AMIC1"),
4397 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", TABLA_A_MICB_1_CTL, 7, 0,
4398 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4399 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4400 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", TABLA_A_MICB_1_CTL, 7, 0,
4401 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4402 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4403 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", TABLA_A_MICB_1_CTL, 7, 0,
4404 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4405 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4406 SND_SOC_DAPM_ADC_E("ADC1", NULL, TABLA_A_TX_1_2_EN, 7, 0,
4407 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4408 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4409
4410 SND_SOC_DAPM_INPUT("AMIC3"),
4411 SND_SOC_DAPM_ADC_E("ADC3", NULL, TABLA_A_TX_3_4_EN, 7, 0,
4412 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4413 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4414
4415 SND_SOC_DAPM_INPUT("AMIC4"),
4416 SND_SOC_DAPM_ADC_E("ADC4", NULL, TABLA_A_TX_3_4_EN, 3, 0,
4417 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4418 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4419
4420 SND_SOC_DAPM_INPUT("AMIC5"),
4421 SND_SOC_DAPM_ADC_E("ADC5", NULL, TABLA_A_TX_5_6_EN, 7, 0,
4422 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
4423
4424 SND_SOC_DAPM_INPUT("AMIC6"),
4425 SND_SOC_DAPM_ADC_E("ADC6", NULL, TABLA_A_TX_5_6_EN, 3, 0,
4426 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
4427
4428 SND_SOC_DAPM_MUX_E("DEC1 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0, 0,
Kiran Kandid8cf5212012-03-02 15:34:53 -08004429 &dec1_mux, tabla_codec_enable_dec,
4430 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4431 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004432
4433 SND_SOC_DAPM_MUX_E("DEC2 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 1, 0,
Kiran Kandid8cf5212012-03-02 15:34:53 -08004434 &dec2_mux, tabla_codec_enable_dec,
4435 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4436 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004437
4438 SND_SOC_DAPM_MUX_E("DEC3 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 2, 0,
Kiran Kandid8cf5212012-03-02 15:34:53 -08004439 &dec3_mux, tabla_codec_enable_dec,
4440 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4441 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004442
4443 SND_SOC_DAPM_MUX_E("DEC4 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 3, 0,
Kiran Kandid8cf5212012-03-02 15:34:53 -08004444 &dec4_mux, tabla_codec_enable_dec,
4445 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4446 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004447
4448 SND_SOC_DAPM_MUX_E("DEC5 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 4, 0,
Kiran Kandid8cf5212012-03-02 15:34:53 -08004449 &dec5_mux, tabla_codec_enable_dec,
4450 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4451 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004452
4453 SND_SOC_DAPM_MUX_E("DEC6 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 5, 0,
Kiran Kandid8cf5212012-03-02 15:34:53 -08004454 &dec6_mux, tabla_codec_enable_dec,
4455 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4456 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004457
4458 SND_SOC_DAPM_MUX_E("DEC7 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 6, 0,
Kiran Kandid8cf5212012-03-02 15:34:53 -08004459 &dec7_mux, tabla_codec_enable_dec,
4460 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4461 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004462
4463 SND_SOC_DAPM_MUX_E("DEC8 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 7, 0,
Kiran Kandid8cf5212012-03-02 15:34:53 -08004464 &dec8_mux, tabla_codec_enable_dec,
4465 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4466 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004467
4468 SND_SOC_DAPM_MUX_E("DEC9 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL, 0, 0,
Kiran Kandid8cf5212012-03-02 15:34:53 -08004469 &dec9_mux, tabla_codec_enable_dec,
4470 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4471 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004472
4473 SND_SOC_DAPM_MUX_E("DEC10 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL, 1, 0,
Kiran Kandid8cf5212012-03-02 15:34:53 -08004474 &dec10_mux, tabla_codec_enable_dec,
4475 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4476 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004477
4478 SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux),
4479 SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux),
4480
4481 SND_SOC_DAPM_MIXER_E("ANC", SND_SOC_NOPM, 0, 0, NULL, 0,
4482 tabla_codec_enable_anc, SND_SOC_DAPM_PRE_PMU |
4483 SND_SOC_DAPM_POST_PMD),
4484
4485 SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux),
4486
4487 SND_SOC_DAPM_INPUT("AMIC2"),
4488 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", TABLA_A_MICB_2_CTL, 7, 0,
4489 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4490 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4491 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", TABLA_A_MICB_2_CTL, 7, 0,
4492 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4493 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4494 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", TABLA_A_MICB_2_CTL, 7, 0,
4495 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4496 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4497 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", TABLA_A_MICB_2_CTL, 7, 0,
4498 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4499 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4500 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", TABLA_A_MICB_3_CTL, 7, 0,
4501 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4502 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4503 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", TABLA_A_MICB_3_CTL, 7, 0,
4504 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4505 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4506 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", TABLA_A_MICB_3_CTL, 7, 0,
4507 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4508 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4509 SND_SOC_DAPM_ADC_E("ADC2", NULL, TABLA_A_TX_1_2_EN, 3, 0,
4510 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4511 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4512
4513 SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, 0, 0, &sb_tx1_mux),
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004514 SND_SOC_DAPM_AIF_OUT_E("SLIM TX1", "AIF2 Capture", 0, SND_SOC_NOPM, 0,
4515 0, tabla_codec_enable_slimtx,
4516 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4517
4518 SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, 0, 0, &sb_tx2_mux),
4519 SND_SOC_DAPM_AIF_OUT_E("SLIM TX2", "AIF2 Capture", 0, SND_SOC_NOPM, 0,
4520 0, tabla_codec_enable_slimtx,
4521 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4522
4523 SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, 0, 0, &sb_tx3_mux),
4524 SND_SOC_DAPM_AIF_OUT_E("SLIM TX3", "AIF1 Capture", 0, SND_SOC_NOPM, 0,
4525 0, tabla_codec_enable_slimtx,
4526 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4527
4528 SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, 0, 0, &sb_tx4_mux),
4529 SND_SOC_DAPM_AIF_OUT_E("SLIM TX4", "AIF2 Capture", 0, SND_SOC_NOPM, 0,
4530 0, tabla_codec_enable_slimtx,
4531 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004532
4533 SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, 0, 0, &sb_tx5_mux),
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004534 SND_SOC_DAPM_AIF_OUT_E("SLIM TX5", "AIF1 Capture", 0, SND_SOC_NOPM, 0,
4535 0, tabla_codec_enable_slimtx,
4536 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004537
4538 SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, 0, 0, &sb_tx6_mux),
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004539 SND_SOC_DAPM_AIF_OUT_E("SLIM TX6", "AIF2 Capture", 0, SND_SOC_NOPM, 0,
4540 0, tabla_codec_enable_slimtx,
4541 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004542
4543 SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, 0, 0, &sb_tx7_mux),
4544 SND_SOC_DAPM_AIF_OUT_E("SLIM TX7", "AIF1 Capture", 0, SND_SOC_NOPM, 0,
4545 0, tabla_codec_enable_slimtx,
4546 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4547
4548 SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, 0, 0, &sb_tx8_mux),
4549 SND_SOC_DAPM_AIF_OUT_E("SLIM TX8", "AIF1 Capture", 0, SND_SOC_NOPM, 0,
4550 0, tabla_codec_enable_slimtx,
4551 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4552
4553 SND_SOC_DAPM_MUX("SLIM TX9 MUX", SND_SOC_NOPM, 0, 0, &sb_tx9_mux),
4554 SND_SOC_DAPM_AIF_OUT_E("SLIM TX9", "AIF1 Capture", NULL, SND_SOC_NOPM,
4555 0, 0, tabla_codec_enable_slimtx,
4556 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4557
4558 SND_SOC_DAPM_MUX("SLIM TX10 MUX", SND_SOC_NOPM, 0, 0, &sb_tx10_mux),
4559 SND_SOC_DAPM_AIF_OUT_E("SLIM TX10", "AIF1 Capture", NULL, SND_SOC_NOPM,
4560 0, 0, tabla_codec_enable_slimtx,
4561 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4562
4563 /* Digital Mic Inputs */
4564 SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
4565 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4566 SND_SOC_DAPM_POST_PMD),
4567
4568 SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
4569 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4570 SND_SOC_DAPM_POST_PMD),
4571
4572 SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0,
4573 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4574 SND_SOC_DAPM_POST_PMD),
4575
4576 SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0,
4577 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4578 SND_SOC_DAPM_POST_PMD),
4579
4580 SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0,
4581 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4582 SND_SOC_DAPM_POST_PMD),
4583 SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 0,
4584 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4585 SND_SOC_DAPM_POST_PMD),
4586
4587 /* Sidetone */
4588 SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux),
4589 SND_SOC_DAPM_PGA("IIR1", TABLA_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0),
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08004590
4591 /* AUX PGA */
4592 SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TABLA_A_AUX_L_EN, 7, 0,
4593 tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
4594 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
4595 SND_SOC_DAPM_POST_PMD),
4596
4597 SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TABLA_A_AUX_R_EN, 7, 0,
4598 tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
4599 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
4600 SND_SOC_DAPM_POST_PMD),
4601
4602 /* Lineout, ear and HPH PA Mixers */
4603 SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0,
4604 hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)),
4605
4606 SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0,
4607 hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)),
4608
4609 SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0,
4610 lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)),
4611
4612 SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0,
4613 lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)),
4614
4615 SND_SOC_DAPM_MIXER("LINEOUT3_PA_MIXER", SND_SOC_NOPM, 0, 0,
4616 lineout3_pa_mix, ARRAY_SIZE(lineout3_pa_mix)),
4617
4618 SND_SOC_DAPM_MIXER("LINEOUT4_PA_MIXER", SND_SOC_NOPM, 0, 0,
4619 lineout4_pa_mix, ARRAY_SIZE(lineout4_pa_mix)),
4620
4621 SND_SOC_DAPM_MIXER("LINEOUT5_PA_MIXER", SND_SOC_NOPM, 0, 0,
4622 lineout5_pa_mix, ARRAY_SIZE(lineout5_pa_mix)),
4623
4624 SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0,
4625 ear_pa_mix, ARRAY_SIZE(ear_pa_mix)),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004626};
4627
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004628static short tabla_codec_read_sta_result(struct snd_soc_codec *codec)
Bradley Rubincb1e2732011-06-23 16:49:20 -07004629{
4630 u8 bias_msb, bias_lsb;
4631 short bias_value;
4632
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004633 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B3_STATUS);
4634 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B2_STATUS);
4635 bias_value = (bias_msb << 8) | bias_lsb;
4636 return bias_value;
4637}
4638
4639static short tabla_codec_read_dce_result(struct snd_soc_codec *codec)
4640{
4641 u8 bias_msb, bias_lsb;
4642 short bias_value;
4643
4644 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B5_STATUS);
4645 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B4_STATUS);
4646 bias_value = (bias_msb << 8) | bias_lsb;
4647 return bias_value;
4648}
4649
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004650static void tabla_turn_onoff_rel_detection(struct snd_soc_codec *codec, bool on)
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004651{
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004652 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, on << 1);
4653}
4654
4655static short __tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce,
4656 bool override_bypass, bool noreldetection)
4657{
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004658 short bias_value;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004659 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
4660
4661 wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
4662 if (noreldetection)
4663 tabla_turn_onoff_rel_detection(codec, false);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004664
Joonwoo Park925914c2012-01-05 13:35:18 -08004665 /* Turn on the override */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004666 if (!override_bypass)
4667 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x4, 0x4);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004668 if (dce) {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004669 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
4670 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
4671 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
Joonwoo Park433149a2012-01-11 09:53:54 -08004672 usleep_range(tabla->mbhc_data.t_sta_dce,
4673 tabla->mbhc_data.t_sta_dce);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004674 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
Joonwoo Park0976d012011-12-22 11:48:18 -08004675 usleep_range(tabla->mbhc_data.t_dce,
4676 tabla->mbhc_data.t_dce);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004677 bias_value = tabla_codec_read_dce_result(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004678 } else {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004679 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004680 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
4681 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
Joonwoo Park433149a2012-01-11 09:53:54 -08004682 usleep_range(tabla->mbhc_data.t_sta_dce,
4683 tabla->mbhc_data.t_sta_dce);
Joonwoo Park0976d012011-12-22 11:48:18 -08004684 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
4685 usleep_range(tabla->mbhc_data.t_sta,
4686 tabla->mbhc_data.t_sta);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004687 bias_value = tabla_codec_read_sta_result(codec);
4688 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
4689 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004690 }
Joonwoo Park925914c2012-01-05 13:35:18 -08004691 /* Turn off the override after measuring mic voltage */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004692 if (!override_bypass)
4693 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00);
4694
4695 if (noreldetection)
4696 tabla_turn_onoff_rel_detection(codec, true);
4697 wcd9xxx_enable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004698
Bradley Rubincb1e2732011-06-23 16:49:20 -07004699 return bias_value;
4700}
4701
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004702static short tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce,
4703 bool norel)
4704{
4705 return __tabla_codec_sta_dce(codec, dce, false, norel);
4706}
4707
4708/* called only from interrupt which is under codec_resource_lock acquisition */
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07004709static short tabla_codec_setup_hs_polling(struct snd_soc_codec *codec)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004710{
4711 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07004712 short bias_value;
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08004713 u8 cfilt_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004714
Joonwoo Parkcf473b42012-03-29 19:48:16 -07004715 pr_debug("%s: enter, mclk_enabled %d\n", __func__, tabla->mclk_enabled);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004716 if (!tabla->mbhc_cfg.calibration) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004717 pr_err("Error, no tabla calibration\n");
Bradley Rubincb1e2732011-06-23 16:49:20 -07004718 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004719 }
4720
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004721 if (!tabla->mclk_enabled) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004722 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_MBHC_MODE);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004723 tabla_enable_rx_bias(codec, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004724 tabla_codec_enable_clock_block(codec, 1);
4725 }
4726
4727 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x01);
4728
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08004729 /* Make sure CFILT is in fast mode, save current mode */
Joonwoo Parkf4267c22012-01-10 13:25:24 -08004730 cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl);
4731 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x70, 0x00);
Patrick Lai3043fba2011-08-01 14:15:57 -07004732
Joonwoo Parkf4267c22012-01-10 13:25:24 -08004733 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x1F, 0x16);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004734
4735 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004736 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004737
4738 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x80);
4739 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x1F, 0x1C);
4740 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x40, 0x40);
4741
4742 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004743 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
4744 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004745
Joonwoo Park925914c2012-01-05 13:35:18 -08004746 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x2, 0x2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004747 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
4748
Bradley Rubincb1e2732011-06-23 16:49:20 -07004749 tabla_codec_calibrate_hs_polling(codec);
4750
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004751 /* don't flip override */
4752 bias_value = __tabla_codec_sta_dce(codec, 1, true, true);
Joonwoo Park0976d012011-12-22 11:48:18 -08004753 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40,
4754 cfilt_mode);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004755 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004756
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07004757 return bias_value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004758}
4759
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004760static int tabla_cancel_btn_work(struct tabla_priv *tabla)
4761{
4762 int r = 0;
4763 struct wcd9xxx *core = dev_get_drvdata(tabla->codec->dev->parent);
4764
4765 if (cancel_delayed_work_sync(&tabla->mbhc_btn_dwork)) {
4766 /* if scheduled mbhc_btn_dwork is canceled from here,
4767 * we have to unlock from here instead btn_work */
4768 wcd9xxx_unlock_sleep(core);
4769 r = 1;
4770 }
4771 return r;
4772}
4773
4774/* called under codec_resource_lock acquisition */
4775void tabla_set_and_turnoff_hph_padac(struct snd_soc_codec *codec)
Joonwoo Park03324832012-03-19 19:36:16 -07004776{
4777 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004778 u8 wg_time;
4779
4780 wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ;
4781 wg_time += 1;
Joonwoo Park03324832012-03-19 19:36:16 -07004782
4783 /* If headphone PA is on, check if userspace receives
4784 * removal event to sync-up PA's state */
4785 if (tabla_is_hph_pa_on(codec)) {
4786 pr_debug("%s PA is on, setting PA_OFF_ACK\n", __func__);
4787 set_bit(TABLA_HPHL_PA_OFF_ACK, &tabla->hph_pa_dac_state);
4788 set_bit(TABLA_HPHR_PA_OFF_ACK, &tabla->hph_pa_dac_state);
4789 } else {
4790 pr_debug("%s PA is off\n", __func__);
4791 }
4792
4793 if (tabla_is_hph_dac_on(codec, 1))
4794 set_bit(TABLA_HPHL_DAC_OFF_ACK, &tabla->hph_pa_dac_state);
4795 if (tabla_is_hph_dac_on(codec, 0))
4796 set_bit(TABLA_HPHR_DAC_OFF_ACK, &tabla->hph_pa_dac_state);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004797
4798 snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00);
4799 snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_DAC_CTL,
4800 0xC0, 0x00);
4801 snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_DAC_CTL,
4802 0xC0, 0x00);
4803 usleep_range(wg_time * 1000, wg_time * 1000);
4804}
4805
4806static void tabla_clr_and_turnon_hph_padac(struct tabla_priv *tabla)
4807{
4808 bool pa_turned_on = false;
4809 struct snd_soc_codec *codec = tabla->codec;
4810 u8 wg_time;
4811
4812 wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ;
4813 wg_time += 1;
4814
4815 if (test_and_clear_bit(TABLA_HPHR_DAC_OFF_ACK,
4816 &tabla->hph_pa_dac_state)) {
4817 pr_debug("%s: HPHR clear flag and enable DAC\n", __func__);
4818 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_R_DAC_CTL,
4819 0xC0, 0xC0);
4820 }
4821 if (test_and_clear_bit(TABLA_HPHL_DAC_OFF_ACK,
4822 &tabla->hph_pa_dac_state)) {
4823 pr_debug("%s: HPHL clear flag and enable DAC\n", __func__);
4824 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_L_DAC_CTL,
4825 0xC0, 0xC0);
4826 }
4827
4828 if (test_and_clear_bit(TABLA_HPHR_PA_OFF_ACK,
4829 &tabla->hph_pa_dac_state)) {
4830 pr_debug("%s: HPHR clear flag and enable PA\n", __func__);
4831 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x10,
4832 1 << 4);
4833 pa_turned_on = true;
4834 }
4835 if (test_and_clear_bit(TABLA_HPHL_PA_OFF_ACK,
4836 &tabla->hph_pa_dac_state)) {
4837 pr_debug("%s: HPHL clear flag and enable PA\n", __func__);
4838 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x20,
4839 1 << 5);
4840 pa_turned_on = true;
4841 }
4842
4843 if (pa_turned_on) {
4844 pr_debug("%s: PA was turned off by MBHC and not by DAPM\n",
4845 __func__);
4846 usleep_range(wg_time * 1000, wg_time * 1000);
4847 }
4848}
4849
4850/* called under codec_resource_lock acquisition */
4851static void tabla_codec_report_plug(struct snd_soc_codec *codec, int insertion,
4852 enum snd_jack_types jack_type)
4853{
4854 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
4855
4856 if (!insertion) {
4857 /* Report removal */
4858 tabla->hph_status &= ~jack_type;
4859 if (tabla->mbhc_cfg.headset_jack) {
4860 /* cancel possibly scheduled btn work and
4861 * report release if we reported button press */
4862 if (tabla_cancel_btn_work(tabla)) {
4863 pr_debug("%s: button press is canceled\n",
4864 __func__);
4865 } else if (tabla->buttons_pressed) {
4866 pr_debug("%s: Reporting release for reported "
4867 "button press %d\n", __func__,
4868 jack_type);
4869 tabla_snd_soc_jack_report(tabla,
4870 tabla->mbhc_cfg.button_jack, 0,
4871 tabla->buttons_pressed);
4872 tabla->buttons_pressed &=
4873 ~TABLA_JACK_BUTTON_MASK;
4874 }
4875 pr_debug("%s: Reporting removal %d\n", __func__,
4876 jack_type);
4877 tabla_snd_soc_jack_report(tabla,
4878 tabla->mbhc_cfg.headset_jack,
4879 tabla->hph_status,
4880 TABLA_JACK_MASK);
4881 }
4882 tabla_set_and_turnoff_hph_padac(codec);
4883 hphocp_off_report(tabla, SND_JACK_OC_HPHR,
4884 TABLA_IRQ_HPH_PA_OCPR_FAULT);
4885 hphocp_off_report(tabla, SND_JACK_OC_HPHL,
4886 TABLA_IRQ_HPH_PA_OCPL_FAULT);
4887 tabla->current_plug = PLUG_TYPE_NONE;
4888 tabla->mbhc_polling_active = false;
4889 } else {
4890 /* Report insertion */
4891 tabla->hph_status |= jack_type;
4892
4893 if (jack_type == SND_JACK_HEADPHONE)
4894 tabla->current_plug = PLUG_TYPE_HEADPHONE;
4895 else if (jack_type == SND_JACK_HEADSET) {
4896 tabla->mbhc_polling_active = true;
4897 tabla->current_plug = PLUG_TYPE_HEADSET;
4898 }
4899 if (tabla->mbhc_cfg.headset_jack) {
4900 pr_debug("%s: Reporting insertion %d\n", __func__,
4901 jack_type);
4902 tabla_snd_soc_jack_report(tabla,
4903 tabla->mbhc_cfg.headset_jack,
4904 tabla->hph_status,
4905 TABLA_JACK_MASK);
4906 }
4907 tabla_clr_and_turnon_hph_padac(tabla);
4908 }
Joonwoo Park03324832012-03-19 19:36:16 -07004909}
4910
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004911static int tabla_codec_enable_hs_detect(struct snd_soc_codec *codec,
Joonwoo Park03324832012-03-19 19:36:16 -07004912 int insertion, int trigger,
4913 bool padac_off)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004914{
4915 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004916 int central_bias_enabled = 0;
Joonwoo Park0976d012011-12-22 11:48:18 -08004917 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004918 TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08004919 const struct tabla_mbhc_plug_detect_cfg *plug_det =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004920 TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004921
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004922 if (!tabla->mbhc_cfg.calibration) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004923 pr_err("Error, no tabla calibration\n");
4924 return -EINVAL;
4925 }
4926
4927 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0);
4928
Joonwoo Park03324832012-03-19 19:36:16 -07004929 /* Make sure mic bias and Mic line schmitt trigger
4930 * are turned OFF
4931 */
4932 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01);
4933 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
4934
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07004935 if (insertion) {
Joonwoo Park03324832012-03-19 19:36:16 -07004936 tabla_codec_switch_micbias(codec, 0);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07004937
Joonwoo Park03324832012-03-19 19:36:16 -07004938 /* DAPM can manipulate PA/DAC bits concurrently */
4939 if (padac_off == true) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004940 tabla_set_and_turnoff_hph_padac(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07004941 }
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07004942
Joonwoo Parkcf473b42012-03-29 19:48:16 -07004943 if (trigger & MBHC_USE_HPHL_TRIGGER) {
Joonwoo Park03324832012-03-19 19:36:16 -07004944 /* Enable HPH Schmitt Trigger */
4945 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x11,
4946 0x11);
4947 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x0C,
4948 plug_det->hph_current << 2);
4949 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x02,
4950 0x02);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07004951 }
4952 if (trigger & MBHC_USE_MB_TRIGGER) {
Joonwoo Park03324832012-03-19 19:36:16 -07004953 /* enable the mic line schmitt trigger */
4954 snd_soc_update_bits(codec,
4955 tabla->mbhc_bias_regs.mbhc_reg,
4956 0x60, plug_det->mic_current << 5);
4957 snd_soc_update_bits(codec,
4958 tabla->mbhc_bias_regs.mbhc_reg,
4959 0x80, 0x80);
4960 usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid);
4961 snd_soc_update_bits(codec,
4962 tabla->mbhc_bias_regs.ctl_reg, 0x01,
4963 0x00);
4964 snd_soc_update_bits(codec,
4965 tabla->mbhc_bias_regs.mbhc_reg,
4966 0x10, 0x10);
4967 }
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07004968
4969 /* setup for insetion detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004970 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07004971 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07004972 pr_debug("setup for removal detection\n");
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07004973 /* Make sure the HPH schmitt trigger is OFF */
4974 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x12, 0x00);
4975
4976 /* enable the mic line schmitt trigger */
Joonwoo Park03324832012-03-19 19:36:16 -07004977 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg,
4978 0x01, 0x00);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07004979 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x60,
Joonwoo Park0976d012011-12-22 11:48:18 -08004980 plug_det->mic_current << 5);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07004981 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
4982 0x80, 0x80);
Joonwoo Park0976d012011-12-22 11:48:18 -08004983 usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07004984 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
4985 0x10, 0x10);
4986
4987 /* Setup for low power removal detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004988 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0x2);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07004989 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004990
4991 if (snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x4) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004992 /* called called by interrupt */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004993 if (!(tabla->clock_active)) {
4994 tabla_codec_enable_config_mode(codec, 1);
4995 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07004996 0x06, 0);
Joonwoo Park0976d012011-12-22 11:48:18 -08004997 usleep_range(generic->t_shutdown_plug_rem,
4998 generic->t_shutdown_plug_rem);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004999 tabla_codec_enable_config_mode(codec, 0);
5000 } else
5001 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07005002 0x06, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005003 }
5004
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07005005 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.int_rbias, 0x80, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005006
5007 /* If central bandgap disabled */
5008 if (!(snd_soc_read(codec, TABLA_A_PIN_CTL_OE1) & 1)) {
5009 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x3, 0x3);
Joonwoo Park0976d012011-12-22 11:48:18 -08005010 usleep_range(generic->t_bg_fast_settle,
5011 generic->t_bg_fast_settle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005012 central_bias_enabled = 1;
5013 }
5014
5015 /* If LDO_H disabled */
5016 if (snd_soc_read(codec, TABLA_A_PIN_CTL_OE0) & 0x80) {
5017 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x10, 0);
5018 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0x80);
Joonwoo Park0976d012011-12-22 11:48:18 -08005019 usleep_range(generic->t_ldoh, generic->t_ldoh);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005020 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0);
5021
5022 if (central_bias_enabled)
5023 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x1, 0);
5024 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005025
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08005026 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x3,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005027 tabla->mbhc_cfg.micbias);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005028
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305029 wcd9xxx_enable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005030 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0x1);
5031 return 0;
5032}
5033
Joonwoo Park0976d012011-12-22 11:48:18 -08005034static u16 tabla_codec_v_sta_dce(struct snd_soc_codec *codec, bool dce,
5035 s16 vin_mv)
5036{
Joonwoo Park0976d012011-12-22 11:48:18 -08005037 struct tabla_priv *tabla;
Joonwoo Park03324832012-03-19 19:36:16 -07005038 s16 diff, zero;
Joonwoo Park0976d012011-12-22 11:48:18 -08005039 u32 mb_mv, in;
Joonwoo Park03324832012-03-19 19:36:16 -07005040 u16 value;
Joonwoo Park0976d012011-12-22 11:48:18 -08005041
5042 tabla = snd_soc_codec_get_drvdata(codec);
5043 mb_mv = tabla->mbhc_data.micb_mv;
5044
5045 if (mb_mv == 0) {
5046 pr_err("%s: Mic Bias voltage is set to zero\n", __func__);
5047 return -EINVAL;
5048 }
5049
5050 if (dce) {
Joonwoo Park03324832012-03-19 19:36:16 -07005051 diff = (tabla->mbhc_data.dce_mb) - (tabla->mbhc_data.dce_z);
5052 zero = (tabla->mbhc_data.dce_z);
Joonwoo Park0976d012011-12-22 11:48:18 -08005053 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07005054 diff = (tabla->mbhc_data.sta_mb) - (tabla->mbhc_data.sta_z);
5055 zero = (tabla->mbhc_data.sta_z);
Joonwoo Park0976d012011-12-22 11:48:18 -08005056 }
5057 in = (u32) diff * vin_mv;
5058
Joonwoo Park03324832012-03-19 19:36:16 -07005059 value = (u16) (in / mb_mv) + zero;
5060 return value;
Joonwoo Park0976d012011-12-22 11:48:18 -08005061}
5062
5063static s32 tabla_codec_sta_dce_v(struct snd_soc_codec *codec, s8 dce,
5064 u16 bias_value)
5065{
5066 struct tabla_priv *tabla;
Joonwoo Park03324832012-03-19 19:36:16 -07005067 s16 value, z, mb;
Joonwoo Park0976d012011-12-22 11:48:18 -08005068 s32 mv;
5069
5070 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07005071 value = bias_value;
Joonwoo Park0976d012011-12-22 11:48:18 -08005072 if (dce) {
Joonwoo Park03324832012-03-19 19:36:16 -07005073 z = (tabla->mbhc_data.dce_z);
5074 mb = (tabla->mbhc_data.dce_mb);
5075 mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z);
Joonwoo Park0976d012011-12-22 11:48:18 -08005076 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07005077 z = (tabla->mbhc_data.sta_z);
5078 mb = (tabla->mbhc_data.sta_mb);
5079 mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z);
Joonwoo Park0976d012011-12-22 11:48:18 -08005080 }
5081
5082 return mv;
5083}
5084
Joonwoo Park03324832012-03-19 19:36:16 -07005085static void btn_lpress_fn(struct work_struct *work)
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005086{
5087 struct delayed_work *delayed_work;
5088 struct tabla_priv *tabla;
Joonwoo Park0976d012011-12-22 11:48:18 -08005089 short bias_value;
5090 int dce_mv, sta_mv;
Joonwoo Park03324832012-03-19 19:36:16 -07005091 struct wcd9xxx *core;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005092
5093 pr_debug("%s:\n", __func__);
5094
5095 delayed_work = to_delayed_work(work);
Joonwoo Park03324832012-03-19 19:36:16 -07005096 tabla = container_of(delayed_work, struct tabla_priv, mbhc_btn_dwork);
Joonwoo Park816b8e62012-01-23 16:03:21 -08005097 core = dev_get_drvdata(tabla->codec->dev->parent);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005098
5099 if (tabla) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005100 if (tabla->mbhc_cfg.button_jack) {
Joonwoo Park0976d012011-12-22 11:48:18 -08005101 bias_value = tabla_codec_read_sta_result(tabla->codec);
5102 sta_mv = tabla_codec_sta_dce_v(tabla->codec, 0,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305103 bias_value);
Joonwoo Park0976d012011-12-22 11:48:18 -08005104 bias_value = tabla_codec_read_dce_result(tabla->codec);
5105 dce_mv = tabla_codec_sta_dce_v(tabla->codec, 1,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305106 bias_value);
Joonwoo Park0976d012011-12-22 11:48:18 -08005107 pr_debug("%s: Reporting long button press event"
5108 " STA: %d, DCE: %d\n", __func__,
5109 sta_mv, dce_mv);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005110 tabla_snd_soc_jack_report(tabla,
5111 tabla->mbhc_cfg.button_jack,
Joonwoo Park03324832012-03-19 19:36:16 -07005112 tabla->buttons_pressed,
5113 tabla->buttons_pressed);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005114 }
5115 } else {
5116 pr_err("%s: Bad tabla private data\n", __func__);
5117 }
5118
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005119 pr_debug("%s: leave\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07005120 wcd9xxx_unlock_sleep(core);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005121}
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07005122
Joonwoo Park0976d012011-12-22 11:48:18 -08005123void tabla_mbhc_cal(struct snd_soc_codec *codec)
5124{
5125 struct tabla_priv *tabla;
5126 struct tabla_mbhc_btn_detect_cfg *btn_det;
5127 u8 cfilt_mode, bg_mode;
5128 u8 ncic, nmeas, navg;
5129 u32 mclk_rate;
5130 u32 dce_wait, sta_wait;
5131 u8 *n_cic;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005132 void *calibration;
Joonwoo Park0976d012011-12-22 11:48:18 -08005133
5134 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005135 calibration = tabla->mbhc_cfg.calibration;
5136
5137 wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
5138 tabla_turn_onoff_rel_detection(codec, false);
Joonwoo Park0976d012011-12-22 11:48:18 -08005139
5140 /* First compute the DCE / STA wait times
5141 * depending on tunable parameters.
5142 * The value is computed in microseconds
5143 */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005144 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08005145 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
Joonwoo Park107edf02012-01-11 11:42:24 -08005146 ncic = n_cic[tabla_codec_mclk_index(tabla)];
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005147 nmeas = TABLA_MBHC_CAL_BTN_DET_PTR(calibration)->n_meas;
5148 navg = TABLA_MBHC_CAL_GENERAL_PTR(calibration)->mbhc_navg;
5149 mclk_rate = tabla->mbhc_cfg.mclk_rate;
Joonwoo Park433149a2012-01-11 09:53:54 -08005150 dce_wait = (1000 * 512 * ncic * (nmeas + 1)) / (mclk_rate / 1000);
5151 sta_wait = (1000 * 128 * (navg + 1)) / (mclk_rate / 1000);
Joonwoo Park0976d012011-12-22 11:48:18 -08005152
5153 tabla->mbhc_data.t_dce = dce_wait;
5154 tabla->mbhc_data.t_sta = sta_wait;
5155
5156 /* LDOH and CFILT are already configured during pdata handling.
5157 * Only need to make sure CFILT and bandgap are in Fast mode.
5158 * Need to restore defaults once calculation is done.
5159 */
5160 cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl);
5161 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, 0x00);
5162 bg_mode = snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02,
5163 0x02);
5164
5165 /* Micbias, CFILT, LDOH, MBHC MUX mode settings
5166 * to perform ADC calibration
5167 */
5168 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x60,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005169 tabla->mbhc_cfg.micbias << 5);
Joonwoo Park0976d012011-12-22 11:48:18 -08005170 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
5171 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x60, 0x60);
5172 snd_soc_write(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x78);
5173 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x04);
5174
5175 /* DCE measurement for 0 volts */
5176 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
5177 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
5178 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
Joonwoo Park0976d012011-12-22 11:48:18 -08005179 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81);
5180 usleep_range(100, 100);
5181 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
5182 usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce);
5183 tabla->mbhc_data.dce_z = tabla_codec_read_dce_result(codec);
5184
5185 /* DCE measurment for MB voltage */
5186 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
5187 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
5188 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82);
5189 usleep_range(100, 100);
5190 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
5191 usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce);
5192 tabla->mbhc_data.dce_mb = tabla_codec_read_dce_result(codec);
5193
5194 /* Sta measuremnt for 0 volts */
5195 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
5196 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
5197 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
Joonwoo Park0976d012011-12-22 11:48:18 -08005198 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81);
5199 usleep_range(100, 100);
5200 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
5201 usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta);
5202 tabla->mbhc_data.sta_z = tabla_codec_read_sta_result(codec);
5203
5204 /* STA Measurement for MB Voltage */
5205 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82);
5206 usleep_range(100, 100);
5207 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
5208 usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta);
5209 tabla->mbhc_data.sta_mb = tabla_codec_read_sta_result(codec);
5210
5211 /* Restore default settings. */
5212 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00);
5213 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40,
5214 cfilt_mode);
5215 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, bg_mode);
5216
5217 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
5218 usleep_range(100, 100);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005219
5220 wcd9xxx_enable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
5221 tabla_turn_onoff_rel_detection(codec, true);
Joonwoo Park0976d012011-12-22 11:48:18 -08005222}
5223
5224void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg* btn_det,
5225 const enum tabla_mbhc_btn_det_mem mem)
5226{
5227 void *ret = &btn_det->_v_btn_low;
5228
5229 switch (mem) {
5230 case TABLA_BTN_DET_GAIN:
5231 ret += sizeof(btn_det->_n_cic);
5232 case TABLA_BTN_DET_N_CIC:
5233 ret += sizeof(btn_det->_n_ready);
Joonwoo Parkc0672392012-01-11 11:03:14 -08005234 case TABLA_BTN_DET_N_READY:
Joonwoo Park0976d012011-12-22 11:48:18 -08005235 ret += sizeof(btn_det->_v_btn_high[0]) * btn_det->num_btn;
5236 case TABLA_BTN_DET_V_BTN_HIGH:
5237 ret += sizeof(btn_det->_v_btn_low[0]) * btn_det->num_btn;
5238 case TABLA_BTN_DET_V_BTN_LOW:
5239 /* do nothing */
5240 break;
5241 default:
5242 ret = NULL;
5243 }
5244
5245 return ret;
5246}
5247
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005248static s16 tabla_scale_v_micb_vddio(struct tabla_priv *tabla, int v,
5249 bool tovddio)
5250{
5251 int r;
5252 int vddio_k, mb_k;
5253 vddio_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v,
5254 VDDIO_MICBIAS_MV);
5255 mb_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v,
5256 tabla->mbhc_data.micb_mv);
5257 if (tovddio)
5258 r = v * vddio_k / mb_k;
5259 else
5260 r = v * mb_k / vddio_k;
5261 return r;
5262}
5263
Joonwoo Park0976d012011-12-22 11:48:18 -08005264static void tabla_mbhc_calc_thres(struct snd_soc_codec *codec)
5265{
5266 struct tabla_priv *tabla;
5267 s16 btn_mv = 0, btn_delta_mv;
5268 struct tabla_mbhc_btn_detect_cfg *btn_det;
5269 struct tabla_mbhc_plug_type_cfg *plug_type;
5270 u16 *btn_high;
Joonwoo Parkc0672392012-01-11 11:03:14 -08005271 u8 *n_ready;
Joonwoo Park0976d012011-12-22 11:48:18 -08005272 int i;
5273
5274 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005275 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
5276 plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08005277
Joonwoo Parkc0672392012-01-11 11:03:14 -08005278 n_ready = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_READY);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005279 if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) {
Joonwoo Park03324832012-03-19 19:36:16 -07005280 tabla->mbhc_data.npoll = 4;
Joonwoo Park0976d012011-12-22 11:48:18 -08005281 tabla->mbhc_data.nbounce_wait = 30;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005282 } else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) {
Joonwoo Park0976d012011-12-22 11:48:18 -08005283 tabla->mbhc_data.npoll = 7;
5284 tabla->mbhc_data.nbounce_wait = 23;
Joonwoo Parkc0672392012-01-11 11:03:14 -08005285 }
Joonwoo Park0976d012011-12-22 11:48:18 -08005286
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005287 tabla->mbhc_data.t_sta_dce = ((1000 * 256) /
5288 (tabla->mbhc_cfg.mclk_rate / 1000) *
Joonwoo Parkc0672392012-01-11 11:03:14 -08005289 n_ready[tabla_codec_mclk_index(tabla)]) +
5290 10;
Joonwoo Park0976d012011-12-22 11:48:18 -08005291 tabla->mbhc_data.v_ins_hu =
5292 tabla_codec_v_sta_dce(codec, STA, plug_type->v_hs_max);
5293 tabla->mbhc_data.v_ins_h =
5294 tabla_codec_v_sta_dce(codec, DCE, plug_type->v_hs_max);
5295
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005296 tabla->mbhc_data.v_inval_ins_low = TABLA_MBHC_FAKE_INSERT_LOW;
5297 if (tabla->mbhc_cfg.gpio)
5298 tabla->mbhc_data.v_inval_ins_high =
5299 TABLA_MBHC_FAKE_INSERT_HIGH;
5300 else
5301 tabla->mbhc_data.v_inval_ins_high =
5302 TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO;
5303
5304 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
5305 tabla->mbhc_data.adj_v_hs_max =
5306 tabla_scale_v_micb_vddio(tabla, plug_type->v_hs_max, true);
5307 tabla->mbhc_data.adj_v_ins_hu =
5308 tabla_codec_v_sta_dce(codec, STA,
5309 tabla->mbhc_data.adj_v_hs_max);
5310 tabla->mbhc_data.adj_v_ins_h =
5311 tabla_codec_v_sta_dce(codec, DCE,
5312 tabla->mbhc_data.adj_v_hs_max);
5313 tabla->mbhc_data.v_inval_ins_low =
5314 tabla_scale_v_micb_vddio(tabla,
5315 tabla->mbhc_data.v_inval_ins_low,
5316 false);
5317 tabla->mbhc_data.v_inval_ins_high =
5318 tabla_scale_v_micb_vddio(tabla,
5319 tabla->mbhc_data.v_inval_ins_high,
5320 false);
5321 }
5322
Joonwoo Park0976d012011-12-22 11:48:18 -08005323 btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_HIGH);
5324 for (i = 0; i < btn_det->num_btn; i++)
5325 btn_mv = btn_high[i] > btn_mv ? btn_high[i] : btn_mv;
5326
5327 tabla->mbhc_data.v_b1_h = tabla_codec_v_sta_dce(codec, DCE, btn_mv);
5328 btn_delta_mv = btn_mv + btn_det->v_btn_press_delta_sta;
Joonwoo Park0976d012011-12-22 11:48:18 -08005329 tabla->mbhc_data.v_b1_hu =
5330 tabla_codec_v_sta_dce(codec, STA, btn_delta_mv);
5331
5332 btn_delta_mv = btn_mv + btn_det->v_btn_press_delta_cic;
5333
5334 tabla->mbhc_data.v_b1_huc =
5335 tabla_codec_v_sta_dce(codec, DCE, btn_delta_mv);
5336
5337 tabla->mbhc_data.v_brh = tabla->mbhc_data.v_b1_h;
Joonwoo Park03324832012-03-19 19:36:16 -07005338 tabla->mbhc_data.v_brl = TABLA_MBHC_BUTTON_MIN;
Joonwoo Park0976d012011-12-22 11:48:18 -08005339
5340 tabla->mbhc_data.v_no_mic =
5341 tabla_codec_v_sta_dce(codec, STA, plug_type->v_no_mic);
5342}
5343
5344void tabla_mbhc_init(struct snd_soc_codec *codec)
5345{
5346 struct tabla_priv *tabla;
5347 struct tabla_mbhc_general_cfg *generic;
5348 struct tabla_mbhc_btn_detect_cfg *btn_det;
5349 int n;
Joonwoo Park0976d012011-12-22 11:48:18 -08005350 u8 *n_cic, *gain;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305351 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Joonwoo Park0976d012011-12-22 11:48:18 -08005352
5353 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005354 generic = TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
5355 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08005356
Joonwoo Park0976d012011-12-22 11:48:18 -08005357 for (n = 0; n < 8; n++) {
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08005358 if ((!TABLA_IS_1_X(tabla_core->version)) || n != 7) {
Joonwoo Park0976d012011-12-22 11:48:18 -08005359 snd_soc_update_bits(codec,
5360 TABLA_A_CDC_MBHC_FEATURE_B1_CFG,
5361 0x07, n);
5362 snd_soc_write(codec, TABLA_A_CDC_MBHC_FEATURE_B2_CFG,
5363 btn_det->c[n]);
5364 }
5365 }
5366 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x07,
5367 btn_det->nc);
5368
5369 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
5370 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL, 0xFF,
Joonwoo Park107edf02012-01-11 11:42:24 -08005371 n_cic[tabla_codec_mclk_index(tabla)]);
Joonwoo Park0976d012011-12-22 11:48:18 -08005372
5373 gain = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_GAIN);
Joonwoo Park107edf02012-01-11 11:42:24 -08005374 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x78,
5375 gain[tabla_codec_mclk_index(tabla)] << 3);
Joonwoo Park0976d012011-12-22 11:48:18 -08005376
5377 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x70,
5378 generic->mbhc_nsa << 4);
5379
5380 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x0F,
5381 btn_det->n_meas);
5382
5383 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B5_CTL, generic->mbhc_navg);
5384
5385 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x80, 0x80);
5386
5387 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x78,
5388 btn_det->mbhc_nsc << 3);
5389
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08005390 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x03,
5391 TABLA_MICBIAS2);
Joonwoo Park0976d012011-12-22 11:48:18 -08005392
5393 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, 0x02);
Joonwoo Park03324832012-03-19 19:36:16 -07005394
5395 snd_soc_update_bits(codec, TABLA_A_MBHC_SCALING_MUX_2, 0xF0, 0xF0);
Joonwoo Park0976d012011-12-22 11:48:18 -08005396}
5397
Patrick Lai64b43262011-12-06 17:29:15 -08005398static bool tabla_mbhc_fw_validate(const struct firmware *fw)
5399{
5400 u32 cfg_offset;
5401 struct tabla_mbhc_imped_detect_cfg *imped_cfg;
5402 struct tabla_mbhc_btn_detect_cfg *btn_cfg;
5403
5404 if (fw->size < TABLA_MBHC_CAL_MIN_SIZE)
5405 return false;
5406
5407 /* previous check guarantees that there is enough fw data up
5408 * to num_btn
5409 */
5410 btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(fw->data);
5411 cfg_offset = (u32) ((void *) btn_cfg - (void *) fw->data);
5412 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_BTN_SZ(btn_cfg)))
5413 return false;
5414
5415 /* previous check guarantees that there is enough fw data up
5416 * to start of impedance detection configuration
5417 */
5418 imped_cfg = TABLA_MBHC_CAL_IMPED_DET_PTR(fw->data);
5419 cfg_offset = (u32) ((void *) imped_cfg - (void *) fw->data);
5420
5421 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_MIN_SZ))
5422 return false;
5423
5424 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_SZ(imped_cfg)))
5425 return false;
5426
5427 return true;
5428}
Joonwoo Park03324832012-03-19 19:36:16 -07005429
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005430static int tabla_determine_button(const struct tabla_priv *priv,
5431 const s32 bias_mv)
5432{
5433 s16 *v_btn_low, *v_btn_high;
5434 struct tabla_mbhc_btn_detect_cfg *btn_det;
5435 int i, btn = -1;
5436
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005437 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005438 v_btn_low = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_LOW);
5439 v_btn_high = tabla_mbhc_cal_btn_det_mp(btn_det,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305440 TABLA_BTN_DET_V_BTN_HIGH);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005441 for (i = 0; i < btn_det->num_btn; i++) {
5442 if ((v_btn_low[i] <= bias_mv) && (v_btn_high[i] >= bias_mv)) {
5443 btn = i;
5444 break;
5445 }
5446 }
5447
5448 if (btn == -1)
5449 pr_debug("%s: couldn't find button number for mic mv %d\n",
5450 __func__, bias_mv);
5451
5452 return btn;
5453}
5454
5455static int tabla_get_button_mask(const int btn)
5456{
5457 int mask = 0;
5458 switch (btn) {
5459 case 0:
5460 mask = SND_JACK_BTN_0;
5461 break;
5462 case 1:
5463 mask = SND_JACK_BTN_1;
5464 break;
5465 case 2:
5466 mask = SND_JACK_BTN_2;
5467 break;
5468 case 3:
5469 mask = SND_JACK_BTN_3;
5470 break;
5471 case 4:
5472 mask = SND_JACK_BTN_4;
5473 break;
5474 case 5:
5475 mask = SND_JACK_BTN_5;
5476 break;
5477 case 6:
5478 mask = SND_JACK_BTN_6;
5479 break;
5480 case 7:
5481 mask = SND_JACK_BTN_7;
5482 break;
5483 }
5484 return mask;
5485}
5486
Bradley Rubincb1e2732011-06-23 16:49:20 -07005487static irqreturn_t tabla_dce_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005488{
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005489 int i, mask;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005490 short dce, sta, bias_value_dce;
5491 s32 mv, stamv, bias_mv_dce;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005492 int btn = -1, meas = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005493 struct tabla_priv *priv = data;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005494 const struct tabla_mbhc_btn_detect_cfg *d =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005495 TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005496 short btnmeas[d->n_btn_meas + 1];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005497 struct snd_soc_codec *codec = priv->codec;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305498 struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent);
Joonwoo Park03324832012-03-19 19:36:16 -07005499 int n_btn_meas = d->n_btn_meas;
5500 u8 mbhc_status = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_STATUS) & 0x3E;
Bradley Rubincb1e2732011-06-23 16:49:20 -07005501
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005502 pr_debug("%s: enter\n", __func__);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005503
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005504 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
5505 if (priv->mbhc_state == MBHC_STATE_POTENTIAL_RECOVERY) {
5506 pr_debug("%s: mbhc is being recovered, skip button press\n",
5507 __func__);
5508 goto done;
5509 }
5510
5511 priv->mbhc_state = MBHC_STATE_POTENTIAL;
5512
5513 if (!priv->mbhc_polling_active) {
5514 pr_warn("%s: mbhc polling is not active, skip button press\n",
5515 __func__);
5516 goto done;
5517 }
Joonwoo Park03324832012-03-19 19:36:16 -07005518
5519 dce = tabla_codec_read_dce_result(codec);
5520 mv = tabla_codec_sta_dce_v(codec, 1, dce);
5521
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005522 /* If GPIO interrupt already kicked in, ignore button press */
5523 if (priv->in_gpio_handler) {
5524 pr_debug("%s: GPIO State Changed, ignore button press\n",
5525 __func__);
5526 btn = -1;
5527 goto done;
5528 }
5529
Joonwoo Park03324832012-03-19 19:36:16 -07005530 if (mbhc_status != TABLA_MBHC_STATUS_REL_DETECTION) {
5531 if (priv->mbhc_last_resume &&
5532 !time_after(jiffies, priv->mbhc_last_resume + HZ)) {
5533 pr_debug("%s: Button is already released shortly after "
5534 "resume\n", __func__);
5535 n_btn_meas = 0;
5536 } else {
5537 pr_debug("%s: Button is already released without "
5538 "resume", __func__);
5539 sta = tabla_codec_read_sta_result(codec);
5540 stamv = tabla_codec_sta_dce_v(codec, 0, sta);
5541 btn = tabla_determine_button(priv, mv);
5542 if (btn != tabla_determine_button(priv, stamv))
5543 btn = -1;
5544 goto done;
5545 }
5546 }
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005547
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005548 /* determine pressed button */
Joonwoo Park03324832012-03-19 19:36:16 -07005549 btnmeas[meas++] = tabla_determine_button(priv, mv);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005550 pr_debug("%s: meas %d - DCE %d,%d, button %d\n", __func__,
Joonwoo Park03324832012-03-19 19:36:16 -07005551 meas - 1, dce, mv, btnmeas[meas - 1]);
5552 if (n_btn_meas == 0)
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005553 btn = btnmeas[0];
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005554 for (; ((d->n_btn_meas) && (meas < (d->n_btn_meas + 1))); meas++) {
5555 bias_value_dce = tabla_codec_sta_dce(codec, 1, false);
5556 bias_mv_dce = tabla_codec_sta_dce_v(codec, 1, bias_value_dce);
5557 btnmeas[meas] = tabla_determine_button(priv, bias_mv_dce);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005558 pr_debug("%s: meas %d - DCE %d,%d, button %d\n",
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005559 __func__, meas, bias_value_dce, bias_mv_dce,
5560 btnmeas[meas]);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005561 /* if large enough measurements are collected,
5562 * start to check if last all n_btn_con measurements were
5563 * in same button low/high range */
5564 if (meas + 1 >= d->n_btn_con) {
5565 for (i = 0; i < d->n_btn_con; i++)
5566 if ((btnmeas[meas] < 0) ||
5567 (btnmeas[meas] != btnmeas[meas - i]))
5568 break;
5569 if (i == d->n_btn_con) {
5570 /* button pressed */
5571 btn = btnmeas[meas];
5572 break;
Joonwoo Park03324832012-03-19 19:36:16 -07005573 } else if ((n_btn_meas - meas) < (d->n_btn_con - 1)) {
5574 /* if left measurements are less than n_btn_con,
5575 * it's impossible to find button number */
5576 break;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005577 }
5578 }
Joonwoo Park8b1f0982011-12-08 17:12:45 -08005579 }
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005580
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005581 if (btn >= 0) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005582 if (priv->in_gpio_handler) {
5583 pr_debug("%s: GPIO already triggered, ignore button "
5584 "press\n", __func__);
5585 goto done;
5586 }
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005587 mask = tabla_get_button_mask(btn);
5588 priv->buttons_pressed |= mask;
Joonwoo Park03324832012-03-19 19:36:16 -07005589 wcd9xxx_lock_sleep(core);
5590 if (schedule_delayed_work(&priv->mbhc_btn_dwork,
5591 msecs_to_jiffies(400)) == 0) {
5592 WARN(1, "Button pressed twice without release"
5593 "event\n");
5594 wcd9xxx_unlock_sleep(core);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005595 }
Joonwoo Park816b8e62012-01-23 16:03:21 -08005596 } else {
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005597 pr_debug("%s: bogus button press, too short press?\n",
5598 __func__);
Joonwoo Park816b8e62012-01-23 16:03:21 -08005599 }
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005600
Joonwoo Park03324832012-03-19 19:36:16 -07005601 done:
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005602 pr_debug("%s: leave\n", __func__);
5603 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005604 return IRQ_HANDLED;
5605}
5606
Joonwoo Park03324832012-03-19 19:36:16 -07005607static int tabla_is_fake_press(struct tabla_priv *priv)
5608{
5609 int i;
5610 int r = 0;
5611 struct snd_soc_codec *codec = priv->codec;
5612 const int dces = MBHC_NUM_DCE_PLUG_DETECT;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005613 s16 mb_v, v_ins_hu, v_ins_h;
5614
5615 v_ins_hu = tabla_get_current_v_ins(priv, true);
5616 v_ins_h = tabla_get_current_v_ins(priv, false);
Joonwoo Park03324832012-03-19 19:36:16 -07005617
5618 for (i = 0; i < dces; i++) {
5619 usleep_range(10000, 10000);
5620 if (i == 0) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005621 mb_v = tabla_codec_sta_dce(codec, 0, true);
Joonwoo Park03324832012-03-19 19:36:16 -07005622 pr_debug("%s: STA[0]: %d,%d\n", __func__, mb_v,
5623 tabla_codec_sta_dce_v(codec, 0, mb_v));
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005624 if (mb_v < (s16)priv->mbhc_data.v_b1_hu ||
5625 mb_v > v_ins_hu) {
Joonwoo Park03324832012-03-19 19:36:16 -07005626 r = 1;
5627 break;
5628 }
5629 } else {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005630 mb_v = tabla_codec_sta_dce(codec, 1, true);
Joonwoo Park03324832012-03-19 19:36:16 -07005631 pr_debug("%s: DCE[%d]: %d,%d\n", __func__, i, mb_v,
5632 tabla_codec_sta_dce_v(codec, 1, mb_v));
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005633 if (mb_v < (s16)priv->mbhc_data.v_b1_h ||
5634 mb_v > v_ins_h) {
Joonwoo Park03324832012-03-19 19:36:16 -07005635 r = 1;
5636 break;
5637 }
5638 }
5639 }
5640
5641 return r;
5642}
5643
Bradley Rubincb1e2732011-06-23 16:49:20 -07005644static irqreturn_t tabla_release_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005645{
Joonwoo Parke5d3aa92012-01-11 14:47:15 -08005646 int ret;
Joonwoo Park816b8e62012-01-23 16:03:21 -08005647 struct tabla_priv *priv = data;
5648 struct snd_soc_codec *codec = priv->codec;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005649
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005650 pr_debug("%s: enter\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07005651
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005652 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
5653 priv->mbhc_state = MBHC_STATE_RELEASE;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005654
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005655 tabla_codec_drive_v_to_micbias(codec, 10000);
5656
Joonwoo Park03324832012-03-19 19:36:16 -07005657 if (priv->buttons_pressed & TABLA_JACK_BUTTON_MASK) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005658 ret = tabla_cancel_btn_work(priv);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005659 if (ret == 0) {
Joonwoo Park03324832012-03-19 19:36:16 -07005660 pr_debug("%s: Reporting long button release event\n",
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005661 __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005662 if (priv->mbhc_cfg.button_jack)
Joonwoo Park8b1f0982011-12-08 17:12:45 -08005663 tabla_snd_soc_jack_report(priv,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005664 priv->mbhc_cfg.button_jack, 0,
5665 priv->buttons_pressed);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005666 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07005667 if (tabla_is_fake_press(priv)) {
5668 pr_debug("%s: Fake button press interrupt\n",
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005669 __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005670 } else if (priv->mbhc_cfg.button_jack) {
5671 if (priv->in_gpio_handler) {
5672 pr_debug("%s: GPIO kicked in, ignore\n",
5673 __func__);
5674 } else {
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005675 pr_debug("%s: Reporting short button "
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005676 "press and release\n",
5677 __func__);
5678 tabla_snd_soc_jack_report(priv,
5679 priv->mbhc_cfg.button_jack,
5680 priv->buttons_pressed,
5681 priv->buttons_pressed);
5682 tabla_snd_soc_jack_report(priv,
5683 priv->mbhc_cfg.button_jack, 0,
5684 priv->buttons_pressed);
5685 }
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005686 }
5687 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005688
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005689 priv->buttons_pressed &= ~TABLA_JACK_BUTTON_MASK;
5690 }
5691
Joonwoo Park03324832012-03-19 19:36:16 -07005692 tabla_codec_calibrate_hs_polling(codec);
5693
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005694 if (priv->mbhc_cfg.gpio)
5695 msleep(TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS);
Joonwoo Park03324832012-03-19 19:36:16 -07005696
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005697 tabla_codec_start_hs_polling(codec);
5698
5699 pr_debug("%s: leave\n", __func__);
5700 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005701 return IRQ_HANDLED;
5702}
5703
Bradley Rubincb1e2732011-06-23 16:49:20 -07005704static void tabla_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec)
5705{
5706 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park0976d012011-12-22 11:48:18 -08005707 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005708 TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005709
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07005710 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07005711 tabla_codec_enable_config_mode(codec, 1);
5712
5713 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
5714 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x6, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005715
Joonwoo Park0976d012011-12-22 11:48:18 -08005716 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00);
5717
5718 usleep_range(generic->t_shutdown_plug_rem,
5719 generic->t_shutdown_plug_rem);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005720
5721 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0xA, 0x8);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07005722 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07005723 tabla_codec_enable_config_mode(codec, 0);
5724
5725 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x00);
5726}
5727
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005728static void tabla_codec_cleanup_hs_polling(struct snd_soc_codec *codec)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005729{
5730 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005731
5732 tabla_codec_shutdown_hs_removal_detect(codec);
5733
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07005734 if (!tabla->mclk_enabled) {
Asish Bhattacharya486745a2012-01-20 06:41:53 +05305735 tabla_codec_disable_clock_block(codec);
5736 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005737 }
5738
5739 tabla->mbhc_polling_active = false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005740 tabla->mbhc_state = MBHC_STATE_NONE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005741}
5742
Patrick Lai49efeac2011-11-03 11:01:12 -07005743static irqreturn_t tabla_hphl_ocp_irq(int irq, void *data)
5744{
5745 struct tabla_priv *tabla = data;
5746 struct snd_soc_codec *codec;
5747
5748 pr_info("%s: received HPHL OCP irq\n", __func__);
5749
5750 if (tabla) {
5751 codec = tabla->codec;
Patrick Laic7cae882011-11-18 11:52:49 -08005752 if (tabla->hphlocp_cnt++ < TABLA_OCP_ATTEMPT) {
5753 pr_info("%s: retry\n", __func__);
5754 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
5755 0x00);
5756 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
5757 0x10);
5758 } else {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305759 wcd9xxx_disable_irq(codec->control_data,
Patrick Laic7cae882011-11-18 11:52:49 -08005760 TABLA_IRQ_HPH_PA_OCPL_FAULT);
5761 tabla->hphlocp_cnt = 0;
5762 tabla->hph_status |= SND_JACK_OC_HPHL;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005763 if (tabla->mbhc_cfg.headset_jack)
Patrick Laic7cae882011-11-18 11:52:49 -08005764 tabla_snd_soc_jack_report(tabla,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005765 tabla->mbhc_cfg.headset_jack,
5766 tabla->hph_status,
5767 TABLA_JACK_MASK);
Patrick Lai49efeac2011-11-03 11:01:12 -07005768 }
5769 } else {
5770 pr_err("%s: Bad tabla private data\n", __func__);
5771 }
5772
5773 return IRQ_HANDLED;
5774}
5775
5776static irqreturn_t tabla_hphr_ocp_irq(int irq, void *data)
5777{
5778 struct tabla_priv *tabla = data;
5779 struct snd_soc_codec *codec;
5780
5781 pr_info("%s: received HPHR OCP irq\n", __func__);
5782
5783 if (tabla) {
5784 codec = tabla->codec;
Patrick Laic7cae882011-11-18 11:52:49 -08005785 if (tabla->hphrocp_cnt++ < TABLA_OCP_ATTEMPT) {
5786 pr_info("%s: retry\n", __func__);
5787 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
5788 0x00);
5789 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
5790 0x10);
5791 } else {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305792 wcd9xxx_disable_irq(codec->control_data,
Patrick Laic7cae882011-11-18 11:52:49 -08005793 TABLA_IRQ_HPH_PA_OCPR_FAULT);
5794 tabla->hphrocp_cnt = 0;
5795 tabla->hph_status |= SND_JACK_OC_HPHR;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005796 if (tabla->mbhc_cfg.headset_jack)
Patrick Laic7cae882011-11-18 11:52:49 -08005797 tabla_snd_soc_jack_report(tabla,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005798 tabla->mbhc_cfg.headset_jack,
5799 tabla->hph_status,
5800 TABLA_JACK_MASK);
Patrick Lai49efeac2011-11-03 11:01:12 -07005801 }
5802 } else {
5803 pr_err("%s: Bad tabla private data\n", __func__);
5804 }
5805
5806 return IRQ_HANDLED;
5807}
5808
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005809static bool tabla_is_invalid_insertion_range(struct snd_soc_codec *codec,
Joonwoo Park41956722012-04-18 13:13:07 -07005810 s32 mic_volt, bool highhph)
Joonwoo Park03324832012-03-19 19:36:16 -07005811{
5812 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005813 bool invalid = false;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005814 s16 v_hs_max;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005815
5816 /* Perform this check only when the high voltage headphone
5817 * needs to be considered as invalid
5818 */
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005819 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Park41956722012-04-18 13:13:07 -07005820 if (!highhph && (mic_volt > v_hs_max))
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005821 invalid = true;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005822 else if (mic_volt < tabla->mbhc_data.v_inval_ins_high &&
5823 (mic_volt > tabla->mbhc_data.v_inval_ins_low))
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005824 invalid = true;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005825
5826 return invalid;
5827}
5828
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005829static bool tabla_is_inval_insert_delta(struct snd_soc_codec *codec,
5830 int mic_volt, int mic_volt_prev,
5831 int threshold)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005832{
5833 int delta = abs(mic_volt - mic_volt_prev);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005834 if (delta > threshold) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005835 pr_debug("%s: volt delta %dmv\n", __func__, delta);
Joonwoo Park03324832012-03-19 19:36:16 -07005836 return true;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005837 }
Joonwoo Park03324832012-03-19 19:36:16 -07005838 return false;
5839}
5840
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005841/* called under codec_resource_lock acquisition */
5842void tabla_find_plug_and_report(struct snd_soc_codec *codec,
5843 enum tabla_mbhc_plug_type plug_type)
Joonwoo Park03324832012-03-19 19:36:16 -07005844{
5845 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005846
5847 if (plug_type == PLUG_TYPE_HEADPHONE
5848 && tabla->current_plug == PLUG_TYPE_NONE) {
5849 /* Nothing was reported previously
5850 * reporte a headphone
5851 */
5852 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
5853 tabla_codec_cleanup_hs_polling(codec);
5854 } else if (plug_type == PLUG_TYPE_HEADSET) {
5855 /* If Headphone was reported previously, this will
5856 * only report the mic line
5857 */
5858 tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET);
5859 msleep(100);
5860 tabla_codec_start_hs_polling(codec);
5861 } else if (plug_type == PLUG_TYPE_HIGH_HPH) {
5862 if (tabla->current_plug == PLUG_TYPE_NONE)
5863 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
5864 tabla_codec_cleanup_hs_polling(codec);
5865 pr_debug("setup mic trigger for further detection\n");
5866 tabla->lpi_enabled = true;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005867 tabla_codec_enable_hs_detect(codec, 1,
5868 MBHC_USE_MB_TRIGGER |
5869 MBHC_USE_HPHL_TRIGGER,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005870 false);
5871 }
5872}
5873
5874/* should be called under interrupt context that hold suspend */
5875static void tabla_schedule_hs_detect_plug(struct tabla_priv *tabla)
5876{
5877 pr_debug("%s: scheduling tabla_hs_correct_gpio_plug\n", __func__);
5878 tabla->hs_detect_work_stop = false;
5879 wcd9xxx_lock_sleep(tabla->codec->control_data);
5880 schedule_work(&tabla->hs_correct_plug_work);
5881}
5882
5883/* called under codec_resource_lock acquisition */
5884static void tabla_cancel_hs_detect_plug(struct tabla_priv *tabla)
5885{
5886 pr_debug("%s: canceling hs_correct_plug_work\n", __func__);
5887 tabla->hs_detect_work_stop = true;
5888 wmb();
5889 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
5890 if (cancel_work_sync(&tabla->hs_correct_plug_work)) {
5891 pr_debug("%s: hs_correct_plug_work is canceled\n", __func__);
5892 wcd9xxx_unlock_sleep(tabla->codec->control_data);
5893 }
5894 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
5895}
5896
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005897static bool tabla_hs_gpio_level_remove(struct tabla_priv *tabla)
5898{
5899 return (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) !=
5900 tabla->mbhc_cfg.gpio_level_insert);
5901}
5902
Joonwoo Park41956722012-04-18 13:13:07 -07005903/* called under codec_resource_lock acquisition */
5904static void tabla_codec_hphr_gnd_switch(struct snd_soc_codec *codec, bool on)
5905{
5906 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, on);
5907 if (on)
5908 usleep_range(5000, 5000);
5909}
5910
5911/* called under codec_resource_lock acquisition and mbhc override = 1 */
5912static enum tabla_mbhc_plug_type
5913tabla_codec_get_plug_type(struct snd_soc_codec *codec, bool highhph)
5914{
5915 int i;
5916 bool gndswitch, vddioswitch;
5917 int scaled;
5918 struct tabla_mbhc_plug_type_cfg *plug_type_ptr;
5919 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
5920 const bool vddio = (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV);
5921 int num_det = (MBHC_NUM_DCE_PLUG_DETECT + vddio);
5922 enum tabla_mbhc_plug_type plug_type[num_det];
5923 s16 mb_v[num_det];
5924 s32 mic_mv[num_det];
5925 bool inval = false;
5926
5927 /* make sure override is on */
5928 WARN_ON(!(snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04));
5929
5930 /* performs DCEs for N times
5931 * 1st: check if voltage is in invalid range
5932 * 2nd - N-2nd: check voltage range and delta
5933 * N-1st: check voltage range, delta with HPHR GND switch
5934 * Nth: check voltage range with VDDIO switch if micbias V != vddio V*/
5935 for (i = 0; i < num_det && !inval; i++) {
5936 gndswitch = (i == (num_det - 1 - vddio));
5937 vddioswitch = (vddio && (i == num_det - 1));
5938 if (i == 0) {
5939 mb_v[i] = tabla_codec_setup_hs_polling(codec);
5940 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
5941 inval = tabla_is_invalid_insertion_range(codec,
5942 mic_mv[i],
5943 highhph);
5944 scaled = mic_mv[i];
5945 } else if (vddioswitch) {
5946 __tabla_codec_switch_micbias(tabla->codec, 1, false,
5947 false);
5948 mb_v[i] = __tabla_codec_sta_dce(codec, 1, true, true);
5949 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
5950 scaled = tabla_scale_v_micb_vddio(tabla, mic_mv[i],
5951 false);
5952 inval = (tabla_is_invalid_insertion_range(codec,
5953 mic_mv[i],
5954 highhph) ||
5955 tabla_is_inval_insert_delta(codec, scaled,
5956 mic_mv[i - 1],
5957 TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV));
5958 __tabla_codec_switch_micbias(tabla->codec, 0, false,
5959 false);
5960 } else {
5961 if (gndswitch)
5962 tabla_codec_hphr_gnd_switch(codec, true);
5963 mb_v[i] = __tabla_codec_sta_dce(codec, 1, true, true);
5964 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
5965 inval = (tabla_is_invalid_insertion_range(codec,
5966 mic_mv[i],
5967 highhph) ||
5968 tabla_is_inval_insert_delta(codec, mic_mv[i],
5969 mic_mv[i - 1],
5970 TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV));
5971 if (gndswitch)
5972 tabla_codec_hphr_gnd_switch(codec, false);
5973 scaled = mic_mv[i];
5974 }
5975 pr_debug("%s: DCE #%d, %04x, V %d, scaled V %d, GND %d, "
5976 "invalid %d\n", __func__,
5977 i + 1, mb_v[i] & 0xffff, mic_mv[i], scaled, gndswitch,
5978 inval);
5979 }
5980
5981 plug_type_ptr =
5982 TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
5983 plug_type[0] = PLUG_TYPE_INVALID;
5984 for (i = 0; !inval && i < num_det; i++) {
5985 /*
5986 * If we are here, means none of the all
5987 * measurements are fake, continue plug type detection.
5988 * If all three measurements do not produce same
5989 * plug type, restart insertion detection
5990 */
5991 if (mic_mv[i] < plug_type_ptr->v_no_mic) {
5992 plug_type[i] = PLUG_TYPE_HEADPHONE;
5993 pr_debug("%s: Detect attempt %d, detected Headphone\n",
5994 __func__, i);
5995 } else if (highhph && (mic_mv[i] > plug_type_ptr->v_hs_max)) {
5996 plug_type[i] = PLUG_TYPE_HIGH_HPH;
5997 pr_debug("%s: Detect attempt %d, detected High "
5998 "Headphone\n", __func__, i);
5999 } else {
6000 plug_type[i] = PLUG_TYPE_HEADSET;
6001 pr_debug("%s: Detect attempt %d, detected Headset\n",
6002 __func__, i);
6003 }
6004
6005 if (i > 0 && (plug_type[i - 1] != plug_type[i])) {
6006 pr_err("%s: Detect attempt %d and %d are not same",
6007 __func__, i - 1, i);
6008 plug_type[0] = PLUG_TYPE_INVALID;
6009 inval = true;
6010 break;
6011 }
6012 }
6013
6014 return plug_type[0];
6015}
6016
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006017static void tabla_hs_correct_gpio_plug(struct work_struct *work)
6018{
6019 struct tabla_priv *tabla;
6020 struct snd_soc_codec *codec;
Joonwoo Park41956722012-04-18 13:13:07 -07006021 int retry = 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006022 bool correction = false;
Joonwoo Park41956722012-04-18 13:13:07 -07006023 enum tabla_mbhc_plug_type plug_type;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006024 unsigned long timeout;
6025
6026 tabla = container_of(work, struct tabla_priv, hs_correct_plug_work);
6027 codec = tabla->codec;
6028
6029 pr_debug("%s: enter\n", __func__);
6030 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
6031
6032 /* Keep override on during entire plug type correction work.
6033 *
6034 * This is okay under the assumption that any GPIO irqs which use
6035 * MBHC block cancel and sync this work so override is off again
6036 * prior to GPIO interrupt handler's MBHC block usage.
6037 * Also while this correction work is running, we can guarantee
6038 * DAPM doesn't use any MBHC block as this work only runs with
6039 * headphone detection.
6040 */
6041 tabla_turn_onoff_override(codec, true);
6042
6043 timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS);
6044 while (!time_after(jiffies, timeout)) {
6045 ++retry;
6046 rmb();
6047 if (tabla->hs_detect_work_stop) {
6048 pr_debug("%s: stop requested\n", __func__);
6049 break;
6050 }
6051
6052 msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS);
6053 if (tabla_hs_gpio_level_remove(tabla)) {
6054 pr_debug("%s: GPIO value is low\n", __func__);
6055 break;
6056 }
6057
6058 /* can race with removal interrupt */
6059 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Joonwoo Park41956722012-04-18 13:13:07 -07006060 plug_type = tabla_codec_get_plug_type(codec, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006061 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
6062
Joonwoo Park41956722012-04-18 13:13:07 -07006063 if (plug_type == PLUG_TYPE_INVALID) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006064 pr_debug("Invalid plug in attempt # %d\n", retry);
6065 if (retry == NUM_ATTEMPTS_TO_REPORT &&
6066 tabla->current_plug == PLUG_TYPE_NONE) {
6067 tabla_codec_report_plug(codec, 1,
6068 SND_JACK_HEADPHONE);
6069 }
Joonwoo Park41956722012-04-18 13:13:07 -07006070 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006071 pr_debug("Good headphone detected, continue polling mic\n");
6072 if (tabla->current_plug == PLUG_TYPE_NONE) {
6073 tabla_codec_report_plug(codec, 1,
6074 SND_JACK_HEADPHONE);
6075 }
6076 } else {
6077 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
6078 /* Turn off override */
6079 tabla_turn_onoff_override(codec, false);
Joonwoo Park41956722012-04-18 13:13:07 -07006080 tabla_find_plug_and_report(codec, plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006081 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
6082 pr_debug("Attempt %d found correct plug %d\n", retry,
Joonwoo Park41956722012-04-18 13:13:07 -07006083 plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006084 correction = true;
6085 break;
6086 }
6087 }
6088
6089 /* Turn off override */
6090 if (!correction)
6091 tabla_turn_onoff_override(codec, false);
6092
6093 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
6094 pr_debug("%s: leave\n", __func__);
6095 /* unlock sleep */
6096 wcd9xxx_unlock_sleep(tabla->codec->control_data);
6097}
6098
6099/* called under codec_resource_lock acquisition */
6100static void tabla_codec_decide_gpio_plug(struct snd_soc_codec *codec)
6101{
6102 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park41956722012-04-18 13:13:07 -07006103 enum tabla_mbhc_plug_type plug_type;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006104
6105 pr_debug("%s: enter\n", __func__);
6106
6107 tabla_turn_onoff_override(codec, true);
Joonwoo Park41956722012-04-18 13:13:07 -07006108 plug_type = tabla_codec_get_plug_type(codec, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006109 tabla_turn_onoff_override(codec, false);
6110
6111 if (tabla_hs_gpio_level_remove(tabla)) {
6112 pr_debug("%s: GPIO value is low when determining plug\n",
6113 __func__);
6114 return;
6115 }
6116
Joonwoo Park41956722012-04-18 13:13:07 -07006117 if (plug_type == PLUG_TYPE_INVALID) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006118 tabla_schedule_hs_detect_plug(tabla);
Joonwoo Park41956722012-04-18 13:13:07 -07006119 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006120 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
6121
6122 tabla_schedule_hs_detect_plug(tabla);
6123 } else {
Joonwoo Park41956722012-04-18 13:13:07 -07006124 pr_debug("%s: Valid plug found, determine plug type %d\n",
6125 __func__, plug_type);
6126 tabla_find_plug_and_report(codec, plug_type);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006127 }
6128}
6129
6130/* called under codec_resource_lock acquisition */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006131static void tabla_codec_detect_plug_type(struct snd_soc_codec *codec)
6132{
Joonwoo Park41956722012-04-18 13:13:07 -07006133 enum tabla_mbhc_plug_type plug_type;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006134 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
6135 const struct tabla_mbhc_plug_detect_cfg *plug_det =
6136 TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park03324832012-03-19 19:36:16 -07006137
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006138 /* Turn on the override,
6139 * tabla_codec_setup_hs_polling requires override on */
6140 tabla_turn_onoff_override(codec, true);
Joonwoo Park03324832012-03-19 19:36:16 -07006141
6142 if (plug_det->t_ins_complete > 20)
6143 msleep(plug_det->t_ins_complete);
6144 else
6145 usleep_range(plug_det->t_ins_complete * 1000,
6146 plug_det->t_ins_complete * 1000);
6147
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006148 if (tabla->mbhc_cfg.gpio) {
6149 /* Turn off the override */
6150 tabla_turn_onoff_override(codec, false);
6151 if (tabla_hs_gpio_level_remove(tabla))
6152 pr_debug("%s: GPIO value is low when determining "
6153 "plug\n", __func__);
6154 else
6155 tabla_codec_decide_gpio_plug(codec);
6156 return;
6157 }
6158
Joonwoo Park41956722012-04-18 13:13:07 -07006159 plug_type = tabla_codec_get_plug_type(codec, tabla->mbhc_cfg.gpio ?
6160 true : false);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006161 tabla_turn_onoff_override(codec, false);
Joonwoo Park03324832012-03-19 19:36:16 -07006162
Joonwoo Park41956722012-04-18 13:13:07 -07006163 if (plug_type == PLUG_TYPE_INVALID) {
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006164 pr_debug("%s: Invalid plug type detected\n", __func__);
6165 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
6166 0x02, 0x02);
6167 tabla_codec_cleanup_hs_polling(codec);
6168 tabla_codec_enable_hs_detect(codec, 1,
6169 MBHC_USE_MB_TRIGGER |
6170 MBHC_USE_HPHL_TRIGGER, false);
Joonwoo Park41956722012-04-18 13:13:07 -07006171 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Park03324832012-03-19 19:36:16 -07006172 pr_debug("%s: Headphone Detected\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006173 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
6174 tabla_codec_cleanup_hs_polling(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07006175 tabla_codec_enable_hs_detect(codec, 0, 0, false);
Joonwoo Park41956722012-04-18 13:13:07 -07006176 } else if (plug_type == PLUG_TYPE_HEADSET) {
Joonwoo Park03324832012-03-19 19:36:16 -07006177 pr_debug("%s: Headset detected\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006178 tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET);
6179
Joonwoo Park03324832012-03-19 19:36:16 -07006180 /* avoid false button press detect */
6181 msleep(50);
Joonwoo Park03324832012-03-19 19:36:16 -07006182 tabla_codec_start_hs_polling(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07006183 }
6184}
6185
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006186/* called only from interrupt which is under codec_resource_lock acquisition */
6187static void tabla_hs_insert_irq_gpio(struct tabla_priv *priv, bool is_removal)
Bradley Rubincb1e2732011-06-23 16:49:20 -07006188{
Bradley Rubincb1e2732011-06-23 16:49:20 -07006189 struct snd_soc_codec *codec = priv->codec;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006190
6191 if (!is_removal) {
6192 pr_debug("%s: MIC trigger insertion interrupt\n", __func__);
6193
6194 rmb();
6195 if (priv->lpi_enabled)
6196 msleep(100);
6197
6198 rmb();
6199 if (!priv->lpi_enabled) {
6200 pr_debug("%s: lpi is disabled\n", __func__);
6201 } else if (gpio_get_value_cansleep(priv->mbhc_cfg.gpio) ==
6202 priv->mbhc_cfg.gpio_level_insert) {
6203 pr_debug("%s: Valid insertion, "
6204 "detect plug type\n", __func__);
6205 tabla_codec_decide_gpio_plug(codec);
6206 } else {
6207 pr_debug("%s: Invalid insertion, "
6208 "stop plug detection\n", __func__);
6209 }
6210 } else {
6211 pr_err("%s: GPIO used, invalid MBHC Removal\n", __func__);
6212 }
6213}
6214
6215/* called only from interrupt which is under codec_resource_lock acquisition */
6216static void tabla_hs_insert_irq_nogpio(struct tabla_priv *priv, bool is_removal,
6217 bool is_mb_trigger)
6218{
Joonwoo Park03324832012-03-19 19:36:16 -07006219 int ret;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006220 struct snd_soc_codec *codec = priv->codec;
6221 struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006222
6223 if (is_removal) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006224 /* cancel possiblely running hs detect work */
6225 tabla_cancel_hs_detect_plug(priv);
6226
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07006227 /*
6228 * If headphone is removed while playback is in progress,
6229 * it is possible that micbias will be switched to VDDIO.
6230 */
Joonwoo Park03324832012-03-19 19:36:16 -07006231 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006232 tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006233 tabla_codec_shutdown_hs_removal_detect(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006234 tabla_codec_enable_hs_detect(codec, 1,
6235 MBHC_USE_MB_TRIGGER |
6236 MBHC_USE_HPHL_TRIGGER,
Joonwoo Park03324832012-03-19 19:36:16 -07006237 true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006238 } else if (is_mb_trigger && !is_removal) {
Joonwoo Park03324832012-03-19 19:36:16 -07006239 pr_debug("%s: Waiting for Headphone left trigger\n",
6240 __func__);
6241 wcd9xxx_lock_sleep(core);
6242 if (schedule_delayed_work(&priv->mbhc_insert_dwork,
6243 usecs_to_jiffies(1000000)) == 0) {
6244 pr_err("%s: mbhc_insert_dwork is already scheduled\n",
6245 __func__);
6246 wcd9xxx_unlock_sleep(core);
Joonwoo Parkf4267c22012-01-10 13:25:24 -08006247 }
Joonwoo Park03324832012-03-19 19:36:16 -07006248 tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER,
6249 false);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006250 } else {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006251 ret = cancel_delayed_work(&priv->mbhc_insert_dwork);
6252 if (ret != 0) {
6253 pr_debug("%s: Complete plug insertion, Detecting plug "
6254 "type\n", __func__);
6255 tabla_codec_detect_plug_type(codec);
6256 wcd9xxx_unlock_sleep(core);
6257 } else {
6258 wcd9xxx_enable_irq(codec->control_data,
6259 TABLA_IRQ_MBHC_INSERTION);
6260 pr_err("%s: Error detecting plug insertion\n",
6261 __func__);
6262 }
Joonwoo Park03324832012-03-19 19:36:16 -07006263 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006264}
Bhalchandra Gajare9494fa262011-11-10 19:25:59 -08006265
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006266static irqreturn_t tabla_hs_insert_irq(int irq, void *data)
6267{
6268 bool is_mb_trigger, is_removal;
6269 struct tabla_priv *priv = data;
6270 struct snd_soc_codec *codec = priv->codec;
Bradley Rubincb1e2732011-06-23 16:49:20 -07006271
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006272 pr_debug("%s: enter\n", __func__);
6273 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
6274 wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
6275
6276 is_mb_trigger = !!(snd_soc_read(codec, priv->mbhc_bias_regs.mbhc_reg) &
6277 0x10);
6278 is_removal = !!(snd_soc_read(codec, TABLA_A_CDC_MBHC_INT_CTL) & 0x02);
6279 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x03, 0x00);
6280
6281 /* Turn off both HPH and MIC line schmitt triggers */
6282 snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
6283 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
6284 snd_soc_update_bits(codec, priv->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
6285
6286 if (priv->mbhc_cfg.gpio)
6287 tabla_hs_insert_irq_gpio(priv, is_removal);
6288 else
6289 tabla_hs_insert_irq_nogpio(priv, is_removal, is_mb_trigger);
6290
6291 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006292 return IRQ_HANDLED;
6293}
6294
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006295static bool is_valid_mic_voltage(struct snd_soc_codec *codec, s32 mic_mv)
6296{
6297 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006298 const struct tabla_mbhc_plug_type_cfg *plug_type =
6299 TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
6300 const s16 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006301
6302 return (!(mic_mv > 10 && mic_mv < 80) && (mic_mv > plug_type->v_no_mic)
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006303 && (mic_mv < v_hs_max)) ? true : false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006304}
6305
6306/* called under codec_resource_lock acquisition
6307 * returns true if mic voltage range is back to normal insertion
6308 * returns false either if timedout or removed */
6309static bool tabla_hs_remove_settle(struct snd_soc_codec *codec)
6310{
6311 int i;
6312 bool timedout, settled = false;
6313 s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT];
6314 short mb_v[MBHC_NUM_DCE_PLUG_DETECT];
6315 unsigned long retry = 0, timeout;
6316 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006317 const s16 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006318
6319 timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS);
6320 while (!(timedout = time_after(jiffies, timeout))) {
6321 retry++;
6322 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
6323 pr_debug("%s: GPIO indicates removal\n", __func__);
6324 break;
6325 }
6326
6327 if (tabla->mbhc_cfg.gpio) {
6328 if (retry > 1)
6329 msleep(250);
6330 else
6331 msleep(50);
6332 }
6333
6334 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
6335 pr_debug("%s: GPIO indicates removal\n", __func__);
6336 break;
6337 }
6338
6339 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) {
6340 mb_v[i] = tabla_codec_sta_dce(codec, 1, true);
6341 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
6342 pr_debug("%s : DCE run %lu, mic_mv = %d(%x)\n",
6343 __func__, retry, mic_mv[i], mb_v[i]);
6344 }
6345
6346 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
6347 pr_debug("%s: GPIO indicates removal\n", __func__);
6348 break;
6349 }
6350
6351 if (tabla->current_plug == PLUG_TYPE_NONE) {
6352 pr_debug("%s : headset/headphone is removed\n",
6353 __func__);
6354 break;
6355 }
6356
6357 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++)
6358 if (!is_valid_mic_voltage(codec, mic_mv[i]))
6359 break;
6360
6361 if (i == MBHC_NUM_DCE_PLUG_DETECT) {
6362 pr_debug("%s: MIC voltage settled\n", __func__);
6363 settled = true;
6364 msleep(200);
6365 break;
6366 }
6367
6368 /* only for non-GPIO remove irq */
6369 if (!tabla->mbhc_cfg.gpio) {
6370 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++)
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006371 if (mic_mv[i] < v_hs_max)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006372 break;
6373 if (i == MBHC_NUM_DCE_PLUG_DETECT) {
6374 pr_debug("%s: Headset is removed\n", __func__);
6375 break;
6376 }
6377 }
6378 }
6379
6380 if (timedout)
6381 pr_debug("%s: Microphone did not settle in %d seconds\n",
6382 __func__, TABLA_HS_DETECT_PLUG_TIME_MS);
6383 return settled;
6384}
6385
6386/* called only from interrupt which is under codec_resource_lock acquisition */
6387static void tabla_hs_remove_irq_gpio(struct tabla_priv *priv)
6388{
6389 struct snd_soc_codec *codec = priv->codec;
6390
6391 if (tabla_hs_remove_settle(codec))
6392 tabla_codec_start_hs_polling(codec);
6393 pr_debug("%s: remove settle done\n", __func__);
6394}
6395
6396/* called only from interrupt which is under codec_resource_lock acquisition */
6397static void tabla_hs_remove_irq_nogpio(struct tabla_priv *priv)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006398{
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006399 short bias_value;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006400 bool removed = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006401 struct snd_soc_codec *codec = priv->codec;
Joonwoo Park0976d012011-12-22 11:48:18 -08006402 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006403 TABLA_MBHC_CAL_GENERAL_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006404 int min_us = TABLA_FAKE_REMOVAL_MIN_PERIOD_MS * 1000;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006405
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006406 if (priv->current_plug != PLUG_TYPE_HEADSET) {
6407 pr_debug("%s(): Headset is not inserted, ignore removal\n",
6408 __func__);
6409 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
6410 0x08, 0x08);
6411 return;
6412 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006413
Joonwoo Park0976d012011-12-22 11:48:18 -08006414 usleep_range(generic->t_shutdown_plug_rem,
6415 generic->t_shutdown_plug_rem);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006416
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006417 do {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006418 bias_value = tabla_codec_sta_dce(codec, 1, true);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006419 pr_debug("%s: DCE %d,%d, %d us left\n", __func__, bias_value,
6420 tabla_codec_sta_dce_v(codec, 1, bias_value), min_us);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006421 if (bias_value < tabla_get_current_v_ins(priv, false)) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006422 pr_debug("%s: checking false removal\n", __func__);
6423 msleep(500);
6424 removed = !tabla_hs_remove_settle(codec);
6425 pr_debug("%s: headset %sactually removed\n", __func__,
6426 removed ? "" : "not ");
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006427 break;
6428 }
6429 min_us -= priv->mbhc_data.t_dce;
6430 } while (min_us > 0);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07006431
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006432 if (removed) {
6433 /* cancel possiblely running hs detect work */
6434 tabla_cancel_hs_detect_plug(priv);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07006435 /*
6436 * If this removal is not false, first check the micbias
6437 * switch status and switch it to LDOH if it is already
6438 * switched to VDDIO.
6439 */
Joonwoo Park03324832012-03-19 19:36:16 -07006440 tabla_codec_switch_micbias(codec, 0);
Joonwoo Park03324832012-03-19 19:36:16 -07006441
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006442 tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET);
6443 tabla_codec_cleanup_hs_polling(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006444 tabla_codec_enable_hs_detect(codec, 1,
6445 MBHC_USE_MB_TRIGGER |
6446 MBHC_USE_HPHL_TRIGGER,
Joonwoo Park03324832012-03-19 19:36:16 -07006447 true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006448 } else {
6449 tabla_codec_start_hs_polling(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006450 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006451}
Joonwoo Park8b1f0982011-12-08 17:12:45 -08006452
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006453static irqreturn_t tabla_hs_remove_irq(int irq, void *data)
6454{
6455 struct tabla_priv *priv = data;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006456 bool vddio;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006457 pr_debug("%s: enter, removal interrupt\n", __func__);
6458
6459 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006460 vddio = (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
6461 priv->mbhc_micbias_switched);
6462 if (vddio)
6463 __tabla_codec_switch_micbias(priv->codec, 0, false, true);
6464
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006465 if (priv->mbhc_cfg.gpio)
6466 tabla_hs_remove_irq_gpio(priv);
6467 else
6468 tabla_hs_remove_irq_nogpio(priv);
6469
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006470 /* if driver turned off vddio switch and headset is not removed,
6471 * turn on the vddio switch back, if headset is removed then vddio
6472 * switch is off by time now and shouldn't be turn on again from here */
6473 if (vddio && priv->current_plug == PLUG_TYPE_HEADSET)
6474 __tabla_codec_switch_micbias(priv->codec, 1, true, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006475 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006476
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006477 return IRQ_HANDLED;
6478}
6479
Joonwoo Park03324832012-03-19 19:36:16 -07006480void mbhc_insert_work(struct work_struct *work)
6481{
6482 struct delayed_work *dwork;
6483 struct tabla_priv *tabla;
6484 struct snd_soc_codec *codec;
6485 struct wcd9xxx *tabla_core;
6486
6487 dwork = to_delayed_work(work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006488 tabla = container_of(dwork, struct tabla_priv, mbhc_insert_dwork);
Joonwoo Park03324832012-03-19 19:36:16 -07006489 codec = tabla->codec;
6490 tabla_core = dev_get_drvdata(codec->dev->parent);
6491
6492 pr_debug("%s:\n", __func__);
6493
6494 /* Turn off both HPH and MIC line schmitt triggers */
6495 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
6496 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
6497 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
6498 wcd9xxx_disable_irq_sync(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
6499 tabla_codec_detect_plug_type(codec);
6500 wcd9xxx_unlock_sleep(tabla_core);
6501}
6502
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006503static void tabla_hs_gpio_handler(struct snd_soc_codec *codec)
6504{
6505 bool insert;
6506 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
6507 bool is_removed = false;
6508
6509 pr_debug("%s: enter\n", __func__);
6510
6511 tabla->in_gpio_handler = true;
6512 /* Wait here for debounce time */
6513 usleep_range(TABLA_GPIO_IRQ_DEBOUNCE_TIME_US,
6514 TABLA_GPIO_IRQ_DEBOUNCE_TIME_US);
6515
6516 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
6517
6518 /* cancel pending button press */
6519 if (tabla_cancel_btn_work(tabla))
6520 pr_debug("%s: button press is canceled\n", __func__);
6521
6522 insert = (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) ==
6523 tabla->mbhc_cfg.gpio_level_insert);
6524 if ((tabla->current_plug == PLUG_TYPE_NONE) && insert) {
6525 tabla->lpi_enabled = false;
6526 wmb();
6527
6528 /* cancel detect plug */
6529 tabla_cancel_hs_detect_plug(tabla);
6530
6531 /* Disable Mic Bias pull down and HPH Switch to GND */
6532 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01,
6533 0x00);
6534 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x00);
6535 tabla_codec_detect_plug_type(codec);
6536 } else if ((tabla->current_plug != PLUG_TYPE_NONE) && !insert) {
6537 tabla->lpi_enabled = false;
6538 wmb();
6539
6540 /* cancel detect plug */
6541 tabla_cancel_hs_detect_plug(tabla);
6542
6543 if (tabla->current_plug == PLUG_TYPE_HEADPHONE) {
6544 tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE);
6545 is_removed = true;
6546 } else if (tabla->current_plug == PLUG_TYPE_HEADSET) {
6547 tabla_codec_pause_hs_polling(codec);
6548 tabla_codec_cleanup_hs_polling(codec);
6549 tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET);
6550 is_removed = true;
6551 }
6552
6553 if (is_removed) {
6554 /* Enable Mic Bias pull down and HPH Switch to GND */
6555 snd_soc_update_bits(codec,
6556 tabla->mbhc_bias_regs.ctl_reg, 0x01,
6557 0x01);
6558 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01,
6559 0x01);
6560 /* Make sure mic trigger is turned off */
6561 snd_soc_update_bits(codec,
6562 tabla->mbhc_bias_regs.ctl_reg,
6563 0x01, 0x01);
6564 snd_soc_update_bits(codec,
6565 tabla->mbhc_bias_regs.mbhc_reg,
6566 0x90, 0x00);
6567 /* Reset MBHC State Machine */
6568 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
6569 0x08, 0x08);
6570 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
6571 0x08, 0x00);
6572 /* Turn off override */
6573 tabla_turn_onoff_override(codec, false);
6574 }
6575 }
6576
6577 tabla->in_gpio_handler = false;
6578 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
6579 pr_debug("%s: leave\n", __func__);
6580}
6581
6582static irqreturn_t tabla_mechanical_plug_detect_irq(int irq, void *data)
6583{
6584 int r = IRQ_HANDLED;
6585 struct snd_soc_codec *codec = data;
6586
6587 if (unlikely(wcd9xxx_lock_sleep(codec->control_data) == false)) {
6588 pr_warn("%s: failed to hold suspend\n", __func__);
6589 r = IRQ_NONE;
6590 } else {
6591 tabla_hs_gpio_handler(codec);
6592 wcd9xxx_unlock_sleep(codec->control_data);
6593 }
6594
6595 return r;
6596}
6597
6598static void mbhc_fw_read(struct work_struct *work)
6599{
6600 struct delayed_work *dwork;
6601 struct tabla_priv *tabla;
6602 struct snd_soc_codec *codec;
6603 const struct firmware *fw;
6604 int ret = -1, retry = 0, rc;
6605
6606 dwork = to_delayed_work(work);
6607 tabla = container_of(dwork, struct tabla_priv,
6608 mbhc_firmware_dwork);
6609 codec = tabla->codec;
6610
6611 while (retry < MBHC_FW_READ_ATTEMPTS) {
6612 retry++;
6613 pr_info("%s:Attempt %d to request MBHC firmware\n",
6614 __func__, retry);
6615 ret = request_firmware(&fw, "wcd9310/wcd9310_mbhc.bin",
6616 codec->dev);
6617
6618 if (ret != 0) {
6619 usleep_range(MBHC_FW_READ_TIMEOUT,
6620 MBHC_FW_READ_TIMEOUT);
6621 } else {
6622 pr_info("%s: MBHC Firmware read succesful\n", __func__);
6623 break;
6624 }
6625 }
6626
6627 if (ret != 0) {
6628 pr_err("%s: Cannot load MBHC firmware use default cal\n",
6629 __func__);
6630 } else if (tabla_mbhc_fw_validate(fw) == false) {
6631 pr_err("%s: Invalid MBHC cal data size use default cal\n",
6632 __func__);
6633 release_firmware(fw);
6634 } else {
6635 tabla->mbhc_cfg.calibration = (void *)fw->data;
6636 tabla->mbhc_fw = fw;
6637 }
6638
6639 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
6640 tabla_mbhc_init(codec);
6641 tabla_mbhc_cal(codec);
6642 tabla_mbhc_calc_thres(codec);
6643 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
6644 tabla_codec_calibrate_hs_polling(codec);
6645 if (!tabla->mbhc_cfg.gpio) {
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006646 rc = tabla_codec_enable_hs_detect(codec, 1,
6647 MBHC_USE_MB_TRIGGER |
6648 MBHC_USE_HPHL_TRIGGER,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006649 false);
6650
6651 if (IS_ERR_VALUE(rc))
6652 pr_err("%s: Failed to setup MBHC detection\n",
6653 __func__);
6654 } else {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006655 /* Enable Mic Bias pull down and HPH Switch to GND */
6656 snd_soc_update_bits(codec,
6657 tabla->mbhc_bias_regs.ctl_reg, 0x01,
6658 0x01);
6659 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01,
6660 0x01);
6661 INIT_WORK(&tabla->hs_correct_plug_work,
6662 tabla_hs_correct_gpio_plug);
6663 }
6664
6665}
6666
Joonwoo Park03324832012-03-19 19:36:16 -07006667int tabla_hs_detect(struct snd_soc_codec *codec,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006668 const struct tabla_mbhc_config *cfg)
Joonwoo Park03324832012-03-19 19:36:16 -07006669{
6670 struct tabla_priv *tabla;
6671 int rc = 0;
6672
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006673 if (!codec || !cfg->calibration) {
Joonwoo Park03324832012-03-19 19:36:16 -07006674 pr_err("Error: no codec or calibration\n");
6675 return -EINVAL;
6676 }
6677
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006678 if (cfg->mclk_rate != TABLA_MCLK_RATE_12288KHZ) {
6679 if (cfg->mclk_rate == TABLA_MCLK_RATE_9600KHZ)
Joonwoo Park03324832012-03-19 19:36:16 -07006680 pr_err("Error: clock rate %dHz is not yet supported\n",
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006681 cfg->mclk_rate);
Joonwoo Park03324832012-03-19 19:36:16 -07006682 else
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006683 pr_err("Error: unsupported clock rate %d\n",
6684 cfg->mclk_rate);
Joonwoo Park03324832012-03-19 19:36:16 -07006685 return -EINVAL;
6686 }
6687
6688 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006689 tabla->mbhc_cfg = *cfg;
6690 tabla->in_gpio_handler = false;
6691 tabla->current_plug = PLUG_TYPE_NONE;
6692 tabla->lpi_enabled = false;
Joonwoo Park03324832012-03-19 19:36:16 -07006693 tabla_get_mbhc_micbias_regs(codec, &tabla->mbhc_bias_regs);
6694
6695 /* Put CFILT in fast mode by default */
6696 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl,
6697 0x40, TABLA_CFILT_FAST_MODE);
6698 INIT_DELAYED_WORK(&tabla->mbhc_firmware_dwork, mbhc_fw_read);
6699 INIT_DELAYED_WORK(&tabla->mbhc_btn_dwork, btn_lpress_fn);
6700 INIT_WORK(&tabla->hphlocp_work, hphlocp_off_report);
6701 INIT_WORK(&tabla->hphrocp_work, hphrocp_off_report);
6702 INIT_DELAYED_WORK(&tabla->mbhc_insert_dwork, mbhc_insert_work);
6703
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006704 if (!tabla->mbhc_cfg.read_fw_bin) {
6705 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
Joonwoo Park03324832012-03-19 19:36:16 -07006706 tabla_mbhc_init(codec);
6707 tabla_mbhc_cal(codec);
6708 tabla_mbhc_calc_thres(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006709 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
Joonwoo Park03324832012-03-19 19:36:16 -07006710 tabla_codec_calibrate_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006711 if (!tabla->mbhc_cfg.gpio) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006712 rc = tabla_codec_enable_hs_detect(codec, 1,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006713 MBHC_USE_MB_TRIGGER |
6714 MBHC_USE_HPHL_TRIGGER,
6715 false);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006716 } else {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006717 /* Enable Mic Bias pull down and HPH Switch to GND */
6718 snd_soc_update_bits(codec,
6719 tabla->mbhc_bias_regs.ctl_reg, 0x01,
6720 0x01);
6721 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01,
6722 0x01);
6723 INIT_WORK(&tabla->hs_correct_plug_work,
6724 tabla_hs_correct_gpio_plug);
6725 }
Joonwoo Park03324832012-03-19 19:36:16 -07006726 } else {
6727 schedule_delayed_work(&tabla->mbhc_firmware_dwork,
6728 usecs_to_jiffies(MBHC_FW_READ_TIMEOUT));
6729 }
6730
6731 if (!IS_ERR_VALUE(rc)) {
6732 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10);
6733 wcd9xxx_enable_irq(codec->control_data,
6734 TABLA_IRQ_HPH_PA_OCPL_FAULT);
6735 wcd9xxx_enable_irq(codec->control_data,
6736 TABLA_IRQ_HPH_PA_OCPR_FAULT);
6737 }
6738
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006739 if (!IS_ERR_VALUE(rc) && tabla->mbhc_cfg.gpio) {
6740 rc = request_threaded_irq(tabla->mbhc_cfg.gpio_irq, NULL,
6741 tabla_mechanical_plug_detect_irq,
6742 (IRQF_TRIGGER_RISING |
6743 IRQF_TRIGGER_FALLING),
6744 "tabla-gpio", codec);
6745 if (!IS_ERR_VALUE(rc)) {
6746 rc = enable_irq_wake(tabla->mbhc_cfg.gpio_irq);
6747 /* Bootup time detection */
6748 tabla_hs_gpio_handler(codec);
6749 }
6750 }
6751
Joonwoo Park03324832012-03-19 19:36:16 -07006752 return rc;
6753}
6754EXPORT_SYMBOL_GPL(tabla_hs_detect);
6755
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006756static unsigned long slimbus_value;
6757
6758static irqreturn_t tabla_slimbus_irq(int irq, void *data)
6759{
6760 struct tabla_priv *priv = data;
6761 struct snd_soc_codec *codec = priv->codec;
6762 int i, j;
6763 u8 val;
6764
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306765 for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) {
6766 slimbus_value = wcd9xxx_interface_reg_read(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006767 TABLA_SLIM_PGD_PORT_INT_STATUS0 + i);
6768 for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306769 val = wcd9xxx_interface_reg_read(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006770 TABLA_SLIM_PGD_PORT_INT_SOURCE0 + i*8 + j);
6771 if (val & 0x1)
6772 pr_err_ratelimited("overflow error on port %x,"
6773 " value %x\n", i*8 + j, val);
6774 if (val & 0x2)
6775 pr_err_ratelimited("underflow error on port %x,"
6776 " value %x\n", i*8 + j, val);
6777 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306778 wcd9xxx_interface_reg_write(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006779 TABLA_SLIM_PGD_PORT_INT_CLR0 + i, 0xFF);
6780 }
6781
6782 return IRQ_HANDLED;
6783}
6784
Patrick Lai3043fba2011-08-01 14:15:57 -07006785
6786static int tabla_handle_pdata(struct tabla_priv *tabla)
6787{
6788 struct snd_soc_codec *codec = tabla->codec;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306789 struct wcd9xxx_pdata *pdata = tabla->pdata;
Patrick Lai3043fba2011-08-01 14:15:57 -07006790 int k1, k2, k3, rc = 0;
Santosh Mardi22920282011-10-26 02:38:40 +05306791 u8 leg_mode = pdata->amic_settings.legacy_mode;
6792 u8 txfe_bypass = pdata->amic_settings.txfe_enable;
6793 u8 txfe_buff = pdata->amic_settings.txfe_buff;
6794 u8 flag = pdata->amic_settings.use_pdata;
6795 u8 i = 0, j = 0;
6796 u8 val_txfe = 0, value = 0;
Patrick Lai3043fba2011-08-01 14:15:57 -07006797
6798 if (!pdata) {
6799 rc = -ENODEV;
6800 goto done;
6801 }
6802
6803 /* Make sure settings are correct */
6804 if ((pdata->micbias.ldoh_v > TABLA_LDOH_2P85_V) ||
6805 (pdata->micbias.bias1_cfilt_sel > TABLA_CFILT3_SEL) ||
6806 (pdata->micbias.bias2_cfilt_sel > TABLA_CFILT3_SEL) ||
6807 (pdata->micbias.bias3_cfilt_sel > TABLA_CFILT3_SEL) ||
6808 (pdata->micbias.bias4_cfilt_sel > TABLA_CFILT3_SEL)) {
6809 rc = -EINVAL;
6810 goto done;
6811 }
6812
6813 /* figure out k value */
6814 k1 = tabla_find_k_value(pdata->micbias.ldoh_v,
6815 pdata->micbias.cfilt1_mv);
6816 k2 = tabla_find_k_value(pdata->micbias.ldoh_v,
6817 pdata->micbias.cfilt2_mv);
6818 k3 = tabla_find_k_value(pdata->micbias.ldoh_v,
6819 pdata->micbias.cfilt3_mv);
6820
6821 if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) {
6822 rc = -EINVAL;
6823 goto done;
6824 }
6825
6826 /* Set voltage level and always use LDO */
6827 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x0C,
6828 (pdata->micbias.ldoh_v << 2));
6829
6830 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_1_VAL, 0xFC,
6831 (k1 << 2));
6832 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_2_VAL, 0xFC,
6833 (k2 << 2));
6834 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_3_VAL, 0xFC,
6835 (k3 << 2));
6836
6837 snd_soc_update_bits(codec, TABLA_A_MICB_1_CTL, 0x60,
6838 (pdata->micbias.bias1_cfilt_sel << 5));
6839 snd_soc_update_bits(codec, TABLA_A_MICB_2_CTL, 0x60,
6840 (pdata->micbias.bias2_cfilt_sel << 5));
6841 snd_soc_update_bits(codec, TABLA_A_MICB_3_CTL, 0x60,
6842 (pdata->micbias.bias3_cfilt_sel << 5));
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08006843 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_ctl, 0x60,
6844 (pdata->micbias.bias4_cfilt_sel << 5));
Patrick Lai3043fba2011-08-01 14:15:57 -07006845
Santosh Mardi22920282011-10-26 02:38:40 +05306846 for (i = 0; i < 6; j++, i += 2) {
6847 if (flag & (0x01 << i)) {
6848 value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00;
6849 val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00;
6850 val_txfe = val_txfe |
6851 ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00);
6852 snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10,
6853 0x10, value);
6854 snd_soc_update_bits(codec,
6855 TABLA_A_TX_1_2_TEST_EN + j * 10,
6856 0x30, val_txfe);
6857 }
6858 if (flag & (0x01 << (i + 1))) {
6859 value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00;
6860 val_txfe = (txfe_bypass &
6861 (0x01 << (i + 1))) ? 0x02 : 0x00;
6862 val_txfe |= (txfe_buff &
6863 (0x01 << (i + 1))) ? 0x01 : 0x00;
6864 snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10,
6865 0x01, value);
6866 snd_soc_update_bits(codec,
6867 TABLA_A_TX_1_2_TEST_EN + j * 10,
6868 0x03, val_txfe);
6869 }
6870 }
6871 if (flag & 0x40) {
6872 value = (leg_mode & 0x40) ? 0x10 : 0x00;
6873 value = value | ((txfe_bypass & 0x40) ? 0x02 : 0x00);
6874 value = value | ((txfe_buff & 0x40) ? 0x01 : 0x00);
6875 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN,
6876 0x13, value);
6877 }
Patrick Lai49efeac2011-11-03 11:01:12 -07006878
6879 if (pdata->ocp.use_pdata) {
6880 /* not defined in CODEC specification */
6881 if (pdata->ocp.hph_ocp_limit == 1 ||
6882 pdata->ocp.hph_ocp_limit == 5) {
6883 rc = -EINVAL;
6884 goto done;
6885 }
6886 snd_soc_update_bits(codec, TABLA_A_RX_COM_OCP_CTL,
6887 0x0F, pdata->ocp.num_attempts);
6888 snd_soc_write(codec, TABLA_A_RX_COM_OCP_COUNT,
6889 ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time));
6890 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL,
6891 0xE0, (pdata->ocp.hph_ocp_limit << 5));
6892 }
Joonwoo Park03324832012-03-19 19:36:16 -07006893
6894 for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
6895 if (!strncmp(pdata->regulator[i].name, "CDC_VDDA_RX", 11)) {
6896 if (pdata->regulator[i].min_uV == 1800000 &&
6897 pdata->regulator[i].max_uV == 1800000) {
6898 snd_soc_write(codec, TABLA_A_BIAS_REF_CTL,
6899 0x1C);
6900 } else if (pdata->regulator[i].min_uV == 2200000 &&
6901 pdata->regulator[i].max_uV == 2200000) {
6902 snd_soc_write(codec, TABLA_A_BIAS_REF_CTL,
6903 0x1E);
6904 } else {
6905 pr_err("%s: unsupported CDC_VDDA_RX voltage "
6906 "min %d, max %d\n", __func__,
6907 pdata->regulator[i].min_uV,
6908 pdata->regulator[i].max_uV);
6909 rc = -EINVAL;
6910 }
6911 break;
6912 }
6913 }
Patrick Lai3043fba2011-08-01 14:15:57 -07006914done:
6915 return rc;
6916}
6917
Kiran Kandi1f6fd722011-08-11 10:36:11 -07006918static const struct tabla_reg_mask_val tabla_1_1_reg_defaults[] = {
6919
6920 /* Tabla 1.1 MICBIAS changes */
6921 TABLA_REG_VAL(TABLA_A_MICB_1_INT_RBIAS, 0x24),
6922 TABLA_REG_VAL(TABLA_A_MICB_2_INT_RBIAS, 0x24),
6923 TABLA_REG_VAL(TABLA_A_MICB_3_INT_RBIAS, 0x24),
Kiran Kandi1f6fd722011-08-11 10:36:11 -07006924
6925 /* Tabla 1.1 HPH changes */
6926 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_PA, 0x57),
6927 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_LDO, 0x56),
6928
6929 /* Tabla 1.1 EAR PA changes */
6930 TABLA_REG_VAL(TABLA_A_RX_EAR_BIAS_PA, 0xA6),
6931 TABLA_REG_VAL(TABLA_A_RX_EAR_GAIN, 0x02),
6932 TABLA_REG_VAL(TABLA_A_RX_EAR_VCM, 0x03),
6933
6934 /* Tabla 1.1 Lineout_5 Changes */
6935 TABLA_REG_VAL(TABLA_A_RX_LINE_5_GAIN, 0x10),
6936
6937 /* Tabla 1.1 RX Changes */
6938 TABLA_REG_VAL(TABLA_A_CDC_RX1_B5_CTL, 0x78),
6939 TABLA_REG_VAL(TABLA_A_CDC_RX2_B5_CTL, 0x78),
6940 TABLA_REG_VAL(TABLA_A_CDC_RX3_B5_CTL, 0x78),
6941 TABLA_REG_VAL(TABLA_A_CDC_RX4_B5_CTL, 0x78),
6942 TABLA_REG_VAL(TABLA_A_CDC_RX5_B5_CTL, 0x78),
6943 TABLA_REG_VAL(TABLA_A_CDC_RX6_B5_CTL, 0x78),
6944 TABLA_REG_VAL(TABLA_A_CDC_RX7_B5_CTL, 0x78),
6945
6946 /* Tabla 1.1 RX1 and RX2 Changes */
6947 TABLA_REG_VAL(TABLA_A_CDC_RX1_B6_CTL, 0xA0),
6948 TABLA_REG_VAL(TABLA_A_CDC_RX2_B6_CTL, 0xA0),
6949
6950 /* Tabla 1.1 RX3 to RX7 Changes */
6951 TABLA_REG_VAL(TABLA_A_CDC_RX3_B6_CTL, 0x80),
6952 TABLA_REG_VAL(TABLA_A_CDC_RX4_B6_CTL, 0x80),
6953 TABLA_REG_VAL(TABLA_A_CDC_RX5_B6_CTL, 0x80),
6954 TABLA_REG_VAL(TABLA_A_CDC_RX6_B6_CTL, 0x80),
6955 TABLA_REG_VAL(TABLA_A_CDC_RX7_B6_CTL, 0x80),
6956
6957 /* Tabla 1.1 CLASSG Changes */
6958 TABLA_REG_VAL(TABLA_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B),
6959};
6960
6961static const struct tabla_reg_mask_val tabla_2_0_reg_defaults[] = {
Kiran Kandi1f6fd722011-08-11 10:36:11 -07006962 /* Tabla 2.0 MICBIAS changes */
6963 TABLA_REG_VAL(TABLA_A_MICB_2_MBHC, 0x02),
6964};
6965
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08006966static const struct tabla_reg_mask_val tabla_1_x_only_reg_2_0_defaults[] = {
6967 TABLA_REG_VAL(TABLA_1_A_MICB_4_INT_RBIAS, 0x24),
6968};
6969
6970static const struct tabla_reg_mask_val tabla_2_only_reg_2_0_defaults[] = {
6971 TABLA_REG_VAL(TABLA_2_A_MICB_4_INT_RBIAS, 0x24),
6972};
6973
Kiran Kandi1f6fd722011-08-11 10:36:11 -07006974static void tabla_update_reg_defaults(struct snd_soc_codec *codec)
6975{
6976 u32 i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306977 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Kiran Kandi1f6fd722011-08-11 10:36:11 -07006978
6979 for (i = 0; i < ARRAY_SIZE(tabla_1_1_reg_defaults); i++)
6980 snd_soc_write(codec, tabla_1_1_reg_defaults[i].reg,
6981 tabla_1_1_reg_defaults[i].val);
6982
6983 for (i = 0; i < ARRAY_SIZE(tabla_2_0_reg_defaults); i++)
6984 snd_soc_write(codec, tabla_2_0_reg_defaults[i].reg,
6985 tabla_2_0_reg_defaults[i].val);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08006986
6987 if (TABLA_IS_1_X(tabla_core->version)) {
6988 for (i = 0; i < ARRAY_SIZE(tabla_1_x_only_reg_2_0_defaults);
6989 i++)
6990 snd_soc_write(codec,
6991 tabla_1_x_only_reg_2_0_defaults[i].reg,
6992 tabla_1_x_only_reg_2_0_defaults[i].val);
6993 } else {
6994 for (i = 0; i < ARRAY_SIZE(tabla_2_only_reg_2_0_defaults); i++)
6995 snd_soc_write(codec,
6996 tabla_2_only_reg_2_0_defaults[i].reg,
6997 tabla_2_only_reg_2_0_defaults[i].val);
6998 }
Kiran Kandi1f6fd722011-08-11 10:36:11 -07006999}
7000
7001static const struct tabla_reg_mask_val tabla_codec_reg_init_val[] = {
Patrick Laic7cae882011-11-18 11:52:49 -08007002 /* Initialize current threshold to 350MA
7003 * number of wait and run cycles to 4096
7004 */
Patrick Lai49efeac2011-11-03 11:01:12 -07007005 {TABLA_A_RX_HPH_OCP_CTL, 0xE0, 0x60},
Patrick Laic7cae882011-11-18 11:52:49 -08007006 {TABLA_A_RX_COM_OCP_COUNT, 0xFF, 0xFF},
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007007
Santosh Mardi32171012011-10-28 23:32:06 +05307008 {TABLA_A_QFUSE_CTL, 0xFF, 0x03},
7009
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007010 /* Initialize gain registers to use register gain */
7011 {TABLA_A_RX_HPH_L_GAIN, 0x10, 0x10},
7012 {TABLA_A_RX_HPH_R_GAIN, 0x10, 0x10},
7013 {TABLA_A_RX_LINE_1_GAIN, 0x10, 0x10},
7014 {TABLA_A_RX_LINE_2_GAIN, 0x10, 0x10},
7015 {TABLA_A_RX_LINE_3_GAIN, 0x10, 0x10},
7016 {TABLA_A_RX_LINE_4_GAIN, 0x10, 0x10},
7017
7018 /* Initialize mic biases to differential mode */
7019 {TABLA_A_MICB_1_INT_RBIAS, 0x24, 0x24},
7020 {TABLA_A_MICB_2_INT_RBIAS, 0x24, 0x24},
7021 {TABLA_A_MICB_3_INT_RBIAS, 0x24, 0x24},
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007022
7023 {TABLA_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14},
7024
7025 /* Use 16 bit sample size for TX1 to TX6 */
7026 {TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20},
7027 {TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20},
7028 {TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20},
7029 {TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20},
7030 {TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20},
7031 {TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0x30, 0x20},
7032
7033 /* Use 16 bit sample size for TX7 to TX10 */
7034 {TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0x60, 0x40},
7035 {TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0x60, 0x40},
7036 {TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0x60, 0x40},
7037 {TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0x60, 0x40},
7038
7039 /* Use 16 bit sample size for RX */
7040 {TABLA_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA},
7041 {TABLA_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0xAA},
7042
7043 /*enable HPF filter for TX paths */
7044 {TABLA_A_CDC_TX1_MUX_CTL, 0x8, 0x0},
7045 {TABLA_A_CDC_TX2_MUX_CTL, 0x8, 0x0},
7046 {TABLA_A_CDC_TX3_MUX_CTL, 0x8, 0x0},
7047 {TABLA_A_CDC_TX4_MUX_CTL, 0x8, 0x0},
7048 {TABLA_A_CDC_TX5_MUX_CTL, 0x8, 0x0},
7049 {TABLA_A_CDC_TX6_MUX_CTL, 0x8, 0x0},
7050 {TABLA_A_CDC_TX7_MUX_CTL, 0x8, 0x0},
7051 {TABLA_A_CDC_TX8_MUX_CTL, 0x8, 0x0},
7052 {TABLA_A_CDC_TX9_MUX_CTL, 0x8, 0x0},
7053 {TABLA_A_CDC_TX10_MUX_CTL, 0x8, 0x0},
7054};
7055
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007056static const struct tabla_reg_mask_val tabla_1_x_codec_reg_init_val[] = {
7057 /* Initialize mic biases to differential mode */
7058 {TABLA_1_A_MICB_4_INT_RBIAS, 0x24, 0x24},
7059};
7060
7061static const struct tabla_reg_mask_val tabla_2_higher_codec_reg_init_val[] = {
7062 /* Initialize mic biases to differential mode */
7063 {TABLA_2_A_MICB_4_INT_RBIAS, 0x24, 0x24},
7064};
7065
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007066static void tabla_codec_init_reg(struct snd_soc_codec *codec)
7067{
7068 u32 i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307069 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007070
7071 for (i = 0; i < ARRAY_SIZE(tabla_codec_reg_init_val); i++)
7072 snd_soc_update_bits(codec, tabla_codec_reg_init_val[i].reg,
7073 tabla_codec_reg_init_val[i].mask,
7074 tabla_codec_reg_init_val[i].val);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007075 if (TABLA_IS_1_X(tabla_core->version)) {
7076 for (i = 0; i < ARRAY_SIZE(tabla_1_x_codec_reg_init_val); i++)
7077 snd_soc_update_bits(codec,
7078 tabla_1_x_codec_reg_init_val[i].reg,
7079 tabla_1_x_codec_reg_init_val[i].mask,
7080 tabla_1_x_codec_reg_init_val[i].val);
7081 } else {
7082 for (i = 0; i < ARRAY_SIZE(tabla_2_higher_codec_reg_init_val);
7083 i++)
7084 snd_soc_update_bits(codec,
7085 tabla_2_higher_codec_reg_init_val[i].reg,
7086 tabla_2_higher_codec_reg_init_val[i].mask,
7087 tabla_2_higher_codec_reg_init_val[i].val);
7088 }
7089}
7090
7091static void tabla_update_reg_address(struct tabla_priv *priv)
7092{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307093 struct wcd9xxx *tabla_core = dev_get_drvdata(priv->codec->dev->parent);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007094 struct tabla_reg_address *reg_addr = &priv->reg_addr;
7095
7096 if (TABLA_IS_1_X(tabla_core->version)) {
Joonwoo Parkcb7c8922012-02-16 23:12:59 -08007097 reg_addr->micb_4_mbhc = TABLA_1_A_MICB_4_MBHC;
7098 reg_addr->micb_4_int_rbias = TABLA_1_A_MICB_4_INT_RBIAS;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007099 reg_addr->micb_4_ctl = TABLA_1_A_MICB_4_CTL;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007100 } else if (TABLA_IS_2_0(tabla_core->version)) {
Joonwoo Parkcb7c8922012-02-16 23:12:59 -08007101 reg_addr->micb_4_mbhc = TABLA_2_A_MICB_4_MBHC;
7102 reg_addr->micb_4_int_rbias = TABLA_2_A_MICB_4_INT_RBIAS;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007103 reg_addr->micb_4_ctl = TABLA_2_A_MICB_4_CTL;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007104 }
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007105}
7106
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007107#ifdef CONFIG_DEBUG_FS
7108static int codec_debug_open(struct inode *inode, struct file *file)
7109{
7110 file->private_data = inode->i_private;
7111 return 0;
7112}
7113
7114static ssize_t codec_debug_write(struct file *filp,
7115 const char __user *ubuf, size_t cnt, loff_t *ppos)
7116{
7117 char lbuf[32];
7118 char *buf;
7119 int rc;
7120 struct tabla_priv *tabla = filp->private_data;
7121
7122 if (cnt > sizeof(lbuf) - 1)
7123 return -EINVAL;
7124
7125 rc = copy_from_user(lbuf, ubuf, cnt);
7126 if (rc)
7127 return -EFAULT;
7128
7129 lbuf[cnt] = '\0';
7130 buf = (char *)lbuf;
7131 tabla->no_mic_headset_override = (*strsep(&buf, " ") == '0') ?
7132 false : true;
7133 return rc;
7134}
7135
7136static ssize_t codec_mbhc_debug_read(struct file *file, char __user *buf,
7137 size_t count, loff_t *pos)
7138{
7139 const int size = 768;
7140 char buffer[size];
7141 int n = 0;
7142 struct tabla_priv *tabla = file->private_data;
7143 struct snd_soc_codec *codec = tabla->codec;
7144 const struct mbhc_internal_cal_data *p = &tabla->mbhc_data;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007145 const s16 v_ins_hu_cur = tabla_get_current_v_ins(tabla, true);
7146 const s16 v_ins_h_cur = tabla_get_current_v_ins(tabla, false);
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007147
7148 n = scnprintf(buffer, size - n, "dce_z = %x(%dmv)\n", p->dce_z,
7149 tabla_codec_sta_dce_v(codec, 1, p->dce_z));
7150 n += scnprintf(buffer + n, size - n, "dce_mb = %x(%dmv)\n",
7151 p->dce_mb, tabla_codec_sta_dce_v(codec, 1, p->dce_mb));
7152 n += scnprintf(buffer + n, size - n, "sta_z = %x(%dmv)\n",
7153 p->sta_z, tabla_codec_sta_dce_v(codec, 0, p->sta_z));
7154 n += scnprintf(buffer + n, size - n, "sta_mb = %x(%dmv)\n",
7155 p->sta_mb, tabla_codec_sta_dce_v(codec, 0, p->sta_mb));
7156 n += scnprintf(buffer + n, size - n, "t_dce = %x\n", p->t_dce);
7157 n += scnprintf(buffer + n, size - n, "t_sta = %x\n", p->t_sta);
7158 n += scnprintf(buffer + n, size - n, "micb_mv = %dmv\n",
7159 p->micb_mv);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007160 n += scnprintf(buffer + n, size - n, "v_ins_hu = %x(%dmv)%s\n",
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007161 p->v_ins_hu,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007162 tabla_codec_sta_dce_v(codec, 0, p->v_ins_hu),
7163 p->v_ins_hu == v_ins_hu_cur ? "*" : "");
7164 n += scnprintf(buffer + n, size - n, "v_ins_h = %x(%dmv)%s\n",
7165 p->v_ins_h, tabla_codec_sta_dce_v(codec, 1, p->v_ins_h),
7166 p->v_ins_h == v_ins_h_cur ? "*" : "");
7167 n += scnprintf(buffer + n, size - n, "adj_v_ins_hu = %x(%dmv)%s\n",
7168 p->adj_v_ins_hu,
7169 tabla_codec_sta_dce_v(codec, 0, p->adj_v_ins_hu),
7170 p->adj_v_ins_hu == v_ins_hu_cur ? "*" : "");
7171 n += scnprintf(buffer + n, size - n, "adj_v_ins_h = %x(%dmv)%s\n",
7172 p->adj_v_ins_h,
7173 tabla_codec_sta_dce_v(codec, 1, p->adj_v_ins_h),
7174 p->adj_v_ins_h == v_ins_h_cur ? "*" : "");
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007175 n += scnprintf(buffer + n, size - n, "v_b1_hu = %x(%dmv)\n",
7176 p->v_b1_hu, tabla_codec_sta_dce_v(codec, 0, p->v_b1_hu));
7177 n += scnprintf(buffer + n, size - n, "v_b1_h = %x(%dmv)\n",
7178 p->v_b1_h, tabla_codec_sta_dce_v(codec, 1, p->v_b1_h));
7179 n += scnprintf(buffer + n, size - n, "v_b1_huc = %x(%dmv)\n",
7180 p->v_b1_huc,
7181 tabla_codec_sta_dce_v(codec, 1, p->v_b1_huc));
7182 n += scnprintf(buffer + n, size - n, "v_brh = %x(%dmv)\n",
7183 p->v_brh, tabla_codec_sta_dce_v(codec, 1, p->v_brh));
7184 n += scnprintf(buffer + n, size - n, "v_brl = %x(%dmv)\n", p->v_brl,
7185 tabla_codec_sta_dce_v(codec, 0, p->v_brl));
7186 n += scnprintf(buffer + n, size - n, "v_no_mic = %x(%dmv)\n",
7187 p->v_no_mic,
7188 tabla_codec_sta_dce_v(codec, 0, p->v_no_mic));
7189 n += scnprintf(buffer + n, size - n, "npoll = %d\n", p->npoll);
7190 n += scnprintf(buffer + n, size - n, "nbounce_wait = %d\n",
7191 p->nbounce_wait);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007192 n += scnprintf(buffer + n, size - n, "v_inval_ins_low = %d\n",
7193 p->v_inval_ins_low);
7194 n += scnprintf(buffer + n, size - n, "v_inval_ins_high = %d\n",
7195 p->v_inval_ins_high);
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007196 buffer[n] = 0;
7197
7198 return simple_read_from_buffer(buf, count, pos, buffer, n);
7199}
7200
7201static const struct file_operations codec_debug_ops = {
7202 .open = codec_debug_open,
7203 .write = codec_debug_write,
7204};
7205
7206static const struct file_operations codec_mbhc_debug_ops = {
7207 .open = codec_debug_open,
7208 .read = codec_mbhc_debug_read,
7209};
7210#endif
7211
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007212static int tabla_codec_probe(struct snd_soc_codec *codec)
7213{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307214 struct wcd9xxx *control;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007215 struct tabla_priv *tabla;
7216 struct snd_soc_dapm_context *dapm = &codec->dapm;
7217 int ret = 0;
7218 int i;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08007219 int ch_cnt;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007220
7221 codec->control_data = dev_get_drvdata(codec->dev->parent);
7222 control = codec->control_data;
7223
7224 tabla = kzalloc(sizeof(struct tabla_priv), GFP_KERNEL);
7225 if (!tabla) {
7226 dev_err(codec->dev, "Failed to allocate private data\n");
7227 return -ENOMEM;
7228 }
Kiran Kandid8cf5212012-03-02 15:34:53 -08007229 for (i = 0 ; i < NUM_DECIMATORS; i++) {
7230 tx_hpf_work[i].tabla = tabla;
7231 tx_hpf_work[i].decimator = i + 1;
7232 INIT_DELAYED_WORK(&tx_hpf_work[i].dwork,
7233 tx_hpf_corner_freq_callback);
7234 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007235
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07007236 /* Make sure mbhc micbias register addresses are zeroed out */
7237 memset(&tabla->mbhc_bias_regs, 0,
7238 sizeof(struct mbhc_micbias_regs));
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07007239 tabla->mbhc_micbias_switched = false;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07007240
Joonwoo Park0976d012011-12-22 11:48:18 -08007241 /* Make sure mbhc intenal calibration data is zeroed out */
7242 memset(&tabla->mbhc_data, 0,
7243 sizeof(struct mbhc_internal_cal_data));
Joonwoo Park433149a2012-01-11 09:53:54 -08007244 tabla->mbhc_data.t_sta_dce = DEFAULT_DCE_STA_WAIT;
Joonwoo Park0976d012011-12-22 11:48:18 -08007245 tabla->mbhc_data.t_dce = DEFAULT_DCE_WAIT;
7246 tabla->mbhc_data.t_sta = DEFAULT_STA_WAIT;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007247 snd_soc_codec_set_drvdata(codec, tabla);
7248
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07007249 tabla->mclk_enabled = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007250 tabla->bandgap_type = TABLA_BANDGAP_OFF;
7251 tabla->clock_active = false;
7252 tabla->config_mode_active = false;
7253 tabla->mbhc_polling_active = false;
Joonwoo Parkf4267c22012-01-10 13:25:24 -08007254 tabla->mbhc_fake_ins_start = 0;
Bradley Rubincb3950a2011-08-18 13:07:26 -07007255 tabla->no_mic_headset_override = false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007256 tabla->hs_polling_irq_prepared = false;
7257 mutex_init(&tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007258 tabla->codec = codec;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007259 tabla->mbhc_state = MBHC_STATE_NONE;
Joonwoo Park03324832012-03-19 19:36:16 -07007260 tabla->mbhc_last_resume = 0;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08007261 for (i = 0; i < COMPANDER_MAX; i++) {
7262 tabla->comp_enabled[i] = 0;
7263 tabla->comp_fs[i] = COMPANDER_FS_48KHZ;
7264 }
Patrick Lai3043fba2011-08-01 14:15:57 -07007265 tabla->pdata = dev_get_platdata(codec->dev->parent);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307266 tabla->intf_type = wcd9xxx_get_intf_type();
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08007267 tabla->aux_pga_cnt = 0;
7268 tabla->aux_l_gain = 0x1F;
7269 tabla->aux_r_gain = 0x1F;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007270 tabla_update_reg_address(tabla);
Santosh Mardi22920282011-10-26 02:38:40 +05307271 tabla_update_reg_defaults(codec);
7272 tabla_codec_init_reg(codec);
Santosh Mardi22920282011-10-26 02:38:40 +05307273 ret = tabla_handle_pdata(tabla);
Patrick Lai3043fba2011-08-01 14:15:57 -07007274 if (IS_ERR_VALUE(ret)) {
7275 pr_err("%s: bad pdata\n", __func__);
7276 goto err_pdata;
7277 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007278
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007279 snd_soc_add_controls(codec, tabla_snd_controls,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007280 ARRAY_SIZE(tabla_snd_controls));
7281 if (TABLA_IS_1_X(control->version))
7282 snd_soc_add_controls(codec, tabla_1_x_snd_controls,
7283 ARRAY_SIZE(tabla_1_x_snd_controls));
7284 else
7285 snd_soc_add_controls(codec, tabla_2_higher_snd_controls,
7286 ARRAY_SIZE(tabla_2_higher_snd_controls));
7287
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007288 snd_soc_dapm_new_controls(dapm, tabla_dapm_widgets,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007289 ARRAY_SIZE(tabla_dapm_widgets));
7290 if (TABLA_IS_1_X(control->version))
7291 snd_soc_dapm_new_controls(dapm, tabla_1_x_dapm_widgets,
7292 ARRAY_SIZE(tabla_1_x_dapm_widgets));
7293 else
7294 snd_soc_dapm_new_controls(dapm, tabla_2_higher_dapm_widgets,
7295 ARRAY_SIZE(tabla_2_higher_dapm_widgets));
7296
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307297 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05307298 snd_soc_dapm_new_controls(dapm, tabla_dapm_i2s_widgets,
7299 ARRAY_SIZE(tabla_dapm_i2s_widgets));
7300 snd_soc_dapm_add_routes(dapm, audio_i2s_map,
7301 ARRAY_SIZE(audio_i2s_map));
7302 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007303 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Kiran Kandi8b3a8302011-09-27 16:13:28 -07007304
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007305 if (TABLA_IS_1_X(control->version)) {
Kiran Kandi7a9fd902011-11-14 13:51:45 -08007306 snd_soc_dapm_add_routes(dapm, tabla_1_x_lineout_2_to_4_map,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007307 ARRAY_SIZE(tabla_1_x_lineout_2_to_4_map));
7308 } else if (TABLA_IS_2_0(control->version)) {
Kiran Kandi7a9fd902011-11-14 13:51:45 -08007309 snd_soc_dapm_add_routes(dapm, tabla_2_x_lineout_2_to_4_map,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007310 ARRAY_SIZE(tabla_2_x_lineout_2_to_4_map));
Kiran Kandi7a9fd902011-11-14 13:51:45 -08007311 } else {
7312 pr_err("%s : ERROR. Unsupported Tabla version 0x%2x\n",
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307313 __func__, control->version);
Kiran Kandi7a9fd902011-11-14 13:51:45 -08007314 goto err_pdata;
7315 }
7316
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007317 snd_soc_dapm_sync(dapm);
7318
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307319 ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007320 tabla_hs_insert_irq, "Headset insert detect", tabla);
7321 if (ret) {
7322 pr_err("%s: Failed to request irq %d\n", __func__,
7323 TABLA_IRQ_MBHC_INSERTION);
7324 goto err_insert_irq;
7325 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307326 wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007327
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307328 ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007329 tabla_hs_remove_irq, "Headset remove detect", tabla);
7330 if (ret) {
7331 pr_err("%s: Failed to request irq %d\n", __func__,
7332 TABLA_IRQ_MBHC_REMOVAL);
7333 goto err_remove_irq;
7334 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007335
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307336 ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07007337 tabla_dce_handler, "DC Estimation detect", tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007338 if (ret) {
7339 pr_err("%s: Failed to request irq %d\n", __func__,
7340 TABLA_IRQ_MBHC_POTENTIAL);
7341 goto err_potential_irq;
7342 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007343
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307344 ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE,
Bradley Rubincb1e2732011-06-23 16:49:20 -07007345 tabla_release_handler, "Button Release detect", tabla);
7346 if (ret) {
7347 pr_err("%s: Failed to request irq %d\n", __func__,
7348 TABLA_IRQ_MBHC_RELEASE);
7349 goto err_release_irq;
7350 }
7351
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307352 ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_SLIMBUS,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007353 tabla_slimbus_irq, "SLIMBUS Slave", tabla);
7354 if (ret) {
7355 pr_err("%s: Failed to request irq %d\n", __func__,
7356 TABLA_IRQ_SLIMBUS);
7357 goto err_slimbus_irq;
7358 }
7359
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307360 for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++)
7361 wcd9xxx_interface_reg_write(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007362 TABLA_SLIM_PGD_PORT_INT_EN0 + i, 0xFF);
7363
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307364 ret = wcd9xxx_request_irq(codec->control_data,
Patrick Lai49efeac2011-11-03 11:01:12 -07007365 TABLA_IRQ_HPH_PA_OCPL_FAULT, tabla_hphl_ocp_irq,
7366 "HPH_L OCP detect", tabla);
7367 if (ret) {
7368 pr_err("%s: Failed to request irq %d\n", __func__,
7369 TABLA_IRQ_HPH_PA_OCPL_FAULT);
7370 goto err_hphl_ocp_irq;
7371 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307372 wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_HPH_PA_OCPL_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07007373
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307374 ret = wcd9xxx_request_irq(codec->control_data,
Patrick Lai49efeac2011-11-03 11:01:12 -07007375 TABLA_IRQ_HPH_PA_OCPR_FAULT, tabla_hphr_ocp_irq,
7376 "HPH_R OCP detect", tabla);
7377 if (ret) {
7378 pr_err("%s: Failed to request irq %d\n", __func__,
7379 TABLA_IRQ_HPH_PA_OCPR_FAULT);
7380 goto err_hphr_ocp_irq;
7381 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307382 wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_HPH_PA_OCPR_FAULT);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08007383 for (i = 0; i < ARRAY_SIZE(tabla_dai); i++) {
7384 switch (tabla_dai[i].id) {
7385 case AIF1_PB:
7386 ch_cnt = tabla_dai[i].playback.channels_max;
7387 break;
7388 case AIF1_CAP:
7389 ch_cnt = tabla_dai[i].capture.channels_max;
7390 break;
Neema Shettyd3a89262012-02-16 10:23:50 -08007391 case AIF2_PB:
7392 ch_cnt = tabla_dai[i].playback.channels_max;
7393 break;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07007394 case AIF2_CAP:
7395 ch_cnt = tabla_dai[i].capture.channels_max;
7396 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08007397 default:
7398 continue;
7399 }
7400 tabla->dai[i].ch_num = kzalloc((sizeof(unsigned int)*
7401 ch_cnt), GFP_KERNEL);
7402 }
Patrick Lai49efeac2011-11-03 11:01:12 -07007403
Bradley Rubincb3950a2011-08-18 13:07:26 -07007404#ifdef CONFIG_DEBUG_FS
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007405 if (ret == 0) {
7406 tabla->debugfs_poke =
7407 debugfs_create_file("TRRS", S_IFREG | S_IRUGO, NULL, tabla,
7408 &codec_debug_ops);
7409 tabla->debugfs_mbhc =
7410 debugfs_create_file("tabla_mbhc", S_IFREG | S_IRUGO,
7411 NULL, tabla, &codec_mbhc_debug_ops);
7412 }
Bradley Rubincb3950a2011-08-18 13:07:26 -07007413#endif
7414
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007415 return ret;
7416
Patrick Lai49efeac2011-11-03 11:01:12 -07007417err_hphr_ocp_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307418 wcd9xxx_free_irq(codec->control_data,
7419 TABLA_IRQ_HPH_PA_OCPL_FAULT, tabla);
Patrick Lai49efeac2011-11-03 11:01:12 -07007420err_hphl_ocp_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307421 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_SLIMBUS, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007422err_slimbus_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307423 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, tabla);
Bradley Rubincb1e2732011-06-23 16:49:20 -07007424err_release_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307425 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007426err_potential_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307427 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007428err_remove_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307429 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007430err_insert_irq:
Patrick Lai3043fba2011-08-01 14:15:57 -07007431err_pdata:
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007432 mutex_destroy(&tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007433 kfree(tabla);
7434 return ret;
7435}
7436static int tabla_codec_remove(struct snd_soc_codec *codec)
7437{
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08007438 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007439 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307440 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_SLIMBUS, tabla);
7441 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, tabla);
7442 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, tabla);
7443 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, tabla);
7444 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007445 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007446 tabla_codec_disable_clock_block(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007447 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007448 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF);
Patrick Lai64b43262011-12-06 17:29:15 -08007449 if (tabla->mbhc_fw)
7450 release_firmware(tabla->mbhc_fw);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08007451 for (i = 0; i < ARRAY_SIZE(tabla_dai); i++)
7452 kfree(tabla->dai[i].ch_num);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007453 mutex_destroy(&tabla->codec_resource_lock);
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007454#ifdef CONFIG_DEBUG_FS
7455 debugfs_remove(tabla->debugfs_poke);
7456 debugfs_remove(tabla->debugfs_mbhc);
7457#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007458 kfree(tabla);
7459 return 0;
7460}
7461static struct snd_soc_codec_driver soc_codec_dev_tabla = {
7462 .probe = tabla_codec_probe,
7463 .remove = tabla_codec_remove,
7464 .read = tabla_read,
7465 .write = tabla_write,
7466
7467 .readable_register = tabla_readable,
7468 .volatile_register = tabla_volatile,
7469
7470 .reg_cache_size = TABLA_CACHE_SIZE,
7471 .reg_cache_default = tabla_reg_defaults,
7472 .reg_word_size = 1,
7473};
Bradley Rubincb3950a2011-08-18 13:07:26 -07007474
Joonwoo Park8b1f0982011-12-08 17:12:45 -08007475#ifdef CONFIG_PM
7476static int tabla_suspend(struct device *dev)
7477{
Joonwoo Park816b8e62012-01-23 16:03:21 -08007478 dev_dbg(dev, "%s: system suspend\n", __func__);
7479 return 0;
Joonwoo Park8b1f0982011-12-08 17:12:45 -08007480}
7481
7482static int tabla_resume(struct device *dev)
7483{
Joonwoo Park03324832012-03-19 19:36:16 -07007484 struct platform_device *pdev = to_platform_device(dev);
7485 struct tabla_priv *tabla = platform_get_drvdata(pdev);
Joonwoo Park816b8e62012-01-23 16:03:21 -08007486 dev_dbg(dev, "%s: system resume\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07007487 tabla->mbhc_last_resume = jiffies;
Joonwoo Park816b8e62012-01-23 16:03:21 -08007488 return 0;
Joonwoo Park8b1f0982011-12-08 17:12:45 -08007489}
7490
7491static const struct dev_pm_ops tabla_pm_ops = {
7492 .suspend = tabla_suspend,
7493 .resume = tabla_resume,
7494};
7495#endif
7496
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007497static int __devinit tabla_probe(struct platform_device *pdev)
7498{
Santosh Mardie15e2302011-11-15 10:39:23 +05307499 int ret = 0;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307500 if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
Santosh Mardie15e2302011-11-15 10:39:23 +05307501 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla,
7502 tabla_dai, ARRAY_SIZE(tabla_dai));
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307503 else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C)
Santosh Mardie15e2302011-11-15 10:39:23 +05307504 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla,
7505 tabla_i2s_dai, ARRAY_SIZE(tabla_i2s_dai));
7506 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007507}
7508static int __devexit tabla_remove(struct platform_device *pdev)
7509{
7510 snd_soc_unregister_codec(&pdev->dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007511 return 0;
7512}
7513static struct platform_driver tabla_codec_driver = {
7514 .probe = tabla_probe,
7515 .remove = tabla_remove,
7516 .driver = {
7517 .name = "tabla_codec",
7518 .owner = THIS_MODULE,
Joonwoo Park8b1f0982011-12-08 17:12:45 -08007519#ifdef CONFIG_PM
7520 .pm = &tabla_pm_ops,
7521#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007522 },
7523};
7524
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08007525static struct platform_driver tabla1x_codec_driver = {
7526 .probe = tabla_probe,
7527 .remove = tabla_remove,
7528 .driver = {
7529 .name = "tabla1x_codec",
7530 .owner = THIS_MODULE,
7531#ifdef CONFIG_PM
7532 .pm = &tabla_pm_ops,
7533#endif
7534 },
7535};
7536
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007537static int __init tabla_codec_init(void)
7538{
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08007539 int rtn = platform_driver_register(&tabla_codec_driver);
7540 if (rtn == 0) {
7541 rtn = platform_driver_register(&tabla1x_codec_driver);
7542 if (rtn != 0)
7543 platform_driver_unregister(&tabla_codec_driver);
7544 }
7545 return rtn;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007546}
7547
7548static void __exit tabla_codec_exit(void)
7549{
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08007550 platform_driver_unregister(&tabla1x_codec_driver);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007551 platform_driver_unregister(&tabla_codec_driver);
7552}
7553
7554module_init(tabla_codec_init);
7555module_exit(tabla_codec_exit);
7556
7557MODULE_DESCRIPTION("Tabla codec driver");
7558MODULE_VERSION("1.0");
7559MODULE_LICENSE("GPL v2");