blob: 29703b93a1ab3b025637bfb8afdd69a2eae6389e [file] [log] [blame]
Simmi Pateriya1b9a3092013-01-02 11:49:26 +05301/* Copyright (c) 2011-2013, The Linux Foundation. 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>
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -070021#include <linux/wait.h>
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +053022#include <linux/mfd/wcd9xxx/core.h>
23#include <linux/mfd/wcd9xxx/wcd9xxx_registers.h>
24#include <linux/mfd/wcd9xxx/wcd9310_registers.h>
25#include <linux/mfd/wcd9xxx/pdata.h>
Santosh Mardie15e2302011-11-15 10:39:23 +053026#include <sound/pcm.h>
27#include <sound/pcm_params.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070028#include <sound/soc.h>
29#include <sound/soc-dapm.h>
30#include <sound/tlv.h>
31#include <linux/bitops.h>
32#include <linux/delay.h>
Kuirong Wanga545e722012-02-06 19:12:54 -080033#include <linux/pm_runtime.h>
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -070034#include <linux/kernel.h>
35#include <linux/gpio.h>
Joonwoo Parkecf379c2012-10-04 16:57:52 -070036#include <linux/irq.h>
37#include <linux/wakelock.h>
38#include <linux/suspend.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039#include "wcd9310.h"
40
Joonwoo Parkc1c67a92012-08-07 16:05:36 -070041static int cfilt_adjust_ms = 10;
42module_param(cfilt_adjust_ms, int, 0644);
43MODULE_PARM_DESC(cfilt_adjust_ms, "delay after adjusting cfilt voltage in ms");
44
Kiran Kandi1e6371d2012-03-29 11:48:57 -070045#define WCD9310_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
46 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
47 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
48
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -070049
50#define NUM_DECIMATORS 10
51#define NUM_INTERPOLATORS 7
52#define BITS_PER_REG 8
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -080053#define TABLA_CFILT_FAST_MODE 0x00
54#define TABLA_CFILT_SLOW_MODE 0x40
Patrick Lai64b43262011-12-06 17:29:15 -080055#define MBHC_FW_READ_ATTEMPTS 15
56#define MBHC_FW_READ_TIMEOUT 2000000
Simmi Pateriyad60186a2012-11-27 13:50:11 +053057#define MBHC_VDDIO_SWITCH_WAIT_MS 10
Kuirong Wang57b4d892013-02-11 09:54:45 -080058#define COMP_DIGITAL_DB_GAIN_APPLY(a, b) \
59 (((a) <= 0) ? ((a) - b) : (a))
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -070060
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -070061#define SLIM_CLOSE_TIMEOUT 1000
Kuirong Wang84ee8802013-02-09 12:52:06 -080062/* The wait time value comes from codec HW specification */
63#define COMP_BRINGUP_WAIT_TIME 2000
Joonwoo Park03324832012-03-19 19:36:16 -070064enum {
65 MBHC_USE_HPHL_TRIGGER = 1,
66 MBHC_USE_MB_TRIGGER = 2
67};
68
69#define MBHC_NUM_DCE_PLUG_DETECT 3
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -070070#define NUM_ATTEMPTS_INSERT_DETECT 25
71#define NUM_ATTEMPTS_TO_REPORT 5
Joonwoo Park03324832012-03-19 19:36:16 -070072
Joonwoo Park2cc13f02012-05-09 12:44:25 -070073#define TABLA_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | \
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -070074 SND_JACK_OC_HPHR | SND_JACK_LINEOUT | \
75 SND_JACK_UNSUPPORTED)
Patrick Lai49efeac2011-11-03 11:01:12 -070076
Santosh Mardie15e2302011-11-15 10:39:23 +053077#define TABLA_I2S_MASTER_MODE_MASK 0x08
78
Patrick Laic7cae882011-11-18 11:52:49 -080079#define TABLA_OCP_ATTEMPT 1
80
Kuirong Wang906ac472012-07-09 12:54:44 -070081enum {
82 AIF1_PB = 0,
83 AIF1_CAP,
84 AIF2_PB,
85 AIF2_CAP,
86 AIF3_PB,
87 AIF3_CAP,
88 NUM_CODEC_DAIS,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -080089};
90
Kuirong Wang906ac472012-07-09 12:54:44 -070091enum {
92 RX_MIX1_INP_SEL_ZERO = 0,
93 RX_MIX1_INP_SEL_SRC1,
94 RX_MIX1_INP_SEL_SRC2,
95 RX_MIX1_INP_SEL_IIR1,
96 RX_MIX1_INP_SEL_IIR2,
97 RX_MIX1_INP_SEL_RX1,
98 RX_MIX1_INP_SEL_RX2,
99 RX_MIX1_INP_SEL_RX3,
100 RX_MIX1_INP_SEL_RX4,
101 RX_MIX1_INP_SEL_RX5,
102 RX_MIX1_INP_SEL_RX6,
103 RX_MIX1_INP_SEL_RX7,
104};
Kuirong Wang57b4d892013-02-11 09:54:45 -0800105#define MAX_PA_GAIN_OPTIONS 13
Kuirong Wang906ac472012-07-09 12:54:44 -0700106
Joonwoo Park0976d012011-12-22 11:48:18 -0800107#define TABLA_MCLK_RATE_12288KHZ 12288000
108#define TABLA_MCLK_RATE_9600KHZ 9600000
109
Joonwoo Parkf4267c22012-01-10 13:25:24 -0800110#define TABLA_FAKE_INS_THRESHOLD_MS 2500
Joonwoo Park6b9b03f2012-01-23 18:48:54 -0800111#define TABLA_FAKE_REMOVAL_MIN_PERIOD_MS 50
Joonwoo Parkf4267c22012-01-10 13:25:24 -0800112
Joonwoo Park03324832012-03-19 19:36:16 -0700113#define TABLA_MBHC_BUTTON_MIN 0x8000
114
Joonwoo Park03324832012-03-19 19:36:16 -0700115#define TABLA_MBHC_FAKE_INSERT_LOW 10
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700116#define TABLA_MBHC_FAKE_INSERT_HIGH 80
117#define TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO 150
Joonwoo Park03324832012-03-19 19:36:16 -0700118
119#define TABLA_MBHC_STATUS_REL_DETECTION 0x0C
120
Joonwoo Parkdb606b02012-08-11 13:46:30 -0700121#define TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS 50
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700122
Joonwoo Parkcf473b42012-03-29 19:48:16 -0700123#define TABLA_MBHC_FAKE_INS_DELTA_MV 200
124#define TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV 300
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700125
126#define TABLA_HS_DETECT_PLUG_TIME_MS (5 * 1000)
127#define TABLA_HS_DETECT_PLUG_INERVAL_MS 100
128
129#define TABLA_GPIO_IRQ_DEBOUNCE_TIME_US 5000
130
Joonwoo Park2cc13f02012-05-09 12:44:25 -0700131#define TABLA_MBHC_GND_MIC_SWAP_THRESHOLD 2
132
Joonwoo Park1f9d7fd2013-01-07 12:40:03 -0800133#define TABLA_ACQUIRE_LOCK(x) do { \
134 mutex_lock_nested(&x, SINGLE_DEPTH_NESTING); \
135} while (0)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700136#define TABLA_RELEASE_LOCK(x) do { mutex_unlock(&x); } while (0)
137
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700138static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
139static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
140static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800141static struct snd_soc_dai_driver tabla_dai[];
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -0800142static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0);
Kiran Kandi93923902012-06-20 17:00:25 -0700143static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
144 struct snd_kcontrol *kcontrol, int event);
145static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
146 struct snd_kcontrol *kcontrol, int event);
147
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700148
149enum tabla_bandgap_type {
150 TABLA_BANDGAP_OFF = 0,
151 TABLA_BANDGAP_AUDIO_MODE,
152 TABLA_BANDGAP_MBHC_MODE,
153};
154
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700155struct mbhc_micbias_regs {
156 u16 cfilt_val;
157 u16 cfilt_ctl;
158 u16 mbhc_reg;
159 u16 int_rbias;
160 u16 ctl_reg;
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -0800161 u8 cfilt_sel;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700162};
163
Ben Romberger1f045a72011-11-04 10:14:57 -0700164/* Codec supports 2 IIR filters */
165enum {
166 IIR1 = 0,
167 IIR2,
168 IIR_MAX,
169};
170/* Codec supports 5 bands */
171enum {
172 BAND1 = 0,
173 BAND2,
174 BAND3,
175 BAND4,
176 BAND5,
177 BAND_MAX,
178};
179
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800180enum {
181 COMPANDER_1 = 0,
182 COMPANDER_2,
183 COMPANDER_MAX,
184};
185
186enum {
187 COMPANDER_FS_8KHZ = 0,
188 COMPANDER_FS_16KHZ,
189 COMPANDER_FS_32KHZ,
190 COMPANDER_FS_48KHZ,
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700191 COMPANDER_FS_96KHZ,
192 COMPANDER_FS_192KHZ,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800193 COMPANDER_FS_MAX,
194};
195
Kuirong Wang678e4172012-06-26 15:35:22 -0700196enum {
197 COMP_SHUTDWN_TIMEOUT_PCM_1 = 0,
198 COMP_SHUTDWN_TIMEOUT_PCM_240,
199 COMP_SHUTDWN_TIMEOUT_PCM_480,
200 COMP_SHUTDWN_TIMEOUT_PCM_960,
201 COMP_SHUTDWN_TIMEOUT_PCM_1440,
202 COMP_SHUTDWN_TIMEOUT_PCM_2880,
203 COMP_SHUTDWN_TIMEOUT_PCM_5760,
204};
205
Joonwoo Parka9444452011-12-08 18:48:27 -0800206/* Flags to track of PA and DAC state.
207 * PA and DAC should be tracked separately as AUXPGA loopback requires
208 * only PA to be turned on without DAC being on. */
209enum tabla_priv_ack_flags {
210 TABLA_HPHL_PA_OFF_ACK = 0,
211 TABLA_HPHR_PA_OFF_ACK,
212 TABLA_HPHL_DAC_OFF_ACK,
213 TABLA_HPHR_DAC_OFF_ACK
214};
215
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800216
217struct comp_sample_dependent_params {
218 u32 peak_det_timeout;
219 u32 rms_meter_div_fact;
220 u32 rms_meter_resamp_fact;
Kuirong Wang678e4172012-06-26 15:35:22 -0700221 u32 shutdown_timeout;
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800222};
223
Kuirong Wang57b4d892013-02-11 09:54:45 -0800224struct comp_dgtl_gain_offset {
225 u8 whole_db_gain;
226 u8 half_db_gain;
227};
228
229static const struct comp_dgtl_gain_offset
230 comp_dgtl_gain[MAX_PA_GAIN_OPTIONS] = {
231 {0, 0},
232 {1, 1},
233 {3, 0},
234 {4, 1},
235 {6, 0},
236 {7, 1},
237 {9, 0},
238 {10, 1},
239 {12, 0},
240 {13, 1},
241 {15, 0},
242 {16, 1},
243 {18, 0},
244};
245
Joonwoo Park0976d012011-12-22 11:48:18 -0800246/* Data used by MBHC */
247struct mbhc_internal_cal_data {
248 u16 dce_z;
249 u16 dce_mb;
250 u16 sta_z;
251 u16 sta_mb;
Joonwoo Park433149a2012-01-11 09:53:54 -0800252 u32 t_sta_dce;
Joonwoo Park0976d012011-12-22 11:48:18 -0800253 u32 t_dce;
254 u32 t_sta;
255 u32 micb_mv;
256 u16 v_ins_hu;
257 u16 v_ins_h;
258 u16 v_b1_hu;
259 u16 v_b1_h;
260 u16 v_b1_huc;
261 u16 v_brh;
262 u16 v_brl;
263 u16 v_no_mic;
Joonwoo Park0976d012011-12-22 11:48:18 -0800264 u8 npoll;
265 u8 nbounce_wait;
Joonwoo Parkcf473b42012-03-29 19:48:16 -0700266 s16 adj_v_hs_max;
267 u16 adj_v_ins_hu;
268 u16 adj_v_ins_h;
269 s16 v_inval_ins_low;
270 s16 v_inval_ins_high;
Joonwoo Park0976d012011-12-22 11:48:18 -0800271};
272
Joonwoo Park6c1ebb62012-01-16 19:08:43 -0800273struct tabla_reg_address {
274 u16 micb_4_ctl;
275 u16 micb_4_int_rbias;
276 u16 micb_4_mbhc;
277};
278
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700279enum tabla_mbhc_plug_type {
Joonwoo Park41956722012-04-18 13:13:07 -0700280 PLUG_TYPE_INVALID = -1,
281 PLUG_TYPE_NONE,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700282 PLUG_TYPE_HEADSET,
283 PLUG_TYPE_HEADPHONE,
284 PLUG_TYPE_HIGH_HPH,
Joonwoo Park2cc13f02012-05-09 12:44:25 -0700285 PLUG_TYPE_GND_MIC_SWAP,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700286};
287
288enum tabla_mbhc_state {
289 MBHC_STATE_NONE = -1,
290 MBHC_STATE_POTENTIAL,
291 MBHC_STATE_POTENTIAL_RECOVERY,
292 MBHC_STATE_RELEASE,
293};
294
Kiran Kandid8cf5212012-03-02 15:34:53 -0800295struct hpf_work {
296 struct tabla_priv *tabla;
297 u32 decimator;
298 u8 tx_hpf_cut_of_freq;
299 struct delayed_work dwork;
300};
301
302static struct hpf_work tx_hpf_work[NUM_DECIMATORS];
303
Kuirong Wang906ac472012-07-09 12:54:44 -0700304static const struct wcd9xxx_ch tabla_rx_chs[TABLA_RX_MAX] = {
305 WCD9XXX_CH(10, 0),
306 WCD9XXX_CH(11, 1),
307 WCD9XXX_CH(12, 2),
308 WCD9XXX_CH(13, 3),
309 WCD9XXX_CH(14, 4),
310 WCD9XXX_CH(15, 5),
311 WCD9XXX_CH(16, 6)
312};
313
314static const struct wcd9xxx_ch tabla_tx_chs[TABLA_TX_MAX] = {
315 WCD9XXX_CH(0, 0),
316 WCD9XXX_CH(1, 1),
317 WCD9XXX_CH(2, 2),
318 WCD9XXX_CH(3, 3),
319 WCD9XXX_CH(4, 4),
320 WCD9XXX_CH(5, 5),
321 WCD9XXX_CH(6, 6),
322 WCD9XXX_CH(7, 7),
323 WCD9XXX_CH(8, 8),
324 WCD9XXX_CH(9, 9)
325};
326
327static const u32 vport_check_table[NUM_CODEC_DAIS] = {
328 0, /* AIF1_PB */
329 (1 << AIF2_CAP) | (1 << AIF3_CAP), /* AIF1_CAP */
330 0, /* AIF2_PB */
331 (1 << AIF1_CAP) | (1 << AIF3_CAP), /* AIF2_CAP */
332 0, /* AIF2_PB */
333 (1 << AIF1_CAP) | (1 << AIF2_CAP), /* AIF2_CAP */
334};
335
Venkat Sudhir96dd28c2012-12-04 17:00:19 -0800336static const u32 vport_i2s_check_table[NUM_CODEC_DAIS] = {
337 0, /* AIF1_PB */
338 0, /* AIF1_CAP */
339};
340
Bradley Rubin229c6a52011-07-12 16:18:48 -0700341struct tabla_priv {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700342 struct snd_soc_codec *codec;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -0800343 struct tabla_reg_address reg_addr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700344 u32 adc_count;
Patrick Lai3043fba2011-08-01 14:15:57 -0700345 u32 cfilt1_cnt;
346 u32 cfilt2_cnt;
347 u32 cfilt3_cnt;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -0700348 u32 rx_bias_count;
Kiran Kandi0ba468f2012-05-08 11:45:05 -0700349 s32 dmic_1_2_clk_cnt;
350 s32 dmic_3_4_clk_cnt;
351 s32 dmic_5_6_clk_cnt;
352
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700353 enum tabla_bandgap_type bandgap_type;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -0700354 bool mclk_enabled;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700355 bool clock_active;
356 bool config_mode_active;
357 bool mbhc_polling_active;
Joonwoo Parkf4267c22012-01-10 13:25:24 -0800358 unsigned long mbhc_fake_ins_start;
Bradley Rubincb1e2732011-06-23 16:49:20 -0700359 int buttons_pressed;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700360 enum tabla_mbhc_state mbhc_state;
361 struct tabla_mbhc_config mbhc_cfg;
Joonwoo Park0976d012011-12-22 11:48:18 -0800362 struct mbhc_internal_cal_data mbhc_data;
Simmi Pateriya71d63872012-11-08 01:06:30 +0530363 u32 ldo_h_count;
364 u32 micbias_enable_count[TABLA_NUM_MICBIAS];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700365
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530366 struct wcd9xxx_pdata *pdata;
Bradley Rubina7096d02011-08-03 18:29:02 -0700367 u32 anc_slot;
Damir Didjustoc6f83cb2012-12-03 00:54:14 -0800368 bool anc_func;
Bradley Rubincb3950a2011-08-18 13:07:26 -0700369 bool no_mic_headset_override;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -0700370 /* Delayed work to report long button press */
Joonwoo Park03324832012-03-19 19:36:16 -0700371 struct delayed_work mbhc_btn_dwork;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700372
373 struct mbhc_micbias_regs mbhc_bias_regs;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -0700374 bool mbhc_micbias_switched;
Patrick Lai49efeac2011-11-03 11:01:12 -0700375
Joonwoo Parka9444452011-12-08 18:48:27 -0800376 /* track PA/DAC state */
377 unsigned long hph_pa_dac_state;
378
Santosh Mardie15e2302011-11-15 10:39:23 +0530379 /*track tabla interface type*/
380 u8 intf_type;
381
Patrick Lai49efeac2011-11-03 11:01:12 -0700382 u32 hph_status; /* track headhpone status */
383 /* define separate work for left and right headphone OCP to avoid
384 * additional checking on which OCP event to report so no locking
385 * to ensure synchronization is required
386 */
387 struct work_struct hphlocp_work; /* reporting left hph ocp off */
388 struct work_struct hphrocp_work; /* reporting right hph ocp off */
Joonwoo Park8b1f0982011-12-08 17:12:45 -0800389
Patrick Laic7cae882011-11-18 11:52:49 -0800390 u8 hphlocp_cnt; /* headphone left ocp retry */
391 u8 hphrocp_cnt; /* headphone right ocp retry */
Joonwoo Park0976d012011-12-22 11:48:18 -0800392
Patrick Lai64b43262011-12-06 17:29:15 -0800393 /* Work to perform MBHC Firmware Read */
394 struct delayed_work mbhc_firmware_dwork;
395 const struct firmware *mbhc_fw;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800396
397 /* num of slim ports required */
Kuirong Wang906ac472012-07-09 12:54:44 -0700398 struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS];
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800399
400 /*compander*/
401 int comp_enabled[COMPANDER_MAX];
402 u32 comp_fs[COMPANDER_MAX];
Kuirong Wang57b4d892013-02-11 09:54:45 -0800403 u8 comp_gain_offset[TABLA_SB_PGD_MAX_NUMBER_OF_RX_SLAVE_DEV_PORTS - 1];
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -0800404
405 /* Maintain the status of AUX PGA */
406 int aux_pga_cnt;
407 u8 aux_l_gain;
408 u8 aux_r_gain;
Joonwoo Park03324832012-03-19 19:36:16 -0700409
Joonwoo Park03324832012-03-19 19:36:16 -0700410 struct delayed_work mbhc_insert_dwork;
411 unsigned long mbhc_last_resume; /* in jiffies */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700412
413 u8 current_plug;
414 struct work_struct hs_correct_plug_work;
415 bool hs_detect_work_stop;
416 bool hs_polling_irq_prepared;
417 bool lpi_enabled; /* low power insertion detection */
418 bool in_gpio_handler;
419 /* Currently, only used for mbhc purpose, to protect
420 * concurrent execution of mbhc threaded irq handlers and
421 * kill race between DAPM and MBHC.But can serve as a
422 * general lock to protect codec resource
423 */
424 struct mutex codec_resource_lock;
425
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -0700426 /* Work to perform polling on microphone voltage
427 * in order to correct plug type once plug type
428 * is detected as headphone
429 */
430 struct work_struct hs_correct_plug_work_nogpio;
431
Joonwoo Parkecf379c2012-10-04 16:57:52 -0700432 bool gpio_irq_resend;
433 struct wake_lock irq_resend_wlock;
434
Bradley Rubincb3950a2011-08-18 13:07:26 -0700435#ifdef CONFIG_DEBUG_FS
Joonwoo Park179b9ec2012-03-26 10:56:20 -0700436 struct dentry *debugfs_poke;
437 struct dentry *debugfs_mbhc;
Bradley Rubincb3950a2011-08-18 13:07:26 -0700438#endif
Joonwoo Park179b9ec2012-03-26 10:56:20 -0700439};
440
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800441static const u32 comp_shift[] = {
442 0,
Kuirong Wang678e4172012-06-26 15:35:22 -0700443 1,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800444};
445
446static const int comp_rx_path[] = {
447 COMPANDER_1,
448 COMPANDER_1,
449 COMPANDER_2,
450 COMPANDER_2,
451 COMPANDER_2,
452 COMPANDER_2,
453 COMPANDER_MAX,
454};
455
Kuirong Wang678e4172012-06-26 15:35:22 -0700456static const struct comp_sample_dependent_params
457 comp_samp_params[COMPANDER_FS_MAX] = {
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800458 {
Kuirong Wang678e4172012-06-26 15:35:22 -0700459 .peak_det_timeout = 0x6,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800460 .rms_meter_div_fact = 0x9 << 4,
Kuirong Wang678e4172012-06-26 15:35:22 -0700461 .rms_meter_resamp_fact = 0x06,
462 .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_240 << 3,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800463 },
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800464 {
Kuirong Wang678e4172012-06-26 15:35:22 -0700465 .peak_det_timeout = 0x7,
466 .rms_meter_div_fact = 0xA << 4,
467 .rms_meter_resamp_fact = 0x0C,
468 .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_480 << 3,
469 },
470 {
471 .peak_det_timeout = 0x8,
472 .rms_meter_div_fact = 0xB << 4,
473 .rms_meter_resamp_fact = 0x30,
474 .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_960 << 3,
475 },
476 {
477 .peak_det_timeout = 0x9,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800478 .rms_meter_div_fact = 0xB << 4,
479 .rms_meter_resamp_fact = 0x28,
Kuirong Wang678e4172012-06-26 15:35:22 -0700480 .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_1440 << 3,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800481 },
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800482 {
Kuirong Wang678e4172012-06-26 15:35:22 -0700483 .peak_det_timeout = 0xA,
484 .rms_meter_div_fact = 0xC << 4,
485 .rms_meter_resamp_fact = 0x50,
486 .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_2880 << 3,
487 },
488 {
489 .peak_det_timeout = 0xB,
490 .rms_meter_div_fact = 0xC << 4,
491 .rms_meter_resamp_fact = 0x50,
492 .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_5760 << 3,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800493 },
494};
495
Kuirong Wange9c8a222012-03-28 16:24:09 -0700496static unsigned short rx_digital_gain_reg[] = {
497 TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
498 TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
499 TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
500 TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
501 TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
502 TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
503 TABLA_A_CDC_RX7_VOL_CTL_B2_CTL,
504};
505
506
507static unsigned short tx_digital_gain_reg[] = {
508 TABLA_A_CDC_TX1_VOL_CTL_GAIN,
509 TABLA_A_CDC_TX2_VOL_CTL_GAIN,
510 TABLA_A_CDC_TX3_VOL_CTL_GAIN,
511 TABLA_A_CDC_TX4_VOL_CTL_GAIN,
512 TABLA_A_CDC_TX5_VOL_CTL_GAIN,
513 TABLA_A_CDC_TX6_VOL_CTL_GAIN,
514 TABLA_A_CDC_TX7_VOL_CTL_GAIN,
515 TABLA_A_CDC_TX8_VOL_CTL_GAIN,
516 TABLA_A_CDC_TX9_VOL_CTL_GAIN,
517 TABLA_A_CDC_TX10_VOL_CTL_GAIN,
518};
519
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700520static int tabla_codec_enable_charge_pump(struct snd_soc_dapm_widget *w,
521 struct snd_kcontrol *kcontrol, int event)
522{
523 struct snd_soc_codec *codec = w->codec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700524
525 pr_debug("%s %d\n", __func__, event);
526 switch (event) {
527 case SND_SOC_DAPM_POST_PMU:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700528 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
529 0x01);
530 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x08);
531 usleep_range(200, 200);
532 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x00);
533 break;
534 case SND_SOC_DAPM_PRE_PMD:
535 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10,
536 0x10);
537 usleep_range(20, 20);
538 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x08);
539 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x10);
540 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x00);
541 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
542 0x00);
Fred Oh54d24d72012-11-29 15:57:36 -0800543 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10,
544 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700545 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700546 break;
547 }
548 return 0;
549}
550
Bradley Rubina7096d02011-08-03 18:29:02 -0700551static int tabla_get_anc_slot(struct snd_kcontrol *kcontrol,
552 struct snd_ctl_elem_value *ucontrol)
553{
554 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
555 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
556 ucontrol->value.integer.value[0] = tabla->anc_slot;
557 return 0;
558}
559
560static int tabla_put_anc_slot(struct snd_kcontrol *kcontrol,
561 struct snd_ctl_elem_value *ucontrol)
562{
563 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
564 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
565 tabla->anc_slot = ucontrol->value.integer.value[0];
566 return 0;
567}
568
Damir Didjustoc6f83cb2012-12-03 00:54:14 -0800569static int tabla_get_anc_func(struct snd_kcontrol *kcontrol,
570 struct snd_ctl_elem_value *ucontrol)
571{
572 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
573 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Kuirong Wang84ee8802013-02-09 12:52:06 -0800574
575 mutex_lock(&codec->dapm.codec->mutex);
Damir Didjustoc6f83cb2012-12-03 00:54:14 -0800576 ucontrol->value.integer.value[0] = (tabla->anc_func == true ? 1 : 0);
Kuirong Wang84ee8802013-02-09 12:52:06 -0800577 mutex_unlock(&codec->dapm.codec->mutex);
Damir Didjustoc6f83cb2012-12-03 00:54:14 -0800578 return 0;
579}
580
581static int tabla_put_anc_func(struct snd_kcontrol *kcontrol,
582 struct snd_ctl_elem_value *ucontrol)
583{
584 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
585 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
586 struct snd_soc_dapm_context *dapm = &codec->dapm;
587
588 mutex_lock(&dapm->codec->mutex);
589
590 tabla->anc_func = (!ucontrol->value.integer.value[0] ? false : true);
591
592 dev_dbg(codec->dev, "%s: anc_func %x", __func__, tabla->anc_func);
593
594 if (tabla->anc_func == true) {
595 snd_soc_dapm_enable_pin(dapm, "ANC HPHR");
596 snd_soc_dapm_enable_pin(dapm, "ANC HPHL");
597 snd_soc_dapm_enable_pin(dapm, "ANC HEADPHONE");
598 snd_soc_dapm_disable_pin(dapm, "HPHR");
599 snd_soc_dapm_disable_pin(dapm, "HPHL");
600 snd_soc_dapm_disable_pin(dapm, "HEADPHONE");
601 } else {
602 snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
603 snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
604 snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE");
605 snd_soc_dapm_enable_pin(dapm, "HPHR");
606 snd_soc_dapm_enable_pin(dapm, "HPHL");
607 snd_soc_dapm_enable_pin(dapm, "HEADPHONE");
608 }
609 snd_soc_dapm_sync(dapm);
610 mutex_unlock(&dapm->codec->mutex);
611 return 0;
612}
613
Kiran Kandid2d86b52011-09-09 17:44:28 -0700614static int tabla_pa_gain_get(struct snd_kcontrol *kcontrol,
615 struct snd_ctl_elem_value *ucontrol)
616{
617 u8 ear_pa_gain;
618 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
619
620 ear_pa_gain = snd_soc_read(codec, TABLA_A_RX_EAR_GAIN);
621
622 ear_pa_gain = ear_pa_gain >> 5;
623
624 if (ear_pa_gain == 0x00) {
625 ucontrol->value.integer.value[0] = 0;
626 } else if (ear_pa_gain == 0x04) {
627 ucontrol->value.integer.value[0] = 1;
628 } else {
629 pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n",
630 __func__, ear_pa_gain);
631 return -EINVAL;
632 }
633
634 pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain);
635
636 return 0;
637}
638
639static int tabla_pa_gain_put(struct snd_kcontrol *kcontrol,
640 struct snd_ctl_elem_value *ucontrol)
641{
642 u8 ear_pa_gain;
643 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
644
645 pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__,
646 ucontrol->value.integer.value[0]);
647
648 switch (ucontrol->value.integer.value[0]) {
649 case 0:
650 ear_pa_gain = 0x00;
651 break;
652 case 1:
653 ear_pa_gain = 0x80;
654 break;
655 default:
656 return -EINVAL;
657 }
658
659 snd_soc_update_bits(codec, TABLA_A_RX_EAR_GAIN, 0xE0, ear_pa_gain);
660 return 0;
661}
662
Ben Romberger1f045a72011-11-04 10:14:57 -0700663static int tabla_get_iir_enable_audio_mixer(
664 struct snd_kcontrol *kcontrol,
665 struct snd_ctl_elem_value *ucontrol)
666{
667 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
668 int iir_idx = ((struct soc_multi_mixer_control *)
669 kcontrol->private_value)->reg;
670 int band_idx = ((struct soc_multi_mixer_control *)
671 kcontrol->private_value)->shift;
672
673 ucontrol->value.integer.value[0] =
674 snd_soc_read(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx)) &
675 (1 << band_idx);
676
677 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
678 iir_idx, band_idx,
679 (uint32_t)ucontrol->value.integer.value[0]);
680 return 0;
681}
682
683static int tabla_put_iir_enable_audio_mixer(
684 struct snd_kcontrol *kcontrol,
685 struct snd_ctl_elem_value *ucontrol)
686{
687 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
688 int iir_idx = ((struct soc_multi_mixer_control *)
689 kcontrol->private_value)->reg;
690 int band_idx = ((struct soc_multi_mixer_control *)
691 kcontrol->private_value)->shift;
692 int value = ucontrol->value.integer.value[0];
693
694 /* Mask first 5 bits, 6-8 are reserved */
695 snd_soc_update_bits(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx),
696 (1 << band_idx), (value << band_idx));
697
698 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
699 iir_idx, band_idx, value);
700 return 0;
701}
702static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
703 int iir_idx, int band_idx,
704 int coeff_idx)
705{
706 /* Address does not automatically update if reading */
Ben Romberger0915aae2012-02-06 23:32:43 -0800707 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700708 (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800709 (band_idx * BAND_MAX + coeff_idx) & 0x1F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700710
711 /* Mask bits top 2 bits since they are reserved */
712 return ((snd_soc_read(codec,
713 (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 24) |
714 (snd_soc_read(codec,
715 (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx)) << 16) |
716 (snd_soc_read(codec,
717 (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx)) << 8) |
718 (snd_soc_read(codec,
719 (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx)))) &
720 0x3FFFFFFF;
721}
722
723static int tabla_get_iir_band_audio_mixer(
724 struct snd_kcontrol *kcontrol,
725 struct snd_ctl_elem_value *ucontrol)
726{
727 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
728 int iir_idx = ((struct soc_multi_mixer_control *)
729 kcontrol->private_value)->reg;
730 int band_idx = ((struct soc_multi_mixer_control *)
731 kcontrol->private_value)->shift;
732
733 ucontrol->value.integer.value[0] =
734 get_iir_band_coeff(codec, iir_idx, band_idx, 0);
735 ucontrol->value.integer.value[1] =
736 get_iir_band_coeff(codec, iir_idx, band_idx, 1);
737 ucontrol->value.integer.value[2] =
738 get_iir_band_coeff(codec, iir_idx, band_idx, 2);
739 ucontrol->value.integer.value[3] =
740 get_iir_band_coeff(codec, iir_idx, band_idx, 3);
741 ucontrol->value.integer.value[4] =
742 get_iir_band_coeff(codec, iir_idx, band_idx, 4);
743
744 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
745 "%s: IIR #%d band #%d b1 = 0x%x\n"
746 "%s: IIR #%d band #%d b2 = 0x%x\n"
747 "%s: IIR #%d band #%d a1 = 0x%x\n"
748 "%s: IIR #%d band #%d a2 = 0x%x\n",
749 __func__, iir_idx, band_idx,
750 (uint32_t)ucontrol->value.integer.value[0],
751 __func__, iir_idx, band_idx,
752 (uint32_t)ucontrol->value.integer.value[1],
753 __func__, iir_idx, band_idx,
754 (uint32_t)ucontrol->value.integer.value[2],
755 __func__, iir_idx, band_idx,
756 (uint32_t)ucontrol->value.integer.value[3],
757 __func__, iir_idx, band_idx,
758 (uint32_t)ucontrol->value.integer.value[4]);
759 return 0;
760}
761
762static void set_iir_band_coeff(struct snd_soc_codec *codec,
763 int iir_idx, int band_idx,
764 int coeff_idx, uint32_t value)
765{
766 /* Mask top 3 bits, 6-8 are reserved */
767 /* Update address manually each time */
Ben Romberger0915aae2012-02-06 23:32:43 -0800768 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700769 (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800770 (band_idx * BAND_MAX + coeff_idx) & 0x1F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700771
772 /* Mask top 2 bits, 7-8 are reserved */
Ben Romberger0915aae2012-02-06 23:32:43 -0800773 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700774 (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800775 (value >> 24) & 0x3F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700776
777 /* Isolate 8bits at a time */
Ben Romberger0915aae2012-02-06 23:32:43 -0800778 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700779 (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800780 (value >> 16) & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700781
Ben Romberger0915aae2012-02-06 23:32:43 -0800782 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700783 (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800784 (value >> 8) & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700785
Ben Romberger0915aae2012-02-06 23:32:43 -0800786 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700787 (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800788 value & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700789}
790
791static int tabla_put_iir_band_audio_mixer(
792 struct snd_kcontrol *kcontrol,
793 struct snd_ctl_elem_value *ucontrol)
794{
795 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
796 int iir_idx = ((struct soc_multi_mixer_control *)
797 kcontrol->private_value)->reg;
798 int band_idx = ((struct soc_multi_mixer_control *)
799 kcontrol->private_value)->shift;
800
801 set_iir_band_coeff(codec, iir_idx, band_idx, 0,
802 ucontrol->value.integer.value[0]);
803 set_iir_band_coeff(codec, iir_idx, band_idx, 1,
804 ucontrol->value.integer.value[1]);
805 set_iir_band_coeff(codec, iir_idx, band_idx, 2,
806 ucontrol->value.integer.value[2]);
807 set_iir_band_coeff(codec, iir_idx, band_idx, 3,
808 ucontrol->value.integer.value[3]);
809 set_iir_band_coeff(codec, iir_idx, band_idx, 4,
810 ucontrol->value.integer.value[4]);
811
812 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
813 "%s: IIR #%d band #%d b1 = 0x%x\n"
814 "%s: IIR #%d band #%d b2 = 0x%x\n"
815 "%s: IIR #%d band #%d a1 = 0x%x\n"
816 "%s: IIR #%d band #%d a2 = 0x%x\n",
817 __func__, iir_idx, band_idx,
818 get_iir_band_coeff(codec, iir_idx, band_idx, 0),
819 __func__, iir_idx, band_idx,
820 get_iir_band_coeff(codec, iir_idx, band_idx, 1),
821 __func__, iir_idx, band_idx,
822 get_iir_band_coeff(codec, iir_idx, band_idx, 2),
823 __func__, iir_idx, band_idx,
824 get_iir_band_coeff(codec, iir_idx, band_idx, 3),
825 __func__, iir_idx, band_idx,
826 get_iir_band_coeff(codec, iir_idx, band_idx, 4));
827 return 0;
828}
829
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800830static int tabla_compander_gain_offset(
831 struct snd_soc_codec *codec, u32 enable,
Kuirong Wang57b4d892013-02-11 09:54:45 -0800832 unsigned int pa_reg, unsigned int vol_reg,
833 int mask, int event,
834 struct comp_dgtl_gain_offset *gain_offset,
835 int index)
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800836{
Kuirong Wang57b4d892013-02-11 09:54:45 -0800837 unsigned int pa_gain = snd_soc_read(codec, pa_reg);
838 unsigned int digital_vol = snd_soc_read(codec, vol_reg);
839 int pa_mode = pa_gain & mask;
840 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
841
842 pr_debug("%s: pa_gain(0x%x=0x%x)digital_vol(0x%x=0x%x)event(0x%x) index(%d)\n",
843 __func__, pa_reg, pa_gain, vol_reg, digital_vol, event, index);
844 if (((pa_gain & 0xF) + 1) > ARRAY_SIZE(comp_dgtl_gain) ||
845 (index >= ARRAY_SIZE(tabla->comp_gain_offset))) {
846 pr_err("%s: Out of array boundary\n", __func__);
847 return -EINVAL;
848 }
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800849
Kuirong Wang678e4172012-06-26 15:35:22 -0700850 if (SND_SOC_DAPM_EVENT_ON(event) && (enable != 0)) {
Kuirong Wang57b4d892013-02-11 09:54:45 -0800851 gain_offset->whole_db_gain = COMP_DIGITAL_DB_GAIN_APPLY(
852 (digital_vol - comp_dgtl_gain[pa_gain & 0xF].whole_db_gain),
853 comp_dgtl_gain[pa_gain & 0xF].half_db_gain);
854 pr_debug("%s: listed whole_db_gain:0x%x, adjusted whole_db_gain:0x%x\n",
855 __func__, comp_dgtl_gain[pa_gain & 0xF].whole_db_gain,
856 gain_offset->whole_db_gain);
857 gain_offset->half_db_gain =
858 comp_dgtl_gain[pa_gain & 0xF].half_db_gain;
859 tabla->comp_gain_offset[index] = digital_vol -
860 gain_offset->whole_db_gain ;
Kuirong Wang678e4172012-06-26 15:35:22 -0700861 }
862 if (SND_SOC_DAPM_EVENT_OFF(event) && (pa_mode == 0)) {
Kuirong Wang57b4d892013-02-11 09:54:45 -0800863 gain_offset->whole_db_gain = digital_vol +
864 tabla->comp_gain_offset[index];
865 pr_debug("%s: listed whole_db_gain:0x%x, adjusted whole_db_gain:0x%x\n",
866 __func__, comp_dgtl_gain[pa_gain & 0xF].whole_db_gain,
867 gain_offset->whole_db_gain);
868 gain_offset->half_db_gain = 0;
Kuirong Wang678e4172012-06-26 15:35:22 -0700869 }
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800870
Kuirong Wang57b4d892013-02-11 09:54:45 -0800871 pr_debug("%s: half_db_gain(%d)whole_db_gain(%d)comp_gain_offset[%d](%d)\n",
872 __func__, gain_offset->half_db_gain,
873 gain_offset->whole_db_gain, index,
874 tabla->comp_gain_offset[index]);
875 return 0;
876}
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800877
878static int tabla_config_gain_compander(
879 struct snd_soc_codec *codec,
880 u32 compander, u32 enable, int event)
881{
882 int value = 0;
883 int mask = 1 << 4;
Kuirong Wang57b4d892013-02-11 09:54:45 -0800884 struct comp_dgtl_gain_offset gain_offset = {0, 0};
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800885 if (compander >= COMPANDER_MAX) {
886 pr_err("%s: Error, invalid compander channel\n", __func__);
887 return -EINVAL;
888 }
889
890 if ((enable == 0) || SND_SOC_DAPM_EVENT_OFF(event))
891 value = 1 << 4;
892
893 if (compander == COMPANDER_1) {
Kuirong Wang57b4d892013-02-11 09:54:45 -0800894 tabla_compander_gain_offset(codec, enable,
895 TABLA_A_RX_HPH_L_GAIN,
896 TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
897 mask, event, &gain_offset, 0);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800898 snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_GAIN, mask, value);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800899 snd_soc_update_bits(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
Kuirong Wang57b4d892013-02-11 09:54:45 -0800900 0xFF, gain_offset.whole_db_gain);
901 snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL,
902 0x02, gain_offset.half_db_gain);
903 tabla_compander_gain_offset(codec, enable,
904 TABLA_A_RX_HPH_R_GAIN,
905 TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
906 mask, event, &gain_offset, 1);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800907 snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_GAIN, mask, value);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800908 snd_soc_update_bits(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
Kuirong Wang57b4d892013-02-11 09:54:45 -0800909 0xFF, gain_offset.whole_db_gain);
910 snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL,
911 0x02, gain_offset.half_db_gain);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800912 } else if (compander == COMPANDER_2) {
Kuirong Wang57b4d892013-02-11 09:54:45 -0800913 tabla_compander_gain_offset(codec, enable,
914 TABLA_A_RX_LINE_1_GAIN,
915 TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
916 mask, event, &gain_offset, 2);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800917 snd_soc_update_bits(codec, TABLA_A_RX_LINE_1_GAIN, mask, value);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800918 snd_soc_update_bits(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
Kuirong Wang57b4d892013-02-11 09:54:45 -0800919 0xFF, gain_offset.whole_db_gain);
920 snd_soc_update_bits(codec, TABLA_A_CDC_RX3_B6_CTL,
921 0x02, gain_offset.half_db_gain);
922 tabla_compander_gain_offset(codec, enable,
923 TABLA_A_RX_LINE_3_GAIN,
924 TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
925 mask, event, &gain_offset, 3);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800926 snd_soc_update_bits(codec, TABLA_A_RX_LINE_3_GAIN, mask, value);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800927 snd_soc_update_bits(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
Kuirong Wang57b4d892013-02-11 09:54:45 -0800928 0xFF, gain_offset.whole_db_gain);
929 snd_soc_update_bits(codec, TABLA_A_CDC_RX4_B6_CTL,
930 0x02, gain_offset.half_db_gain);
931 tabla_compander_gain_offset(codec, enable,
932 TABLA_A_RX_LINE_2_GAIN,
933 TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
934 mask, event, &gain_offset, 4);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800935 snd_soc_update_bits(codec, TABLA_A_RX_LINE_2_GAIN, mask, value);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800936 snd_soc_update_bits(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
Kuirong Wang57b4d892013-02-11 09:54:45 -0800937 0xFF, gain_offset.whole_db_gain);
938 snd_soc_update_bits(codec, TABLA_A_CDC_RX5_B6_CTL,
939 0x02, gain_offset.half_db_gain);
940 tabla_compander_gain_offset(codec, enable,
941 TABLA_A_RX_LINE_4_GAIN,
942 TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
943 mask, event, &gain_offset, 5);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800944 snd_soc_update_bits(codec, TABLA_A_RX_LINE_4_GAIN, mask, value);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800945 snd_soc_update_bits(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
Kuirong Wang57b4d892013-02-11 09:54:45 -0800946 0xFF, gain_offset.whole_db_gain);
947 snd_soc_update_bits(codec, TABLA_A_CDC_RX6_B6_CTL,
948 0x02, gain_offset.half_db_gain);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800949 }
950 return 0;
951}
952static int tabla_get_compander(struct snd_kcontrol *kcontrol,
953 struct snd_ctl_elem_value *ucontrol)
954{
955
956 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
957 int comp = ((struct soc_multi_mixer_control *)
958 kcontrol->private_value)->max;
959 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
960
961 ucontrol->value.integer.value[0] = tabla->comp_enabled[comp];
962
963 return 0;
964}
965
966static int tabla_set_compander(struct snd_kcontrol *kcontrol,
967 struct snd_ctl_elem_value *ucontrol)
968{
969 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
970 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
971 int comp = ((struct soc_multi_mixer_control *)
972 kcontrol->private_value)->max;
973 int value = ucontrol->value.integer.value[0];
Kuirong Wang678e4172012-06-26 15:35:22 -0700974 pr_debug("%s: compander #%d enable %d\n",
975 __func__, comp + 1, value);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800976 if (value == tabla->comp_enabled[comp]) {
977 pr_debug("%s: compander #%d enable %d no change\n",
Kuirong Wang678e4172012-06-26 15:35:22 -0700978 __func__, comp + 1, value);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800979 return 0;
980 }
981 tabla->comp_enabled[comp] = value;
982 return 0;
983}
984
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800985static int tabla_config_compander(struct snd_soc_dapm_widget *w,
986 struct snd_kcontrol *kcontrol,
987 int event)
988{
989 struct snd_soc_codec *codec = w->codec;
990 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
991 u32 rate = tabla->comp_fs[w->shift];
Kuirong Wang84ee8802013-02-09 12:52:06 -0800992
993 pr_debug("%s: compander #%d enable %d event %d widget name %s\n",
Kuirong Wang678e4172012-06-26 15:35:22 -0700994 __func__, w->shift + 1,
Kuirong Wang84ee8802013-02-09 12:52:06 -0800995 tabla->comp_enabled[w->shift], event , w->name);
996 if (tabla->comp_enabled[w->shift] == 0)
997 goto rtn;
998 if ((w->shift == COMPANDER_1) && (tabla->anc_func)) {
999 pr_debug("%s: ANC is enabled so compander #%d cannot be enabled\n",
1000 __func__, w->shift + 1);
1001 goto rtn;
1002 }
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001003 switch (event) {
1004 case SND_SOC_DAPM_PRE_PMU:
Kuirong Wang84ee8802013-02-09 12:52:06 -08001005 /* Update compander sample rate */
1006 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_FS_CFG +
1007 w->shift * 8, 0x07, rate);
1008 /* Enable both L/R compander clocks */
1009 snd_soc_update_bits(codec,
1010 TABLA_A_CDC_CLK_RX_B2_CTL,
1011 1 << comp_shift[w->shift],
1012 1 << comp_shift[w->shift]);
1013 /* Toggle compander reset bits */
1014 snd_soc_update_bits(codec,
1015 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
1016 1 << comp_shift[w->shift],
1017 1 << comp_shift[w->shift]);
1018 snd_soc_update_bits(codec,
1019 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
1020 1 << comp_shift[w->shift], 0);
1021 tabla_config_gain_compander(codec, w->shift, 1, event);
1022 /* Compander enable -> 0x370/0x378 */
1023 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
1024 w->shift * 8, 0x03, 0x03);
1025 /* Update the RMS meter resampling */
1026 snd_soc_update_bits(codec,
1027 TABLA_A_CDC_COMP1_B3_CTL +
1028 w->shift * 8, 0xFF, 0x01);
1029 snd_soc_update_bits(codec,
1030 TABLA_A_CDC_COMP1_B2_CTL +
1031 w->shift * 8, 0xF0, 0x50);
1032 usleep_range(COMP_BRINGUP_WAIT_TIME, COMP_BRINGUP_WAIT_TIME);
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001033 break;
1034 case SND_SOC_DAPM_POST_PMU:
Kuirong Wang84ee8802013-02-09 12:52:06 -08001035 /* Set sample rate dependent paramater */
1036 if (w->shift == COMPANDER_1) {
1037 snd_soc_update_bits(codec,
1038 TABLA_A_CDC_CLSG_CTL,
1039 0x11, 0x00);
1040 snd_soc_write(codec,
1041 TABLA_A_CDC_CONN_CLSG_CTL, 0x11);
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001042 }
Kuirong Wang84ee8802013-02-09 12:52:06 -08001043 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL +
1044 w->shift * 8, 0x0F,
1045 comp_samp_params[rate].peak_det_timeout);
1046 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL +
1047 w->shift * 8, 0xF0,
1048 comp_samp_params[rate].rms_meter_div_fact);
1049 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B3_CTL +
1050 w->shift * 8, 0xFF,
1051 comp_samp_params[rate].rms_meter_resamp_fact);
1052 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
1053 w->shift * 8, 0x38,
1054 comp_samp_params[rate].shutdown_timeout);
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001055 break;
1056 case SND_SOC_DAPM_PRE_PMD:
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001057 break;
1058 case SND_SOC_DAPM_POST_PMD:
Kuirong Wang84ee8802013-02-09 12:52:06 -08001059 /* Disable the compander */
1060 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
1061 w->shift * 8, 0x03, 0x00);
1062 /* Toggle compander reset bits */
1063 snd_soc_update_bits(codec,
1064 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
1065 1 << comp_shift[w->shift],
1066 1 << comp_shift[w->shift]);
1067 snd_soc_update_bits(codec,
1068 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
1069 1 << comp_shift[w->shift], 0);
1070 /* Turn off the clock for compander in pair */
1071 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_B2_CTL,
1072 0x03 << comp_shift[w->shift], 0);
1073 /* Restore the gain */
1074 tabla_config_gain_compander(codec, w->shift,
1075 tabla->comp_enabled[w->shift],
1076 event);
1077 if (w->shift == COMPANDER_1) {
Kuirong Wang678e4172012-06-26 15:35:22 -07001078 snd_soc_update_bits(codec,
Kuirong Wang84ee8802013-02-09 12:52:06 -08001079 TABLA_A_CDC_CLSG_CTL,
1080 0x11, 0x11);
1081 snd_soc_write(codec,
1082 TABLA_A_CDC_CONN_CLSG_CTL, 0x14);
Kuirong Wang678e4172012-06-26 15:35:22 -07001083 }
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001084 break;
1085 }
Kuirong Wang84ee8802013-02-09 12:52:06 -08001086rtn:
1087 return 0;
1088}
1089
1090static int tabla_codec_hphr_dem_input_selection(struct snd_soc_dapm_widget *w,
1091 struct snd_kcontrol *kcontrol,
1092 int event)
1093{
1094 struct snd_soc_codec *codec = w->codec;
1095 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1096
1097 pr_debug("%s: compander#1->enable(%d) reg(0x%x = 0x%x) event(%d)\n",
1098 __func__, tabla->comp_enabled[COMPANDER_1],
1099 TABLA_A_CDC_RX1_B6_CTL,
1100 snd_soc_read(codec, TABLA_A_CDC_RX1_B6_CTL), event);
1101 switch (event) {
1102 case SND_SOC_DAPM_POST_PMU:
1103 if (tabla->comp_enabled[COMPANDER_1] && !tabla->anc_func)
1104 snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL,
1105 1 << w->shift, 0);
1106 else
1107 snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL,
1108 1 << w->shift, 1 << w->shift);
1109 break;
1110 case SND_SOC_DAPM_POST_PMD:
1111 snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL,
1112 1 << w->shift, 0);
1113 break;
1114 default:
1115 return -EINVAL;
1116 }
1117 return 0;
1118}
1119
1120static int tabla_codec_hphl_dem_input_selection(struct snd_soc_dapm_widget *w,
1121 struct snd_kcontrol *kcontrol,
1122 int event)
1123{
1124 struct snd_soc_codec *codec = w->codec;
1125 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1126
1127 pr_debug("%s: compander#1->enable(%d) reg(0x%x = 0x%x) event(%d)\n",
1128 __func__, tabla->comp_enabled[COMPANDER_1],
1129 TABLA_A_CDC_RX2_B6_CTL,
1130 snd_soc_read(codec, TABLA_A_CDC_RX2_B6_CTL), event);
1131 switch (event) {
1132 case SND_SOC_DAPM_POST_PMU:
1133 if (tabla->comp_enabled[COMPANDER_1] && !tabla->anc_func)
1134 snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL,
1135 1 << w->shift, 0);
1136 else
1137 snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL,
1138 1 << w->shift, 1 << w->shift);
1139 break;
1140 case SND_SOC_DAPM_POST_PMD:
1141 snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL,
1142 1 << w->shift, 0);
1143 break;
1144 default:
1145 return -EINVAL;
1146 }
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001147 return 0;
1148}
1149
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08001150static const char *const tabla_anc_func_text[] = {"OFF", "ON"};
1151static const struct soc_enum tabla_anc_func_enum =
1152 SOC_ENUM_SINGLE_EXT(2, tabla_anc_func_text);
1153
Kiran Kandid2d86b52011-09-09 17:44:28 -07001154static const char *tabla_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"};
1155static const struct soc_enum tabla_ear_pa_gain_enum[] = {
1156 SOC_ENUM_SINGLE_EXT(2, tabla_ear_pa_gain_text),
1157};
1158
Santosh Mardi024010f2011-10-18 06:27:21 +05301159/*cut of frequency for high pass filter*/
1160static const char *cf_text[] = {
1161 "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz"
1162};
1163
1164static const struct soc_enum cf_dec1_enum =
1165 SOC_ENUM_SINGLE(TABLA_A_CDC_TX1_MUX_CTL, 4, 3, cf_text);
1166
1167static const struct soc_enum cf_dec2_enum =
1168 SOC_ENUM_SINGLE(TABLA_A_CDC_TX2_MUX_CTL, 4, 3, cf_text);
1169
1170static const struct soc_enum cf_dec3_enum =
1171 SOC_ENUM_SINGLE(TABLA_A_CDC_TX3_MUX_CTL, 4, 3, cf_text);
1172
1173static const struct soc_enum cf_dec4_enum =
1174 SOC_ENUM_SINGLE(TABLA_A_CDC_TX4_MUX_CTL, 4, 3, cf_text);
1175
1176static const struct soc_enum cf_dec5_enum =
1177 SOC_ENUM_SINGLE(TABLA_A_CDC_TX5_MUX_CTL, 4, 3, cf_text);
1178
1179static const struct soc_enum cf_dec6_enum =
1180 SOC_ENUM_SINGLE(TABLA_A_CDC_TX6_MUX_CTL, 4, 3, cf_text);
1181
1182static const struct soc_enum cf_dec7_enum =
1183 SOC_ENUM_SINGLE(TABLA_A_CDC_TX7_MUX_CTL, 4, 3, cf_text);
1184
1185static const struct soc_enum cf_dec8_enum =
1186 SOC_ENUM_SINGLE(TABLA_A_CDC_TX8_MUX_CTL, 4, 3, cf_text);
1187
1188static const struct soc_enum cf_dec9_enum =
1189 SOC_ENUM_SINGLE(TABLA_A_CDC_TX9_MUX_CTL, 4, 3, cf_text);
1190
1191static const struct soc_enum cf_dec10_enum =
1192 SOC_ENUM_SINGLE(TABLA_A_CDC_TX10_MUX_CTL, 4, 3, cf_text);
1193
1194static const struct soc_enum cf_rxmix1_enum =
1195 SOC_ENUM_SINGLE(TABLA_A_CDC_RX1_B4_CTL, 1, 3, cf_text);
1196
1197static const struct soc_enum cf_rxmix2_enum =
1198 SOC_ENUM_SINGLE(TABLA_A_CDC_RX2_B4_CTL, 1, 3, cf_text);
1199
1200static const struct soc_enum cf_rxmix3_enum =
1201 SOC_ENUM_SINGLE(TABLA_A_CDC_RX3_B4_CTL, 1, 3, cf_text);
1202
1203static const struct soc_enum cf_rxmix4_enum =
1204 SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B4_CTL, 1, 3, cf_text);
1205
1206static const struct soc_enum cf_rxmix5_enum =
1207 SOC_ENUM_SINGLE(TABLA_A_CDC_RX5_B4_CTL, 1, 3, cf_text)
1208;
1209static const struct soc_enum cf_rxmix6_enum =
1210 SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B4_CTL, 1, 3, cf_text);
1211
1212static const struct soc_enum cf_rxmix7_enum =
1213 SOC_ENUM_SINGLE(TABLA_A_CDC_RX7_B4_CTL, 1, 3, cf_text);
1214
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001215static const struct snd_kcontrol_new tabla_snd_controls[] = {
Kiran Kandid2d86b52011-09-09 17:44:28 -07001216
1217 SOC_ENUM_EXT("EAR PA Gain", tabla_ear_pa_gain_enum[0],
1218 tabla_pa_gain_get, tabla_pa_gain_put),
1219
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001220 SOC_SINGLE_TLV("LINEOUT1 Volume", TABLA_A_RX_LINE_1_GAIN, 0, 12, 1,
1221 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001222 SOC_SINGLE_TLV("LINEOUT2 Volume", TABLA_A_RX_LINE_2_GAIN, 0, 12, 1,
1223 line_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001224 SOC_SINGLE_TLV("LINEOUT3 Volume", TABLA_A_RX_LINE_3_GAIN, 0, 12, 1,
1225 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001226 SOC_SINGLE_TLV("LINEOUT4 Volume", TABLA_A_RX_LINE_4_GAIN, 0, 12, 1,
1227 line_gain),
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001228 SOC_SINGLE_TLV("LINEOUT5 Volume", TABLA_A_RX_LINE_5_GAIN, 0, 12, 1,
1229 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001230
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001231 SOC_SINGLE_TLV("HPHL Volume", TABLA_A_RX_HPH_L_GAIN, 0, 12, 1,
1232 line_gain),
1233 SOC_SINGLE_TLV("HPHR Volume", TABLA_A_RX_HPH_R_GAIN, 0, 12, 1,
1234 line_gain),
1235
Bradley Rubin410383f2011-07-22 13:44:23 -07001236 SOC_SINGLE_S8_TLV("RX1 Digital Volume", TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
1237 -84, 40, digital_gain),
1238 SOC_SINGLE_S8_TLV("RX2 Digital Volume", TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
1239 -84, 40, digital_gain),
1240 SOC_SINGLE_S8_TLV("RX3 Digital Volume", TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
1241 -84, 40, digital_gain),
1242 SOC_SINGLE_S8_TLV("RX4 Digital Volume", TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
1243 -84, 40, digital_gain),
1244 SOC_SINGLE_S8_TLV("RX5 Digital Volume", TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
1245 -84, 40, digital_gain),
1246 SOC_SINGLE_S8_TLV("RX6 Digital Volume", TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
1247 -84, 40, digital_gain),
Neema Shettyd3a89262012-02-16 10:23:50 -08001248 SOC_SINGLE_S8_TLV("RX7 Digital Volume", TABLA_A_CDC_RX7_VOL_CTL_B2_CTL,
1249 -84, 40, digital_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001250
Bradley Rubin410383f2011-07-22 13:44:23 -07001251 SOC_SINGLE_S8_TLV("DEC1 Volume", TABLA_A_CDC_TX1_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001252 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -07001253 SOC_SINGLE_S8_TLV("DEC2 Volume", TABLA_A_CDC_TX2_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001254 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -07001255 SOC_SINGLE_S8_TLV("DEC3 Volume", TABLA_A_CDC_TX3_VOL_CTL_GAIN, -84, 40,
1256 digital_gain),
1257 SOC_SINGLE_S8_TLV("DEC4 Volume", TABLA_A_CDC_TX4_VOL_CTL_GAIN, -84, 40,
1258 digital_gain),
1259 SOC_SINGLE_S8_TLV("DEC5 Volume", TABLA_A_CDC_TX5_VOL_CTL_GAIN, -84, 40,
1260 digital_gain),
1261 SOC_SINGLE_S8_TLV("DEC6 Volume", TABLA_A_CDC_TX6_VOL_CTL_GAIN, -84, 40,
1262 digital_gain),
1263 SOC_SINGLE_S8_TLV("DEC7 Volume", TABLA_A_CDC_TX7_VOL_CTL_GAIN, -84, 40,
1264 digital_gain),
1265 SOC_SINGLE_S8_TLV("DEC8 Volume", TABLA_A_CDC_TX8_VOL_CTL_GAIN, -84, 40,
1266 digital_gain),
1267 SOC_SINGLE_S8_TLV("DEC9 Volume", TABLA_A_CDC_TX9_VOL_CTL_GAIN, -84, 40,
1268 digital_gain),
1269 SOC_SINGLE_S8_TLV("DEC10 Volume", TABLA_A_CDC_TX10_VOL_CTL_GAIN, -84,
1270 40, digital_gain),
Patrick Lai29006372011-09-28 17:57:42 -07001271 SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TABLA_A_CDC_IIR1_GAIN_B1_CTL, -84,
1272 40, digital_gain),
1273 SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TABLA_A_CDC_IIR1_GAIN_B2_CTL, -84,
1274 40, digital_gain),
1275 SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TABLA_A_CDC_IIR1_GAIN_B3_CTL, -84,
1276 40, digital_gain),
1277 SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TABLA_A_CDC_IIR1_GAIN_B4_CTL, -84,
1278 40, digital_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001279 SOC_SINGLE_TLV("ADC1 Volume", TABLA_A_TX_1_2_EN, 5, 3, 0, analog_gain),
1280 SOC_SINGLE_TLV("ADC2 Volume", TABLA_A_TX_1_2_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001281 SOC_SINGLE_TLV("ADC3 Volume", TABLA_A_TX_3_4_EN, 5, 3, 0, analog_gain),
1282 SOC_SINGLE_TLV("ADC4 Volume", TABLA_A_TX_3_4_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001283 SOC_SINGLE_TLV("ADC5 Volume", TABLA_A_TX_5_6_EN, 5, 3, 0, analog_gain),
1284 SOC_SINGLE_TLV("ADC6 Volume", TABLA_A_TX_5_6_EN, 1, 3, 0, analog_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001285
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001286 SOC_SINGLE_TLV("AUX_PGA_LEFT Volume", TABLA_A_AUX_L_GAIN, 0, 39, 0,
1287 aux_pga_gain),
1288 SOC_SINGLE_TLV("AUX_PGA_RIGHT Volume", TABLA_A_AUX_R_GAIN, 0, 39, 0,
1289 aux_pga_gain),
1290
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001291 SOC_SINGLE("MICBIAS1 CAPLESS Switch", TABLA_A_MICB_1_CTL, 4, 1, 1),
Santosh Mardi680b41e2011-11-22 16:51:16 -08001292 SOC_SINGLE("MICBIAS2 CAPLESS Switch", TABLA_A_MICB_2_CTL, 4, 1, 1),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001293 SOC_SINGLE("MICBIAS3 CAPLESS Switch", TABLA_A_MICB_3_CTL, 4, 1, 1),
Bradley Rubina7096d02011-08-03 18:29:02 -07001294
1295 SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 0, 100, tabla_get_anc_slot,
1296 tabla_put_anc_slot),
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08001297 SOC_ENUM_EXT("ANC Function", tabla_anc_func_enum, tabla_get_anc_func,
1298 tabla_put_anc_func),
Santosh Mardi024010f2011-10-18 06:27:21 +05301299 SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
1300 SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
1301 SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
1302 SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
1303 SOC_ENUM("TX5 HPF cut off", cf_dec5_enum),
1304 SOC_ENUM("TX6 HPF cut off", cf_dec6_enum),
1305 SOC_ENUM("TX7 HPF cut off", cf_dec7_enum),
1306 SOC_ENUM("TX8 HPF cut off", cf_dec8_enum),
1307 SOC_ENUM("TX9 HPF cut off", cf_dec9_enum),
1308 SOC_ENUM("TX10 HPF cut off", cf_dec10_enum),
1309
1310 SOC_SINGLE("TX1 HPF Switch", TABLA_A_CDC_TX1_MUX_CTL, 3, 1, 0),
1311 SOC_SINGLE("TX2 HPF Switch", TABLA_A_CDC_TX2_MUX_CTL, 3, 1, 0),
1312 SOC_SINGLE("TX3 HPF Switch", TABLA_A_CDC_TX3_MUX_CTL, 3, 1, 0),
1313 SOC_SINGLE("TX4 HPF Switch", TABLA_A_CDC_TX4_MUX_CTL, 3, 1, 0),
1314 SOC_SINGLE("TX5 HPF Switch", TABLA_A_CDC_TX5_MUX_CTL, 3, 1, 0),
1315 SOC_SINGLE("TX6 HPF Switch", TABLA_A_CDC_TX6_MUX_CTL, 3, 1, 0),
1316 SOC_SINGLE("TX7 HPF Switch", TABLA_A_CDC_TX7_MUX_CTL, 3, 1, 0),
1317 SOC_SINGLE("TX8 HPF Switch", TABLA_A_CDC_TX8_MUX_CTL, 3, 1, 0),
1318 SOC_SINGLE("TX9 HPF Switch", TABLA_A_CDC_TX9_MUX_CTL, 3, 1, 0),
1319 SOC_SINGLE("TX10 HPF Switch", TABLA_A_CDC_TX10_MUX_CTL, 3, 1, 0),
1320
1321 SOC_SINGLE("RX1 HPF Switch", TABLA_A_CDC_RX1_B5_CTL, 2, 1, 0),
1322 SOC_SINGLE("RX2 HPF Switch", TABLA_A_CDC_RX2_B5_CTL, 2, 1, 0),
1323 SOC_SINGLE("RX3 HPF Switch", TABLA_A_CDC_RX3_B5_CTL, 2, 1, 0),
1324 SOC_SINGLE("RX4 HPF Switch", TABLA_A_CDC_RX4_B5_CTL, 2, 1, 0),
1325 SOC_SINGLE("RX5 HPF Switch", TABLA_A_CDC_RX5_B5_CTL, 2, 1, 0),
1326 SOC_SINGLE("RX6 HPF Switch", TABLA_A_CDC_RX6_B5_CTL, 2, 1, 0),
1327 SOC_SINGLE("RX7 HPF Switch", TABLA_A_CDC_RX7_B5_CTL, 2, 1, 0),
1328
1329 SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum),
1330 SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum),
1331 SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum),
1332 SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum),
1333 SOC_ENUM("RX5 HPF cut off", cf_rxmix5_enum),
1334 SOC_ENUM("RX6 HPF cut off", cf_rxmix6_enum),
1335 SOC_ENUM("RX7 HPF cut off", cf_rxmix7_enum),
Ben Romberger1f045a72011-11-04 10:14:57 -07001336
1337 SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
1338 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1339 SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
1340 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1341 SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
1342 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1343 SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
1344 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1345 SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
1346 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1347 SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0,
1348 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1349 SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0,
1350 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1351 SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0,
1352 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1353 SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0,
1354 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1355 SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0,
1356 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1357
1358 SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
1359 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1360 SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
1361 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1362 SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
1363 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1364 SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
1365 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1366 SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
1367 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1368 SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5,
1369 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1370 SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5,
1371 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1372 SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5,
1373 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1374 SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5,
1375 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1376 SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5,
1377 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001378 SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, 1, COMPANDER_1, 0,
1379 tabla_get_compander, tabla_set_compander),
1380 SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, 0, COMPANDER_2, 0,
1381 tabla_get_compander, tabla_set_compander),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001382};
1383
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08001384static const struct snd_kcontrol_new tabla_1_x_snd_controls[] = {
1385 SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_1_A_MICB_4_CTL, 4, 1, 1),
1386};
1387
1388static const struct snd_kcontrol_new tabla_2_higher_snd_controls[] = {
1389 SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_2_A_MICB_4_CTL, 4, 1, 1),
1390};
1391
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001392static const char *rx_mix1_text[] = {
1393 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
1394 "RX5", "RX6", "RX7"
1395};
1396
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001397static const char *rx_mix2_text[] = {
1398 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2"
1399};
1400
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001401static const char *rx_dsm_text[] = {
1402 "CIC_OUT", "DSM_INV"
1403};
1404
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001405static const char *sb_tx1_mux_text[] = {
1406 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1407 "DEC1"
1408};
1409
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001410static const char *sb_tx2_mux_text[] = {
1411 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1412 "DEC2"
1413};
1414
1415static const char *sb_tx3_mux_text[] = {
1416 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1417 "DEC3"
1418};
1419
1420static const char *sb_tx4_mux_text[] = {
1421 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1422 "DEC4"
1423};
1424
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001425static const char *sb_tx5_mux_text[] = {
1426 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1427 "DEC5"
1428};
1429
1430static const char *sb_tx6_mux_text[] = {
1431 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1432 "DEC6"
1433};
1434
1435static const char const *sb_tx7_to_tx10_mux_text[] = {
1436 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1437 "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
1438 "DEC9", "DEC10"
1439};
1440
1441static const char *dec1_mux_text[] = {
1442 "ZERO", "DMIC1", "ADC6",
1443};
1444
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001445static const char *dec2_mux_text[] = {
1446 "ZERO", "DMIC2", "ADC5",
1447};
1448
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001449static const char *dec3_mux_text[] = {
1450 "ZERO", "DMIC3", "ADC4",
1451};
1452
1453static const char *dec4_mux_text[] = {
1454 "ZERO", "DMIC4", "ADC3",
1455};
1456
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001457static const char *dec5_mux_text[] = {
1458 "ZERO", "DMIC5", "ADC2",
1459};
1460
1461static const char *dec6_mux_text[] = {
1462 "ZERO", "DMIC6", "ADC1",
1463};
1464
1465static const char const *dec7_mux_text[] = {
1466 "ZERO", "DMIC1", "DMIC6", "ADC1", "ADC6", "ANC1_FB", "ANC2_FB",
1467};
1468
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001469static const char *dec8_mux_text[] = {
1470 "ZERO", "DMIC2", "DMIC5", "ADC2", "ADC5",
1471};
1472
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001473static const char *dec9_mux_text[] = {
1474 "ZERO", "DMIC4", "DMIC5", "ADC2", "ADC3", "ADCMB", "ANC1_FB", "ANC2_FB",
1475};
1476
1477static const char *dec10_mux_text[] = {
1478 "ZERO", "DMIC3", "DMIC6", "ADC1", "ADC4", "ADCMB", "ANC1_FB", "ANC2_FB",
1479};
1480
Bradley Rubin229c6a52011-07-12 16:18:48 -07001481static const char const *anc_mux_text[] = {
1482 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6", "ADC_MB",
1483 "RSVD_1", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", "DMIC6"
1484};
1485
1486static const char const *anc1_fb_mux_text[] = {
1487 "ZERO", "EAR_HPH_L", "EAR_LINE_1",
1488};
1489
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07001490static const char *const iir_inp1_text[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001491 "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
1492 "DEC9", "DEC10", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7"
1493};
1494
1495static const struct soc_enum rx_mix1_inp1_chain_enum =
1496 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_mix1_text);
1497
Bradley Rubin229c6a52011-07-12 16:18:48 -07001498static const struct soc_enum rx_mix1_inp2_chain_enum =
1499 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_mix1_text);
1500
Kiran Kandia9fffe92012-05-20 23:42:30 -07001501static const struct soc_enum rx_mix1_inp3_chain_enum =
1502 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B2_CTL, 0, 12, rx_mix1_text);
1503
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001504static const struct soc_enum rx2_mix1_inp1_chain_enum =
1505 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_mix1_text);
1506
Bradley Rubin229c6a52011-07-12 16:18:48 -07001507static const struct soc_enum rx2_mix1_inp2_chain_enum =
1508 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_mix1_text);
1509
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001510static const struct soc_enum rx3_mix1_inp1_chain_enum =
1511 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 0, 12, rx_mix1_text);
1512
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001513static const struct soc_enum rx3_mix1_inp2_chain_enum =
1514 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 4, 12, rx_mix1_text);
1515
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001516static const struct soc_enum rx4_mix1_inp1_chain_enum =
1517 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 0, 12, rx_mix1_text);
1518
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001519static const struct soc_enum rx4_mix1_inp2_chain_enum =
1520 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 4, 12, rx_mix1_text);
1521
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001522static const struct soc_enum rx5_mix1_inp1_chain_enum =
1523 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 0, 12, rx_mix1_text);
1524
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001525static const struct soc_enum rx5_mix1_inp2_chain_enum =
1526 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 4, 12, rx_mix1_text);
1527
1528static const struct soc_enum rx6_mix1_inp1_chain_enum =
1529 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 0, 12, rx_mix1_text);
1530
1531static const struct soc_enum rx6_mix1_inp2_chain_enum =
1532 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 4, 12, rx_mix1_text);
1533
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001534static const struct soc_enum rx7_mix1_inp1_chain_enum =
1535 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 0, 12, rx_mix1_text);
1536
1537static const struct soc_enum rx7_mix1_inp2_chain_enum =
1538 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 4, 12, rx_mix1_text);
1539
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001540static const struct soc_enum rx1_mix2_inp1_chain_enum =
1541 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text);
1542
1543static const struct soc_enum rx1_mix2_inp2_chain_enum =
1544 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text);
1545
1546static const struct soc_enum rx2_mix2_inp1_chain_enum =
1547 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text);
1548
1549static const struct soc_enum rx2_mix2_inp2_chain_enum =
1550 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text);
1551
1552static const struct soc_enum rx3_mix2_inp1_chain_enum =
1553 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 0, 5, rx_mix2_text);
1554
1555static const struct soc_enum rx3_mix2_inp2_chain_enum =
1556 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 3, 5, rx_mix2_text);
1557
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001558static const struct soc_enum rx4_dsm_enum =
1559 SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B6_CTL, 4, 2, rx_dsm_text);
1560
1561static const struct soc_enum rx6_dsm_enum =
1562 SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B6_CTL, 4, 2, rx_dsm_text);
1563
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001564static const struct soc_enum sb_tx1_mux_enum =
1565 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text);
1566
1567static const struct soc_enum sb_tx2_mux_enum =
1568 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0, 9, sb_tx2_mux_text);
1569
1570static const struct soc_enum sb_tx3_mux_enum =
1571 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0, 9, sb_tx3_mux_text);
1572
1573static const struct soc_enum sb_tx4_mux_enum =
1574 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0, 9, sb_tx4_mux_text);
1575
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001576static const struct soc_enum sb_tx5_mux_enum =
1577 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text);
1578
1579static const struct soc_enum sb_tx6_mux_enum =
1580 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0, 9, sb_tx6_mux_text);
1581
1582static const struct soc_enum sb_tx7_mux_enum =
1583 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0, 18,
1584 sb_tx7_to_tx10_mux_text);
1585
1586static const struct soc_enum sb_tx8_mux_enum =
1587 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0, 18,
1588 sb_tx7_to_tx10_mux_text);
1589
Kiran Kandi3426e512011-09-13 22:50:10 -07001590static const struct soc_enum sb_tx9_mux_enum =
1591 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0, 18,
1592 sb_tx7_to_tx10_mux_text);
1593
1594static const struct soc_enum sb_tx10_mux_enum =
1595 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0, 18,
1596 sb_tx7_to_tx10_mux_text);
1597
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001598static const struct soc_enum dec1_mux_enum =
1599 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 0, 3, dec1_mux_text);
1600
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001601static const struct soc_enum dec2_mux_enum =
1602 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 2, 3, dec2_mux_text);
1603
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001604static const struct soc_enum dec3_mux_enum =
1605 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 4, 3, dec3_mux_text);
1606
1607static const struct soc_enum dec4_mux_enum =
1608 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 6, 3, dec4_mux_text);
1609
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001610static const struct soc_enum dec5_mux_enum =
1611 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 0, 3, dec5_mux_text);
1612
1613static const struct soc_enum dec6_mux_enum =
1614 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 2, 3, dec6_mux_text);
1615
1616static const struct soc_enum dec7_mux_enum =
1617 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 4, 7, dec7_mux_text);
1618
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001619static const struct soc_enum dec8_mux_enum =
1620 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 0, 7, dec8_mux_text);
1621
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001622static const struct soc_enum dec9_mux_enum =
1623 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 3, 8, dec9_mux_text);
1624
1625static const struct soc_enum dec10_mux_enum =
1626 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B4_CTL, 0, 8, dec10_mux_text);
1627
Bradley Rubin229c6a52011-07-12 16:18:48 -07001628static const struct soc_enum anc1_mux_enum =
1629 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 0, 16, anc_mux_text);
1630
1631static const struct soc_enum anc2_mux_enum =
1632 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 4, 16, anc_mux_text);
1633
1634static const struct soc_enum anc1_fb_mux_enum =
1635 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text);
1636
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001637static const struct soc_enum iir1_inp1_mux_enum =
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07001638 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ1_B1_CTL, 0, 18, iir_inp1_text);
1639
1640static const struct soc_enum iir2_inp1_mux_enum =
1641 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ2_B1_CTL, 0, 18, iir_inp1_text);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001642
1643static const struct snd_kcontrol_new rx_mix1_inp1_mux =
1644 SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum);
1645
Bradley Rubin229c6a52011-07-12 16:18:48 -07001646static const struct snd_kcontrol_new rx_mix1_inp2_mux =
1647 SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum);
1648
Kiran Kandia9fffe92012-05-20 23:42:30 -07001649static const struct snd_kcontrol_new rx_mix1_inp3_mux =
1650 SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum);
1651
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001652static const struct snd_kcontrol_new rx2_mix1_inp1_mux =
1653 SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum);
1654
Bradley Rubin229c6a52011-07-12 16:18:48 -07001655static const struct snd_kcontrol_new rx2_mix1_inp2_mux =
1656 SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum);
1657
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001658static const struct snd_kcontrol_new rx3_mix1_inp1_mux =
1659 SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum);
1660
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001661static const struct snd_kcontrol_new rx3_mix1_inp2_mux =
1662 SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum);
1663
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001664static const struct snd_kcontrol_new rx4_mix1_inp1_mux =
1665 SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum);
1666
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001667static const struct snd_kcontrol_new rx4_mix1_inp2_mux =
1668 SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum);
1669
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001670static const struct snd_kcontrol_new rx5_mix1_inp1_mux =
1671 SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum);
1672
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001673static const struct snd_kcontrol_new rx5_mix1_inp2_mux =
1674 SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum);
1675
1676static const struct snd_kcontrol_new rx6_mix1_inp1_mux =
1677 SOC_DAPM_ENUM("RX6 MIX1 INP1 Mux", rx6_mix1_inp1_chain_enum);
1678
1679static const struct snd_kcontrol_new rx6_mix1_inp2_mux =
1680 SOC_DAPM_ENUM("RX6 MIX1 INP2 Mux", rx6_mix1_inp2_chain_enum);
1681
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001682static const struct snd_kcontrol_new rx7_mix1_inp1_mux =
1683 SOC_DAPM_ENUM("RX7 MIX1 INP1 Mux", rx7_mix1_inp1_chain_enum);
1684
1685static const struct snd_kcontrol_new rx7_mix1_inp2_mux =
1686 SOC_DAPM_ENUM("RX7 MIX1 INP2 Mux", rx7_mix1_inp2_chain_enum);
1687
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001688static const struct snd_kcontrol_new rx1_mix2_inp1_mux =
1689 SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum);
1690
1691static const struct snd_kcontrol_new rx1_mix2_inp2_mux =
1692 SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum);
1693
1694static const struct snd_kcontrol_new rx2_mix2_inp1_mux =
1695 SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum);
1696
1697static const struct snd_kcontrol_new rx2_mix2_inp2_mux =
1698 SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum);
1699
1700static const struct snd_kcontrol_new rx3_mix2_inp1_mux =
1701 SOC_DAPM_ENUM("RX3 MIX2 INP1 Mux", rx3_mix2_inp1_chain_enum);
1702
1703static const struct snd_kcontrol_new rx3_mix2_inp2_mux =
1704 SOC_DAPM_ENUM("RX3 MIX2 INP2 Mux", rx3_mix2_inp2_chain_enum);
1705
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001706static const struct snd_kcontrol_new rx4_dsm_mux =
1707 SOC_DAPM_ENUM("RX4 DSM MUX Mux", rx4_dsm_enum);
1708
1709static const struct snd_kcontrol_new rx6_dsm_mux =
1710 SOC_DAPM_ENUM("RX6 DSM MUX Mux", rx6_dsm_enum);
1711
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001712static const struct snd_kcontrol_new sb_tx1_mux =
1713 SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum);
1714
1715static const struct snd_kcontrol_new sb_tx2_mux =
1716 SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum);
1717
1718static const struct snd_kcontrol_new sb_tx3_mux =
1719 SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum);
1720
1721static const struct snd_kcontrol_new sb_tx4_mux =
1722 SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum);
1723
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001724static const struct snd_kcontrol_new sb_tx5_mux =
1725 SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum);
1726
1727static const struct snd_kcontrol_new sb_tx6_mux =
1728 SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum);
1729
1730static const struct snd_kcontrol_new sb_tx7_mux =
1731 SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum);
1732
1733static const struct snd_kcontrol_new sb_tx8_mux =
1734 SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum);
1735
Kiran Kandi3426e512011-09-13 22:50:10 -07001736static const struct snd_kcontrol_new sb_tx9_mux =
1737 SOC_DAPM_ENUM("SLIM TX9 MUX Mux", sb_tx9_mux_enum);
1738
1739static const struct snd_kcontrol_new sb_tx10_mux =
1740 SOC_DAPM_ENUM("SLIM TX10 MUX Mux", sb_tx10_mux_enum);
1741
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001742
Kiran Kandi59a96b12012-01-16 02:20:03 -08001743static int wcd9310_put_dec_enum(struct snd_kcontrol *kcontrol,
1744 struct snd_ctl_elem_value *ucontrol)
1745{
1746 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1747 struct snd_soc_dapm_widget *w = wlist->widgets[0];
1748 struct snd_soc_codec *codec = w->codec;
1749 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1750 unsigned int dec_mux, decimator;
1751 char *dec_name = NULL;
1752 char *widget_name = NULL;
1753 char *temp;
1754 u16 tx_mux_ctl_reg;
1755 u8 adc_dmic_sel = 0x0;
1756 int ret = 0;
1757
1758 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1759 return -EINVAL;
1760
1761 dec_mux = ucontrol->value.enumerated.item[0];
1762
1763 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
1764 if (!widget_name)
1765 return -ENOMEM;
1766 temp = widget_name;
1767
1768 dec_name = strsep(&widget_name, " ");
1769 widget_name = temp;
1770 if (!dec_name) {
1771 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
1772 ret = -EINVAL;
1773 goto out;
1774 }
1775
1776 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
1777 if (ret < 0) {
1778 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
1779 ret = -EINVAL;
1780 goto out;
1781 }
1782
1783 dev_dbg(w->dapm->dev, "%s(): widget = %s dec_name = %s decimator = %u"
1784 " dec_mux = %u\n", __func__, w->name, dec_name, decimator,
1785 dec_mux);
1786
1787
1788 switch (decimator) {
1789 case 1:
1790 case 2:
1791 case 3:
1792 case 4:
1793 case 5:
1794 case 6:
1795 if (dec_mux == 1)
1796 adc_dmic_sel = 0x1;
1797 else
1798 adc_dmic_sel = 0x0;
1799 break;
1800 case 7:
1801 case 8:
1802 case 9:
1803 case 10:
1804 if ((dec_mux == 1) || (dec_mux == 2))
1805 adc_dmic_sel = 0x1;
1806 else
1807 adc_dmic_sel = 0x0;
1808 break;
1809 default:
1810 pr_err("%s: Invalid Decimator = %u\n", __func__, decimator);
1811 ret = -EINVAL;
1812 goto out;
1813 }
1814
1815 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
1816
1817 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel);
1818
1819 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1820
1821out:
1822 kfree(widget_name);
1823 return ret;
1824}
1825
1826#define WCD9310_DEC_ENUM(xname, xenum) \
1827{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1828 .info = snd_soc_info_enum_double, \
1829 .get = snd_soc_dapm_get_enum_double, \
1830 .put = wcd9310_put_dec_enum, \
1831 .private_value = (unsigned long)&xenum }
1832
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001833static const struct snd_kcontrol_new dec1_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001834 WCD9310_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001835
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001836static const struct snd_kcontrol_new dec2_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001837 WCD9310_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum);
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001838
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001839static const struct snd_kcontrol_new dec3_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001840 WCD9310_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001841
1842static const struct snd_kcontrol_new dec4_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001843 WCD9310_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001844
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001845static const struct snd_kcontrol_new dec5_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001846 WCD9310_DEC_ENUM("DEC5 MUX Mux", dec5_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001847
1848static const struct snd_kcontrol_new dec6_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001849 WCD9310_DEC_ENUM("DEC6 MUX Mux", dec6_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001850
1851static const struct snd_kcontrol_new dec7_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001852 WCD9310_DEC_ENUM("DEC7 MUX Mux", dec7_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001853
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001854static const struct snd_kcontrol_new dec8_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001855 WCD9310_DEC_ENUM("DEC8 MUX Mux", dec8_mux_enum);
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001856
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001857static const struct snd_kcontrol_new dec9_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001858 WCD9310_DEC_ENUM("DEC9 MUX Mux", dec9_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001859
1860static const struct snd_kcontrol_new dec10_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001861 WCD9310_DEC_ENUM("DEC10 MUX Mux", dec10_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001862
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001863static const struct snd_kcontrol_new iir1_inp1_mux =
1864 SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum);
1865
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07001866static const struct snd_kcontrol_new iir2_inp1_mux =
1867 SOC_DAPM_ENUM("IIR2 INP1 Mux", iir2_inp1_mux_enum);
1868
Kiran Kandi59a96b12012-01-16 02:20:03 -08001869static const struct snd_kcontrol_new anc1_mux =
1870 SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum);
1871
Bradley Rubin229c6a52011-07-12 16:18:48 -07001872static const struct snd_kcontrol_new anc2_mux =
1873 SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001874
Bradley Rubin229c6a52011-07-12 16:18:48 -07001875static const struct snd_kcontrol_new anc1_fb_mux =
1876 SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001877
Bradley Rubin229c6a52011-07-12 16:18:48 -07001878static const struct snd_kcontrol_new dac1_switch[] = {
1879 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_EAR_EN, 5, 1, 0)
1880};
1881static const struct snd_kcontrol_new hphl_switch[] = {
1882 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_HPH_L_DAC_CTL, 6, 1, 0)
1883};
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001884
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001885static const struct snd_kcontrol_new hphl_pa_mix[] = {
1886 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1887 7, 1, 0),
1888 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1889 7, 1, 0),
1890 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1891 TABLA_A_AUX_L_PA_CONN_INV, 7, 1, 0),
1892 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1893 TABLA_A_AUX_R_PA_CONN_INV, 7, 1, 0),
1894};
1895
1896static const struct snd_kcontrol_new hphr_pa_mix[] = {
1897 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1898 6, 1, 0),
1899 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1900 6, 1, 0),
1901 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1902 TABLA_A_AUX_L_PA_CONN_INV, 6, 1, 0),
1903 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1904 TABLA_A_AUX_R_PA_CONN_INV, 6, 1, 0),
1905};
1906
1907static const struct snd_kcontrol_new lineout1_pa_mix[] = {
1908 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1909 5, 1, 0),
1910 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1911 5, 1, 0),
1912 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1913 TABLA_A_AUX_L_PA_CONN_INV, 5, 1, 0),
1914 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1915 TABLA_A_AUX_R_PA_CONN_INV, 5, 1, 0),
1916};
1917
1918static const struct snd_kcontrol_new lineout2_pa_mix[] = {
1919 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1920 4, 1, 0),
1921 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1922 4, 1, 0),
1923 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1924 TABLA_A_AUX_L_PA_CONN_INV, 4, 1, 0),
1925 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1926 TABLA_A_AUX_R_PA_CONN_INV, 4, 1, 0),
1927};
1928
1929static const struct snd_kcontrol_new lineout3_pa_mix[] = {
1930 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1931 3, 1, 0),
1932 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1933 3, 1, 0),
1934 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1935 TABLA_A_AUX_L_PA_CONN_INV, 3, 1, 0),
1936 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1937 TABLA_A_AUX_R_PA_CONN_INV, 3, 1, 0),
1938};
1939
1940static const struct snd_kcontrol_new lineout4_pa_mix[] = {
1941 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1942 2, 1, 0),
1943 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1944 2, 1, 0),
1945 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1946 TABLA_A_AUX_L_PA_CONN_INV, 2, 1, 0),
1947 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1948 TABLA_A_AUX_R_PA_CONN_INV, 2, 1, 0),
1949};
1950
1951static const struct snd_kcontrol_new lineout5_pa_mix[] = {
1952 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1953 1, 1, 0),
1954 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1955 1, 1, 0),
1956 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1957 TABLA_A_AUX_L_PA_CONN_INV, 1, 1, 0),
1958 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1959 TABLA_A_AUX_R_PA_CONN_INV, 1, 1, 0),
1960};
1961
1962static const struct snd_kcontrol_new ear_pa_mix[] = {
1963 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1964 0, 1, 0),
1965 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1966 0, 1, 0),
1967 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1968 TABLA_A_AUX_L_PA_CONN_INV, 0, 1, 0),
1969 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1970 TABLA_A_AUX_R_PA_CONN_INV, 0, 1, 0),
1971};
1972
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001973static const struct snd_kcontrol_new lineout3_ground_switch =
1974 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_3_DAC_CTL, 6, 1, 0);
1975
1976static const struct snd_kcontrol_new lineout4_ground_switch =
1977 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_4_DAC_CTL, 6, 1, 0);
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001978
Kuirong Wang906ac472012-07-09 12:54:44 -07001979/* virtual port entries */
1980static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol,
1981 struct snd_ctl_elem_value *ucontrol)
1982{
1983 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1984 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1985
1986 ucontrol->value.integer.value[0] = widget->value;
1987 return 0;
1988}
1989
1990static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol,
1991 struct snd_ctl_elem_value *ucontrol)
1992{
1993 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1994 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1995 struct snd_soc_codec *codec = widget->codec;
1996 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
1997 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
1998 struct soc_multi_mixer_control *mixer =
1999 ((struct soc_multi_mixer_control *)kcontrol->private_value);
2000 u32 dai_id = widget->shift;
2001 u32 port_id = mixer->shift;
2002 u32 enable = ucontrol->value.integer.value[0];
Venkat Sudhir96dd28c2012-12-04 17:00:19 -08002003 u32 vtable = vport_check_table[dai_id];
Kuirong Wang906ac472012-07-09 12:54:44 -07002004
2005 pr_debug("%s: wname %s cname %s value %u shift %d item %ld\n", __func__,
2006 widget->name, ucontrol->id.name, widget->value, widget->shift,
2007 ucontrol->value.integer.value[0]);
2008
2009 mutex_lock(&codec->mutex);
2010 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
2011 if (dai_id != AIF1_CAP) {
2012 dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
2013 __func__);
2014 mutex_unlock(&codec->mutex);
2015 return -EINVAL;
2016 }
2017 }
2018 switch (dai_id) {
2019 case AIF1_CAP:
2020 case AIF2_CAP:
2021 case AIF3_CAP:
2022 /* only add to the list if value not set
2023 */
2024 if (enable && !(widget->value & 1 << port_id)) {
Venkat Sudhir96dd28c2012-12-04 17:00:19 -08002025 if (tabla_p->intf_type ==
2026 WCD9XXX_INTERFACE_TYPE_SLIMBUS)
2027 vtable = vport_check_table[dai_id];
2028 if (tabla_p->intf_type == WCD9XXX_INTERFACE_TYPE_I2C)
2029 vtable = vport_i2s_check_table[dai_id];
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002030 if (wcd9xxx_tx_vport_validation(
Venkat Sudhir96dd28c2012-12-04 17:00:19 -08002031 vtable,
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002032 port_id,
2033 tabla_p->dai)) {
Kuirong Wang906ac472012-07-09 12:54:44 -07002034 pr_info("%s: TX%u is used by other virtual port\n",
2035 __func__, port_id + 1);
2036 mutex_unlock(&codec->mutex);
2037 return -EINVAL;
2038 }
2039 widget->value |= 1 << port_id;
2040 list_add_tail(&core->tx_chs[port_id].list,
2041 &tabla_p->dai[dai_id].wcd9xxx_ch_list
2042 );
2043 } else if (!enable && (widget->value & 1 << port_id)) {
2044 widget->value &= ~(1 << port_id);
2045 list_del_init(&core->tx_chs[port_id].list);
2046 } else {
2047 if (enable)
2048 pr_info("%s: TX%u port is used by this virtual port\n",
2049 __func__, port_id + 1);
2050 else
2051 pr_info("%s: TX%u port is not used by this virtual port\n",
2052 __func__, port_id + 1);
2053 /* avoid update power function */
2054 mutex_unlock(&codec->mutex);
2055 return 0;
2056 }
2057 break;
2058 default:
2059 pr_err("Unknown AIF %d\n", dai_id);
2060 mutex_unlock(&codec->mutex);
2061 return -EINVAL;
2062 }
2063 pr_debug("%s: name %s sname %s updated value %u shift %d\n", __func__,
2064 widget->name, widget->sname, widget->value, widget->shift);
2065
2066 snd_soc_dapm_mixer_update_power(widget, kcontrol, enable);
2067
2068 mutex_unlock(&codec->mutex);
2069 return 0;
2070}
2071
2072static int slim_rx_mux_get(struct snd_kcontrol *kcontrol,
2073 struct snd_ctl_elem_value *ucontrol)
2074{
2075 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2076 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2077
2078 ucontrol->value.enumerated.item[0] = widget->value;
2079 return 0;
2080}
2081
2082static const char *const slim_rx_mux_text[] = {
2083 "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB"
2084};
2085
2086static int slim_rx_mux_put(struct snd_kcontrol *kcontrol,
2087 struct snd_ctl_elem_value *ucontrol)
2088{
2089 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2090 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2091 struct snd_soc_codec *codec = widget->codec;
2092 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
2093 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
2094 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2095 u32 port_id = widget->shift;
2096
2097 pr_debug("%s: wname %s cname %s value %u shift %d item %u\n", __func__,
2098 widget->name, ucontrol->id.name, widget->value, widget->shift,
2099 ucontrol->value.enumerated.item[0]);
2100
2101 widget->value = ucontrol->value.enumerated.item[0];
2102
2103 mutex_lock(&codec->mutex);
2104
2105 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
2106 if (widget->value > 1) {
2107 dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
2108 __func__);
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002109 goto err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002110 }
2111 }
2112 /* value need to match the Virtual port and AIF number
2113 */
2114 switch (widget->value) {
2115 case 0:
2116 list_del_init(&core->rx_chs[port_id].list);
2117 break;
2118 case 1:
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002119 if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port,
2120 &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list))
2121 goto pr_err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002122 list_add_tail(&core->rx_chs[port_id].list,
2123 &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list);
2124 break;
2125 case 2:
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002126 if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port,
2127 &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list))
2128 goto pr_err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002129 list_add_tail(&core->rx_chs[port_id].list,
2130 &tabla_p->dai[AIF2_PB].wcd9xxx_ch_list);
2131 break;
2132 case 3:
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002133 if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port,
2134 &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list))
2135 goto pr_err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002136 list_add_tail(&core->rx_chs[port_id].list,
2137 &tabla_p->dai[AIF3_PB].wcd9xxx_ch_list);
2138 break;
2139 default:
2140 pr_err("Unknown AIF %d\n", widget->value);
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002141 goto err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002142 }
2143
2144 snd_soc_dapm_mux_update_power(widget, kcontrol, 1, widget->value, e);
2145
2146 mutex_unlock(&codec->mutex);
2147 return 0;
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002148
2149pr_err:
2150 pr_err("%s: RX%u is used by current requesting AIF_PB itself\n",
2151 __func__, port_id + 1);
Santosh Mardi2a831d72012-11-07 20:45:52 +05302152 mutex_unlock(&codec->mutex);
2153 return 0;
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002154err:
2155 mutex_unlock(&codec->mutex);
2156 return -EINVAL;
Kuirong Wang906ac472012-07-09 12:54:44 -07002157}
2158
2159static const struct soc_enum slim_rx_mux_enum =
2160 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text), slim_rx_mux_text);
2161
2162static const struct snd_kcontrol_new slim_rx_mux[TABLA_RX_MAX] = {
2163 SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum,
2164 slim_rx_mux_get, slim_rx_mux_put),
2165 SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum,
2166 slim_rx_mux_get, slim_rx_mux_put),
2167 SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum,
2168 slim_rx_mux_get, slim_rx_mux_put),
2169 SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum,
2170 slim_rx_mux_get, slim_rx_mux_put),
2171 SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum,
2172 slim_rx_mux_get, slim_rx_mux_put),
2173 SOC_DAPM_ENUM_EXT("SLIM RX6 Mux", slim_rx_mux_enum,
2174 slim_rx_mux_get, slim_rx_mux_put),
2175 SOC_DAPM_ENUM_EXT("SLIM RX7 Mux", slim_rx_mux_enum,
2176 slim_rx_mux_get, slim_rx_mux_put),
2177};
2178
2179static const struct snd_kcontrol_new aif_cap_mixer[] = {
2180 SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, TABLA_TX1, 1, 0,
2181 slim_tx_mixer_get, slim_tx_mixer_put),
2182 SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, TABLA_TX2, 1, 0,
2183 slim_tx_mixer_get, slim_tx_mixer_put),
2184 SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, TABLA_TX3, 1, 0,
2185 slim_tx_mixer_get, slim_tx_mixer_put),
2186 SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, TABLA_TX4, 1, 0,
2187 slim_tx_mixer_get, slim_tx_mixer_put),
2188 SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, TABLA_TX5, 1, 0,
2189 slim_tx_mixer_get, slim_tx_mixer_put),
2190 SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, TABLA_TX6, 1, 0,
2191 slim_tx_mixer_get, slim_tx_mixer_put),
2192 SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, TABLA_TX7, 1, 0,
2193 slim_tx_mixer_get, slim_tx_mixer_put),
2194 SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, TABLA_TX8, 1, 0,
2195 slim_tx_mixer_get, slim_tx_mixer_put),
2196 SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, TABLA_TX9, 1, 0,
2197 slim_tx_mixer_get, slim_tx_mixer_put),
2198 SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, TABLA_TX10, 1, 0,
2199 slim_tx_mixer_get, slim_tx_mixer_put),
2200};
2201
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002202static void tabla_codec_enable_adc_block(struct snd_soc_codec *codec,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002203 int enable)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002204{
2205 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2206
2207 pr_debug("%s %d\n", __func__, enable);
2208
2209 if (enable) {
2210 tabla->adc_count++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002211 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x2, 0x2);
2212 } else {
2213 tabla->adc_count--;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002214 if (!tabla->adc_count)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002215 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL,
Joonwoo Park03324832012-03-19 19:36:16 -07002216 0x2, 0x0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002217 }
2218}
2219
2220static int tabla_codec_enable_adc(struct snd_soc_dapm_widget *w,
2221 struct snd_kcontrol *kcontrol, int event)
2222{
2223 struct snd_soc_codec *codec = w->codec;
2224 u16 adc_reg;
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08002225 u8 init_bit_shift;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002226
2227 pr_debug("%s %d\n", __func__, event);
2228
2229 if (w->reg == TABLA_A_TX_1_2_EN)
2230 adc_reg = TABLA_A_TX_1_2_TEST_CTL;
2231 else if (w->reg == TABLA_A_TX_3_4_EN)
2232 adc_reg = TABLA_A_TX_3_4_TEST_CTL;
2233 else if (w->reg == TABLA_A_TX_5_6_EN)
2234 adc_reg = TABLA_A_TX_5_6_TEST_CTL;
2235 else {
2236 pr_err("%s: Error, invalid adc register\n", __func__);
2237 return -EINVAL;
2238 }
2239
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08002240 if (w->shift == 3)
2241 init_bit_shift = 6;
2242 else if (w->shift == 7)
2243 init_bit_shift = 7;
2244 else {
2245 pr_err("%s: Error, invalid init bit postion adc register\n",
2246 __func__);
2247 return -EINVAL;
2248 }
2249
2250
2251
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002252 switch (event) {
2253 case SND_SOC_DAPM_PRE_PMU:
2254 tabla_codec_enable_adc_block(codec, 1);
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08002255 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift,
2256 1 << init_bit_shift);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002257 break;
2258 case SND_SOC_DAPM_POST_PMU:
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08002259
2260 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00);
2261
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002262 break;
2263 case SND_SOC_DAPM_POST_PMD:
2264 tabla_codec_enable_adc_block(codec, 0);
2265 break;
2266 }
2267 return 0;
2268}
2269
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002270static void tabla_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec)
2271{
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002272 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2273 0x80);
2274 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x04,
2275 0x04);
2276 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01,
2277 0x01);
2278 usleep_range(1000, 1000);
2279 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2280 0x00);
2281}
2282
2283static void tabla_codec_enable_bandgap(struct snd_soc_codec *codec,
2284 enum tabla_bandgap_type choice)
2285{
2286 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2287
2288 /* TODO lock resources accessed by audio streams and threaded
2289 * interrupt handlers
2290 */
2291
2292 pr_debug("%s, choice is %d, current is %d\n", __func__, choice,
2293 tabla->bandgap_type);
2294
2295 if (tabla->bandgap_type == choice)
2296 return;
2297
2298 if ((tabla->bandgap_type == TABLA_BANDGAP_OFF) &&
2299 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
2300 tabla_codec_enable_audio_mode_bandgap(codec);
2301 } else if (choice == TABLA_BANDGAP_MBHC_MODE) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002302 /* bandgap mode becomes fast,
2303 * mclk should be off or clk buff source souldn't be VBG
2304 * Let's turn off mclk always */
2305 WARN_ON(snd_soc_read(codec, TABLA_A_CLK_BUFF_EN2) & (1 << 2));
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002306 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x2,
2307 0x2);
2308 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2309 0x80);
2310 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x4,
2311 0x4);
2312 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01,
2313 0x01);
2314 usleep_range(1000, 1000);
2315 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2316 0x00);
2317 } else if ((tabla->bandgap_type == TABLA_BANDGAP_MBHC_MODE) &&
2318 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
Damir Didjusto7c85d712012-08-16 21:22:29 -07002319 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002320 usleep_range(100, 100);
2321 tabla_codec_enable_audio_mode_bandgap(codec);
2322 } else if (choice == TABLA_BANDGAP_OFF) {
Damir Didjusto7c85d712012-08-16 21:22:29 -07002323 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002324 } else {
2325 pr_err("%s: Error, Invalid bandgap settings\n", __func__);
2326 }
2327 tabla->bandgap_type = choice;
2328}
2329
2330static void tabla_codec_disable_clock_block(struct snd_soc_codec *codec)
2331{
2332 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2333 pr_debug("%s\n", __func__);
2334 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x00);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002335 usleep_range(50, 50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002336 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x02);
2337 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x00);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002338 usleep_range(50, 50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002339 tabla->clock_active = false;
2340}
2341
2342static int tabla_codec_mclk_index(const struct tabla_priv *tabla)
2343{
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002344 if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002345 return 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002346 else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002347 return 1;
2348 else {
2349 BUG_ON(1);
2350 return -EINVAL;
2351 }
2352}
2353
2354static void tabla_enable_rx_bias(struct snd_soc_codec *codec, u32 enable)
2355{
2356 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2357
2358 if (enable) {
2359 tabla->rx_bias_count++;
2360 if (tabla->rx_bias_count == 1)
2361 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
2362 0x80, 0x80);
2363 } else {
2364 tabla->rx_bias_count--;
2365 if (!tabla->rx_bias_count)
2366 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
2367 0x80, 0x00);
2368 }
2369}
2370
2371static int tabla_codec_enable_config_mode(struct snd_soc_codec *codec,
2372 int enable)
2373{
2374 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2375
2376 pr_debug("%s: enable = %d\n", __func__, enable);
2377 if (enable) {
2378 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x10, 0);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002379 /* bandgap mode to fast */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002380 snd_soc_write(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x17);
2381 usleep_range(5, 5);
2382 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002383 0x80);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002384 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002385 0x80);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002386 usleep_range(10, 10);
2387 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, 0);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002388 usleep_range(10000, 10000);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002389 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x08);
2390 } else {
2391 snd_soc_update_bits(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x1,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002392 0);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002393 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, 0);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002394 /* clk source to ext clk and clk buff ref to VBG */
2395 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x0C, 0x04);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002396 }
2397 tabla->config_mode_active = enable ? true : false;
2398
2399 return 0;
2400}
2401
2402static int tabla_codec_enable_clock_block(struct snd_soc_codec *codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002403 int config_mode)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002404{
2405 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2406
2407 pr_debug("%s: config_mode = %d\n", __func__, config_mode);
2408
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002409 /* transit to RCO requires mclk off */
2410 WARN_ON(snd_soc_read(codec, TABLA_A_CLK_BUFF_EN2) & (1 << 2));
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002411 if (config_mode) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002412 /* enable RCO and switch to it */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002413 tabla_codec_enable_config_mode(codec, 1);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002414 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002415 usleep_range(1000, 1000);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002416 } else {
2417 /* switch to MCLK */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002418 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00);
2419
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002420 if (tabla->mbhc_polling_active) {
2421 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
2422 tabla_codec_enable_config_mode(codec, 0);
2423 }
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002424 }
2425
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002426 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x01, 0x01);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002427 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x00);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002428 /* on MCLK */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002429 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x04);
2430 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_MCLK_CTL, 0x01, 0x01);
2431 usleep_range(50, 50);
2432 tabla->clock_active = true;
2433 return 0;
2434}
2435
2436static int tabla_codec_enable_aux_pga(struct snd_soc_dapm_widget *w,
2437 struct snd_kcontrol *kcontrol, int event)
2438{
2439 struct snd_soc_codec *codec = w->codec;
2440 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2441
2442 pr_debug("%s: %d\n", __func__, event);
2443
2444 switch (event) {
2445 case SND_SOC_DAPM_PRE_PMU:
2446 tabla_codec_enable_bandgap(codec,
2447 TABLA_BANDGAP_AUDIO_MODE);
2448 tabla_enable_rx_bias(codec, 1);
2449
2450 snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL,
2451 0x08, 0x08);
2452 /* Enable Zero Cross detect for AUX PGA channel
2453 * and set the initial AUX PGA gain to NEG_0P0_DB
2454 * to avoid glitches.
2455 */
2456 if (w->reg == TABLA_A_AUX_L_EN) {
2457 snd_soc_update_bits(codec, TABLA_A_AUX_L_EN,
2458 0x20, 0x20);
2459 tabla->aux_l_gain = snd_soc_read(codec,
2460 TABLA_A_AUX_L_GAIN);
2461 snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F);
2462 } else {
2463 snd_soc_update_bits(codec, TABLA_A_AUX_R_EN,
2464 0x20, 0x20);
2465 tabla->aux_r_gain = snd_soc_read(codec,
2466 TABLA_A_AUX_R_GAIN);
2467 snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F);
2468 }
2469 if (tabla->aux_pga_cnt++ == 1
2470 && !tabla->mclk_enabled) {
2471 tabla_codec_enable_clock_block(codec, 1);
2472 pr_debug("AUX PGA enabled RC osc\n");
2473 }
2474 break;
2475
2476 case SND_SOC_DAPM_POST_PMU:
2477 if (w->reg == TABLA_A_AUX_L_EN)
2478 snd_soc_write(codec, TABLA_A_AUX_L_GAIN,
2479 tabla->aux_l_gain);
2480 else
2481 snd_soc_write(codec, TABLA_A_AUX_R_GAIN,
2482 tabla->aux_r_gain);
2483 break;
2484
2485 case SND_SOC_DAPM_PRE_PMD:
2486 /* Mute AUX PGA channel in use before disabling AUX PGA */
2487 if (w->reg == TABLA_A_AUX_L_EN) {
2488 tabla->aux_l_gain = snd_soc_read(codec,
2489 TABLA_A_AUX_L_GAIN);
2490 snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F);
2491 } else {
2492 tabla->aux_r_gain = snd_soc_read(codec,
2493 TABLA_A_AUX_R_GAIN);
2494 snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F);
2495 }
2496 break;
2497
2498 case SND_SOC_DAPM_POST_PMD:
2499 tabla_enable_rx_bias(codec, 0);
2500
2501 snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL,
2502 0x08, 0x00);
2503 if (w->reg == TABLA_A_AUX_L_EN) {
2504 snd_soc_write(codec, TABLA_A_AUX_L_GAIN,
2505 tabla->aux_l_gain);
2506 snd_soc_update_bits(codec, TABLA_A_AUX_L_EN,
2507 0x20, 0x00);
2508 } else {
2509 snd_soc_write(codec, TABLA_A_AUX_R_GAIN,
2510 tabla->aux_r_gain);
2511 snd_soc_update_bits(codec, TABLA_A_AUX_R_EN,
2512 0x20, 0x00);
2513 }
2514
2515 if (tabla->aux_pga_cnt-- == 0) {
2516 if (tabla->mbhc_polling_active)
2517 tabla_codec_enable_bandgap(codec,
2518 TABLA_BANDGAP_MBHC_MODE);
2519 else
2520 tabla_codec_enable_bandgap(codec,
2521 TABLA_BANDGAP_OFF);
2522
2523 if (!tabla->mclk_enabled &&
2524 !tabla->mbhc_polling_active) {
2525 tabla_codec_enable_clock_block(codec, 0);
2526 }
2527 }
2528 break;
2529 }
2530 return 0;
2531}
2532
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002533static int tabla_codec_enable_lineout(struct snd_soc_dapm_widget *w,
2534 struct snd_kcontrol *kcontrol, int event)
2535{
2536 struct snd_soc_codec *codec = w->codec;
2537 u16 lineout_gain_reg;
2538
Kiran Kandidb0a4b02011-08-23 09:32:09 -07002539 pr_debug("%s %d %s\n", __func__, event, w->name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002540
2541 switch (w->shift) {
2542 case 0:
2543 lineout_gain_reg = TABLA_A_RX_LINE_1_GAIN;
2544 break;
2545 case 1:
2546 lineout_gain_reg = TABLA_A_RX_LINE_2_GAIN;
2547 break;
2548 case 2:
2549 lineout_gain_reg = TABLA_A_RX_LINE_3_GAIN;
2550 break;
2551 case 3:
2552 lineout_gain_reg = TABLA_A_RX_LINE_4_GAIN;
2553 break;
2554 case 4:
2555 lineout_gain_reg = TABLA_A_RX_LINE_5_GAIN;
2556 break;
2557 default:
2558 pr_err("%s: Error, incorrect lineout register value\n",
2559 __func__);
2560 return -EINVAL;
2561 }
2562
2563 switch (event) {
2564 case SND_SOC_DAPM_PRE_PMU:
2565 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40);
2566 break;
2567 case SND_SOC_DAPM_POST_PMU:
Krishnankutty Kolathappilly31169f42011-11-17 10:33:11 -08002568 pr_debug("%s: sleeping 16 ms after %s PA turn on\n",
Kiran Kandidb0a4b02011-08-23 09:32:09 -07002569 __func__, w->name);
Krishnankutty Kolathappilly31169f42011-11-17 10:33:11 -08002570 usleep_range(16000, 16000);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002571 break;
2572 case SND_SOC_DAPM_POST_PMD:
2573 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00);
2574 break;
2575 }
2576 return 0;
2577}
2578
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002579
2580static int tabla_codec_enable_dmic(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002581 struct snd_kcontrol *kcontrol, int event)
2582{
2583 struct snd_soc_codec *codec = w->codec;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002584 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2585 u8 dmic_clk_en;
2586 s32 *dmic_clk_cnt;
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002587 unsigned int dmic;
2588 int ret;
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002589
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002590 ret = kstrtouint(strpbrk(w->name, "123456"), 10, &dmic);
2591 if (ret < 0) {
2592 pr_err("%s: Invalid DMIC line on the codec\n", __func__);
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002593 return -EINVAL;
2594 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002595
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002596 switch (dmic) {
2597 case 1:
2598 case 2:
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002599 dmic_clk_en = 0x01;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002600 dmic_clk_cnt = &(tabla->dmic_1_2_clk_cnt);
2601
2602 pr_debug("%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n",
2603 __func__, event, dmic, *dmic_clk_cnt);
2604
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002605 break;
2606
2607 case 3:
2608 case 4:
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002609 dmic_clk_en = 0x04;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002610 dmic_clk_cnt = &(tabla->dmic_3_4_clk_cnt);
2611
2612 pr_debug("%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n",
2613 __func__, event, dmic, *dmic_clk_cnt);
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002614 break;
2615
2616 case 5:
2617 case 6:
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002618 dmic_clk_en = 0x10;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002619 dmic_clk_cnt = &(tabla->dmic_5_6_clk_cnt);
2620
2621 pr_debug("%s() event %d DMIC%d dmic_5_6_clk_cnt %d\n",
2622 __func__, event, dmic, *dmic_clk_cnt);
2623
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002624 break;
2625
2626 default:
2627 pr_err("%s: Invalid DMIC Selection\n", __func__);
2628 return -EINVAL;
2629 }
2630
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002631 switch (event) {
2632 case SND_SOC_DAPM_PRE_PMU:
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002633
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002634 (*dmic_clk_cnt)++;
2635 if (*dmic_clk_cnt == 1)
2636 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
2637 dmic_clk_en, dmic_clk_en);
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002638
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002639 break;
2640 case SND_SOC_DAPM_POST_PMD:
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002641
2642 (*dmic_clk_cnt)--;
2643 if (*dmic_clk_cnt == 0)
2644 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
2645 dmic_clk_en, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002646 break;
2647 }
2648 return 0;
2649}
2650
Bradley Rubin229c6a52011-07-12 16:18:48 -07002651
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002652/* called under codec_resource_lock acquisition */
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002653static void tabla_codec_start_hs_polling(struct snd_soc_codec *codec)
2654{
Bradley Rubincb3950a2011-08-18 13:07:26 -07002655 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07002656 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
2657 int mbhc_state = tabla->mbhc_state;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002658
Joonwoo Park03324832012-03-19 19:36:16 -07002659 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002660 if (!tabla->mbhc_polling_active) {
2661 pr_debug("Polling is not active, do not start polling\n");
2662 return;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002663 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002664 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Joonwoo Park03324832012-03-19 19:36:16 -07002665
Joonwoo Park5bbcb0c2012-08-07 17:25:52 -07002666 if (tabla->no_mic_headset_override) {
2667 pr_debug("%s setting button threshold to min", __func__);
2668 /* set to min */
2669 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, 0x80);
2670 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0x00);
2671 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0x80);
2672 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0x00);
2673 } else if (unlikely(mbhc_state == MBHC_STATE_POTENTIAL)) {
2674 pr_debug("%s recovering MBHC state machine\n", __func__);
2675 tabla->mbhc_state = MBHC_STATE_POTENTIAL_RECOVERY;
2676 /* set to max button press threshold */
2677 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, 0x7F);
2678 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, 0xFF);
2679 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL,
2680 (TABLA_IS_1_X(tabla_core->version) ?
2681 0x07 : 0x7F));
2682 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0xFF);
2683 /* set to max */
2684 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0x7F);
2685 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0xFF);
Joonwoo Park03324832012-03-19 19:36:16 -07002686 }
2687
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002688 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
2689 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
2690 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
Joonwoo Park03324832012-03-19 19:36:16 -07002691 pr_debug("%s: leave\n", __func__);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002692}
2693
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002694/* called under codec_resource_lock acquisition */
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002695static void tabla_codec_pause_hs_polling(struct snd_soc_codec *codec)
2696{
Bradley Rubincb3950a2011-08-18 13:07:26 -07002697 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2698
Joonwoo Park03324832012-03-19 19:36:16 -07002699 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002700 if (!tabla->mbhc_polling_active) {
2701 pr_debug("polling not active, nothing to pause\n");
2702 return;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002703 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002704
Simmi Pateriya1b9a3092013-01-02 11:49:26 +05302705 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01);
2706 msleep(250);
2707 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002708 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
Joonwoo Park03324832012-03-19 19:36:16 -07002709 pr_debug("%s: leave\n", __func__);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002710}
2711
Joonwoo Park03324832012-03-19 19:36:16 -07002712static void tabla_codec_switch_cfilt_mode(struct snd_soc_codec *codec, int mode)
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002713{
2714 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2715 u8 reg_mode_val, cur_mode_val;
2716 bool mbhc_was_polling = false;
2717
2718 if (mode)
2719 reg_mode_val = TABLA_CFILT_FAST_MODE;
2720 else
2721 reg_mode_val = TABLA_CFILT_SLOW_MODE;
2722
2723 cur_mode_val = snd_soc_read(codec,
2724 tabla->mbhc_bias_regs.cfilt_ctl) & 0x40;
2725
2726 if (cur_mode_val != reg_mode_val) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002727 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002728 if (tabla->mbhc_polling_active) {
2729 tabla_codec_pause_hs_polling(codec);
2730 mbhc_was_polling = true;
2731 }
2732 snd_soc_update_bits(codec,
2733 tabla->mbhc_bias_regs.cfilt_ctl, 0x40, reg_mode_val);
2734 if (mbhc_was_polling)
2735 tabla_codec_start_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002736 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002737 pr_debug("%s: CFILT mode change (%x to %x)\n", __func__,
2738 cur_mode_val, reg_mode_val);
2739 } else {
2740 pr_debug("%s: CFILT Value is already %x\n",
2741 __func__, cur_mode_val);
2742 }
2743}
2744
2745static void tabla_codec_update_cfilt_usage(struct snd_soc_codec *codec,
2746 u8 cfilt_sel, int inc)
2747{
2748 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2749 u32 *cfilt_cnt_ptr = NULL;
2750 u16 micb_cfilt_reg;
2751
2752 switch (cfilt_sel) {
2753 case TABLA_CFILT1_SEL:
2754 cfilt_cnt_ptr = &tabla->cfilt1_cnt;
2755 micb_cfilt_reg = TABLA_A_MICB_CFILT_1_CTL;
2756 break;
2757 case TABLA_CFILT2_SEL:
2758 cfilt_cnt_ptr = &tabla->cfilt2_cnt;
2759 micb_cfilt_reg = TABLA_A_MICB_CFILT_2_CTL;
2760 break;
2761 case TABLA_CFILT3_SEL:
2762 cfilt_cnt_ptr = &tabla->cfilt3_cnt;
2763 micb_cfilt_reg = TABLA_A_MICB_CFILT_3_CTL;
2764 break;
2765 default:
2766 return; /* should not happen */
2767 }
2768
2769 if (inc) {
2770 if (!(*cfilt_cnt_ptr)++) {
2771 /* Switch CFILT to slow mode if MBHC CFILT being used */
2772 if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel)
2773 tabla_codec_switch_cfilt_mode(codec, 0);
2774
2775 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80);
2776 }
2777 } else {
2778 /* check if count not zero, decrement
2779 * then check if zero, go ahead disable cfilter
2780 */
2781 if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr)) {
2782 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0);
2783
2784 /* Switch CFILT to fast mode if MBHC CFILT being used */
2785 if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel)
2786 tabla_codec_switch_cfilt_mode(codec, 1);
2787 }
2788 }
2789}
2790
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002791static int tabla_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv)
2792{
2793 int rc = -EINVAL;
2794 unsigned min_mv, max_mv;
2795
2796 switch (ldoh_v) {
2797 case TABLA_LDOH_1P95_V:
2798 min_mv = 160;
2799 max_mv = 1800;
2800 break;
2801 case TABLA_LDOH_2P35_V:
2802 min_mv = 200;
2803 max_mv = 2200;
2804 break;
2805 case TABLA_LDOH_2P75_V:
2806 min_mv = 240;
2807 max_mv = 2600;
2808 break;
2809 case TABLA_LDOH_2P85_V:
2810 min_mv = 250;
2811 max_mv = 2700;
2812 break;
2813 default:
2814 goto done;
2815 }
2816
2817 if (cfilt_mv < min_mv || cfilt_mv > max_mv)
2818 goto done;
2819
2820 for (rc = 4; rc <= 44; rc++) {
2821 min_mv = max_mv * (rc) / 44;
2822 if (min_mv >= cfilt_mv) {
2823 rc -= 4;
2824 break;
2825 }
2826 }
2827done:
2828 return rc;
2829}
2830
2831static bool tabla_is_hph_pa_on(struct snd_soc_codec *codec)
2832{
2833 u8 hph_reg_val = 0;
2834 hph_reg_val = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_EN);
2835
2836 return (hph_reg_val & 0x30) ? true : false;
2837}
2838
Joonwoo Parka9444452011-12-08 18:48:27 -08002839static bool tabla_is_hph_dac_on(struct snd_soc_codec *codec, int left)
2840{
2841 u8 hph_reg_val = 0;
2842 if (left)
2843 hph_reg_val = snd_soc_read(codec,
2844 TABLA_A_RX_HPH_L_DAC_CTL);
2845 else
2846 hph_reg_val = snd_soc_read(codec,
2847 TABLA_A_RX_HPH_R_DAC_CTL);
2848
2849 return (hph_reg_val & 0xC0) ? true : false;
2850}
2851
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002852static void tabla_turn_onoff_override(struct snd_soc_codec *codec, bool on)
2853{
2854 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, on << 2);
2855}
2856
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002857/* called under codec_resource_lock acquisition */
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002858static void tabla_codec_drive_v_to_micbias(struct snd_soc_codec *codec,
2859 int usec)
2860{
2861 int cfilt_k_val;
2862 bool set = true;
2863 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2864
2865 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
2866 tabla->mbhc_micbias_switched) {
2867 pr_debug("%s: set mic V to micbias V\n", __func__);
2868 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
2869 tabla_turn_onoff_override(codec, true);
2870 while (1) {
2871 cfilt_k_val = tabla_find_k_value(
2872 tabla->pdata->micbias.ldoh_v,
2873 set ? tabla->mbhc_data.micb_mv :
2874 VDDIO_MICBIAS_MV);
2875 snd_soc_update_bits(codec,
2876 tabla->mbhc_bias_regs.cfilt_val,
2877 0xFC, (cfilt_k_val << 2));
2878 if (!set)
2879 break;
2880 usleep_range(usec, usec);
2881 set = false;
2882 }
2883 tabla_turn_onoff_override(codec, false);
2884 }
2885}
2886
2887/* called under codec_resource_lock acquisition */
2888static void __tabla_codec_switch_micbias(struct snd_soc_codec *codec,
2889 int vddio_switch, bool restartpolling,
2890 bool checkpolling)
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002891{
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002892 int cfilt_k_val;
Joonwoo Park41956722012-04-18 13:13:07 -07002893 bool override;
2894 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002895
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002896 if (vddio_switch && !tabla->mbhc_micbias_switched &&
2897 (!checkpolling || tabla->mbhc_polling_active)) {
2898 if (restartpolling)
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08002899 tabla_codec_pause_hs_polling(codec);
Joonwoo Park41956722012-04-18 13:13:07 -07002900 override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04;
2901 if (!override)
2902 tabla_turn_onoff_override(codec, true);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002903 /* Adjust threshold if Mic Bias voltage changes */
2904 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002905 cfilt_k_val = tabla_find_k_value(
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002906 tabla->pdata->micbias.ldoh_v,
2907 VDDIO_MICBIAS_MV);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002908 snd_soc_update_bits(codec,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002909 tabla->mbhc_bias_regs.cfilt_val,
2910 0xFC, (cfilt_k_val << 2));
Joonwoo Parkc1c67a92012-08-07 16:05:36 -07002911 usleep_range(cfilt_adjust_ms * 1000,
2912 cfilt_adjust_ms * 1000);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002913 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
2914 tabla->mbhc_data.adj_v_ins_hu & 0xFF);
2915 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
2916 (tabla->mbhc_data.adj_v_ins_hu >> 8) &
2917 0xFF);
2918 pr_debug("%s: Programmed MBHC thresholds to VDDIO\n",
2919 __func__);
2920 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002921
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002922 /* enable MIC BIAS Switch to VDDIO */
2923 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2924 0x80, 0x80);
2925 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2926 0x10, 0x00);
Joonwoo Park41956722012-04-18 13:13:07 -07002927 if (!override)
2928 tabla_turn_onoff_override(codec, false);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002929 if (restartpolling)
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08002930 tabla_codec_start_hs_polling(codec);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002931
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002932 tabla->mbhc_micbias_switched = true;
2933 pr_debug("%s: VDDIO switch enabled\n", __func__);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002934 } else if (!vddio_switch && tabla->mbhc_micbias_switched) {
2935 if ((!checkpolling || tabla->mbhc_polling_active) &&
2936 restartpolling)
2937 tabla_codec_pause_hs_polling(codec);
2938 /* Reprogram thresholds */
2939 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
2940 cfilt_k_val = tabla_find_k_value(
2941 tabla->pdata->micbias.ldoh_v,
2942 tabla->mbhc_data.micb_mv);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002943 snd_soc_update_bits(codec,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002944 tabla->mbhc_bias_regs.cfilt_val,
2945 0xFC, (cfilt_k_val << 2));
Joonwoo Parkc1c67a92012-08-07 16:05:36 -07002946 usleep_range(cfilt_adjust_ms * 1000,
2947 cfilt_adjust_ms * 1000);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002948 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
2949 tabla->mbhc_data.v_ins_hu & 0xFF);
2950 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
2951 (tabla->mbhc_data.v_ins_hu >> 8) & 0xFF);
2952 pr_debug("%s: Programmed MBHC thresholds to MICBIAS\n",
2953 __func__);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002954 }
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002955
2956 /* Disable MIC BIAS Switch to VDDIO */
2957 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2958 0x80, 0x00);
2959 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2960 0x10, 0x00);
2961
2962 if ((!checkpolling || tabla->mbhc_polling_active) &&
2963 restartpolling)
2964 tabla_codec_start_hs_polling(codec);
2965
2966 tabla->mbhc_micbias_switched = false;
2967 pr_debug("%s: VDDIO switch disabled\n", __func__);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002968 }
2969}
2970
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002971static void tabla_codec_switch_micbias(struct snd_soc_codec *codec,
2972 int vddio_switch)
2973{
2974 return __tabla_codec_switch_micbias(codec, vddio_switch, true, true);
2975}
2976
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002977static int tabla_codec_enable_micbias(struct snd_soc_dapm_widget *w,
2978 struct snd_kcontrol *kcontrol, int event)
2979{
2980 struct snd_soc_codec *codec = w->codec;
Patrick Lai3043fba2011-08-01 14:15:57 -07002981 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2982 u16 micb_int_reg;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002983 int micb_line;
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002984 u8 cfilt_sel_val = 0;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002985 char *internal1_text = "Internal1";
2986 char *internal2_text = "Internal2";
2987 char *internal3_text = "Internal3";
Simmi Pateriya71d63872012-11-08 01:06:30 +05302988 const char *micbias1_text = "MIC BIAS1 ";
2989 const char *micbias2_text = "MIC BIAS2 ";
2990 const char *micbias3_text = "MIC BIAS3 ";
2991 const char *micbias4_text = "MIC BIAS4 ";
2992 u32 *micbias_enable_count;
2993 u16 wreg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002994
2995 pr_debug("%s %d\n", __func__, event);
Simmi Pateriya71d63872012-11-08 01:06:30 +05302996 if (strnstr(w->name, micbias1_text, strlen(micbias1_text))) {
2997 wreg = TABLA_A_MICB_1_CTL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002998 micb_int_reg = TABLA_A_MICB_1_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07002999 cfilt_sel_val = tabla->pdata->micbias.bias1_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003000 micb_line = TABLA_MICBIAS1;
Simmi Pateriya71d63872012-11-08 01:06:30 +05303001 } else if (strnstr(w->name, micbias2_text, strlen(micbias2_text))) {
3002 wreg = TABLA_A_MICB_2_CTL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003003 micb_int_reg = TABLA_A_MICB_2_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07003004 cfilt_sel_val = tabla->pdata->micbias.bias2_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003005 micb_line = TABLA_MICBIAS2;
Simmi Pateriya71d63872012-11-08 01:06:30 +05303006 } else if (strnstr(w->name, micbias3_text, strlen(micbias3_text))) {
3007 wreg = TABLA_A_MICB_3_CTL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003008 micb_int_reg = TABLA_A_MICB_3_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07003009 cfilt_sel_val = tabla->pdata->micbias.bias3_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003010 micb_line = TABLA_MICBIAS3;
Simmi Pateriya71d63872012-11-08 01:06:30 +05303011 } else if (strnstr(w->name, micbias4_text, strlen(micbias4_text))) {
3012 wreg = tabla->reg_addr.micb_4_ctl;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003013 micb_int_reg = tabla->reg_addr.micb_4_int_rbias;
Patrick Lai3043fba2011-08-01 14:15:57 -07003014 cfilt_sel_val = tabla->pdata->micbias.bias4_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003015 micb_line = TABLA_MICBIAS4;
Simmi Pateriya71d63872012-11-08 01:06:30 +05303016 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003017 pr_err("%s: Error, invalid micbias register\n", __func__);
3018 return -EINVAL;
3019 }
3020
Simmi Pateriya71d63872012-11-08 01:06:30 +05303021 micbias_enable_count = &tabla->micbias_enable_count[micb_line];
3022 pr_debug("%s: counter %d\n", __func__, *micbias_enable_count);
3023
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003024 switch (event) {
3025 case SND_SOC_DAPM_PRE_PMU:
Simmi Pateriya71d63872012-11-08 01:06:30 +05303026 if (++*micbias_enable_count > 1) {
3027 pr_debug("%s: do nothing, counter %d\n",
3028 __func__, *micbias_enable_count);
3029 break;
3030 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003031 /* Decide whether to switch the micbias for MBHC */
Simmi Pateriya71d63872012-11-08 01:06:30 +05303032 if (wreg == tabla->mbhc_bias_regs.ctl_reg) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003033 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003034 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003035 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
3036 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003037
Simmi Pateriya71d63872012-11-08 01:06:30 +05303038 snd_soc_update_bits(codec, wreg, 0x0E, 0x0A);
Patrick Lai3043fba2011-08-01 14:15:57 -07003039 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 1);
Bradley Rubin229c6a52011-07-12 16:18:48 -07003040
3041 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003042 snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0);
Bradley Rubin229c6a52011-07-12 16:18:48 -07003043 else if (strnstr(w->name, internal2_text, 30))
3044 snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C);
3045 else if (strnstr(w->name, internal3_text, 30))
3046 snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3);
3047
Simmi Pateriya71d63872012-11-08 01:06:30 +05303048 snd_soc_update_bits(codec, wreg, 1 << 7, 1 << 7);
3049
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003050 break;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003051 case SND_SOC_DAPM_POST_PMU:
Simmi Pateriya71d63872012-11-08 01:06:30 +05303052 if (*micbias_enable_count > 1) {
3053 pr_debug("%s: do nothing, counter %d\n",
3054 __func__, *micbias_enable_count);
3055 break;
3056 }
Kiran Kandid8cf5212012-03-02 15:34:53 -08003057 usleep_range(20000, 20000);
3058
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003059 if (tabla->mbhc_polling_active &&
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003060 tabla->mbhc_cfg.micbias == micb_line) {
3061 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003062 tabla_codec_pause_hs_polling(codec);
3063 tabla_codec_start_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003064 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003065 }
3066 break;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003067
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003068 case SND_SOC_DAPM_POST_PMD:
Simmi Pateriya71d63872012-11-08 01:06:30 +05303069 if (--*micbias_enable_count > 0) {
3070 pr_debug("%s: do nothing, counter %d\n",
3071 __func__, *micbias_enable_count);
3072 break;
3073 }
3074
3075 snd_soc_update_bits(codec, wreg, 1 << 7, 0);
3076
3077 if ((wreg == tabla->mbhc_bias_regs.ctl_reg) &&
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003078 tabla_is_hph_pa_on(codec)) {
3079 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003080 tabla_codec_switch_micbias(codec, 1);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003081 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
3082 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003083
Bradley Rubin229c6a52011-07-12 16:18:48 -07003084 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003085 snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00);
Bradley Rubin229c6a52011-07-12 16:18:48 -07003086 else if (strnstr(w->name, internal2_text, 30))
3087 snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00);
3088 else if (strnstr(w->name, internal3_text, 30))
3089 snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0);
3090
Patrick Lai3043fba2011-08-01 14:15:57 -07003091 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003092 break;
3093 }
3094
3095 return 0;
3096}
3097
Kiran Kandid8cf5212012-03-02 15:34:53 -08003098
3099static void tx_hpf_corner_freq_callback(struct work_struct *work)
3100{
3101 struct delayed_work *hpf_delayed_work;
3102 struct hpf_work *hpf_work;
3103 struct tabla_priv *tabla;
3104 struct snd_soc_codec *codec;
3105 u16 tx_mux_ctl_reg;
3106 u8 hpf_cut_of_freq;
3107
3108 hpf_delayed_work = to_delayed_work(work);
3109 hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
3110 tabla = hpf_work->tabla;
3111 codec = hpf_work->tabla->codec;
3112 hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq;
3113
3114 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL +
3115 (hpf_work->decimator - 1) * 8;
3116
3117 pr_debug("%s(): decimator %u hpf_cut_of_freq 0x%x\n", __func__,
3118 hpf_work->decimator, (unsigned int)hpf_cut_of_freq);
3119
3120 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4);
3121}
3122
3123#define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30
3124#define CF_MIN_3DB_4HZ 0x0
3125#define CF_MIN_3DB_75HZ 0x1
3126#define CF_MIN_3DB_150HZ 0x2
3127
Simmi Pateriya71d63872012-11-08 01:06:30 +05303128static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
3129 struct snd_kcontrol *kcontrol, int event);
3130
3131static int tabla_codec_enable_micbias_power(struct snd_soc_dapm_widget *w,
3132 struct snd_kcontrol *kcontrol,
3133 int event)
3134{
3135 struct snd_soc_codec *codec = w->codec;
3136 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3137
3138 pr_debug("%s %d\n", __func__, event);
3139
3140 switch (event) {
3141 case SND_SOC_DAPM_PRE_PMU:
3142 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, true);
3143 tabla_codec_enable_ldo_h(w, kcontrol, event);
3144 tabla_codec_enable_micbias(w, kcontrol, event);
3145 break;
3146 case SND_SOC_DAPM_POST_PMU:
3147 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, true);
3148 break;
3149 case SND_SOC_DAPM_POST_PMD:
3150 tabla_codec_enable_micbias(w, kcontrol, event);
3151 tabla_codec_enable_ldo_h(w, kcontrol, event);
3152 break;
3153 }
3154 return 0;
3155}
3156
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003157static int tabla_codec_enable_dec(struct snd_soc_dapm_widget *w,
3158 struct snd_kcontrol *kcontrol, int event)
3159{
3160 struct snd_soc_codec *codec = w->codec;
Kiran Kandid8cf5212012-03-02 15:34:53 -08003161 unsigned int decimator;
3162 char *dec_name = NULL;
3163 char *widget_name = NULL;
3164 char *temp;
3165 int ret = 0;
3166 u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg;
3167 u8 dec_hpf_cut_of_freq;
Kuirong Wange9c8a222012-03-28 16:24:09 -07003168 int offset;
3169
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003170
3171 pr_debug("%s %d\n", __func__, event);
3172
Kiran Kandid8cf5212012-03-02 15:34:53 -08003173 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
3174 if (!widget_name)
3175 return -ENOMEM;
3176 temp = widget_name;
3177
3178 dec_name = strsep(&widget_name, " ");
3179 widget_name = temp;
3180 if (!dec_name) {
3181 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
3182 ret = -EINVAL;
3183 goto out;
3184 }
3185
3186 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
3187 if (ret < 0) {
3188 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
3189 ret = -EINVAL;
3190 goto out;
3191 }
3192
3193 pr_debug("%s(): widget = %s dec_name = %s decimator = %u\n", __func__,
3194 w->name, dec_name, decimator);
3195
Kuirong Wange9c8a222012-03-28 16:24:09 -07003196 if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003197 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B1_CTL;
Kuirong Wange9c8a222012-03-28 16:24:09 -07003198 offset = 0;
3199 } else if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003200 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B2_CTL;
Kuirong Wange9c8a222012-03-28 16:24:09 -07003201 offset = 8;
3202 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003203 pr_err("%s: Error, incorrect dec\n", __func__);
3204 return -EINVAL;
3205 }
3206
Kiran Kandid8cf5212012-03-02 15:34:53 -08003207 tx_vol_ctl_reg = TABLA_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator -1);
3208 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
3209
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003210 switch (event) {
3211 case SND_SOC_DAPM_PRE_PMU:
Kiran Kandid8cf5212012-03-02 15:34:53 -08003212
3213 // Enableable TX digital mute */
3214 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
3215
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003216 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift,
3217 1 << w->shift);
3218 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0);
Kiran Kandid8cf5212012-03-02 15:34:53 -08003219
3220 dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg);
3221
3222 dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4;
3223
3224 tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq =
3225 dec_hpf_cut_of_freq;
3226
3227 if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) {
3228
3229 /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */
3230 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
3231 CF_MIN_3DB_150HZ << 4);
3232 }
3233
3234 /* enable HPF */
3235 snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00);
3236
3237 break;
3238
3239 case SND_SOC_DAPM_POST_PMU:
3240
3241 /* Disable TX digital mute */
3242 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00);
3243
3244 if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq !=
3245 CF_MIN_3DB_150HZ) {
3246
3247 schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork,
3248 msecs_to_jiffies(300));
3249 }
Kuirong Wange9c8a222012-03-28 16:24:09 -07003250 /* apply the digital gain after the decimator is enabled*/
Damir Didjustoed406e22012-11-16 15:44:57 -08003251 if ((w->shift + offset) < ARRAY_SIZE(tx_digital_gain_reg))
Kuirong Wange9c8a222012-03-28 16:24:09 -07003252 snd_soc_write(codec,
3253 tx_digital_gain_reg[w->shift + offset],
3254 snd_soc_read(codec,
3255 tx_digital_gain_reg[w->shift + offset])
3256 );
3257
Kiran Kandid8cf5212012-03-02 15:34:53 -08003258 break;
3259
3260 case SND_SOC_DAPM_PRE_PMD:
3261
3262 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
3263 cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork);
3264 break;
3265
3266 case SND_SOC_DAPM_POST_PMD:
3267
3268 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08);
3269 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
3270 (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4);
3271
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003272 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003273 }
Kiran Kandid8cf5212012-03-02 15:34:53 -08003274out:
3275 kfree(widget_name);
3276 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003277}
3278
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003279static int tabla_codec_reset_interpolator(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003280 struct snd_kcontrol *kcontrol, int event)
3281{
3282 struct snd_soc_codec *codec = w->codec;
3283
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003284 pr_debug("%s %d %s\n", __func__, event, w->name);
3285
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003286 switch (event) {
3287 case SND_SOC_DAPM_PRE_PMU:
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003288 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
3289 1 << w->shift, 1 << w->shift);
3290 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
3291 1 << w->shift, 0x0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003292 break;
Kuirong Wange9c8a222012-03-28 16:24:09 -07003293 case SND_SOC_DAPM_POST_PMU:
3294 /* apply the digital gain after the interpolator is enabled*/
3295 if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
3296 snd_soc_write(codec,
3297 rx_digital_gain_reg[w->shift],
3298 snd_soc_read(codec,
3299 rx_digital_gain_reg[w->shift])
3300 );
3301 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003302 }
3303 return 0;
3304}
3305
Simmi Pateriya71d63872012-11-08 01:06:30 +05303306static void tabla_enable_ldo_h(struct snd_soc_codec *codec, u32 enable)
3307{
3308 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3309
3310 if (enable) {
3311 if (++tabla->ldo_h_count == 1)
3312 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1,
3313 0x80, 0x80);
3314 } else {
3315 if (--tabla->ldo_h_count == 0)
3316 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1,
3317 0x80, 0x00);
3318 }
3319}
3320
Bradley Rubin229c6a52011-07-12 16:18:48 -07003321static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
3322 struct snd_kcontrol *kcontrol, int event)
3323{
Simmi Pateriya71d63872012-11-08 01:06:30 +05303324 struct snd_soc_codec *codec = w->codec;
3325
3326 pr_debug("%s %d\n", __func__, event);
3327
Bradley Rubin229c6a52011-07-12 16:18:48 -07003328 switch (event) {
Simmi Pateriya71d63872012-11-08 01:06:30 +05303329 case SND_SOC_DAPM_PRE_PMU:
3330 tabla_enable_ldo_h(codec, 1);
3331 usleep_range(1000, 1000);
3332 break;
Bradley Rubin229c6a52011-07-12 16:18:48 -07003333 case SND_SOC_DAPM_POST_PMD:
Simmi Pateriya71d63872012-11-08 01:06:30 +05303334 tabla_enable_ldo_h(codec, 0);
Bradley Rubin229c6a52011-07-12 16:18:48 -07003335 usleep_range(1000, 1000);
3336 break;
3337 }
3338 return 0;
3339}
3340
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003341static int tabla_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
3342 struct snd_kcontrol *kcontrol, int event)
3343{
3344 struct snd_soc_codec *codec = w->codec;
3345
3346 pr_debug("%s %d\n", __func__, event);
3347
3348 switch (event) {
3349 case SND_SOC_DAPM_PRE_PMU:
3350 tabla_enable_rx_bias(codec, 1);
3351 break;
3352 case SND_SOC_DAPM_POST_PMD:
3353 tabla_enable_rx_bias(codec, 0);
3354 break;
3355 }
3356 return 0;
3357}
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003358static int tabla_hphr_dac_event(struct snd_soc_dapm_widget *w,
3359 struct snd_kcontrol *kcontrol, int event)
3360{
3361 struct snd_soc_codec *codec = w->codec;
3362
3363 pr_debug("%s %s %d\n", __func__, w->name, event);
3364
3365 switch (event) {
3366 case SND_SOC_DAPM_PRE_PMU:
3367 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
3368 break;
3369 case SND_SOC_DAPM_POST_PMD:
3370 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
3371 break;
3372 }
3373 return 0;
3374}
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003375
Joonwoo Park8b1f0982011-12-08 17:12:45 -08003376static void tabla_snd_soc_jack_report(struct tabla_priv *tabla,
3377 struct snd_soc_jack *jack, int status,
3378 int mask)
3379{
3380 /* XXX: wake_lock_timeout()? */
Joonwoo Park03324832012-03-19 19:36:16 -07003381 snd_soc_jack_report_no_dapm(jack, status, mask);
Joonwoo Park8b1f0982011-12-08 17:12:45 -08003382}
3383
Patrick Lai49efeac2011-11-03 11:01:12 -07003384static void hphocp_off_report(struct tabla_priv *tabla,
3385 u32 jack_status, int irq)
3386{
3387 struct snd_soc_codec *codec;
Joonwoo Park03324832012-03-19 19:36:16 -07003388 if (!tabla) {
3389 pr_err("%s: Bad tabla private data\n", __func__);
3390 return;
3391 }
Patrick Lai49efeac2011-11-03 11:01:12 -07003392
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003393 pr_debug("%s: clear ocp status %x\n", __func__, jack_status);
Joonwoo Park03324832012-03-19 19:36:16 -07003394 codec = tabla->codec;
3395 if (tabla->hph_status & jack_status) {
Patrick Lai49efeac2011-11-03 11:01:12 -07003396 tabla->hph_status &= ~jack_status;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003397 if (tabla->mbhc_cfg.headset_jack)
3398 tabla_snd_soc_jack_report(tabla,
3399 tabla->mbhc_cfg.headset_jack,
Joonwoo Park8b1f0982011-12-08 17:12:45 -08003400 tabla->hph_status,
3401 TABLA_JACK_MASK);
Joonwoo Park0976d012011-12-22 11:48:18 -08003402 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x00);
3403 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10);
Patrick Laic7cae882011-11-18 11:52:49 -08003404 /* reset retry counter as PA is turned off signifying
3405 * start of new OCP detection session
3406 */
Joonwoo Parkf6574c72012-10-10 17:29:57 -07003407 if (WCD9XXX_IRQ_HPH_PA_OCPL_FAULT)
Patrick Laic7cae882011-11-18 11:52:49 -08003408 tabla->hphlocp_cnt = 0;
3409 else
3410 tabla->hphrocp_cnt = 0;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303411 wcd9xxx_enable_irq(codec->control_data, irq);
Patrick Lai49efeac2011-11-03 11:01:12 -07003412 }
3413}
3414
3415static void hphlocp_off_report(struct work_struct *work)
3416{
3417 struct tabla_priv *tabla = container_of(work, struct tabla_priv,
3418 hphlocp_work);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07003419 hphocp_off_report(tabla, SND_JACK_OC_HPHL,
3420 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07003421}
3422
3423static void hphrocp_off_report(struct work_struct *work)
3424{
3425 struct tabla_priv *tabla = container_of(work, struct tabla_priv,
3426 hphrocp_work);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07003427 hphocp_off_report(tabla, SND_JACK_OC_HPHR,
3428 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07003429}
3430
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08003431static int tabla_codec_enable_anc(struct snd_soc_dapm_widget *w,
3432 struct snd_kcontrol *kcontrol, int event)
3433{
3434 struct snd_soc_codec *codec = w->codec;
3435 const char *filename;
3436 const struct firmware *fw;
3437 int i;
3438 int ret;
3439 int num_anc_slots;
3440 struct anc_header *anc_head;
3441 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3442 u32 anc_writes_size = 0;
3443 int anc_size_remaining;
3444 u32 *anc_ptr;
3445 u16 reg;
3446 u8 mask, val, old_val;
3447 u8 mbhc_micb_ctl_val;
3448
3449 pr_debug("%s: DAPM Event %d ANC func is %d\n",
3450 __func__, event, tabla->anc_func);
3451
3452 if (tabla->anc_func == 0)
3453 return 0;
3454
3455 switch (event) {
3456 case SND_SOC_DAPM_PRE_PMU:
3457 mbhc_micb_ctl_val = snd_soc_read(codec,
3458 tabla->mbhc_bias_regs.ctl_reg);
3459
3460 if (!(mbhc_micb_ctl_val & 0x80)) {
3461 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
3462 tabla_codec_switch_micbias(codec, 1);
3463 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
3464 }
3465
3466 filename = "wcd9310/wcd9310_anc.bin";
3467
3468 ret = request_firmware(&fw, filename, codec->dev);
3469 if (ret != 0) {
3470 dev_err(codec->dev, "Failed to acquire ANC data: %d\n",
3471 ret);
3472 return -ENODEV;
3473 }
3474
3475 if (fw->size < sizeof(struct anc_header)) {
3476 dev_err(codec->dev, "Not enough data\n");
3477 release_firmware(fw);
3478 return -ENOMEM;
3479 }
3480
3481 /* First number is the number of register writes */
3482 anc_head = (struct anc_header *)(fw->data);
3483 anc_ptr = (u32 *)((u32)fw->data + sizeof(struct anc_header));
3484 anc_size_remaining = fw->size - sizeof(struct anc_header);
3485 num_anc_slots = anc_head->num_anc_slots;
3486
3487 if (tabla->anc_slot >= num_anc_slots) {
3488 dev_err(codec->dev, "Invalid ANC slot selected\n");
3489 release_firmware(fw);
3490 return -EINVAL;
3491 }
3492
3493 for (i = 0; i < num_anc_slots; i++) {
3494
3495 if (anc_size_remaining < TABLA_PACKED_REG_SIZE) {
3496 dev_err(codec->dev, "Invalid register format\n");
3497 release_firmware(fw);
3498 return -EINVAL;
3499 }
3500 anc_writes_size = (u32)(*anc_ptr);
3501 anc_size_remaining -= sizeof(u32);
3502 anc_ptr += 1;
3503
3504 if (anc_writes_size * TABLA_PACKED_REG_SIZE
3505 > anc_size_remaining) {
3506 dev_err(codec->dev, "Invalid register format\n");
3507 release_firmware(fw);
3508 return -ENOMEM;
3509 }
3510
3511 if (tabla->anc_slot == i)
3512 break;
3513
3514 anc_size_remaining -= (anc_writes_size *
3515 TABLA_PACKED_REG_SIZE);
3516 anc_ptr += anc_writes_size;
3517 }
3518 if (i == num_anc_slots) {
3519 dev_err(codec->dev, "Selected ANC slot not present\n");
3520 release_firmware(fw);
3521 return -ENOMEM;
3522 }
3523
3524 for (i = 0; i < anc_writes_size; i++) {
3525 TABLA_CODEC_UNPACK_ENTRY(anc_ptr[i], reg,
3526 mask, val);
3527 old_val = snd_soc_read(codec, reg);
3528 snd_soc_write(codec, reg, (old_val & ~mask) |
3529 (val & mask));
3530 }
3531 usleep_range(10000, 10000);
3532 snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x30);
3533 msleep(30);
3534 release_firmware(fw);
3535 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
3536 /* if MBHC polling is active, set TX7_MBHC_EN bit 7 */
3537 if (tabla->mbhc_polling_active)
3538 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80,
3539 0x80);
3540 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
3541 break;
3542 case SND_SOC_DAPM_POST_PMD:
3543 /* schedule work is required because at the time HPH PA DAPM
3544 * event callback is called by DAPM framework, CODEC dapm mutex
3545 * would have been locked while snd_soc_jack_report also
3546 * attempts to acquire same lock.
3547 */
3548 if (w->shift == 5) {
3549 clear_bit(TABLA_HPHL_PA_OFF_ACK,
3550 &tabla->hph_pa_dac_state);
3551 clear_bit(TABLA_HPHL_DAC_OFF_ACK,
3552 &tabla->hph_pa_dac_state);
3553 if (tabla->hph_status & SND_JACK_OC_HPHL)
3554 schedule_work(&tabla->hphlocp_work);
3555 } else if (w->shift == 4) {
3556 clear_bit(TABLA_HPHR_PA_OFF_ACK,
3557 &tabla->hph_pa_dac_state);
3558 clear_bit(TABLA_HPHR_DAC_OFF_ACK,
3559 &tabla->hph_pa_dac_state);
3560 if (tabla->hph_status & SND_JACK_OC_HPHR)
3561 schedule_work(&tabla->hphrocp_work);
3562 }
3563
3564 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
3565 tabla_codec_switch_micbias(codec, 0);
3566 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
3567
3568 break;
3569 case SND_SOC_DAPM_PRE_PMD:
3570 snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00);
3571 msleep(40);
3572 /* unset TX7_MBHC_EN bit 7 */
3573 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00);
3574 snd_soc_update_bits(codec, TABLA_A_CDC_ANC1_CTL, 0x01, 0x00);
3575 snd_soc_update_bits(codec, TABLA_A_CDC_ANC2_CTL, 0x01, 0x00);
3576 msleep(20);
3577 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0x0F);
3578 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_CLK_EN_CTL, 0);
3579 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0xFF);
3580 break;
3581 }
3582 return 0;
3583}
3584
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003585static int tabla_hph_pa_event(struct snd_soc_dapm_widget *w,
3586 struct snd_kcontrol *kcontrol, int event)
3587{
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003588 struct snd_soc_codec *codec = w->codec;
3589 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3590 u8 mbhc_micb_ctl_val;
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003591 pr_debug("%s: event = %d\n", __func__, event);
3592
3593 switch (event) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003594 case SND_SOC_DAPM_PRE_PMU:
3595 mbhc_micb_ctl_val = snd_soc_read(codec,
3596 tabla->mbhc_bias_regs.ctl_reg);
3597
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003598 if (!(mbhc_micb_ctl_val & 0x80)) {
3599 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003600 tabla_codec_switch_micbias(codec, 1);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003601 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
3602 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003603 break;
3604
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003605 case SND_SOC_DAPM_POST_PMD:
Patrick Lai49efeac2011-11-03 11:01:12 -07003606 /* schedule work is required because at the time HPH PA DAPM
3607 * event callback is called by DAPM framework, CODEC dapm mutex
3608 * would have been locked while snd_soc_jack_report also
3609 * attempts to acquire same lock.
3610 */
Joonwoo Parka9444452011-12-08 18:48:27 -08003611 if (w->shift == 5) {
3612 clear_bit(TABLA_HPHL_PA_OFF_ACK,
3613 &tabla->hph_pa_dac_state);
3614 clear_bit(TABLA_HPHL_DAC_OFF_ACK,
3615 &tabla->hph_pa_dac_state);
3616 if (tabla->hph_status & SND_JACK_OC_HPHL)
3617 schedule_work(&tabla->hphlocp_work);
3618 } else if (w->shift == 4) {
3619 clear_bit(TABLA_HPHR_PA_OFF_ACK,
3620 &tabla->hph_pa_dac_state);
3621 clear_bit(TABLA_HPHR_DAC_OFF_ACK,
3622 &tabla->hph_pa_dac_state);
3623 if (tabla->hph_status & SND_JACK_OC_HPHR)
3624 schedule_work(&tabla->hphrocp_work);
3625 }
3626
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003627 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Joonwoo Park03324832012-03-19 19:36:16 -07003628 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003629 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003630
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003631 pr_debug("%s: sleep 10 ms after %s PA disable.\n", __func__,
3632 w->name);
3633 usleep_range(10000, 10000);
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003634 break;
3635 }
3636 return 0;
3637}
3638
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003639static void tabla_get_mbhc_micbias_regs(struct snd_soc_codec *codec,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003640 struct mbhc_micbias_regs *micbias_regs)
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003641{
3642 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003643 unsigned int cfilt;
3644
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003645 switch (tabla->mbhc_cfg.micbias) {
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003646 case TABLA_MICBIAS1:
3647 cfilt = tabla->pdata->micbias.bias1_cfilt_sel;
3648 micbias_regs->mbhc_reg = TABLA_A_MICB_1_MBHC;
3649 micbias_regs->int_rbias = TABLA_A_MICB_1_INT_RBIAS;
3650 micbias_regs->ctl_reg = TABLA_A_MICB_1_CTL;
3651 break;
3652 case TABLA_MICBIAS2:
3653 cfilt = tabla->pdata->micbias.bias2_cfilt_sel;
3654 micbias_regs->mbhc_reg = TABLA_A_MICB_2_MBHC;
3655 micbias_regs->int_rbias = TABLA_A_MICB_2_INT_RBIAS;
3656 micbias_regs->ctl_reg = TABLA_A_MICB_2_CTL;
3657 break;
3658 case TABLA_MICBIAS3:
3659 cfilt = tabla->pdata->micbias.bias3_cfilt_sel;
3660 micbias_regs->mbhc_reg = TABLA_A_MICB_3_MBHC;
3661 micbias_regs->int_rbias = TABLA_A_MICB_3_INT_RBIAS;
3662 micbias_regs->ctl_reg = TABLA_A_MICB_3_CTL;
3663 break;
3664 case TABLA_MICBIAS4:
3665 cfilt = tabla->pdata->micbias.bias4_cfilt_sel;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003666 micbias_regs->mbhc_reg = tabla->reg_addr.micb_4_mbhc;
3667 micbias_regs->int_rbias = tabla->reg_addr.micb_4_int_rbias;
3668 micbias_regs->ctl_reg = tabla->reg_addr.micb_4_ctl;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003669 break;
3670 default:
3671 /* Should never reach here */
3672 pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__);
Jordan Crouse239d8412011-11-23 11:47:02 -07003673 return;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003674 }
3675
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08003676 micbias_regs->cfilt_sel = cfilt;
3677
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003678 switch (cfilt) {
3679 case TABLA_CFILT1_SEL:
3680 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_1_VAL;
3681 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_1_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08003682 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt1_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003683 break;
3684 case TABLA_CFILT2_SEL:
3685 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_2_VAL;
3686 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_2_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08003687 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt2_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003688 break;
3689 case TABLA_CFILT3_SEL:
3690 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_3_VAL;
3691 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_3_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08003692 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt3_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003693 break;
3694 }
3695}
Santosh Mardie15e2302011-11-15 10:39:23 +05303696static const struct snd_soc_dapm_widget tabla_dapm_i2s_widgets[] = {
3697 SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", TABLA_A_CDC_CLK_RX_I2S_CTL,
3698 4, 0, NULL, 0),
3699 SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", TABLA_A_CDC_CLK_TX_I2S_CTL, 4,
3700 0, NULL, 0),
3701};
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003702
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003703static int tabla_lineout_dac_event(struct snd_soc_dapm_widget *w,
3704 struct snd_kcontrol *kcontrol, int event)
3705{
3706 struct snd_soc_codec *codec = w->codec;
3707
3708 pr_debug("%s %s %d\n", __func__, w->name, event);
3709
3710 switch (event) {
3711 case SND_SOC_DAPM_PRE_PMU:
3712 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
3713 break;
3714
3715 case SND_SOC_DAPM_POST_PMD:
3716 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
3717 break;
3718 }
3719 return 0;
3720}
3721
Damir Didjusto7c85d712012-08-16 21:22:29 -07003722static int tabla_ear_pa_event(struct snd_soc_dapm_widget *w,
3723 struct snd_kcontrol *kcontrol, int event)
3724{
3725 struct snd_soc_codec *codec = w->codec;
3726
3727 pr_debug("%s %d\n", __func__, event);
3728
3729 switch (event) {
3730 case SND_SOC_DAPM_PRE_PMU:
3731 snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x50, 0x50);
3732 break;
3733
3734 case SND_SOC_DAPM_PRE_PMD:
3735 snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x10, 0x00);
3736 snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x40, 0x00);
3737 break;
3738 }
3739 return 0;
3740}
3741
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003742static const struct snd_soc_dapm_widget tabla_1_x_dapm_widgets[] = {
Simmi Pateriya71d63872012-11-08 01:06:30 +05303743 SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", SND_SOC_NOPM, 0,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303744 0, tabla_codec_enable_micbias,
3745 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3746 SND_SOC_DAPM_POST_PMD),
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003747};
3748
3749static const struct snd_soc_dapm_widget tabla_2_higher_dapm_widgets[] = {
Simmi Pateriya71d63872012-11-08 01:06:30 +05303750 SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", SND_SOC_NOPM, 0,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303751 0, tabla_codec_enable_micbias,
3752 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3753 SND_SOC_DAPM_POST_PMD),
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003754};
3755
Santosh Mardie15e2302011-11-15 10:39:23 +05303756static const struct snd_soc_dapm_route audio_i2s_map[] = {
3757 {"RX_I2S_CLK", NULL, "CDC_CONN"},
3758 {"SLIM RX1", NULL, "RX_I2S_CLK"},
3759 {"SLIM RX2", NULL, "RX_I2S_CLK"},
3760 {"SLIM RX3", NULL, "RX_I2S_CLK"},
3761 {"SLIM RX4", NULL, "RX_I2S_CLK"},
3762
3763 {"SLIM TX7", NULL, "TX_I2S_CLK"},
3764 {"SLIM TX8", NULL, "TX_I2S_CLK"},
3765 {"SLIM TX9", NULL, "TX_I2S_CLK"},
3766 {"SLIM TX10", NULL, "TX_I2S_CLK"},
3767};
3768
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003769static const struct snd_soc_dapm_route audio_map[] = {
3770 /* SLIMBUS Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003771
Kuirong Wang906ac472012-07-09 12:54:44 -07003772 {"AIF1 CAP", NULL, "AIF1_CAP Mixer"},
3773 {"AIF2 CAP", NULL, "AIF2_CAP Mixer"},
3774 {"AIF3 CAP", NULL, "AIF3_CAP Mixer"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003775
Kuirong Wang906ac472012-07-09 12:54:44 -07003776 /* SLIM_MIXER("AIF1_CAP Mixer"),*/
3777 {"AIF1_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
3778 {"AIF1_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
3779 {"AIF1_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
3780 {"AIF1_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
3781 {"AIF1_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
3782 {"AIF1_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"},
3783 {"AIF1_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"},
3784 {"AIF1_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"},
3785 {"AIF1_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"},
3786 {"AIF1_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"},
3787 /* SLIM_MIXER("AIF2_CAP Mixer"),*/
3788 {"AIF2_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
3789 {"AIF2_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
3790 {"AIF2_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
3791 {"AIF2_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
3792 {"AIF2_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
3793 {"AIF2_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"},
3794 {"AIF2_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"},
3795 {"AIF2_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"},
3796 {"AIF2_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"},
3797 {"AIF2_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"},
3798 /* SLIM_MIXER("AIF3_CAP Mixer"),*/
3799 {"AIF3_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
3800 {"AIF3_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
3801 {"AIF3_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
3802 {"AIF3_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
3803 {"AIF3_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
3804 {"AIF3_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"},
3805 {"AIF3_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"},
3806 {"AIF3_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"},
3807 {"AIF3_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"},
3808 {"AIF3_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"},
3809
3810 {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003811 {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"},
3812
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003813 {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"},
Neema Shetty3fb1b802012-04-27 13:53:24 -07003814 {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"},
3815 {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"},
3816 {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"},
3817 {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"},
3818 {"SLIM TX3 MUX", "RMIX5", "RX5 MIX1"},
3819 {"SLIM TX3 MUX", "RMIX6", "RX6 MIX1"},
3820 {"SLIM TX3 MUX", "RMIX7", "RX7 MIX1"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003821
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003822 {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"},
3823
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003824 {"SLIM TX5 MUX", "DEC5", "DEC5 MUX"},
Neema Shetty3fb1b802012-04-27 13:53:24 -07003825 {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"},
3826 {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"},
3827 {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"},
3828 {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"},
3829 {"SLIM TX5 MUX", "RMIX5", "RX5 MIX1"},
3830 {"SLIM TX5 MUX", "RMIX6", "RX6 MIX1"},
3831 {"SLIM TX5 MUX", "RMIX7", "RX7 MIX1"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003832
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003833 {"SLIM TX6 MUX", "DEC6", "DEC6 MUX"},
3834
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003835 {"SLIM TX7 MUX", "DEC1", "DEC1 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07003836 {"SLIM TX7 MUX", "DEC2", "DEC2 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003837 {"SLIM TX7 MUX", "DEC3", "DEC3 MUX"},
3838 {"SLIM TX7 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003839 {"SLIM TX7 MUX", "DEC5", "DEC5 MUX"},
3840 {"SLIM TX7 MUX", "DEC6", "DEC6 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07003841 {"SLIM TX7 MUX", "DEC7", "DEC7 MUX"},
3842 {"SLIM TX7 MUX", "DEC8", "DEC8 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003843 {"SLIM TX7 MUX", "DEC9", "DEC9 MUX"},
3844 {"SLIM TX7 MUX", "DEC10", "DEC10 MUX"},
Neema Shetty3fb1b802012-04-27 13:53:24 -07003845 {"SLIM TX7 MUX", "RMIX1", "RX1 MIX1"},
3846 {"SLIM TX7 MUX", "RMIX2", "RX2 MIX1"},
3847 {"SLIM TX7 MUX", "RMIX3", "RX3 MIX1"},
3848 {"SLIM TX7 MUX", "RMIX4", "RX4 MIX1"},
3849 {"SLIM TX7 MUX", "RMIX5", "RX5 MIX1"},
3850 {"SLIM TX7 MUX", "RMIX6", "RX6 MIX1"},
3851 {"SLIM TX7 MUX", "RMIX7", "RX7 MIX1"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003852
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003853 {"SLIM TX8 MUX", "DEC1", "DEC1 MUX"},
3854 {"SLIM TX8 MUX", "DEC2", "DEC2 MUX"},
3855 {"SLIM TX8 MUX", "DEC3", "DEC3 MUX"},
Bhalchandra Gajare9ec83cd2011-09-23 17:25:07 -07003856 {"SLIM TX8 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003857 {"SLIM TX8 MUX", "DEC5", "DEC5 MUX"},
3858 {"SLIM TX8 MUX", "DEC6", "DEC6 MUX"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003859 {"SLIM TX8 MUX", "DEC7", "DEC7 MUX"},
3860 {"SLIM TX8 MUX", "DEC8", "DEC8 MUX"},
3861 {"SLIM TX8 MUX", "DEC9", "DEC9 MUX"},
3862 {"SLIM TX8 MUX", "DEC10", "DEC10 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003863
Kiran Kandi3426e512011-09-13 22:50:10 -07003864 {"SLIM TX9 MUX", "DEC1", "DEC1 MUX"},
3865 {"SLIM TX9 MUX", "DEC2", "DEC2 MUX"},
3866 {"SLIM TX9 MUX", "DEC3", "DEC3 MUX"},
3867 {"SLIM TX9 MUX", "DEC4", "DEC4 MUX"},
3868 {"SLIM TX9 MUX", "DEC5", "DEC5 MUX"},
3869 {"SLIM TX9 MUX", "DEC6", "DEC6 MUX"},
3870 {"SLIM TX9 MUX", "DEC7", "DEC7 MUX"},
3871 {"SLIM TX9 MUX", "DEC8", "DEC8 MUX"},
3872 {"SLIM TX9 MUX", "DEC9", "DEC9 MUX"},
3873 {"SLIM TX9 MUX", "DEC10", "DEC10 MUX"},
3874
Kiran Kandi3426e512011-09-13 22:50:10 -07003875 {"SLIM TX10 MUX", "DEC1", "DEC1 MUX"},
3876 {"SLIM TX10 MUX", "DEC2", "DEC2 MUX"},
3877 {"SLIM TX10 MUX", "DEC3", "DEC3 MUX"},
3878 {"SLIM TX10 MUX", "DEC4", "DEC4 MUX"},
3879 {"SLIM TX10 MUX", "DEC5", "DEC5 MUX"},
3880 {"SLIM TX10 MUX", "DEC6", "DEC6 MUX"},
3881 {"SLIM TX10 MUX", "DEC7", "DEC7 MUX"},
3882 {"SLIM TX10 MUX", "DEC8", "DEC8 MUX"},
3883 {"SLIM TX10 MUX", "DEC9", "DEC9 MUX"},
3884 {"SLIM TX10 MUX", "DEC10", "DEC10 MUX"},
3885
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003886 /* Earpiece (RX MIX1) */
3887 {"EAR", NULL, "EAR PA"},
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003888 {"EAR PA", NULL, "EAR_PA_MIXER"},
3889 {"EAR_PA_MIXER", NULL, "DAC1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003890 {"DAC1", NULL, "CP"},
3891
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003892 {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"},
3893 {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003894
3895 /* Headset (RX MIX1 and RX MIX2) */
3896 {"HEADPHONE", NULL, "HPHL"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003897 {"HEADPHONE", NULL, "HPHR"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003898
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003899 {"HPHL", NULL, "HPHL_PA_MIXER"},
3900 {"HPHL_PA_MIXER", NULL, "HPHL DAC"},
3901
3902 {"HPHR", NULL, "HPHR_PA_MIXER"},
3903 {"HPHR_PA_MIXER", NULL, "HPHR DAC"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003904
3905 {"HPHL DAC", NULL, "CP"},
3906 {"HPHR DAC", NULL, "CP"},
3907
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08003908 {"ANC HEADPHONE", NULL, "ANC HPHL"},
3909 {"ANC HEADPHONE", NULL, "ANC HPHR"},
3910
3911 {"ANC HPHL", NULL, "HPHL_PA_MIXER"},
3912 {"ANC HPHR", NULL, "HPHR_PA_MIXER"},
3913
Bradley Rubin229c6a52011-07-12 16:18:48 -07003914 {"ANC1 MUX", "ADC1", "ADC1"},
3915 {"ANC1 MUX", "ADC2", "ADC2"},
3916 {"ANC1 MUX", "ADC3", "ADC3"},
3917 {"ANC1 MUX", "ADC4", "ADC4"},
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08003918 {"ANC1 MUX", "DMIC1", "DMIC1"},
3919 {"ANC1 MUX", "DMIC2", "DMIC2"},
3920 {"ANC1 MUX", "DMIC3", "DMIC3"},
3921 {"ANC1 MUX", "DMIC4", "DMIC4"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003922 {"ANC2 MUX", "ADC1", "ADC1"},
3923 {"ANC2 MUX", "ADC2", "ADC2"},
3924 {"ANC2 MUX", "ADC3", "ADC3"},
3925 {"ANC2 MUX", "ADC4", "ADC4"},
3926
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08003927 {"ANC HPHR", NULL, "CDC_CONN"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003928 {"DAC1", "Switch", "RX1 CHAIN"},
3929 {"HPHL DAC", "Switch", "RX1 CHAIN"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003930 {"HPHR DAC", NULL, "RX2 CHAIN"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003931
Kiran Kandidb0a4b02011-08-23 09:32:09 -07003932 {"LINEOUT1", NULL, "LINEOUT1 PA"},
3933 {"LINEOUT2", NULL, "LINEOUT2 PA"},
3934 {"LINEOUT3", NULL, "LINEOUT3 PA"},
3935 {"LINEOUT4", NULL, "LINEOUT4 PA"},
3936 {"LINEOUT5", NULL, "LINEOUT5 PA"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003937
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003938 {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"},
3939 {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"},
3940 {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"},
3941 {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"},
3942 {"LINEOUT3 PA", NULL, "LINEOUT3_PA_MIXER"},
3943 {"LINEOUT3_PA_MIXER", NULL, "LINEOUT3 DAC"},
3944 {"LINEOUT4 PA", NULL, "LINEOUT4_PA_MIXER"},
3945 {"LINEOUT4_PA_MIXER", NULL, "LINEOUT4 DAC"},
3946 {"LINEOUT5 PA", NULL, "LINEOUT5_PA_MIXER"},
3947 {"LINEOUT5_PA_MIXER", NULL, "LINEOUT5 DAC"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003948
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003949 {"LINEOUT1 DAC", NULL, "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003950 {"LINEOUT5 DAC", NULL, "RX7 MIX1"},
3951
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003952 {"RX1 CHAIN", NULL, "RX1 MIX2"},
3953 {"RX2 CHAIN", NULL, "RX2 MIX2"},
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08003954 {"RX1 MIX2", NULL, "ANC1 MUX"},
3955 {"RX2 MIX2", NULL, "ANC2 MUX"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003956
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003957 {"CP", NULL, "RX_BIAS"},
3958 {"LINEOUT1 DAC", NULL, "RX_BIAS"},
3959 {"LINEOUT2 DAC", NULL, "RX_BIAS"},
3960 {"LINEOUT3 DAC", NULL, "RX_BIAS"},
3961 {"LINEOUT4 DAC", NULL, "RX_BIAS"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003962 {"LINEOUT5 DAC", NULL, "RX_BIAS"},
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003963
Kuirong Wang0f8ade32012-02-27 16:29:45 -08003964 {"RX1 MIX1", NULL, "COMP1_CLK"},
3965 {"RX2 MIX1", NULL, "COMP1_CLK"},
3966 {"RX3 MIX1", NULL, "COMP2_CLK"},
3967 {"RX5 MIX1", NULL, "COMP2_CLK"},
3968
3969
Bradley Rubin229c6a52011-07-12 16:18:48 -07003970 {"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
3971 {"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003972 {"RX1 MIX1", NULL, "RX1 MIX1 INP3"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003973 {"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
3974 {"RX2 MIX1", NULL, "RX2 MIX1 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003975 {"RX3 MIX1", NULL, "RX3 MIX1 INP1"},
3976 {"RX3 MIX1", NULL, "RX3 MIX1 INP2"},
3977 {"RX4 MIX1", NULL, "RX4 MIX1 INP1"},
3978 {"RX4 MIX1", NULL, "RX4 MIX1 INP2"},
3979 {"RX5 MIX1", NULL, "RX5 MIX1 INP1"},
3980 {"RX5 MIX1", NULL, "RX5 MIX1 INP2"},
3981 {"RX6 MIX1", NULL, "RX6 MIX1 INP1"},
3982 {"RX6 MIX1", NULL, "RX6 MIX1 INP2"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07003983 {"RX7 MIX1", NULL, "RX7 MIX1 INP1"},
3984 {"RX7 MIX1", NULL, "RX7 MIX1 INP2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003985 {"RX1 MIX2", NULL, "RX1 MIX1"},
3986 {"RX1 MIX2", NULL, "RX1 MIX2 INP1"},
3987 {"RX1 MIX2", NULL, "RX1 MIX2 INP2"},
3988 {"RX2 MIX2", NULL, "RX2 MIX1"},
3989 {"RX2 MIX2", NULL, "RX2 MIX2 INP1"},
3990 {"RX2 MIX2", NULL, "RX2 MIX2 INP2"},
3991 {"RX3 MIX2", NULL, "RX3 MIX1"},
3992 {"RX3 MIX2", NULL, "RX3 MIX2 INP1"},
3993 {"RX3 MIX2", NULL, "RX3 MIX2 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003994
Kuirong Wang906ac472012-07-09 12:54:44 -07003995 /* SLIM_MUX("AIF1_PB", "AIF1 PB"),*/
3996 {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"},
3997 {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"},
3998 {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"},
3999 {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"},
4000 {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"},
4001 {"SLIM RX6 MUX", "AIF1_PB", "AIF1 PB"},
4002 {"SLIM RX7 MUX", "AIF1_PB", "AIF1 PB"},
4003 /* SLIM_MUX("AIF2_PB", "AIF2 PB"),*/
4004 {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"},
4005 {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"},
4006 {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"},
4007 {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"},
4008 {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"},
4009 {"SLIM RX6 MUX", "AIF2_PB", "AIF2 PB"},
4010 {"SLIM RX7 MUX", "AIF2_PB", "AIF2 PB"},
4011 /* SLIM_MUX("AIF3_PB", "AIF3 PB"),*/
4012 {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"},
4013 {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"},
4014 {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"},
4015 {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"},
4016 {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"},
4017 {"SLIM RX6 MUX", "AIF3_PB", "AIF3 PB"},
4018 {"SLIM RX7 MUX", "AIF3_PB", "AIF3 PB"},
4019
4020 {"SLIM RX1", NULL, "SLIM RX1 MUX"},
4021 {"SLIM RX2", NULL, "SLIM RX2 MUX"},
4022 {"SLIM RX3", NULL, "SLIM RX3 MUX"},
4023 {"SLIM RX4", NULL, "SLIM RX4 MUX"},
4024 {"SLIM RX5", NULL, "SLIM RX5 MUX"},
4025 {"SLIM RX6", NULL, "SLIM RX6 MUX"},
4026 {"SLIM RX7", NULL, "SLIM RX7 MUX"},
4027
4028 /* Mixer control for output path */
Bradley Rubin229c6a52011-07-12 16:18:48 -07004029 {"RX1 MIX1 INP1", "RX1", "SLIM RX1"},
4030 {"RX1 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304031 {"RX1 MIX1 INP1", "RX3", "SLIM RX3"},
4032 {"RX1 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004033 {"RX1 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004034 {"RX1 MIX1 INP1", "RX6", "SLIM RX6"},
4035 {"RX1 MIX1 INP1", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004036 {"RX1 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004037 {"RX1 MIX1 INP1", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004038 {"RX1 MIX1 INP2", "RX1", "SLIM RX1"},
4039 {"RX1 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304040 {"RX1 MIX1 INP2", "RX3", "SLIM RX3"},
4041 {"RX1 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004042 {"RX1 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004043 {"RX1 MIX1 INP2", "RX6", "SLIM RX6"},
4044 {"RX1 MIX1 INP2", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004045 {"RX1 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004046 {"RX1 MIX1 INP2", "IIR2", "IIR2"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004047 {"RX1 MIX1 INP3", "RX1", "SLIM RX1"},
4048 {"RX1 MIX1 INP3", "RX2", "SLIM RX2"},
4049 {"RX1 MIX1 INP3", "RX3", "SLIM RX3"},
4050 {"RX1 MIX1 INP3", "RX4", "SLIM RX4"},
4051 {"RX1 MIX1 INP3", "RX5", "SLIM RX5"},
4052 {"RX1 MIX1 INP3", "RX6", "SLIM RX6"},
4053 {"RX1 MIX1 INP3", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004054 {"RX2 MIX1 INP1", "RX1", "SLIM RX1"},
4055 {"RX2 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304056 {"RX2 MIX1 INP1", "RX3", "SLIM RX3"},
4057 {"RX2 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004058 {"RX2 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004059 {"RX2 MIX1 INP1", "RX6", "SLIM RX6"},
4060 {"RX2 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004061 {"RX2 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004062 {"RX2 MIX1 INP1", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004063 {"RX2 MIX1 INP2", "RX1", "SLIM RX1"},
4064 {"RX2 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304065 {"RX2 MIX1 INP2", "RX3", "SLIM RX3"},
4066 {"RX2 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004067 {"RX2 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004068 {"RX2 MIX1 INP2", "RX6", "SLIM RX6"},
4069 {"RX2 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004070 {"RX2 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004071 {"RX2 MIX1 INP2", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004072 {"RX3 MIX1 INP1", "RX1", "SLIM RX1"},
4073 {"RX3 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304074 {"RX3 MIX1 INP1", "RX3", "SLIM RX3"},
4075 {"RX3 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004076 {"RX3 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004077 {"RX3 MIX1 INP1", "RX6", "SLIM RX6"},
4078 {"RX3 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004079 {"RX3 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004080 {"RX3 MIX1 INP1", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004081 {"RX3 MIX1 INP2", "RX1", "SLIM RX1"},
4082 {"RX3 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304083 {"RX3 MIX1 INP2", "RX3", "SLIM RX3"},
4084 {"RX3 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004085 {"RX3 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004086 {"RX3 MIX1 INP2", "RX6", "SLIM RX6"},
4087 {"RX3 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004088 {"RX3 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004089 {"RX3 MIX1 INP2", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004090 {"RX4 MIX1 INP1", "RX1", "SLIM RX1"},
4091 {"RX4 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304092 {"RX4 MIX1 INP1", "RX3", "SLIM RX3"},
4093 {"RX4 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004094 {"RX4 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004095 {"RX4 MIX1 INP1", "RX6", "SLIM RX6"},
4096 {"RX4 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004097 {"RX4 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004098 {"RX4 MIX1 INP1", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004099 {"RX4 MIX1 INP2", "RX1", "SLIM RX1"},
4100 {"RX4 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304101 {"RX4 MIX1 INP2", "RX3", "SLIM RX3"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004102 {"RX4 MIX1 INP2", "RX5", "SLIM RX5"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304103 {"RX4 MIX1 INP2", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004104 {"RX4 MIX1 INP2", "RX6", "SLIM RX6"},
4105 {"RX4 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004106 {"RX4 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004107 {"RX4 MIX1 INP2", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004108 {"RX5 MIX1 INP1", "RX1", "SLIM RX1"},
4109 {"RX5 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304110 {"RX5 MIX1 INP1", "RX3", "SLIM RX3"},
4111 {"RX5 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004112 {"RX5 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004113 {"RX5 MIX1 INP1", "RX6", "SLIM RX6"},
4114 {"RX5 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004115 {"RX5 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004116 {"RX5 MIX1 INP1", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004117 {"RX5 MIX1 INP2", "RX1", "SLIM RX1"},
4118 {"RX5 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304119 {"RX5 MIX1 INP2", "RX3", "SLIM RX3"},
4120 {"RX5 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004121 {"RX5 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004122 {"RX5 MIX1 INP2", "RX6", "SLIM RX6"},
4123 {"RX5 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004124 {"RX5 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004125 {"RX5 MIX1 INP2", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004126 {"RX6 MIX1 INP1", "RX1", "SLIM RX1"},
4127 {"RX6 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304128 {"RX6 MIX1 INP1", "RX3", "SLIM RX3"},
4129 {"RX6 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004130 {"RX6 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004131 {"RX6 MIX1 INP1", "RX6", "SLIM RX6"},
4132 {"RX6 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004133 {"RX6 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004134 {"RX6 MIX1 INP1", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004135 {"RX6 MIX1 INP2", "RX1", "SLIM RX1"},
4136 {"RX6 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304137 {"RX6 MIX1 INP2", "RX3", "SLIM RX3"},
4138 {"RX6 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004139 {"RX6 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004140 {"RX6 MIX1 INP2", "RX6", "SLIM RX6"},
4141 {"RX6 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004142 {"RX6 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004143 {"RX6 MIX1 INP2", "IIR2", "IIR2"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07004144 {"RX7 MIX1 INP1", "RX1", "SLIM RX1"},
4145 {"RX7 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304146 {"RX7 MIX1 INP1", "RX3", "SLIM RX3"},
4147 {"RX7 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004148 {"RX7 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004149 {"RX7 MIX1 INP1", "RX6", "SLIM RX6"},
4150 {"RX7 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004151 {"RX7 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004152 {"RX7 MIX1 INP1", "IIR2", "IIR2"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07004153 {"RX7 MIX1 INP2", "RX1", "SLIM RX1"},
4154 {"RX7 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304155 {"RX7 MIX1 INP2", "RX3", "SLIM RX3"},
4156 {"RX7 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004157 {"RX7 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004158 {"RX7 MIX1 INP2", "RX6", "SLIM RX6"},
4159 {"RX7 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004160 {"RX7 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004161 {"RX7 MIX1 INP2", "IIR2", "IIR2"},
4162
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004163 {"RX1 MIX2 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004164 {"RX1 MIX2 INP1", "IIR2", "IIR2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004165 {"RX1 MIX2 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004166 {"RX1 MIX2 INP2", "IIR2", "IIR2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004167 {"RX2 MIX2 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004168 {"RX2 MIX2 INP1", "IIR2", "IIR2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004169 {"RX2 MIX2 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004170 {"RX2 MIX2 INP2", "IIR2", "IIR2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004171 {"RX3 MIX2 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004172 {"RX3 MIX2 INP1", "IIR2", "IIR2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004173 {"RX3 MIX2 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004174 {"RX3 MIX2 INP2", "IIR2", "IIR2"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004175
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004176 /* Decimator Inputs */
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004177 {"DEC1 MUX", "DMIC1", "DMIC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07004178 {"DEC1 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004179 {"DEC1 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07004180 {"DEC2 MUX", "DMIC2", "DMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004181 {"DEC2 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004182 {"DEC2 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07004183 {"DEC3 MUX", "DMIC3", "DMIC3"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004184 {"DEC3 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004185 {"DEC3 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07004186 {"DEC4 MUX", "DMIC4", "DMIC4"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004187 {"DEC4 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004188 {"DEC4 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07004189 {"DEC5 MUX", "DMIC5", "DMIC5"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004190 {"DEC5 MUX", "ADC2", "ADC2"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004191 {"DEC5 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07004192 {"DEC6 MUX", "DMIC6", "DMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004193 {"DEC6 MUX", "ADC1", "ADC1"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004194 {"DEC6 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004195 {"DEC7 MUX", "DMIC1", "DMIC1"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004196 {"DEC7 MUX", "DMIC6", "DMIC6"},
4197 {"DEC7 MUX", "ADC1", "ADC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07004198 {"DEC7 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004199 {"DEC7 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004200 {"DEC8 MUX", "DMIC2", "DMIC2"},
4201 {"DEC8 MUX", "DMIC5", "DMIC5"},
4202 {"DEC8 MUX", "ADC2", "ADC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004203 {"DEC8 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004204 {"DEC8 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004205 {"DEC9 MUX", "DMIC4", "DMIC4"},
4206 {"DEC9 MUX", "DMIC5", "DMIC5"},
4207 {"DEC9 MUX", "ADC2", "ADC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004208 {"DEC9 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004209 {"DEC9 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004210 {"DEC10 MUX", "DMIC3", "DMIC3"},
4211 {"DEC10 MUX", "DMIC6", "DMIC6"},
4212 {"DEC10 MUX", "ADC1", "ADC1"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004213 {"DEC10 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004214 {"DEC10 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004215
4216 /* ADC Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004217 {"ADC1", NULL, "AMIC1"},
4218 {"ADC2", NULL, "AMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004219 {"ADC3", NULL, "AMIC3"},
4220 {"ADC4", NULL, "AMIC4"},
4221 {"ADC5", NULL, "AMIC5"},
4222 {"ADC6", NULL, "AMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004223
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08004224 /* AUX PGA Connections */
4225 {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4226 {"HPHL_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4227 {"HPHL_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4228 {"HPHL_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4229 {"HPHR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4230 {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4231 {"HPHR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4232 {"HPHR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4233 {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4234 {"LINEOUT1_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4235 {"LINEOUT1_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4236 {"LINEOUT1_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4237 {"LINEOUT2_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4238 {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4239 {"LINEOUT2_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4240 {"LINEOUT2_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4241 {"LINEOUT3_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4242 {"LINEOUT3_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4243 {"LINEOUT3_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4244 {"LINEOUT3_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4245 {"LINEOUT4_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4246 {"LINEOUT4_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4247 {"LINEOUT4_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4248 {"LINEOUT4_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4249 {"LINEOUT5_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4250 {"LINEOUT5_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4251 {"LINEOUT5_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4252 {"LINEOUT5_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4253 {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4254 {"EAR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4255 {"EAR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4256 {"EAR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4257 {"AUX_PGA_Left", NULL, "AMIC5"},
4258 {"AUX_PGA_Right", NULL, "AMIC6"},
4259
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004260 {"IIR1", NULL, "IIR1 INP1 MUX"},
Patrick Lai16261e82011-09-30 13:25:52 -07004261 {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"},
4262 {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"},
4263 {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"},
4264 {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"},
4265 {"IIR1 INP1 MUX", "DEC5", "DEC5 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004266 {"IIR1 INP1 MUX", "DEC6", "DEC6 MUX"},
Patrick Lai16261e82011-09-30 13:25:52 -07004267 {"IIR1 INP1 MUX", "DEC7", "DEC7 MUX"},
4268 {"IIR1 INP1 MUX", "DEC8", "DEC8 MUX"},
4269 {"IIR1 INP1 MUX", "DEC9", "DEC9 MUX"},
4270 {"IIR1 INP1 MUX", "DEC10", "DEC10 MUX"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004271
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004272 {"IIR2", NULL, "IIR2 INP1 MUX"},
4273 {"IIR2 INP1 MUX", "DEC1", "DEC1 MUX"},
4274 {"IIR2 INP1 MUX", "DEC2", "DEC2 MUX"},
4275 {"IIR2 INP1 MUX", "DEC3", "DEC3 MUX"},
4276 {"IIR2 INP1 MUX", "DEC4", "DEC4 MUX"},
4277 {"IIR2 INP1 MUX", "DEC5", "DEC5 MUX"},
4278 {"IIR2 INP1 MUX", "DEC6", "DEC6 MUX"},
4279 {"IIR2 INP1 MUX", "DEC7", "DEC7 MUX"},
4280 {"IIR2 INP1 MUX", "DEC8", "DEC8 MUX"},
4281 {"IIR2 INP1 MUX", "DEC9", "DEC9 MUX"},
4282 {"IIR2 INP1 MUX", "DEC10", "DEC10 MUX"},
4283
Bradley Rubin229c6a52011-07-12 16:18:48 -07004284 {"MIC BIAS1 Internal1", NULL, "LDO_H"},
4285 {"MIC BIAS1 Internal2", NULL, "LDO_H"},
4286 {"MIC BIAS1 External", NULL, "LDO_H"},
4287 {"MIC BIAS2 Internal1", NULL, "LDO_H"},
4288 {"MIC BIAS2 Internal2", NULL, "LDO_H"},
4289 {"MIC BIAS2 Internal3", NULL, "LDO_H"},
4290 {"MIC BIAS2 External", NULL, "LDO_H"},
4291 {"MIC BIAS3 Internal1", NULL, "LDO_H"},
4292 {"MIC BIAS3 Internal2", NULL, "LDO_H"},
4293 {"MIC BIAS3 External", NULL, "LDO_H"},
4294 {"MIC BIAS4 External", NULL, "LDO_H"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004295};
4296
Kiran Kandi8b3a8302011-09-27 16:13:28 -07004297static const struct snd_soc_dapm_route tabla_1_x_lineout_2_to_4_map[] = {
4298
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004299 {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07004300 {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"},
4301
4302 {"LINEOUT2 DAC", NULL, "RX4 DSM MUX"},
4303
4304 {"LINEOUT3 DAC", NULL, "RX5 MIX1"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004305 {"LINEOUT3 DAC GROUND", "Switch", "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07004306 {"LINEOUT3 DAC", NULL, "LINEOUT3 DAC GROUND"},
4307
4308 {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"},
4309 {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"},
4310
4311 {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"},
4312 {"LINEOUT4 DAC GROUND", "Switch", "RX4 DSM MUX"},
4313 {"LINEOUT4 DAC", NULL, "LINEOUT4 DAC GROUND"},
4314};
4315
Kiran Kandi7a9fd902011-11-14 13:51:45 -08004316
4317static const struct snd_soc_dapm_route tabla_2_x_lineout_2_to_4_map[] = {
4318
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004319 {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"},
Kiran Kandi7a9fd902011-11-14 13:51:45 -08004320 {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"},
4321
4322 {"LINEOUT3 DAC", NULL, "RX4 DSM MUX"},
4323
4324 {"LINEOUT2 DAC", NULL, "RX5 MIX1"},
4325
4326 {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"},
4327 {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"},
4328
4329 {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"},
4330};
4331
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004332static int tabla_readable(struct snd_soc_codec *ssc, unsigned int reg)
4333{
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08004334 int i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304335 struct wcd9xxx *tabla_core = dev_get_drvdata(ssc->dev->parent);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08004336
4337 if (TABLA_IS_1_X(tabla_core->version)) {
4338 for (i = 0; i < ARRAY_SIZE(tabla_1_reg_readable); i++) {
4339 if (tabla_1_reg_readable[i] == reg)
4340 return 1;
4341 }
4342 } else {
4343 for (i = 0; i < ARRAY_SIZE(tabla_2_reg_readable); i++) {
4344 if (tabla_2_reg_readable[i] == reg)
4345 return 1;
4346 }
4347 }
4348
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004349 return tabla_reg_readable[reg];
4350}
Kuirong Wange9c8a222012-03-28 16:24:09 -07004351static bool tabla_is_digital_gain_register(unsigned int reg)
4352{
4353 bool rtn = false;
4354 switch (reg) {
4355 case TABLA_A_CDC_RX1_VOL_CTL_B2_CTL:
4356 case TABLA_A_CDC_RX2_VOL_CTL_B2_CTL:
4357 case TABLA_A_CDC_RX3_VOL_CTL_B2_CTL:
4358 case TABLA_A_CDC_RX4_VOL_CTL_B2_CTL:
4359 case TABLA_A_CDC_RX5_VOL_CTL_B2_CTL:
4360 case TABLA_A_CDC_RX6_VOL_CTL_B2_CTL:
4361 case TABLA_A_CDC_RX7_VOL_CTL_B2_CTL:
4362 case TABLA_A_CDC_TX1_VOL_CTL_GAIN:
4363 case TABLA_A_CDC_TX2_VOL_CTL_GAIN:
4364 case TABLA_A_CDC_TX3_VOL_CTL_GAIN:
4365 case TABLA_A_CDC_TX4_VOL_CTL_GAIN:
4366 case TABLA_A_CDC_TX5_VOL_CTL_GAIN:
4367 case TABLA_A_CDC_TX6_VOL_CTL_GAIN:
4368 case TABLA_A_CDC_TX7_VOL_CTL_GAIN:
4369 case TABLA_A_CDC_TX8_VOL_CTL_GAIN:
4370 case TABLA_A_CDC_TX9_VOL_CTL_GAIN:
4371 case TABLA_A_CDC_TX10_VOL_CTL_GAIN:
4372 rtn = true;
4373 break;
4374 default:
4375 break;
4376 }
4377 return rtn;
4378}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004379static int tabla_volatile(struct snd_soc_codec *ssc, unsigned int reg)
4380{
4381 /* Registers lower than 0x100 are top level registers which can be
4382 * written by the Tabla core driver.
4383 */
4384
4385 if ((reg >= TABLA_A_CDC_MBHC_EN_CTL) || (reg < 0x100))
4386 return 1;
4387
Ben Romberger1f045a72011-11-04 10:14:57 -07004388 /* IIR Coeff registers are not cacheable */
4389 if ((reg >= TABLA_A_CDC_IIR1_COEF_B1_CTL) &&
4390 (reg <= TABLA_A_CDC_IIR2_COEF_B5_CTL))
4391 return 1;
4392
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08004393 /* ANC filter registers are not cacheable */
4394 if ((reg >= TABLA_A_CDC_ANC1_FILT1_B1_CTL) &&
4395 (reg <= TABLA_A_CDC_ANC1_FILT2_B3_CTL))
4396 return 1;
4397 if ((reg >= TABLA_A_CDC_ANC2_FILT1_B1_CTL) &&
4398 (reg <= TABLA_A_CDC_ANC2_FILT2_B3_CTL))
4399 return 1;
4400
Kuirong Wange9c8a222012-03-28 16:24:09 -07004401 /* Digital gain register is not cacheable so we have to write
4402 * the setting even it is the same
4403 */
4404 if (tabla_is_digital_gain_register(reg))
4405 return 1;
4406
Joonwoo Parkab2c5872012-05-03 15:16:02 -07004407 /* HPH status registers */
4408 if (reg == TABLA_A_RX_HPH_L_STATUS || reg == TABLA_A_RX_HPH_R_STATUS)
4409 return 1;
4410
Kuirong Wang678e4172012-06-26 15:35:22 -07004411 if (reg == TABLA_A_CDC_COMP1_SHUT_DOWN_STATUS ||
4412 reg == TABLA_A_CDC_COMP2_SHUT_DOWN_STATUS)
4413 return 1;
4414
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004415 return 0;
4416}
4417
4418#define TABLA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
4419static int tabla_write(struct snd_soc_codec *codec, unsigned int reg,
4420 unsigned int value)
4421{
4422 int ret;
Kuirong Wang906ac472012-07-09 12:54:44 -07004423
4424 if (reg == SND_SOC_NOPM)
4425 return 0;
4426
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004427 BUG_ON(reg > TABLA_MAX_REGISTER);
4428
4429 if (!tabla_volatile(codec, reg)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004430 ret = snd_soc_cache_write(codec, reg, value);
4431 if (ret != 0)
4432 dev_err(codec->dev, "Cache write to %x failed: %d\n",
4433 reg, ret);
4434 }
4435
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304436 return wcd9xxx_reg_write(codec->control_data, reg, value);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004437}
4438static unsigned int tabla_read(struct snd_soc_codec *codec,
4439 unsigned int reg)
4440{
4441 unsigned int val;
4442 int ret;
4443
Kuirong Wang906ac472012-07-09 12:54:44 -07004444 if (reg == SND_SOC_NOPM)
4445 return 0;
4446
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004447 BUG_ON(reg > TABLA_MAX_REGISTER);
4448
4449 if (!tabla_volatile(codec, reg) && tabla_readable(codec, reg) &&
4450 reg < codec->driver->reg_cache_size) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004451 ret = snd_soc_cache_read(codec, reg, &val);
4452 if (ret >= 0) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004453 return val;
4454 } else
4455 dev_err(codec->dev, "Cache read from %x failed: %d\n",
4456 reg, ret);
4457 }
4458
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304459 val = wcd9xxx_reg_read(codec->control_data, reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004460 return val;
4461}
4462
Joonwoo Parkcf473b42012-03-29 19:48:16 -07004463static s16 tabla_get_current_v_ins(struct tabla_priv *tabla, bool hu)
4464{
4465 s16 v_ins;
4466 if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) &&
4467 tabla->mbhc_micbias_switched)
4468 v_ins = hu ? (s16)tabla->mbhc_data.adj_v_ins_hu :
4469 (s16)tabla->mbhc_data.adj_v_ins_h;
4470 else
4471 v_ins = hu ? (s16)tabla->mbhc_data.v_ins_hu :
4472 (s16)tabla->mbhc_data.v_ins_h;
4473 return v_ins;
4474}
4475
4476static s16 tabla_get_current_v_hs_max(struct tabla_priv *tabla)
4477{
4478 s16 v_hs_max;
4479 struct tabla_mbhc_plug_type_cfg *plug_type;
4480
4481 plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
4482 if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) &&
4483 tabla->mbhc_micbias_switched)
4484 v_hs_max = tabla->mbhc_data.adj_v_hs_max;
4485 else
4486 v_hs_max = plug_type->v_hs_max;
4487 return v_hs_max;
4488}
4489
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07004490static void tabla_codec_calibrate_rel(struct snd_soc_codec *codec)
Bradley Rubincb1e2732011-06-23 16:49:20 -07004491{
Joonwoo Park0976d012011-12-22 11:48:18 -08004492 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004493
Joonwoo Park0976d012011-12-22 11:48:18 -08004494 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL,
4495 tabla->mbhc_data.v_b1_hu & 0xFF);
4496 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL,
4497 (tabla->mbhc_data.v_b1_hu >> 8) & 0xFF);
4498
4499 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL,
4500 tabla->mbhc_data.v_b1_h & 0xFF);
4501 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL,
4502 (tabla->mbhc_data.v_b1_h >> 8) & 0xFF);
4503
4504 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B9_CTL,
4505 tabla->mbhc_data.v_brh & 0xFF);
4506 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B10_CTL,
4507 (tabla->mbhc_data.v_brh >> 8) & 0xFF);
4508
4509 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B11_CTL,
4510 tabla->mbhc_data.v_brl & 0xFF);
4511 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B12_CTL,
4512 (tabla->mbhc_data.v_brl >> 8) & 0xFF);
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07004513}
4514
4515static void tabla_codec_calibrate_hs_polling(struct snd_soc_codec *codec)
4516{
4517 u8 *n_ready, *n_cic;
4518 struct tabla_mbhc_btn_detect_cfg *btn_det;
4519 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
4520 const s16 v_ins_hu = tabla_get_current_v_ins(tabla, true);
4521
4522 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
4523
4524 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
4525 v_ins_hu & 0xFF);
4526 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
4527 (v_ins_hu >> 8) & 0xFF);
4528
4529 tabla_codec_calibrate_rel(codec);
Joonwoo Park0976d012011-12-22 11:48:18 -08004530
Joonwoo Parkc0672392012-01-11 11:03:14 -08004531 n_ready = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_READY);
Joonwoo Park0976d012011-12-22 11:48:18 -08004532 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL,
Joonwoo Parkc0672392012-01-11 11:03:14 -08004533 n_ready[tabla_codec_mclk_index(tabla)]);
Joonwoo Park0976d012011-12-22 11:48:18 -08004534 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B2_CTL,
4535 tabla->mbhc_data.npoll);
4536 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B3_CTL,
4537 tabla->mbhc_data.nbounce_wait);
Joonwoo Park0976d012011-12-22 11:48:18 -08004538 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
Joonwoo Park107edf02012-01-11 11:42:24 -08004539 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL,
4540 n_cic[tabla_codec_mclk_index(tabla)]);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004541}
4542
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004543static int tabla_startup(struct snd_pcm_substream *substream,
4544 struct snd_soc_dai *dai)
4545{
Kuirong Wanga545e722012-02-06 19:12:54 -08004546 struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004547 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
4548 substream->name, substream->stream);
Kuirong Wanga545e722012-02-06 19:12:54 -08004549 if ((tabla_core != NULL) &&
4550 (tabla_core->dev != NULL) &&
4551 (tabla_core->dev->parent != NULL))
4552 pm_runtime_get_sync(tabla_core->dev->parent);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004553
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004554 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004555}
4556
Swaminathan Sathappanf95ece62012-08-23 16:01:50 -07004557static void tabla_shutdown(struct snd_pcm_substream *substream,
4558 struct snd_soc_dai *dai)
4559{
4560 struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent);
4561 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
4562 u32 active = 0;
4563
4564 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
4565 substream->name, substream->stream);
4566 if (tabla->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
4567 return;
4568
4569 if (dai->id <= NUM_CODEC_DAIS) {
Kuirong Wang906ac472012-07-09 12:54:44 -07004570 if (tabla->dai[dai->id].ch_mask) {
Swaminathan Sathappanf95ece62012-08-23 16:01:50 -07004571 active = 1;
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08004572 pr_debug("%s(): Codec DAI: chmask[%d] = 0x%lx\n",
Kuirong Wang906ac472012-07-09 12:54:44 -07004573 __func__, dai->id, tabla->dai[dai->id].ch_mask);
Swaminathan Sathappanf95ece62012-08-23 16:01:50 -07004574 }
4575 }
4576
4577 if ((tabla_core != NULL) &&
4578 (tabla_core->dev != NULL) &&
4579 (tabla_core->dev->parent != NULL) &&
4580 (active == 0)) {
4581 pm_runtime_mark_last_busy(tabla_core->dev->parent);
4582 pm_runtime_put(tabla_core->dev->parent);
4583 }
4584}
4585
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004586int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, bool dapm)
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004587{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004588 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
4589
Joonwoo Parkcf473b42012-03-29 19:48:16 -07004590 pr_debug("%s: mclk_enable = %u, dapm = %d\n", __func__, mclk_enable,
4591 dapm);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004592 if (dapm)
4593 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004594 if (mclk_enable) {
4595 tabla->mclk_enabled = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004596
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004597 if (tabla->mbhc_polling_active) {
Bradley Rubincb1e2732011-06-23 16:49:20 -07004598 tabla_codec_pause_hs_polling(codec);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004599 tabla_codec_disable_clock_block(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004600 tabla_codec_enable_bandgap(codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004601 TABLA_BANDGAP_AUDIO_MODE);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004602 tabla_codec_enable_clock_block(codec, 0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004603 tabla_codec_calibrate_hs_polling(codec);
4604 tabla_codec_start_hs_polling(codec);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05304605 } else {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004606 tabla_codec_disable_clock_block(codec);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05304607 tabla_codec_enable_bandgap(codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004608 TABLA_BANDGAP_AUDIO_MODE);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05304609 tabla_codec_enable_clock_block(codec, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004610 }
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004611 } else {
4612
4613 if (!tabla->mclk_enabled) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004614 if (dapm)
4615 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004616 pr_err("Error, MCLK already diabled\n");
4617 return -EINVAL;
4618 }
4619 tabla->mclk_enabled = false;
4620
4621 if (tabla->mbhc_polling_active) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004622 tabla_codec_pause_hs_polling(codec);
4623 tabla_codec_disable_clock_block(codec);
4624 tabla_codec_enable_bandgap(codec,
Simmi Pateriya71d63872012-11-08 01:06:30 +05304625 TABLA_BANDGAP_MBHC_MODE);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004626 tabla_enable_rx_bias(codec, 1);
4627 tabla_codec_enable_clock_block(codec, 1);
4628 tabla_codec_calibrate_hs_polling(codec);
4629 tabla_codec_start_hs_polling(codec);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004630 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1,
4631 0x05, 0x01);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05304632 } else {
4633 tabla_codec_disable_clock_block(codec);
4634 tabla_codec_enable_bandgap(codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004635 TABLA_BANDGAP_OFF);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004636 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004637 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004638 if (dapm)
4639 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004640 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004641}
4642
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004643static int tabla_set_dai_sysclk(struct snd_soc_dai *dai,
4644 int clk_id, unsigned int freq, int dir)
4645{
4646 pr_debug("%s\n", __func__);
4647 return 0;
4648}
4649
4650static int tabla_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
4651{
Santosh Mardie15e2302011-11-15 10:39:23 +05304652 u8 val = 0;
4653 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
4654
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004655 pr_debug("%s\n", __func__);
Santosh Mardie15e2302011-11-15 10:39:23 +05304656 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
4657 case SND_SOC_DAIFMT_CBS_CFS:
4658 /* CPU is master */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304659 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004660 if (dai->id == AIF1_CAP)
Santosh Mardie15e2302011-11-15 10:39:23 +05304661 snd_soc_update_bits(dai->codec,
4662 TABLA_A_CDC_CLK_TX_I2S_CTL,
4663 TABLA_I2S_MASTER_MODE_MASK, 0);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004664 else if (dai->id == AIF1_PB)
Santosh Mardie15e2302011-11-15 10:39:23 +05304665 snd_soc_update_bits(dai->codec,
4666 TABLA_A_CDC_CLK_RX_I2S_CTL,
4667 TABLA_I2S_MASTER_MODE_MASK, 0);
4668 }
4669 break;
4670 case SND_SOC_DAIFMT_CBM_CFM:
4671 /* CPU is slave */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304672 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05304673 val = TABLA_I2S_MASTER_MODE_MASK;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004674 if (dai->id == AIF1_CAP)
Santosh Mardie15e2302011-11-15 10:39:23 +05304675 snd_soc_update_bits(dai->codec,
4676 TABLA_A_CDC_CLK_TX_I2S_CTL, val, val);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004677 else if (dai->id == AIF1_PB)
Santosh Mardie15e2302011-11-15 10:39:23 +05304678 snd_soc_update_bits(dai->codec,
4679 TABLA_A_CDC_CLK_RX_I2S_CTL, val, val);
4680 }
4681 break;
4682 default:
4683 return -EINVAL;
4684 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004685 return 0;
4686}
4687
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004688static int tabla_set_channel_map(struct snd_soc_dai *dai,
4689 unsigned int tx_num, unsigned int *tx_slot,
4690 unsigned int rx_num, unsigned int *rx_slot)
4691
4692{
4693 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
Kuirong Wang906ac472012-07-09 12:54:44 -07004694 struct wcd9xxx *core = dev_get_drvdata(dai->codec->dev->parent);
4695
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004696 if (!tx_slot && !rx_slot) {
4697 pr_err("%s: Invalid\n", __func__);
4698 return -EINVAL;
4699 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004700 pr_debug("%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n"
4701 "tabla->intf_type %d\n",
4702 __func__, dai->name, dai->id, tx_num, rx_num,
4703 tabla->intf_type);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004704
Kuirong Wang906ac472012-07-09 12:54:44 -07004705 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
4706 wcd9xxx_init_slimslave(core, core->slim->laddr,
4707 tx_num, tx_slot, rx_num, rx_slot);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004708 return 0;
4709}
4710
4711static int tabla_get_channel_map(struct snd_soc_dai *dai,
4712 unsigned int *tx_num, unsigned int *tx_slot,
4713 unsigned int *rx_num, unsigned int *rx_slot)
4714
4715{
Kuirong Wang906ac472012-07-09 12:54:44 -07004716 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(dai->codec);
4717 u32 i = 0;
4718 struct wcd9xxx_ch *ch;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004719
Kuirong Wang906ac472012-07-09 12:54:44 -07004720 switch (dai->id) {
4721 case AIF1_PB:
4722 case AIF2_PB:
4723 case AIF3_PB:
4724 if (!rx_slot || !rx_num) {
4725 pr_err("%s: Invalid rx_slot %d or rx_num %d\n",
4726 __func__, (u32) rx_slot, (u32) rx_num);
4727 return -EINVAL;
4728 }
4729 list_for_each_entry(ch, &tabla_p->dai[dai->id].wcd9xxx_ch_list,
4730 list) {
4731 rx_slot[i++] = ch->ch_num;
4732 }
4733 *rx_num = i;
4734 break;
4735 case AIF1_CAP:
4736 case AIF2_CAP:
4737 case AIF3_CAP:
4738 if (!tx_slot || !tx_num) {
4739 pr_err("%s: Invalid tx_slot %d or tx_num %d\n",
4740 __func__, (u32) tx_slot, (u32) tx_num);
4741 return -EINVAL;
4742 }
4743 list_for_each_entry(ch, &tabla_p->dai[dai->id].wcd9xxx_ch_list,
4744 list) {
4745 tx_slot[i++] = ch->ch_num;
4746 }
4747 *tx_num = i;
4748 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004749
Kuirong Wang906ac472012-07-09 12:54:44 -07004750 default:
4751 pr_err("%s: Invalid DAI ID %x\n", __func__, dai->id);
4752 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004753 }
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004754 return 0;
4755}
4756
Kiran Kandi93923902012-06-20 17:00:25 -07004757
Kiran Kandi93923902012-06-20 17:00:25 -07004758static int tabla_set_interpolator_rate(struct snd_soc_dai *dai,
Kuirong Wang906ac472012-07-09 12:54:44 -07004759 u8 rx_fs_rate_reg_val,
4760 u32 compander_fs,
4761 u32 sample_rate)
Kiran Kandi93923902012-06-20 17:00:25 -07004762{
Kuirong Wang906ac472012-07-09 12:54:44 -07004763 u32 j;
Kiran Kandi93923902012-06-20 17:00:25 -07004764 u8 rx_mix1_inp;
4765 u16 rx_mix_1_reg_1, rx_mix_1_reg_2;
4766 u16 rx_fs_reg;
4767 u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val;
4768 struct snd_soc_codec *codec = dai->codec;
Kuirong Wang906ac472012-07-09 12:54:44 -07004769 struct wcd9xxx_ch *ch;
Kiran Kandi93923902012-06-20 17:00:25 -07004770 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Kiran Kandi93923902012-06-20 17:00:25 -07004771
Kuirong Wang906ac472012-07-09 12:54:44 -07004772 list_for_each_entry(ch, &tabla->dai[dai->id].wcd9xxx_ch_list, list) {
Kiran Kandi93923902012-06-20 17:00:25 -07004773
Kuirong Wang906ac472012-07-09 12:54:44 -07004774 rx_mix1_inp = ch->port - RX_MIX1_INP_SEL_RX1;
Kiran Kandi93923902012-06-20 17:00:25 -07004775
Kuirong Wang906ac472012-07-09 12:54:44 -07004776 if ((rx_mix1_inp < RX_MIX1_INP_SEL_RX1) ||
4777 (rx_mix1_inp > RX_MIX1_INP_SEL_RX7)) {
4778 pr_err("%s: Invalid TABLA_RX%u port. Dai ID is %d\n",
4779 __func__, rx_mix1_inp - 5 , dai->id);
Kiran Kandi93923902012-06-20 17:00:25 -07004780 return -EINVAL;
4781 }
4782
4783 rx_mix_1_reg_1 = TABLA_A_CDC_CONN_RX1_B1_CTL;
4784
4785 for (j = 0; j < NUM_INTERPOLATORS; j++) {
Kiran Kandi93923902012-06-20 17:00:25 -07004786 rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1;
4787
4788 rx_mix_1_reg_1_val = snd_soc_read(codec,
Kuirong Wang906ac472012-07-09 12:54:44 -07004789 rx_mix_1_reg_1);
Kiran Kandi93923902012-06-20 17:00:25 -07004790 rx_mix_1_reg_2_val = snd_soc_read(codec,
Kuirong Wang906ac472012-07-09 12:54:44 -07004791 rx_mix_1_reg_2);
Kiran Kandi93923902012-06-20 17:00:25 -07004792
4793 if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) ||
Kuirong Wang906ac472012-07-09 12:54:44 -07004794 (((rx_mix_1_reg_1_val >> 4) & 0x0F) == rx_mix1_inp) ||
4795 ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) {
Kiran Kandi93923902012-06-20 17:00:25 -07004796
4797 rx_fs_reg = TABLA_A_CDC_RX1_B5_CTL + 8 * j;
4798
Kuirong Wang906ac472012-07-09 12:54:44 -07004799 pr_debug("%s: AIF_PB DAI(%d) connected to RX%u\n",
4800 __func__, dai->id, j + 1);
Kiran Kandi93923902012-06-20 17:00:25 -07004801
4802 pr_debug("%s: set RX%u sample rate to %u\n",
4803 __func__, j + 1, sample_rate);
4804
4805 snd_soc_update_bits(codec, rx_fs_reg,
Kuirong Wang906ac472012-07-09 12:54:44 -07004806 0xE0, rx_fs_rate_reg_val);
Kiran Kandi93923902012-06-20 17:00:25 -07004807
4808 if (comp_rx_path[j] < COMPANDER_MAX)
4809 tabla->comp_fs[comp_rx_path[j]]
4810 = compander_fs;
4811 }
4812 if (j <= 2)
4813 rx_mix_1_reg_1 += 3;
4814 else
4815 rx_mix_1_reg_1 += 2;
4816 }
4817 }
4818 return 0;
4819}
4820
4821static int tabla_set_decimator_rate(struct snd_soc_dai *dai,
Kuirong Wang906ac472012-07-09 12:54:44 -07004822 u8 tx_fs_rate_reg_val,
4823 u32 sample_rate)
Kiran Kandi93923902012-06-20 17:00:25 -07004824{
4825 struct snd_soc_codec *codec = dai->codec;
Kuirong Wang906ac472012-07-09 12:54:44 -07004826 struct wcd9xxx_ch *ch;
4827 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
4828 u32 tx_port;
Kiran Kandi93923902012-06-20 17:00:25 -07004829 u16 tx_port_reg, tx_fs_reg;
4830 u8 tx_port_reg_val;
4831 s8 decimator;
4832
Kuirong Wang906ac472012-07-09 12:54:44 -07004833 list_for_each_entry(ch, &tabla->dai[dai->id].wcd9xxx_ch_list, list) {
Kiran Kandi93923902012-06-20 17:00:25 -07004834
Kuirong Wang906ac472012-07-09 12:54:44 -07004835 tx_port = ch->port + 1;
4836 pr_debug("%s: dai->id = %d, tx_port = %d",
4837 __func__, dai->id, tx_port);
Kiran Kandi93923902012-06-20 17:00:25 -07004838
4839 if ((tx_port < 1) || (tx_port > NUM_DECIMATORS)) {
Kuirong Wang906ac472012-07-09 12:54:44 -07004840 pr_err("%s: Invalid SLIM TX%u port. DAI ID is %d\n",
4841 __func__, tx_port, dai->id);
Kiran Kandi93923902012-06-20 17:00:25 -07004842 return -EINVAL;
4843 }
4844
4845 tx_port_reg = TABLA_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1);
4846 tx_port_reg_val = snd_soc_read(codec, tx_port_reg);
4847
4848 decimator = 0;
4849
4850 if ((tx_port >= 1) && (tx_port <= 6)) {
4851
4852 tx_port_reg_val = tx_port_reg_val & 0x0F;
4853 if (tx_port_reg_val == 0x8)
4854 decimator = tx_port;
4855
4856 } else if ((tx_port >= 7) && (tx_port <= NUM_DECIMATORS)) {
4857
4858 tx_port_reg_val = tx_port_reg_val & 0x1F;
4859
4860 if ((tx_port_reg_val >= 0x8) &&
4861 (tx_port_reg_val <= 0x11)) {
4862
4863 decimator = (tx_port_reg_val - 0x8) + 1;
4864 }
4865 }
4866
4867 if (decimator) { /* SLIM_TX port has a DEC as input */
4868
4869 tx_fs_reg = TABLA_A_CDC_TX1_CLK_FS_CTL +
Kuirong Wang906ac472012-07-09 12:54:44 -07004870 8 * (decimator - 1);
Kiran Kandi93923902012-06-20 17:00:25 -07004871
4872 pr_debug("%s: set DEC%u (-> SLIM_TX%u) rate to %u\n",
4873 __func__, decimator, tx_port, sample_rate);
4874
4875 snd_soc_update_bits(codec, tx_fs_reg, 0x07,
Kuirong Wang906ac472012-07-09 12:54:44 -07004876 tx_fs_rate_reg_val);
Kiran Kandi93923902012-06-20 17:00:25 -07004877
4878 } else {
4879 if ((tx_port_reg_val >= 0x1) &&
Kuirong Wang906ac472012-07-09 12:54:44 -07004880 (tx_port_reg_val <= 0x7)) {
Kiran Kandi93923902012-06-20 17:00:25 -07004881
4882 pr_debug("%s: RMIX%u going to SLIM TX%u\n",
4883 __func__, tx_port_reg_val, tx_port);
4884
4885 } else if ((tx_port_reg_val >= 0x8) &&
Kuirong Wang906ac472012-07-09 12:54:44 -07004886 (tx_port_reg_val <= 0x11)) {
Kiran Kandi93923902012-06-20 17:00:25 -07004887
4888 pr_err("%s: ERROR: Should not be here\n",
Kuirong Wang906ac472012-07-09 12:54:44 -07004889 __func__);
4890 pr_err("%s: ERROR: DEC connected to SLIM TX%u\n",
4891 __func__, tx_port);
Kiran Kandi93923902012-06-20 17:00:25 -07004892 return -EINVAL;
4893
4894 } else if (tx_port_reg_val == 0) {
4895 pr_debug("%s: no signal to SLIM TX%u\n",
Kuirong Wang906ac472012-07-09 12:54:44 -07004896 __func__, tx_port);
Kiran Kandi93923902012-06-20 17:00:25 -07004897 } else {
Kuirong Wang906ac472012-07-09 12:54:44 -07004898 pr_err("%s: ERROR: wrong signal to SLIM TX%u\n",
4899 __func__, tx_port);
4900 pr_err("%s: ERROR: wrong signal = %u\n",
4901 __func__, tx_port_reg_val);
Kiran Kandi93923902012-06-20 17:00:25 -07004902 return -EINVAL;
4903 }
4904 }
4905 }
4906 return 0;
4907}
4908
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004909static int tabla_hw_params(struct snd_pcm_substream *substream,
Kuirong Wang906ac472012-07-09 12:54:44 -07004910 struct snd_pcm_hw_params *params,
4911 struct snd_soc_dai *dai)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004912{
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004913 struct snd_soc_codec *codec = dai->codec;
Santosh Mardie15e2302011-11-15 10:39:23 +05304914 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
Kiran Kandi93923902012-06-20 17:00:25 -07004915 u8 tx_fs_rate_reg_val, rx_fs_rate_reg_val;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004916 u32 compander_fs;
Kiran Kandi93923902012-06-20 17:00:25 -07004917 int ret;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004918
Kiran Kandia9fffe92012-05-20 23:42:30 -07004919 pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004920 dai->name, dai->id, params_rate(params),
4921 params_channels(params));
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004922
4923 switch (params_rate(params)) {
4924 case 8000:
Kiran Kandi93923902012-06-20 17:00:25 -07004925 tx_fs_rate_reg_val = 0x00;
4926 rx_fs_rate_reg_val = 0x00;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004927 compander_fs = COMPANDER_FS_8KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004928 break;
4929 case 16000:
Kiran Kandi93923902012-06-20 17:00:25 -07004930 tx_fs_rate_reg_val = 0x01;
4931 rx_fs_rate_reg_val = 0x20;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004932 compander_fs = COMPANDER_FS_16KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004933 break;
4934 case 32000:
Kiran Kandi93923902012-06-20 17:00:25 -07004935 tx_fs_rate_reg_val = 0x02;
4936 rx_fs_rate_reg_val = 0x40;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004937 compander_fs = COMPANDER_FS_32KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004938 break;
4939 case 48000:
Kiran Kandi93923902012-06-20 17:00:25 -07004940 tx_fs_rate_reg_val = 0x03;
4941 rx_fs_rate_reg_val = 0x60;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004942 compander_fs = COMPANDER_FS_48KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004943 break;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004944 case 96000:
Kiran Kandi93923902012-06-20 17:00:25 -07004945 tx_fs_rate_reg_val = 0x04;
4946 rx_fs_rate_reg_val = 0x80;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004947 compander_fs = COMPANDER_FS_96KHZ;
4948 break;
4949 case 192000:
Kiran Kandi93923902012-06-20 17:00:25 -07004950 tx_fs_rate_reg_val = 0x05;
4951 rx_fs_rate_reg_val = 0xA0;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004952 compander_fs = COMPANDER_FS_192KHZ;
4953 break;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004954 default:
4955 pr_err("%s: Invalid sampling rate %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004956 params_rate(params));
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004957 return -EINVAL;
4958 }
4959
Kiran Kandi93923902012-06-20 17:00:25 -07004960 switch (substream->stream) {
4961 case SNDRV_PCM_STREAM_CAPTURE:
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004962
Kiran Kandi93923902012-06-20 17:00:25 -07004963 ret = tabla_set_decimator_rate(dai, tx_fs_rate_reg_val,
Kuirong Wang906ac472012-07-09 12:54:44 -07004964 params_rate(params));
Kiran Kandi93923902012-06-20 17:00:25 -07004965 if (ret < 0) {
4966 pr_err("%s: set decimator rate failed %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004967 ret);
Kiran Kandi93923902012-06-20 17:00:25 -07004968 return ret;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004969 }
Kiran Kandi93923902012-06-20 17:00:25 -07004970
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304971 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05304972 switch (params_format(params)) {
4973 case SNDRV_PCM_FORMAT_S16_LE:
4974 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004975 TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x20);
Santosh Mardie15e2302011-11-15 10:39:23 +05304976 break;
4977 case SNDRV_PCM_FORMAT_S32_LE:
4978 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004979 TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x00);
Santosh Mardie15e2302011-11-15 10:39:23 +05304980 break;
4981 default:
Kuirong Wang906ac472012-07-09 12:54:44 -07004982 pr_err("%s: Invalid format %d\n", __func__,
4983 params_format(params));
Kiran Kandi93923902012-06-20 17:00:25 -07004984 return -EINVAL;
Santosh Mardie15e2302011-11-15 10:39:23 +05304985 }
4986 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_TX_I2S_CTL,
Kuirong Wang906ac472012-07-09 12:54:44 -07004987 0x07, tx_fs_rate_reg_val);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004988 } else {
Kuirong Wang906ac472012-07-09 12:54:44 -07004989 switch (params_format(params)) {
4990 case SNDRV_PCM_FORMAT_S16_LE:
4991 tabla->dai[dai->id].bit_width = 16;
4992 break;
4993 default:
4994 pr_err("%s: Invalid TX format %d\n", __func__,
4995 params_format(params));
4996 return -EINVAL;
4997 }
4998 tabla->dai[dai->id].rate = params_rate(params);
Santosh Mardie15e2302011-11-15 10:39:23 +05304999 }
Kiran Kandi93923902012-06-20 17:00:25 -07005000 break;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07005001
Kiran Kandi93923902012-06-20 17:00:25 -07005002 case SNDRV_PCM_STREAM_PLAYBACK:
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07005003
Kiran Kandi93923902012-06-20 17:00:25 -07005004 ret = tabla_set_interpolator_rate(dai, rx_fs_rate_reg_val,
Kuirong Wang906ac472012-07-09 12:54:44 -07005005 compander_fs,
5006 params_rate(params));
Kiran Kandi93923902012-06-20 17:00:25 -07005007 if (ret < 0) {
5008 pr_err("%s: set decimator rate failed %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07005009 ret);
Kiran Kandi93923902012-06-20 17:00:25 -07005010 return ret;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07005011 }
Kiran Kandi93923902012-06-20 17:00:25 -07005012
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305013 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05305014 switch (params_format(params)) {
5015 case SNDRV_PCM_FORMAT_S16_LE:
5016 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07005017 TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x20);
Santosh Mardie15e2302011-11-15 10:39:23 +05305018 break;
5019 case SNDRV_PCM_FORMAT_S32_LE:
5020 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07005021 TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x00);
Santosh Mardie15e2302011-11-15 10:39:23 +05305022 break;
5023 default:
Kuirong Wang906ac472012-07-09 12:54:44 -07005024 pr_err("%s: Invalid RX format %d\n", __func__,
5025 params_format(params));
Kiran Kandi93923902012-06-20 17:00:25 -07005026 return -EINVAL;
Santosh Mardie15e2302011-11-15 10:39:23 +05305027 }
5028 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_I2S_CTL,
Kiran Kandi93923902012-06-20 17:00:25 -07005029 0x03, (rx_fs_rate_reg_val >> 0x05));
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005030 } else {
Kuirong Wang906ac472012-07-09 12:54:44 -07005031 switch (params_format(params)) {
5032 case SNDRV_PCM_FORMAT_S16_LE:
5033 tabla->dai[dai->id].bit_width = 16;
5034 break;
5035 default:
5036 pr_err("%s: Invalid format %d\n", __func__,
5037 params_format(params));
5038 return -EINVAL;
5039 }
5040 tabla->dai[dai->id].rate = params_rate(params);
Santosh Mardie15e2302011-11-15 10:39:23 +05305041 }
Kiran Kandi93923902012-06-20 17:00:25 -07005042 break;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07005043
Kiran Kandi93923902012-06-20 17:00:25 -07005044 default:
5045 pr_err("%s: Invalid stream type %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07005046 substream->stream);
Kiran Kandi93923902012-06-20 17:00:25 -07005047 return -EINVAL;
5048 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005049 return 0;
5050}
5051
5052static struct snd_soc_dai_ops tabla_dai_ops = {
5053 .startup = tabla_startup,
Swaminathan Sathappanf95ece62012-08-23 16:01:50 -07005054 .shutdown = tabla_shutdown,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005055 .hw_params = tabla_hw_params,
5056 .set_sysclk = tabla_set_dai_sysclk,
5057 .set_fmt = tabla_set_dai_fmt,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005058 .set_channel_map = tabla_set_channel_map,
5059 .get_channel_map = tabla_get_channel_map,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005060};
5061
5062static struct snd_soc_dai_driver tabla_dai[] = {
5063 {
5064 .name = "tabla_rx1",
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005065 .id = AIF1_PB,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005066 .playback = {
5067 .stream_name = "AIF1 Playback",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07005068 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005069 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005070 .rate_max = 192000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005071 .rate_min = 8000,
5072 .channels_min = 1,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005073 .channels_max = 2,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005074 },
5075 .ops = &tabla_dai_ops,
5076 },
5077 {
5078 .name = "tabla_tx1",
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005079 .id = AIF1_CAP,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005080 .capture = {
5081 .stream_name = "AIF1 Capture",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07005082 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005083 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005084 .rate_max = 192000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005085 .rate_min = 8000,
5086 .channels_min = 1,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005087 .channels_max = 4,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005088 },
5089 .ops = &tabla_dai_ops,
5090 },
Neema Shettyd3a89262012-02-16 10:23:50 -08005091 {
5092 .name = "tabla_rx2",
5093 .id = AIF2_PB,
5094 .playback = {
5095 .stream_name = "AIF2 Playback",
5096 .rates = WCD9310_RATES,
5097 .formats = TABLA_FORMATS,
5098 .rate_min = 8000,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005099 .rate_max = 192000,
Neema Shettyd3a89262012-02-16 10:23:50 -08005100 .channels_min = 1,
5101 .channels_max = 2,
5102 },
5103 .ops = &tabla_dai_ops,
5104 },
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005105 {
5106 .name = "tabla_tx2",
5107 .id = AIF2_CAP,
5108 .capture = {
5109 .stream_name = "AIF2 Capture",
5110 .rates = WCD9310_RATES,
5111 .formats = TABLA_FORMATS,
5112 .rate_max = 192000,
5113 .rate_min = 8000,
5114 .channels_min = 1,
5115 .channels_max = 4,
5116 },
5117 .ops = &tabla_dai_ops,
5118 },
Neema Shetty3fb1b802012-04-27 13:53:24 -07005119 {
5120 .name = "tabla_tx3",
5121 .id = AIF3_CAP,
5122 .capture = {
5123 .stream_name = "AIF3 Capture",
5124 .rates = WCD9310_RATES,
5125 .formats = TABLA_FORMATS,
5126 .rate_max = 48000,
5127 .rate_min = 8000,
5128 .channels_min = 1,
5129 .channels_max = 2,
5130 },
5131 .ops = &tabla_dai_ops,
5132 },
Kiran Kandia9fffe92012-05-20 23:42:30 -07005133 {
5134 .name = "tabla_rx3",
5135 .id = AIF3_PB,
5136 .playback = {
5137 .stream_name = "AIF3 Playback",
5138 .rates = WCD9310_RATES,
5139 .formats = TABLA_FORMATS,
5140 .rate_min = 8000,
5141 .rate_max = 192000,
5142 .channels_min = 1,
5143 .channels_max = 2,
5144 },
5145 .ops = &tabla_dai_ops,
5146 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005147};
Santosh Mardie15e2302011-11-15 10:39:23 +05305148
5149static struct snd_soc_dai_driver tabla_i2s_dai[] = {
5150 {
5151 .name = "tabla_i2s_rx1",
Kuirong Wang906ac472012-07-09 12:54:44 -07005152 .id = AIF1_PB,
Santosh Mardie15e2302011-11-15 10:39:23 +05305153 .playback = {
5154 .stream_name = "AIF1 Playback",
5155 .rates = WCD9310_RATES,
5156 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005157 .rate_max = 192000,
Santosh Mardie15e2302011-11-15 10:39:23 +05305158 .rate_min = 8000,
5159 .channels_min = 1,
5160 .channels_max = 4,
5161 },
5162 .ops = &tabla_dai_ops,
5163 },
5164 {
5165 .name = "tabla_i2s_tx1",
Kuirong Wang906ac472012-07-09 12:54:44 -07005166 .id = AIF1_CAP,
Santosh Mardie15e2302011-11-15 10:39:23 +05305167 .capture = {
5168 .stream_name = "AIF1 Capture",
5169 .rates = WCD9310_RATES,
5170 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005171 .rate_max = 192000,
Santosh Mardie15e2302011-11-15 10:39:23 +05305172 .rate_min = 8000,
5173 .channels_min = 1,
5174 .channels_max = 4,
5175 },
5176 .ops = &tabla_dai_ops,
5177 },
5178};
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005179
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07005180static int tabla_codec_enable_chmask(struct tabla_priv *tabla_p,
Kuirong Wang906ac472012-07-09 12:54:44 -07005181 int event, int index)
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07005182{
5183 int ret = 0;
Kuirong Wang906ac472012-07-09 12:54:44 -07005184 struct wcd9xxx_ch *ch;
5185
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07005186 switch (event) {
5187 case SND_SOC_DAPM_POST_PMU:
Kuirong Wang906ac472012-07-09 12:54:44 -07005188 list_for_each_entry(ch,
5189 &tabla_p->dai[index].wcd9xxx_ch_list, list) {
5190 ret = wcd9xxx_get_slave_port(ch->ch_num);
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07005191 if (ret < 0) {
5192 pr_err("%s: Invalid slave port ID: %d\n",
5193 __func__, ret);
5194 ret = -EINVAL;
5195 break;
5196 }
5197 tabla_p->dai[index].ch_mask |= 1 << ret;
5198 }
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07005199 break;
5200 case SND_SOC_DAPM_POST_PMD:
5201 ret = wait_event_timeout(tabla_p->dai[index].dai_wait,
5202 (tabla_p->dai[index].ch_mask == 0),
5203 msecs_to_jiffies(SLIM_CLOSE_TIMEOUT));
5204 if (!ret) {
5205 pr_err("%s: Slim close tx/rx wait timeout\n",
5206 __func__);
5207 ret = -EINVAL;
Kuirong Wang906ac472012-07-09 12:54:44 -07005208 }
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07005209 break;
5210 }
5211 return ret;
5212}
5213
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005214static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
Kuirong Wang906ac472012-07-09 12:54:44 -07005215 struct snd_kcontrol *kcontrol,
5216 int event)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005217{
Kuirong Wang906ac472012-07-09 12:54:44 -07005218 struct wcd9xxx *core;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005219 struct snd_soc_codec *codec = w->codec;
5220 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
Kuirong Wang906ac472012-07-09 12:54:44 -07005221 u32 ret = 0;
5222 struct wcd9xxx_codec_dai_data *dai;
5223
5224 core = dev_get_drvdata(codec->dev->parent);
5225
5226 pr_debug("%s: event called! codec name %s num_dai %d\n"
5227 "stream name %s event %d\n",
5228 __func__, w->codec->name, w->codec->num_dai,
5229 w->sname, event);
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005230
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005231 /* Execute the callback only if interface type is slimbus */
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005232 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
Kuirong Wang906ac472012-07-09 12:54:44 -07005233 if (event == SND_SOC_DAPM_POST_PMD && (core != NULL) &&
5234 (core->dev != NULL) &&
5235 (core->dev->parent != NULL)) {
5236 pm_runtime_mark_last_busy(core->dev->parent);
5237 pm_runtime_put(core->dev->parent);
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005238 }
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005239 return 0;
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005240 }
Kuirong Wang906ac472012-07-09 12:54:44 -07005241 pr_debug("%s: w->name %s w->shift %d event %d\n",
5242 __func__, w->name, w->shift, event);
5243 dai = &tabla_p->dai[w->shift];
Kiran Kandia9fffe92012-05-20 23:42:30 -07005244
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005245 switch (event) {
5246 case SND_SOC_DAPM_POST_PMU:
Kuirong Wang906ac472012-07-09 12:54:44 -07005247 ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMU,
5248 w->shift);
5249 ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
5250 dai->rate, dai->bit_width,
5251 &dai->grph);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005252 break;
5253 case SND_SOC_DAPM_POST_PMD:
Kuirong Wang906ac472012-07-09 12:54:44 -07005254 ret = wcd9xxx_close_slim_sch_rx(core,
5255 &dai->wcd9xxx_ch_list,
5256 dai->grph);
5257 ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMD,
5258 w->shift);
5259 if (ret < 0) {
5260 ret = wcd9xxx_disconnect_port(core,
5261 &dai->wcd9xxx_ch_list,
5262 dai->grph);
5263 pr_info("%s: Disconnect RX port, ret = %d\n",
5264 __func__, ret);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005265 }
Kuirong Wang906ac472012-07-09 12:54:44 -07005266 if ((core != NULL) &&
5267 (core->dev != NULL) &&
5268 (core->dev->parent != NULL)) {
5269 pm_runtime_mark_last_busy(core->dev->parent);
5270 pm_runtime_put(core->dev->parent);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005271 }
Kuirong Wang906ac472012-07-09 12:54:44 -07005272 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005273 }
Kuirong Wang906ac472012-07-09 12:54:44 -07005274
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005275 return ret;
5276}
5277
5278static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
Kuirong Wang906ac472012-07-09 12:54:44 -07005279 struct snd_kcontrol *kcontrol,
5280 int event)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005281{
Kuirong Wang906ac472012-07-09 12:54:44 -07005282 struct wcd9xxx *core;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005283 struct snd_soc_codec *codec = w->codec;
5284 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
Kuirong Wang906ac472012-07-09 12:54:44 -07005285 u32 ret = 0;
5286 struct wcd9xxx_codec_dai_data *dai;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005287
Kuirong Wang906ac472012-07-09 12:54:44 -07005288 core = dev_get_drvdata(codec->dev->parent);
5289
5290 pr_debug("%s: event called! codec name %s num_dai %d\n"
5291 "stream name %s\n", __func__, w->codec->name,
5292 w->codec->num_dai, w->sname);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005293
5294 /* Execute the callback only if interface type is slimbus */
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005295 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
Kuirong Wang906ac472012-07-09 12:54:44 -07005296 if (event == SND_SOC_DAPM_POST_PMD && (core != NULL) &&
5297 (core->dev != NULL) &&
5298 (core->dev->parent != NULL)) {
5299 pm_runtime_mark_last_busy(core->dev->parent);
5300 pm_runtime_put(core->dev->parent);
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005301 }
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005302 return 0;
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005303 }
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005304
5305 pr_debug("%s(): %s %d\n", __func__, w->name, event);
5306
Kuirong Wang906ac472012-07-09 12:54:44 -07005307 dai = &tabla_p->dai[w->shift];
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005308 switch (event) {
5309 case SND_SOC_DAPM_POST_PMU:
Kuirong Wang906ac472012-07-09 12:54:44 -07005310 ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMU,
5311 w->shift);
5312 ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
5313 dai->rate,
5314 dai->bit_width,
5315 &dai->grph);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005316 break;
5317 case SND_SOC_DAPM_POST_PMD:
Kuirong Wang906ac472012-07-09 12:54:44 -07005318 ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
5319 dai->grph);
5320 ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMD,
5321 w->shift);
5322 if (ret < 0) {
5323 ret = wcd9xxx_disconnect_port(core,
5324 &dai->wcd9xxx_ch_list,
5325 dai->grph);
5326 pr_info("%s: Disconnect TX port, ret = %d\n",
5327 __func__, ret);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005328 }
Kuirong Wang906ac472012-07-09 12:54:44 -07005329 if ((core != NULL) &&
5330 (core->dev != NULL) &&
5331 (core->dev->parent != NULL)) {
5332 pm_runtime_mark_last_busy(core->dev->parent);
5333 pm_runtime_put(core->dev->parent);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005334 }
Kuirong Wang906ac472012-07-09 12:54:44 -07005335 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005336 }
5337 return ret;
5338}
5339
5340/* Todo: Have seperate dapm widgets for I2S and Slimbus.
5341 * Might Need to have callbacks registered only for slimbus
5342 */
5343static const struct snd_soc_dapm_widget tabla_dapm_widgets[] = {
5344 /*RX stuff */
5345 SND_SOC_DAPM_OUTPUT("EAR"),
5346
Damir Didjusto7c85d712012-08-16 21:22:29 -07005347 SND_SOC_DAPM_PGA_E("EAR PA", SND_SOC_NOPM, 0, 0, NULL,
5348 0, tabla_ear_pa_event, SND_SOC_DAPM_PRE_PMU |
5349 SND_SOC_DAPM_PRE_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005350
Damir Didjusto7c85d712012-08-16 21:22:29 -07005351 SND_SOC_DAPM_MIXER("DAC1", SND_SOC_NOPM, 0, 0, dac1_switch,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005352 ARRAY_SIZE(dac1_switch)),
5353
Kuirong Wang906ac472012-07-09 12:54:44 -07005354 SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM,
5355 AIF1_PB, 0, tabla_codec_enable_slimrx,
5356 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5357 SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM,
5358 AIF2_PB, 0, tabla_codec_enable_slimrx,
5359 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5360 SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM,
5361 AIF3_PB, 0, tabla_codec_enable_slimrx,
5362 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5363
5364 SND_SOC_DAPM_MUX("SLIM RX1 MUX", SND_SOC_NOPM, TABLA_RX1, 0,
5365 &slim_rx_mux[TABLA_RX1]),
5366 SND_SOC_DAPM_MUX("SLIM RX2 MUX", SND_SOC_NOPM, TABLA_RX2, 0,
5367 &slim_rx_mux[TABLA_RX2]),
5368 SND_SOC_DAPM_MUX("SLIM RX3 MUX", SND_SOC_NOPM, TABLA_RX3, 0,
5369 &slim_rx_mux[TABLA_RX3]),
5370 SND_SOC_DAPM_MUX("SLIM RX4 MUX", SND_SOC_NOPM, TABLA_RX4, 0,
5371 &slim_rx_mux[TABLA_RX4]),
5372 SND_SOC_DAPM_MUX("SLIM RX5 MUX", SND_SOC_NOPM, TABLA_RX5, 0,
5373 &slim_rx_mux[TABLA_RX5]),
5374 SND_SOC_DAPM_MUX("SLIM RX6 MUX", SND_SOC_NOPM, TABLA_RX6, 0,
5375 &slim_rx_mux[TABLA_RX6]),
5376 SND_SOC_DAPM_MUX("SLIM RX7 MUX", SND_SOC_NOPM, TABLA_RX7, 0,
5377 &slim_rx_mux[TABLA_RX7]),
5378
5379 SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5380 SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
5381 SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
5382 SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
5383 SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
5384 SND_SOC_DAPM_MIXER("SLIM RX6", SND_SOC_NOPM, 0, 0, NULL, 0),
5385 SND_SOC_DAPM_MIXER("SLIM RX7", SND_SOC_NOPM, 0, 0, NULL, 0),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005386 /* Headphone */
5387 SND_SOC_DAPM_OUTPUT("HEADPHONE"),
5388 SND_SOC_DAPM_PGA_E("HPHL", TABLA_A_RX_HPH_CNP_EN, 5, 0, NULL, 0,
5389 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
5390 SND_SOC_DAPM_POST_PMD),
5391 SND_SOC_DAPM_MIXER("HPHL DAC", TABLA_A_RX_HPH_L_DAC_CTL, 7, 0,
5392 hphl_switch, ARRAY_SIZE(hphl_switch)),
5393
5394 SND_SOC_DAPM_PGA_E("HPHR", TABLA_A_RX_HPH_CNP_EN, 4, 0, NULL, 0,
5395 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
5396 SND_SOC_DAPM_POST_PMD),
5397
5398 SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TABLA_A_RX_HPH_R_DAC_CTL, 7, 0,
5399 tabla_hphr_dac_event,
5400 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5401
5402 /* Speaker */
5403 SND_SOC_DAPM_OUTPUT("LINEOUT1"),
5404 SND_SOC_DAPM_OUTPUT("LINEOUT2"),
5405 SND_SOC_DAPM_OUTPUT("LINEOUT3"),
5406 SND_SOC_DAPM_OUTPUT("LINEOUT4"),
5407 SND_SOC_DAPM_OUTPUT("LINEOUT5"),
5408
5409 SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TABLA_A_RX_LINE_CNP_EN, 0, 0, NULL,
5410 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
5411 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5412 SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TABLA_A_RX_LINE_CNP_EN, 1, 0, NULL,
5413 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
5414 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5415 SND_SOC_DAPM_PGA_E("LINEOUT3 PA", TABLA_A_RX_LINE_CNP_EN, 2, 0, NULL,
5416 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
5417 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5418 SND_SOC_DAPM_PGA_E("LINEOUT4 PA", TABLA_A_RX_LINE_CNP_EN, 3, 0, NULL,
5419 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
5420 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5421 SND_SOC_DAPM_PGA_E("LINEOUT5 PA", TABLA_A_RX_LINE_CNP_EN, 4, 0, NULL, 0,
5422 tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
5423 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5424
5425 SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TABLA_A_RX_LINE_1_DAC_CTL, 7, 0
5426 , tabla_lineout_dac_event,
5427 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5428 SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TABLA_A_RX_LINE_2_DAC_CTL, 7, 0
5429 , tabla_lineout_dac_event,
5430 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5431 SND_SOC_DAPM_DAC_E("LINEOUT3 DAC", NULL, TABLA_A_RX_LINE_3_DAC_CTL, 7, 0
5432 , tabla_lineout_dac_event,
5433 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5434 SND_SOC_DAPM_SWITCH("LINEOUT3 DAC GROUND", SND_SOC_NOPM, 0, 0,
5435 &lineout3_ground_switch),
5436 SND_SOC_DAPM_DAC_E("LINEOUT4 DAC", NULL, TABLA_A_RX_LINE_4_DAC_CTL, 7, 0
5437 , tabla_lineout_dac_event,
5438 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5439 SND_SOC_DAPM_SWITCH("LINEOUT4 DAC GROUND", SND_SOC_NOPM, 0, 0,
5440 &lineout4_ground_switch),
5441 SND_SOC_DAPM_DAC_E("LINEOUT5 DAC", NULL, TABLA_A_RX_LINE_5_DAC_CTL, 7, 0
5442 , tabla_lineout_dac_event,
5443 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5444
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005445 SND_SOC_DAPM_MIXER_E("RX1 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005446 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5447 SND_SOC_DAPM_POST_PMU),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005448 SND_SOC_DAPM_MIXER_E("RX2 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005449 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5450 SND_SOC_DAPM_POST_PMU),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005451 SND_SOC_DAPM_MIXER_E("RX3 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005452 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5453 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005454 SND_SOC_DAPM_MIXER_E("RX4 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005455 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5456 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005457 SND_SOC_DAPM_MIXER_E("RX5 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 4, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005458 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5459 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005460 SND_SOC_DAPM_MIXER_E("RX6 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005461 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5462 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005463 SND_SOC_DAPM_MIXER_E("RX7 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 6, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005464 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5465 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005466
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005467 SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5468 SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5469 SND_SOC_DAPM_MIXER("RX3 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5470
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005471 SND_SOC_DAPM_MUX_E("RX4 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0,
5472 &rx4_dsm_mux, tabla_codec_reset_interpolator,
5473 SND_SOC_DAPM_PRE_PMU),
5474
5475 SND_SOC_DAPM_MUX_E("RX6 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0,
5476 &rx6_dsm_mux, tabla_codec_reset_interpolator,
5477 SND_SOC_DAPM_PRE_PMU),
5478
Kuirong Wang84ee8802013-02-09 12:52:06 -08005479 SND_SOC_DAPM_MIXER_E("RX1 CHAIN", SND_SOC_NOPM, 5, 0, NULL,
5480 0, tabla_codec_hphr_dem_input_selection,
5481 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
5482 SND_SOC_DAPM_MIXER_E("RX2 CHAIN", SND_SOC_NOPM, 5, 0, NULL,
5483 0, tabla_codec_hphl_dem_input_selection,
5484 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005485
5486 SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5487 &rx_mix1_inp1_mux),
5488 SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5489 &rx_mix1_inp2_mux),
Kiran Kandia9fffe92012-05-20 23:42:30 -07005490 SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0,
5491 &rx_mix1_inp3_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005492 SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5493 &rx2_mix1_inp1_mux),
5494 SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5495 &rx2_mix1_inp2_mux),
5496 SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5497 &rx3_mix1_inp1_mux),
5498 SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5499 &rx3_mix1_inp2_mux),
5500 SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5501 &rx4_mix1_inp1_mux),
5502 SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5503 &rx4_mix1_inp2_mux),
5504 SND_SOC_DAPM_MUX("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5505 &rx5_mix1_inp1_mux),
5506 SND_SOC_DAPM_MUX("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5507 &rx5_mix1_inp2_mux),
5508 SND_SOC_DAPM_MUX("RX6 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5509 &rx6_mix1_inp1_mux),
5510 SND_SOC_DAPM_MUX("RX6 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5511 &rx6_mix1_inp2_mux),
5512 SND_SOC_DAPM_MUX("RX7 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5513 &rx7_mix1_inp1_mux),
5514 SND_SOC_DAPM_MUX("RX7 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5515 &rx7_mix1_inp2_mux),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005516 SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0,
5517 &rx1_mix2_inp1_mux),
5518 SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0,
5519 &rx1_mix2_inp2_mux),
5520 SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0,
5521 &rx2_mix2_inp1_mux),
5522 SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0,
5523 &rx2_mix2_inp2_mux),
5524 SND_SOC_DAPM_MUX("RX3 MIX2 INP1", SND_SOC_NOPM, 0, 0,
5525 &rx3_mix2_inp1_mux),
5526 SND_SOC_DAPM_MUX("RX3 MIX2 INP2", SND_SOC_NOPM, 0, 0,
5527 &rx3_mix2_inp2_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005528
5529 SND_SOC_DAPM_SUPPLY("CP", TABLA_A_CP_EN, 0, 0,
5530 tabla_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU |
5531 SND_SOC_DAPM_PRE_PMD),
5532
5533 SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
5534 tabla_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
5535 SND_SOC_DAPM_POST_PMD),
5536
5537 /* TX */
5538
5539 SND_SOC_DAPM_SUPPLY("CDC_CONN", TABLA_A_CDC_CLK_OTHR_CTL, 2, 0, NULL,
5540 0),
5541
Simmi Pateriya71d63872012-11-08 01:06:30 +05305542 SND_SOC_DAPM_SUPPLY("LDO_H", SND_SOC_NOPM, 0, 0,
5543 tabla_codec_enable_ldo_h, SND_SOC_DAPM_PRE_PMU |
5544 SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005545
Kuirong Wang0f8ade32012-02-27 16:29:45 -08005546 SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 0, 0,
5547 tabla_config_compander, SND_SOC_DAPM_PRE_PMU |
5548 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
5549 SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 1, 0,
5550 tabla_config_compander, SND_SOC_DAPM_PRE_PMU |
5551 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
5552
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005553 SND_SOC_DAPM_INPUT("AMIC1"),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305554 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005555 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5556 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305557 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005558 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5559 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305560 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005561 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5562 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5563 SND_SOC_DAPM_ADC_E("ADC1", NULL, TABLA_A_TX_1_2_EN, 7, 0,
5564 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
5565 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5566
5567 SND_SOC_DAPM_INPUT("AMIC3"),
5568 SND_SOC_DAPM_ADC_E("ADC3", NULL, TABLA_A_TX_3_4_EN, 7, 0,
5569 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
5570 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5571
5572 SND_SOC_DAPM_INPUT("AMIC4"),
5573 SND_SOC_DAPM_ADC_E("ADC4", NULL, TABLA_A_TX_3_4_EN, 3, 0,
5574 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
5575 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5576
5577 SND_SOC_DAPM_INPUT("AMIC5"),
5578 SND_SOC_DAPM_ADC_E("ADC5", NULL, TABLA_A_TX_5_6_EN, 7, 0,
5579 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
5580
5581 SND_SOC_DAPM_INPUT("AMIC6"),
5582 SND_SOC_DAPM_ADC_E("ADC6", NULL, TABLA_A_TX_5_6_EN, 3, 0,
5583 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
5584
5585 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 -08005586 &dec1_mux, tabla_codec_enable_dec,
5587 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5588 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005589
5590 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 -08005591 &dec2_mux, tabla_codec_enable_dec,
5592 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5593 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005594
5595 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 -08005596 &dec3_mux, tabla_codec_enable_dec,
5597 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5598 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005599
5600 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 -08005601 &dec4_mux, tabla_codec_enable_dec,
5602 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5603 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005604
5605 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 -08005606 &dec5_mux, tabla_codec_enable_dec,
5607 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5608 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005609
5610 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 -08005611 &dec6_mux, tabla_codec_enable_dec,
5612 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5613 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005614
5615 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 -08005616 &dec7_mux, tabla_codec_enable_dec,
5617 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5618 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005619
5620 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 -08005621 &dec8_mux, tabla_codec_enable_dec,
5622 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5623 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005624
5625 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 -08005626 &dec9_mux, tabla_codec_enable_dec,
5627 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5628 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005629
5630 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 -08005631 &dec10_mux, tabla_codec_enable_dec,
5632 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5633 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005634
5635 SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux),
5636 SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux),
5637
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08005638 SND_SOC_DAPM_OUTPUT("ANC HEADPHONE"),
5639 SND_SOC_DAPM_PGA_E("ANC HPHL", SND_SOC_NOPM, 0, 0, NULL, 0,
5640 tabla_codec_enable_anc,
5641 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
5642 SND_SOC_DAPM_PGA_E("ANC HPHR", SND_SOC_NOPM, 0, 0, NULL, 0,
5643 tabla_codec_enable_anc, SND_SOC_DAPM_PRE_PMU),
5644
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005645
5646 SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux),
5647
5648 SND_SOC_DAPM_INPUT("AMIC2"),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305649 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005650 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Simmi Pateriya71d63872012-11-08 01:06:30 +05305651 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5652 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Power External",
5653 TABLA_A_MICB_2_CTL, 7, 0,
5654 tabla_codec_enable_micbias_power,
5655 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5656 SND_SOC_DAPM_POST_PMD),
5657
5658 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005659 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5660 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305661 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005662 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5663 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305664 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005665 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5666 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305667 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005668 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5669 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305670 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005671 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5672 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305673 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005674 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5675 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5676 SND_SOC_DAPM_ADC_E("ADC2", NULL, TABLA_A_TX_1_2_EN, 3, 0,
5677 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
5678 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5679
Kuirong Wang906ac472012-07-09 12:54:44 -07005680 SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM,
5681 AIF1_CAP, 0, tabla_codec_enable_slimtx,
5682 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5683
5684 SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM,
5685 AIF2_CAP, 0, tabla_codec_enable_slimtx,
5686 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5687
5688 SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM,
5689 AIF3_CAP, 0, tabla_codec_enable_slimtx,
5690 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5691
5692 SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0,
5693 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
5694
5695 SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0,
5696 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
5697
5698 SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0,
5699 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
5700
5701 SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, TABLA_TX1, 0,
5702 &sb_tx1_mux),
5703 SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, TABLA_TX2, 0,
5704 &sb_tx2_mux),
5705 SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, TABLA_TX3, 0,
5706 &sb_tx3_mux),
5707 SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, TABLA_TX4, 0,
5708 &sb_tx4_mux),
5709 SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, TABLA_TX5, 0,
5710 &sb_tx5_mux),
5711 SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, TABLA_TX6, 0,
5712 &sb_tx6_mux),
5713 SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, TABLA_TX7, 0,
5714 &sb_tx7_mux),
5715 SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, TABLA_TX8, 0,
5716 &sb_tx8_mux),
5717 SND_SOC_DAPM_MUX("SLIM TX9 MUX", SND_SOC_NOPM, TABLA_TX9, 0,
5718 &sb_tx9_mux),
5719 SND_SOC_DAPM_MUX("SLIM TX10 MUX", SND_SOC_NOPM, TABLA_TX10, 0,
5720 &sb_tx10_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005721
5722 /* Digital Mic Inputs */
5723 SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
5724 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5725 SND_SOC_DAPM_POST_PMD),
5726
5727 SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
5728 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5729 SND_SOC_DAPM_POST_PMD),
5730
5731 SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0,
5732 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5733 SND_SOC_DAPM_POST_PMD),
5734
5735 SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0,
5736 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5737 SND_SOC_DAPM_POST_PMD),
5738
5739 SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0,
5740 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5741 SND_SOC_DAPM_POST_PMD),
5742 SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 0,
5743 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5744 SND_SOC_DAPM_POST_PMD),
5745
5746 /* Sidetone */
5747 SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux),
5748 SND_SOC_DAPM_PGA("IIR1", TABLA_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0),
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08005749
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07005750 SND_SOC_DAPM_MUX("IIR2 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir2_inp1_mux),
5751 SND_SOC_DAPM_PGA("IIR2", TABLA_A_CDC_CLK_SD_CTL, 1, 0, NULL, 0),
5752
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08005753 /* AUX PGA */
5754 SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TABLA_A_AUX_L_EN, 7, 0,
5755 tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
5756 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
5757 SND_SOC_DAPM_POST_PMD),
5758
5759 SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TABLA_A_AUX_R_EN, 7, 0,
5760 tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
5761 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
5762 SND_SOC_DAPM_POST_PMD),
5763
5764 /* Lineout, ear and HPH PA Mixers */
5765 SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0,
5766 hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)),
5767
5768 SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0,
5769 hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)),
5770
5771 SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0,
5772 lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)),
5773
5774 SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0,
5775 lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)),
5776
5777 SND_SOC_DAPM_MIXER("LINEOUT3_PA_MIXER", SND_SOC_NOPM, 0, 0,
5778 lineout3_pa_mix, ARRAY_SIZE(lineout3_pa_mix)),
5779
5780 SND_SOC_DAPM_MIXER("LINEOUT4_PA_MIXER", SND_SOC_NOPM, 0, 0,
5781 lineout4_pa_mix, ARRAY_SIZE(lineout4_pa_mix)),
5782
5783 SND_SOC_DAPM_MIXER("LINEOUT5_PA_MIXER", SND_SOC_NOPM, 0, 0,
5784 lineout5_pa_mix, ARRAY_SIZE(lineout5_pa_mix)),
5785
5786 SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0,
5787 ear_pa_mix, ARRAY_SIZE(ear_pa_mix)),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005788};
5789
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005790static short tabla_codec_read_sta_result(struct snd_soc_codec *codec)
Bradley Rubincb1e2732011-06-23 16:49:20 -07005791{
5792 u8 bias_msb, bias_lsb;
5793 short bias_value;
5794
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005795 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B3_STATUS);
5796 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B2_STATUS);
5797 bias_value = (bias_msb << 8) | bias_lsb;
5798 return bias_value;
5799}
5800
5801static short tabla_codec_read_dce_result(struct snd_soc_codec *codec)
5802{
5803 u8 bias_msb, bias_lsb;
5804 short bias_value;
5805
5806 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B5_STATUS);
5807 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B4_STATUS);
5808 bias_value = (bias_msb << 8) | bias_lsb;
5809 return bias_value;
5810}
5811
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005812static void tabla_turn_onoff_rel_detection(struct snd_soc_codec *codec, bool on)
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005813{
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005814 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, on << 1);
5815}
5816
5817static short __tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce,
5818 bool override_bypass, bool noreldetection)
5819{
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005820 short bias_value;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005821 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
5822
Joonwoo Parkf6574c72012-10-10 17:29:57 -07005823 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005824 if (noreldetection)
5825 tabla_turn_onoff_rel_detection(codec, false);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005826
Joonwoo Park925914c2012-01-05 13:35:18 -08005827 /* Turn on the override */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005828 if (!override_bypass)
5829 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x4, 0x4);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005830 if (dce) {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005831 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5832 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
5833 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
Joonwoo Park433149a2012-01-11 09:53:54 -08005834 usleep_range(tabla->mbhc_data.t_sta_dce,
5835 tabla->mbhc_data.t_sta_dce);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005836 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
Joonwoo Park0976d012011-12-22 11:48:18 -08005837 usleep_range(tabla->mbhc_data.t_dce,
5838 tabla->mbhc_data.t_dce);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005839 bias_value = tabla_codec_read_dce_result(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005840 } else {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005841 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005842 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
5843 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
Joonwoo Park433149a2012-01-11 09:53:54 -08005844 usleep_range(tabla->mbhc_data.t_sta_dce,
5845 tabla->mbhc_data.t_sta_dce);
Joonwoo Park0976d012011-12-22 11:48:18 -08005846 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
5847 usleep_range(tabla->mbhc_data.t_sta,
5848 tabla->mbhc_data.t_sta);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005849 bias_value = tabla_codec_read_sta_result(codec);
5850 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5851 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005852 }
Joonwoo Park925914c2012-01-05 13:35:18 -08005853 /* Turn off the override after measuring mic voltage */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005854 if (!override_bypass)
5855 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00);
5856
5857 if (noreldetection)
5858 tabla_turn_onoff_rel_detection(codec, true);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07005859 wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005860
Bradley Rubincb1e2732011-06-23 16:49:20 -07005861 return bias_value;
5862}
5863
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005864static short tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce,
5865 bool norel)
5866{
5867 return __tabla_codec_sta_dce(codec, dce, false, norel);
5868}
5869
5870/* called only from interrupt which is under codec_resource_lock acquisition */
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07005871static short tabla_codec_setup_hs_polling(struct snd_soc_codec *codec)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005872{
5873 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07005874 short bias_value;
Simmi Pateriya71d63872012-11-08 01:06:30 +05305875 u8 cfilt_mode = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005876
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005877 pr_debug("%s: enter, mclk_enabled %d\n", __func__, tabla->mclk_enabled);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005878 if (!tabla->mbhc_cfg.calibration) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005879 pr_err("Error, no tabla calibration\n");
Bradley Rubincb1e2732011-06-23 16:49:20 -07005880 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005881 }
5882
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07005883 if (!tabla->mclk_enabled) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07005884 tabla_codec_disable_clock_block(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005885 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_MBHC_MODE);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07005886 tabla_enable_rx_bias(codec, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005887 tabla_codec_enable_clock_block(codec, 1);
5888 }
5889
5890 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x01);
Simmi Pateriya71d63872012-11-08 01:06:30 +05305891 if (!tabla->mbhc_cfg.micbias_always_on) {
5892 /* Make sure CFILT is in fast mode, save current mode */
5893 cfilt_mode = snd_soc_read(codec,
5894 tabla->mbhc_bias_regs.cfilt_ctl);
5895 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl,
5896 0x70, 0x00);
5897 }
Patrick Lai3043fba2011-08-01 14:15:57 -07005898
Joonwoo Parkf4267c22012-01-10 13:25:24 -08005899 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x1F, 0x16);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005900
5901 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005902 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005903
5904 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x80);
5905 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x1F, 0x1C);
5906 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x40, 0x40);
5907
5908 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005909 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5910 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005911
Joonwoo Park925914c2012-01-05 13:35:18 -08005912 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x2, 0x2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005913 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5914
Bradley Rubincb1e2732011-06-23 16:49:20 -07005915 tabla_codec_calibrate_hs_polling(codec);
5916
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005917 /* don't flip override */
5918 bias_value = __tabla_codec_sta_dce(codec, 1, true, true);
Simmi Pateriya71d63872012-11-08 01:06:30 +05305919 if (!tabla->mbhc_cfg.micbias_always_on)
5920 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl,
5921 0x40, cfilt_mode);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005922 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005923
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07005924 return bias_value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005925}
5926
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005927static int tabla_cancel_btn_work(struct tabla_priv *tabla)
5928{
5929 int r = 0;
5930 struct wcd9xxx *core = dev_get_drvdata(tabla->codec->dev->parent);
5931
5932 if (cancel_delayed_work_sync(&tabla->mbhc_btn_dwork)) {
5933 /* if scheduled mbhc_btn_dwork is canceled from here,
5934 * we have to unlock from here instead btn_work */
5935 wcd9xxx_unlock_sleep(core);
5936 r = 1;
5937 }
5938 return r;
5939}
5940
5941/* called under codec_resource_lock acquisition */
5942void tabla_set_and_turnoff_hph_padac(struct snd_soc_codec *codec)
Joonwoo Park03324832012-03-19 19:36:16 -07005943{
5944 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005945 u8 wg_time;
5946
5947 wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ;
5948 wg_time += 1;
Joonwoo Park03324832012-03-19 19:36:16 -07005949
5950 /* If headphone PA is on, check if userspace receives
5951 * removal event to sync-up PA's state */
5952 if (tabla_is_hph_pa_on(codec)) {
5953 pr_debug("%s PA is on, setting PA_OFF_ACK\n", __func__);
5954 set_bit(TABLA_HPHL_PA_OFF_ACK, &tabla->hph_pa_dac_state);
5955 set_bit(TABLA_HPHR_PA_OFF_ACK, &tabla->hph_pa_dac_state);
5956 } else {
5957 pr_debug("%s PA is off\n", __func__);
5958 }
5959
5960 if (tabla_is_hph_dac_on(codec, 1))
5961 set_bit(TABLA_HPHL_DAC_OFF_ACK, &tabla->hph_pa_dac_state);
5962 if (tabla_is_hph_dac_on(codec, 0))
5963 set_bit(TABLA_HPHR_DAC_OFF_ACK, &tabla->hph_pa_dac_state);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005964
5965 snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00);
5966 snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_DAC_CTL,
Gopikrishnaiah Anandan3b230b22012-12-07 11:36:58 -05005967 0x80, 0x00);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005968 snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_DAC_CTL,
5969 0xC0, 0x00);
5970 usleep_range(wg_time * 1000, wg_time * 1000);
5971}
5972
5973static void tabla_clr_and_turnon_hph_padac(struct tabla_priv *tabla)
5974{
5975 bool pa_turned_on = false;
5976 struct snd_soc_codec *codec = tabla->codec;
5977 u8 wg_time;
5978
5979 wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ;
5980 wg_time += 1;
5981
5982 if (test_and_clear_bit(TABLA_HPHR_DAC_OFF_ACK,
5983 &tabla->hph_pa_dac_state)) {
5984 pr_debug("%s: HPHR clear flag and enable DAC\n", __func__);
5985 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_R_DAC_CTL,
5986 0xC0, 0xC0);
5987 }
5988 if (test_and_clear_bit(TABLA_HPHL_DAC_OFF_ACK,
5989 &tabla->hph_pa_dac_state)) {
5990 pr_debug("%s: HPHL clear flag and enable DAC\n", __func__);
5991 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_L_DAC_CTL,
5992 0xC0, 0xC0);
5993 }
5994
5995 if (test_and_clear_bit(TABLA_HPHR_PA_OFF_ACK,
5996 &tabla->hph_pa_dac_state)) {
5997 pr_debug("%s: HPHR clear flag and enable PA\n", __func__);
5998 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x10,
5999 1 << 4);
6000 pa_turned_on = true;
6001 }
6002 if (test_and_clear_bit(TABLA_HPHL_PA_OFF_ACK,
6003 &tabla->hph_pa_dac_state)) {
6004 pr_debug("%s: HPHL clear flag and enable PA\n", __func__);
6005 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x20,
6006 1 << 5);
6007 pa_turned_on = true;
6008 }
6009
6010 if (pa_turned_on) {
6011 pr_debug("%s: PA was turned off by MBHC and not by DAPM\n",
6012 __func__);
6013 usleep_range(wg_time * 1000, wg_time * 1000);
6014 }
6015}
6016
6017/* called under codec_resource_lock acquisition */
Simmi Pateriya71d63872012-11-08 01:06:30 +05306018static void tabla_codec_enable_mbhc_micbias(struct snd_soc_codec *codec,
6019 bool enable)
6020{
6021 int r;
6022 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
6023
6024 if (!tabla->mbhc_cfg.micbias_always_on)
6025 return;
6026 if (enable) {
6027 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
6028 tabla_codec_update_cfilt_usage(codec,
6029 tabla->mbhc_bias_regs.cfilt_sel, 1);
6030 r = snd_soc_dapm_force_enable_pin(&codec->dapm,
6031 "MIC BIAS2 Power External");
6032 snd_soc_dapm_sync(&codec->dapm);
6033 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
6034 pr_debug("%s: Turning on MICBIAS2 r %d\n", __func__, r);
6035 } else {
6036 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
6037 r = snd_soc_dapm_disable_pin(&codec->dapm,
6038 "MIC BIAS2 Power External");
6039 snd_soc_dapm_sync(&codec->dapm);
6040 tabla_codec_update_cfilt_usage(codec,
6041 tabla->mbhc_bias_regs.cfilt_sel, 0);
6042 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
6043 pr_debug("%s: Turning off MICBIAS2 r %d\n", __func__, r);
6044 }
6045}
6046
6047/* called under codec_resource_lock acquisition */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006048static void tabla_codec_report_plug(struct snd_soc_codec *codec, int insertion,
6049 enum snd_jack_types jack_type)
6050{
6051 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006052 pr_debug("%s: enter insertion %d hph_status %x\n",
6053 __func__, insertion, tabla->hph_status);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006054 if (!insertion) {
6055 /* Report removal */
6056 tabla->hph_status &= ~jack_type;
6057 if (tabla->mbhc_cfg.headset_jack) {
6058 /* cancel possibly scheduled btn work and
6059 * report release if we reported button press */
6060 if (tabla_cancel_btn_work(tabla)) {
6061 pr_debug("%s: button press is canceled\n",
6062 __func__);
6063 } else if (tabla->buttons_pressed) {
6064 pr_debug("%s: Reporting release for reported "
6065 "button press %d\n", __func__,
6066 jack_type);
6067 tabla_snd_soc_jack_report(tabla,
6068 tabla->mbhc_cfg.button_jack, 0,
6069 tabla->buttons_pressed);
6070 tabla->buttons_pressed &=
6071 ~TABLA_JACK_BUTTON_MASK;
6072 }
Simmi Pateriya71d63872012-11-08 01:06:30 +05306073 if (jack_type == SND_JACK_HEADSET)
6074 tabla_codec_enable_mbhc_micbias(codec, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006075 pr_debug("%s: Reporting removal %d(%x)\n", __func__,
6076 jack_type, tabla->hph_status);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006077 tabla_snd_soc_jack_report(tabla,
6078 tabla->mbhc_cfg.headset_jack,
6079 tabla->hph_status,
6080 TABLA_JACK_MASK);
6081 }
6082 tabla_set_and_turnoff_hph_padac(codec);
6083 hphocp_off_report(tabla, SND_JACK_OC_HPHR,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07006084 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006085 hphocp_off_report(tabla, SND_JACK_OC_HPHL,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07006086 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006087 tabla->current_plug = PLUG_TYPE_NONE;
6088 tabla->mbhc_polling_active = false;
6089 } else {
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006090 if (tabla->mbhc_cfg.detect_extn_cable) {
6091 /* Report removal of current jack type */
6092 if (tabla->hph_status != jack_type &&
6093 tabla->mbhc_cfg.headset_jack) {
6094 pr_debug("%s: Reporting removal (%x)\n",
6095 __func__, tabla->hph_status);
6096 tabla_snd_soc_jack_report(tabla,
6097 tabla->mbhc_cfg.headset_jack,
6098 0, TABLA_JACK_MASK);
6099 tabla->hph_status = 0;
6100 }
6101 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006102 /* Report insertion */
6103 tabla->hph_status |= jack_type;
6104
6105 if (jack_type == SND_JACK_HEADPHONE)
6106 tabla->current_plug = PLUG_TYPE_HEADPHONE;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006107 else if (jack_type == SND_JACK_UNSUPPORTED)
6108 tabla->current_plug = PLUG_TYPE_GND_MIC_SWAP;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006109 else if (jack_type == SND_JACK_HEADSET) {
6110 tabla->mbhc_polling_active = true;
6111 tabla->current_plug = PLUG_TYPE_HEADSET;
Simmi Pateriya71d63872012-11-08 01:06:30 +05306112 tabla_codec_enable_mbhc_micbias(codec, true);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006113 } else if (jack_type == SND_JACK_LINEOUT)
6114 tabla->current_plug = PLUG_TYPE_HIGH_HPH;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006115 if (tabla->mbhc_cfg.headset_jack) {
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006116 pr_debug("%s: Reporting insertion %d(%x)\n", __func__,
6117 jack_type, tabla->hph_status);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006118 tabla_snd_soc_jack_report(tabla,
6119 tabla->mbhc_cfg.headset_jack,
6120 tabla->hph_status,
6121 TABLA_JACK_MASK);
6122 }
6123 tabla_clr_and_turnon_hph_padac(tabla);
6124 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006125 pr_debug("%s: leave hph_status %x\n", __func__, tabla->hph_status);
Joonwoo Park03324832012-03-19 19:36:16 -07006126}
6127
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006128static int tabla_codec_enable_hs_detect(struct snd_soc_codec *codec,
Joonwoo Park03324832012-03-19 19:36:16 -07006129 int insertion, int trigger,
6130 bool padac_off)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006131{
6132 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006133 int central_bias_enabled = 0;
Joonwoo Park0976d012011-12-22 11:48:18 -08006134 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006135 TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08006136 const struct tabla_mbhc_plug_detect_cfg *plug_det =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006137 TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006138
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006139 pr_debug("%s: enter insertion(%d) trigger(0x%x)\n",
6140 __func__, insertion, trigger);
6141
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006142 if (!tabla->mbhc_cfg.calibration) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006143 pr_err("Error, no tabla calibration\n");
6144 return -EINVAL;
6145 }
6146
6147 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0);
6148
Joonwoo Park03324832012-03-19 19:36:16 -07006149 /* Make sure mic bias and Mic line schmitt trigger
6150 * are turned OFF
6151 */
6152 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01);
6153 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
6154
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006155 if (insertion) {
Bhalchandra Gajareafc86432012-08-23 13:44:07 -07006156 pr_debug("%s: setup for insertion\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07006157 tabla_codec_switch_micbias(codec, 0);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006158
Joonwoo Park03324832012-03-19 19:36:16 -07006159 /* DAPM can manipulate PA/DAC bits concurrently */
6160 if (padac_off == true) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006161 tabla_set_and_turnoff_hph_padac(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07006162 }
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006163
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006164 if (trigger & MBHC_USE_HPHL_TRIGGER) {
Joonwoo Park03324832012-03-19 19:36:16 -07006165 /* Enable HPH Schmitt Trigger */
6166 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x11,
6167 0x11);
6168 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x0C,
6169 plug_det->hph_current << 2);
6170 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x02,
6171 0x02);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006172 }
6173 if (trigger & MBHC_USE_MB_TRIGGER) {
Joonwoo Park03324832012-03-19 19:36:16 -07006174 /* enable the mic line schmitt trigger */
6175 snd_soc_update_bits(codec,
6176 tabla->mbhc_bias_regs.mbhc_reg,
6177 0x60, plug_det->mic_current << 5);
6178 snd_soc_update_bits(codec,
6179 tabla->mbhc_bias_regs.mbhc_reg,
6180 0x80, 0x80);
6181 usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid);
6182 snd_soc_update_bits(codec,
6183 tabla->mbhc_bias_regs.ctl_reg, 0x01,
6184 0x00);
6185 snd_soc_update_bits(codec,
6186 tabla->mbhc_bias_regs.mbhc_reg,
6187 0x10, 0x10);
6188 }
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006189
6190 /* setup for insetion detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006191 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006192 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07006193 pr_debug("setup for removal detection\n");
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006194 /* Make sure the HPH schmitt trigger is OFF */
6195 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x12, 0x00);
6196
6197 /* enable the mic line schmitt trigger */
Joonwoo Park03324832012-03-19 19:36:16 -07006198 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg,
6199 0x01, 0x00);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006200 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x60,
Joonwoo Park0976d012011-12-22 11:48:18 -08006201 plug_det->mic_current << 5);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006202 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
6203 0x80, 0x80);
Joonwoo Park0976d012011-12-22 11:48:18 -08006204 usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006205 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
6206 0x10, 0x10);
6207
6208 /* Setup for low power removal detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006209 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0x2);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006210 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006211
6212 if (snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x4) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006213 /* called called by interrupt */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006214 if (!(tabla->clock_active)) {
6215 tabla_codec_enable_config_mode(codec, 1);
6216 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07006217 0x06, 0);
Joonwoo Park0976d012011-12-22 11:48:18 -08006218 usleep_range(generic->t_shutdown_plug_rem,
6219 generic->t_shutdown_plug_rem);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006220 tabla_codec_enable_config_mode(codec, 0);
6221 } else
6222 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07006223 0x06, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006224 }
6225
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07006226 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.int_rbias, 0x80, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006227
6228 /* If central bandgap disabled */
6229 if (!(snd_soc_read(codec, TABLA_A_PIN_CTL_OE1) & 1)) {
6230 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x3, 0x3);
Joonwoo Park0976d012011-12-22 11:48:18 -08006231 usleep_range(generic->t_bg_fast_settle,
6232 generic->t_bg_fast_settle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006233 central_bias_enabled = 1;
6234 }
6235
6236 /* If LDO_H disabled */
6237 if (snd_soc_read(codec, TABLA_A_PIN_CTL_OE0) & 0x80) {
6238 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x10, 0);
6239 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0x80);
Joonwoo Park0976d012011-12-22 11:48:18 -08006240 usleep_range(generic->t_ldoh, generic->t_ldoh);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006241 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0);
6242
6243 if (central_bias_enabled)
6244 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x1, 0);
6245 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006246
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08006247 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x3,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006248 tabla->mbhc_cfg.micbias);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006249
Joonwoo Parkf6574c72012-10-10 17:29:57 -07006250 wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006251 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0x1);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006252 pr_debug("%s: leave\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006253 return 0;
6254}
6255
Joonwoo Park0976d012011-12-22 11:48:18 -08006256static u16 tabla_codec_v_sta_dce(struct snd_soc_codec *codec, bool dce,
6257 s16 vin_mv)
6258{
Joonwoo Park0976d012011-12-22 11:48:18 -08006259 struct tabla_priv *tabla;
Joonwoo Park03324832012-03-19 19:36:16 -07006260 s16 diff, zero;
Joonwoo Park0976d012011-12-22 11:48:18 -08006261 u32 mb_mv, in;
Joonwoo Park03324832012-03-19 19:36:16 -07006262 u16 value;
Joonwoo Park0976d012011-12-22 11:48:18 -08006263
6264 tabla = snd_soc_codec_get_drvdata(codec);
6265 mb_mv = tabla->mbhc_data.micb_mv;
6266
6267 if (mb_mv == 0) {
6268 pr_err("%s: Mic Bias voltage is set to zero\n", __func__);
6269 return -EINVAL;
6270 }
6271
6272 if (dce) {
Joonwoo Park03324832012-03-19 19:36:16 -07006273 diff = (tabla->mbhc_data.dce_mb) - (tabla->mbhc_data.dce_z);
6274 zero = (tabla->mbhc_data.dce_z);
Joonwoo Park0976d012011-12-22 11:48:18 -08006275 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07006276 diff = (tabla->mbhc_data.sta_mb) - (tabla->mbhc_data.sta_z);
6277 zero = (tabla->mbhc_data.sta_z);
Joonwoo Park0976d012011-12-22 11:48:18 -08006278 }
6279 in = (u32) diff * vin_mv;
6280
Joonwoo Park03324832012-03-19 19:36:16 -07006281 value = (u16) (in / mb_mv) + zero;
6282 return value;
Joonwoo Park0976d012011-12-22 11:48:18 -08006283}
6284
6285static s32 tabla_codec_sta_dce_v(struct snd_soc_codec *codec, s8 dce,
6286 u16 bias_value)
6287{
6288 struct tabla_priv *tabla;
Joonwoo Park03324832012-03-19 19:36:16 -07006289 s16 value, z, mb;
Joonwoo Park0976d012011-12-22 11:48:18 -08006290 s32 mv;
6291
6292 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07006293 value = bias_value;
Joonwoo Park0976d012011-12-22 11:48:18 -08006294 if (dce) {
Joonwoo Park03324832012-03-19 19:36:16 -07006295 z = (tabla->mbhc_data.dce_z);
6296 mb = (tabla->mbhc_data.dce_mb);
6297 mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z);
Joonwoo Park0976d012011-12-22 11:48:18 -08006298 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07006299 z = (tabla->mbhc_data.sta_z);
6300 mb = (tabla->mbhc_data.sta_mb);
6301 mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z);
Joonwoo Park0976d012011-12-22 11:48:18 -08006302 }
6303
6304 return mv;
6305}
6306
Joonwoo Park03324832012-03-19 19:36:16 -07006307static void btn_lpress_fn(struct work_struct *work)
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006308{
6309 struct delayed_work *delayed_work;
6310 struct tabla_priv *tabla;
Joonwoo Park0976d012011-12-22 11:48:18 -08006311 short bias_value;
6312 int dce_mv, sta_mv;
Joonwoo Park03324832012-03-19 19:36:16 -07006313 struct wcd9xxx *core;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006314
6315 pr_debug("%s:\n", __func__);
6316
6317 delayed_work = to_delayed_work(work);
Joonwoo Park03324832012-03-19 19:36:16 -07006318 tabla = container_of(delayed_work, struct tabla_priv, mbhc_btn_dwork);
Joonwoo Park816b8e62012-01-23 16:03:21 -08006319 core = dev_get_drvdata(tabla->codec->dev->parent);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006320
6321 if (tabla) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006322 if (tabla->mbhc_cfg.button_jack) {
Joonwoo Park0976d012011-12-22 11:48:18 -08006323 bias_value = tabla_codec_read_sta_result(tabla->codec);
6324 sta_mv = tabla_codec_sta_dce_v(tabla->codec, 0,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306325 bias_value);
Joonwoo Park0976d012011-12-22 11:48:18 -08006326 bias_value = tabla_codec_read_dce_result(tabla->codec);
6327 dce_mv = tabla_codec_sta_dce_v(tabla->codec, 1,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306328 bias_value);
Joonwoo Park0976d012011-12-22 11:48:18 -08006329 pr_debug("%s: Reporting long button press event"
6330 " STA: %d, DCE: %d\n", __func__,
6331 sta_mv, dce_mv);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006332 tabla_snd_soc_jack_report(tabla,
6333 tabla->mbhc_cfg.button_jack,
Joonwoo Park03324832012-03-19 19:36:16 -07006334 tabla->buttons_pressed,
6335 tabla->buttons_pressed);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006336 }
6337 } else {
6338 pr_err("%s: Bad tabla private data\n", __func__);
6339 }
6340
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006341 pr_debug("%s: leave\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07006342 wcd9xxx_unlock_sleep(core);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006343}
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07006344
Joonwoo Parke067b232012-06-14 13:11:30 -07006345static u16 tabla_get_cfilt_reg(struct snd_soc_codec *codec, u8 cfilt)
6346{
6347 u16 reg;
6348
6349 switch (cfilt) {
6350 case TABLA_CFILT1_SEL:
6351 reg = TABLA_A_MICB_CFILT_1_CTL;
6352 break;
6353 case TABLA_CFILT2_SEL:
6354 reg = TABLA_A_MICB_CFILT_2_CTL;
6355 break;
6356 case TABLA_CFILT3_SEL:
6357 reg = TABLA_A_MICB_CFILT_3_CTL;
6358 break;
6359 default:
6360 BUG();
6361 }
6362 return reg;
6363}
6364
Joonwoo Park0976d012011-12-22 11:48:18 -08006365void tabla_mbhc_cal(struct snd_soc_codec *codec)
6366{
6367 struct tabla_priv *tabla;
6368 struct tabla_mbhc_btn_detect_cfg *btn_det;
Joonwoo Parke067b232012-06-14 13:11:30 -07006369 u8 cfilt_mode, micbias2_cfilt_mode, bg_mode;
Joonwoo Park0976d012011-12-22 11:48:18 -08006370 u8 ncic, nmeas, navg;
6371 u32 mclk_rate;
6372 u32 dce_wait, sta_wait;
6373 u8 *n_cic;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006374 void *calibration;
Joonwoo Parke067b232012-06-14 13:11:30 -07006375 u16 bias2_ctl;
Joonwoo Park0976d012011-12-22 11:48:18 -08006376
6377 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006378 calibration = tabla->mbhc_cfg.calibration;
6379
Joonwoo Parkf6574c72012-10-10 17:29:57 -07006380 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006381 tabla_turn_onoff_rel_detection(codec, false);
Joonwoo Park0976d012011-12-22 11:48:18 -08006382
6383 /* First compute the DCE / STA wait times
6384 * depending on tunable parameters.
6385 * The value is computed in microseconds
6386 */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006387 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08006388 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
Joonwoo Park107edf02012-01-11 11:42:24 -08006389 ncic = n_cic[tabla_codec_mclk_index(tabla)];
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006390 nmeas = TABLA_MBHC_CAL_BTN_DET_PTR(calibration)->n_meas;
6391 navg = TABLA_MBHC_CAL_GENERAL_PTR(calibration)->mbhc_navg;
6392 mclk_rate = tabla->mbhc_cfg.mclk_rate;
Joonwoo Park433149a2012-01-11 09:53:54 -08006393 dce_wait = (1000 * 512 * ncic * (nmeas + 1)) / (mclk_rate / 1000);
6394 sta_wait = (1000 * 128 * (navg + 1)) / (mclk_rate / 1000);
Joonwoo Park0976d012011-12-22 11:48:18 -08006395
6396 tabla->mbhc_data.t_dce = dce_wait;
6397 tabla->mbhc_data.t_sta = sta_wait;
6398
6399 /* LDOH and CFILT are already configured during pdata handling.
6400 * Only need to make sure CFILT and bandgap are in Fast mode.
6401 * Need to restore defaults once calculation is done.
6402 */
6403 cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl);
Joonwoo Parke067b232012-06-14 13:11:30 -07006404 micbias2_cfilt_mode =
6405 snd_soc_read(codec, tabla_get_cfilt_reg(codec,
6406 tabla->pdata->micbias.bias2_cfilt_sel));
6407 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40,
6408 TABLA_CFILT_FAST_MODE);
6409 snd_soc_update_bits(codec,
6410 tabla_get_cfilt_reg(codec,
6411 tabla->pdata->micbias.bias2_cfilt_sel),
6412 0x40, TABLA_CFILT_FAST_MODE);
6413
Joonwoo Park0976d012011-12-22 11:48:18 -08006414 bg_mode = snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02,
6415 0x02);
6416
6417 /* Micbias, CFILT, LDOH, MBHC MUX mode settings
6418 * to perform ADC calibration
6419 */
6420 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x60,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006421 tabla->mbhc_cfg.micbias << 5);
Joonwoo Park0976d012011-12-22 11:48:18 -08006422 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
6423 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x60, 0x60);
6424 snd_soc_write(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x78);
6425 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x04);
6426
Joonwoo Parke067b232012-06-14 13:11:30 -07006427 /* MICBIAS2 routing for calibration */
6428 bias2_ctl = snd_soc_read(codec, TABLA_A_MICB_2_CTL);
6429 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, TABLA_MICBIAS2);
6430 snd_soc_write(codec, TABLA_A_MICB_2_CTL,
6431 snd_soc_read(codec, tabla->mbhc_bias_regs.ctl_reg));
6432
Joonwoo Park0976d012011-12-22 11:48:18 -08006433 /* DCE measurement for 0 volts */
6434 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
6435 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
6436 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
Joonwoo Park0976d012011-12-22 11:48:18 -08006437 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81);
6438 usleep_range(100, 100);
6439 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
6440 usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce);
6441 tabla->mbhc_data.dce_z = tabla_codec_read_dce_result(codec);
6442
6443 /* DCE measurment for MB voltage */
6444 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
6445 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
6446 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82);
6447 usleep_range(100, 100);
6448 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
6449 usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce);
6450 tabla->mbhc_data.dce_mb = tabla_codec_read_dce_result(codec);
6451
6452 /* Sta measuremnt for 0 volts */
6453 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
6454 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
6455 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
Joonwoo Park0976d012011-12-22 11:48:18 -08006456 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81);
6457 usleep_range(100, 100);
6458 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
6459 usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta);
6460 tabla->mbhc_data.sta_z = tabla_codec_read_sta_result(codec);
6461
6462 /* STA Measurement for MB Voltage */
6463 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82);
6464 usleep_range(100, 100);
6465 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
6466 usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta);
6467 tabla->mbhc_data.sta_mb = tabla_codec_read_sta_result(codec);
6468
6469 /* Restore default settings. */
Joonwoo Parke067b232012-06-14 13:11:30 -07006470 snd_soc_write(codec, TABLA_A_MICB_2_CTL, bias2_ctl);
6471 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03,
6472 tabla->mbhc_cfg.micbias);
6473
Joonwoo Park0976d012011-12-22 11:48:18 -08006474 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00);
Joonwoo Parke067b232012-06-14 13:11:30 -07006475 snd_soc_update_bits(codec,
6476 tabla_get_cfilt_reg(codec,
6477 tabla->pdata->micbias.bias2_cfilt_sel), 0x40,
6478 micbias2_cfilt_mode);
Joonwoo Park0976d012011-12-22 11:48:18 -08006479 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40,
6480 cfilt_mode);
6481 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, bg_mode);
6482
6483 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
6484 usleep_range(100, 100);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006485
Joonwoo Parkf6574c72012-10-10 17:29:57 -07006486 wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006487 tabla_turn_onoff_rel_detection(codec, true);
Joonwoo Park0976d012011-12-22 11:48:18 -08006488}
6489
6490void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg* btn_det,
6491 const enum tabla_mbhc_btn_det_mem mem)
6492{
6493 void *ret = &btn_det->_v_btn_low;
6494
6495 switch (mem) {
6496 case TABLA_BTN_DET_GAIN:
6497 ret += sizeof(btn_det->_n_cic);
6498 case TABLA_BTN_DET_N_CIC:
6499 ret += sizeof(btn_det->_n_ready);
Joonwoo Parkc0672392012-01-11 11:03:14 -08006500 case TABLA_BTN_DET_N_READY:
Joonwoo Park0976d012011-12-22 11:48:18 -08006501 ret += sizeof(btn_det->_v_btn_high[0]) * btn_det->num_btn;
6502 case TABLA_BTN_DET_V_BTN_HIGH:
6503 ret += sizeof(btn_det->_v_btn_low[0]) * btn_det->num_btn;
6504 case TABLA_BTN_DET_V_BTN_LOW:
6505 /* do nothing */
6506 break;
6507 default:
6508 ret = NULL;
6509 }
6510
6511 return ret;
6512}
6513
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006514static s16 tabla_scale_v_micb_vddio(struct tabla_priv *tabla, int v,
6515 bool tovddio)
6516{
6517 int r;
6518 int vddio_k, mb_k;
6519 vddio_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v,
6520 VDDIO_MICBIAS_MV);
6521 mb_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v,
6522 tabla->mbhc_data.micb_mv);
6523 if (tovddio)
6524 r = v * vddio_k / mb_k;
6525 else
6526 r = v * mb_k / vddio_k;
6527 return r;
6528}
6529
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006530static void tabla_mbhc_calc_rel_thres(struct snd_soc_codec *codec, s16 mv)
6531{
6532 s16 deltamv;
6533 struct tabla_priv *tabla;
6534 struct tabla_mbhc_btn_detect_cfg *btn_det;
6535
6536 tabla = snd_soc_codec_get_drvdata(codec);
6537 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
6538
6539 tabla->mbhc_data.v_b1_h =
6540 tabla_codec_v_sta_dce(codec, DCE,
6541 mv + btn_det->v_btn_press_delta_cic);
6542
6543 tabla->mbhc_data.v_brh = tabla->mbhc_data.v_b1_h;
6544
6545 tabla->mbhc_data.v_brl = TABLA_MBHC_BUTTON_MIN;
6546
6547 deltamv = mv + btn_det->v_btn_press_delta_sta;
6548 tabla->mbhc_data.v_b1_hu = tabla_codec_v_sta_dce(codec, STA, deltamv);
6549
6550 deltamv = mv + btn_det->v_btn_press_delta_cic;
6551 tabla->mbhc_data.v_b1_huc = tabla_codec_v_sta_dce(codec, DCE, deltamv);
6552}
6553
6554static void tabla_mbhc_set_rel_thres(struct snd_soc_codec *codec, s16 mv)
6555{
6556 tabla_mbhc_calc_rel_thres(codec, mv);
6557 tabla_codec_calibrate_rel(codec);
6558}
6559
6560static s16 tabla_mbhc_highest_btn_mv(struct snd_soc_codec *codec)
6561{
6562 struct tabla_priv *tabla;
6563 struct tabla_mbhc_btn_detect_cfg *btn_det;
6564 u16 *btn_high;
6565
6566 tabla = snd_soc_codec_get_drvdata(codec);
6567 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
6568 btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_HIGH);
6569
6570 return btn_high[btn_det->num_btn - 1];
6571}
6572
Joonwoo Park0976d012011-12-22 11:48:18 -08006573static void tabla_mbhc_calc_thres(struct snd_soc_codec *codec)
6574{
6575 struct tabla_priv *tabla;
Joonwoo Park0976d012011-12-22 11:48:18 -08006576 struct tabla_mbhc_btn_detect_cfg *btn_det;
6577 struct tabla_mbhc_plug_type_cfg *plug_type;
Joonwoo Parkc0672392012-01-11 11:03:14 -08006578 u8 *n_ready;
Joonwoo Park0976d012011-12-22 11:48:18 -08006579
6580 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006581 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
6582 plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08006583
Joonwoo Parkc0672392012-01-11 11:03:14 -08006584 n_ready = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_READY);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006585 if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) {
Joonwoo Park03324832012-03-19 19:36:16 -07006586 tabla->mbhc_data.npoll = 4;
Joonwoo Park0976d012011-12-22 11:48:18 -08006587 tabla->mbhc_data.nbounce_wait = 30;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006588 } else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) {
Joonwoo Park0976d012011-12-22 11:48:18 -08006589 tabla->mbhc_data.npoll = 7;
6590 tabla->mbhc_data.nbounce_wait = 23;
Joonwoo Parkc0672392012-01-11 11:03:14 -08006591 }
Joonwoo Park0976d012011-12-22 11:48:18 -08006592
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006593 tabla->mbhc_data.t_sta_dce = ((1000 * 256) /
6594 (tabla->mbhc_cfg.mclk_rate / 1000) *
Joonwoo Parkc0672392012-01-11 11:03:14 -08006595 n_ready[tabla_codec_mclk_index(tabla)]) +
6596 10;
Joonwoo Park0976d012011-12-22 11:48:18 -08006597 tabla->mbhc_data.v_ins_hu =
6598 tabla_codec_v_sta_dce(codec, STA, plug_type->v_hs_max);
6599 tabla->mbhc_data.v_ins_h =
6600 tabla_codec_v_sta_dce(codec, DCE, plug_type->v_hs_max);
6601
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006602 tabla->mbhc_data.v_inval_ins_low = TABLA_MBHC_FAKE_INSERT_LOW;
6603 if (tabla->mbhc_cfg.gpio)
6604 tabla->mbhc_data.v_inval_ins_high =
6605 TABLA_MBHC_FAKE_INSERT_HIGH;
6606 else
6607 tabla->mbhc_data.v_inval_ins_high =
6608 TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO;
6609
6610 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
6611 tabla->mbhc_data.adj_v_hs_max =
6612 tabla_scale_v_micb_vddio(tabla, plug_type->v_hs_max, true);
6613 tabla->mbhc_data.adj_v_ins_hu =
6614 tabla_codec_v_sta_dce(codec, STA,
6615 tabla->mbhc_data.adj_v_hs_max);
6616 tabla->mbhc_data.adj_v_ins_h =
6617 tabla_codec_v_sta_dce(codec, DCE,
6618 tabla->mbhc_data.adj_v_hs_max);
6619 tabla->mbhc_data.v_inval_ins_low =
6620 tabla_scale_v_micb_vddio(tabla,
6621 tabla->mbhc_data.v_inval_ins_low,
6622 false);
6623 tabla->mbhc_data.v_inval_ins_high =
6624 tabla_scale_v_micb_vddio(tabla,
6625 tabla->mbhc_data.v_inval_ins_high,
6626 false);
6627 }
6628
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006629 tabla_mbhc_calc_rel_thres(codec, tabla_mbhc_highest_btn_mv(codec));
Joonwoo Park0976d012011-12-22 11:48:18 -08006630
6631 tabla->mbhc_data.v_no_mic =
6632 tabla_codec_v_sta_dce(codec, STA, plug_type->v_no_mic);
6633}
6634
6635void tabla_mbhc_init(struct snd_soc_codec *codec)
6636{
6637 struct tabla_priv *tabla;
6638 struct tabla_mbhc_general_cfg *generic;
6639 struct tabla_mbhc_btn_detect_cfg *btn_det;
6640 int n;
Joonwoo Park0976d012011-12-22 11:48:18 -08006641 u8 *n_cic, *gain;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306642 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Joonwoo Park0976d012011-12-22 11:48:18 -08006643
6644 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006645 generic = TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
6646 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08006647
Joonwoo Park0976d012011-12-22 11:48:18 -08006648 for (n = 0; n < 8; n++) {
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08006649 if ((!TABLA_IS_1_X(tabla_core->version)) || n != 7) {
Joonwoo Park0976d012011-12-22 11:48:18 -08006650 snd_soc_update_bits(codec,
6651 TABLA_A_CDC_MBHC_FEATURE_B1_CFG,
6652 0x07, n);
6653 snd_soc_write(codec, TABLA_A_CDC_MBHC_FEATURE_B2_CFG,
6654 btn_det->c[n]);
6655 }
6656 }
6657 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x07,
6658 btn_det->nc);
6659
6660 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
6661 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL, 0xFF,
Joonwoo Park107edf02012-01-11 11:42:24 -08006662 n_cic[tabla_codec_mclk_index(tabla)]);
Joonwoo Park0976d012011-12-22 11:48:18 -08006663
6664 gain = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_GAIN);
Joonwoo Park107edf02012-01-11 11:42:24 -08006665 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x78,
6666 gain[tabla_codec_mclk_index(tabla)] << 3);
Joonwoo Park0976d012011-12-22 11:48:18 -08006667
6668 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x70,
6669 generic->mbhc_nsa << 4);
6670
6671 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x0F,
6672 btn_det->n_meas);
6673
6674 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B5_CTL, generic->mbhc_navg);
6675
6676 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x80, 0x80);
6677
6678 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x78,
6679 btn_det->mbhc_nsc << 3);
6680
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08006681 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x03,
6682 TABLA_MICBIAS2);
Joonwoo Park0976d012011-12-22 11:48:18 -08006683
6684 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, 0x02);
Joonwoo Park03324832012-03-19 19:36:16 -07006685
6686 snd_soc_update_bits(codec, TABLA_A_MBHC_SCALING_MUX_2, 0xF0, 0xF0);
Joonwoo Parke067b232012-06-14 13:11:30 -07006687
6688 /* override mbhc's micbias */
6689 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03,
6690 tabla->mbhc_cfg.micbias);
Joonwoo Park0976d012011-12-22 11:48:18 -08006691}
6692
Patrick Lai64b43262011-12-06 17:29:15 -08006693static bool tabla_mbhc_fw_validate(const struct firmware *fw)
6694{
6695 u32 cfg_offset;
6696 struct tabla_mbhc_imped_detect_cfg *imped_cfg;
6697 struct tabla_mbhc_btn_detect_cfg *btn_cfg;
6698
6699 if (fw->size < TABLA_MBHC_CAL_MIN_SIZE)
6700 return false;
6701
6702 /* previous check guarantees that there is enough fw data up
6703 * to num_btn
6704 */
6705 btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(fw->data);
6706 cfg_offset = (u32) ((void *) btn_cfg - (void *) fw->data);
6707 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_BTN_SZ(btn_cfg)))
6708 return false;
6709
6710 /* previous check guarantees that there is enough fw data up
6711 * to start of impedance detection configuration
6712 */
6713 imped_cfg = TABLA_MBHC_CAL_IMPED_DET_PTR(fw->data);
6714 cfg_offset = (u32) ((void *) imped_cfg - (void *) fw->data);
6715
6716 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_MIN_SZ))
6717 return false;
6718
6719 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_SZ(imped_cfg)))
6720 return false;
6721
6722 return true;
6723}
Joonwoo Park03324832012-03-19 19:36:16 -07006724
Joonwoo Parkfee17432012-04-16 16:33:55 -07006725/* called under codec_resource_lock acquisition */
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006726static int tabla_determine_button(const struct tabla_priv *priv,
Joonwoo Parkfee17432012-04-16 16:33:55 -07006727 const s32 micmv)
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006728{
6729 s16 *v_btn_low, *v_btn_high;
6730 struct tabla_mbhc_btn_detect_cfg *btn_det;
6731 int i, btn = -1;
6732
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006733 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006734 v_btn_low = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_LOW);
6735 v_btn_high = tabla_mbhc_cal_btn_det_mp(btn_det,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306736 TABLA_BTN_DET_V_BTN_HIGH);
Joonwoo Parkfee17432012-04-16 16:33:55 -07006737
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006738 for (i = 0; i < btn_det->num_btn; i++) {
Joonwoo Parkfee17432012-04-16 16:33:55 -07006739 if ((v_btn_low[i] <= micmv) && (v_btn_high[i] >= micmv)) {
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006740 btn = i;
6741 break;
6742 }
6743 }
6744
6745 if (btn == -1)
6746 pr_debug("%s: couldn't find button number for mic mv %d\n",
Joonwoo Parkfee17432012-04-16 16:33:55 -07006747 __func__, micmv);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006748
6749 return btn;
6750}
6751
6752static int tabla_get_button_mask(const int btn)
6753{
6754 int mask = 0;
6755 switch (btn) {
6756 case 0:
6757 mask = SND_JACK_BTN_0;
6758 break;
6759 case 1:
6760 mask = SND_JACK_BTN_1;
6761 break;
6762 case 2:
6763 mask = SND_JACK_BTN_2;
6764 break;
6765 case 3:
6766 mask = SND_JACK_BTN_3;
6767 break;
6768 case 4:
6769 mask = SND_JACK_BTN_4;
6770 break;
6771 case 5:
6772 mask = SND_JACK_BTN_5;
6773 break;
6774 case 6:
6775 mask = SND_JACK_BTN_6;
6776 break;
6777 case 7:
6778 mask = SND_JACK_BTN_7;
6779 break;
6780 }
6781 return mask;
6782}
6783
Bradley Rubincb1e2732011-06-23 16:49:20 -07006784static irqreturn_t tabla_dce_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006785{
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006786 int i, mask;
Joonwoo Parkfee17432012-04-16 16:33:55 -07006787 short dce, sta;
Joonwoo Park12334832012-07-23 19:27:52 -07006788 s32 mv, mv_s, stamv, stamv_s;
Joonwoo Parkfee17432012-04-16 16:33:55 -07006789 bool vddio;
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006790 u16 *btn_high;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006791 int btn = -1, meas = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006792 struct tabla_priv *priv = data;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006793 const struct tabla_mbhc_btn_detect_cfg *d =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006794 TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006795 short btnmeas[d->n_btn_meas + 1];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006796 struct snd_soc_codec *codec = priv->codec;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306797 struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent);
Joonwoo Park03324832012-03-19 19:36:16 -07006798 int n_btn_meas = d->n_btn_meas;
6799 u8 mbhc_status = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_STATUS) & 0x3E;
Bradley Rubincb1e2732011-06-23 16:49:20 -07006800
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006801 pr_debug("%s: enter\n", __func__);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006802
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006803 btn_high = tabla_mbhc_cal_btn_det_mp(d, TABLA_BTN_DET_V_BTN_HIGH);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006804 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
6805 if (priv->mbhc_state == MBHC_STATE_POTENTIAL_RECOVERY) {
6806 pr_debug("%s: mbhc is being recovered, skip button press\n",
6807 __func__);
6808 goto done;
6809 }
6810
6811 priv->mbhc_state = MBHC_STATE_POTENTIAL;
6812
6813 if (!priv->mbhc_polling_active) {
6814 pr_warn("%s: mbhc polling is not active, skip button press\n",
6815 __func__);
6816 goto done;
6817 }
Joonwoo Park03324832012-03-19 19:36:16 -07006818
6819 dce = tabla_codec_read_dce_result(codec);
6820 mv = tabla_codec_sta_dce_v(codec, 1, dce);
6821
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006822 /* If GPIO interrupt already kicked in, ignore button press */
6823 if (priv->in_gpio_handler) {
6824 pr_debug("%s: GPIO State Changed, ignore button press\n",
6825 __func__);
6826 btn = -1;
6827 goto done;
6828 }
Simmi Pateriya71d63872012-11-08 01:06:30 +05306829 vddio = !priv->mbhc_cfg.micbias_always_on &&
6830 (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
Joonwoo Parkfee17432012-04-16 16:33:55 -07006831 priv->mbhc_micbias_switched);
6832 mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv;
6833
Joonwoo Park03324832012-03-19 19:36:16 -07006834 if (mbhc_status != TABLA_MBHC_STATUS_REL_DETECTION) {
6835 if (priv->mbhc_last_resume &&
6836 !time_after(jiffies, priv->mbhc_last_resume + HZ)) {
6837 pr_debug("%s: Button is already released shortly after "
6838 "resume\n", __func__);
6839 n_btn_meas = 0;
Joonwoo Park03324832012-03-19 19:36:16 -07006840 }
6841 }
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07006842
Joonwoo Park12334832012-07-23 19:27:52 -07006843 /* save hw dce */
Joonwoo Parkfee17432012-04-16 16:33:55 -07006844 btnmeas[meas++] = tabla_determine_button(priv, mv_s);
Joonwoo Park12334832012-07-23 19:27:52 -07006845 pr_debug("%s: meas HW - DCE %x,%d,%d button %d\n", __func__,
6846 dce, mv, mv_s, btnmeas[0]);
6847 if (n_btn_meas == 0) {
6848 sta = tabla_codec_read_sta_result(codec);
6849 stamv_s = stamv = tabla_codec_sta_dce_v(codec, 0, sta);
6850 if (vddio)
6851 stamv_s = tabla_scale_v_micb_vddio(priv, stamv, false);
6852 btn = tabla_determine_button(priv, stamv_s);
6853 pr_debug("%s: meas HW - STA %x,%d,%d button %d\n", __func__,
6854 sta, stamv, stamv_s, btn);
6855 BUG_ON(meas != 1);
6856 if (btnmeas[0] != btn)
6857 btn = -1;
6858 }
6859
6860 /* determine pressed button */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006861 for (; ((d->n_btn_meas) && (meas < (d->n_btn_meas + 1))); meas++) {
Joonwoo Parkfee17432012-04-16 16:33:55 -07006862 dce = tabla_codec_sta_dce(codec, 1, false);
6863 mv = tabla_codec_sta_dce_v(codec, 1, dce);
6864 mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv;
6865
6866 btnmeas[meas] = tabla_determine_button(priv, mv_s);
Joonwoo Park12334832012-07-23 19:27:52 -07006867 pr_debug("%s: meas %d - DCE %x,%d,%d button %d\n",
Joonwoo Parkfee17432012-04-16 16:33:55 -07006868 __func__, meas, dce, mv, mv_s, btnmeas[meas]);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006869 /* if large enough measurements are collected,
6870 * start to check if last all n_btn_con measurements were
6871 * in same button low/high range */
6872 if (meas + 1 >= d->n_btn_con) {
6873 for (i = 0; i < d->n_btn_con; i++)
6874 if ((btnmeas[meas] < 0) ||
6875 (btnmeas[meas] != btnmeas[meas - i]))
6876 break;
6877 if (i == d->n_btn_con) {
6878 /* button pressed */
6879 btn = btnmeas[meas];
6880 break;
Joonwoo Park03324832012-03-19 19:36:16 -07006881 } else if ((n_btn_meas - meas) < (d->n_btn_con - 1)) {
6882 /* if left measurements are less than n_btn_con,
6883 * it's impossible to find button number */
6884 break;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006885 }
6886 }
Joonwoo Park8b1f0982011-12-08 17:12:45 -08006887 }
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006888
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006889 if (btn >= 0) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006890 if (priv->in_gpio_handler) {
6891 pr_debug("%s: GPIO already triggered, ignore button "
6892 "press\n", __func__);
6893 goto done;
6894 }
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006895 /* narrow down release threshold */
6896 tabla_mbhc_set_rel_thres(codec, btn_high[btn]);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006897 mask = tabla_get_button_mask(btn);
6898 priv->buttons_pressed |= mask;
Joonwoo Park03324832012-03-19 19:36:16 -07006899 wcd9xxx_lock_sleep(core);
6900 if (schedule_delayed_work(&priv->mbhc_btn_dwork,
6901 msecs_to_jiffies(400)) == 0) {
6902 WARN(1, "Button pressed twice without release"
6903 "event\n");
6904 wcd9xxx_unlock_sleep(core);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006905 }
Joonwoo Park816b8e62012-01-23 16:03:21 -08006906 } else {
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006907 pr_debug("%s: bogus button press, too short press?\n",
6908 __func__);
Joonwoo Park816b8e62012-01-23 16:03:21 -08006909 }
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006910
Joonwoo Park03324832012-03-19 19:36:16 -07006911 done:
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006912 pr_debug("%s: leave\n", __func__);
6913 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006914 return IRQ_HANDLED;
6915}
6916
Joonwoo Park03324832012-03-19 19:36:16 -07006917static int tabla_is_fake_press(struct tabla_priv *priv)
6918{
6919 int i;
6920 int r = 0;
6921 struct snd_soc_codec *codec = priv->codec;
6922 const int dces = MBHC_NUM_DCE_PLUG_DETECT;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006923 s16 mb_v, v_ins_hu, v_ins_h;
6924
6925 v_ins_hu = tabla_get_current_v_ins(priv, true);
6926 v_ins_h = tabla_get_current_v_ins(priv, false);
Joonwoo Park03324832012-03-19 19:36:16 -07006927
6928 for (i = 0; i < dces; i++) {
6929 usleep_range(10000, 10000);
6930 if (i == 0) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006931 mb_v = tabla_codec_sta_dce(codec, 0, true);
Joonwoo Park03324832012-03-19 19:36:16 -07006932 pr_debug("%s: STA[0]: %d,%d\n", __func__, mb_v,
6933 tabla_codec_sta_dce_v(codec, 0, mb_v));
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006934 if (mb_v < (s16)priv->mbhc_data.v_b1_hu ||
6935 mb_v > v_ins_hu) {
Joonwoo Park03324832012-03-19 19:36:16 -07006936 r = 1;
6937 break;
6938 }
6939 } else {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006940 mb_v = tabla_codec_sta_dce(codec, 1, true);
Joonwoo Park03324832012-03-19 19:36:16 -07006941 pr_debug("%s: DCE[%d]: %d,%d\n", __func__, i, mb_v,
6942 tabla_codec_sta_dce_v(codec, 1, mb_v));
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006943 if (mb_v < (s16)priv->mbhc_data.v_b1_h ||
6944 mb_v > v_ins_h) {
Joonwoo Park03324832012-03-19 19:36:16 -07006945 r = 1;
6946 break;
6947 }
6948 }
6949 }
6950
6951 return r;
6952}
6953
Bradley Rubincb1e2732011-06-23 16:49:20 -07006954static irqreturn_t tabla_release_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006955{
Joonwoo Parke5d3aa92012-01-11 14:47:15 -08006956 int ret;
Joonwoo Park816b8e62012-01-23 16:03:21 -08006957 struct tabla_priv *priv = data;
6958 struct snd_soc_codec *codec = priv->codec;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006959
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006960 pr_debug("%s: enter\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07006961
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006962 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
6963 priv->mbhc_state = MBHC_STATE_RELEASE;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006964
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006965 tabla_codec_drive_v_to_micbias(codec, 10000);
6966
Joonwoo Park03324832012-03-19 19:36:16 -07006967 if (priv->buttons_pressed & TABLA_JACK_BUTTON_MASK) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006968 ret = tabla_cancel_btn_work(priv);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006969 if (ret == 0) {
Joonwoo Park03324832012-03-19 19:36:16 -07006970 pr_debug("%s: Reporting long button release event\n",
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006971 __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006972 if (priv->mbhc_cfg.button_jack)
Joonwoo Park8b1f0982011-12-08 17:12:45 -08006973 tabla_snd_soc_jack_report(priv,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006974 priv->mbhc_cfg.button_jack, 0,
6975 priv->buttons_pressed);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006976 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07006977 if (tabla_is_fake_press(priv)) {
6978 pr_debug("%s: Fake button press interrupt\n",
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006979 __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006980 } else if (priv->mbhc_cfg.button_jack) {
6981 if (priv->in_gpio_handler) {
6982 pr_debug("%s: GPIO kicked in, ignore\n",
6983 __func__);
6984 } else {
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006985 pr_debug("%s: Reporting short button "
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006986 "press and release\n",
6987 __func__);
6988 tabla_snd_soc_jack_report(priv,
6989 priv->mbhc_cfg.button_jack,
6990 priv->buttons_pressed,
6991 priv->buttons_pressed);
6992 tabla_snd_soc_jack_report(priv,
6993 priv->mbhc_cfg.button_jack, 0,
6994 priv->buttons_pressed);
6995 }
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006996 }
6997 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006998
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006999 priv->buttons_pressed &= ~TABLA_JACK_BUTTON_MASK;
7000 }
7001
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07007002 /* revert narrowed release threshold */
7003 tabla_mbhc_calc_rel_thres(codec, tabla_mbhc_highest_btn_mv(codec));
Joonwoo Park03324832012-03-19 19:36:16 -07007004 tabla_codec_calibrate_hs_polling(codec);
7005
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007006 if (priv->mbhc_cfg.gpio)
7007 msleep(TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS);
Joonwoo Park03324832012-03-19 19:36:16 -07007008
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007009 tabla_codec_start_hs_polling(codec);
7010
7011 pr_debug("%s: leave\n", __func__);
7012 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007013 return IRQ_HANDLED;
7014}
7015
Bradley Rubincb1e2732011-06-23 16:49:20 -07007016static void tabla_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec)
7017{
7018 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park0976d012011-12-22 11:48:18 -08007019 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007020 TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
Bradley Rubincb1e2732011-06-23 16:49:20 -07007021
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07007022 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07007023 tabla_codec_enable_config_mode(codec, 1);
7024
7025 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
7026 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x6, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07007027
Joonwoo Park0976d012011-12-22 11:48:18 -08007028 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00);
7029
7030 usleep_range(generic->t_shutdown_plug_rem,
7031 generic->t_shutdown_plug_rem);
Bradley Rubincb1e2732011-06-23 16:49:20 -07007032
7033 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0xA, 0x8);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07007034 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07007035 tabla_codec_enable_config_mode(codec, 0);
7036
7037 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x00);
7038}
7039
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007040static void tabla_codec_cleanup_hs_polling(struct snd_soc_codec *codec)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007041{
7042 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07007043
7044 tabla_codec_shutdown_hs_removal_detect(codec);
7045
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07007046 if (!tabla->mclk_enabled) {
Asish Bhattacharya486745a2012-01-20 06:41:53 +05307047 tabla_codec_disable_clock_block(codec);
7048 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007049 }
7050
7051 tabla->mbhc_polling_active = false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007052 tabla->mbhc_state = MBHC_STATE_NONE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007053}
7054
Patrick Lai49efeac2011-11-03 11:01:12 -07007055static irqreturn_t tabla_hphl_ocp_irq(int irq, void *data)
7056{
7057 struct tabla_priv *tabla = data;
7058 struct snd_soc_codec *codec;
7059
7060 pr_info("%s: received HPHL OCP irq\n", __func__);
7061
7062 if (tabla) {
7063 codec = tabla->codec;
Patrick Laic2d833d2012-07-06 22:42:52 -07007064 if ((tabla->hphlocp_cnt < TABLA_OCP_ATTEMPT) &&
7065 (!tabla->hphrocp_cnt)) {
Patrick Laic7cae882011-11-18 11:52:49 -08007066 pr_info("%s: retry\n", __func__);
Patrick Laic2d833d2012-07-06 22:42:52 -07007067 tabla->hphlocp_cnt++;
Patrick Laic7cae882011-11-18 11:52:49 -08007068 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
7069 0x00);
7070 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
7071 0x10);
7072 } else {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307073 wcd9xxx_disable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007074 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Patrick Laic7cae882011-11-18 11:52:49 -08007075 tabla->hph_status |= SND_JACK_OC_HPHL;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007076 if (tabla->mbhc_cfg.headset_jack)
Patrick Laic7cae882011-11-18 11:52:49 -08007077 tabla_snd_soc_jack_report(tabla,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007078 tabla->mbhc_cfg.headset_jack,
7079 tabla->hph_status,
7080 TABLA_JACK_MASK);
Patrick Lai49efeac2011-11-03 11:01:12 -07007081 }
7082 } else {
7083 pr_err("%s: Bad tabla private data\n", __func__);
7084 }
7085
7086 return IRQ_HANDLED;
7087}
7088
7089static irqreturn_t tabla_hphr_ocp_irq(int irq, void *data)
7090{
7091 struct tabla_priv *tabla = data;
7092 struct snd_soc_codec *codec;
7093
7094 pr_info("%s: received HPHR OCP irq\n", __func__);
7095
7096 if (tabla) {
7097 codec = tabla->codec;
Patrick Laic2d833d2012-07-06 22:42:52 -07007098 if ((tabla->hphrocp_cnt < TABLA_OCP_ATTEMPT) &&
7099 (!tabla->hphlocp_cnt)) {
Patrick Laic7cae882011-11-18 11:52:49 -08007100 pr_info("%s: retry\n", __func__);
Patrick Laic2d833d2012-07-06 22:42:52 -07007101 tabla->hphrocp_cnt++;
Patrick Laic7cae882011-11-18 11:52:49 -08007102 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
7103 0x00);
7104 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
7105 0x10);
7106 } else {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307107 wcd9xxx_disable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007108 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Patrick Laic7cae882011-11-18 11:52:49 -08007109 tabla->hph_status |= SND_JACK_OC_HPHR;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007110 if (tabla->mbhc_cfg.headset_jack)
Patrick Laic7cae882011-11-18 11:52:49 -08007111 tabla_snd_soc_jack_report(tabla,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007112 tabla->mbhc_cfg.headset_jack,
7113 tabla->hph_status,
7114 TABLA_JACK_MASK);
Patrick Lai49efeac2011-11-03 11:01:12 -07007115 }
7116 } else {
7117 pr_err("%s: Bad tabla private data\n", __func__);
7118 }
7119
7120 return IRQ_HANDLED;
7121}
7122
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007123static bool tabla_is_inval_ins_range(struct snd_soc_codec *codec,
7124 s32 mic_volt, bool highhph, bool *highv)
Joonwoo Park03324832012-03-19 19:36:16 -07007125{
7126 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007127 bool invalid = false;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007128 s16 v_hs_max;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007129
7130 /* Perform this check only when the high voltage headphone
7131 * needs to be considered as invalid
7132 */
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007133 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007134 *highv = mic_volt > v_hs_max;
7135 if (!highhph && *highv)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007136 invalid = true;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007137 else if (mic_volt < tabla->mbhc_data.v_inval_ins_high &&
7138 (mic_volt > tabla->mbhc_data.v_inval_ins_low))
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007139 invalid = true;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007140
7141 return invalid;
7142}
7143
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007144static bool tabla_is_inval_ins_delta(struct snd_soc_codec *codec,
7145 int mic_volt, int mic_volt_prev,
7146 int threshold)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007147{
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007148 return abs(mic_volt - mic_volt_prev) > threshold;
Joonwoo Park03324832012-03-19 19:36:16 -07007149}
7150
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007151/* called under codec_resource_lock acquisition */
7152void tabla_find_plug_and_report(struct snd_soc_codec *codec,
7153 enum tabla_mbhc_plug_type plug_type)
Joonwoo Park03324832012-03-19 19:36:16 -07007154{
7155 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007156
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007157 pr_debug("%s: enter current_plug(%d) new_plug(%d)\n",
7158 __func__, tabla->current_plug, plug_type);
7159
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007160 if (plug_type == PLUG_TYPE_HEADPHONE &&
7161 tabla->current_plug == PLUG_TYPE_NONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007162 /* Nothing was reported previously
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007163 * report a headphone or unsupported
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007164 */
7165 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
7166 tabla_codec_cleanup_hs_polling(codec);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007167 } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) {
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007168 if (!tabla->mbhc_cfg.detect_extn_cable) {
7169 if (tabla->current_plug == PLUG_TYPE_HEADSET)
7170 tabla_codec_report_plug(codec, 0,
7171 SND_JACK_HEADSET);
7172 else if (tabla->current_plug == PLUG_TYPE_HEADPHONE)
7173 tabla_codec_report_plug(codec, 0,
7174 SND_JACK_HEADPHONE);
7175 }
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007176 tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED);
7177 tabla_codec_cleanup_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007178 } else if (plug_type == PLUG_TYPE_HEADSET) {
7179 /* If Headphone was reported previously, this will
7180 * only report the mic line
7181 */
7182 tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET);
Simmi Pateriya21375012012-11-26 23:06:01 +05307183 if (!tabla->mbhc_micbias_switched &&
7184 tabla_is_hph_pa_on(codec)) {
7185 /*If the headphone path is on, switch the micbias
7186 to VDDIO to avoid noise due to button polling */
7187 tabla_codec_switch_micbias(codec, 1);
7188 pr_debug("%s: HPH path is still up\n", __func__);
7189 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007190 msleep(100);
7191 tabla_codec_start_hs_polling(codec);
7192 } else if (plug_type == PLUG_TYPE_HIGH_HPH) {
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007193 if (tabla->mbhc_cfg.detect_extn_cable) {
7194 /* High impedance device found. Report as LINEOUT*/
7195 tabla_codec_report_plug(codec, 1, SND_JACK_LINEOUT);
7196 tabla_codec_cleanup_hs_polling(codec);
7197 pr_debug("%s: setup mic trigger for further detection\n",
7198 __func__);
7199 tabla->lpi_enabled = true;
7200 /*
7201 * Do not enable HPHL trigger. If playback is active,
7202 * it might lead to continuous false HPHL triggers
7203 */
7204 tabla_codec_enable_hs_detect(codec, 1,
7205 MBHC_USE_MB_TRIGGER,
7206 false);
7207 } else {
7208 if (tabla->current_plug == PLUG_TYPE_NONE)
7209 tabla_codec_report_plug(codec, 1,
7210 SND_JACK_HEADPHONE);
7211 tabla_codec_cleanup_hs_polling(codec);
7212 pr_debug("setup mic trigger for further detection\n");
7213 tabla->lpi_enabled = true;
7214 tabla_codec_enable_hs_detect(codec, 1,
7215 MBHC_USE_MB_TRIGGER |
7216 MBHC_USE_HPHL_TRIGGER,
7217 false);
7218 }
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007219 } else {
7220 WARN(1, "Unexpected current plug_type %d, plug_type %d\n",
7221 tabla->current_plug, plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007222 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007223 pr_debug("%s: leave\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007224}
7225
7226/* should be called under interrupt context that hold suspend */
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007227static void tabla_schedule_hs_detect_plug(struct tabla_priv *tabla,
7228 struct work_struct *correct_plug_work)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007229{
7230 pr_debug("%s: scheduling tabla_hs_correct_gpio_plug\n", __func__);
7231 tabla->hs_detect_work_stop = false;
7232 wcd9xxx_lock_sleep(tabla->codec->control_data);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007233 schedule_work(correct_plug_work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007234}
7235
7236/* called under codec_resource_lock acquisition */
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007237static void tabla_cancel_hs_detect_plug(struct tabla_priv *tabla,
7238 struct work_struct *correct_plug_work)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007239{
7240 pr_debug("%s: canceling hs_correct_plug_work\n", __func__);
7241 tabla->hs_detect_work_stop = true;
7242 wmb();
7243 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007244 if (cancel_work_sync(correct_plug_work)) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007245 pr_debug("%s: hs_correct_plug_work is canceled\n", __func__);
7246 wcd9xxx_unlock_sleep(tabla->codec->control_data);
7247 }
7248 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
7249}
7250
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007251static bool tabla_hs_gpio_level_remove(struct tabla_priv *tabla)
7252{
7253 return (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) !=
7254 tabla->mbhc_cfg.gpio_level_insert);
7255}
7256
Joonwoo Park41956722012-04-18 13:13:07 -07007257/* called under codec_resource_lock acquisition */
7258static void tabla_codec_hphr_gnd_switch(struct snd_soc_codec *codec, bool on)
7259{
7260 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, on);
7261 if (on)
7262 usleep_range(5000, 5000);
7263}
7264
Simmi Pateriyad60186a2012-11-27 13:50:11 +05307265
7266static void tabla_codec_onoff_vddio_switch(struct snd_soc_codec *codec, bool on)
7267{
7268 bool override;
7269 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
7270
7271 pr_debug("%s: enter\n", __func__);
7272 if (on) {
7273 override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04;
7274 if (!override)
7275 tabla_turn_onoff_override(codec, true);
7276
7277 /* enable the vddio switch */
7278 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
7279 0x91, 0x81);
7280
7281 /* deroute the override from MicBias2 to MicBias4 */
7282 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC,
7283 0x03, 0x03);
7284
7285 usleep_range(MBHC_VDDIO_SWITCH_WAIT_MS * 1000,
7286 MBHC_VDDIO_SWITCH_WAIT_MS * 1000);
7287
7288 if (!override)
7289 tabla_turn_onoff_override(codec, false);
7290 tabla->mbhc_micbias_switched = true;
7291 pr_debug("%s: VDDIO switch enabled\n", __func__);
7292
7293 } else {
7294
7295 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
7296 0x91, 0x00);
7297
7298 /* reroute the override to MicBias2 */
7299 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC,
7300 0x03, 0x01);
7301
7302 tabla->mbhc_micbias_switched = false;
7303 pr_debug("%s: VDDIO switch disabled\n", __func__);
7304 }
7305}
7306
Joonwoo Park41956722012-04-18 13:13:07 -07007307/* called under codec_resource_lock acquisition and mbhc override = 1 */
7308static enum tabla_mbhc_plug_type
7309tabla_codec_get_plug_type(struct snd_soc_codec *codec, bool highhph)
7310{
7311 int i;
7312 bool gndswitch, vddioswitch;
7313 int scaled;
7314 struct tabla_mbhc_plug_type_cfg *plug_type_ptr;
7315 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Simmi Pateriya71d63872012-11-08 01:06:30 +05307316 const bool vddio = !tabla->mbhc_cfg.micbias_always_on &&
7317 (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV);
7318 int num_det = (MBHC_NUM_DCE_PLUG_DETECT + vddio);
Joonwoo Park41956722012-04-18 13:13:07 -07007319 enum tabla_mbhc_plug_type plug_type[num_det];
7320 s16 mb_v[num_det];
7321 s32 mic_mv[num_det];
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007322 bool inval;
Ravi Kumar Alamanda1c713b22012-09-27 17:14:27 -07007323 bool highdelta = false;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007324 bool ahighv = false, highv;
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07007325 bool gndmicswapped = false;
Joonwoo Park41956722012-04-18 13:13:07 -07007326
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007327 pr_debug("%s: enter\n", __func__);
7328
Joonwoo Park41956722012-04-18 13:13:07 -07007329 /* make sure override is on */
7330 WARN_ON(!(snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04));
7331
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007332 /* GND and MIC swap detection requires at least 2 rounds of DCE */
7333 BUG_ON(num_det < 2);
7334
7335 plug_type_ptr =
7336 TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
7337
7338 plug_type[0] = PLUG_TYPE_INVALID;
7339
Joonwoo Park41956722012-04-18 13:13:07 -07007340 /* performs DCEs for N times
7341 * 1st: check if voltage is in invalid range
7342 * 2nd - N-2nd: check voltage range and delta
7343 * N-1st: check voltage range, delta with HPHR GND switch
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07007344 * Nth: check voltage range with VDDIO switch */
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007345 for (i = 0; i < num_det; i++) {
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07007346 gndswitch = (i == (num_det - 2));
Simmi Pateriyad60186a2012-11-27 13:50:11 +05307347 vddioswitch = (i == (num_det - 1));
Joonwoo Park41956722012-04-18 13:13:07 -07007348 if (i == 0) {
7349 mb_v[i] = tabla_codec_setup_hs_polling(codec);
7350 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007351 inval = tabla_is_inval_ins_range(codec, mic_mv[i],
7352 highhph, &highv);
7353 ahighv |= highv;
Joonwoo Park41956722012-04-18 13:13:07 -07007354 scaled = mic_mv[i];
Joonwoo Park41956722012-04-18 13:13:07 -07007355 } else {
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007356 if (vddioswitch)
Simmi Pateriyad60186a2012-11-27 13:50:11 +05307357 tabla_codec_onoff_vddio_switch(codec, true);
7358
Joonwoo Park41956722012-04-18 13:13:07 -07007359 if (gndswitch)
7360 tabla_codec_hphr_gnd_switch(codec, true);
7361 mb_v[i] = __tabla_codec_sta_dce(codec, 1, true, true);
7362 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007363 if (vddioswitch)
7364 scaled = tabla_scale_v_micb_vddio(tabla,
Joonwoo Park41956722012-04-18 13:13:07 -07007365 mic_mv[i],
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007366 false);
7367 else
7368 scaled = mic_mv[i];
7369 /* !gndswitch & vddioswitch means the previous DCE
7370 * was done with gndswitch, don't compare with DCE
7371 * with gndswitch */
7372 highdelta = tabla_is_inval_ins_delta(codec, scaled,
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07007373 mic_mv[i - 1],
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007374 TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV);
7375 inval = (tabla_is_inval_ins_range(codec, mic_mv[i],
7376 highhph, &highv) ||
7377 highdelta);
7378 ahighv |= highv;
Joonwoo Park41956722012-04-18 13:13:07 -07007379 if (gndswitch)
7380 tabla_codec_hphr_gnd_switch(codec, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007381 if (vddioswitch)
Simmi Pateriyad60186a2012-11-27 13:50:11 +05307382 tabla_codec_onoff_vddio_switch(codec, false);
Joonwoo Park41956722012-04-18 13:13:07 -07007383 }
7384 pr_debug("%s: DCE #%d, %04x, V %d, scaled V %d, GND %d, "
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007385 "VDDIO %d, inval %d\n", __func__,
Joonwoo Park41956722012-04-18 13:13:07 -07007386 i + 1, mb_v[i] & 0xffff, mic_mv[i], scaled, gndswitch,
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007387 vddioswitch, inval);
7388 /* don't need to run further DCEs */
Ravi Kumar Alamanda1c713b22012-09-27 17:14:27 -07007389 if ((ahighv || !vddioswitch) && inval)
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007390 break;
7391 mic_mv[i] = scaled;
Ravi Kumar Alamanda1c713b22012-09-27 17:14:27 -07007392
7393 /*
7394 * claim UNSUPPORTED plug insertion when
7395 * good headset is detected but HPHR GND switch makes
7396 * delta difference
7397 */
7398 if (i == (num_det - 2) && highdelta && !ahighv)
7399 gndmicswapped = true;
7400 else if (i == (num_det - 1) && inval) {
7401 if (gndmicswapped)
7402 plug_type[0] = PLUG_TYPE_GND_MIC_SWAP;
7403 else
7404 plug_type[0] = PLUG_TYPE_INVALID;
7405 }
Joonwoo Park41956722012-04-18 13:13:07 -07007406 }
7407
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007408 for (i = 0; (plug_type[0] != PLUG_TYPE_GND_MIC_SWAP && !inval) &&
7409 i < num_det; i++) {
Joonwoo Park41956722012-04-18 13:13:07 -07007410 /*
7411 * If we are here, means none of the all
7412 * measurements are fake, continue plug type detection.
7413 * If all three measurements do not produce same
7414 * plug type, restart insertion detection
7415 */
7416 if (mic_mv[i] < plug_type_ptr->v_no_mic) {
7417 plug_type[i] = PLUG_TYPE_HEADPHONE;
7418 pr_debug("%s: Detect attempt %d, detected Headphone\n",
7419 __func__, i);
7420 } else if (highhph && (mic_mv[i] > plug_type_ptr->v_hs_max)) {
7421 plug_type[i] = PLUG_TYPE_HIGH_HPH;
7422 pr_debug("%s: Detect attempt %d, detected High "
7423 "Headphone\n", __func__, i);
7424 } else {
7425 plug_type[i] = PLUG_TYPE_HEADSET;
7426 pr_debug("%s: Detect attempt %d, detected Headset\n",
7427 __func__, i);
7428 }
7429
7430 if (i > 0 && (plug_type[i - 1] != plug_type[i])) {
7431 pr_err("%s: Detect attempt %d and %d are not same",
7432 __func__, i - 1, i);
7433 plug_type[0] = PLUG_TYPE_INVALID;
7434 inval = true;
7435 break;
7436 }
7437 }
7438
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007439 pr_debug("%s: Detected plug type %d\n", __func__, plug_type[0]);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007440 pr_debug("%s: leave\n", __func__);
Joonwoo Park41956722012-04-18 13:13:07 -07007441 return plug_type[0];
7442}
7443
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007444static void tabla_hs_correct_gpio_plug(struct work_struct *work)
7445{
7446 struct tabla_priv *tabla;
7447 struct snd_soc_codec *codec;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007448 int retry = 0, pt_gnd_mic_swap_cnt = 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007449 bool correction = false;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007450 enum tabla_mbhc_plug_type plug_type = PLUG_TYPE_INVALID;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007451 unsigned long timeout;
7452
7453 tabla = container_of(work, struct tabla_priv, hs_correct_plug_work);
7454 codec = tabla->codec;
7455
7456 pr_debug("%s: enter\n", __func__);
7457 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
7458
7459 /* Keep override on during entire plug type correction work.
7460 *
7461 * This is okay under the assumption that any GPIO irqs which use
7462 * MBHC block cancel and sync this work so override is off again
7463 * prior to GPIO interrupt handler's MBHC block usage.
7464 * Also while this correction work is running, we can guarantee
7465 * DAPM doesn't use any MBHC block as this work only runs with
7466 * headphone detection.
7467 */
7468 tabla_turn_onoff_override(codec, true);
7469
7470 timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS);
7471 while (!time_after(jiffies, timeout)) {
7472 ++retry;
7473 rmb();
7474 if (tabla->hs_detect_work_stop) {
7475 pr_debug("%s: stop requested\n", __func__);
7476 break;
7477 }
7478
7479 msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS);
7480 if (tabla_hs_gpio_level_remove(tabla)) {
7481 pr_debug("%s: GPIO value is low\n", __func__);
7482 break;
7483 }
7484
7485 /* can race with removal interrupt */
7486 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Joonwoo Park41956722012-04-18 13:13:07 -07007487 plug_type = tabla_codec_get_plug_type(codec, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007488 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
7489
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007490 pr_debug("%s: attempt(%d) current_plug(%d) new_plug(%d)\n",
7491 __func__, retry, tabla->current_plug, plug_type);
Joonwoo Park41956722012-04-18 13:13:07 -07007492 if (plug_type == PLUG_TYPE_INVALID) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007493 pr_debug("Invalid plug in attempt # %d\n", retry);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007494 if (!tabla->mbhc_cfg.detect_extn_cable &&
7495 retry == NUM_ATTEMPTS_TO_REPORT &&
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007496 tabla->current_plug == PLUG_TYPE_NONE) {
7497 tabla_codec_report_plug(codec, 1,
7498 SND_JACK_HEADPHONE);
7499 }
Joonwoo Park41956722012-04-18 13:13:07 -07007500 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007501 pr_debug("Good headphone detected, continue polling mic\n");
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007502 if (tabla->mbhc_cfg.detect_extn_cable) {
7503 if (tabla->current_plug != plug_type)
7504 tabla_codec_report_plug(codec, 1,
7505 SND_JACK_HEADPHONE);
7506 } else if (tabla->current_plug == PLUG_TYPE_NONE)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007507 tabla_codec_report_plug(codec, 1,
7508 SND_JACK_HEADPHONE);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007509 } else {
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007510 if (plug_type == PLUG_TYPE_GND_MIC_SWAP) {
7511 pt_gnd_mic_swap_cnt++;
7512 if (pt_gnd_mic_swap_cnt <
7513 TABLA_MBHC_GND_MIC_SWAP_THRESHOLD)
7514 continue;
7515 else if (pt_gnd_mic_swap_cnt >
7516 TABLA_MBHC_GND_MIC_SWAP_THRESHOLD) {
7517 /* This is due to GND/MIC switch didn't
7518 * work, Report unsupported plug */
7519 } else if (tabla->mbhc_cfg.swap_gnd_mic) {
7520 /* if switch is toggled, check again,
7521 * otherwise report unsupported plug */
7522 if (tabla->mbhc_cfg.swap_gnd_mic(codec))
7523 continue;
7524 }
7525 } else
7526 pt_gnd_mic_swap_cnt = 0;
7527
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007528 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
7529 /* Turn off override */
7530 tabla_turn_onoff_override(codec, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007531 /* The valid plug also includes PLUG_TYPE_GND_MIC_SWAP
7532 */
Joonwoo Park41956722012-04-18 13:13:07 -07007533 tabla_find_plug_and_report(codec, plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007534 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
7535 pr_debug("Attempt %d found correct plug %d\n", retry,
Joonwoo Park41956722012-04-18 13:13:07 -07007536 plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007537 correction = true;
7538 break;
7539 }
7540 }
7541
7542 /* Turn off override */
7543 if (!correction)
7544 tabla_turn_onoff_override(codec, false);
7545
7546 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007547
7548 if (tabla->mbhc_cfg.detect_extn_cable) {
7549 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
7550 if (tabla->current_plug == PLUG_TYPE_HEADPHONE ||
7551 tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP ||
7552 tabla->current_plug == PLUG_TYPE_INVALID ||
7553 plug_type == PLUG_TYPE_INVALID) {
7554 /* Enable removal detection */
7555 tabla_codec_cleanup_hs_polling(codec);
7556 tabla_codec_enable_hs_detect(codec, 0, 0, false);
7557 }
7558 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
7559 }
7560 pr_debug("%s: leave current_plug(%d)\n",
7561 __func__, tabla->current_plug);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007562 /* unlock sleep */
7563 wcd9xxx_unlock_sleep(tabla->codec->control_data);
7564}
7565
7566/* called under codec_resource_lock acquisition */
7567static void tabla_codec_decide_gpio_plug(struct snd_soc_codec *codec)
7568{
Joonwoo Park41956722012-04-18 13:13:07 -07007569 enum tabla_mbhc_plug_type plug_type;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007570 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007571
7572 pr_debug("%s: enter\n", __func__);
7573
7574 tabla_turn_onoff_override(codec, true);
Joonwoo Park41956722012-04-18 13:13:07 -07007575 plug_type = tabla_codec_get_plug_type(codec, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007576 tabla_turn_onoff_override(codec, false);
7577
7578 if (tabla_hs_gpio_level_remove(tabla)) {
7579 pr_debug("%s: GPIO value is low when determining plug\n",
7580 __func__);
7581 return;
7582 }
7583
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007584 if (plug_type == PLUG_TYPE_INVALID ||
7585 plug_type == PLUG_TYPE_GND_MIC_SWAP) {
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007586 tabla_schedule_hs_detect_plug(tabla,
7587 &tabla->hs_correct_plug_work);
Joonwoo Park41956722012-04-18 13:13:07 -07007588 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007589 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
7590
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007591 tabla_schedule_hs_detect_plug(tabla,
7592 &tabla->hs_correct_plug_work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007593 } else {
Joonwoo Park41956722012-04-18 13:13:07 -07007594 pr_debug("%s: Valid plug found, determine plug type %d\n",
7595 __func__, plug_type);
7596 tabla_find_plug_and_report(codec, plug_type);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007597 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007598 pr_debug("%s: leave\n", __func__);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007599}
7600
7601/* called under codec_resource_lock acquisition */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007602static void tabla_codec_detect_plug_type(struct snd_soc_codec *codec)
7603{
Joonwoo Park41956722012-04-18 13:13:07 -07007604 enum tabla_mbhc_plug_type plug_type;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007605 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
7606 const struct tabla_mbhc_plug_detect_cfg *plug_det =
7607 TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007608 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007609 /* Turn on the override,
7610 * tabla_codec_setup_hs_polling requires override on */
7611 tabla_turn_onoff_override(codec, true);
Joonwoo Park03324832012-03-19 19:36:16 -07007612
7613 if (plug_det->t_ins_complete > 20)
7614 msleep(plug_det->t_ins_complete);
7615 else
7616 usleep_range(plug_det->t_ins_complete * 1000,
7617 plug_det->t_ins_complete * 1000);
7618
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007619 if (tabla->mbhc_cfg.gpio) {
7620 /* Turn off the override */
7621 tabla_turn_onoff_override(codec, false);
7622 if (tabla_hs_gpio_level_remove(tabla))
7623 pr_debug("%s: GPIO value is low when determining "
7624 "plug\n", __func__);
7625 else
7626 tabla_codec_decide_gpio_plug(codec);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007627 pr_debug("%s: leave\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007628 return;
7629 }
7630
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007631 plug_type = tabla_codec_get_plug_type(codec, false);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007632 tabla_turn_onoff_override(codec, false);
Joonwoo Park03324832012-03-19 19:36:16 -07007633
Joonwoo Park41956722012-04-18 13:13:07 -07007634 if (plug_type == PLUG_TYPE_INVALID) {
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007635 pr_debug("%s: Invalid plug type detected\n", __func__);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007636 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, 0x02);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007637 tabla_codec_cleanup_hs_polling(codec);
7638 tabla_codec_enable_hs_detect(codec, 1,
7639 MBHC_USE_MB_TRIGGER |
7640 MBHC_USE_HPHL_TRIGGER, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007641 } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) {
7642 pr_debug("%s: GND-MIC swapped plug type detected\n", __func__);
7643 tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED);
7644 tabla_codec_cleanup_hs_polling(codec);
7645 tabla_codec_enable_hs_detect(codec, 0, 0, false);
Joonwoo Park41956722012-04-18 13:13:07 -07007646 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Park03324832012-03-19 19:36:16 -07007647 pr_debug("%s: Headphone Detected\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007648 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
7649 tabla_codec_cleanup_hs_polling(codec);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007650 tabla_schedule_hs_detect_plug(tabla,
7651 &tabla->hs_correct_plug_work_nogpio);
Joonwoo Park41956722012-04-18 13:13:07 -07007652 } else if (plug_type == PLUG_TYPE_HEADSET) {
Joonwoo Park03324832012-03-19 19:36:16 -07007653 pr_debug("%s: Headset detected\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007654 tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET);
Joonwoo Park03324832012-03-19 19:36:16 -07007655 /* avoid false button press detect */
7656 msleep(50);
Joonwoo Park03324832012-03-19 19:36:16 -07007657 tabla_codec_start_hs_polling(codec);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007658 } else if (tabla->mbhc_cfg.detect_extn_cable &&
7659 plug_type == PLUG_TYPE_HIGH_HPH) {
7660 pr_debug("%s: High impedance plug type detected\n", __func__);
7661 tabla_codec_report_plug(codec, 1, SND_JACK_LINEOUT);
7662 /* Enable insertion detection on the other end of cable */
7663 tabla_codec_cleanup_hs_polling(codec);
7664 tabla_codec_enable_hs_detect(codec, 1,
7665 MBHC_USE_MB_TRIGGER, false);
Joonwoo Park03324832012-03-19 19:36:16 -07007666 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007667 pr_debug("%s: leave\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07007668}
7669
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007670/* called only from interrupt which is under codec_resource_lock acquisition */
7671static void tabla_hs_insert_irq_gpio(struct tabla_priv *priv, bool is_removal)
Bradley Rubincb1e2732011-06-23 16:49:20 -07007672{
Bradley Rubincb1e2732011-06-23 16:49:20 -07007673 struct snd_soc_codec *codec = priv->codec;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007674 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007675
7676 if (!is_removal) {
7677 pr_debug("%s: MIC trigger insertion interrupt\n", __func__);
7678
7679 rmb();
7680 if (priv->lpi_enabled)
7681 msleep(100);
7682
7683 rmb();
7684 if (!priv->lpi_enabled) {
7685 pr_debug("%s: lpi is disabled\n", __func__);
7686 } else if (gpio_get_value_cansleep(priv->mbhc_cfg.gpio) ==
7687 priv->mbhc_cfg.gpio_level_insert) {
7688 pr_debug("%s: Valid insertion, "
7689 "detect plug type\n", __func__);
7690 tabla_codec_decide_gpio_plug(codec);
7691 } else {
7692 pr_debug("%s: Invalid insertion, "
7693 "stop plug detection\n", __func__);
7694 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007695 } else if (tabla->mbhc_cfg.detect_extn_cable) {
7696 pr_debug("%s: Removal\n", __func__);
7697 if (!tabla_hs_gpio_level_remove(tabla)) {
7698 /*
7699 * gpio says, something is still inserted, could be
7700 * extension cable i.e. headset is removed from
7701 * extension cable
7702 */
7703 /* cancel detect plug */
7704 tabla_cancel_hs_detect_plug(tabla,
7705 &tabla->hs_correct_plug_work);
7706 tabla_codec_decide_gpio_plug(codec);
7707 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007708 } else {
7709 pr_err("%s: GPIO used, invalid MBHC Removal\n", __func__);
7710 }
7711}
7712
7713/* called only from interrupt which is under codec_resource_lock acquisition */
7714static void tabla_hs_insert_irq_nogpio(struct tabla_priv *priv, bool is_removal,
7715 bool is_mb_trigger)
7716{
Joonwoo Park03324832012-03-19 19:36:16 -07007717 int ret;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007718 struct snd_soc_codec *codec = priv->codec;
7719 struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007720 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
7721
7722 /* Cancel possibly running hs_detect_work */
7723 tabla_cancel_hs_detect_plug(tabla,
7724 &tabla->hs_correct_plug_work_nogpio);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07007725
7726 if (is_removal) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007727
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07007728 /*
7729 * If headphone is removed while playback is in progress,
7730 * it is possible that micbias will be switched to VDDIO.
7731 */
Joonwoo Park03324832012-03-19 19:36:16 -07007732 tabla_codec_switch_micbias(codec, 0);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007733 if (priv->current_plug == PLUG_TYPE_HEADPHONE)
7734 tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE);
7735 else if (priv->current_plug == PLUG_TYPE_GND_MIC_SWAP)
7736 tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED);
7737 else
7738 WARN(1, "%s: Unexpected current plug type %d\n",
7739 __func__, priv->current_plug);
Bradley Rubincb1e2732011-06-23 16:49:20 -07007740 tabla_codec_shutdown_hs_removal_detect(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007741 tabla_codec_enable_hs_detect(codec, 1,
7742 MBHC_USE_MB_TRIGGER |
7743 MBHC_USE_HPHL_TRIGGER,
Joonwoo Park03324832012-03-19 19:36:16 -07007744 true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007745 } else if (is_mb_trigger && !is_removal) {
Joonwoo Park03324832012-03-19 19:36:16 -07007746 pr_debug("%s: Waiting for Headphone left trigger\n",
7747 __func__);
7748 wcd9xxx_lock_sleep(core);
7749 if (schedule_delayed_work(&priv->mbhc_insert_dwork,
7750 usecs_to_jiffies(1000000)) == 0) {
7751 pr_err("%s: mbhc_insert_dwork is already scheduled\n",
7752 __func__);
7753 wcd9xxx_unlock_sleep(core);
Joonwoo Parkf4267c22012-01-10 13:25:24 -08007754 }
Joonwoo Park03324832012-03-19 19:36:16 -07007755 tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER,
7756 false);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007757 } else {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007758 ret = cancel_delayed_work(&priv->mbhc_insert_dwork);
7759 if (ret != 0) {
7760 pr_debug("%s: Complete plug insertion, Detecting plug "
7761 "type\n", __func__);
7762 tabla_codec_detect_plug_type(codec);
7763 wcd9xxx_unlock_sleep(core);
7764 } else {
7765 wcd9xxx_enable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007766 WCD9XXX_IRQ_MBHC_INSERTION);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007767 pr_err("%s: Error detecting plug insertion\n",
7768 __func__);
7769 }
Joonwoo Park03324832012-03-19 19:36:16 -07007770 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007771}
Bhalchandra Gajare9494fa262011-11-10 19:25:59 -08007772
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007773/* called only from interrupt which is under codec_resource_lock acquisition */
7774static void tabla_hs_insert_irq_extn(struct tabla_priv *priv,
7775 bool is_mb_trigger)
7776{
7777 struct snd_soc_codec *codec = priv->codec;
7778 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
7779
7780 /* Cancel possibly running hs_detect_work */
7781 tabla_cancel_hs_detect_plug(tabla,
7782 &tabla->hs_correct_plug_work);
7783
7784 if (is_mb_trigger) {
7785 pr_debug("%s: Waiting for Headphone left trigger\n",
7786 __func__);
7787 tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER,
7788 false);
7789 } else {
7790 pr_debug("%s: HPHL trigger received, detecting plug type\n",
7791 __func__);
7792 tabla_codec_detect_plug_type(codec);
7793 }
7794}
7795
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007796static irqreturn_t tabla_hs_insert_irq(int irq, void *data)
7797{
7798 bool is_mb_trigger, is_removal;
7799 struct tabla_priv *priv = data;
7800 struct snd_soc_codec *codec = priv->codec;
Bradley Rubincb1e2732011-06-23 16:49:20 -07007801
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007802 pr_debug("%s: enter\n", __func__);
7803 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007804 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007805
7806 is_mb_trigger = !!(snd_soc_read(codec, priv->mbhc_bias_regs.mbhc_reg) &
7807 0x10);
7808 is_removal = !!(snd_soc_read(codec, TABLA_A_CDC_MBHC_INT_CTL) & 0x02);
7809 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x03, 0x00);
7810
7811 /* Turn off both HPH and MIC line schmitt triggers */
7812 snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
7813 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
7814 snd_soc_update_bits(codec, priv->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
7815
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007816 if (priv->mbhc_cfg.detect_extn_cable &&
7817 priv->current_plug == PLUG_TYPE_HIGH_HPH)
7818 tabla_hs_insert_irq_extn(priv, is_mb_trigger);
7819 else if (priv->mbhc_cfg.gpio)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007820 tabla_hs_insert_irq_gpio(priv, is_removal);
7821 else
7822 tabla_hs_insert_irq_nogpio(priv, is_removal, is_mb_trigger);
7823
7824 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bradley Rubincb1e2732011-06-23 16:49:20 -07007825 return IRQ_HANDLED;
7826}
7827
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007828static bool is_valid_mic_voltage(struct snd_soc_codec *codec, s32 mic_mv)
7829{
7830 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007831 const struct tabla_mbhc_plug_type_cfg *plug_type =
7832 TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
7833 const s16 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007834
7835 return (!(mic_mv > 10 && mic_mv < 80) && (mic_mv > plug_type->v_no_mic)
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007836 && (mic_mv < v_hs_max)) ? true : false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007837}
7838
7839/* called under codec_resource_lock acquisition
7840 * returns true if mic voltage range is back to normal insertion
7841 * returns false either if timedout or removed */
7842static bool tabla_hs_remove_settle(struct snd_soc_codec *codec)
7843{
7844 int i;
7845 bool timedout, settled = false;
7846 s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT];
7847 short mb_v[MBHC_NUM_DCE_PLUG_DETECT];
7848 unsigned long retry = 0, timeout;
7849 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007850 const s16 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007851
7852 timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS);
7853 while (!(timedout = time_after(jiffies, timeout))) {
7854 retry++;
7855 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
7856 pr_debug("%s: GPIO indicates removal\n", __func__);
7857 break;
7858 }
7859
7860 if (tabla->mbhc_cfg.gpio) {
7861 if (retry > 1)
7862 msleep(250);
7863 else
7864 msleep(50);
7865 }
7866
7867 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
7868 pr_debug("%s: GPIO indicates removal\n", __func__);
7869 break;
7870 }
7871
7872 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) {
7873 mb_v[i] = tabla_codec_sta_dce(codec, 1, true);
7874 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
7875 pr_debug("%s : DCE run %lu, mic_mv = %d(%x)\n",
7876 __func__, retry, mic_mv[i], mb_v[i]);
7877 }
7878
7879 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
7880 pr_debug("%s: GPIO indicates removal\n", __func__);
7881 break;
7882 }
7883
7884 if (tabla->current_plug == PLUG_TYPE_NONE) {
7885 pr_debug("%s : headset/headphone is removed\n",
7886 __func__);
7887 break;
7888 }
7889
7890 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++)
7891 if (!is_valid_mic_voltage(codec, mic_mv[i]))
7892 break;
7893
7894 if (i == MBHC_NUM_DCE_PLUG_DETECT) {
7895 pr_debug("%s: MIC voltage settled\n", __func__);
7896 settled = true;
7897 msleep(200);
7898 break;
7899 }
7900
7901 /* only for non-GPIO remove irq */
7902 if (!tabla->mbhc_cfg.gpio) {
7903 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++)
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007904 if (mic_mv[i] < v_hs_max)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007905 break;
7906 if (i == MBHC_NUM_DCE_PLUG_DETECT) {
7907 pr_debug("%s: Headset is removed\n", __func__);
7908 break;
7909 }
7910 }
7911 }
7912
7913 if (timedout)
7914 pr_debug("%s: Microphone did not settle in %d seconds\n",
7915 __func__, TABLA_HS_DETECT_PLUG_TIME_MS);
7916 return settled;
7917}
7918
7919/* called only from interrupt which is under codec_resource_lock acquisition */
7920static void tabla_hs_remove_irq_gpio(struct tabla_priv *priv)
7921{
7922 struct snd_soc_codec *codec = priv->codec;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007923 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007924 if (tabla_hs_remove_settle(codec))
7925 tabla_codec_start_hs_polling(codec);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007926 pr_debug("%s: leave\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007927}
7928
7929/* called only from interrupt which is under codec_resource_lock acquisition */
7930static void tabla_hs_remove_irq_nogpio(struct tabla_priv *priv)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007931{
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007932 short bias_value;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007933 bool removed = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007934 struct snd_soc_codec *codec = priv->codec;
Joonwoo Park0976d012011-12-22 11:48:18 -08007935 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007936 TABLA_MBHC_CAL_GENERAL_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007937 int min_us = TABLA_FAKE_REMOVAL_MIN_PERIOD_MS * 1000;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007938
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007939 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007940 if (priv->current_plug != PLUG_TYPE_HEADSET) {
7941 pr_debug("%s(): Headset is not inserted, ignore removal\n",
7942 __func__);
7943 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
7944 0x08, 0x08);
7945 return;
7946 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007947
Joonwoo Park0976d012011-12-22 11:48:18 -08007948 usleep_range(generic->t_shutdown_plug_rem,
7949 generic->t_shutdown_plug_rem);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007950
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007951 do {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007952 bias_value = tabla_codec_sta_dce(codec, 1, true);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007953 pr_debug("%s: DCE %d,%d, %d us left\n", __func__, bias_value,
7954 tabla_codec_sta_dce_v(codec, 1, bias_value), min_us);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007955 if (bias_value < tabla_get_current_v_ins(priv, false)) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007956 pr_debug("%s: checking false removal\n", __func__);
7957 msleep(500);
7958 removed = !tabla_hs_remove_settle(codec);
7959 pr_debug("%s: headset %sactually removed\n", __func__,
7960 removed ? "" : "not ");
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007961 break;
7962 }
7963 min_us -= priv->mbhc_data.t_dce;
7964 } while (min_us > 0);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07007965
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007966 if (removed) {
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007967 if (priv->mbhc_cfg.detect_extn_cable) {
7968 if (!tabla_hs_gpio_level_remove(priv)) {
7969 /*
7970 * extension cable is still plugged in
7971 * report it as LINEOUT device
7972 */
7973 tabla_codec_report_plug(codec, 1,
7974 SND_JACK_LINEOUT);
7975 tabla_codec_cleanup_hs_polling(codec);
7976 tabla_codec_enable_hs_detect(codec, 1,
7977 MBHC_USE_MB_TRIGGER,
7978 false);
7979 }
7980 } else {
7981 /* Cancel possibly running hs_detect_work */
7982 tabla_cancel_hs_detect_plug(priv,
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007983 &priv->hs_correct_plug_work_nogpio);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007984 /*
7985 * If this removal is not false, first check the micbias
7986 * switch status and switch it to LDOH if it is already
7987 * switched to VDDIO.
7988 */
7989 tabla_codec_switch_micbias(codec, 0);
Joonwoo Park03324832012-03-19 19:36:16 -07007990
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007991 tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET);
7992 tabla_codec_cleanup_hs_polling(codec);
7993 tabla_codec_enable_hs_detect(codec, 1,
7994 MBHC_USE_MB_TRIGGER |
7995 MBHC_USE_HPHL_TRIGGER,
7996 true);
7997 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007998 } else {
7999 tabla_codec_start_hs_polling(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008000 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07008001 pr_debug("%s: leave\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008002}
Joonwoo Park8b1f0982011-12-08 17:12:45 -08008003
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008004static irqreturn_t tabla_hs_remove_irq(int irq, void *data)
8005{
8006 struct tabla_priv *priv = data;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008007 bool vddio;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008008 pr_debug("%s: enter, removal interrupt\n", __func__);
8009
8010 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
Simmi Pateriya71d63872012-11-08 01:06:30 +05308011 vddio = !priv->mbhc_cfg.micbias_always_on &&
8012 (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008013 priv->mbhc_micbias_switched);
8014 if (vddio)
8015 __tabla_codec_switch_micbias(priv->codec, 0, false, true);
8016
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07008017 if ((priv->mbhc_cfg.detect_extn_cable &&
8018 !tabla_hs_gpio_level_remove(priv)) ||
8019 !priv->mbhc_cfg.gpio) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008020 tabla_hs_remove_irq_nogpio(priv);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07008021 } else
8022 tabla_hs_remove_irq_gpio(priv);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008023
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008024 /* if driver turned off vddio switch and headset is not removed,
8025 * turn on the vddio switch back, if headset is removed then vddio
8026 * switch is off by time now and shouldn't be turn on again from here */
8027 if (vddio && priv->current_plug == PLUG_TYPE_HEADSET)
8028 __tabla_codec_switch_micbias(priv->codec, 1, true, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008029 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008030
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008031 return IRQ_HANDLED;
8032}
8033
Joonwoo Park03324832012-03-19 19:36:16 -07008034void mbhc_insert_work(struct work_struct *work)
8035{
8036 struct delayed_work *dwork;
8037 struct tabla_priv *tabla;
8038 struct snd_soc_codec *codec;
8039 struct wcd9xxx *tabla_core;
8040
8041 dwork = to_delayed_work(work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008042 tabla = container_of(dwork, struct tabla_priv, mbhc_insert_dwork);
Joonwoo Park03324832012-03-19 19:36:16 -07008043 codec = tabla->codec;
8044 tabla_core = dev_get_drvdata(codec->dev->parent);
8045
8046 pr_debug("%s:\n", __func__);
8047
8048 /* Turn off both HPH and MIC line schmitt triggers */
8049 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
8050 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
8051 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008052 wcd9xxx_disable_irq_sync(codec->control_data,
8053 WCD9XXX_IRQ_MBHC_INSERTION);
Joonwoo Park03324832012-03-19 19:36:16 -07008054 tabla_codec_detect_plug_type(codec);
8055 wcd9xxx_unlock_sleep(tabla_core);
8056}
8057
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008058static void tabla_hs_gpio_handler(struct snd_soc_codec *codec)
8059{
8060 bool insert;
8061 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park1f9d7fd2013-01-07 12:40:03 -08008062 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008063 bool is_removed = false;
8064
8065 pr_debug("%s: enter\n", __func__);
8066
8067 tabla->in_gpio_handler = true;
8068 /* Wait here for debounce time */
8069 usleep_range(TABLA_GPIO_IRQ_DEBOUNCE_TIME_US,
8070 TABLA_GPIO_IRQ_DEBOUNCE_TIME_US);
8071
Joonwoo Park1f9d7fd2013-01-07 12:40:03 -08008072 wcd9xxx_nested_irq_lock(core);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008073 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
8074
8075 /* cancel pending button press */
8076 if (tabla_cancel_btn_work(tabla))
8077 pr_debug("%s: button press is canceled\n", __func__);
8078
8079 insert = (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) ==
8080 tabla->mbhc_cfg.gpio_level_insert);
8081 if ((tabla->current_plug == PLUG_TYPE_NONE) && insert) {
8082 tabla->lpi_enabled = false;
8083 wmb();
8084
8085 /* cancel detect plug */
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07008086 tabla_cancel_hs_detect_plug(tabla,
8087 &tabla->hs_correct_plug_work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008088
8089 /* Disable Mic Bias pull down and HPH Switch to GND */
8090 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01,
8091 0x00);
8092 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x00);
8093 tabla_codec_detect_plug_type(codec);
8094 } else if ((tabla->current_plug != PLUG_TYPE_NONE) && !insert) {
8095 tabla->lpi_enabled = false;
8096 wmb();
8097
8098 /* cancel detect plug */
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07008099 tabla_cancel_hs_detect_plug(tabla,
8100 &tabla->hs_correct_plug_work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008101
8102 if (tabla->current_plug == PLUG_TYPE_HEADPHONE) {
8103 tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE);
8104 is_removed = true;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07008105 } else if (tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP) {
8106 tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED);
8107 is_removed = true;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008108 } else if (tabla->current_plug == PLUG_TYPE_HEADSET) {
8109 tabla_codec_pause_hs_polling(codec);
8110 tabla_codec_cleanup_hs_polling(codec);
8111 tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET);
8112 is_removed = true;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07008113 } else if (tabla->current_plug == PLUG_TYPE_HIGH_HPH) {
8114 tabla_codec_report_plug(codec, 0, SND_JACK_LINEOUT);
8115 is_removed = true;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008116 }
8117
8118 if (is_removed) {
8119 /* Enable Mic Bias pull down and HPH Switch to GND */
8120 snd_soc_update_bits(codec,
8121 tabla->mbhc_bias_regs.ctl_reg, 0x01,
8122 0x01);
8123 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01,
8124 0x01);
8125 /* Make sure mic trigger is turned off */
8126 snd_soc_update_bits(codec,
8127 tabla->mbhc_bias_regs.ctl_reg,
8128 0x01, 0x01);
8129 snd_soc_update_bits(codec,
8130 tabla->mbhc_bias_regs.mbhc_reg,
8131 0x90, 0x00);
8132 /* Reset MBHC State Machine */
8133 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
8134 0x08, 0x08);
8135 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
8136 0x08, 0x00);
8137 /* Turn off override */
8138 tabla_turn_onoff_override(codec, false);
Simmi Pateriya21375012012-11-26 23:06:01 +05308139 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008140 }
8141 }
8142
8143 tabla->in_gpio_handler = false;
8144 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Joonwoo Park1f9d7fd2013-01-07 12:40:03 -08008145 wcd9xxx_nested_irq_unlock(core);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008146 pr_debug("%s: leave\n", __func__);
8147}
8148
8149static irqreturn_t tabla_mechanical_plug_detect_irq(int irq, void *data)
8150{
8151 int r = IRQ_HANDLED;
8152 struct snd_soc_codec *codec = data;
Joonwoo Parkecf379c2012-10-04 16:57:52 -07008153 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008154
8155 if (unlikely(wcd9xxx_lock_sleep(codec->control_data) == false)) {
8156 pr_warn("%s: failed to hold suspend\n", __func__);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07008157 /*
8158 * Give up this IRQ for now and resend this IRQ so IRQ can be
8159 * handled after system resume
8160 */
8161 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
8162 tabla->gpio_irq_resend = true;
8163 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
8164 wake_lock_timeout(&tabla->irq_resend_wlock, HZ);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008165 r = IRQ_NONE;
8166 } else {
8167 tabla_hs_gpio_handler(codec);
8168 wcd9xxx_unlock_sleep(codec->control_data);
8169 }
8170
8171 return r;
8172}
8173
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07008174static void tabla_hs_correct_plug_nogpio(struct work_struct *work)
8175{
8176 struct tabla_priv *tabla;
8177 struct snd_soc_codec *codec;
8178 unsigned long timeout;
8179 int retry = 0;
8180 enum tabla_mbhc_plug_type plug_type;
8181 bool is_headset = false;
8182
8183 pr_debug("%s(): Poll Microphone voltage for %d seconds\n",
8184 __func__, TABLA_HS_DETECT_PLUG_TIME_MS / 1000);
8185
8186 tabla = container_of(work, struct tabla_priv,
8187 hs_correct_plug_work_nogpio);
8188 codec = tabla->codec;
8189
8190 /* Make sure the MBHC mux is connected to MIC Path */
8191 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
8192
8193 /* setup for microphone polling */
8194 tabla_turn_onoff_override(codec, true);
8195 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
8196
8197 timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS);
8198 while (!time_after(jiffies, timeout)) {
8199 ++retry;
8200
8201 msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS);
8202 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
8203 plug_type = tabla_codec_get_plug_type(codec, false);
8204 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
8205
8206 if (plug_type == PLUG_TYPE_HIGH_HPH
8207 || plug_type == PLUG_TYPE_INVALID) {
8208
8209 /* this means the plug is removed
8210 * End microphone polling and setup
8211 * for low power removal detection.
8212 */
8213 pr_debug("%s(): Plug may be removed, setup removal\n",
8214 __func__);
8215 break;
8216 } else if (plug_type == PLUG_TYPE_HEADSET) {
8217 /* Plug is corrected from headphone to headset,
8218 * report headset and end the polling
8219 */
8220 is_headset = true;
8221 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
8222 tabla_turn_onoff_override(codec, false);
8223 tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET);
8224 tabla_codec_start_hs_polling(codec);
8225 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
8226 pr_debug("%s(): corrected from headphone to headset\n",
8227 __func__);
8228 break;
8229 }
8230 }
8231
8232 /* Undo setup for microphone polling depending
8233 * result from polling
8234 */
8235 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
8236 if (!is_headset) {
Bhalchandra Gajareafc86432012-08-23 13:44:07 -07008237 pr_debug("%s: Inserted headphone is not a headset\n",
8238 __func__);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07008239 tabla_turn_onoff_override(codec, false);
8240 tabla_codec_cleanup_hs_polling(codec);
8241 tabla_codec_enable_hs_detect(codec, 0, 0, false);
8242 }
8243 wcd9xxx_unlock_sleep(codec->control_data);
8244}
8245
Joonwoo Park1305bab2012-05-21 15:08:42 -07008246static int tabla_mbhc_init_and_calibrate(struct tabla_priv *tabla)
8247{
8248 int ret = 0;
8249 struct snd_soc_codec *codec = tabla->codec;
8250
8251 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
8252 tabla_mbhc_init(codec);
8253 tabla_mbhc_cal(codec);
8254 tabla_mbhc_calc_thres(codec);
8255 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
8256 tabla_codec_calibrate_hs_polling(codec);
8257 if (!tabla->mbhc_cfg.gpio) {
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07008258 INIT_WORK(&tabla->hs_correct_plug_work_nogpio,
8259 tabla_hs_correct_plug_nogpio);
Joonwoo Park1305bab2012-05-21 15:08:42 -07008260 ret = tabla_codec_enable_hs_detect(codec, 1,
8261 MBHC_USE_MB_TRIGGER |
8262 MBHC_USE_HPHL_TRIGGER,
8263 false);
8264
8265 if (IS_ERR_VALUE(ret))
8266 pr_err("%s: Failed to setup MBHC detection\n",
8267 __func__);
8268 } else {
8269 /* Enable Mic Bias pull down and HPH Switch to GND */
8270 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg,
8271 0x01, 0x01);
8272 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x01);
8273 INIT_WORK(&tabla->hs_correct_plug_work,
8274 tabla_hs_correct_gpio_plug);
8275 }
8276
8277 if (!IS_ERR_VALUE(ret)) {
8278 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10);
8279 wcd9xxx_enable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008280 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Joonwoo Park1305bab2012-05-21 15:08:42 -07008281 wcd9xxx_enable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008282 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Joonwoo Park1305bab2012-05-21 15:08:42 -07008283
8284 if (tabla->mbhc_cfg.gpio) {
8285 ret = request_threaded_irq(tabla->mbhc_cfg.gpio_irq,
8286 NULL,
8287 tabla_mechanical_plug_detect_irq,
8288 (IRQF_TRIGGER_RISING |
8289 IRQF_TRIGGER_FALLING),
8290 "tabla-gpio", codec);
8291 if (!IS_ERR_VALUE(ret)) {
8292 ret = enable_irq_wake(tabla->mbhc_cfg.gpio_irq);
8293 /* Bootup time detection */
8294 tabla_hs_gpio_handler(codec);
8295 }
8296 }
8297 }
8298
8299 return ret;
8300}
8301
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008302static void mbhc_fw_read(struct work_struct *work)
8303{
8304 struct delayed_work *dwork;
8305 struct tabla_priv *tabla;
8306 struct snd_soc_codec *codec;
8307 const struct firmware *fw;
Joonwoo Park1305bab2012-05-21 15:08:42 -07008308 int ret = -1, retry = 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008309
8310 dwork = to_delayed_work(work);
Joonwoo Park1305bab2012-05-21 15:08:42 -07008311 tabla = container_of(dwork, struct tabla_priv, mbhc_firmware_dwork);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008312 codec = tabla->codec;
8313
8314 while (retry < MBHC_FW_READ_ATTEMPTS) {
8315 retry++;
8316 pr_info("%s:Attempt %d to request MBHC firmware\n",
8317 __func__, retry);
8318 ret = request_firmware(&fw, "wcd9310/wcd9310_mbhc.bin",
8319 codec->dev);
8320
8321 if (ret != 0) {
8322 usleep_range(MBHC_FW_READ_TIMEOUT,
Joonwoo Park1305bab2012-05-21 15:08:42 -07008323 MBHC_FW_READ_TIMEOUT);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008324 } else {
8325 pr_info("%s: MBHC Firmware read succesful\n", __func__);
8326 break;
8327 }
8328 }
8329
8330 if (ret != 0) {
8331 pr_err("%s: Cannot load MBHC firmware use default cal\n",
8332 __func__);
8333 } else if (tabla_mbhc_fw_validate(fw) == false) {
8334 pr_err("%s: Invalid MBHC cal data size use default cal\n",
8335 __func__);
8336 release_firmware(fw);
8337 } else {
8338 tabla->mbhc_cfg.calibration = (void *)fw->data;
8339 tabla->mbhc_fw = fw;
8340 }
8341
Joonwoo Park1305bab2012-05-21 15:08:42 -07008342 (void) tabla_mbhc_init_and_calibrate(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008343}
8344
Joonwoo Park03324832012-03-19 19:36:16 -07008345int tabla_hs_detect(struct snd_soc_codec *codec,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008346 const struct tabla_mbhc_config *cfg)
Joonwoo Park03324832012-03-19 19:36:16 -07008347{
8348 struct tabla_priv *tabla;
8349 int rc = 0;
8350
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008351 if (!codec || !cfg->calibration) {
Joonwoo Park03324832012-03-19 19:36:16 -07008352 pr_err("Error: no codec or calibration\n");
8353 return -EINVAL;
8354 }
8355
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008356 if (cfg->mclk_rate != TABLA_MCLK_RATE_12288KHZ) {
8357 if (cfg->mclk_rate == TABLA_MCLK_RATE_9600KHZ)
Joonwoo Park03324832012-03-19 19:36:16 -07008358 pr_err("Error: clock rate %dHz is not yet supported\n",
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008359 cfg->mclk_rate);
Joonwoo Park03324832012-03-19 19:36:16 -07008360 else
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008361 pr_err("Error: unsupported clock rate %d\n",
8362 cfg->mclk_rate);
Joonwoo Park03324832012-03-19 19:36:16 -07008363 return -EINVAL;
8364 }
8365
8366 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008367 tabla->mbhc_cfg = *cfg;
8368 tabla->in_gpio_handler = false;
8369 tabla->current_plug = PLUG_TYPE_NONE;
8370 tabla->lpi_enabled = false;
Joonwoo Park03324832012-03-19 19:36:16 -07008371 tabla_get_mbhc_micbias_regs(codec, &tabla->mbhc_bias_regs);
8372
8373 /* Put CFILT in fast mode by default */
Simmi Pateriya71d63872012-11-08 01:06:30 +05308374 if (!tabla->mbhc_cfg.micbias_always_on)
8375 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl,
Joonwoo Park03324832012-03-19 19:36:16 -07008376 0x40, TABLA_CFILT_FAST_MODE);
8377 INIT_DELAYED_WORK(&tabla->mbhc_firmware_dwork, mbhc_fw_read);
8378 INIT_DELAYED_WORK(&tabla->mbhc_btn_dwork, btn_lpress_fn);
8379 INIT_WORK(&tabla->hphlocp_work, hphlocp_off_report);
8380 INIT_WORK(&tabla->hphrocp_work, hphrocp_off_report);
8381 INIT_DELAYED_WORK(&tabla->mbhc_insert_dwork, mbhc_insert_work);
8382
Joonwoo Park1305bab2012-05-21 15:08:42 -07008383 if (!tabla->mbhc_cfg.read_fw_bin)
8384 rc = tabla_mbhc_init_and_calibrate(tabla);
8385 else
Joonwoo Park03324832012-03-19 19:36:16 -07008386 schedule_delayed_work(&tabla->mbhc_firmware_dwork,
8387 usecs_to_jiffies(MBHC_FW_READ_TIMEOUT));
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008388
Joonwoo Park03324832012-03-19 19:36:16 -07008389 return rc;
8390}
8391EXPORT_SYMBOL_GPL(tabla_hs_detect);
8392
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008393static irqreturn_t tabla_slimbus_irq(int irq, void *data)
8394{
8395 struct tabla_priv *priv = data;
8396 struct snd_soc_codec *codec = priv->codec;
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07008397 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
8398 int i, j, port_id, k, ch_mask_temp;
Swaminathan Sathappan4bd38942012-07-17 11:31:31 -07008399 unsigned long slimbus_value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008400 u8 val;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308401 for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) {
8402 slimbus_value = wcd9xxx_interface_reg_read(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008403 TABLA_SLIM_PGD_PORT_INT_STATUS0 + i);
8404 for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308405 val = wcd9xxx_interface_reg_read(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008406 TABLA_SLIM_PGD_PORT_INT_SOURCE0 + i*8 + j);
8407 if (val & 0x1)
8408 pr_err_ratelimited("overflow error on port %x,"
8409 " value %x\n", i*8 + j, val);
8410 if (val & 0x2)
8411 pr_err_ratelimited("underflow error on port %x,"
8412 " value %x\n", i*8 + j, val);
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07008413 if (val & 0x4) {
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07008414 port_id = i*8 + j;
8415 for (k = 0; k < ARRAY_SIZE(tabla_dai); k++) {
8416 ch_mask_temp = 1 << port_id;
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08008417 pr_debug("%s: tabla_p->dai[%d].ch_mask = 0x%lx\n",
Kuirong Wang906ac472012-07-09 12:54:44 -07008418 __func__, k,
8419 tabla_p->dai[k].ch_mask);
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07008420 if (ch_mask_temp &
8421 tabla_p->dai[k].ch_mask) {
8422 tabla_p->dai[k].ch_mask &=
Kuirong Wang906ac472012-07-09 12:54:44 -07008423 ~ch_mask_temp;
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07008424 if (!tabla_p->dai[k].ch_mask)
Kuirong Wang906ac472012-07-09 12:54:44 -07008425 wake_up(
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07008426 &tabla_p->dai[k].dai_wait);
8427 }
8428 }
8429 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008430 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308431 wcd9xxx_interface_reg_write(codec->control_data,
Swaminathan Sathappan4bd38942012-07-17 11:31:31 -07008432 TABLA_SLIM_PGD_PORT_INT_CLR0 + i, slimbus_value);
8433 val = 0x0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008434 }
8435
8436 return IRQ_HANDLED;
8437}
8438
Patrick Lai3043fba2011-08-01 14:15:57 -07008439static int tabla_handle_pdata(struct tabla_priv *tabla)
8440{
8441 struct snd_soc_codec *codec = tabla->codec;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308442 struct wcd9xxx_pdata *pdata = tabla->pdata;
Patrick Lai3043fba2011-08-01 14:15:57 -07008443 int k1, k2, k3, rc = 0;
Santosh Mardi22920282011-10-26 02:38:40 +05308444 u8 leg_mode = pdata->amic_settings.legacy_mode;
8445 u8 txfe_bypass = pdata->amic_settings.txfe_enable;
8446 u8 txfe_buff = pdata->amic_settings.txfe_buff;
8447 u8 flag = pdata->amic_settings.use_pdata;
8448 u8 i = 0, j = 0;
8449 u8 val_txfe = 0, value = 0;
Patrick Lai3043fba2011-08-01 14:15:57 -07008450
8451 if (!pdata) {
8452 rc = -ENODEV;
8453 goto done;
8454 }
8455
8456 /* Make sure settings are correct */
8457 if ((pdata->micbias.ldoh_v > TABLA_LDOH_2P85_V) ||
8458 (pdata->micbias.bias1_cfilt_sel > TABLA_CFILT3_SEL) ||
8459 (pdata->micbias.bias2_cfilt_sel > TABLA_CFILT3_SEL) ||
8460 (pdata->micbias.bias3_cfilt_sel > TABLA_CFILT3_SEL) ||
8461 (pdata->micbias.bias4_cfilt_sel > TABLA_CFILT3_SEL)) {
8462 rc = -EINVAL;
8463 goto done;
8464 }
8465
8466 /* figure out k value */
8467 k1 = tabla_find_k_value(pdata->micbias.ldoh_v,
8468 pdata->micbias.cfilt1_mv);
8469 k2 = tabla_find_k_value(pdata->micbias.ldoh_v,
8470 pdata->micbias.cfilt2_mv);
8471 k3 = tabla_find_k_value(pdata->micbias.ldoh_v,
8472 pdata->micbias.cfilt3_mv);
8473
8474 if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) {
8475 rc = -EINVAL;
8476 goto done;
8477 }
8478
8479 /* Set voltage level and always use LDO */
8480 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x0C,
8481 (pdata->micbias.ldoh_v << 2));
8482
8483 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_1_VAL, 0xFC,
8484 (k1 << 2));
8485 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_2_VAL, 0xFC,
8486 (k2 << 2));
8487 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_3_VAL, 0xFC,
8488 (k3 << 2));
8489
8490 snd_soc_update_bits(codec, TABLA_A_MICB_1_CTL, 0x60,
8491 (pdata->micbias.bias1_cfilt_sel << 5));
8492 snd_soc_update_bits(codec, TABLA_A_MICB_2_CTL, 0x60,
8493 (pdata->micbias.bias2_cfilt_sel << 5));
8494 snd_soc_update_bits(codec, TABLA_A_MICB_3_CTL, 0x60,
8495 (pdata->micbias.bias3_cfilt_sel << 5));
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008496 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_ctl, 0x60,
8497 (pdata->micbias.bias4_cfilt_sel << 5));
Patrick Lai3043fba2011-08-01 14:15:57 -07008498
Santosh Mardi22920282011-10-26 02:38:40 +05308499 for (i = 0; i < 6; j++, i += 2) {
8500 if (flag & (0x01 << i)) {
8501 value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00;
8502 val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00;
8503 val_txfe = val_txfe |
8504 ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00);
8505 snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10,
8506 0x10, value);
8507 snd_soc_update_bits(codec,
8508 TABLA_A_TX_1_2_TEST_EN + j * 10,
8509 0x30, val_txfe);
8510 }
8511 if (flag & (0x01 << (i + 1))) {
8512 value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00;
8513 val_txfe = (txfe_bypass &
8514 (0x01 << (i + 1))) ? 0x02 : 0x00;
8515 val_txfe |= (txfe_buff &
8516 (0x01 << (i + 1))) ? 0x01 : 0x00;
8517 snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10,
8518 0x01, value);
8519 snd_soc_update_bits(codec,
8520 TABLA_A_TX_1_2_TEST_EN + j * 10,
8521 0x03, val_txfe);
8522 }
8523 }
8524 if (flag & 0x40) {
8525 value = (leg_mode & 0x40) ? 0x10 : 0x00;
8526 value = value | ((txfe_bypass & 0x40) ? 0x02 : 0x00);
8527 value = value | ((txfe_buff & 0x40) ? 0x01 : 0x00);
8528 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN,
8529 0x13, value);
8530 }
Patrick Lai49efeac2011-11-03 11:01:12 -07008531
8532 if (pdata->ocp.use_pdata) {
8533 /* not defined in CODEC specification */
8534 if (pdata->ocp.hph_ocp_limit == 1 ||
8535 pdata->ocp.hph_ocp_limit == 5) {
8536 rc = -EINVAL;
8537 goto done;
8538 }
8539 snd_soc_update_bits(codec, TABLA_A_RX_COM_OCP_CTL,
8540 0x0F, pdata->ocp.num_attempts);
8541 snd_soc_write(codec, TABLA_A_RX_COM_OCP_COUNT,
8542 ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time));
8543 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL,
8544 0xE0, (pdata->ocp.hph_ocp_limit << 5));
8545 }
Joonwoo Park03324832012-03-19 19:36:16 -07008546
8547 for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
8548 if (!strncmp(pdata->regulator[i].name, "CDC_VDDA_RX", 11)) {
8549 if (pdata->regulator[i].min_uV == 1800000 &&
8550 pdata->regulator[i].max_uV == 1800000) {
8551 snd_soc_write(codec, TABLA_A_BIAS_REF_CTL,
8552 0x1C);
8553 } else if (pdata->regulator[i].min_uV == 2200000 &&
8554 pdata->regulator[i].max_uV == 2200000) {
8555 snd_soc_write(codec, TABLA_A_BIAS_REF_CTL,
8556 0x1E);
8557 } else {
8558 pr_err("%s: unsupported CDC_VDDA_RX voltage "
8559 "min %d, max %d\n", __func__,
8560 pdata->regulator[i].min_uV,
8561 pdata->regulator[i].max_uV);
8562 rc = -EINVAL;
8563 }
8564 break;
8565 }
8566 }
Patrick Lai3043fba2011-08-01 14:15:57 -07008567done:
8568 return rc;
8569}
8570
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008571static const struct tabla_reg_mask_val tabla_1_1_reg_defaults[] = {
8572
8573 /* Tabla 1.1 MICBIAS changes */
8574 TABLA_REG_VAL(TABLA_A_MICB_1_INT_RBIAS, 0x24),
8575 TABLA_REG_VAL(TABLA_A_MICB_2_INT_RBIAS, 0x24),
8576 TABLA_REG_VAL(TABLA_A_MICB_3_INT_RBIAS, 0x24),
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008577
8578 /* Tabla 1.1 HPH changes */
8579 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_PA, 0x57),
8580 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_LDO, 0x56),
8581
8582 /* Tabla 1.1 EAR PA changes */
8583 TABLA_REG_VAL(TABLA_A_RX_EAR_BIAS_PA, 0xA6),
8584 TABLA_REG_VAL(TABLA_A_RX_EAR_GAIN, 0x02),
8585 TABLA_REG_VAL(TABLA_A_RX_EAR_VCM, 0x03),
8586
8587 /* Tabla 1.1 Lineout_5 Changes */
8588 TABLA_REG_VAL(TABLA_A_RX_LINE_5_GAIN, 0x10),
8589
8590 /* Tabla 1.1 RX Changes */
8591 TABLA_REG_VAL(TABLA_A_CDC_RX1_B5_CTL, 0x78),
8592 TABLA_REG_VAL(TABLA_A_CDC_RX2_B5_CTL, 0x78),
8593 TABLA_REG_VAL(TABLA_A_CDC_RX3_B5_CTL, 0x78),
8594 TABLA_REG_VAL(TABLA_A_CDC_RX4_B5_CTL, 0x78),
8595 TABLA_REG_VAL(TABLA_A_CDC_RX5_B5_CTL, 0x78),
8596 TABLA_REG_VAL(TABLA_A_CDC_RX6_B5_CTL, 0x78),
8597 TABLA_REG_VAL(TABLA_A_CDC_RX7_B5_CTL, 0x78),
8598
8599 /* Tabla 1.1 RX1 and RX2 Changes */
8600 TABLA_REG_VAL(TABLA_A_CDC_RX1_B6_CTL, 0xA0),
8601 TABLA_REG_VAL(TABLA_A_CDC_RX2_B6_CTL, 0xA0),
8602
8603 /* Tabla 1.1 RX3 to RX7 Changes */
8604 TABLA_REG_VAL(TABLA_A_CDC_RX3_B6_CTL, 0x80),
8605 TABLA_REG_VAL(TABLA_A_CDC_RX4_B6_CTL, 0x80),
8606 TABLA_REG_VAL(TABLA_A_CDC_RX5_B6_CTL, 0x80),
8607 TABLA_REG_VAL(TABLA_A_CDC_RX6_B6_CTL, 0x80),
8608 TABLA_REG_VAL(TABLA_A_CDC_RX7_B6_CTL, 0x80),
8609
8610 /* Tabla 1.1 CLASSG Changes */
8611 TABLA_REG_VAL(TABLA_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B),
8612};
8613
8614static const struct tabla_reg_mask_val tabla_2_0_reg_defaults[] = {
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008615 /* Tabla 2.0 MICBIAS changes */
8616 TABLA_REG_VAL(TABLA_A_MICB_2_MBHC, 0x02),
8617};
8618
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008619static const struct tabla_reg_mask_val tabla_1_x_only_reg_2_0_defaults[] = {
8620 TABLA_REG_VAL(TABLA_1_A_MICB_4_INT_RBIAS, 0x24),
8621};
8622
8623static const struct tabla_reg_mask_val tabla_2_only_reg_2_0_defaults[] = {
8624 TABLA_REG_VAL(TABLA_2_A_MICB_4_INT_RBIAS, 0x24),
8625};
8626
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008627static void tabla_update_reg_defaults(struct snd_soc_codec *codec)
8628{
8629 u32 i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308630 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008631
8632 for (i = 0; i < ARRAY_SIZE(tabla_1_1_reg_defaults); i++)
8633 snd_soc_write(codec, tabla_1_1_reg_defaults[i].reg,
8634 tabla_1_1_reg_defaults[i].val);
8635
8636 for (i = 0; i < ARRAY_SIZE(tabla_2_0_reg_defaults); i++)
8637 snd_soc_write(codec, tabla_2_0_reg_defaults[i].reg,
8638 tabla_2_0_reg_defaults[i].val);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008639
8640 if (TABLA_IS_1_X(tabla_core->version)) {
8641 for (i = 0; i < ARRAY_SIZE(tabla_1_x_only_reg_2_0_defaults);
8642 i++)
8643 snd_soc_write(codec,
8644 tabla_1_x_only_reg_2_0_defaults[i].reg,
8645 tabla_1_x_only_reg_2_0_defaults[i].val);
8646 } else {
8647 for (i = 0; i < ARRAY_SIZE(tabla_2_only_reg_2_0_defaults); i++)
8648 snd_soc_write(codec,
8649 tabla_2_only_reg_2_0_defaults[i].reg,
8650 tabla_2_only_reg_2_0_defaults[i].val);
8651 }
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008652}
8653
8654static const struct tabla_reg_mask_val tabla_codec_reg_init_val[] = {
Patrick Laic7cae882011-11-18 11:52:49 -08008655 /* Initialize current threshold to 350MA
8656 * number of wait and run cycles to 4096
8657 */
Patrick Lai49efeac2011-11-03 11:01:12 -07008658 {TABLA_A_RX_HPH_OCP_CTL, 0xE0, 0x60},
Patrick Laic7cae882011-11-18 11:52:49 -08008659 {TABLA_A_RX_COM_OCP_COUNT, 0xFF, 0xFF},
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008660
Santosh Mardi32171012011-10-28 23:32:06 +05308661 {TABLA_A_QFUSE_CTL, 0xFF, 0x03},
8662
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008663 /* Initialize gain registers to use register gain */
8664 {TABLA_A_RX_HPH_L_GAIN, 0x10, 0x10},
8665 {TABLA_A_RX_HPH_R_GAIN, 0x10, 0x10},
8666 {TABLA_A_RX_LINE_1_GAIN, 0x10, 0x10},
8667 {TABLA_A_RX_LINE_2_GAIN, 0x10, 0x10},
8668 {TABLA_A_RX_LINE_3_GAIN, 0x10, 0x10},
8669 {TABLA_A_RX_LINE_4_GAIN, 0x10, 0x10},
8670
Kuirong Wangccb29c62012-06-15 11:09:07 -07008671 /* Set the MICBIAS default output as pull down*/
8672 {TABLA_A_MICB_1_CTL, 0x01, 0x01},
8673 {TABLA_A_MICB_2_CTL, 0x01, 0x01},
8674 {TABLA_A_MICB_3_CTL, 0x01, 0x01},
8675
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008676 /* Initialize mic biases to differential mode */
8677 {TABLA_A_MICB_1_INT_RBIAS, 0x24, 0x24},
8678 {TABLA_A_MICB_2_INT_RBIAS, 0x24, 0x24},
8679 {TABLA_A_MICB_3_INT_RBIAS, 0x24, 0x24},
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008680
8681 {TABLA_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14},
8682
8683 /* Use 16 bit sample size for TX1 to TX6 */
8684 {TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20},
8685 {TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20},
8686 {TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20},
8687 {TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20},
8688 {TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20},
8689 {TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0x30, 0x20},
8690
8691 /* Use 16 bit sample size for TX7 to TX10 */
8692 {TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0x60, 0x40},
8693 {TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0x60, 0x40},
8694 {TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0x60, 0x40},
8695 {TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0x60, 0x40},
8696
8697 /* Use 16 bit sample size for RX */
8698 {TABLA_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA},
8699 {TABLA_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0xAA},
8700
8701 /*enable HPF filter for TX paths */
8702 {TABLA_A_CDC_TX1_MUX_CTL, 0x8, 0x0},
8703 {TABLA_A_CDC_TX2_MUX_CTL, 0x8, 0x0},
8704 {TABLA_A_CDC_TX3_MUX_CTL, 0x8, 0x0},
8705 {TABLA_A_CDC_TX4_MUX_CTL, 0x8, 0x0},
8706 {TABLA_A_CDC_TX5_MUX_CTL, 0x8, 0x0},
8707 {TABLA_A_CDC_TX6_MUX_CTL, 0x8, 0x0},
8708 {TABLA_A_CDC_TX7_MUX_CTL, 0x8, 0x0},
8709 {TABLA_A_CDC_TX8_MUX_CTL, 0x8, 0x0},
8710 {TABLA_A_CDC_TX9_MUX_CTL, 0x8, 0x0},
8711 {TABLA_A_CDC_TX10_MUX_CTL, 0x8, 0x0},
Kiran Kandi0ba468f2012-05-08 11:45:05 -07008712
8713 /* config Decimator for DMIC CLK_MODE_1(3.072Mhz@12.88Mhz mclk) */
8714 {TABLA_A_CDC_TX1_DMIC_CTL, 0x1, 0x1},
8715 {TABLA_A_CDC_TX2_DMIC_CTL, 0x1, 0x1},
8716 {TABLA_A_CDC_TX3_DMIC_CTL, 0x1, 0x1},
8717 {TABLA_A_CDC_TX4_DMIC_CTL, 0x1, 0x1},
8718 {TABLA_A_CDC_TX5_DMIC_CTL, 0x1, 0x1},
8719 {TABLA_A_CDC_TX6_DMIC_CTL, 0x1, 0x1},
8720 {TABLA_A_CDC_TX7_DMIC_CTL, 0x1, 0x1},
8721 {TABLA_A_CDC_TX8_DMIC_CTL, 0x1, 0x1},
8722 {TABLA_A_CDC_TX9_DMIC_CTL, 0x1, 0x1},
8723 {TABLA_A_CDC_TX10_DMIC_CTL, 0x1, 0x1},
8724
8725 /* config DMIC clk to CLK_MODE_1 (3.072Mhz@12.88Mhz mclk) */
8726 {TABLA_A_CDC_CLK_DMIC_CTL, 0x2A, 0x2A},
8727
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008728};
8729
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008730static const struct tabla_reg_mask_val tabla_1_x_codec_reg_init_val[] = {
Kuirong Wangccb29c62012-06-15 11:09:07 -07008731 /* Set the MICBIAS default output as pull down*/
8732 {TABLA_1_A_MICB_4_CTL, 0x01, 0x01},
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008733 /* Initialize mic biases to differential mode */
8734 {TABLA_1_A_MICB_4_INT_RBIAS, 0x24, 0x24},
8735};
8736
8737static const struct tabla_reg_mask_val tabla_2_higher_codec_reg_init_val[] = {
Kuirong Wangccb29c62012-06-15 11:09:07 -07008738
8739 /* Set the MICBIAS default output as pull down*/
8740 {TABLA_2_A_MICB_4_CTL, 0x01, 0x01},
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008741 /* Initialize mic biases to differential mode */
8742 {TABLA_2_A_MICB_4_INT_RBIAS, 0x24, 0x24},
8743};
8744
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008745static void tabla_codec_init_reg(struct snd_soc_codec *codec)
8746{
8747 u32 i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308748 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008749
8750 for (i = 0; i < ARRAY_SIZE(tabla_codec_reg_init_val); i++)
8751 snd_soc_update_bits(codec, tabla_codec_reg_init_val[i].reg,
8752 tabla_codec_reg_init_val[i].mask,
8753 tabla_codec_reg_init_val[i].val);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008754 if (TABLA_IS_1_X(tabla_core->version)) {
8755 for (i = 0; i < ARRAY_SIZE(tabla_1_x_codec_reg_init_val); i++)
8756 snd_soc_update_bits(codec,
8757 tabla_1_x_codec_reg_init_val[i].reg,
8758 tabla_1_x_codec_reg_init_val[i].mask,
8759 tabla_1_x_codec_reg_init_val[i].val);
8760 } else {
8761 for (i = 0; i < ARRAY_SIZE(tabla_2_higher_codec_reg_init_val);
8762 i++)
8763 snd_soc_update_bits(codec,
8764 tabla_2_higher_codec_reg_init_val[i].reg,
8765 tabla_2_higher_codec_reg_init_val[i].mask,
8766 tabla_2_higher_codec_reg_init_val[i].val);
8767 }
8768}
8769
8770static void tabla_update_reg_address(struct tabla_priv *priv)
8771{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308772 struct wcd9xxx *tabla_core = dev_get_drvdata(priv->codec->dev->parent);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008773 struct tabla_reg_address *reg_addr = &priv->reg_addr;
8774
8775 if (TABLA_IS_1_X(tabla_core->version)) {
Joonwoo Parkcb7c8922012-02-16 23:12:59 -08008776 reg_addr->micb_4_mbhc = TABLA_1_A_MICB_4_MBHC;
8777 reg_addr->micb_4_int_rbias = TABLA_1_A_MICB_4_INT_RBIAS;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008778 reg_addr->micb_4_ctl = TABLA_1_A_MICB_4_CTL;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008779 } else if (TABLA_IS_2_0(tabla_core->version)) {
Joonwoo Parkcb7c8922012-02-16 23:12:59 -08008780 reg_addr->micb_4_mbhc = TABLA_2_A_MICB_4_MBHC;
8781 reg_addr->micb_4_int_rbias = TABLA_2_A_MICB_4_INT_RBIAS;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008782 reg_addr->micb_4_ctl = TABLA_2_A_MICB_4_CTL;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008783 }
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008784}
8785
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008786#ifdef CONFIG_DEBUG_FS
8787static int codec_debug_open(struct inode *inode, struct file *file)
8788{
8789 file->private_data = inode->i_private;
8790 return 0;
8791}
8792
8793static ssize_t codec_debug_write(struct file *filp,
8794 const char __user *ubuf, size_t cnt, loff_t *ppos)
8795{
8796 char lbuf[32];
8797 char *buf;
8798 int rc;
8799 struct tabla_priv *tabla = filp->private_data;
8800
8801 if (cnt > sizeof(lbuf) - 1)
8802 return -EINVAL;
8803
8804 rc = copy_from_user(lbuf, ubuf, cnt);
8805 if (rc)
8806 return -EFAULT;
8807
8808 lbuf[cnt] = '\0';
8809 buf = (char *)lbuf;
Joonwoo Park5bbcb0c2012-08-07 17:25:52 -07008810 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
8811 tabla->no_mic_headset_override =
8812 (*strsep(&buf, " ") == '0') ? false : true;
8813 if (tabla->no_mic_headset_override && tabla->mbhc_polling_active) {
8814 tabla_codec_pause_hs_polling(tabla->codec);
8815 tabla_codec_start_hs_polling(tabla->codec);
8816 }
8817 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
8818 return cnt;
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008819}
8820
8821static ssize_t codec_mbhc_debug_read(struct file *file, char __user *buf,
8822 size_t count, loff_t *pos)
8823{
8824 const int size = 768;
8825 char buffer[size];
8826 int n = 0;
8827 struct tabla_priv *tabla = file->private_data;
8828 struct snd_soc_codec *codec = tabla->codec;
8829 const struct mbhc_internal_cal_data *p = &tabla->mbhc_data;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008830 const s16 v_ins_hu_cur = tabla_get_current_v_ins(tabla, true);
8831 const s16 v_ins_h_cur = tabla_get_current_v_ins(tabla, false);
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008832
8833 n = scnprintf(buffer, size - n, "dce_z = %x(%dmv)\n", p->dce_z,
8834 tabla_codec_sta_dce_v(codec, 1, p->dce_z));
8835 n += scnprintf(buffer + n, size - n, "dce_mb = %x(%dmv)\n",
8836 p->dce_mb, tabla_codec_sta_dce_v(codec, 1, p->dce_mb));
8837 n += scnprintf(buffer + n, size - n, "sta_z = %x(%dmv)\n",
8838 p->sta_z, tabla_codec_sta_dce_v(codec, 0, p->sta_z));
8839 n += scnprintf(buffer + n, size - n, "sta_mb = %x(%dmv)\n",
8840 p->sta_mb, tabla_codec_sta_dce_v(codec, 0, p->sta_mb));
8841 n += scnprintf(buffer + n, size - n, "t_dce = %x\n", p->t_dce);
8842 n += scnprintf(buffer + n, size - n, "t_sta = %x\n", p->t_sta);
8843 n += scnprintf(buffer + n, size - n, "micb_mv = %dmv\n",
8844 p->micb_mv);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008845 n += scnprintf(buffer + n, size - n, "v_ins_hu = %x(%dmv)%s\n",
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008846 p->v_ins_hu,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008847 tabla_codec_sta_dce_v(codec, 0, p->v_ins_hu),
8848 p->v_ins_hu == v_ins_hu_cur ? "*" : "");
8849 n += scnprintf(buffer + n, size - n, "v_ins_h = %x(%dmv)%s\n",
8850 p->v_ins_h, tabla_codec_sta_dce_v(codec, 1, p->v_ins_h),
8851 p->v_ins_h == v_ins_h_cur ? "*" : "");
8852 n += scnprintf(buffer + n, size - n, "adj_v_ins_hu = %x(%dmv)%s\n",
8853 p->adj_v_ins_hu,
8854 tabla_codec_sta_dce_v(codec, 0, p->adj_v_ins_hu),
8855 p->adj_v_ins_hu == v_ins_hu_cur ? "*" : "");
8856 n += scnprintf(buffer + n, size - n, "adj_v_ins_h = %x(%dmv)%s\n",
8857 p->adj_v_ins_h,
8858 tabla_codec_sta_dce_v(codec, 1, p->adj_v_ins_h),
8859 p->adj_v_ins_h == v_ins_h_cur ? "*" : "");
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008860 n += scnprintf(buffer + n, size - n, "v_b1_hu = %x(%dmv)\n",
8861 p->v_b1_hu, tabla_codec_sta_dce_v(codec, 0, p->v_b1_hu));
8862 n += scnprintf(buffer + n, size - n, "v_b1_h = %x(%dmv)\n",
8863 p->v_b1_h, tabla_codec_sta_dce_v(codec, 1, p->v_b1_h));
8864 n += scnprintf(buffer + n, size - n, "v_b1_huc = %x(%dmv)\n",
8865 p->v_b1_huc,
8866 tabla_codec_sta_dce_v(codec, 1, p->v_b1_huc));
8867 n += scnprintf(buffer + n, size - n, "v_brh = %x(%dmv)\n",
8868 p->v_brh, tabla_codec_sta_dce_v(codec, 1, p->v_brh));
8869 n += scnprintf(buffer + n, size - n, "v_brl = %x(%dmv)\n", p->v_brl,
8870 tabla_codec_sta_dce_v(codec, 0, p->v_brl));
8871 n += scnprintf(buffer + n, size - n, "v_no_mic = %x(%dmv)\n",
8872 p->v_no_mic,
8873 tabla_codec_sta_dce_v(codec, 0, p->v_no_mic));
8874 n += scnprintf(buffer + n, size - n, "npoll = %d\n", p->npoll);
8875 n += scnprintf(buffer + n, size - n, "nbounce_wait = %d\n",
8876 p->nbounce_wait);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008877 n += scnprintf(buffer + n, size - n, "v_inval_ins_low = %d\n",
8878 p->v_inval_ins_low);
8879 n += scnprintf(buffer + n, size - n, "v_inval_ins_high = %d\n",
8880 p->v_inval_ins_high);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07008881 if (tabla->mbhc_cfg.gpio)
8882 n += scnprintf(buffer + n, size - n, "GPIO insert = %d\n",
8883 tabla_hs_gpio_level_remove(tabla));
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008884 buffer[n] = 0;
8885
8886 return simple_read_from_buffer(buf, count, pos, buffer, n);
8887}
8888
8889static const struct file_operations codec_debug_ops = {
8890 .open = codec_debug_open,
8891 .write = codec_debug_write,
8892};
8893
8894static const struct file_operations codec_mbhc_debug_ops = {
8895 .open = codec_debug_open,
8896 .read = codec_mbhc_debug_read,
8897};
8898#endif
8899
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008900static int tabla_codec_probe(struct snd_soc_codec *codec)
8901{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308902 struct wcd9xxx *control;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008903 struct tabla_priv *tabla;
8904 struct snd_soc_dapm_context *dapm = &codec->dapm;
8905 int ret = 0;
8906 int i;
Kuirong Wang906ac472012-07-09 12:54:44 -07008907 void *ptr = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008908
8909 codec->control_data = dev_get_drvdata(codec->dev->parent);
8910 control = codec->control_data;
8911
8912 tabla = kzalloc(sizeof(struct tabla_priv), GFP_KERNEL);
8913 if (!tabla) {
8914 dev_err(codec->dev, "Failed to allocate private data\n");
8915 return -ENOMEM;
8916 }
Kiran Kandid8cf5212012-03-02 15:34:53 -08008917 for (i = 0 ; i < NUM_DECIMATORS; i++) {
8918 tx_hpf_work[i].tabla = tabla;
8919 tx_hpf_work[i].decimator = i + 1;
8920 INIT_DELAYED_WORK(&tx_hpf_work[i].dwork,
8921 tx_hpf_corner_freq_callback);
8922 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008923
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07008924 /* Make sure mbhc micbias register addresses are zeroed out */
8925 memset(&tabla->mbhc_bias_regs, 0,
8926 sizeof(struct mbhc_micbias_regs));
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07008927 tabla->mbhc_micbias_switched = false;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07008928
Joonwoo Park0976d012011-12-22 11:48:18 -08008929 /* Make sure mbhc intenal calibration data is zeroed out */
8930 memset(&tabla->mbhc_data, 0,
8931 sizeof(struct mbhc_internal_cal_data));
Joonwoo Park433149a2012-01-11 09:53:54 -08008932 tabla->mbhc_data.t_sta_dce = DEFAULT_DCE_STA_WAIT;
Joonwoo Park0976d012011-12-22 11:48:18 -08008933 tabla->mbhc_data.t_dce = DEFAULT_DCE_WAIT;
8934 tabla->mbhc_data.t_sta = DEFAULT_STA_WAIT;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008935 snd_soc_codec_set_drvdata(codec, tabla);
8936
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07008937 tabla->mclk_enabled = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008938 tabla->bandgap_type = TABLA_BANDGAP_OFF;
8939 tabla->clock_active = false;
8940 tabla->config_mode_active = false;
8941 tabla->mbhc_polling_active = false;
Joonwoo Parkf4267c22012-01-10 13:25:24 -08008942 tabla->mbhc_fake_ins_start = 0;
Bradley Rubincb3950a2011-08-18 13:07:26 -07008943 tabla->no_mic_headset_override = false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008944 tabla->hs_polling_irq_prepared = false;
8945 mutex_init(&tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008946 tabla->codec = codec;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008947 tabla->mbhc_state = MBHC_STATE_NONE;
Joonwoo Park03324832012-03-19 19:36:16 -07008948 tabla->mbhc_last_resume = 0;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08008949 for (i = 0; i < COMPANDER_MAX; i++) {
8950 tabla->comp_enabled[i] = 0;
8951 tabla->comp_fs[i] = COMPANDER_FS_48KHZ;
8952 }
Patrick Lai3043fba2011-08-01 14:15:57 -07008953 tabla->pdata = dev_get_platdata(codec->dev->parent);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308954 tabla->intf_type = wcd9xxx_get_intf_type();
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08008955 tabla->aux_pga_cnt = 0;
8956 tabla->aux_l_gain = 0x1F;
8957 tabla->aux_r_gain = 0x1F;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008958 tabla_update_reg_address(tabla);
Santosh Mardi22920282011-10-26 02:38:40 +05308959 tabla_update_reg_defaults(codec);
8960 tabla_codec_init_reg(codec);
Santosh Mardi22920282011-10-26 02:38:40 +05308961 ret = tabla_handle_pdata(tabla);
Patrick Lai3043fba2011-08-01 14:15:57 -07008962 if (IS_ERR_VALUE(ret)) {
8963 pr_err("%s: bad pdata\n", __func__);
8964 goto err_pdata;
8965 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008966
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008967 if (TABLA_IS_1_X(control->version))
Steve Mucklef132c6c2012-06-06 18:30:57 -07008968 snd_soc_add_codec_controls(codec, tabla_1_x_snd_controls,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008969 ARRAY_SIZE(tabla_1_x_snd_controls));
8970 else
Steve Mucklef132c6c2012-06-06 18:30:57 -07008971 snd_soc_add_codec_controls(codec, tabla_2_higher_snd_controls,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008972 ARRAY_SIZE(tabla_2_higher_snd_controls));
8973
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008974 if (TABLA_IS_1_X(control->version))
8975 snd_soc_dapm_new_controls(dapm, tabla_1_x_dapm_widgets,
8976 ARRAY_SIZE(tabla_1_x_dapm_widgets));
8977 else
8978 snd_soc_dapm_new_controls(dapm, tabla_2_higher_dapm_widgets,
8979 ARRAY_SIZE(tabla_2_higher_dapm_widgets));
8980
Kuirong Wang906ac472012-07-09 12:54:44 -07008981 ptr = kmalloc((sizeof(tabla_rx_chs) +
8982 sizeof(tabla_tx_chs)), GFP_KERNEL);
8983 if (!ptr) {
8984 pr_err("%s: no mem for slim chan ctl data\n", __func__);
8985 ret = -ENOMEM;
8986 goto err_nomem_slimch;
8987 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308988 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05308989 snd_soc_dapm_new_controls(dapm, tabla_dapm_i2s_widgets,
8990 ARRAY_SIZE(tabla_dapm_i2s_widgets));
8991 snd_soc_dapm_add_routes(dapm, audio_i2s_map,
8992 ARRAY_SIZE(audio_i2s_map));
Kuirong Wang906ac472012-07-09 12:54:44 -07008993 for (i = 0; i < ARRAY_SIZE(tabla_i2s_dai); i++)
8994 INIT_LIST_HEAD(&tabla->dai[i].wcd9xxx_ch_list);
8995 } else if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
8996 for (i = 0; i < NUM_CODEC_DAIS; i++) {
8997 INIT_LIST_HEAD(&tabla->dai[i].wcd9xxx_ch_list);
8998 init_waitqueue_head(&tabla->dai[i].dai_wait);
8999 }
Santosh Mardie15e2302011-11-15 10:39:23 +05309000 }
Kuirong Wang906ac472012-07-09 12:54:44 -07009001
9002 control->num_rx_port = TABLA_RX_MAX;
9003 control->rx_chs = ptr;
9004 memcpy(control->rx_chs, tabla_rx_chs, sizeof(tabla_rx_chs));
9005 control->num_tx_port = TABLA_TX_MAX;
9006 control->tx_chs = ptr + sizeof(tabla_rx_chs);
9007 memcpy(control->tx_chs, tabla_tx_chs, sizeof(tabla_tx_chs));
9008
Kiran Kandi8b3a8302011-09-27 16:13:28 -07009009
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08009010 if (TABLA_IS_1_X(control->version)) {
Kiran Kandi7a9fd902011-11-14 13:51:45 -08009011 snd_soc_dapm_add_routes(dapm, tabla_1_x_lineout_2_to_4_map,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08009012 ARRAY_SIZE(tabla_1_x_lineout_2_to_4_map));
9013 } else if (TABLA_IS_2_0(control->version)) {
Kiran Kandi7a9fd902011-11-14 13:51:45 -08009014 snd_soc_dapm_add_routes(dapm, tabla_2_x_lineout_2_to_4_map,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08009015 ARRAY_SIZE(tabla_2_x_lineout_2_to_4_map));
Kiran Kandi7a9fd902011-11-14 13:51:45 -08009016 } else {
9017 pr_err("%s : ERROR. Unsupported Tabla version 0x%2x\n",
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05309018 __func__, control->version);
Kiran Kandi7a9fd902011-11-14 13:51:45 -08009019 goto err_pdata;
9020 }
9021
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009022 snd_soc_dapm_sync(dapm);
9023
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009024 ret = wcd9xxx_request_irq(codec->control_data,
9025 WCD9XXX_IRQ_MBHC_INSERTION,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009026 tabla_hs_insert_irq, "Headset insert detect", tabla);
9027 if (ret) {
9028 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009029 WCD9XXX_IRQ_MBHC_INSERTION);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009030 goto err_insert_irq;
9031 }
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009032 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009033
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009034 ret = wcd9xxx_request_irq(codec->control_data,
9035 WCD9XXX_IRQ_MBHC_REMOVAL,
9036 tabla_hs_remove_irq,
9037 "Headset remove detect", tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009038 if (ret) {
9039 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009040 WCD9XXX_IRQ_MBHC_REMOVAL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009041 goto err_remove_irq;
9042 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009043
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009044 ret = wcd9xxx_request_irq(codec->control_data,
9045 WCD9XXX_IRQ_MBHC_POTENTIAL,
9046 tabla_dce_handler, "DC Estimation detect",
9047 tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009048 if (ret) {
9049 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009050 WCD9XXX_IRQ_MBHC_POTENTIAL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009051 goto err_potential_irq;
9052 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009053
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009054 ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE,
9055 tabla_release_handler,
9056 "Button Release detect", tabla);
Bradley Rubincb1e2732011-06-23 16:49:20 -07009057 if (ret) {
9058 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009059 WCD9XXX_IRQ_MBHC_RELEASE);
Bradley Rubincb1e2732011-06-23 16:49:20 -07009060 goto err_release_irq;
9061 }
9062
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009063 ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS,
9064 tabla_slimbus_irq, "SLIMBUS Slave", tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009065 if (ret) {
9066 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009067 WCD9XXX_IRQ_SLIMBUS);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009068 goto err_slimbus_irq;
9069 }
9070
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05309071 for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++)
9072 wcd9xxx_interface_reg_write(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009073 TABLA_SLIM_PGD_PORT_INT_EN0 + i, 0xFF);
9074
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05309075 ret = wcd9xxx_request_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009076 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT,
9077 tabla_hphl_ocp_irq,
9078 "HPH_L OCP detect", tabla);
Patrick Lai49efeac2011-11-03 11:01:12 -07009079 if (ret) {
9080 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009081 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07009082 goto err_hphl_ocp_irq;
9083 }
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009084 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07009085
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05309086 ret = wcd9xxx_request_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009087 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT,
9088 tabla_hphr_ocp_irq,
9089 "HPH_R OCP detect", tabla);
Patrick Lai49efeac2011-11-03 11:01:12 -07009090 if (ret) {
9091 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009092 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07009093 goto err_hphr_ocp_irq;
9094 }
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009095 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07009096
9097 /*
9098 * Register suspend lock and notifier to resend edge triggered
9099 * gpio IRQs
9100 */
9101 wake_lock_init(&tabla->irq_resend_wlock, WAKE_LOCK_SUSPEND,
9102 "tabla_gpio_irq_resend");
9103 tabla->gpio_irq_resend = false;
9104
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08009105 mutex_lock(&dapm->codec->mutex);
9106 snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
9107 snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
9108 snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE");
9109 snd_soc_dapm_sync(dapm);
9110 mutex_unlock(&dapm->codec->mutex);
Patrick Lai49efeac2011-11-03 11:01:12 -07009111
Bradley Rubincb3950a2011-08-18 13:07:26 -07009112#ifdef CONFIG_DEBUG_FS
Joonwoo Park179b9ec2012-03-26 10:56:20 -07009113 if (ret == 0) {
9114 tabla->debugfs_poke =
9115 debugfs_create_file("TRRS", S_IFREG | S_IRUGO, NULL, tabla,
9116 &codec_debug_ops);
9117 tabla->debugfs_mbhc =
9118 debugfs_create_file("tabla_mbhc", S_IFREG | S_IRUGO,
9119 NULL, tabla, &codec_mbhc_debug_ops);
9120 }
Bradley Rubincb3950a2011-08-18 13:07:26 -07009121#endif
Steve Mucklef132c6c2012-06-06 18:30:57 -07009122 codec->ignore_pmdown_time = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009123 return ret;
9124
Patrick Lai49efeac2011-11-03 11:01:12 -07009125err_hphr_ocp_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05309126 wcd9xxx_free_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009127 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT, tabla);
Patrick Lai49efeac2011-11-03 11:01:12 -07009128err_hphl_ocp_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009129 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009130err_slimbus_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009131 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, tabla);
Bradley Rubincb1e2732011-06-23 16:49:20 -07009132err_release_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009133 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL,
9134 tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009135err_potential_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009136 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_REMOVAL, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009137err_remove_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009138 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION,
9139 tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009140err_insert_irq:
Patrick Lai3043fba2011-08-01 14:15:57 -07009141err_pdata:
Kuirong Wang906ac472012-07-09 12:54:44 -07009142 kfree(ptr);
9143err_nomem_slimch:
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07009144 mutex_destroy(&tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009145 kfree(tabla);
9146 return ret;
9147}
9148static int tabla_codec_remove(struct snd_soc_codec *codec)
9149{
9150 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07009151
9152 wake_lock_destroy(&tabla->irq_resend_wlock);
9153
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009154 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, tabla);
9155 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, tabla);
9156 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL,
9157 tabla);
9158 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_REMOVAL, tabla);
9159 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION,
9160 tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07009161 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009162 tabla_codec_disable_clock_block(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07009163 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009164 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF);
Patrick Lai64b43262011-12-06 17:29:15 -08009165 if (tabla->mbhc_fw)
9166 release_firmware(tabla->mbhc_fw);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07009167 mutex_destroy(&tabla->codec_resource_lock);
Joonwoo Park179b9ec2012-03-26 10:56:20 -07009168#ifdef CONFIG_DEBUG_FS
9169 debugfs_remove(tabla->debugfs_poke);
9170 debugfs_remove(tabla->debugfs_mbhc);
9171#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009172 kfree(tabla);
9173 return 0;
9174}
9175static struct snd_soc_codec_driver soc_codec_dev_tabla = {
9176 .probe = tabla_codec_probe,
9177 .remove = tabla_codec_remove,
9178 .read = tabla_read,
9179 .write = tabla_write,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009180 .readable_register = tabla_readable,
9181 .volatile_register = tabla_volatile,
9182
9183 .reg_cache_size = TABLA_CACHE_SIZE,
9184 .reg_cache_default = tabla_reg_defaults,
9185 .reg_word_size = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07009186 .controls = tabla_snd_controls,
9187 .num_controls = ARRAY_SIZE(tabla_snd_controls),
9188 .dapm_widgets = tabla_dapm_widgets,
9189 .num_dapm_widgets = ARRAY_SIZE(tabla_dapm_widgets),
9190 .dapm_routes = audio_map,
9191 .num_dapm_routes = ARRAY_SIZE(audio_map),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009192};
Bradley Rubincb3950a2011-08-18 13:07:26 -07009193
Joonwoo Park8b1f0982011-12-08 17:12:45 -08009194#ifdef CONFIG_PM
9195static int tabla_suspend(struct device *dev)
9196{
Joonwoo Park816b8e62012-01-23 16:03:21 -08009197 dev_dbg(dev, "%s: system suspend\n", __func__);
9198 return 0;
Joonwoo Park8b1f0982011-12-08 17:12:45 -08009199}
9200
9201static int tabla_resume(struct device *dev)
9202{
Joonwoo Parkecf379c2012-10-04 16:57:52 -07009203 int irq;
Joonwoo Park03324832012-03-19 19:36:16 -07009204 struct platform_device *pdev = to_platform_device(dev);
9205 struct tabla_priv *tabla = platform_get_drvdata(pdev);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07009206
Joonwoo Parkd6e48bd2012-09-20 11:14:15 -07009207 dev_dbg(dev, "%s: system resume tabla %p\n", __func__, tabla);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07009208 if (tabla) {
9209 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Joonwoo Parkd6e48bd2012-09-20 11:14:15 -07009210 tabla->mbhc_last_resume = jiffies;
Joonwoo Parkecf379c2012-10-04 16:57:52 -07009211 if (tabla->gpio_irq_resend) {
9212 WARN_ON(!tabla->mbhc_cfg.gpio_irq);
9213 tabla->gpio_irq_resend = false;
9214
9215 irq = tabla->mbhc_cfg.gpio_irq;
9216 pr_debug("%s: Resending GPIO IRQ %d\n", __func__, irq);
9217 irq_set_pending(irq);
9218 check_irq_resend(irq_to_desc(irq), irq);
9219
9220 /* release suspend lock */
9221 wake_unlock(&tabla->irq_resend_wlock);
9222 }
9223 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
9224 }
9225
Joonwoo Park816b8e62012-01-23 16:03:21 -08009226 return 0;
Joonwoo Park8b1f0982011-12-08 17:12:45 -08009227}
9228
9229static const struct dev_pm_ops tabla_pm_ops = {
9230 .suspend = tabla_suspend,
9231 .resume = tabla_resume,
9232};
9233#endif
9234
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009235static int __devinit tabla_probe(struct platform_device *pdev)
9236{
Santosh Mardie15e2302011-11-15 10:39:23 +05309237 int ret = 0;
Steve Mucklef132c6c2012-06-06 18:30:57 -07009238 pr_err("tabla_probe\n");
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05309239 if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
Santosh Mardie15e2302011-11-15 10:39:23 +05309240 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla,
9241 tabla_dai, ARRAY_SIZE(tabla_dai));
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05309242 else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C)
Santosh Mardie15e2302011-11-15 10:39:23 +05309243 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla,
9244 tabla_i2s_dai, ARRAY_SIZE(tabla_i2s_dai));
9245 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009246}
9247static int __devexit tabla_remove(struct platform_device *pdev)
9248{
9249 snd_soc_unregister_codec(&pdev->dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009250 return 0;
9251}
9252static struct platform_driver tabla_codec_driver = {
9253 .probe = tabla_probe,
9254 .remove = tabla_remove,
9255 .driver = {
9256 .name = "tabla_codec",
9257 .owner = THIS_MODULE,
Joonwoo Park8b1f0982011-12-08 17:12:45 -08009258#ifdef CONFIG_PM
9259 .pm = &tabla_pm_ops,
9260#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009261 },
9262};
9263
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08009264static struct platform_driver tabla1x_codec_driver = {
9265 .probe = tabla_probe,
9266 .remove = tabla_remove,
9267 .driver = {
9268 .name = "tabla1x_codec",
9269 .owner = THIS_MODULE,
9270#ifdef CONFIG_PM
9271 .pm = &tabla_pm_ops,
9272#endif
9273 },
9274};
9275
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009276static int __init tabla_codec_init(void)
9277{
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08009278 int rtn = platform_driver_register(&tabla_codec_driver);
9279 if (rtn == 0) {
9280 rtn = platform_driver_register(&tabla1x_codec_driver);
9281 if (rtn != 0)
9282 platform_driver_unregister(&tabla_codec_driver);
9283 }
9284 return rtn;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009285}
9286
9287static void __exit tabla_codec_exit(void)
9288{
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08009289 platform_driver_unregister(&tabla1x_codec_driver);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009290 platform_driver_unregister(&tabla_codec_driver);
9291}
9292
9293module_init(tabla_codec_init);
9294module_exit(tabla_codec_exit);
9295
9296MODULE_DESCRIPTION("Tabla codec driver");
9297MODULE_VERSION("1.0");
9298MODULE_LICENSE("GPL v2");