blob: 845f1a20bef2f112871a6e6fe3f1a727d58ba1a7 [file] [log] [blame]
Ravishankar Sarawadi839fcf32012-11-14 12:13:00 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Kiran Kandic3b24402012-06-11 00:05:59 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12#include <linux/module.h>
13#include <linux/init.h>
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>
Joonwoo Park9bbb4d12012-11-09 19:58:11 -080021#include <linux/wait.h>
22#include <linux/bitops.h>
Kiran Kandic3b24402012-06-11 00:05:59 -070023#include <linux/mfd/wcd9xxx/core.h>
24#include <linux/mfd/wcd9xxx/wcd9xxx_registers.h>
25#include <linux/mfd/wcd9xxx/wcd9320_registers.h>
26#include <linux/mfd/wcd9xxx/pdata.h>
Joonwoo Park448a8fc2013-04-10 15:25:58 -070027#include <linux/regulator/consumer.h>
Kiran Kandic3b24402012-06-11 00:05:59 -070028#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 "wcd9320.h"
Joonwoo Parka8890262012-10-15 12:04:27 -070039#include "wcd9xxx-resmgr.h"
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -080040#include "wcd9xxx-common.h"
Kiran Kandic3b24402012-06-11 00:05:59 -070041
Joonwoo Park1d05bb92013-03-07 16:55:06 -080042#define TAIKO_MAD_SLIMBUS_TX_PORT 12
43#define TAIKO_MAD_AUDIO_FIRMWARE_PATH "wcd9320/wcd9320_mad_audio.bin"
44
Bhalchandra Gajare9581aed2013-03-29 17:06:10 -070045#define TAIKO_HPH_PA_SETTLE_COMP_ON 3000
Bhalchandra Gajareef7810e2013-03-29 16:50:37 -070046#define TAIKO_HPH_PA_SETTLE_COMP_OFF 13000
47
Joonwoo Park125cd4e2012-12-11 15:16:11 -080048static atomic_t kp_taiko_priv;
49static int spkr_drv_wrnd_param_set(const char *val,
50 const struct kernel_param *kp);
51static int spkr_drv_wrnd = 1;
52
53static struct kernel_param_ops spkr_drv_wrnd_param_ops = {
54 .set = spkr_drv_wrnd_param_set,
55 .get = param_get_int,
56};
Joonwoo Park1d05bb92013-03-07 16:55:06 -080057
58static struct afe_param_slimbus_slave_port_cfg taiko_slimbus_slave_port_cfg = {
59 .minor_version = 1,
60 .slimbus_dev_id = AFE_SLIMBUS_DEVICE_1,
61 .slave_dev_pgd_la = 0,
62 .slave_dev_intfdev_la = 0,
63 .bit_width = 16,
64 .data_format = 0,
65 .num_channels = 1
66};
67
68enum {
69 RESERVED = 0,
70 AANC_LPF_FF_FB = 1,
71 AANC_LPF_COEFF_MSB,
72 AANC_LPF_COEFF_LSB,
73 HW_MAD_AUDIO_ENABLE,
74 HW_MAD_ULTR_ENABLE,
75 HW_MAD_BEACON_ENABLE,
76 HW_MAD_AUDIO_SLEEP_TIME,
77 HW_MAD_ULTR_SLEEP_TIME,
78 HW_MAD_BEACON_SLEEP_TIME,
79 HW_MAD_TX_AUDIO_SWITCH_OFF,
80 HW_MAD_TX_ULTR_SWITCH_OFF,
81 HW_MAD_TX_BEACON_SWITCH_OFF,
82 MAD_AUDIO_INT_DEST_SELECT_REG,
83 MAD_ULT_INT_DEST_SELECT_REG,
84 MAD_BEACON_INT_DEST_SELECT_REG,
85 MAD_CLIP_INT_DEST_SELECT_REG,
86 MAD_VBAT_INT_DEST_SELECT_REG,
87 MAD_AUDIO_INT_MASK_REG,
88 MAD_ULT_INT_MASK_REG,
89 MAD_BEACON_INT_MASK_REG,
90 MAD_CLIP_INT_MASK_REG,
91 MAD_VBAT_INT_MASK_REG,
92 MAD_AUDIO_INT_STATUS_REG,
93 MAD_ULT_INT_STATUS_REG,
94 MAD_BEACON_INT_STATUS_REG,
95 MAD_CLIP_INT_STATUS_REG,
96 MAD_VBAT_INT_STATUS_REG,
97 MAD_AUDIO_INT_CLEAR_REG,
98 MAD_ULT_INT_CLEAR_REG,
99 MAD_BEACON_INT_CLEAR_REG,
100 MAD_CLIP_INT_CLEAR_REG,
101 MAD_VBAT_INT_CLEAR_REG,
102 SB_PGD_PORT_TX_WATERMARK_n,
103 SB_PGD_PORT_TX_ENABLE_n,
104 SB_PGD_PORT_RX_WATERMARK_n,
105 SB_PGD_PORT_RX_ENABLE_n,
Damir Didjustodcfdff82013-03-21 23:26:41 -0700106 SB_PGD_TX_PORTn_MULTI_CHNL_0,
107 SB_PGD_TX_PORTn_MULTI_CHNL_1,
108 SB_PGD_RX_PORTn_MULTI_CHNL_0,
109 SB_PGD_RX_PORTn_MULTI_CHNL_1,
110 AANC_FF_GAIN_ADAPTIVE,
111 AANC_FFGAIN_ADAPTIVE_EN,
112 AANC_GAIN_CONTROL,
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -0400113 SPKR_CLIP_PIPE_BANK_SEL,
114 SPKR_CLIPDET_VAL0,
115 SPKR_CLIPDET_VAL1,
116 SPKR_CLIPDET_VAL2,
117 SPKR_CLIPDET_VAL3,
118 SPKR_CLIPDET_VAL4,
119 SPKR_CLIPDET_VAL5,
120 SPKR_CLIPDET_VAL6,
121 SPKR_CLIPDET_VAL7,
Joonwoo Park1d05bb92013-03-07 16:55:06 -0800122 MAX_CFG_REGISTERS,
123};
124
Damir Didjustodcfdff82013-03-21 23:26:41 -0700125static struct afe_param_cdc_reg_cfg audio_reg_cfg[] = {
Joonwoo Park1d05bb92013-03-07 16:55:06 -0800126 {
127 1,
128 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_MAD_MAIN_CTL_1),
129 HW_MAD_AUDIO_ENABLE, 0x1, 8, 0
130 },
131 {
132 1,
133 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_MAD_AUDIO_CTL_3),
134 HW_MAD_AUDIO_SLEEP_TIME, 0xF, 8, 0
135 },
136 {
137 1,
138 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_MAD_AUDIO_CTL_4),
139 HW_MAD_TX_AUDIO_SWITCH_OFF, 0x1, 8, 0
140 },
141 {
142 1,
143 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_INTR_DESTN3),
144 MAD_AUDIO_INT_DEST_SELECT_REG, 0x1, 8, 0
145 },
146 {
147 1,
148 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_INTR_MASK3),
149 MAD_AUDIO_INT_MASK_REG, 0x1, 8, 0
150 },
151 {
152 1,
153 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_INTR_STATUS3),
154 MAD_AUDIO_INT_STATUS_REG, 0x1, 8, 0
155 },
156 {
157 1,
158 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_INTR_CLEAR3),
159 MAD_AUDIO_INT_CLEAR_REG, 0x1, 8, 0
160 },
161 {
162 1,
163 (TAIKO_REGISTER_START_OFFSET + TAIKO_SB_PGD_PORT_TX_BASE),
164 SB_PGD_PORT_TX_WATERMARK_n, 0x1E, 8, 0x1
165 },
166 {
167 1,
168 (TAIKO_REGISTER_START_OFFSET + TAIKO_SB_PGD_PORT_TX_BASE),
169 SB_PGD_PORT_TX_ENABLE_n, 0x1, 8, 0x1
170 },
171 {
172 1,
173 (TAIKO_REGISTER_START_OFFSET + TAIKO_SB_PGD_PORT_RX_BASE),
174 SB_PGD_PORT_RX_WATERMARK_n, 0x1E, 8, 0x1
175 },
176 {
177 1,
178 (TAIKO_REGISTER_START_OFFSET + TAIKO_SB_PGD_PORT_RX_BASE),
179 SB_PGD_PORT_RX_ENABLE_n, 0x1, 8, 0x1
Damir Didjustodcfdff82013-03-21 23:26:41 -0700180 },
181 { 1,
182 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_ANC1_IIR_B1_CTL),
183 AANC_FF_GAIN_ADAPTIVE, 0x4, 8, 0
184 },
185 { 1,
186 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_ANC1_IIR_B1_CTL),
187 AANC_FFGAIN_ADAPTIVE_EN, 0x8, 8, 0
188 },
189 {
190 1,
191 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_ANC1_GAIN_CTL),
192 AANC_GAIN_CONTROL, 0xFF, 8, 0
193 },
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -0400194 {
195 1,
196 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_INTR_DESTN3),
197 MAD_CLIP_INT_DEST_SELECT_REG, 0x8, 8, 0
198 },
199 {
200 1,
201 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_INTR_MASK3),
202 MAD_CLIP_INT_MASK_REG, 0x8, 8, 0
203 },
204 {
205 1,
206 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_INTR_STATUS3),
207 MAD_CLIP_INT_STATUS_REG, 0x8, 8, 0
208 },
209 {
210 1,
211 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_INTR_CLEAR3),
212 MAD_CLIP_INT_CLEAR_REG, 0x8, 8, 0
213 },
214};
215
216static struct afe_param_cdc_reg_cfg clip_reg_cfg[] = {
217 {
218 1,
219 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_SPKR_CLIPDET_B1_CTL),
Gopikrishnaiah Anandand3b89c02013-04-16 11:22:15 -0400220 SPKR_CLIP_PIPE_BANK_SEL, 0x3, 8, 0
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -0400221 },
222 {
223 1,
224 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_SPKR_CLIPDET_VAL0),
Gopikrishnaiah Anandand3b89c02013-04-16 11:22:15 -0400225 SPKR_CLIPDET_VAL0, 0xff, 8, 0
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -0400226 },
227 {
228 1,
229 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_SPKR_CLIPDET_VAL1),
Gopikrishnaiah Anandand3b89c02013-04-16 11:22:15 -0400230 SPKR_CLIPDET_VAL1, 0xff, 8, 0
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -0400231 },
232 {
233 1,
234 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_SPKR_CLIPDET_VAL2),
Gopikrishnaiah Anandand3b89c02013-04-16 11:22:15 -0400235 SPKR_CLIPDET_VAL2, 0xff, 8, 0
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -0400236 },
237 {
238 1,
239 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_SPKR_CLIPDET_VAL3),
Gopikrishnaiah Anandand3b89c02013-04-16 11:22:15 -0400240 SPKR_CLIPDET_VAL3, 0xff, 8, 0
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -0400241 },
242 {
243 1,
244 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_SPKR_CLIPDET_VAL4),
Gopikrishnaiah Anandand3b89c02013-04-16 11:22:15 -0400245 SPKR_CLIPDET_VAL4, 0xff, 8, 0
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -0400246 },
247 {
248 1,
249 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_SPKR_CLIPDET_VAL5),
Gopikrishnaiah Anandand3b89c02013-04-16 11:22:15 -0400250 SPKR_CLIPDET_VAL5, 0xff, 8, 0
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -0400251 },
252 {
253 1,
254 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_SPKR_CLIPDET_VAL6),
Gopikrishnaiah Anandand3b89c02013-04-16 11:22:15 -0400255 SPKR_CLIPDET_VAL6, 0xff, 8, 0
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -0400256 },
257 {
258 1,
259 (TAIKO_REGISTER_START_OFFSET + TAIKO_A_CDC_SPKR_CLIPDET_VAL7),
Gopikrishnaiah Anandand3b89c02013-04-16 11:22:15 -0400260 SPKR_CLIPDET_VAL7, 0xff, 8, 0
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -0400261 },
Joonwoo Park1d05bb92013-03-07 16:55:06 -0800262};
263
Damir Didjustodcfdff82013-03-21 23:26:41 -0700264static struct afe_param_cdc_reg_cfg_data taiko_audio_reg_cfg = {
265 .num_registers = ARRAY_SIZE(audio_reg_cfg),
266 .reg_data = audio_reg_cfg,
267};
268
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -0400269static struct afe_param_cdc_reg_cfg_data taiko_clip_reg_cfg = {
270 .num_registers = ARRAY_SIZE(clip_reg_cfg),
271 .reg_data = clip_reg_cfg,
272};
273
Damir Didjustodcfdff82013-03-21 23:26:41 -0700274static struct afe_param_id_cdc_aanc_version taiko_cdc_aanc_version = {
275 .cdc_aanc_minor_version = AFE_API_VERSION_CDC_AANC_VERSION,
276 .aanc_hw_version = AANC_HW_BLOCK_VERSION_2,
Joonwoo Park1d05bb92013-03-07 16:55:06 -0800277};
278
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -0400279static struct afe_param_id_clip_bank_sel clip_bank_sel = {
280 .minor_version = AFE_API_VERSION_CLIP_BANK_SEL_CFG,
281 .num_banks = AFE_CLIP_MAX_BANKS,
282 .bank_map = {0, 1, 2, 3},
283};
284
Joonwoo Park125cd4e2012-12-11 15:16:11 -0800285module_param_cb(spkr_drv_wrnd, &spkr_drv_wrnd_param_ops, &spkr_drv_wrnd, 0644);
286MODULE_PARM_DESC(spkr_drv_wrnd,
287 "Run software workaround to avoid leakage on the speaker drive");
288
Kiran Kandic3b24402012-06-11 00:05:59 -0700289#define WCD9320_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
290 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
291 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
292
Kiran Kandic3b24402012-06-11 00:05:59 -0700293#define NUM_DECIMATORS 10
294#define NUM_INTERPOLATORS 7
295#define BITS_PER_REG 8
Kuirong Wang906ac472012-07-09 12:54:44 -0700296#define TAIKO_TX_PORT_NUMBER 16
Kiran Kandic3b24402012-06-11 00:05:59 -0700297
Kiran Kandic3b24402012-06-11 00:05:59 -0700298#define TAIKO_I2S_MASTER_MODE_MASK 0x08
Damir Didjusto1a353ce2013-04-02 11:45:47 -0700299
300#define TAIKO_DMIC_SAMPLE_RATE_DIV_2 0x0
301#define TAIKO_DMIC_SAMPLE_RATE_DIV_3 0x1
302#define TAIKO_DMIC_SAMPLE_RATE_DIV_4 0x2
303
304#define TAIKO_DMIC_B1_CTL_DIV_2 0x00
305#define TAIKO_DMIC_B1_CTL_DIV_3 0x22
306#define TAIKO_DMIC_B1_CTL_DIV_4 0x44
307
308#define TAIKO_DMIC_B2_CTL_DIV_2 0x00
309#define TAIKO_DMIC_B2_CTL_DIV_3 0x02
310#define TAIKO_DMIC_B2_CTL_DIV_4 0x04
311
312#define TAIKO_ANC_DMIC_X2_ON 0x1
313#define TAIKO_ANC_DMIC_X2_OFF 0x0
Joonwoo Park9bbb4d12012-11-09 19:58:11 -0800314
315#define TAIKO_SLIM_CLOSE_TIMEOUT 1000
316#define TAIKO_SLIM_IRQ_OVERFLOW (1 << 0)
317#define TAIKO_SLIM_IRQ_UNDERFLOW (1 << 1)
318#define TAIKO_SLIM_IRQ_PORT_CLOSED (1 << 2)
Venkat Sudhira50a3762012-11-26 12:12:15 -0800319#define TAIKO_MCLK_CLK_12P288MHZ 12288000
320#define TAIKO_MCLK_CLK_9P6HZ 9600000
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -0800321
Bhalchandra Gajare5b40c532013-02-19 13:36:47 -0800322#define TAIKO_FORMATS_S16_S24_LE (SNDRV_PCM_FMTBIT_S16_LE | \
323 SNDRV_PCM_FORMAT_S24_LE)
324
325#define TAIKO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
326
Kuirong Wang906ac472012-07-09 12:54:44 -0700327enum {
328 AIF1_PB = 0,
329 AIF1_CAP,
330 AIF2_PB,
331 AIF2_CAP,
332 AIF3_PB,
333 AIF3_CAP,
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -0500334 AIF4_VIFEED,
Joonwoo Park1d05bb92013-03-07 16:55:06 -0800335 AIF4_MAD_TX,
Kuirong Wang906ac472012-07-09 12:54:44 -0700336 NUM_CODEC_DAIS,
Kiran Kandic3b24402012-06-11 00:05:59 -0700337};
338
Kuirong Wang906ac472012-07-09 12:54:44 -0700339enum {
340 RX_MIX1_INP_SEL_ZERO = 0,
341 RX_MIX1_INP_SEL_SRC1,
342 RX_MIX1_INP_SEL_SRC2,
343 RX_MIX1_INP_SEL_IIR1,
344 RX_MIX1_INP_SEL_IIR2,
345 RX_MIX1_INP_SEL_RX1,
346 RX_MIX1_INP_SEL_RX2,
347 RX_MIX1_INP_SEL_RX3,
348 RX_MIX1_INP_SEL_RX4,
349 RX_MIX1_INP_SEL_RX5,
350 RX_MIX1_INP_SEL_RX6,
351 RX_MIX1_INP_SEL_RX7,
352 RX_MIX1_INP_SEL_AUXRX,
353};
354
355#define TAIKO_COMP_DIGITAL_GAIN_OFFSET 3
356
Kiran Kandic3b24402012-06-11 00:05:59 -0700357static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
358static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
359static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
360static struct snd_soc_dai_driver taiko_dai[];
361static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0);
362
Kiran Kandic3b24402012-06-11 00:05:59 -0700363/* Codec supports 2 IIR filters */
364enum {
365 IIR1 = 0,
366 IIR2,
367 IIR_MAX,
368};
369/* Codec supports 5 bands */
370enum {
371 BAND1 = 0,
372 BAND2,
373 BAND3,
374 BAND4,
375 BAND5,
376 BAND_MAX,
377};
378
379enum {
Joonwoo Parkc7731432012-10-17 12:41:44 -0700380 COMPANDER_0,
381 COMPANDER_1,
Kiran Kandic3b24402012-06-11 00:05:59 -0700382 COMPANDER_2,
383 COMPANDER_MAX,
384};
385
386enum {
387 COMPANDER_FS_8KHZ = 0,
388 COMPANDER_FS_16KHZ,
389 COMPANDER_FS_32KHZ,
390 COMPANDER_FS_48KHZ,
391 COMPANDER_FS_96KHZ,
392 COMPANDER_FS_192KHZ,
393 COMPANDER_FS_MAX,
394};
395
Kiran Kandic3b24402012-06-11 00:05:59 -0700396struct comp_sample_dependent_params {
397 u32 peak_det_timeout;
398 u32 rms_meter_div_fact;
399 u32 rms_meter_resamp_fact;
400};
401
Kiran Kandic3b24402012-06-11 00:05:59 -0700402struct hpf_work {
403 struct taiko_priv *taiko;
404 u32 decimator;
405 u8 tx_hpf_cut_of_freq;
406 struct delayed_work dwork;
407};
408
409static struct hpf_work tx_hpf_work[NUM_DECIMATORS];
410
Kuirong Wang906ac472012-07-09 12:54:44 -0700411static const struct wcd9xxx_ch taiko_rx_chs[TAIKO_RX_MAX] = {
412 WCD9XXX_CH(16, 0),
413 WCD9XXX_CH(17, 1),
414 WCD9XXX_CH(18, 2),
415 WCD9XXX_CH(19, 3),
416 WCD9XXX_CH(20, 4),
417 WCD9XXX_CH(21, 5),
418 WCD9XXX_CH(22, 6),
419 WCD9XXX_CH(23, 7),
420 WCD9XXX_CH(24, 8),
421 WCD9XXX_CH(25, 9),
422 WCD9XXX_CH(26, 10),
423 WCD9XXX_CH(27, 11),
424 WCD9XXX_CH(28, 12),
425};
426
427static const struct wcd9xxx_ch taiko_tx_chs[TAIKO_TX_MAX] = {
428 WCD9XXX_CH(0, 0),
429 WCD9XXX_CH(1, 1),
430 WCD9XXX_CH(2, 2),
431 WCD9XXX_CH(3, 3),
432 WCD9XXX_CH(4, 4),
433 WCD9XXX_CH(5, 5),
434 WCD9XXX_CH(6, 6),
435 WCD9XXX_CH(7, 7),
436 WCD9XXX_CH(8, 8),
437 WCD9XXX_CH(9, 9),
438 WCD9XXX_CH(10, 10),
439 WCD9XXX_CH(11, 11),
440 WCD9XXX_CH(12, 12),
441 WCD9XXX_CH(13, 13),
442 WCD9XXX_CH(14, 14),
443 WCD9XXX_CH(15, 15),
444};
445
446static const u32 vport_check_table[NUM_CODEC_DAIS] = {
447 0, /* AIF1_PB */
448 (1 << AIF2_CAP) | (1 << AIF3_CAP), /* AIF1_CAP */
449 0, /* AIF2_PB */
450 (1 << AIF1_CAP) | (1 << AIF3_CAP), /* AIF2_CAP */
451 0, /* AIF2_PB */
452 (1 << AIF1_CAP) | (1 << AIF2_CAP), /* AIF2_CAP */
453};
454
Venkat Sudhir96dd28c2012-12-04 17:00:19 -0800455static const u32 vport_i2s_check_table[NUM_CODEC_DAIS] = {
456 0, /* AIF1_PB */
457 0, /* AIF1_CAP */
Venkat Sudhir994193b2012-12-17 17:30:51 -0800458 0, /* AIF2_PB */
459 0, /* AIF2_CAP */
Venkat Sudhir96dd28c2012-12-04 17:00:19 -0800460};
461
Kiran Kandic3b24402012-06-11 00:05:59 -0700462struct taiko_priv {
463 struct snd_soc_codec *codec;
Kiran Kandic3b24402012-06-11 00:05:59 -0700464 u32 adc_count;
Kiran Kandic3b24402012-06-11 00:05:59 -0700465 u32 rx_bias_count;
466 s32 dmic_1_2_clk_cnt;
467 s32 dmic_3_4_clk_cnt;
468 s32 dmic_5_6_clk_cnt;
469
Kiran Kandic3b24402012-06-11 00:05:59 -0700470 u32 anc_slot;
Damir Didjusto2cb06bd2013-01-30 23:14:55 -0800471 bool anc_func;
Kiran Kandic3b24402012-06-11 00:05:59 -0700472
Kiran Kandic3b24402012-06-11 00:05:59 -0700473 /*track taiko interface type*/
474 u8 intf_type;
475
Kiran Kandic3b24402012-06-11 00:05:59 -0700476 /* num of slim ports required */
Kuirong Wang906ac472012-07-09 12:54:44 -0700477 struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS];
Kiran Kandic3b24402012-06-11 00:05:59 -0700478
479 /*compander*/
480 int comp_enabled[COMPANDER_MAX];
481 u32 comp_fs[COMPANDER_MAX];
482
483 /* Maintain the status of AUX PGA */
484 int aux_pga_cnt;
485 u8 aux_l_gain;
486 u8 aux_r_gain;
487
Joonwoo Park125cd4e2012-12-11 15:16:11 -0800488 bool spkr_pa_widget_on;
Joonwoo Park448a8fc2013-04-10 15:25:58 -0700489 struct regulator *spkdrv_reg;
Joonwoo Park125cd4e2012-12-11 15:16:11 -0800490
Joonwoo Park1d05bb92013-03-07 16:55:06 -0800491 struct afe_param_cdc_slimbus_slave_cfg slimbus_slave_cfg;
492
Joonwoo Parka8890262012-10-15 12:04:27 -0700493 /* resmgr module */
494 struct wcd9xxx_resmgr resmgr;
495 /* mbhc module */
496 struct wcd9xxx_mbhc mbhc;
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -0800497
498 /* class h specific data */
499 struct wcd9xxx_clsh_cdc_data clsh_d;
Kiran Kandic3b24402012-06-11 00:05:59 -0700500};
501
Kiran Kandic3b24402012-06-11 00:05:59 -0700502static const u32 comp_shift[] = {
Joonwoo Parkc7731432012-10-17 12:41:44 -0700503 4, /* Compander 0's clock source is on interpolator 7 */
Kiran Kandic3b24402012-06-11 00:05:59 -0700504 0,
505 2,
506};
507
508static const int comp_rx_path[] = {
509 COMPANDER_1,
510 COMPANDER_1,
511 COMPANDER_2,
512 COMPANDER_2,
513 COMPANDER_2,
514 COMPANDER_2,
Joonwoo Parkc7731432012-10-17 12:41:44 -0700515 COMPANDER_0,
Kiran Kandic3b24402012-06-11 00:05:59 -0700516 COMPANDER_MAX,
517};
518
519static const struct comp_sample_dependent_params comp_samp_params[] = {
520 {
Joonwoo Parkc7731432012-10-17 12:41:44 -0700521 /* 8 Khz */
Bhalchandra Gajareed090e62013-03-29 16:11:49 -0700522 .peak_det_timeout = 0x06,
Joonwoo Parkc7731432012-10-17 12:41:44 -0700523 .rms_meter_div_fact = 0x09,
524 .rms_meter_resamp_fact = 0x06,
Kiran Kandic3b24402012-06-11 00:05:59 -0700525 },
526 {
Joonwoo Parkc7731432012-10-17 12:41:44 -0700527 /* 16 Khz */
Bhalchandra Gajareed090e62013-03-29 16:11:49 -0700528 .peak_det_timeout = 0x07,
Joonwoo Parkc7731432012-10-17 12:41:44 -0700529 .rms_meter_div_fact = 0x0A,
530 .rms_meter_resamp_fact = 0x0C,
531 },
532 {
533 /* 32 Khz */
Bhalchandra Gajareed090e62013-03-29 16:11:49 -0700534 .peak_det_timeout = 0x08,
Joonwoo Parkc7731432012-10-17 12:41:44 -0700535 .rms_meter_div_fact = 0x0B,
536 .rms_meter_resamp_fact = 0x1E,
537 },
538 {
539 /* 48 Khz */
Bhalchandra Gajareed090e62013-03-29 16:11:49 -0700540 .peak_det_timeout = 0x09,
Joonwoo Parkc7731432012-10-17 12:41:44 -0700541 .rms_meter_div_fact = 0x0B,
Kiran Kandic3b24402012-06-11 00:05:59 -0700542 .rms_meter_resamp_fact = 0x28,
543 },
Kiran Kandic3b24402012-06-11 00:05:59 -0700544 {
Joonwoo Parkc7731432012-10-17 12:41:44 -0700545 /* 96 Khz */
Bhalchandra Gajareed090e62013-03-29 16:11:49 -0700546 .peak_det_timeout = 0x0A,
Joonwoo Parkc7731432012-10-17 12:41:44 -0700547 .rms_meter_div_fact = 0x0C,
548 .rms_meter_resamp_fact = 0x50,
Kiran Kandic3b24402012-06-11 00:05:59 -0700549 },
Kiran Kandic3b24402012-06-11 00:05:59 -0700550 {
Joonwoo Parkc7731432012-10-17 12:41:44 -0700551 /* 192 Khz */
Bhalchandra Gajareed090e62013-03-29 16:11:49 -0700552 .peak_det_timeout = 0x0B,
553 .rms_meter_div_fact = 0xC,
554 .rms_meter_resamp_fact = 0x50,
Kiran Kandic3b24402012-06-11 00:05:59 -0700555 },
556};
557
558static unsigned short rx_digital_gain_reg[] = {
559 TAIKO_A_CDC_RX1_VOL_CTL_B2_CTL,
560 TAIKO_A_CDC_RX2_VOL_CTL_B2_CTL,
561 TAIKO_A_CDC_RX3_VOL_CTL_B2_CTL,
562 TAIKO_A_CDC_RX4_VOL_CTL_B2_CTL,
563 TAIKO_A_CDC_RX5_VOL_CTL_B2_CTL,
564 TAIKO_A_CDC_RX6_VOL_CTL_B2_CTL,
565 TAIKO_A_CDC_RX7_VOL_CTL_B2_CTL,
566};
567
568
569static unsigned short tx_digital_gain_reg[] = {
570 TAIKO_A_CDC_TX1_VOL_CTL_GAIN,
571 TAIKO_A_CDC_TX2_VOL_CTL_GAIN,
572 TAIKO_A_CDC_TX3_VOL_CTL_GAIN,
573 TAIKO_A_CDC_TX4_VOL_CTL_GAIN,
574 TAIKO_A_CDC_TX5_VOL_CTL_GAIN,
575 TAIKO_A_CDC_TX6_VOL_CTL_GAIN,
576 TAIKO_A_CDC_TX7_VOL_CTL_GAIN,
577 TAIKO_A_CDC_TX8_VOL_CTL_GAIN,
578 TAIKO_A_CDC_TX9_VOL_CTL_GAIN,
579 TAIKO_A_CDC_TX10_VOL_CTL_GAIN,
580};
581
Joonwoo Park125cd4e2012-12-11 15:16:11 -0800582static int spkr_drv_wrnd_param_set(const char *val,
583 const struct kernel_param *kp)
584{
585 struct snd_soc_codec *codec;
586 int ret, old;
587 struct taiko_priv *priv;
588
589 priv = (struct taiko_priv *)atomic_read(&kp_taiko_priv);
590 if (!priv) {
591 pr_debug("%s: codec isn't yet registered\n", __func__);
592 return 0;
593 }
594
595 WCD9XXX_BCL_LOCK(&priv->resmgr);
596 old = spkr_drv_wrnd;
597 ret = param_set_int(val, kp);
598 if (ret) {
599 WCD9XXX_BCL_UNLOCK(&priv->resmgr);
600 return ret;
601 }
602
603 pr_debug("%s: spkr_drv_wrnd %d -> %d\n", __func__, old, spkr_drv_wrnd);
604 codec = priv->codec;
605 if (old == 0 && spkr_drv_wrnd == 1) {
606 wcd9xxx_resmgr_get_bandgap(&priv->resmgr,
607 WCD9XXX_BANDGAP_AUDIO_MODE);
608 snd_soc_update_bits(codec, TAIKO_A_SPKR_DRV_EN, 0x80, 0x80);
609 } else if (old == 1 && spkr_drv_wrnd == 0) {
610 wcd9xxx_resmgr_put_bandgap(&priv->resmgr,
611 WCD9XXX_BANDGAP_AUDIO_MODE);
612 if (!priv->spkr_pa_widget_on)
613 snd_soc_update_bits(codec, TAIKO_A_SPKR_DRV_EN, 0x80,
614 0x00);
615 }
616
617 WCD9XXX_BCL_UNLOCK(&priv->resmgr);
618 return 0;
619}
620
Kiran Kandic3b24402012-06-11 00:05:59 -0700621static int taiko_get_anc_slot(struct snd_kcontrol *kcontrol,
622 struct snd_ctl_elem_value *ucontrol)
623{
624 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
625 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
626 ucontrol->value.integer.value[0] = taiko->anc_slot;
627 return 0;
628}
629
630static int taiko_put_anc_slot(struct snd_kcontrol *kcontrol,
631 struct snd_ctl_elem_value *ucontrol)
632{
633 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
634 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
635 taiko->anc_slot = ucontrol->value.integer.value[0];
636 return 0;
637}
638
Damir Didjusto2cb06bd2013-01-30 23:14:55 -0800639static int taiko_get_anc_func(struct snd_kcontrol *kcontrol,
640 struct snd_ctl_elem_value *ucontrol)
641{
642 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
643 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
644
645 ucontrol->value.integer.value[0] = (taiko->anc_func == true ? 1 : 0);
646 return 0;
647}
648
649static int taiko_put_anc_func(struct snd_kcontrol *kcontrol,
650 struct snd_ctl_elem_value *ucontrol)
651{
652 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
653 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
654 struct snd_soc_dapm_context *dapm = &codec->dapm;
655
656 mutex_lock(&dapm->codec->mutex);
657 taiko->anc_func = (!ucontrol->value.integer.value[0] ? false : true);
658
659 dev_dbg(codec->dev, "%s: anc_func %x", __func__, taiko->anc_func);
660
661 if (taiko->anc_func == true) {
662 snd_soc_dapm_enable_pin(dapm, "ANC HPHR");
663 snd_soc_dapm_enable_pin(dapm, "ANC HPHL");
664 snd_soc_dapm_enable_pin(dapm, "ANC HEADPHONE");
665 snd_soc_dapm_enable_pin(dapm, "ANC EAR PA");
666 snd_soc_dapm_enable_pin(dapm, "ANC EAR");
667 snd_soc_dapm_disable_pin(dapm, "HPHR");
668 snd_soc_dapm_disable_pin(dapm, "HPHL");
669 snd_soc_dapm_disable_pin(dapm, "HEADPHONE");
670 snd_soc_dapm_disable_pin(dapm, "EAR PA");
671 snd_soc_dapm_disable_pin(dapm, "EAR");
672 } else {
673 snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
674 snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
675 snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE");
676 snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
677 snd_soc_dapm_disable_pin(dapm, "ANC EAR");
678 snd_soc_dapm_enable_pin(dapm, "HPHR");
679 snd_soc_dapm_enable_pin(dapm, "HPHL");
680 snd_soc_dapm_enable_pin(dapm, "HEADPHONE");
681 snd_soc_dapm_enable_pin(dapm, "EAR PA");
682 snd_soc_dapm_enable_pin(dapm, "EAR");
683 }
684 snd_soc_dapm_sync(dapm);
685 mutex_unlock(&dapm->codec->mutex);
686 return 0;
687}
688
Kiran Kandic3b24402012-06-11 00:05:59 -0700689static int taiko_get_iir_enable_audio_mixer(
690 struct snd_kcontrol *kcontrol,
691 struct snd_ctl_elem_value *ucontrol)
692{
693 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
694 int iir_idx = ((struct soc_multi_mixer_control *)
695 kcontrol->private_value)->reg;
696 int band_idx = ((struct soc_multi_mixer_control *)
697 kcontrol->private_value)->shift;
698
699 ucontrol->value.integer.value[0] =
Ben Romberger205e14d2013-02-06 12:31:53 -0800700 (snd_soc_read(codec, (TAIKO_A_CDC_IIR1_CTL + 16 * iir_idx)) &
701 (1 << band_idx)) != 0;
Kiran Kandic3b24402012-06-11 00:05:59 -0700702
703 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
704 iir_idx, band_idx,
705 (uint32_t)ucontrol->value.integer.value[0]);
706 return 0;
707}
708
709static int taiko_put_iir_enable_audio_mixer(
710 struct snd_kcontrol *kcontrol,
711 struct snd_ctl_elem_value *ucontrol)
712{
713 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
714 int iir_idx = ((struct soc_multi_mixer_control *)
715 kcontrol->private_value)->reg;
716 int band_idx = ((struct soc_multi_mixer_control *)
717 kcontrol->private_value)->shift;
718 int value = ucontrol->value.integer.value[0];
719
720 /* Mask first 5 bits, 6-8 are reserved */
721 snd_soc_update_bits(codec, (TAIKO_A_CDC_IIR1_CTL + 16 * iir_idx),
722 (1 << band_idx), (value << band_idx));
723
724 pr_debug("%s: IIR #%d band #%d enable %d\n", __func__,
Ben Romberger205e14d2013-02-06 12:31:53 -0800725 iir_idx, band_idx,
726 ((snd_soc_read(codec, (TAIKO_A_CDC_IIR1_CTL + 16 * iir_idx)) &
727 (1 << band_idx)) != 0));
Kiran Kandic3b24402012-06-11 00:05:59 -0700728 return 0;
729}
730static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
731 int iir_idx, int band_idx,
732 int coeff_idx)
733{
Ben Romberger205e14d2013-02-06 12:31:53 -0800734 uint32_t value = 0;
735
Kiran Kandic3b24402012-06-11 00:05:59 -0700736 /* Address does not automatically update if reading */
737 snd_soc_write(codec,
738 (TAIKO_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
Ben Romberger205e14d2013-02-06 12:31:53 -0800739 ((band_idx * BAND_MAX + coeff_idx)
740 * sizeof(uint32_t)) & 0x7F);
741
742 value |= snd_soc_read(codec,
743 (TAIKO_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx));
744
745 snd_soc_write(codec,
746 (TAIKO_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
747 ((band_idx * BAND_MAX + coeff_idx)
748 * sizeof(uint32_t) + 1) & 0x7F);
749
750 value |= (snd_soc_read(codec,
751 (TAIKO_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 8);
752
753 snd_soc_write(codec,
754 (TAIKO_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
755 ((band_idx * BAND_MAX + coeff_idx)
756 * sizeof(uint32_t) + 2) & 0x7F);
757
758 value |= (snd_soc_read(codec,
759 (TAIKO_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 16);
760
761 snd_soc_write(codec,
762 (TAIKO_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
763 ((band_idx * BAND_MAX + coeff_idx)
764 * sizeof(uint32_t) + 3) & 0x7F);
Kiran Kandic3b24402012-06-11 00:05:59 -0700765
766 /* Mask bits top 2 bits since they are reserved */
Ben Romberger205e14d2013-02-06 12:31:53 -0800767 value |= ((snd_soc_read(codec,
768 (TAIKO_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) & 0x3F) << 24);
769
770 return value;
Kiran Kandic3b24402012-06-11 00:05:59 -0700771}
772
773static int taiko_get_iir_band_audio_mixer(
774 struct snd_kcontrol *kcontrol,
775 struct snd_ctl_elem_value *ucontrol)
776{
777 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
778 int iir_idx = ((struct soc_multi_mixer_control *)
779 kcontrol->private_value)->reg;
780 int band_idx = ((struct soc_multi_mixer_control *)
781 kcontrol->private_value)->shift;
782
783 ucontrol->value.integer.value[0] =
784 get_iir_band_coeff(codec, iir_idx, band_idx, 0);
785 ucontrol->value.integer.value[1] =
786 get_iir_band_coeff(codec, iir_idx, band_idx, 1);
787 ucontrol->value.integer.value[2] =
788 get_iir_band_coeff(codec, iir_idx, band_idx, 2);
789 ucontrol->value.integer.value[3] =
790 get_iir_band_coeff(codec, iir_idx, band_idx, 3);
791 ucontrol->value.integer.value[4] =
792 get_iir_band_coeff(codec, iir_idx, band_idx, 4);
793
794 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
795 "%s: IIR #%d band #%d b1 = 0x%x\n"
796 "%s: IIR #%d band #%d b2 = 0x%x\n"
797 "%s: IIR #%d band #%d a1 = 0x%x\n"
798 "%s: IIR #%d band #%d a2 = 0x%x\n",
799 __func__, iir_idx, band_idx,
800 (uint32_t)ucontrol->value.integer.value[0],
801 __func__, iir_idx, band_idx,
802 (uint32_t)ucontrol->value.integer.value[1],
803 __func__, iir_idx, band_idx,
804 (uint32_t)ucontrol->value.integer.value[2],
805 __func__, iir_idx, band_idx,
806 (uint32_t)ucontrol->value.integer.value[3],
807 __func__, iir_idx, band_idx,
808 (uint32_t)ucontrol->value.integer.value[4]);
809 return 0;
810}
811
812static void set_iir_band_coeff(struct snd_soc_codec *codec,
813 int iir_idx, int band_idx,
Ben Romberger205e14d2013-02-06 12:31:53 -0800814 uint32_t value)
Kiran Kandic3b24402012-06-11 00:05:59 -0700815{
Kiran Kandic3b24402012-06-11 00:05:59 -0700816 snd_soc_write(codec,
Ben Romberger205e14d2013-02-06 12:31:53 -0800817 (TAIKO_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
818 (value & 0xFF));
819
820 snd_soc_write(codec,
821 (TAIKO_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
822 (value >> 8) & 0xFF);
823
824 snd_soc_write(codec,
825 (TAIKO_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
826 (value >> 16) & 0xFF);
Kiran Kandic3b24402012-06-11 00:05:59 -0700827
828 /* Mask top 2 bits, 7-8 are reserved */
829 snd_soc_write(codec,
830 (TAIKO_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx),
831 (value >> 24) & 0x3F);
Kiran Kandic3b24402012-06-11 00:05:59 -0700832}
833
834static int taiko_put_iir_band_audio_mixer(
835 struct snd_kcontrol *kcontrol,
836 struct snd_ctl_elem_value *ucontrol)
837{
838 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
839 int iir_idx = ((struct soc_multi_mixer_control *)
840 kcontrol->private_value)->reg;
841 int band_idx = ((struct soc_multi_mixer_control *)
842 kcontrol->private_value)->shift;
843
Ben Romberger205e14d2013-02-06 12:31:53 -0800844 /* Mask top bit it is reserved */
845 /* Updates addr automatically for each B2 write */
846 snd_soc_write(codec,
847 (TAIKO_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx),
848 (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
849
850 set_iir_band_coeff(codec, iir_idx, band_idx,
Kiran Kandic3b24402012-06-11 00:05:59 -0700851 ucontrol->value.integer.value[0]);
Ben Romberger205e14d2013-02-06 12:31:53 -0800852 set_iir_band_coeff(codec, iir_idx, band_idx,
Kiran Kandic3b24402012-06-11 00:05:59 -0700853 ucontrol->value.integer.value[1]);
Ben Romberger205e14d2013-02-06 12:31:53 -0800854 set_iir_band_coeff(codec, iir_idx, band_idx,
Kiran Kandic3b24402012-06-11 00:05:59 -0700855 ucontrol->value.integer.value[2]);
Ben Romberger205e14d2013-02-06 12:31:53 -0800856 set_iir_band_coeff(codec, iir_idx, band_idx,
Kiran Kandic3b24402012-06-11 00:05:59 -0700857 ucontrol->value.integer.value[3]);
Ben Romberger205e14d2013-02-06 12:31:53 -0800858 set_iir_band_coeff(codec, iir_idx, band_idx,
Kiran Kandic3b24402012-06-11 00:05:59 -0700859 ucontrol->value.integer.value[4]);
860
861 pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
862 "%s: IIR #%d band #%d b1 = 0x%x\n"
863 "%s: IIR #%d band #%d b2 = 0x%x\n"
864 "%s: IIR #%d band #%d a1 = 0x%x\n"
865 "%s: IIR #%d band #%d a2 = 0x%x\n",
866 __func__, iir_idx, band_idx,
867 get_iir_band_coeff(codec, iir_idx, band_idx, 0),
868 __func__, iir_idx, band_idx,
869 get_iir_band_coeff(codec, iir_idx, band_idx, 1),
870 __func__, iir_idx, band_idx,
871 get_iir_band_coeff(codec, iir_idx, band_idx, 2),
872 __func__, iir_idx, band_idx,
873 get_iir_band_coeff(codec, iir_idx, band_idx, 3),
874 __func__, iir_idx, band_idx,
875 get_iir_band_coeff(codec, iir_idx, band_idx, 4));
876 return 0;
877}
878
Kiran Kandic3b24402012-06-11 00:05:59 -0700879static int taiko_get_compander(struct snd_kcontrol *kcontrol,
Joonwoo Parkc7731432012-10-17 12:41:44 -0700880 struct snd_ctl_elem_value *ucontrol)
Kiran Kandic3b24402012-06-11 00:05:59 -0700881{
882
883 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
884 int comp = ((struct soc_multi_mixer_control *)
Joonwoo Parkc7731432012-10-17 12:41:44 -0700885 kcontrol->private_value)->shift;
Kiran Kandic3b24402012-06-11 00:05:59 -0700886 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
887
888 ucontrol->value.integer.value[0] = taiko->comp_enabled[comp];
Kiran Kandic3b24402012-06-11 00:05:59 -0700889 return 0;
890}
891
892static int taiko_set_compander(struct snd_kcontrol *kcontrol,
Joonwoo Parkc7731432012-10-17 12:41:44 -0700893 struct snd_ctl_elem_value *ucontrol)
Kiran Kandic3b24402012-06-11 00:05:59 -0700894{
895 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
896 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
897 int comp = ((struct soc_multi_mixer_control *)
Joonwoo Parkc7731432012-10-17 12:41:44 -0700898 kcontrol->private_value)->shift;
Kiran Kandic3b24402012-06-11 00:05:59 -0700899 int value = ucontrol->value.integer.value[0];
900
Joonwoo Parkc7731432012-10-17 12:41:44 -0700901 pr_debug("%s: Compander %d enable current %d, new %d\n",
902 __func__, comp, taiko->comp_enabled[comp], value);
Kiran Kandic3b24402012-06-11 00:05:59 -0700903 taiko->comp_enabled[comp] = value;
Bhalchandra Gajareef7810e2013-03-29 16:50:37 -0700904
905 if (comp == COMPANDER_1 &&
906 taiko->comp_enabled[comp] == 1) {
907 /* Wavegen to 5 msec */
908 snd_soc_write(codec, TAIKO_A_RX_HPH_CNP_WG_CTL, 0xDA);
909 snd_soc_write(codec, TAIKO_A_RX_HPH_CNP_WG_TIME, 0x15);
910 snd_soc_write(codec, TAIKO_A_RX_HPH_BIAS_WG_OCP, 0x2A);
911
912 /* Enable Chopper */
913 snd_soc_update_bits(codec,
914 TAIKO_A_RX_HPH_CHOP_CTL, 0x80, 0x80);
Bhalchandra Gajare9581aed2013-03-29 17:06:10 -0700915
916 snd_soc_write(codec, TAIKO_A_NCP_DTEST, 0x20);
Bhalchandra Gajareef7810e2013-03-29 16:50:37 -0700917 pr_debug("%s: Enabled Chopper and set wavegen to 5 msec\n",
918 __func__);
919 } else if (comp == COMPANDER_1 &&
920 taiko->comp_enabled[comp] == 0) {
921 /* Wavegen to 20 msec */
922 snd_soc_write(codec, TAIKO_A_RX_HPH_CNP_WG_CTL, 0xDB);
923 snd_soc_write(codec, TAIKO_A_RX_HPH_CNP_WG_TIME, 0x58);
924 snd_soc_write(codec, TAIKO_A_RX_HPH_BIAS_WG_OCP, 0x1A);
925
926 /* Disable CHOPPER block */
927 snd_soc_update_bits(codec,
928 TAIKO_A_RX_HPH_CHOP_CTL, 0x80, 0x00);
Bhalchandra Gajare9581aed2013-03-29 17:06:10 -0700929
930 snd_soc_write(codec, TAIKO_A_NCP_DTEST, 0x10);
Bhalchandra Gajareef7810e2013-03-29 16:50:37 -0700931 pr_debug("%s: Disabled Chopper and set wavegen to 20 msec\n",
932 __func__);
933 }
Kiran Kandic3b24402012-06-11 00:05:59 -0700934 return 0;
935}
936
Joonwoo Parkc7731432012-10-17 12:41:44 -0700937static int taiko_config_gain_compander(struct snd_soc_codec *codec,
938 int comp, bool enable)
939{
940 int ret = 0;
941
942 switch (comp) {
943 case COMPANDER_0:
944 snd_soc_update_bits(codec, TAIKO_A_SPKR_DRV_GAIN,
945 1 << 2, !enable << 2);
946 break;
947 case COMPANDER_1:
948 snd_soc_update_bits(codec, TAIKO_A_RX_HPH_L_GAIN,
949 1 << 5, !enable << 5);
950 snd_soc_update_bits(codec, TAIKO_A_RX_HPH_R_GAIN,
951 1 << 5, !enable << 5);
952 break;
953 case COMPANDER_2:
954 snd_soc_update_bits(codec, TAIKO_A_RX_LINE_1_GAIN,
955 1 << 5, !enable << 5);
956 snd_soc_update_bits(codec, TAIKO_A_RX_LINE_3_GAIN,
957 1 << 5, !enable << 5);
958 snd_soc_update_bits(codec, TAIKO_A_RX_LINE_2_GAIN,
959 1 << 5, !enable << 5);
960 snd_soc_update_bits(codec, TAIKO_A_RX_LINE_4_GAIN,
961 1 << 5, !enable << 5);
962 break;
963 default:
964 WARN_ON(1);
965 ret = -EINVAL;
966 }
967
968 return ret;
969}
970
971static void taiko_discharge_comp(struct snd_soc_codec *codec, int comp)
972{
Bhalchandra Gajareed090e62013-03-29 16:11:49 -0700973 /* Level meter DIV Factor to 5*/
Joonwoo Parkc7731432012-10-17 12:41:44 -0700974 snd_soc_update_bits(codec, TAIKO_A_CDC_COMP0_B2_CTL + (comp * 8), 0xF0,
Bhalchandra Gajareed090e62013-03-29 16:11:49 -0700975 0x05 << 4);
976 /* RMS meter Sampling to 0x01 */
977 snd_soc_write(codec, TAIKO_A_CDC_COMP0_B3_CTL + (comp * 8), 0x01);
978
979 /* Worst case timeout for compander CnP sleep timeout */
980 usleep_range(3000, 3000);
981}
982
983static enum wcd9xxx_buck_volt taiko_codec_get_buck_mv(
984 struct snd_soc_codec *codec)
985{
986 int buck_volt = WCD9XXX_CDC_BUCK_UNSUPPORTED;
987 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
988 struct wcd9xxx_pdata *pdata = taiko->resmgr.pdata;
989 int i;
990
991 for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
992 if (!strncmp(pdata->regulator[i].name,
993 WCD9XXX_SUPPLY_BUCK_NAME,
994 sizeof(WCD9XXX_SUPPLY_BUCK_NAME))) {
995 if ((pdata->regulator[i].min_uV ==
996 WCD9XXX_CDC_BUCK_MV_1P8) ||
997 (pdata->regulator[i].min_uV ==
998 WCD9XXX_CDC_BUCK_MV_2P15))
999 buck_volt = pdata->regulator[i].min_uV;
1000 break;
1001 }
1002 }
1003 return buck_volt;
Joonwoo Parkc7731432012-10-17 12:41:44 -07001004}
Kiran Kandic3b24402012-06-11 00:05:59 -07001005
1006static int taiko_config_compander(struct snd_soc_dapm_widget *w,
Joonwoo Parkc7731432012-10-17 12:41:44 -07001007 struct snd_kcontrol *kcontrol, int event)
Kiran Kandic3b24402012-06-11 00:05:59 -07001008{
Bhalchandra Gajareed090e62013-03-29 16:11:49 -07001009 int mask, enable_mask;
Kiran Kandic3b24402012-06-11 00:05:59 -07001010 struct snd_soc_codec *codec = w->codec;
1011 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
Joonwoo Parkc7731432012-10-17 12:41:44 -07001012 const int comp = w->shift;
1013 const u32 rate = taiko->comp_fs[comp];
1014 const struct comp_sample_dependent_params *comp_params =
1015 &comp_samp_params[rate];
Bhalchandra Gajareed090e62013-03-29 16:11:49 -07001016 enum wcd9xxx_buck_volt buck_mv;
Kiran Kandic3b24402012-06-11 00:05:59 -07001017
Joonwoo Parkc7731432012-10-17 12:41:44 -07001018 pr_debug("%s: %s event %d compander %d, enabled %d", __func__,
1019 w->name, event, comp, taiko->comp_enabled[comp]);
1020
1021 if (!taiko->comp_enabled[comp])
1022 return 0;
1023
1024 /* Compander 0 has single channel */
1025 mask = (comp == COMPANDER_0 ? 0x01 : 0x03);
Bhalchandra Gajareed090e62013-03-29 16:11:49 -07001026 enable_mask = (comp == COMPANDER_0 ? 0x02 : 0x03);
1027 buck_mv = taiko_codec_get_buck_mv(codec);
Kiran Kandid2b46332012-10-05 12:04:00 -07001028
Kiran Kandic3b24402012-06-11 00:05:59 -07001029 switch (event) {
1030 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajareed090e62013-03-29 16:11:49 -07001031 /* Set compander Sample rate */
1032 snd_soc_update_bits(codec,
1033 TAIKO_A_CDC_COMP0_FS_CFG + (comp * 8),
1034 0x07, rate);
1035 /* Set the static gain offset */
1036 if (comp == COMPANDER_1
1037 && buck_mv == WCD9XXX_CDC_BUCK_MV_2P15) {
1038 snd_soc_update_bits(codec,
1039 TAIKO_A_CDC_COMP0_B4_CTL + (comp * 8),
1040 0x80, 0x80);
1041 } else {
1042 snd_soc_update_bits(codec,
1043 TAIKO_A_CDC_COMP0_B4_CTL + (comp * 8),
1044 0x80, 0x00);
1045 }
1046 /* Enable RX interpolation path compander clocks */
Joonwoo Parkc7731432012-10-17 12:41:44 -07001047 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_RX_B2_CTL,
1048 mask << comp_shift[comp],
1049 mask << comp_shift[comp]);
Joonwoo Parkc7731432012-10-17 12:41:44 -07001050 /* Toggle compander reset bits */
1051 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_OTHR_RESET_B2_CTL,
1052 mask << comp_shift[comp],
1053 mask << comp_shift[comp]);
1054 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_OTHR_RESET_B2_CTL,
1055 mask << comp_shift[comp], 0);
Bhalchandra Gajareed090e62013-03-29 16:11:49 -07001056
1057 /* Set gain source to compander */
1058 taiko_config_gain_compander(codec, comp, true);
1059
1060 /* Compander enable */
1061 snd_soc_update_bits(codec, TAIKO_A_CDC_COMP0_B1_CTL +
1062 (comp * 8), enable_mask, enable_mask);
1063
1064 taiko_discharge_comp(codec, comp);
1065
Joonwoo Parkc7731432012-10-17 12:41:44 -07001066 /* Set sample rate dependent paramater */
Joonwoo Parkc7731432012-10-17 12:41:44 -07001067 snd_soc_write(codec, TAIKO_A_CDC_COMP0_B3_CTL + (comp * 8),
1068 comp_params->rms_meter_resamp_fact);
1069 snd_soc_update_bits(codec,
1070 TAIKO_A_CDC_COMP0_B2_CTL + (comp * 8),
Joonwoo Parkc7731432012-10-17 12:41:44 -07001071 0xF0, comp_params->rms_meter_div_fact << 4);
Bhalchandra Gajareed090e62013-03-29 16:11:49 -07001072 snd_soc_update_bits(codec,
1073 TAIKO_A_CDC_COMP0_B2_CTL + (comp * 8),
1074 0x0F, comp_params->peak_det_timeout);
Kiran Kandic3b24402012-06-11 00:05:59 -07001075 break;
1076 case SND_SOC_DAPM_PRE_PMD:
Joonwoo Parkc7731432012-10-17 12:41:44 -07001077 /* Disable compander */
1078 snd_soc_update_bits(codec,
1079 TAIKO_A_CDC_COMP0_B1_CTL + (comp * 8),
Bhalchandra Gajareed090e62013-03-29 16:11:49 -07001080 enable_mask, 0x00);
1081
1082 /* Toggle compander reset bits */
1083 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_OTHR_RESET_B2_CTL,
1084 mask << comp_shift[comp],
1085 mask << comp_shift[comp]);
1086 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_OTHR_RESET_B2_CTL,
1087 mask << comp_shift[comp], 0);
1088
Joonwoo Parkc7731432012-10-17 12:41:44 -07001089 /* Turn off the clock for compander in pair */
1090 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_RX_B2_CTL,
1091 mask << comp_shift[comp], 0);
Bhalchandra Gajareed090e62013-03-29 16:11:49 -07001092
Joonwoo Parkc7731432012-10-17 12:41:44 -07001093 /* Set gain source to register */
1094 taiko_config_gain_compander(codec, comp, false);
Kiran Kandic3b24402012-06-11 00:05:59 -07001095 break;
1096 }
1097 return 0;
1098}
1099
Kiran Kandiec0db5c2013-03-08 16:03:58 -08001100
Kiran Kandic3b24402012-06-11 00:05:59 -07001101
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08001102static const char *const taiko_anc_func_text[] = {"OFF", "ON"};
1103static const struct soc_enum taiko_anc_func_enum =
1104 SOC_ENUM_SINGLE_EXT(2, taiko_anc_func_text);
1105
1106static const char *const tabla_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"};
1107static const struct soc_enum tabla_ear_pa_gain_enum[] = {
1108 SOC_ENUM_SINGLE_EXT(2, tabla_ear_pa_gain_text),
1109};
1110
Kiran Kandic3b24402012-06-11 00:05:59 -07001111/*cut of frequency for high pass filter*/
1112static const char * const cf_text[] = {
1113 "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz"
1114};
1115
1116static const struct soc_enum cf_dec1_enum =
1117 SOC_ENUM_SINGLE(TAIKO_A_CDC_TX1_MUX_CTL, 4, 3, cf_text);
1118
1119static const struct soc_enum cf_dec2_enum =
1120 SOC_ENUM_SINGLE(TAIKO_A_CDC_TX2_MUX_CTL, 4, 3, cf_text);
1121
1122static const struct soc_enum cf_dec3_enum =
1123 SOC_ENUM_SINGLE(TAIKO_A_CDC_TX3_MUX_CTL, 4, 3, cf_text);
1124
1125static const struct soc_enum cf_dec4_enum =
1126 SOC_ENUM_SINGLE(TAIKO_A_CDC_TX4_MUX_CTL, 4, 3, cf_text);
1127
1128static const struct soc_enum cf_dec5_enum =
1129 SOC_ENUM_SINGLE(TAIKO_A_CDC_TX5_MUX_CTL, 4, 3, cf_text);
1130
1131static const struct soc_enum cf_dec6_enum =
1132 SOC_ENUM_SINGLE(TAIKO_A_CDC_TX6_MUX_CTL, 4, 3, cf_text);
1133
1134static const struct soc_enum cf_dec7_enum =
1135 SOC_ENUM_SINGLE(TAIKO_A_CDC_TX7_MUX_CTL, 4, 3, cf_text);
1136
1137static const struct soc_enum cf_dec8_enum =
1138 SOC_ENUM_SINGLE(TAIKO_A_CDC_TX8_MUX_CTL, 4, 3, cf_text);
1139
1140static const struct soc_enum cf_dec9_enum =
1141 SOC_ENUM_SINGLE(TAIKO_A_CDC_TX9_MUX_CTL, 4, 3, cf_text);
1142
1143static const struct soc_enum cf_dec10_enum =
1144 SOC_ENUM_SINGLE(TAIKO_A_CDC_TX10_MUX_CTL, 4, 3, cf_text);
1145
1146static const struct soc_enum cf_rxmix1_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001147 SOC_ENUM_SINGLE(TAIKO_A_CDC_RX1_B4_CTL, 0, 3, cf_text);
Kiran Kandic3b24402012-06-11 00:05:59 -07001148
1149static const struct soc_enum cf_rxmix2_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001150 SOC_ENUM_SINGLE(TAIKO_A_CDC_RX2_B4_CTL, 0, 3, cf_text);
Kiran Kandic3b24402012-06-11 00:05:59 -07001151
1152static const struct soc_enum cf_rxmix3_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001153 SOC_ENUM_SINGLE(TAIKO_A_CDC_RX3_B4_CTL, 0, 3, cf_text);
Kiran Kandic3b24402012-06-11 00:05:59 -07001154
1155static const struct soc_enum cf_rxmix4_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001156 SOC_ENUM_SINGLE(TAIKO_A_CDC_RX4_B4_CTL, 0, 3, cf_text);
Kiran Kandic3b24402012-06-11 00:05:59 -07001157
1158static const struct soc_enum cf_rxmix5_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001159 SOC_ENUM_SINGLE(TAIKO_A_CDC_RX5_B4_CTL, 0, 3, cf_text)
Kiran Kandic3b24402012-06-11 00:05:59 -07001160;
1161static const struct soc_enum cf_rxmix6_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001162 SOC_ENUM_SINGLE(TAIKO_A_CDC_RX6_B4_CTL, 0, 3, cf_text);
Kiran Kandic3b24402012-06-11 00:05:59 -07001163
1164static const struct soc_enum cf_rxmix7_enum =
Joonwoo Park2000a982013-03-01 14:50:31 -08001165 SOC_ENUM_SINGLE(TAIKO_A_CDC_RX7_B4_CTL, 0, 3, cf_text);
Kiran Kandic3b24402012-06-11 00:05:59 -07001166
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08001167static const char * const class_h_dsm_text[] = {
1168 "ZERO", "DSM_HPHL_RX1", "DSM_SPKR_RX7"
1169};
1170
1171static const struct soc_enum class_h_dsm_enum =
1172 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_CLSH_CTL, 4, 3, class_h_dsm_text);
1173
1174static const struct snd_kcontrol_new class_h_dsm_mux =
1175 SOC_DAPM_ENUM("CLASS_H_DSM MUX Mux", class_h_dsm_enum);
1176
1177
Kiran Kandic3b24402012-06-11 00:05:59 -07001178static const struct snd_kcontrol_new taiko_snd_controls[] = {
1179
Kiran Kandic3b24402012-06-11 00:05:59 -07001180 SOC_SINGLE_S8_TLV("RX1 Digital Volume", TAIKO_A_CDC_RX1_VOL_CTL_B2_CTL,
1181 -84, 40, digital_gain),
1182 SOC_SINGLE_S8_TLV("RX2 Digital Volume", TAIKO_A_CDC_RX2_VOL_CTL_B2_CTL,
1183 -84, 40, digital_gain),
1184 SOC_SINGLE_S8_TLV("RX3 Digital Volume", TAIKO_A_CDC_RX3_VOL_CTL_B2_CTL,
1185 -84, 40, digital_gain),
1186 SOC_SINGLE_S8_TLV("RX4 Digital Volume", TAIKO_A_CDC_RX4_VOL_CTL_B2_CTL,
1187 -84, 40, digital_gain),
1188 SOC_SINGLE_S8_TLV("RX5 Digital Volume", TAIKO_A_CDC_RX5_VOL_CTL_B2_CTL,
1189 -84, 40, digital_gain),
1190 SOC_SINGLE_S8_TLV("RX6 Digital Volume", TAIKO_A_CDC_RX6_VOL_CTL_B2_CTL,
1191 -84, 40, digital_gain),
1192 SOC_SINGLE_S8_TLV("RX7 Digital Volume", TAIKO_A_CDC_RX7_VOL_CTL_B2_CTL,
1193 -84, 40, digital_gain),
1194
1195 SOC_SINGLE_S8_TLV("DEC1 Volume", TAIKO_A_CDC_TX1_VOL_CTL_GAIN, -84, 40,
1196 digital_gain),
1197 SOC_SINGLE_S8_TLV("DEC2 Volume", TAIKO_A_CDC_TX2_VOL_CTL_GAIN, -84, 40,
1198 digital_gain),
1199 SOC_SINGLE_S8_TLV("DEC3 Volume", TAIKO_A_CDC_TX3_VOL_CTL_GAIN, -84, 40,
1200 digital_gain),
1201 SOC_SINGLE_S8_TLV("DEC4 Volume", TAIKO_A_CDC_TX4_VOL_CTL_GAIN, -84, 40,
1202 digital_gain),
1203 SOC_SINGLE_S8_TLV("DEC5 Volume", TAIKO_A_CDC_TX5_VOL_CTL_GAIN, -84, 40,
1204 digital_gain),
1205 SOC_SINGLE_S8_TLV("DEC6 Volume", TAIKO_A_CDC_TX6_VOL_CTL_GAIN, -84, 40,
1206 digital_gain),
1207 SOC_SINGLE_S8_TLV("DEC7 Volume", TAIKO_A_CDC_TX7_VOL_CTL_GAIN, -84, 40,
1208 digital_gain),
1209 SOC_SINGLE_S8_TLV("DEC8 Volume", TAIKO_A_CDC_TX8_VOL_CTL_GAIN, -84, 40,
1210 digital_gain),
1211 SOC_SINGLE_S8_TLV("DEC9 Volume", TAIKO_A_CDC_TX9_VOL_CTL_GAIN, -84, 40,
1212 digital_gain),
1213 SOC_SINGLE_S8_TLV("DEC10 Volume", TAIKO_A_CDC_TX10_VOL_CTL_GAIN, -84,
1214 40, digital_gain),
Kiran Kandiec0db5c2013-03-08 16:03:58 -08001215
Kiran Kandic3b24402012-06-11 00:05:59 -07001216 SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TAIKO_A_CDC_IIR1_GAIN_B1_CTL, -84,
1217 40, digital_gain),
1218 SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TAIKO_A_CDC_IIR1_GAIN_B2_CTL, -84,
1219 40, digital_gain),
1220 SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TAIKO_A_CDC_IIR1_GAIN_B3_CTL, -84,
1221 40, digital_gain),
1222 SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TAIKO_A_CDC_IIR1_GAIN_B4_CTL, -84,
1223 40, digital_gain),
Fred Oh456fcb52013-02-28 19:08:15 -08001224 SOC_SINGLE_S8_TLV("IIR2 INP1 Volume", TAIKO_A_CDC_IIR2_GAIN_B1_CTL, -84,
1225 40, digital_gain),
1226 SOC_SINGLE_S8_TLV("IIR2 INP2 Volume", TAIKO_A_CDC_IIR2_GAIN_B2_CTL, -84,
1227 40, digital_gain),
1228 SOC_SINGLE_S8_TLV("IIR2 INP3 Volume", TAIKO_A_CDC_IIR2_GAIN_B3_CTL, -84,
1229 40, digital_gain),
1230 SOC_SINGLE_S8_TLV("IIR2 INP4 Volume", TAIKO_A_CDC_IIR2_GAIN_B4_CTL, -84,
1231 40, digital_gain),
Kiran Kandic3b24402012-06-11 00:05:59 -07001232
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08001233 SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 100, 0, taiko_get_anc_slot,
Kiran Kandic3b24402012-06-11 00:05:59 -07001234 taiko_put_anc_slot),
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08001235 SOC_ENUM_EXT("ANC Function", taiko_anc_func_enum, taiko_get_anc_func,
1236 taiko_put_anc_func),
Kiran Kandiec0db5c2013-03-08 16:03:58 -08001237
Kiran Kandic3b24402012-06-11 00:05:59 -07001238 SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
1239 SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
1240 SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
1241 SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
1242 SOC_ENUM("TX5 HPF cut off", cf_dec5_enum),
1243 SOC_ENUM("TX6 HPF cut off", cf_dec6_enum),
1244 SOC_ENUM("TX7 HPF cut off", cf_dec7_enum),
1245 SOC_ENUM("TX8 HPF cut off", cf_dec8_enum),
1246 SOC_ENUM("TX9 HPF cut off", cf_dec9_enum),
1247 SOC_ENUM("TX10 HPF cut off", cf_dec10_enum),
1248
1249 SOC_SINGLE("TX1 HPF Switch", TAIKO_A_CDC_TX1_MUX_CTL, 3, 1, 0),
1250 SOC_SINGLE("TX2 HPF Switch", TAIKO_A_CDC_TX2_MUX_CTL, 3, 1, 0),
1251 SOC_SINGLE("TX3 HPF Switch", TAIKO_A_CDC_TX3_MUX_CTL, 3, 1, 0),
1252 SOC_SINGLE("TX4 HPF Switch", TAIKO_A_CDC_TX4_MUX_CTL, 3, 1, 0),
1253 SOC_SINGLE("TX5 HPF Switch", TAIKO_A_CDC_TX5_MUX_CTL, 3, 1, 0),
1254 SOC_SINGLE("TX6 HPF Switch", TAIKO_A_CDC_TX6_MUX_CTL, 3, 1, 0),
1255 SOC_SINGLE("TX7 HPF Switch", TAIKO_A_CDC_TX7_MUX_CTL, 3, 1, 0),
1256 SOC_SINGLE("TX8 HPF Switch", TAIKO_A_CDC_TX8_MUX_CTL, 3, 1, 0),
1257 SOC_SINGLE("TX9 HPF Switch", TAIKO_A_CDC_TX9_MUX_CTL, 3, 1, 0),
1258 SOC_SINGLE("TX10 HPF Switch", TAIKO_A_CDC_TX10_MUX_CTL, 3, 1, 0),
1259
1260 SOC_SINGLE("RX1 HPF Switch", TAIKO_A_CDC_RX1_B5_CTL, 2, 1, 0),
1261 SOC_SINGLE("RX2 HPF Switch", TAIKO_A_CDC_RX2_B5_CTL, 2, 1, 0),
1262 SOC_SINGLE("RX3 HPF Switch", TAIKO_A_CDC_RX3_B5_CTL, 2, 1, 0),
1263 SOC_SINGLE("RX4 HPF Switch", TAIKO_A_CDC_RX4_B5_CTL, 2, 1, 0),
1264 SOC_SINGLE("RX5 HPF Switch", TAIKO_A_CDC_RX5_B5_CTL, 2, 1, 0),
1265 SOC_SINGLE("RX6 HPF Switch", TAIKO_A_CDC_RX6_B5_CTL, 2, 1, 0),
1266 SOC_SINGLE("RX7 HPF Switch", TAIKO_A_CDC_RX7_B5_CTL, 2, 1, 0),
1267
1268 SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum),
1269 SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum),
1270 SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum),
1271 SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum),
1272 SOC_ENUM("RX5 HPF cut off", cf_rxmix5_enum),
1273 SOC_ENUM("RX6 HPF cut off", cf_rxmix6_enum),
1274 SOC_ENUM("RX7 HPF cut off", cf_rxmix7_enum),
1275
1276 SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
1277 taiko_get_iir_enable_audio_mixer, taiko_put_iir_enable_audio_mixer),
1278 SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
1279 taiko_get_iir_enable_audio_mixer, taiko_put_iir_enable_audio_mixer),
1280 SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
1281 taiko_get_iir_enable_audio_mixer, taiko_put_iir_enable_audio_mixer),
1282 SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
1283 taiko_get_iir_enable_audio_mixer, taiko_put_iir_enable_audio_mixer),
1284 SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
1285 taiko_get_iir_enable_audio_mixer, taiko_put_iir_enable_audio_mixer),
1286 SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0,
1287 taiko_get_iir_enable_audio_mixer, taiko_put_iir_enable_audio_mixer),
1288 SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0,
1289 taiko_get_iir_enable_audio_mixer, taiko_put_iir_enable_audio_mixer),
1290 SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0,
1291 taiko_get_iir_enable_audio_mixer, taiko_put_iir_enable_audio_mixer),
1292 SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0,
1293 taiko_get_iir_enable_audio_mixer, taiko_put_iir_enable_audio_mixer),
1294 SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0,
1295 taiko_get_iir_enable_audio_mixer, taiko_put_iir_enable_audio_mixer),
1296
1297 SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
1298 taiko_get_iir_band_audio_mixer, taiko_put_iir_band_audio_mixer),
1299 SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
1300 taiko_get_iir_band_audio_mixer, taiko_put_iir_band_audio_mixer),
1301 SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
1302 taiko_get_iir_band_audio_mixer, taiko_put_iir_band_audio_mixer),
1303 SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
1304 taiko_get_iir_band_audio_mixer, taiko_put_iir_band_audio_mixer),
1305 SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
1306 taiko_get_iir_band_audio_mixer, taiko_put_iir_band_audio_mixer),
1307 SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5,
1308 taiko_get_iir_band_audio_mixer, taiko_put_iir_band_audio_mixer),
1309 SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5,
1310 taiko_get_iir_band_audio_mixer, taiko_put_iir_band_audio_mixer),
1311 SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5,
1312 taiko_get_iir_band_audio_mixer, taiko_put_iir_band_audio_mixer),
1313 SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5,
1314 taiko_get_iir_band_audio_mixer, taiko_put_iir_band_audio_mixer),
1315 SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5,
1316 taiko_get_iir_band_audio_mixer, taiko_put_iir_band_audio_mixer),
1317
Joonwoo Parkc7731432012-10-17 12:41:44 -07001318 SOC_SINGLE_EXT("COMP0 Switch", SND_SOC_NOPM, COMPANDER_0, 1, 0,
1319 taiko_get_compander, taiko_set_compander),
1320 SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, COMPANDER_1, 1, 0,
1321 taiko_get_compander, taiko_set_compander),
1322 SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, COMPANDER_2, 1, 0,
1323 taiko_get_compander, taiko_set_compander),
Kiran Kandic3b24402012-06-11 00:05:59 -07001324
1325};
1326
Kiran Kandiec0db5c2013-03-08 16:03:58 -08001327static int taiko_pa_gain_get(struct snd_kcontrol *kcontrol,
1328 struct snd_ctl_elem_value *ucontrol)
1329{
1330 u8 ear_pa_gain;
1331 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1332
1333 ear_pa_gain = snd_soc_read(codec, TAIKO_A_RX_EAR_GAIN);
1334
1335 ear_pa_gain = ear_pa_gain >> 5;
1336
1337 ucontrol->value.integer.value[0] = ear_pa_gain;
1338
1339 pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain);
1340
1341 return 0;
1342}
1343
1344static int taiko_pa_gain_put(struct snd_kcontrol *kcontrol,
1345 struct snd_ctl_elem_value *ucontrol)
1346{
1347 u8 ear_pa_gain;
1348 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1349
1350 pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__,
1351 ucontrol->value.integer.value[0]);
1352
1353 ear_pa_gain = ucontrol->value.integer.value[0] << 5;
1354
1355 snd_soc_update_bits(codec, TAIKO_A_RX_EAR_GAIN, 0xE0, ear_pa_gain);
1356 return 0;
1357}
1358
1359static const char * const taiko_1_x_ear_pa_gain_text[] = {
1360 "POS_6_DB", "UNDEFINED_1", "UNDEFINED_2", "UNDEFINED_3", "POS_2_DB",
1361 "NEG_2P5_DB", "UNDEFINED_4", "NEG_12_DB"
1362};
1363
1364static const struct soc_enum taiko_1_x_ear_pa_gain_enum =
1365 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(taiko_1_x_ear_pa_gain_text),
1366 taiko_1_x_ear_pa_gain_text);
1367
1368static const struct snd_kcontrol_new taiko_1_x_analog_gain_controls[] = {
1369
1370 SOC_ENUM_EXT("EAR PA Gain", taiko_1_x_ear_pa_gain_enum,
1371 taiko_pa_gain_get, taiko_pa_gain_put),
1372
1373 SOC_SINGLE_TLV("HPHL Volume", TAIKO_A_RX_HPH_L_GAIN, 0, 20, 1,
1374 line_gain),
1375 SOC_SINGLE_TLV("HPHR Volume", TAIKO_A_RX_HPH_R_GAIN, 0, 20, 1,
1376 line_gain),
1377
1378 SOC_SINGLE_TLV("LINEOUT1 Volume", TAIKO_A_RX_LINE_1_GAIN, 0, 20, 1,
1379 line_gain),
1380 SOC_SINGLE_TLV("LINEOUT2 Volume", TAIKO_A_RX_LINE_2_GAIN, 0, 20, 1,
1381 line_gain),
1382 SOC_SINGLE_TLV("LINEOUT3 Volume", TAIKO_A_RX_LINE_3_GAIN, 0, 20, 1,
1383 line_gain),
1384 SOC_SINGLE_TLV("LINEOUT4 Volume", TAIKO_A_RX_LINE_4_GAIN, 0, 20, 1,
1385 line_gain),
1386
1387 SOC_SINGLE_TLV("SPK DRV Volume", TAIKO_A_SPKR_DRV_GAIN, 3, 7, 1,
1388 line_gain),
1389
1390 SOC_SINGLE_TLV("ADC1 Volume", TAIKO_A_TX_1_2_EN, 5, 3, 0, analog_gain),
1391 SOC_SINGLE_TLV("ADC2 Volume", TAIKO_A_TX_1_2_EN, 1, 3, 0, analog_gain),
1392 SOC_SINGLE_TLV("ADC3 Volume", TAIKO_A_TX_3_4_EN, 5, 3, 0, analog_gain),
1393 SOC_SINGLE_TLV("ADC4 Volume", TAIKO_A_TX_3_4_EN, 1, 3, 0, analog_gain),
1394 SOC_SINGLE_TLV("ADC5 Volume", TAIKO_A_TX_5_6_EN, 5, 3, 0, analog_gain),
1395 SOC_SINGLE_TLV("ADC6 Volume", TAIKO_A_TX_5_6_EN, 1, 3, 0, analog_gain),
1396};
1397
1398static const char * const taiko_2_x_ear_pa_gain_text[] = {
1399 "POS_6_DB", "POS_4P5_DB", "POS_3_DB", "POS_1P5_DB",
1400 "POS_0_DB", "NEG_2P5_DB", "UNDEFINED", "NEG_12_DB"
1401};
1402
1403static const struct soc_enum taiko_2_x_ear_pa_gain_enum =
1404 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(taiko_2_x_ear_pa_gain_text),
1405 taiko_2_x_ear_pa_gain_text);
1406
1407static const struct snd_kcontrol_new taiko_2_x_analog_gain_controls[] = {
1408
1409 SOC_ENUM_EXT("EAR PA Gain", taiko_2_x_ear_pa_gain_enum,
1410 taiko_pa_gain_get, taiko_pa_gain_put),
1411
1412 SOC_SINGLE_TLV("HPHL Volume", TAIKO_A_RX_HPH_L_GAIN, 0, 20, 1,
1413 line_gain),
1414 SOC_SINGLE_TLV("HPHR Volume", TAIKO_A_RX_HPH_R_GAIN, 0, 20, 1,
1415 line_gain),
1416
1417 SOC_SINGLE_TLV("LINEOUT1 Volume", TAIKO_A_RX_LINE_1_GAIN, 0, 20, 1,
1418 line_gain),
1419 SOC_SINGLE_TLV("LINEOUT2 Volume", TAIKO_A_RX_LINE_2_GAIN, 0, 20, 1,
1420 line_gain),
1421 SOC_SINGLE_TLV("LINEOUT3 Volume", TAIKO_A_RX_LINE_3_GAIN, 0, 20, 1,
1422 line_gain),
1423 SOC_SINGLE_TLV("LINEOUT4 Volume", TAIKO_A_RX_LINE_4_GAIN, 0, 20, 1,
1424 line_gain),
1425
1426 SOC_SINGLE_TLV("SPK DRV Volume", TAIKO_A_SPKR_DRV_GAIN, 3, 8, 1,
1427 line_gain),
1428
1429 SOC_SINGLE_TLV("ADC1 Volume", TAIKO_A_CDC_TX_1_GAIN, 2, 19, 0,
1430 analog_gain),
1431 SOC_SINGLE_TLV("ADC2 Volume", TAIKO_A_CDC_TX_2_GAIN, 2, 19, 0,
1432 analog_gain),
1433 SOC_SINGLE_TLV("ADC3 Volume", TAIKO_A_CDC_TX_3_GAIN, 2, 19, 0,
1434 analog_gain),
1435 SOC_SINGLE_TLV("ADC4 Volume", TAIKO_A_CDC_TX_4_GAIN, 2, 19, 0,
1436 analog_gain),
1437 SOC_SINGLE_TLV("ADC5 Volume", TAIKO_A_CDC_TX_5_GAIN, 2, 19, 0,
1438 analog_gain),
1439 SOC_SINGLE_TLV("ADC6 Volume", TAIKO_A_CDC_TX_6_GAIN, 2, 19, 0,
1440 analog_gain),
1441};
1442
Kiran Kandic3b24402012-06-11 00:05:59 -07001443static const char * const rx_mix1_text[] = {
1444 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4",
1445 "RX5", "RX6", "RX7"
1446};
1447
1448static const char * const rx_mix2_text[] = {
1449 "ZERO", "SRC1", "SRC2", "IIR1", "IIR2"
1450};
1451
Tanya Finkeldaaa6d12012-10-25 11:22:48 +02001452static const char * const rx_rdac5_text[] = {
1453 "DEM4", "DEM3_INV"
Kiran Kandic3b24402012-06-11 00:05:59 -07001454};
1455
Tanya Finkeldaaa6d12012-10-25 11:22:48 +02001456static const char * const rx_rdac7_text[] = {
1457 "DEM6", "DEM5_INV"
1458};
1459
1460
Kiran Kandic3b24402012-06-11 00:05:59 -07001461static const char * const sb_tx1_mux_text[] = {
1462 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1463 "DEC1"
1464};
1465
1466static const char * const sb_tx2_mux_text[] = {
1467 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1468 "DEC2"
1469};
1470
1471static const char * const sb_tx3_mux_text[] = {
1472 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1473 "DEC3"
1474};
1475
1476static const char * const sb_tx4_mux_text[] = {
1477 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1478 "DEC4"
1479};
1480
1481static const char * const sb_tx5_mux_text[] = {
1482 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1483 "DEC5"
1484};
1485
1486static const char * const sb_tx6_mux_text[] = {
1487 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1488 "DEC6"
1489};
1490
1491static const char * const sb_tx7_to_tx10_mux_text[] = {
1492 "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7",
1493 "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
1494 "DEC9", "DEC10"
1495};
1496
1497static const char * const dec1_mux_text[] = {
1498 "ZERO", "DMIC1", "ADC6",
1499};
1500
1501static const char * const dec2_mux_text[] = {
1502 "ZERO", "DMIC2", "ADC5",
1503};
1504
1505static const char * const dec3_mux_text[] = {
1506 "ZERO", "DMIC3", "ADC4",
1507};
1508
1509static const char * const dec4_mux_text[] = {
1510 "ZERO", "DMIC4", "ADC3",
1511};
1512
1513static const char * const dec5_mux_text[] = {
1514 "ZERO", "DMIC5", "ADC2",
1515};
1516
1517static const char * const dec6_mux_text[] = {
1518 "ZERO", "DMIC6", "ADC1",
1519};
1520
1521static const char * const dec7_mux_text[] = {
1522 "ZERO", "DMIC1", "DMIC6", "ADC1", "ADC6", "ANC1_FB", "ANC2_FB",
1523};
1524
1525static const char * const dec8_mux_text[] = {
1526 "ZERO", "DMIC2", "DMIC5", "ADC2", "ADC5",
1527};
1528
1529static const char * const dec9_mux_text[] = {
1530 "ZERO", "DMIC4", "DMIC5", "ADC2", "ADC3", "ADCMB", "ANC1_FB", "ANC2_FB",
1531};
1532
1533static const char * const dec10_mux_text[] = {
1534 "ZERO", "DMIC3", "DMIC6", "ADC1", "ADC4", "ADCMB", "ANC1_FB", "ANC2_FB",
1535};
1536
1537static const char * const anc_mux_text[] = {
1538 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6", "ADC_MB",
1539 "RSVD_1", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", "DMIC6"
1540};
1541
1542static const char * const anc1_fb_mux_text[] = {
1543 "ZERO", "EAR_HPH_L", "EAR_LINE_1",
1544};
1545
Fred Oh456fcb52013-02-28 19:08:15 -08001546static const char * const iir_inp1_text[] = {
Kiran Kandic3b24402012-06-11 00:05:59 -07001547 "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8",
1548 "DEC9", "DEC10", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7"
1549};
1550
1551static const struct soc_enum rx_mix1_inp1_chain_enum =
1552 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_mix1_text);
1553
1554static const struct soc_enum rx_mix1_inp2_chain_enum =
1555 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_mix1_text);
1556
1557static const struct soc_enum rx_mix1_inp3_chain_enum =
1558 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX1_B2_CTL, 0, 12, rx_mix1_text);
1559
1560static const struct soc_enum rx2_mix1_inp1_chain_enum =
1561 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_mix1_text);
1562
1563static const struct soc_enum rx2_mix1_inp2_chain_enum =
1564 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_mix1_text);
1565
1566static const struct soc_enum rx3_mix1_inp1_chain_enum =
1567 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX3_B1_CTL, 0, 12, rx_mix1_text);
1568
1569static const struct soc_enum rx3_mix1_inp2_chain_enum =
1570 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX3_B1_CTL, 4, 12, rx_mix1_text);
1571
1572static const struct soc_enum rx4_mix1_inp1_chain_enum =
1573 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX4_B1_CTL, 0, 12, rx_mix1_text);
1574
1575static const struct soc_enum rx4_mix1_inp2_chain_enum =
1576 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX4_B1_CTL, 4, 12, rx_mix1_text);
1577
1578static const struct soc_enum rx5_mix1_inp1_chain_enum =
1579 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX5_B1_CTL, 0, 12, rx_mix1_text);
1580
1581static const struct soc_enum rx5_mix1_inp2_chain_enum =
1582 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX5_B1_CTL, 4, 12, rx_mix1_text);
1583
1584static const struct soc_enum rx6_mix1_inp1_chain_enum =
1585 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX6_B1_CTL, 0, 12, rx_mix1_text);
1586
1587static const struct soc_enum rx6_mix1_inp2_chain_enum =
1588 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX6_B1_CTL, 4, 12, rx_mix1_text);
1589
1590static const struct soc_enum rx7_mix1_inp1_chain_enum =
1591 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX7_B1_CTL, 0, 12, rx_mix1_text);
1592
1593static const struct soc_enum rx7_mix1_inp2_chain_enum =
1594 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX7_B1_CTL, 4, 12, rx_mix1_text);
1595
1596static const struct soc_enum rx1_mix2_inp1_chain_enum =
1597 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text);
1598
1599static const struct soc_enum rx1_mix2_inp2_chain_enum =
1600 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text);
1601
1602static const struct soc_enum rx2_mix2_inp1_chain_enum =
1603 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text);
1604
1605static const struct soc_enum rx2_mix2_inp2_chain_enum =
1606 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text);
1607
1608static const struct soc_enum rx7_mix2_inp1_chain_enum =
1609 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX7_B3_CTL, 0, 5, rx_mix2_text);
1610
1611static const struct soc_enum rx7_mix2_inp2_chain_enum =
1612 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_RX7_B3_CTL, 3, 5, rx_mix2_text);
1613
Tanya Finkeldaaa6d12012-10-25 11:22:48 +02001614static const struct soc_enum rx_rdac5_enum =
1615 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_MISC, 2, 2, rx_rdac5_text);
Kiran Kandic3b24402012-06-11 00:05:59 -07001616
Tanya Finkeldaaa6d12012-10-25 11:22:48 +02001617static const struct soc_enum rx_rdac7_enum =
1618 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_MISC, 1, 2, rx_rdac7_text);
Kiran Kandic3b24402012-06-11 00:05:59 -07001619
1620static const struct soc_enum sb_tx1_mux_enum =
1621 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text);
1622
1623static const struct soc_enum sb_tx2_mux_enum =
1624 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_SB_B2_CTL, 0, 9, sb_tx2_mux_text);
1625
1626static const struct soc_enum sb_tx3_mux_enum =
1627 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_SB_B3_CTL, 0, 9, sb_tx3_mux_text);
1628
1629static const struct soc_enum sb_tx4_mux_enum =
1630 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_SB_B4_CTL, 0, 9, sb_tx4_mux_text);
1631
1632static const struct soc_enum sb_tx5_mux_enum =
1633 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text);
1634
1635static const struct soc_enum sb_tx6_mux_enum =
1636 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_SB_B6_CTL, 0, 9, sb_tx6_mux_text);
1637
1638static const struct soc_enum sb_tx7_mux_enum =
1639 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_SB_B7_CTL, 0, 18,
1640 sb_tx7_to_tx10_mux_text);
1641
1642static const struct soc_enum sb_tx8_mux_enum =
1643 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_SB_B8_CTL, 0, 18,
1644 sb_tx7_to_tx10_mux_text);
1645
1646static const struct soc_enum sb_tx9_mux_enum =
1647 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_SB_B9_CTL, 0, 18,
1648 sb_tx7_to_tx10_mux_text);
1649
1650static const struct soc_enum sb_tx10_mux_enum =
1651 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_SB_B10_CTL, 0, 18,
1652 sb_tx7_to_tx10_mux_text);
1653
1654static const struct soc_enum dec1_mux_enum =
1655 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_B1_CTL, 0, 3, dec1_mux_text);
1656
1657static const struct soc_enum dec2_mux_enum =
1658 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_B1_CTL, 2, 3, dec2_mux_text);
1659
1660static const struct soc_enum dec3_mux_enum =
1661 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_B1_CTL, 4, 3, dec3_mux_text);
1662
1663static const struct soc_enum dec4_mux_enum =
1664 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_B1_CTL, 6, 3, dec4_mux_text);
1665
1666static const struct soc_enum dec5_mux_enum =
1667 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_B2_CTL, 0, 3, dec5_mux_text);
1668
1669static const struct soc_enum dec6_mux_enum =
1670 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_B2_CTL, 2, 3, dec6_mux_text);
1671
1672static const struct soc_enum dec7_mux_enum =
1673 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_B2_CTL, 4, 7, dec7_mux_text);
1674
1675static const struct soc_enum dec8_mux_enum =
1676 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_B3_CTL, 0, 7, dec8_mux_text);
1677
1678static const struct soc_enum dec9_mux_enum =
1679 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_B3_CTL, 3, 8, dec9_mux_text);
1680
1681static const struct soc_enum dec10_mux_enum =
1682 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_TX_B4_CTL, 0, 8, dec10_mux_text);
1683
1684static const struct soc_enum anc1_mux_enum =
1685 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_ANC_B1_CTL, 0, 16, anc_mux_text);
1686
1687static const struct soc_enum anc2_mux_enum =
1688 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_ANC_B1_CTL, 4, 16, anc_mux_text);
1689
1690static const struct soc_enum anc1_fb_mux_enum =
1691 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text);
1692
1693static const struct soc_enum iir1_inp1_mux_enum =
Fred Oh456fcb52013-02-28 19:08:15 -08001694 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_EQ1_B1_CTL, 0, 18, iir_inp1_text);
1695
1696static const struct soc_enum iir2_inp1_mux_enum =
1697 SOC_ENUM_SINGLE(TAIKO_A_CDC_CONN_EQ2_B1_CTL, 0, 18, iir_inp1_text);
Kiran Kandic3b24402012-06-11 00:05:59 -07001698
1699static const struct snd_kcontrol_new rx_mix1_inp1_mux =
1700 SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum);
1701
1702static const struct snd_kcontrol_new rx_mix1_inp2_mux =
1703 SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum);
1704
1705static const struct snd_kcontrol_new rx_mix1_inp3_mux =
1706 SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum);
1707
1708static const struct snd_kcontrol_new rx2_mix1_inp1_mux =
1709 SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum);
1710
1711static const struct snd_kcontrol_new rx2_mix1_inp2_mux =
1712 SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum);
1713
1714static const struct snd_kcontrol_new rx3_mix1_inp1_mux =
1715 SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum);
1716
1717static const struct snd_kcontrol_new rx3_mix1_inp2_mux =
1718 SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum);
1719
1720static const struct snd_kcontrol_new rx4_mix1_inp1_mux =
1721 SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum);
1722
1723static const struct snd_kcontrol_new rx4_mix1_inp2_mux =
1724 SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum);
1725
1726static const struct snd_kcontrol_new rx5_mix1_inp1_mux =
1727 SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum);
1728
1729static const struct snd_kcontrol_new rx5_mix1_inp2_mux =
1730 SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum);
1731
1732static const struct snd_kcontrol_new rx6_mix1_inp1_mux =
1733 SOC_DAPM_ENUM("RX6 MIX1 INP1 Mux", rx6_mix1_inp1_chain_enum);
1734
1735static const struct snd_kcontrol_new rx6_mix1_inp2_mux =
1736 SOC_DAPM_ENUM("RX6 MIX1 INP2 Mux", rx6_mix1_inp2_chain_enum);
1737
1738static const struct snd_kcontrol_new rx7_mix1_inp1_mux =
1739 SOC_DAPM_ENUM("RX7 MIX1 INP1 Mux", rx7_mix1_inp1_chain_enum);
1740
1741static const struct snd_kcontrol_new rx7_mix1_inp2_mux =
1742 SOC_DAPM_ENUM("RX7 MIX1 INP2 Mux", rx7_mix1_inp2_chain_enum);
1743
1744static const struct snd_kcontrol_new rx1_mix2_inp1_mux =
1745 SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum);
1746
1747static const struct snd_kcontrol_new rx1_mix2_inp2_mux =
1748 SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum);
1749
1750static const struct snd_kcontrol_new rx2_mix2_inp1_mux =
1751 SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum);
1752
1753static const struct snd_kcontrol_new rx2_mix2_inp2_mux =
1754 SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum);
1755
1756static const struct snd_kcontrol_new rx7_mix2_inp1_mux =
1757 SOC_DAPM_ENUM("RX7 MIX2 INP1 Mux", rx7_mix2_inp1_chain_enum);
1758
1759static const struct snd_kcontrol_new rx7_mix2_inp2_mux =
1760 SOC_DAPM_ENUM("RX7 MIX2 INP2 Mux", rx7_mix2_inp2_chain_enum);
1761
Tanya Finkeldaaa6d12012-10-25 11:22:48 +02001762static const struct snd_kcontrol_new rx_dac5_mux =
1763 SOC_DAPM_ENUM("RDAC5 MUX Mux", rx_rdac5_enum);
Kiran Kandic3b24402012-06-11 00:05:59 -07001764
Tanya Finkeldaaa6d12012-10-25 11:22:48 +02001765static const struct snd_kcontrol_new rx_dac7_mux =
1766 SOC_DAPM_ENUM("RDAC7 MUX Mux", rx_rdac7_enum);
Kiran Kandic3b24402012-06-11 00:05:59 -07001767
1768static const struct snd_kcontrol_new sb_tx1_mux =
1769 SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum);
1770
1771static const struct snd_kcontrol_new sb_tx2_mux =
1772 SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum);
1773
1774static const struct snd_kcontrol_new sb_tx3_mux =
1775 SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum);
1776
1777static const struct snd_kcontrol_new sb_tx4_mux =
1778 SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum);
1779
1780static const struct snd_kcontrol_new sb_tx5_mux =
1781 SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum);
1782
1783static const struct snd_kcontrol_new sb_tx6_mux =
1784 SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum);
1785
1786static const struct snd_kcontrol_new sb_tx7_mux =
1787 SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum);
1788
1789static const struct snd_kcontrol_new sb_tx8_mux =
1790 SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum);
1791
1792static const struct snd_kcontrol_new sb_tx9_mux =
1793 SOC_DAPM_ENUM("SLIM TX9 MUX Mux", sb_tx9_mux_enum);
1794
1795static const struct snd_kcontrol_new sb_tx10_mux =
1796 SOC_DAPM_ENUM("SLIM TX10 MUX Mux", sb_tx10_mux_enum);
1797
1798
1799static int wcd9320_put_dec_enum(struct snd_kcontrol *kcontrol,
1800 struct snd_ctl_elem_value *ucontrol)
1801{
1802 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1803 struct snd_soc_dapm_widget *w = wlist->widgets[0];
1804 struct snd_soc_codec *codec = w->codec;
1805 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1806 unsigned int dec_mux, decimator;
1807 char *dec_name = NULL;
1808 char *widget_name = NULL;
1809 char *temp;
1810 u16 tx_mux_ctl_reg;
1811 u8 adc_dmic_sel = 0x0;
1812 int ret = 0;
1813
1814 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1815 return -EINVAL;
1816
1817 dec_mux = ucontrol->value.enumerated.item[0];
1818
1819 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
1820 if (!widget_name)
1821 return -ENOMEM;
1822 temp = widget_name;
1823
1824 dec_name = strsep(&widget_name, " ");
1825 widget_name = temp;
1826 if (!dec_name) {
1827 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
1828 ret = -EINVAL;
1829 goto out;
1830 }
1831
1832 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
1833 if (ret < 0) {
1834 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
1835 ret = -EINVAL;
1836 goto out;
1837 }
1838
1839 dev_dbg(w->dapm->dev, "%s(): widget = %s decimator = %u dec_mux = %u\n"
1840 , __func__, w->name, decimator, dec_mux);
1841
1842
1843 switch (decimator) {
1844 case 1:
1845 case 2:
1846 case 3:
1847 case 4:
1848 case 5:
1849 case 6:
1850 if (dec_mux == 1)
1851 adc_dmic_sel = 0x1;
1852 else
1853 adc_dmic_sel = 0x0;
1854 break;
1855 case 7:
1856 case 8:
1857 case 9:
1858 case 10:
1859 if ((dec_mux == 1) || (dec_mux == 2))
1860 adc_dmic_sel = 0x1;
1861 else
1862 adc_dmic_sel = 0x0;
1863 break;
1864 default:
1865 pr_err("%s: Invalid Decimator = %u\n", __func__, decimator);
1866 ret = -EINVAL;
1867 goto out;
1868 }
1869
1870 tx_mux_ctl_reg = TAIKO_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
1871
1872 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel);
1873
1874 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
1875
1876out:
1877 kfree(widget_name);
1878 return ret;
1879}
1880
1881#define WCD9320_DEC_ENUM(xname, xenum) \
1882{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
1883 .info = snd_soc_info_enum_double, \
1884 .get = snd_soc_dapm_get_enum_double, \
1885 .put = wcd9320_put_dec_enum, \
1886 .private_value = (unsigned long)&xenum }
1887
1888static const struct snd_kcontrol_new dec1_mux =
1889 WCD9320_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum);
1890
1891static const struct snd_kcontrol_new dec2_mux =
1892 WCD9320_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum);
1893
1894static const struct snd_kcontrol_new dec3_mux =
1895 WCD9320_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum);
1896
1897static const struct snd_kcontrol_new dec4_mux =
1898 WCD9320_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum);
1899
1900static const struct snd_kcontrol_new dec5_mux =
1901 WCD9320_DEC_ENUM("DEC5 MUX Mux", dec5_mux_enum);
1902
1903static const struct snd_kcontrol_new dec6_mux =
1904 WCD9320_DEC_ENUM("DEC6 MUX Mux", dec6_mux_enum);
1905
1906static const struct snd_kcontrol_new dec7_mux =
1907 WCD9320_DEC_ENUM("DEC7 MUX Mux", dec7_mux_enum);
1908
1909static const struct snd_kcontrol_new dec8_mux =
1910 WCD9320_DEC_ENUM("DEC8 MUX Mux", dec8_mux_enum);
1911
1912static const struct snd_kcontrol_new dec9_mux =
1913 WCD9320_DEC_ENUM("DEC9 MUX Mux", dec9_mux_enum);
1914
1915static const struct snd_kcontrol_new dec10_mux =
1916 WCD9320_DEC_ENUM("DEC10 MUX Mux", dec10_mux_enum);
1917
1918static const struct snd_kcontrol_new iir1_inp1_mux =
1919 SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum);
1920
Fred Oh456fcb52013-02-28 19:08:15 -08001921static const struct snd_kcontrol_new iir2_inp1_mux =
1922 SOC_DAPM_ENUM("IIR2 INP1 Mux", iir2_inp1_mux_enum);
1923
Kiran Kandic3b24402012-06-11 00:05:59 -07001924static const struct snd_kcontrol_new anc1_mux =
1925 SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum);
1926
1927static const struct snd_kcontrol_new anc2_mux =
1928 SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum);
1929
1930static const struct snd_kcontrol_new anc1_fb_mux =
1931 SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum);
1932
1933static const struct snd_kcontrol_new dac1_switch[] = {
1934 SOC_DAPM_SINGLE("Switch", TAIKO_A_RX_EAR_EN, 5, 1, 0)
1935};
1936static const struct snd_kcontrol_new hphl_switch[] = {
1937 SOC_DAPM_SINGLE("Switch", TAIKO_A_RX_HPH_L_DAC_CTL, 6, 1, 0)
1938};
1939
1940static const struct snd_kcontrol_new hphl_pa_mix[] = {
1941 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAIKO_A_RX_PA_AUX_IN_CONN,
1942 7, 1, 0),
1943};
1944
1945static const struct snd_kcontrol_new hphr_pa_mix[] = {
1946 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TAIKO_A_RX_PA_AUX_IN_CONN,
1947 6, 1, 0),
1948};
1949
1950static const struct snd_kcontrol_new ear_pa_mix[] = {
1951 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAIKO_A_RX_PA_AUX_IN_CONN,
1952 5, 1, 0),
1953};
1954static const struct snd_kcontrol_new lineout1_pa_mix[] = {
1955 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAIKO_A_RX_PA_AUX_IN_CONN,
1956 4, 1, 0),
1957};
1958
1959static const struct snd_kcontrol_new lineout2_pa_mix[] = {
1960 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TAIKO_A_RX_PA_AUX_IN_CONN,
1961 3, 1, 0),
1962};
1963
1964static const struct snd_kcontrol_new lineout3_pa_mix[] = {
1965 SOC_DAPM_SINGLE("AUX_PGA_L Switch", TAIKO_A_RX_PA_AUX_IN_CONN,
1966 2, 1, 0),
1967};
1968
1969static const struct snd_kcontrol_new lineout4_pa_mix[] = {
1970 SOC_DAPM_SINGLE("AUX_PGA_R Switch", TAIKO_A_RX_PA_AUX_IN_CONN,
1971 1, 1, 0),
1972};
1973
1974static const struct snd_kcontrol_new lineout3_ground_switch =
1975 SOC_DAPM_SINGLE("Switch", TAIKO_A_RX_LINE_3_DAC_CTL, 6, 1, 0);
1976
1977static const struct snd_kcontrol_new lineout4_ground_switch =
1978 SOC_DAPM_SINGLE("Switch", TAIKO_A_RX_LINE_4_DAC_CTL, 6, 1, 0);
1979
Joonwoo Park9ead0e92013-03-18 11:33:33 -07001980static const struct snd_kcontrol_new aif4_mad_switch =
1981 SOC_DAPM_SINGLE("Switch", TAIKO_A_CDC_CLK_OTHR_CTL, 4, 1, 0);
1982
Kuirong Wang906ac472012-07-09 12:54:44 -07001983/* virtual port entries */
1984static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol,
1985 struct snd_ctl_elem_value *ucontrol)
1986{
1987 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1988 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1989
1990 ucontrol->value.integer.value[0] = widget->value;
1991 return 0;
1992}
1993
1994static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol,
1995 struct snd_ctl_elem_value *ucontrol)
1996{
1997 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
1998 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
1999 struct snd_soc_codec *codec = widget->codec;
2000 struct taiko_priv *taiko_p = snd_soc_codec_get_drvdata(codec);
2001 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
2002 struct soc_multi_mixer_control *mixer =
2003 ((struct soc_multi_mixer_control *)kcontrol->private_value);
2004 u32 dai_id = widget->shift;
2005 u32 port_id = mixer->shift;
2006 u32 enable = ucontrol->value.integer.value[0];
Venkat Sudhir96dd28c2012-12-04 17:00:19 -08002007 u32 vtable = vport_check_table[dai_id];
Kuirong Wang906ac472012-07-09 12:54:44 -07002008
2009
2010 pr_debug("%s: wname %s cname %s value %u shift %d item %ld\n", __func__,
2011 widget->name, ucontrol->id.name, widget->value, widget->shift,
2012 ucontrol->value.integer.value[0]);
2013
2014 mutex_lock(&codec->mutex);
2015
2016 if (taiko_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
2017 if (dai_id != AIF1_CAP) {
2018 dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
2019 __func__);
2020 mutex_unlock(&codec->mutex);
2021 return -EINVAL;
2022 }
2023 }
Venkat Sudhira41630a2012-10-27 00:57:31 -07002024 switch (dai_id) {
2025 case AIF1_CAP:
2026 case AIF2_CAP:
2027 case AIF3_CAP:
2028 /* only add to the list if value not set
2029 */
2030 if (enable && !(widget->value & 1 << port_id)) {
Venkat Sudhir96dd28c2012-12-04 17:00:19 -08002031
2032 if (taiko_p->intf_type ==
2033 WCD9XXX_INTERFACE_TYPE_SLIMBUS)
2034 vtable = vport_check_table[dai_id];
2035 if (taiko_p->intf_type ==
2036 WCD9XXX_INTERFACE_TYPE_I2C)
2037 vtable = vport_i2s_check_table[dai_id];
2038
Venkat Sudhira41630a2012-10-27 00:57:31 -07002039 if (wcd9xxx_tx_vport_validation(
Venkat Sudhir96dd28c2012-12-04 17:00:19 -08002040 vtable,
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002041 port_id,
2042 taiko_p->dai)) {
Venkat Sudhira41630a2012-10-27 00:57:31 -07002043 pr_debug("%s: TX%u is used by other\n"
2044 "virtual port\n",
2045 __func__, port_id + 1);
2046 mutex_unlock(&codec->mutex);
2047 return -EINVAL;
2048 }
2049 widget->value |= 1 << port_id;
2050 list_add_tail(&core->tx_chs[port_id].list,
Kuirong Wang906ac472012-07-09 12:54:44 -07002051 &taiko_p->dai[dai_id].wcd9xxx_ch_list
Venkat Sudhira41630a2012-10-27 00:57:31 -07002052 );
2053 } else if (!enable && (widget->value & 1 << port_id)) {
2054 widget->value &= ~(1 << port_id);
2055 list_del_init(&core->tx_chs[port_id].list);
2056 } else {
2057 if (enable)
2058 pr_debug("%s: TX%u port is used by\n"
2059 "this virtual port\n",
2060 __func__, port_id + 1);
2061 else
2062 pr_debug("%s: TX%u port is not used by\n"
2063 "this virtual port\n",
2064 __func__, port_id + 1);
2065 /* avoid update power function */
2066 mutex_unlock(&codec->mutex);
2067 return 0;
2068 }
2069 break;
2070 default:
2071 pr_err("Unknown AIF %d\n", dai_id);
Kuirong Wang906ac472012-07-09 12:54:44 -07002072 mutex_unlock(&codec->mutex);
Venkat Sudhira41630a2012-10-27 00:57:31 -07002073 return -EINVAL;
Kuirong Wang906ac472012-07-09 12:54:44 -07002074 }
Kuirong Wang906ac472012-07-09 12:54:44 -07002075 pr_debug("%s: name %s sname %s updated value %u shift %d\n", __func__,
2076 widget->name, widget->sname, widget->value, widget->shift);
2077
2078 snd_soc_dapm_mixer_update_power(widget, kcontrol, enable);
2079
2080 mutex_unlock(&codec->mutex);
2081 return 0;
2082}
2083
2084static int slim_rx_mux_get(struct snd_kcontrol *kcontrol,
2085 struct snd_ctl_elem_value *ucontrol)
2086{
2087 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2088 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2089
2090 ucontrol->value.enumerated.item[0] = widget->value;
2091 return 0;
2092}
2093
2094static const char *const slim_rx_mux_text[] = {
2095 "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB"
2096};
2097
2098static int slim_rx_mux_put(struct snd_kcontrol *kcontrol,
2099 struct snd_ctl_elem_value *ucontrol)
2100{
2101 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
2102 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
2103 struct snd_soc_codec *codec = widget->codec;
2104 struct taiko_priv *taiko_p = snd_soc_codec_get_drvdata(codec);
2105 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
2106 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
2107 u32 port_id = widget->shift;
2108
2109 pr_debug("%s: wname %s cname %s value %u shift %d item %ld\n", __func__,
2110 widget->name, ucontrol->id.name, widget->value, widget->shift,
2111 ucontrol->value.integer.value[0]);
2112
2113 widget->value = ucontrol->value.enumerated.item[0];
2114
2115 mutex_lock(&codec->mutex);
2116
2117 if (taiko_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
Venkat Sudhir994193b2012-12-17 17:30:51 -08002118 if (widget->value > 2) {
Kuirong Wang906ac472012-07-09 12:54:44 -07002119 dev_err(codec->dev, "%s: invalid AIF for I2C mode\n",
2120 __func__);
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002121 goto err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002122 }
2123 }
2124 /* value need to match the Virtual port and AIF number
2125 */
2126 switch (widget->value) {
2127 case 0:
2128 list_del_init(&core->rx_chs[port_id].list);
2129 break;
2130 case 1:
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002131 if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port,
2132 &taiko_p->dai[AIF1_PB].wcd9xxx_ch_list))
2133 goto pr_err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002134 list_add_tail(&core->rx_chs[port_id].list,
2135 &taiko_p->dai[AIF1_PB].wcd9xxx_ch_list);
2136 break;
2137 case 2:
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002138 if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port,
Gopikrishnaiah Anandana8aec1f2013-01-23 14:26:27 -05002139 &taiko_p->dai[AIF2_PB].wcd9xxx_ch_list))
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002140 goto pr_err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002141 list_add_tail(&core->rx_chs[port_id].list,
2142 &taiko_p->dai[AIF2_PB].wcd9xxx_ch_list);
2143 break;
2144 case 3:
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002145 if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port,
Gopikrishnaiah Anandana8aec1f2013-01-23 14:26:27 -05002146 &taiko_p->dai[AIF3_PB].wcd9xxx_ch_list))
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002147 goto pr_err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002148 list_add_tail(&core->rx_chs[port_id].list,
2149 &taiko_p->dai[AIF3_PB].wcd9xxx_ch_list);
2150 break;
2151 default:
2152 pr_err("Unknown AIF %d\n", widget->value);
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002153 goto err;
Kuirong Wang906ac472012-07-09 12:54:44 -07002154 }
2155
2156 snd_soc_dapm_mux_update_power(widget, kcontrol, 1, widget->value, e);
2157
2158 mutex_unlock(&codec->mutex);
2159 return 0;
Kuirong Wangdcc392e2012-10-19 00:33:38 -07002160pr_err:
2161 pr_err("%s: RX%u is used by current requesting AIF_PB itself\n",
2162 __func__, port_id + 1);
2163err:
2164 mutex_unlock(&codec->mutex);
2165 return -EINVAL;
Kuirong Wang906ac472012-07-09 12:54:44 -07002166}
2167
2168static const struct soc_enum slim_rx_mux_enum =
2169 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text), slim_rx_mux_text);
2170
2171static const struct snd_kcontrol_new slim_rx_mux[TAIKO_RX_MAX] = {
2172 SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum,
2173 slim_rx_mux_get, slim_rx_mux_put),
2174 SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum,
2175 slim_rx_mux_get, slim_rx_mux_put),
2176 SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum,
2177 slim_rx_mux_get, slim_rx_mux_put),
2178 SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum,
2179 slim_rx_mux_get, slim_rx_mux_put),
2180 SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum,
2181 slim_rx_mux_get, slim_rx_mux_put),
2182 SOC_DAPM_ENUM_EXT("SLIM RX6 Mux", slim_rx_mux_enum,
2183 slim_rx_mux_get, slim_rx_mux_put),
2184 SOC_DAPM_ENUM_EXT("SLIM RX7 Mux", slim_rx_mux_enum,
2185 slim_rx_mux_get, slim_rx_mux_put),
2186};
2187
2188static const struct snd_kcontrol_new aif_cap_mixer[] = {
2189 SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, TAIKO_TX1, 1, 0,
2190 slim_tx_mixer_get, slim_tx_mixer_put),
2191 SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, TAIKO_TX2, 1, 0,
2192 slim_tx_mixer_get, slim_tx_mixer_put),
2193 SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, TAIKO_TX3, 1, 0,
2194 slim_tx_mixer_get, slim_tx_mixer_put),
2195 SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, TAIKO_TX4, 1, 0,
2196 slim_tx_mixer_get, slim_tx_mixer_put),
2197 SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, TAIKO_TX5, 1, 0,
2198 slim_tx_mixer_get, slim_tx_mixer_put),
2199 SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, TAIKO_TX6, 1, 0,
2200 slim_tx_mixer_get, slim_tx_mixer_put),
2201 SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, TAIKO_TX7, 1, 0,
2202 slim_tx_mixer_get, slim_tx_mixer_put),
2203 SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, TAIKO_TX8, 1, 0,
2204 slim_tx_mixer_get, slim_tx_mixer_put),
2205 SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, TAIKO_TX9, 1, 0,
2206 slim_tx_mixer_get, slim_tx_mixer_put),
2207 SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, TAIKO_TX10, 1, 0,
2208 slim_tx_mixer_get, slim_tx_mixer_put),
2209};
2210
Kiran Kandic3b24402012-06-11 00:05:59 -07002211static void taiko_codec_enable_adc_block(struct snd_soc_codec *codec,
2212 int enable)
2213{
2214 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
2215
2216 pr_debug("%s %d\n", __func__, enable);
2217
2218 if (enable) {
2219 taiko->adc_count++;
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08002220 snd_soc_update_bits(codec, WCD9XXX_A_CDC_CLK_OTHR_CTL,
2221 0x2, 0x2);
Kiran Kandic3b24402012-06-11 00:05:59 -07002222 } else {
2223 taiko->adc_count--;
2224 if (!taiko->adc_count)
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08002225 snd_soc_update_bits(codec, WCD9XXX_A_CDC_CLK_OTHR_CTL,
Kiran Kandic3b24402012-06-11 00:05:59 -07002226 0x2, 0x0);
2227 }
2228}
2229
2230static int taiko_codec_enable_adc(struct snd_soc_dapm_widget *w,
2231 struct snd_kcontrol *kcontrol, int event)
2232{
2233 struct snd_soc_codec *codec = w->codec;
2234 u16 adc_reg;
2235 u8 init_bit_shift;
Joonwoo Park2a9170a2013-03-04 17:05:57 -08002236 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
Kiran Kandic3b24402012-06-11 00:05:59 -07002237
2238 pr_debug("%s %d\n", __func__, event);
2239
Joonwoo Park2a9170a2013-03-04 17:05:57 -08002240 if (TAIKO_IS_1_0(core->version)) {
2241 if (w->reg == TAIKO_A_TX_1_2_EN) {
2242 adc_reg = TAIKO_A_TX_1_2_TEST_CTL;
2243 } else if (w->reg == TAIKO_A_TX_3_4_EN) {
2244 adc_reg = TAIKO_A_TX_3_4_TEST_CTL;
2245 } else if (w->reg == TAIKO_A_TX_5_6_EN) {
2246 adc_reg = TAIKO_A_TX_5_6_TEST_CTL;
2247 } else {
2248 pr_err("%s: Error, invalid adc register\n", __func__);
2249 return -EINVAL;
2250 }
Kiran Kandic3b24402012-06-11 00:05:59 -07002251
Joonwoo Park2a9170a2013-03-04 17:05:57 -08002252 if (w->shift == 3) {
2253 init_bit_shift = 6;
2254 } else if (w->shift == 7) {
2255 init_bit_shift = 7;
2256 } else {
2257 pr_err("%s: Error, invalid init bit postion adc register\n",
2258 __func__);
2259 return -EINVAL;
2260 }
2261 } else {
2262 switch (w->reg) {
2263 case TAIKO_A_CDC_TX_1_GAIN:
2264 adc_reg = TAIKO_A_TX_1_2_TEST_CTL;
2265 init_bit_shift = 7;
2266 break;
2267 case TAIKO_A_CDC_TX_2_GAIN:
2268 adc_reg = TAIKO_A_TX_1_2_TEST_CTL;
2269 init_bit_shift = 6;
2270 break;
2271 case TAIKO_A_CDC_TX_3_GAIN:
2272 adc_reg = TAIKO_A_TX_3_4_TEST_CTL;
2273 init_bit_shift = 7;
2274 break;
2275 case TAIKO_A_CDC_TX_4_GAIN:
2276 adc_reg = TAIKO_A_TX_3_4_TEST_CTL;
2277 init_bit_shift = 6;
2278 break;
2279 case TAIKO_A_CDC_TX_5_GAIN:
2280 adc_reg = TAIKO_A_TX_5_6_TEST_CTL;
2281 init_bit_shift = 7;
2282 break;
2283 case TAIKO_A_CDC_TX_6_GAIN:
2284 adc_reg = TAIKO_A_TX_5_6_TEST_CTL;
2285 init_bit_shift = 6;
2286 break;
2287 default:
2288 pr_err("%s: Error, invalid adc register\n", __func__);
2289 return -EINVAL;
2290 }
Kiran Kandic3b24402012-06-11 00:05:59 -07002291 }
2292
2293 switch (event) {
2294 case SND_SOC_DAPM_PRE_PMU:
2295 taiko_codec_enable_adc_block(codec, 1);
2296 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift,
2297 1 << init_bit_shift);
2298 break;
2299 case SND_SOC_DAPM_POST_PMU:
Kiran Kandic3b24402012-06-11 00:05:59 -07002300 snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00);
Kiran Kandic3b24402012-06-11 00:05:59 -07002301 break;
2302 case SND_SOC_DAPM_POST_PMD:
2303 taiko_codec_enable_adc_block(codec, 0);
2304 break;
2305 }
2306 return 0;
2307}
2308
Kiran Kandic3b24402012-06-11 00:05:59 -07002309static int taiko_codec_enable_aux_pga(struct snd_soc_dapm_widget *w,
2310 struct snd_kcontrol *kcontrol, int event)
2311{
2312 struct snd_soc_codec *codec = w->codec;
2313 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
2314
2315 pr_debug("%s: %d\n", __func__, event);
2316
2317 switch (event) {
2318 case SND_SOC_DAPM_PRE_PMU:
Joonwoo Parka8890262012-10-15 12:04:27 -07002319 WCD9XXX_BCL_LOCK(&taiko->resmgr);
2320 wcd9xxx_resmgr_get_bandgap(&taiko->resmgr,
2321 WCD9XXX_BANDGAP_AUDIO_MODE);
2322 /* AUX PGA requires RCO or MCLK */
2323 wcd9xxx_resmgr_get_clk_block(&taiko->resmgr, WCD9XXX_CLK_RCO);
2324 wcd9xxx_resmgr_enable_rx_bias(&taiko->resmgr, 1);
2325 WCD9XXX_BCL_UNLOCK(&taiko->resmgr);
Kiran Kandic3b24402012-06-11 00:05:59 -07002326 break;
2327
2328 case SND_SOC_DAPM_POST_PMD:
Joonwoo Parka8890262012-10-15 12:04:27 -07002329 WCD9XXX_BCL_LOCK(&taiko->resmgr);
2330 wcd9xxx_resmgr_enable_rx_bias(&taiko->resmgr, 0);
2331 wcd9xxx_resmgr_put_bandgap(&taiko->resmgr,
2332 WCD9XXX_BANDGAP_AUDIO_MODE);
2333 wcd9xxx_resmgr_put_clk_block(&taiko->resmgr, WCD9XXX_CLK_RCO);
2334 WCD9XXX_BCL_UNLOCK(&taiko->resmgr);
Kiran Kandic3b24402012-06-11 00:05:59 -07002335 break;
2336 }
2337 return 0;
2338}
2339
2340static int taiko_codec_enable_lineout(struct snd_soc_dapm_widget *w,
2341 struct snd_kcontrol *kcontrol, int event)
2342{
2343 struct snd_soc_codec *codec = w->codec;
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08002344 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
Kiran Kandic3b24402012-06-11 00:05:59 -07002345 u16 lineout_gain_reg;
2346
2347 pr_debug("%s %d %s\n", __func__, event, w->name);
2348
2349 switch (w->shift) {
2350 case 0:
2351 lineout_gain_reg = TAIKO_A_RX_LINE_1_GAIN;
2352 break;
2353 case 1:
2354 lineout_gain_reg = TAIKO_A_RX_LINE_2_GAIN;
2355 break;
2356 case 2:
2357 lineout_gain_reg = TAIKO_A_RX_LINE_3_GAIN;
2358 break;
2359 case 3:
2360 lineout_gain_reg = TAIKO_A_RX_LINE_4_GAIN;
2361 break;
2362 default:
2363 pr_err("%s: Error, incorrect lineout register value\n",
2364 __func__);
2365 return -EINVAL;
2366 }
2367
2368 switch (event) {
2369 case SND_SOC_DAPM_PRE_PMU:
2370 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40);
2371 break;
2372 case SND_SOC_DAPM_POST_PMU:
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08002373 wcd9xxx_clsh_fsm(codec, &taiko->clsh_d,
2374 WCD9XXX_CLSH_STATE_LO,
2375 WCD9XXX_CLSH_REQ_ENABLE,
2376 WCD9XXX_CLSH_EVENT_POST_PA);
2377 pr_debug("%s: sleeping 3 ms after %s PA turn on\n",
Kiran Kandic3b24402012-06-11 00:05:59 -07002378 __func__, w->name);
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08002379 usleep_range(3000, 3000);
Kiran Kandic3b24402012-06-11 00:05:59 -07002380 break;
2381 case SND_SOC_DAPM_POST_PMD:
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08002382 wcd9xxx_clsh_fsm(codec, &taiko->clsh_d,
2383 WCD9XXX_CLSH_STATE_LO,
2384 WCD9XXX_CLSH_REQ_DISABLE,
2385 WCD9XXX_CLSH_EVENT_POST_PA);
Kiran Kandic3b24402012-06-11 00:05:59 -07002386 snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00);
2387 break;
2388 }
2389 return 0;
2390}
2391
Joonwoo Park7680b9f2012-07-13 11:36:48 -07002392static int taiko_codec_enable_spk_pa(struct snd_soc_dapm_widget *w,
2393 struct snd_kcontrol *kcontrol, int event)
2394{
Joonwoo Park125cd4e2012-12-11 15:16:11 -08002395 struct snd_soc_codec *codec = w->codec;
2396 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
2397
2398 pr_debug("%s: %d %s\n", __func__, event, w->name);
2399 WCD9XXX_BCL_LOCK(&taiko->resmgr);
2400 switch (event) {
2401 case SND_SOC_DAPM_PRE_PMU:
2402 taiko->spkr_pa_widget_on = true;
2403 snd_soc_update_bits(codec, TAIKO_A_SPKR_DRV_EN, 0x80, 0x80);
2404 break;
2405 case SND_SOC_DAPM_POST_PMD:
2406 taiko->spkr_pa_widget_on = false;
2407 snd_soc_update_bits(codec, TAIKO_A_SPKR_DRV_EN, 0x80, 0x00);
2408 break;
2409 }
2410 WCD9XXX_BCL_UNLOCK(&taiko->resmgr);
Joonwoo Park7680b9f2012-07-13 11:36:48 -07002411 return 0;
2412}
Kiran Kandic3b24402012-06-11 00:05:59 -07002413
2414static int taiko_codec_enable_dmic(struct snd_soc_dapm_widget *w,
2415 struct snd_kcontrol *kcontrol, int event)
2416{
2417 struct snd_soc_codec *codec = w->codec;
2418 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
2419 u8 dmic_clk_en;
2420 u16 dmic_clk_reg;
2421 s32 *dmic_clk_cnt;
2422 unsigned int dmic;
2423 int ret;
2424
2425 ret = kstrtouint(strpbrk(w->name, "123456"), 10, &dmic);
2426 if (ret < 0) {
2427 pr_err("%s: Invalid DMIC line on the codec\n", __func__);
2428 return -EINVAL;
2429 }
2430
2431 switch (dmic) {
2432 case 1:
2433 case 2:
2434 dmic_clk_en = 0x01;
2435 dmic_clk_cnt = &(taiko->dmic_1_2_clk_cnt);
2436 dmic_clk_reg = TAIKO_A_CDC_CLK_DMIC_B1_CTL;
2437 pr_debug("%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n",
2438 __func__, event, dmic, *dmic_clk_cnt);
2439
2440 break;
2441
2442 case 3:
2443 case 4:
2444 dmic_clk_en = 0x10;
2445 dmic_clk_cnt = &(taiko->dmic_3_4_clk_cnt);
2446 dmic_clk_reg = TAIKO_A_CDC_CLK_DMIC_B1_CTL;
2447
2448 pr_debug("%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n",
2449 __func__, event, dmic, *dmic_clk_cnt);
2450 break;
2451
2452 case 5:
2453 case 6:
2454 dmic_clk_en = 0x01;
2455 dmic_clk_cnt = &(taiko->dmic_5_6_clk_cnt);
2456 dmic_clk_reg = TAIKO_A_CDC_CLK_DMIC_B2_CTL;
2457
2458 pr_debug("%s() event %d DMIC%d dmic_5_6_clk_cnt %d\n",
2459 __func__, event, dmic, *dmic_clk_cnt);
2460
2461 break;
2462
2463 default:
2464 pr_err("%s: Invalid DMIC Selection\n", __func__);
2465 return -EINVAL;
2466 }
2467
2468 switch (event) {
2469 case SND_SOC_DAPM_PRE_PMU:
2470
2471 (*dmic_clk_cnt)++;
2472 if (*dmic_clk_cnt == 1)
2473 snd_soc_update_bits(codec, dmic_clk_reg,
2474 dmic_clk_en, dmic_clk_en);
2475
2476 break;
2477 case SND_SOC_DAPM_POST_PMD:
2478
2479 (*dmic_clk_cnt)--;
2480 if (*dmic_clk_cnt == 0)
2481 snd_soc_update_bits(codec, dmic_clk_reg,
2482 dmic_clk_en, 0);
2483 break;
2484 }
2485 return 0;
2486}
2487
Joonwoo Park1d05bb92013-03-07 16:55:06 -08002488static int taiko_codec_config_mad(struct snd_soc_codec *codec)
2489{
2490 int ret;
2491 const struct firmware *fw;
2492 struct mad_audio_cal *mad_cal;
2493 const char *filename = TAIKO_MAD_AUDIO_FIRMWARE_PATH;
2494
2495 pr_debug("%s: enter\n", __func__);
2496 ret = request_firmware(&fw, filename, codec->dev);
2497 if (ret != 0) {
2498 pr_err("Failed to acquire MAD firwmare data %s: %d\n", filename,
2499 ret);
2500 return -ENODEV;
2501 }
2502
2503 if (fw->size < sizeof(struct mad_audio_cal)) {
2504 pr_err("%s: incorrect firmware size %u\n", __func__, fw->size);
2505 release_firmware(fw);
2506 return -ENOMEM;
2507 }
2508
2509 mad_cal = (struct mad_audio_cal *)(fw->data);
2510 if (!mad_cal) {
2511 pr_err("%s: Invalid calibration data\n", __func__);
2512 release_firmware(fw);
2513 return -EINVAL;
2514 }
2515
2516 snd_soc_update_bits(codec, TAIKO_A_CDC_CONN_MAD,
2517 0x0F, mad_cal->microphone_info.input_microphone);
2518 snd_soc_write(codec, TAIKO_A_CDC_MAD_MAIN_CTL_2,
2519 mad_cal->microphone_info.cycle_time);
2520 snd_soc_update_bits(codec, TAIKO_A_CDC_MAD_MAIN_CTL_1, 0xFF << 3,
2521 ((uint16_t)mad_cal->microphone_info.settle_time)
2522 << 3);
2523
2524 /* Audio */
2525 snd_soc_write(codec, TAIKO_A_CDC_MAD_AUDIO_CTL_8,
2526 mad_cal->audio_info.rms_omit_samples);
2527 snd_soc_update_bits(codec, TAIKO_A_CDC_MAD_AUDIO_CTL_1,
2528 0x07 << 4, mad_cal->audio_info.rms_comp_time << 4);
2529 snd_soc_update_bits(codec, TAIKO_A_CDC_MAD_AUDIO_CTL_2, 0x03 << 2,
2530 mad_cal->audio_info.detection_mechanism << 2);
2531 snd_soc_write(codec, TAIKO_A_CDC_MAD_AUDIO_CTL_7,
2532 mad_cal->audio_info.rms_diff_threshold & 0x3F);
2533 snd_soc_write(codec, TAIKO_A_CDC_MAD_AUDIO_CTL_5,
2534 mad_cal->audio_info.rms_threshold_lsb);
2535 snd_soc_write(codec, TAIKO_A_CDC_MAD_AUDIO_CTL_6,
2536 mad_cal->audio_info.rms_threshold_msb);
2537
2538
2539 /* Beacon */
2540 snd_soc_write(codec, TAIKO_A_CDC_MAD_BEACON_CTL_8,
2541 mad_cal->beacon_info.rms_omit_samples);
2542 snd_soc_update_bits(codec, TAIKO_A_CDC_MAD_BEACON_CTL_1,
2543 0x07 << 4, mad_cal->beacon_info.rms_comp_time);
2544 snd_soc_update_bits(codec, TAIKO_A_CDC_MAD_BEACON_CTL_2, 0x03 << 2,
2545 mad_cal->beacon_info.detection_mechanism << 2);
2546 snd_soc_write(codec, TAIKO_A_CDC_MAD_BEACON_CTL_7,
2547 mad_cal->beacon_info.rms_diff_threshold & 0x1F);
2548 snd_soc_write(codec, TAIKO_A_CDC_MAD_BEACON_CTL_5,
2549 mad_cal->beacon_info.rms_threshold_lsb);
2550 snd_soc_write(codec, TAIKO_A_CDC_MAD_BEACON_CTL_6,
2551 mad_cal->beacon_info.rms_threshold_msb);
2552
2553 /* Ultrasound */
2554 snd_soc_update_bits(codec, TAIKO_A_CDC_MAD_BEACON_CTL_1,
2555 0x07 << 4, mad_cal->beacon_info.rms_comp_time);
2556 snd_soc_update_bits(codec, TAIKO_A_CDC_MAD_ULTR_CTL_2, 0x03 << 2,
2557 mad_cal->ultrasound_info.detection_mechanism);
2558 snd_soc_write(codec, TAIKO_A_CDC_MAD_ULTR_CTL_7,
2559 mad_cal->ultrasound_info.rms_diff_threshold & 0x1F);
2560 snd_soc_write(codec, TAIKO_A_CDC_MAD_ULTR_CTL_5,
2561 mad_cal->ultrasound_info.rms_threshold_lsb);
2562 snd_soc_write(codec, TAIKO_A_CDC_MAD_ULTR_CTL_6,
2563 mad_cal->ultrasound_info.rms_threshold_msb);
2564
2565 release_firmware(fw);
2566 pr_debug("%s: leave ret %d\n", __func__, ret);
2567
2568 return ret;
2569}
2570
2571static int taiko_codec_enable_mad(struct snd_soc_dapm_widget *w,
2572 struct snd_kcontrol *kcontrol, int event)
2573{
2574 struct snd_soc_codec *codec = w->codec;
2575 int ret = 0;
2576
2577 pr_debug("%s %d\n", __func__, event);
2578 switch (event) {
2579 case SND_SOC_DAPM_PRE_PMU:
2580 ret = taiko_codec_config_mad(codec);
2581 if (ret) {
2582 pr_err("%s: Failed to config MAD\n", __func__);
2583 break;
2584 }
2585 break;
2586 }
2587 return ret;
2588}
2589
Kiran Kandic3b24402012-06-11 00:05:59 -07002590static int taiko_codec_enable_micbias(struct snd_soc_dapm_widget *w,
2591 struct snd_kcontrol *kcontrol, int event)
2592{
2593 struct snd_soc_codec *codec = w->codec;
2594 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
Joonwoo Park3699ca32013-02-08 12:06:15 -08002595 u16 micb_int_reg = 0, micb_ctl_reg = 0;
Kiran Kandic3b24402012-06-11 00:05:59 -07002596 u8 cfilt_sel_val = 0;
2597 char *internal1_text = "Internal1";
2598 char *internal2_text = "Internal2";
2599 char *internal3_text = "Internal3";
Joonwoo Parka8890262012-10-15 12:04:27 -07002600 enum wcd9xxx_notify_event e_post_off, e_pre_on, e_post_on;
Kiran Kandic3b24402012-06-11 00:05:59 -07002601
Joonwoo Park3699ca32013-02-08 12:06:15 -08002602 pr_debug("%s: w->name %s event %d\n", __func__, w->name, event);
2603 if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1"))) {
2604 micb_ctl_reg = TAIKO_A_MICB_1_CTL;
Kiran Kandic3b24402012-06-11 00:05:59 -07002605 micb_int_reg = TAIKO_A_MICB_1_INT_RBIAS;
Joonwoo Parka8890262012-10-15 12:04:27 -07002606 cfilt_sel_val = taiko->resmgr.pdata->micbias.bias1_cfilt_sel;
2607 e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_1_ON;
2608 e_post_on = WCD9XXX_EVENT_POST_MICBIAS_1_ON;
2609 e_post_off = WCD9XXX_EVENT_POST_MICBIAS_1_OFF;
Joonwoo Park3699ca32013-02-08 12:06:15 -08002610 } else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2"))) {
2611 micb_ctl_reg = TAIKO_A_MICB_2_CTL;
Kiran Kandic3b24402012-06-11 00:05:59 -07002612 micb_int_reg = TAIKO_A_MICB_2_INT_RBIAS;
Joonwoo Parka8890262012-10-15 12:04:27 -07002613 cfilt_sel_val = taiko->resmgr.pdata->micbias.bias2_cfilt_sel;
2614 e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_2_ON;
2615 e_post_on = WCD9XXX_EVENT_POST_MICBIAS_2_ON;
2616 e_post_off = WCD9XXX_EVENT_POST_MICBIAS_2_OFF;
Joonwoo Park3699ca32013-02-08 12:06:15 -08002617 } else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3"))) {
Damir Didjusto6e4f9d22013-03-07 10:10:57 -08002618 micb_ctl_reg = TAIKO_A_MICB_3_CTL;
Kiran Kandic3b24402012-06-11 00:05:59 -07002619 micb_int_reg = TAIKO_A_MICB_3_INT_RBIAS;
Joonwoo Parka8890262012-10-15 12:04:27 -07002620 cfilt_sel_val = taiko->resmgr.pdata->micbias.bias3_cfilt_sel;
2621 e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_3_ON;
2622 e_post_on = WCD9XXX_EVENT_POST_MICBIAS_3_ON;
2623 e_post_off = WCD9XXX_EVENT_POST_MICBIAS_3_OFF;
Joonwoo Park3699ca32013-02-08 12:06:15 -08002624 } else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4"))) {
Damir Didjusto6e4f9d22013-03-07 10:10:57 -08002625 micb_ctl_reg = TAIKO_A_MICB_4_CTL;
Joonwoo Parka8890262012-10-15 12:04:27 -07002626 micb_int_reg = taiko->resmgr.reg_addr->micb_4_int_rbias;
2627 cfilt_sel_val = taiko->resmgr.pdata->micbias.bias4_cfilt_sel;
2628 e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_4_ON;
2629 e_post_on = WCD9XXX_EVENT_POST_MICBIAS_4_ON;
2630 e_post_off = WCD9XXX_EVENT_POST_MICBIAS_4_OFF;
Joonwoo Park3699ca32013-02-08 12:06:15 -08002631 } else {
2632 pr_err("%s: Error, invalid micbias %s\n", __func__, w->name);
Kiran Kandic3b24402012-06-11 00:05:59 -07002633 return -EINVAL;
2634 }
2635
2636 switch (event) {
2637 case SND_SOC_DAPM_PRE_PMU:
Joonwoo Parka8890262012-10-15 12:04:27 -07002638 /* Let MBHC module know so micbias switch to be off */
2639 wcd9xxx_resmgr_notifier_call(&taiko->resmgr, e_pre_on);
Kiran Kandic3b24402012-06-11 00:05:59 -07002640
Joonwoo Parka8890262012-10-15 12:04:27 -07002641 /* Get cfilt */
2642 wcd9xxx_resmgr_cfilt_get(&taiko->resmgr, cfilt_sel_val);
Kiran Kandic3b24402012-06-11 00:05:59 -07002643
2644 if (strnstr(w->name, internal1_text, 30))
2645 snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0);
2646 else if (strnstr(w->name, internal2_text, 30))
2647 snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C);
2648 else if (strnstr(w->name, internal3_text, 30))
2649 snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3);
2650
Joonwoo Park3edb9892013-03-05 17:44:54 -08002651 if (micb_ctl_reg == TAIKO_A_MICB_2_CTL)
Joonwoo Park3699ca32013-02-08 12:06:15 -08002652 wcd9xxx_resmgr_add_cond_update_bits(&taiko->resmgr,
2653 WCD9XXX_COND_HPH_MIC,
2654 micb_ctl_reg, w->shift,
2655 false);
Joonwoo Park3edb9892013-03-05 17:44:54 -08002656 else
Joonwoo Park3699ca32013-02-08 12:06:15 -08002657 snd_soc_update_bits(codec, micb_ctl_reg, 1 << w->shift,
2658 1 << w->shift);
Kiran Kandic3b24402012-06-11 00:05:59 -07002659 break;
2660 case SND_SOC_DAPM_POST_PMU:
Kiran Kandic3b24402012-06-11 00:05:59 -07002661 usleep_range(20000, 20000);
Joonwoo Parka8890262012-10-15 12:04:27 -07002662 /* Let MBHC module know so micbias is on */
2663 wcd9xxx_resmgr_notifier_call(&taiko->resmgr, e_post_on);
Kiran Kandic3b24402012-06-11 00:05:59 -07002664 break;
Kiran Kandic3b24402012-06-11 00:05:59 -07002665 case SND_SOC_DAPM_POST_PMD:
Joonwoo Park3edb9892013-03-05 17:44:54 -08002666 if (micb_ctl_reg == TAIKO_A_MICB_2_CTL)
Joonwoo Park3699ca32013-02-08 12:06:15 -08002667 wcd9xxx_resmgr_rm_cond_update_bits(&taiko->resmgr,
2668 WCD9XXX_COND_HPH_MIC,
2669 micb_ctl_reg, 7, false);
Joonwoo Park3edb9892013-03-05 17:44:54 -08002670 else
Joonwoo Park3699ca32013-02-08 12:06:15 -08002671 snd_soc_update_bits(codec, micb_ctl_reg, 1 << w->shift,
2672 0);
2673
Joonwoo Parka8890262012-10-15 12:04:27 -07002674 /* Let MBHC module know so micbias switch to be off */
2675 wcd9xxx_resmgr_notifier_call(&taiko->resmgr, e_post_off);
Kiran Kandic3b24402012-06-11 00:05:59 -07002676
2677 if (strnstr(w->name, internal1_text, 30))
2678 snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00);
2679 else if (strnstr(w->name, internal2_text, 30))
2680 snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00);
2681 else if (strnstr(w->name, internal3_text, 30))
2682 snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0);
2683
Joonwoo Parka8890262012-10-15 12:04:27 -07002684 /* Put cfilt */
2685 wcd9xxx_resmgr_cfilt_put(&taiko->resmgr, cfilt_sel_val);
Kiran Kandic3b24402012-06-11 00:05:59 -07002686 break;
2687 }
2688
2689 return 0;
2690}
2691
2692
2693static void tx_hpf_corner_freq_callback(struct work_struct *work)
2694{
2695 struct delayed_work *hpf_delayed_work;
2696 struct hpf_work *hpf_work;
2697 struct taiko_priv *taiko;
2698 struct snd_soc_codec *codec;
2699 u16 tx_mux_ctl_reg;
2700 u8 hpf_cut_of_freq;
2701
2702 hpf_delayed_work = to_delayed_work(work);
2703 hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
2704 taiko = hpf_work->taiko;
2705 codec = hpf_work->taiko->codec;
2706 hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq;
2707
2708 tx_mux_ctl_reg = TAIKO_A_CDC_TX1_MUX_CTL +
2709 (hpf_work->decimator - 1) * 8;
2710
2711 pr_debug("%s(): decimator %u hpf_cut_of_freq 0x%x\n", __func__,
2712 hpf_work->decimator, (unsigned int)hpf_cut_of_freq);
2713
2714 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4);
2715}
2716
2717#define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30
2718#define CF_MIN_3DB_4HZ 0x0
2719#define CF_MIN_3DB_75HZ 0x1
2720#define CF_MIN_3DB_150HZ 0x2
2721
2722static int taiko_codec_enable_dec(struct snd_soc_dapm_widget *w,
2723 struct snd_kcontrol *kcontrol, int event)
2724{
2725 struct snd_soc_codec *codec = w->codec;
2726 unsigned int decimator;
2727 char *dec_name = NULL;
2728 char *widget_name = NULL;
2729 char *temp;
2730 int ret = 0;
2731 u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg;
2732 u8 dec_hpf_cut_of_freq;
2733 int offset;
2734
2735
2736 pr_debug("%s %d\n", __func__, event);
2737
2738 widget_name = kstrndup(w->name, 15, GFP_KERNEL);
2739 if (!widget_name)
2740 return -ENOMEM;
2741 temp = widget_name;
2742
2743 dec_name = strsep(&widget_name, " ");
2744 widget_name = temp;
2745 if (!dec_name) {
2746 pr_err("%s: Invalid decimator = %s\n", __func__, w->name);
2747 ret = -EINVAL;
2748 goto out;
2749 }
2750
2751 ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator);
2752 if (ret < 0) {
2753 pr_err("%s: Invalid decimator = %s\n", __func__, dec_name);
2754 ret = -EINVAL;
2755 goto out;
2756 }
2757
2758 pr_debug("%s(): widget = %s dec_name = %s decimator = %u\n", __func__,
2759 w->name, dec_name, decimator);
2760
2761 if (w->reg == TAIKO_A_CDC_CLK_TX_CLK_EN_B1_CTL) {
2762 dec_reset_reg = TAIKO_A_CDC_CLK_TX_RESET_B1_CTL;
2763 offset = 0;
2764 } else if (w->reg == TAIKO_A_CDC_CLK_TX_CLK_EN_B2_CTL) {
2765 dec_reset_reg = TAIKO_A_CDC_CLK_TX_RESET_B2_CTL;
2766 offset = 8;
2767 } else {
2768 pr_err("%s: Error, incorrect dec\n", __func__);
2769 return -EINVAL;
2770 }
2771
2772 tx_vol_ctl_reg = TAIKO_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator - 1);
2773 tx_mux_ctl_reg = TAIKO_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1);
2774
2775 switch (event) {
2776 case SND_SOC_DAPM_PRE_PMU:
2777
2778 /* Enableable TX digital mute */
2779 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
2780
2781 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift,
2782 1 << w->shift);
2783 snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0);
2784
2785 dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg);
2786
2787 dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4;
2788
2789 tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq =
2790 dec_hpf_cut_of_freq;
2791
2792 if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) {
2793
2794 /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */
2795 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
2796 CF_MIN_3DB_150HZ << 4);
2797 }
2798
2799 /* enable HPF */
2800 snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00);
2801
2802 break;
2803
2804 case SND_SOC_DAPM_POST_PMU:
2805
2806 /* Disable TX digital mute */
2807 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00);
2808
2809 if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq !=
2810 CF_MIN_3DB_150HZ) {
2811
2812 schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork,
2813 msecs_to_jiffies(300));
2814 }
2815 /* apply the digital gain after the decimator is enabled*/
Damir Didjustoed406e22012-11-16 15:44:57 -08002816 if ((w->shift + offset) < ARRAY_SIZE(tx_digital_gain_reg))
Kiran Kandic3b24402012-06-11 00:05:59 -07002817 snd_soc_write(codec,
2818 tx_digital_gain_reg[w->shift + offset],
2819 snd_soc_read(codec,
2820 tx_digital_gain_reg[w->shift + offset])
2821 );
2822
2823 break;
2824
2825 case SND_SOC_DAPM_PRE_PMD:
2826
2827 snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
2828 cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork);
2829 break;
2830
2831 case SND_SOC_DAPM_POST_PMD:
2832
2833 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08);
2834 snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
2835 (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4);
2836
2837 break;
2838 }
2839out:
2840 kfree(widget_name);
2841 return ret;
2842}
2843
Joonwoo Park125cd4e2012-12-11 15:16:11 -08002844static int taiko_codec_enable_vdd_spkr(struct snd_soc_dapm_widget *w,
2845 struct snd_kcontrol *kcontrol, int event)
2846{
2847 int ret = 0;
2848 struct snd_soc_codec *codec = w->codec;
2849 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
Joonwoo Park448a8fc2013-04-10 15:25:58 -07002850 struct taiko_priv *priv = snd_soc_codec_get_drvdata(codec);
Joonwoo Park125cd4e2012-12-11 15:16:11 -08002851
2852 pr_debug("%s: %d %s\n", __func__, event, w->name);
Joonwoo Park448a8fc2013-04-10 15:25:58 -07002853
2854 WARN_ONCE(!priv->spkdrv_reg, "SPKDRV supply %s isn't defined\n",
2855 WCD9XXX_VDD_SPKDRV_NAME);
Joonwoo Park125cd4e2012-12-11 15:16:11 -08002856 switch (event) {
2857 case SND_SOC_DAPM_PRE_PMU:
Joonwoo Park448a8fc2013-04-10 15:25:58 -07002858 if (priv->spkdrv_reg) {
2859 ret = regulator_enable(priv->spkdrv_reg);
2860 if (ret)
2861 pr_err("%s: Failed to enable spkdrv_reg %s\n",
2862 __func__, WCD9XXX_VDD_SPKDRV_NAME);
2863 }
Joonwoo Park125cd4e2012-12-11 15:16:11 -08002864 if (spkr_drv_wrnd > 0) {
2865 WARN_ON(!(snd_soc_read(codec, TAIKO_A_SPKR_DRV_EN) &
2866 0x80));
2867 snd_soc_update_bits(codec, TAIKO_A_SPKR_DRV_EN, 0x80,
2868 0x00);
2869 }
2870 if (TAIKO_IS_1_0(core->version))
2871 snd_soc_update_bits(codec, TAIKO_A_SPKR_DRV_DBG_PWRSTG,
2872 0x24, 0x00);
2873 break;
2874 case SND_SOC_DAPM_POST_PMD:
2875 if (TAIKO_IS_1_0(core->version))
2876 snd_soc_update_bits(codec, TAIKO_A_SPKR_DRV_DBG_PWRSTG,
2877 0x24, 0x24);
2878 if (spkr_drv_wrnd > 0) {
2879 WARN_ON(!!(snd_soc_read(codec, TAIKO_A_SPKR_DRV_EN) &
2880 0x80));
2881 snd_soc_update_bits(codec, TAIKO_A_SPKR_DRV_EN, 0x80,
2882 0x80);
2883 }
Joonwoo Park448a8fc2013-04-10 15:25:58 -07002884 if (priv->spkdrv_reg) {
2885 ret = regulator_disable(priv->spkdrv_reg);
2886 if (ret)
2887 pr_err("%s: Failed to disable spkdrv_reg %s\n",
2888 __func__, WCD9XXX_VDD_SPKDRV_NAME);
2889 }
Joonwoo Park125cd4e2012-12-11 15:16:11 -08002890 break;
2891 }
2892
2893 return ret;
2894}
2895
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07002896static int taiko_codec_enable_interpolator(struct snd_soc_dapm_widget *w,
Kiran Kandic3b24402012-06-11 00:05:59 -07002897 struct snd_kcontrol *kcontrol, int event)
2898{
2899 struct snd_soc_codec *codec = w->codec;
2900
2901 pr_debug("%s %d %s\n", __func__, event, w->name);
2902
2903 switch (event) {
2904 case SND_SOC_DAPM_PRE_PMU:
2905 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_RX_RESET_CTL,
2906 1 << w->shift, 1 << w->shift);
2907 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_RX_RESET_CTL,
2908 1 << w->shift, 0x0);
2909 break;
2910 case SND_SOC_DAPM_POST_PMU:
2911 /* apply the digital gain after the interpolator is enabled*/
2912 if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
2913 snd_soc_write(codec,
2914 rx_digital_gain_reg[w->shift],
2915 snd_soc_read(codec,
2916 rx_digital_gain_reg[w->shift])
2917 );
2918 break;
2919 }
2920 return 0;
2921}
2922
2923static int taiko_codec_enable_ldo_h(struct snd_soc_dapm_widget *w,
2924 struct snd_kcontrol *kcontrol, int event)
2925{
2926 switch (event) {
2927 case SND_SOC_DAPM_POST_PMU:
2928 case SND_SOC_DAPM_POST_PMD:
2929 usleep_range(1000, 1000);
2930 break;
2931 }
2932 return 0;
2933}
2934
2935static int taiko_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
2936 struct snd_kcontrol *kcontrol, int event)
2937{
2938 struct snd_soc_codec *codec = w->codec;
Joonwoo Parka8890262012-10-15 12:04:27 -07002939 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
Kiran Kandic3b24402012-06-11 00:05:59 -07002940
2941 pr_debug("%s %d\n", __func__, event);
2942
2943 switch (event) {
2944 case SND_SOC_DAPM_PRE_PMU:
Joonwoo Parka8890262012-10-15 12:04:27 -07002945 wcd9xxx_resmgr_enable_rx_bias(&taiko->resmgr, 1);
Kiran Kandic3b24402012-06-11 00:05:59 -07002946 break;
2947 case SND_SOC_DAPM_POST_PMD:
Joonwoo Parka8890262012-10-15 12:04:27 -07002948 wcd9xxx_resmgr_enable_rx_bias(&taiko->resmgr, 0);
Kiran Kandic3b24402012-06-11 00:05:59 -07002949 break;
2950 }
2951 return 0;
2952}
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08002953
2954static int taiko_hphl_dac_event(struct snd_soc_dapm_widget *w,
Kiran Kandic3b24402012-06-11 00:05:59 -07002955 struct snd_kcontrol *kcontrol, int event)
2956{
2957 struct snd_soc_codec *codec = w->codec;
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08002958 struct taiko_priv *taiko_p = snd_soc_codec_get_drvdata(codec);
Kiran Kandic3b24402012-06-11 00:05:59 -07002959
2960 pr_debug("%s %s %d\n", __func__, w->name, event);
2961
2962 switch (event) {
2963 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08002964 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_RDAC_CLK_EN_CTL,
2965 0x02, 0x02);
2966 wcd9xxx_clsh_fsm(codec, &taiko_p->clsh_d,
2967 WCD9XXX_CLSH_STATE_HPHL,
2968 WCD9XXX_CLSH_REQ_ENABLE,
2969 WCD9XXX_CLSH_EVENT_PRE_DAC);
Kiran Kandic3b24402012-06-11 00:05:59 -07002970 break;
2971 case SND_SOC_DAPM_POST_PMD:
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08002972 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_RDAC_CLK_EN_CTL,
2973 0x02, 0x00);
2974 }
2975 return 0;
2976}
2977
2978static int taiko_hphr_dac_event(struct snd_soc_dapm_widget *w,
2979 struct snd_kcontrol *kcontrol, int event)
2980{
2981 struct snd_soc_codec *codec = w->codec;
2982 struct taiko_priv *taiko_p = snd_soc_codec_get_drvdata(codec);
2983
2984 pr_debug("%s %s %d\n", __func__, w->name, event);
2985
2986 switch (event) {
2987 case SND_SOC_DAPM_PRE_PMU:
2988 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_RDAC_CLK_EN_CTL,
2989 0x04, 0x04);
2990 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
2991 wcd9xxx_clsh_fsm(codec, &taiko_p->clsh_d,
2992 WCD9XXX_CLSH_STATE_HPHR,
2993 WCD9XXX_CLSH_REQ_ENABLE,
2994 WCD9XXX_CLSH_EVENT_PRE_DAC);
2995 break;
2996 case SND_SOC_DAPM_POST_PMD:
2997 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_RDAC_CLK_EN_CTL,
2998 0x04, 0x00);
Kiran Kandic3b24402012-06-11 00:05:59 -07002999 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
3000 break;
3001 }
3002 return 0;
3003}
3004
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08003005static int taiko_codec_enable_anc(struct snd_soc_dapm_widget *w,
3006 struct snd_kcontrol *kcontrol, int event)
3007{
3008 struct snd_soc_codec *codec = w->codec;
3009 const char *filename;
3010 const struct firmware *fw;
3011 int i;
3012 int ret;
3013 int num_anc_slots;
Simmi Pateriyadf675e92013-04-05 01:15:54 +05303014 struct wcd9xxx_anc_header *anc_head;
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08003015 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
3016 u32 anc_writes_size = 0;
3017 int anc_size_remaining;
3018 u32 *anc_ptr;
3019 u16 reg;
3020 u8 mask, val, old_val;
3021
3022
3023 if (taiko->anc_func == 0)
3024 return 0;
3025
3026 switch (event) {
3027 case SND_SOC_DAPM_PRE_PMU:
3028 filename = "wcd9320/wcd9320_anc.bin";
3029
3030 ret = request_firmware(&fw, filename, codec->dev);
3031 if (ret != 0) {
3032 dev_err(codec->dev, "Failed to acquire ANC data: %d\n",
3033 ret);
3034 return -ENODEV;
3035 }
3036
Simmi Pateriyadf675e92013-04-05 01:15:54 +05303037 if (fw->size < sizeof(struct wcd9xxx_anc_header)) {
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08003038 dev_err(codec->dev, "Not enough data\n");
3039 release_firmware(fw);
3040 return -ENOMEM;
3041 }
3042
3043 /* First number is the number of register writes */
Simmi Pateriyadf675e92013-04-05 01:15:54 +05303044 anc_head = (struct wcd9xxx_anc_header *)(fw->data);
3045 anc_ptr = (u32 *)((u32)fw->data +
3046 sizeof(struct wcd9xxx_anc_header));
3047 anc_size_remaining = fw->size -
3048 sizeof(struct wcd9xxx_anc_header);
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08003049 num_anc_slots = anc_head->num_anc_slots;
3050
3051 if (taiko->anc_slot >= num_anc_slots) {
3052 dev_err(codec->dev, "Invalid ANC slot selected\n");
3053 release_firmware(fw);
3054 return -EINVAL;
3055 }
3056 for (i = 0; i < num_anc_slots; i++) {
3057 if (anc_size_remaining < TAIKO_PACKED_REG_SIZE) {
3058 dev_err(codec->dev, "Invalid register format\n");
3059 release_firmware(fw);
3060 return -EINVAL;
3061 }
3062 anc_writes_size = (u32)(*anc_ptr);
3063 anc_size_remaining -= sizeof(u32);
3064 anc_ptr += 1;
3065
3066 if (anc_writes_size * TAIKO_PACKED_REG_SIZE
3067 > anc_size_remaining) {
3068 dev_err(codec->dev, "Invalid register format\n");
3069 release_firmware(fw);
3070 return -ENOMEM;
3071 }
3072
3073 if (taiko->anc_slot == i)
3074 break;
3075
3076 anc_size_remaining -= (anc_writes_size *
3077 TAIKO_PACKED_REG_SIZE);
3078 anc_ptr += anc_writes_size;
3079 }
3080 if (i == num_anc_slots) {
3081 dev_err(codec->dev, "Selected ANC slot not present\n");
3082 release_firmware(fw);
3083 return -ENOMEM;
3084 }
3085 for (i = 0; i < anc_writes_size; i++) {
3086 TAIKO_CODEC_UNPACK_ENTRY(anc_ptr[i], reg,
3087 mask, val);
3088 old_val = snd_soc_read(codec, reg);
3089 snd_soc_write(codec, reg, (old_val & ~mask) |
3090 (val & mask));
3091 }
3092 release_firmware(fw);
3093 break;
3094 case SND_SOC_DAPM_POST_PMD:
3095 msleep(40);
3096 snd_soc_update_bits(codec, TAIKO_A_CDC_ANC1_B1_CTL, 0x01, 0x00);
3097 snd_soc_update_bits(codec, TAIKO_A_CDC_ANC2_B1_CTL, 0x02, 0x00);
3098 msleep(20);
3099 snd_soc_write(codec, TAIKO_A_CDC_CLK_ANC_RESET_CTL, 0x0F);
3100 snd_soc_write(codec, TAIKO_A_CDC_CLK_ANC_CLK_EN_CTL, 0);
3101 snd_soc_write(codec, TAIKO_A_CDC_CLK_ANC_RESET_CTL, 0xFF);
3102 break;
3103 }
3104 return 0;
3105}
3106
Kiran Kandic3b24402012-06-11 00:05:59 -07003107static int taiko_hph_pa_event(struct snd_soc_dapm_widget *w,
Joonwoo Parka8890262012-10-15 12:04:27 -07003108 struct snd_kcontrol *kcontrol, int event)
Kiran Kandic3b24402012-06-11 00:05:59 -07003109{
3110 struct snd_soc_codec *codec = w->codec;
3111 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
Joonwoo Parka8890262012-10-15 12:04:27 -07003112 enum wcd9xxx_notify_event e_pre_on, e_post_off;
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08003113 u8 req_clsh_state;
Bhalchandra Gajareef7810e2013-03-29 16:50:37 -07003114 u32 pa_settle_time = TAIKO_HPH_PA_SETTLE_COMP_OFF;
Joonwoo Parka8890262012-10-15 12:04:27 -07003115
Kiran Kandi4c56c592012-07-25 11:04:55 -07003116 pr_debug("%s: %s event = %d\n", __func__, w->name, event);
Joonwoo Parka8890262012-10-15 12:04:27 -07003117 if (w->shift == 5) {
Joonwoo Parka8890262012-10-15 12:04:27 -07003118 e_pre_on = WCD9XXX_EVENT_PRE_HPHL_PA_ON;
3119 e_post_off = WCD9XXX_EVENT_POST_HPHL_PA_OFF;
Patrick Lai453cd742013-03-02 16:51:27 -08003120 req_clsh_state = WCD9XXX_CLSH_STATE_HPHL;
3121 } else if (w->shift == 4) {
3122 e_pre_on = WCD9XXX_EVENT_PRE_HPHR_PA_ON;
3123 e_post_off = WCD9XXX_EVENT_POST_HPHR_PA_OFF;
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08003124 req_clsh_state = WCD9XXX_CLSH_STATE_HPHR;
Joonwoo Parka8890262012-10-15 12:04:27 -07003125 } else {
3126 pr_err("%s: Invalid w->shift %d\n", __func__, w->shift);
3127 return -EINVAL;
3128 }
Kiran Kandic3b24402012-06-11 00:05:59 -07003129
Bhalchandra Gajareef7810e2013-03-29 16:50:37 -07003130 if (taiko->comp_enabled[COMPANDER_1])
3131 pa_settle_time = TAIKO_HPH_PA_SETTLE_COMP_ON;
3132
Kiran Kandic3b24402012-06-11 00:05:59 -07003133 switch (event) {
3134 case SND_SOC_DAPM_PRE_PMU:
Joonwoo Parka8890262012-10-15 12:04:27 -07003135 /* Let MBHC module know PA is turning on */
3136 wcd9xxx_resmgr_notifier_call(&taiko->resmgr, e_pre_on);
Kiran Kandic3b24402012-06-11 00:05:59 -07003137 break;
3138
Kiran Kandi4c56c592012-07-25 11:04:55 -07003139 case SND_SOC_DAPM_POST_PMU:
Bhalchandra Gajareef7810e2013-03-29 16:50:37 -07003140 usleep_range(pa_settle_time, pa_settle_time + 1000);
3141 pr_debug("%s: sleep %d us after %s PA enable\n", __func__,
3142 pa_settle_time, w->name);
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08003143 wcd9xxx_clsh_fsm(codec, &taiko->clsh_d,
3144 req_clsh_state,
3145 WCD9XXX_CLSH_REQ_ENABLE,
3146 WCD9XXX_CLSH_EVENT_POST_PA);
Kiran Kandi4c56c592012-07-25 11:04:55 -07003147
Kiran Kandi4c56c592012-07-25 11:04:55 -07003148 break;
3149
Kiran Kandic3b24402012-06-11 00:05:59 -07003150 case SND_SOC_DAPM_POST_PMD:
Bhalchandra Gajareef7810e2013-03-29 16:50:37 -07003151 usleep_range(pa_settle_time, pa_settle_time + 1000);
3152 pr_debug("%s: sleep %d us after %s PA disable\n", __func__,
3153 pa_settle_time, w->name);
3154
Joonwoo Parka8890262012-10-15 12:04:27 -07003155 /* Let MBHC module know PA turned off */
3156 wcd9xxx_resmgr_notifier_call(&taiko->resmgr, e_post_off);
3157
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08003158 wcd9xxx_clsh_fsm(codec, &taiko->clsh_d,
3159 req_clsh_state,
3160 WCD9XXX_CLSH_REQ_DISABLE,
3161 WCD9XXX_CLSH_EVENT_POST_PA);
3162
Kiran Kandic3b24402012-06-11 00:05:59 -07003163 break;
3164 }
3165 return 0;
3166}
3167
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08003168static int taiko_codec_enable_anc_hph(struct snd_soc_dapm_widget *w,
3169 struct snd_kcontrol *kcontrol, int event)
3170{
3171 struct snd_soc_codec *codec = w->codec;
3172 int ret = 0;
3173
3174 switch (event) {
3175 case SND_SOC_DAPM_PRE_PMU:
3176 ret = taiko_hph_pa_event(w, kcontrol, event);
3177 if (w->shift == 4) {
3178 ret |= taiko_codec_enable_anc(w, kcontrol, event);
3179 msleep(50);
3180 }
3181 break;
3182 case SND_SOC_DAPM_POST_PMU:
3183 if (w->shift == 4) {
3184 snd_soc_update_bits(codec,
3185 TAIKO_A_RX_HPH_CNP_EN, 0x30, 0x30);
3186 msleep(30);
3187 }
3188 ret = taiko_hph_pa_event(w, kcontrol, event);
3189 break;
3190 case SND_SOC_DAPM_PRE_PMD:
3191 if (w->shift == 5) {
3192 snd_soc_update_bits(codec,
3193 TAIKO_A_RX_HPH_CNP_EN, 0x30, 0x00);
3194 msleep(40);
3195 }
3196 if (w->shift == 5) {
3197 snd_soc_update_bits(codec,
3198 TAIKO_A_TX_7_MBHC_EN, 0x80, 00);
3199 ret |= taiko_codec_enable_anc(w, kcontrol, event);
3200 }
3201 case SND_SOC_DAPM_POST_PMD:
3202 ret = taiko_hph_pa_event(w, kcontrol, event);
3203 break;
3204 }
3205 return ret;
3206}
3207
Kiran Kandic3b24402012-06-11 00:05:59 -07003208static const struct snd_soc_dapm_widget taiko_dapm_i2s_widgets[] = {
3209 SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", TAIKO_A_CDC_CLK_RX_I2S_CTL,
3210 4, 0, NULL, 0),
3211 SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", TAIKO_A_CDC_CLK_TX_I2S_CTL, 4,
3212 0, NULL, 0),
3213};
3214
3215static int taiko_lineout_dac_event(struct snd_soc_dapm_widget *w,
3216 struct snd_kcontrol *kcontrol, int event)
3217{
3218 struct snd_soc_codec *codec = w->codec;
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08003219 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
Kiran Kandic3b24402012-06-11 00:05:59 -07003220
3221 pr_debug("%s %s %d\n", __func__, w->name, event);
3222
3223 switch (event) {
3224 case SND_SOC_DAPM_PRE_PMU:
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08003225 wcd9xxx_clsh_fsm(codec, &taiko->clsh_d,
3226 WCD9XXX_CLSH_STATE_LO,
3227 WCD9XXX_CLSH_REQ_ENABLE,
3228 WCD9XXX_CLSH_EVENT_PRE_DAC);
Kiran Kandic3b24402012-06-11 00:05:59 -07003229 snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
3230 break;
3231
3232 case SND_SOC_DAPM_POST_PMD:
3233 snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
3234 break;
3235 }
3236 return 0;
3237}
3238
Joonwoo Park7680b9f2012-07-13 11:36:48 -07003239static int taiko_spk_dac_event(struct snd_soc_dapm_widget *w,
3240 struct snd_kcontrol *kcontrol, int event)
3241{
3242 pr_debug("%s %s %d\n", __func__, w->name, event);
3243 return 0;
3244}
3245
Kiran Kandic3b24402012-06-11 00:05:59 -07003246static const struct snd_soc_dapm_route audio_i2s_map[] = {
Kiran Kandic3b24402012-06-11 00:05:59 -07003247 {"SLIM RX1", NULL, "RX_I2S_CLK"},
3248 {"SLIM RX2", NULL, "RX_I2S_CLK"},
3249 {"SLIM RX3", NULL, "RX_I2S_CLK"},
3250 {"SLIM RX4", NULL, "RX_I2S_CLK"},
3251
Venkat Sudhira41630a2012-10-27 00:57:31 -07003252 {"SLIM TX7 MUX", NULL, "TX_I2S_CLK"},
3253 {"SLIM TX8 MUX", NULL, "TX_I2S_CLK"},
3254 {"SLIM TX9 MUX", NULL, "TX_I2S_CLK"},
3255 {"SLIM TX10 MUX", NULL, "TX_I2S_CLK"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003256};
3257
Joonwoo Park559a5bf2013-02-15 14:46:36 -08003258static const struct snd_soc_dapm_route audio_i2s_map_1_0[] = {
3259 {"RX_I2S_CLK", NULL, "CDC_CONN"},
3260};
3261
3262static const struct snd_soc_dapm_route audio_i2s_map_2_0[] = {
3263 {"RX_I2S_CLK", NULL, "CDC_I2S_RX_CONN"},
3264};
3265
Kiran Kandic3b24402012-06-11 00:05:59 -07003266static const struct snd_soc_dapm_route audio_map[] = {
3267 /* SLIMBUS Connections */
Kuirong Wang906ac472012-07-09 12:54:44 -07003268 {"AIF1 CAP", NULL, "AIF1_CAP Mixer"},
3269 {"AIF2 CAP", NULL, "AIF2_CAP Mixer"},
3270 {"AIF3 CAP", NULL, "AIF3_CAP Mixer"},
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05003271 {"AIF4 VI", NULL, "SPK_OUT"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003272
Joonwoo Park1d05bb92013-03-07 16:55:06 -08003273 /* MAD */
3274 {"AIF4 MAD", NULL, "CDC_CONN"},
Joonwoo Park9ead0e92013-03-18 11:33:33 -07003275 {"MADONOFF", "Switch", "MADINPUT"},
3276 {"AIF4 MAD", NULL, "MADONOFF"},
Joonwoo Park1d05bb92013-03-07 16:55:06 -08003277
Kuirong Wang906ac472012-07-09 12:54:44 -07003278 /* SLIM_MIXER("AIF1_CAP Mixer"),*/
3279 {"AIF1_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
3280 {"AIF1_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
3281 {"AIF1_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
3282 {"AIF1_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
3283 {"AIF1_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
3284 {"AIF1_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"},
3285 {"AIF1_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"},
3286 {"AIF1_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"},
3287 {"AIF1_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"},
3288 {"AIF1_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"},
3289 /* SLIM_MIXER("AIF2_CAP Mixer"),*/
3290 {"AIF2_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
3291 {"AIF2_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
3292 {"AIF2_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
3293 {"AIF2_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
3294 {"AIF2_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
3295 {"AIF2_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"},
3296 {"AIF2_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"},
3297 {"AIF2_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"},
3298 {"AIF2_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"},
3299 {"AIF2_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"},
3300 /* SLIM_MIXER("AIF3_CAP Mixer"),*/
3301 {"AIF3_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"},
3302 {"AIF3_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"},
3303 {"AIF3_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"},
3304 {"AIF3_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"},
3305 {"AIF3_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"},
3306 {"AIF3_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"},
3307 {"AIF3_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"},
3308 {"AIF3_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"},
3309 {"AIF3_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"},
3310 {"AIF3_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"},
3311
Kiran Kandic3b24402012-06-11 00:05:59 -07003312 {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"},
3313
Kiran Kandic3b24402012-06-11 00:05:59 -07003314 {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"},
3315
Kiran Kandic3b24402012-06-11 00:05:59 -07003316 {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"},
3317 {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"},
3318 {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"},
3319 {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"},
3320 {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"},
3321 {"SLIM TX3 MUX", "RMIX5", "RX5 MIX1"},
3322 {"SLIM TX3 MUX", "RMIX6", "RX6 MIX1"},
3323 {"SLIM TX3 MUX", "RMIX7", "RX7 MIX1"},
3324
Kiran Kandic3b24402012-06-11 00:05:59 -07003325 {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"},
3326
Kiran Kandic3b24402012-06-11 00:05:59 -07003327 {"SLIM TX5 MUX", "DEC5", "DEC5 MUX"},
3328 {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"},
3329 {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"},
3330 {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"},
3331 {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"},
3332 {"SLIM TX5 MUX", "RMIX5", "RX5 MIX1"},
3333 {"SLIM TX5 MUX", "RMIX6", "RX6 MIX1"},
3334 {"SLIM TX5 MUX", "RMIX7", "RX7 MIX1"},
3335
Kiran Kandic3b24402012-06-11 00:05:59 -07003336 {"SLIM TX6 MUX", "DEC6", "DEC6 MUX"},
3337
Kiran Kandic3b24402012-06-11 00:05:59 -07003338 {"SLIM TX7 MUX", "DEC1", "DEC1 MUX"},
3339 {"SLIM TX7 MUX", "DEC2", "DEC2 MUX"},
3340 {"SLIM TX7 MUX", "DEC3", "DEC3 MUX"},
3341 {"SLIM TX7 MUX", "DEC4", "DEC4 MUX"},
3342 {"SLIM TX7 MUX", "DEC5", "DEC5 MUX"},
3343 {"SLIM TX7 MUX", "DEC6", "DEC6 MUX"},
3344 {"SLIM TX7 MUX", "DEC7", "DEC7 MUX"},
3345 {"SLIM TX7 MUX", "DEC8", "DEC8 MUX"},
3346 {"SLIM TX7 MUX", "DEC9", "DEC9 MUX"},
3347 {"SLIM TX7 MUX", "DEC10", "DEC10 MUX"},
3348 {"SLIM TX7 MUX", "RMIX1", "RX1 MIX1"},
3349 {"SLIM TX7 MUX", "RMIX2", "RX2 MIX1"},
3350 {"SLIM TX7 MUX", "RMIX3", "RX3 MIX1"},
3351 {"SLIM TX7 MUX", "RMIX4", "RX4 MIX1"},
3352 {"SLIM TX7 MUX", "RMIX5", "RX5 MIX1"},
3353 {"SLIM TX7 MUX", "RMIX6", "RX6 MIX1"},
3354 {"SLIM TX7 MUX", "RMIX7", "RX7 MIX1"},
3355
Kiran Kandic3b24402012-06-11 00:05:59 -07003356 {"SLIM TX8 MUX", "DEC1", "DEC1 MUX"},
3357 {"SLIM TX8 MUX", "DEC2", "DEC2 MUX"},
3358 {"SLIM TX8 MUX", "DEC3", "DEC3 MUX"},
3359 {"SLIM TX8 MUX", "DEC4", "DEC4 MUX"},
3360 {"SLIM TX8 MUX", "DEC5", "DEC5 MUX"},
3361 {"SLIM TX8 MUX", "DEC6", "DEC6 MUX"},
3362 {"SLIM TX8 MUX", "DEC7", "DEC7 MUX"},
3363 {"SLIM TX8 MUX", "DEC8", "DEC8 MUX"},
3364 {"SLIM TX8 MUX", "DEC9", "DEC9 MUX"},
3365 {"SLIM TX8 MUX", "DEC10", "DEC10 MUX"},
3366
Kiran Kandic3b24402012-06-11 00:05:59 -07003367 {"SLIM TX9 MUX", "DEC1", "DEC1 MUX"},
3368 {"SLIM TX9 MUX", "DEC2", "DEC2 MUX"},
3369 {"SLIM TX9 MUX", "DEC3", "DEC3 MUX"},
3370 {"SLIM TX9 MUX", "DEC4", "DEC4 MUX"},
3371 {"SLIM TX9 MUX", "DEC5", "DEC5 MUX"},
3372 {"SLIM TX9 MUX", "DEC6", "DEC6 MUX"},
3373 {"SLIM TX9 MUX", "DEC7", "DEC7 MUX"},
3374 {"SLIM TX9 MUX", "DEC8", "DEC8 MUX"},
3375 {"SLIM TX9 MUX", "DEC9", "DEC9 MUX"},
3376 {"SLIM TX9 MUX", "DEC10", "DEC10 MUX"},
3377
Kiran Kandic3b24402012-06-11 00:05:59 -07003378 {"SLIM TX10 MUX", "DEC1", "DEC1 MUX"},
3379 {"SLIM TX10 MUX", "DEC2", "DEC2 MUX"},
3380 {"SLIM TX10 MUX", "DEC3", "DEC3 MUX"},
3381 {"SLIM TX10 MUX", "DEC4", "DEC4 MUX"},
3382 {"SLIM TX10 MUX", "DEC5", "DEC5 MUX"},
3383 {"SLIM TX10 MUX", "DEC6", "DEC6 MUX"},
3384 {"SLIM TX10 MUX", "DEC7", "DEC7 MUX"},
3385 {"SLIM TX10 MUX", "DEC8", "DEC8 MUX"},
3386 {"SLIM TX10 MUX", "DEC9", "DEC9 MUX"},
3387 {"SLIM TX10 MUX", "DEC10", "DEC10 MUX"},
3388
3389 /* Earpiece (RX MIX1) */
3390 {"EAR", NULL, "EAR PA"},
3391 {"EAR PA", NULL, "EAR_PA_MIXER"},
3392 {"EAR_PA_MIXER", NULL, "DAC1"},
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08003393 {"DAC1", NULL, "RX_BIAS"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003394
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08003395 {"ANC EAR", NULL, "ANC EAR PA"},
3396 {"ANC EAR PA", NULL, "EAR_PA_MIXER"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003397 {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"},
3398 {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003399
3400 /* Headset (RX MIX1 and RX MIX2) */
3401 {"HEADPHONE", NULL, "HPHL"},
3402 {"HEADPHONE", NULL, "HPHR"},
3403
3404 {"HPHL", NULL, "HPHL_PA_MIXER"},
3405 {"HPHL_PA_MIXER", NULL, "HPHL DAC"},
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08003406 {"HPHL DAC", NULL, "RX_BIAS"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003407
3408 {"HPHR", NULL, "HPHR_PA_MIXER"},
3409 {"HPHR_PA_MIXER", NULL, "HPHR DAC"},
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08003410 {"HPHR DAC", NULL, "RX_BIAS"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003411
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08003412 {"ANC HEADPHONE", NULL, "ANC HPHL"},
3413 {"ANC HEADPHONE", NULL, "ANC HPHR"},
3414
3415 {"ANC HPHL", NULL, "HPHL_PA_MIXER"},
3416 {"ANC HPHR", NULL, "HPHR_PA_MIXER"},
3417
Kiran Kandic3b24402012-06-11 00:05:59 -07003418 {"ANC1 MUX", "ADC1", "ADC1"},
3419 {"ANC1 MUX", "ADC2", "ADC2"},
3420 {"ANC1 MUX", "ADC3", "ADC3"},
3421 {"ANC1 MUX", "ADC4", "ADC4"},
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08003422 {"ANC1 MUX", "DMIC1", "DMIC1"},
3423 {"ANC1 MUX", "DMIC2", "DMIC2"},
3424 {"ANC1 MUX", "DMIC3", "DMIC3"},
3425 {"ANC1 MUX", "DMIC4", "DMIC4"},
3426 {"ANC1 MUX", "DMIC5", "DMIC5"},
3427 {"ANC1 MUX", "DMIC6", "DMIC6"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003428 {"ANC2 MUX", "ADC1", "ADC1"},
3429 {"ANC2 MUX", "ADC2", "ADC2"},
3430 {"ANC2 MUX", "ADC3", "ADC3"},
3431 {"ANC2 MUX", "ADC4", "ADC4"},
3432
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08003433 {"ANC HPHR", NULL, "CDC_CONN"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003434
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08003435 {"DAC1", "Switch", "CLASS_H_DSM MUX"},
3436 {"HPHL DAC", "Switch", "CLASS_H_DSM MUX"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003437 {"HPHR DAC", NULL, "RX2 CHAIN"},
3438
3439 {"LINEOUT1", NULL, "LINEOUT1 PA"},
3440 {"LINEOUT2", NULL, "LINEOUT2 PA"},
3441 {"LINEOUT3", NULL, "LINEOUT3 PA"},
3442 {"LINEOUT4", NULL, "LINEOUT4 PA"},
Joonwoo Park7680b9f2012-07-13 11:36:48 -07003443 {"SPK_OUT", NULL, "SPK PA"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003444
3445 {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"},
3446 {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"},
Tanya Finkelfe634462012-10-23 22:12:07 +02003447
Kiran Kandic3b24402012-06-11 00:05:59 -07003448 {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"},
3449 {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"},
Tanya Finkelfe634462012-10-23 22:12:07 +02003450
Kiran Kandic3b24402012-06-11 00:05:59 -07003451 {"LINEOUT3 PA", NULL, "LINEOUT3_PA_MIXER"},
3452 {"LINEOUT3_PA_MIXER", NULL, "LINEOUT3 DAC"},
Tanya Finkelfe634462012-10-23 22:12:07 +02003453
Kiran Kandic3b24402012-06-11 00:05:59 -07003454 {"LINEOUT4 PA", NULL, "LINEOUT4_PA_MIXER"},
3455 {"LINEOUT4_PA_MIXER", NULL, "LINEOUT4 DAC"},
3456
3457 {"LINEOUT1 DAC", NULL, "RX3 MIX1"},
3458
Tanya Finkeldaaa6d12012-10-25 11:22:48 +02003459 {"RDAC5 MUX", "DEM3_INV", "RX3 MIX1"},
3460 {"RDAC5 MUX", "DEM4", "RX4 MIX1"},
3461
3462 {"LINEOUT3 DAC", NULL, "RDAC5 MUX"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003463
3464 {"LINEOUT2 DAC", NULL, "RX5 MIX1"},
3465
Tanya Finkeldaaa6d12012-10-25 11:22:48 +02003466 {"RDAC7 MUX", "DEM5_INV", "RX5 MIX1"},
3467 {"RDAC7 MUX", "DEM6", "RX6 MIX1"},
3468
3469 {"LINEOUT4 DAC", NULL, "RDAC7 MUX"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003470
Joonwoo Park7680b9f2012-07-13 11:36:48 -07003471 {"SPK PA", NULL, "SPK DAC"},
Kiran Kandid2b46332012-10-05 12:04:00 -07003472 {"SPK DAC", NULL, "RX7 MIX2"},
Joonwoo Park125cd4e2012-12-11 15:16:11 -08003473 {"SPK DAC", NULL, "VDD_SPKDRV"},
Joonwoo Park7680b9f2012-07-13 11:36:48 -07003474
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08003475 {"CLASS_H_DSM MUX", "DSM_HPHL_RX1", "RX1 CHAIN"},
3476
Kiran Kandic3b24402012-06-11 00:05:59 -07003477 {"RX1 CHAIN", NULL, "RX1 MIX2"},
3478 {"RX2 CHAIN", NULL, "RX2 MIX2"},
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08003479 {"RX1 MIX2", NULL, "ANC1 MUX"},
3480 {"RX2 MIX2", NULL, "ANC2 MUX"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003481
Kiran Kandic3b24402012-06-11 00:05:59 -07003482 {"LINEOUT1 DAC", NULL, "RX_BIAS"},
3483 {"LINEOUT2 DAC", NULL, "RX_BIAS"},
3484 {"LINEOUT3 DAC", NULL, "RX_BIAS"},
3485 {"LINEOUT4 DAC", NULL, "RX_BIAS"},
Joonwoo Park7680b9f2012-07-13 11:36:48 -07003486 {"SPK DAC", NULL, "RX_BIAS"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003487
Joonwoo Parkc7731432012-10-17 12:41:44 -07003488 {"RX7 MIX1", NULL, "COMP0_CLK"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003489 {"RX1 MIX1", NULL, "COMP1_CLK"},
3490 {"RX2 MIX1", NULL, "COMP1_CLK"},
3491 {"RX3 MIX1", NULL, "COMP2_CLK"},
3492 {"RX5 MIX1", NULL, "COMP2_CLK"},
3493
Kiran Kandic3b24402012-06-11 00:05:59 -07003494 {"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
3495 {"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
3496 {"RX1 MIX1", NULL, "RX1 MIX1 INP3"},
3497 {"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
3498 {"RX2 MIX1", NULL, "RX2 MIX1 INP2"},
3499 {"RX3 MIX1", NULL, "RX3 MIX1 INP1"},
3500 {"RX3 MIX1", NULL, "RX3 MIX1 INP2"},
3501 {"RX4 MIX1", NULL, "RX4 MIX1 INP1"},
3502 {"RX4 MIX1", NULL, "RX4 MIX1 INP2"},
3503 {"RX5 MIX1", NULL, "RX5 MIX1 INP1"},
3504 {"RX5 MIX1", NULL, "RX5 MIX1 INP2"},
3505 {"RX6 MIX1", NULL, "RX6 MIX1 INP1"},
3506 {"RX6 MIX1", NULL, "RX6 MIX1 INP2"},
3507 {"RX7 MIX1", NULL, "RX7 MIX1 INP1"},
3508 {"RX7 MIX1", NULL, "RX7 MIX1 INP2"},
3509 {"RX1 MIX2", NULL, "RX1 MIX1"},
3510 {"RX1 MIX2", NULL, "RX1 MIX2 INP1"},
3511 {"RX1 MIX2", NULL, "RX1 MIX2 INP2"},
3512 {"RX2 MIX2", NULL, "RX2 MIX1"},
3513 {"RX2 MIX2", NULL, "RX2 MIX2 INP1"},
3514 {"RX2 MIX2", NULL, "RX2 MIX2 INP2"},
3515 {"RX7 MIX2", NULL, "RX7 MIX1"},
3516 {"RX7 MIX2", NULL, "RX7 MIX2 INP1"},
3517 {"RX7 MIX2", NULL, "RX7 MIX2 INP2"},
3518
Kuirong Wang906ac472012-07-09 12:54:44 -07003519 /* SLIM_MUX("AIF1_PB", "AIF1 PB"),*/
3520 {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"},
3521 {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"},
3522 {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"},
3523 {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"},
3524 {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"},
3525 {"SLIM RX6 MUX", "AIF1_PB", "AIF1 PB"},
3526 {"SLIM RX7 MUX", "AIF1_PB", "AIF1 PB"},
3527 /* SLIM_MUX("AIF2_PB", "AIF2 PB"),*/
3528 {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"},
3529 {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"},
3530 {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"},
3531 {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"},
3532 {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"},
3533 {"SLIM RX6 MUX", "AIF2_PB", "AIF2 PB"},
3534 {"SLIM RX7 MUX", "AIF2_PB", "AIF2 PB"},
3535 /* SLIM_MUX("AIF3_PB", "AIF3 PB"),*/
3536 {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"},
3537 {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"},
3538 {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"},
3539 {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"},
3540 {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"},
3541 {"SLIM RX6 MUX", "AIF3_PB", "AIF3 PB"},
3542 {"SLIM RX7 MUX", "AIF3_PB", "AIF3 PB"},
3543
3544 {"SLIM RX1", NULL, "SLIM RX1 MUX"},
3545 {"SLIM RX2", NULL, "SLIM RX2 MUX"},
3546 {"SLIM RX3", NULL, "SLIM RX3 MUX"},
3547 {"SLIM RX4", NULL, "SLIM RX4 MUX"},
3548 {"SLIM RX5", NULL, "SLIM RX5 MUX"},
3549 {"SLIM RX6", NULL, "SLIM RX6 MUX"},
3550 {"SLIM RX7", NULL, "SLIM RX7 MUX"},
3551
Kiran Kandic3b24402012-06-11 00:05:59 -07003552 {"RX1 MIX1 INP1", "RX1", "SLIM RX1"},
3553 {"RX1 MIX1 INP1", "RX2", "SLIM RX2"},
3554 {"RX1 MIX1 INP1", "RX3", "SLIM RX3"},
3555 {"RX1 MIX1 INP1", "RX4", "SLIM RX4"},
3556 {"RX1 MIX1 INP1", "RX5", "SLIM RX5"},
3557 {"RX1 MIX1 INP1", "RX6", "SLIM RX6"},
3558 {"RX1 MIX1 INP1", "RX7", "SLIM RX7"},
3559 {"RX1 MIX1 INP1", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003560 {"RX1 MIX1 INP1", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003561 {"RX1 MIX1 INP2", "RX1", "SLIM RX1"},
3562 {"RX1 MIX1 INP2", "RX2", "SLIM RX2"},
3563 {"RX1 MIX1 INP2", "RX3", "SLIM RX3"},
3564 {"RX1 MIX1 INP2", "RX4", "SLIM RX4"},
3565 {"RX1 MIX1 INP2", "RX5", "SLIM RX5"},
3566 {"RX1 MIX1 INP2", "RX6", "SLIM RX6"},
3567 {"RX1 MIX1 INP2", "RX7", "SLIM RX7"},
3568 {"RX1 MIX1 INP2", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003569 {"RX1 MIX1 INP2", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003570 {"RX1 MIX1 INP3", "RX1", "SLIM RX1"},
3571 {"RX1 MIX1 INP3", "RX2", "SLIM RX2"},
3572 {"RX1 MIX1 INP3", "RX3", "SLIM RX3"},
3573 {"RX1 MIX1 INP3", "RX4", "SLIM RX4"},
3574 {"RX1 MIX1 INP3", "RX5", "SLIM RX5"},
3575 {"RX1 MIX1 INP3", "RX6", "SLIM RX6"},
3576 {"RX1 MIX1 INP3", "RX7", "SLIM RX7"},
3577 {"RX2 MIX1 INP1", "RX1", "SLIM RX1"},
3578 {"RX2 MIX1 INP1", "RX2", "SLIM RX2"},
3579 {"RX2 MIX1 INP1", "RX3", "SLIM RX3"},
3580 {"RX2 MIX1 INP1", "RX4", "SLIM RX4"},
3581 {"RX2 MIX1 INP1", "RX5", "SLIM RX5"},
3582 {"RX2 MIX1 INP1", "RX6", "SLIM RX6"},
3583 {"RX2 MIX1 INP1", "RX7", "SLIM RX7"},
3584 {"RX2 MIX1 INP1", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003585 {"RX2 MIX1 INP1", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003586 {"RX2 MIX1 INP2", "RX1", "SLIM RX1"},
3587 {"RX2 MIX1 INP2", "RX2", "SLIM RX2"},
3588 {"RX2 MIX1 INP2", "RX3", "SLIM RX3"},
3589 {"RX2 MIX1 INP2", "RX4", "SLIM RX4"},
3590 {"RX2 MIX1 INP2", "RX5", "SLIM RX5"},
3591 {"RX2 MIX1 INP2", "RX6", "SLIM RX6"},
3592 {"RX2 MIX1 INP2", "RX7", "SLIM RX7"},
3593 {"RX2 MIX1 INP2", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003594 {"RX2 MIX1 INP2", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003595 {"RX3 MIX1 INP1", "RX1", "SLIM RX1"},
3596 {"RX3 MIX1 INP1", "RX2", "SLIM RX2"},
3597 {"RX3 MIX1 INP1", "RX3", "SLIM RX3"},
3598 {"RX3 MIX1 INP1", "RX4", "SLIM RX4"},
3599 {"RX3 MIX1 INP1", "RX5", "SLIM RX5"},
3600 {"RX3 MIX1 INP1", "RX6", "SLIM RX6"},
3601 {"RX3 MIX1 INP1", "RX7", "SLIM RX7"},
3602 {"RX3 MIX1 INP1", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003603 {"RX3 MIX1 INP1", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003604 {"RX3 MIX1 INP2", "RX1", "SLIM RX1"},
3605 {"RX3 MIX1 INP2", "RX2", "SLIM RX2"},
3606 {"RX3 MIX1 INP2", "RX3", "SLIM RX3"},
3607 {"RX3 MIX1 INP2", "RX4", "SLIM RX4"},
3608 {"RX3 MIX1 INP2", "RX5", "SLIM RX5"},
3609 {"RX3 MIX1 INP2", "RX6", "SLIM RX6"},
3610 {"RX3 MIX1 INP2", "RX7", "SLIM RX7"},
3611 {"RX3 MIX1 INP2", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003612 {"RX3 MIX1 INP2", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003613 {"RX4 MIX1 INP1", "RX1", "SLIM RX1"},
3614 {"RX4 MIX1 INP1", "RX2", "SLIM RX2"},
3615 {"RX4 MIX1 INP1", "RX3", "SLIM RX3"},
3616 {"RX4 MIX1 INP1", "RX4", "SLIM RX4"},
3617 {"RX4 MIX1 INP1", "RX5", "SLIM RX5"},
3618 {"RX4 MIX1 INP1", "RX6", "SLIM RX6"},
3619 {"RX4 MIX1 INP1", "RX7", "SLIM RX7"},
3620 {"RX4 MIX1 INP1", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003621 {"RX4 MIX1 INP1", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003622 {"RX4 MIX1 INP2", "RX1", "SLIM RX1"},
3623 {"RX4 MIX1 INP2", "RX2", "SLIM RX2"},
3624 {"RX4 MIX1 INP2", "RX3", "SLIM RX3"},
3625 {"RX4 MIX1 INP2", "RX5", "SLIM RX5"},
3626 {"RX4 MIX1 INP2", "RX4", "SLIM RX4"},
3627 {"RX4 MIX1 INP2", "RX6", "SLIM RX6"},
3628 {"RX4 MIX1 INP2", "RX7", "SLIM RX7"},
3629 {"RX4 MIX1 INP2", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003630 {"RX4 MIX1 INP2", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003631 {"RX5 MIX1 INP1", "RX1", "SLIM RX1"},
3632 {"RX5 MIX1 INP1", "RX2", "SLIM RX2"},
3633 {"RX5 MIX1 INP1", "RX3", "SLIM RX3"},
3634 {"RX5 MIX1 INP1", "RX4", "SLIM RX4"},
3635 {"RX5 MIX1 INP1", "RX5", "SLIM RX5"},
3636 {"RX5 MIX1 INP1", "RX6", "SLIM RX6"},
3637 {"RX5 MIX1 INP1", "RX7", "SLIM RX7"},
3638 {"RX5 MIX1 INP1", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003639 {"RX5 MIX1 INP1", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003640 {"RX5 MIX1 INP2", "RX1", "SLIM RX1"},
3641 {"RX5 MIX1 INP2", "RX2", "SLIM RX2"},
3642 {"RX5 MIX1 INP2", "RX3", "SLIM RX3"},
3643 {"RX5 MIX1 INP2", "RX4", "SLIM RX4"},
3644 {"RX5 MIX1 INP2", "RX5", "SLIM RX5"},
3645 {"RX5 MIX1 INP2", "RX6", "SLIM RX6"},
3646 {"RX5 MIX1 INP2", "RX7", "SLIM RX7"},
3647 {"RX5 MIX1 INP2", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003648 {"RX5 MIX1 INP2", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003649 {"RX6 MIX1 INP1", "RX1", "SLIM RX1"},
3650 {"RX6 MIX1 INP1", "RX2", "SLIM RX2"},
3651 {"RX6 MIX1 INP1", "RX3", "SLIM RX3"},
3652 {"RX6 MIX1 INP1", "RX4", "SLIM RX4"},
3653 {"RX6 MIX1 INP1", "RX5", "SLIM RX5"},
3654 {"RX6 MIX1 INP1", "RX6", "SLIM RX6"},
3655 {"RX6 MIX1 INP1", "RX7", "SLIM RX7"},
3656 {"RX6 MIX1 INP1", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003657 {"RX6 MIX1 INP1", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003658 {"RX6 MIX1 INP2", "RX1", "SLIM RX1"},
3659 {"RX6 MIX1 INP2", "RX2", "SLIM RX2"},
3660 {"RX6 MIX1 INP2", "RX3", "SLIM RX3"},
3661 {"RX6 MIX1 INP2", "RX4", "SLIM RX4"},
3662 {"RX6 MIX1 INP2", "RX5", "SLIM RX5"},
3663 {"RX6 MIX1 INP2", "RX6", "SLIM RX6"},
3664 {"RX6 MIX1 INP2", "RX7", "SLIM RX7"},
3665 {"RX6 MIX1 INP2", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003666 {"RX6 MIX1 INP2", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003667 {"RX7 MIX1 INP1", "RX1", "SLIM RX1"},
3668 {"RX7 MIX1 INP1", "RX2", "SLIM RX2"},
3669 {"RX7 MIX1 INP1", "RX3", "SLIM RX3"},
3670 {"RX7 MIX1 INP1", "RX4", "SLIM RX4"},
3671 {"RX7 MIX1 INP1", "RX5", "SLIM RX5"},
3672 {"RX7 MIX1 INP1", "RX6", "SLIM RX6"},
3673 {"RX7 MIX1 INP1", "RX7", "SLIM RX7"},
3674 {"RX7 MIX1 INP1", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003675 {"RX7 MIX1 INP1", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003676 {"RX7 MIX1 INP2", "RX1", "SLIM RX1"},
3677 {"RX7 MIX1 INP2", "RX2", "SLIM RX2"},
3678 {"RX7 MIX1 INP2", "RX3", "SLIM RX3"},
3679 {"RX7 MIX1 INP2", "RX4", "SLIM RX4"},
3680 {"RX7 MIX1 INP2", "RX5", "SLIM RX5"},
3681 {"RX7 MIX1 INP2", "RX6", "SLIM RX6"},
3682 {"RX7 MIX1 INP2", "RX7", "SLIM RX7"},
3683 {"RX7 MIX1 INP2", "IIR1", "IIR1"},
3684 {"RX1 MIX2 INP1", "IIR1", "IIR1"},
3685 {"RX1 MIX2 INP2", "IIR1", "IIR1"},
3686 {"RX2 MIX2 INP1", "IIR1", "IIR1"},
3687 {"RX2 MIX2 INP2", "IIR1", "IIR1"},
3688 {"RX7 MIX2 INP1", "IIR1", "IIR1"},
3689 {"RX7 MIX2 INP2", "IIR1", "IIR1"},
Fred Oh456fcb52013-02-28 19:08:15 -08003690 {"RX7 MIX1 INP2", "IIR2", "IIR2"},
3691 {"RX1 MIX2 INP1", "IIR2", "IIR2"},
3692 {"RX1 MIX2 INP2", "IIR2", "IIR2"},
3693 {"RX2 MIX2 INP1", "IIR2", "IIR2"},
3694 {"RX2 MIX2 INP2", "IIR2", "IIR2"},
3695 {"RX7 MIX2 INP1", "IIR2", "IIR2"},
3696 {"RX7 MIX2 INP2", "IIR2", "IIR2"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003697
3698 /* Decimator Inputs */
3699 {"DEC1 MUX", "DMIC1", "DMIC1"},
3700 {"DEC1 MUX", "ADC6", "ADC6"},
3701 {"DEC1 MUX", NULL, "CDC_CONN"},
3702 {"DEC2 MUX", "DMIC2", "DMIC2"},
3703 {"DEC2 MUX", "ADC5", "ADC5"},
3704 {"DEC2 MUX", NULL, "CDC_CONN"},
3705 {"DEC3 MUX", "DMIC3", "DMIC3"},
3706 {"DEC3 MUX", "ADC4", "ADC4"},
3707 {"DEC3 MUX", NULL, "CDC_CONN"},
3708 {"DEC4 MUX", "DMIC4", "DMIC4"},
3709 {"DEC4 MUX", "ADC3", "ADC3"},
3710 {"DEC4 MUX", NULL, "CDC_CONN"},
3711 {"DEC5 MUX", "DMIC5", "DMIC5"},
3712 {"DEC5 MUX", "ADC2", "ADC2"},
3713 {"DEC5 MUX", NULL, "CDC_CONN"},
3714 {"DEC6 MUX", "DMIC6", "DMIC6"},
3715 {"DEC6 MUX", "ADC1", "ADC1"},
3716 {"DEC6 MUX", NULL, "CDC_CONN"},
3717 {"DEC7 MUX", "DMIC1", "DMIC1"},
3718 {"DEC7 MUX", "DMIC6", "DMIC6"},
3719 {"DEC7 MUX", "ADC1", "ADC1"},
3720 {"DEC7 MUX", "ADC6", "ADC6"},
3721 {"DEC7 MUX", NULL, "CDC_CONN"},
3722 {"DEC8 MUX", "DMIC2", "DMIC2"},
3723 {"DEC8 MUX", "DMIC5", "DMIC5"},
3724 {"DEC8 MUX", "ADC2", "ADC2"},
3725 {"DEC8 MUX", "ADC5", "ADC5"},
3726 {"DEC8 MUX", NULL, "CDC_CONN"},
3727 {"DEC9 MUX", "DMIC4", "DMIC4"},
3728 {"DEC9 MUX", "DMIC5", "DMIC5"},
3729 {"DEC9 MUX", "ADC2", "ADC2"},
3730 {"DEC9 MUX", "ADC3", "ADC3"},
3731 {"DEC9 MUX", NULL, "CDC_CONN"},
3732 {"DEC10 MUX", "DMIC3", "DMIC3"},
3733 {"DEC10 MUX", "DMIC6", "DMIC6"},
3734 {"DEC10 MUX", "ADC1", "ADC1"},
3735 {"DEC10 MUX", "ADC4", "ADC4"},
3736 {"DEC10 MUX", NULL, "CDC_CONN"},
3737
3738 /* ADC Connections */
3739 {"ADC1", NULL, "AMIC1"},
3740 {"ADC2", NULL, "AMIC2"},
3741 {"ADC3", NULL, "AMIC3"},
3742 {"ADC4", NULL, "AMIC4"},
3743 {"ADC5", NULL, "AMIC5"},
3744 {"ADC6", NULL, "AMIC6"},
3745
3746 /* AUX PGA Connections */
Kiran Kandic3b24402012-06-11 00:05:59 -07003747 {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
Kiran Kandi4c56c592012-07-25 11:04:55 -07003748 {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3749 {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3750 {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3751 {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
3752 {"LINEOUT3_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"},
3753 {"LINEOUT4_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"},
Kiran Kandic3b24402012-06-11 00:05:59 -07003754 {"AUX_PGA_Left", NULL, "AMIC5"},
3755 {"AUX_PGA_Right", NULL, "AMIC6"},
3756
Kiran Kandic3b24402012-06-11 00:05:59 -07003757 {"IIR1", NULL, "IIR1 INP1 MUX"},
3758 {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"},
3759 {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"},
3760 {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"},
3761 {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"},
3762 {"IIR1 INP1 MUX", "DEC5", "DEC5 MUX"},
3763 {"IIR1 INP1 MUX", "DEC6", "DEC6 MUX"},
3764 {"IIR1 INP1 MUX", "DEC7", "DEC7 MUX"},
3765 {"IIR1 INP1 MUX", "DEC8", "DEC8 MUX"},
3766 {"IIR1 INP1 MUX", "DEC9", "DEC9 MUX"},
3767 {"IIR1 INP1 MUX", "DEC10", "DEC10 MUX"},
3768
Fred Oh456fcb52013-02-28 19:08:15 -08003769 {"IIR2", NULL, "IIR2 INP1 MUX"},
3770 {"IIR2 INP1 MUX", "DEC1", "DEC1 MUX"},
3771 {"IIR2 INP1 MUX", "DEC2", "DEC2 MUX"},
3772 {"IIR2 INP1 MUX", "DEC3", "DEC3 MUX"},
3773 {"IIR2 INP1 MUX", "DEC4", "DEC4 MUX"},
3774 {"IIR2 INP1 MUX", "DEC5", "DEC5 MUX"},
3775 {"IIR2 INP1 MUX", "DEC6", "DEC6 MUX"},
3776 {"IIR2 INP1 MUX", "DEC7", "DEC7 MUX"},
3777 {"IIR2 INP1 MUX", "DEC8", "DEC8 MUX"},
3778 {"IIR2 INP1 MUX", "DEC9", "DEC9 MUX"},
3779 {"IIR2 INP1 MUX", "DEC10", "DEC10 MUX"},
3780
Kiran Kandic3b24402012-06-11 00:05:59 -07003781 {"MIC BIAS1 Internal1", NULL, "LDO_H"},
3782 {"MIC BIAS1 Internal2", NULL, "LDO_H"},
3783 {"MIC BIAS1 External", NULL, "LDO_H"},
3784 {"MIC BIAS2 Internal1", NULL, "LDO_H"},
3785 {"MIC BIAS2 Internal2", NULL, "LDO_H"},
3786 {"MIC BIAS2 Internal3", NULL, "LDO_H"},
3787 {"MIC BIAS2 External", NULL, "LDO_H"},
3788 {"MIC BIAS3 Internal1", NULL, "LDO_H"},
3789 {"MIC BIAS3 Internal2", NULL, "LDO_H"},
3790 {"MIC BIAS3 External", NULL, "LDO_H"},
3791 {"MIC BIAS4 External", NULL, "LDO_H"},
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05003792
Kiran Kandic3b24402012-06-11 00:05:59 -07003793};
3794
3795static int taiko_readable(struct snd_soc_codec *ssc, unsigned int reg)
3796{
3797 return taiko_reg_readable[reg];
3798}
3799
3800static bool taiko_is_digital_gain_register(unsigned int reg)
3801{
3802 bool rtn = false;
3803 switch (reg) {
3804 case TAIKO_A_CDC_RX1_VOL_CTL_B2_CTL:
3805 case TAIKO_A_CDC_RX2_VOL_CTL_B2_CTL:
3806 case TAIKO_A_CDC_RX3_VOL_CTL_B2_CTL:
3807 case TAIKO_A_CDC_RX4_VOL_CTL_B2_CTL:
3808 case TAIKO_A_CDC_RX5_VOL_CTL_B2_CTL:
3809 case TAIKO_A_CDC_RX6_VOL_CTL_B2_CTL:
3810 case TAIKO_A_CDC_RX7_VOL_CTL_B2_CTL:
3811 case TAIKO_A_CDC_TX1_VOL_CTL_GAIN:
3812 case TAIKO_A_CDC_TX2_VOL_CTL_GAIN:
3813 case TAIKO_A_CDC_TX3_VOL_CTL_GAIN:
3814 case TAIKO_A_CDC_TX4_VOL_CTL_GAIN:
3815 case TAIKO_A_CDC_TX5_VOL_CTL_GAIN:
3816 case TAIKO_A_CDC_TX6_VOL_CTL_GAIN:
3817 case TAIKO_A_CDC_TX7_VOL_CTL_GAIN:
3818 case TAIKO_A_CDC_TX8_VOL_CTL_GAIN:
3819 case TAIKO_A_CDC_TX9_VOL_CTL_GAIN:
3820 case TAIKO_A_CDC_TX10_VOL_CTL_GAIN:
3821 rtn = true;
3822 break;
3823 default:
3824 break;
3825 }
3826 return rtn;
3827}
3828
3829static int taiko_volatile(struct snd_soc_codec *ssc, unsigned int reg)
3830{
Joonwoo Park1d05bb92013-03-07 16:55:06 -08003831 int i;
3832
Kiran Kandic3b24402012-06-11 00:05:59 -07003833 /* Registers lower than 0x100 are top level registers which can be
3834 * written by the Taiko core driver.
3835 */
3836
3837 if ((reg >= TAIKO_A_CDC_MBHC_EN_CTL) || (reg < 0x100))
3838 return 1;
3839
3840 /* IIR Coeff registers are not cacheable */
3841 if ((reg >= TAIKO_A_CDC_IIR1_COEF_B1_CTL) &&
3842 (reg <= TAIKO_A_CDC_IIR2_COEF_B2_CTL))
3843 return 1;
3844
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08003845 /* ANC filter registers are not cacheable */
3846 if ((reg >= TAIKO_A_CDC_ANC1_IIR_B1_CTL) &&
3847 (reg <= TAIKO_A_CDC_ANC1_LPF_B2_CTL))
3848 return 1;
3849 if ((reg >= TAIKO_A_CDC_ANC2_IIR_B1_CTL) &&
3850 (reg <= TAIKO_A_CDC_ANC2_LPF_B2_CTL))
3851 return 1;
3852
Kiran Kandic3b24402012-06-11 00:05:59 -07003853 /* Digital gain register is not cacheable so we have to write
3854 * the setting even it is the same
3855 */
3856 if (taiko_is_digital_gain_register(reg))
3857 return 1;
3858
3859 /* HPH status registers */
3860 if (reg == TAIKO_A_RX_HPH_L_STATUS || reg == TAIKO_A_RX_HPH_R_STATUS)
3861 return 1;
3862
Joonwoo Parka8890262012-10-15 12:04:27 -07003863 if (reg == TAIKO_A_MBHC_INSERT_DET_STATUS)
3864 return 1;
3865
Joonwoo Park559a5bf2013-02-15 14:46:36 -08003866 switch (reg) {
3867 case TAIKO_A_CDC_SPKR_CLIPDET_VAL0:
3868 case TAIKO_A_CDC_SPKR_CLIPDET_VAL1:
3869 case TAIKO_A_CDC_SPKR_CLIPDET_VAL2:
3870 case TAIKO_A_CDC_SPKR_CLIPDET_VAL3:
3871 case TAIKO_A_CDC_SPKR_CLIPDET_VAL4:
3872 case TAIKO_A_CDC_SPKR_CLIPDET_VAL5:
3873 case TAIKO_A_CDC_SPKR_CLIPDET_VAL6:
3874 case TAIKO_A_CDC_SPKR_CLIPDET_VAL7:
3875 case TAIKO_A_CDC_VBAT_GAIN_MON_VAL:
3876 return 1;
3877 }
3878
Damir Didjustodcfdff82013-03-21 23:26:41 -07003879 for (i = 0; i < ARRAY_SIZE(audio_reg_cfg); i++)
3880 if (audio_reg_cfg[i].reg_logical_addr -
Joonwoo Park1d05bb92013-03-07 16:55:06 -08003881 TAIKO_REGISTER_START_OFFSET == reg)
3882 return 1;
3883
Kiran Kandic3b24402012-06-11 00:05:59 -07003884 return 0;
3885}
3886
Kiran Kandic3b24402012-06-11 00:05:59 -07003887static int taiko_write(struct snd_soc_codec *codec, unsigned int reg,
3888 unsigned int value)
3889{
3890 int ret;
Kuirong Wang906ac472012-07-09 12:54:44 -07003891
3892 if (reg == SND_SOC_NOPM)
3893 return 0;
3894
Kiran Kandic3b24402012-06-11 00:05:59 -07003895 BUG_ON(reg > TAIKO_MAX_REGISTER);
3896
3897 if (!taiko_volatile(codec, reg)) {
3898 ret = snd_soc_cache_write(codec, reg, value);
3899 if (ret != 0)
3900 dev_err(codec->dev, "Cache write to %x failed: %d\n",
3901 reg, ret);
3902 }
3903
3904 return wcd9xxx_reg_write(codec->control_data, reg, value);
3905}
3906static unsigned int taiko_read(struct snd_soc_codec *codec,
3907 unsigned int reg)
3908{
3909 unsigned int val;
3910 int ret;
3911
Kuirong Wang906ac472012-07-09 12:54:44 -07003912 if (reg == SND_SOC_NOPM)
3913 return 0;
3914
Kiran Kandic3b24402012-06-11 00:05:59 -07003915 BUG_ON(reg > TAIKO_MAX_REGISTER);
3916
3917 if (!taiko_volatile(codec, reg) && taiko_readable(codec, reg) &&
3918 reg < codec->driver->reg_cache_size) {
3919 ret = snd_soc_cache_read(codec, reg, &val);
3920 if (ret >= 0) {
3921 return val;
3922 } else
3923 dev_err(codec->dev, "Cache read from %x failed: %d\n",
3924 reg, ret);
3925 }
3926
3927 val = wcd9xxx_reg_read(codec->control_data, reg);
3928 return val;
3929}
3930
Kiran Kandic3b24402012-06-11 00:05:59 -07003931static int taiko_startup(struct snd_pcm_substream *substream,
3932 struct snd_soc_dai *dai)
3933{
3934 struct wcd9xxx *taiko_core = dev_get_drvdata(dai->codec->dev->parent);
3935 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
3936 substream->name, substream->stream);
3937 if ((taiko_core != NULL) &&
3938 (taiko_core->dev != NULL) &&
3939 (taiko_core->dev->parent != NULL))
3940 pm_runtime_get_sync(taiko_core->dev->parent);
3941
3942 return 0;
3943}
3944
3945static void taiko_shutdown(struct snd_pcm_substream *substream,
3946 struct snd_soc_dai *dai)
3947{
3948 struct wcd9xxx *taiko_core = dev_get_drvdata(dai->codec->dev->parent);
3949 pr_debug("%s(): substream = %s stream = %d\n" , __func__,
3950 substream->name, substream->stream);
3951 if ((taiko_core != NULL) &&
3952 (taiko_core->dev != NULL) &&
3953 (taiko_core->dev->parent != NULL)) {
3954 pm_runtime_mark_last_busy(taiko_core->dev->parent);
3955 pm_runtime_put(taiko_core->dev->parent);
3956 }
3957}
3958
3959int taiko_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, bool dapm)
3960{
3961 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
3962
3963 pr_debug("%s: mclk_enable = %u, dapm = %d\n", __func__, mclk_enable,
3964 dapm);
Joonwoo Parka8890262012-10-15 12:04:27 -07003965
3966 WCD9XXX_BCL_LOCK(&taiko->resmgr);
Kiran Kandic3b24402012-06-11 00:05:59 -07003967 if (mclk_enable) {
Joonwoo Parka8890262012-10-15 12:04:27 -07003968 wcd9xxx_resmgr_get_bandgap(&taiko->resmgr,
3969 WCD9XXX_BANDGAP_AUDIO_MODE);
3970 wcd9xxx_resmgr_get_clk_block(&taiko->resmgr, WCD9XXX_CLK_MCLK);
Kiran Kandic3b24402012-06-11 00:05:59 -07003971 } else {
Joonwoo Parka8890262012-10-15 12:04:27 -07003972 /* Put clock and BG */
3973 wcd9xxx_resmgr_put_clk_block(&taiko->resmgr, WCD9XXX_CLK_MCLK);
3974 wcd9xxx_resmgr_put_bandgap(&taiko->resmgr,
3975 WCD9XXX_BANDGAP_AUDIO_MODE);
Kiran Kandic3b24402012-06-11 00:05:59 -07003976 }
Joonwoo Parka8890262012-10-15 12:04:27 -07003977 WCD9XXX_BCL_UNLOCK(&taiko->resmgr);
3978
Kiran Kandic3b24402012-06-11 00:05:59 -07003979 return 0;
3980}
3981
3982static int taiko_set_dai_sysclk(struct snd_soc_dai *dai,
3983 int clk_id, unsigned int freq, int dir)
3984{
Venkat Sudhira50a3762012-11-26 12:12:15 -08003985 pr_debug("%s\n", __func__);
Kiran Kandic3b24402012-06-11 00:05:59 -07003986 return 0;
3987}
3988
3989static int taiko_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3990{
3991 u8 val = 0;
3992 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(dai->codec);
3993
3994 pr_debug("%s\n", __func__);
3995 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
3996 case SND_SOC_DAIFMT_CBS_CFS:
3997 /* CPU is master */
3998 if (taiko->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
3999 if (dai->id == AIF1_CAP)
4000 snd_soc_update_bits(dai->codec,
4001 TAIKO_A_CDC_CLK_TX_I2S_CTL,
4002 TAIKO_I2S_MASTER_MODE_MASK, 0);
4003 else if (dai->id == AIF1_PB)
4004 snd_soc_update_bits(dai->codec,
4005 TAIKO_A_CDC_CLK_RX_I2S_CTL,
4006 TAIKO_I2S_MASTER_MODE_MASK, 0);
4007 }
4008 break;
4009 case SND_SOC_DAIFMT_CBM_CFM:
4010 /* CPU is slave */
4011 if (taiko->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
4012 val = TAIKO_I2S_MASTER_MODE_MASK;
4013 if (dai->id == AIF1_CAP)
4014 snd_soc_update_bits(dai->codec,
4015 TAIKO_A_CDC_CLK_TX_I2S_CTL, val, val);
4016 else if (dai->id == AIF1_PB)
4017 snd_soc_update_bits(dai->codec,
4018 TAIKO_A_CDC_CLK_RX_I2S_CTL, val, val);
4019 }
4020 break;
4021 default:
4022 return -EINVAL;
4023 }
4024 return 0;
4025}
4026
4027static int taiko_set_channel_map(struct snd_soc_dai *dai,
4028 unsigned int tx_num, unsigned int *tx_slot,
4029 unsigned int rx_num, unsigned int *rx_slot)
4030
4031{
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05004032 struct wcd9xxx_codec_dai_data *dai_data = NULL;
Kiran Kandic3b24402012-06-11 00:05:59 -07004033 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(dai->codec);
Kuirong Wang906ac472012-07-09 12:54:44 -07004034 struct wcd9xxx *core = dev_get_drvdata(dai->codec->dev->parent);
Kiran Kandic3b24402012-06-11 00:05:59 -07004035 if (!tx_slot && !rx_slot) {
4036 pr_err("%s: Invalid\n", __func__);
4037 return -EINVAL;
4038 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004039 pr_debug("%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n"
4040 "taiko->intf_type %d\n",
4041 __func__, dai->name, dai->id, tx_num, rx_num,
4042 taiko->intf_type);
Kiran Kandic3b24402012-06-11 00:05:59 -07004043
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05004044 if (taiko->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
Kuirong Wang906ac472012-07-09 12:54:44 -07004045 wcd9xxx_init_slimslave(core, core->slim->laddr,
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05004046 tx_num, tx_slot, rx_num, rx_slot);
4047 /*Reserve tx11 and tx12 for VI feedback path*/
4048 dai_data = &taiko->dai[AIF4_VIFEED];
4049 if (dai_data) {
4050 list_add_tail(&core->tx_chs[TAIKO_TX11].list,
4051 &dai_data->wcd9xxx_ch_list);
4052 list_add_tail(&core->tx_chs[TAIKO_TX12].list,
4053 &dai_data->wcd9xxx_ch_list);
4054 }
4055 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004056 return 0;
4057}
4058
4059static int taiko_get_channel_map(struct snd_soc_dai *dai,
4060 unsigned int *tx_num, unsigned int *tx_slot,
4061 unsigned int *rx_num, unsigned int *rx_slot)
4062
4063{
4064 struct taiko_priv *taiko_p = snd_soc_codec_get_drvdata(dai->codec);
4065 u32 i = 0;
4066 struct wcd9xxx_ch *ch;
4067
4068 switch (dai->id) {
4069 case AIF1_PB:
4070 case AIF2_PB:
4071 case AIF3_PB:
4072 if (!rx_slot || !rx_num) {
4073 pr_err("%s: Invalid rx_slot %d or rx_num %d\n",
4074 __func__, (u32) rx_slot, (u32) rx_num);
4075 return -EINVAL;
Kiran Kandic3b24402012-06-11 00:05:59 -07004076 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004077 list_for_each_entry(ch, &taiko_p->dai[dai->id].wcd9xxx_ch_list,
4078 list) {
Gopikrishnaiah Anandana8aec1f2013-01-23 14:26:27 -05004079 pr_debug("%s: slot_num %u ch->ch_num %d\n",
4080 __func__, i, ch->ch_num);
Kuirong Wang906ac472012-07-09 12:54:44 -07004081 rx_slot[i++] = ch->ch_num;
4082 }
4083 pr_debug("%s: rx_num %d\n", __func__, i);
4084 *rx_num = i;
4085 break;
4086 case AIF1_CAP:
4087 case AIF2_CAP:
4088 case AIF3_CAP:
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05004089 case AIF4_VIFEED:
Joonwoo Park1d05bb92013-03-07 16:55:06 -08004090 case AIF4_MAD_TX:
Kuirong Wang906ac472012-07-09 12:54:44 -07004091 if (!tx_slot || !tx_num) {
4092 pr_err("%s: Invalid tx_slot %d or tx_num %d\n",
4093 __func__, (u32) tx_slot, (u32) tx_num);
4094 return -EINVAL;
4095 }
4096 list_for_each_entry(ch, &taiko_p->dai[dai->id].wcd9xxx_ch_list,
4097 list) {
Gopikrishnaiah Anandana8aec1f2013-01-23 14:26:27 -05004098 pr_debug("%s: slot_num %u ch->ch_num %d\n",
4099 __func__, i, ch->ch_num);
Kuirong Wang906ac472012-07-09 12:54:44 -07004100 tx_slot[i++] = ch->ch_num;
4101 }
4102 pr_debug("%s: tx_num %d\n", __func__, i);
4103 *tx_num = i;
4104 break;
4105
4106 default:
4107 pr_err("%s: Invalid DAI ID %x\n", __func__, dai->id);
4108 break;
4109 }
4110
4111 return 0;
4112}
4113
4114static int taiko_set_interpolator_rate(struct snd_soc_dai *dai,
4115 u8 rx_fs_rate_reg_val, u32 compander_fs, u32 sample_rate)
4116{
4117 u32 j;
4118 u8 rx_mix1_inp;
4119 u16 rx_mix_1_reg_1, rx_mix_1_reg_2;
4120 u16 rx_fs_reg;
4121 u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val;
4122 struct snd_soc_codec *codec = dai->codec;
4123 struct wcd9xxx_ch *ch;
4124 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
4125
4126 list_for_each_entry(ch, &taiko->dai[dai->id].wcd9xxx_ch_list, list) {
4127 /* for RX port starting from 16 instead of 10 like tabla */
4128 rx_mix1_inp = ch->port + RX_MIX1_INP_SEL_RX1 -
4129 TAIKO_TX_PORT_NUMBER;
4130 if ((rx_mix1_inp < RX_MIX1_INP_SEL_RX1) ||
4131 (rx_mix1_inp > RX_MIX1_INP_SEL_RX7)) {
4132 pr_err("%s: Invalid TAIKO_RX%u port. Dai ID is %d\n",
4133 __func__, rx_mix1_inp - 5 , dai->id);
4134 return -EINVAL;
4135 }
4136
4137 rx_mix_1_reg_1 = TAIKO_A_CDC_CONN_RX1_B1_CTL;
4138
4139 for (j = 0; j < NUM_INTERPOLATORS; j++) {
4140 rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1;
4141
4142 rx_mix_1_reg_1_val = snd_soc_read(codec,
4143 rx_mix_1_reg_1);
4144 rx_mix_1_reg_2_val = snd_soc_read(codec,
4145 rx_mix_1_reg_2);
4146
4147 if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) ||
4148 (((rx_mix_1_reg_1_val >> 4) & 0x0F)
4149 == rx_mix1_inp) ||
4150 ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) {
4151
4152 rx_fs_reg = TAIKO_A_CDC_RX1_B5_CTL + 8 * j;
4153
4154 pr_debug("%s: AIF_PB DAI(%d) connected to RX%u\n",
4155 __func__, dai->id, j + 1);
4156
4157 pr_debug("%s: set RX%u sample rate to %u\n",
4158 __func__, j + 1, sample_rate);
4159
4160 snd_soc_update_bits(codec, rx_fs_reg,
4161 0xE0, rx_fs_rate_reg_val);
4162
4163 if (comp_rx_path[j] < COMPANDER_MAX)
4164 taiko->comp_fs[comp_rx_path[j]]
4165 = compander_fs;
4166 }
Kuirong Wang94761952013-03-07 16:19:35 -08004167 if (j < 2)
Kuirong Wang906ac472012-07-09 12:54:44 -07004168 rx_mix_1_reg_1 += 3;
4169 else
4170 rx_mix_1_reg_1 += 2;
Kiran Kandic3b24402012-06-11 00:05:59 -07004171 }
4172 }
4173 return 0;
4174}
4175
Kuirong Wang906ac472012-07-09 12:54:44 -07004176static int taiko_set_decimator_rate(struct snd_soc_dai *dai,
4177 u8 tx_fs_rate_reg_val, u32 sample_rate)
Kiran Kandic3b24402012-06-11 00:05:59 -07004178{
Kuirong Wang906ac472012-07-09 12:54:44 -07004179 struct snd_soc_codec *codec = dai->codec;
4180 struct wcd9xxx_ch *ch;
4181 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
4182 u32 tx_port;
4183 u16 tx_port_reg, tx_fs_reg;
4184 u8 tx_port_reg_val;
4185 s8 decimator;
Kiran Kandic3b24402012-06-11 00:05:59 -07004186
Kuirong Wang906ac472012-07-09 12:54:44 -07004187 list_for_each_entry(ch, &taiko->dai[dai->id].wcd9xxx_ch_list, list) {
Kiran Kandic3b24402012-06-11 00:05:59 -07004188
Kuirong Wang906ac472012-07-09 12:54:44 -07004189 tx_port = ch->port + 1;
4190 pr_debug("%s: dai->id = %d, tx_port = %d",
4191 __func__, dai->id, tx_port);
4192
4193 if ((tx_port < 1) || (tx_port > NUM_DECIMATORS)) {
4194 pr_err("%s: Invalid SLIM TX%u port. DAI ID is %d\n",
4195 __func__, tx_port, dai->id);
4196 return -EINVAL;
4197 }
4198
4199 tx_port_reg = TAIKO_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1);
4200 tx_port_reg_val = snd_soc_read(codec, tx_port_reg);
4201
4202 decimator = 0;
4203
4204 if ((tx_port >= 1) && (tx_port <= 6)) {
4205
4206 tx_port_reg_val = tx_port_reg_val & 0x0F;
4207 if (tx_port_reg_val == 0x8)
4208 decimator = tx_port;
4209
4210 } else if ((tx_port >= 7) && (tx_port <= NUM_DECIMATORS)) {
4211
4212 tx_port_reg_val = tx_port_reg_val & 0x1F;
4213
4214 if ((tx_port_reg_val >= 0x8) &&
4215 (tx_port_reg_val <= 0x11)) {
4216
4217 decimator = (tx_port_reg_val - 0x8) + 1;
4218 }
4219 }
4220
4221 if (decimator) { /* SLIM_TX port has a DEC as input */
4222
4223 tx_fs_reg = TAIKO_A_CDC_TX1_CLK_FS_CTL +
4224 8 * (decimator - 1);
4225
4226 pr_debug("%s: set DEC%u (-> SLIM_TX%u) rate to %u\n",
4227 __func__, decimator, tx_port, sample_rate);
4228
4229 snd_soc_update_bits(codec, tx_fs_reg, 0x07,
4230 tx_fs_rate_reg_val);
4231
4232 } else {
4233 if ((tx_port_reg_val >= 0x1) &&
4234 (tx_port_reg_val <= 0x7)) {
4235
4236 pr_debug("%s: RMIX%u going to SLIM TX%u\n",
4237 __func__, tx_port_reg_val, tx_port);
4238
4239 } else if ((tx_port_reg_val >= 0x8) &&
4240 (tx_port_reg_val <= 0x11)) {
4241
4242 pr_err("%s: ERROR: Should not be here\n",
4243 __func__);
4244 pr_err("%s: ERROR: DEC connected to SLIM TX%u\n",
4245 __func__, tx_port);
4246 return -EINVAL;
4247
4248 } else if (tx_port_reg_val == 0) {
4249 pr_debug("%s: no signal to SLIM TX%u\n",
4250 __func__, tx_port);
4251 } else {
4252 pr_err("%s: ERROR: wrong signal to SLIM TX%u\n",
4253 __func__, tx_port);
4254 pr_err("%s: ERROR: wrong signal = %u\n",
4255 __func__, tx_port_reg_val);
4256 return -EINVAL;
4257 }
4258 }
Kiran Kandic3b24402012-06-11 00:05:59 -07004259 }
Kiran Kandic3b24402012-06-11 00:05:59 -07004260 return 0;
4261}
4262
4263static int taiko_hw_params(struct snd_pcm_substream *substream,
4264 struct snd_pcm_hw_params *params,
4265 struct snd_soc_dai *dai)
4266{
4267 struct snd_soc_codec *codec = dai->codec;
4268 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(dai->codec);
Kuirong Wang906ac472012-07-09 12:54:44 -07004269 u8 tx_fs_rate, rx_fs_rate;
Kiran Kandic3b24402012-06-11 00:05:59 -07004270 u32 compander_fs;
Kuirong Wang906ac472012-07-09 12:54:44 -07004271 int ret;
Kiran Kandic3b24402012-06-11 00:05:59 -07004272
4273 pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
4274 dai->name, dai->id, params_rate(params),
4275 params_channels(params));
4276
4277 switch (params_rate(params)) {
4278 case 8000:
4279 tx_fs_rate = 0x00;
4280 rx_fs_rate = 0x00;
4281 compander_fs = COMPANDER_FS_8KHZ;
4282 break;
4283 case 16000:
4284 tx_fs_rate = 0x01;
4285 rx_fs_rate = 0x20;
4286 compander_fs = COMPANDER_FS_16KHZ;
4287 break;
4288 case 32000:
4289 tx_fs_rate = 0x02;
4290 rx_fs_rate = 0x40;
4291 compander_fs = COMPANDER_FS_32KHZ;
4292 break;
4293 case 48000:
4294 tx_fs_rate = 0x03;
4295 rx_fs_rate = 0x60;
4296 compander_fs = COMPANDER_FS_48KHZ;
4297 break;
4298 case 96000:
4299 tx_fs_rate = 0x04;
4300 rx_fs_rate = 0x80;
4301 compander_fs = COMPANDER_FS_96KHZ;
4302 break;
4303 case 192000:
4304 tx_fs_rate = 0x05;
4305 rx_fs_rate = 0xA0;
4306 compander_fs = COMPANDER_FS_192KHZ;
4307 break;
4308 default:
4309 pr_err("%s: Invalid sampling rate %d\n", __func__,
Kuirong Wang906ac472012-07-09 12:54:44 -07004310 params_rate(params));
Kiran Kandic3b24402012-06-11 00:05:59 -07004311 return -EINVAL;
4312 }
4313
Kuirong Wang906ac472012-07-09 12:54:44 -07004314 switch (substream->stream) {
4315 case SNDRV_PCM_STREAM_CAPTURE:
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05004316 if (dai->id != AIF4_VIFEED) {
4317 ret = taiko_set_decimator_rate(dai, tx_fs_rate,
4318 params_rate(params));
4319 if (ret < 0) {
4320 pr_err("%s: set decimator rate failed %d\n",
4321 __func__, ret);
4322 return ret;
4323 }
Kiran Kandic3b24402012-06-11 00:05:59 -07004324 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004325
Kiran Kandic3b24402012-06-11 00:05:59 -07004326 if (taiko->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
4327 switch (params_format(params)) {
4328 case SNDRV_PCM_FORMAT_S16_LE:
4329 snd_soc_update_bits(codec,
4330 TAIKO_A_CDC_CLK_TX_I2S_CTL,
4331 0x20, 0x20);
4332 break;
4333 case SNDRV_PCM_FORMAT_S32_LE:
4334 snd_soc_update_bits(codec,
4335 TAIKO_A_CDC_CLK_TX_I2S_CTL,
4336 0x20, 0x00);
4337 break;
4338 default:
4339 pr_err("invalid format\n");
4340 break;
4341 }
4342 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_TX_I2S_CTL,
Kuirong Wang906ac472012-07-09 12:54:44 -07004343 0x07, tx_fs_rate);
Kiran Kandic3b24402012-06-11 00:05:59 -07004344 } else {
Kuirong Wang906ac472012-07-09 12:54:44 -07004345 taiko->dai[dai->id].rate = params_rate(params);
Kiran Kandic3b24402012-06-11 00:05:59 -07004346 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004347 break;
Kiran Kandic3b24402012-06-11 00:05:59 -07004348
Kuirong Wang906ac472012-07-09 12:54:44 -07004349 case SNDRV_PCM_STREAM_PLAYBACK:
4350 ret = taiko_set_interpolator_rate(dai, rx_fs_rate,
4351 compander_fs,
4352 params_rate(params));
4353 if (ret < 0) {
4354 pr_err("%s: set decimator rate failed %d\n", __func__,
4355 ret);
4356 return ret;
Kiran Kandic3b24402012-06-11 00:05:59 -07004357 }
4358 if (taiko->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
4359 switch (params_format(params)) {
4360 case SNDRV_PCM_FORMAT_S16_LE:
4361 snd_soc_update_bits(codec,
4362 TAIKO_A_CDC_CLK_RX_I2S_CTL,
4363 0x20, 0x20);
4364 break;
4365 case SNDRV_PCM_FORMAT_S32_LE:
4366 snd_soc_update_bits(codec,
4367 TAIKO_A_CDC_CLK_RX_I2S_CTL,
4368 0x20, 0x00);
4369 break;
4370 default:
4371 pr_err("invalid format\n");
4372 break;
4373 }
4374 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_RX_I2S_CTL,
Kuirong Wang906ac472012-07-09 12:54:44 -07004375 0x03, (rx_fs_rate >> 0x05));
Kiran Kandic3b24402012-06-11 00:05:59 -07004376 } else {
Bhalchandra Gajare5b40c532013-02-19 13:36:47 -08004377 switch (params_format(params)) {
4378 case SNDRV_PCM_FORMAT_S16_LE:
4379 snd_soc_update_bits(codec,
4380 TAIKO_A_CDC_CONN_RX_SB_B1_CTL,
4381 0xFF, 0xAA);
4382 snd_soc_update_bits(codec,
4383 TAIKO_A_CDC_CONN_RX_SB_B2_CTL,
4384 0xFF, 0x2A);
4385 taiko->dai[dai->id].bit_width = 16;
4386 break;
4387 case SNDRV_PCM_FORMAT_S24_LE:
4388 snd_soc_update_bits(codec,
4389 TAIKO_A_CDC_CONN_RX_SB_B1_CTL,
4390 0xFF, 0x00);
4391 snd_soc_update_bits(codec,
4392 TAIKO_A_CDC_CONN_RX_SB_B2_CTL,
4393 0xFF, 0x00);
4394 taiko->dai[dai->id].bit_width = 24;
4395 break;
4396 default:
4397 dev_err(codec->dev, "Invalid format\n");
4398 break;
4399 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004400 taiko->dai[dai->id].rate = params_rate(params);
Kiran Kandic3b24402012-06-11 00:05:59 -07004401 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004402 break;
4403 default:
4404 pr_err("%s: Invalid stream type %d\n", __func__,
4405 substream->stream);
4406 return -EINVAL;
Kiran Kandic3b24402012-06-11 00:05:59 -07004407 }
4408
4409 return 0;
4410}
4411
4412static struct snd_soc_dai_ops taiko_dai_ops = {
4413 .startup = taiko_startup,
4414 .shutdown = taiko_shutdown,
4415 .hw_params = taiko_hw_params,
4416 .set_sysclk = taiko_set_dai_sysclk,
4417 .set_fmt = taiko_set_dai_fmt,
4418 .set_channel_map = taiko_set_channel_map,
4419 .get_channel_map = taiko_get_channel_map,
4420};
4421
4422static struct snd_soc_dai_driver taiko_dai[] = {
4423 {
4424 .name = "taiko_rx1",
4425 .id = AIF1_PB,
4426 .playback = {
4427 .stream_name = "AIF1 Playback",
4428 .rates = WCD9320_RATES,
Bhalchandra Gajare5b40c532013-02-19 13:36:47 -08004429 .formats = TAIKO_FORMATS_S16_S24_LE,
Kiran Kandic3b24402012-06-11 00:05:59 -07004430 .rate_max = 192000,
4431 .rate_min = 8000,
4432 .channels_min = 1,
4433 .channels_max = 2,
4434 },
4435 .ops = &taiko_dai_ops,
4436 },
4437 {
4438 .name = "taiko_tx1",
4439 .id = AIF1_CAP,
4440 .capture = {
4441 .stream_name = "AIF1 Capture",
4442 .rates = WCD9320_RATES,
4443 .formats = TAIKO_FORMATS,
4444 .rate_max = 192000,
4445 .rate_min = 8000,
4446 .channels_min = 1,
4447 .channels_max = 4,
4448 },
4449 .ops = &taiko_dai_ops,
4450 },
4451 {
4452 .name = "taiko_rx2",
4453 .id = AIF2_PB,
4454 .playback = {
4455 .stream_name = "AIF2 Playback",
4456 .rates = WCD9320_RATES,
Bhalchandra Gajare5b40c532013-02-19 13:36:47 -08004457 .formats = TAIKO_FORMATS_S16_S24_LE,
Kiran Kandic3b24402012-06-11 00:05:59 -07004458 .rate_min = 8000,
4459 .rate_max = 192000,
4460 .channels_min = 1,
4461 .channels_max = 2,
4462 },
4463 .ops = &taiko_dai_ops,
4464 },
4465 {
4466 .name = "taiko_tx2",
4467 .id = AIF2_CAP,
4468 .capture = {
4469 .stream_name = "AIF2 Capture",
4470 .rates = WCD9320_RATES,
4471 .formats = TAIKO_FORMATS,
4472 .rate_max = 192000,
4473 .rate_min = 8000,
4474 .channels_min = 1,
Baruch Eruchimovitch64eb8da2013-04-08 14:33:17 +03004475 .channels_max = 5,
Kiran Kandic3b24402012-06-11 00:05:59 -07004476 },
4477 .ops = &taiko_dai_ops,
4478 },
4479 {
4480 .name = "taiko_tx3",
4481 .id = AIF3_CAP,
4482 .capture = {
4483 .stream_name = "AIF3 Capture",
4484 .rates = WCD9320_RATES,
4485 .formats = TAIKO_FORMATS,
4486 .rate_max = 48000,
4487 .rate_min = 8000,
4488 .channels_min = 1,
4489 .channels_max = 2,
4490 },
4491 .ops = &taiko_dai_ops,
4492 },
4493 {
4494 .name = "taiko_rx3",
4495 .id = AIF3_PB,
4496 .playback = {
4497 .stream_name = "AIF3 Playback",
4498 .rates = WCD9320_RATES,
Bhalchandra Gajare5b40c532013-02-19 13:36:47 -08004499 .formats = TAIKO_FORMATS_S16_S24_LE,
Kiran Kandic3b24402012-06-11 00:05:59 -07004500 .rate_min = 8000,
4501 .rate_max = 192000,
4502 .channels_min = 1,
4503 .channels_max = 2,
4504 },
4505 .ops = &taiko_dai_ops,
4506 },
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05004507 {
4508 .name = "taiko_vifeedback",
4509 .id = AIF4_VIFEED,
4510 .capture = {
4511 .stream_name = "VIfeed",
4512 .rates = SNDRV_PCM_RATE_48000,
4513 .formats = TAIKO_FORMATS,
4514 .rate_max = 48000,
4515 .rate_min = 48000,
4516 .channels_min = 2,
4517 .channels_max = 2,
4518 },
4519 .ops = &taiko_dai_ops,
4520 },
Joonwoo Park1d05bb92013-03-07 16:55:06 -08004521 {
4522 .name = "taiko_mad1",
4523 .id = AIF4_MAD_TX,
4524 .capture = {
4525 .stream_name = "AIF4 MAD TX",
4526 .rates = SNDRV_PCM_RATE_16000,
4527 .formats = TAIKO_FORMATS,
4528 .rate_min = 16000,
4529 .rate_max = 16000,
4530 .channels_min = 1,
4531 .channels_max = 1,
4532 },
4533 .ops = &taiko_dai_ops,
4534 },
Kiran Kandic3b24402012-06-11 00:05:59 -07004535};
4536
4537static struct snd_soc_dai_driver taiko_i2s_dai[] = {
4538 {
4539 .name = "taiko_i2s_rx1",
Kuirong Wang906ac472012-07-09 12:54:44 -07004540 .id = AIF1_PB,
Kiran Kandic3b24402012-06-11 00:05:59 -07004541 .playback = {
4542 .stream_name = "AIF1 Playback",
4543 .rates = WCD9320_RATES,
4544 .formats = TAIKO_FORMATS,
4545 .rate_max = 192000,
4546 .rate_min = 8000,
4547 .channels_min = 1,
4548 .channels_max = 4,
4549 },
4550 .ops = &taiko_dai_ops,
4551 },
4552 {
4553 .name = "taiko_i2s_tx1",
Kuirong Wang906ac472012-07-09 12:54:44 -07004554 .id = AIF1_CAP,
Kiran Kandic3b24402012-06-11 00:05:59 -07004555 .capture = {
4556 .stream_name = "AIF1 Capture",
4557 .rates = WCD9320_RATES,
4558 .formats = TAIKO_FORMATS,
4559 .rate_max = 192000,
4560 .rate_min = 8000,
4561 .channels_min = 1,
4562 .channels_max = 4,
4563 },
4564 .ops = &taiko_dai_ops,
4565 },
Venkat Sudhir994193b2012-12-17 17:30:51 -08004566 {
4567 .name = "taiko_i2s_rx2",
4568 .id = AIF1_PB,
4569 .playback = {
4570 .stream_name = "AIF2 Playback",
4571 .rates = WCD9320_RATES,
4572 .formats = TAIKO_FORMATS,
4573 .rate_max = 192000,
4574 .rate_min = 8000,
4575 .channels_min = 1,
4576 .channels_max = 4,
4577 },
4578 .ops = &taiko_dai_ops,
4579 },
4580 {
4581 .name = "taiko_i2s_tx2",
4582 .id = AIF1_CAP,
4583 .capture = {
4584 .stream_name = "AIF2 Capture",
4585 .rates = WCD9320_RATES,
4586 .formats = TAIKO_FORMATS,
4587 .rate_max = 192000,
4588 .rate_min = 8000,
4589 .channels_min = 1,
4590 .channels_max = 4,
4591 },
4592 .ops = &taiko_dai_ops,
4593 },
Kiran Kandic3b24402012-06-11 00:05:59 -07004594};
4595
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08004596static int taiko_codec_enable_slim_chmask(struct wcd9xxx_codec_dai_data *dai,
4597 bool up)
4598{
4599 int ret = 0;
4600 struct wcd9xxx_ch *ch;
4601
4602 if (up) {
4603 list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) {
4604 ret = wcd9xxx_get_slave_port(ch->ch_num);
4605 if (ret < 0) {
4606 pr_err("%s: Invalid slave port ID: %d\n",
4607 __func__, ret);
4608 ret = -EINVAL;
4609 } else {
4610 set_bit(ret, &dai->ch_mask);
4611 }
4612 }
4613 } else {
4614 ret = wait_event_timeout(dai->dai_wait, (dai->ch_mask == 0),
4615 msecs_to_jiffies(
4616 TAIKO_SLIM_CLOSE_TIMEOUT));
4617 if (!ret) {
4618 pr_err("%s: Slim close tx/rx wait timeout\n", __func__);
4619 ret = -ETIMEDOUT;
4620 } else {
4621 ret = 0;
4622 }
4623 }
4624 return ret;
4625}
4626
Kiran Kandic3b24402012-06-11 00:05:59 -07004627static int taiko_codec_enable_slimrx(struct snd_soc_dapm_widget *w,
Kuirong Wang906ac472012-07-09 12:54:44 -07004628 struct snd_kcontrol *kcontrol,
4629 int event)
Kiran Kandic3b24402012-06-11 00:05:59 -07004630{
Kuirong Wang906ac472012-07-09 12:54:44 -07004631 struct wcd9xxx *core;
Kiran Kandic3b24402012-06-11 00:05:59 -07004632 struct snd_soc_codec *codec = w->codec;
4633 struct taiko_priv *taiko_p = snd_soc_codec_get_drvdata(codec);
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08004634 int ret = 0;
Kuirong Wang906ac472012-07-09 12:54:44 -07004635 struct wcd9xxx_codec_dai_data *dai;
4636
4637 core = dev_get_drvdata(codec->dev->parent);
4638
4639 pr_debug("%s: event called! codec name %s num_dai %d\n"
4640 "stream name %s event %d\n",
4641 __func__, w->codec->name, w->codec->num_dai, w->sname, event);
4642
Kiran Kandic3b24402012-06-11 00:05:59 -07004643 /* Execute the callback only if interface type is slimbus */
4644 if (taiko_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
4645 return 0;
4646
Kuirong Wang906ac472012-07-09 12:54:44 -07004647 dai = &taiko_p->dai[w->shift];
4648 pr_debug("%s: w->name %s w->shift %d event %d\n",
4649 __func__, w->name, w->shift, event);
Kiran Kandic3b24402012-06-11 00:05:59 -07004650
4651 switch (event) {
4652 case SND_SOC_DAPM_POST_PMU:
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08004653 (void) taiko_codec_enable_slim_chmask(dai, true);
Kuirong Wang906ac472012-07-09 12:54:44 -07004654 ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
4655 dai->rate, dai->bit_width,
4656 &dai->grph);
Kiran Kandic3b24402012-06-11 00:05:59 -07004657 break;
4658 case SND_SOC_DAPM_POST_PMD:
Kuirong Wang906ac472012-07-09 12:54:44 -07004659 ret = wcd9xxx_close_slim_sch_rx(core, &dai->wcd9xxx_ch_list,
4660 dai->grph);
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08004661 ret = taiko_codec_enable_slim_chmask(dai, false);
4662 if (ret < 0) {
4663 ret = wcd9xxx_disconnect_port(core,
4664 &dai->wcd9xxx_ch_list,
4665 dai->grph);
4666 pr_debug("%s: Disconnect RX port, ret = %d\n",
4667 __func__, ret);
4668 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004669 break;
Kiran Kandic3b24402012-06-11 00:05:59 -07004670 }
4671 return ret;
4672}
4673
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05004674static int taiko_codec_enable_slimvi_feedback(struct snd_soc_dapm_widget *w,
4675 struct snd_kcontrol *kcontrol,
4676 int event)
4677{
4678 struct wcd9xxx *core = NULL;
4679 struct snd_soc_codec *codec = NULL;
4680 struct taiko_priv *taiko_p = NULL;
4681 u32 ret = 0;
4682 struct wcd9xxx_codec_dai_data *dai = NULL;
4683
4684 if (!w || !w->codec) {
4685 pr_err("%s invalid params\n", __func__);
4686 return -EINVAL;
4687 }
4688 codec = w->codec;
4689 taiko_p = snd_soc_codec_get_drvdata(codec);
4690 core = dev_get_drvdata(codec->dev->parent);
4691
4692 pr_debug("%s: event called! codec name %s num_dai %d stream name %s\n",
4693 __func__, w->codec->name, w->codec->num_dai, w->sname);
4694
4695 /* Execute the callback only if interface type is slimbus */
4696 if (taiko_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
4697 pr_err("%s Interface is not correct", __func__);
4698 return 0;
4699 }
4700
4701 pr_debug("%s(): w->name %s event %d w->shift %d\n",
4702 __func__, w->name, event, w->shift);
4703 if (w->shift != AIF4_VIFEED) {
4704 pr_err("%s Error in enabling the tx path\n", __func__);
4705 ret = -EINVAL;
4706 goto out_vi;
4707 }
4708 dai = &taiko_p->dai[w->shift];
4709 switch (event) {
4710 case SND_SOC_DAPM_POST_PMU:
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05004711 /*Enable V&I sensing*/
4712 snd_soc_update_bits(codec, TAIKO_A_SPKR_PROT_EN,
4713 0x88, 0x88);
4714 /*Enable spkr VI clocks*/
4715 snd_soc_update_bits(codec,
4716 TAIKO_A_CDC_CLK_TX_CLK_EN_B2_CTL, 0xC, 0xC);
4717 /*Enable Voltage Decimator*/
4718 snd_soc_update_bits(codec,
4719 TAIKO_A_CDC_CONN_TX_SB_B9_CTL, 0x1F, 0x12);
4720 /*Enable Current Decimator*/
4721 snd_soc_update_bits(codec,
4722 TAIKO_A_CDC_CONN_TX_SB_B10_CTL, 0x1F, 0x13);
Gopikrishnaiah Anandand3b89c02013-04-16 11:22:15 -04004723 (void) taiko_codec_enable_slim_chmask(dai, true);
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05004724 ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
4725 dai->rate, dai->bit_width,
4726 &dai->grph);
4727 break;
4728 case SND_SOC_DAPM_POST_PMD:
4729 ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
4730 dai->grph);
4731 if (ret)
4732 pr_err("%s error in close_slim_sch_tx %d\n",
4733 __func__, ret);
4734 /*Disable Voltage decimator*/
4735 snd_soc_update_bits(codec,
4736 TAIKO_A_CDC_CONN_TX_SB_B9_CTL, 0x1F, 0x0);
4737 /*Disable Current decimator*/
4738 snd_soc_update_bits(codec,
4739 TAIKO_A_CDC_CONN_TX_SB_B10_CTL, 0x1F, 0x0);
4740 /*Disable spkr VI clocks*/
4741 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_TX_CLK_EN_B2_CTL,
4742 0xC, 0x0);
4743 /*Disable V&I sensing*/
4744 snd_soc_update_bits(codec, TAIKO_A_SPKR_PROT_EN,
4745 0x88, 0x00);
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05004746 break;
4747 }
4748out_vi:
4749 return ret;
4750}
4751
Kiran Kandic3b24402012-06-11 00:05:59 -07004752static int taiko_codec_enable_slimtx(struct snd_soc_dapm_widget *w,
Kuirong Wang906ac472012-07-09 12:54:44 -07004753 struct snd_kcontrol *kcontrol,
4754 int event)
Kiran Kandic3b24402012-06-11 00:05:59 -07004755{
Kuirong Wang906ac472012-07-09 12:54:44 -07004756 struct wcd9xxx *core;
Kiran Kandic3b24402012-06-11 00:05:59 -07004757 struct snd_soc_codec *codec = w->codec;
4758 struct taiko_priv *taiko_p = snd_soc_codec_get_drvdata(codec);
Kiran Kandic3b24402012-06-11 00:05:59 -07004759 u32 ret = 0;
Kuirong Wang906ac472012-07-09 12:54:44 -07004760 struct wcd9xxx_codec_dai_data *dai;
Kiran Kandic3b24402012-06-11 00:05:59 -07004761
Kuirong Wang906ac472012-07-09 12:54:44 -07004762 core = dev_get_drvdata(codec->dev->parent);
4763
4764 pr_debug("%s: event called! codec name %s num_dai %d stream name %s\n",
4765 __func__, w->codec->name, w->codec->num_dai, w->sname);
Kiran Kandic3b24402012-06-11 00:05:59 -07004766
4767 /* Execute the callback only if interface type is slimbus */
4768 if (taiko_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS)
4769 return 0;
4770
Kuirong Wang906ac472012-07-09 12:54:44 -07004771 pr_debug("%s(): w->name %s event %d w->shift %d\n",
4772 __func__, w->name, event, w->shift);
Kiran Kandic3b24402012-06-11 00:05:59 -07004773
Kuirong Wang906ac472012-07-09 12:54:44 -07004774 dai = &taiko_p->dai[w->shift];
Kiran Kandic3b24402012-06-11 00:05:59 -07004775 switch (event) {
4776 case SND_SOC_DAPM_POST_PMU:
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08004777 (void) taiko_codec_enable_slim_chmask(dai, true);
Kuirong Wang906ac472012-07-09 12:54:44 -07004778 ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
4779 dai->rate, dai->bit_width,
4780 &dai->grph);
Kiran Kandic3b24402012-06-11 00:05:59 -07004781 break;
4782 case SND_SOC_DAPM_POST_PMD:
Kuirong Wang906ac472012-07-09 12:54:44 -07004783 ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list,
4784 dai->grph);
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08004785 ret = taiko_codec_enable_slim_chmask(dai, false);
4786 if (ret < 0) {
4787 ret = wcd9xxx_disconnect_port(core,
4788 &dai->wcd9xxx_ch_list,
4789 dai->grph);
4790 pr_debug("%s: Disconnect RX port, ret = %d\n",
4791 __func__, ret);
4792 }
Kuirong Wang906ac472012-07-09 12:54:44 -07004793 break;
Kiran Kandic3b24402012-06-11 00:05:59 -07004794 }
4795 return ret;
4796}
4797
Kiran Kandi4c56c592012-07-25 11:04:55 -07004798static int taiko_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
4799 struct snd_kcontrol *kcontrol, int event)
4800{
4801 struct snd_soc_codec *codec = w->codec;
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08004802 struct taiko_priv *taiko_p = snd_soc_codec_get_drvdata(codec);
Kiran Kandi4c56c592012-07-25 11:04:55 -07004803
4804 pr_debug("%s %s %d\n", __func__, w->name, event);
4805
4806 switch (event) {
Kiran Kandi4c56c592012-07-25 11:04:55 -07004807 case SND_SOC_DAPM_POST_PMU:
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08004808 wcd9xxx_clsh_fsm(codec, &taiko_p->clsh_d,
4809 WCD9XXX_CLSH_STATE_EAR,
4810 WCD9XXX_CLSH_REQ_ENABLE,
4811 WCD9XXX_CLSH_EVENT_POST_PA);
Kiran Kandi4c56c592012-07-25 11:04:55 -07004812
4813 usleep_range(5000, 5000);
4814 break;
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08004815 case SND_SOC_DAPM_POST_PMD:
4816 wcd9xxx_clsh_fsm(codec, &taiko_p->clsh_d,
4817 WCD9XXX_CLSH_STATE_EAR,
4818 WCD9XXX_CLSH_REQ_DISABLE,
4819 WCD9XXX_CLSH_EVENT_POST_PA);
4820 usleep_range(5000, 5000);
4821 }
4822 return 0;
4823}
4824
4825static int taiko_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
4826 struct snd_kcontrol *kcontrol, int event)
4827{
4828 struct snd_soc_codec *codec = w->codec;
4829 struct taiko_priv *taiko_p = snd_soc_codec_get_drvdata(codec);
4830
4831 pr_debug("%s %s %d\n", __func__, w->name, event);
4832
4833 switch (event) {
4834 case SND_SOC_DAPM_PRE_PMU:
4835 wcd9xxx_clsh_fsm(codec, &taiko_p->clsh_d,
4836 WCD9XXX_CLSH_STATE_EAR,
4837 WCD9XXX_CLSH_REQ_ENABLE,
4838 WCD9XXX_CLSH_EVENT_PRE_DAC);
4839 break;
4840 }
4841
4842 return 0;
4843}
4844
4845static int taiko_codec_dsm_mux_event(struct snd_soc_dapm_widget *w,
4846 struct snd_kcontrol *kcontrol, int event)
4847{
4848 struct snd_soc_codec *codec = w->codec;
4849 u8 reg_val, zoh_mux_val = 0x00;
4850
4851 pr_debug("%s: event = %d\n", __func__, event);
4852
4853 switch (event) {
4854 case SND_SOC_DAPM_POST_PMU:
4855 reg_val = snd_soc_read(codec, TAIKO_A_CDC_CONN_CLSH_CTL);
4856
4857 if ((reg_val & 0x30) == 0x10)
4858 zoh_mux_val = 0x04;
4859 else if ((reg_val & 0x30) == 0x20)
4860 zoh_mux_val = 0x08;
4861
4862 if (zoh_mux_val != 0x00)
4863 snd_soc_update_bits(codec,
4864 TAIKO_A_CDC_CONN_CLSH_CTL,
4865 0x0C, zoh_mux_val);
4866 break;
4867
4868 case SND_SOC_DAPM_POST_PMD:
4869 snd_soc_update_bits(codec, TAIKO_A_CDC_CONN_CLSH_CTL,
4870 0x0C, 0x00);
4871 break;
Kiran Kandi4c56c592012-07-25 11:04:55 -07004872 }
4873 return 0;
4874}
4875
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08004876static int taiko_codec_enable_anc_ear(struct snd_soc_dapm_widget *w,
4877 struct snd_kcontrol *kcontrol, int event)
4878{
4879 struct snd_soc_codec *codec = w->codec;
4880 int ret = 0;
4881
4882 switch (event) {
4883 case SND_SOC_DAPM_PRE_PMU:
4884 ret = taiko_codec_enable_anc(w, kcontrol, event);
4885 msleep(50);
4886 snd_soc_update_bits(codec, TAIKO_A_RX_EAR_EN, 0x10, 0x10);
4887 break;
4888 case SND_SOC_DAPM_POST_PMU:
4889 ret = taiko_codec_enable_ear_pa(w, kcontrol, event);
4890 break;
4891 case SND_SOC_DAPM_PRE_PMD:
4892 snd_soc_update_bits(codec, TAIKO_A_RX_EAR_EN, 0x10, 0x00);
4893 msleep(40);
4894 ret |= taiko_codec_enable_anc(w, kcontrol, event);
4895 break;
4896 case SND_SOC_DAPM_POST_PMD:
4897 ret = taiko_codec_enable_ear_pa(w, kcontrol, event);
4898 break;
4899 }
4900 return ret;
4901}
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08004902
Kiran Kandic3b24402012-06-11 00:05:59 -07004903/* Todo: Have seperate dapm widgets for I2S and Slimbus.
4904 * Might Need to have callbacks registered only for slimbus
4905 */
4906static const struct snd_soc_dapm_widget taiko_dapm_widgets[] = {
4907 /*RX stuff */
4908 SND_SOC_DAPM_OUTPUT("EAR"),
4909
Kiran Kandi4c56c592012-07-25 11:04:55 -07004910 SND_SOC_DAPM_PGA_E("EAR PA", TAIKO_A_RX_EAR_EN, 4, 0, NULL, 0,
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08004911 taiko_codec_enable_ear_pa, SND_SOC_DAPM_POST_PMU |
4912 SND_SOC_DAPM_POST_PMD),
Kiran Kandic3b24402012-06-11 00:05:59 -07004913
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08004914 SND_SOC_DAPM_MIXER_E("DAC1", TAIKO_A_RX_EAR_EN, 6, 0, dac1_switch,
4915 ARRAY_SIZE(dac1_switch), taiko_codec_ear_dac_event,
4916 SND_SOC_DAPM_PRE_PMU),
Kiran Kandic3b24402012-06-11 00:05:59 -07004917
Kuirong Wang906ac472012-07-09 12:54:44 -07004918 SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM,
4919 AIF1_PB, 0, taiko_codec_enable_slimrx,
Kiran Kandic3b24402012-06-11 00:05:59 -07004920 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Kuirong Wang906ac472012-07-09 12:54:44 -07004921 SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM,
4922 AIF2_PB, 0, taiko_codec_enable_slimrx,
Kiran Kandic3b24402012-06-11 00:05:59 -07004923 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Kuirong Wang906ac472012-07-09 12:54:44 -07004924 SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM,
4925 AIF3_PB, 0, taiko_codec_enable_slimrx,
Kiran Kandic3b24402012-06-11 00:05:59 -07004926 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4927
Kuirong Wang906ac472012-07-09 12:54:44 -07004928 SND_SOC_DAPM_MUX("SLIM RX1 MUX", SND_SOC_NOPM, TAIKO_RX1, 0,
4929 &slim_rx_mux[TAIKO_RX1]),
4930 SND_SOC_DAPM_MUX("SLIM RX2 MUX", SND_SOC_NOPM, TAIKO_RX2, 0,
4931 &slim_rx_mux[TAIKO_RX2]),
4932 SND_SOC_DAPM_MUX("SLIM RX3 MUX", SND_SOC_NOPM, TAIKO_RX3, 0,
4933 &slim_rx_mux[TAIKO_RX3]),
4934 SND_SOC_DAPM_MUX("SLIM RX4 MUX", SND_SOC_NOPM, TAIKO_RX4, 0,
4935 &slim_rx_mux[TAIKO_RX4]),
4936 SND_SOC_DAPM_MUX("SLIM RX5 MUX", SND_SOC_NOPM, TAIKO_RX5, 0,
4937 &slim_rx_mux[TAIKO_RX5]),
4938 SND_SOC_DAPM_MUX("SLIM RX6 MUX", SND_SOC_NOPM, TAIKO_RX6, 0,
4939 &slim_rx_mux[TAIKO_RX6]),
4940 SND_SOC_DAPM_MUX("SLIM RX7 MUX", SND_SOC_NOPM, TAIKO_RX7, 0,
4941 &slim_rx_mux[TAIKO_RX7]),
Kiran Kandic3b24402012-06-11 00:05:59 -07004942
Kuirong Wang906ac472012-07-09 12:54:44 -07004943 SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
4944 SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
4945 SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
4946 SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
4947 SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
4948 SND_SOC_DAPM_MIXER("SLIM RX6", SND_SOC_NOPM, 0, 0, NULL, 0),
4949 SND_SOC_DAPM_MIXER("SLIM RX7", SND_SOC_NOPM, 0, 0, NULL, 0),
Kiran Kandic3b24402012-06-11 00:05:59 -07004950
4951 /* Headphone */
4952 SND_SOC_DAPM_OUTPUT("HEADPHONE"),
4953 SND_SOC_DAPM_PGA_E("HPHL", TAIKO_A_RX_HPH_CNP_EN, 5, 0, NULL, 0,
4954 taiko_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
Kiran Kandi4c56c592012-07-25 11:04:55 -07004955 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08004956 SND_SOC_DAPM_MIXER_E("HPHL DAC", TAIKO_A_RX_HPH_L_DAC_CTL, 7, 0,
4957 hphl_switch, ARRAY_SIZE(hphl_switch), taiko_hphl_dac_event,
4958 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Kiran Kandic3b24402012-06-11 00:05:59 -07004959
4960 SND_SOC_DAPM_PGA_E("HPHR", TAIKO_A_RX_HPH_CNP_EN, 4, 0, NULL, 0,
4961 taiko_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
Kiran Kandi4c56c592012-07-25 11:04:55 -07004962 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Kiran Kandic3b24402012-06-11 00:05:59 -07004963
4964 SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TAIKO_A_RX_HPH_R_DAC_CTL, 7, 0,
4965 taiko_hphr_dac_event,
4966 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4967
4968 /* Speaker */
4969 SND_SOC_DAPM_OUTPUT("LINEOUT1"),
4970 SND_SOC_DAPM_OUTPUT("LINEOUT2"),
4971 SND_SOC_DAPM_OUTPUT("LINEOUT3"),
4972 SND_SOC_DAPM_OUTPUT("LINEOUT4"),
Joonwoo Park7680b9f2012-07-13 11:36:48 -07004973 SND_SOC_DAPM_OUTPUT("SPK_OUT"),
Kiran Kandic3b24402012-06-11 00:05:59 -07004974
4975 SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TAIKO_A_RX_LINE_CNP_EN, 0, 0, NULL,
4976 0, taiko_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4977 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4978 SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TAIKO_A_RX_LINE_CNP_EN, 1, 0, NULL,
4979 0, taiko_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4980 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4981 SND_SOC_DAPM_PGA_E("LINEOUT3 PA", TAIKO_A_RX_LINE_CNP_EN, 2, 0, NULL,
4982 0, taiko_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4983 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
4984 SND_SOC_DAPM_PGA_E("LINEOUT4 PA", TAIKO_A_RX_LINE_CNP_EN, 3, 0, NULL,
4985 0, taiko_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU |
4986 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Joonwoo Park125cd4e2012-12-11 15:16:11 -08004987 SND_SOC_DAPM_PGA_E("SPK PA", SND_SOC_NOPM, 0, 0 , NULL,
4988 0, taiko_codec_enable_spk_pa,
4989 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Kiran Kandic3b24402012-06-11 00:05:59 -07004990
4991 SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TAIKO_A_RX_LINE_1_DAC_CTL, 7, 0
4992 , taiko_lineout_dac_event,
4993 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4994 SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TAIKO_A_RX_LINE_2_DAC_CTL, 7, 0
4995 , taiko_lineout_dac_event,
4996 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
4997 SND_SOC_DAPM_DAC_E("LINEOUT3 DAC", NULL, TAIKO_A_RX_LINE_3_DAC_CTL, 7, 0
4998 , taiko_lineout_dac_event,
4999 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5000 SND_SOC_DAPM_SWITCH("LINEOUT3 DAC GROUND", SND_SOC_NOPM, 0, 0,
5001 &lineout3_ground_switch),
5002 SND_SOC_DAPM_DAC_E("LINEOUT4 DAC", NULL, TAIKO_A_RX_LINE_4_DAC_CTL, 7, 0
5003 , taiko_lineout_dac_event,
5004 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5005 SND_SOC_DAPM_SWITCH("LINEOUT4 DAC GROUND", SND_SOC_NOPM, 0, 0,
5006 &lineout4_ground_switch),
5007
Joonwoo Park7680b9f2012-07-13 11:36:48 -07005008 SND_SOC_DAPM_DAC_E("SPK DAC", NULL, SND_SOC_NOPM, 0, 0,
5009 taiko_spk_dac_event,
5010 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5011
Joonwoo Park125cd4e2012-12-11 15:16:11 -08005012 SND_SOC_DAPM_SUPPLY("VDD_SPKDRV", SND_SOC_NOPM, 0, 0,
5013 taiko_codec_enable_vdd_spkr,
5014 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
5015
Kiran Kandid2b46332012-10-05 12:04:00 -07005016 SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5017 SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5018 SND_SOC_DAPM_MIXER("RX7 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
5019
Kiran Kandic3b24402012-06-11 00:05:59 -07005020 SND_SOC_DAPM_MIXER_E("RX1 MIX2", TAIKO_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL,
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005021 0, taiko_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
Kiran Kandic3b24402012-06-11 00:05:59 -07005022 SND_SOC_DAPM_POST_PMU),
5023 SND_SOC_DAPM_MIXER_E("RX2 MIX2", TAIKO_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL,
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005024 0, taiko_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
Kiran Kandic3b24402012-06-11 00:05:59 -07005025 SND_SOC_DAPM_POST_PMU),
Kiran Kandid2b46332012-10-05 12:04:00 -07005026 SND_SOC_DAPM_MIXER_E("RX3 MIX1", TAIKO_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005027 0, taiko_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
Kiran Kandic3b24402012-06-11 00:05:59 -07005028 SND_SOC_DAPM_POST_PMU),
5029 SND_SOC_DAPM_MIXER_E("RX4 MIX1", TAIKO_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL,
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005030 0, taiko_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
Kiran Kandic3b24402012-06-11 00:05:59 -07005031 SND_SOC_DAPM_POST_PMU),
5032 SND_SOC_DAPM_MIXER_E("RX5 MIX1", TAIKO_A_CDC_CLK_RX_B1_CTL, 4, 0, NULL,
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005033 0, taiko_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
Kiran Kandic3b24402012-06-11 00:05:59 -07005034 SND_SOC_DAPM_POST_PMU),
5035 SND_SOC_DAPM_MIXER_E("RX6 MIX1", TAIKO_A_CDC_CLK_RX_B1_CTL, 5, 0, NULL,
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005036 0, taiko_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
Kiran Kandic3b24402012-06-11 00:05:59 -07005037 SND_SOC_DAPM_POST_PMU),
Kiran Kandid2b46332012-10-05 12:04:00 -07005038 SND_SOC_DAPM_MIXER_E("RX7 MIX2", TAIKO_A_CDC_CLK_RX_B1_CTL, 6, 0, NULL,
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005039 0, taiko_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
Kiran Kandic3b24402012-06-11 00:05:59 -07005040 SND_SOC_DAPM_POST_PMU),
5041
Kiran Kandic3b24402012-06-11 00:05:59 -07005042
5043 SND_SOC_DAPM_MIXER("RX1 CHAIN", TAIKO_A_CDC_RX1_B6_CTL, 5, 0, NULL, 0),
5044 SND_SOC_DAPM_MIXER("RX2 CHAIN", TAIKO_A_CDC_RX2_B6_CTL, 5, 0, NULL, 0),
5045
5046 SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5047 &rx_mix1_inp1_mux),
5048 SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5049 &rx_mix1_inp2_mux),
5050 SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0,
5051 &rx_mix1_inp3_mux),
5052 SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5053 &rx2_mix1_inp1_mux),
5054 SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5055 &rx2_mix1_inp2_mux),
5056 SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5057 &rx3_mix1_inp1_mux),
5058 SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5059 &rx3_mix1_inp2_mux),
5060 SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5061 &rx4_mix1_inp1_mux),
5062 SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5063 &rx4_mix1_inp2_mux),
5064 SND_SOC_DAPM_MUX("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5065 &rx5_mix1_inp1_mux),
5066 SND_SOC_DAPM_MUX("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5067 &rx5_mix1_inp2_mux),
5068 SND_SOC_DAPM_MUX("RX6 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5069 &rx6_mix1_inp1_mux),
5070 SND_SOC_DAPM_MUX("RX6 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5071 &rx6_mix1_inp2_mux),
5072 SND_SOC_DAPM_MUX("RX7 MIX1 INP1", SND_SOC_NOPM, 0, 0,
5073 &rx7_mix1_inp1_mux),
5074 SND_SOC_DAPM_MUX("RX7 MIX1 INP2", SND_SOC_NOPM, 0, 0,
5075 &rx7_mix1_inp2_mux),
5076 SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0,
5077 &rx1_mix2_inp1_mux),
5078 SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0,
5079 &rx1_mix2_inp2_mux),
5080 SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0,
5081 &rx2_mix2_inp1_mux),
5082 SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0,
5083 &rx2_mix2_inp2_mux),
5084 SND_SOC_DAPM_MUX("RX7 MIX2 INP1", SND_SOC_NOPM, 0, 0,
5085 &rx7_mix2_inp1_mux),
5086 SND_SOC_DAPM_MUX("RX7 MIX2 INP2", SND_SOC_NOPM, 0, 0,
5087 &rx7_mix2_inp2_mux),
5088
Tanya Finkeldaaa6d12012-10-25 11:22:48 +02005089 SND_SOC_DAPM_MUX("RDAC5 MUX", SND_SOC_NOPM, 0, 0,
5090 &rx_dac5_mux),
5091 SND_SOC_DAPM_MUX("RDAC7 MUX", SND_SOC_NOPM, 0, 0,
5092 &rx_dac7_mux),
5093
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08005094 SND_SOC_DAPM_MUX_E("CLASS_H_DSM MUX", SND_SOC_NOPM, 0, 0,
5095 &class_h_dsm_mux, taiko_codec_dsm_mux_event,
5096 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Kiran Kandi4c56c592012-07-25 11:04:55 -07005097
Kiran Kandic3b24402012-06-11 00:05:59 -07005098 SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
5099 taiko_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
5100 SND_SOC_DAPM_POST_PMD),
5101
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08005102 SND_SOC_DAPM_SUPPLY("CDC_I2S_RX_CONN", WCD9XXX_A_CDC_CLK_OTHR_CTL, 5, 0,
Joonwoo Park559a5bf2013-02-15 14:46:36 -08005103 NULL, 0),
5104
Kiran Kandic3b24402012-06-11 00:05:59 -07005105 /* TX */
5106
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08005107 SND_SOC_DAPM_SUPPLY("CDC_CONN", WCD9XXX_A_CDC_CLK_OTHR_CTL, 2, 0, NULL,
Kiran Kandic3b24402012-06-11 00:05:59 -07005108 0),
5109
5110 SND_SOC_DAPM_SUPPLY("LDO_H", TAIKO_A_LDO_H_MODE_1, 7, 0,
5111 taiko_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU),
5112
Joonwoo Parkc7731432012-10-17 12:41:44 -07005113 SND_SOC_DAPM_SUPPLY("COMP0_CLK", SND_SOC_NOPM, 0, 0,
Kiran Kandic3b24402012-06-11 00:05:59 -07005114 taiko_config_compander, SND_SOC_DAPM_PRE_PMU |
Bhalchandra Gajareed090e62013-03-29 16:11:49 -07005115 SND_SOC_DAPM_PRE_PMD),
Joonwoo Parkc7731432012-10-17 12:41:44 -07005116 SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 1, 0,
5117 taiko_config_compander, SND_SOC_DAPM_PRE_PMU |
Bhalchandra Gajareed090e62013-03-29 16:11:49 -07005118 SND_SOC_DAPM_PRE_PMD),
Joonwoo Parkc7731432012-10-17 12:41:44 -07005119 SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 2, 0,
Kiran Kandic3b24402012-06-11 00:05:59 -07005120 taiko_config_compander, SND_SOC_DAPM_PRE_PMU |
Bhalchandra Gajareed090e62013-03-29 16:11:49 -07005121 SND_SOC_DAPM_PRE_PMD),
Kiran Kandic3b24402012-06-11 00:05:59 -07005122
5123
5124 SND_SOC_DAPM_INPUT("AMIC1"),
Joonwoo Park3699ca32013-02-08 12:06:15 -08005125 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", SND_SOC_NOPM, 7, 0,
5126 taiko_codec_enable_micbias,
5127 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5128 SND_SOC_DAPM_POST_PMD),
5129 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", SND_SOC_NOPM, 7, 0,
5130 taiko_codec_enable_micbias,
5131 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5132 SND_SOC_DAPM_POST_PMD),
5133 SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", SND_SOC_NOPM, 7, 0,
5134 taiko_codec_enable_micbias,
5135 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5136 SND_SOC_DAPM_POST_PMD),
Kiran Kandic3b24402012-06-11 00:05:59 -07005137
5138 SND_SOC_DAPM_INPUT("AMIC3"),
Kiran Kandic3b24402012-06-11 00:05:59 -07005139
5140 SND_SOC_DAPM_INPUT("AMIC4"),
Kiran Kandic3b24402012-06-11 00:05:59 -07005141
5142 SND_SOC_DAPM_INPUT("AMIC5"),
Kiran Kandic3b24402012-06-11 00:05:59 -07005143
5144 SND_SOC_DAPM_INPUT("AMIC6"),
Kiran Kandic3b24402012-06-11 00:05:59 -07005145
5146 SND_SOC_DAPM_MUX_E("DEC1 MUX", TAIKO_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0, 0,
5147 &dec1_mux, taiko_codec_enable_dec,
5148 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5149 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
5150
5151 SND_SOC_DAPM_MUX_E("DEC2 MUX", TAIKO_A_CDC_CLK_TX_CLK_EN_B1_CTL, 1, 0,
5152 &dec2_mux, taiko_codec_enable_dec,
5153 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5154 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
5155
5156 SND_SOC_DAPM_MUX_E("DEC3 MUX", TAIKO_A_CDC_CLK_TX_CLK_EN_B1_CTL, 2, 0,
5157 &dec3_mux, taiko_codec_enable_dec,
5158 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5159 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
5160
5161 SND_SOC_DAPM_MUX_E("DEC4 MUX", TAIKO_A_CDC_CLK_TX_CLK_EN_B1_CTL, 3, 0,
5162 &dec4_mux, taiko_codec_enable_dec,
5163 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5164 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
5165
5166 SND_SOC_DAPM_MUX_E("DEC5 MUX", TAIKO_A_CDC_CLK_TX_CLK_EN_B1_CTL, 4, 0,
5167 &dec5_mux, taiko_codec_enable_dec,
5168 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5169 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
5170
5171 SND_SOC_DAPM_MUX_E("DEC6 MUX", TAIKO_A_CDC_CLK_TX_CLK_EN_B1_CTL, 5, 0,
5172 &dec6_mux, taiko_codec_enable_dec,
5173 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5174 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
5175
5176 SND_SOC_DAPM_MUX_E("DEC7 MUX", TAIKO_A_CDC_CLK_TX_CLK_EN_B1_CTL, 6, 0,
5177 &dec7_mux, taiko_codec_enable_dec,
5178 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5179 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
5180
5181 SND_SOC_DAPM_MUX_E("DEC8 MUX", TAIKO_A_CDC_CLK_TX_CLK_EN_B1_CTL, 7, 0,
5182 &dec8_mux, taiko_codec_enable_dec,
5183 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5184 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
5185
5186 SND_SOC_DAPM_MUX_E("DEC9 MUX", TAIKO_A_CDC_CLK_TX_CLK_EN_B2_CTL, 0, 0,
5187 &dec9_mux, taiko_codec_enable_dec,
5188 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5189 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
5190
5191 SND_SOC_DAPM_MUX_E("DEC10 MUX", TAIKO_A_CDC_CLK_TX_CLK_EN_B2_CTL, 1, 0,
5192 &dec10_mux, taiko_codec_enable_dec,
5193 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5194 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
5195
5196 SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux),
5197 SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux),
5198
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08005199 SND_SOC_DAPM_OUTPUT("ANC HEADPHONE"),
5200 SND_SOC_DAPM_PGA_E("ANC HPHL", SND_SOC_NOPM, 5, 0, NULL, 0,
5201 taiko_codec_enable_anc_hph,
5202 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD |
5203 SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_POST_PMU),
5204 SND_SOC_DAPM_PGA_E("ANC HPHR", SND_SOC_NOPM, 4, 0, NULL, 0,
5205 taiko_codec_enable_anc_hph, SND_SOC_DAPM_PRE_PMU |
5206 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
5207 SND_SOC_DAPM_POST_PMU),
5208 SND_SOC_DAPM_OUTPUT("ANC EAR"),
5209 SND_SOC_DAPM_PGA_E("ANC EAR PA", SND_SOC_NOPM, 0, 0, NULL, 0,
5210 taiko_codec_enable_anc_ear,
5211 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD |
5212 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Kiran Kandic3b24402012-06-11 00:05:59 -07005213 SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux),
5214
5215 SND_SOC_DAPM_INPUT("AMIC2"),
Joonwoo Park3699ca32013-02-08 12:06:15 -08005216 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", SND_SOC_NOPM, 7, 0,
5217 taiko_codec_enable_micbias,
5218 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5219 SND_SOC_DAPM_POST_PMD),
5220 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", SND_SOC_NOPM, 7, 0,
5221 taiko_codec_enable_micbias,
5222 SND_SOC_DAPM_PRE_PMU |
5223 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5224 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", SND_SOC_NOPM, 7, 0,
5225 taiko_codec_enable_micbias,
5226 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5227 SND_SOC_DAPM_POST_PMD),
5228 SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", SND_SOC_NOPM, 7, 0,
5229 taiko_codec_enable_micbias,
5230 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5231 SND_SOC_DAPM_POST_PMD),
5232 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", SND_SOC_NOPM, 7, 0,
5233 taiko_codec_enable_micbias,
5234 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5235 SND_SOC_DAPM_POST_PMD),
5236 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", SND_SOC_NOPM, 7, 0,
5237 taiko_codec_enable_micbias,
5238 SND_SOC_DAPM_PRE_PMU |
5239 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5240 SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", SND_SOC_NOPM, 7, 0,
5241 taiko_codec_enable_micbias,
5242 SND_SOC_DAPM_PRE_PMU |
5243 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
5244 SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", SND_SOC_NOPM, 7,
5245 0, taiko_codec_enable_micbias,
5246 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
5247 SND_SOC_DAPM_POST_PMD),
Kiran Kandic3b24402012-06-11 00:05:59 -07005248
Kuirong Wang906ac472012-07-09 12:54:44 -07005249 SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM,
5250 AIF1_CAP, 0, taiko_codec_enable_slimtx,
5251 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Kiran Kandic3b24402012-06-11 00:05:59 -07005252
Kuirong Wang906ac472012-07-09 12:54:44 -07005253 SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM,
5254 AIF2_CAP, 0, taiko_codec_enable_slimtx,
5255 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Kiran Kandic3b24402012-06-11 00:05:59 -07005256
Kuirong Wang906ac472012-07-09 12:54:44 -07005257 SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM,
5258 AIF3_CAP, 0, taiko_codec_enable_slimtx,
5259 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Kiran Kandic3b24402012-06-11 00:05:59 -07005260
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05005261 SND_SOC_DAPM_AIF_OUT_E("AIF4 VI", "VIfeed", 0, SND_SOC_NOPM,
5262 AIF4_VIFEED, 0, taiko_codec_enable_slimvi_feedback,
5263 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Joonwoo Park1d05bb92013-03-07 16:55:06 -08005264 SND_SOC_DAPM_AIF_OUT_E("AIF4 MAD", "AIF4 MAD TX", 0,
Joonwoo Park9ead0e92013-03-18 11:33:33 -07005265 SND_SOC_NOPM, 0, 0,
Joonwoo Park1d05bb92013-03-07 16:55:06 -08005266 taiko_codec_enable_mad, SND_SOC_DAPM_PRE_PMU),
Joonwoo Park9ead0e92013-03-18 11:33:33 -07005267 SND_SOC_DAPM_SWITCH("MADONOFF", SND_SOC_NOPM, 0, 0,
5268 &aif4_mad_switch),
Joonwoo Park1d05bb92013-03-07 16:55:06 -08005269 SND_SOC_DAPM_INPUT("MADINPUT"),
Gopikrishnaiah Anandana2627572013-02-26 13:30:50 -05005270
Kuirong Wang906ac472012-07-09 12:54:44 -07005271 SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0,
5272 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
Kiran Kandic3b24402012-06-11 00:05:59 -07005273
Kuirong Wang906ac472012-07-09 12:54:44 -07005274 SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0,
5275 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
Kiran Kandic3b24402012-06-11 00:05:59 -07005276
Kuirong Wang906ac472012-07-09 12:54:44 -07005277 SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0,
5278 aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)),
Kiran Kandic3b24402012-06-11 00:05:59 -07005279
Kuirong Wang906ac472012-07-09 12:54:44 -07005280 SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, TAIKO_TX1, 0,
5281 &sb_tx1_mux),
5282 SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, TAIKO_TX2, 0,
5283 &sb_tx2_mux),
5284 SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, TAIKO_TX3, 0,
5285 &sb_tx3_mux),
5286 SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, TAIKO_TX4, 0,
5287 &sb_tx4_mux),
5288 SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, TAIKO_TX5, 0,
5289 &sb_tx5_mux),
5290 SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, TAIKO_TX6, 0,
5291 &sb_tx6_mux),
5292 SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, TAIKO_TX7, 0,
5293 &sb_tx7_mux),
5294 SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, TAIKO_TX8, 0,
5295 &sb_tx8_mux),
5296 SND_SOC_DAPM_MUX("SLIM TX9 MUX", SND_SOC_NOPM, TAIKO_TX9, 0,
5297 &sb_tx9_mux),
5298 SND_SOC_DAPM_MUX("SLIM TX10 MUX", SND_SOC_NOPM, TAIKO_TX10, 0,
5299 &sb_tx10_mux),
Kiran Kandic3b24402012-06-11 00:05:59 -07005300
5301 /* Digital Mic Inputs */
5302 SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
5303 taiko_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5304 SND_SOC_DAPM_POST_PMD),
5305
5306 SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
5307 taiko_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5308 SND_SOC_DAPM_POST_PMD),
5309
5310 SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0,
5311 taiko_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5312 SND_SOC_DAPM_POST_PMD),
5313
5314 SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0,
5315 taiko_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5316 SND_SOC_DAPM_POST_PMD),
5317
5318 SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0,
5319 taiko_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5320 SND_SOC_DAPM_POST_PMD),
5321 SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 0,
5322 taiko_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
5323 SND_SOC_DAPM_POST_PMD),
5324
5325 /* Sidetone */
5326 SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux),
5327 SND_SOC_DAPM_PGA("IIR1", TAIKO_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0),
5328
Fred Oh456fcb52013-02-28 19:08:15 -08005329 SND_SOC_DAPM_MUX("IIR2 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir2_inp1_mux),
5330 SND_SOC_DAPM_PGA("IIR2", TAIKO_A_CDC_CLK_SD_CTL, 1, 0, NULL, 0),
5331
Kiran Kandic3b24402012-06-11 00:05:59 -07005332 /* AUX PGA */
5333 SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TAIKO_A_RX_AUX_SW_CTL, 7, 0,
5334 taiko_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
5335 SND_SOC_DAPM_POST_PMD),
5336
5337 SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TAIKO_A_RX_AUX_SW_CTL, 6, 0,
5338 taiko_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU |
5339 SND_SOC_DAPM_POST_PMD),
5340
5341 /* Lineout, ear and HPH PA Mixers */
5342
5343 SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0,
5344 ear_pa_mix, ARRAY_SIZE(ear_pa_mix)),
5345
5346 SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0,
5347 hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)),
5348
5349 SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0,
5350 hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)),
5351
5352 SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0,
5353 lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)),
5354
5355 SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0,
5356 lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)),
5357
5358 SND_SOC_DAPM_MIXER("LINEOUT3_PA_MIXER", SND_SOC_NOPM, 0, 0,
5359 lineout3_pa_mix, ARRAY_SIZE(lineout3_pa_mix)),
5360
5361 SND_SOC_DAPM_MIXER("LINEOUT4_PA_MIXER", SND_SOC_NOPM, 0, 0,
5362 lineout4_pa_mix, ARRAY_SIZE(lineout4_pa_mix)),
Kiran Kandic3b24402012-06-11 00:05:59 -07005363};
5364
Kiran Kandic3b24402012-06-11 00:05:59 -07005365static irqreturn_t taiko_slimbus_irq(int irq, void *data)
5366{
5367 struct taiko_priv *priv = data;
5368 struct snd_soc_codec *codec = priv->codec;
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08005369 unsigned long status = 0;
5370 int i, j, port_id, k;
5371 u32 bit;
Kiran Kandic3b24402012-06-11 00:05:59 -07005372 u8 val;
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08005373 bool tx, cleared;
Kiran Kandic3b24402012-06-11 00:05:59 -07005374
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08005375 for (i = TAIKO_SLIM_PGD_PORT_INT_STATUS_RX_0, j = 0;
5376 i <= TAIKO_SLIM_PGD_PORT_INT_STATUS_TX_1; i++, j++) {
5377 val = wcd9xxx_interface_reg_read(codec->control_data, i);
5378 status |= ((u32)val << (8 * j));
5379 }
5380
5381 for_each_set_bit(j, &status, 32) {
5382 tx = (j >= 16 ? true : false);
5383 port_id = (tx ? j - 16 : j);
5384 val = wcd9xxx_interface_reg_read(codec->control_data,
5385 TAIKO_SLIM_PGD_PORT_INT_RX_SOURCE0 + j);
5386 if (val & TAIKO_SLIM_IRQ_OVERFLOW)
5387 pr_err_ratelimited(
5388 "%s: overflow error on %s port %d, value %x\n",
5389 __func__, (tx ? "TX" : "RX"), port_id, val);
5390 if (val & TAIKO_SLIM_IRQ_UNDERFLOW)
5391 pr_err_ratelimited(
5392 "%s: underflow error on %s port %d, value %x\n",
5393 __func__, (tx ? "TX" : "RX"), port_id, val);
5394 if (val & TAIKO_SLIM_IRQ_PORT_CLOSED) {
5395 /*
5396 * INT SOURCE register starts from RX to TX
5397 * but port number in the ch_mask is in opposite way
5398 */
5399 bit = (tx ? j - 16 : j + 16);
5400 pr_debug("%s: %s port %d closed value %x, bit %u\n",
5401 __func__, (tx ? "TX" : "RX"), port_id, val,
5402 bit);
5403 for (k = 0, cleared = false; k < NUM_CODEC_DAIS; k++) {
5404 pr_debug("%s: priv->dai[%d].ch_mask = 0x%lx\n",
5405 __func__, k, priv->dai[k].ch_mask);
5406 if (test_and_clear_bit(bit,
5407 &priv->dai[k].ch_mask)) {
5408 cleared = true;
5409 if (!priv->dai[k].ch_mask)
5410 wake_up(&priv->dai[k].dai_wait);
5411 /*
5412 * There are cases when multiple DAIs
5413 * might be using the same slimbus
5414 * channel. Hence don't break here.
5415 */
5416 }
5417 }
5418 WARN(!cleared,
5419 "Couldn't find slimbus %s port %d for closing\n",
5420 (tx ? "TX" : "RX"), port_id);
Kiran Kandic3b24402012-06-11 00:05:59 -07005421 }
5422 wcd9xxx_interface_reg_write(codec->control_data,
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08005423 TAIKO_SLIM_PGD_PORT_INT_CLR_RX_0 +
5424 (j / 8),
5425 1 << (j % 8));
Joonwoo Parka8890262012-10-15 12:04:27 -07005426 }
Joonwoo Park9bbb4d12012-11-09 19:58:11 -08005427
Kiran Kandic3b24402012-06-11 00:05:59 -07005428 return IRQ_HANDLED;
5429}
5430
5431static int taiko_handle_pdata(struct taiko_priv *taiko)
5432{
5433 struct snd_soc_codec *codec = taiko->codec;
Joonwoo Parka8890262012-10-15 12:04:27 -07005434 struct wcd9xxx_pdata *pdata = taiko->resmgr.pdata;
Kiran Kandic3b24402012-06-11 00:05:59 -07005435 int k1, k2, k3, rc = 0;
Kiran Kandi725f8492012-08-06 13:45:16 -07005436 u8 leg_mode, txfe_bypass, txfe_buff, flag;
Kiran Kandic3b24402012-06-11 00:05:59 -07005437 u8 i = 0, j = 0;
5438 u8 val_txfe = 0, value = 0;
Damir Didjusto1a353ce2013-04-02 11:45:47 -07005439 u8 dmic_sample_rate_value = 0;
5440 u8 dmic_b1_ctl_value = 0, dmic_b2_ctl_value = 0;
5441 u8 anc_ctl_value = 0;
Kiran Kandic3b24402012-06-11 00:05:59 -07005442
5443 if (!pdata) {
Kiran Kandi725f8492012-08-06 13:45:16 -07005444 pr_err("%s: NULL pdata\n", __func__);
Kiran Kandic3b24402012-06-11 00:05:59 -07005445 rc = -ENODEV;
5446 goto done;
5447 }
5448
Kiran Kandi725f8492012-08-06 13:45:16 -07005449 leg_mode = pdata->amic_settings.legacy_mode;
5450 txfe_bypass = pdata->amic_settings.txfe_enable;
5451 txfe_buff = pdata->amic_settings.txfe_buff;
5452 flag = pdata->amic_settings.use_pdata;
5453
Kiran Kandic3b24402012-06-11 00:05:59 -07005454 /* Make sure settings are correct */
Joonwoo Parka8890262012-10-15 12:04:27 -07005455 if ((pdata->micbias.ldoh_v > WCD9XXX_LDOH_3P0_V) ||
5456 (pdata->micbias.bias1_cfilt_sel > WCD9XXX_CFILT3_SEL) ||
5457 (pdata->micbias.bias2_cfilt_sel > WCD9XXX_CFILT3_SEL) ||
5458 (pdata->micbias.bias3_cfilt_sel > WCD9XXX_CFILT3_SEL) ||
5459 (pdata->micbias.bias4_cfilt_sel > WCD9XXX_CFILT3_SEL)) {
Kiran Kandic3b24402012-06-11 00:05:59 -07005460 rc = -EINVAL;
5461 goto done;
5462 }
Kiran Kandic3b24402012-06-11 00:05:59 -07005463 /* figure out k value */
Joonwoo Parka8890262012-10-15 12:04:27 -07005464 k1 = wcd9xxx_resmgr_get_k_val(&taiko->resmgr, pdata->micbias.cfilt1_mv);
5465 k2 = wcd9xxx_resmgr_get_k_val(&taiko->resmgr, pdata->micbias.cfilt2_mv);
5466 k3 = wcd9xxx_resmgr_get_k_val(&taiko->resmgr, pdata->micbias.cfilt3_mv);
Kiran Kandic3b24402012-06-11 00:05:59 -07005467
5468 if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) {
5469 rc = -EINVAL;
5470 goto done;
5471 }
Kiran Kandic3b24402012-06-11 00:05:59 -07005472 /* Set voltage level and always use LDO */
5473 snd_soc_update_bits(codec, TAIKO_A_LDO_H_MODE_1, 0x0C,
Joonwoo Parka8890262012-10-15 12:04:27 -07005474 (pdata->micbias.ldoh_v << 2));
Kiran Kandic3b24402012-06-11 00:05:59 -07005475
Joonwoo Parka8890262012-10-15 12:04:27 -07005476 snd_soc_update_bits(codec, TAIKO_A_MICB_CFILT_1_VAL, 0xFC, (k1 << 2));
5477 snd_soc_update_bits(codec, TAIKO_A_MICB_CFILT_2_VAL, 0xFC, (k2 << 2));
5478 snd_soc_update_bits(codec, TAIKO_A_MICB_CFILT_3_VAL, 0xFC, (k3 << 2));
Kiran Kandic3b24402012-06-11 00:05:59 -07005479
5480 snd_soc_update_bits(codec, TAIKO_A_MICB_1_CTL, 0x60,
Joonwoo Parka8890262012-10-15 12:04:27 -07005481 (pdata->micbias.bias1_cfilt_sel << 5));
Kiran Kandic3b24402012-06-11 00:05:59 -07005482 snd_soc_update_bits(codec, TAIKO_A_MICB_2_CTL, 0x60,
Joonwoo Parka8890262012-10-15 12:04:27 -07005483 (pdata->micbias.bias2_cfilt_sel << 5));
Kiran Kandic3b24402012-06-11 00:05:59 -07005484 snd_soc_update_bits(codec, TAIKO_A_MICB_3_CTL, 0x60,
Joonwoo Parka8890262012-10-15 12:04:27 -07005485 (pdata->micbias.bias3_cfilt_sel << 5));
5486 snd_soc_update_bits(codec, taiko->resmgr.reg_addr->micb_4_ctl, 0x60,
Kiran Kandic3b24402012-06-11 00:05:59 -07005487 (pdata->micbias.bias4_cfilt_sel << 5));
5488
5489 for (i = 0; i < 6; j++, i += 2) {
5490 if (flag & (0x01 << i)) {
5491 value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00;
5492 val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00;
5493 val_txfe = val_txfe |
5494 ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00);
5495 snd_soc_update_bits(codec, TAIKO_A_TX_1_2_EN + j * 10,
5496 0x10, value);
5497 snd_soc_update_bits(codec,
5498 TAIKO_A_TX_1_2_TEST_EN + j * 10,
5499 0x30, val_txfe);
5500 }
5501 if (flag & (0x01 << (i + 1))) {
5502 value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00;
5503 val_txfe = (txfe_bypass &
5504 (0x01 << (i + 1))) ? 0x02 : 0x00;
5505 val_txfe |= (txfe_buff &
5506 (0x01 << (i + 1))) ? 0x01 : 0x00;
5507 snd_soc_update_bits(codec, TAIKO_A_TX_1_2_EN + j * 10,
5508 0x01, value);
5509 snd_soc_update_bits(codec,
5510 TAIKO_A_TX_1_2_TEST_EN + j * 10,
5511 0x03, val_txfe);
5512 }
5513 }
5514 if (flag & 0x40) {
5515 value = (leg_mode & 0x40) ? 0x10 : 0x00;
5516 value = value | ((txfe_bypass & 0x40) ? 0x02 : 0x00);
5517 value = value | ((txfe_buff & 0x40) ? 0x01 : 0x00);
5518 snd_soc_update_bits(codec, TAIKO_A_TX_7_MBHC_EN,
5519 0x13, value);
5520 }
5521
5522 if (pdata->ocp.use_pdata) {
5523 /* not defined in CODEC specification */
5524 if (pdata->ocp.hph_ocp_limit == 1 ||
5525 pdata->ocp.hph_ocp_limit == 5) {
5526 rc = -EINVAL;
5527 goto done;
5528 }
5529 snd_soc_update_bits(codec, TAIKO_A_RX_COM_OCP_CTL,
5530 0x0F, pdata->ocp.num_attempts);
5531 snd_soc_write(codec, TAIKO_A_RX_COM_OCP_COUNT,
5532 ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time));
5533 snd_soc_update_bits(codec, TAIKO_A_RX_HPH_OCP_CTL,
5534 0xE0, (pdata->ocp.hph_ocp_limit << 5));
5535 }
5536
5537 for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
Joonwoo Park448a8fc2013-04-10 15:25:58 -07005538 if (pdata->regulator[i].name &&
5539 !strncmp(pdata->regulator[i].name, "CDC_VDDA_RX", 11)) {
Kiran Kandic3b24402012-06-11 00:05:59 -07005540 if (pdata->regulator[i].min_uV == 1800000 &&
5541 pdata->regulator[i].max_uV == 1800000) {
5542 snd_soc_write(codec, TAIKO_A_BIAS_REF_CTL,
5543 0x1C);
5544 } else if (pdata->regulator[i].min_uV == 2200000 &&
5545 pdata->regulator[i].max_uV == 2200000) {
5546 snd_soc_write(codec, TAIKO_A_BIAS_REF_CTL,
5547 0x1E);
5548 } else {
5549 pr_err("%s: unsupported CDC_VDDA_RX voltage\n"
5550 "min %d, max %d\n", __func__,
5551 pdata->regulator[i].min_uV,
5552 pdata->regulator[i].max_uV);
5553 rc = -EINVAL;
5554 }
5555 break;
5556 }
5557 }
Kiran Kandi4c56c592012-07-25 11:04:55 -07005558
Joonwoo Park1848c762012-10-18 13:16:01 -07005559 /* Set micbias capless mode with tail current */
5560 value = (pdata->micbias.bias1_cap_mode == MICBIAS_EXT_BYP_CAP ?
5561 0x00 : 0x16);
5562 snd_soc_update_bits(codec, TAIKO_A_MICB_1_CTL, 0x1E, value);
5563 value = (pdata->micbias.bias2_cap_mode == MICBIAS_EXT_BYP_CAP ?
5564 0x00 : 0x16);
5565 snd_soc_update_bits(codec, TAIKO_A_MICB_2_CTL, 0x1E, value);
5566 value = (pdata->micbias.bias3_cap_mode == MICBIAS_EXT_BYP_CAP ?
5567 0x00 : 0x16);
5568 snd_soc_update_bits(codec, TAIKO_A_MICB_3_CTL, 0x1E, value);
5569 value = (pdata->micbias.bias4_cap_mode == MICBIAS_EXT_BYP_CAP ?
5570 0x00 : 0x16);
5571 snd_soc_update_bits(codec, TAIKO_A_MICB_4_CTL, 0x1E, value);
5572
Damir Didjusto1a353ce2013-04-02 11:45:47 -07005573 /* Set the DMIC sample rate */
5574 if (pdata->mclk_rate == TAIKO_MCLK_CLK_9P6HZ) {
5575 switch (pdata->dmic_sample_rate) {
5576 case TAIKO_DMIC_SAMPLE_RATE_2P4MHZ:
5577 dmic_sample_rate_value = TAIKO_DMIC_SAMPLE_RATE_DIV_4;
5578 dmic_b1_ctl_value = TAIKO_DMIC_B1_CTL_DIV_4;
5579 dmic_b2_ctl_value = TAIKO_DMIC_B2_CTL_DIV_4;
5580 anc_ctl_value = TAIKO_ANC_DMIC_X2_OFF;
5581 break;
5582 case TAIKO_DMIC_SAMPLE_RATE_4P8MHZ:
5583 dmic_sample_rate_value = TAIKO_DMIC_SAMPLE_RATE_DIV_2;
5584 dmic_b1_ctl_value = TAIKO_DMIC_B1_CTL_DIV_2;
5585 dmic_b2_ctl_value = TAIKO_DMIC_B2_CTL_DIV_2;
5586 anc_ctl_value = TAIKO_ANC_DMIC_X2_ON;
5587 break;
5588 case TAIKO_DMIC_SAMPLE_RATE_3P2MHZ:
5589 case TAIKO_DMIC_SAMPLE_RATE_UNDEFINED:
5590 dmic_sample_rate_value = TAIKO_DMIC_SAMPLE_RATE_DIV_3;
5591 dmic_b1_ctl_value = TAIKO_DMIC_B1_CTL_DIV_3;
5592 dmic_b2_ctl_value = TAIKO_DMIC_B2_CTL_DIV_3;
5593 anc_ctl_value = TAIKO_ANC_DMIC_X2_OFF;
5594 break;
5595 default:
5596 pr_err("%s Invalid sample rate %d for mclk %d\n",
5597 __func__, pdata->dmic_sample_rate, pdata->mclk_rate);
5598 rc = -EINVAL;
5599 goto done;
5600 break;
5601 }
5602 } else if (pdata->mclk_rate == TAIKO_MCLK_CLK_12P288MHZ) {
5603 switch (pdata->dmic_sample_rate) {
5604 case TAIKO_DMIC_SAMPLE_RATE_3P072MHZ:
5605 dmic_sample_rate_value = TAIKO_DMIC_SAMPLE_RATE_DIV_4;
5606 dmic_b1_ctl_value = TAIKO_DMIC_B1_CTL_DIV_4;
5607 dmic_b2_ctl_value = TAIKO_DMIC_B2_CTL_DIV_4;
5608 anc_ctl_value = TAIKO_ANC_DMIC_X2_OFF;
5609 break;
5610 case TAIKO_DMIC_SAMPLE_RATE_6P144MHZ:
5611 dmic_sample_rate_value = TAIKO_DMIC_SAMPLE_RATE_DIV_2;
5612 dmic_b1_ctl_value = TAIKO_DMIC_B1_CTL_DIV_2;
5613 dmic_b2_ctl_value = TAIKO_DMIC_B2_CTL_DIV_2;
5614 anc_ctl_value = TAIKO_ANC_DMIC_X2_ON;
5615 break;
5616 case TAIKO_DMIC_SAMPLE_RATE_4P096MHZ:
5617 case TAIKO_DMIC_SAMPLE_RATE_UNDEFINED:
5618 dmic_sample_rate_value = TAIKO_DMIC_SAMPLE_RATE_DIV_3;
5619 dmic_b1_ctl_value = TAIKO_DMIC_B1_CTL_DIV_3;
5620 dmic_b2_ctl_value = TAIKO_DMIC_B2_CTL_DIV_3;
5621 anc_ctl_value = TAIKO_ANC_DMIC_X2_OFF;
5622 break;
5623 default:
5624 pr_err("%s Invalid sample rate %d for mclk %d\n",
5625 __func__, pdata->dmic_sample_rate, pdata->mclk_rate);
5626 rc = -EINVAL;
5627 goto done;
5628 break;
5629 }
5630 } else {
5631 pr_err("%s MCLK is not set!\n", __func__);
5632 rc = -EINVAL;
5633 goto done;
5634 }
5635
5636 snd_soc_update_bits(codec, TAIKO_A_CDC_TX1_DMIC_CTL,
5637 0x7, dmic_sample_rate_value);
5638 snd_soc_update_bits(codec, TAIKO_A_CDC_TX2_DMIC_CTL,
5639 0x7, dmic_sample_rate_value);
5640 snd_soc_update_bits(codec, TAIKO_A_CDC_TX3_DMIC_CTL,
5641 0x7, dmic_sample_rate_value);
5642 snd_soc_update_bits(codec, TAIKO_A_CDC_TX4_DMIC_CTL,
5643 0x7, dmic_sample_rate_value);
5644 snd_soc_update_bits(codec, TAIKO_A_CDC_TX5_DMIC_CTL,
5645 0x7, dmic_sample_rate_value);
5646 snd_soc_update_bits(codec, TAIKO_A_CDC_TX6_DMIC_CTL,
5647 0x7, dmic_sample_rate_value);
5648 snd_soc_update_bits(codec, TAIKO_A_CDC_TX7_DMIC_CTL,
5649 0x7, dmic_sample_rate_value);
5650 snd_soc_update_bits(codec, TAIKO_A_CDC_TX8_DMIC_CTL,
5651 0x7, dmic_sample_rate_value);
5652 snd_soc_update_bits(codec, TAIKO_A_CDC_TX9_DMIC_CTL,
5653 0x7, dmic_sample_rate_value);
5654 snd_soc_update_bits(codec, TAIKO_A_CDC_TX10_DMIC_CTL,
5655 0x7, dmic_sample_rate_value);
5656 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_DMIC_B1_CTL,
5657 0xEE, dmic_b1_ctl_value);
5658 snd_soc_update_bits(codec, TAIKO_A_CDC_CLK_DMIC_B2_CTL,
5659 0xE, dmic_b2_ctl_value);
5660 snd_soc_update_bits(codec, TAIKO_A_CDC_ANC1_B2_CTL,
5661 0x1, anc_ctl_value);
5662
Kiran Kandic3b24402012-06-11 00:05:59 -07005663done:
5664 return rc;
5665}
5666
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08005667static const struct wcd9xxx_reg_mask_val taiko_reg_defaults[] = {
Kiran Kandic3b24402012-06-11 00:05:59 -07005668
Kiran Kandi4c56c592012-07-25 11:04:55 -07005669 /* set MCLk to 9.6 */
Gopikrishnaiah Anandana8aec1f2013-01-23 14:26:27 -05005670 TAIKO_REG_VAL(TAIKO_A_CHIP_CTL, 0x02),
Kiran Kandi4c56c592012-07-25 11:04:55 -07005671 TAIKO_REG_VAL(TAIKO_A_CDC_CLK_POWER_CTL, 0x03),
Kiran Kandic3b24402012-06-11 00:05:59 -07005672
Kiran Kandi4c56c592012-07-25 11:04:55 -07005673 /* EAR PA deafults */
5674 TAIKO_REG_VAL(TAIKO_A_RX_EAR_CMBUFF, 0x05),
Kiran Kandic3b24402012-06-11 00:05:59 -07005675
Kiran Kandi4c56c592012-07-25 11:04:55 -07005676 /* RX deafults */
Kiran Kandic3b24402012-06-11 00:05:59 -07005677 TAIKO_REG_VAL(TAIKO_A_CDC_RX1_B5_CTL, 0x78),
5678 TAIKO_REG_VAL(TAIKO_A_CDC_RX2_B5_CTL, 0x78),
5679 TAIKO_REG_VAL(TAIKO_A_CDC_RX3_B5_CTL, 0x78),
5680 TAIKO_REG_VAL(TAIKO_A_CDC_RX4_B5_CTL, 0x78),
5681 TAIKO_REG_VAL(TAIKO_A_CDC_RX5_B5_CTL, 0x78),
5682 TAIKO_REG_VAL(TAIKO_A_CDC_RX6_B5_CTL, 0x78),
5683 TAIKO_REG_VAL(TAIKO_A_CDC_RX7_B5_CTL, 0x78),
5684
Kiran Kandi4c56c592012-07-25 11:04:55 -07005685 /* RX1 and RX2 defaults */
Kiran Kandic3b24402012-06-11 00:05:59 -07005686 TAIKO_REG_VAL(TAIKO_A_CDC_RX1_B6_CTL, 0xA0),
5687 TAIKO_REG_VAL(TAIKO_A_CDC_RX2_B6_CTL, 0xA0),
5688
Kiran Kandi4c56c592012-07-25 11:04:55 -07005689 /* RX3 to RX7 defaults */
Kiran Kandic3b24402012-06-11 00:05:59 -07005690 TAIKO_REG_VAL(TAIKO_A_CDC_RX3_B6_CTL, 0x80),
5691 TAIKO_REG_VAL(TAIKO_A_CDC_RX4_B6_CTL, 0x80),
5692 TAIKO_REG_VAL(TAIKO_A_CDC_RX5_B6_CTL, 0x80),
5693 TAIKO_REG_VAL(TAIKO_A_CDC_RX6_B6_CTL, 0x80),
5694 TAIKO_REG_VAL(TAIKO_A_CDC_RX7_B6_CTL, 0x80),
Joonwoo Park1d05bb92013-03-07 16:55:06 -08005695
5696 /* MAD registers */
5697 TAIKO_REG_VAL(TAIKO_A_MAD_ANA_CTRL, 0xF1),
5698 TAIKO_REG_VAL(TAIKO_A_CDC_MAD_MAIN_CTL_1, 0x00),
5699 TAIKO_REG_VAL(TAIKO_A_CDC_MAD_MAIN_CTL_2, 0x00),
5700 TAIKO_REG_VAL(TAIKO_A_CDC_MAD_AUDIO_CTL_1, 0x00),
5701 /* Set SAMPLE_TX_EN bit */
5702 TAIKO_REG_VAL(TAIKO_A_CDC_MAD_AUDIO_CTL_2, 0x03),
5703 TAIKO_REG_VAL(TAIKO_A_CDC_MAD_AUDIO_CTL_3, 0x00),
5704 TAIKO_REG_VAL(TAIKO_A_CDC_MAD_AUDIO_CTL_4, 0x00),
5705 TAIKO_REG_VAL(TAIKO_A_CDC_MAD_AUDIO_CTL_5, 0x00),
5706 TAIKO_REG_VAL(TAIKO_A_CDC_MAD_AUDIO_CTL_6, 0x00),
5707 TAIKO_REG_VAL(TAIKO_A_CDC_MAD_AUDIO_CTL_7, 0x00),
5708 TAIKO_REG_VAL(TAIKO_A_CDC_MAD_AUDIO_CTL_8, 0x00),
5709 TAIKO_REG_VAL(TAIKO_A_CDC_MAD_AUDIO_IIR_CTL_PTR, 0x00),
5710 TAIKO_REG_VAL(TAIKO_A_CDC_MAD_AUDIO_IIR_CTL_VAL, 0x40),
5711 TAIKO_REG_VAL(TAIKO_A_CDC_DEBUG_B7_CTL, 0x00),
5712 TAIKO_REG_VAL(TAIKO_A_CDC_CLK_OTHR_RESET_B1_CTL, 0x00),
5713 TAIKO_REG_VAL(TAIKO_A_CDC_CLK_OTHR_CTL, 0x00),
5714 TAIKO_REG_VAL(TAIKO_A_CDC_CONN_MAD, 0x01),
Kiran Kandic3b24402012-06-11 00:05:59 -07005715};
5716
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08005717static const struct wcd9xxx_reg_mask_val taiko_1_0_reg_defaults[] = {
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005718 /*
5719 * The following only need to be written for Taiko 1.0 parts.
5720 * Taiko 2.0 will have appropriate defaults for these registers.
5721 */
Joonwoo Park559a5bf2013-02-15 14:46:36 -08005722
5723 /* BUCK default */
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08005724 TAIKO_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_4, 0x50),
5725
5726 /* Required defaults for class H operation */
5727 TAIKO_REG_VAL(TAIKO_A_RX_HPH_CHOP_CTL, 0xF4),
5728 TAIKO_REG_VAL(TAIKO_A_BIAS_CURR_CTL_2, 0x08),
5729 TAIKO_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_1, 0x5B),
5730 TAIKO_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_3, 0x60),
Joonwoo Park559a5bf2013-02-15 14:46:36 -08005731
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005732 /* Choose max non-overlap time for NCP */
5733 TAIKO_REG_VAL(TAIKO_A_NCP_CLK, 0xFC),
5734 /* Use 25mV/50mV for deltap/m to reduce ripple */
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08005735 TAIKO_REG_VAL(WCD9XXX_A_BUCK_CTRL_VCL_1, 0x08),
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005736 /*
5737 * Set DISABLE_MODE_SEL<1:0> to 0b10 (disable PWM in auto mode).
5738 * Note that the other bits of this register will be changed during
5739 * Rx PA bring up.
5740 */
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08005741 TAIKO_REG_VAL(WCD9XXX_A_BUCK_MODE_3, 0xCE),
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005742 /* Reduce HPH DAC bias to 70% */
5743 TAIKO_REG_VAL(TAIKO_A_RX_HPH_BIAS_PA, 0x7A),
5744 /*Reduce EAR DAC bias to 70% */
5745 TAIKO_REG_VAL(TAIKO_A_RX_EAR_BIAS_PA, 0x76),
5746 /* Reduce LINE DAC bias to 70% */
5747 TAIKO_REG_VAL(TAIKO_A_RX_LINE_BIAS_PA, 0x78),
Joonwoo Parkd87ec4c2012-10-30 15:44:18 -07005748
5749 /*
5750 * There is a diode to pull down the micbias while doing
5751 * insertion detection. This diode can cause leakage.
5752 * Set bit 0 to 1 to prevent leakage.
5753 * Setting this bit of micbias 2 prevents leakage for all other micbias.
5754 */
5755 TAIKO_REG_VAL(TAIKO_A_MICB_2_MBHC, 0x41),
Joonwoo Park3c7bca62012-10-31 12:44:23 -07005756
5757 /* Disable TX7 internal biasing path which can cause leakage */
5758 TAIKO_REG_VAL(TAIKO_A_TX_SUP_SWITCH_CTRL_1, 0xBF),
Joonwoo Park03604052012-11-06 18:40:25 -08005759 /* Enable MICB 4 VDDIO switch to prevent leakage */
5760 TAIKO_REG_VAL(TAIKO_A_MICB_4_MBHC, 0x81),
Joonwoo Park125cd4e2012-12-11 15:16:11 -08005761
5762 /* Close leakage on the spkdrv */
5763 TAIKO_REG_VAL(TAIKO_A_SPKR_DRV_DBG_PWRSTG, 0x24),
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005764};
5765
Joonwoo Park559a5bf2013-02-15 14:46:36 -08005766/*
5767 * Don't update TAIKO_A_CHIP_CTL, TAIKO_A_BUCK_CTRL_CCL_1 and
5768 * TAIKO_A_RX_EAR_CMBUFF as those are updated in taiko_reg_defaults
5769 */
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08005770static const struct wcd9xxx_reg_mask_val taiko_2_0_reg_defaults[] = {
Joonwoo Park559a5bf2013-02-15 14:46:36 -08005771 TAIKO_REG_VAL(TAIKO_A_CDC_TX_1_GAIN, 0x2),
5772 TAIKO_REG_VAL(TAIKO_A_CDC_TX_2_GAIN, 0x2),
5773 TAIKO_REG_VAL(TAIKO_A_CDC_TX_1_2_ADC_IB, 0x44),
5774 TAIKO_REG_VAL(TAIKO_A_CDC_TX_3_GAIN, 0x2),
5775 TAIKO_REG_VAL(TAIKO_A_CDC_TX_4_GAIN, 0x2),
5776 TAIKO_REG_VAL(TAIKO_A_CDC_TX_3_4_ADC_IB, 0x44),
5777 TAIKO_REG_VAL(TAIKO_A_CDC_TX_5_GAIN, 0x2),
5778 TAIKO_REG_VAL(TAIKO_A_CDC_TX_6_GAIN, 0x2),
5779 TAIKO_REG_VAL(TAIKO_A_CDC_TX_5_6_ADC_IB, 0x44),
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08005780 TAIKO_REG_VAL(WCD9XXX_A_BUCK_MODE_3, 0xCE),
5781 TAIKO_REG_VAL(WCD9XXX_A_BUCK_CTRL_VCL_1, 0x8),
5782 TAIKO_REG_VAL(WCD9XXX_A_BUCK_CTRL_CCL_4, 0x51),
Joonwoo Park559a5bf2013-02-15 14:46:36 -08005783 TAIKO_REG_VAL(TAIKO_A_NCP_DTEST, 0x10),
5784 TAIKO_REG_VAL(TAIKO_A_RX_HPH_CHOP_CTL, 0xA4),
5785 TAIKO_REG_VAL(TAIKO_A_RX_HPH_BIAS_PA, 0x7A),
5786 TAIKO_REG_VAL(TAIKO_A_RX_HPH_OCP_CTL, 0x69),
5787 TAIKO_REG_VAL(TAIKO_A_RX_HPH_CNP_WG_CTL, 0xDA),
5788 TAIKO_REG_VAL(TAIKO_A_RX_HPH_CNP_WG_TIME, 0x15),
5789 TAIKO_REG_VAL(TAIKO_A_RX_EAR_BIAS_PA, 0x76),
5790 TAIKO_REG_VAL(TAIKO_A_RX_EAR_CNP, 0xC0),
5791 TAIKO_REG_VAL(TAIKO_A_RX_LINE_BIAS_PA, 0x78),
5792 TAIKO_REG_VAL(TAIKO_A_RX_LINE_1_TEST, 0x2),
5793 TAIKO_REG_VAL(TAIKO_A_RX_LINE_2_TEST, 0x2),
5794 TAIKO_REG_VAL(TAIKO_A_RX_LINE_3_TEST, 0x2),
5795 TAIKO_REG_VAL(TAIKO_A_RX_LINE_4_TEST, 0x2),
5796 TAIKO_REG_VAL(TAIKO_A_SPKR_DRV_OCP_CTL, 0x97),
5797 TAIKO_REG_VAL(TAIKO_A_SPKR_DRV_CLIP_DET, 0x1),
5798 TAIKO_REG_VAL(TAIKO_A_SPKR_DRV_IEC, 0x0),
5799 TAIKO_REG_VAL(TAIKO_A_CDC_TX1_MUX_CTL, 0x48),
5800 TAIKO_REG_VAL(TAIKO_A_CDC_TX2_MUX_CTL, 0x48),
5801 TAIKO_REG_VAL(TAIKO_A_CDC_TX3_MUX_CTL, 0x48),
5802 TAIKO_REG_VAL(TAIKO_A_CDC_TX4_MUX_CTL, 0x48),
5803 TAIKO_REG_VAL(TAIKO_A_CDC_TX5_MUX_CTL, 0x48),
5804 TAIKO_REG_VAL(TAIKO_A_CDC_TX6_MUX_CTL, 0x48),
5805 TAIKO_REG_VAL(TAIKO_A_CDC_TX7_MUX_CTL, 0x48),
5806 TAIKO_REG_VAL(TAIKO_A_CDC_TX8_MUX_CTL, 0x48),
5807 TAIKO_REG_VAL(TAIKO_A_CDC_TX9_MUX_CTL, 0x48),
5808 TAIKO_REG_VAL(TAIKO_A_CDC_TX10_MUX_CTL, 0x48),
5809 TAIKO_REG_VAL(TAIKO_A_CDC_RX1_B4_CTL, 0x8),
Joonwoo Parkdbbdac02013-03-21 19:24:31 -07005810 TAIKO_REG_VAL(TAIKO_A_CDC_RX2_B4_CTL, 0x8),
5811 TAIKO_REG_VAL(TAIKO_A_CDC_RX3_B4_CTL, 0x8),
5812 TAIKO_REG_VAL(TAIKO_A_CDC_RX4_B4_CTL, 0x8),
5813 TAIKO_REG_VAL(TAIKO_A_CDC_RX5_B4_CTL, 0x8),
5814 TAIKO_REG_VAL(TAIKO_A_CDC_RX6_B4_CTL, 0x8),
5815 TAIKO_REG_VAL(TAIKO_A_CDC_RX7_B4_CTL, 0x8),
Joonwoo Park559a5bf2013-02-15 14:46:36 -08005816 TAIKO_REG_VAL(TAIKO_A_CDC_VBAT_GAIN_UPD_MON, 0x0),
5817 TAIKO_REG_VAL(TAIKO_A_CDC_PA_RAMP_B1_CTL, 0x0),
5818 TAIKO_REG_VAL(TAIKO_A_CDC_PA_RAMP_B2_CTL, 0x0),
5819 TAIKO_REG_VAL(TAIKO_A_CDC_PA_RAMP_B3_CTL, 0x0),
5820 TAIKO_REG_VAL(TAIKO_A_CDC_PA_RAMP_B4_CTL, 0x0),
5821 TAIKO_REG_VAL(TAIKO_A_CDC_SPKR_CLIPDET_B1_CTL, 0x0),
5822 TAIKO_REG_VAL(TAIKO_A_CDC_COMP0_B4_CTL, 0x37),
5823 TAIKO_REG_VAL(TAIKO_A_CDC_COMP0_B5_CTL, 0x7f),
5824};
5825
Kiran Kandic3b24402012-06-11 00:05:59 -07005826static void taiko_update_reg_defaults(struct snd_soc_codec *codec)
5827{
5828 u32 i;
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005829 struct wcd9xxx *taiko_core = dev_get_drvdata(codec->dev->parent);
Kiran Kandic3b24402012-06-11 00:05:59 -07005830
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005831 for (i = 0; i < ARRAY_SIZE(taiko_reg_defaults); i++)
5832 snd_soc_write(codec, taiko_reg_defaults[i].reg,
Joonwoo Park559a5bf2013-02-15 14:46:36 -08005833 taiko_reg_defaults[i].val);
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005834
5835 if (TAIKO_IS_1_0(taiko_core->version)) {
5836 for (i = 0; i < ARRAY_SIZE(taiko_1_0_reg_defaults); i++)
5837 snd_soc_write(codec, taiko_1_0_reg_defaults[i].reg,
Joonwoo Park559a5bf2013-02-15 14:46:36 -08005838 taiko_1_0_reg_defaults[i].val);
5839 if (spkr_drv_wrnd == 1)
5840 snd_soc_write(codec, TAIKO_A_SPKR_DRV_EN, 0xEF);
5841 } else {
5842 for (i = 0; i < ARRAY_SIZE(taiko_2_0_reg_defaults); i++)
5843 snd_soc_write(codec, taiko_2_0_reg_defaults[i].reg,
5844 taiko_2_0_reg_defaults[i].val);
Joonwoo Park125cd4e2012-12-11 15:16:11 -08005845 spkr_drv_wrnd = -1;
Joonwoo Park559a5bf2013-02-15 14:46:36 -08005846 }
Kiran Kandic3b24402012-06-11 00:05:59 -07005847}
5848
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08005849static const struct wcd9xxx_reg_mask_val taiko_codec_reg_init_val[] = {
Kiran Kandic3b24402012-06-11 00:05:59 -07005850 /* Initialize current threshold to 350MA
5851 * number of wait and run cycles to 4096
5852 */
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07005853 {TAIKO_A_RX_HPH_OCP_CTL, 0xE1, 0x61},
Kiran Kandic3b24402012-06-11 00:05:59 -07005854 {TAIKO_A_RX_COM_OCP_COUNT, 0xFF, 0xFF},
Patrick Lai92833bf2012-12-01 10:31:35 -08005855 {TAIKO_A_RX_HPH_L_TEST, 0x01, 0x01},
5856 {TAIKO_A_RX_HPH_R_TEST, 0x01, 0x01},
Kiran Kandic3b24402012-06-11 00:05:59 -07005857
Kiran Kandic3b24402012-06-11 00:05:59 -07005858 /* Initialize gain registers to use register gain */
Kiran Kandi4c56c592012-07-25 11:04:55 -07005859 {TAIKO_A_RX_HPH_L_GAIN, 0x20, 0x20},
5860 {TAIKO_A_RX_HPH_R_GAIN, 0x20, 0x20},
5861 {TAIKO_A_RX_LINE_1_GAIN, 0x20, 0x20},
5862 {TAIKO_A_RX_LINE_2_GAIN, 0x20, 0x20},
5863 {TAIKO_A_RX_LINE_3_GAIN, 0x20, 0x20},
5864 {TAIKO_A_RX_LINE_4_GAIN, 0x20, 0x20},
Joonwoo Parkc7731432012-10-17 12:41:44 -07005865 {TAIKO_A_SPKR_DRV_GAIN, 0x04, 0x04},
Kiran Kandic3b24402012-06-11 00:05:59 -07005866
Kiran Kandic3b24402012-06-11 00:05:59 -07005867 /* Use 16 bit sample size for TX1 to TX6 */
5868 {TAIKO_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20},
5869 {TAIKO_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20},
5870 {TAIKO_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20},
5871 {TAIKO_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20},
5872 {TAIKO_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20},
5873 {TAIKO_A_CDC_CONN_TX_SB_B6_CTL, 0x30, 0x20},
5874
5875 /* Use 16 bit sample size for TX7 to TX10 */
5876 {TAIKO_A_CDC_CONN_TX_SB_B7_CTL, 0x60, 0x40},
5877 {TAIKO_A_CDC_CONN_TX_SB_B8_CTL, 0x60, 0x40},
5878 {TAIKO_A_CDC_CONN_TX_SB_B9_CTL, 0x60, 0x40},
5879 {TAIKO_A_CDC_CONN_TX_SB_B10_CTL, 0x60, 0x40},
5880
Kiran Kandic3b24402012-06-11 00:05:59 -07005881 /*enable HPF filter for TX paths */
5882 {TAIKO_A_CDC_TX1_MUX_CTL, 0x8, 0x0},
5883 {TAIKO_A_CDC_TX2_MUX_CTL, 0x8, 0x0},
5884 {TAIKO_A_CDC_TX3_MUX_CTL, 0x8, 0x0},
5885 {TAIKO_A_CDC_TX4_MUX_CTL, 0x8, 0x0},
5886 {TAIKO_A_CDC_TX5_MUX_CTL, 0x8, 0x0},
5887 {TAIKO_A_CDC_TX6_MUX_CTL, 0x8, 0x0},
5888 {TAIKO_A_CDC_TX7_MUX_CTL, 0x8, 0x0},
5889 {TAIKO_A_CDC_TX8_MUX_CTL, 0x8, 0x0},
5890 {TAIKO_A_CDC_TX9_MUX_CTL, 0x8, 0x0},
5891 {TAIKO_A_CDC_TX10_MUX_CTL, 0x8, 0x0},
5892
Joonwoo Parkc7731432012-10-17 12:41:44 -07005893 /* Compander zone selection */
5894 {TAIKO_A_CDC_COMP0_B4_CTL, 0x3F, 0x37},
5895 {TAIKO_A_CDC_COMP1_B4_CTL, 0x3F, 0x37},
5896 {TAIKO_A_CDC_COMP2_B4_CTL, 0x3F, 0x37},
5897 {TAIKO_A_CDC_COMP0_B5_CTL, 0x7F, 0x7F},
5898 {TAIKO_A_CDC_COMP1_B5_CTL, 0x7F, 0x7F},
5899 {TAIKO_A_CDC_COMP2_B5_CTL, 0x7F, 0x7F},
Bhalchandra Gajareef7810e2013-03-29 16:50:37 -07005900
5901 /*
5902 * Setup wavegen timer to 20msec and disable chopper
5903 * as default. This corresponds to Compander OFF
5904 */
5905 {TAIKO_A_RX_HPH_CNP_WG_CTL, 0xFF, 0xDB},
5906 {TAIKO_A_RX_HPH_CNP_WG_TIME, 0xFF, 0x58},
5907 {TAIKO_A_RX_HPH_BIAS_WG_OCP, 0xFF, 0x1A},
5908 {TAIKO_A_RX_HPH_CHOP_CTL, 0xFF, 0x24},
Bhalchandra Gajare9581aed2013-03-29 17:06:10 -07005909
5910 /* Choose max non-overlap time for NCP */
5911 {TAIKO_A_NCP_CLK, 0xFF, 0xFC},
5912
5913 /* Program the 0.85 volt VBG_REFERENCE */
5914 {TAIKO_A_BIAS_CURR_CTL_2, 0xFF, 0x04},
Kiran Kandic3b24402012-06-11 00:05:59 -07005915};
5916
5917static void taiko_codec_init_reg(struct snd_soc_codec *codec)
5918{
5919 u32 i;
5920
5921 for (i = 0; i < ARRAY_SIZE(taiko_codec_reg_init_val); i++)
5922 snd_soc_update_bits(codec, taiko_codec_reg_init_val[i].reg,
5923 taiko_codec_reg_init_val[i].mask,
5924 taiko_codec_reg_init_val[i].val);
5925}
5926
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07005927static void taiko_slim_interface_init_reg(struct snd_soc_codec *codec)
Joonwoo Park7680b9f2012-07-13 11:36:48 -07005928{
Joonwoo Park7680b9f2012-07-13 11:36:48 -07005929 int i;
Joonwoo Park7680b9f2012-07-13 11:36:48 -07005930
5931 for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++)
5932 wcd9xxx_interface_reg_write(codec->control_data,
Joonwoo Parka8890262012-10-15 12:04:27 -07005933 TAIKO_SLIM_PGD_PORT_INT_EN0 + i,
5934 0xFF);
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07005935}
5936
5937static int taiko_setup_irqs(struct taiko_priv *taiko)
5938{
5939 int ret = 0;
5940 struct snd_soc_codec *codec = taiko->codec;
5941
5942 ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS,
5943 taiko_slimbus_irq, "SLIMBUS Slave", taiko);
5944 if (ret)
5945 pr_err("%s: Failed to request irq %d\n", __func__,
5946 WCD9XXX_IRQ_SLIMBUS);
5947 else
5948 taiko_slim_interface_init_reg(codec);
5949
Joonwoo Park7680b9f2012-07-13 11:36:48 -07005950 return ret;
5951}
5952
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07005953static void taiko_cleanup_irqs(struct taiko_priv *taiko)
5954{
5955 struct snd_soc_codec *codec = taiko->codec;
5956
5957 wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, taiko);
5958}
5959
Joonwoo Parka8890262012-10-15 12:04:27 -07005960int taiko_hs_detect(struct snd_soc_codec *codec,
5961 struct wcd9xxx_mbhc_config *mbhc_cfg)
5962{
5963 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
5964 return wcd9xxx_mbhc_start(&taiko->mbhc, mbhc_cfg);
5965}
5966EXPORT_SYMBOL_GPL(taiko_hs_detect);
5967
Joonwoo Park1d05bb92013-03-07 16:55:06 -08005968static void taiko_init_slim_slave_cfg(struct snd_soc_codec *codec)
5969{
5970 struct taiko_priv *priv = snd_soc_codec_get_drvdata(codec);
5971 struct afe_param_cdc_slimbus_slave_cfg *cfg;
5972 struct wcd9xxx *wcd9xxx = codec->control_data;
5973 uint64_t eaddr = 0;
5974
5975 cfg = &priv->slimbus_slave_cfg;
5976 cfg->minor_version = 1;
5977 cfg->tx_slave_port_offset = 0;
5978 cfg->rx_slave_port_offset = 16;
5979
5980 memcpy(&eaddr, &wcd9xxx->slim->e_addr, sizeof(wcd9xxx->slim->e_addr));
5981 WARN_ON(sizeof(wcd9xxx->slim->e_addr) != 6);
5982 cfg->device_enum_addr_lsw = eaddr & 0xFFFFFFFF;
5983 cfg->device_enum_addr_msw = eaddr >> 32;
5984
5985 pr_debug("%s: slimbus logical address 0x%llx\n", __func__, eaddr);
5986}
5987
Ravishankar Sarawadi839fcf32012-11-14 12:13:00 -08005988static int taiko_post_reset_cb(struct wcd9xxx *wcd9xxx)
5989{
5990 int ret = 0;
5991 struct snd_soc_codec *codec;
5992 struct taiko_priv *taiko;
5993
5994 codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv);
5995 taiko = snd_soc_codec_get_drvdata(codec);
5996 mutex_lock(&codec->mutex);
5997 WCD9XXX_BCL_LOCK(&taiko->resmgr);
Ravishankar Sarawadi839fcf32012-11-14 12:13:00 -08005998
5999 if (codec->reg_def_copy) {
6000 pr_debug("%s: Update ASOC cache", __func__);
6001 kfree(codec->reg_cache);
6002 codec->reg_cache = kmemdup(codec->reg_def_copy,
6003 codec->reg_size, GFP_KERNEL);
6004 }
6005
Ravishankar Sarawadi2293efe2013-01-11 16:37:23 -08006006 wcd9xxx_resmgr_post_ssr(&taiko->resmgr);
6007 if (spkr_drv_wrnd == 1)
6008 snd_soc_update_bits(codec, TAIKO_A_SPKR_DRV_EN, 0x80, 0x80);
6009 WCD9XXX_BCL_UNLOCK(&taiko->resmgr);
6010
Ravishankar Sarawadi839fcf32012-11-14 12:13:00 -08006011 taiko_update_reg_defaults(codec);
6012 taiko_codec_init_reg(codec);
6013 ret = taiko_handle_pdata(taiko);
6014 if (IS_ERR_VALUE(ret))
6015 pr_err("%s: bad pdata\n", __func__);
Ravishankar Sarawadi2293efe2013-01-11 16:37:23 -08006016
Joonwoo Park1d05bb92013-03-07 16:55:06 -08006017 taiko_init_slim_slave_cfg(codec);
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07006018 taiko_slim_interface_init_reg(codec);
Joonwoo Park1d05bb92013-03-07 16:55:06 -08006019
Ravishankar Sarawadi2293efe2013-01-11 16:37:23 -08006020 wcd9xxx_mbhc_deinit(&taiko->mbhc);
Simmi Pateriya0a44d842013-04-03 01:12:42 +05306021 ret = wcd9xxx_mbhc_init(&taiko->mbhc, &taiko->resmgr, codec,
6022 WCD9XXX_MBHC_VERSION_TAIKO);
Ravishankar Sarawadi2293efe2013-01-11 16:37:23 -08006023 if (ret)
6024 pr_err("%s: mbhc init failed %d\n", __func__, ret);
6025 else
6026 wcd9xxx_mbhc_start(&taiko->mbhc, taiko->mbhc.mbhc_cfg);
Ravishankar Sarawadi839fcf32012-11-14 12:13:00 -08006027 mutex_unlock(&codec->mutex);
6028 return ret;
6029}
6030
Joonwoo Park1d05bb92013-03-07 16:55:06 -08006031void *taiko_get_afe_config(struct snd_soc_codec *codec,
6032 enum afe_config_type config_type)
6033{
6034 struct taiko_priv *priv = snd_soc_codec_get_drvdata(codec);
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -04006035 struct wcd9xxx *taiko_core = dev_get_drvdata(codec->dev->parent);
Joonwoo Park1d05bb92013-03-07 16:55:06 -08006036
6037 switch (config_type) {
6038 case AFE_SLIMBUS_SLAVE_CONFIG:
6039 return &priv->slimbus_slave_cfg;
6040 case AFE_CDC_REGISTERS_CONFIG:
Damir Didjustodcfdff82013-03-21 23:26:41 -07006041 return &taiko_audio_reg_cfg;
Joonwoo Park1d05bb92013-03-07 16:55:06 -08006042 case AFE_SLIMBUS_SLAVE_PORT_CONFIG:
6043 return &taiko_slimbus_slave_port_cfg;
Damir Didjustodcfdff82013-03-21 23:26:41 -07006044 case AFE_AANC_VERSION:
6045 return &taiko_cdc_aanc_version;
Gopikrishnaiah Anandaneb51dd72013-04-09 11:39:55 -04006046 case AFE_CLIP_BANK_SEL:
6047 if (!TAIKO_IS_1_0(taiko_core->version))
6048 return &clip_bank_sel;
6049 else
6050 return NULL;
6051 case AFE_CDC_CLIP_REGISTERS_CONFIG:
6052 if (!TAIKO_IS_1_0(taiko_core->version))
6053 return &taiko_clip_reg_cfg;
6054 else
6055 return NULL;
Joonwoo Park1d05bb92013-03-07 16:55:06 -08006056 default:
6057 pr_err("%s: Unknown config_type 0x%x\n", __func__, config_type);
6058 return NULL;
6059 }
6060}
Ravishankar Sarawadi839fcf32012-11-14 12:13:00 -08006061
Joonwoo Parka8890262012-10-15 12:04:27 -07006062static struct wcd9xxx_reg_address taiko_reg_address = {
6063 .micb_4_mbhc = TAIKO_A_MICB_4_MBHC,
6064 .micb_4_int_rbias = TAIKO_A_MICB_4_INT_RBIAS,
6065 .micb_4_ctl = TAIKO_A_MICB_4_CTL,
6066};
6067
Ravishankar Sarawadi839fcf32012-11-14 12:13:00 -08006068static int wcd9xxx_ssr_register(struct wcd9xxx *control,
6069 int (*post_reset_cb)(struct wcd9xxx *wcd9xxx), void *priv)
6070{
6071 control->post_reset = post_reset_cb;
6072 control->ssr_priv = priv;
6073 return 0;
6074}
6075
Joonwoo Park2a9170a2013-03-04 17:05:57 -08006076static const struct snd_soc_dapm_widget taiko_1_dapm_widgets[] = {
6077 SND_SOC_DAPM_ADC_E("ADC1", NULL, TAIKO_A_TX_1_2_EN, 7, 0,
6078 taiko_codec_enable_adc,
6079 SND_SOC_DAPM_PRE_PMU |
6080 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
6081 SND_SOC_DAPM_ADC_E("ADC2", NULL, TAIKO_A_TX_1_2_EN, 3, 0,
6082 taiko_codec_enable_adc,
6083 SND_SOC_DAPM_PRE_PMU |
6084 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
6085 SND_SOC_DAPM_ADC_E("ADC3", NULL, TAIKO_A_TX_3_4_EN, 7, 0,
6086 taiko_codec_enable_adc,
6087 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
6088 SND_SOC_DAPM_POST_PMD),
6089 SND_SOC_DAPM_ADC_E("ADC4", NULL, TAIKO_A_TX_3_4_EN, 3, 0,
6090 taiko_codec_enable_adc,
6091 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
6092 SND_SOC_DAPM_POST_PMD),
6093 SND_SOC_DAPM_ADC_E("ADC5", NULL, TAIKO_A_TX_5_6_EN, 7, 0,
6094 taiko_codec_enable_adc,
6095 SND_SOC_DAPM_POST_PMU),
6096 SND_SOC_DAPM_ADC_E("ADC6", NULL, TAIKO_A_TX_5_6_EN, 3, 0,
6097 taiko_codec_enable_adc,
6098 SND_SOC_DAPM_POST_PMU),
6099};
6100
6101static const struct snd_soc_dapm_widget taiko_2_dapm_widgets[] = {
6102 SND_SOC_DAPM_ADC_E("ADC1", NULL, TAIKO_A_CDC_TX_1_GAIN, 7, 0,
6103 taiko_codec_enable_adc,
6104 SND_SOC_DAPM_PRE_PMU |
6105 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
6106 SND_SOC_DAPM_ADC_E("ADC2", NULL, TAIKO_A_CDC_TX_2_GAIN, 7, 0,
6107 taiko_codec_enable_adc,
6108 SND_SOC_DAPM_PRE_PMU |
6109 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
6110 SND_SOC_DAPM_ADC_E("ADC3", NULL, TAIKO_A_CDC_TX_3_GAIN, 7, 0,
6111 taiko_codec_enable_adc,
6112 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
6113 SND_SOC_DAPM_POST_PMD),
6114 SND_SOC_DAPM_ADC_E("ADC4", NULL, TAIKO_A_CDC_TX_4_GAIN, 7, 0,
6115 taiko_codec_enable_adc,
6116 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
6117 SND_SOC_DAPM_POST_PMD),
6118 SND_SOC_DAPM_ADC_E("ADC5", NULL, TAIKO_A_CDC_TX_5_GAIN, 7, 0,
6119 taiko_codec_enable_adc,
6120 SND_SOC_DAPM_POST_PMU),
6121 SND_SOC_DAPM_ADC_E("ADC6", NULL, TAIKO_A_CDC_TX_6_GAIN, 7, 0,
6122 taiko_codec_enable_adc,
6123 SND_SOC_DAPM_POST_PMU),
6124};
6125
Joonwoo Park448a8fc2013-04-10 15:25:58 -07006126static struct regulator *taiko_codec_find_regulator(struct snd_soc_codec *codec,
6127 const char *name)
6128{
6129 int i;
6130 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
6131
6132 for (i = 0; i < core->num_of_supplies; i++) {
6133 if (core->supplies[i].supply &&
6134 !strcmp(core->supplies[i].supply, name))
6135 return core->supplies[i].consumer;
6136 }
6137
6138 return NULL;
6139}
6140
Kiran Kandic3b24402012-06-11 00:05:59 -07006141static int taiko_codec_probe(struct snd_soc_codec *codec)
6142{
6143 struct wcd9xxx *control;
6144 struct taiko_priv *taiko;
Joonwoo Parka8890262012-10-15 12:04:27 -07006145 struct wcd9xxx_pdata *pdata;
6146 struct wcd9xxx *wcd9xxx;
Kiran Kandic3b24402012-06-11 00:05:59 -07006147 struct snd_soc_dapm_context *dapm = &codec->dapm;
6148 int ret = 0;
6149 int i;
Kuirong Wang906ac472012-07-09 12:54:44 -07006150 void *ptr = NULL;
Joonwoo Park559a5bf2013-02-15 14:46:36 -08006151 struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent);
Kiran Kandic3b24402012-06-11 00:05:59 -07006152
6153 codec->control_data = dev_get_drvdata(codec->dev->parent);
6154 control = codec->control_data;
6155
Ravishankar Sarawadi839fcf32012-11-14 12:13:00 -08006156 wcd9xxx_ssr_register(control, taiko_post_reset_cb, (void *)codec);
6157
Kiran Kandi4c56c592012-07-25 11:04:55 -07006158 dev_info(codec->dev, "%s()\n", __func__);
6159
Kiran Kandic3b24402012-06-11 00:05:59 -07006160 taiko = kzalloc(sizeof(struct taiko_priv), GFP_KERNEL);
6161 if (!taiko) {
6162 dev_err(codec->dev, "Failed to allocate private data\n");
6163 return -ENOMEM;
6164 }
6165 for (i = 0 ; i < NUM_DECIMATORS; i++) {
6166 tx_hpf_work[i].taiko = taiko;
6167 tx_hpf_work[i].decimator = i + 1;
6168 INIT_DELAYED_WORK(&tx_hpf_work[i].dwork,
6169 tx_hpf_corner_freq_callback);
6170 }
6171
Kiran Kandic3b24402012-06-11 00:05:59 -07006172 snd_soc_codec_set_drvdata(codec, taiko);
6173
Joonwoo Parka8890262012-10-15 12:04:27 -07006174 /* codec resmgr module init */
6175 wcd9xxx = codec->control_data;
6176 pdata = dev_get_platdata(codec->dev->parent);
6177 ret = wcd9xxx_resmgr_init(&taiko->resmgr, codec, wcd9xxx, pdata,
6178 &taiko_reg_address);
6179 if (ret) {
6180 pr_err("%s: wcd9xxx init failed %d\n", __func__, ret);
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07006181 goto err_init;
Joonwoo Parka8890262012-10-15 12:04:27 -07006182 }
6183
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08006184 taiko->clsh_d.buck_mv = taiko_codec_get_buck_mv(codec);
Joonwoo Parka08e0552013-03-05 18:28:23 -08006185 wcd9xxx_clsh_init(&taiko->clsh_d, &taiko->resmgr);
Bhalchandra Gajare87fef4c2013-02-19 14:57:03 -08006186
Joonwoo Parka8890262012-10-15 12:04:27 -07006187 /* init and start mbhc */
Simmi Pateriya0a44d842013-04-03 01:12:42 +05306188 ret = wcd9xxx_mbhc_init(&taiko->mbhc, &taiko->resmgr, codec,
6189 WCD9XXX_MBHC_VERSION_TAIKO);
Joonwoo Parka8890262012-10-15 12:04:27 -07006190 if (ret) {
6191 pr_err("%s: mbhc init failed %d\n", __func__, ret);
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07006192 goto err_init;
Joonwoo Parka8890262012-10-15 12:04:27 -07006193 }
6194
Kiran Kandic3b24402012-06-11 00:05:59 -07006195 taiko->codec = codec;
Kiran Kandic3b24402012-06-11 00:05:59 -07006196 for (i = 0; i < COMPANDER_MAX; i++) {
6197 taiko->comp_enabled[i] = 0;
6198 taiko->comp_fs[i] = COMPANDER_FS_48KHZ;
6199 }
Kiran Kandic3b24402012-06-11 00:05:59 -07006200 taiko->intf_type = wcd9xxx_get_intf_type();
6201 taiko->aux_pga_cnt = 0;
6202 taiko->aux_l_gain = 0x1F;
6203 taiko->aux_r_gain = 0x1F;
Kiran Kandic3b24402012-06-11 00:05:59 -07006204 taiko_update_reg_defaults(codec);
Venkat Sudhira50a3762012-11-26 12:12:15 -08006205 pr_debug("%s: MCLK Rate = %x\n", __func__, wcd9xxx->mclk_rate);
6206 if (wcd9xxx->mclk_rate == TAIKO_MCLK_CLK_12P288MHZ)
Venkat Sudhir16d95e62013-02-04 16:57:33 -08006207 snd_soc_update_bits(codec, TAIKO_A_CHIP_CTL, 0x06, 0x0);
Venkat Sudhira50a3762012-11-26 12:12:15 -08006208 else if (wcd9xxx->mclk_rate == TAIKO_MCLK_CLK_9P6HZ)
Venkat Sudhir16d95e62013-02-04 16:57:33 -08006209 snd_soc_update_bits(codec, TAIKO_A_CHIP_CTL, 0x06, 0x2);
Kiran Kandic3b24402012-06-11 00:05:59 -07006210 taiko_codec_init_reg(codec);
6211 ret = taiko_handle_pdata(taiko);
6212 if (IS_ERR_VALUE(ret)) {
6213 pr_err("%s: bad pdata\n", __func__);
6214 goto err_pdata;
6215 }
6216
Joonwoo Park448a8fc2013-04-10 15:25:58 -07006217 taiko->spkdrv_reg = taiko_codec_find_regulator(codec,
6218 WCD9XXX_VDD_SPKDRV_NAME);
6219
Joonwoo Park125cd4e2012-12-11 15:16:11 -08006220 if (spkr_drv_wrnd > 0) {
6221 WCD9XXX_BCL_LOCK(&taiko->resmgr);
6222 wcd9xxx_resmgr_get_bandgap(&taiko->resmgr,
6223 WCD9XXX_BANDGAP_AUDIO_MODE);
6224 WCD9XXX_BCL_UNLOCK(&taiko->resmgr);
6225 }
6226
Kuirong Wang906ac472012-07-09 12:54:44 -07006227 ptr = kmalloc((sizeof(taiko_rx_chs) +
6228 sizeof(taiko_tx_chs)), GFP_KERNEL);
6229 if (!ptr) {
6230 pr_err("%s: no mem for slim chan ctl data\n", __func__);
6231 ret = -ENOMEM;
6232 goto err_nomem_slimch;
6233 }
6234
Kiran Kandic3b24402012-06-11 00:05:59 -07006235 if (taiko->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) {
6236 snd_soc_dapm_new_controls(dapm, taiko_dapm_i2s_widgets,
6237 ARRAY_SIZE(taiko_dapm_i2s_widgets));
6238 snd_soc_dapm_add_routes(dapm, audio_i2s_map,
6239 ARRAY_SIZE(audio_i2s_map));
Joonwoo Park559a5bf2013-02-15 14:46:36 -08006240 if (TAIKO_IS_1_0(core->version))
6241 snd_soc_dapm_add_routes(dapm, audio_i2s_map_1_0,
6242 ARRAY_SIZE(audio_i2s_map_1_0));
6243 else
6244 snd_soc_dapm_add_routes(dapm, audio_i2s_map_2_0,
6245 ARRAY_SIZE(audio_i2s_map_2_0));
Kuirong Wang906ac472012-07-09 12:54:44 -07006246 for (i = 0; i < ARRAY_SIZE(taiko_i2s_dai); i++)
6247 INIT_LIST_HEAD(&taiko->dai[i].wcd9xxx_ch_list);
6248 } else if (taiko->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) {
6249 for (i = 0; i < NUM_CODEC_DAIS; i++) {
6250 INIT_LIST_HEAD(&taiko->dai[i].wcd9xxx_ch_list);
6251 init_waitqueue_head(&taiko->dai[i].dai_wait);
6252 }
Joonwoo Park1d05bb92013-03-07 16:55:06 -08006253 taiko_slimbus_slave_port_cfg.slave_dev_intfdev_la =
6254 control->slim_slave->laddr;
6255 taiko_slimbus_slave_port_cfg.slave_dev_pgd_la =
6256 control->slim->laddr;
6257 taiko_slimbus_slave_port_cfg.slave_port_mapping[0] =
6258 TAIKO_MAD_SLIMBUS_TX_PORT;
6259
6260 taiko_init_slim_slave_cfg(codec);
Kiran Kandic3b24402012-06-11 00:05:59 -07006261 }
6262
Kiran Kandiec0db5c2013-03-08 16:03:58 -08006263 if (TAIKO_IS_1_0(control->version)) {
Joonwoo Park2a9170a2013-03-04 17:05:57 -08006264 snd_soc_dapm_new_controls(dapm, taiko_1_dapm_widgets,
6265 ARRAY_SIZE(taiko_1_dapm_widgets));
Kiran Kandiec0db5c2013-03-08 16:03:58 -08006266 snd_soc_add_codec_controls(codec,
6267 taiko_1_x_analog_gain_controls,
6268 ARRAY_SIZE(taiko_1_x_analog_gain_controls));
6269 } else {
Joonwoo Park2a9170a2013-03-04 17:05:57 -08006270 snd_soc_dapm_new_controls(dapm, taiko_2_dapm_widgets,
6271 ARRAY_SIZE(taiko_2_dapm_widgets));
Kiran Kandiec0db5c2013-03-08 16:03:58 -08006272 snd_soc_add_codec_controls(codec,
6273 taiko_2_x_analog_gain_controls,
6274 ARRAY_SIZE(taiko_2_x_analog_gain_controls));
6275 }
Joonwoo Park2a9170a2013-03-04 17:05:57 -08006276
Kuirong Wang906ac472012-07-09 12:54:44 -07006277 control->num_rx_port = TAIKO_RX_MAX;
6278 control->rx_chs = ptr;
6279 memcpy(control->rx_chs, taiko_rx_chs, sizeof(taiko_rx_chs));
6280 control->num_tx_port = TAIKO_TX_MAX;
6281 control->tx_chs = ptr + sizeof(taiko_rx_chs);
6282 memcpy(control->tx_chs, taiko_tx_chs, sizeof(taiko_tx_chs));
6283
Kiran Kandic3b24402012-06-11 00:05:59 -07006284 snd_soc_dapm_sync(dapm);
6285
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07006286 ret = taiko_setup_irqs(taiko);
6287 if (ret) {
6288 pr_err("%s: taiko irq setup failed %d\n", __func__, ret);
6289 goto err_irq;
6290 }
Kiran Kandic3b24402012-06-11 00:05:59 -07006291
Joonwoo Park125cd4e2012-12-11 15:16:11 -08006292 atomic_set(&kp_taiko_priv, (unsigned long)taiko);
Damir Didjusto2cb06bd2013-01-30 23:14:55 -08006293 mutex_lock(&dapm->codec->mutex);
6294 snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
6295 snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
6296 snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE");
6297 snd_soc_dapm_disable_pin(dapm, "ANC EAR PA");
6298 snd_soc_dapm_disable_pin(dapm, "ANC EAR");
6299 snd_soc_dapm_sync(dapm);
6300 mutex_unlock(&dapm->codec->mutex);
Joonwoo Park125cd4e2012-12-11 15:16:11 -08006301
Kiran Kandic3b24402012-06-11 00:05:59 -07006302 codec->ignore_pmdown_time = 1;
6303 return ret;
6304
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07006305err_irq:
6306 taiko_cleanup_irqs(taiko);
Kiran Kandic3b24402012-06-11 00:05:59 -07006307err_pdata:
Kuirong Wang906ac472012-07-09 12:54:44 -07006308 kfree(ptr);
6309err_nomem_slimch:
Kiran Kandic3b24402012-06-11 00:05:59 -07006310 kfree(taiko);
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07006311err_init:
Kiran Kandic3b24402012-06-11 00:05:59 -07006312 return ret;
6313}
6314static int taiko_codec_remove(struct snd_soc_codec *codec)
6315{
Kiran Kandic3b24402012-06-11 00:05:59 -07006316 struct taiko_priv *taiko = snd_soc_codec_get_drvdata(codec);
Joonwoo Parka8890262012-10-15 12:04:27 -07006317
Joonwoo Park125cd4e2012-12-11 15:16:11 -08006318 WCD9XXX_BCL_LOCK(&taiko->resmgr);
6319 atomic_set(&kp_taiko_priv, 0);
6320
6321 if (spkr_drv_wrnd > 0)
6322 wcd9xxx_resmgr_put_bandgap(&taiko->resmgr,
6323 WCD9XXX_BANDGAP_AUDIO_MODE);
6324 WCD9XXX_BCL_UNLOCK(&taiko->resmgr);
6325
Ravishankar Sarawadi7b700362013-04-18 15:56:02 -07006326 taiko_cleanup_irqs(taiko);
6327
Joonwoo Parka8890262012-10-15 12:04:27 -07006328 /* cleanup MBHC */
6329 wcd9xxx_mbhc_deinit(&taiko->mbhc);
6330 /* cleanup resmgr */
6331 wcd9xxx_resmgr_deinit(&taiko->resmgr);
6332
Joonwoo Park448a8fc2013-04-10 15:25:58 -07006333 taiko->spkdrv_reg = NULL;
6334
Kiran Kandic3b24402012-06-11 00:05:59 -07006335 kfree(taiko);
6336 return 0;
6337}
6338static struct snd_soc_codec_driver soc_codec_dev_taiko = {
6339 .probe = taiko_codec_probe,
6340 .remove = taiko_codec_remove,
6341
6342 .read = taiko_read,
6343 .write = taiko_write,
6344
6345 .readable_register = taiko_readable,
6346 .volatile_register = taiko_volatile,
6347
6348 .reg_cache_size = TAIKO_CACHE_SIZE,
Kiran Kandi7b7d2ff2012-09-14 14:52:14 -07006349 .reg_cache_default = taiko_reset_reg_defaults,
Kiran Kandic3b24402012-06-11 00:05:59 -07006350 .reg_word_size = 1,
6351
6352 .controls = taiko_snd_controls,
6353 .num_controls = ARRAY_SIZE(taiko_snd_controls),
6354 .dapm_widgets = taiko_dapm_widgets,
6355 .num_dapm_widgets = ARRAY_SIZE(taiko_dapm_widgets),
6356 .dapm_routes = audio_map,
6357 .num_dapm_routes = ARRAY_SIZE(audio_map),
6358};
6359
6360#ifdef CONFIG_PM
6361static int taiko_suspend(struct device *dev)
6362{
6363 dev_dbg(dev, "%s: system suspend\n", __func__);
6364 return 0;
6365}
6366
6367static int taiko_resume(struct device *dev)
6368{
6369 struct platform_device *pdev = to_platform_device(dev);
6370 struct taiko_priv *taiko = platform_get_drvdata(pdev);
6371 dev_dbg(dev, "%s: system resume\n", __func__);
Joonwoo Parka8890262012-10-15 12:04:27 -07006372 /* Notify */
6373 wcd9xxx_resmgr_notifier_call(&taiko->resmgr, WCD9XXX_EVENT_POST_RESUME);
Kiran Kandic3b24402012-06-11 00:05:59 -07006374 return 0;
6375}
6376
6377static const struct dev_pm_ops taiko_pm_ops = {
6378 .suspend = taiko_suspend,
6379 .resume = taiko_resume,
6380};
6381#endif
6382
6383static int __devinit taiko_probe(struct platform_device *pdev)
6384{
6385 int ret = 0;
6386 if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS)
6387 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_taiko,
6388 taiko_dai, ARRAY_SIZE(taiko_dai));
6389 else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C)
6390 ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_taiko,
6391 taiko_i2s_dai, ARRAY_SIZE(taiko_i2s_dai));
6392 return ret;
6393}
6394static int __devexit taiko_remove(struct platform_device *pdev)
6395{
6396 snd_soc_unregister_codec(&pdev->dev);
6397 return 0;
6398}
6399static struct platform_driver taiko_codec_driver = {
6400 .probe = taiko_probe,
6401 .remove = taiko_remove,
6402 .driver = {
6403 .name = "taiko_codec",
6404 .owner = THIS_MODULE,
6405#ifdef CONFIG_PM
6406 .pm = &taiko_pm_ops,
6407#endif
6408 },
6409};
6410
6411static int __init taiko_codec_init(void)
6412{
6413 return platform_driver_register(&taiko_codec_driver);
6414}
6415
6416static void __exit taiko_codec_exit(void)
6417{
6418 platform_driver_unregister(&taiko_codec_driver);
6419}
6420
6421module_init(taiko_codec_init);
6422module_exit(taiko_codec_exit);
6423
6424MODULE_DESCRIPTION("Taiko codec driver");
6425MODULE_LICENSE("GPL v2");