blob: 2f7fdcff6cb2827ca28375a91244b7ad12b4b1a5 [file] [log] [blame]
Simmi Pateriya21375012012-11-26 23:06:01 +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
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -070057
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -070058#define SLIM_CLOSE_TIMEOUT 1000
59
Joonwoo Park03324832012-03-19 19:36:16 -070060enum {
61 MBHC_USE_HPHL_TRIGGER = 1,
62 MBHC_USE_MB_TRIGGER = 2
63};
64
65#define MBHC_NUM_DCE_PLUG_DETECT 3
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -070066#define NUM_ATTEMPTS_INSERT_DETECT 25
67#define NUM_ATTEMPTS_TO_REPORT 5
Joonwoo Park03324832012-03-19 19:36:16 -070068
Joonwoo Park2cc13f02012-05-09 12:44:25 -070069#define TABLA_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | \
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -070070 SND_JACK_OC_HPHR | SND_JACK_LINEOUT | \
71 SND_JACK_UNSUPPORTED)
Patrick Lai49efeac2011-11-03 11:01:12 -070072
Santosh Mardie15e2302011-11-15 10:39:23 +053073#define TABLA_I2S_MASTER_MODE_MASK 0x08
74
Patrick Laic7cae882011-11-18 11:52:49 -080075#define TABLA_OCP_ATTEMPT 1
76
Kuirong Wang906ac472012-07-09 12:54:44 -070077enum {
78 AIF1_PB = 0,
79 AIF1_CAP,
80 AIF2_PB,
81 AIF2_CAP,
82 AIF3_PB,
83 AIF3_CAP,
84 NUM_CODEC_DAIS,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -080085};
86
Kuirong Wang906ac472012-07-09 12:54:44 -070087enum {
88 RX_MIX1_INP_SEL_ZERO = 0,
89 RX_MIX1_INP_SEL_SRC1,
90 RX_MIX1_INP_SEL_SRC2,
91 RX_MIX1_INP_SEL_IIR1,
92 RX_MIX1_INP_SEL_IIR2,
93 RX_MIX1_INP_SEL_RX1,
94 RX_MIX1_INP_SEL_RX2,
95 RX_MIX1_INP_SEL_RX3,
96 RX_MIX1_INP_SEL_RX4,
97 RX_MIX1_INP_SEL_RX5,
98 RX_MIX1_INP_SEL_RX6,
99 RX_MIX1_INP_SEL_RX7,
100};
101
102#define TABLA_COMP_DIGITAL_GAIN_OFFSET 3
103
Joonwoo Park0976d012011-12-22 11:48:18 -0800104#define TABLA_MCLK_RATE_12288KHZ 12288000
105#define TABLA_MCLK_RATE_9600KHZ 9600000
106
Joonwoo Parkf4267c22012-01-10 13:25:24 -0800107#define TABLA_FAKE_INS_THRESHOLD_MS 2500
Joonwoo Park6b9b03f2012-01-23 18:48:54 -0800108#define TABLA_FAKE_REMOVAL_MIN_PERIOD_MS 50
Joonwoo Parkf4267c22012-01-10 13:25:24 -0800109
Joonwoo Park03324832012-03-19 19:36:16 -0700110#define TABLA_MBHC_BUTTON_MIN 0x8000
111
Joonwoo Park03324832012-03-19 19:36:16 -0700112#define TABLA_MBHC_FAKE_INSERT_LOW 10
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700113#define TABLA_MBHC_FAKE_INSERT_HIGH 80
114#define TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO 150
Joonwoo Park03324832012-03-19 19:36:16 -0700115
116#define TABLA_MBHC_STATUS_REL_DETECTION 0x0C
117
Joonwoo Parkdb606b02012-08-11 13:46:30 -0700118#define TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS 50
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700119
Joonwoo Parkcf473b42012-03-29 19:48:16 -0700120#define TABLA_MBHC_FAKE_INS_DELTA_MV 200
121#define TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV 300
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700122
123#define TABLA_HS_DETECT_PLUG_TIME_MS (5 * 1000)
124#define TABLA_HS_DETECT_PLUG_INERVAL_MS 100
125
126#define TABLA_GPIO_IRQ_DEBOUNCE_TIME_US 5000
127
Joonwoo Park2cc13f02012-05-09 12:44:25 -0700128#define TABLA_MBHC_GND_MIC_SWAP_THRESHOLD 2
129
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700130#define TABLA_ACQUIRE_LOCK(x) do { mutex_lock(&x); } while (0)
131#define TABLA_RELEASE_LOCK(x) do { mutex_unlock(&x); } while (0)
132
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
134static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
135static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800136static struct snd_soc_dai_driver tabla_dai[];
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -0800137static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0);
Kiran Kandi93923902012-06-20 17:00:25 -0700138static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
139 struct snd_kcontrol *kcontrol, int event);
140static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
141 struct snd_kcontrol *kcontrol, int event);
142
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700143
144enum tabla_bandgap_type {
145 TABLA_BANDGAP_OFF = 0,
146 TABLA_BANDGAP_AUDIO_MODE,
147 TABLA_BANDGAP_MBHC_MODE,
148};
149
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700150struct mbhc_micbias_regs {
151 u16 cfilt_val;
152 u16 cfilt_ctl;
153 u16 mbhc_reg;
154 u16 int_rbias;
155 u16 ctl_reg;
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -0800156 u8 cfilt_sel;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700157};
158
Ben Romberger1f045a72011-11-04 10:14:57 -0700159/* Codec supports 2 IIR filters */
160enum {
161 IIR1 = 0,
162 IIR2,
163 IIR_MAX,
164};
165/* Codec supports 5 bands */
166enum {
167 BAND1 = 0,
168 BAND2,
169 BAND3,
170 BAND4,
171 BAND5,
172 BAND_MAX,
173};
174
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800175enum {
176 COMPANDER_1 = 0,
177 COMPANDER_2,
178 COMPANDER_MAX,
179};
180
181enum {
182 COMPANDER_FS_8KHZ = 0,
183 COMPANDER_FS_16KHZ,
184 COMPANDER_FS_32KHZ,
185 COMPANDER_FS_48KHZ,
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700186 COMPANDER_FS_96KHZ,
187 COMPANDER_FS_192KHZ,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800188 COMPANDER_FS_MAX,
189};
190
Joonwoo Parka9444452011-12-08 18:48:27 -0800191/* Flags to track of PA and DAC state.
192 * PA and DAC should be tracked separately as AUXPGA loopback requires
193 * only PA to be turned on without DAC being on. */
194enum tabla_priv_ack_flags {
195 TABLA_HPHL_PA_OFF_ACK = 0,
196 TABLA_HPHR_PA_OFF_ACK,
197 TABLA_HPHL_DAC_OFF_ACK,
198 TABLA_HPHR_DAC_OFF_ACK
199};
200
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800201
202struct comp_sample_dependent_params {
203 u32 peak_det_timeout;
204 u32 rms_meter_div_fact;
205 u32 rms_meter_resamp_fact;
206};
207
Joonwoo Park0976d012011-12-22 11:48:18 -0800208/* Data used by MBHC */
209struct mbhc_internal_cal_data {
210 u16 dce_z;
211 u16 dce_mb;
212 u16 sta_z;
213 u16 sta_mb;
Joonwoo Park433149a2012-01-11 09:53:54 -0800214 u32 t_sta_dce;
Joonwoo Park0976d012011-12-22 11:48:18 -0800215 u32 t_dce;
216 u32 t_sta;
217 u32 micb_mv;
218 u16 v_ins_hu;
219 u16 v_ins_h;
220 u16 v_b1_hu;
221 u16 v_b1_h;
222 u16 v_b1_huc;
223 u16 v_brh;
224 u16 v_brl;
225 u16 v_no_mic;
Joonwoo Park0976d012011-12-22 11:48:18 -0800226 u8 npoll;
227 u8 nbounce_wait;
Joonwoo Parkcf473b42012-03-29 19:48:16 -0700228 s16 adj_v_hs_max;
229 u16 adj_v_ins_hu;
230 u16 adj_v_ins_h;
231 s16 v_inval_ins_low;
232 s16 v_inval_ins_high;
Joonwoo Park0976d012011-12-22 11:48:18 -0800233};
234
Joonwoo Park6c1ebb62012-01-16 19:08:43 -0800235struct tabla_reg_address {
236 u16 micb_4_ctl;
237 u16 micb_4_int_rbias;
238 u16 micb_4_mbhc;
239};
240
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700241enum tabla_mbhc_plug_type {
Joonwoo Park41956722012-04-18 13:13:07 -0700242 PLUG_TYPE_INVALID = -1,
243 PLUG_TYPE_NONE,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700244 PLUG_TYPE_HEADSET,
245 PLUG_TYPE_HEADPHONE,
246 PLUG_TYPE_HIGH_HPH,
Joonwoo Park2cc13f02012-05-09 12:44:25 -0700247 PLUG_TYPE_GND_MIC_SWAP,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700248};
249
250enum tabla_mbhc_state {
251 MBHC_STATE_NONE = -1,
252 MBHC_STATE_POTENTIAL,
253 MBHC_STATE_POTENTIAL_RECOVERY,
254 MBHC_STATE_RELEASE,
255};
256
Kiran Kandid8cf5212012-03-02 15:34:53 -0800257struct hpf_work {
258 struct tabla_priv *tabla;
259 u32 decimator;
260 u8 tx_hpf_cut_of_freq;
261 struct delayed_work dwork;
262};
263
264static struct hpf_work tx_hpf_work[NUM_DECIMATORS];
265
Kuirong Wang906ac472012-07-09 12:54:44 -0700266static const struct wcd9xxx_ch tabla_rx_chs[TABLA_RX_MAX] = {
267 WCD9XXX_CH(10, 0),
268 WCD9XXX_CH(11, 1),
269 WCD9XXX_CH(12, 2),
270 WCD9XXX_CH(13, 3),
271 WCD9XXX_CH(14, 4),
272 WCD9XXX_CH(15, 5),
273 WCD9XXX_CH(16, 6)
274};
275
276static const struct wcd9xxx_ch tabla_tx_chs[TABLA_TX_MAX] = {
277 WCD9XXX_CH(0, 0),
278 WCD9XXX_CH(1, 1),
279 WCD9XXX_CH(2, 2),
280 WCD9XXX_CH(3, 3),
281 WCD9XXX_CH(4, 4),
282 WCD9XXX_CH(5, 5),
283 WCD9XXX_CH(6, 6),
284 WCD9XXX_CH(7, 7),
285 WCD9XXX_CH(8, 8),
286 WCD9XXX_CH(9, 9)
287};
288
289static const u32 vport_check_table[NUM_CODEC_DAIS] = {
290 0, /* AIF1_PB */
291 (1 << AIF2_CAP) | (1 << AIF3_CAP), /* AIF1_CAP */
292 0, /* AIF2_PB */
293 (1 << AIF1_CAP) | (1 << AIF3_CAP), /* AIF2_CAP */
294 0, /* AIF2_PB */
295 (1 << AIF1_CAP) | (1 << AIF2_CAP), /* AIF2_CAP */
296};
297
Bradley Rubin229c6a52011-07-12 16:18:48 -0700298struct tabla_priv {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700299 struct snd_soc_codec *codec;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -0800300 struct tabla_reg_address reg_addr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700301 u32 adc_count;
Patrick Lai3043fba2011-08-01 14:15:57 -0700302 u32 cfilt1_cnt;
303 u32 cfilt2_cnt;
304 u32 cfilt3_cnt;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -0700305 u32 rx_bias_count;
Kiran Kandi0ba468f2012-05-08 11:45:05 -0700306 s32 dmic_1_2_clk_cnt;
307 s32 dmic_3_4_clk_cnt;
308 s32 dmic_5_6_clk_cnt;
309
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700310 enum tabla_bandgap_type bandgap_type;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -0700311 bool mclk_enabled;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700312 bool clock_active;
313 bool config_mode_active;
314 bool mbhc_polling_active;
Joonwoo Parkf4267c22012-01-10 13:25:24 -0800315 unsigned long mbhc_fake_ins_start;
Bradley Rubincb1e2732011-06-23 16:49:20 -0700316 int buttons_pressed;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700317 enum tabla_mbhc_state mbhc_state;
318 struct tabla_mbhc_config mbhc_cfg;
Joonwoo Park0976d012011-12-22 11:48:18 -0800319 struct mbhc_internal_cal_data mbhc_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700320
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530321 struct wcd9xxx_pdata *pdata;
Bradley Rubina7096d02011-08-03 18:29:02 -0700322 u32 anc_slot;
Bradley Rubincb3950a2011-08-18 13:07:26 -0700323
324 bool no_mic_headset_override;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -0700325 /* Delayed work to report long button press */
Joonwoo Park03324832012-03-19 19:36:16 -0700326 struct delayed_work mbhc_btn_dwork;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700327
328 struct mbhc_micbias_regs mbhc_bias_regs;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -0700329 bool mbhc_micbias_switched;
Patrick Lai49efeac2011-11-03 11:01:12 -0700330
Joonwoo Parka9444452011-12-08 18:48:27 -0800331 /* track PA/DAC state */
332 unsigned long hph_pa_dac_state;
333
Santosh Mardie15e2302011-11-15 10:39:23 +0530334 /*track tabla interface type*/
335 u8 intf_type;
336
Patrick Lai49efeac2011-11-03 11:01:12 -0700337 u32 hph_status; /* track headhpone status */
338 /* define separate work for left and right headphone OCP to avoid
339 * additional checking on which OCP event to report so no locking
340 * to ensure synchronization is required
341 */
342 struct work_struct hphlocp_work; /* reporting left hph ocp off */
343 struct work_struct hphrocp_work; /* reporting right hph ocp off */
Joonwoo Park8b1f0982011-12-08 17:12:45 -0800344
Patrick Laic7cae882011-11-18 11:52:49 -0800345 u8 hphlocp_cnt; /* headphone left ocp retry */
346 u8 hphrocp_cnt; /* headphone right ocp retry */
Joonwoo Park0976d012011-12-22 11:48:18 -0800347
Patrick Lai64b43262011-12-06 17:29:15 -0800348 /* Work to perform MBHC Firmware Read */
349 struct delayed_work mbhc_firmware_dwork;
350 const struct firmware *mbhc_fw;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800351
352 /* num of slim ports required */
Kuirong Wang906ac472012-07-09 12:54:44 -0700353 struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS];
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800354
355 /*compander*/
356 int comp_enabled[COMPANDER_MAX];
357 u32 comp_fs[COMPANDER_MAX];
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -0800358
359 /* Maintain the status of AUX PGA */
360 int aux_pga_cnt;
361 u8 aux_l_gain;
362 u8 aux_r_gain;
Joonwoo Park03324832012-03-19 19:36:16 -0700363
Joonwoo Park03324832012-03-19 19:36:16 -0700364 struct delayed_work mbhc_insert_dwork;
365 unsigned long mbhc_last_resume; /* in jiffies */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700366
367 u8 current_plug;
368 struct work_struct hs_correct_plug_work;
369 bool hs_detect_work_stop;
370 bool hs_polling_irq_prepared;
371 bool lpi_enabled; /* low power insertion detection */
372 bool in_gpio_handler;
373 /* Currently, only used for mbhc purpose, to protect
374 * concurrent execution of mbhc threaded irq handlers and
375 * kill race between DAPM and MBHC.But can serve as a
376 * general lock to protect codec resource
377 */
378 struct mutex codec_resource_lock;
379
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -0700380 /* Work to perform polling on microphone voltage
381 * in order to correct plug type once plug type
382 * is detected as headphone
383 */
384 struct work_struct hs_correct_plug_work_nogpio;
385
Joonwoo Parkecf379c2012-10-04 16:57:52 -0700386 bool gpio_irq_resend;
387 struct wake_lock irq_resend_wlock;
388
Bradley Rubincb3950a2011-08-18 13:07:26 -0700389#ifdef CONFIG_DEBUG_FS
Joonwoo Park179b9ec2012-03-26 10:56:20 -0700390 struct dentry *debugfs_poke;
391 struct dentry *debugfs_mbhc;
Bradley Rubincb3950a2011-08-18 13:07:26 -0700392#endif
Joonwoo Park179b9ec2012-03-26 10:56:20 -0700393};
394
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800395static const u32 comp_shift[] = {
396 0,
397 2,
398};
399
400static const int comp_rx_path[] = {
401 COMPANDER_1,
402 COMPANDER_1,
403 COMPANDER_2,
404 COMPANDER_2,
405 COMPANDER_2,
406 COMPANDER_2,
407 COMPANDER_MAX,
408};
409
410static const struct comp_sample_dependent_params comp_samp_params[] = {
411 {
412 .peak_det_timeout = 0x2,
413 .rms_meter_div_fact = 0x8 << 4,
414 .rms_meter_resamp_fact = 0x21,
415 },
416 {
417 .peak_det_timeout = 0x3,
418 .rms_meter_div_fact = 0x9 << 4,
419 .rms_meter_resamp_fact = 0x28,
420 },
421
422 {
423 .peak_det_timeout = 0x5,
424 .rms_meter_div_fact = 0xB << 4,
425 .rms_meter_resamp_fact = 0x28,
426 },
427
428 {
429 .peak_det_timeout = 0x5,
430 .rms_meter_div_fact = 0xB << 4,
431 .rms_meter_resamp_fact = 0x28,
432 },
433};
434
Kuirong Wange9c8a222012-03-28 16:24:09 -0700435static unsigned short rx_digital_gain_reg[] = {
436 TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
437 TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
438 TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
439 TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
440 TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
441 TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
442 TABLA_A_CDC_RX7_VOL_CTL_B2_CTL,
443};
444
445
446static unsigned short tx_digital_gain_reg[] = {
447 TABLA_A_CDC_TX1_VOL_CTL_GAIN,
448 TABLA_A_CDC_TX2_VOL_CTL_GAIN,
449 TABLA_A_CDC_TX3_VOL_CTL_GAIN,
450 TABLA_A_CDC_TX4_VOL_CTL_GAIN,
451 TABLA_A_CDC_TX5_VOL_CTL_GAIN,
452 TABLA_A_CDC_TX6_VOL_CTL_GAIN,
453 TABLA_A_CDC_TX7_VOL_CTL_GAIN,
454 TABLA_A_CDC_TX8_VOL_CTL_GAIN,
455 TABLA_A_CDC_TX9_VOL_CTL_GAIN,
456 TABLA_A_CDC_TX10_VOL_CTL_GAIN,
457};
458
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700459static int tabla_codec_enable_charge_pump(struct snd_soc_dapm_widget *w,
460 struct snd_kcontrol *kcontrol, int event)
461{
462 struct snd_soc_codec *codec = w->codec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700463
464 pr_debug("%s %d\n", __func__, event);
465 switch (event) {
466 case SND_SOC_DAPM_POST_PMU:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700467 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
468 0x01);
469 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x08);
470 usleep_range(200, 200);
471 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x00);
472 break;
473 case SND_SOC_DAPM_PRE_PMD:
474 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10,
475 0x10);
476 usleep_range(20, 20);
477 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x08);
478 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x10);
479 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x00);
480 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
481 0x00);
482 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700483 break;
484 }
485 return 0;
486}
487
Bradley Rubina7096d02011-08-03 18:29:02 -0700488static int tabla_get_anc_slot(struct snd_kcontrol *kcontrol,
489 struct snd_ctl_elem_value *ucontrol)
490{
491 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
492 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
493 ucontrol->value.integer.value[0] = tabla->anc_slot;
494 return 0;
495}
496
497static int tabla_put_anc_slot(struct snd_kcontrol *kcontrol,
498 struct snd_ctl_elem_value *ucontrol)
499{
500 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
501 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
502 tabla->anc_slot = ucontrol->value.integer.value[0];
503 return 0;
504}
505
Kiran Kandid2d86b52011-09-09 17:44:28 -0700506static int tabla_pa_gain_get(struct snd_kcontrol *kcontrol,
507 struct snd_ctl_elem_value *ucontrol)
508{
509 u8 ear_pa_gain;
510 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
511
512 ear_pa_gain = snd_soc_read(codec, TABLA_A_RX_EAR_GAIN);
513
514 ear_pa_gain = ear_pa_gain >> 5;
515
516 if (ear_pa_gain == 0x00) {
517 ucontrol->value.integer.value[0] = 0;
518 } else if (ear_pa_gain == 0x04) {
519 ucontrol->value.integer.value[0] = 1;
520 } else {
521 pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n",
522 __func__, ear_pa_gain);
523 return -EINVAL;
524 }
525
526 pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain);
527
528 return 0;
529}
530
531static int tabla_pa_gain_put(struct snd_kcontrol *kcontrol,
532 struct snd_ctl_elem_value *ucontrol)
533{
534 u8 ear_pa_gain;
535 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
536
537 pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__,
538 ucontrol->value.integer.value[0]);
539
540 switch (ucontrol->value.integer.value[0]) {
541 case 0:
542 ear_pa_gain = 0x00;
543 break;
544 case 1:
545 ear_pa_gain = 0x80;
546 break;
547 default:
548 return -EINVAL;
549 }
550
551 snd_soc_update_bits(codec, TABLA_A_RX_EAR_GAIN, 0xE0, ear_pa_gain);
552 return 0;
553}
554
Ben Romberger1f045a72011-11-04 10:14:57 -0700555static int tabla_get_iir_enable_audio_mixer(
556 struct snd_kcontrol *kcontrol,
557 struct snd_ctl_elem_value *ucontrol)
558{
559 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
560 int iir_idx = ((struct soc_multi_mixer_control *)
561 kcontrol->private_value)->reg;
562 int band_idx = ((struct soc_multi_mixer_control *)
563 kcontrol->private_value)->shift;
564
565 ucontrol->value.integer.value[0] =
566 snd_soc_read(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx)) &
567 (1 << band_idx);
568
569 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
570 iir_idx, band_idx,
571 (uint32_t)ucontrol->value.integer.value[0]);
572 return 0;
573}
574
575static int tabla_put_iir_enable_audio_mixer(
576 struct snd_kcontrol *kcontrol,
577 struct snd_ctl_elem_value *ucontrol)
578{
579 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
580 int iir_idx = ((struct soc_multi_mixer_control *)
581 kcontrol->private_value)->reg;
582 int band_idx = ((struct soc_multi_mixer_control *)
583 kcontrol->private_value)->shift;
584 int value = ucontrol->value.integer.value[0];
585
586 /* Mask first 5 bits, 6-8 are reserved */
587 snd_soc_update_bits(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx),
588 (1 << band_idx), (value << band_idx));
589
590 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
591 iir_idx, band_idx, value);
592 return 0;
593}
594static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
595 int iir_idx, int band_idx,
596 int coeff_idx)
597{
598 /* Address does not automatically update if reading */
Ben Romberger0915aae2012-02-06 23:32:43 -0800599 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700600 (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800601 (band_idx * BAND_MAX + coeff_idx) & 0x1F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700602
603 /* Mask bits top 2 bits since they are reserved */
604 return ((snd_soc_read(codec,
605 (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 24) |
606 (snd_soc_read(codec,
607 (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx)) << 16) |
608 (snd_soc_read(codec,
609 (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx)) << 8) |
610 (snd_soc_read(codec,
611 (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx)))) &
612 0x3FFFFFFF;
613}
614
615static int tabla_get_iir_band_audio_mixer(
616 struct snd_kcontrol *kcontrol,
617 struct snd_ctl_elem_value *ucontrol)
618{
619 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
620 int iir_idx = ((struct soc_multi_mixer_control *)
621 kcontrol->private_value)->reg;
622 int band_idx = ((struct soc_multi_mixer_control *)
623 kcontrol->private_value)->shift;
624
625 ucontrol->value.integer.value[0] =
626 get_iir_band_coeff(codec, iir_idx, band_idx, 0);
627 ucontrol->value.integer.value[1] =
628 get_iir_band_coeff(codec, iir_idx, band_idx, 1);
629 ucontrol->value.integer.value[2] =
630 get_iir_band_coeff(codec, iir_idx, band_idx, 2);
631 ucontrol->value.integer.value[3] =
632 get_iir_band_coeff(codec, iir_idx, band_idx, 3);
633 ucontrol->value.integer.value[4] =
634 get_iir_band_coeff(codec, iir_idx, band_idx, 4);
635
636 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
637 "%s: IIR #%d band #%d b1 = 0x%x\n"
638 "%s: IIR #%d band #%d b2 = 0x%x\n"
639 "%s: IIR #%d band #%d a1 = 0x%x\n"
640 "%s: IIR #%d band #%d a2 = 0x%x\n",
641 __func__, iir_idx, band_idx,
642 (uint32_t)ucontrol->value.integer.value[0],
643 __func__, iir_idx, band_idx,
644 (uint32_t)ucontrol->value.integer.value[1],
645 __func__, iir_idx, band_idx,
646 (uint32_t)ucontrol->value.integer.value[2],
647 __func__, iir_idx, band_idx,
648 (uint32_t)ucontrol->value.integer.value[3],
649 __func__, iir_idx, band_idx,
650 (uint32_t)ucontrol->value.integer.value[4]);
651 return 0;
652}
653
654static void set_iir_band_coeff(struct snd_soc_codec *codec,
655 int iir_idx, int band_idx,
656 int coeff_idx, uint32_t value)
657{
658 /* Mask top 3 bits, 6-8 are reserved */
659 /* Update address manually each time */
Ben Romberger0915aae2012-02-06 23:32:43 -0800660 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700661 (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800662 (band_idx * BAND_MAX + coeff_idx) & 0x1F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700663
664 /* Mask top 2 bits, 7-8 are reserved */
Ben Romberger0915aae2012-02-06 23:32:43 -0800665 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700666 (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800667 (value >> 24) & 0x3F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700668
669 /* Isolate 8bits at a time */
Ben Romberger0915aae2012-02-06 23:32:43 -0800670 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700671 (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800672 (value >> 16) & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700673
Ben Romberger0915aae2012-02-06 23:32:43 -0800674 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700675 (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800676 (value >> 8) & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700677
Ben Romberger0915aae2012-02-06 23:32:43 -0800678 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700679 (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800680 value & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700681}
682
683static int tabla_put_iir_band_audio_mixer(
684 struct snd_kcontrol *kcontrol,
685 struct snd_ctl_elem_value *ucontrol)
686{
687 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
688 int iir_idx = ((struct soc_multi_mixer_control *)
689 kcontrol->private_value)->reg;
690 int band_idx = ((struct soc_multi_mixer_control *)
691 kcontrol->private_value)->shift;
692
693 set_iir_band_coeff(codec, iir_idx, band_idx, 0,
694 ucontrol->value.integer.value[0]);
695 set_iir_band_coeff(codec, iir_idx, band_idx, 1,
696 ucontrol->value.integer.value[1]);
697 set_iir_band_coeff(codec, iir_idx, band_idx, 2,
698 ucontrol->value.integer.value[2]);
699 set_iir_band_coeff(codec, iir_idx, band_idx, 3,
700 ucontrol->value.integer.value[3]);
701 set_iir_band_coeff(codec, iir_idx, band_idx, 4,
702 ucontrol->value.integer.value[4]);
703
704 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
705 "%s: IIR #%d band #%d b1 = 0x%x\n"
706 "%s: IIR #%d band #%d b2 = 0x%x\n"
707 "%s: IIR #%d band #%d a1 = 0x%x\n"
708 "%s: IIR #%d band #%d a2 = 0x%x\n",
709 __func__, iir_idx, band_idx,
710 get_iir_band_coeff(codec, iir_idx, band_idx, 0),
711 __func__, iir_idx, band_idx,
712 get_iir_band_coeff(codec, iir_idx, band_idx, 1),
713 __func__, iir_idx, band_idx,
714 get_iir_band_coeff(codec, iir_idx, band_idx, 2),
715 __func__, iir_idx, band_idx,
716 get_iir_band_coeff(codec, iir_idx, band_idx, 3),
717 __func__, iir_idx, band_idx,
718 get_iir_band_coeff(codec, iir_idx, band_idx, 4));
719 return 0;
720}
721
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800722static int tabla_compander_gain_offset(
723 struct snd_soc_codec *codec, u32 enable,
724 unsigned int reg, int mask, int event)
725{
726 int pa_mode = snd_soc_read(codec, reg) & mask;
727 int gain_offset = 0;
728 /* if PMU && enable is 1-> offset is 3
729 * if PMU && enable is 0-> offset is 0
730 * if PMD && pa_mode is PA -> offset is 0: PMU compander is off
731 * if PMD && pa_mode is comp -> offset is -3: PMU compander is on.
732 */
733
734 if (SND_SOC_DAPM_EVENT_ON(event) && (enable != 0))
735 gain_offset = TABLA_COMP_DIGITAL_GAIN_OFFSET;
736 if (SND_SOC_DAPM_EVENT_OFF(event) && (pa_mode == 0))
737 gain_offset = -TABLA_COMP_DIGITAL_GAIN_OFFSET;
738 return gain_offset;
739}
740
741
742static int tabla_config_gain_compander(
743 struct snd_soc_codec *codec,
744 u32 compander, u32 enable, int event)
745{
746 int value = 0;
747 int mask = 1 << 4;
748 int gain = 0;
749 int gain_offset;
750 if (compander >= COMPANDER_MAX) {
751 pr_err("%s: Error, invalid compander channel\n", __func__);
752 return -EINVAL;
753 }
754
755 if ((enable == 0) || SND_SOC_DAPM_EVENT_OFF(event))
756 value = 1 << 4;
757
758 if (compander == COMPANDER_1) {
759 gain_offset = tabla_compander_gain_offset(codec, enable,
760 TABLA_A_RX_HPH_L_GAIN, mask, event);
761 snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_GAIN, mask, value);
762 gain = snd_soc_read(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL);
763 snd_soc_update_bits(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
764 0xFF, gain - gain_offset);
765 gain_offset = tabla_compander_gain_offset(codec, enable,
766 TABLA_A_RX_HPH_R_GAIN, mask, event);
767 snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_GAIN, mask, value);
768 gain = snd_soc_read(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL);
769 snd_soc_update_bits(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
770 0xFF, gain - gain_offset);
771 } else if (compander == COMPANDER_2) {
772 gain_offset = tabla_compander_gain_offset(codec, enable,
773 TABLA_A_RX_LINE_1_GAIN, mask, event);
774 snd_soc_update_bits(codec, TABLA_A_RX_LINE_1_GAIN, mask, value);
775 gain = snd_soc_read(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL);
776 snd_soc_update_bits(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
777 0xFF, gain - gain_offset);
778 gain_offset = tabla_compander_gain_offset(codec, enable,
779 TABLA_A_RX_LINE_3_GAIN, mask, event);
780 snd_soc_update_bits(codec, TABLA_A_RX_LINE_3_GAIN, mask, value);
781 gain = snd_soc_read(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL);
782 snd_soc_update_bits(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
783 0xFF, gain - gain_offset);
784 gain_offset = tabla_compander_gain_offset(codec, enable,
785 TABLA_A_RX_LINE_2_GAIN, mask, event);
786 snd_soc_update_bits(codec, TABLA_A_RX_LINE_2_GAIN, mask, value);
787 gain = snd_soc_read(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL);
788 snd_soc_update_bits(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
789 0xFF, gain - gain_offset);
790 gain_offset = tabla_compander_gain_offset(codec, enable,
791 TABLA_A_RX_LINE_4_GAIN, mask, event);
792 snd_soc_update_bits(codec, TABLA_A_RX_LINE_4_GAIN, mask, value);
793 gain = snd_soc_read(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL);
794 snd_soc_update_bits(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
795 0xFF, gain - gain_offset);
796 }
797 return 0;
798}
799static int tabla_get_compander(struct snd_kcontrol *kcontrol,
800 struct snd_ctl_elem_value *ucontrol)
801{
802
803 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
804 int comp = ((struct soc_multi_mixer_control *)
805 kcontrol->private_value)->max;
806 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
807
808 ucontrol->value.integer.value[0] = tabla->comp_enabled[comp];
809
810 return 0;
811}
812
813static int tabla_set_compander(struct snd_kcontrol *kcontrol,
814 struct snd_ctl_elem_value *ucontrol)
815{
816 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
817 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
818 int comp = ((struct soc_multi_mixer_control *)
819 kcontrol->private_value)->max;
820 int value = ucontrol->value.integer.value[0];
821
822 if (value == tabla->comp_enabled[comp]) {
823 pr_debug("%s: compander #%d enable %d no change\n",
824 __func__, comp, value);
825 return 0;
826 }
827 tabla->comp_enabled[comp] = value;
828 return 0;
829}
830
831
832static int tabla_config_compander(struct snd_soc_dapm_widget *w,
833 struct snd_kcontrol *kcontrol,
834 int event)
835{
836 struct snd_soc_codec *codec = w->codec;
837 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
838 u32 rate = tabla->comp_fs[w->shift];
839
840 switch (event) {
841 case SND_SOC_DAPM_PRE_PMU:
842 if (tabla->comp_enabled[w->shift] != 0) {
843 /* Enable both L/R compander clocks */
844 snd_soc_update_bits(codec,
845 TABLA_A_CDC_CLK_RX_B2_CTL,
846 0x03 << comp_shift[w->shift],
847 0x03 << comp_shift[w->shift]);
848 /* Clar the HALT for the compander*/
849 snd_soc_update_bits(codec,
850 TABLA_A_CDC_COMP1_B1_CTL +
851 w->shift * 8, 1 << 2, 0);
852 /* Toggle compander reset bits*/
853 snd_soc_update_bits(codec,
854 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
855 0x03 << comp_shift[w->shift],
856 0x03 << comp_shift[w->shift]);
857 snd_soc_update_bits(codec,
858 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
859 0x03 << comp_shift[w->shift], 0);
860 tabla_config_gain_compander(codec, w->shift, 1, event);
861 /* Update the RMS meter resampling*/
862 snd_soc_update_bits(codec,
863 TABLA_A_CDC_COMP1_B3_CTL +
864 w->shift * 8, 0xFF, 0x01);
865 /* Wait for 1ms*/
866 usleep_range(1000, 1000);
867 }
868 break;
869 case SND_SOC_DAPM_POST_PMU:
870 /* Set sample rate dependent paramater*/
871 if (tabla->comp_enabled[w->shift] != 0) {
872 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_FS_CFG +
873 w->shift * 8, 0x03, rate);
874 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL +
875 w->shift * 8, 0x0F,
876 comp_samp_params[rate].peak_det_timeout);
877 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL +
878 w->shift * 8, 0xF0,
879 comp_samp_params[rate].rms_meter_div_fact);
880 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B3_CTL +
881 w->shift * 8, 0xFF,
882 comp_samp_params[rate].rms_meter_resamp_fact);
883 /* Compander enable -> 0x370/0x378*/
884 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
885 w->shift * 8, 0x03, 0x03);
886 }
887 break;
888 case SND_SOC_DAPM_PRE_PMD:
889 /* Halt the compander*/
890 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
891 w->shift * 8, 1 << 2, 1 << 2);
892 break;
893 case SND_SOC_DAPM_POST_PMD:
894 /* Restore the gain */
895 tabla_config_gain_compander(codec, w->shift,
896 tabla->comp_enabled[w->shift], event);
897 /* Disable the compander*/
898 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
899 w->shift * 8, 0x03, 0x00);
900 /* Turn off the clock for compander in pair*/
901 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_B2_CTL,
902 0x03 << comp_shift[w->shift], 0);
903 break;
904 }
905 return 0;
906}
907
Kiran Kandid2d86b52011-09-09 17:44:28 -0700908static const char *tabla_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"};
909static const struct soc_enum tabla_ear_pa_gain_enum[] = {
910 SOC_ENUM_SINGLE_EXT(2, tabla_ear_pa_gain_text),
911};
912
Santosh Mardi024010f2011-10-18 06:27:21 +0530913/*cut of frequency for high pass filter*/
914static const char *cf_text[] = {
915 "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz"
916};
917
918static const struct soc_enum cf_dec1_enum =
919 SOC_ENUM_SINGLE(TABLA_A_CDC_TX1_MUX_CTL, 4, 3, cf_text);
920
921static const struct soc_enum cf_dec2_enum =
922 SOC_ENUM_SINGLE(TABLA_A_CDC_TX2_MUX_CTL, 4, 3, cf_text);
923
924static const struct soc_enum cf_dec3_enum =
925 SOC_ENUM_SINGLE(TABLA_A_CDC_TX3_MUX_CTL, 4, 3, cf_text);
926
927static const struct soc_enum cf_dec4_enum =
928 SOC_ENUM_SINGLE(TABLA_A_CDC_TX4_MUX_CTL, 4, 3, cf_text);
929
930static const struct soc_enum cf_dec5_enum =
931 SOC_ENUM_SINGLE(TABLA_A_CDC_TX5_MUX_CTL, 4, 3, cf_text);
932
933static const struct soc_enum cf_dec6_enum =
934 SOC_ENUM_SINGLE(TABLA_A_CDC_TX6_MUX_CTL, 4, 3, cf_text);
935
936static const struct soc_enum cf_dec7_enum =
937 SOC_ENUM_SINGLE(TABLA_A_CDC_TX7_MUX_CTL, 4, 3, cf_text);
938
939static const struct soc_enum cf_dec8_enum =
940 SOC_ENUM_SINGLE(TABLA_A_CDC_TX8_MUX_CTL, 4, 3, cf_text);
941
942static const struct soc_enum cf_dec9_enum =
943 SOC_ENUM_SINGLE(TABLA_A_CDC_TX9_MUX_CTL, 4, 3, cf_text);
944
945static const struct soc_enum cf_dec10_enum =
946 SOC_ENUM_SINGLE(TABLA_A_CDC_TX10_MUX_CTL, 4, 3, cf_text);
947
948static const struct soc_enum cf_rxmix1_enum =
949 SOC_ENUM_SINGLE(TABLA_A_CDC_RX1_B4_CTL, 1, 3, cf_text);
950
951static const struct soc_enum cf_rxmix2_enum =
952 SOC_ENUM_SINGLE(TABLA_A_CDC_RX2_B4_CTL, 1, 3, cf_text);
953
954static const struct soc_enum cf_rxmix3_enum =
955 SOC_ENUM_SINGLE(TABLA_A_CDC_RX3_B4_CTL, 1, 3, cf_text);
956
957static const struct soc_enum cf_rxmix4_enum =
958 SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B4_CTL, 1, 3, cf_text);
959
960static const struct soc_enum cf_rxmix5_enum =
961 SOC_ENUM_SINGLE(TABLA_A_CDC_RX5_B4_CTL, 1, 3, cf_text)
962;
963static const struct soc_enum cf_rxmix6_enum =
964 SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B4_CTL, 1, 3, cf_text);
965
966static const struct soc_enum cf_rxmix7_enum =
967 SOC_ENUM_SINGLE(TABLA_A_CDC_RX7_B4_CTL, 1, 3, cf_text);
968
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700969static const struct snd_kcontrol_new tabla_snd_controls[] = {
Kiran Kandid2d86b52011-09-09 17:44:28 -0700970
971 SOC_ENUM_EXT("EAR PA Gain", tabla_ear_pa_gain_enum[0],
972 tabla_pa_gain_get, tabla_pa_gain_put),
973
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700974 SOC_SINGLE_TLV("LINEOUT1 Volume", TABLA_A_RX_LINE_1_GAIN, 0, 12, 1,
975 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700976 SOC_SINGLE_TLV("LINEOUT2 Volume", TABLA_A_RX_LINE_2_GAIN, 0, 12, 1,
977 line_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700978 SOC_SINGLE_TLV("LINEOUT3 Volume", TABLA_A_RX_LINE_3_GAIN, 0, 12, 1,
979 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700980 SOC_SINGLE_TLV("LINEOUT4 Volume", TABLA_A_RX_LINE_4_GAIN, 0, 12, 1,
981 line_gain),
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -0700982 SOC_SINGLE_TLV("LINEOUT5 Volume", TABLA_A_RX_LINE_5_GAIN, 0, 12, 1,
983 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700984
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700985 SOC_SINGLE_TLV("HPHL Volume", TABLA_A_RX_HPH_L_GAIN, 0, 12, 1,
986 line_gain),
987 SOC_SINGLE_TLV("HPHR Volume", TABLA_A_RX_HPH_R_GAIN, 0, 12, 1,
988 line_gain),
989
Bradley Rubin410383f2011-07-22 13:44:23 -0700990 SOC_SINGLE_S8_TLV("RX1 Digital Volume", TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
991 -84, 40, digital_gain),
992 SOC_SINGLE_S8_TLV("RX2 Digital Volume", TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
993 -84, 40, digital_gain),
994 SOC_SINGLE_S8_TLV("RX3 Digital Volume", TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
995 -84, 40, digital_gain),
996 SOC_SINGLE_S8_TLV("RX4 Digital Volume", TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
997 -84, 40, digital_gain),
998 SOC_SINGLE_S8_TLV("RX5 Digital Volume", TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
999 -84, 40, digital_gain),
1000 SOC_SINGLE_S8_TLV("RX6 Digital Volume", TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
1001 -84, 40, digital_gain),
Neema Shettyd3a89262012-02-16 10:23:50 -08001002 SOC_SINGLE_S8_TLV("RX7 Digital Volume", TABLA_A_CDC_RX7_VOL_CTL_B2_CTL,
1003 -84, 40, digital_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001004
Bradley Rubin410383f2011-07-22 13:44:23 -07001005 SOC_SINGLE_S8_TLV("DEC1 Volume", TABLA_A_CDC_TX1_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001006 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -07001007 SOC_SINGLE_S8_TLV("DEC2 Volume", TABLA_A_CDC_TX2_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001008 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -07001009 SOC_SINGLE_S8_TLV("DEC3 Volume", TABLA_A_CDC_TX3_VOL_CTL_GAIN, -84, 40,
1010 digital_gain),
1011 SOC_SINGLE_S8_TLV("DEC4 Volume", TABLA_A_CDC_TX4_VOL_CTL_GAIN, -84, 40,
1012 digital_gain),
1013 SOC_SINGLE_S8_TLV("DEC5 Volume", TABLA_A_CDC_TX5_VOL_CTL_GAIN, -84, 40,
1014 digital_gain),
1015 SOC_SINGLE_S8_TLV("DEC6 Volume", TABLA_A_CDC_TX6_VOL_CTL_GAIN, -84, 40,
1016 digital_gain),
1017 SOC_SINGLE_S8_TLV("DEC7 Volume", TABLA_A_CDC_TX7_VOL_CTL_GAIN, -84, 40,
1018 digital_gain),
1019 SOC_SINGLE_S8_TLV("DEC8 Volume", TABLA_A_CDC_TX8_VOL_CTL_GAIN, -84, 40,
1020 digital_gain),
1021 SOC_SINGLE_S8_TLV("DEC9 Volume", TABLA_A_CDC_TX9_VOL_CTL_GAIN, -84, 40,
1022 digital_gain),
1023 SOC_SINGLE_S8_TLV("DEC10 Volume", TABLA_A_CDC_TX10_VOL_CTL_GAIN, -84,
1024 40, digital_gain),
Patrick Lai29006372011-09-28 17:57:42 -07001025 SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TABLA_A_CDC_IIR1_GAIN_B1_CTL, -84,
1026 40, digital_gain),
1027 SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TABLA_A_CDC_IIR1_GAIN_B2_CTL, -84,
1028 40, digital_gain),
1029 SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TABLA_A_CDC_IIR1_GAIN_B3_CTL, -84,
1030 40, digital_gain),
1031 SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TABLA_A_CDC_IIR1_GAIN_B4_CTL, -84,
1032 40, digital_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001033 SOC_SINGLE_TLV("ADC1 Volume", TABLA_A_TX_1_2_EN, 5, 3, 0, analog_gain),
1034 SOC_SINGLE_TLV("ADC2 Volume", TABLA_A_TX_1_2_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001035 SOC_SINGLE_TLV("ADC3 Volume", TABLA_A_TX_3_4_EN, 5, 3, 0, analog_gain),
1036 SOC_SINGLE_TLV("ADC4 Volume", TABLA_A_TX_3_4_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001037 SOC_SINGLE_TLV("ADC5 Volume", TABLA_A_TX_5_6_EN, 5, 3, 0, analog_gain),
1038 SOC_SINGLE_TLV("ADC6 Volume", TABLA_A_TX_5_6_EN, 1, 3, 0, analog_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001039
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001040 SOC_SINGLE_TLV("AUX_PGA_LEFT Volume", TABLA_A_AUX_L_GAIN, 0, 39, 0,
1041 aux_pga_gain),
1042 SOC_SINGLE_TLV("AUX_PGA_RIGHT Volume", TABLA_A_AUX_R_GAIN, 0, 39, 0,
1043 aux_pga_gain),
1044
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001045 SOC_SINGLE("MICBIAS1 CAPLESS Switch", TABLA_A_MICB_1_CTL, 4, 1, 1),
Santosh Mardi680b41e2011-11-22 16:51:16 -08001046 SOC_SINGLE("MICBIAS2 CAPLESS Switch", TABLA_A_MICB_2_CTL, 4, 1, 1),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001047 SOC_SINGLE("MICBIAS3 CAPLESS Switch", TABLA_A_MICB_3_CTL, 4, 1, 1),
Bradley Rubina7096d02011-08-03 18:29:02 -07001048
1049 SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 0, 100, tabla_get_anc_slot,
1050 tabla_put_anc_slot),
Santosh Mardi024010f2011-10-18 06:27:21 +05301051 SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
1052 SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
1053 SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
1054 SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
1055 SOC_ENUM("TX5 HPF cut off", cf_dec5_enum),
1056 SOC_ENUM("TX6 HPF cut off", cf_dec6_enum),
1057 SOC_ENUM("TX7 HPF cut off", cf_dec7_enum),
1058 SOC_ENUM("TX8 HPF cut off", cf_dec8_enum),
1059 SOC_ENUM("TX9 HPF cut off", cf_dec9_enum),
1060 SOC_ENUM("TX10 HPF cut off", cf_dec10_enum),
1061
1062 SOC_SINGLE("TX1 HPF Switch", TABLA_A_CDC_TX1_MUX_CTL, 3, 1, 0),
1063 SOC_SINGLE("TX2 HPF Switch", TABLA_A_CDC_TX2_MUX_CTL, 3, 1, 0),
1064 SOC_SINGLE("TX3 HPF Switch", TABLA_A_CDC_TX3_MUX_CTL, 3, 1, 0),
1065 SOC_SINGLE("TX4 HPF Switch", TABLA_A_CDC_TX4_MUX_CTL, 3, 1, 0),
1066 SOC_SINGLE("TX5 HPF Switch", TABLA_A_CDC_TX5_MUX_CTL, 3, 1, 0),
1067 SOC_SINGLE("TX6 HPF Switch", TABLA_A_CDC_TX6_MUX_CTL, 3, 1, 0),
1068 SOC_SINGLE("TX7 HPF Switch", TABLA_A_CDC_TX7_MUX_CTL, 3, 1, 0),
1069 SOC_SINGLE("TX8 HPF Switch", TABLA_A_CDC_TX8_MUX_CTL, 3, 1, 0),
1070 SOC_SINGLE("TX9 HPF Switch", TABLA_A_CDC_TX9_MUX_CTL, 3, 1, 0),
1071 SOC_SINGLE("TX10 HPF Switch", TABLA_A_CDC_TX10_MUX_CTL, 3, 1, 0),
1072
1073 SOC_SINGLE("RX1 HPF Switch", TABLA_A_CDC_RX1_B5_CTL, 2, 1, 0),
1074 SOC_SINGLE("RX2 HPF Switch", TABLA_A_CDC_RX2_B5_CTL, 2, 1, 0),
1075 SOC_SINGLE("RX3 HPF Switch", TABLA_A_CDC_RX3_B5_CTL, 2, 1, 0),
1076 SOC_SINGLE("RX4 HPF Switch", TABLA_A_CDC_RX4_B5_CTL, 2, 1, 0),
1077 SOC_SINGLE("RX5 HPF Switch", TABLA_A_CDC_RX5_B5_CTL, 2, 1, 0),
1078 SOC_SINGLE("RX6 HPF Switch", TABLA_A_CDC_RX6_B5_CTL, 2, 1, 0),
1079 SOC_SINGLE("RX7 HPF Switch", TABLA_A_CDC_RX7_B5_CTL, 2, 1, 0),
1080
1081 SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum),
1082 SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum),
1083 SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum),
1084 SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum),
1085 SOC_ENUM("RX5 HPF cut off", cf_rxmix5_enum),
1086 SOC_ENUM("RX6 HPF cut off", cf_rxmix6_enum),
1087 SOC_ENUM("RX7 HPF cut off", cf_rxmix7_enum),
Ben Romberger1f045a72011-11-04 10:14:57 -07001088
1089 SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
1090 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1091 SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
1092 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1093 SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
1094 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1095 SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
1096 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1097 SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
1098 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1099 SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0,
1100 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1101 SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0,
1102 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1103 SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0,
1104 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1105 SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0,
1106 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1107 SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0,
1108 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1109
1110 SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
1111 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1112 SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
1113 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1114 SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
1115 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1116 SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
1117 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1118 SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
1119 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1120 SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5,
1121 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1122 SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5,
1123 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1124 SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5,
1125 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1126 SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5,
1127 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1128 SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5,
1129 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001130 SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, 1, COMPANDER_1, 0,
1131 tabla_get_compander, tabla_set_compander),
1132 SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, 0, COMPANDER_2, 0,
1133 tabla_get_compander, tabla_set_compander),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001134};
1135
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08001136static const struct snd_kcontrol_new tabla_1_x_snd_controls[] = {
1137 SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_1_A_MICB_4_CTL, 4, 1, 1),
1138};
1139
1140static const struct snd_kcontrol_new tabla_2_higher_snd_controls[] = {
1141 SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_2_A_MICB_4_CTL, 4, 1, 1),
1142};
1143
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001144static const char *rx_mix1_text[] = {
1145 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
1146 "RX5", "RX6", "RX7"
1147};
1148
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001149static const char *rx_mix2_text[] = {
1150 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2"
1151};
1152
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001153static const char *rx_dsm_text[] = {
1154 "CIC_OUT", "DSM_INV"
1155};
1156
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001157static const char *sb_tx1_mux_text[] = {
1158 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1159 "DEC1"
1160};
1161
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001162static const char *sb_tx2_mux_text[] = {
1163 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1164 "DEC2"
1165};
1166
1167static const char *sb_tx3_mux_text[] = {
1168 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1169 "DEC3"
1170};
1171
1172static const char *sb_tx4_mux_text[] = {
1173 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1174 "DEC4"
1175};
1176
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001177static const char *sb_tx5_mux_text[] = {
1178 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1179 "DEC5"
1180};
1181
1182static const char *sb_tx6_mux_text[] = {
1183 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1184 "DEC6"
1185};
1186
1187static const char const *sb_tx7_to_tx10_mux_text[] = {
1188 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1189 "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
1190 "DEC9", "DEC10"
1191};
1192
1193static const char *dec1_mux_text[] = {
1194 "ZERO", "DMIC1", "ADC6",
1195};
1196
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001197static const char *dec2_mux_text[] = {
1198 "ZERO", "DMIC2", "ADC5",
1199};
1200
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001201static const char *dec3_mux_text[] = {
1202 "ZERO", "DMIC3", "ADC4",
1203};
1204
1205static const char *dec4_mux_text[] = {
1206 "ZERO", "DMIC4", "ADC3",
1207};
1208
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001209static const char *dec5_mux_text[] = {
1210 "ZERO", "DMIC5", "ADC2",
1211};
1212
1213static const char *dec6_mux_text[] = {
1214 "ZERO", "DMIC6", "ADC1",
1215};
1216
1217static const char const *dec7_mux_text[] = {
1218 "ZERO", "DMIC1", "DMIC6", "ADC1", "ADC6", "ANC1_FB", "ANC2_FB",
1219};
1220
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001221static const char *dec8_mux_text[] = {
1222 "ZERO", "DMIC2", "DMIC5", "ADC2", "ADC5",
1223};
1224
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001225static const char *dec9_mux_text[] = {
1226 "ZERO", "DMIC4", "DMIC5", "ADC2", "ADC3", "ADCMB", "ANC1_FB", "ANC2_FB",
1227};
1228
1229static const char *dec10_mux_text[] = {
1230 "ZERO", "DMIC3", "DMIC6", "ADC1", "ADC4", "ADCMB", "ANC1_FB", "ANC2_FB",
1231};
1232
Bradley Rubin229c6a52011-07-12 16:18:48 -07001233static const char const *anc_mux_text[] = {
1234 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6", "ADC_MB",
1235 "RSVD_1", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", "DMIC6"
1236};
1237
1238static const char const *anc1_fb_mux_text[] = {
1239 "ZERO", "EAR_HPH_L", "EAR_LINE_1",
1240};
1241
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001242static const char *iir1_inp1_text[] = {
1243 "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
1244 "DEC9", "DEC10", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7"
1245};
1246
1247static const struct soc_enum rx_mix1_inp1_chain_enum =
1248 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_mix1_text);
1249
Bradley Rubin229c6a52011-07-12 16:18:48 -07001250static const struct soc_enum rx_mix1_inp2_chain_enum =
1251 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_mix1_text);
1252
Kiran Kandia9fffe92012-05-20 23:42:30 -07001253static const struct soc_enum rx_mix1_inp3_chain_enum =
1254 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B2_CTL, 0, 12, rx_mix1_text);
1255
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001256static const struct soc_enum rx2_mix1_inp1_chain_enum =
1257 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_mix1_text);
1258
Bradley Rubin229c6a52011-07-12 16:18:48 -07001259static const struct soc_enum rx2_mix1_inp2_chain_enum =
1260 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_mix1_text);
1261
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001262static const struct soc_enum rx3_mix1_inp1_chain_enum =
1263 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 0, 12, rx_mix1_text);
1264
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001265static const struct soc_enum rx3_mix1_inp2_chain_enum =
1266 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 4, 12, rx_mix1_text);
1267
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001268static const struct soc_enum rx4_mix1_inp1_chain_enum =
1269 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 0, 12, rx_mix1_text);
1270
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001271static const struct soc_enum rx4_mix1_inp2_chain_enum =
1272 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 4, 12, rx_mix1_text);
1273
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001274static const struct soc_enum rx5_mix1_inp1_chain_enum =
1275 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 0, 12, rx_mix1_text);
1276
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001277static const struct soc_enum rx5_mix1_inp2_chain_enum =
1278 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 4, 12, rx_mix1_text);
1279
1280static const struct soc_enum rx6_mix1_inp1_chain_enum =
1281 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 0, 12, rx_mix1_text);
1282
1283static const struct soc_enum rx6_mix1_inp2_chain_enum =
1284 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 4, 12, rx_mix1_text);
1285
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001286static const struct soc_enum rx7_mix1_inp1_chain_enum =
1287 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 0, 12, rx_mix1_text);
1288
1289static const struct soc_enum rx7_mix1_inp2_chain_enum =
1290 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 4, 12, rx_mix1_text);
1291
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001292static const struct soc_enum rx1_mix2_inp1_chain_enum =
1293 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text);
1294
1295static const struct soc_enum rx1_mix2_inp2_chain_enum =
1296 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text);
1297
1298static const struct soc_enum rx2_mix2_inp1_chain_enum =
1299 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text);
1300
1301static const struct soc_enum rx2_mix2_inp2_chain_enum =
1302 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text);
1303
1304static const struct soc_enum rx3_mix2_inp1_chain_enum =
1305 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 0, 5, rx_mix2_text);
1306
1307static const struct soc_enum rx3_mix2_inp2_chain_enum =
1308 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 3, 5, rx_mix2_text);
1309
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001310static const struct soc_enum rx4_dsm_enum =
1311 SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B6_CTL, 4, 2, rx_dsm_text);
1312
1313static const struct soc_enum rx6_dsm_enum =
1314 SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B6_CTL, 4, 2, rx_dsm_text);
1315
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001316static const struct soc_enum sb_tx1_mux_enum =
1317 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text);
1318
1319static const struct soc_enum sb_tx2_mux_enum =
1320 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0, 9, sb_tx2_mux_text);
1321
1322static const struct soc_enum sb_tx3_mux_enum =
1323 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0, 9, sb_tx3_mux_text);
1324
1325static const struct soc_enum sb_tx4_mux_enum =
1326 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0, 9, sb_tx4_mux_text);
1327
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001328static const struct soc_enum sb_tx5_mux_enum =
1329 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text);
1330
1331static const struct soc_enum sb_tx6_mux_enum =
1332 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0, 9, sb_tx6_mux_text);
1333
1334static const struct soc_enum sb_tx7_mux_enum =
1335 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0, 18,
1336 sb_tx7_to_tx10_mux_text);
1337
1338static const struct soc_enum sb_tx8_mux_enum =
1339 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0, 18,
1340 sb_tx7_to_tx10_mux_text);
1341
Kiran Kandi3426e512011-09-13 22:50:10 -07001342static const struct soc_enum sb_tx9_mux_enum =
1343 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0, 18,
1344 sb_tx7_to_tx10_mux_text);
1345
1346static const struct soc_enum sb_tx10_mux_enum =
1347 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0, 18,
1348 sb_tx7_to_tx10_mux_text);
1349
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001350static const struct soc_enum dec1_mux_enum =
1351 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 0, 3, dec1_mux_text);
1352
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001353static const struct soc_enum dec2_mux_enum =
1354 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 2, 3, dec2_mux_text);
1355
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001356static const struct soc_enum dec3_mux_enum =
1357 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 4, 3, dec3_mux_text);
1358
1359static const struct soc_enum dec4_mux_enum =
1360 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 6, 3, dec4_mux_text);
1361
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001362static const struct soc_enum dec5_mux_enum =
1363 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 0, 3, dec5_mux_text);
1364
1365static const struct soc_enum dec6_mux_enum =
1366 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 2, 3, dec6_mux_text);
1367
1368static const struct soc_enum dec7_mux_enum =
1369 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 4, 7, dec7_mux_text);
1370
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001371static const struct soc_enum dec8_mux_enum =
1372 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 0, 7, dec8_mux_text);
1373
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001374static const struct soc_enum dec9_mux_enum =
1375 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 3, 8, dec9_mux_text);
1376
1377static const struct soc_enum dec10_mux_enum =
1378 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B4_CTL, 0, 8, dec10_mux_text);
1379
Bradley Rubin229c6a52011-07-12 16:18:48 -07001380static const struct soc_enum anc1_mux_enum =
1381 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 0, 16, anc_mux_text);
1382
1383static const struct soc_enum anc2_mux_enum =
1384 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 4, 16, anc_mux_text);
1385
1386static const struct soc_enum anc1_fb_mux_enum =
1387 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text);
1388
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001389static const struct soc_enum iir1_inp1_mux_enum =
1390 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ1_B1_CTL, 0, 18, iir1_inp1_text);
1391
1392static const struct snd_kcontrol_new rx_mix1_inp1_mux =
1393 SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum);
1394
Bradley Rubin229c6a52011-07-12 16:18:48 -07001395static const struct snd_kcontrol_new rx_mix1_inp2_mux =
1396 SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum);
1397
Kiran Kandia9fffe92012-05-20 23:42:30 -07001398static const struct snd_kcontrol_new rx_mix1_inp3_mux =
1399 SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum);
1400
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001401static const struct snd_kcontrol_new rx2_mix1_inp1_mux =
1402 SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum);
1403
Bradley Rubin229c6a52011-07-12 16:18:48 -07001404static const struct snd_kcontrol_new rx2_mix1_inp2_mux =
1405 SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum);
1406
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001407static const struct snd_kcontrol_new rx3_mix1_inp1_mux =
1408 SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum);
1409
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001410static const struct snd_kcontrol_new rx3_mix1_inp2_mux =
1411 SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum);
1412
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001413static const struct snd_kcontrol_new rx4_mix1_inp1_mux =
1414 SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum);
1415
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001416static const struct snd_kcontrol_new rx4_mix1_inp2_mux =
1417 SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum);
1418
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001419static const struct snd_kcontrol_new rx5_mix1_inp1_mux =
1420 SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum);
1421
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001422static const struct snd_kcontrol_new rx5_mix1_inp2_mux =
1423 SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum);
1424
1425static const struct snd_kcontrol_new rx6_mix1_inp1_mux =
1426 SOC_DAPM_ENUM("RX6 MIX1 INP1 Mux", rx6_mix1_inp1_chain_enum);
1427
1428static const struct snd_kcontrol_new rx6_mix1_inp2_mux =
1429 SOC_DAPM_ENUM("RX6 MIX1 INP2 Mux", rx6_mix1_inp2_chain_enum);
1430
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001431static const struct snd_kcontrol_new rx7_mix1_inp1_mux =
1432 SOC_DAPM_ENUM("RX7 MIX1 INP1 Mux", rx7_mix1_inp1_chain_enum);
1433
1434static const struct snd_kcontrol_new rx7_mix1_inp2_mux =
1435 SOC_DAPM_ENUM("RX7 MIX1 INP2 Mux", rx7_mix1_inp2_chain_enum);
1436
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001437static const struct snd_kcontrol_new rx1_mix2_inp1_mux =
1438 SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum);
1439
1440static const struct snd_kcontrol_new rx1_mix2_inp2_mux =
1441 SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum);
1442
1443static const struct snd_kcontrol_new rx2_mix2_inp1_mux =
1444 SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum);
1445
1446static const struct snd_kcontrol_new rx2_mix2_inp2_mux =
1447 SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum);
1448
1449static const struct snd_kcontrol_new rx3_mix2_inp1_mux =
1450 SOC_DAPM_ENUM("RX3 MIX2 INP1 Mux", rx3_mix2_inp1_chain_enum);
1451
1452static const struct snd_kcontrol_new rx3_mix2_inp2_mux =
1453 SOC_DAPM_ENUM("RX3 MIX2 INP2 Mux", rx3_mix2_inp2_chain_enum);
1454
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001455static const struct snd_kcontrol_new rx4_dsm_mux =
1456 SOC_DAPM_ENUM("RX4 DSM MUX Mux", rx4_dsm_enum);
1457
1458static const struct snd_kcontrol_new rx6_dsm_mux =
1459 SOC_DAPM_ENUM("RX6 DSM MUX Mux", rx6_dsm_enum);
1460
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001461static const struct snd_kcontrol_new sb_tx1_mux =
1462 SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum);
1463
1464static const struct snd_kcontrol_new sb_tx2_mux =
1465 SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum);
1466
1467static const struct snd_kcontrol_new sb_tx3_mux =
1468 SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum);
1469
1470static const struct snd_kcontrol_new sb_tx4_mux =
1471 SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum);
1472
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001473static const struct snd_kcontrol_new sb_tx5_mux =
1474 SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum);
1475
1476static const struct snd_kcontrol_new sb_tx6_mux =
1477 SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum);
1478
1479static const struct snd_kcontrol_new sb_tx7_mux =
1480 SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum);
1481
1482static const struct snd_kcontrol_new sb_tx8_mux =
1483 SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum);
1484
Kiran Kandi3426e512011-09-13 22:50:10 -07001485static const struct snd_kcontrol_new sb_tx9_mux =
1486 SOC_DAPM_ENUM("SLIM TX9 MUX Mux", sb_tx9_mux_enum);
1487
1488static const struct snd_kcontrol_new sb_tx10_mux =
1489 SOC_DAPM_ENUM("SLIM TX10 MUX Mux", sb_tx10_mux_enum);
1490
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001491
Kiran Kandi59a96b12012-01-16 02:20:03 -08001492static int wcd9310_put_dec_enum(struct snd_kcontrol *kcontrol,
1493 struct snd_ctl_elem_value *ucontrol)
1494{
1495 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1496 struct snd_soc_dapm_widget *w = wlist->widgets[0];
1497 struct snd_soc_codec *codec = w->codec;
1498 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1499 unsigned int dec_mux, decimator;
1500 char *dec_name = NULL;
1501 char *widget_name = NULL;
1502 char *temp;
1503 u16 tx_mux_ctl_reg;
1504 u8 adc_dmic_sel = 0x0;
1505 int ret = 0;
1506
1507 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1508 return -EINVAL;
1509
1510 dec_mux = ucontrol->value.enumerated.item[0];
1511
1512 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
1513 if (!widget_name)
1514 return -ENOMEM;
1515 temp = widget_name;
1516
1517 dec_name = strsep(&widget_name, " ");
1518 widget_name = temp;
1519 if (!dec_name) {
1520 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
1521 ret = -EINVAL;
1522 goto out;
1523 }
1524
1525 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
1526 if (ret < 0) {
1527 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
1528 ret = -EINVAL;
1529 goto out;
1530 }
1531
1532 dev_dbg(w->dapm->dev, "%s(): widget = %s dec_name = %s decimator = %u"
1533 " dec_mux = %u\n", __func__, w->name, dec_name, decimator,
1534 dec_mux);
1535
1536
1537 switch (decimator) {
1538 case 1:
1539 case 2:
1540 case 3:
1541 case 4:
1542 case 5:
1543 case 6:
1544 if (dec_mux == 1)
1545 adc_dmic_sel = 0x1;
1546 else
1547 adc_dmic_sel = 0x0;
1548 break;
1549 case 7:
1550 case 8:
1551 case 9:
1552 case 10:
1553 if ((dec_mux == 1) || (dec_mux == 2))
1554 adc_dmic_sel = 0x1;
1555 else
1556 adc_dmic_sel = 0x0;
1557 break;
1558 default:
1559 pr_err("%s: Invalid Decimator = %u\n", __func__, decimator);
1560 ret = -EINVAL;
1561 goto out;
1562 }
1563
1564 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
1565
1566 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel);
1567
1568 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1569
1570out:
1571 kfree(widget_name);
1572 return ret;
1573}
1574
1575#define WCD9310_DEC_ENUM(xname, xenum) \
1576{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1577 .info = snd_soc_info_enum_double, \
1578 .get = snd_soc_dapm_get_enum_double, \
1579 .put = wcd9310_put_dec_enum, \
1580 .private_value = (unsigned long)&xenum }
1581
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001582static const struct snd_kcontrol_new dec1_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001583 WCD9310_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001584
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001585static const struct snd_kcontrol_new dec2_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001586 WCD9310_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum);
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001587
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001588static const struct snd_kcontrol_new dec3_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001589 WCD9310_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001590
1591static const struct snd_kcontrol_new dec4_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001592 WCD9310_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001593
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001594static const struct snd_kcontrol_new dec5_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001595 WCD9310_DEC_ENUM("DEC5 MUX Mux", dec5_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001596
1597static const struct snd_kcontrol_new dec6_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001598 WCD9310_DEC_ENUM("DEC6 MUX Mux", dec6_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001599
1600static const struct snd_kcontrol_new dec7_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001601 WCD9310_DEC_ENUM("DEC7 MUX Mux", dec7_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001602
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001603static const struct snd_kcontrol_new dec8_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001604 WCD9310_DEC_ENUM("DEC8 MUX Mux", dec8_mux_enum);
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001605
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001606static const struct snd_kcontrol_new dec9_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001607 WCD9310_DEC_ENUM("DEC9 MUX Mux", dec9_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001608
1609static const struct snd_kcontrol_new dec10_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001610 WCD9310_DEC_ENUM("DEC10 MUX Mux", dec10_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001611
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001612static const struct snd_kcontrol_new iir1_inp1_mux =
1613 SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum);
1614
Kiran Kandi59a96b12012-01-16 02:20:03 -08001615static const struct snd_kcontrol_new anc1_mux =
1616 SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum);
1617
Bradley Rubin229c6a52011-07-12 16:18:48 -07001618static const struct snd_kcontrol_new anc2_mux =
1619 SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001620
Bradley Rubin229c6a52011-07-12 16:18:48 -07001621static const struct snd_kcontrol_new anc1_fb_mux =
1622 SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001623
Bradley Rubin229c6a52011-07-12 16:18:48 -07001624static const struct snd_kcontrol_new dac1_switch[] = {
1625 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_EAR_EN, 5, 1, 0)
1626};
1627static const struct snd_kcontrol_new hphl_switch[] = {
1628 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_HPH_L_DAC_CTL, 6, 1, 0)
1629};
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001630
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001631static const struct snd_kcontrol_new hphl_pa_mix[] = {
1632 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1633 7, 1, 0),
1634 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1635 7, 1, 0),
1636 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1637 TABLA_A_AUX_L_PA_CONN_INV, 7, 1, 0),
1638 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1639 TABLA_A_AUX_R_PA_CONN_INV, 7, 1, 0),
1640};
1641
1642static const struct snd_kcontrol_new hphr_pa_mix[] = {
1643 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1644 6, 1, 0),
1645 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1646 6, 1, 0),
1647 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1648 TABLA_A_AUX_L_PA_CONN_INV, 6, 1, 0),
1649 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1650 TABLA_A_AUX_R_PA_CONN_INV, 6, 1, 0),
1651};
1652
1653static const struct snd_kcontrol_new lineout1_pa_mix[] = {
1654 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1655 5, 1, 0),
1656 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1657 5, 1, 0),
1658 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1659 TABLA_A_AUX_L_PA_CONN_INV, 5, 1, 0),
1660 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1661 TABLA_A_AUX_R_PA_CONN_INV, 5, 1, 0),
1662};
1663
1664static const struct snd_kcontrol_new lineout2_pa_mix[] = {
1665 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1666 4, 1, 0),
1667 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1668 4, 1, 0),
1669 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1670 TABLA_A_AUX_L_PA_CONN_INV, 4, 1, 0),
1671 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1672 TABLA_A_AUX_R_PA_CONN_INV, 4, 1, 0),
1673};
1674
1675static const struct snd_kcontrol_new lineout3_pa_mix[] = {
1676 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1677 3, 1, 0),
1678 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1679 3, 1, 0),
1680 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1681 TABLA_A_AUX_L_PA_CONN_INV, 3, 1, 0),
1682 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1683 TABLA_A_AUX_R_PA_CONN_INV, 3, 1, 0),
1684};
1685
1686static const struct snd_kcontrol_new lineout4_pa_mix[] = {
1687 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1688 2, 1, 0),
1689 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1690 2, 1, 0),
1691 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1692 TABLA_A_AUX_L_PA_CONN_INV, 2, 1, 0),
1693 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1694 TABLA_A_AUX_R_PA_CONN_INV, 2, 1, 0),
1695};
1696
1697static const struct snd_kcontrol_new lineout5_pa_mix[] = {
1698 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1699 1, 1, 0),
1700 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1701 1, 1, 0),
1702 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1703 TABLA_A_AUX_L_PA_CONN_INV, 1, 1, 0),
1704 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1705 TABLA_A_AUX_R_PA_CONN_INV, 1, 1, 0),
1706};
1707
1708static const struct snd_kcontrol_new ear_pa_mix[] = {
1709 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1710 0, 1, 0),
1711 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1712 0, 1, 0),
1713 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1714 TABLA_A_AUX_L_PA_CONN_INV, 0, 1, 0),
1715 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1716 TABLA_A_AUX_R_PA_CONN_INV, 0, 1, 0),
1717};
1718
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001719static const struct snd_kcontrol_new lineout3_ground_switch =
1720 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_3_DAC_CTL, 6, 1, 0);
1721
1722static const struct snd_kcontrol_new lineout4_ground_switch =
1723 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_4_DAC_CTL, 6, 1, 0);
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001724
Kuirong Wang906ac472012-07-09 12:54:44 -07001725/* virtual port entries */
1726static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol,
1727 struct snd_ctl_elem_value *ucontrol)
1728{
1729 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1730 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1731
1732 ucontrol->value.integer.value[0] = widget->value;
1733 return 0;
1734}
1735
1736static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol,
1737 struct snd_ctl_elem_value *ucontrol)
1738{
1739 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1740 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1741 struct snd_soc_codec *codec = widget->codec;
1742 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
1743 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
1744 struct soc_multi_mixer_control *mixer =
1745 ((struct soc_multi_mixer_control *)kcontrol->private_value);
1746 u32 dai_id = widget->shift;
1747 u32 port_id = mixer->shift;
1748 u32 enable = ucontrol->value.integer.value[0];
1749
1750 pr_debug("%s: wname %s cname %s value %u shift %d item %ld\n", __func__,
1751 widget->name, ucontrol->id.name, widget->value, widget->shift,
1752 ucontrol->value.integer.value[0]);
1753
1754 mutex_lock(&codec->mutex);
1755 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
1756 if (dai_id != AIF1_CAP) {
1757 dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
1758 __func__);
1759 mutex_unlock(&codec->mutex);
1760 return -EINVAL;
1761 }
1762 }
1763 switch (dai_id) {
1764 case AIF1_CAP:
1765 case AIF2_CAP:
1766 case AIF3_CAP:
1767 /* only add to the list if value not set
1768 */
1769 if (enable && !(widget->value & 1 << port_id)) {
Kuirong Wangdcc392e2012-10-19 00:33:38 -07001770 if (wcd9xxx_tx_vport_validation(
1771 vport_check_table[dai_id],
1772 port_id,
1773 tabla_p->dai)) {
Kuirong Wang906ac472012-07-09 12:54:44 -07001774 pr_info("%s: TX%u is used by other virtual port\n",
1775 __func__, port_id + 1);
1776 mutex_unlock(&codec->mutex);
1777 return -EINVAL;
1778 }
1779 widget->value |= 1 << port_id;
1780 list_add_tail(&core->tx_chs[port_id].list,
1781 &tabla_p->dai[dai_id].wcd9xxx_ch_list
1782 );
1783 } else if (!enable && (widget->value & 1 << port_id)) {
1784 widget->value &= ~(1 << port_id);
1785 list_del_init(&core->tx_chs[port_id].list);
1786 } else {
1787 if (enable)
1788 pr_info("%s: TX%u port is used by this virtual port\n",
1789 __func__, port_id + 1);
1790 else
1791 pr_info("%s: TX%u port is not used by this virtual port\n",
1792 __func__, port_id + 1);
1793 /* avoid update power function */
1794 mutex_unlock(&codec->mutex);
1795 return 0;
1796 }
1797 break;
1798 default:
1799 pr_err("Unknown AIF %d\n", dai_id);
1800 mutex_unlock(&codec->mutex);
1801 return -EINVAL;
1802 }
1803 pr_debug("%s: name %s sname %s updated value %u shift %d\n", __func__,
1804 widget->name, widget->sname, widget->value, widget->shift);
1805
1806 snd_soc_dapm_mixer_update_power(widget, kcontrol, enable);
1807
1808 mutex_unlock(&codec->mutex);
1809 return 0;
1810}
1811
1812static int slim_rx_mux_get(struct snd_kcontrol *kcontrol,
1813 struct snd_ctl_elem_value *ucontrol)
1814{
1815 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1816 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1817
1818 ucontrol->value.enumerated.item[0] = widget->value;
1819 return 0;
1820}
1821
1822static const char *const slim_rx_mux_text[] = {
1823 "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB"
1824};
1825
1826static int slim_rx_mux_put(struct snd_kcontrol *kcontrol,
1827 struct snd_ctl_elem_value *ucontrol)
1828{
1829 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1830 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1831 struct snd_soc_codec *codec = widget->codec;
1832 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
1833 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
1834 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1835 u32 port_id = widget->shift;
1836
1837 pr_debug("%s: wname %s cname %s value %u shift %d item %u\n", __func__,
1838 widget->name, ucontrol->id.name, widget->value, widget->shift,
1839 ucontrol->value.enumerated.item[0]);
1840
1841 widget->value = ucontrol->value.enumerated.item[0];
1842
1843 mutex_lock(&codec->mutex);
1844
1845 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
1846 if (widget->value > 1) {
1847 dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
1848 __func__);
Kuirong Wangdcc392e2012-10-19 00:33:38 -07001849 goto err;
Kuirong Wang906ac472012-07-09 12:54:44 -07001850 }
1851 }
1852 /* value need to match the Virtual port and AIF number
1853 */
1854 switch (widget->value) {
1855 case 0:
1856 list_del_init(&core->rx_chs[port_id].list);
1857 break;
1858 case 1:
Kuirong Wangdcc392e2012-10-19 00:33:38 -07001859 if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port,
1860 &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list))
1861 goto pr_err;
Kuirong Wang906ac472012-07-09 12:54:44 -07001862 list_add_tail(&core->rx_chs[port_id].list,
1863 &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list);
1864 break;
1865 case 2:
Kuirong Wangdcc392e2012-10-19 00:33:38 -07001866 if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port,
1867 &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list))
1868 goto pr_err;
Kuirong Wang906ac472012-07-09 12:54:44 -07001869 list_add_tail(&core->rx_chs[port_id].list,
1870 &tabla_p->dai[AIF2_PB].wcd9xxx_ch_list);
1871 break;
1872 case 3:
Kuirong Wangdcc392e2012-10-19 00:33:38 -07001873 if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port,
1874 &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list))
1875 goto pr_err;
Kuirong Wang906ac472012-07-09 12:54:44 -07001876 list_add_tail(&core->rx_chs[port_id].list,
1877 &tabla_p->dai[AIF3_PB].wcd9xxx_ch_list);
1878 break;
1879 default:
1880 pr_err("Unknown AIF %d\n", widget->value);
Kuirong Wangdcc392e2012-10-19 00:33:38 -07001881 goto err;
Kuirong Wang906ac472012-07-09 12:54:44 -07001882 }
1883
1884 snd_soc_dapm_mux_update_power(widget, kcontrol, 1, widget->value, e);
1885
1886 mutex_unlock(&codec->mutex);
1887 return 0;
Kuirong Wangdcc392e2012-10-19 00:33:38 -07001888
1889pr_err:
1890 pr_err("%s: RX%u is used by current requesting AIF_PB itself\n",
1891 __func__, port_id + 1);
Santosh Mardi2a831d72012-11-07 20:45:52 +05301892 mutex_unlock(&codec->mutex);
1893 return 0;
Kuirong Wangdcc392e2012-10-19 00:33:38 -07001894err:
1895 mutex_unlock(&codec->mutex);
1896 return -EINVAL;
Kuirong Wang906ac472012-07-09 12:54:44 -07001897}
1898
1899static const struct soc_enum slim_rx_mux_enum =
1900 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text), slim_rx_mux_text);
1901
1902static const struct snd_kcontrol_new slim_rx_mux[TABLA_RX_MAX] = {
1903 SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum,
1904 slim_rx_mux_get, slim_rx_mux_put),
1905 SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum,
1906 slim_rx_mux_get, slim_rx_mux_put),
1907 SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum,
1908 slim_rx_mux_get, slim_rx_mux_put),
1909 SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum,
1910 slim_rx_mux_get, slim_rx_mux_put),
1911 SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum,
1912 slim_rx_mux_get, slim_rx_mux_put),
1913 SOC_DAPM_ENUM_EXT("SLIM RX6 Mux", slim_rx_mux_enum,
1914 slim_rx_mux_get, slim_rx_mux_put),
1915 SOC_DAPM_ENUM_EXT("SLIM RX7 Mux", slim_rx_mux_enum,
1916 slim_rx_mux_get, slim_rx_mux_put),
1917};
1918
1919static const struct snd_kcontrol_new aif_cap_mixer[] = {
1920 SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, TABLA_TX1, 1, 0,
1921 slim_tx_mixer_get, slim_tx_mixer_put),
1922 SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, TABLA_TX2, 1, 0,
1923 slim_tx_mixer_get, slim_tx_mixer_put),
1924 SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, TABLA_TX3, 1, 0,
1925 slim_tx_mixer_get, slim_tx_mixer_put),
1926 SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, TABLA_TX4, 1, 0,
1927 slim_tx_mixer_get, slim_tx_mixer_put),
1928 SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, TABLA_TX5, 1, 0,
1929 slim_tx_mixer_get, slim_tx_mixer_put),
1930 SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, TABLA_TX6, 1, 0,
1931 slim_tx_mixer_get, slim_tx_mixer_put),
1932 SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, TABLA_TX7, 1, 0,
1933 slim_tx_mixer_get, slim_tx_mixer_put),
1934 SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, TABLA_TX8, 1, 0,
1935 slim_tx_mixer_get, slim_tx_mixer_put),
1936 SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, TABLA_TX9, 1, 0,
1937 slim_tx_mixer_get, slim_tx_mixer_put),
1938 SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, TABLA_TX10, 1, 0,
1939 slim_tx_mixer_get, slim_tx_mixer_put),
1940};
1941
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001942static void tabla_codec_enable_adc_block(struct snd_soc_codec *codec,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001943 int enable)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001944{
1945 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1946
1947 pr_debug("%s %d\n", __func__, enable);
1948
1949 if (enable) {
1950 tabla->adc_count++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001951 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x2, 0x2);
1952 } else {
1953 tabla->adc_count--;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001954 if (!tabla->adc_count)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001955 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL,
Joonwoo Park03324832012-03-19 19:36:16 -07001956 0x2, 0x0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001957 }
1958}
1959
1960static int tabla_codec_enable_adc(struct snd_soc_dapm_widget *w,
1961 struct snd_kcontrol *kcontrol, int event)
1962{
1963 struct snd_soc_codec *codec = w->codec;
1964 u16 adc_reg;
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08001965 u8 init_bit_shift;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001966
1967 pr_debug("%s %d\n", __func__, event);
1968
1969 if (w->reg == TABLA_A_TX_1_2_EN)
1970 adc_reg = TABLA_A_TX_1_2_TEST_CTL;
1971 else if (w->reg == TABLA_A_TX_3_4_EN)
1972 adc_reg = TABLA_A_TX_3_4_TEST_CTL;
1973 else if (w->reg == TABLA_A_TX_5_6_EN)
1974 adc_reg = TABLA_A_TX_5_6_TEST_CTL;
1975 else {
1976 pr_err("%s: Error, invalid adc register\n", __func__);
1977 return -EINVAL;
1978 }
1979
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08001980 if (w->shift == 3)
1981 init_bit_shift = 6;
1982 else if (w->shift == 7)
1983 init_bit_shift = 7;
1984 else {
1985 pr_err("%s: Error, invalid init bit postion adc register\n",
1986 __func__);
1987 return -EINVAL;
1988 }
1989
1990
1991
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001992 switch (event) {
1993 case SND_SOC_DAPM_PRE_PMU:
1994 tabla_codec_enable_adc_block(codec, 1);
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08001995 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift,
1996 1 << init_bit_shift);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001997 break;
1998 case SND_SOC_DAPM_POST_PMU:
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08001999
2000 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00);
2001
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002002 break;
2003 case SND_SOC_DAPM_POST_PMD:
2004 tabla_codec_enable_adc_block(codec, 0);
2005 break;
2006 }
2007 return 0;
2008}
2009
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002010static void tabla_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec)
2011{
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002012 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2013 0x80);
2014 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x04,
2015 0x04);
2016 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01,
2017 0x01);
2018 usleep_range(1000, 1000);
2019 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2020 0x00);
2021}
2022
2023static void tabla_codec_enable_bandgap(struct snd_soc_codec *codec,
2024 enum tabla_bandgap_type choice)
2025{
2026 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2027
2028 /* TODO lock resources accessed by audio streams and threaded
2029 * interrupt handlers
2030 */
2031
2032 pr_debug("%s, choice is %d, current is %d\n", __func__, choice,
2033 tabla->bandgap_type);
2034
2035 if (tabla->bandgap_type == choice)
2036 return;
2037
2038 if ((tabla->bandgap_type == TABLA_BANDGAP_OFF) &&
2039 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
2040 tabla_codec_enable_audio_mode_bandgap(codec);
2041 } else if (choice == TABLA_BANDGAP_MBHC_MODE) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002042 /* bandgap mode becomes fast,
2043 * mclk should be off or clk buff source souldn't be VBG
2044 * Let's turn off mclk always */
2045 WARN_ON(snd_soc_read(codec, TABLA_A_CLK_BUFF_EN2) & (1 << 2));
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002046 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x2,
2047 0x2);
2048 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2049 0x80);
2050 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x4,
2051 0x4);
2052 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01,
2053 0x01);
2054 usleep_range(1000, 1000);
2055 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
2056 0x00);
2057 } else if ((tabla->bandgap_type == TABLA_BANDGAP_MBHC_MODE) &&
2058 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
Damir Didjusto7c85d712012-08-16 21:22:29 -07002059 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002060 usleep_range(100, 100);
2061 tabla_codec_enable_audio_mode_bandgap(codec);
2062 } else if (choice == TABLA_BANDGAP_OFF) {
Damir Didjusto7c85d712012-08-16 21:22:29 -07002063 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002064 } else {
2065 pr_err("%s: Error, Invalid bandgap settings\n", __func__);
2066 }
2067 tabla->bandgap_type = choice;
2068}
2069
2070static void tabla_codec_disable_clock_block(struct snd_soc_codec *codec)
2071{
2072 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2073 pr_debug("%s\n", __func__);
2074 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x00);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002075 usleep_range(50, 50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002076 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x02);
2077 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x00);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002078 usleep_range(50, 50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002079 tabla->clock_active = false;
2080}
2081
2082static int tabla_codec_mclk_index(const struct tabla_priv *tabla)
2083{
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002084 if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002085 return 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002086 else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002087 return 1;
2088 else {
2089 BUG_ON(1);
2090 return -EINVAL;
2091 }
2092}
2093
2094static void tabla_enable_rx_bias(struct snd_soc_codec *codec, u32 enable)
2095{
2096 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2097
2098 if (enable) {
2099 tabla->rx_bias_count++;
2100 if (tabla->rx_bias_count == 1)
2101 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
2102 0x80, 0x80);
2103 } else {
2104 tabla->rx_bias_count--;
2105 if (!tabla->rx_bias_count)
2106 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
2107 0x80, 0x00);
2108 }
2109}
2110
2111static int tabla_codec_enable_config_mode(struct snd_soc_codec *codec,
2112 int enable)
2113{
2114 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2115
2116 pr_debug("%s: enable = %d\n", __func__, enable);
2117 if (enable) {
2118 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x10, 0);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002119 /* bandgap mode to fast */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002120 snd_soc_write(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x17);
2121 usleep_range(5, 5);
2122 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002123 0x80);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002124 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002125 0x80);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002126 usleep_range(10, 10);
2127 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, 0);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002128 usleep_range(10000, 10000);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002129 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x08);
2130 } else {
2131 snd_soc_update_bits(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x1,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002132 0);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002133 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, 0);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002134 /* clk source to ext clk and clk buff ref to VBG */
2135 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x0C, 0x04);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002136 }
2137 tabla->config_mode_active = enable ? true : false;
2138
2139 return 0;
2140}
2141
2142static int tabla_codec_enable_clock_block(struct snd_soc_codec *codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002143 int config_mode)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002144{
2145 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2146
2147 pr_debug("%s: config_mode = %d\n", __func__, config_mode);
2148
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002149 /* transit to RCO requires mclk off */
2150 WARN_ON(snd_soc_read(codec, TABLA_A_CLK_BUFF_EN2) & (1 << 2));
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002151 if (config_mode) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002152 /* enable RCO and switch to it */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002153 tabla_codec_enable_config_mode(codec, 1);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002154 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002155 usleep_range(1000, 1000);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002156 } else {
2157 /* switch to MCLK */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002158 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00);
2159
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002160 if (tabla->mbhc_polling_active) {
2161 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
2162 tabla_codec_enable_config_mode(codec, 0);
2163 }
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002164 }
2165
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002166 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x01, 0x01);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002167 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x00);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07002168 /* on MCLK */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08002169 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x04);
2170 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_MCLK_CTL, 0x01, 0x01);
2171 usleep_range(50, 50);
2172 tabla->clock_active = true;
2173 return 0;
2174}
2175
2176static int tabla_codec_enable_aux_pga(struct snd_soc_dapm_widget *w,
2177 struct snd_kcontrol *kcontrol, int event)
2178{
2179 struct snd_soc_codec *codec = w->codec;
2180 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2181
2182 pr_debug("%s: %d\n", __func__, event);
2183
2184 switch (event) {
2185 case SND_SOC_DAPM_PRE_PMU:
2186 tabla_codec_enable_bandgap(codec,
2187 TABLA_BANDGAP_AUDIO_MODE);
2188 tabla_enable_rx_bias(codec, 1);
2189
2190 snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL,
2191 0x08, 0x08);
2192 /* Enable Zero Cross detect for AUX PGA channel
2193 * and set the initial AUX PGA gain to NEG_0P0_DB
2194 * to avoid glitches.
2195 */
2196 if (w->reg == TABLA_A_AUX_L_EN) {
2197 snd_soc_update_bits(codec, TABLA_A_AUX_L_EN,
2198 0x20, 0x20);
2199 tabla->aux_l_gain = snd_soc_read(codec,
2200 TABLA_A_AUX_L_GAIN);
2201 snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F);
2202 } else {
2203 snd_soc_update_bits(codec, TABLA_A_AUX_R_EN,
2204 0x20, 0x20);
2205 tabla->aux_r_gain = snd_soc_read(codec,
2206 TABLA_A_AUX_R_GAIN);
2207 snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F);
2208 }
2209 if (tabla->aux_pga_cnt++ == 1
2210 && !tabla->mclk_enabled) {
2211 tabla_codec_enable_clock_block(codec, 1);
2212 pr_debug("AUX PGA enabled RC osc\n");
2213 }
2214 break;
2215
2216 case SND_SOC_DAPM_POST_PMU:
2217 if (w->reg == TABLA_A_AUX_L_EN)
2218 snd_soc_write(codec, TABLA_A_AUX_L_GAIN,
2219 tabla->aux_l_gain);
2220 else
2221 snd_soc_write(codec, TABLA_A_AUX_R_GAIN,
2222 tabla->aux_r_gain);
2223 break;
2224
2225 case SND_SOC_DAPM_PRE_PMD:
2226 /* Mute AUX PGA channel in use before disabling AUX PGA */
2227 if (w->reg == TABLA_A_AUX_L_EN) {
2228 tabla->aux_l_gain = snd_soc_read(codec,
2229 TABLA_A_AUX_L_GAIN);
2230 snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F);
2231 } else {
2232 tabla->aux_r_gain = snd_soc_read(codec,
2233 TABLA_A_AUX_R_GAIN);
2234 snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F);
2235 }
2236 break;
2237
2238 case SND_SOC_DAPM_POST_PMD:
2239 tabla_enable_rx_bias(codec, 0);
2240
2241 snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL,
2242 0x08, 0x00);
2243 if (w->reg == TABLA_A_AUX_L_EN) {
2244 snd_soc_write(codec, TABLA_A_AUX_L_GAIN,
2245 tabla->aux_l_gain);
2246 snd_soc_update_bits(codec, TABLA_A_AUX_L_EN,
2247 0x20, 0x00);
2248 } else {
2249 snd_soc_write(codec, TABLA_A_AUX_R_GAIN,
2250 tabla->aux_r_gain);
2251 snd_soc_update_bits(codec, TABLA_A_AUX_R_EN,
2252 0x20, 0x00);
2253 }
2254
2255 if (tabla->aux_pga_cnt-- == 0) {
2256 if (tabla->mbhc_polling_active)
2257 tabla_codec_enable_bandgap(codec,
2258 TABLA_BANDGAP_MBHC_MODE);
2259 else
2260 tabla_codec_enable_bandgap(codec,
2261 TABLA_BANDGAP_OFF);
2262
2263 if (!tabla->mclk_enabled &&
2264 !tabla->mbhc_polling_active) {
2265 tabla_codec_enable_clock_block(codec, 0);
2266 }
2267 }
2268 break;
2269 }
2270 return 0;
2271}
2272
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002273static int tabla_codec_enable_lineout(struct snd_soc_dapm_widget *w,
2274 struct snd_kcontrol *kcontrol, int event)
2275{
2276 struct snd_soc_codec *codec = w->codec;
2277 u16 lineout_gain_reg;
2278
Kiran Kandidb0a4b02011-08-23 09:32:09 -07002279 pr_debug("%s %d %s\n", __func__, event, w->name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002280
2281 switch (w->shift) {
2282 case 0:
2283 lineout_gain_reg = TABLA_A_RX_LINE_1_GAIN;
2284 break;
2285 case 1:
2286 lineout_gain_reg = TABLA_A_RX_LINE_2_GAIN;
2287 break;
2288 case 2:
2289 lineout_gain_reg = TABLA_A_RX_LINE_3_GAIN;
2290 break;
2291 case 3:
2292 lineout_gain_reg = TABLA_A_RX_LINE_4_GAIN;
2293 break;
2294 case 4:
2295 lineout_gain_reg = TABLA_A_RX_LINE_5_GAIN;
2296 break;
2297 default:
2298 pr_err("%s: Error, incorrect lineout register value\n",
2299 __func__);
2300 return -EINVAL;
2301 }
2302
2303 switch (event) {
2304 case SND_SOC_DAPM_PRE_PMU:
2305 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40);
2306 break;
2307 case SND_SOC_DAPM_POST_PMU:
Krishnankutty Kolathappilly31169f42011-11-17 10:33:11 -08002308 pr_debug("%s: sleeping 16 ms after %s PA turn on\n",
Kiran Kandidb0a4b02011-08-23 09:32:09 -07002309 __func__, w->name);
Krishnankutty Kolathappilly31169f42011-11-17 10:33:11 -08002310 usleep_range(16000, 16000);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002311 break;
2312 case SND_SOC_DAPM_POST_PMD:
2313 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00);
2314 break;
2315 }
2316 return 0;
2317}
2318
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002319
2320static int tabla_codec_enable_dmic(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002321 struct snd_kcontrol *kcontrol, int event)
2322{
2323 struct snd_soc_codec *codec = w->codec;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002324 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2325 u8 dmic_clk_en;
2326 s32 *dmic_clk_cnt;
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002327 unsigned int dmic;
2328 int ret;
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002329
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002330 ret = kstrtouint(strpbrk(w->name, "123456"), 10, &dmic);
2331 if (ret < 0) {
2332 pr_err("%s: Invalid DMIC line on the codec\n", __func__);
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002333 return -EINVAL;
2334 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002335
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002336 switch (dmic) {
2337 case 1:
2338 case 2:
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002339 dmic_clk_en = 0x01;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002340 dmic_clk_cnt = &(tabla->dmic_1_2_clk_cnt);
2341
2342 pr_debug("%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n",
2343 __func__, event, dmic, *dmic_clk_cnt);
2344
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002345 break;
2346
2347 case 3:
2348 case 4:
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002349 dmic_clk_en = 0x04;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002350 dmic_clk_cnt = &(tabla->dmic_3_4_clk_cnt);
2351
2352 pr_debug("%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n",
2353 __func__, event, dmic, *dmic_clk_cnt);
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002354 break;
2355
2356 case 5:
2357 case 6:
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002358 dmic_clk_en = 0x10;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002359 dmic_clk_cnt = &(tabla->dmic_5_6_clk_cnt);
2360
2361 pr_debug("%s() event %d DMIC%d dmic_5_6_clk_cnt %d\n",
2362 __func__, event, dmic, *dmic_clk_cnt);
2363
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002364 break;
2365
2366 default:
2367 pr_err("%s: Invalid DMIC Selection\n", __func__);
2368 return -EINVAL;
2369 }
2370
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002371 switch (event) {
2372 case SND_SOC_DAPM_PRE_PMU:
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002373
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002374 (*dmic_clk_cnt)++;
2375 if (*dmic_clk_cnt == 1)
2376 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
2377 dmic_clk_en, dmic_clk_en);
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002378
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002379 break;
2380 case SND_SOC_DAPM_POST_PMD:
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002381
2382 (*dmic_clk_cnt)--;
2383 if (*dmic_clk_cnt == 0)
2384 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
2385 dmic_clk_en, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002386 break;
2387 }
2388 return 0;
2389}
2390
Bradley Rubin229c6a52011-07-12 16:18:48 -07002391static int tabla_codec_enable_anc(struct snd_soc_dapm_widget *w,
2392 struct snd_kcontrol *kcontrol, int event)
2393{
2394 struct snd_soc_codec *codec = w->codec;
2395 const char *filename;
2396 const struct firmware *fw;
2397 int i;
2398 int ret;
Bradley Rubina7096d02011-08-03 18:29:02 -07002399 int num_anc_slots;
2400 struct anc_header *anc_head;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002401 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubina7096d02011-08-03 18:29:02 -07002402 u32 anc_writes_size = 0;
2403 int anc_size_remaining;
2404 u32 *anc_ptr;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002405 u16 reg;
2406 u8 mask, val, old_val;
2407
2408 pr_debug("%s %d\n", __func__, event);
2409 switch (event) {
2410 case SND_SOC_DAPM_PRE_PMU:
2411
Bradley Rubin4283a4c2011-07-29 16:18:54 -07002412 filename = "wcd9310/wcd9310_anc.bin";
Bradley Rubin229c6a52011-07-12 16:18:48 -07002413
2414 ret = request_firmware(&fw, filename, codec->dev);
2415 if (ret != 0) {
2416 dev_err(codec->dev, "Failed to acquire ANC data: %d\n",
2417 ret);
2418 return -ENODEV;
2419 }
2420
Bradley Rubina7096d02011-08-03 18:29:02 -07002421 if (fw->size < sizeof(struct anc_header)) {
Bradley Rubin229c6a52011-07-12 16:18:48 -07002422 dev_err(codec->dev, "Not enough data\n");
2423 release_firmware(fw);
2424 return -ENOMEM;
2425 }
2426
2427 /* First number is the number of register writes */
Bradley Rubina7096d02011-08-03 18:29:02 -07002428 anc_head = (struct anc_header *)(fw->data);
2429 anc_ptr = (u32 *)((u32)fw->data + sizeof(struct anc_header));
2430 anc_size_remaining = fw->size - sizeof(struct anc_header);
2431 num_anc_slots = anc_head->num_anc_slots;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002432
Bradley Rubina7096d02011-08-03 18:29:02 -07002433 if (tabla->anc_slot >= num_anc_slots) {
2434 dev_err(codec->dev, "Invalid ANC slot selected\n");
2435 release_firmware(fw);
2436 return -EINVAL;
2437 }
2438
2439 for (i = 0; i < num_anc_slots; i++) {
2440
2441 if (anc_size_remaining < TABLA_PACKED_REG_SIZE) {
2442 dev_err(codec->dev, "Invalid register format\n");
2443 release_firmware(fw);
2444 return -EINVAL;
2445 }
2446 anc_writes_size = (u32)(*anc_ptr);
2447 anc_size_remaining -= sizeof(u32);
2448 anc_ptr += 1;
2449
2450 if (anc_writes_size * TABLA_PACKED_REG_SIZE
2451 > anc_size_remaining) {
2452 dev_err(codec->dev, "Invalid register format\n");
2453 release_firmware(fw);
2454 return -ENOMEM;
2455 }
2456
2457 if (tabla->anc_slot == i)
2458 break;
2459
2460 anc_size_remaining -= (anc_writes_size *
2461 TABLA_PACKED_REG_SIZE);
Bradley Rubin939ff3f2011-08-26 17:19:34 -07002462 anc_ptr += anc_writes_size;
Bradley Rubina7096d02011-08-03 18:29:02 -07002463 }
2464 if (i == num_anc_slots) {
2465 dev_err(codec->dev, "Selected ANC slot not present\n");
Bradley Rubin229c6a52011-07-12 16:18:48 -07002466 release_firmware(fw);
2467 return -ENOMEM;
2468 }
2469
Bradley Rubina7096d02011-08-03 18:29:02 -07002470 for (i = 0; i < anc_writes_size; i++) {
2471 TABLA_CODEC_UNPACK_ENTRY(anc_ptr[i], reg,
Bradley Rubin229c6a52011-07-12 16:18:48 -07002472 mask, val);
2473 old_val = snd_soc_read(codec, reg);
Bradley Rubin4283a4c2011-07-29 16:18:54 -07002474 snd_soc_write(codec, reg, (old_val & ~mask) |
2475 (val & mask));
Bradley Rubin229c6a52011-07-12 16:18:48 -07002476 }
2477 release_firmware(fw);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002478
Joonwoo Park743d0e32012-05-17 15:11:58 -07002479 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
2480 /* if MBHC polling is active, set TX7_MBHC_EN bit 7 */
2481 if (tabla->mbhc_polling_active)
2482 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80,
2483 0x80);
2484 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002485 break;
2486 case SND_SOC_DAPM_POST_PMD:
Joonwoo Park743d0e32012-05-17 15:11:58 -07002487 /* unset TX7_MBHC_EN bit 7 */
2488 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00);
2489
Bradley Rubin229c6a52011-07-12 16:18:48 -07002490 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0xFF);
2491 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_CLK_EN_CTL, 0);
2492 break;
2493 }
2494 return 0;
2495}
2496
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002497/* called under codec_resource_lock acquisition */
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002498static void tabla_codec_start_hs_polling(struct snd_soc_codec *codec)
2499{
Bradley Rubincb3950a2011-08-18 13:07:26 -07002500 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07002501 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
2502 int mbhc_state = tabla->mbhc_state;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002503
Joonwoo Park03324832012-03-19 19:36:16 -07002504 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002505 if (!tabla->mbhc_polling_active) {
2506 pr_debug("Polling is not active, do not start polling\n");
2507 return;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002508 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002509 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Joonwoo Park03324832012-03-19 19:36:16 -07002510
Joonwoo Park5bbcb0c2012-08-07 17:25:52 -07002511 if (tabla->no_mic_headset_override) {
2512 pr_debug("%s setting button threshold to min", __func__);
2513 /* set to min */
2514 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, 0x80);
2515 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0x00);
2516 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0x80);
2517 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0x00);
2518 } else if (unlikely(mbhc_state == MBHC_STATE_POTENTIAL)) {
2519 pr_debug("%s recovering MBHC state machine\n", __func__);
2520 tabla->mbhc_state = MBHC_STATE_POTENTIAL_RECOVERY;
2521 /* set to max button press threshold */
2522 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, 0x7F);
2523 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, 0xFF);
2524 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL,
2525 (TABLA_IS_1_X(tabla_core->version) ?
2526 0x07 : 0x7F));
2527 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0xFF);
2528 /* set to max */
2529 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0x7F);
2530 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0xFF);
Joonwoo Park03324832012-03-19 19:36:16 -07002531 }
2532
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002533 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
2534 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
2535 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
Joonwoo Park03324832012-03-19 19:36:16 -07002536 pr_debug("%s: leave\n", __func__);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002537}
2538
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002539/* called under codec_resource_lock acquisition */
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002540static void tabla_codec_pause_hs_polling(struct snd_soc_codec *codec)
2541{
Bradley Rubincb3950a2011-08-18 13:07:26 -07002542 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2543
Joonwoo Park03324832012-03-19 19:36:16 -07002544 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002545 if (!tabla->mbhc_polling_active) {
2546 pr_debug("polling not active, nothing to pause\n");
2547 return;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002548 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002549
2550 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
Joonwoo Park03324832012-03-19 19:36:16 -07002551 pr_debug("%s: leave\n", __func__);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002552}
2553
Joonwoo Park03324832012-03-19 19:36:16 -07002554static void tabla_codec_switch_cfilt_mode(struct snd_soc_codec *codec, int mode)
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002555{
2556 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2557 u8 reg_mode_val, cur_mode_val;
2558 bool mbhc_was_polling = false;
2559
2560 if (mode)
2561 reg_mode_val = TABLA_CFILT_FAST_MODE;
2562 else
2563 reg_mode_val = TABLA_CFILT_SLOW_MODE;
2564
2565 cur_mode_val = snd_soc_read(codec,
2566 tabla->mbhc_bias_regs.cfilt_ctl) & 0x40;
2567
2568 if (cur_mode_val != reg_mode_val) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002569 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002570 if (tabla->mbhc_polling_active) {
2571 tabla_codec_pause_hs_polling(codec);
2572 mbhc_was_polling = true;
2573 }
2574 snd_soc_update_bits(codec,
2575 tabla->mbhc_bias_regs.cfilt_ctl, 0x40, reg_mode_val);
2576 if (mbhc_was_polling)
2577 tabla_codec_start_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002578 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002579 pr_debug("%s: CFILT mode change (%x to %x)\n", __func__,
2580 cur_mode_val, reg_mode_val);
2581 } else {
2582 pr_debug("%s: CFILT Value is already %x\n",
2583 __func__, cur_mode_val);
2584 }
2585}
2586
2587static void tabla_codec_update_cfilt_usage(struct snd_soc_codec *codec,
2588 u8 cfilt_sel, int inc)
2589{
2590 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2591 u32 *cfilt_cnt_ptr = NULL;
2592 u16 micb_cfilt_reg;
2593
2594 switch (cfilt_sel) {
2595 case TABLA_CFILT1_SEL:
2596 cfilt_cnt_ptr = &tabla->cfilt1_cnt;
2597 micb_cfilt_reg = TABLA_A_MICB_CFILT_1_CTL;
2598 break;
2599 case TABLA_CFILT2_SEL:
2600 cfilt_cnt_ptr = &tabla->cfilt2_cnt;
2601 micb_cfilt_reg = TABLA_A_MICB_CFILT_2_CTL;
2602 break;
2603 case TABLA_CFILT3_SEL:
2604 cfilt_cnt_ptr = &tabla->cfilt3_cnt;
2605 micb_cfilt_reg = TABLA_A_MICB_CFILT_3_CTL;
2606 break;
2607 default:
2608 return; /* should not happen */
2609 }
2610
2611 if (inc) {
2612 if (!(*cfilt_cnt_ptr)++) {
2613 /* Switch CFILT to slow mode if MBHC CFILT being used */
2614 if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel)
2615 tabla_codec_switch_cfilt_mode(codec, 0);
2616
2617 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80);
2618 }
2619 } else {
2620 /* check if count not zero, decrement
2621 * then check if zero, go ahead disable cfilter
2622 */
2623 if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr)) {
2624 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0);
2625
2626 /* Switch CFILT to fast mode if MBHC CFILT being used */
2627 if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel)
2628 tabla_codec_switch_cfilt_mode(codec, 1);
2629 }
2630 }
2631}
2632
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002633static int tabla_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv)
2634{
2635 int rc = -EINVAL;
2636 unsigned min_mv, max_mv;
2637
2638 switch (ldoh_v) {
2639 case TABLA_LDOH_1P95_V:
2640 min_mv = 160;
2641 max_mv = 1800;
2642 break;
2643 case TABLA_LDOH_2P35_V:
2644 min_mv = 200;
2645 max_mv = 2200;
2646 break;
2647 case TABLA_LDOH_2P75_V:
2648 min_mv = 240;
2649 max_mv = 2600;
2650 break;
2651 case TABLA_LDOH_2P85_V:
2652 min_mv = 250;
2653 max_mv = 2700;
2654 break;
2655 default:
2656 goto done;
2657 }
2658
2659 if (cfilt_mv < min_mv || cfilt_mv > max_mv)
2660 goto done;
2661
2662 for (rc = 4; rc <= 44; rc++) {
2663 min_mv = max_mv * (rc) / 44;
2664 if (min_mv >= cfilt_mv) {
2665 rc -= 4;
2666 break;
2667 }
2668 }
2669done:
2670 return rc;
2671}
2672
2673static bool tabla_is_hph_pa_on(struct snd_soc_codec *codec)
2674{
2675 u8 hph_reg_val = 0;
2676 hph_reg_val = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_EN);
2677
2678 return (hph_reg_val & 0x30) ? true : false;
2679}
2680
Joonwoo Parka9444452011-12-08 18:48:27 -08002681static bool tabla_is_hph_dac_on(struct snd_soc_codec *codec, int left)
2682{
2683 u8 hph_reg_val = 0;
2684 if (left)
2685 hph_reg_val = snd_soc_read(codec,
2686 TABLA_A_RX_HPH_L_DAC_CTL);
2687 else
2688 hph_reg_val = snd_soc_read(codec,
2689 TABLA_A_RX_HPH_R_DAC_CTL);
2690
2691 return (hph_reg_val & 0xC0) ? true : false;
2692}
2693
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002694static void tabla_turn_onoff_override(struct snd_soc_codec *codec, bool on)
2695{
2696 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, on << 2);
2697}
2698
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002699/* called under codec_resource_lock acquisition */
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002700static void tabla_codec_drive_v_to_micbias(struct snd_soc_codec *codec,
2701 int usec)
2702{
2703 int cfilt_k_val;
2704 bool set = true;
2705 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2706
2707 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
2708 tabla->mbhc_micbias_switched) {
2709 pr_debug("%s: set mic V to micbias V\n", __func__);
2710 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
2711 tabla_turn_onoff_override(codec, true);
2712 while (1) {
2713 cfilt_k_val = tabla_find_k_value(
2714 tabla->pdata->micbias.ldoh_v,
2715 set ? tabla->mbhc_data.micb_mv :
2716 VDDIO_MICBIAS_MV);
2717 snd_soc_update_bits(codec,
2718 tabla->mbhc_bias_regs.cfilt_val,
2719 0xFC, (cfilt_k_val << 2));
2720 if (!set)
2721 break;
2722 usleep_range(usec, usec);
2723 set = false;
2724 }
2725 tabla_turn_onoff_override(codec, false);
2726 }
2727}
2728
2729/* called under codec_resource_lock acquisition */
2730static void __tabla_codec_switch_micbias(struct snd_soc_codec *codec,
2731 int vddio_switch, bool restartpolling,
2732 bool checkpolling)
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002733{
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002734 int cfilt_k_val;
Joonwoo Park41956722012-04-18 13:13:07 -07002735 bool override;
2736 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002737
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002738 if (vddio_switch && !tabla->mbhc_micbias_switched &&
2739 (!checkpolling || tabla->mbhc_polling_active)) {
2740 if (restartpolling)
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08002741 tabla_codec_pause_hs_polling(codec);
Joonwoo Park41956722012-04-18 13:13:07 -07002742 override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04;
2743 if (!override)
2744 tabla_turn_onoff_override(codec, true);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002745 /* Adjust threshold if Mic Bias voltage changes */
2746 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002747 cfilt_k_val = tabla_find_k_value(
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002748 tabla->pdata->micbias.ldoh_v,
2749 VDDIO_MICBIAS_MV);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002750 snd_soc_update_bits(codec,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002751 tabla->mbhc_bias_regs.cfilt_val,
2752 0xFC, (cfilt_k_val << 2));
Joonwoo Parkc1c67a92012-08-07 16:05:36 -07002753 usleep_range(cfilt_adjust_ms * 1000,
2754 cfilt_adjust_ms * 1000);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002755 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
2756 tabla->mbhc_data.adj_v_ins_hu & 0xFF);
2757 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
2758 (tabla->mbhc_data.adj_v_ins_hu >> 8) &
2759 0xFF);
2760 pr_debug("%s: Programmed MBHC thresholds to VDDIO\n",
2761 __func__);
2762 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002763
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002764 /* enable MIC BIAS Switch to VDDIO */
2765 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2766 0x80, 0x80);
2767 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2768 0x10, 0x00);
Joonwoo Park41956722012-04-18 13:13:07 -07002769 if (!override)
2770 tabla_turn_onoff_override(codec, false);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002771 if (restartpolling)
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08002772 tabla_codec_start_hs_polling(codec);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002773
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002774 tabla->mbhc_micbias_switched = true;
2775 pr_debug("%s: VDDIO switch enabled\n", __func__);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002776 } else if (!vddio_switch && tabla->mbhc_micbias_switched) {
2777 if ((!checkpolling || tabla->mbhc_polling_active) &&
2778 restartpolling)
2779 tabla_codec_pause_hs_polling(codec);
2780 /* Reprogram thresholds */
2781 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
2782 cfilt_k_val = tabla_find_k_value(
2783 tabla->pdata->micbias.ldoh_v,
2784 tabla->mbhc_data.micb_mv);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002785 snd_soc_update_bits(codec,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002786 tabla->mbhc_bias_regs.cfilt_val,
2787 0xFC, (cfilt_k_val << 2));
Joonwoo Parkc1c67a92012-08-07 16:05:36 -07002788 usleep_range(cfilt_adjust_ms * 1000,
2789 cfilt_adjust_ms * 1000);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002790 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
2791 tabla->mbhc_data.v_ins_hu & 0xFF);
2792 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
2793 (tabla->mbhc_data.v_ins_hu >> 8) & 0xFF);
2794 pr_debug("%s: Programmed MBHC thresholds to MICBIAS\n",
2795 __func__);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002796 }
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002797
2798 /* Disable MIC BIAS Switch to VDDIO */
2799 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2800 0x80, 0x00);
2801 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2802 0x10, 0x00);
2803
2804 if ((!checkpolling || tabla->mbhc_polling_active) &&
2805 restartpolling)
2806 tabla_codec_start_hs_polling(codec);
2807
2808 tabla->mbhc_micbias_switched = false;
2809 pr_debug("%s: VDDIO switch disabled\n", __func__);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002810 }
2811}
2812
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002813static void tabla_codec_switch_micbias(struct snd_soc_codec *codec,
2814 int vddio_switch)
2815{
2816 return __tabla_codec_switch_micbias(codec, vddio_switch, true, true);
2817}
2818
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002819static int tabla_codec_enable_micbias(struct snd_soc_dapm_widget *w,
2820 struct snd_kcontrol *kcontrol, int event)
2821{
2822 struct snd_soc_codec *codec = w->codec;
Patrick Lai3043fba2011-08-01 14:15:57 -07002823 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2824 u16 micb_int_reg;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002825 int micb_line;
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002826 u8 cfilt_sel_val = 0;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002827 char *internal1_text = "Internal1";
2828 char *internal2_text = "Internal2";
2829 char *internal3_text = "Internal3";
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002830
2831 pr_debug("%s %d\n", __func__, event);
2832 switch (w->reg) {
2833 case TABLA_A_MICB_1_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002834 micb_int_reg = TABLA_A_MICB_1_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07002835 cfilt_sel_val = tabla->pdata->micbias.bias1_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002836 micb_line = TABLA_MICBIAS1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002837 break;
2838 case TABLA_A_MICB_2_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002839 micb_int_reg = TABLA_A_MICB_2_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07002840 cfilt_sel_val = tabla->pdata->micbias.bias2_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002841 micb_line = TABLA_MICBIAS2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002842 break;
2843 case TABLA_A_MICB_3_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002844 micb_int_reg = TABLA_A_MICB_3_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07002845 cfilt_sel_val = tabla->pdata->micbias.bias3_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002846 micb_line = TABLA_MICBIAS3;
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002847 break;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08002848 case TABLA_1_A_MICB_4_CTL:
2849 case TABLA_2_A_MICB_4_CTL:
2850 micb_int_reg = tabla->reg_addr.micb_4_int_rbias;
Patrick Lai3043fba2011-08-01 14:15:57 -07002851 cfilt_sel_val = tabla->pdata->micbias.bias4_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002852 micb_line = TABLA_MICBIAS4;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002853 break;
2854 default:
2855 pr_err("%s: Error, invalid micbias register\n", __func__);
2856 return -EINVAL;
2857 }
2858
2859 switch (event) {
2860 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002861 /* Decide whether to switch the micbias for MBHC */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002862 if (w->reg == tabla->mbhc_bias_regs.ctl_reg) {
2863 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002864 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002865 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
2866 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002867
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002868 snd_soc_update_bits(codec, w->reg, 0x0E, 0x0A);
Patrick Lai3043fba2011-08-01 14:15:57 -07002869 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 1);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002870
2871 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002872 snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002873 else if (strnstr(w->name, internal2_text, 30))
2874 snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C);
2875 else if (strnstr(w->name, internal3_text, 30))
2876 snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3);
2877
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002878 break;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002879 case SND_SOC_DAPM_POST_PMU:
Kiran Kandid8cf5212012-03-02 15:34:53 -08002880
2881 usleep_range(20000, 20000);
2882
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002883 if (tabla->mbhc_polling_active &&
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002884 tabla->mbhc_cfg.micbias == micb_line) {
2885 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002886 tabla_codec_pause_hs_polling(codec);
2887 tabla_codec_start_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002888 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002889 }
2890 break;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002891
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002892 case SND_SOC_DAPM_POST_PMD:
Joonwoo Park03324832012-03-19 19:36:16 -07002893 if ((w->reg == tabla->mbhc_bias_regs.ctl_reg) &&
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002894 tabla_is_hph_pa_on(codec)) {
2895 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002896 tabla_codec_switch_micbias(codec, 1);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002897 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
2898 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002899
Bradley Rubin229c6a52011-07-12 16:18:48 -07002900 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002901 snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002902 else if (strnstr(w->name, internal2_text, 30))
2903 snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00);
2904 else if (strnstr(w->name, internal3_text, 30))
2905 snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0);
2906
Patrick Lai3043fba2011-08-01 14:15:57 -07002907 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002908 break;
2909 }
2910
2911 return 0;
2912}
2913
Kiran Kandid8cf5212012-03-02 15:34:53 -08002914
2915static void tx_hpf_corner_freq_callback(struct work_struct *work)
2916{
2917 struct delayed_work *hpf_delayed_work;
2918 struct hpf_work *hpf_work;
2919 struct tabla_priv *tabla;
2920 struct snd_soc_codec *codec;
2921 u16 tx_mux_ctl_reg;
2922 u8 hpf_cut_of_freq;
2923
2924 hpf_delayed_work = to_delayed_work(work);
2925 hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
2926 tabla = hpf_work->tabla;
2927 codec = hpf_work->tabla->codec;
2928 hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq;
2929
2930 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL +
2931 (hpf_work->decimator - 1) * 8;
2932
2933 pr_debug("%s(): decimator %u hpf_cut_of_freq 0x%x\n", __func__,
2934 hpf_work->decimator, (unsigned int)hpf_cut_of_freq);
2935
2936 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4);
2937}
2938
2939#define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30
2940#define CF_MIN_3DB_4HZ 0x0
2941#define CF_MIN_3DB_75HZ 0x1
2942#define CF_MIN_3DB_150HZ 0x2
2943
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002944static int tabla_codec_enable_dec(struct snd_soc_dapm_widget *w,
2945 struct snd_kcontrol *kcontrol, int event)
2946{
2947 struct snd_soc_codec *codec = w->codec;
Kiran Kandid8cf5212012-03-02 15:34:53 -08002948 unsigned int decimator;
2949 char *dec_name = NULL;
2950 char *widget_name = NULL;
2951 char *temp;
2952 int ret = 0;
2953 u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg;
2954 u8 dec_hpf_cut_of_freq;
Kuirong Wange9c8a222012-03-28 16:24:09 -07002955 int offset;
2956
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002957
2958 pr_debug("%s %d\n", __func__, event);
2959
Kiran Kandid8cf5212012-03-02 15:34:53 -08002960 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
2961 if (!widget_name)
2962 return -ENOMEM;
2963 temp = widget_name;
2964
2965 dec_name = strsep(&widget_name, " ");
2966 widget_name = temp;
2967 if (!dec_name) {
2968 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
2969 ret = -EINVAL;
2970 goto out;
2971 }
2972
2973 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
2974 if (ret < 0) {
2975 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
2976 ret = -EINVAL;
2977 goto out;
2978 }
2979
2980 pr_debug("%s(): widget = %s dec_name = %s decimator = %u\n", __func__,
2981 w->name, dec_name, decimator);
2982
Kuirong Wange9c8a222012-03-28 16:24:09 -07002983 if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002984 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B1_CTL;
Kuirong Wange9c8a222012-03-28 16:24:09 -07002985 offset = 0;
2986 } else if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002987 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B2_CTL;
Kuirong Wange9c8a222012-03-28 16:24:09 -07002988 offset = 8;
2989 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002990 pr_err("%s: Error, incorrect dec\n", __func__);
2991 return -EINVAL;
2992 }
2993
Kiran Kandid8cf5212012-03-02 15:34:53 -08002994 tx_vol_ctl_reg = TABLA_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator -1);
2995 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
2996
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002997 switch (event) {
2998 case SND_SOC_DAPM_PRE_PMU:
Kiran Kandid8cf5212012-03-02 15:34:53 -08002999
3000 // Enableable TX digital mute */
3001 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
3002
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003003 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift,
3004 1 << w->shift);
3005 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0);
Kiran Kandid8cf5212012-03-02 15:34:53 -08003006
3007 dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg);
3008
3009 dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4;
3010
3011 tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq =
3012 dec_hpf_cut_of_freq;
3013
3014 if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) {
3015
3016 /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */
3017 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
3018 CF_MIN_3DB_150HZ << 4);
3019 }
3020
3021 /* enable HPF */
3022 snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00);
3023
3024 break;
3025
3026 case SND_SOC_DAPM_POST_PMU:
3027
3028 /* Disable TX digital mute */
3029 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00);
3030
3031 if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq !=
3032 CF_MIN_3DB_150HZ) {
3033
3034 schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork,
3035 msecs_to_jiffies(300));
3036 }
Kuirong Wange9c8a222012-03-28 16:24:09 -07003037 /* apply the digital gain after the decimator is enabled*/
3038 if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
3039 snd_soc_write(codec,
3040 tx_digital_gain_reg[w->shift + offset],
3041 snd_soc_read(codec,
3042 tx_digital_gain_reg[w->shift + offset])
3043 );
3044
Kiran Kandid8cf5212012-03-02 15:34:53 -08003045 break;
3046
3047 case SND_SOC_DAPM_PRE_PMD:
3048
3049 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
3050 cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork);
3051 break;
3052
3053 case SND_SOC_DAPM_POST_PMD:
3054
3055 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08);
3056 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
3057 (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4);
3058
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003059 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003060 }
Kiran Kandid8cf5212012-03-02 15:34:53 -08003061out:
3062 kfree(widget_name);
3063 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003064}
3065
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003066static int tabla_codec_reset_interpolator(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003067 struct snd_kcontrol *kcontrol, int event)
3068{
3069 struct snd_soc_codec *codec = w->codec;
3070
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003071 pr_debug("%s %d %s\n", __func__, event, w->name);
3072
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003073 switch (event) {
3074 case SND_SOC_DAPM_PRE_PMU:
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003075 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
3076 1 << w->shift, 1 << w->shift);
3077 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
3078 1 << w->shift, 0x0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003079 break;
Kuirong Wange9c8a222012-03-28 16:24:09 -07003080 case SND_SOC_DAPM_POST_PMU:
3081 /* apply the digital gain after the interpolator is enabled*/
3082 if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
3083 snd_soc_write(codec,
3084 rx_digital_gain_reg[w->shift],
3085 snd_soc_read(codec,
3086 rx_digital_gain_reg[w->shift])
3087 );
3088 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003089 }
3090 return 0;
3091}
3092
Bradley Rubin229c6a52011-07-12 16:18:48 -07003093static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
3094 struct snd_kcontrol *kcontrol, int event)
3095{
3096 switch (event) {
3097 case SND_SOC_DAPM_POST_PMU:
3098 case SND_SOC_DAPM_POST_PMD:
3099 usleep_range(1000, 1000);
3100 break;
3101 }
3102 return 0;
3103}
3104
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003105static int tabla_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
3106 struct snd_kcontrol *kcontrol, int event)
3107{
3108 struct snd_soc_codec *codec = w->codec;
3109
3110 pr_debug("%s %d\n", __func__, event);
3111
3112 switch (event) {
3113 case SND_SOC_DAPM_PRE_PMU:
3114 tabla_enable_rx_bias(codec, 1);
3115 break;
3116 case SND_SOC_DAPM_POST_PMD:
3117 tabla_enable_rx_bias(codec, 0);
3118 break;
3119 }
3120 return 0;
3121}
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003122static int tabla_hphr_dac_event(struct snd_soc_dapm_widget *w,
3123 struct snd_kcontrol *kcontrol, int event)
3124{
3125 struct snd_soc_codec *codec = w->codec;
3126
3127 pr_debug("%s %s %d\n", __func__, w->name, event);
3128
3129 switch (event) {
3130 case SND_SOC_DAPM_PRE_PMU:
3131 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
3132 break;
3133 case SND_SOC_DAPM_POST_PMD:
3134 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
3135 break;
3136 }
3137 return 0;
3138}
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003139
Joonwoo Park8b1f0982011-12-08 17:12:45 -08003140static void tabla_snd_soc_jack_report(struct tabla_priv *tabla,
3141 struct snd_soc_jack *jack, int status,
3142 int mask)
3143{
3144 /* XXX: wake_lock_timeout()? */
Joonwoo Park03324832012-03-19 19:36:16 -07003145 snd_soc_jack_report_no_dapm(jack, status, mask);
Joonwoo Park8b1f0982011-12-08 17:12:45 -08003146}
3147
Patrick Lai49efeac2011-11-03 11:01:12 -07003148static void hphocp_off_report(struct tabla_priv *tabla,
3149 u32 jack_status, int irq)
3150{
3151 struct snd_soc_codec *codec;
Joonwoo Park03324832012-03-19 19:36:16 -07003152 if (!tabla) {
3153 pr_err("%s: Bad tabla private data\n", __func__);
3154 return;
3155 }
Patrick Lai49efeac2011-11-03 11:01:12 -07003156
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003157 pr_debug("%s: clear ocp status %x\n", __func__, jack_status);
Joonwoo Park03324832012-03-19 19:36:16 -07003158 codec = tabla->codec;
3159 if (tabla->hph_status & jack_status) {
Patrick Lai49efeac2011-11-03 11:01:12 -07003160 tabla->hph_status &= ~jack_status;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003161 if (tabla->mbhc_cfg.headset_jack)
3162 tabla_snd_soc_jack_report(tabla,
3163 tabla->mbhc_cfg.headset_jack,
Joonwoo Park8b1f0982011-12-08 17:12:45 -08003164 tabla->hph_status,
3165 TABLA_JACK_MASK);
Joonwoo Park0976d012011-12-22 11:48:18 -08003166 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x00);
3167 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10);
Patrick Laic7cae882011-11-18 11:52:49 -08003168 /* reset retry counter as PA is turned off signifying
3169 * start of new OCP detection session
3170 */
Joonwoo Parkf6574c72012-10-10 17:29:57 -07003171 if (WCD9XXX_IRQ_HPH_PA_OCPL_FAULT)
Patrick Laic7cae882011-11-18 11:52:49 -08003172 tabla->hphlocp_cnt = 0;
3173 else
3174 tabla->hphrocp_cnt = 0;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303175 wcd9xxx_enable_irq(codec->control_data, irq);
Patrick Lai49efeac2011-11-03 11:01:12 -07003176 }
3177}
3178
3179static void hphlocp_off_report(struct work_struct *work)
3180{
3181 struct tabla_priv *tabla = container_of(work, struct tabla_priv,
3182 hphlocp_work);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07003183 hphocp_off_report(tabla, SND_JACK_OC_HPHL,
3184 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07003185}
3186
3187static void hphrocp_off_report(struct work_struct *work)
3188{
3189 struct tabla_priv *tabla = container_of(work, struct tabla_priv,
3190 hphrocp_work);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07003191 hphocp_off_report(tabla, SND_JACK_OC_HPHR,
3192 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07003193}
3194
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003195static int tabla_hph_pa_event(struct snd_soc_dapm_widget *w,
3196 struct snd_kcontrol *kcontrol, int event)
3197{
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003198 struct snd_soc_codec *codec = w->codec;
3199 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3200 u8 mbhc_micb_ctl_val;
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003201 pr_debug("%s: event = %d\n", __func__, event);
3202
3203 switch (event) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003204 case SND_SOC_DAPM_PRE_PMU:
3205 mbhc_micb_ctl_val = snd_soc_read(codec,
3206 tabla->mbhc_bias_regs.ctl_reg);
3207
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003208 if (!(mbhc_micb_ctl_val & 0x80)) {
3209 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003210 tabla_codec_switch_micbias(codec, 1);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003211 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
3212 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003213 break;
3214
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003215 case SND_SOC_DAPM_POST_PMD:
Patrick Lai49efeac2011-11-03 11:01:12 -07003216 /* schedule work is required because at the time HPH PA DAPM
3217 * event callback is called by DAPM framework, CODEC dapm mutex
3218 * would have been locked while snd_soc_jack_report also
3219 * attempts to acquire same lock.
3220 */
Joonwoo Parka9444452011-12-08 18:48:27 -08003221 if (w->shift == 5) {
3222 clear_bit(TABLA_HPHL_PA_OFF_ACK,
3223 &tabla->hph_pa_dac_state);
3224 clear_bit(TABLA_HPHL_DAC_OFF_ACK,
3225 &tabla->hph_pa_dac_state);
3226 if (tabla->hph_status & SND_JACK_OC_HPHL)
3227 schedule_work(&tabla->hphlocp_work);
3228 } else if (w->shift == 4) {
3229 clear_bit(TABLA_HPHR_PA_OFF_ACK,
3230 &tabla->hph_pa_dac_state);
3231 clear_bit(TABLA_HPHR_DAC_OFF_ACK,
3232 &tabla->hph_pa_dac_state);
3233 if (tabla->hph_status & SND_JACK_OC_HPHR)
3234 schedule_work(&tabla->hphrocp_work);
3235 }
3236
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003237 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Joonwoo Park03324832012-03-19 19:36:16 -07003238 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003239 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07003240
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003241 pr_debug("%s: sleep 10 ms after %s PA disable.\n", __func__,
3242 w->name);
3243 usleep_range(10000, 10000);
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07003244 break;
3245 }
3246 return 0;
3247}
3248
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003249static void tabla_get_mbhc_micbias_regs(struct snd_soc_codec *codec,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003250 struct mbhc_micbias_regs *micbias_regs)
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003251{
3252 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003253 unsigned int cfilt;
3254
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003255 switch (tabla->mbhc_cfg.micbias) {
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003256 case TABLA_MICBIAS1:
3257 cfilt = tabla->pdata->micbias.bias1_cfilt_sel;
3258 micbias_regs->mbhc_reg = TABLA_A_MICB_1_MBHC;
3259 micbias_regs->int_rbias = TABLA_A_MICB_1_INT_RBIAS;
3260 micbias_regs->ctl_reg = TABLA_A_MICB_1_CTL;
3261 break;
3262 case TABLA_MICBIAS2:
3263 cfilt = tabla->pdata->micbias.bias2_cfilt_sel;
3264 micbias_regs->mbhc_reg = TABLA_A_MICB_2_MBHC;
3265 micbias_regs->int_rbias = TABLA_A_MICB_2_INT_RBIAS;
3266 micbias_regs->ctl_reg = TABLA_A_MICB_2_CTL;
3267 break;
3268 case TABLA_MICBIAS3:
3269 cfilt = tabla->pdata->micbias.bias3_cfilt_sel;
3270 micbias_regs->mbhc_reg = TABLA_A_MICB_3_MBHC;
3271 micbias_regs->int_rbias = TABLA_A_MICB_3_INT_RBIAS;
3272 micbias_regs->ctl_reg = TABLA_A_MICB_3_CTL;
3273 break;
3274 case TABLA_MICBIAS4:
3275 cfilt = tabla->pdata->micbias.bias4_cfilt_sel;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003276 micbias_regs->mbhc_reg = tabla->reg_addr.micb_4_mbhc;
3277 micbias_regs->int_rbias = tabla->reg_addr.micb_4_int_rbias;
3278 micbias_regs->ctl_reg = tabla->reg_addr.micb_4_ctl;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003279 break;
3280 default:
3281 /* Should never reach here */
3282 pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__);
Jordan Crouse239d8412011-11-23 11:47:02 -07003283 return;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003284 }
3285
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08003286 micbias_regs->cfilt_sel = cfilt;
3287
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003288 switch (cfilt) {
3289 case TABLA_CFILT1_SEL:
3290 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_1_VAL;
3291 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_1_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08003292 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt1_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003293 break;
3294 case TABLA_CFILT2_SEL:
3295 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_2_VAL;
3296 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_2_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08003297 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt2_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003298 break;
3299 case TABLA_CFILT3_SEL:
3300 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_3_VAL;
3301 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_3_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08003302 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt3_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003303 break;
3304 }
3305}
Santosh Mardie15e2302011-11-15 10:39:23 +05303306static const struct snd_soc_dapm_widget tabla_dapm_i2s_widgets[] = {
3307 SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", TABLA_A_CDC_CLK_RX_I2S_CTL,
3308 4, 0, NULL, 0),
3309 SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", TABLA_A_CDC_CLK_TX_I2S_CTL, 4,
3310 0, NULL, 0),
3311};
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003312
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003313static int tabla_lineout_dac_event(struct snd_soc_dapm_widget *w,
3314 struct snd_kcontrol *kcontrol, int event)
3315{
3316 struct snd_soc_codec *codec = w->codec;
3317
3318 pr_debug("%s %s %d\n", __func__, w->name, event);
3319
3320 switch (event) {
3321 case SND_SOC_DAPM_PRE_PMU:
3322 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
3323 break;
3324
3325 case SND_SOC_DAPM_POST_PMD:
3326 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
3327 break;
3328 }
3329 return 0;
3330}
3331
Damir Didjusto7c85d712012-08-16 21:22:29 -07003332static int tabla_ear_pa_event(struct snd_soc_dapm_widget *w,
3333 struct snd_kcontrol *kcontrol, int event)
3334{
3335 struct snd_soc_codec *codec = w->codec;
3336
3337 pr_debug("%s %d\n", __func__, event);
3338
3339 switch (event) {
3340 case SND_SOC_DAPM_PRE_PMU:
3341 snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x50, 0x50);
3342 break;
3343
3344 case SND_SOC_DAPM_PRE_PMD:
3345 snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x10, 0x00);
3346 snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x40, 0x00);
3347 break;
3348 }
3349 return 0;
3350}
3351
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003352static const struct snd_soc_dapm_widget tabla_1_x_dapm_widgets[] = {
3353 SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", TABLA_1_A_MICB_4_CTL, 7,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303354 0, tabla_codec_enable_micbias,
3355 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3356 SND_SOC_DAPM_POST_PMD),
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003357};
3358
3359static const struct snd_soc_dapm_widget tabla_2_higher_dapm_widgets[] = {
3360 SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", TABLA_2_A_MICB_4_CTL, 7,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303361 0, tabla_codec_enable_micbias,
3362 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3363 SND_SOC_DAPM_POST_PMD),
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003364};
3365
Santosh Mardie15e2302011-11-15 10:39:23 +05303366static const struct snd_soc_dapm_route audio_i2s_map[] = {
3367 {"RX_I2S_CLK", NULL, "CDC_CONN"},
3368 {"SLIM RX1", NULL, "RX_I2S_CLK"},
3369 {"SLIM RX2", NULL, "RX_I2S_CLK"},
3370 {"SLIM RX3", NULL, "RX_I2S_CLK"},
3371 {"SLIM RX4", NULL, "RX_I2S_CLK"},
3372
3373 {"SLIM TX7", NULL, "TX_I2S_CLK"},
3374 {"SLIM TX8", NULL, "TX_I2S_CLK"},
3375 {"SLIM TX9", NULL, "TX_I2S_CLK"},
3376 {"SLIM TX10", NULL, "TX_I2S_CLK"},
3377};
3378
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003379static const struct snd_soc_dapm_route audio_map[] = {
3380 /* SLIMBUS Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003381
Kuirong Wang906ac472012-07-09 12:54:44 -07003382 {"AIF1 CAP", NULL, "AIF1_CAP Mixer"},
3383 {"AIF2 CAP", NULL, "AIF2_CAP Mixer"},
3384 {"AIF3 CAP", NULL, "AIF3_CAP Mixer"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003385
Kuirong Wang906ac472012-07-09 12:54:44 -07003386 /* SLIM_MIXER("AIF1_CAP Mixer"),*/
3387 {"AIF1_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
3388 {"AIF1_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
3389 {"AIF1_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
3390 {"AIF1_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
3391 {"AIF1_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
3392 {"AIF1_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"},
3393 {"AIF1_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"},
3394 {"AIF1_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"},
3395 {"AIF1_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"},
3396 {"AIF1_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"},
3397 /* SLIM_MIXER("AIF2_CAP Mixer"),*/
3398 {"AIF2_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
3399 {"AIF2_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
3400 {"AIF2_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
3401 {"AIF2_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
3402 {"AIF2_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
3403 {"AIF2_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"},
3404 {"AIF2_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"},
3405 {"AIF2_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"},
3406 {"AIF2_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"},
3407 {"AIF2_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"},
3408 /* SLIM_MIXER("AIF3_CAP Mixer"),*/
3409 {"AIF3_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
3410 {"AIF3_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
3411 {"AIF3_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
3412 {"AIF3_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
3413 {"AIF3_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
3414 {"AIF3_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"},
3415 {"AIF3_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"},
3416 {"AIF3_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"},
3417 {"AIF3_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"},
3418 {"AIF3_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"},
3419
3420 {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003421 {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"},
3422
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003423 {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"},
Neema Shetty3fb1b802012-04-27 13:53:24 -07003424 {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"},
3425 {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"},
3426 {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"},
3427 {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"},
3428 {"SLIM TX3 MUX", "RMIX5", "RX5 MIX1"},
3429 {"SLIM TX3 MUX", "RMIX6", "RX6 MIX1"},
3430 {"SLIM TX3 MUX", "RMIX7", "RX7 MIX1"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003431
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003432 {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"},
3433
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003434 {"SLIM TX5 MUX", "DEC5", "DEC5 MUX"},
Neema Shetty3fb1b802012-04-27 13:53:24 -07003435 {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"},
3436 {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"},
3437 {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"},
3438 {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"},
3439 {"SLIM TX5 MUX", "RMIX5", "RX5 MIX1"},
3440 {"SLIM TX5 MUX", "RMIX6", "RX6 MIX1"},
3441 {"SLIM TX5 MUX", "RMIX7", "RX7 MIX1"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003442
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003443 {"SLIM TX6 MUX", "DEC6", "DEC6 MUX"},
3444
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003445 {"SLIM TX7 MUX", "DEC1", "DEC1 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07003446 {"SLIM TX7 MUX", "DEC2", "DEC2 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003447 {"SLIM TX7 MUX", "DEC3", "DEC3 MUX"},
3448 {"SLIM TX7 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003449 {"SLIM TX7 MUX", "DEC5", "DEC5 MUX"},
3450 {"SLIM TX7 MUX", "DEC6", "DEC6 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07003451 {"SLIM TX7 MUX", "DEC7", "DEC7 MUX"},
3452 {"SLIM TX7 MUX", "DEC8", "DEC8 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003453 {"SLIM TX7 MUX", "DEC9", "DEC9 MUX"},
3454 {"SLIM TX7 MUX", "DEC10", "DEC10 MUX"},
Neema Shetty3fb1b802012-04-27 13:53:24 -07003455 {"SLIM TX7 MUX", "RMIX1", "RX1 MIX1"},
3456 {"SLIM TX7 MUX", "RMIX2", "RX2 MIX1"},
3457 {"SLIM TX7 MUX", "RMIX3", "RX3 MIX1"},
3458 {"SLIM TX7 MUX", "RMIX4", "RX4 MIX1"},
3459 {"SLIM TX7 MUX", "RMIX5", "RX5 MIX1"},
3460 {"SLIM TX7 MUX", "RMIX6", "RX6 MIX1"},
3461 {"SLIM TX7 MUX", "RMIX7", "RX7 MIX1"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003462
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003463 {"SLIM TX8 MUX", "DEC1", "DEC1 MUX"},
3464 {"SLIM TX8 MUX", "DEC2", "DEC2 MUX"},
3465 {"SLIM TX8 MUX", "DEC3", "DEC3 MUX"},
Bhalchandra Gajare9ec83cd2011-09-23 17:25:07 -07003466 {"SLIM TX8 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003467 {"SLIM TX8 MUX", "DEC5", "DEC5 MUX"},
3468 {"SLIM TX8 MUX", "DEC6", "DEC6 MUX"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003469 {"SLIM TX8 MUX", "DEC7", "DEC7 MUX"},
3470 {"SLIM TX8 MUX", "DEC8", "DEC8 MUX"},
3471 {"SLIM TX8 MUX", "DEC9", "DEC9 MUX"},
3472 {"SLIM TX8 MUX", "DEC10", "DEC10 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003473
Kiran Kandi3426e512011-09-13 22:50:10 -07003474 {"SLIM TX9 MUX", "DEC1", "DEC1 MUX"},
3475 {"SLIM TX9 MUX", "DEC2", "DEC2 MUX"},
3476 {"SLIM TX9 MUX", "DEC3", "DEC3 MUX"},
3477 {"SLIM TX9 MUX", "DEC4", "DEC4 MUX"},
3478 {"SLIM TX9 MUX", "DEC5", "DEC5 MUX"},
3479 {"SLIM TX9 MUX", "DEC6", "DEC6 MUX"},
3480 {"SLIM TX9 MUX", "DEC7", "DEC7 MUX"},
3481 {"SLIM TX9 MUX", "DEC8", "DEC8 MUX"},
3482 {"SLIM TX9 MUX", "DEC9", "DEC9 MUX"},
3483 {"SLIM TX9 MUX", "DEC10", "DEC10 MUX"},
3484
Kiran Kandi3426e512011-09-13 22:50:10 -07003485 {"SLIM TX10 MUX", "DEC1", "DEC1 MUX"},
3486 {"SLIM TX10 MUX", "DEC2", "DEC2 MUX"},
3487 {"SLIM TX10 MUX", "DEC3", "DEC3 MUX"},
3488 {"SLIM TX10 MUX", "DEC4", "DEC4 MUX"},
3489 {"SLIM TX10 MUX", "DEC5", "DEC5 MUX"},
3490 {"SLIM TX10 MUX", "DEC6", "DEC6 MUX"},
3491 {"SLIM TX10 MUX", "DEC7", "DEC7 MUX"},
3492 {"SLIM TX10 MUX", "DEC8", "DEC8 MUX"},
3493 {"SLIM TX10 MUX", "DEC9", "DEC9 MUX"},
3494 {"SLIM TX10 MUX", "DEC10", "DEC10 MUX"},
3495
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003496 /* Earpiece (RX MIX1) */
3497 {"EAR", NULL, "EAR PA"},
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003498 {"EAR PA", NULL, "EAR_PA_MIXER"},
3499 {"EAR_PA_MIXER", NULL, "DAC1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003500 {"DAC1", NULL, "CP"},
3501
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003502 {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"},
3503 {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003504 {"ANC", NULL, "ANC1 FB MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003505
3506 /* Headset (RX MIX1 and RX MIX2) */
3507 {"HEADPHONE", NULL, "HPHL"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003508 {"HEADPHONE", NULL, "HPHR"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003509
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003510 {"HPHL", NULL, "HPHL_PA_MIXER"},
3511 {"HPHL_PA_MIXER", NULL, "HPHL DAC"},
3512
3513 {"HPHR", NULL, "HPHR_PA_MIXER"},
3514 {"HPHR_PA_MIXER", NULL, "HPHR DAC"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003515
3516 {"HPHL DAC", NULL, "CP"},
3517 {"HPHR DAC", NULL, "CP"},
3518
3519 {"ANC", NULL, "ANC1 MUX"},
3520 {"ANC", NULL, "ANC2 MUX"},
3521 {"ANC1 MUX", "ADC1", "ADC1"},
3522 {"ANC1 MUX", "ADC2", "ADC2"},
3523 {"ANC1 MUX", "ADC3", "ADC3"},
3524 {"ANC1 MUX", "ADC4", "ADC4"},
3525 {"ANC2 MUX", "ADC1", "ADC1"},
3526 {"ANC2 MUX", "ADC2", "ADC2"},
3527 {"ANC2 MUX", "ADC3", "ADC3"},
3528 {"ANC2 MUX", "ADC4", "ADC4"},
3529
Bradley Rubine1d08622011-07-20 18:01:35 -07003530 {"ANC", NULL, "CDC_CONN"},
3531
Bradley Rubin229c6a52011-07-12 16:18:48 -07003532 {"DAC1", "Switch", "RX1 CHAIN"},
3533 {"HPHL DAC", "Switch", "RX1 CHAIN"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003534 {"HPHR DAC", NULL, "RX2 CHAIN"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003535
Kiran Kandidb0a4b02011-08-23 09:32:09 -07003536 {"LINEOUT1", NULL, "LINEOUT1 PA"},
3537 {"LINEOUT2", NULL, "LINEOUT2 PA"},
3538 {"LINEOUT3", NULL, "LINEOUT3 PA"},
3539 {"LINEOUT4", NULL, "LINEOUT4 PA"},
3540 {"LINEOUT5", NULL, "LINEOUT5 PA"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003541
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003542 {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"},
3543 {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"},
3544 {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"},
3545 {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"},
3546 {"LINEOUT3 PA", NULL, "LINEOUT3_PA_MIXER"},
3547 {"LINEOUT3_PA_MIXER", NULL, "LINEOUT3 DAC"},
3548 {"LINEOUT4 PA", NULL, "LINEOUT4_PA_MIXER"},
3549 {"LINEOUT4_PA_MIXER", NULL, "LINEOUT4 DAC"},
3550 {"LINEOUT5 PA", NULL, "LINEOUT5_PA_MIXER"},
3551 {"LINEOUT5_PA_MIXER", NULL, "LINEOUT5 DAC"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003552
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003553 {"LINEOUT1 DAC", NULL, "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003554 {"LINEOUT5 DAC", NULL, "RX7 MIX1"},
3555
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003556 {"RX1 CHAIN", NULL, "RX1 MIX2"},
3557 {"RX2 CHAIN", NULL, "RX2 MIX2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003558 {"RX1 CHAIN", NULL, "ANC"},
3559 {"RX2 CHAIN", NULL, "ANC"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003560
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003561 {"CP", NULL, "RX_BIAS"},
3562 {"LINEOUT1 DAC", NULL, "RX_BIAS"},
3563 {"LINEOUT2 DAC", NULL, "RX_BIAS"},
3564 {"LINEOUT3 DAC", NULL, "RX_BIAS"},
3565 {"LINEOUT4 DAC", NULL, "RX_BIAS"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003566 {"LINEOUT5 DAC", NULL, "RX_BIAS"},
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003567
Kuirong Wang0f8ade32012-02-27 16:29:45 -08003568 {"RX1 MIX1", NULL, "COMP1_CLK"},
3569 {"RX2 MIX1", NULL, "COMP1_CLK"},
3570 {"RX3 MIX1", NULL, "COMP2_CLK"},
3571 {"RX5 MIX1", NULL, "COMP2_CLK"},
3572
3573
Bradley Rubin229c6a52011-07-12 16:18:48 -07003574 {"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
3575 {"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003576 {"RX1 MIX1", NULL, "RX1 MIX1 INP3"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003577 {"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
3578 {"RX2 MIX1", NULL, "RX2 MIX1 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003579 {"RX3 MIX1", NULL, "RX3 MIX1 INP1"},
3580 {"RX3 MIX1", NULL, "RX3 MIX1 INP2"},
3581 {"RX4 MIX1", NULL, "RX4 MIX1 INP1"},
3582 {"RX4 MIX1", NULL, "RX4 MIX1 INP2"},
3583 {"RX5 MIX1", NULL, "RX5 MIX1 INP1"},
3584 {"RX5 MIX1", NULL, "RX5 MIX1 INP2"},
3585 {"RX6 MIX1", NULL, "RX6 MIX1 INP1"},
3586 {"RX6 MIX1", NULL, "RX6 MIX1 INP2"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07003587 {"RX7 MIX1", NULL, "RX7 MIX1 INP1"},
3588 {"RX7 MIX1", NULL, "RX7 MIX1 INP2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003589 {"RX1 MIX2", NULL, "RX1 MIX1"},
3590 {"RX1 MIX2", NULL, "RX1 MIX2 INP1"},
3591 {"RX1 MIX2", NULL, "RX1 MIX2 INP2"},
3592 {"RX2 MIX2", NULL, "RX2 MIX1"},
3593 {"RX2 MIX2", NULL, "RX2 MIX2 INP1"},
3594 {"RX2 MIX2", NULL, "RX2 MIX2 INP2"},
3595 {"RX3 MIX2", NULL, "RX3 MIX1"},
3596 {"RX3 MIX2", NULL, "RX3 MIX2 INP1"},
3597 {"RX3 MIX2", NULL, "RX3 MIX2 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003598
Kuirong Wang906ac472012-07-09 12:54:44 -07003599 /* SLIM_MUX("AIF1_PB", "AIF1 PB"),*/
3600 {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"},
3601 {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"},
3602 {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"},
3603 {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"},
3604 {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"},
3605 {"SLIM RX6 MUX", "AIF1_PB", "AIF1 PB"},
3606 {"SLIM RX7 MUX", "AIF1_PB", "AIF1 PB"},
3607 /* SLIM_MUX("AIF2_PB", "AIF2 PB"),*/
3608 {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"},
3609 {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"},
3610 {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"},
3611 {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"},
3612 {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"},
3613 {"SLIM RX6 MUX", "AIF2_PB", "AIF2 PB"},
3614 {"SLIM RX7 MUX", "AIF2_PB", "AIF2 PB"},
3615 /* SLIM_MUX("AIF3_PB", "AIF3 PB"),*/
3616 {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"},
3617 {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"},
3618 {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"},
3619 {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"},
3620 {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"},
3621 {"SLIM RX6 MUX", "AIF3_PB", "AIF3 PB"},
3622 {"SLIM RX7 MUX", "AIF3_PB", "AIF3 PB"},
3623
3624 {"SLIM RX1", NULL, "SLIM RX1 MUX"},
3625 {"SLIM RX2", NULL, "SLIM RX2 MUX"},
3626 {"SLIM RX3", NULL, "SLIM RX3 MUX"},
3627 {"SLIM RX4", NULL, "SLIM RX4 MUX"},
3628 {"SLIM RX5", NULL, "SLIM RX5 MUX"},
3629 {"SLIM RX6", NULL, "SLIM RX6 MUX"},
3630 {"SLIM RX7", NULL, "SLIM RX7 MUX"},
3631
3632 /* Mixer control for output path */
Bradley Rubin229c6a52011-07-12 16:18:48 -07003633 {"RX1 MIX1 INP1", "RX1", "SLIM RX1"},
3634 {"RX1 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303635 {"RX1 MIX1 INP1", "RX3", "SLIM RX3"},
3636 {"RX1 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003637 {"RX1 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003638 {"RX1 MIX1 INP1", "RX6", "SLIM RX6"},
3639 {"RX1 MIX1 INP1", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003640 {"RX1 MIX1 INP1", "IIR1", "IIR1"},
3641 {"RX1 MIX1 INP2", "RX1", "SLIM RX1"},
3642 {"RX1 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303643 {"RX1 MIX1 INP2", "RX3", "SLIM RX3"},
3644 {"RX1 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003645 {"RX1 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003646 {"RX1 MIX1 INP2", "RX6", "SLIM RX6"},
3647 {"RX1 MIX1 INP2", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003648 {"RX1 MIX1 INP2", "IIR1", "IIR1"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003649 {"RX1 MIX1 INP3", "RX1", "SLIM RX1"},
3650 {"RX1 MIX1 INP3", "RX2", "SLIM RX2"},
3651 {"RX1 MIX1 INP3", "RX3", "SLIM RX3"},
3652 {"RX1 MIX1 INP3", "RX4", "SLIM RX4"},
3653 {"RX1 MIX1 INP3", "RX5", "SLIM RX5"},
3654 {"RX1 MIX1 INP3", "RX6", "SLIM RX6"},
3655 {"RX1 MIX1 INP3", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003656 {"RX2 MIX1 INP1", "RX1", "SLIM RX1"},
3657 {"RX2 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303658 {"RX2 MIX1 INP1", "RX3", "SLIM RX3"},
3659 {"RX2 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003660 {"RX2 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003661 {"RX2 MIX1 INP1", "RX6", "SLIM RX6"},
3662 {"RX2 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003663 {"RX2 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003664 {"RX2 MIX1 INP2", "RX1", "SLIM RX1"},
3665 {"RX2 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303666 {"RX2 MIX1 INP2", "RX3", "SLIM RX3"},
3667 {"RX2 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003668 {"RX2 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003669 {"RX2 MIX1 INP2", "RX6", "SLIM RX6"},
3670 {"RX2 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003671 {"RX2 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003672 {"RX3 MIX1 INP1", "RX1", "SLIM RX1"},
3673 {"RX3 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303674 {"RX3 MIX1 INP1", "RX3", "SLIM RX3"},
3675 {"RX3 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003676 {"RX3 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003677 {"RX3 MIX1 INP1", "RX6", "SLIM RX6"},
3678 {"RX3 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003679 {"RX3 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003680 {"RX3 MIX1 INP2", "RX1", "SLIM RX1"},
3681 {"RX3 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303682 {"RX3 MIX1 INP2", "RX3", "SLIM RX3"},
3683 {"RX3 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003684 {"RX3 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003685 {"RX3 MIX1 INP2", "RX6", "SLIM RX6"},
3686 {"RX3 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003687 {"RX3 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003688 {"RX4 MIX1 INP1", "RX1", "SLIM RX1"},
3689 {"RX4 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303690 {"RX4 MIX1 INP1", "RX3", "SLIM RX3"},
3691 {"RX4 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003692 {"RX4 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003693 {"RX4 MIX1 INP1", "RX6", "SLIM RX6"},
3694 {"RX4 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003695 {"RX4 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003696 {"RX4 MIX1 INP2", "RX1", "SLIM RX1"},
3697 {"RX4 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303698 {"RX4 MIX1 INP2", "RX3", "SLIM RX3"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003699 {"RX4 MIX1 INP2", "RX5", "SLIM RX5"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303700 {"RX4 MIX1 INP2", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003701 {"RX4 MIX1 INP2", "RX6", "SLIM RX6"},
3702 {"RX4 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003703 {"RX4 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003704 {"RX5 MIX1 INP1", "RX1", "SLIM RX1"},
3705 {"RX5 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303706 {"RX5 MIX1 INP1", "RX3", "SLIM RX3"},
3707 {"RX5 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003708 {"RX5 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003709 {"RX5 MIX1 INP1", "RX6", "SLIM RX6"},
3710 {"RX5 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003711 {"RX5 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003712 {"RX5 MIX1 INP2", "RX1", "SLIM RX1"},
3713 {"RX5 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303714 {"RX5 MIX1 INP2", "RX3", "SLIM RX3"},
3715 {"RX5 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003716 {"RX5 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003717 {"RX5 MIX1 INP2", "RX6", "SLIM RX6"},
3718 {"RX5 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003719 {"RX5 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003720 {"RX6 MIX1 INP1", "RX1", "SLIM RX1"},
3721 {"RX6 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303722 {"RX6 MIX1 INP1", "RX3", "SLIM RX3"},
3723 {"RX6 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003724 {"RX6 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003725 {"RX6 MIX1 INP1", "RX6", "SLIM RX6"},
3726 {"RX6 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003727 {"RX6 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003728 {"RX6 MIX1 INP2", "RX1", "SLIM RX1"},
3729 {"RX6 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303730 {"RX6 MIX1 INP2", "RX3", "SLIM RX3"},
3731 {"RX6 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003732 {"RX6 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003733 {"RX6 MIX1 INP2", "RX6", "SLIM RX6"},
3734 {"RX6 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003735 {"RX6 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07003736 {"RX7 MIX1 INP1", "RX1", "SLIM RX1"},
3737 {"RX7 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303738 {"RX7 MIX1 INP1", "RX3", "SLIM RX3"},
3739 {"RX7 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003740 {"RX7 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003741 {"RX7 MIX1 INP1", "RX6", "SLIM RX6"},
3742 {"RX7 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003743 {"RX7 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07003744 {"RX7 MIX1 INP2", "RX1", "SLIM RX1"},
3745 {"RX7 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303746 {"RX7 MIX1 INP2", "RX3", "SLIM RX3"},
3747 {"RX7 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003748 {"RX7 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003749 {"RX7 MIX1 INP2", "RX6", "SLIM RX6"},
3750 {"RX7 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003751 {"RX7 MIX1 INP2", "IIR1", "IIR1"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003752 {"RX1 MIX2 INP1", "IIR1", "IIR1"},
3753 {"RX1 MIX2 INP2", "IIR1", "IIR1"},
3754 {"RX2 MIX2 INP1", "IIR1", "IIR1"},
3755 {"RX2 MIX2 INP2", "IIR1", "IIR1"},
3756 {"RX3 MIX2 INP1", "IIR1", "IIR1"},
3757 {"RX3 MIX2 INP2", "IIR1", "IIR1"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003758
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003759 /* Decimator Inputs */
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003760 {"DEC1 MUX", "DMIC1", "DMIC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003761 {"DEC1 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003762 {"DEC1 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003763 {"DEC2 MUX", "DMIC2", "DMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003764 {"DEC2 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003765 {"DEC2 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003766 {"DEC3 MUX", "DMIC3", "DMIC3"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003767 {"DEC3 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003768 {"DEC3 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07003769 {"DEC4 MUX", "DMIC4", "DMIC4"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003770 {"DEC4 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003771 {"DEC4 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07003772 {"DEC5 MUX", "DMIC5", "DMIC5"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003773 {"DEC5 MUX", "ADC2", "ADC2"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003774 {"DEC5 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07003775 {"DEC6 MUX", "DMIC6", "DMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003776 {"DEC6 MUX", "ADC1", "ADC1"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003777 {"DEC6 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003778 {"DEC7 MUX", "DMIC1", "DMIC1"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003779 {"DEC7 MUX", "DMIC6", "DMIC6"},
3780 {"DEC7 MUX", "ADC1", "ADC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003781 {"DEC7 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003782 {"DEC7 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003783 {"DEC8 MUX", "DMIC2", "DMIC2"},
3784 {"DEC8 MUX", "DMIC5", "DMIC5"},
3785 {"DEC8 MUX", "ADC2", "ADC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003786 {"DEC8 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003787 {"DEC8 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003788 {"DEC9 MUX", "DMIC4", "DMIC4"},
3789 {"DEC9 MUX", "DMIC5", "DMIC5"},
3790 {"DEC9 MUX", "ADC2", "ADC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003791 {"DEC9 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003792 {"DEC9 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003793 {"DEC10 MUX", "DMIC3", "DMIC3"},
3794 {"DEC10 MUX", "DMIC6", "DMIC6"},
3795 {"DEC10 MUX", "ADC1", "ADC1"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003796 {"DEC10 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003797 {"DEC10 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003798
3799 /* ADC Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003800 {"ADC1", NULL, "AMIC1"},
3801 {"ADC2", NULL, "AMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003802 {"ADC3", NULL, "AMIC3"},
3803 {"ADC4", NULL, "AMIC4"},
3804 {"ADC5", NULL, "AMIC5"},
3805 {"ADC6", NULL, "AMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003806
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003807 /* AUX PGA Connections */
3808 {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3809 {"HPHL_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3810 {"HPHL_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3811 {"HPHL_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3812 {"HPHR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3813 {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3814 {"HPHR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3815 {"HPHR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3816 {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3817 {"LINEOUT1_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3818 {"LINEOUT1_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3819 {"LINEOUT1_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3820 {"LINEOUT2_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3821 {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3822 {"LINEOUT2_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3823 {"LINEOUT2_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3824 {"LINEOUT3_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3825 {"LINEOUT3_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3826 {"LINEOUT3_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3827 {"LINEOUT3_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3828 {"LINEOUT4_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3829 {"LINEOUT4_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3830 {"LINEOUT4_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3831 {"LINEOUT4_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3832 {"LINEOUT5_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3833 {"LINEOUT5_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3834 {"LINEOUT5_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3835 {"LINEOUT5_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3836 {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3837 {"EAR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3838 {"EAR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3839 {"EAR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3840 {"AUX_PGA_Left", NULL, "AMIC5"},
3841 {"AUX_PGA_Right", NULL, "AMIC6"},
3842
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003843 {"IIR1", NULL, "IIR1 INP1 MUX"},
Patrick Lai16261e82011-09-30 13:25:52 -07003844 {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"},
3845 {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"},
3846 {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"},
3847 {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"},
3848 {"IIR1 INP1 MUX", "DEC5", "DEC5 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003849 {"IIR1 INP1 MUX", "DEC6", "DEC6 MUX"},
Patrick Lai16261e82011-09-30 13:25:52 -07003850 {"IIR1 INP1 MUX", "DEC7", "DEC7 MUX"},
3851 {"IIR1 INP1 MUX", "DEC8", "DEC8 MUX"},
3852 {"IIR1 INP1 MUX", "DEC9", "DEC9 MUX"},
3853 {"IIR1 INP1 MUX", "DEC10", "DEC10 MUX"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003854
3855 {"MIC BIAS1 Internal1", NULL, "LDO_H"},
3856 {"MIC BIAS1 Internal2", NULL, "LDO_H"},
3857 {"MIC BIAS1 External", NULL, "LDO_H"},
3858 {"MIC BIAS2 Internal1", NULL, "LDO_H"},
3859 {"MIC BIAS2 Internal2", NULL, "LDO_H"},
3860 {"MIC BIAS2 Internal3", NULL, "LDO_H"},
3861 {"MIC BIAS2 External", NULL, "LDO_H"},
3862 {"MIC BIAS3 Internal1", NULL, "LDO_H"},
3863 {"MIC BIAS3 Internal2", NULL, "LDO_H"},
3864 {"MIC BIAS3 External", NULL, "LDO_H"},
3865 {"MIC BIAS4 External", NULL, "LDO_H"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003866};
3867
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003868static const struct snd_soc_dapm_route tabla_1_x_lineout_2_to_4_map[] = {
3869
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003870 {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003871 {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"},
3872
3873 {"LINEOUT2 DAC", NULL, "RX4 DSM MUX"},
3874
3875 {"LINEOUT3 DAC", NULL, "RX5 MIX1"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003876 {"LINEOUT3 DAC GROUND", "Switch", "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003877 {"LINEOUT3 DAC", NULL, "LINEOUT3 DAC GROUND"},
3878
3879 {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"},
3880 {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"},
3881
3882 {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"},
3883 {"LINEOUT4 DAC GROUND", "Switch", "RX4 DSM MUX"},
3884 {"LINEOUT4 DAC", NULL, "LINEOUT4 DAC GROUND"},
3885};
3886
Kiran Kandi7a9fd902011-11-14 13:51:45 -08003887
3888static const struct snd_soc_dapm_route tabla_2_x_lineout_2_to_4_map[] = {
3889
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003890 {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"},
Kiran Kandi7a9fd902011-11-14 13:51:45 -08003891 {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"},
3892
3893 {"LINEOUT3 DAC", NULL, "RX4 DSM MUX"},
3894
3895 {"LINEOUT2 DAC", NULL, "RX5 MIX1"},
3896
3897 {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"},
3898 {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"},
3899
3900 {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"},
3901};
3902
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003903static int tabla_readable(struct snd_soc_codec *ssc, unsigned int reg)
3904{
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003905 int i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303906 struct wcd9xxx *tabla_core = dev_get_drvdata(ssc->dev->parent);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003907
3908 if (TABLA_IS_1_X(tabla_core->version)) {
3909 for (i = 0; i < ARRAY_SIZE(tabla_1_reg_readable); i++) {
3910 if (tabla_1_reg_readable[i] == reg)
3911 return 1;
3912 }
3913 } else {
3914 for (i = 0; i < ARRAY_SIZE(tabla_2_reg_readable); i++) {
3915 if (tabla_2_reg_readable[i] == reg)
3916 return 1;
3917 }
3918 }
3919
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003920 return tabla_reg_readable[reg];
3921}
Kuirong Wange9c8a222012-03-28 16:24:09 -07003922static bool tabla_is_digital_gain_register(unsigned int reg)
3923{
3924 bool rtn = false;
3925 switch (reg) {
3926 case TABLA_A_CDC_RX1_VOL_CTL_B2_CTL:
3927 case TABLA_A_CDC_RX2_VOL_CTL_B2_CTL:
3928 case TABLA_A_CDC_RX3_VOL_CTL_B2_CTL:
3929 case TABLA_A_CDC_RX4_VOL_CTL_B2_CTL:
3930 case TABLA_A_CDC_RX5_VOL_CTL_B2_CTL:
3931 case TABLA_A_CDC_RX6_VOL_CTL_B2_CTL:
3932 case TABLA_A_CDC_RX7_VOL_CTL_B2_CTL:
3933 case TABLA_A_CDC_TX1_VOL_CTL_GAIN:
3934 case TABLA_A_CDC_TX2_VOL_CTL_GAIN:
3935 case TABLA_A_CDC_TX3_VOL_CTL_GAIN:
3936 case TABLA_A_CDC_TX4_VOL_CTL_GAIN:
3937 case TABLA_A_CDC_TX5_VOL_CTL_GAIN:
3938 case TABLA_A_CDC_TX6_VOL_CTL_GAIN:
3939 case TABLA_A_CDC_TX7_VOL_CTL_GAIN:
3940 case TABLA_A_CDC_TX8_VOL_CTL_GAIN:
3941 case TABLA_A_CDC_TX9_VOL_CTL_GAIN:
3942 case TABLA_A_CDC_TX10_VOL_CTL_GAIN:
3943 rtn = true;
3944 break;
3945 default:
3946 break;
3947 }
3948 return rtn;
3949}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003950static int tabla_volatile(struct snd_soc_codec *ssc, unsigned int reg)
3951{
3952 /* Registers lower than 0x100 are top level registers which can be
3953 * written by the Tabla core driver.
3954 */
3955
3956 if ((reg >= TABLA_A_CDC_MBHC_EN_CTL) || (reg < 0x100))
3957 return 1;
3958
Ben Romberger1f045a72011-11-04 10:14:57 -07003959 /* IIR Coeff registers are not cacheable */
3960 if ((reg >= TABLA_A_CDC_IIR1_COEF_B1_CTL) &&
3961 (reg <= TABLA_A_CDC_IIR2_COEF_B5_CTL))
3962 return 1;
3963
Kuirong Wange9c8a222012-03-28 16:24:09 -07003964 /* Digital gain register is not cacheable so we have to write
3965 * the setting even it is the same
3966 */
3967 if (tabla_is_digital_gain_register(reg))
3968 return 1;
3969
Joonwoo Parkab2c5872012-05-03 15:16:02 -07003970 /* HPH status registers */
3971 if (reg == TABLA_A_RX_HPH_L_STATUS || reg == TABLA_A_RX_HPH_R_STATUS)
3972 return 1;
3973
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003974 return 0;
3975}
3976
3977#define TABLA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
3978static int tabla_write(struct snd_soc_codec *codec, unsigned int reg,
3979 unsigned int value)
3980{
3981 int ret;
Kuirong Wang906ac472012-07-09 12:54:44 -07003982
3983 if (reg == SND_SOC_NOPM)
3984 return 0;
3985
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003986 BUG_ON(reg > TABLA_MAX_REGISTER);
3987
3988 if (!tabla_volatile(codec, reg)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003989 ret = snd_soc_cache_write(codec, reg, value);
3990 if (ret != 0)
3991 dev_err(codec->dev, "Cache write to %x failed: %d\n",
3992 reg, ret);
3993 }
3994
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303995 return wcd9xxx_reg_write(codec->control_data, reg, value);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003996}
3997static unsigned int tabla_read(struct snd_soc_codec *codec,
3998 unsigned int reg)
3999{
4000 unsigned int val;
4001 int ret;
4002
Kuirong Wang906ac472012-07-09 12:54:44 -07004003 if (reg == SND_SOC_NOPM)
4004 return 0;
4005
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004006 BUG_ON(reg > TABLA_MAX_REGISTER);
4007
4008 if (!tabla_volatile(codec, reg) && tabla_readable(codec, reg) &&
4009 reg < codec->driver->reg_cache_size) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004010 ret = snd_soc_cache_read(codec, reg, &val);
4011 if (ret >= 0) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004012 return val;
4013 } else
4014 dev_err(codec->dev, "Cache read from %x failed: %d\n",
4015 reg, ret);
4016 }
4017
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304018 val = wcd9xxx_reg_read(codec->control_data, reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004019 return val;
4020}
4021
Joonwoo Parkcf473b42012-03-29 19:48:16 -07004022static s16 tabla_get_current_v_ins(struct tabla_priv *tabla, bool hu)
4023{
4024 s16 v_ins;
4025 if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) &&
4026 tabla->mbhc_micbias_switched)
4027 v_ins = hu ? (s16)tabla->mbhc_data.adj_v_ins_hu :
4028 (s16)tabla->mbhc_data.adj_v_ins_h;
4029 else
4030 v_ins = hu ? (s16)tabla->mbhc_data.v_ins_hu :
4031 (s16)tabla->mbhc_data.v_ins_h;
4032 return v_ins;
4033}
4034
4035static s16 tabla_get_current_v_hs_max(struct tabla_priv *tabla)
4036{
4037 s16 v_hs_max;
4038 struct tabla_mbhc_plug_type_cfg *plug_type;
4039
4040 plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
4041 if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) &&
4042 tabla->mbhc_micbias_switched)
4043 v_hs_max = tabla->mbhc_data.adj_v_hs_max;
4044 else
4045 v_hs_max = plug_type->v_hs_max;
4046 return v_hs_max;
4047}
4048
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07004049static void tabla_codec_calibrate_rel(struct snd_soc_codec *codec)
Bradley Rubincb1e2732011-06-23 16:49:20 -07004050{
Joonwoo Park0976d012011-12-22 11:48:18 -08004051 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004052
Joonwoo Park0976d012011-12-22 11:48:18 -08004053 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL,
4054 tabla->mbhc_data.v_b1_hu & 0xFF);
4055 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL,
4056 (tabla->mbhc_data.v_b1_hu >> 8) & 0xFF);
4057
4058 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL,
4059 tabla->mbhc_data.v_b1_h & 0xFF);
4060 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL,
4061 (tabla->mbhc_data.v_b1_h >> 8) & 0xFF);
4062
4063 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B9_CTL,
4064 tabla->mbhc_data.v_brh & 0xFF);
4065 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B10_CTL,
4066 (tabla->mbhc_data.v_brh >> 8) & 0xFF);
4067
4068 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B11_CTL,
4069 tabla->mbhc_data.v_brl & 0xFF);
4070 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B12_CTL,
4071 (tabla->mbhc_data.v_brl >> 8) & 0xFF);
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07004072}
4073
4074static void tabla_codec_calibrate_hs_polling(struct snd_soc_codec *codec)
4075{
4076 u8 *n_ready, *n_cic;
4077 struct tabla_mbhc_btn_detect_cfg *btn_det;
4078 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
4079 const s16 v_ins_hu = tabla_get_current_v_ins(tabla, true);
4080
4081 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
4082
4083 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
4084 v_ins_hu & 0xFF);
4085 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
4086 (v_ins_hu >> 8) & 0xFF);
4087
4088 tabla_codec_calibrate_rel(codec);
Joonwoo Park0976d012011-12-22 11:48:18 -08004089
Joonwoo Parkc0672392012-01-11 11:03:14 -08004090 n_ready = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_READY);
Joonwoo Park0976d012011-12-22 11:48:18 -08004091 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL,
Joonwoo Parkc0672392012-01-11 11:03:14 -08004092 n_ready[tabla_codec_mclk_index(tabla)]);
Joonwoo Park0976d012011-12-22 11:48:18 -08004093 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B2_CTL,
4094 tabla->mbhc_data.npoll);
4095 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B3_CTL,
4096 tabla->mbhc_data.nbounce_wait);
Joonwoo Park0976d012011-12-22 11:48:18 -08004097 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
Joonwoo Park107edf02012-01-11 11:42:24 -08004098 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL,
4099 n_cic[tabla_codec_mclk_index(tabla)]);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004100}
4101
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004102static int tabla_startup(struct snd_pcm_substream *substream,
4103 struct snd_soc_dai *dai)
4104{
Kuirong Wanga545e722012-02-06 19:12:54 -08004105 struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004106 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
4107 substream->name, substream->stream);
Kuirong Wanga545e722012-02-06 19:12:54 -08004108 if ((tabla_core != NULL) &&
4109 (tabla_core->dev != NULL) &&
4110 (tabla_core->dev->parent != NULL))
4111 pm_runtime_get_sync(tabla_core->dev->parent);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004112
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004113 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004114}
4115
Swaminathan Sathappanf95ece62012-08-23 16:01:50 -07004116static void tabla_shutdown(struct snd_pcm_substream *substream,
4117 struct snd_soc_dai *dai)
4118{
4119 struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent);
4120 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
4121 u32 active = 0;
4122
4123 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
4124 substream->name, substream->stream);
4125 if (tabla->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
4126 return;
4127
4128 if (dai->id <= NUM_CODEC_DAIS) {
Kuirong Wang906ac472012-07-09 12:54:44 -07004129 if (tabla->dai[dai->id].ch_mask) {
Swaminathan Sathappanf95ece62012-08-23 16:01:50 -07004130 active = 1;
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08004131 pr_debug("%s(): Codec DAI: chmask[%d] = 0x%lx\n",
Kuirong Wang906ac472012-07-09 12:54:44 -07004132 __func__, dai->id, tabla->dai[dai->id].ch_mask);
Swaminathan Sathappanf95ece62012-08-23 16:01:50 -07004133 }
4134 }
4135
4136 if ((tabla_core != NULL) &&
4137 (tabla_core->dev != NULL) &&
4138 (tabla_core->dev->parent != NULL) &&
4139 (active == 0)) {
4140 pm_runtime_mark_last_busy(tabla_core->dev->parent);
4141 pm_runtime_put(tabla_core->dev->parent);
4142 }
4143}
4144
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004145int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, bool dapm)
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004146{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004147 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
4148
Joonwoo Parkcf473b42012-03-29 19:48:16 -07004149 pr_debug("%s: mclk_enable = %u, dapm = %d\n", __func__, mclk_enable,
4150 dapm);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004151 if (dapm)
4152 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004153 if (mclk_enable) {
4154 tabla->mclk_enabled = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004155
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004156 if (tabla->mbhc_polling_active) {
Bradley Rubincb1e2732011-06-23 16:49:20 -07004157 tabla_codec_pause_hs_polling(codec);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004158 tabla_codec_disable_clock_block(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004159 tabla_codec_enable_bandgap(codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004160 TABLA_BANDGAP_AUDIO_MODE);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004161 tabla_codec_enable_clock_block(codec, 0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07004162 tabla_codec_calibrate_hs_polling(codec);
4163 tabla_codec_start_hs_polling(codec);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05304164 } else {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004165 tabla_codec_disable_clock_block(codec);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05304166 tabla_codec_enable_bandgap(codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004167 TABLA_BANDGAP_AUDIO_MODE);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05304168 tabla_codec_enable_clock_block(codec, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004169 }
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004170 } else {
4171
4172 if (!tabla->mclk_enabled) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004173 if (dapm)
4174 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004175 pr_err("Error, MCLK already diabled\n");
4176 return -EINVAL;
4177 }
4178 tabla->mclk_enabled = false;
4179
4180 if (tabla->mbhc_polling_active) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004181 tabla_codec_pause_hs_polling(codec);
4182 tabla_codec_disable_clock_block(codec);
4183 tabla_codec_enable_bandgap(codec,
4184 TABLA_BANDGAP_MBHC_MODE);
4185 tabla_enable_rx_bias(codec, 1);
4186 tabla_codec_enable_clock_block(codec, 1);
4187 tabla_codec_calibrate_hs_polling(codec);
4188 tabla_codec_start_hs_polling(codec);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004189 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1,
4190 0x05, 0x01);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05304191 } else {
4192 tabla_codec_disable_clock_block(codec);
4193 tabla_codec_enable_bandgap(codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07004194 TABLA_BANDGAP_OFF);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004195 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004196 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004197 if (dapm)
4198 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07004199 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004200}
4201
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004202static int tabla_set_dai_sysclk(struct snd_soc_dai *dai,
4203 int clk_id, unsigned int freq, int dir)
4204{
4205 pr_debug("%s\n", __func__);
4206 return 0;
4207}
4208
4209static int tabla_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
4210{
Santosh Mardie15e2302011-11-15 10:39:23 +05304211 u8 val = 0;
4212 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
4213
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004214 pr_debug("%s\n", __func__);
Santosh Mardie15e2302011-11-15 10:39:23 +05304215 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
4216 case SND_SOC_DAIFMT_CBS_CFS:
4217 /* CPU is master */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304218 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004219 if (dai->id == AIF1_CAP)
Santosh Mardie15e2302011-11-15 10:39:23 +05304220 snd_soc_update_bits(dai->codec,
4221 TABLA_A_CDC_CLK_TX_I2S_CTL,
4222 TABLA_I2S_MASTER_MODE_MASK, 0);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004223 else if (dai->id == AIF1_PB)
Santosh Mardie15e2302011-11-15 10:39:23 +05304224 snd_soc_update_bits(dai->codec,
4225 TABLA_A_CDC_CLK_RX_I2S_CTL,
4226 TABLA_I2S_MASTER_MODE_MASK, 0);
4227 }
4228 break;
4229 case SND_SOC_DAIFMT_CBM_CFM:
4230 /* CPU is slave */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304231 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05304232 val = TABLA_I2S_MASTER_MODE_MASK;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004233 if (dai->id == AIF1_CAP)
Santosh Mardie15e2302011-11-15 10:39:23 +05304234 snd_soc_update_bits(dai->codec,
4235 TABLA_A_CDC_CLK_TX_I2S_CTL, val, val);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004236 else if (dai->id == AIF1_PB)
Santosh Mardie15e2302011-11-15 10:39:23 +05304237 snd_soc_update_bits(dai->codec,
4238 TABLA_A_CDC_CLK_RX_I2S_CTL, val, val);
4239 }
4240 break;
4241 default:
4242 return -EINVAL;
4243 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004244 return 0;
4245}
4246
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004247static int tabla_set_channel_map(struct snd_soc_dai *dai,
4248 unsigned int tx_num, unsigned int *tx_slot,
4249 unsigned int rx_num, unsigned int *rx_slot)
4250
4251{
4252 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
Kuirong Wang906ac472012-07-09 12:54:44 -07004253 struct wcd9xxx *core = dev_get_drvdata(dai->codec->dev->parent);
4254
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004255 if (!tx_slot && !rx_slot) {
4256 pr_err("%s: Invalid\n", __func__);
4257 return -EINVAL;
4258 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004259 pr_debug("%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n"
4260 "tabla->intf_type %d\n",
4261 __func__, dai->name, dai->id, tx_num, rx_num,
4262 tabla->intf_type);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004263
Kuirong Wang906ac472012-07-09 12:54:44 -07004264 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
4265 wcd9xxx_init_slimslave(core, core->slim->laddr,
4266 tx_num, tx_slot, rx_num, rx_slot);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004267 return 0;
4268}
4269
4270static int tabla_get_channel_map(struct snd_soc_dai *dai,
4271 unsigned int *tx_num, unsigned int *tx_slot,
4272 unsigned int *rx_num, unsigned int *rx_slot)
4273
4274{
Kuirong Wang906ac472012-07-09 12:54:44 -07004275 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(dai->codec);
4276 u32 i = 0;
4277 struct wcd9xxx_ch *ch;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004278
Kuirong Wang906ac472012-07-09 12:54:44 -07004279 switch (dai->id) {
4280 case AIF1_PB:
4281 case AIF2_PB:
4282 case AIF3_PB:
4283 if (!rx_slot || !rx_num) {
4284 pr_err("%s: Invalid rx_slot %d or rx_num %d\n",
4285 __func__, (u32) rx_slot, (u32) rx_num);
4286 return -EINVAL;
4287 }
4288 list_for_each_entry(ch, &tabla_p->dai[dai->id].wcd9xxx_ch_list,
4289 list) {
4290 rx_slot[i++] = ch->ch_num;
4291 }
4292 *rx_num = i;
4293 break;
4294 case AIF1_CAP:
4295 case AIF2_CAP:
4296 case AIF3_CAP:
4297 if (!tx_slot || !tx_num) {
4298 pr_err("%s: Invalid tx_slot %d or tx_num %d\n",
4299 __func__, (u32) tx_slot, (u32) tx_num);
4300 return -EINVAL;
4301 }
4302 list_for_each_entry(ch, &tabla_p->dai[dai->id].wcd9xxx_ch_list,
4303 list) {
4304 tx_slot[i++] = ch->ch_num;
4305 }
4306 *tx_num = i;
4307 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004308
Kuirong Wang906ac472012-07-09 12:54:44 -07004309 default:
4310 pr_err("%s: Invalid DAI ID %x\n", __func__, dai->id);
4311 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004312 }
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004313 return 0;
4314}
4315
Kiran Kandi93923902012-06-20 17:00:25 -07004316
Kiran Kandi93923902012-06-20 17:00:25 -07004317static int tabla_set_interpolator_rate(struct snd_soc_dai *dai,
Kuirong Wang906ac472012-07-09 12:54:44 -07004318 u8 rx_fs_rate_reg_val,
4319 u32 compander_fs,
4320 u32 sample_rate)
Kiran Kandi93923902012-06-20 17:00:25 -07004321{
Kuirong Wang906ac472012-07-09 12:54:44 -07004322 u32 j;
Kiran Kandi93923902012-06-20 17:00:25 -07004323 u8 rx_mix1_inp;
4324 u16 rx_mix_1_reg_1, rx_mix_1_reg_2;
4325 u16 rx_fs_reg;
4326 u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val;
4327 struct snd_soc_codec *codec = dai->codec;
Kuirong Wang906ac472012-07-09 12:54:44 -07004328 struct wcd9xxx_ch *ch;
Kiran Kandi93923902012-06-20 17:00:25 -07004329 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Kiran Kandi93923902012-06-20 17:00:25 -07004330
Kuirong Wang906ac472012-07-09 12:54:44 -07004331 list_for_each_entry(ch, &tabla->dai[dai->id].wcd9xxx_ch_list, list) {
Kiran Kandi93923902012-06-20 17:00:25 -07004332
Kuirong Wang906ac472012-07-09 12:54:44 -07004333 rx_mix1_inp = ch->port - RX_MIX1_INP_SEL_RX1;
Kiran Kandi93923902012-06-20 17:00:25 -07004334
Kuirong Wang906ac472012-07-09 12:54:44 -07004335 if ((rx_mix1_inp < RX_MIX1_INP_SEL_RX1) ||
4336 (rx_mix1_inp > RX_MIX1_INP_SEL_RX7)) {
4337 pr_err("%s: Invalid TABLA_RX%u port. Dai ID is %d\n",
4338 __func__, rx_mix1_inp - 5 , dai->id);
Kiran Kandi93923902012-06-20 17:00:25 -07004339 return -EINVAL;
4340 }
4341
4342 rx_mix_1_reg_1 = TABLA_A_CDC_CONN_RX1_B1_CTL;
4343
4344 for (j = 0; j < NUM_INTERPOLATORS; j++) {
Kiran Kandi93923902012-06-20 17:00:25 -07004345 rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1;
4346
4347 rx_mix_1_reg_1_val = snd_soc_read(codec,
Kuirong Wang906ac472012-07-09 12:54:44 -07004348 rx_mix_1_reg_1);
Kiran Kandi93923902012-06-20 17:00:25 -07004349 rx_mix_1_reg_2_val = snd_soc_read(codec,
Kuirong Wang906ac472012-07-09 12:54:44 -07004350 rx_mix_1_reg_2);
Kiran Kandi93923902012-06-20 17:00:25 -07004351
4352 if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) ||
Kuirong Wang906ac472012-07-09 12:54:44 -07004353 (((rx_mix_1_reg_1_val >> 4) & 0x0F) == rx_mix1_inp) ||
4354 ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) {
Kiran Kandi93923902012-06-20 17:00:25 -07004355
4356 rx_fs_reg = TABLA_A_CDC_RX1_B5_CTL + 8 * j;
4357
Kuirong Wang906ac472012-07-09 12:54:44 -07004358 pr_debug("%s: AIF_PB DAI(%d) connected to RX%u\n",
4359 __func__, dai->id, j + 1);
Kiran Kandi93923902012-06-20 17:00:25 -07004360
4361 pr_debug("%s: set RX%u sample rate to %u\n",
4362 __func__, j + 1, sample_rate);
4363
4364 snd_soc_update_bits(codec, rx_fs_reg,
Kuirong Wang906ac472012-07-09 12:54:44 -07004365 0xE0, rx_fs_rate_reg_val);
Kiran Kandi93923902012-06-20 17:00:25 -07004366
4367 if (comp_rx_path[j] < COMPANDER_MAX)
4368 tabla->comp_fs[comp_rx_path[j]]
4369 = compander_fs;
4370 }
4371 if (j <= 2)
4372 rx_mix_1_reg_1 += 3;
4373 else
4374 rx_mix_1_reg_1 += 2;
4375 }
4376 }
4377 return 0;
4378}
4379
4380static int tabla_set_decimator_rate(struct snd_soc_dai *dai,
Kuirong Wang906ac472012-07-09 12:54:44 -07004381 u8 tx_fs_rate_reg_val,
4382 u32 sample_rate)
Kiran Kandi93923902012-06-20 17:00:25 -07004383{
4384 struct snd_soc_codec *codec = dai->codec;
Kuirong Wang906ac472012-07-09 12:54:44 -07004385 struct wcd9xxx_ch *ch;
4386 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
4387 u32 tx_port;
Kiran Kandi93923902012-06-20 17:00:25 -07004388 u16 tx_port_reg, tx_fs_reg;
4389 u8 tx_port_reg_val;
4390 s8 decimator;
4391
Kuirong Wang906ac472012-07-09 12:54:44 -07004392 list_for_each_entry(ch, &tabla->dai[dai->id].wcd9xxx_ch_list, list) {
Kiran Kandi93923902012-06-20 17:00:25 -07004393
Kuirong Wang906ac472012-07-09 12:54:44 -07004394 tx_port = ch->port + 1;
4395 pr_debug("%s: dai->id = %d, tx_port = %d",
4396 __func__, dai->id, tx_port);
Kiran Kandi93923902012-06-20 17:00:25 -07004397
4398 if ((tx_port < 1) || (tx_port > NUM_DECIMATORS)) {
Kuirong Wang906ac472012-07-09 12:54:44 -07004399 pr_err("%s: Invalid SLIM TX%u port. DAI ID is %d\n",
4400 __func__, tx_port, dai->id);
Kiran Kandi93923902012-06-20 17:00:25 -07004401 return -EINVAL;
4402 }
4403
4404 tx_port_reg = TABLA_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1);
4405 tx_port_reg_val = snd_soc_read(codec, tx_port_reg);
4406
4407 decimator = 0;
4408
4409 if ((tx_port >= 1) && (tx_port <= 6)) {
4410
4411 tx_port_reg_val = tx_port_reg_val & 0x0F;
4412 if (tx_port_reg_val == 0x8)
4413 decimator = tx_port;
4414
4415 } else if ((tx_port >= 7) && (tx_port <= NUM_DECIMATORS)) {
4416
4417 tx_port_reg_val = tx_port_reg_val & 0x1F;
4418
4419 if ((tx_port_reg_val >= 0x8) &&
4420 (tx_port_reg_val <= 0x11)) {
4421
4422 decimator = (tx_port_reg_val - 0x8) + 1;
4423 }
4424 }
4425
4426 if (decimator) { /* SLIM_TX port has a DEC as input */
4427
4428 tx_fs_reg = TABLA_A_CDC_TX1_CLK_FS_CTL +
Kuirong Wang906ac472012-07-09 12:54:44 -07004429 8 * (decimator - 1);
Kiran Kandi93923902012-06-20 17:00:25 -07004430
4431 pr_debug("%s: set DEC%u (-> SLIM_TX%u) rate to %u\n",
4432 __func__, decimator, tx_port, sample_rate);
4433
4434 snd_soc_update_bits(codec, tx_fs_reg, 0x07,
Kuirong Wang906ac472012-07-09 12:54:44 -07004435 tx_fs_rate_reg_val);
Kiran Kandi93923902012-06-20 17:00:25 -07004436
4437 } else {
4438 if ((tx_port_reg_val >= 0x1) &&
Kuirong Wang906ac472012-07-09 12:54:44 -07004439 (tx_port_reg_val <= 0x7)) {
Kiran Kandi93923902012-06-20 17:00:25 -07004440
4441 pr_debug("%s: RMIX%u going to SLIM TX%u\n",
4442 __func__, tx_port_reg_val, tx_port);
4443
4444 } else if ((tx_port_reg_val >= 0x8) &&
Kuirong Wang906ac472012-07-09 12:54:44 -07004445 (tx_port_reg_val <= 0x11)) {
Kiran Kandi93923902012-06-20 17:00:25 -07004446
4447 pr_err("%s: ERROR: Should not be here\n",
Kuirong Wang906ac472012-07-09 12:54:44 -07004448 __func__);
4449 pr_err("%s: ERROR: DEC connected to SLIM TX%u\n",
4450 __func__, tx_port);
Kiran Kandi93923902012-06-20 17:00:25 -07004451 return -EINVAL;
4452
4453 } else if (tx_port_reg_val == 0) {
4454 pr_debug("%s: no signal to SLIM TX%u\n",
Kuirong Wang906ac472012-07-09 12:54:44 -07004455 __func__, tx_port);
Kiran Kandi93923902012-06-20 17:00:25 -07004456 } else {
Kuirong Wang906ac472012-07-09 12:54:44 -07004457 pr_err("%s: ERROR: wrong signal to SLIM TX%u\n",
4458 __func__, tx_port);
4459 pr_err("%s: ERROR: wrong signal = %u\n",
4460 __func__, tx_port_reg_val);
Kiran Kandi93923902012-06-20 17:00:25 -07004461 return -EINVAL;
4462 }
4463 }
4464 }
4465 return 0;
4466}
4467
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004468static int tabla_hw_params(struct snd_pcm_substream *substream,
Kuirong Wang906ac472012-07-09 12:54:44 -07004469 struct snd_pcm_hw_params *params,
4470 struct snd_soc_dai *dai)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004471{
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004472 struct snd_soc_codec *codec = dai->codec;
Santosh Mardie15e2302011-11-15 10:39:23 +05304473 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
Kiran Kandi93923902012-06-20 17:00:25 -07004474 u8 tx_fs_rate_reg_val, rx_fs_rate_reg_val;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004475 u32 compander_fs;
Kiran Kandi93923902012-06-20 17:00:25 -07004476 int ret;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004477
Kiran Kandia9fffe92012-05-20 23:42:30 -07004478 pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004479 dai->name, dai->id, params_rate(params),
4480 params_channels(params));
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004481
4482 switch (params_rate(params)) {
4483 case 8000:
Kiran Kandi93923902012-06-20 17:00:25 -07004484 tx_fs_rate_reg_val = 0x00;
4485 rx_fs_rate_reg_val = 0x00;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004486 compander_fs = COMPANDER_FS_8KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004487 break;
4488 case 16000:
Kiran Kandi93923902012-06-20 17:00:25 -07004489 tx_fs_rate_reg_val = 0x01;
4490 rx_fs_rate_reg_val = 0x20;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004491 compander_fs = COMPANDER_FS_16KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004492 break;
4493 case 32000:
Kiran Kandi93923902012-06-20 17:00:25 -07004494 tx_fs_rate_reg_val = 0x02;
4495 rx_fs_rate_reg_val = 0x40;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004496 compander_fs = COMPANDER_FS_32KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004497 break;
4498 case 48000:
Kiran Kandi93923902012-06-20 17:00:25 -07004499 tx_fs_rate_reg_val = 0x03;
4500 rx_fs_rate_reg_val = 0x60;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004501 compander_fs = COMPANDER_FS_48KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004502 break;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004503 case 96000:
Kiran Kandi93923902012-06-20 17:00:25 -07004504 tx_fs_rate_reg_val = 0x04;
4505 rx_fs_rate_reg_val = 0x80;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004506 compander_fs = COMPANDER_FS_96KHZ;
4507 break;
4508 case 192000:
Kiran Kandi93923902012-06-20 17:00:25 -07004509 tx_fs_rate_reg_val = 0x05;
4510 rx_fs_rate_reg_val = 0xA0;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004511 compander_fs = COMPANDER_FS_192KHZ;
4512 break;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004513 default:
4514 pr_err("%s: Invalid sampling rate %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004515 params_rate(params));
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004516 return -EINVAL;
4517 }
4518
Kiran Kandi93923902012-06-20 17:00:25 -07004519 switch (substream->stream) {
4520 case SNDRV_PCM_STREAM_CAPTURE:
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004521
Kiran Kandi93923902012-06-20 17:00:25 -07004522 ret = tabla_set_decimator_rate(dai, tx_fs_rate_reg_val,
Kuirong Wang906ac472012-07-09 12:54:44 -07004523 params_rate(params));
Kiran Kandi93923902012-06-20 17:00:25 -07004524 if (ret < 0) {
4525 pr_err("%s: set decimator rate failed %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004526 ret);
Kiran Kandi93923902012-06-20 17:00:25 -07004527 return ret;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004528 }
Kiran Kandi93923902012-06-20 17:00:25 -07004529
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304530 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05304531 switch (params_format(params)) {
4532 case SNDRV_PCM_FORMAT_S16_LE:
4533 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004534 TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x20);
Santosh Mardie15e2302011-11-15 10:39:23 +05304535 break;
4536 case SNDRV_PCM_FORMAT_S32_LE:
4537 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004538 TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x00);
Santosh Mardie15e2302011-11-15 10:39:23 +05304539 break;
4540 default:
Kuirong Wang906ac472012-07-09 12:54:44 -07004541 pr_err("%s: Invalid format %d\n", __func__,
4542 params_format(params));
Kiran Kandi93923902012-06-20 17:00:25 -07004543 return -EINVAL;
Santosh Mardie15e2302011-11-15 10:39:23 +05304544 }
4545 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_TX_I2S_CTL,
Kuirong Wang906ac472012-07-09 12:54:44 -07004546 0x07, tx_fs_rate_reg_val);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004547 } else {
Kuirong Wang906ac472012-07-09 12:54:44 -07004548 switch (params_format(params)) {
4549 case SNDRV_PCM_FORMAT_S16_LE:
4550 tabla->dai[dai->id].bit_width = 16;
4551 break;
4552 default:
4553 pr_err("%s: Invalid TX format %d\n", __func__,
4554 params_format(params));
4555 return -EINVAL;
4556 }
4557 tabla->dai[dai->id].rate = params_rate(params);
Santosh Mardie15e2302011-11-15 10:39:23 +05304558 }
Kiran Kandi93923902012-06-20 17:00:25 -07004559 break;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004560
Kiran Kandi93923902012-06-20 17:00:25 -07004561 case SNDRV_PCM_STREAM_PLAYBACK:
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004562
Kiran Kandi93923902012-06-20 17:00:25 -07004563 ret = tabla_set_interpolator_rate(dai, rx_fs_rate_reg_val,
Kuirong Wang906ac472012-07-09 12:54:44 -07004564 compander_fs,
4565 params_rate(params));
Kiran Kandi93923902012-06-20 17:00:25 -07004566 if (ret < 0) {
4567 pr_err("%s: set decimator rate failed %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004568 ret);
Kiran Kandi93923902012-06-20 17:00:25 -07004569 return ret;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004570 }
Kiran Kandi93923902012-06-20 17:00:25 -07004571
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304572 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05304573 switch (params_format(params)) {
4574 case SNDRV_PCM_FORMAT_S16_LE:
4575 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004576 TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x20);
Santosh Mardie15e2302011-11-15 10:39:23 +05304577 break;
4578 case SNDRV_PCM_FORMAT_S32_LE:
4579 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004580 TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x00);
Santosh Mardie15e2302011-11-15 10:39:23 +05304581 break;
4582 default:
Kuirong Wang906ac472012-07-09 12:54:44 -07004583 pr_err("%s: Invalid RX format %d\n", __func__,
4584 params_format(params));
Kiran Kandi93923902012-06-20 17:00:25 -07004585 return -EINVAL;
Santosh Mardie15e2302011-11-15 10:39:23 +05304586 }
4587 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_I2S_CTL,
Kiran Kandi93923902012-06-20 17:00:25 -07004588 0x03, (rx_fs_rate_reg_val >> 0x05));
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004589 } else {
Kuirong Wang906ac472012-07-09 12:54:44 -07004590 switch (params_format(params)) {
4591 case SNDRV_PCM_FORMAT_S16_LE:
4592 tabla->dai[dai->id].bit_width = 16;
4593 break;
4594 default:
4595 pr_err("%s: Invalid format %d\n", __func__,
4596 params_format(params));
4597 return -EINVAL;
4598 }
4599 tabla->dai[dai->id].rate = params_rate(params);
Santosh Mardie15e2302011-11-15 10:39:23 +05304600 }
Kiran Kandi93923902012-06-20 17:00:25 -07004601 break;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004602
Kiran Kandi93923902012-06-20 17:00:25 -07004603 default:
4604 pr_err("%s: Invalid stream type %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004605 substream->stream);
Kiran Kandi93923902012-06-20 17:00:25 -07004606 return -EINVAL;
4607 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004608 return 0;
4609}
4610
4611static struct snd_soc_dai_ops tabla_dai_ops = {
4612 .startup = tabla_startup,
Swaminathan Sathappanf95ece62012-08-23 16:01:50 -07004613 .shutdown = tabla_shutdown,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004614 .hw_params = tabla_hw_params,
4615 .set_sysclk = tabla_set_dai_sysclk,
4616 .set_fmt = tabla_set_dai_fmt,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004617 .set_channel_map = tabla_set_channel_map,
4618 .get_channel_map = tabla_get_channel_map,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004619};
4620
4621static struct snd_soc_dai_driver tabla_dai[] = {
4622 {
4623 .name = "tabla_rx1",
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004624 .id = AIF1_PB,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004625 .playback = {
4626 .stream_name = "AIF1 Playback",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004627 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004628 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004629 .rate_max = 192000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004630 .rate_min = 8000,
4631 .channels_min = 1,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004632 .channels_max = 2,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004633 },
4634 .ops = &tabla_dai_ops,
4635 },
4636 {
4637 .name = "tabla_tx1",
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004638 .id = AIF1_CAP,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004639 .capture = {
4640 .stream_name = "AIF1 Capture",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004641 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004642 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004643 .rate_max = 192000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004644 .rate_min = 8000,
4645 .channels_min = 1,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004646 .channels_max = 4,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004647 },
4648 .ops = &tabla_dai_ops,
4649 },
Neema Shettyd3a89262012-02-16 10:23:50 -08004650 {
4651 .name = "tabla_rx2",
4652 .id = AIF2_PB,
4653 .playback = {
4654 .stream_name = "AIF2 Playback",
4655 .rates = WCD9310_RATES,
4656 .formats = TABLA_FORMATS,
4657 .rate_min = 8000,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004658 .rate_max = 192000,
Neema Shettyd3a89262012-02-16 10:23:50 -08004659 .channels_min = 1,
4660 .channels_max = 2,
4661 },
4662 .ops = &tabla_dai_ops,
4663 },
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004664 {
4665 .name = "tabla_tx2",
4666 .id = AIF2_CAP,
4667 .capture = {
4668 .stream_name = "AIF2 Capture",
4669 .rates = WCD9310_RATES,
4670 .formats = TABLA_FORMATS,
4671 .rate_max = 192000,
4672 .rate_min = 8000,
4673 .channels_min = 1,
4674 .channels_max = 4,
4675 },
4676 .ops = &tabla_dai_ops,
4677 },
Neema Shetty3fb1b802012-04-27 13:53:24 -07004678 {
4679 .name = "tabla_tx3",
4680 .id = AIF3_CAP,
4681 .capture = {
4682 .stream_name = "AIF3 Capture",
4683 .rates = WCD9310_RATES,
4684 .formats = TABLA_FORMATS,
4685 .rate_max = 48000,
4686 .rate_min = 8000,
4687 .channels_min = 1,
4688 .channels_max = 2,
4689 },
4690 .ops = &tabla_dai_ops,
4691 },
Kiran Kandia9fffe92012-05-20 23:42:30 -07004692 {
4693 .name = "tabla_rx3",
4694 .id = AIF3_PB,
4695 .playback = {
4696 .stream_name = "AIF3 Playback",
4697 .rates = WCD9310_RATES,
4698 .formats = TABLA_FORMATS,
4699 .rate_min = 8000,
4700 .rate_max = 192000,
4701 .channels_min = 1,
4702 .channels_max = 2,
4703 },
4704 .ops = &tabla_dai_ops,
4705 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004706};
Santosh Mardie15e2302011-11-15 10:39:23 +05304707
4708static struct snd_soc_dai_driver tabla_i2s_dai[] = {
4709 {
4710 .name = "tabla_i2s_rx1",
Kuirong Wang906ac472012-07-09 12:54:44 -07004711 .id = AIF1_PB,
Santosh Mardie15e2302011-11-15 10:39:23 +05304712 .playback = {
4713 .stream_name = "AIF1 Playback",
4714 .rates = WCD9310_RATES,
4715 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004716 .rate_max = 192000,
Santosh Mardie15e2302011-11-15 10:39:23 +05304717 .rate_min = 8000,
4718 .channels_min = 1,
4719 .channels_max = 4,
4720 },
4721 .ops = &tabla_dai_ops,
4722 },
4723 {
4724 .name = "tabla_i2s_tx1",
Kuirong Wang906ac472012-07-09 12:54:44 -07004725 .id = AIF1_CAP,
Santosh Mardie15e2302011-11-15 10:39:23 +05304726 .capture = {
4727 .stream_name = "AIF1 Capture",
4728 .rates = WCD9310_RATES,
4729 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004730 .rate_max = 192000,
Santosh Mardie15e2302011-11-15 10:39:23 +05304731 .rate_min = 8000,
4732 .channels_min = 1,
4733 .channels_max = 4,
4734 },
4735 .ops = &tabla_dai_ops,
4736 },
4737};
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004738
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07004739static int tabla_codec_enable_chmask(struct tabla_priv *tabla_p,
Kuirong Wang906ac472012-07-09 12:54:44 -07004740 int event, int index)
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07004741{
4742 int ret = 0;
Kuirong Wang906ac472012-07-09 12:54:44 -07004743 struct wcd9xxx_ch *ch;
4744
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07004745 switch (event) {
4746 case SND_SOC_DAPM_POST_PMU:
Kuirong Wang906ac472012-07-09 12:54:44 -07004747 list_for_each_entry(ch,
4748 &tabla_p->dai[index].wcd9xxx_ch_list, list) {
4749 ret = wcd9xxx_get_slave_port(ch->ch_num);
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07004750 if (ret < 0) {
4751 pr_err("%s: Invalid slave port ID: %d\n",
4752 __func__, ret);
4753 ret = -EINVAL;
4754 break;
4755 }
4756 tabla_p->dai[index].ch_mask |= 1 << ret;
4757 }
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07004758 break;
4759 case SND_SOC_DAPM_POST_PMD:
4760 ret = wait_event_timeout(tabla_p->dai[index].dai_wait,
4761 (tabla_p->dai[index].ch_mask == 0),
4762 msecs_to_jiffies(SLIM_CLOSE_TIMEOUT));
4763 if (!ret) {
4764 pr_err("%s: Slim close tx/rx wait timeout\n",
4765 __func__);
4766 ret = -EINVAL;
Kuirong Wang906ac472012-07-09 12:54:44 -07004767 }
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07004768 break;
4769 }
4770 return ret;
4771}
4772
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004773static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
Kuirong Wang906ac472012-07-09 12:54:44 -07004774 struct snd_kcontrol *kcontrol,
4775 int event)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004776{
Kuirong Wang906ac472012-07-09 12:54:44 -07004777 struct wcd9xxx *core;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004778 struct snd_soc_codec *codec = w->codec;
4779 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
Kuirong Wang906ac472012-07-09 12:54:44 -07004780 u32 ret = 0;
4781 struct wcd9xxx_codec_dai_data *dai;
4782
4783 core = dev_get_drvdata(codec->dev->parent);
4784
4785 pr_debug("%s: event called! codec name %s num_dai %d\n"
4786 "stream name %s event %d\n",
4787 __func__, w->codec->name, w->codec->num_dai,
4788 w->sname, event);
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07004789
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004790 /* Execute the callback only if interface type is slimbus */
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07004791 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
Kuirong Wang906ac472012-07-09 12:54:44 -07004792 if (event == SND_SOC_DAPM_POST_PMD && (core != NULL) &&
4793 (core->dev != NULL) &&
4794 (core->dev->parent != NULL)) {
4795 pm_runtime_mark_last_busy(core->dev->parent);
4796 pm_runtime_put(core->dev->parent);
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07004797 }
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004798 return 0;
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07004799 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004800 pr_debug("%s: w->name %s w->shift %d event %d\n",
4801 __func__, w->name, w->shift, event);
4802 dai = &tabla_p->dai[w->shift];
Kiran Kandia9fffe92012-05-20 23:42:30 -07004803
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004804 switch (event) {
4805 case SND_SOC_DAPM_POST_PMU:
Kuirong Wang906ac472012-07-09 12:54:44 -07004806 ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMU,
4807 w->shift);
4808 ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
4809 dai->rate, dai->bit_width,
4810 &dai->grph);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004811 break;
4812 case SND_SOC_DAPM_POST_PMD:
Kuirong Wang906ac472012-07-09 12:54:44 -07004813 ret = wcd9xxx_close_slim_sch_rx(core,
4814 &dai->wcd9xxx_ch_list,
4815 dai->grph);
4816 ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMD,
4817 w->shift);
4818 if (ret < 0) {
4819 ret = wcd9xxx_disconnect_port(core,
4820 &dai->wcd9xxx_ch_list,
4821 dai->grph);
4822 pr_info("%s: Disconnect RX port, ret = %d\n",
4823 __func__, ret);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004824 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004825 if ((core != NULL) &&
4826 (core->dev != NULL) &&
4827 (core->dev->parent != NULL)) {
4828 pm_runtime_mark_last_busy(core->dev->parent);
4829 pm_runtime_put(core->dev->parent);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004830 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004831 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004832 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004833
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004834 return ret;
4835}
4836
4837static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
Kuirong Wang906ac472012-07-09 12:54:44 -07004838 struct snd_kcontrol *kcontrol,
4839 int event)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004840{
Kuirong Wang906ac472012-07-09 12:54:44 -07004841 struct wcd9xxx *core;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004842 struct snd_soc_codec *codec = w->codec;
4843 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
Kuirong Wang906ac472012-07-09 12:54:44 -07004844 u32 ret = 0;
4845 struct wcd9xxx_codec_dai_data *dai;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004846
Kuirong Wang906ac472012-07-09 12:54:44 -07004847 core = dev_get_drvdata(codec->dev->parent);
4848
4849 pr_debug("%s: event called! codec name %s num_dai %d\n"
4850 "stream name %s\n", __func__, w->codec->name,
4851 w->codec->num_dai, w->sname);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004852
4853 /* Execute the callback only if interface type is slimbus */
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07004854 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
Kuirong Wang906ac472012-07-09 12:54:44 -07004855 if (event == SND_SOC_DAPM_POST_PMD && (core != NULL) &&
4856 (core->dev != NULL) &&
4857 (core->dev->parent != NULL)) {
4858 pm_runtime_mark_last_busy(core->dev->parent);
4859 pm_runtime_put(core->dev->parent);
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07004860 }
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004861 return 0;
Swaminathan Sathappanb74caaa2012-07-10 17:28:54 -07004862 }
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004863
4864 pr_debug("%s(): %s %d\n", __func__, w->name, event);
4865
Kuirong Wang906ac472012-07-09 12:54:44 -07004866 dai = &tabla_p->dai[w->shift];
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004867 switch (event) {
4868 case SND_SOC_DAPM_POST_PMU:
Kuirong Wang906ac472012-07-09 12:54:44 -07004869 ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMU,
4870 w->shift);
4871 ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
4872 dai->rate,
4873 dai->bit_width,
4874 &dai->grph);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004875 break;
4876 case SND_SOC_DAPM_POST_PMD:
Kuirong Wang906ac472012-07-09 12:54:44 -07004877 ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
4878 dai->grph);
4879 ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMD,
4880 w->shift);
4881 if (ret < 0) {
4882 ret = wcd9xxx_disconnect_port(core,
4883 &dai->wcd9xxx_ch_list,
4884 dai->grph);
4885 pr_info("%s: Disconnect TX port, ret = %d\n",
4886 __func__, ret);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004887 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004888 if ((core != NULL) &&
4889 (core->dev != NULL) &&
4890 (core->dev->parent != NULL)) {
4891 pm_runtime_mark_last_busy(core->dev->parent);
4892 pm_runtime_put(core->dev->parent);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004893 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004894 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004895 }
4896 return ret;
4897}
4898
4899/* Todo: Have seperate dapm widgets for I2S and Slimbus.
4900 * Might Need to have callbacks registered only for slimbus
4901 */
4902static const struct snd_soc_dapm_widget tabla_dapm_widgets[] = {
4903 /*RX stuff */
4904 SND_SOC_DAPM_OUTPUT("EAR"),
4905
Damir Didjusto7c85d712012-08-16 21:22:29 -07004906 SND_SOC_DAPM_PGA_E("EAR PA", SND_SOC_NOPM, 0, 0, NULL,
4907 0, tabla_ear_pa_event, SND_SOC_DAPM_PRE_PMU |
4908 SND_SOC_DAPM_PRE_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004909
Damir Didjusto7c85d712012-08-16 21:22:29 -07004910 SND_SOC_DAPM_MIXER("DAC1", SND_SOC_NOPM, 0, 0, dac1_switch,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004911 ARRAY_SIZE(dac1_switch)),
4912
Kuirong Wang906ac472012-07-09 12:54:44 -07004913 SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM,
4914 AIF1_PB, 0, tabla_codec_enable_slimrx,
4915 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4916 SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM,
4917 AIF2_PB, 0, tabla_codec_enable_slimrx,
4918 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4919 SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM,
4920 AIF3_PB, 0, tabla_codec_enable_slimrx,
4921 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4922
4923 SND_SOC_DAPM_MUX("SLIM RX1 MUX", SND_SOC_NOPM, TABLA_RX1, 0,
4924 &slim_rx_mux[TABLA_RX1]),
4925 SND_SOC_DAPM_MUX("SLIM RX2 MUX", SND_SOC_NOPM, TABLA_RX2, 0,
4926 &slim_rx_mux[TABLA_RX2]),
4927 SND_SOC_DAPM_MUX("SLIM RX3 MUX", SND_SOC_NOPM, TABLA_RX3, 0,
4928 &slim_rx_mux[TABLA_RX3]),
4929 SND_SOC_DAPM_MUX("SLIM RX4 MUX", SND_SOC_NOPM, TABLA_RX4, 0,
4930 &slim_rx_mux[TABLA_RX4]),
4931 SND_SOC_DAPM_MUX("SLIM RX5 MUX", SND_SOC_NOPM, TABLA_RX5, 0,
4932 &slim_rx_mux[TABLA_RX5]),
4933 SND_SOC_DAPM_MUX("SLIM RX6 MUX", SND_SOC_NOPM, TABLA_RX6, 0,
4934 &slim_rx_mux[TABLA_RX6]),
4935 SND_SOC_DAPM_MUX("SLIM RX7 MUX", SND_SOC_NOPM, TABLA_RX7, 0,
4936 &slim_rx_mux[TABLA_RX7]),
4937
4938 SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4939 SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
4940 SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
4941 SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
4942 SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
4943 SND_SOC_DAPM_MIXER("SLIM RX6", SND_SOC_NOPM, 0, 0, NULL, 0),
4944 SND_SOC_DAPM_MIXER("SLIM RX7", SND_SOC_NOPM, 0, 0, NULL, 0),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004945 /* Headphone */
4946 SND_SOC_DAPM_OUTPUT("HEADPHONE"),
4947 SND_SOC_DAPM_PGA_E("HPHL", TABLA_A_RX_HPH_CNP_EN, 5, 0, NULL, 0,
4948 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
4949 SND_SOC_DAPM_POST_PMD),
4950 SND_SOC_DAPM_MIXER("HPHL DAC", TABLA_A_RX_HPH_L_DAC_CTL, 7, 0,
4951 hphl_switch, ARRAY_SIZE(hphl_switch)),
4952
4953 SND_SOC_DAPM_PGA_E("HPHR", TABLA_A_RX_HPH_CNP_EN, 4, 0, NULL, 0,
4954 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
4955 SND_SOC_DAPM_POST_PMD),
4956
4957 SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TABLA_A_RX_HPH_R_DAC_CTL, 7, 0,
4958 tabla_hphr_dac_event,
4959 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4960
4961 /* Speaker */
4962 SND_SOC_DAPM_OUTPUT("LINEOUT1"),
4963 SND_SOC_DAPM_OUTPUT("LINEOUT2"),
4964 SND_SOC_DAPM_OUTPUT("LINEOUT3"),
4965 SND_SOC_DAPM_OUTPUT("LINEOUT4"),
4966 SND_SOC_DAPM_OUTPUT("LINEOUT5"),
4967
4968 SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TABLA_A_RX_LINE_CNP_EN, 0, 0, NULL,
4969 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4970 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4971 SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TABLA_A_RX_LINE_CNP_EN, 1, 0, NULL,
4972 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4973 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4974 SND_SOC_DAPM_PGA_E("LINEOUT3 PA", TABLA_A_RX_LINE_CNP_EN, 2, 0, NULL,
4975 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4976 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4977 SND_SOC_DAPM_PGA_E("LINEOUT4 PA", TABLA_A_RX_LINE_CNP_EN, 3, 0, NULL,
4978 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4979 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4980 SND_SOC_DAPM_PGA_E("LINEOUT5 PA", TABLA_A_RX_LINE_CNP_EN, 4, 0, NULL, 0,
4981 tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4982 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4983
4984 SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TABLA_A_RX_LINE_1_DAC_CTL, 7, 0
4985 , tabla_lineout_dac_event,
4986 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4987 SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TABLA_A_RX_LINE_2_DAC_CTL, 7, 0
4988 , tabla_lineout_dac_event,
4989 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4990 SND_SOC_DAPM_DAC_E("LINEOUT3 DAC", NULL, TABLA_A_RX_LINE_3_DAC_CTL, 7, 0
4991 , tabla_lineout_dac_event,
4992 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4993 SND_SOC_DAPM_SWITCH("LINEOUT3 DAC GROUND", SND_SOC_NOPM, 0, 0,
4994 &lineout3_ground_switch),
4995 SND_SOC_DAPM_DAC_E("LINEOUT4 DAC", NULL, TABLA_A_RX_LINE_4_DAC_CTL, 7, 0
4996 , tabla_lineout_dac_event,
4997 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4998 SND_SOC_DAPM_SWITCH("LINEOUT4 DAC GROUND", SND_SOC_NOPM, 0, 0,
4999 &lineout4_ground_switch),
5000 SND_SOC_DAPM_DAC_E("LINEOUT5 DAC", NULL, TABLA_A_RX_LINE_5_DAC_CTL, 7, 0
5001 , tabla_lineout_dac_event,
5002 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5003
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005004 SND_SOC_DAPM_MIXER_E("RX1 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005005 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5006 SND_SOC_DAPM_POST_PMU),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005007 SND_SOC_DAPM_MIXER_E("RX2 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005008 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5009 SND_SOC_DAPM_POST_PMU),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005010 SND_SOC_DAPM_MIXER_E("RX3 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005011 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5012 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005013 SND_SOC_DAPM_MIXER_E("RX4 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005014 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5015 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005016 SND_SOC_DAPM_MIXER_E("RX5 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 4, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005017 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5018 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005019 SND_SOC_DAPM_MIXER_E("RX6 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005020 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5021 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005022 SND_SOC_DAPM_MIXER_E("RX7 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 6, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07005023 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
5024 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005025
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005026 SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5027 SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5028 SND_SOC_DAPM_MIXER("RX3 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5029
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005030 SND_SOC_DAPM_MUX_E("RX4 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0,
5031 &rx4_dsm_mux, tabla_codec_reset_interpolator,
5032 SND_SOC_DAPM_PRE_PMU),
5033
5034 SND_SOC_DAPM_MUX_E("RX6 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0,
5035 &rx6_dsm_mux, tabla_codec_reset_interpolator,
5036 SND_SOC_DAPM_PRE_PMU),
5037
5038 SND_SOC_DAPM_MIXER("RX1 CHAIN", TABLA_A_CDC_RX1_B6_CTL, 5, 0, NULL, 0),
5039 SND_SOC_DAPM_MIXER("RX2 CHAIN", TABLA_A_CDC_RX2_B6_CTL, 5, 0, NULL, 0),
5040
5041 SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5042 &rx_mix1_inp1_mux),
5043 SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5044 &rx_mix1_inp2_mux),
Kiran Kandia9fffe92012-05-20 23:42:30 -07005045 SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0,
5046 &rx_mix1_inp3_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005047 SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5048 &rx2_mix1_inp1_mux),
5049 SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5050 &rx2_mix1_inp2_mux),
5051 SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5052 &rx3_mix1_inp1_mux),
5053 SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5054 &rx3_mix1_inp2_mux),
5055 SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5056 &rx4_mix1_inp1_mux),
5057 SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5058 &rx4_mix1_inp2_mux),
5059 SND_SOC_DAPM_MUX("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5060 &rx5_mix1_inp1_mux),
5061 SND_SOC_DAPM_MUX("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5062 &rx5_mix1_inp2_mux),
5063 SND_SOC_DAPM_MUX("RX6 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5064 &rx6_mix1_inp1_mux),
5065 SND_SOC_DAPM_MUX("RX6 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5066 &rx6_mix1_inp2_mux),
5067 SND_SOC_DAPM_MUX("RX7 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5068 &rx7_mix1_inp1_mux),
5069 SND_SOC_DAPM_MUX("RX7 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5070 &rx7_mix1_inp2_mux),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08005071 SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0,
5072 &rx1_mix2_inp1_mux),
5073 SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0,
5074 &rx1_mix2_inp2_mux),
5075 SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0,
5076 &rx2_mix2_inp1_mux),
5077 SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0,
5078 &rx2_mix2_inp2_mux),
5079 SND_SOC_DAPM_MUX("RX3 MIX2 INP1", SND_SOC_NOPM, 0, 0,
5080 &rx3_mix2_inp1_mux),
5081 SND_SOC_DAPM_MUX("RX3 MIX2 INP2", SND_SOC_NOPM, 0, 0,
5082 &rx3_mix2_inp2_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005083
5084 SND_SOC_DAPM_SUPPLY("CP", TABLA_A_CP_EN, 0, 0,
5085 tabla_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU |
5086 SND_SOC_DAPM_PRE_PMD),
5087
5088 SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
5089 tabla_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
5090 SND_SOC_DAPM_POST_PMD),
5091
5092 /* TX */
5093
5094 SND_SOC_DAPM_SUPPLY("CDC_CONN", TABLA_A_CDC_CLK_OTHR_CTL, 2, 0, NULL,
5095 0),
5096
5097 SND_SOC_DAPM_SUPPLY("LDO_H", TABLA_A_LDO_H_MODE_1, 7, 0,
5098 tabla_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU),
5099
Kuirong Wang0f8ade32012-02-27 16:29:45 -08005100 SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 0, 0,
5101 tabla_config_compander, SND_SOC_DAPM_PRE_PMU |
5102 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
5103 SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 1, 0,
5104 tabla_config_compander, SND_SOC_DAPM_PRE_PMU |
5105 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
5106
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005107 SND_SOC_DAPM_INPUT("AMIC1"),
5108 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", TABLA_A_MICB_1_CTL, 7, 0,
5109 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5110 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5111 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", TABLA_A_MICB_1_CTL, 7, 0,
5112 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5113 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5114 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", TABLA_A_MICB_1_CTL, 7, 0,
5115 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5116 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5117 SND_SOC_DAPM_ADC_E("ADC1", NULL, TABLA_A_TX_1_2_EN, 7, 0,
5118 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
5119 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5120
5121 SND_SOC_DAPM_INPUT("AMIC3"),
5122 SND_SOC_DAPM_ADC_E("ADC3", NULL, TABLA_A_TX_3_4_EN, 7, 0,
5123 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
5124 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5125
5126 SND_SOC_DAPM_INPUT("AMIC4"),
5127 SND_SOC_DAPM_ADC_E("ADC4", NULL, TABLA_A_TX_3_4_EN, 3, 0,
5128 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
5129 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5130
5131 SND_SOC_DAPM_INPUT("AMIC5"),
5132 SND_SOC_DAPM_ADC_E("ADC5", NULL, TABLA_A_TX_5_6_EN, 7, 0,
5133 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
5134
5135 SND_SOC_DAPM_INPUT("AMIC6"),
5136 SND_SOC_DAPM_ADC_E("ADC6", NULL, TABLA_A_TX_5_6_EN, 3, 0,
5137 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
5138
5139 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 -08005140 &dec1_mux, tabla_codec_enable_dec,
5141 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5142 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005143
5144 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 -08005145 &dec2_mux, tabla_codec_enable_dec,
5146 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5147 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005148
5149 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 -08005150 &dec3_mux, tabla_codec_enable_dec,
5151 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5152 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005153
5154 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 -08005155 &dec4_mux, tabla_codec_enable_dec,
5156 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5157 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005158
5159 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 -08005160 &dec5_mux, tabla_codec_enable_dec,
5161 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5162 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005163
5164 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 -08005165 &dec6_mux, tabla_codec_enable_dec,
5166 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5167 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005168
5169 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 -08005170 &dec7_mux, tabla_codec_enable_dec,
5171 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5172 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005173
5174 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 -08005175 &dec8_mux, tabla_codec_enable_dec,
5176 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5177 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005178
5179 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 -08005180 &dec9_mux, tabla_codec_enable_dec,
5181 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5182 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005183
5184 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 -08005185 &dec10_mux, tabla_codec_enable_dec,
5186 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5187 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005188
5189 SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux),
5190 SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux),
5191
5192 SND_SOC_DAPM_MIXER_E("ANC", SND_SOC_NOPM, 0, 0, NULL, 0,
5193 tabla_codec_enable_anc, SND_SOC_DAPM_PRE_PMU |
5194 SND_SOC_DAPM_POST_PMD),
5195
5196 SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux),
5197
5198 SND_SOC_DAPM_INPUT("AMIC2"),
5199 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", TABLA_A_MICB_2_CTL, 7, 0,
5200 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5201 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5202 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", TABLA_A_MICB_2_CTL, 7, 0,
5203 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5204 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5205 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", TABLA_A_MICB_2_CTL, 7, 0,
5206 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5207 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5208 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", TABLA_A_MICB_2_CTL, 7, 0,
5209 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5210 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5211 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", TABLA_A_MICB_3_CTL, 7, 0,
5212 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5213 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5214 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", TABLA_A_MICB_3_CTL, 7, 0,
5215 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5216 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5217 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", TABLA_A_MICB_3_CTL, 7, 0,
5218 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
5219 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5220 SND_SOC_DAPM_ADC_E("ADC2", NULL, TABLA_A_TX_1_2_EN, 3, 0,
5221 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
5222 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5223
Kuirong Wang906ac472012-07-09 12:54:44 -07005224 SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM,
5225 AIF1_CAP, 0, tabla_codec_enable_slimtx,
5226 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5227
5228 SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM,
5229 AIF2_CAP, 0, tabla_codec_enable_slimtx,
5230 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5231
5232 SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM,
5233 AIF3_CAP, 0, tabla_codec_enable_slimtx,
5234 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5235
5236 SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0,
5237 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
5238
5239 SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0,
5240 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
5241
5242 SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0,
5243 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
5244
5245 SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, TABLA_TX1, 0,
5246 &sb_tx1_mux),
5247 SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, TABLA_TX2, 0,
5248 &sb_tx2_mux),
5249 SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, TABLA_TX3, 0,
5250 &sb_tx3_mux),
5251 SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, TABLA_TX4, 0,
5252 &sb_tx4_mux),
5253 SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, TABLA_TX5, 0,
5254 &sb_tx5_mux),
5255 SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, TABLA_TX6, 0,
5256 &sb_tx6_mux),
5257 SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, TABLA_TX7, 0,
5258 &sb_tx7_mux),
5259 SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, TABLA_TX8, 0,
5260 &sb_tx8_mux),
5261 SND_SOC_DAPM_MUX("SLIM TX9 MUX", SND_SOC_NOPM, TABLA_TX9, 0,
5262 &sb_tx9_mux),
5263 SND_SOC_DAPM_MUX("SLIM TX10 MUX", SND_SOC_NOPM, TABLA_TX10, 0,
5264 &sb_tx10_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005265
5266 /* Digital Mic Inputs */
5267 SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
5268 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5269 SND_SOC_DAPM_POST_PMD),
5270
5271 SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
5272 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5273 SND_SOC_DAPM_POST_PMD),
5274
5275 SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0,
5276 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5277 SND_SOC_DAPM_POST_PMD),
5278
5279 SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0,
5280 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5281 SND_SOC_DAPM_POST_PMD),
5282
5283 SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0,
5284 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5285 SND_SOC_DAPM_POST_PMD),
5286 SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 0,
5287 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5288 SND_SOC_DAPM_POST_PMD),
5289
5290 /* Sidetone */
5291 SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux),
5292 SND_SOC_DAPM_PGA("IIR1", TABLA_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0),
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08005293
5294 /* AUX PGA */
5295 SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TABLA_A_AUX_L_EN, 7, 0,
5296 tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
5297 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
5298 SND_SOC_DAPM_POST_PMD),
5299
5300 SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TABLA_A_AUX_R_EN, 7, 0,
5301 tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
5302 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
5303 SND_SOC_DAPM_POST_PMD),
5304
5305 /* Lineout, ear and HPH PA Mixers */
5306 SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0,
5307 hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)),
5308
5309 SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0,
5310 hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)),
5311
5312 SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0,
5313 lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)),
5314
5315 SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0,
5316 lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)),
5317
5318 SND_SOC_DAPM_MIXER("LINEOUT3_PA_MIXER", SND_SOC_NOPM, 0, 0,
5319 lineout3_pa_mix, ARRAY_SIZE(lineout3_pa_mix)),
5320
5321 SND_SOC_DAPM_MIXER("LINEOUT4_PA_MIXER", SND_SOC_NOPM, 0, 0,
5322 lineout4_pa_mix, ARRAY_SIZE(lineout4_pa_mix)),
5323
5324 SND_SOC_DAPM_MIXER("LINEOUT5_PA_MIXER", SND_SOC_NOPM, 0, 0,
5325 lineout5_pa_mix, ARRAY_SIZE(lineout5_pa_mix)),
5326
5327 SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0,
5328 ear_pa_mix, ARRAY_SIZE(ear_pa_mix)),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08005329};
5330
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005331static short tabla_codec_read_sta_result(struct snd_soc_codec *codec)
Bradley Rubincb1e2732011-06-23 16:49:20 -07005332{
5333 u8 bias_msb, bias_lsb;
5334 short bias_value;
5335
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005336 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B3_STATUS);
5337 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B2_STATUS);
5338 bias_value = (bias_msb << 8) | bias_lsb;
5339 return bias_value;
5340}
5341
5342static short tabla_codec_read_dce_result(struct snd_soc_codec *codec)
5343{
5344 u8 bias_msb, bias_lsb;
5345 short bias_value;
5346
5347 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B5_STATUS);
5348 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B4_STATUS);
5349 bias_value = (bias_msb << 8) | bias_lsb;
5350 return bias_value;
5351}
5352
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005353static void tabla_turn_onoff_rel_detection(struct snd_soc_codec *codec, bool on)
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005354{
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005355 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, on << 1);
5356}
5357
5358static short __tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce,
5359 bool override_bypass, bool noreldetection)
5360{
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005361 short bias_value;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005362 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
5363
Joonwoo Parkf6574c72012-10-10 17:29:57 -07005364 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005365 if (noreldetection)
5366 tabla_turn_onoff_rel_detection(codec, false);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005367
Joonwoo Park925914c2012-01-05 13:35:18 -08005368 /* Turn on the override */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005369 if (!override_bypass)
5370 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x4, 0x4);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005371 if (dce) {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005372 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5373 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
5374 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
Joonwoo Park433149a2012-01-11 09:53:54 -08005375 usleep_range(tabla->mbhc_data.t_sta_dce,
5376 tabla->mbhc_data.t_sta_dce);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005377 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
Joonwoo Park0976d012011-12-22 11:48:18 -08005378 usleep_range(tabla->mbhc_data.t_dce,
5379 tabla->mbhc_data.t_dce);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005380 bias_value = tabla_codec_read_dce_result(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005381 } else {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005382 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005383 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
5384 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
Joonwoo Park433149a2012-01-11 09:53:54 -08005385 usleep_range(tabla->mbhc_data.t_sta_dce,
5386 tabla->mbhc_data.t_sta_dce);
Joonwoo Park0976d012011-12-22 11:48:18 -08005387 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
5388 usleep_range(tabla->mbhc_data.t_sta,
5389 tabla->mbhc_data.t_sta);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005390 bias_value = tabla_codec_read_sta_result(codec);
5391 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5392 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005393 }
Joonwoo Park925914c2012-01-05 13:35:18 -08005394 /* Turn off the override after measuring mic voltage */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005395 if (!override_bypass)
5396 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00);
5397
5398 if (noreldetection)
5399 tabla_turn_onoff_rel_detection(codec, true);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07005400 wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005401
Bradley Rubincb1e2732011-06-23 16:49:20 -07005402 return bias_value;
5403}
5404
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005405static short tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce,
5406 bool norel)
5407{
5408 return __tabla_codec_sta_dce(codec, dce, false, norel);
5409}
5410
5411/* called only from interrupt which is under codec_resource_lock acquisition */
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07005412static short tabla_codec_setup_hs_polling(struct snd_soc_codec *codec)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005413{
5414 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07005415 short bias_value;
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08005416 u8 cfilt_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005417
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005418 pr_debug("%s: enter, mclk_enabled %d\n", __func__, tabla->mclk_enabled);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005419 if (!tabla->mbhc_cfg.calibration) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005420 pr_err("Error, no tabla calibration\n");
Bradley Rubincb1e2732011-06-23 16:49:20 -07005421 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005422 }
5423
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07005424 if (!tabla->mclk_enabled) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07005425 tabla_codec_disable_clock_block(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005426 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_MBHC_MODE);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07005427 tabla_enable_rx_bias(codec, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005428 tabla_codec_enable_clock_block(codec, 1);
5429 }
5430
5431 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x01);
5432
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08005433 /* Make sure CFILT is in fast mode, save current mode */
Joonwoo Parkf4267c22012-01-10 13:25:24 -08005434 cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl);
5435 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x70, 0x00);
Patrick Lai3043fba2011-08-01 14:15:57 -07005436
Joonwoo Parkf4267c22012-01-10 13:25:24 -08005437 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x1F, 0x16);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005438
5439 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005440 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005441
5442 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x80);
5443 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x1F, 0x1C);
5444 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x40, 0x40);
5445
5446 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005447 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5448 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005449
Joonwoo Park925914c2012-01-05 13:35:18 -08005450 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x2, 0x2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005451 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5452
Bradley Rubincb1e2732011-06-23 16:49:20 -07005453 tabla_codec_calibrate_hs_polling(codec);
5454
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005455 /* don't flip override */
5456 bias_value = __tabla_codec_sta_dce(codec, 1, true, true);
Joonwoo Park0976d012011-12-22 11:48:18 -08005457 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40,
5458 cfilt_mode);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005459 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005460
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07005461 return bias_value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005462}
5463
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005464static int tabla_cancel_btn_work(struct tabla_priv *tabla)
5465{
5466 int r = 0;
5467 struct wcd9xxx *core = dev_get_drvdata(tabla->codec->dev->parent);
5468
5469 if (cancel_delayed_work_sync(&tabla->mbhc_btn_dwork)) {
5470 /* if scheduled mbhc_btn_dwork is canceled from here,
5471 * we have to unlock from here instead btn_work */
5472 wcd9xxx_unlock_sleep(core);
5473 r = 1;
5474 }
5475 return r;
5476}
5477
5478/* called under codec_resource_lock acquisition */
5479void tabla_set_and_turnoff_hph_padac(struct snd_soc_codec *codec)
Joonwoo Park03324832012-03-19 19:36:16 -07005480{
5481 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005482 u8 wg_time;
5483
5484 wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ;
5485 wg_time += 1;
Joonwoo Park03324832012-03-19 19:36:16 -07005486
5487 /* If headphone PA is on, check if userspace receives
5488 * removal event to sync-up PA's state */
5489 if (tabla_is_hph_pa_on(codec)) {
5490 pr_debug("%s PA is on, setting PA_OFF_ACK\n", __func__);
5491 set_bit(TABLA_HPHL_PA_OFF_ACK, &tabla->hph_pa_dac_state);
5492 set_bit(TABLA_HPHR_PA_OFF_ACK, &tabla->hph_pa_dac_state);
5493 } else {
5494 pr_debug("%s PA is off\n", __func__);
5495 }
5496
5497 if (tabla_is_hph_dac_on(codec, 1))
5498 set_bit(TABLA_HPHL_DAC_OFF_ACK, &tabla->hph_pa_dac_state);
5499 if (tabla_is_hph_dac_on(codec, 0))
5500 set_bit(TABLA_HPHR_DAC_OFF_ACK, &tabla->hph_pa_dac_state);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005501
5502 snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00);
5503 snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_DAC_CTL,
5504 0xC0, 0x00);
5505 snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_DAC_CTL,
5506 0xC0, 0x00);
5507 usleep_range(wg_time * 1000, wg_time * 1000);
5508}
5509
5510static void tabla_clr_and_turnon_hph_padac(struct tabla_priv *tabla)
5511{
5512 bool pa_turned_on = false;
5513 struct snd_soc_codec *codec = tabla->codec;
5514 u8 wg_time;
5515
5516 wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ;
5517 wg_time += 1;
5518
5519 if (test_and_clear_bit(TABLA_HPHR_DAC_OFF_ACK,
5520 &tabla->hph_pa_dac_state)) {
5521 pr_debug("%s: HPHR clear flag and enable DAC\n", __func__);
5522 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_R_DAC_CTL,
5523 0xC0, 0xC0);
5524 }
5525 if (test_and_clear_bit(TABLA_HPHL_DAC_OFF_ACK,
5526 &tabla->hph_pa_dac_state)) {
5527 pr_debug("%s: HPHL clear flag and enable DAC\n", __func__);
5528 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_L_DAC_CTL,
5529 0xC0, 0xC0);
5530 }
5531
5532 if (test_and_clear_bit(TABLA_HPHR_PA_OFF_ACK,
5533 &tabla->hph_pa_dac_state)) {
5534 pr_debug("%s: HPHR clear flag and enable PA\n", __func__);
5535 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x10,
5536 1 << 4);
5537 pa_turned_on = true;
5538 }
5539 if (test_and_clear_bit(TABLA_HPHL_PA_OFF_ACK,
5540 &tabla->hph_pa_dac_state)) {
5541 pr_debug("%s: HPHL clear flag and enable PA\n", __func__);
5542 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x20,
5543 1 << 5);
5544 pa_turned_on = true;
5545 }
5546
5547 if (pa_turned_on) {
5548 pr_debug("%s: PA was turned off by MBHC and not by DAPM\n",
5549 __func__);
5550 usleep_range(wg_time * 1000, wg_time * 1000);
5551 }
5552}
5553
5554/* called under codec_resource_lock acquisition */
5555static void tabla_codec_report_plug(struct snd_soc_codec *codec, int insertion,
5556 enum snd_jack_types jack_type)
5557{
5558 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07005559 pr_debug("%s: enter insertion %d hph_status %x\n",
5560 __func__, insertion, tabla->hph_status);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005561 if (!insertion) {
5562 /* Report removal */
5563 tabla->hph_status &= ~jack_type;
5564 if (tabla->mbhc_cfg.headset_jack) {
5565 /* cancel possibly scheduled btn work and
5566 * report release if we reported button press */
5567 if (tabla_cancel_btn_work(tabla)) {
5568 pr_debug("%s: button press is canceled\n",
5569 __func__);
5570 } else if (tabla->buttons_pressed) {
5571 pr_debug("%s: Reporting release for reported "
5572 "button press %d\n", __func__,
5573 jack_type);
5574 tabla_snd_soc_jack_report(tabla,
5575 tabla->mbhc_cfg.button_jack, 0,
5576 tabla->buttons_pressed);
5577 tabla->buttons_pressed &=
5578 ~TABLA_JACK_BUTTON_MASK;
5579 }
Joonwoo Park2cc13f02012-05-09 12:44:25 -07005580 pr_debug("%s: Reporting removal %d(%x)\n", __func__,
5581 jack_type, tabla->hph_status);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005582 tabla_snd_soc_jack_report(tabla,
5583 tabla->mbhc_cfg.headset_jack,
5584 tabla->hph_status,
5585 TABLA_JACK_MASK);
5586 }
5587 tabla_set_and_turnoff_hph_padac(codec);
5588 hphocp_off_report(tabla, SND_JACK_OC_HPHR,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07005589 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005590 hphocp_off_report(tabla, SND_JACK_OC_HPHL,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07005591 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005592 tabla->current_plug = PLUG_TYPE_NONE;
5593 tabla->mbhc_polling_active = false;
5594 } else {
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07005595 if (tabla->mbhc_cfg.detect_extn_cable) {
5596 /* Report removal of current jack type */
5597 if (tabla->hph_status != jack_type &&
5598 tabla->mbhc_cfg.headset_jack) {
5599 pr_debug("%s: Reporting removal (%x)\n",
5600 __func__, tabla->hph_status);
5601 tabla_snd_soc_jack_report(tabla,
5602 tabla->mbhc_cfg.headset_jack,
5603 0, TABLA_JACK_MASK);
5604 tabla->hph_status = 0;
5605 }
5606 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005607 /* Report insertion */
5608 tabla->hph_status |= jack_type;
5609
5610 if (jack_type == SND_JACK_HEADPHONE)
5611 tabla->current_plug = PLUG_TYPE_HEADPHONE;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07005612 else if (jack_type == SND_JACK_UNSUPPORTED)
5613 tabla->current_plug = PLUG_TYPE_GND_MIC_SWAP;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005614 else if (jack_type == SND_JACK_HEADSET) {
5615 tabla->mbhc_polling_active = true;
5616 tabla->current_plug = PLUG_TYPE_HEADSET;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07005617 } else if (jack_type == SND_JACK_LINEOUT)
5618 tabla->current_plug = PLUG_TYPE_HIGH_HPH;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005619 if (tabla->mbhc_cfg.headset_jack) {
Joonwoo Park2cc13f02012-05-09 12:44:25 -07005620 pr_debug("%s: Reporting insertion %d(%x)\n", __func__,
5621 jack_type, tabla->hph_status);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005622 tabla_snd_soc_jack_report(tabla,
5623 tabla->mbhc_cfg.headset_jack,
5624 tabla->hph_status,
5625 TABLA_JACK_MASK);
5626 }
5627 tabla_clr_and_turnon_hph_padac(tabla);
5628 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07005629 pr_debug("%s: leave hph_status %x\n", __func__, tabla->hph_status);
Joonwoo Park03324832012-03-19 19:36:16 -07005630}
5631
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005632static int tabla_codec_enable_hs_detect(struct snd_soc_codec *codec,
Joonwoo Park03324832012-03-19 19:36:16 -07005633 int insertion, int trigger,
5634 bool padac_off)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005635{
5636 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005637 int central_bias_enabled = 0;
Joonwoo Park0976d012011-12-22 11:48:18 -08005638 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005639 TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08005640 const struct tabla_mbhc_plug_detect_cfg *plug_det =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005641 TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005642
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07005643 pr_debug("%s: enter insertion(%d) trigger(0x%x)\n",
5644 __func__, insertion, trigger);
5645
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005646 if (!tabla->mbhc_cfg.calibration) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005647 pr_err("Error, no tabla calibration\n");
5648 return -EINVAL;
5649 }
5650
5651 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0);
5652
Joonwoo Park03324832012-03-19 19:36:16 -07005653 /* Make sure mic bias and Mic line schmitt trigger
5654 * are turned OFF
5655 */
5656 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01);
5657 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
5658
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005659 if (insertion) {
Bhalchandra Gajareafc86432012-08-23 13:44:07 -07005660 pr_debug("%s: setup for insertion\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07005661 tabla_codec_switch_micbias(codec, 0);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005662
Joonwoo Park03324832012-03-19 19:36:16 -07005663 /* DAPM can manipulate PA/DAC bits concurrently */
5664 if (padac_off == true) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005665 tabla_set_and_turnoff_hph_padac(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07005666 }
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005667
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005668 if (trigger & MBHC_USE_HPHL_TRIGGER) {
Joonwoo Park03324832012-03-19 19:36:16 -07005669 /* Enable HPH Schmitt Trigger */
5670 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x11,
5671 0x11);
5672 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x0C,
5673 plug_det->hph_current << 2);
5674 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x02,
5675 0x02);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005676 }
5677 if (trigger & MBHC_USE_MB_TRIGGER) {
Joonwoo Park03324832012-03-19 19:36:16 -07005678 /* enable the mic line schmitt trigger */
5679 snd_soc_update_bits(codec,
5680 tabla->mbhc_bias_regs.mbhc_reg,
5681 0x60, plug_det->mic_current << 5);
5682 snd_soc_update_bits(codec,
5683 tabla->mbhc_bias_regs.mbhc_reg,
5684 0x80, 0x80);
5685 usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid);
5686 snd_soc_update_bits(codec,
5687 tabla->mbhc_bias_regs.ctl_reg, 0x01,
5688 0x00);
5689 snd_soc_update_bits(codec,
5690 tabla->mbhc_bias_regs.mbhc_reg,
5691 0x10, 0x10);
5692 }
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005693
5694 /* setup for insetion detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005695 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005696 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07005697 pr_debug("setup for removal detection\n");
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005698 /* Make sure the HPH schmitt trigger is OFF */
5699 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x12, 0x00);
5700
5701 /* enable the mic line schmitt trigger */
Joonwoo Park03324832012-03-19 19:36:16 -07005702 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg,
5703 0x01, 0x00);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005704 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x60,
Joonwoo Park0976d012011-12-22 11:48:18 -08005705 plug_det->mic_current << 5);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005706 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
5707 0x80, 0x80);
Joonwoo Park0976d012011-12-22 11:48:18 -08005708 usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005709 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
5710 0x10, 0x10);
5711
5712 /* Setup for low power removal detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005713 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0x2);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005714 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005715
5716 if (snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x4) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005717 /* called called by interrupt */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005718 if (!(tabla->clock_active)) {
5719 tabla_codec_enable_config_mode(codec, 1);
5720 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07005721 0x06, 0);
Joonwoo Park0976d012011-12-22 11:48:18 -08005722 usleep_range(generic->t_shutdown_plug_rem,
5723 generic->t_shutdown_plug_rem);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005724 tabla_codec_enable_config_mode(codec, 0);
5725 } else
5726 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07005727 0x06, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005728 }
5729
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07005730 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.int_rbias, 0x80, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005731
5732 /* If central bandgap disabled */
5733 if (!(snd_soc_read(codec, TABLA_A_PIN_CTL_OE1) & 1)) {
5734 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x3, 0x3);
Joonwoo Park0976d012011-12-22 11:48:18 -08005735 usleep_range(generic->t_bg_fast_settle,
5736 generic->t_bg_fast_settle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005737 central_bias_enabled = 1;
5738 }
5739
5740 /* If LDO_H disabled */
5741 if (snd_soc_read(codec, TABLA_A_PIN_CTL_OE0) & 0x80) {
5742 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x10, 0);
5743 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0x80);
Joonwoo Park0976d012011-12-22 11:48:18 -08005744 usleep_range(generic->t_ldoh, generic->t_ldoh);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005745 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0);
5746
5747 if (central_bias_enabled)
5748 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x1, 0);
5749 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005750
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08005751 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x3,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005752 tabla->mbhc_cfg.micbias);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005753
Joonwoo Parkf6574c72012-10-10 17:29:57 -07005754 wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005755 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0x1);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07005756 pr_debug("%s: leave\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005757 return 0;
5758}
5759
Joonwoo Park0976d012011-12-22 11:48:18 -08005760static u16 tabla_codec_v_sta_dce(struct snd_soc_codec *codec, bool dce,
5761 s16 vin_mv)
5762{
Joonwoo Park0976d012011-12-22 11:48:18 -08005763 struct tabla_priv *tabla;
Joonwoo Park03324832012-03-19 19:36:16 -07005764 s16 diff, zero;
Joonwoo Park0976d012011-12-22 11:48:18 -08005765 u32 mb_mv, in;
Joonwoo Park03324832012-03-19 19:36:16 -07005766 u16 value;
Joonwoo Park0976d012011-12-22 11:48:18 -08005767
5768 tabla = snd_soc_codec_get_drvdata(codec);
5769 mb_mv = tabla->mbhc_data.micb_mv;
5770
5771 if (mb_mv == 0) {
5772 pr_err("%s: Mic Bias voltage is set to zero\n", __func__);
5773 return -EINVAL;
5774 }
5775
5776 if (dce) {
Joonwoo Park03324832012-03-19 19:36:16 -07005777 diff = (tabla->mbhc_data.dce_mb) - (tabla->mbhc_data.dce_z);
5778 zero = (tabla->mbhc_data.dce_z);
Joonwoo Park0976d012011-12-22 11:48:18 -08005779 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07005780 diff = (tabla->mbhc_data.sta_mb) - (tabla->mbhc_data.sta_z);
5781 zero = (tabla->mbhc_data.sta_z);
Joonwoo Park0976d012011-12-22 11:48:18 -08005782 }
5783 in = (u32) diff * vin_mv;
5784
Joonwoo Park03324832012-03-19 19:36:16 -07005785 value = (u16) (in / mb_mv) + zero;
5786 return value;
Joonwoo Park0976d012011-12-22 11:48:18 -08005787}
5788
5789static s32 tabla_codec_sta_dce_v(struct snd_soc_codec *codec, s8 dce,
5790 u16 bias_value)
5791{
5792 struct tabla_priv *tabla;
Joonwoo Park03324832012-03-19 19:36:16 -07005793 s16 value, z, mb;
Joonwoo Park0976d012011-12-22 11:48:18 -08005794 s32 mv;
5795
5796 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07005797 value = bias_value;
Joonwoo Park0976d012011-12-22 11:48:18 -08005798 if (dce) {
Joonwoo Park03324832012-03-19 19:36:16 -07005799 z = (tabla->mbhc_data.dce_z);
5800 mb = (tabla->mbhc_data.dce_mb);
5801 mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z);
Joonwoo Park0976d012011-12-22 11:48:18 -08005802 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07005803 z = (tabla->mbhc_data.sta_z);
5804 mb = (tabla->mbhc_data.sta_mb);
5805 mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z);
Joonwoo Park0976d012011-12-22 11:48:18 -08005806 }
5807
5808 return mv;
5809}
5810
Joonwoo Park03324832012-03-19 19:36:16 -07005811static void btn_lpress_fn(struct work_struct *work)
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005812{
5813 struct delayed_work *delayed_work;
5814 struct tabla_priv *tabla;
Joonwoo Park0976d012011-12-22 11:48:18 -08005815 short bias_value;
5816 int dce_mv, sta_mv;
Joonwoo Park03324832012-03-19 19:36:16 -07005817 struct wcd9xxx *core;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005818
5819 pr_debug("%s:\n", __func__);
5820
5821 delayed_work = to_delayed_work(work);
Joonwoo Park03324832012-03-19 19:36:16 -07005822 tabla = container_of(delayed_work, struct tabla_priv, mbhc_btn_dwork);
Joonwoo Park816b8e62012-01-23 16:03:21 -08005823 core = dev_get_drvdata(tabla->codec->dev->parent);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005824
5825 if (tabla) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005826 if (tabla->mbhc_cfg.button_jack) {
Joonwoo Park0976d012011-12-22 11:48:18 -08005827 bias_value = tabla_codec_read_sta_result(tabla->codec);
5828 sta_mv = tabla_codec_sta_dce_v(tabla->codec, 0,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305829 bias_value);
Joonwoo Park0976d012011-12-22 11:48:18 -08005830 bias_value = tabla_codec_read_dce_result(tabla->codec);
5831 dce_mv = tabla_codec_sta_dce_v(tabla->codec, 1,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305832 bias_value);
Joonwoo Park0976d012011-12-22 11:48:18 -08005833 pr_debug("%s: Reporting long button press event"
5834 " STA: %d, DCE: %d\n", __func__,
5835 sta_mv, dce_mv);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005836 tabla_snd_soc_jack_report(tabla,
5837 tabla->mbhc_cfg.button_jack,
Joonwoo Park03324832012-03-19 19:36:16 -07005838 tabla->buttons_pressed,
5839 tabla->buttons_pressed);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005840 }
5841 } else {
5842 pr_err("%s: Bad tabla private data\n", __func__);
5843 }
5844
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005845 pr_debug("%s: leave\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07005846 wcd9xxx_unlock_sleep(core);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005847}
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07005848
Joonwoo Parke067b232012-06-14 13:11:30 -07005849static u16 tabla_get_cfilt_reg(struct snd_soc_codec *codec, u8 cfilt)
5850{
5851 u16 reg;
5852
5853 switch (cfilt) {
5854 case TABLA_CFILT1_SEL:
5855 reg = TABLA_A_MICB_CFILT_1_CTL;
5856 break;
5857 case TABLA_CFILT2_SEL:
5858 reg = TABLA_A_MICB_CFILT_2_CTL;
5859 break;
5860 case TABLA_CFILT3_SEL:
5861 reg = TABLA_A_MICB_CFILT_3_CTL;
5862 break;
5863 default:
5864 BUG();
5865 }
5866 return reg;
5867}
5868
Joonwoo Park0976d012011-12-22 11:48:18 -08005869void tabla_mbhc_cal(struct snd_soc_codec *codec)
5870{
5871 struct tabla_priv *tabla;
5872 struct tabla_mbhc_btn_detect_cfg *btn_det;
Joonwoo Parke067b232012-06-14 13:11:30 -07005873 u8 cfilt_mode, micbias2_cfilt_mode, bg_mode;
Joonwoo Park0976d012011-12-22 11:48:18 -08005874 u8 ncic, nmeas, navg;
5875 u32 mclk_rate;
5876 u32 dce_wait, sta_wait;
5877 u8 *n_cic;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005878 void *calibration;
Joonwoo Parke067b232012-06-14 13:11:30 -07005879 u16 bias2_ctl;
Joonwoo Park0976d012011-12-22 11:48:18 -08005880
5881 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005882 calibration = tabla->mbhc_cfg.calibration;
5883
Joonwoo Parkf6574c72012-10-10 17:29:57 -07005884 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005885 tabla_turn_onoff_rel_detection(codec, false);
Joonwoo Park0976d012011-12-22 11:48:18 -08005886
5887 /* First compute the DCE / STA wait times
5888 * depending on tunable parameters.
5889 * The value is computed in microseconds
5890 */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005891 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08005892 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
Joonwoo Park107edf02012-01-11 11:42:24 -08005893 ncic = n_cic[tabla_codec_mclk_index(tabla)];
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005894 nmeas = TABLA_MBHC_CAL_BTN_DET_PTR(calibration)->n_meas;
5895 navg = TABLA_MBHC_CAL_GENERAL_PTR(calibration)->mbhc_navg;
5896 mclk_rate = tabla->mbhc_cfg.mclk_rate;
Joonwoo Park433149a2012-01-11 09:53:54 -08005897 dce_wait = (1000 * 512 * ncic * (nmeas + 1)) / (mclk_rate / 1000);
5898 sta_wait = (1000 * 128 * (navg + 1)) / (mclk_rate / 1000);
Joonwoo Park0976d012011-12-22 11:48:18 -08005899
5900 tabla->mbhc_data.t_dce = dce_wait;
5901 tabla->mbhc_data.t_sta = sta_wait;
5902
5903 /* LDOH and CFILT are already configured during pdata handling.
5904 * Only need to make sure CFILT and bandgap are in Fast mode.
5905 * Need to restore defaults once calculation is done.
5906 */
5907 cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl);
Joonwoo Parke067b232012-06-14 13:11:30 -07005908 micbias2_cfilt_mode =
5909 snd_soc_read(codec, tabla_get_cfilt_reg(codec,
5910 tabla->pdata->micbias.bias2_cfilt_sel));
5911 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40,
5912 TABLA_CFILT_FAST_MODE);
5913 snd_soc_update_bits(codec,
5914 tabla_get_cfilt_reg(codec,
5915 tabla->pdata->micbias.bias2_cfilt_sel),
5916 0x40, TABLA_CFILT_FAST_MODE);
5917
Joonwoo Park0976d012011-12-22 11:48:18 -08005918 bg_mode = snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02,
5919 0x02);
5920
5921 /* Micbias, CFILT, LDOH, MBHC MUX mode settings
5922 * to perform ADC calibration
5923 */
5924 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x60,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005925 tabla->mbhc_cfg.micbias << 5);
Joonwoo Park0976d012011-12-22 11:48:18 -08005926 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
5927 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x60, 0x60);
5928 snd_soc_write(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x78);
5929 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x04);
5930
Joonwoo Parke067b232012-06-14 13:11:30 -07005931 /* MICBIAS2 routing for calibration */
5932 bias2_ctl = snd_soc_read(codec, TABLA_A_MICB_2_CTL);
5933 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, TABLA_MICBIAS2);
5934 snd_soc_write(codec, TABLA_A_MICB_2_CTL,
5935 snd_soc_read(codec, tabla->mbhc_bias_regs.ctl_reg));
5936
Joonwoo Park0976d012011-12-22 11:48:18 -08005937 /* DCE measurement for 0 volts */
5938 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
5939 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
5940 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
Joonwoo Park0976d012011-12-22 11:48:18 -08005941 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81);
5942 usleep_range(100, 100);
5943 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
5944 usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce);
5945 tabla->mbhc_data.dce_z = tabla_codec_read_dce_result(codec);
5946
5947 /* DCE measurment for MB voltage */
5948 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
5949 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
5950 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82);
5951 usleep_range(100, 100);
5952 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
5953 usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce);
5954 tabla->mbhc_data.dce_mb = tabla_codec_read_dce_result(codec);
5955
5956 /* Sta measuremnt for 0 volts */
5957 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
5958 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
5959 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
Joonwoo Park0976d012011-12-22 11:48:18 -08005960 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81);
5961 usleep_range(100, 100);
5962 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
5963 usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta);
5964 tabla->mbhc_data.sta_z = tabla_codec_read_sta_result(codec);
5965
5966 /* STA Measurement for MB Voltage */
5967 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82);
5968 usleep_range(100, 100);
5969 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
5970 usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta);
5971 tabla->mbhc_data.sta_mb = tabla_codec_read_sta_result(codec);
5972
5973 /* Restore default settings. */
Joonwoo Parke067b232012-06-14 13:11:30 -07005974 snd_soc_write(codec, TABLA_A_MICB_2_CTL, bias2_ctl);
5975 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03,
5976 tabla->mbhc_cfg.micbias);
5977
Joonwoo Park0976d012011-12-22 11:48:18 -08005978 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00);
Joonwoo Parke067b232012-06-14 13:11:30 -07005979 snd_soc_update_bits(codec,
5980 tabla_get_cfilt_reg(codec,
5981 tabla->pdata->micbias.bias2_cfilt_sel), 0x40,
5982 micbias2_cfilt_mode);
Joonwoo Park0976d012011-12-22 11:48:18 -08005983 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40,
5984 cfilt_mode);
5985 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, bg_mode);
5986
5987 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
5988 usleep_range(100, 100);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005989
Joonwoo Parkf6574c72012-10-10 17:29:57 -07005990 wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005991 tabla_turn_onoff_rel_detection(codec, true);
Joonwoo Park0976d012011-12-22 11:48:18 -08005992}
5993
5994void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg* btn_det,
5995 const enum tabla_mbhc_btn_det_mem mem)
5996{
5997 void *ret = &btn_det->_v_btn_low;
5998
5999 switch (mem) {
6000 case TABLA_BTN_DET_GAIN:
6001 ret += sizeof(btn_det->_n_cic);
6002 case TABLA_BTN_DET_N_CIC:
6003 ret += sizeof(btn_det->_n_ready);
Joonwoo Parkc0672392012-01-11 11:03:14 -08006004 case TABLA_BTN_DET_N_READY:
Joonwoo Park0976d012011-12-22 11:48:18 -08006005 ret += sizeof(btn_det->_v_btn_high[0]) * btn_det->num_btn;
6006 case TABLA_BTN_DET_V_BTN_HIGH:
6007 ret += sizeof(btn_det->_v_btn_low[0]) * btn_det->num_btn;
6008 case TABLA_BTN_DET_V_BTN_LOW:
6009 /* do nothing */
6010 break;
6011 default:
6012 ret = NULL;
6013 }
6014
6015 return ret;
6016}
6017
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006018static s16 tabla_scale_v_micb_vddio(struct tabla_priv *tabla, int v,
6019 bool tovddio)
6020{
6021 int r;
6022 int vddio_k, mb_k;
6023 vddio_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v,
6024 VDDIO_MICBIAS_MV);
6025 mb_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v,
6026 tabla->mbhc_data.micb_mv);
6027 if (tovddio)
6028 r = v * vddio_k / mb_k;
6029 else
6030 r = v * mb_k / vddio_k;
6031 return r;
6032}
6033
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006034static void tabla_mbhc_calc_rel_thres(struct snd_soc_codec *codec, s16 mv)
6035{
6036 s16 deltamv;
6037 struct tabla_priv *tabla;
6038 struct tabla_mbhc_btn_detect_cfg *btn_det;
6039
6040 tabla = snd_soc_codec_get_drvdata(codec);
6041 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
6042
6043 tabla->mbhc_data.v_b1_h =
6044 tabla_codec_v_sta_dce(codec, DCE,
6045 mv + btn_det->v_btn_press_delta_cic);
6046
6047 tabla->mbhc_data.v_brh = tabla->mbhc_data.v_b1_h;
6048
6049 tabla->mbhc_data.v_brl = TABLA_MBHC_BUTTON_MIN;
6050
6051 deltamv = mv + btn_det->v_btn_press_delta_sta;
6052 tabla->mbhc_data.v_b1_hu = tabla_codec_v_sta_dce(codec, STA, deltamv);
6053
6054 deltamv = mv + btn_det->v_btn_press_delta_cic;
6055 tabla->mbhc_data.v_b1_huc = tabla_codec_v_sta_dce(codec, DCE, deltamv);
6056}
6057
6058static void tabla_mbhc_set_rel_thres(struct snd_soc_codec *codec, s16 mv)
6059{
6060 tabla_mbhc_calc_rel_thres(codec, mv);
6061 tabla_codec_calibrate_rel(codec);
6062}
6063
6064static s16 tabla_mbhc_highest_btn_mv(struct snd_soc_codec *codec)
6065{
6066 struct tabla_priv *tabla;
6067 struct tabla_mbhc_btn_detect_cfg *btn_det;
6068 u16 *btn_high;
6069
6070 tabla = snd_soc_codec_get_drvdata(codec);
6071 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
6072 btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_HIGH);
6073
6074 return btn_high[btn_det->num_btn - 1];
6075}
6076
Joonwoo Park0976d012011-12-22 11:48:18 -08006077static void tabla_mbhc_calc_thres(struct snd_soc_codec *codec)
6078{
6079 struct tabla_priv *tabla;
Joonwoo Park0976d012011-12-22 11:48:18 -08006080 struct tabla_mbhc_btn_detect_cfg *btn_det;
6081 struct tabla_mbhc_plug_type_cfg *plug_type;
Joonwoo Parkc0672392012-01-11 11:03:14 -08006082 u8 *n_ready;
Joonwoo Park0976d012011-12-22 11:48:18 -08006083
6084 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006085 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
6086 plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08006087
Joonwoo Parkc0672392012-01-11 11:03:14 -08006088 n_ready = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_READY);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006089 if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) {
Joonwoo Park03324832012-03-19 19:36:16 -07006090 tabla->mbhc_data.npoll = 4;
Joonwoo Park0976d012011-12-22 11:48:18 -08006091 tabla->mbhc_data.nbounce_wait = 30;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006092 } else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) {
Joonwoo Park0976d012011-12-22 11:48:18 -08006093 tabla->mbhc_data.npoll = 7;
6094 tabla->mbhc_data.nbounce_wait = 23;
Joonwoo Parkc0672392012-01-11 11:03:14 -08006095 }
Joonwoo Park0976d012011-12-22 11:48:18 -08006096
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006097 tabla->mbhc_data.t_sta_dce = ((1000 * 256) /
6098 (tabla->mbhc_cfg.mclk_rate / 1000) *
Joonwoo Parkc0672392012-01-11 11:03:14 -08006099 n_ready[tabla_codec_mclk_index(tabla)]) +
6100 10;
Joonwoo Park0976d012011-12-22 11:48:18 -08006101 tabla->mbhc_data.v_ins_hu =
6102 tabla_codec_v_sta_dce(codec, STA, plug_type->v_hs_max);
6103 tabla->mbhc_data.v_ins_h =
6104 tabla_codec_v_sta_dce(codec, DCE, plug_type->v_hs_max);
6105
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006106 tabla->mbhc_data.v_inval_ins_low = TABLA_MBHC_FAKE_INSERT_LOW;
6107 if (tabla->mbhc_cfg.gpio)
6108 tabla->mbhc_data.v_inval_ins_high =
6109 TABLA_MBHC_FAKE_INSERT_HIGH;
6110 else
6111 tabla->mbhc_data.v_inval_ins_high =
6112 TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO;
6113
6114 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
6115 tabla->mbhc_data.adj_v_hs_max =
6116 tabla_scale_v_micb_vddio(tabla, plug_type->v_hs_max, true);
6117 tabla->mbhc_data.adj_v_ins_hu =
6118 tabla_codec_v_sta_dce(codec, STA,
6119 tabla->mbhc_data.adj_v_hs_max);
6120 tabla->mbhc_data.adj_v_ins_h =
6121 tabla_codec_v_sta_dce(codec, DCE,
6122 tabla->mbhc_data.adj_v_hs_max);
6123 tabla->mbhc_data.v_inval_ins_low =
6124 tabla_scale_v_micb_vddio(tabla,
6125 tabla->mbhc_data.v_inval_ins_low,
6126 false);
6127 tabla->mbhc_data.v_inval_ins_high =
6128 tabla_scale_v_micb_vddio(tabla,
6129 tabla->mbhc_data.v_inval_ins_high,
6130 false);
6131 }
6132
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006133 tabla_mbhc_calc_rel_thres(codec, tabla_mbhc_highest_btn_mv(codec));
Joonwoo Park0976d012011-12-22 11:48:18 -08006134
6135 tabla->mbhc_data.v_no_mic =
6136 tabla_codec_v_sta_dce(codec, STA, plug_type->v_no_mic);
6137}
6138
6139void tabla_mbhc_init(struct snd_soc_codec *codec)
6140{
6141 struct tabla_priv *tabla;
6142 struct tabla_mbhc_general_cfg *generic;
6143 struct tabla_mbhc_btn_detect_cfg *btn_det;
6144 int n;
Joonwoo Park0976d012011-12-22 11:48:18 -08006145 u8 *n_cic, *gain;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306146 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Joonwoo Park0976d012011-12-22 11:48:18 -08006147
6148 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006149 generic = TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
6150 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08006151
Joonwoo Park0976d012011-12-22 11:48:18 -08006152 for (n = 0; n < 8; n++) {
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08006153 if ((!TABLA_IS_1_X(tabla_core->version)) || n != 7) {
Joonwoo Park0976d012011-12-22 11:48:18 -08006154 snd_soc_update_bits(codec,
6155 TABLA_A_CDC_MBHC_FEATURE_B1_CFG,
6156 0x07, n);
6157 snd_soc_write(codec, TABLA_A_CDC_MBHC_FEATURE_B2_CFG,
6158 btn_det->c[n]);
6159 }
6160 }
6161 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x07,
6162 btn_det->nc);
6163
6164 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
6165 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL, 0xFF,
Joonwoo Park107edf02012-01-11 11:42:24 -08006166 n_cic[tabla_codec_mclk_index(tabla)]);
Joonwoo Park0976d012011-12-22 11:48:18 -08006167
6168 gain = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_GAIN);
Joonwoo Park107edf02012-01-11 11:42:24 -08006169 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x78,
6170 gain[tabla_codec_mclk_index(tabla)] << 3);
Joonwoo Park0976d012011-12-22 11:48:18 -08006171
6172 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x70,
6173 generic->mbhc_nsa << 4);
6174
6175 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x0F,
6176 btn_det->n_meas);
6177
6178 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B5_CTL, generic->mbhc_navg);
6179
6180 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x80, 0x80);
6181
6182 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x78,
6183 btn_det->mbhc_nsc << 3);
6184
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08006185 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x03,
6186 TABLA_MICBIAS2);
Joonwoo Park0976d012011-12-22 11:48:18 -08006187
6188 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, 0x02);
Joonwoo Park03324832012-03-19 19:36:16 -07006189
6190 snd_soc_update_bits(codec, TABLA_A_MBHC_SCALING_MUX_2, 0xF0, 0xF0);
Joonwoo Parke067b232012-06-14 13:11:30 -07006191
6192 /* override mbhc's micbias */
6193 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03,
6194 tabla->mbhc_cfg.micbias);
Joonwoo Park0976d012011-12-22 11:48:18 -08006195}
6196
Patrick Lai64b43262011-12-06 17:29:15 -08006197static bool tabla_mbhc_fw_validate(const struct firmware *fw)
6198{
6199 u32 cfg_offset;
6200 struct tabla_mbhc_imped_detect_cfg *imped_cfg;
6201 struct tabla_mbhc_btn_detect_cfg *btn_cfg;
6202
6203 if (fw->size < TABLA_MBHC_CAL_MIN_SIZE)
6204 return false;
6205
6206 /* previous check guarantees that there is enough fw data up
6207 * to num_btn
6208 */
6209 btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(fw->data);
6210 cfg_offset = (u32) ((void *) btn_cfg - (void *) fw->data);
6211 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_BTN_SZ(btn_cfg)))
6212 return false;
6213
6214 /* previous check guarantees that there is enough fw data up
6215 * to start of impedance detection configuration
6216 */
6217 imped_cfg = TABLA_MBHC_CAL_IMPED_DET_PTR(fw->data);
6218 cfg_offset = (u32) ((void *) imped_cfg - (void *) fw->data);
6219
6220 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_MIN_SZ))
6221 return false;
6222
6223 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_SZ(imped_cfg)))
6224 return false;
6225
6226 return true;
6227}
Joonwoo Park03324832012-03-19 19:36:16 -07006228
Joonwoo Parkfee17432012-04-16 16:33:55 -07006229/* called under codec_resource_lock acquisition */
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006230static int tabla_determine_button(const struct tabla_priv *priv,
Joonwoo Parkfee17432012-04-16 16:33:55 -07006231 const s32 micmv)
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006232{
6233 s16 *v_btn_low, *v_btn_high;
6234 struct tabla_mbhc_btn_detect_cfg *btn_det;
6235 int i, btn = -1;
6236
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006237 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006238 v_btn_low = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_LOW);
6239 v_btn_high = tabla_mbhc_cal_btn_det_mp(btn_det,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306240 TABLA_BTN_DET_V_BTN_HIGH);
Joonwoo Parkfee17432012-04-16 16:33:55 -07006241
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006242 for (i = 0; i < btn_det->num_btn; i++) {
Joonwoo Parkfee17432012-04-16 16:33:55 -07006243 if ((v_btn_low[i] <= micmv) && (v_btn_high[i] >= micmv)) {
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006244 btn = i;
6245 break;
6246 }
6247 }
6248
6249 if (btn == -1)
6250 pr_debug("%s: couldn't find button number for mic mv %d\n",
Joonwoo Parkfee17432012-04-16 16:33:55 -07006251 __func__, micmv);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006252
6253 return btn;
6254}
6255
6256static int tabla_get_button_mask(const int btn)
6257{
6258 int mask = 0;
6259 switch (btn) {
6260 case 0:
6261 mask = SND_JACK_BTN_0;
6262 break;
6263 case 1:
6264 mask = SND_JACK_BTN_1;
6265 break;
6266 case 2:
6267 mask = SND_JACK_BTN_2;
6268 break;
6269 case 3:
6270 mask = SND_JACK_BTN_3;
6271 break;
6272 case 4:
6273 mask = SND_JACK_BTN_4;
6274 break;
6275 case 5:
6276 mask = SND_JACK_BTN_5;
6277 break;
6278 case 6:
6279 mask = SND_JACK_BTN_6;
6280 break;
6281 case 7:
6282 mask = SND_JACK_BTN_7;
6283 break;
6284 }
6285 return mask;
6286}
6287
Bradley Rubincb1e2732011-06-23 16:49:20 -07006288static irqreturn_t tabla_dce_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006289{
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006290 int i, mask;
Joonwoo Parkfee17432012-04-16 16:33:55 -07006291 short dce, sta;
Joonwoo Park12334832012-07-23 19:27:52 -07006292 s32 mv, mv_s, stamv, stamv_s;
Joonwoo Parkfee17432012-04-16 16:33:55 -07006293 bool vddio;
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006294 u16 *btn_high;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006295 int btn = -1, meas = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006296 struct tabla_priv *priv = data;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006297 const struct tabla_mbhc_btn_detect_cfg *d =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006298 TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006299 short btnmeas[d->n_btn_meas + 1];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006300 struct snd_soc_codec *codec = priv->codec;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306301 struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent);
Joonwoo Park03324832012-03-19 19:36:16 -07006302 int n_btn_meas = d->n_btn_meas;
6303 u8 mbhc_status = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_STATUS) & 0x3E;
Bradley Rubincb1e2732011-06-23 16:49:20 -07006304
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006305 pr_debug("%s: enter\n", __func__);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006306
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006307 btn_high = tabla_mbhc_cal_btn_det_mp(d, TABLA_BTN_DET_V_BTN_HIGH);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006308 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
6309 if (priv->mbhc_state == MBHC_STATE_POTENTIAL_RECOVERY) {
6310 pr_debug("%s: mbhc is being recovered, skip button press\n",
6311 __func__);
6312 goto done;
6313 }
6314
6315 priv->mbhc_state = MBHC_STATE_POTENTIAL;
6316
6317 if (!priv->mbhc_polling_active) {
6318 pr_warn("%s: mbhc polling is not active, skip button press\n",
6319 __func__);
6320 goto done;
6321 }
Joonwoo Park03324832012-03-19 19:36:16 -07006322
6323 dce = tabla_codec_read_dce_result(codec);
6324 mv = tabla_codec_sta_dce_v(codec, 1, dce);
6325
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006326 /* If GPIO interrupt already kicked in, ignore button press */
6327 if (priv->in_gpio_handler) {
6328 pr_debug("%s: GPIO State Changed, ignore button press\n",
6329 __func__);
6330 btn = -1;
6331 goto done;
6332 }
6333
Joonwoo Parkfee17432012-04-16 16:33:55 -07006334 vddio = (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
6335 priv->mbhc_micbias_switched);
6336 mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv;
6337
Joonwoo Park03324832012-03-19 19:36:16 -07006338 if (mbhc_status != TABLA_MBHC_STATUS_REL_DETECTION) {
6339 if (priv->mbhc_last_resume &&
6340 !time_after(jiffies, priv->mbhc_last_resume + HZ)) {
6341 pr_debug("%s: Button is already released shortly after "
6342 "resume\n", __func__);
6343 n_btn_meas = 0;
Joonwoo Park03324832012-03-19 19:36:16 -07006344 }
6345 }
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07006346
Joonwoo Park12334832012-07-23 19:27:52 -07006347 /* save hw dce */
Joonwoo Parkfee17432012-04-16 16:33:55 -07006348 btnmeas[meas++] = tabla_determine_button(priv, mv_s);
Joonwoo Park12334832012-07-23 19:27:52 -07006349 pr_debug("%s: meas HW - DCE %x,%d,%d button %d\n", __func__,
6350 dce, mv, mv_s, btnmeas[0]);
6351 if (n_btn_meas == 0) {
6352 sta = tabla_codec_read_sta_result(codec);
6353 stamv_s = stamv = tabla_codec_sta_dce_v(codec, 0, sta);
6354 if (vddio)
6355 stamv_s = tabla_scale_v_micb_vddio(priv, stamv, false);
6356 btn = tabla_determine_button(priv, stamv_s);
6357 pr_debug("%s: meas HW - STA %x,%d,%d button %d\n", __func__,
6358 sta, stamv, stamv_s, btn);
6359 BUG_ON(meas != 1);
6360 if (btnmeas[0] != btn)
6361 btn = -1;
6362 }
6363
6364 /* determine pressed button */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006365 for (; ((d->n_btn_meas) && (meas < (d->n_btn_meas + 1))); meas++) {
Joonwoo Parkfee17432012-04-16 16:33:55 -07006366 dce = tabla_codec_sta_dce(codec, 1, false);
6367 mv = tabla_codec_sta_dce_v(codec, 1, dce);
6368 mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv;
6369
6370 btnmeas[meas] = tabla_determine_button(priv, mv_s);
Joonwoo Park12334832012-07-23 19:27:52 -07006371 pr_debug("%s: meas %d - DCE %x,%d,%d button %d\n",
Joonwoo Parkfee17432012-04-16 16:33:55 -07006372 __func__, meas, dce, mv, mv_s, btnmeas[meas]);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006373 /* if large enough measurements are collected,
6374 * start to check if last all n_btn_con measurements were
6375 * in same button low/high range */
6376 if (meas + 1 >= d->n_btn_con) {
6377 for (i = 0; i < d->n_btn_con; i++)
6378 if ((btnmeas[meas] < 0) ||
6379 (btnmeas[meas] != btnmeas[meas - i]))
6380 break;
6381 if (i == d->n_btn_con) {
6382 /* button pressed */
6383 btn = btnmeas[meas];
6384 break;
Joonwoo Park03324832012-03-19 19:36:16 -07006385 } else if ((n_btn_meas - meas) < (d->n_btn_con - 1)) {
6386 /* if left measurements are less than n_btn_con,
6387 * it's impossible to find button number */
6388 break;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006389 }
6390 }
Joonwoo Park8b1f0982011-12-08 17:12:45 -08006391 }
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006392
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006393 if (btn >= 0) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006394 if (priv->in_gpio_handler) {
6395 pr_debug("%s: GPIO already triggered, ignore button "
6396 "press\n", __func__);
6397 goto done;
6398 }
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006399 /* narrow down release threshold */
6400 tabla_mbhc_set_rel_thres(codec, btn_high[btn]);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006401 mask = tabla_get_button_mask(btn);
6402 priv->buttons_pressed |= mask;
Joonwoo Park03324832012-03-19 19:36:16 -07006403 wcd9xxx_lock_sleep(core);
6404 if (schedule_delayed_work(&priv->mbhc_btn_dwork,
6405 msecs_to_jiffies(400)) == 0) {
6406 WARN(1, "Button pressed twice without release"
6407 "event\n");
6408 wcd9xxx_unlock_sleep(core);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006409 }
Joonwoo Park816b8e62012-01-23 16:03:21 -08006410 } else {
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006411 pr_debug("%s: bogus button press, too short press?\n",
6412 __func__);
Joonwoo Park816b8e62012-01-23 16:03:21 -08006413 }
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006414
Joonwoo Park03324832012-03-19 19:36:16 -07006415 done:
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006416 pr_debug("%s: leave\n", __func__);
6417 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006418 return IRQ_HANDLED;
6419}
6420
Joonwoo Park03324832012-03-19 19:36:16 -07006421static int tabla_is_fake_press(struct tabla_priv *priv)
6422{
6423 int i;
6424 int r = 0;
6425 struct snd_soc_codec *codec = priv->codec;
6426 const int dces = MBHC_NUM_DCE_PLUG_DETECT;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006427 s16 mb_v, v_ins_hu, v_ins_h;
6428
6429 v_ins_hu = tabla_get_current_v_ins(priv, true);
6430 v_ins_h = tabla_get_current_v_ins(priv, false);
Joonwoo Park03324832012-03-19 19:36:16 -07006431
6432 for (i = 0; i < dces; i++) {
6433 usleep_range(10000, 10000);
6434 if (i == 0) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006435 mb_v = tabla_codec_sta_dce(codec, 0, true);
Joonwoo Park03324832012-03-19 19:36:16 -07006436 pr_debug("%s: STA[0]: %d,%d\n", __func__, mb_v,
6437 tabla_codec_sta_dce_v(codec, 0, mb_v));
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006438 if (mb_v < (s16)priv->mbhc_data.v_b1_hu ||
6439 mb_v > v_ins_hu) {
Joonwoo Park03324832012-03-19 19:36:16 -07006440 r = 1;
6441 break;
6442 }
6443 } else {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006444 mb_v = tabla_codec_sta_dce(codec, 1, true);
Joonwoo Park03324832012-03-19 19:36:16 -07006445 pr_debug("%s: DCE[%d]: %d,%d\n", __func__, i, mb_v,
6446 tabla_codec_sta_dce_v(codec, 1, mb_v));
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006447 if (mb_v < (s16)priv->mbhc_data.v_b1_h ||
6448 mb_v > v_ins_h) {
Joonwoo Park03324832012-03-19 19:36:16 -07006449 r = 1;
6450 break;
6451 }
6452 }
6453 }
6454
6455 return r;
6456}
6457
Bradley Rubincb1e2732011-06-23 16:49:20 -07006458static irqreturn_t tabla_release_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006459{
Joonwoo Parke5d3aa92012-01-11 14:47:15 -08006460 int ret;
Joonwoo Park816b8e62012-01-23 16:03:21 -08006461 struct tabla_priv *priv = data;
6462 struct snd_soc_codec *codec = priv->codec;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006463
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006464 pr_debug("%s: enter\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07006465
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006466 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
6467 priv->mbhc_state = MBHC_STATE_RELEASE;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006468
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006469 tabla_codec_drive_v_to_micbias(codec, 10000);
6470
Joonwoo Park03324832012-03-19 19:36:16 -07006471 if (priv->buttons_pressed & TABLA_JACK_BUTTON_MASK) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006472 ret = tabla_cancel_btn_work(priv);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006473 if (ret == 0) {
Joonwoo Park03324832012-03-19 19:36:16 -07006474 pr_debug("%s: Reporting long button release event\n",
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006475 __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006476 if (priv->mbhc_cfg.button_jack)
Joonwoo Park8b1f0982011-12-08 17:12:45 -08006477 tabla_snd_soc_jack_report(priv,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006478 priv->mbhc_cfg.button_jack, 0,
6479 priv->buttons_pressed);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006480 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07006481 if (tabla_is_fake_press(priv)) {
6482 pr_debug("%s: Fake button press interrupt\n",
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006483 __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006484 } else if (priv->mbhc_cfg.button_jack) {
6485 if (priv->in_gpio_handler) {
6486 pr_debug("%s: GPIO kicked in, ignore\n",
6487 __func__);
6488 } else {
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006489 pr_debug("%s: Reporting short button "
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006490 "press and release\n",
6491 __func__);
6492 tabla_snd_soc_jack_report(priv,
6493 priv->mbhc_cfg.button_jack,
6494 priv->buttons_pressed,
6495 priv->buttons_pressed);
6496 tabla_snd_soc_jack_report(priv,
6497 priv->mbhc_cfg.button_jack, 0,
6498 priv->buttons_pressed);
6499 }
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006500 }
6501 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006502
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006503 priv->buttons_pressed &= ~TABLA_JACK_BUTTON_MASK;
6504 }
6505
Joonwoo Parkdd9d2962012-07-23 19:24:20 -07006506 /* revert narrowed release threshold */
6507 tabla_mbhc_calc_rel_thres(codec, tabla_mbhc_highest_btn_mv(codec));
Joonwoo Park03324832012-03-19 19:36:16 -07006508 tabla_codec_calibrate_hs_polling(codec);
6509
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006510 if (priv->mbhc_cfg.gpio)
6511 msleep(TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS);
Joonwoo Park03324832012-03-19 19:36:16 -07006512
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006513 tabla_codec_start_hs_polling(codec);
6514
6515 pr_debug("%s: leave\n", __func__);
6516 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006517 return IRQ_HANDLED;
6518}
6519
Bradley Rubincb1e2732011-06-23 16:49:20 -07006520static void tabla_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec)
6521{
6522 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park0976d012011-12-22 11:48:18 -08006523 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006524 TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006525
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07006526 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07006527 tabla_codec_enable_config_mode(codec, 1);
6528
6529 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
6530 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x6, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006531
Joonwoo Park0976d012011-12-22 11:48:18 -08006532 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00);
6533
6534 usleep_range(generic->t_shutdown_plug_rem,
6535 generic->t_shutdown_plug_rem);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006536
6537 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0xA, 0x8);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07006538 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07006539 tabla_codec_enable_config_mode(codec, 0);
6540
6541 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x00);
6542}
6543
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006544static void tabla_codec_cleanup_hs_polling(struct snd_soc_codec *codec)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006545{
6546 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006547
6548 tabla_codec_shutdown_hs_removal_detect(codec);
6549
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07006550 if (!tabla->mclk_enabled) {
Asish Bhattacharya486745a2012-01-20 06:41:53 +05306551 tabla_codec_disable_clock_block(codec);
6552 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006553 }
6554
6555 tabla->mbhc_polling_active = false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006556 tabla->mbhc_state = MBHC_STATE_NONE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006557}
6558
Patrick Lai49efeac2011-11-03 11:01:12 -07006559static irqreturn_t tabla_hphl_ocp_irq(int irq, void *data)
6560{
6561 struct tabla_priv *tabla = data;
6562 struct snd_soc_codec *codec;
6563
6564 pr_info("%s: received HPHL OCP irq\n", __func__);
6565
6566 if (tabla) {
6567 codec = tabla->codec;
Patrick Laic2d833d2012-07-06 22:42:52 -07006568 if ((tabla->hphlocp_cnt < TABLA_OCP_ATTEMPT) &&
6569 (!tabla->hphrocp_cnt)) {
Patrick Laic7cae882011-11-18 11:52:49 -08006570 pr_info("%s: retry\n", __func__);
Patrick Laic2d833d2012-07-06 22:42:52 -07006571 tabla->hphlocp_cnt++;
Patrick Laic7cae882011-11-18 11:52:49 -08006572 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
6573 0x00);
6574 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
6575 0x10);
6576 } else {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306577 wcd9xxx_disable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07006578 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Patrick Laic7cae882011-11-18 11:52:49 -08006579 tabla->hph_status |= SND_JACK_OC_HPHL;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006580 if (tabla->mbhc_cfg.headset_jack)
Patrick Laic7cae882011-11-18 11:52:49 -08006581 tabla_snd_soc_jack_report(tabla,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006582 tabla->mbhc_cfg.headset_jack,
6583 tabla->hph_status,
6584 TABLA_JACK_MASK);
Patrick Lai49efeac2011-11-03 11:01:12 -07006585 }
6586 } else {
6587 pr_err("%s: Bad tabla private data\n", __func__);
6588 }
6589
6590 return IRQ_HANDLED;
6591}
6592
6593static irqreturn_t tabla_hphr_ocp_irq(int irq, void *data)
6594{
6595 struct tabla_priv *tabla = data;
6596 struct snd_soc_codec *codec;
6597
6598 pr_info("%s: received HPHR OCP irq\n", __func__);
6599
6600 if (tabla) {
6601 codec = tabla->codec;
Patrick Laic2d833d2012-07-06 22:42:52 -07006602 if ((tabla->hphrocp_cnt < TABLA_OCP_ATTEMPT) &&
6603 (!tabla->hphlocp_cnt)) {
Patrick Laic7cae882011-11-18 11:52:49 -08006604 pr_info("%s: retry\n", __func__);
Patrick Laic2d833d2012-07-06 22:42:52 -07006605 tabla->hphrocp_cnt++;
Patrick Laic7cae882011-11-18 11:52:49 -08006606 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
6607 0x00);
6608 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
6609 0x10);
6610 } else {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306611 wcd9xxx_disable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07006612 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Patrick Laic7cae882011-11-18 11:52:49 -08006613 tabla->hph_status |= SND_JACK_OC_HPHR;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006614 if (tabla->mbhc_cfg.headset_jack)
Patrick Laic7cae882011-11-18 11:52:49 -08006615 tabla_snd_soc_jack_report(tabla,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006616 tabla->mbhc_cfg.headset_jack,
6617 tabla->hph_status,
6618 TABLA_JACK_MASK);
Patrick Lai49efeac2011-11-03 11:01:12 -07006619 }
6620 } else {
6621 pr_err("%s: Bad tabla private data\n", __func__);
6622 }
6623
6624 return IRQ_HANDLED;
6625}
6626
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006627static bool tabla_is_inval_ins_range(struct snd_soc_codec *codec,
6628 s32 mic_volt, bool highhph, bool *highv)
Joonwoo Park03324832012-03-19 19:36:16 -07006629{
6630 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006631 bool invalid = false;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006632 s16 v_hs_max;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006633
6634 /* Perform this check only when the high voltage headphone
6635 * needs to be considered as invalid
6636 */
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006637 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006638 *highv = mic_volt > v_hs_max;
6639 if (!highhph && *highv)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006640 invalid = true;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006641 else if (mic_volt < tabla->mbhc_data.v_inval_ins_high &&
6642 (mic_volt > tabla->mbhc_data.v_inval_ins_low))
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006643 invalid = true;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006644
6645 return invalid;
6646}
6647
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006648static bool tabla_is_inval_ins_delta(struct snd_soc_codec *codec,
6649 int mic_volt, int mic_volt_prev,
6650 int threshold)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006651{
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006652 return abs(mic_volt - mic_volt_prev) > threshold;
Joonwoo Park03324832012-03-19 19:36:16 -07006653}
6654
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006655/* called under codec_resource_lock acquisition */
6656void tabla_find_plug_and_report(struct snd_soc_codec *codec,
6657 enum tabla_mbhc_plug_type plug_type)
Joonwoo Park03324832012-03-19 19:36:16 -07006658{
6659 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006660
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006661 pr_debug("%s: enter current_plug(%d) new_plug(%d)\n",
6662 __func__, tabla->current_plug, plug_type);
6663
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006664 if (plug_type == PLUG_TYPE_HEADPHONE &&
6665 tabla->current_plug == PLUG_TYPE_NONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006666 /* Nothing was reported previously
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006667 * report a headphone or unsupported
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006668 */
6669 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
6670 tabla_codec_cleanup_hs_polling(codec);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006671 } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) {
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006672 if (!tabla->mbhc_cfg.detect_extn_cable) {
6673 if (tabla->current_plug == PLUG_TYPE_HEADSET)
6674 tabla_codec_report_plug(codec, 0,
6675 SND_JACK_HEADSET);
6676 else if (tabla->current_plug == PLUG_TYPE_HEADPHONE)
6677 tabla_codec_report_plug(codec, 0,
6678 SND_JACK_HEADPHONE);
6679 }
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006680 tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED);
6681 tabla_codec_cleanup_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006682 } else if (plug_type == PLUG_TYPE_HEADSET) {
6683 /* If Headphone was reported previously, this will
6684 * only report the mic line
6685 */
6686 tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET);
Simmi Pateriya21375012012-11-26 23:06:01 +05306687 if (!tabla->mbhc_micbias_switched &&
6688 tabla_is_hph_pa_on(codec)) {
6689 /*If the headphone path is on, switch the micbias
6690 to VDDIO to avoid noise due to button polling */
6691 tabla_codec_switch_micbias(codec, 1);
6692 pr_debug("%s: HPH path is still up\n", __func__);
6693 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006694 msleep(100);
6695 tabla_codec_start_hs_polling(codec);
6696 } else if (plug_type == PLUG_TYPE_HIGH_HPH) {
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006697 if (tabla->mbhc_cfg.detect_extn_cable) {
6698 /* High impedance device found. Report as LINEOUT*/
6699 tabla_codec_report_plug(codec, 1, SND_JACK_LINEOUT);
6700 tabla_codec_cleanup_hs_polling(codec);
6701 pr_debug("%s: setup mic trigger for further detection\n",
6702 __func__);
6703 tabla->lpi_enabled = true;
6704 /*
6705 * Do not enable HPHL trigger. If playback is active,
6706 * it might lead to continuous false HPHL triggers
6707 */
6708 tabla_codec_enable_hs_detect(codec, 1,
6709 MBHC_USE_MB_TRIGGER,
6710 false);
6711 } else {
6712 if (tabla->current_plug == PLUG_TYPE_NONE)
6713 tabla_codec_report_plug(codec, 1,
6714 SND_JACK_HEADPHONE);
6715 tabla_codec_cleanup_hs_polling(codec);
6716 pr_debug("setup mic trigger for further detection\n");
6717 tabla->lpi_enabled = true;
6718 tabla_codec_enable_hs_detect(codec, 1,
6719 MBHC_USE_MB_TRIGGER |
6720 MBHC_USE_HPHL_TRIGGER,
6721 false);
6722 }
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006723 } else {
6724 WARN(1, "Unexpected current plug_type %d, plug_type %d\n",
6725 tabla->current_plug, plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006726 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006727 pr_debug("%s: leave\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006728}
6729
6730/* should be called under interrupt context that hold suspend */
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07006731static void tabla_schedule_hs_detect_plug(struct tabla_priv *tabla,
6732 struct work_struct *correct_plug_work)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006733{
6734 pr_debug("%s: scheduling tabla_hs_correct_gpio_plug\n", __func__);
6735 tabla->hs_detect_work_stop = false;
6736 wcd9xxx_lock_sleep(tabla->codec->control_data);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07006737 schedule_work(correct_plug_work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006738}
6739
6740/* called under codec_resource_lock acquisition */
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07006741static void tabla_cancel_hs_detect_plug(struct tabla_priv *tabla,
6742 struct work_struct *correct_plug_work)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006743{
6744 pr_debug("%s: canceling hs_correct_plug_work\n", __func__);
6745 tabla->hs_detect_work_stop = true;
6746 wmb();
6747 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07006748 if (cancel_work_sync(correct_plug_work)) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006749 pr_debug("%s: hs_correct_plug_work is canceled\n", __func__);
6750 wcd9xxx_unlock_sleep(tabla->codec->control_data);
6751 }
6752 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
6753}
6754
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006755static bool tabla_hs_gpio_level_remove(struct tabla_priv *tabla)
6756{
6757 return (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) !=
6758 tabla->mbhc_cfg.gpio_level_insert);
6759}
6760
Joonwoo Park41956722012-04-18 13:13:07 -07006761/* called under codec_resource_lock acquisition */
6762static void tabla_codec_hphr_gnd_switch(struct snd_soc_codec *codec, bool on)
6763{
6764 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, on);
6765 if (on)
6766 usleep_range(5000, 5000);
6767}
6768
6769/* called under codec_resource_lock acquisition and mbhc override = 1 */
6770static enum tabla_mbhc_plug_type
6771tabla_codec_get_plug_type(struct snd_soc_codec *codec, bool highhph)
6772{
6773 int i;
6774 bool gndswitch, vddioswitch;
6775 int scaled;
6776 struct tabla_mbhc_plug_type_cfg *plug_type_ptr;
6777 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07006778 int num_det = MBHC_NUM_DCE_PLUG_DETECT + 1;
Joonwoo Park41956722012-04-18 13:13:07 -07006779 enum tabla_mbhc_plug_type plug_type[num_det];
6780 s16 mb_v[num_det];
6781 s32 mic_mv[num_det];
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006782 bool inval;
Ravi Kumar Alamanda1c713b22012-09-27 17:14:27 -07006783 bool highdelta = false;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006784 bool ahighv = false, highv;
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07006785 bool gndmicswapped = false;
Joonwoo Park41956722012-04-18 13:13:07 -07006786
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006787 pr_debug("%s: enter\n", __func__);
6788
Joonwoo Park41956722012-04-18 13:13:07 -07006789 /* make sure override is on */
6790 WARN_ON(!(snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04));
6791
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006792 /* GND and MIC swap detection requires at least 2 rounds of DCE */
6793 BUG_ON(num_det < 2);
6794
6795 plug_type_ptr =
6796 TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
6797
6798 plug_type[0] = PLUG_TYPE_INVALID;
6799
Joonwoo Park41956722012-04-18 13:13:07 -07006800 /* performs DCEs for N times
6801 * 1st: check if voltage is in invalid range
6802 * 2nd - N-2nd: check voltage range and delta
6803 * N-1st: check voltage range, delta with HPHR GND switch
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07006804 * Nth: check voltage range with VDDIO switch */
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006805 for (i = 0; i < num_det; i++) {
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07006806 gndswitch = (i == (num_det - 2));
6807 vddioswitch = (i == (num_det - 1)) || (i == (num_det - 2));
Joonwoo Park41956722012-04-18 13:13:07 -07006808 if (i == 0) {
6809 mb_v[i] = tabla_codec_setup_hs_polling(codec);
6810 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006811 inval = tabla_is_inval_ins_range(codec, mic_mv[i],
6812 highhph, &highv);
6813 ahighv |= highv;
Joonwoo Park41956722012-04-18 13:13:07 -07006814 scaled = mic_mv[i];
Joonwoo Park41956722012-04-18 13:13:07 -07006815 } else {
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006816 if (vddioswitch)
6817 __tabla_codec_switch_micbias(tabla->codec, 1,
6818 false, false);
Joonwoo Park41956722012-04-18 13:13:07 -07006819 if (gndswitch)
6820 tabla_codec_hphr_gnd_switch(codec, true);
6821 mb_v[i] = __tabla_codec_sta_dce(codec, 1, true, true);
6822 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006823 if (vddioswitch)
6824 scaled = tabla_scale_v_micb_vddio(tabla,
Joonwoo Park41956722012-04-18 13:13:07 -07006825 mic_mv[i],
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006826 false);
6827 else
6828 scaled = mic_mv[i];
6829 /* !gndswitch & vddioswitch means the previous DCE
6830 * was done with gndswitch, don't compare with DCE
6831 * with gndswitch */
6832 highdelta = tabla_is_inval_ins_delta(codec, scaled,
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07006833 mic_mv[i - 1],
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006834 TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV);
6835 inval = (tabla_is_inval_ins_range(codec, mic_mv[i],
6836 highhph, &highv) ||
6837 highdelta);
6838 ahighv |= highv;
Joonwoo Park41956722012-04-18 13:13:07 -07006839 if (gndswitch)
6840 tabla_codec_hphr_gnd_switch(codec, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006841 if (vddioswitch)
6842 __tabla_codec_switch_micbias(tabla->codec, 0,
6843 false, false);
Joonwoo Park41956722012-04-18 13:13:07 -07006844 }
6845 pr_debug("%s: DCE #%d, %04x, V %d, scaled V %d, GND %d, "
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006846 "VDDIO %d, inval %d\n", __func__,
Joonwoo Park41956722012-04-18 13:13:07 -07006847 i + 1, mb_v[i] & 0xffff, mic_mv[i], scaled, gndswitch,
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006848 vddioswitch, inval);
6849 /* don't need to run further DCEs */
Ravi Kumar Alamanda1c713b22012-09-27 17:14:27 -07006850 if ((ahighv || !vddioswitch) && inval)
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006851 break;
6852 mic_mv[i] = scaled;
Ravi Kumar Alamanda1c713b22012-09-27 17:14:27 -07006853
6854 /*
6855 * claim UNSUPPORTED plug insertion when
6856 * good headset is detected but HPHR GND switch makes
6857 * delta difference
6858 */
6859 if (i == (num_det - 2) && highdelta && !ahighv)
6860 gndmicswapped = true;
6861 else if (i == (num_det - 1) && inval) {
6862 if (gndmicswapped)
6863 plug_type[0] = PLUG_TYPE_GND_MIC_SWAP;
6864 else
6865 plug_type[0] = PLUG_TYPE_INVALID;
6866 }
Joonwoo Park41956722012-04-18 13:13:07 -07006867 }
6868
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006869 for (i = 0; (plug_type[0] != PLUG_TYPE_GND_MIC_SWAP && !inval) &&
6870 i < num_det; i++) {
Joonwoo Park41956722012-04-18 13:13:07 -07006871 /*
6872 * If we are here, means none of the all
6873 * measurements are fake, continue plug type detection.
6874 * If all three measurements do not produce same
6875 * plug type, restart insertion detection
6876 */
6877 if (mic_mv[i] < plug_type_ptr->v_no_mic) {
6878 plug_type[i] = PLUG_TYPE_HEADPHONE;
6879 pr_debug("%s: Detect attempt %d, detected Headphone\n",
6880 __func__, i);
6881 } else if (highhph && (mic_mv[i] > plug_type_ptr->v_hs_max)) {
6882 plug_type[i] = PLUG_TYPE_HIGH_HPH;
6883 pr_debug("%s: Detect attempt %d, detected High "
6884 "Headphone\n", __func__, i);
6885 } else {
6886 plug_type[i] = PLUG_TYPE_HEADSET;
6887 pr_debug("%s: Detect attempt %d, detected Headset\n",
6888 __func__, i);
6889 }
6890
6891 if (i > 0 && (plug_type[i - 1] != plug_type[i])) {
6892 pr_err("%s: Detect attempt %d and %d are not same",
6893 __func__, i - 1, i);
6894 plug_type[0] = PLUG_TYPE_INVALID;
6895 inval = true;
6896 break;
6897 }
6898 }
6899
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006900 pr_debug("%s: Detected plug type %d\n", __func__, plug_type[0]);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006901 pr_debug("%s: leave\n", __func__);
Joonwoo Park41956722012-04-18 13:13:07 -07006902 return plug_type[0];
6903}
6904
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006905static void tabla_hs_correct_gpio_plug(struct work_struct *work)
6906{
6907 struct tabla_priv *tabla;
6908 struct snd_soc_codec *codec;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006909 int retry = 0, pt_gnd_mic_swap_cnt = 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006910 bool correction = false;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006911 enum tabla_mbhc_plug_type plug_type = PLUG_TYPE_INVALID;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006912 unsigned long timeout;
6913
6914 tabla = container_of(work, struct tabla_priv, hs_correct_plug_work);
6915 codec = tabla->codec;
6916
6917 pr_debug("%s: enter\n", __func__);
6918 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
6919
6920 /* Keep override on during entire plug type correction work.
6921 *
6922 * This is okay under the assumption that any GPIO irqs which use
6923 * MBHC block cancel and sync this work so override is off again
6924 * prior to GPIO interrupt handler's MBHC block usage.
6925 * Also while this correction work is running, we can guarantee
6926 * DAPM doesn't use any MBHC block as this work only runs with
6927 * headphone detection.
6928 */
6929 tabla_turn_onoff_override(codec, true);
6930
6931 timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS);
6932 while (!time_after(jiffies, timeout)) {
6933 ++retry;
6934 rmb();
6935 if (tabla->hs_detect_work_stop) {
6936 pr_debug("%s: stop requested\n", __func__);
6937 break;
6938 }
6939
6940 msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS);
6941 if (tabla_hs_gpio_level_remove(tabla)) {
6942 pr_debug("%s: GPIO value is low\n", __func__);
6943 break;
6944 }
6945
6946 /* can race with removal interrupt */
6947 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Joonwoo Park41956722012-04-18 13:13:07 -07006948 plug_type = tabla_codec_get_plug_type(codec, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006949 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
6950
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006951 pr_debug("%s: attempt(%d) current_plug(%d) new_plug(%d)\n",
6952 __func__, retry, tabla->current_plug, plug_type);
Joonwoo Park41956722012-04-18 13:13:07 -07006953 if (plug_type == PLUG_TYPE_INVALID) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006954 pr_debug("Invalid plug in attempt # %d\n", retry);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006955 if (!tabla->mbhc_cfg.detect_extn_cable &&
6956 retry == NUM_ATTEMPTS_TO_REPORT &&
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006957 tabla->current_plug == PLUG_TYPE_NONE) {
6958 tabla_codec_report_plug(codec, 1,
6959 SND_JACK_HEADPHONE);
6960 }
Joonwoo Park41956722012-04-18 13:13:07 -07006961 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006962 pr_debug("Good headphone detected, continue polling mic\n");
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07006963 if (tabla->mbhc_cfg.detect_extn_cable) {
6964 if (tabla->current_plug != plug_type)
6965 tabla_codec_report_plug(codec, 1,
6966 SND_JACK_HEADPHONE);
6967 } else if (tabla->current_plug == PLUG_TYPE_NONE)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006968 tabla_codec_report_plug(codec, 1,
6969 SND_JACK_HEADPHONE);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006970 } else {
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006971 if (plug_type == PLUG_TYPE_GND_MIC_SWAP) {
6972 pt_gnd_mic_swap_cnt++;
6973 if (pt_gnd_mic_swap_cnt <
6974 TABLA_MBHC_GND_MIC_SWAP_THRESHOLD)
6975 continue;
6976 else if (pt_gnd_mic_swap_cnt >
6977 TABLA_MBHC_GND_MIC_SWAP_THRESHOLD) {
6978 /* This is due to GND/MIC switch didn't
6979 * work, Report unsupported plug */
6980 } else if (tabla->mbhc_cfg.swap_gnd_mic) {
6981 /* if switch is toggled, check again,
6982 * otherwise report unsupported plug */
6983 if (tabla->mbhc_cfg.swap_gnd_mic(codec))
6984 continue;
6985 }
6986 } else
6987 pt_gnd_mic_swap_cnt = 0;
6988
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006989 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
6990 /* Turn off override */
6991 tabla_turn_onoff_override(codec, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006992 /* The valid plug also includes PLUG_TYPE_GND_MIC_SWAP
6993 */
Joonwoo Park41956722012-04-18 13:13:07 -07006994 tabla_find_plug_and_report(codec, plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006995 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
6996 pr_debug("Attempt %d found correct plug %d\n", retry,
Joonwoo Park41956722012-04-18 13:13:07 -07006997 plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006998 correction = true;
6999 break;
7000 }
7001 }
7002
7003 /* Turn off override */
7004 if (!correction)
7005 tabla_turn_onoff_override(codec, false);
7006
7007 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007008
7009 if (tabla->mbhc_cfg.detect_extn_cable) {
7010 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
7011 if (tabla->current_plug == PLUG_TYPE_HEADPHONE ||
7012 tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP ||
7013 tabla->current_plug == PLUG_TYPE_INVALID ||
7014 plug_type == PLUG_TYPE_INVALID) {
7015 /* Enable removal detection */
7016 tabla_codec_cleanup_hs_polling(codec);
7017 tabla_codec_enable_hs_detect(codec, 0, 0, false);
7018 }
7019 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
7020 }
7021 pr_debug("%s: leave current_plug(%d)\n",
7022 __func__, tabla->current_plug);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007023 /* unlock sleep */
7024 wcd9xxx_unlock_sleep(tabla->codec->control_data);
7025}
7026
7027/* called under codec_resource_lock acquisition */
7028static void tabla_codec_decide_gpio_plug(struct snd_soc_codec *codec)
7029{
Joonwoo Park41956722012-04-18 13:13:07 -07007030 enum tabla_mbhc_plug_type plug_type;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007031 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007032
7033 pr_debug("%s: enter\n", __func__);
7034
7035 tabla_turn_onoff_override(codec, true);
Joonwoo Park41956722012-04-18 13:13:07 -07007036 plug_type = tabla_codec_get_plug_type(codec, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007037 tabla_turn_onoff_override(codec, false);
7038
7039 if (tabla_hs_gpio_level_remove(tabla)) {
7040 pr_debug("%s: GPIO value is low when determining plug\n",
7041 __func__);
7042 return;
7043 }
7044
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007045 if (plug_type == PLUG_TYPE_INVALID ||
7046 plug_type == PLUG_TYPE_GND_MIC_SWAP) {
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007047 tabla_schedule_hs_detect_plug(tabla,
7048 &tabla->hs_correct_plug_work);
Joonwoo Park41956722012-04-18 13:13:07 -07007049 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007050 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
7051
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007052 tabla_schedule_hs_detect_plug(tabla,
7053 &tabla->hs_correct_plug_work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007054 } else {
Joonwoo Park41956722012-04-18 13:13:07 -07007055 pr_debug("%s: Valid plug found, determine plug type %d\n",
7056 __func__, plug_type);
7057 tabla_find_plug_and_report(codec, plug_type);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007058 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007059 pr_debug("%s: leave\n", __func__);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007060}
7061
7062/* called under codec_resource_lock acquisition */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007063static void tabla_codec_detect_plug_type(struct snd_soc_codec *codec)
7064{
Joonwoo Park41956722012-04-18 13:13:07 -07007065 enum tabla_mbhc_plug_type plug_type;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007066 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
7067 const struct tabla_mbhc_plug_detect_cfg *plug_det =
7068 TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007069 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007070 /* Turn on the override,
7071 * tabla_codec_setup_hs_polling requires override on */
7072 tabla_turn_onoff_override(codec, true);
Joonwoo Park03324832012-03-19 19:36:16 -07007073
7074 if (plug_det->t_ins_complete > 20)
7075 msleep(plug_det->t_ins_complete);
7076 else
7077 usleep_range(plug_det->t_ins_complete * 1000,
7078 plug_det->t_ins_complete * 1000);
7079
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007080 if (tabla->mbhc_cfg.gpio) {
7081 /* Turn off the override */
7082 tabla_turn_onoff_override(codec, false);
7083 if (tabla_hs_gpio_level_remove(tabla))
7084 pr_debug("%s: GPIO value is low when determining "
7085 "plug\n", __func__);
7086 else
7087 tabla_codec_decide_gpio_plug(codec);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007088 pr_debug("%s: leave\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007089 return;
7090 }
7091
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007092 plug_type = tabla_codec_get_plug_type(codec, false);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007093 tabla_turn_onoff_override(codec, false);
Joonwoo Park03324832012-03-19 19:36:16 -07007094
Joonwoo Park41956722012-04-18 13:13:07 -07007095 if (plug_type == PLUG_TYPE_INVALID) {
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007096 pr_debug("%s: Invalid plug type detected\n", __func__);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007097 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, 0x02);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007098 tabla_codec_cleanup_hs_polling(codec);
7099 tabla_codec_enable_hs_detect(codec, 1,
7100 MBHC_USE_MB_TRIGGER |
7101 MBHC_USE_HPHL_TRIGGER, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007102 } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) {
7103 pr_debug("%s: GND-MIC swapped plug type detected\n", __func__);
7104 tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED);
7105 tabla_codec_cleanup_hs_polling(codec);
7106 tabla_codec_enable_hs_detect(codec, 0, 0, false);
Joonwoo Park41956722012-04-18 13:13:07 -07007107 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Park03324832012-03-19 19:36:16 -07007108 pr_debug("%s: Headphone Detected\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007109 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
7110 tabla_codec_cleanup_hs_polling(codec);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007111 tabla_schedule_hs_detect_plug(tabla,
7112 &tabla->hs_correct_plug_work_nogpio);
Joonwoo Park41956722012-04-18 13:13:07 -07007113 } else if (plug_type == PLUG_TYPE_HEADSET) {
Joonwoo Park03324832012-03-19 19:36:16 -07007114 pr_debug("%s: Headset detected\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007115 tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET);
Joonwoo Park03324832012-03-19 19:36:16 -07007116 /* avoid false button press detect */
7117 msleep(50);
Joonwoo Park03324832012-03-19 19:36:16 -07007118 tabla_codec_start_hs_polling(codec);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007119 } else if (tabla->mbhc_cfg.detect_extn_cable &&
7120 plug_type == PLUG_TYPE_HIGH_HPH) {
7121 pr_debug("%s: High impedance plug type detected\n", __func__);
7122 tabla_codec_report_plug(codec, 1, SND_JACK_LINEOUT);
7123 /* Enable insertion detection on the other end of cable */
7124 tabla_codec_cleanup_hs_polling(codec);
7125 tabla_codec_enable_hs_detect(codec, 1,
7126 MBHC_USE_MB_TRIGGER, false);
Joonwoo Park03324832012-03-19 19:36:16 -07007127 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007128 pr_debug("%s: leave\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07007129}
7130
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007131/* called only from interrupt which is under codec_resource_lock acquisition */
7132static void tabla_hs_insert_irq_gpio(struct tabla_priv *priv, bool is_removal)
Bradley Rubincb1e2732011-06-23 16:49:20 -07007133{
Bradley Rubincb1e2732011-06-23 16:49:20 -07007134 struct snd_soc_codec *codec = priv->codec;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007135 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007136
7137 if (!is_removal) {
7138 pr_debug("%s: MIC trigger insertion interrupt\n", __func__);
7139
7140 rmb();
7141 if (priv->lpi_enabled)
7142 msleep(100);
7143
7144 rmb();
7145 if (!priv->lpi_enabled) {
7146 pr_debug("%s: lpi is disabled\n", __func__);
7147 } else if (gpio_get_value_cansleep(priv->mbhc_cfg.gpio) ==
7148 priv->mbhc_cfg.gpio_level_insert) {
7149 pr_debug("%s: Valid insertion, "
7150 "detect plug type\n", __func__);
7151 tabla_codec_decide_gpio_plug(codec);
7152 } else {
7153 pr_debug("%s: Invalid insertion, "
7154 "stop plug detection\n", __func__);
7155 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007156 } else if (tabla->mbhc_cfg.detect_extn_cable) {
7157 pr_debug("%s: Removal\n", __func__);
7158 if (!tabla_hs_gpio_level_remove(tabla)) {
7159 /*
7160 * gpio says, something is still inserted, could be
7161 * extension cable i.e. headset is removed from
7162 * extension cable
7163 */
7164 /* cancel detect plug */
7165 tabla_cancel_hs_detect_plug(tabla,
7166 &tabla->hs_correct_plug_work);
7167 tabla_codec_decide_gpio_plug(codec);
7168 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007169 } else {
7170 pr_err("%s: GPIO used, invalid MBHC Removal\n", __func__);
7171 }
7172}
7173
7174/* called only from interrupt which is under codec_resource_lock acquisition */
7175static void tabla_hs_insert_irq_nogpio(struct tabla_priv *priv, bool is_removal,
7176 bool is_mb_trigger)
7177{
Joonwoo Park03324832012-03-19 19:36:16 -07007178 int ret;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007179 struct snd_soc_codec *codec = priv->codec;
7180 struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007181 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
7182
7183 /* Cancel possibly running hs_detect_work */
7184 tabla_cancel_hs_detect_plug(tabla,
7185 &tabla->hs_correct_plug_work_nogpio);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07007186
7187 if (is_removal) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007188
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07007189 /*
7190 * If headphone is removed while playback is in progress,
7191 * it is possible that micbias will be switched to VDDIO.
7192 */
Joonwoo Park03324832012-03-19 19:36:16 -07007193 tabla_codec_switch_micbias(codec, 0);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007194 if (priv->current_plug == PLUG_TYPE_HEADPHONE)
7195 tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE);
7196 else if (priv->current_plug == PLUG_TYPE_GND_MIC_SWAP)
7197 tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED);
7198 else
7199 WARN(1, "%s: Unexpected current plug type %d\n",
7200 __func__, priv->current_plug);
Bradley Rubincb1e2732011-06-23 16:49:20 -07007201 tabla_codec_shutdown_hs_removal_detect(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007202 tabla_codec_enable_hs_detect(codec, 1,
7203 MBHC_USE_MB_TRIGGER |
7204 MBHC_USE_HPHL_TRIGGER,
Joonwoo Park03324832012-03-19 19:36:16 -07007205 true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007206 } else if (is_mb_trigger && !is_removal) {
Joonwoo Park03324832012-03-19 19:36:16 -07007207 pr_debug("%s: Waiting for Headphone left trigger\n",
7208 __func__);
7209 wcd9xxx_lock_sleep(core);
7210 if (schedule_delayed_work(&priv->mbhc_insert_dwork,
7211 usecs_to_jiffies(1000000)) == 0) {
7212 pr_err("%s: mbhc_insert_dwork is already scheduled\n",
7213 __func__);
7214 wcd9xxx_unlock_sleep(core);
Joonwoo Parkf4267c22012-01-10 13:25:24 -08007215 }
Joonwoo Park03324832012-03-19 19:36:16 -07007216 tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER,
7217 false);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007218 } else {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007219 ret = cancel_delayed_work(&priv->mbhc_insert_dwork);
7220 if (ret != 0) {
7221 pr_debug("%s: Complete plug insertion, Detecting plug "
7222 "type\n", __func__);
7223 tabla_codec_detect_plug_type(codec);
7224 wcd9xxx_unlock_sleep(core);
7225 } else {
7226 wcd9xxx_enable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007227 WCD9XXX_IRQ_MBHC_INSERTION);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007228 pr_err("%s: Error detecting plug insertion\n",
7229 __func__);
7230 }
Joonwoo Park03324832012-03-19 19:36:16 -07007231 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007232}
Bhalchandra Gajare9494fa262011-11-10 19:25:59 -08007233
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007234/* called only from interrupt which is under codec_resource_lock acquisition */
7235static void tabla_hs_insert_irq_extn(struct tabla_priv *priv,
7236 bool is_mb_trigger)
7237{
7238 struct snd_soc_codec *codec = priv->codec;
7239 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
7240
7241 /* Cancel possibly running hs_detect_work */
7242 tabla_cancel_hs_detect_plug(tabla,
7243 &tabla->hs_correct_plug_work);
7244
7245 if (is_mb_trigger) {
7246 pr_debug("%s: Waiting for Headphone left trigger\n",
7247 __func__);
7248 tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER,
7249 false);
7250 } else {
7251 pr_debug("%s: HPHL trigger received, detecting plug type\n",
7252 __func__);
7253 tabla_codec_detect_plug_type(codec);
7254 }
7255}
7256
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007257static irqreturn_t tabla_hs_insert_irq(int irq, void *data)
7258{
7259 bool is_mb_trigger, is_removal;
7260 struct tabla_priv *priv = data;
7261 struct snd_soc_codec *codec = priv->codec;
Bradley Rubincb1e2732011-06-23 16:49:20 -07007262
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007263 pr_debug("%s: enter\n", __func__);
7264 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007265 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007266
7267 is_mb_trigger = !!(snd_soc_read(codec, priv->mbhc_bias_regs.mbhc_reg) &
7268 0x10);
7269 is_removal = !!(snd_soc_read(codec, TABLA_A_CDC_MBHC_INT_CTL) & 0x02);
7270 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x03, 0x00);
7271
7272 /* Turn off both HPH and MIC line schmitt triggers */
7273 snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
7274 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
7275 snd_soc_update_bits(codec, priv->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
7276
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007277 if (priv->mbhc_cfg.detect_extn_cable &&
7278 priv->current_plug == PLUG_TYPE_HIGH_HPH)
7279 tabla_hs_insert_irq_extn(priv, is_mb_trigger);
7280 else if (priv->mbhc_cfg.gpio)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007281 tabla_hs_insert_irq_gpio(priv, is_removal);
7282 else
7283 tabla_hs_insert_irq_nogpio(priv, is_removal, is_mb_trigger);
7284
7285 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bradley Rubincb1e2732011-06-23 16:49:20 -07007286 return IRQ_HANDLED;
7287}
7288
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007289static bool is_valid_mic_voltage(struct snd_soc_codec *codec, s32 mic_mv)
7290{
7291 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007292 const struct tabla_mbhc_plug_type_cfg *plug_type =
7293 TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
7294 const s16 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007295
7296 return (!(mic_mv > 10 && mic_mv < 80) && (mic_mv > plug_type->v_no_mic)
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007297 && (mic_mv < v_hs_max)) ? true : false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007298}
7299
7300/* called under codec_resource_lock acquisition
7301 * returns true if mic voltage range is back to normal insertion
7302 * returns false either if timedout or removed */
7303static bool tabla_hs_remove_settle(struct snd_soc_codec *codec)
7304{
7305 int i;
7306 bool timedout, settled = false;
7307 s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT];
7308 short mb_v[MBHC_NUM_DCE_PLUG_DETECT];
7309 unsigned long retry = 0, timeout;
7310 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007311 const s16 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007312
7313 timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS);
7314 while (!(timedout = time_after(jiffies, timeout))) {
7315 retry++;
7316 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
7317 pr_debug("%s: GPIO indicates removal\n", __func__);
7318 break;
7319 }
7320
7321 if (tabla->mbhc_cfg.gpio) {
7322 if (retry > 1)
7323 msleep(250);
7324 else
7325 msleep(50);
7326 }
7327
7328 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
7329 pr_debug("%s: GPIO indicates removal\n", __func__);
7330 break;
7331 }
7332
7333 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) {
7334 mb_v[i] = tabla_codec_sta_dce(codec, 1, true);
7335 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
7336 pr_debug("%s : DCE run %lu, mic_mv = %d(%x)\n",
7337 __func__, retry, mic_mv[i], mb_v[i]);
7338 }
7339
7340 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
7341 pr_debug("%s: GPIO indicates removal\n", __func__);
7342 break;
7343 }
7344
7345 if (tabla->current_plug == PLUG_TYPE_NONE) {
7346 pr_debug("%s : headset/headphone is removed\n",
7347 __func__);
7348 break;
7349 }
7350
7351 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++)
7352 if (!is_valid_mic_voltage(codec, mic_mv[i]))
7353 break;
7354
7355 if (i == MBHC_NUM_DCE_PLUG_DETECT) {
7356 pr_debug("%s: MIC voltage settled\n", __func__);
7357 settled = true;
7358 msleep(200);
7359 break;
7360 }
7361
7362 /* only for non-GPIO remove irq */
7363 if (!tabla->mbhc_cfg.gpio) {
7364 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++)
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007365 if (mic_mv[i] < v_hs_max)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007366 break;
7367 if (i == MBHC_NUM_DCE_PLUG_DETECT) {
7368 pr_debug("%s: Headset is removed\n", __func__);
7369 break;
7370 }
7371 }
7372 }
7373
7374 if (timedout)
7375 pr_debug("%s: Microphone did not settle in %d seconds\n",
7376 __func__, TABLA_HS_DETECT_PLUG_TIME_MS);
7377 return settled;
7378}
7379
7380/* called only from interrupt which is under codec_resource_lock acquisition */
7381static void tabla_hs_remove_irq_gpio(struct tabla_priv *priv)
7382{
7383 struct snd_soc_codec *codec = priv->codec;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007384 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007385 if (tabla_hs_remove_settle(codec))
7386 tabla_codec_start_hs_polling(codec);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007387 pr_debug("%s: leave\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007388}
7389
7390/* called only from interrupt which is under codec_resource_lock acquisition */
7391static void tabla_hs_remove_irq_nogpio(struct tabla_priv *priv)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007392{
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007393 short bias_value;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007394 bool removed = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007395 struct snd_soc_codec *codec = priv->codec;
Joonwoo Park0976d012011-12-22 11:48:18 -08007396 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007397 TABLA_MBHC_CAL_GENERAL_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007398 int min_us = TABLA_FAKE_REMOVAL_MIN_PERIOD_MS * 1000;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007399
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007400 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007401 if (priv->current_plug != PLUG_TYPE_HEADSET) {
7402 pr_debug("%s(): Headset is not inserted, ignore removal\n",
7403 __func__);
7404 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
7405 0x08, 0x08);
7406 return;
7407 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007408
Joonwoo Park0976d012011-12-22 11:48:18 -08007409 usleep_range(generic->t_shutdown_plug_rem,
7410 generic->t_shutdown_plug_rem);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007411
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007412 do {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007413 bias_value = tabla_codec_sta_dce(codec, 1, true);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007414 pr_debug("%s: DCE %d,%d, %d us left\n", __func__, bias_value,
7415 tabla_codec_sta_dce_v(codec, 1, bias_value), min_us);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007416 if (bias_value < tabla_get_current_v_ins(priv, false)) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007417 pr_debug("%s: checking false removal\n", __func__);
7418 msleep(500);
7419 removed = !tabla_hs_remove_settle(codec);
7420 pr_debug("%s: headset %sactually removed\n", __func__,
7421 removed ? "" : "not ");
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08007422 break;
7423 }
7424 min_us -= priv->mbhc_data.t_dce;
7425 } while (min_us > 0);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07007426
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007427 if (removed) {
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007428 if (priv->mbhc_cfg.detect_extn_cable) {
7429 if (!tabla_hs_gpio_level_remove(priv)) {
7430 /*
7431 * extension cable is still plugged in
7432 * report it as LINEOUT device
7433 */
7434 tabla_codec_report_plug(codec, 1,
7435 SND_JACK_LINEOUT);
7436 tabla_codec_cleanup_hs_polling(codec);
7437 tabla_codec_enable_hs_detect(codec, 1,
7438 MBHC_USE_MB_TRIGGER,
7439 false);
7440 }
7441 } else {
7442 /* Cancel possibly running hs_detect_work */
7443 tabla_cancel_hs_detect_plug(priv,
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007444 &priv->hs_correct_plug_work_nogpio);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007445 /*
7446 * If this removal is not false, first check the micbias
7447 * switch status and switch it to LDOH if it is already
7448 * switched to VDDIO.
7449 */
7450 tabla_codec_switch_micbias(codec, 0);
Joonwoo Park03324832012-03-19 19:36:16 -07007451
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007452 tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET);
7453 tabla_codec_cleanup_hs_polling(codec);
7454 tabla_codec_enable_hs_detect(codec, 1,
7455 MBHC_USE_MB_TRIGGER |
7456 MBHC_USE_HPHL_TRIGGER,
7457 true);
7458 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007459 } else {
7460 tabla_codec_start_hs_polling(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007461 }
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007462 pr_debug("%s: leave\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007463}
Joonwoo Park8b1f0982011-12-08 17:12:45 -08007464
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007465static irqreturn_t tabla_hs_remove_irq(int irq, void *data)
7466{
7467 struct tabla_priv *priv = data;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007468 bool vddio;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007469 pr_debug("%s: enter, removal interrupt\n", __func__);
7470
7471 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007472 vddio = (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
7473 priv->mbhc_micbias_switched);
7474 if (vddio)
7475 __tabla_codec_switch_micbias(priv->codec, 0, false, true);
7476
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007477 if ((priv->mbhc_cfg.detect_extn_cable &&
7478 !tabla_hs_gpio_level_remove(priv)) ||
7479 !priv->mbhc_cfg.gpio) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007480 tabla_hs_remove_irq_nogpio(priv);
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007481 } else
7482 tabla_hs_remove_irq_gpio(priv);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007483
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007484 /* if driver turned off vddio switch and headset is not removed,
7485 * turn on the vddio switch back, if headset is removed then vddio
7486 * switch is off by time now and shouldn't be turn on again from here */
7487 if (vddio && priv->current_plug == PLUG_TYPE_HEADSET)
7488 __tabla_codec_switch_micbias(priv->codec, 1, true, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007489 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007490
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007491 return IRQ_HANDLED;
7492}
7493
Joonwoo Park03324832012-03-19 19:36:16 -07007494void mbhc_insert_work(struct work_struct *work)
7495{
7496 struct delayed_work *dwork;
7497 struct tabla_priv *tabla;
7498 struct snd_soc_codec *codec;
7499 struct wcd9xxx *tabla_core;
7500
7501 dwork = to_delayed_work(work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007502 tabla = container_of(dwork, struct tabla_priv, mbhc_insert_dwork);
Joonwoo Park03324832012-03-19 19:36:16 -07007503 codec = tabla->codec;
7504 tabla_core = dev_get_drvdata(codec->dev->parent);
7505
7506 pr_debug("%s:\n", __func__);
7507
7508 /* Turn off both HPH and MIC line schmitt triggers */
7509 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
7510 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
7511 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007512 wcd9xxx_disable_irq_sync(codec->control_data,
7513 WCD9XXX_IRQ_MBHC_INSERTION);
Joonwoo Park03324832012-03-19 19:36:16 -07007514 tabla_codec_detect_plug_type(codec);
7515 wcd9xxx_unlock_sleep(tabla_core);
7516}
7517
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007518static void tabla_hs_gpio_handler(struct snd_soc_codec *codec)
7519{
7520 bool insert;
7521 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
7522 bool is_removed = false;
7523
7524 pr_debug("%s: enter\n", __func__);
7525
7526 tabla->in_gpio_handler = true;
7527 /* Wait here for debounce time */
7528 usleep_range(TABLA_GPIO_IRQ_DEBOUNCE_TIME_US,
7529 TABLA_GPIO_IRQ_DEBOUNCE_TIME_US);
7530
7531 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
7532
7533 /* cancel pending button press */
7534 if (tabla_cancel_btn_work(tabla))
7535 pr_debug("%s: button press is canceled\n", __func__);
7536
7537 insert = (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) ==
7538 tabla->mbhc_cfg.gpio_level_insert);
7539 if ((tabla->current_plug == PLUG_TYPE_NONE) && insert) {
7540 tabla->lpi_enabled = false;
7541 wmb();
7542
7543 /* cancel detect plug */
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007544 tabla_cancel_hs_detect_plug(tabla,
7545 &tabla->hs_correct_plug_work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007546
7547 /* Disable Mic Bias pull down and HPH Switch to GND */
7548 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01,
7549 0x00);
7550 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x00);
7551 tabla_codec_detect_plug_type(codec);
7552 } else if ((tabla->current_plug != PLUG_TYPE_NONE) && !insert) {
7553 tabla->lpi_enabled = false;
7554 wmb();
7555
7556 /* cancel detect plug */
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007557 tabla_cancel_hs_detect_plug(tabla,
7558 &tabla->hs_correct_plug_work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007559
7560 if (tabla->current_plug == PLUG_TYPE_HEADPHONE) {
7561 tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE);
7562 is_removed = true;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007563 } else if (tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP) {
7564 tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED);
7565 is_removed = true;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007566 } else if (tabla->current_plug == PLUG_TYPE_HEADSET) {
7567 tabla_codec_pause_hs_polling(codec);
7568 tabla_codec_cleanup_hs_polling(codec);
7569 tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET);
7570 is_removed = true;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -07007571 } else if (tabla->current_plug == PLUG_TYPE_HIGH_HPH) {
7572 tabla_codec_report_plug(codec, 0, SND_JACK_LINEOUT);
7573 is_removed = true;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007574 }
7575
7576 if (is_removed) {
7577 /* Enable Mic Bias pull down and HPH Switch to GND */
7578 snd_soc_update_bits(codec,
7579 tabla->mbhc_bias_regs.ctl_reg, 0x01,
7580 0x01);
7581 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01,
7582 0x01);
7583 /* Make sure mic trigger is turned off */
7584 snd_soc_update_bits(codec,
7585 tabla->mbhc_bias_regs.ctl_reg,
7586 0x01, 0x01);
7587 snd_soc_update_bits(codec,
7588 tabla->mbhc_bias_regs.mbhc_reg,
7589 0x90, 0x00);
7590 /* Reset MBHC State Machine */
7591 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
7592 0x08, 0x08);
7593 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
7594 0x08, 0x00);
7595 /* Turn off override */
7596 tabla_turn_onoff_override(codec, false);
Simmi Pateriya21375012012-11-26 23:06:01 +05307597 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007598 }
7599 }
7600
7601 tabla->in_gpio_handler = false;
7602 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
7603 pr_debug("%s: leave\n", __func__);
7604}
7605
7606static irqreturn_t tabla_mechanical_plug_detect_irq(int irq, void *data)
7607{
7608 int r = IRQ_HANDLED;
7609 struct snd_soc_codec *codec = data;
Joonwoo Parkecf379c2012-10-04 16:57:52 -07007610 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007611
7612 if (unlikely(wcd9xxx_lock_sleep(codec->control_data) == false)) {
7613 pr_warn("%s: failed to hold suspend\n", __func__);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07007614 /*
7615 * Give up this IRQ for now and resend this IRQ so IRQ can be
7616 * handled after system resume
7617 */
7618 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
7619 tabla->gpio_irq_resend = true;
7620 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
7621 wake_lock_timeout(&tabla->irq_resend_wlock, HZ);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007622 r = IRQ_NONE;
7623 } else {
7624 tabla_hs_gpio_handler(codec);
7625 wcd9xxx_unlock_sleep(codec->control_data);
7626 }
7627
7628 return r;
7629}
7630
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007631static void tabla_hs_correct_plug_nogpio(struct work_struct *work)
7632{
7633 struct tabla_priv *tabla;
7634 struct snd_soc_codec *codec;
7635 unsigned long timeout;
7636 int retry = 0;
7637 enum tabla_mbhc_plug_type plug_type;
7638 bool is_headset = false;
7639
7640 pr_debug("%s(): Poll Microphone voltage for %d seconds\n",
7641 __func__, TABLA_HS_DETECT_PLUG_TIME_MS / 1000);
7642
7643 tabla = container_of(work, struct tabla_priv,
7644 hs_correct_plug_work_nogpio);
7645 codec = tabla->codec;
7646
7647 /* Make sure the MBHC mux is connected to MIC Path */
7648 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
7649
7650 /* setup for microphone polling */
7651 tabla_turn_onoff_override(codec, true);
7652 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
7653
7654 timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS);
7655 while (!time_after(jiffies, timeout)) {
7656 ++retry;
7657
7658 msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS);
7659 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
7660 plug_type = tabla_codec_get_plug_type(codec, false);
7661 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
7662
7663 if (plug_type == PLUG_TYPE_HIGH_HPH
7664 || plug_type == PLUG_TYPE_INVALID) {
7665
7666 /* this means the plug is removed
7667 * End microphone polling and setup
7668 * for low power removal detection.
7669 */
7670 pr_debug("%s(): Plug may be removed, setup removal\n",
7671 __func__);
7672 break;
7673 } else if (plug_type == PLUG_TYPE_HEADSET) {
7674 /* Plug is corrected from headphone to headset,
7675 * report headset and end the polling
7676 */
7677 is_headset = true;
7678 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
7679 tabla_turn_onoff_override(codec, false);
7680 tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET);
7681 tabla_codec_start_hs_polling(codec);
7682 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
7683 pr_debug("%s(): corrected from headphone to headset\n",
7684 __func__);
7685 break;
7686 }
7687 }
7688
7689 /* Undo setup for microphone polling depending
7690 * result from polling
7691 */
7692 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
7693 if (!is_headset) {
Bhalchandra Gajareafc86432012-08-23 13:44:07 -07007694 pr_debug("%s: Inserted headphone is not a headset\n",
7695 __func__);
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007696 tabla_turn_onoff_override(codec, false);
7697 tabla_codec_cleanup_hs_polling(codec);
7698 tabla_codec_enable_hs_detect(codec, 0, 0, false);
7699 }
7700 wcd9xxx_unlock_sleep(codec->control_data);
7701}
7702
Joonwoo Park1305bab2012-05-21 15:08:42 -07007703static int tabla_mbhc_init_and_calibrate(struct tabla_priv *tabla)
7704{
7705 int ret = 0;
7706 struct snd_soc_codec *codec = tabla->codec;
7707
7708 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
7709 tabla_mbhc_init(codec);
7710 tabla_mbhc_cal(codec);
7711 tabla_mbhc_calc_thres(codec);
7712 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
7713 tabla_codec_calibrate_hs_polling(codec);
7714 if (!tabla->mbhc_cfg.gpio) {
Bhalchandra Gajareac0bddf2012-04-06 12:33:54 -07007715 INIT_WORK(&tabla->hs_correct_plug_work_nogpio,
7716 tabla_hs_correct_plug_nogpio);
Joonwoo Park1305bab2012-05-21 15:08:42 -07007717 ret = tabla_codec_enable_hs_detect(codec, 1,
7718 MBHC_USE_MB_TRIGGER |
7719 MBHC_USE_HPHL_TRIGGER,
7720 false);
7721
7722 if (IS_ERR_VALUE(ret))
7723 pr_err("%s: Failed to setup MBHC detection\n",
7724 __func__);
7725 } else {
7726 /* Enable Mic Bias pull down and HPH Switch to GND */
7727 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg,
7728 0x01, 0x01);
7729 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x01);
7730 INIT_WORK(&tabla->hs_correct_plug_work,
7731 tabla_hs_correct_gpio_plug);
7732 }
7733
7734 if (!IS_ERR_VALUE(ret)) {
7735 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10);
7736 wcd9xxx_enable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007737 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Joonwoo Park1305bab2012-05-21 15:08:42 -07007738 wcd9xxx_enable_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07007739 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Joonwoo Park1305bab2012-05-21 15:08:42 -07007740
7741 if (tabla->mbhc_cfg.gpio) {
7742 ret = request_threaded_irq(tabla->mbhc_cfg.gpio_irq,
7743 NULL,
7744 tabla_mechanical_plug_detect_irq,
7745 (IRQF_TRIGGER_RISING |
7746 IRQF_TRIGGER_FALLING),
7747 "tabla-gpio", codec);
7748 if (!IS_ERR_VALUE(ret)) {
7749 ret = enable_irq_wake(tabla->mbhc_cfg.gpio_irq);
7750 /* Bootup time detection */
7751 tabla_hs_gpio_handler(codec);
7752 }
7753 }
7754 }
7755
7756 return ret;
7757}
7758
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007759static void mbhc_fw_read(struct work_struct *work)
7760{
7761 struct delayed_work *dwork;
7762 struct tabla_priv *tabla;
7763 struct snd_soc_codec *codec;
7764 const struct firmware *fw;
Joonwoo Park1305bab2012-05-21 15:08:42 -07007765 int ret = -1, retry = 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007766
7767 dwork = to_delayed_work(work);
Joonwoo Park1305bab2012-05-21 15:08:42 -07007768 tabla = container_of(dwork, struct tabla_priv, mbhc_firmware_dwork);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007769 codec = tabla->codec;
7770
7771 while (retry < MBHC_FW_READ_ATTEMPTS) {
7772 retry++;
7773 pr_info("%s:Attempt %d to request MBHC firmware\n",
7774 __func__, retry);
7775 ret = request_firmware(&fw, "wcd9310/wcd9310_mbhc.bin",
7776 codec->dev);
7777
7778 if (ret != 0) {
7779 usleep_range(MBHC_FW_READ_TIMEOUT,
Joonwoo Park1305bab2012-05-21 15:08:42 -07007780 MBHC_FW_READ_TIMEOUT);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007781 } else {
7782 pr_info("%s: MBHC Firmware read succesful\n", __func__);
7783 break;
7784 }
7785 }
7786
7787 if (ret != 0) {
7788 pr_err("%s: Cannot load MBHC firmware use default cal\n",
7789 __func__);
7790 } else if (tabla_mbhc_fw_validate(fw) == false) {
7791 pr_err("%s: Invalid MBHC cal data size use default cal\n",
7792 __func__);
7793 release_firmware(fw);
7794 } else {
7795 tabla->mbhc_cfg.calibration = (void *)fw->data;
7796 tabla->mbhc_fw = fw;
7797 }
7798
Joonwoo Park1305bab2012-05-21 15:08:42 -07007799 (void) tabla_mbhc_init_and_calibrate(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007800}
7801
Joonwoo Park03324832012-03-19 19:36:16 -07007802int tabla_hs_detect(struct snd_soc_codec *codec,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007803 const struct tabla_mbhc_config *cfg)
Joonwoo Park03324832012-03-19 19:36:16 -07007804{
7805 struct tabla_priv *tabla;
7806 int rc = 0;
7807
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007808 if (!codec || !cfg->calibration) {
Joonwoo Park03324832012-03-19 19:36:16 -07007809 pr_err("Error: no codec or calibration\n");
7810 return -EINVAL;
7811 }
7812
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007813 if (cfg->mclk_rate != TABLA_MCLK_RATE_12288KHZ) {
7814 if (cfg->mclk_rate == TABLA_MCLK_RATE_9600KHZ)
Joonwoo Park03324832012-03-19 19:36:16 -07007815 pr_err("Error: clock rate %dHz is not yet supported\n",
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007816 cfg->mclk_rate);
Joonwoo Park03324832012-03-19 19:36:16 -07007817 else
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007818 pr_err("Error: unsupported clock rate %d\n",
7819 cfg->mclk_rate);
Joonwoo Park03324832012-03-19 19:36:16 -07007820 return -EINVAL;
7821 }
7822
7823 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007824 tabla->mbhc_cfg = *cfg;
7825 tabla->in_gpio_handler = false;
7826 tabla->current_plug = PLUG_TYPE_NONE;
7827 tabla->lpi_enabled = false;
Joonwoo Park03324832012-03-19 19:36:16 -07007828 tabla_get_mbhc_micbias_regs(codec, &tabla->mbhc_bias_regs);
7829
7830 /* Put CFILT in fast mode by default */
7831 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl,
7832 0x40, TABLA_CFILT_FAST_MODE);
7833 INIT_DELAYED_WORK(&tabla->mbhc_firmware_dwork, mbhc_fw_read);
7834 INIT_DELAYED_WORK(&tabla->mbhc_btn_dwork, btn_lpress_fn);
7835 INIT_WORK(&tabla->hphlocp_work, hphlocp_off_report);
7836 INIT_WORK(&tabla->hphrocp_work, hphrocp_off_report);
7837 INIT_DELAYED_WORK(&tabla->mbhc_insert_dwork, mbhc_insert_work);
7838
Joonwoo Park1305bab2012-05-21 15:08:42 -07007839 if (!tabla->mbhc_cfg.read_fw_bin)
7840 rc = tabla_mbhc_init_and_calibrate(tabla);
7841 else
Joonwoo Park03324832012-03-19 19:36:16 -07007842 schedule_delayed_work(&tabla->mbhc_firmware_dwork,
7843 usecs_to_jiffies(MBHC_FW_READ_TIMEOUT));
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007844
Joonwoo Park03324832012-03-19 19:36:16 -07007845 return rc;
7846}
7847EXPORT_SYMBOL_GPL(tabla_hs_detect);
7848
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007849static irqreturn_t tabla_slimbus_irq(int irq, void *data)
7850{
7851 struct tabla_priv *priv = data;
7852 struct snd_soc_codec *codec = priv->codec;
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07007853 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
7854 int i, j, port_id, k, ch_mask_temp;
Swaminathan Sathappan4bd38942012-07-17 11:31:31 -07007855 unsigned long slimbus_value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007856 u8 val;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307857 for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) {
7858 slimbus_value = wcd9xxx_interface_reg_read(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007859 TABLA_SLIM_PGD_PORT_INT_STATUS0 + i);
7860 for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307861 val = wcd9xxx_interface_reg_read(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007862 TABLA_SLIM_PGD_PORT_INT_SOURCE0 + i*8 + j);
7863 if (val & 0x1)
7864 pr_err_ratelimited("overflow error on port %x,"
7865 " value %x\n", i*8 + j, val);
7866 if (val & 0x2)
7867 pr_err_ratelimited("underflow error on port %x,"
7868 " value %x\n", i*8 + j, val);
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07007869 if (val & 0x4) {
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07007870 port_id = i*8 + j;
7871 for (k = 0; k < ARRAY_SIZE(tabla_dai); k++) {
7872 ch_mask_temp = 1 << port_id;
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08007873 pr_debug("%s: tabla_p->dai[%d].ch_mask = 0x%lx\n",
Kuirong Wang906ac472012-07-09 12:54:44 -07007874 __func__, k,
7875 tabla_p->dai[k].ch_mask);
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07007876 if (ch_mask_temp &
7877 tabla_p->dai[k].ch_mask) {
7878 tabla_p->dai[k].ch_mask &=
Kuirong Wang906ac472012-07-09 12:54:44 -07007879 ~ch_mask_temp;
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07007880 if (!tabla_p->dai[k].ch_mask)
Kuirong Wang906ac472012-07-09 12:54:44 -07007881 wake_up(
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07007882 &tabla_p->dai[k].dai_wait);
7883 }
7884 }
7885 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007886 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307887 wcd9xxx_interface_reg_write(codec->control_data,
Swaminathan Sathappan4bd38942012-07-17 11:31:31 -07007888 TABLA_SLIM_PGD_PORT_INT_CLR0 + i, slimbus_value);
7889 val = 0x0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007890 }
7891
7892 return IRQ_HANDLED;
7893}
7894
Patrick Lai3043fba2011-08-01 14:15:57 -07007895static int tabla_handle_pdata(struct tabla_priv *tabla)
7896{
7897 struct snd_soc_codec *codec = tabla->codec;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307898 struct wcd9xxx_pdata *pdata = tabla->pdata;
Patrick Lai3043fba2011-08-01 14:15:57 -07007899 int k1, k2, k3, rc = 0;
Santosh Mardi22920282011-10-26 02:38:40 +05307900 u8 leg_mode = pdata->amic_settings.legacy_mode;
7901 u8 txfe_bypass = pdata->amic_settings.txfe_enable;
7902 u8 txfe_buff = pdata->amic_settings.txfe_buff;
7903 u8 flag = pdata->amic_settings.use_pdata;
7904 u8 i = 0, j = 0;
7905 u8 val_txfe = 0, value = 0;
Patrick Lai3043fba2011-08-01 14:15:57 -07007906
7907 if (!pdata) {
7908 rc = -ENODEV;
7909 goto done;
7910 }
7911
7912 /* Make sure settings are correct */
7913 if ((pdata->micbias.ldoh_v > TABLA_LDOH_2P85_V) ||
7914 (pdata->micbias.bias1_cfilt_sel > TABLA_CFILT3_SEL) ||
7915 (pdata->micbias.bias2_cfilt_sel > TABLA_CFILT3_SEL) ||
7916 (pdata->micbias.bias3_cfilt_sel > TABLA_CFILT3_SEL) ||
7917 (pdata->micbias.bias4_cfilt_sel > TABLA_CFILT3_SEL)) {
7918 rc = -EINVAL;
7919 goto done;
7920 }
7921
7922 /* figure out k value */
7923 k1 = tabla_find_k_value(pdata->micbias.ldoh_v,
7924 pdata->micbias.cfilt1_mv);
7925 k2 = tabla_find_k_value(pdata->micbias.ldoh_v,
7926 pdata->micbias.cfilt2_mv);
7927 k3 = tabla_find_k_value(pdata->micbias.ldoh_v,
7928 pdata->micbias.cfilt3_mv);
7929
7930 if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) {
7931 rc = -EINVAL;
7932 goto done;
7933 }
7934
7935 /* Set voltage level and always use LDO */
7936 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x0C,
7937 (pdata->micbias.ldoh_v << 2));
7938
7939 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_1_VAL, 0xFC,
7940 (k1 << 2));
7941 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_2_VAL, 0xFC,
7942 (k2 << 2));
7943 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_3_VAL, 0xFC,
7944 (k3 << 2));
7945
7946 snd_soc_update_bits(codec, TABLA_A_MICB_1_CTL, 0x60,
7947 (pdata->micbias.bias1_cfilt_sel << 5));
7948 snd_soc_update_bits(codec, TABLA_A_MICB_2_CTL, 0x60,
7949 (pdata->micbias.bias2_cfilt_sel << 5));
7950 snd_soc_update_bits(codec, TABLA_A_MICB_3_CTL, 0x60,
7951 (pdata->micbias.bias3_cfilt_sel << 5));
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007952 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_ctl, 0x60,
7953 (pdata->micbias.bias4_cfilt_sel << 5));
Patrick Lai3043fba2011-08-01 14:15:57 -07007954
Santosh Mardi22920282011-10-26 02:38:40 +05307955 for (i = 0; i < 6; j++, i += 2) {
7956 if (flag & (0x01 << i)) {
7957 value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00;
7958 val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00;
7959 val_txfe = val_txfe |
7960 ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00);
7961 snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10,
7962 0x10, value);
7963 snd_soc_update_bits(codec,
7964 TABLA_A_TX_1_2_TEST_EN + j * 10,
7965 0x30, val_txfe);
7966 }
7967 if (flag & (0x01 << (i + 1))) {
7968 value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00;
7969 val_txfe = (txfe_bypass &
7970 (0x01 << (i + 1))) ? 0x02 : 0x00;
7971 val_txfe |= (txfe_buff &
7972 (0x01 << (i + 1))) ? 0x01 : 0x00;
7973 snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10,
7974 0x01, value);
7975 snd_soc_update_bits(codec,
7976 TABLA_A_TX_1_2_TEST_EN + j * 10,
7977 0x03, val_txfe);
7978 }
7979 }
7980 if (flag & 0x40) {
7981 value = (leg_mode & 0x40) ? 0x10 : 0x00;
7982 value = value | ((txfe_bypass & 0x40) ? 0x02 : 0x00);
7983 value = value | ((txfe_buff & 0x40) ? 0x01 : 0x00);
7984 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN,
7985 0x13, value);
7986 }
Patrick Lai49efeac2011-11-03 11:01:12 -07007987
7988 if (pdata->ocp.use_pdata) {
7989 /* not defined in CODEC specification */
7990 if (pdata->ocp.hph_ocp_limit == 1 ||
7991 pdata->ocp.hph_ocp_limit == 5) {
7992 rc = -EINVAL;
7993 goto done;
7994 }
7995 snd_soc_update_bits(codec, TABLA_A_RX_COM_OCP_CTL,
7996 0x0F, pdata->ocp.num_attempts);
7997 snd_soc_write(codec, TABLA_A_RX_COM_OCP_COUNT,
7998 ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time));
7999 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL,
8000 0xE0, (pdata->ocp.hph_ocp_limit << 5));
8001 }
Joonwoo Park03324832012-03-19 19:36:16 -07008002
8003 for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
8004 if (!strncmp(pdata->regulator[i].name, "CDC_VDDA_RX", 11)) {
8005 if (pdata->regulator[i].min_uV == 1800000 &&
8006 pdata->regulator[i].max_uV == 1800000) {
8007 snd_soc_write(codec, TABLA_A_BIAS_REF_CTL,
8008 0x1C);
8009 } else if (pdata->regulator[i].min_uV == 2200000 &&
8010 pdata->regulator[i].max_uV == 2200000) {
8011 snd_soc_write(codec, TABLA_A_BIAS_REF_CTL,
8012 0x1E);
8013 } else {
8014 pr_err("%s: unsupported CDC_VDDA_RX voltage "
8015 "min %d, max %d\n", __func__,
8016 pdata->regulator[i].min_uV,
8017 pdata->regulator[i].max_uV);
8018 rc = -EINVAL;
8019 }
8020 break;
8021 }
8022 }
Patrick Lai3043fba2011-08-01 14:15:57 -07008023done:
8024 return rc;
8025}
8026
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008027static const struct tabla_reg_mask_val tabla_1_1_reg_defaults[] = {
8028
8029 /* Tabla 1.1 MICBIAS changes */
8030 TABLA_REG_VAL(TABLA_A_MICB_1_INT_RBIAS, 0x24),
8031 TABLA_REG_VAL(TABLA_A_MICB_2_INT_RBIAS, 0x24),
8032 TABLA_REG_VAL(TABLA_A_MICB_3_INT_RBIAS, 0x24),
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008033
8034 /* Tabla 1.1 HPH changes */
8035 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_PA, 0x57),
8036 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_LDO, 0x56),
8037
8038 /* Tabla 1.1 EAR PA changes */
8039 TABLA_REG_VAL(TABLA_A_RX_EAR_BIAS_PA, 0xA6),
8040 TABLA_REG_VAL(TABLA_A_RX_EAR_GAIN, 0x02),
8041 TABLA_REG_VAL(TABLA_A_RX_EAR_VCM, 0x03),
8042
8043 /* Tabla 1.1 Lineout_5 Changes */
8044 TABLA_REG_VAL(TABLA_A_RX_LINE_5_GAIN, 0x10),
8045
8046 /* Tabla 1.1 RX Changes */
8047 TABLA_REG_VAL(TABLA_A_CDC_RX1_B5_CTL, 0x78),
8048 TABLA_REG_VAL(TABLA_A_CDC_RX2_B5_CTL, 0x78),
8049 TABLA_REG_VAL(TABLA_A_CDC_RX3_B5_CTL, 0x78),
8050 TABLA_REG_VAL(TABLA_A_CDC_RX4_B5_CTL, 0x78),
8051 TABLA_REG_VAL(TABLA_A_CDC_RX5_B5_CTL, 0x78),
8052 TABLA_REG_VAL(TABLA_A_CDC_RX6_B5_CTL, 0x78),
8053 TABLA_REG_VAL(TABLA_A_CDC_RX7_B5_CTL, 0x78),
8054
8055 /* Tabla 1.1 RX1 and RX2 Changes */
8056 TABLA_REG_VAL(TABLA_A_CDC_RX1_B6_CTL, 0xA0),
8057 TABLA_REG_VAL(TABLA_A_CDC_RX2_B6_CTL, 0xA0),
8058
8059 /* Tabla 1.1 RX3 to RX7 Changes */
8060 TABLA_REG_VAL(TABLA_A_CDC_RX3_B6_CTL, 0x80),
8061 TABLA_REG_VAL(TABLA_A_CDC_RX4_B6_CTL, 0x80),
8062 TABLA_REG_VAL(TABLA_A_CDC_RX5_B6_CTL, 0x80),
8063 TABLA_REG_VAL(TABLA_A_CDC_RX6_B6_CTL, 0x80),
8064 TABLA_REG_VAL(TABLA_A_CDC_RX7_B6_CTL, 0x80),
8065
8066 /* Tabla 1.1 CLASSG Changes */
8067 TABLA_REG_VAL(TABLA_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B),
8068};
8069
8070static const struct tabla_reg_mask_val tabla_2_0_reg_defaults[] = {
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008071 /* Tabla 2.0 MICBIAS changes */
8072 TABLA_REG_VAL(TABLA_A_MICB_2_MBHC, 0x02),
8073};
8074
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008075static const struct tabla_reg_mask_val tabla_1_x_only_reg_2_0_defaults[] = {
8076 TABLA_REG_VAL(TABLA_1_A_MICB_4_INT_RBIAS, 0x24),
8077};
8078
8079static const struct tabla_reg_mask_val tabla_2_only_reg_2_0_defaults[] = {
8080 TABLA_REG_VAL(TABLA_2_A_MICB_4_INT_RBIAS, 0x24),
8081};
8082
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008083static void tabla_update_reg_defaults(struct snd_soc_codec *codec)
8084{
8085 u32 i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308086 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008087
8088 for (i = 0; i < ARRAY_SIZE(tabla_1_1_reg_defaults); i++)
8089 snd_soc_write(codec, tabla_1_1_reg_defaults[i].reg,
8090 tabla_1_1_reg_defaults[i].val);
8091
8092 for (i = 0; i < ARRAY_SIZE(tabla_2_0_reg_defaults); i++)
8093 snd_soc_write(codec, tabla_2_0_reg_defaults[i].reg,
8094 tabla_2_0_reg_defaults[i].val);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008095
8096 if (TABLA_IS_1_X(tabla_core->version)) {
8097 for (i = 0; i < ARRAY_SIZE(tabla_1_x_only_reg_2_0_defaults);
8098 i++)
8099 snd_soc_write(codec,
8100 tabla_1_x_only_reg_2_0_defaults[i].reg,
8101 tabla_1_x_only_reg_2_0_defaults[i].val);
8102 } else {
8103 for (i = 0; i < ARRAY_SIZE(tabla_2_only_reg_2_0_defaults); i++)
8104 snd_soc_write(codec,
8105 tabla_2_only_reg_2_0_defaults[i].reg,
8106 tabla_2_only_reg_2_0_defaults[i].val);
8107 }
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008108}
8109
8110static const struct tabla_reg_mask_val tabla_codec_reg_init_val[] = {
Patrick Laic7cae882011-11-18 11:52:49 -08008111 /* Initialize current threshold to 350MA
8112 * number of wait and run cycles to 4096
8113 */
Patrick Lai49efeac2011-11-03 11:01:12 -07008114 {TABLA_A_RX_HPH_OCP_CTL, 0xE0, 0x60},
Patrick Laic7cae882011-11-18 11:52:49 -08008115 {TABLA_A_RX_COM_OCP_COUNT, 0xFF, 0xFF},
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008116
Santosh Mardi32171012011-10-28 23:32:06 +05308117 {TABLA_A_QFUSE_CTL, 0xFF, 0x03},
8118
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008119 /* Initialize gain registers to use register gain */
8120 {TABLA_A_RX_HPH_L_GAIN, 0x10, 0x10},
8121 {TABLA_A_RX_HPH_R_GAIN, 0x10, 0x10},
8122 {TABLA_A_RX_LINE_1_GAIN, 0x10, 0x10},
8123 {TABLA_A_RX_LINE_2_GAIN, 0x10, 0x10},
8124 {TABLA_A_RX_LINE_3_GAIN, 0x10, 0x10},
8125 {TABLA_A_RX_LINE_4_GAIN, 0x10, 0x10},
8126
Kuirong Wangccb29c62012-06-15 11:09:07 -07008127 /* Set the MICBIAS default output as pull down*/
8128 {TABLA_A_MICB_1_CTL, 0x01, 0x01},
8129 {TABLA_A_MICB_2_CTL, 0x01, 0x01},
8130 {TABLA_A_MICB_3_CTL, 0x01, 0x01},
8131
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008132 /* Initialize mic biases to differential mode */
8133 {TABLA_A_MICB_1_INT_RBIAS, 0x24, 0x24},
8134 {TABLA_A_MICB_2_INT_RBIAS, 0x24, 0x24},
8135 {TABLA_A_MICB_3_INT_RBIAS, 0x24, 0x24},
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008136
8137 {TABLA_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14},
8138
8139 /* Use 16 bit sample size for TX1 to TX6 */
8140 {TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20},
8141 {TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20},
8142 {TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20},
8143 {TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20},
8144 {TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20},
8145 {TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0x30, 0x20},
8146
8147 /* Use 16 bit sample size for TX7 to TX10 */
8148 {TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0x60, 0x40},
8149 {TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0x60, 0x40},
8150 {TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0x60, 0x40},
8151 {TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0x60, 0x40},
8152
8153 /* Use 16 bit sample size for RX */
8154 {TABLA_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA},
8155 {TABLA_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0xAA},
8156
8157 /*enable HPF filter for TX paths */
8158 {TABLA_A_CDC_TX1_MUX_CTL, 0x8, 0x0},
8159 {TABLA_A_CDC_TX2_MUX_CTL, 0x8, 0x0},
8160 {TABLA_A_CDC_TX3_MUX_CTL, 0x8, 0x0},
8161 {TABLA_A_CDC_TX4_MUX_CTL, 0x8, 0x0},
8162 {TABLA_A_CDC_TX5_MUX_CTL, 0x8, 0x0},
8163 {TABLA_A_CDC_TX6_MUX_CTL, 0x8, 0x0},
8164 {TABLA_A_CDC_TX7_MUX_CTL, 0x8, 0x0},
8165 {TABLA_A_CDC_TX8_MUX_CTL, 0x8, 0x0},
8166 {TABLA_A_CDC_TX9_MUX_CTL, 0x8, 0x0},
8167 {TABLA_A_CDC_TX10_MUX_CTL, 0x8, 0x0},
Kiran Kandi0ba468f2012-05-08 11:45:05 -07008168
8169 /* config Decimator for DMIC CLK_MODE_1(3.072Mhz@12.88Mhz mclk) */
8170 {TABLA_A_CDC_TX1_DMIC_CTL, 0x1, 0x1},
8171 {TABLA_A_CDC_TX2_DMIC_CTL, 0x1, 0x1},
8172 {TABLA_A_CDC_TX3_DMIC_CTL, 0x1, 0x1},
8173 {TABLA_A_CDC_TX4_DMIC_CTL, 0x1, 0x1},
8174 {TABLA_A_CDC_TX5_DMIC_CTL, 0x1, 0x1},
8175 {TABLA_A_CDC_TX6_DMIC_CTL, 0x1, 0x1},
8176 {TABLA_A_CDC_TX7_DMIC_CTL, 0x1, 0x1},
8177 {TABLA_A_CDC_TX8_DMIC_CTL, 0x1, 0x1},
8178 {TABLA_A_CDC_TX9_DMIC_CTL, 0x1, 0x1},
8179 {TABLA_A_CDC_TX10_DMIC_CTL, 0x1, 0x1},
8180
8181 /* config DMIC clk to CLK_MODE_1 (3.072Mhz@12.88Mhz mclk) */
8182 {TABLA_A_CDC_CLK_DMIC_CTL, 0x2A, 0x2A},
8183
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008184};
8185
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008186static const struct tabla_reg_mask_val tabla_1_x_codec_reg_init_val[] = {
Kuirong Wangccb29c62012-06-15 11:09:07 -07008187 /* Set the MICBIAS default output as pull down*/
8188 {TABLA_1_A_MICB_4_CTL, 0x01, 0x01},
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008189 /* Initialize mic biases to differential mode */
8190 {TABLA_1_A_MICB_4_INT_RBIAS, 0x24, 0x24},
8191};
8192
8193static const struct tabla_reg_mask_val tabla_2_higher_codec_reg_init_val[] = {
Kuirong Wangccb29c62012-06-15 11:09:07 -07008194
8195 /* Set the MICBIAS default output as pull down*/
8196 {TABLA_2_A_MICB_4_CTL, 0x01, 0x01},
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008197 /* Initialize mic biases to differential mode */
8198 {TABLA_2_A_MICB_4_INT_RBIAS, 0x24, 0x24},
8199};
8200
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008201static void tabla_codec_init_reg(struct snd_soc_codec *codec)
8202{
8203 u32 i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308204 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008205
8206 for (i = 0; i < ARRAY_SIZE(tabla_codec_reg_init_val); i++)
8207 snd_soc_update_bits(codec, tabla_codec_reg_init_val[i].reg,
8208 tabla_codec_reg_init_val[i].mask,
8209 tabla_codec_reg_init_val[i].val);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008210 if (TABLA_IS_1_X(tabla_core->version)) {
8211 for (i = 0; i < ARRAY_SIZE(tabla_1_x_codec_reg_init_val); i++)
8212 snd_soc_update_bits(codec,
8213 tabla_1_x_codec_reg_init_val[i].reg,
8214 tabla_1_x_codec_reg_init_val[i].mask,
8215 tabla_1_x_codec_reg_init_val[i].val);
8216 } else {
8217 for (i = 0; i < ARRAY_SIZE(tabla_2_higher_codec_reg_init_val);
8218 i++)
8219 snd_soc_update_bits(codec,
8220 tabla_2_higher_codec_reg_init_val[i].reg,
8221 tabla_2_higher_codec_reg_init_val[i].mask,
8222 tabla_2_higher_codec_reg_init_val[i].val);
8223 }
8224}
8225
8226static void tabla_update_reg_address(struct tabla_priv *priv)
8227{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308228 struct wcd9xxx *tabla_core = dev_get_drvdata(priv->codec->dev->parent);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008229 struct tabla_reg_address *reg_addr = &priv->reg_addr;
8230
8231 if (TABLA_IS_1_X(tabla_core->version)) {
Joonwoo Parkcb7c8922012-02-16 23:12:59 -08008232 reg_addr->micb_4_mbhc = TABLA_1_A_MICB_4_MBHC;
8233 reg_addr->micb_4_int_rbias = TABLA_1_A_MICB_4_INT_RBIAS;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008234 reg_addr->micb_4_ctl = TABLA_1_A_MICB_4_CTL;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008235 } else if (TABLA_IS_2_0(tabla_core->version)) {
Joonwoo Parkcb7c8922012-02-16 23:12:59 -08008236 reg_addr->micb_4_mbhc = TABLA_2_A_MICB_4_MBHC;
8237 reg_addr->micb_4_int_rbias = TABLA_2_A_MICB_4_INT_RBIAS;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008238 reg_addr->micb_4_ctl = TABLA_2_A_MICB_4_CTL;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008239 }
Kiran Kandi1f6fd722011-08-11 10:36:11 -07008240}
8241
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008242#ifdef CONFIG_DEBUG_FS
8243static int codec_debug_open(struct inode *inode, struct file *file)
8244{
8245 file->private_data = inode->i_private;
8246 return 0;
8247}
8248
8249static ssize_t codec_debug_write(struct file *filp,
8250 const char __user *ubuf, size_t cnt, loff_t *ppos)
8251{
8252 char lbuf[32];
8253 char *buf;
8254 int rc;
8255 struct tabla_priv *tabla = filp->private_data;
8256
8257 if (cnt > sizeof(lbuf) - 1)
8258 return -EINVAL;
8259
8260 rc = copy_from_user(lbuf, ubuf, cnt);
8261 if (rc)
8262 return -EFAULT;
8263
8264 lbuf[cnt] = '\0';
8265 buf = (char *)lbuf;
Joonwoo Park5bbcb0c2012-08-07 17:25:52 -07008266 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
8267 tabla->no_mic_headset_override =
8268 (*strsep(&buf, " ") == '0') ? false : true;
8269 if (tabla->no_mic_headset_override && tabla->mbhc_polling_active) {
8270 tabla_codec_pause_hs_polling(tabla->codec);
8271 tabla_codec_start_hs_polling(tabla->codec);
8272 }
8273 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
8274 return cnt;
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008275}
8276
8277static ssize_t codec_mbhc_debug_read(struct file *file, char __user *buf,
8278 size_t count, loff_t *pos)
8279{
8280 const int size = 768;
8281 char buffer[size];
8282 int n = 0;
8283 struct tabla_priv *tabla = file->private_data;
8284 struct snd_soc_codec *codec = tabla->codec;
8285 const struct mbhc_internal_cal_data *p = &tabla->mbhc_data;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008286 const s16 v_ins_hu_cur = tabla_get_current_v_ins(tabla, true);
8287 const s16 v_ins_h_cur = tabla_get_current_v_ins(tabla, false);
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008288
8289 n = scnprintf(buffer, size - n, "dce_z = %x(%dmv)\n", p->dce_z,
8290 tabla_codec_sta_dce_v(codec, 1, p->dce_z));
8291 n += scnprintf(buffer + n, size - n, "dce_mb = %x(%dmv)\n",
8292 p->dce_mb, tabla_codec_sta_dce_v(codec, 1, p->dce_mb));
8293 n += scnprintf(buffer + n, size - n, "sta_z = %x(%dmv)\n",
8294 p->sta_z, tabla_codec_sta_dce_v(codec, 0, p->sta_z));
8295 n += scnprintf(buffer + n, size - n, "sta_mb = %x(%dmv)\n",
8296 p->sta_mb, tabla_codec_sta_dce_v(codec, 0, p->sta_mb));
8297 n += scnprintf(buffer + n, size - n, "t_dce = %x\n", p->t_dce);
8298 n += scnprintf(buffer + n, size - n, "t_sta = %x\n", p->t_sta);
8299 n += scnprintf(buffer + n, size - n, "micb_mv = %dmv\n",
8300 p->micb_mv);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008301 n += scnprintf(buffer + n, size - n, "v_ins_hu = %x(%dmv)%s\n",
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008302 p->v_ins_hu,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008303 tabla_codec_sta_dce_v(codec, 0, p->v_ins_hu),
8304 p->v_ins_hu == v_ins_hu_cur ? "*" : "");
8305 n += scnprintf(buffer + n, size - n, "v_ins_h = %x(%dmv)%s\n",
8306 p->v_ins_h, tabla_codec_sta_dce_v(codec, 1, p->v_ins_h),
8307 p->v_ins_h == v_ins_h_cur ? "*" : "");
8308 n += scnprintf(buffer + n, size - n, "adj_v_ins_hu = %x(%dmv)%s\n",
8309 p->adj_v_ins_hu,
8310 tabla_codec_sta_dce_v(codec, 0, p->adj_v_ins_hu),
8311 p->adj_v_ins_hu == v_ins_hu_cur ? "*" : "");
8312 n += scnprintf(buffer + n, size - n, "adj_v_ins_h = %x(%dmv)%s\n",
8313 p->adj_v_ins_h,
8314 tabla_codec_sta_dce_v(codec, 1, p->adj_v_ins_h),
8315 p->adj_v_ins_h == v_ins_h_cur ? "*" : "");
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008316 n += scnprintf(buffer + n, size - n, "v_b1_hu = %x(%dmv)\n",
8317 p->v_b1_hu, tabla_codec_sta_dce_v(codec, 0, p->v_b1_hu));
8318 n += scnprintf(buffer + n, size - n, "v_b1_h = %x(%dmv)\n",
8319 p->v_b1_h, tabla_codec_sta_dce_v(codec, 1, p->v_b1_h));
8320 n += scnprintf(buffer + n, size - n, "v_b1_huc = %x(%dmv)\n",
8321 p->v_b1_huc,
8322 tabla_codec_sta_dce_v(codec, 1, p->v_b1_huc));
8323 n += scnprintf(buffer + n, size - n, "v_brh = %x(%dmv)\n",
8324 p->v_brh, tabla_codec_sta_dce_v(codec, 1, p->v_brh));
8325 n += scnprintf(buffer + n, size - n, "v_brl = %x(%dmv)\n", p->v_brl,
8326 tabla_codec_sta_dce_v(codec, 0, p->v_brl));
8327 n += scnprintf(buffer + n, size - n, "v_no_mic = %x(%dmv)\n",
8328 p->v_no_mic,
8329 tabla_codec_sta_dce_v(codec, 0, p->v_no_mic));
8330 n += scnprintf(buffer + n, size - n, "npoll = %d\n", p->npoll);
8331 n += scnprintf(buffer + n, size - n, "nbounce_wait = %d\n",
8332 p->nbounce_wait);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07008333 n += scnprintf(buffer + n, size - n, "v_inval_ins_low = %d\n",
8334 p->v_inval_ins_low);
8335 n += scnprintf(buffer + n, size - n, "v_inval_ins_high = %d\n",
8336 p->v_inval_ins_high);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07008337 if (tabla->mbhc_cfg.gpio)
8338 n += scnprintf(buffer + n, size - n, "GPIO insert = %d\n",
8339 tabla_hs_gpio_level_remove(tabla));
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008340 buffer[n] = 0;
8341
8342 return simple_read_from_buffer(buf, count, pos, buffer, n);
8343}
8344
8345static const struct file_operations codec_debug_ops = {
8346 .open = codec_debug_open,
8347 .write = codec_debug_write,
8348};
8349
8350static const struct file_operations codec_mbhc_debug_ops = {
8351 .open = codec_debug_open,
8352 .read = codec_mbhc_debug_read,
8353};
8354#endif
8355
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008356static int tabla_codec_probe(struct snd_soc_codec *codec)
8357{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308358 struct wcd9xxx *control;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008359 struct tabla_priv *tabla;
8360 struct snd_soc_dapm_context *dapm = &codec->dapm;
8361 int ret = 0;
8362 int i;
Kuirong Wang906ac472012-07-09 12:54:44 -07008363 void *ptr = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008364
8365 codec->control_data = dev_get_drvdata(codec->dev->parent);
8366 control = codec->control_data;
8367
8368 tabla = kzalloc(sizeof(struct tabla_priv), GFP_KERNEL);
8369 if (!tabla) {
8370 dev_err(codec->dev, "Failed to allocate private data\n");
8371 return -ENOMEM;
8372 }
Kiran Kandid8cf5212012-03-02 15:34:53 -08008373 for (i = 0 ; i < NUM_DECIMATORS; i++) {
8374 tx_hpf_work[i].tabla = tabla;
8375 tx_hpf_work[i].decimator = i + 1;
8376 INIT_DELAYED_WORK(&tx_hpf_work[i].dwork,
8377 tx_hpf_corner_freq_callback);
8378 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008379
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07008380 /* Make sure mbhc micbias register addresses are zeroed out */
8381 memset(&tabla->mbhc_bias_regs, 0,
8382 sizeof(struct mbhc_micbias_regs));
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07008383 tabla->mbhc_micbias_switched = false;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07008384
Joonwoo Park0976d012011-12-22 11:48:18 -08008385 /* Make sure mbhc intenal calibration data is zeroed out */
8386 memset(&tabla->mbhc_data, 0,
8387 sizeof(struct mbhc_internal_cal_data));
Joonwoo Park433149a2012-01-11 09:53:54 -08008388 tabla->mbhc_data.t_sta_dce = DEFAULT_DCE_STA_WAIT;
Joonwoo Park0976d012011-12-22 11:48:18 -08008389 tabla->mbhc_data.t_dce = DEFAULT_DCE_WAIT;
8390 tabla->mbhc_data.t_sta = DEFAULT_STA_WAIT;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008391 snd_soc_codec_set_drvdata(codec, tabla);
8392
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07008393 tabla->mclk_enabled = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008394 tabla->bandgap_type = TABLA_BANDGAP_OFF;
8395 tabla->clock_active = false;
8396 tabla->config_mode_active = false;
8397 tabla->mbhc_polling_active = false;
Joonwoo Parkf4267c22012-01-10 13:25:24 -08008398 tabla->mbhc_fake_ins_start = 0;
Bradley Rubincb3950a2011-08-18 13:07:26 -07008399 tabla->no_mic_headset_override = false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008400 tabla->hs_polling_irq_prepared = false;
8401 mutex_init(&tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008402 tabla->codec = codec;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008403 tabla->mbhc_state = MBHC_STATE_NONE;
Joonwoo Park03324832012-03-19 19:36:16 -07008404 tabla->mbhc_last_resume = 0;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08008405 for (i = 0; i < COMPANDER_MAX; i++) {
8406 tabla->comp_enabled[i] = 0;
8407 tabla->comp_fs[i] = COMPANDER_FS_48KHZ;
8408 }
Patrick Lai3043fba2011-08-01 14:15:57 -07008409 tabla->pdata = dev_get_platdata(codec->dev->parent);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308410 tabla->intf_type = wcd9xxx_get_intf_type();
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08008411 tabla->aux_pga_cnt = 0;
8412 tabla->aux_l_gain = 0x1F;
8413 tabla->aux_r_gain = 0x1F;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008414 tabla_update_reg_address(tabla);
Santosh Mardi22920282011-10-26 02:38:40 +05308415 tabla_update_reg_defaults(codec);
8416 tabla_codec_init_reg(codec);
Santosh Mardi22920282011-10-26 02:38:40 +05308417 ret = tabla_handle_pdata(tabla);
Patrick Lai3043fba2011-08-01 14:15:57 -07008418 if (IS_ERR_VALUE(ret)) {
8419 pr_err("%s: bad pdata\n", __func__);
8420 goto err_pdata;
8421 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008422
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008423 if (TABLA_IS_1_X(control->version))
Steve Mucklef132c6c2012-06-06 18:30:57 -07008424 snd_soc_add_codec_controls(codec, tabla_1_x_snd_controls,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008425 ARRAY_SIZE(tabla_1_x_snd_controls));
8426 else
Steve Mucklef132c6c2012-06-06 18:30:57 -07008427 snd_soc_add_codec_controls(codec, tabla_2_higher_snd_controls,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008428 ARRAY_SIZE(tabla_2_higher_snd_controls));
8429
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008430 if (TABLA_IS_1_X(control->version))
8431 snd_soc_dapm_new_controls(dapm, tabla_1_x_dapm_widgets,
8432 ARRAY_SIZE(tabla_1_x_dapm_widgets));
8433 else
8434 snd_soc_dapm_new_controls(dapm, tabla_2_higher_dapm_widgets,
8435 ARRAY_SIZE(tabla_2_higher_dapm_widgets));
8436
Kuirong Wang906ac472012-07-09 12:54:44 -07008437
8438 ptr = kmalloc((sizeof(tabla_rx_chs) +
8439 sizeof(tabla_tx_chs)), GFP_KERNEL);
8440 if (!ptr) {
8441 pr_err("%s: no mem for slim chan ctl data\n", __func__);
8442 ret = -ENOMEM;
8443 goto err_nomem_slimch;
8444 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308445 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05308446 snd_soc_dapm_new_controls(dapm, tabla_dapm_i2s_widgets,
8447 ARRAY_SIZE(tabla_dapm_i2s_widgets));
8448 snd_soc_dapm_add_routes(dapm, audio_i2s_map,
8449 ARRAY_SIZE(audio_i2s_map));
Kuirong Wang906ac472012-07-09 12:54:44 -07008450 for (i = 0; i < ARRAY_SIZE(tabla_i2s_dai); i++)
8451 INIT_LIST_HEAD(&tabla->dai[i].wcd9xxx_ch_list);
8452 } else if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
8453 for (i = 0; i < NUM_CODEC_DAIS; i++) {
8454 INIT_LIST_HEAD(&tabla->dai[i].wcd9xxx_ch_list);
8455 init_waitqueue_head(&tabla->dai[i].dai_wait);
8456 }
Santosh Mardie15e2302011-11-15 10:39:23 +05308457 }
Kuirong Wang906ac472012-07-09 12:54:44 -07008458
8459 control->num_rx_port = TABLA_RX_MAX;
8460 control->rx_chs = ptr;
8461 memcpy(control->rx_chs, tabla_rx_chs, sizeof(tabla_rx_chs));
8462 control->num_tx_port = TABLA_TX_MAX;
8463 control->tx_chs = ptr + sizeof(tabla_rx_chs);
8464 memcpy(control->tx_chs, tabla_tx_chs, sizeof(tabla_tx_chs));
8465
Kiran Kandi8b3a8302011-09-27 16:13:28 -07008466
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008467 if (TABLA_IS_1_X(control->version)) {
Kiran Kandi7a9fd902011-11-14 13:51:45 -08008468 snd_soc_dapm_add_routes(dapm, tabla_1_x_lineout_2_to_4_map,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008469 ARRAY_SIZE(tabla_1_x_lineout_2_to_4_map));
8470 } else if (TABLA_IS_2_0(control->version)) {
Kiran Kandi7a9fd902011-11-14 13:51:45 -08008471 snd_soc_dapm_add_routes(dapm, tabla_2_x_lineout_2_to_4_map,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08008472 ARRAY_SIZE(tabla_2_x_lineout_2_to_4_map));
Kiran Kandi7a9fd902011-11-14 13:51:45 -08008473 } else {
8474 pr_err("%s : ERROR. Unsupported Tabla version 0x%2x\n",
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308475 __func__, control->version);
Kiran Kandi7a9fd902011-11-14 13:51:45 -08008476 goto err_pdata;
8477 }
8478
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008479 snd_soc_dapm_sync(dapm);
8480
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008481 ret = wcd9xxx_request_irq(codec->control_data,
8482 WCD9XXX_IRQ_MBHC_INSERTION,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008483 tabla_hs_insert_irq, "Headset insert detect", tabla);
8484 if (ret) {
8485 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008486 WCD9XXX_IRQ_MBHC_INSERTION);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008487 goto err_insert_irq;
8488 }
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008489 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008490
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008491 ret = wcd9xxx_request_irq(codec->control_data,
8492 WCD9XXX_IRQ_MBHC_REMOVAL,
8493 tabla_hs_remove_irq,
8494 "Headset remove detect", tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008495 if (ret) {
8496 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008497 WCD9XXX_IRQ_MBHC_REMOVAL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008498 goto err_remove_irq;
8499 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008500
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008501 ret = wcd9xxx_request_irq(codec->control_data,
8502 WCD9XXX_IRQ_MBHC_POTENTIAL,
8503 tabla_dce_handler, "DC Estimation detect",
8504 tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008505 if (ret) {
8506 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008507 WCD9XXX_IRQ_MBHC_POTENTIAL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008508 goto err_potential_irq;
8509 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008510
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008511 ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE,
8512 tabla_release_handler,
8513 "Button Release detect", tabla);
Bradley Rubincb1e2732011-06-23 16:49:20 -07008514 if (ret) {
8515 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008516 WCD9XXX_IRQ_MBHC_RELEASE);
Bradley Rubincb1e2732011-06-23 16:49:20 -07008517 goto err_release_irq;
8518 }
8519
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008520 ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS,
8521 tabla_slimbus_irq, "SLIMBUS Slave", tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008522 if (ret) {
8523 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008524 WCD9XXX_IRQ_SLIMBUS);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008525 goto err_slimbus_irq;
8526 }
8527
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308528 for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++)
8529 wcd9xxx_interface_reg_write(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008530 TABLA_SLIM_PGD_PORT_INT_EN0 + i, 0xFF);
8531
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308532 ret = wcd9xxx_request_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008533 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT,
8534 tabla_hphl_ocp_irq,
8535 "HPH_L OCP detect", tabla);
Patrick Lai49efeac2011-11-03 11:01:12 -07008536 if (ret) {
8537 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008538 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07008539 goto err_hphl_ocp_irq;
8540 }
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008541 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_HPH_PA_OCPL_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07008542
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308543 ret = wcd9xxx_request_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008544 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT,
8545 tabla_hphr_ocp_irq,
8546 "HPH_R OCP detect", tabla);
Patrick Lai49efeac2011-11-03 11:01:12 -07008547 if (ret) {
8548 pr_err("%s: Failed to request irq %d\n", __func__,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008549 WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07008550 goto err_hphr_ocp_irq;
8551 }
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008552 wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_HPH_PA_OCPR_FAULT);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07008553
8554 /*
8555 * Register suspend lock and notifier to resend edge triggered
8556 * gpio IRQs
8557 */
8558 wake_lock_init(&tabla->irq_resend_wlock, WAKE_LOCK_SUSPEND,
8559 "tabla_gpio_irq_resend");
8560 tabla->gpio_irq_resend = false;
8561
Patrick Lai49efeac2011-11-03 11:01:12 -07008562
Bradley Rubincb3950a2011-08-18 13:07:26 -07008563#ifdef CONFIG_DEBUG_FS
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008564 if (ret == 0) {
8565 tabla->debugfs_poke =
8566 debugfs_create_file("TRRS", S_IFREG | S_IRUGO, NULL, tabla,
8567 &codec_debug_ops);
8568 tabla->debugfs_mbhc =
8569 debugfs_create_file("tabla_mbhc", S_IFREG | S_IRUGO,
8570 NULL, tabla, &codec_mbhc_debug_ops);
8571 }
Bradley Rubincb3950a2011-08-18 13:07:26 -07008572#endif
Steve Mucklef132c6c2012-06-06 18:30:57 -07008573 codec->ignore_pmdown_time = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008574 return ret;
8575
Patrick Lai49efeac2011-11-03 11:01:12 -07008576err_hphr_ocp_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308577 wcd9xxx_free_irq(codec->control_data,
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008578 WCD9XXX_IRQ_HPH_PA_OCPL_FAULT, tabla);
Patrick Lai49efeac2011-11-03 11:01:12 -07008579err_hphl_ocp_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008580 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008581err_slimbus_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008582 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, tabla);
Bradley Rubincb1e2732011-06-23 16:49:20 -07008583err_release_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008584 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL,
8585 tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008586err_potential_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008587 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_REMOVAL, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008588err_remove_irq:
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008589 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION,
8590 tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008591err_insert_irq:
Patrick Lai3043fba2011-08-01 14:15:57 -07008592err_pdata:
Kuirong Wang906ac472012-07-09 12:54:44 -07008593 kfree(ptr);
8594err_nomem_slimch:
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008595 mutex_destroy(&tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008596 kfree(tabla);
8597 return ret;
8598}
8599static int tabla_codec_remove(struct snd_soc_codec *codec)
8600{
8601 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07008602
8603 wake_lock_destroy(&tabla->irq_resend_wlock);
8604
Joonwoo Parkf6574c72012-10-10 17:29:57 -07008605 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, tabla);
8606 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, tabla);
8607 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL,
8608 tabla);
8609 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_REMOVAL, tabla);
8610 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION,
8611 tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008612 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008613 tabla_codec_disable_clock_block(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008614 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008615 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF);
Patrick Lai64b43262011-12-06 17:29:15 -08008616 if (tabla->mbhc_fw)
8617 release_firmware(tabla->mbhc_fw);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07008618 mutex_destroy(&tabla->codec_resource_lock);
Joonwoo Park179b9ec2012-03-26 10:56:20 -07008619#ifdef CONFIG_DEBUG_FS
8620 debugfs_remove(tabla->debugfs_poke);
8621 debugfs_remove(tabla->debugfs_mbhc);
8622#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008623 kfree(tabla);
8624 return 0;
8625}
8626static struct snd_soc_codec_driver soc_codec_dev_tabla = {
8627 .probe = tabla_codec_probe,
8628 .remove = tabla_codec_remove,
8629 .read = tabla_read,
8630 .write = tabla_write,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008631 .readable_register = tabla_readable,
8632 .volatile_register = tabla_volatile,
8633
8634 .reg_cache_size = TABLA_CACHE_SIZE,
8635 .reg_cache_default = tabla_reg_defaults,
8636 .reg_word_size = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07008637 .controls = tabla_snd_controls,
8638 .num_controls = ARRAY_SIZE(tabla_snd_controls),
8639 .dapm_widgets = tabla_dapm_widgets,
8640 .num_dapm_widgets = ARRAY_SIZE(tabla_dapm_widgets),
8641 .dapm_routes = audio_map,
8642 .num_dapm_routes = ARRAY_SIZE(audio_map),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008643};
Bradley Rubincb3950a2011-08-18 13:07:26 -07008644
Joonwoo Park8b1f0982011-12-08 17:12:45 -08008645#ifdef CONFIG_PM
8646static int tabla_suspend(struct device *dev)
8647{
Joonwoo Park816b8e62012-01-23 16:03:21 -08008648 dev_dbg(dev, "%s: system suspend\n", __func__);
8649 return 0;
Joonwoo Park8b1f0982011-12-08 17:12:45 -08008650}
8651
8652static int tabla_resume(struct device *dev)
8653{
Joonwoo Parkecf379c2012-10-04 16:57:52 -07008654 int irq;
Joonwoo Park03324832012-03-19 19:36:16 -07008655 struct platform_device *pdev = to_platform_device(dev);
8656 struct tabla_priv *tabla = platform_get_drvdata(pdev);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07008657
Joonwoo Parkd6e48bd2012-09-20 11:14:15 -07008658 dev_dbg(dev, "%s: system resume tabla %p\n", __func__, tabla);
Joonwoo Parkecf379c2012-10-04 16:57:52 -07008659 if (tabla) {
8660 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Joonwoo Parkd6e48bd2012-09-20 11:14:15 -07008661 tabla->mbhc_last_resume = jiffies;
Joonwoo Parkecf379c2012-10-04 16:57:52 -07008662 if (tabla->gpio_irq_resend) {
8663 WARN_ON(!tabla->mbhc_cfg.gpio_irq);
8664 tabla->gpio_irq_resend = false;
8665
8666 irq = tabla->mbhc_cfg.gpio_irq;
8667 pr_debug("%s: Resending GPIO IRQ %d\n", __func__, irq);
8668 irq_set_pending(irq);
8669 check_irq_resend(irq_to_desc(irq), irq);
8670
8671 /* release suspend lock */
8672 wake_unlock(&tabla->irq_resend_wlock);
8673 }
8674 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
8675 }
8676
Joonwoo Park816b8e62012-01-23 16:03:21 -08008677 return 0;
Joonwoo Park8b1f0982011-12-08 17:12:45 -08008678}
8679
8680static const struct dev_pm_ops tabla_pm_ops = {
8681 .suspend = tabla_suspend,
8682 .resume = tabla_resume,
8683};
8684#endif
8685
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008686static int __devinit tabla_probe(struct platform_device *pdev)
8687{
Santosh Mardie15e2302011-11-15 10:39:23 +05308688 int ret = 0;
Steve Mucklef132c6c2012-06-06 18:30:57 -07008689 pr_err("tabla_probe\n");
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308690 if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
Santosh Mardie15e2302011-11-15 10:39:23 +05308691 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla,
8692 tabla_dai, ARRAY_SIZE(tabla_dai));
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308693 else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C)
Santosh Mardie15e2302011-11-15 10:39:23 +05308694 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla,
8695 tabla_i2s_dai, ARRAY_SIZE(tabla_i2s_dai));
8696 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008697}
8698static int __devexit tabla_remove(struct platform_device *pdev)
8699{
8700 snd_soc_unregister_codec(&pdev->dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008701 return 0;
8702}
8703static struct platform_driver tabla_codec_driver = {
8704 .probe = tabla_probe,
8705 .remove = tabla_remove,
8706 .driver = {
8707 .name = "tabla_codec",
8708 .owner = THIS_MODULE,
Joonwoo Park8b1f0982011-12-08 17:12:45 -08008709#ifdef CONFIG_PM
8710 .pm = &tabla_pm_ops,
8711#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008712 },
8713};
8714
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08008715static struct platform_driver tabla1x_codec_driver = {
8716 .probe = tabla_probe,
8717 .remove = tabla_remove,
8718 .driver = {
8719 .name = "tabla1x_codec",
8720 .owner = THIS_MODULE,
8721#ifdef CONFIG_PM
8722 .pm = &tabla_pm_ops,
8723#endif
8724 },
8725};
8726
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008727static int __init tabla_codec_init(void)
8728{
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08008729 int rtn = platform_driver_register(&tabla_codec_driver);
8730 if (rtn == 0) {
8731 rtn = platform_driver_register(&tabla1x_codec_driver);
8732 if (rtn != 0)
8733 platform_driver_unregister(&tabla_codec_driver);
8734 }
8735 return rtn;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008736}
8737
8738static void __exit tabla_codec_exit(void)
8739{
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08008740 platform_driver_unregister(&tabla1x_codec_driver);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008741 platform_driver_unregister(&tabla_codec_driver);
8742}
8743
8744module_init(tabla_codec_init);
8745module_exit(tabla_codec_exit);
8746
8747MODULE_DESCRIPTION("Tabla codec driver");
8748MODULE_VERSION("1.0");
8749MODULE_LICENSE("GPL v2");