blob: 577c1edd673ca3d9eb1ea446c7844e108766462f [file] [log] [blame]
Banajit Goswamieb1fa162013-02-05 15:11:27 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002 *
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>
14#include <linux/firmware.h>
15#include <linux/slab.h>
16#include <linux/platform_device.h>
17#include <linux/device.h>
18#include <linux/printk.h>
19#include <linux/ratelimit.h>
20#include <linux/debugfs.h>
Bhalchandra Gajareea898742013-03-05 18:15:53 -080021#include <linux/wait.h>
22#include <linux/bitops.h>
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -080023#include <linux/mfd/wcd9xxx/core.h>
24#include <linux/mfd/wcd9xxx/wcd9xxx_registers.h>
25#include <linux/mfd/wcd9xxx/wcd9306_registers.h>
26#include <linux/mfd/wcd9xxx/pdata.h>
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -070027#include <linux/regulator/consumer.h>
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -080028#include <sound/pcm.h>
29#include <sound/pcm_params.h>
30#include <sound/soc.h>
31#include <sound/soc-dapm.h>
32#include <sound/tlv.h>
33#include <linux/bitops.h>
34#include <linux/delay.h>
35#include <linux/pm_runtime.h>
36#include <linux/kernel.h>
37#include <linux/gpio.h>
38#include "wcd9306.h"
39#include "wcd9xxx-resmgr.h"
Bhalchandra Gajareea898742013-03-05 18:15:53 -080040#include "wcd9xxx-common.h"
41
Banajit Goswamia7294452013-06-03 12:42:35 -070042#define TAPAN_HPH_PA_SETTLE_COMP_ON 3000
43#define TAPAN_HPH_PA_SETTLE_COMP_OFF 13000
44
Bhalchandra Gajare4e3dd852013-08-19 17:21:23 -070045#define TAPAN_VDD_CX_OPTIMAL_UA 10000
46#define TAPAN_VDD_CX_SLEEP_UA 2000
47
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -070048/* RX_HPH_CNP_WG_TIME increases by 0.24ms */
49#define TAPAN_WG_TIME_FACTOR_US 240
50
Damir Didjustod6aea992013-09-03 21:18:59 -070051#define TAPAN_SB_PGD_PORT_RX_BASE 0x40
52#define TAPAN_SB_PGD_PORT_TX_BASE 0x50
53#define TAPAN_REGISTER_START_OFFSET 0x800
54
55#define CODEC_REG_CFG_MINOR_VER 1
56
Bhalchandra Gajare4e3dd852013-08-19 17:21:23 -070057static struct regulator *tapan_codec_find_regulator(
58 struct snd_soc_codec *codec,
59 const char *name);
60
Bhalchandra Gajareea898742013-03-05 18:15:53 -080061static atomic_t kp_tapan_priv;
62static int spkr_drv_wrnd_param_set(const char *val,
63 const struct kernel_param *kp);
64static int spkr_drv_wrnd = 1;
65
66static struct kernel_param_ops spkr_drv_wrnd_param_ops = {
67 .set = spkr_drv_wrnd_param_set,
68 .get = param_get_int,
69};
70module_param_cb(spkr_drv_wrnd, &spkr_drv_wrnd_param_ops, &spkr_drv_wrnd, 0644);
71MODULE_PARM_DESC(spkr_drv_wrnd,
72 "Run software workaround to avoid leakage on the speaker drive");
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -080073
74#define WCD9306_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
75 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
76 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
77
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -070078#define WCD9302_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
79 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000)
80
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -080081#define NUM_DECIMATORS 4
82#define NUM_INTERPOLATORS 4
83#define BITS_PER_REG 8
Bhalchandra Gajareea898742013-03-05 18:15:53 -080084/* This actual number of TX ports supported in slimbus slave */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -080085#define TAPAN_TX_PORT_NUMBER 16
Kuirong Wang80aca0d2013-05-09 14:51:09 -070086#define TAPAN_RX_PORT_START_NUMBER 16
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -080087
Bhalchandra Gajareea898742013-03-05 18:15:53 -080088/* Nummer of TX ports actually connected from Slimbus slave to codec Digital */
89#define TAPAN_SLIM_CODEC_TX_PORTS 5
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -080090
Bhalchandra Gajareea898742013-03-05 18:15:53 -080091#define TAPAN_I2S_MASTER_MODE_MASK 0x08
92#define TAPAN_MCLK_CLK_12P288MHZ 12288000
Phani Kumar Uppalapati43bc4152013-05-24 00:44:20 -070093#define TAPAN_MCLK_CLK_9P6MHZ 9600000
Bhalchandra Gajareea898742013-03-05 18:15:53 -080094
95#define TAPAN_SLIM_CLOSE_TIMEOUT 1000
96#define TAPAN_SLIM_IRQ_OVERFLOW (1 << 0)
97#define TAPAN_SLIM_IRQ_UNDERFLOW (1 << 1)
98#define TAPAN_SLIM_IRQ_PORT_CLOSED (1 << 2)
Simmi Pateriya95466b12013-05-09 20:08:46 +053099
100#define TAPAN_IRQ_MBHC_JACK_SWITCH 21
101
Phani Kumar Uppalapaticc3ec0c2013-09-06 18:04:03 -0700102enum tapan_codec_type {
103 WCD9306,
104 WCD9302,
105};
106
107static enum tapan_codec_type codec_ver;
108
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -0700109/*
110 * Multiplication factor to compute impedance on Tapan
111 * This is computed from (Vx / (m*Ical)) = (10mV/(180*30uA))
112 */
113#define TAPAN_ZDET_MUL_FACTOR 1852
114
Damir Didjustod6aea992013-09-03 21:18:59 -0700115static struct afe_param_cdc_reg_cfg audio_reg_cfg[] = {
116 {
117 CODEC_REG_CFG_MINOR_VER,
118 (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_TX_BASE),
119 SB_PGD_PORT_TX_WATERMARK_N, 0x1E, 8, 0x1
120 },
121 {
122 CODEC_REG_CFG_MINOR_VER,
123 (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_TX_BASE),
124 SB_PGD_PORT_TX_ENABLE_N, 0x1, 8, 0x1
125 },
126 {
127 CODEC_REG_CFG_MINOR_VER,
128 (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_RX_BASE),
129 SB_PGD_PORT_RX_WATERMARK_N, 0x1E, 8, 0x1
130 },
131 {
132 CODEC_REG_CFG_MINOR_VER,
133 (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_RX_BASE),
134 SB_PGD_PORT_RX_ENABLE_N, 0x1, 8, 0x1
135 },
136 {
137 CODEC_REG_CFG_MINOR_VER,
138 (TAPAN_REGISTER_START_OFFSET + TAPAN_A_CDC_ANC1_IIR_B1_CTL),
139 AANC_FF_GAIN_ADAPTIVE, 0x4, 8, 0
140 },
141 {
142 CODEC_REG_CFG_MINOR_VER,
143 (TAPAN_REGISTER_START_OFFSET + TAPAN_A_CDC_ANC1_IIR_B1_CTL),
144 AANC_FFGAIN_ADAPTIVE_EN, 0x8, 8, 0
145 },
146 {
147 CODEC_REG_CFG_MINOR_VER,
148 (TAPAN_REGISTER_START_OFFSET + TAPAN_A_CDC_ANC1_GAIN_CTL),
149 AANC_GAIN_CONTROL, 0xFF, 8, 0
150 },
151};
152
153static struct afe_param_cdc_reg_cfg_data tapan_audio_reg_cfg = {
154 .num_registers = ARRAY_SIZE(audio_reg_cfg),
155 .reg_data = audio_reg_cfg,
156};
157
158static struct afe_param_id_cdc_aanc_version tapan_cdc_aanc_version = {
159 .cdc_aanc_minor_version = AFE_API_VERSION_CDC_AANC_VERSION,
160 .aanc_hw_version = AANC_HW_BLOCK_VERSION_2,
161};
162
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800163enum {
164 AIF1_PB = 0,
165 AIF1_CAP,
166 AIF2_PB,
167 AIF2_CAP,
168 AIF3_PB,
169 AIF3_CAP,
170 NUM_CODEC_DAIS,
171};
172
173enum {
174 RX_MIX1_INP_SEL_ZERO = 0,
175 RX_MIX1_INP_SEL_SRC1,
176 RX_MIX1_INP_SEL_SRC2,
177 RX_MIX1_INP_SEL_IIR1,
178 RX_MIX1_INP_SEL_IIR2,
179 RX_MIX1_INP_SEL_RX1,
180 RX_MIX1_INP_SEL_RX2,
181 RX_MIX1_INP_SEL_RX3,
182 RX_MIX1_INP_SEL_RX4,
183 RX_MIX1_INP_SEL_RX5,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800184 RX_MIX1_INP_SEL_AUXRX,
185};
186
187#define TAPAN_COMP_DIGITAL_GAIN_OFFSET 3
188
189static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
190static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
191static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
192static struct snd_soc_dai_driver tapan_dai[];
193static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0);
194
195/* Codec supports 2 IIR filters */
196enum {
197 IIR1 = 0,
198 IIR2,
199 IIR_MAX,
200};
201/* Codec supports 5 bands */
202enum {
203 BAND1 = 0,
204 BAND2,
205 BAND3,
206 BAND4,
207 BAND5,
208 BAND_MAX,
209};
210
211enum {
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800212 COMPANDER_0,
213 COMPANDER_1,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800214 COMPANDER_2,
215 COMPANDER_MAX,
216};
217
218enum {
219 COMPANDER_FS_8KHZ = 0,
220 COMPANDER_FS_16KHZ,
221 COMPANDER_FS_32KHZ,
222 COMPANDER_FS_48KHZ,
223 COMPANDER_FS_96KHZ,
224 COMPANDER_FS_192KHZ,
225 COMPANDER_FS_MAX,
226};
227
228struct comp_sample_dependent_params {
229 u32 peak_det_timeout;
230 u32 rms_meter_div_fact;
231 u32 rms_meter_resamp_fact;
232};
233
234struct hpf_work {
235 struct tapan_priv *tapan;
236 u32 decimator;
237 u8 tx_hpf_cut_of_freq;
238 struct delayed_work dwork;
239};
240
241static struct hpf_work tx_hpf_work[NUM_DECIMATORS];
242
243static const struct wcd9xxx_ch tapan_rx_chs[TAPAN_RX_MAX] = {
Kuirong Wang80aca0d2013-05-09 14:51:09 -0700244 WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER, 0),
245 WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 1, 1),
246 WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 2, 2),
247 WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 3, 3),
248 WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 4, 4),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800249};
250
251static const struct wcd9xxx_ch tapan_tx_chs[TAPAN_TX_MAX] = {
252 WCD9XXX_CH(0, 0),
253 WCD9XXX_CH(1, 1),
254 WCD9XXX_CH(2, 2),
255 WCD9XXX_CH(3, 3),
256 WCD9XXX_CH(4, 4),
257};
258
259static const u32 vport_check_table[NUM_CODEC_DAIS] = {
260 0, /* AIF1_PB */
261 (1 << AIF2_CAP) | (1 << AIF3_CAP), /* AIF1_CAP */
262 0, /* AIF2_PB */
263 (1 << AIF1_CAP) | (1 << AIF3_CAP), /* AIF2_CAP */
264 0, /* AIF2_PB */
265 (1 << AIF1_CAP) | (1 << AIF2_CAP), /* AIF2_CAP */
266};
267
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800268static const u32 vport_i2s_check_table[NUM_CODEC_DAIS] = {
269 0, /* AIF1_PB */
270 0, /* AIF1_CAP */
271};
272
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -0700273enum {
274 CP_REG_BUCK = 0,
275 CP_REG_BHELPER,
276 CP_REG_MAX,
277};
278
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800279struct tapan_priv {
280 struct snd_soc_codec *codec;
281 u32 adc_count;
282 u32 rx_bias_count;
283 s32 dmic_1_2_clk_cnt;
284 s32 dmic_3_4_clk_cnt;
285 s32 dmic_5_6_clk_cnt;
286
287 u32 anc_slot;
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -0700288 bool anc_func;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800289
290 /*track tapan interface type*/
291 u8 intf_type;
292
293 /* num of slim ports required */
294 struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS];
295
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800296 /*compander*/
297 int comp_enabled[COMPANDER_MAX];
298 u32 comp_fs[COMPANDER_MAX];
299
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800300 /* Maintain the status of AUX PGA */
301 int aux_pga_cnt;
302 u8 aux_l_gain;
303 u8 aux_r_gain;
304
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800305 bool spkr_pa_widget_on;
306
Damir Didjustod6aea992013-09-03 21:18:59 -0700307 struct afe_param_cdc_slimbus_slave_cfg slimbus_slave_cfg;
308
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800309 /* resmgr module */
310 struct wcd9xxx_resmgr resmgr;
311 /* mbhc module */
312 struct wcd9xxx_mbhc mbhc;
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800313
314 /* class h specific data */
315 struct wcd9xxx_clsh_cdc_data clsh_d;
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -0700316
317 /* pointers to regulators required for chargepump */
318 struct regulator *cp_regulators[CP_REG_MAX];
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -0700319
320 /*
321 * list used to save/restore registers at start and
322 * end of impedance measurement
323 */
324 struct list_head reg_save_restore;
Damir Didjustod6aea992013-09-03 21:18:59 -0700325
326 int (*machine_codec_event_cb)(struct snd_soc_codec *codec,
327 enum wcd9xxx_codec_event);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800328};
329
330static const u32 comp_shift[] = {
331 0,
Banajit Goswamia7294452013-06-03 12:42:35 -0700332 1,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800333 2,
334};
335
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800336static const int comp_rx_path[] = {
337 COMPANDER_1,
338 COMPANDER_1,
339 COMPANDER_2,
340 COMPANDER_2,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800341 COMPANDER_MAX,
342};
343
344static const struct comp_sample_dependent_params comp_samp_params[] = {
345 {
346 /* 8 Khz */
Banajit Goswamia7294452013-06-03 12:42:35 -0700347 .peak_det_timeout = 0x06,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800348 .rms_meter_div_fact = 0x09,
349 .rms_meter_resamp_fact = 0x06,
350 },
351 {
352 /* 16 Khz */
Banajit Goswamia7294452013-06-03 12:42:35 -0700353 .peak_det_timeout = 0x07,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800354 .rms_meter_div_fact = 0x0A,
355 .rms_meter_resamp_fact = 0x0C,
356 },
357 {
358 /* 32 Khz */
Banajit Goswamia7294452013-06-03 12:42:35 -0700359 .peak_det_timeout = 0x08,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800360 .rms_meter_div_fact = 0x0B,
361 .rms_meter_resamp_fact = 0x1E,
362 },
363 {
364 /* 48 Khz */
Banajit Goswamia7294452013-06-03 12:42:35 -0700365 .peak_det_timeout = 0x09,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800366 .rms_meter_div_fact = 0x0B,
367 .rms_meter_resamp_fact = 0x28,
368 },
369 {
370 /* 96 Khz */
Banajit Goswamia7294452013-06-03 12:42:35 -0700371 .peak_det_timeout = 0x0A,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800372 .rms_meter_div_fact = 0x0C,
373 .rms_meter_resamp_fact = 0x50,
374 },
375 {
376 /* 192 Khz */
Banajit Goswamia7294452013-06-03 12:42:35 -0700377 .peak_det_timeout = 0x0B,
378 .rms_meter_div_fact = 0xC,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800379 .rms_meter_resamp_fact = 0xA0,
380 },
381};
382
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800383static unsigned short rx_digital_gain_reg[] = {
384 TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL,
385 TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL,
386 TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL,
387 TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL,
388};
389
390static unsigned short tx_digital_gain_reg[] = {
391 TAPAN_A_CDC_TX1_VOL_CTL_GAIN,
392 TAPAN_A_CDC_TX2_VOL_CTL_GAIN,
393 TAPAN_A_CDC_TX3_VOL_CTL_GAIN,
394 TAPAN_A_CDC_TX4_VOL_CTL_GAIN,
395};
396
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800397static int spkr_drv_wrnd_param_set(const char *val,
398 const struct kernel_param *kp)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800399{
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800400 struct snd_soc_codec *codec;
401 int ret, old;
402 struct tapan_priv *priv;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800403
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800404 priv = (struct tapan_priv *)atomic_read(&kp_tapan_priv);
405 if (!priv) {
406 pr_debug("%s: codec isn't yet registered\n", __func__);
407 return 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800408 }
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800409
Joonwoo Park973fd352013-06-19 11:38:53 -0700410 codec = priv->codec;
411 mutex_lock(&codec->mutex);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800412 old = spkr_drv_wrnd;
413 ret = param_set_int(val, kp);
414 if (ret) {
Joonwoo Park973fd352013-06-19 11:38:53 -0700415 mutex_unlock(&codec->mutex);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800416 return ret;
417 }
418
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800419 dev_dbg(codec->dev, "%s: spkr_drv_wrnd %d -> %d\n",
420 __func__, old, spkr_drv_wrnd);
Joonwoo Park973fd352013-06-19 11:38:53 -0700421 if ((old == -1 || old == 0) && spkr_drv_wrnd == 1) {
Joonwoo Park533b3682013-06-13 11:41:21 -0700422 WCD9XXX_BG_CLK_LOCK(&priv->resmgr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800423 wcd9xxx_resmgr_get_bandgap(&priv->resmgr,
424 WCD9XXX_BANDGAP_AUDIO_MODE);
Joonwoo Park533b3682013-06-13 11:41:21 -0700425 WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800426 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80);
427 } else if (old == 1 && spkr_drv_wrnd == 0) {
Joonwoo Park533b3682013-06-13 11:41:21 -0700428 WCD9XXX_BG_CLK_LOCK(&priv->resmgr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800429 wcd9xxx_resmgr_put_bandgap(&priv->resmgr,
430 WCD9XXX_BANDGAP_AUDIO_MODE);
Joonwoo Park533b3682013-06-13 11:41:21 -0700431 WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800432 if (!priv->spkr_pa_widget_on)
433 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80,
434 0x00);
435 }
Joonwoo Park973fd352013-06-19 11:38:53 -0700436 mutex_unlock(&codec->mutex);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800437
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800438 return 0;
439}
440
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800441static int tapan_get_anc_slot(struct snd_kcontrol *kcontrol,
442 struct snd_ctl_elem_value *ucontrol)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800443{
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800444 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
445 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
446 ucontrol->value.integer.value[0] = tapan->anc_slot;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800447 return 0;
448}
449
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800450static int tapan_put_anc_slot(struct snd_kcontrol *kcontrol,
451 struct snd_ctl_elem_value *ucontrol)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800452{
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800453 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
454 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
455 tapan->anc_slot = ucontrol->value.integer.value[0];
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800456 return 0;
457}
458
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -0700459static int tapan_get_anc_func(struct snd_kcontrol *kcontrol,
460 struct snd_ctl_elem_value *ucontrol)
461{
462 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
463 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
464
465 ucontrol->value.integer.value[0] = (tapan->anc_func == true ? 1 : 0);
466 return 0;
467}
468
469static int tapan_put_anc_func(struct snd_kcontrol *kcontrol,
470 struct snd_ctl_elem_value *ucontrol)
471{
472 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
473 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
474 struct snd_soc_dapm_context *dapm = &codec->dapm;
475
476 mutex_lock(&dapm->codec->mutex);
477 tapan->anc_func = (!ucontrol->value.integer.value[0] ? false : true);
478
479 dev_err(codec->dev, "%s: anc_func %x", __func__, tapan->anc_func);
480
481 if (tapan->anc_func == true) {
482 pr_info("enable anc virtual widgets");
483 snd_soc_dapm_enable_pin(dapm, "ANC HPHR");
484 snd_soc_dapm_enable_pin(dapm, "ANC HPHL");
485 snd_soc_dapm_enable_pin(dapm, "ANC HEADPHONE");
486 snd_soc_dapm_enable_pin(dapm, "ANC EAR PA");
487 snd_soc_dapm_enable_pin(dapm, "ANC EAR");
488 snd_soc_dapm_disable_pin(dapm, "HPHR");
489 snd_soc_dapm_disable_pin(dapm, "HPHL");
490 snd_soc_dapm_disable_pin(dapm, "HEADPHONE");
491 snd_soc_dapm_disable_pin(dapm, "EAR PA");
492 snd_soc_dapm_disable_pin(dapm, "EAR");
493 } else {
494 pr_info("disable anc virtual widgets");
495 snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
496 snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
497 snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE");
498 snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
499 snd_soc_dapm_disable_pin(dapm, "ANC EAR");
500 snd_soc_dapm_enable_pin(dapm, "HPHR");
501 snd_soc_dapm_enable_pin(dapm, "HPHL");
502 snd_soc_dapm_enable_pin(dapm, "HEADPHONE");
503 snd_soc_dapm_enable_pin(dapm, "EAR PA");
504 snd_soc_dapm_enable_pin(dapm, "EAR");
505 }
506 snd_soc_dapm_sync(dapm);
507 mutex_unlock(&dapm->codec->mutex);
508 return 0;
509}
510
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800511static int tapan_pa_gain_get(struct snd_kcontrol *kcontrol,
512 struct snd_ctl_elem_value *ucontrol)
513{
514 u8 ear_pa_gain;
515 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
516
517 ear_pa_gain = snd_soc_read(codec, TAPAN_A_RX_EAR_GAIN);
518
519 ear_pa_gain = ear_pa_gain >> 5;
520
521 if (ear_pa_gain == 0x00) {
522 ucontrol->value.integer.value[0] = 0;
523 } else if (ear_pa_gain == 0x04) {
524 ucontrol->value.integer.value[0] = 1;
525 } else {
526 pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n",
527 __func__, ear_pa_gain);
528 return -EINVAL;
529 }
530
531 dev_dbg(codec->dev, "%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain);
532
533 return 0;
534}
535
536static int tapan_pa_gain_put(struct snd_kcontrol *kcontrol,
537 struct snd_ctl_elem_value *ucontrol)
538{
539 u8 ear_pa_gain;
540 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
541
542 dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
543 __func__, ucontrol->value.integer.value[0]);
544
545 switch (ucontrol->value.integer.value[0]) {
546 case 0:
547 ear_pa_gain = 0x00;
548 break;
549 case 1:
550 ear_pa_gain = 0x80;
551 break;
552 default:
553 return -EINVAL;
554 }
555
556 snd_soc_update_bits(codec, TAPAN_A_RX_EAR_GAIN, 0xE0, ear_pa_gain);
557 return 0;
558}
559
560static int tapan_get_iir_enable_audio_mixer(
561 struct snd_kcontrol *kcontrol,
562 struct snd_ctl_elem_value *ucontrol)
563{
564 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
565 int iir_idx = ((struct soc_multi_mixer_control *)
566 kcontrol->private_value)->reg;
567 int band_idx = ((struct soc_multi_mixer_control *)
568 kcontrol->private_value)->shift;
569
570 ucontrol->value.integer.value[0] =
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700571 (snd_soc_read(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx)) &
572 (1 << band_idx)) != 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800573
574 dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
575 iir_idx, band_idx,
576 (uint32_t)ucontrol->value.integer.value[0]);
577 return 0;
578}
579
580static int tapan_put_iir_enable_audio_mixer(
581 struct snd_kcontrol *kcontrol,
582 struct snd_ctl_elem_value *ucontrol)
583{
584 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
585 int iir_idx = ((struct soc_multi_mixer_control *)
586 kcontrol->private_value)->reg;
587 int band_idx = ((struct soc_multi_mixer_control *)
588 kcontrol->private_value)->shift;
589 int value = ucontrol->value.integer.value[0];
590
591 /* Mask first 5 bits, 6-8 are reserved */
592 snd_soc_update_bits(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx),
593 (1 << band_idx), (value << band_idx));
594
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700595 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
596 iir_idx, band_idx,
597 ((snd_soc_read(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx)) &
598 (1 << band_idx)) != 0));
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800599 return 0;
600}
601static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
602 int iir_idx, int band_idx,
603 int coeff_idx)
604{
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700605 uint32_t value = 0;
606
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800607 /* Address does not automatically update if reading */
608 snd_soc_write(codec,
609 (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700610 ((band_idx * BAND_MAX + coeff_idx)
611 * sizeof(uint32_t)) & 0x7F);
612
613 value |= snd_soc_read(codec,
614 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx));
615
616 snd_soc_write(codec,
617 (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
618 ((band_idx * BAND_MAX + coeff_idx)
619 * sizeof(uint32_t) + 1) & 0x7F);
620
621 value |= (snd_soc_read(codec,
622 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 8);
623
624 snd_soc_write(codec,
625 (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
626 ((band_idx * BAND_MAX + coeff_idx)
627 * sizeof(uint32_t) + 2) & 0x7F);
628
629 value |= (snd_soc_read(codec,
630 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 16);
631
632 snd_soc_write(codec,
633 (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
634 ((band_idx * BAND_MAX + coeff_idx)
635 * sizeof(uint32_t) + 3) & 0x7F);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800636
637 /* Mask bits top 2 bits since they are reserved */
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700638 value |= ((snd_soc_read(codec,
639 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) & 0x3F) << 24);
640
641 return value;
642
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800643}
644
645static int tapan_get_iir_band_audio_mixer(
646 struct snd_kcontrol *kcontrol,
647 struct snd_ctl_elem_value *ucontrol)
648{
649 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
650 int iir_idx = ((struct soc_multi_mixer_control *)
651 kcontrol->private_value)->reg;
652 int band_idx = ((struct soc_multi_mixer_control *)
653 kcontrol->private_value)->shift;
654
655 ucontrol->value.integer.value[0] =
656 get_iir_band_coeff(codec, iir_idx, band_idx, 0);
657 ucontrol->value.integer.value[1] =
658 get_iir_band_coeff(codec, iir_idx, band_idx, 1);
659 ucontrol->value.integer.value[2] =
660 get_iir_band_coeff(codec, iir_idx, band_idx, 2);
661 ucontrol->value.integer.value[3] =
662 get_iir_band_coeff(codec, iir_idx, band_idx, 3);
663 ucontrol->value.integer.value[4] =
664 get_iir_band_coeff(codec, iir_idx, band_idx, 4);
665
666 dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
667 "%s: IIR #%d band #%d b1 = 0x%x\n"
668 "%s: IIR #%d band #%d b2 = 0x%x\n"
669 "%s: IIR #%d band #%d a1 = 0x%x\n"
670 "%s: IIR #%d band #%d a2 = 0x%x\n",
671 __func__, iir_idx, band_idx,
672 (uint32_t)ucontrol->value.integer.value[0],
673 __func__, iir_idx, band_idx,
674 (uint32_t)ucontrol->value.integer.value[1],
675 __func__, iir_idx, band_idx,
676 (uint32_t)ucontrol->value.integer.value[2],
677 __func__, iir_idx, band_idx,
678 (uint32_t)ucontrol->value.integer.value[3],
679 __func__, iir_idx, band_idx,
680 (uint32_t)ucontrol->value.integer.value[4]);
681 return 0;
682}
683
684static void set_iir_band_coeff(struct snd_soc_codec *codec,
685 int iir_idx, int band_idx,
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700686 uint32_t value)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800687{
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800688 snd_soc_write(codec,
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700689 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
690 (value & 0xFF));
691
692 snd_soc_write(codec,
693 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
694 (value >> 8) & 0xFF);
695
696 snd_soc_write(codec,
697 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
698 (value >> 16) & 0xFF);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800699
700 /* Mask top 2 bits, 7-8 are reserved */
701 snd_soc_write(codec,
702 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
703 (value >> 24) & 0x3F);
704
705}
706
707static int tapan_put_iir_band_audio_mixer(
708 struct snd_kcontrol *kcontrol,
709 struct snd_ctl_elem_value *ucontrol)
710{
711 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
712 int iir_idx = ((struct soc_multi_mixer_control *)
713 kcontrol->private_value)->reg;
714 int band_idx = ((struct soc_multi_mixer_control *)
715 kcontrol->private_value)->shift;
716
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700717 /* Mask top bit it is reserved */
718 /* Updates addr automatically for each B2 write */
719 snd_soc_write(codec,
720 (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
721 (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
722
723 set_iir_band_coeff(codec, iir_idx, band_idx,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800724 ucontrol->value.integer.value[0]);
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700725 set_iir_band_coeff(codec, iir_idx, band_idx,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800726 ucontrol->value.integer.value[1]);
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700727 set_iir_band_coeff(codec, iir_idx, band_idx,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800728 ucontrol->value.integer.value[2]);
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700729 set_iir_band_coeff(codec, iir_idx, band_idx,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800730 ucontrol->value.integer.value[3]);
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700731 set_iir_band_coeff(codec, iir_idx, band_idx,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800732 ucontrol->value.integer.value[4]);
733
734 dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
735 "%s: IIR #%d band #%d b1 = 0x%x\n"
736 "%s: IIR #%d band #%d b2 = 0x%x\n"
737 "%s: IIR #%d band #%d a1 = 0x%x\n"
738 "%s: IIR #%d band #%d a2 = 0x%x\n",
739 __func__, iir_idx, band_idx,
740 get_iir_band_coeff(codec, iir_idx, band_idx, 0),
741 __func__, iir_idx, band_idx,
742 get_iir_band_coeff(codec, iir_idx, band_idx, 1),
743 __func__, iir_idx, band_idx,
744 get_iir_band_coeff(codec, iir_idx, band_idx, 2),
745 __func__, iir_idx, band_idx,
746 get_iir_band_coeff(codec, iir_idx, band_idx, 3),
747 __func__, iir_idx, band_idx,
748 get_iir_band_coeff(codec, iir_idx, band_idx, 4));
749 return 0;
750}
751
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800752static int tapan_get_compander(struct snd_kcontrol *kcontrol,
753 struct snd_ctl_elem_value *ucontrol)
754{
755
756 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
757 int comp = ((struct soc_multi_mixer_control *)
758 kcontrol->private_value)->shift;
759 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
760
761 ucontrol->value.integer.value[0] = tapan->comp_enabled[comp];
762 return 0;
763}
764
765static int tapan_set_compander(struct snd_kcontrol *kcontrol,
766 struct snd_ctl_elem_value *ucontrol)
767{
768 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
769 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
770 int comp = ((struct soc_multi_mixer_control *)
771 kcontrol->private_value)->shift;
772 int value = ucontrol->value.integer.value[0];
773
774 dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n",
775 __func__, comp, tapan->comp_enabled[comp], value);
776 tapan->comp_enabled[comp] = value;
Banajit Goswamia7294452013-06-03 12:42:35 -0700777
778 if (comp == COMPANDER_1 &&
779 tapan->comp_enabled[comp] == 1) {
780 /* Wavegen to 5 msec */
781 snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_CTL, 0xDA);
782 snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_TIME, 0x15);
783 snd_soc_write(codec, TAPAN_A_RX_HPH_BIAS_WG_OCP, 0x2A);
784
785 /* Enable Chopper */
786 snd_soc_update_bits(codec,
787 TAPAN_A_RX_HPH_CHOP_CTL, 0x80, 0x80);
788
789 snd_soc_write(codec, TAPAN_A_NCP_DTEST, 0x20);
790 pr_debug("%s: Enabled Chopper and set wavegen to 5 msec\n",
791 __func__);
792 } else if (comp == COMPANDER_1 &&
793 tapan->comp_enabled[comp] == 0) {
794 /* Wavegen to 20 msec */
795 snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_CTL, 0xDB);
796 snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_TIME, 0x58);
797 snd_soc_write(codec, TAPAN_A_RX_HPH_BIAS_WG_OCP, 0x1A);
798
799 /* Disable CHOPPER block */
800 snd_soc_update_bits(codec,
801 TAPAN_A_RX_HPH_CHOP_CTL, 0x80, 0x00);
802
803 snd_soc_write(codec, TAPAN_A_NCP_DTEST, 0x10);
804 pr_debug("%s: Disabled Chopper and set wavegen to 20 msec\n",
805 __func__);
806 }
807
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800808 return 0;
809}
810
811static int tapan_config_gain_compander(struct snd_soc_codec *codec,
812 int comp, bool enable)
813{
814 int ret = 0;
815
816 switch (comp) {
817 case COMPANDER_0:
818 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_GAIN,
819 1 << 2, !enable << 2);
820 break;
821 case COMPANDER_1:
822 snd_soc_update_bits(codec, TAPAN_A_RX_HPH_L_GAIN,
823 1 << 5, !enable << 5);
824 snd_soc_update_bits(codec, TAPAN_A_RX_HPH_R_GAIN,
825 1 << 5, !enable << 5);
826 break;
827 case COMPANDER_2:
828 snd_soc_update_bits(codec, TAPAN_A_RX_LINE_1_GAIN,
829 1 << 5, !enable << 5);
830 snd_soc_update_bits(codec, TAPAN_A_RX_LINE_2_GAIN,
831 1 << 5, !enable << 5);
832 break;
833 default:
834 WARN_ON(1);
835 ret = -EINVAL;
836 }
837
838 return ret;
839}
840
841static void tapan_discharge_comp(struct snd_soc_codec *codec, int comp)
842{
Banajit Goswamia7294452013-06-03 12:42:35 -0700843 /* Level meter DIV Factor to 5*/
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800844 snd_soc_update_bits(codec, TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8), 0xF0,
Banajit Goswamia7294452013-06-03 12:42:35 -0700845 0x05 << 4);
846 /* RMS meter Sampling to 0x01 */
847 snd_soc_write(codec, TAPAN_A_CDC_COMP0_B3_CTL + (comp * 8), 0x01);
848
849 /* Worst case timeout for compander CnP sleep timeout */
850 usleep_range(3000, 3000);
851}
852
853static enum wcd9xxx_buck_volt tapan_codec_get_buck_mv(
854 struct snd_soc_codec *codec)
855{
856 int buck_volt = WCD9XXX_CDC_BUCK_UNSUPPORTED;
857 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
858 struct wcd9xxx_pdata *pdata = tapan->resmgr.pdata;
859 int i;
Bhalchandra Gajaref49df622013-08-30 12:42:38 -0700860 bool found_regulator = false;
Banajit Goswamia7294452013-06-03 12:42:35 -0700861
862 for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -0700863 if (pdata->regulator[i].name == NULL)
864 continue;
865
Banajit Goswamia7294452013-06-03 12:42:35 -0700866 if (!strncmp(pdata->regulator[i].name,
Bhalchandra Gajaref49df622013-08-30 12:42:38 -0700867 WCD9XXX_SUPPLY_BUCK_NAME,
868 sizeof(WCD9XXX_SUPPLY_BUCK_NAME))) {
869 found_regulator = true;
Banajit Goswamia7294452013-06-03 12:42:35 -0700870 if ((pdata->regulator[i].min_uV ==
Bhalchandra Gajaref49df622013-08-30 12:42:38 -0700871 WCD9XXX_CDC_BUCK_MV_1P8) ||
872 (pdata->regulator[i].min_uV ==
873 WCD9XXX_CDC_BUCK_MV_2P15))
Banajit Goswamia7294452013-06-03 12:42:35 -0700874 buck_volt = pdata->regulator[i].min_uV;
875 break;
876 }
877 }
Bhalchandra Gajaref49df622013-08-30 12:42:38 -0700878
879 if (!found_regulator)
880 dev_err(codec->dev,
881 "%s: Failed to find regulator for %s\n",
882 __func__, WCD9XXX_SUPPLY_BUCK_NAME);
883 else
884 dev_dbg(codec->dev,
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -0700885 "%s: S4 voltage requested is %d\n",
886 __func__, buck_volt);
Bhalchandra Gajaref49df622013-08-30 12:42:38 -0700887
Banajit Goswamia7294452013-06-03 12:42:35 -0700888 return buck_volt;
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800889}
890
891static int tapan_config_compander(struct snd_soc_dapm_widget *w,
892 struct snd_kcontrol *kcontrol, int event)
893{
Banajit Goswamia7294452013-06-03 12:42:35 -0700894 int mask, enable_mask;
895 u8 rdac5_mux;
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800896 struct snd_soc_codec *codec = w->codec;
897 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
898 const int comp = w->shift;
899 const u32 rate = tapan->comp_fs[comp];
900 const struct comp_sample_dependent_params *comp_params =
901 &comp_samp_params[rate];
Banajit Goswamia7294452013-06-03 12:42:35 -0700902 enum wcd9xxx_buck_volt buck_mv;
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800903
904 dev_dbg(codec->dev, "%s: %s event %d compander %d, enabled %d",
905 __func__, w->name, event, comp, tapan->comp_enabled[comp]);
906
907 if (!tapan->comp_enabled[comp])
908 return 0;
909
910 /* Compander 0 has single channel */
911 mask = (comp == COMPANDER_0 ? 0x01 : 0x03);
Banajit Goswamia7294452013-06-03 12:42:35 -0700912 buck_mv = tapan_codec_get_buck_mv(codec);
913
914 rdac5_mux = snd_soc_read(codec, TAPAN_A_CDC_CONN_MISC);
915 rdac5_mux = (rdac5_mux & 0x04) >> 2;
916
917 if (comp == COMPANDER_0) { /* SPK compander */
918 enable_mask = 0x02;
919 } else if (comp == COMPANDER_1) { /* HPH compander */
920 enable_mask = 0x03;
921 } else if (comp == COMPANDER_2) { /* LO compander */
922
923 if (rdac5_mux == 0) { /* DEM4 */
924
925 /* for LO Stereo SE, enable Compander 2 left
926 * channel on RX3 interpolator Path and Compander 2
927 * rigt channel on RX4 interpolator Path.
928 */
929 enable_mask = 0x03;
930 } else if (rdac5_mux == 1) { /* DEM3_INV */
931
932 /* for LO mono differential only enable Compander 2
933 * left channel on RX3 interpolator Path.
934 */
935 enable_mask = 0x02;
936 } else {
937 dev_err(codec->dev, "%s: invalid rdac5_mux val %d",
938 __func__, rdac5_mux);
939 return -EINVAL;
940 }
941 } else {
942 dev_err(codec->dev, "%s: invalid compander %d", __func__, comp);
943 return -EINVAL;
944 }
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800945
946 switch (event) {
947 case SND_SOC_DAPM_PRE_PMU:
Banajit Goswamia7294452013-06-03 12:42:35 -0700948 /* Set compander Sample rate */
949 snd_soc_update_bits(codec,
950 TAPAN_A_CDC_COMP0_FS_CFG + (comp * 8),
951 0x07, rate);
952 /* Set the static gain offset for HPH Path */
953 if (comp == COMPANDER_1) {
954 if (buck_mv == WCD9XXX_CDC_BUCK_MV_2P15)
955 snd_soc_update_bits(codec,
956 TAPAN_A_CDC_COMP0_B4_CTL + (comp * 8),
957 0x80, 0x00);
958 else
959 snd_soc_update_bits(codec,
960 TAPAN_A_CDC_COMP0_B4_CTL + (comp * 8),
961 0x80, 0x80);
962 }
963 /* Enable RX interpolation path compander clocks */
964 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_B2_CTL,
965 0x01 << comp_shift[comp],
966 0x01 << comp_shift[comp]);
967
968 /* Toggle compander reset bits */
969 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL,
970 0x01 << comp_shift[comp],
971 0x01 << comp_shift[comp]);
972 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL,
973 0x01 << comp_shift[comp], 0);
974
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800975 /* Set gain source to compander */
976 tapan_config_gain_compander(codec, comp, true);
Banajit Goswamia7294452013-06-03 12:42:35 -0700977
978 /* Compander enable */
979 snd_soc_update_bits(codec, TAPAN_A_CDC_COMP0_B1_CTL +
980 (comp * 8), enable_mask, enable_mask);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800981
982 tapan_discharge_comp(codec, comp);
983
Banajit Goswamia7294452013-06-03 12:42:35 -0700984 /* Set sample rate dependent paramater */
985 snd_soc_write(codec, TAPAN_A_CDC_COMP0_B3_CTL + (comp * 8),
986 comp_params->rms_meter_resamp_fact);
987 snd_soc_update_bits(codec,
988 TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8),
989 0xF0, comp_params->rms_meter_div_fact << 4);
990 snd_soc_update_bits(codec,
991 TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8),
992 0x0F, comp_params->peak_det_timeout);
993 break;
994 case SND_SOC_DAPM_PRE_PMD:
995 /* Disable compander */
996 snd_soc_update_bits(codec,
997 TAPAN_A_CDC_COMP0_B1_CTL + (comp * 8),
998 enable_mask, 0x00);
999
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001000 /* Toggle compander reset bits */
1001 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL,
1002 mask << comp_shift[comp],
1003 mask << comp_shift[comp]);
1004 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL,
1005 mask << comp_shift[comp], 0);
Banajit Goswamia7294452013-06-03 12:42:35 -07001006
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001007 /* Turn off the clock for compander in pair */
1008 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_B2_CTL,
1009 mask << comp_shift[comp], 0);
Banajit Goswamia7294452013-06-03 12:42:35 -07001010
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001011 /* Set gain source to register */
1012 tapan_config_gain_compander(codec, comp, false);
1013 break;
1014 }
1015 return 0;
1016}
1017
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001018static const char * const tapan_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"};
1019static const struct soc_enum tapan_ear_pa_gain_enum[] = {
1020 SOC_ENUM_SINGLE_EXT(2, tapan_ear_pa_gain_text),
1021};
1022
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07001023static const char *const tapan_anc_func_text[] = {"OFF", "ON"};
1024static const struct soc_enum tapan_anc_func_enum =
1025 SOC_ENUM_SINGLE_EXT(2, tapan_anc_func_text);
1026
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001027/*cut of frequency for high pass filter*/
1028static const char * const cf_text[] = {
1029 "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz"
1030};
1031
1032static const struct soc_enum cf_dec1_enum =
1033 SOC_ENUM_SINGLE(TAPAN_A_CDC_TX1_MUX_CTL, 4, 3, cf_text);
1034
1035static const struct soc_enum cf_dec2_enum =
1036 SOC_ENUM_SINGLE(TAPAN_A_CDC_TX2_MUX_CTL, 4, 3, cf_text);
1037
1038static const struct soc_enum cf_dec3_enum =
1039 SOC_ENUM_SINGLE(TAPAN_A_CDC_TX3_MUX_CTL, 4, 3, cf_text);
1040
1041static const struct soc_enum cf_dec4_enum =
1042 SOC_ENUM_SINGLE(TAPAN_A_CDC_TX4_MUX_CTL, 4, 3, cf_text);
1043
1044static const struct soc_enum cf_rxmix1_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001045 SOC_ENUM_SINGLE(TAPAN_A_CDC_RX1_B4_CTL, 0, 3, cf_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001046
1047static const struct soc_enum cf_rxmix2_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001048 SOC_ENUM_SINGLE(TAPAN_A_CDC_RX2_B4_CTL, 0, 3, cf_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001049
1050static const struct soc_enum cf_rxmix3_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001051 SOC_ENUM_SINGLE(TAPAN_A_CDC_RX3_B4_CTL, 0, 3, cf_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001052
1053static const struct soc_enum cf_rxmix4_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001054 SOC_ENUM_SINGLE(TAPAN_A_CDC_RX4_B4_CTL, 0, 3, cf_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001055
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001056static const char * const class_h_dsm_text[] = {
1057 "ZERO", "RX_HPHL", "RX_SPKR"
1058};
1059
1060static const struct soc_enum class_h_dsm_enum =
1061 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_CLSH_CTL, 2, 3, class_h_dsm_text);
1062
1063static const struct snd_kcontrol_new class_h_dsm_mux =
1064 SOC_DAPM_ENUM("CLASS_H_DSM MUX Mux", class_h_dsm_enum);
1065
Phani Kumar Uppalapati5724aa22013-10-02 12:46:15 -07001066static int tapan_hph_impedance_get(struct snd_kcontrol *kcontrol,
1067 struct snd_ctl_elem_value *ucontrol)
1068{
1069 uint32_t zl, zr;
1070 bool hphr;
1071 struct soc_multi_mixer_control *mc;
1072 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1073 struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
1074
1075 mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
1076
1077 hphr = mc->shift;
1078 wcd9xxx_mbhc_get_impedance(&priv->mbhc, &zl, &zr);
1079 pr_debug("%s: zl %u, zr %u\n", __func__, zl, zr);
1080 ucontrol->value.integer.value[0] = hphr ? zr : zl;
1081
1082 return 0;
1083}
1084
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07001085static const struct snd_kcontrol_new tapan_common_snd_controls[] = {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001086
1087 SOC_ENUM_EXT("EAR PA Gain", tapan_ear_pa_gain_enum[0],
1088 tapan_pa_gain_get, tapan_pa_gain_put),
1089
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001090 SOC_SINGLE_TLV("HPHL Volume", TAPAN_A_RX_HPH_L_GAIN, 0, 14, 1,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001091 line_gain),
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001092 SOC_SINGLE_TLV("HPHR Volume", TAPAN_A_RX_HPH_R_GAIN, 0, 14, 1,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001093 line_gain),
1094
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001095 SOC_SINGLE_TLV("LINEOUT1 Volume", TAPAN_A_RX_LINE_1_GAIN, 0, 14, 1,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001096 line_gain),
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001097 SOC_SINGLE_TLV("LINEOUT2 Volume", TAPAN_A_RX_LINE_2_GAIN, 0, 14, 1,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001098 line_gain),
1099
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001100 SOC_SINGLE_TLV("SPK DRV Volume", TAPAN_A_SPKR_DRV_GAIN, 3, 7, 1,
1101 line_gain),
1102
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07001103 SOC_SINGLE_TLV("ADC1 Volume", TAPAN_A_TX_1_EN, 2, 19, 0, analog_gain),
1104 SOC_SINGLE_TLV("ADC2 Volume", TAPAN_A_TX_2_EN, 2, 19, 0, analog_gain),
1105 SOC_SINGLE_TLV("ADC3 Volume", TAPAN_A_TX_3_EN, 2, 19, 0, analog_gain),
1106 SOC_SINGLE_TLV("ADC4 Volume", TAPAN_A_TX_4_EN, 2, 19, 0, analog_gain),
Jay Chokshi83b4f6132013-02-14 16:20:56 -08001107 SOC_SINGLE_S8_TLV("RX1 Digital Volume", TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL,
1108 -84, 40, digital_gain),
1109 SOC_SINGLE_S8_TLV("RX2 Digital Volume", TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL,
1110 -84, 40, digital_gain),
1111 SOC_SINGLE_S8_TLV("RX3 Digital Volume", TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL,
1112 -84, 40, digital_gain),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001113
Jay Chokshi83b4f6132013-02-14 16:20:56 -08001114 SOC_SINGLE_S8_TLV("DEC1 Volume", TAPAN_A_CDC_TX1_VOL_CTL_GAIN, -84, 40,
1115 digital_gain),
1116 SOC_SINGLE_S8_TLV("DEC2 Volume", TAPAN_A_CDC_TX2_VOL_CTL_GAIN, -84, 40,
1117 digital_gain),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001118
Jay Chokshi83b4f6132013-02-14 16:20:56 -08001119 SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TAPAN_A_CDC_IIR1_GAIN_B1_CTL, -84,
1120 40, digital_gain),
1121 SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TAPAN_A_CDC_IIR1_GAIN_B2_CTL, -84,
1122 40, digital_gain),
1123 SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TAPAN_A_CDC_IIR1_GAIN_B3_CTL, -84,
1124 40, digital_gain),
1125 SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TAPAN_A_CDC_IIR1_GAIN_B4_CTL, -84,
1126 40, digital_gain),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001127
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001128 SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
1129 SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
1130 SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
1131 SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
1132
1133 SOC_SINGLE("TX1 HPF Switch", TAPAN_A_CDC_TX1_MUX_CTL, 3, 1, 0),
1134 SOC_SINGLE("TX2 HPF Switch", TAPAN_A_CDC_TX2_MUX_CTL, 3, 1, 0),
1135 SOC_SINGLE("TX3 HPF Switch", TAPAN_A_CDC_TX3_MUX_CTL, 3, 1, 0),
1136 SOC_SINGLE("TX4 HPF Switch", TAPAN_A_CDC_TX4_MUX_CTL, 3, 1, 0),
1137
1138 SOC_SINGLE("RX1 HPF Switch", TAPAN_A_CDC_RX1_B5_CTL, 2, 1, 0),
1139 SOC_SINGLE("RX2 HPF Switch", TAPAN_A_CDC_RX2_B5_CTL, 2, 1, 0),
1140 SOC_SINGLE("RX3 HPF Switch", TAPAN_A_CDC_RX3_B5_CTL, 2, 1, 0),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001141
1142 SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum),
1143 SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum),
1144 SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001145
1146 SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
1147 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1148 SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
1149 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1150 SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
1151 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1152 SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
1153 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1154 SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
1155 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1156 SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0,
1157 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1158 SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0,
1159 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1160 SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0,
1161 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1162 SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0,
1163 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1164 SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0,
1165 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1166
1167 SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
1168 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1169 SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
1170 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1171 SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
1172 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1173 SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
1174 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1175 SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
1176 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1177 SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5,
1178 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1179 SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5,
1180 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1181 SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5,
1182 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1183 SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5,
1184 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1185 SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5,
1186 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
Phani Kumar Uppalapati5724aa22013-10-02 12:46:15 -07001187
1188 SOC_SINGLE_EXT("HPHL Impedance", 0, 0, UINT_MAX, 0,
1189 tapan_hph_impedance_get, NULL),
1190 SOC_SINGLE_EXT("HPHR Impedance", 0, 1, UINT_MAX, 0,
1191 tapan_hph_impedance_get, NULL),
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07001192};
1193
1194static const struct snd_kcontrol_new tapan_9306_snd_controls[] = {
1195 SOC_SINGLE_TLV("ADC5 Volume", TAPAN_A_TX_5_EN, 2, 19, 0, analog_gain),
1196
1197 SOC_SINGLE_S8_TLV("RX4 Digital Volume", TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL,
1198 -84, 40, digital_gain),
1199 SOC_SINGLE_S8_TLV("DEC3 Volume", TAPAN_A_CDC_TX3_VOL_CTL_GAIN, -84, 40,
1200 digital_gain),
1201 SOC_SINGLE_S8_TLV("DEC4 Volume", TAPAN_A_CDC_TX4_VOL_CTL_GAIN, -84, 40,
1202 digital_gain),
1203 SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 100, 0, tapan_get_anc_slot,
1204 tapan_put_anc_slot),
1205 SOC_ENUM_EXT("ANC Function", tapan_anc_func_enum, tapan_get_anc_func,
1206 tapan_put_anc_func),
1207 SOC_SINGLE("RX4 HPF Switch", TAPAN_A_CDC_RX4_B5_CTL, 2, 1, 0),
1208 SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001209
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001210 SOC_SINGLE_EXT("COMP0 Switch", SND_SOC_NOPM, COMPANDER_0, 1, 0,
1211 tapan_get_compander, tapan_set_compander),
1212 SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, COMPANDER_1, 1, 0,
1213 tapan_get_compander, tapan_set_compander),
1214 SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, COMPANDER_2, 1, 0,
1215 tapan_get_compander, tapan_set_compander),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001216};
1217
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001218static const char * const rx_1_2_mix1_text[] = {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001219 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001220 "RX5", "AUXRX", "AUXTX1"
1221};
1222
1223static const char * const rx_3_4_mix1_text[] = {
1224 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
1225 "RX5", "AUXRX", "AUXTX1", "AUXTX2"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001226};
1227
1228static const char * const rx_mix2_text[] = {
1229 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2"
1230};
1231
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07001232static const char * const rx_rdac3_text[] = {
1233 "DEM1", "DEM2"
1234};
1235
1236static const char * const rx_rdac4_text[] = {
1237 "DEM3", "DEM2"
1238};
1239
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001240static const char * const rx_rdac5_text[] = {
1241 "DEM4", "DEM3_INV"
1242};
1243
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001244static const char * const sb_tx_1_2_mux_text[] = {
1245 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4",
1246 "RSVD", "RSVD", "RSVD",
1247 "DEC1", "DEC2", "DEC3", "DEC4"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001248};
1249
1250static const char * const sb_tx3_mux_text[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001251 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4",
1252 "RSVD", "RSVD", "RSVD", "RSVD", "RSVD",
1253 "DEC3"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001254};
1255
1256static const char * const sb_tx4_mux_text[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001257 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4",
1258 "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", "RSVD",
1259 "DEC4"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001260};
1261
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001262static const char * const sb_tx5_mux_text[] = {
1263 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4",
1264 "RSVD", "RSVD", "RSVD",
1265 "DEC1"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001266};
1267
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001268static const char * const dec_1_2_mux_text[] = {
1269 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADCMB",
1270 "DMIC1", "DMIC2", "DMIC3", "DMIC4"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001271};
1272
1273static const char * const dec3_mux_text[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001274 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADCMB",
1275 "DMIC1", "DMIC2", "DMIC3", "DMIC4",
1276 "ANCFBTUNE1"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001277};
1278
1279static const char * const dec4_mux_text[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001280 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADCMB",
1281 "DMIC1", "DMIC2", "DMIC3", "DMIC4",
1282 "ANCFBTUNE2"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001283};
1284
1285static const char * const anc_mux_text[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001286 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5",
1287 "RSVD", "RSVD", "RSVD",
1288 "DMIC1", "DMIC2", "DMIC3", "DMIC4",
1289 "RSVD", "RSVD"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001290};
1291
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07001292static const char * const anc1_fb_mux_text[] = {
1293 "ZERO", "EAR_HPH_L", "EAR_LINE_1",
1294};
1295
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001296static const char * const iir1_inp1_text[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001297 "ZERO", "DEC1", "DEC2", "DEC3", "DEC4",
1298 "RX1", "RX2", "RX3", "RX4", "RX5"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001299};
1300
1301static const struct soc_enum rx_mix1_inp1_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001302 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_1_2_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001303
1304static const struct soc_enum rx_mix1_inp2_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001305 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_1_2_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001306
1307static const struct soc_enum rx_mix1_inp3_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001308 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B2_CTL, 0, 12, rx_1_2_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001309
1310static const struct soc_enum rx2_mix1_inp1_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001311 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_1_2_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001312
1313static const struct soc_enum rx2_mix1_inp2_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001314 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_1_2_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001315
1316static const struct soc_enum rx3_mix1_inp1_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001317 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX3_B1_CTL, 0, 13, rx_3_4_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001318
1319static const struct soc_enum rx3_mix1_inp2_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001320 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX3_B1_CTL, 4, 13, rx_3_4_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001321
1322static const struct soc_enum rx4_mix1_inp1_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001323 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B1_CTL, 0, 13, rx_3_4_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001324
1325static const struct soc_enum rx4_mix1_inp2_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001326 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B1_CTL, 4, 13, rx_3_4_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001327
1328static const struct soc_enum rx1_mix2_inp1_chain_enum =
1329 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text);
1330
1331static const struct soc_enum rx1_mix2_inp2_chain_enum =
1332 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text);
1333
1334static const struct soc_enum rx2_mix2_inp1_chain_enum =
1335 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text);
1336
1337static const struct soc_enum rx2_mix2_inp2_chain_enum =
1338 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text);
1339
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001340static const struct soc_enum rx4_mix2_inp1_chain_enum =
1341 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B3_CTL, 0, 5, rx_mix2_text);
1342
1343static const struct soc_enum rx4_mix2_inp2_chain_enum =
1344 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B3_CTL, 3, 5, rx_mix2_text);
1345
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07001346static const struct soc_enum rx_rdac3_enum =
1347 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B2_CTL, 4, 2, rx_rdac3_text);
1348
1349static const struct soc_enum rx_rdac4_enum =
1350 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_MISC, 1, 2, rx_rdac4_text);
1351
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001352static const struct soc_enum rx_rdac5_enum =
1353 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_MISC, 2, 2, rx_rdac5_text);
1354
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001355static const struct soc_enum sb_tx1_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001356 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B1_CTL, 0, 12,
1357 sb_tx_1_2_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001358
1359static const struct soc_enum sb_tx2_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001360 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B2_CTL, 0, 12,
1361 sb_tx_1_2_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001362
1363static const struct soc_enum sb_tx3_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001364 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B3_CTL, 0, 11, sb_tx3_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001365
1366static const struct soc_enum sb_tx4_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001367 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B4_CTL, 0, 12, sb_tx4_mux_text);
1368
1369static const struct soc_enum sb_tx5_mux_enum =
1370 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001371
1372static const struct soc_enum dec1_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001373 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B1_CTL, 0, 10, dec_1_2_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001374
1375static const struct soc_enum dec2_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001376 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B1_CTL, 4, 10, dec_1_2_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001377
1378static const struct soc_enum dec3_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001379 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B2_CTL, 0, 12, dec3_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001380
1381static const struct soc_enum dec4_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001382 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B2_CTL, 4, 12, dec4_mux_text);
1383
1384static const struct soc_enum anc1_mux_enum =
1385 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B1_CTL, 0, 15, anc_mux_text);
1386
1387static const struct soc_enum anc2_mux_enum =
1388 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B1_CTL, 4, 15, anc_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001389
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07001390static const struct soc_enum anc1_fb_mux_enum =
1391 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text);
1392
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001393static const struct soc_enum iir1_inp1_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001394 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_EQ1_B1_CTL, 0, 10, iir1_inp1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001395
1396static const struct snd_kcontrol_new rx_mix1_inp1_mux =
1397 SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum);
1398
1399static const struct snd_kcontrol_new rx_mix1_inp2_mux =
1400 SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum);
1401
1402static const struct snd_kcontrol_new rx_mix1_inp3_mux =
1403 SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum);
1404
1405static const struct snd_kcontrol_new rx2_mix1_inp1_mux =
1406 SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum);
1407
1408static const struct snd_kcontrol_new rx2_mix1_inp2_mux =
1409 SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum);
1410
1411static const struct snd_kcontrol_new rx3_mix1_inp1_mux =
1412 SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum);
1413
1414static const struct snd_kcontrol_new rx3_mix1_inp2_mux =
1415 SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum);
1416
1417static const struct snd_kcontrol_new rx4_mix1_inp1_mux =
1418 SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum);
1419
1420static const struct snd_kcontrol_new rx4_mix1_inp2_mux =
1421 SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum);
1422
1423static const struct snd_kcontrol_new rx1_mix2_inp1_mux =
1424 SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum);
1425
1426static const struct snd_kcontrol_new rx1_mix2_inp2_mux =
1427 SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum);
1428
1429static const struct snd_kcontrol_new rx2_mix2_inp1_mux =
1430 SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum);
1431
1432static const struct snd_kcontrol_new rx2_mix2_inp2_mux =
1433 SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum);
1434
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001435static const struct snd_kcontrol_new rx4_mix2_inp1_mux =
1436 SOC_DAPM_ENUM("RX4 MIX2 INP1 Mux", rx4_mix2_inp1_chain_enum);
1437
1438static const struct snd_kcontrol_new rx4_mix2_inp2_mux =
1439 SOC_DAPM_ENUM("RX4 MIX2 INP2 Mux", rx4_mix2_inp2_chain_enum);
1440
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07001441static const struct snd_kcontrol_new rx_dac3_mux =
1442 SOC_DAPM_ENUM("RDAC3 MUX Mux", rx_rdac3_enum);
1443
1444static const struct snd_kcontrol_new rx_dac4_mux =
1445 SOC_DAPM_ENUM("RDAC4 MUX Mux", rx_rdac4_enum);
1446
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001447static const struct snd_kcontrol_new rx_dac5_mux =
1448 SOC_DAPM_ENUM("RDAC5 MUX Mux", rx_rdac5_enum);
1449
1450static const struct snd_kcontrol_new sb_tx1_mux =
1451 SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum);
1452
1453static const struct snd_kcontrol_new sb_tx2_mux =
1454 SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum);
1455
1456static const struct snd_kcontrol_new sb_tx3_mux =
1457 SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum);
1458
1459static const struct snd_kcontrol_new sb_tx4_mux =
1460 SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum);
1461
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001462static const struct snd_kcontrol_new sb_tx5_mux =
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001463 SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001464
1465static int wcd9306_put_dec_enum(struct snd_kcontrol *kcontrol,
1466 struct snd_ctl_elem_value *ucontrol)
1467{
1468 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1469 struct snd_soc_dapm_widget *w = wlist->widgets[0];
1470 struct snd_soc_codec *codec = w->codec;
1471 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1472 unsigned int dec_mux, decimator;
1473 char *dec_name = NULL;
1474 char *widget_name = NULL;
1475 char *temp;
1476 u16 tx_mux_ctl_reg;
1477 u8 adc_dmic_sel = 0x0;
1478 int ret = 0;
1479
1480 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1481 return -EINVAL;
1482
1483 dec_mux = ucontrol->value.enumerated.item[0];
1484
1485 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
1486 if (!widget_name)
1487 return -ENOMEM;
1488 temp = widget_name;
1489
1490 dec_name = strsep(&widget_name, " ");
1491 widget_name = temp;
1492 if (!dec_name) {
1493 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
1494 ret = -EINVAL;
1495 goto out;
1496 }
1497
1498 ret = kstrtouint(strpbrk(dec_name, "1234"), 10, &decimator);
1499 if (ret < 0) {
1500 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
1501 ret = -EINVAL;
1502 goto out;
1503 }
1504
1505 dev_dbg(w->dapm->dev, "%s(): widget = %s decimator = %u dec_mux = %u\n"
1506 , __func__, w->name, decimator, dec_mux);
1507
1508 switch (decimator) {
1509 case 1:
1510 case 2:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001511 if ((dec_mux >= 1) && (dec_mux <= 5))
1512 adc_dmic_sel = 0x0;
1513 else if ((dec_mux >= 6) && (dec_mux <= 9))
1514 adc_dmic_sel = 0x1;
1515 break;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001516 case 3:
1517 case 4:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001518 if ((dec_mux >= 1) && (dec_mux <= 6))
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001519 adc_dmic_sel = 0x0;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001520 else if ((dec_mux >= 7) && (dec_mux <= 10))
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001521 adc_dmic_sel = 0x1;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001522 break;
1523 default:
1524 pr_err("%s: Invalid Decimator = %u\n", __func__, decimator);
1525 ret = -EINVAL;
1526 goto out;
1527 }
1528
1529 tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
1530
1531 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel);
1532
1533 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1534
1535out:
1536 kfree(widget_name);
1537 return ret;
1538}
1539
1540#define WCD9306_DEC_ENUM(xname, xenum) \
1541{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1542 .info = snd_soc_info_enum_double, \
1543 .get = snd_soc_dapm_get_enum_double, \
1544 .put = wcd9306_put_dec_enum, \
1545 .private_value = (unsigned long)&xenum }
1546
1547static const struct snd_kcontrol_new dec1_mux =
1548 WCD9306_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum);
1549
1550static const struct snd_kcontrol_new dec2_mux =
1551 WCD9306_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum);
1552
1553static const struct snd_kcontrol_new dec3_mux =
1554 WCD9306_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum);
1555
1556static const struct snd_kcontrol_new dec4_mux =
1557 WCD9306_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum);
1558
1559static const struct snd_kcontrol_new iir1_inp1_mux =
1560 SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum);
1561
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001562static const struct snd_kcontrol_new anc1_mux =
1563 SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum);
1564
1565static const struct snd_kcontrol_new anc2_mux =
1566 SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum);
1567
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07001568static const struct snd_kcontrol_new anc1_fb_mux =
1569 SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum);
1570
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001571static const struct snd_kcontrol_new dac1_switch[] = {
1572 SOC_DAPM_SINGLE("Switch", TAPAN_A_RX_EAR_EN, 5, 1, 0)
1573};
1574static const struct snd_kcontrol_new hphl_switch[] = {
1575 SOC_DAPM_SINGLE("Switch", TAPAN_A_RX_HPH_L_DAC_CTL, 6, 1, 0)
1576};
1577
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001578static const struct snd_kcontrol_new spk_dac_switch[] = {
1579 SOC_DAPM_SINGLE("Switch", TAPAN_A_SPKR_DRV_DAC_CTL, 2, 1, 0)
1580};
1581
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001582static const struct snd_kcontrol_new hphl_pa_mix[] = {
1583 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
1584 7, 1, 0),
1585};
1586
1587static const struct snd_kcontrol_new hphr_pa_mix[] = {
1588 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
1589 6, 1, 0),
1590};
1591
1592static const struct snd_kcontrol_new ear_pa_mix[] = {
1593 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
1594 5, 1, 0),
1595};
1596static const struct snd_kcontrol_new lineout1_pa_mix[] = {
1597 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
1598 4, 1, 0),
1599};
1600
1601static const struct snd_kcontrol_new lineout2_pa_mix[] = {
1602 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
1603 3, 1, 0),
1604};
1605
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001606
1607/* virtual port entries */
1608static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol,
1609 struct snd_ctl_elem_value *ucontrol)
1610{
1611 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1612 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1613
1614 ucontrol->value.integer.value[0] = widget->value;
1615 return 0;
1616}
1617
1618static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol,
1619 struct snd_ctl_elem_value *ucontrol)
1620{
1621 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1622 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1623 struct snd_soc_codec *codec = widget->codec;
1624 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
1625 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
1626 struct soc_multi_mixer_control *mixer =
1627 ((struct soc_multi_mixer_control *)kcontrol->private_value);
1628 u32 dai_id = widget->shift;
1629 u32 port_id = mixer->shift;
1630 u32 enable = ucontrol->value.integer.value[0];
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001631 u32 vtable = vport_check_table[dai_id];
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001632
1633 dev_dbg(codec->dev, "%s: wname %s cname %s\n",
1634 __func__, widget->name, ucontrol->id.name);
1635 dev_dbg(codec->dev, "%s: value %u shift %d item %ld\n",
1636 __func__, widget->value, widget->shift,
1637 ucontrol->value.integer.value[0]);
1638
1639 mutex_lock(&codec->mutex);
1640
1641 if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
1642 if (dai_id != AIF1_CAP) {
1643 dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
1644 __func__);
1645 mutex_unlock(&codec->mutex);
1646 return -EINVAL;
1647 }
1648 }
1649 switch (dai_id) {
1650 case AIF1_CAP:
1651 case AIF2_CAP:
1652 case AIF3_CAP:
1653 /* only add to the list if value not set
1654 */
1655 if (enable && !(widget->value & 1 << port_id)) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001656 if (tapan_p->intf_type ==
1657 WCD9XXX_INTERFACE_TYPE_SLIMBUS)
1658 vtable = vport_check_table[dai_id];
1659 if (tapan_p->intf_type ==
1660 WCD9XXX_INTERFACE_TYPE_I2C)
1661 vtable = vport_i2s_check_table[dai_id];
1662
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001663 if (wcd9xxx_tx_vport_validation(
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001664 vtable,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001665 port_id,
1666 tapan_p->dai)) {
1667 dev_dbg(codec->dev, "%s: TX%u is used by other virtual port\n",
1668 __func__, port_id + 1);
1669 mutex_unlock(&codec->mutex);
Kuirong Wang80aca0d2013-05-09 14:51:09 -07001670 return 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001671 }
1672 widget->value |= 1 << port_id;
1673 list_add_tail(&core->tx_chs[port_id].list,
1674 &tapan_p->dai[dai_id].wcd9xxx_ch_list
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001675 );
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001676 } else if (!enable && (widget->value & 1 << port_id)) {
1677 widget->value &= ~(1 << port_id);
1678 list_del_init(&core->tx_chs[port_id].list);
1679 } else {
1680 if (enable)
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001681 dev_dbg(codec->dev, "%s: TX%u port is used by\n"
1682 "this virtual port\n",
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001683 __func__, port_id + 1);
1684 else
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001685 dev_dbg(codec->dev, "%s: TX%u port is not used by\n"
1686 "this virtual port\n",
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001687 __func__, port_id + 1);
1688 /* avoid update power function */
1689 mutex_unlock(&codec->mutex);
1690 return 0;
1691 }
1692 break;
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07001693 default:
1694 dev_err(codec->dev, "Unknown AIF %d\n", dai_id);
1695 mutex_unlock(&codec->mutex);
1696 return -EINVAL;
1697 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001698 dev_dbg(codec->dev, "%s: name %s sname %s updated value %u shift %d\n",
1699 __func__, widget->name, widget->sname,
1700 widget->value, widget->shift);
1701
1702 snd_soc_dapm_mixer_update_power(widget, kcontrol, enable);
1703
1704 mutex_unlock(&codec->mutex);
1705 return 0;
1706}
1707
1708static int slim_rx_mux_get(struct snd_kcontrol *kcontrol,
1709 struct snd_ctl_elem_value *ucontrol)
1710{
1711 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1712 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1713
1714 ucontrol->value.enumerated.item[0] = widget->value;
1715 return 0;
1716}
1717
1718static const char *const slim_rx_mux_text[] = {
1719 "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB"
1720};
1721
1722static int slim_rx_mux_put(struct snd_kcontrol *kcontrol,
1723 struct snd_ctl_elem_value *ucontrol)
1724{
1725 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1726 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1727 struct snd_soc_codec *codec = widget->codec;
1728 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
1729 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
1730 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1731 u32 port_id = widget->shift;
1732
1733 dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n",
1734 __func__, widget->name, ucontrol->id.name, widget->value,
1735 widget->shift, ucontrol->value.integer.value[0]);
1736
1737 widget->value = ucontrol->value.enumerated.item[0];
1738
1739 mutex_lock(&codec->mutex);
1740
1741 if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
1742 if (widget->value > 1) {
1743 dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
1744 __func__);
1745 goto err;
1746 }
1747 }
1748 /* value need to match the Virtual port and AIF number
1749 */
1750 switch (widget->value) {
1751 case 0:
1752 list_del_init(&core->rx_chs[port_id].list);
1753 break;
1754 case 1:
Kuirong Wang80aca0d2013-05-09 14:51:09 -07001755 if (wcd9xxx_rx_vport_validation(port_id +
1756 TAPAN_RX_PORT_START_NUMBER,
1757 &tapan_p->dai[AIF1_PB].wcd9xxx_ch_list)) {
1758 dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
1759 __func__, port_id + 1);
1760 goto rtn;
1761 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001762 list_add_tail(&core->rx_chs[port_id].list,
1763 &tapan_p->dai[AIF1_PB].wcd9xxx_ch_list);
1764 break;
1765 case 2:
Kuirong Wang80aca0d2013-05-09 14:51:09 -07001766 if (wcd9xxx_rx_vport_validation(port_id +
1767 TAPAN_RX_PORT_START_NUMBER,
1768 &tapan_p->dai[AIF2_PB].wcd9xxx_ch_list)) {
1769 dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
1770 __func__, port_id + 1);
1771 goto rtn;
1772 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001773 list_add_tail(&core->rx_chs[port_id].list,
1774 &tapan_p->dai[AIF2_PB].wcd9xxx_ch_list);
1775 break;
1776 case 3:
Kuirong Wang80aca0d2013-05-09 14:51:09 -07001777 if (wcd9xxx_rx_vport_validation(port_id +
1778 TAPAN_RX_PORT_START_NUMBER,
1779 &tapan_p->dai[AIF3_PB].wcd9xxx_ch_list)) {
1780 dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
1781 __func__, port_id + 1);
1782 goto rtn;
1783 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001784 list_add_tail(&core->rx_chs[port_id].list,
1785 &tapan_p->dai[AIF3_PB].wcd9xxx_ch_list);
1786 break;
1787 default:
1788 pr_err("Unknown AIF %d\n", widget->value);
1789 goto err;
1790 }
1791
Kuirong Wang80aca0d2013-05-09 14:51:09 -07001792rtn:
Jay Chokshi83b4f6132013-02-14 16:20:56 -08001793 snd_soc_dapm_mux_update_power(widget, kcontrol, 1, widget->value, e);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001794 mutex_unlock(&codec->mutex);
1795 return 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001796err:
1797 mutex_unlock(&codec->mutex);
1798 return -EINVAL;
1799}
1800
1801static const struct soc_enum slim_rx_mux_enum =
1802 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text), slim_rx_mux_text);
1803
1804static const struct snd_kcontrol_new slim_rx_mux[TAPAN_RX_MAX] = {
1805 SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum,
1806 slim_rx_mux_get, slim_rx_mux_put),
1807 SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum,
1808 slim_rx_mux_get, slim_rx_mux_put),
1809 SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum,
1810 slim_rx_mux_get, slim_rx_mux_put),
1811 SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum,
1812 slim_rx_mux_get, slim_rx_mux_put),
1813 SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum,
1814 slim_rx_mux_get, slim_rx_mux_put),
1815};
1816
1817static const struct snd_kcontrol_new aif_cap_mixer[] = {
1818 SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, TAPAN_TX1, 1, 0,
1819 slim_tx_mixer_get, slim_tx_mixer_put),
1820 SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, TAPAN_TX2, 1, 0,
1821 slim_tx_mixer_get, slim_tx_mixer_put),
1822 SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, TAPAN_TX3, 1, 0,
1823 slim_tx_mixer_get, slim_tx_mixer_put),
1824 SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, TAPAN_TX4, 1, 0,
1825 slim_tx_mixer_get, slim_tx_mixer_put),
1826 SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, TAPAN_TX5, 1, 0,
1827 slim_tx_mixer_get, slim_tx_mixer_put),
1828};
1829
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001830static int tapan_codec_enable_adc(struct snd_soc_dapm_widget *w,
1831 struct snd_kcontrol *kcontrol, int event)
1832{
1833 struct snd_soc_codec *codec = w->codec;
1834 u16 adc_reg;
1835 u8 init_bit_shift;
1836
1837 dev_dbg(codec->dev, "%s(): %s %d\n", __func__, w->name, event);
1838
1839 if (w->reg == TAPAN_A_TX_1_EN) {
1840 init_bit_shift = 7;
1841 adc_reg = TAPAN_A_TX_1_2_TEST_CTL;
1842 } else if (w->reg == TAPAN_A_TX_2_EN) {
1843 init_bit_shift = 6;
1844 adc_reg = TAPAN_A_TX_1_2_TEST_CTL;
1845 } else if (w->reg == TAPAN_A_TX_3_EN) {
1846 init_bit_shift = 6;
1847 adc_reg = TAPAN_A_TX_1_2_TEST_CTL;
1848 } else if (w->reg == TAPAN_A_TX_4_EN) {
1849 init_bit_shift = 7;
1850 adc_reg = TAPAN_A_TX_4_5_TEST_CTL;
1851 } else if (w->reg == TAPAN_A_TX_5_EN) {
1852 init_bit_shift = 6;
1853 adc_reg = TAPAN_A_TX_4_5_TEST_CTL;
1854 } else {
1855 pr_err("%s: Error, invalid adc register\n", __func__);
1856 return -EINVAL;
1857 }
1858
1859 switch (event) {
1860 case SND_SOC_DAPM_PRE_PMU:
1861 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift,
1862 1 << init_bit_shift);
1863 break;
1864 case SND_SOC_DAPM_POST_PMU:
1865
1866 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00);
1867
1868 break;
1869 }
1870 return 0;
1871}
1872
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001873static int tapan_codec_enable_aux_pga(struct snd_soc_dapm_widget *w,
1874 struct snd_kcontrol *kcontrol, int event)
1875{
1876 struct snd_soc_codec *codec = w->codec;
1877 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
1878
1879 dev_dbg(codec->dev, "%s: %d\n", __func__, event);
1880
1881 switch (event) {
1882 case SND_SOC_DAPM_PRE_PMU:
Joonwoo Park533b3682013-06-13 11:41:21 -07001883 WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001884 wcd9xxx_resmgr_get_bandgap(&tapan->resmgr,
1885 WCD9XXX_BANDGAP_AUDIO_MODE);
1886 /* AUX PGA requires RCO or MCLK */
1887 wcd9xxx_resmgr_get_clk_block(&tapan->resmgr, WCD9XXX_CLK_RCO);
Joonwoo Park533b3682013-06-13 11:41:21 -07001888 WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001889 wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 1);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001890 break;
1891
1892 case SND_SOC_DAPM_POST_PMD:
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001893 wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 0);
Joonwoo Park533b3682013-06-13 11:41:21 -07001894 WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001895 wcd9xxx_resmgr_put_bandgap(&tapan->resmgr,
1896 WCD9XXX_BANDGAP_AUDIO_MODE);
1897 wcd9xxx_resmgr_put_clk_block(&tapan->resmgr, WCD9XXX_CLK_RCO);
Joonwoo Park533b3682013-06-13 11:41:21 -07001898 WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001899 break;
1900 }
1901 return 0;
1902}
1903
1904static int tapan_codec_enable_lineout(struct snd_soc_dapm_widget *w,
1905 struct snd_kcontrol *kcontrol, int event)
1906{
1907 struct snd_soc_codec *codec = w->codec;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001908 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001909 u16 lineout_gain_reg;
1910
1911 dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
1912
1913 switch (w->shift) {
1914 case 0:
1915 lineout_gain_reg = TAPAN_A_RX_LINE_1_GAIN;
1916 break;
1917 case 1:
1918 lineout_gain_reg = TAPAN_A_RX_LINE_2_GAIN;
1919 break;
1920 default:
1921 pr_err("%s: Error, incorrect lineout register value\n",
1922 __func__);
1923 return -EINVAL;
1924 }
1925
1926 switch (event) {
1927 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001928 break;
1929 case SND_SOC_DAPM_POST_PMU:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001930 wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
1931 WCD9XXX_CLSH_STATE_LO,
1932 WCD9XXX_CLSH_REQ_ENABLE,
1933 WCD9XXX_CLSH_EVENT_POST_PA);
1934 dev_dbg(codec->dev, "%s: sleeping 3 ms after %s PA turn on\n",
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001935 __func__, w->name);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001936 usleep_range(3000, 3010);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001937 break;
1938 case SND_SOC_DAPM_POST_PMD:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001939 wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
1940 WCD9XXX_CLSH_STATE_LO,
1941 WCD9XXX_CLSH_REQ_DISABLE,
1942 WCD9XXX_CLSH_EVENT_POST_PA);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001943 break;
1944 }
1945 return 0;
1946}
1947
1948static int tapan_codec_enable_spk_pa(struct snd_soc_dapm_widget *w,
1949 struct snd_kcontrol *kcontrol, int event)
1950{
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001951 struct snd_soc_codec *codec = w->codec;
1952 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
1953
1954 dev_dbg(codec->dev, "%s: %s %d\n", __func__, w->name, event);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001955 switch (event) {
1956 case SND_SOC_DAPM_PRE_PMU:
1957 tapan->spkr_pa_widget_on = true;
1958 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80);
1959 break;
1960 case SND_SOC_DAPM_POST_PMD:
1961 tapan->spkr_pa_widget_on = false;
1962 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x00);
1963 break;
1964 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001965 return 0;
1966}
1967
1968static int tapan_codec_enable_dmic(struct snd_soc_dapm_widget *w,
1969 struct snd_kcontrol *kcontrol, int event)
1970{
1971 struct snd_soc_codec *codec = w->codec;
1972 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
1973 u8 dmic_clk_en;
1974 u16 dmic_clk_reg;
1975 s32 *dmic_clk_cnt;
1976 unsigned int dmic;
1977 int ret;
1978
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001979 ret = kstrtouint(strpbrk(w->name, "1234"), 10, &dmic);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001980 if (ret < 0) {
1981 pr_err("%s: Invalid DMIC line on the codec\n", __func__);
1982 return -EINVAL;
1983 }
1984
1985 switch (dmic) {
1986 case 1:
1987 case 2:
1988 dmic_clk_en = 0x01;
1989 dmic_clk_cnt = &(tapan->dmic_1_2_clk_cnt);
1990 dmic_clk_reg = TAPAN_A_CDC_CLK_DMIC_B1_CTL;
1991 dev_dbg(codec->dev, "%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n",
1992 __func__, event, dmic, *dmic_clk_cnt);
1993
1994 break;
1995
1996 case 3:
1997 case 4:
1998 dmic_clk_en = 0x10;
1999 dmic_clk_cnt = &(tapan->dmic_3_4_clk_cnt);
2000 dmic_clk_reg = TAPAN_A_CDC_CLK_DMIC_B1_CTL;
2001
2002 dev_dbg(codec->dev, "%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n",
2003 __func__, event, dmic, *dmic_clk_cnt);
2004 break;
2005
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002006 default:
2007 pr_err("%s: Invalid DMIC Selection\n", __func__);
2008 return -EINVAL;
2009 }
2010
2011 switch (event) {
2012 case SND_SOC_DAPM_PRE_PMU:
2013
2014 (*dmic_clk_cnt)++;
2015 if (*dmic_clk_cnt == 1)
2016 snd_soc_update_bits(codec, dmic_clk_reg,
2017 dmic_clk_en, dmic_clk_en);
2018
2019 break;
2020 case SND_SOC_DAPM_POST_PMD:
2021
2022 (*dmic_clk_cnt)--;
2023 if (*dmic_clk_cnt == 0)
2024 snd_soc_update_bits(codec, dmic_clk_reg,
2025 dmic_clk_en, 0);
2026 break;
2027 }
2028 return 0;
2029}
2030
2031static int tapan_codec_enable_anc(struct snd_soc_dapm_widget *w,
2032 struct snd_kcontrol *kcontrol, int event)
2033{
2034 struct snd_soc_codec *codec = w->codec;
2035 const char *filename;
2036 const struct firmware *fw;
2037 int i;
2038 int ret;
2039 int num_anc_slots;
Simmi Pateriyadf675e92013-04-05 01:15:54 +05302040 struct wcd9xxx_anc_header *anc_head;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002041 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
2042 u32 anc_writes_size = 0;
2043 int anc_size_remaining;
2044 u32 *anc_ptr;
2045 u16 reg;
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002046 u8 mask, val, old_val;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002047
2048 dev_dbg(codec->dev, "%s %d\n", __func__, event);
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002049 if (tapan->anc_func == 0)
2050 return 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002051 switch (event) {
2052 case SND_SOC_DAPM_PRE_PMU:
2053
2054 filename = "wcd9306/wcd9306_anc.bin";
2055
2056 ret = request_firmware(&fw, filename, codec->dev);
2057 if (ret != 0) {
2058 dev_err(codec->dev, "Failed to acquire ANC data: %d\n",
2059 ret);
2060 return -ENODEV;
2061 }
2062
Simmi Pateriyadf675e92013-04-05 01:15:54 +05302063 if (fw->size < sizeof(struct wcd9xxx_anc_header)) {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002064 dev_err(codec->dev, "Not enough data\n");
2065 release_firmware(fw);
2066 return -ENOMEM;
2067 }
2068
2069 /* First number is the number of register writes */
Simmi Pateriyadf675e92013-04-05 01:15:54 +05302070 anc_head = (struct wcd9xxx_anc_header *)(fw->data);
2071 anc_ptr = (u32 *)((u32)fw->data +
2072 sizeof(struct wcd9xxx_anc_header));
2073 anc_size_remaining = fw->size -
2074 sizeof(struct wcd9xxx_anc_header);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002075 num_anc_slots = anc_head->num_anc_slots;
2076
2077 if (tapan->anc_slot >= num_anc_slots) {
2078 dev_err(codec->dev, "Invalid ANC slot selected\n");
2079 release_firmware(fw);
2080 return -EINVAL;
2081 }
2082
2083 for (i = 0; i < num_anc_slots; i++) {
2084
2085 if (anc_size_remaining < TAPAN_PACKED_REG_SIZE) {
2086 dev_err(codec->dev, "Invalid register format\n");
2087 release_firmware(fw);
2088 return -EINVAL;
2089 }
2090 anc_writes_size = (u32)(*anc_ptr);
2091 anc_size_remaining -= sizeof(u32);
2092 anc_ptr += 1;
2093
2094 if (anc_writes_size * TAPAN_PACKED_REG_SIZE
2095 > anc_size_remaining) {
2096 dev_err(codec->dev, "Invalid register format\n");
2097 release_firmware(fw);
2098 return -ENOMEM;
2099 }
2100
2101 if (tapan->anc_slot == i)
2102 break;
2103
2104 anc_size_remaining -= (anc_writes_size *
2105 TAPAN_PACKED_REG_SIZE);
2106 anc_ptr += anc_writes_size;
2107 }
2108 if (i == num_anc_slots) {
2109 dev_err(codec->dev, "Selected ANC slot not present\n");
2110 release_firmware(fw);
2111 return -ENOMEM;
2112 }
2113
2114 for (i = 0; i < anc_writes_size; i++) {
2115 TAPAN_CODEC_UNPACK_ENTRY(anc_ptr[i], reg,
2116 mask, val);
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002117 old_val = snd_soc_read(codec, reg);
2118 snd_soc_write(codec, reg, (old_val & ~mask) |
2119 (val & mask));
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002120 }
2121 release_firmware(fw);
2122
2123 break;
Damir Didjusto1ede84a2013-05-23 16:38:11 -07002124 case SND_SOC_DAPM_PRE_PMD:
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002125 msleep(40);
2126 snd_soc_update_bits(codec, TAPAN_A_CDC_ANC1_B1_CTL, 0x01, 0x00);
2127 snd_soc_update_bits(codec, TAPAN_A_CDC_ANC2_B1_CTL, 0x02, 0x00);
2128 msleep(20);
2129 snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_RESET_CTL, 0x0F);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002130 snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_CLK_EN_CTL, 0);
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002131 snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_RESET_CTL, 0xFF);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002132 break;
2133 }
2134 return 0;
2135}
2136
2137static int tapan_codec_enable_micbias(struct snd_soc_dapm_widget *w,
2138 struct snd_kcontrol *kcontrol, int event)
2139{
2140 struct snd_soc_codec *codec = w->codec;
2141 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
2142 u16 micb_int_reg;
2143 u8 cfilt_sel_val = 0;
2144 char *internal1_text = "Internal1";
2145 char *internal2_text = "Internal2";
2146 char *internal3_text = "Internal3";
2147 enum wcd9xxx_notify_event e_post_off, e_pre_on, e_post_on;
2148
2149 dev_dbg(codec->dev, "%s %d\n", __func__, event);
2150 switch (w->reg) {
2151 case TAPAN_A_MICB_1_CTL:
2152 micb_int_reg = TAPAN_A_MICB_1_INT_RBIAS;
2153 cfilt_sel_val = tapan->resmgr.pdata->micbias.bias1_cfilt_sel;
2154 e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_1_ON;
2155 e_post_on = WCD9XXX_EVENT_POST_MICBIAS_1_ON;
2156 e_post_off = WCD9XXX_EVENT_POST_MICBIAS_1_OFF;
2157 break;
2158 case TAPAN_A_MICB_2_CTL:
2159 micb_int_reg = TAPAN_A_MICB_2_INT_RBIAS;
2160 cfilt_sel_val = tapan->resmgr.pdata->micbias.bias2_cfilt_sel;
2161 e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_2_ON;
2162 e_post_on = WCD9XXX_EVENT_POST_MICBIAS_2_ON;
2163 e_post_off = WCD9XXX_EVENT_POST_MICBIAS_2_OFF;
2164 break;
2165 case TAPAN_A_MICB_3_CTL:
2166 micb_int_reg = TAPAN_A_MICB_3_INT_RBIAS;
2167 cfilt_sel_val = tapan->resmgr.pdata->micbias.bias3_cfilt_sel;
2168 e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_3_ON;
2169 e_post_on = WCD9XXX_EVENT_POST_MICBIAS_3_ON;
2170 e_post_off = WCD9XXX_EVENT_POST_MICBIAS_3_OFF;
2171 break;
2172 default:
2173 pr_err("%s: Error, invalid micbias register\n", __func__);
2174 return -EINVAL;
2175 }
2176
2177 switch (event) {
2178 case SND_SOC_DAPM_PRE_PMU:
2179 /* Let MBHC module know so micbias switch to be off */
2180 wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_pre_on);
2181
2182 /* Get cfilt */
2183 wcd9xxx_resmgr_cfilt_get(&tapan->resmgr, cfilt_sel_val);
2184
2185 if (strnstr(w->name, internal1_text, 30))
2186 snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0);
2187 else if (strnstr(w->name, internal2_text, 30))
2188 snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C);
2189 else if (strnstr(w->name, internal3_text, 30))
2190 snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3);
2191
2192 break;
2193 case SND_SOC_DAPM_POST_PMU:
2194 usleep_range(20000, 20000);
2195 /* Let MBHC module know so micbias is on */
2196 wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_on);
2197 break;
2198 case SND_SOC_DAPM_POST_PMD:
2199 /* Let MBHC module know so micbias switch to be off */
2200 wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_off);
2201
2202 if (strnstr(w->name, internal1_text, 30))
2203 snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00);
2204 else if (strnstr(w->name, internal2_text, 30))
2205 snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00);
2206 else if (strnstr(w->name, internal3_text, 30))
2207 snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0);
2208
2209 /* Put cfilt */
2210 wcd9xxx_resmgr_cfilt_put(&tapan->resmgr, cfilt_sel_val);
2211 break;
2212 }
2213
2214 return 0;
2215}
2216
2217static void tx_hpf_corner_freq_callback(struct work_struct *work)
2218{
2219 struct delayed_work *hpf_delayed_work;
2220 struct hpf_work *hpf_work;
2221 struct tapan_priv *tapan;
2222 struct snd_soc_codec *codec;
2223 u16 tx_mux_ctl_reg;
2224 u8 hpf_cut_of_freq;
2225
2226 hpf_delayed_work = to_delayed_work(work);
2227 hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
2228 tapan = hpf_work->tapan;
2229 codec = hpf_work->tapan->codec;
2230 hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq;
2231
2232 tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL +
2233 (hpf_work->decimator - 1) * 8;
2234
2235 dev_dbg(codec->dev, "%s(): decimator %u hpf_cut_of_freq 0x%x\n",
2236 __func__, hpf_work->decimator, (unsigned int)hpf_cut_of_freq);
2237
2238 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4);
2239}
2240
2241#define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30
2242#define CF_MIN_3DB_4HZ 0x0
2243#define CF_MIN_3DB_75HZ 0x1
2244#define CF_MIN_3DB_150HZ 0x2
2245
2246static int tapan_codec_enable_dec(struct snd_soc_dapm_widget *w,
2247 struct snd_kcontrol *kcontrol, int event)
2248{
2249 struct snd_soc_codec *codec = w->codec;
2250 unsigned int decimator;
2251 char *dec_name = NULL;
2252 char *widget_name = NULL;
2253 char *temp;
2254 int ret = 0;
2255 u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg;
2256 u8 dec_hpf_cut_of_freq;
2257 int offset;
2258
2259 dev_dbg(codec->dev, "%s %d\n", __func__, event);
2260
2261 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
2262 if (!widget_name)
2263 return -ENOMEM;
2264 temp = widget_name;
2265
2266 dec_name = strsep(&widget_name, " ");
2267 widget_name = temp;
2268 if (!dec_name) {
2269 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
2270 ret = -EINVAL;
2271 goto out;
2272 }
2273
2274 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
2275 if (ret < 0) {
2276 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
2277 ret = -EINVAL;
2278 goto out;
2279 }
2280
2281 dev_dbg(codec->dev, "%s(): widget = %s dec_name = %s decimator = %u\n",
2282 __func__, w->name, dec_name, decimator);
2283
2284 if (w->reg == TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL) {
2285 dec_reset_reg = TAPAN_A_CDC_CLK_TX_RESET_B1_CTL;
2286 offset = 0;
2287 } else if (w->reg == TAPAN_A_CDC_CLK_TX_CLK_EN_B2_CTL) {
2288 dec_reset_reg = TAPAN_A_CDC_CLK_TX_RESET_B2_CTL;
2289 offset = 8;
2290 } else {
2291 pr_err("%s: Error, incorrect dec\n", __func__);
2292 ret = -EINVAL;
2293 goto out;
2294 }
2295
2296 tx_vol_ctl_reg = TAPAN_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator - 1);
2297 tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
2298
2299 switch (event) {
2300 case SND_SOC_DAPM_PRE_PMU:
2301
2302 /* Enableable TX digital mute */
2303 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
2304
2305 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift,
2306 1 << w->shift);
2307 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0);
2308
2309 dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg);
2310
2311 dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4;
2312
2313 tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq =
2314 dec_hpf_cut_of_freq;
2315
2316 if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) {
2317
2318 /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */
2319 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
2320 CF_MIN_3DB_150HZ << 4);
2321 }
2322
2323 /* enable HPF */
2324 snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00);
2325
2326 break;
2327
2328 case SND_SOC_DAPM_POST_PMU:
2329
2330 /* Disable TX digital mute */
2331 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00);
2332
2333 if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq !=
2334 CF_MIN_3DB_150HZ) {
2335
2336 schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork,
2337 msecs_to_jiffies(300));
2338 }
2339 /* apply the digital gain after the decimator is enabled*/
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002340 if ((w->shift + offset) < ARRAY_SIZE(tx_digital_gain_reg))
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002341 snd_soc_write(codec,
2342 tx_digital_gain_reg[w->shift + offset],
2343 snd_soc_read(codec,
2344 tx_digital_gain_reg[w->shift + offset])
2345 );
2346
2347 break;
2348
2349 case SND_SOC_DAPM_PRE_PMD:
2350
2351 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
2352 cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork);
2353 break;
2354
2355 case SND_SOC_DAPM_POST_PMD:
2356
2357 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08);
2358 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
2359 (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4);
2360
2361 break;
2362 }
2363out:
2364 kfree(widget_name);
2365 return ret;
2366}
2367
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002368static int tapan_codec_enable_vdd_spkr(struct snd_soc_dapm_widget *w,
2369 struct snd_kcontrol *kcontrol, int event)
2370{
2371 struct snd_soc_codec *codec = w->codec;
2372 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
2373
2374 dev_dbg(codec->dev, "%s: %s %d\n", __func__, w->name, event);
2375
2376 switch (event) {
2377 case SND_SOC_DAPM_PRE_PMU:
2378
2379 if (spkr_drv_wrnd > 0) {
2380 WARN_ON(!(snd_soc_read(codec, TAPAN_A_SPKR_DRV_EN) &
2381 0x80));
2382 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80,
2383 0x00);
2384 }
2385 if (TAPAN_IS_1_0(core->version))
2386 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_DBG_PWRSTG,
2387 0x24, 0x00);
2388 break;
2389 case SND_SOC_DAPM_POST_PMD:
2390 if (TAPAN_IS_1_0(core->version))
2391 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_DBG_PWRSTG,
2392 0x24, 0x24);
2393 if (spkr_drv_wrnd > 0) {
2394 WARN_ON(!!(snd_soc_read(codec, TAPAN_A_SPKR_DRV_EN) &
2395 0x80));
2396 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80,
2397 0x80);
2398 }
2399 break;
2400 }
2401 return 0;
2402}
2403
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002404static int tapan_codec_enable_interpolator(struct snd_soc_dapm_widget *w,
2405 struct snd_kcontrol *kcontrol, int event)
2406{
2407 struct snd_soc_codec *codec = w->codec;
2408
2409 dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
2410
2411 switch (event) {
2412 case SND_SOC_DAPM_PRE_PMU:
2413 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_RESET_CTL,
2414 1 << w->shift, 1 << w->shift);
2415 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_RESET_CTL,
2416 1 << w->shift, 0x0);
2417 break;
2418 case SND_SOC_DAPM_POST_PMU:
2419 /* apply the digital gain after the interpolator is enabled*/
2420 if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
2421 snd_soc_write(codec,
2422 rx_digital_gain_reg[w->shift],
2423 snd_soc_read(codec,
2424 rx_digital_gain_reg[w->shift])
2425 );
2426 break;
2427 }
2428 return 0;
2429}
2430
2431static int tapan_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
2432 struct snd_kcontrol *kcontrol, int event)
2433{
2434 switch (event) {
2435 case SND_SOC_DAPM_POST_PMU:
2436 case SND_SOC_DAPM_POST_PMD:
2437 usleep_range(1000, 1000);
2438 break;
2439 }
2440 return 0;
2441}
2442
2443static int tapan_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
2444 struct snd_kcontrol *kcontrol, int event)
2445{
2446 struct snd_soc_codec *codec = w->codec;
2447 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
2448
2449 dev_dbg(codec->dev, "%s %d\n", __func__, event);
2450
2451 switch (event) {
2452 case SND_SOC_DAPM_PRE_PMU:
2453 wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 1);
2454 break;
2455 case SND_SOC_DAPM_POST_PMD:
2456 wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 0);
2457 break;
2458 }
2459 return 0;
2460}
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002461
2462
2463static int tapan_hphl_dac_event(struct snd_soc_dapm_widget *w,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002464 struct snd_kcontrol *kcontrol, int event)
2465{
2466 struct snd_soc_codec *codec = w->codec;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002467 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002468
2469 dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
2470
2471 switch (event) {
2472 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002473 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL,
2474 0x02, 0x02);
2475 wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
2476 WCD9XXX_CLSH_STATE_HPHL,
2477 WCD9XXX_CLSH_REQ_ENABLE,
2478 WCD9XXX_CLSH_EVENT_PRE_DAC);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002479 break;
2480 case SND_SOC_DAPM_POST_PMD:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002481 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL,
2482 0x02, 0x00);
2483 }
2484 return 0;
2485}
2486
2487static int tapan_hphr_dac_event(struct snd_soc_dapm_widget *w,
2488 struct snd_kcontrol *kcontrol, int event)
2489{
2490 struct snd_soc_codec *codec = w->codec;
2491 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
2492
2493 dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
2494
2495 switch (event) {
2496 case SND_SOC_DAPM_PRE_PMU:
2497 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL,
2498 0x04, 0x04);
2499 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
2500 wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
2501 WCD9XXX_CLSH_STATE_HPHR,
2502 WCD9XXX_CLSH_REQ_ENABLE,
2503 WCD9XXX_CLSH_EVENT_PRE_DAC);
2504 break;
2505 case SND_SOC_DAPM_POST_PMD:
2506 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL,
2507 0x04, 0x00);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002508 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
2509 break;
2510 }
2511 return 0;
2512}
2513
2514static int tapan_hph_pa_event(struct snd_soc_dapm_widget *w,
2515 struct snd_kcontrol *kcontrol, int event)
2516{
2517 struct snd_soc_codec *codec = w->codec;
2518 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
2519 enum wcd9xxx_notify_event e_pre_on, e_post_off;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002520 u8 req_clsh_state;
Banajit Goswamia7294452013-06-03 12:42:35 -07002521 u32 pa_settle_time = TAPAN_HPH_PA_SETTLE_COMP_OFF;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002522
2523 dev_dbg(codec->dev, "%s: %s event = %d\n", __func__, w->name, event);
2524 if (w->shift == 5) {
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002525 e_pre_on = WCD9XXX_EVENT_PRE_HPHL_PA_ON;
2526 e_post_off = WCD9XXX_EVENT_POST_HPHL_PA_OFF;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002527 req_clsh_state = WCD9XXX_CLSH_STATE_HPHR;
Phani Kumar Uppalapatieca9a102013-06-18 11:02:38 -07002528 } else if (w->shift == 4) {
2529 e_pre_on = WCD9XXX_EVENT_PRE_HPHR_PA_ON;
2530 e_post_off = WCD9XXX_EVENT_POST_HPHR_PA_OFF;
2531 req_clsh_state = WCD9XXX_CLSH_STATE_HPHL;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002532 } else {
2533 pr_err("%s: Invalid w->shift %d\n", __func__, w->shift);
2534 return -EINVAL;
2535 }
2536
Banajit Goswamia7294452013-06-03 12:42:35 -07002537 if (tapan->comp_enabled[COMPANDER_1])
2538 pa_settle_time = TAPAN_HPH_PA_SETTLE_COMP_ON;
2539
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002540 switch (event) {
2541 case SND_SOC_DAPM_PRE_PMU:
2542 /* Let MBHC module know PA is turning on */
2543 wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_pre_on);
2544 break;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002545 case SND_SOC_DAPM_POST_PMU:
Banajit Goswamia7294452013-06-03 12:42:35 -07002546 dev_dbg(codec->dev, "%s: sleep %d ms after %s PA enable.\n",
2547 __func__, pa_settle_time / 1000, w->name);
2548 /* Time needed for PA to settle */
2549 usleep_range(pa_settle_time, pa_settle_time + 1000);
2550
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002551 wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
2552 req_clsh_state,
2553 WCD9XXX_CLSH_REQ_ENABLE,
2554 WCD9XXX_CLSH_EVENT_POST_PA);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002555
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002556 break;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002557 case SND_SOC_DAPM_POST_PMD:
Banajit Goswamia7294452013-06-03 12:42:35 -07002558 dev_dbg(codec->dev, "%s: sleep %d ms after %s PA disable.\n",
2559 __func__, pa_settle_time / 1000, w->name);
2560 /* Time needed for PA to settle */
2561 usleep_range(pa_settle_time, pa_settle_time + 1000);
2562
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002563 /* Let MBHC module know PA turned off */
2564 wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_off);
2565
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002566 wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
2567 req_clsh_state,
2568 WCD9XXX_CLSH_REQ_DISABLE,
2569 WCD9XXX_CLSH_EVENT_POST_PA);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002570 break;
2571 }
2572 return 0;
2573}
2574
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002575static int tapan_codec_enable_anc_hph(struct snd_soc_dapm_widget *w,
2576 struct snd_kcontrol *kcontrol, int event)
2577{
2578 struct snd_soc_codec *codec = w->codec;
2579 int ret = 0;
2580
2581 switch (event) {
2582 case SND_SOC_DAPM_PRE_PMU:
2583 ret = tapan_hph_pa_event(w, kcontrol, event);
2584 if (w->shift == 4) {
2585 ret |= tapan_codec_enable_anc(w, kcontrol, event);
2586 msleep(50);
2587 }
2588 break;
2589 case SND_SOC_DAPM_POST_PMU:
2590 if (w->shift == 4) {
2591 snd_soc_update_bits(codec,
2592 TAPAN_A_RX_HPH_CNP_EN, 0x30, 0x30);
2593 msleep(30);
2594 }
2595 ret = tapan_hph_pa_event(w, kcontrol, event);
2596 break;
2597 case SND_SOC_DAPM_PRE_PMD:
2598 if (w->shift == 5) {
2599 snd_soc_update_bits(codec,
2600 TAPAN_A_RX_HPH_CNP_EN, 0x30, 0x00);
2601 msleep(40);
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002602 snd_soc_update_bits(codec,
2603 TAPAN_A_TX_7_MBHC_EN, 0x80, 00);
2604 ret |= tapan_codec_enable_anc(w, kcontrol, event);
2605 }
Damir Didjusto1ede84a2013-05-23 16:38:11 -07002606 break;
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002607 case SND_SOC_DAPM_POST_PMD:
2608 ret = tapan_hph_pa_event(w, kcontrol, event);
2609 break;
2610 }
2611 return ret;
2612}
2613
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002614static const struct snd_soc_dapm_widget tapan_dapm_i2s_widgets[] = {
2615 SND_SOC_DAPM_SUPPLY("I2S_CLK", TAPAN_A_CDC_CLK_I2S_CTL,
2616 4, 0, NULL, 0),
2617};
2618
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002619static int tapan_lineout_dac_event(struct snd_soc_dapm_widget *w,
2620 struct snd_kcontrol *kcontrol, int event)
2621{
2622 struct snd_soc_codec *codec = w->codec;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002623 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002624
2625 dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
2626
2627 switch (event) {
2628 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002629 wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
2630 WCD9XXX_CLSH_STATE_LO,
2631 WCD9XXX_CLSH_REQ_ENABLE,
2632 WCD9XXX_CLSH_EVENT_PRE_DAC);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002633 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
2634 break;
2635
2636 case SND_SOC_DAPM_POST_PMD:
2637 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
2638 break;
2639 }
2640 return 0;
2641}
2642
2643static int tapan_spk_dac_event(struct snd_soc_dapm_widget *w,
2644 struct snd_kcontrol *kcontrol, int event)
2645{
2646 struct snd_soc_codec *codec = w->codec;
2647
2648 dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
2649 return 0;
2650}
2651
2652static const struct snd_soc_dapm_route audio_i2s_map[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002653 {"I2S_CLK", NULL, "CDC_CONN"},
2654 {"SLIM RX1", NULL, "I2S_CLK"},
2655 {"SLIM RX2", NULL, "I2S_CLK"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002656
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002657 {"SLIM TX1 MUX", NULL, "I2S_CLK"},
2658 {"SLIM TX2 MUX", NULL, "I2S_CLK"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002659};
2660
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07002661static const struct snd_soc_dapm_route wcd9306_map[] = {
2662 {"SLIM TX1 MUX", "RMIX4", "RX4 MIX1"},
2663 {"SLIM TX2 MUX", "RMIX4", "RX4 MIX1"},
2664 {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"},
2665 {"SLIM TX4 MUX", "RMIX4", "RX4 MIX1"},
2666 {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002667 {"SLIM TX1 MUX", "DEC3", "DEC3 MUX"},
2668 {"SLIM TX1 MUX", "DEC4", "DEC4 MUX"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002669 {"SLIM TX2 MUX", "DEC3", "DEC3 MUX"},
2670 {"SLIM TX2 MUX", "DEC4", "DEC4 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002671 {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002672 {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002673
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002674 {"ANC EAR", NULL, "ANC EAR PA"},
2675 {"ANC EAR PA", NULL, "EAR_PA_MIXER"},
2676 {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"},
2677 {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"},
2678
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002679 {"ANC HEADPHONE", NULL, "ANC HPHL"},
2680 {"ANC HEADPHONE", NULL, "ANC HPHR"},
2681
2682 {"ANC HPHL", NULL, "HPHL_PA_MIXER"},
2683 {"ANC HPHR", NULL, "HPHR_PA_MIXER"},
2684
2685 {"ANC1 MUX", "ADC1", "ADC1"},
2686 {"ANC1 MUX", "ADC2", "ADC2"},
2687 {"ANC1 MUX", "ADC3", "ADC3"},
2688 {"ANC1 MUX", "ADC4", "ADC4"},
2689 {"ANC1 MUX", "ADC5", "ADC5"},
2690 {"ANC1 MUX", "DMIC1", "DMIC1"},
2691 {"ANC1 MUX", "DMIC2", "DMIC2"},
2692 {"ANC1 MUX", "DMIC3", "DMIC3"},
2693 {"ANC1 MUX", "DMIC4", "DMIC4"},
2694 {"ANC2 MUX", "ADC1", "ADC1"},
2695 {"ANC2 MUX", "ADC2", "ADC2"},
2696 {"ANC2 MUX", "ADC3", "ADC3"},
2697 {"ANC2 MUX", "ADC4", "ADC4"},
2698 {"ANC2 MUX", "ADC5", "ADC5"},
2699 {"ANC2 MUX", "DMIC1", "DMIC1"},
2700 {"ANC2 MUX", "DMIC2", "DMIC2"},
2701 {"ANC2 MUX", "DMIC3", "DMIC3"},
2702 {"ANC2 MUX", "DMIC4", "DMIC4"},
2703
2704 {"ANC HPHR", NULL, "CDC_CONN"},
2705
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07002706 {"RDAC5 MUX", "DEM4", "RX4 MIX2"},
2707 {"SPK DAC", "Switch", "RX4 MIX2"},
2708
2709 {"RX1 MIX2", NULL, "ANC1 MUX"},
2710 {"RX2 MIX2", NULL, "ANC2 MUX"},
2711
2712 {"RX1 MIX1", NULL, "COMP1_CLK"},
2713 {"RX2 MIX1", NULL, "COMP1_CLK"},
2714 {"RX3 MIX1", NULL, "COMP2_CLK"},
2715 {"RX4 MIX1", NULL, "COMP0_CLK"},
2716
2717 {"RX4 MIX1", NULL, "RX4 MIX1 INP1"},
2718 {"RX4 MIX1", NULL, "RX4 MIX1 INP2"},
2719 {"RX4 MIX2", NULL, "RX4 MIX1"},
2720 {"RX4 MIX2", NULL, "RX4 MIX2 INP1"},
2721 {"RX4 MIX2", NULL, "RX4 MIX2 INP2"},
2722
2723 {"RX4 MIX1 INP1", "RX1", "SLIM RX1"},
2724 {"RX4 MIX1 INP1", "RX2", "SLIM RX2"},
2725 {"RX4 MIX1 INP1", "RX3", "SLIM RX3"},
2726 {"RX4 MIX1 INP1", "RX4", "SLIM RX4"},
2727 {"RX4 MIX1 INP1", "RX5", "SLIM RX5"},
2728 {"RX4 MIX1 INP1", "IIR1", "IIR1"},
2729 {"RX4 MIX1 INP2", "RX1", "SLIM RX1"},
2730 {"RX4 MIX1 INP2", "RX2", "SLIM RX2"},
2731 {"RX4 MIX1 INP2", "RX3", "SLIM RX3"},
2732 {"RX4 MIX1 INP2", "RX5", "SLIM RX5"},
2733 {"RX4 MIX1 INP2", "RX4", "SLIM RX4"},
2734 {"RX4 MIX1 INP2", "IIR1", "IIR1"},
2735 {"RX4 MIX2 INP1", "IIR1", "IIR1"},
2736 {"RX4 MIX2 INP2", "IIR1", "IIR1"},
2737
2738 {"DEC1 MUX", "DMIC3", "DMIC3"},
2739 {"DEC1 MUX", "DMIC4", "DMIC4"},
2740 {"DEC2 MUX", "DMIC3", "DMIC3"},
2741 {"DEC2 MUX", "DMIC4", "DMIC4"},
2742
2743 {"DEC3 MUX", "ADC1", "ADC1"},
2744 {"DEC3 MUX", "ADC2", "ADC2"},
2745 {"DEC3 MUX", "ADC3", "ADC3"},
2746 {"DEC3 MUX", "ADC4", "ADC4"},
2747 {"DEC3 MUX", "ADC5", "ADC5"},
2748 {"DEC3 MUX", "DMIC1", "DMIC1"},
2749 {"DEC3 MUX", "DMIC2", "DMIC2"},
2750 {"DEC3 MUX", "DMIC3", "DMIC3"},
2751 {"DEC3 MUX", "DMIC4", "DMIC4"},
2752 {"DEC3 MUX", NULL, "CDC_CONN"},
2753
2754 {"DEC4 MUX", "ADC1", "ADC1"},
2755 {"DEC4 MUX", "ADC2", "ADC2"},
2756 {"DEC4 MUX", "ADC3", "ADC3"},
2757 {"DEC4 MUX", "ADC4", "ADC4"},
2758 {"DEC4 MUX", "ADC5", "ADC5"},
2759 {"DEC4 MUX", "DMIC1", "DMIC1"},
2760 {"DEC4 MUX", "DMIC2", "DMIC2"},
2761 {"DEC4 MUX", "DMIC3", "DMIC3"},
2762 {"DEC4 MUX", "DMIC4", "DMIC4"},
2763 {"DEC4 MUX", NULL, "CDC_CONN"},
2764
2765 {"ADC5", NULL, "AMIC5"},
2766
2767 {"AUX_PGA_Left", NULL, "AMIC5"},
2768
2769 {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"},
2770 {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"},
2771
2772 {"MIC BIAS3 Internal1", NULL, "LDO_H"},
2773 {"MIC BIAS3 Internal2", NULL, "LDO_H"},
2774 {"MIC BIAS3 External", NULL, "LDO_H"},
2775};
2776
2777static const struct snd_soc_dapm_route audio_map[] = {
2778 /* SLIMBUS Connections */
2779 {"AIF1 CAP", NULL, "AIF1_CAP Mixer"},
2780 {"AIF2 CAP", NULL, "AIF2_CAP Mixer"},
2781 {"AIF3 CAP", NULL, "AIF3_CAP Mixer"},
2782
2783 /* SLIM_MIXER("AIF1_CAP Mixer"),*/
2784 {"AIF1_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
2785 {"AIF1_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
2786 {"AIF1_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
2787 {"AIF1_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
2788 {"AIF1_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
2789 /* SLIM_MIXER("AIF2_CAP Mixer"),*/
2790 {"AIF2_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
2791 {"AIF2_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
2792 {"AIF2_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
2793 {"AIF2_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
2794 {"AIF2_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
2795 /* SLIM_MIXER("AIF3_CAP Mixer"),*/
2796 {"AIF3_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
2797 {"AIF3_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
2798 {"AIF3_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
2799 {"AIF3_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
2800 {"AIF3_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
2801
2802 {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"},
2803 {"SLIM TX1 MUX", "DEC2", "DEC2 MUX"},
2804 {"SLIM TX1 MUX", "RMIX1", "RX1 MIX1"},
2805 {"SLIM TX1 MUX", "RMIX2", "RX2 MIX1"},
2806 {"SLIM TX1 MUX", "RMIX3", "RX3 MIX1"},
2807
2808 {"SLIM TX2 MUX", "DEC1", "DEC1 MUX"},
2809 {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"},
2810 {"SLIM TX2 MUX", "RMIX1", "RX1 MIX1"},
2811 {"SLIM TX2 MUX", "RMIX2", "RX2 MIX1"},
2812 {"SLIM TX2 MUX", "RMIX3", "RX3 MIX1"},
2813
2814 {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"},
2815 {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"},
2816 {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"},
2817
2818 {"SLIM TX4 MUX", "RMIX1", "RX1 MIX1"},
2819 {"SLIM TX4 MUX", "RMIX2", "RX2 MIX1"},
2820 {"SLIM TX4 MUX", "RMIX3", "RX3 MIX1"},
2821
2822 {"SLIM TX5 MUX", "DEC1", "DEC1 MUX"},
2823 {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"},
2824 {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"},
2825 {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"},
2826
2827 /* Earpiece (RX MIX1) */
2828 {"EAR", NULL, "EAR PA"},
2829 {"EAR PA", NULL, "EAR_PA_MIXER"},
2830 {"EAR_PA_MIXER", NULL, "DAC1"},
2831 {"DAC1", NULL, "RX_BIAS"},
2832 {"DAC1", NULL, "CDC_CP_VDD"},
2833
2834
2835 /* Headset (RX MIX1 and RX MIX2) */
2836 {"HEADPHONE", NULL, "HPHL"},
2837 {"HEADPHONE", NULL, "HPHR"},
2838
2839 {"HPHL", NULL, "HPHL_PA_MIXER"},
2840 {"HPHL_PA_MIXER", NULL, "HPHL DAC"},
2841 {"HPHL DAC", NULL, "RX_BIAS"},
2842 {"HPHL DAC", NULL, "CDC_CP_VDD"},
2843
2844 {"HPHR", NULL, "HPHR_PA_MIXER"},
2845 {"HPHR_PA_MIXER", NULL, "HPHR DAC"},
2846 {"HPHR DAC", NULL, "RX_BIAS"},
2847 {"HPHR DAC", NULL, "CDC_CP_VDD"},
2848
2849
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002850 {"DAC1", "Switch", "CLASS_H_DSM MUX"},
2851 {"HPHL DAC", "Switch", "CLASS_H_DSM MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002852 {"HPHR DAC", NULL, "RX2 CHAIN"},
2853
2854 {"LINEOUT1", NULL, "LINEOUT1 PA"},
2855 {"LINEOUT2", NULL, "LINEOUT2 PA"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002856 {"SPK_OUT", NULL, "SPK PA"},
2857
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002858 {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"},
2859 {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002860 {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"},
2861 {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"},
2862
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002863 {"LINEOUT1 DAC", NULL, "RX3 MIX1"},
2864
2865 {"RDAC5 MUX", "DEM3_INV", "RX3 MIX1"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002866 {"LINEOUT2 DAC", NULL, "RDAC5 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002867
2868 {"SPK PA", NULL, "SPK DAC"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002869 {"SPK DAC", NULL, "VDD_SPKDRV"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002870
2871 {"RX1 CHAIN", NULL, "RX1 MIX2"},
2872 {"RX2 CHAIN", NULL, "RX2 MIX2"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002873 {"CLASS_H_DSM MUX", "RX_HPHL", "RX1 CHAIN"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002874
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002875 {"LINEOUT1 DAC", NULL, "RX_BIAS"},
2876 {"LINEOUT2 DAC", NULL, "RX_BIAS"},
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07002877 {"LINEOUT1 DAC", NULL, "CDC_CP_VDD"},
2878 {"LINEOUT2 DAC", NULL, "CDC_CP_VDD"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002879
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07002880 {"RDAC3 MUX", "DEM2", "RX2 MIX1"},
2881 {"RDAC3 MUX", "DEM1", "RX1 CHAIN"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002882
2883 {"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
2884 {"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
2885 {"RX1 MIX1", NULL, "RX1 MIX1 INP3"},
2886 {"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
2887 {"RX2 MIX1", NULL, "RX2 MIX1 INP2"},
2888 {"RX3 MIX1", NULL, "RX3 MIX1 INP1"},
2889 {"RX3 MIX1", NULL, "RX3 MIX1 INP2"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002890 {"RX1 MIX2", NULL, "RX1 MIX1"},
2891 {"RX1 MIX2", NULL, "RX1 MIX2 INP1"},
2892 {"RX1 MIX2", NULL, "RX1 MIX2 INP2"},
2893 {"RX2 MIX2", NULL, "RX2 MIX1"},
2894 {"RX2 MIX2", NULL, "RX2 MIX2 INP1"},
2895 {"RX2 MIX2", NULL, "RX2 MIX2 INP2"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002896
2897 /* SLIM_MUX("AIF1_PB", "AIF1 PB"),*/
2898 {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"},
2899 {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"},
2900 {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"},
2901 {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"},
2902 {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002903 /* SLIM_MUX("AIF2_PB", "AIF2 PB"),*/
2904 {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"},
2905 {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"},
2906 {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"},
2907 {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"},
2908 {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002909 /* SLIM_MUX("AIF3_PB", "AIF3 PB"),*/
2910 {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"},
2911 {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"},
2912 {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"},
2913 {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"},
2914 {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002915
2916 {"SLIM RX1", NULL, "SLIM RX1 MUX"},
2917 {"SLIM RX2", NULL, "SLIM RX2 MUX"},
2918 {"SLIM RX3", NULL, "SLIM RX3 MUX"},
2919 {"SLIM RX4", NULL, "SLIM RX4 MUX"},
2920 {"SLIM RX5", NULL, "SLIM RX5 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002921
2922 {"RX1 MIX1 INP1", "RX1", "SLIM RX1"},
2923 {"RX1 MIX1 INP1", "RX2", "SLIM RX2"},
2924 {"RX1 MIX1 INP1", "RX3", "SLIM RX3"},
2925 {"RX1 MIX1 INP1", "RX4", "SLIM RX4"},
2926 {"RX1 MIX1 INP1", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002927 {"RX1 MIX1 INP1", "IIR1", "IIR1"},
2928 {"RX1 MIX1 INP2", "RX1", "SLIM RX1"},
2929 {"RX1 MIX1 INP2", "RX2", "SLIM RX2"},
2930 {"RX1 MIX1 INP2", "RX3", "SLIM RX3"},
2931 {"RX1 MIX1 INP2", "RX4", "SLIM RX4"},
2932 {"RX1 MIX1 INP2", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002933 {"RX1 MIX1 INP2", "IIR1", "IIR1"},
2934 {"RX1 MIX1 INP3", "RX1", "SLIM RX1"},
2935 {"RX1 MIX1 INP3", "RX2", "SLIM RX2"},
2936 {"RX1 MIX1 INP3", "RX3", "SLIM RX3"},
2937 {"RX1 MIX1 INP3", "RX4", "SLIM RX4"},
2938 {"RX1 MIX1 INP3", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002939 {"RX2 MIX1 INP1", "RX1", "SLIM RX1"},
2940 {"RX2 MIX1 INP1", "RX2", "SLIM RX2"},
2941 {"RX2 MIX1 INP1", "RX3", "SLIM RX3"},
2942 {"RX2 MIX1 INP1", "RX4", "SLIM RX4"},
2943 {"RX2 MIX1 INP1", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002944 {"RX2 MIX1 INP1", "IIR1", "IIR1"},
2945 {"RX2 MIX1 INP2", "RX1", "SLIM RX1"},
2946 {"RX2 MIX1 INP2", "RX2", "SLIM RX2"},
2947 {"RX2 MIX1 INP2", "RX3", "SLIM RX3"},
2948 {"RX2 MIX1 INP2", "RX4", "SLIM RX4"},
2949 {"RX2 MIX1 INP2", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002950 {"RX2 MIX1 INP2", "IIR1", "IIR1"},
2951 {"RX3 MIX1 INP1", "RX1", "SLIM RX1"},
2952 {"RX3 MIX1 INP1", "RX2", "SLIM RX2"},
2953 {"RX3 MIX1 INP1", "RX3", "SLIM RX3"},
2954 {"RX3 MIX1 INP1", "RX4", "SLIM RX4"},
2955 {"RX3 MIX1 INP1", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002956 {"RX3 MIX1 INP1", "IIR1", "IIR1"},
2957 {"RX3 MIX1 INP2", "RX1", "SLIM RX1"},
2958 {"RX3 MIX1 INP2", "RX2", "SLIM RX2"},
2959 {"RX3 MIX1 INP2", "RX3", "SLIM RX3"},
2960 {"RX3 MIX1 INP2", "RX4", "SLIM RX4"},
2961 {"RX3 MIX1 INP2", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002962 {"RX3 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002963
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002964 {"RX1 MIX2 INP1", "IIR1", "IIR1"},
2965 {"RX1 MIX2 INP2", "IIR1", "IIR1"},
2966 {"RX2 MIX2 INP1", "IIR1", "IIR1"},
2967 {"RX2 MIX2 INP2", "IIR1", "IIR1"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002968
2969 /* Decimator Inputs */
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002970 {"DEC1 MUX", "ADC1", "ADC1"},
2971 {"DEC1 MUX", "ADC2", "ADC2"},
2972 {"DEC1 MUX", "ADC3", "ADC3"},
2973 {"DEC1 MUX", "ADC4", "ADC4"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002974 {"DEC1 MUX", "DMIC1", "DMIC1"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002975 {"DEC1 MUX", "DMIC2", "DMIC2"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002976 {"DEC1 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002977
2978 {"DEC2 MUX", "ADC1", "ADC1"},
2979 {"DEC2 MUX", "ADC2", "ADC2"},
2980 {"DEC2 MUX", "ADC3", "ADC3"},
2981 {"DEC2 MUX", "ADC4", "ADC4"},
2982 {"DEC2 MUX", "DMIC1", "DMIC1"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002983 {"DEC2 MUX", "DMIC2", "DMIC2"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002984 {"DEC2 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002985
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002986 /* ADC Connections */
2987 {"ADC1", NULL, "AMIC1"},
2988 {"ADC2", NULL, "AMIC2"},
2989 {"ADC3", NULL, "AMIC3"},
2990 {"ADC4", NULL, "AMIC4"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002991
2992 /* AUX PGA Connections */
2993 {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
2994 {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
2995 {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
2996 {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
2997 {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002998
2999 {"IIR1", NULL, "IIR1 INP1 MUX"},
3000 {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"},
3001 {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003002
3003 {"MIC BIAS1 Internal1", NULL, "LDO_H"},
3004 {"MIC BIAS1 Internal2", NULL, "LDO_H"},
3005 {"MIC BIAS1 External", NULL, "LDO_H"},
3006 {"MIC BIAS2 Internal1", NULL, "LDO_H"},
3007 {"MIC BIAS2 Internal2", NULL, "LDO_H"},
3008 {"MIC BIAS2 Internal3", NULL, "LDO_H"},
3009 {"MIC BIAS2 External", NULL, "LDO_H"},
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07003010};
3011
3012static const struct snd_soc_dapm_route wcd9302_map[] = {
3013 {"SPK DAC", "Switch", "RX3 MIX1"},
3014
3015 {"RDAC4 MUX", "DEM3", "RX3 MIX1"},
3016 {"RDAC4 MUX", "DEM2", "RX2 CHAIN"},
3017 {"LINEOUT1 DAC", NULL, "RDAC4 MUX"},
3018
3019 {"RDAC5 MUX", "DEM4", "RX3 MIX1"},
3020 {"RDAC5 MUX", "DEM3_INV", "RDAC4 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003021};
3022
3023static int tapan_readable(struct snd_soc_codec *ssc, unsigned int reg)
3024{
3025 return tapan_reg_readable[reg];
3026}
3027
3028static bool tapan_is_digital_gain_register(unsigned int reg)
3029{
3030 bool rtn = false;
3031 switch (reg) {
3032 case TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL:
3033 case TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL:
3034 case TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL:
3035 case TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL:
3036 case TAPAN_A_CDC_TX1_VOL_CTL_GAIN:
3037 case TAPAN_A_CDC_TX2_VOL_CTL_GAIN:
3038 case TAPAN_A_CDC_TX3_VOL_CTL_GAIN:
3039 case TAPAN_A_CDC_TX4_VOL_CTL_GAIN:
3040 rtn = true;
3041 break;
3042 default:
3043 break;
3044 }
3045 return rtn;
3046}
3047
3048static int tapan_volatile(struct snd_soc_codec *ssc, unsigned int reg)
3049{
Damir Didjustod6aea992013-09-03 21:18:59 -07003050
3051 int i = 0;
3052
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003053 /* Registers lower than 0x100 are top level registers which can be
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003054 * written by the Tapan core driver.
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003055 */
3056
3057 if ((reg >= TAPAN_A_CDC_MBHC_EN_CTL) || (reg < 0x100))
3058 return 1;
3059
3060 /* IIR Coeff registers are not cacheable */
3061 if ((reg >= TAPAN_A_CDC_IIR1_COEF_B1_CTL) &&
3062 (reg <= TAPAN_A_CDC_IIR2_COEF_B2_CTL))
3063 return 1;
3064
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07003065 /* ANC filter registers are not cacheable */
3066 if ((reg >= TAPAN_A_CDC_ANC1_IIR_B1_CTL) &&
3067 (reg <= TAPAN_A_CDC_ANC1_LPF_B2_CTL))
3068 return 1;
3069 if ((reg >= TAPAN_A_CDC_ANC2_IIR_B1_CTL) &&
3070 (reg <= TAPAN_A_CDC_ANC2_LPF_B2_CTL))
3071 return 1;
3072
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003073 /* Digital gain register is not cacheable so we have to write
3074 * the setting even it is the same
3075 */
3076 if (tapan_is_digital_gain_register(reg))
3077 return 1;
3078
3079 /* HPH status registers */
3080 if (reg == TAPAN_A_RX_HPH_L_STATUS || reg == TAPAN_A_RX_HPH_R_STATUS)
3081 return 1;
3082
3083 if (reg == TAPAN_A_MBHC_INSERT_DET_STATUS)
3084 return 1;
3085
Damir Didjustod6aea992013-09-03 21:18:59 -07003086 for (i = 0; i < ARRAY_SIZE(audio_reg_cfg); i++)
3087 if (audio_reg_cfg[i].reg_logical_addr -
3088 TAPAN_REGISTER_START_OFFSET == reg)
3089 return 1;
3090
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003091 return 0;
3092}
3093
3094#define TAPAN_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
3095static int tapan_write(struct snd_soc_codec *codec, unsigned int reg,
3096 unsigned int value)
3097{
3098 int ret;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07003099 struct wcd9xxx *wcd9xxx = codec->control_data;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003100
3101 if (reg == SND_SOC_NOPM)
3102 return 0;
3103
3104 BUG_ON(reg > TAPAN_MAX_REGISTER);
3105
3106 if (!tapan_volatile(codec, reg)) {
3107 ret = snd_soc_cache_write(codec, reg, value);
3108 if (ret != 0)
3109 dev_err(codec->dev, "Cache write to %x failed: %d\n",
3110 reg, ret);
3111 }
3112
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07003113 return wcd9xxx_reg_write(&wcd9xxx->core_res, reg, value);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003114}
3115static unsigned int tapan_read(struct snd_soc_codec *codec,
3116 unsigned int reg)
3117{
3118 unsigned int val;
3119 int ret;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07003120 struct wcd9xxx *wcd9xxx = codec->control_data;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003121
3122 if (reg == SND_SOC_NOPM)
3123 return 0;
3124
3125 BUG_ON(reg > TAPAN_MAX_REGISTER);
3126
3127 if (!tapan_volatile(codec, reg) && tapan_readable(codec, reg) &&
3128 reg < codec->driver->reg_cache_size) {
3129 ret = snd_soc_cache_read(codec, reg, &val);
3130 if (ret >= 0) {
3131 return val;
3132 } else
3133 dev_err(codec->dev, "Cache read from %x failed: %d\n",
3134 reg, ret);
3135 }
3136
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07003137 val = wcd9xxx_reg_read(&wcd9xxx->core_res, reg);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003138 return val;
3139}
3140
3141static int tapan_startup(struct snd_pcm_substream *substream,
3142 struct snd_soc_dai *dai)
3143{
3144 struct wcd9xxx *tapan_core = dev_get_drvdata(dai->codec->dev->parent);
3145 dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n",
3146 __func__, substream->name, substream->stream);
3147 if ((tapan_core != NULL) &&
3148 (tapan_core->dev != NULL) &&
3149 (tapan_core->dev->parent != NULL))
3150 pm_runtime_get_sync(tapan_core->dev->parent);
3151
3152 return 0;
3153}
3154
3155static void tapan_shutdown(struct snd_pcm_substream *substream,
3156 struct snd_soc_dai *dai)
3157{
3158 struct wcd9xxx *tapan_core = dev_get_drvdata(dai->codec->dev->parent);
3159 dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n",
3160 __func__, substream->name, substream->stream);
3161 if ((tapan_core != NULL) &&
3162 (tapan_core->dev != NULL) &&
3163 (tapan_core->dev->parent != NULL)) {
3164 pm_runtime_mark_last_busy(tapan_core->dev->parent);
3165 pm_runtime_put(tapan_core->dev->parent);
3166 }
3167}
3168
Bhalchandra Gajare4e3dd852013-08-19 17:21:23 -07003169static void tapan_set_vdd_cx_current(struct snd_soc_codec *codec,
3170 int current_uA)
3171{
3172 struct regulator *cx_regulator;
3173 int ret;
3174
3175 cx_regulator = tapan_codec_find_regulator(codec,
3176 "cdc-vdd-cx");
3177
3178 if (!cx_regulator) {
3179 dev_err(codec->dev, "%s: Regulator %s not defined\n",
3180 __func__, "cdc-vdd-cx-supply");
3181 return;
3182 }
3183
3184 ret = regulator_set_optimum_mode(cx_regulator, current_uA);
3185 if (ret < 0)
3186 dev_err(codec->dev,
3187 "%s: Failed to set vdd_cx current to %d\n",
3188 __func__, current_uA);
3189}
3190
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003191int tapan_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, bool dapm)
3192{
3193 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
3194
3195 dev_dbg(codec->dev, "%s: mclk_enable = %u, dapm = %d\n", __func__,
3196 mclk_enable, dapm);
3197
Joonwoo Park533b3682013-06-13 11:41:21 -07003198 WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003199 if (mclk_enable) {
Bhalchandra Gajare4e3dd852013-08-19 17:21:23 -07003200 tapan_set_vdd_cx_current(codec, TAPAN_VDD_CX_OPTIMAL_UA);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003201 wcd9xxx_resmgr_get_bandgap(&tapan->resmgr,
3202 WCD9XXX_BANDGAP_AUDIO_MODE);
3203 wcd9xxx_resmgr_get_clk_block(&tapan->resmgr, WCD9XXX_CLK_MCLK);
3204 } else {
3205 /* Put clock and BG */
3206 wcd9xxx_resmgr_put_clk_block(&tapan->resmgr, WCD9XXX_CLK_MCLK);
3207 wcd9xxx_resmgr_put_bandgap(&tapan->resmgr,
3208 WCD9XXX_BANDGAP_AUDIO_MODE);
Bhalchandra Gajare4e3dd852013-08-19 17:21:23 -07003209 /* Set the vdd cx power rail sleep mode current */
3210 tapan_set_vdd_cx_current(codec, TAPAN_VDD_CX_SLEEP_UA);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003211 }
Joonwoo Park533b3682013-06-13 11:41:21 -07003212 WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003213
3214 return 0;
3215}
3216
3217static int tapan_set_dai_sysclk(struct snd_soc_dai *dai,
3218 int clk_id, unsigned int freq, int dir)
3219{
3220 dev_dbg(dai->codec->dev, "%s\n", __func__);
3221 return 0;
3222}
3223
3224static int tapan_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3225{
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003226 u8 val = 0;
3227 struct snd_soc_codec *codec = dai->codec;
3228 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
3229
3230 dev_dbg(codec->dev, "%s\n", __func__);
3231 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
3232 case SND_SOC_DAIFMT_CBS_CFS:
3233 /* CPU is master */
3234 if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
3235 if (dai->id == AIF1_CAP)
3236 snd_soc_update_bits(codec,
3237 TAPAN_A_CDC_CLK_I2S_CTL,
3238 TAPAN_I2S_MASTER_MODE_MASK, 0);
3239 else if (dai->id == AIF1_PB)
3240 snd_soc_update_bits(codec,
3241 TAPAN_A_CDC_CLK_I2S_CTL,
3242 TAPAN_I2S_MASTER_MODE_MASK, 0);
3243 }
3244 break;
3245 case SND_SOC_DAIFMT_CBM_CFM:
3246 /* CPU is slave */
3247 if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
3248 val = TAPAN_I2S_MASTER_MODE_MASK;
3249 if (dai->id == AIF1_CAP)
3250 snd_soc_update_bits(codec,
3251 TAPAN_A_CDC_CLK_I2S_CTL, val, val);
3252 else if (dai->id == AIF1_PB)
3253 snd_soc_update_bits(codec,
3254 TAPAN_A_CDC_CLK_I2S_CTL, val, val);
3255 }
3256 break;
3257 default:
3258 return -EINVAL;
3259 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003260 return 0;
3261}
3262
3263static int tapan_set_channel_map(struct snd_soc_dai *dai,
3264 unsigned int tx_num, unsigned int *tx_slot,
3265 unsigned int rx_num, unsigned int *rx_slot)
3266
3267{
3268 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(dai->codec);
3269 struct wcd9xxx *core = dev_get_drvdata(dai->codec->dev->parent);
3270 if (!tx_slot && !rx_slot) {
3271 pr_err("%s: Invalid\n", __func__);
3272 return -EINVAL;
3273 }
3274 dev_dbg(dai->codec->dev, "%s(): dai_name = %s DAI-ID %x\n",
3275 __func__, dai->name, dai->id);
3276 dev_dbg(dai->codec->dev, "%s(): tx_ch %d rx_ch %d\n intf_type %d\n",
3277 __func__, tx_num, rx_num, tapan->intf_type);
3278
3279 if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
3280 wcd9xxx_init_slimslave(core, core->slim->laddr,
3281 tx_num, tx_slot, rx_num, rx_slot);
3282 return 0;
3283}
3284
3285static int tapan_get_channel_map(struct snd_soc_dai *dai,
3286 unsigned int *tx_num, unsigned int *tx_slot,
3287 unsigned int *rx_num, unsigned int *rx_slot)
3288
3289{
3290 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(dai->codec);
3291 u32 i = 0;
3292 struct wcd9xxx_ch *ch;
3293
3294 switch (dai->id) {
3295 case AIF1_PB:
3296 case AIF2_PB:
3297 case AIF3_PB:
3298 if (!rx_slot || !rx_num) {
3299 pr_err("%s: Invalid rx_slot %d or rx_num %d\n",
3300 __func__, (u32) rx_slot, (u32) rx_num);
3301 return -EINVAL;
3302 }
3303 list_for_each_entry(ch, &tapan_p->dai[dai->id].wcd9xxx_ch_list,
3304 list) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003305 dev_dbg(dai->codec->dev, "%s: rx_slot[%d] %d, ch->ch_num %d\n",
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003306 __func__, i, rx_slot[i], ch->ch_num);
3307 rx_slot[i++] = ch->ch_num;
3308 }
3309 dev_dbg(dai->codec->dev, "%s: rx_num %d\n", __func__, i);
3310 *rx_num = i;
3311 break;
3312 case AIF1_CAP:
3313 case AIF2_CAP:
3314 case AIF3_CAP:
3315 if (!tx_slot || !tx_num) {
3316 pr_err("%s: Invalid tx_slot %d or tx_num %d\n",
3317 __func__, (u32) tx_slot, (u32) tx_num);
3318 return -EINVAL;
3319 }
3320 list_for_each_entry(ch, &tapan_p->dai[dai->id].wcd9xxx_ch_list,
3321 list) {
3322 dev_dbg(dai->codec->dev, "%s: tx_slot[%d] %d, ch->ch_num %d\n",
3323 __func__, i, tx_slot[i], ch->ch_num);
3324 tx_slot[i++] = ch->ch_num;
3325 }
3326 dev_dbg(dai->codec->dev, "%s: tx_num %d\n", __func__, i);
3327 *tx_num = i;
3328 break;
3329
3330 default:
3331 pr_err("%s: Invalid DAI ID %x\n", __func__, dai->id);
3332 break;
3333 }
3334
3335 return 0;
3336}
3337
3338static int tapan_set_interpolator_rate(struct snd_soc_dai *dai,
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003339 u8 rx_fs_rate_reg_val, u32 compander_fs, u32 sample_rate)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003340{
3341 u32 j;
3342 u8 rx_mix1_inp;
3343 u16 rx_mix_1_reg_1, rx_mix_1_reg_2;
3344 u16 rx_fs_reg;
3345 u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val;
Banajit Goswamia7294452013-06-03 12:42:35 -07003346 u8 rdac5_mux;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003347 struct snd_soc_codec *codec = dai->codec;
3348 struct wcd9xxx_ch *ch;
3349 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
3350
3351 list_for_each_entry(ch, &tapan->dai[dai->id].wcd9xxx_ch_list, list) {
3352 /* for RX port starting from 16 instead of 10 like tabla */
3353 rx_mix1_inp = ch->port + RX_MIX1_INP_SEL_RX1 -
3354 TAPAN_TX_PORT_NUMBER;
3355 if ((rx_mix1_inp < RX_MIX1_INP_SEL_RX1) ||
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003356 (rx_mix1_inp > RX_MIX1_INP_SEL_RX5)) {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003357 pr_err("%s: Invalid TAPAN_RX%u port. Dai ID is %d\n",
3358 __func__, rx_mix1_inp - 5 , dai->id);
3359 return -EINVAL;
3360 }
3361
3362 rx_mix_1_reg_1 = TAPAN_A_CDC_CONN_RX1_B1_CTL;
3363
Banajit Goswamia7294452013-06-03 12:42:35 -07003364 rdac5_mux = snd_soc_read(codec, TAPAN_A_CDC_CONN_MISC);
3365 rdac5_mux = (rdac5_mux & 0x04) >> 2;
3366
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003367 for (j = 0; j < NUM_INTERPOLATORS; j++) {
3368 rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1;
3369
3370 rx_mix_1_reg_1_val = snd_soc_read(codec,
3371 rx_mix_1_reg_1);
3372 rx_mix_1_reg_2_val = snd_soc_read(codec,
3373 rx_mix_1_reg_2);
3374
3375 if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) ||
3376 (((rx_mix_1_reg_1_val >> 4) & 0x0F)
3377 == rx_mix1_inp) ||
3378 ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) {
3379
3380 rx_fs_reg = TAPAN_A_CDC_RX1_B5_CTL + 8 * j;
3381
3382 dev_dbg(codec->dev, "%s: AIF_PB DAI(%d) connected to RX%u\n",
3383 __func__, dai->id, j + 1);
3384
3385 dev_dbg(codec->dev, "%s: set RX%u sample rate to %u\n",
3386 __func__, j + 1, sample_rate);
3387
3388 snd_soc_update_bits(codec, rx_fs_reg,
3389 0xE0, rx_fs_rate_reg_val);
3390
Banajit Goswamia7294452013-06-03 12:42:35 -07003391 if (comp_rx_path[j] < COMPANDER_MAX) {
3392 if ((j == 3) && (rdac5_mux == 1))
3393 tapan->comp_fs[COMPANDER_0] =
3394 compander_fs;
3395 else
3396 tapan->comp_fs[comp_rx_path[j]]
3397 = compander_fs;
3398 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003399 }
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07003400 if (j <= 1)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003401 rx_mix_1_reg_1 += 3;
3402 else
3403 rx_mix_1_reg_1 += 2;
3404 }
3405 }
3406 return 0;
3407}
3408
3409static int tapan_set_decimator_rate(struct snd_soc_dai *dai,
3410 u8 tx_fs_rate_reg_val, u32 sample_rate)
3411{
3412 struct snd_soc_codec *codec = dai->codec;
3413 struct wcd9xxx_ch *ch;
3414 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
3415 u32 tx_port;
3416 u16 tx_port_reg, tx_fs_reg;
3417 u8 tx_port_reg_val;
3418 s8 decimator;
3419
3420 list_for_each_entry(ch, &tapan->dai[dai->id].wcd9xxx_ch_list, list) {
3421
3422 tx_port = ch->port + 1;
3423 dev_dbg(codec->dev, "%s: dai->id = %d, tx_port = %d",
3424 __func__, dai->id, tx_port);
3425
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003426 if ((tx_port < 1) || (tx_port > TAPAN_SLIM_CODEC_TX_PORTS)) {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003427 pr_err("%s: Invalid SLIM TX%u port. DAI ID is %d\n",
3428 __func__, tx_port, dai->id);
3429 return -EINVAL;
3430 }
3431
3432 tx_port_reg = TAPAN_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1);
3433 tx_port_reg_val = snd_soc_read(codec, tx_port_reg);
3434
3435 decimator = 0;
3436
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003437 tx_port_reg_val = tx_port_reg_val & 0x0F;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003438
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003439 if ((tx_port_reg_val >= 0x8) &&
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003440 (tx_port_reg_val <= 0x11)) {
3441
3442 decimator = (tx_port_reg_val - 0x8) + 1;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003443 }
3444
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003445
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003446 if (decimator) { /* SLIM_TX port has a DEC as input */
3447
3448 tx_fs_reg = TAPAN_A_CDC_TX1_CLK_FS_CTL +
3449 8 * (decimator - 1);
3450
3451 dev_dbg(codec->dev, "%s: set DEC%u (-> SLIM_TX%u) rate to %u\n",
3452 __func__, decimator, tx_port, sample_rate);
3453
3454 snd_soc_update_bits(codec, tx_fs_reg, 0x07,
3455 tx_fs_rate_reg_val);
3456
3457 } else {
3458 if ((tx_port_reg_val >= 0x1) &&
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003459 (tx_port_reg_val <= 0x4)) {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003460
3461 dev_dbg(codec->dev, "%s: RMIX%u going to SLIM TX%u\n",
3462 __func__, tx_port_reg_val, tx_port);
3463
3464 } else if ((tx_port_reg_val >= 0x8) &&
3465 (tx_port_reg_val <= 0x11)) {
3466
3467 pr_err("%s: ERROR: Should not be here\n",
3468 __func__);
3469 pr_err("%s: ERROR: DEC connected to SLIM TX%u\n",
3470 __func__, tx_port);
3471 return -EINVAL;
3472
3473 } else if (tx_port_reg_val == 0) {
3474 dev_dbg(codec->dev, "%s: no signal to SLIM TX%u\n",
3475 __func__, tx_port);
3476 } else {
3477 pr_err("%s: ERROR: wrong signal to SLIM TX%u\n",
3478 __func__, tx_port);
3479 pr_err("%s: ERROR: wrong signal = %u\n",
3480 __func__, tx_port_reg_val);
3481 return -EINVAL;
3482 }
3483 }
3484 }
3485 return 0;
3486}
3487
3488static int tapan_hw_params(struct snd_pcm_substream *substream,
3489 struct snd_pcm_hw_params *params,
3490 struct snd_soc_dai *dai)
3491{
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003492 struct snd_soc_codec *codec = dai->codec;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003493 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(dai->codec);
3494 u8 tx_fs_rate, rx_fs_rate;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003495 u32 compander_fs;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003496 int ret;
3497
3498 dev_dbg(dai->codec->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n",
3499 __func__, dai->name, dai->id,
3500 params_rate(params), params_channels(params));
3501
3502 switch (params_rate(params)) {
3503 case 8000:
3504 tx_fs_rate = 0x00;
3505 rx_fs_rate = 0x00;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003506 compander_fs = COMPANDER_FS_8KHZ;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003507 break;
3508 case 16000:
3509 tx_fs_rate = 0x01;
3510 rx_fs_rate = 0x20;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003511 compander_fs = COMPANDER_FS_16KHZ;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003512 break;
3513 case 32000:
3514 tx_fs_rate = 0x02;
3515 rx_fs_rate = 0x40;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003516 compander_fs = COMPANDER_FS_32KHZ;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003517 break;
3518 case 48000:
3519 tx_fs_rate = 0x03;
3520 rx_fs_rate = 0x60;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003521 compander_fs = COMPANDER_FS_48KHZ;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003522 break;
3523 case 96000:
3524 tx_fs_rate = 0x04;
3525 rx_fs_rate = 0x80;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003526 compander_fs = COMPANDER_FS_96KHZ;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003527 break;
3528 case 192000:
3529 tx_fs_rate = 0x05;
3530 rx_fs_rate = 0xA0;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003531 compander_fs = COMPANDER_FS_192KHZ;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003532 break;
3533 default:
3534 pr_err("%s: Invalid sampling rate %d\n", __func__,
3535 params_rate(params));
3536 return -EINVAL;
3537 }
3538
3539 switch (substream->stream) {
3540 case SNDRV_PCM_STREAM_CAPTURE:
3541 ret = tapan_set_decimator_rate(dai, tx_fs_rate,
3542 params_rate(params));
3543 if (ret < 0) {
3544 pr_err("%s: set decimator rate failed %d\n", __func__,
3545 ret);
3546 return ret;
3547 }
3548
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003549 if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
3550 switch (params_format(params)) {
3551 case SNDRV_PCM_FORMAT_S16_LE:
3552 snd_soc_update_bits(codec,
3553 TAPAN_A_CDC_CLK_I2S_CTL,
3554 0x20, 0x20);
3555 break;
3556 case SNDRV_PCM_FORMAT_S32_LE:
3557 snd_soc_update_bits(codec,
3558 TAPAN_A_CDC_CLK_I2S_CTL,
3559 0x20, 0x00);
3560 break;
3561 default:
3562 pr_err("invalid format\n");
3563 break;
3564 }
3565 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_I2S_CTL,
3566 0x07, tx_fs_rate);
3567 } else {
3568 tapan->dai[dai->id].rate = params_rate(params);
3569 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003570 break;
3571
3572 case SNDRV_PCM_STREAM_PLAYBACK:
3573 ret = tapan_set_interpolator_rate(dai, rx_fs_rate,
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003574 compander_fs,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003575 params_rate(params));
3576 if (ret < 0) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003577 dev_err(codec->dev, "%s: set decimator rate failed %d\n",
3578 __func__, ret);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003579 return ret;
3580 }
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003581 if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
3582 switch (params_format(params)) {
3583 case SNDRV_PCM_FORMAT_S16_LE:
3584 snd_soc_update_bits(codec,
3585 TAPAN_A_CDC_CLK_I2S_CTL,
3586 0x20, 0x20);
3587 break;
3588 case SNDRV_PCM_FORMAT_S32_LE:
3589 snd_soc_update_bits(codec,
3590 TAPAN_A_CDC_CLK_I2S_CTL,
3591 0x20, 0x00);
3592 break;
3593 default:
3594 dev_err(codec->dev, "invalid format\n");
3595 break;
3596 }
3597 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_I2S_CTL,
3598 0x03, (rx_fs_rate >> 0x05));
3599 } else {
3600 switch (params_format(params)) {
3601 case SNDRV_PCM_FORMAT_S16_LE:
3602 snd_soc_update_bits(codec,
3603 TAPAN_A_CDC_CONN_RX_SB_B1_CTL,
3604 0xFF, 0xAA);
3605 snd_soc_update_bits(codec,
3606 TAPAN_A_CDC_CONN_RX_SB_B2_CTL,
3607 0xFF, 0x2A);
3608 tapan->dai[dai->id].bit_width = 16;
3609 break;
3610 case SNDRV_PCM_FORMAT_S24_LE:
3611 snd_soc_update_bits(codec,
3612 TAPAN_A_CDC_CONN_RX_SB_B1_CTL,
3613 0xFF, 0x00);
3614 snd_soc_update_bits(codec,
3615 TAPAN_A_CDC_CONN_RX_SB_B2_CTL,
3616 0xFF, 0x00);
3617 tapan->dai[dai->id].bit_width = 24;
3618 break;
3619 default:
3620 dev_err(codec->dev, "Invalid format\n");
3621 break;
3622 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003623 tapan->dai[dai->id].rate = params_rate(params);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003624 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003625 break;
3626 default:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003627 dev_err(codec->dev, "%s: Invalid stream type %d\n", __func__,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003628 substream->stream);
3629 return -EINVAL;
3630 }
3631
3632 return 0;
3633}
3634
3635static struct snd_soc_dai_ops tapan_dai_ops = {
3636 .startup = tapan_startup,
3637 .shutdown = tapan_shutdown,
3638 .hw_params = tapan_hw_params,
3639 .set_sysclk = tapan_set_dai_sysclk,
3640 .set_fmt = tapan_set_dai_fmt,
3641 .set_channel_map = tapan_set_channel_map,
3642 .get_channel_map = tapan_get_channel_map,
3643};
3644
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07003645static struct snd_soc_dai_driver tapan9302_dai[] = {
3646 {
3647 .name = "tapan9302_rx1",
3648 .id = AIF1_PB,
3649 .playback = {
3650 .stream_name = "AIF1 Playback",
3651 .rates = WCD9302_RATES,
3652 .formats = TAPAN_FORMATS,
3653 .rate_max = 48000,
3654 .rate_min = 8000,
3655 .channels_min = 1,
3656 .channels_max = 2,
3657 },
3658 .ops = &tapan_dai_ops,
3659 },
3660 {
3661 .name = "tapan9302_tx1",
3662 .id = AIF1_CAP,
3663 .capture = {
3664 .stream_name = "AIF1 Capture",
3665 .rates = WCD9302_RATES,
3666 .formats = TAPAN_FORMATS,
3667 .rate_max = 48000,
3668 .rate_min = 8000,
3669 .channels_min = 1,
3670 .channels_max = 4,
3671 },
3672 .ops = &tapan_dai_ops,
3673 },
3674 {
3675 .name = "tapan9302_rx2",
3676 .id = AIF2_PB,
3677 .playback = {
3678 .stream_name = "AIF2 Playback",
3679 .rates = WCD9302_RATES,
3680 .formats = TAPAN_FORMATS,
3681 .rate_min = 8000,
3682 .rate_max = 48000,
3683 .channels_min = 1,
3684 .channels_max = 2,
3685 },
3686 .ops = &tapan_dai_ops,
3687 },
3688 {
3689 .name = "tapan9302_tx2",
3690 .id = AIF2_CAP,
3691 .capture = {
3692 .stream_name = "AIF2 Capture",
3693 .rates = WCD9302_RATES,
3694 .formats = TAPAN_FORMATS,
3695 .rate_max = 48000,
3696 .rate_min = 8000,
3697 .channels_min = 1,
3698 .channels_max = 4,
3699 },
3700 .ops = &tapan_dai_ops,
3701 },
3702 {
3703 .name = "tapan9302_tx3",
3704 .id = AIF3_CAP,
3705 .capture = {
3706 .stream_name = "AIF3 Capture",
3707 .rates = WCD9302_RATES,
3708 .formats = TAPAN_FORMATS,
3709 .rate_max = 48000,
3710 .rate_min = 8000,
3711 .channels_min = 1,
3712 .channels_max = 2,
3713 },
3714 .ops = &tapan_dai_ops,
3715 },
3716 {
3717 .name = "tapan9302_rx3",
3718 .id = AIF3_PB,
3719 .playback = {
3720 .stream_name = "AIF3 Playback",
3721 .rates = WCD9302_RATES,
3722 .formats = TAPAN_FORMATS,
3723 .rate_min = 8000,
3724 .rate_max = 48000,
3725 .channels_min = 1,
3726 .channels_max = 2,
3727 },
3728 .ops = &tapan_dai_ops,
3729 },
3730};
3731
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003732static struct snd_soc_dai_driver tapan_dai[] = {
3733 {
3734 .name = "tapan_rx1",
3735 .id = AIF1_PB,
3736 .playback = {
3737 .stream_name = "AIF1 Playback",
3738 .rates = WCD9306_RATES,
3739 .formats = TAPAN_FORMATS,
3740 .rate_max = 192000,
3741 .rate_min = 8000,
3742 .channels_min = 1,
3743 .channels_max = 2,
3744 },
3745 .ops = &tapan_dai_ops,
3746 },
3747 {
3748 .name = "tapan_tx1",
3749 .id = AIF1_CAP,
3750 .capture = {
3751 .stream_name = "AIF1 Capture",
3752 .rates = WCD9306_RATES,
3753 .formats = TAPAN_FORMATS,
3754 .rate_max = 192000,
3755 .rate_min = 8000,
3756 .channels_min = 1,
3757 .channels_max = 4,
3758 },
3759 .ops = &tapan_dai_ops,
3760 },
3761 {
3762 .name = "tapan_rx2",
3763 .id = AIF2_PB,
3764 .playback = {
3765 .stream_name = "AIF2 Playback",
3766 .rates = WCD9306_RATES,
3767 .formats = TAPAN_FORMATS,
3768 .rate_min = 8000,
3769 .rate_max = 192000,
3770 .channels_min = 1,
3771 .channels_max = 2,
3772 },
3773 .ops = &tapan_dai_ops,
3774 },
3775 {
3776 .name = "tapan_tx2",
3777 .id = AIF2_CAP,
3778 .capture = {
3779 .stream_name = "AIF2 Capture",
3780 .rates = WCD9306_RATES,
3781 .formats = TAPAN_FORMATS,
3782 .rate_max = 192000,
3783 .rate_min = 8000,
3784 .channels_min = 1,
3785 .channels_max = 4,
3786 },
3787 .ops = &tapan_dai_ops,
3788 },
3789 {
3790 .name = "tapan_tx3",
3791 .id = AIF3_CAP,
3792 .capture = {
3793 .stream_name = "AIF3 Capture",
3794 .rates = WCD9306_RATES,
3795 .formats = TAPAN_FORMATS,
3796 .rate_max = 48000,
3797 .rate_min = 8000,
3798 .channels_min = 1,
3799 .channels_max = 2,
3800 },
3801 .ops = &tapan_dai_ops,
3802 },
3803 {
3804 .name = "tapan_rx3",
3805 .id = AIF3_PB,
3806 .playback = {
3807 .stream_name = "AIF3 Playback",
3808 .rates = WCD9306_RATES,
3809 .formats = TAPAN_FORMATS,
3810 .rate_min = 8000,
3811 .rate_max = 192000,
3812 .channels_min = 1,
3813 .channels_max = 2,
3814 },
3815 .ops = &tapan_dai_ops,
3816 },
3817};
3818
3819static struct snd_soc_dai_driver tapan_i2s_dai[] = {
3820 {
3821 .name = "tapan_i2s_rx1",
3822 .id = AIF1_PB,
3823 .playback = {
3824 .stream_name = "AIF1 Playback",
3825 .rates = WCD9306_RATES,
3826 .formats = TAPAN_FORMATS,
3827 .rate_max = 192000,
3828 .rate_min = 8000,
3829 .channels_min = 1,
3830 .channels_max = 4,
3831 },
3832 .ops = &tapan_dai_ops,
3833 },
3834 {
3835 .name = "tapan_i2s_tx1",
3836 .id = AIF1_CAP,
3837 .capture = {
3838 .stream_name = "AIF1 Capture",
3839 .rates = WCD9306_RATES,
3840 .formats = TAPAN_FORMATS,
3841 .rate_max = 192000,
3842 .rate_min = 8000,
3843 .channels_min = 1,
3844 .channels_max = 4,
3845 },
3846 .ops = &tapan_dai_ops,
3847 },
3848};
3849
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003850static int tapan_codec_enable_slim_chmask(struct wcd9xxx_codec_dai_data *dai,
3851 bool up)
3852{
3853 int ret = 0;
3854 struct wcd9xxx_ch *ch;
3855
3856 if (up) {
3857 list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) {
3858 ret = wcd9xxx_get_slave_port(ch->ch_num);
3859 if (ret < 0) {
3860 pr_debug("%s: Invalid slave port ID: %d\n",
3861 __func__, ret);
3862 ret = -EINVAL;
3863 } else {
3864 set_bit(ret, &dai->ch_mask);
3865 }
3866 }
3867 } else {
3868 ret = wait_event_timeout(dai->dai_wait, (dai->ch_mask == 0),
3869 msecs_to_jiffies(
3870 TAPAN_SLIM_CLOSE_TIMEOUT));
3871 if (!ret) {
3872 pr_debug("%s: Slim close tx/rx wait timeout\n",
3873 __func__);
3874 ret = -ETIMEDOUT;
3875 } else {
3876 ret = 0;
3877 }
3878 }
3879 return ret;
3880}
3881
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003882static int tapan_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
3883 struct snd_kcontrol *kcontrol,
3884 int event)
3885{
3886 struct wcd9xxx *core;
3887 struct snd_soc_codec *codec = w->codec;
3888 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003889 int ret = 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003890 struct wcd9xxx_codec_dai_data *dai;
3891
3892 core = dev_get_drvdata(codec->dev->parent);
3893
3894 dev_dbg(codec->dev, "%s: event called! codec name %s\n",
3895 __func__, w->codec->name);
3896 dev_dbg(codec->dev, "%s: num_dai %d stream name %s event %d\n",
3897 __func__, w->codec->num_dai, w->sname, event);
3898
3899 /* Execute the callback only if interface type is slimbus */
3900 if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
3901 return 0;
3902
3903 dai = &tapan_p->dai[w->shift];
3904 dev_dbg(codec->dev, "%s: w->name %s w->shift %d event %d\n",
3905 __func__, w->name, w->shift, event);
3906
3907 switch (event) {
3908 case SND_SOC_DAPM_POST_PMU:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003909 (void) tapan_codec_enable_slim_chmask(dai, true);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003910 ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
3911 dai->rate, dai->bit_width,
3912 &dai->grph);
3913 break;
3914 case SND_SOC_DAPM_POST_PMD:
3915 ret = wcd9xxx_close_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
3916 dai->grph);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003917 ret = tapan_codec_enable_slim_chmask(dai, false);
3918 if (ret < 0) {
3919 ret = wcd9xxx_disconnect_port(core,
3920 &dai->wcd9xxx_ch_list,
3921 dai->grph);
3922 dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n",
3923 __func__, ret);
3924 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003925 break;
3926 }
3927 return ret;
3928}
3929
3930static int tapan_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
3931 struct snd_kcontrol *kcontrol,
3932 int event)
3933{
3934 struct wcd9xxx *core;
3935 struct snd_soc_codec *codec = w->codec;
3936 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
3937 u32 ret = 0;
3938 struct wcd9xxx_codec_dai_data *dai;
3939
3940 core = dev_get_drvdata(codec->dev->parent);
3941
3942 dev_dbg(codec->dev, "%s: event called! codec name %s\n",
3943 __func__, w->codec->name);
3944 dev_dbg(codec->dev, "%s: num_dai %d stream name %s\n",
3945 __func__, w->codec->num_dai, w->sname);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003946 /* Execute the callback only if interface type is slimbus */
3947 if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
3948 return 0;
3949
3950 dev_dbg(codec->dev, "%s(): w->name %s event %d w->shift %d\n",
3951 __func__, w->name, event, w->shift);
3952
3953 dai = &tapan_p->dai[w->shift];
3954 switch (event) {
3955 case SND_SOC_DAPM_POST_PMU:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003956 (void) tapan_codec_enable_slim_chmask(dai, true);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003957 ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
3958 dai->rate, dai->bit_width,
3959 &dai->grph);
3960 break;
3961 case SND_SOC_DAPM_POST_PMD:
3962 ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
3963 dai->grph);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003964 ret = tapan_codec_enable_slim_chmask(dai, false);
3965 if (ret < 0) {
3966 ret = wcd9xxx_disconnect_port(core,
3967 &dai->wcd9xxx_ch_list,
3968 dai->grph);
3969 dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n",
3970 __func__, ret);
3971 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003972 break;
3973 }
3974 return ret;
3975}
3976
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003977
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003978static int tapan_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
3979 struct snd_kcontrol *kcontrol, int event)
3980{
3981 struct snd_soc_codec *codec = w->codec;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003982 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003983
3984 dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
3985
3986 switch (event) {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003987 case SND_SOC_DAPM_POST_PMU:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003988 wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
3989 WCD9XXX_CLSH_STATE_EAR,
3990 WCD9XXX_CLSH_REQ_ENABLE,
3991 WCD9XXX_CLSH_EVENT_POST_PA);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003992
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003993 usleep_range(5000, 5010);
3994 break;
3995 case SND_SOC_DAPM_POST_PMD:
3996 wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
3997 WCD9XXX_CLSH_STATE_EAR,
3998 WCD9XXX_CLSH_REQ_DISABLE,
3999 WCD9XXX_CLSH_EVENT_POST_PA);
4000 usleep_range(5000, 5010);
4001 }
4002 return 0;
4003}
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004004
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004005static int tapan_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
4006 struct snd_kcontrol *kcontrol, int event)
4007{
4008 struct snd_soc_codec *codec = w->codec;
4009 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
4010
4011 dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
4012
4013 switch (event) {
4014 case SND_SOC_DAPM_PRE_PMU:
4015 wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
4016 WCD9XXX_CLSH_STATE_EAR,
4017 WCD9XXX_CLSH_REQ_ENABLE,
4018 WCD9XXX_CLSH_EVENT_PRE_DAC);
4019 break;
4020 }
4021
4022 return 0;
4023}
4024
4025static int tapan_codec_dsm_mux_event(struct snd_soc_dapm_widget *w,
4026 struct snd_kcontrol *kcontrol, int event)
4027{
4028 struct snd_soc_codec *codec = w->codec;
4029 u8 reg_val, zoh_mux_val = 0x00;
4030
4031 dev_dbg(codec->dev, "%s: event = %d\n", __func__, event);
4032
4033 switch (event) {
4034 case SND_SOC_DAPM_POST_PMU:
4035 reg_val = snd_soc_read(codec, TAPAN_A_CDC_CONN_CLSH_CTL);
4036
4037 if ((reg_val & 0x30) == 0x10)
4038 zoh_mux_val = 0x04;
4039 else if ((reg_val & 0x30) == 0x20)
4040 zoh_mux_val = 0x08;
4041
4042 if (zoh_mux_val != 0x00)
4043 snd_soc_update_bits(codec,
4044 TAPAN_A_CDC_CONN_CLSH_CTL,
4045 0x0C, zoh_mux_val);
4046 break;
4047
4048 case SND_SOC_DAPM_POST_PMD:
4049 snd_soc_update_bits(codec, TAPAN_A_CDC_CONN_CLSH_CTL,
4050 0x0C, 0x00);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004051 break;
4052 }
4053 return 0;
4054}
4055
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07004056static int tapan_codec_enable_anc_ear(struct snd_soc_dapm_widget *w,
4057 struct snd_kcontrol *kcontrol, int event)
4058{
4059 struct snd_soc_codec *codec = w->codec;
4060 int ret = 0;
4061
4062 switch (event) {
4063 case SND_SOC_DAPM_PRE_PMU:
4064 ret = tapan_codec_enable_anc(w, kcontrol, event);
4065 msleep(50);
4066 snd_soc_update_bits(codec, TAPAN_A_RX_EAR_EN, 0x10, 0x10);
4067 break;
4068 case SND_SOC_DAPM_POST_PMU:
4069 ret = tapan_codec_enable_ear_pa(w, kcontrol, event);
4070 break;
4071 case SND_SOC_DAPM_PRE_PMD:
4072 snd_soc_update_bits(codec, TAPAN_A_RX_EAR_EN, 0x10, 0x00);
4073 msleep(40);
4074 ret |= tapan_codec_enable_anc(w, kcontrol, event);
4075 break;
4076 case SND_SOC_DAPM_POST_PMD:
4077 ret = tapan_codec_enable_ear_pa(w, kcontrol, event);
4078 break;
4079 }
4080 return ret;
4081}
4082
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07004083static int tapan_codec_chargepump_vdd_event(struct snd_soc_dapm_widget *w,
4084 struct snd_kcontrol *kcontrol, int event)
4085{
4086 struct snd_soc_codec *codec = w->codec;
4087 struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
4088 int ret = 0, i;
4089
4090 pr_info("%s: event = %d\n", __func__, event);
4091
4092
4093 if (!priv->cp_regulators[CP_REG_BUCK]
4094 && !priv->cp_regulators[CP_REG_BHELPER]) {
4095 pr_err("%s: No power supply defined for ChargePump\n",
4096 __func__);
4097 return -EINVAL;
4098 }
4099
4100 switch (event) {
4101 case SND_SOC_DAPM_PRE_PMU:
4102 for (i = 0; i < CP_REG_MAX ; i++) {
4103 if (!priv->cp_regulators[i])
4104 continue;
4105
4106 ret = regulator_enable(priv->cp_regulators[i]);
4107 if (ret) {
4108 pr_err("%s: CP Regulator enable failed, index = %d\n",
4109 __func__, i);
4110 continue;
4111 } else {
4112 pr_debug("%s: Enabled CP regulator, index %d\n",
4113 __func__, i);
4114 }
4115 }
4116 break;
4117 case SND_SOC_DAPM_POST_PMD:
4118 for (i = 0; i < CP_REG_MAX; i++) {
4119 if (!priv->cp_regulators[i])
4120 continue;
4121
4122 ret = regulator_disable(priv->cp_regulators[i]);
4123 if (ret) {
4124 pr_err("%s: CP Regulator disable failed, index = %d\n",
4125 __func__, i);
4126 return ret;
4127 } else {
4128 pr_debug("%s: Disabled CP regulator %d\n",
4129 __func__, i);
4130 }
4131 }
4132 break;
4133 }
4134 return 0;
4135}
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004136
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07004137static const struct snd_soc_dapm_widget tapan_9306_dapm_widgets[] = {
4138 /* RX4 MIX1 mux inputs */
4139 SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4140 &rx4_mix1_inp1_mux),
4141 SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4142 &rx4_mix1_inp2_mux),
4143 SND_SOC_DAPM_MUX("RX4 MIX1 INP3", SND_SOC_NOPM, 0, 0,
4144 &rx4_mix1_inp2_mux),
4145
4146 /* RX4 MIX2 mux inputs */
4147 SND_SOC_DAPM_MUX("RX4 MIX2 INP1", SND_SOC_NOPM, 0, 0,
4148 &rx4_mix2_inp1_mux),
4149 SND_SOC_DAPM_MUX("RX4 MIX2 INP2", SND_SOC_NOPM, 0, 0,
4150 &rx4_mix2_inp2_mux),
4151
4152 SND_SOC_DAPM_MIXER("RX4 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4153
4154 SND_SOC_DAPM_MIXER_E("RX4 MIX2", TAPAN_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL,
4155 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
4156 SND_SOC_DAPM_POST_PMU),
4157
4158 SND_SOC_DAPM_MUX_E("DEC3 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 2, 0,
4159 &dec3_mux, tapan_codec_enable_dec,
4160 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4161 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
4162
4163 SND_SOC_DAPM_MUX_E("DEC4 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 3, 0,
4164 &dec4_mux, tapan_codec_enable_dec,
4165 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4166 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
4167
4168 SND_SOC_DAPM_SUPPLY("COMP0_CLK", SND_SOC_NOPM, 0, 0,
4169 tapan_config_compander, SND_SOC_DAPM_PRE_PMU |
4170 SND_SOC_DAPM_PRE_PMD),
4171 SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 1, 0,
4172 tapan_config_compander, SND_SOC_DAPM_PRE_PMU |
4173 SND_SOC_DAPM_PRE_PMD),
4174 SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 2, 0,
4175 tapan_config_compander, SND_SOC_DAPM_PRE_PMU |
4176 SND_SOC_DAPM_PRE_PMD),
4177
4178 SND_SOC_DAPM_INPUT("AMIC5"),
4179 SND_SOC_DAPM_ADC_E("ADC5", NULL, TAPAN_A_TX_5_EN, 7, 0,
4180 tapan_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
4181
4182 SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux),
4183 SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux),
4184
4185 SND_SOC_DAPM_OUTPUT("ANC HEADPHONE"),
4186 SND_SOC_DAPM_PGA_E("ANC HPHL", SND_SOC_NOPM, 5, 0, NULL, 0,
4187 tapan_codec_enable_anc_hph,
4188 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD |
4189 SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_POST_PMU),
4190 SND_SOC_DAPM_PGA_E("ANC HPHR", SND_SOC_NOPM, 4, 0, NULL, 0,
4191 tapan_codec_enable_anc_hph, SND_SOC_DAPM_PRE_PMU |
4192 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
4193 SND_SOC_DAPM_POST_PMU),
4194 SND_SOC_DAPM_OUTPUT("ANC EAR"),
4195 SND_SOC_DAPM_PGA_E("ANC EAR PA", SND_SOC_NOPM, 0, 0, NULL, 0,
4196 tapan_codec_enable_anc_ear,
4197 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD |
4198 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4199 SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux),
4200
4201 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", TAPAN_A_MICB_3_CTL, 7, 0,
4202 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4203 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4204 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", TAPAN_A_MICB_3_CTL, 7, 0,
4205 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4206 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4207 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", TAPAN_A_MICB_3_CTL, 7, 0,
4208 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4209 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4210
4211 SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0,
4212 tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4213 SND_SOC_DAPM_POST_PMD),
4214
4215 SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0,
4216 tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4217 SND_SOC_DAPM_POST_PMD),
4218};
4219
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004220/* Todo: Have seperate dapm widgets for I2S and Slimbus.
4221 * Might Need to have callbacks registered only for slimbus
4222 */
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07004223static const struct snd_soc_dapm_widget tapan_common_dapm_widgets[] = {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004224
4225 SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM,
4226 AIF1_PB, 0, tapan_codec_enable_slimrx,
4227 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4228 SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM,
4229 AIF2_PB, 0, tapan_codec_enable_slimrx,
4230 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4231 SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM,
4232 AIF3_PB, 0, tapan_codec_enable_slimrx,
4233 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4234
4235 SND_SOC_DAPM_MUX("SLIM RX1 MUX", SND_SOC_NOPM, TAPAN_RX1, 0,
4236 &slim_rx_mux[TAPAN_RX1]),
4237 SND_SOC_DAPM_MUX("SLIM RX2 MUX", SND_SOC_NOPM, TAPAN_RX2, 0,
4238 &slim_rx_mux[TAPAN_RX2]),
4239 SND_SOC_DAPM_MUX("SLIM RX3 MUX", SND_SOC_NOPM, TAPAN_RX3, 0,
4240 &slim_rx_mux[TAPAN_RX3]),
4241 SND_SOC_DAPM_MUX("SLIM RX4 MUX", SND_SOC_NOPM, TAPAN_RX4, 0,
4242 &slim_rx_mux[TAPAN_RX4]),
4243 SND_SOC_DAPM_MUX("SLIM RX5 MUX", SND_SOC_NOPM, TAPAN_RX5, 0,
4244 &slim_rx_mux[TAPAN_RX5]),
4245
4246 SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4247 SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
4248 SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
4249 SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
4250 SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
4251
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004252
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004253 /* RX1 MIX1 mux inputs */
4254 SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4255 &rx_mix1_inp1_mux),
4256 SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4257 &rx_mix1_inp2_mux),
4258 SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0,
4259 &rx_mix1_inp3_mux),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004260
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004261 /* RX2 MIX1 mux inputs */
4262 SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4263 &rx2_mix1_inp1_mux),
4264 SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4265 &rx2_mix1_inp2_mux),
4266 SND_SOC_DAPM_MUX("RX2 MIX1 INP3", SND_SOC_NOPM, 0, 0,
4267 &rx2_mix1_inp2_mux),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004268
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004269 /* RX3 MIX1 mux inputs */
4270 SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4271 &rx3_mix1_inp1_mux),
4272 SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4273 &rx3_mix1_inp2_mux),
4274 SND_SOC_DAPM_MUX("RX3 MIX1 INP3", SND_SOC_NOPM, 0, 0,
4275 &rx3_mix1_inp2_mux),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004276
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004277 /* RX1 MIX2 mux inputs */
4278 SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0,
4279 &rx1_mix2_inp1_mux),
4280 SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0,
4281 &rx1_mix2_inp2_mux),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004282
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004283 /* RX2 MIX2 mux inputs */
4284 SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0,
4285 &rx2_mix2_inp1_mux),
4286 SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0,
4287 &rx2_mix2_inp2_mux),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004288
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004289 SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4290 SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4291
4292 SND_SOC_DAPM_MIXER_E("RX1 MIX2", TAPAN_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL,
4293 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
4294 SND_SOC_DAPM_POST_PMU),
4295 SND_SOC_DAPM_MIXER_E("RX2 MIX2", TAPAN_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL,
4296 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
4297 SND_SOC_DAPM_POST_PMU),
4298 SND_SOC_DAPM_MIXER_E("RX3 MIX1", TAPAN_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
4299 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
4300 SND_SOC_DAPM_POST_PMU),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004301
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004302 SND_SOC_DAPM_MIXER("RX1 CHAIN", TAPAN_A_CDC_RX1_B6_CTL, 5, 0,
4303 NULL, 0),
4304 SND_SOC_DAPM_MIXER("RX2 CHAIN", TAPAN_A_CDC_RX2_B6_CTL, 5, 0,
4305 NULL, 0),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004306
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004307 SND_SOC_DAPM_MUX_E("CLASS_H_DSM MUX", SND_SOC_NOPM, 0, 0,
4308 &class_h_dsm_mux, tapan_codec_dsm_mux_event,
4309 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004310
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004311 /* RX Bias */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004312 SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
4313 tapan_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
4314 SND_SOC_DAPM_POST_PMD),
4315
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07004316 /* CDC_CP_VDD */
4317 SND_SOC_DAPM_SUPPLY("CDC_CP_VDD", SND_SOC_NOPM, 0, 0,
4318 tapan_codec_chargepump_vdd_event, SND_SOC_DAPM_PRE_PMU |
4319 SND_SOC_DAPM_POST_PMD),
4320
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004321 /*EAR */
4322 SND_SOC_DAPM_PGA_E("EAR PA", TAPAN_A_RX_EAR_EN, 4, 0, NULL, 0,
4323 tapan_codec_enable_ear_pa, SND_SOC_DAPM_POST_PMU |
4324 SND_SOC_DAPM_POST_PMD),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004325
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004326 SND_SOC_DAPM_MIXER_E("DAC1", TAPAN_A_RX_EAR_EN, 6, 0, dac1_switch,
4327 ARRAY_SIZE(dac1_switch), tapan_codec_ear_dac_event,
4328 SND_SOC_DAPM_PRE_PMU),
4329
4330 /* Headphone Left */
4331 SND_SOC_DAPM_PGA_E("HPHL", TAPAN_A_RX_HPH_CNP_EN, 5, 0, NULL, 0,
4332 tapan_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
4333 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4334
4335 SND_SOC_DAPM_MIXER_E("HPHL DAC", TAPAN_A_RX_HPH_L_DAC_CTL, 7, 0,
4336 hphl_switch, ARRAY_SIZE(hphl_switch), tapan_hphl_dac_event,
4337 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4338
4339 /* Headphone Right */
4340 SND_SOC_DAPM_PGA_E("HPHR", TAPAN_A_RX_HPH_CNP_EN, 4, 0, NULL, 0,
4341 tapan_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
4342 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4343
4344 SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TAPAN_A_RX_HPH_R_DAC_CTL, 7, 0,
4345 tapan_hphr_dac_event,
4346 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4347
4348 /* LINEOUT1*/
4349 SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TAPAN_A_RX_LINE_1_DAC_CTL, 7, 0
4350 , tapan_lineout_dac_event,
4351 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4352
4353 SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TAPAN_A_RX_LINE_CNP_EN, 0, 0, NULL,
4354 0, tapan_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4355 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4356
4357 /* LINEOUT2*/
4358 SND_SOC_DAPM_MUX("RDAC5 MUX", SND_SOC_NOPM, 0, 0,
4359 &rx_dac5_mux),
4360
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07004361 /* LINEOUT1*/
4362 SND_SOC_DAPM_MUX("RDAC4 MUX", SND_SOC_NOPM, 0, 0,
4363 &rx_dac4_mux),
4364
4365 SND_SOC_DAPM_MUX("RDAC3 MUX", SND_SOC_NOPM, 0, 0,
4366 &rx_dac3_mux),
4367
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004368 SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TAPAN_A_RX_LINE_2_DAC_CTL, 7, 0
4369 , tapan_lineout_dac_event,
4370 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4371
4372 SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TAPAN_A_RX_LINE_CNP_EN, 1, 0, NULL,
4373 0, tapan_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4374 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4375
4376 /* CLASS-D SPK */
4377 SND_SOC_DAPM_MIXER_E("SPK DAC", SND_SOC_NOPM, 0, 0,
4378 spk_dac_switch, ARRAY_SIZE(spk_dac_switch), tapan_spk_dac_event,
4379 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4380
4381 SND_SOC_DAPM_PGA_E("SPK PA", SND_SOC_NOPM, 0, 0 , NULL,
4382 0, tapan_codec_enable_spk_pa,
4383 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4384
4385 SND_SOC_DAPM_SUPPLY("VDD_SPKDRV", SND_SOC_NOPM, 0, 0,
4386 tapan_codec_enable_vdd_spkr,
4387 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4388
4389 SND_SOC_DAPM_OUTPUT("EAR"),
4390 SND_SOC_DAPM_OUTPUT("HEADPHONE"),
4391 SND_SOC_DAPM_OUTPUT("LINEOUT1"),
4392 SND_SOC_DAPM_OUTPUT("LINEOUT2"),
4393 SND_SOC_DAPM_OUTPUT("SPK_OUT"),
4394
4395 /* TX Path*/
4396 SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0,
4397 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
4398
4399 SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0,
4400 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
4401
4402 SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0,
4403 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
4404
4405 SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, TAPAN_TX1, 0,
4406 &sb_tx1_mux),
4407 SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, TAPAN_TX2, 0,
4408 &sb_tx2_mux),
4409 SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, TAPAN_TX3, 0,
4410 &sb_tx3_mux),
4411 SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, TAPAN_TX4, 0,
4412 &sb_tx4_mux),
4413 SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, TAPAN_TX5, 0,
4414 &sb_tx5_mux),
4415
4416 SND_SOC_DAPM_SUPPLY("CDC_CONN", WCD9XXX_A_CDC_CLK_OTHR_CTL, 2, 0, NULL,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004417 0),
4418
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004419 /* Decimator MUX */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004420 SND_SOC_DAPM_MUX_E("DEC1 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0, 0,
4421 &dec1_mux, tapan_codec_enable_dec,
4422 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4423 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
4424
4425 SND_SOC_DAPM_MUX_E("DEC2 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 1, 0,
4426 &dec2_mux, tapan_codec_enable_dec,
4427 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4428 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
4429
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004430 SND_SOC_DAPM_SUPPLY("LDO_H", TAPAN_A_LDO_H_MODE_1, 7, 0,
4431 tapan_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU),
4432
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004433 SND_SOC_DAPM_INPUT("AMIC1"),
4434 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", TAPAN_A_MICB_1_CTL, 7, 0,
4435 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4436 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4437 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", TAPAN_A_MICB_1_CTL, 7, 0,
4438 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4439 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4440 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", TAPAN_A_MICB_1_CTL, 7, 0,
4441 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4442 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4443
4444 SND_SOC_DAPM_ADC_E("ADC1", NULL, TAPAN_A_TX_1_EN, 7, 0,
4445 tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4446 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4447 SND_SOC_DAPM_ADC_E("ADC2", NULL, TAPAN_A_TX_2_EN, 7, 0,
4448 tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4449 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4450
4451 SND_SOC_DAPM_INPUT("AMIC3"),
4452 SND_SOC_DAPM_ADC_E("ADC3", NULL, TAPAN_A_TX_3_EN, 7, 0,
4453 tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4454 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4455
4456 SND_SOC_DAPM_INPUT("AMIC4"),
4457 SND_SOC_DAPM_ADC_E("ADC4", NULL, TAPAN_A_TX_4_EN, 7, 0,
4458 tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4459 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4460
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004461 SND_SOC_DAPM_INPUT("AMIC2"),
4462 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", TAPAN_A_MICB_2_CTL, 7, 0,
4463 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4464 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4465 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", TAPAN_A_MICB_2_CTL, 7, 0,
4466 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4467 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4468 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", TAPAN_A_MICB_2_CTL, 7, 0,
4469 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4470 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4471 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", TAPAN_A_MICB_2_CTL, 7, 0,
4472 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4473 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004474
4475 SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM,
4476 AIF1_CAP, 0, tapan_codec_enable_slimtx,
4477 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4478
4479 SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM,
4480 AIF2_CAP, 0, tapan_codec_enable_slimtx,
4481 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4482
4483 SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM,
4484 AIF3_CAP, 0, tapan_codec_enable_slimtx,
4485 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4486
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004487 /* Digital Mic Inputs */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004488 SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
4489 tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4490 SND_SOC_DAPM_POST_PMD),
4491
4492 SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
4493 tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4494 SND_SOC_DAPM_POST_PMD),
4495
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004496 /* Sidetone */
4497 SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux),
4498 SND_SOC_DAPM_PGA("IIR1", TAPAN_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0),
4499
4500 /* AUX PGA */
4501 SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TAPAN_A_RX_AUX_SW_CTL, 7, 0,
4502 tapan_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
4503 SND_SOC_DAPM_POST_PMD),
4504
4505 SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TAPAN_A_RX_AUX_SW_CTL, 6, 0,
4506 tapan_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
4507 SND_SOC_DAPM_POST_PMD),
4508
4509 /* Lineout, ear and HPH PA Mixers */
4510
4511 SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0,
4512 ear_pa_mix, ARRAY_SIZE(ear_pa_mix)),
4513
4514 SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0,
4515 hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)),
4516
4517 SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0,
4518 hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)),
4519
4520 SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0,
4521 lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)),
4522
4523 SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0,
4524 lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004525};
4526
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004527static irqreturn_t tapan_slimbus_irq(int irq, void *data)
4528{
4529 struct tapan_priv *priv = data;
4530 struct snd_soc_codec *codec = priv->codec;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004531 unsigned long status = 0;
4532 int i, j, port_id, k;
4533 u32 bit;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004534 u8 val;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004535 bool tx, cleared;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004536
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004537 for (i = TAPAN_SLIM_PGD_PORT_INT_STATUS_RX_0, j = 0;
4538 i <= TAPAN_SLIM_PGD_PORT_INT_STATUS_TX_1; i++, j++) {
4539 val = wcd9xxx_interface_reg_read(codec->control_data, i);
4540 status |= ((u32)val << (8 * j));
4541 }
4542
4543 for_each_set_bit(j, &status, 32) {
4544 tx = (j >= 16 ? true : false);
4545 port_id = (tx ? j - 16 : j);
4546 val = wcd9xxx_interface_reg_read(codec->control_data,
4547 TAPAN_SLIM_PGD_PORT_INT_RX_SOURCE0 + j);
4548 if (val & TAPAN_SLIM_IRQ_OVERFLOW)
4549 pr_err_ratelimited(
4550 "%s: overflow error on %s port %d, value %x\n",
4551 __func__, (tx ? "TX" : "RX"), port_id, val);
4552 if (val & TAPAN_SLIM_IRQ_UNDERFLOW)
4553 pr_err_ratelimited(
4554 "%s: underflow error on %s port %d, value %x\n",
4555 __func__, (tx ? "TX" : "RX"), port_id, val);
4556 if (val & TAPAN_SLIM_IRQ_PORT_CLOSED) {
4557 /*
4558 * INT SOURCE register starts from RX to TX
4559 * but port number in the ch_mask is in opposite way
4560 */
4561 bit = (tx ? j - 16 : j + 16);
4562 dev_dbg(codec->dev, "%s: %s port %d closed value %x, bit %u\n",
4563 __func__, (tx ? "TX" : "RX"), port_id, val,
4564 bit);
4565 for (k = 0, cleared = false; k < NUM_CODEC_DAIS; k++) {
4566 dev_dbg(codec->dev, "%s: priv->dai[%d].ch_mask = 0x%lx\n",
4567 __func__, k, priv->dai[k].ch_mask);
4568 if (test_and_clear_bit(bit,
4569 &priv->dai[k].ch_mask)) {
4570 cleared = true;
4571 if (!priv->dai[k].ch_mask)
4572 wake_up(&priv->dai[k].dai_wait);
4573 /*
4574 * There are cases when multiple DAIs
4575 * might be using the same slimbus
4576 * channel. Hence don't break here.
4577 */
4578 }
4579 }
4580 WARN(!cleared,
4581 "Couldn't find slimbus %s port %d for closing\n",
4582 (tx ? "TX" : "RX"), port_id);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004583 }
4584 wcd9xxx_interface_reg_write(codec->control_data,
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004585 TAPAN_SLIM_PGD_PORT_INT_CLR_RX_0 +
4586 (j / 8),
4587 1 << (j % 8));
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004588 }
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004589
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004590 return IRQ_HANDLED;
4591}
4592
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004593static int tapan_handle_pdata(struct tapan_priv *tapan)
4594{
4595 struct snd_soc_codec *codec = tapan->codec;
4596 struct wcd9xxx_pdata *pdata = tapan->resmgr.pdata;
4597 int k1, k2, k3, rc = 0;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004598 u8 txfe_bypass = pdata->amic_settings.txfe_enable;
4599 u8 txfe_buff = pdata->amic_settings.txfe_buff;
4600 u8 flag = pdata->amic_settings.use_pdata;
4601 u8 i = 0, j = 0;
4602 u8 val_txfe = 0, value = 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004603
4604 if (!pdata) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004605 dev_err(codec->dev, "%s: NULL pdata\n", __func__);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004606 rc = -ENODEV;
4607 goto done;
4608 }
4609
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004610 /* Make sure settings are correct */
4611 if ((pdata->micbias.ldoh_v > WCD9XXX_LDOH_3P0_V) ||
4612 (pdata->micbias.bias1_cfilt_sel > WCD9XXX_CFILT3_SEL) ||
4613 (pdata->micbias.bias2_cfilt_sel > WCD9XXX_CFILT3_SEL) ||
4614 (pdata->micbias.bias3_cfilt_sel > WCD9XXX_CFILT3_SEL)) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004615 dev_err(codec->dev, "%s: Invalid ldoh voltage or bias cfilt\n",
4616 __func__);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004617 rc = -EINVAL;
4618 goto done;
4619 }
4620 /* figure out k value */
4621 k1 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt1_mv);
4622 k2 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt2_mv);
4623 k3 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt3_mv);
4624
4625 if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004626 dev_err(codec->dev,
4627 "%s: could not get K value. k1 = %d k2 = %d k3 = %d\n",
4628 __func__, k1, k2, k3);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004629 rc = -EINVAL;
4630 goto done;
4631 }
4632 /* Set voltage level and always use LDO */
4633 snd_soc_update_bits(codec, TAPAN_A_LDO_H_MODE_1, 0x0C,
4634 (pdata->micbias.ldoh_v << 2));
4635
4636 snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_1_VAL, 0xFC, (k1 << 2));
4637 snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_2_VAL, 0xFC, (k2 << 2));
4638 snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_3_VAL, 0xFC, (k3 << 2));
4639
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004640 i = 0;
4641 while (i < 5) {
4642 if (flag & (0x01 << i)) {
4643 val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00;
4644 val_txfe = val_txfe |
4645 ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00);
4646 snd_soc_update_bits(codec,
4647 TAPAN_A_TX_1_2_TEST_EN + j * 10,
4648 0x30, val_txfe);
4649 }
4650 if (flag & (0x01 << (i + 1))) {
4651 val_txfe = (txfe_bypass &
4652 (0x01 << (i + 1))) ? 0x02 : 0x00;
4653 val_txfe |= (txfe_buff &
4654 (0x01 << (i + 1))) ? 0x01 : 0x00;
4655 snd_soc_update_bits(codec,
4656 TAPAN_A_TX_1_2_TEST_EN + j * 10,
4657 0x03, val_txfe);
4658 }
4659 /* Tapan only has TAPAN_A_TX_1_2_TEST_EN and
4660 TAPAN_A_TX_4_5_TEST_EN reg */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004661
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004662 if (i == 0) {
4663 i = 3;
4664 continue;
4665 } else if (i == 3) {
4666 break;
4667 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004668 }
4669
4670 if (pdata->ocp.use_pdata) {
4671 /* not defined in CODEC specification */
4672 if (pdata->ocp.hph_ocp_limit == 1 ||
4673 pdata->ocp.hph_ocp_limit == 5) {
4674 rc = -EINVAL;
4675 goto done;
4676 }
4677 snd_soc_update_bits(codec, TAPAN_A_RX_COM_OCP_CTL,
4678 0x0F, pdata->ocp.num_attempts);
4679 snd_soc_write(codec, TAPAN_A_RX_COM_OCP_COUNT,
4680 ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time));
4681 snd_soc_update_bits(codec, TAPAN_A_RX_HPH_OCP_CTL,
4682 0xE0, (pdata->ocp.hph_ocp_limit << 5));
4683 }
4684
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004685 /* Set micbias capless mode with tail current */
4686 value = (pdata->micbias.bias1_cap_mode == MICBIAS_EXT_BYP_CAP ?
4687 0x00 : 0x10);
4688 snd_soc_update_bits(codec, TAPAN_A_MICB_1_CTL, 0x10, value);
4689 value = (pdata->micbias.bias2_cap_mode == MICBIAS_EXT_BYP_CAP ?
4690 0x00 : 0x10);
4691 snd_soc_update_bits(codec, TAPAN_A_MICB_2_CTL, 0x10, value);
4692 value = (pdata->micbias.bias3_cap_mode == MICBIAS_EXT_BYP_CAP ?
4693 0x00 : 0x10);
4694 snd_soc_update_bits(codec, TAPAN_A_MICB_3_CTL, 0x10, value);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004695
4696done:
4697 return rc;
4698}
4699
4700static const struct tapan_reg_mask_val tapan_reg_defaults[] = {
4701
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004702 /* enable QFUSE for wcd9306 */
4703 TAPAN_REG_VAL(TAPAN_A_QFUSE_CTL, 0x03),
4704
4705 /* PROGRAM_THE_0P85V_VBG_REFERENCE = V_0P858V */
4706 TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x04),
4707
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004708 TAPAN_REG_VAL(TAPAN_A_CDC_CLK_POWER_CTL, 0x03),
4709
4710 /* EAR PA deafults */
4711 TAPAN_REG_VAL(TAPAN_A_RX_EAR_CMBUFF, 0x05),
4712
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004713 /* RX1 and RX2 defaults */
4714 TAPAN_REG_VAL(TAPAN_A_CDC_RX1_B6_CTL, 0xA0),
4715 TAPAN_REG_VAL(TAPAN_A_CDC_RX2_B6_CTL, 0xA0),
4716
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004717 /* Heaset set Right from RX2 */
4718 TAPAN_REG_VAL(TAPAN_A_CDC_CONN_RX2_B2_CTL, 0x10),
4719
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004720
4721 /*
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004722 * The following only need to be written for Tapan 1.0 parts.
4723 * Tapan 2.0 will have appropriate defaults for these registers.
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004724 */
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004725
4726 /* Required defaults for class H operation */
4727 /* borrowed from Taiko class-h */
4728 TAPAN_REG_VAL(TAPAN_A_RX_HPH_CHOP_CTL, 0xF4),
4729 TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x08),
4730 TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_1, 0x5B),
Banajit Goswamia7294452013-06-03 12:42:35 -07004731 TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_3, 0x6F),
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004732
4733 /* TODO: Check below reg writes conflict with above */
4734 /* PROGRAM_THE_0P85V_VBG_REFERENCE = V_0P858V */
4735 TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x04),
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004736 TAPAN_REG_VAL(TAPAN_A_RX_HPH_CHOP_CTL, 0x74),
4737 TAPAN_REG_VAL(TAPAN_A_RX_BUCK_BIAS1, 0x62),
4738
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004739 /* Choose max non-overlap time for NCP */
4740 TAPAN_REG_VAL(TAPAN_A_NCP_CLK, 0xFC),
4741 /* Use 25mV/50mV for deltap/m to reduce ripple */
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004742 TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_VCL_1, 0x08),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004743 /*
4744 * Set DISABLE_MODE_SEL<1:0> to 0b10 (disable PWM in auto mode).
4745 * Note that the other bits of this register will be changed during
4746 * Rx PA bring up.
4747 */
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004748 TAPAN_REG_VAL(WCD9XXX_A_BUCK_MODE_3, 0xCE),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004749 /* Reduce HPH DAC bias to 70% */
4750 TAPAN_REG_VAL(TAPAN_A_RX_HPH_BIAS_PA, 0x7A),
4751 /*Reduce EAR DAC bias to 70% */
4752 TAPAN_REG_VAL(TAPAN_A_RX_EAR_BIAS_PA, 0x76),
4753 /* Reduce LINE DAC bias to 70% */
4754 TAPAN_REG_VAL(TAPAN_A_RX_LINE_BIAS_PA, 0x78),
4755
4756 /*
4757 * There is a diode to pull down the micbias while doing
4758 * insertion detection. This diode can cause leakage.
4759 * Set bit 0 to 1 to prevent leakage.
4760 * Setting this bit of micbias 2 prevents leakage for all other micbias.
4761 */
4762 TAPAN_REG_VAL(TAPAN_A_MICB_2_MBHC, 0x41),
4763
Bhalchandra Gajare7c739522013-06-20 15:31:02 -07004764 /*
4765 * Default register settings to support dynamic change of
4766 * vdd_buck between 1.8 volts and 2.15 volts.
4767 */
4768 TAPAN_REG_VAL(TAPAN_A_BUCK_MODE_2, 0xAA),
4769
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004770};
4771
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004772static const struct tapan_reg_mask_val tapan_2_x_reg_reset_values[] = {
4773
4774 TAPAN_REG_VAL(TAPAN_A_TX_7_MBHC_EN, 0x6C),
4775 TAPAN_REG_VAL(TAPAN_A_BUCK_CTRL_CCL_4, 0x51),
4776 TAPAN_REG_VAL(TAPAN_A_RX_HPH_CNP_WG_CTL, 0xDA),
4777 TAPAN_REG_VAL(TAPAN_A_RX_EAR_CNP, 0xC0),
4778 TAPAN_REG_VAL(TAPAN_A_RX_LINE_1_TEST, 0x02),
4779 TAPAN_REG_VAL(TAPAN_A_RX_LINE_2_TEST, 0x02),
4780 TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_OCP_CTL, 0x97),
4781 TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_CLIP_DET, 0x01),
4782 TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_IEC, 0x00),
4783 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B1_CTL, 0xE4),
4784 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B2_CTL, 0x00),
4785 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B3_CTL, 0x00),
4786 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_BUCK_NCP_VARS, 0x00),
4787 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_HD_EAR, 0x00),
4788 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_HD_HPH, 0x00),
4789 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_MIN_EAR, 0x00),
4790 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_MIN_HPH, 0x00),
4791};
4792
4793static const struct tapan_reg_mask_val tapan_1_0_reg_defaults[] = {
4794 /* Close leakage on the spkdrv */
4795 TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_DBG_PWRSTG, 0x24),
4796 TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_DBG_DAC, 0xE5),
4797
4798};
4799
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004800static void tapan_update_reg_defaults(struct snd_soc_codec *codec)
4801{
4802 u32 i;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004803 struct wcd9xxx *tapan_core = dev_get_drvdata(codec->dev->parent);
4804
4805 if (!TAPAN_IS_1_0(tapan_core->version)) {
4806 for (i = 0; i < ARRAY_SIZE(tapan_2_x_reg_reset_values); i++)
4807 snd_soc_write(codec, tapan_2_x_reg_reset_values[i].reg,
4808 tapan_2_x_reg_reset_values[i].val);
4809 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004810
4811 for (i = 0; i < ARRAY_SIZE(tapan_reg_defaults); i++)
4812 snd_soc_write(codec, tapan_reg_defaults[i].reg,
4813 tapan_reg_defaults[i].val);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004814
4815 if (TAPAN_IS_1_0(tapan_core->version)) {
4816 for (i = 0; i < ARRAY_SIZE(tapan_1_0_reg_defaults); i++)
4817 snd_soc_write(codec, tapan_1_0_reg_defaults[i].reg,
4818 tapan_1_0_reg_defaults[i].val);
4819 }
4820
4821 if (!TAPAN_IS_1_0(tapan_core->version))
4822 spkr_drv_wrnd = -1;
4823 else if (spkr_drv_wrnd == 1)
4824 snd_soc_write(codec, TAPAN_A_SPKR_DRV_EN, 0xEF);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004825}
4826
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07004827static void tapan_update_reg_mclk_rate(struct wcd9xxx *wcd9xxx)
4828{
4829 struct snd_soc_codec *codec;
4830
4831 codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
4832 dev_dbg(codec->dev, "%s: MCLK Rate = %x\n",
4833 __func__, wcd9xxx->mclk_rate);
4834
4835 if (wcd9xxx->mclk_rate == TAPAN_MCLK_CLK_12P288MHZ) {
4836 snd_soc_update_bits(codec, TAPAN_A_CHIP_CTL, 0x06, 0x0);
4837 snd_soc_update_bits(codec, TAPAN_A_RX_COM_TIMER_DIV, 0x01,
4838 0x01);
4839 } else if (wcd9xxx->mclk_rate == TAPAN_MCLK_CLK_9P6MHZ) {
4840 snd_soc_update_bits(codec, TAPAN_A_CHIP_CTL, 0x06, 0x2);
4841 }
4842}
4843
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004844static const struct tapan_reg_mask_val tapan_codec_reg_init_val[] = {
Phani Kumar Uppalapatieca9a102013-06-18 11:02:38 -07004845 /* Initialize current threshold to 365MA
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004846 * number of wait and run cycles to 4096
4847 */
Phani Kumar Uppalapatieca9a102013-06-18 11:02:38 -07004848 {TAPAN_A_RX_HPH_OCP_CTL, 0xE9, 0x69},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004849 {TAPAN_A_RX_COM_OCP_COUNT, 0xFF, 0xFF},
Phani Kumar Uppalapatieca9a102013-06-18 11:02:38 -07004850 {TAPAN_A_RX_HPH_L_TEST, 0x01, 0x01},
4851 {TAPAN_A_RX_HPH_R_TEST, 0x01, 0x01},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004852
4853 /* Initialize gain registers to use register gain */
4854 {TAPAN_A_RX_HPH_L_GAIN, 0x20, 0x20},
4855 {TAPAN_A_RX_HPH_R_GAIN, 0x20, 0x20},
4856 {TAPAN_A_RX_LINE_1_GAIN, 0x20, 0x20},
4857 {TAPAN_A_RX_LINE_2_GAIN, 0x20, 0x20},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004858 {TAPAN_A_SPKR_DRV_GAIN, 0x04, 0x04},
4859
4860 /* Set RDAC5 MUX to take input from DEM3_INV.
4861 * This sets LO2 DAC to get input from DEM3_INV
4862 * for LO1 and LO2 to work as differential outputs.
4863 */
4864 {TAPAN_A_CDC_CONN_MISC, 0x04, 0x04},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004865
4866 /* CLASS H config */
4867 {TAPAN_A_CDC_CONN_CLSH_CTL, 0x3C, 0x14},
4868
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004869 /* Use 16 bit sample size for TX1 to TX5 */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004870 {TAPAN_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20},
4871 {TAPAN_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20},
4872 {TAPAN_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20},
4873 {TAPAN_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20},
4874 {TAPAN_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20},
4875
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004876 /* Disable SPK SWITCH */
4877 {TAPAN_A_SPKR_DRV_DAC_CTL, 0x04, 0x00},
4878
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004879 /* Use 16 bit sample size for RX */
4880 {TAPAN_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA},
4881 {TAPAN_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0x2A},
4882
4883 /*enable HPF filter for TX paths */
4884 {TAPAN_A_CDC_TX1_MUX_CTL, 0x8, 0x0},
4885 {TAPAN_A_CDC_TX2_MUX_CTL, 0x8, 0x0},
4886 {TAPAN_A_CDC_TX3_MUX_CTL, 0x8, 0x0},
4887 {TAPAN_A_CDC_TX4_MUX_CTL, 0x8, 0x0},
4888
4889 /* config Decimator for DMIC CLK_MODE_1(3.2Mhz@9.6Mhz mclk) */
4890 {TAPAN_A_CDC_TX1_DMIC_CTL, 0x7, 0x1},
4891 {TAPAN_A_CDC_TX2_DMIC_CTL, 0x7, 0x1},
4892 {TAPAN_A_CDC_TX3_DMIC_CTL, 0x7, 0x1},
4893 {TAPAN_A_CDC_TX4_DMIC_CTL, 0x7, 0x1},
4894
4895 /* config DMIC clk to CLK_MODE_1 (3.2Mhz@9.6Mhz mclk) */
4896 {TAPAN_A_CDC_CLK_DMIC_B1_CTL, 0xEE, 0x22},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004897
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004898 /* Compander zone selection */
4899 {TAPAN_A_CDC_COMP0_B4_CTL, 0x3F, 0x37},
4900 {TAPAN_A_CDC_COMP1_B4_CTL, 0x3F, 0x37},
4901 {TAPAN_A_CDC_COMP2_B4_CTL, 0x3F, 0x37},
4902 {TAPAN_A_CDC_COMP0_B5_CTL, 0x7F, 0x7F},
4903 {TAPAN_A_CDC_COMP1_B5_CTL, 0x7F, 0x7F},
4904 {TAPAN_A_CDC_COMP2_B5_CTL, 0x7F, 0x7F},
Banajit Goswamia7294452013-06-03 12:42:35 -07004905
4906 /*
4907 * Setup wavegen timer to 20msec and disable chopper
4908 * as default. This corresponds to Compander OFF
4909 */
4910 {TAPAN_A_RX_HPH_CNP_WG_CTL, 0xFF, 0xDB},
4911 {TAPAN_A_RX_HPH_CNP_WG_TIME, 0xFF, 0x58},
4912 {TAPAN_A_RX_HPH_BIAS_WG_OCP, 0xFF, 0x1A},
4913 {TAPAN_A_RX_HPH_CHOP_CTL, 0xFF, 0x24},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004914};
4915
Damir Didjustod6aea992013-09-03 21:18:59 -07004916void *tapan_get_afe_config(struct snd_soc_codec *codec,
4917 enum afe_config_type config_type)
4918{
4919 struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
4920
4921 switch (config_type) {
4922 case AFE_SLIMBUS_SLAVE_CONFIG:
4923 return &priv->slimbus_slave_cfg;
4924 case AFE_CDC_REGISTERS_CONFIG:
4925 return &tapan_audio_reg_cfg;
4926 case AFE_AANC_VERSION:
4927 return &tapan_cdc_aanc_version;
4928 default:
4929 pr_err("%s: Unknown config_type 0x%x\n", __func__, config_type);
4930 return NULL;
4931 }
4932}
4933
4934static void tapan_init_slim_slave_cfg(struct snd_soc_codec *codec)
4935{
4936 struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
4937 struct afe_param_cdc_slimbus_slave_cfg *cfg;
4938 struct wcd9xxx *wcd9xxx = codec->control_data;
4939 uint64_t eaddr = 0;
4940
4941 pr_debug("%s\n", __func__);
4942 cfg = &priv->slimbus_slave_cfg;
4943 cfg->minor_version = 1;
4944 cfg->tx_slave_port_offset = 0;
4945 cfg->rx_slave_port_offset = 16;
4946
4947 memcpy(&eaddr, &wcd9xxx->slim->e_addr, sizeof(wcd9xxx->slim->e_addr));
4948 /* e-addr is 6-byte elemental address of the device */
4949 WARN_ON(sizeof(wcd9xxx->slim->e_addr) != 6);
4950 cfg->device_enum_addr_lsw = eaddr & 0xFFFFFFFF;
4951 cfg->device_enum_addr_msw = eaddr >> 32;
4952
4953 pr_debug("%s: slimbus logical address 0x%llx\n", __func__, eaddr);
4954}
4955
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004956static void tapan_codec_init_reg(struct snd_soc_codec *codec)
4957{
4958 u32 i;
4959
4960 for (i = 0; i < ARRAY_SIZE(tapan_codec_reg_init_val); i++)
4961 snd_soc_update_bits(codec, tapan_codec_reg_init_val[i].reg,
4962 tapan_codec_reg_init_val[i].mask,
4963 tapan_codec_reg_init_val[i].val);
4964}
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07004965static void tapan_slim_interface_init_reg(struct snd_soc_codec *codec)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004966{
4967 int i;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004968
4969 for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++)
4970 wcd9xxx_interface_reg_write(codec->control_data,
4971 TAPAN_SLIM_PGD_PORT_INT_EN0 + i,
4972 0xFF);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07004973}
4974
4975static int tapan_setup_irqs(struct tapan_priv *tapan)
4976{
4977 int ret = 0;
4978 struct snd_soc_codec *codec = tapan->codec;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07004979 struct wcd9xxx *wcd9xxx = codec->control_data;
4980 struct wcd9xxx_core_resource *core_res = &wcd9xxx->core_res;
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07004981
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07004982 ret = wcd9xxx_request_irq(core_res, WCD9XXX_IRQ_SLIMBUS,
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07004983 tapan_slimbus_irq, "SLIMBUS Slave", tapan);
4984 if (ret)
4985 pr_err("%s: Failed to request irq %d\n", __func__,
4986 WCD9XXX_IRQ_SLIMBUS);
4987 else
4988 tapan_slim_interface_init_reg(codec);
4989
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004990 return ret;
4991}
4992
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07004993static void tapan_cleanup_irqs(struct tapan_priv *tapan)
4994{
4995 struct snd_soc_codec *codec = tapan->codec;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07004996 struct wcd9xxx *wcd9xxx = codec->control_data;
4997 struct wcd9xxx_core_resource *core_res = &wcd9xxx->core_res;
4998 wcd9xxx_free_irq(core_res, WCD9XXX_IRQ_SLIMBUS, tapan);
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07004999}
5000
Simmi Pateriya95466b12013-05-09 20:08:46 +05305001
5002static void tapan_enable_mux_bias_block(struct snd_soc_codec *codec)
5003{
5004 snd_soc_update_bits(codec, WCD9XXX_A_MBHC_SCALING_MUX_1,
5005 0x80, 0x00);
5006}
5007
5008static void tapan_put_cfilt_fast_mode(struct snd_soc_codec *codec,
5009 struct wcd9xxx_mbhc *mbhc)
5010{
5011 snd_soc_update_bits(codec, mbhc->mbhc_bias_regs.cfilt_ctl,
5012 0x30, 0x30);
5013}
5014
5015static void tapan_codec_specific_cal_setup(struct snd_soc_codec *codec,
5016 struct wcd9xxx_mbhc *mbhc)
5017{
5018 snd_soc_update_bits(codec, WCD9XXX_A_CDC_MBHC_B1_CTL,
Phani Kumar Uppalapati10754402013-07-12 22:48:45 -07005019 0x04, 0x04);
Simmi Pateriya95466b12013-05-09 20:08:46 +05305020 snd_soc_update_bits(codec, WCD9XXX_A_TX_7_MBHC_EN, 0xE0, 0xE0);
5021}
5022
5023static int tapan_get_jack_detect_irq(struct snd_soc_codec *codec)
5024{
5025 return TAPAN_IRQ_MBHC_JACK_SWITCH;
5026}
5027
5028static struct wcd9xxx_cfilt_mode tapan_codec_switch_cfilt_mode(
5029 struct wcd9xxx_mbhc *mbhc,
5030 bool fast)
5031{
5032 struct snd_soc_codec *codec = mbhc->codec;
5033 struct wcd9xxx_cfilt_mode cfilt_mode;
5034
5035 if (fast)
5036 cfilt_mode.reg_mode_val = WCD9XXX_CFILT_EXT_PRCHG_EN;
5037 else
5038 cfilt_mode.reg_mode_val = WCD9XXX_CFILT_EXT_PRCHG_DSBL;
5039
5040 cfilt_mode.cur_mode_val =
5041 snd_soc_read(codec, mbhc->mbhc_bias_regs.cfilt_ctl) & 0x30;
Bhalchandra Gajare8e5fe252013-07-15 19:42:21 -07005042 cfilt_mode.reg_mask = 0x30;
5043
Simmi Pateriya95466b12013-05-09 20:08:46 +05305044 return cfilt_mode;
5045}
5046
5047static void tapan_select_cfilt(struct snd_soc_codec *codec,
5048 struct wcd9xxx_mbhc *mbhc)
5049{
5050 snd_soc_update_bits(codec, mbhc->mbhc_bias_regs.ctl_reg, 0x60, 0x00);
5051}
5052
5053static void tapan_free_irq(struct wcd9xxx_mbhc *mbhc)
5054{
Bhalchandra Gajare8e5fe252013-07-15 19:42:21 -07005055 struct wcd9xxx *wcd9xxx = mbhc->codec->control_data;
5056 struct wcd9xxx_core_resource *core_res =
5057 &wcd9xxx->core_res;
5058 wcd9xxx_free_irq(core_res, WCD9306_IRQ_MBHC_JACK_SWITCH, mbhc);
5059}
5060
5061enum wcd9xxx_cdc_type tapan_get_cdc_type(void)
5062{
5063 return WCD9XXX_CDC_TYPE_TAPAN;
Simmi Pateriya95466b12013-05-09 20:08:46 +05305064}
5065
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -07005066static void wcd9xxx_prepare_hph_pa(struct wcd9xxx_mbhc *mbhc,
5067 struct list_head *lh)
5068{
5069 int i;
5070 struct snd_soc_codec *codec = mbhc->codec;
5071 u32 delay;
5072
5073 const struct wcd9xxx_reg_mask_val reg_set_paon[] = {
5074 {WCD9XXX_A_CDC_CLSH_B1_CTL, 0x0F, 0x00},
5075 {WCD9XXX_A_RX_HPH_CHOP_CTL, 0xFF, 0xA4},
5076 {WCD9XXX_A_RX_HPH_OCP_CTL, 0xFF, 0x67},
5077 {WCD9XXX_A_RX_HPH_L_TEST, 0x1, 0x0},
5078 {WCD9XXX_A_RX_HPH_R_TEST, 0x1, 0x0},
5079 {WCD9XXX_A_RX_HPH_BIAS_WG_OCP, 0xFF, 0x1A},
5080 {WCD9XXX_A_RX_HPH_CNP_WG_CTL, 0xFF, 0xDB},
5081 {WCD9XXX_A_RX_HPH_CNP_WG_TIME, 0xFF, 0x2A},
5082 {TAPAN_A_CDC_CONN_RX2_B2_CTL, 0xFF, 0x10},
5083 {WCD9XXX_A_CDC_CLK_OTHR_CTL, 0xFF, 0x05},
5084 {WCD9XXX_A_CDC_RX1_B6_CTL, 0xFF, 0x81},
5085 {WCD9XXX_A_CDC_CLK_RX_B1_CTL, 0x03, 0x03},
5086 {WCD9XXX_A_RX_HPH_L_GAIN, 0xFF, 0x2C},
5087 {WCD9XXX_A_CDC_RX2_B6_CTL, 0xFF, 0x81},
5088 {WCD9XXX_A_RX_HPH_R_GAIN, 0xFF, 0x2C},
5089 {WCD9XXX_A_BUCK_CTRL_CCL_4, 0xFF, 0x50},
5090 {WCD9XXX_A_BUCK_CTRL_VCL_1, 0xFF, 0x08},
5091 {WCD9XXX_A_BUCK_CTRL_CCL_1, 0xFF, 0x5B},
5092 {WCD9XXX_A_NCP_CLK, 0xFF, 0x9C},
5093 {WCD9XXX_A_NCP_CLK, 0xFF, 0xFC},
5094 {WCD9XXX_A_BUCK_MODE_3, 0xFF, 0xCE},
5095 {WCD9XXX_A_BUCK_CTRL_CCL_3, 0xFF, 0x6B},
5096 {WCD9XXX_A_BUCK_CTRL_CCL_3, 0xFF, 0x6F},
5097 {TAPAN_A_RX_BUCK_BIAS1, 0xFF, 0x62},
5098 {TAPAN_A_RX_HPH_BIAS_PA, 0xFF, 0x7A},
5099 {TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, 0xFF, 0x02},
5100 {TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, 0xFF, 0x06},
5101 {WCD9XXX_A_RX_COM_BIAS, 0xFF, 0x80},
5102 {WCD9XXX_A_BUCK_MODE_3, 0xFF, 0xC6},
5103 {WCD9XXX_A_BUCK_MODE_4, 0xFF, 0xE6},
5104 {WCD9XXX_A_BUCK_MODE_5, 0xFF, 0x02},
5105 {WCD9XXX_A_BUCK_MODE_1, 0xFF, 0xA1},
5106 /* Delay 1ms */
5107 {WCD9XXX_A_NCP_EN, 0xFF, 0xFF},
5108 /* Delay 1ms */
5109 {WCD9XXX_A_BUCK_MODE_5, 0xFF, 0x03},
5110 {WCD9XXX_A_BUCK_MODE_5, 0xFF, 0x7B},
5111 {WCD9XXX_A_CDC_CLSH_B1_CTL, 0xFF, 0xE6},
5112 {WCD9XXX_A_RX_HPH_L_DAC_CTL, 0xFF, 0x40},
5113 {WCD9XXX_A_RX_HPH_L_DAC_CTL, 0xFF, 0xC0},
5114 {WCD9XXX_A_RX_HPH_R_DAC_CTL, 0xFF, 0x40},
5115 {WCD9XXX_A_RX_HPH_R_DAC_CTL, 0xFF, 0xC0},
5116 {WCD9XXX_A_NCP_STATIC, 0xFF, 0x08},
5117 {WCD9XXX_A_RX_HPH_L_DAC_CTL, 0x03, 0x01},
5118 {WCD9XXX_A_RX_HPH_R_DAC_CTL, 0x03, 0x01},
5119 };
5120
5121 /*
5122 * Configure PA in class-AB, -18dB gain,
5123 * companding off, OCP off, Chopping ON
5124 */
5125 for (i = 0; i < ARRAY_SIZE(reg_set_paon); i++) {
5126 /*
5127 * Some of the codec registers like BUCK_MODE_1
5128 * and NCP_EN requires 1ms wait time for them
5129 * to take effect. Other register writes for
5130 * PA configuration do not require any wait time.
5131 */
5132 if (reg_set_paon[i].reg == WCD9XXX_A_BUCK_MODE_1 ||
5133 reg_set_paon[i].reg == WCD9XXX_A_NCP_EN)
5134 delay = 1000;
5135 else
5136 delay = 0;
5137 wcd9xxx_soc_update_bits_push(codec, lh,
5138 reg_set_paon[i].reg,
5139 reg_set_paon[i].mask,
5140 reg_set_paon[i].val, delay);
5141 }
5142 pr_debug("%s: PAs are prepared\n", __func__);
5143 return;
5144}
5145
5146static int wcd9xxx_enable_static_pa(struct wcd9xxx_mbhc *mbhc, bool enable)
5147{
5148 struct snd_soc_codec *codec = mbhc->codec;
5149 int wg_time = snd_soc_read(codec, WCD9XXX_A_RX_HPH_CNP_WG_TIME) *
5150 TAPAN_WG_TIME_FACTOR_US;
5151 /*
5152 * Tapan requires additional time to enable PA.
5153 * It is observed during experiments that we need
5154 * an additional wait time about 0.35 times of
5155 * the WG_TIME
5156 */
5157 wg_time += (int) (wg_time * 35) / 100;
5158
5159 snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_CNP_EN, 0x30,
5160 enable ? 0x30 : 0x0);
5161 /* Wait for wave gen time to avoid pop noise */
5162 usleep_range(wg_time, wg_time + WCD9XXX_USLEEP_RANGE_MARGIN_US);
5163 pr_debug("%s: PAs are %s as static mode (wg_time %d)\n", __func__,
5164 enable ? "enabled" : "disabled", wg_time);
5165 return 0;
5166}
5167
5168static int tapan_setup_zdet(struct wcd9xxx_mbhc *mbhc,
5169 enum mbhc_impedance_detect_stages stage)
5170{
5171
5172 int ret = 0;
5173 struct snd_soc_codec *codec = mbhc->codec;
5174 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
5175 const int mux_wait_us = 25;
5176
5177 switch (stage) {
5178
5179 case PRE_MEAS:
5180 INIT_LIST_HEAD(&tapan->reg_save_restore);
5181 /* Configure PA */
5182 wcd9xxx_prepare_hph_pa(mbhc, &tapan->reg_save_restore);
5183
5184#define __wr(reg, mask, value) \
5185 do { \
5186 ret = wcd9xxx_soc_update_bits_push(codec, \
5187 &tapan->reg_save_restore, \
5188 reg, mask, value, 0); \
5189 if (ret < 0) \
5190 return ret; \
5191 } while (0)
5192
5193 /* Setup MBHC */
5194 __wr(WCD9XXX_A_MBHC_SCALING_MUX_1, 0x7F, 0x40);
5195 __wr(WCD9XXX_A_MBHC_SCALING_MUX_2, 0xFF, 0xF0);
5196 __wr(WCD9XXX_A_TX_7_MBHC_TEST_CTL, 0xFF, 0x78);
5197 __wr(WCD9XXX_A_TX_7_MBHC_EN, 0xFF, 0xEC);
5198 __wr(WCD9XXX_A_CDC_MBHC_TIMER_B4_CTL, 0xFF, 0x45);
5199 __wr(WCD9XXX_A_CDC_MBHC_TIMER_B5_CTL, 0xFF, 0x80);
5200
5201 __wr(WCD9XXX_A_CDC_MBHC_CLK_CTL, 0xFF, 0x0A);
5202 snd_soc_write(codec, WCD9XXX_A_CDC_MBHC_EN_CTL, 0x2);
5203 __wr(WCD9XXX_A_CDC_MBHC_CLK_CTL, 0xFF, 0x02);
5204
5205 /* Enable Impedance Detection */
5206 __wr(WCD9XXX_A_MBHC_HPH, 0xFF, 0xC8);
5207
5208 /*
5209 * CnP setup for 0mV
5210 * Route static data as input to noise shaper
5211 */
5212 __wr(TAPAN_A_CDC_RX1_B3_CTL, 0xFF, 0x02);
5213 __wr(TAPAN_A_CDC_RX2_B3_CTL, 0xFF, 0x02);
5214
5215 snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_L_TEST,
5216 0x02, 0x00);
5217 snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_R_TEST,
5218 0x02, 0x00);
5219
5220 /* Reset the HPHL static data pointer */
5221 __wr(TAPAN_A_CDC_RX1_B2_CTL, 0xFF, 0x00);
5222 /* Four consecutive writes to set 0V as static data input */
5223 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
5224 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
5225 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
5226 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
5227
5228 /* Reset the HPHR static data pointer */
5229 __wr(TAPAN_A_CDC_RX2_B2_CTL, 0xFF, 0x00);
5230 /* Four consecutive writes to set 0V as static data input */
5231 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
5232 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
5233 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
5234 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
5235
5236 /* Enable the HPHL and HPHR PA */
5237 wcd9xxx_enable_static_pa(mbhc, true);
5238 break;
5239 case POST_MEAS:
5240 /* Turn off ICAL */
5241 snd_soc_write(codec, WCD9XXX_A_MBHC_SCALING_MUX_2, 0xF0);
5242
5243 wcd9xxx_enable_static_pa(mbhc, false);
5244
5245 /*
5246 * Setup CnP wavegen to ramp to the desired
5247 * output using a 40ms ramp
5248 */
5249
5250 /* CnP wavegen current to 0.5uA */
5251 snd_soc_write(codec, WCD9XXX_A_RX_HPH_BIAS_WG_OCP, 0x1A);
5252 /* Set the current division ratio to 2000 */
5253 snd_soc_write(codec, WCD9XXX_A_RX_HPH_CNP_WG_CTL, 0xDF);
5254 /* Set the wavegen timer to max (60msec) */
5255 snd_soc_write(codec, WCD9XXX_A_RX_HPH_CNP_WG_TIME, 0xA0);
5256 /* Set the CnP reference current to sc_bias */
5257 snd_soc_write(codec, WCD9XXX_A_RX_HPH_OCP_CTL, 0x6D);
5258
5259 snd_soc_write(codec, TAPAN_A_CDC_RX1_B2_CTL, 0x00);
5260 /* Four consecutive writes to set -10mV as static data input */
5261 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
5262 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x1F);
5263 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x19);
5264 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0xAA);
5265
5266 snd_soc_write(codec, TAPAN_A_CDC_RX2_B2_CTL, 0x00);
5267 /* Four consecutive writes to set -10mV as static data input */
5268 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
5269 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x1F);
5270 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x19);
5271 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0xAA);
5272
5273 snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_L_TEST,
5274 0x02, 0x02);
5275 snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_R_TEST,
5276 0x02, 0x02);
5277 /* Enable the HPHL and HPHR PA and wait for 60mS */
5278 wcd9xxx_enable_static_pa(mbhc, true);
5279
5280 snd_soc_update_bits(codec, WCD9XXX_A_MBHC_SCALING_MUX_1,
5281 0x7F, 0x40);
5282 usleep_range(mux_wait_us,
5283 mux_wait_us + WCD9XXX_USLEEP_RANGE_MARGIN_US);
5284 break;
5285 case PA_DISABLE:
5286 wcd9xxx_enable_static_pa(mbhc, false);
5287 wcd9xxx_restore_registers(codec, &tapan->reg_save_restore);
5288 break;
5289 }
5290#undef __wr
5291
5292 return ret;
5293}
5294
5295static void tapan_compute_impedance(s16 *l, s16 *r, uint32_t *zl, uint32_t *zr)
5296{
5297 int zln, zld;
5298 int zrn, zrd;
5299 int rl = 0, rr = 0;
5300
5301 zln = (l[1] - l[0]) * TAPAN_ZDET_MUL_FACTOR;
5302 zld = (l[2] - l[0]);
5303 if (zld)
5304 rl = zln / zld;
5305
5306 zrn = (r[1] - r[0]) * TAPAN_ZDET_MUL_FACTOR;
5307 zrd = (r[2] - r[0]);
5308 if (zrd)
5309 rr = zrn / zrd;
5310
5311 *zl = rl;
5312 *zr = rr;
5313}
5314
Simmi Pateriya95466b12013-05-09 20:08:46 +05305315static const struct wcd9xxx_mbhc_cb mbhc_cb = {
5316 .enable_mux_bias_block = tapan_enable_mux_bias_block,
5317 .cfilt_fast_mode = tapan_put_cfilt_fast_mode,
5318 .codec_specific_cal = tapan_codec_specific_cal_setup,
5319 .jack_detect_irq = tapan_get_jack_detect_irq,
5320 .switch_cfilt_mode = tapan_codec_switch_cfilt_mode,
5321 .select_cfilt = tapan_select_cfilt,
5322 .free_irq = tapan_free_irq,
Bhalchandra Gajare8e5fe252013-07-15 19:42:21 -07005323 .get_cdc_type = tapan_get_cdc_type,
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -07005324 .setup_zdet = tapan_setup_zdet,
5325 .compute_impedance = tapan_compute_impedance,
Simmi Pateriya95466b12013-05-09 20:08:46 +05305326};
5327
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005328int tapan_hs_detect(struct snd_soc_codec *codec,
5329 struct wcd9xxx_mbhc_config *mbhc_cfg)
5330{
5331 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
5332 return wcd9xxx_mbhc_start(&tapan->mbhc, mbhc_cfg);
5333}
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005334EXPORT_SYMBOL(tapan_hs_detect);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005335
Joonwoo Parke7d724e2013-08-19 15:51:01 -07005336void tapan_hs_detect_exit(struct snd_soc_codec *codec)
5337{
5338 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
5339 wcd9xxx_mbhc_stop(&tapan->mbhc);
5340}
5341EXPORT_SYMBOL(tapan_hs_detect_exit);
5342
Damir Didjustod6aea992013-09-03 21:18:59 -07005343void tapan_event_register(
5344 int (*machine_event_cb)(struct snd_soc_codec *codec,
5345 enum wcd9xxx_codec_event),
5346 struct snd_soc_codec *codec)
5347{
5348 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
5349 tapan->machine_codec_event_cb = machine_event_cb;
5350}
5351EXPORT_SYMBOL(tapan_event_register);
5352
Joonwoo Park8ffa2812013-08-07 19:01:30 -07005353static int tapan_device_down(struct wcd9xxx *wcd9xxx)
5354{
5355 struct snd_soc_codec *codec;
5356
5357 codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
5358 snd_soc_card_change_online_state(codec->card, 0);
5359
5360 return 0;
5361}
5362
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005363static int tapan_post_reset_cb(struct wcd9xxx *wcd9xxx)
5364{
5365 int ret = 0;
5366 int rco_clk_rate;
5367 struct snd_soc_codec *codec;
5368 struct tapan_priv *tapan;
5369
5370 codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
5371 tapan = snd_soc_codec_get_drvdata(codec);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005372
Joonwoo Park8ffa2812013-08-07 19:01:30 -07005373 snd_soc_card_change_online_state(codec->card, 1);
5374
5375 mutex_lock(&codec->mutex);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005376 if (codec->reg_def_copy) {
5377 pr_debug("%s: Update ASOC cache", __func__);
5378 kfree(codec->reg_cache);
5379 codec->reg_cache = kmemdup(codec->reg_def_copy,
5380 codec->reg_size, GFP_KERNEL);
5381 if (!codec->reg_cache) {
5382 pr_err("%s: Cache update failed!\n", __func__);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005383 mutex_unlock(&codec->mutex);
5384 return -ENOMEM;
5385 }
5386 }
5387
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005388 if (spkr_drv_wrnd == 1)
5389 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005390
5391 tapan_update_reg_defaults(codec);
5392 tapan_update_reg_mclk_rate(wcd9xxx);
5393 tapan_codec_init_reg(codec);
5394 ret = tapan_handle_pdata(tapan);
5395 if (IS_ERR_VALUE(ret))
5396 pr_err("%s: bad pdata\n", __func__);
5397
5398 tapan_slim_interface_init_reg(codec);
5399
Joonwoo Park865bcf02013-07-15 14:05:32 -07005400 wcd9xxx_resmgr_post_ssr(&tapan->resmgr);
5401
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005402 wcd9xxx_mbhc_deinit(&tapan->mbhc);
5403
5404 if (TAPAN_IS_1_0(wcd9xxx->version))
5405 rco_clk_rate = TAPAN_MCLK_CLK_12P288MHZ;
5406 else
5407 rco_clk_rate = TAPAN_MCLK_CLK_9P6MHZ;
5408
5409 ret = wcd9xxx_mbhc_init(&tapan->mbhc, &tapan->resmgr, codec, NULL,
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -07005410 &mbhc_cb, rco_clk_rate,
5411 TAPAN_CDC_ZDET_SUPPORTED);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005412 if (ret)
5413 pr_err("%s: mbhc init failed %d\n", __func__, ret);
5414 else
5415 wcd9xxx_mbhc_start(&tapan->mbhc, tapan->mbhc.mbhc_cfg);
Joonwoo Parkc98049a2013-07-30 16:43:34 -07005416
5417 tapan_cleanup_irqs(tapan);
5418 ret = tapan_setup_irqs(tapan);
5419 if (ret)
5420 pr_err("%s: Failed to setup irq: %d\n", __func__, ret);
5421
Damir Didjustod6aea992013-09-03 21:18:59 -07005422 tapan->machine_codec_event_cb(codec, WCD9XXX_CODEC_EVENT_CODEC_UP);
5423
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005424 mutex_unlock(&codec->mutex);
5425 return ret;
5426}
5427
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005428static struct wcd9xxx_reg_address tapan_reg_address = {
5429};
5430
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005431static int wcd9xxx_ssr_register(struct wcd9xxx *control,
Joonwoo Park8ffa2812013-08-07 19:01:30 -07005432 int (*device_down_cb)(struct wcd9xxx *wcd9xxx),
5433 int (*device_up_cb)(struct wcd9xxx *wcd9xxx),
5434 void *priv)
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005435{
Joonwoo Park8ffa2812013-08-07 19:01:30 -07005436 control->dev_down = device_down_cb;
5437 control->post_reset = device_up_cb;
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005438 control->ssr_priv = priv;
5439 return 0;
5440}
5441
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07005442static struct regulator *tapan_codec_find_regulator(
5443 struct snd_soc_codec *codec,
5444 const char *name)
5445{
5446 int i;
5447 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
5448
5449 for (i = 0; i < core->num_of_supplies; i++) {
5450 if (core->supplies[i].supply &&
5451 !strcmp(core->supplies[i].supply, name))
5452 return core->supplies[i].consumer;
5453 }
5454 return NULL;
5455}
5456
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005457static void tapan_enable_config_rco(struct wcd9xxx *core, bool enable)
5458{
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005459 struct wcd9xxx_core_resource *core_res = &core->core_res;
5460
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005461 if (enable) {
Phani Kumar Uppalapaticc3ec0c2013-09-06 18:04:03 -07005462 wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
5463 0x80, 0x80);
5464 wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
5465 0x04, 0x04);
5466 wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
5467 0x01, 0x01);
5468 usleep_range(1000, 1000);
5469 wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
5470 0x80, 0x00);
5471
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005472 /* Enable RC Oscillator */
5473 wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_FREQ, 0x10, 0x00);
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005474 wcd9xxx_reg_write(core_res, WCD9XXX_A_BIAS_OSC_BG_CTL, 0x17);
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005475 usleep_range(5, 5);
5476 wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_FREQ, 0x80, 0x80);
5477 wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_TEST, 0x80, 0x80);
5478 usleep_range(10, 10);
5479 wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_TEST, 0x80, 0x00);
5480 usleep_range(20, 20);
5481 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN1, 0x08, 0x08);
5482 /* Enable MCLK and wait 1ms till it gets enabled */
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005483 wcd9xxx_reg_write(core_res, WCD9XXX_A_CLK_BUFF_EN2, 0x02);
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005484 usleep_range(1000, 1000);
5485 /* Enable CLK BUFF and wait for 1.2ms */
5486 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN1, 0x01, 0x01);
5487 usleep_range(1000, 1200);
5488
5489 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x02, 0x00);
5490 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x04, 0x04);
5491 wcd9xxx_reg_update(core, WCD9XXX_A_CDC_CLK_MCLK_CTL,
5492 0x01, 0x01);
5493 usleep_range(50, 50);
5494 } else {
5495 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x04, 0x00);
5496 usleep_range(50, 50);
5497 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x02, 0x02);
5498 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN1, 0x05, 0x00);
5499 usleep_range(50, 50);
Phani Kumar Uppalapaticc3ec0c2013-09-06 18:04:03 -07005500
5501 wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_FREQ, 0x80, 0x00);
5502 usleep_range(10, 10);
5503 wcd9xxx_reg_write(core_res, WCD9XXX_A_BIAS_OSC_BG_CTL, 0x16);
5504 wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
5505 0x03, 0x00);
5506 usleep_range(100, 100);
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005507 }
5508
5509}
5510
5511static bool tapan_check_wcd9306(struct device *cdc_dev, bool sensed)
5512{
5513 struct wcd9xxx *core = dev_get_drvdata(cdc_dev->parent);
5514 u8 reg_val;
5515 bool ret = true;
5516 unsigned long timeout;
5517 bool timedout;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005518 struct wcd9xxx_core_resource *core_res = &core->core_res;
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005519
5520 if (!core) {
5521 dev_err(cdc_dev, "%s: core not initialized\n", __func__);
5522 return -EINVAL;
5523 }
5524
5525 tapan_enable_config_rco(core, 1);
5526
5527 if (sensed == false) {
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005528 reg_val = wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_CTL);
5529 wcd9xxx_reg_write(core_res, TAPAN_A_QFUSE_CTL,
5530 (reg_val | 0x03));
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005531 }
5532
5533 timeout = jiffies + HZ;
5534 do {
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005535 if ((wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_STATUS)))
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005536 break;
5537 } while (!(timedout = time_after(jiffies, timeout)));
5538
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005539 if (wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_DATA_OUT1) ||
5540 wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_DATA_OUT2)) {
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005541 dev_info(cdc_dev, "%s: wcd9302 detected\n", __func__);
5542 ret = false;
5543 } else
5544 dev_info(cdc_dev, "%s: wcd9306 detected\n", __func__);
5545
5546 tapan_enable_config_rco(core, 0);
5547 return ret;
5548};
5549
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005550static int tapan_codec_probe(struct snd_soc_codec *codec)
5551{
5552 struct wcd9xxx *control;
5553 struct tapan_priv *tapan;
5554 struct wcd9xxx_pdata *pdata;
5555 struct wcd9xxx *wcd9xxx;
5556 struct snd_soc_dapm_context *dapm = &codec->dapm;
5557 int ret = 0;
Phani Kumar Uppalapati43bc4152013-05-24 00:44:20 -07005558 int i, rco_clk_rate;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005559 void *ptr = NULL;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005560 struct wcd9xxx_core_resource *core_res;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005561
5562 codec->control_data = dev_get_drvdata(codec->dev->parent);
5563 control = codec->control_data;
5564
Joonwoo Park8ffa2812013-08-07 19:01:30 -07005565 wcd9xxx_ssr_register(control, tapan_device_down,
5566 tapan_post_reset_cb, (void *)codec);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005567
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005568 dev_info(codec->dev, "%s()\n", __func__);
5569
5570 tapan = kzalloc(sizeof(struct tapan_priv), GFP_KERNEL);
5571 if (!tapan) {
5572 dev_err(codec->dev, "Failed to allocate private data\n");
5573 return -ENOMEM;
5574 }
5575 for (i = 0 ; i < NUM_DECIMATORS; i++) {
5576 tx_hpf_work[i].tapan = tapan;
5577 tx_hpf_work[i].decimator = i + 1;
5578 INIT_DELAYED_WORK(&tx_hpf_work[i].dwork,
5579 tx_hpf_corner_freq_callback);
5580 }
5581
5582 snd_soc_codec_set_drvdata(codec, tapan);
5583
5584 /* codec resmgr module init */
5585 wcd9xxx = codec->control_data;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005586 core_res = &wcd9xxx->core_res;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005587 pdata = dev_get_platdata(codec->dev->parent);
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005588 ret = wcd9xxx_resmgr_init(&tapan->resmgr, codec, core_res, pdata,
Bhalchandra Gajare8e5fe252013-07-15 19:42:21 -07005589 &tapan_reg_address, WCD9XXX_CDC_TYPE_TAPAN);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005590 if (ret) {
5591 pr_err("%s: wcd9xxx init failed %d\n", __func__, ret);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005592 return ret;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005593 }
5594
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07005595 tapan->cp_regulators[CP_REG_BUCK] = tapan_codec_find_regulator(codec,
5596 WCD9XXX_SUPPLY_BUCK_NAME);
5597 tapan->cp_regulators[CP_REG_BHELPER] = tapan_codec_find_regulator(codec,
5598 "cdc-vdd-buckhelper");
5599
Bhalchandra Gajare7c739522013-06-20 15:31:02 -07005600 tapan->clsh_d.buck_mv = tapan_codec_get_buck_mv(codec);
5601 /*
5602 * If 1.8 volts is requested on the vdd_cp line, then
5603 * assume that S4 is in a dynamically switchable state
5604 * and can switch between 1.8 volts and 2.15 volts
5605 */
5606 if (tapan->clsh_d.buck_mv == WCD9XXX_CDC_BUCK_MV_1P8)
5607 tapan->clsh_d.is_dynamic_vdd_cp = true;
5608 wcd9xxx_clsh_init(&tapan->clsh_d, &tapan->resmgr);
5609
Phani Kumar Uppalapati43bc4152013-05-24 00:44:20 -07005610 if (TAPAN_IS_1_0(control->version))
5611 rco_clk_rate = TAPAN_MCLK_CLK_12P288MHZ;
5612 else
5613 rco_clk_rate = TAPAN_MCLK_CLK_9P6MHZ;
5614
Joonwoo Parkccccba72013-04-26 11:19:46 -07005615 ret = wcd9xxx_mbhc_init(&tapan->mbhc, &tapan->resmgr, codec, NULL,
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -07005616 &mbhc_cb, rco_clk_rate,
5617 TAPAN_CDC_ZDET_SUPPORTED);
Simmi Pateriya95466b12013-05-09 20:08:46 +05305618
Simmi Pateriya0a44d842013-04-03 01:12:42 +05305619 if (ret) {
5620 pr_err("%s: mbhc init failed %d\n", __func__, ret);
5621 return ret;
5622 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005623
5624 tapan->codec = codec;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005625 for (i = 0; i < COMPANDER_MAX; i++) {
5626 tapan->comp_enabled[i] = 0;
5627 tapan->comp_fs[i] = COMPANDER_FS_48KHZ;
5628 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005629 tapan->intf_type = wcd9xxx_get_intf_type();
5630 tapan->aux_pga_cnt = 0;
5631 tapan->aux_l_gain = 0x1F;
5632 tapan->aux_r_gain = 0x1F;
5633 tapan_update_reg_defaults(codec);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005634 tapan_update_reg_mclk_rate(wcd9xxx);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005635 tapan_codec_init_reg(codec);
5636 ret = tapan_handle_pdata(tapan);
5637 if (IS_ERR_VALUE(ret)) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005638 dev_err(codec->dev, "%s: bad pdata\n", __func__);
5639 goto err_pdata;
5640 }
5641
5642 if (spkr_drv_wrnd > 0) {
Joonwoo Park533b3682013-06-13 11:41:21 -07005643 WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005644 wcd9xxx_resmgr_get_bandgap(&tapan->resmgr,
5645 WCD9XXX_BANDGAP_AUDIO_MODE);
Joonwoo Park533b3682013-06-13 11:41:21 -07005646 WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005647 }
5648
5649 ptr = kmalloc((sizeof(tapan_rx_chs) +
5650 sizeof(tapan_tx_chs)), GFP_KERNEL);
5651 if (!ptr) {
5652 pr_err("%s: no mem for slim chan ctl data\n", __func__);
5653 ret = -ENOMEM;
5654 goto err_nomem_slimch;
5655 }
5656
5657 if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005658 snd_soc_dapm_new_controls(dapm, tapan_dapm_i2s_widgets,
5659 ARRAY_SIZE(tapan_dapm_i2s_widgets));
5660 snd_soc_dapm_add_routes(dapm, audio_i2s_map,
5661 ARRAY_SIZE(audio_i2s_map));
5662 for (i = 0; i < ARRAY_SIZE(tapan_i2s_dai); i++)
5663 INIT_LIST_HEAD(&tapan->dai[i].wcd9xxx_ch_list);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005664 } else if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
5665 for (i = 0; i < NUM_CODEC_DAIS; i++) {
5666 INIT_LIST_HEAD(&tapan->dai[i].wcd9xxx_ch_list);
5667 init_waitqueue_head(&tapan->dai[i].dai_wait);
5668 }
Damir Didjustod6aea992013-09-03 21:18:59 -07005669 tapan_init_slim_slave_cfg(codec);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005670 }
5671
Phani Kumar Uppalapaticc3ec0c2013-09-06 18:04:03 -07005672 if (codec_ver == WCD9306) {
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005673 snd_soc_add_codec_controls(codec, tapan_9306_snd_controls,
5674 ARRAY_SIZE(tapan_9306_snd_controls));
5675 snd_soc_dapm_new_controls(dapm, tapan_9306_dapm_widgets,
5676 ARRAY_SIZE(tapan_9306_dapm_widgets));
5677 snd_soc_dapm_add_routes(dapm, wcd9306_map,
5678 ARRAY_SIZE(wcd9306_map));
5679 } else {
5680 snd_soc_dapm_add_routes(dapm, wcd9302_map,
5681 ARRAY_SIZE(wcd9302_map));
5682 }
5683
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005684 control->num_rx_port = TAPAN_RX_MAX;
5685 control->rx_chs = ptr;
5686 memcpy(control->rx_chs, tapan_rx_chs, sizeof(tapan_rx_chs));
5687 control->num_tx_port = TAPAN_TX_MAX;
5688 control->tx_chs = ptr + sizeof(tapan_rx_chs);
5689 memcpy(control->tx_chs, tapan_tx_chs, sizeof(tapan_tx_chs));
5690
5691 snd_soc_dapm_sync(dapm);
5692
5693 (void) tapan_setup_irqs(tapan);
5694
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005695 atomic_set(&kp_tapan_priv, (unsigned long)tapan);
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07005696 mutex_lock(&dapm->codec->mutex);
Phani Kumar Uppalapaticc3ec0c2013-09-06 18:04:03 -07005697 if (codec_ver == WCD9306) {
5698 snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
5699 snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
5700 snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE");
5701 snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
5702 snd_soc_dapm_disable_pin(dapm, "ANC EAR");
5703 }
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07005704 snd_soc_dapm_sync(dapm);
5705 mutex_unlock(&dapm->codec->mutex);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005706
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005707 codec->ignore_pmdown_time = 1;
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07005708
5709 if (ret)
5710 tapan_cleanup_irqs(tapan);
5711
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005712 return ret;
5713
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005714err_pdata:
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005715 kfree(ptr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005716err_nomem_slimch:
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005717 kfree(tapan);
5718 return ret;
5719}
5720
5721static int tapan_codec_remove(struct snd_soc_codec *codec)
5722{
5723 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07005724 int index = 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005725
Joonwoo Park533b3682013-06-13 11:41:21 -07005726 WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005727 atomic_set(&kp_tapan_priv, 0);
5728
5729 if (spkr_drv_wrnd > 0)
5730 wcd9xxx_resmgr_put_bandgap(&tapan->resmgr,
5731 WCD9XXX_BANDGAP_AUDIO_MODE);
Joonwoo Park533b3682013-06-13 11:41:21 -07005732 WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07005733
5734 tapan_cleanup_irqs(tapan);
5735
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005736 /* cleanup MBHC */
5737 wcd9xxx_mbhc_deinit(&tapan->mbhc);
5738 /* cleanup resmgr */
5739 wcd9xxx_resmgr_deinit(&tapan->resmgr);
5740
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07005741 for (index = 0; index < CP_REG_MAX; index++)
5742 tapan->cp_regulators[index] = NULL;
5743
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005744 kfree(tapan);
5745 return 0;
5746}
5747
5748static struct snd_soc_codec_driver soc_codec_dev_tapan = {
5749 .probe = tapan_codec_probe,
5750 .remove = tapan_codec_remove,
5751
5752 .read = tapan_read,
5753 .write = tapan_write,
5754
5755 .readable_register = tapan_readable,
5756 .volatile_register = tapan_volatile,
5757
5758 .reg_cache_size = TAPAN_CACHE_SIZE,
5759 .reg_cache_default = tapan_reset_reg_defaults,
5760 .reg_word_size = 1,
5761
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005762 .controls = tapan_common_snd_controls,
5763 .num_controls = ARRAY_SIZE(tapan_common_snd_controls),
5764 .dapm_widgets = tapan_common_dapm_widgets,
5765 .num_dapm_widgets = ARRAY_SIZE(tapan_common_dapm_widgets),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005766 .dapm_routes = audio_map,
5767 .num_dapm_routes = ARRAY_SIZE(audio_map),
5768};
5769
5770#ifdef CONFIG_PM
5771static int tapan_suspend(struct device *dev)
5772{
5773 dev_dbg(dev, "%s: system suspend\n", __func__);
5774 return 0;
5775}
5776
5777static int tapan_resume(struct device *dev)
5778{
5779 struct platform_device *pdev = to_platform_device(dev);
5780 struct tapan_priv *tapan = platform_get_drvdata(pdev);
5781 dev_dbg(dev, "%s: system resume\n", __func__);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005782 /* Notify */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005783 wcd9xxx_resmgr_notifier_call(&tapan->resmgr, WCD9XXX_EVENT_POST_RESUME);
5784 return 0;
5785}
5786
5787static const struct dev_pm_ops tapan_pm_ops = {
5788 .suspend = tapan_suspend,
5789 .resume = tapan_resume,
5790};
5791#endif
5792
5793static int __devinit tapan_probe(struct platform_device *pdev)
5794{
5795 int ret = 0;
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005796 bool is_wcd9306;
5797
5798 is_wcd9306 = tapan_check_wcd9306(&pdev->dev, false);
5799 if (is_wcd9306 < 0) {
5800 dev_info(&pdev->dev, "%s: cannot find codec type, default to 9306\n",
5801 __func__);
5802 is_wcd9306 = true;
5803 }
Phani Kumar Uppalapaticc3ec0c2013-09-06 18:04:03 -07005804 codec_ver = is_wcd9306 ? WCD9306 : WCD9302;
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005805
5806 if (!is_wcd9306) {
5807 if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
5808 ret = snd_soc_register_codec(&pdev->dev,
5809 &soc_codec_dev_tapan,
5810 tapan9302_dai, ARRAY_SIZE(tapan9302_dai));
5811 else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C)
5812 ret = snd_soc_register_codec(&pdev->dev,
5813 &soc_codec_dev_tapan,
5814 tapan_i2s_dai, ARRAY_SIZE(tapan_i2s_dai));
5815 } else {
5816 if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
5817 ret = snd_soc_register_codec(&pdev->dev,
5818 &soc_codec_dev_tapan,
5819 tapan_dai, ARRAY_SIZE(tapan_dai));
5820 else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C)
5821 ret = snd_soc_register_codec(&pdev->dev,
5822 &soc_codec_dev_tapan,
5823 tapan_i2s_dai, ARRAY_SIZE(tapan_i2s_dai));
5824 }
5825
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005826 return ret;
5827}
5828static int __devexit tapan_remove(struct platform_device *pdev)
5829{
5830 snd_soc_unregister_codec(&pdev->dev);
5831 return 0;
5832}
5833static struct platform_driver tapan_codec_driver = {
5834 .probe = tapan_probe,
5835 .remove = tapan_remove,
5836 .driver = {
5837 .name = "tapan_codec",
5838 .owner = THIS_MODULE,
5839#ifdef CONFIG_PM
5840 .pm = &tapan_pm_ops,
5841#endif
5842 },
5843};
5844
5845static int __init tapan_codec_init(void)
5846{
5847 return platform_driver_register(&tapan_codec_driver);
5848}
5849
5850static void __exit tapan_codec_exit(void)
5851{
5852 platform_driver_unregister(&tapan_codec_driver);
5853}
5854
5855module_init(tapan_codec_init);
5856module_exit(tapan_codec_exit);
5857
5858MODULE_DESCRIPTION("Tapan codec driver");
5859MODULE_LICENSE("GPL v2");