blob: ed10ebe9cb4db721db7c290139b263e51b868ef8 [file] [log] [blame]
Kiran Kandi3426e512011-09-13 22:50:10 -07001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12#include <linux/module.h>
13#include <linux/init.h>
Bradley Rubin229c6a52011-07-12 16:18:48 -070014#include <linux/firmware.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070015#include <linux/slab.h>
16#include <linux/platform_device.h>
Santosh Mardie15e2302011-11-15 10:39:23 +053017#include <linux/device.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070018#include <linux/printk.h>
19#include <linux/ratelimit.h>
Bradley Rubincb3950a2011-08-18 13:07:26 -070020#include <linux/debugfs.h>
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>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036#include "wcd9310.h"
37
Kiran Kandi1e6371d2012-03-29 11:48:57 -070038#define WCD9310_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
39 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
40 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
41
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -070042
43#define NUM_DECIMATORS 10
44#define NUM_INTERPOLATORS 7
45#define BITS_PER_REG 8
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -080046#define TABLA_CFILT_FAST_MODE 0x00
47#define TABLA_CFILT_SLOW_MODE 0x40
Patrick Lai64b43262011-12-06 17:29:15 -080048#define MBHC_FW_READ_ATTEMPTS 15
49#define MBHC_FW_READ_TIMEOUT 2000000
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -070050
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -070051#define SLIM_CLOSE_TIMEOUT 1000
52
Joonwoo Park03324832012-03-19 19:36:16 -070053enum {
54 MBHC_USE_HPHL_TRIGGER = 1,
55 MBHC_USE_MB_TRIGGER = 2
56};
57
58#define MBHC_NUM_DCE_PLUG_DETECT 3
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -070059#define NUM_ATTEMPTS_INSERT_DETECT 25
60#define NUM_ATTEMPTS_TO_REPORT 5
Joonwoo Park03324832012-03-19 19:36:16 -070061
Joonwoo Park2cc13f02012-05-09 12:44:25 -070062#define TABLA_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | \
63 SND_JACK_OC_HPHR | SND_JACK_UNSUPPORTED)
Patrick Lai49efeac2011-11-03 11:01:12 -070064
Santosh Mardie15e2302011-11-15 10:39:23 +053065#define TABLA_I2S_MASTER_MODE_MASK 0x08
66
Patrick Laic7cae882011-11-18 11:52:49 -080067#define TABLA_OCP_ATTEMPT 1
68
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -080069#define AIF1_PB 1
70#define AIF1_CAP 2
Neema Shettyd3a89262012-02-16 10:23:50 -080071#define AIF2_PB 3
Kiran Kandi1e6371d2012-03-29 11:48:57 -070072#define AIF2_CAP 4
Neema Shetty3fb1b802012-04-27 13:53:24 -070073#define AIF3_CAP 5
Kiran Kandia9fffe92012-05-20 23:42:30 -070074#define AIF3_PB 6
Kiran Kandi1e6371d2012-03-29 11:48:57 -070075
Kiran Kandia9fffe92012-05-20 23:42:30 -070076#define NUM_CODEC_DAIS 6
Kuirong Wang0f8ade32012-02-27 16:29:45 -080077#define TABLA_COMP_DIGITAL_GAIN_OFFSET 3
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -080078
79struct tabla_codec_dai_data {
80 u32 rate;
81 u32 *ch_num;
82 u32 ch_act;
83 u32 ch_tot;
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -070084 u32 ch_mask;
85 wait_queue_head_t dai_wait;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -080086};
87
Joonwoo Park0976d012011-12-22 11:48:18 -080088#define TABLA_MCLK_RATE_12288KHZ 12288000
89#define TABLA_MCLK_RATE_9600KHZ 9600000
90
Joonwoo Parkf4267c22012-01-10 13:25:24 -080091#define TABLA_FAKE_INS_THRESHOLD_MS 2500
Joonwoo Park6b9b03f2012-01-23 18:48:54 -080092#define TABLA_FAKE_REMOVAL_MIN_PERIOD_MS 50
Joonwoo Parkf4267c22012-01-10 13:25:24 -080093
Joonwoo Park03324832012-03-19 19:36:16 -070094#define TABLA_MBHC_BUTTON_MIN 0x8000
95
Joonwoo Park03324832012-03-19 19:36:16 -070096#define TABLA_MBHC_FAKE_INSERT_LOW 10
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -070097#define TABLA_MBHC_FAKE_INSERT_HIGH 80
98#define TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO 150
Joonwoo Park03324832012-03-19 19:36:16 -070099
100#define TABLA_MBHC_STATUS_REL_DETECTION 0x0C
101
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700102#define TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS 200
103
Joonwoo Parkcf473b42012-03-29 19:48:16 -0700104#define TABLA_MBHC_FAKE_INS_DELTA_MV 200
105#define TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV 300
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700106
107#define TABLA_HS_DETECT_PLUG_TIME_MS (5 * 1000)
108#define TABLA_HS_DETECT_PLUG_INERVAL_MS 100
109
110#define TABLA_GPIO_IRQ_DEBOUNCE_TIME_US 5000
111
Joonwoo Park2cc13f02012-05-09 12:44:25 -0700112#define TABLA_MBHC_GND_MIC_SWAP_THRESHOLD 2
113
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700114#define TABLA_ACQUIRE_LOCK(x) do { mutex_lock(&x); } while (0)
115#define TABLA_RELEASE_LOCK(x) do { mutex_unlock(&x); } while (0)
116
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700117static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
118static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
119static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800120static struct snd_soc_dai_driver tabla_dai[];
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -0800121static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0);
Kiran Kandi93923902012-06-20 17:00:25 -0700122static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
123 struct snd_kcontrol *kcontrol, int event);
124static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
125 struct snd_kcontrol *kcontrol, int event);
126
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700127
128enum tabla_bandgap_type {
129 TABLA_BANDGAP_OFF = 0,
130 TABLA_BANDGAP_AUDIO_MODE,
131 TABLA_BANDGAP_MBHC_MODE,
132};
133
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700134struct mbhc_micbias_regs {
135 u16 cfilt_val;
136 u16 cfilt_ctl;
137 u16 mbhc_reg;
138 u16 int_rbias;
139 u16 ctl_reg;
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -0800140 u8 cfilt_sel;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700141};
142
Ben Romberger1f045a72011-11-04 10:14:57 -0700143/* Codec supports 2 IIR filters */
144enum {
145 IIR1 = 0,
146 IIR2,
147 IIR_MAX,
148};
149/* Codec supports 5 bands */
150enum {
151 BAND1 = 0,
152 BAND2,
153 BAND3,
154 BAND4,
155 BAND5,
156 BAND_MAX,
157};
158
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800159enum {
160 COMPANDER_1 = 0,
161 COMPANDER_2,
162 COMPANDER_MAX,
163};
164
165enum {
166 COMPANDER_FS_8KHZ = 0,
167 COMPANDER_FS_16KHZ,
168 COMPANDER_FS_32KHZ,
169 COMPANDER_FS_48KHZ,
Kiran Kandi1e6371d2012-03-29 11:48:57 -0700170 COMPANDER_FS_96KHZ,
171 COMPANDER_FS_192KHZ,
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800172 COMPANDER_FS_MAX,
173};
174
Joonwoo Parka9444452011-12-08 18:48:27 -0800175/* Flags to track of PA and DAC state.
176 * PA and DAC should be tracked separately as AUXPGA loopback requires
177 * only PA to be turned on without DAC being on. */
178enum tabla_priv_ack_flags {
179 TABLA_HPHL_PA_OFF_ACK = 0,
180 TABLA_HPHR_PA_OFF_ACK,
181 TABLA_HPHL_DAC_OFF_ACK,
182 TABLA_HPHR_DAC_OFF_ACK
183};
184
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800185
186struct comp_sample_dependent_params {
187 u32 peak_det_timeout;
188 u32 rms_meter_div_fact;
189 u32 rms_meter_resamp_fact;
190};
191
Joonwoo Park0976d012011-12-22 11:48:18 -0800192/* Data used by MBHC */
193struct mbhc_internal_cal_data {
194 u16 dce_z;
195 u16 dce_mb;
196 u16 sta_z;
197 u16 sta_mb;
Joonwoo Park433149a2012-01-11 09:53:54 -0800198 u32 t_sta_dce;
Joonwoo Park0976d012011-12-22 11:48:18 -0800199 u32 t_dce;
200 u32 t_sta;
201 u32 micb_mv;
202 u16 v_ins_hu;
203 u16 v_ins_h;
204 u16 v_b1_hu;
205 u16 v_b1_h;
206 u16 v_b1_huc;
207 u16 v_brh;
208 u16 v_brl;
209 u16 v_no_mic;
Joonwoo Park0976d012011-12-22 11:48:18 -0800210 u8 npoll;
211 u8 nbounce_wait;
Joonwoo Parkcf473b42012-03-29 19:48:16 -0700212 s16 adj_v_hs_max;
213 u16 adj_v_ins_hu;
214 u16 adj_v_ins_h;
215 s16 v_inval_ins_low;
216 s16 v_inval_ins_high;
Joonwoo Park0976d012011-12-22 11:48:18 -0800217};
218
Joonwoo Park6c1ebb62012-01-16 19:08:43 -0800219struct tabla_reg_address {
220 u16 micb_4_ctl;
221 u16 micb_4_int_rbias;
222 u16 micb_4_mbhc;
223};
224
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700225enum tabla_mbhc_plug_type {
Joonwoo Park41956722012-04-18 13:13:07 -0700226 PLUG_TYPE_INVALID = -1,
227 PLUG_TYPE_NONE,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700228 PLUG_TYPE_HEADSET,
229 PLUG_TYPE_HEADPHONE,
230 PLUG_TYPE_HIGH_HPH,
Joonwoo Park2cc13f02012-05-09 12:44:25 -0700231 PLUG_TYPE_GND_MIC_SWAP,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700232};
233
234enum tabla_mbhc_state {
235 MBHC_STATE_NONE = -1,
236 MBHC_STATE_POTENTIAL,
237 MBHC_STATE_POTENTIAL_RECOVERY,
238 MBHC_STATE_RELEASE,
239};
240
Kiran Kandid8cf5212012-03-02 15:34:53 -0800241struct hpf_work {
242 struct tabla_priv *tabla;
243 u32 decimator;
244 u8 tx_hpf_cut_of_freq;
245 struct delayed_work dwork;
246};
247
248static struct hpf_work tx_hpf_work[NUM_DECIMATORS];
249
Bradley Rubin229c6a52011-07-12 16:18:48 -0700250struct tabla_priv {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700251 struct snd_soc_codec *codec;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -0800252 struct tabla_reg_address reg_addr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700253 u32 adc_count;
Patrick Lai3043fba2011-08-01 14:15:57 -0700254 u32 cfilt1_cnt;
255 u32 cfilt2_cnt;
256 u32 cfilt3_cnt;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -0700257 u32 rx_bias_count;
Kiran Kandi0ba468f2012-05-08 11:45:05 -0700258 s32 dmic_1_2_clk_cnt;
259 s32 dmic_3_4_clk_cnt;
260 s32 dmic_5_6_clk_cnt;
261
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700262 enum tabla_bandgap_type bandgap_type;
Kiran Kandi6fae8bf2011-08-15 10:36:42 -0700263 bool mclk_enabled;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700264 bool clock_active;
265 bool config_mode_active;
266 bool mbhc_polling_active;
Joonwoo Parkf4267c22012-01-10 13:25:24 -0800267 unsigned long mbhc_fake_ins_start;
Bradley Rubincb1e2732011-06-23 16:49:20 -0700268 int buttons_pressed;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700269 enum tabla_mbhc_state mbhc_state;
270 struct tabla_mbhc_config mbhc_cfg;
Joonwoo Park0976d012011-12-22 11:48:18 -0800271 struct mbhc_internal_cal_data mbhc_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700272
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +0530273 struct wcd9xxx_pdata *pdata;
Bradley Rubina7096d02011-08-03 18:29:02 -0700274 u32 anc_slot;
Bradley Rubincb3950a2011-08-18 13:07:26 -0700275
276 bool no_mic_headset_override;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -0700277 /* Delayed work to report long button press */
Joonwoo Park03324832012-03-19 19:36:16 -0700278 struct delayed_work mbhc_btn_dwork;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -0700279
280 struct mbhc_micbias_regs mbhc_bias_regs;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -0700281 bool mbhc_micbias_switched;
Patrick Lai49efeac2011-11-03 11:01:12 -0700282
Joonwoo Parka9444452011-12-08 18:48:27 -0800283 /* track PA/DAC state */
284 unsigned long hph_pa_dac_state;
285
Santosh Mardie15e2302011-11-15 10:39:23 +0530286 /*track tabla interface type*/
287 u8 intf_type;
288
Patrick Lai49efeac2011-11-03 11:01:12 -0700289 u32 hph_status; /* track headhpone status */
290 /* define separate work for left and right headphone OCP to avoid
291 * additional checking on which OCP event to report so no locking
292 * to ensure synchronization is required
293 */
294 struct work_struct hphlocp_work; /* reporting left hph ocp off */
295 struct work_struct hphrocp_work; /* reporting right hph ocp off */
Joonwoo Park8b1f0982011-12-08 17:12:45 -0800296
Patrick Laic7cae882011-11-18 11:52:49 -0800297 u8 hphlocp_cnt; /* headphone left ocp retry */
298 u8 hphrocp_cnt; /* headphone right ocp retry */
Joonwoo Park0976d012011-12-22 11:48:18 -0800299
Patrick Lai64b43262011-12-06 17:29:15 -0800300 /* Work to perform MBHC Firmware Read */
301 struct delayed_work mbhc_firmware_dwork;
302 const struct firmware *mbhc_fw;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -0800303
304 /* num of slim ports required */
305 struct tabla_codec_dai_data dai[NUM_CODEC_DAIS];
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800306
307 /*compander*/
308 int comp_enabled[COMPANDER_MAX];
309 u32 comp_fs[COMPANDER_MAX];
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -0800310
311 /* Maintain the status of AUX PGA */
312 int aux_pga_cnt;
313 u8 aux_l_gain;
314 u8 aux_r_gain;
Joonwoo Park03324832012-03-19 19:36:16 -0700315
Joonwoo Park03324832012-03-19 19:36:16 -0700316 struct delayed_work mbhc_insert_dwork;
317 unsigned long mbhc_last_resume; /* in jiffies */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700318
319 u8 current_plug;
320 struct work_struct hs_correct_plug_work;
321 bool hs_detect_work_stop;
322 bool hs_polling_irq_prepared;
323 bool lpi_enabled; /* low power insertion detection */
324 bool in_gpio_handler;
325 /* Currently, only used for mbhc purpose, to protect
326 * concurrent execution of mbhc threaded irq handlers and
327 * kill race between DAPM and MBHC.But can serve as a
328 * general lock to protect codec resource
329 */
330 struct mutex codec_resource_lock;
331
Bradley Rubincb3950a2011-08-18 13:07:26 -0700332#ifdef CONFIG_DEBUG_FS
Joonwoo Park179b9ec2012-03-26 10:56:20 -0700333 struct dentry *debugfs_poke;
334 struct dentry *debugfs_mbhc;
Bradley Rubincb3950a2011-08-18 13:07:26 -0700335#endif
Joonwoo Park179b9ec2012-03-26 10:56:20 -0700336};
337
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800338static const u32 comp_shift[] = {
339 0,
340 2,
341};
342
343static const int comp_rx_path[] = {
344 COMPANDER_1,
345 COMPANDER_1,
346 COMPANDER_2,
347 COMPANDER_2,
348 COMPANDER_2,
349 COMPANDER_2,
350 COMPANDER_MAX,
351};
352
353static const struct comp_sample_dependent_params comp_samp_params[] = {
354 {
355 .peak_det_timeout = 0x2,
356 .rms_meter_div_fact = 0x8 << 4,
357 .rms_meter_resamp_fact = 0x21,
358 },
359 {
360 .peak_det_timeout = 0x3,
361 .rms_meter_div_fact = 0x9 << 4,
362 .rms_meter_resamp_fact = 0x28,
363 },
364
365 {
366 .peak_det_timeout = 0x5,
367 .rms_meter_div_fact = 0xB << 4,
368 .rms_meter_resamp_fact = 0x28,
369 },
370
371 {
372 .peak_det_timeout = 0x5,
373 .rms_meter_div_fact = 0xB << 4,
374 .rms_meter_resamp_fact = 0x28,
375 },
376};
377
Kuirong Wange9c8a222012-03-28 16:24:09 -0700378static unsigned short rx_digital_gain_reg[] = {
379 TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
380 TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
381 TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
382 TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
383 TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
384 TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
385 TABLA_A_CDC_RX7_VOL_CTL_B2_CTL,
386};
387
388
389static unsigned short tx_digital_gain_reg[] = {
390 TABLA_A_CDC_TX1_VOL_CTL_GAIN,
391 TABLA_A_CDC_TX2_VOL_CTL_GAIN,
392 TABLA_A_CDC_TX3_VOL_CTL_GAIN,
393 TABLA_A_CDC_TX4_VOL_CTL_GAIN,
394 TABLA_A_CDC_TX5_VOL_CTL_GAIN,
395 TABLA_A_CDC_TX6_VOL_CTL_GAIN,
396 TABLA_A_CDC_TX7_VOL_CTL_GAIN,
397 TABLA_A_CDC_TX8_VOL_CTL_GAIN,
398 TABLA_A_CDC_TX9_VOL_CTL_GAIN,
399 TABLA_A_CDC_TX10_VOL_CTL_GAIN,
400};
401
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700402static int tabla_codec_enable_charge_pump(struct snd_soc_dapm_widget *w,
403 struct snd_kcontrol *kcontrol, int event)
404{
405 struct snd_soc_codec *codec = w->codec;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700406
407 pr_debug("%s %d\n", __func__, event);
408 switch (event) {
409 case SND_SOC_DAPM_POST_PMU:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700410 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
411 0x01);
412 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x08);
413 usleep_range(200, 200);
414 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x00);
415 break;
416 case SND_SOC_DAPM_PRE_PMD:
417 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10,
418 0x10);
419 usleep_range(20, 20);
420 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x08);
421 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x10);
422 snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x00);
423 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01,
424 0x00);
425 snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700426 break;
427 }
428 return 0;
429}
430
Bradley Rubina7096d02011-08-03 18:29:02 -0700431static int tabla_get_anc_slot(struct snd_kcontrol *kcontrol,
432 struct snd_ctl_elem_value *ucontrol)
433{
434 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
435 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
436 ucontrol->value.integer.value[0] = tabla->anc_slot;
437 return 0;
438}
439
440static int tabla_put_anc_slot(struct snd_kcontrol *kcontrol,
441 struct snd_ctl_elem_value *ucontrol)
442{
443 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
444 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
445 tabla->anc_slot = ucontrol->value.integer.value[0];
446 return 0;
447}
448
Kiran Kandid2d86b52011-09-09 17:44:28 -0700449static int tabla_pa_gain_get(struct snd_kcontrol *kcontrol,
450 struct snd_ctl_elem_value *ucontrol)
451{
452 u8 ear_pa_gain;
453 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
454
455 ear_pa_gain = snd_soc_read(codec, TABLA_A_RX_EAR_GAIN);
456
457 ear_pa_gain = ear_pa_gain >> 5;
458
459 if (ear_pa_gain == 0x00) {
460 ucontrol->value.integer.value[0] = 0;
461 } else if (ear_pa_gain == 0x04) {
462 ucontrol->value.integer.value[0] = 1;
463 } else {
464 pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n",
465 __func__, ear_pa_gain);
466 return -EINVAL;
467 }
468
469 pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain);
470
471 return 0;
472}
473
474static int tabla_pa_gain_put(struct snd_kcontrol *kcontrol,
475 struct snd_ctl_elem_value *ucontrol)
476{
477 u8 ear_pa_gain;
478 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
479
480 pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__,
481 ucontrol->value.integer.value[0]);
482
483 switch (ucontrol->value.integer.value[0]) {
484 case 0:
485 ear_pa_gain = 0x00;
486 break;
487 case 1:
488 ear_pa_gain = 0x80;
489 break;
490 default:
491 return -EINVAL;
492 }
493
494 snd_soc_update_bits(codec, TABLA_A_RX_EAR_GAIN, 0xE0, ear_pa_gain);
495 return 0;
496}
497
Ben Romberger1f045a72011-11-04 10:14:57 -0700498static int tabla_get_iir_enable_audio_mixer(
499 struct snd_kcontrol *kcontrol,
500 struct snd_ctl_elem_value *ucontrol)
501{
502 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
503 int iir_idx = ((struct soc_multi_mixer_control *)
504 kcontrol->private_value)->reg;
505 int band_idx = ((struct soc_multi_mixer_control *)
506 kcontrol->private_value)->shift;
507
508 ucontrol->value.integer.value[0] =
509 snd_soc_read(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx)) &
510 (1 << band_idx);
511
512 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
513 iir_idx, band_idx,
514 (uint32_t)ucontrol->value.integer.value[0]);
515 return 0;
516}
517
518static int tabla_put_iir_enable_audio_mixer(
519 struct snd_kcontrol *kcontrol,
520 struct snd_ctl_elem_value *ucontrol)
521{
522 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
523 int iir_idx = ((struct soc_multi_mixer_control *)
524 kcontrol->private_value)->reg;
525 int band_idx = ((struct soc_multi_mixer_control *)
526 kcontrol->private_value)->shift;
527 int value = ucontrol->value.integer.value[0];
528
529 /* Mask first 5 bits, 6-8 are reserved */
530 snd_soc_update_bits(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx),
531 (1 << band_idx), (value << band_idx));
532
533 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
534 iir_idx, band_idx, value);
535 return 0;
536}
537static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
538 int iir_idx, int band_idx,
539 int coeff_idx)
540{
541 /* Address does not automatically update if reading */
Ben Romberger0915aae2012-02-06 23:32:43 -0800542 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700543 (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800544 (band_idx * BAND_MAX + coeff_idx) & 0x1F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700545
546 /* Mask bits top 2 bits since they are reserved */
547 return ((snd_soc_read(codec,
548 (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 24) |
549 (snd_soc_read(codec,
550 (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx)) << 16) |
551 (snd_soc_read(codec,
552 (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx)) << 8) |
553 (snd_soc_read(codec,
554 (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx)))) &
555 0x3FFFFFFF;
556}
557
558static int tabla_get_iir_band_audio_mixer(
559 struct snd_kcontrol *kcontrol,
560 struct snd_ctl_elem_value *ucontrol)
561{
562 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
563 int iir_idx = ((struct soc_multi_mixer_control *)
564 kcontrol->private_value)->reg;
565 int band_idx = ((struct soc_multi_mixer_control *)
566 kcontrol->private_value)->shift;
567
568 ucontrol->value.integer.value[0] =
569 get_iir_band_coeff(codec, iir_idx, band_idx, 0);
570 ucontrol->value.integer.value[1] =
571 get_iir_band_coeff(codec, iir_idx, band_idx, 1);
572 ucontrol->value.integer.value[2] =
573 get_iir_band_coeff(codec, iir_idx, band_idx, 2);
574 ucontrol->value.integer.value[3] =
575 get_iir_band_coeff(codec, iir_idx, band_idx, 3);
576 ucontrol->value.integer.value[4] =
577 get_iir_band_coeff(codec, iir_idx, band_idx, 4);
578
579 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
580 "%s: IIR #%d band #%d b1 = 0x%x\n"
581 "%s: IIR #%d band #%d b2 = 0x%x\n"
582 "%s: IIR #%d band #%d a1 = 0x%x\n"
583 "%s: IIR #%d band #%d a2 = 0x%x\n",
584 __func__, iir_idx, band_idx,
585 (uint32_t)ucontrol->value.integer.value[0],
586 __func__, iir_idx, band_idx,
587 (uint32_t)ucontrol->value.integer.value[1],
588 __func__, iir_idx, band_idx,
589 (uint32_t)ucontrol->value.integer.value[2],
590 __func__, iir_idx, band_idx,
591 (uint32_t)ucontrol->value.integer.value[3],
592 __func__, iir_idx, band_idx,
593 (uint32_t)ucontrol->value.integer.value[4]);
594 return 0;
595}
596
597static void set_iir_band_coeff(struct snd_soc_codec *codec,
598 int iir_idx, int band_idx,
599 int coeff_idx, uint32_t value)
600{
601 /* Mask top 3 bits, 6-8 are reserved */
602 /* Update address manually each time */
Ben Romberger0915aae2012-02-06 23:32:43 -0800603 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700604 (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800605 (band_idx * BAND_MAX + coeff_idx) & 0x1F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700606
607 /* Mask top 2 bits, 7-8 are reserved */
Ben Romberger0915aae2012-02-06 23:32:43 -0800608 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700609 (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800610 (value >> 24) & 0x3F);
Ben Romberger1f045a72011-11-04 10:14:57 -0700611
612 /* Isolate 8bits at a time */
Ben Romberger0915aae2012-02-06 23:32:43 -0800613 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700614 (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800615 (value >> 16) & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700616
Ben Romberger0915aae2012-02-06 23:32:43 -0800617 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700618 (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800619 (value >> 8) & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700620
Ben Romberger0915aae2012-02-06 23:32:43 -0800621 snd_soc_write(codec,
Ben Romberger1f045a72011-11-04 10:14:57 -0700622 (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx),
Ben Romberger0915aae2012-02-06 23:32:43 -0800623 value & 0xFF);
Ben Romberger1f045a72011-11-04 10:14:57 -0700624}
625
626static int tabla_put_iir_band_audio_mixer(
627 struct snd_kcontrol *kcontrol,
628 struct snd_ctl_elem_value *ucontrol)
629{
630 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
631 int iir_idx = ((struct soc_multi_mixer_control *)
632 kcontrol->private_value)->reg;
633 int band_idx = ((struct soc_multi_mixer_control *)
634 kcontrol->private_value)->shift;
635
636 set_iir_band_coeff(codec, iir_idx, band_idx, 0,
637 ucontrol->value.integer.value[0]);
638 set_iir_band_coeff(codec, iir_idx, band_idx, 1,
639 ucontrol->value.integer.value[1]);
640 set_iir_band_coeff(codec, iir_idx, band_idx, 2,
641 ucontrol->value.integer.value[2]);
642 set_iir_band_coeff(codec, iir_idx, band_idx, 3,
643 ucontrol->value.integer.value[3]);
644 set_iir_band_coeff(codec, iir_idx, band_idx, 4,
645 ucontrol->value.integer.value[4]);
646
647 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
648 "%s: IIR #%d band #%d b1 = 0x%x\n"
649 "%s: IIR #%d band #%d b2 = 0x%x\n"
650 "%s: IIR #%d band #%d a1 = 0x%x\n"
651 "%s: IIR #%d band #%d a2 = 0x%x\n",
652 __func__, iir_idx, band_idx,
653 get_iir_band_coeff(codec, iir_idx, band_idx, 0),
654 __func__, iir_idx, band_idx,
655 get_iir_band_coeff(codec, iir_idx, band_idx, 1),
656 __func__, iir_idx, band_idx,
657 get_iir_band_coeff(codec, iir_idx, band_idx, 2),
658 __func__, iir_idx, band_idx,
659 get_iir_band_coeff(codec, iir_idx, band_idx, 3),
660 __func__, iir_idx, band_idx,
661 get_iir_band_coeff(codec, iir_idx, band_idx, 4));
662 return 0;
663}
664
Kuirong Wang0f8ade32012-02-27 16:29:45 -0800665static int tabla_compander_gain_offset(
666 struct snd_soc_codec *codec, u32 enable,
667 unsigned int reg, int mask, int event)
668{
669 int pa_mode = snd_soc_read(codec, reg) & mask;
670 int gain_offset = 0;
671 /* if PMU && enable is 1-> offset is 3
672 * if PMU && enable is 0-> offset is 0
673 * if PMD && pa_mode is PA -> offset is 0: PMU compander is off
674 * if PMD && pa_mode is comp -> offset is -3: PMU compander is on.
675 */
676
677 if (SND_SOC_DAPM_EVENT_ON(event) && (enable != 0))
678 gain_offset = TABLA_COMP_DIGITAL_GAIN_OFFSET;
679 if (SND_SOC_DAPM_EVENT_OFF(event) && (pa_mode == 0))
680 gain_offset = -TABLA_COMP_DIGITAL_GAIN_OFFSET;
681 return gain_offset;
682}
683
684
685static int tabla_config_gain_compander(
686 struct snd_soc_codec *codec,
687 u32 compander, u32 enable, int event)
688{
689 int value = 0;
690 int mask = 1 << 4;
691 int gain = 0;
692 int gain_offset;
693 if (compander >= COMPANDER_MAX) {
694 pr_err("%s: Error, invalid compander channel\n", __func__);
695 return -EINVAL;
696 }
697
698 if ((enable == 0) || SND_SOC_DAPM_EVENT_OFF(event))
699 value = 1 << 4;
700
701 if (compander == COMPANDER_1) {
702 gain_offset = tabla_compander_gain_offset(codec, enable,
703 TABLA_A_RX_HPH_L_GAIN, mask, event);
704 snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_GAIN, mask, value);
705 gain = snd_soc_read(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL);
706 snd_soc_update_bits(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
707 0xFF, gain - gain_offset);
708 gain_offset = tabla_compander_gain_offset(codec, enable,
709 TABLA_A_RX_HPH_R_GAIN, mask, event);
710 snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_GAIN, mask, value);
711 gain = snd_soc_read(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL);
712 snd_soc_update_bits(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
713 0xFF, gain - gain_offset);
714 } else if (compander == COMPANDER_2) {
715 gain_offset = tabla_compander_gain_offset(codec, enable,
716 TABLA_A_RX_LINE_1_GAIN, mask, event);
717 snd_soc_update_bits(codec, TABLA_A_RX_LINE_1_GAIN, mask, value);
718 gain = snd_soc_read(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL);
719 snd_soc_update_bits(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
720 0xFF, gain - gain_offset);
721 gain_offset = tabla_compander_gain_offset(codec, enable,
722 TABLA_A_RX_LINE_3_GAIN, mask, event);
723 snd_soc_update_bits(codec, TABLA_A_RX_LINE_3_GAIN, mask, value);
724 gain = snd_soc_read(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL);
725 snd_soc_update_bits(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
726 0xFF, gain - gain_offset);
727 gain_offset = tabla_compander_gain_offset(codec, enable,
728 TABLA_A_RX_LINE_2_GAIN, mask, event);
729 snd_soc_update_bits(codec, TABLA_A_RX_LINE_2_GAIN, mask, value);
730 gain = snd_soc_read(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL);
731 snd_soc_update_bits(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
732 0xFF, gain - gain_offset);
733 gain_offset = tabla_compander_gain_offset(codec, enable,
734 TABLA_A_RX_LINE_4_GAIN, mask, event);
735 snd_soc_update_bits(codec, TABLA_A_RX_LINE_4_GAIN, mask, value);
736 gain = snd_soc_read(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL);
737 snd_soc_update_bits(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
738 0xFF, gain - gain_offset);
739 }
740 return 0;
741}
742static int tabla_get_compander(struct snd_kcontrol *kcontrol,
743 struct snd_ctl_elem_value *ucontrol)
744{
745
746 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
747 int comp = ((struct soc_multi_mixer_control *)
748 kcontrol->private_value)->max;
749 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
750
751 ucontrol->value.integer.value[0] = tabla->comp_enabled[comp];
752
753 return 0;
754}
755
756static int tabla_set_compander(struct snd_kcontrol *kcontrol,
757 struct snd_ctl_elem_value *ucontrol)
758{
759 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
760 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
761 int comp = ((struct soc_multi_mixer_control *)
762 kcontrol->private_value)->max;
763 int value = ucontrol->value.integer.value[0];
764
765 if (value == tabla->comp_enabled[comp]) {
766 pr_debug("%s: compander #%d enable %d no change\n",
767 __func__, comp, value);
768 return 0;
769 }
770 tabla->comp_enabled[comp] = value;
771 return 0;
772}
773
774
775static int tabla_config_compander(struct snd_soc_dapm_widget *w,
776 struct snd_kcontrol *kcontrol,
777 int event)
778{
779 struct snd_soc_codec *codec = w->codec;
780 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
781 u32 rate = tabla->comp_fs[w->shift];
782
783 switch (event) {
784 case SND_SOC_DAPM_PRE_PMU:
785 if (tabla->comp_enabled[w->shift] != 0) {
786 /* Enable both L/R compander clocks */
787 snd_soc_update_bits(codec,
788 TABLA_A_CDC_CLK_RX_B2_CTL,
789 0x03 << comp_shift[w->shift],
790 0x03 << comp_shift[w->shift]);
791 /* Clar the HALT for the compander*/
792 snd_soc_update_bits(codec,
793 TABLA_A_CDC_COMP1_B1_CTL +
794 w->shift * 8, 1 << 2, 0);
795 /* Toggle compander reset bits*/
796 snd_soc_update_bits(codec,
797 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
798 0x03 << comp_shift[w->shift],
799 0x03 << comp_shift[w->shift]);
800 snd_soc_update_bits(codec,
801 TABLA_A_CDC_CLK_OTHR_RESET_CTL,
802 0x03 << comp_shift[w->shift], 0);
803 tabla_config_gain_compander(codec, w->shift, 1, event);
804 /* Update the RMS meter resampling*/
805 snd_soc_update_bits(codec,
806 TABLA_A_CDC_COMP1_B3_CTL +
807 w->shift * 8, 0xFF, 0x01);
808 /* Wait for 1ms*/
809 usleep_range(1000, 1000);
810 }
811 break;
812 case SND_SOC_DAPM_POST_PMU:
813 /* Set sample rate dependent paramater*/
814 if (tabla->comp_enabled[w->shift] != 0) {
815 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_FS_CFG +
816 w->shift * 8, 0x03, rate);
817 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL +
818 w->shift * 8, 0x0F,
819 comp_samp_params[rate].peak_det_timeout);
820 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL +
821 w->shift * 8, 0xF0,
822 comp_samp_params[rate].rms_meter_div_fact);
823 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B3_CTL +
824 w->shift * 8, 0xFF,
825 comp_samp_params[rate].rms_meter_resamp_fact);
826 /* Compander enable -> 0x370/0x378*/
827 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
828 w->shift * 8, 0x03, 0x03);
829 }
830 break;
831 case SND_SOC_DAPM_PRE_PMD:
832 /* Halt the compander*/
833 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
834 w->shift * 8, 1 << 2, 1 << 2);
835 break;
836 case SND_SOC_DAPM_POST_PMD:
837 /* Restore the gain */
838 tabla_config_gain_compander(codec, w->shift,
839 tabla->comp_enabled[w->shift], event);
840 /* Disable the compander*/
841 snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL +
842 w->shift * 8, 0x03, 0x00);
843 /* Turn off the clock for compander in pair*/
844 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_B2_CTL,
845 0x03 << comp_shift[w->shift], 0);
846 break;
847 }
848 return 0;
849}
850
Kiran Kandid2d86b52011-09-09 17:44:28 -0700851static const char *tabla_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"};
852static const struct soc_enum tabla_ear_pa_gain_enum[] = {
853 SOC_ENUM_SINGLE_EXT(2, tabla_ear_pa_gain_text),
854};
855
Santosh Mardi024010f2011-10-18 06:27:21 +0530856/*cut of frequency for high pass filter*/
857static const char *cf_text[] = {
858 "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz"
859};
860
861static const struct soc_enum cf_dec1_enum =
862 SOC_ENUM_SINGLE(TABLA_A_CDC_TX1_MUX_CTL, 4, 3, cf_text);
863
864static const struct soc_enum cf_dec2_enum =
865 SOC_ENUM_SINGLE(TABLA_A_CDC_TX2_MUX_CTL, 4, 3, cf_text);
866
867static const struct soc_enum cf_dec3_enum =
868 SOC_ENUM_SINGLE(TABLA_A_CDC_TX3_MUX_CTL, 4, 3, cf_text);
869
870static const struct soc_enum cf_dec4_enum =
871 SOC_ENUM_SINGLE(TABLA_A_CDC_TX4_MUX_CTL, 4, 3, cf_text);
872
873static const struct soc_enum cf_dec5_enum =
874 SOC_ENUM_SINGLE(TABLA_A_CDC_TX5_MUX_CTL, 4, 3, cf_text);
875
876static const struct soc_enum cf_dec6_enum =
877 SOC_ENUM_SINGLE(TABLA_A_CDC_TX6_MUX_CTL, 4, 3, cf_text);
878
879static const struct soc_enum cf_dec7_enum =
880 SOC_ENUM_SINGLE(TABLA_A_CDC_TX7_MUX_CTL, 4, 3, cf_text);
881
882static const struct soc_enum cf_dec8_enum =
883 SOC_ENUM_SINGLE(TABLA_A_CDC_TX8_MUX_CTL, 4, 3, cf_text);
884
885static const struct soc_enum cf_dec9_enum =
886 SOC_ENUM_SINGLE(TABLA_A_CDC_TX9_MUX_CTL, 4, 3, cf_text);
887
888static const struct soc_enum cf_dec10_enum =
889 SOC_ENUM_SINGLE(TABLA_A_CDC_TX10_MUX_CTL, 4, 3, cf_text);
890
891static const struct soc_enum cf_rxmix1_enum =
892 SOC_ENUM_SINGLE(TABLA_A_CDC_RX1_B4_CTL, 1, 3, cf_text);
893
894static const struct soc_enum cf_rxmix2_enum =
895 SOC_ENUM_SINGLE(TABLA_A_CDC_RX2_B4_CTL, 1, 3, cf_text);
896
897static const struct soc_enum cf_rxmix3_enum =
898 SOC_ENUM_SINGLE(TABLA_A_CDC_RX3_B4_CTL, 1, 3, cf_text);
899
900static const struct soc_enum cf_rxmix4_enum =
901 SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B4_CTL, 1, 3, cf_text);
902
903static const struct soc_enum cf_rxmix5_enum =
904 SOC_ENUM_SINGLE(TABLA_A_CDC_RX5_B4_CTL, 1, 3, cf_text)
905;
906static const struct soc_enum cf_rxmix6_enum =
907 SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B4_CTL, 1, 3, cf_text);
908
909static const struct soc_enum cf_rxmix7_enum =
910 SOC_ENUM_SINGLE(TABLA_A_CDC_RX7_B4_CTL, 1, 3, cf_text);
911
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700912static const struct snd_kcontrol_new tabla_snd_controls[] = {
Kiran Kandid2d86b52011-09-09 17:44:28 -0700913
914 SOC_ENUM_EXT("EAR PA Gain", tabla_ear_pa_gain_enum[0],
915 tabla_pa_gain_get, tabla_pa_gain_put),
916
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700917 SOC_SINGLE_TLV("LINEOUT1 Volume", TABLA_A_RX_LINE_1_GAIN, 0, 12, 1,
918 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700919 SOC_SINGLE_TLV("LINEOUT2 Volume", TABLA_A_RX_LINE_2_GAIN, 0, 12, 1,
920 line_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700921 SOC_SINGLE_TLV("LINEOUT3 Volume", TABLA_A_RX_LINE_3_GAIN, 0, 12, 1,
922 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700923 SOC_SINGLE_TLV("LINEOUT4 Volume", TABLA_A_RX_LINE_4_GAIN, 0, 12, 1,
924 line_gain),
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -0700925 SOC_SINGLE_TLV("LINEOUT5 Volume", TABLA_A_RX_LINE_5_GAIN, 0, 12, 1,
926 line_gain),
Bradley Rubin74a9b4a2011-06-13 15:03:43 -0700927
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700928 SOC_SINGLE_TLV("HPHL Volume", TABLA_A_RX_HPH_L_GAIN, 0, 12, 1,
929 line_gain),
930 SOC_SINGLE_TLV("HPHR Volume", TABLA_A_RX_HPH_R_GAIN, 0, 12, 1,
931 line_gain),
932
Bradley Rubin410383f2011-07-22 13:44:23 -0700933 SOC_SINGLE_S8_TLV("RX1 Digital Volume", TABLA_A_CDC_RX1_VOL_CTL_B2_CTL,
934 -84, 40, digital_gain),
935 SOC_SINGLE_S8_TLV("RX2 Digital Volume", TABLA_A_CDC_RX2_VOL_CTL_B2_CTL,
936 -84, 40, digital_gain),
937 SOC_SINGLE_S8_TLV("RX3 Digital Volume", TABLA_A_CDC_RX3_VOL_CTL_B2_CTL,
938 -84, 40, digital_gain),
939 SOC_SINGLE_S8_TLV("RX4 Digital Volume", TABLA_A_CDC_RX4_VOL_CTL_B2_CTL,
940 -84, 40, digital_gain),
941 SOC_SINGLE_S8_TLV("RX5 Digital Volume", TABLA_A_CDC_RX5_VOL_CTL_B2_CTL,
942 -84, 40, digital_gain),
943 SOC_SINGLE_S8_TLV("RX6 Digital Volume", TABLA_A_CDC_RX6_VOL_CTL_B2_CTL,
944 -84, 40, digital_gain),
Neema Shettyd3a89262012-02-16 10:23:50 -0800945 SOC_SINGLE_S8_TLV("RX7 Digital Volume", TABLA_A_CDC_RX7_VOL_CTL_B2_CTL,
946 -84, 40, digital_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700947
Bradley Rubin410383f2011-07-22 13:44:23 -0700948 SOC_SINGLE_S8_TLV("DEC1 Volume", TABLA_A_CDC_TX1_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700949 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -0700950 SOC_SINGLE_S8_TLV("DEC2 Volume", TABLA_A_CDC_TX2_VOL_CTL_GAIN, -84, 40,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700951 digital_gain),
Bradley Rubin410383f2011-07-22 13:44:23 -0700952 SOC_SINGLE_S8_TLV("DEC3 Volume", TABLA_A_CDC_TX3_VOL_CTL_GAIN, -84, 40,
953 digital_gain),
954 SOC_SINGLE_S8_TLV("DEC4 Volume", TABLA_A_CDC_TX4_VOL_CTL_GAIN, -84, 40,
955 digital_gain),
956 SOC_SINGLE_S8_TLV("DEC5 Volume", TABLA_A_CDC_TX5_VOL_CTL_GAIN, -84, 40,
957 digital_gain),
958 SOC_SINGLE_S8_TLV("DEC6 Volume", TABLA_A_CDC_TX6_VOL_CTL_GAIN, -84, 40,
959 digital_gain),
960 SOC_SINGLE_S8_TLV("DEC7 Volume", TABLA_A_CDC_TX7_VOL_CTL_GAIN, -84, 40,
961 digital_gain),
962 SOC_SINGLE_S8_TLV("DEC8 Volume", TABLA_A_CDC_TX8_VOL_CTL_GAIN, -84, 40,
963 digital_gain),
964 SOC_SINGLE_S8_TLV("DEC9 Volume", TABLA_A_CDC_TX9_VOL_CTL_GAIN, -84, 40,
965 digital_gain),
966 SOC_SINGLE_S8_TLV("DEC10 Volume", TABLA_A_CDC_TX10_VOL_CTL_GAIN, -84,
967 40, digital_gain),
Patrick Lai29006372011-09-28 17:57:42 -0700968 SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TABLA_A_CDC_IIR1_GAIN_B1_CTL, -84,
969 40, digital_gain),
970 SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TABLA_A_CDC_IIR1_GAIN_B2_CTL, -84,
971 40, digital_gain),
972 SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TABLA_A_CDC_IIR1_GAIN_B3_CTL, -84,
973 40, digital_gain),
974 SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TABLA_A_CDC_IIR1_GAIN_B4_CTL, -84,
975 40, digital_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700976 SOC_SINGLE_TLV("ADC1 Volume", TABLA_A_TX_1_2_EN, 5, 3, 0, analog_gain),
977 SOC_SINGLE_TLV("ADC2 Volume", TABLA_A_TX_1_2_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700978 SOC_SINGLE_TLV("ADC3 Volume", TABLA_A_TX_3_4_EN, 5, 3, 0, analog_gain),
979 SOC_SINGLE_TLV("ADC4 Volume", TABLA_A_TX_3_4_EN, 1, 3, 0, analog_gain),
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -0700980 SOC_SINGLE_TLV("ADC5 Volume", TABLA_A_TX_5_6_EN, 5, 3, 0, analog_gain),
981 SOC_SINGLE_TLV("ADC6 Volume", TABLA_A_TX_5_6_EN, 1, 3, 0, analog_gain),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700982
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -0800983 SOC_SINGLE_TLV("AUX_PGA_LEFT Volume", TABLA_A_AUX_L_GAIN, 0, 39, 0,
984 aux_pga_gain),
985 SOC_SINGLE_TLV("AUX_PGA_RIGHT Volume", TABLA_A_AUX_R_GAIN, 0, 39, 0,
986 aux_pga_gain),
987
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700988 SOC_SINGLE("MICBIAS1 CAPLESS Switch", TABLA_A_MICB_1_CTL, 4, 1, 1),
Santosh Mardi680b41e2011-11-22 16:51:16 -0800989 SOC_SINGLE("MICBIAS2 CAPLESS Switch", TABLA_A_MICB_2_CTL, 4, 1, 1),
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -0700990 SOC_SINGLE("MICBIAS3 CAPLESS Switch", TABLA_A_MICB_3_CTL, 4, 1, 1),
Bradley Rubina7096d02011-08-03 18:29:02 -0700991
992 SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 0, 100, tabla_get_anc_slot,
993 tabla_put_anc_slot),
Santosh Mardi024010f2011-10-18 06:27:21 +0530994 SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
995 SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
996 SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
997 SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
998 SOC_ENUM("TX5 HPF cut off", cf_dec5_enum),
999 SOC_ENUM("TX6 HPF cut off", cf_dec6_enum),
1000 SOC_ENUM("TX7 HPF cut off", cf_dec7_enum),
1001 SOC_ENUM("TX8 HPF cut off", cf_dec8_enum),
1002 SOC_ENUM("TX9 HPF cut off", cf_dec9_enum),
1003 SOC_ENUM("TX10 HPF cut off", cf_dec10_enum),
1004
1005 SOC_SINGLE("TX1 HPF Switch", TABLA_A_CDC_TX1_MUX_CTL, 3, 1, 0),
1006 SOC_SINGLE("TX2 HPF Switch", TABLA_A_CDC_TX2_MUX_CTL, 3, 1, 0),
1007 SOC_SINGLE("TX3 HPF Switch", TABLA_A_CDC_TX3_MUX_CTL, 3, 1, 0),
1008 SOC_SINGLE("TX4 HPF Switch", TABLA_A_CDC_TX4_MUX_CTL, 3, 1, 0),
1009 SOC_SINGLE("TX5 HPF Switch", TABLA_A_CDC_TX5_MUX_CTL, 3, 1, 0),
1010 SOC_SINGLE("TX6 HPF Switch", TABLA_A_CDC_TX6_MUX_CTL, 3, 1, 0),
1011 SOC_SINGLE("TX7 HPF Switch", TABLA_A_CDC_TX7_MUX_CTL, 3, 1, 0),
1012 SOC_SINGLE("TX8 HPF Switch", TABLA_A_CDC_TX8_MUX_CTL, 3, 1, 0),
1013 SOC_SINGLE("TX9 HPF Switch", TABLA_A_CDC_TX9_MUX_CTL, 3, 1, 0),
1014 SOC_SINGLE("TX10 HPF Switch", TABLA_A_CDC_TX10_MUX_CTL, 3, 1, 0),
1015
1016 SOC_SINGLE("RX1 HPF Switch", TABLA_A_CDC_RX1_B5_CTL, 2, 1, 0),
1017 SOC_SINGLE("RX2 HPF Switch", TABLA_A_CDC_RX2_B5_CTL, 2, 1, 0),
1018 SOC_SINGLE("RX3 HPF Switch", TABLA_A_CDC_RX3_B5_CTL, 2, 1, 0),
1019 SOC_SINGLE("RX4 HPF Switch", TABLA_A_CDC_RX4_B5_CTL, 2, 1, 0),
1020 SOC_SINGLE("RX5 HPF Switch", TABLA_A_CDC_RX5_B5_CTL, 2, 1, 0),
1021 SOC_SINGLE("RX6 HPF Switch", TABLA_A_CDC_RX6_B5_CTL, 2, 1, 0),
1022 SOC_SINGLE("RX7 HPF Switch", TABLA_A_CDC_RX7_B5_CTL, 2, 1, 0),
1023
1024 SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum),
1025 SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum),
1026 SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum),
1027 SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum),
1028 SOC_ENUM("RX5 HPF cut off", cf_rxmix5_enum),
1029 SOC_ENUM("RX6 HPF cut off", cf_rxmix6_enum),
1030 SOC_ENUM("RX7 HPF cut off", cf_rxmix7_enum),
Ben Romberger1f045a72011-11-04 10:14:57 -07001031
1032 SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
1033 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1034 SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
1035 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1036 SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
1037 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1038 SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
1039 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1040 SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
1041 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1042 SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0,
1043 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1044 SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0,
1045 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1046 SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0,
1047 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1048 SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0,
1049 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1050 SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0,
1051 tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer),
1052
1053 SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
1054 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1055 SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
1056 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1057 SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
1058 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1059 SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
1060 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1061 SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
1062 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1063 SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5,
1064 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1065 SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5,
1066 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1067 SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5,
1068 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1069 SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5,
1070 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
1071 SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5,
1072 tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer),
Kuirong Wang0f8ade32012-02-27 16:29:45 -08001073 SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, 1, COMPANDER_1, 0,
1074 tabla_get_compander, tabla_set_compander),
1075 SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, 0, COMPANDER_2, 0,
1076 tabla_get_compander, tabla_set_compander),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001077};
1078
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08001079static const struct snd_kcontrol_new tabla_1_x_snd_controls[] = {
1080 SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_1_A_MICB_4_CTL, 4, 1, 1),
1081};
1082
1083static const struct snd_kcontrol_new tabla_2_higher_snd_controls[] = {
1084 SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_2_A_MICB_4_CTL, 4, 1, 1),
1085};
1086
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001087static const char *rx_mix1_text[] = {
1088 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
1089 "RX5", "RX6", "RX7"
1090};
1091
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001092static const char *rx_mix2_text[] = {
1093 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2"
1094};
1095
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001096static const char *rx_dsm_text[] = {
1097 "CIC_OUT", "DSM_INV"
1098};
1099
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001100static const char *sb_tx1_mux_text[] = {
1101 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1102 "DEC1"
1103};
1104
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001105static const char *sb_tx2_mux_text[] = {
1106 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1107 "DEC2"
1108};
1109
1110static const char *sb_tx3_mux_text[] = {
1111 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1112 "DEC3"
1113};
1114
1115static const char *sb_tx4_mux_text[] = {
1116 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1117 "DEC4"
1118};
1119
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001120static const char *sb_tx5_mux_text[] = {
1121 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1122 "DEC5"
1123};
1124
1125static const char *sb_tx6_mux_text[] = {
1126 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1127 "DEC6"
1128};
1129
1130static const char const *sb_tx7_to_tx10_mux_text[] = {
1131 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1132 "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
1133 "DEC9", "DEC10"
1134};
1135
1136static const char *dec1_mux_text[] = {
1137 "ZERO", "DMIC1", "ADC6",
1138};
1139
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001140static const char *dec2_mux_text[] = {
1141 "ZERO", "DMIC2", "ADC5",
1142};
1143
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001144static const char *dec3_mux_text[] = {
1145 "ZERO", "DMIC3", "ADC4",
1146};
1147
1148static const char *dec4_mux_text[] = {
1149 "ZERO", "DMIC4", "ADC3",
1150};
1151
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001152static const char *dec5_mux_text[] = {
1153 "ZERO", "DMIC5", "ADC2",
1154};
1155
1156static const char *dec6_mux_text[] = {
1157 "ZERO", "DMIC6", "ADC1",
1158};
1159
1160static const char const *dec7_mux_text[] = {
1161 "ZERO", "DMIC1", "DMIC6", "ADC1", "ADC6", "ANC1_FB", "ANC2_FB",
1162};
1163
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001164static const char *dec8_mux_text[] = {
1165 "ZERO", "DMIC2", "DMIC5", "ADC2", "ADC5",
1166};
1167
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001168static const char *dec9_mux_text[] = {
1169 "ZERO", "DMIC4", "DMIC5", "ADC2", "ADC3", "ADCMB", "ANC1_FB", "ANC2_FB",
1170};
1171
1172static const char *dec10_mux_text[] = {
1173 "ZERO", "DMIC3", "DMIC6", "ADC1", "ADC4", "ADCMB", "ANC1_FB", "ANC2_FB",
1174};
1175
Bradley Rubin229c6a52011-07-12 16:18:48 -07001176static const char const *anc_mux_text[] = {
1177 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6", "ADC_MB",
1178 "RSVD_1", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", "DMIC6"
1179};
1180
1181static const char const *anc1_fb_mux_text[] = {
1182 "ZERO", "EAR_HPH_L", "EAR_LINE_1",
1183};
1184
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001185static const char *iir1_inp1_text[] = {
1186 "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
1187 "DEC9", "DEC10", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7"
1188};
1189
1190static const struct soc_enum rx_mix1_inp1_chain_enum =
1191 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_mix1_text);
1192
Bradley Rubin229c6a52011-07-12 16:18:48 -07001193static const struct soc_enum rx_mix1_inp2_chain_enum =
1194 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_mix1_text);
1195
Kiran Kandia9fffe92012-05-20 23:42:30 -07001196static const struct soc_enum rx_mix1_inp3_chain_enum =
1197 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B2_CTL, 0, 12, rx_mix1_text);
1198
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001199static const struct soc_enum rx2_mix1_inp1_chain_enum =
1200 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_mix1_text);
1201
Bradley Rubin229c6a52011-07-12 16:18:48 -07001202static const struct soc_enum rx2_mix1_inp2_chain_enum =
1203 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_mix1_text);
1204
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001205static const struct soc_enum rx3_mix1_inp1_chain_enum =
1206 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 0, 12, rx_mix1_text);
1207
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001208static const struct soc_enum rx3_mix1_inp2_chain_enum =
1209 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 4, 12, rx_mix1_text);
1210
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001211static const struct soc_enum rx4_mix1_inp1_chain_enum =
1212 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 0, 12, rx_mix1_text);
1213
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001214static const struct soc_enum rx4_mix1_inp2_chain_enum =
1215 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 4, 12, rx_mix1_text);
1216
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001217static const struct soc_enum rx5_mix1_inp1_chain_enum =
1218 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 0, 12, rx_mix1_text);
1219
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001220static const struct soc_enum rx5_mix1_inp2_chain_enum =
1221 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 4, 12, rx_mix1_text);
1222
1223static const struct soc_enum rx6_mix1_inp1_chain_enum =
1224 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 0, 12, rx_mix1_text);
1225
1226static const struct soc_enum rx6_mix1_inp2_chain_enum =
1227 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 4, 12, rx_mix1_text);
1228
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001229static const struct soc_enum rx7_mix1_inp1_chain_enum =
1230 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 0, 12, rx_mix1_text);
1231
1232static const struct soc_enum rx7_mix1_inp2_chain_enum =
1233 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 4, 12, rx_mix1_text);
1234
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001235static const struct soc_enum rx1_mix2_inp1_chain_enum =
1236 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text);
1237
1238static const struct soc_enum rx1_mix2_inp2_chain_enum =
1239 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text);
1240
1241static const struct soc_enum rx2_mix2_inp1_chain_enum =
1242 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text);
1243
1244static const struct soc_enum rx2_mix2_inp2_chain_enum =
1245 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text);
1246
1247static const struct soc_enum rx3_mix2_inp1_chain_enum =
1248 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 0, 5, rx_mix2_text);
1249
1250static const struct soc_enum rx3_mix2_inp2_chain_enum =
1251 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 3, 5, rx_mix2_text);
1252
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001253static const struct soc_enum rx4_dsm_enum =
1254 SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B6_CTL, 4, 2, rx_dsm_text);
1255
1256static const struct soc_enum rx6_dsm_enum =
1257 SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B6_CTL, 4, 2, rx_dsm_text);
1258
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001259static const struct soc_enum sb_tx1_mux_enum =
1260 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text);
1261
1262static const struct soc_enum sb_tx2_mux_enum =
1263 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0, 9, sb_tx2_mux_text);
1264
1265static const struct soc_enum sb_tx3_mux_enum =
1266 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0, 9, sb_tx3_mux_text);
1267
1268static const struct soc_enum sb_tx4_mux_enum =
1269 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0, 9, sb_tx4_mux_text);
1270
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001271static const struct soc_enum sb_tx5_mux_enum =
1272 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text);
1273
1274static const struct soc_enum sb_tx6_mux_enum =
1275 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0, 9, sb_tx6_mux_text);
1276
1277static const struct soc_enum sb_tx7_mux_enum =
1278 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0, 18,
1279 sb_tx7_to_tx10_mux_text);
1280
1281static const struct soc_enum sb_tx8_mux_enum =
1282 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0, 18,
1283 sb_tx7_to_tx10_mux_text);
1284
Kiran Kandi3426e512011-09-13 22:50:10 -07001285static const struct soc_enum sb_tx9_mux_enum =
1286 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0, 18,
1287 sb_tx7_to_tx10_mux_text);
1288
1289static const struct soc_enum sb_tx10_mux_enum =
1290 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0, 18,
1291 sb_tx7_to_tx10_mux_text);
1292
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001293static const struct soc_enum dec1_mux_enum =
1294 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 0, 3, dec1_mux_text);
1295
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001296static const struct soc_enum dec2_mux_enum =
1297 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 2, 3, dec2_mux_text);
1298
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001299static const struct soc_enum dec3_mux_enum =
1300 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 4, 3, dec3_mux_text);
1301
1302static const struct soc_enum dec4_mux_enum =
1303 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 6, 3, dec4_mux_text);
1304
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001305static const struct soc_enum dec5_mux_enum =
1306 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 0, 3, dec5_mux_text);
1307
1308static const struct soc_enum dec6_mux_enum =
1309 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 2, 3, dec6_mux_text);
1310
1311static const struct soc_enum dec7_mux_enum =
1312 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 4, 7, dec7_mux_text);
1313
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001314static const struct soc_enum dec8_mux_enum =
1315 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 0, 7, dec8_mux_text);
1316
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001317static const struct soc_enum dec9_mux_enum =
1318 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 3, 8, dec9_mux_text);
1319
1320static const struct soc_enum dec10_mux_enum =
1321 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B4_CTL, 0, 8, dec10_mux_text);
1322
Bradley Rubin229c6a52011-07-12 16:18:48 -07001323static const struct soc_enum anc1_mux_enum =
1324 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 0, 16, anc_mux_text);
1325
1326static const struct soc_enum anc2_mux_enum =
1327 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 4, 16, anc_mux_text);
1328
1329static const struct soc_enum anc1_fb_mux_enum =
1330 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text);
1331
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001332static const struct soc_enum iir1_inp1_mux_enum =
1333 SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ1_B1_CTL, 0, 18, iir1_inp1_text);
1334
1335static const struct snd_kcontrol_new rx_mix1_inp1_mux =
1336 SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum);
1337
Bradley Rubin229c6a52011-07-12 16:18:48 -07001338static const struct snd_kcontrol_new rx_mix1_inp2_mux =
1339 SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum);
1340
Kiran Kandia9fffe92012-05-20 23:42:30 -07001341static const struct snd_kcontrol_new rx_mix1_inp3_mux =
1342 SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum);
1343
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001344static const struct snd_kcontrol_new rx2_mix1_inp1_mux =
1345 SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum);
1346
Bradley Rubin229c6a52011-07-12 16:18:48 -07001347static const struct snd_kcontrol_new rx2_mix1_inp2_mux =
1348 SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum);
1349
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001350static const struct snd_kcontrol_new rx3_mix1_inp1_mux =
1351 SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum);
1352
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001353static const struct snd_kcontrol_new rx3_mix1_inp2_mux =
1354 SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum);
1355
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001356static const struct snd_kcontrol_new rx4_mix1_inp1_mux =
1357 SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum);
1358
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001359static const struct snd_kcontrol_new rx4_mix1_inp2_mux =
1360 SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum);
1361
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001362static const struct snd_kcontrol_new rx5_mix1_inp1_mux =
1363 SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum);
1364
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001365static const struct snd_kcontrol_new rx5_mix1_inp2_mux =
1366 SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum);
1367
1368static const struct snd_kcontrol_new rx6_mix1_inp1_mux =
1369 SOC_DAPM_ENUM("RX6 MIX1 INP1 Mux", rx6_mix1_inp1_chain_enum);
1370
1371static const struct snd_kcontrol_new rx6_mix1_inp2_mux =
1372 SOC_DAPM_ENUM("RX6 MIX1 INP2 Mux", rx6_mix1_inp2_chain_enum);
1373
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07001374static const struct snd_kcontrol_new rx7_mix1_inp1_mux =
1375 SOC_DAPM_ENUM("RX7 MIX1 INP1 Mux", rx7_mix1_inp1_chain_enum);
1376
1377static const struct snd_kcontrol_new rx7_mix1_inp2_mux =
1378 SOC_DAPM_ENUM("RX7 MIX1 INP2 Mux", rx7_mix1_inp2_chain_enum);
1379
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08001380static const struct snd_kcontrol_new rx1_mix2_inp1_mux =
1381 SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum);
1382
1383static const struct snd_kcontrol_new rx1_mix2_inp2_mux =
1384 SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum);
1385
1386static const struct snd_kcontrol_new rx2_mix2_inp1_mux =
1387 SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum);
1388
1389static const struct snd_kcontrol_new rx2_mix2_inp2_mux =
1390 SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum);
1391
1392static const struct snd_kcontrol_new rx3_mix2_inp1_mux =
1393 SOC_DAPM_ENUM("RX3 MIX2 INP1 Mux", rx3_mix2_inp1_chain_enum);
1394
1395static const struct snd_kcontrol_new rx3_mix2_inp2_mux =
1396 SOC_DAPM_ENUM("RX3 MIX2 INP2 Mux", rx3_mix2_inp2_chain_enum);
1397
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001398static const struct snd_kcontrol_new rx4_dsm_mux =
1399 SOC_DAPM_ENUM("RX4 DSM MUX Mux", rx4_dsm_enum);
1400
1401static const struct snd_kcontrol_new rx6_dsm_mux =
1402 SOC_DAPM_ENUM("RX6 DSM MUX Mux", rx6_dsm_enum);
1403
Kiran Kandi1e6371d2012-03-29 11:48:57 -07001404static const struct snd_kcontrol_new sb_tx1_mux =
1405 SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum);
1406
1407static const struct snd_kcontrol_new sb_tx2_mux =
1408 SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum);
1409
1410static const struct snd_kcontrol_new sb_tx3_mux =
1411 SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum);
1412
1413static const struct snd_kcontrol_new sb_tx4_mux =
1414 SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum);
1415
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001416static const struct snd_kcontrol_new sb_tx5_mux =
1417 SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum);
1418
1419static const struct snd_kcontrol_new sb_tx6_mux =
1420 SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum);
1421
1422static const struct snd_kcontrol_new sb_tx7_mux =
1423 SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum);
1424
1425static const struct snd_kcontrol_new sb_tx8_mux =
1426 SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum);
1427
Kiran Kandi3426e512011-09-13 22:50:10 -07001428static const struct snd_kcontrol_new sb_tx9_mux =
1429 SOC_DAPM_ENUM("SLIM TX9 MUX Mux", sb_tx9_mux_enum);
1430
1431static const struct snd_kcontrol_new sb_tx10_mux =
1432 SOC_DAPM_ENUM("SLIM TX10 MUX Mux", sb_tx10_mux_enum);
1433
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001434
Kiran Kandi59a96b12012-01-16 02:20:03 -08001435static int wcd9310_put_dec_enum(struct snd_kcontrol *kcontrol,
1436 struct snd_ctl_elem_value *ucontrol)
1437{
1438 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1439 struct snd_soc_dapm_widget *w = wlist->widgets[0];
1440 struct snd_soc_codec *codec = w->codec;
1441 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1442 unsigned int dec_mux, decimator;
1443 char *dec_name = NULL;
1444 char *widget_name = NULL;
1445 char *temp;
1446 u16 tx_mux_ctl_reg;
1447 u8 adc_dmic_sel = 0x0;
1448 int ret = 0;
1449
1450 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1451 return -EINVAL;
1452
1453 dec_mux = ucontrol->value.enumerated.item[0];
1454
1455 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
1456 if (!widget_name)
1457 return -ENOMEM;
1458 temp = widget_name;
1459
1460 dec_name = strsep(&widget_name, " ");
1461 widget_name = temp;
1462 if (!dec_name) {
1463 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
1464 ret = -EINVAL;
1465 goto out;
1466 }
1467
1468 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
1469 if (ret < 0) {
1470 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
1471 ret = -EINVAL;
1472 goto out;
1473 }
1474
1475 dev_dbg(w->dapm->dev, "%s(): widget = %s dec_name = %s decimator = %u"
1476 " dec_mux = %u\n", __func__, w->name, dec_name, decimator,
1477 dec_mux);
1478
1479
1480 switch (decimator) {
1481 case 1:
1482 case 2:
1483 case 3:
1484 case 4:
1485 case 5:
1486 case 6:
1487 if (dec_mux == 1)
1488 adc_dmic_sel = 0x1;
1489 else
1490 adc_dmic_sel = 0x0;
1491 break;
1492 case 7:
1493 case 8:
1494 case 9:
1495 case 10:
1496 if ((dec_mux == 1) || (dec_mux == 2))
1497 adc_dmic_sel = 0x1;
1498 else
1499 adc_dmic_sel = 0x0;
1500 break;
1501 default:
1502 pr_err("%s: Invalid Decimator = %u\n", __func__, decimator);
1503 ret = -EINVAL;
1504 goto out;
1505 }
1506
1507 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
1508
1509 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel);
1510
1511 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1512
1513out:
1514 kfree(widget_name);
1515 return ret;
1516}
1517
1518#define WCD9310_DEC_ENUM(xname, xenum) \
1519{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1520 .info = snd_soc_info_enum_double, \
1521 .get = snd_soc_dapm_get_enum_double, \
1522 .put = wcd9310_put_dec_enum, \
1523 .private_value = (unsigned long)&xenum }
1524
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001525static const struct snd_kcontrol_new dec1_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001526 WCD9310_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001527
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001528static const struct snd_kcontrol_new dec2_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001529 WCD9310_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum);
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001530
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001531static const struct snd_kcontrol_new dec3_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001532 WCD9310_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001533
1534static const struct snd_kcontrol_new dec4_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001535 WCD9310_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001536
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001537static const struct snd_kcontrol_new dec5_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001538 WCD9310_DEC_ENUM("DEC5 MUX Mux", dec5_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001539
1540static const struct snd_kcontrol_new dec6_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001541 WCD9310_DEC_ENUM("DEC6 MUX Mux", dec6_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001542
1543static const struct snd_kcontrol_new dec7_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001544 WCD9310_DEC_ENUM("DEC7 MUX Mux", dec7_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001545
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001546static const struct snd_kcontrol_new dec8_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001547 WCD9310_DEC_ENUM("DEC8 MUX Mux", dec8_mux_enum);
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07001548
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001549static const struct snd_kcontrol_new dec9_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001550 WCD9310_DEC_ENUM("DEC9 MUX Mux", dec9_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001551
1552static const struct snd_kcontrol_new dec10_mux =
Kiran Kandi59a96b12012-01-16 02:20:03 -08001553 WCD9310_DEC_ENUM("DEC10 MUX Mux", dec10_mux_enum);
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07001554
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001555static const struct snd_kcontrol_new iir1_inp1_mux =
1556 SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum);
1557
Kiran Kandi59a96b12012-01-16 02:20:03 -08001558static const struct snd_kcontrol_new anc1_mux =
1559 SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum);
1560
Bradley Rubin229c6a52011-07-12 16:18:48 -07001561static const struct snd_kcontrol_new anc2_mux =
1562 SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001563
Bradley Rubin229c6a52011-07-12 16:18:48 -07001564static const struct snd_kcontrol_new anc1_fb_mux =
1565 SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001566
Bradley Rubin229c6a52011-07-12 16:18:48 -07001567static const struct snd_kcontrol_new dac1_switch[] = {
1568 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_EAR_EN, 5, 1, 0)
1569};
1570static const struct snd_kcontrol_new hphl_switch[] = {
1571 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_HPH_L_DAC_CTL, 6, 1, 0)
1572};
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001573
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001574static const struct snd_kcontrol_new hphl_pa_mix[] = {
1575 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1576 7, 1, 0),
1577 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1578 7, 1, 0),
1579 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1580 TABLA_A_AUX_L_PA_CONN_INV, 7, 1, 0),
1581 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1582 TABLA_A_AUX_R_PA_CONN_INV, 7, 1, 0),
1583};
1584
1585static const struct snd_kcontrol_new hphr_pa_mix[] = {
1586 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1587 6, 1, 0),
1588 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1589 6, 1, 0),
1590 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1591 TABLA_A_AUX_L_PA_CONN_INV, 6, 1, 0),
1592 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1593 TABLA_A_AUX_R_PA_CONN_INV, 6, 1, 0),
1594};
1595
1596static const struct snd_kcontrol_new lineout1_pa_mix[] = {
1597 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1598 5, 1, 0),
1599 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1600 5, 1, 0),
1601 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1602 TABLA_A_AUX_L_PA_CONN_INV, 5, 1, 0),
1603 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1604 TABLA_A_AUX_R_PA_CONN_INV, 5, 1, 0),
1605};
1606
1607static const struct snd_kcontrol_new lineout2_pa_mix[] = {
1608 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1609 4, 1, 0),
1610 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1611 4, 1, 0),
1612 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1613 TABLA_A_AUX_L_PA_CONN_INV, 4, 1, 0),
1614 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1615 TABLA_A_AUX_R_PA_CONN_INV, 4, 1, 0),
1616};
1617
1618static const struct snd_kcontrol_new lineout3_pa_mix[] = {
1619 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1620 3, 1, 0),
1621 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1622 3, 1, 0),
1623 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1624 TABLA_A_AUX_L_PA_CONN_INV, 3, 1, 0),
1625 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1626 TABLA_A_AUX_R_PA_CONN_INV, 3, 1, 0),
1627};
1628
1629static const struct snd_kcontrol_new lineout4_pa_mix[] = {
1630 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1631 2, 1, 0),
1632 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1633 2, 1, 0),
1634 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1635 TABLA_A_AUX_L_PA_CONN_INV, 2, 1, 0),
1636 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1637 TABLA_A_AUX_R_PA_CONN_INV, 2, 1, 0),
1638};
1639
1640static const struct snd_kcontrol_new lineout5_pa_mix[] = {
1641 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1642 1, 1, 0),
1643 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1644 1, 1, 0),
1645 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1646 TABLA_A_AUX_L_PA_CONN_INV, 1, 1, 0),
1647 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1648 TABLA_A_AUX_R_PA_CONN_INV, 1, 1, 0),
1649};
1650
1651static const struct snd_kcontrol_new ear_pa_mix[] = {
1652 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN,
1653 0, 1, 0),
1654 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN,
1655 0, 1, 0),
1656 SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch",
1657 TABLA_A_AUX_L_PA_CONN_INV, 0, 1, 0),
1658 SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch",
1659 TABLA_A_AUX_R_PA_CONN_INV, 0, 1, 0),
1660};
1661
Kiran Kandi8b3a8302011-09-27 16:13:28 -07001662static const struct snd_kcontrol_new lineout3_ground_switch =
1663 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_3_DAC_CTL, 6, 1, 0);
1664
1665static const struct snd_kcontrol_new lineout4_ground_switch =
1666 SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_4_DAC_CTL, 6, 1, 0);
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07001667
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001668static void tabla_codec_enable_adc_block(struct snd_soc_codec *codec,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001669 int enable)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001670{
1671 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1672
1673 pr_debug("%s %d\n", __func__, enable);
1674
1675 if (enable) {
1676 tabla->adc_count++;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001677 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x2, 0x2);
1678 } else {
1679 tabla->adc_count--;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001680 if (!tabla->adc_count)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001681 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL,
Joonwoo Park03324832012-03-19 19:36:16 -07001682 0x2, 0x0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001683 }
1684}
1685
1686static int tabla_codec_enable_adc(struct snd_soc_dapm_widget *w,
1687 struct snd_kcontrol *kcontrol, int event)
1688{
1689 struct snd_soc_codec *codec = w->codec;
1690 u16 adc_reg;
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08001691 u8 init_bit_shift;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001692
1693 pr_debug("%s %d\n", __func__, event);
1694
1695 if (w->reg == TABLA_A_TX_1_2_EN)
1696 adc_reg = TABLA_A_TX_1_2_TEST_CTL;
1697 else if (w->reg == TABLA_A_TX_3_4_EN)
1698 adc_reg = TABLA_A_TX_3_4_TEST_CTL;
1699 else if (w->reg == TABLA_A_TX_5_6_EN)
1700 adc_reg = TABLA_A_TX_5_6_TEST_CTL;
1701 else {
1702 pr_err("%s: Error, invalid adc register\n", __func__);
1703 return -EINVAL;
1704 }
1705
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08001706 if (w->shift == 3)
1707 init_bit_shift = 6;
1708 else if (w->shift == 7)
1709 init_bit_shift = 7;
1710 else {
1711 pr_err("%s: Error, invalid init bit postion adc register\n",
1712 __func__);
1713 return -EINVAL;
1714 }
1715
1716
1717
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001718 switch (event) {
1719 case SND_SOC_DAPM_PRE_PMU:
1720 tabla_codec_enable_adc_block(codec, 1);
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08001721 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift,
1722 1 << init_bit_shift);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001723 break;
1724 case SND_SOC_DAPM_POST_PMU:
Kiran Kandi9a2c62a82011-12-07 13:13:26 -08001725
1726 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00);
1727
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001728 break;
1729 case SND_SOC_DAPM_POST_PMD:
1730 tabla_codec_enable_adc_block(codec, 0);
1731 break;
1732 }
1733 return 0;
1734}
1735
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001736static void tabla_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec)
1737{
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001738 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
1739 0x80);
1740 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x04,
1741 0x04);
1742 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01,
1743 0x01);
1744 usleep_range(1000, 1000);
1745 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
1746 0x00);
1747}
1748
1749static void tabla_codec_enable_bandgap(struct snd_soc_codec *codec,
1750 enum tabla_bandgap_type choice)
1751{
1752 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1753
1754 /* TODO lock resources accessed by audio streams and threaded
1755 * interrupt handlers
1756 */
1757
1758 pr_debug("%s, choice is %d, current is %d\n", __func__, choice,
1759 tabla->bandgap_type);
1760
1761 if (tabla->bandgap_type == choice)
1762 return;
1763
1764 if ((tabla->bandgap_type == TABLA_BANDGAP_OFF) &&
1765 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
1766 tabla_codec_enable_audio_mode_bandgap(codec);
1767 } else if (choice == TABLA_BANDGAP_MBHC_MODE) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001768 /* bandgap mode becomes fast,
1769 * mclk should be off or clk buff source souldn't be VBG
1770 * Let's turn off mclk always */
1771 WARN_ON(snd_soc_read(codec, TABLA_A_CLK_BUFF_EN2) & (1 << 2));
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001772 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x2,
1773 0x2);
1774 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
1775 0x80);
1776 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x4,
1777 0x4);
1778 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01,
1779 0x01);
1780 usleep_range(1000, 1000);
1781 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80,
1782 0x00);
1783 } else if ((tabla->bandgap_type == TABLA_BANDGAP_MBHC_MODE) &&
1784 (choice == TABLA_BANDGAP_AUDIO_MODE)) {
1785 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x00);
1786 usleep_range(100, 100);
1787 tabla_codec_enable_audio_mode_bandgap(codec);
1788 } else if (choice == TABLA_BANDGAP_OFF) {
1789 snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x00);
1790 } else {
1791 pr_err("%s: Error, Invalid bandgap settings\n", __func__);
1792 }
1793 tabla->bandgap_type = choice;
1794}
1795
1796static void tabla_codec_disable_clock_block(struct snd_soc_codec *codec)
1797{
1798 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1799 pr_debug("%s\n", __func__);
1800 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x00);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001801 usleep_range(50, 50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001802 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x02);
1803 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x00);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001804 usleep_range(50, 50);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001805 tabla->clock_active = false;
1806}
1807
1808static int tabla_codec_mclk_index(const struct tabla_priv *tabla)
1809{
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001810 if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001811 return 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07001812 else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001813 return 1;
1814 else {
1815 BUG_ON(1);
1816 return -EINVAL;
1817 }
1818}
1819
1820static void tabla_enable_rx_bias(struct snd_soc_codec *codec, u32 enable)
1821{
1822 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1823
1824 if (enable) {
1825 tabla->rx_bias_count++;
1826 if (tabla->rx_bias_count == 1)
1827 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
1828 0x80, 0x80);
1829 } else {
1830 tabla->rx_bias_count--;
1831 if (!tabla->rx_bias_count)
1832 snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS,
1833 0x80, 0x00);
1834 }
1835}
1836
1837static int tabla_codec_enable_config_mode(struct snd_soc_codec *codec,
1838 int enable)
1839{
1840 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1841
1842 pr_debug("%s: enable = %d\n", __func__, enable);
1843 if (enable) {
1844 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x10, 0);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001845 /* bandgap mode to fast */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001846 snd_soc_write(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x17);
1847 usleep_range(5, 5);
1848 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001849 0x80);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001850 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001851 0x80);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001852 usleep_range(10, 10);
1853 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, 0);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001854 usleep_range(10000, 10000);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001855 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x08);
1856 } else {
1857 snd_soc_update_bits(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x1,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001858 0);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001859 snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, 0);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001860 /* clk source to ext clk and clk buff ref to VBG */
1861 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x0C, 0x04);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001862 }
1863 tabla->config_mode_active = enable ? true : false;
1864
1865 return 0;
1866}
1867
1868static int tabla_codec_enable_clock_block(struct snd_soc_codec *codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001869 int config_mode)
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001870{
1871 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1872
1873 pr_debug("%s: config_mode = %d\n", __func__, config_mode);
1874
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001875 /* transit to RCO requires mclk off */
1876 WARN_ON(snd_soc_read(codec, TABLA_A_CLK_BUFF_EN2) & (1 << 2));
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001877 if (config_mode) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001878 /* enable RCO and switch to it */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001879 tabla_codec_enable_config_mode(codec, 1);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001880 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001881 usleep_range(1000, 1000);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001882 } else {
1883 /* switch to MCLK */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001884 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00);
1885
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001886 if (tabla->mbhc_polling_active) {
1887 snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02);
1888 tabla_codec_enable_config_mode(codec, 0);
1889 }
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001890 }
1891
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001892 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x01, 0x01);
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001893 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x00);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07001894 /* on MCLK */
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08001895 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x04);
1896 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_MCLK_CTL, 0x01, 0x01);
1897 usleep_range(50, 50);
1898 tabla->clock_active = true;
1899 return 0;
1900}
1901
1902static int tabla_codec_enable_aux_pga(struct snd_soc_dapm_widget *w,
1903 struct snd_kcontrol *kcontrol, int event)
1904{
1905 struct snd_soc_codec *codec = w->codec;
1906 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
1907
1908 pr_debug("%s: %d\n", __func__, event);
1909
1910 switch (event) {
1911 case SND_SOC_DAPM_PRE_PMU:
1912 tabla_codec_enable_bandgap(codec,
1913 TABLA_BANDGAP_AUDIO_MODE);
1914 tabla_enable_rx_bias(codec, 1);
1915
1916 snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL,
1917 0x08, 0x08);
1918 /* Enable Zero Cross detect for AUX PGA channel
1919 * and set the initial AUX PGA gain to NEG_0P0_DB
1920 * to avoid glitches.
1921 */
1922 if (w->reg == TABLA_A_AUX_L_EN) {
1923 snd_soc_update_bits(codec, TABLA_A_AUX_L_EN,
1924 0x20, 0x20);
1925 tabla->aux_l_gain = snd_soc_read(codec,
1926 TABLA_A_AUX_L_GAIN);
1927 snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F);
1928 } else {
1929 snd_soc_update_bits(codec, TABLA_A_AUX_R_EN,
1930 0x20, 0x20);
1931 tabla->aux_r_gain = snd_soc_read(codec,
1932 TABLA_A_AUX_R_GAIN);
1933 snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F);
1934 }
1935 if (tabla->aux_pga_cnt++ == 1
1936 && !tabla->mclk_enabled) {
1937 tabla_codec_enable_clock_block(codec, 1);
1938 pr_debug("AUX PGA enabled RC osc\n");
1939 }
1940 break;
1941
1942 case SND_SOC_DAPM_POST_PMU:
1943 if (w->reg == TABLA_A_AUX_L_EN)
1944 snd_soc_write(codec, TABLA_A_AUX_L_GAIN,
1945 tabla->aux_l_gain);
1946 else
1947 snd_soc_write(codec, TABLA_A_AUX_R_GAIN,
1948 tabla->aux_r_gain);
1949 break;
1950
1951 case SND_SOC_DAPM_PRE_PMD:
1952 /* Mute AUX PGA channel in use before disabling AUX PGA */
1953 if (w->reg == TABLA_A_AUX_L_EN) {
1954 tabla->aux_l_gain = snd_soc_read(codec,
1955 TABLA_A_AUX_L_GAIN);
1956 snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F);
1957 } else {
1958 tabla->aux_r_gain = snd_soc_read(codec,
1959 TABLA_A_AUX_R_GAIN);
1960 snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F);
1961 }
1962 break;
1963
1964 case SND_SOC_DAPM_POST_PMD:
1965 tabla_enable_rx_bias(codec, 0);
1966
1967 snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL,
1968 0x08, 0x00);
1969 if (w->reg == TABLA_A_AUX_L_EN) {
1970 snd_soc_write(codec, TABLA_A_AUX_L_GAIN,
1971 tabla->aux_l_gain);
1972 snd_soc_update_bits(codec, TABLA_A_AUX_L_EN,
1973 0x20, 0x00);
1974 } else {
1975 snd_soc_write(codec, TABLA_A_AUX_R_GAIN,
1976 tabla->aux_r_gain);
1977 snd_soc_update_bits(codec, TABLA_A_AUX_R_EN,
1978 0x20, 0x00);
1979 }
1980
1981 if (tabla->aux_pga_cnt-- == 0) {
1982 if (tabla->mbhc_polling_active)
1983 tabla_codec_enable_bandgap(codec,
1984 TABLA_BANDGAP_MBHC_MODE);
1985 else
1986 tabla_codec_enable_bandgap(codec,
1987 TABLA_BANDGAP_OFF);
1988
1989 if (!tabla->mclk_enabled &&
1990 !tabla->mbhc_polling_active) {
1991 tabla_codec_enable_clock_block(codec, 0);
1992 }
1993 }
1994 break;
1995 }
1996 return 0;
1997}
1998
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001999static int tabla_codec_enable_lineout(struct snd_soc_dapm_widget *w,
2000 struct snd_kcontrol *kcontrol, int event)
2001{
2002 struct snd_soc_codec *codec = w->codec;
2003 u16 lineout_gain_reg;
2004
Kiran Kandidb0a4b02011-08-23 09:32:09 -07002005 pr_debug("%s %d %s\n", __func__, event, w->name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002006
2007 switch (w->shift) {
2008 case 0:
2009 lineout_gain_reg = TABLA_A_RX_LINE_1_GAIN;
2010 break;
2011 case 1:
2012 lineout_gain_reg = TABLA_A_RX_LINE_2_GAIN;
2013 break;
2014 case 2:
2015 lineout_gain_reg = TABLA_A_RX_LINE_3_GAIN;
2016 break;
2017 case 3:
2018 lineout_gain_reg = TABLA_A_RX_LINE_4_GAIN;
2019 break;
2020 case 4:
2021 lineout_gain_reg = TABLA_A_RX_LINE_5_GAIN;
2022 break;
2023 default:
2024 pr_err("%s: Error, incorrect lineout register value\n",
2025 __func__);
2026 return -EINVAL;
2027 }
2028
2029 switch (event) {
2030 case SND_SOC_DAPM_PRE_PMU:
2031 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40);
2032 break;
2033 case SND_SOC_DAPM_POST_PMU:
Krishnankutty Kolathappilly31169f42011-11-17 10:33:11 -08002034 pr_debug("%s: sleeping 16 ms after %s PA turn on\n",
Kiran Kandidb0a4b02011-08-23 09:32:09 -07002035 __func__, w->name);
Krishnankutty Kolathappilly31169f42011-11-17 10:33:11 -08002036 usleep_range(16000, 16000);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002037 break;
2038 case SND_SOC_DAPM_POST_PMD:
2039 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00);
2040 break;
2041 }
2042 return 0;
2043}
2044
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002045
2046static int tabla_codec_enable_dmic(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002047 struct snd_kcontrol *kcontrol, int event)
2048{
2049 struct snd_soc_codec *codec = w->codec;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002050 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2051 u8 dmic_clk_en;
2052 s32 *dmic_clk_cnt;
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002053 unsigned int dmic;
2054 int ret;
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002055
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002056 ret = kstrtouint(strpbrk(w->name, "123456"), 10, &dmic);
2057 if (ret < 0) {
2058 pr_err("%s: Invalid DMIC line on the codec\n", __func__);
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002059 return -EINVAL;
2060 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002061
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002062 switch (dmic) {
2063 case 1:
2064 case 2:
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002065 dmic_clk_en = 0x01;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002066 dmic_clk_cnt = &(tabla->dmic_1_2_clk_cnt);
2067
2068 pr_debug("%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n",
2069 __func__, event, dmic, *dmic_clk_cnt);
2070
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002071 break;
2072
2073 case 3:
2074 case 4:
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002075 dmic_clk_en = 0x04;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002076 dmic_clk_cnt = &(tabla->dmic_3_4_clk_cnt);
2077
2078 pr_debug("%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n",
2079 __func__, event, dmic, *dmic_clk_cnt);
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002080 break;
2081
2082 case 5:
2083 case 6:
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002084 dmic_clk_en = 0x10;
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002085 dmic_clk_cnt = &(tabla->dmic_5_6_clk_cnt);
2086
2087 pr_debug("%s() event %d DMIC%d dmic_5_6_clk_cnt %d\n",
2088 __func__, event, dmic, *dmic_clk_cnt);
2089
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07002090 break;
2091
2092 default:
2093 pr_err("%s: Invalid DMIC Selection\n", __func__);
2094 return -EINVAL;
2095 }
2096
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002097 switch (event) {
2098 case SND_SOC_DAPM_PRE_PMU:
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002099
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002100 (*dmic_clk_cnt)++;
2101 if (*dmic_clk_cnt == 1)
2102 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
2103 dmic_clk_en, dmic_clk_en);
Kiran Kandicf45f6a2011-07-17 21:10:19 -07002104
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002105 break;
2106 case SND_SOC_DAPM_POST_PMD:
Kiran Kandi0ba468f2012-05-08 11:45:05 -07002107
2108 (*dmic_clk_cnt)--;
2109 if (*dmic_clk_cnt == 0)
2110 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL,
2111 dmic_clk_en, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002112 break;
2113 }
2114 return 0;
2115}
2116
Bradley Rubin229c6a52011-07-12 16:18:48 -07002117static int tabla_codec_enable_anc(struct snd_soc_dapm_widget *w,
2118 struct snd_kcontrol *kcontrol, int event)
2119{
2120 struct snd_soc_codec *codec = w->codec;
2121 const char *filename;
2122 const struct firmware *fw;
2123 int i;
2124 int ret;
Bradley Rubina7096d02011-08-03 18:29:02 -07002125 int num_anc_slots;
2126 struct anc_header *anc_head;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002127 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubina7096d02011-08-03 18:29:02 -07002128 u32 anc_writes_size = 0;
2129 int anc_size_remaining;
2130 u32 *anc_ptr;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002131 u16 reg;
2132 u8 mask, val, old_val;
2133
2134 pr_debug("%s %d\n", __func__, event);
2135 switch (event) {
2136 case SND_SOC_DAPM_PRE_PMU:
2137
Bradley Rubin4283a4c2011-07-29 16:18:54 -07002138 filename = "wcd9310/wcd9310_anc.bin";
Bradley Rubin229c6a52011-07-12 16:18:48 -07002139
2140 ret = request_firmware(&fw, filename, codec->dev);
2141 if (ret != 0) {
2142 dev_err(codec->dev, "Failed to acquire ANC data: %d\n",
2143 ret);
2144 return -ENODEV;
2145 }
2146
Bradley Rubina7096d02011-08-03 18:29:02 -07002147 if (fw->size < sizeof(struct anc_header)) {
Bradley Rubin229c6a52011-07-12 16:18:48 -07002148 dev_err(codec->dev, "Not enough data\n");
2149 release_firmware(fw);
2150 return -ENOMEM;
2151 }
2152
2153 /* First number is the number of register writes */
Bradley Rubina7096d02011-08-03 18:29:02 -07002154 anc_head = (struct anc_header *)(fw->data);
2155 anc_ptr = (u32 *)((u32)fw->data + sizeof(struct anc_header));
2156 anc_size_remaining = fw->size - sizeof(struct anc_header);
2157 num_anc_slots = anc_head->num_anc_slots;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002158
Bradley Rubina7096d02011-08-03 18:29:02 -07002159 if (tabla->anc_slot >= num_anc_slots) {
2160 dev_err(codec->dev, "Invalid ANC slot selected\n");
2161 release_firmware(fw);
2162 return -EINVAL;
2163 }
2164
2165 for (i = 0; i < num_anc_slots; i++) {
2166
2167 if (anc_size_remaining < TABLA_PACKED_REG_SIZE) {
2168 dev_err(codec->dev, "Invalid register format\n");
2169 release_firmware(fw);
2170 return -EINVAL;
2171 }
2172 anc_writes_size = (u32)(*anc_ptr);
2173 anc_size_remaining -= sizeof(u32);
2174 anc_ptr += 1;
2175
2176 if (anc_writes_size * TABLA_PACKED_REG_SIZE
2177 > anc_size_remaining) {
2178 dev_err(codec->dev, "Invalid register format\n");
2179 release_firmware(fw);
2180 return -ENOMEM;
2181 }
2182
2183 if (tabla->anc_slot == i)
2184 break;
2185
2186 anc_size_remaining -= (anc_writes_size *
2187 TABLA_PACKED_REG_SIZE);
Bradley Rubin939ff3f2011-08-26 17:19:34 -07002188 anc_ptr += anc_writes_size;
Bradley Rubina7096d02011-08-03 18:29:02 -07002189 }
2190 if (i == num_anc_slots) {
2191 dev_err(codec->dev, "Selected ANC slot not present\n");
Bradley Rubin229c6a52011-07-12 16:18:48 -07002192 release_firmware(fw);
2193 return -ENOMEM;
2194 }
2195
Bradley Rubina7096d02011-08-03 18:29:02 -07002196 for (i = 0; i < anc_writes_size; i++) {
2197 TABLA_CODEC_UNPACK_ENTRY(anc_ptr[i], reg,
Bradley Rubin229c6a52011-07-12 16:18:48 -07002198 mask, val);
2199 old_val = snd_soc_read(codec, reg);
Bradley Rubin4283a4c2011-07-29 16:18:54 -07002200 snd_soc_write(codec, reg, (old_val & ~mask) |
2201 (val & mask));
Bradley Rubin229c6a52011-07-12 16:18:48 -07002202 }
2203 release_firmware(fw);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002204
Joonwoo Park743d0e32012-05-17 15:11:58 -07002205 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
2206 /* if MBHC polling is active, set TX7_MBHC_EN bit 7 */
2207 if (tabla->mbhc_polling_active)
2208 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80,
2209 0x80);
2210 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002211 break;
2212 case SND_SOC_DAPM_POST_PMD:
Joonwoo Park743d0e32012-05-17 15:11:58 -07002213 /* unset TX7_MBHC_EN bit 7 */
2214 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00);
2215
Bradley Rubin229c6a52011-07-12 16:18:48 -07002216 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0xFF);
2217 snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_CLK_EN_CTL, 0);
2218 break;
2219 }
2220 return 0;
2221}
2222
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002223/* called under codec_resource_lock acquisition */
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002224static void tabla_codec_start_hs_polling(struct snd_soc_codec *codec)
2225{
Bradley Rubincb3950a2011-08-18 13:07:26 -07002226 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07002227 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
2228 int mbhc_state = tabla->mbhc_state;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002229
Joonwoo Park03324832012-03-19 19:36:16 -07002230 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002231 if (!tabla->mbhc_polling_active) {
2232 pr_debug("Polling is not active, do not start polling\n");
2233 return;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002234 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002235 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Joonwoo Park03324832012-03-19 19:36:16 -07002236
2237 if (!tabla->no_mic_headset_override) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002238 if (mbhc_state == MBHC_STATE_POTENTIAL) {
2239 pr_debug("%s recovering MBHC state macine\n", __func__);
2240 tabla->mbhc_state = MBHC_STATE_POTENTIAL_RECOVERY;
Joonwoo Park03324832012-03-19 19:36:16 -07002241 /* set to max button press threshold */
2242 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
2243 0x7F);
2244 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
2245 0xFF);
2246 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL,
2247 (TABLA_IS_1_X(tabla_core->version) ?
2248 0x07 : 0x7F));
2249 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL,
2250 0xFF);
2251 /* set to max */
2252 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL,
2253 0x7F);
2254 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL,
2255 0xFF);
2256 }
2257 }
2258
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002259 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
2260 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
2261 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1);
Joonwoo Park03324832012-03-19 19:36:16 -07002262 pr_debug("%s: leave\n", __func__);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002263}
2264
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002265/* called under codec_resource_lock acquisition */
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002266static void tabla_codec_pause_hs_polling(struct snd_soc_codec *codec)
2267{
Bradley Rubincb3950a2011-08-18 13:07:26 -07002268 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2269
Joonwoo Park03324832012-03-19 19:36:16 -07002270 pr_debug("%s: enter\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002271 if (!tabla->mbhc_polling_active) {
2272 pr_debug("polling not active, nothing to pause\n");
2273 return;
Bradley Rubincb3950a2011-08-18 13:07:26 -07002274 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002275
2276 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
Joonwoo Park03324832012-03-19 19:36:16 -07002277 pr_debug("%s: leave\n", __func__);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002278}
2279
Joonwoo Park03324832012-03-19 19:36:16 -07002280static void tabla_codec_switch_cfilt_mode(struct snd_soc_codec *codec, int mode)
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002281{
2282 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2283 u8 reg_mode_val, cur_mode_val;
2284 bool mbhc_was_polling = false;
2285
2286 if (mode)
2287 reg_mode_val = TABLA_CFILT_FAST_MODE;
2288 else
2289 reg_mode_val = TABLA_CFILT_SLOW_MODE;
2290
2291 cur_mode_val = snd_soc_read(codec,
2292 tabla->mbhc_bias_regs.cfilt_ctl) & 0x40;
2293
2294 if (cur_mode_val != reg_mode_val) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002295 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002296 if (tabla->mbhc_polling_active) {
2297 tabla_codec_pause_hs_polling(codec);
2298 mbhc_was_polling = true;
2299 }
2300 snd_soc_update_bits(codec,
2301 tabla->mbhc_bias_regs.cfilt_ctl, 0x40, reg_mode_val);
2302 if (mbhc_was_polling)
2303 tabla_codec_start_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002304 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08002305 pr_debug("%s: CFILT mode change (%x to %x)\n", __func__,
2306 cur_mode_val, reg_mode_val);
2307 } else {
2308 pr_debug("%s: CFILT Value is already %x\n",
2309 __func__, cur_mode_val);
2310 }
2311}
2312
2313static void tabla_codec_update_cfilt_usage(struct snd_soc_codec *codec,
2314 u8 cfilt_sel, int inc)
2315{
2316 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2317 u32 *cfilt_cnt_ptr = NULL;
2318 u16 micb_cfilt_reg;
2319
2320 switch (cfilt_sel) {
2321 case TABLA_CFILT1_SEL:
2322 cfilt_cnt_ptr = &tabla->cfilt1_cnt;
2323 micb_cfilt_reg = TABLA_A_MICB_CFILT_1_CTL;
2324 break;
2325 case TABLA_CFILT2_SEL:
2326 cfilt_cnt_ptr = &tabla->cfilt2_cnt;
2327 micb_cfilt_reg = TABLA_A_MICB_CFILT_2_CTL;
2328 break;
2329 case TABLA_CFILT3_SEL:
2330 cfilt_cnt_ptr = &tabla->cfilt3_cnt;
2331 micb_cfilt_reg = TABLA_A_MICB_CFILT_3_CTL;
2332 break;
2333 default:
2334 return; /* should not happen */
2335 }
2336
2337 if (inc) {
2338 if (!(*cfilt_cnt_ptr)++) {
2339 /* Switch CFILT to slow mode if MBHC CFILT being used */
2340 if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel)
2341 tabla_codec_switch_cfilt_mode(codec, 0);
2342
2343 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80);
2344 }
2345 } else {
2346 /* check if count not zero, decrement
2347 * then check if zero, go ahead disable cfilter
2348 */
2349 if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr)) {
2350 snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0);
2351
2352 /* Switch CFILT to fast mode if MBHC CFILT being used */
2353 if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel)
2354 tabla_codec_switch_cfilt_mode(codec, 1);
2355 }
2356 }
2357}
2358
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002359static int tabla_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv)
2360{
2361 int rc = -EINVAL;
2362 unsigned min_mv, max_mv;
2363
2364 switch (ldoh_v) {
2365 case TABLA_LDOH_1P95_V:
2366 min_mv = 160;
2367 max_mv = 1800;
2368 break;
2369 case TABLA_LDOH_2P35_V:
2370 min_mv = 200;
2371 max_mv = 2200;
2372 break;
2373 case TABLA_LDOH_2P75_V:
2374 min_mv = 240;
2375 max_mv = 2600;
2376 break;
2377 case TABLA_LDOH_2P85_V:
2378 min_mv = 250;
2379 max_mv = 2700;
2380 break;
2381 default:
2382 goto done;
2383 }
2384
2385 if (cfilt_mv < min_mv || cfilt_mv > max_mv)
2386 goto done;
2387
2388 for (rc = 4; rc <= 44; rc++) {
2389 min_mv = max_mv * (rc) / 44;
2390 if (min_mv >= cfilt_mv) {
2391 rc -= 4;
2392 break;
2393 }
2394 }
2395done:
2396 return rc;
2397}
2398
2399static bool tabla_is_hph_pa_on(struct snd_soc_codec *codec)
2400{
2401 u8 hph_reg_val = 0;
2402 hph_reg_val = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_EN);
2403
2404 return (hph_reg_val & 0x30) ? true : false;
2405}
2406
Joonwoo Parka9444452011-12-08 18:48:27 -08002407static bool tabla_is_hph_dac_on(struct snd_soc_codec *codec, int left)
2408{
2409 u8 hph_reg_val = 0;
2410 if (left)
2411 hph_reg_val = snd_soc_read(codec,
2412 TABLA_A_RX_HPH_L_DAC_CTL);
2413 else
2414 hph_reg_val = snd_soc_read(codec,
2415 TABLA_A_RX_HPH_R_DAC_CTL);
2416
2417 return (hph_reg_val & 0xC0) ? true : false;
2418}
2419
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002420static void tabla_turn_onoff_override(struct snd_soc_codec *codec, bool on)
2421{
2422 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, on << 2);
2423}
2424
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002425/* called under codec_resource_lock acquisition */
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002426static void tabla_codec_drive_v_to_micbias(struct snd_soc_codec *codec,
2427 int usec)
2428{
2429 int cfilt_k_val;
2430 bool set = true;
2431 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2432
2433 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
2434 tabla->mbhc_micbias_switched) {
2435 pr_debug("%s: set mic V to micbias V\n", __func__);
2436 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
2437 tabla_turn_onoff_override(codec, true);
2438 while (1) {
2439 cfilt_k_val = tabla_find_k_value(
2440 tabla->pdata->micbias.ldoh_v,
2441 set ? tabla->mbhc_data.micb_mv :
2442 VDDIO_MICBIAS_MV);
2443 snd_soc_update_bits(codec,
2444 tabla->mbhc_bias_regs.cfilt_val,
2445 0xFC, (cfilt_k_val << 2));
2446 if (!set)
2447 break;
2448 usleep_range(usec, usec);
2449 set = false;
2450 }
2451 tabla_turn_onoff_override(codec, false);
2452 }
2453}
2454
2455/* called under codec_resource_lock acquisition */
2456static void __tabla_codec_switch_micbias(struct snd_soc_codec *codec,
2457 int vddio_switch, bool restartpolling,
2458 bool checkpolling)
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002459{
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002460 int cfilt_k_val;
Joonwoo Park41956722012-04-18 13:13:07 -07002461 bool override;
2462 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002463
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002464 if (vddio_switch && !tabla->mbhc_micbias_switched &&
2465 (!checkpolling || tabla->mbhc_polling_active)) {
2466 if (restartpolling)
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08002467 tabla_codec_pause_hs_polling(codec);
Joonwoo Park41956722012-04-18 13:13:07 -07002468 override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04;
2469 if (!override)
2470 tabla_turn_onoff_override(codec, true);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002471 /* Adjust threshold if Mic Bias voltage changes */
2472 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002473 cfilt_k_val = tabla_find_k_value(
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002474 tabla->pdata->micbias.ldoh_v,
2475 VDDIO_MICBIAS_MV);
2476 usleep_range(10000, 10000);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002477 snd_soc_update_bits(codec,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002478 tabla->mbhc_bias_regs.cfilt_val,
2479 0xFC, (cfilt_k_val << 2));
2480 usleep_range(10000, 10000);
2481 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
2482 tabla->mbhc_data.adj_v_ins_hu & 0xFF);
2483 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
2484 (tabla->mbhc_data.adj_v_ins_hu >> 8) &
2485 0xFF);
2486 pr_debug("%s: Programmed MBHC thresholds to VDDIO\n",
2487 __func__);
2488 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002489
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002490 /* enable MIC BIAS Switch to VDDIO */
2491 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2492 0x80, 0x80);
2493 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2494 0x10, 0x00);
Joonwoo Park41956722012-04-18 13:13:07 -07002495 if (!override)
2496 tabla_turn_onoff_override(codec, false);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002497 if (restartpolling)
Bhalchandra Gajarec1e19c42011-11-18 11:22:56 -08002498 tabla_codec_start_hs_polling(codec);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002499
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002500 tabla->mbhc_micbias_switched = true;
2501 pr_debug("%s: VDDIO switch enabled\n", __func__);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002502 } else if (!vddio_switch && tabla->mbhc_micbias_switched) {
2503 if ((!checkpolling || tabla->mbhc_polling_active) &&
2504 restartpolling)
2505 tabla_codec_pause_hs_polling(codec);
2506 /* Reprogram thresholds */
2507 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
2508 cfilt_k_val = tabla_find_k_value(
2509 tabla->pdata->micbias.ldoh_v,
2510 tabla->mbhc_data.micb_mv);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002511 snd_soc_update_bits(codec,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002512 tabla->mbhc_bias_regs.cfilt_val,
2513 0xFC, (cfilt_k_val << 2));
2514 usleep_range(10000, 10000);
2515 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
2516 tabla->mbhc_data.v_ins_hu & 0xFF);
2517 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
2518 (tabla->mbhc_data.v_ins_hu >> 8) & 0xFF);
2519 pr_debug("%s: Programmed MBHC thresholds to MICBIAS\n",
2520 __func__);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002521 }
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002522
2523 /* Disable MIC BIAS Switch to VDDIO */
2524 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2525 0x80, 0x00);
2526 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
2527 0x10, 0x00);
2528
2529 if ((!checkpolling || tabla->mbhc_polling_active) &&
2530 restartpolling)
2531 tabla_codec_start_hs_polling(codec);
2532
2533 tabla->mbhc_micbias_switched = false;
2534 pr_debug("%s: VDDIO switch disabled\n", __func__);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002535 }
2536}
2537
Joonwoo Parkcf473b42012-03-29 19:48:16 -07002538static void tabla_codec_switch_micbias(struct snd_soc_codec *codec,
2539 int vddio_switch)
2540{
2541 return __tabla_codec_switch_micbias(codec, vddio_switch, true, true);
2542}
2543
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002544static int tabla_codec_enable_micbias(struct snd_soc_dapm_widget *w,
2545 struct snd_kcontrol *kcontrol, int event)
2546{
2547 struct snd_soc_codec *codec = w->codec;
Patrick Lai3043fba2011-08-01 14:15:57 -07002548 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2549 u16 micb_int_reg;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002550 int micb_line;
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002551 u8 cfilt_sel_val = 0;
Bradley Rubin229c6a52011-07-12 16:18:48 -07002552 char *internal1_text = "Internal1";
2553 char *internal2_text = "Internal2";
2554 char *internal3_text = "Internal3";
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002555
2556 pr_debug("%s %d\n", __func__, event);
2557 switch (w->reg) {
2558 case TABLA_A_MICB_1_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002559 micb_int_reg = TABLA_A_MICB_1_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07002560 cfilt_sel_val = tabla->pdata->micbias.bias1_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002561 micb_line = TABLA_MICBIAS1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002562 break;
2563 case TABLA_A_MICB_2_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002564 micb_int_reg = TABLA_A_MICB_2_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07002565 cfilt_sel_val = tabla->pdata->micbias.bias2_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002566 micb_line = TABLA_MICBIAS2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002567 break;
2568 case TABLA_A_MICB_3_CTL:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002569 micb_int_reg = TABLA_A_MICB_3_INT_RBIAS;
Patrick Lai3043fba2011-08-01 14:15:57 -07002570 cfilt_sel_val = tabla->pdata->micbias.bias3_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002571 micb_line = TABLA_MICBIAS3;
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002572 break;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08002573 case TABLA_1_A_MICB_4_CTL:
2574 case TABLA_2_A_MICB_4_CTL:
2575 micb_int_reg = tabla->reg_addr.micb_4_int_rbias;
Patrick Lai3043fba2011-08-01 14:15:57 -07002576 cfilt_sel_val = tabla->pdata->micbias.bias4_cfilt_sel;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002577 micb_line = TABLA_MICBIAS4;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002578 break;
2579 default:
2580 pr_err("%s: Error, invalid micbias register\n", __func__);
2581 return -EINVAL;
2582 }
2583
2584 switch (event) {
2585 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002586 /* Decide whether to switch the micbias for MBHC */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002587 if (w->reg == tabla->mbhc_bias_regs.ctl_reg) {
2588 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002589 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002590 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
2591 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002592
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07002593 snd_soc_update_bits(codec, w->reg, 0x0E, 0x0A);
Patrick Lai3043fba2011-08-01 14:15:57 -07002594 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 1);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002595
2596 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002597 snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002598 else if (strnstr(w->name, internal2_text, 30))
2599 snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C);
2600 else if (strnstr(w->name, internal3_text, 30))
2601 snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3);
2602
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002603 break;
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002604 case SND_SOC_DAPM_POST_PMU:
Kiran Kandid8cf5212012-03-02 15:34:53 -08002605
2606 usleep_range(20000, 20000);
2607
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002608 if (tabla->mbhc_polling_active &&
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002609 tabla->mbhc_cfg.micbias == micb_line) {
2610 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002611 tabla_codec_pause_hs_polling(codec);
2612 tabla_codec_start_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002613 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bradley Rubin4d09cf42011-08-17 17:59:16 -07002614 }
2615 break;
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002616
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002617 case SND_SOC_DAPM_POST_PMD:
Joonwoo Park03324832012-03-19 19:36:16 -07002618 if ((w->reg == tabla->mbhc_bias_regs.ctl_reg) &&
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002619 tabla_is_hph_pa_on(codec)) {
2620 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002621 tabla_codec_switch_micbias(codec, 1);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002622 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
2623 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002624
Bradley Rubin229c6a52011-07-12 16:18:48 -07002625 if (strnstr(w->name, internal1_text, 30))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002626 snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00);
Bradley Rubin229c6a52011-07-12 16:18:48 -07002627 else if (strnstr(w->name, internal2_text, 30))
2628 snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00);
2629 else if (strnstr(w->name, internal3_text, 30))
2630 snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0);
2631
Patrick Lai3043fba2011-08-01 14:15:57 -07002632 tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002633 break;
2634 }
2635
2636 return 0;
2637}
2638
Kiran Kandid8cf5212012-03-02 15:34:53 -08002639
2640static void tx_hpf_corner_freq_callback(struct work_struct *work)
2641{
2642 struct delayed_work *hpf_delayed_work;
2643 struct hpf_work *hpf_work;
2644 struct tabla_priv *tabla;
2645 struct snd_soc_codec *codec;
2646 u16 tx_mux_ctl_reg;
2647 u8 hpf_cut_of_freq;
2648
2649 hpf_delayed_work = to_delayed_work(work);
2650 hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
2651 tabla = hpf_work->tabla;
2652 codec = hpf_work->tabla->codec;
2653 hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq;
2654
2655 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL +
2656 (hpf_work->decimator - 1) * 8;
2657
2658 pr_debug("%s(): decimator %u hpf_cut_of_freq 0x%x\n", __func__,
2659 hpf_work->decimator, (unsigned int)hpf_cut_of_freq);
2660
2661 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4);
2662}
2663
2664#define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30
2665#define CF_MIN_3DB_4HZ 0x0
2666#define CF_MIN_3DB_75HZ 0x1
2667#define CF_MIN_3DB_150HZ 0x2
2668
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002669static int tabla_codec_enable_dec(struct snd_soc_dapm_widget *w,
2670 struct snd_kcontrol *kcontrol, int event)
2671{
2672 struct snd_soc_codec *codec = w->codec;
Kiran Kandid8cf5212012-03-02 15:34:53 -08002673 unsigned int decimator;
2674 char *dec_name = NULL;
2675 char *widget_name = NULL;
2676 char *temp;
2677 int ret = 0;
2678 u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg;
2679 u8 dec_hpf_cut_of_freq;
Kuirong Wange9c8a222012-03-28 16:24:09 -07002680 int offset;
2681
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002682
2683 pr_debug("%s %d\n", __func__, event);
2684
Kiran Kandid8cf5212012-03-02 15:34:53 -08002685 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
2686 if (!widget_name)
2687 return -ENOMEM;
2688 temp = widget_name;
2689
2690 dec_name = strsep(&widget_name, " ");
2691 widget_name = temp;
2692 if (!dec_name) {
2693 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
2694 ret = -EINVAL;
2695 goto out;
2696 }
2697
2698 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
2699 if (ret < 0) {
2700 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
2701 ret = -EINVAL;
2702 goto out;
2703 }
2704
2705 pr_debug("%s(): widget = %s dec_name = %s decimator = %u\n", __func__,
2706 w->name, dec_name, decimator);
2707
Kuirong Wange9c8a222012-03-28 16:24:09 -07002708 if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002709 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B1_CTL;
Kuirong Wange9c8a222012-03-28 16:24:09 -07002710 offset = 0;
2711 } else if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002712 dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B2_CTL;
Kuirong Wange9c8a222012-03-28 16:24:09 -07002713 offset = 8;
2714 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002715 pr_err("%s: Error, incorrect dec\n", __func__);
2716 return -EINVAL;
2717 }
2718
Kiran Kandid8cf5212012-03-02 15:34:53 -08002719 tx_vol_ctl_reg = TABLA_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator -1);
2720 tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
2721
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002722 switch (event) {
2723 case SND_SOC_DAPM_PRE_PMU:
Kiran Kandid8cf5212012-03-02 15:34:53 -08002724
2725 // Enableable TX digital mute */
2726 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
2727
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002728 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift,
2729 1 << w->shift);
2730 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0);
Kiran Kandid8cf5212012-03-02 15:34:53 -08002731
2732 dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg);
2733
2734 dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4;
2735
2736 tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq =
2737 dec_hpf_cut_of_freq;
2738
2739 if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) {
2740
2741 /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */
2742 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
2743 CF_MIN_3DB_150HZ << 4);
2744 }
2745
2746 /* enable HPF */
2747 snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00);
2748
2749 break;
2750
2751 case SND_SOC_DAPM_POST_PMU:
2752
2753 /* Disable TX digital mute */
2754 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00);
2755
2756 if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq !=
2757 CF_MIN_3DB_150HZ) {
2758
2759 schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork,
2760 msecs_to_jiffies(300));
2761 }
Kuirong Wange9c8a222012-03-28 16:24:09 -07002762 /* apply the digital gain after the decimator is enabled*/
2763 if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
2764 snd_soc_write(codec,
2765 tx_digital_gain_reg[w->shift + offset],
2766 snd_soc_read(codec,
2767 tx_digital_gain_reg[w->shift + offset])
2768 );
2769
Kiran Kandid8cf5212012-03-02 15:34:53 -08002770 break;
2771
2772 case SND_SOC_DAPM_PRE_PMD:
2773
2774 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
2775 cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork);
2776 break;
2777
2778 case SND_SOC_DAPM_POST_PMD:
2779
2780 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08);
2781 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
2782 (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4);
2783
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002784 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002785 }
Kiran Kandid8cf5212012-03-02 15:34:53 -08002786out:
2787 kfree(widget_name);
2788 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002789}
2790
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07002791static int tabla_codec_reset_interpolator(struct snd_soc_dapm_widget *w,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002792 struct snd_kcontrol *kcontrol, int event)
2793{
2794 struct snd_soc_codec *codec = w->codec;
2795
Kiran Kandi8b3a8302011-09-27 16:13:28 -07002796 pr_debug("%s %d %s\n", __func__, event, w->name);
2797
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002798 switch (event) {
2799 case SND_SOC_DAPM_PRE_PMU:
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07002800 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
2801 1 << w->shift, 1 << w->shift);
2802 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL,
2803 1 << w->shift, 0x0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002804 break;
Kuirong Wange9c8a222012-03-28 16:24:09 -07002805 case SND_SOC_DAPM_POST_PMU:
2806 /* apply the digital gain after the interpolator is enabled*/
2807 if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
2808 snd_soc_write(codec,
2809 rx_digital_gain_reg[w->shift],
2810 snd_soc_read(codec,
2811 rx_digital_gain_reg[w->shift])
2812 );
2813 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002814 }
2815 return 0;
2816}
2817
Bradley Rubin229c6a52011-07-12 16:18:48 -07002818static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
2819 struct snd_kcontrol *kcontrol, int event)
2820{
2821 switch (event) {
2822 case SND_SOC_DAPM_POST_PMU:
2823 case SND_SOC_DAPM_POST_PMD:
2824 usleep_range(1000, 1000);
2825 break;
2826 }
2827 return 0;
2828}
2829
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002830static int tabla_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
2831 struct snd_kcontrol *kcontrol, int event)
2832{
2833 struct snd_soc_codec *codec = w->codec;
2834
2835 pr_debug("%s %d\n", __func__, event);
2836
2837 switch (event) {
2838 case SND_SOC_DAPM_PRE_PMU:
2839 tabla_enable_rx_bias(codec, 1);
2840 break;
2841 case SND_SOC_DAPM_POST_PMD:
2842 tabla_enable_rx_bias(codec, 0);
2843 break;
2844 }
2845 return 0;
2846}
Kiran Kandi8b3a8302011-09-27 16:13:28 -07002847static int tabla_hphr_dac_event(struct snd_soc_dapm_widget *w,
2848 struct snd_kcontrol *kcontrol, int event)
2849{
2850 struct snd_soc_codec *codec = w->codec;
2851
2852 pr_debug("%s %s %d\n", __func__, w->name, event);
2853
2854 switch (event) {
2855 case SND_SOC_DAPM_PRE_PMU:
2856 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
2857 break;
2858 case SND_SOC_DAPM_POST_PMD:
2859 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
2860 break;
2861 }
2862 return 0;
2863}
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07002864
Joonwoo Park8b1f0982011-12-08 17:12:45 -08002865static void tabla_snd_soc_jack_report(struct tabla_priv *tabla,
2866 struct snd_soc_jack *jack, int status,
2867 int mask)
2868{
2869 /* XXX: wake_lock_timeout()? */
Joonwoo Park03324832012-03-19 19:36:16 -07002870 snd_soc_jack_report_no_dapm(jack, status, mask);
Joonwoo Park8b1f0982011-12-08 17:12:45 -08002871}
2872
Patrick Lai49efeac2011-11-03 11:01:12 -07002873static void hphocp_off_report(struct tabla_priv *tabla,
2874 u32 jack_status, int irq)
2875{
2876 struct snd_soc_codec *codec;
Joonwoo Park03324832012-03-19 19:36:16 -07002877 if (!tabla) {
2878 pr_err("%s: Bad tabla private data\n", __func__);
2879 return;
2880 }
Patrick Lai49efeac2011-11-03 11:01:12 -07002881
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002882 pr_debug("%s: clear ocp status %x\n", __func__, jack_status);
Joonwoo Park03324832012-03-19 19:36:16 -07002883 codec = tabla->codec;
2884 if (tabla->hph_status & jack_status) {
Patrick Lai49efeac2011-11-03 11:01:12 -07002885 tabla->hph_status &= ~jack_status;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002886 if (tabla->mbhc_cfg.headset_jack)
2887 tabla_snd_soc_jack_report(tabla,
2888 tabla->mbhc_cfg.headset_jack,
Joonwoo Park8b1f0982011-12-08 17:12:45 -08002889 tabla->hph_status,
2890 TABLA_JACK_MASK);
Joonwoo Park0976d012011-12-22 11:48:18 -08002891 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x00);
2892 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10);
Patrick Laic7cae882011-11-18 11:52:49 -08002893 /* reset retry counter as PA is turned off signifying
2894 * start of new OCP detection session
2895 */
2896 if (TABLA_IRQ_HPH_PA_OCPL_FAULT)
2897 tabla->hphlocp_cnt = 0;
2898 else
2899 tabla->hphrocp_cnt = 0;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05302900 wcd9xxx_enable_irq(codec->control_data, irq);
Patrick Lai49efeac2011-11-03 11:01:12 -07002901 }
2902}
2903
2904static void hphlocp_off_report(struct work_struct *work)
2905{
2906 struct tabla_priv *tabla = container_of(work, struct tabla_priv,
2907 hphlocp_work);
2908 hphocp_off_report(tabla, SND_JACK_OC_HPHL, TABLA_IRQ_HPH_PA_OCPL_FAULT);
2909}
2910
2911static void hphrocp_off_report(struct work_struct *work)
2912{
2913 struct tabla_priv *tabla = container_of(work, struct tabla_priv,
2914 hphrocp_work);
2915 hphocp_off_report(tabla, SND_JACK_OC_HPHR, TABLA_IRQ_HPH_PA_OCPR_FAULT);
2916}
2917
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07002918static int tabla_hph_pa_event(struct snd_soc_dapm_widget *w,
2919 struct snd_kcontrol *kcontrol, int event)
2920{
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002921 struct snd_soc_codec *codec = w->codec;
2922 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
2923 u8 mbhc_micb_ctl_val;
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07002924 pr_debug("%s: event = %d\n", __func__, event);
2925
2926 switch (event) {
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002927 case SND_SOC_DAPM_PRE_PMU:
2928 mbhc_micb_ctl_val = snd_soc_read(codec,
2929 tabla->mbhc_bias_regs.ctl_reg);
2930
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002931 if (!(mbhc_micb_ctl_val & 0x80)) {
2932 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002933 tabla_codec_switch_micbias(codec, 1);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002934 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
2935 }
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002936 break;
2937
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07002938 case SND_SOC_DAPM_POST_PMD:
Patrick Lai49efeac2011-11-03 11:01:12 -07002939 /* schedule work is required because at the time HPH PA DAPM
2940 * event callback is called by DAPM framework, CODEC dapm mutex
2941 * would have been locked while snd_soc_jack_report also
2942 * attempts to acquire same lock.
2943 */
Joonwoo Parka9444452011-12-08 18:48:27 -08002944 if (w->shift == 5) {
2945 clear_bit(TABLA_HPHL_PA_OFF_ACK,
2946 &tabla->hph_pa_dac_state);
2947 clear_bit(TABLA_HPHL_DAC_OFF_ACK,
2948 &tabla->hph_pa_dac_state);
2949 if (tabla->hph_status & SND_JACK_OC_HPHL)
2950 schedule_work(&tabla->hphlocp_work);
2951 } else if (w->shift == 4) {
2952 clear_bit(TABLA_HPHR_PA_OFF_ACK,
2953 &tabla->hph_pa_dac_state);
2954 clear_bit(TABLA_HPHR_DAC_OFF_ACK,
2955 &tabla->hph_pa_dac_state);
2956 if (tabla->hph_status & SND_JACK_OC_HPHR)
2957 schedule_work(&tabla->hphrocp_work);
2958 }
2959
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002960 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Joonwoo Park03324832012-03-19 19:36:16 -07002961 tabla_codec_switch_micbias(codec, 0);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002962 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07002963
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07002964 pr_debug("%s: sleep 10 ms after %s PA disable.\n", __func__,
2965 w->name);
2966 usleep_range(10000, 10000);
Kiran Kandibf0b1ff2011-09-15 13:55:21 -07002967 break;
2968 }
2969 return 0;
2970}
2971
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002972static void tabla_get_mbhc_micbias_regs(struct snd_soc_codec *codec,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08002973 struct mbhc_micbias_regs *micbias_regs)
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002974{
2975 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002976 unsigned int cfilt;
2977
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07002978 switch (tabla->mbhc_cfg.micbias) {
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07002979 case TABLA_MICBIAS1:
2980 cfilt = tabla->pdata->micbias.bias1_cfilt_sel;
2981 micbias_regs->mbhc_reg = TABLA_A_MICB_1_MBHC;
2982 micbias_regs->int_rbias = TABLA_A_MICB_1_INT_RBIAS;
2983 micbias_regs->ctl_reg = TABLA_A_MICB_1_CTL;
2984 break;
2985 case TABLA_MICBIAS2:
2986 cfilt = tabla->pdata->micbias.bias2_cfilt_sel;
2987 micbias_regs->mbhc_reg = TABLA_A_MICB_2_MBHC;
2988 micbias_regs->int_rbias = TABLA_A_MICB_2_INT_RBIAS;
2989 micbias_regs->ctl_reg = TABLA_A_MICB_2_CTL;
2990 break;
2991 case TABLA_MICBIAS3:
2992 cfilt = tabla->pdata->micbias.bias3_cfilt_sel;
2993 micbias_regs->mbhc_reg = TABLA_A_MICB_3_MBHC;
2994 micbias_regs->int_rbias = TABLA_A_MICB_3_INT_RBIAS;
2995 micbias_regs->ctl_reg = TABLA_A_MICB_3_CTL;
2996 break;
2997 case TABLA_MICBIAS4:
2998 cfilt = tabla->pdata->micbias.bias4_cfilt_sel;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08002999 micbias_regs->mbhc_reg = tabla->reg_addr.micb_4_mbhc;
3000 micbias_regs->int_rbias = tabla->reg_addr.micb_4_int_rbias;
3001 micbias_regs->ctl_reg = tabla->reg_addr.micb_4_ctl;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003002 break;
3003 default:
3004 /* Should never reach here */
3005 pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__);
Jordan Crouse239d8412011-11-23 11:47:02 -07003006 return;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003007 }
3008
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08003009 micbias_regs->cfilt_sel = cfilt;
3010
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003011 switch (cfilt) {
3012 case TABLA_CFILT1_SEL:
3013 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_1_VAL;
3014 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_1_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08003015 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt1_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003016 break;
3017 case TABLA_CFILT2_SEL:
3018 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_2_VAL;
3019 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_2_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08003020 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt2_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003021 break;
3022 case TABLA_CFILT3_SEL:
3023 micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_3_VAL;
3024 micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_3_CTL;
Joonwoo Park0976d012011-12-22 11:48:18 -08003025 tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt3_mv;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003026 break;
3027 }
3028}
Santosh Mardie15e2302011-11-15 10:39:23 +05303029static const struct snd_soc_dapm_widget tabla_dapm_i2s_widgets[] = {
3030 SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", TABLA_A_CDC_CLK_RX_I2S_CTL,
3031 4, 0, NULL, 0),
3032 SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", TABLA_A_CDC_CLK_TX_I2S_CTL, 4,
3033 0, NULL, 0),
3034};
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07003035
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003036static int tabla_lineout_dac_event(struct snd_soc_dapm_widget *w,
3037 struct snd_kcontrol *kcontrol, int event)
3038{
3039 struct snd_soc_codec *codec = w->codec;
3040
3041 pr_debug("%s %s %d\n", __func__, w->name, event);
3042
3043 switch (event) {
3044 case SND_SOC_DAPM_PRE_PMU:
3045 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
3046 break;
3047
3048 case SND_SOC_DAPM_POST_PMD:
3049 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
3050 break;
3051 }
3052 return 0;
3053}
3054
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003055static const struct snd_soc_dapm_widget tabla_1_x_dapm_widgets[] = {
3056 SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", TABLA_1_A_MICB_4_CTL, 7,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303057 0, tabla_codec_enable_micbias,
3058 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3059 SND_SOC_DAPM_POST_PMD),
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003060};
3061
3062static const struct snd_soc_dapm_widget tabla_2_higher_dapm_widgets[] = {
3063 SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", TABLA_2_A_MICB_4_CTL, 7,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303064 0, tabla_codec_enable_micbias,
3065 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3066 SND_SOC_DAPM_POST_PMD),
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003067};
3068
Santosh Mardie15e2302011-11-15 10:39:23 +05303069static const struct snd_soc_dapm_route audio_i2s_map[] = {
3070 {"RX_I2S_CLK", NULL, "CDC_CONN"},
3071 {"SLIM RX1", NULL, "RX_I2S_CLK"},
3072 {"SLIM RX2", NULL, "RX_I2S_CLK"},
3073 {"SLIM RX3", NULL, "RX_I2S_CLK"},
3074 {"SLIM RX4", NULL, "RX_I2S_CLK"},
3075
3076 {"SLIM TX7", NULL, "TX_I2S_CLK"},
3077 {"SLIM TX8", NULL, "TX_I2S_CLK"},
3078 {"SLIM TX9", NULL, "TX_I2S_CLK"},
3079 {"SLIM TX10", NULL, "TX_I2S_CLK"},
3080};
3081
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003082static const struct snd_soc_dapm_route audio_map[] = {
3083 /* SLIMBUS Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003084
3085 {"SLIM TX1", NULL, "SLIM TX1 MUX"},
3086 {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"},
3087
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003088 {"SLIM TX2", NULL, "SLIM TX2 MUX"},
3089 {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"},
3090
3091 {"SLIM TX3", NULL, "SLIM TX3 MUX"},
3092 {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"},
Neema Shetty3fb1b802012-04-27 13:53:24 -07003093 {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"},
3094 {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"},
3095 {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"},
3096 {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"},
3097 {"SLIM TX3 MUX", "RMIX5", "RX5 MIX1"},
3098 {"SLIM TX3 MUX", "RMIX6", "RX6 MIX1"},
3099 {"SLIM TX3 MUX", "RMIX7", "RX7 MIX1"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003100
3101 {"SLIM TX4", NULL, "SLIM TX4 MUX"},
3102 {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"},
3103
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003104 {"SLIM TX5", NULL, "SLIM TX5 MUX"},
3105 {"SLIM TX5 MUX", "DEC5", "DEC5 MUX"},
Neema Shetty3fb1b802012-04-27 13:53:24 -07003106 {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"},
3107 {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"},
3108 {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"},
3109 {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"},
3110 {"SLIM TX5 MUX", "RMIX5", "RX5 MIX1"},
3111 {"SLIM TX5 MUX", "RMIX6", "RX6 MIX1"},
3112 {"SLIM TX5 MUX", "RMIX7", "RX7 MIX1"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003113
3114 {"SLIM TX6", NULL, "SLIM TX6 MUX"},
3115 {"SLIM TX6 MUX", "DEC6", "DEC6 MUX"},
3116
3117 {"SLIM TX7", NULL, "SLIM TX7 MUX"},
3118 {"SLIM TX7 MUX", "DEC1", "DEC1 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07003119 {"SLIM TX7 MUX", "DEC2", "DEC2 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003120 {"SLIM TX7 MUX", "DEC3", "DEC3 MUX"},
3121 {"SLIM TX7 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003122 {"SLIM TX7 MUX", "DEC5", "DEC5 MUX"},
3123 {"SLIM TX7 MUX", "DEC6", "DEC6 MUX"},
Bhalchandra Gajare0d77e1b2011-07-08 10:54:14 -07003124 {"SLIM TX7 MUX", "DEC7", "DEC7 MUX"},
3125 {"SLIM TX7 MUX", "DEC8", "DEC8 MUX"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003126 {"SLIM TX7 MUX", "DEC9", "DEC9 MUX"},
3127 {"SLIM TX7 MUX", "DEC10", "DEC10 MUX"},
Neema Shetty3fb1b802012-04-27 13:53:24 -07003128 {"SLIM TX7 MUX", "RMIX1", "RX1 MIX1"},
3129 {"SLIM TX7 MUX", "RMIX2", "RX2 MIX1"},
3130 {"SLIM TX7 MUX", "RMIX3", "RX3 MIX1"},
3131 {"SLIM TX7 MUX", "RMIX4", "RX4 MIX1"},
3132 {"SLIM TX7 MUX", "RMIX5", "RX5 MIX1"},
3133 {"SLIM TX7 MUX", "RMIX6", "RX6 MIX1"},
3134 {"SLIM TX7 MUX", "RMIX7", "RX7 MIX1"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003135
3136 {"SLIM TX8", NULL, "SLIM TX8 MUX"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003137 {"SLIM TX8 MUX", "DEC1", "DEC1 MUX"},
3138 {"SLIM TX8 MUX", "DEC2", "DEC2 MUX"},
3139 {"SLIM TX8 MUX", "DEC3", "DEC3 MUX"},
Bhalchandra Gajare9ec83cd2011-09-23 17:25:07 -07003140 {"SLIM TX8 MUX", "DEC4", "DEC4 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003141 {"SLIM TX8 MUX", "DEC5", "DEC5 MUX"},
3142 {"SLIM TX8 MUX", "DEC6", "DEC6 MUX"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003143 {"SLIM TX8 MUX", "DEC7", "DEC7 MUX"},
3144 {"SLIM TX8 MUX", "DEC8", "DEC8 MUX"},
3145 {"SLIM TX8 MUX", "DEC9", "DEC9 MUX"},
3146 {"SLIM TX8 MUX", "DEC10", "DEC10 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003147
Kiran Kandi3426e512011-09-13 22:50:10 -07003148 {"SLIM TX9", NULL, "SLIM TX9 MUX"},
3149 {"SLIM TX9 MUX", "DEC1", "DEC1 MUX"},
3150 {"SLIM TX9 MUX", "DEC2", "DEC2 MUX"},
3151 {"SLIM TX9 MUX", "DEC3", "DEC3 MUX"},
3152 {"SLIM TX9 MUX", "DEC4", "DEC4 MUX"},
3153 {"SLIM TX9 MUX", "DEC5", "DEC5 MUX"},
3154 {"SLIM TX9 MUX", "DEC6", "DEC6 MUX"},
3155 {"SLIM TX9 MUX", "DEC7", "DEC7 MUX"},
3156 {"SLIM TX9 MUX", "DEC8", "DEC8 MUX"},
3157 {"SLIM TX9 MUX", "DEC9", "DEC9 MUX"},
3158 {"SLIM TX9 MUX", "DEC10", "DEC10 MUX"},
3159
3160 {"SLIM TX10", NULL, "SLIM TX10 MUX"},
3161 {"SLIM TX10 MUX", "DEC1", "DEC1 MUX"},
3162 {"SLIM TX10 MUX", "DEC2", "DEC2 MUX"},
3163 {"SLIM TX10 MUX", "DEC3", "DEC3 MUX"},
3164 {"SLIM TX10 MUX", "DEC4", "DEC4 MUX"},
3165 {"SLIM TX10 MUX", "DEC5", "DEC5 MUX"},
3166 {"SLIM TX10 MUX", "DEC6", "DEC6 MUX"},
3167 {"SLIM TX10 MUX", "DEC7", "DEC7 MUX"},
3168 {"SLIM TX10 MUX", "DEC8", "DEC8 MUX"},
3169 {"SLIM TX10 MUX", "DEC9", "DEC9 MUX"},
3170 {"SLIM TX10 MUX", "DEC10", "DEC10 MUX"},
3171
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003172 /* Earpiece (RX MIX1) */
3173 {"EAR", NULL, "EAR PA"},
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003174 {"EAR PA", NULL, "EAR_PA_MIXER"},
3175 {"EAR_PA_MIXER", NULL, "DAC1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003176 {"DAC1", NULL, "CP"},
3177
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003178 {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"},
3179 {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003180 {"ANC", NULL, "ANC1 FB MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003181
3182 /* Headset (RX MIX1 and RX MIX2) */
3183 {"HEADPHONE", NULL, "HPHL"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003184 {"HEADPHONE", NULL, "HPHR"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003185
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003186 {"HPHL", NULL, "HPHL_PA_MIXER"},
3187 {"HPHL_PA_MIXER", NULL, "HPHL DAC"},
3188
3189 {"HPHR", NULL, "HPHR_PA_MIXER"},
3190 {"HPHR_PA_MIXER", NULL, "HPHR DAC"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003191
3192 {"HPHL DAC", NULL, "CP"},
3193 {"HPHR DAC", NULL, "CP"},
3194
3195 {"ANC", NULL, "ANC1 MUX"},
3196 {"ANC", NULL, "ANC2 MUX"},
3197 {"ANC1 MUX", "ADC1", "ADC1"},
3198 {"ANC1 MUX", "ADC2", "ADC2"},
3199 {"ANC1 MUX", "ADC3", "ADC3"},
3200 {"ANC1 MUX", "ADC4", "ADC4"},
3201 {"ANC2 MUX", "ADC1", "ADC1"},
3202 {"ANC2 MUX", "ADC2", "ADC2"},
3203 {"ANC2 MUX", "ADC3", "ADC3"},
3204 {"ANC2 MUX", "ADC4", "ADC4"},
3205
Bradley Rubine1d08622011-07-20 18:01:35 -07003206 {"ANC", NULL, "CDC_CONN"},
3207
Bradley Rubin229c6a52011-07-12 16:18:48 -07003208 {"DAC1", "Switch", "RX1 CHAIN"},
3209 {"HPHL DAC", "Switch", "RX1 CHAIN"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003210 {"HPHR DAC", NULL, "RX2 CHAIN"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003211
Kiran Kandidb0a4b02011-08-23 09:32:09 -07003212 {"LINEOUT1", NULL, "LINEOUT1 PA"},
3213 {"LINEOUT2", NULL, "LINEOUT2 PA"},
3214 {"LINEOUT3", NULL, "LINEOUT3 PA"},
3215 {"LINEOUT4", NULL, "LINEOUT4 PA"},
3216 {"LINEOUT5", NULL, "LINEOUT5 PA"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003217
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003218 {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"},
3219 {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"},
3220 {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"},
3221 {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"},
3222 {"LINEOUT3 PA", NULL, "LINEOUT3_PA_MIXER"},
3223 {"LINEOUT3_PA_MIXER", NULL, "LINEOUT3 DAC"},
3224 {"LINEOUT4 PA", NULL, "LINEOUT4_PA_MIXER"},
3225 {"LINEOUT4_PA_MIXER", NULL, "LINEOUT4 DAC"},
3226 {"LINEOUT5 PA", NULL, "LINEOUT5_PA_MIXER"},
3227 {"LINEOUT5_PA_MIXER", NULL, "LINEOUT5 DAC"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003228
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003229 {"LINEOUT1 DAC", NULL, "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003230 {"LINEOUT5 DAC", NULL, "RX7 MIX1"},
3231
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003232 {"RX1 CHAIN", NULL, "RX1 MIX2"},
3233 {"RX2 CHAIN", NULL, "RX2 MIX2"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003234 {"RX1 CHAIN", NULL, "ANC"},
3235 {"RX2 CHAIN", NULL, "ANC"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003236
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003237 {"CP", NULL, "RX_BIAS"},
3238 {"LINEOUT1 DAC", NULL, "RX_BIAS"},
3239 {"LINEOUT2 DAC", NULL, "RX_BIAS"},
3240 {"LINEOUT3 DAC", NULL, "RX_BIAS"},
3241 {"LINEOUT4 DAC", NULL, "RX_BIAS"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003242 {"LINEOUT5 DAC", NULL, "RX_BIAS"},
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003243
Kuirong Wang0f8ade32012-02-27 16:29:45 -08003244 {"RX1 MIX1", NULL, "COMP1_CLK"},
3245 {"RX2 MIX1", NULL, "COMP1_CLK"},
3246 {"RX3 MIX1", NULL, "COMP2_CLK"},
3247 {"RX5 MIX1", NULL, "COMP2_CLK"},
3248
3249
Bradley Rubin229c6a52011-07-12 16:18:48 -07003250 {"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
3251 {"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003252 {"RX1 MIX1", NULL, "RX1 MIX1 INP3"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003253 {"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
3254 {"RX2 MIX1", NULL, "RX2 MIX1 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003255 {"RX3 MIX1", NULL, "RX3 MIX1 INP1"},
3256 {"RX3 MIX1", NULL, "RX3 MIX1 INP2"},
3257 {"RX4 MIX1", NULL, "RX4 MIX1 INP1"},
3258 {"RX4 MIX1", NULL, "RX4 MIX1 INP2"},
3259 {"RX5 MIX1", NULL, "RX5 MIX1 INP1"},
3260 {"RX5 MIX1", NULL, "RX5 MIX1 INP2"},
3261 {"RX6 MIX1", NULL, "RX6 MIX1 INP1"},
3262 {"RX6 MIX1", NULL, "RX6 MIX1 INP2"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07003263 {"RX7 MIX1", NULL, "RX7 MIX1 INP1"},
3264 {"RX7 MIX1", NULL, "RX7 MIX1 INP2"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003265 {"RX1 MIX2", NULL, "RX1 MIX1"},
3266 {"RX1 MIX2", NULL, "RX1 MIX2 INP1"},
3267 {"RX1 MIX2", NULL, "RX1 MIX2 INP2"},
3268 {"RX2 MIX2", NULL, "RX2 MIX1"},
3269 {"RX2 MIX2", NULL, "RX2 MIX2 INP1"},
3270 {"RX2 MIX2", NULL, "RX2 MIX2 INP2"},
3271 {"RX3 MIX2", NULL, "RX3 MIX1"},
3272 {"RX3 MIX2", NULL, "RX3 MIX2 INP1"},
3273 {"RX3 MIX2", NULL, "RX3 MIX2 INP2"},
Bradley Rubin74a9b4a2011-06-13 15:03:43 -07003274
Bradley Rubin229c6a52011-07-12 16:18:48 -07003275 {"RX1 MIX1 INP1", "RX1", "SLIM RX1"},
3276 {"RX1 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303277 {"RX1 MIX1 INP1", "RX3", "SLIM RX3"},
3278 {"RX1 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003279 {"RX1 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003280 {"RX1 MIX1 INP1", "RX6", "SLIM RX6"},
3281 {"RX1 MIX1 INP1", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003282 {"RX1 MIX1 INP1", "IIR1", "IIR1"},
3283 {"RX1 MIX1 INP2", "RX1", "SLIM RX1"},
3284 {"RX1 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303285 {"RX1 MIX1 INP2", "RX3", "SLIM RX3"},
3286 {"RX1 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003287 {"RX1 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003288 {"RX1 MIX1 INP2", "RX6", "SLIM RX6"},
3289 {"RX1 MIX1 INP2", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003290 {"RX1 MIX1 INP2", "IIR1", "IIR1"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003291 {"RX1 MIX1 INP3", "RX1", "SLIM RX1"},
3292 {"RX1 MIX1 INP3", "RX2", "SLIM RX2"},
3293 {"RX1 MIX1 INP3", "RX3", "SLIM RX3"},
3294 {"RX1 MIX1 INP3", "RX4", "SLIM RX4"},
3295 {"RX1 MIX1 INP3", "RX5", "SLIM RX5"},
3296 {"RX1 MIX1 INP3", "RX6", "SLIM RX6"},
3297 {"RX1 MIX1 INP3", "RX7", "SLIM RX7"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003298 {"RX2 MIX1 INP1", "RX1", "SLIM RX1"},
3299 {"RX2 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303300 {"RX2 MIX1 INP1", "RX3", "SLIM RX3"},
3301 {"RX2 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003302 {"RX2 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003303 {"RX2 MIX1 INP1", "RX6", "SLIM RX6"},
3304 {"RX2 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003305 {"RX2 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003306 {"RX2 MIX1 INP2", "RX1", "SLIM RX1"},
3307 {"RX2 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303308 {"RX2 MIX1 INP2", "RX3", "SLIM RX3"},
3309 {"RX2 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003310 {"RX2 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003311 {"RX2 MIX1 INP2", "RX6", "SLIM RX6"},
3312 {"RX2 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003313 {"RX2 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003314 {"RX3 MIX1 INP1", "RX1", "SLIM RX1"},
3315 {"RX3 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303316 {"RX3 MIX1 INP1", "RX3", "SLIM RX3"},
3317 {"RX3 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003318 {"RX3 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003319 {"RX3 MIX1 INP1", "RX6", "SLIM RX6"},
3320 {"RX3 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003321 {"RX3 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003322 {"RX3 MIX1 INP2", "RX1", "SLIM RX1"},
3323 {"RX3 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303324 {"RX3 MIX1 INP2", "RX3", "SLIM RX3"},
3325 {"RX3 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003326 {"RX3 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003327 {"RX3 MIX1 INP2", "RX6", "SLIM RX6"},
3328 {"RX3 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003329 {"RX3 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003330 {"RX4 MIX1 INP1", "RX1", "SLIM RX1"},
3331 {"RX4 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303332 {"RX4 MIX1 INP1", "RX3", "SLIM RX3"},
3333 {"RX4 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003334 {"RX4 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003335 {"RX4 MIX1 INP1", "RX6", "SLIM RX6"},
3336 {"RX4 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003337 {"RX4 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003338 {"RX4 MIX1 INP2", "RX1", "SLIM RX1"},
3339 {"RX4 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303340 {"RX4 MIX1 INP2", "RX3", "SLIM RX3"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003341 {"RX4 MIX1 INP2", "RX5", "SLIM RX5"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303342 {"RX4 MIX1 INP2", "RX4", "SLIM RX4"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003343 {"RX4 MIX1 INP2", "RX6", "SLIM RX6"},
3344 {"RX4 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003345 {"RX4 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003346 {"RX5 MIX1 INP1", "RX1", "SLIM RX1"},
3347 {"RX5 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303348 {"RX5 MIX1 INP1", "RX3", "SLIM RX3"},
3349 {"RX5 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003350 {"RX5 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003351 {"RX5 MIX1 INP1", "RX6", "SLIM RX6"},
3352 {"RX5 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003353 {"RX5 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003354 {"RX5 MIX1 INP2", "RX1", "SLIM RX1"},
3355 {"RX5 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303356 {"RX5 MIX1 INP2", "RX3", "SLIM RX3"},
3357 {"RX5 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003358 {"RX5 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003359 {"RX5 MIX1 INP2", "RX6", "SLIM RX6"},
3360 {"RX5 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003361 {"RX5 MIX1 INP2", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003362 {"RX6 MIX1 INP1", "RX1", "SLIM RX1"},
3363 {"RX6 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303364 {"RX6 MIX1 INP1", "RX3", "SLIM RX3"},
3365 {"RX6 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003366 {"RX6 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003367 {"RX6 MIX1 INP1", "RX6", "SLIM RX6"},
3368 {"RX6 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003369 {"RX6 MIX1 INP1", "IIR1", "IIR1"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003370 {"RX6 MIX1 INP2", "RX1", "SLIM RX1"},
3371 {"RX6 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303372 {"RX6 MIX1 INP2", "RX3", "SLIM RX3"},
3373 {"RX6 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003374 {"RX6 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003375 {"RX6 MIX1 INP2", "RX6", "SLIM RX6"},
3376 {"RX6 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003377 {"RX6 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07003378 {"RX7 MIX1 INP1", "RX1", "SLIM RX1"},
3379 {"RX7 MIX1 INP1", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303380 {"RX7 MIX1 INP1", "RX3", "SLIM RX3"},
3381 {"RX7 MIX1 INP1", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003382 {"RX7 MIX1 INP1", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003383 {"RX7 MIX1 INP1", "RX6", "SLIM RX6"},
3384 {"RX7 MIX1 INP1", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003385 {"RX7 MIX1 INP1", "IIR1", "IIR1"},
Bhalchandra Gajare0a8ad172011-08-12 13:32:22 -07003386 {"RX7 MIX1 INP2", "RX1", "SLIM RX1"},
3387 {"RX7 MIX1 INP2", "RX2", "SLIM RX2"},
Santosh Mardie15e2302011-11-15 10:39:23 +05303388 {"RX7 MIX1 INP2", "RX3", "SLIM RX3"},
3389 {"RX7 MIX1 INP2", "RX4", "SLIM RX4"},
Kiran Kandia9fffe92012-05-20 23:42:30 -07003390 {"RX7 MIX1 INP2", "RX5", "SLIM RX5"},
Neema Shettyd3a89262012-02-16 10:23:50 -08003391 {"RX7 MIX1 INP2", "RX6", "SLIM RX6"},
3392 {"RX7 MIX1 INP2", "RX7", "SLIM RX7"},
Patrick Lai16261e82011-09-30 13:25:52 -07003393 {"RX7 MIX1 INP2", "IIR1", "IIR1"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003394 {"RX1 MIX2 INP1", "IIR1", "IIR1"},
3395 {"RX1 MIX2 INP2", "IIR1", "IIR1"},
3396 {"RX2 MIX2 INP1", "IIR1", "IIR1"},
3397 {"RX2 MIX2 INP2", "IIR1", "IIR1"},
3398 {"RX3 MIX2 INP1", "IIR1", "IIR1"},
3399 {"RX3 MIX2 INP2", "IIR1", "IIR1"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003400
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003401 /* Decimator Inputs */
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003402 {"DEC1 MUX", "DMIC1", "DMIC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003403 {"DEC1 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003404 {"DEC1 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003405 {"DEC2 MUX", "DMIC2", "DMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003406 {"DEC2 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003407 {"DEC2 MUX", NULL, "CDC_CONN"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003408 {"DEC3 MUX", "DMIC3", "DMIC3"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003409 {"DEC3 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003410 {"DEC3 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07003411 {"DEC4 MUX", "DMIC4", "DMIC4"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003412 {"DEC4 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003413 {"DEC4 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07003414 {"DEC5 MUX", "DMIC5", "DMIC5"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003415 {"DEC5 MUX", "ADC2", "ADC2"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003416 {"DEC5 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajare7cf018e2011-08-11 18:58:32 -07003417 {"DEC6 MUX", "DMIC6", "DMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003418 {"DEC6 MUX", "ADC1", "ADC1"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003419 {"DEC6 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003420 {"DEC7 MUX", "DMIC1", "DMIC1"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003421 {"DEC7 MUX", "DMIC6", "DMIC6"},
3422 {"DEC7 MUX", "ADC1", "ADC1"},
Kiran Kandicf45f6a2011-07-17 21:10:19 -07003423 {"DEC7 MUX", "ADC6", "ADC6"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003424 {"DEC7 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003425 {"DEC8 MUX", "DMIC2", "DMIC2"},
3426 {"DEC8 MUX", "DMIC5", "DMIC5"},
3427 {"DEC8 MUX", "ADC2", "ADC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003428 {"DEC8 MUX", "ADC5", "ADC5"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003429 {"DEC8 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003430 {"DEC9 MUX", "DMIC4", "DMIC4"},
3431 {"DEC9 MUX", "DMIC5", "DMIC5"},
3432 {"DEC9 MUX", "ADC2", "ADC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003433 {"DEC9 MUX", "ADC3", "ADC3"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003434 {"DEC9 MUX", NULL, "CDC_CONN"},
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003435 {"DEC10 MUX", "DMIC3", "DMIC3"},
3436 {"DEC10 MUX", "DMIC6", "DMIC6"},
3437 {"DEC10 MUX", "ADC1", "ADC1"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003438 {"DEC10 MUX", "ADC4", "ADC4"},
Bradley Rubine1d08622011-07-20 18:01:35 -07003439 {"DEC10 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003440
3441 /* ADC Connections */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003442 {"ADC1", NULL, "AMIC1"},
3443 {"ADC2", NULL, "AMIC2"},
Bhalchandra Gajarecc6ffa02011-07-14 18:35:41 -07003444 {"ADC3", NULL, "AMIC3"},
3445 {"ADC4", NULL, "AMIC4"},
3446 {"ADC5", NULL, "AMIC5"},
3447 {"ADC6", NULL, "AMIC6"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003448
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08003449 /* AUX PGA Connections */
3450 {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3451 {"HPHL_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3452 {"HPHL_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3453 {"HPHL_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3454 {"HPHR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3455 {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3456 {"HPHR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3457 {"HPHR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3458 {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3459 {"LINEOUT1_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3460 {"LINEOUT1_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3461 {"LINEOUT1_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3462 {"LINEOUT2_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3463 {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3464 {"LINEOUT2_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3465 {"LINEOUT2_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3466 {"LINEOUT3_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3467 {"LINEOUT3_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3468 {"LINEOUT3_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3469 {"LINEOUT3_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3470 {"LINEOUT4_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3471 {"LINEOUT4_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3472 {"LINEOUT4_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3473 {"LINEOUT4_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3474 {"LINEOUT5_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3475 {"LINEOUT5_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3476 {"LINEOUT5_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3477 {"LINEOUT5_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3478 {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3479 {"EAR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3480 {"EAR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"},
3481 {"EAR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"},
3482 {"AUX_PGA_Left", NULL, "AMIC5"},
3483 {"AUX_PGA_Right", NULL, "AMIC6"},
3484
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003485 {"IIR1", NULL, "IIR1 INP1 MUX"},
Patrick Lai16261e82011-09-30 13:25:52 -07003486 {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"},
3487 {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"},
3488 {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"},
3489 {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"},
3490 {"IIR1 INP1 MUX", "DEC5", "DEC5 MUX"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003491 {"IIR1 INP1 MUX", "DEC6", "DEC6 MUX"},
Patrick Lai16261e82011-09-30 13:25:52 -07003492 {"IIR1 INP1 MUX", "DEC7", "DEC7 MUX"},
3493 {"IIR1 INP1 MUX", "DEC8", "DEC8 MUX"},
3494 {"IIR1 INP1 MUX", "DEC9", "DEC9 MUX"},
3495 {"IIR1 INP1 MUX", "DEC10", "DEC10 MUX"},
Bradley Rubin229c6a52011-07-12 16:18:48 -07003496
3497 {"MIC BIAS1 Internal1", NULL, "LDO_H"},
3498 {"MIC BIAS1 Internal2", NULL, "LDO_H"},
3499 {"MIC BIAS1 External", NULL, "LDO_H"},
3500 {"MIC BIAS2 Internal1", NULL, "LDO_H"},
3501 {"MIC BIAS2 Internal2", NULL, "LDO_H"},
3502 {"MIC BIAS2 Internal3", NULL, "LDO_H"},
3503 {"MIC BIAS2 External", NULL, "LDO_H"},
3504 {"MIC BIAS3 Internal1", NULL, "LDO_H"},
3505 {"MIC BIAS3 Internal2", NULL, "LDO_H"},
3506 {"MIC BIAS3 External", NULL, "LDO_H"},
3507 {"MIC BIAS4 External", NULL, "LDO_H"},
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003508};
3509
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003510static const struct snd_soc_dapm_route tabla_1_x_lineout_2_to_4_map[] = {
3511
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003512 {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003513 {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"},
3514
3515 {"LINEOUT2 DAC", NULL, "RX4 DSM MUX"},
3516
3517 {"LINEOUT3 DAC", NULL, "RX5 MIX1"},
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003518 {"LINEOUT3 DAC GROUND", "Switch", "RX3 MIX2"},
Kiran Kandi8b3a8302011-09-27 16:13:28 -07003519 {"LINEOUT3 DAC", NULL, "LINEOUT3 DAC GROUND"},
3520
3521 {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"},
3522 {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"},
3523
3524 {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"},
3525 {"LINEOUT4 DAC GROUND", "Switch", "RX4 DSM MUX"},
3526 {"LINEOUT4 DAC", NULL, "LINEOUT4 DAC GROUND"},
3527};
3528
Kiran Kandi7a9fd902011-11-14 13:51:45 -08003529
3530static const struct snd_soc_dapm_route tabla_2_x_lineout_2_to_4_map[] = {
3531
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08003532 {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"},
Kiran Kandi7a9fd902011-11-14 13:51:45 -08003533 {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"},
3534
3535 {"LINEOUT3 DAC", NULL, "RX4 DSM MUX"},
3536
3537 {"LINEOUT2 DAC", NULL, "RX5 MIX1"},
3538
3539 {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"},
3540 {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"},
3541
3542 {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"},
3543};
3544
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003545static int tabla_readable(struct snd_soc_codec *ssc, unsigned int reg)
3546{
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003547 int i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303548 struct wcd9xxx *tabla_core = dev_get_drvdata(ssc->dev->parent);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08003549
3550 if (TABLA_IS_1_X(tabla_core->version)) {
3551 for (i = 0; i < ARRAY_SIZE(tabla_1_reg_readable); i++) {
3552 if (tabla_1_reg_readable[i] == reg)
3553 return 1;
3554 }
3555 } else {
3556 for (i = 0; i < ARRAY_SIZE(tabla_2_reg_readable); i++) {
3557 if (tabla_2_reg_readable[i] == reg)
3558 return 1;
3559 }
3560 }
3561
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003562 return tabla_reg_readable[reg];
3563}
Kuirong Wange9c8a222012-03-28 16:24:09 -07003564static bool tabla_is_digital_gain_register(unsigned int reg)
3565{
3566 bool rtn = false;
3567 switch (reg) {
3568 case TABLA_A_CDC_RX1_VOL_CTL_B2_CTL:
3569 case TABLA_A_CDC_RX2_VOL_CTL_B2_CTL:
3570 case TABLA_A_CDC_RX3_VOL_CTL_B2_CTL:
3571 case TABLA_A_CDC_RX4_VOL_CTL_B2_CTL:
3572 case TABLA_A_CDC_RX5_VOL_CTL_B2_CTL:
3573 case TABLA_A_CDC_RX6_VOL_CTL_B2_CTL:
3574 case TABLA_A_CDC_RX7_VOL_CTL_B2_CTL:
3575 case TABLA_A_CDC_TX1_VOL_CTL_GAIN:
3576 case TABLA_A_CDC_TX2_VOL_CTL_GAIN:
3577 case TABLA_A_CDC_TX3_VOL_CTL_GAIN:
3578 case TABLA_A_CDC_TX4_VOL_CTL_GAIN:
3579 case TABLA_A_CDC_TX5_VOL_CTL_GAIN:
3580 case TABLA_A_CDC_TX6_VOL_CTL_GAIN:
3581 case TABLA_A_CDC_TX7_VOL_CTL_GAIN:
3582 case TABLA_A_CDC_TX8_VOL_CTL_GAIN:
3583 case TABLA_A_CDC_TX9_VOL_CTL_GAIN:
3584 case TABLA_A_CDC_TX10_VOL_CTL_GAIN:
3585 rtn = true;
3586 break;
3587 default:
3588 break;
3589 }
3590 return rtn;
3591}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003592static int tabla_volatile(struct snd_soc_codec *ssc, unsigned int reg)
3593{
3594 /* Registers lower than 0x100 are top level registers which can be
3595 * written by the Tabla core driver.
3596 */
3597
3598 if ((reg >= TABLA_A_CDC_MBHC_EN_CTL) || (reg < 0x100))
3599 return 1;
3600
Ben Romberger1f045a72011-11-04 10:14:57 -07003601 /* IIR Coeff registers are not cacheable */
3602 if ((reg >= TABLA_A_CDC_IIR1_COEF_B1_CTL) &&
3603 (reg <= TABLA_A_CDC_IIR2_COEF_B5_CTL))
3604 return 1;
3605
Kuirong Wange9c8a222012-03-28 16:24:09 -07003606 /* Digital gain register is not cacheable so we have to write
3607 * the setting even it is the same
3608 */
3609 if (tabla_is_digital_gain_register(reg))
3610 return 1;
3611
Joonwoo Parkab2c5872012-05-03 15:16:02 -07003612 /* HPH status registers */
3613 if (reg == TABLA_A_RX_HPH_L_STATUS || reg == TABLA_A_RX_HPH_R_STATUS)
3614 return 1;
3615
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003616 return 0;
3617}
3618
3619#define TABLA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
3620static int tabla_write(struct snd_soc_codec *codec, unsigned int reg,
3621 unsigned int value)
3622{
3623 int ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003624 BUG_ON(reg > TABLA_MAX_REGISTER);
3625
3626 if (!tabla_volatile(codec, reg)) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003627 ret = snd_soc_cache_write(codec, reg, value);
3628 if (ret != 0)
3629 dev_err(codec->dev, "Cache write to %x failed: %d\n",
3630 reg, ret);
3631 }
3632
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303633 return wcd9xxx_reg_write(codec->control_data, reg, value);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003634}
3635static unsigned int tabla_read(struct snd_soc_codec *codec,
3636 unsigned int reg)
3637{
3638 unsigned int val;
3639 int ret;
3640
3641 BUG_ON(reg > TABLA_MAX_REGISTER);
3642
3643 if (!tabla_volatile(codec, reg) && tabla_readable(codec, reg) &&
3644 reg < codec->driver->reg_cache_size) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003645 ret = snd_soc_cache_read(codec, reg, &val);
3646 if (ret >= 0) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003647 return val;
3648 } else
3649 dev_err(codec->dev, "Cache read from %x failed: %d\n",
3650 reg, ret);
3651 }
3652
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303653 val = wcd9xxx_reg_read(codec->control_data, reg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003654 return val;
3655}
3656
Joonwoo Parkcf473b42012-03-29 19:48:16 -07003657static s16 tabla_get_current_v_ins(struct tabla_priv *tabla, bool hu)
3658{
3659 s16 v_ins;
3660 if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) &&
3661 tabla->mbhc_micbias_switched)
3662 v_ins = hu ? (s16)tabla->mbhc_data.adj_v_ins_hu :
3663 (s16)tabla->mbhc_data.adj_v_ins_h;
3664 else
3665 v_ins = hu ? (s16)tabla->mbhc_data.v_ins_hu :
3666 (s16)tabla->mbhc_data.v_ins_h;
3667 return v_ins;
3668}
3669
3670static s16 tabla_get_current_v_hs_max(struct tabla_priv *tabla)
3671{
3672 s16 v_hs_max;
3673 struct tabla_mbhc_plug_type_cfg *plug_type;
3674
3675 plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
3676 if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) &&
3677 tabla->mbhc_micbias_switched)
3678 v_hs_max = tabla->mbhc_data.adj_v_hs_max;
3679 else
3680 v_hs_max = plug_type->v_hs_max;
3681 return v_hs_max;
3682}
3683
Bradley Rubincb1e2732011-06-23 16:49:20 -07003684static void tabla_codec_calibrate_hs_polling(struct snd_soc_codec *codec)
3685{
Joonwoo Parkc0672392012-01-11 11:03:14 -08003686 u8 *n_ready, *n_cic;
Joonwoo Park0976d012011-12-22 11:48:18 -08003687 struct tabla_mbhc_btn_detect_cfg *btn_det;
3688 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07003689 const s16 v_ins_hu = tabla_get_current_v_ins(tabla, true);
3690
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003691 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003692
Joonwoo Park0976d012011-12-22 11:48:18 -08003693 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07003694 v_ins_hu & 0xFF);
Joonwoo Park0976d012011-12-22 11:48:18 -08003695 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07003696 (v_ins_hu >> 8) & 0xFF);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003697
Joonwoo Park0976d012011-12-22 11:48:18 -08003698 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL,
3699 tabla->mbhc_data.v_b1_hu & 0xFF);
3700 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL,
3701 (tabla->mbhc_data.v_b1_hu >> 8) & 0xFF);
3702
3703 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL,
3704 tabla->mbhc_data.v_b1_h & 0xFF);
3705 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL,
3706 (tabla->mbhc_data.v_b1_h >> 8) & 0xFF);
3707
3708 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B9_CTL,
3709 tabla->mbhc_data.v_brh & 0xFF);
3710 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B10_CTL,
3711 (tabla->mbhc_data.v_brh >> 8) & 0xFF);
3712
3713 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B11_CTL,
3714 tabla->mbhc_data.v_brl & 0xFF);
3715 snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B12_CTL,
3716 (tabla->mbhc_data.v_brl >> 8) & 0xFF);
3717
Joonwoo Parkc0672392012-01-11 11:03:14 -08003718 n_ready = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_READY);
Joonwoo Park0976d012011-12-22 11:48:18 -08003719 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL,
Joonwoo Parkc0672392012-01-11 11:03:14 -08003720 n_ready[tabla_codec_mclk_index(tabla)]);
Joonwoo Park0976d012011-12-22 11:48:18 -08003721 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B2_CTL,
3722 tabla->mbhc_data.npoll);
3723 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B3_CTL,
3724 tabla->mbhc_data.nbounce_wait);
Joonwoo Park0976d012011-12-22 11:48:18 -08003725 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
Joonwoo Park107edf02012-01-11 11:42:24 -08003726 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL,
3727 n_cic[tabla_codec_mclk_index(tabla)]);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003728}
3729
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003730static int tabla_startup(struct snd_pcm_substream *substream,
3731 struct snd_soc_dai *dai)
3732{
Kuirong Wanga545e722012-02-06 19:12:54 -08003733 struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003734 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
3735 substream->name, substream->stream);
Kuirong Wanga545e722012-02-06 19:12:54 -08003736 if ((tabla_core != NULL) &&
3737 (tabla_core->dev != NULL) &&
3738 (tabla_core->dev->parent != NULL))
3739 pm_runtime_get_sync(tabla_core->dev->parent);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003740
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003741 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003742}
3743
3744static void tabla_shutdown(struct snd_pcm_substream *substream,
3745 struct snd_soc_dai *dai)
3746{
Kuirong Wanga545e722012-02-06 19:12:54 -08003747 struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003748 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
3749 substream->name, substream->stream);
Kuirong Wanga545e722012-02-06 19:12:54 -08003750 if ((tabla_core != NULL) &&
3751 (tabla_core->dev != NULL) &&
3752 (tabla_core->dev->parent != NULL)) {
3753 pm_runtime_mark_last_busy(tabla_core->dev->parent);
3754 pm_runtime_put(tabla_core->dev->parent);
3755 }
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003756}
3757
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003758int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, bool dapm)
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003759{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003760 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
3761
Joonwoo Parkcf473b42012-03-29 19:48:16 -07003762 pr_debug("%s: mclk_enable = %u, dapm = %d\n", __func__, mclk_enable,
3763 dapm);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003764 if (dapm)
3765 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003766 if (mclk_enable) {
3767 tabla->mclk_enabled = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003768
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07003769 if (tabla->mbhc_polling_active) {
Bradley Rubincb1e2732011-06-23 16:49:20 -07003770 tabla_codec_pause_hs_polling(codec);
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07003771 tabla_codec_disable_clock_block(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003772 tabla_codec_enable_bandgap(codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07003773 TABLA_BANDGAP_AUDIO_MODE);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003774 tabla_codec_enable_clock_block(codec, 0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07003775 tabla_codec_calibrate_hs_polling(codec);
3776 tabla_codec_start_hs_polling(codec);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05303777 } else {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07003778 tabla_codec_disable_clock_block(codec);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05303779 tabla_codec_enable_bandgap(codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07003780 TABLA_BANDGAP_AUDIO_MODE);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05303781 tabla_codec_enable_clock_block(codec, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003782 }
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003783 } else {
3784
3785 if (!tabla->mclk_enabled) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003786 if (dapm)
3787 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003788 pr_err("Error, MCLK already diabled\n");
3789 return -EINVAL;
3790 }
3791 tabla->mclk_enabled = false;
3792
3793 if (tabla->mbhc_polling_active) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07003794 tabla_codec_pause_hs_polling(codec);
3795 tabla_codec_disable_clock_block(codec);
3796 tabla_codec_enable_bandgap(codec,
3797 TABLA_BANDGAP_MBHC_MODE);
3798 tabla_enable_rx_bias(codec, 1);
3799 tabla_codec_enable_clock_block(codec, 1);
3800 tabla_codec_calibrate_hs_polling(codec);
3801 tabla_codec_start_hs_polling(codec);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003802 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1,
3803 0x05, 0x01);
Asish Bhattacharya486745a2012-01-20 06:41:53 +05303804 } else {
3805 tabla_codec_disable_clock_block(codec);
3806 tabla_codec_enable_bandgap(codec,
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07003807 TABLA_BANDGAP_OFF);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003808 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003809 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07003810 if (dapm)
3811 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07003812 return 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003813}
3814
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003815static int tabla_set_dai_sysclk(struct snd_soc_dai *dai,
3816 int clk_id, unsigned int freq, int dir)
3817{
3818 pr_debug("%s\n", __func__);
3819 return 0;
3820}
3821
3822static int tabla_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3823{
Santosh Mardie15e2302011-11-15 10:39:23 +05303824 u8 val = 0;
3825 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
3826
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003827 pr_debug("%s\n", __func__);
Santosh Mardie15e2302011-11-15 10:39:23 +05303828 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
3829 case SND_SOC_DAIFMT_CBS_CFS:
3830 /* CPU is master */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303831 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003832 if (dai->id == AIF1_CAP)
Santosh Mardie15e2302011-11-15 10:39:23 +05303833 snd_soc_update_bits(dai->codec,
3834 TABLA_A_CDC_CLK_TX_I2S_CTL,
3835 TABLA_I2S_MASTER_MODE_MASK, 0);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003836 else if (dai->id == AIF1_PB)
Santosh Mardie15e2302011-11-15 10:39:23 +05303837 snd_soc_update_bits(dai->codec,
3838 TABLA_A_CDC_CLK_RX_I2S_CTL,
3839 TABLA_I2S_MASTER_MODE_MASK, 0);
3840 }
3841 break;
3842 case SND_SOC_DAIFMT_CBM_CFM:
3843 /* CPU is slave */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303844 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05303845 val = TABLA_I2S_MASTER_MODE_MASK;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003846 if (dai->id == AIF1_CAP)
Santosh Mardie15e2302011-11-15 10:39:23 +05303847 snd_soc_update_bits(dai->codec,
3848 TABLA_A_CDC_CLK_TX_I2S_CTL, val, val);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003849 else if (dai->id == AIF1_PB)
Santosh Mardie15e2302011-11-15 10:39:23 +05303850 snd_soc_update_bits(dai->codec,
3851 TABLA_A_CDC_CLK_RX_I2S_CTL, val, val);
3852 }
3853 break;
3854 default:
3855 return -EINVAL;
3856 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003857 return 0;
3858}
3859
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003860static int tabla_set_channel_map(struct snd_soc_dai *dai,
3861 unsigned int tx_num, unsigned int *tx_slot,
3862 unsigned int rx_num, unsigned int *rx_slot)
3863
3864{
3865 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
3866 u32 i = 0;
3867 if (!tx_slot && !rx_slot) {
3868 pr_err("%s: Invalid\n", __func__);
3869 return -EINVAL;
3870 }
Kiran Kandia9fffe92012-05-20 23:42:30 -07003871 pr_debug("%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n",
3872 __func__, dai->name, dai->id, tx_num, rx_num);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003873
Kiran Kandia9fffe92012-05-20 23:42:30 -07003874 if (dai->id == AIF1_PB || dai->id == AIF2_PB || dai->id == AIF3_PB) {
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003875 for (i = 0; i < rx_num; i++) {
3876 tabla->dai[dai->id - 1].ch_num[i] = rx_slot[i];
3877 tabla->dai[dai->id - 1].ch_act = 0;
3878 tabla->dai[dai->id - 1].ch_tot = rx_num;
3879 }
Neema Shetty3fb1b802012-04-27 13:53:24 -07003880 } else if (dai->id == AIF1_CAP || dai->id == AIF2_CAP ||
3881 dai->id == AIF3_CAP) {
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003882 for (i = 0; i < tx_num; i++) {
3883 tabla->dai[dai->id - 1].ch_num[i] = tx_slot[i];
3884 tabla->dai[dai->id - 1].ch_act = 0;
3885 tabla->dai[dai->id - 1].ch_tot = tx_num;
3886 }
3887 }
3888 return 0;
3889}
3890
3891static int tabla_get_channel_map(struct snd_soc_dai *dai,
3892 unsigned int *tx_num, unsigned int *tx_slot,
3893 unsigned int *rx_num, unsigned int *rx_slot)
3894
3895{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303896 struct wcd9xxx *tabla = dev_get_drvdata(dai->codec->control_data);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003897
3898 u32 cnt = 0;
3899 u32 tx_ch[SLIM_MAX_TX_PORTS];
3900 u32 rx_ch[SLIM_MAX_RX_PORTS];
3901
3902 if (!rx_slot && !tx_slot) {
3903 pr_err("%s: Invalid\n", __func__);
3904 return -EINVAL;
3905 }
Kiran Kandia9fffe92012-05-20 23:42:30 -07003906
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003907 /* for virtual port, codec driver needs to do
3908 * housekeeping, for now should be ok
3909 */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05303910 wcd9xxx_get_channel(tabla, rx_ch, tx_ch);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003911 if (dai->id == AIF1_PB) {
3912 *rx_num = tabla_dai[dai->id - 1].playback.channels_max;
3913 while (cnt < *rx_num) {
3914 rx_slot[cnt] = rx_ch[cnt];
3915 cnt++;
3916 }
3917 } else if (dai->id == AIF1_CAP) {
3918 *tx_num = tabla_dai[dai->id - 1].capture.channels_max;
3919 while (cnt < *tx_num) {
3920 tx_slot[cnt] = tx_ch[6 + cnt];
3921 cnt++;
3922 }
Neema Shettyd3a89262012-02-16 10:23:50 -08003923 } else if (dai->id == AIF2_PB) {
3924 *rx_num = tabla_dai[dai->id - 1].playback.channels_max;
3925 while (cnt < *rx_num) {
3926 rx_slot[cnt] = rx_ch[5 + cnt];
3927 cnt++;
3928 }
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003929 } else if (dai->id == AIF2_CAP) {
3930 *tx_num = tabla_dai[dai->id - 1].capture.channels_max;
3931 tx_slot[0] = tx_ch[cnt];
3932 tx_slot[1] = tx_ch[1 + cnt];
Kiran Kandi323d7102012-04-18 19:56:14 -07003933 tx_slot[2] = tx_ch[5 + cnt];
Kiran Kandie408b842012-05-17 19:48:04 -07003934 tx_slot[3] = tx_ch[3 + cnt];
Kiran Kandia9fffe92012-05-20 23:42:30 -07003935
3936 } else if (dai->id == AIF3_PB) {
3937 *rx_num = tabla_dai[dai->id - 1].playback.channels_max;
3938 rx_slot[0] = rx_ch[3];
3939 rx_slot[1] = rx_ch[4];
3940
Neema Shetty3fb1b802012-04-27 13:53:24 -07003941 } else if (dai->id == AIF3_CAP) {
3942 *tx_num = tabla_dai[dai->id - 1].capture.channels_max;
3943 tx_slot[cnt] = tx_ch[2 + cnt];
3944 tx_slot[cnt + 1] = tx_ch[4 + cnt];
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003945 }
Kiran Kandia9fffe92012-05-20 23:42:30 -07003946 pr_debug("%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n",
3947 __func__, dai->name, dai->id, *tx_num, *rx_num);
3948
Kiran Kandi1e6371d2012-03-29 11:48:57 -07003949
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08003950 return 0;
3951}
3952
Kiran Kandi93923902012-06-20 17:00:25 -07003953
3954static struct snd_soc_dapm_widget tabla_dapm_aif_in_widgets[] = {
3955
3956 SND_SOC_DAPM_AIF_IN_E("SLIM RX1", "AIF1 Playback", 0, SND_SOC_NOPM, 1,
3957 0, tabla_codec_enable_slimrx,
3958 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
3959
3960 SND_SOC_DAPM_AIF_IN_E("SLIM RX2", "AIF1 Playback", 0, SND_SOC_NOPM, 2,
3961 0, tabla_codec_enable_slimrx,
3962 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
3963
3964 SND_SOC_DAPM_AIF_IN_E("SLIM RX3", "AIF1 Playback", 0, SND_SOC_NOPM, 3,
3965 0, tabla_codec_enable_slimrx,
3966 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
3967
3968 SND_SOC_DAPM_AIF_IN_E("SLIM RX4", "AIF3 Playback", 0, SND_SOC_NOPM, 4,
3969 0, tabla_codec_enable_slimrx,
3970 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
3971
3972 SND_SOC_DAPM_AIF_IN_E("SLIM RX5", "AIF3 Playback", 0, SND_SOC_NOPM, 5,
3973 0, tabla_codec_enable_slimrx,
3974 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
3975
3976 SND_SOC_DAPM_AIF_IN_E("SLIM RX6", "AIF2 Playback", 0, SND_SOC_NOPM, 6,
3977 0, tabla_codec_enable_slimrx,
3978 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
3979
3980 SND_SOC_DAPM_AIF_IN_E("SLIM RX7", "AIF2 Playback", 0, SND_SOC_NOPM, 7,
3981 0, tabla_codec_enable_slimrx,
3982 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
3983};
3984
3985static struct snd_soc_dapm_widget tabla_dapm_aif_out_widgets[] = {
3986
3987 SND_SOC_DAPM_AIF_OUT_E("SLIM TX1", "AIF2 Capture", 0, SND_SOC_NOPM, 1,
3988 0, tabla_codec_enable_slimtx,
3989 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
3990
3991 SND_SOC_DAPM_AIF_OUT_E("SLIM TX2", "AIF2 Capture", 0, SND_SOC_NOPM, 2,
3992 0, tabla_codec_enable_slimtx,
3993 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
3994
3995 SND_SOC_DAPM_AIF_OUT_E("SLIM TX3", "AIF3 Capture", 0, SND_SOC_NOPM, 3,
3996 0, tabla_codec_enable_slimtx,
3997 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
3998
3999 SND_SOC_DAPM_AIF_OUT_E("SLIM TX4", "AIF2 Capture", 0, SND_SOC_NOPM, 4,
4000 0, tabla_codec_enable_slimtx,
4001 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4002
4003 SND_SOC_DAPM_AIF_OUT_E("SLIM TX5", "AIF3 Capture", 0, SND_SOC_NOPM, 5,
4004 0, tabla_codec_enable_slimtx,
4005 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4006
4007 SND_SOC_DAPM_AIF_OUT_E("SLIM TX6", "AIF2 Capture", 0, SND_SOC_NOPM, 6,
4008 0, tabla_codec_enable_slimtx,
4009 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4010
4011 SND_SOC_DAPM_AIF_OUT_E("SLIM TX7", "AIF1 Capture", 0, SND_SOC_NOPM, 7,
4012 0, tabla_codec_enable_slimtx,
4013 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4014
4015 SND_SOC_DAPM_AIF_OUT_E("SLIM TX8", "AIF1 Capture", 0, SND_SOC_NOPM, 8,
4016 0, tabla_codec_enable_slimtx,
4017 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4018
4019 SND_SOC_DAPM_AIF_OUT_E("SLIM TX9", "AIF1 Capture", 0, SND_SOC_NOPM, 9,
4020 0, tabla_codec_enable_slimtx,
4021 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4022
4023 SND_SOC_DAPM_AIF_OUT_E("SLIM TX10", "AIF1 Capture", 0, SND_SOC_NOPM, 10,
4024 0, tabla_codec_enable_slimtx,
4025 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4026};
4027
4028static int tabla_set_interpolator_rate(struct snd_soc_dai *dai,
4029 u8 rx_fs_rate_reg_val, u32 compander_fs, u32 sample_rate)
4030{
4031 u32 i, j;
4032 u8 rx_mix1_inp;
4033 u16 rx_mix_1_reg_1, rx_mix_1_reg_2;
4034 u16 rx_fs_reg;
4035 u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val;
4036 struct snd_soc_codec *codec = dai->codec;
4037 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
4038 struct snd_soc_dapm_widget *w = tabla_dapm_aif_in_widgets;
4039
4040 for (i = 0; i < ARRAY_SIZE(tabla_dapm_aif_in_widgets); i++) {
4041
4042 if (strncmp(dai->driver->playback.stream_name, w[i].sname, 13))
4043 continue;
4044
4045 rx_mix1_inp = w[i].shift + 4;
4046
4047 if ((rx_mix1_inp < 0x5) || (rx_mix1_inp > 0xB)) {
4048
4049 pr_err("%s: Invalid SLIM RX%u port. widget = %s\n",
4050 __func__, rx_mix1_inp - 4 , w[i].name);
4051 return -EINVAL;
4052 }
4053
4054 rx_mix_1_reg_1 = TABLA_A_CDC_CONN_RX1_B1_CTL;
4055
4056 for (j = 0; j < NUM_INTERPOLATORS; j++) {
4057
4058 rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1;
4059
4060 rx_mix_1_reg_1_val = snd_soc_read(codec,
4061 rx_mix_1_reg_1);
4062 rx_mix_1_reg_2_val = snd_soc_read(codec,
4063 rx_mix_1_reg_2);
4064
4065 if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) ||
4066 (((rx_mix_1_reg_1_val >> 4) & 0x0F) == rx_mix1_inp)
4067 || ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) {
4068
4069 rx_fs_reg = TABLA_A_CDC_RX1_B5_CTL + 8 * j;
4070
4071 pr_debug("%s: %s connected to RX%u\n", __func__,
4072 w[i].name, j + 1);
4073
4074 pr_debug("%s: set RX%u sample rate to %u\n",
4075 __func__, j + 1, sample_rate);
4076
4077 snd_soc_update_bits(codec, rx_fs_reg,
4078 0xE0, rx_fs_rate_reg_val);
4079
4080 if (comp_rx_path[j] < COMPANDER_MAX)
4081 tabla->comp_fs[comp_rx_path[j]]
4082 = compander_fs;
4083 }
4084 if (j <= 2)
4085 rx_mix_1_reg_1 += 3;
4086 else
4087 rx_mix_1_reg_1 += 2;
4088 }
4089 }
4090 return 0;
4091}
4092
4093static int tabla_set_decimator_rate(struct snd_soc_dai *dai,
4094 u8 tx_fs_rate_reg_val, u32 sample_rate)
4095{
4096 struct snd_soc_codec *codec = dai->codec;
4097 struct snd_soc_dapm_widget *w = tabla_dapm_aif_out_widgets;
4098
4099 u32 i, tx_port;
4100 u16 tx_port_reg, tx_fs_reg;
4101 u8 tx_port_reg_val;
4102 s8 decimator;
4103
4104 for (i = 0; i < ARRAY_SIZE(tabla_dapm_aif_out_widgets); i++) {
4105
4106 if (strncmp(dai->driver->capture.stream_name, w[i].sname, 12))
4107 continue;
4108
4109 tx_port = w[i].shift;
4110
4111 if ((tx_port < 1) || (tx_port > NUM_DECIMATORS)) {
4112 pr_err("%s: Invalid SLIM TX%u port. widget = %s\n",
4113 __func__, tx_port, w[i].name);
4114 return -EINVAL;
4115 }
4116
4117 tx_port_reg = TABLA_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1);
4118 tx_port_reg_val = snd_soc_read(codec, tx_port_reg);
4119
4120 decimator = 0;
4121
4122 if ((tx_port >= 1) && (tx_port <= 6)) {
4123
4124 tx_port_reg_val = tx_port_reg_val & 0x0F;
4125 if (tx_port_reg_val == 0x8)
4126 decimator = tx_port;
4127
4128 } else if ((tx_port >= 7) && (tx_port <= NUM_DECIMATORS)) {
4129
4130 tx_port_reg_val = tx_port_reg_val & 0x1F;
4131
4132 if ((tx_port_reg_val >= 0x8) &&
4133 (tx_port_reg_val <= 0x11)) {
4134
4135 decimator = (tx_port_reg_val - 0x8) + 1;
4136 }
4137 }
4138
4139 if (decimator) { /* SLIM_TX port has a DEC as input */
4140
4141 tx_fs_reg = TABLA_A_CDC_TX1_CLK_FS_CTL +
4142 8 * (decimator - 1);
4143
4144 pr_debug("%s: set DEC%u (-> SLIM_TX%u) rate to %u\n",
4145 __func__, decimator, tx_port, sample_rate);
4146
4147 snd_soc_update_bits(codec, tx_fs_reg, 0x07,
4148 tx_fs_rate_reg_val);
4149
4150 } else {
4151 if ((tx_port_reg_val >= 0x1) &&
4152 (tx_port_reg_val <= 0x7)) {
4153
4154 pr_debug("%s: RMIX%u going to SLIM TX%u\n",
4155 __func__, tx_port_reg_val, tx_port);
4156
4157 } else if ((tx_port_reg_val >= 0x8) &&
4158 (tx_port_reg_val <= 0x11)) {
4159
4160 pr_err("%s: ERROR: Should not be here\n",
4161 __func__);
4162 pr_err("%s: ERROR: DEC connected to SLIM TX%u\n"
4163 , __func__, tx_port);
4164 return -EINVAL;
4165
4166 } else if (tx_port_reg_val == 0) {
4167 pr_debug("%s: no signal to SLIM TX%u\n",
4168 __func__, tx_port);
4169 } else {
4170 pr_err("%s: ERROR: wrong signal to SLIM TX%u\n"
4171 , __func__, tx_port);
4172 pr_err("%s: ERROR: wrong signal = %u\n"
4173 , __func__, tx_port_reg_val);
4174 return -EINVAL;
4175 }
4176 }
4177 }
4178 return 0;
4179}
4180
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004181static int tabla_hw_params(struct snd_pcm_substream *substream,
Kiran Kandi93923902012-06-20 17:00:25 -07004182 struct snd_pcm_hw_params *params,
4183 struct snd_soc_dai *dai)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004184{
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004185 struct snd_soc_codec *codec = dai->codec;
Santosh Mardie15e2302011-11-15 10:39:23 +05304186 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec);
Kiran Kandi93923902012-06-20 17:00:25 -07004187 u8 tx_fs_rate_reg_val, rx_fs_rate_reg_val;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004188 u32 compander_fs;
Kiran Kandi93923902012-06-20 17:00:25 -07004189 int ret;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004190
Kiran Kandia9fffe92012-05-20 23:42:30 -07004191 pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
Kiran Kandi93923902012-06-20 17:00:25 -07004192 dai->name, dai->id, params_rate(params),
4193 params_channels(params));
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004194
4195 switch (params_rate(params)) {
4196 case 8000:
Kiran Kandi93923902012-06-20 17:00:25 -07004197 tx_fs_rate_reg_val = 0x00;
4198 rx_fs_rate_reg_val = 0x00;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004199 compander_fs = COMPANDER_FS_8KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004200 break;
4201 case 16000:
Kiran Kandi93923902012-06-20 17:00:25 -07004202 tx_fs_rate_reg_val = 0x01;
4203 rx_fs_rate_reg_val = 0x20;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004204 compander_fs = COMPANDER_FS_16KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004205 break;
4206 case 32000:
Kiran Kandi93923902012-06-20 17:00:25 -07004207 tx_fs_rate_reg_val = 0x02;
4208 rx_fs_rate_reg_val = 0x40;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004209 compander_fs = COMPANDER_FS_32KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004210 break;
4211 case 48000:
Kiran Kandi93923902012-06-20 17:00:25 -07004212 tx_fs_rate_reg_val = 0x03;
4213 rx_fs_rate_reg_val = 0x60;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004214 compander_fs = COMPANDER_FS_48KHZ;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004215 break;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004216 case 96000:
Kiran Kandi93923902012-06-20 17:00:25 -07004217 tx_fs_rate_reg_val = 0x04;
4218 rx_fs_rate_reg_val = 0x80;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004219 compander_fs = COMPANDER_FS_96KHZ;
4220 break;
4221 case 192000:
Kiran Kandi93923902012-06-20 17:00:25 -07004222 tx_fs_rate_reg_val = 0x05;
4223 rx_fs_rate_reg_val = 0xA0;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004224 compander_fs = COMPANDER_FS_192KHZ;
4225 break;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004226 default:
4227 pr_err("%s: Invalid sampling rate %d\n", __func__,
4228 params_rate(params));
4229 return -EINVAL;
4230 }
4231
Kiran Kandi93923902012-06-20 17:00:25 -07004232 switch (substream->stream) {
4233 case SNDRV_PCM_STREAM_CAPTURE:
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004234
Kiran Kandi93923902012-06-20 17:00:25 -07004235 ret = tabla_set_decimator_rate(dai, tx_fs_rate_reg_val,
4236 params_rate(params));
4237 if (ret < 0) {
4238 pr_err("%s: set decimator rate failed %d\n", __func__,
4239 ret);
4240 return ret;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004241 }
Kiran Kandi93923902012-06-20 17:00:25 -07004242
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304243 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05304244 switch (params_format(params)) {
4245 case SNDRV_PCM_FORMAT_S16_LE:
4246 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004247 TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x20);
Santosh Mardie15e2302011-11-15 10:39:23 +05304248 break;
4249 case SNDRV_PCM_FORMAT_S32_LE:
4250 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004251 TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x00);
Santosh Mardie15e2302011-11-15 10:39:23 +05304252 break;
4253 default:
Kiran Kandi93923902012-06-20 17:00:25 -07004254 pr_err("%s: invalid TX format %u\n", __func__,
4255 params_format(params));
4256 return -EINVAL;
Santosh Mardie15e2302011-11-15 10:39:23 +05304257 }
4258 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_TX_I2S_CTL,
Kiran Kandi93923902012-06-20 17:00:25 -07004259 0x07, tx_fs_rate_reg_val);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004260 } else {
4261 tabla->dai[dai->id - 1].rate = params_rate(params);
Santosh Mardie15e2302011-11-15 10:39:23 +05304262 }
Kiran Kandi93923902012-06-20 17:00:25 -07004263 break;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004264
Kiran Kandi93923902012-06-20 17:00:25 -07004265 case SNDRV_PCM_STREAM_PLAYBACK:
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004266
Kiran Kandi93923902012-06-20 17:00:25 -07004267 ret = tabla_set_interpolator_rate(dai, rx_fs_rate_reg_val,
4268 compander_fs, params_rate(params));
4269 if (ret < 0) {
4270 pr_err("%s: set decimator rate failed %d\n", __func__,
4271 ret);
4272 return ret;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004273 }
Kiran Kandi93923902012-06-20 17:00:25 -07004274
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304275 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05304276 switch (params_format(params)) {
4277 case SNDRV_PCM_FORMAT_S16_LE:
4278 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004279 TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x20);
Santosh Mardie15e2302011-11-15 10:39:23 +05304280 break;
4281 case SNDRV_PCM_FORMAT_S32_LE:
4282 snd_soc_update_bits(codec,
Kiran Kandi93923902012-06-20 17:00:25 -07004283 TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x00);
Santosh Mardie15e2302011-11-15 10:39:23 +05304284 break;
4285 default:
Kiran Kandi93923902012-06-20 17:00:25 -07004286 pr_err("%s: invalid RX format %u\n", __func__,
4287 params_format(params));
4288 return -EINVAL;
Santosh Mardie15e2302011-11-15 10:39:23 +05304289 }
4290 snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_I2S_CTL,
Kiran Kandi93923902012-06-20 17:00:25 -07004291 0x03, (rx_fs_rate_reg_val >> 0x05));
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004292 } else {
4293 tabla->dai[dai->id - 1].rate = params_rate(params);
Santosh Mardie15e2302011-11-15 10:39:23 +05304294 }
Kiran Kandi93923902012-06-20 17:00:25 -07004295 break;
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004296
Kiran Kandi93923902012-06-20 17:00:25 -07004297 default:
4298 pr_err("%s: Invalid stream type %d\n", __func__,
4299 substream->stream);
4300 return -EINVAL;
4301 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004302 return 0;
4303}
4304
4305static struct snd_soc_dai_ops tabla_dai_ops = {
4306 .startup = tabla_startup,
4307 .shutdown = tabla_shutdown,
4308 .hw_params = tabla_hw_params,
4309 .set_sysclk = tabla_set_dai_sysclk,
4310 .set_fmt = tabla_set_dai_fmt,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004311 .set_channel_map = tabla_set_channel_map,
4312 .get_channel_map = tabla_get_channel_map,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004313};
4314
4315static struct snd_soc_dai_driver tabla_dai[] = {
4316 {
4317 .name = "tabla_rx1",
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004318 .id = AIF1_PB,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004319 .playback = {
4320 .stream_name = "AIF1 Playback",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004321 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004322 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004323 .rate_max = 192000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004324 .rate_min = 8000,
4325 .channels_min = 1,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004326 .channels_max = 2,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004327 },
4328 .ops = &tabla_dai_ops,
4329 },
4330 {
4331 .name = "tabla_tx1",
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004332 .id = AIF1_CAP,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004333 .capture = {
4334 .stream_name = "AIF1 Capture",
Bhalchandra Gajare9a901fd2011-08-01 10:07:15 -07004335 .rates = WCD9310_RATES,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004336 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004337 .rate_max = 192000,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004338 .rate_min = 8000,
4339 .channels_min = 1,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004340 .channels_max = 4,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004341 },
4342 .ops = &tabla_dai_ops,
4343 },
Neema Shettyd3a89262012-02-16 10:23:50 -08004344 {
4345 .name = "tabla_rx2",
4346 .id = AIF2_PB,
4347 .playback = {
4348 .stream_name = "AIF2 Playback",
4349 .rates = WCD9310_RATES,
4350 .formats = TABLA_FORMATS,
4351 .rate_min = 8000,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004352 .rate_max = 192000,
Neema Shettyd3a89262012-02-16 10:23:50 -08004353 .channels_min = 1,
4354 .channels_max = 2,
4355 },
4356 .ops = &tabla_dai_ops,
4357 },
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004358 {
4359 .name = "tabla_tx2",
4360 .id = AIF2_CAP,
4361 .capture = {
4362 .stream_name = "AIF2 Capture",
4363 .rates = WCD9310_RATES,
4364 .formats = TABLA_FORMATS,
4365 .rate_max = 192000,
4366 .rate_min = 8000,
4367 .channels_min = 1,
4368 .channels_max = 4,
4369 },
4370 .ops = &tabla_dai_ops,
4371 },
Neema Shetty3fb1b802012-04-27 13:53:24 -07004372 {
4373 .name = "tabla_tx3",
4374 .id = AIF3_CAP,
4375 .capture = {
4376 .stream_name = "AIF3 Capture",
4377 .rates = WCD9310_RATES,
4378 .formats = TABLA_FORMATS,
4379 .rate_max = 48000,
4380 .rate_min = 8000,
4381 .channels_min = 1,
4382 .channels_max = 2,
4383 },
4384 .ops = &tabla_dai_ops,
4385 },
Kiran Kandia9fffe92012-05-20 23:42:30 -07004386 {
4387 .name = "tabla_rx3",
4388 .id = AIF3_PB,
4389 .playback = {
4390 .stream_name = "AIF3 Playback",
4391 .rates = WCD9310_RATES,
4392 .formats = TABLA_FORMATS,
4393 .rate_min = 8000,
4394 .rate_max = 192000,
4395 .channels_min = 1,
4396 .channels_max = 2,
4397 },
4398 .ops = &tabla_dai_ops,
4399 },
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004400};
Santosh Mardie15e2302011-11-15 10:39:23 +05304401
4402static struct snd_soc_dai_driver tabla_i2s_dai[] = {
4403 {
4404 .name = "tabla_i2s_rx1",
4405 .id = 1,
4406 .playback = {
4407 .stream_name = "AIF1 Playback",
4408 .rates = WCD9310_RATES,
4409 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004410 .rate_max = 192000,
Santosh Mardie15e2302011-11-15 10:39:23 +05304411 .rate_min = 8000,
4412 .channels_min = 1,
4413 .channels_max = 4,
4414 },
4415 .ops = &tabla_dai_ops,
4416 },
4417 {
4418 .name = "tabla_i2s_tx1",
4419 .id = 2,
4420 .capture = {
4421 .stream_name = "AIF1 Capture",
4422 .rates = WCD9310_RATES,
4423 .formats = TABLA_FORMATS,
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004424 .rate_max = 192000,
Santosh Mardie15e2302011-11-15 10:39:23 +05304425 .rate_min = 8000,
4426 .channels_min = 1,
4427 .channels_max = 4,
4428 },
4429 .ops = &tabla_dai_ops,
4430 },
4431};
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004432
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07004433static int tabla_codec_enable_chmask(struct tabla_priv *tabla_p,
4434 int event, int index)
4435{
4436 int ret = 0;
4437 u32 k = 0;
4438 switch (event) {
4439 case SND_SOC_DAPM_POST_PMU:
4440 for (k = 0; k < tabla_p->dai[index].ch_tot; k++) {
4441 ret = wcd9xxx_get_slave_port(
4442 tabla_p->dai[index].ch_num[k]);
4443 if (ret < 0) {
4444 pr_err("%s: Invalid slave port ID: %d\n",
4445 __func__, ret);
4446 ret = -EINVAL;
4447 break;
4448 }
4449 tabla_p->dai[index].ch_mask |= 1 << ret;
4450 }
4451 ret = 0;
4452 break;
4453 case SND_SOC_DAPM_POST_PMD:
4454 ret = wait_event_timeout(tabla_p->dai[index].dai_wait,
4455 (tabla_p->dai[index].ch_mask == 0),
4456 msecs_to_jiffies(SLIM_CLOSE_TIMEOUT));
4457 if (!ret) {
4458 pr_err("%s: Slim close tx/rx wait timeout\n",
4459 __func__);
4460 ret = -EINVAL;
4461 }
4462 ret = 0;
4463 break;
4464 }
4465 return ret;
4466}
4467
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004468static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
4469 struct snd_kcontrol *kcontrol, int event)
4470{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304471 struct wcd9xxx *tabla;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004472 struct snd_soc_codec *codec = w->codec;
4473 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
4474 u32 j = 0;
4475 u32 ret = 0;
4476 codec->control_data = dev_get_drvdata(codec->dev->parent);
4477 tabla = codec->control_data;
4478 /* Execute the callback only if interface type is slimbus */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304479 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004480 return 0;
Kiran Kandia9fffe92012-05-20 23:42:30 -07004481
4482 pr_debug("%s: %s %d\n", __func__, w->name, event);
4483
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004484 switch (event) {
4485 case SND_SOC_DAPM_POST_PMU:
4486 for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) {
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004487 if ((tabla_dai[j].id == AIF1_CAP) ||
Neema Shetty3fb1b802012-04-27 13:53:24 -07004488 (tabla_dai[j].id == AIF2_CAP) ||
4489 (tabla_dai[j].id == AIF3_CAP))
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004490 continue;
4491 if (!strncmp(w->sname,
4492 tabla_dai[j].playback.stream_name, 13)) {
4493 ++tabla_p->dai[j].ch_act;
4494 break;
4495 }
4496 }
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07004497 if (tabla_p->dai[j].ch_act == tabla_p->dai[j].ch_tot) {
4498 ret = tabla_codec_enable_chmask(tabla_p,
4499 SND_SOC_DAPM_POST_PMU,
4500 j);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304501 ret = wcd9xxx_cfg_slim_sch_rx(tabla,
4502 tabla_p->dai[j].ch_num,
4503 tabla_p->dai[j].ch_tot,
4504 tabla_p->dai[j].rate);
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07004505 }
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004506 break;
4507 case SND_SOC_DAPM_POST_PMD:
4508 for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) {
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004509 if ((tabla_dai[j].id == AIF1_CAP) ||
Neema Shetty3fb1b802012-04-27 13:53:24 -07004510 (tabla_dai[j].id == AIF2_CAP) ||
4511 (tabla_dai[j].id == AIF3_CAP))
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004512 continue;
4513 if (!strncmp(w->sname,
4514 tabla_dai[j].playback.stream_name, 13)) {
Helen Zeng2aaa3c12012-06-08 20:29:21 -07004515 if (tabla_p->dai[j].ch_act)
4516 --tabla_p->dai[j].ch_act;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004517 break;
4518 }
4519 }
4520 if (!tabla_p->dai[j].ch_act) {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304521 ret = wcd9xxx_close_slim_sch_rx(tabla,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004522 tabla_p->dai[j].ch_num,
4523 tabla_p->dai[j].ch_tot);
4524 tabla_p->dai[j].rate = 0;
4525 memset(tabla_p->dai[j].ch_num, 0, (sizeof(u32)*
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304526 tabla_p->dai[j].ch_tot));
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004527 tabla_p->dai[j].ch_tot = 0;
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07004528 ret = tabla_codec_enable_chmask(tabla_p,
4529 SND_SOC_DAPM_POST_PMD,
4530 j);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004531 }
4532 }
4533 return ret;
4534}
4535
4536static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
4537 struct snd_kcontrol *kcontrol, int event)
4538{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304539 struct wcd9xxx *tabla;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004540 struct snd_soc_codec *codec = w->codec;
4541 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
4542 /* index to the DAI ID, for now hardcoding */
4543 u32 j = 0;
4544 u32 ret = 0;
4545
4546 codec->control_data = dev_get_drvdata(codec->dev->parent);
4547 tabla = codec->control_data;
4548
4549 /* Execute the callback only if interface type is slimbus */
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304550 if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004551 return 0;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004552
4553 pr_debug("%s(): %s %d\n", __func__, w->name, event);
4554
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004555 switch (event) {
4556 case SND_SOC_DAPM_POST_PMU:
4557 for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) {
Neema Shettyd3a89262012-02-16 10:23:50 -08004558 if (tabla_dai[j].id == AIF1_PB ||
Kiran Kandia9fffe92012-05-20 23:42:30 -07004559 tabla_dai[j].id == AIF2_PB ||
4560 tabla_dai[j].id == AIF3_PB)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004561 continue;
4562 if (!strncmp(w->sname,
4563 tabla_dai[j].capture.stream_name, 13)) {
4564 ++tabla_p->dai[j].ch_act;
4565 break;
4566 }
4567 }
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07004568 if (tabla_p->dai[j].ch_act == tabla_p->dai[j].ch_tot) {
4569 ret = tabla_codec_enable_chmask(tabla_p,
4570 SND_SOC_DAPM_POST_PMU,
4571 j);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304572 ret = wcd9xxx_cfg_slim_sch_tx(tabla,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004573 tabla_p->dai[j].ch_num,
4574 tabla_p->dai[j].ch_tot,
4575 tabla_p->dai[j].rate);
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07004576 }
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004577 break;
4578 case SND_SOC_DAPM_POST_PMD:
4579 for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) {
Neema Shettyd3a89262012-02-16 10:23:50 -08004580 if (tabla_dai[j].id == AIF1_PB ||
Kiran Kandia9fffe92012-05-20 23:42:30 -07004581 tabla_dai[j].id == AIF2_PB ||
4582 tabla_dai[j].id == AIF3_PB)
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004583 continue;
4584 if (!strncmp(w->sname,
4585 tabla_dai[j].capture.stream_name, 13)) {
4586 --tabla_p->dai[j].ch_act;
4587 break;
4588 }
4589 }
4590 if (!tabla_p->dai[j].ch_act) {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304591 ret = wcd9xxx_close_slim_sch_tx(tabla,
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004592 tabla_p->dai[j].ch_num,
4593 tabla_p->dai[j].ch_tot);
4594 tabla_p->dai[j].rate = 0;
4595 memset(tabla_p->dai[j].ch_num, 0, (sizeof(u32)*
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05304596 tabla_p->dai[j].ch_tot));
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004597 tabla_p->dai[j].ch_tot = 0;
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07004598 ret = tabla_codec_enable_chmask(tabla_p,
4599 SND_SOC_DAPM_POST_PMD,
4600 j);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004601 }
4602 }
4603 return ret;
4604}
4605
4606/* Todo: Have seperate dapm widgets for I2S and Slimbus.
4607 * Might Need to have callbacks registered only for slimbus
4608 */
4609static const struct snd_soc_dapm_widget tabla_dapm_widgets[] = {
4610 /*RX stuff */
4611 SND_SOC_DAPM_OUTPUT("EAR"),
4612
4613 SND_SOC_DAPM_PGA("EAR PA", TABLA_A_RX_EAR_EN, 4, 0, NULL, 0),
4614
4615 SND_SOC_DAPM_MIXER("DAC1", TABLA_A_RX_EAR_EN, 6, 0, dac1_switch,
4616 ARRAY_SIZE(dac1_switch)),
4617
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004618 /* Headphone */
4619 SND_SOC_DAPM_OUTPUT("HEADPHONE"),
4620 SND_SOC_DAPM_PGA_E("HPHL", TABLA_A_RX_HPH_CNP_EN, 5, 0, NULL, 0,
4621 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
4622 SND_SOC_DAPM_POST_PMD),
4623 SND_SOC_DAPM_MIXER("HPHL DAC", TABLA_A_RX_HPH_L_DAC_CTL, 7, 0,
4624 hphl_switch, ARRAY_SIZE(hphl_switch)),
4625
4626 SND_SOC_DAPM_PGA_E("HPHR", TABLA_A_RX_HPH_CNP_EN, 4, 0, NULL, 0,
4627 tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
4628 SND_SOC_DAPM_POST_PMD),
4629
4630 SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TABLA_A_RX_HPH_R_DAC_CTL, 7, 0,
4631 tabla_hphr_dac_event,
4632 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4633
4634 /* Speaker */
4635 SND_SOC_DAPM_OUTPUT("LINEOUT1"),
4636 SND_SOC_DAPM_OUTPUT("LINEOUT2"),
4637 SND_SOC_DAPM_OUTPUT("LINEOUT3"),
4638 SND_SOC_DAPM_OUTPUT("LINEOUT4"),
4639 SND_SOC_DAPM_OUTPUT("LINEOUT5"),
4640
4641 SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TABLA_A_RX_LINE_CNP_EN, 0, 0, NULL,
4642 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4643 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4644 SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TABLA_A_RX_LINE_CNP_EN, 1, 0, NULL,
4645 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4646 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4647 SND_SOC_DAPM_PGA_E("LINEOUT3 PA", TABLA_A_RX_LINE_CNP_EN, 2, 0, NULL,
4648 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4649 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4650 SND_SOC_DAPM_PGA_E("LINEOUT4 PA", TABLA_A_RX_LINE_CNP_EN, 3, 0, NULL,
4651 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4652 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4653 SND_SOC_DAPM_PGA_E("LINEOUT5 PA", TABLA_A_RX_LINE_CNP_EN, 4, 0, NULL, 0,
4654 tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4655 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4656
4657 SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TABLA_A_RX_LINE_1_DAC_CTL, 7, 0
4658 , tabla_lineout_dac_event,
4659 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4660 SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TABLA_A_RX_LINE_2_DAC_CTL, 7, 0
4661 , tabla_lineout_dac_event,
4662 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4663 SND_SOC_DAPM_DAC_E("LINEOUT3 DAC", NULL, TABLA_A_RX_LINE_3_DAC_CTL, 7, 0
4664 , tabla_lineout_dac_event,
4665 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4666 SND_SOC_DAPM_SWITCH("LINEOUT3 DAC GROUND", SND_SOC_NOPM, 0, 0,
4667 &lineout3_ground_switch),
4668 SND_SOC_DAPM_DAC_E("LINEOUT4 DAC", NULL, TABLA_A_RX_LINE_4_DAC_CTL, 7, 0
4669 , tabla_lineout_dac_event,
4670 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4671 SND_SOC_DAPM_SWITCH("LINEOUT4 DAC GROUND", SND_SOC_NOPM, 0, 0,
4672 &lineout4_ground_switch),
4673 SND_SOC_DAPM_DAC_E("LINEOUT5 DAC", NULL, TABLA_A_RX_LINE_5_DAC_CTL, 7, 0
4674 , tabla_lineout_dac_event,
4675 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4676
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004677 SND_SOC_DAPM_MIXER_E("RX1 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004678 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4679 SND_SOC_DAPM_POST_PMU),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004680 SND_SOC_DAPM_MIXER_E("RX2 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004681 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4682 SND_SOC_DAPM_POST_PMU),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004683 SND_SOC_DAPM_MIXER_E("RX3 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004684 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4685 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004686 SND_SOC_DAPM_MIXER_E("RX4 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004687 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4688 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004689 SND_SOC_DAPM_MIXER_E("RX5 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 4, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004690 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4691 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004692 SND_SOC_DAPM_MIXER_E("RX6 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004693 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4694 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004695 SND_SOC_DAPM_MIXER_E("RX7 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 6, 0, NULL,
Kuirong Wange9c8a222012-03-28 16:24:09 -07004696 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU |
4697 SND_SOC_DAPM_POST_PMU),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004698
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004699 SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4700 SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4701 SND_SOC_DAPM_MIXER("RX3 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4702
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004703 SND_SOC_DAPM_MUX_E("RX4 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0,
4704 &rx4_dsm_mux, tabla_codec_reset_interpolator,
4705 SND_SOC_DAPM_PRE_PMU),
4706
4707 SND_SOC_DAPM_MUX_E("RX6 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0,
4708 &rx6_dsm_mux, tabla_codec_reset_interpolator,
4709 SND_SOC_DAPM_PRE_PMU),
4710
4711 SND_SOC_DAPM_MIXER("RX1 CHAIN", TABLA_A_CDC_RX1_B6_CTL, 5, 0, NULL, 0),
4712 SND_SOC_DAPM_MIXER("RX2 CHAIN", TABLA_A_CDC_RX2_B6_CTL, 5, 0, NULL, 0),
4713
4714 SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4715 &rx_mix1_inp1_mux),
4716 SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4717 &rx_mix1_inp2_mux),
Kiran Kandia9fffe92012-05-20 23:42:30 -07004718 SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0,
4719 &rx_mix1_inp3_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004720 SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4721 &rx2_mix1_inp1_mux),
4722 SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4723 &rx2_mix1_inp2_mux),
4724 SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4725 &rx3_mix1_inp1_mux),
4726 SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4727 &rx3_mix1_inp2_mux),
4728 SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4729 &rx4_mix1_inp1_mux),
4730 SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4731 &rx4_mix1_inp2_mux),
4732 SND_SOC_DAPM_MUX("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4733 &rx5_mix1_inp1_mux),
4734 SND_SOC_DAPM_MUX("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4735 &rx5_mix1_inp2_mux),
4736 SND_SOC_DAPM_MUX("RX6 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4737 &rx6_mix1_inp1_mux),
4738 SND_SOC_DAPM_MUX("RX6 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4739 &rx6_mix1_inp2_mux),
4740 SND_SOC_DAPM_MUX("RX7 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4741 &rx7_mix1_inp1_mux),
4742 SND_SOC_DAPM_MUX("RX7 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4743 &rx7_mix1_inp2_mux),
Kuirong Wangbfdd6ca2012-02-29 13:06:38 -08004744 SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0,
4745 &rx1_mix2_inp1_mux),
4746 SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0,
4747 &rx1_mix2_inp2_mux),
4748 SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0,
4749 &rx2_mix2_inp1_mux),
4750 SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0,
4751 &rx2_mix2_inp2_mux),
4752 SND_SOC_DAPM_MUX("RX3 MIX2 INP1", SND_SOC_NOPM, 0, 0,
4753 &rx3_mix2_inp1_mux),
4754 SND_SOC_DAPM_MUX("RX3 MIX2 INP2", SND_SOC_NOPM, 0, 0,
4755 &rx3_mix2_inp2_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004756
4757 SND_SOC_DAPM_SUPPLY("CP", TABLA_A_CP_EN, 0, 0,
4758 tabla_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU |
4759 SND_SOC_DAPM_PRE_PMD),
4760
4761 SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
4762 tabla_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
4763 SND_SOC_DAPM_POST_PMD),
4764
4765 /* TX */
4766
4767 SND_SOC_DAPM_SUPPLY("CDC_CONN", TABLA_A_CDC_CLK_OTHR_CTL, 2, 0, NULL,
4768 0),
4769
4770 SND_SOC_DAPM_SUPPLY("LDO_H", TABLA_A_LDO_H_MODE_1, 7, 0,
4771 tabla_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU),
4772
Kuirong Wang0f8ade32012-02-27 16:29:45 -08004773 SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 0, 0,
4774 tabla_config_compander, SND_SOC_DAPM_PRE_PMU |
4775 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
4776 SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 1, 0,
4777 tabla_config_compander, SND_SOC_DAPM_PRE_PMU |
4778 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD),
4779
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004780 SND_SOC_DAPM_INPUT("AMIC1"),
4781 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", TABLA_A_MICB_1_CTL, 7, 0,
4782 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4783 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4784 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", TABLA_A_MICB_1_CTL, 7, 0,
4785 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4786 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4787 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", TABLA_A_MICB_1_CTL, 7, 0,
4788 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4789 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4790 SND_SOC_DAPM_ADC_E("ADC1", NULL, TABLA_A_TX_1_2_EN, 7, 0,
4791 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4792 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4793
4794 SND_SOC_DAPM_INPUT("AMIC3"),
4795 SND_SOC_DAPM_ADC_E("ADC3", NULL, TABLA_A_TX_3_4_EN, 7, 0,
4796 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4797 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4798
4799 SND_SOC_DAPM_INPUT("AMIC4"),
4800 SND_SOC_DAPM_ADC_E("ADC4", NULL, TABLA_A_TX_3_4_EN, 3, 0,
4801 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4802 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4803
4804 SND_SOC_DAPM_INPUT("AMIC5"),
4805 SND_SOC_DAPM_ADC_E("ADC5", NULL, TABLA_A_TX_5_6_EN, 7, 0,
4806 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
4807
4808 SND_SOC_DAPM_INPUT("AMIC6"),
4809 SND_SOC_DAPM_ADC_E("ADC6", NULL, TABLA_A_TX_5_6_EN, 3, 0,
4810 tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
4811
4812 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 -08004813 &dec1_mux, tabla_codec_enable_dec,
4814 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4815 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004816
4817 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 -08004818 &dec2_mux, tabla_codec_enable_dec,
4819 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4820 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004821
4822 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 -08004823 &dec3_mux, tabla_codec_enable_dec,
4824 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4825 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004826
4827 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 -08004828 &dec4_mux, tabla_codec_enable_dec,
4829 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4830 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004831
4832 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 -08004833 &dec5_mux, tabla_codec_enable_dec,
4834 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4835 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004836
4837 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 -08004838 &dec6_mux, tabla_codec_enable_dec,
4839 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4840 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004841
4842 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 -08004843 &dec7_mux, tabla_codec_enable_dec,
4844 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4845 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004846
4847 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 -08004848 &dec8_mux, tabla_codec_enable_dec,
4849 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4850 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004851
4852 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 -08004853 &dec9_mux, tabla_codec_enable_dec,
4854 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4855 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004856
4857 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 -08004858 &dec10_mux, tabla_codec_enable_dec,
4859 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4860 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004861
4862 SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux),
4863 SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux),
4864
4865 SND_SOC_DAPM_MIXER_E("ANC", SND_SOC_NOPM, 0, 0, NULL, 0,
4866 tabla_codec_enable_anc, SND_SOC_DAPM_PRE_PMU |
4867 SND_SOC_DAPM_POST_PMD),
4868
4869 SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux),
4870
4871 SND_SOC_DAPM_INPUT("AMIC2"),
4872 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", TABLA_A_MICB_2_CTL, 7, 0,
4873 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4874 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4875 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", TABLA_A_MICB_2_CTL, 7, 0,
4876 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4877 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4878 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", TABLA_A_MICB_2_CTL, 7, 0,
4879 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4880 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4881 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", TABLA_A_MICB_2_CTL, 7, 0,
4882 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4883 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4884 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", TABLA_A_MICB_3_CTL, 7, 0,
4885 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4886 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4887 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", TABLA_A_MICB_3_CTL, 7, 0,
4888 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4889 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4890 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", TABLA_A_MICB_3_CTL, 7, 0,
4891 tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4892 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4893 SND_SOC_DAPM_ADC_E("ADC2", NULL, TABLA_A_TX_1_2_EN, 3, 0,
4894 tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4895 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4896
4897 SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, 0, 0, &sb_tx1_mux),
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004898 SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, 0, 0, &sb_tx2_mux),
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004899 SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, 0, 0, &sb_tx3_mux),
Kiran Kandi1e6371d2012-03-29 11:48:57 -07004900 SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, 0, 0, &sb_tx4_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004901 SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, 0, 0, &sb_tx5_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004902 SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, 0, 0, &sb_tx6_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004903 SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, 0, 0, &sb_tx7_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004904 SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, 0, 0, &sb_tx8_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004905 SND_SOC_DAPM_MUX("SLIM TX9 MUX", SND_SOC_NOPM, 0, 0, &sb_tx9_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004906 SND_SOC_DAPM_MUX("SLIM TX10 MUX", SND_SOC_NOPM, 0, 0, &sb_tx10_mux),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004907
4908 /* Digital Mic Inputs */
4909 SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
4910 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4911 SND_SOC_DAPM_POST_PMD),
4912
4913 SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
4914 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4915 SND_SOC_DAPM_POST_PMD),
4916
4917 SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0,
4918 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4919 SND_SOC_DAPM_POST_PMD),
4920
4921 SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0,
4922 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4923 SND_SOC_DAPM_POST_PMD),
4924
4925 SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0,
4926 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4927 SND_SOC_DAPM_POST_PMD),
4928 SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 0,
4929 tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4930 SND_SOC_DAPM_POST_PMD),
4931
4932 /* Sidetone */
4933 SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux),
4934 SND_SOC_DAPM_PGA("IIR1", TABLA_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0),
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08004935
4936 /* AUX PGA */
4937 SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TABLA_A_AUX_L_EN, 7, 0,
4938 tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
4939 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
4940 SND_SOC_DAPM_POST_PMD),
4941
4942 SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TABLA_A_AUX_R_EN, 7, 0,
4943 tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
4944 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
4945 SND_SOC_DAPM_POST_PMD),
4946
4947 /* Lineout, ear and HPH PA Mixers */
4948 SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0,
4949 hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)),
4950
4951 SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0,
4952 hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)),
4953
4954 SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0,
4955 lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)),
4956
4957 SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0,
4958 lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)),
4959
4960 SND_SOC_DAPM_MIXER("LINEOUT3_PA_MIXER", SND_SOC_NOPM, 0, 0,
4961 lineout3_pa_mix, ARRAY_SIZE(lineout3_pa_mix)),
4962
4963 SND_SOC_DAPM_MIXER("LINEOUT4_PA_MIXER", SND_SOC_NOPM, 0, 0,
4964 lineout4_pa_mix, ARRAY_SIZE(lineout4_pa_mix)),
4965
4966 SND_SOC_DAPM_MIXER("LINEOUT5_PA_MIXER", SND_SOC_NOPM, 0, 0,
4967 lineout5_pa_mix, ARRAY_SIZE(lineout5_pa_mix)),
4968
4969 SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0,
4970 ear_pa_mix, ARRAY_SIZE(ear_pa_mix)),
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08004971};
4972
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004973static short tabla_codec_read_sta_result(struct snd_soc_codec *codec)
Bradley Rubincb1e2732011-06-23 16:49:20 -07004974{
4975 u8 bias_msb, bias_lsb;
4976 short bias_value;
4977
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004978 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B3_STATUS);
4979 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B2_STATUS);
4980 bias_value = (bias_msb << 8) | bias_lsb;
4981 return bias_value;
4982}
4983
4984static short tabla_codec_read_dce_result(struct snd_soc_codec *codec)
4985{
4986 u8 bias_msb, bias_lsb;
4987 short bias_value;
4988
4989 bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B5_STATUS);
4990 bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B4_STATUS);
4991 bias_value = (bias_msb << 8) | bias_lsb;
4992 return bias_value;
4993}
4994
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004995static void tabla_turn_onoff_rel_detection(struct snd_soc_codec *codec, bool on)
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07004996{
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07004997 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, on << 1);
4998}
4999
5000static short __tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce,
5001 bool override_bypass, bool noreldetection)
5002{
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005003 short bias_value;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005004 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
5005
5006 wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
5007 if (noreldetection)
5008 tabla_turn_onoff_rel_detection(codec, false);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005009
Joonwoo Park925914c2012-01-05 13:35:18 -08005010 /* Turn on the override */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005011 if (!override_bypass)
5012 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x4, 0x4);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005013 if (dce) {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005014 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5015 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
5016 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
Joonwoo Park433149a2012-01-11 09:53:54 -08005017 usleep_range(tabla->mbhc_data.t_sta_dce,
5018 tabla->mbhc_data.t_sta_dce);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005019 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4);
Joonwoo Park0976d012011-12-22 11:48:18 -08005020 usleep_range(tabla->mbhc_data.t_dce,
5021 tabla->mbhc_data.t_dce);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005022 bias_value = tabla_codec_read_dce_result(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005023 } else {
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005024 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005025 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
5026 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0);
Joonwoo Park433149a2012-01-11 09:53:54 -08005027 usleep_range(tabla->mbhc_data.t_sta_dce,
5028 tabla->mbhc_data.t_sta_dce);
Joonwoo Park0976d012011-12-22 11:48:18 -08005029 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2);
5030 usleep_range(tabla->mbhc_data.t_sta,
5031 tabla->mbhc_data.t_sta);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005032 bias_value = tabla_codec_read_sta_result(codec);
5033 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5034 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005035 }
Joonwoo Park925914c2012-01-05 13:35:18 -08005036 /* Turn off the override after measuring mic voltage */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005037 if (!override_bypass)
5038 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00);
5039
5040 if (noreldetection)
5041 tabla_turn_onoff_rel_detection(codec, true);
5042 wcd9xxx_enable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005043
Bradley Rubincb1e2732011-06-23 16:49:20 -07005044 return bias_value;
5045}
5046
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005047static short tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce,
5048 bool norel)
5049{
5050 return __tabla_codec_sta_dce(codec, dce, false, norel);
5051}
5052
5053/* called only from interrupt which is under codec_resource_lock acquisition */
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07005054static short tabla_codec_setup_hs_polling(struct snd_soc_codec *codec)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005055{
5056 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07005057 short bias_value;
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08005058 u8 cfilt_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005059
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005060 pr_debug("%s: enter, mclk_enabled %d\n", __func__, tabla->mclk_enabled);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005061 if (!tabla->mbhc_cfg.calibration) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005062 pr_err("Error, no tabla calibration\n");
Bradley Rubincb1e2732011-06-23 16:49:20 -07005063 return -ENODEV;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005064 }
5065
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07005066 if (!tabla->mclk_enabled) {
Joonwoo Park8a6bccc2012-05-03 15:13:13 -07005067 tabla_codec_disable_clock_block(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005068 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_MBHC_MODE);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07005069 tabla_enable_rx_bias(codec, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005070 tabla_codec_enable_clock_block(codec, 1);
5071 }
5072
5073 snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x01);
5074
Bhalchandra Gajare19d9c132011-11-18 14:57:08 -08005075 /* Make sure CFILT is in fast mode, save current mode */
Joonwoo Parkf4267c22012-01-10 13:25:24 -08005076 cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl);
5077 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x70, 0x00);
Patrick Lai3043fba2011-08-01 14:15:57 -07005078
Joonwoo Parkf4267c22012-01-10 13:25:24 -08005079 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x1F, 0x16);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005080
5081 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005082 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005083
5084 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x80);
5085 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x1F, 0x1C);
5086 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x40, 0x40);
5087
5088 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005089 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5090 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x00);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005091
Joonwoo Park925914c2012-01-05 13:35:18 -08005092 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x2, 0x2);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005093 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8);
5094
Bradley Rubincb1e2732011-06-23 16:49:20 -07005095 tabla_codec_calibrate_hs_polling(codec);
5096
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005097 /* don't flip override */
5098 bias_value = __tabla_codec_sta_dce(codec, 1, true, true);
Joonwoo Park0976d012011-12-22 11:48:18 -08005099 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40,
5100 cfilt_mode);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005101 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005102
Bhalchandra Gajare343cbb02011-09-07 18:58:19 -07005103 return bias_value;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005104}
5105
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005106static int tabla_cancel_btn_work(struct tabla_priv *tabla)
5107{
5108 int r = 0;
5109 struct wcd9xxx *core = dev_get_drvdata(tabla->codec->dev->parent);
5110
5111 if (cancel_delayed_work_sync(&tabla->mbhc_btn_dwork)) {
5112 /* if scheduled mbhc_btn_dwork is canceled from here,
5113 * we have to unlock from here instead btn_work */
5114 wcd9xxx_unlock_sleep(core);
5115 r = 1;
5116 }
5117 return r;
5118}
5119
5120/* called under codec_resource_lock acquisition */
5121void tabla_set_and_turnoff_hph_padac(struct snd_soc_codec *codec)
Joonwoo Park03324832012-03-19 19:36:16 -07005122{
5123 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005124 u8 wg_time;
5125
5126 wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ;
5127 wg_time += 1;
Joonwoo Park03324832012-03-19 19:36:16 -07005128
5129 /* If headphone PA is on, check if userspace receives
5130 * removal event to sync-up PA's state */
5131 if (tabla_is_hph_pa_on(codec)) {
5132 pr_debug("%s PA is on, setting PA_OFF_ACK\n", __func__);
5133 set_bit(TABLA_HPHL_PA_OFF_ACK, &tabla->hph_pa_dac_state);
5134 set_bit(TABLA_HPHR_PA_OFF_ACK, &tabla->hph_pa_dac_state);
5135 } else {
5136 pr_debug("%s PA is off\n", __func__);
5137 }
5138
5139 if (tabla_is_hph_dac_on(codec, 1))
5140 set_bit(TABLA_HPHL_DAC_OFF_ACK, &tabla->hph_pa_dac_state);
5141 if (tabla_is_hph_dac_on(codec, 0))
5142 set_bit(TABLA_HPHR_DAC_OFF_ACK, &tabla->hph_pa_dac_state);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005143
5144 snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00);
5145 snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_DAC_CTL,
5146 0xC0, 0x00);
5147 snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_DAC_CTL,
5148 0xC0, 0x00);
5149 usleep_range(wg_time * 1000, wg_time * 1000);
5150}
5151
5152static void tabla_clr_and_turnon_hph_padac(struct tabla_priv *tabla)
5153{
5154 bool pa_turned_on = false;
5155 struct snd_soc_codec *codec = tabla->codec;
5156 u8 wg_time;
5157
5158 wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ;
5159 wg_time += 1;
5160
5161 if (test_and_clear_bit(TABLA_HPHR_DAC_OFF_ACK,
5162 &tabla->hph_pa_dac_state)) {
5163 pr_debug("%s: HPHR clear flag and enable DAC\n", __func__);
5164 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_R_DAC_CTL,
5165 0xC0, 0xC0);
5166 }
5167 if (test_and_clear_bit(TABLA_HPHL_DAC_OFF_ACK,
5168 &tabla->hph_pa_dac_state)) {
5169 pr_debug("%s: HPHL clear flag and enable DAC\n", __func__);
5170 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_L_DAC_CTL,
5171 0xC0, 0xC0);
5172 }
5173
5174 if (test_and_clear_bit(TABLA_HPHR_PA_OFF_ACK,
5175 &tabla->hph_pa_dac_state)) {
5176 pr_debug("%s: HPHR clear flag and enable PA\n", __func__);
5177 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x10,
5178 1 << 4);
5179 pa_turned_on = true;
5180 }
5181 if (test_and_clear_bit(TABLA_HPHL_PA_OFF_ACK,
5182 &tabla->hph_pa_dac_state)) {
5183 pr_debug("%s: HPHL clear flag and enable PA\n", __func__);
5184 snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x20,
5185 1 << 5);
5186 pa_turned_on = true;
5187 }
5188
5189 if (pa_turned_on) {
5190 pr_debug("%s: PA was turned off by MBHC and not by DAPM\n",
5191 __func__);
5192 usleep_range(wg_time * 1000, wg_time * 1000);
5193 }
5194}
5195
5196/* called under codec_resource_lock acquisition */
5197static void tabla_codec_report_plug(struct snd_soc_codec *codec, int insertion,
5198 enum snd_jack_types jack_type)
5199{
5200 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
5201
5202 if (!insertion) {
5203 /* Report removal */
5204 tabla->hph_status &= ~jack_type;
5205 if (tabla->mbhc_cfg.headset_jack) {
5206 /* cancel possibly scheduled btn work and
5207 * report release if we reported button press */
5208 if (tabla_cancel_btn_work(tabla)) {
5209 pr_debug("%s: button press is canceled\n",
5210 __func__);
5211 } else if (tabla->buttons_pressed) {
5212 pr_debug("%s: Reporting release for reported "
5213 "button press %d\n", __func__,
5214 jack_type);
5215 tabla_snd_soc_jack_report(tabla,
5216 tabla->mbhc_cfg.button_jack, 0,
5217 tabla->buttons_pressed);
5218 tabla->buttons_pressed &=
5219 ~TABLA_JACK_BUTTON_MASK;
5220 }
Joonwoo Park2cc13f02012-05-09 12:44:25 -07005221 pr_debug("%s: Reporting removal %d(%x)\n", __func__,
5222 jack_type, tabla->hph_status);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005223 tabla_snd_soc_jack_report(tabla,
5224 tabla->mbhc_cfg.headset_jack,
5225 tabla->hph_status,
5226 TABLA_JACK_MASK);
5227 }
5228 tabla_set_and_turnoff_hph_padac(codec);
5229 hphocp_off_report(tabla, SND_JACK_OC_HPHR,
5230 TABLA_IRQ_HPH_PA_OCPR_FAULT);
5231 hphocp_off_report(tabla, SND_JACK_OC_HPHL,
5232 TABLA_IRQ_HPH_PA_OCPL_FAULT);
5233 tabla->current_plug = PLUG_TYPE_NONE;
5234 tabla->mbhc_polling_active = false;
5235 } else {
5236 /* Report insertion */
5237 tabla->hph_status |= jack_type;
5238
5239 if (jack_type == SND_JACK_HEADPHONE)
5240 tabla->current_plug = PLUG_TYPE_HEADPHONE;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07005241 else if (jack_type == SND_JACK_UNSUPPORTED)
5242 tabla->current_plug = PLUG_TYPE_GND_MIC_SWAP;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005243 else if (jack_type == SND_JACK_HEADSET) {
5244 tabla->mbhc_polling_active = true;
5245 tabla->current_plug = PLUG_TYPE_HEADSET;
5246 }
5247 if (tabla->mbhc_cfg.headset_jack) {
Joonwoo Park2cc13f02012-05-09 12:44:25 -07005248 pr_debug("%s: Reporting insertion %d(%x)\n", __func__,
5249 jack_type, tabla->hph_status);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005250 tabla_snd_soc_jack_report(tabla,
5251 tabla->mbhc_cfg.headset_jack,
5252 tabla->hph_status,
5253 TABLA_JACK_MASK);
5254 }
5255 tabla_clr_and_turnon_hph_padac(tabla);
5256 }
Joonwoo Park03324832012-03-19 19:36:16 -07005257}
5258
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005259static int tabla_codec_enable_hs_detect(struct snd_soc_codec *codec,
Joonwoo Park03324832012-03-19 19:36:16 -07005260 int insertion, int trigger,
5261 bool padac_off)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005262{
5263 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005264 int central_bias_enabled = 0;
Joonwoo Park0976d012011-12-22 11:48:18 -08005265 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005266 TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08005267 const struct tabla_mbhc_plug_detect_cfg *plug_det =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005268 TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005269
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005270 if (!tabla->mbhc_cfg.calibration) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005271 pr_err("Error, no tabla calibration\n");
5272 return -EINVAL;
5273 }
5274
5275 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0);
5276
Joonwoo Park03324832012-03-19 19:36:16 -07005277 /* Make sure mic bias and Mic line schmitt trigger
5278 * are turned OFF
5279 */
5280 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01);
5281 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
5282
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005283 if (insertion) {
Joonwoo Park03324832012-03-19 19:36:16 -07005284 tabla_codec_switch_micbias(codec, 0);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005285
Joonwoo Park03324832012-03-19 19:36:16 -07005286 /* DAPM can manipulate PA/DAC bits concurrently */
5287 if (padac_off == true) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005288 tabla_set_and_turnoff_hph_padac(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07005289 }
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005290
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005291 if (trigger & MBHC_USE_HPHL_TRIGGER) {
Joonwoo Park03324832012-03-19 19:36:16 -07005292 /* Enable HPH Schmitt Trigger */
5293 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x11,
5294 0x11);
5295 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x0C,
5296 plug_det->hph_current << 2);
5297 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x02,
5298 0x02);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005299 }
5300 if (trigger & MBHC_USE_MB_TRIGGER) {
Joonwoo Park03324832012-03-19 19:36:16 -07005301 /* enable the mic line schmitt trigger */
5302 snd_soc_update_bits(codec,
5303 tabla->mbhc_bias_regs.mbhc_reg,
5304 0x60, plug_det->mic_current << 5);
5305 snd_soc_update_bits(codec,
5306 tabla->mbhc_bias_regs.mbhc_reg,
5307 0x80, 0x80);
5308 usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid);
5309 snd_soc_update_bits(codec,
5310 tabla->mbhc_bias_regs.ctl_reg, 0x01,
5311 0x00);
5312 snd_soc_update_bits(codec,
5313 tabla->mbhc_bias_regs.mbhc_reg,
5314 0x10, 0x10);
5315 }
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005316
5317 /* setup for insetion detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005318 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005319 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07005320 pr_debug("setup for removal detection\n");
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005321 /* Make sure the HPH schmitt trigger is OFF */
5322 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x12, 0x00);
5323
5324 /* enable the mic line schmitt trigger */
Joonwoo Park03324832012-03-19 19:36:16 -07005325 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg,
5326 0x01, 0x00);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005327 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x60,
Joonwoo Park0976d012011-12-22 11:48:18 -08005328 plug_det->mic_current << 5);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005329 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
5330 0x80, 0x80);
Joonwoo Park0976d012011-12-22 11:48:18 -08005331 usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005332 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg,
5333 0x10, 0x10);
5334
5335 /* Setup for low power removal detection */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005336 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0x2);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07005337 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005338
5339 if (snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x4) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005340 /* called called by interrupt */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005341 if (!(tabla->clock_active)) {
5342 tabla_codec_enable_config_mode(codec, 1);
5343 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07005344 0x06, 0);
Joonwoo Park0976d012011-12-22 11:48:18 -08005345 usleep_range(generic->t_shutdown_plug_rem,
5346 generic->t_shutdown_plug_rem);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005347 tabla_codec_enable_config_mode(codec, 0);
5348 } else
5349 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07005350 0x06, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005351 }
5352
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07005353 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.int_rbias, 0x80, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005354
5355 /* If central bandgap disabled */
5356 if (!(snd_soc_read(codec, TABLA_A_PIN_CTL_OE1) & 1)) {
5357 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x3, 0x3);
Joonwoo Park0976d012011-12-22 11:48:18 -08005358 usleep_range(generic->t_bg_fast_settle,
5359 generic->t_bg_fast_settle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005360 central_bias_enabled = 1;
5361 }
5362
5363 /* If LDO_H disabled */
5364 if (snd_soc_read(codec, TABLA_A_PIN_CTL_OE0) & 0x80) {
5365 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x10, 0);
5366 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0x80);
Joonwoo Park0976d012011-12-22 11:48:18 -08005367 usleep_range(generic->t_ldoh, generic->t_ldoh);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005368 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0);
5369
5370 if (central_bias_enabled)
5371 snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x1, 0);
5372 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005373
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08005374 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x3,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005375 tabla->mbhc_cfg.micbias);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005376
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305377 wcd9xxx_enable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005378 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0x1);
5379 return 0;
5380}
5381
Joonwoo Park0976d012011-12-22 11:48:18 -08005382static u16 tabla_codec_v_sta_dce(struct snd_soc_codec *codec, bool dce,
5383 s16 vin_mv)
5384{
Joonwoo Park0976d012011-12-22 11:48:18 -08005385 struct tabla_priv *tabla;
Joonwoo Park03324832012-03-19 19:36:16 -07005386 s16 diff, zero;
Joonwoo Park0976d012011-12-22 11:48:18 -08005387 u32 mb_mv, in;
Joonwoo Park03324832012-03-19 19:36:16 -07005388 u16 value;
Joonwoo Park0976d012011-12-22 11:48:18 -08005389
5390 tabla = snd_soc_codec_get_drvdata(codec);
5391 mb_mv = tabla->mbhc_data.micb_mv;
5392
5393 if (mb_mv == 0) {
5394 pr_err("%s: Mic Bias voltage is set to zero\n", __func__);
5395 return -EINVAL;
5396 }
5397
5398 if (dce) {
Joonwoo Park03324832012-03-19 19:36:16 -07005399 diff = (tabla->mbhc_data.dce_mb) - (tabla->mbhc_data.dce_z);
5400 zero = (tabla->mbhc_data.dce_z);
Joonwoo Park0976d012011-12-22 11:48:18 -08005401 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07005402 diff = (tabla->mbhc_data.sta_mb) - (tabla->mbhc_data.sta_z);
5403 zero = (tabla->mbhc_data.sta_z);
Joonwoo Park0976d012011-12-22 11:48:18 -08005404 }
5405 in = (u32) diff * vin_mv;
5406
Joonwoo Park03324832012-03-19 19:36:16 -07005407 value = (u16) (in / mb_mv) + zero;
5408 return value;
Joonwoo Park0976d012011-12-22 11:48:18 -08005409}
5410
5411static s32 tabla_codec_sta_dce_v(struct snd_soc_codec *codec, s8 dce,
5412 u16 bias_value)
5413{
5414 struct tabla_priv *tabla;
Joonwoo Park03324832012-03-19 19:36:16 -07005415 s16 value, z, mb;
Joonwoo Park0976d012011-12-22 11:48:18 -08005416 s32 mv;
5417
5418 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07005419 value = bias_value;
Joonwoo Park0976d012011-12-22 11:48:18 -08005420 if (dce) {
Joonwoo Park03324832012-03-19 19:36:16 -07005421 z = (tabla->mbhc_data.dce_z);
5422 mb = (tabla->mbhc_data.dce_mb);
5423 mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z);
Joonwoo Park0976d012011-12-22 11:48:18 -08005424 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07005425 z = (tabla->mbhc_data.sta_z);
5426 mb = (tabla->mbhc_data.sta_mb);
5427 mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z);
Joonwoo Park0976d012011-12-22 11:48:18 -08005428 }
5429
5430 return mv;
5431}
5432
Joonwoo Park03324832012-03-19 19:36:16 -07005433static void btn_lpress_fn(struct work_struct *work)
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005434{
5435 struct delayed_work *delayed_work;
5436 struct tabla_priv *tabla;
Joonwoo Park0976d012011-12-22 11:48:18 -08005437 short bias_value;
5438 int dce_mv, sta_mv;
Joonwoo Park03324832012-03-19 19:36:16 -07005439 struct wcd9xxx *core;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005440
5441 pr_debug("%s:\n", __func__);
5442
5443 delayed_work = to_delayed_work(work);
Joonwoo Park03324832012-03-19 19:36:16 -07005444 tabla = container_of(delayed_work, struct tabla_priv, mbhc_btn_dwork);
Joonwoo Park816b8e62012-01-23 16:03:21 -08005445 core = dev_get_drvdata(tabla->codec->dev->parent);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005446
5447 if (tabla) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005448 if (tabla->mbhc_cfg.button_jack) {
Joonwoo Park0976d012011-12-22 11:48:18 -08005449 bias_value = tabla_codec_read_sta_result(tabla->codec);
5450 sta_mv = tabla_codec_sta_dce_v(tabla->codec, 0,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305451 bias_value);
Joonwoo Park0976d012011-12-22 11:48:18 -08005452 bias_value = tabla_codec_read_dce_result(tabla->codec);
5453 dce_mv = tabla_codec_sta_dce_v(tabla->codec, 1,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305454 bias_value);
Joonwoo Park0976d012011-12-22 11:48:18 -08005455 pr_debug("%s: Reporting long button press event"
5456 " STA: %d, DCE: %d\n", __func__,
5457 sta_mv, dce_mv);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005458 tabla_snd_soc_jack_report(tabla,
5459 tabla->mbhc_cfg.button_jack,
Joonwoo Park03324832012-03-19 19:36:16 -07005460 tabla->buttons_pressed,
5461 tabla->buttons_pressed);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005462 }
5463 } else {
5464 pr_err("%s: Bad tabla private data\n", __func__);
5465 }
5466
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005467 pr_debug("%s: leave\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07005468 wcd9xxx_unlock_sleep(core);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005469}
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07005470
Joonwoo Parke067b232012-06-14 13:11:30 -07005471static u16 tabla_get_cfilt_reg(struct snd_soc_codec *codec, u8 cfilt)
5472{
5473 u16 reg;
5474
5475 switch (cfilt) {
5476 case TABLA_CFILT1_SEL:
5477 reg = TABLA_A_MICB_CFILT_1_CTL;
5478 break;
5479 case TABLA_CFILT2_SEL:
5480 reg = TABLA_A_MICB_CFILT_2_CTL;
5481 break;
5482 case TABLA_CFILT3_SEL:
5483 reg = TABLA_A_MICB_CFILT_3_CTL;
5484 break;
5485 default:
5486 BUG();
5487 }
5488 return reg;
5489}
5490
Joonwoo Park0976d012011-12-22 11:48:18 -08005491void tabla_mbhc_cal(struct snd_soc_codec *codec)
5492{
5493 struct tabla_priv *tabla;
5494 struct tabla_mbhc_btn_detect_cfg *btn_det;
Joonwoo Parke067b232012-06-14 13:11:30 -07005495 u8 cfilt_mode, micbias2_cfilt_mode, bg_mode;
Joonwoo Park0976d012011-12-22 11:48:18 -08005496 u8 ncic, nmeas, navg;
5497 u32 mclk_rate;
5498 u32 dce_wait, sta_wait;
5499 u8 *n_cic;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005500 void *calibration;
Joonwoo Parke067b232012-06-14 13:11:30 -07005501 u16 bias2_ctl;
Joonwoo Park0976d012011-12-22 11:48:18 -08005502
5503 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005504 calibration = tabla->mbhc_cfg.calibration;
5505
5506 wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
5507 tabla_turn_onoff_rel_detection(codec, false);
Joonwoo Park0976d012011-12-22 11:48:18 -08005508
5509 /* First compute the DCE / STA wait times
5510 * depending on tunable parameters.
5511 * The value is computed in microseconds
5512 */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005513 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08005514 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
Joonwoo Park107edf02012-01-11 11:42:24 -08005515 ncic = n_cic[tabla_codec_mclk_index(tabla)];
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005516 nmeas = TABLA_MBHC_CAL_BTN_DET_PTR(calibration)->n_meas;
5517 navg = TABLA_MBHC_CAL_GENERAL_PTR(calibration)->mbhc_navg;
5518 mclk_rate = tabla->mbhc_cfg.mclk_rate;
Joonwoo Park433149a2012-01-11 09:53:54 -08005519 dce_wait = (1000 * 512 * ncic * (nmeas + 1)) / (mclk_rate / 1000);
5520 sta_wait = (1000 * 128 * (navg + 1)) / (mclk_rate / 1000);
Joonwoo Park0976d012011-12-22 11:48:18 -08005521
5522 tabla->mbhc_data.t_dce = dce_wait;
5523 tabla->mbhc_data.t_sta = sta_wait;
5524
5525 /* LDOH and CFILT are already configured during pdata handling.
5526 * Only need to make sure CFILT and bandgap are in Fast mode.
5527 * Need to restore defaults once calculation is done.
5528 */
5529 cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl);
Joonwoo Parke067b232012-06-14 13:11:30 -07005530 micbias2_cfilt_mode =
5531 snd_soc_read(codec, tabla_get_cfilt_reg(codec,
5532 tabla->pdata->micbias.bias2_cfilt_sel));
5533 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40,
5534 TABLA_CFILT_FAST_MODE);
5535 snd_soc_update_bits(codec,
5536 tabla_get_cfilt_reg(codec,
5537 tabla->pdata->micbias.bias2_cfilt_sel),
5538 0x40, TABLA_CFILT_FAST_MODE);
5539
Joonwoo Park0976d012011-12-22 11:48:18 -08005540 bg_mode = snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02,
5541 0x02);
5542
5543 /* Micbias, CFILT, LDOH, MBHC MUX mode settings
5544 * to perform ADC calibration
5545 */
5546 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x60,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005547 tabla->mbhc_cfg.micbias << 5);
Joonwoo Park0976d012011-12-22 11:48:18 -08005548 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
5549 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x60, 0x60);
5550 snd_soc_write(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x78);
5551 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x04);
5552
Joonwoo Parke067b232012-06-14 13:11:30 -07005553 /* MICBIAS2 routing for calibration */
5554 bias2_ctl = snd_soc_read(codec, TABLA_A_MICB_2_CTL);
5555 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, TABLA_MICBIAS2);
5556 snd_soc_write(codec, TABLA_A_MICB_2_CTL,
5557 snd_soc_read(codec, tabla->mbhc_bias_regs.ctl_reg));
5558
Joonwoo Park0976d012011-12-22 11:48:18 -08005559 /* DCE measurement for 0 volts */
5560 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
5561 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
5562 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
Joonwoo Park0976d012011-12-22 11:48:18 -08005563 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81);
5564 usleep_range(100, 100);
5565 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
5566 usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce);
5567 tabla->mbhc_data.dce_z = tabla_codec_read_dce_result(codec);
5568
5569 /* DCE measurment for MB voltage */
5570 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
5571 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
5572 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82);
5573 usleep_range(100, 100);
5574 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04);
5575 usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce);
5576 tabla->mbhc_data.dce_mb = tabla_codec_read_dce_result(codec);
5577
5578 /* Sta measuremnt for 0 volts */
5579 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A);
5580 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
5581 snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02);
Joonwoo Park0976d012011-12-22 11:48:18 -08005582 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81);
5583 usleep_range(100, 100);
5584 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
5585 usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta);
5586 tabla->mbhc_data.sta_z = tabla_codec_read_sta_result(codec);
5587
5588 /* STA Measurement for MB Voltage */
5589 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82);
5590 usleep_range(100, 100);
5591 snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02);
5592 usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta);
5593 tabla->mbhc_data.sta_mb = tabla_codec_read_sta_result(codec);
5594
5595 /* Restore default settings. */
Joonwoo Parke067b232012-06-14 13:11:30 -07005596 snd_soc_write(codec, TABLA_A_MICB_2_CTL, bias2_ctl);
5597 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03,
5598 tabla->mbhc_cfg.micbias);
5599
Joonwoo Park0976d012011-12-22 11:48:18 -08005600 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00);
Joonwoo Parke067b232012-06-14 13:11:30 -07005601 snd_soc_update_bits(codec,
5602 tabla_get_cfilt_reg(codec,
5603 tabla->pdata->micbias.bias2_cfilt_sel), 0x40,
5604 micbias2_cfilt_mode);
Joonwoo Park0976d012011-12-22 11:48:18 -08005605 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40,
5606 cfilt_mode);
5607 snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, bg_mode);
5608
5609 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84);
5610 usleep_range(100, 100);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005611
5612 wcd9xxx_enable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL);
5613 tabla_turn_onoff_rel_detection(codec, true);
Joonwoo Park0976d012011-12-22 11:48:18 -08005614}
5615
5616void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg* btn_det,
5617 const enum tabla_mbhc_btn_det_mem mem)
5618{
5619 void *ret = &btn_det->_v_btn_low;
5620
5621 switch (mem) {
5622 case TABLA_BTN_DET_GAIN:
5623 ret += sizeof(btn_det->_n_cic);
5624 case TABLA_BTN_DET_N_CIC:
5625 ret += sizeof(btn_det->_n_ready);
Joonwoo Parkc0672392012-01-11 11:03:14 -08005626 case TABLA_BTN_DET_N_READY:
Joonwoo Park0976d012011-12-22 11:48:18 -08005627 ret += sizeof(btn_det->_v_btn_high[0]) * btn_det->num_btn;
5628 case TABLA_BTN_DET_V_BTN_HIGH:
5629 ret += sizeof(btn_det->_v_btn_low[0]) * btn_det->num_btn;
5630 case TABLA_BTN_DET_V_BTN_LOW:
5631 /* do nothing */
5632 break;
5633 default:
5634 ret = NULL;
5635 }
5636
5637 return ret;
5638}
5639
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005640static s16 tabla_scale_v_micb_vddio(struct tabla_priv *tabla, int v,
5641 bool tovddio)
5642{
5643 int r;
5644 int vddio_k, mb_k;
5645 vddio_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v,
5646 VDDIO_MICBIAS_MV);
5647 mb_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v,
5648 tabla->mbhc_data.micb_mv);
5649 if (tovddio)
5650 r = v * vddio_k / mb_k;
5651 else
5652 r = v * mb_k / vddio_k;
5653 return r;
5654}
5655
Joonwoo Park0976d012011-12-22 11:48:18 -08005656static void tabla_mbhc_calc_thres(struct snd_soc_codec *codec)
5657{
5658 struct tabla_priv *tabla;
5659 s16 btn_mv = 0, btn_delta_mv;
5660 struct tabla_mbhc_btn_detect_cfg *btn_det;
5661 struct tabla_mbhc_plug_type_cfg *plug_type;
5662 u16 *btn_high;
Joonwoo Parkc0672392012-01-11 11:03:14 -08005663 u8 *n_ready;
Joonwoo Park0976d012011-12-22 11:48:18 -08005664 int i;
5665
5666 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005667 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
5668 plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08005669
Joonwoo Parkc0672392012-01-11 11:03:14 -08005670 n_ready = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_READY);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005671 if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) {
Joonwoo Park03324832012-03-19 19:36:16 -07005672 tabla->mbhc_data.npoll = 4;
Joonwoo Park0976d012011-12-22 11:48:18 -08005673 tabla->mbhc_data.nbounce_wait = 30;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005674 } else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) {
Joonwoo Park0976d012011-12-22 11:48:18 -08005675 tabla->mbhc_data.npoll = 7;
5676 tabla->mbhc_data.nbounce_wait = 23;
Joonwoo Parkc0672392012-01-11 11:03:14 -08005677 }
Joonwoo Park0976d012011-12-22 11:48:18 -08005678
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005679 tabla->mbhc_data.t_sta_dce = ((1000 * 256) /
5680 (tabla->mbhc_cfg.mclk_rate / 1000) *
Joonwoo Parkc0672392012-01-11 11:03:14 -08005681 n_ready[tabla_codec_mclk_index(tabla)]) +
5682 10;
Joonwoo Park0976d012011-12-22 11:48:18 -08005683 tabla->mbhc_data.v_ins_hu =
5684 tabla_codec_v_sta_dce(codec, STA, plug_type->v_hs_max);
5685 tabla->mbhc_data.v_ins_h =
5686 tabla_codec_v_sta_dce(codec, DCE, plug_type->v_hs_max);
5687
Joonwoo Parkcf473b42012-03-29 19:48:16 -07005688 tabla->mbhc_data.v_inval_ins_low = TABLA_MBHC_FAKE_INSERT_LOW;
5689 if (tabla->mbhc_cfg.gpio)
5690 tabla->mbhc_data.v_inval_ins_high =
5691 TABLA_MBHC_FAKE_INSERT_HIGH;
5692 else
5693 tabla->mbhc_data.v_inval_ins_high =
5694 TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO;
5695
5696 if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) {
5697 tabla->mbhc_data.adj_v_hs_max =
5698 tabla_scale_v_micb_vddio(tabla, plug_type->v_hs_max, true);
5699 tabla->mbhc_data.adj_v_ins_hu =
5700 tabla_codec_v_sta_dce(codec, STA,
5701 tabla->mbhc_data.adj_v_hs_max);
5702 tabla->mbhc_data.adj_v_ins_h =
5703 tabla_codec_v_sta_dce(codec, DCE,
5704 tabla->mbhc_data.adj_v_hs_max);
5705 tabla->mbhc_data.v_inval_ins_low =
5706 tabla_scale_v_micb_vddio(tabla,
5707 tabla->mbhc_data.v_inval_ins_low,
5708 false);
5709 tabla->mbhc_data.v_inval_ins_high =
5710 tabla_scale_v_micb_vddio(tabla,
5711 tabla->mbhc_data.v_inval_ins_high,
5712 false);
5713 }
5714
Joonwoo Park0976d012011-12-22 11:48:18 -08005715 btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_HIGH);
5716 for (i = 0; i < btn_det->num_btn; i++)
5717 btn_mv = btn_high[i] > btn_mv ? btn_high[i] : btn_mv;
5718
5719 tabla->mbhc_data.v_b1_h = tabla_codec_v_sta_dce(codec, DCE, btn_mv);
5720 btn_delta_mv = btn_mv + btn_det->v_btn_press_delta_sta;
Joonwoo Park0976d012011-12-22 11:48:18 -08005721 tabla->mbhc_data.v_b1_hu =
5722 tabla_codec_v_sta_dce(codec, STA, btn_delta_mv);
5723
5724 btn_delta_mv = btn_mv + btn_det->v_btn_press_delta_cic;
5725
5726 tabla->mbhc_data.v_b1_huc =
5727 tabla_codec_v_sta_dce(codec, DCE, btn_delta_mv);
5728
5729 tabla->mbhc_data.v_brh = tabla->mbhc_data.v_b1_h;
Joonwoo Park03324832012-03-19 19:36:16 -07005730 tabla->mbhc_data.v_brl = TABLA_MBHC_BUTTON_MIN;
Joonwoo Park0976d012011-12-22 11:48:18 -08005731
5732 tabla->mbhc_data.v_no_mic =
5733 tabla_codec_v_sta_dce(codec, STA, plug_type->v_no_mic);
5734}
5735
5736void tabla_mbhc_init(struct snd_soc_codec *codec)
5737{
5738 struct tabla_priv *tabla;
5739 struct tabla_mbhc_general_cfg *generic;
5740 struct tabla_mbhc_btn_detect_cfg *btn_det;
5741 int n;
Joonwoo Park0976d012011-12-22 11:48:18 -08005742 u8 *n_cic, *gain;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305743 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Joonwoo Park0976d012011-12-22 11:48:18 -08005744
5745 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005746 generic = TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
5747 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park0976d012011-12-22 11:48:18 -08005748
Joonwoo Park0976d012011-12-22 11:48:18 -08005749 for (n = 0; n < 8; n++) {
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08005750 if ((!TABLA_IS_1_X(tabla_core->version)) || n != 7) {
Joonwoo Park0976d012011-12-22 11:48:18 -08005751 snd_soc_update_bits(codec,
5752 TABLA_A_CDC_MBHC_FEATURE_B1_CFG,
5753 0x07, n);
5754 snd_soc_write(codec, TABLA_A_CDC_MBHC_FEATURE_B2_CFG,
5755 btn_det->c[n]);
5756 }
5757 }
5758 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x07,
5759 btn_det->nc);
5760
5761 n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC);
5762 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL, 0xFF,
Joonwoo Park107edf02012-01-11 11:42:24 -08005763 n_cic[tabla_codec_mclk_index(tabla)]);
Joonwoo Park0976d012011-12-22 11:48:18 -08005764
5765 gain = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_GAIN);
Joonwoo Park107edf02012-01-11 11:42:24 -08005766 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x78,
5767 gain[tabla_codec_mclk_index(tabla)] << 3);
Joonwoo Park0976d012011-12-22 11:48:18 -08005768
5769 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x70,
5770 generic->mbhc_nsa << 4);
5771
5772 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x0F,
5773 btn_det->n_meas);
5774
5775 snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B5_CTL, generic->mbhc_navg);
5776
5777 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x80, 0x80);
5778
5779 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x78,
5780 btn_det->mbhc_nsc << 3);
5781
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08005782 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x03,
5783 TABLA_MICBIAS2);
Joonwoo Park0976d012011-12-22 11:48:18 -08005784
5785 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, 0x02);
Joonwoo Park03324832012-03-19 19:36:16 -07005786
5787 snd_soc_update_bits(codec, TABLA_A_MBHC_SCALING_MUX_2, 0xF0, 0xF0);
Joonwoo Parke067b232012-06-14 13:11:30 -07005788
5789 /* override mbhc's micbias */
5790 snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03,
5791 tabla->mbhc_cfg.micbias);
Joonwoo Park0976d012011-12-22 11:48:18 -08005792}
5793
Patrick Lai64b43262011-12-06 17:29:15 -08005794static bool tabla_mbhc_fw_validate(const struct firmware *fw)
5795{
5796 u32 cfg_offset;
5797 struct tabla_mbhc_imped_detect_cfg *imped_cfg;
5798 struct tabla_mbhc_btn_detect_cfg *btn_cfg;
5799
5800 if (fw->size < TABLA_MBHC_CAL_MIN_SIZE)
5801 return false;
5802
5803 /* previous check guarantees that there is enough fw data up
5804 * to num_btn
5805 */
5806 btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(fw->data);
5807 cfg_offset = (u32) ((void *) btn_cfg - (void *) fw->data);
5808 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_BTN_SZ(btn_cfg)))
5809 return false;
5810
5811 /* previous check guarantees that there is enough fw data up
5812 * to start of impedance detection configuration
5813 */
5814 imped_cfg = TABLA_MBHC_CAL_IMPED_DET_PTR(fw->data);
5815 cfg_offset = (u32) ((void *) imped_cfg - (void *) fw->data);
5816
5817 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_MIN_SZ))
5818 return false;
5819
5820 if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_SZ(imped_cfg)))
5821 return false;
5822
5823 return true;
5824}
Joonwoo Park03324832012-03-19 19:36:16 -07005825
Joonwoo Parkfee17432012-04-16 16:33:55 -07005826/* called under codec_resource_lock acquisition */
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005827static int tabla_determine_button(const struct tabla_priv *priv,
Joonwoo Parkfee17432012-04-16 16:33:55 -07005828 const s32 micmv)
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005829{
5830 s16 *v_btn_low, *v_btn_high;
5831 struct tabla_mbhc_btn_detect_cfg *btn_det;
5832 int i, btn = -1;
5833
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005834 btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005835 v_btn_low = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_LOW);
5836 v_btn_high = tabla_mbhc_cal_btn_det_mp(btn_det,
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305837 TABLA_BTN_DET_V_BTN_HIGH);
Joonwoo Parkfee17432012-04-16 16:33:55 -07005838
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005839 for (i = 0; i < btn_det->num_btn; i++) {
Joonwoo Parkfee17432012-04-16 16:33:55 -07005840 if ((v_btn_low[i] <= micmv) && (v_btn_high[i] >= micmv)) {
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005841 btn = i;
5842 break;
5843 }
5844 }
5845
5846 if (btn == -1)
5847 pr_debug("%s: couldn't find button number for mic mv %d\n",
Joonwoo Parkfee17432012-04-16 16:33:55 -07005848 __func__, micmv);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005849
5850 return btn;
5851}
5852
5853static int tabla_get_button_mask(const int btn)
5854{
5855 int mask = 0;
5856 switch (btn) {
5857 case 0:
5858 mask = SND_JACK_BTN_0;
5859 break;
5860 case 1:
5861 mask = SND_JACK_BTN_1;
5862 break;
5863 case 2:
5864 mask = SND_JACK_BTN_2;
5865 break;
5866 case 3:
5867 mask = SND_JACK_BTN_3;
5868 break;
5869 case 4:
5870 mask = SND_JACK_BTN_4;
5871 break;
5872 case 5:
5873 mask = SND_JACK_BTN_5;
5874 break;
5875 case 6:
5876 mask = SND_JACK_BTN_6;
5877 break;
5878 case 7:
5879 mask = SND_JACK_BTN_7;
5880 break;
5881 }
5882 return mask;
5883}
5884
Bradley Rubincb1e2732011-06-23 16:49:20 -07005885static irqreturn_t tabla_dce_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005886{
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005887 int i, mask;
Joonwoo Parkfee17432012-04-16 16:33:55 -07005888 short dce, sta;
5889 s32 mv, mv_s, stamv_s;
5890 bool vddio;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005891 int btn = -1, meas = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005892 struct tabla_priv *priv = data;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005893 const struct tabla_mbhc_btn_detect_cfg *d =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005894 TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005895 short btnmeas[d->n_btn_meas + 1];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005896 struct snd_soc_codec *codec = priv->codec;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05305897 struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent);
Joonwoo Park03324832012-03-19 19:36:16 -07005898 int n_btn_meas = d->n_btn_meas;
5899 u8 mbhc_status = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_STATUS) & 0x3E;
Bradley Rubincb1e2732011-06-23 16:49:20 -07005900
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005901 pr_debug("%s: enter\n", __func__);
Bradley Rubincb1e2732011-06-23 16:49:20 -07005902
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005903 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
5904 if (priv->mbhc_state == MBHC_STATE_POTENTIAL_RECOVERY) {
5905 pr_debug("%s: mbhc is being recovered, skip button press\n",
5906 __func__);
5907 goto done;
5908 }
5909
5910 priv->mbhc_state = MBHC_STATE_POTENTIAL;
5911
5912 if (!priv->mbhc_polling_active) {
5913 pr_warn("%s: mbhc polling is not active, skip button press\n",
5914 __func__);
5915 goto done;
5916 }
Joonwoo Park03324832012-03-19 19:36:16 -07005917
5918 dce = tabla_codec_read_dce_result(codec);
5919 mv = tabla_codec_sta_dce_v(codec, 1, dce);
5920
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005921 /* If GPIO interrupt already kicked in, ignore button press */
5922 if (priv->in_gpio_handler) {
5923 pr_debug("%s: GPIO State Changed, ignore button press\n",
5924 __func__);
5925 btn = -1;
5926 goto done;
5927 }
5928
Joonwoo Parkfee17432012-04-16 16:33:55 -07005929 vddio = (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
5930 priv->mbhc_micbias_switched);
5931 mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv;
5932
Joonwoo Park03324832012-03-19 19:36:16 -07005933 if (mbhc_status != TABLA_MBHC_STATUS_REL_DETECTION) {
5934 if (priv->mbhc_last_resume &&
5935 !time_after(jiffies, priv->mbhc_last_resume + HZ)) {
5936 pr_debug("%s: Button is already released shortly after "
5937 "resume\n", __func__);
5938 n_btn_meas = 0;
5939 } else {
5940 pr_debug("%s: Button is already released without "
5941 "resume", __func__);
5942 sta = tabla_codec_read_sta_result(codec);
Joonwoo Parkfee17432012-04-16 16:33:55 -07005943 stamv_s = tabla_codec_sta_dce_v(codec, 0, sta);
5944 if (vddio)
5945 stamv_s = tabla_scale_v_micb_vddio(priv,
5946 stamv_s,
5947 false);
5948 btn = tabla_determine_button(priv, mv_s);
5949 if (btn != tabla_determine_button(priv, stamv_s))
Joonwoo Park03324832012-03-19 19:36:16 -07005950 btn = -1;
5951 goto done;
5952 }
5953 }
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07005954
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005955 /* determine pressed button */
Joonwoo Parkfee17432012-04-16 16:33:55 -07005956 btnmeas[meas++] = tabla_determine_button(priv, mv_s);
5957 pr_debug("%s: meas %d - DCE %d,%d,%d button %d\n", __func__,
5958 meas - 1, dce, mv, mv_s, btnmeas[meas - 1]);
Joonwoo Park03324832012-03-19 19:36:16 -07005959 if (n_btn_meas == 0)
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005960 btn = btnmeas[0];
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005961 for (; ((d->n_btn_meas) && (meas < (d->n_btn_meas + 1))); meas++) {
Joonwoo Parkfee17432012-04-16 16:33:55 -07005962 dce = tabla_codec_sta_dce(codec, 1, false);
5963 mv = tabla_codec_sta_dce_v(codec, 1, dce);
5964 mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv;
5965
5966 btnmeas[meas] = tabla_determine_button(priv, mv_s);
5967 pr_debug("%s: meas %d - DCE %d,%d,%d button %d\n",
5968 __func__, meas, dce, mv, mv_s, btnmeas[meas]);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005969 /* if large enough measurements are collected,
5970 * start to check if last all n_btn_con measurements were
5971 * in same button low/high range */
5972 if (meas + 1 >= d->n_btn_con) {
5973 for (i = 0; i < d->n_btn_con; i++)
5974 if ((btnmeas[meas] < 0) ||
5975 (btnmeas[meas] != btnmeas[meas - i]))
5976 break;
5977 if (i == d->n_btn_con) {
5978 /* button pressed */
5979 btn = btnmeas[meas];
5980 break;
Joonwoo Park03324832012-03-19 19:36:16 -07005981 } else if ((n_btn_meas - meas) < (d->n_btn_con - 1)) {
5982 /* if left measurements are less than n_btn_con,
5983 * it's impossible to find button number */
5984 break;
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005985 }
5986 }
Joonwoo Park8b1f0982011-12-08 17:12:45 -08005987 }
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07005988
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005989 if (btn >= 0) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07005990 if (priv->in_gpio_handler) {
5991 pr_debug("%s: GPIO already triggered, ignore button "
5992 "press\n", __func__);
5993 goto done;
5994 }
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08005995 mask = tabla_get_button_mask(btn);
5996 priv->buttons_pressed |= mask;
Joonwoo Park03324832012-03-19 19:36:16 -07005997 wcd9xxx_lock_sleep(core);
5998 if (schedule_delayed_work(&priv->mbhc_btn_dwork,
5999 msecs_to_jiffies(400)) == 0) {
6000 WARN(1, "Button pressed twice without release"
6001 "event\n");
6002 wcd9xxx_unlock_sleep(core);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006003 }
Joonwoo Park816b8e62012-01-23 16:03:21 -08006004 } else {
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006005 pr_debug("%s: bogus button press, too short press?\n",
6006 __func__);
Joonwoo Park816b8e62012-01-23 16:03:21 -08006007 }
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006008
Joonwoo Park03324832012-03-19 19:36:16 -07006009 done:
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006010 pr_debug("%s: leave\n", __func__);
6011 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006012 return IRQ_HANDLED;
6013}
6014
Joonwoo Park03324832012-03-19 19:36:16 -07006015static int tabla_is_fake_press(struct tabla_priv *priv)
6016{
6017 int i;
6018 int r = 0;
6019 struct snd_soc_codec *codec = priv->codec;
6020 const int dces = MBHC_NUM_DCE_PLUG_DETECT;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006021 s16 mb_v, v_ins_hu, v_ins_h;
6022
6023 v_ins_hu = tabla_get_current_v_ins(priv, true);
6024 v_ins_h = tabla_get_current_v_ins(priv, false);
Joonwoo Park03324832012-03-19 19:36:16 -07006025
6026 for (i = 0; i < dces; i++) {
6027 usleep_range(10000, 10000);
6028 if (i == 0) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006029 mb_v = tabla_codec_sta_dce(codec, 0, true);
Joonwoo Park03324832012-03-19 19:36:16 -07006030 pr_debug("%s: STA[0]: %d,%d\n", __func__, mb_v,
6031 tabla_codec_sta_dce_v(codec, 0, mb_v));
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006032 if (mb_v < (s16)priv->mbhc_data.v_b1_hu ||
6033 mb_v > v_ins_hu) {
Joonwoo Park03324832012-03-19 19:36:16 -07006034 r = 1;
6035 break;
6036 }
6037 } else {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006038 mb_v = tabla_codec_sta_dce(codec, 1, true);
Joonwoo Park03324832012-03-19 19:36:16 -07006039 pr_debug("%s: DCE[%d]: %d,%d\n", __func__, i, mb_v,
6040 tabla_codec_sta_dce_v(codec, 1, mb_v));
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006041 if (mb_v < (s16)priv->mbhc_data.v_b1_h ||
6042 mb_v > v_ins_h) {
Joonwoo Park03324832012-03-19 19:36:16 -07006043 r = 1;
6044 break;
6045 }
6046 }
6047 }
6048
6049 return r;
6050}
6051
Bradley Rubincb1e2732011-06-23 16:49:20 -07006052static irqreturn_t tabla_release_handler(int irq, void *data)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006053{
Joonwoo Parke5d3aa92012-01-11 14:47:15 -08006054 int ret;
Joonwoo Park816b8e62012-01-23 16:03:21 -08006055 struct tabla_priv *priv = data;
6056 struct snd_soc_codec *codec = priv->codec;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006057
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006058 pr_debug("%s: enter\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07006059
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006060 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
6061 priv->mbhc_state = MBHC_STATE_RELEASE;
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006062
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006063 tabla_codec_drive_v_to_micbias(codec, 10000);
6064
Joonwoo Park03324832012-03-19 19:36:16 -07006065 if (priv->buttons_pressed & TABLA_JACK_BUTTON_MASK) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006066 ret = tabla_cancel_btn_work(priv);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006067 if (ret == 0) {
Joonwoo Park03324832012-03-19 19:36:16 -07006068 pr_debug("%s: Reporting long button release event\n",
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006069 __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006070 if (priv->mbhc_cfg.button_jack)
Joonwoo Park8b1f0982011-12-08 17:12:45 -08006071 tabla_snd_soc_jack_report(priv,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006072 priv->mbhc_cfg.button_jack, 0,
6073 priv->buttons_pressed);
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006074 } else {
Joonwoo Park03324832012-03-19 19:36:16 -07006075 if (tabla_is_fake_press(priv)) {
6076 pr_debug("%s: Fake button press interrupt\n",
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006077 __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006078 } else if (priv->mbhc_cfg.button_jack) {
6079 if (priv->in_gpio_handler) {
6080 pr_debug("%s: GPIO kicked in, ignore\n",
6081 __func__);
6082 } else {
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006083 pr_debug("%s: Reporting short button "
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006084 "press and release\n",
6085 __func__);
6086 tabla_snd_soc_jack_report(priv,
6087 priv->mbhc_cfg.button_jack,
6088 priv->buttons_pressed,
6089 priv->buttons_pressed);
6090 tabla_snd_soc_jack_report(priv,
6091 priv->mbhc_cfg.button_jack, 0,
6092 priv->buttons_pressed);
6093 }
Bhalchandra Gajare0a792b12011-09-06 16:36:58 -07006094 }
6095 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006096
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006097 priv->buttons_pressed &= ~TABLA_JACK_BUTTON_MASK;
6098 }
6099
Joonwoo Park03324832012-03-19 19:36:16 -07006100 tabla_codec_calibrate_hs_polling(codec);
6101
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006102 if (priv->mbhc_cfg.gpio)
6103 msleep(TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS);
Joonwoo Park03324832012-03-19 19:36:16 -07006104
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006105 tabla_codec_start_hs_polling(codec);
6106
6107 pr_debug("%s: leave\n", __func__);
6108 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006109 return IRQ_HANDLED;
6110}
6111
Bradley Rubincb1e2732011-06-23 16:49:20 -07006112static void tabla_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec)
6113{
6114 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park0976d012011-12-22 11:48:18 -08006115 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006116 TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006117
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07006118 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07006119 tabla_codec_enable_config_mode(codec, 1);
6120
6121 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2);
6122 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x6, 0x0);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006123
Joonwoo Park0976d012011-12-22 11:48:18 -08006124 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00);
6125
6126 usleep_range(generic->t_shutdown_plug_rem,
6127 generic->t_shutdown_plug_rem);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006128
6129 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0xA, 0x8);
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07006130 if (!tabla->mclk_enabled && !tabla->mbhc_polling_active)
Bradley Rubincb1e2732011-06-23 16:49:20 -07006131 tabla_codec_enable_config_mode(codec, 0);
6132
6133 snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x00);
6134}
6135
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006136static void tabla_codec_cleanup_hs_polling(struct snd_soc_codec *codec)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006137{
6138 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006139
6140 tabla_codec_shutdown_hs_removal_detect(codec);
6141
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07006142 if (!tabla->mclk_enabled) {
Asish Bhattacharya486745a2012-01-20 06:41:53 +05306143 tabla_codec_disable_clock_block(codec);
6144 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006145 }
6146
6147 tabla->mbhc_polling_active = false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006148 tabla->mbhc_state = MBHC_STATE_NONE;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006149}
6150
Patrick Lai49efeac2011-11-03 11:01:12 -07006151static irqreturn_t tabla_hphl_ocp_irq(int irq, void *data)
6152{
6153 struct tabla_priv *tabla = data;
6154 struct snd_soc_codec *codec;
6155
6156 pr_info("%s: received HPHL OCP irq\n", __func__);
6157
6158 if (tabla) {
6159 codec = tabla->codec;
Patrick Laic7cae882011-11-18 11:52:49 -08006160 if (tabla->hphlocp_cnt++ < TABLA_OCP_ATTEMPT) {
6161 pr_info("%s: retry\n", __func__);
6162 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
6163 0x00);
6164 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
6165 0x10);
6166 } else {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306167 wcd9xxx_disable_irq(codec->control_data,
Patrick Laic7cae882011-11-18 11:52:49 -08006168 TABLA_IRQ_HPH_PA_OCPL_FAULT);
6169 tabla->hphlocp_cnt = 0;
6170 tabla->hph_status |= SND_JACK_OC_HPHL;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006171 if (tabla->mbhc_cfg.headset_jack)
Patrick Laic7cae882011-11-18 11:52:49 -08006172 tabla_snd_soc_jack_report(tabla,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006173 tabla->mbhc_cfg.headset_jack,
6174 tabla->hph_status,
6175 TABLA_JACK_MASK);
Patrick Lai49efeac2011-11-03 11:01:12 -07006176 }
6177 } else {
6178 pr_err("%s: Bad tabla private data\n", __func__);
6179 }
6180
6181 return IRQ_HANDLED;
6182}
6183
6184static irqreturn_t tabla_hphr_ocp_irq(int irq, void *data)
6185{
6186 struct tabla_priv *tabla = data;
6187 struct snd_soc_codec *codec;
6188
6189 pr_info("%s: received HPHR OCP irq\n", __func__);
6190
6191 if (tabla) {
6192 codec = tabla->codec;
Patrick Laic7cae882011-11-18 11:52:49 -08006193 if (tabla->hphrocp_cnt++ < TABLA_OCP_ATTEMPT) {
6194 pr_info("%s: retry\n", __func__);
6195 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
6196 0x00);
6197 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10,
6198 0x10);
6199 } else {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05306200 wcd9xxx_disable_irq(codec->control_data,
Patrick Laic7cae882011-11-18 11:52:49 -08006201 TABLA_IRQ_HPH_PA_OCPR_FAULT);
6202 tabla->hphrocp_cnt = 0;
6203 tabla->hph_status |= SND_JACK_OC_HPHR;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006204 if (tabla->mbhc_cfg.headset_jack)
Patrick Laic7cae882011-11-18 11:52:49 -08006205 tabla_snd_soc_jack_report(tabla,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006206 tabla->mbhc_cfg.headset_jack,
6207 tabla->hph_status,
6208 TABLA_JACK_MASK);
Patrick Lai49efeac2011-11-03 11:01:12 -07006209 }
6210 } else {
6211 pr_err("%s: Bad tabla private data\n", __func__);
6212 }
6213
6214 return IRQ_HANDLED;
6215}
6216
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006217static bool tabla_is_inval_ins_range(struct snd_soc_codec *codec,
6218 s32 mic_volt, bool highhph, bool *highv)
Joonwoo Park03324832012-03-19 19:36:16 -07006219{
6220 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006221 bool invalid = false;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006222 s16 v_hs_max;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006223
6224 /* Perform this check only when the high voltage headphone
6225 * needs to be considered as invalid
6226 */
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006227 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006228 *highv = mic_volt > v_hs_max;
6229 if (!highhph && *highv)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006230 invalid = true;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006231 else if (mic_volt < tabla->mbhc_data.v_inval_ins_high &&
6232 (mic_volt > tabla->mbhc_data.v_inval_ins_low))
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006233 invalid = true;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006234
6235 return invalid;
6236}
6237
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006238static bool tabla_is_inval_ins_delta(struct snd_soc_codec *codec,
6239 int mic_volt, int mic_volt_prev,
6240 int threshold)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006241{
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006242 return abs(mic_volt - mic_volt_prev) > threshold;
Joonwoo Park03324832012-03-19 19:36:16 -07006243}
6244
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006245/* called under codec_resource_lock acquisition */
6246void tabla_find_plug_and_report(struct snd_soc_codec *codec,
6247 enum tabla_mbhc_plug_type plug_type)
Joonwoo Park03324832012-03-19 19:36:16 -07006248{
6249 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006250
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006251 if (plug_type == PLUG_TYPE_HEADPHONE &&
6252 tabla->current_plug == PLUG_TYPE_NONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006253 /* Nothing was reported previously
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006254 * report a headphone or unsupported
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006255 */
6256 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
6257 tabla_codec_cleanup_hs_polling(codec);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006258 } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) {
6259 if (tabla->current_plug == PLUG_TYPE_HEADSET)
6260 tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET);
6261 else if (tabla->current_plug == PLUG_TYPE_HEADPHONE)
6262 tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE);
6263
6264 tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED);
6265 tabla_codec_cleanup_hs_polling(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006266 } else if (plug_type == PLUG_TYPE_HEADSET) {
6267 /* If Headphone was reported previously, this will
6268 * only report the mic line
6269 */
6270 tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET);
6271 msleep(100);
6272 tabla_codec_start_hs_polling(codec);
6273 } else if (plug_type == PLUG_TYPE_HIGH_HPH) {
6274 if (tabla->current_plug == PLUG_TYPE_NONE)
6275 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
6276 tabla_codec_cleanup_hs_polling(codec);
6277 pr_debug("setup mic trigger for further detection\n");
6278 tabla->lpi_enabled = true;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006279 tabla_codec_enable_hs_detect(codec, 1,
6280 MBHC_USE_MB_TRIGGER |
6281 MBHC_USE_HPHL_TRIGGER,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006282 false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006283 } else {
6284 WARN(1, "Unexpected current plug_type %d, plug_type %d\n",
6285 tabla->current_plug, plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006286 }
6287}
6288
6289/* should be called under interrupt context that hold suspend */
6290static void tabla_schedule_hs_detect_plug(struct tabla_priv *tabla)
6291{
6292 pr_debug("%s: scheduling tabla_hs_correct_gpio_plug\n", __func__);
6293 tabla->hs_detect_work_stop = false;
6294 wcd9xxx_lock_sleep(tabla->codec->control_data);
6295 schedule_work(&tabla->hs_correct_plug_work);
6296}
6297
6298/* called under codec_resource_lock acquisition */
6299static void tabla_cancel_hs_detect_plug(struct tabla_priv *tabla)
6300{
6301 pr_debug("%s: canceling hs_correct_plug_work\n", __func__);
6302 tabla->hs_detect_work_stop = true;
6303 wmb();
6304 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
6305 if (cancel_work_sync(&tabla->hs_correct_plug_work)) {
6306 pr_debug("%s: hs_correct_plug_work is canceled\n", __func__);
6307 wcd9xxx_unlock_sleep(tabla->codec->control_data);
6308 }
6309 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
6310}
6311
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006312static bool tabla_hs_gpio_level_remove(struct tabla_priv *tabla)
6313{
6314 return (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) !=
6315 tabla->mbhc_cfg.gpio_level_insert);
6316}
6317
Joonwoo Park41956722012-04-18 13:13:07 -07006318/* called under codec_resource_lock acquisition */
6319static void tabla_codec_hphr_gnd_switch(struct snd_soc_codec *codec, bool on)
6320{
6321 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, on);
6322 if (on)
6323 usleep_range(5000, 5000);
6324}
6325
6326/* called under codec_resource_lock acquisition and mbhc override = 1 */
6327static enum tabla_mbhc_plug_type
6328tabla_codec_get_plug_type(struct snd_soc_codec *codec, bool highhph)
6329{
6330 int i;
6331 bool gndswitch, vddioswitch;
6332 int scaled;
6333 struct tabla_mbhc_plug_type_cfg *plug_type_ptr;
6334 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07006335 int num_det = MBHC_NUM_DCE_PLUG_DETECT + 1;
Joonwoo Park41956722012-04-18 13:13:07 -07006336 enum tabla_mbhc_plug_type plug_type[num_det];
6337 s16 mb_v[num_det];
6338 s32 mic_mv[num_det];
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006339 bool inval;
6340 bool highdelta;
6341 bool ahighv = false, highv;
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07006342 bool gndmicswapped = false;
Joonwoo Park41956722012-04-18 13:13:07 -07006343
6344 /* make sure override is on */
6345 WARN_ON(!(snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04));
6346
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006347 /* GND and MIC swap detection requires at least 2 rounds of DCE */
6348 BUG_ON(num_det < 2);
6349
6350 plug_type_ptr =
6351 TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
6352
6353 plug_type[0] = PLUG_TYPE_INVALID;
6354
Joonwoo Park41956722012-04-18 13:13:07 -07006355 /* performs DCEs for N times
6356 * 1st: check if voltage is in invalid range
6357 * 2nd - N-2nd: check voltage range and delta
6358 * N-1st: check voltage range, delta with HPHR GND switch
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07006359 * Nth: check voltage range with VDDIO switch */
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006360 for (i = 0; i < num_det; i++) {
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07006361 gndswitch = (i == (num_det - 2));
6362 vddioswitch = (i == (num_det - 1)) || (i == (num_det - 2));
Joonwoo Park41956722012-04-18 13:13:07 -07006363 if (i == 0) {
6364 mb_v[i] = tabla_codec_setup_hs_polling(codec);
6365 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006366 inval = tabla_is_inval_ins_range(codec, mic_mv[i],
6367 highhph, &highv);
6368 ahighv |= highv;
Joonwoo Park41956722012-04-18 13:13:07 -07006369 scaled = mic_mv[i];
Joonwoo Park41956722012-04-18 13:13:07 -07006370 } else {
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006371 if (vddioswitch)
6372 __tabla_codec_switch_micbias(tabla->codec, 1,
6373 false, false);
Joonwoo Park41956722012-04-18 13:13:07 -07006374 if (gndswitch)
6375 tabla_codec_hphr_gnd_switch(codec, true);
6376 mb_v[i] = __tabla_codec_sta_dce(codec, 1, true, true);
6377 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006378 if (vddioswitch)
6379 scaled = tabla_scale_v_micb_vddio(tabla,
Joonwoo Park41956722012-04-18 13:13:07 -07006380 mic_mv[i],
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006381 false);
6382 else
6383 scaled = mic_mv[i];
6384 /* !gndswitch & vddioswitch means the previous DCE
6385 * was done with gndswitch, don't compare with DCE
6386 * with gndswitch */
6387 highdelta = tabla_is_inval_ins_delta(codec, scaled,
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07006388 mic_mv[i - 1],
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006389 TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV);
6390 inval = (tabla_is_inval_ins_range(codec, mic_mv[i],
6391 highhph, &highv) ||
6392 highdelta);
6393 ahighv |= highv;
Joonwoo Park41956722012-04-18 13:13:07 -07006394 if (gndswitch)
6395 tabla_codec_hphr_gnd_switch(codec, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006396 if (vddioswitch)
6397 __tabla_codec_switch_micbias(tabla->codec, 0,
6398 false, false);
6399 /* claim UNSUPPORTED plug insertion when
6400 * good headset is detected but HPHR GND switch makes
6401 * delta difference */
6402 if (i == (num_det - 2) && highdelta && !ahighv)
Joonwoo Park6a5a4f12012-06-15 15:56:25 -07006403 gndmicswapped = true;
6404 else if (i == (num_det - 1) && inval) {
6405 if (gndmicswapped)
6406 plug_type[0] = PLUG_TYPE_GND_MIC_SWAP;
6407 else
6408 plug_type[0] = PLUG_TYPE_INVALID;
6409 }
Joonwoo Park41956722012-04-18 13:13:07 -07006410 }
6411 pr_debug("%s: DCE #%d, %04x, V %d, scaled V %d, GND %d, "
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006412 "VDDIO %d, inval %d\n", __func__,
Joonwoo Park41956722012-04-18 13:13:07 -07006413 i + 1, mb_v[i] & 0xffff, mic_mv[i], scaled, gndswitch,
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006414 vddioswitch, inval);
6415 /* don't need to run further DCEs */
6416 if (ahighv && inval)
6417 break;
6418 mic_mv[i] = scaled;
Joonwoo Park41956722012-04-18 13:13:07 -07006419 }
6420
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006421 for (i = 0; (plug_type[0] != PLUG_TYPE_GND_MIC_SWAP && !inval) &&
6422 i < num_det; i++) {
Joonwoo Park41956722012-04-18 13:13:07 -07006423 /*
6424 * If we are here, means none of the all
6425 * measurements are fake, continue plug type detection.
6426 * If all three measurements do not produce same
6427 * plug type, restart insertion detection
6428 */
6429 if (mic_mv[i] < plug_type_ptr->v_no_mic) {
6430 plug_type[i] = PLUG_TYPE_HEADPHONE;
6431 pr_debug("%s: Detect attempt %d, detected Headphone\n",
6432 __func__, i);
6433 } else if (highhph && (mic_mv[i] > plug_type_ptr->v_hs_max)) {
6434 plug_type[i] = PLUG_TYPE_HIGH_HPH;
6435 pr_debug("%s: Detect attempt %d, detected High "
6436 "Headphone\n", __func__, i);
6437 } else {
6438 plug_type[i] = PLUG_TYPE_HEADSET;
6439 pr_debug("%s: Detect attempt %d, detected Headset\n",
6440 __func__, i);
6441 }
6442
6443 if (i > 0 && (plug_type[i - 1] != plug_type[i])) {
6444 pr_err("%s: Detect attempt %d and %d are not same",
6445 __func__, i - 1, i);
6446 plug_type[0] = PLUG_TYPE_INVALID;
6447 inval = true;
6448 break;
6449 }
6450 }
6451
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006452 pr_debug("%s: Detected plug type %d\n", __func__, plug_type[0]);
Joonwoo Park41956722012-04-18 13:13:07 -07006453 return plug_type[0];
6454}
6455
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006456static void tabla_hs_correct_gpio_plug(struct work_struct *work)
6457{
6458 struct tabla_priv *tabla;
6459 struct snd_soc_codec *codec;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006460 int retry = 0, pt_gnd_mic_swap_cnt = 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006461 bool correction = false;
Joonwoo Park41956722012-04-18 13:13:07 -07006462 enum tabla_mbhc_plug_type plug_type;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006463 unsigned long timeout;
6464
6465 tabla = container_of(work, struct tabla_priv, hs_correct_plug_work);
6466 codec = tabla->codec;
6467
6468 pr_debug("%s: enter\n", __func__);
6469 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
6470
6471 /* Keep override on during entire plug type correction work.
6472 *
6473 * This is okay under the assumption that any GPIO irqs which use
6474 * MBHC block cancel and sync this work so override is off again
6475 * prior to GPIO interrupt handler's MBHC block usage.
6476 * Also while this correction work is running, we can guarantee
6477 * DAPM doesn't use any MBHC block as this work only runs with
6478 * headphone detection.
6479 */
6480 tabla_turn_onoff_override(codec, true);
6481
6482 timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS);
6483 while (!time_after(jiffies, timeout)) {
6484 ++retry;
6485 rmb();
6486 if (tabla->hs_detect_work_stop) {
6487 pr_debug("%s: stop requested\n", __func__);
6488 break;
6489 }
6490
6491 msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS);
6492 if (tabla_hs_gpio_level_remove(tabla)) {
6493 pr_debug("%s: GPIO value is low\n", __func__);
6494 break;
6495 }
6496
6497 /* can race with removal interrupt */
6498 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Joonwoo Park41956722012-04-18 13:13:07 -07006499 plug_type = tabla_codec_get_plug_type(codec, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006500 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
6501
Joonwoo Park41956722012-04-18 13:13:07 -07006502 if (plug_type == PLUG_TYPE_INVALID) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006503 pr_debug("Invalid plug in attempt # %d\n", retry);
6504 if (retry == NUM_ATTEMPTS_TO_REPORT &&
6505 tabla->current_plug == PLUG_TYPE_NONE) {
6506 tabla_codec_report_plug(codec, 1,
6507 SND_JACK_HEADPHONE);
6508 }
Joonwoo Park41956722012-04-18 13:13:07 -07006509 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006510 pr_debug("Good headphone detected, continue polling mic\n");
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006511 if (tabla->current_plug == PLUG_TYPE_NONE)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006512 tabla_codec_report_plug(codec, 1,
6513 SND_JACK_HEADPHONE);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006514 } else {
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006515 if (plug_type == PLUG_TYPE_GND_MIC_SWAP) {
6516 pt_gnd_mic_swap_cnt++;
6517 if (pt_gnd_mic_swap_cnt <
6518 TABLA_MBHC_GND_MIC_SWAP_THRESHOLD)
6519 continue;
6520 else if (pt_gnd_mic_swap_cnt >
6521 TABLA_MBHC_GND_MIC_SWAP_THRESHOLD) {
6522 /* This is due to GND/MIC switch didn't
6523 * work, Report unsupported plug */
6524 } else if (tabla->mbhc_cfg.swap_gnd_mic) {
6525 /* if switch is toggled, check again,
6526 * otherwise report unsupported plug */
6527 if (tabla->mbhc_cfg.swap_gnd_mic(codec))
6528 continue;
6529 }
6530 } else
6531 pt_gnd_mic_swap_cnt = 0;
6532
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006533 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
6534 /* Turn off override */
6535 tabla_turn_onoff_override(codec, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006536 /* The valid plug also includes PLUG_TYPE_GND_MIC_SWAP
6537 */
Joonwoo Park41956722012-04-18 13:13:07 -07006538 tabla_find_plug_and_report(codec, plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006539 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
6540 pr_debug("Attempt %d found correct plug %d\n", retry,
Joonwoo Park41956722012-04-18 13:13:07 -07006541 plug_type);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006542 correction = true;
6543 break;
6544 }
6545 }
6546
6547 /* Turn off override */
6548 if (!correction)
6549 tabla_turn_onoff_override(codec, false);
6550
6551 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
6552 pr_debug("%s: leave\n", __func__);
6553 /* unlock sleep */
6554 wcd9xxx_unlock_sleep(tabla->codec->control_data);
6555}
6556
6557/* called under codec_resource_lock acquisition */
6558static void tabla_codec_decide_gpio_plug(struct snd_soc_codec *codec)
6559{
Joonwoo Park41956722012-04-18 13:13:07 -07006560 enum tabla_mbhc_plug_type plug_type;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006561 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006562
6563 pr_debug("%s: enter\n", __func__);
6564
6565 tabla_turn_onoff_override(codec, true);
Joonwoo Park41956722012-04-18 13:13:07 -07006566 plug_type = tabla_codec_get_plug_type(codec, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006567 tabla_turn_onoff_override(codec, false);
6568
6569 if (tabla_hs_gpio_level_remove(tabla)) {
6570 pr_debug("%s: GPIO value is low when determining plug\n",
6571 __func__);
6572 return;
6573 }
6574
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006575 if (plug_type == PLUG_TYPE_INVALID ||
6576 plug_type == PLUG_TYPE_GND_MIC_SWAP) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006577 tabla_schedule_hs_detect_plug(tabla);
Joonwoo Park41956722012-04-18 13:13:07 -07006578 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006579 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
6580
6581 tabla_schedule_hs_detect_plug(tabla);
6582 } else {
Joonwoo Park41956722012-04-18 13:13:07 -07006583 pr_debug("%s: Valid plug found, determine plug type %d\n",
6584 __func__, plug_type);
6585 tabla_find_plug_and_report(codec, plug_type);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006586 }
6587}
6588
6589/* called under codec_resource_lock acquisition */
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006590static void tabla_codec_detect_plug_type(struct snd_soc_codec *codec)
6591{
Joonwoo Park41956722012-04-18 13:13:07 -07006592 enum tabla_mbhc_plug_type plug_type;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006593 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
6594 const struct tabla_mbhc_plug_detect_cfg *plug_det =
6595 TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration);
Joonwoo Park03324832012-03-19 19:36:16 -07006596
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006597 /* Turn on the override,
6598 * tabla_codec_setup_hs_polling requires override on */
6599 tabla_turn_onoff_override(codec, true);
Joonwoo Park03324832012-03-19 19:36:16 -07006600
6601 if (plug_det->t_ins_complete > 20)
6602 msleep(plug_det->t_ins_complete);
6603 else
6604 usleep_range(plug_det->t_ins_complete * 1000,
6605 plug_det->t_ins_complete * 1000);
6606
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006607 if (tabla->mbhc_cfg.gpio) {
6608 /* Turn off the override */
6609 tabla_turn_onoff_override(codec, false);
6610 if (tabla_hs_gpio_level_remove(tabla))
6611 pr_debug("%s: GPIO value is low when determining "
6612 "plug\n", __func__);
6613 else
6614 tabla_codec_decide_gpio_plug(codec);
6615 return;
6616 }
6617
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006618 plug_type = tabla_codec_get_plug_type(codec, false);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006619 tabla_turn_onoff_override(codec, false);
Joonwoo Park03324832012-03-19 19:36:16 -07006620
Joonwoo Park41956722012-04-18 13:13:07 -07006621 if (plug_type == PLUG_TYPE_INVALID) {
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006622 pr_debug("%s: Invalid plug type detected\n", __func__);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006623 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, 0x02);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006624 tabla_codec_cleanup_hs_polling(codec);
6625 tabla_codec_enable_hs_detect(codec, 1,
6626 MBHC_USE_MB_TRIGGER |
6627 MBHC_USE_HPHL_TRIGGER, false);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006628 } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) {
6629 pr_debug("%s: GND-MIC swapped plug type detected\n", __func__);
6630 tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED);
6631 tabla_codec_cleanup_hs_polling(codec);
6632 tabla_codec_enable_hs_detect(codec, 0, 0, false);
Joonwoo Park41956722012-04-18 13:13:07 -07006633 } else if (plug_type == PLUG_TYPE_HEADPHONE) {
Joonwoo Park03324832012-03-19 19:36:16 -07006634 pr_debug("%s: Headphone Detected\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006635 tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE);
6636 tabla_codec_cleanup_hs_polling(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07006637 tabla_codec_enable_hs_detect(codec, 0, 0, false);
Joonwoo Park41956722012-04-18 13:13:07 -07006638 } else if (plug_type == PLUG_TYPE_HEADSET) {
Joonwoo Park03324832012-03-19 19:36:16 -07006639 pr_debug("%s: Headset detected\n", __func__);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006640 tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET);
6641
Joonwoo Park03324832012-03-19 19:36:16 -07006642 /* avoid false button press detect */
6643 msleep(50);
Joonwoo Park03324832012-03-19 19:36:16 -07006644 tabla_codec_start_hs_polling(codec);
Joonwoo Park03324832012-03-19 19:36:16 -07006645 }
6646}
6647
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006648/* called only from interrupt which is under codec_resource_lock acquisition */
6649static void tabla_hs_insert_irq_gpio(struct tabla_priv *priv, bool is_removal)
Bradley Rubincb1e2732011-06-23 16:49:20 -07006650{
Bradley Rubincb1e2732011-06-23 16:49:20 -07006651 struct snd_soc_codec *codec = priv->codec;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006652
6653 if (!is_removal) {
6654 pr_debug("%s: MIC trigger insertion interrupt\n", __func__);
6655
6656 rmb();
6657 if (priv->lpi_enabled)
6658 msleep(100);
6659
6660 rmb();
6661 if (!priv->lpi_enabled) {
6662 pr_debug("%s: lpi is disabled\n", __func__);
6663 } else if (gpio_get_value_cansleep(priv->mbhc_cfg.gpio) ==
6664 priv->mbhc_cfg.gpio_level_insert) {
6665 pr_debug("%s: Valid insertion, "
6666 "detect plug type\n", __func__);
6667 tabla_codec_decide_gpio_plug(codec);
6668 } else {
6669 pr_debug("%s: Invalid insertion, "
6670 "stop plug detection\n", __func__);
6671 }
6672 } else {
6673 pr_err("%s: GPIO used, invalid MBHC Removal\n", __func__);
6674 }
6675}
6676
6677/* called only from interrupt which is under codec_resource_lock acquisition */
6678static void tabla_hs_insert_irq_nogpio(struct tabla_priv *priv, bool is_removal,
6679 bool is_mb_trigger)
6680{
Joonwoo Park03324832012-03-19 19:36:16 -07006681 int ret;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006682 struct snd_soc_codec *codec = priv->codec;
6683 struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent);
Bhalchandra Gajare7fc72332011-10-13 19:01:55 -07006684
6685 if (is_removal) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006686 /* cancel possiblely running hs detect work */
6687 tabla_cancel_hs_detect_plug(priv);
6688
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07006689 /*
6690 * If headphone is removed while playback is in progress,
6691 * it is possible that micbias will be switched to VDDIO.
6692 */
Joonwoo Park03324832012-03-19 19:36:16 -07006693 tabla_codec_switch_micbias(codec, 0);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07006694 if (priv->current_plug == PLUG_TYPE_HEADPHONE)
6695 tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE);
6696 else if (priv->current_plug == PLUG_TYPE_GND_MIC_SWAP)
6697 tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED);
6698 else
6699 WARN(1, "%s: Unexpected current plug type %d\n",
6700 __func__, priv->current_plug);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006701 tabla_codec_shutdown_hs_removal_detect(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006702 tabla_codec_enable_hs_detect(codec, 1,
6703 MBHC_USE_MB_TRIGGER |
6704 MBHC_USE_HPHL_TRIGGER,
Joonwoo Park03324832012-03-19 19:36:16 -07006705 true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006706 } else if (is_mb_trigger && !is_removal) {
Joonwoo Park03324832012-03-19 19:36:16 -07006707 pr_debug("%s: Waiting for Headphone left trigger\n",
6708 __func__);
6709 wcd9xxx_lock_sleep(core);
6710 if (schedule_delayed_work(&priv->mbhc_insert_dwork,
6711 usecs_to_jiffies(1000000)) == 0) {
6712 pr_err("%s: mbhc_insert_dwork is already scheduled\n",
6713 __func__);
6714 wcd9xxx_unlock_sleep(core);
Joonwoo Parkf4267c22012-01-10 13:25:24 -08006715 }
Joonwoo Park03324832012-03-19 19:36:16 -07006716 tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER,
6717 false);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006718 } else {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006719 ret = cancel_delayed_work(&priv->mbhc_insert_dwork);
6720 if (ret != 0) {
6721 pr_debug("%s: Complete plug insertion, Detecting plug "
6722 "type\n", __func__);
6723 tabla_codec_detect_plug_type(codec);
6724 wcd9xxx_unlock_sleep(core);
6725 } else {
6726 wcd9xxx_enable_irq(codec->control_data,
6727 TABLA_IRQ_MBHC_INSERTION);
6728 pr_err("%s: Error detecting plug insertion\n",
6729 __func__);
6730 }
Joonwoo Park03324832012-03-19 19:36:16 -07006731 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006732}
Bhalchandra Gajare9494fa262011-11-10 19:25:59 -08006733
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006734static irqreturn_t tabla_hs_insert_irq(int irq, void *data)
6735{
6736 bool is_mb_trigger, is_removal;
6737 struct tabla_priv *priv = data;
6738 struct snd_soc_codec *codec = priv->codec;
Bradley Rubincb1e2732011-06-23 16:49:20 -07006739
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006740 pr_debug("%s: enter\n", __func__);
6741 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
6742 wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
6743
6744 is_mb_trigger = !!(snd_soc_read(codec, priv->mbhc_bias_regs.mbhc_reg) &
6745 0x10);
6746 is_removal = !!(snd_soc_read(codec, TABLA_A_CDC_MBHC_INT_CTL) & 0x02);
6747 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x03, 0x00);
6748
6749 /* Turn off both HPH and MIC line schmitt triggers */
6750 snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
6751 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
6752 snd_soc_update_bits(codec, priv->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
6753
6754 if (priv->mbhc_cfg.gpio)
6755 tabla_hs_insert_irq_gpio(priv, is_removal);
6756 else
6757 tabla_hs_insert_irq_nogpio(priv, is_removal, is_mb_trigger);
6758
6759 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Bradley Rubincb1e2732011-06-23 16:49:20 -07006760 return IRQ_HANDLED;
6761}
6762
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006763static bool is_valid_mic_voltage(struct snd_soc_codec *codec, s32 mic_mv)
6764{
6765 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006766 const struct tabla_mbhc_plug_type_cfg *plug_type =
6767 TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration);
6768 const s16 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006769
6770 return (!(mic_mv > 10 && mic_mv < 80) && (mic_mv > plug_type->v_no_mic)
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006771 && (mic_mv < v_hs_max)) ? true : false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006772}
6773
6774/* called under codec_resource_lock acquisition
6775 * returns true if mic voltage range is back to normal insertion
6776 * returns false either if timedout or removed */
6777static bool tabla_hs_remove_settle(struct snd_soc_codec *codec)
6778{
6779 int i;
6780 bool timedout, settled = false;
6781 s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT];
6782 short mb_v[MBHC_NUM_DCE_PLUG_DETECT];
6783 unsigned long retry = 0, timeout;
6784 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006785 const s16 v_hs_max = tabla_get_current_v_hs_max(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006786
6787 timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS);
6788 while (!(timedout = time_after(jiffies, timeout))) {
6789 retry++;
6790 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
6791 pr_debug("%s: GPIO indicates removal\n", __func__);
6792 break;
6793 }
6794
6795 if (tabla->mbhc_cfg.gpio) {
6796 if (retry > 1)
6797 msleep(250);
6798 else
6799 msleep(50);
6800 }
6801
6802 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
6803 pr_debug("%s: GPIO indicates removal\n", __func__);
6804 break;
6805 }
6806
6807 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) {
6808 mb_v[i] = tabla_codec_sta_dce(codec, 1, true);
6809 mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]);
6810 pr_debug("%s : DCE run %lu, mic_mv = %d(%x)\n",
6811 __func__, retry, mic_mv[i], mb_v[i]);
6812 }
6813
6814 if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) {
6815 pr_debug("%s: GPIO indicates removal\n", __func__);
6816 break;
6817 }
6818
6819 if (tabla->current_plug == PLUG_TYPE_NONE) {
6820 pr_debug("%s : headset/headphone is removed\n",
6821 __func__);
6822 break;
6823 }
6824
6825 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++)
6826 if (!is_valid_mic_voltage(codec, mic_mv[i]))
6827 break;
6828
6829 if (i == MBHC_NUM_DCE_PLUG_DETECT) {
6830 pr_debug("%s: MIC voltage settled\n", __func__);
6831 settled = true;
6832 msleep(200);
6833 break;
6834 }
6835
6836 /* only for non-GPIO remove irq */
6837 if (!tabla->mbhc_cfg.gpio) {
6838 for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++)
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006839 if (mic_mv[i] < v_hs_max)
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006840 break;
6841 if (i == MBHC_NUM_DCE_PLUG_DETECT) {
6842 pr_debug("%s: Headset is removed\n", __func__);
6843 break;
6844 }
6845 }
6846 }
6847
6848 if (timedout)
6849 pr_debug("%s: Microphone did not settle in %d seconds\n",
6850 __func__, TABLA_HS_DETECT_PLUG_TIME_MS);
6851 return settled;
6852}
6853
6854/* called only from interrupt which is under codec_resource_lock acquisition */
6855static void tabla_hs_remove_irq_gpio(struct tabla_priv *priv)
6856{
6857 struct snd_soc_codec *codec = priv->codec;
6858
6859 if (tabla_hs_remove_settle(codec))
6860 tabla_codec_start_hs_polling(codec);
6861 pr_debug("%s: remove settle done\n", __func__);
6862}
6863
6864/* called only from interrupt which is under codec_resource_lock acquisition */
6865static void tabla_hs_remove_irq_nogpio(struct tabla_priv *priv)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006866{
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006867 short bias_value;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006868 bool removed = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006869 struct snd_soc_codec *codec = priv->codec;
Joonwoo Park0976d012011-12-22 11:48:18 -08006870 const struct tabla_mbhc_general_cfg *generic =
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006871 TABLA_MBHC_CAL_GENERAL_PTR(priv->mbhc_cfg.calibration);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006872 int min_us = TABLA_FAKE_REMOVAL_MIN_PERIOD_MS * 1000;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006873
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006874 if (priv->current_plug != PLUG_TYPE_HEADSET) {
6875 pr_debug("%s(): Headset is not inserted, ignore removal\n",
6876 __func__);
6877 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
6878 0x08, 0x08);
6879 return;
6880 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006881
Joonwoo Park0976d012011-12-22 11:48:18 -08006882 usleep_range(generic->t_shutdown_plug_rem,
6883 generic->t_shutdown_plug_rem);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006884
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006885 do {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006886 bias_value = tabla_codec_sta_dce(codec, 1, true);
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006887 pr_debug("%s: DCE %d,%d, %d us left\n", __func__, bias_value,
6888 tabla_codec_sta_dce_v(codec, 1, bias_value), min_us);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006889 if (bias_value < tabla_get_current_v_ins(priv, false)) {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006890 pr_debug("%s: checking false removal\n", __func__);
6891 msleep(500);
6892 removed = !tabla_hs_remove_settle(codec);
6893 pr_debug("%s: headset %sactually removed\n", __func__,
6894 removed ? "" : "not ");
Joonwoo Park6b9b03f2012-01-23 18:48:54 -08006895 break;
6896 }
6897 min_us -= priv->mbhc_data.t_dce;
6898 } while (min_us > 0);
Bradley Rubin89ffd0a2011-07-21 16:04:06 -07006899
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006900 if (removed) {
6901 /* cancel possiblely running hs detect work */
6902 tabla_cancel_hs_detect_plug(priv);
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07006903 /*
6904 * If this removal is not false, first check the micbias
6905 * switch status and switch it to LDOH if it is already
6906 * switched to VDDIO.
6907 */
Joonwoo Park03324832012-03-19 19:36:16 -07006908 tabla_codec_switch_micbias(codec, 0);
Joonwoo Park03324832012-03-19 19:36:16 -07006909
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006910 tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET);
6911 tabla_codec_cleanup_hs_polling(codec);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006912 tabla_codec_enable_hs_detect(codec, 1,
6913 MBHC_USE_MB_TRIGGER |
6914 MBHC_USE_HPHL_TRIGGER,
Joonwoo Park03324832012-03-19 19:36:16 -07006915 true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006916 } else {
6917 tabla_codec_start_hs_polling(codec);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006918 }
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006919}
Joonwoo Park8b1f0982011-12-08 17:12:45 -08006920
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006921static irqreturn_t tabla_hs_remove_irq(int irq, void *data)
6922{
6923 struct tabla_priv *priv = data;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006924 bool vddio;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006925 pr_debug("%s: enter, removal interrupt\n", __func__);
6926
6927 TABLA_ACQUIRE_LOCK(priv->codec_resource_lock);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006928 vddio = (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV &&
6929 priv->mbhc_micbias_switched);
6930 if (vddio)
6931 __tabla_codec_switch_micbias(priv->codec, 0, false, true);
6932
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006933 if (priv->mbhc_cfg.gpio)
6934 tabla_hs_remove_irq_gpio(priv);
6935 else
6936 tabla_hs_remove_irq_nogpio(priv);
6937
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006938 /* if driver turned off vddio switch and headset is not removed,
6939 * turn on the vddio switch back, if headset is removed then vddio
6940 * switch is off by time now and shouldn't be turn on again from here */
6941 if (vddio && priv->current_plug == PLUG_TYPE_HEADSET)
6942 __tabla_codec_switch_micbias(priv->codec, 1, true, true);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006943 TABLA_RELEASE_LOCK(priv->codec_resource_lock);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07006944
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006945 return IRQ_HANDLED;
6946}
6947
Joonwoo Park03324832012-03-19 19:36:16 -07006948void mbhc_insert_work(struct work_struct *work)
6949{
6950 struct delayed_work *dwork;
6951 struct tabla_priv *tabla;
6952 struct snd_soc_codec *codec;
6953 struct wcd9xxx *tabla_core;
6954
6955 dwork = to_delayed_work(work);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006956 tabla = container_of(dwork, struct tabla_priv, mbhc_insert_dwork);
Joonwoo Park03324832012-03-19 19:36:16 -07006957 codec = tabla->codec;
6958 tabla_core = dev_get_drvdata(codec->dev->parent);
6959
6960 pr_debug("%s:\n", __func__);
6961
6962 /* Turn off both HPH and MIC line schmitt triggers */
6963 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00);
6964 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00);
6965 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00);
6966 wcd9xxx_disable_irq_sync(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
6967 tabla_codec_detect_plug_type(codec);
6968 wcd9xxx_unlock_sleep(tabla_core);
6969}
6970
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07006971static void tabla_hs_gpio_handler(struct snd_soc_codec *codec)
6972{
6973 bool insert;
6974 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
6975 bool is_removed = false;
6976
6977 pr_debug("%s: enter\n", __func__);
6978
6979 tabla->in_gpio_handler = true;
6980 /* Wait here for debounce time */
6981 usleep_range(TABLA_GPIO_IRQ_DEBOUNCE_TIME_US,
6982 TABLA_GPIO_IRQ_DEBOUNCE_TIME_US);
6983
6984 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
6985
6986 /* cancel pending button press */
6987 if (tabla_cancel_btn_work(tabla))
6988 pr_debug("%s: button press is canceled\n", __func__);
6989
6990 insert = (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) ==
6991 tabla->mbhc_cfg.gpio_level_insert);
6992 if ((tabla->current_plug == PLUG_TYPE_NONE) && insert) {
6993 tabla->lpi_enabled = false;
6994 wmb();
6995
6996 /* cancel detect plug */
6997 tabla_cancel_hs_detect_plug(tabla);
6998
6999 /* Disable Mic Bias pull down and HPH Switch to GND */
7000 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01,
7001 0x00);
7002 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x00);
7003 tabla_codec_detect_plug_type(codec);
7004 } else if ((tabla->current_plug != PLUG_TYPE_NONE) && !insert) {
7005 tabla->lpi_enabled = false;
7006 wmb();
7007
7008 /* cancel detect plug */
7009 tabla_cancel_hs_detect_plug(tabla);
7010
7011 if (tabla->current_plug == PLUG_TYPE_HEADPHONE) {
7012 tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE);
7013 is_removed = true;
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007014 } else if (tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP) {
7015 tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED);
7016 is_removed = true;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007017 } else if (tabla->current_plug == PLUG_TYPE_HEADSET) {
7018 tabla_codec_pause_hs_polling(codec);
7019 tabla_codec_cleanup_hs_polling(codec);
7020 tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET);
7021 is_removed = true;
7022 }
7023
7024 if (is_removed) {
7025 /* Enable Mic Bias pull down and HPH Switch to GND */
7026 snd_soc_update_bits(codec,
7027 tabla->mbhc_bias_regs.ctl_reg, 0x01,
7028 0x01);
7029 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01,
7030 0x01);
7031 /* Make sure mic trigger is turned off */
7032 snd_soc_update_bits(codec,
7033 tabla->mbhc_bias_regs.ctl_reg,
7034 0x01, 0x01);
7035 snd_soc_update_bits(codec,
7036 tabla->mbhc_bias_regs.mbhc_reg,
7037 0x90, 0x00);
7038 /* Reset MBHC State Machine */
7039 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
7040 0x08, 0x08);
7041 snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL,
7042 0x08, 0x00);
7043 /* Turn off override */
7044 tabla_turn_onoff_override(codec, false);
7045 }
7046 }
7047
7048 tabla->in_gpio_handler = false;
7049 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
7050 pr_debug("%s: leave\n", __func__);
7051}
7052
7053static irqreturn_t tabla_mechanical_plug_detect_irq(int irq, void *data)
7054{
7055 int r = IRQ_HANDLED;
7056 struct snd_soc_codec *codec = data;
7057
7058 if (unlikely(wcd9xxx_lock_sleep(codec->control_data) == false)) {
7059 pr_warn("%s: failed to hold suspend\n", __func__);
7060 r = IRQ_NONE;
7061 } else {
7062 tabla_hs_gpio_handler(codec);
7063 wcd9xxx_unlock_sleep(codec->control_data);
7064 }
7065
7066 return r;
7067}
7068
Joonwoo Park1305bab2012-05-21 15:08:42 -07007069static int tabla_mbhc_init_and_calibrate(struct tabla_priv *tabla)
7070{
7071 int ret = 0;
7072 struct snd_soc_codec *codec = tabla->codec;
7073
7074 tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false);
7075 tabla_mbhc_init(codec);
7076 tabla_mbhc_cal(codec);
7077 tabla_mbhc_calc_thres(codec);
7078 tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false);
7079 tabla_codec_calibrate_hs_polling(codec);
7080 if (!tabla->mbhc_cfg.gpio) {
7081 ret = tabla_codec_enable_hs_detect(codec, 1,
7082 MBHC_USE_MB_TRIGGER |
7083 MBHC_USE_HPHL_TRIGGER,
7084 false);
7085
7086 if (IS_ERR_VALUE(ret))
7087 pr_err("%s: Failed to setup MBHC detection\n",
7088 __func__);
7089 } else {
7090 /* Enable Mic Bias pull down and HPH Switch to GND */
7091 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg,
7092 0x01, 0x01);
7093 snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x01);
7094 INIT_WORK(&tabla->hs_correct_plug_work,
7095 tabla_hs_correct_gpio_plug);
7096 }
7097
7098 if (!IS_ERR_VALUE(ret)) {
7099 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10);
7100 wcd9xxx_enable_irq(codec->control_data,
7101 TABLA_IRQ_HPH_PA_OCPL_FAULT);
7102 wcd9xxx_enable_irq(codec->control_data,
7103 TABLA_IRQ_HPH_PA_OCPR_FAULT);
7104
7105 if (tabla->mbhc_cfg.gpio) {
7106 ret = request_threaded_irq(tabla->mbhc_cfg.gpio_irq,
7107 NULL,
7108 tabla_mechanical_plug_detect_irq,
7109 (IRQF_TRIGGER_RISING |
7110 IRQF_TRIGGER_FALLING),
7111 "tabla-gpio", codec);
7112 if (!IS_ERR_VALUE(ret)) {
7113 ret = enable_irq_wake(tabla->mbhc_cfg.gpio_irq);
7114 /* Bootup time detection */
7115 tabla_hs_gpio_handler(codec);
7116 }
7117 }
7118 }
7119
7120 return ret;
7121}
7122
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007123static void mbhc_fw_read(struct work_struct *work)
7124{
7125 struct delayed_work *dwork;
7126 struct tabla_priv *tabla;
7127 struct snd_soc_codec *codec;
7128 const struct firmware *fw;
Joonwoo Park1305bab2012-05-21 15:08:42 -07007129 int ret = -1, retry = 0;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007130
7131 dwork = to_delayed_work(work);
Joonwoo Park1305bab2012-05-21 15:08:42 -07007132 tabla = container_of(dwork, struct tabla_priv, mbhc_firmware_dwork);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007133 codec = tabla->codec;
7134
7135 while (retry < MBHC_FW_READ_ATTEMPTS) {
7136 retry++;
7137 pr_info("%s:Attempt %d to request MBHC firmware\n",
7138 __func__, retry);
7139 ret = request_firmware(&fw, "wcd9310/wcd9310_mbhc.bin",
7140 codec->dev);
7141
7142 if (ret != 0) {
7143 usleep_range(MBHC_FW_READ_TIMEOUT,
Joonwoo Park1305bab2012-05-21 15:08:42 -07007144 MBHC_FW_READ_TIMEOUT);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007145 } else {
7146 pr_info("%s: MBHC Firmware read succesful\n", __func__);
7147 break;
7148 }
7149 }
7150
7151 if (ret != 0) {
7152 pr_err("%s: Cannot load MBHC firmware use default cal\n",
7153 __func__);
7154 } else if (tabla_mbhc_fw_validate(fw) == false) {
7155 pr_err("%s: Invalid MBHC cal data size use default cal\n",
7156 __func__);
7157 release_firmware(fw);
7158 } else {
7159 tabla->mbhc_cfg.calibration = (void *)fw->data;
7160 tabla->mbhc_fw = fw;
7161 }
7162
Joonwoo Park1305bab2012-05-21 15:08:42 -07007163 (void) tabla_mbhc_init_and_calibrate(tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007164}
7165
Joonwoo Park03324832012-03-19 19:36:16 -07007166int tabla_hs_detect(struct snd_soc_codec *codec,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007167 const struct tabla_mbhc_config *cfg)
Joonwoo Park03324832012-03-19 19:36:16 -07007168{
7169 struct tabla_priv *tabla;
7170 int rc = 0;
7171
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007172 if (!codec || !cfg->calibration) {
Joonwoo Park03324832012-03-19 19:36:16 -07007173 pr_err("Error: no codec or calibration\n");
7174 return -EINVAL;
7175 }
7176
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007177 if (cfg->mclk_rate != TABLA_MCLK_RATE_12288KHZ) {
7178 if (cfg->mclk_rate == TABLA_MCLK_RATE_9600KHZ)
Joonwoo Park03324832012-03-19 19:36:16 -07007179 pr_err("Error: clock rate %dHz is not yet supported\n",
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007180 cfg->mclk_rate);
Joonwoo Park03324832012-03-19 19:36:16 -07007181 else
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007182 pr_err("Error: unsupported clock rate %d\n",
7183 cfg->mclk_rate);
Joonwoo Park03324832012-03-19 19:36:16 -07007184 return -EINVAL;
7185 }
7186
7187 tabla = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007188 tabla->mbhc_cfg = *cfg;
7189 tabla->in_gpio_handler = false;
7190 tabla->current_plug = PLUG_TYPE_NONE;
7191 tabla->lpi_enabled = false;
Joonwoo Park03324832012-03-19 19:36:16 -07007192 tabla_get_mbhc_micbias_regs(codec, &tabla->mbhc_bias_regs);
7193
7194 /* Put CFILT in fast mode by default */
7195 snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl,
7196 0x40, TABLA_CFILT_FAST_MODE);
7197 INIT_DELAYED_WORK(&tabla->mbhc_firmware_dwork, mbhc_fw_read);
7198 INIT_DELAYED_WORK(&tabla->mbhc_btn_dwork, btn_lpress_fn);
7199 INIT_WORK(&tabla->hphlocp_work, hphlocp_off_report);
7200 INIT_WORK(&tabla->hphrocp_work, hphrocp_off_report);
7201 INIT_DELAYED_WORK(&tabla->mbhc_insert_dwork, mbhc_insert_work);
7202
Joonwoo Park1305bab2012-05-21 15:08:42 -07007203 if (!tabla->mbhc_cfg.read_fw_bin)
7204 rc = tabla_mbhc_init_and_calibrate(tabla);
7205 else
Joonwoo Park03324832012-03-19 19:36:16 -07007206 schedule_delayed_work(&tabla->mbhc_firmware_dwork,
7207 usecs_to_jiffies(MBHC_FW_READ_TIMEOUT));
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007208
Joonwoo Park03324832012-03-19 19:36:16 -07007209 return rc;
7210}
7211EXPORT_SYMBOL_GPL(tabla_hs_detect);
7212
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007213static unsigned long slimbus_value;
7214
7215static irqreturn_t tabla_slimbus_irq(int irq, void *data)
7216{
7217 struct tabla_priv *priv = data;
7218 struct snd_soc_codec *codec = priv->codec;
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07007219 struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec);
7220 int i, j, port_id, k, ch_mask_temp;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007221 u8 val;
7222
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307223 for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) {
7224 slimbus_value = wcd9xxx_interface_reg_read(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007225 TABLA_SLIM_PGD_PORT_INT_STATUS0 + i);
7226 for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) {
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307227 val = wcd9xxx_interface_reg_read(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007228 TABLA_SLIM_PGD_PORT_INT_SOURCE0 + i*8 + j);
7229 if (val & 0x1)
7230 pr_err_ratelimited("overflow error on port %x,"
7231 " value %x\n", i*8 + j, val);
7232 if (val & 0x2)
7233 pr_err_ratelimited("underflow error on port %x,"
7234 " value %x\n", i*8 + j, val);
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07007235 if (val & 0x4) {
7236 pr_debug("%s: port %x disconnect value %x\n",
7237 __func__, i*8 + j, val);
7238 port_id = i*8 + j;
7239 for (k = 0; k < ARRAY_SIZE(tabla_dai); k++) {
7240 ch_mask_temp = 1 << port_id;
7241 if (ch_mask_temp &
7242 tabla_p->dai[k].ch_mask) {
7243 tabla_p->dai[k].ch_mask &=
7244 ~ch_mask_temp;
7245 if (!tabla_p->dai[k].ch_mask)
7246 wake_up(
7247 &tabla_p->dai[k].dai_wait);
7248 }
7249 }
7250 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007251 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307252 wcd9xxx_interface_reg_write(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007253 TABLA_SLIM_PGD_PORT_INT_CLR0 + i, 0xFF);
7254 }
7255
7256 return IRQ_HANDLED;
7257}
7258
Patrick Lai3043fba2011-08-01 14:15:57 -07007259static int tabla_handle_pdata(struct tabla_priv *tabla)
7260{
7261 struct snd_soc_codec *codec = tabla->codec;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307262 struct wcd9xxx_pdata *pdata = tabla->pdata;
Patrick Lai3043fba2011-08-01 14:15:57 -07007263 int k1, k2, k3, rc = 0;
Santosh Mardi22920282011-10-26 02:38:40 +05307264 u8 leg_mode = pdata->amic_settings.legacy_mode;
7265 u8 txfe_bypass = pdata->amic_settings.txfe_enable;
7266 u8 txfe_buff = pdata->amic_settings.txfe_buff;
7267 u8 flag = pdata->amic_settings.use_pdata;
7268 u8 i = 0, j = 0;
7269 u8 val_txfe = 0, value = 0;
Patrick Lai3043fba2011-08-01 14:15:57 -07007270
7271 if (!pdata) {
7272 rc = -ENODEV;
7273 goto done;
7274 }
7275
7276 /* Make sure settings are correct */
7277 if ((pdata->micbias.ldoh_v > TABLA_LDOH_2P85_V) ||
7278 (pdata->micbias.bias1_cfilt_sel > TABLA_CFILT3_SEL) ||
7279 (pdata->micbias.bias2_cfilt_sel > TABLA_CFILT3_SEL) ||
7280 (pdata->micbias.bias3_cfilt_sel > TABLA_CFILT3_SEL) ||
7281 (pdata->micbias.bias4_cfilt_sel > TABLA_CFILT3_SEL)) {
7282 rc = -EINVAL;
7283 goto done;
7284 }
7285
7286 /* figure out k value */
7287 k1 = tabla_find_k_value(pdata->micbias.ldoh_v,
7288 pdata->micbias.cfilt1_mv);
7289 k2 = tabla_find_k_value(pdata->micbias.ldoh_v,
7290 pdata->micbias.cfilt2_mv);
7291 k3 = tabla_find_k_value(pdata->micbias.ldoh_v,
7292 pdata->micbias.cfilt3_mv);
7293
7294 if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) {
7295 rc = -EINVAL;
7296 goto done;
7297 }
7298
7299 /* Set voltage level and always use LDO */
7300 snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x0C,
7301 (pdata->micbias.ldoh_v << 2));
7302
7303 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_1_VAL, 0xFC,
7304 (k1 << 2));
7305 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_2_VAL, 0xFC,
7306 (k2 << 2));
7307 snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_3_VAL, 0xFC,
7308 (k3 << 2));
7309
7310 snd_soc_update_bits(codec, TABLA_A_MICB_1_CTL, 0x60,
7311 (pdata->micbias.bias1_cfilt_sel << 5));
7312 snd_soc_update_bits(codec, TABLA_A_MICB_2_CTL, 0x60,
7313 (pdata->micbias.bias2_cfilt_sel << 5));
7314 snd_soc_update_bits(codec, TABLA_A_MICB_3_CTL, 0x60,
7315 (pdata->micbias.bias3_cfilt_sel << 5));
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007316 snd_soc_update_bits(codec, tabla->reg_addr.micb_4_ctl, 0x60,
7317 (pdata->micbias.bias4_cfilt_sel << 5));
Patrick Lai3043fba2011-08-01 14:15:57 -07007318
Santosh Mardi22920282011-10-26 02:38:40 +05307319 for (i = 0; i < 6; j++, i += 2) {
7320 if (flag & (0x01 << i)) {
7321 value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00;
7322 val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00;
7323 val_txfe = val_txfe |
7324 ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00);
7325 snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10,
7326 0x10, value);
7327 snd_soc_update_bits(codec,
7328 TABLA_A_TX_1_2_TEST_EN + j * 10,
7329 0x30, val_txfe);
7330 }
7331 if (flag & (0x01 << (i + 1))) {
7332 value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00;
7333 val_txfe = (txfe_bypass &
7334 (0x01 << (i + 1))) ? 0x02 : 0x00;
7335 val_txfe |= (txfe_buff &
7336 (0x01 << (i + 1))) ? 0x01 : 0x00;
7337 snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10,
7338 0x01, value);
7339 snd_soc_update_bits(codec,
7340 TABLA_A_TX_1_2_TEST_EN + j * 10,
7341 0x03, val_txfe);
7342 }
7343 }
7344 if (flag & 0x40) {
7345 value = (leg_mode & 0x40) ? 0x10 : 0x00;
7346 value = value | ((txfe_bypass & 0x40) ? 0x02 : 0x00);
7347 value = value | ((txfe_buff & 0x40) ? 0x01 : 0x00);
7348 snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN,
7349 0x13, value);
7350 }
Patrick Lai49efeac2011-11-03 11:01:12 -07007351
7352 if (pdata->ocp.use_pdata) {
7353 /* not defined in CODEC specification */
7354 if (pdata->ocp.hph_ocp_limit == 1 ||
7355 pdata->ocp.hph_ocp_limit == 5) {
7356 rc = -EINVAL;
7357 goto done;
7358 }
7359 snd_soc_update_bits(codec, TABLA_A_RX_COM_OCP_CTL,
7360 0x0F, pdata->ocp.num_attempts);
7361 snd_soc_write(codec, TABLA_A_RX_COM_OCP_COUNT,
7362 ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time));
7363 snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL,
7364 0xE0, (pdata->ocp.hph_ocp_limit << 5));
7365 }
Joonwoo Park03324832012-03-19 19:36:16 -07007366
7367 for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
7368 if (!strncmp(pdata->regulator[i].name, "CDC_VDDA_RX", 11)) {
7369 if (pdata->regulator[i].min_uV == 1800000 &&
7370 pdata->regulator[i].max_uV == 1800000) {
7371 snd_soc_write(codec, TABLA_A_BIAS_REF_CTL,
7372 0x1C);
7373 } else if (pdata->regulator[i].min_uV == 2200000 &&
7374 pdata->regulator[i].max_uV == 2200000) {
7375 snd_soc_write(codec, TABLA_A_BIAS_REF_CTL,
7376 0x1E);
7377 } else {
7378 pr_err("%s: unsupported CDC_VDDA_RX voltage "
7379 "min %d, max %d\n", __func__,
7380 pdata->regulator[i].min_uV,
7381 pdata->regulator[i].max_uV);
7382 rc = -EINVAL;
7383 }
7384 break;
7385 }
7386 }
Patrick Lai3043fba2011-08-01 14:15:57 -07007387done:
7388 return rc;
7389}
7390
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007391static const struct tabla_reg_mask_val tabla_1_1_reg_defaults[] = {
7392
7393 /* Tabla 1.1 MICBIAS changes */
7394 TABLA_REG_VAL(TABLA_A_MICB_1_INT_RBIAS, 0x24),
7395 TABLA_REG_VAL(TABLA_A_MICB_2_INT_RBIAS, 0x24),
7396 TABLA_REG_VAL(TABLA_A_MICB_3_INT_RBIAS, 0x24),
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007397
7398 /* Tabla 1.1 HPH changes */
7399 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_PA, 0x57),
7400 TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_LDO, 0x56),
7401
7402 /* Tabla 1.1 EAR PA changes */
7403 TABLA_REG_VAL(TABLA_A_RX_EAR_BIAS_PA, 0xA6),
7404 TABLA_REG_VAL(TABLA_A_RX_EAR_GAIN, 0x02),
7405 TABLA_REG_VAL(TABLA_A_RX_EAR_VCM, 0x03),
7406
7407 /* Tabla 1.1 Lineout_5 Changes */
7408 TABLA_REG_VAL(TABLA_A_RX_LINE_5_GAIN, 0x10),
7409
7410 /* Tabla 1.1 RX Changes */
7411 TABLA_REG_VAL(TABLA_A_CDC_RX1_B5_CTL, 0x78),
7412 TABLA_REG_VAL(TABLA_A_CDC_RX2_B5_CTL, 0x78),
7413 TABLA_REG_VAL(TABLA_A_CDC_RX3_B5_CTL, 0x78),
7414 TABLA_REG_VAL(TABLA_A_CDC_RX4_B5_CTL, 0x78),
7415 TABLA_REG_VAL(TABLA_A_CDC_RX5_B5_CTL, 0x78),
7416 TABLA_REG_VAL(TABLA_A_CDC_RX6_B5_CTL, 0x78),
7417 TABLA_REG_VAL(TABLA_A_CDC_RX7_B5_CTL, 0x78),
7418
7419 /* Tabla 1.1 RX1 and RX2 Changes */
7420 TABLA_REG_VAL(TABLA_A_CDC_RX1_B6_CTL, 0xA0),
7421 TABLA_REG_VAL(TABLA_A_CDC_RX2_B6_CTL, 0xA0),
7422
7423 /* Tabla 1.1 RX3 to RX7 Changes */
7424 TABLA_REG_VAL(TABLA_A_CDC_RX3_B6_CTL, 0x80),
7425 TABLA_REG_VAL(TABLA_A_CDC_RX4_B6_CTL, 0x80),
7426 TABLA_REG_VAL(TABLA_A_CDC_RX5_B6_CTL, 0x80),
7427 TABLA_REG_VAL(TABLA_A_CDC_RX6_B6_CTL, 0x80),
7428 TABLA_REG_VAL(TABLA_A_CDC_RX7_B6_CTL, 0x80),
7429
7430 /* Tabla 1.1 CLASSG Changes */
7431 TABLA_REG_VAL(TABLA_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B),
7432};
7433
7434static const struct tabla_reg_mask_val tabla_2_0_reg_defaults[] = {
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007435 /* Tabla 2.0 MICBIAS changes */
7436 TABLA_REG_VAL(TABLA_A_MICB_2_MBHC, 0x02),
7437};
7438
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007439static const struct tabla_reg_mask_val tabla_1_x_only_reg_2_0_defaults[] = {
7440 TABLA_REG_VAL(TABLA_1_A_MICB_4_INT_RBIAS, 0x24),
7441};
7442
7443static const struct tabla_reg_mask_val tabla_2_only_reg_2_0_defaults[] = {
7444 TABLA_REG_VAL(TABLA_2_A_MICB_4_INT_RBIAS, 0x24),
7445};
7446
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007447static void tabla_update_reg_defaults(struct snd_soc_codec *codec)
7448{
7449 u32 i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307450 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007451
7452 for (i = 0; i < ARRAY_SIZE(tabla_1_1_reg_defaults); i++)
7453 snd_soc_write(codec, tabla_1_1_reg_defaults[i].reg,
7454 tabla_1_1_reg_defaults[i].val);
7455
7456 for (i = 0; i < ARRAY_SIZE(tabla_2_0_reg_defaults); i++)
7457 snd_soc_write(codec, tabla_2_0_reg_defaults[i].reg,
7458 tabla_2_0_reg_defaults[i].val);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007459
7460 if (TABLA_IS_1_X(tabla_core->version)) {
7461 for (i = 0; i < ARRAY_SIZE(tabla_1_x_only_reg_2_0_defaults);
7462 i++)
7463 snd_soc_write(codec,
7464 tabla_1_x_only_reg_2_0_defaults[i].reg,
7465 tabla_1_x_only_reg_2_0_defaults[i].val);
7466 } else {
7467 for (i = 0; i < ARRAY_SIZE(tabla_2_only_reg_2_0_defaults); i++)
7468 snd_soc_write(codec,
7469 tabla_2_only_reg_2_0_defaults[i].reg,
7470 tabla_2_only_reg_2_0_defaults[i].val);
7471 }
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007472}
7473
7474static const struct tabla_reg_mask_val tabla_codec_reg_init_val[] = {
Patrick Laic7cae882011-11-18 11:52:49 -08007475 /* Initialize current threshold to 350MA
7476 * number of wait and run cycles to 4096
7477 */
Patrick Lai49efeac2011-11-03 11:01:12 -07007478 {TABLA_A_RX_HPH_OCP_CTL, 0xE0, 0x60},
Patrick Laic7cae882011-11-18 11:52:49 -08007479 {TABLA_A_RX_COM_OCP_COUNT, 0xFF, 0xFF},
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007480
Santosh Mardi32171012011-10-28 23:32:06 +05307481 {TABLA_A_QFUSE_CTL, 0xFF, 0x03},
7482
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007483 /* Initialize gain registers to use register gain */
7484 {TABLA_A_RX_HPH_L_GAIN, 0x10, 0x10},
7485 {TABLA_A_RX_HPH_R_GAIN, 0x10, 0x10},
7486 {TABLA_A_RX_LINE_1_GAIN, 0x10, 0x10},
7487 {TABLA_A_RX_LINE_2_GAIN, 0x10, 0x10},
7488 {TABLA_A_RX_LINE_3_GAIN, 0x10, 0x10},
7489 {TABLA_A_RX_LINE_4_GAIN, 0x10, 0x10},
7490
7491 /* Initialize mic biases to differential mode */
7492 {TABLA_A_MICB_1_INT_RBIAS, 0x24, 0x24},
7493 {TABLA_A_MICB_2_INT_RBIAS, 0x24, 0x24},
7494 {TABLA_A_MICB_3_INT_RBIAS, 0x24, 0x24},
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007495
7496 {TABLA_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14},
7497
7498 /* Use 16 bit sample size for TX1 to TX6 */
7499 {TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20},
7500 {TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20},
7501 {TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20},
7502 {TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20},
7503 {TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20},
7504 {TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0x30, 0x20},
7505
7506 /* Use 16 bit sample size for TX7 to TX10 */
7507 {TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0x60, 0x40},
7508 {TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0x60, 0x40},
7509 {TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0x60, 0x40},
7510 {TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0x60, 0x40},
7511
7512 /* Use 16 bit sample size for RX */
7513 {TABLA_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA},
7514 {TABLA_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0xAA},
7515
7516 /*enable HPF filter for TX paths */
7517 {TABLA_A_CDC_TX1_MUX_CTL, 0x8, 0x0},
7518 {TABLA_A_CDC_TX2_MUX_CTL, 0x8, 0x0},
7519 {TABLA_A_CDC_TX3_MUX_CTL, 0x8, 0x0},
7520 {TABLA_A_CDC_TX4_MUX_CTL, 0x8, 0x0},
7521 {TABLA_A_CDC_TX5_MUX_CTL, 0x8, 0x0},
7522 {TABLA_A_CDC_TX6_MUX_CTL, 0x8, 0x0},
7523 {TABLA_A_CDC_TX7_MUX_CTL, 0x8, 0x0},
7524 {TABLA_A_CDC_TX8_MUX_CTL, 0x8, 0x0},
7525 {TABLA_A_CDC_TX9_MUX_CTL, 0x8, 0x0},
7526 {TABLA_A_CDC_TX10_MUX_CTL, 0x8, 0x0},
Kiran Kandi0ba468f2012-05-08 11:45:05 -07007527
7528 /* config Decimator for DMIC CLK_MODE_1(3.072Mhz@12.88Mhz mclk) */
7529 {TABLA_A_CDC_TX1_DMIC_CTL, 0x1, 0x1},
7530 {TABLA_A_CDC_TX2_DMIC_CTL, 0x1, 0x1},
7531 {TABLA_A_CDC_TX3_DMIC_CTL, 0x1, 0x1},
7532 {TABLA_A_CDC_TX4_DMIC_CTL, 0x1, 0x1},
7533 {TABLA_A_CDC_TX5_DMIC_CTL, 0x1, 0x1},
7534 {TABLA_A_CDC_TX6_DMIC_CTL, 0x1, 0x1},
7535 {TABLA_A_CDC_TX7_DMIC_CTL, 0x1, 0x1},
7536 {TABLA_A_CDC_TX8_DMIC_CTL, 0x1, 0x1},
7537 {TABLA_A_CDC_TX9_DMIC_CTL, 0x1, 0x1},
7538 {TABLA_A_CDC_TX10_DMIC_CTL, 0x1, 0x1},
7539
7540 /* config DMIC clk to CLK_MODE_1 (3.072Mhz@12.88Mhz mclk) */
7541 {TABLA_A_CDC_CLK_DMIC_CTL, 0x2A, 0x2A},
7542
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007543};
7544
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007545static const struct tabla_reg_mask_val tabla_1_x_codec_reg_init_val[] = {
7546 /* Initialize mic biases to differential mode */
7547 {TABLA_1_A_MICB_4_INT_RBIAS, 0x24, 0x24},
7548};
7549
7550static const struct tabla_reg_mask_val tabla_2_higher_codec_reg_init_val[] = {
7551 /* Initialize mic biases to differential mode */
7552 {TABLA_2_A_MICB_4_INT_RBIAS, 0x24, 0x24},
7553};
7554
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007555static void tabla_codec_init_reg(struct snd_soc_codec *codec)
7556{
7557 u32 i;
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307558 struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent);
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007559
7560 for (i = 0; i < ARRAY_SIZE(tabla_codec_reg_init_val); i++)
7561 snd_soc_update_bits(codec, tabla_codec_reg_init_val[i].reg,
7562 tabla_codec_reg_init_val[i].mask,
7563 tabla_codec_reg_init_val[i].val);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007564 if (TABLA_IS_1_X(tabla_core->version)) {
7565 for (i = 0; i < ARRAY_SIZE(tabla_1_x_codec_reg_init_val); i++)
7566 snd_soc_update_bits(codec,
7567 tabla_1_x_codec_reg_init_val[i].reg,
7568 tabla_1_x_codec_reg_init_val[i].mask,
7569 tabla_1_x_codec_reg_init_val[i].val);
7570 } else {
7571 for (i = 0; i < ARRAY_SIZE(tabla_2_higher_codec_reg_init_val);
7572 i++)
7573 snd_soc_update_bits(codec,
7574 tabla_2_higher_codec_reg_init_val[i].reg,
7575 tabla_2_higher_codec_reg_init_val[i].mask,
7576 tabla_2_higher_codec_reg_init_val[i].val);
7577 }
7578}
7579
7580static void tabla_update_reg_address(struct tabla_priv *priv)
7581{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307582 struct wcd9xxx *tabla_core = dev_get_drvdata(priv->codec->dev->parent);
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007583 struct tabla_reg_address *reg_addr = &priv->reg_addr;
7584
7585 if (TABLA_IS_1_X(tabla_core->version)) {
Joonwoo Parkcb7c8922012-02-16 23:12:59 -08007586 reg_addr->micb_4_mbhc = TABLA_1_A_MICB_4_MBHC;
7587 reg_addr->micb_4_int_rbias = TABLA_1_A_MICB_4_INT_RBIAS;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007588 reg_addr->micb_4_ctl = TABLA_1_A_MICB_4_CTL;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007589 } else if (TABLA_IS_2_0(tabla_core->version)) {
Joonwoo Parkcb7c8922012-02-16 23:12:59 -08007590 reg_addr->micb_4_mbhc = TABLA_2_A_MICB_4_MBHC;
7591 reg_addr->micb_4_int_rbias = TABLA_2_A_MICB_4_INT_RBIAS;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007592 reg_addr->micb_4_ctl = TABLA_2_A_MICB_4_CTL;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007593 }
Kiran Kandi1f6fd722011-08-11 10:36:11 -07007594}
7595
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007596#ifdef CONFIG_DEBUG_FS
7597static int codec_debug_open(struct inode *inode, struct file *file)
7598{
7599 file->private_data = inode->i_private;
7600 return 0;
7601}
7602
7603static ssize_t codec_debug_write(struct file *filp,
7604 const char __user *ubuf, size_t cnt, loff_t *ppos)
7605{
7606 char lbuf[32];
7607 char *buf;
7608 int rc;
7609 struct tabla_priv *tabla = filp->private_data;
7610
7611 if (cnt > sizeof(lbuf) - 1)
7612 return -EINVAL;
7613
7614 rc = copy_from_user(lbuf, ubuf, cnt);
7615 if (rc)
7616 return -EFAULT;
7617
7618 lbuf[cnt] = '\0';
7619 buf = (char *)lbuf;
7620 tabla->no_mic_headset_override = (*strsep(&buf, " ") == '0') ?
7621 false : true;
7622 return rc;
7623}
7624
7625static ssize_t codec_mbhc_debug_read(struct file *file, char __user *buf,
7626 size_t count, loff_t *pos)
7627{
7628 const int size = 768;
7629 char buffer[size];
7630 int n = 0;
7631 struct tabla_priv *tabla = file->private_data;
7632 struct snd_soc_codec *codec = tabla->codec;
7633 const struct mbhc_internal_cal_data *p = &tabla->mbhc_data;
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007634 const s16 v_ins_hu_cur = tabla_get_current_v_ins(tabla, true);
7635 const s16 v_ins_h_cur = tabla_get_current_v_ins(tabla, false);
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007636
7637 n = scnprintf(buffer, size - n, "dce_z = %x(%dmv)\n", p->dce_z,
7638 tabla_codec_sta_dce_v(codec, 1, p->dce_z));
7639 n += scnprintf(buffer + n, size - n, "dce_mb = %x(%dmv)\n",
7640 p->dce_mb, tabla_codec_sta_dce_v(codec, 1, p->dce_mb));
7641 n += scnprintf(buffer + n, size - n, "sta_z = %x(%dmv)\n",
7642 p->sta_z, tabla_codec_sta_dce_v(codec, 0, p->sta_z));
7643 n += scnprintf(buffer + n, size - n, "sta_mb = %x(%dmv)\n",
7644 p->sta_mb, tabla_codec_sta_dce_v(codec, 0, p->sta_mb));
7645 n += scnprintf(buffer + n, size - n, "t_dce = %x\n", p->t_dce);
7646 n += scnprintf(buffer + n, size - n, "t_sta = %x\n", p->t_sta);
7647 n += scnprintf(buffer + n, size - n, "micb_mv = %dmv\n",
7648 p->micb_mv);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007649 n += scnprintf(buffer + n, size - n, "v_ins_hu = %x(%dmv)%s\n",
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007650 p->v_ins_hu,
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007651 tabla_codec_sta_dce_v(codec, 0, p->v_ins_hu),
7652 p->v_ins_hu == v_ins_hu_cur ? "*" : "");
7653 n += scnprintf(buffer + n, size - n, "v_ins_h = %x(%dmv)%s\n",
7654 p->v_ins_h, tabla_codec_sta_dce_v(codec, 1, p->v_ins_h),
7655 p->v_ins_h == v_ins_h_cur ? "*" : "");
7656 n += scnprintf(buffer + n, size - n, "adj_v_ins_hu = %x(%dmv)%s\n",
7657 p->adj_v_ins_hu,
7658 tabla_codec_sta_dce_v(codec, 0, p->adj_v_ins_hu),
7659 p->adj_v_ins_hu == v_ins_hu_cur ? "*" : "");
7660 n += scnprintf(buffer + n, size - n, "adj_v_ins_h = %x(%dmv)%s\n",
7661 p->adj_v_ins_h,
7662 tabla_codec_sta_dce_v(codec, 1, p->adj_v_ins_h),
7663 p->adj_v_ins_h == v_ins_h_cur ? "*" : "");
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007664 n += scnprintf(buffer + n, size - n, "v_b1_hu = %x(%dmv)\n",
7665 p->v_b1_hu, tabla_codec_sta_dce_v(codec, 0, p->v_b1_hu));
7666 n += scnprintf(buffer + n, size - n, "v_b1_h = %x(%dmv)\n",
7667 p->v_b1_h, tabla_codec_sta_dce_v(codec, 1, p->v_b1_h));
7668 n += scnprintf(buffer + n, size - n, "v_b1_huc = %x(%dmv)\n",
7669 p->v_b1_huc,
7670 tabla_codec_sta_dce_v(codec, 1, p->v_b1_huc));
7671 n += scnprintf(buffer + n, size - n, "v_brh = %x(%dmv)\n",
7672 p->v_brh, tabla_codec_sta_dce_v(codec, 1, p->v_brh));
7673 n += scnprintf(buffer + n, size - n, "v_brl = %x(%dmv)\n", p->v_brl,
7674 tabla_codec_sta_dce_v(codec, 0, p->v_brl));
7675 n += scnprintf(buffer + n, size - n, "v_no_mic = %x(%dmv)\n",
7676 p->v_no_mic,
7677 tabla_codec_sta_dce_v(codec, 0, p->v_no_mic));
7678 n += scnprintf(buffer + n, size - n, "npoll = %d\n", p->npoll);
7679 n += scnprintf(buffer + n, size - n, "nbounce_wait = %d\n",
7680 p->nbounce_wait);
Joonwoo Parkcf473b42012-03-29 19:48:16 -07007681 n += scnprintf(buffer + n, size - n, "v_inval_ins_low = %d\n",
7682 p->v_inval_ins_low);
7683 n += scnprintf(buffer + n, size - n, "v_inval_ins_high = %d\n",
7684 p->v_inval_ins_high);
Joonwoo Park2cc13f02012-05-09 12:44:25 -07007685 if (tabla->mbhc_cfg.gpio)
7686 n += scnprintf(buffer + n, size - n, "GPIO insert = %d\n",
7687 tabla_hs_gpio_level_remove(tabla));
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007688 buffer[n] = 0;
7689
7690 return simple_read_from_buffer(buf, count, pos, buffer, n);
7691}
7692
7693static const struct file_operations codec_debug_ops = {
7694 .open = codec_debug_open,
7695 .write = codec_debug_write,
7696};
7697
7698static const struct file_operations codec_mbhc_debug_ops = {
7699 .open = codec_debug_open,
7700 .read = codec_mbhc_debug_read,
7701};
7702#endif
7703
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007704static int tabla_codec_probe(struct snd_soc_codec *codec)
7705{
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307706 struct wcd9xxx *control;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007707 struct tabla_priv *tabla;
7708 struct snd_soc_dapm_context *dapm = &codec->dapm;
7709 int ret = 0;
7710 int i;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08007711 int ch_cnt;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007712
7713 codec->control_data = dev_get_drvdata(codec->dev->parent);
7714 control = codec->control_data;
7715
7716 tabla = kzalloc(sizeof(struct tabla_priv), GFP_KERNEL);
7717 if (!tabla) {
7718 dev_err(codec->dev, "Failed to allocate private data\n");
7719 return -ENOMEM;
7720 }
Kiran Kandid8cf5212012-03-02 15:34:53 -08007721 for (i = 0 ; i < NUM_DECIMATORS; i++) {
7722 tx_hpf_work[i].tabla = tabla;
7723 tx_hpf_work[i].decimator = i + 1;
7724 INIT_DELAYED_WORK(&tx_hpf_work[i].dwork,
7725 tx_hpf_corner_freq_callback);
7726 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007727
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07007728 /* Make sure mbhc micbias register addresses are zeroed out */
7729 memset(&tabla->mbhc_bias_regs, 0,
7730 sizeof(struct mbhc_micbias_regs));
Bhalchandra Gajared9ebb6c2011-10-03 19:54:41 -07007731 tabla->mbhc_micbias_switched = false;
Bhalchandra Gajare02d90cd2011-09-30 16:14:00 -07007732
Joonwoo Park0976d012011-12-22 11:48:18 -08007733 /* Make sure mbhc intenal calibration data is zeroed out */
7734 memset(&tabla->mbhc_data, 0,
7735 sizeof(struct mbhc_internal_cal_data));
Joonwoo Park433149a2012-01-11 09:53:54 -08007736 tabla->mbhc_data.t_sta_dce = DEFAULT_DCE_STA_WAIT;
Joonwoo Park0976d012011-12-22 11:48:18 -08007737 tabla->mbhc_data.t_dce = DEFAULT_DCE_WAIT;
7738 tabla->mbhc_data.t_sta = DEFAULT_STA_WAIT;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007739 snd_soc_codec_set_drvdata(codec, tabla);
7740
Kiran Kandi6fae8bf2011-08-15 10:36:42 -07007741 tabla->mclk_enabled = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007742 tabla->bandgap_type = TABLA_BANDGAP_OFF;
7743 tabla->clock_active = false;
7744 tabla->config_mode_active = false;
7745 tabla->mbhc_polling_active = false;
Joonwoo Parkf4267c22012-01-10 13:25:24 -08007746 tabla->mbhc_fake_ins_start = 0;
Bradley Rubincb3950a2011-08-18 13:07:26 -07007747 tabla->no_mic_headset_override = false;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007748 tabla->hs_polling_irq_prepared = false;
7749 mutex_init(&tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007750 tabla->codec = codec;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007751 tabla->mbhc_state = MBHC_STATE_NONE;
Joonwoo Park03324832012-03-19 19:36:16 -07007752 tabla->mbhc_last_resume = 0;
Kuirong Wang0f8ade32012-02-27 16:29:45 -08007753 for (i = 0; i < COMPANDER_MAX; i++) {
7754 tabla->comp_enabled[i] = 0;
7755 tabla->comp_fs[i] = COMPANDER_FS_48KHZ;
7756 }
Patrick Lai3043fba2011-08-01 14:15:57 -07007757 tabla->pdata = dev_get_platdata(codec->dev->parent);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307758 tabla->intf_type = wcd9xxx_get_intf_type();
Bhalchandra Gajareb0f15132012-02-07 15:00:21 -08007759 tabla->aux_pga_cnt = 0;
7760 tabla->aux_l_gain = 0x1F;
7761 tabla->aux_r_gain = 0x1F;
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007762 tabla_update_reg_address(tabla);
Santosh Mardi22920282011-10-26 02:38:40 +05307763 tabla_update_reg_defaults(codec);
7764 tabla_codec_init_reg(codec);
Santosh Mardi22920282011-10-26 02:38:40 +05307765 ret = tabla_handle_pdata(tabla);
Patrick Lai3043fba2011-08-01 14:15:57 -07007766 if (IS_ERR_VALUE(ret)) {
7767 pr_err("%s: bad pdata\n", __func__);
7768 goto err_pdata;
7769 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007770
Steve Mucklef132c6c2012-06-06 18:30:57 -07007771// snd_soc_add_codec_controls(codec, tabla_snd_controls,
7772// ARRAY_SIZE(tabla_snd_controls));
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007773 if (TABLA_IS_1_X(control->version))
Steve Mucklef132c6c2012-06-06 18:30:57 -07007774 snd_soc_add_codec_controls(codec, tabla_1_x_snd_controls,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007775 ARRAY_SIZE(tabla_1_x_snd_controls));
7776 else
Steve Mucklef132c6c2012-06-06 18:30:57 -07007777 snd_soc_add_codec_controls(codec, tabla_2_higher_snd_controls,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007778 ARRAY_SIZE(tabla_2_higher_snd_controls));
7779
Steve Mucklef132c6c2012-06-06 18:30:57 -07007780// snd_soc_dapm_new_controls(dapm, tabla_dapm_widgets,
7781// ARRAY_SIZE(tabla_dapm_widgets));
Kiran Kandi93923902012-06-20 17:00:25 -07007782
7783 snd_soc_dapm_new_controls(dapm, tabla_dapm_aif_in_widgets,
7784 ARRAY_SIZE(tabla_dapm_aif_in_widgets));
7785
7786 snd_soc_dapm_new_controls(dapm, tabla_dapm_aif_out_widgets,
7787 ARRAY_SIZE(tabla_dapm_aif_out_widgets));
7788
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007789 if (TABLA_IS_1_X(control->version))
7790 snd_soc_dapm_new_controls(dapm, tabla_1_x_dapm_widgets,
7791 ARRAY_SIZE(tabla_1_x_dapm_widgets));
7792 else
7793 snd_soc_dapm_new_controls(dapm, tabla_2_higher_dapm_widgets,
7794 ARRAY_SIZE(tabla_2_higher_dapm_widgets));
7795
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307796 if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Santosh Mardie15e2302011-11-15 10:39:23 +05307797 snd_soc_dapm_new_controls(dapm, tabla_dapm_i2s_widgets,
7798 ARRAY_SIZE(tabla_dapm_i2s_widgets));
7799 snd_soc_dapm_add_routes(dapm, audio_i2s_map,
7800 ARRAY_SIZE(audio_i2s_map));
7801 }
Steve Mucklef132c6c2012-06-06 18:30:57 -07007802// snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
Kiran Kandi8b3a8302011-09-27 16:13:28 -07007803
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007804 if (TABLA_IS_1_X(control->version)) {
Kiran Kandi7a9fd902011-11-14 13:51:45 -08007805 snd_soc_dapm_add_routes(dapm, tabla_1_x_lineout_2_to_4_map,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007806 ARRAY_SIZE(tabla_1_x_lineout_2_to_4_map));
7807 } else if (TABLA_IS_2_0(control->version)) {
Kiran Kandi7a9fd902011-11-14 13:51:45 -08007808 snd_soc_dapm_add_routes(dapm, tabla_2_x_lineout_2_to_4_map,
Joonwoo Park6c1ebb62012-01-16 19:08:43 -08007809 ARRAY_SIZE(tabla_2_x_lineout_2_to_4_map));
Kiran Kandi7a9fd902011-11-14 13:51:45 -08007810 } else {
7811 pr_err("%s : ERROR. Unsupported Tabla version 0x%2x\n",
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307812 __func__, control->version);
Kiran Kandi7a9fd902011-11-14 13:51:45 -08007813 goto err_pdata;
7814 }
7815
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007816 snd_soc_dapm_sync(dapm);
7817
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307818 ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007819 tabla_hs_insert_irq, "Headset insert detect", tabla);
7820 if (ret) {
7821 pr_err("%s: Failed to request irq %d\n", __func__,
7822 TABLA_IRQ_MBHC_INSERTION);
7823 goto err_insert_irq;
7824 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307825 wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007826
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307827 ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007828 tabla_hs_remove_irq, "Headset remove detect", tabla);
7829 if (ret) {
7830 pr_err("%s: Failed to request irq %d\n", __func__,
7831 TABLA_IRQ_MBHC_REMOVAL);
7832 goto err_remove_irq;
7833 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007834
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307835 ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL,
Bradley Rubincb1e2732011-06-23 16:49:20 -07007836 tabla_dce_handler, "DC Estimation detect", tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007837 if (ret) {
7838 pr_err("%s: Failed to request irq %d\n", __func__,
7839 TABLA_IRQ_MBHC_POTENTIAL);
7840 goto err_potential_irq;
7841 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007842
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307843 ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE,
Bradley Rubincb1e2732011-06-23 16:49:20 -07007844 tabla_release_handler, "Button Release detect", tabla);
7845 if (ret) {
7846 pr_err("%s: Failed to request irq %d\n", __func__,
7847 TABLA_IRQ_MBHC_RELEASE);
7848 goto err_release_irq;
7849 }
7850
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307851 ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_SLIMBUS,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007852 tabla_slimbus_irq, "SLIMBUS Slave", tabla);
7853 if (ret) {
7854 pr_err("%s: Failed to request irq %d\n", __func__,
7855 TABLA_IRQ_SLIMBUS);
7856 goto err_slimbus_irq;
7857 }
7858
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307859 for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++)
7860 wcd9xxx_interface_reg_write(codec->control_data,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007861 TABLA_SLIM_PGD_PORT_INT_EN0 + i, 0xFF);
7862
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307863 ret = wcd9xxx_request_irq(codec->control_data,
Patrick Lai49efeac2011-11-03 11:01:12 -07007864 TABLA_IRQ_HPH_PA_OCPL_FAULT, tabla_hphl_ocp_irq,
7865 "HPH_L OCP detect", tabla);
7866 if (ret) {
7867 pr_err("%s: Failed to request irq %d\n", __func__,
7868 TABLA_IRQ_HPH_PA_OCPL_FAULT);
7869 goto err_hphl_ocp_irq;
7870 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307871 wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_HPH_PA_OCPL_FAULT);
Patrick Lai49efeac2011-11-03 11:01:12 -07007872
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307873 ret = wcd9xxx_request_irq(codec->control_data,
Patrick Lai49efeac2011-11-03 11:01:12 -07007874 TABLA_IRQ_HPH_PA_OCPR_FAULT, tabla_hphr_ocp_irq,
7875 "HPH_R OCP detect", tabla);
7876 if (ret) {
7877 pr_err("%s: Failed to request irq %d\n", __func__,
7878 TABLA_IRQ_HPH_PA_OCPR_FAULT);
7879 goto err_hphr_ocp_irq;
7880 }
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307881 wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_HPH_PA_OCPR_FAULT);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08007882 for (i = 0; i < ARRAY_SIZE(tabla_dai); i++) {
7883 switch (tabla_dai[i].id) {
7884 case AIF1_PB:
7885 ch_cnt = tabla_dai[i].playback.channels_max;
7886 break;
7887 case AIF1_CAP:
7888 ch_cnt = tabla_dai[i].capture.channels_max;
7889 break;
Neema Shettyd3a89262012-02-16 10:23:50 -08007890 case AIF2_PB:
7891 ch_cnt = tabla_dai[i].playback.channels_max;
7892 break;
Kiran Kandi1e6371d2012-03-29 11:48:57 -07007893 case AIF2_CAP:
7894 ch_cnt = tabla_dai[i].capture.channels_max;
7895 break;
Kiran Kandia9fffe92012-05-20 23:42:30 -07007896 case AIF3_PB:
7897 ch_cnt = tabla_dai[i].playback.channels_max;
7898 break;
Neema Shetty3fb1b802012-04-27 13:53:24 -07007899 case AIF3_CAP:
7900 ch_cnt = tabla_dai[i].capture.channels_max;
7901 break;
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08007902 default:
7903 continue;
7904 }
7905 tabla->dai[i].ch_num = kzalloc((sizeof(unsigned int)*
7906 ch_cnt), GFP_KERNEL);
Swaminathan Sathappan2aa4c042012-06-26 13:08:45 -07007907 init_waitqueue_head(&tabla->dai[i].dai_wait);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08007908 }
Patrick Lai49efeac2011-11-03 11:01:12 -07007909
Bradley Rubincb3950a2011-08-18 13:07:26 -07007910#ifdef CONFIG_DEBUG_FS
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007911 if (ret == 0) {
7912 tabla->debugfs_poke =
7913 debugfs_create_file("TRRS", S_IFREG | S_IRUGO, NULL, tabla,
7914 &codec_debug_ops);
7915 tabla->debugfs_mbhc =
7916 debugfs_create_file("tabla_mbhc", S_IFREG | S_IRUGO,
7917 NULL, tabla, &codec_mbhc_debug_ops);
7918 }
Bradley Rubincb3950a2011-08-18 13:07:26 -07007919#endif
Steve Mucklef132c6c2012-06-06 18:30:57 -07007920 codec->ignore_pmdown_time = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007921 return ret;
7922
Patrick Lai49efeac2011-11-03 11:01:12 -07007923err_hphr_ocp_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307924 wcd9xxx_free_irq(codec->control_data,
7925 TABLA_IRQ_HPH_PA_OCPL_FAULT, tabla);
Patrick Lai49efeac2011-11-03 11:01:12 -07007926err_hphl_ocp_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307927 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_SLIMBUS, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007928err_slimbus_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307929 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, tabla);
Bradley Rubincb1e2732011-06-23 16:49:20 -07007930err_release_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307931 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007932err_potential_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307933 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007934err_remove_irq:
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307935 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, tabla);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007936err_insert_irq:
Patrick Lai3043fba2011-08-01 14:15:57 -07007937err_pdata:
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007938 mutex_destroy(&tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007939 kfree(tabla);
7940 return ret;
7941}
7942static int tabla_codec_remove(struct snd_soc_codec *codec)
7943{
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08007944 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007945 struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec);
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05307946 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_SLIMBUS, tabla);
7947 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, tabla);
7948 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, tabla);
7949 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, tabla);
7950 wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, tabla);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007951 TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007952 tabla_codec_disable_clock_block(codec);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007953 TABLA_RELEASE_LOCK(tabla->codec_resource_lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007954 tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF);
Patrick Lai64b43262011-12-06 17:29:15 -08007955 if (tabla->mbhc_fw)
7956 release_firmware(tabla->mbhc_fw);
Bharath Ramachandramurthy9c79f132011-11-28 11:18:57 -08007957 for (i = 0; i < ARRAY_SIZE(tabla_dai); i++)
7958 kfree(tabla->dai[i].ch_num);
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -07007959 mutex_destroy(&tabla->codec_resource_lock);
Joonwoo Park179b9ec2012-03-26 10:56:20 -07007960#ifdef CONFIG_DEBUG_FS
7961 debugfs_remove(tabla->debugfs_poke);
7962 debugfs_remove(tabla->debugfs_mbhc);
7963#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007964 kfree(tabla);
7965 return 0;
7966}
7967static struct snd_soc_codec_driver soc_codec_dev_tabla = {
7968 .probe = tabla_codec_probe,
7969 .remove = tabla_codec_remove,
7970 .read = tabla_read,
7971 .write = tabla_write,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007972 .readable_register = tabla_readable,
7973 .volatile_register = tabla_volatile,
7974
7975 .reg_cache_size = TABLA_CACHE_SIZE,
7976 .reg_cache_default = tabla_reg_defaults,
7977 .reg_word_size = 1,
Steve Mucklef132c6c2012-06-06 18:30:57 -07007978 .controls = tabla_snd_controls,
7979 .num_controls = ARRAY_SIZE(tabla_snd_controls),
7980 .dapm_widgets = tabla_dapm_widgets,
7981 .num_dapm_widgets = ARRAY_SIZE(tabla_dapm_widgets),
7982 .dapm_routes = audio_map,
7983 .num_dapm_routes = ARRAY_SIZE(audio_map),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07007984};
Bradley Rubincb3950a2011-08-18 13:07:26 -07007985
Joonwoo Park8b1f0982011-12-08 17:12:45 -08007986#ifdef CONFIG_PM
7987static int tabla_suspend(struct device *dev)
7988{
Joonwoo Park816b8e62012-01-23 16:03:21 -08007989 dev_dbg(dev, "%s: system suspend\n", __func__);
7990 return 0;
Joonwoo Park8b1f0982011-12-08 17:12:45 -08007991}
7992
7993static int tabla_resume(struct device *dev)
7994{
Joonwoo Park03324832012-03-19 19:36:16 -07007995 struct platform_device *pdev = to_platform_device(dev);
7996 struct tabla_priv *tabla = platform_get_drvdata(pdev);
Joonwoo Park816b8e62012-01-23 16:03:21 -08007997 dev_dbg(dev, "%s: system resume\n", __func__);
Joonwoo Park03324832012-03-19 19:36:16 -07007998 tabla->mbhc_last_resume = jiffies;
Joonwoo Park816b8e62012-01-23 16:03:21 -08007999 return 0;
Joonwoo Park8b1f0982011-12-08 17:12:45 -08008000}
8001
8002static const struct dev_pm_ops tabla_pm_ops = {
8003 .suspend = tabla_suspend,
8004 .resume = tabla_resume,
8005};
8006#endif
8007
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008008static int __devinit tabla_probe(struct platform_device *pdev)
8009{
Santosh Mardie15e2302011-11-15 10:39:23 +05308010 int ret = 0;
Steve Mucklef132c6c2012-06-06 18:30:57 -07008011 pr_err("tabla_probe\n");
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308012 if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
Santosh Mardie15e2302011-11-15 10:39:23 +05308013 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla,
8014 tabla_dai, ARRAY_SIZE(tabla_dai));
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +05308015 else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C)
Santosh Mardie15e2302011-11-15 10:39:23 +05308016 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla,
8017 tabla_i2s_dai, ARRAY_SIZE(tabla_i2s_dai));
8018 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008019}
8020static int __devexit tabla_remove(struct platform_device *pdev)
8021{
8022 snd_soc_unregister_codec(&pdev->dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008023 return 0;
8024}
8025static struct platform_driver tabla_codec_driver = {
8026 .probe = tabla_probe,
8027 .remove = tabla_remove,
8028 .driver = {
8029 .name = "tabla_codec",
8030 .owner = THIS_MODULE,
Joonwoo Park8b1f0982011-12-08 17:12:45 -08008031#ifdef CONFIG_PM
8032 .pm = &tabla_pm_ops,
8033#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008034 },
8035};
8036
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08008037static struct platform_driver tabla1x_codec_driver = {
8038 .probe = tabla_probe,
8039 .remove = tabla_remove,
8040 .driver = {
8041 .name = "tabla1x_codec",
8042 .owner = THIS_MODULE,
8043#ifdef CONFIG_PM
8044 .pm = &tabla_pm_ops,
8045#endif
8046 },
8047};
8048
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008049static int __init tabla_codec_init(void)
8050{
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08008051 int rtn = platform_driver_register(&tabla_codec_driver);
8052 if (rtn == 0) {
8053 rtn = platform_driver_register(&tabla1x_codec_driver);
8054 if (rtn != 0)
8055 platform_driver_unregister(&tabla_codec_driver);
8056 }
8057 return rtn;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008058}
8059
8060static void __exit tabla_codec_exit(void)
8061{
Kuirong Wangcd4b6da2012-01-16 22:54:45 -08008062 platform_driver_unregister(&tabla1x_codec_driver);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07008063 platform_driver_unregister(&tabla_codec_driver);
8064}
8065
8066module_init(tabla_codec_init);
8067module_exit(tabla_codec_exit);
8068
8069MODULE_DESCRIPTION("Tabla codec driver");
8070MODULE_VERSION("1.0");
8071MODULE_LICENSE("GPL v2");