1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
3 // Copyright (c) 2017-2018, Linaro Limited
5 #include <linux/module.h>
6 #include <linux/init.h>
7 #include <linux/platform_device.h>
8 #include <linux/device.h>
9 #include <linux/wait.h>
10 #include <linux/bitops.h>
11 #include <linux/regulator/consumer.h>
12 #include <linux/clk.h>
13 #include <linux/delay.h>
14 #include <linux/kernel.h>
15 #include <linux/slimbus.h>
16 #include <sound/soc.h>
17 #include <sound/pcm_params.h>
18 #include <sound/soc-dapm.h>
19 #include <linux/of_gpio.h>
21 #include <linux/of_irq.h>
22 #include <sound/tlv.h>
23 #include <sound/info.h>
25 #include "wcd-clsh-v2.h"
27 #define WCD9335_RATES_MASK (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
28 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
29 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
30 /* Fractional Rates */
31 #define WCD9335_FRAC_RATES_MASK (SNDRV_PCM_RATE_44100)
32 #define WCD9335_FORMATS_S16_S24_LE (SNDRV_PCM_FMTBIT_S16_LE | \
33 SNDRV_PCM_FMTBIT_S24_LE)
35 /* slave port water mark level
36 * (0: 6bytes, 1: 9bytes, 2: 12 bytes, 3: 15 bytes)
38 #define SLAVE_PORT_WATER_MARK_6BYTES 0
39 #define SLAVE_PORT_WATER_MARK_9BYTES 1
40 #define SLAVE_PORT_WATER_MARK_12BYTES 2
41 #define SLAVE_PORT_WATER_MARK_15BYTES 3
42 #define SLAVE_PORT_WATER_MARK_SHIFT 1
43 #define SLAVE_PORT_ENABLE 1
44 #define SLAVE_PORT_DISABLE 0
45 #define WCD9335_SLIM_WATER_MARK_VAL \
46 ((SLAVE_PORT_WATER_MARK_12BYTES << SLAVE_PORT_WATER_MARK_SHIFT) | \
49 #define WCD9335_SLIM_NUM_PORT_REG 3
50 #define WCD9335_SLIM_PGD_PORT_INT_TX_EN0 (WCD9335_SLIM_PGD_PORT_INT_EN0 + 2)
52 #define WCD9335_MCLK_CLK_12P288MHZ 12288000
53 #define WCD9335_MCLK_CLK_9P6MHZ 9600000
55 #define WCD9335_SLIM_CLOSE_TIMEOUT 1000
56 #define WCD9335_SLIM_IRQ_OVERFLOW (1 << 0)
57 #define WCD9335_SLIM_IRQ_UNDERFLOW (1 << 1)
58 #define WCD9335_SLIM_IRQ_PORT_CLOSED (1 << 2)
60 #define WCD9335_NUM_INTERPOLATORS 9
61 #define WCD9335_RX_START 16
62 #define WCD9335_SLIM_CH_START 128
63 #define WCD9335_MAX_MICBIAS 4
64 #define WCD9335_MAX_VALID_ADC_MUX 13
65 #define WCD9335_INVALID_ADC_MUX 9
67 #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
68 #define CF_MIN_3DB_4HZ 0x0
69 #define CF_MIN_3DB_75HZ 0x1
70 #define CF_MIN_3DB_150HZ 0x2
71 #define WCD9335_DMIC_CLK_DIV_2 0x0
72 #define WCD9335_DMIC_CLK_DIV_3 0x1
73 #define WCD9335_DMIC_CLK_DIV_4 0x2
74 #define WCD9335_DMIC_CLK_DIV_6 0x3
75 #define WCD9335_DMIC_CLK_DIV_8 0x4
76 #define WCD9335_DMIC_CLK_DIV_16 0x5
77 #define WCD9335_DMIC_CLK_DRIVE_DEFAULT 0x02
78 #define WCD9335_AMIC_PWR_LEVEL_LP 0
79 #define WCD9335_AMIC_PWR_LEVEL_DEFAULT 1
80 #define WCD9335_AMIC_PWR_LEVEL_HP 2
81 #define WCD9335_AMIC_PWR_LVL_MASK 0x60
82 #define WCD9335_AMIC_PWR_LVL_SHIFT 0x5
84 #define WCD9335_DEC_PWR_LVL_MASK 0x06
85 #define WCD9335_DEC_PWR_LVL_LP 0x02
86 #define WCD9335_DEC_PWR_LVL_HP 0x04
87 #define WCD9335_DEC_PWR_LVL_DF 0x00
89 #define WCD9335_SLIM_RX_CH(p) \
90 {.port = p + WCD9335_RX_START, .shift = p,}
92 #define WCD9335_SLIM_TX_CH(p) \
93 {.port = p, .shift = p,}
96 #define WCD9335_CALCULATE_VOUT_D(req_mv) (((req_mv - 650) * 10) / 25)
98 #define WCD9335_INTERPOLATOR_PATH(id) \
99 {"RX INT" #id "_1 MIX1 INP0", "RX0", "SLIM RX0"}, \
100 {"RX INT" #id "_1 MIX1 INP0", "RX1", "SLIM RX1"}, \
101 {"RX INT" #id "_1 MIX1 INP0", "RX2", "SLIM RX2"}, \
102 {"RX INT" #id "_1 MIX1 INP0", "RX3", "SLIM RX3"}, \
103 {"RX INT" #id "_1 MIX1 INP0", "RX4", "SLIM RX4"}, \
104 {"RX INT" #id "_1 MIX1 INP0", "RX5", "SLIM RX5"}, \
105 {"RX INT" #id "_1 MIX1 INP0", "RX6", "SLIM RX6"}, \
106 {"RX INT" #id "_1 MIX1 INP0", "RX7", "SLIM RX7"}, \
107 {"RX INT" #id "_1 MIX1 INP1", "RX0", "SLIM RX0"}, \
108 {"RX INT" #id "_1 MIX1 INP1", "RX1", "SLIM RX1"}, \
109 {"RX INT" #id "_1 MIX1 INP1", "RX2", "SLIM RX2"}, \
110 {"RX INT" #id "_1 MIX1 INP1", "RX3", "SLIM RX3"}, \
111 {"RX INT" #id "_1 MIX1 INP1", "RX4", "SLIM RX4"}, \
112 {"RX INT" #id "_1 MIX1 INP1", "RX5", "SLIM RX5"}, \
113 {"RX INT" #id "_1 MIX1 INP1", "RX6", "SLIM RX6"}, \
114 {"RX INT" #id "_1 MIX1 INP1", "RX7", "SLIM RX7"}, \
115 {"RX INT" #id "_1 MIX1 INP2", "RX0", "SLIM RX0"}, \
116 {"RX INT" #id "_1 MIX1 INP2", "RX1", "SLIM RX1"}, \
117 {"RX INT" #id "_1 MIX1 INP2", "RX2", "SLIM RX2"}, \
118 {"RX INT" #id "_1 MIX1 INP2", "RX3", "SLIM RX3"}, \
119 {"RX INT" #id "_1 MIX1 INP2", "RX4", "SLIM RX4"}, \
120 {"RX INT" #id "_1 MIX1 INP2", "RX5", "SLIM RX5"}, \
121 {"RX INT" #id "_1 MIX1 INP2", "RX6", "SLIM RX6"}, \
122 {"RX INT" #id "_1 MIX1 INP2", "RX7", "SLIM RX7"}, \
123 {"RX INT" #id "_2 MUX", "RX0", "SLIM RX0"}, \
124 {"RX INT" #id "_2 MUX", "RX1", "SLIM RX1"}, \
125 {"RX INT" #id "_2 MUX", "RX2", "SLIM RX2"}, \
126 {"RX INT" #id "_2 MUX", "RX3", "SLIM RX3"}, \
127 {"RX INT" #id "_2 MUX", "RX4", "SLIM RX4"}, \
128 {"RX INT" #id "_2 MUX", "RX5", "SLIM RX5"}, \
129 {"RX INT" #id "_2 MUX", "RX6", "SLIM RX6"}, \
130 {"RX INT" #id "_2 MUX", "RX7", "SLIM RX7"}, \
131 {"RX INT" #id "_1 MIX1", NULL, "RX INT" #id "_1 MIX1 INP0"}, \
132 {"RX INT" #id "_1 MIX1", NULL, "RX INT" #id "_1 MIX1 INP1"}, \
133 {"RX INT" #id "_1 MIX1", NULL, "RX INT" #id "_1 MIX1 INP2"}, \
134 {"RX INT" #id " SEC MIX", NULL, "RX INT" #id "_2 MUX"}, \
135 {"RX INT" #id " SEC MIX", NULL, "RX INT" #id "_1 MIX1"}, \
136 {"RX INT" #id " MIX2", NULL, "RX INT" #id " SEC MIX"}, \
137 {"RX INT" #id " INTERP", NULL, "RX INT" #id " MIX2"}
139 #define WCD9335_ADC_MUX_PATH(id) \
140 {"AIF1_CAP Mixer", "SLIM TX" #id, "SLIM TX" #id " MUX"}, \
141 {"AIF2_CAP Mixer", "SLIM TX" #id, "SLIM TX" #id " MUX"}, \
142 {"AIF3_CAP Mixer", "SLIM TX" #id, "SLIM TX" #id " MUX"}, \
143 {"SLIM TX" #id " MUX", "DEC" #id, "ADC MUX" #id}, \
144 {"ADC MUX" #id, "DMIC", "DMIC MUX" #id}, \
145 {"ADC MUX" #id, "AMIC", "AMIC MUX" #id}, \
146 {"DMIC MUX" #id, "DMIC0", "DMIC0"}, \
147 {"DMIC MUX" #id, "DMIC1", "DMIC1"}, \
148 {"DMIC MUX" #id, "DMIC2", "DMIC2"}, \
149 {"DMIC MUX" #id, "DMIC3", "DMIC3"}, \
150 {"DMIC MUX" #id, "DMIC4", "DMIC4"}, \
151 {"DMIC MUX" #id, "DMIC5", "DMIC5"}, \
152 {"AMIC MUX" #id, "ADC1", "ADC1"}, \
153 {"AMIC MUX" #id, "ADC2", "ADC2"}, \
154 {"AMIC MUX" #id, "ADC3", "ADC3"}, \
155 {"AMIC MUX" #id, "ADC4", "ADC4"}, \
156 {"AMIC MUX" #id, "ADC5", "ADC5"}, \
157 {"AMIC MUX" #id, "ADC6", "ADC6"}
197 SIDO_SOURCE_INTERNAL
= 0,
201 enum wcd9335_sido_voltage
{
202 SIDO_VOLTAGE_SVS_MV
= 950,
203 SIDO_VOLTAGE_NOMINAL_MV
= 1100,
218 COMPANDER_1
, /* HPH_L */
219 COMPANDER_2
, /* HPH_R */
220 COMPANDER_3
, /* LO1_DIFF */
221 COMPANDER_4
, /* LO2_DIFF */
222 COMPANDER_5
, /* LO3_SE */
223 COMPANDER_6
, /* LO4_SE */
224 COMPANDER_7
, /* SWR SPK CH1 */
225 COMPANDER_8
, /* SWR SPK CH2 */
230 INTn_2_INP_SEL_ZERO
= 0,
239 INTn_2_INP_SEL_PROXIMITY
,
243 INTn_1_MIX_INP_SEL_ZERO
= 0,
244 INTn_1_MIX_INP_SEL_DEC0
,
245 INTn_1_MIX_INP_SEL_DEC1
,
246 INTn_1_MIX_INP_SEL_IIR0
,
247 INTn_1_MIX_INP_SEL_IIR1
,
248 INTn_1_MIX_INP_SEL_RX0
,
249 INTn_1_MIX_INP_SEL_RX1
,
250 INTn_1_MIX_INP_SEL_RX2
,
251 INTn_1_MIX_INP_SEL_RX3
,
252 INTn_1_MIX_INP_SEL_RX4
,
253 INTn_1_MIX_INP_SEL_RX5
,
254 INTn_1_MIX_INP_SEL_RX6
,
255 INTn_1_MIX_INP_SEL_RX7
,
271 enum wcd_clock_type
{
291 struct wcd9335_slim_ch
{
295 struct list_head list
;
298 struct wcd_slim_codec_dai_data
{
299 struct list_head slim_ch_list
;
300 struct slim_stream_config sconfig
;
301 struct slim_stream_runtime
*sruntime
;
304 struct wcd9335_codec
{
307 struct clk
*native_clk
;
311 struct slim_device
*slim
;
312 struct slim_device
*slim_ifc_dev
;
313 struct regmap
*regmap
;
314 struct regmap
*if_regmap
;
315 struct regmap_irq_chip_data
*irq_data
;
317 struct wcd9335_slim_ch rx_chs
[WCD9335_RX_MAX
];
318 struct wcd9335_slim_ch tx_chs
[WCD9335_TX_MAX
];
323 enum wcd9335_sido_voltage sido_voltage
;
325 struct wcd_slim_codec_dai_data dai
[NUM_CODEC_DAIS
];
326 struct snd_soc_component
*component
;
328 int master_bias_users
;
332 enum wcd_clock_type clk_type
;
334 struct wcd_clsh_ctrl
*clsh_ctrl
;
336 int prim_int_users
[WCD9335_NUM_INTERPOLATORS
];
338 int comp_enabled
[COMPANDER_MAX
];
342 struct regulator_bulk_data supplies
[WCD9335_MAX_SUPPLY
];
344 unsigned int rx_port_value
;
345 unsigned int tx_port_value
;
351 int micb_ref
[WCD9335_MAX_MICBIAS
];
352 int pullup_ref
[WCD9335_MAX_MICBIAS
];
354 int dmic_0_1_clk_cnt
;
355 int dmic_2_3_clk_cnt
;
356 int dmic_4_5_clk_cnt
;
357 int dmic_sample_rate
;
358 int mad_dmic_sample_rate
;
360 int native_clk_users
;
365 irqreturn_t (*handler
)(int irq
, void *data
);
369 static const struct wcd9335_slim_ch wcd9335_tx_chs
[WCD9335_TX_MAX
] = {
370 WCD9335_SLIM_TX_CH(0),
371 WCD9335_SLIM_TX_CH(1),
372 WCD9335_SLIM_TX_CH(2),
373 WCD9335_SLIM_TX_CH(3),
374 WCD9335_SLIM_TX_CH(4),
375 WCD9335_SLIM_TX_CH(5),
376 WCD9335_SLIM_TX_CH(6),
377 WCD9335_SLIM_TX_CH(7),
378 WCD9335_SLIM_TX_CH(8),
379 WCD9335_SLIM_TX_CH(9),
380 WCD9335_SLIM_TX_CH(10),
381 WCD9335_SLIM_TX_CH(11),
382 WCD9335_SLIM_TX_CH(12),
383 WCD9335_SLIM_TX_CH(13),
384 WCD9335_SLIM_TX_CH(14),
385 WCD9335_SLIM_TX_CH(15),
388 static const struct wcd9335_slim_ch wcd9335_rx_chs
[WCD9335_RX_MAX
] = {
389 WCD9335_SLIM_RX_CH(0), /* 16 */
390 WCD9335_SLIM_RX_CH(1), /* 17 */
391 WCD9335_SLIM_RX_CH(2),
392 WCD9335_SLIM_RX_CH(3),
393 WCD9335_SLIM_RX_CH(4),
394 WCD9335_SLIM_RX_CH(5),
395 WCD9335_SLIM_RX_CH(6),
396 WCD9335_SLIM_RX_CH(7),
397 WCD9335_SLIM_RX_CH(8),
398 WCD9335_SLIM_RX_CH(9),
399 WCD9335_SLIM_RX_CH(10),
400 WCD9335_SLIM_RX_CH(11),
401 WCD9335_SLIM_RX_CH(12),
404 struct interp_sample_rate
{
409 static struct interp_sample_rate int_mix_rate_val
[] = {
410 {48000, 0x4}, /* 48K */
411 {96000, 0x5}, /* 96K */
412 {192000, 0x6}, /* 192K */
415 static struct interp_sample_rate int_prim_rate_val
[] = {
416 {8000, 0x0}, /* 8K */
417 {16000, 0x1}, /* 16K */
418 {24000, -EINVAL
},/* 24K */
419 {32000, 0x3}, /* 32K */
420 {48000, 0x4}, /* 48K */
421 {96000, 0x5}, /* 96K */
422 {192000, 0x6}, /* 192K */
423 {384000, 0x7}, /* 384K */
424 {44100, 0x8}, /* 44.1K */
427 struct wcd9335_reg_mask_val
{
433 static const struct wcd9335_reg_mask_val wcd9335_codec_reg_init
[] = {
434 /* Rbuckfly/R_EAR(32) */
435 {WCD9335_CDC_CLSH_K2_MSB
, 0x0F, 0x00},
436 {WCD9335_CDC_CLSH_K2_LSB
, 0xFF, 0x60},
437 {WCD9335_CPE_SS_DMIC_CFG
, 0x80, 0x00},
438 {WCD9335_CDC_BOOST0_BOOST_CTL
, 0x70, 0x50},
439 {WCD9335_CDC_BOOST1_BOOST_CTL
, 0x70, 0x50},
440 {WCD9335_CDC_RX7_RX_PATH_CFG1
, 0x08, 0x08},
441 {WCD9335_CDC_RX8_RX_PATH_CFG1
, 0x08, 0x08},
442 {WCD9335_ANA_LO_1_2
, 0x3C, 0X3C},
443 {WCD9335_DIFF_LO_COM_SWCAP_REFBUF_FREQ
, 0x70, 0x00},
444 {WCD9335_DIFF_LO_COM_PA_FREQ
, 0x70, 0x40},
445 {WCD9335_SOC_MAD_AUDIO_CTL_2
, 0x03, 0x03},
446 {WCD9335_CDC_TOP_TOP_CFG1
, 0x02, 0x02},
447 {WCD9335_CDC_TOP_TOP_CFG1
, 0x01, 0x01},
448 {WCD9335_EAR_CMBUFF
, 0x08, 0x00},
449 {WCD9335_CDC_TX9_SPKR_PROT_PATH_CFG0
, 0x01, 0x01},
450 {WCD9335_CDC_TX10_SPKR_PROT_PATH_CFG0
, 0x01, 0x01},
451 {WCD9335_CDC_TX11_SPKR_PROT_PATH_CFG0
, 0x01, 0x01},
452 {WCD9335_CDC_TX12_SPKR_PROT_PATH_CFG0
, 0x01, 0x01},
453 {WCD9335_CDC_COMPANDER7_CTL3
, 0x80, 0x80},
454 {WCD9335_CDC_COMPANDER8_CTL3
, 0x80, 0x80},
455 {WCD9335_CDC_COMPANDER7_CTL7
, 0x01, 0x01},
456 {WCD9335_CDC_COMPANDER8_CTL7
, 0x01, 0x01},
457 {WCD9335_CDC_RX0_RX_PATH_CFG0
, 0x01, 0x01},
458 {WCD9335_CDC_RX1_RX_PATH_CFG0
, 0x01, 0x01},
459 {WCD9335_CDC_RX2_RX_PATH_CFG0
, 0x01, 0x01},
460 {WCD9335_CDC_RX3_RX_PATH_CFG0
, 0x01, 0x01},
461 {WCD9335_CDC_RX4_RX_PATH_CFG0
, 0x01, 0x01},
462 {WCD9335_CDC_RX5_RX_PATH_CFG0
, 0x01, 0x01},
463 {WCD9335_CDC_RX6_RX_PATH_CFG0
, 0x01, 0x01},
464 {WCD9335_CDC_RX7_RX_PATH_CFG0
, 0x01, 0x01},
465 {WCD9335_CDC_RX8_RX_PATH_CFG0
, 0x01, 0x01},
466 {WCD9335_CDC_RX0_RX_PATH_MIX_CFG
, 0x01, 0x01},
467 {WCD9335_CDC_RX1_RX_PATH_MIX_CFG
, 0x01, 0x01},
468 {WCD9335_CDC_RX2_RX_PATH_MIX_CFG
, 0x01, 0x01},
469 {WCD9335_CDC_RX3_RX_PATH_MIX_CFG
, 0x01, 0x01},
470 {WCD9335_CDC_RX4_RX_PATH_MIX_CFG
, 0x01, 0x01},
471 {WCD9335_CDC_RX5_RX_PATH_MIX_CFG
, 0x01, 0x01},
472 {WCD9335_CDC_RX6_RX_PATH_MIX_CFG
, 0x01, 0x01},
473 {WCD9335_CDC_RX7_RX_PATH_MIX_CFG
, 0x01, 0x01},
474 {WCD9335_CDC_RX8_RX_PATH_MIX_CFG
, 0x01, 0x01},
475 {WCD9335_VBADC_IBIAS_FE
, 0x0C, 0x08},
476 {WCD9335_RCO_CTRL_2
, 0x0F, 0x08},
477 {WCD9335_RX_BIAS_FLYB_MID_RST
, 0xF0, 0x10},
478 {WCD9335_FLYBACK_CTRL_1
, 0x20, 0x20},
479 {WCD9335_HPH_OCP_CTL
, 0xFF, 0x5A},
480 {WCD9335_HPH_L_TEST
, 0x01, 0x01},
481 {WCD9335_HPH_R_TEST
, 0x01, 0x01},
482 {WCD9335_CDC_BOOST0_BOOST_CFG1
, 0x3F, 0x12},
483 {WCD9335_CDC_BOOST0_BOOST_CFG2
, 0x1C, 0x08},
484 {WCD9335_CDC_COMPANDER7_CTL7
, 0x1E, 0x18},
485 {WCD9335_CDC_BOOST1_BOOST_CFG1
, 0x3F, 0x12},
486 {WCD9335_CDC_BOOST1_BOOST_CFG2
, 0x1C, 0x08},
487 {WCD9335_CDC_COMPANDER8_CTL7
, 0x1E, 0x18},
488 {WCD9335_CDC_TX0_TX_PATH_SEC7
, 0xFF, 0x45},
489 {WCD9335_CDC_RX0_RX_PATH_SEC0
, 0xFC, 0xF4},
490 {WCD9335_HPH_REFBUFF_LP_CTL
, 0x08, 0x08},
491 {WCD9335_HPH_REFBUFF_LP_CTL
, 0x06, 0x02},
494 /* Cutoff frequency for high pass filter */
495 static const char * const cf_text
[] = {
496 "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ"
499 static const char * const rx_cf_text
[] = {
500 "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ",
504 static const char * const rx_int0_7_mix_mux_text
[] = {
505 "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5",
506 "RX6", "RX7", "PROXIMITY"
509 static const char * const rx_int_mix_mux_text
[] = {
510 "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5",
514 static const char * const rx_prim_mix_text
[] = {
515 "ZERO", "DEC0", "DEC1", "IIR0", "IIR1", "RX0", "RX1", "RX2",
516 "RX3", "RX4", "RX5", "RX6", "RX7"
519 static const char * const rx_int_dem_inp_mux_text
[] = {
520 "NORMAL_DSM_OUT", "CLSH_DSM_OUT",
523 static const char * const rx_int0_interp_mux_text
[] = {
524 "ZERO", "RX INT0 MIX2",
527 static const char * const rx_int1_interp_mux_text
[] = {
528 "ZERO", "RX INT1 MIX2",
531 static const char * const rx_int2_interp_mux_text
[] = {
532 "ZERO", "RX INT2 MIX2",
535 static const char * const rx_int3_interp_mux_text
[] = {
536 "ZERO", "RX INT3 MIX2",
539 static const char * const rx_int4_interp_mux_text
[] = {
540 "ZERO", "RX INT4 MIX2",
543 static const char * const rx_int5_interp_mux_text
[] = {
544 "ZERO", "RX INT5 MIX2",
547 static const char * const rx_int6_interp_mux_text
[] = {
548 "ZERO", "RX INT6 MIX2",
551 static const char * const rx_int7_interp_mux_text
[] = {
552 "ZERO", "RX INT7 MIX2",
555 static const char * const rx_int8_interp_mux_text
[] = {
556 "ZERO", "RX INT8 SEC MIX"
559 static const char * const rx_hph_mode_mux_text
[] = {
560 "Class H Invalid", "Class-H Hi-Fi", "Class-H Low Power", "Class-AB",
561 "Class-H Hi-Fi Low Power"
564 static const char *const slim_rx_mux_text
[] = {
565 "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB", "AIF4_PB",
568 static const char * const adc_mux_text
[] = {
569 "DMIC", "AMIC", "ANC_FB_TUNE1", "ANC_FB_TUNE2"
572 static const char * const dmic_mux_text
[] = {
573 "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5",
574 "SMIC0", "SMIC1", "SMIC2", "SMIC3"
577 static const char * const dmic_mux_alt_text
[] = {
578 "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5",
581 static const char * const amic_mux_text
[] = {
582 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6"
585 static const char * const sb_tx0_mux_text
[] = {
586 "ZERO", "RX_MIX_TX0", "DEC0", "DEC0_192"
589 static const char * const sb_tx1_mux_text
[] = {
590 "ZERO", "RX_MIX_TX1", "DEC1", "DEC1_192"
593 static const char * const sb_tx2_mux_text
[] = {
594 "ZERO", "RX_MIX_TX2", "DEC2", "DEC2_192"
597 static const char * const sb_tx3_mux_text
[] = {
598 "ZERO", "RX_MIX_TX3", "DEC3", "DEC3_192"
601 static const char * const sb_tx4_mux_text
[] = {
602 "ZERO", "RX_MIX_TX4", "DEC4", "DEC4_192"
605 static const char * const sb_tx5_mux_text
[] = {
606 "ZERO", "RX_MIX_TX5", "DEC5", "DEC5_192"
609 static const char * const sb_tx6_mux_text
[] = {
610 "ZERO", "RX_MIX_TX6", "DEC6", "DEC6_192"
613 static const char * const sb_tx7_mux_text
[] = {
614 "ZERO", "RX_MIX_TX7", "DEC7", "DEC7_192"
617 static const char * const sb_tx8_mux_text
[] = {
618 "ZERO", "RX_MIX_TX8", "DEC8", "DEC8_192"
621 static const DECLARE_TLV_DB_SCALE(digital_gain
, 0, 1, 0);
622 static const DECLARE_TLV_DB_SCALE(line_gain
, 0, 7, 1);
623 static const DECLARE_TLV_DB_SCALE(analog_gain
, 0, 25, 1);
624 static const DECLARE_TLV_DB_SCALE(ear_pa_gain
, 0, 150, 0);
626 static const struct soc_enum cf_dec0_enum
=
627 SOC_ENUM_SINGLE(WCD9335_CDC_TX0_TX_PATH_CFG0
, 5, 3, cf_text
);
629 static const struct soc_enum cf_dec1_enum
=
630 SOC_ENUM_SINGLE(WCD9335_CDC_TX1_TX_PATH_CFG0
, 5, 3, cf_text
);
632 static const struct soc_enum cf_dec2_enum
=
633 SOC_ENUM_SINGLE(WCD9335_CDC_TX2_TX_PATH_CFG0
, 5, 3, cf_text
);
635 static const struct soc_enum cf_dec3_enum
=
636 SOC_ENUM_SINGLE(WCD9335_CDC_TX3_TX_PATH_CFG0
, 5, 3, cf_text
);
638 static const struct soc_enum cf_dec4_enum
=
639 SOC_ENUM_SINGLE(WCD9335_CDC_TX4_TX_PATH_CFG0
, 5, 3, cf_text
);
641 static const struct soc_enum cf_dec5_enum
=
642 SOC_ENUM_SINGLE(WCD9335_CDC_TX5_TX_PATH_CFG0
, 5, 3, cf_text
);
644 static const struct soc_enum cf_dec6_enum
=
645 SOC_ENUM_SINGLE(WCD9335_CDC_TX6_TX_PATH_CFG0
, 5, 3, cf_text
);
647 static const struct soc_enum cf_dec7_enum
=
648 SOC_ENUM_SINGLE(WCD9335_CDC_TX7_TX_PATH_CFG0
, 5, 3, cf_text
);
650 static const struct soc_enum cf_dec8_enum
=
651 SOC_ENUM_SINGLE(WCD9335_CDC_TX8_TX_PATH_CFG0
, 5, 3, cf_text
);
653 static const struct soc_enum cf_int0_1_enum
=
654 SOC_ENUM_SINGLE(WCD9335_CDC_RX0_RX_PATH_CFG2
, 0, 4, rx_cf_text
);
656 static SOC_ENUM_SINGLE_DECL(cf_int0_2_enum
, WCD9335_CDC_RX0_RX_PATH_MIX_CFG
, 2,
659 static const struct soc_enum cf_int1_1_enum
=
660 SOC_ENUM_SINGLE(WCD9335_CDC_RX1_RX_PATH_CFG2
, 0, 4, rx_cf_text
);
662 static SOC_ENUM_SINGLE_DECL(cf_int1_2_enum
, WCD9335_CDC_RX1_RX_PATH_MIX_CFG
, 2,
665 static const struct soc_enum cf_int2_1_enum
=
666 SOC_ENUM_SINGLE(WCD9335_CDC_RX2_RX_PATH_CFG2
, 0, 4, rx_cf_text
);
668 static SOC_ENUM_SINGLE_DECL(cf_int2_2_enum
, WCD9335_CDC_RX2_RX_PATH_MIX_CFG
, 2,
671 static const struct soc_enum cf_int3_1_enum
=
672 SOC_ENUM_SINGLE(WCD9335_CDC_RX3_RX_PATH_CFG2
, 0, 4, rx_cf_text
);
674 static SOC_ENUM_SINGLE_DECL(cf_int3_2_enum
, WCD9335_CDC_RX3_RX_PATH_MIX_CFG
, 2,
677 static const struct soc_enum cf_int4_1_enum
=
678 SOC_ENUM_SINGLE(WCD9335_CDC_RX4_RX_PATH_CFG2
, 0, 4, rx_cf_text
);
680 static SOC_ENUM_SINGLE_DECL(cf_int4_2_enum
, WCD9335_CDC_RX4_RX_PATH_MIX_CFG
, 2,
683 static const struct soc_enum cf_int5_1_enum
=
684 SOC_ENUM_SINGLE(WCD9335_CDC_RX5_RX_PATH_CFG2
, 0, 4, rx_cf_text
);
686 static SOC_ENUM_SINGLE_DECL(cf_int5_2_enum
, WCD9335_CDC_RX5_RX_PATH_MIX_CFG
, 2,
689 static const struct soc_enum cf_int6_1_enum
=
690 SOC_ENUM_SINGLE(WCD9335_CDC_RX6_RX_PATH_CFG2
, 0, 4, rx_cf_text
);
692 static SOC_ENUM_SINGLE_DECL(cf_int6_2_enum
, WCD9335_CDC_RX6_RX_PATH_MIX_CFG
, 2,
695 static const struct soc_enum cf_int7_1_enum
=
696 SOC_ENUM_SINGLE(WCD9335_CDC_RX7_RX_PATH_CFG2
, 0, 4, rx_cf_text
);
698 static SOC_ENUM_SINGLE_DECL(cf_int7_2_enum
, WCD9335_CDC_RX7_RX_PATH_MIX_CFG
, 2,
701 static const struct soc_enum cf_int8_1_enum
=
702 SOC_ENUM_SINGLE(WCD9335_CDC_RX8_RX_PATH_CFG2
, 0, 4, rx_cf_text
);
704 static SOC_ENUM_SINGLE_DECL(cf_int8_2_enum
, WCD9335_CDC_RX8_RX_PATH_MIX_CFG
, 2,
707 static const struct soc_enum rx_hph_mode_mux_enum
=
708 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text
),
709 rx_hph_mode_mux_text
);
711 static const struct soc_enum slim_rx_mux_enum
=
712 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text
), slim_rx_mux_text
);
714 static const struct soc_enum rx_int0_2_mux_chain_enum
=
715 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT0_CFG1
, 0, 10,
716 rx_int0_7_mix_mux_text
);
718 static const struct soc_enum rx_int1_2_mux_chain_enum
=
719 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT1_CFG1
, 0, 9,
720 rx_int_mix_mux_text
);
722 static const struct soc_enum rx_int2_2_mux_chain_enum
=
723 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT2_CFG1
, 0, 9,
724 rx_int_mix_mux_text
);
726 static const struct soc_enum rx_int3_2_mux_chain_enum
=
727 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT3_CFG1
, 0, 9,
728 rx_int_mix_mux_text
);
730 static const struct soc_enum rx_int4_2_mux_chain_enum
=
731 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT4_CFG1
, 0, 9,
732 rx_int_mix_mux_text
);
734 static const struct soc_enum rx_int5_2_mux_chain_enum
=
735 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT5_CFG1
, 0, 9,
736 rx_int_mix_mux_text
);
738 static const struct soc_enum rx_int6_2_mux_chain_enum
=
739 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT6_CFG1
, 0, 9,
740 rx_int_mix_mux_text
);
742 static const struct soc_enum rx_int7_2_mux_chain_enum
=
743 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT7_CFG1
, 0, 10,
744 rx_int0_7_mix_mux_text
);
746 static const struct soc_enum rx_int8_2_mux_chain_enum
=
747 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT8_CFG1
, 0, 9,
748 rx_int_mix_mux_text
);
750 static const struct soc_enum rx_int0_1_mix_inp0_chain_enum
=
751 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT0_CFG0
, 0, 13,
754 static const struct soc_enum rx_int0_1_mix_inp1_chain_enum
=
755 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT0_CFG0
, 4, 13,
758 static const struct soc_enum rx_int0_1_mix_inp2_chain_enum
=
759 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT0_CFG1
, 4, 13,
762 static const struct soc_enum rx_int1_1_mix_inp0_chain_enum
=
763 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT1_CFG0
, 0, 13,
766 static const struct soc_enum rx_int1_1_mix_inp1_chain_enum
=
767 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT1_CFG0
, 4, 13,
770 static const struct soc_enum rx_int1_1_mix_inp2_chain_enum
=
771 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT1_CFG1
, 4, 13,
774 static const struct soc_enum rx_int2_1_mix_inp0_chain_enum
=
775 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT2_CFG0
, 0, 13,
778 static const struct soc_enum rx_int2_1_mix_inp1_chain_enum
=
779 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT2_CFG0
, 4, 13,
782 static const struct soc_enum rx_int2_1_mix_inp2_chain_enum
=
783 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT2_CFG1
, 4, 13,
786 static const struct soc_enum rx_int3_1_mix_inp0_chain_enum
=
787 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT3_CFG0
, 0, 13,
790 static const struct soc_enum rx_int3_1_mix_inp1_chain_enum
=
791 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT3_CFG0
, 4, 13,
794 static const struct soc_enum rx_int3_1_mix_inp2_chain_enum
=
795 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT3_CFG1
, 4, 13,
798 static const struct soc_enum rx_int4_1_mix_inp0_chain_enum
=
799 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT4_CFG0
, 0, 13,
802 static const struct soc_enum rx_int4_1_mix_inp1_chain_enum
=
803 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT4_CFG0
, 4, 13,
806 static const struct soc_enum rx_int4_1_mix_inp2_chain_enum
=
807 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT4_CFG1
, 4, 13,
810 static const struct soc_enum rx_int5_1_mix_inp0_chain_enum
=
811 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT5_CFG0
, 0, 13,
814 static const struct soc_enum rx_int5_1_mix_inp1_chain_enum
=
815 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT5_CFG0
, 4, 13,
818 static const struct soc_enum rx_int5_1_mix_inp2_chain_enum
=
819 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT5_CFG1
, 4, 13,
822 static const struct soc_enum rx_int6_1_mix_inp0_chain_enum
=
823 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT6_CFG0
, 0, 13,
826 static const struct soc_enum rx_int6_1_mix_inp1_chain_enum
=
827 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT6_CFG0
, 4, 13,
830 static const struct soc_enum rx_int6_1_mix_inp2_chain_enum
=
831 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT6_CFG1
, 4, 13,
834 static const struct soc_enum rx_int7_1_mix_inp0_chain_enum
=
835 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT7_CFG0
, 0, 13,
838 static const struct soc_enum rx_int7_1_mix_inp1_chain_enum
=
839 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT7_CFG0
, 4, 13,
842 static const struct soc_enum rx_int7_1_mix_inp2_chain_enum
=
843 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT7_CFG1
, 4, 13,
846 static const struct soc_enum rx_int8_1_mix_inp0_chain_enum
=
847 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT8_CFG0
, 0, 13,
850 static const struct soc_enum rx_int8_1_mix_inp1_chain_enum
=
851 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT8_CFG0
, 4, 13,
854 static const struct soc_enum rx_int8_1_mix_inp2_chain_enum
=
855 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT8_CFG1
, 4, 13,
858 static const struct soc_enum rx_int0_dem_inp_mux_enum
=
859 SOC_ENUM_SINGLE(WCD9335_CDC_RX0_RX_PATH_SEC0
, 0,
860 ARRAY_SIZE(rx_int_dem_inp_mux_text
),
861 rx_int_dem_inp_mux_text
);
863 static const struct soc_enum rx_int1_dem_inp_mux_enum
=
864 SOC_ENUM_SINGLE(WCD9335_CDC_RX1_RX_PATH_SEC0
, 0,
865 ARRAY_SIZE(rx_int_dem_inp_mux_text
),
866 rx_int_dem_inp_mux_text
);
868 static const struct soc_enum rx_int2_dem_inp_mux_enum
=
869 SOC_ENUM_SINGLE(WCD9335_CDC_RX2_RX_PATH_SEC0
, 0,
870 ARRAY_SIZE(rx_int_dem_inp_mux_text
),
871 rx_int_dem_inp_mux_text
);
873 static const struct soc_enum rx_int0_interp_mux_enum
=
874 SOC_ENUM_SINGLE(WCD9335_CDC_RX0_RX_PATH_CTL
, 5, 2,
875 rx_int0_interp_mux_text
);
877 static const struct soc_enum rx_int1_interp_mux_enum
=
878 SOC_ENUM_SINGLE(WCD9335_CDC_RX1_RX_PATH_CTL
, 5, 2,
879 rx_int1_interp_mux_text
);
881 static const struct soc_enum rx_int2_interp_mux_enum
=
882 SOC_ENUM_SINGLE(WCD9335_CDC_RX2_RX_PATH_CTL
, 5, 2,
883 rx_int2_interp_mux_text
);
885 static const struct soc_enum rx_int3_interp_mux_enum
=
886 SOC_ENUM_SINGLE(WCD9335_CDC_RX3_RX_PATH_CTL
, 5, 2,
887 rx_int3_interp_mux_text
);
889 static const struct soc_enum rx_int4_interp_mux_enum
=
890 SOC_ENUM_SINGLE(WCD9335_CDC_RX4_RX_PATH_CTL
, 5, 2,
891 rx_int4_interp_mux_text
);
893 static const struct soc_enum rx_int5_interp_mux_enum
=
894 SOC_ENUM_SINGLE(WCD9335_CDC_RX5_RX_PATH_CTL
, 5, 2,
895 rx_int5_interp_mux_text
);
897 static const struct soc_enum rx_int6_interp_mux_enum
=
898 SOC_ENUM_SINGLE(WCD9335_CDC_RX6_RX_PATH_CTL
, 5, 2,
899 rx_int6_interp_mux_text
);
901 static const struct soc_enum rx_int7_interp_mux_enum
=
902 SOC_ENUM_SINGLE(WCD9335_CDC_RX7_RX_PATH_CTL
, 5, 2,
903 rx_int7_interp_mux_text
);
905 static const struct soc_enum rx_int8_interp_mux_enum
=
906 SOC_ENUM_SINGLE(WCD9335_CDC_RX8_RX_PATH_CTL
, 5, 2,
907 rx_int8_interp_mux_text
);
909 static const struct soc_enum tx_adc_mux0_chain_enum
=
910 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX0_CFG1
, 0, 4,
913 static const struct soc_enum tx_adc_mux1_chain_enum
=
914 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX1_CFG1
, 0, 4,
917 static const struct soc_enum tx_adc_mux2_chain_enum
=
918 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX2_CFG1
, 0, 4,
921 static const struct soc_enum tx_adc_mux3_chain_enum
=
922 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX3_CFG1
, 0, 4,
925 static const struct soc_enum tx_adc_mux4_chain_enum
=
926 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX4_CFG0
, 6, 4,
929 static const struct soc_enum tx_adc_mux5_chain_enum
=
930 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX5_CFG0
, 6, 4,
933 static const struct soc_enum tx_adc_mux6_chain_enum
=
934 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX6_CFG0
, 6, 4,
937 static const struct soc_enum tx_adc_mux7_chain_enum
=
938 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX7_CFG0
, 6, 4,
941 static const struct soc_enum tx_adc_mux8_chain_enum
=
942 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX8_CFG0
, 6, 4,
945 static const struct soc_enum tx_dmic_mux0_enum
=
946 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX0_CFG0
, 3, 11,
949 static const struct soc_enum tx_dmic_mux1_enum
=
950 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX1_CFG0
, 3, 11,
953 static const struct soc_enum tx_dmic_mux2_enum
=
954 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX2_CFG0
, 3, 11,
957 static const struct soc_enum tx_dmic_mux3_enum
=
958 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX3_CFG0
, 3, 11,
961 static const struct soc_enum tx_dmic_mux4_enum
=
962 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX4_CFG0
, 3, 7,
965 static const struct soc_enum tx_dmic_mux5_enum
=
966 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX5_CFG0
, 3, 7,
969 static const struct soc_enum tx_dmic_mux6_enum
=
970 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX6_CFG0
, 3, 7,
973 static const struct soc_enum tx_dmic_mux7_enum
=
974 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX7_CFG0
, 3, 7,
977 static const struct soc_enum tx_dmic_mux8_enum
=
978 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX8_CFG0
, 3, 7,
981 static const struct soc_enum tx_amic_mux0_enum
=
982 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX0_CFG0
, 0, 7,
985 static const struct soc_enum tx_amic_mux1_enum
=
986 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX1_CFG0
, 0, 7,
989 static const struct soc_enum tx_amic_mux2_enum
=
990 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX2_CFG0
, 0, 7,
993 static const struct soc_enum tx_amic_mux3_enum
=
994 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX3_CFG0
, 0, 7,
997 static const struct soc_enum tx_amic_mux4_enum
=
998 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX4_CFG0
, 0, 7,
1001 static const struct soc_enum tx_amic_mux5_enum
=
1002 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX5_CFG0
, 0, 7,
1005 static const struct soc_enum tx_amic_mux6_enum
=
1006 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX6_CFG0
, 0, 7,
1009 static const struct soc_enum tx_amic_mux7_enum
=
1010 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX7_CFG0
, 0, 7,
1013 static const struct soc_enum tx_amic_mux8_enum
=
1014 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX8_CFG0
, 0, 7,
1017 static const struct soc_enum sb_tx0_mux_enum
=
1018 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG0
, 0, 4,
1021 static const struct soc_enum sb_tx1_mux_enum
=
1022 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG0
, 2, 4,
1025 static const struct soc_enum sb_tx2_mux_enum
=
1026 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG0
, 4, 4,
1029 static const struct soc_enum sb_tx3_mux_enum
=
1030 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG0
, 6, 4,
1033 static const struct soc_enum sb_tx4_mux_enum
=
1034 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG1
, 0, 4,
1037 static const struct soc_enum sb_tx5_mux_enum
=
1038 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG1
, 2, 4,
1041 static const struct soc_enum sb_tx6_mux_enum
=
1042 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG1
, 4, 4,
1045 static const struct soc_enum sb_tx7_mux_enum
=
1046 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG1
, 6, 4,
1049 static const struct soc_enum sb_tx8_mux_enum
=
1050 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG2
, 0, 4,
1053 static const struct snd_kcontrol_new rx_int0_2_mux
=
1054 SOC_DAPM_ENUM("RX INT0_2 MUX Mux", rx_int0_2_mux_chain_enum
);
1056 static const struct snd_kcontrol_new rx_int1_2_mux
=
1057 SOC_DAPM_ENUM("RX INT1_2 MUX Mux", rx_int1_2_mux_chain_enum
);
1059 static const struct snd_kcontrol_new rx_int2_2_mux
=
1060 SOC_DAPM_ENUM("RX INT2_2 MUX Mux", rx_int2_2_mux_chain_enum
);
1062 static const struct snd_kcontrol_new rx_int3_2_mux
=
1063 SOC_DAPM_ENUM("RX INT3_2 MUX Mux", rx_int3_2_mux_chain_enum
);
1065 static const struct snd_kcontrol_new rx_int4_2_mux
=
1066 SOC_DAPM_ENUM("RX INT4_2 MUX Mux", rx_int4_2_mux_chain_enum
);
1068 static const struct snd_kcontrol_new rx_int5_2_mux
=
1069 SOC_DAPM_ENUM("RX INT5_2 MUX Mux", rx_int5_2_mux_chain_enum
);
1071 static const struct snd_kcontrol_new rx_int6_2_mux
=
1072 SOC_DAPM_ENUM("RX INT6_2 MUX Mux", rx_int6_2_mux_chain_enum
);
1074 static const struct snd_kcontrol_new rx_int7_2_mux
=
1075 SOC_DAPM_ENUM("RX INT7_2 MUX Mux", rx_int7_2_mux_chain_enum
);
1077 static const struct snd_kcontrol_new rx_int8_2_mux
=
1078 SOC_DAPM_ENUM("RX INT8_2 MUX Mux", rx_int8_2_mux_chain_enum
);
1080 static const struct snd_kcontrol_new rx_int0_1_mix_inp0_mux
=
1081 SOC_DAPM_ENUM("RX INT0_1 MIX1 INP0 Mux", rx_int0_1_mix_inp0_chain_enum
);
1083 static const struct snd_kcontrol_new rx_int0_1_mix_inp1_mux
=
1084 SOC_DAPM_ENUM("RX INT0_1 MIX1 INP1 Mux", rx_int0_1_mix_inp1_chain_enum
);
1086 static const struct snd_kcontrol_new rx_int0_1_mix_inp2_mux
=
1087 SOC_DAPM_ENUM("RX INT0_1 MIX1 INP2 Mux", rx_int0_1_mix_inp2_chain_enum
);
1089 static const struct snd_kcontrol_new rx_int1_1_mix_inp0_mux
=
1090 SOC_DAPM_ENUM("RX INT1_1 MIX1 INP0 Mux", rx_int1_1_mix_inp0_chain_enum
);
1092 static const struct snd_kcontrol_new rx_int1_1_mix_inp1_mux
=
1093 SOC_DAPM_ENUM("RX INT1_1 MIX1 INP1 Mux", rx_int1_1_mix_inp1_chain_enum
);
1095 static const struct snd_kcontrol_new rx_int1_1_mix_inp2_mux
=
1096 SOC_DAPM_ENUM("RX INT1_1 MIX1 INP2 Mux", rx_int1_1_mix_inp2_chain_enum
);
1098 static const struct snd_kcontrol_new rx_int2_1_mix_inp0_mux
=
1099 SOC_DAPM_ENUM("RX INT2_1 MIX1 INP0 Mux", rx_int2_1_mix_inp0_chain_enum
);
1101 static const struct snd_kcontrol_new rx_int2_1_mix_inp1_mux
=
1102 SOC_DAPM_ENUM("RX INT2_1 MIX1 INP1 Mux", rx_int2_1_mix_inp1_chain_enum
);
1104 static const struct snd_kcontrol_new rx_int2_1_mix_inp2_mux
=
1105 SOC_DAPM_ENUM("RX INT2_1 MIX1 INP2 Mux", rx_int2_1_mix_inp2_chain_enum
);
1107 static const struct snd_kcontrol_new rx_int3_1_mix_inp0_mux
=
1108 SOC_DAPM_ENUM("RX INT3_1 MIX1 INP0 Mux", rx_int3_1_mix_inp0_chain_enum
);
1110 static const struct snd_kcontrol_new rx_int3_1_mix_inp1_mux
=
1111 SOC_DAPM_ENUM("RX INT3_1 MIX1 INP1 Mux", rx_int3_1_mix_inp1_chain_enum
);
1113 static const struct snd_kcontrol_new rx_int3_1_mix_inp2_mux
=
1114 SOC_DAPM_ENUM("RX INT3_1 MIX1 INP2 Mux", rx_int3_1_mix_inp2_chain_enum
);
1116 static const struct snd_kcontrol_new rx_int4_1_mix_inp0_mux
=
1117 SOC_DAPM_ENUM("RX INT4_1 MIX1 INP0 Mux", rx_int4_1_mix_inp0_chain_enum
);
1119 static const struct snd_kcontrol_new rx_int4_1_mix_inp1_mux
=
1120 SOC_DAPM_ENUM("RX INT4_1 MIX1 INP1 Mux", rx_int4_1_mix_inp1_chain_enum
);
1122 static const struct snd_kcontrol_new rx_int4_1_mix_inp2_mux
=
1123 SOC_DAPM_ENUM("RX INT4_1 MIX1 INP2 Mux", rx_int4_1_mix_inp2_chain_enum
);
1125 static const struct snd_kcontrol_new rx_int5_1_mix_inp0_mux
=
1126 SOC_DAPM_ENUM("RX INT5_1 MIX1 INP0 Mux", rx_int5_1_mix_inp0_chain_enum
);
1128 static const struct snd_kcontrol_new rx_int5_1_mix_inp1_mux
=
1129 SOC_DAPM_ENUM("RX INT5_1 MIX1 INP1 Mux", rx_int5_1_mix_inp1_chain_enum
);
1131 static const struct snd_kcontrol_new rx_int5_1_mix_inp2_mux
=
1132 SOC_DAPM_ENUM("RX INT5_1 MIX1 INP2 Mux", rx_int5_1_mix_inp2_chain_enum
);
1134 static const struct snd_kcontrol_new rx_int6_1_mix_inp0_mux
=
1135 SOC_DAPM_ENUM("RX INT6_1 MIX1 INP0 Mux", rx_int6_1_mix_inp0_chain_enum
);
1137 static const struct snd_kcontrol_new rx_int6_1_mix_inp1_mux
=
1138 SOC_DAPM_ENUM("RX INT6_1 MIX1 INP1 Mux", rx_int6_1_mix_inp1_chain_enum
);
1140 static const struct snd_kcontrol_new rx_int6_1_mix_inp2_mux
=
1141 SOC_DAPM_ENUM("RX INT6_1 MIX1 INP2 Mux", rx_int6_1_mix_inp2_chain_enum
);
1143 static const struct snd_kcontrol_new rx_int7_1_mix_inp0_mux
=
1144 SOC_DAPM_ENUM("RX INT7_1 MIX1 INP0 Mux", rx_int7_1_mix_inp0_chain_enum
);
1146 static const struct snd_kcontrol_new rx_int7_1_mix_inp1_mux
=
1147 SOC_DAPM_ENUM("RX INT7_1 MIX1 INP1 Mux", rx_int7_1_mix_inp1_chain_enum
);
1149 static const struct snd_kcontrol_new rx_int7_1_mix_inp2_mux
=
1150 SOC_DAPM_ENUM("RX INT7_1 MIX1 INP2 Mux", rx_int7_1_mix_inp2_chain_enum
);
1152 static const struct snd_kcontrol_new rx_int8_1_mix_inp0_mux
=
1153 SOC_DAPM_ENUM("RX INT8_1 MIX1 INP0 Mux", rx_int8_1_mix_inp0_chain_enum
);
1155 static const struct snd_kcontrol_new rx_int8_1_mix_inp1_mux
=
1156 SOC_DAPM_ENUM("RX INT8_1 MIX1 INP1 Mux", rx_int8_1_mix_inp1_chain_enum
);
1158 static const struct snd_kcontrol_new rx_int8_1_mix_inp2_mux
=
1159 SOC_DAPM_ENUM("RX INT8_1 MIX1 INP2 Mux", rx_int8_1_mix_inp2_chain_enum
);
1161 static const struct snd_kcontrol_new rx_int0_interp_mux
=
1162 SOC_DAPM_ENUM("RX INT0 INTERP Mux", rx_int0_interp_mux_enum
);
1164 static const struct snd_kcontrol_new rx_int1_interp_mux
=
1165 SOC_DAPM_ENUM("RX INT1 INTERP Mux", rx_int1_interp_mux_enum
);
1167 static const struct snd_kcontrol_new rx_int2_interp_mux
=
1168 SOC_DAPM_ENUM("RX INT2 INTERP Mux", rx_int2_interp_mux_enum
);
1170 static const struct snd_kcontrol_new rx_int3_interp_mux
=
1171 SOC_DAPM_ENUM("RX INT3 INTERP Mux", rx_int3_interp_mux_enum
);
1173 static const struct snd_kcontrol_new rx_int4_interp_mux
=
1174 SOC_DAPM_ENUM("RX INT4 INTERP Mux", rx_int4_interp_mux_enum
);
1176 static const struct snd_kcontrol_new rx_int5_interp_mux
=
1177 SOC_DAPM_ENUM("RX INT5 INTERP Mux", rx_int5_interp_mux_enum
);
1179 static const struct snd_kcontrol_new rx_int6_interp_mux
=
1180 SOC_DAPM_ENUM("RX INT6 INTERP Mux", rx_int6_interp_mux_enum
);
1182 static const struct snd_kcontrol_new rx_int7_interp_mux
=
1183 SOC_DAPM_ENUM("RX INT7 INTERP Mux", rx_int7_interp_mux_enum
);
1185 static const struct snd_kcontrol_new rx_int8_interp_mux
=
1186 SOC_DAPM_ENUM("RX INT8 INTERP Mux", rx_int8_interp_mux_enum
);
1188 static const struct snd_kcontrol_new tx_dmic_mux0
=
1189 SOC_DAPM_ENUM("DMIC MUX0 Mux", tx_dmic_mux0_enum
);
1191 static const struct snd_kcontrol_new tx_dmic_mux1
=
1192 SOC_DAPM_ENUM("DMIC MUX1 Mux", tx_dmic_mux1_enum
);
1194 static const struct snd_kcontrol_new tx_dmic_mux2
=
1195 SOC_DAPM_ENUM("DMIC MUX2 Mux", tx_dmic_mux2_enum
);
1197 static const struct snd_kcontrol_new tx_dmic_mux3
=
1198 SOC_DAPM_ENUM("DMIC MUX3 Mux", tx_dmic_mux3_enum
);
1200 static const struct snd_kcontrol_new tx_dmic_mux4
=
1201 SOC_DAPM_ENUM("DMIC MUX4 Mux", tx_dmic_mux4_enum
);
1203 static const struct snd_kcontrol_new tx_dmic_mux5
=
1204 SOC_DAPM_ENUM("DMIC MUX5 Mux", tx_dmic_mux5_enum
);
1206 static const struct snd_kcontrol_new tx_dmic_mux6
=
1207 SOC_DAPM_ENUM("DMIC MUX6 Mux", tx_dmic_mux6_enum
);
1209 static const struct snd_kcontrol_new tx_dmic_mux7
=
1210 SOC_DAPM_ENUM("DMIC MUX7 Mux", tx_dmic_mux7_enum
);
1212 static const struct snd_kcontrol_new tx_dmic_mux8
=
1213 SOC_DAPM_ENUM("DMIC MUX8 Mux", tx_dmic_mux8_enum
);
1215 static const struct snd_kcontrol_new tx_amic_mux0
=
1216 SOC_DAPM_ENUM("AMIC MUX0 Mux", tx_amic_mux0_enum
);
1218 static const struct snd_kcontrol_new tx_amic_mux1
=
1219 SOC_DAPM_ENUM("AMIC MUX1 Mux", tx_amic_mux1_enum
);
1221 static const struct snd_kcontrol_new tx_amic_mux2
=
1222 SOC_DAPM_ENUM("AMIC MUX2 Mux", tx_amic_mux2_enum
);
1224 static const struct snd_kcontrol_new tx_amic_mux3
=
1225 SOC_DAPM_ENUM("AMIC MUX3 Mux", tx_amic_mux3_enum
);
1227 static const struct snd_kcontrol_new tx_amic_mux4
=
1228 SOC_DAPM_ENUM("AMIC MUX4 Mux", tx_amic_mux4_enum
);
1230 static const struct snd_kcontrol_new tx_amic_mux5
=
1231 SOC_DAPM_ENUM("AMIC MUX5 Mux", tx_amic_mux5_enum
);
1233 static const struct snd_kcontrol_new tx_amic_mux6
=
1234 SOC_DAPM_ENUM("AMIC MUX6 Mux", tx_amic_mux6_enum
);
1236 static const struct snd_kcontrol_new tx_amic_mux7
=
1237 SOC_DAPM_ENUM("AMIC MUX7 Mux", tx_amic_mux7_enum
);
1239 static const struct snd_kcontrol_new tx_amic_mux8
=
1240 SOC_DAPM_ENUM("AMIC MUX8 Mux", tx_amic_mux8_enum
);
1242 static const struct snd_kcontrol_new sb_tx0_mux
=
1243 SOC_DAPM_ENUM("SLIM TX0 MUX Mux", sb_tx0_mux_enum
);
1245 static const struct snd_kcontrol_new sb_tx1_mux
=
1246 SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum
);
1248 static const struct snd_kcontrol_new sb_tx2_mux
=
1249 SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum
);
1251 static const struct snd_kcontrol_new sb_tx3_mux
=
1252 SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum
);
1254 static const struct snd_kcontrol_new sb_tx4_mux
=
1255 SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum
);
1257 static const struct snd_kcontrol_new sb_tx5_mux
=
1258 SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum
);
1260 static const struct snd_kcontrol_new sb_tx6_mux
=
1261 SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum
);
1263 static const struct snd_kcontrol_new sb_tx7_mux
=
1264 SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum
);
1266 static const struct snd_kcontrol_new sb_tx8_mux
=
1267 SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum
);
1269 static int slim_rx_mux_get(struct snd_kcontrol
*kc
,
1270 struct snd_ctl_elem_value
*ucontrol
)
1272 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kc
);
1273 struct wcd9335_codec
*wcd
= dev_get_drvdata(dapm
->dev
);
1275 ucontrol
->value
.enumerated
.item
[0] = wcd
->rx_port_value
;
1280 static int slim_rx_mux_put(struct snd_kcontrol
*kc
,
1281 struct snd_ctl_elem_value
*ucontrol
)
1283 struct snd_soc_dapm_widget
*w
= snd_soc_dapm_kcontrol_widget(kc
);
1284 struct wcd9335_codec
*wcd
= dev_get_drvdata(w
->dapm
->dev
);
1285 struct soc_enum
*e
= (struct soc_enum
*)kc
->private_value
;
1286 struct snd_soc_dapm_update
*update
= NULL
;
1287 u32 port_id
= w
->shift
;
1289 wcd
->rx_port_value
= ucontrol
->value
.enumerated
.item
[0];
1291 switch (wcd
->rx_port_value
) {
1293 list_del_init(&wcd
->rx_chs
[port_id
].list
);
1296 list_add_tail(&wcd
->rx_chs
[port_id
].list
,
1297 &wcd
->dai
[AIF1_PB
].slim_ch_list
);
1300 list_add_tail(&wcd
->rx_chs
[port_id
].list
,
1301 &wcd
->dai
[AIF2_PB
].slim_ch_list
);
1304 list_add_tail(&wcd
->rx_chs
[port_id
].list
,
1305 &wcd
->dai
[AIF3_PB
].slim_ch_list
);
1308 list_add_tail(&wcd
->rx_chs
[port_id
].list
,
1309 &wcd
->dai
[AIF4_PB
].slim_ch_list
);
1312 dev_err(wcd
->dev
, "Unknown AIF %d\n", wcd
->rx_port_value
);
1316 snd_soc_dapm_mux_update_power(w
->dapm
, kc
, wcd
->rx_port_value
,
1324 static int slim_tx_mixer_get(struct snd_kcontrol
*kc
,
1325 struct snd_ctl_elem_value
*ucontrol
)
1328 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kc
);
1329 struct wcd9335_codec
*wcd
= dev_get_drvdata(dapm
->dev
);
1331 ucontrol
->value
.integer
.value
[0] = wcd
->tx_port_value
;
1336 static int slim_tx_mixer_put(struct snd_kcontrol
*kc
,
1337 struct snd_ctl_elem_value
*ucontrol
)
1340 struct snd_soc_dapm_widget
*widget
= snd_soc_dapm_kcontrol_widget(kc
);
1341 struct wcd9335_codec
*wcd
= dev_get_drvdata(widget
->dapm
->dev
);
1342 struct snd_soc_dapm_update
*update
= NULL
;
1343 struct soc_mixer_control
*mixer
=
1344 (struct soc_mixer_control
*)kc
->private_value
;
1345 int enable
= ucontrol
->value
.integer
.value
[0];
1346 int dai_id
= widget
->shift
;
1347 int port_id
= mixer
->shift
;
1353 /* only add to the list if value not set */
1354 if (enable
&& !(wcd
->tx_port_value
& BIT(port_id
))) {
1355 wcd
->tx_port_value
|= BIT(port_id
);
1356 list_add_tail(&wcd
->tx_chs
[port_id
].list
,
1357 &wcd
->dai
[dai_id
].slim_ch_list
);
1358 } else if (!enable
&& (wcd
->tx_port_value
& BIT(port_id
))) {
1359 wcd
->tx_port_value
&= ~BIT(port_id
);
1360 list_del_init(&wcd
->tx_chs
[port_id
].list
);
1364 dev_err(wcd
->dev
, "Unknown AIF %d\n", dai_id
);
1368 snd_soc_dapm_mixer_update_power(widget
->dapm
, kc
, enable
, update
);
1373 static const struct snd_kcontrol_new slim_rx_mux
[WCD9335_RX_MAX
] = {
1374 SOC_DAPM_ENUM_EXT("SLIM RX0 Mux", slim_rx_mux_enum
,
1375 slim_rx_mux_get
, slim_rx_mux_put
),
1376 SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum
,
1377 slim_rx_mux_get
, slim_rx_mux_put
),
1378 SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum
,
1379 slim_rx_mux_get
, slim_rx_mux_put
),
1380 SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum
,
1381 slim_rx_mux_get
, slim_rx_mux_put
),
1382 SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum
,
1383 slim_rx_mux_get
, slim_rx_mux_put
),
1384 SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum
,
1385 slim_rx_mux_get
, slim_rx_mux_put
),
1386 SOC_DAPM_ENUM_EXT("SLIM RX6 Mux", slim_rx_mux_enum
,
1387 slim_rx_mux_get
, slim_rx_mux_put
),
1388 SOC_DAPM_ENUM_EXT("SLIM RX7 Mux", slim_rx_mux_enum
,
1389 slim_rx_mux_get
, slim_rx_mux_put
),
1392 static const struct snd_kcontrol_new aif1_cap_mixer
[] = {
1393 SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM
, WCD9335_TX0
, 1, 0,
1394 slim_tx_mixer_get
, slim_tx_mixer_put
),
1395 SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM
, WCD9335_TX1
, 1, 0,
1396 slim_tx_mixer_get
, slim_tx_mixer_put
),
1397 SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM
, WCD9335_TX2
, 1, 0,
1398 slim_tx_mixer_get
, slim_tx_mixer_put
),
1399 SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM
, WCD9335_TX3
, 1, 0,
1400 slim_tx_mixer_get
, slim_tx_mixer_put
),
1401 SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM
, WCD9335_TX4
, 1, 0,
1402 slim_tx_mixer_get
, slim_tx_mixer_put
),
1403 SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM
, WCD9335_TX5
, 1, 0,
1404 slim_tx_mixer_get
, slim_tx_mixer_put
),
1405 SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM
, WCD9335_TX6
, 1, 0,
1406 slim_tx_mixer_get
, slim_tx_mixer_put
),
1407 SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM
, WCD9335_TX7
, 1, 0,
1408 slim_tx_mixer_get
, slim_tx_mixer_put
),
1409 SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM
, WCD9335_TX8
, 1, 0,
1410 slim_tx_mixer_get
, slim_tx_mixer_put
),
1411 SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM
, WCD9335_TX9
, 1, 0,
1412 slim_tx_mixer_get
, slim_tx_mixer_put
),
1413 SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM
, WCD9335_TX10
, 1, 0,
1414 slim_tx_mixer_get
, slim_tx_mixer_put
),
1415 SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM
, WCD9335_TX11
, 1, 0,
1416 slim_tx_mixer_get
, slim_tx_mixer_put
),
1417 SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM
, WCD9335_TX13
, 1, 0,
1418 slim_tx_mixer_get
, slim_tx_mixer_put
),
1421 static const struct snd_kcontrol_new aif2_cap_mixer
[] = {
1422 SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM
, WCD9335_TX0
, 1, 0,
1423 slim_tx_mixer_get
, slim_tx_mixer_put
),
1424 SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM
, WCD9335_TX1
, 1, 0,
1425 slim_tx_mixer_get
, slim_tx_mixer_put
),
1426 SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM
, WCD9335_TX2
, 1, 0,
1427 slim_tx_mixer_get
, slim_tx_mixer_put
),
1428 SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM
, WCD9335_TX3
, 1, 0,
1429 slim_tx_mixer_get
, slim_tx_mixer_put
),
1430 SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM
, WCD9335_TX4
, 1, 0,
1431 slim_tx_mixer_get
, slim_tx_mixer_put
),
1432 SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM
, WCD9335_TX5
, 1, 0,
1433 slim_tx_mixer_get
, slim_tx_mixer_put
),
1434 SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM
, WCD9335_TX6
, 1, 0,
1435 slim_tx_mixer_get
, slim_tx_mixer_put
),
1436 SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM
, WCD9335_TX7
, 1, 0,
1437 slim_tx_mixer_get
, slim_tx_mixer_put
),
1438 SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM
, WCD9335_TX8
, 1, 0,
1439 slim_tx_mixer_get
, slim_tx_mixer_put
),
1440 SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM
, WCD9335_TX9
, 1, 0,
1441 slim_tx_mixer_get
, slim_tx_mixer_put
),
1442 SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM
, WCD9335_TX10
, 1, 0,
1443 slim_tx_mixer_get
, slim_tx_mixer_put
),
1444 SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM
, WCD9335_TX11
, 1, 0,
1445 slim_tx_mixer_get
, slim_tx_mixer_put
),
1446 SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM
, WCD9335_TX13
, 1, 0,
1447 slim_tx_mixer_get
, slim_tx_mixer_put
),
1450 static const struct snd_kcontrol_new aif3_cap_mixer
[] = {
1451 SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM
, WCD9335_TX0
, 1, 0,
1452 slim_tx_mixer_get
, slim_tx_mixer_put
),
1453 SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM
, WCD9335_TX1
, 1, 0,
1454 slim_tx_mixer_get
, slim_tx_mixer_put
),
1455 SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM
, WCD9335_TX2
, 1, 0,
1456 slim_tx_mixer_get
, slim_tx_mixer_put
),
1457 SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM
, WCD9335_TX3
, 1, 0,
1458 slim_tx_mixer_get
, slim_tx_mixer_put
),
1459 SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM
, WCD9335_TX4
, 1, 0,
1460 slim_tx_mixer_get
, slim_tx_mixer_put
),
1461 SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM
, WCD9335_TX5
, 1, 0,
1462 slim_tx_mixer_get
, slim_tx_mixer_put
),
1463 SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM
, WCD9335_TX6
, 1, 0,
1464 slim_tx_mixer_get
, slim_tx_mixer_put
),
1465 SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM
, WCD9335_TX7
, 1, 0,
1466 slim_tx_mixer_get
, slim_tx_mixer_put
),
1467 SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM
, WCD9335_TX8
, 1, 0,
1468 slim_tx_mixer_get
, slim_tx_mixer_put
),
1471 static int wcd9335_put_dec_enum(struct snd_kcontrol
*kc
,
1472 struct snd_ctl_elem_value
*ucontrol
)
1474 struct snd_soc_dapm_context
*dapm
= snd_soc_dapm_kcontrol_dapm(kc
);
1475 struct snd_soc_component
*component
= snd_soc_dapm_to_component(dapm
);
1476 struct soc_enum
*e
= (struct soc_enum
*)kc
->private_value
;
1477 unsigned int val
, reg
, sel
;
1479 val
= ucontrol
->value
.enumerated
.item
[0];
1482 case WCD9335_CDC_TX_INP_MUX_ADC_MUX0_CFG1
:
1483 reg
= WCD9335_CDC_TX0_TX_PATH_CFG0
;
1485 case WCD9335_CDC_TX_INP_MUX_ADC_MUX1_CFG1
:
1486 reg
= WCD9335_CDC_TX1_TX_PATH_CFG0
;
1488 case WCD9335_CDC_TX_INP_MUX_ADC_MUX2_CFG1
:
1489 reg
= WCD9335_CDC_TX2_TX_PATH_CFG0
;
1491 case WCD9335_CDC_TX_INP_MUX_ADC_MUX3_CFG1
:
1492 reg
= WCD9335_CDC_TX3_TX_PATH_CFG0
;
1494 case WCD9335_CDC_TX_INP_MUX_ADC_MUX4_CFG0
:
1495 reg
= WCD9335_CDC_TX4_TX_PATH_CFG0
;
1497 case WCD9335_CDC_TX_INP_MUX_ADC_MUX5_CFG0
:
1498 reg
= WCD9335_CDC_TX5_TX_PATH_CFG0
;
1500 case WCD9335_CDC_TX_INP_MUX_ADC_MUX6_CFG0
:
1501 reg
= WCD9335_CDC_TX6_TX_PATH_CFG0
;
1503 case WCD9335_CDC_TX_INP_MUX_ADC_MUX7_CFG0
:
1504 reg
= WCD9335_CDC_TX7_TX_PATH_CFG0
;
1506 case WCD9335_CDC_TX_INP_MUX_ADC_MUX8_CFG0
:
1507 reg
= WCD9335_CDC_TX8_TX_PATH_CFG0
;
1513 /* AMIC: 0, DMIC: 1 */
1514 sel
= val
? WCD9335_CDC_TX_ADC_AMIC_SEL
: WCD9335_CDC_TX_ADC_DMIC_SEL
;
1515 snd_soc_component_update_bits(component
, reg
,
1516 WCD9335_CDC_TX_ADC_AMIC_DMIC_SEL_MASK
,
1519 return snd_soc_dapm_put_enum_double(kc
, ucontrol
);
1522 static int wcd9335_int_dem_inp_mux_put(struct snd_kcontrol
*kc
,
1523 struct snd_ctl_elem_value
*ucontrol
)
1525 struct soc_enum
*e
= (struct soc_enum
*)kc
->private_value
;
1526 struct snd_soc_component
*component
;
1529 component
= snd_soc_dapm_kcontrol_component(kc
);
1530 val
= ucontrol
->value
.enumerated
.item
[0];
1532 if (e
->reg
== WCD9335_CDC_RX0_RX_PATH_SEC0
)
1533 reg
= WCD9335_CDC_RX0_RX_PATH_CFG0
;
1534 else if (e
->reg
== WCD9335_CDC_RX1_RX_PATH_SEC0
)
1535 reg
= WCD9335_CDC_RX1_RX_PATH_CFG0
;
1536 else if (e
->reg
== WCD9335_CDC_RX2_RX_PATH_SEC0
)
1537 reg
= WCD9335_CDC_RX2_RX_PATH_CFG0
;
1541 /* Set Look Ahead Delay */
1542 snd_soc_component_update_bits(component
, reg
,
1543 WCD9335_CDC_RX_PATH_CFG0_DLY_ZN_EN_MASK
,
1544 val
? WCD9335_CDC_RX_PATH_CFG0_DLY_ZN_EN
: 0);
1545 /* Set DEM INP Select */
1546 return snd_soc_dapm_put_enum_double(kc
, ucontrol
);
1549 static const struct snd_kcontrol_new rx_int0_dem_inp_mux
=
1550 SOC_DAPM_ENUM_EXT("RX INT0 DEM MUX Mux", rx_int0_dem_inp_mux_enum
,
1551 snd_soc_dapm_get_enum_double
,
1552 wcd9335_int_dem_inp_mux_put
);
1554 static const struct snd_kcontrol_new rx_int1_dem_inp_mux
=
1555 SOC_DAPM_ENUM_EXT("RX INT1 DEM MUX Mux", rx_int1_dem_inp_mux_enum
,
1556 snd_soc_dapm_get_enum_double
,
1557 wcd9335_int_dem_inp_mux_put
);
1559 static const struct snd_kcontrol_new rx_int2_dem_inp_mux
=
1560 SOC_DAPM_ENUM_EXT("RX INT2 DEM MUX Mux", rx_int2_dem_inp_mux_enum
,
1561 snd_soc_dapm_get_enum_double
,
1562 wcd9335_int_dem_inp_mux_put
);
1564 static const struct snd_kcontrol_new tx_adc_mux0
=
1565 SOC_DAPM_ENUM_EXT("ADC MUX0 Mux", tx_adc_mux0_chain_enum
,
1566 snd_soc_dapm_get_enum_double
,
1567 wcd9335_put_dec_enum
);
1569 static const struct snd_kcontrol_new tx_adc_mux1
=
1570 SOC_DAPM_ENUM_EXT("ADC MUX1 Mux", tx_adc_mux1_chain_enum
,
1571 snd_soc_dapm_get_enum_double
,
1572 wcd9335_put_dec_enum
);
1574 static const struct snd_kcontrol_new tx_adc_mux2
=
1575 SOC_DAPM_ENUM_EXT("ADC MUX2 Mux", tx_adc_mux2_chain_enum
,
1576 snd_soc_dapm_get_enum_double
,
1577 wcd9335_put_dec_enum
);
1579 static const struct snd_kcontrol_new tx_adc_mux3
=
1580 SOC_DAPM_ENUM_EXT("ADC MUX3 Mux", tx_adc_mux3_chain_enum
,
1581 snd_soc_dapm_get_enum_double
,
1582 wcd9335_put_dec_enum
);
1584 static const struct snd_kcontrol_new tx_adc_mux4
=
1585 SOC_DAPM_ENUM_EXT("ADC MUX4 Mux", tx_adc_mux4_chain_enum
,
1586 snd_soc_dapm_get_enum_double
,
1587 wcd9335_put_dec_enum
);
1589 static const struct snd_kcontrol_new tx_adc_mux5
=
1590 SOC_DAPM_ENUM_EXT("ADC MUX5 Mux", tx_adc_mux5_chain_enum
,
1591 snd_soc_dapm_get_enum_double
,
1592 wcd9335_put_dec_enum
);
1594 static const struct snd_kcontrol_new tx_adc_mux6
=
1595 SOC_DAPM_ENUM_EXT("ADC MUX6 Mux", tx_adc_mux6_chain_enum
,
1596 snd_soc_dapm_get_enum_double
,
1597 wcd9335_put_dec_enum
);
1599 static const struct snd_kcontrol_new tx_adc_mux7
=
1600 SOC_DAPM_ENUM_EXT("ADC MUX7 Mux", tx_adc_mux7_chain_enum
,
1601 snd_soc_dapm_get_enum_double
,
1602 wcd9335_put_dec_enum
);
1604 static const struct snd_kcontrol_new tx_adc_mux8
=
1605 SOC_DAPM_ENUM_EXT("ADC MUX8 Mux", tx_adc_mux8_chain_enum
,
1606 snd_soc_dapm_get_enum_double
,
1607 wcd9335_put_dec_enum
);
1609 static int wcd9335_set_mix_interpolator_rate(struct snd_soc_dai
*dai
,
1613 struct snd_soc_component
*component
= dai
->component
;
1614 struct wcd9335_codec
*wcd
= dev_get_drvdata(component
->dev
);
1615 struct wcd9335_slim_ch
*ch
;
1618 list_for_each_entry(ch
, &wcd
->dai
[dai
->id
].slim_ch_list
, list
) {
1619 for (j
= 0; j
< WCD9335_NUM_INTERPOLATORS
; j
++) {
1620 val
= snd_soc_component_read32(component
,
1621 WCD9335_CDC_RX_INP_MUX_RX_INT_CFG1(j
)) &
1622 WCD9335_CDC_RX_INP_MUX_RX_INT_SEL_MASK
;
1624 if (val
== (ch
->shift
+ INTn_2_INP_SEL_RX0
))
1625 snd_soc_component_update_bits(component
,
1626 WCD9335_CDC_RX_PATH_MIX_CTL(j
),
1627 WCD9335_CDC_MIX_PCM_RATE_MASK
,
1635 static int wcd9335_set_prim_interpolator_rate(struct snd_soc_dai
*dai
,
1639 struct snd_soc_component
*comp
= dai
->component
;
1640 struct wcd9335_codec
*wcd
= dev_get_drvdata(comp
->dev
);
1641 struct wcd9335_slim_ch
*ch
;
1642 u8 cfg0
, cfg1
, inp0_sel
, inp1_sel
, inp2_sel
;
1645 list_for_each_entry(ch
, &wcd
->dai
[dai
->id
].slim_ch_list
, list
) {
1646 inp
= ch
->shift
+ INTn_1_MIX_INP_SEL_RX0
;
1648 * Loop through all interpolator MUX inputs and find out
1649 * to which interpolator input, the slim rx port
1652 for (j
= 0; j
< WCD9335_NUM_INTERPOLATORS
; j
++) {
1653 cfg0
= snd_soc_component_read32(comp
,
1654 WCD9335_CDC_RX_INP_MUX_RX_INT_CFG0(j
));
1655 cfg1
= snd_soc_component_read32(comp
,
1656 WCD9335_CDC_RX_INP_MUX_RX_INT_CFG1(j
));
1659 WCD9335_CDC_RX_INP_MUX_RX_INT_SEL_MASK
;
1660 inp1_sel
= (cfg0
>> 4) &
1661 WCD9335_CDC_RX_INP_MUX_RX_INT_SEL_MASK
;
1662 inp2_sel
= (cfg1
>> 4) &
1663 WCD9335_CDC_RX_INP_MUX_RX_INT_SEL_MASK
;
1665 if ((inp0_sel
== inp
) || (inp1_sel
== inp
) ||
1666 (inp2_sel
== inp
)) {
1668 if ((j
== 0) && (rate
== 44100))
1670 "Cannot set 44.1KHz on INT0\n");
1672 snd_soc_component_update_bits(comp
,
1673 WCD9335_CDC_RX_PATH_CTL(j
),
1674 WCD9335_CDC_MIX_PCM_RATE_MASK
,
1683 static int wcd9335_set_interpolator_rate(struct snd_soc_dai
*dai
, u32 rate
)
1687 /* set mixing path rate */
1688 for (i
= 0; i
< ARRAY_SIZE(int_mix_rate_val
); i
++) {
1689 if (rate
== int_mix_rate_val
[i
].rate
) {
1690 wcd9335_set_mix_interpolator_rate(dai
,
1691 int_mix_rate_val
[i
].rate_val
, rate
);
1696 /* set primary path sample rate */
1697 for (i
= 0; i
< ARRAY_SIZE(int_prim_rate_val
); i
++) {
1698 if (rate
== int_prim_rate_val
[i
].rate
) {
1699 wcd9335_set_prim_interpolator_rate(dai
,
1700 int_prim_rate_val
[i
].rate_val
, rate
);
1708 static int wcd9335_slim_set_hw_params(struct wcd9335_codec
*wcd
,
1709 struct wcd_slim_codec_dai_data
*dai_data
,
1712 struct list_head
*slim_ch_list
= &dai_data
->slim_ch_list
;
1713 struct slim_stream_config
*cfg
= &dai_data
->sconfig
;
1714 struct wcd9335_slim_ch
*ch
;
1719 cfg
->direction
= direction
;
1722 /* Configure slave interface device */
1723 list_for_each_entry(ch
, slim_ch_list
, list
) {
1725 payload
|= 1 << ch
->shift
;
1726 cfg
->port_mask
|= BIT(ch
->port
);
1729 cfg
->chs
= kcalloc(cfg
->ch_count
, sizeof(unsigned int), GFP_KERNEL
);
1734 list_for_each_entry(ch
, slim_ch_list
, list
) {
1735 cfg
->chs
[i
++] = ch
->ch_num
;
1736 if (direction
== SNDRV_PCM_STREAM_PLAYBACK
) {
1737 /* write to interface device */
1738 ret
= regmap_write(wcd
->if_regmap
,
1739 WCD9335_SLIM_PGD_RX_PORT_MULTI_CHNL_0(ch
->port
),
1745 /* configure the slave port for water mark and enable*/
1746 ret
= regmap_write(wcd
->if_regmap
,
1747 WCD9335_SLIM_PGD_RX_PORT_CFG(ch
->port
),
1748 WCD9335_SLIM_WATER_MARK_VAL
);
1752 ret
= regmap_write(wcd
->if_regmap
,
1753 WCD9335_SLIM_PGD_TX_PORT_MULTI_CHNL_0(ch
->port
),
1759 ret
= regmap_write(wcd
->if_regmap
,
1760 WCD9335_SLIM_PGD_TX_PORT_MULTI_CHNL_1(ch
->port
),
1761 (payload
& 0xFF00)>>8);
1765 /* configure the slave port for water mark and enable*/
1766 ret
= regmap_write(wcd
->if_regmap
,
1767 WCD9335_SLIM_PGD_TX_PORT_CFG(ch
->port
),
1768 WCD9335_SLIM_WATER_MARK_VAL
);
1775 dai_data
->sruntime
= slim_stream_allocate(wcd
->slim
, "WCD9335-SLIM");
1780 dev_err(wcd
->dev
, "Error Setting slim hw params\n");
1787 static int wcd9335_set_decimator_rate(struct snd_soc_dai
*dai
,
1788 u8 rate_val
, u32 rate
)
1790 struct snd_soc_component
*comp
= dai
->component
;
1791 struct wcd9335_codec
*wcd
= snd_soc_component_get_drvdata(comp
);
1792 u8 shift
= 0, shift_val
= 0, tx_mux_sel
;
1793 struct wcd9335_slim_ch
*ch
;
1794 int tx_port
, tx_port_reg
;
1797 list_for_each_entry(ch
, &wcd
->dai
[dai
->id
].slim_ch_list
, list
) {
1799 if ((tx_port
== 12) || (tx_port
>= 14)) {
1800 dev_err(wcd
->dev
, "Invalid SLIM TX%u port DAI ID:%d\n",
1804 /* Find the SB TX MUX input - which decimator is connected */
1806 tx_port_reg
= WCD9335_CDC_IF_ROUTER_TX_MUX_CFG0
;
1807 shift
= (tx_port
<< 1);
1809 } else if ((tx_port
>= 4) && (tx_port
< 8)) {
1810 tx_port_reg
= WCD9335_CDC_IF_ROUTER_TX_MUX_CFG1
;
1811 shift
= ((tx_port
- 4) << 1);
1813 } else if ((tx_port
>= 8) && (tx_port
< 11)) {
1814 tx_port_reg
= WCD9335_CDC_IF_ROUTER_TX_MUX_CFG2
;
1815 shift
= ((tx_port
- 8) << 1);
1817 } else if (tx_port
== 11) {
1818 tx_port_reg
= WCD9335_CDC_IF_ROUTER_TX_MUX_CFG3
;
1821 } else if (tx_port
== 13) {
1822 tx_port_reg
= WCD9335_CDC_IF_ROUTER_TX_MUX_CFG3
;
1829 tx_mux_sel
= snd_soc_component_read32(comp
, tx_port_reg
) &
1830 (shift_val
<< shift
);
1832 tx_mux_sel
= tx_mux_sel
>> shift
;
1834 if ((tx_mux_sel
== 0x2) || (tx_mux_sel
== 0x3))
1835 decimator
= tx_port
;
1836 } else if (tx_port
<= 10) {
1837 if ((tx_mux_sel
== 0x1) || (tx_mux_sel
== 0x2))
1838 decimator
= ((tx_port
== 9) ? 7 : 6);
1839 } else if (tx_port
== 11) {
1840 if ((tx_mux_sel
>= 1) && (tx_mux_sel
< 7))
1841 decimator
= tx_mux_sel
- 1;
1842 } else if (tx_port
== 13) {
1843 if ((tx_mux_sel
== 0x1) || (tx_mux_sel
== 0x2))
1847 if (decimator
>= 0) {
1848 snd_soc_component_update_bits(comp
,
1849 WCD9335_CDC_TX_PATH_CTL(decimator
),
1850 WCD9335_CDC_TX_PATH_CTL_PCM_RATE_MASK
,
1852 } else if ((tx_port
<= 8) && (tx_mux_sel
== 0x01)) {
1853 /* Check if the TX Mux input is RX MIX TXn */
1854 dev_err(wcd
->dev
, "RX_MIX_TX%u going to SLIM TX%u\n",
1857 dev_err(wcd
->dev
, "ERROR: Invalid decimator: %d\n",
1866 static int wcd9335_hw_params(struct snd_pcm_substream
*substream
,
1867 struct snd_pcm_hw_params
*params
,
1868 struct snd_soc_dai
*dai
)
1870 struct wcd9335_codec
*wcd
;
1871 int ret
, tx_fs_rate
= 0;
1873 wcd
= snd_soc_component_get_drvdata(dai
->component
);
1875 switch (substream
->stream
) {
1876 case SNDRV_PCM_STREAM_PLAYBACK
:
1877 ret
= wcd9335_set_interpolator_rate(dai
, params_rate(params
));
1879 dev_err(wcd
->dev
, "cannot set sample rate: %u\n",
1880 params_rate(params
));
1883 switch (params_width(params
)) {
1885 wcd
->dai
[dai
->id
].sconfig
.bps
= params_width(params
);
1888 dev_err(wcd
->dev
, "%s: Invalid format 0x%x\n",
1889 __func__
, params_width(params
));
1894 case SNDRV_PCM_STREAM_CAPTURE
:
1895 switch (params_rate(params
)) {
1918 dev_err(wcd
->dev
, "%s: Invalid TX sample rate: %d\n",
1919 __func__
, params_rate(params
));
1924 ret
= wcd9335_set_decimator_rate(dai
, tx_fs_rate
,
1925 params_rate(params
));
1927 dev_err(wcd
->dev
, "Cannot set TX Decimator rate\n");
1930 switch (params_width(params
)) {
1932 wcd
->dai
[dai
->id
].sconfig
.bps
= params_width(params
);
1935 dev_err(wcd
->dev
, "%s: Invalid format 0x%x\n",
1936 __func__
, params_width(params
));
1941 dev_err(wcd
->dev
, "Invalid stream type %d\n",
1946 wcd
->dai
[dai
->id
].sconfig
.rate
= params_rate(params
);
1947 wcd9335_slim_set_hw_params(wcd
, &wcd
->dai
[dai
->id
], substream
->stream
);
1952 static int wcd9335_trigger(struct snd_pcm_substream
*substream
, int cmd
,
1953 struct snd_soc_dai
*dai
)
1955 struct wcd_slim_codec_dai_data
*dai_data
;
1956 struct wcd9335_codec
*wcd
;
1957 struct slim_stream_config
*cfg
;
1959 wcd
= snd_soc_component_get_drvdata(dai
->component
);
1961 dai_data
= &wcd
->dai
[dai
->id
];
1964 case SNDRV_PCM_TRIGGER_START
:
1965 case SNDRV_PCM_TRIGGER_RESUME
:
1966 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1967 cfg
= &dai_data
->sconfig
;
1968 slim_stream_prepare(dai_data
->sruntime
, cfg
);
1969 slim_stream_enable(dai_data
->sruntime
);
1971 case SNDRV_PCM_TRIGGER_STOP
:
1972 case SNDRV_PCM_TRIGGER_SUSPEND
:
1973 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1974 slim_stream_unprepare(dai_data
->sruntime
);
1975 slim_stream_disable(dai_data
->sruntime
);
1984 static int wcd9335_set_channel_map(struct snd_soc_dai
*dai
,
1985 unsigned int tx_num
, unsigned int *tx_slot
,
1986 unsigned int rx_num
, unsigned int *rx_slot
)
1988 struct wcd9335_codec
*wcd
;
1991 wcd
= snd_soc_component_get_drvdata(dai
->component
);
1993 if (!tx_slot
|| !rx_slot
) {
1994 dev_err(wcd
->dev
, "Invalid tx_slot=%p, rx_slot=%p\n",
1999 wcd
->num_rx_port
= rx_num
;
2000 for (i
= 0; i
< rx_num
; i
++) {
2001 wcd
->rx_chs
[i
].ch_num
= rx_slot
[i
];
2002 INIT_LIST_HEAD(&wcd
->rx_chs
[i
].list
);
2005 wcd
->num_tx_port
= tx_num
;
2006 for (i
= 0; i
< tx_num
; i
++) {
2007 wcd
->tx_chs
[i
].ch_num
= tx_slot
[i
];
2008 INIT_LIST_HEAD(&wcd
->tx_chs
[i
].list
);
2014 static int wcd9335_get_channel_map(struct snd_soc_dai
*dai
,
2015 unsigned int *tx_num
, unsigned int *tx_slot
,
2016 unsigned int *rx_num
, unsigned int *rx_slot
)
2018 struct wcd9335_slim_ch
*ch
;
2019 struct wcd9335_codec
*wcd
;
2022 wcd
= snd_soc_component_get_drvdata(dai
->component
);
2029 if (!rx_slot
|| !rx_num
) {
2030 dev_err(wcd
->dev
, "Invalid rx_slot %p or rx_num %p\n",
2035 list_for_each_entry(ch
, &wcd
->dai
[dai
->id
].slim_ch_list
, list
)
2036 rx_slot
[i
++] = ch
->ch_num
;
2043 if (!tx_slot
|| !tx_num
) {
2044 dev_err(wcd
->dev
, "Invalid tx_slot %p or tx_num %p\n",
2048 list_for_each_entry(ch
, &wcd
->dai
[dai
->id
].slim_ch_list
, list
)
2049 tx_slot
[i
++] = ch
->ch_num
;
2054 dev_err(wcd
->dev
, "Invalid DAI ID %x\n", dai
->id
);
2061 static struct snd_soc_dai_ops wcd9335_dai_ops
= {
2062 .hw_params
= wcd9335_hw_params
,
2063 .trigger
= wcd9335_trigger
,
2064 .set_channel_map
= wcd9335_set_channel_map
,
2065 .get_channel_map
= wcd9335_get_channel_map
,
2068 static struct snd_soc_dai_driver wcd9335_slim_dais
[] = {
2070 .name
= "wcd9335_rx1",
2073 .stream_name
= "AIF1 Playback",
2074 .rates
= WCD9335_RATES_MASK
| WCD9335_FRAC_RATES_MASK
|
2075 SNDRV_PCM_RATE_384000
,
2076 .formats
= WCD9335_FORMATS_S16_S24_LE
,
2082 .ops
= &wcd9335_dai_ops
,
2085 .name
= "wcd9335_tx1",
2088 .stream_name
= "AIF1 Capture",
2089 .rates
= WCD9335_RATES_MASK
,
2090 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
2096 .ops
= &wcd9335_dai_ops
,
2099 .name
= "wcd9335_rx2",
2102 .stream_name
= "AIF2 Playback",
2103 .rates
= WCD9335_RATES_MASK
| WCD9335_FRAC_RATES_MASK
|
2104 SNDRV_PCM_RATE_384000
,
2105 .formats
= WCD9335_FORMATS_S16_S24_LE
,
2111 .ops
= &wcd9335_dai_ops
,
2114 .name
= "wcd9335_tx2",
2117 .stream_name
= "AIF2 Capture",
2118 .rates
= WCD9335_RATES_MASK
,
2119 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
2125 .ops
= &wcd9335_dai_ops
,
2128 .name
= "wcd9335_rx3",
2131 .stream_name
= "AIF3 Playback",
2132 .rates
= WCD9335_RATES_MASK
| WCD9335_FRAC_RATES_MASK
|
2133 SNDRV_PCM_RATE_384000
,
2134 .formats
= WCD9335_FORMATS_S16_S24_LE
,
2140 .ops
= &wcd9335_dai_ops
,
2143 .name
= "wcd9335_tx3",
2146 .stream_name
= "AIF3 Capture",
2147 .rates
= WCD9335_RATES_MASK
,
2148 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
2154 .ops
= &wcd9335_dai_ops
,
2157 .name
= "wcd9335_rx4",
2160 .stream_name
= "AIF4 Playback",
2161 .rates
= WCD9335_RATES_MASK
| WCD9335_FRAC_RATES_MASK
|
2162 SNDRV_PCM_RATE_384000
,
2163 .formats
= WCD9335_FORMATS_S16_S24_LE
,
2169 .ops
= &wcd9335_dai_ops
,
2173 static int wcd9335_get_compander(struct snd_kcontrol
*kc
,
2174 struct snd_ctl_elem_value
*ucontrol
)
2177 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kc
);
2178 int comp
= ((struct soc_mixer_control
*)kc
->private_value
)->shift
;
2179 struct wcd9335_codec
*wcd
= dev_get_drvdata(component
->dev
);
2181 ucontrol
->value
.integer
.value
[0] = wcd
->comp_enabled
[comp
];
2185 static int wcd9335_set_compander(struct snd_kcontrol
*kc
,
2186 struct snd_ctl_elem_value
*ucontrol
)
2188 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kc
);
2189 struct wcd9335_codec
*wcd
= dev_get_drvdata(component
->dev
);
2190 int comp
= ((struct soc_mixer_control
*) kc
->private_value
)->shift
;
2191 int value
= ucontrol
->value
.integer
.value
[0];
2194 wcd
->comp_enabled
[comp
] = value
;
2195 sel
= value
? WCD9335_HPH_GAIN_SRC_SEL_COMPANDER
:
2196 WCD9335_HPH_GAIN_SRC_SEL_REGISTER
;
2198 /* Any specific register configuration for compander */
2201 /* Set Gain Source Select based on compander enable/disable */
2202 snd_soc_component_update_bits(component
, WCD9335_HPH_L_EN
,
2203 WCD9335_HPH_GAIN_SRC_SEL_MASK
, sel
);
2206 snd_soc_component_update_bits(component
, WCD9335_HPH_R_EN
,
2207 WCD9335_HPH_GAIN_SRC_SEL_MASK
, sel
);
2210 snd_soc_component_update_bits(component
, WCD9335_SE_LO_LO3_GAIN
,
2211 WCD9335_HPH_GAIN_SRC_SEL_MASK
, sel
);
2214 snd_soc_component_update_bits(component
, WCD9335_SE_LO_LO4_GAIN
,
2215 WCD9335_HPH_GAIN_SRC_SEL_MASK
, sel
);
2224 static int wcd9335_rx_hph_mode_get(struct snd_kcontrol
*kc
,
2225 struct snd_ctl_elem_value
*ucontrol
)
2227 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kc
);
2228 struct wcd9335_codec
*wcd
= dev_get_drvdata(component
->dev
);
2230 ucontrol
->value
.enumerated
.item
[0] = wcd
->hph_mode
;
2235 static int wcd9335_rx_hph_mode_put(struct snd_kcontrol
*kc
,
2236 struct snd_ctl_elem_value
*ucontrol
)
2238 struct snd_soc_component
*component
= snd_soc_kcontrol_component(kc
);
2239 struct wcd9335_codec
*wcd
= dev_get_drvdata(component
->dev
);
2242 mode_val
= ucontrol
->value
.enumerated
.item
[0];
2244 if (mode_val
== 0) {
2245 dev_err(wcd
->dev
, "Invalid HPH Mode, default to ClSH HiFi\n");
2246 mode_val
= CLS_H_HIFI
;
2248 wcd
->hph_mode
= mode_val
;
2253 static const struct snd_kcontrol_new wcd9335_snd_controls
[] = {
2254 /* -84dB min - 40dB max */
2255 SOC_SINGLE_SX_TLV("RX0 Digital Volume", WCD9335_CDC_RX0_RX_VOL_CTL
,
2256 0, -84, 40, digital_gain
),
2257 SOC_SINGLE_SX_TLV("RX1 Digital Volume", WCD9335_CDC_RX1_RX_VOL_CTL
,
2258 0, -84, 40, digital_gain
),
2259 SOC_SINGLE_SX_TLV("RX2 Digital Volume", WCD9335_CDC_RX2_RX_VOL_CTL
,
2260 0, -84, 40, digital_gain
),
2261 SOC_SINGLE_SX_TLV("RX3 Digital Volume", WCD9335_CDC_RX3_RX_VOL_CTL
,
2262 0, -84, 40, digital_gain
),
2263 SOC_SINGLE_SX_TLV("RX4 Digital Volume", WCD9335_CDC_RX4_RX_VOL_CTL
,
2264 0, -84, 40, digital_gain
),
2265 SOC_SINGLE_SX_TLV("RX5 Digital Volume", WCD9335_CDC_RX5_RX_VOL_CTL
,
2266 0, -84, 40, digital_gain
),
2267 SOC_SINGLE_SX_TLV("RX6 Digital Volume", WCD9335_CDC_RX6_RX_VOL_CTL
,
2268 0, -84, 40, digital_gain
),
2269 SOC_SINGLE_SX_TLV("RX7 Digital Volume", WCD9335_CDC_RX7_RX_VOL_CTL
,
2270 0, -84, 40, digital_gain
),
2271 SOC_SINGLE_SX_TLV("RX8 Digital Volume", WCD9335_CDC_RX8_RX_VOL_CTL
,
2272 0, -84, 40, digital_gain
),
2273 SOC_SINGLE_SX_TLV("RX0 Mix Digital Volume",
2274 WCD9335_CDC_RX0_RX_VOL_MIX_CTL
,
2275 0, -84, 40, digital_gain
),
2276 SOC_SINGLE_SX_TLV("RX1 Mix Digital Volume",
2277 WCD9335_CDC_RX1_RX_VOL_MIX_CTL
,
2278 0, -84, 40, digital_gain
),
2279 SOC_SINGLE_SX_TLV("RX2 Mix Digital Volume",
2280 WCD9335_CDC_RX2_RX_VOL_MIX_CTL
,
2281 0, -84, 40, digital_gain
),
2282 SOC_SINGLE_SX_TLV("RX3 Mix Digital Volume",
2283 WCD9335_CDC_RX3_RX_VOL_MIX_CTL
,
2284 0, -84, 40, digital_gain
),
2285 SOC_SINGLE_SX_TLV("RX4 Mix Digital Volume",
2286 WCD9335_CDC_RX4_RX_VOL_MIX_CTL
,
2287 0, -84, 40, digital_gain
),
2288 SOC_SINGLE_SX_TLV("RX5 Mix Digital Volume",
2289 WCD9335_CDC_RX5_RX_VOL_MIX_CTL
,
2290 0, -84, 40, digital_gain
),
2291 SOC_SINGLE_SX_TLV("RX6 Mix Digital Volume",
2292 WCD9335_CDC_RX6_RX_VOL_MIX_CTL
,
2293 0, -84, 40, digital_gain
),
2294 SOC_SINGLE_SX_TLV("RX7 Mix Digital Volume",
2295 WCD9335_CDC_RX7_RX_VOL_MIX_CTL
,
2296 0, -84, 40, digital_gain
),
2297 SOC_SINGLE_SX_TLV("RX8 Mix Digital Volume",
2298 WCD9335_CDC_RX8_RX_VOL_MIX_CTL
,
2299 0, -84, 40, digital_gain
),
2300 SOC_ENUM("RX INT0_1 HPF cut off", cf_int0_1_enum
),
2301 SOC_ENUM("RX INT0_2 HPF cut off", cf_int0_2_enum
),
2302 SOC_ENUM("RX INT1_1 HPF cut off", cf_int1_1_enum
),
2303 SOC_ENUM("RX INT1_2 HPF cut off", cf_int1_2_enum
),
2304 SOC_ENUM("RX INT2_1 HPF cut off", cf_int2_1_enum
),
2305 SOC_ENUM("RX INT2_2 HPF cut off", cf_int2_2_enum
),
2306 SOC_ENUM("RX INT3_1 HPF cut off", cf_int3_1_enum
),
2307 SOC_ENUM("RX INT3_2 HPF cut off", cf_int3_2_enum
),
2308 SOC_ENUM("RX INT4_1 HPF cut off", cf_int4_1_enum
),
2309 SOC_ENUM("RX INT4_2 HPF cut off", cf_int4_2_enum
),
2310 SOC_ENUM("RX INT5_1 HPF cut off", cf_int5_1_enum
),
2311 SOC_ENUM("RX INT5_2 HPF cut off", cf_int5_2_enum
),
2312 SOC_ENUM("RX INT6_1 HPF cut off", cf_int6_1_enum
),
2313 SOC_ENUM("RX INT6_2 HPF cut off", cf_int6_2_enum
),
2314 SOC_ENUM("RX INT7_1 HPF cut off", cf_int7_1_enum
),
2315 SOC_ENUM("RX INT7_2 HPF cut off", cf_int7_2_enum
),
2316 SOC_ENUM("RX INT8_1 HPF cut off", cf_int8_1_enum
),
2317 SOC_ENUM("RX INT8_2 HPF cut off", cf_int8_2_enum
),
2318 SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM
, COMPANDER_1
, 1, 0,
2319 wcd9335_get_compander
, wcd9335_set_compander
),
2320 SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM
, COMPANDER_2
, 1, 0,
2321 wcd9335_get_compander
, wcd9335_set_compander
),
2322 SOC_SINGLE_EXT("COMP3 Switch", SND_SOC_NOPM
, COMPANDER_3
, 1, 0,
2323 wcd9335_get_compander
, wcd9335_set_compander
),
2324 SOC_SINGLE_EXT("COMP4 Switch", SND_SOC_NOPM
, COMPANDER_4
, 1, 0,
2325 wcd9335_get_compander
, wcd9335_set_compander
),
2326 SOC_SINGLE_EXT("COMP5 Switch", SND_SOC_NOPM
, COMPANDER_5
, 1, 0,
2327 wcd9335_get_compander
, wcd9335_set_compander
),
2328 SOC_SINGLE_EXT("COMP6 Switch", SND_SOC_NOPM
, COMPANDER_6
, 1, 0,
2329 wcd9335_get_compander
, wcd9335_set_compander
),
2330 SOC_SINGLE_EXT("COMP7 Switch", SND_SOC_NOPM
, COMPANDER_7
, 1, 0,
2331 wcd9335_get_compander
, wcd9335_set_compander
),
2332 SOC_SINGLE_EXT("COMP8 Switch", SND_SOC_NOPM
, COMPANDER_8
, 1, 0,
2333 wcd9335_get_compander
, wcd9335_set_compander
),
2334 SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum
,
2335 wcd9335_rx_hph_mode_get
, wcd9335_rx_hph_mode_put
),
2338 SOC_SINGLE_TLV("EAR PA Volume", WCD9335_ANA_EAR
, 4, 4, 1,
2340 SOC_SINGLE_TLV("HPHL Volume", WCD9335_HPH_L_EN
, 0, 20, 1,
2342 SOC_SINGLE_TLV("HPHR Volume", WCD9335_HPH_R_EN
, 0, 20, 1,
2344 SOC_SINGLE_TLV("LINEOUT1 Volume", WCD9335_DIFF_LO_LO1_COMPANDER
,
2345 3, 16, 1, line_gain
),
2346 SOC_SINGLE_TLV("LINEOUT2 Volume", WCD9335_DIFF_LO_LO2_COMPANDER
,
2347 3, 16, 1, line_gain
),
2348 SOC_SINGLE_TLV("LINEOUT3 Volume", WCD9335_SE_LO_LO3_GAIN
, 0, 20, 1,
2350 SOC_SINGLE_TLV("LINEOUT4 Volume", WCD9335_SE_LO_LO4_GAIN
, 0, 20, 1,
2353 SOC_SINGLE_TLV("ADC1 Volume", WCD9335_ANA_AMIC1
, 0, 20, 0,
2355 SOC_SINGLE_TLV("ADC2 Volume", WCD9335_ANA_AMIC2
, 0, 20, 0,
2357 SOC_SINGLE_TLV("ADC3 Volume", WCD9335_ANA_AMIC3
, 0, 20, 0,
2359 SOC_SINGLE_TLV("ADC4 Volume", WCD9335_ANA_AMIC4
, 0, 20, 0,
2361 SOC_SINGLE_TLV("ADC5 Volume", WCD9335_ANA_AMIC5
, 0, 20, 0,
2363 SOC_SINGLE_TLV("ADC6 Volume", WCD9335_ANA_AMIC6
, 0, 20, 0,
2366 SOC_ENUM("TX0 HPF cut off", cf_dec0_enum
),
2367 SOC_ENUM("TX1 HPF cut off", cf_dec1_enum
),
2368 SOC_ENUM("TX2 HPF cut off", cf_dec2_enum
),
2369 SOC_ENUM("TX3 HPF cut off", cf_dec3_enum
),
2370 SOC_ENUM("TX4 HPF cut off", cf_dec4_enum
),
2371 SOC_ENUM("TX5 HPF cut off", cf_dec5_enum
),
2372 SOC_ENUM("TX6 HPF cut off", cf_dec6_enum
),
2373 SOC_ENUM("TX7 HPF cut off", cf_dec7_enum
),
2374 SOC_ENUM("TX8 HPF cut off", cf_dec8_enum
),
2377 static const struct snd_soc_dapm_route wcd9335_audio_map
[] = {
2378 {"SLIM RX0 MUX", "AIF1_PB", "AIF1 PB"},
2379 {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"},
2380 {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"},
2381 {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"},
2382 {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"},
2383 {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"},
2384 {"SLIM RX6 MUX", "AIF1_PB", "AIF1 PB"},
2385 {"SLIM RX7 MUX", "AIF1_PB", "AIF1 PB"},
2387 {"SLIM RX0 MUX", "AIF2_PB", "AIF2 PB"},
2388 {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"},
2389 {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"},
2390 {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"},
2391 {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"},
2392 {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"},
2393 {"SLIM RX6 MUX", "AIF2_PB", "AIF2 PB"},
2394 {"SLIM RX7 MUX", "AIF2_PB", "AIF2 PB"},
2396 {"SLIM RX0 MUX", "AIF3_PB", "AIF3 PB"},
2397 {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"},
2398 {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"},
2399 {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"},
2400 {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"},
2401 {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"},
2402 {"SLIM RX6 MUX", "AIF3_PB", "AIF3 PB"},
2403 {"SLIM RX7 MUX", "AIF3_PB", "AIF3 PB"},
2405 {"SLIM RX0 MUX", "AIF4_PB", "AIF4 PB"},
2406 {"SLIM RX1 MUX", "AIF4_PB", "AIF4 PB"},
2407 {"SLIM RX2 MUX", "AIF4_PB", "AIF4 PB"},
2408 {"SLIM RX3 MUX", "AIF4_PB", "AIF4 PB"},
2409 {"SLIM RX4 MUX", "AIF4_PB", "AIF4 PB"},
2410 {"SLIM RX5 MUX", "AIF4_PB", "AIF4 PB"},
2411 {"SLIM RX6 MUX", "AIF4_PB", "AIF4 PB"},
2412 {"SLIM RX7 MUX", "AIF4_PB", "AIF4 PB"},
2414 {"SLIM RX0", NULL
, "SLIM RX0 MUX"},
2415 {"SLIM RX1", NULL
, "SLIM RX1 MUX"},
2416 {"SLIM RX2", NULL
, "SLIM RX2 MUX"},
2417 {"SLIM RX3", NULL
, "SLIM RX3 MUX"},
2418 {"SLIM RX4", NULL
, "SLIM RX4 MUX"},
2419 {"SLIM RX5", NULL
, "SLIM RX5 MUX"},
2420 {"SLIM RX6", NULL
, "SLIM RX6 MUX"},
2421 {"SLIM RX7", NULL
, "SLIM RX7 MUX"},
2423 WCD9335_INTERPOLATOR_PATH(0),
2424 WCD9335_INTERPOLATOR_PATH(1),
2425 WCD9335_INTERPOLATOR_PATH(2),
2426 WCD9335_INTERPOLATOR_PATH(3),
2427 WCD9335_INTERPOLATOR_PATH(4),
2428 WCD9335_INTERPOLATOR_PATH(5),
2429 WCD9335_INTERPOLATOR_PATH(6),
2430 WCD9335_INTERPOLATOR_PATH(7),
2431 WCD9335_INTERPOLATOR_PATH(8),
2434 {"RX INT0 DEM MUX", "CLSH_DSM_OUT", "RX INT0 INTERP"},
2435 {"RX INT0 DAC", NULL
, "RX INT0 DEM MUX"},
2436 {"RX INT0 DAC", NULL
, "RX_BIAS"},
2437 {"EAR PA", NULL
, "RX INT0 DAC"},
2438 {"EAR", NULL
, "EAR PA"},
2441 {"RX INT1 DEM MUX", "CLSH_DSM_OUT", "RX INT1 INTERP"},
2442 {"RX INT1 DAC", NULL
, "RX INT1 DEM MUX"},
2443 {"RX INT1 DAC", NULL
, "RX_BIAS"},
2444 {"HPHL PA", NULL
, "RX INT1 DAC"},
2445 {"HPHL", NULL
, "HPHL PA"},
2448 {"RX INT2 DEM MUX", "CLSH_DSM_OUT", "RX INT2 INTERP"},
2449 {"RX INT2 DAC", NULL
, "RX INT2 DEM MUX"},
2450 {"RX INT2 DAC", NULL
, "RX_BIAS"},
2451 {"HPHR PA", NULL
, "RX INT2 DAC"},
2452 {"HPHR", NULL
, "HPHR PA"},
2455 {"RX INT3 DAC", NULL
, "RX INT3 INTERP"},
2456 {"RX INT3 DAC", NULL
, "RX_BIAS"},
2457 {"LINEOUT1 PA", NULL
, "RX INT3 DAC"},
2458 {"LINEOUT1", NULL
, "LINEOUT1 PA"},
2461 {"RX INT4 DAC", NULL
, "RX INT4 INTERP"},
2462 {"RX INT4 DAC", NULL
, "RX_BIAS"},
2463 {"LINEOUT2 PA", NULL
, "RX INT4 DAC"},
2464 {"LINEOUT2", NULL
, "LINEOUT2 PA"},
2467 {"RX INT5 DAC", NULL
, "RX INT5 INTERP"},
2468 {"RX INT5 DAC", NULL
, "RX_BIAS"},
2469 {"LINEOUT3 PA", NULL
, "RX INT5 DAC"},
2470 {"LINEOUT3", NULL
, "LINEOUT3 PA"},
2473 {"RX INT6 DAC", NULL
, "RX INT6 INTERP"},
2474 {"RX INT6 DAC", NULL
, "RX_BIAS"},
2475 {"LINEOUT4 PA", NULL
, "RX INT6 DAC"},
2476 {"LINEOUT4", NULL
, "LINEOUT4 PA"},
2478 /* SLIMBUS Connections */
2479 {"AIF1 CAP", NULL
, "AIF1_CAP Mixer"},
2480 {"AIF2 CAP", NULL
, "AIF2_CAP Mixer"},
2481 {"AIF3 CAP", NULL
, "AIF3_CAP Mixer"},
2484 WCD9335_ADC_MUX_PATH(0),
2485 WCD9335_ADC_MUX_PATH(1),
2486 WCD9335_ADC_MUX_PATH(2),
2487 WCD9335_ADC_MUX_PATH(3),
2488 WCD9335_ADC_MUX_PATH(4),
2489 WCD9335_ADC_MUX_PATH(5),
2490 WCD9335_ADC_MUX_PATH(6),
2491 WCD9335_ADC_MUX_PATH(7),
2492 WCD9335_ADC_MUX_PATH(8),
2494 /* ADC Connections */
2495 {"ADC1", NULL
, "AMIC1"},
2496 {"ADC2", NULL
, "AMIC2"},
2497 {"ADC3", NULL
, "AMIC3"},
2498 {"ADC4", NULL
, "AMIC4"},
2499 {"ADC5", NULL
, "AMIC5"},
2500 {"ADC6", NULL
, "AMIC6"},
2503 static int wcd9335_micbias_control(struct snd_soc_component
*component
,
2504 int micb_num
, int req
, bool is_dapm
)
2506 struct wcd9335_codec
*wcd
= snd_soc_component_get_drvdata(component
);
2507 int micb_index
= micb_num
- 1;
2510 if ((micb_index
< 0) || (micb_index
> WCD9335_MAX_MICBIAS
- 1)) {
2511 dev_err(wcd
->dev
, "Invalid micbias index, micb_ind:%d\n",
2518 micb_reg
= WCD9335_ANA_MICB1
;
2521 micb_reg
= WCD9335_ANA_MICB2
;
2524 micb_reg
= WCD9335_ANA_MICB3
;
2527 micb_reg
= WCD9335_ANA_MICB4
;
2530 dev_err(component
->dev
, "%s: Invalid micbias number: %d\n",
2531 __func__
, micb_num
);
2536 case MICB_PULLUP_ENABLE
:
2537 wcd
->pullup_ref
[micb_index
]++;
2538 if ((wcd
->pullup_ref
[micb_index
] == 1) &&
2539 (wcd
->micb_ref
[micb_index
] == 0))
2540 snd_soc_component_update_bits(component
, micb_reg
,
2543 case MICB_PULLUP_DISABLE
:
2544 wcd
->pullup_ref
[micb_index
]--;
2545 if ((wcd
->pullup_ref
[micb_index
] == 0) &&
2546 (wcd
->micb_ref
[micb_index
] == 0))
2547 snd_soc_component_update_bits(component
, micb_reg
,
2551 wcd
->micb_ref
[micb_index
]++;
2552 if (wcd
->micb_ref
[micb_index
] == 1)
2553 snd_soc_component_update_bits(component
, micb_reg
,
2557 wcd
->micb_ref
[micb_index
]--;
2558 if ((wcd
->micb_ref
[micb_index
] == 0) &&
2559 (wcd
->pullup_ref
[micb_index
] > 0))
2560 snd_soc_component_update_bits(component
, micb_reg
,
2562 else if ((wcd
->micb_ref
[micb_index
] == 0) &&
2563 (wcd
->pullup_ref
[micb_index
] == 0)) {
2564 snd_soc_component_update_bits(component
, micb_reg
,
2573 static int __wcd9335_codec_enable_micbias(struct snd_soc_dapm_widget
*w
,
2576 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
2579 if (strnstr(w
->name
, "MIC BIAS1", sizeof("MIC BIAS1")))
2580 micb_num
= MIC_BIAS_1
;
2581 else if (strnstr(w
->name
, "MIC BIAS2", sizeof("MIC BIAS2")))
2582 micb_num
= MIC_BIAS_2
;
2583 else if (strnstr(w
->name
, "MIC BIAS3", sizeof("MIC BIAS3")))
2584 micb_num
= MIC_BIAS_3
;
2585 else if (strnstr(w
->name
, "MIC BIAS4", sizeof("MIC BIAS4")))
2586 micb_num
= MIC_BIAS_4
;
2591 case SND_SOC_DAPM_PRE_PMU
:
2593 * MIC BIAS can also be requested by MBHC,
2594 * so use ref count to handle micbias pullup
2595 * and enable requests
2597 wcd9335_micbias_control(comp
, micb_num
, MICB_ENABLE
, true);
2599 case SND_SOC_DAPM_POST_PMU
:
2600 /* wait for cnp time */
2601 usleep_range(1000, 1100);
2603 case SND_SOC_DAPM_POST_PMD
:
2604 wcd9335_micbias_control(comp
, micb_num
, MICB_DISABLE
, true);
2611 static int wcd9335_codec_enable_micbias(struct snd_soc_dapm_widget
*w
,
2612 struct snd_kcontrol
*kc
, int event
)
2614 return __wcd9335_codec_enable_micbias(w
, event
);
2617 static void wcd9335_codec_set_tx_hold(struct snd_soc_component
*comp
,
2618 u16 amic_reg
, bool set
)
2623 if (amic_reg
== WCD9335_ANA_AMIC1
|| amic_reg
== WCD9335_ANA_AMIC3
||
2624 amic_reg
== WCD9335_ANA_AMIC5
)
2627 val
= set
? mask
: 0x00;
2630 case WCD9335_ANA_AMIC1
:
2631 case WCD9335_ANA_AMIC2
:
2632 snd_soc_component_update_bits(comp
, WCD9335_ANA_AMIC2
, mask
,
2635 case WCD9335_ANA_AMIC3
:
2636 case WCD9335_ANA_AMIC4
:
2637 snd_soc_component_update_bits(comp
, WCD9335_ANA_AMIC4
, mask
,
2640 case WCD9335_ANA_AMIC5
:
2641 case WCD9335_ANA_AMIC6
:
2642 snd_soc_component_update_bits(comp
, WCD9335_ANA_AMIC6
, mask
,
2646 dev_err(comp
->dev
, "%s: invalid amic: %d\n",
2647 __func__
, amic_reg
);
2652 static int wcd9335_codec_enable_adc(struct snd_soc_dapm_widget
*w
,
2653 struct snd_kcontrol
*kc
, int event
)
2655 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
2658 case SND_SOC_DAPM_PRE_PMU
:
2659 wcd9335_codec_set_tx_hold(comp
, w
->reg
, true);
2668 static int wcd9335_codec_find_amic_input(struct snd_soc_component
*comp
,
2671 int mux_sel
, reg
, mreg
;
2673 if (adc_mux_n
< 0 || adc_mux_n
> WCD9335_MAX_VALID_ADC_MUX
||
2674 adc_mux_n
== WCD9335_INVALID_ADC_MUX
)
2677 /* Check whether adc mux input is AMIC or DMIC */
2678 if (adc_mux_n
< 4) {
2679 reg
= WCD9335_CDC_TX_INP_MUX_ADC_MUX0_CFG1
+ 2 * adc_mux_n
;
2680 mreg
= WCD9335_CDC_TX_INP_MUX_ADC_MUX0_CFG0
+ 2 * adc_mux_n
;
2681 mux_sel
= snd_soc_component_read32(comp
, reg
) & 0x3;
2683 reg
= WCD9335_CDC_TX_INP_MUX_ADC_MUX4_CFG0
+ adc_mux_n
- 4;
2685 mux_sel
= snd_soc_component_read32(comp
, reg
) >> 6;
2688 if (mux_sel
!= WCD9335_CDC_TX_INP_MUX_SEL_AMIC
)
2691 return snd_soc_component_read32(comp
, mreg
) & 0x07;
2694 static u16
wcd9335_codec_get_amic_pwlvl_reg(struct snd_soc_component
*comp
,
2697 u16 pwr_level_reg
= 0;
2702 pwr_level_reg
= WCD9335_ANA_AMIC1
;
2707 pwr_level_reg
= WCD9335_ANA_AMIC3
;
2712 pwr_level_reg
= WCD9335_ANA_AMIC5
;
2715 dev_err(comp
->dev
, "invalid amic: %d\n", amic
);
2719 return pwr_level_reg
;
2722 static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget
*w
,
2723 struct snd_kcontrol
*kc
, int event
)
2725 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
2726 unsigned int decimator
;
2727 char *dec_adc_mux_name
= NULL
;
2728 char *widget_name
= NULL
;
2730 int ret
= 0, amic_n
;
2731 u16 tx_vol_ctl_reg
, pwr_level_reg
= 0, dec_cfg_reg
, hpf_gate_reg
;
2732 u16 tx_gain_ctl_reg
;
2736 widget_name
= kmemdup_nul(w
->name
, 15, GFP_KERNEL
);
2740 wname
= widget_name
;
2741 dec_adc_mux_name
= strsep(&widget_name
, " ");
2742 if (!dec_adc_mux_name
) {
2743 dev_err(comp
->dev
, "%s: Invalid decimator = %s\n",
2748 dec_adc_mux_name
= widget_name
;
2750 dec
= strpbrk(dec_adc_mux_name
, "012345678");
2752 dev_err(comp
->dev
, "%s: decimator index not found\n",
2758 ret
= kstrtouint(dec
, 10, &decimator
);
2760 dev_err(comp
->dev
, "%s: Invalid decimator = %s\n",
2766 tx_vol_ctl_reg
= WCD9335_CDC_TX0_TX_PATH_CTL
+ 16 * decimator
;
2767 hpf_gate_reg
= WCD9335_CDC_TX0_TX_PATH_SEC2
+ 16 * decimator
;
2768 dec_cfg_reg
= WCD9335_CDC_TX0_TX_PATH_CFG0
+ 16 * decimator
;
2769 tx_gain_ctl_reg
= WCD9335_CDC_TX0_TX_VOL_CTL
+ 16 * decimator
;
2772 case SND_SOC_DAPM_PRE_PMU
:
2773 amic_n
= wcd9335_codec_find_amic_input(comp
, decimator
);
2775 pwr_level_reg
= wcd9335_codec_get_amic_pwlvl_reg(comp
,
2778 if (pwr_level_reg
) {
2779 switch ((snd_soc_component_read32(comp
, pwr_level_reg
) &
2780 WCD9335_AMIC_PWR_LVL_MASK
) >>
2781 WCD9335_AMIC_PWR_LVL_SHIFT
) {
2782 case WCD9335_AMIC_PWR_LEVEL_LP
:
2783 snd_soc_component_update_bits(comp
, dec_cfg_reg
,
2784 WCD9335_DEC_PWR_LVL_MASK
,
2785 WCD9335_DEC_PWR_LVL_LP
);
2788 case WCD9335_AMIC_PWR_LEVEL_HP
:
2789 snd_soc_component_update_bits(comp
, dec_cfg_reg
,
2790 WCD9335_DEC_PWR_LVL_MASK
,
2791 WCD9335_DEC_PWR_LVL_HP
);
2793 case WCD9335_AMIC_PWR_LEVEL_DEFAULT
:
2795 snd_soc_component_update_bits(comp
, dec_cfg_reg
,
2796 WCD9335_DEC_PWR_LVL_MASK
,
2797 WCD9335_DEC_PWR_LVL_DF
);
2801 hpf_coff_freq
= (snd_soc_component_read32(comp
, dec_cfg_reg
) &
2802 TX_HPF_CUT_OFF_FREQ_MASK
) >> 5;
2804 if (hpf_coff_freq
!= CF_MIN_3DB_150HZ
)
2805 snd_soc_component_update_bits(comp
, dec_cfg_reg
,
2806 TX_HPF_CUT_OFF_FREQ_MASK
,
2807 CF_MIN_3DB_150HZ
<< 5);
2808 /* Enable TX PGA Mute */
2809 snd_soc_component_update_bits(comp
, tx_vol_ctl_reg
,
2812 snd_soc_component_update_bits(comp
, dec_cfg_reg
, 0x08, 0x08);
2814 case SND_SOC_DAPM_POST_PMU
:
2815 snd_soc_component_update_bits(comp
, hpf_gate_reg
, 0x01, 0x00);
2817 if (decimator
== 0) {
2818 snd_soc_component_write(comp
,
2819 WCD9335_MBHC_ZDET_RAMP_CTL
, 0x83);
2820 snd_soc_component_write(comp
,
2821 WCD9335_MBHC_ZDET_RAMP_CTL
, 0xA3);
2822 snd_soc_component_write(comp
,
2823 WCD9335_MBHC_ZDET_RAMP_CTL
, 0x83);
2824 snd_soc_component_write(comp
,
2825 WCD9335_MBHC_ZDET_RAMP_CTL
, 0x03);
2828 snd_soc_component_update_bits(comp
, hpf_gate_reg
,
2830 snd_soc_component_update_bits(comp
, tx_vol_ctl_reg
,
2832 snd_soc_component_write(comp
, tx_gain_ctl_reg
,
2833 snd_soc_component_read32(comp
, tx_gain_ctl_reg
));
2835 case SND_SOC_DAPM_PRE_PMD
:
2836 hpf_coff_freq
= (snd_soc_component_read32(comp
, dec_cfg_reg
) &
2837 TX_HPF_CUT_OFF_FREQ_MASK
) >> 5;
2838 snd_soc_component_update_bits(comp
, tx_vol_ctl_reg
, 0x10, 0x10);
2839 snd_soc_component_update_bits(comp
, dec_cfg_reg
, 0x08, 0x00);
2840 if (hpf_coff_freq
!= CF_MIN_3DB_150HZ
) {
2841 snd_soc_component_update_bits(comp
, dec_cfg_reg
,
2842 TX_HPF_CUT_OFF_FREQ_MASK
,
2843 hpf_coff_freq
<< 5);
2846 case SND_SOC_DAPM_POST_PMD
:
2847 snd_soc_component_update_bits(comp
, tx_vol_ctl_reg
, 0x10, 0x00);
2855 static u8
wcd9335_get_dmic_clk_val(struct snd_soc_component
*component
,
2856 u32 mclk_rate
, u32 dmic_clk_rate
)
2861 dev_err(component
->dev
,
2862 "%s: mclk_rate = %d, dmic_sample_rate = %d\n",
2863 __func__
, mclk_rate
, dmic_clk_rate
);
2865 /* Default value to return in case of error */
2866 if (mclk_rate
== WCD9335_MCLK_CLK_9P6MHZ
)
2867 dmic_ctl_val
= WCD9335_DMIC_CLK_DIV_2
;
2869 dmic_ctl_val
= WCD9335_DMIC_CLK_DIV_3
;
2871 if (dmic_clk_rate
== 0) {
2872 dev_err(component
->dev
,
2873 "%s: dmic_sample_rate cannot be 0\n",
2878 div_factor
= mclk_rate
/ dmic_clk_rate
;
2879 switch (div_factor
) {
2881 dmic_ctl_val
= WCD9335_DMIC_CLK_DIV_2
;
2884 dmic_ctl_val
= WCD9335_DMIC_CLK_DIV_3
;
2887 dmic_ctl_val
= WCD9335_DMIC_CLK_DIV_4
;
2890 dmic_ctl_val
= WCD9335_DMIC_CLK_DIV_6
;
2893 dmic_ctl_val
= WCD9335_DMIC_CLK_DIV_8
;
2896 dmic_ctl_val
= WCD9335_DMIC_CLK_DIV_16
;
2899 dev_err(component
->dev
,
2900 "%s: Invalid div_factor %u, clk_rate(%u), dmic_rate(%u)\n",
2901 __func__
, div_factor
, mclk_rate
, dmic_clk_rate
);
2906 return dmic_ctl_val
;
2909 static int wcd9335_codec_enable_dmic(struct snd_soc_dapm_widget
*w
,
2910 struct snd_kcontrol
*kc
, int event
)
2912 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
2913 struct wcd9335_codec
*wcd
= snd_soc_component_get_drvdata(comp
);
2914 u8 dmic_clk_en
= 0x01;
2917 u8 dmic_rate_val
, dmic_rate_shift
= 1;
2922 wname
= strpbrk(w
->name
, "012345");
2924 dev_err(comp
->dev
, "%s: widget not found\n", __func__
);
2928 ret
= kstrtouint(wname
, 10, &dmic
);
2930 dev_err(comp
->dev
, "%s: Invalid DMIC line on the codec\n",
2938 dmic_clk_cnt
= &(wcd
->dmic_0_1_clk_cnt
);
2939 dmic_clk_reg
= WCD9335_CPE_SS_DMIC0_CTL
;
2943 dmic_clk_cnt
= &(wcd
->dmic_2_3_clk_cnt
);
2944 dmic_clk_reg
= WCD9335_CPE_SS_DMIC1_CTL
;
2948 dmic_clk_cnt
= &(wcd
->dmic_4_5_clk_cnt
);
2949 dmic_clk_reg
= WCD9335_CPE_SS_DMIC2_CTL
;
2952 dev_err(comp
->dev
, "%s: Invalid DMIC Selection\n",
2958 case SND_SOC_DAPM_PRE_PMU
:
2960 wcd9335_get_dmic_clk_val(comp
,
2962 wcd
->dmic_sample_rate
);
2965 if (*dmic_clk_cnt
== 1) {
2966 snd_soc_component_update_bits(comp
, dmic_clk_reg
,
2967 0x07 << dmic_rate_shift
,
2968 dmic_rate_val
<< dmic_rate_shift
);
2969 snd_soc_component_update_bits(comp
, dmic_clk_reg
,
2970 dmic_clk_en
, dmic_clk_en
);
2974 case SND_SOC_DAPM_POST_PMD
:
2976 wcd9335_get_dmic_clk_val(comp
,
2978 wcd
->mad_dmic_sample_rate
);
2980 if (*dmic_clk_cnt
== 0) {
2981 snd_soc_component_update_bits(comp
, dmic_clk_reg
,
2983 snd_soc_component_update_bits(comp
, dmic_clk_reg
,
2984 0x07 << dmic_rate_shift
,
2985 dmic_rate_val
<< dmic_rate_shift
);
2993 static void wcd9335_codec_enable_int_port(struct wcd_slim_codec_dai_data
*dai
,
2994 struct snd_soc_component
*component
)
2997 unsigned short reg
= 0;
2998 unsigned int val
= 0;
2999 struct wcd9335_codec
*wcd
= dev_get_drvdata(component
->dev
);
3000 struct wcd9335_slim_ch
*ch
;
3002 list_for_each_entry(ch
, &dai
->slim_ch_list
, list
) {
3003 if (ch
->port
>= WCD9335_RX_START
) {
3004 port_num
= ch
->port
- WCD9335_RX_START
;
3005 reg
= WCD9335_SLIM_PGD_PORT_INT_EN0
+ (port_num
/ 8);
3007 port_num
= ch
->port
;
3008 reg
= WCD9335_SLIM_PGD_PORT_INT_TX_EN0
+ (port_num
/ 8);
3011 regmap_read(wcd
->if_regmap
, reg
, &val
);
3012 if (!(val
& BIT(port_num
% 8)))
3013 regmap_write(wcd
->if_regmap
, reg
,
3014 val
| BIT(port_num
% 8));
3018 static int wcd9335_codec_enable_slim(struct snd_soc_dapm_widget
*w
,
3019 struct snd_kcontrol
*kc
,
3022 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
3023 struct wcd9335_codec
*wcd
= snd_soc_component_get_drvdata(comp
);
3024 struct wcd_slim_codec_dai_data
*dai
= &wcd
->dai
[w
->shift
];
3027 case SND_SOC_DAPM_POST_PMU
:
3028 wcd9335_codec_enable_int_port(dai
, comp
);
3030 case SND_SOC_DAPM_POST_PMD
:
3031 kfree(dai
->sconfig
.chs
);
3039 static int wcd9335_codec_enable_mix_path(struct snd_soc_dapm_widget
*w
,
3040 struct snd_kcontrol
*kc
, int event
)
3042 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
3048 case WCD9335_CDC_RX0_RX_PATH_MIX_CTL
:
3049 gain_reg
= WCD9335_CDC_RX0_RX_VOL_MIX_CTL
;
3051 case WCD9335_CDC_RX1_RX_PATH_MIX_CTL
:
3052 gain_reg
= WCD9335_CDC_RX1_RX_VOL_MIX_CTL
;
3054 case WCD9335_CDC_RX2_RX_PATH_MIX_CTL
:
3055 gain_reg
= WCD9335_CDC_RX2_RX_VOL_MIX_CTL
;
3057 case WCD9335_CDC_RX3_RX_PATH_MIX_CTL
:
3058 gain_reg
= WCD9335_CDC_RX3_RX_VOL_MIX_CTL
;
3060 case WCD9335_CDC_RX4_RX_PATH_MIX_CTL
:
3061 gain_reg
= WCD9335_CDC_RX4_RX_VOL_MIX_CTL
;
3063 case WCD9335_CDC_RX5_RX_PATH_MIX_CTL
:
3064 gain_reg
= WCD9335_CDC_RX5_RX_VOL_MIX_CTL
;
3066 case WCD9335_CDC_RX6_RX_PATH_MIX_CTL
:
3067 gain_reg
= WCD9335_CDC_RX6_RX_VOL_MIX_CTL
;
3069 case WCD9335_CDC_RX7_RX_PATH_MIX_CTL
:
3070 gain_reg
= WCD9335_CDC_RX7_RX_VOL_MIX_CTL
;
3072 case WCD9335_CDC_RX8_RX_PATH_MIX_CTL
:
3073 gain_reg
= WCD9335_CDC_RX8_RX_VOL_MIX_CTL
;
3076 dev_err(comp
->dev
, "%s: No gain register avail for %s\n",
3082 case SND_SOC_DAPM_POST_PMU
:
3083 val
= snd_soc_component_read32(comp
, gain_reg
);
3085 snd_soc_component_write(comp
, gain_reg
, val
);
3087 case SND_SOC_DAPM_POST_PMD
:
3094 static u16
wcd9335_interp_get_primary_reg(u16 reg
, u16
*ind
)
3096 u16 prim_int_reg
= WCD9335_CDC_RX0_RX_PATH_CTL
;
3099 case WCD9335_CDC_RX0_RX_PATH_CTL
:
3100 case WCD9335_CDC_RX0_RX_PATH_MIX_CTL
:
3101 prim_int_reg
= WCD9335_CDC_RX0_RX_PATH_CTL
;
3104 case WCD9335_CDC_RX1_RX_PATH_CTL
:
3105 case WCD9335_CDC_RX1_RX_PATH_MIX_CTL
:
3106 prim_int_reg
= WCD9335_CDC_RX1_RX_PATH_CTL
;
3109 case WCD9335_CDC_RX2_RX_PATH_CTL
:
3110 case WCD9335_CDC_RX2_RX_PATH_MIX_CTL
:
3111 prim_int_reg
= WCD9335_CDC_RX2_RX_PATH_CTL
;
3114 case WCD9335_CDC_RX3_RX_PATH_CTL
:
3115 case WCD9335_CDC_RX3_RX_PATH_MIX_CTL
:
3116 prim_int_reg
= WCD9335_CDC_RX3_RX_PATH_CTL
;
3119 case WCD9335_CDC_RX4_RX_PATH_CTL
:
3120 case WCD9335_CDC_RX4_RX_PATH_MIX_CTL
:
3121 prim_int_reg
= WCD9335_CDC_RX4_RX_PATH_CTL
;
3124 case WCD9335_CDC_RX5_RX_PATH_CTL
:
3125 case WCD9335_CDC_RX5_RX_PATH_MIX_CTL
:
3126 prim_int_reg
= WCD9335_CDC_RX5_RX_PATH_CTL
;
3129 case WCD9335_CDC_RX6_RX_PATH_CTL
:
3130 case WCD9335_CDC_RX6_RX_PATH_MIX_CTL
:
3131 prim_int_reg
= WCD9335_CDC_RX6_RX_PATH_CTL
;
3134 case WCD9335_CDC_RX7_RX_PATH_CTL
:
3135 case WCD9335_CDC_RX7_RX_PATH_MIX_CTL
:
3136 prim_int_reg
= WCD9335_CDC_RX7_RX_PATH_CTL
;
3139 case WCD9335_CDC_RX8_RX_PATH_CTL
:
3140 case WCD9335_CDC_RX8_RX_PATH_MIX_CTL
:
3141 prim_int_reg
= WCD9335_CDC_RX8_RX_PATH_CTL
;
3146 return prim_int_reg
;
3149 static void wcd9335_codec_hd2_control(struct snd_soc_component
*component
,
3150 u16 prim_int_reg
, int event
)
3153 u16 hd2_enable_reg
= 0;
3155 if (prim_int_reg
== WCD9335_CDC_RX1_RX_PATH_CTL
) {
3156 hd2_scale_reg
= WCD9335_CDC_RX1_RX_PATH_SEC3
;
3157 hd2_enable_reg
= WCD9335_CDC_RX1_RX_PATH_CFG0
;
3159 if (prim_int_reg
== WCD9335_CDC_RX2_RX_PATH_CTL
) {
3160 hd2_scale_reg
= WCD9335_CDC_RX2_RX_PATH_SEC3
;
3161 hd2_enable_reg
= WCD9335_CDC_RX2_RX_PATH_CFG0
;
3164 if (hd2_enable_reg
&& SND_SOC_DAPM_EVENT_ON(event
)) {
3165 snd_soc_component_update_bits(component
, hd2_scale_reg
,
3166 WCD9335_CDC_RX_PATH_SEC_HD2_ALPHA_MASK
,
3167 WCD9335_CDC_RX_PATH_SEC_HD2_ALPHA_0P2500
);
3168 snd_soc_component_update_bits(component
, hd2_scale_reg
,
3169 WCD9335_CDC_RX_PATH_SEC_HD2_SCALE_MASK
,
3170 WCD9335_CDC_RX_PATH_SEC_HD2_SCALE_2
);
3171 snd_soc_component_update_bits(component
, hd2_enable_reg
,
3172 WCD9335_CDC_RX_PATH_CFG_HD2_EN_MASK
,
3173 WCD9335_CDC_RX_PATH_CFG_HD2_ENABLE
);
3176 if (hd2_enable_reg
&& SND_SOC_DAPM_EVENT_OFF(event
)) {
3177 snd_soc_component_update_bits(component
, hd2_enable_reg
,
3178 WCD9335_CDC_RX_PATH_CFG_HD2_EN_MASK
,
3179 WCD9335_CDC_RX_PATH_CFG_HD2_DISABLE
);
3180 snd_soc_component_update_bits(component
, hd2_scale_reg
,
3181 WCD9335_CDC_RX_PATH_SEC_HD2_SCALE_MASK
,
3182 WCD9335_CDC_RX_PATH_SEC_HD2_SCALE_1
);
3183 snd_soc_component_update_bits(component
, hd2_scale_reg
,
3184 WCD9335_CDC_RX_PATH_SEC_HD2_ALPHA_MASK
,
3185 WCD9335_CDC_RX_PATH_SEC_HD2_ALPHA_0P0000
);
3189 static int wcd9335_codec_enable_prim_interpolator(
3190 struct snd_soc_component
*comp
,
3193 struct wcd9335_codec
*wcd
= dev_get_drvdata(comp
->dev
);
3195 int prim_int_reg
= wcd9335_interp_get_primary_reg(reg
, &ind
);
3198 case SND_SOC_DAPM_PRE_PMU
:
3199 wcd
->prim_int_users
[ind
]++;
3200 if (wcd
->prim_int_users
[ind
] == 1) {
3201 snd_soc_component_update_bits(comp
, prim_int_reg
,
3202 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
,
3203 WCD9335_CDC_RX_PGA_MUTE_ENABLE
);
3204 wcd9335_codec_hd2_control(comp
, prim_int_reg
, event
);
3205 snd_soc_component_update_bits(comp
, prim_int_reg
,
3206 WCD9335_CDC_RX_CLK_EN_MASK
,
3207 WCD9335_CDC_RX_CLK_ENABLE
);
3210 if ((reg
!= prim_int_reg
) &&
3211 ((snd_soc_component_read32(comp
, prim_int_reg
)) &
3212 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
))
3213 snd_soc_component_update_bits(comp
, reg
,
3214 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
,
3215 WCD9335_CDC_RX_PGA_MUTE_ENABLE
);
3217 case SND_SOC_DAPM_POST_PMD
:
3218 wcd
->prim_int_users
[ind
]--;
3219 if (wcd
->prim_int_users
[ind
] == 0) {
3220 snd_soc_component_update_bits(comp
, prim_int_reg
,
3221 WCD9335_CDC_RX_CLK_EN_MASK
,
3222 WCD9335_CDC_RX_CLK_DISABLE
);
3223 snd_soc_component_update_bits(comp
, prim_int_reg
,
3224 WCD9335_CDC_RX_RESET_MASK
,
3225 WCD9335_CDC_RX_RESET_ENABLE
);
3226 snd_soc_component_update_bits(comp
, prim_int_reg
,
3227 WCD9335_CDC_RX_RESET_MASK
,
3228 WCD9335_CDC_RX_RESET_DISABLE
);
3229 wcd9335_codec_hd2_control(comp
, prim_int_reg
, event
);
3237 static int wcd9335_config_compander(struct snd_soc_component
*component
,
3238 int interp_n
, int event
)
3240 struct wcd9335_codec
*wcd
= dev_get_drvdata(component
->dev
);
3242 u16 comp_ctl0_reg
, rx_path_cfg0_reg
;
3244 /* EAR does not have compander */
3248 comp
= interp_n
- 1;
3249 if (!wcd
->comp_enabled
[comp
])
3252 comp_ctl0_reg
= WCD9335_CDC_COMPANDER1_CTL(comp
);
3253 rx_path_cfg0_reg
= WCD9335_CDC_RX1_RX_PATH_CFG(comp
);
3255 if (SND_SOC_DAPM_EVENT_ON(event
)) {
3256 /* Enable Compander Clock */
3257 snd_soc_component_update_bits(component
, comp_ctl0_reg
,
3258 WCD9335_CDC_COMPANDER_CLK_EN_MASK
,
3259 WCD9335_CDC_COMPANDER_CLK_ENABLE
);
3260 /* Reset comander */
3261 snd_soc_component_update_bits(component
, comp_ctl0_reg
,
3262 WCD9335_CDC_COMPANDER_SOFT_RST_MASK
,
3263 WCD9335_CDC_COMPANDER_SOFT_RST_ENABLE
);
3264 snd_soc_component_update_bits(component
, comp_ctl0_reg
,
3265 WCD9335_CDC_COMPANDER_SOFT_RST_MASK
,
3266 WCD9335_CDC_COMPANDER_SOFT_RST_DISABLE
);
3267 /* Enables DRE in this path */
3268 snd_soc_component_update_bits(component
, rx_path_cfg0_reg
,
3269 WCD9335_CDC_RX_PATH_CFG_CMP_EN_MASK
,
3270 WCD9335_CDC_RX_PATH_CFG_CMP_ENABLE
);
3273 if (SND_SOC_DAPM_EVENT_OFF(event
)) {
3274 snd_soc_component_update_bits(component
, comp_ctl0_reg
,
3275 WCD9335_CDC_COMPANDER_HALT_MASK
,
3276 WCD9335_CDC_COMPANDER_HALT
);
3277 snd_soc_component_update_bits(component
, rx_path_cfg0_reg
,
3278 WCD9335_CDC_RX_PATH_CFG_CMP_EN_MASK
,
3279 WCD9335_CDC_RX_PATH_CFG_CMP_DISABLE
);
3281 snd_soc_component_update_bits(component
, comp_ctl0_reg
,
3282 WCD9335_CDC_COMPANDER_SOFT_RST_MASK
,
3283 WCD9335_CDC_COMPANDER_SOFT_RST_ENABLE
);
3284 snd_soc_component_update_bits(component
, comp_ctl0_reg
,
3285 WCD9335_CDC_COMPANDER_SOFT_RST_MASK
,
3286 WCD9335_CDC_COMPANDER_SOFT_RST_DISABLE
);
3287 snd_soc_component_update_bits(component
, comp_ctl0_reg
,
3288 WCD9335_CDC_COMPANDER_CLK_EN_MASK
,
3289 WCD9335_CDC_COMPANDER_CLK_DISABLE
);
3290 snd_soc_component_update_bits(component
, comp_ctl0_reg
,
3291 WCD9335_CDC_COMPANDER_HALT_MASK
,
3292 WCD9335_CDC_COMPANDER_NOHALT
);
3298 static int wcd9335_codec_enable_interpolator(struct snd_soc_dapm_widget
*w
,
3299 struct snd_kcontrol
*kc
, int event
)
3301 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
3307 if (!(strcmp(w
->name
, "RX INT0 INTERP"))) {
3308 reg
= WCD9335_CDC_RX0_RX_PATH_CTL
;
3309 gain_reg
= WCD9335_CDC_RX0_RX_VOL_CTL
;
3310 } else if (!(strcmp(w
->name
, "RX INT1 INTERP"))) {
3311 reg
= WCD9335_CDC_RX1_RX_PATH_CTL
;
3312 gain_reg
= WCD9335_CDC_RX1_RX_VOL_CTL
;
3313 } else if (!(strcmp(w
->name
, "RX INT2 INTERP"))) {
3314 reg
= WCD9335_CDC_RX2_RX_PATH_CTL
;
3315 gain_reg
= WCD9335_CDC_RX2_RX_VOL_CTL
;
3316 } else if (!(strcmp(w
->name
, "RX INT3 INTERP"))) {
3317 reg
= WCD9335_CDC_RX3_RX_PATH_CTL
;
3318 gain_reg
= WCD9335_CDC_RX3_RX_VOL_CTL
;
3319 } else if (!(strcmp(w
->name
, "RX INT4 INTERP"))) {
3320 reg
= WCD9335_CDC_RX4_RX_PATH_CTL
;
3321 gain_reg
= WCD9335_CDC_RX4_RX_VOL_CTL
;
3322 } else if (!(strcmp(w
->name
, "RX INT5 INTERP"))) {
3323 reg
= WCD9335_CDC_RX5_RX_PATH_CTL
;
3324 gain_reg
= WCD9335_CDC_RX5_RX_VOL_CTL
;
3325 } else if (!(strcmp(w
->name
, "RX INT6 INTERP"))) {
3326 reg
= WCD9335_CDC_RX6_RX_PATH_CTL
;
3327 gain_reg
= WCD9335_CDC_RX6_RX_VOL_CTL
;
3328 } else if (!(strcmp(w
->name
, "RX INT7 INTERP"))) {
3329 reg
= WCD9335_CDC_RX7_RX_PATH_CTL
;
3330 gain_reg
= WCD9335_CDC_RX7_RX_VOL_CTL
;
3331 } else if (!(strcmp(w
->name
, "RX INT8 INTERP"))) {
3332 reg
= WCD9335_CDC_RX8_RX_PATH_CTL
;
3333 gain_reg
= WCD9335_CDC_RX8_RX_VOL_CTL
;
3335 dev_err(comp
->dev
, "%s: Interpolator reg not found\n",
3341 case SND_SOC_DAPM_PRE_PMU
:
3342 /* Reset if needed */
3343 wcd9335_codec_enable_prim_interpolator(comp
, reg
, event
);
3345 case SND_SOC_DAPM_POST_PMU
:
3346 wcd9335_config_compander(comp
, w
->shift
, event
);
3347 val
= snd_soc_component_read32(comp
, gain_reg
);
3349 snd_soc_component_write(comp
, gain_reg
, val
);
3351 case SND_SOC_DAPM_POST_PMD
:
3352 wcd9335_config_compander(comp
, w
->shift
, event
);
3353 wcd9335_codec_enable_prim_interpolator(comp
, reg
, event
);
3360 static void wcd9335_codec_hph_mode_gain_opt(struct snd_soc_component
*component
,
3363 struct wcd9335_codec
*wcd
= dev_get_drvdata(component
->dev
);
3364 u8 hph_l_en
, hph_r_en
;
3367 bool is_hphl_pa
, is_hphr_pa
;
3369 hph_pa_status
= snd_soc_component_read32(component
, WCD9335_ANA_HPH
);
3370 is_hphl_pa
= hph_pa_status
>> 7;
3371 is_hphr_pa
= (hph_pa_status
& 0x40) >> 6;
3373 hph_l_en
= snd_soc_component_read32(component
, WCD9335_HPH_L_EN
);
3374 hph_r_en
= snd_soc_component_read32(component
, WCD9335_HPH_R_EN
);
3376 l_val
= (hph_l_en
& 0xC0) | 0x20 | gain
;
3377 r_val
= (hph_r_en
& 0xC0) | 0x20 | gain
;
3380 * Set HPH_L & HPH_R gain source selection to REGISTER
3381 * for better click and pop only if corresponding PAs are
3382 * not enabled. Also cache the values of the HPHL/R
3383 * PA gains to be applied after PAs are enabled
3385 if ((l_val
!= hph_l_en
) && !is_hphl_pa
) {
3386 snd_soc_component_write(component
, WCD9335_HPH_L_EN
, l_val
);
3387 wcd
->hph_l_gain
= hph_l_en
& 0x1F;
3390 if ((r_val
!= hph_r_en
) && !is_hphr_pa
) {
3391 snd_soc_component_write(component
, WCD9335_HPH_R_EN
, r_val
);
3392 wcd
->hph_r_gain
= hph_r_en
& 0x1F;
3396 static void wcd9335_codec_hph_lohifi_config(struct snd_soc_component
*comp
,
3399 if (SND_SOC_DAPM_EVENT_ON(event
)) {
3400 snd_soc_component_update_bits(comp
, WCD9335_RX_BIAS_HPH_PA
,
3401 WCD9335_RX_BIAS_HPH_PA_AMP_5_UA_MASK
,
3403 snd_soc_component_update_bits(comp
,
3404 WCD9335_RX_BIAS_HPH_RDACBUFF_CNP2
,
3406 snd_soc_component_update_bits(comp
, WCD9335_HPH_CNP_WG_CTL
,
3407 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_MASK
,
3408 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_RATIO_1000
);
3409 snd_soc_component_update_bits(comp
, WCD9335_HPH_PA_CTL2
,
3410 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_MASK
,
3411 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_ENABLE
);
3412 snd_soc_component_update_bits(comp
, WCD9335_HPH_PA_CTL1
,
3413 WCD9335_HPH_PA_GM3_IB_SCALE_MASK
,
3415 wcd9335_codec_hph_mode_gain_opt(comp
, 0x11);
3418 if (SND_SOC_DAPM_EVENT_OFF(event
)) {
3419 snd_soc_component_update_bits(comp
, WCD9335_HPH_PA_CTL2
,
3420 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_MASK
,
3421 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_DISABLE
);
3422 snd_soc_component_update_bits(comp
, WCD9335_HPH_CNP_WG_CTL
,
3423 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_MASK
,
3424 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_RATIO_500
);
3425 snd_soc_component_write(comp
, WCD9335_RX_BIAS_HPH_RDACBUFF_CNP2
,
3427 snd_soc_component_update_bits(comp
, WCD9335_RX_BIAS_HPH_PA
,
3428 WCD9335_RX_BIAS_HPH_PA_AMP_5_UA_MASK
,
3433 static void wcd9335_codec_hph_lp_config(struct snd_soc_component
*comp
,
3436 if (SND_SOC_DAPM_EVENT_ON(event
)) {
3437 snd_soc_component_update_bits(comp
, WCD9335_HPH_PA_CTL1
,
3438 WCD9335_HPH_PA_GM3_IB_SCALE_MASK
,
3440 wcd9335_codec_hph_mode_gain_opt(comp
, 0x10);
3441 snd_soc_component_update_bits(comp
, WCD9335_HPH_CNP_WG_CTL
,
3442 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_MASK
,
3443 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_RATIO_1000
);
3444 snd_soc_component_update_bits(comp
, WCD9335_HPH_PA_CTL2
,
3445 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_MASK
,
3446 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_ENABLE
);
3447 snd_soc_component_update_bits(comp
, WCD9335_HPH_PA_CTL2
,
3448 WCD9335_HPH_PA_CTL2_FORCE_PSRREH_MASK
,
3449 WCD9335_HPH_PA_CTL2_FORCE_PSRREH_ENABLE
);
3450 snd_soc_component_update_bits(comp
, WCD9335_HPH_PA_CTL2
,
3451 WCD9335_HPH_PA_CTL2_HPH_PSRR_ENH_MASK
,
3452 WCD9335_HPH_PA_CTL2_HPH_PSRR_ENABLE
);
3453 snd_soc_component_update_bits(comp
, WCD9335_HPH_RDAC_LDO_CTL
,
3454 WCD9335_HPH_RDAC_N1P65_LD_OUTCTL_MASK
,
3455 WCD9335_HPH_RDAC_N1P65_LD_OUTCTL_V_N1P60
);
3456 snd_soc_component_update_bits(comp
, WCD9335_HPH_RDAC_LDO_CTL
,
3457 WCD9335_HPH_RDAC_1P65_LD_OUTCTL_MASK
,
3458 WCD9335_HPH_RDAC_1P65_LD_OUTCTL_V_N1P60
);
3459 snd_soc_component_update_bits(comp
,
3460 WCD9335_RX_BIAS_HPH_RDAC_LDO
, 0x0F, 0x01);
3461 snd_soc_component_update_bits(comp
,
3462 WCD9335_RX_BIAS_HPH_RDAC_LDO
, 0xF0, 0x10);
3465 if (SND_SOC_DAPM_EVENT_OFF(event
)) {
3466 snd_soc_component_write(comp
, WCD9335_RX_BIAS_HPH_RDAC_LDO
,
3468 snd_soc_component_write(comp
, WCD9335_HPH_RDAC_LDO_CTL
,
3470 snd_soc_component_update_bits(comp
, WCD9335_HPH_PA_CTL2
,
3471 WCD9335_HPH_PA_CTL2_HPH_PSRR_ENH_MASK
,
3472 WCD9335_HPH_PA_CTL2_HPH_PSRR_DISABLE
);
3473 snd_soc_component_update_bits(comp
, WCD9335_HPH_PA_CTL2
,
3474 WCD9335_HPH_PA_CTL2_FORCE_PSRREH_MASK
,
3475 WCD9335_HPH_PA_CTL2_FORCE_PSRREH_DISABLE
);
3476 snd_soc_component_update_bits(comp
, WCD9335_HPH_PA_CTL2
,
3477 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_MASK
,
3478 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_DISABLE
);
3479 snd_soc_component_update_bits(comp
, WCD9335_HPH_CNP_WG_CTL
,
3480 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_MASK
,
3481 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_RATIO_500
);
3482 snd_soc_component_update_bits(comp
, WCD9335_HPH_R_EN
,
3483 WCD9335_HPH_CONST_SEL_L_MASK
,
3484 WCD9335_HPH_CONST_SEL_L_HQ_PATH
);
3485 snd_soc_component_update_bits(comp
, WCD9335_HPH_L_EN
,
3486 WCD9335_HPH_CONST_SEL_L_MASK
,
3487 WCD9335_HPH_CONST_SEL_L_HQ_PATH
);
3491 static void wcd9335_codec_hph_hifi_config(struct snd_soc_component
*comp
,
3494 if (SND_SOC_DAPM_EVENT_ON(event
)) {
3495 snd_soc_component_update_bits(comp
, WCD9335_HPH_CNP_WG_CTL
,
3496 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_MASK
,
3497 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_RATIO_1000
);
3498 snd_soc_component_update_bits(comp
, WCD9335_HPH_PA_CTL2
,
3499 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_MASK
,
3500 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_ENABLE
);
3501 snd_soc_component_update_bits(comp
, WCD9335_HPH_PA_CTL1
,
3502 WCD9335_HPH_PA_GM3_IB_SCALE_MASK
,
3504 wcd9335_codec_hph_mode_gain_opt(comp
, 0x11);
3507 if (SND_SOC_DAPM_EVENT_OFF(event
)) {
3508 snd_soc_component_update_bits(comp
, WCD9335_HPH_PA_CTL2
,
3509 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_MASK
,
3510 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_DISABLE
);
3511 snd_soc_component_update_bits(comp
, WCD9335_HPH_CNP_WG_CTL
,
3512 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_MASK
,
3513 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_RATIO_500
);
3517 static void wcd9335_codec_hph_mode_config(struct snd_soc_component
*component
,
3518 int event
, int mode
)
3522 wcd9335_codec_hph_lp_config(component
, event
);
3525 wcd9335_codec_hph_lohifi_config(component
, event
);
3528 wcd9335_codec_hph_hifi_config(component
, event
);
3533 static int wcd9335_codec_hphl_dac_event(struct snd_soc_dapm_widget
*w
,
3534 struct snd_kcontrol
*kc
,
3537 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
3538 struct wcd9335_codec
*wcd
= dev_get_drvdata(comp
->dev
);
3539 int hph_mode
= wcd
->hph_mode
;
3543 case SND_SOC_DAPM_PRE_PMU
:
3544 /* Read DEM INP Select */
3545 dem_inp
= snd_soc_component_read32(comp
,
3546 WCD9335_CDC_RX1_RX_PATH_SEC0
) & 0x03;
3547 if (((hph_mode
== CLS_H_HIFI
) || (hph_mode
== CLS_H_LOHIFI
) ||
3548 (hph_mode
== CLS_H_LP
)) && (dem_inp
!= 0x01)) {
3549 dev_err(comp
->dev
, "Incorrect DEM Input\n");
3552 wcd_clsh_ctrl_set_state(wcd
->clsh_ctrl
, WCD_CLSH_EVENT_PRE_DAC
,
3553 WCD_CLSH_STATE_HPHL
,
3554 ((hph_mode
== CLS_H_LOHIFI
) ?
3555 CLS_H_HIFI
: hph_mode
));
3557 wcd9335_codec_hph_mode_config(comp
, event
, hph_mode
);
3560 case SND_SOC_DAPM_POST_PMU
:
3561 usleep_range(1000, 1100);
3563 case SND_SOC_DAPM_PRE_PMD
:
3565 case SND_SOC_DAPM_POST_PMD
:
3566 /* 1000us required as per HW requirement */
3567 usleep_range(1000, 1100);
3569 if (!(wcd_clsh_ctrl_get_state(wcd
->clsh_ctrl
) &
3570 WCD_CLSH_STATE_HPHR
))
3571 wcd9335_codec_hph_mode_config(comp
, event
, hph_mode
);
3573 wcd_clsh_ctrl_set_state(wcd
->clsh_ctrl
, WCD_CLSH_EVENT_POST_PA
,
3574 WCD_CLSH_STATE_HPHL
,
3575 ((hph_mode
== CLS_H_LOHIFI
) ?
3576 CLS_H_HIFI
: hph_mode
));
3583 static int wcd9335_codec_lineout_dac_event(struct snd_soc_dapm_widget
*w
,
3584 struct snd_kcontrol
*kc
, int event
)
3586 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
3587 struct wcd9335_codec
*wcd
= dev_get_drvdata(comp
->dev
);
3590 case SND_SOC_DAPM_PRE_PMU
:
3591 wcd_clsh_ctrl_set_state(wcd
->clsh_ctrl
, WCD_CLSH_EVENT_PRE_DAC
,
3592 WCD_CLSH_STATE_LO
, CLS_AB
);
3594 case SND_SOC_DAPM_POST_PMD
:
3595 wcd_clsh_ctrl_set_state(wcd
->clsh_ctrl
, WCD_CLSH_EVENT_POST_PA
,
3596 WCD_CLSH_STATE_LO
, CLS_AB
);
3603 static int wcd9335_codec_ear_dac_event(struct snd_soc_dapm_widget
*w
,
3604 struct snd_kcontrol
*kc
, int event
)
3606 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
3607 struct wcd9335_codec
*wcd
= dev_get_drvdata(comp
->dev
);
3610 case SND_SOC_DAPM_PRE_PMU
:
3611 wcd_clsh_ctrl_set_state(wcd
->clsh_ctrl
, WCD_CLSH_EVENT_PRE_DAC
,
3612 WCD_CLSH_STATE_EAR
, CLS_H_NORMAL
);
3615 case SND_SOC_DAPM_POST_PMD
:
3616 wcd_clsh_ctrl_set_state(wcd
->clsh_ctrl
, WCD_CLSH_EVENT_POST_PA
,
3617 WCD_CLSH_STATE_EAR
, CLS_H_NORMAL
);
3624 static void wcd9335_codec_hph_post_pa_config(struct wcd9335_codec
*wcd
,
3625 int mode
, int event
)
3630 case SND_SOC_DAPM_POST_PMU
:
3640 case SND_SOC_DAPM_PRE_PMD
:
3646 snd_soc_component_update_bits(wcd
->component
,
3647 WCD9335_HPH_PA_CTL1
,
3648 WCD9335_HPH_PA_GM3_IB_SCALE_MASK
,
3650 if (SND_SOC_DAPM_EVENT_ON(event
)) {
3651 if (wcd
->comp_enabled
[COMPANDER_1
] ||
3652 wcd
->comp_enabled
[COMPANDER_2
]) {
3653 /* GAIN Source Selection */
3654 snd_soc_component_update_bits(wcd
->component
,
3656 WCD9335_HPH_GAIN_SRC_SEL_MASK
,
3657 WCD9335_HPH_GAIN_SRC_SEL_COMPANDER
);
3658 snd_soc_component_update_bits(wcd
->component
,
3660 WCD9335_HPH_GAIN_SRC_SEL_MASK
,
3661 WCD9335_HPH_GAIN_SRC_SEL_COMPANDER
);
3662 snd_soc_component_update_bits(wcd
->component
,
3663 WCD9335_HPH_AUTO_CHOP
,
3664 WCD9335_HPH_AUTO_CHOP_MASK
,
3665 WCD9335_HPH_AUTO_CHOP_FORCE_ENABLE
);
3667 snd_soc_component_update_bits(wcd
->component
,
3669 WCD9335_HPH_PA_GAIN_MASK
,
3671 snd_soc_component_update_bits(wcd
->component
,
3673 WCD9335_HPH_PA_GAIN_MASK
,
3677 if (SND_SOC_DAPM_EVENT_OFF(event
))
3678 snd_soc_component_update_bits(wcd
->component
,
3679 WCD9335_HPH_AUTO_CHOP
,
3680 WCD9335_HPH_AUTO_CHOP_MASK
,
3681 WCD9335_HPH_AUTO_CHOP_ENABLE_BY_CMPDR_GAIN
);
3684 static int wcd9335_codec_hphr_dac_event(struct snd_soc_dapm_widget
*w
,
3685 struct snd_kcontrol
*kc
,
3688 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
3689 struct wcd9335_codec
*wcd
= dev_get_drvdata(comp
->dev
);
3690 int hph_mode
= wcd
->hph_mode
;
3694 case SND_SOC_DAPM_PRE_PMU
:
3696 /* Read DEM INP Select */
3697 dem_inp
= snd_soc_component_read32(comp
,
3698 WCD9335_CDC_RX2_RX_PATH_SEC0
) &
3699 WCD9335_CDC_RX_PATH_DEM_INP_SEL_MASK
;
3700 if (((hph_mode
== CLS_H_HIFI
) || (hph_mode
== CLS_H_LOHIFI
) ||
3701 (hph_mode
== CLS_H_LP
)) && (dem_inp
!= 0x01)) {
3702 dev_err(comp
->dev
, "DEM Input not set correctly, hph_mode: %d\n",
3707 wcd_clsh_ctrl_set_state(wcd
->clsh_ctrl
,
3708 WCD_CLSH_EVENT_PRE_DAC
,
3709 WCD_CLSH_STATE_HPHR
,
3710 ((hph_mode
== CLS_H_LOHIFI
) ?
3711 CLS_H_HIFI
: hph_mode
));
3713 wcd9335_codec_hph_mode_config(comp
, event
, hph_mode
);
3716 case SND_SOC_DAPM_POST_PMD
:
3717 /* 1000us required as per HW requirement */
3718 usleep_range(1000, 1100);
3720 if (!(wcd_clsh_ctrl_get_state(wcd
->clsh_ctrl
) &
3721 WCD_CLSH_STATE_HPHL
))
3722 wcd9335_codec_hph_mode_config(comp
, event
, hph_mode
);
3724 wcd_clsh_ctrl_set_state(wcd
->clsh_ctrl
, WCD_CLSH_EVENT_POST_PA
,
3725 WCD_CLSH_STATE_HPHR
, ((hph_mode
== CLS_H_LOHIFI
) ?
3726 CLS_H_HIFI
: hph_mode
));
3733 static int wcd9335_codec_enable_hphl_pa(struct snd_soc_dapm_widget
*w
,
3734 struct snd_kcontrol
*kc
,
3737 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
3738 struct wcd9335_codec
*wcd
= dev_get_drvdata(comp
->dev
);
3739 int hph_mode
= wcd
->hph_mode
;
3742 case SND_SOC_DAPM_PRE_PMU
:
3744 case SND_SOC_DAPM_POST_PMU
:
3746 * 7ms sleep is required after PA is enabled as per
3749 usleep_range(7000, 7100);
3751 wcd9335_codec_hph_post_pa_config(wcd
, hph_mode
, event
);
3752 snd_soc_component_update_bits(comp
,
3753 WCD9335_CDC_RX1_RX_PATH_CTL
,
3754 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
,
3755 WCD9335_CDC_RX_PGA_MUTE_DISABLE
);
3757 /* Remove mix path mute if it is enabled */
3758 if ((snd_soc_component_read32(comp
,
3759 WCD9335_CDC_RX1_RX_PATH_MIX_CTL
)) &
3760 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
)
3761 snd_soc_component_update_bits(comp
,
3762 WCD9335_CDC_RX1_RX_PATH_MIX_CTL
,
3763 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
,
3764 WCD9335_CDC_RX_PGA_MUTE_DISABLE
);
3767 case SND_SOC_DAPM_PRE_PMD
:
3768 wcd9335_codec_hph_post_pa_config(wcd
, hph_mode
, event
);
3770 case SND_SOC_DAPM_POST_PMD
:
3771 /* 5ms sleep is required after PA is disabled as per
3774 usleep_range(5000, 5500);
3781 static int wcd9335_codec_enable_lineout_pa(struct snd_soc_dapm_widget
*w
,
3782 struct snd_kcontrol
*kc
,
3785 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
3786 int vol_reg
= 0, mix_vol_reg
= 0;
3788 if (w
->reg
== WCD9335_ANA_LO_1_2
) {
3789 if (w
->shift
== 7) {
3790 vol_reg
= WCD9335_CDC_RX3_RX_PATH_CTL
;
3791 mix_vol_reg
= WCD9335_CDC_RX3_RX_PATH_MIX_CTL
;
3792 } else if (w
->shift
== 6) {
3793 vol_reg
= WCD9335_CDC_RX4_RX_PATH_CTL
;
3794 mix_vol_reg
= WCD9335_CDC_RX4_RX_PATH_MIX_CTL
;
3796 } else if (w
->reg
== WCD9335_ANA_LO_3_4
) {
3797 if (w
->shift
== 7) {
3798 vol_reg
= WCD9335_CDC_RX5_RX_PATH_CTL
;
3799 mix_vol_reg
= WCD9335_CDC_RX5_RX_PATH_MIX_CTL
;
3800 } else if (w
->shift
== 6) {
3801 vol_reg
= WCD9335_CDC_RX6_RX_PATH_CTL
;
3802 mix_vol_reg
= WCD9335_CDC_RX6_RX_PATH_MIX_CTL
;
3805 dev_err(comp
->dev
, "Error enabling lineout PA\n");
3810 case SND_SOC_DAPM_POST_PMU
:
3811 /* 5ms sleep is required after PA is enabled as per
3814 usleep_range(5000, 5500);
3815 snd_soc_component_update_bits(comp
, vol_reg
,
3816 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
,
3817 WCD9335_CDC_RX_PGA_MUTE_DISABLE
);
3819 /* Remove mix path mute if it is enabled */
3820 if ((snd_soc_component_read32(comp
, mix_vol_reg
)) &
3821 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
)
3822 snd_soc_component_update_bits(comp
, mix_vol_reg
,
3823 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
,
3824 WCD9335_CDC_RX_PGA_MUTE_DISABLE
);
3826 case SND_SOC_DAPM_POST_PMD
:
3827 /* 5ms sleep is required after PA is disabled as per
3830 usleep_range(5000, 5500);
3837 static void wcd9335_codec_init_flyback(struct snd_soc_component
*component
)
3839 snd_soc_component_update_bits(component
, WCD9335_HPH_L_EN
,
3840 WCD9335_HPH_CONST_SEL_L_MASK
,
3841 WCD9335_HPH_CONST_SEL_L_BYPASS
);
3842 snd_soc_component_update_bits(component
, WCD9335_HPH_R_EN
,
3843 WCD9335_HPH_CONST_SEL_L_MASK
,
3844 WCD9335_HPH_CONST_SEL_L_BYPASS
);
3845 snd_soc_component_update_bits(component
, WCD9335_RX_BIAS_FLYB_BUFF
,
3846 WCD9335_RX_BIAS_FLYB_VPOS_5_UA_MASK
,
3847 WCD9335_RX_BIAS_FLYB_I_0P0_UA
);
3848 snd_soc_component_update_bits(component
, WCD9335_RX_BIAS_FLYB_BUFF
,
3849 WCD9335_RX_BIAS_FLYB_VNEG_5_UA_MASK
,
3850 WCD9335_RX_BIAS_FLYB_I_0P0_UA
);
3853 static int wcd9335_codec_enable_rx_bias(struct snd_soc_dapm_widget
*w
,
3854 struct snd_kcontrol
*kc
, int event
)
3856 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
3857 struct wcd9335_codec
*wcd
= dev_get_drvdata(comp
->dev
);
3860 case SND_SOC_DAPM_PRE_PMU
:
3861 wcd
->rx_bias_count
++;
3862 if (wcd
->rx_bias_count
== 1) {
3863 wcd9335_codec_init_flyback(comp
);
3864 snd_soc_component_update_bits(comp
,
3865 WCD9335_ANA_RX_SUPPLIES
,
3866 WCD9335_ANA_RX_BIAS_ENABLE_MASK
,
3867 WCD9335_ANA_RX_BIAS_ENABLE
);
3870 case SND_SOC_DAPM_POST_PMD
:
3871 wcd
->rx_bias_count
--;
3872 if (!wcd
->rx_bias_count
)
3873 snd_soc_component_update_bits(comp
,
3874 WCD9335_ANA_RX_SUPPLIES
,
3875 WCD9335_ANA_RX_BIAS_ENABLE_MASK
,
3876 WCD9335_ANA_RX_BIAS_DISABLE
);
3883 static int wcd9335_codec_enable_hphr_pa(struct snd_soc_dapm_widget
*w
,
3884 struct snd_kcontrol
*kc
, int event
)
3886 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
3887 struct wcd9335_codec
*wcd
= dev_get_drvdata(comp
->dev
);
3888 int hph_mode
= wcd
->hph_mode
;
3891 case SND_SOC_DAPM_PRE_PMU
:
3893 case SND_SOC_DAPM_POST_PMU
:
3895 * 7ms sleep is required after PA is enabled as per
3898 usleep_range(7000, 7100);
3899 wcd9335_codec_hph_post_pa_config(wcd
, hph_mode
, event
);
3900 snd_soc_component_update_bits(comp
,
3901 WCD9335_CDC_RX2_RX_PATH_CTL
,
3902 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
,
3903 WCD9335_CDC_RX_PGA_MUTE_DISABLE
);
3904 /* Remove mix path mute if it is enabled */
3905 if ((snd_soc_component_read32(comp
,
3906 WCD9335_CDC_RX2_RX_PATH_MIX_CTL
)) &
3907 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
)
3908 snd_soc_component_update_bits(comp
,
3909 WCD9335_CDC_RX2_RX_PATH_MIX_CTL
,
3910 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
,
3911 WCD9335_CDC_RX_PGA_MUTE_DISABLE
);
3915 case SND_SOC_DAPM_PRE_PMD
:
3916 wcd9335_codec_hph_post_pa_config(wcd
, hph_mode
, event
);
3918 case SND_SOC_DAPM_POST_PMD
:
3919 /* 5ms sleep is required after PA is disabled as per
3922 usleep_range(5000, 5500);
3929 static int wcd9335_codec_enable_ear_pa(struct snd_soc_dapm_widget
*w
,
3930 struct snd_kcontrol
*kc
, int event
)
3932 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
3935 case SND_SOC_DAPM_POST_PMU
:
3936 /* 5ms sleep is required after PA is enabled as per
3939 usleep_range(5000, 5500);
3940 snd_soc_component_update_bits(comp
,
3941 WCD9335_CDC_RX0_RX_PATH_CTL
,
3942 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
,
3943 WCD9335_CDC_RX_PGA_MUTE_DISABLE
);
3944 /* Remove mix path mute if it is enabled */
3945 if ((snd_soc_component_read32(comp
,
3946 WCD9335_CDC_RX0_RX_PATH_MIX_CTL
)) &
3947 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
)
3948 snd_soc_component_update_bits(comp
,
3949 WCD9335_CDC_RX0_RX_PATH_MIX_CTL
,
3950 WCD9335_CDC_RX_PGA_MUTE_EN_MASK
,
3951 WCD9335_CDC_RX_PGA_MUTE_DISABLE
);
3953 case SND_SOC_DAPM_POST_PMD
:
3954 /* 5ms sleep is required after PA is disabled as per
3957 usleep_range(5000, 5500);
3965 static irqreturn_t
wcd9335_slimbus_irq(int irq
, void *data
)
3967 struct wcd9335_codec
*wcd
= data
;
3968 unsigned long status
= 0;
3970 unsigned int val
, int_val
= 0;
3971 irqreturn_t ret
= IRQ_NONE
;
3973 unsigned short reg
= 0;
3975 for (i
= WCD9335_SLIM_PGD_PORT_INT_STATUS_RX_0
, j
= 0;
3976 i
<= WCD9335_SLIM_PGD_PORT_INT_STATUS_TX_1
; i
++, j
++) {
3977 regmap_read(wcd
->if_regmap
, i
, &val
);
3978 status
|= ((u32
)val
<< (8 * j
));
3981 for_each_set_bit(j
, &status
, 32) {
3982 tx
= (j
>= 16 ? true : false);
3983 port_id
= (tx
? j
- 16 : j
);
3984 regmap_read(wcd
->if_regmap
,
3985 WCD9335_SLIM_PGD_PORT_INT_RX_SOURCE0
+ j
, &val
);
3988 reg
= WCD9335_SLIM_PGD_PORT_INT_EN0
+
3991 reg
= WCD9335_SLIM_PGD_PORT_INT_TX_EN0
+
3994 wcd
->if_regmap
, reg
, &int_val
);
3996 * Ignore interrupts for ports for which the
3997 * interrupts are not specifically enabled.
3999 if (!(int_val
& (1 << (port_id
% 8))))
4003 if (val
& WCD9335_SLIM_IRQ_OVERFLOW
)
4004 dev_err_ratelimited(wcd
->dev
,
4005 "%s: overflow error on %s port %d, value %x\n",
4006 __func__
, (tx
? "TX" : "RX"), port_id
, val
);
4008 if (val
& WCD9335_SLIM_IRQ_UNDERFLOW
)
4009 dev_err_ratelimited(wcd
->dev
,
4010 "%s: underflow error on %s port %d, value %x\n",
4011 __func__
, (tx
? "TX" : "RX"), port_id
, val
);
4013 if ((val
& WCD9335_SLIM_IRQ_OVERFLOW
) ||
4014 (val
& WCD9335_SLIM_IRQ_UNDERFLOW
)) {
4016 reg
= WCD9335_SLIM_PGD_PORT_INT_EN0
+
4019 reg
= WCD9335_SLIM_PGD_PORT_INT_TX_EN0
+
4022 wcd
->if_regmap
, reg
, &int_val
);
4023 if (int_val
& (1 << (port_id
% 8))) {
4024 int_val
= int_val
^ (1 << (port_id
% 8));
4025 regmap_write(wcd
->if_regmap
,
4030 regmap_write(wcd
->if_regmap
,
4031 WCD9335_SLIM_PGD_PORT_INT_CLR_RX_0
+ (j
/ 8),
4039 static struct wcd9335_irq wcd9335_irqs
[] = {
4041 .irq
= WCD9335_IRQ_SLIMBUS
,
4042 .handler
= wcd9335_slimbus_irq
,
4043 .name
= "SLIM Slave",
4047 static int wcd9335_setup_irqs(struct wcd9335_codec
*wcd
)
4051 for (i
= 0; i
< ARRAY_SIZE(wcd9335_irqs
); i
++) {
4052 irq
= regmap_irq_get_virq(wcd
->irq_data
, wcd9335_irqs
[i
].irq
);
4054 dev_err(wcd
->dev
, "Failed to get %s\n",
4055 wcd9335_irqs
[i
].name
);
4059 ret
= devm_request_threaded_irq(wcd
->dev
, irq
, NULL
,
4060 wcd9335_irqs
[i
].handler
,
4061 IRQF_TRIGGER_RISING
|
4063 wcd9335_irqs
[i
].name
, wcd
);
4065 dev_err(wcd
->dev
, "Failed to request %s\n",
4066 wcd9335_irqs
[i
].name
);
4071 /* enable interrupts on all slave ports */
4072 for (i
= 0; i
< WCD9335_SLIM_NUM_PORT_REG
; i
++)
4073 regmap_write(wcd
->if_regmap
, WCD9335_SLIM_PGD_PORT_INT_EN0
+ i
,
4079 static void wcd9335_cdc_sido_ccl_enable(struct wcd9335_codec
*wcd
,
4082 struct snd_soc_component
*comp
= wcd
->component
;
4085 if (++wcd
->sido_ccl_cnt
== 1)
4086 snd_soc_component_write(comp
, WCD9335_SIDO_SIDO_CCL_10
,
4087 WCD9335_SIDO_SIDO_CCL_DEF_VALUE
);
4089 if (wcd
->sido_ccl_cnt
== 0) {
4090 dev_err(wcd
->dev
, "sido_ccl already disabled\n");
4093 if (--wcd
->sido_ccl_cnt
== 0)
4094 snd_soc_component_write(comp
, WCD9335_SIDO_SIDO_CCL_10
,
4095 WCD9335_SIDO_SIDO_CCL_10_ICHARG_PWR_SEL_C320FF
);
4099 static int wcd9335_enable_master_bias(struct wcd9335_codec
*wcd
)
4101 wcd
->master_bias_users
++;
4102 if (wcd
->master_bias_users
== 1) {
4103 regmap_update_bits(wcd
->regmap
, WCD9335_ANA_BIAS
,
4104 WCD9335_ANA_BIAS_EN_MASK
,
4105 WCD9335_ANA_BIAS_ENABLE
);
4106 regmap_update_bits(wcd
->regmap
, WCD9335_ANA_BIAS
,
4107 WCD9335_ANA_BIAS_PRECHRG_EN_MASK
,
4108 WCD9335_ANA_BIAS_PRECHRG_ENABLE
);
4110 * 1ms delay is required after pre-charge is enabled
4111 * as per HW requirement
4113 usleep_range(1000, 1100);
4114 regmap_update_bits(wcd
->regmap
, WCD9335_ANA_BIAS
,
4115 WCD9335_ANA_BIAS_PRECHRG_EN_MASK
,
4116 WCD9335_ANA_BIAS_PRECHRG_DISABLE
);
4117 regmap_update_bits(wcd
->regmap
, WCD9335_ANA_BIAS
,
4118 WCD9335_ANA_BIAS_PRECHRG_CTL_MODE
,
4119 WCD9335_ANA_BIAS_PRECHRG_CTL_MODE_MANUAL
);
4125 static int wcd9335_enable_mclk(struct wcd9335_codec
*wcd
)
4127 /* Enable mclk requires master bias to be enabled first */
4128 if (wcd
->master_bias_users
<= 0)
4131 if (((wcd
->clk_mclk_users
== 0) && (wcd
->clk_type
== WCD_CLK_MCLK
)) ||
4132 ((wcd
->clk_mclk_users
> 0) && (wcd
->clk_type
!= WCD_CLK_MCLK
))) {
4133 dev_err(wcd
->dev
, "Error enabling MCLK, clk_type: %d\n",
4138 if (++wcd
->clk_mclk_users
== 1) {
4139 regmap_update_bits(wcd
->regmap
, WCD9335_ANA_CLK_TOP
,
4140 WCD9335_ANA_CLK_EXT_CLKBUF_EN_MASK
,
4141 WCD9335_ANA_CLK_EXT_CLKBUF_ENABLE
);
4142 regmap_update_bits(wcd
->regmap
, WCD9335_ANA_CLK_TOP
,
4143 WCD9335_ANA_CLK_MCLK_SRC_MASK
,
4144 WCD9335_ANA_CLK_MCLK_SRC_EXTERNAL
);
4145 regmap_update_bits(wcd
->regmap
, WCD9335_ANA_CLK_TOP
,
4146 WCD9335_ANA_CLK_MCLK_EN_MASK
,
4147 WCD9335_ANA_CLK_MCLK_ENABLE
);
4148 regmap_update_bits(wcd
->regmap
,
4149 WCD9335_CDC_CLK_RST_CTRL_FS_CNT_CONTROL
,
4150 WCD9335_CDC_CLK_RST_CTRL_FS_CNT_EN_MASK
,
4151 WCD9335_CDC_CLK_RST_CTRL_FS_CNT_ENABLE
);
4152 regmap_update_bits(wcd
->regmap
,
4153 WCD9335_CDC_CLK_RST_CTRL_MCLK_CONTROL
,
4154 WCD9335_CDC_CLK_RST_CTRL_MCLK_EN_MASK
,
4155 WCD9335_CDC_CLK_RST_CTRL_MCLK_ENABLE
);
4157 * 10us sleep is required after clock is enabled
4158 * as per HW requirement
4160 usleep_range(10, 15);
4163 wcd
->clk_type
= WCD_CLK_MCLK
;
4168 static int wcd9335_disable_mclk(struct wcd9335_codec
*wcd
)
4170 if (wcd
->clk_mclk_users
<= 0)
4173 if (--wcd
->clk_mclk_users
== 0) {
4174 if (wcd
->clk_rco_users
> 0) {
4175 /* MCLK to RCO switch */
4176 regmap_update_bits(wcd
->regmap
, WCD9335_ANA_CLK_TOP
,
4177 WCD9335_ANA_CLK_MCLK_SRC_MASK
,
4178 WCD9335_ANA_CLK_MCLK_SRC_RCO
);
4179 wcd
->clk_type
= WCD_CLK_RCO
;
4181 regmap_update_bits(wcd
->regmap
, WCD9335_ANA_CLK_TOP
,
4182 WCD9335_ANA_CLK_MCLK_EN_MASK
,
4183 WCD9335_ANA_CLK_MCLK_DISABLE
);
4184 wcd
->clk_type
= WCD_CLK_OFF
;
4187 regmap_update_bits(wcd
->regmap
, WCD9335_ANA_CLK_TOP
,
4188 WCD9335_ANA_CLK_EXT_CLKBUF_EN_MASK
,
4189 WCD9335_ANA_CLK_EXT_CLKBUF_DISABLE
);
4195 static int wcd9335_disable_master_bias(struct wcd9335_codec
*wcd
)
4197 if (wcd
->master_bias_users
<= 0)
4200 wcd
->master_bias_users
--;
4201 if (wcd
->master_bias_users
== 0) {
4202 regmap_update_bits(wcd
->regmap
, WCD9335_ANA_BIAS
,
4203 WCD9335_ANA_BIAS_EN_MASK
,
4204 WCD9335_ANA_BIAS_DISABLE
);
4205 regmap_update_bits(wcd
->regmap
, WCD9335_ANA_BIAS
,
4206 WCD9335_ANA_BIAS_PRECHRG_CTL_MODE
,
4207 WCD9335_ANA_BIAS_PRECHRG_CTL_MODE_MANUAL
);
4212 static int wcd9335_cdc_req_mclk_enable(struct wcd9335_codec
*wcd
,
4218 wcd9335_cdc_sido_ccl_enable(wcd
, true);
4219 ret
= clk_prepare_enable(wcd
->mclk
);
4221 dev_err(wcd
->dev
, "%s: ext clk enable failed\n",
4226 wcd9335_enable_master_bias(wcd
);
4228 wcd9335_enable_mclk(wcd
);
4232 wcd9335_disable_mclk(wcd
);
4234 wcd9335_disable_master_bias(wcd
);
4235 clk_disable_unprepare(wcd
->mclk
);
4236 wcd9335_cdc_sido_ccl_enable(wcd
, false);
4242 static void wcd9335_codec_apply_sido_voltage(struct wcd9335_codec
*wcd
,
4243 enum wcd9335_sido_voltage req_mv
)
4245 struct snd_soc_component
*comp
= wcd
->component
;
4248 if (req_mv
== wcd
->sido_voltage
)
4251 /* compute the vout_d step value */
4252 vout_d_val
= WCD9335_CALCULATE_VOUT_D(req_mv
) &
4253 WCD9335_ANA_BUCK_VOUT_MASK
;
4254 snd_soc_component_write(comp
, WCD9335_ANA_BUCK_VOUT_D
, vout_d_val
);
4255 snd_soc_component_update_bits(comp
, WCD9335_ANA_BUCK_CTL
,
4256 WCD9335_ANA_BUCK_CTL_RAMP_START_MASK
,
4257 WCD9335_ANA_BUCK_CTL_RAMP_START_ENABLE
);
4259 /* 1 msec sleep required after SIDO Vout_D voltage change */
4260 usleep_range(1000, 1100);
4261 wcd
->sido_voltage
= req_mv
;
4262 snd_soc_component_update_bits(comp
, WCD9335_ANA_BUCK_CTL
,
4263 WCD9335_ANA_BUCK_CTL_RAMP_START_MASK
,
4264 WCD9335_ANA_BUCK_CTL_RAMP_START_DISABLE
);
4267 static int wcd9335_codec_update_sido_voltage(struct wcd9335_codec
*wcd
,
4268 enum wcd9335_sido_voltage req_mv
)
4272 /* enable mclk before setting SIDO voltage */
4273 ret
= wcd9335_cdc_req_mclk_enable(wcd
, true);
4275 dev_err(wcd
->dev
, "Ext clk enable failed\n");
4279 wcd9335_codec_apply_sido_voltage(wcd
, req_mv
);
4280 wcd9335_cdc_req_mclk_enable(wcd
, false);
4286 static int _wcd9335_codec_enable_mclk(struct snd_soc_component
*component
,
4289 struct wcd9335_codec
*wcd
= dev_get_drvdata(component
->dev
);
4293 ret
= wcd9335_cdc_req_mclk_enable(wcd
, true);
4297 wcd9335_codec_apply_sido_voltage(wcd
,
4298 SIDO_VOLTAGE_NOMINAL_MV
);
4300 wcd9335_codec_update_sido_voltage(wcd
,
4302 wcd9335_cdc_req_mclk_enable(wcd
, false);
4308 static int wcd9335_codec_enable_mclk(struct snd_soc_dapm_widget
*w
,
4309 struct snd_kcontrol
*kc
, int event
)
4311 struct snd_soc_component
*comp
= snd_soc_dapm_to_component(w
->dapm
);
4314 case SND_SOC_DAPM_PRE_PMU
:
4315 return _wcd9335_codec_enable_mclk(comp
, true);
4316 case SND_SOC_DAPM_POST_PMD
:
4317 return _wcd9335_codec_enable_mclk(comp
, false);
4323 static const struct snd_soc_dapm_widget wcd9335_dapm_widgets
[] = {
4324 /* TODO SPK1 & SPK2 OUT*/
4325 SND_SOC_DAPM_OUTPUT("EAR"),
4326 SND_SOC_DAPM_OUTPUT("HPHL"),
4327 SND_SOC_DAPM_OUTPUT("HPHR"),
4328 SND_SOC_DAPM_OUTPUT("LINEOUT1"),
4329 SND_SOC_DAPM_OUTPUT("LINEOUT2"),
4330 SND_SOC_DAPM_OUTPUT("LINEOUT3"),
4331 SND_SOC_DAPM_OUTPUT("LINEOUT4"),
4332 SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM
,
4333 AIF1_PB
, 0, wcd9335_codec_enable_slim
,
4334 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
4335 SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM
,
4336 AIF2_PB
, 0, wcd9335_codec_enable_slim
,
4337 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
4338 SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM
,
4339 AIF3_PB
, 0, wcd9335_codec_enable_slim
,
4340 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
4341 SND_SOC_DAPM_AIF_IN_E("AIF4 PB", "AIF4 Playback", 0, SND_SOC_NOPM
,
4342 AIF4_PB
, 0, wcd9335_codec_enable_slim
,
4343 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
4344 SND_SOC_DAPM_MUX("SLIM RX0 MUX", SND_SOC_NOPM
, WCD9335_RX0
, 0,
4345 &slim_rx_mux
[WCD9335_RX0
]),
4346 SND_SOC_DAPM_MUX("SLIM RX1 MUX", SND_SOC_NOPM
, WCD9335_RX1
, 0,
4347 &slim_rx_mux
[WCD9335_RX1
]),
4348 SND_SOC_DAPM_MUX("SLIM RX2 MUX", SND_SOC_NOPM
, WCD9335_RX2
, 0,
4349 &slim_rx_mux
[WCD9335_RX2
]),
4350 SND_SOC_DAPM_MUX("SLIM RX3 MUX", SND_SOC_NOPM
, WCD9335_RX3
, 0,
4351 &slim_rx_mux
[WCD9335_RX3
]),
4352 SND_SOC_DAPM_MUX("SLIM RX4 MUX", SND_SOC_NOPM
, WCD9335_RX4
, 0,
4353 &slim_rx_mux
[WCD9335_RX4
]),
4354 SND_SOC_DAPM_MUX("SLIM RX5 MUX", SND_SOC_NOPM
, WCD9335_RX5
, 0,
4355 &slim_rx_mux
[WCD9335_RX5
]),
4356 SND_SOC_DAPM_MUX("SLIM RX6 MUX", SND_SOC_NOPM
, WCD9335_RX6
, 0,
4357 &slim_rx_mux
[WCD9335_RX6
]),
4358 SND_SOC_DAPM_MUX("SLIM RX7 MUX", SND_SOC_NOPM
, WCD9335_RX7
, 0,
4359 &slim_rx_mux
[WCD9335_RX7
]),
4360 SND_SOC_DAPM_MIXER("SLIM RX0", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4361 SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4362 SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4363 SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4364 SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4365 SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4366 SND_SOC_DAPM_MIXER("SLIM RX6", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4367 SND_SOC_DAPM_MIXER("SLIM RX7", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4368 SND_SOC_DAPM_MUX_E("RX INT0_2 MUX", WCD9335_CDC_RX0_RX_PATH_MIX_CTL
,
4369 5, 0, &rx_int0_2_mux
, wcd9335_codec_enable_mix_path
,
4370 SND_SOC_DAPM_POST_PMU
),
4371 SND_SOC_DAPM_MUX_E("RX INT1_2 MUX", WCD9335_CDC_RX1_RX_PATH_MIX_CTL
,
4372 5, 0, &rx_int1_2_mux
, wcd9335_codec_enable_mix_path
,
4373 SND_SOC_DAPM_POST_PMU
),
4374 SND_SOC_DAPM_MUX_E("RX INT2_2 MUX", WCD9335_CDC_RX2_RX_PATH_MIX_CTL
,
4375 5, 0, &rx_int2_2_mux
, wcd9335_codec_enable_mix_path
,
4376 SND_SOC_DAPM_POST_PMU
),
4377 SND_SOC_DAPM_MUX_E("RX INT3_2 MUX", WCD9335_CDC_RX3_RX_PATH_MIX_CTL
,
4378 5, 0, &rx_int3_2_mux
, wcd9335_codec_enable_mix_path
,
4379 SND_SOC_DAPM_POST_PMU
),
4380 SND_SOC_DAPM_MUX_E("RX INT4_2 MUX", WCD9335_CDC_RX4_RX_PATH_MIX_CTL
,
4381 5, 0, &rx_int4_2_mux
, wcd9335_codec_enable_mix_path
,
4382 SND_SOC_DAPM_POST_PMU
),
4383 SND_SOC_DAPM_MUX_E("RX INT5_2 MUX", WCD9335_CDC_RX5_RX_PATH_MIX_CTL
,
4384 5, 0, &rx_int5_2_mux
, wcd9335_codec_enable_mix_path
,
4385 SND_SOC_DAPM_POST_PMU
),
4386 SND_SOC_DAPM_MUX_E("RX INT6_2 MUX", WCD9335_CDC_RX6_RX_PATH_MIX_CTL
,
4387 5, 0, &rx_int6_2_mux
, wcd9335_codec_enable_mix_path
,
4388 SND_SOC_DAPM_POST_PMU
),
4389 SND_SOC_DAPM_MUX_E("RX INT7_2 MUX", WCD9335_CDC_RX7_RX_PATH_MIX_CTL
,
4390 5, 0, &rx_int7_2_mux
, wcd9335_codec_enable_mix_path
,
4391 SND_SOC_DAPM_POST_PMU
),
4392 SND_SOC_DAPM_MUX_E("RX INT8_2 MUX", WCD9335_CDC_RX8_RX_PATH_MIX_CTL
,
4393 5, 0, &rx_int8_2_mux
, wcd9335_codec_enable_mix_path
,
4394 SND_SOC_DAPM_POST_PMU
),
4395 SND_SOC_DAPM_MUX("RX INT0_1 MIX1 INP0", SND_SOC_NOPM
, 0, 0,
4396 &rx_int0_1_mix_inp0_mux
),
4397 SND_SOC_DAPM_MUX("RX INT0_1 MIX1 INP1", SND_SOC_NOPM
, 0, 0,
4398 &rx_int0_1_mix_inp1_mux
),
4399 SND_SOC_DAPM_MUX("RX INT0_1 MIX1 INP2", SND_SOC_NOPM
, 0, 0,
4400 &rx_int0_1_mix_inp2_mux
),
4401 SND_SOC_DAPM_MUX("RX INT1_1 MIX1 INP0", SND_SOC_NOPM
, 0, 0,
4402 &rx_int1_1_mix_inp0_mux
),
4403 SND_SOC_DAPM_MUX("RX INT1_1 MIX1 INP1", SND_SOC_NOPM
, 0, 0,
4404 &rx_int1_1_mix_inp1_mux
),
4405 SND_SOC_DAPM_MUX("RX INT1_1 MIX1 INP2", SND_SOC_NOPM
, 0, 0,
4406 &rx_int1_1_mix_inp2_mux
),
4407 SND_SOC_DAPM_MUX("RX INT2_1 MIX1 INP0", SND_SOC_NOPM
, 0, 0,
4408 &rx_int2_1_mix_inp0_mux
),
4409 SND_SOC_DAPM_MUX("RX INT2_1 MIX1 INP1", SND_SOC_NOPM
, 0, 0,
4410 &rx_int2_1_mix_inp1_mux
),
4411 SND_SOC_DAPM_MUX("RX INT2_1 MIX1 INP2", SND_SOC_NOPM
, 0, 0,
4412 &rx_int2_1_mix_inp2_mux
),
4413 SND_SOC_DAPM_MUX("RX INT3_1 MIX1 INP0", SND_SOC_NOPM
, 0, 0,
4414 &rx_int3_1_mix_inp0_mux
),
4415 SND_SOC_DAPM_MUX("RX INT3_1 MIX1 INP1", SND_SOC_NOPM
, 0, 0,
4416 &rx_int3_1_mix_inp1_mux
),
4417 SND_SOC_DAPM_MUX("RX INT3_1 MIX1 INP2", SND_SOC_NOPM
, 0, 0,
4418 &rx_int3_1_mix_inp2_mux
),
4419 SND_SOC_DAPM_MUX("RX INT4_1 MIX1 INP0", SND_SOC_NOPM
, 0, 0,
4420 &rx_int4_1_mix_inp0_mux
),
4421 SND_SOC_DAPM_MUX("RX INT4_1 MIX1 INP1", SND_SOC_NOPM
, 0, 0,
4422 &rx_int4_1_mix_inp1_mux
),
4423 SND_SOC_DAPM_MUX("RX INT4_1 MIX1 INP2", SND_SOC_NOPM
, 0, 0,
4424 &rx_int4_1_mix_inp2_mux
),
4425 SND_SOC_DAPM_MUX("RX INT5_1 MIX1 INP0", SND_SOC_NOPM
, 0, 0,
4426 &rx_int5_1_mix_inp0_mux
),
4427 SND_SOC_DAPM_MUX("RX INT5_1 MIX1 INP1", SND_SOC_NOPM
, 0, 0,
4428 &rx_int5_1_mix_inp1_mux
),
4429 SND_SOC_DAPM_MUX("RX INT5_1 MIX1 INP2", SND_SOC_NOPM
, 0, 0,
4430 &rx_int5_1_mix_inp2_mux
),
4431 SND_SOC_DAPM_MUX("RX INT6_1 MIX1 INP0", SND_SOC_NOPM
, 0, 0,
4432 &rx_int6_1_mix_inp0_mux
),
4433 SND_SOC_DAPM_MUX("RX INT6_1 MIX1 INP1", SND_SOC_NOPM
, 0, 0,
4434 &rx_int6_1_mix_inp1_mux
),
4435 SND_SOC_DAPM_MUX("RX INT6_1 MIX1 INP2", SND_SOC_NOPM
, 0, 0,
4436 &rx_int6_1_mix_inp2_mux
),
4437 SND_SOC_DAPM_MUX("RX INT7_1 MIX1 INP0", SND_SOC_NOPM
, 0, 0,
4438 &rx_int7_1_mix_inp0_mux
),
4439 SND_SOC_DAPM_MUX("RX INT7_1 MIX1 INP1", SND_SOC_NOPM
, 0, 0,
4440 &rx_int7_1_mix_inp1_mux
),
4441 SND_SOC_DAPM_MUX("RX INT7_1 MIX1 INP2", SND_SOC_NOPM
, 0, 0,
4442 &rx_int7_1_mix_inp2_mux
),
4443 SND_SOC_DAPM_MUX("RX INT8_1 MIX1 INP0", SND_SOC_NOPM
, 0, 0,
4444 &rx_int8_1_mix_inp0_mux
),
4445 SND_SOC_DAPM_MUX("RX INT8_1 MIX1 INP1", SND_SOC_NOPM
, 0, 0,
4446 &rx_int8_1_mix_inp1_mux
),
4447 SND_SOC_DAPM_MUX("RX INT8_1 MIX1 INP2", SND_SOC_NOPM
, 0, 0,
4448 &rx_int8_1_mix_inp2_mux
),
4450 SND_SOC_DAPM_MIXER("RX INT0_1 MIX1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4451 SND_SOC_DAPM_MIXER("RX INT0 SEC MIX", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4452 SND_SOC_DAPM_MIXER("RX INT1_1 MIX1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4453 SND_SOC_DAPM_MIXER("RX INT1 SEC MIX", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4454 SND_SOC_DAPM_MIXER("RX INT2_1 MIX1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4455 SND_SOC_DAPM_MIXER("RX INT2 SEC MIX", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4456 SND_SOC_DAPM_MIXER("RX INT3_1 MIX1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4457 SND_SOC_DAPM_MIXER("RX INT3 SEC MIX", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4458 SND_SOC_DAPM_MIXER("RX INT4_1 MIX1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4459 SND_SOC_DAPM_MIXER("RX INT4 SEC MIX", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4460 SND_SOC_DAPM_MIXER("RX INT5_1 MIX1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4461 SND_SOC_DAPM_MIXER("RX INT5 SEC MIX", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4462 SND_SOC_DAPM_MIXER("RX INT6_1 MIX1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4463 SND_SOC_DAPM_MIXER("RX INT6 SEC MIX", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4464 SND_SOC_DAPM_MIXER("RX INT7_1 MIX1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4465 SND_SOC_DAPM_MIXER("RX INT7 SEC MIX", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4466 SND_SOC_DAPM_MIXER("RX INT8_1 MIX1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4467 SND_SOC_DAPM_MIXER("RX INT8 SEC MIX", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4469 SND_SOC_DAPM_MIXER("RX INT0 MIX2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4470 SND_SOC_DAPM_MIXER("RX INT1 MIX2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4471 SND_SOC_DAPM_MIXER("RX INT2 MIX2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4472 SND_SOC_DAPM_MIXER("RX INT3 MIX2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4473 SND_SOC_DAPM_MIXER("RX INT4 MIX2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4474 SND_SOC_DAPM_MIXER("RX INT5 MIX2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4475 SND_SOC_DAPM_MIXER("RX INT6 MIX2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4476 SND_SOC_DAPM_MIXER("RX INT7 MIX2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4477 SND_SOC_DAPM_MIXER("RX INT8 MIX2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
4479 SND_SOC_DAPM_MUX("RX INT0 DEM MUX", SND_SOC_NOPM
, 0, 0,
4480 &rx_int0_dem_inp_mux
),
4481 SND_SOC_DAPM_MUX("RX INT1 DEM MUX", SND_SOC_NOPM
, 0, 0,
4482 &rx_int1_dem_inp_mux
),
4483 SND_SOC_DAPM_MUX("RX INT2 DEM MUX", SND_SOC_NOPM
, 0, 0,
4484 &rx_int2_dem_inp_mux
),
4486 SND_SOC_DAPM_MUX_E("RX INT0 INTERP", SND_SOC_NOPM
,
4487 INTERP_EAR
, 0, &rx_int0_interp_mux
,
4488 wcd9335_codec_enable_interpolator
,
4489 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4490 SND_SOC_DAPM_POST_PMD
),
4491 SND_SOC_DAPM_MUX_E("RX INT1 INTERP", SND_SOC_NOPM
,
4492 INTERP_HPHL
, 0, &rx_int1_interp_mux
,
4493 wcd9335_codec_enable_interpolator
,
4494 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4495 SND_SOC_DAPM_POST_PMD
),
4496 SND_SOC_DAPM_MUX_E("RX INT2 INTERP", SND_SOC_NOPM
,
4497 INTERP_HPHR
, 0, &rx_int2_interp_mux
,
4498 wcd9335_codec_enable_interpolator
,
4499 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4500 SND_SOC_DAPM_POST_PMD
),
4501 SND_SOC_DAPM_MUX_E("RX INT3 INTERP", SND_SOC_NOPM
,
4502 INTERP_LO1
, 0, &rx_int3_interp_mux
,
4503 wcd9335_codec_enable_interpolator
,
4504 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4505 SND_SOC_DAPM_POST_PMD
),
4506 SND_SOC_DAPM_MUX_E("RX INT4 INTERP", SND_SOC_NOPM
,
4507 INTERP_LO2
, 0, &rx_int4_interp_mux
,
4508 wcd9335_codec_enable_interpolator
,
4509 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4510 SND_SOC_DAPM_POST_PMD
),
4511 SND_SOC_DAPM_MUX_E("RX INT5 INTERP", SND_SOC_NOPM
,
4512 INTERP_LO3
, 0, &rx_int5_interp_mux
,
4513 wcd9335_codec_enable_interpolator
,
4514 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4515 SND_SOC_DAPM_POST_PMD
),
4516 SND_SOC_DAPM_MUX_E("RX INT6 INTERP", SND_SOC_NOPM
,
4517 INTERP_LO4
, 0, &rx_int6_interp_mux
,
4518 wcd9335_codec_enable_interpolator
,
4519 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4520 SND_SOC_DAPM_POST_PMD
),
4521 SND_SOC_DAPM_MUX_E("RX INT7 INTERP", SND_SOC_NOPM
,
4522 INTERP_SPKR1
, 0, &rx_int7_interp_mux
,
4523 wcd9335_codec_enable_interpolator
,
4524 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4525 SND_SOC_DAPM_POST_PMD
),
4526 SND_SOC_DAPM_MUX_E("RX INT8 INTERP", SND_SOC_NOPM
,
4527 INTERP_SPKR2
, 0, &rx_int8_interp_mux
,
4528 wcd9335_codec_enable_interpolator
,
4529 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4530 SND_SOC_DAPM_POST_PMD
),
4532 SND_SOC_DAPM_DAC_E("RX INT0 DAC", NULL
, SND_SOC_NOPM
,
4533 0, 0, wcd9335_codec_ear_dac_event
,
4534 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4535 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4536 SND_SOC_DAPM_DAC_E("RX INT1 DAC", NULL
, WCD9335_ANA_HPH
,
4537 5, 0, wcd9335_codec_hphl_dac_event
,
4538 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4539 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4540 SND_SOC_DAPM_DAC_E("RX INT2 DAC", NULL
, WCD9335_ANA_HPH
,
4541 4, 0, wcd9335_codec_hphr_dac_event
,
4542 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4543 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4544 SND_SOC_DAPM_DAC_E("RX INT3 DAC", NULL
, SND_SOC_NOPM
,
4545 0, 0, wcd9335_codec_lineout_dac_event
,
4546 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
4547 SND_SOC_DAPM_DAC_E("RX INT4 DAC", NULL
, SND_SOC_NOPM
,
4548 0, 0, wcd9335_codec_lineout_dac_event
,
4549 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
4550 SND_SOC_DAPM_DAC_E("RX INT5 DAC", NULL
, SND_SOC_NOPM
,
4551 0, 0, wcd9335_codec_lineout_dac_event
,
4552 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
4553 SND_SOC_DAPM_DAC_E("RX INT6 DAC", NULL
, SND_SOC_NOPM
,
4554 0, 0, wcd9335_codec_lineout_dac_event
,
4555 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMD
),
4556 SND_SOC_DAPM_PGA_E("HPHL PA", WCD9335_ANA_HPH
, 7, 0, NULL
, 0,
4557 wcd9335_codec_enable_hphl_pa
,
4558 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4559 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4560 SND_SOC_DAPM_PGA_E("HPHR PA", WCD9335_ANA_HPH
, 6, 0, NULL
, 0,
4561 wcd9335_codec_enable_hphr_pa
,
4562 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4563 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4564 SND_SOC_DAPM_PGA_E("EAR PA", WCD9335_ANA_EAR
, 7, 0, NULL
, 0,
4565 wcd9335_codec_enable_ear_pa
,
4566 SND_SOC_DAPM_POST_PMU
|
4567 SND_SOC_DAPM_POST_PMD
),
4568 SND_SOC_DAPM_PGA_E("LINEOUT1 PA", WCD9335_ANA_LO_1_2
, 7, 0, NULL
, 0,
4569 wcd9335_codec_enable_lineout_pa
,
4570 SND_SOC_DAPM_POST_PMU
|
4571 SND_SOC_DAPM_POST_PMD
),
4572 SND_SOC_DAPM_PGA_E("LINEOUT2 PA", WCD9335_ANA_LO_1_2
, 6, 0, NULL
, 0,
4573 wcd9335_codec_enable_lineout_pa
,
4574 SND_SOC_DAPM_POST_PMU
|
4575 SND_SOC_DAPM_POST_PMD
),
4576 SND_SOC_DAPM_PGA_E("LINEOUT3 PA", WCD9335_ANA_LO_3_4
, 7, 0, NULL
, 0,
4577 wcd9335_codec_enable_lineout_pa
,
4578 SND_SOC_DAPM_POST_PMU
|
4579 SND_SOC_DAPM_POST_PMD
),
4580 SND_SOC_DAPM_PGA_E("LINEOUT4 PA", WCD9335_ANA_LO_3_4
, 6, 0, NULL
, 0,
4581 wcd9335_codec_enable_lineout_pa
,
4582 SND_SOC_DAPM_POST_PMU
|
4583 SND_SOC_DAPM_POST_PMD
),
4584 SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM
, 0, 0,
4585 wcd9335_codec_enable_rx_bias
, SND_SOC_DAPM_PRE_PMU
|
4586 SND_SOC_DAPM_POST_PMD
),
4587 SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM
, 0, 0,
4588 wcd9335_codec_enable_mclk
, SND_SOC_DAPM_PRE_PMU
|
4589 SND_SOC_DAPM_POST_PMD
),
4592 SND_SOC_DAPM_INPUT("AMIC1"),
4593 SND_SOC_DAPM_INPUT("AMIC2"),
4594 SND_SOC_DAPM_INPUT("AMIC3"),
4595 SND_SOC_DAPM_INPUT("AMIC4"),
4596 SND_SOC_DAPM_INPUT("AMIC5"),
4597 SND_SOC_DAPM_INPUT("AMIC6"),
4599 SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM
,
4600 AIF1_CAP
, 0, wcd9335_codec_enable_slim
,
4601 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
4603 SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM
,
4604 AIF2_CAP
, 0, wcd9335_codec_enable_slim
,
4605 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
4607 SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM
,
4608 AIF3_CAP
, 0, wcd9335_codec_enable_slim
,
4609 SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_POST_PMD
),
4611 SND_SOC_DAPM_SUPPLY("MIC BIAS1", SND_SOC_NOPM
, 0, 0,
4612 wcd9335_codec_enable_micbias
,
4613 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4614 SND_SOC_DAPM_POST_PMD
),
4615 SND_SOC_DAPM_SUPPLY("MIC BIAS2", SND_SOC_NOPM
, 0, 0,
4616 wcd9335_codec_enable_micbias
,
4617 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4618 SND_SOC_DAPM_POST_PMD
),
4619 SND_SOC_DAPM_SUPPLY("MIC BIAS3", SND_SOC_NOPM
, 0, 0,
4620 wcd9335_codec_enable_micbias
,
4621 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4622 SND_SOC_DAPM_POST_PMD
),
4623 SND_SOC_DAPM_SUPPLY("MIC BIAS4", SND_SOC_NOPM
, 0, 0,
4624 wcd9335_codec_enable_micbias
,
4625 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4626 SND_SOC_DAPM_POST_PMD
),
4628 SND_SOC_DAPM_ADC_E("ADC1", NULL
, WCD9335_ANA_AMIC1
, 7, 0,
4629 wcd9335_codec_enable_adc
, SND_SOC_DAPM_PRE_PMU
),
4630 SND_SOC_DAPM_ADC_E("ADC2", NULL
, WCD9335_ANA_AMIC2
, 7, 0,
4631 wcd9335_codec_enable_adc
, SND_SOC_DAPM_PRE_PMU
),
4632 SND_SOC_DAPM_ADC_E("ADC3", NULL
, WCD9335_ANA_AMIC3
, 7, 0,
4633 wcd9335_codec_enable_adc
, SND_SOC_DAPM_PRE_PMU
),
4634 SND_SOC_DAPM_ADC_E("ADC4", NULL
, WCD9335_ANA_AMIC4
, 7, 0,
4635 wcd9335_codec_enable_adc
, SND_SOC_DAPM_PRE_PMU
),
4636 SND_SOC_DAPM_ADC_E("ADC5", NULL
, WCD9335_ANA_AMIC5
, 7, 0,
4637 wcd9335_codec_enable_adc
, SND_SOC_DAPM_PRE_PMU
),
4638 SND_SOC_DAPM_ADC_E("ADC6", NULL
, WCD9335_ANA_AMIC6
, 7, 0,
4639 wcd9335_codec_enable_adc
, SND_SOC_DAPM_PRE_PMU
),
4641 /* Digital Mic Inputs */
4642 SND_SOC_DAPM_ADC_E("DMIC0", NULL
, SND_SOC_NOPM
, 0, 0,
4643 wcd9335_codec_enable_dmic
, SND_SOC_DAPM_PRE_PMU
|
4644 SND_SOC_DAPM_POST_PMD
),
4646 SND_SOC_DAPM_ADC_E("DMIC1", NULL
, SND_SOC_NOPM
, 0, 0,
4647 wcd9335_codec_enable_dmic
, SND_SOC_DAPM_PRE_PMU
|
4648 SND_SOC_DAPM_POST_PMD
),
4650 SND_SOC_DAPM_ADC_E("DMIC2", NULL
, SND_SOC_NOPM
, 0, 0,
4651 wcd9335_codec_enable_dmic
, SND_SOC_DAPM_PRE_PMU
|
4652 SND_SOC_DAPM_POST_PMD
),
4654 SND_SOC_DAPM_ADC_E("DMIC3", NULL
, SND_SOC_NOPM
, 0, 0,
4655 wcd9335_codec_enable_dmic
, SND_SOC_DAPM_PRE_PMU
|
4656 SND_SOC_DAPM_POST_PMD
),
4658 SND_SOC_DAPM_ADC_E("DMIC4", NULL
, SND_SOC_NOPM
, 0, 0,
4659 wcd9335_codec_enable_dmic
, SND_SOC_DAPM_PRE_PMU
|
4660 SND_SOC_DAPM_POST_PMD
),
4662 SND_SOC_DAPM_ADC_E("DMIC5", NULL
, SND_SOC_NOPM
, 0, 0,
4663 wcd9335_codec_enable_dmic
, SND_SOC_DAPM_PRE_PMU
|
4664 SND_SOC_DAPM_POST_PMD
),
4666 SND_SOC_DAPM_MUX("DMIC MUX0", SND_SOC_NOPM
, 0, 0,
4668 SND_SOC_DAPM_MUX("DMIC MUX1", SND_SOC_NOPM
, 0, 0,
4670 SND_SOC_DAPM_MUX("DMIC MUX2", SND_SOC_NOPM
, 0, 0,
4672 SND_SOC_DAPM_MUX("DMIC MUX3", SND_SOC_NOPM
, 0, 0,
4674 SND_SOC_DAPM_MUX("DMIC MUX4", SND_SOC_NOPM
, 0, 0,
4676 SND_SOC_DAPM_MUX("DMIC MUX5", SND_SOC_NOPM
, 0, 0,
4678 SND_SOC_DAPM_MUX("DMIC MUX6", SND_SOC_NOPM
, 0, 0,
4680 SND_SOC_DAPM_MUX("DMIC MUX7", SND_SOC_NOPM
, 0, 0,
4682 SND_SOC_DAPM_MUX("DMIC MUX8", SND_SOC_NOPM
, 0, 0,
4685 SND_SOC_DAPM_MUX("AMIC MUX0", SND_SOC_NOPM
, 0, 0,
4687 SND_SOC_DAPM_MUX("AMIC MUX1", SND_SOC_NOPM
, 0, 0,
4689 SND_SOC_DAPM_MUX("AMIC MUX2", SND_SOC_NOPM
, 0, 0,
4691 SND_SOC_DAPM_MUX("AMIC MUX3", SND_SOC_NOPM
, 0, 0,
4693 SND_SOC_DAPM_MUX("AMIC MUX4", SND_SOC_NOPM
, 0, 0,
4695 SND_SOC_DAPM_MUX("AMIC MUX5", SND_SOC_NOPM
, 0, 0,
4697 SND_SOC_DAPM_MUX("AMIC MUX6", SND_SOC_NOPM
, 0, 0,
4699 SND_SOC_DAPM_MUX("AMIC MUX7", SND_SOC_NOPM
, 0, 0,
4701 SND_SOC_DAPM_MUX("AMIC MUX8", SND_SOC_NOPM
, 0, 0,
4704 SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM
, AIF1_CAP
, 0,
4705 aif1_cap_mixer
, ARRAY_SIZE(aif1_cap_mixer
)),
4707 SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM
, AIF2_CAP
, 0,
4708 aif2_cap_mixer
, ARRAY_SIZE(aif2_cap_mixer
)),
4710 SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM
, AIF3_CAP
, 0,
4711 aif3_cap_mixer
, ARRAY_SIZE(aif3_cap_mixer
)),
4713 SND_SOC_DAPM_MUX("SLIM TX0 MUX", SND_SOC_NOPM
, WCD9335_TX0
, 0,
4715 SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM
, WCD9335_TX1
, 0,
4717 SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM
, WCD9335_TX2
, 0,
4719 SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM
, WCD9335_TX3
, 0,
4721 SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM
, WCD9335_TX4
, 0,
4723 SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM
, WCD9335_TX5
, 0,
4725 SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM
, WCD9335_TX6
, 0,
4727 SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM
, WCD9335_TX7
, 0,
4729 SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM
, WCD9335_TX8
, 0,
4732 SND_SOC_DAPM_MUX_E("ADC MUX0", WCD9335_CDC_TX0_TX_PATH_CTL
, 5, 0,
4733 &tx_adc_mux0
, wcd9335_codec_enable_dec
,
4734 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4735 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4737 SND_SOC_DAPM_MUX_E("ADC MUX1", WCD9335_CDC_TX1_TX_PATH_CTL
, 5, 0,
4738 &tx_adc_mux1
, wcd9335_codec_enable_dec
,
4739 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4740 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4742 SND_SOC_DAPM_MUX_E("ADC MUX2", WCD9335_CDC_TX2_TX_PATH_CTL
, 5, 0,
4743 &tx_adc_mux2
, wcd9335_codec_enable_dec
,
4744 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4745 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4747 SND_SOC_DAPM_MUX_E("ADC MUX3", WCD9335_CDC_TX3_TX_PATH_CTL
, 5, 0,
4748 &tx_adc_mux3
, wcd9335_codec_enable_dec
,
4749 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4750 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4752 SND_SOC_DAPM_MUX_E("ADC MUX4", WCD9335_CDC_TX4_TX_PATH_CTL
, 5, 0,
4753 &tx_adc_mux4
, wcd9335_codec_enable_dec
,
4754 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4755 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4757 SND_SOC_DAPM_MUX_E("ADC MUX5", WCD9335_CDC_TX5_TX_PATH_CTL
, 5, 0,
4758 &tx_adc_mux5
, wcd9335_codec_enable_dec
,
4759 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4760 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4762 SND_SOC_DAPM_MUX_E("ADC MUX6", WCD9335_CDC_TX6_TX_PATH_CTL
, 5, 0,
4763 &tx_adc_mux6
, wcd9335_codec_enable_dec
,
4764 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4765 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4767 SND_SOC_DAPM_MUX_E("ADC MUX7", WCD9335_CDC_TX7_TX_PATH_CTL
, 5, 0,
4768 &tx_adc_mux7
, wcd9335_codec_enable_dec
,
4769 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4770 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4772 SND_SOC_DAPM_MUX_E("ADC MUX8", WCD9335_CDC_TX8_TX_PATH_CTL
, 5, 0,
4773 &tx_adc_mux8
, wcd9335_codec_enable_dec
,
4774 SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
|
4775 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMD
),
4778 static void wcd9335_enable_sido_buck(struct snd_soc_component
*component
)
4780 struct wcd9335_codec
*wcd
= dev_get_drvdata(component
->dev
);
4782 snd_soc_component_update_bits(component
, WCD9335_ANA_RCO
,
4783 WCD9335_ANA_RCO_BG_EN_MASK
,
4784 WCD9335_ANA_RCO_BG_ENABLE
);
4785 snd_soc_component_update_bits(component
, WCD9335_ANA_BUCK_CTL
,
4786 WCD9335_ANA_BUCK_CTL_VOUT_D_IREF_MASK
,
4787 WCD9335_ANA_BUCK_CTL_VOUT_D_IREF_EXT
);
4788 /* 100us sleep needed after IREF settings */
4789 usleep_range(100, 110);
4790 snd_soc_component_update_bits(component
, WCD9335_ANA_BUCK_CTL
,
4791 WCD9335_ANA_BUCK_CTL_VOUT_D_VREF_MASK
,
4792 WCD9335_ANA_BUCK_CTL_VOUT_D_VREF_EXT
);
4793 /* 100us sleep needed after VREF settings */
4794 usleep_range(100, 110);
4795 wcd
->sido_input_src
= SIDO_SOURCE_RCO_BG
;
4798 static int wcd9335_enable_efuse_sensing(struct snd_soc_component
*comp
)
4800 _wcd9335_codec_enable_mclk(comp
, true);
4801 snd_soc_component_update_bits(comp
,
4802 WCD9335_CHIP_TIER_CTRL_EFUSE_CTL
,
4803 WCD9335_CHIP_TIER_CTRL_EFUSE_EN_MASK
,
4804 WCD9335_CHIP_TIER_CTRL_EFUSE_ENABLE
);
4806 * 5ms sleep required after enabling efuse control
4807 * before checking the status.
4809 usleep_range(5000, 5500);
4811 if (!(snd_soc_component_read32(comp
,
4812 WCD9335_CHIP_TIER_CTRL_EFUSE_STATUS
) &
4813 WCD9335_CHIP_TIER_CTRL_EFUSE_EN_MASK
))
4814 WARN(1, "%s: Efuse sense is not complete\n", __func__
);
4816 wcd9335_enable_sido_buck(comp
);
4817 _wcd9335_codec_enable_mclk(comp
, false);
4822 static void wcd9335_codec_init(struct snd_soc_component
*component
)
4824 struct wcd9335_codec
*wcd
= dev_get_drvdata(component
->dev
);
4827 /* ungate MCLK and set clk rate */
4828 regmap_update_bits(wcd
->regmap
, WCD9335_CODEC_RPM_CLK_GATE
,
4829 WCD9335_CODEC_RPM_CLK_GATE_MCLK_GATE_MASK
, 0);
4831 regmap_update_bits(wcd
->regmap
, WCD9335_CODEC_RPM_CLK_MCLK_CFG
,
4832 WCD9335_CODEC_RPM_CLK_MCLK_CFG_MCLK_MASK
,
4833 WCD9335_CODEC_RPM_CLK_MCLK_CFG_9P6MHZ
);
4835 for (i
= 0; i
< ARRAY_SIZE(wcd9335_codec_reg_init
); i
++)
4836 snd_soc_component_update_bits(component
,
4837 wcd9335_codec_reg_init
[i
].reg
,
4838 wcd9335_codec_reg_init
[i
].mask
,
4839 wcd9335_codec_reg_init
[i
].val
);
4841 wcd9335_enable_efuse_sensing(component
);
4844 static int wcd9335_codec_probe(struct snd_soc_component
*component
)
4846 struct wcd9335_codec
*wcd
= dev_get_drvdata(component
->dev
);
4849 snd_soc_component_init_regmap(component
, wcd
->regmap
);
4851 wcd
->clsh_ctrl
= wcd_clsh_ctrl_alloc(component
, wcd
->version
);
4852 if (IS_ERR(wcd
->clsh_ctrl
))
4853 return PTR_ERR(wcd
->clsh_ctrl
);
4855 /* Default HPH Mode to Class-H HiFi */
4856 wcd
->hph_mode
= CLS_H_HIFI
;
4857 wcd
->component
= component
;
4859 wcd9335_codec_init(component
);
4861 for (i
= 0; i
< NUM_CODEC_DAIS
; i
++)
4862 INIT_LIST_HEAD(&wcd
->dai
[i
].slim_ch_list
);
4864 return wcd9335_setup_irqs(wcd
);
4867 static void wcd9335_codec_remove(struct snd_soc_component
*comp
)
4869 struct wcd9335_codec
*wcd
= dev_get_drvdata(comp
->dev
);
4871 wcd_clsh_ctrl_free(wcd
->clsh_ctrl
);
4872 free_irq(regmap_irq_get_virq(wcd
->irq_data
, WCD9335_IRQ_SLIMBUS
), wcd
);
4875 static int wcd9335_codec_set_sysclk(struct snd_soc_component
*comp
,
4876 int clk_id
, int source
,
4877 unsigned int freq
, int dir
)
4879 struct wcd9335_codec
*wcd
= dev_get_drvdata(comp
->dev
);
4881 wcd
->mclk_rate
= freq
;
4883 if (wcd
->mclk_rate
== WCD9335_MCLK_CLK_12P288MHZ
)
4884 snd_soc_component_update_bits(comp
,
4885 WCD9335_CODEC_RPM_CLK_MCLK_CFG
,
4886 WCD9335_CODEC_RPM_CLK_MCLK_CFG_MCLK_MASK
,
4887 WCD9335_CODEC_RPM_CLK_MCLK_CFG_12P288MHZ
);
4888 else if (wcd
->mclk_rate
== WCD9335_MCLK_CLK_9P6MHZ
)
4889 snd_soc_component_update_bits(comp
,
4890 WCD9335_CODEC_RPM_CLK_MCLK_CFG
,
4891 WCD9335_CODEC_RPM_CLK_MCLK_CFG_MCLK_MASK
,
4892 WCD9335_CODEC_RPM_CLK_MCLK_CFG_9P6MHZ
);
4894 return clk_set_rate(wcd
->mclk
, freq
);
4897 static const struct snd_soc_component_driver wcd9335_component_drv
= {
4898 .probe
= wcd9335_codec_probe
,
4899 .remove
= wcd9335_codec_remove
,
4900 .set_sysclk
= wcd9335_codec_set_sysclk
,
4901 .controls
= wcd9335_snd_controls
,
4902 .num_controls
= ARRAY_SIZE(wcd9335_snd_controls
),
4903 .dapm_widgets
= wcd9335_dapm_widgets
,
4904 .num_dapm_widgets
= ARRAY_SIZE(wcd9335_dapm_widgets
),
4905 .dapm_routes
= wcd9335_audio_map
,
4906 .num_dapm_routes
= ARRAY_SIZE(wcd9335_audio_map
),
4909 static int wcd9335_probe(struct wcd9335_codec
*wcd
)
4911 struct device
*dev
= wcd
->dev
;
4913 memcpy(wcd
->rx_chs
, wcd9335_rx_chs
, sizeof(wcd9335_rx_chs
));
4914 memcpy(wcd
->tx_chs
, wcd9335_tx_chs
, sizeof(wcd9335_tx_chs
));
4916 wcd
->sido_input_src
= SIDO_SOURCE_INTERNAL
;
4917 wcd
->sido_voltage
= SIDO_VOLTAGE_NOMINAL_MV
;
4919 return devm_snd_soc_register_component(dev
, &wcd9335_component_drv
,
4921 ARRAY_SIZE(wcd9335_slim_dais
));
4924 static const struct regmap_range_cfg wcd9335_ranges
[] = {
4928 .range_max
= WCD9335_MAX_REGISTER
,
4929 .selector_reg
= WCD9335_REG(0x0, 0),
4930 .selector_mask
= 0xff,
4931 .selector_shift
= 0,
4932 .window_start
= 0x0,
4933 .window_len
= 0x1000,
4937 static bool wcd9335_is_volatile_register(struct device
*dev
, unsigned int reg
)
4940 case WCD9335_INTR_PIN1_STATUS0
...WCD9335_INTR_PIN2_CLEAR3
:
4941 case WCD9335_ANA_MBHC_RESULT_3
:
4942 case WCD9335_ANA_MBHC_RESULT_2
:
4943 case WCD9335_ANA_MBHC_RESULT_1
:
4944 case WCD9335_ANA_MBHC_MECH
:
4945 case WCD9335_ANA_MBHC_ELECT
:
4946 case WCD9335_ANA_MBHC_ZDET
:
4947 case WCD9335_ANA_MICB2
:
4948 case WCD9335_ANA_RCO
:
4949 case WCD9335_ANA_BIAS
:
4956 static struct regmap_config wcd9335_regmap_config
= {
4959 .cache_type
= REGCACHE_RBTREE
,
4960 .max_register
= WCD9335_MAX_REGISTER
,
4961 .can_multi_write
= true,
4962 .ranges
= wcd9335_ranges
,
4963 .num_ranges
= ARRAY_SIZE(wcd9335_ranges
),
4964 .volatile_reg
= wcd9335_is_volatile_register
,
4967 static const struct regmap_range_cfg wcd9335_ifc_ranges
[] = {
4969 .name
= "WCD9335-IFC-DEV",
4971 .range_max
= WCD9335_REG(0, 0x7ff),
4972 .selector_reg
= WCD9335_REG(0, 0x0),
4973 .selector_mask
= 0xff,
4974 .selector_shift
= 0,
4975 .window_start
= 0x0,
4976 .window_len
= 0x1000,
4980 static struct regmap_config wcd9335_ifc_regmap_config
= {
4983 .can_multi_write
= true,
4984 .max_register
= WCD9335_REG(0, 0x7FF),
4985 .ranges
= wcd9335_ifc_ranges
,
4986 .num_ranges
= ARRAY_SIZE(wcd9335_ifc_ranges
),
4989 static const struct regmap_irq wcd9335_codec_irqs
[] = {
4991 [WCD9335_IRQ_SLIMBUS
] = {
4995 .type_reg_offset
= 0,
4996 .types_supported
= IRQ_TYPE_EDGE_BOTH
,
4997 .type_reg_mask
= BIT(0),
5002 static const struct regmap_irq_chip wcd9335_regmap_irq1_chip
= {
5003 .name
= "wcd9335_pin1_irq",
5004 .status_base
= WCD9335_INTR_PIN1_STATUS0
,
5005 .mask_base
= WCD9335_INTR_PIN1_MASK0
,
5006 .ack_base
= WCD9335_INTR_PIN1_CLEAR0
,
5007 .type_base
= WCD9335_INTR_LEVEL0
,
5010 .irqs
= wcd9335_codec_irqs
,
5011 .num_irqs
= ARRAY_SIZE(wcd9335_codec_irqs
),
5014 static int wcd9335_parse_dt(struct wcd9335_codec
*wcd
)
5016 struct device
*dev
= wcd
->dev
;
5017 struct device_node
*np
= dev
->of_node
;
5020 wcd
->reset_gpio
= of_get_named_gpio(np
, "reset-gpios", 0);
5021 if (wcd
->reset_gpio
< 0) {
5022 dev_err(dev
, "Reset GPIO missing from DT\n");
5023 return wcd
->reset_gpio
;
5026 wcd
->mclk
= devm_clk_get(dev
, "mclk");
5027 if (IS_ERR(wcd
->mclk
)) {
5028 dev_err(dev
, "mclk not found\n");
5029 return PTR_ERR(wcd
->mclk
);
5032 wcd
->native_clk
= devm_clk_get(dev
, "slimbus");
5033 if (IS_ERR(wcd
->native_clk
)) {
5034 dev_err(dev
, "slimbus clock not found\n");
5035 return PTR_ERR(wcd
->native_clk
);
5038 wcd
->supplies
[0].supply
= "vdd-buck";
5039 wcd
->supplies
[1].supply
= "vdd-buck-sido";
5040 wcd
->supplies
[2].supply
= "vdd-tx";
5041 wcd
->supplies
[3].supply
= "vdd-rx";
5042 wcd
->supplies
[4].supply
= "vdd-io";
5044 ret
= regulator_bulk_get(dev
, WCD9335_MAX_SUPPLY
, wcd
->supplies
);
5046 dev_err(dev
, "Failed to get supplies: err = %d\n", ret
);
5053 static int wcd9335_power_on_reset(struct wcd9335_codec
*wcd
)
5055 struct device
*dev
= wcd
->dev
;
5058 ret
= regulator_bulk_enable(WCD9335_MAX_SUPPLY
, wcd
->supplies
);
5060 dev_err(dev
, "Failed to get supplies: err = %d\n", ret
);
5065 * For WCD9335, it takes about 600us for the Vout_A and
5066 * Vout_D to be ready after BUCK_SIDO is powered up.
5067 * SYS_RST_N shouldn't be pulled high during this time
5068 * Toggle the reset line to make sure the reset pulse is
5071 usleep_range(600, 650);
5073 gpio_direction_output(wcd
->reset_gpio
, 0);
5075 gpio_set_value(wcd
->reset_gpio
, 1);
5081 static int wcd9335_bring_up(struct wcd9335_codec
*wcd
)
5083 struct regmap
*rm
= wcd
->regmap
;
5086 regmap_read(rm
, WCD9335_CHIP_TIER_CTRL_EFUSE_VAL_OUT0
, &val
);
5087 regmap_read(rm
, WCD9335_CHIP_TIER_CTRL_CHIP_ID_BYTE0
, &byte0
);
5089 if ((val
< 0) || (byte0
< 0)) {
5090 dev_err(wcd
->dev
, "WCD9335 CODEC version detection fail!\n");
5095 dev_info(wcd
->dev
, "WCD9335 CODEC version is v2.0\n");
5096 wcd
->version
= WCD9335_VERSION_2_0
;
5097 regmap_write(rm
, WCD9335_CODEC_RPM_RST_CTL
, 0x01);
5098 regmap_write(rm
, WCD9335_SIDO_SIDO_TEST_2
, 0x00);
5099 regmap_write(rm
, WCD9335_SIDO_SIDO_CCL_8
, 0x6F);
5100 regmap_write(rm
, WCD9335_BIAS_VBG_FINE_ADJ
, 0x65);
5101 regmap_write(rm
, WCD9335_CODEC_RPM_PWR_CDC_DIG_HM_CTL
, 0x5);
5102 regmap_write(rm
, WCD9335_CODEC_RPM_PWR_CDC_DIG_HM_CTL
, 0x7);
5103 regmap_write(rm
, WCD9335_CODEC_RPM_PWR_CDC_DIG_HM_CTL
, 0x3);
5104 regmap_write(rm
, WCD9335_CODEC_RPM_RST_CTL
, 0x3);
5106 dev_err(wcd
->dev
, "WCD9335 CODEC version not supported\n");
5113 static int wcd9335_irq_init(struct wcd9335_codec
*wcd
)
5118 * INTR1 consists of all possible interrupt sources Ear OCP,
5119 * HPH OCP, MBHC, MAD, VBAT, and SVA
5120 * INTR2 is a subset of first interrupt sources MAD, VBAT, and SVA
5122 wcd
->intr1
= of_irq_get_byname(wcd
->dev
->of_node
, "intr1");
5123 if (wcd
->intr1
< 0) {
5124 if (wcd
->intr1
!= -EPROBE_DEFER
)
5125 dev_err(wcd
->dev
, "Unable to configure IRQ\n");
5130 ret
= devm_regmap_add_irq_chip(wcd
->dev
, wcd
->regmap
, wcd
->intr1
,
5131 IRQF_TRIGGER_HIGH
, 0,
5132 &wcd9335_regmap_irq1_chip
, &wcd
->irq_data
);
5134 dev_err(wcd
->dev
, "Failed to register IRQ chip: %d\n", ret
);
5139 static int wcd9335_slim_probe(struct slim_device
*slim
)
5141 struct device
*dev
= &slim
->dev
;
5142 struct wcd9335_codec
*wcd
;
5145 wcd
= devm_kzalloc(dev
, sizeof(*wcd
), GFP_KERNEL
);
5150 ret
= wcd9335_parse_dt(wcd
);
5152 dev_err(dev
, "Error parsing DT: %d\n", ret
);
5156 ret
= wcd9335_power_on_reset(wcd
);
5160 dev_set_drvdata(dev
, wcd
);
5165 static int wcd9335_slim_status(struct slim_device
*sdev
,
5166 enum slim_device_status status
)
5168 struct device
*dev
= &sdev
->dev
;
5169 struct device_node
*ifc_dev_np
;
5170 struct wcd9335_codec
*wcd
;
5173 wcd
= dev_get_drvdata(dev
);
5175 ifc_dev_np
= of_parse_phandle(dev
->of_node
, "slim-ifc-dev", 0);
5177 dev_err(dev
, "No Interface device found\n");
5182 wcd
->slim_ifc_dev
= of_slim_get_device(sdev
->ctrl
, ifc_dev_np
);
5183 of_node_put(ifc_dev_np
);
5184 if (!wcd
->slim_ifc_dev
) {
5185 dev_err(dev
, "Unable to get SLIM Interface device\n");
5189 slim_get_logical_addr(wcd
->slim_ifc_dev
);
5191 wcd
->regmap
= regmap_init_slimbus(sdev
, &wcd9335_regmap_config
);
5192 if (IS_ERR(wcd
->regmap
)) {
5193 dev_err(dev
, "Failed to allocate slim register map\n");
5194 return PTR_ERR(wcd
->regmap
);
5197 wcd
->if_regmap
= regmap_init_slimbus(wcd
->slim_ifc_dev
,
5198 &wcd9335_ifc_regmap_config
);
5199 if (IS_ERR(wcd
->if_regmap
)) {
5200 dev_err(dev
, "Failed to allocate ifc register map\n");
5201 return PTR_ERR(wcd
->if_regmap
);
5204 ret
= wcd9335_bring_up(wcd
);
5206 dev_err(dev
, "Failed to bringup WCD9335\n");
5210 ret
= wcd9335_irq_init(wcd
);
5219 static const struct slim_device_id wcd9335_slim_id
[] = {
5220 {SLIM_MANF_ID_QCOM
, SLIM_PROD_CODE_WCD9335
, 0x1, 0x0},
5223 MODULE_DEVICE_TABLE(slim
, wcd9335_slim_id
);
5225 static struct slim_driver wcd9335_slim_driver
= {
5227 .name
= "wcd9335-slim",
5229 .probe
= wcd9335_slim_probe
,
5230 .device_status
= wcd9335_slim_status
,
5231 .id_table
= wcd9335_slim_id
,
5234 module_slim_driver(wcd9335_slim_driver
);
5235 MODULE_DESCRIPTION("WCD9335 slim driver");
5236 MODULE_LICENSE("GPL v2");
5237 MODULE_ALIAS("slim:217:1a0:*");