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 4 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> 20 #include <linux/of.h> 21 #include <linux/of_irq.h> 22 #include <sound/tlv.h> 23 #include <sound/info.h> 24 #include "wcd9335.h" 25 #include "wcd-clsh-v2.h" 26 27 #include <dt-bindings/sound/qcom,wcd9335.h> 28 29 #define WCD9335_RATES_MASK (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ 30 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\ 31 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000) 32 /* Fractional Rates */ 33 #define WCD9335_FRAC_RATES_MASK (SNDRV_PCM_RATE_44100) 34 #define WCD9335_FORMATS_S16_S24_LE (SNDRV_PCM_FMTBIT_S16_LE | \ 35 SNDRV_PCM_FMTBIT_S24_LE) 36 37 /* slave port water mark level 38 * (0: 6bytes, 1: 9bytes, 2: 12 bytes, 3: 15 bytes) 39 */ 40 #define SLAVE_PORT_WATER_MARK_6BYTES 0 41 #define SLAVE_PORT_WATER_MARK_9BYTES 1 42 #define SLAVE_PORT_WATER_MARK_12BYTES 2 43 #define SLAVE_PORT_WATER_MARK_15BYTES 3 44 #define SLAVE_PORT_WATER_MARK_SHIFT 1 45 #define SLAVE_PORT_ENABLE 1 46 #define SLAVE_PORT_DISABLE 0 47 #define WCD9335_SLIM_WATER_MARK_VAL \ 48 ((SLAVE_PORT_WATER_MARK_12BYTES << SLAVE_PORT_WATER_MARK_SHIFT) | \ 49 (SLAVE_PORT_ENABLE)) 50 51 #define WCD9335_SLIM_NUM_PORT_REG 3 52 #define WCD9335_SLIM_PGD_PORT_INT_TX_EN0 (WCD9335_SLIM_PGD_PORT_INT_EN0 + 2) 53 54 #define WCD9335_MCLK_CLK_12P288MHZ 12288000 55 #define WCD9335_MCLK_CLK_9P6MHZ 9600000 56 57 #define WCD9335_SLIM_CLOSE_TIMEOUT 1000 58 #define WCD9335_SLIM_IRQ_OVERFLOW (1 << 0) 59 #define WCD9335_SLIM_IRQ_UNDERFLOW (1 << 1) 60 #define WCD9335_SLIM_IRQ_PORT_CLOSED (1 << 2) 61 62 #define WCD9335_NUM_INTERPOLATORS 9 63 #define WCD9335_RX_START 16 64 #define WCD9335_SLIM_CH_START 128 65 #define WCD9335_MAX_MICBIAS 4 66 #define WCD9335_MAX_VALID_ADC_MUX 13 67 #define WCD9335_INVALID_ADC_MUX 9 68 69 #define TX_HPF_CUT_OFF_FREQ_MASK 0x60 70 #define CF_MIN_3DB_4HZ 0x0 71 #define CF_MIN_3DB_75HZ 0x1 72 #define CF_MIN_3DB_150HZ 0x2 73 #define WCD9335_DMIC_CLK_DIV_2 0x0 74 #define WCD9335_DMIC_CLK_DIV_3 0x1 75 #define WCD9335_DMIC_CLK_DIV_4 0x2 76 #define WCD9335_DMIC_CLK_DIV_6 0x3 77 #define WCD9335_DMIC_CLK_DIV_8 0x4 78 #define WCD9335_DMIC_CLK_DIV_16 0x5 79 #define WCD9335_DMIC_CLK_DRIVE_DEFAULT 0x02 80 #define WCD9335_AMIC_PWR_LEVEL_LP 0 81 #define WCD9335_AMIC_PWR_LEVEL_DEFAULT 1 82 #define WCD9335_AMIC_PWR_LEVEL_HP 2 83 #define WCD9335_AMIC_PWR_LVL_MASK 0x60 84 #define WCD9335_AMIC_PWR_LVL_SHIFT 0x5 85 86 #define WCD9335_DEC_PWR_LVL_MASK 0x06 87 #define WCD9335_DEC_PWR_LVL_LP 0x02 88 #define WCD9335_DEC_PWR_LVL_HP 0x04 89 #define WCD9335_DEC_PWR_LVL_DF 0x00 90 91 #define WCD9335_SLIM_RX_CH(p) \ 92 {.port = p + WCD9335_RX_START, .shift = p,} 93 94 #define WCD9335_SLIM_TX_CH(p) \ 95 {.port = p, .shift = p,} 96 97 /* vout step value */ 98 #define WCD9335_CALCULATE_VOUT_D(req_mv) (((req_mv - 650) * 10) / 25) 99 100 #define WCD9335_INTERPOLATOR_PATH(id) \ 101 {"RX INT" #id "_1 MIX1 INP0", "RX0", "SLIM RX0"}, \ 102 {"RX INT" #id "_1 MIX1 INP0", "RX1", "SLIM RX1"}, \ 103 {"RX INT" #id "_1 MIX1 INP0", "RX2", "SLIM RX2"}, \ 104 {"RX INT" #id "_1 MIX1 INP0", "RX3", "SLIM RX3"}, \ 105 {"RX INT" #id "_1 MIX1 INP0", "RX4", "SLIM RX4"}, \ 106 {"RX INT" #id "_1 MIX1 INP0", "RX5", "SLIM RX5"}, \ 107 {"RX INT" #id "_1 MIX1 INP0", "RX6", "SLIM RX6"}, \ 108 {"RX INT" #id "_1 MIX1 INP0", "RX7", "SLIM RX7"}, \ 109 {"RX INT" #id "_1 MIX1 INP1", "RX0", "SLIM RX0"}, \ 110 {"RX INT" #id "_1 MIX1 INP1", "RX1", "SLIM RX1"}, \ 111 {"RX INT" #id "_1 MIX1 INP1", "RX2", "SLIM RX2"}, \ 112 {"RX INT" #id "_1 MIX1 INP1", "RX3", "SLIM RX3"}, \ 113 {"RX INT" #id "_1 MIX1 INP1", "RX4", "SLIM RX4"}, \ 114 {"RX INT" #id "_1 MIX1 INP1", "RX5", "SLIM RX5"}, \ 115 {"RX INT" #id "_1 MIX1 INP1", "RX6", "SLIM RX6"}, \ 116 {"RX INT" #id "_1 MIX1 INP1", "RX7", "SLIM RX7"}, \ 117 {"RX INT" #id "_1 MIX1 INP2", "RX0", "SLIM RX0"}, \ 118 {"RX INT" #id "_1 MIX1 INP2", "RX1", "SLIM RX1"}, \ 119 {"RX INT" #id "_1 MIX1 INP2", "RX2", "SLIM RX2"}, \ 120 {"RX INT" #id "_1 MIX1 INP2", "RX3", "SLIM RX3"}, \ 121 {"RX INT" #id "_1 MIX1 INP2", "RX4", "SLIM RX4"}, \ 122 {"RX INT" #id "_1 MIX1 INP2", "RX5", "SLIM RX5"}, \ 123 {"RX INT" #id "_1 MIX1 INP2", "RX6", "SLIM RX6"}, \ 124 {"RX INT" #id "_1 MIX1 INP2", "RX7", "SLIM RX7"}, \ 125 {"RX INT" #id "_2 MUX", "RX0", "SLIM RX0"}, \ 126 {"RX INT" #id "_2 MUX", "RX1", "SLIM RX1"}, \ 127 {"RX INT" #id "_2 MUX", "RX2", "SLIM RX2"}, \ 128 {"RX INT" #id "_2 MUX", "RX3", "SLIM RX3"}, \ 129 {"RX INT" #id "_2 MUX", "RX4", "SLIM RX4"}, \ 130 {"RX INT" #id "_2 MUX", "RX5", "SLIM RX5"}, \ 131 {"RX INT" #id "_2 MUX", "RX6", "SLIM RX6"}, \ 132 {"RX INT" #id "_2 MUX", "RX7", "SLIM RX7"}, \ 133 {"RX INT" #id "_1 MIX1", NULL, "RX INT" #id "_1 MIX1 INP0"}, \ 134 {"RX INT" #id "_1 MIX1", NULL, "RX INT" #id "_1 MIX1 INP1"}, \ 135 {"RX INT" #id "_1 MIX1", NULL, "RX INT" #id "_1 MIX1 INP2"}, \ 136 {"RX INT" #id " SEC MIX", NULL, "RX INT" #id "_2 MUX"}, \ 137 {"RX INT" #id " SEC MIX", NULL, "RX INT" #id "_1 MIX1"}, \ 138 {"RX INT" #id " MIX2", NULL, "RX INT" #id " SEC MIX"}, \ 139 {"RX INT" #id " INTERP", NULL, "RX INT" #id " MIX2"} 140 141 #define WCD9335_ADC_MUX_PATH(id) \ 142 {"AIF1_CAP Mixer", "SLIM TX" #id, "SLIM TX" #id " MUX"}, \ 143 {"AIF2_CAP Mixer", "SLIM TX" #id, "SLIM TX" #id " MUX"}, \ 144 {"AIF3_CAP Mixer", "SLIM TX" #id, "SLIM TX" #id " MUX"}, \ 145 {"SLIM TX" #id " MUX", "DEC" #id, "ADC MUX" #id}, \ 146 {"ADC MUX" #id, "DMIC", "DMIC MUX" #id}, \ 147 {"ADC MUX" #id, "AMIC", "AMIC MUX" #id}, \ 148 {"DMIC MUX" #id, "DMIC0", "DMIC0"}, \ 149 {"DMIC MUX" #id, "DMIC1", "DMIC1"}, \ 150 {"DMIC MUX" #id, "DMIC2", "DMIC2"}, \ 151 {"DMIC MUX" #id, "DMIC3", "DMIC3"}, \ 152 {"DMIC MUX" #id, "DMIC4", "DMIC4"}, \ 153 {"DMIC MUX" #id, "DMIC5", "DMIC5"}, \ 154 {"AMIC MUX" #id, "ADC1", "ADC1"}, \ 155 {"AMIC MUX" #id, "ADC2", "ADC2"}, \ 156 {"AMIC MUX" #id, "ADC3", "ADC3"}, \ 157 {"AMIC MUX" #id, "ADC4", "ADC4"}, \ 158 {"AMIC MUX" #id, "ADC5", "ADC5"}, \ 159 {"AMIC MUX" #id, "ADC6", "ADC6"} 160 161 enum { 162 WCD9335_RX0 = 0, 163 WCD9335_RX1, 164 WCD9335_RX2, 165 WCD9335_RX3, 166 WCD9335_RX4, 167 WCD9335_RX5, 168 WCD9335_RX6, 169 WCD9335_RX7, 170 WCD9335_RX8, 171 WCD9335_RX9, 172 WCD9335_RX10, 173 WCD9335_RX11, 174 WCD9335_RX12, 175 WCD9335_RX_MAX, 176 }; 177 178 enum { 179 WCD9335_TX0 = 0, 180 WCD9335_TX1, 181 WCD9335_TX2, 182 WCD9335_TX3, 183 WCD9335_TX4, 184 WCD9335_TX5, 185 WCD9335_TX6, 186 WCD9335_TX7, 187 WCD9335_TX8, 188 WCD9335_TX9, 189 WCD9335_TX10, 190 WCD9335_TX11, 191 WCD9335_TX12, 192 WCD9335_TX13, 193 WCD9335_TX14, 194 WCD9335_TX15, 195 WCD9335_TX_MAX, 196 }; 197 198 enum { 199 SIDO_SOURCE_INTERNAL = 0, 200 SIDO_SOURCE_RCO_BG, 201 }; 202 203 enum wcd9335_sido_voltage { 204 SIDO_VOLTAGE_SVS_MV = 950, 205 SIDO_VOLTAGE_NOMINAL_MV = 1100, 206 }; 207 208 enum { 209 COMPANDER_1, /* HPH_L */ 210 COMPANDER_2, /* HPH_R */ 211 COMPANDER_3, /* LO1_DIFF */ 212 COMPANDER_4, /* LO2_DIFF */ 213 COMPANDER_5, /* LO3_SE */ 214 COMPANDER_6, /* LO4_SE */ 215 COMPANDER_7, /* SWR SPK CH1 */ 216 COMPANDER_8, /* SWR SPK CH2 */ 217 COMPANDER_MAX, 218 }; 219 220 enum { 221 INTn_2_INP_SEL_ZERO = 0, 222 INTn_2_INP_SEL_RX0, 223 INTn_2_INP_SEL_RX1, 224 INTn_2_INP_SEL_RX2, 225 INTn_2_INP_SEL_RX3, 226 INTn_2_INP_SEL_RX4, 227 INTn_2_INP_SEL_RX5, 228 INTn_2_INP_SEL_RX6, 229 INTn_2_INP_SEL_RX7, 230 INTn_2_INP_SEL_PROXIMITY, 231 }; 232 233 enum { 234 INTn_1_MIX_INP_SEL_ZERO = 0, 235 INTn_1_MIX_INP_SEL_DEC0, 236 INTn_1_MIX_INP_SEL_DEC1, 237 INTn_1_MIX_INP_SEL_IIR0, 238 INTn_1_MIX_INP_SEL_IIR1, 239 INTn_1_MIX_INP_SEL_RX0, 240 INTn_1_MIX_INP_SEL_RX1, 241 INTn_1_MIX_INP_SEL_RX2, 242 INTn_1_MIX_INP_SEL_RX3, 243 INTn_1_MIX_INP_SEL_RX4, 244 INTn_1_MIX_INP_SEL_RX5, 245 INTn_1_MIX_INP_SEL_RX6, 246 INTn_1_MIX_INP_SEL_RX7, 247 248 }; 249 250 enum { 251 INTERP_EAR = 0, 252 INTERP_HPHL, 253 INTERP_HPHR, 254 INTERP_LO1, 255 INTERP_LO2, 256 INTERP_LO3, 257 INTERP_LO4, 258 INTERP_SPKR1, 259 INTERP_SPKR2, 260 }; 261 262 enum wcd_clock_type { 263 WCD_CLK_OFF, 264 WCD_CLK_RCO, 265 WCD_CLK_MCLK, 266 }; 267 268 enum { 269 MIC_BIAS_1 = 1, 270 MIC_BIAS_2, 271 MIC_BIAS_3, 272 MIC_BIAS_4 273 }; 274 275 enum { 276 MICB_PULLUP_ENABLE, 277 MICB_PULLUP_DISABLE, 278 MICB_ENABLE, 279 MICB_DISABLE, 280 }; 281 282 struct wcd9335_slim_ch { 283 u32 ch_num; 284 u16 port; 285 u16 shift; 286 struct list_head list; 287 }; 288 289 struct wcd_slim_codec_dai_data { 290 struct list_head slim_ch_list; 291 struct slim_stream_config sconfig; 292 struct slim_stream_runtime *sruntime; 293 }; 294 295 struct wcd9335_codec { 296 struct device *dev; 297 struct clk *mclk; 298 struct clk *native_clk; 299 u32 mclk_rate; 300 u8 version; 301 302 struct slim_device *slim; 303 struct slim_device *slim_ifc_dev; 304 struct regmap *regmap; 305 struct regmap *if_regmap; 306 struct regmap_irq_chip_data *irq_data; 307 308 struct wcd9335_slim_ch rx_chs[WCD9335_RX_MAX]; 309 struct wcd9335_slim_ch tx_chs[WCD9335_TX_MAX]; 310 u32 num_rx_port; 311 u32 num_tx_port; 312 313 int sido_input_src; 314 enum wcd9335_sido_voltage sido_voltage; 315 316 struct wcd_slim_codec_dai_data dai[NUM_CODEC_DAIS]; 317 struct snd_soc_component *component; 318 319 int master_bias_users; 320 int clk_mclk_users; 321 int clk_rco_users; 322 int sido_ccl_cnt; 323 enum wcd_clock_type clk_type; 324 325 struct wcd_clsh_ctrl *clsh_ctrl; 326 u32 hph_mode; 327 int prim_int_users[WCD9335_NUM_INTERPOLATORS]; 328 329 int comp_enabled[COMPANDER_MAX]; 330 331 int intr1; 332 int reset_gpio; 333 struct regulator_bulk_data supplies[WCD9335_MAX_SUPPLY]; 334 335 unsigned int rx_port_value[WCD9335_RX_MAX]; 336 unsigned int tx_port_value[WCD9335_TX_MAX]; 337 int hph_l_gain; 338 int hph_r_gain; 339 u32 rx_bias_count; 340 341 /*TX*/ 342 int micb_ref[WCD9335_MAX_MICBIAS]; 343 int pullup_ref[WCD9335_MAX_MICBIAS]; 344 345 int dmic_0_1_clk_cnt; 346 int dmic_2_3_clk_cnt; 347 int dmic_4_5_clk_cnt; 348 int dmic_sample_rate; 349 int mad_dmic_sample_rate; 350 351 int native_clk_users; 352 }; 353 354 struct wcd9335_irq { 355 int irq; 356 irqreturn_t (*handler)(int irq, void *data); 357 char *name; 358 }; 359 360 static const struct wcd9335_slim_ch wcd9335_tx_chs[WCD9335_TX_MAX] = { 361 WCD9335_SLIM_TX_CH(0), 362 WCD9335_SLIM_TX_CH(1), 363 WCD9335_SLIM_TX_CH(2), 364 WCD9335_SLIM_TX_CH(3), 365 WCD9335_SLIM_TX_CH(4), 366 WCD9335_SLIM_TX_CH(5), 367 WCD9335_SLIM_TX_CH(6), 368 WCD9335_SLIM_TX_CH(7), 369 WCD9335_SLIM_TX_CH(8), 370 WCD9335_SLIM_TX_CH(9), 371 WCD9335_SLIM_TX_CH(10), 372 WCD9335_SLIM_TX_CH(11), 373 WCD9335_SLIM_TX_CH(12), 374 WCD9335_SLIM_TX_CH(13), 375 WCD9335_SLIM_TX_CH(14), 376 WCD9335_SLIM_TX_CH(15), 377 }; 378 379 static const struct wcd9335_slim_ch wcd9335_rx_chs[WCD9335_RX_MAX] = { 380 WCD9335_SLIM_RX_CH(0), /* 16 */ 381 WCD9335_SLIM_RX_CH(1), /* 17 */ 382 WCD9335_SLIM_RX_CH(2), 383 WCD9335_SLIM_RX_CH(3), 384 WCD9335_SLIM_RX_CH(4), 385 WCD9335_SLIM_RX_CH(5), 386 WCD9335_SLIM_RX_CH(6), 387 WCD9335_SLIM_RX_CH(7), 388 WCD9335_SLIM_RX_CH(8), 389 WCD9335_SLIM_RX_CH(9), 390 WCD9335_SLIM_RX_CH(10), 391 WCD9335_SLIM_RX_CH(11), 392 WCD9335_SLIM_RX_CH(12), 393 }; 394 395 struct interp_sample_rate { 396 int rate; 397 int rate_val; 398 }; 399 400 static struct interp_sample_rate int_mix_rate_val[] = { 401 {48000, 0x4}, /* 48K */ 402 {96000, 0x5}, /* 96K */ 403 {192000, 0x6}, /* 192K */ 404 }; 405 406 static struct interp_sample_rate int_prim_rate_val[] = { 407 {8000, 0x0}, /* 8K */ 408 {16000, 0x1}, /* 16K */ 409 {24000, -EINVAL},/* 24K */ 410 {32000, 0x3}, /* 32K */ 411 {48000, 0x4}, /* 48K */ 412 {96000, 0x5}, /* 96K */ 413 {192000, 0x6}, /* 192K */ 414 {384000, 0x7}, /* 384K */ 415 {44100, 0x8}, /* 44.1K */ 416 }; 417 418 struct wcd9335_reg_mask_val { 419 u16 reg; 420 u8 mask; 421 u8 val; 422 }; 423 424 static const struct wcd9335_reg_mask_val wcd9335_codec_reg_init[] = { 425 /* Rbuckfly/R_EAR(32) */ 426 {WCD9335_CDC_CLSH_K2_MSB, 0x0F, 0x00}, 427 {WCD9335_CDC_CLSH_K2_LSB, 0xFF, 0x60}, 428 {WCD9335_CPE_SS_DMIC_CFG, 0x80, 0x00}, 429 {WCD9335_CDC_BOOST0_BOOST_CTL, 0x70, 0x50}, 430 {WCD9335_CDC_BOOST1_BOOST_CTL, 0x70, 0x50}, 431 {WCD9335_CDC_RX7_RX_PATH_CFG1, 0x08, 0x08}, 432 {WCD9335_CDC_RX8_RX_PATH_CFG1, 0x08, 0x08}, 433 {WCD9335_ANA_LO_1_2, 0x3C, 0X3C}, 434 {WCD9335_DIFF_LO_COM_SWCAP_REFBUF_FREQ, 0x70, 0x00}, 435 {WCD9335_DIFF_LO_COM_PA_FREQ, 0x70, 0x40}, 436 {WCD9335_SOC_MAD_AUDIO_CTL_2, 0x03, 0x03}, 437 {WCD9335_CDC_TOP_TOP_CFG1, 0x02, 0x02}, 438 {WCD9335_CDC_TOP_TOP_CFG1, 0x01, 0x01}, 439 {WCD9335_EAR_CMBUFF, 0x08, 0x00}, 440 {WCD9335_CDC_TX9_SPKR_PROT_PATH_CFG0, 0x01, 0x01}, 441 {WCD9335_CDC_TX10_SPKR_PROT_PATH_CFG0, 0x01, 0x01}, 442 {WCD9335_CDC_TX11_SPKR_PROT_PATH_CFG0, 0x01, 0x01}, 443 {WCD9335_CDC_TX12_SPKR_PROT_PATH_CFG0, 0x01, 0x01}, 444 {WCD9335_CDC_COMPANDER7_CTL3, 0x80, 0x80}, 445 {WCD9335_CDC_COMPANDER8_CTL3, 0x80, 0x80}, 446 {WCD9335_CDC_COMPANDER7_CTL7, 0x01, 0x01}, 447 {WCD9335_CDC_COMPANDER8_CTL7, 0x01, 0x01}, 448 {WCD9335_CDC_RX0_RX_PATH_CFG0, 0x01, 0x01}, 449 {WCD9335_CDC_RX1_RX_PATH_CFG0, 0x01, 0x01}, 450 {WCD9335_CDC_RX2_RX_PATH_CFG0, 0x01, 0x01}, 451 {WCD9335_CDC_RX3_RX_PATH_CFG0, 0x01, 0x01}, 452 {WCD9335_CDC_RX4_RX_PATH_CFG0, 0x01, 0x01}, 453 {WCD9335_CDC_RX5_RX_PATH_CFG0, 0x01, 0x01}, 454 {WCD9335_CDC_RX6_RX_PATH_CFG0, 0x01, 0x01}, 455 {WCD9335_CDC_RX7_RX_PATH_CFG0, 0x01, 0x01}, 456 {WCD9335_CDC_RX8_RX_PATH_CFG0, 0x01, 0x01}, 457 {WCD9335_CDC_RX0_RX_PATH_MIX_CFG, 0x01, 0x01}, 458 {WCD9335_CDC_RX1_RX_PATH_MIX_CFG, 0x01, 0x01}, 459 {WCD9335_CDC_RX2_RX_PATH_MIX_CFG, 0x01, 0x01}, 460 {WCD9335_CDC_RX3_RX_PATH_MIX_CFG, 0x01, 0x01}, 461 {WCD9335_CDC_RX4_RX_PATH_MIX_CFG, 0x01, 0x01}, 462 {WCD9335_CDC_RX5_RX_PATH_MIX_CFG, 0x01, 0x01}, 463 {WCD9335_CDC_RX6_RX_PATH_MIX_CFG, 0x01, 0x01}, 464 {WCD9335_CDC_RX7_RX_PATH_MIX_CFG, 0x01, 0x01}, 465 {WCD9335_CDC_RX8_RX_PATH_MIX_CFG, 0x01, 0x01}, 466 {WCD9335_VBADC_IBIAS_FE, 0x0C, 0x08}, 467 {WCD9335_RCO_CTRL_2, 0x0F, 0x08}, 468 {WCD9335_RX_BIAS_FLYB_MID_RST, 0xF0, 0x10}, 469 {WCD9335_FLYBACK_CTRL_1, 0x20, 0x20}, 470 {WCD9335_HPH_OCP_CTL, 0xFF, 0x5A}, 471 {WCD9335_HPH_L_TEST, 0x01, 0x01}, 472 {WCD9335_HPH_R_TEST, 0x01, 0x01}, 473 {WCD9335_CDC_BOOST0_BOOST_CFG1, 0x3F, 0x12}, 474 {WCD9335_CDC_BOOST0_BOOST_CFG2, 0x1C, 0x08}, 475 {WCD9335_CDC_COMPANDER7_CTL7, 0x1E, 0x18}, 476 {WCD9335_CDC_BOOST1_BOOST_CFG1, 0x3F, 0x12}, 477 {WCD9335_CDC_BOOST1_BOOST_CFG2, 0x1C, 0x08}, 478 {WCD9335_CDC_COMPANDER8_CTL7, 0x1E, 0x18}, 479 {WCD9335_CDC_TX0_TX_PATH_SEC7, 0xFF, 0x45}, 480 {WCD9335_CDC_RX0_RX_PATH_SEC0, 0xFC, 0xF4}, 481 {WCD9335_HPH_REFBUFF_LP_CTL, 0x08, 0x08}, 482 {WCD9335_HPH_REFBUFF_LP_CTL, 0x06, 0x02}, 483 }; 484 485 /* Cutoff frequency for high pass filter */ 486 static const char * const cf_text[] = { 487 "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ" 488 }; 489 490 static const char * const rx_cf_text[] = { 491 "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ", 492 "CF_NEG_3DB_0P48HZ" 493 }; 494 495 static const char * const rx_int0_7_mix_mux_text[] = { 496 "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5", 497 "RX6", "RX7", "PROXIMITY" 498 }; 499 500 static const char * const rx_int_mix_mux_text[] = { 501 "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5", 502 "RX6", "RX7" 503 }; 504 505 static const char * const rx_prim_mix_text[] = { 506 "ZERO", "DEC0", "DEC1", "IIR0", "IIR1", "RX0", "RX1", "RX2", 507 "RX3", "RX4", "RX5", "RX6", "RX7" 508 }; 509 510 static const char * const rx_int_dem_inp_mux_text[] = { 511 "NORMAL_DSM_OUT", "CLSH_DSM_OUT", 512 }; 513 514 static const char * const rx_int0_interp_mux_text[] = { 515 "ZERO", "RX INT0 MIX2", 516 }; 517 518 static const char * const rx_int1_interp_mux_text[] = { 519 "ZERO", "RX INT1 MIX2", 520 }; 521 522 static const char * const rx_int2_interp_mux_text[] = { 523 "ZERO", "RX INT2 MIX2", 524 }; 525 526 static const char * const rx_int3_interp_mux_text[] = { 527 "ZERO", "RX INT3 MIX2", 528 }; 529 530 static const char * const rx_int4_interp_mux_text[] = { 531 "ZERO", "RX INT4 MIX2", 532 }; 533 534 static const char * const rx_int5_interp_mux_text[] = { 535 "ZERO", "RX INT5 MIX2", 536 }; 537 538 static const char * const rx_int6_interp_mux_text[] = { 539 "ZERO", "RX INT6 MIX2", 540 }; 541 542 static const char * const rx_int7_interp_mux_text[] = { 543 "ZERO", "RX INT7 MIX2", 544 }; 545 546 static const char * const rx_int8_interp_mux_text[] = { 547 "ZERO", "RX INT8 SEC MIX" 548 }; 549 550 static const char * const rx_hph_mode_mux_text[] = { 551 "Class H Invalid", "Class-H Hi-Fi", "Class-H Low Power", "Class-AB", 552 "Class-H Hi-Fi Low Power" 553 }; 554 555 static const char *const slim_rx_mux_text[] = { 556 "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB", "AIF4_PB", 557 }; 558 559 static const char * const adc_mux_text[] = { 560 "DMIC", "AMIC", "ANC_FB_TUNE1", "ANC_FB_TUNE2" 561 }; 562 563 static const char * const dmic_mux_text[] = { 564 "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", 565 "SMIC0", "SMIC1", "SMIC2", "SMIC3" 566 }; 567 568 static const char * const dmic_mux_alt_text[] = { 569 "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", 570 }; 571 572 static const char * const amic_mux_text[] = { 573 "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6" 574 }; 575 576 static const char * const sb_tx0_mux_text[] = { 577 "ZERO", "RX_MIX_TX0", "DEC0", "DEC0_192" 578 }; 579 580 static const char * const sb_tx1_mux_text[] = { 581 "ZERO", "RX_MIX_TX1", "DEC1", "DEC1_192" 582 }; 583 584 static const char * const sb_tx2_mux_text[] = { 585 "ZERO", "RX_MIX_TX2", "DEC2", "DEC2_192" 586 }; 587 588 static const char * const sb_tx3_mux_text[] = { 589 "ZERO", "RX_MIX_TX3", "DEC3", "DEC3_192" 590 }; 591 592 static const char * const sb_tx4_mux_text[] = { 593 "ZERO", "RX_MIX_TX4", "DEC4", "DEC4_192" 594 }; 595 596 static const char * const sb_tx5_mux_text[] = { 597 "ZERO", "RX_MIX_TX5", "DEC5", "DEC5_192" 598 }; 599 600 static const char * const sb_tx6_mux_text[] = { 601 "ZERO", "RX_MIX_TX6", "DEC6", "DEC6_192" 602 }; 603 604 static const char * const sb_tx7_mux_text[] = { 605 "ZERO", "RX_MIX_TX7", "DEC7", "DEC7_192" 606 }; 607 608 static const char * const sb_tx8_mux_text[] = { 609 "ZERO", "RX_MIX_TX8", "DEC8", "DEC8_192" 610 }; 611 612 static const DECLARE_TLV_DB_SCALE(digital_gain, -8400, 100, -8400); 613 static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1); 614 static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1); 615 static const DECLARE_TLV_DB_SCALE(ear_pa_gain, 0, 150, 0); 616 617 static const struct soc_enum cf_dec0_enum = 618 SOC_ENUM_SINGLE(WCD9335_CDC_TX0_TX_PATH_CFG0, 5, 3, cf_text); 619 620 static const struct soc_enum cf_dec1_enum = 621 SOC_ENUM_SINGLE(WCD9335_CDC_TX1_TX_PATH_CFG0, 5, 3, cf_text); 622 623 static const struct soc_enum cf_dec2_enum = 624 SOC_ENUM_SINGLE(WCD9335_CDC_TX2_TX_PATH_CFG0, 5, 3, cf_text); 625 626 static const struct soc_enum cf_dec3_enum = 627 SOC_ENUM_SINGLE(WCD9335_CDC_TX3_TX_PATH_CFG0, 5, 3, cf_text); 628 629 static const struct soc_enum cf_dec4_enum = 630 SOC_ENUM_SINGLE(WCD9335_CDC_TX4_TX_PATH_CFG0, 5, 3, cf_text); 631 632 static const struct soc_enum cf_dec5_enum = 633 SOC_ENUM_SINGLE(WCD9335_CDC_TX5_TX_PATH_CFG0, 5, 3, cf_text); 634 635 static const struct soc_enum cf_dec6_enum = 636 SOC_ENUM_SINGLE(WCD9335_CDC_TX6_TX_PATH_CFG0, 5, 3, cf_text); 637 638 static const struct soc_enum cf_dec7_enum = 639 SOC_ENUM_SINGLE(WCD9335_CDC_TX7_TX_PATH_CFG0, 5, 3, cf_text); 640 641 static const struct soc_enum cf_dec8_enum = 642 SOC_ENUM_SINGLE(WCD9335_CDC_TX8_TX_PATH_CFG0, 5, 3, cf_text); 643 644 static const struct soc_enum cf_int0_1_enum = 645 SOC_ENUM_SINGLE(WCD9335_CDC_RX0_RX_PATH_CFG2, 0, 4, rx_cf_text); 646 647 static SOC_ENUM_SINGLE_DECL(cf_int0_2_enum, WCD9335_CDC_RX0_RX_PATH_MIX_CFG, 2, 648 rx_cf_text); 649 650 static const struct soc_enum cf_int1_1_enum = 651 SOC_ENUM_SINGLE(WCD9335_CDC_RX1_RX_PATH_CFG2, 0, 4, rx_cf_text); 652 653 static SOC_ENUM_SINGLE_DECL(cf_int1_2_enum, WCD9335_CDC_RX1_RX_PATH_MIX_CFG, 2, 654 rx_cf_text); 655 656 static const struct soc_enum cf_int2_1_enum = 657 SOC_ENUM_SINGLE(WCD9335_CDC_RX2_RX_PATH_CFG2, 0, 4, rx_cf_text); 658 659 static SOC_ENUM_SINGLE_DECL(cf_int2_2_enum, WCD9335_CDC_RX2_RX_PATH_MIX_CFG, 2, 660 rx_cf_text); 661 662 static const struct soc_enum cf_int3_1_enum = 663 SOC_ENUM_SINGLE(WCD9335_CDC_RX3_RX_PATH_CFG2, 0, 4, rx_cf_text); 664 665 static SOC_ENUM_SINGLE_DECL(cf_int3_2_enum, WCD9335_CDC_RX3_RX_PATH_MIX_CFG, 2, 666 rx_cf_text); 667 668 static const struct soc_enum cf_int4_1_enum = 669 SOC_ENUM_SINGLE(WCD9335_CDC_RX4_RX_PATH_CFG2, 0, 4, rx_cf_text); 670 671 static SOC_ENUM_SINGLE_DECL(cf_int4_2_enum, WCD9335_CDC_RX4_RX_PATH_MIX_CFG, 2, 672 rx_cf_text); 673 674 static const struct soc_enum cf_int5_1_enum = 675 SOC_ENUM_SINGLE(WCD9335_CDC_RX5_RX_PATH_CFG2, 0, 4, rx_cf_text); 676 677 static SOC_ENUM_SINGLE_DECL(cf_int5_2_enum, WCD9335_CDC_RX5_RX_PATH_MIX_CFG, 2, 678 rx_cf_text); 679 680 static const struct soc_enum cf_int6_1_enum = 681 SOC_ENUM_SINGLE(WCD9335_CDC_RX6_RX_PATH_CFG2, 0, 4, rx_cf_text); 682 683 static SOC_ENUM_SINGLE_DECL(cf_int6_2_enum, WCD9335_CDC_RX6_RX_PATH_MIX_CFG, 2, 684 rx_cf_text); 685 686 static const struct soc_enum cf_int7_1_enum = 687 SOC_ENUM_SINGLE(WCD9335_CDC_RX7_RX_PATH_CFG2, 0, 4, rx_cf_text); 688 689 static SOC_ENUM_SINGLE_DECL(cf_int7_2_enum, WCD9335_CDC_RX7_RX_PATH_MIX_CFG, 2, 690 rx_cf_text); 691 692 static const struct soc_enum cf_int8_1_enum = 693 SOC_ENUM_SINGLE(WCD9335_CDC_RX8_RX_PATH_CFG2, 0, 4, rx_cf_text); 694 695 static SOC_ENUM_SINGLE_DECL(cf_int8_2_enum, WCD9335_CDC_RX8_RX_PATH_MIX_CFG, 2, 696 rx_cf_text); 697 698 static const struct soc_enum rx_hph_mode_mux_enum = 699 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text), 700 rx_hph_mode_mux_text); 701 702 static const struct soc_enum slim_rx_mux_enum = 703 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text), slim_rx_mux_text); 704 705 static const struct soc_enum rx_int0_2_mux_chain_enum = 706 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT0_CFG1, 0, 10, 707 rx_int0_7_mix_mux_text); 708 709 static const struct soc_enum rx_int1_2_mux_chain_enum = 710 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT1_CFG1, 0, 9, 711 rx_int_mix_mux_text); 712 713 static const struct soc_enum rx_int2_2_mux_chain_enum = 714 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT2_CFG1, 0, 9, 715 rx_int_mix_mux_text); 716 717 static const struct soc_enum rx_int3_2_mux_chain_enum = 718 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT3_CFG1, 0, 9, 719 rx_int_mix_mux_text); 720 721 static const struct soc_enum rx_int4_2_mux_chain_enum = 722 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT4_CFG1, 0, 9, 723 rx_int_mix_mux_text); 724 725 static const struct soc_enum rx_int5_2_mux_chain_enum = 726 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT5_CFG1, 0, 9, 727 rx_int_mix_mux_text); 728 729 static const struct soc_enum rx_int6_2_mux_chain_enum = 730 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT6_CFG1, 0, 9, 731 rx_int_mix_mux_text); 732 733 static const struct soc_enum rx_int7_2_mux_chain_enum = 734 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT7_CFG1, 0, 10, 735 rx_int0_7_mix_mux_text); 736 737 static const struct soc_enum rx_int8_2_mux_chain_enum = 738 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT8_CFG1, 0, 9, 739 rx_int_mix_mux_text); 740 741 static const struct soc_enum rx_int0_1_mix_inp0_chain_enum = 742 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT0_CFG0, 0, 13, 743 rx_prim_mix_text); 744 745 static const struct soc_enum rx_int0_1_mix_inp1_chain_enum = 746 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT0_CFG0, 4, 13, 747 rx_prim_mix_text); 748 749 static const struct soc_enum rx_int0_1_mix_inp2_chain_enum = 750 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT0_CFG1, 4, 13, 751 rx_prim_mix_text); 752 753 static const struct soc_enum rx_int1_1_mix_inp0_chain_enum = 754 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT1_CFG0, 0, 13, 755 rx_prim_mix_text); 756 757 static const struct soc_enum rx_int1_1_mix_inp1_chain_enum = 758 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT1_CFG0, 4, 13, 759 rx_prim_mix_text); 760 761 static const struct soc_enum rx_int1_1_mix_inp2_chain_enum = 762 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT1_CFG1, 4, 13, 763 rx_prim_mix_text); 764 765 static const struct soc_enum rx_int2_1_mix_inp0_chain_enum = 766 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT2_CFG0, 0, 13, 767 rx_prim_mix_text); 768 769 static const struct soc_enum rx_int2_1_mix_inp1_chain_enum = 770 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT2_CFG0, 4, 13, 771 rx_prim_mix_text); 772 773 static const struct soc_enum rx_int2_1_mix_inp2_chain_enum = 774 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT2_CFG1, 4, 13, 775 rx_prim_mix_text); 776 777 static const struct soc_enum rx_int3_1_mix_inp0_chain_enum = 778 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT3_CFG0, 0, 13, 779 rx_prim_mix_text); 780 781 static const struct soc_enum rx_int3_1_mix_inp1_chain_enum = 782 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT3_CFG0, 4, 13, 783 rx_prim_mix_text); 784 785 static const struct soc_enum rx_int3_1_mix_inp2_chain_enum = 786 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT3_CFG1, 4, 13, 787 rx_prim_mix_text); 788 789 static const struct soc_enum rx_int4_1_mix_inp0_chain_enum = 790 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT4_CFG0, 0, 13, 791 rx_prim_mix_text); 792 793 static const struct soc_enum rx_int4_1_mix_inp1_chain_enum = 794 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT4_CFG0, 4, 13, 795 rx_prim_mix_text); 796 797 static const struct soc_enum rx_int4_1_mix_inp2_chain_enum = 798 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT4_CFG1, 4, 13, 799 rx_prim_mix_text); 800 801 static const struct soc_enum rx_int5_1_mix_inp0_chain_enum = 802 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT5_CFG0, 0, 13, 803 rx_prim_mix_text); 804 805 static const struct soc_enum rx_int5_1_mix_inp1_chain_enum = 806 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT5_CFG0, 4, 13, 807 rx_prim_mix_text); 808 809 static const struct soc_enum rx_int5_1_mix_inp2_chain_enum = 810 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT5_CFG1, 4, 13, 811 rx_prim_mix_text); 812 813 static const struct soc_enum rx_int6_1_mix_inp0_chain_enum = 814 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT6_CFG0, 0, 13, 815 rx_prim_mix_text); 816 817 static const struct soc_enum rx_int6_1_mix_inp1_chain_enum = 818 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT6_CFG0, 4, 13, 819 rx_prim_mix_text); 820 821 static const struct soc_enum rx_int6_1_mix_inp2_chain_enum = 822 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT6_CFG1, 4, 13, 823 rx_prim_mix_text); 824 825 static const struct soc_enum rx_int7_1_mix_inp0_chain_enum = 826 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT7_CFG0, 0, 13, 827 rx_prim_mix_text); 828 829 static const struct soc_enum rx_int7_1_mix_inp1_chain_enum = 830 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT7_CFG0, 4, 13, 831 rx_prim_mix_text); 832 833 static const struct soc_enum rx_int7_1_mix_inp2_chain_enum = 834 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT7_CFG1, 4, 13, 835 rx_prim_mix_text); 836 837 static const struct soc_enum rx_int8_1_mix_inp0_chain_enum = 838 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT8_CFG0, 0, 13, 839 rx_prim_mix_text); 840 841 static const struct soc_enum rx_int8_1_mix_inp1_chain_enum = 842 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT8_CFG0, 4, 13, 843 rx_prim_mix_text); 844 845 static const struct soc_enum rx_int8_1_mix_inp2_chain_enum = 846 SOC_ENUM_SINGLE(WCD9335_CDC_RX_INP_MUX_RX_INT8_CFG1, 4, 13, 847 rx_prim_mix_text); 848 849 static const struct soc_enum rx_int0_dem_inp_mux_enum = 850 SOC_ENUM_SINGLE(WCD9335_CDC_RX0_RX_PATH_SEC0, 0, 851 ARRAY_SIZE(rx_int_dem_inp_mux_text), 852 rx_int_dem_inp_mux_text); 853 854 static const struct soc_enum rx_int1_dem_inp_mux_enum = 855 SOC_ENUM_SINGLE(WCD9335_CDC_RX1_RX_PATH_SEC0, 0, 856 ARRAY_SIZE(rx_int_dem_inp_mux_text), 857 rx_int_dem_inp_mux_text); 858 859 static const struct soc_enum rx_int2_dem_inp_mux_enum = 860 SOC_ENUM_SINGLE(WCD9335_CDC_RX2_RX_PATH_SEC0, 0, 861 ARRAY_SIZE(rx_int_dem_inp_mux_text), 862 rx_int_dem_inp_mux_text); 863 864 static const struct soc_enum rx_int0_interp_mux_enum = 865 SOC_ENUM_SINGLE(WCD9335_CDC_RX0_RX_PATH_CTL, 5, 2, 866 rx_int0_interp_mux_text); 867 868 static const struct soc_enum rx_int1_interp_mux_enum = 869 SOC_ENUM_SINGLE(WCD9335_CDC_RX1_RX_PATH_CTL, 5, 2, 870 rx_int1_interp_mux_text); 871 872 static const struct soc_enum rx_int2_interp_mux_enum = 873 SOC_ENUM_SINGLE(WCD9335_CDC_RX2_RX_PATH_CTL, 5, 2, 874 rx_int2_interp_mux_text); 875 876 static const struct soc_enum rx_int3_interp_mux_enum = 877 SOC_ENUM_SINGLE(WCD9335_CDC_RX3_RX_PATH_CTL, 5, 2, 878 rx_int3_interp_mux_text); 879 880 static const struct soc_enum rx_int4_interp_mux_enum = 881 SOC_ENUM_SINGLE(WCD9335_CDC_RX4_RX_PATH_CTL, 5, 2, 882 rx_int4_interp_mux_text); 883 884 static const struct soc_enum rx_int5_interp_mux_enum = 885 SOC_ENUM_SINGLE(WCD9335_CDC_RX5_RX_PATH_CTL, 5, 2, 886 rx_int5_interp_mux_text); 887 888 static const struct soc_enum rx_int6_interp_mux_enum = 889 SOC_ENUM_SINGLE(WCD9335_CDC_RX6_RX_PATH_CTL, 5, 2, 890 rx_int6_interp_mux_text); 891 892 static const struct soc_enum rx_int7_interp_mux_enum = 893 SOC_ENUM_SINGLE(WCD9335_CDC_RX7_RX_PATH_CTL, 5, 2, 894 rx_int7_interp_mux_text); 895 896 static const struct soc_enum rx_int8_interp_mux_enum = 897 SOC_ENUM_SINGLE(WCD9335_CDC_RX8_RX_PATH_CTL, 5, 2, 898 rx_int8_interp_mux_text); 899 900 static const struct soc_enum tx_adc_mux0_chain_enum = 901 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 0, 4, 902 adc_mux_text); 903 904 static const struct soc_enum tx_adc_mux1_chain_enum = 905 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 0, 4, 906 adc_mux_text); 907 908 static const struct soc_enum tx_adc_mux2_chain_enum = 909 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 0, 4, 910 adc_mux_text); 911 912 static const struct soc_enum tx_adc_mux3_chain_enum = 913 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX3_CFG1, 0, 4, 914 adc_mux_text); 915 916 static const struct soc_enum tx_adc_mux4_chain_enum = 917 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX4_CFG0, 6, 4, 918 adc_mux_text); 919 920 static const struct soc_enum tx_adc_mux5_chain_enum = 921 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX5_CFG0, 6, 4, 922 adc_mux_text); 923 924 static const struct soc_enum tx_adc_mux6_chain_enum = 925 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX6_CFG0, 6, 4, 926 adc_mux_text); 927 928 static const struct soc_enum tx_adc_mux7_chain_enum = 929 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX7_CFG0, 6, 4, 930 adc_mux_text); 931 932 static const struct soc_enum tx_adc_mux8_chain_enum = 933 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX8_CFG0, 6, 4, 934 adc_mux_text); 935 936 static const struct soc_enum tx_dmic_mux0_enum = 937 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX0_CFG0, 3, 11, 938 dmic_mux_text); 939 940 static const struct soc_enum tx_dmic_mux1_enum = 941 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX1_CFG0, 3, 11, 942 dmic_mux_text); 943 944 static const struct soc_enum tx_dmic_mux2_enum = 945 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX2_CFG0, 3, 11, 946 dmic_mux_text); 947 948 static const struct soc_enum tx_dmic_mux3_enum = 949 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX3_CFG0, 3, 11, 950 dmic_mux_text); 951 952 static const struct soc_enum tx_dmic_mux4_enum = 953 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX4_CFG0, 3, 7, 954 dmic_mux_alt_text); 955 956 static const struct soc_enum tx_dmic_mux5_enum = 957 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX5_CFG0, 3, 7, 958 dmic_mux_alt_text); 959 960 static const struct soc_enum tx_dmic_mux6_enum = 961 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX6_CFG0, 3, 7, 962 dmic_mux_alt_text); 963 964 static const struct soc_enum tx_dmic_mux7_enum = 965 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX7_CFG0, 3, 7, 966 dmic_mux_alt_text); 967 968 static const struct soc_enum tx_dmic_mux8_enum = 969 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX8_CFG0, 3, 7, 970 dmic_mux_alt_text); 971 972 static const struct soc_enum tx_amic_mux0_enum = 973 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX0_CFG0, 0, 7, 974 amic_mux_text); 975 976 static const struct soc_enum tx_amic_mux1_enum = 977 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX1_CFG0, 0, 7, 978 amic_mux_text); 979 980 static const struct soc_enum tx_amic_mux2_enum = 981 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX2_CFG0, 0, 7, 982 amic_mux_text); 983 984 static const struct soc_enum tx_amic_mux3_enum = 985 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX3_CFG0, 0, 7, 986 amic_mux_text); 987 988 static const struct soc_enum tx_amic_mux4_enum = 989 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX4_CFG0, 0, 7, 990 amic_mux_text); 991 992 static const struct soc_enum tx_amic_mux5_enum = 993 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX5_CFG0, 0, 7, 994 amic_mux_text); 995 996 static const struct soc_enum tx_amic_mux6_enum = 997 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX6_CFG0, 0, 7, 998 amic_mux_text); 999 1000 static const struct soc_enum tx_amic_mux7_enum = 1001 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX7_CFG0, 0, 7, 1002 amic_mux_text); 1003 1004 static const struct soc_enum tx_amic_mux8_enum = 1005 SOC_ENUM_SINGLE(WCD9335_CDC_TX_INP_MUX_ADC_MUX8_CFG0, 0, 7, 1006 amic_mux_text); 1007 1008 static const struct soc_enum sb_tx0_mux_enum = 1009 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG0, 0, 4, 1010 sb_tx0_mux_text); 1011 1012 static const struct soc_enum sb_tx1_mux_enum = 1013 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG0, 2, 4, 1014 sb_tx1_mux_text); 1015 1016 static const struct soc_enum sb_tx2_mux_enum = 1017 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG0, 4, 4, 1018 sb_tx2_mux_text); 1019 1020 static const struct soc_enum sb_tx3_mux_enum = 1021 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG0, 6, 4, 1022 sb_tx3_mux_text); 1023 1024 static const struct soc_enum sb_tx4_mux_enum = 1025 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG1, 0, 4, 1026 sb_tx4_mux_text); 1027 1028 static const struct soc_enum sb_tx5_mux_enum = 1029 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG1, 2, 4, 1030 sb_tx5_mux_text); 1031 1032 static const struct soc_enum sb_tx6_mux_enum = 1033 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG1, 4, 4, 1034 sb_tx6_mux_text); 1035 1036 static const struct soc_enum sb_tx7_mux_enum = 1037 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG1, 6, 4, 1038 sb_tx7_mux_text); 1039 1040 static const struct soc_enum sb_tx8_mux_enum = 1041 SOC_ENUM_SINGLE(WCD9335_CDC_IF_ROUTER_TX_MUX_CFG2, 0, 4, 1042 sb_tx8_mux_text); 1043 1044 static const struct snd_kcontrol_new rx_int0_2_mux = 1045 SOC_DAPM_ENUM("RX INT0_2 MUX Mux", rx_int0_2_mux_chain_enum); 1046 1047 static const struct snd_kcontrol_new rx_int1_2_mux = 1048 SOC_DAPM_ENUM("RX INT1_2 MUX Mux", rx_int1_2_mux_chain_enum); 1049 1050 static const struct snd_kcontrol_new rx_int2_2_mux = 1051 SOC_DAPM_ENUM("RX INT2_2 MUX Mux", rx_int2_2_mux_chain_enum); 1052 1053 static const struct snd_kcontrol_new rx_int3_2_mux = 1054 SOC_DAPM_ENUM("RX INT3_2 MUX Mux", rx_int3_2_mux_chain_enum); 1055 1056 static const struct snd_kcontrol_new rx_int4_2_mux = 1057 SOC_DAPM_ENUM("RX INT4_2 MUX Mux", rx_int4_2_mux_chain_enum); 1058 1059 static const struct snd_kcontrol_new rx_int5_2_mux = 1060 SOC_DAPM_ENUM("RX INT5_2 MUX Mux", rx_int5_2_mux_chain_enum); 1061 1062 static const struct snd_kcontrol_new rx_int6_2_mux = 1063 SOC_DAPM_ENUM("RX INT6_2 MUX Mux", rx_int6_2_mux_chain_enum); 1064 1065 static const struct snd_kcontrol_new rx_int7_2_mux = 1066 SOC_DAPM_ENUM("RX INT7_2 MUX Mux", rx_int7_2_mux_chain_enum); 1067 1068 static const struct snd_kcontrol_new rx_int8_2_mux = 1069 SOC_DAPM_ENUM("RX INT8_2 MUX Mux", rx_int8_2_mux_chain_enum); 1070 1071 static const struct snd_kcontrol_new rx_int0_1_mix_inp0_mux = 1072 SOC_DAPM_ENUM("RX INT0_1 MIX1 INP0 Mux", rx_int0_1_mix_inp0_chain_enum); 1073 1074 static const struct snd_kcontrol_new rx_int0_1_mix_inp1_mux = 1075 SOC_DAPM_ENUM("RX INT0_1 MIX1 INP1 Mux", rx_int0_1_mix_inp1_chain_enum); 1076 1077 static const struct snd_kcontrol_new rx_int0_1_mix_inp2_mux = 1078 SOC_DAPM_ENUM("RX INT0_1 MIX1 INP2 Mux", rx_int0_1_mix_inp2_chain_enum); 1079 1080 static const struct snd_kcontrol_new rx_int1_1_mix_inp0_mux = 1081 SOC_DAPM_ENUM("RX INT1_1 MIX1 INP0 Mux", rx_int1_1_mix_inp0_chain_enum); 1082 1083 static const struct snd_kcontrol_new rx_int1_1_mix_inp1_mux = 1084 SOC_DAPM_ENUM("RX INT1_1 MIX1 INP1 Mux", rx_int1_1_mix_inp1_chain_enum); 1085 1086 static const struct snd_kcontrol_new rx_int1_1_mix_inp2_mux = 1087 SOC_DAPM_ENUM("RX INT1_1 MIX1 INP2 Mux", rx_int1_1_mix_inp2_chain_enum); 1088 1089 static const struct snd_kcontrol_new rx_int2_1_mix_inp0_mux = 1090 SOC_DAPM_ENUM("RX INT2_1 MIX1 INP0 Mux", rx_int2_1_mix_inp0_chain_enum); 1091 1092 static const struct snd_kcontrol_new rx_int2_1_mix_inp1_mux = 1093 SOC_DAPM_ENUM("RX INT2_1 MIX1 INP1 Mux", rx_int2_1_mix_inp1_chain_enum); 1094 1095 static const struct snd_kcontrol_new rx_int2_1_mix_inp2_mux = 1096 SOC_DAPM_ENUM("RX INT2_1 MIX1 INP2 Mux", rx_int2_1_mix_inp2_chain_enum); 1097 1098 static const struct snd_kcontrol_new rx_int3_1_mix_inp0_mux = 1099 SOC_DAPM_ENUM("RX INT3_1 MIX1 INP0 Mux", rx_int3_1_mix_inp0_chain_enum); 1100 1101 static const struct snd_kcontrol_new rx_int3_1_mix_inp1_mux = 1102 SOC_DAPM_ENUM("RX INT3_1 MIX1 INP1 Mux", rx_int3_1_mix_inp1_chain_enum); 1103 1104 static const struct snd_kcontrol_new rx_int3_1_mix_inp2_mux = 1105 SOC_DAPM_ENUM("RX INT3_1 MIX1 INP2 Mux", rx_int3_1_mix_inp2_chain_enum); 1106 1107 static const struct snd_kcontrol_new rx_int4_1_mix_inp0_mux = 1108 SOC_DAPM_ENUM("RX INT4_1 MIX1 INP0 Mux", rx_int4_1_mix_inp0_chain_enum); 1109 1110 static const struct snd_kcontrol_new rx_int4_1_mix_inp1_mux = 1111 SOC_DAPM_ENUM("RX INT4_1 MIX1 INP1 Mux", rx_int4_1_mix_inp1_chain_enum); 1112 1113 static const struct snd_kcontrol_new rx_int4_1_mix_inp2_mux = 1114 SOC_DAPM_ENUM("RX INT4_1 MIX1 INP2 Mux", rx_int4_1_mix_inp2_chain_enum); 1115 1116 static const struct snd_kcontrol_new rx_int5_1_mix_inp0_mux = 1117 SOC_DAPM_ENUM("RX INT5_1 MIX1 INP0 Mux", rx_int5_1_mix_inp0_chain_enum); 1118 1119 static const struct snd_kcontrol_new rx_int5_1_mix_inp1_mux = 1120 SOC_DAPM_ENUM("RX INT5_1 MIX1 INP1 Mux", rx_int5_1_mix_inp1_chain_enum); 1121 1122 static const struct snd_kcontrol_new rx_int5_1_mix_inp2_mux = 1123 SOC_DAPM_ENUM("RX INT5_1 MIX1 INP2 Mux", rx_int5_1_mix_inp2_chain_enum); 1124 1125 static const struct snd_kcontrol_new rx_int6_1_mix_inp0_mux = 1126 SOC_DAPM_ENUM("RX INT6_1 MIX1 INP0 Mux", rx_int6_1_mix_inp0_chain_enum); 1127 1128 static const struct snd_kcontrol_new rx_int6_1_mix_inp1_mux = 1129 SOC_DAPM_ENUM("RX INT6_1 MIX1 INP1 Mux", rx_int6_1_mix_inp1_chain_enum); 1130 1131 static const struct snd_kcontrol_new rx_int6_1_mix_inp2_mux = 1132 SOC_DAPM_ENUM("RX INT6_1 MIX1 INP2 Mux", rx_int6_1_mix_inp2_chain_enum); 1133 1134 static const struct snd_kcontrol_new rx_int7_1_mix_inp0_mux = 1135 SOC_DAPM_ENUM("RX INT7_1 MIX1 INP0 Mux", rx_int7_1_mix_inp0_chain_enum); 1136 1137 static const struct snd_kcontrol_new rx_int7_1_mix_inp1_mux = 1138 SOC_DAPM_ENUM("RX INT7_1 MIX1 INP1 Mux", rx_int7_1_mix_inp1_chain_enum); 1139 1140 static const struct snd_kcontrol_new rx_int7_1_mix_inp2_mux = 1141 SOC_DAPM_ENUM("RX INT7_1 MIX1 INP2 Mux", rx_int7_1_mix_inp2_chain_enum); 1142 1143 static const struct snd_kcontrol_new rx_int8_1_mix_inp0_mux = 1144 SOC_DAPM_ENUM("RX INT8_1 MIX1 INP0 Mux", rx_int8_1_mix_inp0_chain_enum); 1145 1146 static const struct snd_kcontrol_new rx_int8_1_mix_inp1_mux = 1147 SOC_DAPM_ENUM("RX INT8_1 MIX1 INP1 Mux", rx_int8_1_mix_inp1_chain_enum); 1148 1149 static const struct snd_kcontrol_new rx_int8_1_mix_inp2_mux = 1150 SOC_DAPM_ENUM("RX INT8_1 MIX1 INP2 Mux", rx_int8_1_mix_inp2_chain_enum); 1151 1152 static const struct snd_kcontrol_new rx_int0_interp_mux = 1153 SOC_DAPM_ENUM("RX INT0 INTERP Mux", rx_int0_interp_mux_enum); 1154 1155 static const struct snd_kcontrol_new rx_int1_interp_mux = 1156 SOC_DAPM_ENUM("RX INT1 INTERP Mux", rx_int1_interp_mux_enum); 1157 1158 static const struct snd_kcontrol_new rx_int2_interp_mux = 1159 SOC_DAPM_ENUM("RX INT2 INTERP Mux", rx_int2_interp_mux_enum); 1160 1161 static const struct snd_kcontrol_new rx_int3_interp_mux = 1162 SOC_DAPM_ENUM("RX INT3 INTERP Mux", rx_int3_interp_mux_enum); 1163 1164 static const struct snd_kcontrol_new rx_int4_interp_mux = 1165 SOC_DAPM_ENUM("RX INT4 INTERP Mux", rx_int4_interp_mux_enum); 1166 1167 static const struct snd_kcontrol_new rx_int5_interp_mux = 1168 SOC_DAPM_ENUM("RX INT5 INTERP Mux", rx_int5_interp_mux_enum); 1169 1170 static const struct snd_kcontrol_new rx_int6_interp_mux = 1171 SOC_DAPM_ENUM("RX INT6 INTERP Mux", rx_int6_interp_mux_enum); 1172 1173 static const struct snd_kcontrol_new rx_int7_interp_mux = 1174 SOC_DAPM_ENUM("RX INT7 INTERP Mux", rx_int7_interp_mux_enum); 1175 1176 static const struct snd_kcontrol_new rx_int8_interp_mux = 1177 SOC_DAPM_ENUM("RX INT8 INTERP Mux", rx_int8_interp_mux_enum); 1178 1179 static const struct snd_kcontrol_new tx_dmic_mux0 = 1180 SOC_DAPM_ENUM("DMIC MUX0 Mux", tx_dmic_mux0_enum); 1181 1182 static const struct snd_kcontrol_new tx_dmic_mux1 = 1183 SOC_DAPM_ENUM("DMIC MUX1 Mux", tx_dmic_mux1_enum); 1184 1185 static const struct snd_kcontrol_new tx_dmic_mux2 = 1186 SOC_DAPM_ENUM("DMIC MUX2 Mux", tx_dmic_mux2_enum); 1187 1188 static const struct snd_kcontrol_new tx_dmic_mux3 = 1189 SOC_DAPM_ENUM("DMIC MUX3 Mux", tx_dmic_mux3_enum); 1190 1191 static const struct snd_kcontrol_new tx_dmic_mux4 = 1192 SOC_DAPM_ENUM("DMIC MUX4 Mux", tx_dmic_mux4_enum); 1193 1194 static const struct snd_kcontrol_new tx_dmic_mux5 = 1195 SOC_DAPM_ENUM("DMIC MUX5 Mux", tx_dmic_mux5_enum); 1196 1197 static const struct snd_kcontrol_new tx_dmic_mux6 = 1198 SOC_DAPM_ENUM("DMIC MUX6 Mux", tx_dmic_mux6_enum); 1199 1200 static const struct snd_kcontrol_new tx_dmic_mux7 = 1201 SOC_DAPM_ENUM("DMIC MUX7 Mux", tx_dmic_mux7_enum); 1202 1203 static const struct snd_kcontrol_new tx_dmic_mux8 = 1204 SOC_DAPM_ENUM("DMIC MUX8 Mux", tx_dmic_mux8_enum); 1205 1206 static const struct snd_kcontrol_new tx_amic_mux0 = 1207 SOC_DAPM_ENUM("AMIC MUX0 Mux", tx_amic_mux0_enum); 1208 1209 static const struct snd_kcontrol_new tx_amic_mux1 = 1210 SOC_DAPM_ENUM("AMIC MUX1 Mux", tx_amic_mux1_enum); 1211 1212 static const struct snd_kcontrol_new tx_amic_mux2 = 1213 SOC_DAPM_ENUM("AMIC MUX2 Mux", tx_amic_mux2_enum); 1214 1215 static const struct snd_kcontrol_new tx_amic_mux3 = 1216 SOC_DAPM_ENUM("AMIC MUX3 Mux", tx_amic_mux3_enum); 1217 1218 static const struct snd_kcontrol_new tx_amic_mux4 = 1219 SOC_DAPM_ENUM("AMIC MUX4 Mux", tx_amic_mux4_enum); 1220 1221 static const struct snd_kcontrol_new tx_amic_mux5 = 1222 SOC_DAPM_ENUM("AMIC MUX5 Mux", tx_amic_mux5_enum); 1223 1224 static const struct snd_kcontrol_new tx_amic_mux6 = 1225 SOC_DAPM_ENUM("AMIC MUX6 Mux", tx_amic_mux6_enum); 1226 1227 static const struct snd_kcontrol_new tx_amic_mux7 = 1228 SOC_DAPM_ENUM("AMIC MUX7 Mux", tx_amic_mux7_enum); 1229 1230 static const struct snd_kcontrol_new tx_amic_mux8 = 1231 SOC_DAPM_ENUM("AMIC MUX8 Mux", tx_amic_mux8_enum); 1232 1233 static const struct snd_kcontrol_new sb_tx0_mux = 1234 SOC_DAPM_ENUM("SLIM TX0 MUX Mux", sb_tx0_mux_enum); 1235 1236 static const struct snd_kcontrol_new sb_tx1_mux = 1237 SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum); 1238 1239 static const struct snd_kcontrol_new sb_tx2_mux = 1240 SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum); 1241 1242 static const struct snd_kcontrol_new sb_tx3_mux = 1243 SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum); 1244 1245 static const struct snd_kcontrol_new sb_tx4_mux = 1246 SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum); 1247 1248 static const struct snd_kcontrol_new sb_tx5_mux = 1249 SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum); 1250 1251 static const struct snd_kcontrol_new sb_tx6_mux = 1252 SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum); 1253 1254 static const struct snd_kcontrol_new sb_tx7_mux = 1255 SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum); 1256 1257 static const struct snd_kcontrol_new sb_tx8_mux = 1258 SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum); 1259 1260 static int slim_rx_mux_get(struct snd_kcontrol *kc, 1261 struct snd_ctl_elem_value *ucontrol) 1262 { 1263 struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kc); 1264 struct wcd9335_codec *wcd = dev_get_drvdata(w->dapm->dev); 1265 u32 port_id = w->shift; 1266 1267 ucontrol->value.enumerated.item[0] = wcd->rx_port_value[port_id]; 1268 1269 return 0; 1270 } 1271 1272 static int slim_rx_mux_put(struct snd_kcontrol *kc, 1273 struct snd_ctl_elem_value *ucontrol) 1274 { 1275 struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kc); 1276 struct wcd9335_codec *wcd = dev_get_drvdata(w->dapm->dev); 1277 struct soc_enum *e = (struct soc_enum *)kc->private_value; 1278 struct snd_soc_dapm_update *update = NULL; 1279 u32 port_id = w->shift; 1280 1281 if (wcd->rx_port_value[port_id] == ucontrol->value.enumerated.item[0]) 1282 return 0; 1283 1284 wcd->rx_port_value[port_id] = ucontrol->value.enumerated.item[0]; 1285 1286 /* Remove channel from any list it's in before adding it to a new one */ 1287 list_del_init(&wcd->rx_chs[port_id].list); 1288 1289 switch (wcd->rx_port_value[port_id]) { 1290 case 0: 1291 /* Channel already removed from lists. Nothing to do here */ 1292 break; 1293 case 1: 1294 list_add_tail(&wcd->rx_chs[port_id].list, 1295 &wcd->dai[AIF1_PB].slim_ch_list); 1296 break; 1297 case 2: 1298 list_add_tail(&wcd->rx_chs[port_id].list, 1299 &wcd->dai[AIF2_PB].slim_ch_list); 1300 break; 1301 case 3: 1302 list_add_tail(&wcd->rx_chs[port_id].list, 1303 &wcd->dai[AIF3_PB].slim_ch_list); 1304 break; 1305 case 4: 1306 list_add_tail(&wcd->rx_chs[port_id].list, 1307 &wcd->dai[AIF4_PB].slim_ch_list); 1308 break; 1309 default: 1310 dev_err(wcd->dev, "Unknown AIF %d\n", wcd->rx_port_value[port_id]); 1311 goto err; 1312 } 1313 1314 snd_soc_dapm_mux_update_power(w->dapm, kc, wcd->rx_port_value[port_id], 1315 e, update); 1316 1317 return 0; 1318 err: 1319 return -EINVAL; 1320 } 1321 1322 static int slim_tx_mixer_get(struct snd_kcontrol *kc, 1323 struct snd_ctl_elem_value *ucontrol) 1324 { 1325 1326 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kc); 1327 struct wcd9335_codec *wcd = dev_get_drvdata(dapm->dev); 1328 struct snd_soc_dapm_widget *widget = snd_soc_dapm_kcontrol_widget(kc); 1329 struct soc_mixer_control *mixer = 1330 (struct soc_mixer_control *)kc->private_value; 1331 int dai_id = widget->shift; 1332 int port_id = mixer->shift; 1333 1334 ucontrol->value.integer.value[0] = wcd->tx_port_value[port_id] == dai_id; 1335 1336 return 0; 1337 } 1338 1339 static int slim_tx_mixer_put(struct snd_kcontrol *kc, 1340 struct snd_ctl_elem_value *ucontrol) 1341 { 1342 1343 struct snd_soc_dapm_widget *widget = snd_soc_dapm_kcontrol_widget(kc); 1344 struct wcd9335_codec *wcd = dev_get_drvdata(widget->dapm->dev); 1345 struct snd_soc_dapm_update *update = NULL; 1346 struct soc_mixer_control *mixer = 1347 (struct soc_mixer_control *)kc->private_value; 1348 int enable = ucontrol->value.integer.value[0]; 1349 int dai_id = widget->shift; 1350 int port_id = mixer->shift; 1351 1352 switch (dai_id) { 1353 case AIF1_CAP: 1354 case AIF2_CAP: 1355 case AIF3_CAP: 1356 /* only add to the list if value not set */ 1357 if (enable && wcd->tx_port_value[port_id] != dai_id) { 1358 wcd->tx_port_value[port_id] = dai_id; 1359 list_add_tail(&wcd->tx_chs[port_id].list, 1360 &wcd->dai[dai_id].slim_ch_list); 1361 } else if (!enable && wcd->tx_port_value[port_id] == dai_id) { 1362 wcd->tx_port_value[port_id] = -1; 1363 list_del_init(&wcd->tx_chs[port_id].list); 1364 } 1365 break; 1366 default: 1367 dev_err(wcd->dev, "Unknown AIF %d\n", dai_id); 1368 return -EINVAL; 1369 } 1370 1371 snd_soc_dapm_mixer_update_power(widget->dapm, kc, enable, update); 1372 1373 return 0; 1374 } 1375 1376 static const struct snd_kcontrol_new slim_rx_mux[WCD9335_RX_MAX] = { 1377 SOC_DAPM_ENUM_EXT("SLIM RX0 Mux", slim_rx_mux_enum, 1378 slim_rx_mux_get, slim_rx_mux_put), 1379 SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum, 1380 slim_rx_mux_get, slim_rx_mux_put), 1381 SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum, 1382 slim_rx_mux_get, slim_rx_mux_put), 1383 SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum, 1384 slim_rx_mux_get, slim_rx_mux_put), 1385 SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum, 1386 slim_rx_mux_get, slim_rx_mux_put), 1387 SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum, 1388 slim_rx_mux_get, slim_rx_mux_put), 1389 SOC_DAPM_ENUM_EXT("SLIM RX6 Mux", slim_rx_mux_enum, 1390 slim_rx_mux_get, slim_rx_mux_put), 1391 SOC_DAPM_ENUM_EXT("SLIM RX7 Mux", slim_rx_mux_enum, 1392 slim_rx_mux_get, slim_rx_mux_put), 1393 }; 1394 1395 static const struct snd_kcontrol_new aif1_cap_mixer[] = { 1396 SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD9335_TX0, 1, 0, 1397 slim_tx_mixer_get, slim_tx_mixer_put), 1398 SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD9335_TX1, 1, 0, 1399 slim_tx_mixer_get, slim_tx_mixer_put), 1400 SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD9335_TX2, 1, 0, 1401 slim_tx_mixer_get, slim_tx_mixer_put), 1402 SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD9335_TX3, 1, 0, 1403 slim_tx_mixer_get, slim_tx_mixer_put), 1404 SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD9335_TX4, 1, 0, 1405 slim_tx_mixer_get, slim_tx_mixer_put), 1406 SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD9335_TX5, 1, 0, 1407 slim_tx_mixer_get, slim_tx_mixer_put), 1408 SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD9335_TX6, 1, 0, 1409 slim_tx_mixer_get, slim_tx_mixer_put), 1410 SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD9335_TX7, 1, 0, 1411 slim_tx_mixer_get, slim_tx_mixer_put), 1412 SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD9335_TX8, 1, 0, 1413 slim_tx_mixer_get, slim_tx_mixer_put), 1414 SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD9335_TX9, 1, 0, 1415 slim_tx_mixer_get, slim_tx_mixer_put), 1416 SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD9335_TX10, 1, 0, 1417 slim_tx_mixer_get, slim_tx_mixer_put), 1418 SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD9335_TX11, 1, 0, 1419 slim_tx_mixer_get, slim_tx_mixer_put), 1420 SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD9335_TX13, 1, 0, 1421 slim_tx_mixer_get, slim_tx_mixer_put), 1422 }; 1423 1424 static const struct snd_kcontrol_new aif2_cap_mixer[] = { 1425 SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD9335_TX0, 1, 0, 1426 slim_tx_mixer_get, slim_tx_mixer_put), 1427 SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD9335_TX1, 1, 0, 1428 slim_tx_mixer_get, slim_tx_mixer_put), 1429 SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD9335_TX2, 1, 0, 1430 slim_tx_mixer_get, slim_tx_mixer_put), 1431 SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD9335_TX3, 1, 0, 1432 slim_tx_mixer_get, slim_tx_mixer_put), 1433 SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD9335_TX4, 1, 0, 1434 slim_tx_mixer_get, slim_tx_mixer_put), 1435 SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD9335_TX5, 1, 0, 1436 slim_tx_mixer_get, slim_tx_mixer_put), 1437 SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD9335_TX6, 1, 0, 1438 slim_tx_mixer_get, slim_tx_mixer_put), 1439 SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD9335_TX7, 1, 0, 1440 slim_tx_mixer_get, slim_tx_mixer_put), 1441 SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD9335_TX8, 1, 0, 1442 slim_tx_mixer_get, slim_tx_mixer_put), 1443 SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD9335_TX9, 1, 0, 1444 slim_tx_mixer_get, slim_tx_mixer_put), 1445 SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD9335_TX10, 1, 0, 1446 slim_tx_mixer_get, slim_tx_mixer_put), 1447 SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD9335_TX11, 1, 0, 1448 slim_tx_mixer_get, slim_tx_mixer_put), 1449 SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD9335_TX13, 1, 0, 1450 slim_tx_mixer_get, slim_tx_mixer_put), 1451 }; 1452 1453 static const struct snd_kcontrol_new aif3_cap_mixer[] = { 1454 SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD9335_TX0, 1, 0, 1455 slim_tx_mixer_get, slim_tx_mixer_put), 1456 SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD9335_TX1, 1, 0, 1457 slim_tx_mixer_get, slim_tx_mixer_put), 1458 SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD9335_TX2, 1, 0, 1459 slim_tx_mixer_get, slim_tx_mixer_put), 1460 SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD9335_TX3, 1, 0, 1461 slim_tx_mixer_get, slim_tx_mixer_put), 1462 SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD9335_TX4, 1, 0, 1463 slim_tx_mixer_get, slim_tx_mixer_put), 1464 SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD9335_TX5, 1, 0, 1465 slim_tx_mixer_get, slim_tx_mixer_put), 1466 SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD9335_TX6, 1, 0, 1467 slim_tx_mixer_get, slim_tx_mixer_put), 1468 SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD9335_TX7, 1, 0, 1469 slim_tx_mixer_get, slim_tx_mixer_put), 1470 SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD9335_TX8, 1, 0, 1471 slim_tx_mixer_get, slim_tx_mixer_put), 1472 }; 1473 1474 static int wcd9335_put_dec_enum(struct snd_kcontrol *kc, 1475 struct snd_ctl_elem_value *ucontrol) 1476 { 1477 struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kc); 1478 struct snd_soc_component *component = snd_soc_dapm_to_component(dapm); 1479 struct soc_enum *e = (struct soc_enum *)kc->private_value; 1480 unsigned int val, reg, sel; 1481 1482 val = ucontrol->value.enumerated.item[0]; 1483 1484 switch (e->reg) { 1485 case WCD9335_CDC_TX_INP_MUX_ADC_MUX0_CFG1: 1486 reg = WCD9335_CDC_TX0_TX_PATH_CFG0; 1487 break; 1488 case WCD9335_CDC_TX_INP_MUX_ADC_MUX1_CFG1: 1489 reg = WCD9335_CDC_TX1_TX_PATH_CFG0; 1490 break; 1491 case WCD9335_CDC_TX_INP_MUX_ADC_MUX2_CFG1: 1492 reg = WCD9335_CDC_TX2_TX_PATH_CFG0; 1493 break; 1494 case WCD9335_CDC_TX_INP_MUX_ADC_MUX3_CFG1: 1495 reg = WCD9335_CDC_TX3_TX_PATH_CFG0; 1496 break; 1497 case WCD9335_CDC_TX_INP_MUX_ADC_MUX4_CFG0: 1498 reg = WCD9335_CDC_TX4_TX_PATH_CFG0; 1499 break; 1500 case WCD9335_CDC_TX_INP_MUX_ADC_MUX5_CFG0: 1501 reg = WCD9335_CDC_TX5_TX_PATH_CFG0; 1502 break; 1503 case WCD9335_CDC_TX_INP_MUX_ADC_MUX6_CFG0: 1504 reg = WCD9335_CDC_TX6_TX_PATH_CFG0; 1505 break; 1506 case WCD9335_CDC_TX_INP_MUX_ADC_MUX7_CFG0: 1507 reg = WCD9335_CDC_TX7_TX_PATH_CFG0; 1508 break; 1509 case WCD9335_CDC_TX_INP_MUX_ADC_MUX8_CFG0: 1510 reg = WCD9335_CDC_TX8_TX_PATH_CFG0; 1511 break; 1512 default: 1513 return -EINVAL; 1514 } 1515 1516 /* AMIC: 0, DMIC: 1 */ 1517 sel = val ? WCD9335_CDC_TX_ADC_AMIC_SEL : WCD9335_CDC_TX_ADC_DMIC_SEL; 1518 snd_soc_component_update_bits(component, reg, 1519 WCD9335_CDC_TX_ADC_AMIC_DMIC_SEL_MASK, 1520 sel); 1521 1522 return snd_soc_dapm_put_enum_double(kc, ucontrol); 1523 } 1524 1525 static int wcd9335_int_dem_inp_mux_put(struct snd_kcontrol *kc, 1526 struct snd_ctl_elem_value *ucontrol) 1527 { 1528 struct soc_enum *e = (struct soc_enum *)kc->private_value; 1529 struct snd_soc_component *component; 1530 int reg, val; 1531 1532 component = snd_soc_dapm_kcontrol_component(kc); 1533 val = ucontrol->value.enumerated.item[0]; 1534 1535 if (e->reg == WCD9335_CDC_RX0_RX_PATH_SEC0) 1536 reg = WCD9335_CDC_RX0_RX_PATH_CFG0; 1537 else if (e->reg == WCD9335_CDC_RX1_RX_PATH_SEC0) 1538 reg = WCD9335_CDC_RX1_RX_PATH_CFG0; 1539 else if (e->reg == WCD9335_CDC_RX2_RX_PATH_SEC0) 1540 reg = WCD9335_CDC_RX2_RX_PATH_CFG0; 1541 else 1542 return -EINVAL; 1543 1544 /* Set Look Ahead Delay */ 1545 snd_soc_component_update_bits(component, reg, 1546 WCD9335_CDC_RX_PATH_CFG0_DLY_ZN_EN_MASK, 1547 val ? WCD9335_CDC_RX_PATH_CFG0_DLY_ZN_EN : 0); 1548 /* Set DEM INP Select */ 1549 return snd_soc_dapm_put_enum_double(kc, ucontrol); 1550 } 1551 1552 static const struct snd_kcontrol_new rx_int0_dem_inp_mux = 1553 SOC_DAPM_ENUM_EXT("RX INT0 DEM MUX Mux", rx_int0_dem_inp_mux_enum, 1554 snd_soc_dapm_get_enum_double, 1555 wcd9335_int_dem_inp_mux_put); 1556 1557 static const struct snd_kcontrol_new rx_int1_dem_inp_mux = 1558 SOC_DAPM_ENUM_EXT("RX INT1 DEM MUX Mux", rx_int1_dem_inp_mux_enum, 1559 snd_soc_dapm_get_enum_double, 1560 wcd9335_int_dem_inp_mux_put); 1561 1562 static const struct snd_kcontrol_new rx_int2_dem_inp_mux = 1563 SOC_DAPM_ENUM_EXT("RX INT2 DEM MUX Mux", rx_int2_dem_inp_mux_enum, 1564 snd_soc_dapm_get_enum_double, 1565 wcd9335_int_dem_inp_mux_put); 1566 1567 static const struct snd_kcontrol_new tx_adc_mux0 = 1568 SOC_DAPM_ENUM_EXT("ADC MUX0 Mux", tx_adc_mux0_chain_enum, 1569 snd_soc_dapm_get_enum_double, 1570 wcd9335_put_dec_enum); 1571 1572 static const struct snd_kcontrol_new tx_adc_mux1 = 1573 SOC_DAPM_ENUM_EXT("ADC MUX1 Mux", tx_adc_mux1_chain_enum, 1574 snd_soc_dapm_get_enum_double, 1575 wcd9335_put_dec_enum); 1576 1577 static const struct snd_kcontrol_new tx_adc_mux2 = 1578 SOC_DAPM_ENUM_EXT("ADC MUX2 Mux", tx_adc_mux2_chain_enum, 1579 snd_soc_dapm_get_enum_double, 1580 wcd9335_put_dec_enum); 1581 1582 static const struct snd_kcontrol_new tx_adc_mux3 = 1583 SOC_DAPM_ENUM_EXT("ADC MUX3 Mux", tx_adc_mux3_chain_enum, 1584 snd_soc_dapm_get_enum_double, 1585 wcd9335_put_dec_enum); 1586 1587 static const struct snd_kcontrol_new tx_adc_mux4 = 1588 SOC_DAPM_ENUM_EXT("ADC MUX4 Mux", tx_adc_mux4_chain_enum, 1589 snd_soc_dapm_get_enum_double, 1590 wcd9335_put_dec_enum); 1591 1592 static const struct snd_kcontrol_new tx_adc_mux5 = 1593 SOC_DAPM_ENUM_EXT("ADC MUX5 Mux", tx_adc_mux5_chain_enum, 1594 snd_soc_dapm_get_enum_double, 1595 wcd9335_put_dec_enum); 1596 1597 static const struct snd_kcontrol_new tx_adc_mux6 = 1598 SOC_DAPM_ENUM_EXT("ADC MUX6 Mux", tx_adc_mux6_chain_enum, 1599 snd_soc_dapm_get_enum_double, 1600 wcd9335_put_dec_enum); 1601 1602 static const struct snd_kcontrol_new tx_adc_mux7 = 1603 SOC_DAPM_ENUM_EXT("ADC MUX7 Mux", tx_adc_mux7_chain_enum, 1604 snd_soc_dapm_get_enum_double, 1605 wcd9335_put_dec_enum); 1606 1607 static const struct snd_kcontrol_new tx_adc_mux8 = 1608 SOC_DAPM_ENUM_EXT("ADC MUX8 Mux", tx_adc_mux8_chain_enum, 1609 snd_soc_dapm_get_enum_double, 1610 wcd9335_put_dec_enum); 1611 1612 static int wcd9335_set_mix_interpolator_rate(struct snd_soc_dai *dai, 1613 int rate_val, 1614 u32 rate) 1615 { 1616 struct snd_soc_component *component = dai->component; 1617 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); 1618 struct wcd9335_slim_ch *ch; 1619 int val, j; 1620 1621 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) { 1622 for (j = 0; j < WCD9335_NUM_INTERPOLATORS; j++) { 1623 val = snd_soc_component_read(component, 1624 WCD9335_CDC_RX_INP_MUX_RX_INT_CFG1(j)) & 1625 WCD9335_CDC_RX_INP_MUX_RX_INT_SEL_MASK; 1626 1627 if (val == (ch->shift + INTn_2_INP_SEL_RX0)) 1628 snd_soc_component_update_bits(component, 1629 WCD9335_CDC_RX_PATH_MIX_CTL(j), 1630 WCD9335_CDC_MIX_PCM_RATE_MASK, 1631 rate_val); 1632 } 1633 } 1634 1635 return 0; 1636 } 1637 1638 static int wcd9335_set_prim_interpolator_rate(struct snd_soc_dai *dai, 1639 u8 rate_val, 1640 u32 rate) 1641 { 1642 struct snd_soc_component *comp = dai->component; 1643 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); 1644 struct wcd9335_slim_ch *ch; 1645 u8 cfg0, cfg1, inp0_sel, inp1_sel, inp2_sel; 1646 int inp, j; 1647 1648 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) { 1649 inp = ch->shift + INTn_1_MIX_INP_SEL_RX0; 1650 /* 1651 * Loop through all interpolator MUX inputs and find out 1652 * to which interpolator input, the slim rx port 1653 * is connected 1654 */ 1655 for (j = 0; j < WCD9335_NUM_INTERPOLATORS; j++) { 1656 cfg0 = snd_soc_component_read(comp, 1657 WCD9335_CDC_RX_INP_MUX_RX_INT_CFG0(j)); 1658 cfg1 = snd_soc_component_read(comp, 1659 WCD9335_CDC_RX_INP_MUX_RX_INT_CFG1(j)); 1660 1661 inp0_sel = cfg0 & 1662 WCD9335_CDC_RX_INP_MUX_RX_INT_SEL_MASK; 1663 inp1_sel = (cfg0 >> 4) & 1664 WCD9335_CDC_RX_INP_MUX_RX_INT_SEL_MASK; 1665 inp2_sel = (cfg1 >> 4) & 1666 WCD9335_CDC_RX_INP_MUX_RX_INT_SEL_MASK; 1667 1668 if ((inp0_sel == inp) || (inp1_sel == inp) || 1669 (inp2_sel == inp)) { 1670 /* rate is in Hz */ 1671 if ((j == 0) && (rate == 44100)) 1672 dev_info(wcd->dev, 1673 "Cannot set 44.1KHz on INT0\n"); 1674 else 1675 snd_soc_component_update_bits(comp, 1676 WCD9335_CDC_RX_PATH_CTL(j), 1677 WCD9335_CDC_MIX_PCM_RATE_MASK, 1678 rate_val); 1679 } 1680 } 1681 } 1682 1683 return 0; 1684 } 1685 1686 static int wcd9335_set_interpolator_rate(struct snd_soc_dai *dai, u32 rate) 1687 { 1688 int i; 1689 1690 /* set mixing path rate */ 1691 for (i = 0; i < ARRAY_SIZE(int_mix_rate_val); i++) { 1692 if (rate == int_mix_rate_val[i].rate) { 1693 wcd9335_set_mix_interpolator_rate(dai, 1694 int_mix_rate_val[i].rate_val, rate); 1695 break; 1696 } 1697 } 1698 1699 /* set primary path sample rate */ 1700 for (i = 0; i < ARRAY_SIZE(int_prim_rate_val); i++) { 1701 if (rate == int_prim_rate_val[i].rate) { 1702 wcd9335_set_prim_interpolator_rate(dai, 1703 int_prim_rate_val[i].rate_val, rate); 1704 break; 1705 } 1706 } 1707 1708 return 0; 1709 } 1710 1711 static int wcd9335_slim_set_hw_params(struct wcd9335_codec *wcd, 1712 struct wcd_slim_codec_dai_data *dai_data, 1713 int direction) 1714 { 1715 struct list_head *slim_ch_list = &dai_data->slim_ch_list; 1716 struct slim_stream_config *cfg = &dai_data->sconfig; 1717 struct wcd9335_slim_ch *ch; 1718 u16 payload = 0; 1719 int ret, i; 1720 1721 cfg->ch_count = 0; 1722 cfg->direction = direction; 1723 cfg->port_mask = 0; 1724 1725 /* Configure slave interface device */ 1726 list_for_each_entry(ch, slim_ch_list, list) { 1727 cfg->ch_count++; 1728 payload |= 1 << ch->shift; 1729 cfg->port_mask |= BIT(ch->port); 1730 } 1731 1732 cfg->chs = kcalloc(cfg->ch_count, sizeof(unsigned int), GFP_KERNEL); 1733 if (!cfg->chs) 1734 return -ENOMEM; 1735 1736 i = 0; 1737 list_for_each_entry(ch, slim_ch_list, list) { 1738 cfg->chs[i++] = ch->ch_num; 1739 if (direction == SNDRV_PCM_STREAM_PLAYBACK) { 1740 /* write to interface device */ 1741 ret = regmap_write(wcd->if_regmap, 1742 WCD9335_SLIM_PGD_RX_PORT_MULTI_CHNL_0(ch->port), 1743 payload); 1744 1745 if (ret < 0) 1746 goto err; 1747 1748 /* configure the slave port for water mark and enable*/ 1749 ret = regmap_write(wcd->if_regmap, 1750 WCD9335_SLIM_PGD_RX_PORT_CFG(ch->port), 1751 WCD9335_SLIM_WATER_MARK_VAL); 1752 if (ret < 0) 1753 goto err; 1754 } else { 1755 ret = regmap_write(wcd->if_regmap, 1756 WCD9335_SLIM_PGD_TX_PORT_MULTI_CHNL_0(ch->port), 1757 payload & 0x00FF); 1758 if (ret < 0) 1759 goto err; 1760 1761 /* ports 8,9 */ 1762 ret = regmap_write(wcd->if_regmap, 1763 WCD9335_SLIM_PGD_TX_PORT_MULTI_CHNL_1(ch->port), 1764 (payload & 0xFF00)>>8); 1765 if (ret < 0) 1766 goto err; 1767 1768 /* configure the slave port for water mark and enable*/ 1769 ret = regmap_write(wcd->if_regmap, 1770 WCD9335_SLIM_PGD_TX_PORT_CFG(ch->port), 1771 WCD9335_SLIM_WATER_MARK_VAL); 1772 1773 if (ret < 0) 1774 goto err; 1775 } 1776 } 1777 1778 dai_data->sruntime = slim_stream_allocate(wcd->slim, "WCD9335-SLIM"); 1779 1780 return 0; 1781 1782 err: 1783 dev_err(wcd->dev, "Error Setting slim hw params\n"); 1784 kfree(cfg->chs); 1785 cfg->chs = NULL; 1786 1787 return ret; 1788 } 1789 1790 static int wcd9335_set_decimator_rate(struct snd_soc_dai *dai, 1791 u8 rate_val, u32 rate) 1792 { 1793 struct snd_soc_component *comp = dai->component; 1794 struct wcd9335_codec *wcd = snd_soc_component_get_drvdata(comp); 1795 u8 shift = 0, shift_val = 0, tx_mux_sel; 1796 struct wcd9335_slim_ch *ch; 1797 int tx_port, tx_port_reg; 1798 int decimator = -1; 1799 1800 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) { 1801 tx_port = ch->port; 1802 if ((tx_port == 12) || (tx_port >= 14)) { 1803 dev_err(wcd->dev, "Invalid SLIM TX%u port DAI ID:%d\n", 1804 tx_port, dai->id); 1805 return -EINVAL; 1806 } 1807 /* Find the SB TX MUX input - which decimator is connected */ 1808 if (tx_port < 4) { 1809 tx_port_reg = WCD9335_CDC_IF_ROUTER_TX_MUX_CFG0; 1810 shift = (tx_port << 1); 1811 shift_val = 0x03; 1812 } else if (tx_port < 8) { 1813 tx_port_reg = WCD9335_CDC_IF_ROUTER_TX_MUX_CFG1; 1814 shift = ((tx_port - 4) << 1); 1815 shift_val = 0x03; 1816 } else if (tx_port < 11) { 1817 tx_port_reg = WCD9335_CDC_IF_ROUTER_TX_MUX_CFG2; 1818 shift = ((tx_port - 8) << 1); 1819 shift_val = 0x03; 1820 } else if (tx_port == 11) { 1821 tx_port_reg = WCD9335_CDC_IF_ROUTER_TX_MUX_CFG3; 1822 shift = 0; 1823 shift_val = 0x0F; 1824 } else /* (tx_port == 13) */ { 1825 tx_port_reg = WCD9335_CDC_IF_ROUTER_TX_MUX_CFG3; 1826 shift = 4; 1827 shift_val = 0x03; 1828 } 1829 1830 tx_mux_sel = snd_soc_component_read(comp, tx_port_reg) & 1831 (shift_val << shift); 1832 1833 tx_mux_sel = tx_mux_sel >> shift; 1834 if (tx_port <= 8) { 1835 if ((tx_mux_sel == 0x2) || (tx_mux_sel == 0x3)) 1836 decimator = tx_port; 1837 } else if (tx_port <= 10) { 1838 if ((tx_mux_sel == 0x1) || (tx_mux_sel == 0x2)) 1839 decimator = ((tx_port == 9) ? 7 : 6); 1840 } else if (tx_port == 11) { 1841 if ((tx_mux_sel >= 1) && (tx_mux_sel < 7)) 1842 decimator = tx_mux_sel - 1; 1843 } else if (tx_port == 13) { 1844 if ((tx_mux_sel == 0x1) || (tx_mux_sel == 0x2)) 1845 decimator = 5; 1846 } 1847 1848 if (decimator >= 0) { 1849 snd_soc_component_update_bits(comp, 1850 WCD9335_CDC_TX_PATH_CTL(decimator), 1851 WCD9335_CDC_TX_PATH_CTL_PCM_RATE_MASK, 1852 rate_val); 1853 } else if ((tx_port <= 8) && (tx_mux_sel == 0x01)) { 1854 /* Check if the TX Mux input is RX MIX TXn */ 1855 dev_err(wcd->dev, "RX_MIX_TX%u going to SLIM TX%u\n", 1856 tx_port, tx_port); 1857 } else { 1858 dev_err(wcd->dev, "ERROR: Invalid decimator: %d\n", 1859 decimator); 1860 return -EINVAL; 1861 } 1862 } 1863 1864 return 0; 1865 } 1866 1867 static int wcd9335_hw_params(struct snd_pcm_substream *substream, 1868 struct snd_pcm_hw_params *params, 1869 struct snd_soc_dai *dai) 1870 { 1871 struct wcd9335_codec *wcd; 1872 int ret, tx_fs_rate = 0; 1873 1874 wcd = snd_soc_component_get_drvdata(dai->component); 1875 1876 switch (substream->stream) { 1877 case SNDRV_PCM_STREAM_PLAYBACK: 1878 ret = wcd9335_set_interpolator_rate(dai, params_rate(params)); 1879 if (ret) { 1880 dev_err(wcd->dev, "cannot set sample rate: %u\n", 1881 params_rate(params)); 1882 return ret; 1883 } 1884 switch (params_width(params)) { 1885 case 16 ... 24: 1886 wcd->dai[dai->id].sconfig.bps = params_width(params); 1887 break; 1888 default: 1889 dev_err(wcd->dev, "%s: Invalid format 0x%x\n", 1890 __func__, params_width(params)); 1891 return -EINVAL; 1892 } 1893 break; 1894 1895 case SNDRV_PCM_STREAM_CAPTURE: 1896 switch (params_rate(params)) { 1897 case 8000: 1898 tx_fs_rate = 0; 1899 break; 1900 case 16000: 1901 tx_fs_rate = 1; 1902 break; 1903 case 32000: 1904 tx_fs_rate = 3; 1905 break; 1906 case 48000: 1907 tx_fs_rate = 4; 1908 break; 1909 case 96000: 1910 tx_fs_rate = 5; 1911 break; 1912 case 192000: 1913 tx_fs_rate = 6; 1914 break; 1915 case 384000: 1916 tx_fs_rate = 7; 1917 break; 1918 default: 1919 dev_err(wcd->dev, "%s: Invalid TX sample rate: %d\n", 1920 __func__, params_rate(params)); 1921 return -EINVAL; 1922 1923 } 1924 1925 ret = wcd9335_set_decimator_rate(dai, tx_fs_rate, 1926 params_rate(params)); 1927 if (ret < 0) { 1928 dev_err(wcd->dev, "Cannot set TX Decimator rate\n"); 1929 return ret; 1930 } 1931 switch (params_width(params)) { 1932 case 16 ... 32: 1933 wcd->dai[dai->id].sconfig.bps = params_width(params); 1934 break; 1935 default: 1936 dev_err(wcd->dev, "%s: Invalid format 0x%x\n", 1937 __func__, params_width(params)); 1938 return -EINVAL; 1939 } 1940 break; 1941 default: 1942 dev_err(wcd->dev, "Invalid stream type %d\n", 1943 substream->stream); 1944 return -EINVAL; 1945 } 1946 1947 wcd->dai[dai->id].sconfig.rate = params_rate(params); 1948 wcd9335_slim_set_hw_params(wcd, &wcd->dai[dai->id], substream->stream); 1949 1950 return 0; 1951 } 1952 1953 static int wcd9335_trigger(struct snd_pcm_substream *substream, int cmd, 1954 struct snd_soc_dai *dai) 1955 { 1956 struct wcd_slim_codec_dai_data *dai_data; 1957 struct wcd9335_codec *wcd; 1958 struct slim_stream_config *cfg; 1959 1960 wcd = snd_soc_component_get_drvdata(dai->component); 1961 1962 dai_data = &wcd->dai[dai->id]; 1963 1964 switch (cmd) { 1965 case SNDRV_PCM_TRIGGER_START: 1966 case SNDRV_PCM_TRIGGER_RESUME: 1967 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 1968 cfg = &dai_data->sconfig; 1969 slim_stream_prepare(dai_data->sruntime, cfg); 1970 slim_stream_enable(dai_data->sruntime); 1971 break; 1972 case SNDRV_PCM_TRIGGER_STOP: 1973 case SNDRV_PCM_TRIGGER_SUSPEND: 1974 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1975 slim_stream_disable(dai_data->sruntime); 1976 slim_stream_unprepare(dai_data->sruntime); 1977 break; 1978 default: 1979 break; 1980 } 1981 1982 return 0; 1983 } 1984 1985 static int wcd9335_set_channel_map(struct snd_soc_dai *dai, 1986 unsigned int tx_num, 1987 const unsigned int *tx_slot, 1988 unsigned int rx_num, 1989 const unsigned int *rx_slot) 1990 { 1991 struct wcd9335_codec *wcd; 1992 int i; 1993 1994 wcd = snd_soc_component_get_drvdata(dai->component); 1995 1996 if (!tx_slot || !rx_slot) { 1997 dev_err(wcd->dev, "Invalid tx_slot=%p, rx_slot=%p\n", 1998 tx_slot, rx_slot); 1999 return -EINVAL; 2000 } 2001 2002 wcd->num_rx_port = rx_num; 2003 for (i = 0; i < rx_num; i++) { 2004 wcd->rx_chs[i].ch_num = rx_slot[i]; 2005 INIT_LIST_HEAD(&wcd->rx_chs[i].list); 2006 } 2007 2008 wcd->num_tx_port = tx_num; 2009 for (i = 0; i < tx_num; i++) { 2010 wcd->tx_chs[i].ch_num = tx_slot[i]; 2011 INIT_LIST_HEAD(&wcd->tx_chs[i].list); 2012 } 2013 2014 return 0; 2015 } 2016 2017 static int wcd9335_get_channel_map(const struct snd_soc_dai *dai, 2018 unsigned int *tx_num, unsigned int *tx_slot, 2019 unsigned int *rx_num, unsigned int *rx_slot) 2020 { 2021 struct wcd9335_slim_ch *ch; 2022 struct wcd9335_codec *wcd; 2023 int i = 0; 2024 2025 wcd = snd_soc_component_get_drvdata(dai->component); 2026 2027 switch (dai->id) { 2028 case AIF1_PB: 2029 case AIF2_PB: 2030 case AIF3_PB: 2031 case AIF4_PB: 2032 if (!rx_slot || !rx_num) { 2033 dev_err(wcd->dev, "Invalid rx_slot %p or rx_num %p\n", 2034 rx_slot, rx_num); 2035 return -EINVAL; 2036 } 2037 2038 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) 2039 rx_slot[i++] = ch->ch_num; 2040 2041 *rx_num = i; 2042 break; 2043 case AIF1_CAP: 2044 case AIF2_CAP: 2045 case AIF3_CAP: 2046 if (!tx_slot || !tx_num) { 2047 dev_err(wcd->dev, "Invalid tx_slot %p or tx_num %p\n", 2048 tx_slot, tx_num); 2049 return -EINVAL; 2050 } 2051 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) 2052 tx_slot[i++] = ch->ch_num; 2053 2054 *tx_num = i; 2055 break; 2056 default: 2057 dev_err(wcd->dev, "Invalid DAI ID %x\n", dai->id); 2058 break; 2059 } 2060 2061 return 0; 2062 } 2063 2064 static const struct snd_soc_dai_ops wcd9335_dai_ops = { 2065 .hw_params = wcd9335_hw_params, 2066 .trigger = wcd9335_trigger, 2067 .set_channel_map = wcd9335_set_channel_map, 2068 .get_channel_map = wcd9335_get_channel_map, 2069 }; 2070 2071 static struct snd_soc_dai_driver wcd9335_slim_dais[] = { 2072 [0] = { 2073 .name = "wcd9335_rx1", 2074 .id = AIF1_PB, 2075 .playback = { 2076 .stream_name = "AIF1 Playback", 2077 .rates = WCD9335_RATES_MASK | WCD9335_FRAC_RATES_MASK | 2078 SNDRV_PCM_RATE_384000, 2079 .formats = WCD9335_FORMATS_S16_S24_LE, 2080 .rate_max = 384000, 2081 .rate_min = 8000, 2082 .channels_min = 1, 2083 .channels_max = 2, 2084 }, 2085 .ops = &wcd9335_dai_ops, 2086 }, 2087 [1] = { 2088 .name = "wcd9335_tx1", 2089 .id = AIF1_CAP, 2090 .capture = { 2091 .stream_name = "AIF1 Capture", 2092 .rates = WCD9335_RATES_MASK, 2093 .formats = SNDRV_PCM_FMTBIT_S16_LE, 2094 .rate_min = 8000, 2095 .rate_max = 192000, 2096 .channels_min = 1, 2097 .channels_max = 4, 2098 }, 2099 .ops = &wcd9335_dai_ops, 2100 }, 2101 [2] = { 2102 .name = "wcd9335_rx2", 2103 .id = AIF2_PB, 2104 .playback = { 2105 .stream_name = "AIF2 Playback", 2106 .rates = WCD9335_RATES_MASK | WCD9335_FRAC_RATES_MASK | 2107 SNDRV_PCM_RATE_384000, 2108 .formats = WCD9335_FORMATS_S16_S24_LE, 2109 .rate_min = 8000, 2110 .rate_max = 384000, 2111 .channels_min = 1, 2112 .channels_max = 2, 2113 }, 2114 .ops = &wcd9335_dai_ops, 2115 }, 2116 [3] = { 2117 .name = "wcd9335_tx2", 2118 .id = AIF2_CAP, 2119 .capture = { 2120 .stream_name = "AIF2 Capture", 2121 .rates = WCD9335_RATES_MASK, 2122 .formats = SNDRV_PCM_FMTBIT_S16_LE, 2123 .rate_min = 8000, 2124 .rate_max = 192000, 2125 .channels_min = 1, 2126 .channels_max = 4, 2127 }, 2128 .ops = &wcd9335_dai_ops, 2129 }, 2130 [4] = { 2131 .name = "wcd9335_rx3", 2132 .id = AIF3_PB, 2133 .playback = { 2134 .stream_name = "AIF3 Playback", 2135 .rates = WCD9335_RATES_MASK | WCD9335_FRAC_RATES_MASK | 2136 SNDRV_PCM_RATE_384000, 2137 .formats = WCD9335_FORMATS_S16_S24_LE, 2138 .rate_min = 8000, 2139 .rate_max = 384000, 2140 .channels_min = 1, 2141 .channels_max = 2, 2142 }, 2143 .ops = &wcd9335_dai_ops, 2144 }, 2145 [5] = { 2146 .name = "wcd9335_tx3", 2147 .id = AIF3_CAP, 2148 .capture = { 2149 .stream_name = "AIF3 Capture", 2150 .rates = WCD9335_RATES_MASK, 2151 .formats = SNDRV_PCM_FMTBIT_S16_LE, 2152 .rate_min = 8000, 2153 .rate_max = 192000, 2154 .channels_min = 1, 2155 .channels_max = 4, 2156 }, 2157 .ops = &wcd9335_dai_ops, 2158 }, 2159 [6] = { 2160 .name = "wcd9335_rx4", 2161 .id = AIF4_PB, 2162 .playback = { 2163 .stream_name = "AIF4 Playback", 2164 .rates = WCD9335_RATES_MASK | WCD9335_FRAC_RATES_MASK | 2165 SNDRV_PCM_RATE_384000, 2166 .formats = WCD9335_FORMATS_S16_S24_LE, 2167 .rate_min = 8000, 2168 .rate_max = 384000, 2169 .channels_min = 1, 2170 .channels_max = 2, 2171 }, 2172 .ops = &wcd9335_dai_ops, 2173 }, 2174 }; 2175 2176 static int wcd9335_get_compander(struct snd_kcontrol *kc, 2177 struct snd_ctl_elem_value *ucontrol) 2178 { 2179 2180 struct snd_soc_component *component = snd_soc_kcontrol_component(kc); 2181 int comp = ((struct soc_mixer_control *)kc->private_value)->shift; 2182 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); 2183 2184 ucontrol->value.integer.value[0] = wcd->comp_enabled[comp]; 2185 return 0; 2186 } 2187 2188 static int wcd9335_set_compander(struct snd_kcontrol *kc, 2189 struct snd_ctl_elem_value *ucontrol) 2190 { 2191 struct snd_soc_component *component = snd_soc_kcontrol_component(kc); 2192 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); 2193 int comp = ((struct soc_mixer_control *) kc->private_value)->shift; 2194 int value = ucontrol->value.integer.value[0]; 2195 int sel; 2196 2197 wcd->comp_enabled[comp] = value; 2198 sel = value ? WCD9335_HPH_GAIN_SRC_SEL_COMPANDER : 2199 WCD9335_HPH_GAIN_SRC_SEL_REGISTER; 2200 2201 /* Any specific register configuration for compander */ 2202 switch (comp) { 2203 case COMPANDER_1: 2204 /* Set Gain Source Select based on compander enable/disable */ 2205 snd_soc_component_update_bits(component, WCD9335_HPH_L_EN, 2206 WCD9335_HPH_GAIN_SRC_SEL_MASK, sel); 2207 break; 2208 case COMPANDER_2: 2209 snd_soc_component_update_bits(component, WCD9335_HPH_R_EN, 2210 WCD9335_HPH_GAIN_SRC_SEL_MASK, sel); 2211 break; 2212 case COMPANDER_5: 2213 snd_soc_component_update_bits(component, WCD9335_SE_LO_LO3_GAIN, 2214 WCD9335_HPH_GAIN_SRC_SEL_MASK, sel); 2215 break; 2216 case COMPANDER_6: 2217 snd_soc_component_update_bits(component, WCD9335_SE_LO_LO4_GAIN, 2218 WCD9335_HPH_GAIN_SRC_SEL_MASK, sel); 2219 break; 2220 default: 2221 break; 2222 } 2223 2224 return 0; 2225 } 2226 2227 static int wcd9335_rx_hph_mode_get(struct snd_kcontrol *kc, 2228 struct snd_ctl_elem_value *ucontrol) 2229 { 2230 struct snd_soc_component *component = snd_soc_kcontrol_component(kc); 2231 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); 2232 2233 ucontrol->value.enumerated.item[0] = wcd->hph_mode; 2234 2235 return 0; 2236 } 2237 2238 static int wcd9335_rx_hph_mode_put(struct snd_kcontrol *kc, 2239 struct snd_ctl_elem_value *ucontrol) 2240 { 2241 struct snd_soc_component *component = snd_soc_kcontrol_component(kc); 2242 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); 2243 u32 mode_val; 2244 2245 mode_val = ucontrol->value.enumerated.item[0]; 2246 2247 if (mode_val == 0) { 2248 dev_err(wcd->dev, "Invalid HPH Mode, default to ClSH HiFi\n"); 2249 mode_val = CLS_H_HIFI; 2250 } 2251 wcd->hph_mode = mode_val; 2252 2253 return 0; 2254 } 2255 2256 static const struct snd_kcontrol_new wcd9335_snd_controls[] = { 2257 /* -84dB min - 40dB max */ 2258 SOC_SINGLE_S8_TLV("RX0 Digital Volume", WCD9335_CDC_RX0_RX_VOL_CTL, 2259 -84, 40, digital_gain), 2260 SOC_SINGLE_S8_TLV("RX1 Digital Volume", WCD9335_CDC_RX1_RX_VOL_CTL, 2261 -84, 40, digital_gain), 2262 SOC_SINGLE_S8_TLV("RX2 Digital Volume", WCD9335_CDC_RX2_RX_VOL_CTL, 2263 -84, 40, digital_gain), 2264 SOC_SINGLE_S8_TLV("RX3 Digital Volume", WCD9335_CDC_RX3_RX_VOL_CTL, 2265 -84, 40, digital_gain), 2266 SOC_SINGLE_S8_TLV("RX4 Digital Volume", WCD9335_CDC_RX4_RX_VOL_CTL, 2267 -84, 40, digital_gain), 2268 SOC_SINGLE_S8_TLV("RX5 Digital Volume", WCD9335_CDC_RX5_RX_VOL_CTL, 2269 -84, 40, digital_gain), 2270 SOC_SINGLE_S8_TLV("RX6 Digital Volume", WCD9335_CDC_RX6_RX_VOL_CTL, 2271 -84, 40, digital_gain), 2272 SOC_SINGLE_S8_TLV("RX7 Digital Volume", WCD9335_CDC_RX7_RX_VOL_CTL, 2273 -84, 40, digital_gain), 2274 SOC_SINGLE_S8_TLV("RX8 Digital Volume", WCD9335_CDC_RX8_RX_VOL_CTL, 2275 -84, 40, digital_gain), 2276 SOC_SINGLE_S8_TLV("RX0 Mix Digital Volume", WCD9335_CDC_RX0_RX_VOL_MIX_CTL, 2277 -84, 40, digital_gain), 2278 SOC_SINGLE_S8_TLV("RX1 Mix Digital Volume", WCD9335_CDC_RX1_RX_VOL_MIX_CTL, 2279 -84, 40, digital_gain), 2280 SOC_SINGLE_S8_TLV("RX2 Mix Digital Volume", WCD9335_CDC_RX2_RX_VOL_MIX_CTL, 2281 -84, 40, digital_gain), 2282 SOC_SINGLE_S8_TLV("RX3 Mix Digital Volume", WCD9335_CDC_RX3_RX_VOL_MIX_CTL, 2283 -84, 40, digital_gain), 2284 SOC_SINGLE_S8_TLV("RX4 Mix Digital Volume", WCD9335_CDC_RX4_RX_VOL_MIX_CTL, 2285 -84, 40, digital_gain), 2286 SOC_SINGLE_S8_TLV("RX5 Mix Digital Volume", WCD9335_CDC_RX5_RX_VOL_MIX_CTL, 2287 -84, 40, digital_gain), 2288 SOC_SINGLE_S8_TLV("RX6 Mix Digital Volume", WCD9335_CDC_RX6_RX_VOL_MIX_CTL, 2289 -84, 40, digital_gain), 2290 SOC_SINGLE_S8_TLV("RX7 Mix Digital Volume", WCD9335_CDC_RX7_RX_VOL_MIX_CTL, 2291 -84, 40, digital_gain), 2292 SOC_SINGLE_S8_TLV("RX8 Mix Digital Volume", WCD9335_CDC_RX8_RX_VOL_MIX_CTL, 2293 -84, 40, digital_gain), 2294 SOC_ENUM("RX INT0_1 HPF cut off", cf_int0_1_enum), 2295 SOC_ENUM("RX INT0_2 HPF cut off", cf_int0_2_enum), 2296 SOC_ENUM("RX INT1_1 HPF cut off", cf_int1_1_enum), 2297 SOC_ENUM("RX INT1_2 HPF cut off", cf_int1_2_enum), 2298 SOC_ENUM("RX INT2_1 HPF cut off", cf_int2_1_enum), 2299 SOC_ENUM("RX INT2_2 HPF cut off", cf_int2_2_enum), 2300 SOC_ENUM("RX INT3_1 HPF cut off", cf_int3_1_enum), 2301 SOC_ENUM("RX INT3_2 HPF cut off", cf_int3_2_enum), 2302 SOC_ENUM("RX INT4_1 HPF cut off", cf_int4_1_enum), 2303 SOC_ENUM("RX INT4_2 HPF cut off", cf_int4_2_enum), 2304 SOC_ENUM("RX INT5_1 HPF cut off", cf_int5_1_enum), 2305 SOC_ENUM("RX INT5_2 HPF cut off", cf_int5_2_enum), 2306 SOC_ENUM("RX INT6_1 HPF cut off", cf_int6_1_enum), 2307 SOC_ENUM("RX INT6_2 HPF cut off", cf_int6_2_enum), 2308 SOC_ENUM("RX INT7_1 HPF cut off", cf_int7_1_enum), 2309 SOC_ENUM("RX INT7_2 HPF cut off", cf_int7_2_enum), 2310 SOC_ENUM("RX INT8_1 HPF cut off", cf_int8_1_enum), 2311 SOC_ENUM("RX INT8_2 HPF cut off", cf_int8_2_enum), 2312 SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, COMPANDER_1, 1, 0, 2313 wcd9335_get_compander, wcd9335_set_compander), 2314 SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, COMPANDER_2, 1, 0, 2315 wcd9335_get_compander, wcd9335_set_compander), 2316 SOC_SINGLE_EXT("COMP3 Switch", SND_SOC_NOPM, COMPANDER_3, 1, 0, 2317 wcd9335_get_compander, wcd9335_set_compander), 2318 SOC_SINGLE_EXT("COMP4 Switch", SND_SOC_NOPM, COMPANDER_4, 1, 0, 2319 wcd9335_get_compander, wcd9335_set_compander), 2320 SOC_SINGLE_EXT("COMP5 Switch", SND_SOC_NOPM, COMPANDER_5, 1, 0, 2321 wcd9335_get_compander, wcd9335_set_compander), 2322 SOC_SINGLE_EXT("COMP6 Switch", SND_SOC_NOPM, COMPANDER_6, 1, 0, 2323 wcd9335_get_compander, wcd9335_set_compander), 2324 SOC_SINGLE_EXT("COMP7 Switch", SND_SOC_NOPM, COMPANDER_7, 1, 0, 2325 wcd9335_get_compander, wcd9335_set_compander), 2326 SOC_SINGLE_EXT("COMP8 Switch", SND_SOC_NOPM, COMPANDER_8, 1, 0, 2327 wcd9335_get_compander, wcd9335_set_compander), 2328 SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum, 2329 wcd9335_rx_hph_mode_get, wcd9335_rx_hph_mode_put), 2330 2331 /* Gain Controls */ 2332 SOC_SINGLE_TLV("EAR PA Volume", WCD9335_ANA_EAR, 4, 4, 1, 2333 ear_pa_gain), 2334 SOC_SINGLE_TLV("HPHL Volume", WCD9335_HPH_L_EN, 0, 20, 1, 2335 line_gain), 2336 SOC_SINGLE_TLV("HPHR Volume", WCD9335_HPH_R_EN, 0, 20, 1, 2337 line_gain), 2338 SOC_SINGLE_TLV("LINEOUT1 Volume", WCD9335_DIFF_LO_LO1_COMPANDER, 2339 3, 16, 1, line_gain), 2340 SOC_SINGLE_TLV("LINEOUT2 Volume", WCD9335_DIFF_LO_LO2_COMPANDER, 2341 3, 16, 1, line_gain), 2342 SOC_SINGLE_TLV("LINEOUT3 Volume", WCD9335_SE_LO_LO3_GAIN, 0, 20, 1, 2343 line_gain), 2344 SOC_SINGLE_TLV("LINEOUT4 Volume", WCD9335_SE_LO_LO4_GAIN, 0, 20, 1, 2345 line_gain), 2346 2347 SOC_SINGLE_TLV("ADC1 Volume", WCD9335_ANA_AMIC1, 0, 20, 0, 2348 analog_gain), 2349 SOC_SINGLE_TLV("ADC2 Volume", WCD9335_ANA_AMIC2, 0, 20, 0, 2350 analog_gain), 2351 SOC_SINGLE_TLV("ADC3 Volume", WCD9335_ANA_AMIC3, 0, 20, 0, 2352 analog_gain), 2353 SOC_SINGLE_TLV("ADC4 Volume", WCD9335_ANA_AMIC4, 0, 20, 0, 2354 analog_gain), 2355 SOC_SINGLE_TLV("ADC5 Volume", WCD9335_ANA_AMIC5, 0, 20, 0, 2356 analog_gain), 2357 SOC_SINGLE_TLV("ADC6 Volume", WCD9335_ANA_AMIC6, 0, 20, 0, 2358 analog_gain), 2359 2360 SOC_ENUM("TX0 HPF cut off", cf_dec0_enum), 2361 SOC_ENUM("TX1 HPF cut off", cf_dec1_enum), 2362 SOC_ENUM("TX2 HPF cut off", cf_dec2_enum), 2363 SOC_ENUM("TX3 HPF cut off", cf_dec3_enum), 2364 SOC_ENUM("TX4 HPF cut off", cf_dec4_enum), 2365 SOC_ENUM("TX5 HPF cut off", cf_dec5_enum), 2366 SOC_ENUM("TX6 HPF cut off", cf_dec6_enum), 2367 SOC_ENUM("TX7 HPF cut off", cf_dec7_enum), 2368 SOC_ENUM("TX8 HPF cut off", cf_dec8_enum), 2369 }; 2370 2371 static const struct snd_soc_dapm_route wcd9335_audio_map[] = { 2372 {"SLIM RX0 MUX", "AIF1_PB", "AIF1 PB"}, 2373 {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"}, 2374 {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"}, 2375 {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"}, 2376 {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"}, 2377 {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"}, 2378 {"SLIM RX6 MUX", "AIF1_PB", "AIF1 PB"}, 2379 {"SLIM RX7 MUX", "AIF1_PB", "AIF1 PB"}, 2380 2381 {"SLIM RX0 MUX", "AIF2_PB", "AIF2 PB"}, 2382 {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"}, 2383 {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"}, 2384 {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"}, 2385 {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"}, 2386 {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"}, 2387 {"SLIM RX6 MUX", "AIF2_PB", "AIF2 PB"}, 2388 {"SLIM RX7 MUX", "AIF2_PB", "AIF2 PB"}, 2389 2390 {"SLIM RX0 MUX", "AIF3_PB", "AIF3 PB"}, 2391 {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"}, 2392 {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"}, 2393 {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"}, 2394 {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"}, 2395 {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"}, 2396 {"SLIM RX6 MUX", "AIF3_PB", "AIF3 PB"}, 2397 {"SLIM RX7 MUX", "AIF3_PB", "AIF3 PB"}, 2398 2399 {"SLIM RX0 MUX", "AIF4_PB", "AIF4 PB"}, 2400 {"SLIM RX1 MUX", "AIF4_PB", "AIF4 PB"}, 2401 {"SLIM RX2 MUX", "AIF4_PB", "AIF4 PB"}, 2402 {"SLIM RX3 MUX", "AIF4_PB", "AIF4 PB"}, 2403 {"SLIM RX4 MUX", "AIF4_PB", "AIF4 PB"}, 2404 {"SLIM RX5 MUX", "AIF4_PB", "AIF4 PB"}, 2405 {"SLIM RX6 MUX", "AIF4_PB", "AIF4 PB"}, 2406 {"SLIM RX7 MUX", "AIF4_PB", "AIF4 PB"}, 2407 2408 {"SLIM RX0", NULL, "SLIM RX0 MUX"}, 2409 {"SLIM RX1", NULL, "SLIM RX1 MUX"}, 2410 {"SLIM RX2", NULL, "SLIM RX2 MUX"}, 2411 {"SLIM RX3", NULL, "SLIM RX3 MUX"}, 2412 {"SLIM RX4", NULL, "SLIM RX4 MUX"}, 2413 {"SLIM RX5", NULL, "SLIM RX5 MUX"}, 2414 {"SLIM RX6", NULL, "SLIM RX6 MUX"}, 2415 {"SLIM RX7", NULL, "SLIM RX7 MUX"}, 2416 2417 WCD9335_INTERPOLATOR_PATH(0), 2418 WCD9335_INTERPOLATOR_PATH(1), 2419 WCD9335_INTERPOLATOR_PATH(2), 2420 WCD9335_INTERPOLATOR_PATH(3), 2421 WCD9335_INTERPOLATOR_PATH(4), 2422 WCD9335_INTERPOLATOR_PATH(5), 2423 WCD9335_INTERPOLATOR_PATH(6), 2424 WCD9335_INTERPOLATOR_PATH(7), 2425 WCD9335_INTERPOLATOR_PATH(8), 2426 2427 /* EAR PA */ 2428 {"RX INT0 DEM MUX", "CLSH_DSM_OUT", "RX INT0 INTERP"}, 2429 {"RX INT0 DAC", NULL, "RX INT0 DEM MUX"}, 2430 {"RX INT0 DAC", NULL, "RX_BIAS"}, 2431 {"EAR PA", NULL, "RX INT0 DAC"}, 2432 {"EAR", NULL, "EAR PA"}, 2433 2434 /* HPHL */ 2435 {"RX INT1 DEM MUX", "CLSH_DSM_OUT", "RX INT1 INTERP"}, 2436 {"RX INT1 DAC", NULL, "RX INT1 DEM MUX"}, 2437 {"RX INT1 DAC", NULL, "RX_BIAS"}, 2438 {"HPHL PA", NULL, "RX INT1 DAC"}, 2439 {"HPHL", NULL, "HPHL PA"}, 2440 2441 /* HPHR */ 2442 {"RX INT2 DEM MUX", "CLSH_DSM_OUT", "RX INT2 INTERP"}, 2443 {"RX INT2 DAC", NULL, "RX INT2 DEM MUX"}, 2444 {"RX INT2 DAC", NULL, "RX_BIAS"}, 2445 {"HPHR PA", NULL, "RX INT2 DAC"}, 2446 {"HPHR", NULL, "HPHR PA"}, 2447 2448 /* LINEOUT1 */ 2449 {"RX INT3 DAC", NULL, "RX INT3 INTERP"}, 2450 {"RX INT3 DAC", NULL, "RX_BIAS"}, 2451 {"LINEOUT1 PA", NULL, "RX INT3 DAC"}, 2452 {"LINEOUT1", NULL, "LINEOUT1 PA"}, 2453 2454 /* LINEOUT2 */ 2455 {"RX INT4 DAC", NULL, "RX INT4 INTERP"}, 2456 {"RX INT4 DAC", NULL, "RX_BIAS"}, 2457 {"LINEOUT2 PA", NULL, "RX INT4 DAC"}, 2458 {"LINEOUT2", NULL, "LINEOUT2 PA"}, 2459 2460 /* LINEOUT3 */ 2461 {"RX INT5 DAC", NULL, "RX INT5 INTERP"}, 2462 {"RX INT5 DAC", NULL, "RX_BIAS"}, 2463 {"LINEOUT3 PA", NULL, "RX INT5 DAC"}, 2464 {"LINEOUT3", NULL, "LINEOUT3 PA"}, 2465 2466 /* LINEOUT4 */ 2467 {"RX INT6 DAC", NULL, "RX INT6 INTERP"}, 2468 {"RX INT6 DAC", NULL, "RX_BIAS"}, 2469 {"LINEOUT4 PA", NULL, "RX INT6 DAC"}, 2470 {"LINEOUT4", NULL, "LINEOUT4 PA"}, 2471 2472 /* SLIMBUS Connections */ 2473 {"AIF1 CAP", NULL, "AIF1_CAP Mixer"}, 2474 {"AIF2 CAP", NULL, "AIF2_CAP Mixer"}, 2475 {"AIF3 CAP", NULL, "AIF3_CAP Mixer"}, 2476 2477 /* ADC Mux */ 2478 WCD9335_ADC_MUX_PATH(0), 2479 WCD9335_ADC_MUX_PATH(1), 2480 WCD9335_ADC_MUX_PATH(2), 2481 WCD9335_ADC_MUX_PATH(3), 2482 WCD9335_ADC_MUX_PATH(4), 2483 WCD9335_ADC_MUX_PATH(5), 2484 WCD9335_ADC_MUX_PATH(6), 2485 WCD9335_ADC_MUX_PATH(7), 2486 WCD9335_ADC_MUX_PATH(8), 2487 2488 /* ADC Connections */ 2489 {"ADC1", NULL, "AMIC1"}, 2490 {"ADC2", NULL, "AMIC2"}, 2491 {"ADC3", NULL, "AMIC3"}, 2492 {"ADC4", NULL, "AMIC4"}, 2493 {"ADC5", NULL, "AMIC5"}, 2494 {"ADC6", NULL, "AMIC6"}, 2495 }; 2496 2497 static int wcd9335_micbias_control(struct snd_soc_component *component, 2498 int micb_num, int req, bool is_dapm) 2499 { 2500 struct wcd9335_codec *wcd = snd_soc_component_get_drvdata(component); 2501 int micb_index = micb_num - 1; 2502 u16 micb_reg; 2503 2504 if ((micb_index < 0) || (micb_index > WCD9335_MAX_MICBIAS - 1)) { 2505 dev_err(wcd->dev, "Invalid micbias index, micb_ind:%d\n", 2506 micb_index); 2507 return -EINVAL; 2508 } 2509 2510 switch (micb_num) { 2511 case MIC_BIAS_1: 2512 micb_reg = WCD9335_ANA_MICB1; 2513 break; 2514 case MIC_BIAS_2: 2515 micb_reg = WCD9335_ANA_MICB2; 2516 break; 2517 case MIC_BIAS_3: 2518 micb_reg = WCD9335_ANA_MICB3; 2519 break; 2520 case MIC_BIAS_4: 2521 micb_reg = WCD9335_ANA_MICB4; 2522 break; 2523 default: 2524 dev_err(component->dev, "%s: Invalid micbias number: %d\n", 2525 __func__, micb_num); 2526 return -EINVAL; 2527 } 2528 2529 switch (req) { 2530 case MICB_PULLUP_ENABLE: 2531 wcd->pullup_ref[micb_index]++; 2532 if ((wcd->pullup_ref[micb_index] == 1) && 2533 (wcd->micb_ref[micb_index] == 0)) 2534 snd_soc_component_update_bits(component, micb_reg, 2535 0xC0, 0x80); 2536 break; 2537 case MICB_PULLUP_DISABLE: 2538 wcd->pullup_ref[micb_index]--; 2539 if ((wcd->pullup_ref[micb_index] == 0) && 2540 (wcd->micb_ref[micb_index] == 0)) 2541 snd_soc_component_update_bits(component, micb_reg, 2542 0xC0, 0x00); 2543 break; 2544 case MICB_ENABLE: 2545 wcd->micb_ref[micb_index]++; 2546 if (wcd->micb_ref[micb_index] == 1) 2547 snd_soc_component_update_bits(component, micb_reg, 2548 0xC0, 0x40); 2549 break; 2550 case MICB_DISABLE: 2551 wcd->micb_ref[micb_index]--; 2552 if ((wcd->micb_ref[micb_index] == 0) && 2553 (wcd->pullup_ref[micb_index] > 0)) 2554 snd_soc_component_update_bits(component, micb_reg, 2555 0xC0, 0x80); 2556 else if ((wcd->micb_ref[micb_index] == 0) && 2557 (wcd->pullup_ref[micb_index] == 0)) { 2558 snd_soc_component_update_bits(component, micb_reg, 2559 0xC0, 0x00); 2560 } 2561 break; 2562 } 2563 2564 return 0; 2565 } 2566 2567 static int __wcd9335_codec_enable_micbias(struct snd_soc_dapm_widget *w, 2568 int event) 2569 { 2570 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 2571 int micb_num; 2572 2573 if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1"))) 2574 micb_num = MIC_BIAS_1; 2575 else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2"))) 2576 micb_num = MIC_BIAS_2; 2577 else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3"))) 2578 micb_num = MIC_BIAS_3; 2579 else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4"))) 2580 micb_num = MIC_BIAS_4; 2581 else 2582 return -EINVAL; 2583 2584 switch (event) { 2585 case SND_SOC_DAPM_PRE_PMU: 2586 /* 2587 * MIC BIAS can also be requested by MBHC, 2588 * so use ref count to handle micbias pullup 2589 * and enable requests 2590 */ 2591 wcd9335_micbias_control(comp, micb_num, MICB_ENABLE, true); 2592 break; 2593 case SND_SOC_DAPM_POST_PMU: 2594 /* wait for cnp time */ 2595 usleep_range(1000, 1100); 2596 break; 2597 case SND_SOC_DAPM_POST_PMD: 2598 wcd9335_micbias_control(comp, micb_num, MICB_DISABLE, true); 2599 break; 2600 } 2601 2602 return 0; 2603 } 2604 2605 static int wcd9335_codec_enable_micbias(struct snd_soc_dapm_widget *w, 2606 struct snd_kcontrol *kc, int event) 2607 { 2608 return __wcd9335_codec_enable_micbias(w, event); 2609 } 2610 2611 static void wcd9335_codec_set_tx_hold(struct snd_soc_component *comp, 2612 u16 amic_reg, bool set) 2613 { 2614 u8 mask = 0x20; 2615 u8 val; 2616 2617 if (amic_reg == WCD9335_ANA_AMIC1 || amic_reg == WCD9335_ANA_AMIC3 || 2618 amic_reg == WCD9335_ANA_AMIC5) 2619 mask = 0x40; 2620 2621 val = set ? mask : 0x00; 2622 2623 switch (amic_reg) { 2624 case WCD9335_ANA_AMIC1: 2625 case WCD9335_ANA_AMIC2: 2626 snd_soc_component_update_bits(comp, WCD9335_ANA_AMIC2, mask, 2627 val); 2628 break; 2629 case WCD9335_ANA_AMIC3: 2630 case WCD9335_ANA_AMIC4: 2631 snd_soc_component_update_bits(comp, WCD9335_ANA_AMIC4, mask, 2632 val); 2633 break; 2634 case WCD9335_ANA_AMIC5: 2635 case WCD9335_ANA_AMIC6: 2636 snd_soc_component_update_bits(comp, WCD9335_ANA_AMIC6, mask, 2637 val); 2638 break; 2639 default: 2640 dev_err(comp->dev, "%s: invalid amic: %d\n", 2641 __func__, amic_reg); 2642 break; 2643 } 2644 } 2645 2646 static int wcd9335_codec_enable_adc(struct snd_soc_dapm_widget *w, 2647 struct snd_kcontrol *kc, int event) 2648 { 2649 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 2650 2651 switch (event) { 2652 case SND_SOC_DAPM_PRE_PMU: 2653 wcd9335_codec_set_tx_hold(comp, w->reg, true); 2654 break; 2655 default: 2656 break; 2657 } 2658 2659 return 0; 2660 } 2661 2662 static int wcd9335_codec_find_amic_input(struct snd_soc_component *comp, 2663 int adc_mux_n) 2664 { 2665 int mux_sel, reg, mreg; 2666 2667 if (adc_mux_n < 0 || adc_mux_n > WCD9335_MAX_VALID_ADC_MUX || 2668 adc_mux_n == WCD9335_INVALID_ADC_MUX) 2669 return 0; 2670 2671 /* Check whether adc mux input is AMIC or DMIC */ 2672 if (adc_mux_n < 4) { 2673 reg = WCD9335_CDC_TX_INP_MUX_ADC_MUX0_CFG1 + 2 * adc_mux_n; 2674 mreg = WCD9335_CDC_TX_INP_MUX_ADC_MUX0_CFG0 + 2 * adc_mux_n; 2675 mux_sel = snd_soc_component_read(comp, reg) & 0x3; 2676 } else { 2677 reg = WCD9335_CDC_TX_INP_MUX_ADC_MUX4_CFG0 + adc_mux_n - 4; 2678 mreg = reg; 2679 mux_sel = snd_soc_component_read(comp, reg) >> 6; 2680 } 2681 2682 if (mux_sel != WCD9335_CDC_TX_INP_MUX_SEL_AMIC) 2683 return 0; 2684 2685 return snd_soc_component_read(comp, mreg) & 0x07; 2686 } 2687 2688 static u16 wcd9335_codec_get_amic_pwlvl_reg(struct snd_soc_component *comp, 2689 int amic) 2690 { 2691 u16 pwr_level_reg = 0; 2692 2693 switch (amic) { 2694 case 1: 2695 case 2: 2696 pwr_level_reg = WCD9335_ANA_AMIC1; 2697 break; 2698 2699 case 3: 2700 case 4: 2701 pwr_level_reg = WCD9335_ANA_AMIC3; 2702 break; 2703 2704 case 5: 2705 case 6: 2706 pwr_level_reg = WCD9335_ANA_AMIC5; 2707 break; 2708 default: 2709 dev_err(comp->dev, "invalid amic: %d\n", amic); 2710 break; 2711 } 2712 2713 return pwr_level_reg; 2714 } 2715 2716 static int wcd9335_codec_enable_dec(struct snd_soc_dapm_widget *w, 2717 struct snd_kcontrol *kc, int event) 2718 { 2719 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 2720 unsigned int decimator; 2721 char *dec_adc_mux_name = NULL; 2722 char *widget_name = NULL; 2723 char *wname; 2724 int ret = 0, amic_n; 2725 u16 tx_vol_ctl_reg, pwr_level_reg = 0, dec_cfg_reg, hpf_gate_reg; 2726 u16 tx_gain_ctl_reg; 2727 char *dec; 2728 u8 hpf_coff_freq; 2729 2730 widget_name = kmemdup_nul(w->name, 15, GFP_KERNEL); 2731 if (!widget_name) 2732 return -ENOMEM; 2733 2734 wname = widget_name; 2735 dec_adc_mux_name = strsep(&widget_name, " "); 2736 if (!dec_adc_mux_name) { 2737 dev_err(comp->dev, "%s: Invalid decimator = %s\n", 2738 __func__, w->name); 2739 ret = -EINVAL; 2740 goto out; 2741 } 2742 dec_adc_mux_name = widget_name; 2743 2744 dec = strpbrk(dec_adc_mux_name, "012345678"); 2745 if (!dec) { 2746 dev_err(comp->dev, "%s: decimator index not found\n", 2747 __func__); 2748 ret = -EINVAL; 2749 goto out; 2750 } 2751 2752 ret = kstrtouint(dec, 10, &decimator); 2753 if (ret < 0) { 2754 dev_err(comp->dev, "%s: Invalid decimator = %s\n", 2755 __func__, wname); 2756 ret = -EINVAL; 2757 goto out; 2758 } 2759 2760 tx_vol_ctl_reg = WCD9335_CDC_TX0_TX_PATH_CTL + 16 * decimator; 2761 hpf_gate_reg = WCD9335_CDC_TX0_TX_PATH_SEC2 + 16 * decimator; 2762 dec_cfg_reg = WCD9335_CDC_TX0_TX_PATH_CFG0 + 16 * decimator; 2763 tx_gain_ctl_reg = WCD9335_CDC_TX0_TX_VOL_CTL + 16 * decimator; 2764 2765 switch (event) { 2766 case SND_SOC_DAPM_PRE_PMU: 2767 amic_n = wcd9335_codec_find_amic_input(comp, decimator); 2768 if (amic_n) 2769 pwr_level_reg = wcd9335_codec_get_amic_pwlvl_reg(comp, 2770 amic_n); 2771 2772 if (pwr_level_reg) { 2773 switch ((snd_soc_component_read(comp, pwr_level_reg) & 2774 WCD9335_AMIC_PWR_LVL_MASK) >> 2775 WCD9335_AMIC_PWR_LVL_SHIFT) { 2776 case WCD9335_AMIC_PWR_LEVEL_LP: 2777 snd_soc_component_update_bits(comp, dec_cfg_reg, 2778 WCD9335_DEC_PWR_LVL_MASK, 2779 WCD9335_DEC_PWR_LVL_LP); 2780 break; 2781 2782 case WCD9335_AMIC_PWR_LEVEL_HP: 2783 snd_soc_component_update_bits(comp, dec_cfg_reg, 2784 WCD9335_DEC_PWR_LVL_MASK, 2785 WCD9335_DEC_PWR_LVL_HP); 2786 break; 2787 case WCD9335_AMIC_PWR_LEVEL_DEFAULT: 2788 default: 2789 snd_soc_component_update_bits(comp, dec_cfg_reg, 2790 WCD9335_DEC_PWR_LVL_MASK, 2791 WCD9335_DEC_PWR_LVL_DF); 2792 break; 2793 } 2794 } 2795 hpf_coff_freq = (snd_soc_component_read(comp, dec_cfg_reg) & 2796 TX_HPF_CUT_OFF_FREQ_MASK) >> 5; 2797 2798 if (hpf_coff_freq != CF_MIN_3DB_150HZ) 2799 snd_soc_component_update_bits(comp, dec_cfg_reg, 2800 TX_HPF_CUT_OFF_FREQ_MASK, 2801 CF_MIN_3DB_150HZ << 5); 2802 /* Enable TX PGA Mute */ 2803 snd_soc_component_update_bits(comp, tx_vol_ctl_reg, 2804 0x10, 0x10); 2805 /* Enable APC */ 2806 snd_soc_component_update_bits(comp, dec_cfg_reg, 0x08, 0x08); 2807 break; 2808 case SND_SOC_DAPM_POST_PMU: 2809 snd_soc_component_update_bits(comp, hpf_gate_reg, 0x01, 0x00); 2810 2811 if (decimator == 0) { 2812 snd_soc_component_write(comp, 2813 WCD9335_MBHC_ZDET_RAMP_CTL, 0x83); 2814 snd_soc_component_write(comp, 2815 WCD9335_MBHC_ZDET_RAMP_CTL, 0xA3); 2816 snd_soc_component_write(comp, 2817 WCD9335_MBHC_ZDET_RAMP_CTL, 0x83); 2818 snd_soc_component_write(comp, 2819 WCD9335_MBHC_ZDET_RAMP_CTL, 0x03); 2820 } 2821 2822 snd_soc_component_update_bits(comp, hpf_gate_reg, 2823 0x01, 0x01); 2824 snd_soc_component_update_bits(comp, tx_vol_ctl_reg, 2825 0x10, 0x00); 2826 snd_soc_component_write(comp, tx_gain_ctl_reg, 2827 snd_soc_component_read(comp, tx_gain_ctl_reg)); 2828 break; 2829 case SND_SOC_DAPM_PRE_PMD: 2830 hpf_coff_freq = (snd_soc_component_read(comp, dec_cfg_reg) & 2831 TX_HPF_CUT_OFF_FREQ_MASK) >> 5; 2832 snd_soc_component_update_bits(comp, tx_vol_ctl_reg, 0x10, 0x10); 2833 snd_soc_component_update_bits(comp, dec_cfg_reg, 0x08, 0x00); 2834 if (hpf_coff_freq != CF_MIN_3DB_150HZ) { 2835 snd_soc_component_update_bits(comp, dec_cfg_reg, 2836 TX_HPF_CUT_OFF_FREQ_MASK, 2837 hpf_coff_freq << 5); 2838 } 2839 break; 2840 case SND_SOC_DAPM_POST_PMD: 2841 snd_soc_component_update_bits(comp, tx_vol_ctl_reg, 0x10, 0x00); 2842 break; 2843 } 2844 out: 2845 kfree(wname); 2846 return ret; 2847 } 2848 2849 static u8 wcd9335_get_dmic_clk_val(struct snd_soc_component *component, 2850 u32 mclk_rate, u32 dmic_clk_rate) 2851 { 2852 u32 div_factor; 2853 u8 dmic_ctl_val; 2854 2855 dev_err(component->dev, 2856 "%s: mclk_rate = %d, dmic_sample_rate = %d\n", 2857 __func__, mclk_rate, dmic_clk_rate); 2858 2859 /* Default value to return in case of error */ 2860 if (mclk_rate == WCD9335_MCLK_CLK_9P6MHZ) 2861 dmic_ctl_val = WCD9335_DMIC_CLK_DIV_2; 2862 else 2863 dmic_ctl_val = WCD9335_DMIC_CLK_DIV_3; 2864 2865 if (dmic_clk_rate == 0) { 2866 dev_err(component->dev, 2867 "%s: dmic_sample_rate cannot be 0\n", 2868 __func__); 2869 goto done; 2870 } 2871 2872 div_factor = mclk_rate / dmic_clk_rate; 2873 switch (div_factor) { 2874 case 2: 2875 dmic_ctl_val = WCD9335_DMIC_CLK_DIV_2; 2876 break; 2877 case 3: 2878 dmic_ctl_val = WCD9335_DMIC_CLK_DIV_3; 2879 break; 2880 case 4: 2881 dmic_ctl_val = WCD9335_DMIC_CLK_DIV_4; 2882 break; 2883 case 6: 2884 dmic_ctl_val = WCD9335_DMIC_CLK_DIV_6; 2885 break; 2886 case 8: 2887 dmic_ctl_val = WCD9335_DMIC_CLK_DIV_8; 2888 break; 2889 case 16: 2890 dmic_ctl_val = WCD9335_DMIC_CLK_DIV_16; 2891 break; 2892 default: 2893 dev_err(component->dev, 2894 "%s: Invalid div_factor %u, clk_rate(%u), dmic_rate(%u)\n", 2895 __func__, div_factor, mclk_rate, dmic_clk_rate); 2896 break; 2897 } 2898 2899 done: 2900 return dmic_ctl_val; 2901 } 2902 2903 static int wcd9335_codec_enable_dmic(struct snd_soc_dapm_widget *w, 2904 struct snd_kcontrol *kc, int event) 2905 { 2906 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 2907 struct wcd9335_codec *wcd = snd_soc_component_get_drvdata(comp); 2908 u8 dmic_clk_en = 0x01; 2909 u16 dmic_clk_reg; 2910 s32 *dmic_clk_cnt; 2911 u8 dmic_rate_val, dmic_rate_shift = 1; 2912 unsigned int dmic; 2913 int ret; 2914 char *wname; 2915 2916 wname = strpbrk(w->name, "012345"); 2917 if (!wname) { 2918 dev_err(comp->dev, "%s: widget not found\n", __func__); 2919 return -EINVAL; 2920 } 2921 2922 ret = kstrtouint(wname, 10, &dmic); 2923 if (ret < 0) { 2924 dev_err(comp->dev, "%s: Invalid DMIC line on the codec\n", 2925 __func__); 2926 return -EINVAL; 2927 } 2928 2929 switch (dmic) { 2930 case 0: 2931 case 1: 2932 dmic_clk_cnt = &(wcd->dmic_0_1_clk_cnt); 2933 dmic_clk_reg = WCD9335_CPE_SS_DMIC0_CTL; 2934 break; 2935 case 2: 2936 case 3: 2937 dmic_clk_cnt = &(wcd->dmic_2_3_clk_cnt); 2938 dmic_clk_reg = WCD9335_CPE_SS_DMIC1_CTL; 2939 break; 2940 case 4: 2941 case 5: 2942 dmic_clk_cnt = &(wcd->dmic_4_5_clk_cnt); 2943 dmic_clk_reg = WCD9335_CPE_SS_DMIC2_CTL; 2944 break; 2945 default: 2946 dev_err(comp->dev, "%s: Invalid DMIC Selection\n", 2947 __func__); 2948 return -EINVAL; 2949 } 2950 2951 switch (event) { 2952 case SND_SOC_DAPM_PRE_PMU: 2953 dmic_rate_val = 2954 wcd9335_get_dmic_clk_val(comp, 2955 wcd->mclk_rate, 2956 wcd->dmic_sample_rate); 2957 2958 (*dmic_clk_cnt)++; 2959 if (*dmic_clk_cnt == 1) { 2960 snd_soc_component_update_bits(comp, dmic_clk_reg, 2961 0x07 << dmic_rate_shift, 2962 dmic_rate_val << dmic_rate_shift); 2963 snd_soc_component_update_bits(comp, dmic_clk_reg, 2964 dmic_clk_en, dmic_clk_en); 2965 } 2966 2967 break; 2968 case SND_SOC_DAPM_POST_PMD: 2969 dmic_rate_val = 2970 wcd9335_get_dmic_clk_val(comp, 2971 wcd->mclk_rate, 2972 wcd->mad_dmic_sample_rate); 2973 (*dmic_clk_cnt)--; 2974 if (*dmic_clk_cnt == 0) { 2975 snd_soc_component_update_bits(comp, dmic_clk_reg, 2976 dmic_clk_en, 0); 2977 snd_soc_component_update_bits(comp, dmic_clk_reg, 2978 0x07 << dmic_rate_shift, 2979 dmic_rate_val << dmic_rate_shift); 2980 } 2981 break; 2982 } 2983 2984 return 0; 2985 } 2986 2987 static void wcd9335_codec_enable_int_port(struct wcd_slim_codec_dai_data *dai, 2988 struct snd_soc_component *component) 2989 { 2990 int port_num = 0; 2991 unsigned short reg = 0; 2992 unsigned int val = 0; 2993 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); 2994 struct wcd9335_slim_ch *ch; 2995 2996 list_for_each_entry(ch, &dai->slim_ch_list, list) { 2997 if (ch->port >= WCD9335_RX_START) { 2998 port_num = ch->port - WCD9335_RX_START; 2999 reg = WCD9335_SLIM_PGD_PORT_INT_EN0 + (port_num / 8); 3000 } else { 3001 port_num = ch->port; 3002 reg = WCD9335_SLIM_PGD_PORT_INT_TX_EN0 + (port_num / 8); 3003 } 3004 3005 regmap_read(wcd->if_regmap, reg, &val); 3006 if (!(val & BIT(port_num % 8))) 3007 regmap_write(wcd->if_regmap, reg, 3008 val | BIT(port_num % 8)); 3009 } 3010 } 3011 3012 static int wcd9335_codec_enable_slim(struct snd_soc_dapm_widget *w, 3013 struct snd_kcontrol *kc, 3014 int event) 3015 { 3016 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 3017 struct wcd9335_codec *wcd = snd_soc_component_get_drvdata(comp); 3018 struct wcd_slim_codec_dai_data *dai = &wcd->dai[w->shift]; 3019 3020 switch (event) { 3021 case SND_SOC_DAPM_POST_PMU: 3022 wcd9335_codec_enable_int_port(dai, comp); 3023 break; 3024 case SND_SOC_DAPM_POST_PMD: 3025 kfree(dai->sconfig.chs); 3026 3027 break; 3028 } 3029 3030 return 0; 3031 } 3032 3033 static int wcd9335_codec_enable_mix_path(struct snd_soc_dapm_widget *w, 3034 struct snd_kcontrol *kc, int event) 3035 { 3036 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 3037 u16 gain_reg; 3038 int val = 0; 3039 3040 switch (w->reg) { 3041 case WCD9335_CDC_RX0_RX_PATH_MIX_CTL: 3042 gain_reg = WCD9335_CDC_RX0_RX_VOL_MIX_CTL; 3043 break; 3044 case WCD9335_CDC_RX1_RX_PATH_MIX_CTL: 3045 gain_reg = WCD9335_CDC_RX1_RX_VOL_MIX_CTL; 3046 break; 3047 case WCD9335_CDC_RX2_RX_PATH_MIX_CTL: 3048 gain_reg = WCD9335_CDC_RX2_RX_VOL_MIX_CTL; 3049 break; 3050 case WCD9335_CDC_RX3_RX_PATH_MIX_CTL: 3051 gain_reg = WCD9335_CDC_RX3_RX_VOL_MIX_CTL; 3052 break; 3053 case WCD9335_CDC_RX4_RX_PATH_MIX_CTL: 3054 gain_reg = WCD9335_CDC_RX4_RX_VOL_MIX_CTL; 3055 break; 3056 case WCD9335_CDC_RX5_RX_PATH_MIX_CTL: 3057 gain_reg = WCD9335_CDC_RX5_RX_VOL_MIX_CTL; 3058 break; 3059 case WCD9335_CDC_RX6_RX_PATH_MIX_CTL: 3060 gain_reg = WCD9335_CDC_RX6_RX_VOL_MIX_CTL; 3061 break; 3062 case WCD9335_CDC_RX7_RX_PATH_MIX_CTL: 3063 gain_reg = WCD9335_CDC_RX7_RX_VOL_MIX_CTL; 3064 break; 3065 case WCD9335_CDC_RX8_RX_PATH_MIX_CTL: 3066 gain_reg = WCD9335_CDC_RX8_RX_VOL_MIX_CTL; 3067 break; 3068 default: 3069 dev_err(comp->dev, "%s: No gain register avail for %s\n", 3070 __func__, w->name); 3071 return 0; 3072 } 3073 3074 switch (event) { 3075 case SND_SOC_DAPM_POST_PMU: 3076 val = snd_soc_component_read(comp, gain_reg); 3077 snd_soc_component_write(comp, gain_reg, val); 3078 break; 3079 case SND_SOC_DAPM_POST_PMD: 3080 break; 3081 } 3082 3083 return 0; 3084 } 3085 3086 static u16 wcd9335_interp_get_primary_reg(u16 reg, u16 *ind) 3087 { 3088 u16 prim_int_reg = WCD9335_CDC_RX0_RX_PATH_CTL; 3089 3090 switch (reg) { 3091 case WCD9335_CDC_RX0_RX_PATH_CTL: 3092 case WCD9335_CDC_RX0_RX_PATH_MIX_CTL: 3093 prim_int_reg = WCD9335_CDC_RX0_RX_PATH_CTL; 3094 *ind = 0; 3095 break; 3096 case WCD9335_CDC_RX1_RX_PATH_CTL: 3097 case WCD9335_CDC_RX1_RX_PATH_MIX_CTL: 3098 prim_int_reg = WCD9335_CDC_RX1_RX_PATH_CTL; 3099 *ind = 1; 3100 break; 3101 case WCD9335_CDC_RX2_RX_PATH_CTL: 3102 case WCD9335_CDC_RX2_RX_PATH_MIX_CTL: 3103 prim_int_reg = WCD9335_CDC_RX2_RX_PATH_CTL; 3104 *ind = 2; 3105 break; 3106 case WCD9335_CDC_RX3_RX_PATH_CTL: 3107 case WCD9335_CDC_RX3_RX_PATH_MIX_CTL: 3108 prim_int_reg = WCD9335_CDC_RX3_RX_PATH_CTL; 3109 *ind = 3; 3110 break; 3111 case WCD9335_CDC_RX4_RX_PATH_CTL: 3112 case WCD9335_CDC_RX4_RX_PATH_MIX_CTL: 3113 prim_int_reg = WCD9335_CDC_RX4_RX_PATH_CTL; 3114 *ind = 4; 3115 break; 3116 case WCD9335_CDC_RX5_RX_PATH_CTL: 3117 case WCD9335_CDC_RX5_RX_PATH_MIX_CTL: 3118 prim_int_reg = WCD9335_CDC_RX5_RX_PATH_CTL; 3119 *ind = 5; 3120 break; 3121 case WCD9335_CDC_RX6_RX_PATH_CTL: 3122 case WCD9335_CDC_RX6_RX_PATH_MIX_CTL: 3123 prim_int_reg = WCD9335_CDC_RX6_RX_PATH_CTL; 3124 *ind = 6; 3125 break; 3126 case WCD9335_CDC_RX7_RX_PATH_CTL: 3127 case WCD9335_CDC_RX7_RX_PATH_MIX_CTL: 3128 prim_int_reg = WCD9335_CDC_RX7_RX_PATH_CTL; 3129 *ind = 7; 3130 break; 3131 case WCD9335_CDC_RX8_RX_PATH_CTL: 3132 case WCD9335_CDC_RX8_RX_PATH_MIX_CTL: 3133 prim_int_reg = WCD9335_CDC_RX8_RX_PATH_CTL; 3134 *ind = 8; 3135 break; 3136 } 3137 3138 return prim_int_reg; 3139 } 3140 3141 static void wcd9335_codec_hd2_control(struct snd_soc_component *component, 3142 u16 prim_int_reg, int event) 3143 { 3144 u16 hd2_scale_reg; 3145 u16 hd2_enable_reg = 0; 3146 3147 if (prim_int_reg == WCD9335_CDC_RX1_RX_PATH_CTL) { 3148 hd2_scale_reg = WCD9335_CDC_RX1_RX_PATH_SEC3; 3149 hd2_enable_reg = WCD9335_CDC_RX1_RX_PATH_CFG0; 3150 } 3151 if (prim_int_reg == WCD9335_CDC_RX2_RX_PATH_CTL) { 3152 hd2_scale_reg = WCD9335_CDC_RX2_RX_PATH_SEC3; 3153 hd2_enable_reg = WCD9335_CDC_RX2_RX_PATH_CFG0; 3154 } 3155 3156 if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) { 3157 snd_soc_component_update_bits(component, hd2_scale_reg, 3158 WCD9335_CDC_RX_PATH_SEC_HD2_ALPHA_MASK, 3159 WCD9335_CDC_RX_PATH_SEC_HD2_ALPHA_0P2500); 3160 snd_soc_component_update_bits(component, hd2_scale_reg, 3161 WCD9335_CDC_RX_PATH_SEC_HD2_SCALE_MASK, 3162 WCD9335_CDC_RX_PATH_SEC_HD2_SCALE_2); 3163 snd_soc_component_update_bits(component, hd2_enable_reg, 3164 WCD9335_CDC_RX_PATH_CFG_HD2_EN_MASK, 3165 WCD9335_CDC_RX_PATH_CFG_HD2_ENABLE); 3166 } 3167 3168 if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) { 3169 snd_soc_component_update_bits(component, hd2_enable_reg, 3170 WCD9335_CDC_RX_PATH_CFG_HD2_EN_MASK, 3171 WCD9335_CDC_RX_PATH_CFG_HD2_DISABLE); 3172 snd_soc_component_update_bits(component, hd2_scale_reg, 3173 WCD9335_CDC_RX_PATH_SEC_HD2_SCALE_MASK, 3174 WCD9335_CDC_RX_PATH_SEC_HD2_SCALE_1); 3175 snd_soc_component_update_bits(component, hd2_scale_reg, 3176 WCD9335_CDC_RX_PATH_SEC_HD2_ALPHA_MASK, 3177 WCD9335_CDC_RX_PATH_SEC_HD2_ALPHA_0P0000); 3178 } 3179 } 3180 3181 static int wcd9335_codec_enable_prim_interpolator( 3182 struct snd_soc_component *comp, 3183 u16 reg, int event) 3184 { 3185 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); 3186 u16 ind = 0; 3187 int prim_int_reg = wcd9335_interp_get_primary_reg(reg, &ind); 3188 3189 switch (event) { 3190 case SND_SOC_DAPM_PRE_PMU: 3191 wcd->prim_int_users[ind]++; 3192 if (wcd->prim_int_users[ind] == 1) { 3193 snd_soc_component_update_bits(comp, prim_int_reg, 3194 WCD9335_CDC_RX_PGA_MUTE_EN_MASK, 3195 WCD9335_CDC_RX_PGA_MUTE_ENABLE); 3196 wcd9335_codec_hd2_control(comp, prim_int_reg, event); 3197 snd_soc_component_update_bits(comp, prim_int_reg, 3198 WCD9335_CDC_RX_CLK_EN_MASK, 3199 WCD9335_CDC_RX_CLK_ENABLE); 3200 } 3201 3202 if ((reg != prim_int_reg) && 3203 ((snd_soc_component_read(comp, prim_int_reg)) & 3204 WCD9335_CDC_RX_PGA_MUTE_EN_MASK)) 3205 snd_soc_component_update_bits(comp, reg, 3206 WCD9335_CDC_RX_PGA_MUTE_EN_MASK, 3207 WCD9335_CDC_RX_PGA_MUTE_ENABLE); 3208 break; 3209 case SND_SOC_DAPM_POST_PMD: 3210 wcd->prim_int_users[ind]--; 3211 if (wcd->prim_int_users[ind] == 0) { 3212 snd_soc_component_update_bits(comp, prim_int_reg, 3213 WCD9335_CDC_RX_CLK_EN_MASK, 3214 WCD9335_CDC_RX_CLK_DISABLE); 3215 snd_soc_component_update_bits(comp, prim_int_reg, 3216 WCD9335_CDC_RX_RESET_MASK, 3217 WCD9335_CDC_RX_RESET_ENABLE); 3218 snd_soc_component_update_bits(comp, prim_int_reg, 3219 WCD9335_CDC_RX_RESET_MASK, 3220 WCD9335_CDC_RX_RESET_DISABLE); 3221 wcd9335_codec_hd2_control(comp, prim_int_reg, event); 3222 } 3223 break; 3224 } 3225 3226 return 0; 3227 } 3228 3229 static int wcd9335_config_compander(struct snd_soc_component *component, 3230 int interp_n, int event) 3231 { 3232 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); 3233 int comp; 3234 u16 comp_ctl0_reg, rx_path_cfg0_reg; 3235 3236 /* EAR does not have compander */ 3237 if (!interp_n) 3238 return 0; 3239 3240 comp = interp_n - 1; 3241 if (!wcd->comp_enabled[comp]) 3242 return 0; 3243 3244 comp_ctl0_reg = WCD9335_CDC_COMPANDER1_CTL(comp); 3245 rx_path_cfg0_reg = WCD9335_CDC_RX1_RX_PATH_CFG(comp); 3246 3247 if (SND_SOC_DAPM_EVENT_ON(event)) { 3248 /* Enable Compander Clock */ 3249 snd_soc_component_update_bits(component, comp_ctl0_reg, 3250 WCD9335_CDC_COMPANDER_CLK_EN_MASK, 3251 WCD9335_CDC_COMPANDER_CLK_ENABLE); 3252 /* Reset comander */ 3253 snd_soc_component_update_bits(component, comp_ctl0_reg, 3254 WCD9335_CDC_COMPANDER_SOFT_RST_MASK, 3255 WCD9335_CDC_COMPANDER_SOFT_RST_ENABLE); 3256 snd_soc_component_update_bits(component, comp_ctl0_reg, 3257 WCD9335_CDC_COMPANDER_SOFT_RST_MASK, 3258 WCD9335_CDC_COMPANDER_SOFT_RST_DISABLE); 3259 /* Enables DRE in this path */ 3260 snd_soc_component_update_bits(component, rx_path_cfg0_reg, 3261 WCD9335_CDC_RX_PATH_CFG_CMP_EN_MASK, 3262 WCD9335_CDC_RX_PATH_CFG_CMP_ENABLE); 3263 } 3264 3265 if (SND_SOC_DAPM_EVENT_OFF(event)) { 3266 snd_soc_component_update_bits(component, comp_ctl0_reg, 3267 WCD9335_CDC_COMPANDER_HALT_MASK, 3268 WCD9335_CDC_COMPANDER_HALT); 3269 snd_soc_component_update_bits(component, rx_path_cfg0_reg, 3270 WCD9335_CDC_RX_PATH_CFG_CMP_EN_MASK, 3271 WCD9335_CDC_RX_PATH_CFG_CMP_DISABLE); 3272 3273 snd_soc_component_update_bits(component, comp_ctl0_reg, 3274 WCD9335_CDC_COMPANDER_SOFT_RST_MASK, 3275 WCD9335_CDC_COMPANDER_SOFT_RST_ENABLE); 3276 snd_soc_component_update_bits(component, comp_ctl0_reg, 3277 WCD9335_CDC_COMPANDER_SOFT_RST_MASK, 3278 WCD9335_CDC_COMPANDER_SOFT_RST_DISABLE); 3279 snd_soc_component_update_bits(component, comp_ctl0_reg, 3280 WCD9335_CDC_COMPANDER_CLK_EN_MASK, 3281 WCD9335_CDC_COMPANDER_CLK_DISABLE); 3282 snd_soc_component_update_bits(component, comp_ctl0_reg, 3283 WCD9335_CDC_COMPANDER_HALT_MASK, 3284 WCD9335_CDC_COMPANDER_NOHALT); 3285 } 3286 3287 return 0; 3288 } 3289 3290 static int wcd9335_codec_enable_interpolator(struct snd_soc_dapm_widget *w, 3291 struct snd_kcontrol *kc, int event) 3292 { 3293 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 3294 u16 gain_reg; 3295 u16 reg; 3296 int val; 3297 3298 if (!(snd_soc_dapm_widget_name_cmp(w, "RX INT0 INTERP"))) { 3299 reg = WCD9335_CDC_RX0_RX_PATH_CTL; 3300 gain_reg = WCD9335_CDC_RX0_RX_VOL_CTL; 3301 } else if (!(snd_soc_dapm_widget_name_cmp(w, "RX INT1 INTERP"))) { 3302 reg = WCD9335_CDC_RX1_RX_PATH_CTL; 3303 gain_reg = WCD9335_CDC_RX1_RX_VOL_CTL; 3304 } else if (!(snd_soc_dapm_widget_name_cmp(w, "RX INT2 INTERP"))) { 3305 reg = WCD9335_CDC_RX2_RX_PATH_CTL; 3306 gain_reg = WCD9335_CDC_RX2_RX_VOL_CTL; 3307 } else if (!(snd_soc_dapm_widget_name_cmp(w, "RX INT3 INTERP"))) { 3308 reg = WCD9335_CDC_RX3_RX_PATH_CTL; 3309 gain_reg = WCD9335_CDC_RX3_RX_VOL_CTL; 3310 } else if (!(snd_soc_dapm_widget_name_cmp(w, "RX INT4 INTERP"))) { 3311 reg = WCD9335_CDC_RX4_RX_PATH_CTL; 3312 gain_reg = WCD9335_CDC_RX4_RX_VOL_CTL; 3313 } else if (!(snd_soc_dapm_widget_name_cmp(w, "RX INT5 INTERP"))) { 3314 reg = WCD9335_CDC_RX5_RX_PATH_CTL; 3315 gain_reg = WCD9335_CDC_RX5_RX_VOL_CTL; 3316 } else if (!(snd_soc_dapm_widget_name_cmp(w, "RX INT6 INTERP"))) { 3317 reg = WCD9335_CDC_RX6_RX_PATH_CTL; 3318 gain_reg = WCD9335_CDC_RX6_RX_VOL_CTL; 3319 } else if (!(snd_soc_dapm_widget_name_cmp(w, "RX INT7 INTERP"))) { 3320 reg = WCD9335_CDC_RX7_RX_PATH_CTL; 3321 gain_reg = WCD9335_CDC_RX7_RX_VOL_CTL; 3322 } else if (!(snd_soc_dapm_widget_name_cmp(w, "RX INT8 INTERP"))) { 3323 reg = WCD9335_CDC_RX8_RX_PATH_CTL; 3324 gain_reg = WCD9335_CDC_RX8_RX_VOL_CTL; 3325 } else { 3326 dev_err(comp->dev, "%s: Interpolator reg not found\n", 3327 __func__); 3328 return -EINVAL; 3329 } 3330 3331 switch (event) { 3332 case SND_SOC_DAPM_PRE_PMU: 3333 /* Reset if needed */ 3334 wcd9335_codec_enable_prim_interpolator(comp, reg, event); 3335 break; 3336 case SND_SOC_DAPM_POST_PMU: 3337 wcd9335_config_compander(comp, w->shift, event); 3338 val = snd_soc_component_read(comp, gain_reg); 3339 snd_soc_component_write(comp, gain_reg, val); 3340 break; 3341 case SND_SOC_DAPM_POST_PMD: 3342 wcd9335_config_compander(comp, w->shift, event); 3343 wcd9335_codec_enable_prim_interpolator(comp, reg, event); 3344 break; 3345 } 3346 3347 return 0; 3348 } 3349 3350 static void wcd9335_codec_hph_mode_gain_opt(struct snd_soc_component *component, 3351 u8 gain) 3352 { 3353 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); 3354 u8 hph_l_en, hph_r_en; 3355 u8 l_val, r_val; 3356 u8 hph_pa_status; 3357 bool is_hphl_pa, is_hphr_pa; 3358 3359 hph_pa_status = snd_soc_component_read(component, WCD9335_ANA_HPH); 3360 is_hphl_pa = hph_pa_status >> 7; 3361 is_hphr_pa = (hph_pa_status & 0x40) >> 6; 3362 3363 hph_l_en = snd_soc_component_read(component, WCD9335_HPH_L_EN); 3364 hph_r_en = snd_soc_component_read(component, WCD9335_HPH_R_EN); 3365 3366 l_val = (hph_l_en & 0xC0) | 0x20 | gain; 3367 r_val = (hph_r_en & 0xC0) | 0x20 | gain; 3368 3369 /* 3370 * Set HPH_L & HPH_R gain source selection to REGISTER 3371 * for better click and pop only if corresponding PAs are 3372 * not enabled. Also cache the values of the HPHL/R 3373 * PA gains to be applied after PAs are enabled 3374 */ 3375 if ((l_val != hph_l_en) && !is_hphl_pa) { 3376 snd_soc_component_write(component, WCD9335_HPH_L_EN, l_val); 3377 wcd->hph_l_gain = hph_l_en & 0x1F; 3378 } 3379 3380 if ((r_val != hph_r_en) && !is_hphr_pa) { 3381 snd_soc_component_write(component, WCD9335_HPH_R_EN, r_val); 3382 wcd->hph_r_gain = hph_r_en & 0x1F; 3383 } 3384 } 3385 3386 static void wcd9335_codec_hph_lohifi_config(struct snd_soc_component *comp, 3387 int event) 3388 { 3389 if (SND_SOC_DAPM_EVENT_ON(event)) { 3390 snd_soc_component_update_bits(comp, WCD9335_RX_BIAS_HPH_PA, 3391 WCD9335_RX_BIAS_HPH_PA_AMP_5_UA_MASK, 3392 0x06); 3393 snd_soc_component_update_bits(comp, 3394 WCD9335_RX_BIAS_HPH_RDACBUFF_CNP2, 3395 0xF0, 0x40); 3396 snd_soc_component_update_bits(comp, WCD9335_HPH_CNP_WG_CTL, 3397 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_MASK, 3398 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_RATIO_1000); 3399 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, 3400 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_MASK, 3401 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_ENABLE); 3402 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL1, 3403 WCD9335_HPH_PA_GM3_IB_SCALE_MASK, 3404 0x0C); 3405 wcd9335_codec_hph_mode_gain_opt(comp, 0x11); 3406 } 3407 3408 if (SND_SOC_DAPM_EVENT_OFF(event)) { 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_DISABLE); 3412 snd_soc_component_update_bits(comp, WCD9335_HPH_CNP_WG_CTL, 3413 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_MASK, 3414 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_RATIO_500); 3415 snd_soc_component_write(comp, WCD9335_RX_BIAS_HPH_RDACBUFF_CNP2, 3416 0x8A); 3417 snd_soc_component_update_bits(comp, WCD9335_RX_BIAS_HPH_PA, 3418 WCD9335_RX_BIAS_HPH_PA_AMP_5_UA_MASK, 3419 0x0A); 3420 } 3421 } 3422 3423 static void wcd9335_codec_hph_lp_config(struct snd_soc_component *comp, 3424 int event) 3425 { 3426 if (SND_SOC_DAPM_EVENT_ON(event)) { 3427 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL1, 3428 WCD9335_HPH_PA_GM3_IB_SCALE_MASK, 3429 0x0C); 3430 wcd9335_codec_hph_mode_gain_opt(comp, 0x10); 3431 snd_soc_component_update_bits(comp, WCD9335_HPH_CNP_WG_CTL, 3432 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_MASK, 3433 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_RATIO_1000); 3434 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, 3435 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_MASK, 3436 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_ENABLE); 3437 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, 3438 WCD9335_HPH_PA_CTL2_FORCE_PSRREH_MASK, 3439 WCD9335_HPH_PA_CTL2_FORCE_PSRREH_ENABLE); 3440 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, 3441 WCD9335_HPH_PA_CTL2_HPH_PSRR_ENH_MASK, 3442 WCD9335_HPH_PA_CTL2_HPH_PSRR_ENABLE); 3443 snd_soc_component_update_bits(comp, WCD9335_HPH_RDAC_LDO_CTL, 3444 WCD9335_HPH_RDAC_N1P65_LD_OUTCTL_MASK, 3445 WCD9335_HPH_RDAC_N1P65_LD_OUTCTL_V_N1P60); 3446 snd_soc_component_update_bits(comp, WCD9335_HPH_RDAC_LDO_CTL, 3447 WCD9335_HPH_RDAC_1P65_LD_OUTCTL_MASK, 3448 WCD9335_HPH_RDAC_1P65_LD_OUTCTL_V_N1P60); 3449 snd_soc_component_update_bits(comp, 3450 WCD9335_RX_BIAS_HPH_RDAC_LDO, 0x0F, 0x01); 3451 snd_soc_component_update_bits(comp, 3452 WCD9335_RX_BIAS_HPH_RDAC_LDO, 0xF0, 0x10); 3453 } 3454 3455 if (SND_SOC_DAPM_EVENT_OFF(event)) { 3456 snd_soc_component_write(comp, WCD9335_RX_BIAS_HPH_RDAC_LDO, 3457 0x88); 3458 snd_soc_component_write(comp, WCD9335_HPH_RDAC_LDO_CTL, 3459 0x33); 3460 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, 3461 WCD9335_HPH_PA_CTL2_HPH_PSRR_ENH_MASK, 3462 WCD9335_HPH_PA_CTL2_HPH_PSRR_DISABLE); 3463 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, 3464 WCD9335_HPH_PA_CTL2_FORCE_PSRREH_MASK, 3465 WCD9335_HPH_PA_CTL2_FORCE_PSRREH_DISABLE); 3466 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, 3467 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_MASK, 3468 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_DISABLE); 3469 snd_soc_component_update_bits(comp, WCD9335_HPH_CNP_WG_CTL, 3470 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_MASK, 3471 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_RATIO_500); 3472 snd_soc_component_update_bits(comp, WCD9335_HPH_R_EN, 3473 WCD9335_HPH_CONST_SEL_L_MASK, 3474 WCD9335_HPH_CONST_SEL_L_HQ_PATH); 3475 snd_soc_component_update_bits(comp, WCD9335_HPH_L_EN, 3476 WCD9335_HPH_CONST_SEL_L_MASK, 3477 WCD9335_HPH_CONST_SEL_L_HQ_PATH); 3478 } 3479 } 3480 3481 static void wcd9335_codec_hph_hifi_config(struct snd_soc_component *comp, 3482 int event) 3483 { 3484 if (SND_SOC_DAPM_EVENT_ON(event)) { 3485 snd_soc_component_update_bits(comp, WCD9335_HPH_CNP_WG_CTL, 3486 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_MASK, 3487 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_RATIO_1000); 3488 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL2, 3489 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_MASK, 3490 WCD9335_HPH_PA_CTL2_FORCE_IQCTRL_ENABLE); 3491 snd_soc_component_update_bits(comp, WCD9335_HPH_PA_CTL1, 3492 WCD9335_HPH_PA_GM3_IB_SCALE_MASK, 3493 0x0C); 3494 wcd9335_codec_hph_mode_gain_opt(comp, 0x11); 3495 } 3496 3497 if (SND_SOC_DAPM_EVENT_OFF(event)) { 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_DISABLE); 3501 snd_soc_component_update_bits(comp, WCD9335_HPH_CNP_WG_CTL, 3502 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_MASK, 3503 WCD9335_HPH_CNP_WG_CTL_CURR_LDIV_RATIO_500); 3504 } 3505 } 3506 3507 static void wcd9335_codec_hph_mode_config(struct snd_soc_component *component, 3508 int event, int mode) 3509 { 3510 switch (mode) { 3511 case CLS_H_LP: 3512 wcd9335_codec_hph_lp_config(component, event); 3513 break; 3514 case CLS_H_LOHIFI: 3515 wcd9335_codec_hph_lohifi_config(component, event); 3516 break; 3517 case CLS_H_HIFI: 3518 wcd9335_codec_hph_hifi_config(component, event); 3519 break; 3520 } 3521 } 3522 3523 static int wcd9335_codec_hphl_dac_event(struct snd_soc_dapm_widget *w, 3524 struct snd_kcontrol *kc, 3525 int event) 3526 { 3527 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 3528 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); 3529 int hph_mode = wcd->hph_mode; 3530 u8 dem_inp; 3531 3532 switch (event) { 3533 case SND_SOC_DAPM_PRE_PMU: 3534 /* Read DEM INP Select */ 3535 dem_inp = snd_soc_component_read(comp, 3536 WCD9335_CDC_RX1_RX_PATH_SEC0) & 0x03; 3537 if (((hph_mode == CLS_H_HIFI) || (hph_mode == CLS_H_LOHIFI) || 3538 (hph_mode == CLS_H_LP)) && (dem_inp != 0x01)) { 3539 dev_err(comp->dev, "Incorrect DEM Input\n"); 3540 return -EINVAL; 3541 } 3542 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_PRE_DAC, 3543 WCD_CLSH_STATE_HPHL, 3544 ((hph_mode == CLS_H_LOHIFI) ? 3545 CLS_H_HIFI : hph_mode)); 3546 3547 wcd9335_codec_hph_mode_config(comp, event, hph_mode); 3548 3549 break; 3550 case SND_SOC_DAPM_POST_PMU: 3551 usleep_range(1000, 1100); 3552 break; 3553 case SND_SOC_DAPM_PRE_PMD: 3554 break; 3555 case SND_SOC_DAPM_POST_PMD: 3556 /* 1000us required as per HW requirement */ 3557 usleep_range(1000, 1100); 3558 3559 if (!(wcd_clsh_ctrl_get_state(wcd->clsh_ctrl) & 3560 WCD_CLSH_STATE_HPHR)) 3561 wcd9335_codec_hph_mode_config(comp, event, hph_mode); 3562 3563 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_POST_PA, 3564 WCD_CLSH_STATE_HPHL, 3565 ((hph_mode == CLS_H_LOHIFI) ? 3566 CLS_H_HIFI : hph_mode)); 3567 break; 3568 } 3569 3570 return 0; 3571 } 3572 3573 static int wcd9335_codec_lineout_dac_event(struct snd_soc_dapm_widget *w, 3574 struct snd_kcontrol *kc, int event) 3575 { 3576 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 3577 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); 3578 3579 switch (event) { 3580 case SND_SOC_DAPM_PRE_PMU: 3581 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_PRE_DAC, 3582 WCD_CLSH_STATE_LO, CLS_AB); 3583 break; 3584 case SND_SOC_DAPM_POST_PMD: 3585 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_POST_PA, 3586 WCD_CLSH_STATE_LO, CLS_AB); 3587 break; 3588 } 3589 3590 return 0; 3591 } 3592 3593 static int wcd9335_codec_ear_dac_event(struct snd_soc_dapm_widget *w, 3594 struct snd_kcontrol *kc, int event) 3595 { 3596 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 3597 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); 3598 3599 switch (event) { 3600 case SND_SOC_DAPM_PRE_PMU: 3601 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_PRE_DAC, 3602 WCD_CLSH_STATE_EAR, CLS_H_NORMAL); 3603 3604 break; 3605 case SND_SOC_DAPM_POST_PMD: 3606 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_POST_PA, 3607 WCD_CLSH_STATE_EAR, CLS_H_NORMAL); 3608 break; 3609 } 3610 3611 return 0; 3612 } 3613 3614 static void wcd9335_codec_hph_post_pa_config(struct wcd9335_codec *wcd, 3615 int mode, int event) 3616 { 3617 u8 scale_val = 0; 3618 3619 switch (event) { 3620 case SND_SOC_DAPM_POST_PMU: 3621 switch (mode) { 3622 case CLS_H_HIFI: 3623 scale_val = 0x3; 3624 break; 3625 case CLS_H_LOHIFI: 3626 scale_val = 0x1; 3627 break; 3628 } 3629 break; 3630 case SND_SOC_DAPM_PRE_PMD: 3631 scale_val = 0x6; 3632 break; 3633 } 3634 3635 if (scale_val) 3636 snd_soc_component_update_bits(wcd->component, 3637 WCD9335_HPH_PA_CTL1, 3638 WCD9335_HPH_PA_GM3_IB_SCALE_MASK, 3639 scale_val << 1); 3640 if (SND_SOC_DAPM_EVENT_ON(event)) { 3641 if (wcd->comp_enabled[COMPANDER_1] || 3642 wcd->comp_enabled[COMPANDER_2]) { 3643 /* GAIN Source Selection */ 3644 snd_soc_component_update_bits(wcd->component, 3645 WCD9335_HPH_L_EN, 3646 WCD9335_HPH_GAIN_SRC_SEL_MASK, 3647 WCD9335_HPH_GAIN_SRC_SEL_COMPANDER); 3648 snd_soc_component_update_bits(wcd->component, 3649 WCD9335_HPH_R_EN, 3650 WCD9335_HPH_GAIN_SRC_SEL_MASK, 3651 WCD9335_HPH_GAIN_SRC_SEL_COMPANDER); 3652 snd_soc_component_update_bits(wcd->component, 3653 WCD9335_HPH_AUTO_CHOP, 3654 WCD9335_HPH_AUTO_CHOP_MASK, 3655 WCD9335_HPH_AUTO_CHOP_FORCE_ENABLE); 3656 } 3657 snd_soc_component_update_bits(wcd->component, 3658 WCD9335_HPH_L_EN, 3659 WCD9335_HPH_PA_GAIN_MASK, 3660 wcd->hph_l_gain); 3661 snd_soc_component_update_bits(wcd->component, 3662 WCD9335_HPH_R_EN, 3663 WCD9335_HPH_PA_GAIN_MASK, 3664 wcd->hph_r_gain); 3665 } 3666 3667 if (SND_SOC_DAPM_EVENT_OFF(event)) 3668 snd_soc_component_update_bits(wcd->component, 3669 WCD9335_HPH_AUTO_CHOP, 3670 WCD9335_HPH_AUTO_CHOP_MASK, 3671 WCD9335_HPH_AUTO_CHOP_ENABLE_BY_CMPDR_GAIN); 3672 } 3673 3674 static int wcd9335_codec_hphr_dac_event(struct snd_soc_dapm_widget *w, 3675 struct snd_kcontrol *kc, 3676 int event) 3677 { 3678 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 3679 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); 3680 int hph_mode = wcd->hph_mode; 3681 u8 dem_inp; 3682 3683 switch (event) { 3684 case SND_SOC_DAPM_PRE_PMU: 3685 3686 /* Read DEM INP Select */ 3687 dem_inp = snd_soc_component_read(comp, 3688 WCD9335_CDC_RX2_RX_PATH_SEC0) & 3689 WCD9335_CDC_RX_PATH_DEM_INP_SEL_MASK; 3690 if (((hph_mode == CLS_H_HIFI) || (hph_mode == CLS_H_LOHIFI) || 3691 (hph_mode == CLS_H_LP)) && (dem_inp != 0x01)) { 3692 dev_err(comp->dev, "DEM Input not set correctly, hph_mode: %d\n", 3693 hph_mode); 3694 return -EINVAL; 3695 } 3696 3697 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, 3698 WCD_CLSH_EVENT_PRE_DAC, 3699 WCD_CLSH_STATE_HPHR, 3700 ((hph_mode == CLS_H_LOHIFI) ? 3701 CLS_H_HIFI : hph_mode)); 3702 3703 wcd9335_codec_hph_mode_config(comp, event, hph_mode); 3704 3705 break; 3706 case SND_SOC_DAPM_POST_PMD: 3707 /* 1000us required as per HW requirement */ 3708 usleep_range(1000, 1100); 3709 3710 if (!(wcd_clsh_ctrl_get_state(wcd->clsh_ctrl) & 3711 WCD_CLSH_STATE_HPHL)) 3712 wcd9335_codec_hph_mode_config(comp, event, hph_mode); 3713 3714 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_POST_PA, 3715 WCD_CLSH_STATE_HPHR, ((hph_mode == CLS_H_LOHIFI) ? 3716 CLS_H_HIFI : hph_mode)); 3717 break; 3718 } 3719 3720 return 0; 3721 } 3722 3723 static int wcd9335_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w, 3724 struct snd_kcontrol *kc, 3725 int event) 3726 { 3727 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 3728 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); 3729 int hph_mode = wcd->hph_mode; 3730 3731 switch (event) { 3732 case SND_SOC_DAPM_PRE_PMU: 3733 break; 3734 case SND_SOC_DAPM_POST_PMU: 3735 /* 3736 * 7ms sleep is required after PA is enabled as per 3737 * HW requirement 3738 */ 3739 usleep_range(7000, 7100); 3740 3741 wcd9335_codec_hph_post_pa_config(wcd, hph_mode, event); 3742 snd_soc_component_update_bits(comp, 3743 WCD9335_CDC_RX1_RX_PATH_CTL, 3744 WCD9335_CDC_RX_PGA_MUTE_EN_MASK, 3745 WCD9335_CDC_RX_PGA_MUTE_DISABLE); 3746 3747 /* Remove mix path mute if it is enabled */ 3748 if ((snd_soc_component_read(comp, 3749 WCD9335_CDC_RX1_RX_PATH_MIX_CTL)) & 3750 WCD9335_CDC_RX_PGA_MUTE_EN_MASK) 3751 snd_soc_component_update_bits(comp, 3752 WCD9335_CDC_RX1_RX_PATH_MIX_CTL, 3753 WCD9335_CDC_RX_PGA_MUTE_EN_MASK, 3754 WCD9335_CDC_RX_PGA_MUTE_DISABLE); 3755 3756 break; 3757 case SND_SOC_DAPM_PRE_PMD: 3758 wcd9335_codec_hph_post_pa_config(wcd, hph_mode, event); 3759 break; 3760 case SND_SOC_DAPM_POST_PMD: 3761 /* 5ms sleep is required after PA is disabled as per 3762 * HW requirement 3763 */ 3764 usleep_range(5000, 5500); 3765 break; 3766 } 3767 3768 return 0; 3769 } 3770 3771 static int wcd9335_codec_enable_lineout_pa(struct snd_soc_dapm_widget *w, 3772 struct snd_kcontrol *kc, 3773 int event) 3774 { 3775 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 3776 int vol_reg = 0, mix_vol_reg = 0; 3777 3778 if (w->reg == WCD9335_ANA_LO_1_2) { 3779 if (w->shift == 7) { 3780 vol_reg = WCD9335_CDC_RX3_RX_PATH_CTL; 3781 mix_vol_reg = WCD9335_CDC_RX3_RX_PATH_MIX_CTL; 3782 } else if (w->shift == 6) { 3783 vol_reg = WCD9335_CDC_RX4_RX_PATH_CTL; 3784 mix_vol_reg = WCD9335_CDC_RX4_RX_PATH_MIX_CTL; 3785 } 3786 } else if (w->reg == WCD9335_ANA_LO_3_4) { 3787 if (w->shift == 7) { 3788 vol_reg = WCD9335_CDC_RX5_RX_PATH_CTL; 3789 mix_vol_reg = WCD9335_CDC_RX5_RX_PATH_MIX_CTL; 3790 } else if (w->shift == 6) { 3791 vol_reg = WCD9335_CDC_RX6_RX_PATH_CTL; 3792 mix_vol_reg = WCD9335_CDC_RX6_RX_PATH_MIX_CTL; 3793 } 3794 } else { 3795 dev_err(comp->dev, "Error enabling lineout PA\n"); 3796 return -EINVAL; 3797 } 3798 3799 switch (event) { 3800 case SND_SOC_DAPM_POST_PMU: 3801 /* 5ms sleep is required after PA is enabled as per 3802 * HW requirement 3803 */ 3804 usleep_range(5000, 5500); 3805 snd_soc_component_update_bits(comp, vol_reg, 3806 WCD9335_CDC_RX_PGA_MUTE_EN_MASK, 3807 WCD9335_CDC_RX_PGA_MUTE_DISABLE); 3808 3809 /* Remove mix path mute if it is enabled */ 3810 if ((snd_soc_component_read(comp, mix_vol_reg)) & 3811 WCD9335_CDC_RX_PGA_MUTE_EN_MASK) 3812 snd_soc_component_update_bits(comp, mix_vol_reg, 3813 WCD9335_CDC_RX_PGA_MUTE_EN_MASK, 3814 WCD9335_CDC_RX_PGA_MUTE_DISABLE); 3815 break; 3816 case SND_SOC_DAPM_POST_PMD: 3817 /* 5ms sleep is required after PA is disabled as per 3818 * HW requirement 3819 */ 3820 usleep_range(5000, 5500); 3821 break; 3822 } 3823 3824 return 0; 3825 } 3826 3827 static void wcd9335_codec_init_flyback(struct snd_soc_component *component) 3828 { 3829 snd_soc_component_update_bits(component, WCD9335_HPH_L_EN, 3830 WCD9335_HPH_CONST_SEL_L_MASK, 3831 WCD9335_HPH_CONST_SEL_L_BYPASS); 3832 snd_soc_component_update_bits(component, WCD9335_HPH_R_EN, 3833 WCD9335_HPH_CONST_SEL_L_MASK, 3834 WCD9335_HPH_CONST_SEL_L_BYPASS); 3835 snd_soc_component_update_bits(component, WCD9335_RX_BIAS_FLYB_BUFF, 3836 WCD9335_RX_BIAS_FLYB_VPOS_5_UA_MASK, 3837 WCD9335_RX_BIAS_FLYB_I_0P0_UA); 3838 snd_soc_component_update_bits(component, WCD9335_RX_BIAS_FLYB_BUFF, 3839 WCD9335_RX_BIAS_FLYB_VNEG_5_UA_MASK, 3840 WCD9335_RX_BIAS_FLYB_I_0P0_UA); 3841 } 3842 3843 static int wcd9335_codec_enable_rx_bias(struct snd_soc_dapm_widget *w, 3844 struct snd_kcontrol *kc, int event) 3845 { 3846 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 3847 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); 3848 3849 switch (event) { 3850 case SND_SOC_DAPM_PRE_PMU: 3851 wcd->rx_bias_count++; 3852 if (wcd->rx_bias_count == 1) { 3853 wcd9335_codec_init_flyback(comp); 3854 snd_soc_component_update_bits(comp, 3855 WCD9335_ANA_RX_SUPPLIES, 3856 WCD9335_ANA_RX_BIAS_ENABLE_MASK, 3857 WCD9335_ANA_RX_BIAS_ENABLE); 3858 } 3859 break; 3860 case SND_SOC_DAPM_POST_PMD: 3861 wcd->rx_bias_count--; 3862 if (!wcd->rx_bias_count) 3863 snd_soc_component_update_bits(comp, 3864 WCD9335_ANA_RX_SUPPLIES, 3865 WCD9335_ANA_RX_BIAS_ENABLE_MASK, 3866 WCD9335_ANA_RX_BIAS_DISABLE); 3867 break; 3868 } 3869 3870 return 0; 3871 } 3872 3873 static int wcd9335_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w, 3874 struct snd_kcontrol *kc, int event) 3875 { 3876 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 3877 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); 3878 int hph_mode = wcd->hph_mode; 3879 3880 switch (event) { 3881 case SND_SOC_DAPM_PRE_PMU: 3882 break; 3883 case SND_SOC_DAPM_POST_PMU: 3884 /* 3885 * 7ms sleep is required after PA is enabled as per 3886 * HW requirement 3887 */ 3888 usleep_range(7000, 7100); 3889 wcd9335_codec_hph_post_pa_config(wcd, hph_mode, event); 3890 snd_soc_component_update_bits(comp, 3891 WCD9335_CDC_RX2_RX_PATH_CTL, 3892 WCD9335_CDC_RX_PGA_MUTE_EN_MASK, 3893 WCD9335_CDC_RX_PGA_MUTE_DISABLE); 3894 /* Remove mix path mute if it is enabled */ 3895 if ((snd_soc_component_read(comp, 3896 WCD9335_CDC_RX2_RX_PATH_MIX_CTL)) & 3897 WCD9335_CDC_RX_PGA_MUTE_EN_MASK) 3898 snd_soc_component_update_bits(comp, 3899 WCD9335_CDC_RX2_RX_PATH_MIX_CTL, 3900 WCD9335_CDC_RX_PGA_MUTE_EN_MASK, 3901 WCD9335_CDC_RX_PGA_MUTE_DISABLE); 3902 3903 break; 3904 3905 case SND_SOC_DAPM_PRE_PMD: 3906 wcd9335_codec_hph_post_pa_config(wcd, hph_mode, event); 3907 break; 3908 case SND_SOC_DAPM_POST_PMD: 3909 /* 5ms sleep is required after PA is disabled as per 3910 * HW requirement 3911 */ 3912 usleep_range(5000, 5500); 3913 break; 3914 } 3915 3916 return 0; 3917 } 3918 3919 static int wcd9335_codec_enable_ear_pa(struct snd_soc_dapm_widget *w, 3920 struct snd_kcontrol *kc, int event) 3921 { 3922 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 3923 3924 switch (event) { 3925 case SND_SOC_DAPM_POST_PMU: 3926 /* 5ms sleep is required after PA is enabled as per 3927 * HW requirement 3928 */ 3929 usleep_range(5000, 5500); 3930 snd_soc_component_update_bits(comp, 3931 WCD9335_CDC_RX0_RX_PATH_CTL, 3932 WCD9335_CDC_RX_PGA_MUTE_EN_MASK, 3933 WCD9335_CDC_RX_PGA_MUTE_DISABLE); 3934 /* Remove mix path mute if it is enabled */ 3935 if ((snd_soc_component_read(comp, 3936 WCD9335_CDC_RX0_RX_PATH_MIX_CTL)) & 3937 WCD9335_CDC_RX_PGA_MUTE_EN_MASK) 3938 snd_soc_component_update_bits(comp, 3939 WCD9335_CDC_RX0_RX_PATH_MIX_CTL, 3940 WCD9335_CDC_RX_PGA_MUTE_EN_MASK, 3941 WCD9335_CDC_RX_PGA_MUTE_DISABLE); 3942 break; 3943 case SND_SOC_DAPM_POST_PMD: 3944 /* 5ms sleep is required after PA is disabled as per 3945 * HW requirement 3946 */ 3947 usleep_range(5000, 5500); 3948 3949 break; 3950 } 3951 3952 return 0; 3953 } 3954 3955 static irqreturn_t wcd9335_slimbus_irq(int irq, void *data) 3956 { 3957 struct wcd9335_codec *wcd = data; 3958 unsigned long status = 0; 3959 int i, j, port_id; 3960 unsigned int val, int_val = 0; 3961 irqreturn_t ret = IRQ_NONE; 3962 bool tx; 3963 unsigned short reg = 0; 3964 3965 for (i = WCD9335_SLIM_PGD_PORT_INT_STATUS_RX_0, j = 0; 3966 i <= WCD9335_SLIM_PGD_PORT_INT_STATUS_TX_1; i++, j++) { 3967 regmap_read(wcd->if_regmap, i, &val); 3968 status |= ((u32)val << (8 * j)); 3969 } 3970 3971 for_each_set_bit(j, &status, 32) { 3972 tx = (j >= 16); 3973 port_id = (tx ? j - 16 : j); 3974 regmap_read(wcd->if_regmap, 3975 WCD9335_SLIM_PGD_PORT_INT_RX_SOURCE0 + j, &val); 3976 if (val) { 3977 if (!tx) 3978 reg = WCD9335_SLIM_PGD_PORT_INT_EN0 + 3979 (port_id / 8); 3980 else 3981 reg = WCD9335_SLIM_PGD_PORT_INT_TX_EN0 + 3982 (port_id / 8); 3983 regmap_read( 3984 wcd->if_regmap, reg, &int_val); 3985 /* 3986 * Ignore interrupts for ports for which the 3987 * interrupts are not specifically enabled. 3988 */ 3989 if (!(int_val & (1 << (port_id % 8)))) 3990 continue; 3991 } 3992 3993 if (val & WCD9335_SLIM_IRQ_OVERFLOW) 3994 dev_err_ratelimited(wcd->dev, 3995 "%s: overflow error on %s port %d, value %x\n", 3996 __func__, (tx ? "TX" : "RX"), port_id, val); 3997 3998 if (val & WCD9335_SLIM_IRQ_UNDERFLOW) 3999 dev_err_ratelimited(wcd->dev, 4000 "%s: underflow error on %s port %d, value %x\n", 4001 __func__, (tx ? "TX" : "RX"), port_id, val); 4002 4003 if ((val & WCD9335_SLIM_IRQ_OVERFLOW) || 4004 (val & WCD9335_SLIM_IRQ_UNDERFLOW)) { 4005 if (!tx) 4006 reg = WCD9335_SLIM_PGD_PORT_INT_EN0 + 4007 (port_id / 8); 4008 else 4009 reg = WCD9335_SLIM_PGD_PORT_INT_TX_EN0 + 4010 (port_id / 8); 4011 regmap_read( 4012 wcd->if_regmap, reg, &int_val); 4013 if (int_val & (1 << (port_id % 8))) { 4014 int_val = int_val ^ (1 << (port_id % 8)); 4015 regmap_write(wcd->if_regmap, 4016 reg, int_val); 4017 } 4018 } 4019 4020 regmap_write(wcd->if_regmap, 4021 WCD9335_SLIM_PGD_PORT_INT_CLR_RX_0 + (j / 8), 4022 BIT(j % 8)); 4023 ret = IRQ_HANDLED; 4024 } 4025 4026 return ret; 4027 } 4028 4029 static struct wcd9335_irq wcd9335_irqs[] = { 4030 { 4031 .irq = WCD9335_IRQ_SLIMBUS, 4032 .handler = wcd9335_slimbus_irq, 4033 .name = "SLIM Slave", 4034 }, 4035 }; 4036 4037 static int wcd9335_setup_irqs(struct wcd9335_codec *wcd) 4038 { 4039 int irq, ret, i; 4040 4041 for (i = 0; i < ARRAY_SIZE(wcd9335_irqs); i++) { 4042 irq = regmap_irq_get_virq(wcd->irq_data, wcd9335_irqs[i].irq); 4043 if (irq < 0) { 4044 dev_err(wcd->dev, "Failed to get %s\n", 4045 wcd9335_irqs[i].name); 4046 return irq; 4047 } 4048 4049 ret = devm_request_threaded_irq(wcd->dev, irq, NULL, 4050 wcd9335_irqs[i].handler, 4051 IRQF_TRIGGER_RISING | 4052 IRQF_ONESHOT, 4053 wcd9335_irqs[i].name, wcd); 4054 if (ret) { 4055 dev_err(wcd->dev, "Failed to request %s\n", 4056 wcd9335_irqs[i].name); 4057 return ret; 4058 } 4059 } 4060 4061 /* enable interrupts on all slave ports */ 4062 for (i = 0; i < WCD9335_SLIM_NUM_PORT_REG; i++) 4063 regmap_write(wcd->if_regmap, WCD9335_SLIM_PGD_PORT_INT_EN0 + i, 4064 0xFF); 4065 4066 return ret; 4067 } 4068 4069 static void wcd9335_teardown_irqs(struct wcd9335_codec *wcd) 4070 { 4071 int i; 4072 4073 /* disable interrupts on all slave ports */ 4074 for (i = 0; i < WCD9335_SLIM_NUM_PORT_REG; i++) 4075 regmap_write(wcd->if_regmap, WCD9335_SLIM_PGD_PORT_INT_EN0 + i, 4076 0x00); 4077 } 4078 4079 static void wcd9335_cdc_sido_ccl_enable(struct wcd9335_codec *wcd, 4080 bool ccl_flag) 4081 { 4082 struct snd_soc_component *comp = wcd->component; 4083 4084 if (ccl_flag) { 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); 4088 } else { 4089 if (wcd->sido_ccl_cnt == 0) { 4090 dev_err(wcd->dev, "sido_ccl already disabled\n"); 4091 return; 4092 } 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); 4096 } 4097 } 4098 4099 static int wcd9335_enable_master_bias(struct wcd9335_codec *wcd) 4100 { 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); 4109 /* 4110 * 1ms delay is required after pre-charge is enabled 4111 * as per HW requirement 4112 */ 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); 4120 } 4121 4122 return 0; 4123 } 4124 4125 static int wcd9335_enable_mclk(struct wcd9335_codec *wcd) 4126 { 4127 /* Enable mclk requires master bias to be enabled first */ 4128 if (wcd->master_bias_users <= 0) 4129 return -EINVAL; 4130 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", 4134 wcd->clk_type); 4135 return -EINVAL; 4136 } 4137 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); 4156 /* 4157 * 10us sleep is required after clock is enabled 4158 * as per HW requirement 4159 */ 4160 usleep_range(10, 15); 4161 } 4162 4163 wcd->clk_type = WCD_CLK_MCLK; 4164 4165 return 0; 4166 } 4167 4168 static int wcd9335_disable_mclk(struct wcd9335_codec *wcd) 4169 { 4170 if (wcd->clk_mclk_users <= 0) 4171 return -EINVAL; 4172 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; 4180 } else { 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; 4185 } 4186 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); 4190 } 4191 4192 return 0; 4193 } 4194 4195 static int wcd9335_disable_master_bias(struct wcd9335_codec *wcd) 4196 { 4197 if (wcd->master_bias_users <= 0) 4198 return -EINVAL; 4199 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); 4208 } 4209 return 0; 4210 } 4211 4212 static int wcd9335_cdc_req_mclk_enable(struct wcd9335_codec *wcd, 4213 bool enable) 4214 { 4215 int ret = 0; 4216 4217 if (enable) { 4218 wcd9335_cdc_sido_ccl_enable(wcd, true); 4219 ret = clk_prepare_enable(wcd->mclk); 4220 if (ret) { 4221 dev_err(wcd->dev, "%s: ext clk enable failed\n", 4222 __func__); 4223 goto err; 4224 } 4225 /* get BG */ 4226 wcd9335_enable_master_bias(wcd); 4227 /* get MCLK */ 4228 wcd9335_enable_mclk(wcd); 4229 4230 } else { 4231 /* put MCLK */ 4232 wcd9335_disable_mclk(wcd); 4233 /* put BG */ 4234 wcd9335_disable_master_bias(wcd); 4235 clk_disable_unprepare(wcd->mclk); 4236 wcd9335_cdc_sido_ccl_enable(wcd, false); 4237 } 4238 err: 4239 return ret; 4240 } 4241 4242 static void wcd9335_codec_apply_sido_voltage(struct wcd9335_codec *wcd, 4243 enum wcd9335_sido_voltage req_mv) 4244 { 4245 struct snd_soc_component *comp = wcd->component; 4246 int vout_d_val; 4247 4248 if (req_mv == wcd->sido_voltage) 4249 return; 4250 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); 4258 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); 4265 } 4266 4267 static int wcd9335_codec_update_sido_voltage(struct wcd9335_codec *wcd, 4268 enum wcd9335_sido_voltage req_mv) 4269 { 4270 int ret = 0; 4271 4272 /* enable mclk before setting SIDO voltage */ 4273 ret = wcd9335_cdc_req_mclk_enable(wcd, true); 4274 if (ret) { 4275 dev_err(wcd->dev, "Ext clk enable failed\n"); 4276 goto err; 4277 } 4278 4279 wcd9335_codec_apply_sido_voltage(wcd, req_mv); 4280 wcd9335_cdc_req_mclk_enable(wcd, false); 4281 4282 err: 4283 return ret; 4284 } 4285 4286 static int _wcd9335_codec_enable_mclk(struct snd_soc_component *component, 4287 int enable) 4288 { 4289 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); 4290 int ret; 4291 4292 if (enable) { 4293 ret = wcd9335_cdc_req_mclk_enable(wcd, true); 4294 if (ret) 4295 return ret; 4296 4297 wcd9335_codec_apply_sido_voltage(wcd, 4298 SIDO_VOLTAGE_NOMINAL_MV); 4299 } else { 4300 wcd9335_codec_update_sido_voltage(wcd, 4301 wcd->sido_voltage); 4302 wcd9335_cdc_req_mclk_enable(wcd, false); 4303 } 4304 4305 return 0; 4306 } 4307 4308 static int wcd9335_codec_enable_mclk(struct snd_soc_dapm_widget *w, 4309 struct snd_kcontrol *kc, int event) 4310 { 4311 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); 4312 4313 switch (event) { 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); 4318 } 4319 4320 return 0; 4321 } 4322 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), 4449 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), 4468 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), 4478 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), 4485 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), 4531 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), 4590 4591 /* TX */ 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"), 4598 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), 4602 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), 4606 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), 4610 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), 4627 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), 4640 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), 4645 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), 4649 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), 4653 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), 4657 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), 4661 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), 4665 4666 SND_SOC_DAPM_MUX("DMIC MUX0", SND_SOC_NOPM, 0, 0, 4667 &tx_dmic_mux0), 4668 SND_SOC_DAPM_MUX("DMIC MUX1", SND_SOC_NOPM, 0, 0, 4669 &tx_dmic_mux1), 4670 SND_SOC_DAPM_MUX("DMIC MUX2", SND_SOC_NOPM, 0, 0, 4671 &tx_dmic_mux2), 4672 SND_SOC_DAPM_MUX("DMIC MUX3", SND_SOC_NOPM, 0, 0, 4673 &tx_dmic_mux3), 4674 SND_SOC_DAPM_MUX("DMIC MUX4", SND_SOC_NOPM, 0, 0, 4675 &tx_dmic_mux4), 4676 SND_SOC_DAPM_MUX("DMIC MUX5", SND_SOC_NOPM, 0, 0, 4677 &tx_dmic_mux5), 4678 SND_SOC_DAPM_MUX("DMIC MUX6", SND_SOC_NOPM, 0, 0, 4679 &tx_dmic_mux6), 4680 SND_SOC_DAPM_MUX("DMIC MUX7", SND_SOC_NOPM, 0, 0, 4681 &tx_dmic_mux7), 4682 SND_SOC_DAPM_MUX("DMIC MUX8", SND_SOC_NOPM, 0, 0, 4683 &tx_dmic_mux8), 4684 4685 SND_SOC_DAPM_MUX("AMIC MUX0", SND_SOC_NOPM, 0, 0, 4686 &tx_amic_mux0), 4687 SND_SOC_DAPM_MUX("AMIC MUX1", SND_SOC_NOPM, 0, 0, 4688 &tx_amic_mux1), 4689 SND_SOC_DAPM_MUX("AMIC MUX2", SND_SOC_NOPM, 0, 0, 4690 &tx_amic_mux2), 4691 SND_SOC_DAPM_MUX("AMIC MUX3", SND_SOC_NOPM, 0, 0, 4692 &tx_amic_mux3), 4693 SND_SOC_DAPM_MUX("AMIC MUX4", SND_SOC_NOPM, 0, 0, 4694 &tx_amic_mux4), 4695 SND_SOC_DAPM_MUX("AMIC MUX5", SND_SOC_NOPM, 0, 0, 4696 &tx_amic_mux5), 4697 SND_SOC_DAPM_MUX("AMIC MUX6", SND_SOC_NOPM, 0, 0, 4698 &tx_amic_mux6), 4699 SND_SOC_DAPM_MUX("AMIC MUX7", SND_SOC_NOPM, 0, 0, 4700 &tx_amic_mux7), 4701 SND_SOC_DAPM_MUX("AMIC MUX8", SND_SOC_NOPM, 0, 0, 4702 &tx_amic_mux8), 4703 4704 SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0, 4705 aif1_cap_mixer, ARRAY_SIZE(aif1_cap_mixer)), 4706 4707 SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0, 4708 aif2_cap_mixer, ARRAY_SIZE(aif2_cap_mixer)), 4709 4710 SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0, 4711 aif3_cap_mixer, ARRAY_SIZE(aif3_cap_mixer)), 4712 4713 SND_SOC_DAPM_MUX("SLIM TX0 MUX", SND_SOC_NOPM, WCD9335_TX0, 0, 4714 &sb_tx0_mux), 4715 SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, WCD9335_TX1, 0, 4716 &sb_tx1_mux), 4717 SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, WCD9335_TX2, 0, 4718 &sb_tx2_mux), 4719 SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, WCD9335_TX3, 0, 4720 &sb_tx3_mux), 4721 SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, WCD9335_TX4, 0, 4722 &sb_tx4_mux), 4723 SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, WCD9335_TX5, 0, 4724 &sb_tx5_mux), 4725 SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, WCD9335_TX6, 0, 4726 &sb_tx6_mux), 4727 SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, WCD9335_TX7, 0, 4728 &sb_tx7_mux), 4729 SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, WCD9335_TX8, 0, 4730 &sb_tx8_mux), 4731 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), 4736 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), 4741 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), 4746 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), 4751 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), 4756 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), 4761 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), 4766 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), 4771 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), 4776 }; 4777 4778 static void wcd9335_enable_sido_buck(struct snd_soc_component *component) 4779 { 4780 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); 4781 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; 4796 } 4797 4798 static int wcd9335_enable_efuse_sensing(struct snd_soc_component *comp) 4799 { 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); 4805 /* 4806 * 5ms sleep required after enabling efuse control 4807 * before checking the status. 4808 */ 4809 usleep_range(5000, 5500); 4810 4811 if (!(snd_soc_component_read(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__); 4815 4816 wcd9335_enable_sido_buck(comp); 4817 _wcd9335_codec_enable_mclk(comp, false); 4818 4819 return 0; 4820 } 4821 4822 static void wcd9335_codec_init(struct snd_soc_component *component) 4823 { 4824 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); 4825 int i; 4826 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); 4830 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); 4834 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); 4840 4841 wcd9335_enable_efuse_sensing(component); 4842 } 4843 4844 static int wcd9335_codec_probe(struct snd_soc_component *component) 4845 { 4846 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); 4847 int ret; 4848 int i; 4849 4850 snd_soc_component_init_regmap(component, wcd->regmap); 4851 /* Class-H Init*/ 4852 wcd->clsh_ctrl = wcd_clsh_ctrl_alloc(component, WCD9335); 4853 if (IS_ERR(wcd->clsh_ctrl)) 4854 return PTR_ERR(wcd->clsh_ctrl); 4855 4856 /* Default HPH Mode to Class-H HiFi */ 4857 wcd->hph_mode = CLS_H_HIFI; 4858 wcd->component = component; 4859 4860 wcd9335_codec_init(component); 4861 4862 for (i = 0; i < NUM_CODEC_DAIS; i++) 4863 INIT_LIST_HEAD(&wcd->dai[i].slim_ch_list); 4864 4865 ret = wcd9335_setup_irqs(wcd); 4866 if (ret) 4867 goto free_clsh_ctrl; 4868 4869 return 0; 4870 4871 free_clsh_ctrl: 4872 wcd_clsh_ctrl_free(wcd->clsh_ctrl); 4873 return ret; 4874 } 4875 4876 static void wcd9335_codec_remove(struct snd_soc_component *comp) 4877 { 4878 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); 4879 4880 wcd_clsh_ctrl_free(wcd->clsh_ctrl); 4881 wcd9335_teardown_irqs(wcd); 4882 } 4883 4884 static int wcd9335_codec_set_sysclk(struct snd_soc_component *comp, 4885 int clk_id, int source, 4886 unsigned int freq, int dir) 4887 { 4888 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); 4889 4890 wcd->mclk_rate = freq; 4891 4892 if (wcd->mclk_rate == WCD9335_MCLK_CLK_12P288MHZ) 4893 snd_soc_component_update_bits(comp, 4894 WCD9335_CODEC_RPM_CLK_MCLK_CFG, 4895 WCD9335_CODEC_RPM_CLK_MCLK_CFG_MCLK_MASK, 4896 WCD9335_CODEC_RPM_CLK_MCLK_CFG_12P288MHZ); 4897 else if (wcd->mclk_rate == WCD9335_MCLK_CLK_9P6MHZ) 4898 snd_soc_component_update_bits(comp, 4899 WCD9335_CODEC_RPM_CLK_MCLK_CFG, 4900 WCD9335_CODEC_RPM_CLK_MCLK_CFG_MCLK_MASK, 4901 WCD9335_CODEC_RPM_CLK_MCLK_CFG_9P6MHZ); 4902 4903 return clk_set_rate(wcd->mclk, freq); 4904 } 4905 4906 static const struct snd_soc_component_driver wcd9335_component_drv = { 4907 .probe = wcd9335_codec_probe, 4908 .remove = wcd9335_codec_remove, 4909 .set_sysclk = wcd9335_codec_set_sysclk, 4910 .controls = wcd9335_snd_controls, 4911 .num_controls = ARRAY_SIZE(wcd9335_snd_controls), 4912 .dapm_widgets = wcd9335_dapm_widgets, 4913 .num_dapm_widgets = ARRAY_SIZE(wcd9335_dapm_widgets), 4914 .dapm_routes = wcd9335_audio_map, 4915 .num_dapm_routes = ARRAY_SIZE(wcd9335_audio_map), 4916 .endianness = 1, 4917 }; 4918 4919 static int wcd9335_probe(struct wcd9335_codec *wcd) 4920 { 4921 struct device *dev = wcd->dev; 4922 4923 memcpy(wcd->rx_chs, wcd9335_rx_chs, sizeof(wcd9335_rx_chs)); 4924 memcpy(wcd->tx_chs, wcd9335_tx_chs, sizeof(wcd9335_tx_chs)); 4925 4926 wcd->sido_input_src = SIDO_SOURCE_INTERNAL; 4927 wcd->sido_voltage = SIDO_VOLTAGE_NOMINAL_MV; 4928 4929 return devm_snd_soc_register_component(dev, &wcd9335_component_drv, 4930 wcd9335_slim_dais, 4931 ARRAY_SIZE(wcd9335_slim_dais)); 4932 } 4933 4934 static const struct regmap_range_cfg wcd9335_ranges[] = { 4935 { 4936 .name = "WCD9335", 4937 .range_min = 0x0, 4938 .range_max = WCD9335_MAX_REGISTER, 4939 .selector_reg = WCD9335_SEL_REGISTER, 4940 .selector_mask = 0xff, 4941 .selector_shift = 0, 4942 .window_start = 0x800, 4943 .window_len = 0x100, 4944 }, 4945 }; 4946 4947 static bool wcd9335_is_volatile_register(struct device *dev, unsigned int reg) 4948 { 4949 switch (reg) { 4950 case WCD9335_INTR_PIN1_STATUS0...WCD9335_INTR_PIN2_CLEAR3: 4951 case WCD9335_ANA_MBHC_RESULT_3: 4952 case WCD9335_ANA_MBHC_RESULT_2: 4953 case WCD9335_ANA_MBHC_RESULT_1: 4954 case WCD9335_ANA_MBHC_MECH: 4955 case WCD9335_ANA_MBHC_ELECT: 4956 case WCD9335_ANA_MBHC_ZDET: 4957 case WCD9335_ANA_MICB2: 4958 case WCD9335_ANA_RCO: 4959 case WCD9335_ANA_BIAS: 4960 return true; 4961 default: 4962 return false; 4963 } 4964 } 4965 4966 static struct regmap_config wcd9335_regmap_config = { 4967 .reg_bits = 16, 4968 .val_bits = 8, 4969 .cache_type = REGCACHE_MAPLE, 4970 .max_register = WCD9335_MAX_REGISTER, 4971 .can_multi_write = true, 4972 .ranges = wcd9335_ranges, 4973 .num_ranges = ARRAY_SIZE(wcd9335_ranges), 4974 .volatile_reg = wcd9335_is_volatile_register, 4975 }; 4976 4977 static const struct regmap_range_cfg wcd9335_ifc_ranges[] = { 4978 { 4979 .name = "WCD9335-IFC-DEV", 4980 .range_min = 0x0, 4981 .range_max = WCD9335_MAX_REGISTER, 4982 .selector_reg = WCD9335_SEL_REGISTER, 4983 .selector_mask = 0xfff, 4984 .selector_shift = 0, 4985 .window_start = 0x800, 4986 .window_len = 0x400, 4987 }, 4988 }; 4989 4990 static struct regmap_config wcd9335_ifc_regmap_config = { 4991 .reg_bits = 16, 4992 .val_bits = 8, 4993 .can_multi_write = true, 4994 .max_register = WCD9335_MAX_REGISTER, 4995 .ranges = wcd9335_ifc_ranges, 4996 .num_ranges = ARRAY_SIZE(wcd9335_ifc_ranges), 4997 }; 4998 4999 static const struct regmap_irq wcd9335_codec_irqs[] = { 5000 /* INTR_REG 0 */ 5001 [WCD9335_IRQ_SLIMBUS] = { 5002 .reg_offset = 0, 5003 .mask = BIT(0), 5004 .type = { 5005 .type_reg_offset = 0, 5006 .types_supported = IRQ_TYPE_EDGE_BOTH, 5007 .type_reg_mask = BIT(0), 5008 }, 5009 }, 5010 }; 5011 5012 static const unsigned int wcd9335_config_regs[] = { 5013 WCD9335_INTR_LEVEL0, 5014 }; 5015 5016 static const struct regmap_irq_chip wcd9335_regmap_irq1_chip = { 5017 .name = "wcd9335_pin1_irq", 5018 .status_base = WCD9335_INTR_PIN1_STATUS0, 5019 .mask_base = WCD9335_INTR_PIN1_MASK0, 5020 .ack_base = WCD9335_INTR_PIN1_CLEAR0, 5021 .num_regs = 4, 5022 .irqs = wcd9335_codec_irqs, 5023 .num_irqs = ARRAY_SIZE(wcd9335_codec_irqs), 5024 .config_base = wcd9335_config_regs, 5025 .num_config_bases = ARRAY_SIZE(wcd9335_config_regs), 5026 .num_config_regs = 4, 5027 .set_type_config = regmap_irq_set_type_config_simple, 5028 }; 5029 5030 static int wcd9335_parse_dt(struct wcd9335_codec *wcd) 5031 { 5032 struct device *dev = wcd->dev; 5033 struct device_node *np = dev->of_node; 5034 int ret; 5035 5036 wcd->reset_gpio = of_get_named_gpio(np, "reset-gpios", 0); 5037 if (wcd->reset_gpio < 0) { 5038 dev_err(dev, "Reset GPIO missing from DT\n"); 5039 return wcd->reset_gpio; 5040 } 5041 5042 wcd->mclk = devm_clk_get(dev, "mclk"); 5043 if (IS_ERR(wcd->mclk)) { 5044 dev_err(dev, "mclk not found\n"); 5045 return PTR_ERR(wcd->mclk); 5046 } 5047 5048 wcd->native_clk = devm_clk_get(dev, "slimbus"); 5049 if (IS_ERR(wcd->native_clk)) { 5050 dev_err(dev, "slimbus clock not found\n"); 5051 return PTR_ERR(wcd->native_clk); 5052 } 5053 5054 wcd->supplies[0].supply = "vdd-buck"; 5055 wcd->supplies[1].supply = "vdd-buck-sido"; 5056 wcd->supplies[2].supply = "vdd-tx"; 5057 wcd->supplies[3].supply = "vdd-rx"; 5058 wcd->supplies[4].supply = "vdd-io"; 5059 5060 ret = regulator_bulk_get(dev, WCD9335_MAX_SUPPLY, wcd->supplies); 5061 if (ret) { 5062 dev_err(dev, "Failed to get supplies: err = %d\n", ret); 5063 return ret; 5064 } 5065 5066 return 0; 5067 } 5068 5069 static int wcd9335_power_on_reset(struct wcd9335_codec *wcd) 5070 { 5071 struct device *dev = wcd->dev; 5072 int ret; 5073 5074 ret = regulator_bulk_enable(WCD9335_MAX_SUPPLY, wcd->supplies); 5075 if (ret) { 5076 dev_err(dev, "Failed to get supplies: err = %d\n", ret); 5077 return ret; 5078 } 5079 5080 /* 5081 * For WCD9335, it takes about 600us for the Vout_A and 5082 * Vout_D to be ready after BUCK_SIDO is powered up. 5083 * SYS_RST_N shouldn't be pulled high during this time 5084 * Toggle the reset line to make sure the reset pulse is 5085 * correctly applied 5086 */ 5087 usleep_range(600, 650); 5088 5089 gpio_direction_output(wcd->reset_gpio, 0); 5090 msleep(20); 5091 gpio_set_value(wcd->reset_gpio, 1); 5092 msleep(20); 5093 5094 return 0; 5095 } 5096 5097 static int wcd9335_bring_up(struct wcd9335_codec *wcd) 5098 { 5099 struct regmap *rm = wcd->regmap; 5100 int val, byte0; 5101 5102 regmap_read(rm, WCD9335_CHIP_TIER_CTRL_EFUSE_VAL_OUT0, &val); 5103 regmap_read(rm, WCD9335_CHIP_TIER_CTRL_CHIP_ID_BYTE0, &byte0); 5104 5105 if ((val < 0) || (byte0 < 0)) { 5106 dev_err(wcd->dev, "WCD9335 CODEC version detection fail!\n"); 5107 return -EINVAL; 5108 } 5109 5110 if (byte0 == 0x1) { 5111 dev_info(wcd->dev, "WCD9335 CODEC version is v2.0\n"); 5112 wcd->version = WCD9335_VERSION_2_0; 5113 regmap_write(rm, WCD9335_CODEC_RPM_RST_CTL, 0x01); 5114 regmap_write(rm, WCD9335_SIDO_SIDO_TEST_2, 0x00); 5115 regmap_write(rm, WCD9335_SIDO_SIDO_CCL_8, 0x6F); 5116 regmap_write(rm, WCD9335_BIAS_VBG_FINE_ADJ, 0x65); 5117 regmap_write(rm, WCD9335_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x5); 5118 regmap_write(rm, WCD9335_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x7); 5119 regmap_write(rm, WCD9335_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x3); 5120 regmap_write(rm, WCD9335_CODEC_RPM_RST_CTL, 0x3); 5121 } else { 5122 dev_err(wcd->dev, "WCD9335 CODEC version not supported\n"); 5123 return -EINVAL; 5124 } 5125 5126 return 0; 5127 } 5128 5129 static int wcd9335_irq_init(struct wcd9335_codec *wcd) 5130 { 5131 int ret; 5132 5133 /* 5134 * INTR1 consists of all possible interrupt sources Ear OCP, 5135 * HPH OCP, MBHC, MAD, VBAT, and SVA 5136 * INTR2 is a subset of first interrupt sources MAD, VBAT, and SVA 5137 */ 5138 wcd->intr1 = of_irq_get_byname(wcd->dev->of_node, "intr1"); 5139 if (wcd->intr1 < 0) 5140 return dev_err_probe(wcd->dev, wcd->intr1, 5141 "Unable to configure IRQ\n"); 5142 5143 ret = devm_regmap_add_irq_chip(wcd->dev, wcd->regmap, wcd->intr1, 5144 IRQF_TRIGGER_HIGH, 0, 5145 &wcd9335_regmap_irq1_chip, &wcd->irq_data); 5146 if (ret) 5147 return dev_err_probe(wcd->dev, ret, "Failed to register IRQ chip\n"); 5148 5149 return 0; 5150 } 5151 5152 static int wcd9335_slim_probe(struct slim_device *slim) 5153 { 5154 struct device *dev = &slim->dev; 5155 struct wcd9335_codec *wcd; 5156 int ret; 5157 5158 wcd = devm_kzalloc(dev, sizeof(*wcd), GFP_KERNEL); 5159 if (!wcd) 5160 return -ENOMEM; 5161 5162 wcd->dev = dev; 5163 ret = wcd9335_parse_dt(wcd); 5164 if (ret) { 5165 dev_err(dev, "Error parsing DT: %d\n", ret); 5166 return ret; 5167 } 5168 5169 ret = wcd9335_power_on_reset(wcd); 5170 if (ret) 5171 return ret; 5172 5173 dev_set_drvdata(dev, wcd); 5174 5175 return 0; 5176 } 5177 5178 static int wcd9335_slim_status(struct slim_device *sdev, 5179 enum slim_device_status status) 5180 { 5181 struct device *dev = &sdev->dev; 5182 struct device_node *ifc_dev_np; 5183 struct wcd9335_codec *wcd; 5184 int ret; 5185 5186 wcd = dev_get_drvdata(dev); 5187 5188 ifc_dev_np = of_parse_phandle(dev->of_node, "slim-ifc-dev", 0); 5189 if (!ifc_dev_np) { 5190 dev_err(dev, "No Interface device found\n"); 5191 return -EINVAL; 5192 } 5193 5194 wcd->slim = sdev; 5195 wcd->slim_ifc_dev = of_slim_get_device(sdev->ctrl, ifc_dev_np); 5196 of_node_put(ifc_dev_np); 5197 if (!wcd->slim_ifc_dev) { 5198 dev_err(dev, "Unable to get SLIM Interface device\n"); 5199 return -EINVAL; 5200 } 5201 5202 slim_get_logical_addr(wcd->slim_ifc_dev); 5203 5204 wcd->regmap = regmap_init_slimbus(sdev, &wcd9335_regmap_config); 5205 if (IS_ERR(wcd->regmap)) 5206 return dev_err_probe(dev, PTR_ERR(wcd->regmap), 5207 "Failed to allocate slim register map\n"); 5208 5209 wcd->if_regmap = regmap_init_slimbus(wcd->slim_ifc_dev, 5210 &wcd9335_ifc_regmap_config); 5211 if (IS_ERR(wcd->if_regmap)) 5212 return dev_err_probe(dev, PTR_ERR(wcd->if_regmap), 5213 "Failed to allocate ifc register map\n"); 5214 5215 ret = wcd9335_bring_up(wcd); 5216 if (ret) { 5217 dev_err(dev, "Failed to bringup WCD9335\n"); 5218 return ret; 5219 } 5220 5221 ret = wcd9335_irq_init(wcd); 5222 if (ret) 5223 return ret; 5224 5225 wcd9335_probe(wcd); 5226 5227 return 0; 5228 } 5229 5230 static const struct slim_device_id wcd9335_slim_id[] = { 5231 {SLIM_MANF_ID_QCOM, SLIM_PROD_CODE_WCD9335, 0x1, 0x0}, 5232 {} 5233 }; 5234 MODULE_DEVICE_TABLE(slim, wcd9335_slim_id); 5235 5236 static struct slim_driver wcd9335_slim_driver = { 5237 .driver = { 5238 .name = "wcd9335-slim", 5239 }, 5240 .probe = wcd9335_slim_probe, 5241 .device_status = wcd9335_slim_status, 5242 .id_table = wcd9335_slim_id, 5243 }; 5244 5245 module_slim_driver(wcd9335_slim_driver); 5246 MODULE_DESCRIPTION("WCD9335 slim driver"); 5247 MODULE_LICENSE("GPL v2"); 5248 MODULE_ALIAS("slim:217:1a0:*"); 5249