blob: 0be9365ee1830b49de0ae6819822c068af1fbab7 [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
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -070058
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -070059#define SLIM_CLOSE_TIMEOUT 1000
Kuirong Wang84ee8802013-02-09 12:52:06 -080060/* The wait time value comes from codec HW specification */
61#define COMP_BRINGUP_WAIT_TIME 2000
Joonwoo Park03324832012-03-19 19:36:16 -070062enum {
63 MBHC_USE_HPHL_TRIGGER = 1,
64 MBHC_USE_MB_TRIGGER = 2
65};
66
67#define MBHC_NUM_DCE_PLUG_DETECT 3
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -070068#define NUM_ATTEMPTS_INSERT_DETECT 25
69#define NUM_ATTEMPTS_TO_REPORT 5
Joonwoo Park03324832012-03-19 19:36:16 -070070
Joonwoo Park2cc13f02012-05-09 12:44:25 -070071#define TABLA_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | \
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -070072 SND_JACK_OC_HPHR | SND_JACK_LINEOUT | \
73 SND_JACK_UNSUPPORTED)
Patrick Lai49efeac2011-11-03 11:01:12 -070074
Santosh Mardie15e2302011-11-15 10:39:23 +053075#define TABLA_I2S_MASTER_MODE_MASK 0x08
76
Patrick Laic7cae882011-11-18 11:52:49 -080077#define TABLA_OCP_ATTEMPT 1
78
Kuirong Wang906ac472012-07-09 12:54:44 -070079enum {
80 AIF1_PB = 0,
81 AIF1_CAP,
82 AIF2_PB,
83 AIF2_CAP,
84 AIF3_PB,
85 AIF3_CAP,
86 NUM_CODEC_DAIS,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -080087};
88
Kuirong Wang906ac472012-07-09 12:54:44 -070089enum {
90 RX_MIX1_INP_SEL_ZERO = 0,
91 RX_MIX1_INP_SEL_SRC1,
92 RX_MIX1_INP_SEL_SRC2,
93 RX_MIX1_INP_SEL_IIR1,
94 RX_MIX1_INP_SEL_IIR2,
95 RX_MIX1_INP_SEL_RX1,
96 RX_MIX1_INP_SEL_RX2,
97 RX_MIX1_INP_SEL_RX3,
98 RX_MIX1_INP_SEL_RX4,
99 RX_MIX1_INP_SEL_RX5,
100 RX_MIX1_INP_SEL_RX6,
101 RX_MIX1_INP_SEL_RX7,
102};
103
Kuirong Wang678e4172012-06-26 15:35:22 -0700104#define TABLA_COMP_DIGITAL_GAIN_HP_OFFSET 3
105#define TABLA_COMP_DIGITAL_GAIN_LINEOUT_OFFSET 6
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
Joonwoo Park0976d012011-12-22 11:48:18 -0800224/* Data used by MBHC */
225struct mbhc_internal_cal_data {
226 u16 dce_z;
227 u16 dce_mb;
228 u16 sta_z;
229 u16 sta_mb;
Joonwoo Park433149a2012-01-11 09:53:54 -0800230 u32 t_sta_dce;
Joonwoo Park0976d012011-12-22 11:48:18 -0800231 u32 t_dce;
232 u32 t_sta;
233 u32 micb_mv;
234 u16 v_ins_hu;
235 u16 v_ins_h;
236 u16 v_b1_hu;
237 u16 v_b1_h;
238 u16 v_b1_huc;
239 u16 v_brh;
240 u16 v_brl;
241 u16 v_no_mic;
Joonwoo Park0976d012011-12-22 11:48:18 -0800242 u8 npoll;
243 u8 nbounce_wait;
Joonwoo Parkcf473b42012-03-29 19:48:16 -0700244 s16 adj_v_hs_max;
245 u16 adj_v_ins_hu;
246 u16 adj_v_ins_h;
247 s16 v_inval_ins_low;
248 s16 v_inval_ins_high;
Joonwoo Park0976d012011-12-22 11:48:18 -0800249};
250
Joonwoo Park6c1ebb62012-01-16 19:08:43 -0800251struct tabla_reg_address {
252 u16 micb_4_ctl;
253 u16 micb_4_int_rbias;
254 u16 micb_4_mbhc;
255};
256
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700257enum tabla_mbhc_plug_type {
Joonwoo Park41956722012-04-18 13:13:07 -0700258 PLUG_TYPE_INVALID = -1,
259 PLUG_TYPE_NONE,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700260 PLUG_TYPE_HEADSET,
261 PLUG_TYPE_HEADPHONE,
262 PLUG_TYPE_HIGH_HPH,
Joonwoo Park2cc13f02012-05-09 12:44:25 -0700263 PLUG_TYPE_GND_MIC_SWAP,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700264};
265
266enum tabla_mbhc_state {
267 MBHC_STATE_NONE = -1,
268 MBHC_STATE_POTENTIAL,
269 MBHC_STATE_POTENTIAL_RECOVERY,
270 MBHC_STATE_RELEASE,
271};
272
Kiran Kandid8cf5212012-03-02 15:34:53 -0800273struct hpf_work {
274 struct tabla_priv *tabla;
275 u32 decimator;
276 u8 tx_hpf_cut_of_freq;
277 struct delayed_work dwork;
278};
279
280static struct hpf_work tx_hpf_work[NUM_DECIMATORS];
281
Kuirong Wang906ac472012-07-09 12:54:44 -0700282static const struct wcd9xxx_ch tabla_rx_chs[TABLA_RX_MAX] = {
283 WCD9XXX_CH(10, 0),
284 WCD9XXX_CH(11, 1),
285 WCD9XXX_CH(12, 2),
286 WCD9XXX_CH(13, 3),
287 WCD9XXX_CH(14, 4),
288 WCD9XXX_CH(15, 5),
289 WCD9XXX_CH(16, 6)
290};
291
292static const struct wcd9xxx_ch tabla_tx_chs[TABLA_TX_MAX] = {
293 WCD9XXX_CH(0, 0),
294 WCD9XXX_CH(1, 1),
295 WCD9XXX_CH(2, 2),
296 WCD9XXX_CH(3, 3),
297 WCD9XXX_CH(4, 4),
298 WCD9XXX_CH(5, 5),
299 WCD9XXX_CH(6, 6),
300 WCD9XXX_CH(7, 7),
301 WCD9XXX_CH(8, 8),
302 WCD9XXX_CH(9, 9)
303};
304
305static const u32 vport_check_table[NUM_CODEC_DAIS] = {
306 0, /* AIF1_PB */
307 (1 << AIF2_CAP) | (1 << AIF3_CAP), /* AIF1_CAP */
308 0, /* AIF2_PB */
309 (1 << AIF1_CAP) | (1 << AIF3_CAP), /* AIF2_CAP */
310 0, /* AIF2_PB */
311 (1 << AIF1_CAP) | (1 << AIF2_CAP), /* AIF2_CAP */
312};
313
Venkat Sudhir96dd28c2012-12-04 17:00:19 -0800314static const u32 vport_i2s_check_table[NUM_CODEC_DAIS] = {
315 0, /* AIF1_PB */
316 0, /* AIF1_CAP */
317};
318
Bradley Rubin229c6a52011-07-12 16:18:48 -0700319struct tabla_priv {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700320 struct snd_soc_codec *codec;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -0800321 struct tabla_reg_address reg_addr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700322 u32 adc_count;
Patrick Lai3043fba2011-08-01 14:15:57 -0700323 u32 cfilt1_cnt;
324 u32 cfilt2_cnt;
325 u32 cfilt3_cnt;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -0700326 u32 rx_bias_count;
Kiran Kandi0ba468f2012-05-08 11:45:05 -0700327 s32 dmic_1_2_clk_cnt;
328 s32 dmic_3_4_clk_cnt;
329 s32 dmic_5_6_clk_cnt;
330
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700331 enum tabla_bandgap_type bandgap_type;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -0700332 bool mclk_enabled;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700333 bool clock_active;
334 bool config_mode_active;
335 bool mbhc_polling_active;
Joonwoo Parkf4267c22012-01-10 13:25:24 -0800336 unsigned long mbhc_fake_ins_start;
Bradley Rubincb1e2732011-06-23 16:49:20 -0700337 int buttons_pressed;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700338 enum tabla_mbhc_state mbhc_state;
339 struct tabla_mbhc_config mbhc_cfg;
Joonwoo Park0976d012011-12-22 11:48:18 -0800340 struct mbhc_internal_cal_data mbhc_data;
Simmi Pateriya71d63872012-11-08 01:06:30 +0530341 u32 ldo_h_count;
342 u32 micbias_enable_count[TABLA_NUM_MICBIAS];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700343
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530344 struct wcd9xxx_pdata *pdata;
Bradley Rubina7096d02011-08-03 18:29:02 -0700345 u32 anc_slot;
Damir Didjustoc6f83cb2012-12-03 00:54:14 -0800346 bool anc_func;
Bradley Rubincb3950a2011-08-18 13:07:26 -0700347 bool no_mic_headset_override;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -0700348 /* Delayed work to report long button press */
Joonwoo Park03324832012-03-19 19:36:16 -0700349 struct delayed_work mbhc_btn_dwork;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700350
351 struct mbhc_micbias_regs mbhc_bias_regs;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -0700352 bool mbhc_micbias_switched;
Patrick Lai49efeac2011-11-03 11:01:12 -0700353
Joonwoo Parka9444452011-12-08 18:48:27 -0800354 /* track PA/DAC state */
355 unsigned long hph_pa_dac_state;
356
Santosh Mardie15e2302011-11-15 10:39:23 +0530357 /*track tabla interface type*/
358 u8 intf_type;
359
Patrick Lai49efeac2011-11-03 11:01:12 -0700360 u32 hph_status; /* track headhpone status */
361 /* define separate work for left and right headphone OCP to avoid
362 * additional checking on which OCP event to report so no locking
363 * to ensure synchronization is required
364 */
365 struct work_struct hphlocp_work; /* reporting left hph ocp off */
366 struct work_struct hphrocp_work; /* reporting right hph ocp off */
Joonwoo Park8b1f0982011-12-08 17:12:45 -0800367
Patrick Laic7cae882011-11-18 11:52:49 -0800368 u8 hphlocp_cnt; /* headphone left ocp retry */
369 u8 hphrocp_cnt; /* headphone right ocp retry */
Joonwoo Park0976d012011-12-22 11:48:18 -0800370
Patrick Lai64b43262011-12-06 17:29:15 -0800371 /* Work to perform MBHC Firmware Read */
372 struct delayed_work mbhc_firmware_dwork;
373 const struct firmware *mbhc_fw;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800374
375 /* num of slim ports required */
Kuirong Wang906ac472012-07-09 12:54:44 -0700376 struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS];
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800377
378 /*compander*/
379 int comp_enabled[COMPANDER_MAX];
380 u32 comp_fs[COMPANDER_MAX];
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -0800381
382 /* Maintain the status of AUX PGA */
383 int aux_pga_cnt;
384 u8 aux_l_gain;
385 u8 aux_r_gain;
Joonwoo Park03324832012-03-19 19:36:16 -0700386
Joonwoo Park03324832012-03-19 19:36:16 -0700387 struct delayed_work mbhc_insert_dwork;
388 unsigned long mbhc_last_resume; /* in jiffies */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700389
390 u8 current_plug;
391 struct work_struct hs_correct_plug_work;
392 bool hs_detect_work_stop;
393 bool hs_polling_irq_prepared;
394 bool lpi_enabled; /* low power insertion detection */
395 bool in_gpio_handler;
396 /* Currently, only used for mbhc purpose, to protect
397 * concurrent execution of mbhc threaded irq handlers and
398 * kill race between DAPM and MBHC.But can serve as a
399 * general lock to protect codec resource
400 */
401 struct mutex codec_resource_lock;
402
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -0700403 /* Work to perform polling on microphone voltage
404 * in order to correct plug type once plug type
405 * is detected as headphone
406 */
407 struct work_struct hs_correct_plug_work_nogpio;
408
Joonwoo Parkecf379c2012-10-04 16:57:52 -0700409 bool gpio_irq_resend;
410 struct wake_lock irq_resend_wlock;
411
Bradley Rubincb3950a2011-08-18 13:07:26 -0700412#ifdef CONFIG_DEBUG_FS
Joonwoo Park179b9ec2012-03-26 10:56:20 -0700413 struct dentry *debugfs_poke;
414 struct dentry *debugfs_mbhc;
Bradley Rubincb3950a2011-08-18 13:07:26 -0700415#endif
Joonwoo Park179b9ec2012-03-26 10:56:20 -0700416};
417
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800418static const u32 comp_shift[] = {
419 0,
Kuirong Wang678e4172012-06-26 15:35:22 -0700420 1,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800421};
422
423static const int comp_rx_path[] = {
424 COMPANDER_1,
425 COMPANDER_1,
426 COMPANDER_2,
427 COMPANDER_2,
428 COMPANDER_2,
429 COMPANDER_2,
430 COMPANDER_MAX,
431};
432
Kuirong Wang678e4172012-06-26 15:35:22 -0700433static const struct comp_sample_dependent_params
434 comp_samp_params[COMPANDER_FS_MAX] = {
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800435 {
Kuirong Wang678e4172012-06-26 15:35:22 -0700436 .peak_det_timeout = 0x6,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800437 .rms_meter_div_fact = 0x9 << 4,
Kuirong Wang678e4172012-06-26 15:35:22 -0700438 .rms_meter_resamp_fact = 0x06,
439 .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_240 << 3,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800440 },
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800441 {
Kuirong Wang678e4172012-06-26 15:35:22 -0700442 .peak_det_timeout = 0x7,
443 .rms_meter_div_fact = 0xA << 4,
444 .rms_meter_resamp_fact = 0x0C,
445 .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_480 << 3,
446 },
447 {
448 .peak_det_timeout = 0x8,
449 .rms_meter_div_fact = 0xB << 4,
450 .rms_meter_resamp_fact = 0x30,
451 .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_960 << 3,
452 },
453 {
454 .peak_det_timeout = 0x9,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800455 .rms_meter_div_fact = 0xB << 4,
456 .rms_meter_resamp_fact = 0x28,
Kuirong Wang678e4172012-06-26 15:35:22 -0700457 .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_1440 << 3,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800458 },
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800459 {
Kuirong Wang678e4172012-06-26 15:35:22 -0700460 .peak_det_timeout = 0xA,
461 .rms_meter_div_fact = 0xC << 4,
462 .rms_meter_resamp_fact = 0x50,
463 .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_2880 << 3,
464 },
465 {
466 .peak_det_timeout = 0xB,
467 .rms_meter_div_fact = 0xC << 4,
468 .rms_meter_resamp_fact = 0x50,
469 .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_5760 << 3,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800470 },
471};
472
Kuirong Wange9c8a222012-03-28 16:24:09 -0700473static unsigned short rx_digital_gain_reg[] = {
474 TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
475 TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
476 TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
477 TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
478 TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
479 TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
480 TABLA_A_CDC_RX7_VOL_CTL_B2_CTL,
481};
482
483
484static unsigned short tx_digital_gain_reg[] = {
485 TABLA_A_CDC_TX1_VOL_CTL_GAIN,
486 TABLA_A_CDC_TX2_VOL_CTL_GAIN,
487 TABLA_A_CDC_TX3_VOL_CTL_GAIN,
488 TABLA_A_CDC_TX4_VOL_CTL_GAIN,
489 TABLA_A_CDC_TX5_VOL_CTL_GAIN,
490 TABLA_A_CDC_TX6_VOL_CTL_GAIN,
491 TABLA_A_CDC_TX7_VOL_CTL_GAIN,
492 TABLA_A_CDC_TX8_VOL_CTL_GAIN,
493 TABLA_A_CDC_TX9_VOL_CTL_GAIN,
494 TABLA_A_CDC_TX10_VOL_CTL_GAIN,
495};
496
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700497static int tabla_codec_enable_charge_pump(struct snd_soc_dapm_widget *w,
498 struct snd_kcontrol *kcontrol, int event)
499{
500 struct snd_soc_codec *codec = w->codec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700501
502 pr_debug("%s %d\n", __func__, event);
503 switch (event) {
504 case SND_SOC_DAPM_POST_PMU:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700505 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
506 0x01);
507 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x08);
508 usleep_range(200, 200);
509 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x00);
510 break;
511 case SND_SOC_DAPM_PRE_PMD:
512 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10,
513 0x10);
514 usleep_range(20, 20);
515 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x08);
516 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x10);
517 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x00);
518 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
519 0x00);
Fred Oh54d24d72012-11-29 15:57:36 -0800520 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10,
521 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700522 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700523 break;
524 }
525 return 0;
526}
527
Bradley Rubina7096d02011-08-03 18:29:02 -0700528static int tabla_get_anc_slot(struct snd_kcontrol *kcontrol,
529 struct snd_ctl_elem_value *ucontrol)
530{
531 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
532 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
533 ucontrol->value.integer.value[0] = tabla->anc_slot;
534 return 0;
535}
536
537static int tabla_put_anc_slot(struct snd_kcontrol *kcontrol,
538 struct snd_ctl_elem_value *ucontrol)
539{
540 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
541 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
542 tabla->anc_slot = ucontrol->value.integer.value[0];
543 return 0;
544}
545
Damir Didjustoc6f83cb2012-12-03 00:54:14 -0800546static int tabla_get_anc_func(struct snd_kcontrol *kcontrol,
547 struct snd_ctl_elem_value *ucontrol)
548{
549 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
550 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Kuirong Wang84ee8802013-02-09 12:52:06 -0800551
552 mutex_lock(&codec->dapm.codec->mutex);
Damir Didjustoc6f83cb2012-12-03 00:54:14 -0800553 ucontrol->value.integer.value[0] = (tabla->anc_func == true ? 1 : 0);
Kuirong Wang84ee8802013-02-09 12:52:06 -0800554 mutex_unlock(&codec->dapm.codec->mutex);
Damir Didjustoc6f83cb2012-12-03 00:54:14 -0800555 return 0;
556}
557
558static int tabla_put_anc_func(struct snd_kcontrol *kcontrol,
559 struct snd_ctl_elem_value *ucontrol)
560{
561 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
562 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
563 struct snd_soc_dapm_context *dapm = &codec->dapm;
564
565 mutex_lock(&dapm->codec->mutex);
566
567 tabla->anc_func = (!ucontrol->value.integer.value[0] ? false : true);
568
569 dev_dbg(codec->dev, "%s: anc_func %x", __func__, tabla->anc_func);
570
571 if (tabla->anc_func == true) {
572 snd_soc_dapm_enable_pin(dapm, "ANC HPHR");
573 snd_soc_dapm_enable_pin(dapm, "ANC HPHL");
574 snd_soc_dapm_enable_pin(dapm, "ANC HEADPHONE");
575 snd_soc_dapm_disable_pin(dapm, "HPHR");
576 snd_soc_dapm_disable_pin(dapm, "HPHL");
577 snd_soc_dapm_disable_pin(dapm, "HEADPHONE");
578 } else {
579 snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
580 snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
581 snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE");
582 snd_soc_dapm_enable_pin(dapm, "HPHR");
583 snd_soc_dapm_enable_pin(dapm, "HPHL");
584 snd_soc_dapm_enable_pin(dapm, "HEADPHONE");
585 }
586 snd_soc_dapm_sync(dapm);
587 mutex_unlock(&dapm->codec->mutex);
588 return 0;
589}
590
Kiran Kandid2d86b52011-09-09 17:44:28 -0700591static int tabla_pa_gain_get(struct snd_kcontrol *kcontrol,
592 struct snd_ctl_elem_value *ucontrol)
593{
594 u8 ear_pa_gain;
595 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
596
597 ear_pa_gain = snd_soc_read(codec, TABLA_A_RX_EAR_GAIN);
598
599 ear_pa_gain = ear_pa_gain >> 5;
600
601 if (ear_pa_gain == 0x00) {
602 ucontrol->value.integer.value[0] = 0;
603 } else if (ear_pa_gain == 0x04) {
604 ucontrol->value.integer.value[0] = 1;
605 } else {
606 pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n",
607 __func__, ear_pa_gain);
608 return -EINVAL;
609 }
610
611 pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain);
612
613 return 0;
614}
615
616static int tabla_pa_gain_put(struct snd_kcontrol *kcontrol,
617 struct snd_ctl_elem_value *ucontrol)
618{
619 u8 ear_pa_gain;
620 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
621
622 pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__,
623 ucontrol->value.integer.value[0]);
624
625 switch (ucontrol->value.integer.value[0]) {
626 case 0:
627 ear_pa_gain = 0x00;
628 break;
629 case 1:
630 ear_pa_gain = 0x80;
631 break;
632 default:
633 return -EINVAL;
634 }
635
636 snd_soc_update_bits(codec, TABLA_A_RX_EAR_GAIN, 0xE0, ear_pa_gain);
637 return 0;
638}
639
Ben Romberger1f045a72011-11-04 10:14:57 -0700640static int tabla_get_iir_enable_audio_mixer(
641 struct snd_kcontrol *kcontrol,
642 struct snd_ctl_elem_value *ucontrol)
643{
644 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
645 int iir_idx = ((struct soc_multi_mixer_control *)
646 kcontrol->private_value)->reg;
647 int band_idx = ((struct soc_multi_mixer_control *)
648 kcontrol->private_value)->shift;
649
650 ucontrol->value.integer.value[0] =
651 snd_soc_read(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx)) &
652 (1 << band_idx);
653
654 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
655 iir_idx, band_idx,
656 (uint32_t)ucontrol->value.integer.value[0]);
657 return 0;
658}
659
660static int tabla_put_iir_enable_audio_mixer(
661 struct snd_kcontrol *kcontrol,
662 struct snd_ctl_elem_value *ucontrol)
663{
664 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
665 int iir_idx = ((struct soc_multi_mixer_control *)
666 kcontrol->private_value)->reg;
667 int band_idx = ((struct soc_multi_mixer_control *)
668 kcontrol->private_value)->shift;
669 int value = ucontrol->value.integer.value[0];
670
671 /* Mask first 5 bits, 6-8 are reserved */
672 snd_soc_update_bits(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx),
673 (1 << band_idx), (value << band_idx));
674
675 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
676 iir_idx, band_idx, value);
677 return 0;
678}
679static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
680 int iir_idx, int band_idx,
681 int coeff_idx)
682{
683 /* Address does not automatically update if reading */
Ben Romberger0915aae2012-02-06 23:32:43 -0800684 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700685 (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800686 (band_idx * BAND_MAX + coeff_idx) & 0x1F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700687
688 /* Mask bits top 2 bits since they are reserved */
689 return ((snd_soc_read(codec,
690 (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 24) |
691 (snd_soc_read(codec,
692 (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx)) << 16) |
693 (snd_soc_read(codec,
694 (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx)) << 8) |
695 (snd_soc_read(codec,
696 (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx)))) &
697 0x3FFFFFFF;
698}
699
700static int tabla_get_iir_band_audio_mixer(
701 struct snd_kcontrol *kcontrol,
702 struct snd_ctl_elem_value *ucontrol)
703{
704 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
705 int iir_idx = ((struct soc_multi_mixer_control *)
706 kcontrol->private_value)->reg;
707 int band_idx = ((struct soc_multi_mixer_control *)
708 kcontrol->private_value)->shift;
709
710 ucontrol->value.integer.value[0] =
711 get_iir_band_coeff(codec, iir_idx, band_idx, 0);
712 ucontrol->value.integer.value[1] =
713 get_iir_band_coeff(codec, iir_idx, band_idx, 1);
714 ucontrol->value.integer.value[2] =
715 get_iir_band_coeff(codec, iir_idx, band_idx, 2);
716 ucontrol->value.integer.value[3] =
717 get_iir_band_coeff(codec, iir_idx, band_idx, 3);
718 ucontrol->value.integer.value[4] =
719 get_iir_band_coeff(codec, iir_idx, band_idx, 4);
720
721 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
722 "%s: IIR #%d band #%d b1 = 0x%x\n"
723 "%s: IIR #%d band #%d b2 = 0x%x\n"
724 "%s: IIR #%d band #%d a1 = 0x%x\n"
725 "%s: IIR #%d band #%d a2 = 0x%x\n",
726 __func__, iir_idx, band_idx,
727 (uint32_t)ucontrol->value.integer.value[0],
728 __func__, iir_idx, band_idx,
729 (uint32_t)ucontrol->value.integer.value[1],
730 __func__, iir_idx, band_idx,
731 (uint32_t)ucontrol->value.integer.value[2],
732 __func__, iir_idx, band_idx,
733 (uint32_t)ucontrol->value.integer.value[3],
734 __func__, iir_idx, band_idx,
735 (uint32_t)ucontrol->value.integer.value[4]);
736 return 0;
737}
738
739static void set_iir_band_coeff(struct snd_soc_codec *codec,
740 int iir_idx, int band_idx,
741 int coeff_idx, uint32_t value)
742{
743 /* Mask top 3 bits, 6-8 are reserved */
744 /* Update address manually each time */
Ben Romberger0915aae2012-02-06 23:32:43 -0800745 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700746 (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800747 (band_idx * BAND_MAX + coeff_idx) & 0x1F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700748
749 /* Mask top 2 bits, 7-8 are reserved */
Ben Romberger0915aae2012-02-06 23:32:43 -0800750 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700751 (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800752 (value >> 24) & 0x3F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700753
754 /* Isolate 8bits at a time */
Ben Romberger0915aae2012-02-06 23:32:43 -0800755 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700756 (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800757 (value >> 16) & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700758
Ben Romberger0915aae2012-02-06 23:32:43 -0800759 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700760 (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800761 (value >> 8) & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700762
Ben Romberger0915aae2012-02-06 23:32:43 -0800763 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700764 (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800765 value & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700766}
767
768static int tabla_put_iir_band_audio_mixer(
769 struct snd_kcontrol *kcontrol,
770 struct snd_ctl_elem_value *ucontrol)
771{
772 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
773 int iir_idx = ((struct soc_multi_mixer_control *)
774 kcontrol->private_value)->reg;
775 int band_idx = ((struct soc_multi_mixer_control *)
776 kcontrol->private_value)->shift;
777
778 set_iir_band_coeff(codec, iir_idx, band_idx, 0,
779 ucontrol->value.integer.value[0]);
780 set_iir_band_coeff(codec, iir_idx, band_idx, 1,
781 ucontrol->value.integer.value[1]);
782 set_iir_band_coeff(codec, iir_idx, band_idx, 2,
783 ucontrol->value.integer.value[2]);
784 set_iir_band_coeff(codec, iir_idx, band_idx, 3,
785 ucontrol->value.integer.value[3]);
786 set_iir_band_coeff(codec, iir_idx, band_idx, 4,
787 ucontrol->value.integer.value[4]);
788
789 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
790 "%s: IIR #%d band #%d b1 = 0x%x\n"
791 "%s: IIR #%d band #%d b2 = 0x%x\n"
792 "%s: IIR #%d band #%d a1 = 0x%x\n"
793 "%s: IIR #%d band #%d a2 = 0x%x\n",
794 __func__, iir_idx, band_idx,
795 get_iir_band_coeff(codec, iir_idx, band_idx, 0),
796 __func__, iir_idx, band_idx,
797 get_iir_band_coeff(codec, iir_idx, band_idx, 1),
798 __func__, iir_idx, band_idx,
799 get_iir_band_coeff(codec, iir_idx, band_idx, 2),
800 __func__, iir_idx, band_idx,
801 get_iir_band_coeff(codec, iir_idx, band_idx, 3),
802 __func__, iir_idx, band_idx,
803 get_iir_band_coeff(codec, iir_idx, band_idx, 4));
804 return 0;
805}
806
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800807static int tabla_compander_gain_offset(
808 struct snd_soc_codec *codec, u32 enable,
Kuirong Wang678e4172012-06-26 15:35:22 -0700809 unsigned int reg, int mask, int event, u32 comp)
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800810{
811 int pa_mode = snd_soc_read(codec, reg) & mask;
812 int gain_offset = 0;
813 /* if PMU && enable is 1-> offset is 3
814 * if PMU && enable is 0-> offset is 0
815 * if PMD && pa_mode is PA -> offset is 0: PMU compander is off
816 * if PMD && pa_mode is comp -> offset is -3: PMU compander is on.
817 */
818
Kuirong Wang678e4172012-06-26 15:35:22 -0700819 if (SND_SOC_DAPM_EVENT_ON(event) && (enable != 0)) {
820 if (comp == COMPANDER_1)
821 gain_offset = TABLA_COMP_DIGITAL_GAIN_HP_OFFSET;
822 if (comp == COMPANDER_2)
823 gain_offset = TABLA_COMP_DIGITAL_GAIN_LINEOUT_OFFSET;
824 }
825 if (SND_SOC_DAPM_EVENT_OFF(event) && (pa_mode == 0)) {
826 if (comp == COMPANDER_1)
827 gain_offset = -TABLA_COMP_DIGITAL_GAIN_HP_OFFSET;
828 if (comp == COMPANDER_2)
829 gain_offset = -TABLA_COMP_DIGITAL_GAIN_LINEOUT_OFFSET;
830
831 }
832 pr_debug("%s: compander #%d gain_offset %d\n",
833 __func__, comp + 1, gain_offset);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800834 return gain_offset;
835}
836
837
838static int tabla_config_gain_compander(
839 struct snd_soc_codec *codec,
840 u32 compander, u32 enable, int event)
841{
842 int value = 0;
843 int mask = 1 << 4;
844 int gain = 0;
845 int gain_offset;
846 if (compander >= COMPANDER_MAX) {
847 pr_err("%s: Error, invalid compander channel\n", __func__);
848 return -EINVAL;
849 }
850
851 if ((enable == 0) || SND_SOC_DAPM_EVENT_OFF(event))
852 value = 1 << 4;
853
854 if (compander == COMPANDER_1) {
855 gain_offset = tabla_compander_gain_offset(codec, enable,
Kuirong Wang678e4172012-06-26 15:35:22 -0700856 TABLA_A_RX_HPH_L_GAIN, mask, event, compander);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800857 snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_GAIN, mask, value);
858 gain = snd_soc_read(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL);
859 snd_soc_update_bits(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
860 0xFF, gain - gain_offset);
861 gain_offset = tabla_compander_gain_offset(codec, enable,
Kuirong Wang678e4172012-06-26 15:35:22 -0700862 TABLA_A_RX_HPH_R_GAIN, mask, event, compander);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800863 snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_GAIN, mask, value);
864 gain = snd_soc_read(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL);
865 snd_soc_update_bits(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
866 0xFF, gain - gain_offset);
867 } else if (compander == COMPANDER_2) {
868 gain_offset = tabla_compander_gain_offset(codec, enable,
Kuirong Wang678e4172012-06-26 15:35:22 -0700869 TABLA_A_RX_LINE_1_GAIN, mask, event, compander);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800870 snd_soc_update_bits(codec, TABLA_A_RX_LINE_1_GAIN, mask, value);
871 gain = snd_soc_read(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL);
872 snd_soc_update_bits(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
873 0xFF, gain - gain_offset);
874 gain_offset = tabla_compander_gain_offset(codec, enable,
Kuirong Wang678e4172012-06-26 15:35:22 -0700875 TABLA_A_RX_LINE_3_GAIN, mask, event, compander);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800876 snd_soc_update_bits(codec, TABLA_A_RX_LINE_3_GAIN, mask, value);
877 gain = snd_soc_read(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL);
878 snd_soc_update_bits(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
879 0xFF, gain - gain_offset);
880 gain_offset = tabla_compander_gain_offset(codec, enable,
Kuirong Wang678e4172012-06-26 15:35:22 -0700881 TABLA_A_RX_LINE_2_GAIN, mask, event, compander);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800882 snd_soc_update_bits(codec, TABLA_A_RX_LINE_2_GAIN, mask, value);
883 gain = snd_soc_read(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL);
884 snd_soc_update_bits(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
885 0xFF, gain - gain_offset);
886 gain_offset = tabla_compander_gain_offset(codec, enable,
Kuirong Wang678e4172012-06-26 15:35:22 -0700887 TABLA_A_RX_LINE_4_GAIN, mask, event, compander);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800888 snd_soc_update_bits(codec, TABLA_A_RX_LINE_4_GAIN, mask, value);
889 gain = snd_soc_read(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL);
890 snd_soc_update_bits(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
891 0xFF, gain - gain_offset);
892 }
893 return 0;
894}
895static int tabla_get_compander(struct snd_kcontrol *kcontrol,
896 struct snd_ctl_elem_value *ucontrol)
897{
898
899 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
900 int comp = ((struct soc_multi_mixer_control *)
901 kcontrol->private_value)->max;
902 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
903
904 ucontrol->value.integer.value[0] = tabla->comp_enabled[comp];
905
906 return 0;
907}
908
909static int tabla_set_compander(struct snd_kcontrol *kcontrol,
910 struct snd_ctl_elem_value *ucontrol)
911{
912 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
913 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
914 int comp = ((struct soc_multi_mixer_control *)
915 kcontrol->private_value)->max;
916 int value = ucontrol->value.integer.value[0];
Kuirong Wang678e4172012-06-26 15:35:22 -0700917 pr_debug("%s: compander #%d enable %d\n",
918 __func__, comp + 1, value);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800919 if (value == tabla->comp_enabled[comp]) {
920 pr_debug("%s: compander #%d enable %d no change\n",
Kuirong Wang678e4172012-06-26 15:35:22 -0700921 __func__, comp + 1, value);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800922 return 0;
923 }
924 tabla->comp_enabled[comp] = value;
925 return 0;
926}
927
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800928static int tabla_config_compander(struct snd_soc_dapm_widget *w,
929 struct snd_kcontrol *kcontrol,
930 int event)
931{
932 struct snd_soc_codec *codec = w->codec;
933 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
934 u32 rate = tabla->comp_fs[w->shift];
Kuirong Wang84ee8802013-02-09 12:52:06 -0800935
936 pr_debug("%s: compander #%d enable %d event %d widget name %s\n",
Kuirong Wang678e4172012-06-26 15:35:22 -0700937 __func__, w->shift + 1,
Kuirong Wang84ee8802013-02-09 12:52:06 -0800938 tabla->comp_enabled[w->shift], event , w->name);
939 if (tabla->comp_enabled[w->shift] == 0)
940 goto rtn;
941 if ((w->shift == COMPANDER_1) && (tabla->anc_func)) {
942 pr_debug("%s: ANC is enabled so compander #%d cannot be enabled\n",
943 __func__, w->shift + 1);
944 goto rtn;
945 }
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800946 switch (event) {
947 case SND_SOC_DAPM_PRE_PMU:
Kuirong Wang84ee8802013-02-09 12:52:06 -0800948 /* Update compander sample rate */
949 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_FS_CFG +
950 w->shift * 8, 0x07, rate);
951 /* Enable both L/R compander clocks */
952 snd_soc_update_bits(codec,
953 TABLA_A_CDC_CLK_RX_B2_CTL,
954 1 << comp_shift[w->shift],
955 1 << comp_shift[w->shift]);
956 /* Toggle compander reset bits */
957 snd_soc_update_bits(codec,
958 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
959 1 << comp_shift[w->shift],
960 1 << comp_shift[w->shift]);
961 snd_soc_update_bits(codec,
962 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
963 1 << comp_shift[w->shift], 0);
964 tabla_config_gain_compander(codec, w->shift, 1, event);
965 /* Compander enable -> 0x370/0x378 */
966 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
967 w->shift * 8, 0x03, 0x03);
968 /* Update the RMS meter resampling */
969 snd_soc_update_bits(codec,
970 TABLA_A_CDC_COMP1_B3_CTL +
971 w->shift * 8, 0xFF, 0x01);
972 snd_soc_update_bits(codec,
973 TABLA_A_CDC_COMP1_B2_CTL +
974 w->shift * 8, 0xF0, 0x50);
975 usleep_range(COMP_BRINGUP_WAIT_TIME, COMP_BRINGUP_WAIT_TIME);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800976 break;
977 case SND_SOC_DAPM_POST_PMU:
Kuirong Wang84ee8802013-02-09 12:52:06 -0800978 /* Set sample rate dependent paramater */
979 if (w->shift == COMPANDER_1) {
980 snd_soc_update_bits(codec,
981 TABLA_A_CDC_CLSG_CTL,
982 0x11, 0x00);
983 snd_soc_write(codec,
984 TABLA_A_CDC_CONN_CLSG_CTL, 0x11);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800985 }
Kuirong Wang84ee8802013-02-09 12:52:06 -0800986 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL +
987 w->shift * 8, 0x0F,
988 comp_samp_params[rate].peak_det_timeout);
989 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL +
990 w->shift * 8, 0xF0,
991 comp_samp_params[rate].rms_meter_div_fact);
992 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B3_CTL +
993 w->shift * 8, 0xFF,
994 comp_samp_params[rate].rms_meter_resamp_fact);
995 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
996 w->shift * 8, 0x38,
997 comp_samp_params[rate].shutdown_timeout);
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800998 break;
999 case SND_SOC_DAPM_PRE_PMD:
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001000 break;
1001 case SND_SOC_DAPM_POST_PMD:
Kuirong Wang84ee8802013-02-09 12:52:06 -08001002 /* Disable the compander */
1003 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
1004 w->shift * 8, 0x03, 0x00);
1005 /* Toggle compander reset bits */
1006 snd_soc_update_bits(codec,
1007 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
1008 1 << comp_shift[w->shift],
1009 1 << comp_shift[w->shift]);
1010 snd_soc_update_bits(codec,
1011 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
1012 1 << comp_shift[w->shift], 0);
1013 /* Turn off the clock for compander in pair */
1014 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_B2_CTL,
1015 0x03 << comp_shift[w->shift], 0);
1016 /* Restore the gain */
1017 tabla_config_gain_compander(codec, w->shift,
1018 tabla->comp_enabled[w->shift],
1019 event);
1020 if (w->shift == COMPANDER_1) {
Kuirong Wang678e4172012-06-26 15:35:22 -07001021 snd_soc_update_bits(codec,
Kuirong Wang84ee8802013-02-09 12:52:06 -08001022 TABLA_A_CDC_CLSG_CTL,
1023 0x11, 0x11);
1024 snd_soc_write(codec,
1025 TABLA_A_CDC_CONN_CLSG_CTL, 0x14);
Kuirong Wang678e4172012-06-26 15:35:22 -07001026 }
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001027 break;
1028 }
Kuirong Wang84ee8802013-02-09 12:52:06 -08001029rtn:
1030 return 0;
1031}
1032
1033static int tabla_codec_hphr_dem_input_selection(struct snd_soc_dapm_widget *w,
1034 struct snd_kcontrol *kcontrol,
1035 int event)
1036{
1037 struct snd_soc_codec *codec = w->codec;
1038 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1039
1040 pr_debug("%s: compander#1->enable(%d) reg(0x%x = 0x%x) event(%d)\n",
1041 __func__, tabla->comp_enabled[COMPANDER_1],
1042 TABLA_A_CDC_RX1_B6_CTL,
1043 snd_soc_read(codec, TABLA_A_CDC_RX1_B6_CTL), event);
1044 switch (event) {
1045 case SND_SOC_DAPM_POST_PMU:
1046 if (tabla->comp_enabled[COMPANDER_1] && !tabla->anc_func)
1047 snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL,
1048 1 << w->shift, 0);
1049 else
1050 snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL,
1051 1 << w->shift, 1 << w->shift);
1052 break;
1053 case SND_SOC_DAPM_POST_PMD:
1054 snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL,
1055 1 << w->shift, 0);
1056 break;
1057 default:
1058 return -EINVAL;
1059 }
1060 return 0;
1061}
1062
1063static int tabla_codec_hphl_dem_input_selection(struct snd_soc_dapm_widget *w,
1064 struct snd_kcontrol *kcontrol,
1065 int event)
1066{
1067 struct snd_soc_codec *codec = w->codec;
1068 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1069
1070 pr_debug("%s: compander#1->enable(%d) reg(0x%x = 0x%x) event(%d)\n",
1071 __func__, tabla->comp_enabled[COMPANDER_1],
1072 TABLA_A_CDC_RX2_B6_CTL,
1073 snd_soc_read(codec, TABLA_A_CDC_RX2_B6_CTL), event);
1074 switch (event) {
1075 case SND_SOC_DAPM_POST_PMU:
1076 if (tabla->comp_enabled[COMPANDER_1] && !tabla->anc_func)
1077 snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL,
1078 1 << w->shift, 0);
1079 else
1080 snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL,
1081 1 << w->shift, 1 << w->shift);
1082 break;
1083 case SND_SOC_DAPM_POST_PMD:
1084 snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL,
1085 1 << w->shift, 0);
1086 break;
1087 default:
1088 return -EINVAL;
1089 }
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001090 return 0;
1091}
1092
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08001093static const char *const tabla_anc_func_text[] = {"OFF", "ON"};
1094static const struct soc_enum tabla_anc_func_enum =
1095 SOC_ENUM_SINGLE_EXT(2, tabla_anc_func_text);
1096
Kiran Kandid2d86b52011-09-09 17:44:28 -07001097static const char *tabla_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"};
1098static const struct soc_enum tabla_ear_pa_gain_enum[] = {
1099 SOC_ENUM_SINGLE_EXT(2, tabla_ear_pa_gain_text),
1100};
1101
Santosh Mardi024010f2011-10-18 06:27:21 +05301102/*cut of frequency for high pass filter*/
1103static const char *cf_text[] = {
1104 "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz"
1105};
1106
1107static const struct soc_enum cf_dec1_enum =
1108 SOC_ENUM_SINGLE(TABLA_A_CDC_TX1_MUX_CTL, 4, 3, cf_text);
1109
1110static const struct soc_enum cf_dec2_enum =
1111 SOC_ENUM_SINGLE(TABLA_A_CDC_TX2_MUX_CTL, 4, 3, cf_text);
1112
1113static const struct soc_enum cf_dec3_enum =
1114 SOC_ENUM_SINGLE(TABLA_A_CDC_TX3_MUX_CTL, 4, 3, cf_text);
1115
1116static const struct soc_enum cf_dec4_enum =
1117 SOC_ENUM_SINGLE(TABLA_A_CDC_TX4_MUX_CTL, 4, 3, cf_text);
1118
1119static const struct soc_enum cf_dec5_enum =
1120 SOC_ENUM_SINGLE(TABLA_A_CDC_TX5_MUX_CTL, 4, 3, cf_text);
1121
1122static const struct soc_enum cf_dec6_enum =
1123 SOC_ENUM_SINGLE(TABLA_A_CDC_TX6_MUX_CTL, 4, 3, cf_text);
1124
1125static const struct soc_enum cf_dec7_enum =
1126 SOC_ENUM_SINGLE(TABLA_A_CDC_TX7_MUX_CTL, 4, 3, cf_text);
1127
1128static const struct soc_enum cf_dec8_enum =
1129 SOC_ENUM_SINGLE(TABLA_A_CDC_TX8_MUX_CTL, 4, 3, cf_text);
1130
1131static const struct soc_enum cf_dec9_enum =
1132 SOC_ENUM_SINGLE(TABLA_A_CDC_TX9_MUX_CTL, 4, 3, cf_text);
1133
1134static const struct soc_enum cf_dec10_enum =
1135 SOC_ENUM_SINGLE(TABLA_A_CDC_TX10_MUX_CTL, 4, 3, cf_text);
1136
1137static const struct soc_enum cf_rxmix1_enum =
1138 SOC_ENUM_SINGLE(TABLA_A_CDC_RX1_B4_CTL, 1, 3, cf_text);
1139
1140static const struct soc_enum cf_rxmix2_enum =
1141 SOC_ENUM_SINGLE(TABLA_A_CDC_RX2_B4_CTL, 1, 3, cf_text);
1142
1143static const struct soc_enum cf_rxmix3_enum =
1144 SOC_ENUM_SINGLE(TABLA_A_CDC_RX3_B4_CTL, 1, 3, cf_text);
1145
1146static const struct soc_enum cf_rxmix4_enum =
1147 SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B4_CTL, 1, 3, cf_text);
1148
1149static const struct soc_enum cf_rxmix5_enum =
1150 SOC_ENUM_SINGLE(TABLA_A_CDC_RX5_B4_CTL, 1, 3, cf_text)
1151;
1152static const struct soc_enum cf_rxmix6_enum =
1153 SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B4_CTL, 1, 3, cf_text);
1154
1155static const struct soc_enum cf_rxmix7_enum =
1156 SOC_ENUM_SINGLE(TABLA_A_CDC_RX7_B4_CTL, 1, 3, cf_text);
1157
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001158static const struct snd_kcontrol_new tabla_snd_controls[] = {
Kiran Kandid2d86b52011-09-09 17:44:28 -07001159
1160 SOC_ENUM_EXT("EAR PA Gain", tabla_ear_pa_gain_enum[0],
1161 tabla_pa_gain_get, tabla_pa_gain_put),
1162
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001163 SOC_SINGLE_TLV("LINEOUT1 Volume", TABLA_A_RX_LINE_1_GAIN, 0, 12, 1,
1164 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001165 SOC_SINGLE_TLV("LINEOUT2 Volume", TABLA_A_RX_LINE_2_GAIN, 0, 12, 1,
1166 line_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001167 SOC_SINGLE_TLV("LINEOUT3 Volume", TABLA_A_RX_LINE_3_GAIN, 0, 12, 1,
1168 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001169 SOC_SINGLE_TLV("LINEOUT4 Volume", TABLA_A_RX_LINE_4_GAIN, 0, 12, 1,
1170 line_gain),
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001171 SOC_SINGLE_TLV("LINEOUT5 Volume", TABLA_A_RX_LINE_5_GAIN, 0, 12, 1,
1172 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001173
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001174 SOC_SINGLE_TLV("HPHL Volume", TABLA_A_RX_HPH_L_GAIN, 0, 12, 1,
1175 line_gain),
1176 SOC_SINGLE_TLV("HPHR Volume", TABLA_A_RX_HPH_R_GAIN, 0, 12, 1,
1177 line_gain),
1178
Bradley Rubin410383f2011-07-22 13:44:23 -07001179 SOC_SINGLE_S8_TLV("RX1 Digital Volume", TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
1180 -84, 40, digital_gain),
1181 SOC_SINGLE_S8_TLV("RX2 Digital Volume", TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
1182 -84, 40, digital_gain),
1183 SOC_SINGLE_S8_TLV("RX3 Digital Volume", TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
1184 -84, 40, digital_gain),
1185 SOC_SINGLE_S8_TLV("RX4 Digital Volume", TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
1186 -84, 40, digital_gain),
1187 SOC_SINGLE_S8_TLV("RX5 Digital Volume", TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
1188 -84, 40, digital_gain),
1189 SOC_SINGLE_S8_TLV("RX6 Digital Volume", TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
1190 -84, 40, digital_gain),
Neema Shettyd3a89262012-02-16 10:23:50 -08001191 SOC_SINGLE_S8_TLV("RX7 Digital Volume", TABLA_A_CDC_RX7_VOL_CTL_B2_CTL,
1192 -84, 40, digital_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001193
Bradley Rubin410383f2011-07-22 13:44:23 -07001194 SOC_SINGLE_S8_TLV("DEC1 Volume", TABLA_A_CDC_TX1_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001195 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -07001196 SOC_SINGLE_S8_TLV("DEC2 Volume", TABLA_A_CDC_TX2_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001197 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -07001198 SOC_SINGLE_S8_TLV("DEC3 Volume", TABLA_A_CDC_TX3_VOL_CTL_GAIN, -84, 40,
1199 digital_gain),
1200 SOC_SINGLE_S8_TLV("DEC4 Volume", TABLA_A_CDC_TX4_VOL_CTL_GAIN, -84, 40,
1201 digital_gain),
1202 SOC_SINGLE_S8_TLV("DEC5 Volume", TABLA_A_CDC_TX5_VOL_CTL_GAIN, -84, 40,
1203 digital_gain),
1204 SOC_SINGLE_S8_TLV("DEC6 Volume", TABLA_A_CDC_TX6_VOL_CTL_GAIN, -84, 40,
1205 digital_gain),
1206 SOC_SINGLE_S8_TLV("DEC7 Volume", TABLA_A_CDC_TX7_VOL_CTL_GAIN, -84, 40,
1207 digital_gain),
1208 SOC_SINGLE_S8_TLV("DEC8 Volume", TABLA_A_CDC_TX8_VOL_CTL_GAIN, -84, 40,
1209 digital_gain),
1210 SOC_SINGLE_S8_TLV("DEC9 Volume", TABLA_A_CDC_TX9_VOL_CTL_GAIN, -84, 40,
1211 digital_gain),
1212 SOC_SINGLE_S8_TLV("DEC10 Volume", TABLA_A_CDC_TX10_VOL_CTL_GAIN, -84,
1213 40, digital_gain),
Patrick Lai29006372011-09-28 17:57:42 -07001214 SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TABLA_A_CDC_IIR1_GAIN_B1_CTL, -84,
1215 40, digital_gain),
1216 SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TABLA_A_CDC_IIR1_GAIN_B2_CTL, -84,
1217 40, digital_gain),
1218 SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TABLA_A_CDC_IIR1_GAIN_B3_CTL, -84,
1219 40, digital_gain),
1220 SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TABLA_A_CDC_IIR1_GAIN_B4_CTL, -84,
1221 40, digital_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001222 SOC_SINGLE_TLV("ADC1 Volume", TABLA_A_TX_1_2_EN, 5, 3, 0, analog_gain),
1223 SOC_SINGLE_TLV("ADC2 Volume", TABLA_A_TX_1_2_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001224 SOC_SINGLE_TLV("ADC3 Volume", TABLA_A_TX_3_4_EN, 5, 3, 0, analog_gain),
1225 SOC_SINGLE_TLV("ADC4 Volume", TABLA_A_TX_3_4_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001226 SOC_SINGLE_TLV("ADC5 Volume", TABLA_A_TX_5_6_EN, 5, 3, 0, analog_gain),
1227 SOC_SINGLE_TLV("ADC6 Volume", TABLA_A_TX_5_6_EN, 1, 3, 0, analog_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001228
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001229 SOC_SINGLE_TLV("AUX_PGA_LEFT Volume", TABLA_A_AUX_L_GAIN, 0, 39, 0,
1230 aux_pga_gain),
1231 SOC_SINGLE_TLV("AUX_PGA_RIGHT Volume", TABLA_A_AUX_R_GAIN, 0, 39, 0,
1232 aux_pga_gain),
1233
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001234 SOC_SINGLE("MICBIAS1 CAPLESS Switch", TABLA_A_MICB_1_CTL, 4, 1, 1),
Santosh Mardi680b41e2011-11-22 16:51:16 -08001235 SOC_SINGLE("MICBIAS2 CAPLESS Switch", TABLA_A_MICB_2_CTL, 4, 1, 1),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001236 SOC_SINGLE("MICBIAS3 CAPLESS Switch", TABLA_A_MICB_3_CTL, 4, 1, 1),
Bradley Rubina7096d02011-08-03 18:29:02 -07001237
1238 SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 0, 100, tabla_get_anc_slot,
1239 tabla_put_anc_slot),
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08001240 SOC_ENUM_EXT("ANC Function", tabla_anc_func_enum, tabla_get_anc_func,
1241 tabla_put_anc_func),
Santosh Mardi024010f2011-10-18 06:27:21 +05301242 SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
1243 SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
1244 SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
1245 SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
1246 SOC_ENUM("TX5 HPF cut off", cf_dec5_enum),
1247 SOC_ENUM("TX6 HPF cut off", cf_dec6_enum),
1248 SOC_ENUM("TX7 HPF cut off", cf_dec7_enum),
1249 SOC_ENUM("TX8 HPF cut off", cf_dec8_enum),
1250 SOC_ENUM("TX9 HPF cut off", cf_dec9_enum),
1251 SOC_ENUM("TX10 HPF cut off", cf_dec10_enum),
1252
1253 SOC_SINGLE("TX1 HPF Switch", TABLA_A_CDC_TX1_MUX_CTL, 3, 1, 0),
1254 SOC_SINGLE("TX2 HPF Switch", TABLA_A_CDC_TX2_MUX_CTL, 3, 1, 0),
1255 SOC_SINGLE("TX3 HPF Switch", TABLA_A_CDC_TX3_MUX_CTL, 3, 1, 0),
1256 SOC_SINGLE("TX4 HPF Switch", TABLA_A_CDC_TX4_MUX_CTL, 3, 1, 0),
1257 SOC_SINGLE("TX5 HPF Switch", TABLA_A_CDC_TX5_MUX_CTL, 3, 1, 0),
1258 SOC_SINGLE("TX6 HPF Switch", TABLA_A_CDC_TX6_MUX_CTL, 3, 1, 0),
1259 SOC_SINGLE("TX7 HPF Switch", TABLA_A_CDC_TX7_MUX_CTL, 3, 1, 0),
1260 SOC_SINGLE("TX8 HPF Switch", TABLA_A_CDC_TX8_MUX_CTL, 3, 1, 0),
1261 SOC_SINGLE("TX9 HPF Switch", TABLA_A_CDC_TX9_MUX_CTL, 3, 1, 0),
1262 SOC_SINGLE("TX10 HPF Switch", TABLA_A_CDC_TX10_MUX_CTL, 3, 1, 0),
1263
1264 SOC_SINGLE("RX1 HPF Switch", TABLA_A_CDC_RX1_B5_CTL, 2, 1, 0),
1265 SOC_SINGLE("RX2 HPF Switch", TABLA_A_CDC_RX2_B5_CTL, 2, 1, 0),
1266 SOC_SINGLE("RX3 HPF Switch", TABLA_A_CDC_RX3_B5_CTL, 2, 1, 0),
1267 SOC_SINGLE("RX4 HPF Switch", TABLA_A_CDC_RX4_B5_CTL, 2, 1, 0),
1268 SOC_SINGLE("RX5 HPF Switch", TABLA_A_CDC_RX5_B5_CTL, 2, 1, 0),
1269 SOC_SINGLE("RX6 HPF Switch", TABLA_A_CDC_RX6_B5_CTL, 2, 1, 0),
1270 SOC_SINGLE("RX7 HPF Switch", TABLA_A_CDC_RX7_B5_CTL, 2, 1, 0),
1271
1272 SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum),
1273 SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum),
1274 SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum),
1275 SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum),
1276 SOC_ENUM("RX5 HPF cut off", cf_rxmix5_enum),
1277 SOC_ENUM("RX6 HPF cut off", cf_rxmix6_enum),
1278 SOC_ENUM("RX7 HPF cut off", cf_rxmix7_enum),
Ben Romberger1f045a72011-11-04 10:14:57 -07001279
1280 SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
1281 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1282 SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
1283 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1284 SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
1285 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1286 SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
1287 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1288 SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
1289 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1290 SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0,
1291 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1292 SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0,
1293 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1294 SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0,
1295 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1296 SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0,
1297 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1298 SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0,
1299 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1300
1301 SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
1302 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1303 SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
1304 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1305 SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
1306 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1307 SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
1308 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1309 SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
1310 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1311 SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5,
1312 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1313 SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5,
1314 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1315 SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5,
1316 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1317 SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5,
1318 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1319 SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5,
1320 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001321 SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, 1, COMPANDER_1, 0,
1322 tabla_get_compander, tabla_set_compander),
1323 SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, 0, COMPANDER_2, 0,
1324 tabla_get_compander, tabla_set_compander),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001325};
1326
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08001327static const struct snd_kcontrol_new tabla_1_x_snd_controls[] = {
1328 SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_1_A_MICB_4_CTL, 4, 1, 1),
1329};
1330
1331static const struct snd_kcontrol_new tabla_2_higher_snd_controls[] = {
1332 SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_2_A_MICB_4_CTL, 4, 1, 1),
1333};
1334
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001335static const char *rx_mix1_text[] = {
1336 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
1337 "RX5", "RX6", "RX7"
1338};
1339
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001340static const char *rx_mix2_text[] = {
1341 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2"
1342};
1343
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001344static const char *rx_dsm_text[] = {
1345 "CIC_OUT", "DSM_INV"
1346};
1347
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001348static const char *sb_tx1_mux_text[] = {
1349 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1350 "DEC1"
1351};
1352
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001353static const char *sb_tx2_mux_text[] = {
1354 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1355 "DEC2"
1356};
1357
1358static const char *sb_tx3_mux_text[] = {
1359 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1360 "DEC3"
1361};
1362
1363static const char *sb_tx4_mux_text[] = {
1364 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1365 "DEC4"
1366};
1367
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001368static const char *sb_tx5_mux_text[] = {
1369 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1370 "DEC5"
1371};
1372
1373static const char *sb_tx6_mux_text[] = {
1374 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1375 "DEC6"
1376};
1377
1378static const char const *sb_tx7_to_tx10_mux_text[] = {
1379 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1380 "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
1381 "DEC9", "DEC10"
1382};
1383
1384static const char *dec1_mux_text[] = {
1385 "ZERO", "DMIC1", "ADC6",
1386};
1387
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001388static const char *dec2_mux_text[] = {
1389 "ZERO", "DMIC2", "ADC5",
1390};
1391
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001392static const char *dec3_mux_text[] = {
1393 "ZERO", "DMIC3", "ADC4",
1394};
1395
1396static const char *dec4_mux_text[] = {
1397 "ZERO", "DMIC4", "ADC3",
1398};
1399
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001400static const char *dec5_mux_text[] = {
1401 "ZERO", "DMIC5", "ADC2",
1402};
1403
1404static const char *dec6_mux_text[] = {
1405 "ZERO", "DMIC6", "ADC1",
1406};
1407
1408static const char const *dec7_mux_text[] = {
1409 "ZERO", "DMIC1", "DMIC6", "ADC1", "ADC6", "ANC1_FB", "ANC2_FB",
1410};
1411
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001412static const char *dec8_mux_text[] = {
1413 "ZERO", "DMIC2", "DMIC5", "ADC2", "ADC5",
1414};
1415
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001416static const char *dec9_mux_text[] = {
1417 "ZERO", "DMIC4", "DMIC5", "ADC2", "ADC3", "ADCMB", "ANC1_FB", "ANC2_FB",
1418};
1419
1420static const char *dec10_mux_text[] = {
1421 "ZERO", "DMIC3", "DMIC6", "ADC1", "ADC4", "ADCMB", "ANC1_FB", "ANC2_FB",
1422};
1423
Bradley Rubin229c6a52011-07-12 16:18:48 -07001424static const char const *anc_mux_text[] = {
1425 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6", "ADC_MB",
1426 "RSVD_1", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", "DMIC6"
1427};
1428
1429static const char const *anc1_fb_mux_text[] = {
1430 "ZERO", "EAR_HPH_L", "EAR_LINE_1",
1431};
1432
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07001433static const char *const iir_inp1_text[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001434 "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
1435 "DEC9", "DEC10", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7"
1436};
1437
1438static const struct soc_enum rx_mix1_inp1_chain_enum =
1439 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_mix1_text);
1440
Bradley Rubin229c6a52011-07-12 16:18:48 -07001441static const struct soc_enum rx_mix1_inp2_chain_enum =
1442 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_mix1_text);
1443
Kiran Kandia9fffe92012-05-20 23:42:30 -07001444static const struct soc_enum rx_mix1_inp3_chain_enum =
1445 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B2_CTL, 0, 12, rx_mix1_text);
1446
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001447static const struct soc_enum rx2_mix1_inp1_chain_enum =
1448 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_mix1_text);
1449
Bradley Rubin229c6a52011-07-12 16:18:48 -07001450static const struct soc_enum rx2_mix1_inp2_chain_enum =
1451 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_mix1_text);
1452
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001453static const struct soc_enum rx3_mix1_inp1_chain_enum =
1454 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 0, 12, rx_mix1_text);
1455
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001456static const struct soc_enum rx3_mix1_inp2_chain_enum =
1457 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 4, 12, rx_mix1_text);
1458
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001459static const struct soc_enum rx4_mix1_inp1_chain_enum =
1460 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 0, 12, rx_mix1_text);
1461
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001462static const struct soc_enum rx4_mix1_inp2_chain_enum =
1463 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 4, 12, rx_mix1_text);
1464
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001465static const struct soc_enum rx5_mix1_inp1_chain_enum =
1466 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 0, 12, rx_mix1_text);
1467
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001468static const struct soc_enum rx5_mix1_inp2_chain_enum =
1469 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 4, 12, rx_mix1_text);
1470
1471static const struct soc_enum rx6_mix1_inp1_chain_enum =
1472 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 0, 12, rx_mix1_text);
1473
1474static const struct soc_enum rx6_mix1_inp2_chain_enum =
1475 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 4, 12, rx_mix1_text);
1476
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001477static const struct soc_enum rx7_mix1_inp1_chain_enum =
1478 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 0, 12, rx_mix1_text);
1479
1480static const struct soc_enum rx7_mix1_inp2_chain_enum =
1481 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 4, 12, rx_mix1_text);
1482
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001483static const struct soc_enum rx1_mix2_inp1_chain_enum =
1484 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text);
1485
1486static const struct soc_enum rx1_mix2_inp2_chain_enum =
1487 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text);
1488
1489static const struct soc_enum rx2_mix2_inp1_chain_enum =
1490 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text);
1491
1492static const struct soc_enum rx2_mix2_inp2_chain_enum =
1493 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text);
1494
1495static const struct soc_enum rx3_mix2_inp1_chain_enum =
1496 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 0, 5, rx_mix2_text);
1497
1498static const struct soc_enum rx3_mix2_inp2_chain_enum =
1499 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 3, 5, rx_mix2_text);
1500
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001501static const struct soc_enum rx4_dsm_enum =
1502 SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B6_CTL, 4, 2, rx_dsm_text);
1503
1504static const struct soc_enum rx6_dsm_enum =
1505 SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B6_CTL, 4, 2, rx_dsm_text);
1506
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001507static const struct soc_enum sb_tx1_mux_enum =
1508 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text);
1509
1510static const struct soc_enum sb_tx2_mux_enum =
1511 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0, 9, sb_tx2_mux_text);
1512
1513static const struct soc_enum sb_tx3_mux_enum =
1514 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0, 9, sb_tx3_mux_text);
1515
1516static const struct soc_enum sb_tx4_mux_enum =
1517 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0, 9, sb_tx4_mux_text);
1518
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001519static const struct soc_enum sb_tx5_mux_enum =
1520 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text);
1521
1522static const struct soc_enum sb_tx6_mux_enum =
1523 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0, 9, sb_tx6_mux_text);
1524
1525static const struct soc_enum sb_tx7_mux_enum =
1526 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0, 18,
1527 sb_tx7_to_tx10_mux_text);
1528
1529static const struct soc_enum sb_tx8_mux_enum =
1530 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0, 18,
1531 sb_tx7_to_tx10_mux_text);
1532
Kiran Kandi3426e512011-09-13 22:50:10 -07001533static const struct soc_enum sb_tx9_mux_enum =
1534 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0, 18,
1535 sb_tx7_to_tx10_mux_text);
1536
1537static const struct soc_enum sb_tx10_mux_enum =
1538 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0, 18,
1539 sb_tx7_to_tx10_mux_text);
1540
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001541static const struct soc_enum dec1_mux_enum =
1542 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 0, 3, dec1_mux_text);
1543
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001544static const struct soc_enum dec2_mux_enum =
1545 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 2, 3, dec2_mux_text);
1546
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001547static const struct soc_enum dec3_mux_enum =
1548 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 4, 3, dec3_mux_text);
1549
1550static const struct soc_enum dec4_mux_enum =
1551 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 6, 3, dec4_mux_text);
1552
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001553static const struct soc_enum dec5_mux_enum =
1554 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 0, 3, dec5_mux_text);
1555
1556static const struct soc_enum dec6_mux_enum =
1557 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 2, 3, dec6_mux_text);
1558
1559static const struct soc_enum dec7_mux_enum =
1560 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 4, 7, dec7_mux_text);
1561
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001562static const struct soc_enum dec8_mux_enum =
1563 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 0, 7, dec8_mux_text);
1564
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001565static const struct soc_enum dec9_mux_enum =
1566 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 3, 8, dec9_mux_text);
1567
1568static const struct soc_enum dec10_mux_enum =
1569 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B4_CTL, 0, 8, dec10_mux_text);
1570
Bradley Rubin229c6a52011-07-12 16:18:48 -07001571static const struct soc_enum anc1_mux_enum =
1572 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 0, 16, anc_mux_text);
1573
1574static const struct soc_enum anc2_mux_enum =
1575 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 4, 16, anc_mux_text);
1576
1577static const struct soc_enum anc1_fb_mux_enum =
1578 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text);
1579
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001580static const struct soc_enum iir1_inp1_mux_enum =
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07001581 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ1_B1_CTL, 0, 18, iir_inp1_text);
1582
1583static const struct soc_enum iir2_inp1_mux_enum =
1584 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ2_B1_CTL, 0, 18, iir_inp1_text);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001585
1586static const struct snd_kcontrol_new rx_mix1_inp1_mux =
1587 SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum);
1588
Bradley Rubin229c6a52011-07-12 16:18:48 -07001589static const struct snd_kcontrol_new rx_mix1_inp2_mux =
1590 SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum);
1591
Kiran Kandia9fffe92012-05-20 23:42:30 -07001592static const struct snd_kcontrol_new rx_mix1_inp3_mux =
1593 SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum);
1594
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001595static const struct snd_kcontrol_new rx2_mix1_inp1_mux =
1596 SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum);
1597
Bradley Rubin229c6a52011-07-12 16:18:48 -07001598static const struct snd_kcontrol_new rx2_mix1_inp2_mux =
1599 SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum);
1600
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001601static const struct snd_kcontrol_new rx3_mix1_inp1_mux =
1602 SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum);
1603
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001604static const struct snd_kcontrol_new rx3_mix1_inp2_mux =
1605 SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum);
1606
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001607static const struct snd_kcontrol_new rx4_mix1_inp1_mux =
1608 SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum);
1609
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001610static const struct snd_kcontrol_new rx4_mix1_inp2_mux =
1611 SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum);
1612
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001613static const struct snd_kcontrol_new rx5_mix1_inp1_mux =
1614 SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum);
1615
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001616static const struct snd_kcontrol_new rx5_mix1_inp2_mux =
1617 SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum);
1618
1619static const struct snd_kcontrol_new rx6_mix1_inp1_mux =
1620 SOC_DAPM_ENUM("RX6 MIX1 INP1 Mux", rx6_mix1_inp1_chain_enum);
1621
1622static const struct snd_kcontrol_new rx6_mix1_inp2_mux =
1623 SOC_DAPM_ENUM("RX6 MIX1 INP2 Mux", rx6_mix1_inp2_chain_enum);
1624
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001625static const struct snd_kcontrol_new rx7_mix1_inp1_mux =
1626 SOC_DAPM_ENUM("RX7 MIX1 INP1 Mux", rx7_mix1_inp1_chain_enum);
1627
1628static const struct snd_kcontrol_new rx7_mix1_inp2_mux =
1629 SOC_DAPM_ENUM("RX7 MIX1 INP2 Mux", rx7_mix1_inp2_chain_enum);
1630
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001631static const struct snd_kcontrol_new rx1_mix2_inp1_mux =
1632 SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum);
1633
1634static const struct snd_kcontrol_new rx1_mix2_inp2_mux =
1635 SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum);
1636
1637static const struct snd_kcontrol_new rx2_mix2_inp1_mux =
1638 SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum);
1639
1640static const struct snd_kcontrol_new rx2_mix2_inp2_mux =
1641 SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum);
1642
1643static const struct snd_kcontrol_new rx3_mix2_inp1_mux =
1644 SOC_DAPM_ENUM("RX3 MIX2 INP1 Mux", rx3_mix2_inp1_chain_enum);
1645
1646static const struct snd_kcontrol_new rx3_mix2_inp2_mux =
1647 SOC_DAPM_ENUM("RX3 MIX2 INP2 Mux", rx3_mix2_inp2_chain_enum);
1648
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001649static const struct snd_kcontrol_new rx4_dsm_mux =
1650 SOC_DAPM_ENUM("RX4 DSM MUX Mux", rx4_dsm_enum);
1651
1652static const struct snd_kcontrol_new rx6_dsm_mux =
1653 SOC_DAPM_ENUM("RX6 DSM MUX Mux", rx6_dsm_enum);
1654
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001655static const struct snd_kcontrol_new sb_tx1_mux =
1656 SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum);
1657
1658static const struct snd_kcontrol_new sb_tx2_mux =
1659 SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum);
1660
1661static const struct snd_kcontrol_new sb_tx3_mux =
1662 SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum);
1663
1664static const struct snd_kcontrol_new sb_tx4_mux =
1665 SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum);
1666
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001667static const struct snd_kcontrol_new sb_tx5_mux =
1668 SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum);
1669
1670static const struct snd_kcontrol_new sb_tx6_mux =
1671 SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum);
1672
1673static const struct snd_kcontrol_new sb_tx7_mux =
1674 SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum);
1675
1676static const struct snd_kcontrol_new sb_tx8_mux =
1677 SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum);
1678
Kiran Kandi3426e512011-09-13 22:50:10 -07001679static const struct snd_kcontrol_new sb_tx9_mux =
1680 SOC_DAPM_ENUM("SLIM TX9 MUX Mux", sb_tx9_mux_enum);
1681
1682static const struct snd_kcontrol_new sb_tx10_mux =
1683 SOC_DAPM_ENUM("SLIM TX10 MUX Mux", sb_tx10_mux_enum);
1684
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001685
Kiran Kandi59a96b12012-01-16 02:20:03 -08001686static int wcd9310_put_dec_enum(struct snd_kcontrol *kcontrol,
1687 struct snd_ctl_elem_value *ucontrol)
1688{
1689 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1690 struct snd_soc_dapm_widget *w = wlist->widgets[0];
1691 struct snd_soc_codec *codec = w->codec;
1692 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1693 unsigned int dec_mux, decimator;
1694 char *dec_name = NULL;
1695 char *widget_name = NULL;
1696 char *temp;
1697 u16 tx_mux_ctl_reg;
1698 u8 adc_dmic_sel = 0x0;
1699 int ret = 0;
1700
1701 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1702 return -EINVAL;
1703
1704 dec_mux = ucontrol->value.enumerated.item[0];
1705
1706 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
1707 if (!widget_name)
1708 return -ENOMEM;
1709 temp = widget_name;
1710
1711 dec_name = strsep(&widget_name, " ");
1712 widget_name = temp;
1713 if (!dec_name) {
1714 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
1715 ret = -EINVAL;
1716 goto out;
1717 }
1718
1719 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
1720 if (ret < 0) {
1721 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
1722 ret = -EINVAL;
1723 goto out;
1724 }
1725
1726 dev_dbg(w->dapm->dev, "%s(): widget = %s dec_name = %s decimator = %u"
1727 " dec_mux = %u\n", __func__, w->name, dec_name, decimator,
1728 dec_mux);
1729
1730
1731 switch (decimator) {
1732 case 1:
1733 case 2:
1734 case 3:
1735 case 4:
1736 case 5:
1737 case 6:
1738 if (dec_mux == 1)
1739 adc_dmic_sel = 0x1;
1740 else
1741 adc_dmic_sel = 0x0;
1742 break;
1743 case 7:
1744 case 8:
1745 case 9:
1746 case 10:
1747 if ((dec_mux == 1) || (dec_mux == 2))
1748 adc_dmic_sel = 0x1;
1749 else
1750 adc_dmic_sel = 0x0;
1751 break;
1752 default:
1753 pr_err("%s: Invalid Decimator = %u\n", __func__, decimator);
1754 ret = -EINVAL;
1755 goto out;
1756 }
1757
1758 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
1759
1760 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel);
1761
1762 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1763
1764out:
1765 kfree(widget_name);
1766 return ret;
1767}
1768
1769#define WCD9310_DEC_ENUM(xname, xenum) \
1770{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1771 .info = snd_soc_info_enum_double, \
1772 .get = snd_soc_dapm_get_enum_double, \
1773 .put = wcd9310_put_dec_enum, \
1774 .private_value = (unsigned long)&xenum }
1775
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001776static const struct snd_kcontrol_new dec1_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001777 WCD9310_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001778
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001779static const struct snd_kcontrol_new dec2_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001780 WCD9310_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum);
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001781
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001782static const struct snd_kcontrol_new dec3_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001783 WCD9310_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001784
1785static const struct snd_kcontrol_new dec4_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001786 WCD9310_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001787
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001788static const struct snd_kcontrol_new dec5_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001789 WCD9310_DEC_ENUM("DEC5 MUX Mux", dec5_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001790
1791static const struct snd_kcontrol_new dec6_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001792 WCD9310_DEC_ENUM("DEC6 MUX Mux", dec6_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001793
1794static const struct snd_kcontrol_new dec7_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001795 WCD9310_DEC_ENUM("DEC7 MUX Mux", dec7_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001796
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001797static const struct snd_kcontrol_new dec8_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001798 WCD9310_DEC_ENUM("DEC8 MUX Mux", dec8_mux_enum);
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001799
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001800static const struct snd_kcontrol_new dec9_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001801 WCD9310_DEC_ENUM("DEC9 MUX Mux", dec9_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001802
1803static const struct snd_kcontrol_new dec10_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001804 WCD9310_DEC_ENUM("DEC10 MUX Mux", dec10_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001805
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001806static const struct snd_kcontrol_new iir1_inp1_mux =
1807 SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum);
1808
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07001809static const struct snd_kcontrol_new iir2_inp1_mux =
1810 SOC_DAPM_ENUM("IIR2 INP1 Mux", iir2_inp1_mux_enum);
1811
Kiran Kandi59a96b12012-01-16 02:20:03 -08001812static const struct snd_kcontrol_new anc1_mux =
1813 SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum);
1814
Bradley Rubin229c6a52011-07-12 16:18:48 -07001815static const struct snd_kcontrol_new anc2_mux =
1816 SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001817
Bradley Rubin229c6a52011-07-12 16:18:48 -07001818static const struct snd_kcontrol_new anc1_fb_mux =
1819 SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001820
Bradley Rubin229c6a52011-07-12 16:18:48 -07001821static const struct snd_kcontrol_new dac1_switch[] = {
1822 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_EAR_EN, 5, 1, 0)
1823};
1824static const struct snd_kcontrol_new hphl_switch[] = {
1825 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_HPH_L_DAC_CTL, 6, 1, 0)
1826};
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001827
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001828static const struct snd_kcontrol_new hphl_pa_mix[] = {
1829 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1830 7, 1, 0),
1831 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1832 7, 1, 0),
1833 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1834 TABLA_A_AUX_L_PA_CONN_INV, 7, 1, 0),
1835 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1836 TABLA_A_AUX_R_PA_CONN_INV, 7, 1, 0),
1837};
1838
1839static const struct snd_kcontrol_new hphr_pa_mix[] = {
1840 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1841 6, 1, 0),
1842 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1843 6, 1, 0),
1844 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1845 TABLA_A_AUX_L_PA_CONN_INV, 6, 1, 0),
1846 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1847 TABLA_A_AUX_R_PA_CONN_INV, 6, 1, 0),
1848};
1849
1850static const struct snd_kcontrol_new lineout1_pa_mix[] = {
1851 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1852 5, 1, 0),
1853 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1854 5, 1, 0),
1855 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1856 TABLA_A_AUX_L_PA_CONN_INV, 5, 1, 0),
1857 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1858 TABLA_A_AUX_R_PA_CONN_INV, 5, 1, 0),
1859};
1860
1861static const struct snd_kcontrol_new lineout2_pa_mix[] = {
1862 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1863 4, 1, 0),
1864 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1865 4, 1, 0),
1866 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1867 TABLA_A_AUX_L_PA_CONN_INV, 4, 1, 0),
1868 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1869 TABLA_A_AUX_R_PA_CONN_INV, 4, 1, 0),
1870};
1871
1872static const struct snd_kcontrol_new lineout3_pa_mix[] = {
1873 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1874 3, 1, 0),
1875 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1876 3, 1, 0),
1877 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1878 TABLA_A_AUX_L_PA_CONN_INV, 3, 1, 0),
1879 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1880 TABLA_A_AUX_R_PA_CONN_INV, 3, 1, 0),
1881};
1882
1883static const struct snd_kcontrol_new lineout4_pa_mix[] = {
1884 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1885 2, 1, 0),
1886 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1887 2, 1, 0),
1888 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1889 TABLA_A_AUX_L_PA_CONN_INV, 2, 1, 0),
1890 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1891 TABLA_A_AUX_R_PA_CONN_INV, 2, 1, 0),
1892};
1893
1894static const struct snd_kcontrol_new lineout5_pa_mix[] = {
1895 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1896 1, 1, 0),
1897 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1898 1, 1, 0),
1899 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1900 TABLA_A_AUX_L_PA_CONN_INV, 1, 1, 0),
1901 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1902 TABLA_A_AUX_R_PA_CONN_INV, 1, 1, 0),
1903};
1904
1905static const struct snd_kcontrol_new ear_pa_mix[] = {
1906 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1907 0, 1, 0),
1908 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1909 0, 1, 0),
1910 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1911 TABLA_A_AUX_L_PA_CONN_INV, 0, 1, 0),
1912 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1913 TABLA_A_AUX_R_PA_CONN_INV, 0, 1, 0),
1914};
1915
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001916static const struct snd_kcontrol_new lineout3_ground_switch =
1917 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_3_DAC_CTL, 6, 1, 0);
1918
1919static const struct snd_kcontrol_new lineout4_ground_switch =
1920 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_4_DAC_CTL, 6, 1, 0);
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001921
Kuirong Wang906ac472012-07-09 12:54:44 -07001922/* virtual port entries */
1923static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol,
1924 struct snd_ctl_elem_value *ucontrol)
1925{
1926 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1927 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1928
1929 ucontrol->value.integer.value[0] = widget->value;
1930 return 0;
1931}
1932
1933static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol,
1934 struct snd_ctl_elem_value *ucontrol)
1935{
1936 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1937 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1938 struct snd_soc_codec *codec = widget->codec;
1939 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
1940 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
1941 struct soc_multi_mixer_control *mixer =
1942 ((struct soc_multi_mixer_control *)kcontrol->private_value);
1943 u32 dai_id = widget->shift;
1944 u32 port_id = mixer->shift;
1945 u32 enable = ucontrol->value.integer.value[0];
Venkat Sudhir96dd28c2012-12-04 17:00:19 -08001946 u32 vtable = vport_check_table[dai_id];
Kuirong Wang906ac472012-07-09 12:54:44 -07001947
1948 pr_debug("%s: wname %s cname %s value %u shift %d item %ld\n", __func__,
1949 widget->name, ucontrol->id.name, widget->value, widget->shift,
1950 ucontrol->value.integer.value[0]);
1951
1952 mutex_lock(&codec->mutex);
1953 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
1954 if (dai_id != AIF1_CAP) {
1955 dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
1956 __func__);
1957 mutex_unlock(&codec->mutex);
1958 return -EINVAL;
1959 }
1960 }
1961 switch (dai_id) {
1962 case AIF1_CAP:
1963 case AIF2_CAP:
1964 case AIF3_CAP:
1965 /* only add to the list if value not set
1966 */
1967 if (enable && !(widget->value & 1 << port_id)) {
Venkat Sudhir96dd28c2012-12-04 17:00:19 -08001968 if (tabla_p->intf_type ==
1969 WCD9XXX_INTERFACE_TYPE_SLIMBUS)
1970 vtable = vport_check_table[dai_id];
1971 if (tabla_p->intf_type == WCD9XXX_INTERFACE_TYPE_I2C)
1972 vtable = vport_i2s_check_table[dai_id];
Kuirong Wangdcc392e2012-10-19 00:33:38 -07001973 if (wcd9xxx_tx_vport_validation(
Venkat Sudhir96dd28c2012-12-04 17:00:19 -08001974 vtable,
Kuirong Wangdcc392e2012-10-19 00:33:38 -07001975 port_id,
1976 tabla_p->dai)) {
Kuirong Wang906ac472012-07-09 12:54:44 -07001977 pr_info("%s: TX%u is used by other virtual port\n",
1978 __func__, port_id + 1);
1979 mutex_unlock(&codec->mutex);
1980 return -EINVAL;
1981 }
1982 widget->value |= 1 << port_id;
1983 list_add_tail(&core->tx_chs[port_id].list,
1984 &tabla_p->dai[dai_id].wcd9xxx_ch_list
1985 );
1986 } else if (!enable && (widget->value & 1 << port_id)) {
1987 widget->value &= ~(1 << port_id);
1988 list_del_init(&core->tx_chs[port_id].list);
1989 } else {
1990 if (enable)
1991 pr_info("%s: TX%u port is used by this virtual port\n",
1992 __func__, port_id + 1);
1993 else
1994 pr_info("%s: TX%u port is not used by this virtual port\n",
1995 __func__, port_id + 1);
1996 /* avoid update power function */
1997 mutex_unlock(&codec->mutex);
1998 return 0;
1999 }
2000 break;
2001 default:
2002 pr_err("Unknown AIF %d\n", dai_id);
2003 mutex_unlock(&codec->mutex);
2004 return -EINVAL;
2005 }
2006 pr_debug("%s: name %s sname %s updated value %u shift %d\n", __func__,
2007 widget->name, widget->sname, widget->value, widget->shift);
2008
2009 snd_soc_dapm_mixer_update_power(widget, kcontrol, enable);
2010
2011 mutex_unlock(&codec->mutex);
2012 return 0;
2013}
2014
2015static int slim_rx_mux_get(struct snd_kcontrol *kcontrol,
2016 struct snd_ctl_elem_value *ucontrol)
2017{
2018 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2019 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2020
2021 ucontrol->value.enumerated.item[0] = widget->value;
2022 return 0;
2023}
2024
2025static const char *const slim_rx_mux_text[] = {
2026 "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB"
2027};
2028
2029static int slim_rx_mux_put(struct snd_kcontrol *kcontrol,
2030 struct snd_ctl_elem_value *ucontrol)
2031{
2032 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2033 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2034 struct snd_soc_codec *codec = widget->codec;
2035 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
2036 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
2037 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2038 u32 port_id = widget->shift;
2039
2040 pr_debug("%s: wname %s cname %s value %u shift %d item %u\n", __func__,
2041 widget->name, ucontrol->id.name, widget->value, widget->shift,
2042 ucontrol->value.enumerated.item[0]);
2043
2044 widget->value = ucontrol->value.enumerated.item[0];
2045
2046 mutex_lock(&codec->mutex);
2047
2048 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
2049 if (widget->value > 1) {
2050 dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
2051 __func__);
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002052 goto err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002053 }
2054 }
2055 /* value need to match the Virtual port and AIF number
2056 */
2057 switch (widget->value) {
2058 case 0:
2059 list_del_init(&core->rx_chs[port_id].list);
2060 break;
2061 case 1:
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002062 if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port,
2063 &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list))
2064 goto pr_err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002065 list_add_tail(&core->rx_chs[port_id].list,
2066 &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list);
2067 break;
2068 case 2:
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002069 if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port,
2070 &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list))
2071 goto pr_err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002072 list_add_tail(&core->rx_chs[port_id].list,
2073 &tabla_p->dai[AIF2_PB].wcd9xxx_ch_list);
2074 break;
2075 case 3:
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002076 if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port,
2077 &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list))
2078 goto pr_err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002079 list_add_tail(&core->rx_chs[port_id].list,
2080 &tabla_p->dai[AIF3_PB].wcd9xxx_ch_list);
2081 break;
2082 default:
2083 pr_err("Unknown AIF %d\n", widget->value);
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002084 goto err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002085 }
2086
2087 snd_soc_dapm_mux_update_power(widget, kcontrol, 1, widget->value, e);
2088
2089 mutex_unlock(&codec->mutex);
2090 return 0;
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002091
2092pr_err:
2093 pr_err("%s: RX%u is used by current requesting AIF_PB itself\n",
2094 __func__, port_id + 1);
Santosh Mardi2a831d72012-11-07 20:45:52 +05302095 mutex_unlock(&codec->mutex);
2096 return 0;
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002097err:
2098 mutex_unlock(&codec->mutex);
2099 return -EINVAL;
Kuirong Wang906ac472012-07-09 12:54:44 -07002100}
2101
2102static const struct soc_enum slim_rx_mux_enum =
2103 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text), slim_rx_mux_text);
2104
2105static const struct snd_kcontrol_new slim_rx_mux[TABLA_RX_MAX] = {
2106 SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum,
2107 slim_rx_mux_get, slim_rx_mux_put),
2108 SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum,
2109 slim_rx_mux_get, slim_rx_mux_put),
2110 SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum,
2111 slim_rx_mux_get, slim_rx_mux_put),
2112 SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum,
2113 slim_rx_mux_get, slim_rx_mux_put),
2114 SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum,
2115 slim_rx_mux_get, slim_rx_mux_put),
2116 SOC_DAPM_ENUM_EXT("SLIM RX6 Mux", slim_rx_mux_enum,
2117 slim_rx_mux_get, slim_rx_mux_put),
2118 SOC_DAPM_ENUM_EXT("SLIM RX7 Mux", slim_rx_mux_enum,
2119 slim_rx_mux_get, slim_rx_mux_put),
2120};
2121
2122static const struct snd_kcontrol_new aif_cap_mixer[] = {
2123 SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, TABLA_TX1, 1, 0,
2124 slim_tx_mixer_get, slim_tx_mixer_put),
2125 SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, TABLA_TX2, 1, 0,
2126 slim_tx_mixer_get, slim_tx_mixer_put),
2127 SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, TABLA_TX3, 1, 0,
2128 slim_tx_mixer_get, slim_tx_mixer_put),
2129 SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, TABLA_TX4, 1, 0,
2130 slim_tx_mixer_get, slim_tx_mixer_put),
2131 SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, TABLA_TX5, 1, 0,
2132 slim_tx_mixer_get, slim_tx_mixer_put),
2133 SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, TABLA_TX6, 1, 0,
2134 slim_tx_mixer_get, slim_tx_mixer_put),
2135 SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, TABLA_TX7, 1, 0,
2136 slim_tx_mixer_get, slim_tx_mixer_put),
2137 SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, TABLA_TX8, 1, 0,
2138 slim_tx_mixer_get, slim_tx_mixer_put),
2139 SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, TABLA_TX9, 1, 0,
2140 slim_tx_mixer_get, slim_tx_mixer_put),
2141 SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, TABLA_TX10, 1, 0,
2142 slim_tx_mixer_get, slim_tx_mixer_put),
2143};
2144
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002145static void tabla_codec_enable_adc_block(struct snd_soc_codec *codec,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002146 int enable)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002147{
2148 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2149
2150 pr_debug("%s %d\n", __func__, enable);
2151
2152 if (enable) {
2153 tabla->adc_count++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002154 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x2, 0x2);
2155 } else {
2156 tabla->adc_count--;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002157 if (!tabla->adc_count)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002158 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL,
Joonwoo Park03324832012-03-19 19:36:16 -07002159 0x2, 0x0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002160 }
2161}
2162
2163static int tabla_codec_enable_adc(struct snd_soc_dapm_widget *w,
2164 struct snd_kcontrol *kcontrol, int event)
2165{
2166 struct snd_soc_codec *codec = w->codec;
2167 u16 adc_reg;
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08002168 u8 init_bit_shift;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002169
2170 pr_debug("%s %d\n", __func__, event);
2171
2172 if (w->reg == TABLA_A_TX_1_2_EN)
2173 adc_reg = TABLA_A_TX_1_2_TEST_CTL;
2174 else if (w->reg == TABLA_A_TX_3_4_EN)
2175 adc_reg = TABLA_A_TX_3_4_TEST_CTL;
2176 else if (w->reg == TABLA_A_TX_5_6_EN)
2177 adc_reg = TABLA_A_TX_5_6_TEST_CTL;
2178 else {
2179 pr_err("%s: Error, invalid adc register\n", __func__);
2180 return -EINVAL;
2181 }
2182
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08002183 if (w->shift == 3)
2184 init_bit_shift = 6;
2185 else if (w->shift == 7)
2186 init_bit_shift = 7;
2187 else {
2188 pr_err("%s: Error, invalid init bit postion adc register\n",
2189 __func__);
2190 return -EINVAL;
2191 }
2192
2193
2194
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002195 switch (event) {
2196 case SND_SOC_DAPM_PRE_PMU:
2197 tabla_codec_enable_adc_block(codec, 1);
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08002198 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift,
2199 1 << init_bit_shift);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002200 break;
2201 case SND_SOC_DAPM_POST_PMU:
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08002202
2203 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00);
2204
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002205 break;
2206 case SND_SOC_DAPM_POST_PMD:
2207 tabla_codec_enable_adc_block(codec, 0);
2208 break;
2209 }
2210 return 0;
2211}
2212
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002213static void tabla_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec)
2214{
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002215 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2216 0x80);
2217 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x04,
2218 0x04);
2219 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01,
2220 0x01);
2221 usleep_range(1000, 1000);
2222 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2223 0x00);
2224}
2225
2226static void tabla_codec_enable_bandgap(struct snd_soc_codec *codec,
2227 enum tabla_bandgap_type choice)
2228{
2229 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2230
2231 /* TODO lock resources accessed by audio streams and threaded
2232 * interrupt handlers
2233 */
2234
2235 pr_debug("%s, choice is %d, current is %d\n", __func__, choice,
2236 tabla->bandgap_type);
2237
2238 if (tabla->bandgap_type == choice)
2239 return;
2240
2241 if ((tabla->bandgap_type == TABLA_BANDGAP_OFF) &&
2242 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
2243 tabla_codec_enable_audio_mode_bandgap(codec);
2244 } else if (choice == TABLA_BANDGAP_MBHC_MODE) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002245 /* bandgap mode becomes fast,
2246 * mclk should be off or clk buff source souldn't be VBG
2247 * Let's turn off mclk always */
2248 WARN_ON(snd_soc_read(codec, TABLA_A_CLK_BUFF_EN2) & (1 << 2));
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002249 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x2,
2250 0x2);
2251 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2252 0x80);
2253 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x4,
2254 0x4);
2255 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01,
2256 0x01);
2257 usleep_range(1000, 1000);
2258 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2259 0x00);
2260 } else if ((tabla->bandgap_type == TABLA_BANDGAP_MBHC_MODE) &&
2261 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
Damir Didjusto7c85d712012-08-16 21:22:29 -07002262 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002263 usleep_range(100, 100);
2264 tabla_codec_enable_audio_mode_bandgap(codec);
2265 } else if (choice == TABLA_BANDGAP_OFF) {
Damir Didjusto7c85d712012-08-16 21:22:29 -07002266 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002267 } else {
2268 pr_err("%s: Error, Invalid bandgap settings\n", __func__);
2269 }
2270 tabla->bandgap_type = choice;
2271}
2272
2273static void tabla_codec_disable_clock_block(struct snd_soc_codec *codec)
2274{
2275 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2276 pr_debug("%s\n", __func__);
2277 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x00);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002278 usleep_range(50, 50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002279 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x02);
2280 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x00);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002281 usleep_range(50, 50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002282 tabla->clock_active = false;
2283}
2284
2285static int tabla_codec_mclk_index(const struct tabla_priv *tabla)
2286{
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002287 if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002288 return 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002289 else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002290 return 1;
2291 else {
2292 BUG_ON(1);
2293 return -EINVAL;
2294 }
2295}
2296
2297static void tabla_enable_rx_bias(struct snd_soc_codec *codec, u32 enable)
2298{
2299 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2300
2301 if (enable) {
2302 tabla->rx_bias_count++;
2303 if (tabla->rx_bias_count == 1)
2304 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
2305 0x80, 0x80);
2306 } else {
2307 tabla->rx_bias_count--;
2308 if (!tabla->rx_bias_count)
2309 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
2310 0x80, 0x00);
2311 }
2312}
2313
2314static int tabla_codec_enable_config_mode(struct snd_soc_codec *codec,
2315 int enable)
2316{
2317 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2318
2319 pr_debug("%s: enable = %d\n", __func__, enable);
2320 if (enable) {
2321 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x10, 0);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002322 /* bandgap mode to fast */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002323 snd_soc_write(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x17);
2324 usleep_range(5, 5);
2325 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002326 0x80);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002327 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002328 0x80);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002329 usleep_range(10, 10);
2330 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, 0);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002331 usleep_range(10000, 10000);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002332 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x08);
2333 } else {
2334 snd_soc_update_bits(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x1,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002335 0);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002336 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, 0);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002337 /* clk source to ext clk and clk buff ref to VBG */
2338 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x0C, 0x04);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002339 }
2340 tabla->config_mode_active = enable ? true : false;
2341
2342 return 0;
2343}
2344
2345static int tabla_codec_enable_clock_block(struct snd_soc_codec *codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002346 int config_mode)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002347{
2348 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2349
2350 pr_debug("%s: config_mode = %d\n", __func__, config_mode);
2351
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002352 /* transit to RCO requires mclk off */
2353 WARN_ON(snd_soc_read(codec, TABLA_A_CLK_BUFF_EN2) & (1 << 2));
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002354 if (config_mode) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002355 /* enable RCO and switch to it */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002356 tabla_codec_enable_config_mode(codec, 1);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002357 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002358 usleep_range(1000, 1000);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002359 } else {
2360 /* switch to MCLK */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002361 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00);
2362
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002363 if (tabla->mbhc_polling_active) {
2364 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
2365 tabla_codec_enable_config_mode(codec, 0);
2366 }
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002367 }
2368
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002369 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x01, 0x01);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002370 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x00);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002371 /* on MCLK */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002372 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x04);
2373 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_MCLK_CTL, 0x01, 0x01);
2374 usleep_range(50, 50);
2375 tabla->clock_active = true;
2376 return 0;
2377}
2378
2379static int tabla_codec_enable_aux_pga(struct snd_soc_dapm_widget *w,
2380 struct snd_kcontrol *kcontrol, int event)
2381{
2382 struct snd_soc_codec *codec = w->codec;
2383 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2384
2385 pr_debug("%s: %d\n", __func__, event);
2386
2387 switch (event) {
2388 case SND_SOC_DAPM_PRE_PMU:
2389 tabla_codec_enable_bandgap(codec,
2390 TABLA_BANDGAP_AUDIO_MODE);
2391 tabla_enable_rx_bias(codec, 1);
2392
2393 snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL,
2394 0x08, 0x08);
2395 /* Enable Zero Cross detect for AUX PGA channel
2396 * and set the initial AUX PGA gain to NEG_0P0_DB
2397 * to avoid glitches.
2398 */
2399 if (w->reg == TABLA_A_AUX_L_EN) {
2400 snd_soc_update_bits(codec, TABLA_A_AUX_L_EN,
2401 0x20, 0x20);
2402 tabla->aux_l_gain = snd_soc_read(codec,
2403 TABLA_A_AUX_L_GAIN);
2404 snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F);
2405 } else {
2406 snd_soc_update_bits(codec, TABLA_A_AUX_R_EN,
2407 0x20, 0x20);
2408 tabla->aux_r_gain = snd_soc_read(codec,
2409 TABLA_A_AUX_R_GAIN);
2410 snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F);
2411 }
2412 if (tabla->aux_pga_cnt++ == 1
2413 && !tabla->mclk_enabled) {
2414 tabla_codec_enable_clock_block(codec, 1);
2415 pr_debug("AUX PGA enabled RC osc\n");
2416 }
2417 break;
2418
2419 case SND_SOC_DAPM_POST_PMU:
2420 if (w->reg == TABLA_A_AUX_L_EN)
2421 snd_soc_write(codec, TABLA_A_AUX_L_GAIN,
2422 tabla->aux_l_gain);
2423 else
2424 snd_soc_write(codec, TABLA_A_AUX_R_GAIN,
2425 tabla->aux_r_gain);
2426 break;
2427
2428 case SND_SOC_DAPM_PRE_PMD:
2429 /* Mute AUX PGA channel in use before disabling AUX PGA */
2430 if (w->reg == TABLA_A_AUX_L_EN) {
2431 tabla->aux_l_gain = snd_soc_read(codec,
2432 TABLA_A_AUX_L_GAIN);
2433 snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F);
2434 } else {
2435 tabla->aux_r_gain = snd_soc_read(codec,
2436 TABLA_A_AUX_R_GAIN);
2437 snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F);
2438 }
2439 break;
2440
2441 case SND_SOC_DAPM_POST_PMD:
2442 tabla_enable_rx_bias(codec, 0);
2443
2444 snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL,
2445 0x08, 0x00);
2446 if (w->reg == TABLA_A_AUX_L_EN) {
2447 snd_soc_write(codec, TABLA_A_AUX_L_GAIN,
2448 tabla->aux_l_gain);
2449 snd_soc_update_bits(codec, TABLA_A_AUX_L_EN,
2450 0x20, 0x00);
2451 } else {
2452 snd_soc_write(codec, TABLA_A_AUX_R_GAIN,
2453 tabla->aux_r_gain);
2454 snd_soc_update_bits(codec, TABLA_A_AUX_R_EN,
2455 0x20, 0x00);
2456 }
2457
2458 if (tabla->aux_pga_cnt-- == 0) {
2459 if (tabla->mbhc_polling_active)
2460 tabla_codec_enable_bandgap(codec,
2461 TABLA_BANDGAP_MBHC_MODE);
2462 else
2463 tabla_codec_enable_bandgap(codec,
2464 TABLA_BANDGAP_OFF);
2465
2466 if (!tabla->mclk_enabled &&
2467 !tabla->mbhc_polling_active) {
2468 tabla_codec_enable_clock_block(codec, 0);
2469 }
2470 }
2471 break;
2472 }
2473 return 0;
2474}
2475
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002476static int tabla_codec_enable_lineout(struct snd_soc_dapm_widget *w,
2477 struct snd_kcontrol *kcontrol, int event)
2478{
2479 struct snd_soc_codec *codec = w->codec;
2480 u16 lineout_gain_reg;
2481
Kiran Kandidb0a4b02011-08-23 09:32:09 -07002482 pr_debug("%s %d %s\n", __func__, event, w->name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002483
2484 switch (w->shift) {
2485 case 0:
2486 lineout_gain_reg = TABLA_A_RX_LINE_1_GAIN;
2487 break;
2488 case 1:
2489 lineout_gain_reg = TABLA_A_RX_LINE_2_GAIN;
2490 break;
2491 case 2:
2492 lineout_gain_reg = TABLA_A_RX_LINE_3_GAIN;
2493 break;
2494 case 3:
2495 lineout_gain_reg = TABLA_A_RX_LINE_4_GAIN;
2496 break;
2497 case 4:
2498 lineout_gain_reg = TABLA_A_RX_LINE_5_GAIN;
2499 break;
2500 default:
2501 pr_err("%s: Error, incorrect lineout register value\n",
2502 __func__);
2503 return -EINVAL;
2504 }
2505
2506 switch (event) {
2507 case SND_SOC_DAPM_PRE_PMU:
2508 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40);
2509 break;
2510 case SND_SOC_DAPM_POST_PMU:
Krishnankutty Kolathappilly31169f42011-11-17 10:33:11 -08002511 pr_debug("%s: sleeping 16 ms after %s PA turn on\n",
Kiran Kandidb0a4b02011-08-23 09:32:09 -07002512 __func__, w->name);
Krishnankutty Kolathappilly31169f42011-11-17 10:33:11 -08002513 usleep_range(16000, 16000);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002514 break;
2515 case SND_SOC_DAPM_POST_PMD:
2516 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00);
2517 break;
2518 }
2519 return 0;
2520}
2521
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002522
2523static int tabla_codec_enable_dmic(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002524 struct snd_kcontrol *kcontrol, int event)
2525{
2526 struct snd_soc_codec *codec = w->codec;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002527 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2528 u8 dmic_clk_en;
2529 s32 *dmic_clk_cnt;
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002530 unsigned int dmic;
2531 int ret;
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002532
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002533 ret = kstrtouint(strpbrk(w->name, "123456"), 10, &dmic);
2534 if (ret < 0) {
2535 pr_err("%s: Invalid DMIC line on the codec\n", __func__);
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002536 return -EINVAL;
2537 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002538
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002539 switch (dmic) {
2540 case 1:
2541 case 2:
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002542 dmic_clk_en = 0x01;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002543 dmic_clk_cnt = &(tabla->dmic_1_2_clk_cnt);
2544
2545 pr_debug("%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n",
2546 __func__, event, dmic, *dmic_clk_cnt);
2547
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002548 break;
2549
2550 case 3:
2551 case 4:
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002552 dmic_clk_en = 0x04;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002553 dmic_clk_cnt = &(tabla->dmic_3_4_clk_cnt);
2554
2555 pr_debug("%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n",
2556 __func__, event, dmic, *dmic_clk_cnt);
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002557 break;
2558
2559 case 5:
2560 case 6:
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002561 dmic_clk_en = 0x10;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002562 dmic_clk_cnt = &(tabla->dmic_5_6_clk_cnt);
2563
2564 pr_debug("%s() event %d DMIC%d dmic_5_6_clk_cnt %d\n",
2565 __func__, event, dmic, *dmic_clk_cnt);
2566
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002567 break;
2568
2569 default:
2570 pr_err("%s: Invalid DMIC Selection\n", __func__);
2571 return -EINVAL;
2572 }
2573
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002574 switch (event) {
2575 case SND_SOC_DAPM_PRE_PMU:
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002576
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002577 (*dmic_clk_cnt)++;
2578 if (*dmic_clk_cnt == 1)
2579 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
2580 dmic_clk_en, dmic_clk_en);
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002581
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002582 break;
2583 case SND_SOC_DAPM_POST_PMD:
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002584
2585 (*dmic_clk_cnt)--;
2586 if (*dmic_clk_cnt == 0)
2587 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
2588 dmic_clk_en, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002589 break;
2590 }
2591 return 0;
2592}
2593
Bradley Rubin229c6a52011-07-12 16:18:48 -07002594
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002595/* called under codec_resource_lock acquisition */
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002596static void tabla_codec_start_hs_polling(struct snd_soc_codec *codec)
2597{
Bradley Rubincb3950a2011-08-18 13:07:26 -07002598 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07002599 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
2600 int mbhc_state = tabla->mbhc_state;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002601
Joonwoo Park03324832012-03-19 19:36:16 -07002602 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002603 if (!tabla->mbhc_polling_active) {
2604 pr_debug("Polling is not active, do not start polling\n");
2605 return;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002606 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002607 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Joonwoo Park03324832012-03-19 19:36:16 -07002608
Joonwoo Park5bbcb0c2012-08-07 17:25:52 -07002609 if (tabla->no_mic_headset_override) {
2610 pr_debug("%s setting button threshold to min", __func__);
2611 /* set to min */
2612 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, 0x80);
2613 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0x00);
2614 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0x80);
2615 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0x00);
2616 } else if (unlikely(mbhc_state == MBHC_STATE_POTENTIAL)) {
2617 pr_debug("%s recovering MBHC state machine\n", __func__);
2618 tabla->mbhc_state = MBHC_STATE_POTENTIAL_RECOVERY;
2619 /* set to max button press threshold */
2620 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, 0x7F);
2621 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, 0xFF);
2622 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL,
2623 (TABLA_IS_1_X(tabla_core->version) ?
2624 0x07 : 0x7F));
2625 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0xFF);
2626 /* set to max */
2627 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0x7F);
2628 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0xFF);
Joonwoo Park03324832012-03-19 19:36:16 -07002629 }
2630
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002631 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
2632 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
2633 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
Joonwoo Park03324832012-03-19 19:36:16 -07002634 pr_debug("%s: leave\n", __func__);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002635}
2636
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002637/* called under codec_resource_lock acquisition */
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002638static void tabla_codec_pause_hs_polling(struct snd_soc_codec *codec)
2639{
Bradley Rubincb3950a2011-08-18 13:07:26 -07002640 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2641
Joonwoo Park03324832012-03-19 19:36:16 -07002642 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002643 if (!tabla->mbhc_polling_active) {
2644 pr_debug("polling not active, nothing to pause\n");
2645 return;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002646 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002647
Simmi Pateriya1b9a3092013-01-02 11:49:26 +05302648 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01);
2649 msleep(250);
2650 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002651 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
Joonwoo Park03324832012-03-19 19:36:16 -07002652 pr_debug("%s: leave\n", __func__);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002653}
2654
Joonwoo Park03324832012-03-19 19:36:16 -07002655static void tabla_codec_switch_cfilt_mode(struct snd_soc_codec *codec, int mode)
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002656{
2657 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2658 u8 reg_mode_val, cur_mode_val;
2659 bool mbhc_was_polling = false;
2660
2661 if (mode)
2662 reg_mode_val = TABLA_CFILT_FAST_MODE;
2663 else
2664 reg_mode_val = TABLA_CFILT_SLOW_MODE;
2665
2666 cur_mode_val = snd_soc_read(codec,
2667 tabla->mbhc_bias_regs.cfilt_ctl) & 0x40;
2668
2669 if (cur_mode_val != reg_mode_val) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002670 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002671 if (tabla->mbhc_polling_active) {
2672 tabla_codec_pause_hs_polling(codec);
2673 mbhc_was_polling = true;
2674 }
2675 snd_soc_update_bits(codec,
2676 tabla->mbhc_bias_regs.cfilt_ctl, 0x40, reg_mode_val);
2677 if (mbhc_was_polling)
2678 tabla_codec_start_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002679 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002680 pr_debug("%s: CFILT mode change (%x to %x)\n", __func__,
2681 cur_mode_val, reg_mode_val);
2682 } else {
2683 pr_debug("%s: CFILT Value is already %x\n",
2684 __func__, cur_mode_val);
2685 }
2686}
2687
2688static void tabla_codec_update_cfilt_usage(struct snd_soc_codec *codec,
2689 u8 cfilt_sel, int inc)
2690{
2691 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2692 u32 *cfilt_cnt_ptr = NULL;
2693 u16 micb_cfilt_reg;
2694
2695 switch (cfilt_sel) {
2696 case TABLA_CFILT1_SEL:
2697 cfilt_cnt_ptr = &tabla->cfilt1_cnt;
2698 micb_cfilt_reg = TABLA_A_MICB_CFILT_1_CTL;
2699 break;
2700 case TABLA_CFILT2_SEL:
2701 cfilt_cnt_ptr = &tabla->cfilt2_cnt;
2702 micb_cfilt_reg = TABLA_A_MICB_CFILT_2_CTL;
2703 break;
2704 case TABLA_CFILT3_SEL:
2705 cfilt_cnt_ptr = &tabla->cfilt3_cnt;
2706 micb_cfilt_reg = TABLA_A_MICB_CFILT_3_CTL;
2707 break;
2708 default:
2709 return; /* should not happen */
2710 }
2711
2712 if (inc) {
2713 if (!(*cfilt_cnt_ptr)++) {
2714 /* Switch CFILT to slow mode if MBHC CFILT being used */
2715 if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel)
2716 tabla_codec_switch_cfilt_mode(codec, 0);
2717
2718 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80);
2719 }
2720 } else {
2721 /* check if count not zero, decrement
2722 * then check if zero, go ahead disable cfilter
2723 */
2724 if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr)) {
2725 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0);
2726
2727 /* Switch CFILT to fast mode if MBHC CFILT being used */
2728 if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel)
2729 tabla_codec_switch_cfilt_mode(codec, 1);
2730 }
2731 }
2732}
2733
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002734static int tabla_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv)
2735{
2736 int rc = -EINVAL;
2737 unsigned min_mv, max_mv;
2738
2739 switch (ldoh_v) {
2740 case TABLA_LDOH_1P95_V:
2741 min_mv = 160;
2742 max_mv = 1800;
2743 break;
2744 case TABLA_LDOH_2P35_V:
2745 min_mv = 200;
2746 max_mv = 2200;
2747 break;
2748 case TABLA_LDOH_2P75_V:
2749 min_mv = 240;
2750 max_mv = 2600;
2751 break;
2752 case TABLA_LDOH_2P85_V:
2753 min_mv = 250;
2754 max_mv = 2700;
2755 break;
2756 default:
2757 goto done;
2758 }
2759
2760 if (cfilt_mv < min_mv || cfilt_mv > max_mv)
2761 goto done;
2762
2763 for (rc = 4; rc <= 44; rc++) {
2764 min_mv = max_mv * (rc) / 44;
2765 if (min_mv >= cfilt_mv) {
2766 rc -= 4;
2767 break;
2768 }
2769 }
2770done:
2771 return rc;
2772}
2773
2774static bool tabla_is_hph_pa_on(struct snd_soc_codec *codec)
2775{
2776 u8 hph_reg_val = 0;
2777 hph_reg_val = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_EN);
2778
2779 return (hph_reg_val & 0x30) ? true : false;
2780}
2781
Joonwoo Parka9444452011-12-08 18:48:27 -08002782static bool tabla_is_hph_dac_on(struct snd_soc_codec *codec, int left)
2783{
2784 u8 hph_reg_val = 0;
2785 if (left)
2786 hph_reg_val = snd_soc_read(codec,
2787 TABLA_A_RX_HPH_L_DAC_CTL);
2788 else
2789 hph_reg_val = snd_soc_read(codec,
2790 TABLA_A_RX_HPH_R_DAC_CTL);
2791
2792 return (hph_reg_val & 0xC0) ? true : false;
2793}
2794
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002795static void tabla_turn_onoff_override(struct snd_soc_codec *codec, bool on)
2796{
2797 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, on << 2);
2798}
2799
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002800/* called under codec_resource_lock acquisition */
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002801static void tabla_codec_drive_v_to_micbias(struct snd_soc_codec *codec,
2802 int usec)
2803{
2804 int cfilt_k_val;
2805 bool set = true;
2806 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2807
2808 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
2809 tabla->mbhc_micbias_switched) {
2810 pr_debug("%s: set mic V to micbias V\n", __func__);
2811 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
2812 tabla_turn_onoff_override(codec, true);
2813 while (1) {
2814 cfilt_k_val = tabla_find_k_value(
2815 tabla->pdata->micbias.ldoh_v,
2816 set ? tabla->mbhc_data.micb_mv :
2817 VDDIO_MICBIAS_MV);
2818 snd_soc_update_bits(codec,
2819 tabla->mbhc_bias_regs.cfilt_val,
2820 0xFC, (cfilt_k_val << 2));
2821 if (!set)
2822 break;
2823 usleep_range(usec, usec);
2824 set = false;
2825 }
2826 tabla_turn_onoff_override(codec, false);
2827 }
2828}
2829
2830/* called under codec_resource_lock acquisition */
2831static void __tabla_codec_switch_micbias(struct snd_soc_codec *codec,
2832 int vddio_switch, bool restartpolling,
2833 bool checkpolling)
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002834{
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002835 int cfilt_k_val;
Joonwoo Park41956722012-04-18 13:13:07 -07002836 bool override;
2837 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002838
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002839 if (vddio_switch && !tabla->mbhc_micbias_switched &&
2840 (!checkpolling || tabla->mbhc_polling_active)) {
2841 if (restartpolling)
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08002842 tabla_codec_pause_hs_polling(codec);
Joonwoo Park41956722012-04-18 13:13:07 -07002843 override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04;
2844 if (!override)
2845 tabla_turn_onoff_override(codec, true);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002846 /* Adjust threshold if Mic Bias voltage changes */
2847 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002848 cfilt_k_val = tabla_find_k_value(
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002849 tabla->pdata->micbias.ldoh_v,
2850 VDDIO_MICBIAS_MV);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002851 snd_soc_update_bits(codec,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002852 tabla->mbhc_bias_regs.cfilt_val,
2853 0xFC, (cfilt_k_val << 2));
Joonwoo Parkc1c67a92012-08-07 16:05:36 -07002854 usleep_range(cfilt_adjust_ms * 1000,
2855 cfilt_adjust_ms * 1000);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002856 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
2857 tabla->mbhc_data.adj_v_ins_hu & 0xFF);
2858 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
2859 (tabla->mbhc_data.adj_v_ins_hu >> 8) &
2860 0xFF);
2861 pr_debug("%s: Programmed MBHC thresholds to VDDIO\n",
2862 __func__);
2863 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002864
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002865 /* enable MIC BIAS Switch to VDDIO */
2866 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2867 0x80, 0x80);
2868 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2869 0x10, 0x00);
Joonwoo Park41956722012-04-18 13:13:07 -07002870 if (!override)
2871 tabla_turn_onoff_override(codec, false);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002872 if (restartpolling)
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08002873 tabla_codec_start_hs_polling(codec);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002874
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002875 tabla->mbhc_micbias_switched = true;
2876 pr_debug("%s: VDDIO switch enabled\n", __func__);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002877 } else if (!vddio_switch && tabla->mbhc_micbias_switched) {
2878 if ((!checkpolling || tabla->mbhc_polling_active) &&
2879 restartpolling)
2880 tabla_codec_pause_hs_polling(codec);
2881 /* Reprogram thresholds */
2882 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
2883 cfilt_k_val = tabla_find_k_value(
2884 tabla->pdata->micbias.ldoh_v,
2885 tabla->mbhc_data.micb_mv);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002886 snd_soc_update_bits(codec,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002887 tabla->mbhc_bias_regs.cfilt_val,
2888 0xFC, (cfilt_k_val << 2));
Joonwoo Parkc1c67a92012-08-07 16:05:36 -07002889 usleep_range(cfilt_adjust_ms * 1000,
2890 cfilt_adjust_ms * 1000);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002891 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
2892 tabla->mbhc_data.v_ins_hu & 0xFF);
2893 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
2894 (tabla->mbhc_data.v_ins_hu >> 8) & 0xFF);
2895 pr_debug("%s: Programmed MBHC thresholds to MICBIAS\n",
2896 __func__);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002897 }
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002898
2899 /* Disable MIC BIAS Switch to VDDIO */
2900 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2901 0x80, 0x00);
2902 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2903 0x10, 0x00);
2904
2905 if ((!checkpolling || tabla->mbhc_polling_active) &&
2906 restartpolling)
2907 tabla_codec_start_hs_polling(codec);
2908
2909 tabla->mbhc_micbias_switched = false;
2910 pr_debug("%s: VDDIO switch disabled\n", __func__);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002911 }
2912}
2913
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002914static void tabla_codec_switch_micbias(struct snd_soc_codec *codec,
2915 int vddio_switch)
2916{
2917 return __tabla_codec_switch_micbias(codec, vddio_switch, true, true);
2918}
2919
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002920static int tabla_codec_enable_micbias(struct snd_soc_dapm_widget *w,
2921 struct snd_kcontrol *kcontrol, int event)
2922{
2923 struct snd_soc_codec *codec = w->codec;
Patrick Lai3043fba2011-08-01 14:15:57 -07002924 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2925 u16 micb_int_reg;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002926 int micb_line;
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002927 u8 cfilt_sel_val = 0;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002928 char *internal1_text = "Internal1";
2929 char *internal2_text = "Internal2";
2930 char *internal3_text = "Internal3";
Simmi Pateriya71d63872012-11-08 01:06:30 +05302931 const char *micbias1_text = "MIC BIAS1 ";
2932 const char *micbias2_text = "MIC BIAS2 ";
2933 const char *micbias3_text = "MIC BIAS3 ";
2934 const char *micbias4_text = "MIC BIAS4 ";
2935 u32 *micbias_enable_count;
2936 u16 wreg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002937
2938 pr_debug("%s %d\n", __func__, event);
Simmi Pateriya71d63872012-11-08 01:06:30 +05302939 if (strnstr(w->name, micbias1_text, strlen(micbias1_text))) {
2940 wreg = TABLA_A_MICB_1_CTL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002941 micb_int_reg = TABLA_A_MICB_1_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07002942 cfilt_sel_val = tabla->pdata->micbias.bias1_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002943 micb_line = TABLA_MICBIAS1;
Simmi Pateriya71d63872012-11-08 01:06:30 +05302944 } else if (strnstr(w->name, micbias2_text, strlen(micbias2_text))) {
2945 wreg = TABLA_A_MICB_2_CTL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002946 micb_int_reg = TABLA_A_MICB_2_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07002947 cfilt_sel_val = tabla->pdata->micbias.bias2_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002948 micb_line = TABLA_MICBIAS2;
Simmi Pateriya71d63872012-11-08 01:06:30 +05302949 } else if (strnstr(w->name, micbias3_text, strlen(micbias3_text))) {
2950 wreg = TABLA_A_MICB_3_CTL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002951 micb_int_reg = TABLA_A_MICB_3_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07002952 cfilt_sel_val = tabla->pdata->micbias.bias3_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002953 micb_line = TABLA_MICBIAS3;
Simmi Pateriya71d63872012-11-08 01:06:30 +05302954 } else if (strnstr(w->name, micbias4_text, strlen(micbias4_text))) {
2955 wreg = tabla->reg_addr.micb_4_ctl;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08002956 micb_int_reg = tabla->reg_addr.micb_4_int_rbias;
Patrick Lai3043fba2011-08-01 14:15:57 -07002957 cfilt_sel_val = tabla->pdata->micbias.bias4_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002958 micb_line = TABLA_MICBIAS4;
Simmi Pateriya71d63872012-11-08 01:06:30 +05302959 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002960 pr_err("%s: Error, invalid micbias register\n", __func__);
2961 return -EINVAL;
2962 }
2963
Simmi Pateriya71d63872012-11-08 01:06:30 +05302964 micbias_enable_count = &tabla->micbias_enable_count[micb_line];
2965 pr_debug("%s: counter %d\n", __func__, *micbias_enable_count);
2966
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002967 switch (event) {
2968 case SND_SOC_DAPM_PRE_PMU:
Simmi Pateriya71d63872012-11-08 01:06:30 +05302969 if (++*micbias_enable_count > 1) {
2970 pr_debug("%s: do nothing, counter %d\n",
2971 __func__, *micbias_enable_count);
2972 break;
2973 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002974 /* Decide whether to switch the micbias for MBHC */
Simmi Pateriya71d63872012-11-08 01:06:30 +05302975 if (wreg == tabla->mbhc_bias_regs.ctl_reg) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002976 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002977 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002978 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
2979 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002980
Simmi Pateriya71d63872012-11-08 01:06:30 +05302981 snd_soc_update_bits(codec, wreg, 0x0E, 0x0A);
Patrick Lai3043fba2011-08-01 14:15:57 -07002982 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 1);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002983
2984 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002985 snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002986 else if (strnstr(w->name, internal2_text, 30))
2987 snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C);
2988 else if (strnstr(w->name, internal3_text, 30))
2989 snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3);
2990
Simmi Pateriya71d63872012-11-08 01:06:30 +05302991 snd_soc_update_bits(codec, wreg, 1 << 7, 1 << 7);
2992
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002993 break;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002994 case SND_SOC_DAPM_POST_PMU:
Simmi Pateriya71d63872012-11-08 01:06:30 +05302995 if (*micbias_enable_count > 1) {
2996 pr_debug("%s: do nothing, counter %d\n",
2997 __func__, *micbias_enable_count);
2998 break;
2999 }
Kiran Kandid8cf5212012-03-02 15:34:53 -08003000 usleep_range(20000, 20000);
3001
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003002 if (tabla->mbhc_polling_active &&
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003003 tabla->mbhc_cfg.micbias == micb_line) {
3004 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003005 tabla_codec_pause_hs_polling(codec);
3006 tabla_codec_start_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003007 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07003008 }
3009 break;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003010
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003011 case SND_SOC_DAPM_POST_PMD:
Simmi Pateriya71d63872012-11-08 01:06:30 +05303012 if (--*micbias_enable_count > 0) {
3013 pr_debug("%s: do nothing, counter %d\n",
3014 __func__, *micbias_enable_count);
3015 break;
3016 }
3017
3018 snd_soc_update_bits(codec, wreg, 1 << 7, 0);
3019
3020 if ((wreg == tabla->mbhc_bias_regs.ctl_reg) &&
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003021 tabla_is_hph_pa_on(codec)) {
3022 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003023 tabla_codec_switch_micbias(codec, 1);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003024 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
3025 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003026
Bradley Rubin229c6a52011-07-12 16:18:48 -07003027 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003028 snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00);
Bradley Rubin229c6a52011-07-12 16:18:48 -07003029 else if (strnstr(w->name, internal2_text, 30))
3030 snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00);
3031 else if (strnstr(w->name, internal3_text, 30))
3032 snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0);
3033
Patrick Lai3043fba2011-08-01 14:15:57 -07003034 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003035 break;
3036 }
3037
3038 return 0;
3039}
3040
Kiran Kandid8cf5212012-03-02 15:34:53 -08003041
3042static void tx_hpf_corner_freq_callback(struct work_struct *work)
3043{
3044 struct delayed_work *hpf_delayed_work;
3045 struct hpf_work *hpf_work;
3046 struct tabla_priv *tabla;
3047 struct snd_soc_codec *codec;
3048 u16 tx_mux_ctl_reg;
3049 u8 hpf_cut_of_freq;
3050
3051 hpf_delayed_work = to_delayed_work(work);
3052 hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
3053 tabla = hpf_work->tabla;
3054 codec = hpf_work->tabla->codec;
3055 hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq;
3056
3057 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL +
3058 (hpf_work->decimator - 1) * 8;
3059
3060 pr_debug("%s(): decimator %u hpf_cut_of_freq 0x%x\n", __func__,
3061 hpf_work->decimator, (unsigned int)hpf_cut_of_freq);
3062
3063 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4);
3064}
3065
3066#define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30
3067#define CF_MIN_3DB_4HZ 0x0
3068#define CF_MIN_3DB_75HZ 0x1
3069#define CF_MIN_3DB_150HZ 0x2
3070
Simmi Pateriya71d63872012-11-08 01:06:30 +05303071static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
3072 struct snd_kcontrol *kcontrol, int event);
3073
3074static int tabla_codec_enable_micbias_power(struct snd_soc_dapm_widget *w,
3075 struct snd_kcontrol *kcontrol,
3076 int event)
3077{
3078 struct snd_soc_codec *codec = w->codec;
3079 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3080
3081 pr_debug("%s %d\n", __func__, event);
3082
3083 switch (event) {
3084 case SND_SOC_DAPM_PRE_PMU:
3085 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, true);
3086 tabla_codec_enable_ldo_h(w, kcontrol, event);
3087 tabla_codec_enable_micbias(w, kcontrol, event);
3088 break;
3089 case SND_SOC_DAPM_POST_PMU:
3090 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, true);
3091 break;
3092 case SND_SOC_DAPM_POST_PMD:
3093 tabla_codec_enable_micbias(w, kcontrol, event);
3094 tabla_codec_enable_ldo_h(w, kcontrol, event);
3095 break;
3096 }
3097 return 0;
3098}
3099
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003100static int tabla_codec_enable_dec(struct snd_soc_dapm_widget *w,
3101 struct snd_kcontrol *kcontrol, int event)
3102{
3103 struct snd_soc_codec *codec = w->codec;
Kiran Kandid8cf5212012-03-02 15:34:53 -08003104 unsigned int decimator;
3105 char *dec_name = NULL;
3106 char *widget_name = NULL;
3107 char *temp;
3108 int ret = 0;
3109 u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg;
3110 u8 dec_hpf_cut_of_freq;
Kuirong Wange9c8a222012-03-28 16:24:09 -07003111 int offset;
3112
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003113
3114 pr_debug("%s %d\n", __func__, event);
3115
Kiran Kandid8cf5212012-03-02 15:34:53 -08003116 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
3117 if (!widget_name)
3118 return -ENOMEM;
3119 temp = widget_name;
3120
3121 dec_name = strsep(&widget_name, " ");
3122 widget_name = temp;
3123 if (!dec_name) {
3124 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
3125 ret = -EINVAL;
3126 goto out;
3127 }
3128
3129 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
3130 if (ret < 0) {
3131 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
3132 ret = -EINVAL;
3133 goto out;
3134 }
3135
3136 pr_debug("%s(): widget = %s dec_name = %s decimator = %u\n", __func__,
3137 w->name, dec_name, decimator);
3138
Kuirong Wange9c8a222012-03-28 16:24:09 -07003139 if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003140 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B1_CTL;
Kuirong Wange9c8a222012-03-28 16:24:09 -07003141 offset = 0;
3142 } else if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003143 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B2_CTL;
Kuirong Wange9c8a222012-03-28 16:24:09 -07003144 offset = 8;
3145 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003146 pr_err("%s: Error, incorrect dec\n", __func__);
3147 return -EINVAL;
3148 }
3149
Kiran Kandid8cf5212012-03-02 15:34:53 -08003150 tx_vol_ctl_reg = TABLA_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator -1);
3151 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
3152
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003153 switch (event) {
3154 case SND_SOC_DAPM_PRE_PMU:
Kiran Kandid8cf5212012-03-02 15:34:53 -08003155
3156 // Enableable TX digital mute */
3157 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
3158
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003159 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift,
3160 1 << w->shift);
3161 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0);
Kiran Kandid8cf5212012-03-02 15:34:53 -08003162
3163 dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg);
3164
3165 dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4;
3166
3167 tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq =
3168 dec_hpf_cut_of_freq;
3169
3170 if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) {
3171
3172 /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */
3173 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
3174 CF_MIN_3DB_150HZ << 4);
3175 }
3176
3177 /* enable HPF */
3178 snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00);
3179
3180 break;
3181
3182 case SND_SOC_DAPM_POST_PMU:
3183
3184 /* Disable TX digital mute */
3185 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00);
3186
3187 if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq !=
3188 CF_MIN_3DB_150HZ) {
3189
3190 schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork,
3191 msecs_to_jiffies(300));
3192 }
Kuirong Wange9c8a222012-03-28 16:24:09 -07003193 /* apply the digital gain after the decimator is enabled*/
Damir Didjustoed406e22012-11-16 15:44:57 -08003194 if ((w->shift + offset) < ARRAY_SIZE(tx_digital_gain_reg))
Kuirong Wange9c8a222012-03-28 16:24:09 -07003195 snd_soc_write(codec,
3196 tx_digital_gain_reg[w->shift + offset],
3197 snd_soc_read(codec,
3198 tx_digital_gain_reg[w->shift + offset])
3199 );
3200
Kiran Kandid8cf5212012-03-02 15:34:53 -08003201 break;
3202
3203 case SND_SOC_DAPM_PRE_PMD:
3204
3205 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
3206 cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork);
3207 break;
3208
3209 case SND_SOC_DAPM_POST_PMD:
3210
3211 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08);
3212 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
3213 (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4);
3214
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003215 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003216 }
Kiran Kandid8cf5212012-03-02 15:34:53 -08003217out:
3218 kfree(widget_name);
3219 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003220}
3221
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003222static int tabla_codec_reset_interpolator(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003223 struct snd_kcontrol *kcontrol, int event)
3224{
3225 struct snd_soc_codec *codec = w->codec;
3226
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003227 pr_debug("%s %d %s\n", __func__, event, w->name);
3228
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003229 switch (event) {
3230 case SND_SOC_DAPM_PRE_PMU:
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003231 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
3232 1 << w->shift, 1 << w->shift);
3233 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
3234 1 << w->shift, 0x0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003235 break;
Kuirong Wange9c8a222012-03-28 16:24:09 -07003236 case SND_SOC_DAPM_POST_PMU:
3237 /* apply the digital gain after the interpolator is enabled*/
3238 if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
3239 snd_soc_write(codec,
3240 rx_digital_gain_reg[w->shift],
3241 snd_soc_read(codec,
3242 rx_digital_gain_reg[w->shift])
3243 );
3244 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003245 }
3246 return 0;
3247}
3248
Simmi Pateriya71d63872012-11-08 01:06:30 +05303249static void tabla_enable_ldo_h(struct snd_soc_codec *codec, u32 enable)
3250{
3251 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3252
3253 if (enable) {
3254 if (++tabla->ldo_h_count == 1)
3255 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1,
3256 0x80, 0x80);
3257 } else {
3258 if (--tabla->ldo_h_count == 0)
3259 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1,
3260 0x80, 0x00);
3261 }
3262}
3263
Bradley Rubin229c6a52011-07-12 16:18:48 -07003264static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
3265 struct snd_kcontrol *kcontrol, int event)
3266{
Simmi Pateriya71d63872012-11-08 01:06:30 +05303267 struct snd_soc_codec *codec = w->codec;
3268
3269 pr_debug("%s %d\n", __func__, event);
3270
Bradley Rubin229c6a52011-07-12 16:18:48 -07003271 switch (event) {
Simmi Pateriya71d63872012-11-08 01:06:30 +05303272 case SND_SOC_DAPM_PRE_PMU:
3273 tabla_enable_ldo_h(codec, 1);
3274 usleep_range(1000, 1000);
3275 break;
Bradley Rubin229c6a52011-07-12 16:18:48 -07003276 case SND_SOC_DAPM_POST_PMD:
Simmi Pateriya71d63872012-11-08 01:06:30 +05303277 tabla_enable_ldo_h(codec, 0);
Bradley Rubin229c6a52011-07-12 16:18:48 -07003278 usleep_range(1000, 1000);
3279 break;
3280 }
3281 return 0;
3282}
3283
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003284static int tabla_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
3285 struct snd_kcontrol *kcontrol, int event)
3286{
3287 struct snd_soc_codec *codec = w->codec;
3288
3289 pr_debug("%s %d\n", __func__, event);
3290
3291 switch (event) {
3292 case SND_SOC_DAPM_PRE_PMU:
3293 tabla_enable_rx_bias(codec, 1);
3294 break;
3295 case SND_SOC_DAPM_POST_PMD:
3296 tabla_enable_rx_bias(codec, 0);
3297 break;
3298 }
3299 return 0;
3300}
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003301static int tabla_hphr_dac_event(struct snd_soc_dapm_widget *w,
3302 struct snd_kcontrol *kcontrol, int event)
3303{
3304 struct snd_soc_codec *codec = w->codec;
3305
3306 pr_debug("%s %s %d\n", __func__, w->name, event);
3307
3308 switch (event) {
3309 case SND_SOC_DAPM_PRE_PMU:
3310 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
3311 break;
3312 case SND_SOC_DAPM_POST_PMD:
3313 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
3314 break;
3315 }
3316 return 0;
3317}
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003318
Joonwoo Park8b1f0982011-12-08 17:12:45 -08003319static void tabla_snd_soc_jack_report(struct tabla_priv *tabla,
3320 struct snd_soc_jack *jack, int status,
3321 int mask)
3322{
3323 /* XXX: wake_lock_timeout()? */
Joonwoo Park03324832012-03-19 19:36:16 -07003324 snd_soc_jack_report_no_dapm(jack, status, mask);
Joonwoo Park8b1f0982011-12-08 17:12:45 -08003325}
3326
Patrick Lai49efeac2011-11-03 11:01:12 -07003327static void hphocp_off_report(struct tabla_priv *tabla,
3328 u32 jack_status, int irq)
3329{
3330 struct snd_soc_codec *codec;
Joonwoo Park03324832012-03-19 19:36:16 -07003331 if (!tabla) {
3332 pr_err("%s: Bad tabla private data\n", __func__);
3333 return;
3334 }
Patrick Lai49efeac2011-11-03 11:01:12 -07003335
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003336 pr_debug("%s: clear ocp status %x\n", __func__, jack_status);
Joonwoo Park03324832012-03-19 19:36:16 -07003337 codec = tabla->codec;
3338 if (tabla->hph_status & jack_status) {
Patrick Lai49efeac2011-11-03 11:01:12 -07003339 tabla->hph_status &= ~jack_status;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003340 if (tabla->mbhc_cfg.headset_jack)
3341 tabla_snd_soc_jack_report(tabla,
3342 tabla->mbhc_cfg.headset_jack,
Joonwoo Park8b1f0982011-12-08 17:12:45 -08003343 tabla->hph_status,
3344 TABLA_JACK_MASK);
Joonwoo Park0976d012011-12-22 11:48:18 -08003345 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x00);
3346 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10);
Patrick Laic7cae882011-11-18 11:52:49 -08003347 /* reset retry counter as PA is turned off signifying
3348 * start of new OCP detection session
3349 */
Joonwoo Parkf6574c72012-10-10 17:29:57 -07003350 if (WCD9XXX_IRQ_HPH_PA_OCPL_FAULT)
Patrick Laic7cae882011-11-18 11:52:49 -08003351 tabla->hphlocp_cnt = 0;
3352 else
3353 tabla->hphrocp_cnt = 0;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303354 wcd9xxx_enable_irq(codec->control_data, irq);
Patrick Lai49efeac2011-11-03 11:01:12 -07003355 }
3356}
3357
3358static void hphlocp_off_report(struct work_struct *work)
3359{
3360 struct tabla_priv *tabla = container_of(work, struct tabla_priv,
3361 hphlocp_work);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07003362 hphocp_off_report(tabla, SND_JACK_OC_HPHL,
3363 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07003364}
3365
3366static void hphrocp_off_report(struct work_struct *work)
3367{
3368 struct tabla_priv *tabla = container_of(work, struct tabla_priv,
3369 hphrocp_work);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07003370 hphocp_off_report(tabla, SND_JACK_OC_HPHR,
3371 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07003372}
3373
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08003374static int tabla_codec_enable_anc(struct snd_soc_dapm_widget *w,
3375 struct snd_kcontrol *kcontrol, int event)
3376{
3377 struct snd_soc_codec *codec = w->codec;
3378 const char *filename;
3379 const struct firmware *fw;
3380 int i;
3381 int ret;
3382 int num_anc_slots;
3383 struct anc_header *anc_head;
3384 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3385 u32 anc_writes_size = 0;
3386 int anc_size_remaining;
3387 u32 *anc_ptr;
3388 u16 reg;
3389 u8 mask, val, old_val;
3390 u8 mbhc_micb_ctl_val;
3391
3392 pr_debug("%s: DAPM Event %d ANC func is %d\n",
3393 __func__, event, tabla->anc_func);
3394
3395 if (tabla->anc_func == 0)
3396 return 0;
3397
3398 switch (event) {
3399 case SND_SOC_DAPM_PRE_PMU:
3400 mbhc_micb_ctl_val = snd_soc_read(codec,
3401 tabla->mbhc_bias_regs.ctl_reg);
3402
3403 if (!(mbhc_micb_ctl_val & 0x80)) {
3404 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
3405 tabla_codec_switch_micbias(codec, 1);
3406 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
3407 }
3408
3409 filename = "wcd9310/wcd9310_anc.bin";
3410
3411 ret = request_firmware(&fw, filename, codec->dev);
3412 if (ret != 0) {
3413 dev_err(codec->dev, "Failed to acquire ANC data: %d\n",
3414 ret);
3415 return -ENODEV;
3416 }
3417
3418 if (fw->size < sizeof(struct anc_header)) {
3419 dev_err(codec->dev, "Not enough data\n");
3420 release_firmware(fw);
3421 return -ENOMEM;
3422 }
3423
3424 /* First number is the number of register writes */
3425 anc_head = (struct anc_header *)(fw->data);
3426 anc_ptr = (u32 *)((u32)fw->data + sizeof(struct anc_header));
3427 anc_size_remaining = fw->size - sizeof(struct anc_header);
3428 num_anc_slots = anc_head->num_anc_slots;
3429
3430 if (tabla->anc_slot >= num_anc_slots) {
3431 dev_err(codec->dev, "Invalid ANC slot selected\n");
3432 release_firmware(fw);
3433 return -EINVAL;
3434 }
3435
3436 for (i = 0; i < num_anc_slots; i++) {
3437
3438 if (anc_size_remaining < TABLA_PACKED_REG_SIZE) {
3439 dev_err(codec->dev, "Invalid register format\n");
3440 release_firmware(fw);
3441 return -EINVAL;
3442 }
3443 anc_writes_size = (u32)(*anc_ptr);
3444 anc_size_remaining -= sizeof(u32);
3445 anc_ptr += 1;
3446
3447 if (anc_writes_size * TABLA_PACKED_REG_SIZE
3448 > anc_size_remaining) {
3449 dev_err(codec->dev, "Invalid register format\n");
3450 release_firmware(fw);
3451 return -ENOMEM;
3452 }
3453
3454 if (tabla->anc_slot == i)
3455 break;
3456
3457 anc_size_remaining -= (anc_writes_size *
3458 TABLA_PACKED_REG_SIZE);
3459 anc_ptr += anc_writes_size;
3460 }
3461 if (i == num_anc_slots) {
3462 dev_err(codec->dev, "Selected ANC slot not present\n");
3463 release_firmware(fw);
3464 return -ENOMEM;
3465 }
3466
3467 for (i = 0; i < anc_writes_size; i++) {
3468 TABLA_CODEC_UNPACK_ENTRY(anc_ptr[i], reg,
3469 mask, val);
3470 old_val = snd_soc_read(codec, reg);
3471 snd_soc_write(codec, reg, (old_val & ~mask) |
3472 (val & mask));
3473 }
3474 usleep_range(10000, 10000);
3475 snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x30);
3476 msleep(30);
3477 release_firmware(fw);
3478 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
3479 /* if MBHC polling is active, set TX7_MBHC_EN bit 7 */
3480 if (tabla->mbhc_polling_active)
3481 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80,
3482 0x80);
3483 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
3484 break;
3485 case SND_SOC_DAPM_POST_PMD:
3486 /* schedule work is required because at the time HPH PA DAPM
3487 * event callback is called by DAPM framework, CODEC dapm mutex
3488 * would have been locked while snd_soc_jack_report also
3489 * attempts to acquire same lock.
3490 */
3491 if (w->shift == 5) {
3492 clear_bit(TABLA_HPHL_PA_OFF_ACK,
3493 &tabla->hph_pa_dac_state);
3494 clear_bit(TABLA_HPHL_DAC_OFF_ACK,
3495 &tabla->hph_pa_dac_state);
3496 if (tabla->hph_status & SND_JACK_OC_HPHL)
3497 schedule_work(&tabla->hphlocp_work);
3498 } else if (w->shift == 4) {
3499 clear_bit(TABLA_HPHR_PA_OFF_ACK,
3500 &tabla->hph_pa_dac_state);
3501 clear_bit(TABLA_HPHR_DAC_OFF_ACK,
3502 &tabla->hph_pa_dac_state);
3503 if (tabla->hph_status & SND_JACK_OC_HPHR)
3504 schedule_work(&tabla->hphrocp_work);
3505 }
3506
3507 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
3508 tabla_codec_switch_micbias(codec, 0);
3509 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
3510
3511 break;
3512 case SND_SOC_DAPM_PRE_PMD:
3513 snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00);
3514 msleep(40);
3515 /* unset TX7_MBHC_EN bit 7 */
3516 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00);
3517 snd_soc_update_bits(codec, TABLA_A_CDC_ANC1_CTL, 0x01, 0x00);
3518 snd_soc_update_bits(codec, TABLA_A_CDC_ANC2_CTL, 0x01, 0x00);
3519 msleep(20);
3520 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0x0F);
3521 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_CLK_EN_CTL, 0);
3522 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0xFF);
3523 break;
3524 }
3525 return 0;
3526}
3527
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003528static int tabla_hph_pa_event(struct snd_soc_dapm_widget *w,
3529 struct snd_kcontrol *kcontrol, int event)
3530{
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003531 struct snd_soc_codec *codec = w->codec;
3532 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3533 u8 mbhc_micb_ctl_val;
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003534 pr_debug("%s: event = %d\n", __func__, event);
3535
3536 switch (event) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003537 case SND_SOC_DAPM_PRE_PMU:
3538 mbhc_micb_ctl_val = snd_soc_read(codec,
3539 tabla->mbhc_bias_regs.ctl_reg);
3540
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003541 if (!(mbhc_micb_ctl_val & 0x80)) {
3542 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003543 tabla_codec_switch_micbias(codec, 1);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003544 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
3545 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003546 break;
3547
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003548 case SND_SOC_DAPM_POST_PMD:
Patrick Lai49efeac2011-11-03 11:01:12 -07003549 /* schedule work is required because at the time HPH PA DAPM
3550 * event callback is called by DAPM framework, CODEC dapm mutex
3551 * would have been locked while snd_soc_jack_report also
3552 * attempts to acquire same lock.
3553 */
Joonwoo Parka9444452011-12-08 18:48:27 -08003554 if (w->shift == 5) {
3555 clear_bit(TABLA_HPHL_PA_OFF_ACK,
3556 &tabla->hph_pa_dac_state);
3557 clear_bit(TABLA_HPHL_DAC_OFF_ACK,
3558 &tabla->hph_pa_dac_state);
3559 if (tabla->hph_status & SND_JACK_OC_HPHL)
3560 schedule_work(&tabla->hphlocp_work);
3561 } else if (w->shift == 4) {
3562 clear_bit(TABLA_HPHR_PA_OFF_ACK,
3563 &tabla->hph_pa_dac_state);
3564 clear_bit(TABLA_HPHR_DAC_OFF_ACK,
3565 &tabla->hph_pa_dac_state);
3566 if (tabla->hph_status & SND_JACK_OC_HPHR)
3567 schedule_work(&tabla->hphrocp_work);
3568 }
3569
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003570 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Joonwoo Park03324832012-03-19 19:36:16 -07003571 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003572 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003573
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003574 pr_debug("%s: sleep 10 ms after %s PA disable.\n", __func__,
3575 w->name);
3576 usleep_range(10000, 10000);
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003577 break;
3578 }
3579 return 0;
3580}
3581
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003582static void tabla_get_mbhc_micbias_regs(struct snd_soc_codec *codec,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003583 struct mbhc_micbias_regs *micbias_regs)
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003584{
3585 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003586 unsigned int cfilt;
3587
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003588 switch (tabla->mbhc_cfg.micbias) {
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003589 case TABLA_MICBIAS1:
3590 cfilt = tabla->pdata->micbias.bias1_cfilt_sel;
3591 micbias_regs->mbhc_reg = TABLA_A_MICB_1_MBHC;
3592 micbias_regs->int_rbias = TABLA_A_MICB_1_INT_RBIAS;
3593 micbias_regs->ctl_reg = TABLA_A_MICB_1_CTL;
3594 break;
3595 case TABLA_MICBIAS2:
3596 cfilt = tabla->pdata->micbias.bias2_cfilt_sel;
3597 micbias_regs->mbhc_reg = TABLA_A_MICB_2_MBHC;
3598 micbias_regs->int_rbias = TABLA_A_MICB_2_INT_RBIAS;
3599 micbias_regs->ctl_reg = TABLA_A_MICB_2_CTL;
3600 break;
3601 case TABLA_MICBIAS3:
3602 cfilt = tabla->pdata->micbias.bias3_cfilt_sel;
3603 micbias_regs->mbhc_reg = TABLA_A_MICB_3_MBHC;
3604 micbias_regs->int_rbias = TABLA_A_MICB_3_INT_RBIAS;
3605 micbias_regs->ctl_reg = TABLA_A_MICB_3_CTL;
3606 break;
3607 case TABLA_MICBIAS4:
3608 cfilt = tabla->pdata->micbias.bias4_cfilt_sel;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003609 micbias_regs->mbhc_reg = tabla->reg_addr.micb_4_mbhc;
3610 micbias_regs->int_rbias = tabla->reg_addr.micb_4_int_rbias;
3611 micbias_regs->ctl_reg = tabla->reg_addr.micb_4_ctl;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003612 break;
3613 default:
3614 /* Should never reach here */
3615 pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__);
Jordan Crouse239d8412011-11-23 11:47:02 -07003616 return;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003617 }
3618
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08003619 micbias_regs->cfilt_sel = cfilt;
3620
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003621 switch (cfilt) {
3622 case TABLA_CFILT1_SEL:
3623 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_1_VAL;
3624 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_1_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08003625 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt1_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003626 break;
3627 case TABLA_CFILT2_SEL:
3628 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_2_VAL;
3629 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_2_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08003630 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt2_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003631 break;
3632 case TABLA_CFILT3_SEL:
3633 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_3_VAL;
3634 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_3_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08003635 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt3_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003636 break;
3637 }
3638}
Santosh Mardie15e2302011-11-15 10:39:23 +05303639static const struct snd_soc_dapm_widget tabla_dapm_i2s_widgets[] = {
3640 SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", TABLA_A_CDC_CLK_RX_I2S_CTL,
3641 4, 0, NULL, 0),
3642 SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", TABLA_A_CDC_CLK_TX_I2S_CTL, 4,
3643 0, NULL, 0),
3644};
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003645
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003646static int tabla_lineout_dac_event(struct snd_soc_dapm_widget *w,
3647 struct snd_kcontrol *kcontrol, int event)
3648{
3649 struct snd_soc_codec *codec = w->codec;
3650
3651 pr_debug("%s %s %d\n", __func__, w->name, event);
3652
3653 switch (event) {
3654 case SND_SOC_DAPM_PRE_PMU:
3655 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
3656 break;
3657
3658 case SND_SOC_DAPM_POST_PMD:
3659 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
3660 break;
3661 }
3662 return 0;
3663}
3664
Damir Didjusto7c85d712012-08-16 21:22:29 -07003665static int tabla_ear_pa_event(struct snd_soc_dapm_widget *w,
3666 struct snd_kcontrol *kcontrol, int event)
3667{
3668 struct snd_soc_codec *codec = w->codec;
3669
3670 pr_debug("%s %d\n", __func__, event);
3671
3672 switch (event) {
3673 case SND_SOC_DAPM_PRE_PMU:
3674 snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x50, 0x50);
3675 break;
3676
3677 case SND_SOC_DAPM_PRE_PMD:
3678 snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x10, 0x00);
3679 snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x40, 0x00);
3680 break;
3681 }
3682 return 0;
3683}
3684
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003685static const struct snd_soc_dapm_widget tabla_1_x_dapm_widgets[] = {
Simmi Pateriya71d63872012-11-08 01:06:30 +05303686 SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", SND_SOC_NOPM, 0,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303687 0, tabla_codec_enable_micbias,
3688 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3689 SND_SOC_DAPM_POST_PMD),
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003690};
3691
3692static const struct snd_soc_dapm_widget tabla_2_higher_dapm_widgets[] = {
Simmi Pateriya71d63872012-11-08 01:06:30 +05303693 SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", SND_SOC_NOPM, 0,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303694 0, tabla_codec_enable_micbias,
3695 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3696 SND_SOC_DAPM_POST_PMD),
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003697};
3698
Santosh Mardie15e2302011-11-15 10:39:23 +05303699static const struct snd_soc_dapm_route audio_i2s_map[] = {
3700 {"RX_I2S_CLK", NULL, "CDC_CONN"},
3701 {"SLIM RX1", NULL, "RX_I2S_CLK"},
3702 {"SLIM RX2", NULL, "RX_I2S_CLK"},
3703 {"SLIM RX3", NULL, "RX_I2S_CLK"},
3704 {"SLIM RX4", NULL, "RX_I2S_CLK"},
3705
3706 {"SLIM TX7", NULL, "TX_I2S_CLK"},
3707 {"SLIM TX8", NULL, "TX_I2S_CLK"},
3708 {"SLIM TX9", NULL, "TX_I2S_CLK"},
3709 {"SLIM TX10", NULL, "TX_I2S_CLK"},
3710};
3711
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003712static const struct snd_soc_dapm_route audio_map[] = {
3713 /* SLIMBUS Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003714
Kuirong Wang906ac472012-07-09 12:54:44 -07003715 {"AIF1 CAP", NULL, "AIF1_CAP Mixer"},
3716 {"AIF2 CAP", NULL, "AIF2_CAP Mixer"},
3717 {"AIF3 CAP", NULL, "AIF3_CAP Mixer"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003718
Kuirong Wang906ac472012-07-09 12:54:44 -07003719 /* SLIM_MIXER("AIF1_CAP Mixer"),*/
3720 {"AIF1_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
3721 {"AIF1_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
3722 {"AIF1_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
3723 {"AIF1_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
3724 {"AIF1_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
3725 {"AIF1_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"},
3726 {"AIF1_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"},
3727 {"AIF1_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"},
3728 {"AIF1_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"},
3729 {"AIF1_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"},
3730 /* SLIM_MIXER("AIF2_CAP Mixer"),*/
3731 {"AIF2_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
3732 {"AIF2_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
3733 {"AIF2_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
3734 {"AIF2_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
3735 {"AIF2_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
3736 {"AIF2_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"},
3737 {"AIF2_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"},
3738 {"AIF2_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"},
3739 {"AIF2_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"},
3740 {"AIF2_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"},
3741 /* SLIM_MIXER("AIF3_CAP Mixer"),*/
3742 {"AIF3_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
3743 {"AIF3_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
3744 {"AIF3_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
3745 {"AIF3_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
3746 {"AIF3_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
3747 {"AIF3_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"},
3748 {"AIF3_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"},
3749 {"AIF3_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"},
3750 {"AIF3_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"},
3751 {"AIF3_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"},
3752
3753 {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003754 {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"},
3755
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003756 {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"},
Neema Shetty3fb1b802012-04-27 13:53:24 -07003757 {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"},
3758 {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"},
3759 {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"},
3760 {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"},
3761 {"SLIM TX3 MUX", "RMIX5", "RX5 MIX1"},
3762 {"SLIM TX3 MUX", "RMIX6", "RX6 MIX1"},
3763 {"SLIM TX3 MUX", "RMIX7", "RX7 MIX1"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003764
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003765 {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"},
3766
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003767 {"SLIM TX5 MUX", "DEC5", "DEC5 MUX"},
Neema Shetty3fb1b802012-04-27 13:53:24 -07003768 {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"},
3769 {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"},
3770 {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"},
3771 {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"},
3772 {"SLIM TX5 MUX", "RMIX5", "RX5 MIX1"},
3773 {"SLIM TX5 MUX", "RMIX6", "RX6 MIX1"},
3774 {"SLIM TX5 MUX", "RMIX7", "RX7 MIX1"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003775
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003776 {"SLIM TX6 MUX", "DEC6", "DEC6 MUX"},
3777
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003778 {"SLIM TX7 MUX", "DEC1", "DEC1 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07003779 {"SLIM TX7 MUX", "DEC2", "DEC2 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003780 {"SLIM TX7 MUX", "DEC3", "DEC3 MUX"},
3781 {"SLIM TX7 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003782 {"SLIM TX7 MUX", "DEC5", "DEC5 MUX"},
3783 {"SLIM TX7 MUX", "DEC6", "DEC6 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07003784 {"SLIM TX7 MUX", "DEC7", "DEC7 MUX"},
3785 {"SLIM TX7 MUX", "DEC8", "DEC8 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003786 {"SLIM TX7 MUX", "DEC9", "DEC9 MUX"},
3787 {"SLIM TX7 MUX", "DEC10", "DEC10 MUX"},
Neema Shetty3fb1b802012-04-27 13:53:24 -07003788 {"SLIM TX7 MUX", "RMIX1", "RX1 MIX1"},
3789 {"SLIM TX7 MUX", "RMIX2", "RX2 MIX1"},
3790 {"SLIM TX7 MUX", "RMIX3", "RX3 MIX1"},
3791 {"SLIM TX7 MUX", "RMIX4", "RX4 MIX1"},
3792 {"SLIM TX7 MUX", "RMIX5", "RX5 MIX1"},
3793 {"SLIM TX7 MUX", "RMIX6", "RX6 MIX1"},
3794 {"SLIM TX7 MUX", "RMIX7", "RX7 MIX1"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003795
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003796 {"SLIM TX8 MUX", "DEC1", "DEC1 MUX"},
3797 {"SLIM TX8 MUX", "DEC2", "DEC2 MUX"},
3798 {"SLIM TX8 MUX", "DEC3", "DEC3 MUX"},
Bhalchandra Gajare9ec83cd2011-09-23 17:25:07 -07003799 {"SLIM TX8 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003800 {"SLIM TX8 MUX", "DEC5", "DEC5 MUX"},
3801 {"SLIM TX8 MUX", "DEC6", "DEC6 MUX"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003802 {"SLIM TX8 MUX", "DEC7", "DEC7 MUX"},
3803 {"SLIM TX8 MUX", "DEC8", "DEC8 MUX"},
3804 {"SLIM TX8 MUX", "DEC9", "DEC9 MUX"},
3805 {"SLIM TX8 MUX", "DEC10", "DEC10 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003806
Kiran Kandi3426e512011-09-13 22:50:10 -07003807 {"SLIM TX9 MUX", "DEC1", "DEC1 MUX"},
3808 {"SLIM TX9 MUX", "DEC2", "DEC2 MUX"},
3809 {"SLIM TX9 MUX", "DEC3", "DEC3 MUX"},
3810 {"SLIM TX9 MUX", "DEC4", "DEC4 MUX"},
3811 {"SLIM TX9 MUX", "DEC5", "DEC5 MUX"},
3812 {"SLIM TX9 MUX", "DEC6", "DEC6 MUX"},
3813 {"SLIM TX9 MUX", "DEC7", "DEC7 MUX"},
3814 {"SLIM TX9 MUX", "DEC8", "DEC8 MUX"},
3815 {"SLIM TX9 MUX", "DEC9", "DEC9 MUX"},
3816 {"SLIM TX9 MUX", "DEC10", "DEC10 MUX"},
3817
Kiran Kandi3426e512011-09-13 22:50:10 -07003818 {"SLIM TX10 MUX", "DEC1", "DEC1 MUX"},
3819 {"SLIM TX10 MUX", "DEC2", "DEC2 MUX"},
3820 {"SLIM TX10 MUX", "DEC3", "DEC3 MUX"},
3821 {"SLIM TX10 MUX", "DEC4", "DEC4 MUX"},
3822 {"SLIM TX10 MUX", "DEC5", "DEC5 MUX"},
3823 {"SLIM TX10 MUX", "DEC6", "DEC6 MUX"},
3824 {"SLIM TX10 MUX", "DEC7", "DEC7 MUX"},
3825 {"SLIM TX10 MUX", "DEC8", "DEC8 MUX"},
3826 {"SLIM TX10 MUX", "DEC9", "DEC9 MUX"},
3827 {"SLIM TX10 MUX", "DEC10", "DEC10 MUX"},
3828
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003829 /* Earpiece (RX MIX1) */
3830 {"EAR", NULL, "EAR PA"},
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003831 {"EAR PA", NULL, "EAR_PA_MIXER"},
3832 {"EAR_PA_MIXER", NULL, "DAC1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003833 {"DAC1", NULL, "CP"},
3834
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003835 {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"},
3836 {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003837
3838 /* Headset (RX MIX1 and RX MIX2) */
3839 {"HEADPHONE", NULL, "HPHL"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003840 {"HEADPHONE", NULL, "HPHR"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003841
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003842 {"HPHL", NULL, "HPHL_PA_MIXER"},
3843 {"HPHL_PA_MIXER", NULL, "HPHL DAC"},
3844
3845 {"HPHR", NULL, "HPHR_PA_MIXER"},
3846 {"HPHR_PA_MIXER", NULL, "HPHR DAC"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003847
3848 {"HPHL DAC", NULL, "CP"},
3849 {"HPHR DAC", NULL, "CP"},
3850
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08003851 {"ANC HEADPHONE", NULL, "ANC HPHL"},
3852 {"ANC HEADPHONE", NULL, "ANC HPHR"},
3853
3854 {"ANC HPHL", NULL, "HPHL_PA_MIXER"},
3855 {"ANC HPHR", NULL, "HPHR_PA_MIXER"},
3856
Bradley Rubin229c6a52011-07-12 16:18:48 -07003857 {"ANC1 MUX", "ADC1", "ADC1"},
3858 {"ANC1 MUX", "ADC2", "ADC2"},
3859 {"ANC1 MUX", "ADC3", "ADC3"},
3860 {"ANC1 MUX", "ADC4", "ADC4"},
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08003861 {"ANC1 MUX", "DMIC1", "DMIC1"},
3862 {"ANC1 MUX", "DMIC2", "DMIC2"},
3863 {"ANC1 MUX", "DMIC3", "DMIC3"},
3864 {"ANC1 MUX", "DMIC4", "DMIC4"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003865 {"ANC2 MUX", "ADC1", "ADC1"},
3866 {"ANC2 MUX", "ADC2", "ADC2"},
3867 {"ANC2 MUX", "ADC3", "ADC3"},
3868 {"ANC2 MUX", "ADC4", "ADC4"},
3869
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08003870 {"ANC HPHR", NULL, "CDC_CONN"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003871 {"DAC1", "Switch", "RX1 CHAIN"},
3872 {"HPHL DAC", "Switch", "RX1 CHAIN"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003873 {"HPHR DAC", NULL, "RX2 CHAIN"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003874
Kiran Kandidb0a4b02011-08-23 09:32:09 -07003875 {"LINEOUT1", NULL, "LINEOUT1 PA"},
3876 {"LINEOUT2", NULL, "LINEOUT2 PA"},
3877 {"LINEOUT3", NULL, "LINEOUT3 PA"},
3878 {"LINEOUT4", NULL, "LINEOUT4 PA"},
3879 {"LINEOUT5", NULL, "LINEOUT5 PA"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003880
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003881 {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"},
3882 {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"},
3883 {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"},
3884 {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"},
3885 {"LINEOUT3 PA", NULL, "LINEOUT3_PA_MIXER"},
3886 {"LINEOUT3_PA_MIXER", NULL, "LINEOUT3 DAC"},
3887 {"LINEOUT4 PA", NULL, "LINEOUT4_PA_MIXER"},
3888 {"LINEOUT4_PA_MIXER", NULL, "LINEOUT4 DAC"},
3889 {"LINEOUT5 PA", NULL, "LINEOUT5_PA_MIXER"},
3890 {"LINEOUT5_PA_MIXER", NULL, "LINEOUT5 DAC"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003891
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003892 {"LINEOUT1 DAC", NULL, "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003893 {"LINEOUT5 DAC", NULL, "RX7 MIX1"},
3894
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003895 {"RX1 CHAIN", NULL, "RX1 MIX2"},
3896 {"RX2 CHAIN", NULL, "RX2 MIX2"},
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08003897 {"RX1 MIX2", NULL, "ANC1 MUX"},
3898 {"RX2 MIX2", NULL, "ANC2 MUX"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003899
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003900 {"CP", NULL, "RX_BIAS"},
3901 {"LINEOUT1 DAC", NULL, "RX_BIAS"},
3902 {"LINEOUT2 DAC", NULL, "RX_BIAS"},
3903 {"LINEOUT3 DAC", NULL, "RX_BIAS"},
3904 {"LINEOUT4 DAC", NULL, "RX_BIAS"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003905 {"LINEOUT5 DAC", NULL, "RX_BIAS"},
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003906
Kuirong Wang0f8ade32012-02-27 16:29:45 -08003907 {"RX1 MIX1", NULL, "COMP1_CLK"},
3908 {"RX2 MIX1", NULL, "COMP1_CLK"},
3909 {"RX3 MIX1", NULL, "COMP2_CLK"},
3910 {"RX5 MIX1", NULL, "COMP2_CLK"},
3911
3912
Bradley Rubin229c6a52011-07-12 16:18:48 -07003913 {"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
3914 {"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003915 {"RX1 MIX1", NULL, "RX1 MIX1 INP3"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003916 {"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
3917 {"RX2 MIX1", NULL, "RX2 MIX1 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003918 {"RX3 MIX1", NULL, "RX3 MIX1 INP1"},
3919 {"RX3 MIX1", NULL, "RX3 MIX1 INP2"},
3920 {"RX4 MIX1", NULL, "RX4 MIX1 INP1"},
3921 {"RX4 MIX1", NULL, "RX4 MIX1 INP2"},
3922 {"RX5 MIX1", NULL, "RX5 MIX1 INP1"},
3923 {"RX5 MIX1", NULL, "RX5 MIX1 INP2"},
3924 {"RX6 MIX1", NULL, "RX6 MIX1 INP1"},
3925 {"RX6 MIX1", NULL, "RX6 MIX1 INP2"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07003926 {"RX7 MIX1", NULL, "RX7 MIX1 INP1"},
3927 {"RX7 MIX1", NULL, "RX7 MIX1 INP2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003928 {"RX1 MIX2", NULL, "RX1 MIX1"},
3929 {"RX1 MIX2", NULL, "RX1 MIX2 INP1"},
3930 {"RX1 MIX2", NULL, "RX1 MIX2 INP2"},
3931 {"RX2 MIX2", NULL, "RX2 MIX1"},
3932 {"RX2 MIX2", NULL, "RX2 MIX2 INP1"},
3933 {"RX2 MIX2", NULL, "RX2 MIX2 INP2"},
3934 {"RX3 MIX2", NULL, "RX3 MIX1"},
3935 {"RX3 MIX2", NULL, "RX3 MIX2 INP1"},
3936 {"RX3 MIX2", NULL, "RX3 MIX2 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003937
Kuirong Wang906ac472012-07-09 12:54:44 -07003938 /* SLIM_MUX("AIF1_PB", "AIF1 PB"),*/
3939 {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"},
3940 {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"},
3941 {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"},
3942 {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"},
3943 {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"},
3944 {"SLIM RX6 MUX", "AIF1_PB", "AIF1 PB"},
3945 {"SLIM RX7 MUX", "AIF1_PB", "AIF1 PB"},
3946 /* SLIM_MUX("AIF2_PB", "AIF2 PB"),*/
3947 {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"},
3948 {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"},
3949 {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"},
3950 {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"},
3951 {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"},
3952 {"SLIM RX6 MUX", "AIF2_PB", "AIF2 PB"},
3953 {"SLIM RX7 MUX", "AIF2_PB", "AIF2 PB"},
3954 /* SLIM_MUX("AIF3_PB", "AIF3 PB"),*/
3955 {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"},
3956 {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"},
3957 {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"},
3958 {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"},
3959 {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"},
3960 {"SLIM RX6 MUX", "AIF3_PB", "AIF3 PB"},
3961 {"SLIM RX7 MUX", "AIF3_PB", "AIF3 PB"},
3962
3963 {"SLIM RX1", NULL, "SLIM RX1 MUX"},
3964 {"SLIM RX2", NULL, "SLIM RX2 MUX"},
3965 {"SLIM RX3", NULL, "SLIM RX3 MUX"},
3966 {"SLIM RX4", NULL, "SLIM RX4 MUX"},
3967 {"SLIM RX5", NULL, "SLIM RX5 MUX"},
3968 {"SLIM RX6", NULL, "SLIM RX6 MUX"},
3969 {"SLIM RX7", NULL, "SLIM RX7 MUX"},
3970
3971 /* Mixer control for output path */
Bradley Rubin229c6a52011-07-12 16:18:48 -07003972 {"RX1 MIX1 INP1", "RX1", "SLIM RX1"},
3973 {"RX1 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303974 {"RX1 MIX1 INP1", "RX3", "SLIM RX3"},
3975 {"RX1 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003976 {"RX1 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003977 {"RX1 MIX1 INP1", "RX6", "SLIM RX6"},
3978 {"RX1 MIX1 INP1", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003979 {"RX1 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07003980 {"RX1 MIX1 INP1", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003981 {"RX1 MIX1 INP2", "RX1", "SLIM RX1"},
3982 {"RX1 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303983 {"RX1 MIX1 INP2", "RX3", "SLIM RX3"},
3984 {"RX1 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003985 {"RX1 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003986 {"RX1 MIX1 INP2", "RX6", "SLIM RX6"},
3987 {"RX1 MIX1 INP2", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003988 {"RX1 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07003989 {"RX1 MIX1 INP2", "IIR2", "IIR2"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003990 {"RX1 MIX1 INP3", "RX1", "SLIM RX1"},
3991 {"RX1 MIX1 INP3", "RX2", "SLIM RX2"},
3992 {"RX1 MIX1 INP3", "RX3", "SLIM RX3"},
3993 {"RX1 MIX1 INP3", "RX4", "SLIM RX4"},
3994 {"RX1 MIX1 INP3", "RX5", "SLIM RX5"},
3995 {"RX1 MIX1 INP3", "RX6", "SLIM RX6"},
3996 {"RX1 MIX1 INP3", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003997 {"RX2 MIX1 INP1", "RX1", "SLIM RX1"},
3998 {"RX2 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303999 {"RX2 MIX1 INP1", "RX3", "SLIM RX3"},
4000 {"RX2 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004001 {"RX2 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004002 {"RX2 MIX1 INP1", "RX6", "SLIM RX6"},
4003 {"RX2 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004004 {"RX2 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004005 {"RX2 MIX1 INP1", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004006 {"RX2 MIX1 INP2", "RX1", "SLIM RX1"},
4007 {"RX2 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304008 {"RX2 MIX1 INP2", "RX3", "SLIM RX3"},
4009 {"RX2 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004010 {"RX2 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004011 {"RX2 MIX1 INP2", "RX6", "SLIM RX6"},
4012 {"RX2 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004013 {"RX2 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004014 {"RX2 MIX1 INP2", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004015 {"RX3 MIX1 INP1", "RX1", "SLIM RX1"},
4016 {"RX3 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304017 {"RX3 MIX1 INP1", "RX3", "SLIM RX3"},
4018 {"RX3 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004019 {"RX3 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004020 {"RX3 MIX1 INP1", "RX6", "SLIM RX6"},
4021 {"RX3 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004022 {"RX3 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004023 {"RX3 MIX1 INP1", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004024 {"RX3 MIX1 INP2", "RX1", "SLIM RX1"},
4025 {"RX3 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304026 {"RX3 MIX1 INP2", "RX3", "SLIM RX3"},
4027 {"RX3 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004028 {"RX3 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004029 {"RX3 MIX1 INP2", "RX6", "SLIM RX6"},
4030 {"RX3 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004031 {"RX3 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004032 {"RX3 MIX1 INP2", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004033 {"RX4 MIX1 INP1", "RX1", "SLIM RX1"},
4034 {"RX4 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304035 {"RX4 MIX1 INP1", "RX3", "SLIM RX3"},
4036 {"RX4 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004037 {"RX4 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004038 {"RX4 MIX1 INP1", "RX6", "SLIM RX6"},
4039 {"RX4 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004040 {"RX4 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004041 {"RX4 MIX1 INP1", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004042 {"RX4 MIX1 INP2", "RX1", "SLIM RX1"},
4043 {"RX4 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304044 {"RX4 MIX1 INP2", "RX3", "SLIM RX3"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004045 {"RX4 MIX1 INP2", "RX5", "SLIM RX5"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304046 {"RX4 MIX1 INP2", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004047 {"RX4 MIX1 INP2", "RX6", "SLIM RX6"},
4048 {"RX4 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004049 {"RX4 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004050 {"RX4 MIX1 INP2", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004051 {"RX5 MIX1 INP1", "RX1", "SLIM RX1"},
4052 {"RX5 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304053 {"RX5 MIX1 INP1", "RX3", "SLIM RX3"},
4054 {"RX5 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004055 {"RX5 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004056 {"RX5 MIX1 INP1", "RX6", "SLIM RX6"},
4057 {"RX5 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004058 {"RX5 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004059 {"RX5 MIX1 INP1", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004060 {"RX5 MIX1 INP2", "RX1", "SLIM RX1"},
4061 {"RX5 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304062 {"RX5 MIX1 INP2", "RX3", "SLIM RX3"},
4063 {"RX5 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004064 {"RX5 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004065 {"RX5 MIX1 INP2", "RX6", "SLIM RX6"},
4066 {"RX5 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004067 {"RX5 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004068 {"RX5 MIX1 INP2", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004069 {"RX6 MIX1 INP1", "RX1", "SLIM RX1"},
4070 {"RX6 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304071 {"RX6 MIX1 INP1", "RX3", "SLIM RX3"},
4072 {"RX6 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004073 {"RX6 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004074 {"RX6 MIX1 INP1", "RX6", "SLIM RX6"},
4075 {"RX6 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004076 {"RX6 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004077 {"RX6 MIX1 INP1", "IIR2", "IIR2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004078 {"RX6 MIX1 INP2", "RX1", "SLIM RX1"},
4079 {"RX6 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304080 {"RX6 MIX1 INP2", "RX3", "SLIM RX3"},
4081 {"RX6 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004082 {"RX6 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004083 {"RX6 MIX1 INP2", "RX6", "SLIM RX6"},
4084 {"RX6 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004085 {"RX6 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004086 {"RX6 MIX1 INP2", "IIR2", "IIR2"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07004087 {"RX7 MIX1 INP1", "RX1", "SLIM RX1"},
4088 {"RX7 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304089 {"RX7 MIX1 INP1", "RX3", "SLIM RX3"},
4090 {"RX7 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004091 {"RX7 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004092 {"RX7 MIX1 INP1", "RX6", "SLIM RX6"},
4093 {"RX7 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004094 {"RX7 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004095 {"RX7 MIX1 INP1", "IIR2", "IIR2"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07004096 {"RX7 MIX1 INP2", "RX1", "SLIM RX1"},
4097 {"RX7 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05304098 {"RX7 MIX1 INP2", "RX3", "SLIM RX3"},
4099 {"RX7 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07004100 {"RX7 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08004101 {"RX7 MIX1 INP2", "RX6", "SLIM RX6"},
4102 {"RX7 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07004103 {"RX7 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004104 {"RX7 MIX1 INP2", "IIR2", "IIR2"},
4105
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004106 {"RX1 MIX2 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004107 {"RX1 MIX2 INP1", "IIR2", "IIR2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004108 {"RX1 MIX2 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004109 {"RX1 MIX2 INP2", "IIR2", "IIR2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004110 {"RX2 MIX2 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004111 {"RX2 MIX2 INP1", "IIR2", "IIR2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004112 {"RX2 MIX2 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004113 {"RX2 MIX2 INP2", "IIR2", "IIR2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004114 {"RX3 MIX2 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004115 {"RX3 MIX2 INP1", "IIR2", "IIR2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004116 {"RX3 MIX2 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004117 {"RX3 MIX2 INP2", "IIR2", "IIR2"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004118
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004119 /* Decimator Inputs */
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004120 {"DEC1 MUX", "DMIC1", "DMIC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07004121 {"DEC1 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004122 {"DEC1 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07004123 {"DEC2 MUX", "DMIC2", "DMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004124 {"DEC2 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004125 {"DEC2 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07004126 {"DEC3 MUX", "DMIC3", "DMIC3"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004127 {"DEC3 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004128 {"DEC3 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07004129 {"DEC4 MUX", "DMIC4", "DMIC4"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004130 {"DEC4 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004131 {"DEC4 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07004132 {"DEC5 MUX", "DMIC5", "DMIC5"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004133 {"DEC5 MUX", "ADC2", "ADC2"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004134 {"DEC5 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07004135 {"DEC6 MUX", "DMIC6", "DMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004136 {"DEC6 MUX", "ADC1", "ADC1"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004137 {"DEC6 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004138 {"DEC7 MUX", "DMIC1", "DMIC1"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004139 {"DEC7 MUX", "DMIC6", "DMIC6"},
4140 {"DEC7 MUX", "ADC1", "ADC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07004141 {"DEC7 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004142 {"DEC7 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004143 {"DEC8 MUX", "DMIC2", "DMIC2"},
4144 {"DEC8 MUX", "DMIC5", "DMIC5"},
4145 {"DEC8 MUX", "ADC2", "ADC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004146 {"DEC8 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004147 {"DEC8 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004148 {"DEC9 MUX", "DMIC4", "DMIC4"},
4149 {"DEC9 MUX", "DMIC5", "DMIC5"},
4150 {"DEC9 MUX", "ADC2", "ADC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004151 {"DEC9 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004152 {"DEC9 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004153 {"DEC10 MUX", "DMIC3", "DMIC3"},
4154 {"DEC10 MUX", "DMIC6", "DMIC6"},
4155 {"DEC10 MUX", "ADC1", "ADC1"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004156 {"DEC10 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07004157 {"DEC10 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004158
4159 /* ADC Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004160 {"ADC1", NULL, "AMIC1"},
4161 {"ADC2", NULL, "AMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07004162 {"ADC3", NULL, "AMIC3"},
4163 {"ADC4", NULL, "AMIC4"},
4164 {"ADC5", NULL, "AMIC5"},
4165 {"ADC6", NULL, "AMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004166
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08004167 /* AUX PGA Connections */
4168 {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4169 {"HPHL_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4170 {"HPHL_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4171 {"HPHL_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4172 {"HPHR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4173 {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4174 {"HPHR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4175 {"HPHR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4176 {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4177 {"LINEOUT1_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4178 {"LINEOUT1_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4179 {"LINEOUT1_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4180 {"LINEOUT2_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4181 {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4182 {"LINEOUT2_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4183 {"LINEOUT2_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4184 {"LINEOUT3_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4185 {"LINEOUT3_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4186 {"LINEOUT3_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4187 {"LINEOUT3_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4188 {"LINEOUT4_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4189 {"LINEOUT4_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4190 {"LINEOUT4_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4191 {"LINEOUT4_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4192 {"LINEOUT5_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4193 {"LINEOUT5_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4194 {"LINEOUT5_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4195 {"LINEOUT5_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4196 {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
4197 {"EAR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
4198 {"EAR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
4199 {"EAR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
4200 {"AUX_PGA_Left", NULL, "AMIC5"},
4201 {"AUX_PGA_Right", NULL, "AMIC6"},
4202
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004203 {"IIR1", NULL, "IIR1 INP1 MUX"},
Patrick Lai16261e82011-09-30 13:25:52 -07004204 {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"},
4205 {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"},
4206 {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"},
4207 {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"},
4208 {"IIR1 INP1 MUX", "DEC5", "DEC5 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004209 {"IIR1 INP1 MUX", "DEC6", "DEC6 MUX"},
Patrick Lai16261e82011-09-30 13:25:52 -07004210 {"IIR1 INP1 MUX", "DEC7", "DEC7 MUX"},
4211 {"IIR1 INP1 MUX", "DEC8", "DEC8 MUX"},
4212 {"IIR1 INP1 MUX", "DEC9", "DEC9 MUX"},
4213 {"IIR1 INP1 MUX", "DEC10", "DEC10 MUX"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07004214
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07004215 {"IIR2", NULL, "IIR2 INP1 MUX"},
4216 {"IIR2 INP1 MUX", "DEC1", "DEC1 MUX"},
4217 {"IIR2 INP1 MUX", "DEC2", "DEC2 MUX"},
4218 {"IIR2 INP1 MUX", "DEC3", "DEC3 MUX"},
4219 {"IIR2 INP1 MUX", "DEC4", "DEC4 MUX"},
4220 {"IIR2 INP1 MUX", "DEC5", "DEC5 MUX"},
4221 {"IIR2 INP1 MUX", "DEC6", "DEC6 MUX"},
4222 {"IIR2 INP1 MUX", "DEC7", "DEC7 MUX"},
4223 {"IIR2 INP1 MUX", "DEC8", "DEC8 MUX"},
4224 {"IIR2 INP1 MUX", "DEC9", "DEC9 MUX"},
4225 {"IIR2 INP1 MUX", "DEC10", "DEC10 MUX"},
4226
Bradley Rubin229c6a52011-07-12 16:18:48 -07004227 {"MIC BIAS1 Internal1", NULL, "LDO_H"},
4228 {"MIC BIAS1 Internal2", NULL, "LDO_H"},
4229 {"MIC BIAS1 External", NULL, "LDO_H"},
4230 {"MIC BIAS2 Internal1", NULL, "LDO_H"},
4231 {"MIC BIAS2 Internal2", NULL, "LDO_H"},
4232 {"MIC BIAS2 Internal3", NULL, "LDO_H"},
4233 {"MIC BIAS2 External", NULL, "LDO_H"},
4234 {"MIC BIAS3 Internal1", NULL, "LDO_H"},
4235 {"MIC BIAS3 Internal2", NULL, "LDO_H"},
4236 {"MIC BIAS3 External", NULL, "LDO_H"},
4237 {"MIC BIAS4 External", NULL, "LDO_H"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004238};
4239
Kiran Kandi8b3a8302011-09-27 16:13:28 -07004240static const struct snd_soc_dapm_route tabla_1_x_lineout_2_to_4_map[] = {
4241
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004242 {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07004243 {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"},
4244
4245 {"LINEOUT2 DAC", NULL, "RX4 DSM MUX"},
4246
4247 {"LINEOUT3 DAC", NULL, "RX5 MIX1"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004248 {"LINEOUT3 DAC GROUND", "Switch", "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07004249 {"LINEOUT3 DAC", NULL, "LINEOUT3 DAC GROUND"},
4250
4251 {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"},
4252 {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"},
4253
4254 {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"},
4255 {"LINEOUT4 DAC GROUND", "Switch", "RX4 DSM MUX"},
4256 {"LINEOUT4 DAC", NULL, "LINEOUT4 DAC GROUND"},
4257};
4258
Kiran Kandi7a9fd902011-11-14 13:51:45 -08004259
4260static const struct snd_soc_dapm_route tabla_2_x_lineout_2_to_4_map[] = {
4261
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004262 {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"},
Kiran Kandi7a9fd902011-11-14 13:51:45 -08004263 {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"},
4264
4265 {"LINEOUT3 DAC", NULL, "RX4 DSM MUX"},
4266
4267 {"LINEOUT2 DAC", NULL, "RX5 MIX1"},
4268
4269 {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"},
4270 {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"},
4271
4272 {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"},
4273};
4274
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004275static int tabla_readable(struct snd_soc_codec *ssc, unsigned int reg)
4276{
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08004277 int i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304278 struct wcd9xxx *tabla_core = dev_get_drvdata(ssc->dev->parent);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08004279
4280 if (TABLA_IS_1_X(tabla_core->version)) {
4281 for (i = 0; i < ARRAY_SIZE(tabla_1_reg_readable); i++) {
4282 if (tabla_1_reg_readable[i] == reg)
4283 return 1;
4284 }
4285 } else {
4286 for (i = 0; i < ARRAY_SIZE(tabla_2_reg_readable); i++) {
4287 if (tabla_2_reg_readable[i] == reg)
4288 return 1;
4289 }
4290 }
4291
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004292 return tabla_reg_readable[reg];
4293}
Kuirong Wange9c8a222012-03-28 16:24:09 -07004294static bool tabla_is_digital_gain_register(unsigned int reg)
4295{
4296 bool rtn = false;
4297 switch (reg) {
4298 case TABLA_A_CDC_RX1_VOL_CTL_B2_CTL:
4299 case TABLA_A_CDC_RX2_VOL_CTL_B2_CTL:
4300 case TABLA_A_CDC_RX3_VOL_CTL_B2_CTL:
4301 case TABLA_A_CDC_RX4_VOL_CTL_B2_CTL:
4302 case TABLA_A_CDC_RX5_VOL_CTL_B2_CTL:
4303 case TABLA_A_CDC_RX6_VOL_CTL_B2_CTL:
4304 case TABLA_A_CDC_RX7_VOL_CTL_B2_CTL:
4305 case TABLA_A_CDC_TX1_VOL_CTL_GAIN:
4306 case TABLA_A_CDC_TX2_VOL_CTL_GAIN:
4307 case TABLA_A_CDC_TX3_VOL_CTL_GAIN:
4308 case TABLA_A_CDC_TX4_VOL_CTL_GAIN:
4309 case TABLA_A_CDC_TX5_VOL_CTL_GAIN:
4310 case TABLA_A_CDC_TX6_VOL_CTL_GAIN:
4311 case TABLA_A_CDC_TX7_VOL_CTL_GAIN:
4312 case TABLA_A_CDC_TX8_VOL_CTL_GAIN:
4313 case TABLA_A_CDC_TX9_VOL_CTL_GAIN:
4314 case TABLA_A_CDC_TX10_VOL_CTL_GAIN:
4315 rtn = true;
4316 break;
4317 default:
4318 break;
4319 }
4320 return rtn;
4321}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004322static int tabla_volatile(struct snd_soc_codec *ssc, unsigned int reg)
4323{
4324 /* Registers lower than 0x100 are top level registers which can be
4325 * written by the Tabla core driver.
4326 */
4327
4328 if ((reg >= TABLA_A_CDC_MBHC_EN_CTL) || (reg < 0x100))
4329 return 1;
4330
Ben Romberger1f045a72011-11-04 10:14:57 -07004331 /* IIR Coeff registers are not cacheable */
4332 if ((reg >= TABLA_A_CDC_IIR1_COEF_B1_CTL) &&
4333 (reg <= TABLA_A_CDC_IIR2_COEF_B5_CTL))
4334 return 1;
4335
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08004336 /* ANC filter registers are not cacheable */
4337 if ((reg >= TABLA_A_CDC_ANC1_FILT1_B1_CTL) &&
4338 (reg <= TABLA_A_CDC_ANC1_FILT2_B3_CTL))
4339 return 1;
4340 if ((reg >= TABLA_A_CDC_ANC2_FILT1_B1_CTL) &&
4341 (reg <= TABLA_A_CDC_ANC2_FILT2_B3_CTL))
4342 return 1;
4343
Kuirong Wange9c8a222012-03-28 16:24:09 -07004344 /* Digital gain register is not cacheable so we have to write
4345 * the setting even it is the same
4346 */
4347 if (tabla_is_digital_gain_register(reg))
4348 return 1;
4349
Joonwoo Parkab2c5872012-05-03 15:16:02 -07004350 /* HPH status registers */
4351 if (reg == TABLA_A_RX_HPH_L_STATUS || reg == TABLA_A_RX_HPH_R_STATUS)
4352 return 1;
4353
Kuirong Wang678e4172012-06-26 15:35:22 -07004354 if (reg == TABLA_A_CDC_COMP1_SHUT_DOWN_STATUS ||
4355 reg == TABLA_A_CDC_COMP2_SHUT_DOWN_STATUS)
4356 return 1;
4357
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004358 return 0;
4359}
4360
4361#define TABLA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
4362static int tabla_write(struct snd_soc_codec *codec, unsigned int reg,
4363 unsigned int value)
4364{
4365 int ret;
Kuirong Wang906ac472012-07-09 12:54:44 -07004366
4367 if (reg == SND_SOC_NOPM)
4368 return 0;
4369
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004370 BUG_ON(reg > TABLA_MAX_REGISTER);
4371
4372 if (!tabla_volatile(codec, reg)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004373 ret = snd_soc_cache_write(codec, reg, value);
4374 if (ret != 0)
4375 dev_err(codec->dev, "Cache write to %x failed: %d\n",
4376 reg, ret);
4377 }
4378
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304379 return wcd9xxx_reg_write(codec->control_data, reg, value);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004380}
4381static unsigned int tabla_read(struct snd_soc_codec *codec,
4382 unsigned int reg)
4383{
4384 unsigned int val;
4385 int ret;
4386
Kuirong Wang906ac472012-07-09 12:54:44 -07004387 if (reg == SND_SOC_NOPM)
4388 return 0;
4389
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004390 BUG_ON(reg > TABLA_MAX_REGISTER);
4391
4392 if (!tabla_volatile(codec, reg) && tabla_readable(codec, reg) &&
4393 reg < codec->driver->reg_cache_size) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004394 ret = snd_soc_cache_read(codec, reg, &val);
4395 if (ret >= 0) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004396 return val;
4397 } else
4398 dev_err(codec->dev, "Cache read from %x failed: %d\n",
4399 reg, ret);
4400 }
4401
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304402 val = wcd9xxx_reg_read(codec->control_data, reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004403 return val;
4404}
4405
Joonwoo Parkcf473b42012-03-29 19:48:16 -07004406static s16 tabla_get_current_v_ins(struct tabla_priv *tabla, bool hu)
4407{
4408 s16 v_ins;
4409 if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) &&
4410 tabla->mbhc_micbias_switched)
4411 v_ins = hu ? (s16)tabla->mbhc_data.adj_v_ins_hu :
4412 (s16)tabla->mbhc_data.adj_v_ins_h;
4413 else
4414 v_ins = hu ? (s16)tabla->mbhc_data.v_ins_hu :
4415 (s16)tabla->mbhc_data.v_ins_h;
4416 return v_ins;
4417}
4418
4419static s16 tabla_get_current_v_hs_max(struct tabla_priv *tabla)
4420{
4421 s16 v_hs_max;
4422 struct tabla_mbhc_plug_type_cfg *plug_type;
4423
4424 plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
4425 if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) &&
4426 tabla->mbhc_micbias_switched)
4427 v_hs_max = tabla->mbhc_data.adj_v_hs_max;
4428 else
4429 v_hs_max = plug_type->v_hs_max;
4430 return v_hs_max;
4431}
4432
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07004433static void tabla_codec_calibrate_rel(struct snd_soc_codec *codec)
Bradley Rubincb1e2732011-06-23 16:49:20 -07004434{
Joonwoo Park0976d012011-12-22 11:48:18 -08004435 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004436
Joonwoo Park0976d012011-12-22 11:48:18 -08004437 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL,
4438 tabla->mbhc_data.v_b1_hu & 0xFF);
4439 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL,
4440 (tabla->mbhc_data.v_b1_hu >> 8) & 0xFF);
4441
4442 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL,
4443 tabla->mbhc_data.v_b1_h & 0xFF);
4444 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL,
4445 (tabla->mbhc_data.v_b1_h >> 8) & 0xFF);
4446
4447 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B9_CTL,
4448 tabla->mbhc_data.v_brh & 0xFF);
4449 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B10_CTL,
4450 (tabla->mbhc_data.v_brh >> 8) & 0xFF);
4451
4452 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B11_CTL,
4453 tabla->mbhc_data.v_brl & 0xFF);
4454 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B12_CTL,
4455 (tabla->mbhc_data.v_brl >> 8) & 0xFF);
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07004456}
4457
4458static void tabla_codec_calibrate_hs_polling(struct snd_soc_codec *codec)
4459{
4460 u8 *n_ready, *n_cic;
4461 struct tabla_mbhc_btn_detect_cfg *btn_det;
4462 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
4463 const s16 v_ins_hu = tabla_get_current_v_ins(tabla, true);
4464
4465 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
4466
4467 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
4468 v_ins_hu & 0xFF);
4469 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
4470 (v_ins_hu >> 8) & 0xFF);
4471
4472 tabla_codec_calibrate_rel(codec);
Joonwoo Park0976d012011-12-22 11:48:18 -08004473
Joonwoo Parkc0672392012-01-11 11:03:14 -08004474 n_ready = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_READY);
Joonwoo Park0976d012011-12-22 11:48:18 -08004475 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL,
Joonwoo Parkc0672392012-01-11 11:03:14 -08004476 n_ready[tabla_codec_mclk_index(tabla)]);
Joonwoo Park0976d012011-12-22 11:48:18 -08004477 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B2_CTL,
4478 tabla->mbhc_data.npoll);
4479 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B3_CTL,
4480 tabla->mbhc_data.nbounce_wait);
Joonwoo Park0976d012011-12-22 11:48:18 -08004481 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
Joonwoo Park107edf02012-01-11 11:42:24 -08004482 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL,
4483 n_cic[tabla_codec_mclk_index(tabla)]);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004484}
4485
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004486static int tabla_startup(struct snd_pcm_substream *substream,
4487 struct snd_soc_dai *dai)
4488{
Kuirong Wanga545e722012-02-06 19:12:54 -08004489 struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004490 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
4491 substream->name, substream->stream);
Kuirong Wanga545e722012-02-06 19:12:54 -08004492 if ((tabla_core != NULL) &&
4493 (tabla_core->dev != NULL) &&
4494 (tabla_core->dev->parent != NULL))
4495 pm_runtime_get_sync(tabla_core->dev->parent);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004496
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004497 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004498}
4499
Swaminathan Sathappanf95ece62012-08-23 16:01:50 -07004500static void tabla_shutdown(struct snd_pcm_substream *substream,
4501 struct snd_soc_dai *dai)
4502{
4503 struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent);
4504 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
4505 u32 active = 0;
4506
4507 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
4508 substream->name, substream->stream);
4509 if (tabla->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
4510 return;
4511
4512 if (dai->id <= NUM_CODEC_DAIS) {
Kuirong Wang906ac472012-07-09 12:54:44 -07004513 if (tabla->dai[dai->id].ch_mask) {
Swaminathan Sathappanf95ece62012-08-23 16:01:50 -07004514 active = 1;
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08004515 pr_debug("%s(): Codec DAI: chmask[%d] = 0x%lx\n",
Kuirong Wang906ac472012-07-09 12:54:44 -07004516 __func__, dai->id, tabla->dai[dai->id].ch_mask);
Swaminathan Sathappanf95ece62012-08-23 16:01:50 -07004517 }
4518 }
4519
4520 if ((tabla_core != NULL) &&
4521 (tabla_core->dev != NULL) &&
4522 (tabla_core->dev->parent != NULL) &&
4523 (active == 0)) {
4524 pm_runtime_mark_last_busy(tabla_core->dev->parent);
4525 pm_runtime_put(tabla_core->dev->parent);
4526 }
4527}
4528
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004529int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, bool dapm)
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004530{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004531 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
4532
Joonwoo Parkcf473b42012-03-29 19:48:16 -07004533 pr_debug("%s: mclk_enable = %u, dapm = %d\n", __func__, mclk_enable,
4534 dapm);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004535 if (dapm)
4536 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004537 if (mclk_enable) {
4538 tabla->mclk_enabled = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004539
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004540 if (tabla->mbhc_polling_active) {
Bradley Rubincb1e2732011-06-23 16:49:20 -07004541 tabla_codec_pause_hs_polling(codec);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004542 tabla_codec_disable_clock_block(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004543 tabla_codec_enable_bandgap(codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004544 TABLA_BANDGAP_AUDIO_MODE);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004545 tabla_codec_enable_clock_block(codec, 0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004546 tabla_codec_calibrate_hs_polling(codec);
4547 tabla_codec_start_hs_polling(codec);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05304548 } else {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004549 tabla_codec_disable_clock_block(codec);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05304550 tabla_codec_enable_bandgap(codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004551 TABLA_BANDGAP_AUDIO_MODE);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05304552 tabla_codec_enable_clock_block(codec, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004553 }
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004554 } else {
4555
4556 if (!tabla->mclk_enabled) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004557 if (dapm)
4558 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004559 pr_err("Error, MCLK already diabled\n");
4560 return -EINVAL;
4561 }
4562 tabla->mclk_enabled = false;
4563
4564 if (tabla->mbhc_polling_active) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004565 tabla_codec_pause_hs_polling(codec);
4566 tabla_codec_disable_clock_block(codec);
4567 tabla_codec_enable_bandgap(codec,
Simmi Pateriya71d63872012-11-08 01:06:30 +05304568 TABLA_BANDGAP_MBHC_MODE);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004569 tabla_enable_rx_bias(codec, 1);
4570 tabla_codec_enable_clock_block(codec, 1);
4571 tabla_codec_calibrate_hs_polling(codec);
4572 tabla_codec_start_hs_polling(codec);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004573 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1,
4574 0x05, 0x01);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05304575 } else {
4576 tabla_codec_disable_clock_block(codec);
4577 tabla_codec_enable_bandgap(codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004578 TABLA_BANDGAP_OFF);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004579 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004580 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004581 if (dapm)
4582 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004583 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004584}
4585
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004586static int tabla_set_dai_sysclk(struct snd_soc_dai *dai,
4587 int clk_id, unsigned int freq, int dir)
4588{
4589 pr_debug("%s\n", __func__);
4590 return 0;
4591}
4592
4593static int tabla_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
4594{
Santosh Mardie15e2302011-11-15 10:39:23 +05304595 u8 val = 0;
4596 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
4597
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004598 pr_debug("%s\n", __func__);
Santosh Mardie15e2302011-11-15 10:39:23 +05304599 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
4600 case SND_SOC_DAIFMT_CBS_CFS:
4601 /* CPU is master */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304602 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004603 if (dai->id == AIF1_CAP)
Santosh Mardie15e2302011-11-15 10:39:23 +05304604 snd_soc_update_bits(dai->codec,
4605 TABLA_A_CDC_CLK_TX_I2S_CTL,
4606 TABLA_I2S_MASTER_MODE_MASK, 0);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004607 else if (dai->id == AIF1_PB)
Santosh Mardie15e2302011-11-15 10:39:23 +05304608 snd_soc_update_bits(dai->codec,
4609 TABLA_A_CDC_CLK_RX_I2S_CTL,
4610 TABLA_I2S_MASTER_MODE_MASK, 0);
4611 }
4612 break;
4613 case SND_SOC_DAIFMT_CBM_CFM:
4614 /* CPU is slave */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304615 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05304616 val = TABLA_I2S_MASTER_MODE_MASK;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004617 if (dai->id == AIF1_CAP)
Santosh Mardie15e2302011-11-15 10:39:23 +05304618 snd_soc_update_bits(dai->codec,
4619 TABLA_A_CDC_CLK_TX_I2S_CTL, val, val);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004620 else if (dai->id == AIF1_PB)
Santosh Mardie15e2302011-11-15 10:39:23 +05304621 snd_soc_update_bits(dai->codec,
4622 TABLA_A_CDC_CLK_RX_I2S_CTL, val, val);
4623 }
4624 break;
4625 default:
4626 return -EINVAL;
4627 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004628 return 0;
4629}
4630
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004631static int tabla_set_channel_map(struct snd_soc_dai *dai,
4632 unsigned int tx_num, unsigned int *tx_slot,
4633 unsigned int rx_num, unsigned int *rx_slot)
4634
4635{
4636 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
Kuirong Wang906ac472012-07-09 12:54:44 -07004637 struct wcd9xxx *core = dev_get_drvdata(dai->codec->dev->parent);
4638
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004639 if (!tx_slot && !rx_slot) {
4640 pr_err("%s: Invalid\n", __func__);
4641 return -EINVAL;
4642 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004643 pr_debug("%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n"
4644 "tabla->intf_type %d\n",
4645 __func__, dai->name, dai->id, tx_num, rx_num,
4646 tabla->intf_type);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004647
Kuirong Wang906ac472012-07-09 12:54:44 -07004648 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
4649 wcd9xxx_init_slimslave(core, core->slim->laddr,
4650 tx_num, tx_slot, rx_num, rx_slot);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004651 return 0;
4652}
4653
4654static int tabla_get_channel_map(struct snd_soc_dai *dai,
4655 unsigned int *tx_num, unsigned int *tx_slot,
4656 unsigned int *rx_num, unsigned int *rx_slot)
4657
4658{
Kuirong Wang906ac472012-07-09 12:54:44 -07004659 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(dai->codec);
4660 u32 i = 0;
4661 struct wcd9xxx_ch *ch;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004662
Kuirong Wang906ac472012-07-09 12:54:44 -07004663 switch (dai->id) {
4664 case AIF1_PB:
4665 case AIF2_PB:
4666 case AIF3_PB:
4667 if (!rx_slot || !rx_num) {
4668 pr_err("%s: Invalid rx_slot %d or rx_num %d\n",
4669 __func__, (u32) rx_slot, (u32) rx_num);
4670 return -EINVAL;
4671 }
4672 list_for_each_entry(ch, &tabla_p->dai[dai->id].wcd9xxx_ch_list,
4673 list) {
4674 rx_slot[i++] = ch->ch_num;
4675 }
4676 *rx_num = i;
4677 break;
4678 case AIF1_CAP:
4679 case AIF2_CAP:
4680 case AIF3_CAP:
4681 if (!tx_slot || !tx_num) {
4682 pr_err("%s: Invalid tx_slot %d or tx_num %d\n",
4683 __func__, (u32) tx_slot, (u32) tx_num);
4684 return -EINVAL;
4685 }
4686 list_for_each_entry(ch, &tabla_p->dai[dai->id].wcd9xxx_ch_list,
4687 list) {
4688 tx_slot[i++] = ch->ch_num;
4689 }
4690 *tx_num = i;
4691 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004692
Kuirong Wang906ac472012-07-09 12:54:44 -07004693 default:
4694 pr_err("%s: Invalid DAI ID %x\n", __func__, dai->id);
4695 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004696 }
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004697 return 0;
4698}
4699
Kiran Kandi93923902012-06-20 17:00:25 -07004700
Kiran Kandi93923902012-06-20 17:00:25 -07004701static int tabla_set_interpolator_rate(struct snd_soc_dai *dai,
Kuirong Wang906ac472012-07-09 12:54:44 -07004702 u8 rx_fs_rate_reg_val,
4703 u32 compander_fs,
4704 u32 sample_rate)
Kiran Kandi93923902012-06-20 17:00:25 -07004705{
Kuirong Wang906ac472012-07-09 12:54:44 -07004706 u32 j;
Kiran Kandi93923902012-06-20 17:00:25 -07004707 u8 rx_mix1_inp;
4708 u16 rx_mix_1_reg_1, rx_mix_1_reg_2;
4709 u16 rx_fs_reg;
4710 u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val;
4711 struct snd_soc_codec *codec = dai->codec;
Kuirong Wang906ac472012-07-09 12:54:44 -07004712 struct wcd9xxx_ch *ch;
Kiran Kandi93923902012-06-20 17:00:25 -07004713 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Kiran Kandi93923902012-06-20 17:00:25 -07004714
Kuirong Wang906ac472012-07-09 12:54:44 -07004715 list_for_each_entry(ch, &tabla->dai[dai->id].wcd9xxx_ch_list, list) {
Kiran Kandi93923902012-06-20 17:00:25 -07004716
Kuirong Wang906ac472012-07-09 12:54:44 -07004717 rx_mix1_inp = ch->port - RX_MIX1_INP_SEL_RX1;
Kiran Kandi93923902012-06-20 17:00:25 -07004718
Kuirong Wang906ac472012-07-09 12:54:44 -07004719 if ((rx_mix1_inp < RX_MIX1_INP_SEL_RX1) ||
4720 (rx_mix1_inp > RX_MIX1_INP_SEL_RX7)) {
4721 pr_err("%s: Invalid TABLA_RX%u port. Dai ID is %d\n",
4722 __func__, rx_mix1_inp - 5 , dai->id);
Kiran Kandi93923902012-06-20 17:00:25 -07004723 return -EINVAL;
4724 }
4725
4726 rx_mix_1_reg_1 = TABLA_A_CDC_CONN_RX1_B1_CTL;
4727
4728 for (j = 0; j < NUM_INTERPOLATORS; j++) {
Kiran Kandi93923902012-06-20 17:00:25 -07004729 rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1;
4730
4731 rx_mix_1_reg_1_val = snd_soc_read(codec,
Kuirong Wang906ac472012-07-09 12:54:44 -07004732 rx_mix_1_reg_1);
Kiran Kandi93923902012-06-20 17:00:25 -07004733 rx_mix_1_reg_2_val = snd_soc_read(codec,
Kuirong Wang906ac472012-07-09 12:54:44 -07004734 rx_mix_1_reg_2);
Kiran Kandi93923902012-06-20 17:00:25 -07004735
4736 if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) ||
Kuirong Wang906ac472012-07-09 12:54:44 -07004737 (((rx_mix_1_reg_1_val >> 4) & 0x0F) == rx_mix1_inp) ||
4738 ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) {
Kiran Kandi93923902012-06-20 17:00:25 -07004739
4740 rx_fs_reg = TABLA_A_CDC_RX1_B5_CTL + 8 * j;
4741
Kuirong Wang906ac472012-07-09 12:54:44 -07004742 pr_debug("%s: AIF_PB DAI(%d) connected to RX%u\n",
4743 __func__, dai->id, j + 1);
Kiran Kandi93923902012-06-20 17:00:25 -07004744
4745 pr_debug("%s: set RX%u sample rate to %u\n",
4746 __func__, j + 1, sample_rate);
4747
4748 snd_soc_update_bits(codec, rx_fs_reg,
Kuirong Wang906ac472012-07-09 12:54:44 -07004749 0xE0, rx_fs_rate_reg_val);
Kiran Kandi93923902012-06-20 17:00:25 -07004750
4751 if (comp_rx_path[j] < COMPANDER_MAX)
4752 tabla->comp_fs[comp_rx_path[j]]
4753 = compander_fs;
4754 }
4755 if (j <= 2)
4756 rx_mix_1_reg_1 += 3;
4757 else
4758 rx_mix_1_reg_1 += 2;
4759 }
4760 }
4761 return 0;
4762}
4763
4764static int tabla_set_decimator_rate(struct snd_soc_dai *dai,
Kuirong Wang906ac472012-07-09 12:54:44 -07004765 u8 tx_fs_rate_reg_val,
4766 u32 sample_rate)
Kiran Kandi93923902012-06-20 17:00:25 -07004767{
4768 struct snd_soc_codec *codec = dai->codec;
Kuirong Wang906ac472012-07-09 12:54:44 -07004769 struct wcd9xxx_ch *ch;
4770 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
4771 u32 tx_port;
Kiran Kandi93923902012-06-20 17:00:25 -07004772 u16 tx_port_reg, tx_fs_reg;
4773 u8 tx_port_reg_val;
4774 s8 decimator;
4775
Kuirong Wang906ac472012-07-09 12:54:44 -07004776 list_for_each_entry(ch, &tabla->dai[dai->id].wcd9xxx_ch_list, list) {
Kiran Kandi93923902012-06-20 17:00:25 -07004777
Kuirong Wang906ac472012-07-09 12:54:44 -07004778 tx_port = ch->port + 1;
4779 pr_debug("%s: dai->id = %d, tx_port = %d",
4780 __func__, dai->id, tx_port);
Kiran Kandi93923902012-06-20 17:00:25 -07004781
4782 if ((tx_port < 1) || (tx_port > NUM_DECIMATORS)) {
Kuirong Wang906ac472012-07-09 12:54:44 -07004783 pr_err("%s: Invalid SLIM TX%u port. DAI ID is %d\n",
4784 __func__, tx_port, dai->id);
Kiran Kandi93923902012-06-20 17:00:25 -07004785 return -EINVAL;
4786 }
4787
4788 tx_port_reg = TABLA_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1);
4789 tx_port_reg_val = snd_soc_read(codec, tx_port_reg);
4790
4791 decimator = 0;
4792
4793 if ((tx_port >= 1) && (tx_port <= 6)) {
4794
4795 tx_port_reg_val = tx_port_reg_val & 0x0F;
4796 if (tx_port_reg_val == 0x8)
4797 decimator = tx_port;
4798
4799 } else if ((tx_port >= 7) && (tx_port <= NUM_DECIMATORS)) {
4800
4801 tx_port_reg_val = tx_port_reg_val & 0x1F;
4802
4803 if ((tx_port_reg_val >= 0x8) &&
4804 (tx_port_reg_val <= 0x11)) {
4805
4806 decimator = (tx_port_reg_val - 0x8) + 1;
4807 }
4808 }
4809
4810 if (decimator) { /* SLIM_TX port has a DEC as input */
4811
4812 tx_fs_reg = TABLA_A_CDC_TX1_CLK_FS_CTL +
Kuirong Wang906ac472012-07-09 12:54:44 -07004813 8 * (decimator - 1);
Kiran Kandi93923902012-06-20 17:00:25 -07004814
4815 pr_debug("%s: set DEC%u (-> SLIM_TX%u) rate to %u\n",
4816 __func__, decimator, tx_port, sample_rate);
4817
4818 snd_soc_update_bits(codec, tx_fs_reg, 0x07,
Kuirong Wang906ac472012-07-09 12:54:44 -07004819 tx_fs_rate_reg_val);
Kiran Kandi93923902012-06-20 17:00:25 -07004820
4821 } else {
4822 if ((tx_port_reg_val >= 0x1) &&
Kuirong Wang906ac472012-07-09 12:54:44 -07004823 (tx_port_reg_val <= 0x7)) {
Kiran Kandi93923902012-06-20 17:00:25 -07004824
4825 pr_debug("%s: RMIX%u going to SLIM TX%u\n",
4826 __func__, tx_port_reg_val, tx_port);
4827
4828 } else if ((tx_port_reg_val >= 0x8) &&
Kuirong Wang906ac472012-07-09 12:54:44 -07004829 (tx_port_reg_val <= 0x11)) {
Kiran Kandi93923902012-06-20 17:00:25 -07004830
4831 pr_err("%s: ERROR: Should not be here\n",
Kuirong Wang906ac472012-07-09 12:54:44 -07004832 __func__);
4833 pr_err("%s: ERROR: DEC connected to SLIM TX%u\n",
4834 __func__, tx_port);
Kiran Kandi93923902012-06-20 17:00:25 -07004835 return -EINVAL;
4836
4837 } else if (tx_port_reg_val == 0) {
4838 pr_debug("%s: no signal to SLIM TX%u\n",
Kuirong Wang906ac472012-07-09 12:54:44 -07004839 __func__, tx_port);
Kiran Kandi93923902012-06-20 17:00:25 -07004840 } else {
Kuirong Wang906ac472012-07-09 12:54:44 -07004841 pr_err("%s: ERROR: wrong signal to SLIM TX%u\n",
4842 __func__, tx_port);
4843 pr_err("%s: ERROR: wrong signal = %u\n",
4844 __func__, tx_port_reg_val);
Kiran Kandi93923902012-06-20 17:00:25 -07004845 return -EINVAL;
4846 }
4847 }
4848 }
4849 return 0;
4850}
4851
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004852static int tabla_hw_params(struct snd_pcm_substream *substream,
Kuirong Wang906ac472012-07-09 12:54:44 -07004853 struct snd_pcm_hw_params *params,
4854 struct snd_soc_dai *dai)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004855{
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004856 struct snd_soc_codec *codec = dai->codec;
Santosh Mardie15e2302011-11-15 10:39:23 +05304857 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
Kiran Kandi93923902012-06-20 17:00:25 -07004858 u8 tx_fs_rate_reg_val, rx_fs_rate_reg_val;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004859 u32 compander_fs;
Kiran Kandi93923902012-06-20 17:00:25 -07004860 int ret;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004861
Kiran Kandia9fffe92012-05-20 23:42:30 -07004862 pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004863 dai->name, dai->id, params_rate(params),
4864 params_channels(params));
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004865
4866 switch (params_rate(params)) {
4867 case 8000:
Kiran Kandi93923902012-06-20 17:00:25 -07004868 tx_fs_rate_reg_val = 0x00;
4869 rx_fs_rate_reg_val = 0x00;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004870 compander_fs = COMPANDER_FS_8KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004871 break;
4872 case 16000:
Kiran Kandi93923902012-06-20 17:00:25 -07004873 tx_fs_rate_reg_val = 0x01;
4874 rx_fs_rate_reg_val = 0x20;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004875 compander_fs = COMPANDER_FS_16KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004876 break;
4877 case 32000:
Kiran Kandi93923902012-06-20 17:00:25 -07004878 tx_fs_rate_reg_val = 0x02;
4879 rx_fs_rate_reg_val = 0x40;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004880 compander_fs = COMPANDER_FS_32KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004881 break;
4882 case 48000:
Kiran Kandi93923902012-06-20 17:00:25 -07004883 tx_fs_rate_reg_val = 0x03;
4884 rx_fs_rate_reg_val = 0x60;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004885 compander_fs = COMPANDER_FS_48KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004886 break;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004887 case 96000:
Kiran Kandi93923902012-06-20 17:00:25 -07004888 tx_fs_rate_reg_val = 0x04;
4889 rx_fs_rate_reg_val = 0x80;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004890 compander_fs = COMPANDER_FS_96KHZ;
4891 break;
4892 case 192000:
Kiran Kandi93923902012-06-20 17:00:25 -07004893 tx_fs_rate_reg_val = 0x05;
4894 rx_fs_rate_reg_val = 0xA0;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004895 compander_fs = COMPANDER_FS_192KHZ;
4896 break;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004897 default:
4898 pr_err("%s: Invalid sampling rate %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004899 params_rate(params));
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004900 return -EINVAL;
4901 }
4902
Kiran Kandi93923902012-06-20 17:00:25 -07004903 switch (substream->stream) {
4904 case SNDRV_PCM_STREAM_CAPTURE:
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004905
Kiran Kandi93923902012-06-20 17:00:25 -07004906 ret = tabla_set_decimator_rate(dai, tx_fs_rate_reg_val,
Kuirong Wang906ac472012-07-09 12:54:44 -07004907 params_rate(params));
Kiran Kandi93923902012-06-20 17:00:25 -07004908 if (ret < 0) {
4909 pr_err("%s: set decimator rate failed %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004910 ret);
Kiran Kandi93923902012-06-20 17:00:25 -07004911 return ret;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004912 }
Kiran Kandi93923902012-06-20 17:00:25 -07004913
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304914 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05304915 switch (params_format(params)) {
4916 case SNDRV_PCM_FORMAT_S16_LE:
4917 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004918 TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x20);
Santosh Mardie15e2302011-11-15 10:39:23 +05304919 break;
4920 case SNDRV_PCM_FORMAT_S32_LE:
4921 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004922 TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x00);
Santosh Mardie15e2302011-11-15 10:39:23 +05304923 break;
4924 default:
Kuirong Wang906ac472012-07-09 12:54:44 -07004925 pr_err("%s: Invalid format %d\n", __func__,
4926 params_format(params));
Kiran Kandi93923902012-06-20 17:00:25 -07004927 return -EINVAL;
Santosh Mardie15e2302011-11-15 10:39:23 +05304928 }
4929 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_TX_I2S_CTL,
Kuirong Wang906ac472012-07-09 12:54:44 -07004930 0x07, tx_fs_rate_reg_val);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004931 } else {
Kuirong Wang906ac472012-07-09 12:54:44 -07004932 switch (params_format(params)) {
4933 case SNDRV_PCM_FORMAT_S16_LE:
4934 tabla->dai[dai->id].bit_width = 16;
4935 break;
4936 default:
4937 pr_err("%s: Invalid TX format %d\n", __func__,
4938 params_format(params));
4939 return -EINVAL;
4940 }
4941 tabla->dai[dai->id].rate = params_rate(params);
Santosh Mardie15e2302011-11-15 10:39:23 +05304942 }
Kiran Kandi93923902012-06-20 17:00:25 -07004943 break;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004944
Kiran Kandi93923902012-06-20 17:00:25 -07004945 case SNDRV_PCM_STREAM_PLAYBACK:
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004946
Kiran Kandi93923902012-06-20 17:00:25 -07004947 ret = tabla_set_interpolator_rate(dai, rx_fs_rate_reg_val,
Kuirong Wang906ac472012-07-09 12:54:44 -07004948 compander_fs,
4949 params_rate(params));
Kiran Kandi93923902012-06-20 17:00:25 -07004950 if (ret < 0) {
4951 pr_err("%s: set decimator rate failed %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004952 ret);
Kiran Kandi93923902012-06-20 17:00:25 -07004953 return ret;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004954 }
Kiran Kandi93923902012-06-20 17:00:25 -07004955
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304956 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05304957 switch (params_format(params)) {
4958 case SNDRV_PCM_FORMAT_S16_LE:
4959 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004960 TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x20);
Santosh Mardie15e2302011-11-15 10:39:23 +05304961 break;
4962 case SNDRV_PCM_FORMAT_S32_LE:
4963 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004964 TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x00);
Santosh Mardie15e2302011-11-15 10:39:23 +05304965 break;
4966 default:
Kuirong Wang906ac472012-07-09 12:54:44 -07004967 pr_err("%s: Invalid RX format %d\n", __func__,
4968 params_format(params));
Kiran Kandi93923902012-06-20 17:00:25 -07004969 return -EINVAL;
Santosh Mardie15e2302011-11-15 10:39:23 +05304970 }
4971 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_I2S_CTL,
Kiran Kandi93923902012-06-20 17:00:25 -07004972 0x03, (rx_fs_rate_reg_val >> 0x05));
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004973 } else {
Kuirong Wang906ac472012-07-09 12:54:44 -07004974 switch (params_format(params)) {
4975 case SNDRV_PCM_FORMAT_S16_LE:
4976 tabla->dai[dai->id].bit_width = 16;
4977 break;
4978 default:
4979 pr_err("%s: Invalid format %d\n", __func__,
4980 params_format(params));
4981 return -EINVAL;
4982 }
4983 tabla->dai[dai->id].rate = params_rate(params);
Santosh Mardie15e2302011-11-15 10:39:23 +05304984 }
Kiran Kandi93923902012-06-20 17:00:25 -07004985 break;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004986
Kiran Kandi93923902012-06-20 17:00:25 -07004987 default:
4988 pr_err("%s: Invalid stream type %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004989 substream->stream);
Kiran Kandi93923902012-06-20 17:00:25 -07004990 return -EINVAL;
4991 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004992 return 0;
4993}
4994
4995static struct snd_soc_dai_ops tabla_dai_ops = {
4996 .startup = tabla_startup,
Swaminathan Sathappanf95ece62012-08-23 16:01:50 -07004997 .shutdown = tabla_shutdown,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004998 .hw_params = tabla_hw_params,
4999 .set_sysclk = tabla_set_dai_sysclk,
5000 .set_fmt = tabla_set_dai_fmt,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005001 .set_channel_map = tabla_set_channel_map,
5002 .get_channel_map = tabla_get_channel_map,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005003};
5004
5005static struct snd_soc_dai_driver tabla_dai[] = {
5006 {
5007 .name = "tabla_rx1",
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005008 .id = AIF1_PB,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005009 .playback = {
5010 .stream_name = "AIF1 Playback",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07005011 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005012 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005013 .rate_max = 192000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005014 .rate_min = 8000,
5015 .channels_min = 1,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005016 .channels_max = 2,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005017 },
5018 .ops = &tabla_dai_ops,
5019 },
5020 {
5021 .name = "tabla_tx1",
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005022 .id = AIF1_CAP,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005023 .capture = {
5024 .stream_name = "AIF1 Capture",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07005025 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005026 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005027 .rate_max = 192000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005028 .rate_min = 8000,
5029 .channels_min = 1,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005030 .channels_max = 4,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005031 },
5032 .ops = &tabla_dai_ops,
5033 },
Neema Shettyd3a89262012-02-16 10:23:50 -08005034 {
5035 .name = "tabla_rx2",
5036 .id = AIF2_PB,
5037 .playback = {
5038 .stream_name = "AIF2 Playback",
5039 .rates = WCD9310_RATES,
5040 .formats = TABLA_FORMATS,
5041 .rate_min = 8000,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005042 .rate_max = 192000,
Neema Shettyd3a89262012-02-16 10:23:50 -08005043 .channels_min = 1,
5044 .channels_max = 2,
5045 },
5046 .ops = &tabla_dai_ops,
5047 },
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005048 {
5049 .name = "tabla_tx2",
5050 .id = AIF2_CAP,
5051 .capture = {
5052 .stream_name = "AIF2 Capture",
5053 .rates = WCD9310_RATES,
5054 .formats = TABLA_FORMATS,
5055 .rate_max = 192000,
5056 .rate_min = 8000,
5057 .channels_min = 1,
5058 .channels_max = 4,
5059 },
5060 .ops = &tabla_dai_ops,
5061 },
Neema Shetty3fb1b802012-04-27 13:53:24 -07005062 {
5063 .name = "tabla_tx3",
5064 .id = AIF3_CAP,
5065 .capture = {
5066 .stream_name = "AIF3 Capture",
5067 .rates = WCD9310_RATES,
5068 .formats = TABLA_FORMATS,
5069 .rate_max = 48000,
5070 .rate_min = 8000,
5071 .channels_min = 1,
5072 .channels_max = 2,
5073 },
5074 .ops = &tabla_dai_ops,
5075 },
Kiran Kandia9fffe92012-05-20 23:42:30 -07005076 {
5077 .name = "tabla_rx3",
5078 .id = AIF3_PB,
5079 .playback = {
5080 .stream_name = "AIF3 Playback",
5081 .rates = WCD9310_RATES,
5082 .formats = TABLA_FORMATS,
5083 .rate_min = 8000,
5084 .rate_max = 192000,
5085 .channels_min = 1,
5086 .channels_max = 2,
5087 },
5088 .ops = &tabla_dai_ops,
5089 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005090};
Santosh Mardie15e2302011-11-15 10:39:23 +05305091
5092static struct snd_soc_dai_driver tabla_i2s_dai[] = {
5093 {
5094 .name = "tabla_i2s_rx1",
Kuirong Wang906ac472012-07-09 12:54:44 -07005095 .id = AIF1_PB,
Santosh Mardie15e2302011-11-15 10:39:23 +05305096 .playback = {
5097 .stream_name = "AIF1 Playback",
5098 .rates = WCD9310_RATES,
5099 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005100 .rate_max = 192000,
Santosh Mardie15e2302011-11-15 10:39:23 +05305101 .rate_min = 8000,
5102 .channels_min = 1,
5103 .channels_max = 4,
5104 },
5105 .ops = &tabla_dai_ops,
5106 },
5107 {
5108 .name = "tabla_i2s_tx1",
Kuirong Wang906ac472012-07-09 12:54:44 -07005109 .id = AIF1_CAP,
Santosh Mardie15e2302011-11-15 10:39:23 +05305110 .capture = {
5111 .stream_name = "AIF1 Capture",
5112 .rates = WCD9310_RATES,
5113 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005114 .rate_max = 192000,
Santosh Mardie15e2302011-11-15 10:39:23 +05305115 .rate_min = 8000,
5116 .channels_min = 1,
5117 .channels_max = 4,
5118 },
5119 .ops = &tabla_dai_ops,
5120 },
5121};
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005122
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07005123static int tabla_codec_enable_chmask(struct tabla_priv *tabla_p,
Kuirong Wang906ac472012-07-09 12:54:44 -07005124 int event, int index)
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07005125{
5126 int ret = 0;
Kuirong Wang906ac472012-07-09 12:54:44 -07005127 struct wcd9xxx_ch *ch;
5128
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07005129 switch (event) {
5130 case SND_SOC_DAPM_POST_PMU:
Kuirong Wang906ac472012-07-09 12:54:44 -07005131 list_for_each_entry(ch,
5132 &tabla_p->dai[index].wcd9xxx_ch_list, list) {
5133 ret = wcd9xxx_get_slave_port(ch->ch_num);
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07005134 if (ret < 0) {
5135 pr_err("%s: Invalid slave port ID: %d\n",
5136 __func__, ret);
5137 ret = -EINVAL;
5138 break;
5139 }
5140 tabla_p->dai[index].ch_mask |= 1 << ret;
5141 }
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07005142 break;
5143 case SND_SOC_DAPM_POST_PMD:
5144 ret = wait_event_timeout(tabla_p->dai[index].dai_wait,
5145 (tabla_p->dai[index].ch_mask == 0),
5146 msecs_to_jiffies(SLIM_CLOSE_TIMEOUT));
5147 if (!ret) {
5148 pr_err("%s: Slim close tx/rx wait timeout\n",
5149 __func__);
5150 ret = -EINVAL;
Kuirong Wang906ac472012-07-09 12:54:44 -07005151 }
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07005152 break;
5153 }
5154 return ret;
5155}
5156
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005157static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
Kuirong Wang906ac472012-07-09 12:54:44 -07005158 struct snd_kcontrol *kcontrol,
5159 int event)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005160{
Kuirong Wang906ac472012-07-09 12:54:44 -07005161 struct wcd9xxx *core;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005162 struct snd_soc_codec *codec = w->codec;
5163 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
Kuirong Wang906ac472012-07-09 12:54:44 -07005164 u32 ret = 0;
5165 struct wcd9xxx_codec_dai_data *dai;
5166
5167 core = dev_get_drvdata(codec->dev->parent);
5168
5169 pr_debug("%s: event called! codec name %s num_dai %d\n"
5170 "stream name %s event %d\n",
5171 __func__, w->codec->name, w->codec->num_dai,
5172 w->sname, event);
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005173
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005174 /* Execute the callback only if interface type is slimbus */
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005175 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
Kuirong Wang906ac472012-07-09 12:54:44 -07005176 if (event == SND_SOC_DAPM_POST_PMD && (core != NULL) &&
5177 (core->dev != NULL) &&
5178 (core->dev->parent != NULL)) {
5179 pm_runtime_mark_last_busy(core->dev->parent);
5180 pm_runtime_put(core->dev->parent);
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005181 }
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005182 return 0;
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005183 }
Kuirong Wang906ac472012-07-09 12:54:44 -07005184 pr_debug("%s: w->name %s w->shift %d event %d\n",
5185 __func__, w->name, w->shift, event);
5186 dai = &tabla_p->dai[w->shift];
Kiran Kandia9fffe92012-05-20 23:42:30 -07005187
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005188 switch (event) {
5189 case SND_SOC_DAPM_POST_PMU:
Kuirong Wang906ac472012-07-09 12:54:44 -07005190 ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMU,
5191 w->shift);
5192 ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
5193 dai->rate, dai->bit_width,
5194 &dai->grph);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005195 break;
5196 case SND_SOC_DAPM_POST_PMD:
Kuirong Wang906ac472012-07-09 12:54:44 -07005197 ret = wcd9xxx_close_slim_sch_rx(core,
5198 &dai->wcd9xxx_ch_list,
5199 dai->grph);
5200 ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMD,
5201 w->shift);
5202 if (ret < 0) {
5203 ret = wcd9xxx_disconnect_port(core,
5204 &dai->wcd9xxx_ch_list,
5205 dai->grph);
5206 pr_info("%s: Disconnect RX port, ret = %d\n",
5207 __func__, ret);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005208 }
Kuirong Wang906ac472012-07-09 12:54:44 -07005209 if ((core != NULL) &&
5210 (core->dev != NULL) &&
5211 (core->dev->parent != NULL)) {
5212 pm_runtime_mark_last_busy(core->dev->parent);
5213 pm_runtime_put(core->dev->parent);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005214 }
Kuirong Wang906ac472012-07-09 12:54:44 -07005215 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005216 }
Kuirong Wang906ac472012-07-09 12:54:44 -07005217
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005218 return ret;
5219}
5220
5221static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
Kuirong Wang906ac472012-07-09 12:54:44 -07005222 struct snd_kcontrol *kcontrol,
5223 int event)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005224{
Kuirong Wang906ac472012-07-09 12:54:44 -07005225 struct wcd9xxx *core;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005226 struct snd_soc_codec *codec = w->codec;
5227 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
Kuirong Wang906ac472012-07-09 12:54:44 -07005228 u32 ret = 0;
5229 struct wcd9xxx_codec_dai_data *dai;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005230
Kuirong Wang906ac472012-07-09 12:54:44 -07005231 core = dev_get_drvdata(codec->dev->parent);
5232
5233 pr_debug("%s: event called! codec name %s num_dai %d\n"
5234 "stream name %s\n", __func__, w->codec->name,
5235 w->codec->num_dai, w->sname);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005236
5237 /* Execute the callback only if interface type is slimbus */
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005238 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
Kuirong Wang906ac472012-07-09 12:54:44 -07005239 if (event == SND_SOC_DAPM_POST_PMD && (core != NULL) &&
5240 (core->dev != NULL) &&
5241 (core->dev->parent != NULL)) {
5242 pm_runtime_mark_last_busy(core->dev->parent);
5243 pm_runtime_put(core->dev->parent);
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005244 }
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005245 return 0;
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07005246 }
Kiran Kandi1e6371d2012-03-29 11:48:57 -07005247
5248 pr_debug("%s(): %s %d\n", __func__, w->name, event);
5249
Kuirong Wang906ac472012-07-09 12:54:44 -07005250 dai = &tabla_p->dai[w->shift];
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005251 switch (event) {
5252 case SND_SOC_DAPM_POST_PMU:
Kuirong Wang906ac472012-07-09 12:54:44 -07005253 ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMU,
5254 w->shift);
5255 ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
5256 dai->rate,
5257 dai->bit_width,
5258 &dai->grph);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005259 break;
5260 case SND_SOC_DAPM_POST_PMD:
Kuirong Wang906ac472012-07-09 12:54:44 -07005261 ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
5262 dai->grph);
5263 ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMD,
5264 w->shift);
5265 if (ret < 0) {
5266 ret = wcd9xxx_disconnect_port(core,
5267 &dai->wcd9xxx_ch_list,
5268 dai->grph);
5269 pr_info("%s: Disconnect TX port, ret = %d\n",
5270 __func__, ret);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005271 }
Kuirong Wang906ac472012-07-09 12:54:44 -07005272 if ((core != NULL) &&
5273 (core->dev != NULL) &&
5274 (core->dev->parent != NULL)) {
5275 pm_runtime_mark_last_busy(core->dev->parent);
5276 pm_runtime_put(core->dev->parent);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005277 }
Kuirong Wang906ac472012-07-09 12:54:44 -07005278 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005279 }
5280 return ret;
5281}
5282
5283/* Todo: Have seperate dapm widgets for I2S and Slimbus.
5284 * Might Need to have callbacks registered only for slimbus
5285 */
5286static const struct snd_soc_dapm_widget tabla_dapm_widgets[] = {
5287 /*RX stuff */
5288 SND_SOC_DAPM_OUTPUT("EAR"),
5289
Damir Didjusto7c85d712012-08-16 21:22:29 -07005290 SND_SOC_DAPM_PGA_E("EAR PA", SND_SOC_NOPM, 0, 0, NULL,
5291 0, tabla_ear_pa_event, SND_SOC_DAPM_PRE_PMU |
5292 SND_SOC_DAPM_PRE_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005293
Damir Didjusto7c85d712012-08-16 21:22:29 -07005294 SND_SOC_DAPM_MIXER("DAC1", SND_SOC_NOPM, 0, 0, dac1_switch,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005295 ARRAY_SIZE(dac1_switch)),
5296
Kuirong Wang906ac472012-07-09 12:54:44 -07005297 SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM,
5298 AIF1_PB, 0, tabla_codec_enable_slimrx,
5299 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5300 SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM,
5301 AIF2_PB, 0, tabla_codec_enable_slimrx,
5302 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5303 SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM,
5304 AIF3_PB, 0, tabla_codec_enable_slimrx,
5305 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5306
5307 SND_SOC_DAPM_MUX("SLIM RX1 MUX", SND_SOC_NOPM, TABLA_RX1, 0,
5308 &slim_rx_mux[TABLA_RX1]),
5309 SND_SOC_DAPM_MUX("SLIM RX2 MUX", SND_SOC_NOPM, TABLA_RX2, 0,
5310 &slim_rx_mux[TABLA_RX2]),
5311 SND_SOC_DAPM_MUX("SLIM RX3 MUX", SND_SOC_NOPM, TABLA_RX3, 0,
5312 &slim_rx_mux[TABLA_RX3]),
5313 SND_SOC_DAPM_MUX("SLIM RX4 MUX", SND_SOC_NOPM, TABLA_RX4, 0,
5314 &slim_rx_mux[TABLA_RX4]),
5315 SND_SOC_DAPM_MUX("SLIM RX5 MUX", SND_SOC_NOPM, TABLA_RX5, 0,
5316 &slim_rx_mux[TABLA_RX5]),
5317 SND_SOC_DAPM_MUX("SLIM RX6 MUX", SND_SOC_NOPM, TABLA_RX6, 0,
5318 &slim_rx_mux[TABLA_RX6]),
5319 SND_SOC_DAPM_MUX("SLIM RX7 MUX", SND_SOC_NOPM, TABLA_RX7, 0,
5320 &slim_rx_mux[TABLA_RX7]),
5321
5322 SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5323 SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
5324 SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
5325 SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
5326 SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
5327 SND_SOC_DAPM_MIXER("SLIM RX6", SND_SOC_NOPM, 0, 0, NULL, 0),
5328 SND_SOC_DAPM_MIXER("SLIM RX7", SND_SOC_NOPM, 0, 0, NULL, 0),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005329 /* Headphone */
5330 SND_SOC_DAPM_OUTPUT("HEADPHONE"),
5331 SND_SOC_DAPM_PGA_E("HPHL", TABLA_A_RX_HPH_CNP_EN, 5, 0, NULL, 0,
5332 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
5333 SND_SOC_DAPM_POST_PMD),
5334 SND_SOC_DAPM_MIXER("HPHL DAC", TABLA_A_RX_HPH_L_DAC_CTL, 7, 0,
5335 hphl_switch, ARRAY_SIZE(hphl_switch)),
5336
5337 SND_SOC_DAPM_PGA_E("HPHR", TABLA_A_RX_HPH_CNP_EN, 4, 0, NULL, 0,
5338 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
5339 SND_SOC_DAPM_POST_PMD),
5340
5341 SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TABLA_A_RX_HPH_R_DAC_CTL, 7, 0,
5342 tabla_hphr_dac_event,
5343 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5344
5345 /* Speaker */
5346 SND_SOC_DAPM_OUTPUT("LINEOUT1"),
5347 SND_SOC_DAPM_OUTPUT("LINEOUT2"),
5348 SND_SOC_DAPM_OUTPUT("LINEOUT3"),
5349 SND_SOC_DAPM_OUTPUT("LINEOUT4"),
5350 SND_SOC_DAPM_OUTPUT("LINEOUT5"),
5351
5352 SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TABLA_A_RX_LINE_CNP_EN, 0, 0, NULL,
5353 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
5354 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5355 SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TABLA_A_RX_LINE_CNP_EN, 1, 0, NULL,
5356 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
5357 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5358 SND_SOC_DAPM_PGA_E("LINEOUT3 PA", TABLA_A_RX_LINE_CNP_EN, 2, 0, NULL,
5359 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
5360 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5361 SND_SOC_DAPM_PGA_E("LINEOUT4 PA", TABLA_A_RX_LINE_CNP_EN, 3, 0, NULL,
5362 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
5363 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5364 SND_SOC_DAPM_PGA_E("LINEOUT5 PA", TABLA_A_RX_LINE_CNP_EN, 4, 0, NULL, 0,
5365 tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
5366 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5367
5368 SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TABLA_A_RX_LINE_1_DAC_CTL, 7, 0
5369 , tabla_lineout_dac_event,
5370 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5371 SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TABLA_A_RX_LINE_2_DAC_CTL, 7, 0
5372 , tabla_lineout_dac_event,
5373 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5374 SND_SOC_DAPM_DAC_E("LINEOUT3 DAC", NULL, TABLA_A_RX_LINE_3_DAC_CTL, 7, 0
5375 , tabla_lineout_dac_event,
5376 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5377 SND_SOC_DAPM_SWITCH("LINEOUT3 DAC GROUND", SND_SOC_NOPM, 0, 0,
5378 &lineout3_ground_switch),
5379 SND_SOC_DAPM_DAC_E("LINEOUT4 DAC", NULL, TABLA_A_RX_LINE_4_DAC_CTL, 7, 0
5380 , tabla_lineout_dac_event,
5381 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5382 SND_SOC_DAPM_SWITCH("LINEOUT4 DAC GROUND", SND_SOC_NOPM, 0, 0,
5383 &lineout4_ground_switch),
5384 SND_SOC_DAPM_DAC_E("LINEOUT5 DAC", NULL, TABLA_A_RX_LINE_5_DAC_CTL, 7, 0
5385 , tabla_lineout_dac_event,
5386 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5387
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005388 SND_SOC_DAPM_MIXER_E("RX1 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005389 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5390 SND_SOC_DAPM_POST_PMU),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005391 SND_SOC_DAPM_MIXER_E("RX2 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005392 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5393 SND_SOC_DAPM_POST_PMU),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005394 SND_SOC_DAPM_MIXER_E("RX3 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005395 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5396 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005397 SND_SOC_DAPM_MIXER_E("RX4 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005398 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5399 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005400 SND_SOC_DAPM_MIXER_E("RX5 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 4, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005401 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5402 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005403 SND_SOC_DAPM_MIXER_E("RX6 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005404 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5405 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005406 SND_SOC_DAPM_MIXER_E("RX7 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 6, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005407 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5408 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005409
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005410 SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5411 SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5412 SND_SOC_DAPM_MIXER("RX3 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5413
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005414 SND_SOC_DAPM_MUX_E("RX4 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0,
5415 &rx4_dsm_mux, tabla_codec_reset_interpolator,
5416 SND_SOC_DAPM_PRE_PMU),
5417
5418 SND_SOC_DAPM_MUX_E("RX6 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0,
5419 &rx6_dsm_mux, tabla_codec_reset_interpolator,
5420 SND_SOC_DAPM_PRE_PMU),
5421
Kuirong Wang84ee8802013-02-09 12:52:06 -08005422 SND_SOC_DAPM_MIXER_E("RX1 CHAIN", SND_SOC_NOPM, 5, 0, NULL,
5423 0, tabla_codec_hphr_dem_input_selection,
5424 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
5425 SND_SOC_DAPM_MIXER_E("RX2 CHAIN", SND_SOC_NOPM, 5, 0, NULL,
5426 0, tabla_codec_hphl_dem_input_selection,
5427 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005428
5429 SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5430 &rx_mix1_inp1_mux),
5431 SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5432 &rx_mix1_inp2_mux),
Kiran Kandia9fffe92012-05-20 23:42:30 -07005433 SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0,
5434 &rx_mix1_inp3_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005435 SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5436 &rx2_mix1_inp1_mux),
5437 SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5438 &rx2_mix1_inp2_mux),
5439 SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5440 &rx3_mix1_inp1_mux),
5441 SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5442 &rx3_mix1_inp2_mux),
5443 SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5444 &rx4_mix1_inp1_mux),
5445 SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5446 &rx4_mix1_inp2_mux),
5447 SND_SOC_DAPM_MUX("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5448 &rx5_mix1_inp1_mux),
5449 SND_SOC_DAPM_MUX("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5450 &rx5_mix1_inp2_mux),
5451 SND_SOC_DAPM_MUX("RX6 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5452 &rx6_mix1_inp1_mux),
5453 SND_SOC_DAPM_MUX("RX6 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5454 &rx6_mix1_inp2_mux),
5455 SND_SOC_DAPM_MUX("RX7 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5456 &rx7_mix1_inp1_mux),
5457 SND_SOC_DAPM_MUX("RX7 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5458 &rx7_mix1_inp2_mux),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005459 SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0,
5460 &rx1_mix2_inp1_mux),
5461 SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0,
5462 &rx1_mix2_inp2_mux),
5463 SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0,
5464 &rx2_mix2_inp1_mux),
5465 SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0,
5466 &rx2_mix2_inp2_mux),
5467 SND_SOC_DAPM_MUX("RX3 MIX2 INP1", SND_SOC_NOPM, 0, 0,
5468 &rx3_mix2_inp1_mux),
5469 SND_SOC_DAPM_MUX("RX3 MIX2 INP2", SND_SOC_NOPM, 0, 0,
5470 &rx3_mix2_inp2_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005471
5472 SND_SOC_DAPM_SUPPLY("CP", TABLA_A_CP_EN, 0, 0,
5473 tabla_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU |
5474 SND_SOC_DAPM_PRE_PMD),
5475
5476 SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
5477 tabla_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
5478 SND_SOC_DAPM_POST_PMD),
5479
5480 /* TX */
5481
5482 SND_SOC_DAPM_SUPPLY("CDC_CONN", TABLA_A_CDC_CLK_OTHR_CTL, 2, 0, NULL,
5483 0),
5484
Simmi Pateriya71d63872012-11-08 01:06:30 +05305485 SND_SOC_DAPM_SUPPLY("LDO_H", SND_SOC_NOPM, 0, 0,
5486 tabla_codec_enable_ldo_h, SND_SOC_DAPM_PRE_PMU |
5487 SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005488
Kuirong Wang0f8ade32012-02-27 16:29:45 -08005489 SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 0, 0,
5490 tabla_config_compander, SND_SOC_DAPM_PRE_PMU |
5491 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
5492 SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 1, 0,
5493 tabla_config_compander, SND_SOC_DAPM_PRE_PMU |
5494 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
5495
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005496 SND_SOC_DAPM_INPUT("AMIC1"),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305497 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005498 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5499 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305500 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005501 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5502 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305503 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005504 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5505 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5506 SND_SOC_DAPM_ADC_E("ADC1", NULL, TABLA_A_TX_1_2_EN, 7, 0,
5507 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
5508 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5509
5510 SND_SOC_DAPM_INPUT("AMIC3"),
5511 SND_SOC_DAPM_ADC_E("ADC3", NULL, TABLA_A_TX_3_4_EN, 7, 0,
5512 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
5513 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5514
5515 SND_SOC_DAPM_INPUT("AMIC4"),
5516 SND_SOC_DAPM_ADC_E("ADC4", NULL, TABLA_A_TX_3_4_EN, 3, 0,
5517 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
5518 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5519
5520 SND_SOC_DAPM_INPUT("AMIC5"),
5521 SND_SOC_DAPM_ADC_E("ADC5", NULL, TABLA_A_TX_5_6_EN, 7, 0,
5522 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
5523
5524 SND_SOC_DAPM_INPUT("AMIC6"),
5525 SND_SOC_DAPM_ADC_E("ADC6", NULL, TABLA_A_TX_5_6_EN, 3, 0,
5526 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
5527
5528 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 -08005529 &dec1_mux, tabla_codec_enable_dec,
5530 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5531 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005532
5533 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 -08005534 &dec2_mux, tabla_codec_enable_dec,
5535 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5536 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005537
5538 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 -08005539 &dec3_mux, tabla_codec_enable_dec,
5540 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5541 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005542
5543 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 -08005544 &dec4_mux, tabla_codec_enable_dec,
5545 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5546 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005547
5548 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 -08005549 &dec5_mux, tabla_codec_enable_dec,
5550 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5551 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005552
5553 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 -08005554 &dec6_mux, tabla_codec_enable_dec,
5555 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5556 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005557
5558 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 -08005559 &dec7_mux, tabla_codec_enable_dec,
5560 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5561 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005562
5563 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 -08005564 &dec8_mux, tabla_codec_enable_dec,
5565 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5566 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005567
5568 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 -08005569 &dec9_mux, tabla_codec_enable_dec,
5570 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5571 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005572
5573 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 -08005574 &dec10_mux, tabla_codec_enable_dec,
5575 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5576 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005577
5578 SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux),
5579 SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux),
5580
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08005581 SND_SOC_DAPM_OUTPUT("ANC HEADPHONE"),
5582 SND_SOC_DAPM_PGA_E("ANC HPHL", SND_SOC_NOPM, 0, 0, NULL, 0,
5583 tabla_codec_enable_anc,
5584 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
5585 SND_SOC_DAPM_PGA_E("ANC HPHR", SND_SOC_NOPM, 0, 0, NULL, 0,
5586 tabla_codec_enable_anc, SND_SOC_DAPM_PRE_PMU),
5587
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005588
5589 SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux),
5590
5591 SND_SOC_DAPM_INPUT("AMIC2"),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305592 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005593 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
Simmi Pateriya71d63872012-11-08 01:06:30 +05305594 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5595 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Power External",
5596 TABLA_A_MICB_2_CTL, 7, 0,
5597 tabla_codec_enable_micbias_power,
5598 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5599 SND_SOC_DAPM_POST_PMD),
5600
5601 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005602 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5603 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305604 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005605 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5606 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305607 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005608 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5609 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305610 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005611 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5612 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305613 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005614 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5615 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Simmi Pateriya71d63872012-11-08 01:06:30 +05305616 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", SND_SOC_NOPM, 0, 0,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005617 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5618 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5619 SND_SOC_DAPM_ADC_E("ADC2", NULL, TABLA_A_TX_1_2_EN, 3, 0,
5620 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
5621 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5622
Kuirong Wang906ac472012-07-09 12:54:44 -07005623 SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM,
5624 AIF1_CAP, 0, tabla_codec_enable_slimtx,
5625 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5626
5627 SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM,
5628 AIF2_CAP, 0, tabla_codec_enable_slimtx,
5629 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5630
5631 SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM,
5632 AIF3_CAP, 0, tabla_codec_enable_slimtx,
5633 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5634
5635 SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0,
5636 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
5637
5638 SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0,
5639 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
5640
5641 SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0,
5642 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
5643
5644 SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, TABLA_TX1, 0,
5645 &sb_tx1_mux),
5646 SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, TABLA_TX2, 0,
5647 &sb_tx2_mux),
5648 SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, TABLA_TX3, 0,
5649 &sb_tx3_mux),
5650 SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, TABLA_TX4, 0,
5651 &sb_tx4_mux),
5652 SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, TABLA_TX5, 0,
5653 &sb_tx5_mux),
5654 SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, TABLA_TX6, 0,
5655 &sb_tx6_mux),
5656 SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, TABLA_TX7, 0,
5657 &sb_tx7_mux),
5658 SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, TABLA_TX8, 0,
5659 &sb_tx8_mux),
5660 SND_SOC_DAPM_MUX("SLIM TX9 MUX", SND_SOC_NOPM, TABLA_TX9, 0,
5661 &sb_tx9_mux),
5662 SND_SOC_DAPM_MUX("SLIM TX10 MUX", SND_SOC_NOPM, TABLA_TX10, 0,
5663 &sb_tx10_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005664
5665 /* Digital Mic Inputs */
5666 SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
5667 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5668 SND_SOC_DAPM_POST_PMD),
5669
5670 SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
5671 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5672 SND_SOC_DAPM_POST_PMD),
5673
5674 SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0,
5675 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5676 SND_SOC_DAPM_POST_PMD),
5677
5678 SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0,
5679 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5680 SND_SOC_DAPM_POST_PMD),
5681
5682 SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0,
5683 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5684 SND_SOC_DAPM_POST_PMD),
5685 SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 0,
5686 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5687 SND_SOC_DAPM_POST_PMD),
5688
5689 /* Sidetone */
5690 SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux),
5691 SND_SOC_DAPM_PGA("IIR1", TABLA_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0),
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08005692
Bhalchandra Gajare8ba44462012-07-26 18:08:21 -07005693 SND_SOC_DAPM_MUX("IIR2 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir2_inp1_mux),
5694 SND_SOC_DAPM_PGA("IIR2", TABLA_A_CDC_CLK_SD_CTL, 1, 0, NULL, 0),
5695
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08005696 /* AUX PGA */
5697 SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TABLA_A_AUX_L_EN, 7, 0,
5698 tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
5699 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
5700 SND_SOC_DAPM_POST_PMD),
5701
5702 SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TABLA_A_AUX_R_EN, 7, 0,
5703 tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
5704 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
5705 SND_SOC_DAPM_POST_PMD),
5706
5707 /* Lineout, ear and HPH PA Mixers */
5708 SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0,
5709 hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)),
5710
5711 SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0,
5712 hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)),
5713
5714 SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0,
5715 lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)),
5716
5717 SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0,
5718 lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)),
5719
5720 SND_SOC_DAPM_MIXER("LINEOUT3_PA_MIXER", SND_SOC_NOPM, 0, 0,
5721 lineout3_pa_mix, ARRAY_SIZE(lineout3_pa_mix)),
5722
5723 SND_SOC_DAPM_MIXER("LINEOUT4_PA_MIXER", SND_SOC_NOPM, 0, 0,
5724 lineout4_pa_mix, ARRAY_SIZE(lineout4_pa_mix)),
5725
5726 SND_SOC_DAPM_MIXER("LINEOUT5_PA_MIXER", SND_SOC_NOPM, 0, 0,
5727 lineout5_pa_mix, ARRAY_SIZE(lineout5_pa_mix)),
5728
5729 SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0,
5730 ear_pa_mix, ARRAY_SIZE(ear_pa_mix)),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005731};
5732
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005733static short tabla_codec_read_sta_result(struct snd_soc_codec *codec)
Bradley Rubincb1e2732011-06-23 16:49:20 -07005734{
5735 u8 bias_msb, bias_lsb;
5736 short bias_value;
5737
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005738 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B3_STATUS);
5739 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B2_STATUS);
5740 bias_value = (bias_msb << 8) | bias_lsb;
5741 return bias_value;
5742}
5743
5744static short tabla_codec_read_dce_result(struct snd_soc_codec *codec)
5745{
5746 u8 bias_msb, bias_lsb;
5747 short bias_value;
5748
5749 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B5_STATUS);
5750 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B4_STATUS);
5751 bias_value = (bias_msb << 8) | bias_lsb;
5752 return bias_value;
5753}
5754
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005755static void tabla_turn_onoff_rel_detection(struct snd_soc_codec *codec, bool on)
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005756{
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005757 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, on << 1);
5758}
5759
5760static short __tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce,
5761 bool override_bypass, bool noreldetection)
5762{
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005763 short bias_value;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005764 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
5765
Joonwoo Parkf6574c72012-10-10 17:29:57 -07005766 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005767 if (noreldetection)
5768 tabla_turn_onoff_rel_detection(codec, false);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005769
Joonwoo Park925914c2012-01-05 13:35:18 -08005770 /* Turn on the override */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005771 if (!override_bypass)
5772 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x4, 0x4);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005773 if (dce) {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005774 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5775 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
5776 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
Joonwoo Park433149a2012-01-11 09:53:54 -08005777 usleep_range(tabla->mbhc_data.t_sta_dce,
5778 tabla->mbhc_data.t_sta_dce);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005779 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
Joonwoo Park0976d012011-12-22 11:48:18 -08005780 usleep_range(tabla->mbhc_data.t_dce,
5781 tabla->mbhc_data.t_dce);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005782 bias_value = tabla_codec_read_dce_result(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005783 } else {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005784 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005785 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
5786 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
Joonwoo Park433149a2012-01-11 09:53:54 -08005787 usleep_range(tabla->mbhc_data.t_sta_dce,
5788 tabla->mbhc_data.t_sta_dce);
Joonwoo Park0976d012011-12-22 11:48:18 -08005789 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
5790 usleep_range(tabla->mbhc_data.t_sta,
5791 tabla->mbhc_data.t_sta);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005792 bias_value = tabla_codec_read_sta_result(codec);
5793 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5794 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005795 }
Joonwoo Park925914c2012-01-05 13:35:18 -08005796 /* Turn off the override after measuring mic voltage */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005797 if (!override_bypass)
5798 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00);
5799
5800 if (noreldetection)
5801 tabla_turn_onoff_rel_detection(codec, true);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07005802 wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005803
Bradley Rubincb1e2732011-06-23 16:49:20 -07005804 return bias_value;
5805}
5806
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005807static short tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce,
5808 bool norel)
5809{
5810 return __tabla_codec_sta_dce(codec, dce, false, norel);
5811}
5812
5813/* called only from interrupt which is under codec_resource_lock acquisition */
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07005814static short tabla_codec_setup_hs_polling(struct snd_soc_codec *codec)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005815{
5816 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07005817 short bias_value;
Simmi Pateriya71d63872012-11-08 01:06:30 +05305818 u8 cfilt_mode = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005819
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005820 pr_debug("%s: enter, mclk_enabled %d\n", __func__, tabla->mclk_enabled);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005821 if (!tabla->mbhc_cfg.calibration) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005822 pr_err("Error, no tabla calibration\n");
Bradley Rubincb1e2732011-06-23 16:49:20 -07005823 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005824 }
5825
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07005826 if (!tabla->mclk_enabled) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07005827 tabla_codec_disable_clock_block(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005828 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_MBHC_MODE);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07005829 tabla_enable_rx_bias(codec, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005830 tabla_codec_enable_clock_block(codec, 1);
5831 }
5832
5833 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x01);
Simmi Pateriya71d63872012-11-08 01:06:30 +05305834 if (!tabla->mbhc_cfg.micbias_always_on) {
5835 /* Make sure CFILT is in fast mode, save current mode */
5836 cfilt_mode = snd_soc_read(codec,
5837 tabla->mbhc_bias_regs.cfilt_ctl);
5838 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl,
5839 0x70, 0x00);
5840 }
Patrick Lai3043fba2011-08-01 14:15:57 -07005841
Joonwoo Parkf4267c22012-01-10 13:25:24 -08005842 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x1F, 0x16);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005843
5844 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005845 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005846
5847 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x80);
5848 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x1F, 0x1C);
5849 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x40, 0x40);
5850
5851 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005852 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5853 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005854
Joonwoo Park925914c2012-01-05 13:35:18 -08005855 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x2, 0x2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005856 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5857
Bradley Rubincb1e2732011-06-23 16:49:20 -07005858 tabla_codec_calibrate_hs_polling(codec);
5859
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005860 /* don't flip override */
5861 bias_value = __tabla_codec_sta_dce(codec, 1, true, true);
Simmi Pateriya71d63872012-11-08 01:06:30 +05305862 if (!tabla->mbhc_cfg.micbias_always_on)
5863 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl,
5864 0x40, cfilt_mode);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005865 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005866
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07005867 return bias_value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005868}
5869
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005870static int tabla_cancel_btn_work(struct tabla_priv *tabla)
5871{
5872 int r = 0;
5873 struct wcd9xxx *core = dev_get_drvdata(tabla->codec->dev->parent);
5874
5875 if (cancel_delayed_work_sync(&tabla->mbhc_btn_dwork)) {
5876 /* if scheduled mbhc_btn_dwork is canceled from here,
5877 * we have to unlock from here instead btn_work */
5878 wcd9xxx_unlock_sleep(core);
5879 r = 1;
5880 }
5881 return r;
5882}
5883
5884/* called under codec_resource_lock acquisition */
5885void tabla_set_and_turnoff_hph_padac(struct snd_soc_codec *codec)
Joonwoo Park03324832012-03-19 19:36:16 -07005886{
5887 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005888 u8 wg_time;
5889
5890 wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ;
5891 wg_time += 1;
Joonwoo Park03324832012-03-19 19:36:16 -07005892
5893 /* If headphone PA is on, check if userspace receives
5894 * removal event to sync-up PA's state */
5895 if (tabla_is_hph_pa_on(codec)) {
5896 pr_debug("%s PA is on, setting PA_OFF_ACK\n", __func__);
5897 set_bit(TABLA_HPHL_PA_OFF_ACK, &tabla->hph_pa_dac_state);
5898 set_bit(TABLA_HPHR_PA_OFF_ACK, &tabla->hph_pa_dac_state);
5899 } else {
5900 pr_debug("%s PA is off\n", __func__);
5901 }
5902
5903 if (tabla_is_hph_dac_on(codec, 1))
5904 set_bit(TABLA_HPHL_DAC_OFF_ACK, &tabla->hph_pa_dac_state);
5905 if (tabla_is_hph_dac_on(codec, 0))
5906 set_bit(TABLA_HPHR_DAC_OFF_ACK, &tabla->hph_pa_dac_state);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005907
5908 snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00);
5909 snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_DAC_CTL,
Gopikrishnaiah Anandan3b230b22012-12-07 11:36:58 -05005910 0x80, 0x00);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005911 snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_DAC_CTL,
5912 0xC0, 0x00);
5913 usleep_range(wg_time * 1000, wg_time * 1000);
5914}
5915
5916static void tabla_clr_and_turnon_hph_padac(struct tabla_priv *tabla)
5917{
5918 bool pa_turned_on = false;
5919 struct snd_soc_codec *codec = tabla->codec;
5920 u8 wg_time;
5921
5922 wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ;
5923 wg_time += 1;
5924
5925 if (test_and_clear_bit(TABLA_HPHR_DAC_OFF_ACK,
5926 &tabla->hph_pa_dac_state)) {
5927 pr_debug("%s: HPHR clear flag and enable DAC\n", __func__);
5928 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_R_DAC_CTL,
5929 0xC0, 0xC0);
5930 }
5931 if (test_and_clear_bit(TABLA_HPHL_DAC_OFF_ACK,
5932 &tabla->hph_pa_dac_state)) {
5933 pr_debug("%s: HPHL clear flag and enable DAC\n", __func__);
5934 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_L_DAC_CTL,
5935 0xC0, 0xC0);
5936 }
5937
5938 if (test_and_clear_bit(TABLA_HPHR_PA_OFF_ACK,
5939 &tabla->hph_pa_dac_state)) {
5940 pr_debug("%s: HPHR clear flag and enable PA\n", __func__);
5941 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x10,
5942 1 << 4);
5943 pa_turned_on = true;
5944 }
5945 if (test_and_clear_bit(TABLA_HPHL_PA_OFF_ACK,
5946 &tabla->hph_pa_dac_state)) {
5947 pr_debug("%s: HPHL clear flag and enable PA\n", __func__);
5948 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x20,
5949 1 << 5);
5950 pa_turned_on = true;
5951 }
5952
5953 if (pa_turned_on) {
5954 pr_debug("%s: PA was turned off by MBHC and not by DAPM\n",
5955 __func__);
5956 usleep_range(wg_time * 1000, wg_time * 1000);
5957 }
5958}
5959
5960/* called under codec_resource_lock acquisition */
Simmi Pateriya71d63872012-11-08 01:06:30 +05305961static void tabla_codec_enable_mbhc_micbias(struct snd_soc_codec *codec,
5962 bool enable)
5963{
5964 int r;
5965 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
5966
5967 if (!tabla->mbhc_cfg.micbias_always_on)
5968 return;
5969 if (enable) {
5970 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
5971 tabla_codec_update_cfilt_usage(codec,
5972 tabla->mbhc_bias_regs.cfilt_sel, 1);
5973 r = snd_soc_dapm_force_enable_pin(&codec->dapm,
5974 "MIC BIAS2 Power External");
5975 snd_soc_dapm_sync(&codec->dapm);
5976 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
5977 pr_debug("%s: Turning on MICBIAS2 r %d\n", __func__, r);
5978 } else {
5979 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
5980 r = snd_soc_dapm_disable_pin(&codec->dapm,
5981 "MIC BIAS2 Power External");
5982 snd_soc_dapm_sync(&codec->dapm);
5983 tabla_codec_update_cfilt_usage(codec,
5984 tabla->mbhc_bias_regs.cfilt_sel, 0);
5985 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
5986 pr_debug("%s: Turning off MICBIAS2 r %d\n", __func__, r);
5987 }
5988}
5989
5990/* called under codec_resource_lock acquisition */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005991static void tabla_codec_report_plug(struct snd_soc_codec *codec, int insertion,
5992 enum snd_jack_types jack_type)
5993{
5994 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07005995 pr_debug("%s: enter insertion %d hph_status %x\n",
5996 __func__, insertion, tabla->hph_status);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005997 if (!insertion) {
5998 /* Report removal */
5999 tabla->hph_status &= ~jack_type;
6000 if (tabla->mbhc_cfg.headset_jack) {
6001 /* cancel possibly scheduled btn work and
6002 * report release if we reported button press */
6003 if (tabla_cancel_btn_work(tabla)) {
6004 pr_debug("%s: button press is canceled\n",
6005 __func__);
6006 } else if (tabla->buttons_pressed) {
6007 pr_debug("%s: Reporting release for reported "
6008 "button press %d\n", __func__,
6009 jack_type);
6010 tabla_snd_soc_jack_report(tabla,
6011 tabla->mbhc_cfg.button_jack, 0,
6012 tabla->buttons_pressed);
6013 tabla->buttons_pressed &=
6014 ~TABLA_JACK_BUTTON_MASK;
6015 }
Simmi Pateriya71d63872012-11-08 01:06:30 +05306016 if (jack_type == SND_JACK_HEADSET)
6017 tabla_codec_enable_mbhc_micbias(codec, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006018 pr_debug("%s: Reporting removal %d(%x)\n", __func__,
6019 jack_type, tabla->hph_status);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006020 tabla_snd_soc_jack_report(tabla,
6021 tabla->mbhc_cfg.headset_jack,
6022 tabla->hph_status,
6023 TABLA_JACK_MASK);
6024 }
6025 tabla_set_and_turnoff_hph_padac(codec);
6026 hphocp_off_report(tabla, SND_JACK_OC_HPHR,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07006027 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006028 hphocp_off_report(tabla, SND_JACK_OC_HPHL,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07006029 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006030 tabla->current_plug = PLUG_TYPE_NONE;
6031 tabla->mbhc_polling_active = false;
6032 } else {
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006033 if (tabla->mbhc_cfg.detect_extn_cable) {
6034 /* Report removal of current jack type */
6035 if (tabla->hph_status != jack_type &&
6036 tabla->mbhc_cfg.headset_jack) {
6037 pr_debug("%s: Reporting removal (%x)\n",
6038 __func__, tabla->hph_status);
6039 tabla_snd_soc_jack_report(tabla,
6040 tabla->mbhc_cfg.headset_jack,
6041 0, TABLA_JACK_MASK);
6042 tabla->hph_status = 0;
6043 }
6044 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006045 /* Report insertion */
6046 tabla->hph_status |= jack_type;
6047
6048 if (jack_type == SND_JACK_HEADPHONE)
6049 tabla->current_plug = PLUG_TYPE_HEADPHONE;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006050 else if (jack_type == SND_JACK_UNSUPPORTED)
6051 tabla->current_plug = PLUG_TYPE_GND_MIC_SWAP;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006052 else if (jack_type == SND_JACK_HEADSET) {
6053 tabla->mbhc_polling_active = true;
6054 tabla->current_plug = PLUG_TYPE_HEADSET;
Simmi Pateriya71d63872012-11-08 01:06:30 +05306055 tabla_codec_enable_mbhc_micbias(codec, true);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006056 } else if (jack_type == SND_JACK_LINEOUT)
6057 tabla->current_plug = PLUG_TYPE_HIGH_HPH;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006058 if (tabla->mbhc_cfg.headset_jack) {
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006059 pr_debug("%s: Reporting insertion %d(%x)\n", __func__,
6060 jack_type, tabla->hph_status);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006061 tabla_snd_soc_jack_report(tabla,
6062 tabla->mbhc_cfg.headset_jack,
6063 tabla->hph_status,
6064 TABLA_JACK_MASK);
6065 }
6066 tabla_clr_and_turnon_hph_padac(tabla);
6067 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006068 pr_debug("%s: leave hph_status %x\n", __func__, tabla->hph_status);
Joonwoo Park03324832012-03-19 19:36:16 -07006069}
6070
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006071static int tabla_codec_enable_hs_detect(struct snd_soc_codec *codec,
Joonwoo Park03324832012-03-19 19:36:16 -07006072 int insertion, int trigger,
6073 bool padac_off)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006074{
6075 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006076 int central_bias_enabled = 0;
Joonwoo Park0976d012011-12-22 11:48:18 -08006077 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006078 TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08006079 const struct tabla_mbhc_plug_detect_cfg *plug_det =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006080 TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006081
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006082 pr_debug("%s: enter insertion(%d) trigger(0x%x)\n",
6083 __func__, insertion, trigger);
6084
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006085 if (!tabla->mbhc_cfg.calibration) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006086 pr_err("Error, no tabla calibration\n");
6087 return -EINVAL;
6088 }
6089
6090 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0);
6091
Joonwoo Park03324832012-03-19 19:36:16 -07006092 /* Make sure mic bias and Mic line schmitt trigger
6093 * are turned OFF
6094 */
6095 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01);
6096 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
6097
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006098 if (insertion) {
Bhalchandra Gajareafc86432012-08-23 13:44:07 -07006099 pr_debug("%s: setup for insertion\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07006100 tabla_codec_switch_micbias(codec, 0);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006101
Joonwoo Park03324832012-03-19 19:36:16 -07006102 /* DAPM can manipulate PA/DAC bits concurrently */
6103 if (padac_off == true) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006104 tabla_set_and_turnoff_hph_padac(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07006105 }
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006106
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006107 if (trigger & MBHC_USE_HPHL_TRIGGER) {
Joonwoo Park03324832012-03-19 19:36:16 -07006108 /* Enable HPH Schmitt Trigger */
6109 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x11,
6110 0x11);
6111 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x0C,
6112 plug_det->hph_current << 2);
6113 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x02,
6114 0x02);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006115 }
6116 if (trigger & MBHC_USE_MB_TRIGGER) {
Joonwoo Park03324832012-03-19 19:36:16 -07006117 /* enable the mic line schmitt trigger */
6118 snd_soc_update_bits(codec,
6119 tabla->mbhc_bias_regs.mbhc_reg,
6120 0x60, plug_det->mic_current << 5);
6121 snd_soc_update_bits(codec,
6122 tabla->mbhc_bias_regs.mbhc_reg,
6123 0x80, 0x80);
6124 usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid);
6125 snd_soc_update_bits(codec,
6126 tabla->mbhc_bias_regs.ctl_reg, 0x01,
6127 0x00);
6128 snd_soc_update_bits(codec,
6129 tabla->mbhc_bias_regs.mbhc_reg,
6130 0x10, 0x10);
6131 }
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006132
6133 /* setup for insetion detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006134 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006135 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07006136 pr_debug("setup for removal detection\n");
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006137 /* Make sure the HPH schmitt trigger is OFF */
6138 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x12, 0x00);
6139
6140 /* enable the mic line schmitt trigger */
Joonwoo Park03324832012-03-19 19:36:16 -07006141 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg,
6142 0x01, 0x00);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006143 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x60,
Joonwoo Park0976d012011-12-22 11:48:18 -08006144 plug_det->mic_current << 5);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006145 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
6146 0x80, 0x80);
Joonwoo Park0976d012011-12-22 11:48:18 -08006147 usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006148 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
6149 0x10, 0x10);
6150
6151 /* Setup for low power removal detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006152 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0x2);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006153 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006154
6155 if (snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x4) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006156 /* called called by interrupt */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006157 if (!(tabla->clock_active)) {
6158 tabla_codec_enable_config_mode(codec, 1);
6159 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07006160 0x06, 0);
Joonwoo Park0976d012011-12-22 11:48:18 -08006161 usleep_range(generic->t_shutdown_plug_rem,
6162 generic->t_shutdown_plug_rem);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006163 tabla_codec_enable_config_mode(codec, 0);
6164 } else
6165 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07006166 0x06, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006167 }
6168
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07006169 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.int_rbias, 0x80, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006170
6171 /* If central bandgap disabled */
6172 if (!(snd_soc_read(codec, TABLA_A_PIN_CTL_OE1) & 1)) {
6173 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x3, 0x3);
Joonwoo Park0976d012011-12-22 11:48:18 -08006174 usleep_range(generic->t_bg_fast_settle,
6175 generic->t_bg_fast_settle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006176 central_bias_enabled = 1;
6177 }
6178
6179 /* If LDO_H disabled */
6180 if (snd_soc_read(codec, TABLA_A_PIN_CTL_OE0) & 0x80) {
6181 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x10, 0);
6182 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0x80);
Joonwoo Park0976d012011-12-22 11:48:18 -08006183 usleep_range(generic->t_ldoh, generic->t_ldoh);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006184 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0);
6185
6186 if (central_bias_enabled)
6187 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x1, 0);
6188 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006189
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08006190 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x3,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006191 tabla->mbhc_cfg.micbias);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006192
Joonwoo Parkf6574c72012-10-10 17:29:57 -07006193 wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006194 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0x1);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006195 pr_debug("%s: leave\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006196 return 0;
6197}
6198
Joonwoo Park0976d012011-12-22 11:48:18 -08006199static u16 tabla_codec_v_sta_dce(struct snd_soc_codec *codec, bool dce,
6200 s16 vin_mv)
6201{
Joonwoo Park0976d012011-12-22 11:48:18 -08006202 struct tabla_priv *tabla;
Joonwoo Park03324832012-03-19 19:36:16 -07006203 s16 diff, zero;
Joonwoo Park0976d012011-12-22 11:48:18 -08006204 u32 mb_mv, in;
Joonwoo Park03324832012-03-19 19:36:16 -07006205 u16 value;
Joonwoo Park0976d012011-12-22 11:48:18 -08006206
6207 tabla = snd_soc_codec_get_drvdata(codec);
6208 mb_mv = tabla->mbhc_data.micb_mv;
6209
6210 if (mb_mv == 0) {
6211 pr_err("%s: Mic Bias voltage is set to zero\n", __func__);
6212 return -EINVAL;
6213 }
6214
6215 if (dce) {
Joonwoo Park03324832012-03-19 19:36:16 -07006216 diff = (tabla->mbhc_data.dce_mb) - (tabla->mbhc_data.dce_z);
6217 zero = (tabla->mbhc_data.dce_z);
Joonwoo Park0976d012011-12-22 11:48:18 -08006218 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07006219 diff = (tabla->mbhc_data.sta_mb) - (tabla->mbhc_data.sta_z);
6220 zero = (tabla->mbhc_data.sta_z);
Joonwoo Park0976d012011-12-22 11:48:18 -08006221 }
6222 in = (u32) diff * vin_mv;
6223
Joonwoo Park03324832012-03-19 19:36:16 -07006224 value = (u16) (in / mb_mv) + zero;
6225 return value;
Joonwoo Park0976d012011-12-22 11:48:18 -08006226}
6227
6228static s32 tabla_codec_sta_dce_v(struct snd_soc_codec *codec, s8 dce,
6229 u16 bias_value)
6230{
6231 struct tabla_priv *tabla;
Joonwoo Park03324832012-03-19 19:36:16 -07006232 s16 value, z, mb;
Joonwoo Park0976d012011-12-22 11:48:18 -08006233 s32 mv;
6234
6235 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07006236 value = bias_value;
Joonwoo Park0976d012011-12-22 11:48:18 -08006237 if (dce) {
Joonwoo Park03324832012-03-19 19:36:16 -07006238 z = (tabla->mbhc_data.dce_z);
6239 mb = (tabla->mbhc_data.dce_mb);
6240 mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z);
Joonwoo Park0976d012011-12-22 11:48:18 -08006241 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07006242 z = (tabla->mbhc_data.sta_z);
6243 mb = (tabla->mbhc_data.sta_mb);
6244 mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z);
Joonwoo Park0976d012011-12-22 11:48:18 -08006245 }
6246
6247 return mv;
6248}
6249
Joonwoo Park03324832012-03-19 19:36:16 -07006250static void btn_lpress_fn(struct work_struct *work)
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006251{
6252 struct delayed_work *delayed_work;
6253 struct tabla_priv *tabla;
Joonwoo Park0976d012011-12-22 11:48:18 -08006254 short bias_value;
6255 int dce_mv, sta_mv;
Joonwoo Park03324832012-03-19 19:36:16 -07006256 struct wcd9xxx *core;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006257
6258 pr_debug("%s:\n", __func__);
6259
6260 delayed_work = to_delayed_work(work);
Joonwoo Park03324832012-03-19 19:36:16 -07006261 tabla = container_of(delayed_work, struct tabla_priv, mbhc_btn_dwork);
Joonwoo Park816b8e62012-01-23 16:03:21 -08006262 core = dev_get_drvdata(tabla->codec->dev->parent);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006263
6264 if (tabla) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006265 if (tabla->mbhc_cfg.button_jack) {
Joonwoo Park0976d012011-12-22 11:48:18 -08006266 bias_value = tabla_codec_read_sta_result(tabla->codec);
6267 sta_mv = tabla_codec_sta_dce_v(tabla->codec, 0,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306268 bias_value);
Joonwoo Park0976d012011-12-22 11:48:18 -08006269 bias_value = tabla_codec_read_dce_result(tabla->codec);
6270 dce_mv = tabla_codec_sta_dce_v(tabla->codec, 1,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306271 bias_value);
Joonwoo Park0976d012011-12-22 11:48:18 -08006272 pr_debug("%s: Reporting long button press event"
6273 " STA: %d, DCE: %d\n", __func__,
6274 sta_mv, dce_mv);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006275 tabla_snd_soc_jack_report(tabla,
6276 tabla->mbhc_cfg.button_jack,
Joonwoo Park03324832012-03-19 19:36:16 -07006277 tabla->buttons_pressed,
6278 tabla->buttons_pressed);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006279 }
6280 } else {
6281 pr_err("%s: Bad tabla private data\n", __func__);
6282 }
6283
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006284 pr_debug("%s: leave\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07006285 wcd9xxx_unlock_sleep(core);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006286}
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07006287
Joonwoo Parke067b232012-06-14 13:11:30 -07006288static u16 tabla_get_cfilt_reg(struct snd_soc_codec *codec, u8 cfilt)
6289{
6290 u16 reg;
6291
6292 switch (cfilt) {
6293 case TABLA_CFILT1_SEL:
6294 reg = TABLA_A_MICB_CFILT_1_CTL;
6295 break;
6296 case TABLA_CFILT2_SEL:
6297 reg = TABLA_A_MICB_CFILT_2_CTL;
6298 break;
6299 case TABLA_CFILT3_SEL:
6300 reg = TABLA_A_MICB_CFILT_3_CTL;
6301 break;
6302 default:
6303 BUG();
6304 }
6305 return reg;
6306}
6307
Joonwoo Park0976d012011-12-22 11:48:18 -08006308void tabla_mbhc_cal(struct snd_soc_codec *codec)
6309{
6310 struct tabla_priv *tabla;
6311 struct tabla_mbhc_btn_detect_cfg *btn_det;
Joonwoo Parke067b232012-06-14 13:11:30 -07006312 u8 cfilt_mode, micbias2_cfilt_mode, bg_mode;
Joonwoo Park0976d012011-12-22 11:48:18 -08006313 u8 ncic, nmeas, navg;
6314 u32 mclk_rate;
6315 u32 dce_wait, sta_wait;
6316 u8 *n_cic;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006317 void *calibration;
Joonwoo Parke067b232012-06-14 13:11:30 -07006318 u16 bias2_ctl;
Joonwoo Park0976d012011-12-22 11:48:18 -08006319
6320 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006321 calibration = tabla->mbhc_cfg.calibration;
6322
Joonwoo Parkf6574c72012-10-10 17:29:57 -07006323 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006324 tabla_turn_onoff_rel_detection(codec, false);
Joonwoo Park0976d012011-12-22 11:48:18 -08006325
6326 /* First compute the DCE / STA wait times
6327 * depending on tunable parameters.
6328 * The value is computed in microseconds
6329 */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006330 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08006331 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
Joonwoo Park107edf02012-01-11 11:42:24 -08006332 ncic = n_cic[tabla_codec_mclk_index(tabla)];
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006333 nmeas = TABLA_MBHC_CAL_BTN_DET_PTR(calibration)->n_meas;
6334 navg = TABLA_MBHC_CAL_GENERAL_PTR(calibration)->mbhc_navg;
6335 mclk_rate = tabla->mbhc_cfg.mclk_rate;
Joonwoo Park433149a2012-01-11 09:53:54 -08006336 dce_wait = (1000 * 512 * ncic * (nmeas + 1)) / (mclk_rate / 1000);
6337 sta_wait = (1000 * 128 * (navg + 1)) / (mclk_rate / 1000);
Joonwoo Park0976d012011-12-22 11:48:18 -08006338
6339 tabla->mbhc_data.t_dce = dce_wait;
6340 tabla->mbhc_data.t_sta = sta_wait;
6341
6342 /* LDOH and CFILT are already configured during pdata handling.
6343 * Only need to make sure CFILT and bandgap are in Fast mode.
6344 * Need to restore defaults once calculation is done.
6345 */
6346 cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl);
Joonwoo Parke067b232012-06-14 13:11:30 -07006347 micbias2_cfilt_mode =
6348 snd_soc_read(codec, tabla_get_cfilt_reg(codec,
6349 tabla->pdata->micbias.bias2_cfilt_sel));
6350 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40,
6351 TABLA_CFILT_FAST_MODE);
6352 snd_soc_update_bits(codec,
6353 tabla_get_cfilt_reg(codec,
6354 tabla->pdata->micbias.bias2_cfilt_sel),
6355 0x40, TABLA_CFILT_FAST_MODE);
6356
Joonwoo Park0976d012011-12-22 11:48:18 -08006357 bg_mode = snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02,
6358 0x02);
6359
6360 /* Micbias, CFILT, LDOH, MBHC MUX mode settings
6361 * to perform ADC calibration
6362 */
6363 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x60,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006364 tabla->mbhc_cfg.micbias << 5);
Joonwoo Park0976d012011-12-22 11:48:18 -08006365 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
6366 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x60, 0x60);
6367 snd_soc_write(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x78);
6368 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x04);
6369
Joonwoo Parke067b232012-06-14 13:11:30 -07006370 /* MICBIAS2 routing for calibration */
6371 bias2_ctl = snd_soc_read(codec, TABLA_A_MICB_2_CTL);
6372 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, TABLA_MICBIAS2);
6373 snd_soc_write(codec, TABLA_A_MICB_2_CTL,
6374 snd_soc_read(codec, tabla->mbhc_bias_regs.ctl_reg));
6375
Joonwoo Park0976d012011-12-22 11:48:18 -08006376 /* DCE measurement for 0 volts */
6377 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
6378 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
6379 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
Joonwoo Park0976d012011-12-22 11:48:18 -08006380 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81);
6381 usleep_range(100, 100);
6382 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
6383 usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce);
6384 tabla->mbhc_data.dce_z = tabla_codec_read_dce_result(codec);
6385
6386 /* DCE measurment for MB voltage */
6387 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
6388 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
6389 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82);
6390 usleep_range(100, 100);
6391 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
6392 usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce);
6393 tabla->mbhc_data.dce_mb = tabla_codec_read_dce_result(codec);
6394
6395 /* Sta measuremnt for 0 volts */
6396 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
6397 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
6398 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
Joonwoo Park0976d012011-12-22 11:48:18 -08006399 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81);
6400 usleep_range(100, 100);
6401 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
6402 usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta);
6403 tabla->mbhc_data.sta_z = tabla_codec_read_sta_result(codec);
6404
6405 /* STA Measurement for MB Voltage */
6406 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82);
6407 usleep_range(100, 100);
6408 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
6409 usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta);
6410 tabla->mbhc_data.sta_mb = tabla_codec_read_sta_result(codec);
6411
6412 /* Restore default settings. */
Joonwoo Parke067b232012-06-14 13:11:30 -07006413 snd_soc_write(codec, TABLA_A_MICB_2_CTL, bias2_ctl);
6414 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03,
6415 tabla->mbhc_cfg.micbias);
6416
Joonwoo Park0976d012011-12-22 11:48:18 -08006417 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00);
Joonwoo Parke067b232012-06-14 13:11:30 -07006418 snd_soc_update_bits(codec,
6419 tabla_get_cfilt_reg(codec,
6420 tabla->pdata->micbias.bias2_cfilt_sel), 0x40,
6421 micbias2_cfilt_mode);
Joonwoo Park0976d012011-12-22 11:48:18 -08006422 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40,
6423 cfilt_mode);
6424 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, bg_mode);
6425
6426 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
6427 usleep_range(100, 100);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006428
Joonwoo Parkf6574c72012-10-10 17:29:57 -07006429 wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006430 tabla_turn_onoff_rel_detection(codec, true);
Joonwoo Park0976d012011-12-22 11:48:18 -08006431}
6432
6433void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg* btn_det,
6434 const enum tabla_mbhc_btn_det_mem mem)
6435{
6436 void *ret = &btn_det->_v_btn_low;
6437
6438 switch (mem) {
6439 case TABLA_BTN_DET_GAIN:
6440 ret += sizeof(btn_det->_n_cic);
6441 case TABLA_BTN_DET_N_CIC:
6442 ret += sizeof(btn_det->_n_ready);
Joonwoo Parkc0672392012-01-11 11:03:14 -08006443 case TABLA_BTN_DET_N_READY:
Joonwoo Park0976d012011-12-22 11:48:18 -08006444 ret += sizeof(btn_det->_v_btn_high[0]) * btn_det->num_btn;
6445 case TABLA_BTN_DET_V_BTN_HIGH:
6446 ret += sizeof(btn_det->_v_btn_low[0]) * btn_det->num_btn;
6447 case TABLA_BTN_DET_V_BTN_LOW:
6448 /* do nothing */
6449 break;
6450 default:
6451 ret = NULL;
6452 }
6453
6454 return ret;
6455}
6456
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006457static s16 tabla_scale_v_micb_vddio(struct tabla_priv *tabla, int v,
6458 bool tovddio)
6459{
6460 int r;
6461 int vddio_k, mb_k;
6462 vddio_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v,
6463 VDDIO_MICBIAS_MV);
6464 mb_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v,
6465 tabla->mbhc_data.micb_mv);
6466 if (tovddio)
6467 r = v * vddio_k / mb_k;
6468 else
6469 r = v * mb_k / vddio_k;
6470 return r;
6471}
6472
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006473static void tabla_mbhc_calc_rel_thres(struct snd_soc_codec *codec, s16 mv)
6474{
6475 s16 deltamv;
6476 struct tabla_priv *tabla;
6477 struct tabla_mbhc_btn_detect_cfg *btn_det;
6478
6479 tabla = snd_soc_codec_get_drvdata(codec);
6480 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
6481
6482 tabla->mbhc_data.v_b1_h =
6483 tabla_codec_v_sta_dce(codec, DCE,
6484 mv + btn_det->v_btn_press_delta_cic);
6485
6486 tabla->mbhc_data.v_brh = tabla->mbhc_data.v_b1_h;
6487
6488 tabla->mbhc_data.v_brl = TABLA_MBHC_BUTTON_MIN;
6489
6490 deltamv = mv + btn_det->v_btn_press_delta_sta;
6491 tabla->mbhc_data.v_b1_hu = tabla_codec_v_sta_dce(codec, STA, deltamv);
6492
6493 deltamv = mv + btn_det->v_btn_press_delta_cic;
6494 tabla->mbhc_data.v_b1_huc = tabla_codec_v_sta_dce(codec, DCE, deltamv);
6495}
6496
6497static void tabla_mbhc_set_rel_thres(struct snd_soc_codec *codec, s16 mv)
6498{
6499 tabla_mbhc_calc_rel_thres(codec, mv);
6500 tabla_codec_calibrate_rel(codec);
6501}
6502
6503static s16 tabla_mbhc_highest_btn_mv(struct snd_soc_codec *codec)
6504{
6505 struct tabla_priv *tabla;
6506 struct tabla_mbhc_btn_detect_cfg *btn_det;
6507 u16 *btn_high;
6508
6509 tabla = snd_soc_codec_get_drvdata(codec);
6510 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
6511 btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_HIGH);
6512
6513 return btn_high[btn_det->num_btn - 1];
6514}
6515
Joonwoo Park0976d012011-12-22 11:48:18 -08006516static void tabla_mbhc_calc_thres(struct snd_soc_codec *codec)
6517{
6518 struct tabla_priv *tabla;
Joonwoo Park0976d012011-12-22 11:48:18 -08006519 struct tabla_mbhc_btn_detect_cfg *btn_det;
6520 struct tabla_mbhc_plug_type_cfg *plug_type;
Joonwoo Parkc0672392012-01-11 11:03:14 -08006521 u8 *n_ready;
Joonwoo Park0976d012011-12-22 11:48:18 -08006522
6523 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006524 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
6525 plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08006526
Joonwoo Parkc0672392012-01-11 11:03:14 -08006527 n_ready = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_READY);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006528 if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) {
Joonwoo Park03324832012-03-19 19:36:16 -07006529 tabla->mbhc_data.npoll = 4;
Joonwoo Park0976d012011-12-22 11:48:18 -08006530 tabla->mbhc_data.nbounce_wait = 30;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006531 } else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) {
Joonwoo Park0976d012011-12-22 11:48:18 -08006532 tabla->mbhc_data.npoll = 7;
6533 tabla->mbhc_data.nbounce_wait = 23;
Joonwoo Parkc0672392012-01-11 11:03:14 -08006534 }
Joonwoo Park0976d012011-12-22 11:48:18 -08006535
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006536 tabla->mbhc_data.t_sta_dce = ((1000 * 256) /
6537 (tabla->mbhc_cfg.mclk_rate / 1000) *
Joonwoo Parkc0672392012-01-11 11:03:14 -08006538 n_ready[tabla_codec_mclk_index(tabla)]) +
6539 10;
Joonwoo Park0976d012011-12-22 11:48:18 -08006540 tabla->mbhc_data.v_ins_hu =
6541 tabla_codec_v_sta_dce(codec, STA, plug_type->v_hs_max);
6542 tabla->mbhc_data.v_ins_h =
6543 tabla_codec_v_sta_dce(codec, DCE, plug_type->v_hs_max);
6544
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006545 tabla->mbhc_data.v_inval_ins_low = TABLA_MBHC_FAKE_INSERT_LOW;
6546 if (tabla->mbhc_cfg.gpio)
6547 tabla->mbhc_data.v_inval_ins_high =
6548 TABLA_MBHC_FAKE_INSERT_HIGH;
6549 else
6550 tabla->mbhc_data.v_inval_ins_high =
6551 TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO;
6552
6553 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
6554 tabla->mbhc_data.adj_v_hs_max =
6555 tabla_scale_v_micb_vddio(tabla, plug_type->v_hs_max, true);
6556 tabla->mbhc_data.adj_v_ins_hu =
6557 tabla_codec_v_sta_dce(codec, STA,
6558 tabla->mbhc_data.adj_v_hs_max);
6559 tabla->mbhc_data.adj_v_ins_h =
6560 tabla_codec_v_sta_dce(codec, DCE,
6561 tabla->mbhc_data.adj_v_hs_max);
6562 tabla->mbhc_data.v_inval_ins_low =
6563 tabla_scale_v_micb_vddio(tabla,
6564 tabla->mbhc_data.v_inval_ins_low,
6565 false);
6566 tabla->mbhc_data.v_inval_ins_high =
6567 tabla_scale_v_micb_vddio(tabla,
6568 tabla->mbhc_data.v_inval_ins_high,
6569 false);
6570 }
6571
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006572 tabla_mbhc_calc_rel_thres(codec, tabla_mbhc_highest_btn_mv(codec));
Joonwoo Park0976d012011-12-22 11:48:18 -08006573
6574 tabla->mbhc_data.v_no_mic =
6575 tabla_codec_v_sta_dce(codec, STA, plug_type->v_no_mic);
6576}
6577
6578void tabla_mbhc_init(struct snd_soc_codec *codec)
6579{
6580 struct tabla_priv *tabla;
6581 struct tabla_mbhc_general_cfg *generic;
6582 struct tabla_mbhc_btn_detect_cfg *btn_det;
6583 int n;
Joonwoo Park0976d012011-12-22 11:48:18 -08006584 u8 *n_cic, *gain;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306585 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Joonwoo Park0976d012011-12-22 11:48:18 -08006586
6587 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006588 generic = TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
6589 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08006590
Joonwoo Park0976d012011-12-22 11:48:18 -08006591 for (n = 0; n < 8; n++) {
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08006592 if ((!TABLA_IS_1_X(tabla_core->version)) || n != 7) {
Joonwoo Park0976d012011-12-22 11:48:18 -08006593 snd_soc_update_bits(codec,
6594 TABLA_A_CDC_MBHC_FEATURE_B1_CFG,
6595 0x07, n);
6596 snd_soc_write(codec, TABLA_A_CDC_MBHC_FEATURE_B2_CFG,
6597 btn_det->c[n]);
6598 }
6599 }
6600 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x07,
6601 btn_det->nc);
6602
6603 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
6604 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL, 0xFF,
Joonwoo Park107edf02012-01-11 11:42:24 -08006605 n_cic[tabla_codec_mclk_index(tabla)]);
Joonwoo Park0976d012011-12-22 11:48:18 -08006606
6607 gain = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_GAIN);
Joonwoo Park107edf02012-01-11 11:42:24 -08006608 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x78,
6609 gain[tabla_codec_mclk_index(tabla)] << 3);
Joonwoo Park0976d012011-12-22 11:48:18 -08006610
6611 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x70,
6612 generic->mbhc_nsa << 4);
6613
6614 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x0F,
6615 btn_det->n_meas);
6616
6617 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B5_CTL, generic->mbhc_navg);
6618
6619 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x80, 0x80);
6620
6621 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x78,
6622 btn_det->mbhc_nsc << 3);
6623
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08006624 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x03,
6625 TABLA_MICBIAS2);
Joonwoo Park0976d012011-12-22 11:48:18 -08006626
6627 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, 0x02);
Joonwoo Park03324832012-03-19 19:36:16 -07006628
6629 snd_soc_update_bits(codec, TABLA_A_MBHC_SCALING_MUX_2, 0xF0, 0xF0);
Joonwoo Parke067b232012-06-14 13:11:30 -07006630
6631 /* override mbhc's micbias */
6632 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03,
6633 tabla->mbhc_cfg.micbias);
Joonwoo Park0976d012011-12-22 11:48:18 -08006634}
6635
Patrick Lai64b43262011-12-06 17:29:15 -08006636static bool tabla_mbhc_fw_validate(const struct firmware *fw)
6637{
6638 u32 cfg_offset;
6639 struct tabla_mbhc_imped_detect_cfg *imped_cfg;
6640 struct tabla_mbhc_btn_detect_cfg *btn_cfg;
6641
6642 if (fw->size < TABLA_MBHC_CAL_MIN_SIZE)
6643 return false;
6644
6645 /* previous check guarantees that there is enough fw data up
6646 * to num_btn
6647 */
6648 btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(fw->data);
6649 cfg_offset = (u32) ((void *) btn_cfg - (void *) fw->data);
6650 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_BTN_SZ(btn_cfg)))
6651 return false;
6652
6653 /* previous check guarantees that there is enough fw data up
6654 * to start of impedance detection configuration
6655 */
6656 imped_cfg = TABLA_MBHC_CAL_IMPED_DET_PTR(fw->data);
6657 cfg_offset = (u32) ((void *) imped_cfg - (void *) fw->data);
6658
6659 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_MIN_SZ))
6660 return false;
6661
6662 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_SZ(imped_cfg)))
6663 return false;
6664
6665 return true;
6666}
Joonwoo Park03324832012-03-19 19:36:16 -07006667
Joonwoo Parkfee17432012-04-16 16:33:55 -07006668/* called under codec_resource_lock acquisition */
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006669static int tabla_determine_button(const struct tabla_priv *priv,
Joonwoo Parkfee17432012-04-16 16:33:55 -07006670 const s32 micmv)
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006671{
6672 s16 *v_btn_low, *v_btn_high;
6673 struct tabla_mbhc_btn_detect_cfg *btn_det;
6674 int i, btn = -1;
6675
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006676 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006677 v_btn_low = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_LOW);
6678 v_btn_high = tabla_mbhc_cal_btn_det_mp(btn_det,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306679 TABLA_BTN_DET_V_BTN_HIGH);
Joonwoo Parkfee17432012-04-16 16:33:55 -07006680
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006681 for (i = 0; i < btn_det->num_btn; i++) {
Joonwoo Parkfee17432012-04-16 16:33:55 -07006682 if ((v_btn_low[i] <= micmv) && (v_btn_high[i] >= micmv)) {
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006683 btn = i;
6684 break;
6685 }
6686 }
6687
6688 if (btn == -1)
6689 pr_debug("%s: couldn't find button number for mic mv %d\n",
Joonwoo Parkfee17432012-04-16 16:33:55 -07006690 __func__, micmv);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006691
6692 return btn;
6693}
6694
6695static int tabla_get_button_mask(const int btn)
6696{
6697 int mask = 0;
6698 switch (btn) {
6699 case 0:
6700 mask = SND_JACK_BTN_0;
6701 break;
6702 case 1:
6703 mask = SND_JACK_BTN_1;
6704 break;
6705 case 2:
6706 mask = SND_JACK_BTN_2;
6707 break;
6708 case 3:
6709 mask = SND_JACK_BTN_3;
6710 break;
6711 case 4:
6712 mask = SND_JACK_BTN_4;
6713 break;
6714 case 5:
6715 mask = SND_JACK_BTN_5;
6716 break;
6717 case 6:
6718 mask = SND_JACK_BTN_6;
6719 break;
6720 case 7:
6721 mask = SND_JACK_BTN_7;
6722 break;
6723 }
6724 return mask;
6725}
6726
Bradley Rubincb1e2732011-06-23 16:49:20 -07006727static irqreturn_t tabla_dce_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006728{
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006729 int i, mask;
Joonwoo Parkfee17432012-04-16 16:33:55 -07006730 short dce, sta;
Joonwoo Park12334832012-07-23 19:27:52 -07006731 s32 mv, mv_s, stamv, stamv_s;
Joonwoo Parkfee17432012-04-16 16:33:55 -07006732 bool vddio;
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006733 u16 *btn_high;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006734 int btn = -1, meas = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006735 struct tabla_priv *priv = data;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006736 const struct tabla_mbhc_btn_detect_cfg *d =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006737 TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006738 short btnmeas[d->n_btn_meas + 1];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006739 struct snd_soc_codec *codec = priv->codec;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306740 struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent);
Joonwoo Park03324832012-03-19 19:36:16 -07006741 int n_btn_meas = d->n_btn_meas;
6742 u8 mbhc_status = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_STATUS) & 0x3E;
Bradley Rubincb1e2732011-06-23 16:49:20 -07006743
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006744 pr_debug("%s: enter\n", __func__);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006745
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006746 btn_high = tabla_mbhc_cal_btn_det_mp(d, TABLA_BTN_DET_V_BTN_HIGH);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006747 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
6748 if (priv->mbhc_state == MBHC_STATE_POTENTIAL_RECOVERY) {
6749 pr_debug("%s: mbhc is being recovered, skip button press\n",
6750 __func__);
6751 goto done;
6752 }
6753
6754 priv->mbhc_state = MBHC_STATE_POTENTIAL;
6755
6756 if (!priv->mbhc_polling_active) {
6757 pr_warn("%s: mbhc polling is not active, skip button press\n",
6758 __func__);
6759 goto done;
6760 }
Joonwoo Park03324832012-03-19 19:36:16 -07006761
6762 dce = tabla_codec_read_dce_result(codec);
6763 mv = tabla_codec_sta_dce_v(codec, 1, dce);
6764
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006765 /* If GPIO interrupt already kicked in, ignore button press */
6766 if (priv->in_gpio_handler) {
6767 pr_debug("%s: GPIO State Changed, ignore button press\n",
6768 __func__);
6769 btn = -1;
6770 goto done;
6771 }
Simmi Pateriya71d63872012-11-08 01:06:30 +05306772 vddio = !priv->mbhc_cfg.micbias_always_on &&
6773 (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
Joonwoo Parkfee17432012-04-16 16:33:55 -07006774 priv->mbhc_micbias_switched);
6775 mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv;
6776
Joonwoo Park03324832012-03-19 19:36:16 -07006777 if (mbhc_status != TABLA_MBHC_STATUS_REL_DETECTION) {
6778 if (priv->mbhc_last_resume &&
6779 !time_after(jiffies, priv->mbhc_last_resume + HZ)) {
6780 pr_debug("%s: Button is already released shortly after "
6781 "resume\n", __func__);
6782 n_btn_meas = 0;
Joonwoo Park03324832012-03-19 19:36:16 -07006783 }
6784 }
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07006785
Joonwoo Park12334832012-07-23 19:27:52 -07006786 /* save hw dce */
Joonwoo Parkfee17432012-04-16 16:33:55 -07006787 btnmeas[meas++] = tabla_determine_button(priv, mv_s);
Joonwoo Park12334832012-07-23 19:27:52 -07006788 pr_debug("%s: meas HW - DCE %x,%d,%d button %d\n", __func__,
6789 dce, mv, mv_s, btnmeas[0]);
6790 if (n_btn_meas == 0) {
6791 sta = tabla_codec_read_sta_result(codec);
6792 stamv_s = stamv = tabla_codec_sta_dce_v(codec, 0, sta);
6793 if (vddio)
6794 stamv_s = tabla_scale_v_micb_vddio(priv, stamv, false);
6795 btn = tabla_determine_button(priv, stamv_s);
6796 pr_debug("%s: meas HW - STA %x,%d,%d button %d\n", __func__,
6797 sta, stamv, stamv_s, btn);
6798 BUG_ON(meas != 1);
6799 if (btnmeas[0] != btn)
6800 btn = -1;
6801 }
6802
6803 /* determine pressed button */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006804 for (; ((d->n_btn_meas) && (meas < (d->n_btn_meas + 1))); meas++) {
Joonwoo Parkfee17432012-04-16 16:33:55 -07006805 dce = tabla_codec_sta_dce(codec, 1, false);
6806 mv = tabla_codec_sta_dce_v(codec, 1, dce);
6807 mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv;
6808
6809 btnmeas[meas] = tabla_determine_button(priv, mv_s);
Joonwoo Park12334832012-07-23 19:27:52 -07006810 pr_debug("%s: meas %d - DCE %x,%d,%d button %d\n",
Joonwoo Parkfee17432012-04-16 16:33:55 -07006811 __func__, meas, dce, mv, mv_s, btnmeas[meas]);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006812 /* if large enough measurements are collected,
6813 * start to check if last all n_btn_con measurements were
6814 * in same button low/high range */
6815 if (meas + 1 >= d->n_btn_con) {
6816 for (i = 0; i < d->n_btn_con; i++)
6817 if ((btnmeas[meas] < 0) ||
6818 (btnmeas[meas] != btnmeas[meas - i]))
6819 break;
6820 if (i == d->n_btn_con) {
6821 /* button pressed */
6822 btn = btnmeas[meas];
6823 break;
Joonwoo Park03324832012-03-19 19:36:16 -07006824 } else if ((n_btn_meas - meas) < (d->n_btn_con - 1)) {
6825 /* if left measurements are less than n_btn_con,
6826 * it's impossible to find button number */
6827 break;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006828 }
6829 }
Joonwoo Park8b1f0982011-12-08 17:12:45 -08006830 }
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006831
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006832 if (btn >= 0) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006833 if (priv->in_gpio_handler) {
6834 pr_debug("%s: GPIO already triggered, ignore button "
6835 "press\n", __func__);
6836 goto done;
6837 }
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006838 /* narrow down release threshold */
6839 tabla_mbhc_set_rel_thres(codec, btn_high[btn]);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006840 mask = tabla_get_button_mask(btn);
6841 priv->buttons_pressed |= mask;
Joonwoo Park03324832012-03-19 19:36:16 -07006842 wcd9xxx_lock_sleep(core);
6843 if (schedule_delayed_work(&priv->mbhc_btn_dwork,
6844 msecs_to_jiffies(400)) == 0) {
6845 WARN(1, "Button pressed twice without release"
6846 "event\n");
6847 wcd9xxx_unlock_sleep(core);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006848 }
Joonwoo Park816b8e62012-01-23 16:03:21 -08006849 } else {
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006850 pr_debug("%s: bogus button press, too short press?\n",
6851 __func__);
Joonwoo Park816b8e62012-01-23 16:03:21 -08006852 }
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006853
Joonwoo Park03324832012-03-19 19:36:16 -07006854 done:
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006855 pr_debug("%s: leave\n", __func__);
6856 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006857 return IRQ_HANDLED;
6858}
6859
Joonwoo Park03324832012-03-19 19:36:16 -07006860static int tabla_is_fake_press(struct tabla_priv *priv)
6861{
6862 int i;
6863 int r = 0;
6864 struct snd_soc_codec *codec = priv->codec;
6865 const int dces = MBHC_NUM_DCE_PLUG_DETECT;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006866 s16 mb_v, v_ins_hu, v_ins_h;
6867
6868 v_ins_hu = tabla_get_current_v_ins(priv, true);
6869 v_ins_h = tabla_get_current_v_ins(priv, false);
Joonwoo Park03324832012-03-19 19:36:16 -07006870
6871 for (i = 0; i < dces; i++) {
6872 usleep_range(10000, 10000);
6873 if (i == 0) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006874 mb_v = tabla_codec_sta_dce(codec, 0, true);
Joonwoo Park03324832012-03-19 19:36:16 -07006875 pr_debug("%s: STA[0]: %d,%d\n", __func__, mb_v,
6876 tabla_codec_sta_dce_v(codec, 0, mb_v));
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006877 if (mb_v < (s16)priv->mbhc_data.v_b1_hu ||
6878 mb_v > v_ins_hu) {
Joonwoo Park03324832012-03-19 19:36:16 -07006879 r = 1;
6880 break;
6881 }
6882 } else {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006883 mb_v = tabla_codec_sta_dce(codec, 1, true);
Joonwoo Park03324832012-03-19 19:36:16 -07006884 pr_debug("%s: DCE[%d]: %d,%d\n", __func__, i, mb_v,
6885 tabla_codec_sta_dce_v(codec, 1, mb_v));
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006886 if (mb_v < (s16)priv->mbhc_data.v_b1_h ||
6887 mb_v > v_ins_h) {
Joonwoo Park03324832012-03-19 19:36:16 -07006888 r = 1;
6889 break;
6890 }
6891 }
6892 }
6893
6894 return r;
6895}
6896
Bradley Rubincb1e2732011-06-23 16:49:20 -07006897static irqreturn_t tabla_release_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006898{
Joonwoo Parke5d3aa92012-01-11 14:47:15 -08006899 int ret;
Joonwoo Park816b8e62012-01-23 16:03:21 -08006900 struct tabla_priv *priv = data;
6901 struct snd_soc_codec *codec = priv->codec;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006902
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006903 pr_debug("%s: enter\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07006904
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006905 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
6906 priv->mbhc_state = MBHC_STATE_RELEASE;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006907
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006908 tabla_codec_drive_v_to_micbias(codec, 10000);
6909
Joonwoo Park03324832012-03-19 19:36:16 -07006910 if (priv->buttons_pressed & TABLA_JACK_BUTTON_MASK) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006911 ret = tabla_cancel_btn_work(priv);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006912 if (ret == 0) {
Joonwoo Park03324832012-03-19 19:36:16 -07006913 pr_debug("%s: Reporting long button release event\n",
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006914 __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006915 if (priv->mbhc_cfg.button_jack)
Joonwoo Park8b1f0982011-12-08 17:12:45 -08006916 tabla_snd_soc_jack_report(priv,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006917 priv->mbhc_cfg.button_jack, 0,
6918 priv->buttons_pressed);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006919 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07006920 if (tabla_is_fake_press(priv)) {
6921 pr_debug("%s: Fake button press interrupt\n",
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006922 __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006923 } else if (priv->mbhc_cfg.button_jack) {
6924 if (priv->in_gpio_handler) {
6925 pr_debug("%s: GPIO kicked in, ignore\n",
6926 __func__);
6927 } else {
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006928 pr_debug("%s: Reporting short button "
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006929 "press and release\n",
6930 __func__);
6931 tabla_snd_soc_jack_report(priv,
6932 priv->mbhc_cfg.button_jack,
6933 priv->buttons_pressed,
6934 priv->buttons_pressed);
6935 tabla_snd_soc_jack_report(priv,
6936 priv->mbhc_cfg.button_jack, 0,
6937 priv->buttons_pressed);
6938 }
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006939 }
6940 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006941
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006942 priv->buttons_pressed &= ~TABLA_JACK_BUTTON_MASK;
6943 }
6944
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006945 /* revert narrowed release threshold */
6946 tabla_mbhc_calc_rel_thres(codec, tabla_mbhc_highest_btn_mv(codec));
Joonwoo Park03324832012-03-19 19:36:16 -07006947 tabla_codec_calibrate_hs_polling(codec);
6948
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006949 if (priv->mbhc_cfg.gpio)
6950 msleep(TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS);
Joonwoo Park03324832012-03-19 19:36:16 -07006951
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006952 tabla_codec_start_hs_polling(codec);
6953
6954 pr_debug("%s: leave\n", __func__);
6955 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006956 return IRQ_HANDLED;
6957}
6958
Bradley Rubincb1e2732011-06-23 16:49:20 -07006959static void tabla_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec)
6960{
6961 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park0976d012011-12-22 11:48:18 -08006962 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006963 TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006964
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07006965 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07006966 tabla_codec_enable_config_mode(codec, 1);
6967
6968 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
6969 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x6, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006970
Joonwoo Park0976d012011-12-22 11:48:18 -08006971 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00);
6972
6973 usleep_range(generic->t_shutdown_plug_rem,
6974 generic->t_shutdown_plug_rem);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006975
6976 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0xA, 0x8);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07006977 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07006978 tabla_codec_enable_config_mode(codec, 0);
6979
6980 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x00);
6981}
6982
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006983static void tabla_codec_cleanup_hs_polling(struct snd_soc_codec *codec)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006984{
6985 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006986
6987 tabla_codec_shutdown_hs_removal_detect(codec);
6988
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07006989 if (!tabla->mclk_enabled) {
Asish Bhattacharya486745a2012-01-20 06:41:53 +05306990 tabla_codec_disable_clock_block(codec);
6991 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006992 }
6993
6994 tabla->mbhc_polling_active = false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006995 tabla->mbhc_state = MBHC_STATE_NONE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006996}
6997
Patrick Lai49efeac2011-11-03 11:01:12 -07006998static irqreturn_t tabla_hphl_ocp_irq(int irq, void *data)
6999{
7000 struct tabla_priv *tabla = data;
7001 struct snd_soc_codec *codec;
7002
7003 pr_info("%s: received HPHL OCP irq\n", __func__);
7004
7005 if (tabla) {
7006 codec = tabla->codec;
Patrick Laic2d833d2012-07-06 22:42:52 -07007007 if ((tabla->hphlocp_cnt < TABLA_OCP_ATTEMPT) &&
7008 (!tabla->hphrocp_cnt)) {
Patrick Laic7cae882011-11-18 11:52:49 -08007009 pr_info("%s: retry\n", __func__);
Patrick Laic2d833d2012-07-06 22:42:52 -07007010 tabla->hphlocp_cnt++;
Patrick Laic7cae882011-11-18 11:52:49 -08007011 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
7012 0x00);
7013 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
7014 0x10);
7015 } else {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307016 wcd9xxx_disable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007017 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Patrick Laic7cae882011-11-18 11:52:49 -08007018 tabla->hph_status |= SND_JACK_OC_HPHL;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007019 if (tabla->mbhc_cfg.headset_jack)
Patrick Laic7cae882011-11-18 11:52:49 -08007020 tabla_snd_soc_jack_report(tabla,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007021 tabla->mbhc_cfg.headset_jack,
7022 tabla->hph_status,
7023 TABLA_JACK_MASK);
Patrick Lai49efeac2011-11-03 11:01:12 -07007024 }
7025 } else {
7026 pr_err("%s: Bad tabla private data\n", __func__);
7027 }
7028
7029 return IRQ_HANDLED;
7030}
7031
7032static irqreturn_t tabla_hphr_ocp_irq(int irq, void *data)
7033{
7034 struct tabla_priv *tabla = data;
7035 struct snd_soc_codec *codec;
7036
7037 pr_info("%s: received HPHR OCP irq\n", __func__);
7038
7039 if (tabla) {
7040 codec = tabla->codec;
Patrick Laic2d833d2012-07-06 22:42:52 -07007041 if ((tabla->hphrocp_cnt < TABLA_OCP_ATTEMPT) &&
7042 (!tabla->hphlocp_cnt)) {
Patrick Laic7cae882011-11-18 11:52:49 -08007043 pr_info("%s: retry\n", __func__);
Patrick Laic2d833d2012-07-06 22:42:52 -07007044 tabla->hphrocp_cnt++;
Patrick Laic7cae882011-11-18 11:52:49 -08007045 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
7046 0x00);
7047 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
7048 0x10);
7049 } else {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307050 wcd9xxx_disable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007051 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Patrick Laic7cae882011-11-18 11:52:49 -08007052 tabla->hph_status |= SND_JACK_OC_HPHR;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007053 if (tabla->mbhc_cfg.headset_jack)
Patrick Laic7cae882011-11-18 11:52:49 -08007054 tabla_snd_soc_jack_report(tabla,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007055 tabla->mbhc_cfg.headset_jack,
7056 tabla->hph_status,
7057 TABLA_JACK_MASK);
Patrick Lai49efeac2011-11-03 11:01:12 -07007058 }
7059 } else {
7060 pr_err("%s: Bad tabla private data\n", __func__);
7061 }
7062
7063 return IRQ_HANDLED;
7064}
7065
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007066static bool tabla_is_inval_ins_range(struct snd_soc_codec *codec,
7067 s32 mic_volt, bool highhph, bool *highv)
Joonwoo Park03324832012-03-19 19:36:16 -07007068{
7069 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007070 bool invalid = false;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007071 s16 v_hs_max;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007072
7073 /* Perform this check only when the high voltage headphone
7074 * needs to be considered as invalid
7075 */
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007076 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007077 *highv = mic_volt > v_hs_max;
7078 if (!highhph && *highv)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007079 invalid = true;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007080 else if (mic_volt < tabla->mbhc_data.v_inval_ins_high &&
7081 (mic_volt > tabla->mbhc_data.v_inval_ins_low))
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007082 invalid = true;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007083
7084 return invalid;
7085}
7086
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007087static bool tabla_is_inval_ins_delta(struct snd_soc_codec *codec,
7088 int mic_volt, int mic_volt_prev,
7089 int threshold)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007090{
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007091 return abs(mic_volt - mic_volt_prev) > threshold;
Joonwoo Park03324832012-03-19 19:36:16 -07007092}
7093
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007094/* called under codec_resource_lock acquisition */
7095void tabla_find_plug_and_report(struct snd_soc_codec *codec,
7096 enum tabla_mbhc_plug_type plug_type)
Joonwoo Park03324832012-03-19 19:36:16 -07007097{
7098 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007099
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007100 pr_debug("%s: enter current_plug(%d) new_plug(%d)\n",
7101 __func__, tabla->current_plug, plug_type);
7102
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007103 if (plug_type == PLUG_TYPE_HEADPHONE &&
7104 tabla->current_plug == PLUG_TYPE_NONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007105 /* Nothing was reported previously
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007106 * report a headphone or unsupported
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007107 */
7108 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
7109 tabla_codec_cleanup_hs_polling(codec);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007110 } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) {
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007111 if (!tabla->mbhc_cfg.detect_extn_cable) {
7112 if (tabla->current_plug == PLUG_TYPE_HEADSET)
7113 tabla_codec_report_plug(codec, 0,
7114 SND_JACK_HEADSET);
7115 else if (tabla->current_plug == PLUG_TYPE_HEADPHONE)
7116 tabla_codec_report_plug(codec, 0,
7117 SND_JACK_HEADPHONE);
7118 }
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007119 tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED);
7120 tabla_codec_cleanup_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007121 } else if (plug_type == PLUG_TYPE_HEADSET) {
7122 /* If Headphone was reported previously, this will
7123 * only report the mic line
7124 */
7125 tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET);
Simmi Pateriya21375012012-11-26 23:06:01 +05307126 if (!tabla->mbhc_micbias_switched &&
7127 tabla_is_hph_pa_on(codec)) {
7128 /*If the headphone path is on, switch the micbias
7129 to VDDIO to avoid noise due to button polling */
7130 tabla_codec_switch_micbias(codec, 1);
7131 pr_debug("%s: HPH path is still up\n", __func__);
7132 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007133 msleep(100);
7134 tabla_codec_start_hs_polling(codec);
7135 } else if (plug_type == PLUG_TYPE_HIGH_HPH) {
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007136 if (tabla->mbhc_cfg.detect_extn_cable) {
7137 /* High impedance device found. Report as LINEOUT*/
7138 tabla_codec_report_plug(codec, 1, SND_JACK_LINEOUT);
7139 tabla_codec_cleanup_hs_polling(codec);
7140 pr_debug("%s: setup mic trigger for further detection\n",
7141 __func__);
7142 tabla->lpi_enabled = true;
7143 /*
7144 * Do not enable HPHL trigger. If playback is active,
7145 * it might lead to continuous false HPHL triggers
7146 */
7147 tabla_codec_enable_hs_detect(codec, 1,
7148 MBHC_USE_MB_TRIGGER,
7149 false);
7150 } else {
7151 if (tabla->current_plug == PLUG_TYPE_NONE)
7152 tabla_codec_report_plug(codec, 1,
7153 SND_JACK_HEADPHONE);
7154 tabla_codec_cleanup_hs_polling(codec);
7155 pr_debug("setup mic trigger for further detection\n");
7156 tabla->lpi_enabled = true;
7157 tabla_codec_enable_hs_detect(codec, 1,
7158 MBHC_USE_MB_TRIGGER |
7159 MBHC_USE_HPHL_TRIGGER,
7160 false);
7161 }
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007162 } else {
7163 WARN(1, "Unexpected current plug_type %d, plug_type %d\n",
7164 tabla->current_plug, plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007165 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007166 pr_debug("%s: leave\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007167}
7168
7169/* should be called under interrupt context that hold suspend */
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007170static void tabla_schedule_hs_detect_plug(struct tabla_priv *tabla,
7171 struct work_struct *correct_plug_work)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007172{
7173 pr_debug("%s: scheduling tabla_hs_correct_gpio_plug\n", __func__);
7174 tabla->hs_detect_work_stop = false;
7175 wcd9xxx_lock_sleep(tabla->codec->control_data);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007176 schedule_work(correct_plug_work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007177}
7178
7179/* called under codec_resource_lock acquisition */
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007180static void tabla_cancel_hs_detect_plug(struct tabla_priv *tabla,
7181 struct work_struct *correct_plug_work)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007182{
7183 pr_debug("%s: canceling hs_correct_plug_work\n", __func__);
7184 tabla->hs_detect_work_stop = true;
7185 wmb();
7186 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007187 if (cancel_work_sync(correct_plug_work)) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007188 pr_debug("%s: hs_correct_plug_work is canceled\n", __func__);
7189 wcd9xxx_unlock_sleep(tabla->codec->control_data);
7190 }
7191 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
7192}
7193
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007194static bool tabla_hs_gpio_level_remove(struct tabla_priv *tabla)
7195{
7196 return (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) !=
7197 tabla->mbhc_cfg.gpio_level_insert);
7198}
7199
Joonwoo Park41956722012-04-18 13:13:07 -07007200/* called under codec_resource_lock acquisition */
7201static void tabla_codec_hphr_gnd_switch(struct snd_soc_codec *codec, bool on)
7202{
7203 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, on);
7204 if (on)
7205 usleep_range(5000, 5000);
7206}
7207
Simmi Pateriyad60186a2012-11-27 13:50:11 +05307208
7209static void tabla_codec_onoff_vddio_switch(struct snd_soc_codec *codec, bool on)
7210{
7211 bool override;
7212 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
7213
7214 pr_debug("%s: enter\n", __func__);
7215 if (on) {
7216 override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04;
7217 if (!override)
7218 tabla_turn_onoff_override(codec, true);
7219
7220 /* enable the vddio switch */
7221 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
7222 0x91, 0x81);
7223
7224 /* deroute the override from MicBias2 to MicBias4 */
7225 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC,
7226 0x03, 0x03);
7227
7228 usleep_range(MBHC_VDDIO_SWITCH_WAIT_MS * 1000,
7229 MBHC_VDDIO_SWITCH_WAIT_MS * 1000);
7230
7231 if (!override)
7232 tabla_turn_onoff_override(codec, false);
7233 tabla->mbhc_micbias_switched = true;
7234 pr_debug("%s: VDDIO switch enabled\n", __func__);
7235
7236 } else {
7237
7238 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
7239 0x91, 0x00);
7240
7241 /* reroute the override to MicBias2 */
7242 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC,
7243 0x03, 0x01);
7244
7245 tabla->mbhc_micbias_switched = false;
7246 pr_debug("%s: VDDIO switch disabled\n", __func__);
7247 }
7248}
7249
Joonwoo Park41956722012-04-18 13:13:07 -07007250/* called under codec_resource_lock acquisition and mbhc override = 1 */
7251static enum tabla_mbhc_plug_type
7252tabla_codec_get_plug_type(struct snd_soc_codec *codec, bool highhph)
7253{
7254 int i;
7255 bool gndswitch, vddioswitch;
7256 int scaled;
7257 struct tabla_mbhc_plug_type_cfg *plug_type_ptr;
7258 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Simmi Pateriya71d63872012-11-08 01:06:30 +05307259 const bool vddio = !tabla->mbhc_cfg.micbias_always_on &&
7260 (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV);
7261 int num_det = (MBHC_NUM_DCE_PLUG_DETECT + vddio);
Joonwoo Park41956722012-04-18 13:13:07 -07007262 enum tabla_mbhc_plug_type plug_type[num_det];
7263 s16 mb_v[num_det];
7264 s32 mic_mv[num_det];
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007265 bool inval;
Ravi Kumar Alamanda1c713b22012-09-27 17:14:27 -07007266 bool highdelta = false;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007267 bool ahighv = false, highv;
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07007268 bool gndmicswapped = false;
Joonwoo Park41956722012-04-18 13:13:07 -07007269
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007270 pr_debug("%s: enter\n", __func__);
7271
Joonwoo Park41956722012-04-18 13:13:07 -07007272 /* make sure override is on */
7273 WARN_ON(!(snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04));
7274
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007275 /* GND and MIC swap detection requires at least 2 rounds of DCE */
7276 BUG_ON(num_det < 2);
7277
7278 plug_type_ptr =
7279 TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
7280
7281 plug_type[0] = PLUG_TYPE_INVALID;
7282
Joonwoo Park41956722012-04-18 13:13:07 -07007283 /* performs DCEs for N times
7284 * 1st: check if voltage is in invalid range
7285 * 2nd - N-2nd: check voltage range and delta
7286 * N-1st: check voltage range, delta with HPHR GND switch
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07007287 * Nth: check voltage range with VDDIO switch */
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007288 for (i = 0; i < num_det; i++) {
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07007289 gndswitch = (i == (num_det - 2));
Simmi Pateriyad60186a2012-11-27 13:50:11 +05307290 vddioswitch = (i == (num_det - 1));
Joonwoo Park41956722012-04-18 13:13:07 -07007291 if (i == 0) {
7292 mb_v[i] = tabla_codec_setup_hs_polling(codec);
7293 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007294 inval = tabla_is_inval_ins_range(codec, mic_mv[i],
7295 highhph, &highv);
7296 ahighv |= highv;
Joonwoo Park41956722012-04-18 13:13:07 -07007297 scaled = mic_mv[i];
Joonwoo Park41956722012-04-18 13:13:07 -07007298 } else {
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007299 if (vddioswitch)
Simmi Pateriyad60186a2012-11-27 13:50:11 +05307300 tabla_codec_onoff_vddio_switch(codec, true);
7301
Joonwoo Park41956722012-04-18 13:13:07 -07007302 if (gndswitch)
7303 tabla_codec_hphr_gnd_switch(codec, true);
7304 mb_v[i] = __tabla_codec_sta_dce(codec, 1, true, true);
7305 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007306 if (vddioswitch)
7307 scaled = tabla_scale_v_micb_vddio(tabla,
Joonwoo Park41956722012-04-18 13:13:07 -07007308 mic_mv[i],
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007309 false);
7310 else
7311 scaled = mic_mv[i];
7312 /* !gndswitch & vddioswitch means the previous DCE
7313 * was done with gndswitch, don't compare with DCE
7314 * with gndswitch */
7315 highdelta = tabla_is_inval_ins_delta(codec, scaled,
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07007316 mic_mv[i - 1],
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007317 TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV);
7318 inval = (tabla_is_inval_ins_range(codec, mic_mv[i],
7319 highhph, &highv) ||
7320 highdelta);
7321 ahighv |= highv;
Joonwoo Park41956722012-04-18 13:13:07 -07007322 if (gndswitch)
7323 tabla_codec_hphr_gnd_switch(codec, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007324 if (vddioswitch)
Simmi Pateriyad60186a2012-11-27 13:50:11 +05307325 tabla_codec_onoff_vddio_switch(codec, false);
Joonwoo Park41956722012-04-18 13:13:07 -07007326 }
7327 pr_debug("%s: DCE #%d, %04x, V %d, scaled V %d, GND %d, "
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007328 "VDDIO %d, inval %d\n", __func__,
Joonwoo Park41956722012-04-18 13:13:07 -07007329 i + 1, mb_v[i] & 0xffff, mic_mv[i], scaled, gndswitch,
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007330 vddioswitch, inval);
7331 /* don't need to run further DCEs */
Ravi Kumar Alamanda1c713b22012-09-27 17:14:27 -07007332 if ((ahighv || !vddioswitch) && inval)
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007333 break;
7334 mic_mv[i] = scaled;
Ravi Kumar Alamanda1c713b22012-09-27 17:14:27 -07007335
7336 /*
7337 * claim UNSUPPORTED plug insertion when
7338 * good headset is detected but HPHR GND switch makes
7339 * delta difference
7340 */
7341 if (i == (num_det - 2) && highdelta && !ahighv)
7342 gndmicswapped = true;
7343 else if (i == (num_det - 1) && inval) {
7344 if (gndmicswapped)
7345 plug_type[0] = PLUG_TYPE_GND_MIC_SWAP;
7346 else
7347 plug_type[0] = PLUG_TYPE_INVALID;
7348 }
Joonwoo Park41956722012-04-18 13:13:07 -07007349 }
7350
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007351 for (i = 0; (plug_type[0] != PLUG_TYPE_GND_MIC_SWAP && !inval) &&
7352 i < num_det; i++) {
Joonwoo Park41956722012-04-18 13:13:07 -07007353 /*
7354 * If we are here, means none of the all
7355 * measurements are fake, continue plug type detection.
7356 * If all three measurements do not produce same
7357 * plug type, restart insertion detection
7358 */
7359 if (mic_mv[i] < plug_type_ptr->v_no_mic) {
7360 plug_type[i] = PLUG_TYPE_HEADPHONE;
7361 pr_debug("%s: Detect attempt %d, detected Headphone\n",
7362 __func__, i);
7363 } else if (highhph && (mic_mv[i] > plug_type_ptr->v_hs_max)) {
7364 plug_type[i] = PLUG_TYPE_HIGH_HPH;
7365 pr_debug("%s: Detect attempt %d, detected High "
7366 "Headphone\n", __func__, i);
7367 } else {
7368 plug_type[i] = PLUG_TYPE_HEADSET;
7369 pr_debug("%s: Detect attempt %d, detected Headset\n",
7370 __func__, i);
7371 }
7372
7373 if (i > 0 && (plug_type[i - 1] != plug_type[i])) {
7374 pr_err("%s: Detect attempt %d and %d are not same",
7375 __func__, i - 1, i);
7376 plug_type[0] = PLUG_TYPE_INVALID;
7377 inval = true;
7378 break;
7379 }
7380 }
7381
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007382 pr_debug("%s: Detected plug type %d\n", __func__, plug_type[0]);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007383 pr_debug("%s: leave\n", __func__);
Joonwoo Park41956722012-04-18 13:13:07 -07007384 return plug_type[0];
7385}
7386
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007387static void tabla_hs_correct_gpio_plug(struct work_struct *work)
7388{
7389 struct tabla_priv *tabla;
7390 struct snd_soc_codec *codec;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007391 int retry = 0, pt_gnd_mic_swap_cnt = 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007392 bool correction = false;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007393 enum tabla_mbhc_plug_type plug_type = PLUG_TYPE_INVALID;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007394 unsigned long timeout;
7395
7396 tabla = container_of(work, struct tabla_priv, hs_correct_plug_work);
7397 codec = tabla->codec;
7398
7399 pr_debug("%s: enter\n", __func__);
7400 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
7401
7402 /* Keep override on during entire plug type correction work.
7403 *
7404 * This is okay under the assumption that any GPIO irqs which use
7405 * MBHC block cancel and sync this work so override is off again
7406 * prior to GPIO interrupt handler's MBHC block usage.
7407 * Also while this correction work is running, we can guarantee
7408 * DAPM doesn't use any MBHC block as this work only runs with
7409 * headphone detection.
7410 */
7411 tabla_turn_onoff_override(codec, true);
7412
7413 timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS);
7414 while (!time_after(jiffies, timeout)) {
7415 ++retry;
7416 rmb();
7417 if (tabla->hs_detect_work_stop) {
7418 pr_debug("%s: stop requested\n", __func__);
7419 break;
7420 }
7421
7422 msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS);
7423 if (tabla_hs_gpio_level_remove(tabla)) {
7424 pr_debug("%s: GPIO value is low\n", __func__);
7425 break;
7426 }
7427
7428 /* can race with removal interrupt */
7429 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Joonwoo Park41956722012-04-18 13:13:07 -07007430 plug_type = tabla_codec_get_plug_type(codec, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007431 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
7432
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007433 pr_debug("%s: attempt(%d) current_plug(%d) new_plug(%d)\n",
7434 __func__, retry, tabla->current_plug, plug_type);
Joonwoo Park41956722012-04-18 13:13:07 -07007435 if (plug_type == PLUG_TYPE_INVALID) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007436 pr_debug("Invalid plug in attempt # %d\n", retry);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007437 if (!tabla->mbhc_cfg.detect_extn_cable &&
7438 retry == NUM_ATTEMPTS_TO_REPORT &&
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007439 tabla->current_plug == PLUG_TYPE_NONE) {
7440 tabla_codec_report_plug(codec, 1,
7441 SND_JACK_HEADPHONE);
7442 }
Joonwoo Park41956722012-04-18 13:13:07 -07007443 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007444 pr_debug("Good headphone detected, continue polling mic\n");
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007445 if (tabla->mbhc_cfg.detect_extn_cable) {
7446 if (tabla->current_plug != plug_type)
7447 tabla_codec_report_plug(codec, 1,
7448 SND_JACK_HEADPHONE);
7449 } else if (tabla->current_plug == PLUG_TYPE_NONE)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007450 tabla_codec_report_plug(codec, 1,
7451 SND_JACK_HEADPHONE);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007452 } else {
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007453 if (plug_type == PLUG_TYPE_GND_MIC_SWAP) {
7454 pt_gnd_mic_swap_cnt++;
7455 if (pt_gnd_mic_swap_cnt <
7456 TABLA_MBHC_GND_MIC_SWAP_THRESHOLD)
7457 continue;
7458 else if (pt_gnd_mic_swap_cnt >
7459 TABLA_MBHC_GND_MIC_SWAP_THRESHOLD) {
7460 /* This is due to GND/MIC switch didn't
7461 * work, Report unsupported plug */
7462 } else if (tabla->mbhc_cfg.swap_gnd_mic) {
7463 /* if switch is toggled, check again,
7464 * otherwise report unsupported plug */
7465 if (tabla->mbhc_cfg.swap_gnd_mic(codec))
7466 continue;
7467 }
7468 } else
7469 pt_gnd_mic_swap_cnt = 0;
7470
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007471 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
7472 /* Turn off override */
7473 tabla_turn_onoff_override(codec, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007474 /* The valid plug also includes PLUG_TYPE_GND_MIC_SWAP
7475 */
Joonwoo Park41956722012-04-18 13:13:07 -07007476 tabla_find_plug_and_report(codec, plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007477 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
7478 pr_debug("Attempt %d found correct plug %d\n", retry,
Joonwoo Park41956722012-04-18 13:13:07 -07007479 plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007480 correction = true;
7481 break;
7482 }
7483 }
7484
7485 /* Turn off override */
7486 if (!correction)
7487 tabla_turn_onoff_override(codec, false);
7488
7489 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007490
7491 if (tabla->mbhc_cfg.detect_extn_cable) {
7492 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
7493 if (tabla->current_plug == PLUG_TYPE_HEADPHONE ||
7494 tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP ||
7495 tabla->current_plug == PLUG_TYPE_INVALID ||
7496 plug_type == PLUG_TYPE_INVALID) {
7497 /* Enable removal detection */
7498 tabla_codec_cleanup_hs_polling(codec);
7499 tabla_codec_enable_hs_detect(codec, 0, 0, false);
7500 }
7501 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
7502 }
7503 pr_debug("%s: leave current_plug(%d)\n",
7504 __func__, tabla->current_plug);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007505 /* unlock sleep */
7506 wcd9xxx_unlock_sleep(tabla->codec->control_data);
7507}
7508
7509/* called under codec_resource_lock acquisition */
7510static void tabla_codec_decide_gpio_plug(struct snd_soc_codec *codec)
7511{
Joonwoo Park41956722012-04-18 13:13:07 -07007512 enum tabla_mbhc_plug_type plug_type;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007513 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007514
7515 pr_debug("%s: enter\n", __func__);
7516
7517 tabla_turn_onoff_override(codec, true);
Joonwoo Park41956722012-04-18 13:13:07 -07007518 plug_type = tabla_codec_get_plug_type(codec, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007519 tabla_turn_onoff_override(codec, false);
7520
7521 if (tabla_hs_gpio_level_remove(tabla)) {
7522 pr_debug("%s: GPIO value is low when determining plug\n",
7523 __func__);
7524 return;
7525 }
7526
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007527 if (plug_type == PLUG_TYPE_INVALID ||
7528 plug_type == PLUG_TYPE_GND_MIC_SWAP) {
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007529 tabla_schedule_hs_detect_plug(tabla,
7530 &tabla->hs_correct_plug_work);
Joonwoo Park41956722012-04-18 13:13:07 -07007531 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007532 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
7533
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007534 tabla_schedule_hs_detect_plug(tabla,
7535 &tabla->hs_correct_plug_work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007536 } else {
Joonwoo Park41956722012-04-18 13:13:07 -07007537 pr_debug("%s: Valid plug found, determine plug type %d\n",
7538 __func__, plug_type);
7539 tabla_find_plug_and_report(codec, plug_type);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007540 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007541 pr_debug("%s: leave\n", __func__);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007542}
7543
7544/* called under codec_resource_lock acquisition */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007545static void tabla_codec_detect_plug_type(struct snd_soc_codec *codec)
7546{
Joonwoo Park41956722012-04-18 13:13:07 -07007547 enum tabla_mbhc_plug_type plug_type;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007548 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
7549 const struct tabla_mbhc_plug_detect_cfg *plug_det =
7550 TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007551 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007552 /* Turn on the override,
7553 * tabla_codec_setup_hs_polling requires override on */
7554 tabla_turn_onoff_override(codec, true);
Joonwoo Park03324832012-03-19 19:36:16 -07007555
7556 if (plug_det->t_ins_complete > 20)
7557 msleep(plug_det->t_ins_complete);
7558 else
7559 usleep_range(plug_det->t_ins_complete * 1000,
7560 plug_det->t_ins_complete * 1000);
7561
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007562 if (tabla->mbhc_cfg.gpio) {
7563 /* Turn off the override */
7564 tabla_turn_onoff_override(codec, false);
7565 if (tabla_hs_gpio_level_remove(tabla))
7566 pr_debug("%s: GPIO value is low when determining "
7567 "plug\n", __func__);
7568 else
7569 tabla_codec_decide_gpio_plug(codec);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007570 pr_debug("%s: leave\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007571 return;
7572 }
7573
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007574 plug_type = tabla_codec_get_plug_type(codec, false);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007575 tabla_turn_onoff_override(codec, false);
Joonwoo Park03324832012-03-19 19:36:16 -07007576
Joonwoo Park41956722012-04-18 13:13:07 -07007577 if (plug_type == PLUG_TYPE_INVALID) {
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007578 pr_debug("%s: Invalid plug type detected\n", __func__);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007579 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, 0x02);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007580 tabla_codec_cleanup_hs_polling(codec);
7581 tabla_codec_enable_hs_detect(codec, 1,
7582 MBHC_USE_MB_TRIGGER |
7583 MBHC_USE_HPHL_TRIGGER, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007584 } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) {
7585 pr_debug("%s: GND-MIC swapped plug type detected\n", __func__);
7586 tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED);
7587 tabla_codec_cleanup_hs_polling(codec);
7588 tabla_codec_enable_hs_detect(codec, 0, 0, false);
Joonwoo Park41956722012-04-18 13:13:07 -07007589 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Park03324832012-03-19 19:36:16 -07007590 pr_debug("%s: Headphone Detected\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007591 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
7592 tabla_codec_cleanup_hs_polling(codec);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007593 tabla_schedule_hs_detect_plug(tabla,
7594 &tabla->hs_correct_plug_work_nogpio);
Joonwoo Park41956722012-04-18 13:13:07 -07007595 } else if (plug_type == PLUG_TYPE_HEADSET) {
Joonwoo Park03324832012-03-19 19:36:16 -07007596 pr_debug("%s: Headset detected\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007597 tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET);
Joonwoo Park03324832012-03-19 19:36:16 -07007598 /* avoid false button press detect */
7599 msleep(50);
Joonwoo Park03324832012-03-19 19:36:16 -07007600 tabla_codec_start_hs_polling(codec);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007601 } else if (tabla->mbhc_cfg.detect_extn_cable &&
7602 plug_type == PLUG_TYPE_HIGH_HPH) {
7603 pr_debug("%s: High impedance plug type detected\n", __func__);
7604 tabla_codec_report_plug(codec, 1, SND_JACK_LINEOUT);
7605 /* Enable insertion detection on the other end of cable */
7606 tabla_codec_cleanup_hs_polling(codec);
7607 tabla_codec_enable_hs_detect(codec, 1,
7608 MBHC_USE_MB_TRIGGER, false);
Joonwoo Park03324832012-03-19 19:36:16 -07007609 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007610 pr_debug("%s: leave\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07007611}
7612
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007613/* called only from interrupt which is under codec_resource_lock acquisition */
7614static void tabla_hs_insert_irq_gpio(struct tabla_priv *priv, bool is_removal)
Bradley Rubincb1e2732011-06-23 16:49:20 -07007615{
Bradley Rubincb1e2732011-06-23 16:49:20 -07007616 struct snd_soc_codec *codec = priv->codec;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007617 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007618
7619 if (!is_removal) {
7620 pr_debug("%s: MIC trigger insertion interrupt\n", __func__);
7621
7622 rmb();
7623 if (priv->lpi_enabled)
7624 msleep(100);
7625
7626 rmb();
7627 if (!priv->lpi_enabled) {
7628 pr_debug("%s: lpi is disabled\n", __func__);
7629 } else if (gpio_get_value_cansleep(priv->mbhc_cfg.gpio) ==
7630 priv->mbhc_cfg.gpio_level_insert) {
7631 pr_debug("%s: Valid insertion, "
7632 "detect plug type\n", __func__);
7633 tabla_codec_decide_gpio_plug(codec);
7634 } else {
7635 pr_debug("%s: Invalid insertion, "
7636 "stop plug detection\n", __func__);
7637 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007638 } else if (tabla->mbhc_cfg.detect_extn_cable) {
7639 pr_debug("%s: Removal\n", __func__);
7640 if (!tabla_hs_gpio_level_remove(tabla)) {
7641 /*
7642 * gpio says, something is still inserted, could be
7643 * extension cable i.e. headset is removed from
7644 * extension cable
7645 */
7646 /* cancel detect plug */
7647 tabla_cancel_hs_detect_plug(tabla,
7648 &tabla->hs_correct_plug_work);
7649 tabla_codec_decide_gpio_plug(codec);
7650 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007651 } else {
7652 pr_err("%s: GPIO used, invalid MBHC Removal\n", __func__);
7653 }
7654}
7655
7656/* called only from interrupt which is under codec_resource_lock acquisition */
7657static void tabla_hs_insert_irq_nogpio(struct tabla_priv *priv, bool is_removal,
7658 bool is_mb_trigger)
7659{
Joonwoo Park03324832012-03-19 19:36:16 -07007660 int ret;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007661 struct snd_soc_codec *codec = priv->codec;
7662 struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007663 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
7664
7665 /* Cancel possibly running hs_detect_work */
7666 tabla_cancel_hs_detect_plug(tabla,
7667 &tabla->hs_correct_plug_work_nogpio);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07007668
7669 if (is_removal) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007670
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07007671 /*
7672 * If headphone is removed while playback is in progress,
7673 * it is possible that micbias will be switched to VDDIO.
7674 */
Joonwoo Park03324832012-03-19 19:36:16 -07007675 tabla_codec_switch_micbias(codec, 0);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007676 if (priv->current_plug == PLUG_TYPE_HEADPHONE)
7677 tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE);
7678 else if (priv->current_plug == PLUG_TYPE_GND_MIC_SWAP)
7679 tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED);
7680 else
7681 WARN(1, "%s: Unexpected current plug type %d\n",
7682 __func__, priv->current_plug);
Bradley Rubincb1e2732011-06-23 16:49:20 -07007683 tabla_codec_shutdown_hs_removal_detect(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007684 tabla_codec_enable_hs_detect(codec, 1,
7685 MBHC_USE_MB_TRIGGER |
7686 MBHC_USE_HPHL_TRIGGER,
Joonwoo Park03324832012-03-19 19:36:16 -07007687 true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007688 } else if (is_mb_trigger && !is_removal) {
Joonwoo Park03324832012-03-19 19:36:16 -07007689 pr_debug("%s: Waiting for Headphone left trigger\n",
7690 __func__);
7691 wcd9xxx_lock_sleep(core);
7692 if (schedule_delayed_work(&priv->mbhc_insert_dwork,
7693 usecs_to_jiffies(1000000)) == 0) {
7694 pr_err("%s: mbhc_insert_dwork is already scheduled\n",
7695 __func__);
7696 wcd9xxx_unlock_sleep(core);
Joonwoo Parkf4267c22012-01-10 13:25:24 -08007697 }
Joonwoo Park03324832012-03-19 19:36:16 -07007698 tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER,
7699 false);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007700 } else {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007701 ret = cancel_delayed_work(&priv->mbhc_insert_dwork);
7702 if (ret != 0) {
7703 pr_debug("%s: Complete plug insertion, Detecting plug "
7704 "type\n", __func__);
7705 tabla_codec_detect_plug_type(codec);
7706 wcd9xxx_unlock_sleep(core);
7707 } else {
7708 wcd9xxx_enable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007709 WCD9XXX_IRQ_MBHC_INSERTION);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007710 pr_err("%s: Error detecting plug insertion\n",
7711 __func__);
7712 }
Joonwoo Park03324832012-03-19 19:36:16 -07007713 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007714}
Bhalchandra Gajare9494fa262011-11-10 19:25:59 -08007715
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007716/* called only from interrupt which is under codec_resource_lock acquisition */
7717static void tabla_hs_insert_irq_extn(struct tabla_priv *priv,
7718 bool is_mb_trigger)
7719{
7720 struct snd_soc_codec *codec = priv->codec;
7721 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
7722
7723 /* Cancel possibly running hs_detect_work */
7724 tabla_cancel_hs_detect_plug(tabla,
7725 &tabla->hs_correct_plug_work);
7726
7727 if (is_mb_trigger) {
7728 pr_debug("%s: Waiting for Headphone left trigger\n",
7729 __func__);
7730 tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER,
7731 false);
7732 } else {
7733 pr_debug("%s: HPHL trigger received, detecting plug type\n",
7734 __func__);
7735 tabla_codec_detect_plug_type(codec);
7736 }
7737}
7738
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007739static irqreturn_t tabla_hs_insert_irq(int irq, void *data)
7740{
7741 bool is_mb_trigger, is_removal;
7742 struct tabla_priv *priv = data;
7743 struct snd_soc_codec *codec = priv->codec;
Bradley Rubincb1e2732011-06-23 16:49:20 -07007744
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007745 pr_debug("%s: enter\n", __func__);
7746 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007747 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007748
7749 is_mb_trigger = !!(snd_soc_read(codec, priv->mbhc_bias_regs.mbhc_reg) &
7750 0x10);
7751 is_removal = !!(snd_soc_read(codec, TABLA_A_CDC_MBHC_INT_CTL) & 0x02);
7752 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x03, 0x00);
7753
7754 /* Turn off both HPH and MIC line schmitt triggers */
7755 snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
7756 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
7757 snd_soc_update_bits(codec, priv->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
7758
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007759 if (priv->mbhc_cfg.detect_extn_cable &&
7760 priv->current_plug == PLUG_TYPE_HIGH_HPH)
7761 tabla_hs_insert_irq_extn(priv, is_mb_trigger);
7762 else if (priv->mbhc_cfg.gpio)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007763 tabla_hs_insert_irq_gpio(priv, is_removal);
7764 else
7765 tabla_hs_insert_irq_nogpio(priv, is_removal, is_mb_trigger);
7766
7767 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bradley Rubincb1e2732011-06-23 16:49:20 -07007768 return IRQ_HANDLED;
7769}
7770
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007771static bool is_valid_mic_voltage(struct snd_soc_codec *codec, s32 mic_mv)
7772{
7773 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007774 const struct tabla_mbhc_plug_type_cfg *plug_type =
7775 TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
7776 const s16 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007777
7778 return (!(mic_mv > 10 && mic_mv < 80) && (mic_mv > plug_type->v_no_mic)
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007779 && (mic_mv < v_hs_max)) ? true : false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007780}
7781
7782/* called under codec_resource_lock acquisition
7783 * returns true if mic voltage range is back to normal insertion
7784 * returns false either if timedout or removed */
7785static bool tabla_hs_remove_settle(struct snd_soc_codec *codec)
7786{
7787 int i;
7788 bool timedout, settled = false;
7789 s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT];
7790 short mb_v[MBHC_NUM_DCE_PLUG_DETECT];
7791 unsigned long retry = 0, timeout;
7792 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007793 const s16 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007794
7795 timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS);
7796 while (!(timedout = time_after(jiffies, timeout))) {
7797 retry++;
7798 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
7799 pr_debug("%s: GPIO indicates removal\n", __func__);
7800 break;
7801 }
7802
7803 if (tabla->mbhc_cfg.gpio) {
7804 if (retry > 1)
7805 msleep(250);
7806 else
7807 msleep(50);
7808 }
7809
7810 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
7811 pr_debug("%s: GPIO indicates removal\n", __func__);
7812 break;
7813 }
7814
7815 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) {
7816 mb_v[i] = tabla_codec_sta_dce(codec, 1, true);
7817 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
7818 pr_debug("%s : DCE run %lu, mic_mv = %d(%x)\n",
7819 __func__, retry, mic_mv[i], mb_v[i]);
7820 }
7821
7822 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
7823 pr_debug("%s: GPIO indicates removal\n", __func__);
7824 break;
7825 }
7826
7827 if (tabla->current_plug == PLUG_TYPE_NONE) {
7828 pr_debug("%s : headset/headphone is removed\n",
7829 __func__);
7830 break;
7831 }
7832
7833 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++)
7834 if (!is_valid_mic_voltage(codec, mic_mv[i]))
7835 break;
7836
7837 if (i == MBHC_NUM_DCE_PLUG_DETECT) {
7838 pr_debug("%s: MIC voltage settled\n", __func__);
7839 settled = true;
7840 msleep(200);
7841 break;
7842 }
7843
7844 /* only for non-GPIO remove irq */
7845 if (!tabla->mbhc_cfg.gpio) {
7846 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++)
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007847 if (mic_mv[i] < v_hs_max)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007848 break;
7849 if (i == MBHC_NUM_DCE_PLUG_DETECT) {
7850 pr_debug("%s: Headset is removed\n", __func__);
7851 break;
7852 }
7853 }
7854 }
7855
7856 if (timedout)
7857 pr_debug("%s: Microphone did not settle in %d seconds\n",
7858 __func__, TABLA_HS_DETECT_PLUG_TIME_MS);
7859 return settled;
7860}
7861
7862/* called only from interrupt which is under codec_resource_lock acquisition */
7863static void tabla_hs_remove_irq_gpio(struct tabla_priv *priv)
7864{
7865 struct snd_soc_codec *codec = priv->codec;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007866 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007867 if (tabla_hs_remove_settle(codec))
7868 tabla_codec_start_hs_polling(codec);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007869 pr_debug("%s: leave\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007870}
7871
7872/* called only from interrupt which is under codec_resource_lock acquisition */
7873static void tabla_hs_remove_irq_nogpio(struct tabla_priv *priv)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007874{
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007875 short bias_value;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007876 bool removed = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007877 struct snd_soc_codec *codec = priv->codec;
Joonwoo Park0976d012011-12-22 11:48:18 -08007878 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007879 TABLA_MBHC_CAL_GENERAL_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007880 int min_us = TABLA_FAKE_REMOVAL_MIN_PERIOD_MS * 1000;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007881
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007882 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007883 if (priv->current_plug != PLUG_TYPE_HEADSET) {
7884 pr_debug("%s(): Headset is not inserted, ignore removal\n",
7885 __func__);
7886 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
7887 0x08, 0x08);
7888 return;
7889 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007890
Joonwoo Park0976d012011-12-22 11:48:18 -08007891 usleep_range(generic->t_shutdown_plug_rem,
7892 generic->t_shutdown_plug_rem);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007893
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007894 do {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007895 bias_value = tabla_codec_sta_dce(codec, 1, true);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007896 pr_debug("%s: DCE %d,%d, %d us left\n", __func__, bias_value,
7897 tabla_codec_sta_dce_v(codec, 1, bias_value), min_us);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007898 if (bias_value < tabla_get_current_v_ins(priv, false)) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007899 pr_debug("%s: checking false removal\n", __func__);
7900 msleep(500);
7901 removed = !tabla_hs_remove_settle(codec);
7902 pr_debug("%s: headset %sactually removed\n", __func__,
7903 removed ? "" : "not ");
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007904 break;
7905 }
7906 min_us -= priv->mbhc_data.t_dce;
7907 } while (min_us > 0);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07007908
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007909 if (removed) {
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007910 if (priv->mbhc_cfg.detect_extn_cable) {
7911 if (!tabla_hs_gpio_level_remove(priv)) {
7912 /*
7913 * extension cable is still plugged in
7914 * report it as LINEOUT device
7915 */
7916 tabla_codec_report_plug(codec, 1,
7917 SND_JACK_LINEOUT);
7918 tabla_codec_cleanup_hs_polling(codec);
7919 tabla_codec_enable_hs_detect(codec, 1,
7920 MBHC_USE_MB_TRIGGER,
7921 false);
7922 }
7923 } else {
7924 /* Cancel possibly running hs_detect_work */
7925 tabla_cancel_hs_detect_plug(priv,
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007926 &priv->hs_correct_plug_work_nogpio);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007927 /*
7928 * If this removal is not false, first check the micbias
7929 * switch status and switch it to LDOH if it is already
7930 * switched to VDDIO.
7931 */
7932 tabla_codec_switch_micbias(codec, 0);
Joonwoo Park03324832012-03-19 19:36:16 -07007933
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007934 tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET);
7935 tabla_codec_cleanup_hs_polling(codec);
7936 tabla_codec_enable_hs_detect(codec, 1,
7937 MBHC_USE_MB_TRIGGER |
7938 MBHC_USE_HPHL_TRIGGER,
7939 true);
7940 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007941 } else {
7942 tabla_codec_start_hs_polling(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007943 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007944 pr_debug("%s: leave\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007945}
Joonwoo Park8b1f0982011-12-08 17:12:45 -08007946
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007947static irqreturn_t tabla_hs_remove_irq(int irq, void *data)
7948{
7949 struct tabla_priv *priv = data;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007950 bool vddio;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007951 pr_debug("%s: enter, removal interrupt\n", __func__);
7952
7953 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
Simmi Pateriya71d63872012-11-08 01:06:30 +05307954 vddio = !priv->mbhc_cfg.micbias_always_on &&
7955 (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007956 priv->mbhc_micbias_switched);
7957 if (vddio)
7958 __tabla_codec_switch_micbias(priv->codec, 0, false, true);
7959
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007960 if ((priv->mbhc_cfg.detect_extn_cable &&
7961 !tabla_hs_gpio_level_remove(priv)) ||
7962 !priv->mbhc_cfg.gpio) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007963 tabla_hs_remove_irq_nogpio(priv);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007964 } else
7965 tabla_hs_remove_irq_gpio(priv);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007966
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007967 /* if driver turned off vddio switch and headset is not removed,
7968 * turn on the vddio switch back, if headset is removed then vddio
7969 * switch is off by time now and shouldn't be turn on again from here */
7970 if (vddio && priv->current_plug == PLUG_TYPE_HEADSET)
7971 __tabla_codec_switch_micbias(priv->codec, 1, true, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007972 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007973
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007974 return IRQ_HANDLED;
7975}
7976
Joonwoo Park03324832012-03-19 19:36:16 -07007977void mbhc_insert_work(struct work_struct *work)
7978{
7979 struct delayed_work *dwork;
7980 struct tabla_priv *tabla;
7981 struct snd_soc_codec *codec;
7982 struct wcd9xxx *tabla_core;
7983
7984 dwork = to_delayed_work(work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007985 tabla = container_of(dwork, struct tabla_priv, mbhc_insert_dwork);
Joonwoo Park03324832012-03-19 19:36:16 -07007986 codec = tabla->codec;
7987 tabla_core = dev_get_drvdata(codec->dev->parent);
7988
7989 pr_debug("%s:\n", __func__);
7990
7991 /* Turn off both HPH and MIC line schmitt triggers */
7992 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
7993 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
7994 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007995 wcd9xxx_disable_irq_sync(codec->control_data,
7996 WCD9XXX_IRQ_MBHC_INSERTION);
Joonwoo Park03324832012-03-19 19:36:16 -07007997 tabla_codec_detect_plug_type(codec);
7998 wcd9xxx_unlock_sleep(tabla_core);
7999}
8000
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008001static void tabla_hs_gpio_handler(struct snd_soc_codec *codec)
8002{
8003 bool insert;
8004 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park1f9d7fd2013-01-07 12:40:03 -08008005 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008006 bool is_removed = false;
8007
8008 pr_debug("%s: enter\n", __func__);
8009
8010 tabla->in_gpio_handler = true;
8011 /* Wait here for debounce time */
8012 usleep_range(TABLA_GPIO_IRQ_DEBOUNCE_TIME_US,
8013 TABLA_GPIO_IRQ_DEBOUNCE_TIME_US);
8014
Joonwoo Park1f9d7fd2013-01-07 12:40:03 -08008015 wcd9xxx_nested_irq_lock(core);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008016 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
8017
8018 /* cancel pending button press */
8019 if (tabla_cancel_btn_work(tabla))
8020 pr_debug("%s: button press is canceled\n", __func__);
8021
8022 insert = (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) ==
8023 tabla->mbhc_cfg.gpio_level_insert);
8024 if ((tabla->current_plug == PLUG_TYPE_NONE) && insert) {
8025 tabla->lpi_enabled = false;
8026 wmb();
8027
8028 /* cancel detect plug */
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07008029 tabla_cancel_hs_detect_plug(tabla,
8030 &tabla->hs_correct_plug_work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008031
8032 /* Disable Mic Bias pull down and HPH Switch to GND */
8033 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01,
8034 0x00);
8035 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x00);
8036 tabla_codec_detect_plug_type(codec);
8037 } else if ((tabla->current_plug != PLUG_TYPE_NONE) && !insert) {
8038 tabla->lpi_enabled = false;
8039 wmb();
8040
8041 /* cancel detect plug */
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07008042 tabla_cancel_hs_detect_plug(tabla,
8043 &tabla->hs_correct_plug_work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008044
8045 if (tabla->current_plug == PLUG_TYPE_HEADPHONE) {
8046 tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE);
8047 is_removed = true;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07008048 } else if (tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP) {
8049 tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED);
8050 is_removed = true;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008051 } else if (tabla->current_plug == PLUG_TYPE_HEADSET) {
8052 tabla_codec_pause_hs_polling(codec);
8053 tabla_codec_cleanup_hs_polling(codec);
8054 tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET);
8055 is_removed = true;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07008056 } else if (tabla->current_plug == PLUG_TYPE_HIGH_HPH) {
8057 tabla_codec_report_plug(codec, 0, SND_JACK_LINEOUT);
8058 is_removed = true;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008059 }
8060
8061 if (is_removed) {
8062 /* Enable Mic Bias pull down and HPH Switch to GND */
8063 snd_soc_update_bits(codec,
8064 tabla->mbhc_bias_regs.ctl_reg, 0x01,
8065 0x01);
8066 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01,
8067 0x01);
8068 /* Make sure mic trigger is turned off */
8069 snd_soc_update_bits(codec,
8070 tabla->mbhc_bias_regs.ctl_reg,
8071 0x01, 0x01);
8072 snd_soc_update_bits(codec,
8073 tabla->mbhc_bias_regs.mbhc_reg,
8074 0x90, 0x00);
8075 /* Reset MBHC State Machine */
8076 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
8077 0x08, 0x08);
8078 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
8079 0x08, 0x00);
8080 /* Turn off override */
8081 tabla_turn_onoff_override(codec, false);
Simmi Pateriya21375012012-11-26 23:06:01 +05308082 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008083 }
8084 }
8085
8086 tabla->in_gpio_handler = false;
8087 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Joonwoo Park1f9d7fd2013-01-07 12:40:03 -08008088 wcd9xxx_nested_irq_unlock(core);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008089 pr_debug("%s: leave\n", __func__);
8090}
8091
8092static irqreturn_t tabla_mechanical_plug_detect_irq(int irq, void *data)
8093{
8094 int r = IRQ_HANDLED;
8095 struct snd_soc_codec *codec = data;
Joonwoo Parkecf379c2012-10-04 16:57:52 -07008096 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008097
8098 if (unlikely(wcd9xxx_lock_sleep(codec->control_data) == false)) {
8099 pr_warn("%s: failed to hold suspend\n", __func__);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07008100 /*
8101 * Give up this IRQ for now and resend this IRQ so IRQ can be
8102 * handled after system resume
8103 */
8104 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
8105 tabla->gpio_irq_resend = true;
8106 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
8107 wake_lock_timeout(&tabla->irq_resend_wlock, HZ);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008108 r = IRQ_NONE;
8109 } else {
8110 tabla_hs_gpio_handler(codec);
8111 wcd9xxx_unlock_sleep(codec->control_data);
8112 }
8113
8114 return r;
8115}
8116
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07008117static void tabla_hs_correct_plug_nogpio(struct work_struct *work)
8118{
8119 struct tabla_priv *tabla;
8120 struct snd_soc_codec *codec;
8121 unsigned long timeout;
8122 int retry = 0;
8123 enum tabla_mbhc_plug_type plug_type;
8124 bool is_headset = false;
8125
8126 pr_debug("%s(): Poll Microphone voltage for %d seconds\n",
8127 __func__, TABLA_HS_DETECT_PLUG_TIME_MS / 1000);
8128
8129 tabla = container_of(work, struct tabla_priv,
8130 hs_correct_plug_work_nogpio);
8131 codec = tabla->codec;
8132
8133 /* Make sure the MBHC mux is connected to MIC Path */
8134 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
8135
8136 /* setup for microphone polling */
8137 tabla_turn_onoff_override(codec, true);
8138 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
8139
8140 timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS);
8141 while (!time_after(jiffies, timeout)) {
8142 ++retry;
8143
8144 msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS);
8145 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
8146 plug_type = tabla_codec_get_plug_type(codec, false);
8147 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
8148
8149 if (plug_type == PLUG_TYPE_HIGH_HPH
8150 || plug_type == PLUG_TYPE_INVALID) {
8151
8152 /* this means the plug is removed
8153 * End microphone polling and setup
8154 * for low power removal detection.
8155 */
8156 pr_debug("%s(): Plug may be removed, setup removal\n",
8157 __func__);
8158 break;
8159 } else if (plug_type == PLUG_TYPE_HEADSET) {
8160 /* Plug is corrected from headphone to headset,
8161 * report headset and end the polling
8162 */
8163 is_headset = true;
8164 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
8165 tabla_turn_onoff_override(codec, false);
8166 tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET);
8167 tabla_codec_start_hs_polling(codec);
8168 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
8169 pr_debug("%s(): corrected from headphone to headset\n",
8170 __func__);
8171 break;
8172 }
8173 }
8174
8175 /* Undo setup for microphone polling depending
8176 * result from polling
8177 */
8178 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
8179 if (!is_headset) {
Bhalchandra Gajareafc86432012-08-23 13:44:07 -07008180 pr_debug("%s: Inserted headphone is not a headset\n",
8181 __func__);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07008182 tabla_turn_onoff_override(codec, false);
8183 tabla_codec_cleanup_hs_polling(codec);
8184 tabla_codec_enable_hs_detect(codec, 0, 0, false);
8185 }
8186 wcd9xxx_unlock_sleep(codec->control_data);
8187}
8188
Joonwoo Park1305bab2012-05-21 15:08:42 -07008189static int tabla_mbhc_init_and_calibrate(struct tabla_priv *tabla)
8190{
8191 int ret = 0;
8192 struct snd_soc_codec *codec = tabla->codec;
8193
8194 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
8195 tabla_mbhc_init(codec);
8196 tabla_mbhc_cal(codec);
8197 tabla_mbhc_calc_thres(codec);
8198 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
8199 tabla_codec_calibrate_hs_polling(codec);
8200 if (!tabla->mbhc_cfg.gpio) {
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07008201 INIT_WORK(&tabla->hs_correct_plug_work_nogpio,
8202 tabla_hs_correct_plug_nogpio);
Joonwoo Park1305bab2012-05-21 15:08:42 -07008203 ret = tabla_codec_enable_hs_detect(codec, 1,
8204 MBHC_USE_MB_TRIGGER |
8205 MBHC_USE_HPHL_TRIGGER,
8206 false);
8207
8208 if (IS_ERR_VALUE(ret))
8209 pr_err("%s: Failed to setup MBHC detection\n",
8210 __func__);
8211 } else {
8212 /* Enable Mic Bias pull down and HPH Switch to GND */
8213 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg,
8214 0x01, 0x01);
8215 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x01);
8216 INIT_WORK(&tabla->hs_correct_plug_work,
8217 tabla_hs_correct_gpio_plug);
8218 }
8219
8220 if (!IS_ERR_VALUE(ret)) {
8221 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10);
8222 wcd9xxx_enable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008223 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Joonwoo Park1305bab2012-05-21 15:08:42 -07008224 wcd9xxx_enable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008225 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Joonwoo Park1305bab2012-05-21 15:08:42 -07008226
8227 if (tabla->mbhc_cfg.gpio) {
8228 ret = request_threaded_irq(tabla->mbhc_cfg.gpio_irq,
8229 NULL,
8230 tabla_mechanical_plug_detect_irq,
8231 (IRQF_TRIGGER_RISING |
8232 IRQF_TRIGGER_FALLING),
8233 "tabla-gpio", codec);
8234 if (!IS_ERR_VALUE(ret)) {
8235 ret = enable_irq_wake(tabla->mbhc_cfg.gpio_irq);
8236 /* Bootup time detection */
8237 tabla_hs_gpio_handler(codec);
8238 }
8239 }
8240 }
8241
8242 return ret;
8243}
8244
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008245static void mbhc_fw_read(struct work_struct *work)
8246{
8247 struct delayed_work *dwork;
8248 struct tabla_priv *tabla;
8249 struct snd_soc_codec *codec;
8250 const struct firmware *fw;
Joonwoo Park1305bab2012-05-21 15:08:42 -07008251 int ret = -1, retry = 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008252
8253 dwork = to_delayed_work(work);
Joonwoo Park1305bab2012-05-21 15:08:42 -07008254 tabla = container_of(dwork, struct tabla_priv, mbhc_firmware_dwork);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008255 codec = tabla->codec;
8256
8257 while (retry < MBHC_FW_READ_ATTEMPTS) {
8258 retry++;
8259 pr_info("%s:Attempt %d to request MBHC firmware\n",
8260 __func__, retry);
8261 ret = request_firmware(&fw, "wcd9310/wcd9310_mbhc.bin",
8262 codec->dev);
8263
8264 if (ret != 0) {
8265 usleep_range(MBHC_FW_READ_TIMEOUT,
Joonwoo Park1305bab2012-05-21 15:08:42 -07008266 MBHC_FW_READ_TIMEOUT);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008267 } else {
8268 pr_info("%s: MBHC Firmware read succesful\n", __func__);
8269 break;
8270 }
8271 }
8272
8273 if (ret != 0) {
8274 pr_err("%s: Cannot load MBHC firmware use default cal\n",
8275 __func__);
8276 } else if (tabla_mbhc_fw_validate(fw) == false) {
8277 pr_err("%s: Invalid MBHC cal data size use default cal\n",
8278 __func__);
8279 release_firmware(fw);
8280 } else {
8281 tabla->mbhc_cfg.calibration = (void *)fw->data;
8282 tabla->mbhc_fw = fw;
8283 }
8284
Joonwoo Park1305bab2012-05-21 15:08:42 -07008285 (void) tabla_mbhc_init_and_calibrate(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008286}
8287
Joonwoo Park03324832012-03-19 19:36:16 -07008288int tabla_hs_detect(struct snd_soc_codec *codec,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008289 const struct tabla_mbhc_config *cfg)
Joonwoo Park03324832012-03-19 19:36:16 -07008290{
8291 struct tabla_priv *tabla;
8292 int rc = 0;
8293
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008294 if (!codec || !cfg->calibration) {
Joonwoo Park03324832012-03-19 19:36:16 -07008295 pr_err("Error: no codec or calibration\n");
8296 return -EINVAL;
8297 }
8298
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008299 if (cfg->mclk_rate != TABLA_MCLK_RATE_12288KHZ) {
8300 if (cfg->mclk_rate == TABLA_MCLK_RATE_9600KHZ)
Joonwoo Park03324832012-03-19 19:36:16 -07008301 pr_err("Error: clock rate %dHz is not yet supported\n",
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008302 cfg->mclk_rate);
Joonwoo Park03324832012-03-19 19:36:16 -07008303 else
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008304 pr_err("Error: unsupported clock rate %d\n",
8305 cfg->mclk_rate);
Joonwoo Park03324832012-03-19 19:36:16 -07008306 return -EINVAL;
8307 }
8308
8309 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008310 tabla->mbhc_cfg = *cfg;
8311 tabla->in_gpio_handler = false;
8312 tabla->current_plug = PLUG_TYPE_NONE;
8313 tabla->lpi_enabled = false;
Joonwoo Park03324832012-03-19 19:36:16 -07008314 tabla_get_mbhc_micbias_regs(codec, &tabla->mbhc_bias_regs);
8315
8316 /* Put CFILT in fast mode by default */
Simmi Pateriya71d63872012-11-08 01:06:30 +05308317 if (!tabla->mbhc_cfg.micbias_always_on)
8318 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl,
Joonwoo Park03324832012-03-19 19:36:16 -07008319 0x40, TABLA_CFILT_FAST_MODE);
8320 INIT_DELAYED_WORK(&tabla->mbhc_firmware_dwork, mbhc_fw_read);
8321 INIT_DELAYED_WORK(&tabla->mbhc_btn_dwork, btn_lpress_fn);
8322 INIT_WORK(&tabla->hphlocp_work, hphlocp_off_report);
8323 INIT_WORK(&tabla->hphrocp_work, hphrocp_off_report);
8324 INIT_DELAYED_WORK(&tabla->mbhc_insert_dwork, mbhc_insert_work);
8325
Joonwoo Park1305bab2012-05-21 15:08:42 -07008326 if (!tabla->mbhc_cfg.read_fw_bin)
8327 rc = tabla_mbhc_init_and_calibrate(tabla);
8328 else
Joonwoo Park03324832012-03-19 19:36:16 -07008329 schedule_delayed_work(&tabla->mbhc_firmware_dwork,
8330 usecs_to_jiffies(MBHC_FW_READ_TIMEOUT));
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008331
Joonwoo Park03324832012-03-19 19:36:16 -07008332 return rc;
8333}
8334EXPORT_SYMBOL_GPL(tabla_hs_detect);
8335
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008336static irqreturn_t tabla_slimbus_irq(int irq, void *data)
8337{
8338 struct tabla_priv *priv = data;
8339 struct snd_soc_codec *codec = priv->codec;
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07008340 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
8341 int i, j, port_id, k, ch_mask_temp;
Swaminathan Sathappan4bd38942012-07-17 11:31:31 -07008342 unsigned long slimbus_value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008343 u8 val;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308344 for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) {
8345 slimbus_value = wcd9xxx_interface_reg_read(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008346 TABLA_SLIM_PGD_PORT_INT_STATUS0 + i);
8347 for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308348 val = wcd9xxx_interface_reg_read(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008349 TABLA_SLIM_PGD_PORT_INT_SOURCE0 + i*8 + j);
8350 if (val & 0x1)
8351 pr_err_ratelimited("overflow error on port %x,"
8352 " value %x\n", i*8 + j, val);
8353 if (val & 0x2)
8354 pr_err_ratelimited("underflow error on port %x,"
8355 " value %x\n", i*8 + j, val);
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07008356 if (val & 0x4) {
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07008357 port_id = i*8 + j;
8358 for (k = 0; k < ARRAY_SIZE(tabla_dai); k++) {
8359 ch_mask_temp = 1 << port_id;
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08008360 pr_debug("%s: tabla_p->dai[%d].ch_mask = 0x%lx\n",
Kuirong Wang906ac472012-07-09 12:54:44 -07008361 __func__, k,
8362 tabla_p->dai[k].ch_mask);
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07008363 if (ch_mask_temp &
8364 tabla_p->dai[k].ch_mask) {
8365 tabla_p->dai[k].ch_mask &=
Kuirong Wang906ac472012-07-09 12:54:44 -07008366 ~ch_mask_temp;
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07008367 if (!tabla_p->dai[k].ch_mask)
Kuirong Wang906ac472012-07-09 12:54:44 -07008368 wake_up(
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07008369 &tabla_p->dai[k].dai_wait);
8370 }
8371 }
8372 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008373 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308374 wcd9xxx_interface_reg_write(codec->control_data,
Swaminathan Sathappan4bd38942012-07-17 11:31:31 -07008375 TABLA_SLIM_PGD_PORT_INT_CLR0 + i, slimbus_value);
8376 val = 0x0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008377 }
8378
8379 return IRQ_HANDLED;
8380}
8381
Patrick Lai3043fba2011-08-01 14:15:57 -07008382static int tabla_handle_pdata(struct tabla_priv *tabla)
8383{
8384 struct snd_soc_codec *codec = tabla->codec;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308385 struct wcd9xxx_pdata *pdata = tabla->pdata;
Patrick Lai3043fba2011-08-01 14:15:57 -07008386 int k1, k2, k3, rc = 0;
Santosh Mardi22920282011-10-26 02:38:40 +05308387 u8 leg_mode = pdata->amic_settings.legacy_mode;
8388 u8 txfe_bypass = pdata->amic_settings.txfe_enable;
8389 u8 txfe_buff = pdata->amic_settings.txfe_buff;
8390 u8 flag = pdata->amic_settings.use_pdata;
8391 u8 i = 0, j = 0;
8392 u8 val_txfe = 0, value = 0;
Patrick Lai3043fba2011-08-01 14:15:57 -07008393
8394 if (!pdata) {
8395 rc = -ENODEV;
8396 goto done;
8397 }
8398
8399 /* Make sure settings are correct */
8400 if ((pdata->micbias.ldoh_v > TABLA_LDOH_2P85_V) ||
8401 (pdata->micbias.bias1_cfilt_sel > TABLA_CFILT3_SEL) ||
8402 (pdata->micbias.bias2_cfilt_sel > TABLA_CFILT3_SEL) ||
8403 (pdata->micbias.bias3_cfilt_sel > TABLA_CFILT3_SEL) ||
8404 (pdata->micbias.bias4_cfilt_sel > TABLA_CFILT3_SEL)) {
8405 rc = -EINVAL;
8406 goto done;
8407 }
8408
8409 /* figure out k value */
8410 k1 = tabla_find_k_value(pdata->micbias.ldoh_v,
8411 pdata->micbias.cfilt1_mv);
8412 k2 = tabla_find_k_value(pdata->micbias.ldoh_v,
8413 pdata->micbias.cfilt2_mv);
8414 k3 = tabla_find_k_value(pdata->micbias.ldoh_v,
8415 pdata->micbias.cfilt3_mv);
8416
8417 if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) {
8418 rc = -EINVAL;
8419 goto done;
8420 }
8421
8422 /* Set voltage level and always use LDO */
8423 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x0C,
8424 (pdata->micbias.ldoh_v << 2));
8425
8426 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_1_VAL, 0xFC,
8427 (k1 << 2));
8428 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_2_VAL, 0xFC,
8429 (k2 << 2));
8430 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_3_VAL, 0xFC,
8431 (k3 << 2));
8432
8433 snd_soc_update_bits(codec, TABLA_A_MICB_1_CTL, 0x60,
8434 (pdata->micbias.bias1_cfilt_sel << 5));
8435 snd_soc_update_bits(codec, TABLA_A_MICB_2_CTL, 0x60,
8436 (pdata->micbias.bias2_cfilt_sel << 5));
8437 snd_soc_update_bits(codec, TABLA_A_MICB_3_CTL, 0x60,
8438 (pdata->micbias.bias3_cfilt_sel << 5));
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008439 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_ctl, 0x60,
8440 (pdata->micbias.bias4_cfilt_sel << 5));
Patrick Lai3043fba2011-08-01 14:15:57 -07008441
Santosh Mardi22920282011-10-26 02:38:40 +05308442 for (i = 0; i < 6; j++, i += 2) {
8443 if (flag & (0x01 << i)) {
8444 value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00;
8445 val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00;
8446 val_txfe = val_txfe |
8447 ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00);
8448 snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10,
8449 0x10, value);
8450 snd_soc_update_bits(codec,
8451 TABLA_A_TX_1_2_TEST_EN + j * 10,
8452 0x30, val_txfe);
8453 }
8454 if (flag & (0x01 << (i + 1))) {
8455 value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00;
8456 val_txfe = (txfe_bypass &
8457 (0x01 << (i + 1))) ? 0x02 : 0x00;
8458 val_txfe |= (txfe_buff &
8459 (0x01 << (i + 1))) ? 0x01 : 0x00;
8460 snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10,
8461 0x01, value);
8462 snd_soc_update_bits(codec,
8463 TABLA_A_TX_1_2_TEST_EN + j * 10,
8464 0x03, val_txfe);
8465 }
8466 }
8467 if (flag & 0x40) {
8468 value = (leg_mode & 0x40) ? 0x10 : 0x00;
8469 value = value | ((txfe_bypass & 0x40) ? 0x02 : 0x00);
8470 value = value | ((txfe_buff & 0x40) ? 0x01 : 0x00);
8471 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN,
8472 0x13, value);
8473 }
Patrick Lai49efeac2011-11-03 11:01:12 -07008474
8475 if (pdata->ocp.use_pdata) {
8476 /* not defined in CODEC specification */
8477 if (pdata->ocp.hph_ocp_limit == 1 ||
8478 pdata->ocp.hph_ocp_limit == 5) {
8479 rc = -EINVAL;
8480 goto done;
8481 }
8482 snd_soc_update_bits(codec, TABLA_A_RX_COM_OCP_CTL,
8483 0x0F, pdata->ocp.num_attempts);
8484 snd_soc_write(codec, TABLA_A_RX_COM_OCP_COUNT,
8485 ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time));
8486 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL,
8487 0xE0, (pdata->ocp.hph_ocp_limit << 5));
8488 }
Joonwoo Park03324832012-03-19 19:36:16 -07008489
8490 for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
8491 if (!strncmp(pdata->regulator[i].name, "CDC_VDDA_RX", 11)) {
8492 if (pdata->regulator[i].min_uV == 1800000 &&
8493 pdata->regulator[i].max_uV == 1800000) {
8494 snd_soc_write(codec, TABLA_A_BIAS_REF_CTL,
8495 0x1C);
8496 } else if (pdata->regulator[i].min_uV == 2200000 &&
8497 pdata->regulator[i].max_uV == 2200000) {
8498 snd_soc_write(codec, TABLA_A_BIAS_REF_CTL,
8499 0x1E);
8500 } else {
8501 pr_err("%s: unsupported CDC_VDDA_RX voltage "
8502 "min %d, max %d\n", __func__,
8503 pdata->regulator[i].min_uV,
8504 pdata->regulator[i].max_uV);
8505 rc = -EINVAL;
8506 }
8507 break;
8508 }
8509 }
Patrick Lai3043fba2011-08-01 14:15:57 -07008510done:
8511 return rc;
8512}
8513
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008514static const struct tabla_reg_mask_val tabla_1_1_reg_defaults[] = {
8515
8516 /* Tabla 1.1 MICBIAS changes */
8517 TABLA_REG_VAL(TABLA_A_MICB_1_INT_RBIAS, 0x24),
8518 TABLA_REG_VAL(TABLA_A_MICB_2_INT_RBIAS, 0x24),
8519 TABLA_REG_VAL(TABLA_A_MICB_3_INT_RBIAS, 0x24),
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008520
8521 /* Tabla 1.1 HPH changes */
8522 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_PA, 0x57),
8523 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_LDO, 0x56),
8524
8525 /* Tabla 1.1 EAR PA changes */
8526 TABLA_REG_VAL(TABLA_A_RX_EAR_BIAS_PA, 0xA6),
8527 TABLA_REG_VAL(TABLA_A_RX_EAR_GAIN, 0x02),
8528 TABLA_REG_VAL(TABLA_A_RX_EAR_VCM, 0x03),
8529
8530 /* Tabla 1.1 Lineout_5 Changes */
8531 TABLA_REG_VAL(TABLA_A_RX_LINE_5_GAIN, 0x10),
8532
8533 /* Tabla 1.1 RX Changes */
8534 TABLA_REG_VAL(TABLA_A_CDC_RX1_B5_CTL, 0x78),
8535 TABLA_REG_VAL(TABLA_A_CDC_RX2_B5_CTL, 0x78),
8536 TABLA_REG_VAL(TABLA_A_CDC_RX3_B5_CTL, 0x78),
8537 TABLA_REG_VAL(TABLA_A_CDC_RX4_B5_CTL, 0x78),
8538 TABLA_REG_VAL(TABLA_A_CDC_RX5_B5_CTL, 0x78),
8539 TABLA_REG_VAL(TABLA_A_CDC_RX6_B5_CTL, 0x78),
8540 TABLA_REG_VAL(TABLA_A_CDC_RX7_B5_CTL, 0x78),
8541
8542 /* Tabla 1.1 RX1 and RX2 Changes */
8543 TABLA_REG_VAL(TABLA_A_CDC_RX1_B6_CTL, 0xA0),
8544 TABLA_REG_VAL(TABLA_A_CDC_RX2_B6_CTL, 0xA0),
8545
8546 /* Tabla 1.1 RX3 to RX7 Changes */
8547 TABLA_REG_VAL(TABLA_A_CDC_RX3_B6_CTL, 0x80),
8548 TABLA_REG_VAL(TABLA_A_CDC_RX4_B6_CTL, 0x80),
8549 TABLA_REG_VAL(TABLA_A_CDC_RX5_B6_CTL, 0x80),
8550 TABLA_REG_VAL(TABLA_A_CDC_RX6_B6_CTL, 0x80),
8551 TABLA_REG_VAL(TABLA_A_CDC_RX7_B6_CTL, 0x80),
8552
8553 /* Tabla 1.1 CLASSG Changes */
8554 TABLA_REG_VAL(TABLA_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B),
8555};
8556
8557static const struct tabla_reg_mask_val tabla_2_0_reg_defaults[] = {
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008558 /* Tabla 2.0 MICBIAS changes */
8559 TABLA_REG_VAL(TABLA_A_MICB_2_MBHC, 0x02),
8560};
8561
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008562static const struct tabla_reg_mask_val tabla_1_x_only_reg_2_0_defaults[] = {
8563 TABLA_REG_VAL(TABLA_1_A_MICB_4_INT_RBIAS, 0x24),
8564};
8565
8566static const struct tabla_reg_mask_val tabla_2_only_reg_2_0_defaults[] = {
8567 TABLA_REG_VAL(TABLA_2_A_MICB_4_INT_RBIAS, 0x24),
8568};
8569
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008570static void tabla_update_reg_defaults(struct snd_soc_codec *codec)
8571{
8572 u32 i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308573 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008574
8575 for (i = 0; i < ARRAY_SIZE(tabla_1_1_reg_defaults); i++)
8576 snd_soc_write(codec, tabla_1_1_reg_defaults[i].reg,
8577 tabla_1_1_reg_defaults[i].val);
8578
8579 for (i = 0; i < ARRAY_SIZE(tabla_2_0_reg_defaults); i++)
8580 snd_soc_write(codec, tabla_2_0_reg_defaults[i].reg,
8581 tabla_2_0_reg_defaults[i].val);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008582
8583 if (TABLA_IS_1_X(tabla_core->version)) {
8584 for (i = 0; i < ARRAY_SIZE(tabla_1_x_only_reg_2_0_defaults);
8585 i++)
8586 snd_soc_write(codec,
8587 tabla_1_x_only_reg_2_0_defaults[i].reg,
8588 tabla_1_x_only_reg_2_0_defaults[i].val);
8589 } else {
8590 for (i = 0; i < ARRAY_SIZE(tabla_2_only_reg_2_0_defaults); i++)
8591 snd_soc_write(codec,
8592 tabla_2_only_reg_2_0_defaults[i].reg,
8593 tabla_2_only_reg_2_0_defaults[i].val);
8594 }
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008595}
8596
8597static const struct tabla_reg_mask_val tabla_codec_reg_init_val[] = {
Patrick Laic7cae882011-11-18 11:52:49 -08008598 /* Initialize current threshold to 350MA
8599 * number of wait and run cycles to 4096
8600 */
Patrick Lai49efeac2011-11-03 11:01:12 -07008601 {TABLA_A_RX_HPH_OCP_CTL, 0xE0, 0x60},
Patrick Laic7cae882011-11-18 11:52:49 -08008602 {TABLA_A_RX_COM_OCP_COUNT, 0xFF, 0xFF},
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008603
Santosh Mardi32171012011-10-28 23:32:06 +05308604 {TABLA_A_QFUSE_CTL, 0xFF, 0x03},
8605
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008606 /* Initialize gain registers to use register gain */
8607 {TABLA_A_RX_HPH_L_GAIN, 0x10, 0x10},
8608 {TABLA_A_RX_HPH_R_GAIN, 0x10, 0x10},
8609 {TABLA_A_RX_LINE_1_GAIN, 0x10, 0x10},
8610 {TABLA_A_RX_LINE_2_GAIN, 0x10, 0x10},
8611 {TABLA_A_RX_LINE_3_GAIN, 0x10, 0x10},
8612 {TABLA_A_RX_LINE_4_GAIN, 0x10, 0x10},
8613
Kuirong Wangccb29c62012-06-15 11:09:07 -07008614 /* Set the MICBIAS default output as pull down*/
8615 {TABLA_A_MICB_1_CTL, 0x01, 0x01},
8616 {TABLA_A_MICB_2_CTL, 0x01, 0x01},
8617 {TABLA_A_MICB_3_CTL, 0x01, 0x01},
8618
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008619 /* Initialize mic biases to differential mode */
8620 {TABLA_A_MICB_1_INT_RBIAS, 0x24, 0x24},
8621 {TABLA_A_MICB_2_INT_RBIAS, 0x24, 0x24},
8622 {TABLA_A_MICB_3_INT_RBIAS, 0x24, 0x24},
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008623
8624 {TABLA_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14},
8625
8626 /* Use 16 bit sample size for TX1 to TX6 */
8627 {TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20},
8628 {TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20},
8629 {TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20},
8630 {TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20},
8631 {TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20},
8632 {TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0x30, 0x20},
8633
8634 /* Use 16 bit sample size for TX7 to TX10 */
8635 {TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0x60, 0x40},
8636 {TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0x60, 0x40},
8637 {TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0x60, 0x40},
8638 {TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0x60, 0x40},
8639
8640 /* Use 16 bit sample size for RX */
8641 {TABLA_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA},
8642 {TABLA_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0xAA},
8643
8644 /*enable HPF filter for TX paths */
8645 {TABLA_A_CDC_TX1_MUX_CTL, 0x8, 0x0},
8646 {TABLA_A_CDC_TX2_MUX_CTL, 0x8, 0x0},
8647 {TABLA_A_CDC_TX3_MUX_CTL, 0x8, 0x0},
8648 {TABLA_A_CDC_TX4_MUX_CTL, 0x8, 0x0},
8649 {TABLA_A_CDC_TX5_MUX_CTL, 0x8, 0x0},
8650 {TABLA_A_CDC_TX6_MUX_CTL, 0x8, 0x0},
8651 {TABLA_A_CDC_TX7_MUX_CTL, 0x8, 0x0},
8652 {TABLA_A_CDC_TX8_MUX_CTL, 0x8, 0x0},
8653 {TABLA_A_CDC_TX9_MUX_CTL, 0x8, 0x0},
8654 {TABLA_A_CDC_TX10_MUX_CTL, 0x8, 0x0},
Kiran Kandi0ba468f2012-05-08 11:45:05 -07008655
8656 /* config Decimator for DMIC CLK_MODE_1(3.072Mhz@12.88Mhz mclk) */
8657 {TABLA_A_CDC_TX1_DMIC_CTL, 0x1, 0x1},
8658 {TABLA_A_CDC_TX2_DMIC_CTL, 0x1, 0x1},
8659 {TABLA_A_CDC_TX3_DMIC_CTL, 0x1, 0x1},
8660 {TABLA_A_CDC_TX4_DMIC_CTL, 0x1, 0x1},
8661 {TABLA_A_CDC_TX5_DMIC_CTL, 0x1, 0x1},
8662 {TABLA_A_CDC_TX6_DMIC_CTL, 0x1, 0x1},
8663 {TABLA_A_CDC_TX7_DMIC_CTL, 0x1, 0x1},
8664 {TABLA_A_CDC_TX8_DMIC_CTL, 0x1, 0x1},
8665 {TABLA_A_CDC_TX9_DMIC_CTL, 0x1, 0x1},
8666 {TABLA_A_CDC_TX10_DMIC_CTL, 0x1, 0x1},
8667
8668 /* config DMIC clk to CLK_MODE_1 (3.072Mhz@12.88Mhz mclk) */
8669 {TABLA_A_CDC_CLK_DMIC_CTL, 0x2A, 0x2A},
8670
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008671};
8672
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008673static const struct tabla_reg_mask_val tabla_1_x_codec_reg_init_val[] = {
Kuirong Wangccb29c62012-06-15 11:09:07 -07008674 /* Set the MICBIAS default output as pull down*/
8675 {TABLA_1_A_MICB_4_CTL, 0x01, 0x01},
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008676 /* Initialize mic biases to differential mode */
8677 {TABLA_1_A_MICB_4_INT_RBIAS, 0x24, 0x24},
8678};
8679
8680static const struct tabla_reg_mask_val tabla_2_higher_codec_reg_init_val[] = {
Kuirong Wangccb29c62012-06-15 11:09:07 -07008681
8682 /* Set the MICBIAS default output as pull down*/
8683 {TABLA_2_A_MICB_4_CTL, 0x01, 0x01},
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008684 /* Initialize mic biases to differential mode */
8685 {TABLA_2_A_MICB_4_INT_RBIAS, 0x24, 0x24},
8686};
8687
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008688static void tabla_codec_init_reg(struct snd_soc_codec *codec)
8689{
8690 u32 i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308691 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008692
8693 for (i = 0; i < ARRAY_SIZE(tabla_codec_reg_init_val); i++)
8694 snd_soc_update_bits(codec, tabla_codec_reg_init_val[i].reg,
8695 tabla_codec_reg_init_val[i].mask,
8696 tabla_codec_reg_init_val[i].val);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008697 if (TABLA_IS_1_X(tabla_core->version)) {
8698 for (i = 0; i < ARRAY_SIZE(tabla_1_x_codec_reg_init_val); i++)
8699 snd_soc_update_bits(codec,
8700 tabla_1_x_codec_reg_init_val[i].reg,
8701 tabla_1_x_codec_reg_init_val[i].mask,
8702 tabla_1_x_codec_reg_init_val[i].val);
8703 } else {
8704 for (i = 0; i < ARRAY_SIZE(tabla_2_higher_codec_reg_init_val);
8705 i++)
8706 snd_soc_update_bits(codec,
8707 tabla_2_higher_codec_reg_init_val[i].reg,
8708 tabla_2_higher_codec_reg_init_val[i].mask,
8709 tabla_2_higher_codec_reg_init_val[i].val);
8710 }
8711}
8712
8713static void tabla_update_reg_address(struct tabla_priv *priv)
8714{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308715 struct wcd9xxx *tabla_core = dev_get_drvdata(priv->codec->dev->parent);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008716 struct tabla_reg_address *reg_addr = &priv->reg_addr;
8717
8718 if (TABLA_IS_1_X(tabla_core->version)) {
Joonwoo Parkcb7c8922012-02-16 23:12:59 -08008719 reg_addr->micb_4_mbhc = TABLA_1_A_MICB_4_MBHC;
8720 reg_addr->micb_4_int_rbias = TABLA_1_A_MICB_4_INT_RBIAS;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008721 reg_addr->micb_4_ctl = TABLA_1_A_MICB_4_CTL;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008722 } else if (TABLA_IS_2_0(tabla_core->version)) {
Joonwoo Parkcb7c8922012-02-16 23:12:59 -08008723 reg_addr->micb_4_mbhc = TABLA_2_A_MICB_4_MBHC;
8724 reg_addr->micb_4_int_rbias = TABLA_2_A_MICB_4_INT_RBIAS;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008725 reg_addr->micb_4_ctl = TABLA_2_A_MICB_4_CTL;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008726 }
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008727}
8728
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008729#ifdef CONFIG_DEBUG_FS
8730static int codec_debug_open(struct inode *inode, struct file *file)
8731{
8732 file->private_data = inode->i_private;
8733 return 0;
8734}
8735
8736static ssize_t codec_debug_write(struct file *filp,
8737 const char __user *ubuf, size_t cnt, loff_t *ppos)
8738{
8739 char lbuf[32];
8740 char *buf;
8741 int rc;
8742 struct tabla_priv *tabla = filp->private_data;
8743
8744 if (cnt > sizeof(lbuf) - 1)
8745 return -EINVAL;
8746
8747 rc = copy_from_user(lbuf, ubuf, cnt);
8748 if (rc)
8749 return -EFAULT;
8750
8751 lbuf[cnt] = '\0';
8752 buf = (char *)lbuf;
Joonwoo Park5bbcb0c2012-08-07 17:25:52 -07008753 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
8754 tabla->no_mic_headset_override =
8755 (*strsep(&buf, " ") == '0') ? false : true;
8756 if (tabla->no_mic_headset_override && tabla->mbhc_polling_active) {
8757 tabla_codec_pause_hs_polling(tabla->codec);
8758 tabla_codec_start_hs_polling(tabla->codec);
8759 }
8760 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
8761 return cnt;
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008762}
8763
8764static ssize_t codec_mbhc_debug_read(struct file *file, char __user *buf,
8765 size_t count, loff_t *pos)
8766{
8767 const int size = 768;
8768 char buffer[size];
8769 int n = 0;
8770 struct tabla_priv *tabla = file->private_data;
8771 struct snd_soc_codec *codec = tabla->codec;
8772 const struct mbhc_internal_cal_data *p = &tabla->mbhc_data;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008773 const s16 v_ins_hu_cur = tabla_get_current_v_ins(tabla, true);
8774 const s16 v_ins_h_cur = tabla_get_current_v_ins(tabla, false);
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008775
8776 n = scnprintf(buffer, size - n, "dce_z = %x(%dmv)\n", p->dce_z,
8777 tabla_codec_sta_dce_v(codec, 1, p->dce_z));
8778 n += scnprintf(buffer + n, size - n, "dce_mb = %x(%dmv)\n",
8779 p->dce_mb, tabla_codec_sta_dce_v(codec, 1, p->dce_mb));
8780 n += scnprintf(buffer + n, size - n, "sta_z = %x(%dmv)\n",
8781 p->sta_z, tabla_codec_sta_dce_v(codec, 0, p->sta_z));
8782 n += scnprintf(buffer + n, size - n, "sta_mb = %x(%dmv)\n",
8783 p->sta_mb, tabla_codec_sta_dce_v(codec, 0, p->sta_mb));
8784 n += scnprintf(buffer + n, size - n, "t_dce = %x\n", p->t_dce);
8785 n += scnprintf(buffer + n, size - n, "t_sta = %x\n", p->t_sta);
8786 n += scnprintf(buffer + n, size - n, "micb_mv = %dmv\n",
8787 p->micb_mv);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008788 n += scnprintf(buffer + n, size - n, "v_ins_hu = %x(%dmv)%s\n",
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008789 p->v_ins_hu,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008790 tabla_codec_sta_dce_v(codec, 0, p->v_ins_hu),
8791 p->v_ins_hu == v_ins_hu_cur ? "*" : "");
8792 n += scnprintf(buffer + n, size - n, "v_ins_h = %x(%dmv)%s\n",
8793 p->v_ins_h, tabla_codec_sta_dce_v(codec, 1, p->v_ins_h),
8794 p->v_ins_h == v_ins_h_cur ? "*" : "");
8795 n += scnprintf(buffer + n, size - n, "adj_v_ins_hu = %x(%dmv)%s\n",
8796 p->adj_v_ins_hu,
8797 tabla_codec_sta_dce_v(codec, 0, p->adj_v_ins_hu),
8798 p->adj_v_ins_hu == v_ins_hu_cur ? "*" : "");
8799 n += scnprintf(buffer + n, size - n, "adj_v_ins_h = %x(%dmv)%s\n",
8800 p->adj_v_ins_h,
8801 tabla_codec_sta_dce_v(codec, 1, p->adj_v_ins_h),
8802 p->adj_v_ins_h == v_ins_h_cur ? "*" : "");
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008803 n += scnprintf(buffer + n, size - n, "v_b1_hu = %x(%dmv)\n",
8804 p->v_b1_hu, tabla_codec_sta_dce_v(codec, 0, p->v_b1_hu));
8805 n += scnprintf(buffer + n, size - n, "v_b1_h = %x(%dmv)\n",
8806 p->v_b1_h, tabla_codec_sta_dce_v(codec, 1, p->v_b1_h));
8807 n += scnprintf(buffer + n, size - n, "v_b1_huc = %x(%dmv)\n",
8808 p->v_b1_huc,
8809 tabla_codec_sta_dce_v(codec, 1, p->v_b1_huc));
8810 n += scnprintf(buffer + n, size - n, "v_brh = %x(%dmv)\n",
8811 p->v_brh, tabla_codec_sta_dce_v(codec, 1, p->v_brh));
8812 n += scnprintf(buffer + n, size - n, "v_brl = %x(%dmv)\n", p->v_brl,
8813 tabla_codec_sta_dce_v(codec, 0, p->v_brl));
8814 n += scnprintf(buffer + n, size - n, "v_no_mic = %x(%dmv)\n",
8815 p->v_no_mic,
8816 tabla_codec_sta_dce_v(codec, 0, p->v_no_mic));
8817 n += scnprintf(buffer + n, size - n, "npoll = %d\n", p->npoll);
8818 n += scnprintf(buffer + n, size - n, "nbounce_wait = %d\n",
8819 p->nbounce_wait);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008820 n += scnprintf(buffer + n, size - n, "v_inval_ins_low = %d\n",
8821 p->v_inval_ins_low);
8822 n += scnprintf(buffer + n, size - n, "v_inval_ins_high = %d\n",
8823 p->v_inval_ins_high);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07008824 if (tabla->mbhc_cfg.gpio)
8825 n += scnprintf(buffer + n, size - n, "GPIO insert = %d\n",
8826 tabla_hs_gpio_level_remove(tabla));
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008827 buffer[n] = 0;
8828
8829 return simple_read_from_buffer(buf, count, pos, buffer, n);
8830}
8831
8832static const struct file_operations codec_debug_ops = {
8833 .open = codec_debug_open,
8834 .write = codec_debug_write,
8835};
8836
8837static const struct file_operations codec_mbhc_debug_ops = {
8838 .open = codec_debug_open,
8839 .read = codec_mbhc_debug_read,
8840};
8841#endif
8842
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008843static int tabla_codec_probe(struct snd_soc_codec *codec)
8844{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308845 struct wcd9xxx *control;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008846 struct tabla_priv *tabla;
8847 struct snd_soc_dapm_context *dapm = &codec->dapm;
8848 int ret = 0;
8849 int i;
Kuirong Wang906ac472012-07-09 12:54:44 -07008850 void *ptr = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008851
8852 codec->control_data = dev_get_drvdata(codec->dev->parent);
8853 control = codec->control_data;
8854
8855 tabla = kzalloc(sizeof(struct tabla_priv), GFP_KERNEL);
8856 if (!tabla) {
8857 dev_err(codec->dev, "Failed to allocate private data\n");
8858 return -ENOMEM;
8859 }
Kiran Kandid8cf5212012-03-02 15:34:53 -08008860 for (i = 0 ; i < NUM_DECIMATORS; i++) {
8861 tx_hpf_work[i].tabla = tabla;
8862 tx_hpf_work[i].decimator = i + 1;
8863 INIT_DELAYED_WORK(&tx_hpf_work[i].dwork,
8864 tx_hpf_corner_freq_callback);
8865 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008866
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07008867 /* Make sure mbhc micbias register addresses are zeroed out */
8868 memset(&tabla->mbhc_bias_regs, 0,
8869 sizeof(struct mbhc_micbias_regs));
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07008870 tabla->mbhc_micbias_switched = false;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07008871
Joonwoo Park0976d012011-12-22 11:48:18 -08008872 /* Make sure mbhc intenal calibration data is zeroed out */
8873 memset(&tabla->mbhc_data, 0,
8874 sizeof(struct mbhc_internal_cal_data));
Joonwoo Park433149a2012-01-11 09:53:54 -08008875 tabla->mbhc_data.t_sta_dce = DEFAULT_DCE_STA_WAIT;
Joonwoo Park0976d012011-12-22 11:48:18 -08008876 tabla->mbhc_data.t_dce = DEFAULT_DCE_WAIT;
8877 tabla->mbhc_data.t_sta = DEFAULT_STA_WAIT;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008878 snd_soc_codec_set_drvdata(codec, tabla);
8879
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07008880 tabla->mclk_enabled = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008881 tabla->bandgap_type = TABLA_BANDGAP_OFF;
8882 tabla->clock_active = false;
8883 tabla->config_mode_active = false;
8884 tabla->mbhc_polling_active = false;
Joonwoo Parkf4267c22012-01-10 13:25:24 -08008885 tabla->mbhc_fake_ins_start = 0;
Bradley Rubincb3950a2011-08-18 13:07:26 -07008886 tabla->no_mic_headset_override = false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008887 tabla->hs_polling_irq_prepared = false;
8888 mutex_init(&tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008889 tabla->codec = codec;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008890 tabla->mbhc_state = MBHC_STATE_NONE;
Joonwoo Park03324832012-03-19 19:36:16 -07008891 tabla->mbhc_last_resume = 0;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08008892 for (i = 0; i < COMPANDER_MAX; i++) {
8893 tabla->comp_enabled[i] = 0;
8894 tabla->comp_fs[i] = COMPANDER_FS_48KHZ;
8895 }
Patrick Lai3043fba2011-08-01 14:15:57 -07008896 tabla->pdata = dev_get_platdata(codec->dev->parent);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308897 tabla->intf_type = wcd9xxx_get_intf_type();
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08008898 tabla->aux_pga_cnt = 0;
8899 tabla->aux_l_gain = 0x1F;
8900 tabla->aux_r_gain = 0x1F;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008901 tabla_update_reg_address(tabla);
Santosh Mardi22920282011-10-26 02:38:40 +05308902 tabla_update_reg_defaults(codec);
8903 tabla_codec_init_reg(codec);
Santosh Mardi22920282011-10-26 02:38:40 +05308904 ret = tabla_handle_pdata(tabla);
Patrick Lai3043fba2011-08-01 14:15:57 -07008905 if (IS_ERR_VALUE(ret)) {
8906 pr_err("%s: bad pdata\n", __func__);
8907 goto err_pdata;
8908 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008909
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008910 if (TABLA_IS_1_X(control->version))
Steve Mucklef132c6c2012-06-06 18:30:57 -07008911 snd_soc_add_codec_controls(codec, tabla_1_x_snd_controls,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008912 ARRAY_SIZE(tabla_1_x_snd_controls));
8913 else
Steve Mucklef132c6c2012-06-06 18:30:57 -07008914 snd_soc_add_codec_controls(codec, tabla_2_higher_snd_controls,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008915 ARRAY_SIZE(tabla_2_higher_snd_controls));
8916
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008917 if (TABLA_IS_1_X(control->version))
8918 snd_soc_dapm_new_controls(dapm, tabla_1_x_dapm_widgets,
8919 ARRAY_SIZE(tabla_1_x_dapm_widgets));
8920 else
8921 snd_soc_dapm_new_controls(dapm, tabla_2_higher_dapm_widgets,
8922 ARRAY_SIZE(tabla_2_higher_dapm_widgets));
8923
Kuirong Wang906ac472012-07-09 12:54:44 -07008924 ptr = kmalloc((sizeof(tabla_rx_chs) +
8925 sizeof(tabla_tx_chs)), GFP_KERNEL);
8926 if (!ptr) {
8927 pr_err("%s: no mem for slim chan ctl data\n", __func__);
8928 ret = -ENOMEM;
8929 goto err_nomem_slimch;
8930 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308931 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05308932 snd_soc_dapm_new_controls(dapm, tabla_dapm_i2s_widgets,
8933 ARRAY_SIZE(tabla_dapm_i2s_widgets));
8934 snd_soc_dapm_add_routes(dapm, audio_i2s_map,
8935 ARRAY_SIZE(audio_i2s_map));
Kuirong Wang906ac472012-07-09 12:54:44 -07008936 for (i = 0; i < ARRAY_SIZE(tabla_i2s_dai); i++)
8937 INIT_LIST_HEAD(&tabla->dai[i].wcd9xxx_ch_list);
8938 } else if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
8939 for (i = 0; i < NUM_CODEC_DAIS; i++) {
8940 INIT_LIST_HEAD(&tabla->dai[i].wcd9xxx_ch_list);
8941 init_waitqueue_head(&tabla->dai[i].dai_wait);
8942 }
Santosh Mardie15e2302011-11-15 10:39:23 +05308943 }
Kuirong Wang906ac472012-07-09 12:54:44 -07008944
8945 control->num_rx_port = TABLA_RX_MAX;
8946 control->rx_chs = ptr;
8947 memcpy(control->rx_chs, tabla_rx_chs, sizeof(tabla_rx_chs));
8948 control->num_tx_port = TABLA_TX_MAX;
8949 control->tx_chs = ptr + sizeof(tabla_rx_chs);
8950 memcpy(control->tx_chs, tabla_tx_chs, sizeof(tabla_tx_chs));
8951
Kiran Kandi8b3a8302011-09-27 16:13:28 -07008952
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008953 if (TABLA_IS_1_X(control->version)) {
Kiran Kandi7a9fd902011-11-14 13:51:45 -08008954 snd_soc_dapm_add_routes(dapm, tabla_1_x_lineout_2_to_4_map,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008955 ARRAY_SIZE(tabla_1_x_lineout_2_to_4_map));
8956 } else if (TABLA_IS_2_0(control->version)) {
Kiran Kandi7a9fd902011-11-14 13:51:45 -08008957 snd_soc_dapm_add_routes(dapm, tabla_2_x_lineout_2_to_4_map,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008958 ARRAY_SIZE(tabla_2_x_lineout_2_to_4_map));
Kiran Kandi7a9fd902011-11-14 13:51:45 -08008959 } else {
8960 pr_err("%s : ERROR. Unsupported Tabla version 0x%2x\n",
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308961 __func__, control->version);
Kiran Kandi7a9fd902011-11-14 13:51:45 -08008962 goto err_pdata;
8963 }
8964
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008965 snd_soc_dapm_sync(dapm);
8966
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008967 ret = wcd9xxx_request_irq(codec->control_data,
8968 WCD9XXX_IRQ_MBHC_INSERTION,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008969 tabla_hs_insert_irq, "Headset insert detect", tabla);
8970 if (ret) {
8971 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008972 WCD9XXX_IRQ_MBHC_INSERTION);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008973 goto err_insert_irq;
8974 }
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008975 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008976
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008977 ret = wcd9xxx_request_irq(codec->control_data,
8978 WCD9XXX_IRQ_MBHC_REMOVAL,
8979 tabla_hs_remove_irq,
8980 "Headset remove detect", tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008981 if (ret) {
8982 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008983 WCD9XXX_IRQ_MBHC_REMOVAL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008984 goto err_remove_irq;
8985 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008986
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008987 ret = wcd9xxx_request_irq(codec->control_data,
8988 WCD9XXX_IRQ_MBHC_POTENTIAL,
8989 tabla_dce_handler, "DC Estimation detect",
8990 tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008991 if (ret) {
8992 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008993 WCD9XXX_IRQ_MBHC_POTENTIAL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008994 goto err_potential_irq;
8995 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008996
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008997 ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE,
8998 tabla_release_handler,
8999 "Button Release detect", tabla);
Bradley Rubincb1e2732011-06-23 16:49:20 -07009000 if (ret) {
9001 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009002 WCD9XXX_IRQ_MBHC_RELEASE);
Bradley Rubincb1e2732011-06-23 16:49:20 -07009003 goto err_release_irq;
9004 }
9005
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009006 ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS,
9007 tabla_slimbus_irq, "SLIMBUS Slave", tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009008 if (ret) {
9009 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009010 WCD9XXX_IRQ_SLIMBUS);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009011 goto err_slimbus_irq;
9012 }
9013
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05309014 for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++)
9015 wcd9xxx_interface_reg_write(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009016 TABLA_SLIM_PGD_PORT_INT_EN0 + i, 0xFF);
9017
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05309018 ret = wcd9xxx_request_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009019 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT,
9020 tabla_hphl_ocp_irq,
9021 "HPH_L OCP detect", tabla);
Patrick Lai49efeac2011-11-03 11:01:12 -07009022 if (ret) {
9023 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009024 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07009025 goto err_hphl_ocp_irq;
9026 }
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009027 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07009028
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05309029 ret = wcd9xxx_request_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009030 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT,
9031 tabla_hphr_ocp_irq,
9032 "HPH_R OCP detect", tabla);
Patrick Lai49efeac2011-11-03 11:01:12 -07009033 if (ret) {
9034 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009035 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07009036 goto err_hphr_ocp_irq;
9037 }
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009038 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07009039
9040 /*
9041 * Register suspend lock and notifier to resend edge triggered
9042 * gpio IRQs
9043 */
9044 wake_lock_init(&tabla->irq_resend_wlock, WAKE_LOCK_SUSPEND,
9045 "tabla_gpio_irq_resend");
9046 tabla->gpio_irq_resend = false;
9047
Damir Didjustoc6f83cb2012-12-03 00:54:14 -08009048 mutex_lock(&dapm->codec->mutex);
9049 snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
9050 snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
9051 snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE");
9052 snd_soc_dapm_sync(dapm);
9053 mutex_unlock(&dapm->codec->mutex);
Patrick Lai49efeac2011-11-03 11:01:12 -07009054
Bradley Rubincb3950a2011-08-18 13:07:26 -07009055#ifdef CONFIG_DEBUG_FS
Joonwoo Park179b9ec2012-03-26 10:56:20 -07009056 if (ret == 0) {
9057 tabla->debugfs_poke =
9058 debugfs_create_file("TRRS", S_IFREG | S_IRUGO, NULL, tabla,
9059 &codec_debug_ops);
9060 tabla->debugfs_mbhc =
9061 debugfs_create_file("tabla_mbhc", S_IFREG | S_IRUGO,
9062 NULL, tabla, &codec_mbhc_debug_ops);
9063 }
Bradley Rubincb3950a2011-08-18 13:07:26 -07009064#endif
Steve Mucklef132c6c2012-06-06 18:30:57 -07009065 codec->ignore_pmdown_time = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009066 return ret;
9067
Patrick Lai49efeac2011-11-03 11:01:12 -07009068err_hphr_ocp_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05309069 wcd9xxx_free_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009070 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT, tabla);
Patrick Lai49efeac2011-11-03 11:01:12 -07009071err_hphl_ocp_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009072 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009073err_slimbus_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009074 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, tabla);
Bradley Rubincb1e2732011-06-23 16:49:20 -07009075err_release_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009076 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL,
9077 tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009078err_potential_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009079 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_REMOVAL, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009080err_remove_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009081 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION,
9082 tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009083err_insert_irq:
Patrick Lai3043fba2011-08-01 14:15:57 -07009084err_pdata:
Kuirong Wang906ac472012-07-09 12:54:44 -07009085 kfree(ptr);
9086err_nomem_slimch:
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07009087 mutex_destroy(&tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009088 kfree(tabla);
9089 return ret;
9090}
9091static int tabla_codec_remove(struct snd_soc_codec *codec)
9092{
9093 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07009094
9095 wake_lock_destroy(&tabla->irq_resend_wlock);
9096
Joonwoo Parkf6574c72012-10-10 17:29:57 -07009097 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, tabla);
9098 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, tabla);
9099 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL,
9100 tabla);
9101 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_REMOVAL, tabla);
9102 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION,
9103 tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07009104 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009105 tabla_codec_disable_clock_block(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07009106 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009107 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF);
Patrick Lai64b43262011-12-06 17:29:15 -08009108 if (tabla->mbhc_fw)
9109 release_firmware(tabla->mbhc_fw);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07009110 mutex_destroy(&tabla->codec_resource_lock);
Joonwoo Park179b9ec2012-03-26 10:56:20 -07009111#ifdef CONFIG_DEBUG_FS
9112 debugfs_remove(tabla->debugfs_poke);
9113 debugfs_remove(tabla->debugfs_mbhc);
9114#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009115 kfree(tabla);
9116 return 0;
9117}
9118static struct snd_soc_codec_driver soc_codec_dev_tabla = {
9119 .probe = tabla_codec_probe,
9120 .remove = tabla_codec_remove,
9121 .read = tabla_read,
9122 .write = tabla_write,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009123 .readable_register = tabla_readable,
9124 .volatile_register = tabla_volatile,
9125
9126 .reg_cache_size = TABLA_CACHE_SIZE,
9127 .reg_cache_default = tabla_reg_defaults,
9128 .reg_word_size = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07009129 .controls = tabla_snd_controls,
9130 .num_controls = ARRAY_SIZE(tabla_snd_controls),
9131 .dapm_widgets = tabla_dapm_widgets,
9132 .num_dapm_widgets = ARRAY_SIZE(tabla_dapm_widgets),
9133 .dapm_routes = audio_map,
9134 .num_dapm_routes = ARRAY_SIZE(audio_map),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009135};
Bradley Rubincb3950a2011-08-18 13:07:26 -07009136
Joonwoo Park8b1f0982011-12-08 17:12:45 -08009137#ifdef CONFIG_PM
9138static int tabla_suspend(struct device *dev)
9139{
Joonwoo Park816b8e62012-01-23 16:03:21 -08009140 dev_dbg(dev, "%s: system suspend\n", __func__);
9141 return 0;
Joonwoo Park8b1f0982011-12-08 17:12:45 -08009142}
9143
9144static int tabla_resume(struct device *dev)
9145{
Joonwoo Parkecf379c2012-10-04 16:57:52 -07009146 int irq;
Joonwoo Park03324832012-03-19 19:36:16 -07009147 struct platform_device *pdev = to_platform_device(dev);
9148 struct tabla_priv *tabla = platform_get_drvdata(pdev);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07009149
Joonwoo Parkd6e48bd2012-09-20 11:14:15 -07009150 dev_dbg(dev, "%s: system resume tabla %p\n", __func__, tabla);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07009151 if (tabla) {
9152 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Joonwoo Parkd6e48bd2012-09-20 11:14:15 -07009153 tabla->mbhc_last_resume = jiffies;
Joonwoo Parkecf379c2012-10-04 16:57:52 -07009154 if (tabla->gpio_irq_resend) {
9155 WARN_ON(!tabla->mbhc_cfg.gpio_irq);
9156 tabla->gpio_irq_resend = false;
9157
9158 irq = tabla->mbhc_cfg.gpio_irq;
9159 pr_debug("%s: Resending GPIO IRQ %d\n", __func__, irq);
9160 irq_set_pending(irq);
9161 check_irq_resend(irq_to_desc(irq), irq);
9162
9163 /* release suspend lock */
9164 wake_unlock(&tabla->irq_resend_wlock);
9165 }
9166 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
9167 }
9168
Joonwoo Park816b8e62012-01-23 16:03:21 -08009169 return 0;
Joonwoo Park8b1f0982011-12-08 17:12:45 -08009170}
9171
9172static const struct dev_pm_ops tabla_pm_ops = {
9173 .suspend = tabla_suspend,
9174 .resume = tabla_resume,
9175};
9176#endif
9177
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009178static int __devinit tabla_probe(struct platform_device *pdev)
9179{
Santosh Mardie15e2302011-11-15 10:39:23 +05309180 int ret = 0;
Steve Mucklef132c6c2012-06-06 18:30:57 -07009181 pr_err("tabla_probe\n");
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05309182 if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
Santosh Mardie15e2302011-11-15 10:39:23 +05309183 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla,
9184 tabla_dai, ARRAY_SIZE(tabla_dai));
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05309185 else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C)
Santosh Mardie15e2302011-11-15 10:39:23 +05309186 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla,
9187 tabla_i2s_dai, ARRAY_SIZE(tabla_i2s_dai));
9188 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009189}
9190static int __devexit tabla_remove(struct platform_device *pdev)
9191{
9192 snd_soc_unregister_codec(&pdev->dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009193 return 0;
9194}
9195static struct platform_driver tabla_codec_driver = {
9196 .probe = tabla_probe,
9197 .remove = tabla_remove,
9198 .driver = {
9199 .name = "tabla_codec",
9200 .owner = THIS_MODULE,
Joonwoo Park8b1f0982011-12-08 17:12:45 -08009201#ifdef CONFIG_PM
9202 .pm = &tabla_pm_ops,
9203#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009204 },
9205};
9206
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08009207static struct platform_driver tabla1x_codec_driver = {
9208 .probe = tabla_probe,
9209 .remove = tabla_remove,
9210 .driver = {
9211 .name = "tabla1x_codec",
9212 .owner = THIS_MODULE,
9213#ifdef CONFIG_PM
9214 .pm = &tabla_pm_ops,
9215#endif
9216 },
9217};
9218
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009219static int __init tabla_codec_init(void)
9220{
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08009221 int rtn = platform_driver_register(&tabla_codec_driver);
9222 if (rtn == 0) {
9223 rtn = platform_driver_register(&tabla1x_codec_driver);
9224 if (rtn != 0)
9225 platform_driver_unregister(&tabla_codec_driver);
9226 }
9227 return rtn;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009228}
9229
9230static void __exit tabla_codec_exit(void)
9231{
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08009232 platform_driver_unregister(&tabla1x_codec_driver);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07009233 platform_driver_unregister(&tabla_codec_driver);
9234}
9235
9236module_init(tabla_codec_init);
9237module_exit(tabla_codec_exit);
9238
9239MODULE_DESCRIPTION("Tabla codec driver");
9240MODULE_VERSION("1.0");
9241MODULE_LICENSE("GPL v2");