blob: 95f204190686cc8fae5c22b201826f10040730ad [file] [log] [blame]
Mohammad Johny Shaikabb80c62013-12-27 11:02:02 +05301/* Copyright (c) 2012-2014, 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
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -070045#define DAPM_MICBIAS2_EXTERNAL_STANDALONE "MIC BIAS2 External Standalone"
Venkat Sudhirbb444472014-01-14 10:03:23 -080046#define TAPAN_VALIDATE_RX_SBPORT_RANGE(port) ((port >= 16) && (port <= 20))
47#define TAPAN_CONVERT_RX_SBPORT_ID(port) (port - 16) /* RX1 port ID = 0 */
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -070048
Bhalchandra Gajare4e3dd852013-08-19 17:21:23 -070049#define TAPAN_VDD_CX_OPTIMAL_UA 10000
50#define TAPAN_VDD_CX_SLEEP_UA 2000
51
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -070052/* RX_HPH_CNP_WG_TIME increases by 0.24ms */
53#define TAPAN_WG_TIME_FACTOR_US 240
54
Damir Didjustod6aea992013-09-03 21:18:59 -070055#define TAPAN_SB_PGD_PORT_RX_BASE 0x40
56#define TAPAN_SB_PGD_PORT_TX_BASE 0x50
57#define TAPAN_REGISTER_START_OFFSET 0x800
58
59#define CODEC_REG_CFG_MINOR_VER 1
60
Bhalchandra Gajare4e3dd852013-08-19 17:21:23 -070061static struct regulator *tapan_codec_find_regulator(
62 struct snd_soc_codec *codec,
63 const char *name);
64
Bhalchandra Gajareea898742013-03-05 18:15:53 -080065static atomic_t kp_tapan_priv;
66static int spkr_drv_wrnd_param_set(const char *val,
67 const struct kernel_param *kp);
68static int spkr_drv_wrnd = 1;
69
70static struct kernel_param_ops spkr_drv_wrnd_param_ops = {
71 .set = spkr_drv_wrnd_param_set,
72 .get = param_get_int,
73};
74module_param_cb(spkr_drv_wrnd, &spkr_drv_wrnd_param_ops, &spkr_drv_wrnd, 0644);
75MODULE_PARM_DESC(spkr_drv_wrnd,
76 "Run software workaround to avoid leakage on the speaker drive");
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -080077
78#define WCD9306_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
79 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
80 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
81
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -070082#define WCD9302_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
83 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000)
84
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -080085#define NUM_DECIMATORS 4
86#define NUM_INTERPOLATORS 4
87#define BITS_PER_REG 8
Bhalchandra Gajareea898742013-03-05 18:15:53 -080088/* This actual number of TX ports supported in slimbus slave */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -080089#define TAPAN_TX_PORT_NUMBER 16
Kuirong Wang80aca0d2013-05-09 14:51:09 -070090#define TAPAN_RX_PORT_START_NUMBER 16
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -080091
Bhalchandra Gajareea898742013-03-05 18:15:53 -080092/* Nummer of TX ports actually connected from Slimbus slave to codec Digital */
93#define TAPAN_SLIM_CODEC_TX_PORTS 5
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -080094
Bhalchandra Gajareea898742013-03-05 18:15:53 -080095#define TAPAN_I2S_MASTER_MODE_MASK 0x08
96#define TAPAN_MCLK_CLK_12P288MHZ 12288000
Phani Kumar Uppalapati43bc4152013-05-24 00:44:20 -070097#define TAPAN_MCLK_CLK_9P6MHZ 9600000
Bhalchandra Gajareea898742013-03-05 18:15:53 -080098
99#define TAPAN_SLIM_CLOSE_TIMEOUT 1000
100#define TAPAN_SLIM_IRQ_OVERFLOW (1 << 0)
101#define TAPAN_SLIM_IRQ_UNDERFLOW (1 << 1)
102#define TAPAN_SLIM_IRQ_PORT_CLOSED (1 << 2)
Simmi Pateriya95466b12013-05-09 20:08:46 +0530103
Phani Kumar Uppalapaticc3ec0c2013-09-06 18:04:03 -0700104enum tapan_codec_type {
105 WCD9306,
106 WCD9302,
107};
108
109static enum tapan_codec_type codec_ver;
110
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -0700111/*
112 * Multiplication factor to compute impedance on Tapan
113 * This is computed from (Vx / (m*Ical)) = (10mV/(180*30uA))
114 */
115#define TAPAN_ZDET_MUL_FACTOR 1852
116
Damir Didjustod6aea992013-09-03 21:18:59 -0700117static struct afe_param_cdc_reg_cfg audio_reg_cfg[] = {
118 {
119 CODEC_REG_CFG_MINOR_VER,
120 (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_TX_BASE),
121 SB_PGD_PORT_TX_WATERMARK_N, 0x1E, 8, 0x1
122 },
123 {
124 CODEC_REG_CFG_MINOR_VER,
125 (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_TX_BASE),
126 SB_PGD_PORT_TX_ENABLE_N, 0x1, 8, 0x1
127 },
128 {
129 CODEC_REG_CFG_MINOR_VER,
130 (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_RX_BASE),
131 SB_PGD_PORT_RX_WATERMARK_N, 0x1E, 8, 0x1
132 },
133 {
134 CODEC_REG_CFG_MINOR_VER,
135 (TAPAN_REGISTER_START_OFFSET + TAPAN_SB_PGD_PORT_RX_BASE),
136 SB_PGD_PORT_RX_ENABLE_N, 0x1, 8, 0x1
137 },
138 {
139 CODEC_REG_CFG_MINOR_VER,
140 (TAPAN_REGISTER_START_OFFSET + TAPAN_A_CDC_ANC1_IIR_B1_CTL),
141 AANC_FF_GAIN_ADAPTIVE, 0x4, 8, 0
142 },
143 {
144 CODEC_REG_CFG_MINOR_VER,
145 (TAPAN_REGISTER_START_OFFSET + TAPAN_A_CDC_ANC1_IIR_B1_CTL),
146 AANC_FFGAIN_ADAPTIVE_EN, 0x8, 8, 0
147 },
148 {
149 CODEC_REG_CFG_MINOR_VER,
150 (TAPAN_REGISTER_START_OFFSET + TAPAN_A_CDC_ANC1_GAIN_CTL),
151 AANC_GAIN_CONTROL, 0xFF, 8, 0
152 },
153};
154
155static struct afe_param_cdc_reg_cfg_data tapan_audio_reg_cfg = {
156 .num_registers = ARRAY_SIZE(audio_reg_cfg),
157 .reg_data = audio_reg_cfg,
158};
159
160static struct afe_param_id_cdc_aanc_version tapan_cdc_aanc_version = {
161 .cdc_aanc_minor_version = AFE_API_VERSION_CDC_AANC_VERSION,
162 .aanc_hw_version = AANC_HW_BLOCK_VERSION_2,
163};
164
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800165enum {
166 AIF1_PB = 0,
167 AIF1_CAP,
168 AIF2_PB,
169 AIF2_CAP,
170 AIF3_PB,
171 AIF3_CAP,
172 NUM_CODEC_DAIS,
173};
174
175enum {
176 RX_MIX1_INP_SEL_ZERO = 0,
177 RX_MIX1_INP_SEL_SRC1,
178 RX_MIX1_INP_SEL_SRC2,
179 RX_MIX1_INP_SEL_IIR1,
180 RX_MIX1_INP_SEL_IIR2,
181 RX_MIX1_INP_SEL_RX1,
182 RX_MIX1_INP_SEL_RX2,
183 RX_MIX1_INP_SEL_RX3,
184 RX_MIX1_INP_SEL_RX4,
185 RX_MIX1_INP_SEL_RX5,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800186 RX_MIX1_INP_SEL_AUXRX,
187};
188
189#define TAPAN_COMP_DIGITAL_GAIN_OFFSET 3
190
191static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
192static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
193static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
194static struct snd_soc_dai_driver tapan_dai[];
195static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0);
196
197/* Codec supports 2 IIR filters */
198enum {
199 IIR1 = 0,
200 IIR2,
201 IIR_MAX,
202};
203/* Codec supports 5 bands */
204enum {
205 BAND1 = 0,
206 BAND2,
207 BAND3,
208 BAND4,
209 BAND5,
210 BAND_MAX,
211};
212
213enum {
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800214 COMPANDER_0,
215 COMPANDER_1,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800216 COMPANDER_2,
217 COMPANDER_MAX,
218};
219
220enum {
221 COMPANDER_FS_8KHZ = 0,
222 COMPANDER_FS_16KHZ,
223 COMPANDER_FS_32KHZ,
224 COMPANDER_FS_48KHZ,
225 COMPANDER_FS_96KHZ,
226 COMPANDER_FS_192KHZ,
227 COMPANDER_FS_MAX,
228};
229
230struct comp_sample_dependent_params {
231 u32 peak_det_timeout;
232 u32 rms_meter_div_fact;
233 u32 rms_meter_resamp_fact;
234};
235
236struct hpf_work {
237 struct tapan_priv *tapan;
238 u32 decimator;
239 u8 tx_hpf_cut_of_freq;
240 struct delayed_work dwork;
241};
242
243static struct hpf_work tx_hpf_work[NUM_DECIMATORS];
244
245static const struct wcd9xxx_ch tapan_rx_chs[TAPAN_RX_MAX] = {
Kuirong Wang80aca0d2013-05-09 14:51:09 -0700246 WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER, 0),
247 WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 1, 1),
248 WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 2, 2),
249 WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 3, 3),
250 WCD9XXX_CH(TAPAN_RX_PORT_START_NUMBER + 4, 4),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800251};
252
253static const struct wcd9xxx_ch tapan_tx_chs[TAPAN_TX_MAX] = {
254 WCD9XXX_CH(0, 0),
255 WCD9XXX_CH(1, 1),
256 WCD9XXX_CH(2, 2),
257 WCD9XXX_CH(3, 3),
258 WCD9XXX_CH(4, 4),
259};
260
261static const u32 vport_check_table[NUM_CODEC_DAIS] = {
262 0, /* AIF1_PB */
263 (1 << AIF2_CAP) | (1 << AIF3_CAP), /* AIF1_CAP */
264 0, /* AIF2_PB */
265 (1 << AIF1_CAP) | (1 << AIF3_CAP), /* AIF2_CAP */
266 0, /* AIF2_PB */
267 (1 << AIF1_CAP) | (1 << AIF2_CAP), /* AIF2_CAP */
268};
269
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800270static const u32 vport_i2s_check_table[NUM_CODEC_DAIS] = {
271 0, /* AIF1_PB */
272 0, /* AIF1_CAP */
273};
274
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -0700275enum {
276 CP_REG_BUCK = 0,
277 CP_REG_BHELPER,
278 CP_REG_MAX,
279};
280
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800281struct tapan_priv {
282 struct snd_soc_codec *codec;
283 u32 adc_count;
284 u32 rx_bias_count;
285 s32 dmic_1_2_clk_cnt;
286 s32 dmic_3_4_clk_cnt;
287 s32 dmic_5_6_clk_cnt;
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -0700288 s32 ldo_h_users;
289 s32 micb_2_users;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800290
291 u32 anc_slot;
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -0700292 bool anc_func;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800293
294 /*track tapan interface type*/
295 u8 intf_type;
296
297 /* num of slim ports required */
298 struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS];
299
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800300 /*compander*/
301 int comp_enabled[COMPANDER_MAX];
302 u32 comp_fs[COMPANDER_MAX];
303
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800304 /* Maintain the status of AUX PGA */
305 int aux_pga_cnt;
306 u8 aux_l_gain;
307 u8 aux_r_gain;
308
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800309 bool spkr_pa_widget_on;
310
Damir Didjustod6aea992013-09-03 21:18:59 -0700311 struct afe_param_cdc_slimbus_slave_cfg slimbus_slave_cfg;
312
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800313 /* resmgr module */
314 struct wcd9xxx_resmgr resmgr;
315 /* mbhc module */
316 struct wcd9xxx_mbhc mbhc;
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800317
318 /* class h specific data */
319 struct wcd9xxx_clsh_cdc_data clsh_d;
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -0700320
321 /* pointers to regulators required for chargepump */
322 struct regulator *cp_regulators[CP_REG_MAX];
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -0700323
324 /*
325 * list used to save/restore registers at start and
326 * end of impedance measurement
327 */
328 struct list_head reg_save_restore;
Damir Didjustod6aea992013-09-03 21:18:59 -0700329
330 int (*machine_codec_event_cb)(struct snd_soc_codec *codec,
331 enum wcd9xxx_codec_event);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800332};
333
334static const u32 comp_shift[] = {
335 0,
Banajit Goswamia7294452013-06-03 12:42:35 -0700336 1,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800337 2,
338};
339
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800340static const int comp_rx_path[] = {
341 COMPANDER_1,
342 COMPANDER_1,
343 COMPANDER_2,
344 COMPANDER_2,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800345 COMPANDER_MAX,
346};
347
348static const struct comp_sample_dependent_params comp_samp_params[] = {
349 {
350 /* 8 Khz */
Banajit Goswamia7294452013-06-03 12:42:35 -0700351 .peak_det_timeout = 0x06,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800352 .rms_meter_div_fact = 0x09,
353 .rms_meter_resamp_fact = 0x06,
354 },
355 {
356 /* 16 Khz */
Banajit Goswamia7294452013-06-03 12:42:35 -0700357 .peak_det_timeout = 0x07,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800358 .rms_meter_div_fact = 0x0A,
359 .rms_meter_resamp_fact = 0x0C,
360 },
361 {
362 /* 32 Khz */
Banajit Goswamia7294452013-06-03 12:42:35 -0700363 .peak_det_timeout = 0x08,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800364 .rms_meter_div_fact = 0x0B,
365 .rms_meter_resamp_fact = 0x1E,
366 },
367 {
368 /* 48 Khz */
Banajit Goswamia7294452013-06-03 12:42:35 -0700369 .peak_det_timeout = 0x09,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800370 .rms_meter_div_fact = 0x0B,
371 .rms_meter_resamp_fact = 0x28,
372 },
373 {
374 /* 96 Khz */
Banajit Goswamia7294452013-06-03 12:42:35 -0700375 .peak_det_timeout = 0x0A,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800376 .rms_meter_div_fact = 0x0C,
377 .rms_meter_resamp_fact = 0x50,
378 },
379 {
380 /* 192 Khz */
Banajit Goswamia7294452013-06-03 12:42:35 -0700381 .peak_det_timeout = 0x0B,
382 .rms_meter_div_fact = 0xC,
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800383 .rms_meter_resamp_fact = 0xA0,
384 },
385};
386
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800387static unsigned short rx_digital_gain_reg[] = {
388 TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL,
389 TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL,
390 TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL,
391 TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL,
392};
393
394static unsigned short tx_digital_gain_reg[] = {
395 TAPAN_A_CDC_TX1_VOL_CTL_GAIN,
396 TAPAN_A_CDC_TX2_VOL_CTL_GAIN,
397 TAPAN_A_CDC_TX3_VOL_CTL_GAIN,
398 TAPAN_A_CDC_TX4_VOL_CTL_GAIN,
399};
400
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800401static int spkr_drv_wrnd_param_set(const char *val,
402 const struct kernel_param *kp)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800403{
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800404 struct snd_soc_codec *codec;
405 int ret, old;
406 struct tapan_priv *priv;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800407
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800408 priv = (struct tapan_priv *)atomic_read(&kp_tapan_priv);
409 if (!priv) {
410 pr_debug("%s: codec isn't yet registered\n", __func__);
411 return 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800412 }
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800413
Joonwoo Park973fd352013-06-19 11:38:53 -0700414 codec = priv->codec;
415 mutex_lock(&codec->mutex);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800416 old = spkr_drv_wrnd;
417 ret = param_set_int(val, kp);
418 if (ret) {
Joonwoo Park973fd352013-06-19 11:38:53 -0700419 mutex_unlock(&codec->mutex);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800420 return ret;
421 }
422
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800423 dev_dbg(codec->dev, "%s: spkr_drv_wrnd %d -> %d\n",
424 __func__, old, spkr_drv_wrnd);
Joonwoo Park973fd352013-06-19 11:38:53 -0700425 if ((old == -1 || old == 0) && spkr_drv_wrnd == 1) {
Joonwoo Park533b3682013-06-13 11:41:21 -0700426 WCD9XXX_BG_CLK_LOCK(&priv->resmgr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800427 wcd9xxx_resmgr_get_bandgap(&priv->resmgr,
428 WCD9XXX_BANDGAP_AUDIO_MODE);
Joonwoo Park533b3682013-06-13 11:41:21 -0700429 WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800430 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80);
431 } else if (old == 1 && spkr_drv_wrnd == 0) {
Joonwoo Park533b3682013-06-13 11:41:21 -0700432 WCD9XXX_BG_CLK_LOCK(&priv->resmgr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800433 wcd9xxx_resmgr_put_bandgap(&priv->resmgr,
434 WCD9XXX_BANDGAP_AUDIO_MODE);
Joonwoo Park533b3682013-06-13 11:41:21 -0700435 WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800436 if (!priv->spkr_pa_widget_on)
437 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80,
438 0x00);
439 }
Joonwoo Park973fd352013-06-19 11:38:53 -0700440 mutex_unlock(&codec->mutex);
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800441
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800442 return 0;
443}
444
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800445static int tapan_get_anc_slot(struct snd_kcontrol *kcontrol,
446 struct snd_ctl_elem_value *ucontrol)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800447{
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800448 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
449 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
450 ucontrol->value.integer.value[0] = tapan->anc_slot;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800451 return 0;
452}
453
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800454static int tapan_put_anc_slot(struct snd_kcontrol *kcontrol,
455 struct snd_ctl_elem_value *ucontrol)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800456{
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800457 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
458 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
459 tapan->anc_slot = ucontrol->value.integer.value[0];
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800460 return 0;
461}
462
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -0700463static int tapan_get_anc_func(struct snd_kcontrol *kcontrol,
464 struct snd_ctl_elem_value *ucontrol)
465{
466 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
467 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
468
469 ucontrol->value.integer.value[0] = (tapan->anc_func == true ? 1 : 0);
470 return 0;
471}
472
473static int tapan_put_anc_func(struct snd_kcontrol *kcontrol,
474 struct snd_ctl_elem_value *ucontrol)
475{
476 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
477 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
478 struct snd_soc_dapm_context *dapm = &codec->dapm;
479
480 mutex_lock(&dapm->codec->mutex);
481 tapan->anc_func = (!ucontrol->value.integer.value[0] ? false : true);
482
483 dev_err(codec->dev, "%s: anc_func %x", __func__, tapan->anc_func);
484
485 if (tapan->anc_func == true) {
486 pr_info("enable anc virtual widgets");
487 snd_soc_dapm_enable_pin(dapm, "ANC HPHR");
488 snd_soc_dapm_enable_pin(dapm, "ANC HPHL");
489 snd_soc_dapm_enable_pin(dapm, "ANC HEADPHONE");
490 snd_soc_dapm_enable_pin(dapm, "ANC EAR PA");
491 snd_soc_dapm_enable_pin(dapm, "ANC EAR");
492 snd_soc_dapm_disable_pin(dapm, "HPHR");
493 snd_soc_dapm_disable_pin(dapm, "HPHL");
494 snd_soc_dapm_disable_pin(dapm, "HEADPHONE");
495 snd_soc_dapm_disable_pin(dapm, "EAR PA");
496 snd_soc_dapm_disable_pin(dapm, "EAR");
497 } else {
498 pr_info("disable anc virtual widgets");
499 snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
500 snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
501 snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE");
502 snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
503 snd_soc_dapm_disable_pin(dapm, "ANC EAR");
504 snd_soc_dapm_enable_pin(dapm, "HPHR");
505 snd_soc_dapm_enable_pin(dapm, "HPHL");
506 snd_soc_dapm_enable_pin(dapm, "HEADPHONE");
507 snd_soc_dapm_enable_pin(dapm, "EAR PA");
508 snd_soc_dapm_enable_pin(dapm, "EAR");
509 }
510 snd_soc_dapm_sync(dapm);
511 mutex_unlock(&dapm->codec->mutex);
512 return 0;
513}
514
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800515static int tapan_pa_gain_get(struct snd_kcontrol *kcontrol,
516 struct snd_ctl_elem_value *ucontrol)
517{
518 u8 ear_pa_gain;
Venkat Sudhir43efc0c2013-10-01 16:07:41 -0700519 int rc = 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800520 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
521
522 ear_pa_gain = snd_soc_read(codec, TAPAN_A_RX_EAR_GAIN);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800523 ear_pa_gain = ear_pa_gain >> 5;
524
Venkat Sudhir43efc0c2013-10-01 16:07:41 -0700525 switch (ear_pa_gain) {
526 case 0:
527 case 1:
528 case 2:
529 case 3:
530 case 4:
531 case 5:
532 ucontrol->value.integer.value[0] = ear_pa_gain;
533 break;
534 case 7:
535 ucontrol->value.integer.value[0] = (ear_pa_gain - 1);
536 break;
537 default:
538 rc = -EINVAL;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800539 pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n",
Venkat Sudhir43efc0c2013-10-01 16:07:41 -0700540 __func__, ear_pa_gain);
541 break;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800542 }
543
544 dev_dbg(codec->dev, "%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain);
545
Venkat Sudhir43efc0c2013-10-01 16:07:41 -0700546 return rc;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800547}
548
549static int tapan_pa_gain_put(struct snd_kcontrol *kcontrol,
550 struct snd_ctl_elem_value *ucontrol)
551{
552 u8 ear_pa_gain;
Venkat Sudhir43efc0c2013-10-01 16:07:41 -0700553 int rc = 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800554 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
555
556 dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
557 __func__, ucontrol->value.integer.value[0]);
558
559 switch (ucontrol->value.integer.value[0]) {
560 case 0:
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800561 case 1:
Venkat Sudhir43efc0c2013-10-01 16:07:41 -0700562 case 2:
563 case 3:
564 case 4:
565 case 5:
566 ear_pa_gain = ucontrol->value.integer.value[0];
567 break;
568 case 6:
569 ear_pa_gain = 0x07;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800570 break;
571 default:
Venkat Sudhir43efc0c2013-10-01 16:07:41 -0700572 rc = -EINVAL;
573 break;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800574 }
Venkat Sudhir43efc0c2013-10-01 16:07:41 -0700575 if (!rc)
576 snd_soc_update_bits(codec, TAPAN_A_RX_EAR_GAIN,
577 0xE0, ear_pa_gain << 5);
578 return rc;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800579}
580
581static int tapan_get_iir_enable_audio_mixer(
582 struct snd_kcontrol *kcontrol,
583 struct snd_ctl_elem_value *ucontrol)
584{
585 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
586 int iir_idx = ((struct soc_multi_mixer_control *)
587 kcontrol->private_value)->reg;
588 int band_idx = ((struct soc_multi_mixer_control *)
589 kcontrol->private_value)->shift;
590
591 ucontrol->value.integer.value[0] =
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700592 (snd_soc_read(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx)) &
593 (1 << band_idx)) != 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800594
595 dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
596 iir_idx, band_idx,
597 (uint32_t)ucontrol->value.integer.value[0]);
598 return 0;
599}
600
601static int tapan_put_iir_enable_audio_mixer(
602 struct snd_kcontrol *kcontrol,
603 struct snd_ctl_elem_value *ucontrol)
604{
605 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
606 int iir_idx = ((struct soc_multi_mixer_control *)
607 kcontrol->private_value)->reg;
608 int band_idx = ((struct soc_multi_mixer_control *)
609 kcontrol->private_value)->shift;
610 int value = ucontrol->value.integer.value[0];
611
612 /* Mask first 5 bits, 6-8 are reserved */
613 snd_soc_update_bits(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx),
614 (1 << band_idx), (value << band_idx));
615
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700616 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
617 iir_idx, band_idx,
618 ((snd_soc_read(codec, (TAPAN_A_CDC_IIR1_CTL + 16 * iir_idx)) &
619 (1 << band_idx)) != 0));
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800620 return 0;
621}
622static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
623 int iir_idx, int band_idx,
624 int coeff_idx)
625{
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700626 uint32_t value = 0;
627
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800628 /* Address does not automatically update if reading */
629 snd_soc_write(codec,
630 (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700631 ((band_idx * BAND_MAX + coeff_idx)
632 * sizeof(uint32_t)) & 0x7F);
633
634 value |= snd_soc_read(codec,
635 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx));
636
637 snd_soc_write(codec,
638 (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
639 ((band_idx * BAND_MAX + coeff_idx)
640 * sizeof(uint32_t) + 1) & 0x7F);
641
642 value |= (snd_soc_read(codec,
643 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 8);
644
645 snd_soc_write(codec,
646 (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
647 ((band_idx * BAND_MAX + coeff_idx)
648 * sizeof(uint32_t) + 2) & 0x7F);
649
650 value |= (snd_soc_read(codec,
651 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 16);
652
653 snd_soc_write(codec,
654 (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
655 ((band_idx * BAND_MAX + coeff_idx)
656 * sizeof(uint32_t) + 3) & 0x7F);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800657
658 /* Mask bits top 2 bits since they are reserved */
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700659 value |= ((snd_soc_read(codec,
660 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) & 0x3F) << 24);
661
662 return value;
663
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800664}
665
666static int tapan_get_iir_band_audio_mixer(
667 struct snd_kcontrol *kcontrol,
668 struct snd_ctl_elem_value *ucontrol)
669{
670 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
671 int iir_idx = ((struct soc_multi_mixer_control *)
672 kcontrol->private_value)->reg;
673 int band_idx = ((struct soc_multi_mixer_control *)
674 kcontrol->private_value)->shift;
675
676 ucontrol->value.integer.value[0] =
677 get_iir_band_coeff(codec, iir_idx, band_idx, 0);
678 ucontrol->value.integer.value[1] =
679 get_iir_band_coeff(codec, iir_idx, band_idx, 1);
680 ucontrol->value.integer.value[2] =
681 get_iir_band_coeff(codec, iir_idx, band_idx, 2);
682 ucontrol->value.integer.value[3] =
683 get_iir_band_coeff(codec, iir_idx, band_idx, 3);
684 ucontrol->value.integer.value[4] =
685 get_iir_band_coeff(codec, iir_idx, band_idx, 4);
686
687 dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
688 "%s: IIR #%d band #%d b1 = 0x%x\n"
689 "%s: IIR #%d band #%d b2 = 0x%x\n"
690 "%s: IIR #%d band #%d a1 = 0x%x\n"
691 "%s: IIR #%d band #%d a2 = 0x%x\n",
692 __func__, iir_idx, band_idx,
693 (uint32_t)ucontrol->value.integer.value[0],
694 __func__, iir_idx, band_idx,
695 (uint32_t)ucontrol->value.integer.value[1],
696 __func__, iir_idx, band_idx,
697 (uint32_t)ucontrol->value.integer.value[2],
698 __func__, iir_idx, band_idx,
699 (uint32_t)ucontrol->value.integer.value[3],
700 __func__, iir_idx, band_idx,
701 (uint32_t)ucontrol->value.integer.value[4]);
702 return 0;
703}
704
705static void set_iir_band_coeff(struct snd_soc_codec *codec,
706 int iir_idx, int band_idx,
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700707 uint32_t value)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800708{
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800709 snd_soc_write(codec,
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700710 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
711 (value & 0xFF));
712
713 snd_soc_write(codec,
714 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
715 (value >> 8) & 0xFF);
716
717 snd_soc_write(codec,
718 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
719 (value >> 16) & 0xFF);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800720
721 /* Mask top 2 bits, 7-8 are reserved */
722 snd_soc_write(codec,
723 (TAPAN_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
724 (value >> 24) & 0x3F);
725
726}
727
728static int tapan_put_iir_band_audio_mixer(
729 struct snd_kcontrol *kcontrol,
730 struct snd_ctl_elem_value *ucontrol)
731{
732 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
733 int iir_idx = ((struct soc_multi_mixer_control *)
734 kcontrol->private_value)->reg;
735 int band_idx = ((struct soc_multi_mixer_control *)
736 kcontrol->private_value)->shift;
737
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700738 /* Mask top bit it is reserved */
739 /* Updates addr automatically for each B2 write */
740 snd_soc_write(codec,
741 (TAPAN_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
742 (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
743
744 set_iir_band_coeff(codec, iir_idx, band_idx,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800745 ucontrol->value.integer.value[0]);
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700746 set_iir_band_coeff(codec, iir_idx, band_idx,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800747 ucontrol->value.integer.value[1]);
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700748 set_iir_band_coeff(codec, iir_idx, band_idx,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800749 ucontrol->value.integer.value[2]);
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700750 set_iir_band_coeff(codec, iir_idx, band_idx,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800751 ucontrol->value.integer.value[3]);
Phani Kumar Uppalapati4a7b76f2013-04-26 13:47:24 -0700752 set_iir_band_coeff(codec, iir_idx, band_idx,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -0800753 ucontrol->value.integer.value[4]);
754
755 dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
756 "%s: IIR #%d band #%d b1 = 0x%x\n"
757 "%s: IIR #%d band #%d b2 = 0x%x\n"
758 "%s: IIR #%d band #%d a1 = 0x%x\n"
759 "%s: IIR #%d band #%d a2 = 0x%x\n",
760 __func__, iir_idx, band_idx,
761 get_iir_band_coeff(codec, iir_idx, band_idx, 0),
762 __func__, iir_idx, band_idx,
763 get_iir_band_coeff(codec, iir_idx, band_idx, 1),
764 __func__, iir_idx, band_idx,
765 get_iir_band_coeff(codec, iir_idx, band_idx, 2),
766 __func__, iir_idx, band_idx,
767 get_iir_band_coeff(codec, iir_idx, band_idx, 3),
768 __func__, iir_idx, band_idx,
769 get_iir_band_coeff(codec, iir_idx, band_idx, 4));
770 return 0;
771}
772
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800773static int tapan_get_compander(struct snd_kcontrol *kcontrol,
774 struct snd_ctl_elem_value *ucontrol)
775{
776
777 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
778 int comp = ((struct soc_multi_mixer_control *)
779 kcontrol->private_value)->shift;
780 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
781
782 ucontrol->value.integer.value[0] = tapan->comp_enabled[comp];
783 return 0;
784}
785
786static int tapan_set_compander(struct snd_kcontrol *kcontrol,
787 struct snd_ctl_elem_value *ucontrol)
788{
789 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
790 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
791 int comp = ((struct soc_multi_mixer_control *)
792 kcontrol->private_value)->shift;
793 int value = ucontrol->value.integer.value[0];
794
795 dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n",
796 __func__, comp, tapan->comp_enabled[comp], value);
797 tapan->comp_enabled[comp] = value;
Banajit Goswamia7294452013-06-03 12:42:35 -0700798
799 if (comp == COMPANDER_1 &&
800 tapan->comp_enabled[comp] == 1) {
801 /* Wavegen to 5 msec */
802 snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_CTL, 0xDA);
803 snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_TIME, 0x15);
804 snd_soc_write(codec, TAPAN_A_RX_HPH_BIAS_WG_OCP, 0x2A);
805
806 /* Enable Chopper */
807 snd_soc_update_bits(codec,
808 TAPAN_A_RX_HPH_CHOP_CTL, 0x80, 0x80);
809
810 snd_soc_write(codec, TAPAN_A_NCP_DTEST, 0x20);
811 pr_debug("%s: Enabled Chopper and set wavegen to 5 msec\n",
812 __func__);
813 } else if (comp == COMPANDER_1 &&
814 tapan->comp_enabled[comp] == 0) {
815 /* Wavegen to 20 msec */
816 snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_CTL, 0xDB);
817 snd_soc_write(codec, TAPAN_A_RX_HPH_CNP_WG_TIME, 0x58);
818 snd_soc_write(codec, TAPAN_A_RX_HPH_BIAS_WG_OCP, 0x1A);
819
820 /* Disable CHOPPER block */
821 snd_soc_update_bits(codec,
822 TAPAN_A_RX_HPH_CHOP_CTL, 0x80, 0x00);
823
824 snd_soc_write(codec, TAPAN_A_NCP_DTEST, 0x10);
825 pr_debug("%s: Disabled Chopper and set wavegen to 20 msec\n",
826 __func__);
827 }
828
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800829 return 0;
830}
831
832static int tapan_config_gain_compander(struct snd_soc_codec *codec,
833 int comp, bool enable)
834{
835 int ret = 0;
836
837 switch (comp) {
838 case COMPANDER_0:
839 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_GAIN,
840 1 << 2, !enable << 2);
841 break;
842 case COMPANDER_1:
843 snd_soc_update_bits(codec, TAPAN_A_RX_HPH_L_GAIN,
844 1 << 5, !enable << 5);
845 snd_soc_update_bits(codec, TAPAN_A_RX_HPH_R_GAIN,
846 1 << 5, !enable << 5);
847 break;
848 case COMPANDER_2:
849 snd_soc_update_bits(codec, TAPAN_A_RX_LINE_1_GAIN,
850 1 << 5, !enable << 5);
851 snd_soc_update_bits(codec, TAPAN_A_RX_LINE_2_GAIN,
852 1 << 5, !enable << 5);
853 break;
854 default:
855 WARN_ON(1);
856 ret = -EINVAL;
857 }
858
859 return ret;
860}
861
862static void tapan_discharge_comp(struct snd_soc_codec *codec, int comp)
863{
Banajit Goswamia7294452013-06-03 12:42:35 -0700864 /* Level meter DIV Factor to 5*/
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800865 snd_soc_update_bits(codec, TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8), 0xF0,
Banajit Goswamia7294452013-06-03 12:42:35 -0700866 0x05 << 4);
867 /* RMS meter Sampling to 0x01 */
868 snd_soc_write(codec, TAPAN_A_CDC_COMP0_B3_CTL + (comp * 8), 0x01);
869
870 /* Worst case timeout for compander CnP sleep timeout */
871 usleep_range(3000, 3000);
872}
873
874static enum wcd9xxx_buck_volt tapan_codec_get_buck_mv(
875 struct snd_soc_codec *codec)
876{
877 int buck_volt = WCD9XXX_CDC_BUCK_UNSUPPORTED;
878 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
879 struct wcd9xxx_pdata *pdata = tapan->resmgr.pdata;
880 int i;
Bhalchandra Gajaref49df622013-08-30 12:42:38 -0700881 bool found_regulator = false;
Banajit Goswamia7294452013-06-03 12:42:35 -0700882
883 for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -0700884 if (pdata->regulator[i].name == NULL)
885 continue;
886
Banajit Goswamia7294452013-06-03 12:42:35 -0700887 if (!strncmp(pdata->regulator[i].name,
Bhalchandra Gajaref49df622013-08-30 12:42:38 -0700888 WCD9XXX_SUPPLY_BUCK_NAME,
889 sizeof(WCD9XXX_SUPPLY_BUCK_NAME))) {
890 found_regulator = true;
Banajit Goswamia7294452013-06-03 12:42:35 -0700891 if ((pdata->regulator[i].min_uV ==
Bhalchandra Gajaref49df622013-08-30 12:42:38 -0700892 WCD9XXX_CDC_BUCK_MV_1P8) ||
893 (pdata->regulator[i].min_uV ==
894 WCD9XXX_CDC_BUCK_MV_2P15))
Banajit Goswamia7294452013-06-03 12:42:35 -0700895 buck_volt = pdata->regulator[i].min_uV;
896 break;
897 }
898 }
Bhalchandra Gajaref49df622013-08-30 12:42:38 -0700899
900 if (!found_regulator)
901 dev_err(codec->dev,
902 "%s: Failed to find regulator for %s\n",
903 __func__, WCD9XXX_SUPPLY_BUCK_NAME);
904 else
905 dev_dbg(codec->dev,
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -0700906 "%s: S4 voltage requested is %d\n",
907 __func__, buck_volt);
Bhalchandra Gajaref49df622013-08-30 12:42:38 -0700908
Banajit Goswamia7294452013-06-03 12:42:35 -0700909 return buck_volt;
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800910}
911
912static int tapan_config_compander(struct snd_soc_dapm_widget *w,
913 struct snd_kcontrol *kcontrol, int event)
914{
Banajit Goswamia7294452013-06-03 12:42:35 -0700915 int mask, enable_mask;
916 u8 rdac5_mux;
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800917 struct snd_soc_codec *codec = w->codec;
918 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
919 const int comp = w->shift;
920 const u32 rate = tapan->comp_fs[comp];
921 const struct comp_sample_dependent_params *comp_params =
922 &comp_samp_params[rate];
Banajit Goswamia7294452013-06-03 12:42:35 -0700923 enum wcd9xxx_buck_volt buck_mv;
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800924
925 dev_dbg(codec->dev, "%s: %s event %d compander %d, enabled %d",
926 __func__, w->name, event, comp, tapan->comp_enabled[comp]);
927
928 if (!tapan->comp_enabled[comp])
929 return 0;
930
931 /* Compander 0 has single channel */
932 mask = (comp == COMPANDER_0 ? 0x01 : 0x03);
Banajit Goswamia7294452013-06-03 12:42:35 -0700933 buck_mv = tapan_codec_get_buck_mv(codec);
934
935 rdac5_mux = snd_soc_read(codec, TAPAN_A_CDC_CONN_MISC);
936 rdac5_mux = (rdac5_mux & 0x04) >> 2;
937
938 if (comp == COMPANDER_0) { /* SPK compander */
939 enable_mask = 0x02;
940 } else if (comp == COMPANDER_1) { /* HPH compander */
941 enable_mask = 0x03;
942 } else if (comp == COMPANDER_2) { /* LO compander */
943
944 if (rdac5_mux == 0) { /* DEM4 */
945
946 /* for LO Stereo SE, enable Compander 2 left
947 * channel on RX3 interpolator Path and Compander 2
948 * rigt channel on RX4 interpolator Path.
949 */
950 enable_mask = 0x03;
951 } else if (rdac5_mux == 1) { /* DEM3_INV */
952
953 /* for LO mono differential only enable Compander 2
954 * left channel on RX3 interpolator Path.
955 */
956 enable_mask = 0x02;
957 } else {
958 dev_err(codec->dev, "%s: invalid rdac5_mux val %d",
959 __func__, rdac5_mux);
960 return -EINVAL;
961 }
962 } else {
963 dev_err(codec->dev, "%s: invalid compander %d", __func__, comp);
964 return -EINVAL;
965 }
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800966
967 switch (event) {
968 case SND_SOC_DAPM_PRE_PMU:
Banajit Goswamia7294452013-06-03 12:42:35 -0700969 /* Set compander Sample rate */
970 snd_soc_update_bits(codec,
971 TAPAN_A_CDC_COMP0_FS_CFG + (comp * 8),
972 0x07, rate);
973 /* Set the static gain offset for HPH Path */
974 if (comp == COMPANDER_1) {
975 if (buck_mv == WCD9XXX_CDC_BUCK_MV_2P15)
976 snd_soc_update_bits(codec,
977 TAPAN_A_CDC_COMP0_B4_CTL + (comp * 8),
978 0x80, 0x00);
979 else
980 snd_soc_update_bits(codec,
981 TAPAN_A_CDC_COMP0_B4_CTL + (comp * 8),
982 0x80, 0x80);
983 }
984 /* Enable RX interpolation path compander clocks */
985 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_B2_CTL,
986 0x01 << comp_shift[comp],
987 0x01 << comp_shift[comp]);
988
989 /* Toggle compander reset bits */
990 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL,
991 0x01 << comp_shift[comp],
992 0x01 << comp_shift[comp]);
993 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL,
994 0x01 << comp_shift[comp], 0);
995
Bhalchandra Gajareea898742013-03-05 18:15:53 -0800996 /* Set gain source to compander */
997 tapan_config_gain_compander(codec, comp, true);
Banajit Goswamia7294452013-06-03 12:42:35 -0700998
999 /* Compander enable */
1000 snd_soc_update_bits(codec, TAPAN_A_CDC_COMP0_B1_CTL +
1001 (comp * 8), enable_mask, enable_mask);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001002
1003 tapan_discharge_comp(codec, comp);
1004
Banajit Goswamia7294452013-06-03 12:42:35 -07001005 /* Set sample rate dependent paramater */
1006 snd_soc_write(codec, TAPAN_A_CDC_COMP0_B3_CTL + (comp * 8),
1007 comp_params->rms_meter_resamp_fact);
1008 snd_soc_update_bits(codec,
1009 TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8),
1010 0xF0, comp_params->rms_meter_div_fact << 4);
1011 snd_soc_update_bits(codec,
1012 TAPAN_A_CDC_COMP0_B2_CTL + (comp * 8),
1013 0x0F, comp_params->peak_det_timeout);
1014 break;
1015 case SND_SOC_DAPM_PRE_PMD:
1016 /* Disable compander */
1017 snd_soc_update_bits(codec,
1018 TAPAN_A_CDC_COMP0_B1_CTL + (comp * 8),
1019 enable_mask, 0x00);
1020
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001021 /* Toggle compander reset bits */
1022 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL,
1023 mask << comp_shift[comp],
1024 mask << comp_shift[comp]);
1025 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_OTHR_RESET_B2_CTL,
1026 mask << comp_shift[comp], 0);
Banajit Goswamia7294452013-06-03 12:42:35 -07001027
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001028 /* Turn off the clock for compander in pair */
1029 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_B2_CTL,
1030 mask << comp_shift[comp], 0);
Banajit Goswamia7294452013-06-03 12:42:35 -07001031
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001032 /* Set gain source to register */
1033 tapan_config_gain_compander(codec, comp, false);
1034 break;
1035 }
1036 return 0;
1037}
1038
Venkat Sudhir43efc0c2013-10-01 16:07:41 -07001039static const char * const tapan_ear_pa_gain_text[] = {"POS_6_DB", "POS_4P5_DB",
1040 "POS_3_DB", "POS_1P5_DB",
1041 "POS_0_DB", "NEG_2P5_DB",
1042 "NEG_12_DB"};
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001043static const struct soc_enum tapan_ear_pa_gain_enum[] = {
Venkat Sudhir43efc0c2013-10-01 16:07:41 -07001044 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tapan_ear_pa_gain_text),
1045 tapan_ear_pa_gain_text),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001046};
1047
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07001048static const char *const tapan_anc_func_text[] = {"OFF", "ON"};
1049static const struct soc_enum tapan_anc_func_enum =
1050 SOC_ENUM_SINGLE_EXT(2, tapan_anc_func_text);
1051
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001052/*cut of frequency for high pass filter*/
1053static const char * const cf_text[] = {
1054 "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz"
1055};
1056
1057static const struct soc_enum cf_dec1_enum =
1058 SOC_ENUM_SINGLE(TAPAN_A_CDC_TX1_MUX_CTL, 4, 3, cf_text);
1059
1060static const struct soc_enum cf_dec2_enum =
1061 SOC_ENUM_SINGLE(TAPAN_A_CDC_TX2_MUX_CTL, 4, 3, cf_text);
1062
1063static const struct soc_enum cf_dec3_enum =
1064 SOC_ENUM_SINGLE(TAPAN_A_CDC_TX3_MUX_CTL, 4, 3, cf_text);
1065
1066static const struct soc_enum cf_dec4_enum =
1067 SOC_ENUM_SINGLE(TAPAN_A_CDC_TX4_MUX_CTL, 4, 3, cf_text);
1068
1069static const struct soc_enum cf_rxmix1_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001070 SOC_ENUM_SINGLE(TAPAN_A_CDC_RX1_B4_CTL, 0, 3, cf_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001071
1072static const struct soc_enum cf_rxmix2_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001073 SOC_ENUM_SINGLE(TAPAN_A_CDC_RX2_B4_CTL, 0, 3, cf_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001074
1075static const struct soc_enum cf_rxmix3_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001076 SOC_ENUM_SINGLE(TAPAN_A_CDC_RX3_B4_CTL, 0, 3, cf_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001077
1078static const struct soc_enum cf_rxmix4_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001079 SOC_ENUM_SINGLE(TAPAN_A_CDC_RX4_B4_CTL, 0, 3, cf_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001080
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001081static const char * const class_h_dsm_text[] = {
1082 "ZERO", "RX_HPHL", "RX_SPKR"
1083};
1084
1085static const struct soc_enum class_h_dsm_enum =
1086 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_CLSH_CTL, 2, 3, class_h_dsm_text);
1087
1088static const struct snd_kcontrol_new class_h_dsm_mux =
1089 SOC_DAPM_ENUM("CLASS_H_DSM MUX Mux", class_h_dsm_enum);
1090
Phani Kumar Uppalapati5724aa22013-10-02 12:46:15 -07001091static int tapan_hph_impedance_get(struct snd_kcontrol *kcontrol,
1092 struct snd_ctl_elem_value *ucontrol)
1093{
1094 uint32_t zl, zr;
1095 bool hphr;
1096 struct soc_multi_mixer_control *mc;
1097 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1098 struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
1099
1100 mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
1101
1102 hphr = mc->shift;
1103 wcd9xxx_mbhc_get_impedance(&priv->mbhc, &zl, &zr);
1104 pr_debug("%s: zl %u, zr %u\n", __func__, zl, zr);
1105 ucontrol->value.integer.value[0] = hphr ? zr : zl;
1106
1107 return 0;
1108}
1109
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07001110static const struct snd_kcontrol_new tapan_common_snd_controls[] = {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001111
1112 SOC_ENUM_EXT("EAR PA Gain", tapan_ear_pa_gain_enum[0],
1113 tapan_pa_gain_get, tapan_pa_gain_put),
1114
Damir Didjustofc6016e2014-02-10 19:00:11 -08001115 SOC_SINGLE_TLV("HPHL Volume", TAPAN_A_RX_HPH_L_GAIN, 0, 20, 1,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001116 line_gain),
Damir Didjustofc6016e2014-02-10 19:00:11 -08001117 SOC_SINGLE_TLV("HPHR Volume", TAPAN_A_RX_HPH_R_GAIN, 0, 20, 1,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001118 line_gain),
1119
Damir Didjustofc6016e2014-02-10 19:00:11 -08001120 SOC_SINGLE_TLV("LINEOUT1 Volume", TAPAN_A_RX_LINE_1_GAIN, 0, 20, 1,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001121 line_gain),
Damir Didjustofc6016e2014-02-10 19:00:11 -08001122 SOC_SINGLE_TLV("LINEOUT2 Volume", TAPAN_A_RX_LINE_2_GAIN, 0, 20, 1,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001123 line_gain),
1124
Mohammad Johny Shaikabb80c62013-12-27 11:02:02 +05301125 SOC_SINGLE_TLV("SPK DRV Volume", TAPAN_A_SPKR_DRV_GAIN, 3, 8, 1,
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001126 line_gain),
1127
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07001128 SOC_SINGLE_TLV("ADC1 Volume", TAPAN_A_TX_1_EN, 2, 19, 0, analog_gain),
1129 SOC_SINGLE_TLV("ADC2 Volume", TAPAN_A_TX_2_EN, 2, 19, 0, analog_gain),
1130 SOC_SINGLE_TLV("ADC3 Volume", TAPAN_A_TX_3_EN, 2, 19, 0, analog_gain),
1131 SOC_SINGLE_TLV("ADC4 Volume", TAPAN_A_TX_4_EN, 2, 19, 0, analog_gain),
Jay Chokshi83b4f6132013-02-14 16:20:56 -08001132 SOC_SINGLE_S8_TLV("RX1 Digital Volume", TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL,
1133 -84, 40, digital_gain),
1134 SOC_SINGLE_S8_TLV("RX2 Digital Volume", TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL,
1135 -84, 40, digital_gain),
1136 SOC_SINGLE_S8_TLV("RX3 Digital Volume", TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL,
1137 -84, 40, digital_gain),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001138
Jay Chokshi83b4f6132013-02-14 16:20:56 -08001139 SOC_SINGLE_S8_TLV("DEC1 Volume", TAPAN_A_CDC_TX1_VOL_CTL_GAIN, -84, 40,
1140 digital_gain),
1141 SOC_SINGLE_S8_TLV("DEC2 Volume", TAPAN_A_CDC_TX2_VOL_CTL_GAIN, -84, 40,
1142 digital_gain),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001143
Jay Chokshi83b4f6132013-02-14 16:20:56 -08001144 SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TAPAN_A_CDC_IIR1_GAIN_B1_CTL, -84,
1145 40, digital_gain),
1146 SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TAPAN_A_CDC_IIR1_GAIN_B2_CTL, -84,
1147 40, digital_gain),
1148 SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TAPAN_A_CDC_IIR1_GAIN_B3_CTL, -84,
1149 40, digital_gain),
1150 SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TAPAN_A_CDC_IIR1_GAIN_B4_CTL, -84,
1151 40, digital_gain),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001152
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001153 SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
1154 SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
1155 SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
1156 SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
1157
1158 SOC_SINGLE("TX1 HPF Switch", TAPAN_A_CDC_TX1_MUX_CTL, 3, 1, 0),
1159 SOC_SINGLE("TX2 HPF Switch", TAPAN_A_CDC_TX2_MUX_CTL, 3, 1, 0),
1160 SOC_SINGLE("TX3 HPF Switch", TAPAN_A_CDC_TX3_MUX_CTL, 3, 1, 0),
1161 SOC_SINGLE("TX4 HPF Switch", TAPAN_A_CDC_TX4_MUX_CTL, 3, 1, 0),
1162
1163 SOC_SINGLE("RX1 HPF Switch", TAPAN_A_CDC_RX1_B5_CTL, 2, 1, 0),
1164 SOC_SINGLE("RX2 HPF Switch", TAPAN_A_CDC_RX2_B5_CTL, 2, 1, 0),
1165 SOC_SINGLE("RX3 HPF Switch", TAPAN_A_CDC_RX3_B5_CTL, 2, 1, 0),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001166
1167 SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum),
1168 SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum),
1169 SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001170
1171 SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
1172 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1173 SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
1174 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1175 SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
1176 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1177 SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
1178 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1179 SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
1180 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1181 SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0,
1182 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1183 SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0,
1184 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1185 SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0,
1186 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1187 SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0,
1188 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1189 SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0,
1190 tapan_get_iir_enable_audio_mixer, tapan_put_iir_enable_audio_mixer),
1191
1192 SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
1193 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1194 SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
1195 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1196 SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
1197 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1198 SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
1199 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1200 SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
1201 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1202 SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5,
1203 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1204 SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5,
1205 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1206 SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5,
1207 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1208 SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5,
1209 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
1210 SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5,
1211 tapan_get_iir_band_audio_mixer, tapan_put_iir_band_audio_mixer),
Phani Kumar Uppalapati5724aa22013-10-02 12:46:15 -07001212
1213 SOC_SINGLE_EXT("HPHL Impedance", 0, 0, UINT_MAX, 0,
1214 tapan_hph_impedance_get, NULL),
1215 SOC_SINGLE_EXT("HPHR Impedance", 0, 1, UINT_MAX, 0,
1216 tapan_hph_impedance_get, NULL),
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07001217};
1218
1219static const struct snd_kcontrol_new tapan_9306_snd_controls[] = {
1220 SOC_SINGLE_TLV("ADC5 Volume", TAPAN_A_TX_5_EN, 2, 19, 0, analog_gain),
1221
1222 SOC_SINGLE_S8_TLV("RX4 Digital Volume", TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL,
1223 -84, 40, digital_gain),
1224 SOC_SINGLE_S8_TLV("DEC3 Volume", TAPAN_A_CDC_TX3_VOL_CTL_GAIN, -84, 40,
1225 digital_gain),
1226 SOC_SINGLE_S8_TLV("DEC4 Volume", TAPAN_A_CDC_TX4_VOL_CTL_GAIN, -84, 40,
1227 digital_gain),
1228 SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 100, 0, tapan_get_anc_slot,
1229 tapan_put_anc_slot),
1230 SOC_ENUM_EXT("ANC Function", tapan_anc_func_enum, tapan_get_anc_func,
1231 tapan_put_anc_func),
1232 SOC_SINGLE("RX4 HPF Switch", TAPAN_A_CDC_RX4_B5_CTL, 2, 1, 0),
1233 SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001234
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001235 SOC_SINGLE_EXT("COMP0 Switch", SND_SOC_NOPM, COMPANDER_0, 1, 0,
1236 tapan_get_compander, tapan_set_compander),
1237 SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, COMPANDER_1, 1, 0,
1238 tapan_get_compander, tapan_set_compander),
1239 SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, COMPANDER_2, 1, 0,
1240 tapan_get_compander, tapan_set_compander),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001241};
1242
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001243static const char * const rx_1_2_mix1_text[] = {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001244 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001245 "RX5", "AUXRX", "AUXTX1"
1246};
1247
1248static const char * const rx_3_4_mix1_text[] = {
1249 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
1250 "RX5", "AUXRX", "AUXTX1", "AUXTX2"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001251};
1252
1253static const char * const rx_mix2_text[] = {
1254 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2"
1255};
1256
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07001257static const char * const rx_rdac3_text[] = {
1258 "DEM1", "DEM2"
1259};
1260
1261static const char * const rx_rdac4_text[] = {
1262 "DEM3", "DEM2"
1263};
1264
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001265static const char * const rx_rdac5_text[] = {
1266 "DEM4", "DEM3_INV"
1267};
1268
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001269static const char * const sb_tx_1_2_mux_text[] = {
1270 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4",
1271 "RSVD", "RSVD", "RSVD",
1272 "DEC1", "DEC2", "DEC3", "DEC4"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001273};
1274
1275static const char * const sb_tx3_mux_text[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001276 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4",
1277 "RSVD", "RSVD", "RSVD", "RSVD", "RSVD",
1278 "DEC3"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001279};
1280
1281static const char * const sb_tx4_mux_text[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001282 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4",
1283 "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", "RSVD",
1284 "DEC4"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001285};
1286
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001287static const char * const sb_tx5_mux_text[] = {
1288 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4",
1289 "RSVD", "RSVD", "RSVD",
1290 "DEC1"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001291};
1292
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001293static const char * const dec_1_2_mux_text[] = {
1294 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADCMB",
1295 "DMIC1", "DMIC2", "DMIC3", "DMIC4"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001296};
1297
1298static const char * const dec3_mux_text[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001299 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADCMB",
1300 "DMIC1", "DMIC2", "DMIC3", "DMIC4",
1301 "ANCFBTUNE1"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001302};
1303
1304static const char * const dec4_mux_text[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001305 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADCMB",
1306 "DMIC1", "DMIC2", "DMIC3", "DMIC4",
1307 "ANCFBTUNE2"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001308};
1309
1310static const char * const anc_mux_text[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001311 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5",
1312 "RSVD", "RSVD", "RSVD",
1313 "DMIC1", "DMIC2", "DMIC3", "DMIC4",
1314 "RSVD", "RSVD"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001315};
1316
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07001317static const char * const anc1_fb_mux_text[] = {
1318 "ZERO", "EAR_HPH_L", "EAR_LINE_1",
1319};
1320
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001321static const char * const iir1_inp1_text[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001322 "ZERO", "DEC1", "DEC2", "DEC3", "DEC4",
1323 "RX1", "RX2", "RX3", "RX4", "RX5"
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001324};
1325
1326static const struct soc_enum rx_mix1_inp1_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001327 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_1_2_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001328
1329static const struct soc_enum rx_mix1_inp2_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001330 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_1_2_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001331
1332static const struct soc_enum rx_mix1_inp3_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001333 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B2_CTL, 0, 12, rx_1_2_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001334
1335static const struct soc_enum rx2_mix1_inp1_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001336 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_1_2_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001337
1338static const struct soc_enum rx2_mix1_inp2_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001339 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_1_2_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001340
1341static const struct soc_enum rx3_mix1_inp1_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001342 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX3_B1_CTL, 0, 13, rx_3_4_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001343
1344static const struct soc_enum rx3_mix1_inp2_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001345 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX3_B1_CTL, 4, 13, rx_3_4_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001346
1347static const struct soc_enum rx4_mix1_inp1_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001348 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B1_CTL, 0, 13, rx_3_4_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001349
1350static const struct soc_enum rx4_mix1_inp2_chain_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001351 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B1_CTL, 4, 13, rx_3_4_mix1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001352
Santosh Mardi330ad2a2013-11-21 18:12:14 +05301353static const struct soc_enum rx4_mix1_inp3_chain_enum =
1354 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B2_CTL, 0, 13, rx_3_4_mix1_text);
1355
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001356static const struct soc_enum rx1_mix2_inp1_chain_enum =
1357 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text);
1358
1359static const struct soc_enum rx1_mix2_inp2_chain_enum =
1360 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text);
1361
1362static const struct soc_enum rx2_mix2_inp1_chain_enum =
1363 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text);
1364
1365static const struct soc_enum rx2_mix2_inp2_chain_enum =
1366 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text);
1367
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001368static const struct soc_enum rx4_mix2_inp1_chain_enum =
1369 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B3_CTL, 0, 5, rx_mix2_text);
1370
1371static const struct soc_enum rx4_mix2_inp2_chain_enum =
1372 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX4_B3_CTL, 3, 5, rx_mix2_text);
1373
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07001374static const struct soc_enum rx_rdac3_enum =
1375 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_RX2_B2_CTL, 4, 2, rx_rdac3_text);
1376
1377static const struct soc_enum rx_rdac4_enum =
1378 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_MISC, 1, 2, rx_rdac4_text);
1379
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001380static const struct soc_enum rx_rdac5_enum =
1381 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_MISC, 2, 2, rx_rdac5_text);
1382
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001383static const struct soc_enum sb_tx1_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001384 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B1_CTL, 0, 12,
1385 sb_tx_1_2_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001386
1387static const struct soc_enum sb_tx2_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001388 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B2_CTL, 0, 12,
1389 sb_tx_1_2_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001390
1391static const struct soc_enum sb_tx3_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001392 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B3_CTL, 0, 11, sb_tx3_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001393
1394static const struct soc_enum sb_tx4_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001395 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B4_CTL, 0, 12, sb_tx4_mux_text);
1396
1397static const struct soc_enum sb_tx5_mux_enum =
1398 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001399
1400static const struct soc_enum dec1_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001401 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B1_CTL, 0, 10, dec_1_2_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001402
1403static const struct soc_enum dec2_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001404 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B1_CTL, 4, 10, dec_1_2_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001405
1406static const struct soc_enum dec3_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001407 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B2_CTL, 0, 12, dec3_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001408
1409static const struct soc_enum dec4_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001410 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_TX_B2_CTL, 4, 12, dec4_mux_text);
1411
1412static const struct soc_enum anc1_mux_enum =
1413 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B1_CTL, 0, 15, anc_mux_text);
1414
1415static const struct soc_enum anc2_mux_enum =
1416 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B1_CTL, 4, 15, anc_mux_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001417
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07001418static const struct soc_enum anc1_fb_mux_enum =
1419 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text);
1420
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001421static const struct soc_enum iir1_inp1_mux_enum =
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001422 SOC_ENUM_SINGLE(TAPAN_A_CDC_CONN_EQ1_B1_CTL, 0, 10, iir1_inp1_text);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001423
1424static const struct snd_kcontrol_new rx_mix1_inp1_mux =
1425 SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum);
1426
1427static const struct snd_kcontrol_new rx_mix1_inp2_mux =
1428 SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum);
1429
1430static const struct snd_kcontrol_new rx_mix1_inp3_mux =
1431 SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum);
1432
1433static const struct snd_kcontrol_new rx2_mix1_inp1_mux =
1434 SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum);
1435
1436static const struct snd_kcontrol_new rx2_mix1_inp2_mux =
1437 SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum);
1438
1439static const struct snd_kcontrol_new rx3_mix1_inp1_mux =
1440 SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum);
1441
1442static const struct snd_kcontrol_new rx3_mix1_inp2_mux =
1443 SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum);
1444
1445static const struct snd_kcontrol_new rx4_mix1_inp1_mux =
1446 SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum);
1447
1448static const struct snd_kcontrol_new rx4_mix1_inp2_mux =
1449 SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum);
1450
Santosh Mardi330ad2a2013-11-21 18:12:14 +05301451static const struct snd_kcontrol_new rx4_mix1_inp3_mux =
1452 SOC_DAPM_ENUM("RX4 MIX1 INP3 Mux", rx4_mix1_inp3_chain_enum);
1453
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001454static const struct snd_kcontrol_new rx1_mix2_inp1_mux =
1455 SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum);
1456
1457static const struct snd_kcontrol_new rx1_mix2_inp2_mux =
1458 SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum);
1459
1460static const struct snd_kcontrol_new rx2_mix2_inp1_mux =
1461 SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum);
1462
1463static const struct snd_kcontrol_new rx2_mix2_inp2_mux =
1464 SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum);
1465
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001466static const struct snd_kcontrol_new rx4_mix2_inp1_mux =
1467 SOC_DAPM_ENUM("RX4 MIX2 INP1 Mux", rx4_mix2_inp1_chain_enum);
1468
1469static const struct snd_kcontrol_new rx4_mix2_inp2_mux =
1470 SOC_DAPM_ENUM("RX4 MIX2 INP2 Mux", rx4_mix2_inp2_chain_enum);
1471
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07001472static const struct snd_kcontrol_new rx_dac3_mux =
1473 SOC_DAPM_ENUM("RDAC3 MUX Mux", rx_rdac3_enum);
1474
1475static const struct snd_kcontrol_new rx_dac4_mux =
1476 SOC_DAPM_ENUM("RDAC4 MUX Mux", rx_rdac4_enum);
1477
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001478static const struct snd_kcontrol_new rx_dac5_mux =
1479 SOC_DAPM_ENUM("RDAC5 MUX Mux", rx_rdac5_enum);
1480
1481static const struct snd_kcontrol_new sb_tx1_mux =
1482 SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum);
1483
1484static const struct snd_kcontrol_new sb_tx2_mux =
1485 SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum);
1486
1487static const struct snd_kcontrol_new sb_tx3_mux =
1488 SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum);
1489
1490static const struct snd_kcontrol_new sb_tx4_mux =
1491 SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum);
1492
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001493static const struct snd_kcontrol_new sb_tx5_mux =
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001494 SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001495
1496static int wcd9306_put_dec_enum(struct snd_kcontrol *kcontrol,
1497 struct snd_ctl_elem_value *ucontrol)
1498{
1499 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1500 struct snd_soc_dapm_widget *w = wlist->widgets[0];
1501 struct snd_soc_codec *codec = w->codec;
1502 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1503 unsigned int dec_mux, decimator;
1504 char *dec_name = NULL;
1505 char *widget_name = NULL;
1506 char *temp;
1507 u16 tx_mux_ctl_reg;
1508 u8 adc_dmic_sel = 0x0;
1509 int ret = 0;
1510
1511 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1512 return -EINVAL;
1513
1514 dec_mux = ucontrol->value.enumerated.item[0];
1515
1516 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
1517 if (!widget_name)
1518 return -ENOMEM;
1519 temp = widget_name;
1520
1521 dec_name = strsep(&widget_name, " ");
1522 widget_name = temp;
1523 if (!dec_name) {
1524 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
1525 ret = -EINVAL;
1526 goto out;
1527 }
1528
1529 ret = kstrtouint(strpbrk(dec_name, "1234"), 10, &decimator);
1530 if (ret < 0) {
1531 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
1532 ret = -EINVAL;
1533 goto out;
1534 }
1535
1536 dev_dbg(w->dapm->dev, "%s(): widget = %s decimator = %u dec_mux = %u\n"
1537 , __func__, w->name, decimator, dec_mux);
1538
1539 switch (decimator) {
1540 case 1:
1541 case 2:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001542 if ((dec_mux >= 1) && (dec_mux <= 5))
1543 adc_dmic_sel = 0x0;
1544 else if ((dec_mux >= 6) && (dec_mux <= 9))
1545 adc_dmic_sel = 0x1;
1546 break;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001547 case 3:
1548 case 4:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001549 if ((dec_mux >= 1) && (dec_mux <= 6))
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001550 adc_dmic_sel = 0x0;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001551 else if ((dec_mux >= 7) && (dec_mux <= 10))
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001552 adc_dmic_sel = 0x1;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001553 break;
1554 default:
1555 pr_err("%s: Invalid Decimator = %u\n", __func__, decimator);
1556 ret = -EINVAL;
1557 goto out;
1558 }
1559
1560 tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
1561
1562 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel);
1563
1564 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1565
1566out:
1567 kfree(widget_name);
1568 return ret;
1569}
1570
1571#define WCD9306_DEC_ENUM(xname, xenum) \
1572{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1573 .info = snd_soc_info_enum_double, \
1574 .get = snd_soc_dapm_get_enum_double, \
1575 .put = wcd9306_put_dec_enum, \
1576 .private_value = (unsigned long)&xenum }
1577
1578static const struct snd_kcontrol_new dec1_mux =
1579 WCD9306_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum);
1580
1581static const struct snd_kcontrol_new dec2_mux =
1582 WCD9306_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum);
1583
1584static const struct snd_kcontrol_new dec3_mux =
1585 WCD9306_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum);
1586
1587static const struct snd_kcontrol_new dec4_mux =
1588 WCD9306_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum);
1589
1590static const struct snd_kcontrol_new iir1_inp1_mux =
1591 SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum);
1592
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001593static const struct snd_kcontrol_new anc1_mux =
1594 SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum);
1595
1596static const struct snd_kcontrol_new anc2_mux =
1597 SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum);
1598
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07001599static const struct snd_kcontrol_new anc1_fb_mux =
1600 SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum);
1601
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001602static const struct snd_kcontrol_new dac1_switch[] = {
1603 SOC_DAPM_SINGLE("Switch", TAPAN_A_RX_EAR_EN, 5, 1, 0)
1604};
1605static const struct snd_kcontrol_new hphl_switch[] = {
1606 SOC_DAPM_SINGLE("Switch", TAPAN_A_RX_HPH_L_DAC_CTL, 6, 1, 0)
1607};
1608
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001609static const struct snd_kcontrol_new spk_dac_switch[] = {
1610 SOC_DAPM_SINGLE("Switch", TAPAN_A_SPKR_DRV_DAC_CTL, 2, 1, 0)
1611};
1612
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001613static const struct snd_kcontrol_new hphl_pa_mix[] = {
1614 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
1615 7, 1, 0),
1616};
1617
1618static const struct snd_kcontrol_new hphr_pa_mix[] = {
1619 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
1620 6, 1, 0),
1621};
1622
1623static const struct snd_kcontrol_new ear_pa_mix[] = {
1624 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
1625 5, 1, 0),
1626};
1627static const struct snd_kcontrol_new lineout1_pa_mix[] = {
1628 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
1629 4, 1, 0),
1630};
1631
1632static const struct snd_kcontrol_new lineout2_pa_mix[] = {
1633 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TAPAN_A_RX_PA_AUX_IN_CONN,
1634 3, 1, 0),
1635};
1636
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001637
1638/* virtual port entries */
1639static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol,
1640 struct snd_ctl_elem_value *ucontrol)
1641{
1642 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1643 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1644
1645 ucontrol->value.integer.value[0] = widget->value;
1646 return 0;
1647}
1648
1649static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol,
1650 struct snd_ctl_elem_value *ucontrol)
1651{
1652 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1653 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1654 struct snd_soc_codec *codec = widget->codec;
1655 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
1656 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
1657 struct soc_multi_mixer_control *mixer =
1658 ((struct soc_multi_mixer_control *)kcontrol->private_value);
1659 u32 dai_id = widget->shift;
1660 u32 port_id = mixer->shift;
1661 u32 enable = ucontrol->value.integer.value[0];
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001662 u32 vtable = vport_check_table[dai_id];
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001663
1664 dev_dbg(codec->dev, "%s: wname %s cname %s\n",
1665 __func__, widget->name, ucontrol->id.name);
1666 dev_dbg(codec->dev, "%s: value %u shift %d item %ld\n",
1667 __func__, widget->value, widget->shift,
1668 ucontrol->value.integer.value[0]);
1669
1670 mutex_lock(&codec->mutex);
1671
1672 if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
1673 if (dai_id != AIF1_CAP) {
1674 dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
1675 __func__);
1676 mutex_unlock(&codec->mutex);
1677 return -EINVAL;
1678 }
1679 }
1680 switch (dai_id) {
1681 case AIF1_CAP:
1682 case AIF2_CAP:
1683 case AIF3_CAP:
1684 /* only add to the list if value not set
1685 */
1686 if (enable && !(widget->value & 1 << port_id)) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001687 if (tapan_p->intf_type ==
1688 WCD9XXX_INTERFACE_TYPE_SLIMBUS)
1689 vtable = vport_check_table[dai_id];
1690 if (tapan_p->intf_type ==
1691 WCD9XXX_INTERFACE_TYPE_I2C)
1692 vtable = vport_i2s_check_table[dai_id];
1693
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001694 if (wcd9xxx_tx_vport_validation(
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001695 vtable,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001696 port_id,
1697 tapan_p->dai)) {
1698 dev_dbg(codec->dev, "%s: TX%u is used by other virtual port\n",
1699 __func__, port_id + 1);
1700 mutex_unlock(&codec->mutex);
Kuirong Wang80aca0d2013-05-09 14:51:09 -07001701 return 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001702 }
1703 widget->value |= 1 << port_id;
1704 list_add_tail(&core->tx_chs[port_id].list,
1705 &tapan_p->dai[dai_id].wcd9xxx_ch_list
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001706 );
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001707 } else if (!enable && (widget->value & 1 << port_id)) {
1708 widget->value &= ~(1 << port_id);
1709 list_del_init(&core->tx_chs[port_id].list);
1710 } else {
1711 if (enable)
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001712 dev_dbg(codec->dev, "%s: TX%u port is used by\n"
1713 "this virtual port\n",
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001714 __func__, port_id + 1);
1715 else
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001716 dev_dbg(codec->dev, "%s: TX%u port is not used by\n"
1717 "this virtual port\n",
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001718 __func__, port_id + 1);
1719 /* avoid update power function */
1720 mutex_unlock(&codec->mutex);
1721 return 0;
1722 }
1723 break;
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07001724 default:
1725 dev_err(codec->dev, "Unknown AIF %d\n", dai_id);
1726 mutex_unlock(&codec->mutex);
1727 return -EINVAL;
1728 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001729 dev_dbg(codec->dev, "%s: name %s sname %s updated value %u shift %d\n",
1730 __func__, widget->name, widget->sname,
1731 widget->value, widget->shift);
1732
1733 snd_soc_dapm_mixer_update_power(widget, kcontrol, enable);
1734
1735 mutex_unlock(&codec->mutex);
1736 return 0;
1737}
1738
1739static int slim_rx_mux_get(struct snd_kcontrol *kcontrol,
1740 struct snd_ctl_elem_value *ucontrol)
1741{
1742 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1743 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1744
1745 ucontrol->value.enumerated.item[0] = widget->value;
1746 return 0;
1747}
1748
1749static const char *const slim_rx_mux_text[] = {
1750 "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB"
1751};
1752
1753static int slim_rx_mux_put(struct snd_kcontrol *kcontrol,
1754 struct snd_ctl_elem_value *ucontrol)
1755{
1756 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1757 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1758 struct snd_soc_codec *codec = widget->codec;
1759 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
1760 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
1761 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1762 u32 port_id = widget->shift;
1763
1764 dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n",
1765 __func__, widget->name, ucontrol->id.name, widget->value,
1766 widget->shift, ucontrol->value.integer.value[0]);
1767
1768 widget->value = ucontrol->value.enumerated.item[0];
1769
1770 mutex_lock(&codec->mutex);
1771
1772 if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
1773 if (widget->value > 1) {
1774 dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
1775 __func__);
1776 goto err;
1777 }
1778 }
1779 /* value need to match the Virtual port and AIF number
1780 */
1781 switch (widget->value) {
1782 case 0:
1783 list_del_init(&core->rx_chs[port_id].list);
1784 break;
1785 case 1:
Kuirong Wang80aca0d2013-05-09 14:51:09 -07001786 if (wcd9xxx_rx_vport_validation(port_id +
1787 TAPAN_RX_PORT_START_NUMBER,
1788 &tapan_p->dai[AIF1_PB].wcd9xxx_ch_list)) {
1789 dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
1790 __func__, port_id + 1);
1791 goto rtn;
1792 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001793 list_add_tail(&core->rx_chs[port_id].list,
1794 &tapan_p->dai[AIF1_PB].wcd9xxx_ch_list);
1795 break;
1796 case 2:
Kuirong Wang80aca0d2013-05-09 14:51:09 -07001797 if (wcd9xxx_rx_vport_validation(port_id +
1798 TAPAN_RX_PORT_START_NUMBER,
1799 &tapan_p->dai[AIF2_PB].wcd9xxx_ch_list)) {
1800 dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
1801 __func__, port_id + 1);
1802 goto rtn;
1803 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001804 list_add_tail(&core->rx_chs[port_id].list,
1805 &tapan_p->dai[AIF2_PB].wcd9xxx_ch_list);
1806 break;
1807 case 3:
Kuirong Wang80aca0d2013-05-09 14:51:09 -07001808 if (wcd9xxx_rx_vport_validation(port_id +
1809 TAPAN_RX_PORT_START_NUMBER,
1810 &tapan_p->dai[AIF3_PB].wcd9xxx_ch_list)) {
1811 dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n",
1812 __func__, port_id + 1);
1813 goto rtn;
1814 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001815 list_add_tail(&core->rx_chs[port_id].list,
1816 &tapan_p->dai[AIF3_PB].wcd9xxx_ch_list);
1817 break;
1818 default:
1819 pr_err("Unknown AIF %d\n", widget->value);
1820 goto err;
1821 }
1822
Kuirong Wang80aca0d2013-05-09 14:51:09 -07001823rtn:
Jay Chokshi83b4f6132013-02-14 16:20:56 -08001824 snd_soc_dapm_mux_update_power(widget, kcontrol, 1, widget->value, e);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001825 mutex_unlock(&codec->mutex);
1826 return 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001827err:
1828 mutex_unlock(&codec->mutex);
1829 return -EINVAL;
1830}
1831
1832static const struct soc_enum slim_rx_mux_enum =
1833 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text), slim_rx_mux_text);
1834
1835static const struct snd_kcontrol_new slim_rx_mux[TAPAN_RX_MAX] = {
1836 SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum,
1837 slim_rx_mux_get, slim_rx_mux_put),
1838 SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum,
1839 slim_rx_mux_get, slim_rx_mux_put),
1840 SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum,
1841 slim_rx_mux_get, slim_rx_mux_put),
1842 SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum,
1843 slim_rx_mux_get, slim_rx_mux_put),
1844 SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum,
1845 slim_rx_mux_get, slim_rx_mux_put),
1846};
1847
1848static const struct snd_kcontrol_new aif_cap_mixer[] = {
1849 SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, TAPAN_TX1, 1, 0,
1850 slim_tx_mixer_get, slim_tx_mixer_put),
1851 SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, TAPAN_TX2, 1, 0,
1852 slim_tx_mixer_get, slim_tx_mixer_put),
1853 SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, TAPAN_TX3, 1, 0,
1854 slim_tx_mixer_get, slim_tx_mixer_put),
1855 SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, TAPAN_TX4, 1, 0,
1856 slim_tx_mixer_get, slim_tx_mixer_put),
1857 SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, TAPAN_TX5, 1, 0,
1858 slim_tx_mixer_get, slim_tx_mixer_put),
1859};
1860
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001861static int tapan_codec_enable_adc(struct snd_soc_dapm_widget *w,
1862 struct snd_kcontrol *kcontrol, int event)
1863{
1864 struct snd_soc_codec *codec = w->codec;
Phani Kumar Uppalapati7c0bf702013-11-25 13:39:53 -08001865 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001866 u16 adc_reg;
1867 u8 init_bit_shift;
1868
1869 dev_dbg(codec->dev, "%s(): %s %d\n", __func__, w->name, event);
1870
1871 if (w->reg == TAPAN_A_TX_1_EN) {
1872 init_bit_shift = 7;
1873 adc_reg = TAPAN_A_TX_1_2_TEST_CTL;
1874 } else if (w->reg == TAPAN_A_TX_2_EN) {
1875 init_bit_shift = 6;
1876 adc_reg = TAPAN_A_TX_1_2_TEST_CTL;
1877 } else if (w->reg == TAPAN_A_TX_3_EN) {
1878 init_bit_shift = 6;
1879 adc_reg = TAPAN_A_TX_1_2_TEST_CTL;
1880 } else if (w->reg == TAPAN_A_TX_4_EN) {
1881 init_bit_shift = 7;
1882 adc_reg = TAPAN_A_TX_4_5_TEST_CTL;
1883 } else if (w->reg == TAPAN_A_TX_5_EN) {
1884 init_bit_shift = 6;
1885 adc_reg = TAPAN_A_TX_4_5_TEST_CTL;
1886 } else {
1887 pr_err("%s: Error, invalid adc register\n", __func__);
1888 return -EINVAL;
1889 }
1890
1891 switch (event) {
1892 case SND_SOC_DAPM_PRE_PMU:
Phani Kumar Uppalapati7e3f57d2013-12-12 12:26:59 -08001893 if (w->reg == TAPAN_A_TX_3_EN ||
1894 w->reg == TAPAN_A_TX_1_EN)
Phani Kumar Uppalapati7c0bf702013-11-25 13:39:53 -08001895 wcd9xxx_resmgr_notifier_call(&tapan->resmgr,
Phani Kumar Uppalapati7e3f57d2013-12-12 12:26:59 -08001896 WCD9XXX_EVENT_PRE_TX_1_3_ON);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001897 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift,
1898 1 << init_bit_shift);
1899 break;
1900 case SND_SOC_DAPM_POST_PMU:
1901
1902 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00);
1903
1904 break;
Phani Kumar Uppalapati7c0bf702013-11-25 13:39:53 -08001905 case SND_SOC_DAPM_POST_PMD:
Phani Kumar Uppalapati7e3f57d2013-12-12 12:26:59 -08001906 if (w->reg == TAPAN_A_TX_3_EN ||
1907 w->reg == TAPAN_A_TX_1_EN)
Phani Kumar Uppalapati7c0bf702013-11-25 13:39:53 -08001908 wcd9xxx_resmgr_notifier_call(&tapan->resmgr,
Phani Kumar Uppalapati7e3f57d2013-12-12 12:26:59 -08001909 WCD9XXX_EVENT_POST_TX_1_3_OFF);
Phani Kumar Uppalapati7c0bf702013-11-25 13:39:53 -08001910 break;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001911 }
1912 return 0;
1913}
1914
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001915static int tapan_codec_enable_aux_pga(struct snd_soc_dapm_widget *w,
1916 struct snd_kcontrol *kcontrol, int event)
1917{
1918 struct snd_soc_codec *codec = w->codec;
1919 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
1920
1921 dev_dbg(codec->dev, "%s: %d\n", __func__, event);
1922
1923 switch (event) {
1924 case SND_SOC_DAPM_PRE_PMU:
Joonwoo Park533b3682013-06-13 11:41:21 -07001925 WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001926 wcd9xxx_resmgr_get_bandgap(&tapan->resmgr,
1927 WCD9XXX_BANDGAP_AUDIO_MODE);
1928 /* AUX PGA requires RCO or MCLK */
1929 wcd9xxx_resmgr_get_clk_block(&tapan->resmgr, WCD9XXX_CLK_RCO);
Joonwoo Park533b3682013-06-13 11:41:21 -07001930 WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001931 wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 1);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001932 break;
1933
1934 case SND_SOC_DAPM_POST_PMD:
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001935 wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 0);
Joonwoo Park533b3682013-06-13 11:41:21 -07001936 WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001937 wcd9xxx_resmgr_put_bandgap(&tapan->resmgr,
1938 WCD9XXX_BANDGAP_AUDIO_MODE);
1939 wcd9xxx_resmgr_put_clk_block(&tapan->resmgr, WCD9XXX_CLK_RCO);
Joonwoo Park533b3682013-06-13 11:41:21 -07001940 WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001941 break;
1942 }
1943 return 0;
1944}
1945
1946static int tapan_codec_enable_lineout(struct snd_soc_dapm_widget *w,
1947 struct snd_kcontrol *kcontrol, int event)
1948{
1949 struct snd_soc_codec *codec = w->codec;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001950 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001951 u16 lineout_gain_reg;
1952
1953 dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
1954
1955 switch (w->shift) {
1956 case 0:
1957 lineout_gain_reg = TAPAN_A_RX_LINE_1_GAIN;
1958 break;
1959 case 1:
1960 lineout_gain_reg = TAPAN_A_RX_LINE_2_GAIN;
1961 break;
1962 default:
1963 pr_err("%s: Error, incorrect lineout register value\n",
1964 __func__);
1965 return -EINVAL;
1966 }
1967
1968 switch (event) {
1969 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001970 break;
1971 case SND_SOC_DAPM_POST_PMU:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001972 wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
1973 WCD9XXX_CLSH_STATE_LO,
1974 WCD9XXX_CLSH_REQ_ENABLE,
1975 WCD9XXX_CLSH_EVENT_POST_PA);
1976 dev_dbg(codec->dev, "%s: sleeping 3 ms after %s PA turn on\n",
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001977 __func__, w->name);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001978 usleep_range(3000, 3010);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001979 break;
1980 case SND_SOC_DAPM_POST_PMD:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001981 wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
1982 WCD9XXX_CLSH_STATE_LO,
1983 WCD9XXX_CLSH_REQ_DISABLE,
1984 WCD9XXX_CLSH_EVENT_POST_PA);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08001985 break;
1986 }
1987 return 0;
1988}
1989
1990static int tapan_codec_enable_spk_pa(struct snd_soc_dapm_widget *w,
1991 struct snd_kcontrol *kcontrol, int event)
1992{
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001993 struct snd_soc_codec *codec = w->codec;
1994 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
1995
1996 dev_dbg(codec->dev, "%s: %s %d\n", __func__, w->name, event);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08001997 switch (event) {
1998 case SND_SOC_DAPM_PRE_PMU:
1999 tapan->spkr_pa_widget_on = true;
2000 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80);
2001 break;
2002 case SND_SOC_DAPM_POST_PMD:
2003 tapan->spkr_pa_widget_on = false;
2004 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x00);
2005 break;
2006 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002007 return 0;
2008}
2009
2010static int tapan_codec_enable_dmic(struct snd_soc_dapm_widget *w,
2011 struct snd_kcontrol *kcontrol, int event)
2012{
2013 struct snd_soc_codec *codec = w->codec;
2014 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
2015 u8 dmic_clk_en;
2016 u16 dmic_clk_reg;
2017 s32 *dmic_clk_cnt;
2018 unsigned int dmic;
2019 int ret;
2020
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002021 ret = kstrtouint(strpbrk(w->name, "1234"), 10, &dmic);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002022 if (ret < 0) {
2023 pr_err("%s: Invalid DMIC line on the codec\n", __func__);
2024 return -EINVAL;
2025 }
2026
2027 switch (dmic) {
2028 case 1:
2029 case 2:
2030 dmic_clk_en = 0x01;
2031 dmic_clk_cnt = &(tapan->dmic_1_2_clk_cnt);
2032 dmic_clk_reg = TAPAN_A_CDC_CLK_DMIC_B1_CTL;
2033 dev_dbg(codec->dev, "%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n",
2034 __func__, event, dmic, *dmic_clk_cnt);
2035
2036 break;
2037
2038 case 3:
2039 case 4:
2040 dmic_clk_en = 0x10;
2041 dmic_clk_cnt = &(tapan->dmic_3_4_clk_cnt);
2042 dmic_clk_reg = TAPAN_A_CDC_CLK_DMIC_B1_CTL;
2043
2044 dev_dbg(codec->dev, "%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n",
2045 __func__, event, dmic, *dmic_clk_cnt);
2046 break;
2047
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002048 default:
2049 pr_err("%s: Invalid DMIC Selection\n", __func__);
2050 return -EINVAL;
2051 }
2052
2053 switch (event) {
2054 case SND_SOC_DAPM_PRE_PMU:
2055
2056 (*dmic_clk_cnt)++;
2057 if (*dmic_clk_cnt == 1)
2058 snd_soc_update_bits(codec, dmic_clk_reg,
2059 dmic_clk_en, dmic_clk_en);
2060
2061 break;
2062 case SND_SOC_DAPM_POST_PMD:
2063
2064 (*dmic_clk_cnt)--;
2065 if (*dmic_clk_cnt == 0)
2066 snd_soc_update_bits(codec, dmic_clk_reg,
2067 dmic_clk_en, 0);
2068 break;
2069 }
2070 return 0;
2071}
2072
2073static int tapan_codec_enable_anc(struct snd_soc_dapm_widget *w,
2074 struct snd_kcontrol *kcontrol, int event)
2075{
2076 struct snd_soc_codec *codec = w->codec;
2077 const char *filename;
2078 const struct firmware *fw;
2079 int i;
2080 int ret;
2081 int num_anc_slots;
Simmi Pateriyadf675e92013-04-05 01:15:54 +05302082 struct wcd9xxx_anc_header *anc_head;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002083 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
2084 u32 anc_writes_size = 0;
2085 int anc_size_remaining;
2086 u32 *anc_ptr;
2087 u16 reg;
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002088 u8 mask, val, old_val;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002089
2090 dev_dbg(codec->dev, "%s %d\n", __func__, event);
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002091 if (tapan->anc_func == 0)
2092 return 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002093 switch (event) {
2094 case SND_SOC_DAPM_PRE_PMU:
2095
2096 filename = "wcd9306/wcd9306_anc.bin";
2097
2098 ret = request_firmware(&fw, filename, codec->dev);
2099 if (ret != 0) {
2100 dev_err(codec->dev, "Failed to acquire ANC data: %d\n",
2101 ret);
2102 return -ENODEV;
2103 }
2104
Simmi Pateriyadf675e92013-04-05 01:15:54 +05302105 if (fw->size < sizeof(struct wcd9xxx_anc_header)) {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002106 dev_err(codec->dev, "Not enough data\n");
2107 release_firmware(fw);
2108 return -ENOMEM;
2109 }
2110
2111 /* First number is the number of register writes */
Simmi Pateriyadf675e92013-04-05 01:15:54 +05302112 anc_head = (struct wcd9xxx_anc_header *)(fw->data);
2113 anc_ptr = (u32 *)((u32)fw->data +
2114 sizeof(struct wcd9xxx_anc_header));
2115 anc_size_remaining = fw->size -
2116 sizeof(struct wcd9xxx_anc_header);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002117 num_anc_slots = anc_head->num_anc_slots;
2118
2119 if (tapan->anc_slot >= num_anc_slots) {
2120 dev_err(codec->dev, "Invalid ANC slot selected\n");
2121 release_firmware(fw);
2122 return -EINVAL;
2123 }
2124
2125 for (i = 0; i < num_anc_slots; i++) {
2126
2127 if (anc_size_remaining < TAPAN_PACKED_REG_SIZE) {
2128 dev_err(codec->dev, "Invalid register format\n");
2129 release_firmware(fw);
2130 return -EINVAL;
2131 }
2132 anc_writes_size = (u32)(*anc_ptr);
2133 anc_size_remaining -= sizeof(u32);
2134 anc_ptr += 1;
2135
2136 if (anc_writes_size * TAPAN_PACKED_REG_SIZE
2137 > anc_size_remaining) {
2138 dev_err(codec->dev, "Invalid register format\n");
2139 release_firmware(fw);
2140 return -ENOMEM;
2141 }
2142
2143 if (tapan->anc_slot == i)
2144 break;
2145
2146 anc_size_remaining -= (anc_writes_size *
2147 TAPAN_PACKED_REG_SIZE);
2148 anc_ptr += anc_writes_size;
2149 }
2150 if (i == num_anc_slots) {
2151 dev_err(codec->dev, "Selected ANC slot not present\n");
2152 release_firmware(fw);
2153 return -ENOMEM;
2154 }
2155
2156 for (i = 0; i < anc_writes_size; i++) {
2157 TAPAN_CODEC_UNPACK_ENTRY(anc_ptr[i], reg,
2158 mask, val);
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002159 old_val = snd_soc_read(codec, reg);
2160 snd_soc_write(codec, reg, (old_val & ~mask) |
2161 (val & mask));
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002162 }
2163 release_firmware(fw);
2164
2165 break;
Damir Didjusto1ede84a2013-05-23 16:38:11 -07002166 case SND_SOC_DAPM_PRE_PMD:
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002167 msleep(40);
2168 snd_soc_update_bits(codec, TAPAN_A_CDC_ANC1_B1_CTL, 0x01, 0x00);
2169 snd_soc_update_bits(codec, TAPAN_A_CDC_ANC2_B1_CTL, 0x02, 0x00);
2170 msleep(20);
2171 snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_RESET_CTL, 0x0F);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002172 snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_CLK_EN_CTL, 0);
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002173 snd_soc_write(codec, TAPAN_A_CDC_CLK_ANC_RESET_CTL, 0xFF);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002174 break;
2175 }
2176 return 0;
2177}
2178
2179static int tapan_codec_enable_micbias(struct snd_soc_dapm_widget *w,
2180 struct snd_kcontrol *kcontrol, int event)
2181{
2182 struct snd_soc_codec *codec = w->codec;
2183 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002184 u16 micb_int_reg = 0, micb_ctl_reg = 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002185 u8 cfilt_sel_val = 0;
2186 char *internal1_text = "Internal1";
2187 char *internal2_text = "Internal2";
2188 char *internal3_text = "Internal3";
2189 enum wcd9xxx_notify_event e_post_off, e_pre_on, e_post_on;
2190
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002191 pr_debug("%s: w->name %s event %d\n", __func__, w->name, event);
2192 if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1"))) {
2193 micb_ctl_reg = TAPAN_A_MICB_1_CTL;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002194 micb_int_reg = TAPAN_A_MICB_1_INT_RBIAS;
2195 cfilt_sel_val = tapan->resmgr.pdata->micbias.bias1_cfilt_sel;
2196 e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_1_ON;
2197 e_post_on = WCD9XXX_EVENT_POST_MICBIAS_1_ON;
2198 e_post_off = WCD9XXX_EVENT_POST_MICBIAS_1_OFF;
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002199 } else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2"))) {
2200 micb_ctl_reg = TAPAN_A_MICB_2_CTL;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002201 micb_int_reg = TAPAN_A_MICB_2_INT_RBIAS;
2202 cfilt_sel_val = tapan->resmgr.pdata->micbias.bias2_cfilt_sel;
2203 e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_2_ON;
2204 e_post_on = WCD9XXX_EVENT_POST_MICBIAS_2_ON;
2205 e_post_off = WCD9XXX_EVENT_POST_MICBIAS_2_OFF;
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002206 } else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3"))) {
2207 micb_ctl_reg = TAPAN_A_MICB_3_CTL;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002208 micb_int_reg = TAPAN_A_MICB_3_INT_RBIAS;
2209 cfilt_sel_val = tapan->resmgr.pdata->micbias.bias3_cfilt_sel;
2210 e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_3_ON;
2211 e_post_on = WCD9XXX_EVENT_POST_MICBIAS_3_ON;
2212 e_post_off = WCD9XXX_EVENT_POST_MICBIAS_3_OFF;
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002213 } else {
2214 pr_err("%s: Error, invalid micbias %s\n", __func__, w->name);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002215 return -EINVAL;
2216 }
2217
2218 switch (event) {
2219 case SND_SOC_DAPM_PRE_PMU:
2220 /* Let MBHC module know so micbias switch to be off */
2221 wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_pre_on);
2222
2223 /* Get cfilt */
2224 wcd9xxx_resmgr_cfilt_get(&tapan->resmgr, cfilt_sel_val);
2225
2226 if (strnstr(w->name, internal1_text, 30))
2227 snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0);
2228 else if (strnstr(w->name, internal2_text, 30))
2229 snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C);
2230 else if (strnstr(w->name, internal3_text, 30))
2231 snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3);
2232
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002233 if (micb_ctl_reg == TAPAN_A_MICB_2_CTL) {
2234 if (++tapan->micb_2_users == 1)
2235 wcd9xxx_resmgr_add_cond_update_bits(
2236 &tapan->resmgr,
2237 WCD9XXX_COND_HPH_MIC,
2238 micb_ctl_reg, w->shift,
2239 false);
2240 pr_debug("%s: micb_2_users %d\n", __func__,
2241 tapan->micb_2_users);
2242 } else
2243 snd_soc_update_bits(codec, micb_ctl_reg, 1 << w->shift,
2244 1 << w->shift);
2245
2246
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002247 break;
2248 case SND_SOC_DAPM_POST_PMU:
2249 usleep_range(20000, 20000);
2250 /* Let MBHC module know so micbias is on */
2251 wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_on);
2252 break;
2253 case SND_SOC_DAPM_POST_PMD:
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002254 if (micb_ctl_reg == TAPAN_A_MICB_2_CTL) {
2255 if (--tapan->micb_2_users == 0)
2256 wcd9xxx_resmgr_rm_cond_update_bits(
2257 &tapan->resmgr,
2258 WCD9XXX_COND_HPH_MIC,
2259 micb_ctl_reg, 7,
2260 false);
2261 pr_debug("%s: micb_2_users %d\n", __func__,
2262 tapan->micb_2_users);
2263 WARN(tapan->micb_2_users < 0,
2264 "Unexpected micbias users %d\n",
2265 tapan->micb_2_users);
2266 } else
2267 snd_soc_update_bits(codec, micb_ctl_reg, 1 << w->shift,
2268 0);
2269
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002270 /* Let MBHC module know so micbias switch to be off */
2271 wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_off);
2272
2273 if (strnstr(w->name, internal1_text, 30))
2274 snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00);
2275 else if (strnstr(w->name, internal2_text, 30))
2276 snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00);
2277 else if (strnstr(w->name, internal3_text, 30))
2278 snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0);
2279
2280 /* Put cfilt */
2281 wcd9xxx_resmgr_cfilt_put(&tapan->resmgr, cfilt_sel_val);
2282 break;
2283 }
2284
2285 return 0;
2286}
2287
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002288/* called under codec_resource_lock acquisition */
Phani Kumar Uppalapatib7266bd2013-10-21 14:26:10 -07002289static int tapan_enable_mbhc_micbias(struct snd_soc_codec *codec, bool enable,
2290 enum wcd9xxx_micbias_num micb_num)
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002291{
2292 int rc;
Phani Kumar Uppalapatib7266bd2013-10-21 14:26:10 -07002293 const char *micbias;
2294
2295 if (micb_num == MBHC_MICBIAS2)
2296 micbias = DAPM_MICBIAS2_EXTERNAL_STANDALONE;
2297 else
2298 return -EINVAL;
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002299
2300 if (enable)
2301 rc = snd_soc_dapm_force_enable_pin(&codec->dapm,
Phani Kumar Uppalapatib7266bd2013-10-21 14:26:10 -07002302 micbias);
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002303 else
2304 rc = snd_soc_dapm_disable_pin(&codec->dapm,
Phani Kumar Uppalapatib7266bd2013-10-21 14:26:10 -07002305 micbias);
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002306 if (!rc)
2307 snd_soc_dapm_sync(&codec->dapm);
2308 pr_debug("%s: leave ret %d\n", __func__, rc);
2309 return rc;
2310}
2311
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002312static void tx_hpf_corner_freq_callback(struct work_struct *work)
2313{
2314 struct delayed_work *hpf_delayed_work;
2315 struct hpf_work *hpf_work;
2316 struct tapan_priv *tapan;
2317 struct snd_soc_codec *codec;
2318 u16 tx_mux_ctl_reg;
2319 u8 hpf_cut_of_freq;
2320
2321 hpf_delayed_work = to_delayed_work(work);
2322 hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
2323 tapan = hpf_work->tapan;
2324 codec = hpf_work->tapan->codec;
2325 hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq;
2326
2327 tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL +
2328 (hpf_work->decimator - 1) * 8;
2329
2330 dev_dbg(codec->dev, "%s(): decimator %u hpf_cut_of_freq 0x%x\n",
2331 __func__, hpf_work->decimator, (unsigned int)hpf_cut_of_freq);
2332
2333 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4);
2334}
2335
2336#define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30
2337#define CF_MIN_3DB_4HZ 0x0
2338#define CF_MIN_3DB_75HZ 0x1
2339#define CF_MIN_3DB_150HZ 0x2
2340
2341static int tapan_codec_enable_dec(struct snd_soc_dapm_widget *w,
2342 struct snd_kcontrol *kcontrol, int event)
2343{
2344 struct snd_soc_codec *codec = w->codec;
2345 unsigned int decimator;
2346 char *dec_name = NULL;
2347 char *widget_name = NULL;
2348 char *temp;
2349 int ret = 0;
2350 u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg;
2351 u8 dec_hpf_cut_of_freq;
2352 int offset;
2353
2354 dev_dbg(codec->dev, "%s %d\n", __func__, event);
2355
2356 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
2357 if (!widget_name)
2358 return -ENOMEM;
2359 temp = widget_name;
2360
2361 dec_name = strsep(&widget_name, " ");
2362 widget_name = temp;
2363 if (!dec_name) {
2364 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
2365 ret = -EINVAL;
2366 goto out;
2367 }
2368
2369 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
2370 if (ret < 0) {
2371 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
2372 ret = -EINVAL;
2373 goto out;
2374 }
2375
2376 dev_dbg(codec->dev, "%s(): widget = %s dec_name = %s decimator = %u\n",
2377 __func__, w->name, dec_name, decimator);
2378
2379 if (w->reg == TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL) {
2380 dec_reset_reg = TAPAN_A_CDC_CLK_TX_RESET_B1_CTL;
2381 offset = 0;
2382 } else if (w->reg == TAPAN_A_CDC_CLK_TX_CLK_EN_B2_CTL) {
2383 dec_reset_reg = TAPAN_A_CDC_CLK_TX_RESET_B2_CTL;
2384 offset = 8;
2385 } else {
2386 pr_err("%s: Error, incorrect dec\n", __func__);
2387 ret = -EINVAL;
2388 goto out;
2389 }
2390
2391 tx_vol_ctl_reg = TAPAN_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator - 1);
2392 tx_mux_ctl_reg = TAPAN_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
2393
2394 switch (event) {
2395 case SND_SOC_DAPM_PRE_PMU:
2396
2397 /* Enableable TX digital mute */
2398 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
2399
2400 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift,
2401 1 << w->shift);
2402 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0);
2403
2404 dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg);
2405
2406 dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4;
2407
2408 tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq =
2409 dec_hpf_cut_of_freq;
2410
2411 if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) {
2412
2413 /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */
2414 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
2415 CF_MIN_3DB_150HZ << 4);
2416 }
2417
2418 /* enable HPF */
2419 snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00);
2420
2421 break;
2422
2423 case SND_SOC_DAPM_POST_PMU:
2424
2425 /* Disable TX digital mute */
2426 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00);
2427
2428 if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq !=
2429 CF_MIN_3DB_150HZ) {
2430
2431 schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork,
2432 msecs_to_jiffies(300));
2433 }
2434 /* apply the digital gain after the decimator is enabled*/
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002435 if ((w->shift + offset) < ARRAY_SIZE(tx_digital_gain_reg))
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002436 snd_soc_write(codec,
2437 tx_digital_gain_reg[w->shift + offset],
2438 snd_soc_read(codec,
2439 tx_digital_gain_reg[w->shift + offset])
2440 );
2441
2442 break;
2443
2444 case SND_SOC_DAPM_PRE_PMD:
2445
2446 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
2447 cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork);
2448 break;
2449
2450 case SND_SOC_DAPM_POST_PMD:
2451
2452 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08);
2453 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
2454 (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4);
2455
2456 break;
2457 }
2458out:
2459 kfree(widget_name);
2460 return ret;
2461}
2462
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002463static int tapan_codec_enable_vdd_spkr(struct snd_soc_dapm_widget *w,
2464 struct snd_kcontrol *kcontrol, int event)
2465{
2466 struct snd_soc_codec *codec = w->codec;
2467 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
2468
2469 dev_dbg(codec->dev, "%s: %s %d\n", __func__, w->name, event);
2470
2471 switch (event) {
2472 case SND_SOC_DAPM_PRE_PMU:
2473
2474 if (spkr_drv_wrnd > 0) {
2475 WARN_ON(!(snd_soc_read(codec, TAPAN_A_SPKR_DRV_EN) &
2476 0x80));
2477 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80,
2478 0x00);
2479 }
2480 if (TAPAN_IS_1_0(core->version))
2481 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_DBG_PWRSTG,
2482 0x24, 0x00);
2483 break;
2484 case SND_SOC_DAPM_POST_PMD:
2485 if (TAPAN_IS_1_0(core->version))
2486 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_DBG_PWRSTG,
2487 0x24, 0x24);
2488 if (spkr_drv_wrnd > 0) {
2489 WARN_ON(!!(snd_soc_read(codec, TAPAN_A_SPKR_DRV_EN) &
2490 0x80));
2491 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80,
2492 0x80);
2493 }
2494 break;
2495 }
2496 return 0;
2497}
2498
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002499static int tapan_codec_enable_interpolator(struct snd_soc_dapm_widget *w,
2500 struct snd_kcontrol *kcontrol, int event)
2501{
2502 struct snd_soc_codec *codec = w->codec;
2503
2504 dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
2505
2506 switch (event) {
2507 case SND_SOC_DAPM_PRE_PMU:
2508 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_RESET_CTL,
2509 1 << w->shift, 1 << w->shift);
2510 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RX_RESET_CTL,
2511 1 << w->shift, 0x0);
2512 break;
2513 case SND_SOC_DAPM_POST_PMU:
2514 /* apply the digital gain after the interpolator is enabled*/
2515 if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
2516 snd_soc_write(codec,
2517 rx_digital_gain_reg[w->shift],
2518 snd_soc_read(codec,
2519 rx_digital_gain_reg[w->shift])
2520 );
2521 break;
2522 }
2523 return 0;
2524}
2525
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002526/* called under codec_resource_lock acquisition */
2527static int __tapan_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
2528 struct snd_kcontrol *kcontrol, int event)
2529{
2530 struct snd_soc_codec *codec = w->codec;
2531 struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
2532
2533 pr_debug("%s: enter\n", __func__);
2534 switch (event) {
2535 case SND_SOC_DAPM_PRE_PMU:
2536 /*
2537 * ldo_h_users is protected by codec->mutex, don't need
2538 * additional mutex
2539 */
2540 if (++priv->ldo_h_users == 1) {
2541 WCD9XXX_BG_CLK_LOCK(&priv->resmgr);
2542 wcd9xxx_resmgr_get_bandgap(&priv->resmgr,
2543 WCD9XXX_BANDGAP_AUDIO_MODE);
2544 wcd9xxx_resmgr_get_clk_block(&priv->resmgr,
2545 WCD9XXX_CLK_RCO);
2546 snd_soc_update_bits(codec, TAPAN_A_LDO_H_MODE_1, 1 << 7,
2547 1 << 7);
2548 wcd9xxx_resmgr_put_clk_block(&priv->resmgr,
2549 WCD9XXX_CLK_RCO);
2550 WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr);
2551 pr_debug("%s: ldo_h_users %d\n", __func__,
2552 priv->ldo_h_users);
2553 /* LDO enable requires 1ms to settle down */
2554 usleep_range(1000, 1010);
2555 }
2556 break;
2557 case SND_SOC_DAPM_POST_PMD:
2558 if (--priv->ldo_h_users == 0) {
2559 WCD9XXX_BG_CLK_LOCK(&priv->resmgr);
2560 wcd9xxx_resmgr_get_clk_block(&priv->resmgr,
2561 WCD9XXX_CLK_RCO);
2562 snd_soc_update_bits(codec, TAPAN_A_LDO_H_MODE_1, 1 << 7,
2563 0);
2564 wcd9xxx_resmgr_put_clk_block(&priv->resmgr,
2565 WCD9XXX_CLK_RCO);
2566 wcd9xxx_resmgr_put_bandgap(&priv->resmgr,
2567 WCD9XXX_BANDGAP_AUDIO_MODE);
2568 WCD9XXX_BG_CLK_UNLOCK(&priv->resmgr);
2569 pr_debug("%s: ldo_h_users %d\n", __func__,
2570 priv->ldo_h_users);
2571 }
2572 WARN(priv->ldo_h_users < 0, "Unexpected ldo_h users %d\n",
2573 priv->ldo_h_users);
2574 break;
2575 }
2576 pr_debug("%s: leave\n", __func__);
2577 return 0;
2578}
2579
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002580static int tapan_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
2581 struct snd_kcontrol *kcontrol, int event)
2582{
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07002583 int rc;
2584 rc = __tapan_codec_enable_ldo_h(w, kcontrol, event);
2585 return rc;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002586}
2587
2588static int tapan_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
2589 struct snd_kcontrol *kcontrol, int event)
2590{
2591 struct snd_soc_codec *codec = w->codec;
2592 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
2593
2594 dev_dbg(codec->dev, "%s %d\n", __func__, event);
2595
2596 switch (event) {
2597 case SND_SOC_DAPM_PRE_PMU:
2598 wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 1);
2599 break;
2600 case SND_SOC_DAPM_POST_PMD:
2601 wcd9xxx_resmgr_enable_rx_bias(&tapan->resmgr, 0);
2602 break;
2603 }
2604 return 0;
2605}
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002606
2607
2608static int tapan_hphl_dac_event(struct snd_soc_dapm_widget *w,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002609 struct snd_kcontrol *kcontrol, int event)
2610{
2611 struct snd_soc_codec *codec = w->codec;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002612 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002613
2614 dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
2615
2616 switch (event) {
2617 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002618 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL,
2619 0x02, 0x02);
2620 wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
2621 WCD9XXX_CLSH_STATE_HPHL,
2622 WCD9XXX_CLSH_REQ_ENABLE,
2623 WCD9XXX_CLSH_EVENT_PRE_DAC);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002624 break;
2625 case SND_SOC_DAPM_POST_PMD:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002626 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL,
2627 0x02, 0x00);
2628 }
2629 return 0;
2630}
2631
2632static int tapan_hphr_dac_event(struct snd_soc_dapm_widget *w,
2633 struct snd_kcontrol *kcontrol, int event)
2634{
2635 struct snd_soc_codec *codec = w->codec;
2636 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
2637
2638 dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
2639
2640 switch (event) {
2641 case SND_SOC_DAPM_PRE_PMU:
2642 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL,
2643 0x04, 0x04);
2644 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
2645 wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
2646 WCD9XXX_CLSH_STATE_HPHR,
2647 WCD9XXX_CLSH_REQ_ENABLE,
2648 WCD9XXX_CLSH_EVENT_PRE_DAC);
2649 break;
2650 case SND_SOC_DAPM_POST_PMD:
2651 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL,
2652 0x04, 0x00);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002653 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
2654 break;
2655 }
2656 return 0;
2657}
2658
2659static int tapan_hph_pa_event(struct snd_soc_dapm_widget *w,
2660 struct snd_kcontrol *kcontrol, int event)
2661{
2662 struct snd_soc_codec *codec = w->codec;
2663 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
2664 enum wcd9xxx_notify_event e_pre_on, e_post_off;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002665 u8 req_clsh_state;
Banajit Goswamia7294452013-06-03 12:42:35 -07002666 u32 pa_settle_time = TAPAN_HPH_PA_SETTLE_COMP_OFF;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002667
2668 dev_dbg(codec->dev, "%s: %s event = %d\n", __func__, w->name, event);
2669 if (w->shift == 5) {
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002670 e_pre_on = WCD9XXX_EVENT_PRE_HPHL_PA_ON;
2671 e_post_off = WCD9XXX_EVENT_POST_HPHL_PA_OFF;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002672 req_clsh_state = WCD9XXX_CLSH_STATE_HPHR;
Phani Kumar Uppalapatieca9a102013-06-18 11:02:38 -07002673 } else if (w->shift == 4) {
2674 e_pre_on = WCD9XXX_EVENT_PRE_HPHR_PA_ON;
2675 e_post_off = WCD9XXX_EVENT_POST_HPHR_PA_OFF;
2676 req_clsh_state = WCD9XXX_CLSH_STATE_HPHL;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002677 } else {
2678 pr_err("%s: Invalid w->shift %d\n", __func__, w->shift);
2679 return -EINVAL;
2680 }
2681
Banajit Goswamia7294452013-06-03 12:42:35 -07002682 if (tapan->comp_enabled[COMPANDER_1])
2683 pa_settle_time = TAPAN_HPH_PA_SETTLE_COMP_ON;
2684
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002685 switch (event) {
2686 case SND_SOC_DAPM_PRE_PMU:
2687 /* Let MBHC module know PA is turning on */
2688 wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_pre_on);
2689 break;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002690 case SND_SOC_DAPM_POST_PMU:
Banajit Goswamia7294452013-06-03 12:42:35 -07002691 dev_dbg(codec->dev, "%s: sleep %d ms after %s PA enable.\n",
2692 __func__, pa_settle_time / 1000, w->name);
2693 /* Time needed for PA to settle */
2694 usleep_range(pa_settle_time, pa_settle_time + 1000);
2695
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002696 wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
2697 req_clsh_state,
2698 WCD9XXX_CLSH_REQ_ENABLE,
2699 WCD9XXX_CLSH_EVENT_POST_PA);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002700
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002701 break;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002702 case SND_SOC_DAPM_POST_PMD:
Banajit Goswamia7294452013-06-03 12:42:35 -07002703 dev_dbg(codec->dev, "%s: sleep %d ms after %s PA disable.\n",
2704 __func__, pa_settle_time / 1000, w->name);
2705 /* Time needed for PA to settle */
2706 usleep_range(pa_settle_time, pa_settle_time + 1000);
2707
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002708 /* Let MBHC module know PA turned off */
2709 wcd9xxx_resmgr_notifier_call(&tapan->resmgr, e_post_off);
2710
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002711 wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
2712 req_clsh_state,
2713 WCD9XXX_CLSH_REQ_DISABLE,
2714 WCD9XXX_CLSH_EVENT_POST_PA);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002715 break;
2716 }
2717 return 0;
2718}
2719
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002720static int tapan_codec_enable_anc_hph(struct snd_soc_dapm_widget *w,
2721 struct snd_kcontrol *kcontrol, int event)
2722{
2723 struct snd_soc_codec *codec = w->codec;
2724 int ret = 0;
2725
2726 switch (event) {
2727 case SND_SOC_DAPM_PRE_PMU:
2728 ret = tapan_hph_pa_event(w, kcontrol, event);
2729 if (w->shift == 4) {
2730 ret |= tapan_codec_enable_anc(w, kcontrol, event);
2731 msleep(50);
2732 }
2733 break;
2734 case SND_SOC_DAPM_POST_PMU:
2735 if (w->shift == 4) {
2736 snd_soc_update_bits(codec,
2737 TAPAN_A_RX_HPH_CNP_EN, 0x30, 0x30);
2738 msleep(30);
2739 }
2740 ret = tapan_hph_pa_event(w, kcontrol, event);
2741 break;
2742 case SND_SOC_DAPM_PRE_PMD:
2743 if (w->shift == 5) {
2744 snd_soc_update_bits(codec,
2745 TAPAN_A_RX_HPH_CNP_EN, 0x30, 0x00);
2746 msleep(40);
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002747 snd_soc_update_bits(codec,
2748 TAPAN_A_TX_7_MBHC_EN, 0x80, 00);
2749 ret |= tapan_codec_enable_anc(w, kcontrol, event);
2750 }
Damir Didjusto1ede84a2013-05-23 16:38:11 -07002751 break;
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002752 case SND_SOC_DAPM_POST_PMD:
2753 ret = tapan_hph_pa_event(w, kcontrol, event);
2754 break;
2755 }
2756 return ret;
2757}
2758
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002759static const struct snd_soc_dapm_widget tapan_dapm_i2s_widgets[] = {
2760 SND_SOC_DAPM_SUPPLY("I2S_CLK", TAPAN_A_CDC_CLK_I2S_CTL,
2761 4, 0, NULL, 0),
2762};
2763
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002764static int tapan_lineout_dac_event(struct snd_soc_dapm_widget *w,
2765 struct snd_kcontrol *kcontrol, int event)
2766{
2767 struct snd_soc_codec *codec = w->codec;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002768 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002769
2770 dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
2771
2772 switch (event) {
2773 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002774 wcd9xxx_clsh_fsm(codec, &tapan->clsh_d,
2775 WCD9XXX_CLSH_STATE_LO,
2776 WCD9XXX_CLSH_REQ_ENABLE,
2777 WCD9XXX_CLSH_EVENT_PRE_DAC);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002778 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
2779 break;
2780
2781 case SND_SOC_DAPM_POST_PMD:
2782 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
2783 break;
2784 }
2785 return 0;
2786}
2787
2788static int tapan_spk_dac_event(struct snd_soc_dapm_widget *w,
2789 struct snd_kcontrol *kcontrol, int event)
2790{
2791 struct snd_soc_codec *codec = w->codec;
2792
2793 dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
2794 return 0;
2795}
2796
2797static const struct snd_soc_dapm_route audio_i2s_map[] = {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002798 {"I2S_CLK", NULL, "CDC_CONN"},
2799 {"SLIM RX1", NULL, "I2S_CLK"},
2800 {"SLIM RX2", NULL, "I2S_CLK"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002801
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002802 {"SLIM TX1 MUX", NULL, "I2S_CLK"},
2803 {"SLIM TX2 MUX", NULL, "I2S_CLK"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002804};
2805
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07002806static const struct snd_soc_dapm_route wcd9306_map[] = {
2807 {"SLIM TX1 MUX", "RMIX4", "RX4 MIX1"},
2808 {"SLIM TX2 MUX", "RMIX4", "RX4 MIX1"},
2809 {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"},
2810 {"SLIM TX4 MUX", "RMIX4", "RX4 MIX1"},
2811 {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002812 {"SLIM TX1 MUX", "DEC3", "DEC3 MUX"},
2813 {"SLIM TX1 MUX", "DEC4", "DEC4 MUX"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002814 {"SLIM TX2 MUX", "DEC3", "DEC3 MUX"},
2815 {"SLIM TX2 MUX", "DEC4", "DEC4 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002816 {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002817 {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002818
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002819 {"ANC EAR", NULL, "ANC EAR PA"},
2820 {"ANC EAR PA", NULL, "EAR_PA_MIXER"},
2821 {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"},
2822 {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"},
2823
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07002824 {"ANC HEADPHONE", NULL, "ANC HPHL"},
2825 {"ANC HEADPHONE", NULL, "ANC HPHR"},
2826
2827 {"ANC HPHL", NULL, "HPHL_PA_MIXER"},
2828 {"ANC HPHR", NULL, "HPHR_PA_MIXER"},
2829
2830 {"ANC1 MUX", "ADC1", "ADC1"},
2831 {"ANC1 MUX", "ADC2", "ADC2"},
2832 {"ANC1 MUX", "ADC3", "ADC3"},
2833 {"ANC1 MUX", "ADC4", "ADC4"},
2834 {"ANC1 MUX", "ADC5", "ADC5"},
2835 {"ANC1 MUX", "DMIC1", "DMIC1"},
2836 {"ANC1 MUX", "DMIC2", "DMIC2"},
2837 {"ANC1 MUX", "DMIC3", "DMIC3"},
2838 {"ANC1 MUX", "DMIC4", "DMIC4"},
2839 {"ANC2 MUX", "ADC1", "ADC1"},
2840 {"ANC2 MUX", "ADC2", "ADC2"},
2841 {"ANC2 MUX", "ADC3", "ADC3"},
2842 {"ANC2 MUX", "ADC4", "ADC4"},
2843 {"ANC2 MUX", "ADC5", "ADC5"},
2844 {"ANC2 MUX", "DMIC1", "DMIC1"},
2845 {"ANC2 MUX", "DMIC2", "DMIC2"},
2846 {"ANC2 MUX", "DMIC3", "DMIC3"},
2847 {"ANC2 MUX", "DMIC4", "DMIC4"},
2848
2849 {"ANC HPHR", NULL, "CDC_CONN"},
2850
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07002851 {"RDAC5 MUX", "DEM4", "RX4 MIX2"},
2852 {"SPK DAC", "Switch", "RX4 MIX2"},
2853
2854 {"RX1 MIX2", NULL, "ANC1 MUX"},
2855 {"RX2 MIX2", NULL, "ANC2 MUX"},
2856
2857 {"RX1 MIX1", NULL, "COMP1_CLK"},
2858 {"RX2 MIX1", NULL, "COMP1_CLK"},
2859 {"RX3 MIX1", NULL, "COMP2_CLK"},
2860 {"RX4 MIX1", NULL, "COMP0_CLK"},
2861
2862 {"RX4 MIX1", NULL, "RX4 MIX1 INP1"},
2863 {"RX4 MIX1", NULL, "RX4 MIX1 INP2"},
2864 {"RX4 MIX2", NULL, "RX4 MIX1"},
2865 {"RX4 MIX2", NULL, "RX4 MIX2 INP1"},
2866 {"RX4 MIX2", NULL, "RX4 MIX2 INP2"},
2867
2868 {"RX4 MIX1 INP1", "RX1", "SLIM RX1"},
2869 {"RX4 MIX1 INP1", "RX2", "SLIM RX2"},
2870 {"RX4 MIX1 INP1", "RX3", "SLIM RX3"},
2871 {"RX4 MIX1 INP1", "RX4", "SLIM RX4"},
2872 {"RX4 MIX1 INP1", "RX5", "SLIM RX5"},
2873 {"RX4 MIX1 INP1", "IIR1", "IIR1"},
2874 {"RX4 MIX1 INP2", "RX1", "SLIM RX1"},
2875 {"RX4 MIX1 INP2", "RX2", "SLIM RX2"},
2876 {"RX4 MIX1 INP2", "RX3", "SLIM RX3"},
2877 {"RX4 MIX1 INP2", "RX5", "SLIM RX5"},
2878 {"RX4 MIX1 INP2", "RX4", "SLIM RX4"},
2879 {"RX4 MIX1 INP2", "IIR1", "IIR1"},
2880 {"RX4 MIX2 INP1", "IIR1", "IIR1"},
2881 {"RX4 MIX2 INP2", "IIR1", "IIR1"},
2882
2883 {"DEC1 MUX", "DMIC3", "DMIC3"},
2884 {"DEC1 MUX", "DMIC4", "DMIC4"},
2885 {"DEC2 MUX", "DMIC3", "DMIC3"},
2886 {"DEC2 MUX", "DMIC4", "DMIC4"},
2887
2888 {"DEC3 MUX", "ADC1", "ADC1"},
2889 {"DEC3 MUX", "ADC2", "ADC2"},
2890 {"DEC3 MUX", "ADC3", "ADC3"},
2891 {"DEC3 MUX", "ADC4", "ADC4"},
2892 {"DEC3 MUX", "ADC5", "ADC5"},
2893 {"DEC3 MUX", "DMIC1", "DMIC1"},
2894 {"DEC3 MUX", "DMIC2", "DMIC2"},
2895 {"DEC3 MUX", "DMIC3", "DMIC3"},
2896 {"DEC3 MUX", "DMIC4", "DMIC4"},
2897 {"DEC3 MUX", NULL, "CDC_CONN"},
2898
2899 {"DEC4 MUX", "ADC1", "ADC1"},
2900 {"DEC4 MUX", "ADC2", "ADC2"},
2901 {"DEC4 MUX", "ADC3", "ADC3"},
2902 {"DEC4 MUX", "ADC4", "ADC4"},
2903 {"DEC4 MUX", "ADC5", "ADC5"},
2904 {"DEC4 MUX", "DMIC1", "DMIC1"},
2905 {"DEC4 MUX", "DMIC2", "DMIC2"},
2906 {"DEC4 MUX", "DMIC3", "DMIC3"},
2907 {"DEC4 MUX", "DMIC4", "DMIC4"},
2908 {"DEC4 MUX", NULL, "CDC_CONN"},
2909
2910 {"ADC5", NULL, "AMIC5"},
2911
2912 {"AUX_PGA_Left", NULL, "AMIC5"},
2913
2914 {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"},
2915 {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"},
2916
2917 {"MIC BIAS3 Internal1", NULL, "LDO_H"},
2918 {"MIC BIAS3 Internal2", NULL, "LDO_H"},
2919 {"MIC BIAS3 External", NULL, "LDO_H"},
2920};
2921
2922static const struct snd_soc_dapm_route audio_map[] = {
2923 /* SLIMBUS Connections */
2924 {"AIF1 CAP", NULL, "AIF1_CAP Mixer"},
2925 {"AIF2 CAP", NULL, "AIF2_CAP Mixer"},
2926 {"AIF3 CAP", NULL, "AIF3_CAP Mixer"},
2927
2928 /* SLIM_MIXER("AIF1_CAP Mixer"),*/
2929 {"AIF1_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
2930 {"AIF1_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
2931 {"AIF1_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
2932 {"AIF1_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
2933 {"AIF1_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
2934 /* SLIM_MIXER("AIF2_CAP Mixer"),*/
2935 {"AIF2_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
2936 {"AIF2_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
2937 {"AIF2_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
2938 {"AIF2_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
2939 {"AIF2_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
2940 /* SLIM_MIXER("AIF3_CAP Mixer"),*/
2941 {"AIF3_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
2942 {"AIF3_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
2943 {"AIF3_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
2944 {"AIF3_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
2945 {"AIF3_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
2946
2947 {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"},
2948 {"SLIM TX1 MUX", "DEC2", "DEC2 MUX"},
2949 {"SLIM TX1 MUX", "RMIX1", "RX1 MIX1"},
2950 {"SLIM TX1 MUX", "RMIX2", "RX2 MIX1"},
2951 {"SLIM TX1 MUX", "RMIX3", "RX3 MIX1"},
2952
2953 {"SLIM TX2 MUX", "DEC1", "DEC1 MUX"},
2954 {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"},
2955 {"SLIM TX2 MUX", "RMIX1", "RX1 MIX1"},
2956 {"SLIM TX2 MUX", "RMIX2", "RX2 MIX1"},
2957 {"SLIM TX2 MUX", "RMIX3", "RX3 MIX1"},
2958
2959 {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"},
2960 {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"},
2961 {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"},
2962
2963 {"SLIM TX4 MUX", "RMIX1", "RX1 MIX1"},
2964 {"SLIM TX4 MUX", "RMIX2", "RX2 MIX1"},
2965 {"SLIM TX4 MUX", "RMIX3", "RX3 MIX1"},
2966
2967 {"SLIM TX5 MUX", "DEC1", "DEC1 MUX"},
2968 {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"},
2969 {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"},
2970 {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"},
2971
2972 /* Earpiece (RX MIX1) */
2973 {"EAR", NULL, "EAR PA"},
2974 {"EAR PA", NULL, "EAR_PA_MIXER"},
2975 {"EAR_PA_MIXER", NULL, "DAC1"},
2976 {"DAC1", NULL, "RX_BIAS"},
2977 {"DAC1", NULL, "CDC_CP_VDD"},
2978
2979
2980 /* Headset (RX MIX1 and RX MIX2) */
2981 {"HEADPHONE", NULL, "HPHL"},
2982 {"HEADPHONE", NULL, "HPHR"},
2983
2984 {"HPHL", NULL, "HPHL_PA_MIXER"},
2985 {"HPHL_PA_MIXER", NULL, "HPHL DAC"},
2986 {"HPHL DAC", NULL, "RX_BIAS"},
2987 {"HPHL DAC", NULL, "CDC_CP_VDD"},
2988
2989 {"HPHR", NULL, "HPHR_PA_MIXER"},
2990 {"HPHR_PA_MIXER", NULL, "HPHR DAC"},
2991 {"HPHR DAC", NULL, "RX_BIAS"},
2992 {"HPHR DAC", NULL, "CDC_CP_VDD"},
2993
2994
Bhalchandra Gajareea898742013-03-05 18:15:53 -08002995 {"DAC1", "Switch", "CLASS_H_DSM MUX"},
2996 {"HPHL DAC", "Switch", "CLASS_H_DSM MUX"},
Bhalchandra Gajare363f3f52013-10-08 18:43:22 -07002997 {"HPHR DAC", NULL, "RDAC3 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08002998
2999 {"LINEOUT1", NULL, "LINEOUT1 PA"},
3000 {"LINEOUT2", NULL, "LINEOUT2 PA"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003001 {"SPK_OUT", NULL, "SPK PA"},
3002
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003003 {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"},
3004 {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003005 {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"},
3006 {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"},
3007
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003008
3009 {"RDAC5 MUX", "DEM3_INV", "RX3 MIX1"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003010 {"LINEOUT2 DAC", NULL, "RDAC5 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003011
Bhalchandra Gajare363f3f52013-10-08 18:43:22 -07003012 {"RDAC4 MUX", "DEM3", "RX3 MIX1"},
3013 {"RDAC4 MUX", "DEM2", "RX2 CHAIN"},
3014 {"LINEOUT1 DAC", NULL, "RDAC4 MUX"},
3015
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003016 {"SPK PA", NULL, "SPK DAC"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003017 {"SPK DAC", NULL, "VDD_SPKDRV"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003018
3019 {"RX1 CHAIN", NULL, "RX1 MIX2"},
3020 {"RX2 CHAIN", NULL, "RX2 MIX2"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003021 {"CLASS_H_DSM MUX", "RX_HPHL", "RX1 CHAIN"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003022
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003023 {"LINEOUT1 DAC", NULL, "RX_BIAS"},
3024 {"LINEOUT2 DAC", NULL, "RX_BIAS"},
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07003025 {"LINEOUT1 DAC", NULL, "CDC_CP_VDD"},
3026 {"LINEOUT2 DAC", NULL, "CDC_CP_VDD"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003027
Bhalchandra Gajare363f3f52013-10-08 18:43:22 -07003028 {"RDAC3 MUX", "DEM2", "RX2 CHAIN"},
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07003029 {"RDAC3 MUX", "DEM1", "RX1 CHAIN"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003030
3031 {"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
3032 {"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
3033 {"RX1 MIX1", NULL, "RX1 MIX1 INP3"},
3034 {"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
3035 {"RX2 MIX1", NULL, "RX2 MIX1 INP2"},
3036 {"RX3 MIX1", NULL, "RX3 MIX1 INP1"},
3037 {"RX3 MIX1", NULL, "RX3 MIX1 INP2"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003038 {"RX1 MIX2", NULL, "RX1 MIX1"},
3039 {"RX1 MIX2", NULL, "RX1 MIX2 INP1"},
3040 {"RX1 MIX2", NULL, "RX1 MIX2 INP2"},
3041 {"RX2 MIX2", NULL, "RX2 MIX1"},
3042 {"RX2 MIX2", NULL, "RX2 MIX2 INP1"},
3043 {"RX2 MIX2", NULL, "RX2 MIX2 INP2"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003044
3045 /* SLIM_MUX("AIF1_PB", "AIF1 PB"),*/
3046 {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"},
3047 {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"},
3048 {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"},
3049 {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"},
3050 {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003051 /* SLIM_MUX("AIF2_PB", "AIF2 PB"),*/
3052 {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"},
3053 {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"},
3054 {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"},
3055 {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"},
3056 {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003057 /* SLIM_MUX("AIF3_PB", "AIF3 PB"),*/
3058 {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"},
3059 {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"},
3060 {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"},
3061 {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"},
3062 {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003063
3064 {"SLIM RX1", NULL, "SLIM RX1 MUX"},
3065 {"SLIM RX2", NULL, "SLIM RX2 MUX"},
3066 {"SLIM RX3", NULL, "SLIM RX3 MUX"},
3067 {"SLIM RX4", NULL, "SLIM RX4 MUX"},
3068 {"SLIM RX5", NULL, "SLIM RX5 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003069
3070 {"RX1 MIX1 INP1", "RX1", "SLIM RX1"},
3071 {"RX1 MIX1 INP1", "RX2", "SLIM RX2"},
3072 {"RX1 MIX1 INP1", "RX3", "SLIM RX3"},
3073 {"RX1 MIX1 INP1", "RX4", "SLIM RX4"},
3074 {"RX1 MIX1 INP1", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003075 {"RX1 MIX1 INP1", "IIR1", "IIR1"},
3076 {"RX1 MIX1 INP2", "RX1", "SLIM RX1"},
3077 {"RX1 MIX1 INP2", "RX2", "SLIM RX2"},
3078 {"RX1 MIX1 INP2", "RX3", "SLIM RX3"},
3079 {"RX1 MIX1 INP2", "RX4", "SLIM RX4"},
3080 {"RX1 MIX1 INP2", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003081 {"RX1 MIX1 INP2", "IIR1", "IIR1"},
3082 {"RX1 MIX1 INP3", "RX1", "SLIM RX1"},
3083 {"RX1 MIX1 INP3", "RX2", "SLIM RX2"},
3084 {"RX1 MIX1 INP3", "RX3", "SLIM RX3"},
3085 {"RX1 MIX1 INP3", "RX4", "SLIM RX4"},
3086 {"RX1 MIX1 INP3", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003087 {"RX2 MIX1 INP1", "RX1", "SLIM RX1"},
3088 {"RX2 MIX1 INP1", "RX2", "SLIM RX2"},
3089 {"RX2 MIX1 INP1", "RX3", "SLIM RX3"},
3090 {"RX2 MIX1 INP1", "RX4", "SLIM RX4"},
3091 {"RX2 MIX1 INP1", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003092 {"RX2 MIX1 INP1", "IIR1", "IIR1"},
3093 {"RX2 MIX1 INP2", "RX1", "SLIM RX1"},
3094 {"RX2 MIX1 INP2", "RX2", "SLIM RX2"},
3095 {"RX2 MIX1 INP2", "RX3", "SLIM RX3"},
3096 {"RX2 MIX1 INP2", "RX4", "SLIM RX4"},
3097 {"RX2 MIX1 INP2", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003098 {"RX2 MIX1 INP2", "IIR1", "IIR1"},
3099 {"RX3 MIX1 INP1", "RX1", "SLIM RX1"},
3100 {"RX3 MIX1 INP1", "RX2", "SLIM RX2"},
3101 {"RX3 MIX1 INP1", "RX3", "SLIM RX3"},
3102 {"RX3 MIX1 INP1", "RX4", "SLIM RX4"},
3103 {"RX3 MIX1 INP1", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003104 {"RX3 MIX1 INP1", "IIR1", "IIR1"},
3105 {"RX3 MIX1 INP2", "RX1", "SLIM RX1"},
3106 {"RX3 MIX1 INP2", "RX2", "SLIM RX2"},
3107 {"RX3 MIX1 INP2", "RX3", "SLIM RX3"},
3108 {"RX3 MIX1 INP2", "RX4", "SLIM RX4"},
3109 {"RX3 MIX1 INP2", "RX5", "SLIM RX5"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003110 {"RX3 MIX1 INP2", "IIR1", "IIR1"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003111
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003112 {"RX1 MIX2 INP1", "IIR1", "IIR1"},
3113 {"RX1 MIX2 INP2", "IIR1", "IIR1"},
3114 {"RX2 MIX2 INP1", "IIR1", "IIR1"},
3115 {"RX2 MIX2 INP2", "IIR1", "IIR1"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003116
3117 /* Decimator Inputs */
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003118 {"DEC1 MUX", "ADC1", "ADC1"},
3119 {"DEC1 MUX", "ADC2", "ADC2"},
3120 {"DEC1 MUX", "ADC3", "ADC3"},
3121 {"DEC1 MUX", "ADC4", "ADC4"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003122 {"DEC1 MUX", "DMIC1", "DMIC1"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003123 {"DEC1 MUX", "DMIC2", "DMIC2"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003124 {"DEC1 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003125
3126 {"DEC2 MUX", "ADC1", "ADC1"},
3127 {"DEC2 MUX", "ADC2", "ADC2"},
3128 {"DEC2 MUX", "ADC3", "ADC3"},
3129 {"DEC2 MUX", "ADC4", "ADC4"},
3130 {"DEC2 MUX", "DMIC1", "DMIC1"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003131 {"DEC2 MUX", "DMIC2", "DMIC2"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003132 {"DEC2 MUX", NULL, "CDC_CONN"},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003133
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003134 /* ADC Connections */
3135 {"ADC1", NULL, "AMIC1"},
3136 {"ADC2", NULL, "AMIC2"},
3137 {"ADC3", NULL, "AMIC3"},
3138 {"ADC4", NULL, "AMIC4"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003139
3140 /* AUX PGA Connections */
3141 {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3142 {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3143 {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3144 {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3145 {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003146
3147 {"IIR1", NULL, "IIR1 INP1 MUX"},
3148 {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"},
3149 {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003150
3151 {"MIC BIAS1 Internal1", NULL, "LDO_H"},
3152 {"MIC BIAS1 Internal2", NULL, "LDO_H"},
3153 {"MIC BIAS1 External", NULL, "LDO_H"},
3154 {"MIC BIAS2 Internal1", NULL, "LDO_H"},
3155 {"MIC BIAS2 Internal2", NULL, "LDO_H"},
3156 {"MIC BIAS2 Internal3", NULL, "LDO_H"},
3157 {"MIC BIAS2 External", NULL, "LDO_H"},
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07003158 {DAPM_MICBIAS2_EXTERNAL_STANDALONE, NULL, "LDO_H Standalone"},
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07003159};
3160
3161static const struct snd_soc_dapm_route wcd9302_map[] = {
3162 {"SPK DAC", "Switch", "RX3 MIX1"},
3163
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07003164
3165 {"RDAC5 MUX", "DEM4", "RX3 MIX1"},
3166 {"RDAC5 MUX", "DEM3_INV", "RDAC4 MUX"},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003167};
3168
3169static int tapan_readable(struct snd_soc_codec *ssc, unsigned int reg)
3170{
3171 return tapan_reg_readable[reg];
3172}
3173
3174static bool tapan_is_digital_gain_register(unsigned int reg)
3175{
3176 bool rtn = false;
3177 switch (reg) {
3178 case TAPAN_A_CDC_RX1_VOL_CTL_B2_CTL:
3179 case TAPAN_A_CDC_RX2_VOL_CTL_B2_CTL:
3180 case TAPAN_A_CDC_RX3_VOL_CTL_B2_CTL:
3181 case TAPAN_A_CDC_RX4_VOL_CTL_B2_CTL:
3182 case TAPAN_A_CDC_TX1_VOL_CTL_GAIN:
3183 case TAPAN_A_CDC_TX2_VOL_CTL_GAIN:
3184 case TAPAN_A_CDC_TX3_VOL_CTL_GAIN:
3185 case TAPAN_A_CDC_TX4_VOL_CTL_GAIN:
3186 rtn = true;
3187 break;
3188 default:
3189 break;
3190 }
3191 return rtn;
3192}
3193
3194static int tapan_volatile(struct snd_soc_codec *ssc, unsigned int reg)
3195{
Damir Didjustod6aea992013-09-03 21:18:59 -07003196
3197 int i = 0;
3198
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003199 /* Registers lower than 0x100 are top level registers which can be
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003200 * written by the Tapan core driver.
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003201 */
3202
3203 if ((reg >= TAPAN_A_CDC_MBHC_EN_CTL) || (reg < 0x100))
3204 return 1;
3205
3206 /* IIR Coeff registers are not cacheable */
3207 if ((reg >= TAPAN_A_CDC_IIR1_COEF_B1_CTL) &&
3208 (reg <= TAPAN_A_CDC_IIR2_COEF_B2_CTL))
3209 return 1;
3210
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07003211 /* ANC filter registers are not cacheable */
3212 if ((reg >= TAPAN_A_CDC_ANC1_IIR_B1_CTL) &&
3213 (reg <= TAPAN_A_CDC_ANC1_LPF_B2_CTL))
3214 return 1;
3215 if ((reg >= TAPAN_A_CDC_ANC2_IIR_B1_CTL) &&
3216 (reg <= TAPAN_A_CDC_ANC2_LPF_B2_CTL))
3217 return 1;
3218
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003219 /* Digital gain register is not cacheable so we have to write
3220 * the setting even it is the same
3221 */
3222 if (tapan_is_digital_gain_register(reg))
3223 return 1;
3224
3225 /* HPH status registers */
3226 if (reg == TAPAN_A_RX_HPH_L_STATUS || reg == TAPAN_A_RX_HPH_R_STATUS)
3227 return 1;
3228
3229 if (reg == TAPAN_A_MBHC_INSERT_DET_STATUS)
3230 return 1;
3231
Damir Didjustod6aea992013-09-03 21:18:59 -07003232 for (i = 0; i < ARRAY_SIZE(audio_reg_cfg); i++)
3233 if (audio_reg_cfg[i].reg_logical_addr -
3234 TAPAN_REGISTER_START_OFFSET == reg)
3235 return 1;
3236
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003237 return 0;
3238}
3239
3240#define TAPAN_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
Venkat Sudhirbb444472014-01-14 10:03:23 -08003241#define TAPAN_FORMATS_S16_S24_LE (SNDRV_PCM_FMTBIT_S16_LE | \
3242 SNDRV_PCM_FORMAT_S24_LE)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003243static int tapan_write(struct snd_soc_codec *codec, unsigned int reg,
3244 unsigned int value)
3245{
3246 int ret;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07003247 struct wcd9xxx *wcd9xxx = codec->control_data;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003248
3249 if (reg == SND_SOC_NOPM)
3250 return 0;
3251
3252 BUG_ON(reg > TAPAN_MAX_REGISTER);
3253
3254 if (!tapan_volatile(codec, reg)) {
3255 ret = snd_soc_cache_write(codec, reg, value);
3256 if (ret != 0)
3257 dev_err(codec->dev, "Cache write to %x failed: %d\n",
3258 reg, ret);
3259 }
3260
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07003261 return wcd9xxx_reg_write(&wcd9xxx->core_res, reg, value);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003262}
3263static unsigned int tapan_read(struct snd_soc_codec *codec,
3264 unsigned int reg)
3265{
3266 unsigned int val;
3267 int ret;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07003268 struct wcd9xxx *wcd9xxx = codec->control_data;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003269
3270 if (reg == SND_SOC_NOPM)
3271 return 0;
3272
3273 BUG_ON(reg > TAPAN_MAX_REGISTER);
3274
3275 if (!tapan_volatile(codec, reg) && tapan_readable(codec, reg) &&
3276 reg < codec->driver->reg_cache_size) {
3277 ret = snd_soc_cache_read(codec, reg, &val);
3278 if (ret >= 0) {
3279 return val;
3280 } else
3281 dev_err(codec->dev, "Cache read from %x failed: %d\n",
3282 reg, ret);
3283 }
3284
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07003285 val = wcd9xxx_reg_read(&wcd9xxx->core_res, reg);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003286 return val;
3287}
3288
3289static int tapan_startup(struct snd_pcm_substream *substream,
3290 struct snd_soc_dai *dai)
3291{
3292 struct wcd9xxx *tapan_core = dev_get_drvdata(dai->codec->dev->parent);
3293 dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n",
3294 __func__, substream->name, substream->stream);
3295 if ((tapan_core != NULL) &&
3296 (tapan_core->dev != NULL) &&
3297 (tapan_core->dev->parent != NULL))
3298 pm_runtime_get_sync(tapan_core->dev->parent);
3299
3300 return 0;
3301}
3302
3303static void tapan_shutdown(struct snd_pcm_substream *substream,
3304 struct snd_soc_dai *dai)
3305{
3306 struct wcd9xxx *tapan_core = dev_get_drvdata(dai->codec->dev->parent);
Phani Kumar Uppalapatie2a18e22013-10-24 14:32:54 -07003307 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(dai->codec);
3308 u32 active = 0;
3309
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003310 dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n",
3311 __func__, substream->name, substream->stream);
Phani Kumar Uppalapatie2a18e22013-10-24 14:32:54 -07003312
3313 if (dai->id <= NUM_CODEC_DAIS) {
3314 if (tapan->dai[dai->id].ch_mask) {
3315 active = 1;
3316 dev_dbg(dai->codec->dev, "%s(): Codec DAI: chmask[%d] = 0x%lx\n",
3317 __func__, dai->id,
3318 tapan->dai[dai->id].ch_mask);
3319 }
3320 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003321 if ((tapan_core != NULL) &&
3322 (tapan_core->dev != NULL) &&
Phani Kumar Uppalapatie2a18e22013-10-24 14:32:54 -07003323 (tapan_core->dev->parent != NULL) &&
3324 (active == 0)) {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003325 pm_runtime_mark_last_busy(tapan_core->dev->parent);
3326 pm_runtime_put(tapan_core->dev->parent);
Phani Kumar Uppalapatie2a18e22013-10-24 14:32:54 -07003327 dev_dbg(dai->codec->dev, "%s: unvote requested", __func__);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003328 }
3329}
3330
Bhalchandra Gajare4e3dd852013-08-19 17:21:23 -07003331static void tapan_set_vdd_cx_current(struct snd_soc_codec *codec,
3332 int current_uA)
3333{
3334 struct regulator *cx_regulator;
3335 int ret;
3336
3337 cx_regulator = tapan_codec_find_regulator(codec,
3338 "cdc-vdd-cx");
3339
3340 if (!cx_regulator) {
3341 dev_err(codec->dev, "%s: Regulator %s not defined\n",
3342 __func__, "cdc-vdd-cx-supply");
3343 return;
3344 }
3345
3346 ret = regulator_set_optimum_mode(cx_regulator, current_uA);
3347 if (ret < 0)
3348 dev_err(codec->dev,
3349 "%s: Failed to set vdd_cx current to %d\n",
3350 __func__, current_uA);
3351}
3352
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003353int tapan_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, bool dapm)
3354{
3355 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
3356
3357 dev_dbg(codec->dev, "%s: mclk_enable = %u, dapm = %d\n", __func__,
3358 mclk_enable, dapm);
3359
Joonwoo Park533b3682013-06-13 11:41:21 -07003360 WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003361 if (mclk_enable) {
Bhalchandra Gajare4e3dd852013-08-19 17:21:23 -07003362 tapan_set_vdd_cx_current(codec, TAPAN_VDD_CX_OPTIMAL_UA);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003363 wcd9xxx_resmgr_get_bandgap(&tapan->resmgr,
3364 WCD9XXX_BANDGAP_AUDIO_MODE);
3365 wcd9xxx_resmgr_get_clk_block(&tapan->resmgr, WCD9XXX_CLK_MCLK);
3366 } else {
3367 /* Put clock and BG */
3368 wcd9xxx_resmgr_put_clk_block(&tapan->resmgr, WCD9XXX_CLK_MCLK);
3369 wcd9xxx_resmgr_put_bandgap(&tapan->resmgr,
3370 WCD9XXX_BANDGAP_AUDIO_MODE);
Bhalchandra Gajare4e3dd852013-08-19 17:21:23 -07003371 /* Set the vdd cx power rail sleep mode current */
3372 tapan_set_vdd_cx_current(codec, TAPAN_VDD_CX_SLEEP_UA);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003373 }
Joonwoo Park533b3682013-06-13 11:41:21 -07003374 WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003375
3376 return 0;
3377}
3378
3379static int tapan_set_dai_sysclk(struct snd_soc_dai *dai,
3380 int clk_id, unsigned int freq, int dir)
3381{
3382 dev_dbg(dai->codec->dev, "%s\n", __func__);
3383 return 0;
3384}
3385
3386static int tapan_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3387{
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003388 u8 val = 0;
3389 struct snd_soc_codec *codec = dai->codec;
3390 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
3391
3392 dev_dbg(codec->dev, "%s\n", __func__);
3393 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
3394 case SND_SOC_DAIFMT_CBS_CFS:
3395 /* CPU is master */
3396 if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
3397 if (dai->id == AIF1_CAP)
3398 snd_soc_update_bits(codec,
3399 TAPAN_A_CDC_CLK_I2S_CTL,
3400 TAPAN_I2S_MASTER_MODE_MASK, 0);
3401 else if (dai->id == AIF1_PB)
3402 snd_soc_update_bits(codec,
3403 TAPAN_A_CDC_CLK_I2S_CTL,
3404 TAPAN_I2S_MASTER_MODE_MASK, 0);
3405 }
3406 break;
3407 case SND_SOC_DAIFMT_CBM_CFM:
3408 /* CPU is slave */
3409 if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
3410 val = TAPAN_I2S_MASTER_MODE_MASK;
3411 if (dai->id == AIF1_CAP)
3412 snd_soc_update_bits(codec,
3413 TAPAN_A_CDC_CLK_I2S_CTL, val, val);
3414 else if (dai->id == AIF1_PB)
3415 snd_soc_update_bits(codec,
3416 TAPAN_A_CDC_CLK_I2S_CTL, val, val);
3417 }
3418 break;
3419 default:
3420 return -EINVAL;
3421 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003422 return 0;
3423}
3424
3425static int tapan_set_channel_map(struct snd_soc_dai *dai,
3426 unsigned int tx_num, unsigned int *tx_slot,
3427 unsigned int rx_num, unsigned int *rx_slot)
3428
3429{
3430 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(dai->codec);
3431 struct wcd9xxx *core = dev_get_drvdata(dai->codec->dev->parent);
3432 if (!tx_slot && !rx_slot) {
3433 pr_err("%s: Invalid\n", __func__);
3434 return -EINVAL;
3435 }
3436 dev_dbg(dai->codec->dev, "%s(): dai_name = %s DAI-ID %x\n",
3437 __func__, dai->name, dai->id);
3438 dev_dbg(dai->codec->dev, "%s(): tx_ch %d rx_ch %d\n intf_type %d\n",
3439 __func__, tx_num, rx_num, tapan->intf_type);
3440
3441 if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
3442 wcd9xxx_init_slimslave(core, core->slim->laddr,
3443 tx_num, tx_slot, rx_num, rx_slot);
3444 return 0;
3445}
3446
3447static int tapan_get_channel_map(struct snd_soc_dai *dai,
3448 unsigned int *tx_num, unsigned int *tx_slot,
3449 unsigned int *rx_num, unsigned int *rx_slot)
3450
3451{
3452 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(dai->codec);
3453 u32 i = 0;
3454 struct wcd9xxx_ch *ch;
3455
3456 switch (dai->id) {
3457 case AIF1_PB:
3458 case AIF2_PB:
3459 case AIF3_PB:
3460 if (!rx_slot || !rx_num) {
3461 pr_err("%s: Invalid rx_slot %d or rx_num %d\n",
3462 __func__, (u32) rx_slot, (u32) rx_num);
3463 return -EINVAL;
3464 }
3465 list_for_each_entry(ch, &tapan_p->dai[dai->id].wcd9xxx_ch_list,
3466 list) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003467 dev_dbg(dai->codec->dev, "%s: rx_slot[%d] %d, ch->ch_num %d\n",
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003468 __func__, i, rx_slot[i], ch->ch_num);
3469 rx_slot[i++] = ch->ch_num;
3470 }
3471 dev_dbg(dai->codec->dev, "%s: rx_num %d\n", __func__, i);
3472 *rx_num = i;
3473 break;
3474 case AIF1_CAP:
3475 case AIF2_CAP:
3476 case AIF3_CAP:
3477 if (!tx_slot || !tx_num) {
3478 pr_err("%s: Invalid tx_slot %d or tx_num %d\n",
3479 __func__, (u32) tx_slot, (u32) tx_num);
3480 return -EINVAL;
3481 }
3482 list_for_each_entry(ch, &tapan_p->dai[dai->id].wcd9xxx_ch_list,
3483 list) {
3484 dev_dbg(dai->codec->dev, "%s: tx_slot[%d] %d, ch->ch_num %d\n",
3485 __func__, i, tx_slot[i], ch->ch_num);
3486 tx_slot[i++] = ch->ch_num;
3487 }
3488 dev_dbg(dai->codec->dev, "%s: tx_num %d\n", __func__, i);
3489 *tx_num = i;
3490 break;
3491
3492 default:
3493 pr_err("%s: Invalid DAI ID %x\n", __func__, dai->id);
3494 break;
3495 }
3496
3497 return 0;
3498}
3499
3500static int tapan_set_interpolator_rate(struct snd_soc_dai *dai,
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003501 u8 rx_fs_rate_reg_val, u32 compander_fs, u32 sample_rate)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003502{
3503 u32 j;
3504 u8 rx_mix1_inp;
3505 u16 rx_mix_1_reg_1, rx_mix_1_reg_2;
3506 u16 rx_fs_reg;
3507 u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val;
Banajit Goswamia7294452013-06-03 12:42:35 -07003508 u8 rdac5_mux;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003509 struct snd_soc_codec *codec = dai->codec;
3510 struct wcd9xxx_ch *ch;
3511 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
3512
3513 list_for_each_entry(ch, &tapan->dai[dai->id].wcd9xxx_ch_list, list) {
3514 /* for RX port starting from 16 instead of 10 like tabla */
3515 rx_mix1_inp = ch->port + RX_MIX1_INP_SEL_RX1 -
3516 TAPAN_TX_PORT_NUMBER;
3517 if ((rx_mix1_inp < RX_MIX1_INP_SEL_RX1) ||
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003518 (rx_mix1_inp > RX_MIX1_INP_SEL_RX5)) {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003519 pr_err("%s: Invalid TAPAN_RX%u port. Dai ID is %d\n",
3520 __func__, rx_mix1_inp - 5 , dai->id);
3521 return -EINVAL;
3522 }
3523
3524 rx_mix_1_reg_1 = TAPAN_A_CDC_CONN_RX1_B1_CTL;
3525
Banajit Goswamia7294452013-06-03 12:42:35 -07003526 rdac5_mux = snd_soc_read(codec, TAPAN_A_CDC_CONN_MISC);
3527 rdac5_mux = (rdac5_mux & 0x04) >> 2;
3528
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003529 for (j = 0; j < NUM_INTERPOLATORS; j++) {
3530 rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1;
3531
3532 rx_mix_1_reg_1_val = snd_soc_read(codec,
3533 rx_mix_1_reg_1);
3534 rx_mix_1_reg_2_val = snd_soc_read(codec,
3535 rx_mix_1_reg_2);
3536
3537 if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) ||
3538 (((rx_mix_1_reg_1_val >> 4) & 0x0F)
3539 == rx_mix1_inp) ||
3540 ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) {
3541
3542 rx_fs_reg = TAPAN_A_CDC_RX1_B5_CTL + 8 * j;
3543
3544 dev_dbg(codec->dev, "%s: AIF_PB DAI(%d) connected to RX%u\n",
3545 __func__, dai->id, j + 1);
3546
3547 dev_dbg(codec->dev, "%s: set RX%u sample rate to %u\n",
3548 __func__, j + 1, sample_rate);
3549
3550 snd_soc_update_bits(codec, rx_fs_reg,
3551 0xE0, rx_fs_rate_reg_val);
3552
Banajit Goswamia7294452013-06-03 12:42:35 -07003553 if (comp_rx_path[j] < COMPANDER_MAX) {
3554 if ((j == 3) && (rdac5_mux == 1))
3555 tapan->comp_fs[COMPANDER_0] =
3556 compander_fs;
3557 else
3558 tapan->comp_fs[comp_rx_path[j]]
3559 = compander_fs;
3560 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003561 }
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07003562 if (j <= 1)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003563 rx_mix_1_reg_1 += 3;
3564 else
3565 rx_mix_1_reg_1 += 2;
3566 }
3567 }
3568 return 0;
3569}
3570
3571static int tapan_set_decimator_rate(struct snd_soc_dai *dai,
3572 u8 tx_fs_rate_reg_val, u32 sample_rate)
3573{
3574 struct snd_soc_codec *codec = dai->codec;
3575 struct wcd9xxx_ch *ch;
3576 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
3577 u32 tx_port;
3578 u16 tx_port_reg, tx_fs_reg;
3579 u8 tx_port_reg_val;
3580 s8 decimator;
3581
3582 list_for_each_entry(ch, &tapan->dai[dai->id].wcd9xxx_ch_list, list) {
3583
3584 tx_port = ch->port + 1;
3585 dev_dbg(codec->dev, "%s: dai->id = %d, tx_port = %d",
3586 __func__, dai->id, tx_port);
3587
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003588 if ((tx_port < 1) || (tx_port > TAPAN_SLIM_CODEC_TX_PORTS)) {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003589 pr_err("%s: Invalid SLIM TX%u port. DAI ID is %d\n",
3590 __func__, tx_port, dai->id);
3591 return -EINVAL;
3592 }
3593
3594 tx_port_reg = TAPAN_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1);
3595 tx_port_reg_val = snd_soc_read(codec, tx_port_reg);
3596
3597 decimator = 0;
3598
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003599 tx_port_reg_val = tx_port_reg_val & 0x0F;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003600
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003601 if ((tx_port_reg_val >= 0x8) &&
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003602 (tx_port_reg_val <= 0x11)) {
3603
3604 decimator = (tx_port_reg_val - 0x8) + 1;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003605 }
3606
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003607
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003608 if (decimator) { /* SLIM_TX port has a DEC as input */
3609
3610 tx_fs_reg = TAPAN_A_CDC_TX1_CLK_FS_CTL +
3611 8 * (decimator - 1);
3612
3613 dev_dbg(codec->dev, "%s: set DEC%u (-> SLIM_TX%u) rate to %u\n",
3614 __func__, decimator, tx_port, sample_rate);
3615
3616 snd_soc_update_bits(codec, tx_fs_reg, 0x07,
3617 tx_fs_rate_reg_val);
3618
3619 } else {
3620 if ((tx_port_reg_val >= 0x1) &&
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003621 (tx_port_reg_val <= 0x4)) {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003622
3623 dev_dbg(codec->dev, "%s: RMIX%u going to SLIM TX%u\n",
3624 __func__, tx_port_reg_val, tx_port);
3625
3626 } else if ((tx_port_reg_val >= 0x8) &&
3627 (tx_port_reg_val <= 0x11)) {
3628
3629 pr_err("%s: ERROR: Should not be here\n",
3630 __func__);
3631 pr_err("%s: ERROR: DEC connected to SLIM TX%u\n",
3632 __func__, tx_port);
3633 return -EINVAL;
3634
3635 } else if (tx_port_reg_val == 0) {
3636 dev_dbg(codec->dev, "%s: no signal to SLIM TX%u\n",
3637 __func__, tx_port);
3638 } else {
3639 pr_err("%s: ERROR: wrong signal to SLIM TX%u\n",
3640 __func__, tx_port);
3641 pr_err("%s: ERROR: wrong signal = %u\n",
3642 __func__, tx_port_reg_val);
3643 return -EINVAL;
3644 }
3645 }
3646 }
3647 return 0;
3648}
3649
Venkat Sudhirbb444472014-01-14 10:03:23 -08003650static void tapan_set_rxsb_port_format(struct snd_pcm_hw_params *params,
3651 struct snd_soc_dai *dai)
3652{
3653 struct snd_soc_codec *codec = dai->codec;
3654 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
3655 struct wcd9xxx_codec_dai_data *cdc_dai;
3656 struct wcd9xxx_ch *ch;
3657 int port;
3658 u8 bit_sel;
3659 u16 sb_ctl_reg, field_shift;
3660
3661 switch (params_format(params)) {
3662 case SNDRV_PCM_FORMAT_S16_LE:
3663 bit_sel = 0x2;
3664 tapan_p->dai[dai->id].bit_width = 16;
3665 break;
3666 case SNDRV_PCM_FORMAT_S24_LE:
3667 bit_sel = 0x0;
3668 tapan_p->dai[dai->id].bit_width = 24;
3669 break;
3670 default:
3671 dev_err(codec->dev, "Invalid format %x\n",
3672 params_format(params));
3673 return;
3674 }
3675
3676 cdc_dai = &tapan_p->dai[dai->id];
3677
3678 list_for_each_entry(ch, &cdc_dai->wcd9xxx_ch_list, list) {
3679 port = wcd9xxx_get_slave_port(ch->ch_num);
3680
3681 if (IS_ERR_VALUE(port) ||
3682 !TAPAN_VALIDATE_RX_SBPORT_RANGE(port)) {
3683 dev_warn(codec->dev,
3684 "%s: invalid port ID %d returned for RX DAI\n",
3685 __func__, port);
3686 return;
3687 }
3688
3689 port = TAPAN_CONVERT_RX_SBPORT_ID(port);
3690
3691 if (port <= 3) {
3692 sb_ctl_reg = TAPAN_A_CDC_CONN_RX_SB_B1_CTL;
3693 field_shift = port << 1;
3694 } else if (port <= 4) {
3695 sb_ctl_reg = TAPAN_A_CDC_CONN_RX_SB_B2_CTL;
3696 field_shift = (port - 4) << 1;
3697 } else { /* should not happen */
3698 dev_warn(codec->dev,
3699 "%s: bad port ID %d\n", __func__, port);
3700 return;
3701 }
3702
3703 dev_dbg(codec->dev, "%s: sb_ctl_reg %x field_shift %x\n"
3704 "bit_sel %x\n", __func__, sb_ctl_reg, field_shift,
3705 bit_sel);
3706 snd_soc_update_bits(codec, sb_ctl_reg, 0x3 << field_shift,
3707 bit_sel << field_shift);
3708 }
3709}
3710
3711
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003712static int tapan_hw_params(struct snd_pcm_substream *substream,
3713 struct snd_pcm_hw_params *params,
3714 struct snd_soc_dai *dai)
3715{
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003716 struct snd_soc_codec *codec = dai->codec;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003717 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(dai->codec);
3718 u8 tx_fs_rate, rx_fs_rate;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003719 u32 compander_fs;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003720 int ret;
3721
3722 dev_dbg(dai->codec->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n",
3723 __func__, dai->name, dai->id,
3724 params_rate(params), params_channels(params));
3725
3726 switch (params_rate(params)) {
3727 case 8000:
3728 tx_fs_rate = 0x00;
3729 rx_fs_rate = 0x00;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003730 compander_fs = COMPANDER_FS_8KHZ;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003731 break;
3732 case 16000:
3733 tx_fs_rate = 0x01;
3734 rx_fs_rate = 0x20;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003735 compander_fs = COMPANDER_FS_16KHZ;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003736 break;
3737 case 32000:
3738 tx_fs_rate = 0x02;
3739 rx_fs_rate = 0x40;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003740 compander_fs = COMPANDER_FS_32KHZ;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003741 break;
3742 case 48000:
3743 tx_fs_rate = 0x03;
3744 rx_fs_rate = 0x60;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003745 compander_fs = COMPANDER_FS_48KHZ;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003746 break;
3747 case 96000:
3748 tx_fs_rate = 0x04;
3749 rx_fs_rate = 0x80;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003750 compander_fs = COMPANDER_FS_96KHZ;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003751 break;
3752 case 192000:
3753 tx_fs_rate = 0x05;
3754 rx_fs_rate = 0xA0;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003755 compander_fs = COMPANDER_FS_192KHZ;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003756 break;
3757 default:
3758 pr_err("%s: Invalid sampling rate %d\n", __func__,
3759 params_rate(params));
3760 return -EINVAL;
3761 }
3762
3763 switch (substream->stream) {
3764 case SNDRV_PCM_STREAM_CAPTURE:
3765 ret = tapan_set_decimator_rate(dai, tx_fs_rate,
3766 params_rate(params));
3767 if (ret < 0) {
3768 pr_err("%s: set decimator rate failed %d\n", __func__,
3769 ret);
3770 return ret;
3771 }
3772
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003773 if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
3774 switch (params_format(params)) {
3775 case SNDRV_PCM_FORMAT_S16_LE:
3776 snd_soc_update_bits(codec,
3777 TAPAN_A_CDC_CLK_I2S_CTL,
3778 0x20, 0x20);
3779 break;
3780 case SNDRV_PCM_FORMAT_S32_LE:
3781 snd_soc_update_bits(codec,
3782 TAPAN_A_CDC_CLK_I2S_CTL,
3783 0x20, 0x00);
3784 break;
3785 default:
3786 pr_err("invalid format\n");
3787 break;
3788 }
3789 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_I2S_CTL,
3790 0x07, tx_fs_rate);
3791 } else {
3792 tapan->dai[dai->id].rate = params_rate(params);
3793 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003794 break;
3795
3796 case SNDRV_PCM_STREAM_PLAYBACK:
3797 ret = tapan_set_interpolator_rate(dai, rx_fs_rate,
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003798 compander_fs,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003799 params_rate(params));
3800 if (ret < 0) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003801 dev_err(codec->dev, "%s: set decimator rate failed %d\n",
3802 __func__, ret);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003803 return ret;
3804 }
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003805 if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
3806 switch (params_format(params)) {
3807 case SNDRV_PCM_FORMAT_S16_LE:
3808 snd_soc_update_bits(codec,
3809 TAPAN_A_CDC_CLK_I2S_CTL,
3810 0x20, 0x20);
3811 break;
3812 case SNDRV_PCM_FORMAT_S32_LE:
3813 snd_soc_update_bits(codec,
3814 TAPAN_A_CDC_CLK_I2S_CTL,
3815 0x20, 0x00);
3816 break;
3817 default:
3818 dev_err(codec->dev, "invalid format\n");
3819 break;
3820 }
3821 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_I2S_CTL,
3822 0x03, (rx_fs_rate >> 0x05));
3823 } else {
Venkat Sudhirbb444472014-01-14 10:03:23 -08003824 tapan_set_rxsb_port_format(params, dai);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003825 tapan->dai[dai->id].rate = params_rate(params);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003826 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003827 break;
3828 default:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08003829 dev_err(codec->dev, "%s: Invalid stream type %d\n", __func__,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003830 substream->stream);
3831 return -EINVAL;
3832 }
3833
3834 return 0;
3835}
3836
3837static struct snd_soc_dai_ops tapan_dai_ops = {
3838 .startup = tapan_startup,
3839 .shutdown = tapan_shutdown,
3840 .hw_params = tapan_hw_params,
3841 .set_sysclk = tapan_set_dai_sysclk,
3842 .set_fmt = tapan_set_dai_fmt,
3843 .set_channel_map = tapan_set_channel_map,
3844 .get_channel_map = tapan_get_channel_map,
3845};
3846
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07003847static struct snd_soc_dai_driver tapan9302_dai[] = {
3848 {
3849 .name = "tapan9302_rx1",
3850 .id = AIF1_PB,
3851 .playback = {
3852 .stream_name = "AIF1 Playback",
3853 .rates = WCD9302_RATES,
3854 .formats = TAPAN_FORMATS,
3855 .rate_max = 48000,
3856 .rate_min = 8000,
3857 .channels_min = 1,
3858 .channels_max = 2,
3859 },
3860 .ops = &tapan_dai_ops,
3861 },
3862 {
3863 .name = "tapan9302_tx1",
3864 .id = AIF1_CAP,
3865 .capture = {
3866 .stream_name = "AIF1 Capture",
3867 .rates = WCD9302_RATES,
3868 .formats = TAPAN_FORMATS,
3869 .rate_max = 48000,
3870 .rate_min = 8000,
3871 .channels_min = 1,
3872 .channels_max = 4,
3873 },
3874 .ops = &tapan_dai_ops,
3875 },
3876 {
3877 .name = "tapan9302_rx2",
3878 .id = AIF2_PB,
3879 .playback = {
3880 .stream_name = "AIF2 Playback",
3881 .rates = WCD9302_RATES,
3882 .formats = TAPAN_FORMATS,
3883 .rate_min = 8000,
3884 .rate_max = 48000,
3885 .channels_min = 1,
3886 .channels_max = 2,
3887 },
3888 .ops = &tapan_dai_ops,
3889 },
3890 {
3891 .name = "tapan9302_tx2",
3892 .id = AIF2_CAP,
3893 .capture = {
3894 .stream_name = "AIF2 Capture",
3895 .rates = WCD9302_RATES,
3896 .formats = TAPAN_FORMATS,
3897 .rate_max = 48000,
3898 .rate_min = 8000,
3899 .channels_min = 1,
3900 .channels_max = 4,
3901 },
3902 .ops = &tapan_dai_ops,
3903 },
3904 {
3905 .name = "tapan9302_tx3",
3906 .id = AIF3_CAP,
3907 .capture = {
3908 .stream_name = "AIF3 Capture",
3909 .rates = WCD9302_RATES,
3910 .formats = TAPAN_FORMATS,
3911 .rate_max = 48000,
3912 .rate_min = 8000,
3913 .channels_min = 1,
3914 .channels_max = 2,
3915 },
3916 .ops = &tapan_dai_ops,
3917 },
3918 {
3919 .name = "tapan9302_rx3",
3920 .id = AIF3_PB,
3921 .playback = {
3922 .stream_name = "AIF3 Playback",
3923 .rates = WCD9302_RATES,
3924 .formats = TAPAN_FORMATS,
3925 .rate_min = 8000,
3926 .rate_max = 48000,
3927 .channels_min = 1,
3928 .channels_max = 2,
3929 },
3930 .ops = &tapan_dai_ops,
3931 },
3932};
3933
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003934static struct snd_soc_dai_driver tapan_dai[] = {
3935 {
3936 .name = "tapan_rx1",
3937 .id = AIF1_PB,
3938 .playback = {
3939 .stream_name = "AIF1 Playback",
3940 .rates = WCD9306_RATES,
Venkat Sudhirbb444472014-01-14 10:03:23 -08003941 .formats = TAPAN_FORMATS_S16_S24_LE,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003942 .rate_max = 192000,
3943 .rate_min = 8000,
3944 .channels_min = 1,
3945 .channels_max = 2,
3946 },
3947 .ops = &tapan_dai_ops,
3948 },
3949 {
3950 .name = "tapan_tx1",
3951 .id = AIF1_CAP,
3952 .capture = {
3953 .stream_name = "AIF1 Capture",
3954 .rates = WCD9306_RATES,
3955 .formats = TAPAN_FORMATS,
3956 .rate_max = 192000,
3957 .rate_min = 8000,
3958 .channels_min = 1,
3959 .channels_max = 4,
3960 },
3961 .ops = &tapan_dai_ops,
3962 },
3963 {
3964 .name = "tapan_rx2",
3965 .id = AIF2_PB,
3966 .playback = {
3967 .stream_name = "AIF2 Playback",
3968 .rates = WCD9306_RATES,
Venkat Sudhirbb444472014-01-14 10:03:23 -08003969 .formats = TAPAN_FORMATS_S16_S24_LE,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08003970 .rate_min = 8000,
3971 .rate_max = 192000,
3972 .channels_min = 1,
3973 .channels_max = 2,
3974 },
3975 .ops = &tapan_dai_ops,
3976 },
3977 {
3978 .name = "tapan_tx2",
3979 .id = AIF2_CAP,
3980 .capture = {
3981 .stream_name = "AIF2 Capture",
3982 .rates = WCD9306_RATES,
3983 .formats = TAPAN_FORMATS,
3984 .rate_max = 192000,
3985 .rate_min = 8000,
3986 .channels_min = 1,
3987 .channels_max = 4,
3988 },
3989 .ops = &tapan_dai_ops,
3990 },
3991 {
3992 .name = "tapan_tx3",
3993 .id = AIF3_CAP,
3994 .capture = {
3995 .stream_name = "AIF3 Capture",
3996 .rates = WCD9306_RATES,
3997 .formats = TAPAN_FORMATS,
3998 .rate_max = 48000,
3999 .rate_min = 8000,
4000 .channels_min = 1,
4001 .channels_max = 2,
4002 },
4003 .ops = &tapan_dai_ops,
4004 },
4005 {
4006 .name = "tapan_rx3",
4007 .id = AIF3_PB,
4008 .playback = {
4009 .stream_name = "AIF3 Playback",
4010 .rates = WCD9306_RATES,
Venkat Sudhirbb444472014-01-14 10:03:23 -08004011 .formats = TAPAN_FORMATS_S16_S24_LE,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004012 .rate_min = 8000,
4013 .rate_max = 192000,
4014 .channels_min = 1,
4015 .channels_max = 2,
4016 },
4017 .ops = &tapan_dai_ops,
4018 },
4019};
4020
4021static struct snd_soc_dai_driver tapan_i2s_dai[] = {
4022 {
4023 .name = "tapan_i2s_rx1",
4024 .id = AIF1_PB,
4025 .playback = {
4026 .stream_name = "AIF1 Playback",
4027 .rates = WCD9306_RATES,
4028 .formats = TAPAN_FORMATS,
4029 .rate_max = 192000,
4030 .rate_min = 8000,
4031 .channels_min = 1,
4032 .channels_max = 4,
4033 },
4034 .ops = &tapan_dai_ops,
4035 },
4036 {
4037 .name = "tapan_i2s_tx1",
4038 .id = AIF1_CAP,
4039 .capture = {
4040 .stream_name = "AIF1 Capture",
4041 .rates = WCD9306_RATES,
4042 .formats = TAPAN_FORMATS,
4043 .rate_max = 192000,
4044 .rate_min = 8000,
4045 .channels_min = 1,
4046 .channels_max = 4,
4047 },
4048 .ops = &tapan_dai_ops,
4049 },
4050};
4051
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004052static int tapan_codec_enable_slim_chmask(struct wcd9xxx_codec_dai_data *dai,
4053 bool up)
4054{
4055 int ret = 0;
4056 struct wcd9xxx_ch *ch;
4057
4058 if (up) {
4059 list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) {
4060 ret = wcd9xxx_get_slave_port(ch->ch_num);
4061 if (ret < 0) {
4062 pr_debug("%s: Invalid slave port ID: %d\n",
4063 __func__, ret);
4064 ret = -EINVAL;
4065 } else {
4066 set_bit(ret, &dai->ch_mask);
4067 }
4068 }
4069 } else {
4070 ret = wait_event_timeout(dai->dai_wait, (dai->ch_mask == 0),
4071 msecs_to_jiffies(
4072 TAPAN_SLIM_CLOSE_TIMEOUT));
4073 if (!ret) {
4074 pr_debug("%s: Slim close tx/rx wait timeout\n",
4075 __func__);
4076 ret = -ETIMEDOUT;
4077 } else {
4078 ret = 0;
4079 }
4080 }
4081 return ret;
4082}
4083
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004084static int tapan_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
4085 struct snd_kcontrol *kcontrol,
4086 int event)
4087{
4088 struct wcd9xxx *core;
4089 struct snd_soc_codec *codec = w->codec;
4090 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004091 int ret = 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004092 struct wcd9xxx_codec_dai_data *dai;
4093
4094 core = dev_get_drvdata(codec->dev->parent);
4095
4096 dev_dbg(codec->dev, "%s: event called! codec name %s\n",
4097 __func__, w->codec->name);
4098 dev_dbg(codec->dev, "%s: num_dai %d stream name %s event %d\n",
4099 __func__, w->codec->num_dai, w->sname, event);
4100
4101 /* Execute the callback only if interface type is slimbus */
4102 if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
4103 return 0;
4104
4105 dai = &tapan_p->dai[w->shift];
4106 dev_dbg(codec->dev, "%s: w->name %s w->shift %d event %d\n",
4107 __func__, w->name, w->shift, event);
4108
4109 switch (event) {
4110 case SND_SOC_DAPM_POST_PMU:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004111 (void) tapan_codec_enable_slim_chmask(dai, true);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004112 ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
4113 dai->rate, dai->bit_width,
4114 &dai->grph);
4115 break;
4116 case SND_SOC_DAPM_POST_PMD:
4117 ret = wcd9xxx_close_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
4118 dai->grph);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004119 ret = tapan_codec_enable_slim_chmask(dai, false);
4120 if (ret < 0) {
4121 ret = wcd9xxx_disconnect_port(core,
4122 &dai->wcd9xxx_ch_list,
4123 dai->grph);
4124 dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n",
4125 __func__, ret);
4126 }
Phani Kumar Uppalapatie2a18e22013-10-24 14:32:54 -07004127 if ((core != NULL) &&
4128 (core->dev != NULL) &&
4129 (core->dev->parent != NULL)) {
4130 pm_runtime_mark_last_busy(core->dev->parent);
4131 pm_runtime_put(core->dev->parent);
4132 dev_dbg(codec->dev, "%s: unvote requested", __func__);
4133 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004134 break;
4135 }
4136 return ret;
4137}
4138
4139static int tapan_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
4140 struct snd_kcontrol *kcontrol,
4141 int event)
4142{
4143 struct wcd9xxx *core;
4144 struct snd_soc_codec *codec = w->codec;
4145 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
4146 u32 ret = 0;
4147 struct wcd9xxx_codec_dai_data *dai;
4148
4149 core = dev_get_drvdata(codec->dev->parent);
4150
4151 dev_dbg(codec->dev, "%s: event called! codec name %s\n",
4152 __func__, w->codec->name);
4153 dev_dbg(codec->dev, "%s: num_dai %d stream name %s\n",
4154 __func__, w->codec->num_dai, w->sname);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004155 /* Execute the callback only if interface type is slimbus */
4156 if (tapan_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
4157 return 0;
4158
4159 dev_dbg(codec->dev, "%s(): w->name %s event %d w->shift %d\n",
4160 __func__, w->name, event, w->shift);
4161
4162 dai = &tapan_p->dai[w->shift];
4163 switch (event) {
4164 case SND_SOC_DAPM_POST_PMU:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004165 (void) tapan_codec_enable_slim_chmask(dai, true);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004166 ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
4167 dai->rate, dai->bit_width,
4168 &dai->grph);
4169 break;
4170 case SND_SOC_DAPM_POST_PMD:
4171 ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
4172 dai->grph);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004173 ret = tapan_codec_enable_slim_chmask(dai, false);
4174 if (ret < 0) {
4175 ret = wcd9xxx_disconnect_port(core,
4176 &dai->wcd9xxx_ch_list,
4177 dai->grph);
4178 dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n",
4179 __func__, ret);
4180 }
Phani Kumar Uppalapatie2a18e22013-10-24 14:32:54 -07004181 if ((core != NULL) &&
4182 (core->dev != NULL) &&
4183 (core->dev->parent != NULL)) {
4184 pm_runtime_mark_last_busy(core->dev->parent);
4185 pm_runtime_put(core->dev->parent);
4186 dev_dbg(codec->dev, "%s: unvote requested", __func__);
4187 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004188 break;
4189 }
4190 return ret;
4191}
4192
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004193
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004194static int tapan_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
4195 struct snd_kcontrol *kcontrol, int event)
4196{
4197 struct snd_soc_codec *codec = w->codec;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004198 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004199
4200 dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
4201
4202 switch (event) {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004203 case SND_SOC_DAPM_POST_PMU:
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004204 wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
4205 WCD9XXX_CLSH_STATE_EAR,
4206 WCD9XXX_CLSH_REQ_ENABLE,
4207 WCD9XXX_CLSH_EVENT_POST_PA);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004208
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004209 usleep_range(5000, 5010);
4210 break;
4211 case SND_SOC_DAPM_POST_PMD:
4212 wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
4213 WCD9XXX_CLSH_STATE_EAR,
4214 WCD9XXX_CLSH_REQ_DISABLE,
4215 WCD9XXX_CLSH_EVENT_POST_PA);
4216 usleep_range(5000, 5010);
4217 }
4218 return 0;
4219}
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004220
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004221static int tapan_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
4222 struct snd_kcontrol *kcontrol, int event)
4223{
4224 struct snd_soc_codec *codec = w->codec;
4225 struct tapan_priv *tapan_p = snd_soc_codec_get_drvdata(codec);
4226
4227 dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
4228
4229 switch (event) {
4230 case SND_SOC_DAPM_PRE_PMU:
4231 wcd9xxx_clsh_fsm(codec, &tapan_p->clsh_d,
4232 WCD9XXX_CLSH_STATE_EAR,
4233 WCD9XXX_CLSH_REQ_ENABLE,
4234 WCD9XXX_CLSH_EVENT_PRE_DAC);
4235 break;
4236 }
4237
4238 return 0;
4239}
4240
4241static int tapan_codec_dsm_mux_event(struct snd_soc_dapm_widget *w,
4242 struct snd_kcontrol *kcontrol, int event)
4243{
4244 struct snd_soc_codec *codec = w->codec;
4245 u8 reg_val, zoh_mux_val = 0x00;
4246
4247 dev_dbg(codec->dev, "%s: event = %d\n", __func__, event);
4248
4249 switch (event) {
4250 case SND_SOC_DAPM_POST_PMU:
4251 reg_val = snd_soc_read(codec, TAPAN_A_CDC_CONN_CLSH_CTL);
4252
4253 if ((reg_val & 0x30) == 0x10)
4254 zoh_mux_val = 0x04;
4255 else if ((reg_val & 0x30) == 0x20)
4256 zoh_mux_val = 0x08;
4257
4258 if (zoh_mux_val != 0x00)
4259 snd_soc_update_bits(codec,
4260 TAPAN_A_CDC_CONN_CLSH_CTL,
4261 0x0C, zoh_mux_val);
4262 break;
4263
4264 case SND_SOC_DAPM_POST_PMD:
4265 snd_soc_update_bits(codec, TAPAN_A_CDC_CONN_CLSH_CTL,
4266 0x0C, 0x00);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004267 break;
4268 }
4269 return 0;
4270}
4271
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07004272static int tapan_codec_enable_anc_ear(struct snd_soc_dapm_widget *w,
4273 struct snd_kcontrol *kcontrol, int event)
4274{
4275 struct snd_soc_codec *codec = w->codec;
4276 int ret = 0;
4277
4278 switch (event) {
4279 case SND_SOC_DAPM_PRE_PMU:
4280 ret = tapan_codec_enable_anc(w, kcontrol, event);
4281 msleep(50);
4282 snd_soc_update_bits(codec, TAPAN_A_RX_EAR_EN, 0x10, 0x10);
4283 break;
4284 case SND_SOC_DAPM_POST_PMU:
4285 ret = tapan_codec_enable_ear_pa(w, kcontrol, event);
4286 break;
4287 case SND_SOC_DAPM_PRE_PMD:
4288 snd_soc_update_bits(codec, TAPAN_A_RX_EAR_EN, 0x10, 0x00);
4289 msleep(40);
4290 ret |= tapan_codec_enable_anc(w, kcontrol, event);
4291 break;
4292 case SND_SOC_DAPM_POST_PMD:
4293 ret = tapan_codec_enable_ear_pa(w, kcontrol, event);
4294 break;
4295 }
4296 return ret;
4297}
4298
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07004299static int tapan_codec_chargepump_vdd_event(struct snd_soc_dapm_widget *w,
4300 struct snd_kcontrol *kcontrol, int event)
4301{
4302 struct snd_soc_codec *codec = w->codec;
4303 struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
4304 int ret = 0, i;
4305
4306 pr_info("%s: event = %d\n", __func__, event);
4307
4308
4309 if (!priv->cp_regulators[CP_REG_BUCK]
4310 && !priv->cp_regulators[CP_REG_BHELPER]) {
4311 pr_err("%s: No power supply defined for ChargePump\n",
4312 __func__);
4313 return -EINVAL;
4314 }
4315
4316 switch (event) {
4317 case SND_SOC_DAPM_PRE_PMU:
4318 for (i = 0; i < CP_REG_MAX ; i++) {
4319 if (!priv->cp_regulators[i])
4320 continue;
4321
4322 ret = regulator_enable(priv->cp_regulators[i]);
4323 if (ret) {
4324 pr_err("%s: CP Regulator enable failed, index = %d\n",
4325 __func__, i);
4326 continue;
4327 } else {
4328 pr_debug("%s: Enabled CP regulator, index %d\n",
4329 __func__, i);
4330 }
4331 }
4332 break;
4333 case SND_SOC_DAPM_POST_PMD:
4334 for (i = 0; i < CP_REG_MAX; i++) {
4335 if (!priv->cp_regulators[i])
4336 continue;
4337
4338 ret = regulator_disable(priv->cp_regulators[i]);
4339 if (ret) {
4340 pr_err("%s: CP Regulator disable failed, index = %d\n",
4341 __func__, i);
4342 return ret;
4343 } else {
4344 pr_debug("%s: Disabled CP regulator %d\n",
4345 __func__, i);
4346 }
4347 }
4348 break;
4349 }
4350 return 0;
4351}
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004352
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07004353static const struct snd_soc_dapm_widget tapan_9306_dapm_widgets[] = {
4354 /* RX4 MIX1 mux inputs */
4355 SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4356 &rx4_mix1_inp1_mux),
4357 SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4358 &rx4_mix1_inp2_mux),
4359 SND_SOC_DAPM_MUX("RX4 MIX1 INP3", SND_SOC_NOPM, 0, 0,
Santosh Mardi330ad2a2013-11-21 18:12:14 +05304360 &rx4_mix1_inp3_mux),
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07004361
4362 /* RX4 MIX2 mux inputs */
4363 SND_SOC_DAPM_MUX("RX4 MIX2 INP1", SND_SOC_NOPM, 0, 0,
4364 &rx4_mix2_inp1_mux),
4365 SND_SOC_DAPM_MUX("RX4 MIX2 INP2", SND_SOC_NOPM, 0, 0,
4366 &rx4_mix2_inp2_mux),
4367
4368 SND_SOC_DAPM_MIXER("RX4 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4369
4370 SND_SOC_DAPM_MIXER_E("RX4 MIX2", TAPAN_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL,
4371 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
4372 SND_SOC_DAPM_POST_PMU),
4373
4374 SND_SOC_DAPM_MUX_E("DEC3 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 2, 0,
4375 &dec3_mux, tapan_codec_enable_dec,
4376 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4377 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
4378
4379 SND_SOC_DAPM_MUX_E("DEC4 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 3, 0,
4380 &dec4_mux, tapan_codec_enable_dec,
4381 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4382 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
4383
4384 SND_SOC_DAPM_SUPPLY("COMP0_CLK", SND_SOC_NOPM, 0, 0,
4385 tapan_config_compander, SND_SOC_DAPM_PRE_PMU |
4386 SND_SOC_DAPM_PRE_PMD),
4387 SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 1, 0,
4388 tapan_config_compander, SND_SOC_DAPM_PRE_PMU |
4389 SND_SOC_DAPM_PRE_PMD),
4390 SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 2, 0,
4391 tapan_config_compander, SND_SOC_DAPM_PRE_PMU |
4392 SND_SOC_DAPM_PRE_PMD),
4393
4394 SND_SOC_DAPM_INPUT("AMIC5"),
4395 SND_SOC_DAPM_ADC_E("ADC5", NULL, TAPAN_A_TX_5_EN, 7, 0,
4396 tapan_codec_enable_adc, SND_SOC_DAPM_POST_PMU),
4397
4398 SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux),
4399 SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux),
4400
4401 SND_SOC_DAPM_OUTPUT("ANC HEADPHONE"),
4402 SND_SOC_DAPM_PGA_E("ANC HPHL", SND_SOC_NOPM, 5, 0, NULL, 0,
4403 tapan_codec_enable_anc_hph,
4404 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD |
4405 SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_POST_PMU),
4406 SND_SOC_DAPM_PGA_E("ANC HPHR", SND_SOC_NOPM, 4, 0, NULL, 0,
4407 tapan_codec_enable_anc_hph, SND_SOC_DAPM_PRE_PMU |
4408 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
4409 SND_SOC_DAPM_POST_PMU),
4410 SND_SOC_DAPM_OUTPUT("ANC EAR"),
4411 SND_SOC_DAPM_PGA_E("ANC EAR PA", SND_SOC_NOPM, 0, 0, NULL, 0,
4412 tapan_codec_enable_anc_ear,
4413 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD |
4414 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4415 SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux),
4416
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07004417 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", SND_SOC_NOPM, 7, 0,
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07004418 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4419 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07004420 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", SND_SOC_NOPM, 7, 0,
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07004421 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4422 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07004423 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", SND_SOC_NOPM, 7, 0,
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07004424 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4425 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4426
4427 SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0,
4428 tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4429 SND_SOC_DAPM_POST_PMD),
4430
4431 SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0,
4432 tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4433 SND_SOC_DAPM_POST_PMD),
4434};
4435
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004436/* Todo: Have seperate dapm widgets for I2S and Slimbus.
4437 * Might Need to have callbacks registered only for slimbus
4438 */
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07004439static const struct snd_soc_dapm_widget tapan_common_dapm_widgets[] = {
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004440
4441 SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM,
4442 AIF1_PB, 0, tapan_codec_enable_slimrx,
4443 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4444 SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM,
4445 AIF2_PB, 0, tapan_codec_enable_slimrx,
4446 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4447 SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM,
4448 AIF3_PB, 0, tapan_codec_enable_slimrx,
4449 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4450
4451 SND_SOC_DAPM_MUX("SLIM RX1 MUX", SND_SOC_NOPM, TAPAN_RX1, 0,
4452 &slim_rx_mux[TAPAN_RX1]),
4453 SND_SOC_DAPM_MUX("SLIM RX2 MUX", SND_SOC_NOPM, TAPAN_RX2, 0,
4454 &slim_rx_mux[TAPAN_RX2]),
4455 SND_SOC_DAPM_MUX("SLIM RX3 MUX", SND_SOC_NOPM, TAPAN_RX3, 0,
4456 &slim_rx_mux[TAPAN_RX3]),
4457 SND_SOC_DAPM_MUX("SLIM RX4 MUX", SND_SOC_NOPM, TAPAN_RX4, 0,
4458 &slim_rx_mux[TAPAN_RX4]),
4459 SND_SOC_DAPM_MUX("SLIM RX5 MUX", SND_SOC_NOPM, TAPAN_RX5, 0,
4460 &slim_rx_mux[TAPAN_RX5]),
4461
4462 SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4463 SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
4464 SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
4465 SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
4466 SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
4467
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004468
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004469 /* RX1 MIX1 mux inputs */
4470 SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4471 &rx_mix1_inp1_mux),
4472 SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4473 &rx_mix1_inp2_mux),
4474 SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0,
4475 &rx_mix1_inp3_mux),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004476
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004477 /* RX2 MIX1 mux inputs */
4478 SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4479 &rx2_mix1_inp1_mux),
4480 SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4481 &rx2_mix1_inp2_mux),
4482 SND_SOC_DAPM_MUX("RX2 MIX1 INP3", SND_SOC_NOPM, 0, 0,
4483 &rx2_mix1_inp2_mux),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004484
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004485 /* RX3 MIX1 mux inputs */
4486 SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0,
4487 &rx3_mix1_inp1_mux),
4488 SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0,
4489 &rx3_mix1_inp2_mux),
4490 SND_SOC_DAPM_MUX("RX3 MIX1 INP3", SND_SOC_NOPM, 0, 0,
4491 &rx3_mix1_inp2_mux),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004492
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004493 /* RX1 MIX2 mux inputs */
4494 SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0,
4495 &rx1_mix2_inp1_mux),
4496 SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0,
4497 &rx1_mix2_inp2_mux),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004498
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004499 /* RX2 MIX2 mux inputs */
4500 SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0,
4501 &rx2_mix2_inp1_mux),
4502 SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0,
4503 &rx2_mix2_inp2_mux),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004504
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004505 SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4506 SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4507
4508 SND_SOC_DAPM_MIXER_E("RX1 MIX2", TAPAN_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL,
4509 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
4510 SND_SOC_DAPM_POST_PMU),
4511 SND_SOC_DAPM_MIXER_E("RX2 MIX2", TAPAN_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL,
4512 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
4513 SND_SOC_DAPM_POST_PMU),
4514 SND_SOC_DAPM_MIXER_E("RX3 MIX1", TAPAN_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
4515 0, tapan_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
4516 SND_SOC_DAPM_POST_PMU),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004517
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004518 SND_SOC_DAPM_MIXER("RX1 CHAIN", TAPAN_A_CDC_RX1_B6_CTL, 5, 0,
4519 NULL, 0),
4520 SND_SOC_DAPM_MIXER("RX2 CHAIN", TAPAN_A_CDC_RX2_B6_CTL, 5, 0,
4521 NULL, 0),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004522
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004523 SND_SOC_DAPM_MUX_E("CLASS_H_DSM MUX", SND_SOC_NOPM, 0, 0,
4524 &class_h_dsm_mux, tapan_codec_dsm_mux_event,
4525 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004526
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004527 /* RX Bias */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004528 SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
4529 tapan_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
4530 SND_SOC_DAPM_POST_PMD),
4531
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07004532 /* CDC_CP_VDD */
4533 SND_SOC_DAPM_SUPPLY("CDC_CP_VDD", SND_SOC_NOPM, 0, 0,
4534 tapan_codec_chargepump_vdd_event, SND_SOC_DAPM_PRE_PMU |
4535 SND_SOC_DAPM_POST_PMD),
4536
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004537 /*EAR */
4538 SND_SOC_DAPM_PGA_E("EAR PA", TAPAN_A_RX_EAR_EN, 4, 0, NULL, 0,
4539 tapan_codec_enable_ear_pa, SND_SOC_DAPM_POST_PMU |
4540 SND_SOC_DAPM_POST_PMD),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004541
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004542 SND_SOC_DAPM_MIXER_E("DAC1", TAPAN_A_RX_EAR_EN, 6, 0, dac1_switch,
4543 ARRAY_SIZE(dac1_switch), tapan_codec_ear_dac_event,
4544 SND_SOC_DAPM_PRE_PMU),
4545
4546 /* Headphone Left */
4547 SND_SOC_DAPM_PGA_E("HPHL", TAPAN_A_RX_HPH_CNP_EN, 5, 0, NULL, 0,
4548 tapan_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
4549 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4550
4551 SND_SOC_DAPM_MIXER_E("HPHL DAC", TAPAN_A_RX_HPH_L_DAC_CTL, 7, 0,
4552 hphl_switch, ARRAY_SIZE(hphl_switch), tapan_hphl_dac_event,
4553 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4554
4555 /* Headphone Right */
4556 SND_SOC_DAPM_PGA_E("HPHR", TAPAN_A_RX_HPH_CNP_EN, 4, 0, NULL, 0,
4557 tapan_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
4558 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4559
4560 SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TAPAN_A_RX_HPH_R_DAC_CTL, 7, 0,
4561 tapan_hphr_dac_event,
4562 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4563
4564 /* LINEOUT1*/
4565 SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TAPAN_A_RX_LINE_1_DAC_CTL, 7, 0
4566 , tapan_lineout_dac_event,
4567 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4568
4569 SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TAPAN_A_RX_LINE_CNP_EN, 0, 0, NULL,
4570 0, tapan_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4571 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4572
4573 /* LINEOUT2*/
4574 SND_SOC_DAPM_MUX("RDAC5 MUX", SND_SOC_NOPM, 0, 0,
4575 &rx_dac5_mux),
4576
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07004577 /* LINEOUT1*/
4578 SND_SOC_DAPM_MUX("RDAC4 MUX", SND_SOC_NOPM, 0, 0,
4579 &rx_dac4_mux),
4580
4581 SND_SOC_DAPM_MUX("RDAC3 MUX", SND_SOC_NOPM, 0, 0,
4582 &rx_dac3_mux),
4583
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004584 SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TAPAN_A_RX_LINE_2_DAC_CTL, 7, 0
4585 , tapan_lineout_dac_event,
4586 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4587
4588 SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TAPAN_A_RX_LINE_CNP_EN, 1, 0, NULL,
4589 0, tapan_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4590 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4591
4592 /* CLASS-D SPK */
4593 SND_SOC_DAPM_MIXER_E("SPK DAC", SND_SOC_NOPM, 0, 0,
4594 spk_dac_switch, ARRAY_SIZE(spk_dac_switch), tapan_spk_dac_event,
4595 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4596
4597 SND_SOC_DAPM_PGA_E("SPK PA", SND_SOC_NOPM, 0, 0 , NULL,
4598 0, tapan_codec_enable_spk_pa,
4599 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4600
4601 SND_SOC_DAPM_SUPPLY("VDD_SPKDRV", SND_SOC_NOPM, 0, 0,
4602 tapan_codec_enable_vdd_spkr,
4603 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4604
4605 SND_SOC_DAPM_OUTPUT("EAR"),
4606 SND_SOC_DAPM_OUTPUT("HEADPHONE"),
4607 SND_SOC_DAPM_OUTPUT("LINEOUT1"),
4608 SND_SOC_DAPM_OUTPUT("LINEOUT2"),
4609 SND_SOC_DAPM_OUTPUT("SPK_OUT"),
4610
4611 /* TX Path*/
4612 SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0,
4613 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
4614
4615 SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0,
4616 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
4617
4618 SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0,
4619 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
4620
4621 SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, TAPAN_TX1, 0,
4622 &sb_tx1_mux),
4623 SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, TAPAN_TX2, 0,
4624 &sb_tx2_mux),
4625 SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, TAPAN_TX3, 0,
4626 &sb_tx3_mux),
4627 SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, TAPAN_TX4, 0,
4628 &sb_tx4_mux),
4629 SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, TAPAN_TX5, 0,
4630 &sb_tx5_mux),
4631
4632 SND_SOC_DAPM_SUPPLY("CDC_CONN", WCD9XXX_A_CDC_CLK_OTHR_CTL, 2, 0, NULL,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004633 0),
4634
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004635 /* Decimator MUX */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004636 SND_SOC_DAPM_MUX_E("DEC1 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0, 0,
4637 &dec1_mux, tapan_codec_enable_dec,
4638 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4639 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
4640
4641 SND_SOC_DAPM_MUX_E("DEC2 MUX", TAPAN_A_CDC_CLK_TX_CLK_EN_B1_CTL, 1, 0,
4642 &dec2_mux, tapan_codec_enable_dec,
4643 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4644 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
4645
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07004646 SND_SOC_DAPM_SUPPLY("LDO_H", SND_SOC_NOPM, 7, 0,
4647 tapan_codec_enable_ldo_h,
4648 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4649
4650 /*
4651 * DAPM 'LDO_H Standalone' is to be powered by mbhc driver after
4652 * acquring codec_resource lock.
4653 * So call __tapan_codec_enable_ldo_h instead and avoid deadlock.
4654 */
4655 SND_SOC_DAPM_SUPPLY("LDO_H Standalone", SND_SOC_NOPM, 7, 0,
4656 __tapan_codec_enable_ldo_h,
4657 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004658
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004659 SND_SOC_DAPM_INPUT("AMIC1"),
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07004660 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", SND_SOC_NOPM, 7, 0,
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004661 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4662 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07004663 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", SND_SOC_NOPM, 7, 0,
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004664 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4665 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07004666 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", SND_SOC_NOPM, 7, 0,
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004667 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4668 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4669
4670 SND_SOC_DAPM_ADC_E("ADC1", NULL, TAPAN_A_TX_1_EN, 7, 0,
4671 tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4672 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4673 SND_SOC_DAPM_ADC_E("ADC2", NULL, TAPAN_A_TX_2_EN, 7, 0,
4674 tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4675 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4676
4677 SND_SOC_DAPM_INPUT("AMIC3"),
4678 SND_SOC_DAPM_ADC_E("ADC3", NULL, TAPAN_A_TX_3_EN, 7, 0,
4679 tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4680 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4681
4682 SND_SOC_DAPM_INPUT("AMIC4"),
4683 SND_SOC_DAPM_ADC_E("ADC4", NULL, TAPAN_A_TX_4_EN, 7, 0,
4684 tapan_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
4685 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4686
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004687 SND_SOC_DAPM_INPUT("AMIC2"),
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07004688 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", SND_SOC_NOPM, 7, 0,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004689 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4690 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07004691 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", SND_SOC_NOPM, 7, 0,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004692 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4693 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07004694 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", SND_SOC_NOPM, 7, 0,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004695 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4696 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07004697 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", SND_SOC_NOPM, 7, 0,
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004698 tapan_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
4699 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004700
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07004701 SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS2_EXTERNAL_STANDALONE, SND_SOC_NOPM,
4702 7, 0, tapan_codec_enable_micbias,
4703 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
4704 SND_SOC_DAPM_POST_PMD),
4705
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004706 SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM,
4707 AIF1_CAP, 0, tapan_codec_enable_slimtx,
4708 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4709
4710 SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM,
4711 AIF2_CAP, 0, tapan_codec_enable_slimtx,
4712 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4713
4714 SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM,
4715 AIF3_CAP, 0, tapan_codec_enable_slimtx,
4716 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4717
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004718 /* Digital Mic Inputs */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004719 SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
4720 tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4721 SND_SOC_DAPM_POST_PMD),
4722
4723 SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
4724 tapan_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
4725 SND_SOC_DAPM_POST_PMD),
4726
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004727 /* Sidetone */
4728 SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux),
4729 SND_SOC_DAPM_PGA("IIR1", TAPAN_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0),
4730
4731 /* AUX PGA */
4732 SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TAPAN_A_RX_AUX_SW_CTL, 7, 0,
4733 tapan_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
4734 SND_SOC_DAPM_POST_PMD),
4735
4736 SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TAPAN_A_RX_AUX_SW_CTL, 6, 0,
4737 tapan_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
4738 SND_SOC_DAPM_POST_PMD),
4739
4740 /* Lineout, ear and HPH PA Mixers */
4741
4742 SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0,
4743 ear_pa_mix, ARRAY_SIZE(ear_pa_mix)),
4744
4745 SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0,
4746 hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)),
4747
4748 SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0,
4749 hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)),
4750
4751 SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0,
4752 lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)),
4753
4754 SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0,
4755 lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004756};
4757
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004758static irqreturn_t tapan_slimbus_irq(int irq, void *data)
4759{
4760 struct tapan_priv *priv = data;
4761 struct snd_soc_codec *codec = priv->codec;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004762 unsigned long status = 0;
4763 int i, j, port_id, k;
4764 u32 bit;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004765 u8 val;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004766 bool tx, cleared;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004767
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004768 for (i = TAPAN_SLIM_PGD_PORT_INT_STATUS_RX_0, j = 0;
4769 i <= TAPAN_SLIM_PGD_PORT_INT_STATUS_TX_1; i++, j++) {
4770 val = wcd9xxx_interface_reg_read(codec->control_data, i);
4771 status |= ((u32)val << (8 * j));
4772 }
4773
4774 for_each_set_bit(j, &status, 32) {
4775 tx = (j >= 16 ? true : false);
4776 port_id = (tx ? j - 16 : j);
4777 val = wcd9xxx_interface_reg_read(codec->control_data,
4778 TAPAN_SLIM_PGD_PORT_INT_RX_SOURCE0 + j);
4779 if (val & TAPAN_SLIM_IRQ_OVERFLOW)
4780 pr_err_ratelimited(
4781 "%s: overflow error on %s port %d, value %x\n",
4782 __func__, (tx ? "TX" : "RX"), port_id, val);
4783 if (val & TAPAN_SLIM_IRQ_UNDERFLOW)
4784 pr_err_ratelimited(
4785 "%s: underflow error on %s port %d, value %x\n",
4786 __func__, (tx ? "TX" : "RX"), port_id, val);
4787 if (val & TAPAN_SLIM_IRQ_PORT_CLOSED) {
4788 /*
4789 * INT SOURCE register starts from RX to TX
4790 * but port number in the ch_mask is in opposite way
4791 */
4792 bit = (tx ? j - 16 : j + 16);
4793 dev_dbg(codec->dev, "%s: %s port %d closed value %x, bit %u\n",
4794 __func__, (tx ? "TX" : "RX"), port_id, val,
4795 bit);
4796 for (k = 0, cleared = false; k < NUM_CODEC_DAIS; k++) {
4797 dev_dbg(codec->dev, "%s: priv->dai[%d].ch_mask = 0x%lx\n",
4798 __func__, k, priv->dai[k].ch_mask);
4799 if (test_and_clear_bit(bit,
4800 &priv->dai[k].ch_mask)) {
4801 cleared = true;
4802 if (!priv->dai[k].ch_mask)
4803 wake_up(&priv->dai[k].dai_wait);
4804 /*
4805 * There are cases when multiple DAIs
4806 * might be using the same slimbus
4807 * channel. Hence don't break here.
4808 */
4809 }
4810 }
4811 WARN(!cleared,
4812 "Couldn't find slimbus %s port %d for closing\n",
4813 (tx ? "TX" : "RX"), port_id);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004814 }
4815 wcd9xxx_interface_reg_write(codec->control_data,
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004816 TAPAN_SLIM_PGD_PORT_INT_CLR_RX_0 +
4817 (j / 8),
4818 1 << (j % 8));
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004819 }
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004820
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004821 return IRQ_HANDLED;
4822}
4823
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004824static int tapan_handle_pdata(struct tapan_priv *tapan)
4825{
4826 struct snd_soc_codec *codec = tapan->codec;
4827 struct wcd9xxx_pdata *pdata = tapan->resmgr.pdata;
4828 int k1, k2, k3, rc = 0;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004829 u8 txfe_bypass = pdata->amic_settings.txfe_enable;
4830 u8 txfe_buff = pdata->amic_settings.txfe_buff;
4831 u8 flag = pdata->amic_settings.use_pdata;
4832 u8 i = 0, j = 0;
4833 u8 val_txfe = 0, value = 0;
Damir Didjusto5f553e92013-10-02 14:54:31 -07004834 u8 dmic_sample_rate_value = 0;
4835 u8 dmic_b1_ctl_value = 0;
4836 u8 anc_ctl_value = 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004837
4838 if (!pdata) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004839 dev_err(codec->dev, "%s: NULL pdata\n", __func__);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004840 rc = -ENODEV;
4841 goto done;
4842 }
4843
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004844 /* Make sure settings are correct */
4845 if ((pdata->micbias.ldoh_v > WCD9XXX_LDOH_3P0_V) ||
4846 (pdata->micbias.bias1_cfilt_sel > WCD9XXX_CFILT3_SEL) ||
4847 (pdata->micbias.bias2_cfilt_sel > WCD9XXX_CFILT3_SEL) ||
4848 (pdata->micbias.bias3_cfilt_sel > WCD9XXX_CFILT3_SEL)) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004849 dev_err(codec->dev, "%s: Invalid ldoh voltage or bias cfilt\n",
4850 __func__);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004851 rc = -EINVAL;
4852 goto done;
4853 }
4854 /* figure out k value */
4855 k1 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt1_mv);
4856 k2 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt2_mv);
4857 k3 = wcd9xxx_resmgr_get_k_val(&tapan->resmgr, pdata->micbias.cfilt3_mv);
4858
4859 if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004860 dev_err(codec->dev,
4861 "%s: could not get K value. k1 = %d k2 = %d k3 = %d\n",
4862 __func__, k1, k2, k3);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004863 rc = -EINVAL;
4864 goto done;
4865 }
4866 /* Set voltage level and always use LDO */
4867 snd_soc_update_bits(codec, TAPAN_A_LDO_H_MODE_1, 0x0C,
4868 (pdata->micbias.ldoh_v << 2));
4869
4870 snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_1_VAL, 0xFC, (k1 << 2));
4871 snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_2_VAL, 0xFC, (k2 << 2));
4872 snd_soc_update_bits(codec, TAPAN_A_MICB_CFILT_3_VAL, 0xFC, (k3 << 2));
4873
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004874 i = 0;
4875 while (i < 5) {
4876 if (flag & (0x01 << i)) {
4877 val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00;
4878 val_txfe = val_txfe |
4879 ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00);
4880 snd_soc_update_bits(codec,
4881 TAPAN_A_TX_1_2_TEST_EN + j * 10,
4882 0x30, val_txfe);
4883 }
4884 if (flag & (0x01 << (i + 1))) {
4885 val_txfe = (txfe_bypass &
4886 (0x01 << (i + 1))) ? 0x02 : 0x00;
4887 val_txfe |= (txfe_buff &
4888 (0x01 << (i + 1))) ? 0x01 : 0x00;
4889 snd_soc_update_bits(codec,
4890 TAPAN_A_TX_1_2_TEST_EN + j * 10,
4891 0x03, val_txfe);
4892 }
4893 /* Tapan only has TAPAN_A_TX_1_2_TEST_EN and
4894 TAPAN_A_TX_4_5_TEST_EN reg */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004895
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004896 if (i == 0) {
4897 i = 3;
4898 continue;
4899 } else if (i == 3) {
4900 break;
4901 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004902 }
4903
4904 if (pdata->ocp.use_pdata) {
4905 /* not defined in CODEC specification */
4906 if (pdata->ocp.hph_ocp_limit == 1 ||
4907 pdata->ocp.hph_ocp_limit == 5) {
4908 rc = -EINVAL;
4909 goto done;
4910 }
4911 snd_soc_update_bits(codec, TAPAN_A_RX_COM_OCP_CTL,
4912 0x0F, pdata->ocp.num_attempts);
4913 snd_soc_write(codec, TAPAN_A_RX_COM_OCP_COUNT,
4914 ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time));
4915 snd_soc_update_bits(codec, TAPAN_A_RX_HPH_OCP_CTL,
4916 0xE0, (pdata->ocp.hph_ocp_limit << 5));
4917 }
4918
Bhalchandra Gajareea898742013-03-05 18:15:53 -08004919 /* Set micbias capless mode with tail current */
4920 value = (pdata->micbias.bias1_cap_mode == MICBIAS_EXT_BYP_CAP ?
4921 0x00 : 0x10);
4922 snd_soc_update_bits(codec, TAPAN_A_MICB_1_CTL, 0x10, value);
4923 value = (pdata->micbias.bias2_cap_mode == MICBIAS_EXT_BYP_CAP ?
4924 0x00 : 0x10);
4925 snd_soc_update_bits(codec, TAPAN_A_MICB_2_CTL, 0x10, value);
4926 value = (pdata->micbias.bias3_cap_mode == MICBIAS_EXT_BYP_CAP ?
4927 0x00 : 0x10);
4928 snd_soc_update_bits(codec, TAPAN_A_MICB_3_CTL, 0x10, value);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08004929
Damir Didjusto5f553e92013-10-02 14:54:31 -07004930 /* Set the DMIC sample rate */
4931 if (pdata->mclk_rate == TAPAN_MCLK_CLK_9P6MHZ) {
4932 switch (pdata->dmic_sample_rate) {
4933 case WCD9XXX_DMIC_SAMPLE_RATE_2P4MHZ:
4934 dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_4;
4935 dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_4;
4936 anc_ctl_value = WCD9XXX_ANC_DMIC_X2_OFF;
4937 break;
4938 case WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ:
4939 dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_2;
4940 dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_2;
4941 anc_ctl_value = WCD9XXX_ANC_DMIC_X2_ON;
4942 break;
4943 case WCD9XXX_DMIC_SAMPLE_RATE_3P2MHZ:
4944 case WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED:
4945 dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_3;
4946 dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_3;
4947 anc_ctl_value = WCD9XXX_ANC_DMIC_X2_OFF;
4948 break;
4949 default:
4950 dev_err(codec->dev,
4951 "%s Invalid sample rate %d for mclk %d\n",
4952 __func__, pdata->dmic_sample_rate,
4953 pdata->mclk_rate);
4954 rc = -EINVAL;
4955 goto done;
4956 }
4957 } else if (pdata->mclk_rate == TAPAN_MCLK_CLK_12P288MHZ) {
4958 switch (pdata->dmic_sample_rate) {
4959 case WCD9XXX_DMIC_SAMPLE_RATE_3P072MHZ:
4960 dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_4;
4961 dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_4;
4962 anc_ctl_value = WCD9XXX_ANC_DMIC_X2_OFF;
4963 break;
4964 case WCD9XXX_DMIC_SAMPLE_RATE_6P144MHZ:
4965 dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_2;
4966 dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_2;
4967 anc_ctl_value = WCD9XXX_ANC_DMIC_X2_ON;
4968 break;
4969 case WCD9XXX_DMIC_SAMPLE_RATE_4P096MHZ:
4970 case WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED:
4971 dmic_sample_rate_value = WCD9XXX_DMIC_SAMPLE_RATE_DIV_3;
4972 dmic_b1_ctl_value = WCD9XXX_DMIC_B1_CTL_DIV_3;
4973 anc_ctl_value = WCD9XXX_ANC_DMIC_X2_OFF;
4974 break;
4975 default:
4976 dev_err(codec->dev,
4977 "%s Invalid sample rate %d for mclk %d\n",
4978 __func__, pdata->dmic_sample_rate,
4979 pdata->mclk_rate);
4980 rc = -EINVAL;
4981 goto done;
4982 }
4983 } else {
4984 dev_err(codec->dev, "%s MCLK is not set!\n", __func__);
4985 rc = -EINVAL;
4986 goto done;
4987 }
4988
4989 snd_soc_update_bits(codec, TAPAN_A_CDC_TX1_DMIC_CTL,
4990 0x7, dmic_sample_rate_value);
4991 snd_soc_update_bits(codec, TAPAN_A_CDC_TX2_DMIC_CTL,
4992 0x7, dmic_sample_rate_value);
4993 snd_soc_update_bits(codec, TAPAN_A_CDC_TX3_DMIC_CTL,
4994 0x7, dmic_sample_rate_value);
4995 snd_soc_update_bits(codec, TAPAN_A_CDC_TX4_DMIC_CTL,
4996 0x7, dmic_sample_rate_value);
4997 snd_soc_update_bits(codec, TAPAN_A_CDC_CLK_DMIC_B1_CTL,
4998 0xEE, dmic_b1_ctl_value);
4999 snd_soc_update_bits(codec, TAPAN_A_CDC_ANC1_B2_CTL,
5000 0x1, anc_ctl_value);
5001
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005002done:
5003 return rc;
5004}
5005
5006static const struct tapan_reg_mask_val tapan_reg_defaults[] = {
5007
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005008 /* enable QFUSE for wcd9306 */
5009 TAPAN_REG_VAL(TAPAN_A_QFUSE_CTL, 0x03),
5010
5011 /* PROGRAM_THE_0P85V_VBG_REFERENCE = V_0P858V */
5012 TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x04),
5013
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005014 TAPAN_REG_VAL(TAPAN_A_CDC_CLK_POWER_CTL, 0x03),
5015
5016 /* EAR PA deafults */
5017 TAPAN_REG_VAL(TAPAN_A_RX_EAR_CMBUFF, 0x05),
5018
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005019 /* RX1 and RX2 defaults */
5020 TAPAN_REG_VAL(TAPAN_A_CDC_RX1_B6_CTL, 0xA0),
5021 TAPAN_REG_VAL(TAPAN_A_CDC_RX2_B6_CTL, 0xA0),
5022
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005023 /* Heaset set Right from RX2 */
5024 TAPAN_REG_VAL(TAPAN_A_CDC_CONN_RX2_B2_CTL, 0x10),
5025
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005026
5027 /*
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005028 * The following only need to be written for Tapan 1.0 parts.
5029 * Tapan 2.0 will have appropriate defaults for these registers.
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005030 */
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005031
5032 /* Required defaults for class H operation */
5033 /* borrowed from Taiko class-h */
5034 TAPAN_REG_VAL(TAPAN_A_RX_HPH_CHOP_CTL, 0xF4),
5035 TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x08),
5036 TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_1, 0x5B),
Banajit Goswamia7294452013-06-03 12:42:35 -07005037 TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_3, 0x6F),
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005038
5039 /* TODO: Check below reg writes conflict with above */
5040 /* PROGRAM_THE_0P85V_VBG_REFERENCE = V_0P858V */
5041 TAPAN_REG_VAL(TAPAN_A_BIAS_CURR_CTL_2, 0x04),
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005042 TAPAN_REG_VAL(TAPAN_A_RX_HPH_CHOP_CTL, 0x74),
5043 TAPAN_REG_VAL(TAPAN_A_RX_BUCK_BIAS1, 0x62),
5044
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005045 /* Choose max non-overlap time for NCP */
5046 TAPAN_REG_VAL(TAPAN_A_NCP_CLK, 0xFC),
5047 /* Use 25mV/50mV for deltap/m to reduce ripple */
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005048 TAPAN_REG_VAL(WCD9XXX_A_BUCK_CTRL_VCL_1, 0x08),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005049 /*
5050 * Set DISABLE_MODE_SEL<1:0> to 0b10 (disable PWM in auto mode).
5051 * Note that the other bits of this register will be changed during
5052 * Rx PA bring up.
5053 */
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005054 TAPAN_REG_VAL(WCD9XXX_A_BUCK_MODE_3, 0xCE),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005055 /* Reduce HPH DAC bias to 70% */
5056 TAPAN_REG_VAL(TAPAN_A_RX_HPH_BIAS_PA, 0x7A),
5057 /*Reduce EAR DAC bias to 70% */
5058 TAPAN_REG_VAL(TAPAN_A_RX_EAR_BIAS_PA, 0x76),
5059 /* Reduce LINE DAC bias to 70% */
5060 TAPAN_REG_VAL(TAPAN_A_RX_LINE_BIAS_PA, 0x78),
5061
5062 /*
5063 * There is a diode to pull down the micbias while doing
5064 * insertion detection. This diode can cause leakage.
5065 * Set bit 0 to 1 to prevent leakage.
5066 * Setting this bit of micbias 2 prevents leakage for all other micbias.
5067 */
5068 TAPAN_REG_VAL(TAPAN_A_MICB_2_MBHC, 0x41),
5069
Bhalchandra Gajare7c739522013-06-20 15:31:02 -07005070 /*
5071 * Default register settings to support dynamic change of
5072 * vdd_buck between 1.8 volts and 2.15 volts.
5073 */
5074 TAPAN_REG_VAL(TAPAN_A_BUCK_MODE_2, 0xAA),
5075
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005076};
5077
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005078static const struct tapan_reg_mask_val tapan_2_x_reg_reset_values[] = {
5079
5080 TAPAN_REG_VAL(TAPAN_A_TX_7_MBHC_EN, 0x6C),
5081 TAPAN_REG_VAL(TAPAN_A_BUCK_CTRL_CCL_4, 0x51),
5082 TAPAN_REG_VAL(TAPAN_A_RX_HPH_CNP_WG_CTL, 0xDA),
5083 TAPAN_REG_VAL(TAPAN_A_RX_EAR_CNP, 0xC0),
5084 TAPAN_REG_VAL(TAPAN_A_RX_LINE_1_TEST, 0x02),
5085 TAPAN_REG_VAL(TAPAN_A_RX_LINE_2_TEST, 0x02),
5086 TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_OCP_CTL, 0x97),
5087 TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_CLIP_DET, 0x01),
5088 TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_IEC, 0x00),
5089 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B1_CTL, 0xE4),
5090 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B2_CTL, 0x00),
5091 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_B3_CTL, 0x00),
5092 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_BUCK_NCP_VARS, 0x00),
5093 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_HD_EAR, 0x00),
5094 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_HD_HPH, 0x00),
5095 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_MIN_EAR, 0x00),
5096 TAPAN_REG_VAL(TAPAN_A_CDC_CLSH_V_PA_MIN_HPH, 0x00),
5097};
5098
5099static const struct tapan_reg_mask_val tapan_1_0_reg_defaults[] = {
5100 /* Close leakage on the spkdrv */
5101 TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_DBG_PWRSTG, 0x24),
5102 TAPAN_REG_VAL(TAPAN_A_SPKR_DRV_DBG_DAC, 0xE5),
5103
5104};
5105
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005106static void tapan_update_reg_defaults(struct snd_soc_codec *codec)
5107{
5108 u32 i;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005109 struct wcd9xxx *tapan_core = dev_get_drvdata(codec->dev->parent);
5110
5111 if (!TAPAN_IS_1_0(tapan_core->version)) {
5112 for (i = 0; i < ARRAY_SIZE(tapan_2_x_reg_reset_values); i++)
5113 snd_soc_write(codec, tapan_2_x_reg_reset_values[i].reg,
5114 tapan_2_x_reg_reset_values[i].val);
5115 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005116
5117 for (i = 0; i < ARRAY_SIZE(tapan_reg_defaults); i++)
5118 snd_soc_write(codec, tapan_reg_defaults[i].reg,
5119 tapan_reg_defaults[i].val);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005120
5121 if (TAPAN_IS_1_0(tapan_core->version)) {
5122 for (i = 0; i < ARRAY_SIZE(tapan_1_0_reg_defaults); i++)
5123 snd_soc_write(codec, tapan_1_0_reg_defaults[i].reg,
5124 tapan_1_0_reg_defaults[i].val);
5125 }
5126
5127 if (!TAPAN_IS_1_0(tapan_core->version))
5128 spkr_drv_wrnd = -1;
5129 else if (spkr_drv_wrnd == 1)
5130 snd_soc_write(codec, TAPAN_A_SPKR_DRV_EN, 0xEF);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005131}
5132
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005133static void tapan_update_reg_mclk_rate(struct wcd9xxx *wcd9xxx)
5134{
5135 struct snd_soc_codec *codec;
5136
5137 codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
5138 dev_dbg(codec->dev, "%s: MCLK Rate = %x\n",
5139 __func__, wcd9xxx->mclk_rate);
5140
5141 if (wcd9xxx->mclk_rate == TAPAN_MCLK_CLK_12P288MHZ) {
5142 snd_soc_update_bits(codec, TAPAN_A_CHIP_CTL, 0x06, 0x0);
5143 snd_soc_update_bits(codec, TAPAN_A_RX_COM_TIMER_DIV, 0x01,
5144 0x01);
5145 } else if (wcd9xxx->mclk_rate == TAPAN_MCLK_CLK_9P6MHZ) {
5146 snd_soc_update_bits(codec, TAPAN_A_CHIP_CTL, 0x06, 0x2);
5147 }
5148}
5149
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005150static const struct tapan_reg_mask_val tapan_codec_reg_init_val[] = {
Phani Kumar Uppalapatieca9a102013-06-18 11:02:38 -07005151 /* Initialize current threshold to 365MA
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005152 * number of wait and run cycles to 4096
5153 */
Phani Kumar Uppalapatieca9a102013-06-18 11:02:38 -07005154 {TAPAN_A_RX_HPH_OCP_CTL, 0xE9, 0x69},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005155 {TAPAN_A_RX_COM_OCP_COUNT, 0xFF, 0xFF},
Phani Kumar Uppalapatieca9a102013-06-18 11:02:38 -07005156 {TAPAN_A_RX_HPH_L_TEST, 0x01, 0x01},
5157 {TAPAN_A_RX_HPH_R_TEST, 0x01, 0x01},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005158
5159 /* Initialize gain registers to use register gain */
5160 {TAPAN_A_RX_HPH_L_GAIN, 0x20, 0x20},
5161 {TAPAN_A_RX_HPH_R_GAIN, 0x20, 0x20},
5162 {TAPAN_A_RX_LINE_1_GAIN, 0x20, 0x20},
5163 {TAPAN_A_RX_LINE_2_GAIN, 0x20, 0x20},
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005164 {TAPAN_A_SPKR_DRV_GAIN, 0x04, 0x04},
5165
5166 /* Set RDAC5 MUX to take input from DEM3_INV.
5167 * This sets LO2 DAC to get input from DEM3_INV
5168 * for LO1 and LO2 to work as differential outputs.
5169 */
5170 {TAPAN_A_CDC_CONN_MISC, 0x04, 0x04},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005171
5172 /* CLASS H config */
5173 {TAPAN_A_CDC_CONN_CLSH_CTL, 0x3C, 0x14},
5174
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005175 /* Use 16 bit sample size for TX1 to TX5 */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005176 {TAPAN_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20},
5177 {TAPAN_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20},
5178 {TAPAN_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20},
5179 {TAPAN_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20},
5180 {TAPAN_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20},
5181
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005182 /* Disable SPK SWITCH */
5183 {TAPAN_A_SPKR_DRV_DAC_CTL, 0x04, 0x00},
5184
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005185 /* Use 16 bit sample size for RX */
5186 {TAPAN_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA},
5187 {TAPAN_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0x2A},
5188
5189 /*enable HPF filter for TX paths */
5190 {TAPAN_A_CDC_TX1_MUX_CTL, 0x8, 0x0},
5191 {TAPAN_A_CDC_TX2_MUX_CTL, 0x8, 0x0},
5192 {TAPAN_A_CDC_TX3_MUX_CTL, 0x8, 0x0},
5193 {TAPAN_A_CDC_TX4_MUX_CTL, 0x8, 0x0},
5194
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005195 /* Compander zone selection */
5196 {TAPAN_A_CDC_COMP0_B4_CTL, 0x3F, 0x37},
5197 {TAPAN_A_CDC_COMP1_B4_CTL, 0x3F, 0x37},
5198 {TAPAN_A_CDC_COMP2_B4_CTL, 0x3F, 0x37},
5199 {TAPAN_A_CDC_COMP0_B5_CTL, 0x7F, 0x7F},
5200 {TAPAN_A_CDC_COMP1_B5_CTL, 0x7F, 0x7F},
5201 {TAPAN_A_CDC_COMP2_B5_CTL, 0x7F, 0x7F},
Banajit Goswamia7294452013-06-03 12:42:35 -07005202
5203 /*
5204 * Setup wavegen timer to 20msec and disable chopper
5205 * as default. This corresponds to Compander OFF
5206 */
5207 {TAPAN_A_RX_HPH_CNP_WG_CTL, 0xFF, 0xDB},
5208 {TAPAN_A_RX_HPH_CNP_WG_TIME, 0xFF, 0x58},
5209 {TAPAN_A_RX_HPH_BIAS_WG_OCP, 0xFF, 0x1A},
5210 {TAPAN_A_RX_HPH_CHOP_CTL, 0xFF, 0x24},
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005211};
5212
Damir Didjustod6aea992013-09-03 21:18:59 -07005213void *tapan_get_afe_config(struct snd_soc_codec *codec,
5214 enum afe_config_type config_type)
5215{
5216 struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
5217
5218 switch (config_type) {
5219 case AFE_SLIMBUS_SLAVE_CONFIG:
5220 return &priv->slimbus_slave_cfg;
5221 case AFE_CDC_REGISTERS_CONFIG:
5222 return &tapan_audio_reg_cfg;
5223 case AFE_AANC_VERSION:
5224 return &tapan_cdc_aanc_version;
5225 default:
5226 pr_err("%s: Unknown config_type 0x%x\n", __func__, config_type);
5227 return NULL;
5228 }
5229}
5230
5231static void tapan_init_slim_slave_cfg(struct snd_soc_codec *codec)
5232{
5233 struct tapan_priv *priv = snd_soc_codec_get_drvdata(codec);
5234 struct afe_param_cdc_slimbus_slave_cfg *cfg;
5235 struct wcd9xxx *wcd9xxx = codec->control_data;
5236 uint64_t eaddr = 0;
5237
5238 pr_debug("%s\n", __func__);
5239 cfg = &priv->slimbus_slave_cfg;
5240 cfg->minor_version = 1;
5241 cfg->tx_slave_port_offset = 0;
5242 cfg->rx_slave_port_offset = 16;
5243
5244 memcpy(&eaddr, &wcd9xxx->slim->e_addr, sizeof(wcd9xxx->slim->e_addr));
5245 /* e-addr is 6-byte elemental address of the device */
5246 WARN_ON(sizeof(wcd9xxx->slim->e_addr) != 6);
5247 cfg->device_enum_addr_lsw = eaddr & 0xFFFFFFFF;
5248 cfg->device_enum_addr_msw = eaddr >> 32;
5249
5250 pr_debug("%s: slimbus logical address 0x%llx\n", __func__, eaddr);
5251}
5252
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005253static void tapan_codec_init_reg(struct snd_soc_codec *codec)
5254{
5255 u32 i;
5256
5257 for (i = 0; i < ARRAY_SIZE(tapan_codec_reg_init_val); i++)
5258 snd_soc_update_bits(codec, tapan_codec_reg_init_val[i].reg,
5259 tapan_codec_reg_init_val[i].mask,
5260 tapan_codec_reg_init_val[i].val);
5261}
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005262static void tapan_slim_interface_init_reg(struct snd_soc_codec *codec)
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005263{
5264 int i;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005265
5266 for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++)
5267 wcd9xxx_interface_reg_write(codec->control_data,
5268 TAPAN_SLIM_PGD_PORT_INT_EN0 + i,
5269 0xFF);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005270}
5271
5272static int tapan_setup_irqs(struct tapan_priv *tapan)
5273{
5274 int ret = 0;
5275 struct snd_soc_codec *codec = tapan->codec;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005276 struct wcd9xxx *wcd9xxx = codec->control_data;
5277 struct wcd9xxx_core_resource *core_res = &wcd9xxx->core_res;
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005278
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005279 ret = wcd9xxx_request_irq(core_res, WCD9XXX_IRQ_SLIMBUS,
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005280 tapan_slimbus_irq, "SLIMBUS Slave", tapan);
5281 if (ret)
5282 pr_err("%s: Failed to request irq %d\n", __func__,
5283 WCD9XXX_IRQ_SLIMBUS);
5284 else
5285 tapan_slim_interface_init_reg(codec);
5286
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005287 return ret;
5288}
5289
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07005290static void tapan_cleanup_irqs(struct tapan_priv *tapan)
5291{
5292 struct snd_soc_codec *codec = tapan->codec;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005293 struct wcd9xxx *wcd9xxx = codec->control_data;
5294 struct wcd9xxx_core_resource *core_res = &wcd9xxx->core_res;
5295 wcd9xxx_free_irq(core_res, WCD9XXX_IRQ_SLIMBUS, tapan);
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07005296}
5297
Simmi Pateriya95466b12013-05-09 20:08:46 +05305298
5299static void tapan_enable_mux_bias_block(struct snd_soc_codec *codec)
5300{
5301 snd_soc_update_bits(codec, WCD9XXX_A_MBHC_SCALING_MUX_1,
5302 0x80, 0x00);
5303}
5304
5305static void tapan_put_cfilt_fast_mode(struct snd_soc_codec *codec,
5306 struct wcd9xxx_mbhc *mbhc)
5307{
5308 snd_soc_update_bits(codec, mbhc->mbhc_bias_regs.cfilt_ctl,
5309 0x30, 0x30);
5310}
5311
5312static void tapan_codec_specific_cal_setup(struct snd_soc_codec *codec,
5313 struct wcd9xxx_mbhc *mbhc)
5314{
5315 snd_soc_update_bits(codec, WCD9XXX_A_CDC_MBHC_B1_CTL,
Phani Kumar Uppalapati10754402013-07-12 22:48:45 -07005316 0x04, 0x04);
Simmi Pateriya95466b12013-05-09 20:08:46 +05305317 snd_soc_update_bits(codec, WCD9XXX_A_TX_7_MBHC_EN, 0xE0, 0xE0);
5318}
5319
Simmi Pateriya95466b12013-05-09 20:08:46 +05305320static struct wcd9xxx_cfilt_mode tapan_codec_switch_cfilt_mode(
5321 struct wcd9xxx_mbhc *mbhc,
5322 bool fast)
5323{
5324 struct snd_soc_codec *codec = mbhc->codec;
5325 struct wcd9xxx_cfilt_mode cfilt_mode;
5326
5327 if (fast)
5328 cfilt_mode.reg_mode_val = WCD9XXX_CFILT_EXT_PRCHG_EN;
5329 else
5330 cfilt_mode.reg_mode_val = WCD9XXX_CFILT_EXT_PRCHG_DSBL;
5331
5332 cfilt_mode.cur_mode_val =
5333 snd_soc_read(codec, mbhc->mbhc_bias_regs.cfilt_ctl) & 0x30;
Bhalchandra Gajare8e5fe252013-07-15 19:42:21 -07005334 cfilt_mode.reg_mask = 0x30;
5335
Simmi Pateriya95466b12013-05-09 20:08:46 +05305336 return cfilt_mode;
5337}
5338
5339static void tapan_select_cfilt(struct snd_soc_codec *codec,
5340 struct wcd9xxx_mbhc *mbhc)
5341{
5342 snd_soc_update_bits(codec, mbhc->mbhc_bias_regs.ctl_reg, 0x60, 0x00);
5343}
5344
Bhalchandra Gajare8e5fe252013-07-15 19:42:21 -07005345enum wcd9xxx_cdc_type tapan_get_cdc_type(void)
5346{
5347 return WCD9XXX_CDC_TYPE_TAPAN;
Simmi Pateriya95466b12013-05-09 20:08:46 +05305348}
5349
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -07005350static void wcd9xxx_prepare_hph_pa(struct wcd9xxx_mbhc *mbhc,
5351 struct list_head *lh)
5352{
5353 int i;
5354 struct snd_soc_codec *codec = mbhc->codec;
5355 u32 delay;
5356
5357 const struct wcd9xxx_reg_mask_val reg_set_paon[] = {
5358 {WCD9XXX_A_CDC_CLSH_B1_CTL, 0x0F, 0x00},
5359 {WCD9XXX_A_RX_HPH_CHOP_CTL, 0xFF, 0xA4},
5360 {WCD9XXX_A_RX_HPH_OCP_CTL, 0xFF, 0x67},
5361 {WCD9XXX_A_RX_HPH_L_TEST, 0x1, 0x0},
5362 {WCD9XXX_A_RX_HPH_R_TEST, 0x1, 0x0},
5363 {WCD9XXX_A_RX_HPH_BIAS_WG_OCP, 0xFF, 0x1A},
5364 {WCD9XXX_A_RX_HPH_CNP_WG_CTL, 0xFF, 0xDB},
5365 {WCD9XXX_A_RX_HPH_CNP_WG_TIME, 0xFF, 0x2A},
5366 {TAPAN_A_CDC_CONN_RX2_B2_CTL, 0xFF, 0x10},
5367 {WCD9XXX_A_CDC_CLK_OTHR_CTL, 0xFF, 0x05},
5368 {WCD9XXX_A_CDC_RX1_B6_CTL, 0xFF, 0x81},
5369 {WCD9XXX_A_CDC_CLK_RX_B1_CTL, 0x03, 0x03},
5370 {WCD9XXX_A_RX_HPH_L_GAIN, 0xFF, 0x2C},
5371 {WCD9XXX_A_CDC_RX2_B6_CTL, 0xFF, 0x81},
5372 {WCD9XXX_A_RX_HPH_R_GAIN, 0xFF, 0x2C},
5373 {WCD9XXX_A_BUCK_CTRL_CCL_4, 0xFF, 0x50},
5374 {WCD9XXX_A_BUCK_CTRL_VCL_1, 0xFF, 0x08},
5375 {WCD9XXX_A_BUCK_CTRL_CCL_1, 0xFF, 0x5B},
5376 {WCD9XXX_A_NCP_CLK, 0xFF, 0x9C},
5377 {WCD9XXX_A_NCP_CLK, 0xFF, 0xFC},
5378 {WCD9XXX_A_BUCK_MODE_3, 0xFF, 0xCE},
5379 {WCD9XXX_A_BUCK_CTRL_CCL_3, 0xFF, 0x6B},
5380 {WCD9XXX_A_BUCK_CTRL_CCL_3, 0xFF, 0x6F},
5381 {TAPAN_A_RX_BUCK_BIAS1, 0xFF, 0x62},
5382 {TAPAN_A_RX_HPH_BIAS_PA, 0xFF, 0x7A},
5383 {TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, 0xFF, 0x02},
5384 {TAPAN_A_CDC_CLK_RDAC_CLK_EN_CTL, 0xFF, 0x06},
5385 {WCD9XXX_A_RX_COM_BIAS, 0xFF, 0x80},
5386 {WCD9XXX_A_BUCK_MODE_3, 0xFF, 0xC6},
5387 {WCD9XXX_A_BUCK_MODE_4, 0xFF, 0xE6},
5388 {WCD9XXX_A_BUCK_MODE_5, 0xFF, 0x02},
5389 {WCD9XXX_A_BUCK_MODE_1, 0xFF, 0xA1},
5390 /* Delay 1ms */
5391 {WCD9XXX_A_NCP_EN, 0xFF, 0xFF},
5392 /* Delay 1ms */
5393 {WCD9XXX_A_BUCK_MODE_5, 0xFF, 0x03},
5394 {WCD9XXX_A_BUCK_MODE_5, 0xFF, 0x7B},
5395 {WCD9XXX_A_CDC_CLSH_B1_CTL, 0xFF, 0xE6},
5396 {WCD9XXX_A_RX_HPH_L_DAC_CTL, 0xFF, 0x40},
5397 {WCD9XXX_A_RX_HPH_L_DAC_CTL, 0xFF, 0xC0},
5398 {WCD9XXX_A_RX_HPH_R_DAC_CTL, 0xFF, 0x40},
5399 {WCD9XXX_A_RX_HPH_R_DAC_CTL, 0xFF, 0xC0},
5400 {WCD9XXX_A_NCP_STATIC, 0xFF, 0x08},
5401 {WCD9XXX_A_RX_HPH_L_DAC_CTL, 0x03, 0x01},
5402 {WCD9XXX_A_RX_HPH_R_DAC_CTL, 0x03, 0x01},
5403 };
5404
5405 /*
5406 * Configure PA in class-AB, -18dB gain,
5407 * companding off, OCP off, Chopping ON
5408 */
5409 for (i = 0; i < ARRAY_SIZE(reg_set_paon); i++) {
5410 /*
5411 * Some of the codec registers like BUCK_MODE_1
5412 * and NCP_EN requires 1ms wait time for them
5413 * to take effect. Other register writes for
5414 * PA configuration do not require any wait time.
5415 */
5416 if (reg_set_paon[i].reg == WCD9XXX_A_BUCK_MODE_1 ||
5417 reg_set_paon[i].reg == WCD9XXX_A_NCP_EN)
5418 delay = 1000;
5419 else
5420 delay = 0;
5421 wcd9xxx_soc_update_bits_push(codec, lh,
5422 reg_set_paon[i].reg,
5423 reg_set_paon[i].mask,
5424 reg_set_paon[i].val, delay);
5425 }
5426 pr_debug("%s: PAs are prepared\n", __func__);
5427 return;
5428}
5429
5430static int wcd9xxx_enable_static_pa(struct wcd9xxx_mbhc *mbhc, bool enable)
5431{
5432 struct snd_soc_codec *codec = mbhc->codec;
5433 int wg_time = snd_soc_read(codec, WCD9XXX_A_RX_HPH_CNP_WG_TIME) *
5434 TAPAN_WG_TIME_FACTOR_US;
5435 /*
5436 * Tapan requires additional time to enable PA.
5437 * It is observed during experiments that we need
5438 * an additional wait time about 0.35 times of
5439 * the WG_TIME
5440 */
5441 wg_time += (int) (wg_time * 35) / 100;
5442
5443 snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_CNP_EN, 0x30,
5444 enable ? 0x30 : 0x0);
5445 /* Wait for wave gen time to avoid pop noise */
5446 usleep_range(wg_time, wg_time + WCD9XXX_USLEEP_RANGE_MARGIN_US);
5447 pr_debug("%s: PAs are %s as static mode (wg_time %d)\n", __func__,
5448 enable ? "enabled" : "disabled", wg_time);
5449 return 0;
5450}
5451
5452static int tapan_setup_zdet(struct wcd9xxx_mbhc *mbhc,
5453 enum mbhc_impedance_detect_stages stage)
5454{
5455
5456 int ret = 0;
5457 struct snd_soc_codec *codec = mbhc->codec;
5458 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
5459 const int mux_wait_us = 25;
5460
5461 switch (stage) {
5462
5463 case PRE_MEAS:
5464 INIT_LIST_HEAD(&tapan->reg_save_restore);
5465 /* Configure PA */
5466 wcd9xxx_prepare_hph_pa(mbhc, &tapan->reg_save_restore);
5467
5468#define __wr(reg, mask, value) \
5469 do { \
5470 ret = wcd9xxx_soc_update_bits_push(codec, \
5471 &tapan->reg_save_restore, \
5472 reg, mask, value, 0); \
5473 if (ret < 0) \
5474 return ret; \
5475 } while (0)
5476
5477 /* Setup MBHC */
5478 __wr(WCD9XXX_A_MBHC_SCALING_MUX_1, 0x7F, 0x40);
5479 __wr(WCD9XXX_A_MBHC_SCALING_MUX_2, 0xFF, 0xF0);
5480 __wr(WCD9XXX_A_TX_7_MBHC_TEST_CTL, 0xFF, 0x78);
5481 __wr(WCD9XXX_A_TX_7_MBHC_EN, 0xFF, 0xEC);
5482 __wr(WCD9XXX_A_CDC_MBHC_TIMER_B4_CTL, 0xFF, 0x45);
5483 __wr(WCD9XXX_A_CDC_MBHC_TIMER_B5_CTL, 0xFF, 0x80);
5484
5485 __wr(WCD9XXX_A_CDC_MBHC_CLK_CTL, 0xFF, 0x0A);
5486 snd_soc_write(codec, WCD9XXX_A_CDC_MBHC_EN_CTL, 0x2);
5487 __wr(WCD9XXX_A_CDC_MBHC_CLK_CTL, 0xFF, 0x02);
5488
5489 /* Enable Impedance Detection */
5490 __wr(WCD9XXX_A_MBHC_HPH, 0xFF, 0xC8);
5491
5492 /*
5493 * CnP setup for 0mV
5494 * Route static data as input to noise shaper
5495 */
5496 __wr(TAPAN_A_CDC_RX1_B3_CTL, 0xFF, 0x02);
5497 __wr(TAPAN_A_CDC_RX2_B3_CTL, 0xFF, 0x02);
5498
5499 snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_L_TEST,
5500 0x02, 0x00);
5501 snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_R_TEST,
5502 0x02, 0x00);
5503
5504 /* Reset the HPHL static data pointer */
5505 __wr(TAPAN_A_CDC_RX1_B2_CTL, 0xFF, 0x00);
5506 /* Four consecutive writes to set 0V as static data input */
5507 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
5508 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
5509 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
5510 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
5511
5512 /* Reset the HPHR static data pointer */
5513 __wr(TAPAN_A_CDC_RX2_B2_CTL, 0xFF, 0x00);
5514 /* Four consecutive writes to set 0V as static data input */
5515 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
5516 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
5517 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
5518 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
5519
5520 /* Enable the HPHL and HPHR PA */
5521 wcd9xxx_enable_static_pa(mbhc, true);
5522 break;
5523 case POST_MEAS:
5524 /* Turn off ICAL */
5525 snd_soc_write(codec, WCD9XXX_A_MBHC_SCALING_MUX_2, 0xF0);
5526
5527 wcd9xxx_enable_static_pa(mbhc, false);
5528
5529 /*
5530 * Setup CnP wavegen to ramp to the desired
5531 * output using a 40ms ramp
5532 */
5533
5534 /* CnP wavegen current to 0.5uA */
5535 snd_soc_write(codec, WCD9XXX_A_RX_HPH_BIAS_WG_OCP, 0x1A);
5536 /* Set the current division ratio to 2000 */
5537 snd_soc_write(codec, WCD9XXX_A_RX_HPH_CNP_WG_CTL, 0xDF);
5538 /* Set the wavegen timer to max (60msec) */
5539 snd_soc_write(codec, WCD9XXX_A_RX_HPH_CNP_WG_TIME, 0xA0);
5540 /* Set the CnP reference current to sc_bias */
5541 snd_soc_write(codec, WCD9XXX_A_RX_HPH_OCP_CTL, 0x6D);
5542
5543 snd_soc_write(codec, TAPAN_A_CDC_RX1_B2_CTL, 0x00);
5544 /* Four consecutive writes to set -10mV as static data input */
5545 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x00);
5546 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x1F);
5547 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0x19);
5548 snd_soc_write(codec, TAPAN_A_CDC_RX1_B1_CTL, 0xAA);
5549
5550 snd_soc_write(codec, TAPAN_A_CDC_RX2_B2_CTL, 0x00);
5551 /* Four consecutive writes to set -10mV as static data input */
5552 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x00);
5553 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x1F);
5554 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0x19);
5555 snd_soc_write(codec, TAPAN_A_CDC_RX2_B1_CTL, 0xAA);
5556
5557 snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_L_TEST,
5558 0x02, 0x02);
5559 snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_R_TEST,
5560 0x02, 0x02);
5561 /* Enable the HPHL and HPHR PA and wait for 60mS */
5562 wcd9xxx_enable_static_pa(mbhc, true);
5563
5564 snd_soc_update_bits(codec, WCD9XXX_A_MBHC_SCALING_MUX_1,
5565 0x7F, 0x40);
5566 usleep_range(mux_wait_us,
5567 mux_wait_us + WCD9XXX_USLEEP_RANGE_MARGIN_US);
5568 break;
5569 case PA_DISABLE:
Sudheer Papothi3fb420b2013-12-05 05:30:15 +05305570 if (!mbhc->hph_pa_dac_state)
5571 wcd9xxx_enable_static_pa(mbhc, false);
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -07005572 wcd9xxx_restore_registers(codec, &tapan->reg_save_restore);
5573 break;
5574 }
5575#undef __wr
5576
5577 return ret;
5578}
5579
5580static void tapan_compute_impedance(s16 *l, s16 *r, uint32_t *zl, uint32_t *zr)
5581{
5582 int zln, zld;
5583 int zrn, zrd;
5584 int rl = 0, rr = 0;
5585
5586 zln = (l[1] - l[0]) * TAPAN_ZDET_MUL_FACTOR;
5587 zld = (l[2] - l[0]);
5588 if (zld)
5589 rl = zln / zld;
5590
5591 zrn = (r[1] - r[0]) * TAPAN_ZDET_MUL_FACTOR;
5592 zrd = (r[2] - r[0]);
5593 if (zrd)
5594 rr = zrn / zrd;
5595
5596 *zl = rl;
5597 *zr = rr;
5598}
5599
Simmi Pateriya95466b12013-05-09 20:08:46 +05305600static const struct wcd9xxx_mbhc_cb mbhc_cb = {
5601 .enable_mux_bias_block = tapan_enable_mux_bias_block,
5602 .cfilt_fast_mode = tapan_put_cfilt_fast_mode,
5603 .codec_specific_cal = tapan_codec_specific_cal_setup,
Simmi Pateriya95466b12013-05-09 20:08:46 +05305604 .switch_cfilt_mode = tapan_codec_switch_cfilt_mode,
5605 .select_cfilt = tapan_select_cfilt,
Bhalchandra Gajare8e5fe252013-07-15 19:42:21 -07005606 .get_cdc_type = tapan_get_cdc_type,
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -07005607 .setup_zdet = tapan_setup_zdet,
5608 .compute_impedance = tapan_compute_impedance,
Simmi Pateriya95466b12013-05-09 20:08:46 +05305609};
5610
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005611int tapan_hs_detect(struct snd_soc_codec *codec,
5612 struct wcd9xxx_mbhc_config *mbhc_cfg)
5613{
5614 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
5615 return wcd9xxx_mbhc_start(&tapan->mbhc, mbhc_cfg);
5616}
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005617EXPORT_SYMBOL(tapan_hs_detect);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005618
Joonwoo Parke7d724e2013-08-19 15:51:01 -07005619void tapan_hs_detect_exit(struct snd_soc_codec *codec)
5620{
5621 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
5622 wcd9xxx_mbhc_stop(&tapan->mbhc);
5623}
5624EXPORT_SYMBOL(tapan_hs_detect_exit);
5625
Damir Didjustod6aea992013-09-03 21:18:59 -07005626void tapan_event_register(
5627 int (*machine_event_cb)(struct snd_soc_codec *codec,
5628 enum wcd9xxx_codec_event),
5629 struct snd_soc_codec *codec)
5630{
5631 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
5632 tapan->machine_codec_event_cb = machine_event_cb;
5633}
5634EXPORT_SYMBOL(tapan_event_register);
5635
Joonwoo Park8ffa2812013-08-07 19:01:30 -07005636static int tapan_device_down(struct wcd9xxx *wcd9xxx)
5637{
5638 struct snd_soc_codec *codec;
5639
5640 codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
5641 snd_soc_card_change_online_state(codec->card, 0);
5642
5643 return 0;
5644}
5645
Bhalchandra Gajare16748932013-10-01 18:16:05 -07005646static const struct wcd9xxx_mbhc_intr cdc_intr_ids = {
5647 .poll_plug_rem = WCD9XXX_IRQ_MBHC_REMOVAL,
5648 .shortavg_complete = WCD9XXX_IRQ_MBHC_SHORT_TERM,
5649 .potential_button_press = WCD9XXX_IRQ_MBHC_PRESS,
5650 .button_release = WCD9XXX_IRQ_MBHC_RELEASE,
5651 .dce_est_complete = WCD9XXX_IRQ_MBHC_POTENTIAL,
5652 .insertion = WCD9XXX_IRQ_MBHC_INSERTION,
5653 .hph_left_ocp = WCD9306_IRQ_HPH_PA_OCPL_FAULT,
5654 .hph_right_ocp = WCD9306_IRQ_HPH_PA_OCPR_FAULT,
5655 .hs_jack_switch = WCD9306_IRQ_MBHC_JACK_SWITCH,
5656};
5657
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005658static int tapan_post_reset_cb(struct wcd9xxx *wcd9xxx)
5659{
5660 int ret = 0;
5661 int rco_clk_rate;
5662 struct snd_soc_codec *codec;
5663 struct tapan_priv *tapan;
5664
5665 codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
5666 tapan = snd_soc_codec_get_drvdata(codec);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005667
Joonwoo Park8ffa2812013-08-07 19:01:30 -07005668 snd_soc_card_change_online_state(codec->card, 1);
5669
5670 mutex_lock(&codec->mutex);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005671 if (codec->reg_def_copy) {
5672 pr_debug("%s: Update ASOC cache", __func__);
5673 kfree(codec->reg_cache);
5674 codec->reg_cache = kmemdup(codec->reg_def_copy,
5675 codec->reg_size, GFP_KERNEL);
5676 if (!codec->reg_cache) {
5677 pr_err("%s: Cache update failed!\n", __func__);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005678 mutex_unlock(&codec->mutex);
5679 return -ENOMEM;
5680 }
5681 }
5682
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005683 if (spkr_drv_wrnd == 1)
5684 snd_soc_update_bits(codec, TAPAN_A_SPKR_DRV_EN, 0x80, 0x80);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005685
5686 tapan_update_reg_defaults(codec);
5687 tapan_update_reg_mclk_rate(wcd9xxx);
5688 tapan_codec_init_reg(codec);
5689 ret = tapan_handle_pdata(tapan);
5690 if (IS_ERR_VALUE(ret))
5691 pr_err("%s: bad pdata\n", __func__);
5692
5693 tapan_slim_interface_init_reg(codec);
5694
Joonwoo Park865bcf02013-07-15 14:05:32 -07005695 wcd9xxx_resmgr_post_ssr(&tapan->resmgr);
5696
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005697 wcd9xxx_mbhc_deinit(&tapan->mbhc);
5698
5699 if (TAPAN_IS_1_0(wcd9xxx->version))
5700 rco_clk_rate = TAPAN_MCLK_CLK_12P288MHZ;
5701 else
5702 rco_clk_rate = TAPAN_MCLK_CLK_9P6MHZ;
5703
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07005704 ret = wcd9xxx_mbhc_init(&tapan->mbhc, &tapan->resmgr, codec,
5705 tapan_enable_mbhc_micbias,
Bhalchandra Gajare16748932013-10-01 18:16:05 -07005706 &mbhc_cb, &cdc_intr_ids, rco_clk_rate,
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -07005707 TAPAN_CDC_ZDET_SUPPORTED);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005708 if (ret)
5709 pr_err("%s: mbhc init failed %d\n", __func__, ret);
5710 else
5711 wcd9xxx_mbhc_start(&tapan->mbhc, tapan->mbhc.mbhc_cfg);
Joonwoo Parkc98049a2013-07-30 16:43:34 -07005712
5713 tapan_cleanup_irqs(tapan);
5714 ret = tapan_setup_irqs(tapan);
5715 if (ret)
5716 pr_err("%s: Failed to setup irq: %d\n", __func__, ret);
5717
Damir Didjustod6aea992013-09-03 21:18:59 -07005718 tapan->machine_codec_event_cb(codec, WCD9XXX_CODEC_EVENT_CODEC_UP);
5719
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005720 mutex_unlock(&codec->mutex);
5721 return ret;
5722}
5723
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005724static struct wcd9xxx_reg_address tapan_reg_address = {
5725};
5726
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005727static int wcd9xxx_ssr_register(struct wcd9xxx *control,
Joonwoo Park8ffa2812013-08-07 19:01:30 -07005728 int (*device_down_cb)(struct wcd9xxx *wcd9xxx),
5729 int (*device_up_cb)(struct wcd9xxx *wcd9xxx),
5730 void *priv)
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005731{
Joonwoo Park8ffa2812013-08-07 19:01:30 -07005732 control->dev_down = device_down_cb;
5733 control->post_reset = device_up_cb;
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005734 control->ssr_priv = priv;
5735 return 0;
5736}
5737
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07005738static struct regulator *tapan_codec_find_regulator(
5739 struct snd_soc_codec *codec,
5740 const char *name)
5741{
5742 int i;
5743 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
5744
5745 for (i = 0; i < core->num_of_supplies; i++) {
5746 if (core->supplies[i].supply &&
5747 !strcmp(core->supplies[i].supply, name))
5748 return core->supplies[i].consumer;
5749 }
5750 return NULL;
5751}
5752
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005753static void tapan_enable_config_rco(struct wcd9xxx *core, bool enable)
5754{
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005755 struct wcd9xxx_core_resource *core_res = &core->core_res;
5756
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005757 if (enable) {
Phani Kumar Uppalapaticc3ec0c2013-09-06 18:04:03 -07005758 wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
5759 0x80, 0x80);
5760 wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
5761 0x04, 0x04);
5762 wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
5763 0x01, 0x01);
5764 usleep_range(1000, 1000);
5765 wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
5766 0x80, 0x00);
5767
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005768 /* Enable RC Oscillator */
5769 wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_FREQ, 0x10, 0x00);
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005770 wcd9xxx_reg_write(core_res, WCD9XXX_A_BIAS_OSC_BG_CTL, 0x17);
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005771 usleep_range(5, 5);
5772 wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_FREQ, 0x80, 0x80);
5773 wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_TEST, 0x80, 0x80);
5774 usleep_range(10, 10);
5775 wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_TEST, 0x80, 0x00);
5776 usleep_range(20, 20);
5777 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN1, 0x08, 0x08);
5778 /* Enable MCLK and wait 1ms till it gets enabled */
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005779 wcd9xxx_reg_write(core_res, WCD9XXX_A_CLK_BUFF_EN2, 0x02);
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005780 usleep_range(1000, 1000);
5781 /* Enable CLK BUFF and wait for 1.2ms */
5782 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN1, 0x01, 0x01);
5783 usleep_range(1000, 1200);
5784
5785 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x02, 0x00);
5786 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x04, 0x04);
5787 wcd9xxx_reg_update(core, WCD9XXX_A_CDC_CLK_MCLK_CTL,
5788 0x01, 0x01);
5789 usleep_range(50, 50);
5790 } else {
5791 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x04, 0x00);
5792 usleep_range(50, 50);
5793 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN2, 0x02, 0x02);
5794 wcd9xxx_reg_update(core, WCD9XXX_A_CLK_BUFF_EN1, 0x05, 0x00);
5795 usleep_range(50, 50);
Phani Kumar Uppalapaticc3ec0c2013-09-06 18:04:03 -07005796
5797 wcd9xxx_reg_update(core, WCD9XXX_A_RC_OSC_FREQ, 0x80, 0x00);
5798 usleep_range(10, 10);
5799 wcd9xxx_reg_write(core_res, WCD9XXX_A_BIAS_OSC_BG_CTL, 0x16);
5800 wcd9xxx_reg_update(core, WCD9XXX_A_BIAS_CENTRAL_BG_CTL,
5801 0x03, 0x00);
5802 usleep_range(100, 100);
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005803 }
5804
5805}
5806
5807static bool tapan_check_wcd9306(struct device *cdc_dev, bool sensed)
5808{
5809 struct wcd9xxx *core = dev_get_drvdata(cdc_dev->parent);
5810 u8 reg_val;
5811 bool ret = true;
5812 unsigned long timeout;
5813 bool timedout;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005814 struct wcd9xxx_core_resource *core_res = &core->core_res;
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005815
5816 if (!core) {
5817 dev_err(cdc_dev, "%s: core not initialized\n", __func__);
5818 return -EINVAL;
5819 }
5820
5821 tapan_enable_config_rco(core, 1);
5822
5823 if (sensed == false) {
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005824 reg_val = wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_CTL);
5825 wcd9xxx_reg_write(core_res, TAPAN_A_QFUSE_CTL,
5826 (reg_val | 0x03));
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005827 }
5828
5829 timeout = jiffies + HZ;
5830 do {
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005831 if ((wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_STATUS)))
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005832 break;
5833 } while (!(timedout = time_after(jiffies, timeout)));
5834
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005835 if (wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_DATA_OUT1) ||
5836 wcd9xxx_reg_read(core_res, TAPAN_A_QFUSE_DATA_OUT2)) {
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005837 dev_info(cdc_dev, "%s: wcd9302 detected\n", __func__);
5838 ret = false;
5839 } else
5840 dev_info(cdc_dev, "%s: wcd9306 detected\n", __func__);
5841
5842 tapan_enable_config_rco(core, 0);
5843 return ret;
5844};
5845
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005846static int tapan_codec_probe(struct snd_soc_codec *codec)
5847{
5848 struct wcd9xxx *control;
5849 struct tapan_priv *tapan;
5850 struct wcd9xxx_pdata *pdata;
5851 struct wcd9xxx *wcd9xxx;
5852 struct snd_soc_dapm_context *dapm = &codec->dapm;
5853 int ret = 0;
Phani Kumar Uppalapati43bc4152013-05-24 00:44:20 -07005854 int i, rco_clk_rate;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005855 void *ptr = NULL;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005856 struct wcd9xxx_core_resource *core_res;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005857
5858 codec->control_data = dev_get_drvdata(codec->dev->parent);
5859 control = codec->control_data;
5860
Joonwoo Park8ffa2812013-08-07 19:01:30 -07005861 wcd9xxx_ssr_register(control, tapan_device_down,
5862 tapan_post_reset_cb, (void *)codec);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005863
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005864 dev_info(codec->dev, "%s()\n", __func__);
5865
5866 tapan = kzalloc(sizeof(struct tapan_priv), GFP_KERNEL);
5867 if (!tapan) {
5868 dev_err(codec->dev, "Failed to allocate private data\n");
5869 return -ENOMEM;
5870 }
5871 for (i = 0 ; i < NUM_DECIMATORS; i++) {
5872 tx_hpf_work[i].tapan = tapan;
5873 tx_hpf_work[i].decimator = i + 1;
5874 INIT_DELAYED_WORK(&tx_hpf_work[i].dwork,
5875 tx_hpf_corner_freq_callback);
5876 }
5877
5878 snd_soc_codec_set_drvdata(codec, tapan);
5879
5880 /* codec resmgr module init */
5881 wcd9xxx = codec->control_data;
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005882 core_res = &wcd9xxx->core_res;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005883 pdata = dev_get_platdata(codec->dev->parent);
Bhalchandra Gajare9b4eb3b2013-04-30 12:00:41 -07005884 ret = wcd9xxx_resmgr_init(&tapan->resmgr, codec, core_res, pdata,
Bhalchandra Gajare9943aa62013-10-09 18:40:11 -07005885 &pdata->micbias, &tapan_reg_address,
5886 WCD9XXX_CDC_TYPE_TAPAN);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005887 if (ret) {
5888 pr_err("%s: wcd9xxx init failed %d\n", __func__, ret);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005889 return ret;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005890 }
5891
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07005892 tapan->cp_regulators[CP_REG_BUCK] = tapan_codec_find_regulator(codec,
5893 WCD9XXX_SUPPLY_BUCK_NAME);
5894 tapan->cp_regulators[CP_REG_BHELPER] = tapan_codec_find_regulator(codec,
5895 "cdc-vdd-buckhelper");
5896
Bhalchandra Gajare7c739522013-06-20 15:31:02 -07005897 tapan->clsh_d.buck_mv = tapan_codec_get_buck_mv(codec);
5898 /*
5899 * If 1.8 volts is requested on the vdd_cp line, then
5900 * assume that S4 is in a dynamically switchable state
5901 * and can switch between 1.8 volts and 2.15 volts
5902 */
5903 if (tapan->clsh_d.buck_mv == WCD9XXX_CDC_BUCK_MV_1P8)
5904 tapan->clsh_d.is_dynamic_vdd_cp = true;
5905 wcd9xxx_clsh_init(&tapan->clsh_d, &tapan->resmgr);
5906
Phani Kumar Uppalapati43bc4152013-05-24 00:44:20 -07005907 if (TAPAN_IS_1_0(control->version))
5908 rco_clk_rate = TAPAN_MCLK_CLK_12P288MHZ;
5909 else
5910 rco_clk_rate = TAPAN_MCLK_CLK_9P6MHZ;
5911
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07005912 ret = wcd9xxx_mbhc_init(&tapan->mbhc, &tapan->resmgr, codec,
5913 tapan_enable_mbhc_micbias,
Bhalchandra Gajare16748932013-10-01 18:16:05 -07005914 &mbhc_cb, &cdc_intr_ids, rco_clk_rate,
Phani Kumar Uppalapati01a77e12013-08-08 15:31:35 -07005915 TAPAN_CDC_ZDET_SUPPORTED);
Simmi Pateriya95466b12013-05-09 20:08:46 +05305916
Simmi Pateriya0a44d842013-04-03 01:12:42 +05305917 if (ret) {
5918 pr_err("%s: mbhc init failed %d\n", __func__, ret);
5919 return ret;
5920 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005921
5922 tapan->codec = codec;
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005923 for (i = 0; i < COMPANDER_MAX; i++) {
5924 tapan->comp_enabled[i] = 0;
5925 tapan->comp_fs[i] = COMPANDER_FS_48KHZ;
5926 }
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005927 tapan->intf_type = wcd9xxx_get_intf_type();
5928 tapan->aux_pga_cnt = 0;
5929 tapan->aux_l_gain = 0x1F;
5930 tapan->aux_r_gain = 0x1F;
Phani Kumar Uppalapati07420de2013-08-28 21:35:00 -07005931 tapan->ldo_h_users = 0;
5932 tapan->micb_2_users = 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005933 tapan_update_reg_defaults(codec);
Ravishankar Sarawadid6273212013-05-07 15:08:27 -07005934 tapan_update_reg_mclk_rate(wcd9xxx);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005935 tapan_codec_init_reg(codec);
5936 ret = tapan_handle_pdata(tapan);
5937 if (IS_ERR_VALUE(ret)) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005938 dev_err(codec->dev, "%s: bad pdata\n", __func__);
5939 goto err_pdata;
5940 }
5941
5942 if (spkr_drv_wrnd > 0) {
Joonwoo Park533b3682013-06-13 11:41:21 -07005943 WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005944 wcd9xxx_resmgr_get_bandgap(&tapan->resmgr,
5945 WCD9XXX_BANDGAP_AUDIO_MODE);
Joonwoo Park533b3682013-06-13 11:41:21 -07005946 WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005947 }
5948
5949 ptr = kmalloc((sizeof(tapan_rx_chs) +
5950 sizeof(tapan_tx_chs)), GFP_KERNEL);
5951 if (!ptr) {
5952 pr_err("%s: no mem for slim chan ctl data\n", __func__);
5953 ret = -ENOMEM;
5954 goto err_nomem_slimch;
5955 }
5956
5957 if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005958 snd_soc_dapm_new_controls(dapm, tapan_dapm_i2s_widgets,
5959 ARRAY_SIZE(tapan_dapm_i2s_widgets));
5960 snd_soc_dapm_add_routes(dapm, audio_i2s_map,
5961 ARRAY_SIZE(audio_i2s_map));
5962 for (i = 0; i < ARRAY_SIZE(tapan_i2s_dai); i++)
5963 INIT_LIST_HEAD(&tapan->dai[i].wcd9xxx_ch_list);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005964 } else if (tapan->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
5965 for (i = 0; i < NUM_CODEC_DAIS; i++) {
5966 INIT_LIST_HEAD(&tapan->dai[i].wcd9xxx_ch_list);
5967 init_waitqueue_head(&tapan->dai[i].dai_wait);
5968 }
Damir Didjustod6aea992013-09-03 21:18:59 -07005969 tapan_init_slim_slave_cfg(codec);
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005970 }
5971
Phani Kumar Uppalapaticc3ec0c2013-09-06 18:04:03 -07005972 if (codec_ver == WCD9306) {
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07005973 snd_soc_add_codec_controls(codec, tapan_9306_snd_controls,
5974 ARRAY_SIZE(tapan_9306_snd_controls));
5975 snd_soc_dapm_new_controls(dapm, tapan_9306_dapm_widgets,
5976 ARRAY_SIZE(tapan_9306_dapm_widgets));
5977 snd_soc_dapm_add_routes(dapm, wcd9306_map,
5978 ARRAY_SIZE(wcd9306_map));
5979 } else {
5980 snd_soc_dapm_add_routes(dapm, wcd9302_map,
5981 ARRAY_SIZE(wcd9302_map));
5982 }
5983
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08005984 control->num_rx_port = TAPAN_RX_MAX;
5985 control->rx_chs = ptr;
5986 memcpy(control->rx_chs, tapan_rx_chs, sizeof(tapan_rx_chs));
5987 control->num_tx_port = TAPAN_TX_MAX;
5988 control->tx_chs = ptr + sizeof(tapan_rx_chs);
5989 memcpy(control->tx_chs, tapan_tx_chs, sizeof(tapan_tx_chs));
5990
5991 snd_soc_dapm_sync(dapm);
5992
5993 (void) tapan_setup_irqs(tapan);
5994
Bhalchandra Gajareea898742013-03-05 18:15:53 -08005995 atomic_set(&kp_tapan_priv, (unsigned long)tapan);
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07005996 mutex_lock(&dapm->codec->mutex);
Phani Kumar Uppalapaticc3ec0c2013-09-06 18:04:03 -07005997 if (codec_ver == WCD9306) {
5998 snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
5999 snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
6000 snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE");
6001 snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
6002 snd_soc_dapm_disable_pin(dapm, "ANC EAR");
6003 }
Phani Kumar Uppalapati3a5f8cc2013-04-08 21:30:02 -07006004 snd_soc_dapm_sync(dapm);
6005 mutex_unlock(&dapm->codec->mutex);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08006006
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08006007 codec->ignore_pmdown_time = 1;
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07006008
6009 if (ret)
6010 tapan_cleanup_irqs(tapan);
6011
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08006012 return ret;
6013
Bhalchandra Gajareea898742013-03-05 18:15:53 -08006014err_pdata:
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08006015 kfree(ptr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08006016err_nomem_slimch:
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08006017 kfree(tapan);
6018 return ret;
6019}
6020
6021static int tapan_codec_remove(struct snd_soc_codec *codec)
6022{
6023 struct tapan_priv *tapan = snd_soc_codec_get_drvdata(codec);
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07006024 int index = 0;
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08006025
Joonwoo Park533b3682013-06-13 11:41:21 -07006026 WCD9XXX_BG_CLK_LOCK(&tapan->resmgr);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08006027 atomic_set(&kp_tapan_priv, 0);
6028
6029 if (spkr_drv_wrnd > 0)
6030 wcd9xxx_resmgr_put_bandgap(&tapan->resmgr,
6031 WCD9XXX_BANDGAP_AUDIO_MODE);
Joonwoo Park533b3682013-06-13 11:41:21 -07006032 WCD9XXX_BG_CLK_UNLOCK(&tapan->resmgr);
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07006033
6034 tapan_cleanup_irqs(tapan);
6035
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08006036 /* cleanup MBHC */
6037 wcd9xxx_mbhc_deinit(&tapan->mbhc);
6038 /* cleanup resmgr */
6039 wcd9xxx_resmgr_deinit(&tapan->resmgr);
6040
Bhalchandra Gajare5b4199c2013-07-03 14:35:43 -07006041 for (index = 0; index < CP_REG_MAX; index++)
6042 tapan->cp_regulators[index] = NULL;
6043
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08006044 kfree(tapan);
6045 return 0;
6046}
6047
6048static struct snd_soc_codec_driver soc_codec_dev_tapan = {
6049 .probe = tapan_codec_probe,
6050 .remove = tapan_codec_remove,
6051
6052 .read = tapan_read,
6053 .write = tapan_write,
6054
6055 .readable_register = tapan_readable,
6056 .volatile_register = tapan_volatile,
6057
6058 .reg_cache_size = TAPAN_CACHE_SIZE,
6059 .reg_cache_default = tapan_reset_reg_defaults,
6060 .reg_word_size = 1,
6061
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07006062 .controls = tapan_common_snd_controls,
6063 .num_controls = ARRAY_SIZE(tapan_common_snd_controls),
6064 .dapm_widgets = tapan_common_dapm_widgets,
6065 .num_dapm_widgets = ARRAY_SIZE(tapan_common_dapm_widgets),
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08006066 .dapm_routes = audio_map,
6067 .num_dapm_routes = ARRAY_SIZE(audio_map),
6068};
6069
6070#ifdef CONFIG_PM
6071static int tapan_suspend(struct device *dev)
6072{
6073 dev_dbg(dev, "%s: system suspend\n", __func__);
6074 return 0;
6075}
6076
6077static int tapan_resume(struct device *dev)
6078{
6079 struct platform_device *pdev = to_platform_device(dev);
6080 struct tapan_priv *tapan = platform_get_drvdata(pdev);
6081 dev_dbg(dev, "%s: system resume\n", __func__);
Bhalchandra Gajareea898742013-03-05 18:15:53 -08006082 /* Notify */
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08006083 wcd9xxx_resmgr_notifier_call(&tapan->resmgr, WCD9XXX_EVENT_POST_RESUME);
6084 return 0;
6085}
6086
6087static const struct dev_pm_ops tapan_pm_ops = {
6088 .suspend = tapan_suspend,
6089 .resume = tapan_resume,
6090};
6091#endif
6092
6093static int __devinit tapan_probe(struct platform_device *pdev)
6094{
6095 int ret = 0;
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07006096 bool is_wcd9306;
6097
6098 is_wcd9306 = tapan_check_wcd9306(&pdev->dev, false);
6099 if (is_wcd9306 < 0) {
6100 dev_info(&pdev->dev, "%s: cannot find codec type, default to 9306\n",
6101 __func__);
6102 is_wcd9306 = true;
6103 }
Phani Kumar Uppalapaticc3ec0c2013-09-06 18:04:03 -07006104 codec_ver = is_wcd9306 ? WCD9306 : WCD9302;
Phani Kumar Uppalapati71ba8882013-04-12 19:57:52 -07006105
6106 if (!is_wcd9306) {
6107 if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
6108 ret = snd_soc_register_codec(&pdev->dev,
6109 &soc_codec_dev_tapan,
6110 tapan9302_dai, ARRAY_SIZE(tapan9302_dai));
6111 else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C)
6112 ret = snd_soc_register_codec(&pdev->dev,
6113 &soc_codec_dev_tapan,
6114 tapan_i2s_dai, ARRAY_SIZE(tapan_i2s_dai));
6115 } else {
6116 if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
6117 ret = snd_soc_register_codec(&pdev->dev,
6118 &soc_codec_dev_tapan,
6119 tapan_dai, ARRAY_SIZE(tapan_dai));
6120 else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C)
6121 ret = snd_soc_register_codec(&pdev->dev,
6122 &soc_codec_dev_tapan,
6123 tapan_i2s_dai, ARRAY_SIZE(tapan_i2s_dai));
6124 }
6125
Bhalchandra Gajaredcf09f82012-11-09 11:58:26 -08006126 return ret;
6127}
6128static int __devexit tapan_remove(struct platform_device *pdev)
6129{
6130 snd_soc_unregister_codec(&pdev->dev);
6131 return 0;
6132}
6133static struct platform_driver tapan_codec_driver = {
6134 .probe = tapan_probe,
6135 .remove = tapan_remove,
6136 .driver = {
6137 .name = "tapan_codec",
6138 .owner = THIS_MODULE,
6139#ifdef CONFIG_PM
6140 .pm = &tapan_pm_ops,
6141#endif
6142 },
6143};
6144
6145static int __init tapan_codec_init(void)
6146{
6147 return platform_driver_register(&tapan_codec_driver);
6148}
6149
6150static void __exit tapan_codec_exit(void)
6151{
6152 platform_driver_unregister(&tapan_codec_driver);
6153}
6154
6155module_init(tapan_codec_init);
6156module_exit(tapan_codec_exit);
6157
6158MODULE_DESCRIPTION("Tapan codec driver");
6159MODULE_LICENSE("GPL v2");