Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/firmware.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/printk.h> |
| 19 | #include <linux/ratelimit.h> |
| 20 | #include <linux/debugfs.h> |
| 21 | #include <linux/wait.h> |
| 22 | #include <linux/bitops.h> |
| 23 | #include <linux/clk.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/pm_runtime.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/gpio.h> |
| 28 | #include <linux/regmap.h> |
| 29 | #include <linux/spi/spi.h> |
| 30 | #include <linux/mfd/wcd9xxx/core.h> |
| 31 | #include <linux/mfd/wcd9xxx/wcd9xxx-irq.h> |
| 32 | #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h> |
| 33 | #include <linux/mfd/wcd934x/registers.h> |
| 34 | #include <linux/mfd/wcd9xxx/pdata.h> |
| 35 | #include <linux/regulator/consumer.h> |
| 36 | #include <linux/soundwire/swr-wcd.h> |
| 37 | #include <sound/pcm.h> |
| 38 | #include <sound/pcm_params.h> |
| 39 | #include <sound/soc.h> |
| 40 | #include <sound/soc-dapm.h> |
| 41 | #include <sound/tlv.h> |
| 42 | #include <sound/info.h> |
| 43 | #include "wcd934x.h" |
| 44 | #include "wcd934x-mbhc.h" |
| 45 | #include "wcd934x-routing.h" |
| 46 | #include "wcd934x-dsp-cntl.h" |
| 47 | #include "../wcd9xxx-common-v2.h" |
| 48 | #include "../wcd9xxx-resmgr-v2.h" |
| 49 | #include "../wcdcal-hwdep.h" |
| 50 | #include "wcd934x-dsd.h" |
| 51 | |
| 52 | #define WCD934X_RATES_MASK (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ |
| 53 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\ |
| 54 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\ |
| 55 | SNDRV_PCM_RATE_384000) |
| 56 | /* Fractional Rates */ |
| 57 | #define WCD934X_FRAC_RATES_MASK (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\ |
| 58 | SNDRV_PCM_RATE_176400) |
| 59 | |
| 60 | #define WCD934X_FORMATS_S16_S24_LE (SNDRV_PCM_FMTBIT_S16_LE | \ |
| 61 | SNDRV_PCM_FMTBIT_S24_LE) |
| 62 | |
| 63 | #define WCD934X_FORMATS_S16_S24_S32_LE (SNDRV_PCM_FMTBIT_S16_LE | \ |
| 64 | SNDRV_PCM_FMTBIT_S24_LE | \ |
| 65 | SNDRV_PCM_FMTBIT_S32_LE) |
| 66 | |
| 67 | #define WCD934X_FORMATS_S16_LE (SNDRV_PCM_FMTBIT_S16_LE) |
| 68 | |
| 69 | /* Macros for packing register writes into a U32 */ |
| 70 | #define WCD934X_PACKED_REG_SIZE sizeof(u32) |
| 71 | #define WCD934X_CODEC_UNPACK_ENTRY(packed, reg, mask, val) \ |
| 72 | do { \ |
| 73 | ((reg) = ((packed >> 16) & (0xffff))); \ |
| 74 | ((mask) = ((packed >> 8) & (0xff))); \ |
| 75 | ((val) = ((packed) & (0xff))); \ |
| 76 | } while (0) |
| 77 | |
| 78 | #define STRING(name) #name |
| 79 | #define WCD_DAPM_ENUM(name, reg, offset, text) \ |
| 80 | static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \ |
| 81 | static const struct snd_kcontrol_new name##_mux = \ |
| 82 | SOC_DAPM_ENUM(STRING(name), name##_enum) |
| 83 | |
| 84 | #define WCD_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \ |
| 85 | static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \ |
| 86 | static const struct snd_kcontrol_new name##_mux = \ |
| 87 | SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname) |
| 88 | |
| 89 | #define WCD_DAPM_MUX(name, shift, kctl) \ |
| 90 | SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux) |
| 91 | |
| 92 | /* |
| 93 | * Timeout in milli seconds and it is the wait time for |
| 94 | * slim channel removal interrupt to receive. |
| 95 | */ |
| 96 | #define WCD934X_SLIM_CLOSE_TIMEOUT 1000 |
| 97 | #define WCD934X_SLIM_IRQ_OVERFLOW (1 << 0) |
| 98 | #define WCD934X_SLIM_IRQ_UNDERFLOW (1 << 1) |
| 99 | #define WCD934X_SLIM_IRQ_PORT_CLOSED (1 << 2) |
| 100 | #define WCD934X_MCLK_CLK_12P288MHZ 12288000 |
| 101 | #define WCD934X_MCLK_CLK_9P6MHZ 9600000 |
| 102 | |
| 103 | #define WCD934X_INTERP_MUX_NUM_INPUTS 3 |
| 104 | #define WCD934X_NUM_INTERPOLATORS 9 |
| 105 | #define WCD934X_NUM_DECIMATORS 9 |
| 106 | #define WCD934X_RX_PATH_CTL_OFFSET 20 |
| 107 | |
| 108 | #define BYTE_BIT_MASK(nr) (1 << ((nr) % BITS_PER_BYTE)) |
| 109 | |
| 110 | #define WCD934X_REG_BITS 8 |
| 111 | #define WCD934X_MAX_VALID_ADC_MUX 13 |
| 112 | #define WCD934X_INVALID_ADC_MUX 9 |
| 113 | |
| 114 | #define WCD934X_AMIC_PWR_LEVEL_LP 0 |
| 115 | #define WCD934X_AMIC_PWR_LEVEL_DEFAULT 1 |
| 116 | #define WCD934X_AMIC_PWR_LEVEL_HP 2 |
| 117 | #define WCD934X_AMIC_PWR_LVL_MASK 0x60 |
| 118 | #define WCD934X_AMIC_PWR_LVL_SHIFT 0x5 |
| 119 | |
| 120 | #define WCD934X_DEC_PWR_LVL_MASK 0x06 |
| 121 | #define WCD934X_DEC_PWR_LVL_LP 0x02 |
| 122 | #define WCD934X_DEC_PWR_LVL_HP 0x04 |
| 123 | #define WCD934X_DEC_PWR_LVL_DF 0x00 |
| 124 | #define WCD934X_STRING_LEN 100 |
| 125 | |
| 126 | #define WCD934X_DIG_CORE_REG_MIN WCD934X_CDC_ANC0_CLK_RESET_CTL |
| 127 | #define WCD934X_DIG_CORE_REG_MAX 0xFFF |
| 128 | |
| 129 | #define WCD934X_MAX_MICBIAS 4 |
| 130 | #define DAPM_MICBIAS1_STANDALONE "MIC BIAS1 Standalone" |
| 131 | #define DAPM_MICBIAS2_STANDALONE "MIC BIAS2 Standalone" |
| 132 | #define DAPM_MICBIAS3_STANDALONE "MIC BIAS3 Standalone" |
| 133 | #define DAPM_MICBIAS4_STANDALONE "MIC BIAS4 Standalone" |
| 134 | |
| 135 | #define TX_HPF_CUT_OFF_FREQ_MASK 0x60 |
| 136 | #define CF_MIN_3DB_4HZ 0x0 |
| 137 | #define CF_MIN_3DB_75HZ 0x1 |
| 138 | #define CF_MIN_3DB_150HZ 0x2 |
| 139 | |
| 140 | #define CPE_ERR_WDOG_BITE BIT(0) |
| 141 | #define CPE_FATAL_IRQS CPE_ERR_WDOG_BITE |
| 142 | |
| 143 | #define WCD934X_MAD_AUDIO_FIRMWARE_PATH "wcd934x/wcd934x_mad_audio.bin" |
| 144 | |
| 145 | #define TAVIL_VERSION_ENTRY_SIZE 17 |
| 146 | |
| 147 | #define WCD934X_DIG_CORE_COLLAPSE_TIMER_MS (5 * 1000) |
| 148 | |
| 149 | enum { |
| 150 | POWER_COLLAPSE, |
| 151 | POWER_RESUME, |
| 152 | }; |
| 153 | |
| 154 | static int dig_core_collapse_enable = 1; |
| 155 | module_param(dig_core_collapse_enable, int, 0664); |
| 156 | MODULE_PARM_DESC(dig_core_collapse_enable, "enable/disable power gating"); |
| 157 | |
| 158 | /* dig_core_collapse timer in seconds */ |
| 159 | static int dig_core_collapse_timer = (WCD934X_DIG_CORE_COLLAPSE_TIMER_MS/1000); |
| 160 | module_param(dig_core_collapse_timer, int, 0664); |
| 161 | MODULE_PARM_DESC(dig_core_collapse_timer, "timer for power gating"); |
| 162 | |
| 163 | #define TAVIL_HPH_REG_RANGE_1 (WCD934X_HPH_R_DAC_CTL - WCD934X_HPH_CNP_EN + 1) |
| 164 | #define TAVIL_HPH_REG_RANGE_2 (WCD934X_HPH_NEW_ANA_HPH3 -\ |
| 165 | WCD934X_HPH_NEW_ANA_HPH2 + 1) |
| 166 | #define TAVIL_HPH_REG_RANGE_3 (WCD934X_HPH_NEW_INT_PA_RDAC_MISC3 -\ |
| 167 | WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL + 1) |
| 168 | #define TAVIL_HPH_TOTAL_REG (TAVIL_HPH_REG_RANGE_1 + TAVIL_HPH_REG_RANGE_2 +\ |
| 169 | TAVIL_HPH_REG_RANGE_3) |
| 170 | |
| 171 | enum { |
| 172 | VI_SENSE_1, |
| 173 | VI_SENSE_2, |
| 174 | AUDIO_NOMINAL, |
| 175 | HPH_PA_DELAY, |
Phani Kumar Uppalapati | b506bc0 | 2016-12-06 16:08:24 -0800 | [diff] [blame] | 176 | CLSH_Z_CONFIG, |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | enum { |
| 180 | AIF1_PB = 0, |
| 181 | AIF1_CAP, |
| 182 | AIF2_PB, |
| 183 | AIF2_CAP, |
| 184 | AIF3_PB, |
| 185 | AIF3_CAP, |
| 186 | AIF4_PB, |
| 187 | AIF4_VIFEED, |
| 188 | AIF4_MAD_TX, |
| 189 | NUM_CODEC_DAIS, |
| 190 | }; |
| 191 | |
| 192 | enum { |
| 193 | INTn_1_INP_SEL_ZERO = 0, |
| 194 | INTn_1_INP_SEL_DEC0, |
| 195 | INTn_1_INP_SEL_DEC1, |
| 196 | INTn_1_INP_SEL_IIR0, |
| 197 | INTn_1_INP_SEL_IIR1, |
| 198 | INTn_1_INP_SEL_RX0, |
| 199 | INTn_1_INP_SEL_RX1, |
| 200 | INTn_1_INP_SEL_RX2, |
| 201 | INTn_1_INP_SEL_RX3, |
| 202 | INTn_1_INP_SEL_RX4, |
| 203 | INTn_1_INP_SEL_RX5, |
| 204 | INTn_1_INP_SEL_RX6, |
| 205 | INTn_1_INP_SEL_RX7, |
| 206 | }; |
| 207 | |
| 208 | enum { |
| 209 | INTn_2_INP_SEL_ZERO = 0, |
| 210 | INTn_2_INP_SEL_RX0, |
| 211 | INTn_2_INP_SEL_RX1, |
| 212 | INTn_2_INP_SEL_RX2, |
| 213 | INTn_2_INP_SEL_RX3, |
| 214 | INTn_2_INP_SEL_RX4, |
| 215 | INTn_2_INP_SEL_RX5, |
| 216 | INTn_2_INP_SEL_RX6, |
| 217 | INTn_2_INP_SEL_RX7, |
| 218 | INTn_2_INP_SEL_PROXIMITY, |
| 219 | }; |
| 220 | |
| 221 | enum { |
| 222 | INTERP_MAIN_PATH, |
| 223 | INTERP_MIX_PATH, |
| 224 | }; |
| 225 | |
| 226 | struct tavil_idle_detect_config { |
| 227 | u8 hph_idle_thr; |
| 228 | u8 hph_idle_detect_en; |
| 229 | }; |
| 230 | |
| 231 | static const struct intr_data wcd934x_intr_table[] = { |
| 232 | {WCD9XXX_IRQ_SLIMBUS, false}, |
| 233 | {WCD934X_IRQ_MBHC_SW_DET, true}, |
| 234 | {WCD934X_IRQ_MBHC_BUTTON_PRESS_DET, true}, |
| 235 | {WCD934X_IRQ_MBHC_BUTTON_RELEASE_DET, true}, |
| 236 | {WCD934X_IRQ_MBHC_ELECT_INS_REM_DET, true}, |
| 237 | {WCD934X_IRQ_MBHC_ELECT_INS_REM_LEG_DET, true}, |
| 238 | {WCD934X_IRQ_MISC, false}, |
| 239 | {WCD934X_IRQ_HPH_PA_CNPL_COMPLETE, false}, |
| 240 | {WCD934X_IRQ_HPH_PA_CNPR_COMPLETE, false}, |
| 241 | {WCD934X_IRQ_EAR_PA_CNP_COMPLETE, false}, |
| 242 | {WCD934X_IRQ_LINE_PA1_CNP_COMPLETE, false}, |
| 243 | {WCD934X_IRQ_LINE_PA2_CNP_COMPLETE, false}, |
| 244 | {WCD934X_IRQ_SLNQ_ANALOG_ERROR, false}, |
| 245 | {WCD934X_IRQ_RESERVED_3, false}, |
| 246 | {WCD934X_IRQ_HPH_PA_OCPL_FAULT, false}, |
| 247 | {WCD934X_IRQ_HPH_PA_OCPR_FAULT, false}, |
| 248 | {WCD934X_IRQ_EAR_PA_OCP_FAULT, false}, |
| 249 | {WCD934X_IRQ_SOUNDWIRE, false}, |
| 250 | {WCD934X_IRQ_VDD_DIG_RAMP_COMPLETE, false}, |
| 251 | {WCD934X_IRQ_RCO_ERROR, false}, |
| 252 | {WCD934X_IRQ_CPE_ERROR, false}, |
| 253 | {WCD934X_IRQ_MAD_AUDIO, false}, |
| 254 | {WCD934X_IRQ_MAD_BEACON, false}, |
| 255 | {WCD934X_IRQ_CPE1_INTR, true}, |
| 256 | {WCD934X_IRQ_RESERVED_4, false}, |
| 257 | {WCD934X_IRQ_MAD_ULTRASOUND, false}, |
| 258 | {WCD934X_IRQ_VBAT_ATTACK, false}, |
| 259 | {WCD934X_IRQ_VBAT_RESTORE, false}, |
| 260 | }; |
| 261 | |
| 262 | struct tavil_cpr_reg_defaults { |
| 263 | int wr_data; |
| 264 | int wr_addr; |
| 265 | }; |
| 266 | |
| 267 | struct interp_sample_rate { |
| 268 | int sample_rate; |
| 269 | int rate_val; |
| 270 | }; |
| 271 | |
| 272 | static struct interp_sample_rate sr_val_tbl[] = { |
| 273 | {8000, 0x0}, {16000, 0x1}, {32000, 0x3}, {48000, 0x4}, {96000, 0x5}, |
| 274 | {192000, 0x6}, {384000, 0x7}, {44100, 0x9}, {88200, 0xA}, |
| 275 | {176400, 0xB}, {352800, 0xC}, |
| 276 | }; |
| 277 | |
| 278 | static const struct wcd9xxx_ch tavil_rx_chs[WCD934X_RX_MAX] = { |
| 279 | WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER, 0), |
| 280 | WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 1, 1), |
| 281 | WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 2, 2), |
| 282 | WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 3, 3), |
| 283 | WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 4, 4), |
| 284 | WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 5, 5), |
| 285 | WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 6, 6), |
| 286 | WCD9XXX_CH(WCD934X_RX_PORT_START_NUMBER + 7, 7), |
| 287 | }; |
| 288 | |
| 289 | static const struct wcd9xxx_ch tavil_tx_chs[WCD934X_TX_MAX] = { |
| 290 | WCD9XXX_CH(0, 0), |
| 291 | WCD9XXX_CH(1, 1), |
| 292 | WCD9XXX_CH(2, 2), |
| 293 | WCD9XXX_CH(3, 3), |
| 294 | WCD9XXX_CH(4, 4), |
| 295 | WCD9XXX_CH(5, 5), |
| 296 | WCD9XXX_CH(6, 6), |
| 297 | WCD9XXX_CH(7, 7), |
| 298 | WCD9XXX_CH(8, 8), |
| 299 | WCD9XXX_CH(9, 9), |
| 300 | WCD9XXX_CH(10, 10), |
| 301 | WCD9XXX_CH(11, 11), |
| 302 | WCD9XXX_CH(12, 12), |
| 303 | WCD9XXX_CH(13, 13), |
| 304 | WCD9XXX_CH(14, 14), |
| 305 | WCD9XXX_CH(15, 15), |
| 306 | }; |
| 307 | |
| 308 | static const u32 vport_slim_check_table[NUM_CODEC_DAIS] = { |
| 309 | 0, /* AIF1_PB */ |
| 310 | BIT(AIF2_CAP) | BIT(AIF3_CAP) | BIT(AIF4_MAD_TX), /* AIF1_CAP */ |
| 311 | 0, /* AIF2_PB */ |
| 312 | BIT(AIF1_CAP) | BIT(AIF3_CAP) | BIT(AIF4_MAD_TX), /* AIF2_CAP */ |
| 313 | 0, /* AIF3_PB */ |
| 314 | BIT(AIF1_CAP) | BIT(AIF2_CAP) | BIT(AIF4_MAD_TX), /* AIF3_CAP */ |
| 315 | 0, /* AIF4_PB */ |
| 316 | }; |
| 317 | |
| 318 | /* Codec supports 2 IIR filters */ |
| 319 | enum { |
| 320 | IIR0 = 0, |
| 321 | IIR1, |
| 322 | IIR_MAX, |
| 323 | }; |
| 324 | |
| 325 | /* Each IIR has 5 Filter Stages */ |
| 326 | enum { |
| 327 | BAND1 = 0, |
| 328 | BAND2, |
| 329 | BAND3, |
| 330 | BAND4, |
| 331 | BAND5, |
| 332 | BAND_MAX, |
| 333 | }; |
| 334 | |
| 335 | enum { |
| 336 | COMPANDER_1, /* HPH_L */ |
| 337 | COMPANDER_2, /* HPH_R */ |
| 338 | COMPANDER_3, /* LO1_DIFF */ |
| 339 | COMPANDER_4, /* LO2_DIFF */ |
| 340 | COMPANDER_5, /* LO3_SE - not used in Tavil */ |
| 341 | COMPANDER_6, /* LO4_SE - not used in Tavil */ |
| 342 | COMPANDER_7, /* SWR SPK CH1 */ |
| 343 | COMPANDER_8, /* SWR SPK CH2 */ |
| 344 | COMPANDER_MAX, |
| 345 | }; |
| 346 | |
| 347 | enum { |
| 348 | ASRC_IN_HPHL, |
| 349 | ASRC_IN_LO1, |
| 350 | ASRC_IN_HPHR, |
| 351 | ASRC_IN_LO2, |
| 352 | ASRC_IN_SPKR1, |
| 353 | ASRC_IN_SPKR2, |
| 354 | ASRC_INVALID, |
| 355 | }; |
| 356 | |
| 357 | enum { |
| 358 | ASRC0, |
| 359 | ASRC1, |
| 360 | ASRC2, |
| 361 | ASRC3, |
| 362 | ASRC_MAX, |
| 363 | }; |
| 364 | |
| 365 | enum { |
| 366 | CONV_88P2K_TO_384K, |
| 367 | CONV_96K_TO_352P8K, |
| 368 | CONV_352P8K_TO_384K, |
| 369 | CONV_384K_TO_352P8K, |
| 370 | CONV_384K_TO_384K, |
| 371 | CONV_96K_TO_384K, |
| 372 | }; |
| 373 | |
| 374 | static struct afe_param_slimbus_slave_port_cfg tavil_slimbus_slave_port_cfg = { |
| 375 | .minor_version = 1, |
| 376 | .slimbus_dev_id = AFE_SLIMBUS_DEVICE_1, |
| 377 | .slave_dev_pgd_la = 0, |
| 378 | .slave_dev_intfdev_la = 0, |
| 379 | .bit_width = 16, |
| 380 | .data_format = 0, |
| 381 | .num_channels = 1 |
| 382 | }; |
| 383 | |
| 384 | static struct afe_param_cdc_reg_page_cfg tavil_cdc_reg_page_cfg = { |
| 385 | .minor_version = AFE_API_VERSION_CDC_REG_PAGE_CFG, |
| 386 | .enable = 1, |
| 387 | .proc_id = AFE_CDC_REG_PAGE_ASSIGN_PROC_ID_1, |
| 388 | }; |
| 389 | |
| 390 | static struct afe_param_cdc_reg_cfg audio_reg_cfg[] = { |
| 391 | { |
| 392 | 1, |
| 393 | (WCD934X_REGISTER_START_OFFSET + WCD934X_SOC_MAD_MAIN_CTL_1), |
| 394 | HW_MAD_AUDIO_ENABLE, 0x1, WCD934X_REG_BITS, 0 |
| 395 | }, |
| 396 | { |
| 397 | 1, |
| 398 | (WCD934X_REGISTER_START_OFFSET + WCD934X_SOC_MAD_AUDIO_CTL_3), |
| 399 | HW_MAD_AUDIO_SLEEP_TIME, 0xF, WCD934X_REG_BITS, 0 |
| 400 | }, |
| 401 | { |
| 402 | 1, |
| 403 | (WCD934X_REGISTER_START_OFFSET + WCD934X_SOC_MAD_AUDIO_CTL_4), |
| 404 | HW_MAD_TX_AUDIO_SWITCH_OFF, 0x1, WCD934X_REG_BITS, 0 |
| 405 | }, |
| 406 | { |
| 407 | 1, |
| 408 | (WCD934X_REGISTER_START_OFFSET + WCD934X_INTR_CFG), |
| 409 | MAD_AUDIO_INT_DEST_SELECT_REG, 0x2, WCD934X_REG_BITS, 0 |
| 410 | }, |
| 411 | { |
| 412 | 1, |
| 413 | (WCD934X_REGISTER_START_OFFSET + WCD934X_INTR_PIN2_MASK3), |
| 414 | MAD_AUDIO_INT_MASK_REG, 0x1, WCD934X_REG_BITS, 0 |
| 415 | }, |
| 416 | { |
| 417 | 1, |
| 418 | (WCD934X_REGISTER_START_OFFSET + WCD934X_INTR_PIN2_STATUS3), |
| 419 | MAD_AUDIO_INT_STATUS_REG, 0x1, WCD934X_REG_BITS, 0 |
| 420 | }, |
| 421 | { |
| 422 | 1, |
| 423 | (WCD934X_REGISTER_START_OFFSET + WCD934X_INTR_PIN2_CLEAR3), |
| 424 | MAD_AUDIO_INT_CLEAR_REG, 0x1, WCD934X_REG_BITS, 0 |
| 425 | }, |
| 426 | { |
| 427 | 1, |
| 428 | (WCD934X_REGISTER_START_OFFSET + WCD934X_SB_PGD_PORT_TX_BASE), |
| 429 | SB_PGD_PORT_TX_WATERMARK_N, 0x1E, WCD934X_REG_BITS, 0x1 |
| 430 | }, |
| 431 | { |
| 432 | 1, |
| 433 | (WCD934X_REGISTER_START_OFFSET + WCD934X_SB_PGD_PORT_TX_BASE), |
| 434 | SB_PGD_PORT_TX_ENABLE_N, 0x1, WCD934X_REG_BITS, 0x1 |
| 435 | }, |
| 436 | { |
| 437 | 1, |
| 438 | (WCD934X_REGISTER_START_OFFSET + WCD934X_SB_PGD_PORT_RX_BASE), |
| 439 | SB_PGD_PORT_RX_WATERMARK_N, 0x1E, WCD934X_REG_BITS, 0x1 |
| 440 | }, |
| 441 | { |
| 442 | 1, |
| 443 | (WCD934X_REGISTER_START_OFFSET + WCD934X_SB_PGD_PORT_RX_BASE), |
| 444 | SB_PGD_PORT_RX_ENABLE_N, 0x1, WCD934X_REG_BITS, 0x1 |
| 445 | }, |
| 446 | { |
| 447 | 1, |
| 448 | (WCD934X_REGISTER_START_OFFSET + |
| 449 | WCD934X_CDC_ANC0_IIR_ADAPT_CTL), |
| 450 | AANC_FF_GAIN_ADAPTIVE, 0x4, WCD934X_REG_BITS, 0 |
| 451 | }, |
| 452 | { |
| 453 | 1, |
| 454 | (WCD934X_REGISTER_START_OFFSET + |
| 455 | WCD934X_CDC_ANC0_IIR_ADAPT_CTL), |
| 456 | AANC_FFGAIN_ADAPTIVE_EN, 0x8, WCD934X_REG_BITS, 0 |
| 457 | }, |
| 458 | { |
| 459 | 1, |
| 460 | (WCD934X_REGISTER_START_OFFSET + |
| 461 | WCD934X_CDC_ANC0_FF_A_GAIN_CTL), |
| 462 | AANC_GAIN_CONTROL, 0xFF, WCD934X_REG_BITS, 0 |
| 463 | }, |
| 464 | { |
| 465 | 1, |
| 466 | (WCD934X_REGISTER_START_OFFSET + |
| 467 | SB_PGD_TX_PORT_MULTI_CHANNEL_0(0)), |
| 468 | SB_PGD_TX_PORTn_MULTI_CHNL_0, 0xFF, WCD934X_REG_BITS, 0x4 |
| 469 | }, |
| 470 | { |
| 471 | 1, |
| 472 | (WCD934X_REGISTER_START_OFFSET + |
| 473 | SB_PGD_TX_PORT_MULTI_CHANNEL_1(0)), |
| 474 | SB_PGD_TX_PORTn_MULTI_CHNL_1, 0xFF, WCD934X_REG_BITS, 0x4 |
| 475 | }, |
| 476 | { |
| 477 | 1, |
| 478 | (WCD934X_REGISTER_START_OFFSET + |
| 479 | SB_PGD_RX_PORT_MULTI_CHANNEL_0(0x180, 0)), |
| 480 | SB_PGD_RX_PORTn_MULTI_CHNL_0, 0xFF, WCD934X_REG_BITS, 0x4 |
| 481 | }, |
| 482 | { |
| 483 | 1, |
| 484 | (WCD934X_REGISTER_START_OFFSET + |
| 485 | SB_PGD_RX_PORT_MULTI_CHANNEL_0(0x181, 0)), |
| 486 | SB_PGD_RX_PORTn_MULTI_CHNL_1, 0xFF, WCD934X_REG_BITS, 0x4 |
| 487 | }, |
| 488 | }; |
| 489 | |
| 490 | static struct afe_param_cdc_reg_cfg_data tavil_audio_reg_cfg = { |
| 491 | .num_registers = ARRAY_SIZE(audio_reg_cfg), |
| 492 | .reg_data = audio_reg_cfg, |
| 493 | }; |
| 494 | |
| 495 | static struct afe_param_id_cdc_aanc_version tavil_cdc_aanc_version = { |
| 496 | .cdc_aanc_minor_version = AFE_API_VERSION_CDC_AANC_VERSION, |
| 497 | .aanc_hw_version = AANC_HW_BLOCK_VERSION_2, |
| 498 | }; |
| 499 | |
| 500 | static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0); |
| 501 | static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1); |
| 502 | static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1); |
| 503 | |
| 504 | #define WCD934X_TX_UNMUTE_DELAY_MS 25 |
| 505 | |
| 506 | static int tx_unmute_delay = WCD934X_TX_UNMUTE_DELAY_MS; |
| 507 | module_param(tx_unmute_delay, int, 0664); |
| 508 | MODULE_PARM_DESC(tx_unmute_delay, "delay to unmute the tx path"); |
| 509 | |
| 510 | |
| 511 | /* Hold instance to soundwire platform device */ |
| 512 | struct tavil_swr_ctrl_data { |
| 513 | struct platform_device *swr_pdev; |
| 514 | }; |
| 515 | |
| 516 | struct wcd_swr_ctrl_platform_data { |
| 517 | void *handle; /* holds codec private data */ |
| 518 | int (*read)(void *handle, int reg); |
| 519 | int (*write)(void *handle, int reg, int val); |
| 520 | int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len); |
| 521 | int (*clk)(void *handle, bool enable); |
| 522 | int (*handle_irq)(void *handle, |
| 523 | irqreturn_t (*swrm_irq_handler)(int irq, void *data), |
| 524 | void *swrm_handle, int action); |
| 525 | }; |
| 526 | |
| 527 | /* Holds all Soundwire and speaker related information */ |
| 528 | struct wcd934x_swr { |
| 529 | struct tavil_swr_ctrl_data *ctrl_data; |
| 530 | struct wcd_swr_ctrl_platform_data plat_data; |
| 531 | struct mutex read_mutex; |
| 532 | struct mutex write_mutex; |
| 533 | struct mutex clk_mutex; |
| 534 | int spkr_gain_offset; |
| 535 | int spkr_mode; |
| 536 | int clk_users; |
| 537 | int rx_7_count; |
| 538 | int rx_8_count; |
| 539 | }; |
| 540 | |
| 541 | struct tx_mute_work { |
| 542 | struct tavil_priv *tavil; |
| 543 | u8 decimator; |
| 544 | struct delayed_work dwork; |
| 545 | }; |
| 546 | |
| 547 | #define WCD934X_SPK_ANC_EN_DELAY_MS 350 |
| 548 | static int spk_anc_en_delay = WCD934X_SPK_ANC_EN_DELAY_MS; |
| 549 | module_param(spk_anc_en_delay, int, 0664); |
| 550 | MODULE_PARM_DESC(spk_anc_en_delay, "delay to enable anc in speaker path"); |
| 551 | |
| 552 | struct spk_anc_work { |
| 553 | struct tavil_priv *tavil; |
| 554 | struct delayed_work dwork; |
| 555 | }; |
| 556 | |
| 557 | struct hpf_work { |
| 558 | struct tavil_priv *tavil; |
| 559 | u8 decimator; |
| 560 | u8 hpf_cut_off_freq; |
| 561 | struct delayed_work dwork; |
| 562 | }; |
| 563 | |
| 564 | struct tavil_priv { |
| 565 | struct device *dev; |
| 566 | struct wcd9xxx *wcd9xxx; |
| 567 | struct snd_soc_codec *codec; |
| 568 | u32 rx_bias_count; |
| 569 | s32 dmic_0_1_clk_cnt; |
| 570 | s32 dmic_2_3_clk_cnt; |
| 571 | s32 dmic_4_5_clk_cnt; |
| 572 | s32 micb_ref[TAVIL_MAX_MICBIAS]; |
| 573 | s32 pullup_ref[TAVIL_MAX_MICBIAS]; |
| 574 | |
| 575 | /* ANC related */ |
| 576 | u32 anc_slot; |
| 577 | bool anc_func; |
| 578 | |
| 579 | /* compander */ |
| 580 | int comp_enabled[COMPANDER_MAX]; |
| 581 | int ear_spkr_gain; |
| 582 | |
| 583 | /* class h specific data */ |
| 584 | struct wcd_clsh_cdc_data clsh_d; |
| 585 | /* Tavil Interpolator Mode Select for EAR, HPH_L and HPH_R */ |
| 586 | u32 hph_mode; |
| 587 | |
| 588 | /* Mad switch reference count */ |
| 589 | int mad_switch_cnt; |
| 590 | |
| 591 | /* track tavil interface type */ |
| 592 | u8 intf_type; |
| 593 | |
| 594 | /* to track the status */ |
| 595 | unsigned long status_mask; |
| 596 | |
| 597 | struct afe_param_cdc_slimbus_slave_cfg slimbus_slave_cfg; |
| 598 | |
| 599 | /* num of slim ports required */ |
| 600 | struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS]; |
| 601 | /* Port values for Rx and Tx codec_dai */ |
| 602 | unsigned int rx_port_value[WCD934X_RX_MAX]; |
| 603 | unsigned int tx_port_value; |
| 604 | |
| 605 | struct wcd9xxx_resmgr_v2 *resmgr; |
| 606 | struct wcd934x_swr swr; |
| 607 | struct mutex micb_lock; |
| 608 | |
| 609 | struct delayed_work power_gate_work; |
| 610 | struct mutex power_lock; |
| 611 | |
| 612 | struct clk *wcd_ext_clk; |
| 613 | |
| 614 | /* mbhc module */ |
| 615 | struct wcd934x_mbhc *mbhc; |
| 616 | |
| 617 | struct mutex codec_mutex; |
| 618 | struct work_struct tavil_add_child_devices_work; |
| 619 | struct hpf_work tx_hpf_work[WCD934X_NUM_DECIMATORS]; |
| 620 | struct tx_mute_work tx_mute_dwork[WCD934X_NUM_DECIMATORS]; |
| 621 | struct spk_anc_work spk_anc_dwork; |
| 622 | |
| 623 | unsigned int vi_feed_value; |
| 624 | |
| 625 | /* DSP control */ |
| 626 | struct wcd_dsp_cntl *wdsp_cntl; |
| 627 | |
| 628 | /* cal info for codec */ |
| 629 | struct fw_info *fw_data; |
| 630 | |
| 631 | /* Entry for version info */ |
| 632 | struct snd_info_entry *entry; |
| 633 | struct snd_info_entry *version_entry; |
| 634 | |
| 635 | /* SVS voting related */ |
| 636 | struct mutex svs_mutex; |
| 637 | int svs_ref_cnt; |
| 638 | |
| 639 | int native_clk_users; |
| 640 | /* ASRC users count */ |
| 641 | int asrc_users[ASRC_MAX]; |
| 642 | int asrc_output_mode[ASRC_MAX]; |
| 643 | /* Main path clock users count */ |
| 644 | int main_clk_users[WCD934X_NUM_INTERPOLATORS]; |
| 645 | struct tavil_dsd_config *dsd_config; |
| 646 | struct tavil_idle_detect_config idle_det_cfg; |
| 647 | |
| 648 | int power_active_ref; |
| 649 | }; |
| 650 | |
| 651 | static const struct tavil_reg_mask_val tavil_spkr_default[] = { |
| 652 | {WCD934X_CDC_COMPANDER7_CTL3, 0x80, 0x80}, |
| 653 | {WCD934X_CDC_COMPANDER8_CTL3, 0x80, 0x80}, |
| 654 | {WCD934X_CDC_COMPANDER7_CTL7, 0x01, 0x01}, |
| 655 | {WCD934X_CDC_COMPANDER8_CTL7, 0x01, 0x01}, |
| 656 | {WCD934X_CDC_BOOST0_BOOST_CTL, 0x7C, 0x50}, |
| 657 | {WCD934X_CDC_BOOST1_BOOST_CTL, 0x7C, 0x50}, |
| 658 | }; |
| 659 | |
| 660 | static const struct tavil_reg_mask_val tavil_spkr_mode1[] = { |
| 661 | {WCD934X_CDC_COMPANDER7_CTL3, 0x80, 0x00}, |
| 662 | {WCD934X_CDC_COMPANDER8_CTL3, 0x80, 0x00}, |
| 663 | {WCD934X_CDC_COMPANDER7_CTL7, 0x01, 0x00}, |
| 664 | {WCD934X_CDC_COMPANDER8_CTL7, 0x01, 0x00}, |
| 665 | {WCD934X_CDC_BOOST0_BOOST_CTL, 0x7C, 0x44}, |
| 666 | {WCD934X_CDC_BOOST1_BOOST_CTL, 0x7C, 0x44}, |
| 667 | }; |
| 668 | |
| 669 | static int __tavil_enable_efuse_sensing(struct tavil_priv *tavil); |
| 670 | |
| 671 | /* |
| 672 | * wcd934x_get_codec_info: Get codec specific information |
| 673 | * |
| 674 | * @wcd9xxx: pointer to wcd9xxx structure |
| 675 | * @wcd_type: pointer to wcd9xxx_codec_type structure |
| 676 | * |
| 677 | * Returns 0 for success or negative error code for failure |
| 678 | */ |
| 679 | int wcd934x_get_codec_info(struct wcd9xxx *wcd9xxx, |
| 680 | struct wcd9xxx_codec_type *wcd_type) |
| 681 | { |
| 682 | u16 id_minor, id_major; |
| 683 | struct regmap *wcd_regmap; |
| 684 | int rc, version = -1; |
| 685 | |
| 686 | if (!wcd9xxx || !wcd_type) |
| 687 | return -EINVAL; |
| 688 | |
| 689 | if (!wcd9xxx->regmap) { |
| 690 | dev_err(wcd9xxx->dev, "%s: wcd9xxx regmap is null\n", __func__); |
| 691 | return -EINVAL; |
| 692 | } |
| 693 | wcd_regmap = wcd9xxx->regmap; |
| 694 | |
| 695 | rc = regmap_bulk_read(wcd_regmap, WCD934X_CHIP_TIER_CTRL_CHIP_ID_BYTE0, |
| 696 | (u8 *)&id_minor, sizeof(u16)); |
| 697 | if (rc) |
| 698 | return -EINVAL; |
| 699 | |
| 700 | rc = regmap_bulk_read(wcd_regmap, WCD934X_CHIP_TIER_CTRL_CHIP_ID_BYTE2, |
| 701 | (u8 *)&id_major, sizeof(u16)); |
| 702 | if (rc) |
| 703 | return -EINVAL; |
| 704 | |
| 705 | dev_info(wcd9xxx->dev, "%s: wcd9xxx chip id major 0x%x, minor 0x%x\n", |
| 706 | __func__, id_major, id_minor); |
| 707 | |
| 708 | if (id_major != TAVIL_MAJOR) |
| 709 | goto version_unknown; |
| 710 | |
| 711 | /* |
| 712 | * As fine version info cannot be retrieved before tavil probe. |
| 713 | * Assign coarse versions for possible future use before tavil probe. |
| 714 | */ |
| 715 | if (id_minor == cpu_to_le16(0)) |
| 716 | version = TAVIL_VERSION_1_0; |
| 717 | else if (id_minor == cpu_to_le16(0x01)) |
| 718 | version = TAVIL_VERSION_1_1; |
| 719 | |
| 720 | version_unknown: |
| 721 | if (version < 0) |
| 722 | dev_err(wcd9xxx->dev, "%s: wcd934x version unknown\n", |
| 723 | __func__); |
| 724 | |
| 725 | /* Fill codec type info */ |
| 726 | wcd_type->id_major = id_major; |
| 727 | wcd_type->id_minor = id_minor; |
| 728 | wcd_type->num_irqs = WCD934X_NUM_IRQS; |
| 729 | wcd_type->version = version; |
| 730 | wcd_type->slim_slave_type = WCD9XXX_SLIM_SLAVE_ADDR_TYPE_1; |
| 731 | wcd_type->i2c_chip_status = 0x01; |
| 732 | wcd_type->intr_tbl = wcd934x_intr_table; |
| 733 | wcd_type->intr_tbl_size = ARRAY_SIZE(wcd934x_intr_table); |
| 734 | |
| 735 | wcd_type->intr_reg[WCD9XXX_INTR_STATUS_BASE] = |
| 736 | WCD934X_INTR_PIN1_STATUS0; |
| 737 | wcd_type->intr_reg[WCD9XXX_INTR_CLEAR_BASE] = |
| 738 | WCD934X_INTR_PIN1_CLEAR0; |
| 739 | wcd_type->intr_reg[WCD9XXX_INTR_MASK_BASE] = |
| 740 | WCD934X_INTR_PIN1_MASK0; |
| 741 | wcd_type->intr_reg[WCD9XXX_INTR_LEVEL_BASE] = |
| 742 | WCD934X_INTR_LEVEL0; |
| 743 | wcd_type->intr_reg[WCD9XXX_INTR_CLR_COMMIT] = |
| 744 | WCD934X_INTR_CLR_COMMIT; |
| 745 | |
| 746 | return rc; |
| 747 | } |
| 748 | EXPORT_SYMBOL(wcd934x_get_codec_info); |
| 749 | |
| 750 | /* |
| 751 | * wcd934x_bringdown: Bringdown WCD Codec |
| 752 | * |
| 753 | * @wcd9xxx: Pointer to wcd9xxx structure |
| 754 | * |
| 755 | * Returns 0 for success or negative error code for failure |
| 756 | */ |
| 757 | int wcd934x_bringdown(struct wcd9xxx *wcd9xxx) |
| 758 | { |
| 759 | if (!wcd9xxx || !wcd9xxx->regmap) |
| 760 | return -EINVAL; |
| 761 | |
| 762 | regmap_write(wcd9xxx->regmap, WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, |
| 763 | 0x04); |
| 764 | |
| 765 | return 0; |
| 766 | } |
| 767 | EXPORT_SYMBOL(wcd934x_bringdown); |
| 768 | |
| 769 | /* |
| 770 | * wcd934x_bringup: Bringup WCD Codec |
| 771 | * |
| 772 | * @wcd9xxx: Pointer to the wcd9xxx structure |
| 773 | * |
| 774 | * Returns 0 for success or negative error code for failure |
| 775 | */ |
| 776 | int wcd934x_bringup(struct wcd9xxx *wcd9xxx) |
| 777 | { |
| 778 | struct regmap *wcd_regmap; |
| 779 | |
| 780 | if (!wcd9xxx) |
| 781 | return -EINVAL; |
| 782 | |
| 783 | if (!wcd9xxx->regmap) { |
| 784 | dev_err(wcd9xxx->dev, "%s: wcd9xxx regmap is null!\n", |
| 785 | __func__); |
| 786 | return -EINVAL; |
| 787 | } |
| 788 | wcd_regmap = wcd9xxx->regmap; |
| 789 | |
| 790 | regmap_write(wcd_regmap, WCD934X_CODEC_RPM_RST_CTL, 0x01); |
| 791 | regmap_write(wcd_regmap, WCD934X_SIDO_NEW_VOUT_A_STARTUP, 0x19); |
| 792 | regmap_write(wcd_regmap, WCD934X_SIDO_NEW_VOUT_D_STARTUP, 0x15); |
| 793 | regmap_write(wcd_regmap, WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x5); |
| 794 | regmap_write(wcd_regmap, WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x7); |
| 795 | regmap_write(wcd_regmap, WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x3); |
| 796 | regmap_write(wcd_regmap, WCD934X_CODEC_RPM_RST_CTL, 0x3); |
| 797 | regmap_write(wcd_regmap, WCD934X_CODEC_RPM_RST_CTL, 0x7); |
| 798 | |
| 799 | return 0; |
| 800 | } |
| 801 | EXPORT_SYMBOL(wcd934x_bringup); |
| 802 | |
| 803 | /** |
| 804 | * tavil_set_spkr_gain_offset - offset the speaker path |
| 805 | * gain with the given offset value. |
| 806 | * |
| 807 | * @codec: codec instance |
| 808 | * @offset: Indicates speaker path gain offset value. |
| 809 | * |
| 810 | * Returns 0 on success or -EINVAL on error. |
| 811 | */ |
| 812 | int tavil_set_spkr_gain_offset(struct snd_soc_codec *codec, int offset) |
| 813 | { |
| 814 | struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec); |
| 815 | |
| 816 | if (!priv) |
| 817 | return -EINVAL; |
| 818 | |
| 819 | priv->swr.spkr_gain_offset = offset; |
| 820 | return 0; |
| 821 | } |
| 822 | EXPORT_SYMBOL(tavil_set_spkr_gain_offset); |
| 823 | |
| 824 | /** |
| 825 | * tavil_set_spkr_mode - Configures speaker compander and smartboost |
| 826 | * settings based on speaker mode. |
| 827 | * |
| 828 | * @codec: codec instance |
| 829 | * @mode: Indicates speaker configuration mode. |
| 830 | * |
| 831 | * Returns 0 on success or -EINVAL on error. |
| 832 | */ |
| 833 | int tavil_set_spkr_mode(struct snd_soc_codec *codec, int mode) |
| 834 | { |
| 835 | struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec); |
| 836 | int i; |
| 837 | const struct tavil_reg_mask_val *regs; |
| 838 | int size; |
| 839 | |
| 840 | if (!priv) |
| 841 | return -EINVAL; |
| 842 | |
| 843 | switch (mode) { |
| 844 | case WCD934X_SPKR_MODE_1: |
| 845 | regs = tavil_spkr_mode1; |
| 846 | size = ARRAY_SIZE(tavil_spkr_mode1); |
| 847 | break; |
| 848 | default: |
| 849 | regs = tavil_spkr_default; |
| 850 | size = ARRAY_SIZE(tavil_spkr_default); |
| 851 | break; |
| 852 | } |
| 853 | |
| 854 | priv->swr.spkr_mode = mode; |
| 855 | for (i = 0; i < size; i++) |
| 856 | snd_soc_update_bits(codec, regs[i].reg, |
| 857 | regs[i].mask, regs[i].val); |
| 858 | return 0; |
| 859 | } |
| 860 | EXPORT_SYMBOL(tavil_set_spkr_mode); |
| 861 | |
| 862 | /** |
| 863 | * tavil_get_afe_config - returns specific codec configuration to afe to write |
| 864 | * |
| 865 | * @codec: codec instance |
| 866 | * @config_type: Indicates type of configuration to write. |
| 867 | */ |
| 868 | void *tavil_get_afe_config(struct snd_soc_codec *codec, |
| 869 | enum afe_config_type config_type) |
| 870 | { |
| 871 | struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec); |
| 872 | |
| 873 | switch (config_type) { |
| 874 | case AFE_SLIMBUS_SLAVE_CONFIG: |
| 875 | return &priv->slimbus_slave_cfg; |
| 876 | case AFE_CDC_REGISTERS_CONFIG: |
| 877 | return &tavil_audio_reg_cfg; |
| 878 | case AFE_SLIMBUS_SLAVE_PORT_CONFIG: |
| 879 | return &tavil_slimbus_slave_port_cfg; |
| 880 | case AFE_AANC_VERSION: |
| 881 | return &tavil_cdc_aanc_version; |
| 882 | case AFE_CDC_REGISTER_PAGE_CONFIG: |
| 883 | return &tavil_cdc_reg_page_cfg; |
| 884 | default: |
| 885 | dev_info(codec->dev, "%s: Unknown config_type 0x%x\n", |
| 886 | __func__, config_type); |
| 887 | return NULL; |
| 888 | } |
| 889 | } |
| 890 | EXPORT_SYMBOL(tavil_get_afe_config); |
| 891 | |
| 892 | static bool is_tavil_playback_dai(int dai_id) |
| 893 | { |
| 894 | if ((dai_id == AIF1_PB) || (dai_id == AIF2_PB) || |
| 895 | (dai_id == AIF3_PB) || (dai_id == AIF4_PB)) |
| 896 | return true; |
| 897 | |
| 898 | return false; |
| 899 | } |
| 900 | |
| 901 | static int tavil_find_playback_dai_id_for_port(int port_id, |
| 902 | struct tavil_priv *tavil) |
| 903 | { |
| 904 | struct wcd9xxx_codec_dai_data *dai; |
| 905 | struct wcd9xxx_ch *ch; |
| 906 | int i, slv_port_id; |
| 907 | |
| 908 | for (i = AIF1_PB; i < NUM_CODEC_DAIS; i++) { |
| 909 | if (!is_tavil_playback_dai(i)) |
| 910 | continue; |
| 911 | |
| 912 | dai = &tavil->dai[i]; |
| 913 | list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) { |
| 914 | slv_port_id = wcd9xxx_get_slave_port(ch->ch_num); |
| 915 | if ((slv_port_id > 0) && (slv_port_id == port_id)) |
| 916 | return i; |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | return -EINVAL; |
| 921 | } |
| 922 | |
| 923 | static void tavil_vote_svs(struct tavil_priv *tavil, bool vote) |
| 924 | { |
| 925 | struct wcd9xxx *wcd9xxx; |
| 926 | |
| 927 | wcd9xxx = tavil->wcd9xxx; |
| 928 | |
| 929 | mutex_lock(&tavil->svs_mutex); |
| 930 | if (vote) { |
| 931 | tavil->svs_ref_cnt++; |
| 932 | if (tavil->svs_ref_cnt == 1) |
| 933 | regmap_update_bits(wcd9xxx->regmap, |
| 934 | WCD934X_CPE_SS_PWR_SYS_PSTATE_CTL_0, |
| 935 | 0x01, 0x01); |
| 936 | } else { |
| 937 | /* Do not decrement ref count if it is already 0 */ |
| 938 | if (tavil->svs_ref_cnt == 0) |
| 939 | goto done; |
| 940 | |
| 941 | tavil->svs_ref_cnt--; |
| 942 | if (tavil->svs_ref_cnt == 0) |
| 943 | regmap_update_bits(wcd9xxx->regmap, |
| 944 | WCD934X_CPE_SS_PWR_SYS_PSTATE_CTL_0, |
| 945 | 0x01, 0x00); |
| 946 | } |
| 947 | done: |
| 948 | dev_dbg(tavil->dev, "%s: vote = %s, updated ref cnt = %u\n", __func__, |
| 949 | vote ? "vote" : "Unvote", tavil->svs_ref_cnt); |
| 950 | mutex_unlock(&tavil->svs_mutex); |
| 951 | } |
| 952 | |
| 953 | static int tavil_get_anc_slot(struct snd_kcontrol *kcontrol, |
| 954 | struct snd_ctl_elem_value *ucontrol) |
| 955 | { |
| 956 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 957 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 958 | |
| 959 | ucontrol->value.integer.value[0] = tavil->anc_slot; |
| 960 | return 0; |
| 961 | } |
| 962 | |
| 963 | static int tavil_put_anc_slot(struct snd_kcontrol *kcontrol, |
| 964 | struct snd_ctl_elem_value *ucontrol) |
| 965 | { |
| 966 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 967 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 968 | |
| 969 | tavil->anc_slot = ucontrol->value.integer.value[0]; |
| 970 | return 0; |
| 971 | } |
| 972 | |
| 973 | static int tavil_get_anc_func(struct snd_kcontrol *kcontrol, |
| 974 | struct snd_ctl_elem_value *ucontrol) |
| 975 | { |
| 976 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 977 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 978 | |
| 979 | ucontrol->value.integer.value[0] = (tavil->anc_func == true ? 1 : 0); |
| 980 | return 0; |
| 981 | } |
| 982 | |
| 983 | static int tavil_put_anc_func(struct snd_kcontrol *kcontrol, |
| 984 | struct snd_ctl_elem_value *ucontrol) |
| 985 | { |
| 986 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 987 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 988 | struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); |
| 989 | |
| 990 | mutex_lock(&tavil->codec_mutex); |
| 991 | tavil->anc_func = (!ucontrol->value.integer.value[0] ? false : true); |
| 992 | dev_dbg(codec->dev, "%s: anc_func %x", __func__, tavil->anc_func); |
| 993 | |
| 994 | if (tavil->anc_func == true) { |
| 995 | snd_soc_dapm_enable_pin(dapm, "ANC EAR PA"); |
| 996 | snd_soc_dapm_enable_pin(dapm, "ANC EAR"); |
| 997 | snd_soc_dapm_enable_pin(dapm, "ANC SPK1 PA"); |
| 998 | snd_soc_dapm_disable_pin(dapm, "EAR PA"); |
| 999 | snd_soc_dapm_disable_pin(dapm, "EAR"); |
| 1000 | } else { |
| 1001 | snd_soc_dapm_disable_pin(dapm, "ANC EAR PA"); |
| 1002 | snd_soc_dapm_disable_pin(dapm, "ANC EAR"); |
| 1003 | snd_soc_dapm_disable_pin(dapm, "ANC SPK1 PA"); |
| 1004 | snd_soc_dapm_enable_pin(dapm, "EAR PA"); |
| 1005 | snd_soc_dapm_enable_pin(dapm, "EAR"); |
| 1006 | } |
| 1007 | mutex_unlock(&tavil->codec_mutex); |
| 1008 | |
| 1009 | snd_soc_dapm_sync(dapm); |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
| 1013 | static int tavil_codec_enable_anc(struct snd_soc_dapm_widget *w, |
| 1014 | struct snd_kcontrol *kcontrol, int event) |
| 1015 | { |
| 1016 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 1017 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 1018 | const char *filename; |
| 1019 | const struct firmware *fw; |
| 1020 | int i; |
| 1021 | int ret = 0; |
| 1022 | int num_anc_slots; |
| 1023 | struct wcd9xxx_anc_header *anc_head; |
| 1024 | struct firmware_cal *hwdep_cal = NULL; |
| 1025 | u32 anc_writes_size = 0; |
| 1026 | u32 anc_cal_size = 0; |
| 1027 | int anc_size_remaining; |
| 1028 | u32 *anc_ptr; |
| 1029 | u16 reg; |
| 1030 | u8 mask, val; |
| 1031 | size_t cal_size; |
| 1032 | const void *data; |
| 1033 | |
| 1034 | if (!tavil->anc_func) |
| 1035 | return 0; |
| 1036 | |
| 1037 | switch (event) { |
| 1038 | case SND_SOC_DAPM_PRE_PMU: |
| 1039 | hwdep_cal = wcdcal_get_fw_cal(tavil->fw_data, WCD9XXX_ANC_CAL); |
| 1040 | if (hwdep_cal) { |
| 1041 | data = hwdep_cal->data; |
| 1042 | cal_size = hwdep_cal->size; |
| 1043 | dev_dbg(codec->dev, "%s: using hwdep calibration, cal_size %zd", |
| 1044 | __func__, cal_size); |
| 1045 | } else { |
| 1046 | filename = "WCD934X/WCD934X_anc.bin"; |
| 1047 | ret = request_firmware(&fw, filename, codec->dev); |
Xiaoyu Ye | 1a2d8bd9 | 2017-01-31 18:54:15 -0800 | [diff] [blame] | 1048 | if (ret < 0) { |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 1049 | dev_err(codec->dev, "%s: Failed to acquire ANC data: %d\n", |
| 1050 | __func__, ret); |
| 1051 | return ret; |
| 1052 | } |
| 1053 | if (!fw) { |
| 1054 | dev_err(codec->dev, "%s: Failed to get anc fw\n", |
| 1055 | __func__); |
| 1056 | return -ENODEV; |
| 1057 | } |
| 1058 | data = fw->data; |
| 1059 | cal_size = fw->size; |
| 1060 | dev_dbg(codec->dev, "%s: using request_firmware calibration\n", |
| 1061 | __func__); |
| 1062 | } |
| 1063 | if (cal_size < sizeof(struct wcd9xxx_anc_header)) { |
| 1064 | dev_err(codec->dev, "%s: Invalid cal_size %zd\n", |
| 1065 | __func__, cal_size); |
| 1066 | ret = -EINVAL; |
| 1067 | goto err; |
| 1068 | } |
| 1069 | /* First number is the number of register writes */ |
| 1070 | anc_head = (struct wcd9xxx_anc_header *)(data); |
| 1071 | anc_ptr = (u32 *)(data + sizeof(struct wcd9xxx_anc_header)); |
| 1072 | anc_size_remaining = cal_size - |
| 1073 | sizeof(struct wcd9xxx_anc_header); |
| 1074 | num_anc_slots = anc_head->num_anc_slots; |
| 1075 | |
| 1076 | if (tavil->anc_slot >= num_anc_slots) { |
| 1077 | dev_err(codec->dev, "%s: Invalid ANC slot selected\n", |
| 1078 | __func__); |
| 1079 | ret = -EINVAL; |
| 1080 | goto err; |
| 1081 | } |
| 1082 | for (i = 0; i < num_anc_slots; i++) { |
| 1083 | if (anc_size_remaining < WCD934X_PACKED_REG_SIZE) { |
| 1084 | dev_err(codec->dev, "%s: Invalid register format\n", |
| 1085 | __func__); |
| 1086 | ret = -EINVAL; |
| 1087 | goto err; |
| 1088 | } |
| 1089 | anc_writes_size = (u32)(*anc_ptr); |
| 1090 | anc_size_remaining -= sizeof(u32); |
| 1091 | anc_ptr += 1; |
| 1092 | |
| 1093 | if ((anc_writes_size * WCD934X_PACKED_REG_SIZE) > |
| 1094 | anc_size_remaining) { |
| 1095 | dev_err(codec->dev, "%s: Invalid register format\n", |
| 1096 | __func__); |
| 1097 | ret = -EINVAL; |
| 1098 | goto err; |
| 1099 | } |
| 1100 | |
| 1101 | if (tavil->anc_slot == i) |
| 1102 | break; |
| 1103 | |
| 1104 | anc_size_remaining -= (anc_writes_size * |
| 1105 | WCD934X_PACKED_REG_SIZE); |
| 1106 | anc_ptr += anc_writes_size; |
| 1107 | } |
| 1108 | if (i == num_anc_slots) { |
| 1109 | dev_err(codec->dev, "%s: Selected ANC slot not present\n", |
| 1110 | __func__); |
| 1111 | ret = -EINVAL; |
| 1112 | goto err; |
| 1113 | } |
| 1114 | |
| 1115 | anc_cal_size = anc_writes_size; |
| 1116 | for (i = 0; i < anc_writes_size; i++) { |
| 1117 | WCD934X_CODEC_UNPACK_ENTRY(anc_ptr[i], reg, mask, val); |
| 1118 | snd_soc_write(codec, reg, (val & mask)); |
| 1119 | } |
| 1120 | |
| 1121 | /* Rate converter clk enable and set bypass mode */ |
| 1122 | snd_soc_update_bits(codec, WCD934X_CDC_ANC0_RC_COMMON_CTL, |
| 1123 | 0x05, 0x05); |
| 1124 | if (!hwdep_cal) |
| 1125 | release_firmware(fw); |
| 1126 | break; |
| 1127 | case SND_SOC_DAPM_POST_PMD: |
| 1128 | snd_soc_update_bits(codec, WCD934X_CDC_ANC0_RC_COMMON_CTL, |
| 1129 | 0x05, 0x00); |
| 1130 | if (!strcmp(w->name, "ANC EAR PA") || |
| 1131 | !strcmp(w->name, "ANC SPK1 PA")) { |
| 1132 | snd_soc_update_bits(codec, WCD934X_CDC_ANC0_MODE_1_CTL, |
| 1133 | 0x30, 0x00); |
| 1134 | msleep(50); |
| 1135 | snd_soc_update_bits(codec, WCD934X_CDC_ANC0_MODE_1_CTL, |
| 1136 | 0x01, 0x00); |
| 1137 | snd_soc_update_bits(codec, |
| 1138 | WCD934X_CDC_ANC0_CLK_RESET_CTL, |
| 1139 | 0x38, 0x38); |
| 1140 | snd_soc_update_bits(codec, |
| 1141 | WCD934X_CDC_ANC0_CLK_RESET_CTL, |
| 1142 | 0x07, 0x00); |
| 1143 | snd_soc_update_bits(codec, |
| 1144 | WCD934X_CDC_ANC0_CLK_RESET_CTL, |
| 1145 | 0x38, 0x00); |
| 1146 | } |
| 1147 | break; |
| 1148 | } |
| 1149 | |
| 1150 | return 0; |
| 1151 | err: |
| 1152 | if (!hwdep_cal) |
| 1153 | release_firmware(fw); |
| 1154 | return ret; |
| 1155 | } |
| 1156 | |
| 1157 | static int tavil_vi_feed_mixer_get(struct snd_kcontrol *kcontrol, |
| 1158 | struct snd_ctl_elem_value *ucontrol) |
| 1159 | { |
| 1160 | struct snd_soc_dapm_widget_list *wlist = |
| 1161 | dapm_kcontrol_get_wlist(kcontrol); |
| 1162 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1163 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm); |
| 1164 | struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec); |
| 1165 | |
| 1166 | ucontrol->value.integer.value[0] = tavil_p->vi_feed_value; |
| 1167 | |
| 1168 | return 0; |
| 1169 | } |
| 1170 | |
| 1171 | static int tavil_vi_feed_mixer_put(struct snd_kcontrol *kcontrol, |
| 1172 | struct snd_ctl_elem_value *ucontrol) |
| 1173 | { |
| 1174 | struct snd_soc_dapm_widget_list *wlist = |
| 1175 | dapm_kcontrol_get_wlist(kcontrol); |
| 1176 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1177 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm); |
| 1178 | struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec); |
| 1179 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 1180 | struct soc_multi_mixer_control *mixer = |
| 1181 | ((struct soc_multi_mixer_control *)kcontrol->private_value); |
| 1182 | u32 dai_id = widget->shift; |
| 1183 | u32 port_id = mixer->shift; |
| 1184 | u32 enable = ucontrol->value.integer.value[0]; |
| 1185 | |
| 1186 | dev_dbg(codec->dev, "%s: enable: %d, port_id:%d, dai_id: %d\n", |
| 1187 | __func__, enable, port_id, dai_id); |
| 1188 | |
| 1189 | tavil_p->vi_feed_value = ucontrol->value.integer.value[0]; |
| 1190 | |
| 1191 | mutex_lock(&tavil_p->codec_mutex); |
| 1192 | if (enable) { |
| 1193 | if (port_id == WCD934X_TX14 && !test_bit(VI_SENSE_1, |
| 1194 | &tavil_p->status_mask)) { |
| 1195 | list_add_tail(&core->tx_chs[WCD934X_TX14].list, |
| 1196 | &tavil_p->dai[dai_id].wcd9xxx_ch_list); |
| 1197 | set_bit(VI_SENSE_1, &tavil_p->status_mask); |
| 1198 | } |
| 1199 | if (port_id == WCD934X_TX15 && !test_bit(VI_SENSE_2, |
| 1200 | &tavil_p->status_mask)) { |
| 1201 | list_add_tail(&core->tx_chs[WCD934X_TX15].list, |
| 1202 | &tavil_p->dai[dai_id].wcd9xxx_ch_list); |
| 1203 | set_bit(VI_SENSE_2, &tavil_p->status_mask); |
| 1204 | } |
| 1205 | } else { |
| 1206 | if (port_id == WCD934X_TX14 && test_bit(VI_SENSE_1, |
| 1207 | &tavil_p->status_mask)) { |
| 1208 | list_del_init(&core->tx_chs[WCD934X_TX14].list); |
| 1209 | clear_bit(VI_SENSE_1, &tavil_p->status_mask); |
| 1210 | } |
| 1211 | if (port_id == WCD934X_TX15 && test_bit(VI_SENSE_2, |
| 1212 | &tavil_p->status_mask)) { |
| 1213 | list_del_init(&core->tx_chs[WCD934X_TX15].list); |
| 1214 | clear_bit(VI_SENSE_2, &tavil_p->status_mask); |
| 1215 | } |
| 1216 | } |
| 1217 | mutex_unlock(&tavil_p->codec_mutex); |
| 1218 | snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, NULL); |
| 1219 | |
| 1220 | return 0; |
| 1221 | } |
| 1222 | |
| 1223 | static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol, |
| 1224 | struct snd_ctl_elem_value *ucontrol) |
| 1225 | { |
| 1226 | struct snd_soc_dapm_widget_list *wlist = |
| 1227 | dapm_kcontrol_get_wlist(kcontrol); |
| 1228 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1229 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm); |
| 1230 | struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec); |
| 1231 | |
| 1232 | ucontrol->value.integer.value[0] = tavil_p->tx_port_value; |
| 1233 | return 0; |
| 1234 | } |
| 1235 | |
| 1236 | static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol, |
| 1237 | struct snd_ctl_elem_value *ucontrol) |
| 1238 | { |
| 1239 | struct snd_soc_dapm_widget_list *wlist = |
| 1240 | dapm_kcontrol_get_wlist(kcontrol); |
| 1241 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1242 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm); |
| 1243 | struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec); |
| 1244 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 1245 | struct snd_soc_dapm_update *update = NULL; |
| 1246 | struct soc_multi_mixer_control *mixer = |
| 1247 | ((struct soc_multi_mixer_control *)kcontrol->private_value); |
| 1248 | u32 dai_id = widget->shift; |
| 1249 | u32 port_id = mixer->shift; |
| 1250 | u32 enable = ucontrol->value.integer.value[0]; |
| 1251 | u32 vtable; |
| 1252 | |
| 1253 | dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n", |
| 1254 | __func__, |
| 1255 | widget->name, ucontrol->id.name, tavil_p->tx_port_value, |
| 1256 | widget->shift, ucontrol->value.integer.value[0]); |
| 1257 | |
| 1258 | mutex_lock(&tavil_p->codec_mutex); |
| 1259 | if (dai_id >= ARRAY_SIZE(vport_slim_check_table)) { |
| 1260 | dev_err(codec->dev, "%s: dai_id: %d, out of bounds\n", |
| 1261 | __func__, dai_id); |
| 1262 | mutex_unlock(&tavil_p->codec_mutex); |
| 1263 | return -EINVAL; |
| 1264 | } |
| 1265 | vtable = vport_slim_check_table[dai_id]; |
| 1266 | |
| 1267 | switch (dai_id) { |
| 1268 | case AIF1_CAP: |
| 1269 | case AIF2_CAP: |
| 1270 | case AIF3_CAP: |
| 1271 | /* only add to the list if value not set */ |
| 1272 | if (enable && !(tavil_p->tx_port_value & 1 << port_id)) { |
| 1273 | if (wcd9xxx_tx_vport_validation(vtable, port_id, |
| 1274 | tavil_p->dai, NUM_CODEC_DAIS)) { |
| 1275 | dev_dbg(codec->dev, "%s: TX%u is used by other virtual port\n", |
| 1276 | __func__, port_id); |
| 1277 | mutex_unlock(&tavil_p->codec_mutex); |
| 1278 | return 0; |
| 1279 | } |
| 1280 | tavil_p->tx_port_value |= 1 << port_id; |
| 1281 | list_add_tail(&core->tx_chs[port_id].list, |
| 1282 | &tavil_p->dai[dai_id].wcd9xxx_ch_list); |
| 1283 | } else if (!enable && (tavil_p->tx_port_value & |
| 1284 | 1 << port_id)) { |
| 1285 | tavil_p->tx_port_value &= ~(1 << port_id); |
| 1286 | list_del_init(&core->tx_chs[port_id].list); |
| 1287 | } else { |
| 1288 | if (enable) |
| 1289 | dev_dbg(codec->dev, "%s: TX%u port is used by\n" |
| 1290 | "this virtual port\n", |
| 1291 | __func__, port_id); |
| 1292 | else |
| 1293 | dev_dbg(codec->dev, "%s: TX%u port is not used by\n" |
| 1294 | "this virtual port\n", |
| 1295 | __func__, port_id); |
| 1296 | /* avoid update power function */ |
| 1297 | mutex_unlock(&tavil_p->codec_mutex); |
| 1298 | return 0; |
| 1299 | } |
| 1300 | break; |
| 1301 | case AIF4_MAD_TX: |
| 1302 | break; |
| 1303 | default: |
| 1304 | dev_err(codec->dev, "Unknown AIF %d\n", dai_id); |
| 1305 | mutex_unlock(&tavil_p->codec_mutex); |
| 1306 | return -EINVAL; |
| 1307 | } |
| 1308 | dev_dbg(codec->dev, "%s: name %s sname %s updated value %u shift %d\n", |
| 1309 | __func__, widget->name, widget->sname, tavil_p->tx_port_value, |
| 1310 | widget->shift); |
| 1311 | |
| 1312 | mutex_unlock(&tavil_p->codec_mutex); |
| 1313 | snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update); |
| 1314 | |
| 1315 | return 0; |
| 1316 | } |
| 1317 | |
| 1318 | static int slim_rx_mux_get(struct snd_kcontrol *kcontrol, |
| 1319 | struct snd_ctl_elem_value *ucontrol) |
| 1320 | { |
| 1321 | struct snd_soc_dapm_widget_list *wlist = |
| 1322 | dapm_kcontrol_get_wlist(kcontrol); |
| 1323 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1324 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm); |
| 1325 | struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec); |
| 1326 | |
| 1327 | ucontrol->value.enumerated.item[0] = |
| 1328 | tavil_p->rx_port_value[widget->shift]; |
| 1329 | return 0; |
| 1330 | } |
| 1331 | |
| 1332 | static int slim_rx_mux_put(struct snd_kcontrol *kcontrol, |
| 1333 | struct snd_ctl_elem_value *ucontrol) |
| 1334 | { |
| 1335 | struct snd_soc_dapm_widget_list *wlist = |
| 1336 | dapm_kcontrol_get_wlist(kcontrol); |
| 1337 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1338 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm); |
| 1339 | struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec); |
| 1340 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 1341 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1342 | struct snd_soc_dapm_update *update = NULL; |
| 1343 | unsigned int rx_port_value; |
| 1344 | u32 port_id = widget->shift; |
| 1345 | |
| 1346 | tavil_p->rx_port_value[port_id] = ucontrol->value.enumerated.item[0]; |
| 1347 | rx_port_value = tavil_p->rx_port_value[port_id]; |
| 1348 | |
| 1349 | mutex_lock(&tavil_p->codec_mutex); |
| 1350 | dev_dbg(codec->dev, "%s: wname %s cname %s value %u shift %d item %ld\n", |
| 1351 | __func__, widget->name, ucontrol->id.name, |
| 1352 | rx_port_value, widget->shift, |
| 1353 | ucontrol->value.integer.value[0]); |
| 1354 | |
| 1355 | /* value need to match the Virtual port and AIF number */ |
| 1356 | switch (rx_port_value) { |
| 1357 | case 0: |
| 1358 | list_del_init(&core->rx_chs[port_id].list); |
| 1359 | break; |
| 1360 | case 1: |
| 1361 | if (wcd9xxx_rx_vport_validation(port_id + |
| 1362 | WCD934X_RX_PORT_START_NUMBER, |
| 1363 | &tavil_p->dai[AIF1_PB].wcd9xxx_ch_list)) { |
| 1364 | dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n", |
| 1365 | __func__, port_id); |
| 1366 | goto rtn; |
| 1367 | } |
| 1368 | list_add_tail(&core->rx_chs[port_id].list, |
| 1369 | &tavil_p->dai[AIF1_PB].wcd9xxx_ch_list); |
| 1370 | break; |
| 1371 | case 2: |
| 1372 | if (wcd9xxx_rx_vport_validation(port_id + |
| 1373 | WCD934X_RX_PORT_START_NUMBER, |
| 1374 | &tavil_p->dai[AIF2_PB].wcd9xxx_ch_list)) { |
| 1375 | dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n", |
| 1376 | __func__, port_id); |
| 1377 | goto rtn; |
| 1378 | } |
| 1379 | list_add_tail(&core->rx_chs[port_id].list, |
| 1380 | &tavil_p->dai[AIF2_PB].wcd9xxx_ch_list); |
| 1381 | break; |
| 1382 | case 3: |
| 1383 | if (wcd9xxx_rx_vport_validation(port_id + |
| 1384 | WCD934X_RX_PORT_START_NUMBER, |
| 1385 | &tavil_p->dai[AIF3_PB].wcd9xxx_ch_list)) { |
| 1386 | dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n", |
| 1387 | __func__, port_id); |
| 1388 | goto rtn; |
| 1389 | } |
| 1390 | list_add_tail(&core->rx_chs[port_id].list, |
| 1391 | &tavil_p->dai[AIF3_PB].wcd9xxx_ch_list); |
| 1392 | break; |
| 1393 | case 4: |
| 1394 | if (wcd9xxx_rx_vport_validation(port_id + |
| 1395 | WCD934X_RX_PORT_START_NUMBER, |
| 1396 | &tavil_p->dai[AIF4_PB].wcd9xxx_ch_list)) { |
| 1397 | dev_dbg(codec->dev, "%s: RX%u is used by current requesting AIF_PB itself\n", |
| 1398 | __func__, port_id); |
| 1399 | goto rtn; |
| 1400 | } |
| 1401 | list_add_tail(&core->rx_chs[port_id].list, |
| 1402 | &tavil_p->dai[AIF4_PB].wcd9xxx_ch_list); |
| 1403 | break; |
| 1404 | default: |
| 1405 | dev_err(codec->dev, "Unknown AIF %d\n", rx_port_value); |
| 1406 | goto err; |
| 1407 | } |
| 1408 | rtn: |
| 1409 | mutex_unlock(&tavil_p->codec_mutex); |
| 1410 | snd_soc_dapm_mux_update_power(widget->dapm, kcontrol, |
| 1411 | rx_port_value, e, update); |
| 1412 | |
| 1413 | return 0; |
| 1414 | err: |
| 1415 | mutex_unlock(&tavil_p->codec_mutex); |
| 1416 | return -EINVAL; |
| 1417 | } |
| 1418 | |
| 1419 | static void tavil_codec_enable_slim_port_intr( |
| 1420 | struct wcd9xxx_codec_dai_data *dai, |
| 1421 | struct snd_soc_codec *codec) |
| 1422 | { |
| 1423 | struct wcd9xxx_ch *ch; |
| 1424 | int port_num = 0; |
| 1425 | unsigned short reg = 0; |
| 1426 | u8 val = 0; |
| 1427 | struct tavil_priv *tavil_p; |
| 1428 | |
| 1429 | if (!dai || !codec) { |
| 1430 | pr_err("%s: Invalid params\n", __func__); |
| 1431 | return; |
| 1432 | } |
| 1433 | |
| 1434 | tavil_p = snd_soc_codec_get_drvdata(codec); |
| 1435 | list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) { |
| 1436 | if (ch->port >= WCD934X_RX_PORT_START_NUMBER) { |
| 1437 | port_num = ch->port - WCD934X_RX_PORT_START_NUMBER; |
| 1438 | reg = WCD934X_SLIM_PGD_PORT_INT_RX_EN0 + (port_num / 8); |
| 1439 | val = wcd9xxx_interface_reg_read(tavil_p->wcd9xxx, |
| 1440 | reg); |
| 1441 | if (!(val & BYTE_BIT_MASK(port_num))) { |
| 1442 | val |= BYTE_BIT_MASK(port_num); |
| 1443 | wcd9xxx_interface_reg_write( |
| 1444 | tavil_p->wcd9xxx, reg, val); |
| 1445 | val = wcd9xxx_interface_reg_read( |
| 1446 | tavil_p->wcd9xxx, reg); |
| 1447 | } |
| 1448 | } else { |
| 1449 | port_num = ch->port; |
| 1450 | reg = WCD934X_SLIM_PGD_PORT_INT_TX_EN0 + (port_num / 8); |
| 1451 | val = wcd9xxx_interface_reg_read(tavil_p->wcd9xxx, |
| 1452 | reg); |
| 1453 | if (!(val & BYTE_BIT_MASK(port_num))) { |
| 1454 | val |= BYTE_BIT_MASK(port_num); |
| 1455 | wcd9xxx_interface_reg_write(tavil_p->wcd9xxx, |
| 1456 | reg, val); |
| 1457 | val = wcd9xxx_interface_reg_read( |
| 1458 | tavil_p->wcd9xxx, reg); |
| 1459 | } |
| 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | static int tavil_codec_enable_slim_chmask(struct wcd9xxx_codec_dai_data *dai, |
| 1465 | bool up) |
| 1466 | { |
| 1467 | int ret = 0; |
| 1468 | struct wcd9xxx_ch *ch; |
| 1469 | |
| 1470 | if (up) { |
| 1471 | list_for_each_entry(ch, &dai->wcd9xxx_ch_list, list) { |
| 1472 | ret = wcd9xxx_get_slave_port(ch->ch_num); |
| 1473 | if (ret < 0) { |
| 1474 | pr_err("%s: Invalid slave port ID: %d\n", |
| 1475 | __func__, ret); |
| 1476 | ret = -EINVAL; |
| 1477 | } else { |
| 1478 | set_bit(ret, &dai->ch_mask); |
| 1479 | } |
| 1480 | } |
| 1481 | } else { |
| 1482 | ret = wait_event_timeout(dai->dai_wait, (dai->ch_mask == 0), |
| 1483 | msecs_to_jiffies( |
| 1484 | WCD934X_SLIM_CLOSE_TIMEOUT)); |
| 1485 | if (!ret) { |
| 1486 | pr_err("%s: Slim close tx/rx wait timeout, ch_mask:0x%lx\n", |
| 1487 | __func__, dai->ch_mask); |
| 1488 | ret = -ETIMEDOUT; |
| 1489 | } else { |
| 1490 | ret = 0; |
| 1491 | } |
| 1492 | } |
| 1493 | return ret; |
| 1494 | } |
| 1495 | |
| 1496 | static void tavil_codec_mute_dsd(struct snd_soc_codec *codec, |
| 1497 | struct list_head *ch_list) |
| 1498 | { |
| 1499 | u8 dsd0_in; |
| 1500 | u8 dsd1_in; |
| 1501 | struct wcd9xxx_ch *ch; |
| 1502 | |
| 1503 | /* Read DSD Input Ports */ |
| 1504 | dsd0_in = (snd_soc_read(codec, WCD934X_CDC_DSD0_CFG0) & 0x3C) >> 2; |
| 1505 | dsd1_in = (snd_soc_read(codec, WCD934X_CDC_DSD1_CFG0) & 0x3C) >> 2; |
| 1506 | |
| 1507 | if ((dsd0_in == 0) && (dsd1_in == 0)) |
| 1508 | return; |
| 1509 | |
| 1510 | /* |
| 1511 | * Check if the ports getting disabled are connected to DSD inputs. |
| 1512 | * If connected, enable DSD mute to avoid DC entering into DSD Filter |
| 1513 | */ |
| 1514 | list_for_each_entry(ch, ch_list, list) { |
| 1515 | if (ch->port == (dsd0_in + WCD934X_RX_PORT_START_NUMBER - 1)) |
| 1516 | snd_soc_update_bits(codec, WCD934X_CDC_DSD0_CFG2, |
| 1517 | 0x04, 0x04); |
| 1518 | if (ch->port == (dsd1_in + WCD934X_RX_PORT_START_NUMBER - 1)) |
| 1519 | snd_soc_update_bits(codec, WCD934X_CDC_DSD1_CFG2, |
| 1520 | 0x04, 0x04); |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | static int tavil_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
| 1525 | struct snd_kcontrol *kcontrol, |
| 1526 | int event) |
| 1527 | { |
| 1528 | struct wcd9xxx *core; |
| 1529 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 1530 | struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec); |
| 1531 | int ret = 0; |
| 1532 | struct wcd9xxx_codec_dai_data *dai; |
| 1533 | struct tavil_dsd_config *dsd_conf = tavil_p->dsd_config; |
| 1534 | |
| 1535 | core = dev_get_drvdata(codec->dev->parent); |
| 1536 | |
| 1537 | dev_dbg(codec->dev, "%s: event called! codec name %s num_dai %d\n" |
| 1538 | "stream name %s event %d\n", |
| 1539 | __func__, codec->component.name, |
| 1540 | codec->component.num_dai, w->sname, event); |
| 1541 | |
| 1542 | dai = &tavil_p->dai[w->shift]; |
| 1543 | dev_dbg(codec->dev, "%s: w->name %s w->shift %d event %d\n", |
| 1544 | __func__, w->name, w->shift, event); |
| 1545 | |
| 1546 | switch (event) { |
| 1547 | case SND_SOC_DAPM_POST_PMU: |
| 1548 | dai->bus_down_in_recovery = false; |
| 1549 | tavil_codec_enable_slim_port_intr(dai, codec); |
| 1550 | (void) tavil_codec_enable_slim_chmask(dai, true); |
| 1551 | ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list, |
| 1552 | dai->rate, dai->bit_width, |
| 1553 | &dai->grph); |
| 1554 | break; |
| 1555 | case SND_SOC_DAPM_POST_PMD: |
| 1556 | if (dsd_conf) |
| 1557 | tavil_codec_mute_dsd(codec, &dai->wcd9xxx_ch_list); |
| 1558 | |
| 1559 | ret = wcd9xxx_disconnect_port(core, &dai->wcd9xxx_ch_list, |
| 1560 | dai->grph); |
| 1561 | dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n", |
| 1562 | __func__, ret); |
| 1563 | |
| 1564 | if (!dai->bus_down_in_recovery) |
| 1565 | ret = tavil_codec_enable_slim_chmask(dai, false); |
| 1566 | else |
| 1567 | dev_dbg(codec->dev, |
| 1568 | "%s: bus in recovery skip enable slim_chmask", |
| 1569 | __func__); |
| 1570 | ret = wcd9xxx_close_slim_sch_rx(core, &dai->wcd9xxx_ch_list, |
| 1571 | dai->grph); |
| 1572 | break; |
| 1573 | } |
| 1574 | return ret; |
| 1575 | } |
| 1576 | |
| 1577 | static int tavil_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
| 1578 | struct snd_kcontrol *kcontrol, |
| 1579 | int event) |
| 1580 | { |
| 1581 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 1582 | struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec); |
| 1583 | struct wcd9xxx_codec_dai_data *dai; |
| 1584 | struct wcd9xxx *core; |
| 1585 | int ret = 0; |
| 1586 | |
| 1587 | dev_dbg(codec->dev, |
| 1588 | "%s: w->name %s, w->shift = %d, num_dai %d stream name %s\n", |
| 1589 | __func__, w->name, w->shift, |
| 1590 | codec->component.num_dai, w->sname); |
| 1591 | |
| 1592 | dai = &tavil_p->dai[w->shift]; |
| 1593 | core = dev_get_drvdata(codec->dev->parent); |
| 1594 | |
| 1595 | switch (event) { |
| 1596 | case SND_SOC_DAPM_POST_PMU: |
| 1597 | dai->bus_down_in_recovery = false; |
| 1598 | tavil_codec_enable_slim_port_intr(dai, codec); |
| 1599 | (void) tavil_codec_enable_slim_chmask(dai, true); |
| 1600 | ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 1601 | dai->rate, dai->bit_width, |
| 1602 | &dai->grph); |
| 1603 | break; |
| 1604 | case SND_SOC_DAPM_POST_PMD: |
| 1605 | ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 1606 | dai->grph); |
| 1607 | if (!dai->bus_down_in_recovery) |
| 1608 | ret = tavil_codec_enable_slim_chmask(dai, false); |
| 1609 | if (ret < 0) { |
| 1610 | ret = wcd9xxx_disconnect_port(core, |
| 1611 | &dai->wcd9xxx_ch_list, |
| 1612 | dai->grph); |
| 1613 | dev_dbg(codec->dev, "%s: Disconnect RX port, ret = %d\n", |
| 1614 | __func__, ret); |
| 1615 | } |
| 1616 | break; |
| 1617 | } |
| 1618 | return ret; |
| 1619 | } |
| 1620 | |
| 1621 | static int tavil_codec_enable_slimvi_feedback(struct snd_soc_dapm_widget *w, |
| 1622 | struct snd_kcontrol *kcontrol, |
| 1623 | int event) |
| 1624 | { |
| 1625 | struct wcd9xxx *core = NULL; |
| 1626 | struct snd_soc_codec *codec = NULL; |
| 1627 | struct tavil_priv *tavil_p = NULL; |
| 1628 | int ret = 0; |
| 1629 | struct wcd9xxx_codec_dai_data *dai = NULL; |
| 1630 | |
| 1631 | codec = snd_soc_dapm_to_codec(w->dapm); |
| 1632 | tavil_p = snd_soc_codec_get_drvdata(codec); |
| 1633 | core = dev_get_drvdata(codec->dev->parent); |
| 1634 | |
| 1635 | dev_dbg(codec->dev, |
| 1636 | "%s: num_dai %d stream name %s w->name %s event %d shift %d\n", |
| 1637 | __func__, codec->component.num_dai, w->sname, |
| 1638 | w->name, event, w->shift); |
| 1639 | |
| 1640 | if (w->shift != AIF4_VIFEED) { |
| 1641 | pr_err("%s Error in enabling the tx path\n", __func__); |
| 1642 | ret = -EINVAL; |
| 1643 | goto done; |
| 1644 | } |
| 1645 | dai = &tavil_p->dai[w->shift]; |
| 1646 | switch (event) { |
| 1647 | case SND_SOC_DAPM_POST_PMU: |
| 1648 | if (test_bit(VI_SENSE_1, &tavil_p->status_mask)) { |
| 1649 | dev_dbg(codec->dev, "%s: spkr1 enabled\n", __func__); |
| 1650 | /* Enable V&I sensing */ |
| 1651 | snd_soc_update_bits(codec, |
| 1652 | WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x20); |
| 1653 | snd_soc_update_bits(codec, |
| 1654 | WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x20, |
| 1655 | 0x20); |
| 1656 | snd_soc_update_bits(codec, |
| 1657 | WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x0F, 0x00); |
| 1658 | snd_soc_update_bits(codec, |
| 1659 | WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x0F, |
| 1660 | 0x00); |
| 1661 | snd_soc_update_bits(codec, |
| 1662 | WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x10, 0x10); |
| 1663 | snd_soc_update_bits(codec, |
| 1664 | WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x10, |
| 1665 | 0x10); |
| 1666 | snd_soc_update_bits(codec, |
| 1667 | WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x00); |
| 1668 | snd_soc_update_bits(codec, |
| 1669 | WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x20, |
| 1670 | 0x00); |
| 1671 | } |
| 1672 | if (test_bit(VI_SENSE_2, &tavil_p->status_mask)) { |
| 1673 | pr_debug("%s: spkr2 enabled\n", __func__); |
| 1674 | /* Enable V&I sensing */ |
| 1675 | snd_soc_update_bits(codec, |
| 1676 | WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x20, |
| 1677 | 0x20); |
| 1678 | snd_soc_update_bits(codec, |
| 1679 | WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x20, |
| 1680 | 0x20); |
| 1681 | snd_soc_update_bits(codec, |
| 1682 | WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x0F, |
| 1683 | 0x00); |
| 1684 | snd_soc_update_bits(codec, |
| 1685 | WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x0F, |
| 1686 | 0x00); |
| 1687 | snd_soc_update_bits(codec, |
| 1688 | WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x10, |
| 1689 | 0x10); |
| 1690 | snd_soc_update_bits(codec, |
| 1691 | WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x10, |
| 1692 | 0x10); |
| 1693 | snd_soc_update_bits(codec, |
| 1694 | WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x20, |
| 1695 | 0x00); |
| 1696 | snd_soc_update_bits(codec, |
| 1697 | WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x20, |
| 1698 | 0x00); |
| 1699 | } |
| 1700 | dai->bus_down_in_recovery = false; |
| 1701 | tavil_codec_enable_slim_port_intr(dai, codec); |
| 1702 | (void) tavil_codec_enable_slim_chmask(dai, true); |
| 1703 | ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 1704 | dai->rate, dai->bit_width, |
| 1705 | &dai->grph); |
| 1706 | break; |
| 1707 | case SND_SOC_DAPM_POST_PMD: |
| 1708 | ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 1709 | dai->grph); |
| 1710 | if (ret) |
| 1711 | dev_err(codec->dev, "%s error in close_slim_sch_tx %d\n", |
| 1712 | __func__, ret); |
| 1713 | if (!dai->bus_down_in_recovery) |
| 1714 | ret = tavil_codec_enable_slim_chmask(dai, false); |
| 1715 | if (ret < 0) { |
| 1716 | ret = wcd9xxx_disconnect_port(core, |
| 1717 | &dai->wcd9xxx_ch_list, |
| 1718 | dai->grph); |
| 1719 | dev_dbg(codec->dev, "%s: Disconnect TX port, ret = %d\n", |
| 1720 | __func__, ret); |
| 1721 | } |
| 1722 | if (test_bit(VI_SENSE_1, &tavil_p->status_mask)) { |
| 1723 | /* Disable V&I sensing */ |
| 1724 | dev_dbg(codec->dev, "%s: spkr1 disabled\n", __func__); |
| 1725 | snd_soc_update_bits(codec, |
| 1726 | WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x20, 0x20); |
| 1727 | snd_soc_update_bits(codec, |
| 1728 | WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x20, |
| 1729 | 0x20); |
| 1730 | snd_soc_update_bits(codec, |
| 1731 | WCD934X_CDC_TX9_SPKR_PROT_PATH_CTL, 0x10, 0x00); |
| 1732 | snd_soc_update_bits(codec, |
| 1733 | WCD934X_CDC_TX10_SPKR_PROT_PATH_CTL, 0x10, |
| 1734 | 0x00); |
| 1735 | } |
| 1736 | if (test_bit(VI_SENSE_2, &tavil_p->status_mask)) { |
| 1737 | /* Disable V&I sensing */ |
| 1738 | dev_dbg(codec->dev, "%s: spkr2 disabled\n", __func__); |
| 1739 | snd_soc_update_bits(codec, |
| 1740 | WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x20, |
| 1741 | 0x20); |
| 1742 | snd_soc_update_bits(codec, |
| 1743 | WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x20, |
| 1744 | 0x20); |
| 1745 | snd_soc_update_bits(codec, |
| 1746 | WCD934X_CDC_TX11_SPKR_PROT_PATH_CTL, 0x10, |
| 1747 | 0x00); |
| 1748 | snd_soc_update_bits(codec, |
| 1749 | WCD934X_CDC_TX12_SPKR_PROT_PATH_CTL, 0x10, |
| 1750 | 0x00); |
| 1751 | } |
| 1752 | break; |
| 1753 | } |
| 1754 | done: |
| 1755 | return ret; |
| 1756 | } |
| 1757 | |
| 1758 | static int tavil_codec_enable_rx_bias(struct snd_soc_dapm_widget *w, |
| 1759 | struct snd_kcontrol *kcontrol, int event) |
| 1760 | { |
| 1761 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 1762 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 1763 | |
| 1764 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 1765 | |
| 1766 | switch (event) { |
| 1767 | case SND_SOC_DAPM_PRE_PMU: |
| 1768 | tavil->rx_bias_count++; |
| 1769 | if (tavil->rx_bias_count == 1) { |
| 1770 | snd_soc_update_bits(codec, WCD934X_ANA_RX_SUPPLIES, |
| 1771 | 0x01, 0x01); |
| 1772 | } |
| 1773 | break; |
| 1774 | case SND_SOC_DAPM_POST_PMD: |
| 1775 | tavil->rx_bias_count--; |
| 1776 | if (!tavil->rx_bias_count) |
| 1777 | snd_soc_update_bits(codec, WCD934X_ANA_RX_SUPPLIES, |
| 1778 | 0x01, 0x00); |
| 1779 | break; |
| 1780 | }; |
| 1781 | dev_dbg(codec->dev, "%s: Current RX BIAS user count: %d\n", __func__, |
| 1782 | tavil->rx_bias_count); |
| 1783 | |
| 1784 | return 0; |
| 1785 | } |
| 1786 | |
| 1787 | static void tavil_spk_anc_update_callback(struct work_struct *work) |
| 1788 | { |
| 1789 | struct spk_anc_work *spk_anc_dwork; |
| 1790 | struct tavil_priv *tavil; |
| 1791 | struct delayed_work *delayed_work; |
| 1792 | struct snd_soc_codec *codec; |
| 1793 | |
| 1794 | delayed_work = to_delayed_work(work); |
| 1795 | spk_anc_dwork = container_of(delayed_work, struct spk_anc_work, dwork); |
| 1796 | tavil = spk_anc_dwork->tavil; |
| 1797 | codec = tavil->codec; |
| 1798 | |
| 1799 | snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_CFG0, 0x10, 0x10); |
| 1800 | } |
| 1801 | |
| 1802 | static int tavil_codec_enable_spkr_anc(struct snd_soc_dapm_widget *w, |
| 1803 | struct snd_kcontrol *kcontrol, |
| 1804 | int event) |
| 1805 | { |
| 1806 | int ret = 0; |
| 1807 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 1808 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 1809 | |
| 1810 | if (!tavil->anc_func) |
| 1811 | return 0; |
| 1812 | |
| 1813 | dev_dbg(codec->dev, "%s: w: %s event: %d anc: %d\n", __func__, |
| 1814 | w->name, event, tavil->anc_func); |
| 1815 | |
| 1816 | switch (event) { |
| 1817 | case SND_SOC_DAPM_PRE_PMU: |
| 1818 | ret = tavil_codec_enable_anc(w, kcontrol, event); |
| 1819 | schedule_delayed_work(&tavil->spk_anc_dwork.dwork, |
| 1820 | msecs_to_jiffies(spk_anc_en_delay)); |
| 1821 | break; |
| 1822 | case SND_SOC_DAPM_POST_PMD: |
| 1823 | cancel_delayed_work_sync(&tavil->spk_anc_dwork.dwork); |
| 1824 | snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_CFG0, |
| 1825 | 0x10, 0x00); |
| 1826 | ret = tavil_codec_enable_anc(w, kcontrol, event); |
| 1827 | break; |
| 1828 | } |
| 1829 | return ret; |
| 1830 | } |
| 1831 | |
| 1832 | static int tavil_codec_enable_ear_pa(struct snd_soc_dapm_widget *w, |
| 1833 | struct snd_kcontrol *kcontrol, |
| 1834 | int event) |
| 1835 | { |
| 1836 | int ret = 0; |
| 1837 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 1838 | |
| 1839 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 1840 | |
| 1841 | switch (event) { |
| 1842 | case SND_SOC_DAPM_POST_PMU: |
| 1843 | /* |
| 1844 | * 5ms sleep is required after PA is enabled as per |
| 1845 | * HW requirement |
| 1846 | */ |
| 1847 | usleep_range(5000, 5500); |
| 1848 | snd_soc_update_bits(codec, WCD934X_CDC_RX0_RX_PATH_CTL, |
| 1849 | 0x10, 0x00); |
| 1850 | /* Remove mix path mute if it is enabled */ |
| 1851 | if ((snd_soc_read(codec, WCD934X_CDC_RX0_RX_PATH_MIX_CTL)) & |
| 1852 | 0x10) |
| 1853 | snd_soc_update_bits(codec, |
| 1854 | WCD934X_CDC_RX0_RX_PATH_MIX_CTL, |
| 1855 | 0x10, 0x00); |
| 1856 | break; |
| 1857 | case SND_SOC_DAPM_POST_PMD: |
| 1858 | /* |
| 1859 | * 5ms sleep is required after PA is disabled as per |
| 1860 | * HW requirement |
| 1861 | */ |
| 1862 | usleep_range(5000, 5500); |
| 1863 | |
| 1864 | if (!(strcmp(w->name, "ANC EAR PA"))) { |
| 1865 | ret = tavil_codec_enable_anc(w, kcontrol, event); |
| 1866 | snd_soc_update_bits(codec, WCD934X_CDC_RX0_RX_PATH_CFG0, |
| 1867 | 0x10, 0x00); |
| 1868 | } |
| 1869 | break; |
| 1870 | }; |
| 1871 | |
| 1872 | return ret; |
| 1873 | } |
| 1874 | |
| 1875 | static void tavil_codec_override(struct snd_soc_codec *codec, int mode, |
| 1876 | int event) |
| 1877 | { |
| 1878 | if (mode == CLS_AB || mode == CLS_AB_HIFI) { |
| 1879 | switch (event) { |
| 1880 | case SND_SOC_DAPM_PRE_PMU: |
| 1881 | case SND_SOC_DAPM_POST_PMU: |
Karthikeyan Mani | 387d398 | 2016-12-09 16:39:42 -0800 | [diff] [blame] | 1882 | snd_soc_update_bits(codec, |
| 1883 | WCD9XXX_A_ANA_RX_SUPPLIES, 0x02, 0x02); |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 1884 | break; |
| 1885 | case SND_SOC_DAPM_POST_PMD: |
| 1886 | snd_soc_update_bits(codec, |
| 1887 | WCD9XXX_A_ANA_RX_SUPPLIES, 0x02, 0x00); |
| 1888 | break; |
| 1889 | } |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | static int tavil_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w, |
| 1894 | struct snd_kcontrol *kcontrol, |
| 1895 | int event) |
| 1896 | { |
| 1897 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 1898 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 1899 | struct tavil_dsd_config *dsd_conf = tavil->dsd_config; |
| 1900 | |
| 1901 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 1902 | |
| 1903 | switch (event) { |
| 1904 | case SND_SOC_DAPM_PRE_PMU: |
| 1905 | if (TAVIL_IS_1_0(tavil->wcd9xxx)) |
| 1906 | snd_soc_update_bits(codec, WCD934X_HPH_REFBUFF_LP_CTL, |
| 1907 | 0x06, (0x03 << 1)); |
| 1908 | set_bit(HPH_PA_DELAY, &tavil->status_mask); |
| 1909 | if (dsd_conf && |
| 1910 | (snd_soc_read(codec, WCD934X_CDC_DSD1_PATH_CTL) & 0x01)) { |
| 1911 | /* Set regulator mode to AB if DSD is enabled */ |
| 1912 | snd_soc_update_bits(codec, WCD934X_ANA_RX_SUPPLIES, |
| 1913 | 0x02, 0x02); |
| 1914 | } |
| 1915 | break; |
| 1916 | case SND_SOC_DAPM_POST_PMU: |
| 1917 | /* |
| 1918 | * 7ms sleep is required after PA is enabled as per |
Sudheer Papothi | 3be7677 | 2017-01-11 06:08:13 +0530 | [diff] [blame^] | 1919 | * HW requirement. If compander is disabled, then |
| 1920 | * 20ms delay is needed. |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 1921 | */ |
| 1922 | if (test_bit(HPH_PA_DELAY, &tavil->status_mask)) { |
Sudheer Papothi | 3be7677 | 2017-01-11 06:08:13 +0530 | [diff] [blame^] | 1923 | if (!tavil->comp_enabled[COMPANDER_2]) |
| 1924 | usleep_range(20000, 20100); |
| 1925 | else |
| 1926 | usleep_range(7000, 7100); |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 1927 | clear_bit(HPH_PA_DELAY, &tavil->status_mask); |
| 1928 | } |
| 1929 | |
| 1930 | snd_soc_update_bits(codec, WCD934X_HPH_R_TEST, 0x01, 0x01); |
| 1931 | |
| 1932 | /* Remove mute */ |
| 1933 | snd_soc_update_bits(codec, WCD934X_CDC_RX2_RX_PATH_CTL, |
| 1934 | 0x10, 0x00); |
| 1935 | /* Enable GM3 boost */ |
| 1936 | snd_soc_update_bits(codec, WCD934X_HPH_CNP_WG_CTL, |
| 1937 | 0x80, 0x80); |
| 1938 | /* Enable AutoChop timer at the end of power up */ |
| 1939 | snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1, |
| 1940 | 0x02, 0x02); |
| 1941 | /* Remove mix path mute if it is enabled */ |
| 1942 | if ((snd_soc_read(codec, WCD934X_CDC_RX2_RX_PATH_MIX_CTL)) & |
| 1943 | 0x10) |
| 1944 | snd_soc_update_bits(codec, |
| 1945 | WCD934X_CDC_RX2_RX_PATH_MIX_CTL, |
| 1946 | 0x10, 0x00); |
| 1947 | if (dsd_conf && |
| 1948 | (snd_soc_read(codec, WCD934X_CDC_DSD1_PATH_CTL) & 0x01)) |
| 1949 | snd_soc_update_bits(codec, WCD934X_CDC_DSD1_CFG2, |
| 1950 | 0x04, 0x00); |
| 1951 | tavil_codec_override(codec, tavil->hph_mode, event); |
| 1952 | break; |
| 1953 | case SND_SOC_DAPM_PRE_PMD: |
| 1954 | blocking_notifier_call_chain(&tavil->mbhc->notifier, |
| 1955 | WCD_EVENT_PRE_HPHR_PA_OFF, |
| 1956 | &tavil->mbhc->wcd_mbhc); |
| 1957 | /* Enable DSD Mute before PA disable */ |
| 1958 | if (dsd_conf && |
| 1959 | (snd_soc_read(codec, WCD934X_CDC_DSD1_PATH_CTL) & 0x01)) |
| 1960 | snd_soc_update_bits(codec, WCD934X_CDC_DSD1_CFG2, |
| 1961 | 0x04, 0x04); |
| 1962 | snd_soc_update_bits(codec, WCD934X_HPH_R_TEST, 0x01, 0x00); |
| 1963 | snd_soc_update_bits(codec, WCD934X_CDC_RX2_RX_PATH_CTL, |
| 1964 | 0x10, 0x10); |
Sudheer Papothi | 3be7677 | 2017-01-11 06:08:13 +0530 | [diff] [blame^] | 1965 | snd_soc_update_bits(codec, WCD934X_CDC_RX2_RX_PATH_MIX_CTL, |
| 1966 | 0x10, 0x10); |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 1967 | break; |
| 1968 | case SND_SOC_DAPM_POST_PMD: |
Sudheer Papothi | 3be7677 | 2017-01-11 06:08:13 +0530 | [diff] [blame^] | 1969 | /* |
| 1970 | * 5ms sleep is required after PA disable. If compander is |
| 1971 | * disabled, then 20ms delay is needed after PA disable. |
| 1972 | */ |
| 1973 | if (!tavil->comp_enabled[COMPANDER_2]) |
| 1974 | usleep_range(20000, 20100); |
| 1975 | else |
| 1976 | usleep_range(5000, 5100); |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 1977 | tavil_codec_override(codec, tavil->hph_mode, event); |
| 1978 | blocking_notifier_call_chain(&tavil->mbhc->notifier, |
| 1979 | WCD_EVENT_POST_HPHR_PA_OFF, |
| 1980 | &tavil->mbhc->wcd_mbhc); |
| 1981 | if (TAVIL_IS_1_0(tavil->wcd9xxx)) |
| 1982 | snd_soc_update_bits(codec, WCD934X_HPH_REFBUFF_LP_CTL, |
| 1983 | 0x06, 0x0); |
| 1984 | break; |
| 1985 | }; |
| 1986 | |
| 1987 | return 0; |
| 1988 | } |
| 1989 | |
| 1990 | static int tavil_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w, |
| 1991 | struct snd_kcontrol *kcontrol, |
| 1992 | int event) |
| 1993 | { |
| 1994 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 1995 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 1996 | struct tavil_dsd_config *dsd_conf = tavil->dsd_config; |
| 1997 | |
| 1998 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 1999 | |
| 2000 | switch (event) { |
| 2001 | case SND_SOC_DAPM_PRE_PMU: |
| 2002 | if (TAVIL_IS_1_0(tavil->wcd9xxx)) |
| 2003 | snd_soc_update_bits(codec, WCD934X_HPH_REFBUFF_LP_CTL, |
| 2004 | 0x06, (0x03 << 1)); |
| 2005 | set_bit(HPH_PA_DELAY, &tavil->status_mask); |
| 2006 | if (dsd_conf && |
| 2007 | (snd_soc_read(codec, WCD934X_CDC_DSD0_PATH_CTL) & 0x01)) { |
| 2008 | /* Set regulator mode to AB if DSD is enabled */ |
| 2009 | snd_soc_update_bits(codec, WCD934X_ANA_RX_SUPPLIES, |
| 2010 | 0x02, 0x02); |
| 2011 | } |
| 2012 | break; |
| 2013 | case SND_SOC_DAPM_POST_PMU: |
| 2014 | /* |
| 2015 | * 7ms sleep is required after PA is enabled as per |
Sudheer Papothi | 3be7677 | 2017-01-11 06:08:13 +0530 | [diff] [blame^] | 2016 | * HW requirement. If compander is disabled, then |
| 2017 | * 20ms delay is needed. |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 2018 | */ |
| 2019 | if (test_bit(HPH_PA_DELAY, &tavil->status_mask)) { |
Sudheer Papothi | 3be7677 | 2017-01-11 06:08:13 +0530 | [diff] [blame^] | 2020 | if (!tavil->comp_enabled[COMPANDER_1]) |
| 2021 | usleep_range(20000, 20100); |
| 2022 | else |
| 2023 | usleep_range(7000, 7100); |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 2024 | clear_bit(HPH_PA_DELAY, &tavil->status_mask); |
| 2025 | } |
| 2026 | snd_soc_update_bits(codec, WCD934X_HPH_L_TEST, 0x01, 0x01); |
| 2027 | /* Remove Mute on primary path */ |
| 2028 | snd_soc_update_bits(codec, WCD934X_CDC_RX1_RX_PATH_CTL, |
| 2029 | 0x10, 0x00); |
| 2030 | /* Enable GM3 boost */ |
| 2031 | snd_soc_update_bits(codec, WCD934X_HPH_CNP_WG_CTL, |
| 2032 | 0x80, 0x80); |
| 2033 | /* Enable AutoChop timer at the end of power up */ |
| 2034 | snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1, |
| 2035 | 0x02, 0x02); |
| 2036 | /* Remove mix path mute if it is enabled */ |
| 2037 | if ((snd_soc_read(codec, WCD934X_CDC_RX1_RX_PATH_MIX_CTL)) & |
| 2038 | 0x10) |
| 2039 | snd_soc_update_bits(codec, |
| 2040 | WCD934X_CDC_RX1_RX_PATH_MIX_CTL, |
| 2041 | 0x10, 0x00); |
| 2042 | if (dsd_conf && |
| 2043 | (snd_soc_read(codec, WCD934X_CDC_DSD0_PATH_CTL) & 0x01)) |
| 2044 | snd_soc_update_bits(codec, WCD934X_CDC_DSD0_CFG2, |
| 2045 | 0x04, 0x00); |
| 2046 | tavil_codec_override(codec, tavil->hph_mode, event); |
| 2047 | break; |
| 2048 | case SND_SOC_DAPM_PRE_PMD: |
| 2049 | blocking_notifier_call_chain(&tavil->mbhc->notifier, |
| 2050 | WCD_EVENT_PRE_HPHL_PA_OFF, |
| 2051 | &tavil->mbhc->wcd_mbhc); |
| 2052 | /* Enable DSD Mute before PA disable */ |
| 2053 | if (dsd_conf && |
| 2054 | (snd_soc_read(codec, WCD934X_CDC_DSD0_PATH_CTL) & 0x01)) |
| 2055 | snd_soc_update_bits(codec, WCD934X_CDC_DSD0_CFG2, |
| 2056 | 0x04, 0x04); |
| 2057 | |
| 2058 | snd_soc_update_bits(codec, WCD934X_HPH_L_TEST, 0x01, 0x00); |
| 2059 | snd_soc_update_bits(codec, WCD934X_CDC_RX1_RX_PATH_CTL, |
| 2060 | 0x10, 0x10); |
Sudheer Papothi | 3be7677 | 2017-01-11 06:08:13 +0530 | [diff] [blame^] | 2061 | snd_soc_update_bits(codec, WCD934X_CDC_RX1_RX_PATH_MIX_CTL, |
| 2062 | 0x10, 0x10); |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 2063 | break; |
| 2064 | case SND_SOC_DAPM_POST_PMD: |
Sudheer Papothi | 3be7677 | 2017-01-11 06:08:13 +0530 | [diff] [blame^] | 2065 | /* |
| 2066 | * 5ms sleep is required after PA disable. If compander is |
| 2067 | * disabled, then 20ms delay is needed after PA disable. |
| 2068 | */ |
| 2069 | if (!tavil->comp_enabled[COMPANDER_1]) |
| 2070 | usleep_range(20000, 20100); |
| 2071 | else |
| 2072 | usleep_range(5000, 5100); |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 2073 | tavil_codec_override(codec, tavil->hph_mode, event); |
| 2074 | blocking_notifier_call_chain(&tavil->mbhc->notifier, |
| 2075 | WCD_EVENT_POST_HPHL_PA_OFF, |
| 2076 | &tavil->mbhc->wcd_mbhc); |
| 2077 | if (TAVIL_IS_1_0(tavil->wcd9xxx)) |
| 2078 | snd_soc_update_bits(codec, WCD934X_HPH_REFBUFF_LP_CTL, |
| 2079 | 0x06, 0x0); |
| 2080 | break; |
| 2081 | }; |
| 2082 | |
| 2083 | return 0; |
| 2084 | } |
| 2085 | |
| 2086 | static int tavil_codec_enable_lineout_pa(struct snd_soc_dapm_widget *w, |
| 2087 | struct snd_kcontrol *kcontrol, |
| 2088 | int event) |
| 2089 | { |
| 2090 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 2091 | u16 lineout_vol_reg = 0, lineout_mix_vol_reg = 0; |
| 2092 | |
| 2093 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 2094 | |
| 2095 | if (w->reg == WCD934X_ANA_LO_1_2) { |
| 2096 | if (w->shift == 7) { |
| 2097 | lineout_vol_reg = WCD934X_CDC_RX3_RX_PATH_CTL; |
| 2098 | lineout_mix_vol_reg = WCD934X_CDC_RX3_RX_PATH_MIX_CTL; |
| 2099 | } else if (w->shift == 6) { |
| 2100 | lineout_vol_reg = WCD934X_CDC_RX4_RX_PATH_CTL; |
| 2101 | lineout_mix_vol_reg = WCD934X_CDC_RX4_RX_PATH_MIX_CTL; |
| 2102 | } |
| 2103 | } else { |
| 2104 | dev_err(codec->dev, "%s: Error enabling lineout PA\n", |
| 2105 | __func__); |
| 2106 | return -EINVAL; |
| 2107 | } |
| 2108 | |
| 2109 | switch (event) { |
| 2110 | case SND_SOC_DAPM_PRE_PMU: |
| 2111 | tavil_codec_override(codec, CLS_AB, event); |
| 2112 | break; |
| 2113 | case SND_SOC_DAPM_POST_PMU: |
| 2114 | /* |
| 2115 | * 5ms sleep is required after PA is enabled as per |
| 2116 | * HW requirement |
| 2117 | */ |
| 2118 | usleep_range(5000, 5500); |
| 2119 | snd_soc_update_bits(codec, lineout_vol_reg, |
| 2120 | 0x10, 0x00); |
| 2121 | /* Remove mix path mute if it is enabled */ |
| 2122 | if ((snd_soc_read(codec, lineout_mix_vol_reg)) & 0x10) |
| 2123 | snd_soc_update_bits(codec, |
| 2124 | lineout_mix_vol_reg, |
| 2125 | 0x10, 0x00); |
| 2126 | break; |
| 2127 | case SND_SOC_DAPM_POST_PMD: |
| 2128 | /* |
| 2129 | * 5ms sleep is required after PA is disabled as per |
| 2130 | * HW requirement |
| 2131 | */ |
| 2132 | usleep_range(5000, 5500); |
| 2133 | tavil_codec_override(codec, CLS_AB, event); |
| 2134 | default: |
| 2135 | break; |
| 2136 | }; |
| 2137 | |
| 2138 | return 0; |
| 2139 | } |
| 2140 | |
| 2141 | static int tavil_codec_ear_dac_event(struct snd_soc_dapm_widget *w, |
| 2142 | struct snd_kcontrol *kcontrol, |
| 2143 | int event) |
| 2144 | { |
| 2145 | int ret = 0; |
| 2146 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 2147 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 2148 | |
| 2149 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 2150 | |
| 2151 | switch (event) { |
| 2152 | case SND_SOC_DAPM_PRE_PMU: |
| 2153 | /* Disable AutoChop timer during power up */ |
| 2154 | snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1, |
| 2155 | 0x02, 0x00); |
| 2156 | |
| 2157 | if (tavil->anc_func) |
| 2158 | ret = tavil_codec_enable_anc(w, kcontrol, event); |
| 2159 | |
| 2160 | wcd_clsh_fsm(codec, &tavil->clsh_d, |
| 2161 | WCD_CLSH_EVENT_PRE_DAC, |
| 2162 | WCD_CLSH_STATE_EAR, |
| 2163 | CLS_H_NORMAL); |
| 2164 | if (tavil->anc_func) |
| 2165 | snd_soc_update_bits(codec, WCD934X_CDC_RX0_RX_PATH_CFG0, |
| 2166 | 0x10, 0x10); |
| 2167 | break; |
| 2168 | case SND_SOC_DAPM_POST_PMD: |
| 2169 | wcd_clsh_fsm(codec, &tavil->clsh_d, |
| 2170 | WCD_CLSH_EVENT_POST_PA, |
| 2171 | WCD_CLSH_STATE_EAR, |
| 2172 | CLS_H_NORMAL); |
| 2173 | break; |
| 2174 | default: |
| 2175 | break; |
| 2176 | }; |
| 2177 | |
| 2178 | return ret; |
| 2179 | } |
| 2180 | |
| 2181 | static int tavil_codec_hphr_dac_event(struct snd_soc_dapm_widget *w, |
| 2182 | struct snd_kcontrol *kcontrol, |
| 2183 | int event) |
| 2184 | { |
| 2185 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 2186 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 2187 | int hph_mode = tavil->hph_mode; |
| 2188 | u8 dem_inp; |
| 2189 | struct tavil_dsd_config *dsd_conf = tavil->dsd_config; |
| 2190 | |
| 2191 | dev_dbg(codec->dev, "%s wname: %s event: %d hph_mode: %d\n", __func__, |
| 2192 | w->name, event, hph_mode); |
| 2193 | |
| 2194 | switch (event) { |
| 2195 | case SND_SOC_DAPM_PRE_PMU: |
| 2196 | /* Read DEM INP Select */ |
| 2197 | dem_inp = snd_soc_read(codec, WCD934X_CDC_RX2_RX_PATH_SEC0) & |
| 2198 | 0x03; |
| 2199 | if (((hph_mode == CLS_H_HIFI) || (hph_mode == CLS_H_LOHIFI) || |
| 2200 | (hph_mode == CLS_H_LP)) && (dem_inp != 0x01)) { |
| 2201 | dev_err(codec->dev, "%s: DEM Input not set correctly, hph_mode: %d\n", |
| 2202 | __func__, hph_mode); |
| 2203 | return -EINVAL; |
| 2204 | } |
| 2205 | if ((hph_mode != CLS_H_LP) && (hph_mode != CLS_H_ULP)) |
| 2206 | /* Ripple freq control enable */ |
| 2207 | snd_soc_update_bits(codec, |
| 2208 | WCD934X_SIDO_NEW_VOUT_D_FREQ2, |
| 2209 | 0x01, 0x01); |
| 2210 | /* Disable AutoChop timer during power up */ |
| 2211 | snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1, |
| 2212 | 0x02, 0x00); |
| 2213 | /* Set RDAC gain */ |
| 2214 | if (TAVIL_IS_1_0(tavil->wcd9xxx)) |
| 2215 | snd_soc_update_bits(codec, |
| 2216 | WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, |
| 2217 | 0xF0, 0x40); |
| 2218 | if (dsd_conf && |
| 2219 | (snd_soc_read(codec, WCD934X_CDC_DSD1_PATH_CTL) & 0x01)) |
| 2220 | hph_mode = CLS_H_HIFI; |
| 2221 | |
| 2222 | wcd_clsh_fsm(codec, &tavil->clsh_d, |
| 2223 | WCD_CLSH_EVENT_PRE_DAC, |
| 2224 | WCD_CLSH_STATE_HPHR, |
| 2225 | hph_mode); |
| 2226 | break; |
| 2227 | case SND_SOC_DAPM_POST_PMD: |
| 2228 | /* 1000us required as per HW requirement */ |
| 2229 | usleep_range(1000, 1100); |
| 2230 | wcd_clsh_fsm(codec, &tavil->clsh_d, |
| 2231 | WCD_CLSH_EVENT_POST_PA, |
| 2232 | WCD_CLSH_STATE_HPHR, |
| 2233 | hph_mode); |
| 2234 | if ((hph_mode != CLS_H_LP) && (hph_mode != CLS_H_ULP)) |
| 2235 | /* Ripple freq control disable */ |
| 2236 | snd_soc_update_bits(codec, |
| 2237 | WCD934X_SIDO_NEW_VOUT_D_FREQ2, |
| 2238 | 0x01, 0x0); |
| 2239 | /* Re-set RDAC gain */ |
| 2240 | if (TAVIL_IS_1_0(tavil->wcd9xxx)) |
| 2241 | snd_soc_update_bits(codec, |
| 2242 | WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, |
| 2243 | 0xF0, 0x0); |
| 2244 | break; |
| 2245 | default: |
| 2246 | break; |
| 2247 | }; |
| 2248 | |
| 2249 | return 0; |
| 2250 | } |
| 2251 | |
| 2252 | static int tavil_codec_hphl_dac_event(struct snd_soc_dapm_widget *w, |
| 2253 | struct snd_kcontrol *kcontrol, |
| 2254 | int event) |
| 2255 | { |
| 2256 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 2257 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 2258 | int hph_mode = tavil->hph_mode; |
| 2259 | u8 dem_inp; |
| 2260 | int ret = 0; |
| 2261 | struct tavil_dsd_config *dsd_conf = tavil->dsd_config; |
Phani Kumar Uppalapati | b506bc0 | 2016-12-06 16:08:24 -0800 | [diff] [blame] | 2262 | uint32_t impedl = 0, impedr = 0; |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 2263 | |
| 2264 | dev_dbg(codec->dev, "%s wname: %s event: %d hph_mode: %d\n", __func__, |
| 2265 | w->name, event, hph_mode); |
| 2266 | |
| 2267 | switch (event) { |
| 2268 | case SND_SOC_DAPM_PRE_PMU: |
| 2269 | /* Read DEM INP Select */ |
| 2270 | dem_inp = snd_soc_read(codec, WCD934X_CDC_RX1_RX_PATH_SEC0) & |
| 2271 | 0x03; |
| 2272 | if (((hph_mode == CLS_H_HIFI) || (hph_mode == CLS_H_LOHIFI) || |
| 2273 | (hph_mode == CLS_H_LP)) && (dem_inp != 0x01)) { |
| 2274 | dev_err(codec->dev, "%s: DEM Input not set correctly, hph_mode: %d\n", |
| 2275 | __func__, hph_mode); |
| 2276 | return -EINVAL; |
| 2277 | } |
| 2278 | if ((hph_mode != CLS_H_LP) && (hph_mode != CLS_H_ULP)) |
| 2279 | /* Ripple freq control enable */ |
| 2280 | snd_soc_update_bits(codec, |
| 2281 | WCD934X_SIDO_NEW_VOUT_D_FREQ2, |
| 2282 | 0x01, 0x01); |
| 2283 | /* Disable AutoChop timer during power up */ |
| 2284 | snd_soc_update_bits(codec, WCD934X_HPH_NEW_INT_HPH_TIMER1, |
| 2285 | 0x02, 0x00); |
| 2286 | /* Set RDAC gain */ |
| 2287 | if (TAVIL_IS_1_0(tavil->wcd9xxx)) |
| 2288 | snd_soc_update_bits(codec, |
| 2289 | WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, |
| 2290 | 0xF0, 0x40); |
| 2291 | if (dsd_conf && |
| 2292 | (snd_soc_read(codec, WCD934X_CDC_DSD0_PATH_CTL) & 0x01)) |
| 2293 | hph_mode = CLS_H_HIFI; |
| 2294 | |
| 2295 | wcd_clsh_fsm(codec, &tavil->clsh_d, |
| 2296 | WCD_CLSH_EVENT_PRE_DAC, |
| 2297 | WCD_CLSH_STATE_HPHL, |
| 2298 | hph_mode); |
Phani Kumar Uppalapati | b506bc0 | 2016-12-06 16:08:24 -0800 | [diff] [blame] | 2299 | |
| 2300 | ret = tavil_mbhc_get_impedance(tavil->mbhc, |
| 2301 | &impedl, &impedr); |
| 2302 | if (!ret) { |
| 2303 | wcd_clsh_imped_config(codec, impedl, false); |
| 2304 | set_bit(CLSH_Z_CONFIG, &tavil->status_mask); |
| 2305 | } else { |
| 2306 | dev_dbg(codec->dev, "%s: Failed to get mbhc impedance %d\n", |
| 2307 | __func__, ret); |
| 2308 | ret = 0; |
| 2309 | } |
| 2310 | |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 2311 | break; |
| 2312 | case SND_SOC_DAPM_POST_PMD: |
| 2313 | /* 1000us required as per HW requirement */ |
| 2314 | usleep_range(1000, 1100); |
| 2315 | wcd_clsh_fsm(codec, &tavil->clsh_d, |
| 2316 | WCD_CLSH_EVENT_POST_PA, |
| 2317 | WCD_CLSH_STATE_HPHL, |
| 2318 | hph_mode); |
| 2319 | if ((hph_mode != CLS_H_LP) && (hph_mode != CLS_H_ULP)) |
| 2320 | /* Ripple freq control disable */ |
| 2321 | snd_soc_update_bits(codec, |
| 2322 | WCD934X_SIDO_NEW_VOUT_D_FREQ2, |
| 2323 | 0x01, 0x0); |
| 2324 | /* Re-set RDAC gain */ |
| 2325 | if (TAVIL_IS_1_0(tavil->wcd9xxx)) |
| 2326 | snd_soc_update_bits(codec, |
| 2327 | WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, |
| 2328 | 0xF0, 0x0); |
Phani Kumar Uppalapati | b506bc0 | 2016-12-06 16:08:24 -0800 | [diff] [blame] | 2329 | |
| 2330 | if (test_bit(CLSH_Z_CONFIG, &tavil->status_mask)) { |
| 2331 | wcd_clsh_imped_config(codec, impedl, true); |
| 2332 | clear_bit(CLSH_Z_CONFIG, &tavil->status_mask); |
| 2333 | } |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 2334 | break; |
| 2335 | default: |
| 2336 | break; |
| 2337 | }; |
| 2338 | |
| 2339 | return ret; |
| 2340 | } |
| 2341 | |
| 2342 | static int tavil_codec_lineout_dac_event(struct snd_soc_dapm_widget *w, |
| 2343 | struct snd_kcontrol *kcontrol, |
| 2344 | int event) |
| 2345 | { |
| 2346 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 2347 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 2348 | |
| 2349 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 2350 | |
| 2351 | switch (event) { |
| 2352 | case SND_SOC_DAPM_PRE_PMU: |
| 2353 | wcd_clsh_fsm(codec, &tavil->clsh_d, |
| 2354 | WCD_CLSH_EVENT_PRE_DAC, |
| 2355 | WCD_CLSH_STATE_LO, |
| 2356 | CLS_AB); |
| 2357 | break; |
| 2358 | case SND_SOC_DAPM_POST_PMD: |
| 2359 | wcd_clsh_fsm(codec, &tavil->clsh_d, |
| 2360 | WCD_CLSH_EVENT_POST_PA, |
| 2361 | WCD_CLSH_STATE_LO, |
| 2362 | CLS_AB); |
| 2363 | break; |
| 2364 | } |
| 2365 | |
| 2366 | return 0; |
| 2367 | } |
| 2368 | |
| 2369 | static int tavil_codec_spk_boost_event(struct snd_soc_dapm_widget *w, |
| 2370 | struct snd_kcontrol *kcontrol, |
| 2371 | int event) |
| 2372 | { |
| 2373 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 2374 | u16 boost_path_ctl, boost_path_cfg1; |
| 2375 | u16 reg, reg_mix; |
| 2376 | |
| 2377 | dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event); |
| 2378 | |
| 2379 | if (!strcmp(w->name, "RX INT7 CHAIN")) { |
| 2380 | boost_path_ctl = WCD934X_CDC_BOOST0_BOOST_PATH_CTL; |
| 2381 | boost_path_cfg1 = WCD934X_CDC_RX7_RX_PATH_CFG1; |
| 2382 | reg = WCD934X_CDC_RX7_RX_PATH_CTL; |
| 2383 | reg_mix = WCD934X_CDC_RX7_RX_PATH_MIX_CTL; |
| 2384 | } else if (!strcmp(w->name, "RX INT8 CHAIN")) { |
| 2385 | boost_path_ctl = WCD934X_CDC_BOOST1_BOOST_PATH_CTL; |
| 2386 | boost_path_cfg1 = WCD934X_CDC_RX8_RX_PATH_CFG1; |
| 2387 | reg = WCD934X_CDC_RX8_RX_PATH_CTL; |
| 2388 | reg_mix = WCD934X_CDC_RX8_RX_PATH_MIX_CTL; |
| 2389 | } else { |
| 2390 | dev_err(codec->dev, "%s: unknown widget: %s\n", |
| 2391 | __func__, w->name); |
| 2392 | return -EINVAL; |
| 2393 | } |
| 2394 | |
| 2395 | switch (event) { |
| 2396 | case SND_SOC_DAPM_PRE_PMU: |
| 2397 | snd_soc_update_bits(codec, boost_path_cfg1, 0x01, 0x01); |
| 2398 | snd_soc_update_bits(codec, boost_path_ctl, 0x10, 0x10); |
| 2399 | snd_soc_update_bits(codec, reg, 0x10, 0x00); |
| 2400 | if ((snd_soc_read(codec, reg_mix)) & 0x10) |
| 2401 | snd_soc_update_bits(codec, reg_mix, 0x10, 0x00); |
| 2402 | break; |
| 2403 | case SND_SOC_DAPM_POST_PMD: |
| 2404 | snd_soc_update_bits(codec, boost_path_ctl, 0x10, 0x00); |
| 2405 | snd_soc_update_bits(codec, boost_path_cfg1, 0x01, 0x00); |
| 2406 | break; |
| 2407 | }; |
| 2408 | |
| 2409 | return 0; |
| 2410 | } |
| 2411 | |
| 2412 | static int __tavil_codec_enable_swr(struct snd_soc_dapm_widget *w, int event) |
| 2413 | { |
| 2414 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 2415 | struct tavil_priv *tavil; |
| 2416 | int ch_cnt = 0; |
| 2417 | |
| 2418 | tavil = snd_soc_codec_get_drvdata(codec); |
| 2419 | |
| 2420 | switch (event) { |
| 2421 | case SND_SOC_DAPM_PRE_PMU: |
| 2422 | if (((strnstr(w->name, "INT7_", sizeof("RX INT7_"))) || |
| 2423 | (strnstr(w->name, "INT7 MIX2", |
| 2424 | sizeof("RX INT7 MIX2"))))) |
| 2425 | tavil->swr.rx_7_count++; |
| 2426 | if ((strnstr(w->name, "INT8_", sizeof("RX INT8_"))) && |
| 2427 | !tavil->swr.rx_8_count) |
| 2428 | tavil->swr.rx_8_count++; |
| 2429 | ch_cnt = !!(tavil->swr.rx_7_count) + tavil->swr.rx_8_count; |
| 2430 | |
| 2431 | swrm_wcd_notify(tavil->swr.ctrl_data[0].swr_pdev, |
| 2432 | SWR_DEVICE_UP, NULL); |
| 2433 | swrm_wcd_notify(tavil->swr.ctrl_data[0].swr_pdev, |
| 2434 | SWR_SET_NUM_RX_CH, &ch_cnt); |
| 2435 | break; |
| 2436 | case SND_SOC_DAPM_POST_PMD: |
| 2437 | if ((strnstr(w->name, "INT7_", sizeof("RX INT7_"))) || |
| 2438 | (strnstr(w->name, "INT7 MIX2", |
| 2439 | sizeof("RX INT7 MIX2")))) |
| 2440 | tavil->swr.rx_7_count--; |
| 2441 | if ((strnstr(w->name, "INT8_", sizeof("RX INT8_"))) && |
| 2442 | tavil->swr.rx_8_count) |
| 2443 | tavil->swr.rx_8_count--; |
| 2444 | ch_cnt = !!(tavil->swr.rx_7_count) + tavil->swr.rx_8_count; |
| 2445 | |
| 2446 | swrm_wcd_notify(tavil->swr.ctrl_data[0].swr_pdev, |
| 2447 | SWR_SET_NUM_RX_CH, &ch_cnt); |
| 2448 | |
| 2449 | break; |
| 2450 | } |
| 2451 | dev_dbg(tavil->dev, "%s: %s: current swr ch cnt: %d\n", |
| 2452 | __func__, w->name, ch_cnt); |
| 2453 | |
| 2454 | return 0; |
| 2455 | } |
| 2456 | |
| 2457 | static int tavil_codec_enable_swr(struct snd_soc_dapm_widget *w, |
| 2458 | struct snd_kcontrol *kcontrol, int event) |
| 2459 | { |
| 2460 | return __tavil_codec_enable_swr(w, event); |
| 2461 | } |
| 2462 | |
| 2463 | static int tavil_codec_config_mad(struct snd_soc_codec *codec) |
| 2464 | { |
| 2465 | int ret = 0; |
| 2466 | int idx; |
| 2467 | const struct firmware *fw; |
| 2468 | struct firmware_cal *hwdep_cal = NULL; |
| 2469 | struct wcd_mad_audio_cal *mad_cal = NULL; |
| 2470 | const void *data; |
| 2471 | const char *filename = WCD934X_MAD_AUDIO_FIRMWARE_PATH; |
| 2472 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 2473 | size_t cal_size; |
| 2474 | |
| 2475 | hwdep_cal = wcdcal_get_fw_cal(tavil->fw_data, WCD9XXX_MAD_CAL); |
| 2476 | if (hwdep_cal) { |
| 2477 | data = hwdep_cal->data; |
| 2478 | cal_size = hwdep_cal->size; |
| 2479 | dev_dbg(codec->dev, "%s: using hwdep calibration\n", |
| 2480 | __func__); |
| 2481 | } else { |
| 2482 | ret = request_firmware(&fw, filename, codec->dev); |
| 2483 | if (ret || !fw) { |
| 2484 | dev_err(codec->dev, |
| 2485 | "%s: MAD firmware acquire failed, err = %d\n", |
| 2486 | __func__, ret); |
| 2487 | return -ENODEV; |
| 2488 | } |
| 2489 | data = fw->data; |
| 2490 | cal_size = fw->size; |
| 2491 | dev_dbg(codec->dev, "%s: using request_firmware calibration\n", |
| 2492 | __func__); |
| 2493 | } |
| 2494 | |
| 2495 | if (cal_size < sizeof(*mad_cal)) { |
| 2496 | dev_err(codec->dev, |
| 2497 | "%s: Incorrect size %zd for MAD Cal, expected %zd\n", |
| 2498 | __func__, cal_size, sizeof(*mad_cal)); |
| 2499 | ret = -ENOMEM; |
| 2500 | goto done; |
| 2501 | } |
| 2502 | |
| 2503 | mad_cal = (struct wcd_mad_audio_cal *) (data); |
| 2504 | if (!mad_cal) { |
| 2505 | dev_err(codec->dev, |
| 2506 | "%s: Invalid calibration data\n", |
| 2507 | __func__); |
| 2508 | ret = -EINVAL; |
| 2509 | goto done; |
| 2510 | } |
| 2511 | |
| 2512 | snd_soc_write(codec, WCD934X_SOC_MAD_MAIN_CTL_2, |
| 2513 | mad_cal->microphone_info.cycle_time); |
| 2514 | snd_soc_update_bits(codec, WCD934X_SOC_MAD_MAIN_CTL_1, 0xFF << 3, |
| 2515 | ((uint16_t)mad_cal->microphone_info.settle_time) |
| 2516 | << 3); |
| 2517 | |
| 2518 | /* Audio */ |
| 2519 | snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_CTL_8, |
| 2520 | mad_cal->audio_info.rms_omit_samples); |
| 2521 | snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_1, |
| 2522 | 0x07 << 4, mad_cal->audio_info.rms_comp_time << 4); |
| 2523 | snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_2, 0x03 << 2, |
| 2524 | mad_cal->audio_info.detection_mechanism << 2); |
| 2525 | snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_CTL_7, |
| 2526 | mad_cal->audio_info.rms_diff_threshold & 0x3F); |
| 2527 | snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_CTL_5, |
| 2528 | mad_cal->audio_info.rms_threshold_lsb); |
| 2529 | snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_CTL_6, |
| 2530 | mad_cal->audio_info.rms_threshold_msb); |
| 2531 | |
| 2532 | for (idx = 0; idx < ARRAY_SIZE(mad_cal->audio_info.iir_coefficients); |
| 2533 | idx++) { |
| 2534 | snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_IIR_CTL_PTR, |
| 2535 | 0x3F, idx); |
| 2536 | snd_soc_write(codec, WCD934X_SOC_MAD_AUDIO_IIR_CTL_VAL, |
| 2537 | mad_cal->audio_info.iir_coefficients[idx]); |
| 2538 | dev_dbg(codec->dev, "%s:MAD Audio IIR Coef[%d] = 0X%x", |
| 2539 | __func__, idx, |
| 2540 | mad_cal->audio_info.iir_coefficients[idx]); |
| 2541 | } |
| 2542 | |
| 2543 | /* Beacon */ |
| 2544 | snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_CTL_8, |
| 2545 | mad_cal->beacon_info.rms_omit_samples); |
| 2546 | snd_soc_update_bits(codec, WCD934X_SOC_MAD_BEACON_CTL_1, |
| 2547 | 0x07 << 4, mad_cal->beacon_info.rms_comp_time << 4); |
| 2548 | snd_soc_update_bits(codec, WCD934X_SOC_MAD_BEACON_CTL_2, 0x03 << 2, |
| 2549 | mad_cal->beacon_info.detection_mechanism << 2); |
| 2550 | snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_CTL_7, |
| 2551 | mad_cal->beacon_info.rms_diff_threshold & 0x1F); |
| 2552 | snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_CTL_5, |
| 2553 | mad_cal->beacon_info.rms_threshold_lsb); |
| 2554 | snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_CTL_6, |
| 2555 | mad_cal->beacon_info.rms_threshold_msb); |
| 2556 | |
| 2557 | for (idx = 0; idx < ARRAY_SIZE(mad_cal->beacon_info.iir_coefficients); |
| 2558 | idx++) { |
| 2559 | snd_soc_update_bits(codec, WCD934X_SOC_MAD_BEACON_IIR_CTL_PTR, |
| 2560 | 0x3F, idx); |
| 2561 | snd_soc_write(codec, WCD934X_SOC_MAD_BEACON_IIR_CTL_VAL, |
| 2562 | mad_cal->beacon_info.iir_coefficients[idx]); |
| 2563 | dev_dbg(codec->dev, "%s:MAD Beacon IIR Coef[%d] = 0X%x", |
| 2564 | __func__, idx, |
| 2565 | mad_cal->beacon_info.iir_coefficients[idx]); |
| 2566 | } |
| 2567 | |
| 2568 | /* Ultrasound */ |
| 2569 | snd_soc_update_bits(codec, WCD934X_SOC_MAD_ULTR_CTL_1, |
| 2570 | 0x07 << 4, |
| 2571 | mad_cal->ultrasound_info.rms_comp_time << 4); |
| 2572 | snd_soc_update_bits(codec, WCD934X_SOC_MAD_ULTR_CTL_2, 0x03 << 2, |
| 2573 | mad_cal->ultrasound_info.detection_mechanism << 2); |
| 2574 | snd_soc_write(codec, WCD934X_SOC_MAD_ULTR_CTL_7, |
| 2575 | mad_cal->ultrasound_info.rms_diff_threshold & 0x1F); |
| 2576 | snd_soc_write(codec, WCD934X_SOC_MAD_ULTR_CTL_5, |
| 2577 | mad_cal->ultrasound_info.rms_threshold_lsb); |
| 2578 | snd_soc_write(codec, WCD934X_SOC_MAD_ULTR_CTL_6, |
| 2579 | mad_cal->ultrasound_info.rms_threshold_msb); |
| 2580 | |
| 2581 | done: |
| 2582 | if (!hwdep_cal) |
| 2583 | release_firmware(fw); |
| 2584 | |
| 2585 | return ret; |
| 2586 | } |
| 2587 | |
| 2588 | static int __tavil_codec_enable_mad(struct snd_soc_codec *codec, bool enable) |
| 2589 | { |
| 2590 | int rc = 0; |
| 2591 | |
| 2592 | /* Return if CPE INPUT is DEC1 */ |
| 2593 | if (snd_soc_read(codec, WCD934X_CPE_SS_SVA_CFG) & 0x04) { |
| 2594 | dev_dbg(codec->dev, "%s: MAD is bypassed, skip mad %s\n", |
| 2595 | __func__, enable ? "enable" : "disable"); |
| 2596 | return rc; |
| 2597 | } |
| 2598 | |
| 2599 | dev_dbg(codec->dev, "%s: enable = %s\n", __func__, |
| 2600 | enable ? "enable" : "disable"); |
| 2601 | |
| 2602 | if (enable) { |
| 2603 | snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_2, |
| 2604 | 0x03, 0x03); |
| 2605 | rc = tavil_codec_config_mad(codec); |
Xiaoyu Ye | 1a2d8bd9 | 2017-01-31 18:54:15 -0800 | [diff] [blame] | 2606 | if (rc < 0) { |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 2607 | snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_2, |
| 2608 | 0x03, 0x00); |
| 2609 | goto done; |
| 2610 | } |
| 2611 | |
| 2612 | /* Turn on MAD clk */ |
| 2613 | snd_soc_update_bits(codec, WCD934X_CPE_SS_MAD_CTL, |
| 2614 | 0x01, 0x01); |
| 2615 | |
| 2616 | /* Undo reset for MAD */ |
| 2617 | snd_soc_update_bits(codec, WCD934X_CPE_SS_MAD_CTL, |
| 2618 | 0x02, 0x00); |
| 2619 | } else { |
| 2620 | snd_soc_update_bits(codec, WCD934X_SOC_MAD_AUDIO_CTL_2, |
| 2621 | 0x03, 0x00); |
| 2622 | /* Reset the MAD block */ |
| 2623 | snd_soc_update_bits(codec, WCD934X_CPE_SS_MAD_CTL, |
| 2624 | 0x02, 0x02); |
| 2625 | /* Turn off MAD clk */ |
| 2626 | snd_soc_update_bits(codec, WCD934X_CPE_SS_MAD_CTL, |
| 2627 | 0x01, 0x00); |
| 2628 | } |
| 2629 | done: |
| 2630 | return rc; |
| 2631 | } |
| 2632 | |
| 2633 | static int tavil_codec_ape_enable_mad(struct snd_soc_dapm_widget *w, |
| 2634 | struct snd_kcontrol *kcontrol, |
| 2635 | int event) |
| 2636 | { |
| 2637 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 2638 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 2639 | int rc = 0; |
| 2640 | |
| 2641 | switch (event) { |
| 2642 | case SND_SOC_DAPM_PRE_PMU: |
| 2643 | snd_soc_update_bits(codec, WCD934X_CPE_SS_SVA_CFG, 0x40, 0x40); |
| 2644 | rc = __tavil_codec_enable_mad(codec, true); |
| 2645 | break; |
| 2646 | case SND_SOC_DAPM_PRE_PMD: |
| 2647 | snd_soc_update_bits(codec, WCD934X_CPE_SS_SVA_CFG, 0x40, 0x00); |
| 2648 | __tavil_codec_enable_mad(codec, false); |
| 2649 | break; |
| 2650 | } |
| 2651 | |
| 2652 | dev_dbg(tavil->dev, "%s: event = %d\n", __func__, event); |
| 2653 | return rc; |
| 2654 | } |
| 2655 | |
| 2656 | static int tavil_codec_cpe_mad_ctl(struct snd_soc_dapm_widget *w, |
| 2657 | struct snd_kcontrol *kcontrol, int event) |
| 2658 | { |
| 2659 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 2660 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 2661 | int rc = 0; |
| 2662 | |
| 2663 | switch (event) { |
| 2664 | case SND_SOC_DAPM_PRE_PMU: |
| 2665 | tavil->mad_switch_cnt++; |
| 2666 | if (tavil->mad_switch_cnt != 1) |
| 2667 | goto done; |
| 2668 | |
| 2669 | snd_soc_update_bits(codec, WCD934X_CPE_SS_SVA_CFG, 0x20, 0x20); |
| 2670 | rc = __tavil_codec_enable_mad(codec, true); |
Xiaoyu Ye | 1a2d8bd9 | 2017-01-31 18:54:15 -0800 | [diff] [blame] | 2671 | if (rc < 0) { |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 2672 | tavil->mad_switch_cnt--; |
| 2673 | goto done; |
| 2674 | } |
| 2675 | |
| 2676 | break; |
| 2677 | case SND_SOC_DAPM_PRE_PMD: |
| 2678 | tavil->mad_switch_cnt--; |
| 2679 | if (tavil->mad_switch_cnt != 0) |
| 2680 | goto done; |
| 2681 | |
| 2682 | snd_soc_update_bits(codec, WCD934X_CPE_SS_SVA_CFG, 0x20, 0x00); |
| 2683 | __tavil_codec_enable_mad(codec, false); |
| 2684 | break; |
| 2685 | } |
| 2686 | done: |
| 2687 | dev_dbg(tavil->dev, "%s: event = %d, mad_switch_cnt = %d\n", |
| 2688 | __func__, event, tavil->mad_switch_cnt); |
| 2689 | return rc; |
| 2690 | } |
| 2691 | |
| 2692 | static int tavil_get_asrc_mode(struct tavil_priv *tavil, int asrc, |
| 2693 | u8 main_sr, u8 mix_sr) |
| 2694 | { |
| 2695 | u8 asrc_output_mode; |
| 2696 | int asrc_mode = CONV_88P2K_TO_384K; |
| 2697 | |
| 2698 | if ((asrc < 0) || (asrc >= ASRC_MAX)) |
| 2699 | return 0; |
| 2700 | |
| 2701 | asrc_output_mode = tavil->asrc_output_mode[asrc]; |
| 2702 | |
| 2703 | if (asrc_output_mode) { |
| 2704 | /* |
| 2705 | * If Mix sample rate is < 96KHz, use 96K to 352.8K |
| 2706 | * conversion, or else use 384K to 352.8K conversion |
| 2707 | */ |
| 2708 | if (mix_sr < 5) |
| 2709 | asrc_mode = CONV_96K_TO_352P8K; |
| 2710 | else |
| 2711 | asrc_mode = CONV_384K_TO_352P8K; |
| 2712 | } else { |
| 2713 | /* Integer main and Fractional mix path */ |
| 2714 | if (main_sr < 8 && mix_sr > 9) { |
| 2715 | asrc_mode = CONV_352P8K_TO_384K; |
| 2716 | } else if (main_sr > 8 && mix_sr < 8) { |
| 2717 | /* Fractional main and Integer mix path */ |
| 2718 | if (mix_sr < 5) |
| 2719 | asrc_mode = CONV_96K_TO_352P8K; |
| 2720 | else |
| 2721 | asrc_mode = CONV_384K_TO_352P8K; |
| 2722 | } else if (main_sr < 8 && mix_sr < 8) { |
| 2723 | /* Integer main and Integer mix path */ |
| 2724 | asrc_mode = CONV_96K_TO_384K; |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | return asrc_mode; |
| 2729 | } |
| 2730 | |
| 2731 | static int tavil_codec_enable_asrc(struct snd_soc_codec *codec, |
| 2732 | int asrc_in, int event) |
| 2733 | { |
| 2734 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 2735 | u16 cfg_reg, ctl_reg, clk_reg, asrc_ctl, mix_ctl_reg; |
| 2736 | int asrc, ret = 0; |
| 2737 | u8 main_sr, mix_sr, asrc_mode = 0; |
| 2738 | |
| 2739 | switch (asrc_in) { |
| 2740 | case ASRC_IN_HPHL: |
| 2741 | cfg_reg = WCD934X_CDC_RX1_RX_PATH_CFG0; |
| 2742 | ctl_reg = WCD934X_CDC_RX1_RX_PATH_CTL; |
| 2743 | clk_reg = WCD934X_MIXING_ASRC0_CLK_RST_CTL; |
| 2744 | asrc_ctl = WCD934X_MIXING_ASRC0_CTL1; |
| 2745 | asrc = ASRC0; |
| 2746 | break; |
| 2747 | case ASRC_IN_LO1: |
| 2748 | cfg_reg = WCD934X_CDC_RX3_RX_PATH_CFG0; |
| 2749 | ctl_reg = WCD934X_CDC_RX3_RX_PATH_CTL; |
| 2750 | clk_reg = WCD934X_MIXING_ASRC0_CLK_RST_CTL; |
| 2751 | asrc_ctl = WCD934X_MIXING_ASRC0_CTL1; |
| 2752 | asrc = ASRC0; |
| 2753 | break; |
| 2754 | case ASRC_IN_HPHR: |
| 2755 | cfg_reg = WCD934X_CDC_RX2_RX_PATH_CFG0; |
| 2756 | ctl_reg = WCD934X_CDC_RX2_RX_PATH_CTL; |
| 2757 | clk_reg = WCD934X_MIXING_ASRC1_CLK_RST_CTL; |
| 2758 | asrc_ctl = WCD934X_MIXING_ASRC1_CTL1; |
| 2759 | asrc = ASRC1; |
| 2760 | break; |
| 2761 | case ASRC_IN_LO2: |
| 2762 | cfg_reg = WCD934X_CDC_RX4_RX_PATH_CFG0; |
| 2763 | ctl_reg = WCD934X_CDC_RX4_RX_PATH_CTL; |
| 2764 | clk_reg = WCD934X_MIXING_ASRC1_CLK_RST_CTL; |
| 2765 | asrc_ctl = WCD934X_MIXING_ASRC1_CTL1; |
| 2766 | asrc = ASRC1; |
| 2767 | break; |
| 2768 | case ASRC_IN_SPKR1: |
| 2769 | cfg_reg = WCD934X_CDC_RX7_RX_PATH_CFG0; |
| 2770 | ctl_reg = WCD934X_CDC_RX7_RX_PATH_CTL; |
| 2771 | clk_reg = WCD934X_MIXING_ASRC2_CLK_RST_CTL; |
| 2772 | asrc_ctl = WCD934X_MIXING_ASRC2_CTL1; |
| 2773 | asrc = ASRC2; |
| 2774 | break; |
| 2775 | case ASRC_IN_SPKR2: |
| 2776 | cfg_reg = WCD934X_CDC_RX8_RX_PATH_CFG0; |
| 2777 | ctl_reg = WCD934X_CDC_RX8_RX_PATH_CTL; |
| 2778 | clk_reg = WCD934X_MIXING_ASRC3_CLK_RST_CTL; |
| 2779 | asrc_ctl = WCD934X_MIXING_ASRC3_CTL1; |
| 2780 | asrc = ASRC3; |
| 2781 | break; |
| 2782 | default: |
| 2783 | dev_err(codec->dev, "%s: Invalid asrc input :%d\n", __func__, |
| 2784 | asrc_in); |
| 2785 | ret = -EINVAL; |
| 2786 | goto done; |
| 2787 | }; |
| 2788 | |
| 2789 | switch (event) { |
| 2790 | case SND_SOC_DAPM_PRE_PMU: |
| 2791 | if (tavil->asrc_users[asrc] == 0) { |
| 2792 | snd_soc_update_bits(codec, cfg_reg, 0x80, 0x80); |
| 2793 | snd_soc_update_bits(codec, clk_reg, 0x01, 0x01); |
| 2794 | main_sr = snd_soc_read(codec, ctl_reg) & 0x0F; |
| 2795 | mix_ctl_reg = ctl_reg + 5; |
| 2796 | mix_sr = snd_soc_read(codec, mix_ctl_reg) & 0x0F; |
| 2797 | asrc_mode = tavil_get_asrc_mode(tavil, asrc, |
| 2798 | main_sr, mix_sr); |
| 2799 | dev_dbg(codec->dev, "%s: main_sr:%d mix_sr:%d asrc_mode %d\n", |
| 2800 | __func__, main_sr, mix_sr, asrc_mode); |
| 2801 | snd_soc_update_bits(codec, asrc_ctl, 0x07, asrc_mode); |
| 2802 | } |
| 2803 | tavil->asrc_users[asrc]++; |
| 2804 | break; |
| 2805 | case SND_SOC_DAPM_POST_PMD: |
| 2806 | tavil->asrc_users[asrc]--; |
| 2807 | if (tavil->asrc_users[asrc] <= 0) { |
| 2808 | tavil->asrc_users[asrc] = 0; |
| 2809 | snd_soc_update_bits(codec, asrc_ctl, 0x07, 0x00); |
| 2810 | snd_soc_update_bits(codec, cfg_reg, 0x80, 0x00); |
| 2811 | snd_soc_update_bits(codec, clk_reg, 0x01, 0x00); |
| 2812 | } |
| 2813 | break; |
| 2814 | }; |
| 2815 | |
| 2816 | dev_dbg(codec->dev, "%s: ASRC%d, users: %d\n", |
| 2817 | __func__, asrc, tavil->asrc_users[asrc]); |
| 2818 | |
| 2819 | done: |
| 2820 | return ret; |
| 2821 | } |
| 2822 | |
| 2823 | static int tavil_codec_enable_asrc_resampler(struct snd_soc_dapm_widget *w, |
| 2824 | struct snd_kcontrol *kcontrol, |
| 2825 | int event) |
| 2826 | { |
| 2827 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 2828 | int ret = 0; |
| 2829 | u8 cfg, asrc_in; |
| 2830 | |
| 2831 | cfg = snd_soc_read(codec, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0); |
| 2832 | if (!(cfg & 0xFF)) { |
| 2833 | dev_err(codec->dev, "%s: ASRC%u input not selected\n", |
| 2834 | __func__, w->shift); |
| 2835 | return -EINVAL; |
| 2836 | } |
| 2837 | |
| 2838 | switch (w->shift) { |
| 2839 | case ASRC0: |
| 2840 | asrc_in = ((cfg & 0x03) == 1) ? ASRC_IN_HPHL : ASRC_IN_LO1; |
| 2841 | ret = tavil_codec_enable_asrc(codec, asrc_in, event); |
| 2842 | break; |
| 2843 | case ASRC1: |
| 2844 | asrc_in = ((cfg & 0x0C) == 4) ? ASRC_IN_HPHR : ASRC_IN_LO2; |
| 2845 | ret = tavil_codec_enable_asrc(codec, asrc_in, event); |
| 2846 | break; |
| 2847 | case ASRC2: |
| 2848 | asrc_in = ((cfg & 0x30) == 0x20) ? ASRC_IN_SPKR1 : ASRC_INVALID; |
| 2849 | ret = tavil_codec_enable_asrc(codec, asrc_in, event); |
| 2850 | break; |
| 2851 | case ASRC3: |
| 2852 | asrc_in = ((cfg & 0xC0) == 0x80) ? ASRC_IN_SPKR2 : ASRC_INVALID; |
| 2853 | ret = tavil_codec_enable_asrc(codec, asrc_in, event); |
| 2854 | break; |
| 2855 | default: |
| 2856 | dev_err(codec->dev, "%s: Invalid asrc:%u\n", __func__, |
| 2857 | w->shift); |
| 2858 | ret = -EINVAL; |
| 2859 | break; |
| 2860 | }; |
| 2861 | |
| 2862 | return ret; |
| 2863 | } |
| 2864 | |
| 2865 | static int tavil_enable_native_supply(struct snd_soc_dapm_widget *w, |
| 2866 | struct snd_kcontrol *kcontrol, int event) |
| 2867 | { |
| 2868 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 2869 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 2870 | |
| 2871 | switch (event) { |
| 2872 | case SND_SOC_DAPM_PRE_PMU: |
| 2873 | if (++tavil->native_clk_users == 1) { |
| 2874 | snd_soc_update_bits(codec, WCD934X_CLK_SYS_PLL_ENABLES, |
| 2875 | 0x01, 0x01); |
| 2876 | usleep_range(100, 120); |
| 2877 | snd_soc_update_bits(codec, WCD934X_CLK_SYS_MCLK2_PRG1, |
| 2878 | 0x06, 0x02); |
| 2879 | snd_soc_update_bits(codec, WCD934X_CLK_SYS_MCLK2_PRG1, |
| 2880 | 0x01, 0x01); |
| 2881 | snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_GATE, |
| 2882 | 0x04, 0x00); |
| 2883 | usleep_range(30, 50); |
| 2884 | snd_soc_update_bits(codec, |
| 2885 | WCD934X_CDC_CLK_RST_CTRL_MCLK_CONTROL, |
| 2886 | 0x02, 0x02); |
| 2887 | snd_soc_update_bits(codec, |
| 2888 | WCD934X_CDC_CLK_RST_CTRL_FS_CNT_CONTROL, |
| 2889 | 0x10, 0x10); |
| 2890 | } |
| 2891 | break; |
| 2892 | case SND_SOC_DAPM_PRE_PMD: |
| 2893 | if (tavil->native_clk_users && |
| 2894 | (--tavil->native_clk_users == 0)) { |
| 2895 | snd_soc_update_bits(codec, |
| 2896 | WCD934X_CDC_CLK_RST_CTRL_FS_CNT_CONTROL, |
| 2897 | 0x10, 0x00); |
| 2898 | snd_soc_update_bits(codec, |
| 2899 | WCD934X_CDC_CLK_RST_CTRL_MCLK_CONTROL, |
| 2900 | 0x02, 0x00); |
| 2901 | snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_GATE, |
| 2902 | 0x04, 0x04); |
| 2903 | snd_soc_update_bits(codec, WCD934X_CLK_SYS_MCLK2_PRG1, |
| 2904 | 0x01, 0x00); |
| 2905 | snd_soc_update_bits(codec, WCD934X_CLK_SYS_MCLK2_PRG1, |
| 2906 | 0x06, 0x00); |
| 2907 | snd_soc_update_bits(codec, WCD934X_CLK_SYS_PLL_ENABLES, |
| 2908 | 0x01, 0x00); |
| 2909 | } |
| 2910 | break; |
| 2911 | } |
| 2912 | |
| 2913 | dev_dbg(codec->dev, "%s: native_clk_users: %d, event: %d\n", |
| 2914 | __func__, tavil->native_clk_users, event); |
| 2915 | |
| 2916 | return 0; |
| 2917 | } |
| 2918 | |
| 2919 | static void tavil_codec_hphdelay_lutbypass(struct snd_soc_codec *codec, |
| 2920 | u16 interp_idx, int event) |
| 2921 | { |
| 2922 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 2923 | u8 hph_dly_mask; |
| 2924 | u16 hph_lut_bypass_reg = 0; |
| 2925 | u16 hph_comp_ctrl7 = 0; |
| 2926 | |
| 2927 | |
| 2928 | switch (interp_idx) { |
| 2929 | case INTERP_HPHL: |
| 2930 | hph_dly_mask = 1; |
| 2931 | hph_lut_bypass_reg = WCD934X_CDC_TOP_HPHL_COMP_LUT; |
| 2932 | hph_comp_ctrl7 = WCD934X_CDC_COMPANDER1_CTL7; |
| 2933 | break; |
| 2934 | case INTERP_HPHR: |
| 2935 | hph_dly_mask = 2; |
| 2936 | hph_lut_bypass_reg = WCD934X_CDC_TOP_HPHR_COMP_LUT; |
| 2937 | hph_comp_ctrl7 = WCD934X_CDC_COMPANDER2_CTL7; |
| 2938 | break; |
| 2939 | default: |
| 2940 | break; |
| 2941 | } |
| 2942 | |
| 2943 | if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_ON(event)) { |
| 2944 | snd_soc_update_bits(codec, WCD934X_CDC_CLSH_TEST0, |
| 2945 | hph_dly_mask, 0x0); |
| 2946 | snd_soc_update_bits(codec, hph_lut_bypass_reg, 0x80, 0x80); |
| 2947 | if (tavil->hph_mode == CLS_H_ULP) |
| 2948 | snd_soc_update_bits(codec, hph_comp_ctrl7, 0x20, 0x20); |
| 2949 | } |
| 2950 | |
| 2951 | if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_OFF(event)) { |
| 2952 | snd_soc_update_bits(codec, WCD934X_CDC_CLSH_TEST0, |
| 2953 | hph_dly_mask, hph_dly_mask); |
| 2954 | snd_soc_update_bits(codec, hph_lut_bypass_reg, 0x80, 0x00); |
| 2955 | snd_soc_update_bits(codec, hph_comp_ctrl7, 0x20, 0x0); |
| 2956 | } |
| 2957 | } |
| 2958 | |
| 2959 | static void tavil_codec_hd2_control(struct tavil_priv *priv, |
| 2960 | u16 interp_idx, int event) |
| 2961 | { |
| 2962 | u16 hd2_scale_reg; |
| 2963 | u16 hd2_enable_reg = 0; |
| 2964 | struct snd_soc_codec *codec = priv->codec; |
| 2965 | |
| 2966 | if (TAVIL_IS_1_1(priv->wcd9xxx)) |
| 2967 | return; |
| 2968 | |
| 2969 | switch (interp_idx) { |
| 2970 | case INTERP_HPHL: |
| 2971 | hd2_scale_reg = WCD934X_CDC_RX1_RX_PATH_SEC3; |
| 2972 | hd2_enable_reg = WCD934X_CDC_RX1_RX_PATH_CFG0; |
| 2973 | break; |
| 2974 | case INTERP_HPHR: |
| 2975 | hd2_scale_reg = WCD934X_CDC_RX2_RX_PATH_SEC3; |
| 2976 | hd2_enable_reg = WCD934X_CDC_RX2_RX_PATH_CFG0; |
| 2977 | break; |
| 2978 | } |
| 2979 | |
| 2980 | if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) { |
| 2981 | snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x14); |
| 2982 | snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x04); |
| 2983 | } |
| 2984 | |
| 2985 | if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) { |
| 2986 | snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x00); |
| 2987 | snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x00); |
| 2988 | } |
| 2989 | } |
| 2990 | |
| 2991 | static int tavil_codec_config_ear_spkr_gain(struct snd_soc_codec *codec, |
| 2992 | int event, int gain_reg) |
| 2993 | { |
| 2994 | int comp_gain_offset, val; |
| 2995 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 2996 | |
| 2997 | switch (tavil->swr.spkr_mode) { |
| 2998 | /* Compander gain in SPKR_MODE1 case is 12 dB */ |
| 2999 | case WCD934X_SPKR_MODE_1: |
| 3000 | comp_gain_offset = -12; |
| 3001 | break; |
| 3002 | /* Default case compander gain is 15 dB */ |
| 3003 | default: |
| 3004 | comp_gain_offset = -15; |
| 3005 | break; |
| 3006 | } |
| 3007 | |
| 3008 | switch (event) { |
| 3009 | case SND_SOC_DAPM_POST_PMU: |
| 3010 | /* Apply ear spkr gain only if compander is enabled */ |
| 3011 | if (tavil->comp_enabled[COMPANDER_7] && |
| 3012 | (gain_reg == WCD934X_CDC_RX7_RX_VOL_CTL || |
| 3013 | gain_reg == WCD934X_CDC_RX7_RX_VOL_MIX_CTL) && |
| 3014 | (tavil->ear_spkr_gain != 0)) { |
| 3015 | /* For example, val is -8(-12+5-1) for 4dB of gain */ |
| 3016 | val = comp_gain_offset + tavil->ear_spkr_gain - 1; |
| 3017 | snd_soc_write(codec, gain_reg, val); |
| 3018 | |
| 3019 | dev_dbg(codec->dev, "%s: RX7 Volume %d dB\n", |
| 3020 | __func__, val); |
| 3021 | } |
| 3022 | break; |
| 3023 | case SND_SOC_DAPM_POST_PMD: |
| 3024 | /* |
| 3025 | * Reset RX7 volume to 0 dB if compander is enabled and |
| 3026 | * ear_spkr_gain is non-zero. |
| 3027 | */ |
| 3028 | if (tavil->comp_enabled[COMPANDER_7] && |
| 3029 | (gain_reg == WCD934X_CDC_RX7_RX_VOL_CTL || |
| 3030 | gain_reg == WCD934X_CDC_RX7_RX_VOL_MIX_CTL) && |
| 3031 | (tavil->ear_spkr_gain != 0)) { |
| 3032 | snd_soc_write(codec, gain_reg, 0x0); |
| 3033 | |
| 3034 | dev_dbg(codec->dev, "%s: Reset RX7 Volume to 0 dB\n", |
| 3035 | __func__); |
| 3036 | } |
| 3037 | break; |
| 3038 | } |
| 3039 | |
| 3040 | return 0; |
| 3041 | } |
| 3042 | |
| 3043 | static int tavil_config_compander(struct snd_soc_codec *codec, int interp_n, |
| 3044 | int event) |
| 3045 | { |
| 3046 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 3047 | int comp; |
| 3048 | u16 comp_ctl0_reg, rx_path_cfg0_reg; |
| 3049 | |
| 3050 | /* EAR does not have compander */ |
| 3051 | if (!interp_n) |
| 3052 | return 0; |
| 3053 | |
| 3054 | comp = interp_n - 1; |
| 3055 | dev_dbg(codec->dev, "%s: event %d compander %d, enabled %d\n", |
| 3056 | __func__, event, comp + 1, tavil->comp_enabled[comp]); |
| 3057 | |
| 3058 | if (!tavil->comp_enabled[comp]) |
| 3059 | return 0; |
| 3060 | |
| 3061 | comp_ctl0_reg = WCD934X_CDC_COMPANDER1_CTL0 + (comp * 8); |
| 3062 | rx_path_cfg0_reg = WCD934X_CDC_RX1_RX_PATH_CFG0 + (comp * 20); |
| 3063 | |
| 3064 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
| 3065 | /* Enable Compander Clock */ |
| 3066 | snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x01); |
| 3067 | snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02); |
| 3068 | snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00); |
| 3069 | snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x02); |
| 3070 | } |
| 3071 | |
| 3072 | if (SND_SOC_DAPM_EVENT_OFF(event)) { |
| 3073 | snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x00); |
| 3074 | snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x04); |
| 3075 | snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02); |
| 3076 | snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00); |
| 3077 | snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x00); |
| 3078 | snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x00); |
| 3079 | } |
| 3080 | |
| 3081 | return 0; |
| 3082 | } |
| 3083 | |
| 3084 | static void tavil_codec_idle_detect_control(struct snd_soc_codec *codec, |
| 3085 | int interp, int event) |
| 3086 | { |
| 3087 | int reg = 0, mask, val; |
| 3088 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 3089 | |
| 3090 | if (!tavil->idle_det_cfg.hph_idle_detect_en) |
| 3091 | return; |
| 3092 | |
| 3093 | if (interp == INTERP_HPHL) { |
| 3094 | reg = WCD934X_CDC_RX_IDLE_DET_PATH_CTL; |
| 3095 | mask = 0x01; |
| 3096 | val = 0x01; |
| 3097 | } |
| 3098 | if (interp == INTERP_HPHR) { |
| 3099 | reg = WCD934X_CDC_RX_IDLE_DET_PATH_CTL; |
| 3100 | mask = 0x02; |
| 3101 | val = 0x02; |
| 3102 | } |
| 3103 | |
| 3104 | if (reg && SND_SOC_DAPM_EVENT_ON(event)) |
| 3105 | snd_soc_update_bits(codec, reg, mask, val); |
| 3106 | |
| 3107 | if (reg && SND_SOC_DAPM_EVENT_OFF(event)) { |
| 3108 | snd_soc_update_bits(codec, reg, mask, 0x00); |
| 3109 | tavil->idle_det_cfg.hph_idle_thr = 0; |
| 3110 | snd_soc_write(codec, WCD934X_CDC_RX_IDLE_DET_CFG3, 0x0); |
| 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | /** |
| 3115 | * tavil_codec_enable_interp_clk - Enable main path Interpolator |
| 3116 | * clock. |
| 3117 | * |
| 3118 | * @codec: Codec instance |
| 3119 | * @event: Indicates speaker path gain offset value |
| 3120 | * @intp_idx: Interpolator index |
| 3121 | * Returns number of main clock users |
| 3122 | */ |
| 3123 | int tavil_codec_enable_interp_clk(struct snd_soc_codec *codec, |
| 3124 | int event, int interp_idx) |
| 3125 | { |
| 3126 | struct tavil_priv *tavil; |
| 3127 | u16 main_reg; |
| 3128 | |
| 3129 | if (!codec) { |
| 3130 | pr_err("%s: codec is NULL\n", __func__); |
| 3131 | return -EINVAL; |
| 3132 | } |
| 3133 | |
| 3134 | tavil = snd_soc_codec_get_drvdata(codec); |
| 3135 | main_reg = WCD934X_CDC_RX0_RX_PATH_CTL + (interp_idx * 20); |
| 3136 | |
| 3137 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
| 3138 | if (tavil->main_clk_users[interp_idx] == 0) { |
| 3139 | /* Main path PGA mute enable */ |
| 3140 | snd_soc_update_bits(codec, main_reg, 0x10, 0x10); |
| 3141 | /* Clk enable */ |
| 3142 | snd_soc_update_bits(codec, main_reg, 0x20, 0x20); |
| 3143 | tavil_codec_idle_detect_control(codec, interp_idx, |
| 3144 | event); |
| 3145 | tavil_codec_hd2_control(tavil, interp_idx, event); |
| 3146 | tavil_codec_hphdelay_lutbypass(codec, interp_idx, |
| 3147 | event); |
| 3148 | tavil_config_compander(codec, interp_idx, event); |
| 3149 | } |
| 3150 | tavil->main_clk_users[interp_idx]++; |
| 3151 | } |
| 3152 | |
| 3153 | if (SND_SOC_DAPM_EVENT_OFF(event)) { |
| 3154 | tavil->main_clk_users[interp_idx]--; |
| 3155 | if (tavil->main_clk_users[interp_idx] <= 0) { |
| 3156 | tavil->main_clk_users[interp_idx] = 0; |
| 3157 | tavil_config_compander(codec, interp_idx, event); |
| 3158 | tavil_codec_hphdelay_lutbypass(codec, interp_idx, |
| 3159 | event); |
| 3160 | tavil_codec_hd2_control(tavil, interp_idx, event); |
| 3161 | tavil_codec_idle_detect_control(codec, interp_idx, |
| 3162 | event); |
| 3163 | /* Clk Disable */ |
| 3164 | snd_soc_update_bits(codec, main_reg, 0x20, 0x00); |
| 3165 | /* Reset enable and disable */ |
| 3166 | snd_soc_update_bits(codec, main_reg, 0x40, 0x40); |
| 3167 | snd_soc_update_bits(codec, main_reg, 0x40, 0x00); |
| 3168 | /* Reset rate to 48K*/ |
| 3169 | snd_soc_update_bits(codec, main_reg, 0x0F, 0x04); |
| 3170 | } |
| 3171 | } |
| 3172 | |
| 3173 | dev_dbg(codec->dev, "%s event %d main_clk_users %d\n", |
| 3174 | __func__, event, tavil->main_clk_users[interp_idx]); |
| 3175 | |
| 3176 | return tavil->main_clk_users[interp_idx]; |
| 3177 | } |
| 3178 | EXPORT_SYMBOL(tavil_codec_enable_interp_clk); |
| 3179 | |
| 3180 | static int tavil_codec_set_idle_detect_thr(struct snd_soc_codec *codec, |
| 3181 | int interp, int path_type) |
| 3182 | { |
| 3183 | int port_id[4] = { 0, 0, 0, 0 }; |
| 3184 | int *port_ptr, num_ports; |
| 3185 | int bit_width = 0, i; |
| 3186 | int mux_reg, mux_reg_val; |
| 3187 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 3188 | int dai_id, idle_thr; |
| 3189 | |
| 3190 | if ((interp != INTERP_HPHL) && (interp != INTERP_HPHR)) |
| 3191 | return 0; |
| 3192 | |
| 3193 | if (!tavil->idle_det_cfg.hph_idle_detect_en) |
| 3194 | return 0; |
| 3195 | |
| 3196 | port_ptr = &port_id[0]; |
| 3197 | num_ports = 0; |
| 3198 | |
| 3199 | /* |
| 3200 | * Read interpolator MUX input registers and find |
| 3201 | * which slimbus port is connected and store the port |
| 3202 | * numbers in port_id array. |
| 3203 | */ |
| 3204 | if (path_type == INTERP_MIX_PATH) { |
| 3205 | mux_reg = WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG1 + |
| 3206 | 2 * (interp - 1); |
| 3207 | mux_reg_val = snd_soc_read(codec, mux_reg) & 0x0f; |
| 3208 | |
| 3209 | if ((mux_reg_val >= INTn_2_INP_SEL_RX0) && |
| 3210 | (mux_reg_val < INTn_2_INP_SEL_PROXIMITY)) { |
| 3211 | *port_ptr++ = mux_reg_val + |
| 3212 | WCD934X_RX_PORT_START_NUMBER - 1; |
| 3213 | num_ports++; |
| 3214 | } |
| 3215 | } |
| 3216 | |
| 3217 | if (path_type == INTERP_MAIN_PATH) { |
| 3218 | mux_reg = WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG0 + |
| 3219 | 2 * (interp - 1); |
| 3220 | mux_reg_val = snd_soc_read(codec, mux_reg) & 0x0f; |
| 3221 | i = WCD934X_INTERP_MUX_NUM_INPUTS; |
| 3222 | |
| 3223 | while (i) { |
| 3224 | if ((mux_reg_val >= INTn_1_INP_SEL_RX0) && |
| 3225 | (mux_reg_val <= INTn_1_INP_SEL_RX7)) { |
| 3226 | *port_ptr++ = mux_reg_val + |
| 3227 | WCD934X_RX_PORT_START_NUMBER - |
| 3228 | INTn_1_INP_SEL_RX0; |
| 3229 | num_ports++; |
| 3230 | } |
| 3231 | mux_reg_val = (snd_soc_read(codec, mux_reg) & |
| 3232 | 0xf0) >> 4; |
| 3233 | mux_reg += 1; |
| 3234 | i--; |
| 3235 | } |
| 3236 | } |
| 3237 | |
| 3238 | dev_dbg(codec->dev, "%s: num_ports: %d, ports[%d %d %d %d]\n", |
| 3239 | __func__, num_ports, port_id[0], port_id[1], |
| 3240 | port_id[2], port_id[3]); |
| 3241 | |
| 3242 | i = 0; |
| 3243 | while (num_ports) { |
| 3244 | dai_id = tavil_find_playback_dai_id_for_port(port_id[i++], |
| 3245 | tavil); |
| 3246 | |
| 3247 | if ((dai_id >= 0) && (dai_id < NUM_CODEC_DAIS)) { |
| 3248 | dev_dbg(codec->dev, "%s: dai_id: %d bit_width: %d\n", |
| 3249 | __func__, dai_id, |
| 3250 | tavil->dai[dai_id].bit_width); |
| 3251 | |
| 3252 | if (tavil->dai[dai_id].bit_width > bit_width) |
| 3253 | bit_width = tavil->dai[dai_id].bit_width; |
| 3254 | } |
| 3255 | |
| 3256 | num_ports--; |
| 3257 | } |
| 3258 | |
| 3259 | switch (bit_width) { |
| 3260 | case 16: |
| 3261 | idle_thr = 0xff; /* F16 */ |
| 3262 | break; |
| 3263 | case 24: |
| 3264 | case 32: |
| 3265 | idle_thr = 0x03; /* F22 */ |
| 3266 | break; |
| 3267 | default: |
| 3268 | idle_thr = 0x00; |
| 3269 | break; |
| 3270 | } |
| 3271 | |
| 3272 | dev_dbg(codec->dev, "%s: (new) idle_thr: %d, (cur) idle_thr: %d\n", |
| 3273 | __func__, idle_thr, tavil->idle_det_cfg.hph_idle_thr); |
| 3274 | |
| 3275 | if ((tavil->idle_det_cfg.hph_idle_thr == 0) || |
| 3276 | (idle_thr < tavil->idle_det_cfg.hph_idle_thr)) { |
| 3277 | snd_soc_write(codec, WCD934X_CDC_RX_IDLE_DET_CFG3, idle_thr); |
| 3278 | tavil->idle_det_cfg.hph_idle_thr = idle_thr; |
| 3279 | } |
| 3280 | |
| 3281 | return 0; |
| 3282 | } |
| 3283 | |
| 3284 | static int tavil_codec_enable_mix_path(struct snd_soc_dapm_widget *w, |
| 3285 | struct snd_kcontrol *kcontrol, |
| 3286 | int event) |
| 3287 | { |
| 3288 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 3289 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 3290 | u16 gain_reg, mix_reg; |
| 3291 | int offset_val = 0; |
| 3292 | int val = 0; |
| 3293 | |
| 3294 | if (w->shift >= WCD934X_NUM_INTERPOLATORS || |
| 3295 | w->shift == INTERP_LO3_NA || w->shift == INTERP_LO4_NA) { |
| 3296 | dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n", |
| 3297 | __func__, w->shift, w->name); |
| 3298 | return -EINVAL; |
| 3299 | }; |
| 3300 | |
| 3301 | gain_reg = WCD934X_CDC_RX0_RX_VOL_MIX_CTL + |
| 3302 | (w->shift * WCD934X_RX_PATH_CTL_OFFSET); |
| 3303 | mix_reg = WCD934X_CDC_RX0_RX_PATH_MIX_CTL + |
| 3304 | (w->shift * WCD934X_RX_PATH_CTL_OFFSET); |
| 3305 | |
| 3306 | if (w->shift == INTERP_SPKR1 || w->shift == INTERP_SPKR2) |
| 3307 | __tavil_codec_enable_swr(w, event); |
| 3308 | |
| 3309 | switch (event) { |
| 3310 | case SND_SOC_DAPM_PRE_PMU: |
| 3311 | tavil_codec_set_idle_detect_thr(codec, w->shift, |
| 3312 | INTERP_MIX_PATH); |
| 3313 | tavil_codec_enable_interp_clk(codec, event, w->shift); |
| 3314 | /* Clk enable */ |
| 3315 | snd_soc_update_bits(codec, mix_reg, 0x20, 0x20); |
| 3316 | break; |
| 3317 | case SND_SOC_DAPM_POST_PMU: |
| 3318 | if ((tavil->swr.spkr_gain_offset == |
| 3319 | WCD934X_RX_GAIN_OFFSET_M1P5_DB) && |
| 3320 | (tavil->comp_enabled[COMPANDER_7] || |
| 3321 | tavil->comp_enabled[COMPANDER_8]) && |
| 3322 | (gain_reg == WCD934X_CDC_RX7_RX_VOL_MIX_CTL || |
| 3323 | gain_reg == WCD934X_CDC_RX8_RX_VOL_MIX_CTL)) { |
| 3324 | snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_SEC1, |
| 3325 | 0x01, 0x01); |
| 3326 | snd_soc_update_bits(codec, |
| 3327 | WCD934X_CDC_RX7_RX_PATH_MIX_SEC0, |
| 3328 | 0x01, 0x01); |
| 3329 | snd_soc_update_bits(codec, WCD934X_CDC_RX8_RX_PATH_SEC1, |
| 3330 | 0x01, 0x01); |
| 3331 | snd_soc_update_bits(codec, |
| 3332 | WCD934X_CDC_RX8_RX_PATH_MIX_SEC0, |
| 3333 | 0x01, 0x01); |
| 3334 | offset_val = -2; |
| 3335 | } |
| 3336 | val = snd_soc_read(codec, gain_reg); |
| 3337 | val += offset_val; |
| 3338 | snd_soc_write(codec, gain_reg, val); |
| 3339 | tavil_codec_config_ear_spkr_gain(codec, event, gain_reg); |
| 3340 | break; |
| 3341 | case SND_SOC_DAPM_POST_PMD: |
| 3342 | /* Clk Disable */ |
| 3343 | snd_soc_update_bits(codec, mix_reg, 0x20, 0x00); |
| 3344 | tavil_codec_enable_interp_clk(codec, event, w->shift); |
| 3345 | /* Reset enable and disable */ |
| 3346 | snd_soc_update_bits(codec, mix_reg, 0x40, 0x40); |
| 3347 | snd_soc_update_bits(codec, mix_reg, 0x40, 0x00); |
| 3348 | |
| 3349 | if ((tavil->swr.spkr_gain_offset == |
| 3350 | WCD934X_RX_GAIN_OFFSET_M1P5_DB) && |
| 3351 | (tavil->comp_enabled[COMPANDER_7] || |
| 3352 | tavil->comp_enabled[COMPANDER_8]) && |
| 3353 | (gain_reg == WCD934X_CDC_RX7_RX_VOL_MIX_CTL || |
| 3354 | gain_reg == WCD934X_CDC_RX8_RX_VOL_MIX_CTL)) { |
| 3355 | snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_SEC1, |
| 3356 | 0x01, 0x00); |
| 3357 | snd_soc_update_bits(codec, |
| 3358 | WCD934X_CDC_RX7_RX_PATH_MIX_SEC0, |
| 3359 | 0x01, 0x00); |
| 3360 | snd_soc_update_bits(codec, WCD934X_CDC_RX8_RX_PATH_SEC1, |
| 3361 | 0x01, 0x00); |
| 3362 | snd_soc_update_bits(codec, |
| 3363 | WCD934X_CDC_RX8_RX_PATH_MIX_SEC0, |
| 3364 | 0x01, 0x00); |
| 3365 | offset_val = 2; |
| 3366 | val = snd_soc_read(codec, gain_reg); |
| 3367 | val += offset_val; |
| 3368 | snd_soc_write(codec, gain_reg, val); |
| 3369 | } |
| 3370 | tavil_codec_config_ear_spkr_gain(codec, event, gain_reg); |
| 3371 | break; |
| 3372 | }; |
| 3373 | dev_dbg(codec->dev, "%s event %d name %s\n", __func__, event, w->name); |
| 3374 | |
| 3375 | return 0; |
| 3376 | } |
| 3377 | |
| 3378 | /** |
| 3379 | * tavil_get_dsd_config - Get pointer to dsd config structure |
| 3380 | * |
| 3381 | * @codec: pointer to snd_soc_codec structure |
| 3382 | * |
| 3383 | * Returns pointer to tavil_dsd_config structure |
| 3384 | */ |
| 3385 | struct tavil_dsd_config *tavil_get_dsd_config(struct snd_soc_codec *codec) |
| 3386 | { |
| 3387 | struct tavil_priv *tavil; |
| 3388 | |
| 3389 | if (!codec) |
| 3390 | return NULL; |
| 3391 | |
| 3392 | tavil = snd_soc_codec_get_drvdata(codec); |
| 3393 | |
| 3394 | if (!tavil) |
| 3395 | return NULL; |
| 3396 | |
| 3397 | return tavil->dsd_config; |
| 3398 | } |
| 3399 | EXPORT_SYMBOL(tavil_get_dsd_config); |
| 3400 | |
| 3401 | static int tavil_codec_enable_main_path(struct snd_soc_dapm_widget *w, |
| 3402 | struct snd_kcontrol *kcontrol, |
| 3403 | int event) |
| 3404 | { |
| 3405 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 3406 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 3407 | u16 gain_reg; |
| 3408 | u16 reg; |
| 3409 | int val; |
| 3410 | int offset_val = 0; |
| 3411 | |
| 3412 | dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name); |
| 3413 | |
| 3414 | if (w->shift >= WCD934X_NUM_INTERPOLATORS || |
| 3415 | w->shift == INTERP_LO3_NA || w->shift == INTERP_LO4_NA) { |
| 3416 | dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n", |
| 3417 | __func__, w->shift, w->name); |
| 3418 | return -EINVAL; |
| 3419 | }; |
| 3420 | |
| 3421 | reg = WCD934X_CDC_RX0_RX_PATH_CTL + (w->shift * |
| 3422 | WCD934X_RX_PATH_CTL_OFFSET); |
| 3423 | gain_reg = WCD934X_CDC_RX0_RX_VOL_CTL + (w->shift * |
| 3424 | WCD934X_RX_PATH_CTL_OFFSET); |
| 3425 | |
| 3426 | switch (event) { |
| 3427 | case SND_SOC_DAPM_PRE_PMU: |
| 3428 | tavil_codec_set_idle_detect_thr(codec, w->shift, |
| 3429 | INTERP_MAIN_PATH); |
| 3430 | tavil_codec_enable_interp_clk(codec, event, w->shift); |
| 3431 | break; |
| 3432 | case SND_SOC_DAPM_POST_PMU: |
| 3433 | /* apply gain after int clk is enabled */ |
| 3434 | if ((tavil->swr.spkr_gain_offset == |
| 3435 | WCD934X_RX_GAIN_OFFSET_M1P5_DB) && |
| 3436 | (tavil->comp_enabled[COMPANDER_7] || |
| 3437 | tavil->comp_enabled[COMPANDER_8]) && |
| 3438 | (gain_reg == WCD934X_CDC_RX7_RX_VOL_CTL || |
| 3439 | gain_reg == WCD934X_CDC_RX8_RX_VOL_CTL)) { |
| 3440 | snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_SEC1, |
| 3441 | 0x01, 0x01); |
| 3442 | snd_soc_update_bits(codec, |
| 3443 | WCD934X_CDC_RX7_RX_PATH_MIX_SEC0, |
| 3444 | 0x01, 0x01); |
| 3445 | snd_soc_update_bits(codec, WCD934X_CDC_RX8_RX_PATH_SEC1, |
| 3446 | 0x01, 0x01); |
| 3447 | snd_soc_update_bits(codec, |
| 3448 | WCD934X_CDC_RX8_RX_PATH_MIX_SEC0, |
| 3449 | 0x01, 0x01); |
| 3450 | offset_val = -2; |
| 3451 | } |
| 3452 | val = snd_soc_read(codec, gain_reg); |
| 3453 | val += offset_val; |
| 3454 | snd_soc_write(codec, gain_reg, val); |
| 3455 | tavil_codec_config_ear_spkr_gain(codec, event, gain_reg); |
| 3456 | break; |
| 3457 | case SND_SOC_DAPM_POST_PMD: |
| 3458 | tavil_codec_enable_interp_clk(codec, event, w->shift); |
| 3459 | |
| 3460 | if ((tavil->swr.spkr_gain_offset == |
| 3461 | WCD934X_RX_GAIN_OFFSET_M1P5_DB) && |
| 3462 | (tavil->comp_enabled[COMPANDER_7] || |
| 3463 | tavil->comp_enabled[COMPANDER_8]) && |
| 3464 | (gain_reg == WCD934X_CDC_RX7_RX_VOL_CTL || |
| 3465 | gain_reg == WCD934X_CDC_RX8_RX_VOL_CTL)) { |
| 3466 | snd_soc_update_bits(codec, WCD934X_CDC_RX7_RX_PATH_SEC1, |
| 3467 | 0x01, 0x00); |
| 3468 | snd_soc_update_bits(codec, |
| 3469 | WCD934X_CDC_RX7_RX_PATH_MIX_SEC0, |
| 3470 | 0x01, 0x00); |
| 3471 | snd_soc_update_bits(codec, WCD934X_CDC_RX8_RX_PATH_SEC1, |
| 3472 | 0x01, 0x00); |
| 3473 | snd_soc_update_bits(codec, |
| 3474 | WCD934X_CDC_RX8_RX_PATH_MIX_SEC0, |
| 3475 | 0x01, 0x00); |
| 3476 | offset_val = 2; |
| 3477 | val = snd_soc_read(codec, gain_reg); |
| 3478 | val += offset_val; |
| 3479 | snd_soc_write(codec, gain_reg, val); |
| 3480 | } |
| 3481 | tavil_codec_config_ear_spkr_gain(codec, event, gain_reg); |
| 3482 | break; |
| 3483 | }; |
| 3484 | |
| 3485 | return 0; |
| 3486 | } |
| 3487 | |
| 3488 | static int tavil_codec_set_iir_gain(struct snd_soc_dapm_widget *w, |
| 3489 | struct snd_kcontrol *kcontrol, int event) |
| 3490 | { |
| 3491 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 3492 | |
| 3493 | dev_dbg(codec->dev, "%s: event = %d\n", __func__, event); |
| 3494 | |
| 3495 | switch (event) { |
| 3496 | case SND_SOC_DAPM_POST_PMU: /* fall through */ |
| 3497 | case SND_SOC_DAPM_PRE_PMD: |
| 3498 | if (strnstr(w->name, "IIR0", sizeof("IIR0"))) { |
| 3499 | snd_soc_write(codec, |
| 3500 | WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL, |
| 3501 | snd_soc_read(codec, |
| 3502 | WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL)); |
| 3503 | snd_soc_write(codec, |
| 3504 | WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL, |
| 3505 | snd_soc_read(codec, |
| 3506 | WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL)); |
| 3507 | snd_soc_write(codec, |
| 3508 | WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL, |
| 3509 | snd_soc_read(codec, |
| 3510 | WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL)); |
| 3511 | snd_soc_write(codec, |
| 3512 | WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL, |
| 3513 | snd_soc_read(codec, |
| 3514 | WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL)); |
| 3515 | } else { |
| 3516 | snd_soc_write(codec, |
| 3517 | WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B1_CTL, |
| 3518 | snd_soc_read(codec, |
| 3519 | WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B1_CTL)); |
| 3520 | snd_soc_write(codec, |
| 3521 | WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B2_CTL, |
| 3522 | snd_soc_read(codec, |
| 3523 | WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B2_CTL)); |
| 3524 | snd_soc_write(codec, |
| 3525 | WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B3_CTL, |
| 3526 | snd_soc_read(codec, |
| 3527 | WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B3_CTL)); |
| 3528 | } |
| 3529 | break; |
| 3530 | } |
| 3531 | return 0; |
| 3532 | } |
| 3533 | |
| 3534 | static int tavil_codec_find_amic_input(struct snd_soc_codec *codec, |
| 3535 | int adc_mux_n) |
| 3536 | { |
| 3537 | u16 mask, shift, adc_mux_in_reg; |
| 3538 | u16 amic_mux_sel_reg; |
| 3539 | bool is_amic; |
| 3540 | |
| 3541 | if (adc_mux_n < 0 || adc_mux_n > WCD934X_MAX_VALID_ADC_MUX || |
| 3542 | adc_mux_n == WCD934X_INVALID_ADC_MUX) |
| 3543 | return 0; |
| 3544 | |
| 3545 | if (adc_mux_n < 3) { |
| 3546 | adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1 + |
| 3547 | adc_mux_n; |
| 3548 | mask = 0x03; |
| 3549 | shift = 0; |
| 3550 | amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0 + |
| 3551 | 2 * adc_mux_n; |
| 3552 | } else if (adc_mux_n < 4) { |
| 3553 | adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1; |
| 3554 | mask = 0x03; |
| 3555 | shift = 0; |
| 3556 | amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0 + |
| 3557 | 2 * adc_mux_n; |
| 3558 | } else if (adc_mux_n < 7) { |
| 3559 | adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1 + |
| 3560 | (adc_mux_n - 4); |
| 3561 | mask = 0x0C; |
| 3562 | shift = 2; |
| 3563 | amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 + |
| 3564 | adc_mux_n - 4; |
| 3565 | } else if (adc_mux_n < 8) { |
| 3566 | adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1; |
| 3567 | mask = 0x0C; |
| 3568 | shift = 2; |
| 3569 | amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 + |
| 3570 | adc_mux_n - 4; |
| 3571 | } else if (adc_mux_n < 12) { |
| 3572 | adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1 + |
| 3573 | ((adc_mux_n == 8) ? (adc_mux_n - 8) : |
| 3574 | (adc_mux_n - 9)); |
| 3575 | mask = 0x30; |
| 3576 | shift = 4; |
| 3577 | amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 + |
| 3578 | adc_mux_n - 4; |
| 3579 | } else if (adc_mux_n < 13) { |
| 3580 | adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1; |
| 3581 | mask = 0x30; |
| 3582 | shift = 4; |
| 3583 | amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 + |
| 3584 | adc_mux_n - 4; |
| 3585 | } else { |
| 3586 | adc_mux_in_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1; |
| 3587 | mask = 0xC0; |
| 3588 | shift = 6; |
| 3589 | amic_mux_sel_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 + |
| 3590 | adc_mux_n - 4; |
| 3591 | } |
| 3592 | |
| 3593 | is_amic = (((snd_soc_read(codec, adc_mux_in_reg) & mask) >> shift) |
| 3594 | == 1); |
| 3595 | if (!is_amic) |
| 3596 | return 0; |
| 3597 | |
| 3598 | return snd_soc_read(codec, amic_mux_sel_reg) & 0x07; |
| 3599 | } |
| 3600 | |
| 3601 | static void tavil_codec_set_tx_hold(struct snd_soc_codec *codec, |
| 3602 | u16 amic_reg, bool set) |
| 3603 | { |
| 3604 | u8 mask = 0x20; |
| 3605 | u8 val; |
| 3606 | |
| 3607 | if (amic_reg == WCD934X_ANA_AMIC1 || |
| 3608 | amic_reg == WCD934X_ANA_AMIC3) |
| 3609 | mask = 0x40; |
| 3610 | |
| 3611 | val = set ? mask : 0x00; |
| 3612 | |
| 3613 | switch (amic_reg) { |
| 3614 | case WCD934X_ANA_AMIC1: |
| 3615 | case WCD934X_ANA_AMIC2: |
| 3616 | snd_soc_update_bits(codec, WCD934X_ANA_AMIC2, mask, val); |
| 3617 | break; |
| 3618 | case WCD934X_ANA_AMIC3: |
| 3619 | case WCD934X_ANA_AMIC4: |
| 3620 | snd_soc_update_bits(codec, WCD934X_ANA_AMIC4, mask, val); |
| 3621 | break; |
| 3622 | default: |
| 3623 | dev_dbg(codec->dev, "%s: invalid amic: %d\n", |
| 3624 | __func__, amic_reg); |
| 3625 | break; |
| 3626 | } |
| 3627 | } |
| 3628 | |
| 3629 | static int tavil_codec_tx_adc_cfg(struct snd_soc_dapm_widget *w, |
| 3630 | struct snd_kcontrol *kcontrol, int event) |
| 3631 | { |
| 3632 | int adc_mux_n = w->shift; |
| 3633 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 3634 | int amic_n; |
| 3635 | u16 amic_reg; |
| 3636 | |
| 3637 | dev_dbg(codec->dev, "%s: event: %d\n", __func__, event); |
| 3638 | |
| 3639 | switch (event) { |
| 3640 | case SND_SOC_DAPM_POST_PMU: |
| 3641 | amic_n = tavil_codec_find_amic_input(codec, adc_mux_n); |
| 3642 | if (amic_n) { |
| 3643 | amic_reg = WCD934X_ANA_AMIC1 + amic_n - 1; |
| 3644 | tavil_codec_set_tx_hold(codec, amic_reg, false); |
| 3645 | } |
| 3646 | break; |
| 3647 | default: |
| 3648 | break; |
| 3649 | } |
| 3650 | |
| 3651 | return 0; |
| 3652 | } |
| 3653 | |
| 3654 | static u16 tavil_codec_get_amic_pwlvl_reg(struct snd_soc_codec *codec, int amic) |
| 3655 | { |
| 3656 | u16 pwr_level_reg = 0; |
| 3657 | |
| 3658 | switch (amic) { |
| 3659 | case 1: |
| 3660 | case 2: |
| 3661 | pwr_level_reg = WCD934X_ANA_AMIC1; |
| 3662 | break; |
| 3663 | |
| 3664 | case 3: |
| 3665 | case 4: |
| 3666 | pwr_level_reg = WCD934X_ANA_AMIC3; |
| 3667 | break; |
| 3668 | default: |
| 3669 | dev_dbg(codec->dev, "%s: invalid amic: %d\n", |
| 3670 | __func__, amic); |
| 3671 | break; |
| 3672 | } |
| 3673 | |
| 3674 | return pwr_level_reg; |
| 3675 | } |
| 3676 | |
| 3677 | #define TX_HPF_CUT_OFF_FREQ_MASK 0x60 |
| 3678 | #define CF_MIN_3DB_4HZ 0x0 |
| 3679 | #define CF_MIN_3DB_75HZ 0x1 |
| 3680 | #define CF_MIN_3DB_150HZ 0x2 |
| 3681 | |
| 3682 | static void tavil_tx_hpf_corner_freq_callback(struct work_struct *work) |
| 3683 | { |
| 3684 | struct delayed_work *hpf_delayed_work; |
| 3685 | struct hpf_work *hpf_work; |
| 3686 | struct tavil_priv *tavil; |
| 3687 | struct snd_soc_codec *codec; |
| 3688 | u16 dec_cfg_reg, amic_reg, go_bit_reg; |
| 3689 | u8 hpf_cut_off_freq; |
| 3690 | int amic_n; |
| 3691 | |
| 3692 | hpf_delayed_work = to_delayed_work(work); |
| 3693 | hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork); |
| 3694 | tavil = hpf_work->tavil; |
| 3695 | codec = tavil->codec; |
| 3696 | hpf_cut_off_freq = hpf_work->hpf_cut_off_freq; |
| 3697 | |
| 3698 | dec_cfg_reg = WCD934X_CDC_TX0_TX_PATH_CFG0 + 16 * hpf_work->decimator; |
| 3699 | go_bit_reg = dec_cfg_reg + 7; |
| 3700 | |
| 3701 | dev_dbg(codec->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n", |
| 3702 | __func__, hpf_work->decimator, hpf_cut_off_freq); |
| 3703 | |
| 3704 | amic_n = tavil_codec_find_amic_input(codec, hpf_work->decimator); |
| 3705 | if (amic_n) { |
| 3706 | amic_reg = WCD934X_ANA_AMIC1 + amic_n - 1; |
| 3707 | tavil_codec_set_tx_hold(codec, amic_reg, false); |
| 3708 | } |
| 3709 | snd_soc_update_bits(codec, dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK, |
| 3710 | hpf_cut_off_freq << 5); |
| 3711 | snd_soc_update_bits(codec, go_bit_reg, 0x02, 0x02); |
| 3712 | /* Minimum 1 clk cycle delay is required as per HW spec */ |
| 3713 | usleep_range(1000, 1010); |
| 3714 | snd_soc_update_bits(codec, go_bit_reg, 0x02, 0x00); |
| 3715 | } |
| 3716 | |
| 3717 | static void tavil_tx_mute_update_callback(struct work_struct *work) |
| 3718 | { |
| 3719 | struct tx_mute_work *tx_mute_dwork; |
| 3720 | struct tavil_priv *tavil; |
| 3721 | struct delayed_work *delayed_work; |
| 3722 | struct snd_soc_codec *codec; |
| 3723 | u16 tx_vol_ctl_reg, hpf_gate_reg; |
| 3724 | |
| 3725 | delayed_work = to_delayed_work(work); |
| 3726 | tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork); |
| 3727 | tavil = tx_mute_dwork->tavil; |
| 3728 | codec = tavil->codec; |
| 3729 | |
| 3730 | tx_vol_ctl_reg = WCD934X_CDC_TX0_TX_PATH_CTL + |
| 3731 | 16 * tx_mute_dwork->decimator; |
| 3732 | hpf_gate_reg = WCD934X_CDC_TX0_TX_PATH_SEC2 + |
| 3733 | 16 * tx_mute_dwork->decimator; |
| 3734 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00); |
| 3735 | } |
| 3736 | |
| 3737 | static int tavil_codec_enable_rx_path_clk(struct snd_soc_dapm_widget *w, |
| 3738 | struct snd_kcontrol *kcontrol, int event) |
| 3739 | { |
| 3740 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 3741 | u16 sidetone_reg; |
| 3742 | |
| 3743 | dev_dbg(codec->dev, "%s %d %d\n", __func__, event, w->shift); |
| 3744 | sidetone_reg = WCD934X_CDC_RX0_RX_PATH_CFG1 + 0x14*(w->shift); |
| 3745 | |
| 3746 | switch (event) { |
| 3747 | case SND_SOC_DAPM_PRE_PMU: |
| 3748 | if (!strcmp(w->name, "RX INT7 MIX2 INP")) |
| 3749 | __tavil_codec_enable_swr(w, event); |
| 3750 | tavil_codec_enable_interp_clk(codec, event, w->shift); |
| 3751 | snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x10); |
| 3752 | break; |
| 3753 | case SND_SOC_DAPM_POST_PMD: |
| 3754 | snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x00); |
| 3755 | tavil_codec_enable_interp_clk(codec, event, w->shift); |
| 3756 | if (!strcmp(w->name, "RX INT7 MIX2 INP")) |
| 3757 | __tavil_codec_enable_swr(w, event); |
| 3758 | break; |
| 3759 | default: |
| 3760 | break; |
| 3761 | }; |
| 3762 | return 0; |
| 3763 | } |
| 3764 | |
| 3765 | static int tavil_codec_enable_dec(struct snd_soc_dapm_widget *w, |
| 3766 | struct snd_kcontrol *kcontrol, int event) |
| 3767 | { |
| 3768 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 3769 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 3770 | unsigned int decimator; |
| 3771 | char *dec_adc_mux_name = NULL; |
| 3772 | char *widget_name = NULL; |
| 3773 | char *wname; |
| 3774 | int ret = 0, amic_n; |
| 3775 | u16 tx_vol_ctl_reg, pwr_level_reg = 0, dec_cfg_reg, hpf_gate_reg; |
| 3776 | u16 tx_gain_ctl_reg; |
| 3777 | char *dec; |
| 3778 | u8 hpf_cut_off_freq; |
| 3779 | |
| 3780 | dev_dbg(codec->dev, "%s %d\n", __func__, event); |
| 3781 | |
| 3782 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 3783 | if (!widget_name) |
| 3784 | return -ENOMEM; |
| 3785 | |
| 3786 | wname = widget_name; |
| 3787 | dec_adc_mux_name = strsep(&widget_name, " "); |
| 3788 | if (!dec_adc_mux_name) { |
| 3789 | dev_err(codec->dev, "%s: Invalid decimator = %s\n", |
| 3790 | __func__, w->name); |
| 3791 | ret = -EINVAL; |
| 3792 | goto out; |
| 3793 | } |
| 3794 | dec_adc_mux_name = widget_name; |
| 3795 | |
| 3796 | dec = strpbrk(dec_adc_mux_name, "012345678"); |
| 3797 | if (!dec) { |
| 3798 | dev_err(codec->dev, "%s: decimator index not found\n", |
| 3799 | __func__); |
| 3800 | ret = -EINVAL; |
| 3801 | goto out; |
| 3802 | } |
| 3803 | |
| 3804 | ret = kstrtouint(dec, 10, &decimator); |
| 3805 | if (ret < 0) { |
| 3806 | dev_err(codec->dev, "%s: Invalid decimator = %s\n", |
| 3807 | __func__, wname); |
| 3808 | ret = -EINVAL; |
| 3809 | goto out; |
| 3810 | } |
| 3811 | |
| 3812 | dev_dbg(codec->dev, "%s(): widget = %s decimator = %u\n", __func__, |
| 3813 | w->name, decimator); |
| 3814 | |
| 3815 | tx_vol_ctl_reg = WCD934X_CDC_TX0_TX_PATH_CTL + 16 * decimator; |
| 3816 | hpf_gate_reg = WCD934X_CDC_TX0_TX_PATH_SEC2 + 16 * decimator; |
| 3817 | dec_cfg_reg = WCD934X_CDC_TX0_TX_PATH_CFG0 + 16 * decimator; |
| 3818 | tx_gain_ctl_reg = WCD934X_CDC_TX0_TX_VOL_CTL + 16 * decimator; |
| 3819 | |
| 3820 | switch (event) { |
| 3821 | case SND_SOC_DAPM_PRE_PMU: |
| 3822 | amic_n = tavil_codec_find_amic_input(codec, decimator); |
| 3823 | if (amic_n) |
| 3824 | pwr_level_reg = tavil_codec_get_amic_pwlvl_reg(codec, |
| 3825 | amic_n); |
| 3826 | |
| 3827 | if (pwr_level_reg) { |
| 3828 | switch ((snd_soc_read(codec, pwr_level_reg) & |
| 3829 | WCD934X_AMIC_PWR_LVL_MASK) >> |
| 3830 | WCD934X_AMIC_PWR_LVL_SHIFT) { |
| 3831 | case WCD934X_AMIC_PWR_LEVEL_LP: |
| 3832 | snd_soc_update_bits(codec, dec_cfg_reg, |
| 3833 | WCD934X_DEC_PWR_LVL_MASK, |
| 3834 | WCD934X_DEC_PWR_LVL_LP); |
| 3835 | break; |
| 3836 | |
| 3837 | case WCD934X_AMIC_PWR_LEVEL_HP: |
| 3838 | snd_soc_update_bits(codec, dec_cfg_reg, |
| 3839 | WCD934X_DEC_PWR_LVL_MASK, |
| 3840 | WCD934X_DEC_PWR_LVL_HP); |
| 3841 | break; |
| 3842 | case WCD934X_AMIC_PWR_LEVEL_DEFAULT: |
| 3843 | default: |
| 3844 | snd_soc_update_bits(codec, dec_cfg_reg, |
| 3845 | WCD934X_DEC_PWR_LVL_MASK, |
| 3846 | WCD934X_DEC_PWR_LVL_DF); |
| 3847 | break; |
| 3848 | } |
| 3849 | } |
| 3850 | /* Enable TX PGA Mute */ |
| 3851 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10); |
| 3852 | break; |
| 3853 | case SND_SOC_DAPM_POST_PMU: |
| 3854 | hpf_cut_off_freq = (snd_soc_read(codec, dec_cfg_reg) & |
| 3855 | TX_HPF_CUT_OFF_FREQ_MASK) >> 5; |
| 3856 | |
| 3857 | tavil->tx_hpf_work[decimator].hpf_cut_off_freq = |
| 3858 | hpf_cut_off_freq; |
| 3859 | if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) { |
| 3860 | snd_soc_update_bits(codec, dec_cfg_reg, |
| 3861 | TX_HPF_CUT_OFF_FREQ_MASK, |
| 3862 | CF_MIN_3DB_150HZ << 5); |
| 3863 | snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x02); |
| 3864 | /* |
| 3865 | * Minimum 1 clk cycle delay is required as per |
| 3866 | * HW spec. |
| 3867 | */ |
| 3868 | usleep_range(1000, 1010); |
| 3869 | snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x00); |
| 3870 | } |
| 3871 | /* schedule work queue to Remove Mute */ |
| 3872 | schedule_delayed_work(&tavil->tx_mute_dwork[decimator].dwork, |
| 3873 | msecs_to_jiffies(tx_unmute_delay)); |
| 3874 | if (tavil->tx_hpf_work[decimator].hpf_cut_off_freq != |
| 3875 | CF_MIN_3DB_150HZ) |
| 3876 | schedule_delayed_work( |
| 3877 | &tavil->tx_hpf_work[decimator].dwork, |
| 3878 | msecs_to_jiffies(300)); |
| 3879 | /* apply gain after decimator is enabled */ |
| 3880 | snd_soc_write(codec, tx_gain_ctl_reg, |
| 3881 | snd_soc_read(codec, tx_gain_ctl_reg)); |
| 3882 | break; |
| 3883 | case SND_SOC_DAPM_PRE_PMD: |
| 3884 | hpf_cut_off_freq = |
| 3885 | tavil->tx_hpf_work[decimator].hpf_cut_off_freq; |
| 3886 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10); |
| 3887 | if (cancel_delayed_work_sync( |
| 3888 | &tavil->tx_hpf_work[decimator].dwork)) { |
| 3889 | if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) { |
| 3890 | snd_soc_update_bits(codec, dec_cfg_reg, |
| 3891 | TX_HPF_CUT_OFF_FREQ_MASK, |
| 3892 | hpf_cut_off_freq << 5); |
| 3893 | snd_soc_update_bits(codec, hpf_gate_reg, |
| 3894 | 0x02, 0x02); |
| 3895 | /* |
| 3896 | * Minimum 1 clk cycle delay is required as per |
| 3897 | * HW spec. |
| 3898 | */ |
| 3899 | usleep_range(1000, 1010); |
| 3900 | snd_soc_update_bits(codec, hpf_gate_reg, |
| 3901 | 0x02, 0x00); |
| 3902 | } |
| 3903 | } |
| 3904 | cancel_delayed_work_sync( |
| 3905 | &tavil->tx_mute_dwork[decimator].dwork); |
| 3906 | break; |
| 3907 | case SND_SOC_DAPM_POST_PMD: |
| 3908 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00); |
| 3909 | snd_soc_update_bits(codec, dec_cfg_reg, |
| 3910 | WCD934X_DEC_PWR_LVL_MASK, |
| 3911 | WCD934X_DEC_PWR_LVL_DF); |
| 3912 | break; |
| 3913 | }; |
| 3914 | out: |
| 3915 | kfree(wname); |
| 3916 | return ret; |
| 3917 | } |
| 3918 | |
| 3919 | static u32 tavil_get_dmic_sample_rate(struct snd_soc_codec *codec, |
| 3920 | unsigned int dmic, |
| 3921 | struct wcd9xxx_pdata *pdata) |
| 3922 | { |
| 3923 | u8 tx_stream_fs; |
| 3924 | u8 adc_mux_index = 0, adc_mux_sel = 0; |
| 3925 | bool dec_found = false; |
| 3926 | u16 adc_mux_ctl_reg, tx_fs_reg; |
| 3927 | u32 dmic_fs; |
| 3928 | |
| 3929 | while (dec_found == 0 && adc_mux_index < WCD934X_MAX_VALID_ADC_MUX) { |
| 3930 | if (adc_mux_index < 4) { |
| 3931 | adc_mux_ctl_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0 + |
| 3932 | (adc_mux_index * 2); |
| 3933 | } else if (adc_mux_index < WCD934X_INVALID_ADC_MUX) { |
| 3934 | adc_mux_ctl_reg = WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0 + |
| 3935 | adc_mux_index - 4; |
| 3936 | } else if (adc_mux_index == WCD934X_INVALID_ADC_MUX) { |
| 3937 | ++adc_mux_index; |
| 3938 | continue; |
| 3939 | } |
| 3940 | adc_mux_sel = ((snd_soc_read(codec, adc_mux_ctl_reg) & |
| 3941 | 0xF8) >> 3) - 1; |
| 3942 | |
| 3943 | if (adc_mux_sel == dmic) { |
| 3944 | dec_found = true; |
| 3945 | break; |
| 3946 | } |
| 3947 | |
| 3948 | ++adc_mux_index; |
| 3949 | } |
| 3950 | |
| 3951 | if (dec_found && adc_mux_index <= 8) { |
| 3952 | tx_fs_reg = WCD934X_CDC_TX0_TX_PATH_CTL + (16 * adc_mux_index); |
| 3953 | tx_stream_fs = snd_soc_read(codec, tx_fs_reg) & 0x0F; |
| 3954 | if (tx_stream_fs <= 4) { |
| 3955 | if (pdata->dmic_sample_rate <= |
| 3956 | WCD9XXX_DMIC_SAMPLE_RATE_2P4MHZ) |
| 3957 | dmic_fs = pdata->dmic_sample_rate; |
| 3958 | else |
| 3959 | dmic_fs = WCD9XXX_DMIC_SAMPLE_RATE_2P4MHZ; |
| 3960 | } else |
| 3961 | dmic_fs = WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ; |
| 3962 | } else { |
| 3963 | dmic_fs = pdata->dmic_sample_rate; |
| 3964 | } |
| 3965 | |
| 3966 | return dmic_fs; |
| 3967 | } |
| 3968 | |
| 3969 | static u8 tavil_get_dmic_clk_val(struct snd_soc_codec *codec, |
| 3970 | u32 mclk_rate, u32 dmic_clk_rate) |
| 3971 | { |
| 3972 | u32 div_factor; |
| 3973 | u8 dmic_ctl_val; |
| 3974 | |
| 3975 | dev_dbg(codec->dev, |
| 3976 | "%s: mclk_rate = %d, dmic_sample_rate = %d\n", |
| 3977 | __func__, mclk_rate, dmic_clk_rate); |
| 3978 | |
| 3979 | /* Default value to return in case of error */ |
| 3980 | if (mclk_rate == WCD934X_MCLK_CLK_9P6MHZ) |
| 3981 | dmic_ctl_val = WCD934X_DMIC_CLK_DIV_2; |
| 3982 | else |
| 3983 | dmic_ctl_val = WCD934X_DMIC_CLK_DIV_3; |
| 3984 | |
| 3985 | if (dmic_clk_rate == 0) { |
| 3986 | dev_err(codec->dev, |
| 3987 | "%s: dmic_sample_rate cannot be 0\n", |
| 3988 | __func__); |
| 3989 | goto done; |
| 3990 | } |
| 3991 | |
| 3992 | div_factor = mclk_rate / dmic_clk_rate; |
| 3993 | switch (div_factor) { |
| 3994 | case 2: |
| 3995 | dmic_ctl_val = WCD934X_DMIC_CLK_DIV_2; |
| 3996 | break; |
| 3997 | case 3: |
| 3998 | dmic_ctl_val = WCD934X_DMIC_CLK_DIV_3; |
| 3999 | break; |
| 4000 | case 4: |
| 4001 | dmic_ctl_val = WCD934X_DMIC_CLK_DIV_4; |
| 4002 | break; |
| 4003 | case 6: |
| 4004 | dmic_ctl_val = WCD934X_DMIC_CLK_DIV_6; |
| 4005 | break; |
| 4006 | case 8: |
| 4007 | dmic_ctl_val = WCD934X_DMIC_CLK_DIV_8; |
| 4008 | break; |
| 4009 | case 16: |
| 4010 | dmic_ctl_val = WCD934X_DMIC_CLK_DIV_16; |
| 4011 | break; |
| 4012 | default: |
| 4013 | dev_err(codec->dev, |
| 4014 | "%s: Invalid div_factor %u, clk_rate(%u), dmic_rate(%u)\n", |
| 4015 | __func__, div_factor, mclk_rate, dmic_clk_rate); |
| 4016 | break; |
| 4017 | } |
| 4018 | |
| 4019 | done: |
| 4020 | return dmic_ctl_val; |
| 4021 | } |
| 4022 | |
| 4023 | static int tavil_codec_enable_adc(struct snd_soc_dapm_widget *w, |
| 4024 | struct snd_kcontrol *kcontrol, int event) |
| 4025 | { |
| 4026 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 4027 | |
| 4028 | dev_dbg(codec->dev, "%s: event:%d\n", __func__, event); |
| 4029 | |
| 4030 | switch (event) { |
| 4031 | case SND_SOC_DAPM_PRE_PMU: |
| 4032 | tavil_codec_set_tx_hold(codec, w->reg, true); |
| 4033 | break; |
| 4034 | default: |
| 4035 | break; |
| 4036 | } |
| 4037 | |
| 4038 | return 0; |
| 4039 | } |
| 4040 | |
| 4041 | static int tavil_codec_enable_dmic(struct snd_soc_dapm_widget *w, |
| 4042 | struct snd_kcontrol *kcontrol, int event) |
| 4043 | { |
| 4044 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 4045 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 4046 | struct wcd9xxx_pdata *pdata = dev_get_platdata(codec->dev->parent); |
| 4047 | u8 dmic_clk_en = 0x01; |
| 4048 | u16 dmic_clk_reg; |
| 4049 | s32 *dmic_clk_cnt; |
| 4050 | u8 dmic_rate_val, dmic_rate_shift = 1; |
| 4051 | unsigned int dmic; |
| 4052 | u32 dmic_sample_rate; |
| 4053 | int ret; |
| 4054 | char *wname; |
| 4055 | |
| 4056 | wname = strpbrk(w->name, "012345"); |
| 4057 | if (!wname) { |
| 4058 | dev_err(codec->dev, "%s: widget not found\n", __func__); |
| 4059 | return -EINVAL; |
| 4060 | } |
| 4061 | |
| 4062 | ret = kstrtouint(wname, 10, &dmic); |
| 4063 | if (ret < 0) { |
| 4064 | dev_err(codec->dev, "%s: Invalid DMIC line on the codec\n", |
| 4065 | __func__); |
| 4066 | return -EINVAL; |
| 4067 | } |
| 4068 | |
| 4069 | switch (dmic) { |
| 4070 | case 0: |
| 4071 | case 1: |
| 4072 | dmic_clk_cnt = &(tavil->dmic_0_1_clk_cnt); |
| 4073 | dmic_clk_reg = WCD934X_CPE_SS_DMIC0_CTL; |
| 4074 | break; |
| 4075 | case 2: |
| 4076 | case 3: |
| 4077 | dmic_clk_cnt = &(tavil->dmic_2_3_clk_cnt); |
| 4078 | dmic_clk_reg = WCD934X_CPE_SS_DMIC1_CTL; |
| 4079 | break; |
| 4080 | case 4: |
| 4081 | case 5: |
| 4082 | dmic_clk_cnt = &(tavil->dmic_4_5_clk_cnt); |
| 4083 | dmic_clk_reg = WCD934X_CPE_SS_DMIC2_CTL; |
| 4084 | break; |
| 4085 | default: |
| 4086 | dev_err(codec->dev, "%s: Invalid DMIC Selection\n", |
| 4087 | __func__); |
| 4088 | return -EINVAL; |
| 4089 | }; |
| 4090 | dev_dbg(codec->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n", |
| 4091 | __func__, event, dmic, *dmic_clk_cnt); |
| 4092 | |
| 4093 | switch (event) { |
| 4094 | case SND_SOC_DAPM_PRE_PMU: |
| 4095 | dmic_sample_rate = tavil_get_dmic_sample_rate(codec, dmic, |
| 4096 | pdata); |
| 4097 | dmic_rate_val = |
| 4098 | tavil_get_dmic_clk_val(codec, |
| 4099 | pdata->mclk_rate, |
| 4100 | dmic_sample_rate); |
| 4101 | |
| 4102 | (*dmic_clk_cnt)++; |
| 4103 | if (*dmic_clk_cnt == 1) { |
| 4104 | snd_soc_update_bits(codec, dmic_clk_reg, |
| 4105 | 0x07 << dmic_rate_shift, |
| 4106 | dmic_rate_val << dmic_rate_shift); |
| 4107 | snd_soc_update_bits(codec, dmic_clk_reg, |
| 4108 | dmic_clk_en, dmic_clk_en); |
| 4109 | } |
| 4110 | |
| 4111 | break; |
| 4112 | case SND_SOC_DAPM_POST_PMD: |
| 4113 | dmic_rate_val = |
| 4114 | tavil_get_dmic_clk_val(codec, |
| 4115 | pdata->mclk_rate, |
| 4116 | pdata->mad_dmic_sample_rate); |
| 4117 | (*dmic_clk_cnt)--; |
| 4118 | if (*dmic_clk_cnt == 0) { |
| 4119 | snd_soc_update_bits(codec, dmic_clk_reg, |
| 4120 | dmic_clk_en, 0); |
| 4121 | snd_soc_update_bits(codec, dmic_clk_reg, |
| 4122 | 0x07 << dmic_rate_shift, |
| 4123 | dmic_rate_val << dmic_rate_shift); |
| 4124 | } |
| 4125 | break; |
| 4126 | }; |
| 4127 | |
| 4128 | return 0; |
| 4129 | } |
| 4130 | |
| 4131 | /* |
| 4132 | * tavil_mbhc_micb_adjust_voltage: adjust specific micbias voltage |
| 4133 | * @codec: handle to snd_soc_codec * |
| 4134 | * @req_volt: micbias voltage to be set |
| 4135 | * @micb_num: micbias to be set, e.g. micbias1 or micbias2 |
| 4136 | * |
| 4137 | * return 0 if adjustment is success or error code in case of failure |
| 4138 | */ |
| 4139 | int tavil_mbhc_micb_adjust_voltage(struct snd_soc_codec *codec, |
| 4140 | int req_volt, int micb_num) |
| 4141 | { |
| 4142 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 4143 | int cur_vout_ctl, req_vout_ctl; |
| 4144 | int micb_reg, micb_val, micb_en; |
| 4145 | int ret = 0; |
| 4146 | |
| 4147 | switch (micb_num) { |
| 4148 | case MIC_BIAS_1: |
| 4149 | micb_reg = WCD934X_ANA_MICB1; |
| 4150 | break; |
| 4151 | case MIC_BIAS_2: |
| 4152 | micb_reg = WCD934X_ANA_MICB2; |
| 4153 | break; |
| 4154 | case MIC_BIAS_3: |
| 4155 | micb_reg = WCD934X_ANA_MICB3; |
| 4156 | break; |
| 4157 | case MIC_BIAS_4: |
| 4158 | micb_reg = WCD934X_ANA_MICB4; |
| 4159 | break; |
| 4160 | default: |
| 4161 | return -EINVAL; |
| 4162 | } |
| 4163 | mutex_lock(&tavil->micb_lock); |
| 4164 | |
| 4165 | /* |
| 4166 | * If requested micbias voltage is same as current micbias |
| 4167 | * voltage, then just return. Otherwise, adjust voltage as |
| 4168 | * per requested value. If micbias is already enabled, then |
| 4169 | * to avoid slow micbias ramp-up or down enable pull-up |
| 4170 | * momentarily, change the micbias value and then re-enable |
| 4171 | * micbias. |
| 4172 | */ |
| 4173 | micb_val = snd_soc_read(codec, micb_reg); |
| 4174 | micb_en = (micb_val & 0xC0) >> 6; |
| 4175 | cur_vout_ctl = micb_val & 0x3F; |
| 4176 | |
| 4177 | req_vout_ctl = wcd934x_get_micb_vout_ctl_val(req_volt); |
Xiaoyu Ye | 1a2d8bd9 | 2017-01-31 18:54:15 -0800 | [diff] [blame] | 4178 | if (req_vout_ctl < 0) { |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 4179 | ret = -EINVAL; |
| 4180 | goto exit; |
| 4181 | } |
| 4182 | if (cur_vout_ctl == req_vout_ctl) { |
| 4183 | ret = 0; |
| 4184 | goto exit; |
| 4185 | } |
| 4186 | |
| 4187 | dev_dbg(codec->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n", |
| 4188 | __func__, micb_num, WCD_VOUT_CTL_TO_MICB(cur_vout_ctl), |
| 4189 | req_volt, micb_en); |
| 4190 | |
| 4191 | if (micb_en == 0x1) |
| 4192 | snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80); |
| 4193 | |
| 4194 | snd_soc_update_bits(codec, micb_reg, 0x3F, req_vout_ctl); |
| 4195 | |
| 4196 | if (micb_en == 0x1) { |
| 4197 | snd_soc_update_bits(codec, micb_reg, 0xC0, 0x40); |
| 4198 | /* |
| 4199 | * Add 2ms delay as per HW requirement after enabling |
| 4200 | * micbias |
| 4201 | */ |
| 4202 | usleep_range(2000, 2100); |
| 4203 | } |
| 4204 | exit: |
| 4205 | mutex_unlock(&tavil->micb_lock); |
| 4206 | return ret; |
| 4207 | } |
| 4208 | EXPORT_SYMBOL(tavil_mbhc_micb_adjust_voltage); |
| 4209 | |
| 4210 | /* |
| 4211 | * tavil_micbias_control: enable/disable micbias |
| 4212 | * @codec: handle to snd_soc_codec * |
| 4213 | * @micb_num: micbias to be enabled/disabled, e.g. micbias1 or micbias2 |
| 4214 | * @req: control requested, enable/disable or pullup enable/disable |
| 4215 | * @is_dapm: triggered by dapm or not |
| 4216 | * |
| 4217 | * return 0 if control is success or error code in case of failure |
| 4218 | */ |
| 4219 | int tavil_micbias_control(struct snd_soc_codec *codec, |
| 4220 | int micb_num, int req, bool is_dapm) |
| 4221 | { |
| 4222 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 4223 | int micb_index = micb_num - 1; |
| 4224 | u16 micb_reg; |
| 4225 | int pre_off_event = 0, post_off_event = 0; |
| 4226 | int post_on_event = 0, post_dapm_off = 0; |
| 4227 | int post_dapm_on = 0; |
| 4228 | |
| 4229 | if ((micb_index < 0) || (micb_index > TAVIL_MAX_MICBIAS - 1)) { |
| 4230 | dev_err(codec->dev, "%s: Invalid micbias index, micb_ind:%d\n", |
| 4231 | __func__, micb_index); |
| 4232 | return -EINVAL; |
| 4233 | } |
| 4234 | |
| 4235 | switch (micb_num) { |
| 4236 | case MIC_BIAS_1: |
| 4237 | micb_reg = WCD934X_ANA_MICB1; |
| 4238 | break; |
| 4239 | case MIC_BIAS_2: |
| 4240 | micb_reg = WCD934X_ANA_MICB2; |
| 4241 | pre_off_event = WCD_EVENT_PRE_MICBIAS_2_OFF; |
| 4242 | post_off_event = WCD_EVENT_POST_MICBIAS_2_OFF; |
| 4243 | post_on_event = WCD_EVENT_POST_MICBIAS_2_ON; |
| 4244 | post_dapm_on = WCD_EVENT_POST_DAPM_MICBIAS_2_ON; |
| 4245 | post_dapm_off = WCD_EVENT_POST_DAPM_MICBIAS_2_OFF; |
| 4246 | break; |
| 4247 | case MIC_BIAS_3: |
| 4248 | micb_reg = WCD934X_ANA_MICB3; |
| 4249 | break; |
| 4250 | case MIC_BIAS_4: |
| 4251 | micb_reg = WCD934X_ANA_MICB4; |
| 4252 | break; |
| 4253 | default: |
| 4254 | dev_err(codec->dev, "%s: Invalid micbias number: %d\n", |
| 4255 | __func__, micb_num); |
| 4256 | return -EINVAL; |
| 4257 | } |
| 4258 | mutex_lock(&tavil->micb_lock); |
| 4259 | |
| 4260 | switch (req) { |
| 4261 | case MICB_PULLUP_ENABLE: |
| 4262 | tavil->pullup_ref[micb_index]++; |
| 4263 | if ((tavil->pullup_ref[micb_index] == 1) && |
| 4264 | (tavil->micb_ref[micb_index] == 0)) |
| 4265 | snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80); |
| 4266 | break; |
| 4267 | case MICB_PULLUP_DISABLE: |
| 4268 | if (tavil->pullup_ref[micb_index] > 0) |
| 4269 | tavil->pullup_ref[micb_index]--; |
| 4270 | if ((tavil->pullup_ref[micb_index] == 0) && |
| 4271 | (tavil->micb_ref[micb_index] == 0)) |
| 4272 | snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00); |
| 4273 | break; |
| 4274 | case MICB_ENABLE: |
| 4275 | tavil->micb_ref[micb_index]++; |
| 4276 | if (tavil->micb_ref[micb_index] == 1) { |
| 4277 | snd_soc_update_bits(codec, micb_reg, 0xC0, 0x40); |
| 4278 | if (post_on_event && tavil->mbhc) |
| 4279 | blocking_notifier_call_chain( |
| 4280 | &tavil->mbhc->notifier, |
| 4281 | post_on_event, |
| 4282 | &tavil->mbhc->wcd_mbhc); |
| 4283 | } |
| 4284 | if (is_dapm && post_dapm_on && tavil->mbhc) |
| 4285 | blocking_notifier_call_chain(&tavil->mbhc->notifier, |
| 4286 | post_dapm_on, &tavil->mbhc->wcd_mbhc); |
| 4287 | break; |
| 4288 | case MICB_DISABLE: |
| 4289 | if (tavil->micb_ref[micb_index] > 0) |
| 4290 | tavil->micb_ref[micb_index]--; |
| 4291 | if ((tavil->micb_ref[micb_index] == 0) && |
| 4292 | (tavil->pullup_ref[micb_index] > 0)) |
| 4293 | snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80); |
| 4294 | else if ((tavil->micb_ref[micb_index] == 0) && |
| 4295 | (tavil->pullup_ref[micb_index] == 0)) { |
| 4296 | if (pre_off_event && tavil->mbhc) |
| 4297 | blocking_notifier_call_chain( |
| 4298 | &tavil->mbhc->notifier, |
| 4299 | pre_off_event, |
| 4300 | &tavil->mbhc->wcd_mbhc); |
| 4301 | snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00); |
| 4302 | if (post_off_event && tavil->mbhc) |
| 4303 | blocking_notifier_call_chain( |
| 4304 | &tavil->mbhc->notifier, |
| 4305 | post_off_event, |
| 4306 | &tavil->mbhc->wcd_mbhc); |
| 4307 | } |
| 4308 | if (is_dapm && post_dapm_off && tavil->mbhc) |
| 4309 | blocking_notifier_call_chain(&tavil->mbhc->notifier, |
| 4310 | post_dapm_off, &tavil->mbhc->wcd_mbhc); |
| 4311 | break; |
| 4312 | }; |
| 4313 | |
| 4314 | dev_dbg(codec->dev, "%s: micb_num:%d, micb_ref: %d, pullup_ref: %d\n", |
| 4315 | __func__, micb_num, tavil->micb_ref[micb_index], |
| 4316 | tavil->pullup_ref[micb_index]); |
| 4317 | |
| 4318 | mutex_unlock(&tavil->micb_lock); |
| 4319 | |
| 4320 | return 0; |
| 4321 | } |
| 4322 | EXPORT_SYMBOL(tavil_micbias_control); |
| 4323 | |
| 4324 | static int __tavil_codec_enable_micbias(struct snd_soc_dapm_widget *w, |
| 4325 | int event) |
| 4326 | { |
| 4327 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 4328 | int micb_num; |
| 4329 | |
| 4330 | dev_dbg(codec->dev, "%s: wname: %s, event: %d\n", |
| 4331 | __func__, w->name, event); |
| 4332 | |
| 4333 | if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1"))) |
| 4334 | micb_num = MIC_BIAS_1; |
| 4335 | else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2"))) |
| 4336 | micb_num = MIC_BIAS_2; |
| 4337 | else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3"))) |
| 4338 | micb_num = MIC_BIAS_3; |
| 4339 | else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4"))) |
| 4340 | micb_num = MIC_BIAS_4; |
| 4341 | else |
| 4342 | return -EINVAL; |
| 4343 | |
| 4344 | switch (event) { |
| 4345 | case SND_SOC_DAPM_PRE_PMU: |
| 4346 | /* |
| 4347 | * MIC BIAS can also be requested by MBHC, |
| 4348 | * so use ref count to handle micbias pullup |
| 4349 | * and enable requests |
| 4350 | */ |
| 4351 | tavil_micbias_control(codec, micb_num, MICB_ENABLE, true); |
| 4352 | break; |
| 4353 | case SND_SOC_DAPM_POST_PMU: |
| 4354 | /* wait for cnp time */ |
| 4355 | usleep_range(1000, 1100); |
| 4356 | break; |
| 4357 | case SND_SOC_DAPM_POST_PMD: |
| 4358 | tavil_micbias_control(codec, micb_num, MICB_DISABLE, true); |
| 4359 | break; |
| 4360 | }; |
| 4361 | |
| 4362 | return 0; |
| 4363 | } |
| 4364 | |
| 4365 | /* |
| 4366 | * tavil_codec_enable_standalone_micbias - enable micbias standalone |
| 4367 | * @codec: pointer to codec instance |
| 4368 | * @micb_num: number of micbias to be enabled |
| 4369 | * @enable: true to enable micbias or false to disable |
| 4370 | * |
| 4371 | * This function is used to enable micbias (1, 2, 3 or 4) during |
| 4372 | * standalone independent of whether TX use-case is running or not |
| 4373 | * |
| 4374 | * Return: error code in case of failure or 0 for success |
| 4375 | */ |
| 4376 | int tavil_codec_enable_standalone_micbias(struct snd_soc_codec *codec, |
| 4377 | int micb_num, |
| 4378 | bool enable) |
| 4379 | { |
| 4380 | const char * const micb_names[] = { |
| 4381 | DAPM_MICBIAS1_STANDALONE, DAPM_MICBIAS2_STANDALONE, |
| 4382 | DAPM_MICBIAS3_STANDALONE, DAPM_MICBIAS4_STANDALONE |
| 4383 | }; |
| 4384 | int micb_index = micb_num - 1; |
| 4385 | int rc; |
| 4386 | |
| 4387 | if (!codec) { |
| 4388 | pr_err("%s: Codec memory is NULL\n", __func__); |
| 4389 | return -EINVAL; |
| 4390 | } |
| 4391 | |
| 4392 | if ((micb_index < 0) || (micb_index > TAVIL_MAX_MICBIAS - 1)) { |
| 4393 | dev_err(codec->dev, "%s: Invalid micbias index, micb_ind:%d\n", |
| 4394 | __func__, micb_index); |
| 4395 | return -EINVAL; |
| 4396 | } |
| 4397 | |
| 4398 | if (enable) |
| 4399 | rc = snd_soc_dapm_force_enable_pin( |
| 4400 | snd_soc_codec_get_dapm(codec), |
| 4401 | micb_names[micb_index]); |
| 4402 | else |
| 4403 | rc = snd_soc_dapm_disable_pin(snd_soc_codec_get_dapm(codec), |
| 4404 | micb_names[micb_index]); |
| 4405 | |
| 4406 | if (!rc) |
| 4407 | snd_soc_dapm_sync(snd_soc_codec_get_dapm(codec)); |
| 4408 | else |
| 4409 | dev_err(codec->dev, "%s: micbias%d force %s pin failed\n", |
| 4410 | __func__, micb_num, (enable ? "enable" : "disable")); |
| 4411 | |
| 4412 | return rc; |
| 4413 | } |
| 4414 | EXPORT_SYMBOL(tavil_codec_enable_standalone_micbias); |
| 4415 | |
| 4416 | static int tavil_codec_force_enable_micbias(struct snd_soc_dapm_widget *w, |
| 4417 | struct snd_kcontrol *kcontrol, |
| 4418 | int event) |
| 4419 | { |
| 4420 | int ret = 0; |
| 4421 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 4422 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 4423 | |
| 4424 | switch (event) { |
| 4425 | case SND_SOC_DAPM_PRE_PMU: |
| 4426 | wcd_resmgr_enable_master_bias(tavil->resmgr); |
| 4427 | tavil_cdc_mclk_enable(codec, true); |
| 4428 | ret = __tavil_codec_enable_micbias(w, SND_SOC_DAPM_PRE_PMU); |
| 4429 | /* Wait for 1ms for better cnp */ |
| 4430 | usleep_range(1000, 1100); |
| 4431 | tavil_cdc_mclk_enable(codec, false); |
| 4432 | break; |
| 4433 | case SND_SOC_DAPM_POST_PMD: |
| 4434 | ret = __tavil_codec_enable_micbias(w, SND_SOC_DAPM_POST_PMD); |
| 4435 | wcd_resmgr_disable_master_bias(tavil->resmgr); |
| 4436 | break; |
| 4437 | } |
| 4438 | |
| 4439 | return ret; |
| 4440 | } |
| 4441 | |
| 4442 | static int tavil_codec_enable_micbias(struct snd_soc_dapm_widget *w, |
| 4443 | struct snd_kcontrol *kcontrol, int event) |
| 4444 | { |
| 4445 | return __tavil_codec_enable_micbias(w, event); |
| 4446 | } |
| 4447 | |
| 4448 | |
| 4449 | static const struct reg_sequence tavil_hph_reset_tbl[] = { |
| 4450 | { WCD934X_HPH_CNP_EN, 0x80 }, |
| 4451 | { WCD934X_HPH_CNP_WG_CTL, 0x9A }, |
| 4452 | { WCD934X_HPH_CNP_WG_TIME, 0x14 }, |
| 4453 | { WCD934X_HPH_OCP_CTL, 0x28 }, |
| 4454 | { WCD934X_HPH_AUTO_CHOP, 0x16 }, |
| 4455 | { WCD934X_HPH_CHOP_CTL, 0x83 }, |
| 4456 | { WCD934X_HPH_PA_CTL1, 0x46 }, |
| 4457 | { WCD934X_HPH_PA_CTL2, 0x50 }, |
| 4458 | { WCD934X_HPH_L_EN, 0x80 }, |
| 4459 | { WCD934X_HPH_L_TEST, 0xE0 }, |
| 4460 | { WCD934X_HPH_L_ATEST, 0x50 }, |
| 4461 | { WCD934X_HPH_R_EN, 0x80 }, |
| 4462 | { WCD934X_HPH_R_TEST, 0xE0 }, |
| 4463 | { WCD934X_HPH_R_ATEST, 0x54 }, |
| 4464 | { WCD934X_HPH_RDAC_CLK_CTL1, 0x99 }, |
| 4465 | { WCD934X_HPH_RDAC_CLK_CTL2, 0x9B }, |
| 4466 | { WCD934X_HPH_RDAC_LDO_CTL, 0x33 }, |
| 4467 | { WCD934X_HPH_RDAC_CHOP_CLK_LP_CTL, 0x00 }, |
| 4468 | { WCD934X_HPH_REFBUFF_UHQA_CTL, 0xA8 }, |
| 4469 | }; |
| 4470 | |
| 4471 | static const struct reg_sequence tavil_hph_reset_tbl_1_0[] = { |
| 4472 | { WCD934X_HPH_REFBUFF_LP_CTL, 0x0A }, |
| 4473 | { WCD934X_HPH_L_DAC_CTL, 0x00 }, |
| 4474 | { WCD934X_HPH_R_DAC_CTL, 0x00 }, |
| 4475 | { WCD934X_HPH_NEW_ANA_HPH2, 0x00 }, |
| 4476 | { WCD934X_HPH_NEW_ANA_HPH3, 0x00 }, |
| 4477 | { WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, 0x00 }, |
| 4478 | { WCD934X_HPH_NEW_INT_RDAC_HD2_CTL, 0xA0 }, |
| 4479 | { WCD934X_HPH_NEW_INT_RDAC_VREF_CTL, 0x10 }, |
| 4480 | { WCD934X_HPH_NEW_INT_RDAC_OVERRIDE_CTL, 0x00 }, |
| 4481 | { WCD934X_HPH_NEW_INT_RDAC_MISC1, 0x00 }, |
| 4482 | { WCD934X_HPH_NEW_INT_PA_MISC1, 0x22 }, |
| 4483 | { WCD934X_HPH_NEW_INT_PA_MISC2, 0x00 }, |
| 4484 | { WCD934X_HPH_NEW_INT_PA_RDAC_MISC, 0x00 }, |
| 4485 | { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0xFE }, |
| 4486 | { WCD934X_HPH_NEW_INT_HPH_TIMER2, 0x2 }, |
| 4487 | { WCD934X_HPH_NEW_INT_HPH_TIMER3, 0x4e}, |
| 4488 | { WCD934X_HPH_NEW_INT_HPH_TIMER4, 0x54 }, |
| 4489 | { WCD934X_HPH_NEW_INT_PA_RDAC_MISC2, 0x00 }, |
| 4490 | { WCD934X_HPH_NEW_INT_PA_RDAC_MISC3, 0x00 }, |
| 4491 | }; |
| 4492 | |
| 4493 | static const struct reg_sequence tavil_hph_reset_tbl_1_1[] = { |
| 4494 | { WCD934X_HPH_REFBUFF_LP_CTL, 0x0E }, |
| 4495 | { WCD934X_HPH_L_DAC_CTL, 0x00 }, |
| 4496 | { WCD934X_HPH_R_DAC_CTL, 0x00 }, |
| 4497 | { WCD934X_HPH_NEW_ANA_HPH2, 0x00 }, |
| 4498 | { WCD934X_HPH_NEW_ANA_HPH3, 0x00 }, |
| 4499 | { WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, 0x40 }, |
| 4500 | { WCD934X_HPH_NEW_INT_RDAC_HD2_CTL, 0x81 }, |
| 4501 | { WCD934X_HPH_NEW_INT_RDAC_VREF_CTL, 0x10 }, |
| 4502 | { WCD934X_HPH_NEW_INT_RDAC_OVERRIDE_CTL, 0x00 }, |
| 4503 | { WCD934X_HPH_NEW_INT_RDAC_MISC1, 0x81 }, |
| 4504 | { WCD934X_HPH_NEW_INT_PA_MISC1, 0x22 }, |
| 4505 | { WCD934X_HPH_NEW_INT_PA_MISC2, 0x00 }, |
| 4506 | { WCD934X_HPH_NEW_INT_PA_RDAC_MISC, 0x00 }, |
| 4507 | { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0xFE }, |
| 4508 | { WCD934X_HPH_NEW_INT_HPH_TIMER2, 0x2 }, |
| 4509 | { WCD934X_HPH_NEW_INT_HPH_TIMER3, 0x4e}, |
| 4510 | { WCD934X_HPH_NEW_INT_HPH_TIMER4, 0x54 }, |
| 4511 | { WCD934X_HPH_NEW_INT_PA_RDAC_MISC2, 0x00 }, |
| 4512 | { WCD934X_HPH_NEW_INT_PA_RDAC_MISC3, 0x00 }, |
| 4513 | }; |
| 4514 | |
| 4515 | static const struct tavil_reg_mask_val tavil_pa_disable[] = { |
| 4516 | { WCD934X_CDC_RX1_RX_PATH_CTL, 0x30, 0x10 }, /* RX1 mute enable */ |
| 4517 | { WCD934X_CDC_RX2_RX_PATH_CTL, 0x30, 0x10 }, /* RX2 mute enable */ |
| 4518 | { WCD934X_HPH_CNP_WG_CTL, 0x80, 0x00 }, /* GM3 boost disable */ |
| 4519 | { WCD934X_ANA_HPH, 0x80, 0x00 }, /* HPHL PA disable */ |
| 4520 | { WCD934X_ANA_HPH, 0x40, 0x00 }, /* HPHR PA disable */ |
| 4521 | { WCD934X_ANA_HPH, 0x20, 0x00 }, /* HPHL REF dsable */ |
| 4522 | { WCD934X_ANA_HPH, 0x10, 0x00 }, /* HPHR REF disable */ |
| 4523 | }; |
| 4524 | |
| 4525 | static const struct tavil_reg_mask_val tavil_ocp_en_seq[] = { |
| 4526 | { WCD934X_RX_OCP_CTL, 0x0F, 0x02 }, /* OCP number of attempts is 2 */ |
| 4527 | { WCD934X_HPH_OCP_CTL, 0xFA, 0x3A }, /* OCP current limit */ |
| 4528 | { WCD934X_HPH_L_TEST, 0x01, 0x01 }, /* Enable HPHL OCP */ |
| 4529 | { WCD934X_HPH_R_TEST, 0x01, 0x01 }, /* Enable HPHR OCP */ |
| 4530 | }; |
| 4531 | |
| 4532 | static const struct tavil_reg_mask_val tavil_ocp_en_seq_1[] = { |
| 4533 | { WCD934X_RX_OCP_CTL, 0x0F, 0x02 }, /* OCP number of attempts is 2 */ |
| 4534 | { WCD934X_HPH_OCP_CTL, 0xFA, 0x3A }, /* OCP current limit */ |
| 4535 | }; |
| 4536 | |
| 4537 | /* LO-HIFI */ |
| 4538 | static const struct tavil_reg_mask_val tavil_pre_pa_en_lohifi[] = { |
| 4539 | { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00 }, |
| 4540 | { WCD934X_FLYBACK_VNEG_CTRL_4, 0xf0, 0x80 }, |
| 4541 | { WCD934X_HPH_NEW_INT_PA_MISC2, 0x20, 0x20 }, |
| 4542 | { WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, 0xf0, 0x40 }, |
| 4543 | { WCD934X_HPH_CNP_WG_CTL, 0x80, 0x00 }, |
| 4544 | { WCD934X_RX_BIAS_HPH_LOWPOWER, 0xf0, 0xc0 }, |
| 4545 | { WCD934X_HPH_PA_CTL1, 0x0e, 0x02 }, |
| 4546 | { WCD934X_HPH_REFBUFF_LP_CTL, 0x06, 0x06 }, |
| 4547 | }; |
| 4548 | |
| 4549 | static const struct tavil_reg_mask_val tavil_pre_pa_en[] = { |
| 4550 | { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00 }, |
| 4551 | { WCD934X_HPH_NEW_INT_PA_MISC2, 0x20, 0x0 }, |
| 4552 | { WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, 0xf0, 0x40 }, |
| 4553 | { WCD934X_HPH_CNP_WG_CTL, 0x80, 0x00 }, |
| 4554 | { WCD934X_RX_BIAS_HPH_LOWPOWER, 0xf0, 0x80 }, |
| 4555 | { WCD934X_HPH_PA_CTL1, 0x0e, 0x06 }, |
| 4556 | { WCD934X_HPH_REFBUFF_LP_CTL, 0x06, 0x06 }, |
| 4557 | }; |
| 4558 | |
| 4559 | static const struct tavil_reg_mask_val tavil_post_pa_en[] = { |
| 4560 | { WCD934X_HPH_L_TEST, 0x01, 0x01 }, /* Enable HPHL OCP */ |
| 4561 | { WCD934X_HPH_R_TEST, 0x01, 0x01 }, /* Enable HPHR OCP */ |
| 4562 | { WCD934X_CDC_RX1_RX_PATH_CTL, 0x30, 0x20 }, /* RX1 mute disable */ |
| 4563 | { WCD934X_CDC_RX2_RX_PATH_CTL, 0x30, 0x20 }, /* RX2 mute disable */ |
| 4564 | { WCD934X_HPH_CNP_WG_CTL, 0x80, 0x80 }, /* GM3 boost enable */ |
| 4565 | { WCD934X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x02 }, |
| 4566 | }; |
| 4567 | |
| 4568 | static void tavil_codec_hph_reg_range_read(struct regmap *map, u8 *buf) |
| 4569 | { |
| 4570 | regmap_bulk_read(map, WCD934X_HPH_CNP_EN, buf, TAVIL_HPH_REG_RANGE_1); |
| 4571 | regmap_bulk_read(map, WCD934X_HPH_NEW_ANA_HPH2, |
| 4572 | buf + TAVIL_HPH_REG_RANGE_1, TAVIL_HPH_REG_RANGE_2); |
| 4573 | regmap_bulk_read(map, WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL, |
| 4574 | buf + TAVIL_HPH_REG_RANGE_1 + TAVIL_HPH_REG_RANGE_2, |
| 4575 | TAVIL_HPH_REG_RANGE_3); |
| 4576 | } |
| 4577 | |
| 4578 | static void tavil_codec_hph_reg_recover(struct tavil_priv *tavil, |
| 4579 | struct regmap *map, int pa_status) |
| 4580 | { |
| 4581 | int i; |
| 4582 | unsigned int reg; |
| 4583 | |
| 4584 | blocking_notifier_call_chain(&tavil->mbhc->notifier, |
| 4585 | WCD_EVENT_OCP_OFF, |
| 4586 | &tavil->mbhc->wcd_mbhc); |
| 4587 | |
| 4588 | if (pa_status & 0xC0) |
| 4589 | goto pa_en_restore; |
| 4590 | |
| 4591 | dev_dbg(tavil->dev, "%s: HPH PA in disable state (0x%x)\n", |
| 4592 | __func__, pa_status); |
| 4593 | |
| 4594 | regmap_write_bits(map, WCD934X_CDC_RX1_RX_PATH_CTL, 0x10, 0x10); |
| 4595 | regmap_write_bits(map, WCD934X_CDC_RX2_RX_PATH_CTL, 0x10, 0x10); |
| 4596 | regmap_write_bits(map, WCD934X_ANA_HPH, 0xC0, 0x00); |
| 4597 | regmap_write_bits(map, WCD934X_ANA_HPH, 0x30, 0x00); |
| 4598 | regmap_write_bits(map, WCD934X_CDC_RX1_RX_PATH_CTL, 0x10, 0x00); |
| 4599 | regmap_write_bits(map, WCD934X_CDC_RX2_RX_PATH_CTL, 0x10, 0x00); |
| 4600 | |
| 4601 | /* Restore to HW defaults */ |
| 4602 | regmap_multi_reg_write(map, tavil_hph_reset_tbl, |
| 4603 | ARRAY_SIZE(tavil_hph_reset_tbl)); |
| 4604 | if (TAVIL_IS_1_1(tavil->wcd9xxx)) |
| 4605 | regmap_multi_reg_write(map, tavil_hph_reset_tbl_1_1, |
| 4606 | ARRAY_SIZE(tavil_hph_reset_tbl_1_1)); |
| 4607 | if (TAVIL_IS_1_0(tavil->wcd9xxx)) |
| 4608 | regmap_multi_reg_write(map, tavil_hph_reset_tbl_1_0, |
| 4609 | ARRAY_SIZE(tavil_hph_reset_tbl_1_0)); |
| 4610 | |
| 4611 | for (i = 0; i < ARRAY_SIZE(tavil_ocp_en_seq); i++) |
| 4612 | regmap_write_bits(map, tavil_ocp_en_seq[i].reg, |
| 4613 | tavil_ocp_en_seq[i].mask, |
| 4614 | tavil_ocp_en_seq[i].val); |
| 4615 | goto end; |
| 4616 | |
| 4617 | |
| 4618 | pa_en_restore: |
| 4619 | dev_dbg(tavil->dev, "%s: HPH PA in enable state (0x%x)\n", |
| 4620 | __func__, pa_status); |
| 4621 | |
| 4622 | /* Disable PA and other registers before restoring */ |
| 4623 | for (i = 0; i < ARRAY_SIZE(tavil_pa_disable); i++) { |
| 4624 | if (TAVIL_IS_1_1(tavil->wcd9xxx) && |
| 4625 | (tavil_pa_disable[i].reg == WCD934X_HPH_CNP_WG_CTL)) |
| 4626 | continue; |
| 4627 | regmap_write_bits(map, tavil_pa_disable[i].reg, |
| 4628 | tavil_pa_disable[i].mask, |
| 4629 | tavil_pa_disable[i].val); |
| 4630 | } |
| 4631 | |
| 4632 | regmap_multi_reg_write(map, tavil_hph_reset_tbl, |
| 4633 | ARRAY_SIZE(tavil_hph_reset_tbl)); |
| 4634 | if (TAVIL_IS_1_1(tavil->wcd9xxx)) |
| 4635 | regmap_multi_reg_write(map, tavil_hph_reset_tbl_1_1, |
| 4636 | ARRAY_SIZE(tavil_hph_reset_tbl_1_1)); |
| 4637 | if (TAVIL_IS_1_0(tavil->wcd9xxx)) |
| 4638 | regmap_multi_reg_write(map, tavil_hph_reset_tbl_1_0, |
| 4639 | ARRAY_SIZE(tavil_hph_reset_tbl_1_0)); |
| 4640 | |
| 4641 | for (i = 0; i < ARRAY_SIZE(tavil_ocp_en_seq_1); i++) |
| 4642 | regmap_write_bits(map, tavil_ocp_en_seq_1[i].reg, |
| 4643 | tavil_ocp_en_seq_1[i].mask, |
| 4644 | tavil_ocp_en_seq_1[i].val); |
| 4645 | |
| 4646 | if (tavil->hph_mode == CLS_H_LOHIFI) { |
| 4647 | for (i = 0; i < ARRAY_SIZE(tavil_pre_pa_en_lohifi); i++) { |
| 4648 | reg = tavil_pre_pa_en_lohifi[i].reg; |
| 4649 | if ((TAVIL_IS_1_1(tavil->wcd9xxx)) && |
| 4650 | ((reg == WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL) || |
| 4651 | (reg == WCD934X_HPH_CNP_WG_CTL) || |
| 4652 | (reg == WCD934X_HPH_REFBUFF_LP_CTL))) |
| 4653 | continue; |
| 4654 | regmap_write_bits(map, |
| 4655 | tavil_pre_pa_en_lohifi[i].reg, |
| 4656 | tavil_pre_pa_en_lohifi[i].mask, |
| 4657 | tavil_pre_pa_en_lohifi[i].val); |
| 4658 | } |
| 4659 | } else { |
| 4660 | for (i = 0; i < ARRAY_SIZE(tavil_pre_pa_en); i++) { |
| 4661 | reg = tavil_pre_pa_en[i].reg; |
| 4662 | if ((TAVIL_IS_1_1(tavil->wcd9xxx)) && |
| 4663 | ((reg == WCD934X_HPH_NEW_INT_RDAC_GAIN_CTL) || |
| 4664 | (reg == WCD934X_HPH_CNP_WG_CTL) || |
| 4665 | (reg == WCD934X_HPH_REFBUFF_LP_CTL))) |
| 4666 | continue; |
| 4667 | regmap_write_bits(map, tavil_pre_pa_en[i].reg, |
| 4668 | tavil_pre_pa_en[i].mask, |
| 4669 | tavil_pre_pa_en[i].val); |
| 4670 | } |
| 4671 | } |
| 4672 | |
| 4673 | if (TAVIL_IS_1_1(tavil->wcd9xxx)) { |
| 4674 | regmap_write(map, WCD934X_HPH_NEW_INT_RDAC_HD2_CTL_L, 0x84); |
| 4675 | regmap_write(map, WCD934X_HPH_NEW_INT_RDAC_HD2_CTL_R, 0x84); |
| 4676 | } |
| 4677 | |
| 4678 | regmap_write_bits(map, WCD934X_ANA_HPH, 0x0C, pa_status & 0x0C); |
| 4679 | regmap_write_bits(map, WCD934X_ANA_HPH, 0x30, 0x30); |
| 4680 | /* wait for 100usec after HPH DAC is enabled */ |
| 4681 | usleep_range(100, 110); |
| 4682 | regmap_write(map, WCD934X_ANA_HPH, pa_status); |
| 4683 | /* Sleep for 7msec after PA is enabled */ |
| 4684 | usleep_range(7000, 7100); |
| 4685 | |
| 4686 | for (i = 0; i < ARRAY_SIZE(tavil_post_pa_en); i++) { |
| 4687 | if ((TAVIL_IS_1_1(tavil->wcd9xxx)) && |
| 4688 | (tavil_post_pa_en[i].reg == WCD934X_HPH_CNP_WG_CTL)) |
| 4689 | continue; |
| 4690 | regmap_write_bits(map, tavil_post_pa_en[i].reg, |
| 4691 | tavil_post_pa_en[i].mask, |
| 4692 | tavil_post_pa_en[i].val); |
| 4693 | } |
| 4694 | |
| 4695 | end: |
| 4696 | tavil->mbhc->is_hph_recover = true; |
| 4697 | blocking_notifier_call_chain( |
| 4698 | &tavil->mbhc->notifier, |
| 4699 | WCD_EVENT_OCP_ON, |
| 4700 | &tavil->mbhc->wcd_mbhc); |
| 4701 | } |
| 4702 | |
| 4703 | static int tavil_codec_reset_hph_registers(struct snd_soc_dapm_widget *w, |
| 4704 | struct snd_kcontrol *kcontrol, |
| 4705 | int event) |
| 4706 | { |
| 4707 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
| 4708 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 4709 | struct wcd9xxx *wcd9xxx = dev_get_drvdata(codec->dev->parent); |
| 4710 | u8 cache_val[TAVIL_HPH_TOTAL_REG]; |
| 4711 | u8 hw_val[TAVIL_HPH_TOTAL_REG]; |
| 4712 | int pa_status; |
| 4713 | int ret; |
| 4714 | |
| 4715 | dev_dbg(wcd9xxx->dev, "%s: event: %d\n", __func__, event); |
| 4716 | |
| 4717 | switch (event) { |
| 4718 | case SND_SOC_DAPM_PRE_PMU: |
| 4719 | memset(cache_val, 0, TAVIL_HPH_TOTAL_REG); |
| 4720 | memset(hw_val, 0, TAVIL_HPH_TOTAL_REG); |
| 4721 | |
| 4722 | regmap_read(wcd9xxx->regmap, WCD934X_ANA_HPH, &pa_status); |
| 4723 | |
| 4724 | tavil_codec_hph_reg_range_read(wcd9xxx->regmap, cache_val); |
| 4725 | |
| 4726 | /* Read register values from HW directly */ |
| 4727 | regcache_cache_bypass(wcd9xxx->regmap, true); |
| 4728 | tavil_codec_hph_reg_range_read(wcd9xxx->regmap, hw_val); |
| 4729 | regcache_cache_bypass(wcd9xxx->regmap, false); |
| 4730 | |
| 4731 | /* compare both the registers to know if there is corruption */ |
| 4732 | ret = memcmp(cache_val, hw_val, TAVIL_HPH_TOTAL_REG); |
| 4733 | |
| 4734 | /* If both the values are same, it means no corruption */ |
| 4735 | if (ret) { |
| 4736 | dev_dbg(codec->dev, "%s: cache and hw reg are not same\n", |
| 4737 | __func__); |
| 4738 | tavil_codec_hph_reg_recover(tavil, wcd9xxx->regmap, |
| 4739 | pa_status); |
| 4740 | } else { |
| 4741 | dev_dbg(codec->dev, "%s: cache and hw reg are same\n", |
| 4742 | __func__); |
| 4743 | tavil->mbhc->is_hph_recover = false; |
| 4744 | } |
| 4745 | break; |
| 4746 | default: |
| 4747 | break; |
| 4748 | }; |
| 4749 | |
| 4750 | return 0; |
| 4751 | } |
| 4752 | |
| 4753 | static int tavil_iir_enable_audio_mixer_get(struct snd_kcontrol *kcontrol, |
| 4754 | struct snd_ctl_elem_value *ucontrol) |
| 4755 | { |
| 4756 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 4757 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 4758 | kcontrol->private_value)->reg; |
| 4759 | int band_idx = ((struct soc_multi_mixer_control *) |
| 4760 | kcontrol->private_value)->shift; |
| 4761 | /* IIR filter band registers are at integer multiples of 16 */ |
| 4762 | u16 iir_reg = WCD934X_CDC_SIDETONE_IIR0_IIR_CTL + 16 * iir_idx; |
| 4763 | |
| 4764 | ucontrol->value.integer.value[0] = (snd_soc_read(codec, iir_reg) & |
| 4765 | (1 << band_idx)) != 0; |
| 4766 | |
| 4767 | dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__, |
| 4768 | iir_idx, band_idx, |
| 4769 | (uint32_t)ucontrol->value.integer.value[0]); |
| 4770 | return 0; |
| 4771 | } |
| 4772 | |
| 4773 | static int tavil_iir_enable_audio_mixer_put(struct snd_kcontrol *kcontrol, |
| 4774 | struct snd_ctl_elem_value *ucontrol) |
| 4775 | { |
| 4776 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 4777 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 4778 | kcontrol->private_value)->reg; |
| 4779 | int band_idx = ((struct soc_multi_mixer_control *) |
| 4780 | kcontrol->private_value)->shift; |
| 4781 | bool iir_band_en_status; |
| 4782 | int value = ucontrol->value.integer.value[0]; |
| 4783 | u16 iir_reg = WCD934X_CDC_SIDETONE_IIR0_IIR_CTL + 16 * iir_idx; |
| 4784 | |
| 4785 | /* Mask first 5 bits, 6-8 are reserved */ |
| 4786 | snd_soc_update_bits(codec, iir_reg, (1 << band_idx), |
| 4787 | (value << band_idx)); |
| 4788 | |
| 4789 | iir_band_en_status = ((snd_soc_read(codec, iir_reg) & |
| 4790 | (1 << band_idx)) != 0); |
| 4791 | dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__, |
| 4792 | iir_idx, band_idx, iir_band_en_status); |
| 4793 | return 0; |
| 4794 | } |
| 4795 | |
| 4796 | static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec, |
| 4797 | int iir_idx, int band_idx, |
| 4798 | int coeff_idx) |
| 4799 | { |
| 4800 | uint32_t value = 0; |
| 4801 | |
| 4802 | /* Address does not automatically update if reading */ |
| 4803 | snd_soc_write(codec, |
| 4804 | (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx), |
| 4805 | ((band_idx * BAND_MAX + coeff_idx) |
| 4806 | * sizeof(uint32_t)) & 0x7F); |
| 4807 | |
| 4808 | value |= snd_soc_read(codec, |
| 4809 | (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx)); |
| 4810 | |
| 4811 | snd_soc_write(codec, |
| 4812 | (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx), |
| 4813 | ((band_idx * BAND_MAX + coeff_idx) |
| 4814 | * sizeof(uint32_t) + 1) & 0x7F); |
| 4815 | |
| 4816 | value |= (snd_soc_read(codec, |
| 4817 | (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + |
| 4818 | 16 * iir_idx)) << 8); |
| 4819 | |
| 4820 | snd_soc_write(codec, |
| 4821 | (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx), |
| 4822 | ((band_idx * BAND_MAX + coeff_idx) |
| 4823 | * sizeof(uint32_t) + 2) & 0x7F); |
| 4824 | |
| 4825 | value |= (snd_soc_read(codec, |
| 4826 | (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + |
| 4827 | 16 * iir_idx)) << 16); |
| 4828 | |
| 4829 | snd_soc_write(codec, |
| 4830 | (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx), |
| 4831 | ((band_idx * BAND_MAX + coeff_idx) |
| 4832 | * sizeof(uint32_t) + 3) & 0x7F); |
| 4833 | |
| 4834 | /* Mask bits top 2 bits since they are reserved */ |
| 4835 | value |= ((snd_soc_read(codec, |
| 4836 | (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + |
| 4837 | 16 * iir_idx)) & 0x3F) << 24); |
| 4838 | |
| 4839 | return value; |
| 4840 | } |
| 4841 | |
| 4842 | static int tavil_iir_band_audio_mixer_get(struct snd_kcontrol *kcontrol, |
| 4843 | struct snd_ctl_elem_value *ucontrol) |
| 4844 | { |
| 4845 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 4846 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 4847 | kcontrol->private_value)->reg; |
| 4848 | int band_idx = ((struct soc_multi_mixer_control *) |
| 4849 | kcontrol->private_value)->shift; |
| 4850 | |
| 4851 | ucontrol->value.integer.value[0] = |
| 4852 | get_iir_band_coeff(codec, iir_idx, band_idx, 0); |
| 4853 | ucontrol->value.integer.value[1] = |
| 4854 | get_iir_band_coeff(codec, iir_idx, band_idx, 1); |
| 4855 | ucontrol->value.integer.value[2] = |
| 4856 | get_iir_band_coeff(codec, iir_idx, band_idx, 2); |
| 4857 | ucontrol->value.integer.value[3] = |
| 4858 | get_iir_band_coeff(codec, iir_idx, band_idx, 3); |
| 4859 | ucontrol->value.integer.value[4] = |
| 4860 | get_iir_band_coeff(codec, iir_idx, band_idx, 4); |
| 4861 | |
| 4862 | dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n" |
| 4863 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 4864 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 4865 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 4866 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 4867 | __func__, iir_idx, band_idx, |
| 4868 | (uint32_t)ucontrol->value.integer.value[0], |
| 4869 | __func__, iir_idx, band_idx, |
| 4870 | (uint32_t)ucontrol->value.integer.value[1], |
| 4871 | __func__, iir_idx, band_idx, |
| 4872 | (uint32_t)ucontrol->value.integer.value[2], |
| 4873 | __func__, iir_idx, band_idx, |
| 4874 | (uint32_t)ucontrol->value.integer.value[3], |
| 4875 | __func__, iir_idx, band_idx, |
| 4876 | (uint32_t)ucontrol->value.integer.value[4]); |
| 4877 | return 0; |
| 4878 | } |
| 4879 | |
| 4880 | static void set_iir_band_coeff(struct snd_soc_codec *codec, |
| 4881 | int iir_idx, int band_idx, |
| 4882 | uint32_t value) |
| 4883 | { |
| 4884 | snd_soc_write(codec, |
| 4885 | (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx), |
| 4886 | (value & 0xFF)); |
| 4887 | |
| 4888 | snd_soc_write(codec, |
| 4889 | (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx), |
| 4890 | (value >> 8) & 0xFF); |
| 4891 | |
| 4892 | snd_soc_write(codec, |
| 4893 | (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx), |
| 4894 | (value >> 16) & 0xFF); |
| 4895 | |
| 4896 | /* Mask top 2 bits, 7-8 are reserved */ |
| 4897 | snd_soc_write(codec, |
| 4898 | (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL + 16 * iir_idx), |
| 4899 | (value >> 24) & 0x3F); |
| 4900 | } |
| 4901 | |
| 4902 | static int tavil_iir_band_audio_mixer_put(struct snd_kcontrol *kcontrol, |
| 4903 | struct snd_ctl_elem_value *ucontrol) |
| 4904 | { |
| 4905 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 4906 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 4907 | kcontrol->private_value)->reg; |
| 4908 | int band_idx = ((struct soc_multi_mixer_control *) |
| 4909 | kcontrol->private_value)->shift; |
| 4910 | |
| 4911 | /* |
| 4912 | * Mask top bit it is reserved |
| 4913 | * Updates addr automatically for each B2 write |
| 4914 | */ |
| 4915 | snd_soc_write(codec, |
| 4916 | (WCD934X_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx), |
| 4917 | (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F); |
| 4918 | |
| 4919 | set_iir_band_coeff(codec, iir_idx, band_idx, |
| 4920 | ucontrol->value.integer.value[0]); |
| 4921 | set_iir_band_coeff(codec, iir_idx, band_idx, |
| 4922 | ucontrol->value.integer.value[1]); |
| 4923 | set_iir_band_coeff(codec, iir_idx, band_idx, |
| 4924 | ucontrol->value.integer.value[2]); |
| 4925 | set_iir_band_coeff(codec, iir_idx, band_idx, |
| 4926 | ucontrol->value.integer.value[3]); |
| 4927 | set_iir_band_coeff(codec, iir_idx, band_idx, |
| 4928 | ucontrol->value.integer.value[4]); |
| 4929 | |
| 4930 | pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n" |
| 4931 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 4932 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 4933 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 4934 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 4935 | __func__, iir_idx, band_idx, |
| 4936 | get_iir_band_coeff(codec, iir_idx, band_idx, 0), |
| 4937 | __func__, iir_idx, band_idx, |
| 4938 | get_iir_band_coeff(codec, iir_idx, band_idx, 1), |
| 4939 | __func__, iir_idx, band_idx, |
| 4940 | get_iir_band_coeff(codec, iir_idx, band_idx, 2), |
| 4941 | __func__, iir_idx, band_idx, |
| 4942 | get_iir_band_coeff(codec, iir_idx, band_idx, 3), |
| 4943 | __func__, iir_idx, band_idx, |
| 4944 | get_iir_band_coeff(codec, iir_idx, band_idx, 4)); |
| 4945 | return 0; |
| 4946 | } |
| 4947 | |
| 4948 | static int tavil_compander_get(struct snd_kcontrol *kcontrol, |
| 4949 | struct snd_ctl_elem_value *ucontrol) |
| 4950 | { |
| 4951 | |
| 4952 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 4953 | int comp = ((struct soc_multi_mixer_control *) |
| 4954 | kcontrol->private_value)->shift; |
| 4955 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 4956 | |
| 4957 | ucontrol->value.integer.value[0] = tavil->comp_enabled[comp]; |
| 4958 | return 0; |
| 4959 | } |
| 4960 | |
| 4961 | static int tavil_compander_put(struct snd_kcontrol *kcontrol, |
| 4962 | struct snd_ctl_elem_value *ucontrol) |
| 4963 | { |
| 4964 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 4965 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 4966 | int comp = ((struct soc_multi_mixer_control *) |
| 4967 | kcontrol->private_value)->shift; |
| 4968 | int value = ucontrol->value.integer.value[0]; |
| 4969 | |
| 4970 | dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n", |
| 4971 | __func__, comp + 1, tavil->comp_enabled[comp], value); |
| 4972 | tavil->comp_enabled[comp] = value; |
| 4973 | |
| 4974 | /* Any specific register configuration for compander */ |
| 4975 | switch (comp) { |
| 4976 | case COMPANDER_1: |
| 4977 | /* Set Gain Source Select based on compander enable/disable */ |
| 4978 | snd_soc_update_bits(codec, WCD934X_HPH_L_EN, 0x20, |
| 4979 | (value ? 0x00:0x20)); |
| 4980 | break; |
| 4981 | case COMPANDER_2: |
| 4982 | snd_soc_update_bits(codec, WCD934X_HPH_R_EN, 0x20, |
| 4983 | (value ? 0x00:0x20)); |
| 4984 | break; |
| 4985 | case COMPANDER_3: |
| 4986 | case COMPANDER_4: |
| 4987 | case COMPANDER_7: |
| 4988 | case COMPANDER_8: |
| 4989 | break; |
| 4990 | default: |
| 4991 | /* |
| 4992 | * if compander is not enabled for any interpolator, |
| 4993 | * it does not cause any audio failure, so do not |
| 4994 | * return error in this case, but just print a log |
| 4995 | */ |
| 4996 | dev_warn(codec->dev, "%s: unknown compander: %d\n", |
| 4997 | __func__, comp); |
| 4998 | }; |
| 4999 | return 0; |
| 5000 | } |
| 5001 | |
| 5002 | static int tavil_hph_asrc_mode_put(struct snd_kcontrol *kcontrol, |
| 5003 | struct snd_ctl_elem_value *ucontrol) |
| 5004 | { |
| 5005 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5006 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 5007 | int index = -EINVAL; |
| 5008 | |
| 5009 | if (!strcmp(kcontrol->id.name, "ASRC0 Output Mode")) |
| 5010 | index = ASRC0; |
| 5011 | if (!strcmp(kcontrol->id.name, "ASRC1 Output Mode")) |
| 5012 | index = ASRC1; |
| 5013 | |
| 5014 | if (tavil && (index >= 0) && (index < ASRC_MAX)) |
| 5015 | tavil->asrc_output_mode[index] = |
| 5016 | ucontrol->value.integer.value[0]; |
| 5017 | |
| 5018 | return 0; |
| 5019 | } |
| 5020 | |
| 5021 | static int tavil_hph_asrc_mode_get(struct snd_kcontrol *kcontrol, |
| 5022 | struct snd_ctl_elem_value *ucontrol) |
| 5023 | { |
| 5024 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5025 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 5026 | int val = 0; |
| 5027 | int index = -EINVAL; |
| 5028 | |
| 5029 | if (!strcmp(kcontrol->id.name, "ASRC0 Output Mode")) |
| 5030 | index = ASRC0; |
| 5031 | if (!strcmp(kcontrol->id.name, "ASRC1 Output Mode")) |
| 5032 | index = ASRC1; |
| 5033 | |
| 5034 | if (tavil && (index >= 0) && (index < ASRC_MAX)) |
| 5035 | val = tavil->asrc_output_mode[index]; |
| 5036 | |
| 5037 | ucontrol->value.integer.value[0] = val; |
| 5038 | |
| 5039 | return 0; |
| 5040 | } |
| 5041 | |
| 5042 | static int tavil_hph_idle_detect_get(struct snd_kcontrol *kcontrol, |
| 5043 | struct snd_ctl_elem_value *ucontrol) |
| 5044 | { |
| 5045 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5046 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 5047 | int val = 0; |
| 5048 | |
| 5049 | if (tavil) |
| 5050 | val = tavil->idle_det_cfg.hph_idle_detect_en; |
| 5051 | |
| 5052 | ucontrol->value.integer.value[0] = val; |
| 5053 | |
| 5054 | return 0; |
| 5055 | } |
| 5056 | |
| 5057 | static int tavil_hph_idle_detect_put(struct snd_kcontrol *kcontrol, |
| 5058 | struct snd_ctl_elem_value *ucontrol) |
| 5059 | { |
| 5060 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5061 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 5062 | |
| 5063 | if (tavil) |
| 5064 | tavil->idle_det_cfg.hph_idle_detect_en = |
| 5065 | ucontrol->value.integer.value[0]; |
| 5066 | |
| 5067 | return 0; |
| 5068 | } |
| 5069 | |
| 5070 | static int tavil_dmic_pin_mode_get(struct snd_kcontrol *kcontrol, |
| 5071 | struct snd_ctl_elem_value *ucontrol) |
| 5072 | { |
| 5073 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5074 | u16 dmic_pin; |
| 5075 | u8 reg_val, pinctl_position; |
| 5076 | |
| 5077 | pinctl_position = ((struct soc_multi_mixer_control *) |
| 5078 | kcontrol->private_value)->shift; |
| 5079 | |
| 5080 | dmic_pin = pinctl_position & 0x07; |
| 5081 | reg_val = snd_soc_read(codec, |
| 5082 | WCD934X_TLMM_DMIC1_CLK_PINCFG + dmic_pin - 1); |
| 5083 | |
| 5084 | ucontrol->value.integer.value[0] = !!reg_val; |
| 5085 | |
| 5086 | return 0; |
| 5087 | } |
| 5088 | |
| 5089 | static int tavil_dmic_pin_mode_put(struct snd_kcontrol *kcontrol, |
| 5090 | struct snd_ctl_elem_value *ucontrol) |
| 5091 | { |
| 5092 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5093 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 5094 | u16 ctl_reg, cfg_reg, dmic_pin; |
| 5095 | u8 ctl_val, cfg_val, pinctl_position, pinctl_mode, mask; |
| 5096 | |
| 5097 | /* 0- high or low; 1- high Z */ |
| 5098 | pinctl_mode = ucontrol->value.integer.value[0]; |
| 5099 | pinctl_position = ((struct soc_multi_mixer_control *) |
| 5100 | kcontrol->private_value)->shift; |
| 5101 | |
| 5102 | switch (pinctl_position >> 3) { |
| 5103 | case 0: |
| 5104 | ctl_reg = WCD934X_TEST_DEBUG_PIN_CTL_OE_0; |
| 5105 | break; |
| 5106 | case 1: |
| 5107 | ctl_reg = WCD934X_TEST_DEBUG_PIN_CTL_OE_1; |
| 5108 | break; |
| 5109 | case 2: |
| 5110 | ctl_reg = WCD934X_TEST_DEBUG_PIN_CTL_OE_2; |
| 5111 | break; |
| 5112 | case 3: |
| 5113 | ctl_reg = WCD934X_TEST_DEBUG_PIN_CTL_OE_3; |
| 5114 | break; |
| 5115 | default: |
| 5116 | dev_err(codec->dev, "%s: Invalid pinctl position = %d\n", |
| 5117 | __func__, pinctl_position); |
| 5118 | return -EINVAL; |
| 5119 | } |
| 5120 | |
| 5121 | ctl_val = ~(pinctl_mode << (pinctl_position & 0x07)); |
| 5122 | mask = 1 << (pinctl_position & 0x07); |
| 5123 | snd_soc_update_bits(codec, ctl_reg, mask, ctl_val); |
| 5124 | |
| 5125 | dmic_pin = pinctl_position & 0x07; |
| 5126 | cfg_reg = WCD934X_TLMM_DMIC1_CLK_PINCFG + dmic_pin - 1; |
| 5127 | if (pinctl_mode) { |
| 5128 | if (tavil->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 5129 | cfg_val = 0x6; |
| 5130 | else |
| 5131 | cfg_val = 0xD; |
| 5132 | } else |
| 5133 | cfg_val = 0; |
| 5134 | snd_soc_update_bits(codec, cfg_reg, 0x1F, cfg_val); |
| 5135 | |
| 5136 | dev_dbg(codec->dev, "%s: reg=0x%x mask=0x%x val=%d reg=0x%x val=%d\n", |
| 5137 | __func__, ctl_reg, mask, ctl_val, cfg_reg, cfg_val); |
| 5138 | |
| 5139 | return 0; |
| 5140 | } |
| 5141 | |
| 5142 | static int tavil_amic_pwr_lvl_get(struct snd_kcontrol *kcontrol, |
| 5143 | struct snd_ctl_elem_value *ucontrol) |
| 5144 | { |
| 5145 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
Phani Kumar Uppalapati | afdc5a8 | 2016-12-16 17:06:27 -0800 | [diff] [blame] | 5146 | u16 amic_reg = 0; |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 5147 | |
| 5148 | if (!strcmp(kcontrol->id.name, "AMIC_1_2 PWR MODE")) |
| 5149 | amic_reg = WCD934X_ANA_AMIC1; |
| 5150 | if (!strcmp(kcontrol->id.name, "AMIC_3_4 PWR MODE")) |
| 5151 | amic_reg = WCD934X_ANA_AMIC3; |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 5152 | |
Phani Kumar Uppalapati | afdc5a8 | 2016-12-16 17:06:27 -0800 | [diff] [blame] | 5153 | if (amic_reg) |
| 5154 | ucontrol->value.integer.value[0] = |
| 5155 | (snd_soc_read(codec, amic_reg) & |
| 5156 | WCD934X_AMIC_PWR_LVL_MASK) >> |
| 5157 | WCD934X_AMIC_PWR_LVL_SHIFT; |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 5158 | return 0; |
| 5159 | } |
| 5160 | |
| 5161 | static int tavil_amic_pwr_lvl_put(struct snd_kcontrol *kcontrol, |
| 5162 | struct snd_ctl_elem_value *ucontrol) |
| 5163 | { |
| 5164 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5165 | u32 mode_val; |
Phani Kumar Uppalapati | afdc5a8 | 2016-12-16 17:06:27 -0800 | [diff] [blame] | 5166 | u16 amic_reg = 0; |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 5167 | |
| 5168 | mode_val = ucontrol->value.enumerated.item[0]; |
| 5169 | |
| 5170 | dev_dbg(codec->dev, "%s: mode: %d\n", __func__, mode_val); |
| 5171 | |
| 5172 | if (!strcmp(kcontrol->id.name, "AMIC_1_2 PWR MODE")) |
| 5173 | amic_reg = WCD934X_ANA_AMIC1; |
| 5174 | if (!strcmp(kcontrol->id.name, "AMIC_3_4 PWR MODE")) |
| 5175 | amic_reg = WCD934X_ANA_AMIC3; |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 5176 | |
Phani Kumar Uppalapati | afdc5a8 | 2016-12-16 17:06:27 -0800 | [diff] [blame] | 5177 | if (amic_reg) |
| 5178 | snd_soc_update_bits(codec, amic_reg, WCD934X_AMIC_PWR_LVL_MASK, |
| 5179 | mode_val << WCD934X_AMIC_PWR_LVL_SHIFT); |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 5180 | return 0; |
| 5181 | } |
| 5182 | |
| 5183 | static const char *const tavil_conn_mad_text[] = { |
| 5184 | "NOTUSED1", "ADC1", "ADC2", "ADC3", "ADC4", "NOTUSED5", |
| 5185 | "NOTUSED6", "NOTUSED2", "DMIC0", "DMIC1", "DMIC2", "DMIC3", |
| 5186 | "DMIC4", "DMIC5", "NOTUSED3", "NOTUSED4" |
| 5187 | }; |
| 5188 | |
| 5189 | static const struct soc_enum tavil_conn_mad_enum = |
| 5190 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tavil_conn_mad_text), |
| 5191 | tavil_conn_mad_text); |
| 5192 | |
| 5193 | static int tavil_mad_input_get(struct snd_kcontrol *kcontrol, |
| 5194 | struct snd_ctl_elem_value *ucontrol) |
| 5195 | { |
| 5196 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5197 | u8 tavil_mad_input; |
| 5198 | |
| 5199 | tavil_mad_input = snd_soc_read(codec, WCD934X_SOC_MAD_INP_SEL) & 0x0F; |
| 5200 | ucontrol->value.integer.value[0] = tavil_mad_input; |
| 5201 | |
| 5202 | dev_dbg(codec->dev, "%s: tavil_mad_input = %s\n", __func__, |
| 5203 | tavil_conn_mad_text[tavil_mad_input]); |
| 5204 | |
| 5205 | return 0; |
| 5206 | } |
| 5207 | |
| 5208 | static int tavil_mad_input_put(struct snd_kcontrol *kcontrol, |
| 5209 | struct snd_ctl_elem_value *ucontrol) |
| 5210 | { |
| 5211 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5212 | struct snd_soc_card *card = codec->component.card; |
| 5213 | u8 tavil_mad_input; |
| 5214 | char mad_amic_input_widget[6]; |
| 5215 | const char *mad_input_widget; |
| 5216 | const char *source_widget = NULL; |
| 5217 | u32 adc, i, mic_bias_found = 0; |
| 5218 | int ret = 0; |
| 5219 | char *mad_input; |
| 5220 | bool is_adc2_input = false; |
| 5221 | |
| 5222 | tavil_mad_input = ucontrol->value.integer.value[0]; |
| 5223 | |
Karthikeyan Mani | 5b976ab | 2016-12-12 11:04:01 -0800 | [diff] [blame] | 5224 | if (tavil_mad_input >= sizeof(tavil_conn_mad_text)/ |
| 5225 | sizeof(tavil_conn_mad_text[0])) { |
| 5226 | dev_err(codec->dev, |
| 5227 | "%s: tavil_mad_input = %d out of bounds\n", |
| 5228 | __func__, tavil_mad_input); |
| 5229 | return -EINVAL; |
| 5230 | } |
| 5231 | |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 5232 | if (strnstr(tavil_conn_mad_text[tavil_mad_input], "NOTUSED", |
| 5233 | sizeof("NOTUSED"))) { |
| 5234 | dev_dbg(codec->dev, |
| 5235 | "%s: Unsupported tavil_mad_input = %s\n", |
| 5236 | __func__, tavil_conn_mad_text[tavil_mad_input]); |
| 5237 | /* Make sure the MAD register is updated */ |
| 5238 | snd_soc_update_bits(codec, WCD934X_ANA_MAD_SETUP, |
| 5239 | 0x88, 0x00); |
| 5240 | return -EINVAL; |
| 5241 | } |
| 5242 | |
| 5243 | if (strnstr(tavil_conn_mad_text[tavil_mad_input], |
| 5244 | "ADC", sizeof("ADC"))) { |
| 5245 | mad_input = strpbrk(tavil_conn_mad_text[tavil_mad_input], |
| 5246 | "1234"); |
| 5247 | if (!mad_input) { |
| 5248 | dev_err(codec->dev, "%s: Invalid MAD input %s\n", |
| 5249 | __func__, tavil_conn_mad_text[tavil_mad_input]); |
| 5250 | return -EINVAL; |
| 5251 | } |
| 5252 | |
| 5253 | ret = kstrtouint(mad_input, 10, &adc); |
| 5254 | if ((ret < 0) || (adc > 4)) { |
| 5255 | dev_err(codec->dev, "%s: Invalid ADC = %s\n", __func__, |
| 5256 | tavil_conn_mad_text[tavil_mad_input]); |
| 5257 | return -EINVAL; |
| 5258 | } |
| 5259 | |
| 5260 | /*AMIC4 and AMIC5 share ADC4*/ |
| 5261 | if ((adc == 4) && |
| 5262 | (snd_soc_read(codec, WCD934X_TX_NEW_AMIC_4_5_SEL) & 0x10)) |
| 5263 | adc = 5; |
| 5264 | |
| 5265 | snprintf(mad_amic_input_widget, 6, "%s%u", "AMIC", adc); |
| 5266 | |
| 5267 | mad_input_widget = mad_amic_input_widget; |
| 5268 | if (adc == 2) |
| 5269 | is_adc2_input = true; |
| 5270 | } else { |
| 5271 | /* DMIC type input widget*/ |
| 5272 | mad_input_widget = tavil_conn_mad_text[tavil_mad_input]; |
| 5273 | } |
| 5274 | |
| 5275 | dev_dbg(codec->dev, |
| 5276 | "%s: tavil input widget = %s, adc_input = %s\n", __func__, |
| 5277 | mad_input_widget, is_adc2_input ? "true" : "false"); |
| 5278 | |
| 5279 | for (i = 0; i < card->num_of_dapm_routes; i++) { |
| 5280 | if (!strcmp(card->of_dapm_routes[i].sink, mad_input_widget)) { |
| 5281 | source_widget = card->of_dapm_routes[i].source; |
| 5282 | if (!source_widget) { |
| 5283 | dev_err(codec->dev, |
| 5284 | "%s: invalid source widget\n", |
| 5285 | __func__); |
| 5286 | return -EINVAL; |
| 5287 | } |
| 5288 | |
| 5289 | if (strnstr(source_widget, |
| 5290 | "MIC BIAS1", sizeof("MIC BIAS1"))) { |
| 5291 | mic_bias_found = 1; |
| 5292 | break; |
| 5293 | } else if (strnstr(source_widget, |
| 5294 | "MIC BIAS2", sizeof("MIC BIAS2"))) { |
| 5295 | mic_bias_found = 2; |
| 5296 | break; |
| 5297 | } else if (strnstr(source_widget, |
| 5298 | "MIC BIAS3", sizeof("MIC BIAS3"))) { |
| 5299 | mic_bias_found = 3; |
| 5300 | break; |
| 5301 | } else if (strnstr(source_widget, |
| 5302 | "MIC BIAS4", sizeof("MIC BIAS4"))) { |
| 5303 | mic_bias_found = 4; |
| 5304 | break; |
| 5305 | } |
| 5306 | } |
| 5307 | } |
| 5308 | |
| 5309 | if (!mic_bias_found) { |
| 5310 | dev_err(codec->dev, "%s: mic bias not found for input %s\n", |
| 5311 | __func__, mad_input_widget); |
| 5312 | return -EINVAL; |
| 5313 | } |
| 5314 | |
| 5315 | dev_dbg(codec->dev, "%s: mic_bias found = %d\n", __func__, |
| 5316 | mic_bias_found); |
| 5317 | |
| 5318 | snd_soc_update_bits(codec, WCD934X_SOC_MAD_INP_SEL, |
| 5319 | 0x0F, tavil_mad_input); |
| 5320 | snd_soc_update_bits(codec, WCD934X_ANA_MAD_SETUP, |
| 5321 | 0x07, mic_bias_found); |
| 5322 | /* for adc2 input, mad should be in micbias mode with BG enabled */ |
| 5323 | if (is_adc2_input) |
| 5324 | snd_soc_update_bits(codec, WCD934X_ANA_MAD_SETUP, |
| 5325 | 0x88, 0x88); |
| 5326 | else |
| 5327 | snd_soc_update_bits(codec, WCD934X_ANA_MAD_SETUP, |
| 5328 | 0x88, 0x00); |
| 5329 | return 0; |
| 5330 | } |
| 5331 | |
| 5332 | static int tavil_ear_pa_gain_get(struct snd_kcontrol *kcontrol, |
| 5333 | struct snd_ctl_elem_value *ucontrol) |
| 5334 | { |
| 5335 | u8 ear_pa_gain; |
| 5336 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5337 | |
| 5338 | ear_pa_gain = snd_soc_read(codec, WCD934X_ANA_EAR); |
| 5339 | |
| 5340 | ear_pa_gain = (ear_pa_gain & 0x70) >> 4; |
| 5341 | |
| 5342 | ucontrol->value.integer.value[0] = ear_pa_gain; |
| 5343 | |
| 5344 | dev_dbg(codec->dev, "%s: ear_pa_gain = 0x%x\n", __func__, |
| 5345 | ear_pa_gain); |
| 5346 | |
| 5347 | return 0; |
| 5348 | } |
| 5349 | |
| 5350 | static int tavil_ear_pa_gain_put(struct snd_kcontrol *kcontrol, |
| 5351 | struct snd_ctl_elem_value *ucontrol) |
| 5352 | { |
| 5353 | u8 ear_pa_gain; |
| 5354 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5355 | |
| 5356 | dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n", |
| 5357 | __func__, ucontrol->value.integer.value[0]); |
| 5358 | |
| 5359 | ear_pa_gain = ucontrol->value.integer.value[0] << 4; |
| 5360 | |
| 5361 | snd_soc_update_bits(codec, WCD934X_ANA_EAR, 0x70, ear_pa_gain); |
| 5362 | return 0; |
| 5363 | } |
| 5364 | |
| 5365 | static int tavil_ear_spkr_pa_gain_get(struct snd_kcontrol *kcontrol, |
| 5366 | struct snd_ctl_elem_value *ucontrol) |
| 5367 | { |
| 5368 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5369 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 5370 | |
| 5371 | ucontrol->value.integer.value[0] = tavil->ear_spkr_gain; |
| 5372 | |
| 5373 | dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n", |
| 5374 | __func__, ucontrol->value.integer.value[0]); |
| 5375 | |
| 5376 | return 0; |
| 5377 | } |
| 5378 | |
| 5379 | static int tavil_ear_spkr_pa_gain_put(struct snd_kcontrol *kcontrol, |
| 5380 | struct snd_ctl_elem_value *ucontrol) |
| 5381 | { |
| 5382 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5383 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 5384 | |
| 5385 | tavil->ear_spkr_gain = ucontrol->value.integer.value[0]; |
| 5386 | |
| 5387 | dev_dbg(codec->dev, "%s: gain = %d\n", __func__, tavil->ear_spkr_gain); |
| 5388 | |
| 5389 | return 0; |
| 5390 | } |
| 5391 | |
| 5392 | static int tavil_rx_hph_mode_get(struct snd_kcontrol *kcontrol, |
| 5393 | struct snd_ctl_elem_value *ucontrol) |
| 5394 | { |
| 5395 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5396 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 5397 | |
| 5398 | ucontrol->value.integer.value[0] = tavil->hph_mode; |
| 5399 | return 0; |
| 5400 | } |
| 5401 | |
| 5402 | static int tavil_rx_hph_mode_put(struct snd_kcontrol *kcontrol, |
| 5403 | struct snd_ctl_elem_value *ucontrol) |
| 5404 | { |
| 5405 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
| 5406 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 5407 | u32 mode_val; |
| 5408 | |
| 5409 | mode_val = ucontrol->value.enumerated.item[0]; |
| 5410 | |
| 5411 | dev_dbg(codec->dev, "%s: mode: %d\n", __func__, mode_val); |
| 5412 | |
| 5413 | if (mode_val == 0) { |
| 5414 | dev_warn(codec->dev, "%s:Invalid HPH Mode, default to Cls-H LOHiFi\n", |
| 5415 | __func__); |
| 5416 | mode_val = CLS_H_LOHIFI; |
| 5417 | } |
| 5418 | tavil->hph_mode = mode_val; |
| 5419 | return 0; |
| 5420 | } |
| 5421 | |
| 5422 | static const char * const rx_hph_mode_mux_text[] = { |
| 5423 | "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI", |
| 5424 | "CLS_H_ULP", "CLS_AB_HIFI", |
| 5425 | }; |
| 5426 | |
| 5427 | static const struct soc_enum rx_hph_mode_mux_enum = |
| 5428 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text), |
| 5429 | rx_hph_mode_mux_text); |
| 5430 | |
| 5431 | static const char *const tavil_anc_func_text[] = {"OFF", "ON"}; |
| 5432 | static const struct soc_enum tavil_anc_func_enum = |
| 5433 | SOC_ENUM_SINGLE_EXT(2, tavil_anc_func_text); |
| 5434 | |
| 5435 | /* Cutoff frequency for high pass filter */ |
| 5436 | static const char * const cf_text[] = { |
| 5437 | "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ" |
| 5438 | }; |
| 5439 | |
| 5440 | static const char * const rx_cf_text[] = { |
| 5441 | "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ", |
| 5442 | "CF_NEG_3DB_0P48HZ" |
| 5443 | }; |
| 5444 | |
| 5445 | static const char * const amic_pwr_lvl_text[] = { |
| 5446 | "LOW_PWR", "DEFAULT", "HIGH_PERF" |
| 5447 | }; |
| 5448 | |
| 5449 | static const char * const hph_idle_detect_text[] = { |
| 5450 | "OFF", "ON" |
| 5451 | }; |
| 5452 | |
| 5453 | static const char * const asrc_mode_text[] = { |
| 5454 | "INT", "FRAC" |
| 5455 | }; |
| 5456 | |
| 5457 | static const char * const tavil_ear_pa_gain_text[] = { |
| 5458 | "G_6_DB", "G_4P5_DB", "G_3_DB", "G_1P5_DB", |
| 5459 | "G_0_DB", "G_M2P5_DB", "UNDEFINED", "G_M12_DB" |
| 5460 | }; |
| 5461 | |
| 5462 | static const char * const tavil_ear_spkr_pa_gain_text[] = { |
| 5463 | "G_DEFAULT", "G_0_DB", "G_1_DB", "G_2_DB", "G_3_DB", |
| 5464 | "G_4_DB", "G_5_DB", "G_6_DB" |
| 5465 | }; |
| 5466 | |
| 5467 | static SOC_ENUM_SINGLE_EXT_DECL(tavil_ear_pa_gain_enum, tavil_ear_pa_gain_text); |
| 5468 | static SOC_ENUM_SINGLE_EXT_DECL(tavil_ear_spkr_pa_gain_enum, |
| 5469 | tavil_ear_spkr_pa_gain_text); |
| 5470 | static SOC_ENUM_SINGLE_EXT_DECL(amic_pwr_lvl_enum, amic_pwr_lvl_text); |
| 5471 | static SOC_ENUM_SINGLE_EXT_DECL(hph_idle_detect_enum, hph_idle_detect_text); |
| 5472 | static SOC_ENUM_SINGLE_EXT_DECL(asrc_mode_enum, asrc_mode_text); |
| 5473 | static SOC_ENUM_SINGLE_DECL(cf_dec0_enum, WCD934X_CDC_TX0_TX_PATH_CFG0, 5, |
| 5474 | cf_text); |
| 5475 | static SOC_ENUM_SINGLE_DECL(cf_dec1_enum, WCD934X_CDC_TX1_TX_PATH_CFG0, 5, |
| 5476 | cf_text); |
| 5477 | static SOC_ENUM_SINGLE_DECL(cf_dec2_enum, WCD934X_CDC_TX2_TX_PATH_CFG0, 5, |
| 5478 | cf_text); |
| 5479 | static SOC_ENUM_SINGLE_DECL(cf_dec3_enum, WCD934X_CDC_TX3_TX_PATH_CFG0, 5, |
| 5480 | cf_text); |
| 5481 | static SOC_ENUM_SINGLE_DECL(cf_dec4_enum, WCD934X_CDC_TX4_TX_PATH_CFG0, 5, |
| 5482 | cf_text); |
| 5483 | static SOC_ENUM_SINGLE_DECL(cf_dec5_enum, WCD934X_CDC_TX5_TX_PATH_CFG0, 5, |
| 5484 | cf_text); |
| 5485 | static SOC_ENUM_SINGLE_DECL(cf_dec6_enum, WCD934X_CDC_TX6_TX_PATH_CFG0, 5, |
| 5486 | cf_text); |
| 5487 | static SOC_ENUM_SINGLE_DECL(cf_dec7_enum, WCD934X_CDC_TX7_TX_PATH_CFG0, 5, |
| 5488 | cf_text); |
| 5489 | static SOC_ENUM_SINGLE_DECL(cf_dec8_enum, WCD934X_CDC_TX8_TX_PATH_CFG0, 5, |
| 5490 | cf_text); |
| 5491 | static SOC_ENUM_SINGLE_DECL(cf_int0_1_enum, WCD934X_CDC_RX0_RX_PATH_CFG2, 0, |
| 5492 | rx_cf_text); |
| 5493 | static SOC_ENUM_SINGLE_DECL(cf_int0_2_enum, WCD934X_CDC_RX0_RX_PATH_MIX_CFG, 2, |
| 5494 | rx_cf_text); |
| 5495 | static SOC_ENUM_SINGLE_DECL(cf_int1_1_enum, WCD934X_CDC_RX1_RX_PATH_CFG2, 0, |
| 5496 | rx_cf_text); |
| 5497 | static SOC_ENUM_SINGLE_DECL(cf_int1_2_enum, WCD934X_CDC_RX1_RX_PATH_MIX_CFG, 2, |
| 5498 | rx_cf_text); |
| 5499 | static SOC_ENUM_SINGLE_DECL(cf_int2_1_enum, WCD934X_CDC_RX2_RX_PATH_CFG2, 0, |
| 5500 | rx_cf_text); |
| 5501 | static SOC_ENUM_SINGLE_DECL(cf_int2_2_enum, WCD934X_CDC_RX2_RX_PATH_MIX_CFG, 2, |
| 5502 | rx_cf_text); |
| 5503 | static SOC_ENUM_SINGLE_DECL(cf_int3_1_enum, WCD934X_CDC_RX3_RX_PATH_CFG2, 0, |
| 5504 | rx_cf_text); |
| 5505 | static SOC_ENUM_SINGLE_DECL(cf_int3_2_enum, WCD934X_CDC_RX3_RX_PATH_MIX_CFG, 2, |
| 5506 | rx_cf_text); |
| 5507 | static SOC_ENUM_SINGLE_DECL(cf_int4_1_enum, WCD934X_CDC_RX4_RX_PATH_CFG2, 0, |
| 5508 | rx_cf_text); |
| 5509 | static SOC_ENUM_SINGLE_DECL(cf_int4_2_enum, WCD934X_CDC_RX4_RX_PATH_MIX_CFG, 2, |
| 5510 | rx_cf_text); |
| 5511 | static SOC_ENUM_SINGLE_DECL(cf_int7_1_enum, WCD934X_CDC_RX7_RX_PATH_CFG2, 0, |
| 5512 | rx_cf_text); |
| 5513 | static SOC_ENUM_SINGLE_DECL(cf_int7_2_enum, WCD934X_CDC_RX7_RX_PATH_MIX_CFG, 2, |
| 5514 | rx_cf_text); |
| 5515 | static SOC_ENUM_SINGLE_DECL(cf_int8_1_enum, WCD934X_CDC_RX8_RX_PATH_CFG2, 0, |
| 5516 | rx_cf_text); |
| 5517 | static SOC_ENUM_SINGLE_DECL(cf_int8_2_enum, WCD934X_CDC_RX8_RX_PATH_MIX_CFG, 2, |
| 5518 | rx_cf_text); |
| 5519 | |
| 5520 | static const struct snd_kcontrol_new tavil_snd_controls[] = { |
| 5521 | SOC_ENUM_EXT("EAR PA Gain", tavil_ear_pa_gain_enum, |
| 5522 | tavil_ear_pa_gain_get, tavil_ear_pa_gain_put), |
| 5523 | SOC_ENUM_EXT("EAR SPKR PA Gain", tavil_ear_spkr_pa_gain_enum, |
| 5524 | tavil_ear_spkr_pa_gain_get, tavil_ear_spkr_pa_gain_put), |
| 5525 | SOC_SINGLE_TLV("HPHL Volume", WCD934X_HPH_L_EN, 0, 20, 1, line_gain), |
| 5526 | SOC_SINGLE_TLV("HPHR Volume", WCD934X_HPH_R_EN, 0, 20, 1, line_gain), |
| 5527 | SOC_SINGLE_TLV("LINEOUT1 Volume", WCD934X_DIFF_LO_LO1_COMPANDER, |
| 5528 | 3, 16, 1, line_gain), |
| 5529 | SOC_SINGLE_TLV("LINEOUT2 Volume", WCD934X_DIFF_LO_LO2_COMPANDER, |
| 5530 | 3, 16, 1, line_gain), |
| 5531 | SOC_SINGLE_TLV("ADC1 Volume", WCD934X_ANA_AMIC1, 0, 20, 0, analog_gain), |
| 5532 | SOC_SINGLE_TLV("ADC2 Volume", WCD934X_ANA_AMIC2, 0, 20, 0, analog_gain), |
| 5533 | SOC_SINGLE_TLV("ADC3 Volume", WCD934X_ANA_AMIC3, 0, 20, 0, analog_gain), |
| 5534 | SOC_SINGLE_TLV("ADC4 Volume", WCD934X_ANA_AMIC4, 0, 20, 0, analog_gain), |
| 5535 | |
| 5536 | SOC_SINGLE_SX_TLV("RX0 Digital Volume", WCD934X_CDC_RX0_RX_VOL_CTL, |
| 5537 | 0, -84, 40, digital_gain), /* -84dB min - 40dB max */ |
| 5538 | SOC_SINGLE_SX_TLV("RX1 Digital Volume", WCD934X_CDC_RX1_RX_VOL_CTL, |
| 5539 | 0, -84, 40, digital_gain), |
| 5540 | SOC_SINGLE_SX_TLV("RX2 Digital Volume", WCD934X_CDC_RX2_RX_VOL_CTL, |
| 5541 | 0, -84, 40, digital_gain), |
| 5542 | SOC_SINGLE_SX_TLV("RX3 Digital Volume", WCD934X_CDC_RX3_RX_VOL_CTL, |
| 5543 | 0, -84, 40, digital_gain), |
| 5544 | SOC_SINGLE_SX_TLV("RX4 Digital Volume", WCD934X_CDC_RX4_RX_VOL_CTL, |
| 5545 | 0, -84, 40, digital_gain), |
| 5546 | SOC_SINGLE_SX_TLV("RX7 Digital Volume", WCD934X_CDC_RX7_RX_VOL_CTL, |
| 5547 | 0, -84, 40, digital_gain), |
| 5548 | SOC_SINGLE_SX_TLV("RX8 Digital Volume", WCD934X_CDC_RX8_RX_VOL_CTL, |
| 5549 | 0, -84, 40, digital_gain), |
| 5550 | SOC_SINGLE_SX_TLV("RX0 Mix Digital Volume", |
| 5551 | WCD934X_CDC_RX0_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain), |
| 5552 | SOC_SINGLE_SX_TLV("RX1 Mix Digital Volume", |
| 5553 | WCD934X_CDC_RX1_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain), |
| 5554 | SOC_SINGLE_SX_TLV("RX2 Mix Digital Volume", |
| 5555 | WCD934X_CDC_RX2_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain), |
| 5556 | SOC_SINGLE_SX_TLV("RX3 Mix Digital Volume", |
| 5557 | WCD934X_CDC_RX3_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain), |
| 5558 | SOC_SINGLE_SX_TLV("RX4 Mix Digital Volume", |
| 5559 | WCD934X_CDC_RX4_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain), |
| 5560 | SOC_SINGLE_SX_TLV("RX7 Mix Digital Volume", |
| 5561 | WCD934X_CDC_RX7_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain), |
| 5562 | SOC_SINGLE_SX_TLV("RX8 Mix Digital Volume", |
| 5563 | WCD934X_CDC_RX8_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain), |
| 5564 | |
| 5565 | SOC_SINGLE_SX_TLV("DEC0 Volume", WCD934X_CDC_TX0_TX_VOL_CTL, 0, |
| 5566 | -84, 40, digital_gain), |
| 5567 | SOC_SINGLE_SX_TLV("DEC1 Volume", WCD934X_CDC_TX1_TX_VOL_CTL, 0, |
| 5568 | -84, 40, digital_gain), |
| 5569 | SOC_SINGLE_SX_TLV("DEC2 Volume", WCD934X_CDC_TX2_TX_VOL_CTL, 0, |
| 5570 | -84, 40, digital_gain), |
| 5571 | SOC_SINGLE_SX_TLV("DEC3 Volume", WCD934X_CDC_TX3_TX_VOL_CTL, 0, |
| 5572 | -84, 40, digital_gain), |
| 5573 | SOC_SINGLE_SX_TLV("DEC4 Volume", WCD934X_CDC_TX4_TX_VOL_CTL, 0, |
| 5574 | -84, 40, digital_gain), |
| 5575 | SOC_SINGLE_SX_TLV("DEC5 Volume", WCD934X_CDC_TX5_TX_VOL_CTL, 0, |
| 5576 | -84, 40, digital_gain), |
| 5577 | SOC_SINGLE_SX_TLV("DEC6 Volume", WCD934X_CDC_TX6_TX_VOL_CTL, 0, |
| 5578 | -84, 40, digital_gain), |
| 5579 | SOC_SINGLE_SX_TLV("DEC7 Volume", WCD934X_CDC_TX7_TX_VOL_CTL, 0, |
| 5580 | -84, 40, digital_gain), |
| 5581 | SOC_SINGLE_SX_TLV("DEC8 Volume", WCD934X_CDC_TX8_TX_VOL_CTL, 0, |
| 5582 | -84, 40, digital_gain), |
| 5583 | |
| 5584 | SOC_SINGLE_SX_TLV("IIR0 INP0 Volume", |
| 5585 | WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL, 0, -84, 40, |
| 5586 | digital_gain), |
| 5587 | SOC_SINGLE_SX_TLV("IIR0 INP1 Volume", |
| 5588 | WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL, 0, -84, 40, |
| 5589 | digital_gain), |
| 5590 | SOC_SINGLE_SX_TLV("IIR0 INP2 Volume", |
| 5591 | WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL, 0, -84, 40, |
| 5592 | digital_gain), |
| 5593 | SOC_SINGLE_SX_TLV("IIR0 INP3 Volume", |
| 5594 | WCD934X_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL, 0, -84, 40, |
| 5595 | digital_gain), |
| 5596 | SOC_SINGLE_SX_TLV("IIR1 INP0 Volume", |
| 5597 | WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B1_CTL, 0, -84, 40, |
| 5598 | digital_gain), |
| 5599 | SOC_SINGLE_SX_TLV("IIR1 INP1 Volume", |
| 5600 | WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B2_CTL, 0, -84, 40, |
| 5601 | digital_gain), |
| 5602 | SOC_SINGLE_SX_TLV("IIR1 INP2 Volume", |
| 5603 | WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B3_CTL, 0, -84, 40, |
| 5604 | digital_gain), |
| 5605 | SOC_SINGLE_SX_TLV("IIR1 INP3 Volume", |
| 5606 | WCD934X_CDC_SIDETONE_IIR1_IIR_GAIN_B4_CTL, 0, -84, 40, |
| 5607 | digital_gain), |
| 5608 | |
| 5609 | SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 100, 0, tavil_get_anc_slot, |
| 5610 | tavil_put_anc_slot), |
| 5611 | SOC_ENUM_EXT("ANC Function", tavil_anc_func_enum, tavil_get_anc_func, |
| 5612 | tavil_put_anc_func), |
| 5613 | |
| 5614 | SOC_ENUM("TX0 HPF cut off", cf_dec0_enum), |
| 5615 | SOC_ENUM("TX1 HPF cut off", cf_dec1_enum), |
| 5616 | SOC_ENUM("TX2 HPF cut off", cf_dec2_enum), |
| 5617 | SOC_ENUM("TX3 HPF cut off", cf_dec3_enum), |
| 5618 | SOC_ENUM("TX4 HPF cut off", cf_dec4_enum), |
| 5619 | SOC_ENUM("TX5 HPF cut off", cf_dec5_enum), |
| 5620 | SOC_ENUM("TX6 HPF cut off", cf_dec6_enum), |
| 5621 | SOC_ENUM("TX7 HPF cut off", cf_dec7_enum), |
| 5622 | SOC_ENUM("TX8 HPF cut off", cf_dec8_enum), |
| 5623 | |
| 5624 | SOC_ENUM("RX INT0_1 HPF cut off", cf_int0_1_enum), |
| 5625 | SOC_ENUM("RX INT0_2 HPF cut off", cf_int0_2_enum), |
| 5626 | SOC_ENUM("RX INT1_1 HPF cut off", cf_int1_1_enum), |
| 5627 | SOC_ENUM("RX INT1_2 HPF cut off", cf_int1_2_enum), |
| 5628 | SOC_ENUM("RX INT2_1 HPF cut off", cf_int2_1_enum), |
| 5629 | SOC_ENUM("RX INT2_2 HPF cut off", cf_int2_2_enum), |
| 5630 | SOC_ENUM("RX INT3_1 HPF cut off", cf_int3_1_enum), |
| 5631 | SOC_ENUM("RX INT3_2 HPF cut off", cf_int3_2_enum), |
| 5632 | SOC_ENUM("RX INT4_1 HPF cut off", cf_int4_1_enum), |
| 5633 | SOC_ENUM("RX INT4_2 HPF cut off", cf_int4_2_enum), |
| 5634 | SOC_ENUM("RX INT7_1 HPF cut off", cf_int7_1_enum), |
| 5635 | SOC_ENUM("RX INT7_2 HPF cut off", cf_int7_2_enum), |
| 5636 | SOC_ENUM("RX INT8_1 HPF cut off", cf_int8_1_enum), |
| 5637 | SOC_ENUM("RX INT8_2 HPF cut off", cf_int8_2_enum), |
| 5638 | |
| 5639 | SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum, |
| 5640 | tavil_rx_hph_mode_get, tavil_rx_hph_mode_put), |
| 5641 | |
| 5642 | SOC_SINGLE_EXT("IIR0 Enable Band1", IIR0, BAND1, 1, 0, |
| 5643 | tavil_iir_enable_audio_mixer_get, |
| 5644 | tavil_iir_enable_audio_mixer_put), |
| 5645 | SOC_SINGLE_EXT("IIR0 Enable Band2", IIR0, BAND2, 1, 0, |
| 5646 | tavil_iir_enable_audio_mixer_get, |
| 5647 | tavil_iir_enable_audio_mixer_put), |
| 5648 | SOC_SINGLE_EXT("IIR0 Enable Band3", IIR0, BAND3, 1, 0, |
| 5649 | tavil_iir_enable_audio_mixer_get, |
| 5650 | tavil_iir_enable_audio_mixer_put), |
| 5651 | SOC_SINGLE_EXT("IIR0 Enable Band4", IIR0, BAND4, 1, 0, |
| 5652 | tavil_iir_enable_audio_mixer_get, |
| 5653 | tavil_iir_enable_audio_mixer_put), |
| 5654 | SOC_SINGLE_EXT("IIR0 Enable Band5", IIR0, BAND5, 1, 0, |
| 5655 | tavil_iir_enable_audio_mixer_get, |
| 5656 | tavil_iir_enable_audio_mixer_put), |
| 5657 | SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0, |
| 5658 | tavil_iir_enable_audio_mixer_get, |
| 5659 | tavil_iir_enable_audio_mixer_put), |
| 5660 | SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0, |
| 5661 | tavil_iir_enable_audio_mixer_get, |
| 5662 | tavil_iir_enable_audio_mixer_put), |
| 5663 | SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0, |
| 5664 | tavil_iir_enable_audio_mixer_get, |
| 5665 | tavil_iir_enable_audio_mixer_put), |
| 5666 | SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0, |
| 5667 | tavil_iir_enable_audio_mixer_get, |
| 5668 | tavil_iir_enable_audio_mixer_put), |
| 5669 | SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0, |
| 5670 | tavil_iir_enable_audio_mixer_get, |
| 5671 | tavil_iir_enable_audio_mixer_put), |
| 5672 | |
| 5673 | SOC_SINGLE_MULTI_EXT("IIR0 Band1", IIR0, BAND1, 255, 0, 5, |
| 5674 | tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put), |
| 5675 | SOC_SINGLE_MULTI_EXT("IIR0 Band2", IIR0, BAND2, 255, 0, 5, |
| 5676 | tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put), |
| 5677 | SOC_SINGLE_MULTI_EXT("IIR0 Band3", IIR0, BAND3, 255, 0, 5, |
| 5678 | tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put), |
| 5679 | SOC_SINGLE_MULTI_EXT("IIR0 Band4", IIR0, BAND4, 255, 0, 5, |
| 5680 | tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put), |
| 5681 | SOC_SINGLE_MULTI_EXT("IIR0 Band5", IIR0, BAND5, 255, 0, 5, |
| 5682 | tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put), |
| 5683 | SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5, |
| 5684 | tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put), |
| 5685 | SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5, |
| 5686 | tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put), |
| 5687 | SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5, |
| 5688 | tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put), |
| 5689 | SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5, |
| 5690 | tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put), |
| 5691 | SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5, |
| 5692 | tavil_iir_band_audio_mixer_get, tavil_iir_band_audio_mixer_put), |
| 5693 | |
| 5694 | SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, COMPANDER_1, 1, 0, |
| 5695 | tavil_compander_get, tavil_compander_put), |
| 5696 | SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, COMPANDER_2, 1, 0, |
| 5697 | tavil_compander_get, tavil_compander_put), |
| 5698 | SOC_SINGLE_EXT("COMP3 Switch", SND_SOC_NOPM, COMPANDER_3, 1, 0, |
| 5699 | tavil_compander_get, tavil_compander_put), |
| 5700 | SOC_SINGLE_EXT("COMP4 Switch", SND_SOC_NOPM, COMPANDER_4, 1, 0, |
| 5701 | tavil_compander_get, tavil_compander_put), |
| 5702 | SOC_SINGLE_EXT("COMP7 Switch", SND_SOC_NOPM, COMPANDER_7, 1, 0, |
| 5703 | tavil_compander_get, tavil_compander_put), |
| 5704 | SOC_SINGLE_EXT("COMP8 Switch", SND_SOC_NOPM, COMPANDER_8, 1, 0, |
| 5705 | tavil_compander_get, tavil_compander_put), |
| 5706 | |
| 5707 | SOC_ENUM_EXT("ASRC0 Output Mode", asrc_mode_enum, |
| 5708 | tavil_hph_asrc_mode_get, tavil_hph_asrc_mode_put), |
| 5709 | SOC_ENUM_EXT("ASRC1 Output Mode", asrc_mode_enum, |
| 5710 | tavil_hph_asrc_mode_get, tavil_hph_asrc_mode_put), |
| 5711 | |
| 5712 | SOC_ENUM_EXT("HPH Idle Detect", hph_idle_detect_enum, |
| 5713 | tavil_hph_idle_detect_get, tavil_hph_idle_detect_put), |
| 5714 | |
| 5715 | SOC_ENUM_EXT("MAD Input", tavil_conn_mad_enum, |
| 5716 | tavil_mad_input_get, tavil_mad_input_put), |
| 5717 | |
| 5718 | SOC_SINGLE_EXT("DMIC1_CLK_PIN_MODE", SND_SOC_NOPM, 17, 1, 0, |
| 5719 | tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put), |
| 5720 | |
| 5721 | SOC_SINGLE_EXT("DMIC1_DATA_PIN_MODE", SND_SOC_NOPM, 18, 1, 0, |
| 5722 | tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put), |
| 5723 | |
| 5724 | SOC_SINGLE_EXT("DMIC2_CLK_PIN_MODE", SND_SOC_NOPM, 19, 1, 0, |
| 5725 | tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put), |
| 5726 | |
| 5727 | SOC_SINGLE_EXT("DMIC2_DATA_PIN_MODE", SND_SOC_NOPM, 20, 1, 0, |
| 5728 | tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put), |
| 5729 | |
| 5730 | SOC_SINGLE_EXT("DMIC3_CLK_PIN_MODE", SND_SOC_NOPM, 21, 1, 0, |
| 5731 | tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put), |
| 5732 | |
| 5733 | SOC_SINGLE_EXT("DMIC3_DATA_PIN_MODE", SND_SOC_NOPM, 22, 1, 0, |
| 5734 | tavil_dmic_pin_mode_get, tavil_dmic_pin_mode_put), |
| 5735 | SOC_ENUM_EXT("AMIC_1_2 PWR MODE", amic_pwr_lvl_enum, |
| 5736 | tavil_amic_pwr_lvl_get, tavil_amic_pwr_lvl_put), |
| 5737 | SOC_ENUM_EXT("AMIC_3_4 PWR MODE", amic_pwr_lvl_enum, |
| 5738 | tavil_amic_pwr_lvl_get, tavil_amic_pwr_lvl_put), |
| 5739 | SOC_ENUM_EXT("AMIC_5_6 PWR MODE", amic_pwr_lvl_enum, |
| 5740 | tavil_amic_pwr_lvl_get, tavil_amic_pwr_lvl_put), |
| 5741 | }; |
| 5742 | |
| 5743 | static int tavil_dec_enum_put(struct snd_kcontrol *kcontrol, |
| 5744 | struct snd_ctl_elem_value *ucontrol) |
| 5745 | { |
| 5746 | struct snd_soc_dapm_widget_list *wlist = |
| 5747 | dapm_kcontrol_get_wlist(kcontrol); |
| 5748 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 5749 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm); |
| 5750 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 5751 | unsigned int val; |
| 5752 | u16 mic_sel_reg = 0; |
| 5753 | u8 mic_sel; |
| 5754 | |
| 5755 | val = ucontrol->value.enumerated.item[0]; |
| 5756 | if (val > e->items - 1) |
| 5757 | return -EINVAL; |
| 5758 | |
| 5759 | dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__, |
| 5760 | widget->name, val); |
| 5761 | |
| 5762 | switch (e->reg) { |
| 5763 | case WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1: |
| 5764 | if (e->shift_l == 0) |
| 5765 | mic_sel_reg = WCD934X_CDC_TX0_TX_PATH_CFG0; |
| 5766 | else if (e->shift_l == 2) |
| 5767 | mic_sel_reg = WCD934X_CDC_TX4_TX_PATH_CFG0; |
| 5768 | else if (e->shift_l == 4) |
| 5769 | mic_sel_reg = WCD934X_CDC_TX8_TX_PATH_CFG0; |
| 5770 | break; |
| 5771 | case WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG1: |
| 5772 | if (e->shift_l == 0) |
| 5773 | mic_sel_reg = WCD934X_CDC_TX1_TX_PATH_CFG0; |
| 5774 | else if (e->shift_l == 2) |
| 5775 | mic_sel_reg = WCD934X_CDC_TX5_TX_PATH_CFG0; |
| 5776 | break; |
| 5777 | case WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG1: |
| 5778 | if (e->shift_l == 0) |
| 5779 | mic_sel_reg = WCD934X_CDC_TX2_TX_PATH_CFG0; |
| 5780 | else if (e->shift_l == 2) |
| 5781 | mic_sel_reg = WCD934X_CDC_TX6_TX_PATH_CFG0; |
| 5782 | break; |
| 5783 | case WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1: |
| 5784 | if (e->shift_l == 0) |
| 5785 | mic_sel_reg = WCD934X_CDC_TX3_TX_PATH_CFG0; |
| 5786 | else if (e->shift_l == 2) |
| 5787 | mic_sel_reg = WCD934X_CDC_TX7_TX_PATH_CFG0; |
| 5788 | break; |
| 5789 | default: |
| 5790 | dev_err(codec->dev, "%s: e->reg: 0x%x not expected\n", |
| 5791 | __func__, e->reg); |
| 5792 | return -EINVAL; |
| 5793 | } |
| 5794 | |
| 5795 | /* ADC: 0, DMIC: 1 */ |
| 5796 | mic_sel = val ? 0x0 : 0x1; |
| 5797 | if (mic_sel_reg) |
| 5798 | snd_soc_update_bits(codec, mic_sel_reg, 1 << 7, mic_sel << 7); |
| 5799 | |
| 5800 | return snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 5801 | } |
| 5802 | |
| 5803 | static int tavil_int_dem_inp_mux_put(struct snd_kcontrol *kcontrol, |
| 5804 | struct snd_ctl_elem_value *ucontrol) |
| 5805 | { |
| 5806 | struct snd_soc_dapm_widget_list *wlist = |
| 5807 | dapm_kcontrol_get_wlist(kcontrol); |
| 5808 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 5809 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm); |
| 5810 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 5811 | unsigned int val; |
| 5812 | unsigned short look_ahead_dly_reg = WCD934X_CDC_RX0_RX_PATH_CFG0; |
| 5813 | |
| 5814 | val = ucontrol->value.enumerated.item[0]; |
| 5815 | if (val >= e->items) |
| 5816 | return -EINVAL; |
| 5817 | |
| 5818 | dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__, |
| 5819 | widget->name, val); |
| 5820 | |
| 5821 | if (e->reg == WCD934X_CDC_RX0_RX_PATH_SEC0) |
| 5822 | look_ahead_dly_reg = WCD934X_CDC_RX0_RX_PATH_CFG0; |
| 5823 | else if (e->reg == WCD934X_CDC_RX1_RX_PATH_SEC0) |
| 5824 | look_ahead_dly_reg = WCD934X_CDC_RX1_RX_PATH_CFG0; |
| 5825 | else if (e->reg == WCD934X_CDC_RX2_RX_PATH_SEC0) |
| 5826 | look_ahead_dly_reg = WCD934X_CDC_RX2_RX_PATH_CFG0; |
| 5827 | |
| 5828 | /* Set Look Ahead Delay */ |
| 5829 | snd_soc_update_bits(codec, look_ahead_dly_reg, |
| 5830 | 0x08, (val ? 0x08 : 0x00)); |
| 5831 | /* Set DEM INP Select */ |
| 5832 | return snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 5833 | } |
| 5834 | |
| 5835 | static const char * const rx_int0_7_mix_mux_text[] = { |
| 5836 | "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5", |
| 5837 | "RX6", "RX7", "PROXIMITY" |
| 5838 | }; |
| 5839 | |
| 5840 | static const char * const rx_int_mix_mux_text[] = { |
| 5841 | "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5", |
| 5842 | "RX6", "RX7" |
| 5843 | }; |
| 5844 | |
| 5845 | static const char * const rx_prim_mix_text[] = { |
| 5846 | "ZERO", "DEC0", "DEC1", "IIR0", "IIR1", "RX0", "RX1", "RX2", |
| 5847 | "RX3", "RX4", "RX5", "RX6", "RX7" |
| 5848 | }; |
| 5849 | |
| 5850 | static const char * const rx_sidetone_mix_text[] = { |
| 5851 | "ZERO", "SRC0", "SRC1", "SRC_SUM" |
| 5852 | }; |
| 5853 | |
| 5854 | static const char * const cdc_if_tx0_mux_text[] = { |
| 5855 | "ZERO", "RX_MIX_TX0", "DEC0", "DEC0_192" |
| 5856 | }; |
| 5857 | static const char * const cdc_if_tx1_mux_text[] = { |
| 5858 | "ZERO", "RX_MIX_TX1", "DEC1", "DEC1_192" |
| 5859 | }; |
| 5860 | static const char * const cdc_if_tx2_mux_text[] = { |
| 5861 | "ZERO", "RX_MIX_TX2", "DEC2", "DEC2_192" |
| 5862 | }; |
| 5863 | static const char * const cdc_if_tx3_mux_text[] = { |
| 5864 | "ZERO", "RX_MIX_TX3", "DEC3", "DEC3_192" |
| 5865 | }; |
| 5866 | static const char * const cdc_if_tx4_mux_text[] = { |
| 5867 | "ZERO", "RX_MIX_TX4", "DEC4", "DEC4_192" |
| 5868 | }; |
| 5869 | static const char * const cdc_if_tx5_mux_text[] = { |
| 5870 | "ZERO", "RX_MIX_TX5", "DEC5", "DEC5_192" |
| 5871 | }; |
| 5872 | static const char * const cdc_if_tx6_mux_text[] = { |
| 5873 | "ZERO", "RX_MIX_TX6", "DEC6", "DEC6_192" |
| 5874 | }; |
| 5875 | static const char * const cdc_if_tx7_mux_text[] = { |
| 5876 | "ZERO", "RX_MIX_TX7", "DEC7", "DEC7_192" |
| 5877 | }; |
| 5878 | static const char * const cdc_if_tx8_mux_text[] = { |
| 5879 | "ZERO", "RX_MIX_TX8", "DEC8", "DEC8_192" |
| 5880 | }; |
| 5881 | static const char * const cdc_if_tx9_mux_text[] = { |
| 5882 | "ZERO", "DEC7", "DEC7_192" |
| 5883 | }; |
| 5884 | static const char * const cdc_if_tx10_mux_text[] = { |
| 5885 | "ZERO", "DEC6", "DEC6_192" |
| 5886 | }; |
| 5887 | static const char * const cdc_if_tx11_mux_text[] = { |
| 5888 | "DEC_0_5", "DEC_9_12", "MAD_AUDIO", "MAD_BRDCST" |
| 5889 | }; |
| 5890 | static const char * const cdc_if_tx11_inp1_mux_text[] = { |
| 5891 | "ZERO", "DEC0", "DEC1", "DEC2", "DEC3", "DEC4", |
| 5892 | "DEC5", "RX_MIX_TX5", "DEC9_10", "DEC11_12" |
| 5893 | }; |
| 5894 | static const char * const cdc_if_tx13_mux_text[] = { |
| 5895 | "CDC_DEC_5", "MAD_BRDCST" |
| 5896 | }; |
| 5897 | static const char * const cdc_if_tx13_inp1_mux_text[] = { |
| 5898 | "ZERO", "DEC5", "DEC5_192" |
| 5899 | }; |
| 5900 | |
| 5901 | static const char * const iir_inp_mux_text[] = { |
| 5902 | "ZERO", "DEC0", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", |
| 5903 | "DEC7", "DEC8", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7" |
| 5904 | }; |
| 5905 | |
| 5906 | static const char * const rx_int_dem_inp_mux_text[] = { |
| 5907 | "NORMAL_DSM_OUT", "CLSH_DSM_OUT", |
| 5908 | }; |
| 5909 | |
| 5910 | static const char * const rx_int0_1_interp_mux_text[] = { |
| 5911 | "ZERO", "RX INT0_1 MIX1", |
| 5912 | }; |
| 5913 | |
| 5914 | static const char * const rx_int1_1_interp_mux_text[] = { |
| 5915 | "ZERO", "RX INT1_1 MIX1", |
| 5916 | }; |
| 5917 | |
| 5918 | static const char * const rx_int2_1_interp_mux_text[] = { |
| 5919 | "ZERO", "RX INT2_1 MIX1", |
| 5920 | }; |
| 5921 | |
| 5922 | static const char * const rx_int3_1_interp_mux_text[] = { |
| 5923 | "ZERO", "RX INT3_1 MIX1", |
| 5924 | }; |
| 5925 | |
| 5926 | static const char * const rx_int4_1_interp_mux_text[] = { |
| 5927 | "ZERO", "RX INT4_1 MIX1", |
| 5928 | }; |
| 5929 | |
| 5930 | static const char * const rx_int7_1_interp_mux_text[] = { |
| 5931 | "ZERO", "RX INT7_1 MIX1", |
| 5932 | }; |
| 5933 | |
| 5934 | static const char * const rx_int8_1_interp_mux_text[] = { |
| 5935 | "ZERO", "RX INT8_1 MIX1", |
| 5936 | }; |
| 5937 | |
| 5938 | static const char * const rx_int0_2_interp_mux_text[] = { |
| 5939 | "ZERO", "RX INT0_2 MUX", |
| 5940 | }; |
| 5941 | |
| 5942 | static const char * const rx_int1_2_interp_mux_text[] = { |
| 5943 | "ZERO", "RX INT1_2 MUX", |
| 5944 | }; |
| 5945 | |
| 5946 | static const char * const rx_int2_2_interp_mux_text[] = { |
| 5947 | "ZERO", "RX INT2_2 MUX", |
| 5948 | }; |
| 5949 | |
| 5950 | static const char * const rx_int3_2_interp_mux_text[] = { |
| 5951 | "ZERO", "RX INT3_2 MUX", |
| 5952 | }; |
| 5953 | |
| 5954 | static const char * const rx_int4_2_interp_mux_text[] = { |
| 5955 | "ZERO", "RX INT4_2 MUX", |
| 5956 | }; |
| 5957 | |
| 5958 | static const char * const rx_int7_2_interp_mux_text[] = { |
| 5959 | "ZERO", "RX INT7_2 MUX", |
| 5960 | }; |
| 5961 | |
| 5962 | static const char * const rx_int8_2_interp_mux_text[] = { |
| 5963 | "ZERO", "RX INT8_2 MUX", |
| 5964 | }; |
| 5965 | |
| 5966 | static const char * const mad_sel_txt[] = { |
| 5967 | "SPE", "MSM" |
| 5968 | }; |
| 5969 | |
| 5970 | static const char * const mad_inp_mux_txt[] = { |
| 5971 | "MAD", "DEC1" |
| 5972 | }; |
| 5973 | |
| 5974 | static const char * const adc_mux_text[] = { |
| 5975 | "DMIC", "AMIC", "ANC_FB_TUNE1", "ANC_FB_TUNE2" |
| 5976 | }; |
| 5977 | |
| 5978 | static const char * const dmic_mux_text[] = { |
| 5979 | "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5" |
| 5980 | }; |
| 5981 | |
| 5982 | static const char * const amic_mux_text[] = { |
| 5983 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4" |
| 5984 | }; |
| 5985 | |
| 5986 | static const char * const amic4_5_sel_text[] = { |
| 5987 | "AMIC4", "AMIC5" |
| 5988 | }; |
| 5989 | |
| 5990 | static const char * const anc0_fb_mux_text[] = { |
| 5991 | "ZERO", "ANC_IN_HPHL", "ANC_IN_EAR", "ANC_IN_EAR_SPKR", |
| 5992 | "ANC_IN_LO1" |
| 5993 | }; |
| 5994 | |
| 5995 | static const char * const anc1_fb_mux_text[] = { |
| 5996 | "ZERO", "ANC_IN_HPHR", "ANC_IN_LO2" |
| 5997 | }; |
| 5998 | |
| 5999 | static const char * const rx_echo_mux_text[] = { |
| 6000 | "ZERO", "RX_MIX0", "RX_MIX1", "RX_MIX2", "RX_MIX3", "RX_MIX4", |
| 6001 | "RX_MIX5", "RX_MIX6", "RX_MIX7", "RX_MIX8" |
| 6002 | }; |
| 6003 | |
| 6004 | static const char *const slim_rx_mux_text[] = { |
| 6005 | "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB", "AIF4_PB" |
| 6006 | }; |
| 6007 | |
| 6008 | static const char *const cdc_if_rx0_mux_text[] = { |
| 6009 | "SLIM RX0", "I2S_0 RX0" |
| 6010 | }; |
| 6011 | static const char *const cdc_if_rx1_mux_text[] = { |
| 6012 | "SLIM RX1", "I2S_0 RX1" |
| 6013 | }; |
| 6014 | static const char *const cdc_if_rx2_mux_text[] = { |
| 6015 | "SLIM RX2", "I2S_0 RX2" |
| 6016 | }; |
| 6017 | static const char *const cdc_if_rx3_mux_text[] = { |
| 6018 | "SLIM RX3", "I2S_0 RX3" |
| 6019 | }; |
| 6020 | static const char *const cdc_if_rx4_mux_text[] = { |
| 6021 | "SLIM RX4", "I2S_0 RX4" |
| 6022 | }; |
| 6023 | static const char *const cdc_if_rx5_mux_text[] = { |
| 6024 | "SLIM RX5", "I2S_0 RX5" |
| 6025 | }; |
| 6026 | static const char *const cdc_if_rx6_mux_text[] = { |
| 6027 | "SLIM RX6", "I2S_0 RX6" |
| 6028 | }; |
| 6029 | static const char *const cdc_if_rx7_mux_text[] = { |
| 6030 | "SLIM RX7", "I2S_0 RX7" |
| 6031 | }; |
| 6032 | |
| 6033 | static const char * const asrc0_mux_text[] = { |
| 6034 | "ZERO", "ASRC_IN_HPHL", "ASRC_IN_LO1", |
| 6035 | }; |
| 6036 | |
| 6037 | static const char * const asrc1_mux_text[] = { |
| 6038 | "ZERO", "ASRC_IN_HPHR", "ASRC_IN_LO2", |
| 6039 | }; |
| 6040 | |
| 6041 | static const char * const asrc2_mux_text[] = { |
| 6042 | "ZERO", "ASRC_IN_SPKR1", |
| 6043 | }; |
| 6044 | |
| 6045 | static const char * const asrc3_mux_text[] = { |
| 6046 | "ZERO", "ASRC_IN_SPKR2", |
| 6047 | }; |
| 6048 | |
| 6049 | static const char * const native_mux_text[] = { |
| 6050 | "OFF", "ON", |
| 6051 | }; |
| 6052 | |
| 6053 | static const struct snd_kcontrol_new aif4_vi_mixer[] = { |
| 6054 | SOC_SINGLE_EXT("SPKR_VI_1", SND_SOC_NOPM, WCD934X_TX14, 1, 0, |
| 6055 | tavil_vi_feed_mixer_get, tavil_vi_feed_mixer_put), |
| 6056 | SOC_SINGLE_EXT("SPKR_VI_2", SND_SOC_NOPM, WCD934X_TX15, 1, 0, |
| 6057 | tavil_vi_feed_mixer_get, tavil_vi_feed_mixer_put), |
| 6058 | }; |
| 6059 | |
| 6060 | static const struct snd_kcontrol_new aif1_cap_mixer[] = { |
| 6061 | SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD934X_TX0, 1, 0, |
| 6062 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6063 | SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD934X_TX1, 1, 0, |
| 6064 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6065 | SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD934X_TX2, 1, 0, |
| 6066 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6067 | SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD934X_TX3, 1, 0, |
| 6068 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6069 | SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD934X_TX4, 1, 0, |
| 6070 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6071 | SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD934X_TX5, 1, 0, |
| 6072 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6073 | SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD934X_TX6, 1, 0, |
| 6074 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6075 | SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD934X_TX7, 1, 0, |
| 6076 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6077 | SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD934X_TX8, 1, 0, |
| 6078 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6079 | SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD934X_TX9, 1, 0, |
| 6080 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6081 | SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD934X_TX10, 1, 0, |
| 6082 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6083 | SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD934X_TX11, 1, 0, |
| 6084 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6085 | SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD934X_TX13, 1, 0, |
| 6086 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6087 | }; |
| 6088 | |
| 6089 | static const struct snd_kcontrol_new aif2_cap_mixer[] = { |
| 6090 | SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD934X_TX0, 1, 0, |
| 6091 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6092 | SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD934X_TX1, 1, 0, |
| 6093 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6094 | SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD934X_TX2, 1, 0, |
| 6095 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6096 | SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD934X_TX3, 1, 0, |
| 6097 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6098 | SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD934X_TX4, 1, 0, |
| 6099 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6100 | SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD934X_TX5, 1, 0, |
| 6101 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6102 | SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD934X_TX6, 1, 0, |
| 6103 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6104 | SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD934X_TX7, 1, 0, |
| 6105 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6106 | SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD934X_TX8, 1, 0, |
| 6107 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6108 | SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD934X_TX9, 1, 0, |
| 6109 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6110 | SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD934X_TX10, 1, 0, |
| 6111 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6112 | SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD934X_TX11, 1, 0, |
| 6113 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6114 | SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD934X_TX13, 1, 0, |
| 6115 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6116 | }; |
| 6117 | |
| 6118 | static const struct snd_kcontrol_new aif3_cap_mixer[] = { |
| 6119 | SOC_SINGLE_EXT("SLIM TX0", SND_SOC_NOPM, WCD934X_TX0, 1, 0, |
| 6120 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6121 | SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, WCD934X_TX1, 1, 0, |
| 6122 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6123 | SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, WCD934X_TX2, 1, 0, |
| 6124 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6125 | SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, WCD934X_TX3, 1, 0, |
| 6126 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6127 | SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, WCD934X_TX4, 1, 0, |
| 6128 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6129 | SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, WCD934X_TX5, 1, 0, |
| 6130 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6131 | SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, WCD934X_TX6, 1, 0, |
| 6132 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6133 | SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, WCD934X_TX7, 1, 0, |
| 6134 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6135 | SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, WCD934X_TX8, 1, 0, |
| 6136 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6137 | SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, WCD934X_TX9, 1, 0, |
| 6138 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6139 | SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, WCD934X_TX10, 1, 0, |
| 6140 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6141 | SOC_SINGLE_EXT("SLIM TX11", SND_SOC_NOPM, WCD934X_TX11, 1, 0, |
| 6142 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6143 | SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD934X_TX13, 1, 0, |
| 6144 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6145 | }; |
| 6146 | |
| 6147 | static const struct snd_kcontrol_new aif4_mad_mixer[] = { |
| 6148 | SOC_SINGLE_EXT("SLIM TX13", SND_SOC_NOPM, WCD934X_TX13, 1, 0, |
| 6149 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 6150 | }; |
| 6151 | |
| 6152 | WCD_DAPM_ENUM_EXT(slim_rx0, SND_SOC_NOPM, 0, slim_rx_mux_text, |
| 6153 | slim_rx_mux_get, slim_rx_mux_put); |
| 6154 | WCD_DAPM_ENUM_EXT(slim_rx1, SND_SOC_NOPM, 0, slim_rx_mux_text, |
| 6155 | slim_rx_mux_get, slim_rx_mux_put); |
| 6156 | WCD_DAPM_ENUM_EXT(slim_rx2, SND_SOC_NOPM, 0, slim_rx_mux_text, |
| 6157 | slim_rx_mux_get, slim_rx_mux_put); |
| 6158 | WCD_DAPM_ENUM_EXT(slim_rx3, SND_SOC_NOPM, 0, slim_rx_mux_text, |
| 6159 | slim_rx_mux_get, slim_rx_mux_put); |
| 6160 | WCD_DAPM_ENUM_EXT(slim_rx4, SND_SOC_NOPM, 0, slim_rx_mux_text, |
| 6161 | slim_rx_mux_get, slim_rx_mux_put); |
| 6162 | WCD_DAPM_ENUM_EXT(slim_rx5, SND_SOC_NOPM, 0, slim_rx_mux_text, |
| 6163 | slim_rx_mux_get, slim_rx_mux_put); |
| 6164 | WCD_DAPM_ENUM_EXT(slim_rx6, SND_SOC_NOPM, 0, slim_rx_mux_text, |
| 6165 | slim_rx_mux_get, slim_rx_mux_put); |
| 6166 | WCD_DAPM_ENUM_EXT(slim_rx7, SND_SOC_NOPM, 0, slim_rx_mux_text, |
| 6167 | slim_rx_mux_get, slim_rx_mux_put); |
| 6168 | |
| 6169 | WCD_DAPM_ENUM(cdc_if_rx0, SND_SOC_NOPM, 0, cdc_if_rx0_mux_text); |
| 6170 | WCD_DAPM_ENUM(cdc_if_rx1, SND_SOC_NOPM, 0, cdc_if_rx1_mux_text); |
| 6171 | WCD_DAPM_ENUM(cdc_if_rx2, SND_SOC_NOPM, 0, cdc_if_rx2_mux_text); |
| 6172 | WCD_DAPM_ENUM(cdc_if_rx3, SND_SOC_NOPM, 0, cdc_if_rx3_mux_text); |
| 6173 | WCD_DAPM_ENUM(cdc_if_rx4, SND_SOC_NOPM, 0, cdc_if_rx4_mux_text); |
| 6174 | WCD_DAPM_ENUM(cdc_if_rx5, SND_SOC_NOPM, 0, cdc_if_rx5_mux_text); |
| 6175 | WCD_DAPM_ENUM(cdc_if_rx6, SND_SOC_NOPM, 0, cdc_if_rx6_mux_text); |
| 6176 | WCD_DAPM_ENUM(cdc_if_rx7, SND_SOC_NOPM, 0, cdc_if_rx7_mux_text); |
| 6177 | |
| 6178 | WCD_DAPM_ENUM(rx_int0_2, WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG1, 0, |
| 6179 | rx_int0_7_mix_mux_text); |
| 6180 | WCD_DAPM_ENUM(rx_int1_2, WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG1, 0, |
| 6181 | rx_int_mix_mux_text); |
| 6182 | WCD_DAPM_ENUM(rx_int2_2, WCD934X_CDC_RX_INP_MUX_RX_INT2_CFG1, 0, |
| 6183 | rx_int_mix_mux_text); |
| 6184 | WCD_DAPM_ENUM(rx_int3_2, WCD934X_CDC_RX_INP_MUX_RX_INT3_CFG1, 0, |
| 6185 | rx_int_mix_mux_text); |
| 6186 | WCD_DAPM_ENUM(rx_int4_2, WCD934X_CDC_RX_INP_MUX_RX_INT4_CFG1, 0, |
| 6187 | rx_int_mix_mux_text); |
| 6188 | WCD_DAPM_ENUM(rx_int7_2, WCD934X_CDC_RX_INP_MUX_RX_INT7_CFG1, 0, |
| 6189 | rx_int0_7_mix_mux_text); |
| 6190 | WCD_DAPM_ENUM(rx_int8_2, WCD934X_CDC_RX_INP_MUX_RX_INT8_CFG1, 0, |
| 6191 | rx_int_mix_mux_text); |
| 6192 | |
| 6193 | WCD_DAPM_ENUM(rx_int0_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG0, 0, |
| 6194 | rx_prim_mix_text); |
| 6195 | WCD_DAPM_ENUM(rx_int0_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG0, 4, |
| 6196 | rx_prim_mix_text); |
| 6197 | WCD_DAPM_ENUM(rx_int0_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG1, 4, |
| 6198 | rx_prim_mix_text); |
| 6199 | WCD_DAPM_ENUM(rx_int1_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG0, 0, |
| 6200 | rx_prim_mix_text); |
| 6201 | WCD_DAPM_ENUM(rx_int1_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG0, 4, |
| 6202 | rx_prim_mix_text); |
| 6203 | WCD_DAPM_ENUM(rx_int1_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT1_CFG1, 4, |
| 6204 | rx_prim_mix_text); |
| 6205 | WCD_DAPM_ENUM(rx_int2_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT2_CFG0, 0, |
| 6206 | rx_prim_mix_text); |
| 6207 | WCD_DAPM_ENUM(rx_int2_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT2_CFG0, 4, |
| 6208 | rx_prim_mix_text); |
| 6209 | WCD_DAPM_ENUM(rx_int2_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT2_CFG1, 4, |
| 6210 | rx_prim_mix_text); |
| 6211 | WCD_DAPM_ENUM(rx_int3_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT3_CFG0, 0, |
| 6212 | rx_prim_mix_text); |
| 6213 | WCD_DAPM_ENUM(rx_int3_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT3_CFG0, 4, |
| 6214 | rx_prim_mix_text); |
| 6215 | WCD_DAPM_ENUM(rx_int3_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT3_CFG1, 4, |
| 6216 | rx_prim_mix_text); |
| 6217 | WCD_DAPM_ENUM(rx_int4_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT4_CFG0, 0, |
| 6218 | rx_prim_mix_text); |
| 6219 | WCD_DAPM_ENUM(rx_int4_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT4_CFG0, 4, |
| 6220 | rx_prim_mix_text); |
| 6221 | WCD_DAPM_ENUM(rx_int4_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT4_CFG1, 4, |
| 6222 | rx_prim_mix_text); |
| 6223 | WCD_DAPM_ENUM(rx_int7_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT7_CFG0, 0, |
| 6224 | rx_prim_mix_text); |
| 6225 | WCD_DAPM_ENUM(rx_int7_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT7_CFG0, 4, |
| 6226 | rx_prim_mix_text); |
| 6227 | WCD_DAPM_ENUM(rx_int7_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT7_CFG1, 4, |
| 6228 | rx_prim_mix_text); |
| 6229 | WCD_DAPM_ENUM(rx_int8_1_mix_inp0, WCD934X_CDC_RX_INP_MUX_RX_INT8_CFG0, 0, |
| 6230 | rx_prim_mix_text); |
| 6231 | WCD_DAPM_ENUM(rx_int8_1_mix_inp1, WCD934X_CDC_RX_INP_MUX_RX_INT8_CFG0, 4, |
| 6232 | rx_prim_mix_text); |
| 6233 | WCD_DAPM_ENUM(rx_int8_1_mix_inp2, WCD934X_CDC_RX_INP_MUX_RX_INT8_CFG1, 4, |
| 6234 | rx_prim_mix_text); |
| 6235 | |
| 6236 | WCD_DAPM_ENUM(rx_int0_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 0, |
| 6237 | rx_sidetone_mix_text); |
| 6238 | WCD_DAPM_ENUM(rx_int1_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 2, |
| 6239 | rx_sidetone_mix_text); |
| 6240 | WCD_DAPM_ENUM(rx_int2_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 4, |
| 6241 | rx_sidetone_mix_text); |
| 6242 | WCD_DAPM_ENUM(rx_int3_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 6, |
| 6243 | rx_sidetone_mix_text); |
| 6244 | WCD_DAPM_ENUM(rx_int4_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG1, 0, |
| 6245 | rx_sidetone_mix_text); |
| 6246 | WCD_DAPM_ENUM(rx_int7_mix2_inp, WCD934X_CDC_RX_INP_MUX_SIDETONE_SRC_CFG1, 2, |
| 6247 | rx_sidetone_mix_text); |
| 6248 | |
| 6249 | WCD_DAPM_ENUM(tx_adc_mux10, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 4, |
| 6250 | adc_mux_text); |
| 6251 | WCD_DAPM_ENUM(tx_adc_mux11, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 4, |
| 6252 | adc_mux_text); |
| 6253 | WCD_DAPM_ENUM(tx_adc_mux12, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1, 4, |
| 6254 | adc_mux_text); |
| 6255 | WCD_DAPM_ENUM(tx_adc_mux13, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 6, |
| 6256 | adc_mux_text); |
| 6257 | |
| 6258 | |
| 6259 | WCD_DAPM_ENUM(tx_dmic_mux0, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0, 3, |
| 6260 | dmic_mux_text); |
| 6261 | WCD_DAPM_ENUM(tx_dmic_mux1, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG0, 3, |
| 6262 | dmic_mux_text); |
| 6263 | WCD_DAPM_ENUM(tx_dmic_mux2, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG0, 3, |
| 6264 | dmic_mux_text); |
| 6265 | WCD_DAPM_ENUM(tx_dmic_mux3, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG0, 3, |
| 6266 | dmic_mux_text); |
| 6267 | WCD_DAPM_ENUM(tx_dmic_mux4, WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0, 3, |
| 6268 | dmic_mux_text); |
| 6269 | WCD_DAPM_ENUM(tx_dmic_mux5, WCD934X_CDC_TX_INP_MUX_ADC_MUX5_CFG0, 3, |
| 6270 | dmic_mux_text); |
| 6271 | WCD_DAPM_ENUM(tx_dmic_mux6, WCD934X_CDC_TX_INP_MUX_ADC_MUX6_CFG0, 3, |
| 6272 | dmic_mux_text); |
| 6273 | WCD_DAPM_ENUM(tx_dmic_mux7, WCD934X_CDC_TX_INP_MUX_ADC_MUX7_CFG0, 3, |
| 6274 | dmic_mux_text); |
| 6275 | WCD_DAPM_ENUM(tx_dmic_mux8, WCD934X_CDC_TX_INP_MUX_ADC_MUX8_CFG0, 3, |
| 6276 | dmic_mux_text); |
| 6277 | WCD_DAPM_ENUM(tx_dmic_mux10, WCD934X_CDC_TX_INP_MUX_ADC_MUX10_CFG0, 3, |
| 6278 | dmic_mux_text); |
| 6279 | WCD_DAPM_ENUM(tx_dmic_mux11, WCD934X_CDC_TX_INP_MUX_ADC_MUX11_CFG0, 3, |
| 6280 | dmic_mux_text); |
| 6281 | WCD_DAPM_ENUM(tx_dmic_mux12, WCD934X_CDC_TX_INP_MUX_ADC_MUX12_CFG0, 3, |
| 6282 | dmic_mux_text); |
| 6283 | WCD_DAPM_ENUM(tx_dmic_mux13, WCD934X_CDC_TX_INP_MUX_ADC_MUX13_CFG0, 3, |
| 6284 | dmic_mux_text); |
| 6285 | |
| 6286 | |
| 6287 | WCD_DAPM_ENUM(tx_amic_mux0, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG0, 0, |
| 6288 | amic_mux_text); |
| 6289 | WCD_DAPM_ENUM(tx_amic_mux1, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG0, 0, |
| 6290 | amic_mux_text); |
| 6291 | WCD_DAPM_ENUM(tx_amic_mux2, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG0, 0, |
| 6292 | amic_mux_text); |
| 6293 | WCD_DAPM_ENUM(tx_amic_mux3, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG0, 0, |
| 6294 | amic_mux_text); |
| 6295 | WCD_DAPM_ENUM(tx_amic_mux4, WCD934X_CDC_TX_INP_MUX_ADC_MUX4_CFG0, 0, |
| 6296 | amic_mux_text); |
| 6297 | WCD_DAPM_ENUM(tx_amic_mux5, WCD934X_CDC_TX_INP_MUX_ADC_MUX5_CFG0, 0, |
| 6298 | amic_mux_text); |
| 6299 | WCD_DAPM_ENUM(tx_amic_mux6, WCD934X_CDC_TX_INP_MUX_ADC_MUX6_CFG0, 0, |
| 6300 | amic_mux_text); |
| 6301 | WCD_DAPM_ENUM(tx_amic_mux7, WCD934X_CDC_TX_INP_MUX_ADC_MUX7_CFG0, 0, |
| 6302 | amic_mux_text); |
| 6303 | WCD_DAPM_ENUM(tx_amic_mux8, WCD934X_CDC_TX_INP_MUX_ADC_MUX8_CFG0, 0, |
| 6304 | amic_mux_text); |
| 6305 | WCD_DAPM_ENUM(tx_amic_mux10, WCD934X_CDC_TX_INP_MUX_ADC_MUX10_CFG0, 0, |
| 6306 | amic_mux_text); |
| 6307 | WCD_DAPM_ENUM(tx_amic_mux11, WCD934X_CDC_TX_INP_MUX_ADC_MUX11_CFG0, 0, |
| 6308 | amic_mux_text); |
| 6309 | WCD_DAPM_ENUM(tx_amic_mux12, WCD934X_CDC_TX_INP_MUX_ADC_MUX12_CFG0, 0, |
| 6310 | amic_mux_text); |
| 6311 | WCD_DAPM_ENUM(tx_amic_mux13, WCD934X_CDC_TX_INP_MUX_ADC_MUX13_CFG0, 0, |
| 6312 | amic_mux_text); |
| 6313 | |
| 6314 | WCD_DAPM_ENUM(tx_amic4_5, WCD934X_TX_NEW_AMIC_4_5_SEL, 7, amic4_5_sel_text); |
| 6315 | |
| 6316 | WCD_DAPM_ENUM(cdc_if_tx0, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0, 0, |
| 6317 | cdc_if_tx0_mux_text); |
| 6318 | WCD_DAPM_ENUM(cdc_if_tx1, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0, 2, |
| 6319 | cdc_if_tx1_mux_text); |
| 6320 | WCD_DAPM_ENUM(cdc_if_tx2, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0, 4, |
| 6321 | cdc_if_tx2_mux_text); |
| 6322 | WCD_DAPM_ENUM(cdc_if_tx3, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0, 6, |
| 6323 | cdc_if_tx3_mux_text); |
| 6324 | WCD_DAPM_ENUM(cdc_if_tx4, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1, 0, |
| 6325 | cdc_if_tx4_mux_text); |
| 6326 | WCD_DAPM_ENUM(cdc_if_tx5, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1, 2, |
| 6327 | cdc_if_tx5_mux_text); |
| 6328 | WCD_DAPM_ENUM(cdc_if_tx6, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1, 4, |
| 6329 | cdc_if_tx6_mux_text); |
| 6330 | WCD_DAPM_ENUM(cdc_if_tx7, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1, 6, |
| 6331 | cdc_if_tx7_mux_text); |
| 6332 | WCD_DAPM_ENUM(cdc_if_tx8, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG2, 0, |
| 6333 | cdc_if_tx8_mux_text); |
| 6334 | WCD_DAPM_ENUM(cdc_if_tx9, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG2, 2, |
| 6335 | cdc_if_tx9_mux_text); |
| 6336 | WCD_DAPM_ENUM(cdc_if_tx10, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG2, 4, |
| 6337 | cdc_if_tx10_mux_text); |
| 6338 | WCD_DAPM_ENUM(cdc_if_tx11_inp1, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG3, 0, |
| 6339 | cdc_if_tx11_inp1_mux_text); |
| 6340 | WCD_DAPM_ENUM(cdc_if_tx11, WCD934X_DATA_HUB_SB_TX11_INP_CFG, 0, |
| 6341 | cdc_if_tx11_mux_text); |
| 6342 | WCD_DAPM_ENUM(cdc_if_tx13_inp1, WCD934X_CDC_IF_ROUTER_TX_MUX_CFG3, 4, |
| 6343 | cdc_if_tx13_inp1_mux_text); |
| 6344 | WCD_DAPM_ENUM(cdc_if_tx13, WCD934X_DATA_HUB_SB_TX13_INP_CFG, 0, |
| 6345 | cdc_if_tx13_mux_text); |
| 6346 | |
| 6347 | WCD_DAPM_ENUM(rx_mix_tx0, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG0, 0, |
| 6348 | rx_echo_mux_text); |
| 6349 | WCD_DAPM_ENUM(rx_mix_tx1, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG0, 4, |
| 6350 | rx_echo_mux_text); |
| 6351 | WCD_DAPM_ENUM(rx_mix_tx2, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG1, 0, |
| 6352 | rx_echo_mux_text); |
| 6353 | WCD_DAPM_ENUM(rx_mix_tx3, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG1, 4, |
| 6354 | rx_echo_mux_text); |
| 6355 | WCD_DAPM_ENUM(rx_mix_tx4, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG2, 0, |
| 6356 | rx_echo_mux_text); |
| 6357 | WCD_DAPM_ENUM(rx_mix_tx5, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG2, 4, |
| 6358 | rx_echo_mux_text); |
| 6359 | WCD_DAPM_ENUM(rx_mix_tx6, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG3, 0, |
| 6360 | rx_echo_mux_text); |
| 6361 | WCD_DAPM_ENUM(rx_mix_tx7, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG3, 4, |
| 6362 | rx_echo_mux_text); |
| 6363 | WCD_DAPM_ENUM(rx_mix_tx8, WCD934X_CDC_RX_INP_MUX_RX_MIX_CFG4, 0, |
| 6364 | rx_echo_mux_text); |
| 6365 | |
| 6366 | WCD_DAPM_ENUM(iir0_inp0, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG0, 0, |
| 6367 | iir_inp_mux_text); |
| 6368 | WCD_DAPM_ENUM(iir0_inp1, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG1, 0, |
| 6369 | iir_inp_mux_text); |
| 6370 | WCD_DAPM_ENUM(iir0_inp2, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG2, 0, |
| 6371 | iir_inp_mux_text); |
| 6372 | WCD_DAPM_ENUM(iir0_inp3, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR0_MIX_CFG3, 0, |
| 6373 | iir_inp_mux_text); |
| 6374 | WCD_DAPM_ENUM(iir1_inp0, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR1_MIX_CFG0, 0, |
| 6375 | iir_inp_mux_text); |
| 6376 | WCD_DAPM_ENUM(iir1_inp1, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR1_MIX_CFG1, 0, |
| 6377 | iir_inp_mux_text); |
| 6378 | WCD_DAPM_ENUM(iir1_inp2, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR1_MIX_CFG2, 0, |
| 6379 | iir_inp_mux_text); |
| 6380 | WCD_DAPM_ENUM(iir1_inp3, WCD934X_CDC_SIDETONE_IIR_INP_MUX_IIR1_MIX_CFG3, 0, |
| 6381 | iir_inp_mux_text); |
| 6382 | |
| 6383 | WCD_DAPM_ENUM(rx_int0_1_interp, SND_SOC_NOPM, 0, rx_int0_1_interp_mux_text); |
| 6384 | WCD_DAPM_ENUM(rx_int1_1_interp, SND_SOC_NOPM, 0, rx_int1_1_interp_mux_text); |
| 6385 | WCD_DAPM_ENUM(rx_int2_1_interp, SND_SOC_NOPM, 0, rx_int2_1_interp_mux_text); |
| 6386 | WCD_DAPM_ENUM(rx_int3_1_interp, SND_SOC_NOPM, 0, rx_int3_1_interp_mux_text); |
| 6387 | WCD_DAPM_ENUM(rx_int4_1_interp, SND_SOC_NOPM, 0, rx_int4_1_interp_mux_text); |
| 6388 | WCD_DAPM_ENUM(rx_int7_1_interp, SND_SOC_NOPM, 0, rx_int7_1_interp_mux_text); |
| 6389 | WCD_DAPM_ENUM(rx_int8_1_interp, SND_SOC_NOPM, 0, rx_int8_1_interp_mux_text); |
| 6390 | |
| 6391 | WCD_DAPM_ENUM(rx_int0_2_interp, SND_SOC_NOPM, 0, rx_int0_2_interp_mux_text); |
| 6392 | WCD_DAPM_ENUM(rx_int1_2_interp, SND_SOC_NOPM, 0, rx_int1_2_interp_mux_text); |
| 6393 | WCD_DAPM_ENUM(rx_int2_2_interp, SND_SOC_NOPM, 0, rx_int2_2_interp_mux_text); |
| 6394 | WCD_DAPM_ENUM(rx_int3_2_interp, SND_SOC_NOPM, 0, rx_int3_2_interp_mux_text); |
| 6395 | WCD_DAPM_ENUM(rx_int4_2_interp, SND_SOC_NOPM, 0, rx_int4_2_interp_mux_text); |
| 6396 | WCD_DAPM_ENUM(rx_int7_2_interp, SND_SOC_NOPM, 0, rx_int7_2_interp_mux_text); |
| 6397 | WCD_DAPM_ENUM(rx_int8_2_interp, SND_SOC_NOPM, 0, rx_int8_2_interp_mux_text); |
| 6398 | |
| 6399 | WCD_DAPM_ENUM(mad_sel, WCD934X_CPE_SS_SVA_CFG, 0, |
| 6400 | mad_sel_txt); |
| 6401 | |
| 6402 | WCD_DAPM_ENUM(mad_inp_mux, WCD934X_CPE_SS_SVA_CFG, 2, |
| 6403 | mad_inp_mux_txt); |
| 6404 | |
| 6405 | WCD_DAPM_ENUM_EXT(rx_int0_dem_inp, WCD934X_CDC_RX0_RX_PATH_SEC0, 0, |
| 6406 | rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double, |
| 6407 | tavil_int_dem_inp_mux_put); |
| 6408 | WCD_DAPM_ENUM_EXT(rx_int1_dem_inp, WCD934X_CDC_RX1_RX_PATH_SEC0, 0, |
| 6409 | rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double, |
| 6410 | tavil_int_dem_inp_mux_put); |
| 6411 | WCD_DAPM_ENUM_EXT(rx_int2_dem_inp, WCD934X_CDC_RX2_RX_PATH_SEC0, 0, |
| 6412 | rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double, |
| 6413 | tavil_int_dem_inp_mux_put); |
| 6414 | |
| 6415 | WCD_DAPM_ENUM_EXT(tx_adc_mux0, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 0, |
| 6416 | adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put); |
| 6417 | WCD_DAPM_ENUM_EXT(tx_adc_mux1, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 0, |
| 6418 | adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put); |
| 6419 | WCD_DAPM_ENUM_EXT(tx_adc_mux2, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 0, |
| 6420 | adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put); |
| 6421 | WCD_DAPM_ENUM_EXT(tx_adc_mux3, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1, 0, |
| 6422 | adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put); |
| 6423 | WCD_DAPM_ENUM_EXT(tx_adc_mux4, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 2, |
| 6424 | adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put); |
| 6425 | WCD_DAPM_ENUM_EXT(tx_adc_mux5, WCD934X_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 2, |
| 6426 | adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put); |
| 6427 | WCD_DAPM_ENUM_EXT(tx_adc_mux6, WCD934X_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 2, |
| 6428 | adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put); |
| 6429 | WCD_DAPM_ENUM_EXT(tx_adc_mux7, WCD934X_CDC_TX_INP_MUX_ADC_MUX3_CFG1, 2, |
| 6430 | adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put); |
| 6431 | WCD_DAPM_ENUM_EXT(tx_adc_mux8, WCD934X_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 4, |
| 6432 | adc_mux_text, snd_soc_dapm_get_enum_double, tavil_dec_enum_put); |
| 6433 | |
| 6434 | WCD_DAPM_ENUM(asrc0, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 0, |
| 6435 | asrc0_mux_text); |
| 6436 | WCD_DAPM_ENUM(asrc1, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 2, |
| 6437 | asrc1_mux_text); |
| 6438 | WCD_DAPM_ENUM(asrc2, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 4, |
| 6439 | asrc2_mux_text); |
| 6440 | WCD_DAPM_ENUM(asrc3, WCD934X_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 6, |
| 6441 | asrc3_mux_text); |
| 6442 | |
| 6443 | WCD_DAPM_ENUM(int1_1_native, SND_SOC_NOPM, 0, native_mux_text); |
| 6444 | WCD_DAPM_ENUM(int2_1_native, SND_SOC_NOPM, 0, native_mux_text); |
| 6445 | WCD_DAPM_ENUM(int3_1_native, SND_SOC_NOPM, 0, native_mux_text); |
| 6446 | WCD_DAPM_ENUM(int4_1_native, SND_SOC_NOPM, 0, native_mux_text); |
| 6447 | |
| 6448 | WCD_DAPM_ENUM(int1_2_native, SND_SOC_NOPM, 0, native_mux_text); |
| 6449 | WCD_DAPM_ENUM(int2_2_native, SND_SOC_NOPM, 0, native_mux_text); |
| 6450 | WCD_DAPM_ENUM(int3_2_native, SND_SOC_NOPM, 0, native_mux_text); |
| 6451 | WCD_DAPM_ENUM(int4_2_native, SND_SOC_NOPM, 0, native_mux_text); |
| 6452 | WCD_DAPM_ENUM(int7_2_native, SND_SOC_NOPM, 0, native_mux_text); |
| 6453 | WCD_DAPM_ENUM(int8_2_native, SND_SOC_NOPM, 0, native_mux_text); |
| 6454 | |
| 6455 | WCD_DAPM_ENUM(anc0_fb, WCD934X_CDC_RX_INP_MUX_ANC_CFG0, 0, anc0_fb_mux_text); |
| 6456 | WCD_DAPM_ENUM(anc1_fb, WCD934X_CDC_RX_INP_MUX_ANC_CFG0, 3, anc1_fb_mux_text); |
| 6457 | |
| 6458 | static const struct snd_kcontrol_new anc_ear_switch = |
| 6459 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6460 | |
| 6461 | static const struct snd_kcontrol_new anc_ear_spkr_switch = |
| 6462 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6463 | |
| 6464 | static const struct snd_kcontrol_new anc_spkr_pa_switch = |
| 6465 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6466 | |
| 6467 | static const struct snd_kcontrol_new mad_cpe1_switch = |
| 6468 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6469 | |
| 6470 | static const struct snd_kcontrol_new mad_cpe2_switch = |
| 6471 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6472 | |
| 6473 | static const struct snd_kcontrol_new mad_brdcst_switch = |
| 6474 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6475 | |
| 6476 | static const struct snd_kcontrol_new adc_us_mux0_switch = |
| 6477 | SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6478 | |
| 6479 | static const struct snd_kcontrol_new adc_us_mux1_switch = |
| 6480 | SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6481 | |
| 6482 | static const struct snd_kcontrol_new adc_us_mux2_switch = |
| 6483 | SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6484 | |
| 6485 | static const struct snd_kcontrol_new adc_us_mux3_switch = |
| 6486 | SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6487 | |
| 6488 | static const struct snd_kcontrol_new adc_us_mux4_switch = |
| 6489 | SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6490 | |
| 6491 | static const struct snd_kcontrol_new adc_us_mux5_switch = |
| 6492 | SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6493 | |
| 6494 | static const struct snd_kcontrol_new adc_us_mux6_switch = |
| 6495 | SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6496 | |
| 6497 | static const struct snd_kcontrol_new adc_us_mux7_switch = |
| 6498 | SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6499 | |
| 6500 | static const struct snd_kcontrol_new adc_us_mux8_switch = |
| 6501 | SOC_DAPM_SINGLE("US_Switch", SND_SOC_NOPM, 0, 1, 0); |
| 6502 | |
| 6503 | static const struct snd_kcontrol_new rx_int1_asrc_switch[] = { |
| 6504 | SOC_DAPM_SINGLE("HPHL Switch", SND_SOC_NOPM, 0, 1, 0), |
| 6505 | }; |
| 6506 | |
| 6507 | static const struct snd_kcontrol_new rx_int2_asrc_switch[] = { |
| 6508 | SOC_DAPM_SINGLE("HPHR Switch", SND_SOC_NOPM, 0, 1, 0), |
| 6509 | }; |
| 6510 | |
| 6511 | static const struct snd_kcontrol_new rx_int3_asrc_switch[] = { |
| 6512 | SOC_DAPM_SINGLE("LO1 Switch", SND_SOC_NOPM, 0, 1, 0), |
| 6513 | }; |
| 6514 | |
| 6515 | static const struct snd_kcontrol_new rx_int4_asrc_switch[] = { |
| 6516 | SOC_DAPM_SINGLE("LO2 Switch", SND_SOC_NOPM, 0, 1, 0), |
| 6517 | }; |
| 6518 | |
| 6519 | static int tavil_dsd_mixer_get(struct snd_kcontrol *kcontrol, |
| 6520 | struct snd_ctl_elem_value *ucontrol) |
| 6521 | { |
| 6522 | struct snd_soc_dapm_context *dapm = |
| 6523 | snd_soc_dapm_kcontrol_dapm(kcontrol); |
| 6524 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); |
| 6525 | struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec); |
| 6526 | struct soc_mixer_control *mc = |
| 6527 | (struct soc_mixer_control *)kcontrol->private_value; |
| 6528 | struct tavil_dsd_config *dsd_conf = tavil_p->dsd_config; |
| 6529 | int val; |
| 6530 | |
| 6531 | val = tavil_dsd_get_current_mixer_value(dsd_conf, mc->shift); |
| 6532 | |
| 6533 | ucontrol->value.integer.value[0] = ((val < 0) ? 0 : val); |
| 6534 | |
| 6535 | return 0; |
| 6536 | } |
| 6537 | |
| 6538 | static int tavil_dsd_mixer_put(struct snd_kcontrol *kcontrol, |
| 6539 | struct snd_ctl_elem_value *ucontrol) |
| 6540 | { |
| 6541 | struct soc_mixer_control *mc = |
| 6542 | (struct soc_mixer_control *)kcontrol->private_value; |
| 6543 | struct snd_soc_dapm_context *dapm = |
| 6544 | snd_soc_dapm_kcontrol_dapm(kcontrol); |
| 6545 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); |
| 6546 | struct tavil_priv *tavil_p = snd_soc_codec_get_drvdata(codec); |
| 6547 | unsigned int wval = ucontrol->value.integer.value[0]; |
| 6548 | struct tavil_dsd_config *dsd_conf = tavil_p->dsd_config; |
| 6549 | |
| 6550 | if (!dsd_conf) |
| 6551 | return 0; |
| 6552 | |
| 6553 | mutex_lock(&tavil_p->codec_mutex); |
| 6554 | |
| 6555 | tavil_dsd_set_out_select(dsd_conf, mc->shift); |
| 6556 | tavil_dsd_set_mixer_value(dsd_conf, mc->shift, wval); |
| 6557 | |
| 6558 | mutex_unlock(&tavil_p->codec_mutex); |
| 6559 | snd_soc_dapm_mixer_update_power(dapm, kcontrol, wval, NULL); |
| 6560 | |
| 6561 | return 0; |
| 6562 | } |
| 6563 | |
| 6564 | static const struct snd_kcontrol_new hphl_mixer[] = { |
| 6565 | SOC_SINGLE_EXT("DSD HPHL Switch", SND_SOC_NOPM, INTERP_HPHL, 1, 0, |
| 6566 | tavil_dsd_mixer_get, tavil_dsd_mixer_put), |
| 6567 | }; |
| 6568 | |
| 6569 | static const struct snd_kcontrol_new hphr_mixer[] = { |
| 6570 | SOC_SINGLE_EXT("DSD HPHR Switch", SND_SOC_NOPM, INTERP_HPHR, 1, 0, |
| 6571 | tavil_dsd_mixer_get, tavil_dsd_mixer_put), |
| 6572 | }; |
| 6573 | |
| 6574 | static const struct snd_soc_dapm_widget tavil_dapm_widgets[] = { |
| 6575 | SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM, |
| 6576 | AIF1_PB, 0, tavil_codec_enable_slimrx, |
| 6577 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 6578 | SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM, |
| 6579 | AIF2_PB, 0, tavil_codec_enable_slimrx, |
| 6580 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 6581 | SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM, |
| 6582 | AIF3_PB, 0, tavil_codec_enable_slimrx, |
| 6583 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 6584 | SND_SOC_DAPM_AIF_IN_E("AIF4 PB", "AIF4 Playback", 0, SND_SOC_NOPM, |
| 6585 | AIF4_PB, 0, tavil_codec_enable_slimrx, |
| 6586 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 6587 | |
| 6588 | WCD_DAPM_MUX("SLIM RX0 MUX", WCD934X_RX0, slim_rx0), |
| 6589 | WCD_DAPM_MUX("SLIM RX1 MUX", WCD934X_RX1, slim_rx1), |
| 6590 | WCD_DAPM_MUX("SLIM RX2 MUX", WCD934X_RX2, slim_rx2), |
| 6591 | WCD_DAPM_MUX("SLIM RX3 MUX", WCD934X_RX3, slim_rx3), |
| 6592 | WCD_DAPM_MUX("SLIM RX4 MUX", WCD934X_RX4, slim_rx4), |
| 6593 | WCD_DAPM_MUX("SLIM RX5 MUX", WCD934X_RX5, slim_rx5), |
| 6594 | WCD_DAPM_MUX("SLIM RX6 MUX", WCD934X_RX6, slim_rx6), |
| 6595 | WCD_DAPM_MUX("SLIM RX7 MUX", WCD934X_RX7, slim_rx7), |
| 6596 | |
| 6597 | SND_SOC_DAPM_MIXER("SLIM RX0", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6598 | SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6599 | SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6600 | SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6601 | SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6602 | SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6603 | SND_SOC_DAPM_MIXER("SLIM RX6", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6604 | SND_SOC_DAPM_MIXER("SLIM RX7", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6605 | |
| 6606 | WCD_DAPM_MUX("CDC_IF RX0 MUX", WCD934X_RX0, cdc_if_rx0), |
| 6607 | WCD_DAPM_MUX("CDC_IF RX1 MUX", WCD934X_RX1, cdc_if_rx1), |
| 6608 | WCD_DAPM_MUX("CDC_IF RX2 MUX", WCD934X_RX2, cdc_if_rx2), |
| 6609 | WCD_DAPM_MUX("CDC_IF RX3 MUX", WCD934X_RX3, cdc_if_rx3), |
| 6610 | WCD_DAPM_MUX("CDC_IF RX4 MUX", WCD934X_RX4, cdc_if_rx4), |
| 6611 | WCD_DAPM_MUX("CDC_IF RX5 MUX", WCD934X_RX5, cdc_if_rx5), |
| 6612 | WCD_DAPM_MUX("CDC_IF RX6 MUX", WCD934X_RX6, cdc_if_rx6), |
| 6613 | WCD_DAPM_MUX("CDC_IF RX7 MUX", WCD934X_RX7, cdc_if_rx7), |
| 6614 | |
| 6615 | SND_SOC_DAPM_MUX_E("RX INT0_2 MUX", SND_SOC_NOPM, INTERP_EAR, 0, |
| 6616 | &rx_int0_2_mux, tavil_codec_enable_mix_path, |
| 6617 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6618 | SND_SOC_DAPM_POST_PMD), |
| 6619 | SND_SOC_DAPM_MUX_E("RX INT1_2 MUX", SND_SOC_NOPM, INTERP_HPHL, 0, |
| 6620 | &rx_int1_2_mux, tavil_codec_enable_mix_path, |
| 6621 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6622 | SND_SOC_DAPM_POST_PMD), |
| 6623 | SND_SOC_DAPM_MUX_E("RX INT2_2 MUX", SND_SOC_NOPM, INTERP_HPHR, 0, |
| 6624 | &rx_int2_2_mux, tavil_codec_enable_mix_path, |
| 6625 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6626 | SND_SOC_DAPM_POST_PMD), |
| 6627 | SND_SOC_DAPM_MUX_E("RX INT3_2 MUX", SND_SOC_NOPM, INTERP_LO1, 0, |
| 6628 | &rx_int3_2_mux, tavil_codec_enable_mix_path, |
| 6629 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6630 | SND_SOC_DAPM_POST_PMD), |
| 6631 | SND_SOC_DAPM_MUX_E("RX INT4_2 MUX", SND_SOC_NOPM, INTERP_LO2, 0, |
| 6632 | &rx_int4_2_mux, tavil_codec_enable_mix_path, |
| 6633 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6634 | SND_SOC_DAPM_POST_PMD), |
| 6635 | SND_SOC_DAPM_MUX_E("RX INT7_2 MUX", SND_SOC_NOPM, INTERP_SPKR1, 0, |
| 6636 | &rx_int7_2_mux, tavil_codec_enable_mix_path, |
| 6637 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6638 | SND_SOC_DAPM_POST_PMD), |
| 6639 | SND_SOC_DAPM_MUX_E("RX INT8_2 MUX", SND_SOC_NOPM, INTERP_SPKR2, 0, |
| 6640 | &rx_int8_2_mux, tavil_codec_enable_mix_path, |
| 6641 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6642 | SND_SOC_DAPM_POST_PMD), |
| 6643 | |
| 6644 | WCD_DAPM_MUX("RX INT0_1 MIX1 INP0", 0, rx_int0_1_mix_inp0), |
| 6645 | WCD_DAPM_MUX("RX INT0_1 MIX1 INP1", 0, rx_int0_1_mix_inp1), |
| 6646 | WCD_DAPM_MUX("RX INT0_1 MIX1 INP2", 0, rx_int0_1_mix_inp2), |
| 6647 | WCD_DAPM_MUX("RX INT1_1 MIX1 INP0", 0, rx_int1_1_mix_inp0), |
| 6648 | WCD_DAPM_MUX("RX INT1_1 MIX1 INP1", 0, rx_int1_1_mix_inp1), |
| 6649 | WCD_DAPM_MUX("RX INT1_1 MIX1 INP2", 0, rx_int1_1_mix_inp2), |
| 6650 | WCD_DAPM_MUX("RX INT2_1 MIX1 INP0", 0, rx_int2_1_mix_inp0), |
| 6651 | WCD_DAPM_MUX("RX INT2_1 MIX1 INP1", 0, rx_int2_1_mix_inp1), |
| 6652 | WCD_DAPM_MUX("RX INT2_1 MIX1 INP2", 0, rx_int2_1_mix_inp2), |
| 6653 | WCD_DAPM_MUX("RX INT3_1 MIX1 INP0", 0, rx_int3_1_mix_inp0), |
| 6654 | WCD_DAPM_MUX("RX INT3_1 MIX1 INP1", 0, rx_int3_1_mix_inp1), |
| 6655 | WCD_DAPM_MUX("RX INT3_1 MIX1 INP2", 0, rx_int3_1_mix_inp2), |
| 6656 | WCD_DAPM_MUX("RX INT4_1 MIX1 INP0", 0, rx_int4_1_mix_inp0), |
| 6657 | WCD_DAPM_MUX("RX INT4_1 MIX1 INP1", 0, rx_int4_1_mix_inp1), |
| 6658 | WCD_DAPM_MUX("RX INT4_1 MIX1 INP2", 0, rx_int4_1_mix_inp2), |
| 6659 | |
| 6660 | SND_SOC_DAPM_MUX_E("RX INT7_1 MIX1 INP0", SND_SOC_NOPM, 0, 0, |
| 6661 | &rx_int7_1_mix_inp0_mux, tavil_codec_enable_swr, |
| 6662 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6663 | SND_SOC_DAPM_MUX_E("RX INT7_1 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 6664 | &rx_int7_1_mix_inp1_mux, tavil_codec_enable_swr, |
| 6665 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6666 | SND_SOC_DAPM_MUX_E("RX INT7_1 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 6667 | &rx_int7_1_mix_inp2_mux, tavil_codec_enable_swr, |
| 6668 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6669 | SND_SOC_DAPM_MUX_E("RX INT8_1 MIX1 INP0", SND_SOC_NOPM, 0, 0, |
| 6670 | &rx_int8_1_mix_inp0_mux, tavil_codec_enable_swr, |
| 6671 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6672 | SND_SOC_DAPM_MUX_E("RX INT8_1 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 6673 | &rx_int8_1_mix_inp1_mux, tavil_codec_enable_swr, |
| 6674 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6675 | SND_SOC_DAPM_MUX_E("RX INT8_1 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 6676 | &rx_int8_1_mix_inp2_mux, tavil_codec_enable_swr, |
| 6677 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6678 | |
| 6679 | SND_SOC_DAPM_MIXER("RX INT0_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6680 | SND_SOC_DAPM_MIXER("RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6681 | SND_SOC_DAPM_MIXER("RX INT1_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6682 | SND_SOC_DAPM_MIXER("RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0, |
| 6683 | rx_int1_asrc_switch, ARRAY_SIZE(rx_int1_asrc_switch)), |
| 6684 | SND_SOC_DAPM_MIXER("RX INT2_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6685 | SND_SOC_DAPM_MIXER("RX INT2 SEC MIX", SND_SOC_NOPM, 0, 0, |
| 6686 | rx_int2_asrc_switch, ARRAY_SIZE(rx_int2_asrc_switch)), |
| 6687 | SND_SOC_DAPM_MIXER("RX INT3_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6688 | SND_SOC_DAPM_MIXER("RX INT3 SEC MIX", SND_SOC_NOPM, 0, 0, |
| 6689 | rx_int3_asrc_switch, ARRAY_SIZE(rx_int3_asrc_switch)), |
| 6690 | SND_SOC_DAPM_MIXER("RX INT4_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6691 | SND_SOC_DAPM_MIXER("RX INT4 SEC MIX", SND_SOC_NOPM, 0, 0, |
| 6692 | rx_int4_asrc_switch, ARRAY_SIZE(rx_int4_asrc_switch)), |
| 6693 | SND_SOC_DAPM_MIXER("RX INT7_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6694 | SND_SOC_DAPM_MIXER("RX INT7 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6695 | SND_SOC_DAPM_MIXER("RX INT8_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6696 | SND_SOC_DAPM_MIXER("RX INT8 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6697 | |
| 6698 | SND_SOC_DAPM_MIXER("RX INT0 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6699 | SND_SOC_DAPM_MIXER("RX INT1 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6700 | SND_SOC_DAPM_MIXER("RX INT1 MIX3", SND_SOC_NOPM, 0, 0, hphl_mixer, |
| 6701 | ARRAY_SIZE(hphl_mixer)), |
| 6702 | SND_SOC_DAPM_MIXER("RX INT2 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6703 | SND_SOC_DAPM_MIXER("RX INT2 MIX3", SND_SOC_NOPM, 0, 0, hphr_mixer, |
| 6704 | ARRAY_SIZE(hphr_mixer)), |
| 6705 | SND_SOC_DAPM_MIXER("RX INT3 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6706 | SND_SOC_DAPM_MIXER("RX INT4 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6707 | SND_SOC_DAPM_MIXER("RX INT7 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6708 | SND_SOC_DAPM_MIXER_E("RX INT7 CHAIN", SND_SOC_NOPM, 0, 0, |
| 6709 | NULL, 0, tavil_codec_spk_boost_event, |
| 6710 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6711 | SND_SOC_DAPM_MIXER_E("RX INT8 CHAIN", SND_SOC_NOPM, 0, 0, |
| 6712 | NULL, 0, tavil_codec_spk_boost_event, |
| 6713 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6714 | |
| 6715 | SND_SOC_DAPM_MUX_E("RX INT0 MIX2 INP", SND_SOC_NOPM, INTERP_EAR, |
| 6716 | 0, &rx_int0_mix2_inp_mux, tavil_codec_enable_rx_path_clk, |
| 6717 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6718 | SND_SOC_DAPM_MUX_E("RX INT1 MIX2 INP", SND_SOC_NOPM, INTERP_HPHL, |
| 6719 | 0, &rx_int1_mix2_inp_mux, tavil_codec_enable_rx_path_clk, |
| 6720 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6721 | SND_SOC_DAPM_MUX_E("RX INT2 MIX2 INP", SND_SOC_NOPM, INTERP_HPHR, |
| 6722 | 0, &rx_int2_mix2_inp_mux, tavil_codec_enable_rx_path_clk, |
| 6723 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6724 | SND_SOC_DAPM_MUX_E("RX INT3 MIX2 INP", SND_SOC_NOPM, INTERP_LO1, |
| 6725 | 0, &rx_int3_mix2_inp_mux, tavil_codec_enable_rx_path_clk, |
| 6726 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6727 | SND_SOC_DAPM_MUX_E("RX INT4 MIX2 INP", SND_SOC_NOPM, INTERP_LO2, |
| 6728 | 0, &rx_int4_mix2_inp_mux, tavil_codec_enable_rx_path_clk, |
| 6729 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6730 | SND_SOC_DAPM_MUX_E("RX INT7 MIX2 INP", SND_SOC_NOPM, INTERP_SPKR1, |
| 6731 | 0, &rx_int7_mix2_inp_mux, tavil_codec_enable_rx_path_clk, |
| 6732 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6733 | |
| 6734 | WCD_DAPM_MUX("CDC_IF TX0 MUX", WCD934X_TX0, cdc_if_tx0), |
| 6735 | WCD_DAPM_MUX("CDC_IF TX1 MUX", WCD934X_TX1, cdc_if_tx1), |
| 6736 | WCD_DAPM_MUX("CDC_IF TX2 MUX", WCD934X_TX2, cdc_if_tx2), |
| 6737 | WCD_DAPM_MUX("CDC_IF TX3 MUX", WCD934X_TX3, cdc_if_tx3), |
| 6738 | WCD_DAPM_MUX("CDC_IF TX4 MUX", WCD934X_TX4, cdc_if_tx4), |
| 6739 | WCD_DAPM_MUX("CDC_IF TX5 MUX", WCD934X_TX5, cdc_if_tx5), |
| 6740 | WCD_DAPM_MUX("CDC_IF TX6 MUX", WCD934X_TX6, cdc_if_tx6), |
| 6741 | WCD_DAPM_MUX("CDC_IF TX7 MUX", WCD934X_TX7, cdc_if_tx7), |
| 6742 | WCD_DAPM_MUX("CDC_IF TX8 MUX", WCD934X_TX8, cdc_if_tx8), |
| 6743 | WCD_DAPM_MUX("CDC_IF TX9 MUX", WCD934X_TX9, cdc_if_tx9), |
| 6744 | WCD_DAPM_MUX("CDC_IF TX10 MUX", WCD934X_TX10, cdc_if_tx10), |
| 6745 | WCD_DAPM_MUX("CDC_IF TX11 MUX", WCD934X_TX11, cdc_if_tx11), |
| 6746 | WCD_DAPM_MUX("CDC_IF TX11 INP1 MUX", WCD934X_TX11, cdc_if_tx11_inp1), |
| 6747 | WCD_DAPM_MUX("CDC_IF TX13 MUX", WCD934X_TX13, cdc_if_tx13), |
| 6748 | WCD_DAPM_MUX("CDC_IF TX13 INP1 MUX", WCD934X_TX13, cdc_if_tx13_inp1), |
| 6749 | |
| 6750 | SND_SOC_DAPM_MUX_E("ADC MUX0", WCD934X_CDC_TX0_TX_PATH_CTL, 5, 0, |
| 6751 | &tx_adc_mux0_mux, tavil_codec_enable_dec, |
| 6752 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6753 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 6754 | |
| 6755 | SND_SOC_DAPM_MUX_E("ADC MUX1", WCD934X_CDC_TX1_TX_PATH_CTL, 5, 0, |
| 6756 | &tx_adc_mux1_mux, tavil_codec_enable_dec, |
| 6757 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6758 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 6759 | |
| 6760 | SND_SOC_DAPM_MUX_E("ADC MUX2", WCD934X_CDC_TX2_TX_PATH_CTL, 5, 0, |
| 6761 | &tx_adc_mux2_mux, tavil_codec_enable_dec, |
| 6762 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6763 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 6764 | |
| 6765 | SND_SOC_DAPM_MUX_E("ADC MUX3", WCD934X_CDC_TX3_TX_PATH_CTL, 5, 0, |
| 6766 | &tx_adc_mux3_mux, tavil_codec_enable_dec, |
| 6767 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6768 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 6769 | |
| 6770 | SND_SOC_DAPM_MUX_E("ADC MUX4", WCD934X_CDC_TX4_TX_PATH_CTL, 5, 0, |
| 6771 | &tx_adc_mux4_mux, tavil_codec_enable_dec, |
| 6772 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6773 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 6774 | |
| 6775 | SND_SOC_DAPM_MUX_E("ADC MUX5", WCD934X_CDC_TX5_TX_PATH_CTL, 5, 0, |
| 6776 | &tx_adc_mux5_mux, tavil_codec_enable_dec, |
| 6777 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6778 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 6779 | |
| 6780 | SND_SOC_DAPM_MUX_E("ADC MUX6", WCD934X_CDC_TX6_TX_PATH_CTL, 5, 0, |
| 6781 | &tx_adc_mux6_mux, tavil_codec_enable_dec, |
| 6782 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6783 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 6784 | |
| 6785 | SND_SOC_DAPM_MUX_E("ADC MUX7", WCD934X_CDC_TX7_TX_PATH_CTL, 5, 0, |
| 6786 | &tx_adc_mux7_mux, tavil_codec_enable_dec, |
| 6787 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6788 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 6789 | |
| 6790 | SND_SOC_DAPM_MUX_E("ADC MUX8", WCD934X_CDC_TX8_TX_PATH_CTL, 5, 0, |
| 6791 | &tx_adc_mux8_mux, tavil_codec_enable_dec, |
| 6792 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6793 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 6794 | |
| 6795 | SND_SOC_DAPM_MUX_E("ADC MUX10", SND_SOC_NOPM, 10, 0, &tx_adc_mux10_mux, |
| 6796 | tavil_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU), |
| 6797 | |
| 6798 | SND_SOC_DAPM_MUX_E("ADC MUX11", SND_SOC_NOPM, 11, 0, &tx_adc_mux11_mux, |
| 6799 | tavil_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU), |
| 6800 | |
| 6801 | SND_SOC_DAPM_MUX_E("ADC MUX12", SND_SOC_NOPM, 12, 0, &tx_adc_mux12_mux, |
| 6802 | tavil_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU), |
| 6803 | |
| 6804 | SND_SOC_DAPM_MUX_E("ADC MUX13", SND_SOC_NOPM, 13, 0, &tx_adc_mux13_mux, |
| 6805 | tavil_codec_tx_adc_cfg, SND_SOC_DAPM_POST_PMU), |
| 6806 | |
| 6807 | WCD_DAPM_MUX("DMIC MUX0", 0, tx_dmic_mux0), |
| 6808 | WCD_DAPM_MUX("DMIC MUX1", 0, tx_dmic_mux1), |
| 6809 | WCD_DAPM_MUX("DMIC MUX2", 0, tx_dmic_mux2), |
| 6810 | WCD_DAPM_MUX("DMIC MUX3", 0, tx_dmic_mux3), |
| 6811 | WCD_DAPM_MUX("DMIC MUX4", 0, tx_dmic_mux4), |
| 6812 | WCD_DAPM_MUX("DMIC MUX5", 0, tx_dmic_mux5), |
| 6813 | WCD_DAPM_MUX("DMIC MUX6", 0, tx_dmic_mux6), |
| 6814 | WCD_DAPM_MUX("DMIC MUX7", 0, tx_dmic_mux7), |
| 6815 | WCD_DAPM_MUX("DMIC MUX8", 0, tx_dmic_mux8), |
| 6816 | WCD_DAPM_MUX("DMIC MUX10", 0, tx_dmic_mux10), |
| 6817 | WCD_DAPM_MUX("DMIC MUX11", 0, tx_dmic_mux11), |
| 6818 | WCD_DAPM_MUX("DMIC MUX12", 0, tx_dmic_mux12), |
| 6819 | WCD_DAPM_MUX("DMIC MUX13", 0, tx_dmic_mux13), |
| 6820 | |
| 6821 | WCD_DAPM_MUX("AMIC MUX0", 0, tx_amic_mux0), |
| 6822 | WCD_DAPM_MUX("AMIC MUX1", 0, tx_amic_mux1), |
| 6823 | WCD_DAPM_MUX("AMIC MUX2", 0, tx_amic_mux2), |
| 6824 | WCD_DAPM_MUX("AMIC MUX3", 0, tx_amic_mux3), |
| 6825 | WCD_DAPM_MUX("AMIC MUX4", 0, tx_amic_mux4), |
| 6826 | WCD_DAPM_MUX("AMIC MUX5", 0, tx_amic_mux5), |
| 6827 | WCD_DAPM_MUX("AMIC MUX6", 0, tx_amic_mux6), |
| 6828 | WCD_DAPM_MUX("AMIC MUX7", 0, tx_amic_mux7), |
| 6829 | WCD_DAPM_MUX("AMIC MUX8", 0, tx_amic_mux8), |
| 6830 | WCD_DAPM_MUX("AMIC MUX10", 0, tx_amic_mux10), |
| 6831 | WCD_DAPM_MUX("AMIC MUX11", 0, tx_amic_mux11), |
| 6832 | WCD_DAPM_MUX("AMIC MUX12", 0, tx_amic_mux12), |
| 6833 | WCD_DAPM_MUX("AMIC MUX13", 0, tx_amic_mux13), |
| 6834 | |
| 6835 | SND_SOC_DAPM_ADC_E("ADC1", NULL, WCD934X_ANA_AMIC1, 7, 0, |
| 6836 | tavil_codec_enable_adc, SND_SOC_DAPM_PRE_PMU), |
| 6837 | SND_SOC_DAPM_ADC_E("ADC2", NULL, WCD934X_ANA_AMIC2, 7, 0, |
| 6838 | tavil_codec_enable_adc, SND_SOC_DAPM_PRE_PMU), |
| 6839 | SND_SOC_DAPM_ADC_E("ADC3", NULL, WCD934X_ANA_AMIC3, 7, 0, |
| 6840 | tavil_codec_enable_adc, SND_SOC_DAPM_PRE_PMU), |
| 6841 | SND_SOC_DAPM_ADC_E("ADC4", NULL, WCD934X_ANA_AMIC4, 7, 0, |
| 6842 | tavil_codec_enable_adc, SND_SOC_DAPM_PRE_PMU), |
| 6843 | |
| 6844 | WCD_DAPM_MUX("AMIC4_5 SEL", 0, tx_amic4_5), |
| 6845 | |
| 6846 | WCD_DAPM_MUX("ANC0 FB MUX", 0, anc0_fb), |
| 6847 | WCD_DAPM_MUX("ANC1 FB MUX", 0, anc1_fb), |
| 6848 | |
| 6849 | SND_SOC_DAPM_INPUT("AMIC1"), |
| 6850 | SND_SOC_DAPM_INPUT("AMIC2"), |
| 6851 | SND_SOC_DAPM_INPUT("AMIC3"), |
| 6852 | SND_SOC_DAPM_INPUT("AMIC4"), |
| 6853 | SND_SOC_DAPM_INPUT("AMIC5"), |
| 6854 | |
| 6855 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1", SND_SOC_NOPM, 0, 0, |
| 6856 | tavil_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 6857 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 6858 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2", SND_SOC_NOPM, 0, 0, |
| 6859 | tavil_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 6860 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 6861 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3", SND_SOC_NOPM, 0, 0, |
| 6862 | tavil_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 6863 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 6864 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS4", SND_SOC_NOPM, 0, 0, |
| 6865 | tavil_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 6866 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 6867 | |
| 6868 | /* |
| 6869 | * Not supply widget, this is used to recover HPH registers. |
| 6870 | * It is not connected to any other widgets |
| 6871 | */ |
| 6872 | SND_SOC_DAPM_SUPPLY("RESET_HPH_REGISTERS", SND_SOC_NOPM, |
| 6873 | 0, 0, tavil_codec_reset_hph_registers, |
| 6874 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6875 | |
| 6876 | SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS1_STANDALONE, SND_SOC_NOPM, 0, 0, |
| 6877 | tavil_codec_force_enable_micbias, |
| 6878 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6879 | SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS2_STANDALONE, SND_SOC_NOPM, 0, 0, |
| 6880 | tavil_codec_force_enable_micbias, |
| 6881 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6882 | SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS3_STANDALONE, SND_SOC_NOPM, 0, 0, |
| 6883 | tavil_codec_force_enable_micbias, |
| 6884 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6885 | SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS4_STANDALONE, SND_SOC_NOPM, 0, 0, |
| 6886 | tavil_codec_force_enable_micbias, |
| 6887 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6888 | |
| 6889 | SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM, |
| 6890 | AIF1_CAP, 0, tavil_codec_enable_slimtx, |
| 6891 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 6892 | SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM, |
| 6893 | AIF2_CAP, 0, tavil_codec_enable_slimtx, |
| 6894 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 6895 | SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM, |
| 6896 | AIF3_CAP, 0, tavil_codec_enable_slimtx, |
| 6897 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 6898 | SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0, |
| 6899 | aif1_cap_mixer, ARRAY_SIZE(aif1_cap_mixer)), |
| 6900 | SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0, |
| 6901 | aif2_cap_mixer, ARRAY_SIZE(aif2_cap_mixer)), |
| 6902 | SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0, |
| 6903 | aif3_cap_mixer, ARRAY_SIZE(aif3_cap_mixer)), |
| 6904 | SND_SOC_DAPM_MIXER("AIF4_MAD Mixer", SND_SOC_NOPM, AIF4_MAD_TX, 0, |
| 6905 | aif4_mad_mixer, ARRAY_SIZE(aif4_mad_mixer)), |
| 6906 | |
| 6907 | SND_SOC_DAPM_AIF_OUT_E("AIF4 VI", "VIfeed", 0, SND_SOC_NOPM, |
| 6908 | AIF4_VIFEED, 0, tavil_codec_enable_slimvi_feedback, |
| 6909 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 6910 | |
| 6911 | SND_SOC_DAPM_AIF_OUT("AIF4 MAD", "AIF4 MAD TX", 0, |
| 6912 | SND_SOC_NOPM, 0, 0), |
| 6913 | |
| 6914 | SND_SOC_DAPM_MIXER("AIF4_VI Mixer", SND_SOC_NOPM, AIF4_VIFEED, 0, |
| 6915 | aif4_vi_mixer, ARRAY_SIZE(aif4_vi_mixer)), |
| 6916 | SND_SOC_DAPM_INPUT("VIINPUT"), |
| 6917 | |
| 6918 | SND_SOC_DAPM_MIXER("SLIM TX0", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6919 | SND_SOC_DAPM_MIXER("SLIM TX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6920 | SND_SOC_DAPM_MIXER("SLIM TX2", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6921 | SND_SOC_DAPM_MIXER("SLIM TX3", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6922 | SND_SOC_DAPM_MIXER("SLIM TX4", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6923 | SND_SOC_DAPM_MIXER("SLIM TX5", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6924 | SND_SOC_DAPM_MIXER("SLIM TX6", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6925 | SND_SOC_DAPM_MIXER("SLIM TX7", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6926 | SND_SOC_DAPM_MIXER("SLIM TX8", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6927 | SND_SOC_DAPM_MIXER("SLIM TX9", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6928 | SND_SOC_DAPM_MIXER("SLIM TX10", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6929 | SND_SOC_DAPM_MIXER("SLIM TX11", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6930 | SND_SOC_DAPM_MIXER("SLIM TX13", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 6931 | |
| 6932 | /* Digital Mic Inputs */ |
| 6933 | SND_SOC_DAPM_ADC_E("DMIC0", NULL, SND_SOC_NOPM, 0, 0, |
| 6934 | tavil_codec_enable_dmic, |
| 6935 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6936 | SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0, |
| 6937 | tavil_codec_enable_dmic, |
| 6938 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6939 | SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0, |
| 6940 | tavil_codec_enable_dmic, |
| 6941 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6942 | SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0, |
| 6943 | tavil_codec_enable_dmic, |
| 6944 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6945 | SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0, |
| 6946 | tavil_codec_enable_dmic, |
| 6947 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6948 | SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0, |
| 6949 | tavil_codec_enable_dmic, |
| 6950 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 6951 | |
| 6952 | WCD_DAPM_MUX("IIR0 INP0 MUX", 0, iir0_inp0), |
| 6953 | WCD_DAPM_MUX("IIR0 INP1 MUX", 0, iir0_inp1), |
| 6954 | WCD_DAPM_MUX("IIR0 INP2 MUX", 0, iir0_inp2), |
| 6955 | WCD_DAPM_MUX("IIR0 INP3 MUX", 0, iir0_inp3), |
| 6956 | WCD_DAPM_MUX("IIR1 INP0 MUX", 0, iir1_inp0), |
| 6957 | WCD_DAPM_MUX("IIR1 INP1 MUX", 0, iir1_inp1), |
| 6958 | WCD_DAPM_MUX("IIR1 INP2 MUX", 0, iir1_inp2), |
| 6959 | WCD_DAPM_MUX("IIR1 INP3 MUX", 0, iir1_inp3), |
| 6960 | |
| 6961 | SND_SOC_DAPM_MIXER_E("IIR0", WCD934X_CDC_SIDETONE_IIR0_IIR_PATH_CTL, |
| 6962 | 4, 0, NULL, 0, tavil_codec_set_iir_gain, |
| 6963 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 6964 | SND_SOC_DAPM_MIXER_E("IIR1", WCD934X_CDC_SIDETONE_IIR1_IIR_PATH_CTL, |
| 6965 | 4, 0, NULL, 0, tavil_codec_set_iir_gain, |
| 6966 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 6967 | SND_SOC_DAPM_MIXER("SRC0", WCD934X_CDC_SIDETONE_SRC0_ST_SRC_PATH_CTL, |
| 6968 | 4, 0, NULL, 0), |
| 6969 | SND_SOC_DAPM_MIXER("SRC1", WCD934X_CDC_SIDETONE_SRC1_ST_SRC_PATH_CTL, |
| 6970 | 4, 0, NULL, 0), |
| 6971 | |
| 6972 | WCD_DAPM_MUX("RX MIX TX0 MUX", 0, rx_mix_tx0), |
| 6973 | WCD_DAPM_MUX("RX MIX TX1 MUX", 0, rx_mix_tx1), |
| 6974 | WCD_DAPM_MUX("RX MIX TX2 MUX", 0, rx_mix_tx2), |
| 6975 | WCD_DAPM_MUX("RX MIX TX3 MUX", 0, rx_mix_tx3), |
| 6976 | WCD_DAPM_MUX("RX MIX TX4 MUX", 0, rx_mix_tx4), |
| 6977 | WCD_DAPM_MUX("RX MIX TX5 MUX", 0, rx_mix_tx5), |
| 6978 | WCD_DAPM_MUX("RX MIX TX6 MUX", 0, rx_mix_tx6), |
| 6979 | WCD_DAPM_MUX("RX MIX TX7 MUX", 0, rx_mix_tx7), |
| 6980 | WCD_DAPM_MUX("RX MIX TX8 MUX", 0, rx_mix_tx8), |
| 6981 | WCD_DAPM_MUX("RX INT0 DEM MUX", 0, rx_int0_dem_inp), |
| 6982 | WCD_DAPM_MUX("RX INT1 DEM MUX", 0, rx_int1_dem_inp), |
| 6983 | WCD_DAPM_MUX("RX INT2 DEM MUX", 0, rx_int2_dem_inp), |
| 6984 | |
| 6985 | SND_SOC_DAPM_MUX_E("RX INT0_1 INTERP", SND_SOC_NOPM, INTERP_EAR, 0, |
| 6986 | &rx_int0_1_interp_mux, tavil_codec_enable_main_path, |
| 6987 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6988 | SND_SOC_DAPM_POST_PMD), |
| 6989 | SND_SOC_DAPM_MUX_E("RX INT1_1 INTERP", SND_SOC_NOPM, INTERP_HPHL, 0, |
| 6990 | &rx_int1_1_interp_mux, tavil_codec_enable_main_path, |
| 6991 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6992 | SND_SOC_DAPM_POST_PMD), |
| 6993 | SND_SOC_DAPM_MUX_E("RX INT2_1 INTERP", SND_SOC_NOPM, INTERP_HPHR, 0, |
| 6994 | &rx_int2_1_interp_mux, tavil_codec_enable_main_path, |
| 6995 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 6996 | SND_SOC_DAPM_POST_PMD), |
| 6997 | SND_SOC_DAPM_MUX_E("RX INT3_1 INTERP", SND_SOC_NOPM, INTERP_LO1, 0, |
| 6998 | &rx_int3_1_interp_mux, tavil_codec_enable_main_path, |
| 6999 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 7000 | SND_SOC_DAPM_POST_PMD), |
| 7001 | SND_SOC_DAPM_MUX_E("RX INT4_1 INTERP", SND_SOC_NOPM, INTERP_LO2, 0, |
| 7002 | &rx_int4_1_interp_mux, tavil_codec_enable_main_path, |
| 7003 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 7004 | SND_SOC_DAPM_POST_PMD), |
| 7005 | SND_SOC_DAPM_MUX_E("RX INT7_1 INTERP", SND_SOC_NOPM, INTERP_SPKR1, 0, |
| 7006 | &rx_int7_1_interp_mux, tavil_codec_enable_main_path, |
| 7007 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 7008 | SND_SOC_DAPM_POST_PMD), |
| 7009 | SND_SOC_DAPM_MUX_E("RX INT8_1 INTERP", SND_SOC_NOPM, INTERP_SPKR2, 0, |
| 7010 | &rx_int8_1_interp_mux, tavil_codec_enable_main_path, |
| 7011 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 7012 | SND_SOC_DAPM_POST_PMD), |
| 7013 | |
| 7014 | WCD_DAPM_MUX("RX INT0_2 INTERP", 0, rx_int0_2_interp), |
| 7015 | WCD_DAPM_MUX("RX INT1_2 INTERP", 0, rx_int1_2_interp), |
| 7016 | WCD_DAPM_MUX("RX INT2_2 INTERP", 0, rx_int2_2_interp), |
| 7017 | WCD_DAPM_MUX("RX INT3_2 INTERP", 0, rx_int3_2_interp), |
| 7018 | WCD_DAPM_MUX("RX INT4_2 INTERP", 0, rx_int4_2_interp), |
| 7019 | WCD_DAPM_MUX("RX INT7_2 INTERP", 0, rx_int7_2_interp), |
| 7020 | WCD_DAPM_MUX("RX INT8_2 INTERP", 0, rx_int8_2_interp), |
| 7021 | |
| 7022 | SND_SOC_DAPM_SWITCH("ADC US MUX0", WCD934X_CDC_TX0_TX_PATH_192_CTL, 0, |
| 7023 | 0, &adc_us_mux0_switch), |
| 7024 | SND_SOC_DAPM_SWITCH("ADC US MUX1", WCD934X_CDC_TX1_TX_PATH_192_CTL, 0, |
| 7025 | 0, &adc_us_mux1_switch), |
| 7026 | SND_SOC_DAPM_SWITCH("ADC US MUX2", WCD934X_CDC_TX2_TX_PATH_192_CTL, 0, |
| 7027 | 0, &adc_us_mux2_switch), |
| 7028 | SND_SOC_DAPM_SWITCH("ADC US MUX3", WCD934X_CDC_TX3_TX_PATH_192_CTL, 0, |
| 7029 | 0, &adc_us_mux3_switch), |
| 7030 | SND_SOC_DAPM_SWITCH("ADC US MUX4", WCD934X_CDC_TX4_TX_PATH_192_CTL, 0, |
| 7031 | 0, &adc_us_mux4_switch), |
| 7032 | SND_SOC_DAPM_SWITCH("ADC US MUX5", WCD934X_CDC_TX5_TX_PATH_192_CTL, 0, |
| 7033 | 0, &adc_us_mux5_switch), |
| 7034 | SND_SOC_DAPM_SWITCH("ADC US MUX6", WCD934X_CDC_TX6_TX_PATH_192_CTL, 0, |
| 7035 | 0, &adc_us_mux6_switch), |
| 7036 | SND_SOC_DAPM_SWITCH("ADC US MUX7", WCD934X_CDC_TX7_TX_PATH_192_CTL, 0, |
| 7037 | 0, &adc_us_mux7_switch), |
| 7038 | SND_SOC_DAPM_SWITCH("ADC US MUX8", WCD934X_CDC_TX8_TX_PATH_192_CTL, 0, |
| 7039 | 0, &adc_us_mux8_switch), |
| 7040 | |
| 7041 | /* MAD related widgets */ |
| 7042 | SND_SOC_DAPM_INPUT("MAD_CPE_INPUT"), |
| 7043 | SND_SOC_DAPM_INPUT("MADINPUT"), |
| 7044 | |
| 7045 | WCD_DAPM_MUX("MAD_SEL MUX", 0, mad_sel), |
| 7046 | WCD_DAPM_MUX("MAD_INP MUX", 0, mad_inp_mux), |
| 7047 | |
| 7048 | SND_SOC_DAPM_SWITCH_E("MAD_BROADCAST", SND_SOC_NOPM, 0, 0, |
| 7049 | &mad_brdcst_switch, tavil_codec_ape_enable_mad, |
| 7050 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 7051 | |
| 7052 | SND_SOC_DAPM_SWITCH_E("MAD_CPE1", SND_SOC_NOPM, 0, 0, |
| 7053 | &mad_cpe1_switch, tavil_codec_cpe_mad_ctl, |
| 7054 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 7055 | SND_SOC_DAPM_SWITCH_E("MAD_CPE2", SND_SOC_NOPM, 0, 0, |
| 7056 | &mad_cpe2_switch, tavil_codec_cpe_mad_ctl, |
| 7057 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 7058 | |
| 7059 | SND_SOC_DAPM_OUTPUT("MAD_CPE_OUT1"), |
| 7060 | SND_SOC_DAPM_OUTPUT("MAD_CPE_OUT2"), |
| 7061 | |
| 7062 | SND_SOC_DAPM_DAC_E("RX INT0 DAC", NULL, SND_SOC_NOPM, |
| 7063 | 0, 0, tavil_codec_ear_dac_event, |
| 7064 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 7065 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 7066 | SND_SOC_DAPM_DAC_E("RX INT1 DAC", NULL, WCD934X_ANA_HPH, |
| 7067 | 5, 0, tavil_codec_hphl_dac_event, |
| 7068 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 7069 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 7070 | SND_SOC_DAPM_DAC_E("RX INT2 DAC", NULL, WCD934X_ANA_HPH, |
| 7071 | 4, 0, tavil_codec_hphr_dac_event, |
| 7072 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 7073 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 7074 | SND_SOC_DAPM_DAC_E("RX INT3 DAC", NULL, SND_SOC_NOPM, |
| 7075 | 0, 0, tavil_codec_lineout_dac_event, |
| 7076 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 7077 | SND_SOC_DAPM_DAC_E("RX INT4 DAC", NULL, SND_SOC_NOPM, |
| 7078 | 0, 0, tavil_codec_lineout_dac_event, |
| 7079 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 7080 | |
| 7081 | SND_SOC_DAPM_PGA_E("EAR PA", WCD934X_ANA_EAR, 7, 0, NULL, 0, |
| 7082 | tavil_codec_enable_ear_pa, |
| 7083 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 7084 | SND_SOC_DAPM_PGA_E("HPHL PA", WCD934X_ANA_HPH, 7, 0, NULL, 0, |
| 7085 | tavil_codec_enable_hphl_pa, |
| 7086 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 7087 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 7088 | SND_SOC_DAPM_PGA_E("HPHR PA", WCD934X_ANA_HPH, 6, 0, NULL, 0, |
| 7089 | tavil_codec_enable_hphr_pa, |
| 7090 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 7091 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 7092 | SND_SOC_DAPM_PGA_E("LINEOUT1 PA", WCD934X_ANA_LO_1_2, 7, 0, NULL, 0, |
| 7093 | tavil_codec_enable_lineout_pa, |
| 7094 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 7095 | SND_SOC_DAPM_POST_PMD), |
| 7096 | SND_SOC_DAPM_PGA_E("LINEOUT2 PA", WCD934X_ANA_LO_1_2, 6, 0, NULL, 0, |
| 7097 | tavil_codec_enable_lineout_pa, |
| 7098 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 7099 | SND_SOC_DAPM_POST_PMD), |
| 7100 | SND_SOC_DAPM_PGA_E("ANC EAR PA", WCD934X_ANA_EAR, 7, 0, NULL, 0, |
| 7101 | tavil_codec_enable_ear_pa, SND_SOC_DAPM_POST_PMU | |
| 7102 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 7103 | SND_SOC_DAPM_PGA_E("ANC SPK1 PA", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 7104 | tavil_codec_enable_spkr_anc, |
| 7105 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 7106 | |
| 7107 | SND_SOC_DAPM_OUTPUT("EAR"), |
| 7108 | SND_SOC_DAPM_OUTPUT("HPHL"), |
| 7109 | SND_SOC_DAPM_OUTPUT("HPHR"), |
| 7110 | SND_SOC_DAPM_OUTPUT("LINEOUT1"), |
| 7111 | SND_SOC_DAPM_OUTPUT("LINEOUT2"), |
| 7112 | SND_SOC_DAPM_OUTPUT("SPK1 OUT"), |
| 7113 | SND_SOC_DAPM_OUTPUT("SPK2 OUT"), |
| 7114 | SND_SOC_DAPM_OUTPUT("ANC EAR"), |
| 7115 | |
| 7116 | SND_SOC_DAPM_SWITCH("ANC OUT EAR Enable", SND_SOC_NOPM, 0, 0, |
| 7117 | &anc_ear_switch), |
| 7118 | SND_SOC_DAPM_SWITCH("ANC OUT EAR SPKR Enable", SND_SOC_NOPM, 0, 0, |
| 7119 | &anc_ear_spkr_switch), |
| 7120 | SND_SOC_DAPM_SWITCH("ANC SPKR PA Enable", SND_SOC_NOPM, 0, 0, |
| 7121 | &anc_spkr_pa_switch), |
| 7122 | |
| 7123 | SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0, |
| 7124 | tavil_codec_enable_rx_bias, |
| 7125 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 7126 | |
| 7127 | SND_SOC_DAPM_SUPPLY("RX INT1 NATIVE SUPPLY", SND_SOC_NOPM, |
| 7128 | INTERP_HPHL, 0, tavil_enable_native_supply, |
| 7129 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 7130 | SND_SOC_DAPM_SUPPLY("RX INT2 NATIVE SUPPLY", SND_SOC_NOPM, |
| 7131 | INTERP_HPHR, 0, tavil_enable_native_supply, |
| 7132 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 7133 | SND_SOC_DAPM_SUPPLY("RX INT3 NATIVE SUPPLY", SND_SOC_NOPM, |
| 7134 | INTERP_LO1, 0, tavil_enable_native_supply, |
| 7135 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 7136 | SND_SOC_DAPM_SUPPLY("RX INT4 NATIVE SUPPLY", SND_SOC_NOPM, |
| 7137 | INTERP_LO2, 0, tavil_enable_native_supply, |
| 7138 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 7139 | SND_SOC_DAPM_SUPPLY("RX INT7 NATIVE SUPPLY", SND_SOC_NOPM, |
| 7140 | INTERP_SPKR1, 0, tavil_enable_native_supply, |
| 7141 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 7142 | SND_SOC_DAPM_SUPPLY("RX INT8 NATIVE SUPPLY", SND_SOC_NOPM, |
| 7143 | INTERP_SPKR2, 0, tavil_enable_native_supply, |
| 7144 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
| 7145 | |
| 7146 | WCD_DAPM_MUX("RX INT1_1 NATIVE MUX", 0, int1_1_native), |
| 7147 | WCD_DAPM_MUX("RX INT2_1 NATIVE MUX", 0, int2_1_native), |
| 7148 | WCD_DAPM_MUX("RX INT3_1 NATIVE MUX", 0, int3_1_native), |
| 7149 | WCD_DAPM_MUX("RX INT4_1 NATIVE MUX", 0, int4_1_native), |
| 7150 | |
| 7151 | WCD_DAPM_MUX("RX INT1_2 NATIVE MUX", 0, int1_2_native), |
| 7152 | WCD_DAPM_MUX("RX INT2_2 NATIVE MUX", 0, int2_2_native), |
| 7153 | WCD_DAPM_MUX("RX INT3_2 NATIVE MUX", 0, int3_2_native), |
| 7154 | WCD_DAPM_MUX("RX INT4_2 NATIVE MUX", 0, int4_2_native), |
| 7155 | WCD_DAPM_MUX("RX INT7_2 NATIVE MUX", 0, int7_2_native), |
| 7156 | WCD_DAPM_MUX("RX INT8_2 NATIVE MUX", 0, int8_2_native), |
| 7157 | |
| 7158 | SND_SOC_DAPM_MUX_E("ASRC0 MUX", SND_SOC_NOPM, ASRC0, 0, |
| 7159 | &asrc0_mux, tavil_codec_enable_asrc_resampler, |
| 7160 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 7161 | SND_SOC_DAPM_MUX_E("ASRC1 MUX", SND_SOC_NOPM, ASRC1, 0, |
| 7162 | &asrc1_mux, tavil_codec_enable_asrc_resampler, |
| 7163 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 7164 | SND_SOC_DAPM_MUX_E("ASRC2 MUX", SND_SOC_NOPM, ASRC2, 0, |
| 7165 | &asrc2_mux, tavil_codec_enable_asrc_resampler, |
| 7166 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 7167 | SND_SOC_DAPM_MUX_E("ASRC3 MUX", SND_SOC_NOPM, ASRC3, 0, |
| 7168 | &asrc3_mux, tavil_codec_enable_asrc_resampler, |
| 7169 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 7170 | }; |
| 7171 | |
| 7172 | static int tavil_get_channel_map(struct snd_soc_dai *dai, |
| 7173 | unsigned int *tx_num, unsigned int *tx_slot, |
| 7174 | unsigned int *rx_num, unsigned int *rx_slot) |
| 7175 | { |
| 7176 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(dai->codec); |
| 7177 | u32 i = 0; |
| 7178 | struct wcd9xxx_ch *ch; |
| 7179 | int ret = 0; |
| 7180 | |
| 7181 | switch (dai->id) { |
| 7182 | case AIF1_PB: |
| 7183 | case AIF2_PB: |
| 7184 | case AIF3_PB: |
| 7185 | case AIF4_PB: |
| 7186 | if (!rx_slot || !rx_num) { |
| 7187 | dev_err(tavil->dev, "%s: Invalid rx_slot 0x%pK or rx_num 0x%pK\n", |
| 7188 | __func__, rx_slot, rx_num); |
| 7189 | ret = -EINVAL; |
| 7190 | break; |
| 7191 | } |
| 7192 | list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list, |
| 7193 | list) { |
| 7194 | dev_dbg(tavil->dev, "%s: slot_num %u ch->ch_num %d\n", |
| 7195 | __func__, i, ch->ch_num); |
| 7196 | rx_slot[i++] = ch->ch_num; |
| 7197 | } |
| 7198 | *rx_num = i; |
| 7199 | dev_dbg(tavil->dev, "%s: dai_name = %s dai_id = %x rx_num = %d\n", |
| 7200 | __func__, dai->name, dai->id, i); |
| 7201 | if (*rx_num == 0) { |
| 7202 | dev_err(tavil->dev, "%s: Channel list empty for dai_name = %s dai_id = %x\n", |
| 7203 | __func__, dai->name, dai->id); |
| 7204 | ret = -EINVAL; |
| 7205 | } |
| 7206 | break; |
| 7207 | case AIF1_CAP: |
| 7208 | case AIF2_CAP: |
| 7209 | case AIF3_CAP: |
| 7210 | case AIF4_MAD_TX: |
| 7211 | case AIF4_VIFEED: |
| 7212 | if (!tx_slot || !tx_num) { |
| 7213 | dev_err(tavil->dev, "%s: Invalid tx_slot 0x%pK or tx_num 0x%pK\n", |
| 7214 | __func__, tx_slot, tx_num); |
| 7215 | ret = -EINVAL; |
| 7216 | break; |
| 7217 | } |
| 7218 | list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list, |
| 7219 | list) { |
| 7220 | dev_dbg(tavil->dev, "%s: slot_num %u ch->ch_num %d\n", |
| 7221 | __func__, i, ch->ch_num); |
| 7222 | tx_slot[i++] = ch->ch_num; |
| 7223 | } |
| 7224 | *tx_num = i; |
| 7225 | dev_dbg(tavil->dev, "%s: dai_name = %s dai_id = %x tx_num = %d\n", |
| 7226 | __func__, dai->name, dai->id, i); |
| 7227 | if (*tx_num == 0) { |
| 7228 | dev_err(tavil->dev, "%s: Channel list empty for dai_name = %s dai_id = %x\n", |
| 7229 | __func__, dai->name, dai->id); |
| 7230 | ret = -EINVAL; |
| 7231 | } |
| 7232 | break; |
| 7233 | default: |
| 7234 | dev_err(tavil->dev, "%s: Invalid DAI ID %x\n", |
| 7235 | __func__, dai->id); |
| 7236 | ret = -EINVAL; |
| 7237 | break; |
| 7238 | } |
| 7239 | |
| 7240 | return ret; |
| 7241 | } |
| 7242 | |
| 7243 | static int tavil_set_channel_map(struct snd_soc_dai *dai, |
| 7244 | unsigned int tx_num, unsigned int *tx_slot, |
| 7245 | unsigned int rx_num, unsigned int *rx_slot) |
| 7246 | { |
| 7247 | struct tavil_priv *tavil; |
| 7248 | struct wcd9xxx *core; |
| 7249 | struct wcd9xxx_codec_dai_data *dai_data = NULL; |
| 7250 | |
| 7251 | tavil = snd_soc_codec_get_drvdata(dai->codec); |
| 7252 | core = dev_get_drvdata(dai->codec->dev->parent); |
| 7253 | |
| 7254 | if (!tx_slot || !rx_slot) { |
| 7255 | dev_err(tavil->dev, "%s: Invalid tx_slot 0x%pK, rx_slot 0x%pK\n", |
| 7256 | __func__, tx_slot, rx_slot); |
| 7257 | return -EINVAL; |
| 7258 | } |
| 7259 | dev_dbg(tavil->dev, "%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n", |
| 7260 | __func__, dai->name, dai->id, tx_num, rx_num); |
| 7261 | |
| 7262 | wcd9xxx_init_slimslave(core, core->slim->laddr, |
| 7263 | tx_num, tx_slot, rx_num, rx_slot); |
| 7264 | /* Reserve TX13 for MAD data channel */ |
| 7265 | dai_data = &tavil->dai[AIF4_MAD_TX]; |
| 7266 | if (dai_data) |
| 7267 | list_add_tail(&core->tx_chs[WCD934X_TX13].list, |
| 7268 | &dai_data->wcd9xxx_ch_list); |
| 7269 | |
| 7270 | return 0; |
| 7271 | } |
| 7272 | |
| 7273 | static int tavil_startup(struct snd_pcm_substream *substream, |
| 7274 | struct snd_soc_dai *dai) |
| 7275 | { |
| 7276 | pr_debug("%s(): substream = %s stream = %d\n", __func__, |
| 7277 | substream->name, substream->stream); |
| 7278 | |
| 7279 | return 0; |
| 7280 | } |
| 7281 | |
| 7282 | static void tavil_shutdown(struct snd_pcm_substream *substream, |
| 7283 | struct snd_soc_dai *dai) |
| 7284 | { |
| 7285 | pr_debug("%s(): substream = %s stream = %d\n", __func__, |
| 7286 | substream->name, substream->stream); |
| 7287 | } |
| 7288 | |
| 7289 | static int tavil_set_decimator_rate(struct snd_soc_dai *dai, |
| 7290 | u32 sample_rate) |
| 7291 | { |
| 7292 | struct snd_soc_codec *codec = dai->codec; |
| 7293 | struct wcd9xxx_ch *ch; |
| 7294 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 7295 | u32 tx_port = 0, tx_fs_rate = 0; |
| 7296 | u8 shift = 0, shift_val = 0, tx_mux_sel = 0; |
| 7297 | int decimator = -1; |
| 7298 | u16 tx_port_reg = 0, tx_fs_reg = 0; |
| 7299 | |
| 7300 | switch (sample_rate) { |
| 7301 | case 8000: |
| 7302 | tx_fs_rate = 0; |
| 7303 | break; |
| 7304 | case 16000: |
| 7305 | tx_fs_rate = 1; |
| 7306 | break; |
| 7307 | case 32000: |
| 7308 | tx_fs_rate = 3; |
| 7309 | break; |
| 7310 | case 48000: |
| 7311 | tx_fs_rate = 4; |
| 7312 | break; |
| 7313 | case 96000: |
| 7314 | tx_fs_rate = 5; |
| 7315 | break; |
| 7316 | case 192000: |
| 7317 | tx_fs_rate = 6; |
| 7318 | break; |
| 7319 | default: |
| 7320 | dev_err(tavil->dev, "%s: Invalid TX sample rate: %d\n", |
| 7321 | __func__, sample_rate); |
| 7322 | return -EINVAL; |
| 7323 | |
| 7324 | }; |
| 7325 | |
| 7326 | list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list, list) { |
| 7327 | tx_port = ch->port; |
| 7328 | dev_dbg(codec->dev, "%s: dai->id = %d, tx_port = %d", |
| 7329 | __func__, dai->id, tx_port); |
| 7330 | |
| 7331 | if ((tx_port < 0) || (tx_port == 12) || (tx_port >= 14)) { |
| 7332 | dev_err(codec->dev, "%s: Invalid SLIM TX%u port. DAI ID: %d\n", |
| 7333 | __func__, tx_port, dai->id); |
| 7334 | return -EINVAL; |
| 7335 | } |
| 7336 | /* Find the SB TX MUX input - which decimator is connected */ |
| 7337 | if (tx_port < 4) { |
| 7338 | tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG0; |
| 7339 | shift = (tx_port << 1); |
| 7340 | shift_val = 0x03; |
| 7341 | } else if ((tx_port >= 4) && (tx_port < 8)) { |
| 7342 | tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG1; |
| 7343 | shift = ((tx_port - 4) << 1); |
| 7344 | shift_val = 0x03; |
| 7345 | } else if ((tx_port >= 8) && (tx_port < 11)) { |
| 7346 | tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG2; |
| 7347 | shift = ((tx_port - 8) << 1); |
| 7348 | shift_val = 0x03; |
| 7349 | } else if (tx_port == 11) { |
| 7350 | tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG3; |
| 7351 | shift = 0; |
| 7352 | shift_val = 0x0F; |
| 7353 | } else if (tx_port == 13) { |
| 7354 | tx_port_reg = WCD934X_CDC_IF_ROUTER_TX_MUX_CFG3; |
| 7355 | shift = 4; |
| 7356 | shift_val = 0x03; |
| 7357 | } |
| 7358 | tx_mux_sel = snd_soc_read(codec, tx_port_reg) & |
| 7359 | (shift_val << shift); |
| 7360 | tx_mux_sel = tx_mux_sel >> shift; |
| 7361 | |
| 7362 | if (tx_port <= 8) { |
| 7363 | if ((tx_mux_sel == 0x2) || (tx_mux_sel == 0x3)) |
| 7364 | decimator = tx_port; |
| 7365 | } else if (tx_port <= 10) { |
| 7366 | if ((tx_mux_sel == 0x1) || (tx_mux_sel == 0x2)) |
| 7367 | decimator = ((tx_port == 9) ? 7 : 6); |
| 7368 | } else if (tx_port == 11) { |
| 7369 | if ((tx_mux_sel >= 1) && (tx_mux_sel < 7)) |
| 7370 | decimator = tx_mux_sel - 1; |
| 7371 | } else if (tx_port == 13) { |
| 7372 | if ((tx_mux_sel == 0x1) || (tx_mux_sel == 0x2)) |
| 7373 | decimator = 5; |
| 7374 | } |
| 7375 | |
| 7376 | if (decimator >= 0) { |
| 7377 | tx_fs_reg = WCD934X_CDC_TX0_TX_PATH_CTL + |
| 7378 | 16 * decimator; |
| 7379 | dev_dbg(codec->dev, "%s: set DEC%u (-> SLIM_TX%u) rate to %u\n", |
| 7380 | __func__, decimator, tx_port, sample_rate); |
| 7381 | snd_soc_update_bits(codec, tx_fs_reg, 0x0F, tx_fs_rate); |
| 7382 | } else if ((tx_port <= 8) && (tx_mux_sel == 0x01)) { |
| 7383 | /* Check if the TX Mux input is RX MIX TXn */ |
| 7384 | dev_dbg(codec->dev, "%s: RX_MIX_TX%u going to CDC_IF TX%u\n", |
| 7385 | __func__, tx_port, tx_port); |
| 7386 | } else { |
| 7387 | dev_err(codec->dev, "%s: ERROR: Invalid decimator: %d\n", |
| 7388 | __func__, decimator); |
| 7389 | return -EINVAL; |
| 7390 | } |
| 7391 | } |
| 7392 | return 0; |
| 7393 | } |
| 7394 | |
| 7395 | static int tavil_set_mix_interpolator_rate(struct snd_soc_dai *dai, |
| 7396 | u8 rate_reg_val, |
| 7397 | u32 sample_rate) |
| 7398 | { |
| 7399 | u8 int_2_inp; |
| 7400 | u32 j; |
| 7401 | u16 int_mux_cfg1, int_fs_reg; |
| 7402 | u8 int_mux_cfg1_val; |
| 7403 | struct snd_soc_codec *codec = dai->codec; |
| 7404 | struct wcd9xxx_ch *ch; |
| 7405 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 7406 | |
| 7407 | list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list, list) { |
| 7408 | int_2_inp = INTn_2_INP_SEL_RX0 + ch->port - |
| 7409 | WCD934X_RX_PORT_START_NUMBER; |
| 7410 | if ((int_2_inp < INTn_2_INP_SEL_RX0) || |
| 7411 | (int_2_inp > INTn_2_INP_SEL_RX7)) { |
| 7412 | dev_err(codec->dev, "%s: Invalid RX%u port, Dai ID is %d\n", |
| 7413 | __func__, |
| 7414 | (ch->port - WCD934X_RX_PORT_START_NUMBER), |
| 7415 | dai->id); |
| 7416 | return -EINVAL; |
| 7417 | } |
| 7418 | |
| 7419 | int_mux_cfg1 = WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG1; |
| 7420 | for (j = 0; j < WCD934X_NUM_INTERPOLATORS; j++) { |
| 7421 | /* Interpolators 5 and 6 are not aviliable in Tavil */ |
| 7422 | if (j == INTERP_LO3_NA || j == INTERP_LO4_NA) { |
| 7423 | int_mux_cfg1 += 2; |
| 7424 | continue; |
| 7425 | } |
| 7426 | int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1) & |
| 7427 | 0x0F; |
| 7428 | if (int_mux_cfg1_val == int_2_inp) { |
| 7429 | /* |
| 7430 | * Ear mix path supports only 48, 96, 192, |
| 7431 | * 384KHz only |
| 7432 | */ |
| 7433 | if ((j == INTERP_EAR) && |
| 7434 | (rate_reg_val < 0x4 || |
| 7435 | rate_reg_val > 0x7)) { |
| 7436 | dev_err_ratelimited(codec->dev, |
| 7437 | "%s: Invalid rate for AIF_PB DAI(%d)\n", |
| 7438 | __func__, dai->id); |
| 7439 | return -EINVAL; |
| 7440 | } |
| 7441 | |
| 7442 | int_fs_reg = WCD934X_CDC_RX0_RX_PATH_MIX_CTL + |
| 7443 | 20 * j; |
| 7444 | dev_dbg(codec->dev, "%s: AIF_PB DAI(%d) connected to INT%u_2\n", |
| 7445 | __func__, dai->id, j); |
| 7446 | dev_dbg(codec->dev, "%s: set INT%u_2 sample rate to %u\n", |
| 7447 | __func__, j, sample_rate); |
| 7448 | snd_soc_update_bits(codec, int_fs_reg, 0x0F, |
| 7449 | rate_reg_val); |
| 7450 | } |
| 7451 | int_mux_cfg1 += 2; |
| 7452 | } |
| 7453 | } |
| 7454 | return 0; |
| 7455 | } |
| 7456 | |
| 7457 | static int tavil_set_prim_interpolator_rate(struct snd_soc_dai *dai, |
| 7458 | u8 rate_reg_val, |
| 7459 | u32 sample_rate) |
| 7460 | { |
| 7461 | u8 int_1_mix1_inp; |
| 7462 | u32 j; |
| 7463 | u16 int_mux_cfg0, int_mux_cfg1; |
| 7464 | u16 int_fs_reg; |
| 7465 | u8 int_mux_cfg0_val, int_mux_cfg1_val; |
| 7466 | u8 inp0_sel, inp1_sel, inp2_sel; |
| 7467 | struct snd_soc_codec *codec = dai->codec; |
| 7468 | struct wcd9xxx_ch *ch; |
| 7469 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 7470 | struct tavil_dsd_config *dsd_conf = tavil->dsd_config; |
| 7471 | |
| 7472 | list_for_each_entry(ch, &tavil->dai[dai->id].wcd9xxx_ch_list, list) { |
| 7473 | int_1_mix1_inp = INTn_1_INP_SEL_RX0 + ch->port - |
| 7474 | WCD934X_RX_PORT_START_NUMBER; |
| 7475 | if ((int_1_mix1_inp < INTn_1_INP_SEL_RX0) || |
| 7476 | (int_1_mix1_inp > INTn_1_INP_SEL_RX7)) { |
| 7477 | dev_err(codec->dev, "%s: Invalid RX%u port, Dai ID is %d\n", |
| 7478 | __func__, |
| 7479 | (ch->port - WCD934X_RX_PORT_START_NUMBER), |
| 7480 | dai->id); |
| 7481 | return -EINVAL; |
| 7482 | } |
| 7483 | |
| 7484 | int_mux_cfg0 = WCD934X_CDC_RX_INP_MUX_RX_INT0_CFG0; |
| 7485 | |
| 7486 | /* |
| 7487 | * Loop through all interpolator MUX inputs and find out |
| 7488 | * to which interpolator input, the slim rx port |
| 7489 | * is connected |
| 7490 | */ |
| 7491 | for (j = 0; j < WCD934X_NUM_INTERPOLATORS; j++) { |
| 7492 | /* Interpolators 5 and 6 are not aviliable in Tavil */ |
| 7493 | if (j == INTERP_LO3_NA || j == INTERP_LO4_NA) { |
| 7494 | int_mux_cfg0 += 2; |
| 7495 | continue; |
| 7496 | } |
| 7497 | int_mux_cfg1 = int_mux_cfg0 + 1; |
| 7498 | |
| 7499 | int_mux_cfg0_val = snd_soc_read(codec, int_mux_cfg0); |
| 7500 | int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1); |
| 7501 | inp0_sel = int_mux_cfg0_val & 0x0F; |
| 7502 | inp1_sel = (int_mux_cfg0_val >> 4) & 0x0F; |
| 7503 | inp2_sel = (int_mux_cfg1_val >> 4) & 0x0F; |
| 7504 | if ((inp0_sel == int_1_mix1_inp) || |
| 7505 | (inp1_sel == int_1_mix1_inp) || |
| 7506 | (inp2_sel == int_1_mix1_inp)) { |
| 7507 | /* |
| 7508 | * Ear and speaker primary path does not support |
| 7509 | * native sample rates |
| 7510 | */ |
| 7511 | if ((j == INTERP_EAR || j == INTERP_SPKR1 || |
| 7512 | j == INTERP_SPKR2) && |
| 7513 | (rate_reg_val > 0x7)) { |
| 7514 | dev_err_ratelimited(codec->dev, |
| 7515 | "%s: Invalid rate for AIF_PB DAI(%d)\n", |
| 7516 | __func__, dai->id); |
| 7517 | return -EINVAL; |
| 7518 | } |
| 7519 | |
| 7520 | int_fs_reg = WCD934X_CDC_RX0_RX_PATH_CTL + |
| 7521 | 20 * j; |
| 7522 | dev_dbg(codec->dev, |
| 7523 | "%s: AIF_PB DAI(%d) connected to INT%u_1\n", |
| 7524 | __func__, dai->id, j); |
| 7525 | dev_dbg(codec->dev, |
| 7526 | "%s: set INT%u_1 sample rate to %u\n", |
| 7527 | __func__, j, sample_rate); |
| 7528 | snd_soc_update_bits(codec, int_fs_reg, 0x0F, |
| 7529 | rate_reg_val); |
| 7530 | } |
| 7531 | int_mux_cfg0 += 2; |
| 7532 | } |
| 7533 | if (dsd_conf) |
| 7534 | tavil_dsd_set_interp_rate(dsd_conf, ch->port, |
| 7535 | sample_rate, rate_reg_val); |
| 7536 | } |
| 7537 | |
| 7538 | return 0; |
| 7539 | } |
| 7540 | |
| 7541 | |
| 7542 | static int tavil_set_interpolator_rate(struct snd_soc_dai *dai, |
| 7543 | u32 sample_rate) |
| 7544 | { |
| 7545 | struct snd_soc_codec *codec = dai->codec; |
| 7546 | int rate_val = 0; |
| 7547 | int i, ret; |
| 7548 | |
| 7549 | for (i = 0; i < ARRAY_SIZE(sr_val_tbl); i++) { |
| 7550 | if (sample_rate == sr_val_tbl[i].sample_rate) { |
| 7551 | rate_val = sr_val_tbl[i].rate_val; |
| 7552 | break; |
| 7553 | } |
| 7554 | } |
| 7555 | if ((i == ARRAY_SIZE(sr_val_tbl)) || (rate_val < 0)) { |
| 7556 | dev_err(codec->dev, "%s: Unsupported sample rate: %d\n", |
| 7557 | __func__, sample_rate); |
| 7558 | return -EINVAL; |
| 7559 | } |
| 7560 | |
| 7561 | ret = tavil_set_prim_interpolator_rate(dai, (u8)rate_val, sample_rate); |
| 7562 | if (ret) |
| 7563 | return ret; |
| 7564 | ret = tavil_set_mix_interpolator_rate(dai, (u8)rate_val, sample_rate); |
| 7565 | if (ret) |
| 7566 | return ret; |
| 7567 | |
| 7568 | return ret; |
| 7569 | } |
| 7570 | |
| 7571 | static int tavil_prepare(struct snd_pcm_substream *substream, |
| 7572 | struct snd_soc_dai *dai) |
| 7573 | { |
| 7574 | pr_debug("%s(): substream = %s stream = %d\n", __func__, |
| 7575 | substream->name, substream->stream); |
| 7576 | return 0; |
| 7577 | } |
| 7578 | |
| 7579 | static int tavil_vi_hw_params(struct snd_pcm_substream *substream, |
| 7580 | struct snd_pcm_hw_params *params, |
| 7581 | struct snd_soc_dai *dai) |
| 7582 | { |
| 7583 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(dai->codec); |
| 7584 | |
| 7585 | dev_dbg(tavil->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", |
| 7586 | __func__, dai->name, dai->id, params_rate(params), |
| 7587 | params_channels(params)); |
| 7588 | |
| 7589 | tavil->dai[dai->id].rate = params_rate(params); |
| 7590 | tavil->dai[dai->id].bit_width = 32; |
| 7591 | |
| 7592 | return 0; |
| 7593 | } |
| 7594 | |
| 7595 | static int tavil_hw_params(struct snd_pcm_substream *substream, |
| 7596 | struct snd_pcm_hw_params *params, |
| 7597 | struct snd_soc_dai *dai) |
| 7598 | { |
| 7599 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(dai->codec); |
| 7600 | int ret = 0; |
| 7601 | |
| 7602 | dev_dbg(tavil->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", |
| 7603 | __func__, dai->name, dai->id, params_rate(params), |
| 7604 | params_channels(params)); |
| 7605 | |
| 7606 | switch (substream->stream) { |
| 7607 | case SNDRV_PCM_STREAM_PLAYBACK: |
| 7608 | ret = tavil_set_interpolator_rate(dai, params_rate(params)); |
| 7609 | if (ret) { |
| 7610 | dev_err(tavil->dev, "%s: cannot set sample rate: %u\n", |
| 7611 | __func__, params_rate(params)); |
| 7612 | return ret; |
| 7613 | } |
| 7614 | switch (params_width(params)) { |
| 7615 | case 16: |
| 7616 | tavil->dai[dai->id].bit_width = 16; |
| 7617 | break; |
| 7618 | case 24: |
| 7619 | tavil->dai[dai->id].bit_width = 24; |
| 7620 | break; |
| 7621 | case 32: |
| 7622 | tavil->dai[dai->id].bit_width = 32; |
| 7623 | break; |
| 7624 | default: |
| 7625 | return -EINVAL; |
| 7626 | } |
| 7627 | tavil->dai[dai->id].rate = params_rate(params); |
| 7628 | break; |
| 7629 | case SNDRV_PCM_STREAM_CAPTURE: |
| 7630 | if (dai->id != AIF4_MAD_TX) |
| 7631 | ret = tavil_set_decimator_rate(dai, |
| 7632 | params_rate(params)); |
| 7633 | if (ret) { |
| 7634 | dev_err(tavil->dev, "%s: cannot set TX Decimator rate: %d\n", |
| 7635 | __func__, ret); |
| 7636 | return ret; |
| 7637 | } |
| 7638 | switch (params_width(params)) { |
| 7639 | case 16: |
| 7640 | tavil->dai[dai->id].bit_width = 16; |
| 7641 | break; |
| 7642 | case 24: |
| 7643 | tavil->dai[dai->id].bit_width = 24; |
| 7644 | break; |
| 7645 | default: |
| 7646 | dev_err(tavil->dev, "%s: Invalid format 0x%x\n", |
| 7647 | __func__, params_width(params)); |
| 7648 | return -EINVAL; |
| 7649 | }; |
| 7650 | tavil->dai[dai->id].rate = params_rate(params); |
| 7651 | break; |
| 7652 | default: |
| 7653 | dev_err(tavil->dev, "%s: Invalid stream type %d\n", __func__, |
| 7654 | substream->stream); |
| 7655 | return -EINVAL; |
| 7656 | }; |
| 7657 | |
| 7658 | return 0; |
| 7659 | } |
| 7660 | |
| 7661 | static struct snd_soc_dai_ops tavil_dai_ops = { |
| 7662 | .startup = tavil_startup, |
| 7663 | .shutdown = tavil_shutdown, |
| 7664 | .hw_params = tavil_hw_params, |
| 7665 | .prepare = tavil_prepare, |
| 7666 | .set_channel_map = tavil_set_channel_map, |
| 7667 | .get_channel_map = tavil_get_channel_map, |
| 7668 | }; |
| 7669 | |
| 7670 | static struct snd_soc_dai_ops tavil_vi_dai_ops = { |
| 7671 | .hw_params = tavil_vi_hw_params, |
| 7672 | .set_channel_map = tavil_set_channel_map, |
| 7673 | .get_channel_map = tavil_get_channel_map, |
| 7674 | }; |
| 7675 | |
| 7676 | static struct snd_soc_dai_driver tavil_dai[] = { |
| 7677 | { |
| 7678 | .name = "tavil_rx1", |
| 7679 | .id = AIF1_PB, |
| 7680 | .playback = { |
| 7681 | .stream_name = "AIF1 Playback", |
| 7682 | .rates = WCD934X_RATES_MASK | WCD934X_FRAC_RATES_MASK, |
| 7683 | .formats = WCD934X_FORMATS_S16_S24_S32_LE, |
| 7684 | .rate_min = 8000, |
| 7685 | .rate_max = 384000, |
| 7686 | .channels_min = 1, |
| 7687 | .channels_max = 2, |
| 7688 | }, |
| 7689 | .ops = &tavil_dai_ops, |
| 7690 | }, |
| 7691 | { |
| 7692 | .name = "tavil_tx1", |
| 7693 | .id = AIF1_CAP, |
| 7694 | .capture = { |
| 7695 | .stream_name = "AIF1 Capture", |
| 7696 | .rates = WCD934X_RATES_MASK, |
| 7697 | .formats = WCD934X_FORMATS_S16_S24_LE, |
| 7698 | .rate_min = 8000, |
| 7699 | .rate_max = 192000, |
| 7700 | .channels_min = 1, |
| 7701 | .channels_max = 4, |
| 7702 | }, |
| 7703 | .ops = &tavil_dai_ops, |
| 7704 | }, |
| 7705 | { |
| 7706 | .name = "tavil_rx2", |
| 7707 | .id = AIF2_PB, |
| 7708 | .playback = { |
| 7709 | .stream_name = "AIF2 Playback", |
| 7710 | .rates = WCD934X_RATES_MASK | WCD934X_FRAC_RATES_MASK, |
| 7711 | .formats = WCD934X_FORMATS_S16_S24_S32_LE, |
| 7712 | .rate_min = 8000, |
| 7713 | .rate_max = 384000, |
| 7714 | .channels_min = 1, |
| 7715 | .channels_max = 2, |
| 7716 | }, |
| 7717 | .ops = &tavil_dai_ops, |
| 7718 | }, |
| 7719 | { |
| 7720 | .name = "tavil_tx2", |
| 7721 | .id = AIF2_CAP, |
| 7722 | .capture = { |
| 7723 | .stream_name = "AIF2 Capture", |
| 7724 | .rates = WCD934X_RATES_MASK, |
| 7725 | .formats = WCD934X_FORMATS_S16_S24_LE, |
| 7726 | .rate_min = 8000, |
| 7727 | .rate_max = 192000, |
| 7728 | .channels_min = 1, |
| 7729 | .channels_max = 4, |
| 7730 | }, |
| 7731 | .ops = &tavil_dai_ops, |
| 7732 | }, |
| 7733 | { |
| 7734 | .name = "tavil_rx3", |
| 7735 | .id = AIF3_PB, |
| 7736 | .playback = { |
| 7737 | .stream_name = "AIF3 Playback", |
| 7738 | .rates = WCD934X_RATES_MASK | WCD934X_FRAC_RATES_MASK, |
| 7739 | .formats = WCD934X_FORMATS_S16_S24_S32_LE, |
| 7740 | .rate_min = 8000, |
| 7741 | .rate_max = 384000, |
| 7742 | .channels_min = 1, |
| 7743 | .channels_max = 2, |
| 7744 | }, |
| 7745 | .ops = &tavil_dai_ops, |
| 7746 | }, |
| 7747 | { |
| 7748 | .name = "tavil_tx3", |
| 7749 | .id = AIF3_CAP, |
| 7750 | .capture = { |
| 7751 | .stream_name = "AIF3 Capture", |
| 7752 | .rates = WCD934X_RATES_MASK, |
| 7753 | .formats = WCD934X_FORMATS_S16_S24_LE, |
| 7754 | .rate_min = 8000, |
| 7755 | .rate_max = 192000, |
| 7756 | .channels_min = 1, |
| 7757 | .channels_max = 4, |
| 7758 | }, |
| 7759 | .ops = &tavil_dai_ops, |
| 7760 | }, |
| 7761 | { |
| 7762 | .name = "tavil_rx4", |
| 7763 | .id = AIF4_PB, |
| 7764 | .playback = { |
| 7765 | .stream_name = "AIF4 Playback", |
| 7766 | .rates = WCD934X_RATES_MASK | WCD934X_FRAC_RATES_MASK, |
| 7767 | .formats = WCD934X_FORMATS_S16_S24_S32_LE, |
| 7768 | .rate_min = 8000, |
| 7769 | .rate_max = 384000, |
| 7770 | .channels_min = 1, |
| 7771 | .channels_max = 2, |
| 7772 | }, |
| 7773 | .ops = &tavil_dai_ops, |
| 7774 | }, |
| 7775 | { |
| 7776 | .name = "tavil_vifeedback", |
| 7777 | .id = AIF4_VIFEED, |
| 7778 | .capture = { |
| 7779 | .stream_name = "VIfeed", |
| 7780 | .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_48000, |
| 7781 | .formats = WCD934X_FORMATS_S16_S24_S32_LE, |
| 7782 | .rate_min = 8000, |
| 7783 | .rate_max = 48000, |
| 7784 | .channels_min = 1, |
| 7785 | .channels_max = 4, |
| 7786 | }, |
| 7787 | .ops = &tavil_vi_dai_ops, |
| 7788 | }, |
| 7789 | { |
| 7790 | .name = "tavil_mad1", |
| 7791 | .id = AIF4_MAD_TX, |
| 7792 | .capture = { |
| 7793 | .stream_name = "AIF4 MAD TX", |
| 7794 | .rates = SNDRV_PCM_RATE_16000, |
| 7795 | .formats = WCD934X_FORMATS_S16_LE, |
| 7796 | .rate_min = 16000, |
| 7797 | .rate_max = 16000, |
| 7798 | .channels_min = 1, |
| 7799 | .channels_max = 1, |
| 7800 | }, |
| 7801 | .ops = &tavil_dai_ops, |
| 7802 | }, |
| 7803 | }; |
| 7804 | |
| 7805 | static void tavil_codec_power_gate_digital_core(struct tavil_priv *tavil) |
| 7806 | { |
| 7807 | struct snd_soc_codec *codec = tavil->codec; |
| 7808 | |
| 7809 | if (!codec) |
| 7810 | return; |
| 7811 | |
| 7812 | mutex_lock(&tavil->power_lock); |
| 7813 | dev_dbg(codec->dev, "%s: Entering power gating function, %d\n", |
| 7814 | __func__, tavil->power_active_ref); |
| 7815 | |
| 7816 | if (tavil->power_active_ref > 0) |
| 7817 | goto exit; |
| 7818 | |
| 7819 | wcd9xxx_set_power_state(tavil->wcd9xxx, |
| 7820 | WCD_REGION_POWER_COLLAPSE_BEGIN, |
| 7821 | WCD9XXX_DIG_CORE_REGION_1); |
| 7822 | snd_soc_update_bits(codec, WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, |
| 7823 | 0x04, 0x04); |
| 7824 | snd_soc_update_bits(codec, WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, |
| 7825 | 0x01, 0x00); |
| 7826 | snd_soc_update_bits(codec, WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, |
| 7827 | 0x02, 0x00); |
| 7828 | wcd9xxx_set_power_state(tavil->wcd9xxx, WCD_REGION_POWER_DOWN, |
| 7829 | WCD9XXX_DIG_CORE_REGION_1); |
| 7830 | exit: |
| 7831 | dev_dbg(codec->dev, "%s: Exiting power gating function, %d\n", |
| 7832 | __func__, tavil->power_active_ref); |
| 7833 | mutex_unlock(&tavil->power_lock); |
| 7834 | } |
| 7835 | |
| 7836 | static void tavil_codec_power_gate_work(struct work_struct *work) |
| 7837 | { |
| 7838 | struct tavil_priv *tavil; |
| 7839 | struct delayed_work *dwork; |
| 7840 | struct snd_soc_codec *codec; |
| 7841 | |
| 7842 | dwork = to_delayed_work(work); |
| 7843 | tavil = container_of(dwork, struct tavil_priv, power_gate_work); |
| 7844 | codec = tavil->codec; |
| 7845 | |
| 7846 | if (!codec) |
| 7847 | return; |
| 7848 | |
| 7849 | tavil_codec_power_gate_digital_core(tavil); |
| 7850 | } |
| 7851 | |
| 7852 | /* called under power_lock acquisition */ |
| 7853 | static int tavil_dig_core_remove_power_collapse(struct snd_soc_codec *codec) |
| 7854 | { |
| 7855 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 7856 | |
| 7857 | snd_soc_write(codec, WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x5); |
| 7858 | snd_soc_write(codec, WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x7); |
| 7859 | snd_soc_write(codec, WCD934X_CODEC_RPM_PWR_CDC_DIG_HM_CTL, 0x3); |
| 7860 | snd_soc_update_bits(codec, WCD934X_CODEC_RPM_RST_CTL, 0x02, 0x00); |
| 7861 | snd_soc_update_bits(codec, WCD934X_CODEC_RPM_RST_CTL, 0x02, 0x02); |
| 7862 | |
| 7863 | wcd9xxx_set_power_state(tavil->wcd9xxx, |
| 7864 | WCD_REGION_POWER_COLLAPSE_REMOVE, |
| 7865 | WCD9XXX_DIG_CORE_REGION_1); |
| 7866 | regcache_mark_dirty(codec->component.regmap); |
| 7867 | regcache_sync_region(codec->component.regmap, |
| 7868 | WCD934X_DIG_CORE_REG_MIN, |
| 7869 | WCD934X_DIG_CORE_REG_MAX); |
| 7870 | |
| 7871 | return 0; |
| 7872 | } |
| 7873 | |
| 7874 | static int tavil_dig_core_power_collapse(struct tavil_priv *tavil, |
| 7875 | int req_state) |
| 7876 | { |
| 7877 | struct snd_soc_codec *codec; |
| 7878 | int cur_state; |
| 7879 | |
| 7880 | /* Exit if feature is disabled */ |
| 7881 | if (!dig_core_collapse_enable) |
| 7882 | return 0; |
| 7883 | |
| 7884 | mutex_lock(&tavil->power_lock); |
| 7885 | if (req_state == POWER_COLLAPSE) |
| 7886 | tavil->power_active_ref--; |
| 7887 | else if (req_state == POWER_RESUME) |
| 7888 | tavil->power_active_ref++; |
| 7889 | else |
| 7890 | goto unlock_mutex; |
| 7891 | |
| 7892 | if (tavil->power_active_ref < 0) { |
| 7893 | dev_dbg(tavil->dev, "%s: power_active_ref is negative\n", |
| 7894 | __func__); |
| 7895 | goto unlock_mutex; |
| 7896 | } |
| 7897 | |
| 7898 | codec = tavil->codec; |
| 7899 | if (!codec) |
| 7900 | goto unlock_mutex; |
| 7901 | |
| 7902 | if (req_state == POWER_COLLAPSE) { |
| 7903 | if (tavil->power_active_ref == 0) { |
| 7904 | schedule_delayed_work(&tavil->power_gate_work, |
| 7905 | msecs_to_jiffies(dig_core_collapse_timer * 1000)); |
| 7906 | } |
| 7907 | } else if (req_state == POWER_RESUME) { |
| 7908 | if (tavil->power_active_ref == 1) { |
| 7909 | /* |
| 7910 | * At this point, there can be two cases: |
| 7911 | * 1. Core already in power collapse state |
| 7912 | * 2. Timer kicked in and still did not expire or |
| 7913 | * waiting for the power_lock |
| 7914 | */ |
| 7915 | cur_state = wcd9xxx_get_current_power_state( |
| 7916 | tavil->wcd9xxx, |
| 7917 | WCD9XXX_DIG_CORE_REGION_1); |
| 7918 | if (cur_state == WCD_REGION_POWER_DOWN) { |
| 7919 | tavil_dig_core_remove_power_collapse(codec); |
| 7920 | } else { |
| 7921 | mutex_unlock(&tavil->power_lock); |
| 7922 | cancel_delayed_work_sync( |
| 7923 | &tavil->power_gate_work); |
| 7924 | mutex_lock(&tavil->power_lock); |
| 7925 | } |
| 7926 | } |
| 7927 | } |
| 7928 | |
| 7929 | unlock_mutex: |
| 7930 | mutex_unlock(&tavil->power_lock); |
| 7931 | |
| 7932 | return 0; |
| 7933 | } |
| 7934 | |
| 7935 | static int tavil_cdc_req_mclk_enable(struct tavil_priv *tavil, |
| 7936 | bool enable) |
| 7937 | { |
| 7938 | int ret = 0; |
| 7939 | |
| 7940 | if (enable) { |
| 7941 | ret = clk_prepare_enable(tavil->wcd_ext_clk); |
| 7942 | if (ret) { |
| 7943 | dev_err(tavil->dev, "%s: ext clk enable failed\n", |
| 7944 | __func__); |
| 7945 | goto done; |
| 7946 | } |
| 7947 | /* get BG */ |
| 7948 | wcd_resmgr_enable_master_bias(tavil->resmgr); |
| 7949 | /* get MCLK */ |
| 7950 | wcd_resmgr_enable_clk_block(tavil->resmgr, WCD_CLK_MCLK); |
| 7951 | } else { |
| 7952 | /* put MCLK */ |
| 7953 | wcd_resmgr_disable_clk_block(tavil->resmgr, WCD_CLK_MCLK); |
| 7954 | /* put BG */ |
| 7955 | wcd_resmgr_disable_master_bias(tavil->resmgr); |
| 7956 | clk_disable_unprepare(tavil->wcd_ext_clk); |
| 7957 | } |
| 7958 | |
| 7959 | done: |
| 7960 | return ret; |
| 7961 | } |
| 7962 | |
| 7963 | static int __tavil_cdc_mclk_enable_locked(struct tavil_priv *tavil, |
| 7964 | bool enable) |
| 7965 | { |
| 7966 | int ret = 0; |
| 7967 | |
| 7968 | if (!tavil->wcd_ext_clk) { |
| 7969 | dev_err(tavil->dev, "%s: wcd ext clock is NULL\n", __func__); |
| 7970 | return -EINVAL; |
| 7971 | } |
| 7972 | |
| 7973 | dev_dbg(tavil->dev, "%s: mclk_enable = %u\n", __func__, enable); |
| 7974 | |
| 7975 | if (enable) { |
| 7976 | tavil_dig_core_power_collapse(tavil, POWER_RESUME); |
| 7977 | tavil_vote_svs(tavil, true); |
| 7978 | ret = tavil_cdc_req_mclk_enable(tavil, true); |
| 7979 | if (ret) |
| 7980 | goto done; |
| 7981 | } else { |
| 7982 | tavil_cdc_req_mclk_enable(tavil, false); |
| 7983 | tavil_vote_svs(tavil, false); |
| 7984 | tavil_dig_core_power_collapse(tavil, POWER_COLLAPSE); |
| 7985 | } |
| 7986 | |
| 7987 | done: |
| 7988 | return ret; |
| 7989 | } |
| 7990 | |
| 7991 | static int __tavil_cdc_mclk_enable(struct tavil_priv *tavil, |
| 7992 | bool enable) |
| 7993 | { |
| 7994 | int ret; |
| 7995 | |
| 7996 | WCD9XXX_V2_BG_CLK_LOCK(tavil->resmgr); |
| 7997 | ret = __tavil_cdc_mclk_enable_locked(tavil, enable); |
| 7998 | WCD9XXX_V2_BG_CLK_UNLOCK(tavil->resmgr); |
| 7999 | |
| 8000 | return ret; |
| 8001 | } |
| 8002 | |
| 8003 | static ssize_t tavil_codec_version_read(struct snd_info_entry *entry, |
| 8004 | void *file_private_data, |
| 8005 | struct file *file, |
| 8006 | char __user *buf, size_t count, |
| 8007 | loff_t pos) |
| 8008 | { |
| 8009 | struct tavil_priv *tavil; |
| 8010 | struct wcd9xxx *wcd9xxx; |
| 8011 | char buffer[TAVIL_VERSION_ENTRY_SIZE]; |
| 8012 | int len = 0; |
| 8013 | |
| 8014 | tavil = (struct tavil_priv *) entry->private_data; |
| 8015 | if (!tavil) { |
| 8016 | pr_err("%s: tavil priv is null\n", __func__); |
| 8017 | return -EINVAL; |
| 8018 | } |
| 8019 | |
| 8020 | wcd9xxx = tavil->wcd9xxx; |
| 8021 | |
| 8022 | switch (wcd9xxx->version) { |
| 8023 | case TAVIL_VERSION_WCD9340_1_0: |
| 8024 | len = snprintf(buffer, sizeof(buffer), "WCD9340_1_0\n"); |
| 8025 | break; |
| 8026 | case TAVIL_VERSION_WCD9341_1_0: |
| 8027 | len = snprintf(buffer, sizeof(buffer), "WCD9341_1_0\n"); |
| 8028 | break; |
| 8029 | case TAVIL_VERSION_WCD9340_1_1: |
| 8030 | len = snprintf(buffer, sizeof(buffer), "WCD9340_1_1\n"); |
| 8031 | break; |
| 8032 | case TAVIL_VERSION_WCD9341_1_1: |
| 8033 | len = snprintf(buffer, sizeof(buffer), "WCD9341_1_1\n"); |
| 8034 | break; |
| 8035 | default: |
| 8036 | len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n"); |
| 8037 | } |
| 8038 | |
| 8039 | return simple_read_from_buffer(buf, count, &pos, buffer, len); |
| 8040 | } |
| 8041 | |
| 8042 | static struct snd_info_entry_ops tavil_codec_info_ops = { |
| 8043 | .read = tavil_codec_version_read, |
| 8044 | }; |
| 8045 | |
| 8046 | /* |
| 8047 | * tavil_codec_info_create_codec_entry - creates wcd934x module |
| 8048 | * @codec_root: The parent directory |
| 8049 | * @codec: Codec instance |
| 8050 | * |
| 8051 | * Creates wcd934x module and version entry under the given |
| 8052 | * parent directory. |
| 8053 | * |
| 8054 | * Return: 0 on success or negative error code on failure. |
| 8055 | */ |
| 8056 | int tavil_codec_info_create_codec_entry(struct snd_info_entry *codec_root, |
| 8057 | struct snd_soc_codec *codec) |
| 8058 | { |
| 8059 | struct snd_info_entry *version_entry; |
| 8060 | struct tavil_priv *tavil; |
| 8061 | struct snd_soc_card *card; |
| 8062 | |
| 8063 | if (!codec_root || !codec) |
| 8064 | return -EINVAL; |
| 8065 | |
| 8066 | tavil = snd_soc_codec_get_drvdata(codec); |
| 8067 | card = codec->component.card; |
Banajit Goswami | 7f40ea4 | 2017-01-30 13:32:41 -0800 | [diff] [blame] | 8068 | tavil->entry = snd_info_create_subdir(codec_root->module, |
| 8069 | "tavil", codec_root); |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 8070 | if (!tavil->entry) { |
| 8071 | dev_dbg(codec->dev, "%s: failed to create wcd934x entry\n", |
| 8072 | __func__); |
| 8073 | return -ENOMEM; |
| 8074 | } |
| 8075 | |
| 8076 | version_entry = snd_info_create_card_entry(card->snd_card, |
| 8077 | "version", |
| 8078 | tavil->entry); |
| 8079 | if (!version_entry) { |
| 8080 | dev_dbg(codec->dev, "%s: failed to create wcd934x version entry\n", |
| 8081 | __func__); |
| 8082 | return -ENOMEM; |
| 8083 | } |
| 8084 | |
| 8085 | version_entry->private_data = tavil; |
| 8086 | version_entry->size = TAVIL_VERSION_ENTRY_SIZE; |
| 8087 | version_entry->content = SNDRV_INFO_CONTENT_DATA; |
| 8088 | version_entry->c.ops = &tavil_codec_info_ops; |
| 8089 | |
| 8090 | if (snd_info_register(version_entry) < 0) { |
| 8091 | snd_info_free_entry(version_entry); |
| 8092 | return -ENOMEM; |
| 8093 | } |
| 8094 | tavil->version_entry = version_entry; |
| 8095 | |
| 8096 | return 0; |
| 8097 | } |
| 8098 | EXPORT_SYMBOL(tavil_codec_info_create_codec_entry); |
| 8099 | |
| 8100 | /** |
| 8101 | * tavil_cdc_mclk_enable - Enable/disable codec mclk |
| 8102 | * |
| 8103 | * @codec: codec instance |
| 8104 | * @enable: Indicates clk enable or disable |
| 8105 | * |
| 8106 | * Returns 0 on Success and error on failure |
| 8107 | */ |
| 8108 | int tavil_cdc_mclk_enable(struct snd_soc_codec *codec, bool enable) |
| 8109 | { |
| 8110 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 8111 | |
| 8112 | return __tavil_cdc_mclk_enable(tavil, enable); |
| 8113 | } |
| 8114 | EXPORT_SYMBOL(tavil_cdc_mclk_enable); |
| 8115 | |
| 8116 | static int __tavil_codec_internal_rco_ctrl(struct snd_soc_codec *codec, |
| 8117 | bool enable) |
| 8118 | { |
| 8119 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 8120 | int ret = 0; |
| 8121 | |
| 8122 | if (enable) { |
| 8123 | if (wcd_resmgr_get_clk_type(tavil->resmgr) == |
| 8124 | WCD_CLK_RCO) { |
| 8125 | ret = wcd_resmgr_enable_clk_block(tavil->resmgr, |
| 8126 | WCD_CLK_RCO); |
| 8127 | } else { |
| 8128 | ret = tavil_cdc_req_mclk_enable(tavil, true); |
| 8129 | if (ret) { |
| 8130 | dev_err(codec->dev, |
| 8131 | "%s: mclk_enable failed, err = %d\n", |
| 8132 | __func__, ret); |
| 8133 | goto done; |
| 8134 | } |
| 8135 | ret = wcd_resmgr_enable_clk_block(tavil->resmgr, |
| 8136 | WCD_CLK_RCO); |
| 8137 | ret |= tavil_cdc_req_mclk_enable(tavil, false); |
| 8138 | } |
| 8139 | |
| 8140 | } else { |
| 8141 | ret = wcd_resmgr_disable_clk_block(tavil->resmgr, |
| 8142 | WCD_CLK_RCO); |
| 8143 | } |
| 8144 | |
| 8145 | if (ret) { |
| 8146 | dev_err(codec->dev, "%s: Error in %s RCO\n", |
| 8147 | __func__, (enable ? "enabling" : "disabling")); |
| 8148 | ret = -EINVAL; |
| 8149 | } |
| 8150 | |
| 8151 | done: |
| 8152 | return ret; |
| 8153 | } |
| 8154 | |
| 8155 | /* |
| 8156 | * tavil_codec_internal_rco_ctrl: Enable/Disable codec's RCO clock |
| 8157 | * @codec: Handle to the codec |
| 8158 | * @enable: Indicates whether clock should be enabled or disabled |
| 8159 | */ |
| 8160 | static int tavil_codec_internal_rco_ctrl(struct snd_soc_codec *codec, |
| 8161 | bool enable) |
| 8162 | { |
| 8163 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 8164 | int ret = 0; |
| 8165 | |
| 8166 | WCD9XXX_V2_BG_CLK_LOCK(tavil->resmgr); |
| 8167 | ret = __tavil_codec_internal_rco_ctrl(codec, enable); |
| 8168 | WCD9XXX_V2_BG_CLK_UNLOCK(tavil->resmgr); |
| 8169 | return ret; |
| 8170 | } |
| 8171 | |
| 8172 | static const struct wcd_resmgr_cb tavil_resmgr_cb = { |
| 8173 | .cdc_rco_ctrl = __tavil_codec_internal_rco_ctrl, |
| 8174 | }; |
| 8175 | |
| 8176 | static const struct tavil_reg_mask_val tavil_codec_mclk2_1_1_defaults[] = { |
| 8177 | {WCD934X_CLK_SYS_MCLK2_PRG1, 0x60, 0x20}, |
| 8178 | }; |
| 8179 | |
| 8180 | static const struct tavil_reg_mask_val tavil_codec_mclk2_1_0_defaults[] = { |
| 8181 | /* |
| 8182 | * PLL Settings: |
| 8183 | * Clock Root: MCLK2, |
| 8184 | * Clock Source: EXT_CLK, |
| 8185 | * Clock Destination: MCLK2 |
| 8186 | * Clock Freq In: 19.2MHz, |
| 8187 | * Clock Freq Out: 11.2896MHz |
| 8188 | */ |
| 8189 | {WCD934X_CLK_SYS_MCLK2_PRG1, 0x60, 0x20}, |
| 8190 | {WCD934X_CLK_SYS_INT_POST_DIV_REG0, 0xFF, 0x5E}, |
| 8191 | {WCD934X_CLK_SYS_INT_POST_DIV_REG1, 0x1F, 0x1F}, |
| 8192 | {WCD934X_CLK_SYS_INT_REF_DIV_REG0, 0xFF, 0x54}, |
| 8193 | {WCD934X_CLK_SYS_INT_REF_DIV_REG1, 0xFF, 0x01}, |
| 8194 | {WCD934X_CLK_SYS_INT_FILTER_REG1, 0x07, 0x04}, |
| 8195 | {WCD934X_CLK_SYS_INT_PLL_L_VAL, 0xFF, 0x93}, |
| 8196 | {WCD934X_CLK_SYS_INT_PLL_N_VAL, 0xFF, 0xFA}, |
| 8197 | {WCD934X_CLK_SYS_INT_TEST_REG0, 0xFF, 0x90}, |
| 8198 | {WCD934X_CLK_SYS_INT_PFD_CP_DSM_PROG, 0xFF, 0x7E}, |
| 8199 | {WCD934X_CLK_SYS_INT_VCO_PROG, 0xFF, 0xF8}, |
| 8200 | {WCD934X_CLK_SYS_INT_TEST_REG1, 0xFF, 0x68}, |
| 8201 | {WCD934X_CLK_SYS_INT_LDO_LOCK_CFG, 0xFF, 0x40}, |
| 8202 | {WCD934X_CLK_SYS_INT_DIG_LOCK_DET_CFG, 0xFF, 0x32}, |
| 8203 | }; |
| 8204 | |
| 8205 | static const struct tavil_reg_mask_val tavil_codec_reg_defaults[] = { |
| 8206 | {WCD934X_BIAS_VBG_FINE_ADJ, 0xFF, 0x75}, |
| 8207 | {WCD934X_CODEC_CPR_SVS_CX_VDD, 0xFF, 0x7C}, /* value in svs mode */ |
| 8208 | {WCD934X_CODEC_CPR_SVS2_CX_VDD, 0xFF, 0x58}, /* value in svs2 mode */ |
| 8209 | {WCD934X_CDC_RX0_RX_PATH_DSMDEM_CTL, 0x01, 0x01}, |
| 8210 | {WCD934X_CDC_RX1_RX_PATH_DSMDEM_CTL, 0x01, 0x01}, |
| 8211 | {WCD934X_CDC_RX2_RX_PATH_DSMDEM_CTL, 0x01, 0x01}, |
| 8212 | {WCD934X_CDC_RX3_RX_PATH_DSMDEM_CTL, 0x01, 0x01}, |
| 8213 | {WCD934X_CDC_RX4_RX_PATH_DSMDEM_CTL, 0x01, 0x01}, |
| 8214 | {WCD934X_CDC_RX7_RX_PATH_DSMDEM_CTL, 0x01, 0x01}, |
| 8215 | {WCD934X_CDC_RX8_RX_PATH_DSMDEM_CTL, 0x01, 0x01}, |
| 8216 | {WCD934X_CDC_COMPANDER8_CTL7, 0x1E, 0x18}, |
| 8217 | {WCD934X_CDC_COMPANDER7_CTL7, 0x1E, 0x18}, |
| 8218 | {WCD934X_CDC_RX0_RX_PATH_SEC0, 0x08, 0x0}, |
| 8219 | {WCD934X_CDC_CLSH_DECAY_CTRL, 0x03, 0x0}, |
| 8220 | {WCD934X_MICB1_TEST_CTL_2, 0x07, 0x01}, |
| 8221 | {WCD934X_CDC_BOOST0_BOOST_CFG1, 0x3F, 0x12}, |
| 8222 | {WCD934X_CDC_BOOST0_BOOST_CFG2, 0x1C, 0x08}, |
| 8223 | {WCD934X_CDC_BOOST1_BOOST_CFG1, 0x3F, 0x12}, |
| 8224 | {WCD934X_CDC_BOOST1_BOOST_CFG2, 0x1C, 0x08}, |
| 8225 | {WCD934X_CPE_SS_CPARMAD_BUFRDY_INT_PERIOD, 0x1F, 0x09}, |
| 8226 | {WCD934X_CDC_TX0_TX_PATH_CFG1, 0x01, 0x00}, |
| 8227 | {WCD934X_CDC_TX1_TX_PATH_CFG1, 0x01, 0x00}, |
| 8228 | {WCD934X_CDC_TX2_TX_PATH_CFG1, 0x01, 0x00}, |
| 8229 | {WCD934X_CDC_TX3_TX_PATH_CFG1, 0x01, 0x00}, |
| 8230 | {WCD934X_CDC_TX4_TX_PATH_CFG1, 0x01, 0x00}, |
| 8231 | {WCD934X_CDC_TX5_TX_PATH_CFG1, 0x01, 0x00}, |
| 8232 | {WCD934X_CDC_TX6_TX_PATH_CFG1, 0x01, 0x00}, |
| 8233 | {WCD934X_CDC_TX7_TX_PATH_CFG1, 0x01, 0x00}, |
| 8234 | {WCD934X_CDC_TX8_TX_PATH_CFG1, 0x01, 0x00}, |
| 8235 | {WCD934X_RX_OCP_CTL, 0x0F, 0x02}, /* OCP number of attempts is 2 */ |
| 8236 | {WCD934X_HPH_OCP_CTL, 0xFF, 0x3A}, /* OCP current limit */ |
| 8237 | {WCD934X_HPH_L_TEST, 0x01, 0x01}, |
| 8238 | {WCD934X_HPH_R_TEST, 0x01, 0x01}, |
| 8239 | {WCD934X_CPE_FLL_CONFIG_CTL_2, 0xFF, 0x20}, |
| 8240 | }; |
| 8241 | |
| 8242 | static const struct tavil_reg_mask_val tavil_codec_reg_init_1_1_val[] = { |
| 8243 | {WCD934X_CDC_COMPANDER1_CTL7, 0x1E, 0x06}, |
| 8244 | {WCD934X_CDC_COMPANDER2_CTL7, 0x1E, 0x06}, |
| 8245 | {WCD934X_HPH_NEW_INT_RDAC_HD2_CTL_L, 0xFF, 0x84}, |
| 8246 | {WCD934X_HPH_NEW_INT_RDAC_HD2_CTL_R, 0xFF, 0x84}, |
| 8247 | {WCD934X_CDC_RX3_RX_PATH_SEC0, 0xFC, 0xF4}, |
| 8248 | {WCD934X_CDC_RX4_RX_PATH_SEC0, 0xFC, 0xF4}, |
| 8249 | }; |
| 8250 | |
| 8251 | static const struct tavil_cpr_reg_defaults cpr_defaults[] = { |
| 8252 | { 0x00000820, 0x00000094 }, |
| 8253 | { 0x00000fC0, 0x00000048 }, |
| 8254 | { 0x0000f000, 0x00000044 }, |
| 8255 | { 0x0000bb80, 0xC0000178 }, |
| 8256 | { 0x00000000, 0x00000160 }, |
| 8257 | { 0x10854522, 0x00000060 }, |
| 8258 | { 0x10854509, 0x00000064 }, |
| 8259 | { 0x108544dd, 0x00000068 }, |
| 8260 | { 0x108544ad, 0x0000006C }, |
| 8261 | { 0x0000077E, 0x00000070 }, |
| 8262 | { 0x000007da, 0x00000074 }, |
| 8263 | { 0x00000000, 0x00000078 }, |
| 8264 | { 0x00000000, 0x0000007C }, |
| 8265 | { 0x00042029, 0x00000080 }, |
| 8266 | { 0x4002002A, 0x00000090 }, |
| 8267 | { 0x4002002B, 0x00000090 }, |
| 8268 | }; |
| 8269 | |
| 8270 | static const struct tavil_reg_mask_val tavil_codec_reg_init_common_val[] = { |
| 8271 | {WCD934X_CDC_CLSH_K2_MSB, 0x0F, 0x00}, |
| 8272 | {WCD934X_CDC_CLSH_K2_LSB, 0xFF, 0x60}, |
| 8273 | {WCD934X_CPE_SS_DMIC_CFG, 0x80, 0x00}, |
| 8274 | {WCD934X_CDC_BOOST0_BOOST_CTL, 0x70, 0x50}, |
| 8275 | {WCD934X_CDC_BOOST1_BOOST_CTL, 0x70, 0x50}, |
| 8276 | {WCD934X_CDC_RX7_RX_PATH_CFG1, 0x08, 0x08}, |
| 8277 | {WCD934X_CDC_RX8_RX_PATH_CFG1, 0x08, 0x08}, |
| 8278 | {WCD934X_CDC_TOP_TOP_CFG1, 0x02, 0x02}, |
| 8279 | {WCD934X_CDC_TOP_TOP_CFG1, 0x01, 0x01}, |
| 8280 | {WCD934X_CDC_TX9_SPKR_PROT_PATH_CFG0, 0x01, 0x01}, |
| 8281 | {WCD934X_CDC_TX10_SPKR_PROT_PATH_CFG0, 0x01, 0x01}, |
| 8282 | {WCD934X_CDC_TX11_SPKR_PROT_PATH_CFG0, 0x01, 0x01}, |
| 8283 | {WCD934X_CDC_TX12_SPKR_PROT_PATH_CFG0, 0x01, 0x01}, |
| 8284 | {WCD934X_DATA_HUB_SB_TX11_INP_CFG, 0x01, 0x01}, |
| 8285 | {WCD934X_CDC_CLK_RST_CTRL_FS_CNT_CONTROL, 0x01, 0x01}, |
| 8286 | {WCD934X_CDC_COMPANDER7_CTL3, 0x80, 0x80}, |
| 8287 | {WCD934X_CDC_COMPANDER8_CTL3, 0x80, 0x80}, |
| 8288 | {WCD934X_CDC_COMPANDER7_CTL7, 0x01, 0x01}, |
| 8289 | {WCD934X_CDC_COMPANDER8_CTL7, 0x01, 0x01}, |
| 8290 | {WCD934X_CODEC_RPM_CLK_GATE, 0x08, 0x00}, |
| 8291 | {WCD934X_TLMM_DMIC3_CLK_PINCFG, 0xFF, 0x0a}, |
| 8292 | {WCD934X_TLMM_DMIC3_DATA_PINCFG, 0xFF, 0x0a}, |
| 8293 | {WCD934X_CPE_SS_SVA_CFG, 0x60, 0x00}, |
| 8294 | }; |
| 8295 | |
| 8296 | static void tavil_codec_init_reg(struct tavil_priv *priv) |
| 8297 | { |
| 8298 | struct snd_soc_codec *codec = priv->codec; |
| 8299 | u32 i; |
| 8300 | |
| 8301 | for (i = 0; i < ARRAY_SIZE(tavil_codec_reg_init_common_val); i++) |
| 8302 | snd_soc_update_bits(codec, |
| 8303 | tavil_codec_reg_init_common_val[i].reg, |
| 8304 | tavil_codec_reg_init_common_val[i].mask, |
| 8305 | tavil_codec_reg_init_common_val[i].val); |
| 8306 | |
| 8307 | if (TAVIL_IS_1_1(priv->wcd9xxx)) { |
| 8308 | for (i = 0; i < ARRAY_SIZE(tavil_codec_reg_init_1_1_val); i++) |
| 8309 | snd_soc_update_bits(codec, |
| 8310 | tavil_codec_reg_init_1_1_val[i].reg, |
| 8311 | tavil_codec_reg_init_1_1_val[i].mask, |
| 8312 | tavil_codec_reg_init_1_1_val[i].val); |
| 8313 | } |
| 8314 | } |
| 8315 | |
| 8316 | static void tavil_update_reg_defaults(struct tavil_priv *tavil) |
| 8317 | { |
| 8318 | u32 i; |
| 8319 | struct wcd9xxx *wcd9xxx; |
| 8320 | |
| 8321 | wcd9xxx = tavil->wcd9xxx; |
| 8322 | for (i = 0; i < ARRAY_SIZE(tavil_codec_reg_defaults); i++) |
| 8323 | regmap_update_bits(wcd9xxx->regmap, |
| 8324 | tavil_codec_reg_defaults[i].reg, |
| 8325 | tavil_codec_reg_defaults[i].mask, |
| 8326 | tavil_codec_reg_defaults[i].val); |
| 8327 | } |
| 8328 | |
| 8329 | static void tavil_update_cpr_defaults(struct tavil_priv *tavil) |
| 8330 | { |
| 8331 | int i; |
| 8332 | struct wcd9xxx *wcd9xxx; |
| 8333 | |
| 8334 | wcd9xxx = tavil->wcd9xxx; |
| 8335 | if (!TAVIL_IS_1_1(wcd9xxx)) |
| 8336 | return; |
| 8337 | |
| 8338 | __tavil_cdc_mclk_enable(tavil, true); |
| 8339 | |
| 8340 | regmap_write(wcd9xxx->regmap, WCD934X_CODEC_CPR_SVS2_MIN_CX_VDD, 0x2C); |
| 8341 | regmap_update_bits(wcd9xxx->regmap, WCD934X_CODEC_RPM_CLK_GATE, |
| 8342 | 0x10, 0x00); |
| 8343 | |
| 8344 | for (i = 0; i < ARRAY_SIZE(cpr_defaults); i++) { |
| 8345 | regmap_bulk_write(wcd9xxx->regmap, |
| 8346 | WCD934X_CODEC_CPR_WR_DATA_0, |
| 8347 | (u8 *)&cpr_defaults[i].wr_data, 4); |
| 8348 | regmap_bulk_write(wcd9xxx->regmap, |
| 8349 | WCD934X_CODEC_CPR_WR_ADDR_0, |
| 8350 | (u8 *)&cpr_defaults[i].wr_addr, 4); |
| 8351 | } |
| 8352 | |
| 8353 | __tavil_cdc_mclk_enable(tavil, false); |
| 8354 | } |
| 8355 | |
| 8356 | static void tavil_slim_interface_init_reg(struct snd_soc_codec *codec) |
| 8357 | { |
| 8358 | int i; |
| 8359 | struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec); |
| 8360 | |
| 8361 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) |
| 8362 | wcd9xxx_interface_reg_write(priv->wcd9xxx, |
| 8363 | WCD934X_SLIM_PGD_PORT_INT_RX_EN0 + i, |
| 8364 | 0xFF); |
| 8365 | } |
| 8366 | |
| 8367 | static irqreturn_t tavil_misc_irq(int irq, void *data) |
| 8368 | { |
| 8369 | struct tavil_priv *tavil = data; |
| 8370 | int misc_val; |
| 8371 | |
| 8372 | /* Find source of interrupt */ |
| 8373 | regmap_read(tavil->wcd9xxx->regmap, WCD934X_INTR_CODEC_MISC_STATUS, |
| 8374 | &misc_val); |
| 8375 | |
| 8376 | if (misc_val & 0x08) { |
| 8377 | dev_info(tavil->dev, "%s: irq: %d, DSD DC detected!\n", |
| 8378 | __func__, irq); |
| 8379 | /* DSD DC interrupt, reset DSD path */ |
| 8380 | tavil_dsd_reset(tavil->dsd_config); |
| 8381 | } else { |
| 8382 | dev_err(tavil->dev, "%s: Codec misc irq: %d, val: 0x%x\n", |
| 8383 | __func__, irq, misc_val); |
| 8384 | } |
| 8385 | |
| 8386 | /* Clear interrupt status */ |
| 8387 | regmap_update_bits(tavil->wcd9xxx->regmap, |
| 8388 | WCD934X_INTR_CODEC_MISC_CLEAR, misc_val, 0x00); |
| 8389 | |
| 8390 | return IRQ_HANDLED; |
| 8391 | } |
| 8392 | |
| 8393 | static irqreturn_t tavil_slimbus_irq(int irq, void *data) |
| 8394 | { |
| 8395 | struct tavil_priv *tavil = data; |
| 8396 | unsigned long status = 0; |
| 8397 | int i, j, port_id, k; |
| 8398 | u32 bit; |
| 8399 | u8 val, int_val = 0; |
| 8400 | bool tx, cleared; |
| 8401 | unsigned short reg = 0; |
| 8402 | |
| 8403 | for (i = WCD934X_SLIM_PGD_PORT_INT_STATUS_RX_0, j = 0; |
| 8404 | i <= WCD934X_SLIM_PGD_PORT_INT_STATUS_TX_1; i++, j++) { |
| 8405 | val = wcd9xxx_interface_reg_read(tavil->wcd9xxx, i); |
| 8406 | status |= ((u32)val << (8 * j)); |
| 8407 | } |
| 8408 | |
| 8409 | for_each_set_bit(j, &status, 32) { |
| 8410 | tx = (j >= 16 ? true : false); |
| 8411 | port_id = (tx ? j - 16 : j); |
| 8412 | val = wcd9xxx_interface_reg_read(tavil->wcd9xxx, |
| 8413 | WCD934X_SLIM_PGD_PORT_INT_RX_SOURCE0 + j); |
| 8414 | if (val) { |
| 8415 | if (!tx) |
| 8416 | reg = WCD934X_SLIM_PGD_PORT_INT_RX_EN0 + |
| 8417 | (port_id / 8); |
| 8418 | else |
| 8419 | reg = WCD934X_SLIM_PGD_PORT_INT_TX_EN0 + |
| 8420 | (port_id / 8); |
| 8421 | int_val = wcd9xxx_interface_reg_read( |
| 8422 | tavil->wcd9xxx, reg); |
| 8423 | /* |
| 8424 | * Ignore interrupts for ports for which the |
| 8425 | * interrupts are not specifically enabled. |
| 8426 | */ |
| 8427 | if (!(int_val & (1 << (port_id % 8)))) |
| 8428 | continue; |
| 8429 | } |
| 8430 | if (val & WCD934X_SLIM_IRQ_OVERFLOW) |
| 8431 | dev_err_ratelimited(tavil->dev, "%s: overflow error on %s port %d, value %x\n", |
| 8432 | __func__, (tx ? "TX" : "RX"), port_id, val); |
| 8433 | if (val & WCD934X_SLIM_IRQ_UNDERFLOW) |
| 8434 | dev_err_ratelimited(tavil->dev, "%s: underflow error on %s port %d, value %x\n", |
| 8435 | __func__, (tx ? "TX" : "RX"), port_id, val); |
| 8436 | if ((val & WCD934X_SLIM_IRQ_OVERFLOW) || |
| 8437 | (val & WCD934X_SLIM_IRQ_UNDERFLOW)) { |
| 8438 | if (!tx) |
| 8439 | reg = WCD934X_SLIM_PGD_PORT_INT_RX_EN0 + |
| 8440 | (port_id / 8); |
| 8441 | else |
| 8442 | reg = WCD934X_SLIM_PGD_PORT_INT_TX_EN0 + |
| 8443 | (port_id / 8); |
| 8444 | int_val = wcd9xxx_interface_reg_read( |
| 8445 | tavil->wcd9xxx, reg); |
| 8446 | if (int_val & (1 << (port_id % 8))) { |
| 8447 | int_val = int_val ^ (1 << (port_id % 8)); |
| 8448 | wcd9xxx_interface_reg_write(tavil->wcd9xxx, |
| 8449 | reg, int_val); |
| 8450 | } |
| 8451 | } |
| 8452 | if (val & WCD934X_SLIM_IRQ_PORT_CLOSED) { |
| 8453 | /* |
| 8454 | * INT SOURCE register starts from RX to TX |
| 8455 | * but port number in the ch_mask is in opposite way |
| 8456 | */ |
| 8457 | bit = (tx ? j - 16 : j + 16); |
| 8458 | dev_dbg(tavil->dev, "%s: %s port %d closed value %x, bit %u\n", |
| 8459 | __func__, (tx ? "TX" : "RX"), port_id, val, |
| 8460 | bit); |
| 8461 | for (k = 0, cleared = false; k < NUM_CODEC_DAIS; k++) { |
| 8462 | dev_dbg(tavil->dev, "%s: tavil->dai[%d].ch_mask = 0x%lx\n", |
| 8463 | __func__, k, tavil->dai[k].ch_mask); |
| 8464 | if (test_and_clear_bit(bit, |
| 8465 | &tavil->dai[k].ch_mask)) { |
| 8466 | cleared = true; |
| 8467 | if (!tavil->dai[k].ch_mask) |
| 8468 | wake_up( |
| 8469 | &tavil->dai[k].dai_wait); |
| 8470 | /* |
| 8471 | * There are cases when multiple DAIs |
| 8472 | * might be using the same slimbus |
| 8473 | * channel. Hence don't break here. |
| 8474 | */ |
| 8475 | } |
| 8476 | } |
| 8477 | WARN(!cleared, |
| 8478 | "Couldn't find slimbus %s port %d for closing\n", |
| 8479 | (tx ? "TX" : "RX"), port_id); |
| 8480 | } |
| 8481 | wcd9xxx_interface_reg_write(tavil->wcd9xxx, |
| 8482 | WCD934X_SLIM_PGD_PORT_INT_CLR_RX_0 + |
| 8483 | (j / 8), |
| 8484 | 1 << (j % 8)); |
| 8485 | } |
| 8486 | |
| 8487 | return IRQ_HANDLED; |
| 8488 | } |
| 8489 | |
| 8490 | static int tavil_setup_irqs(struct tavil_priv *tavil) |
| 8491 | { |
| 8492 | int ret = 0; |
| 8493 | struct snd_soc_codec *codec = tavil->codec; |
| 8494 | struct wcd9xxx *wcd9xxx = tavil->wcd9xxx; |
| 8495 | struct wcd9xxx_core_resource *core_res = |
| 8496 | &wcd9xxx->core_res; |
| 8497 | |
| 8498 | ret = wcd9xxx_request_irq(core_res, WCD9XXX_IRQ_SLIMBUS, |
| 8499 | tavil_slimbus_irq, "SLIMBUS Slave", tavil); |
| 8500 | if (ret) |
| 8501 | dev_err(codec->dev, "%s: Failed to request irq %d\n", __func__, |
| 8502 | WCD9XXX_IRQ_SLIMBUS); |
| 8503 | else |
| 8504 | tavil_slim_interface_init_reg(codec); |
| 8505 | |
| 8506 | /* Register for misc interrupts as well */ |
| 8507 | ret = wcd9xxx_request_irq(core_res, WCD934X_IRQ_MISC, |
| 8508 | tavil_misc_irq, "CDC MISC Irq", tavil); |
| 8509 | if (ret) |
| 8510 | dev_err(codec->dev, "%s: Failed to request cdc misc irq\n", |
| 8511 | __func__); |
| 8512 | |
| 8513 | return ret; |
| 8514 | } |
| 8515 | |
| 8516 | static void tavil_init_slim_slave_cfg(struct snd_soc_codec *codec) |
| 8517 | { |
| 8518 | struct tavil_priv *priv = snd_soc_codec_get_drvdata(codec); |
| 8519 | struct afe_param_cdc_slimbus_slave_cfg *cfg; |
| 8520 | struct wcd9xxx *wcd9xxx = priv->wcd9xxx; |
| 8521 | uint64_t eaddr = 0; |
| 8522 | |
| 8523 | cfg = &priv->slimbus_slave_cfg; |
| 8524 | cfg->minor_version = 1; |
| 8525 | cfg->tx_slave_port_offset = 0; |
| 8526 | cfg->rx_slave_port_offset = 16; |
| 8527 | |
| 8528 | memcpy(&eaddr, &wcd9xxx->slim->e_addr, sizeof(wcd9xxx->slim->e_addr)); |
| 8529 | WARN_ON(sizeof(wcd9xxx->slim->e_addr) != 6); |
| 8530 | cfg->device_enum_addr_lsw = eaddr & 0xFFFFFFFF; |
| 8531 | cfg->device_enum_addr_msw = eaddr >> 32; |
| 8532 | |
| 8533 | dev_dbg(codec->dev, "%s: slimbus logical address 0x%llx\n", |
| 8534 | __func__, eaddr); |
| 8535 | } |
| 8536 | |
| 8537 | static void tavil_cleanup_irqs(struct tavil_priv *tavil) |
| 8538 | { |
| 8539 | struct wcd9xxx *wcd9xxx = tavil->wcd9xxx; |
| 8540 | struct wcd9xxx_core_resource *core_res = |
| 8541 | &wcd9xxx->core_res; |
| 8542 | |
| 8543 | wcd9xxx_free_irq(core_res, WCD9XXX_IRQ_SLIMBUS, tavil); |
| 8544 | wcd9xxx_free_irq(core_res, WCD934X_IRQ_MISC, tavil); |
| 8545 | } |
| 8546 | |
| 8547 | /* |
| 8548 | * wcd934x_get_micb_vout_ctl_val: converts micbias from volts to register value |
| 8549 | * @micb_mv: micbias in mv |
| 8550 | * |
| 8551 | * return register value converted |
| 8552 | */ |
| 8553 | int wcd934x_get_micb_vout_ctl_val(u32 micb_mv) |
| 8554 | { |
| 8555 | /* min micbias voltage is 1V and maximum is 2.85V */ |
| 8556 | if (micb_mv < 1000 || micb_mv > 2850) { |
| 8557 | pr_err("%s: unsupported micbias voltage\n", __func__); |
| 8558 | return -EINVAL; |
| 8559 | } |
| 8560 | |
| 8561 | return (micb_mv - 1000) / 50; |
| 8562 | } |
| 8563 | EXPORT_SYMBOL(wcd934x_get_micb_vout_ctl_val); |
| 8564 | |
| 8565 | static int tavil_handle_pdata(struct tavil_priv *tavil, |
| 8566 | struct wcd9xxx_pdata *pdata) |
| 8567 | { |
| 8568 | struct snd_soc_codec *codec = tavil->codec; |
| 8569 | u8 mad_dmic_ctl_val; |
| 8570 | u8 anc_ctl_value; |
| 8571 | u32 def_dmic_rate, dmic_clk_drv; |
| 8572 | int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4; |
| 8573 | int rc = 0; |
| 8574 | |
| 8575 | if (!pdata) { |
| 8576 | dev_err(codec->dev, "%s: NULL pdata\n", __func__); |
| 8577 | return -ENODEV; |
| 8578 | } |
| 8579 | |
| 8580 | /* set micbias voltage */ |
| 8581 | vout_ctl_1 = wcd934x_get_micb_vout_ctl_val(pdata->micbias.micb1_mv); |
| 8582 | vout_ctl_2 = wcd934x_get_micb_vout_ctl_val(pdata->micbias.micb2_mv); |
| 8583 | vout_ctl_3 = wcd934x_get_micb_vout_ctl_val(pdata->micbias.micb3_mv); |
| 8584 | vout_ctl_4 = wcd934x_get_micb_vout_ctl_val(pdata->micbias.micb4_mv); |
Xiaoyu Ye | 1a2d8bd9 | 2017-01-31 18:54:15 -0800 | [diff] [blame] | 8585 | if (vout_ctl_1 < 0 || vout_ctl_2 < 0 || |
| 8586 | vout_ctl_3 < 0 || vout_ctl_4 < 0) { |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 8587 | rc = -EINVAL; |
| 8588 | goto done; |
| 8589 | } |
| 8590 | snd_soc_update_bits(codec, WCD934X_ANA_MICB1, 0x3F, vout_ctl_1); |
| 8591 | snd_soc_update_bits(codec, WCD934X_ANA_MICB2, 0x3F, vout_ctl_2); |
| 8592 | snd_soc_update_bits(codec, WCD934X_ANA_MICB3, 0x3F, vout_ctl_3); |
| 8593 | snd_soc_update_bits(codec, WCD934X_ANA_MICB4, 0x3F, vout_ctl_4); |
| 8594 | |
| 8595 | /* Set the DMIC sample rate */ |
| 8596 | switch (pdata->mclk_rate) { |
| 8597 | case WCD934X_MCLK_CLK_9P6MHZ: |
| 8598 | def_dmic_rate = WCD9XXX_DMIC_SAMPLE_RATE_4P8MHZ; |
| 8599 | break; |
| 8600 | case WCD934X_MCLK_CLK_12P288MHZ: |
| 8601 | def_dmic_rate = WCD9XXX_DMIC_SAMPLE_RATE_4P096MHZ; |
| 8602 | break; |
| 8603 | default: |
| 8604 | /* should never happen */ |
| 8605 | dev_err(codec->dev, "%s: Invalid mclk_rate %d\n", |
| 8606 | __func__, pdata->mclk_rate); |
| 8607 | rc = -EINVAL; |
| 8608 | goto done; |
| 8609 | }; |
| 8610 | |
| 8611 | if (pdata->dmic_sample_rate == |
| 8612 | WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED) { |
| 8613 | dev_info(codec->dev, "%s: dmic_rate invalid default = %d\n", |
| 8614 | __func__, def_dmic_rate); |
| 8615 | pdata->dmic_sample_rate = def_dmic_rate; |
| 8616 | } |
| 8617 | if (pdata->mad_dmic_sample_rate == |
| 8618 | WCD9XXX_DMIC_SAMPLE_RATE_UNDEFINED) { |
| 8619 | dev_info(codec->dev, "%s: mad_dmic_rate invalid default = %d\n", |
| 8620 | __func__, def_dmic_rate); |
| 8621 | /* |
| 8622 | * use dmic_sample_rate as the default for MAD |
| 8623 | * if mad dmic sample rate is undefined |
| 8624 | */ |
| 8625 | pdata->mad_dmic_sample_rate = pdata->dmic_sample_rate; |
| 8626 | } |
| 8627 | |
| 8628 | if (pdata->dmic_clk_drv == |
| 8629 | WCD9XXX_DMIC_CLK_DRIVE_UNDEFINED) { |
| 8630 | pdata->dmic_clk_drv = WCD934X_DMIC_CLK_DRIVE_DEFAULT; |
Karthikeyan Mani | 3570e6c | 2016-11-14 11:05:53 -0800 | [diff] [blame] | 8631 | dev_dbg(codec->dev, |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 8632 | "%s: dmic_clk_strength invalid, default = %d\n", |
| 8633 | __func__, pdata->dmic_clk_drv); |
| 8634 | } |
| 8635 | |
| 8636 | switch (pdata->dmic_clk_drv) { |
| 8637 | case 2: |
| 8638 | dmic_clk_drv = 0; |
| 8639 | break; |
| 8640 | case 4: |
| 8641 | dmic_clk_drv = 1; |
| 8642 | break; |
| 8643 | case 8: |
| 8644 | dmic_clk_drv = 2; |
| 8645 | break; |
| 8646 | case 16: |
| 8647 | dmic_clk_drv = 3; |
| 8648 | break; |
| 8649 | default: |
| 8650 | dev_err(codec->dev, |
| 8651 | "%s: invalid dmic_clk_drv %d, using default\n", |
| 8652 | __func__, pdata->dmic_clk_drv); |
| 8653 | dmic_clk_drv = 0; |
| 8654 | break; |
| 8655 | } |
| 8656 | |
| 8657 | snd_soc_update_bits(codec, WCD934X_TEST_DEBUG_PAD_DRVCTL_0, |
| 8658 | 0x0C, dmic_clk_drv << 2); |
| 8659 | |
| 8660 | /* |
| 8661 | * Default the DMIC clk rates to mad_dmic_sample_rate, |
| 8662 | * whereas, the anc/txfe dmic rates to dmic_sample_rate |
| 8663 | * since the anc/txfe are independent of mad block. |
| 8664 | */ |
| 8665 | mad_dmic_ctl_val = tavil_get_dmic_clk_val(tavil->codec, |
| 8666 | pdata->mclk_rate, |
| 8667 | pdata->mad_dmic_sample_rate); |
| 8668 | snd_soc_update_bits(codec, WCD934X_CPE_SS_DMIC0_CTL, |
| 8669 | 0x0E, mad_dmic_ctl_val << 1); |
| 8670 | snd_soc_update_bits(codec, WCD934X_CPE_SS_DMIC1_CTL, |
| 8671 | 0x0E, mad_dmic_ctl_val << 1); |
| 8672 | snd_soc_update_bits(codec, WCD934X_CPE_SS_DMIC2_CTL, |
| 8673 | 0x0E, mad_dmic_ctl_val << 1); |
| 8674 | |
| 8675 | if (dmic_clk_drv == WCD934X_DMIC_CLK_DIV_2) |
| 8676 | anc_ctl_value = WCD934X_ANC_DMIC_X2_FULL_RATE; |
| 8677 | else |
| 8678 | anc_ctl_value = WCD934X_ANC_DMIC_X2_HALF_RATE; |
| 8679 | |
| 8680 | snd_soc_update_bits(codec, WCD934X_CDC_ANC0_MODE_2_CTL, |
| 8681 | 0x40, anc_ctl_value << 6); |
| 8682 | snd_soc_update_bits(codec, WCD934X_CDC_ANC0_MODE_2_CTL, |
| 8683 | 0x20, anc_ctl_value << 5); |
| 8684 | snd_soc_update_bits(codec, WCD934X_CDC_ANC1_MODE_2_CTL, |
| 8685 | 0x40, anc_ctl_value << 6); |
| 8686 | snd_soc_update_bits(codec, WCD934X_CDC_ANC1_MODE_2_CTL, |
| 8687 | 0x20, anc_ctl_value << 5); |
| 8688 | |
| 8689 | done: |
| 8690 | return rc; |
| 8691 | } |
| 8692 | |
| 8693 | static void tavil_cdc_vote_svs(struct snd_soc_codec *codec, bool vote) |
| 8694 | { |
| 8695 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 8696 | |
| 8697 | return tavil_vote_svs(tavil, vote); |
| 8698 | } |
| 8699 | |
| 8700 | struct wcd_dsp_cdc_cb cdc_cb = { |
| 8701 | .cdc_clk_en = tavil_codec_internal_rco_ctrl, |
| 8702 | .cdc_vote_svs = tavil_cdc_vote_svs, |
| 8703 | }; |
| 8704 | |
| 8705 | static int tavil_wdsp_initialize(struct snd_soc_codec *codec) |
| 8706 | { |
| 8707 | struct wcd9xxx *control; |
| 8708 | struct tavil_priv *tavil; |
| 8709 | struct wcd_dsp_params params; |
| 8710 | int ret = 0; |
| 8711 | |
| 8712 | control = dev_get_drvdata(codec->dev->parent); |
| 8713 | tavil = snd_soc_codec_get_drvdata(codec); |
| 8714 | |
| 8715 | params.cb = &cdc_cb; |
| 8716 | params.irqs.cpe_ipc1_irq = WCD934X_IRQ_CPE1_INTR; |
| 8717 | params.irqs.cpe_err_irq = WCD934X_IRQ_CPE_ERROR; |
| 8718 | params.irqs.fatal_irqs = CPE_FATAL_IRQS; |
| 8719 | params.clk_rate = control->mclk_rate; |
| 8720 | params.dsp_instance = 0; |
| 8721 | |
| 8722 | wcd_dsp_cntl_init(codec, ¶ms, &tavil->wdsp_cntl); |
| 8723 | if (!tavil->wdsp_cntl) { |
| 8724 | dev_err(tavil->dev, "%s: wcd-dsp-control init failed\n", |
| 8725 | __func__); |
| 8726 | ret = -EINVAL; |
| 8727 | } |
| 8728 | |
| 8729 | return ret; |
| 8730 | } |
| 8731 | |
| 8732 | /* |
| 8733 | * tavil_soc_get_mbhc: get wcd934x_mbhc handle of corresponding codec |
| 8734 | * @codec: handle to snd_soc_codec * |
| 8735 | * |
| 8736 | * return wcd934x_mbhc handle or error code in case of failure |
| 8737 | */ |
| 8738 | struct wcd934x_mbhc *tavil_soc_get_mbhc(struct snd_soc_codec *codec) |
| 8739 | { |
| 8740 | struct tavil_priv *tavil; |
| 8741 | |
| 8742 | if (!codec) { |
| 8743 | pr_err("%s: Invalid params, NULL codec\n", __func__); |
| 8744 | return NULL; |
| 8745 | } |
| 8746 | tavil = snd_soc_codec_get_drvdata(codec); |
| 8747 | |
| 8748 | if (!tavil) { |
| 8749 | pr_err("%s: Invalid params, NULL tavil\n", __func__); |
| 8750 | return NULL; |
| 8751 | } |
| 8752 | |
| 8753 | return tavil->mbhc; |
| 8754 | } |
| 8755 | EXPORT_SYMBOL(tavil_soc_get_mbhc); |
| 8756 | |
| 8757 | static void tavil_mclk2_reg_defaults(struct tavil_priv *tavil) |
| 8758 | { |
| 8759 | int i; |
| 8760 | struct snd_soc_codec *codec = tavil->codec; |
| 8761 | |
| 8762 | if (TAVIL_IS_1_0(tavil->wcd9xxx)) { |
| 8763 | /* MCLK2 configuration */ |
| 8764 | for (i = 0; i < ARRAY_SIZE(tavil_codec_mclk2_1_0_defaults); i++) |
| 8765 | snd_soc_update_bits(codec, |
| 8766 | tavil_codec_mclk2_1_0_defaults[i].reg, |
| 8767 | tavil_codec_mclk2_1_0_defaults[i].mask, |
| 8768 | tavil_codec_mclk2_1_0_defaults[i].val); |
| 8769 | } |
| 8770 | if (TAVIL_IS_1_1(tavil->wcd9xxx)) { |
| 8771 | /* MCLK2 configuration */ |
| 8772 | for (i = 0; i < ARRAY_SIZE(tavil_codec_mclk2_1_1_defaults); i++) |
| 8773 | snd_soc_update_bits(codec, |
| 8774 | tavil_codec_mclk2_1_1_defaults[i].reg, |
| 8775 | tavil_codec_mclk2_1_1_defaults[i].mask, |
| 8776 | tavil_codec_mclk2_1_1_defaults[i].val); |
| 8777 | } |
| 8778 | } |
| 8779 | |
| 8780 | static int tavil_device_down(struct wcd9xxx *wcd9xxx) |
| 8781 | { |
| 8782 | struct snd_soc_codec *codec; |
| 8783 | struct tavil_priv *priv; |
| 8784 | int count; |
| 8785 | |
| 8786 | codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv); |
| 8787 | priv = snd_soc_codec_get_drvdata(codec); |
| 8788 | swrm_wcd_notify(priv->swr.ctrl_data[0].swr_pdev, |
| 8789 | SWR_DEVICE_DOWN, NULL); |
| 8790 | tavil_dsd_reset(priv->dsd_config); |
| 8791 | snd_soc_card_change_online_state(codec->component.card, 0); |
| 8792 | for (count = 0; count < NUM_CODEC_DAIS; count++) |
| 8793 | priv->dai[count].bus_down_in_recovery = true; |
| 8794 | wcd_dsp_ssr_event(priv->wdsp_cntl, WCD_CDC_DOWN_EVENT); |
| 8795 | wcd_resmgr_set_sido_input_src_locked(priv->resmgr, |
| 8796 | SIDO_SOURCE_INTERNAL); |
| 8797 | |
| 8798 | return 0; |
| 8799 | } |
| 8800 | |
| 8801 | static int tavil_post_reset_cb(struct wcd9xxx *wcd9xxx) |
| 8802 | { |
| 8803 | int i, ret = 0; |
| 8804 | struct wcd9xxx *control; |
| 8805 | struct snd_soc_codec *codec; |
| 8806 | struct tavil_priv *tavil; |
| 8807 | struct wcd9xxx_pdata *pdata; |
| 8808 | struct wcd_mbhc *mbhc; |
| 8809 | |
| 8810 | codec = (struct snd_soc_codec *)(wcd9xxx->ssr_priv); |
| 8811 | tavil = snd_soc_codec_get_drvdata(codec); |
| 8812 | control = dev_get_drvdata(codec->dev->parent); |
| 8813 | |
| 8814 | wcd9xxx_set_power_state(tavil->wcd9xxx, |
| 8815 | WCD_REGION_POWER_COLLAPSE_REMOVE, |
| 8816 | WCD9XXX_DIG_CORE_REGION_1); |
| 8817 | |
| 8818 | mutex_lock(&tavil->codec_mutex); |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 8819 | |
Vidyakumar Athota | ae60b99 | 2017-01-04 11:21:48 -0800 | [diff] [blame] | 8820 | tavil_vote_svs(tavil, true); |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 8821 | tavil_slimbus_slave_port_cfg.slave_dev_intfdev_la = |
| 8822 | control->slim_slave->laddr; |
| 8823 | tavil_slimbus_slave_port_cfg.slave_dev_pgd_la = |
| 8824 | control->slim->laddr; |
| 8825 | tavil_init_slim_slave_cfg(codec); |
| 8826 | snd_soc_card_change_online_state(codec->component.card, 1); |
| 8827 | |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 8828 | for (i = 0; i < TAVIL_MAX_MICBIAS; i++) |
| 8829 | tavil->micb_ref[i] = 0; |
| 8830 | |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 8831 | dev_dbg(codec->dev, "%s: MCLK Rate = %x\n", |
| 8832 | __func__, control->mclk_rate); |
| 8833 | |
| 8834 | if (control->mclk_rate == WCD934X_MCLK_CLK_12P288MHZ) |
| 8835 | snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_MCLK_CFG, |
| 8836 | 0x03, 0x00); |
| 8837 | else if (control->mclk_rate == WCD934X_MCLK_CLK_9P6MHZ) |
| 8838 | snd_soc_update_bits(codec, WCD934X_CODEC_RPM_CLK_MCLK_CFG, |
| 8839 | 0x03, 0x01); |
| 8840 | wcd_resmgr_post_ssr_v2(tavil->resmgr); |
| 8841 | tavil_update_reg_defaults(tavil); |
| 8842 | tavil_codec_init_reg(tavil); |
| 8843 | __tavil_enable_efuse_sensing(tavil); |
| 8844 | tavil_mclk2_reg_defaults(tavil); |
| 8845 | |
| 8846 | __tavil_cdc_mclk_enable(tavil, true); |
| 8847 | regcache_mark_dirty(codec->component.regmap); |
| 8848 | regcache_sync(codec->component.regmap); |
| 8849 | __tavil_cdc_mclk_enable(tavil, false); |
| 8850 | |
| 8851 | tavil_update_cpr_defaults(tavil); |
| 8852 | |
| 8853 | pdata = dev_get_platdata(codec->dev->parent); |
| 8854 | ret = tavil_handle_pdata(tavil, pdata); |
Xiaoyu Ye | 1a2d8bd9 | 2017-01-31 18:54:15 -0800 | [diff] [blame] | 8855 | if (ret < 0) |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 8856 | dev_err(codec->dev, "%s: invalid pdata\n", __func__); |
| 8857 | |
| 8858 | /* Initialize MBHC module */ |
| 8859 | mbhc = &tavil->mbhc->wcd_mbhc; |
| 8860 | ret = tavil_mbhc_post_ssr_init(tavil->mbhc, codec); |
| 8861 | if (ret) { |
| 8862 | dev_err(codec->dev, "%s: mbhc initialization failed\n", |
| 8863 | __func__); |
| 8864 | goto done; |
| 8865 | } else { |
| 8866 | tavil_mbhc_hs_detect(codec, mbhc->mbhc_cfg); |
| 8867 | } |
| 8868 | |
| 8869 | /* DSD initialization */ |
| 8870 | ret = tavil_dsd_post_ssr_init(tavil->dsd_config); |
| 8871 | if (ret) |
| 8872 | dev_dbg(tavil->dev, "%s: DSD init failed\n", __func__); |
| 8873 | |
| 8874 | tavil_cleanup_irqs(tavil); |
| 8875 | ret = tavil_setup_irqs(tavil); |
| 8876 | if (ret) { |
| 8877 | dev_err(codec->dev, "%s: tavil irq setup failed %d\n", |
| 8878 | __func__, ret); |
| 8879 | goto done; |
| 8880 | } |
| 8881 | |
| 8882 | tavil_set_spkr_mode(codec, tavil->swr.spkr_mode); |
| 8883 | /* |
| 8884 | * Once the codec initialization is completed, the svs vote |
| 8885 | * can be released allowing the codec to go to SVS2. |
| 8886 | */ |
| 8887 | tavil_vote_svs(tavil, false); |
| 8888 | wcd_dsp_ssr_event(tavil->wdsp_cntl, WCD_CDC_UP_EVENT); |
| 8889 | |
| 8890 | done: |
| 8891 | mutex_unlock(&tavil->codec_mutex); |
| 8892 | return ret; |
| 8893 | } |
| 8894 | |
Banajit Goswami | 2be7b48 | 2017-02-03 23:32:37 -0800 | [diff] [blame] | 8895 | static int tavil_soc_codec_probe(struct snd_soc_codec *codec) |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 8896 | { |
| 8897 | struct wcd9xxx *control; |
| 8898 | struct tavil_priv *tavil; |
| 8899 | struct wcd9xxx_pdata *pdata; |
| 8900 | struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec); |
| 8901 | int i, ret; |
| 8902 | void *ptr = NULL; |
| 8903 | |
| 8904 | control = dev_get_drvdata(codec->dev->parent); |
| 8905 | |
| 8906 | dev_info(codec->dev, "%s()\n", __func__); |
| 8907 | tavil = snd_soc_codec_get_drvdata(codec); |
| 8908 | tavil->intf_type = wcd9xxx_get_intf_type(); |
| 8909 | |
| 8910 | control->dev_down = tavil_device_down; |
| 8911 | control->post_reset = tavil_post_reset_cb; |
| 8912 | control->ssr_priv = (void *)codec; |
| 8913 | |
| 8914 | /* Resource Manager post Init */ |
| 8915 | ret = wcd_resmgr_post_init(tavil->resmgr, &tavil_resmgr_cb, codec); |
| 8916 | if (ret) { |
| 8917 | dev_err(codec->dev, "%s: wcd resmgr post init failed\n", |
| 8918 | __func__); |
| 8919 | goto err; |
| 8920 | } |
| 8921 | /* Class-H Init */ |
| 8922 | wcd_clsh_init(&tavil->clsh_d); |
| 8923 | /* Default HPH Mode to Class-H Low HiFi */ |
| 8924 | tavil->hph_mode = CLS_H_LOHIFI; |
| 8925 | |
| 8926 | tavil->fw_data = devm_kzalloc(codec->dev, sizeof(*(tavil->fw_data)), |
| 8927 | GFP_KERNEL); |
| 8928 | if (!tavil->fw_data) |
| 8929 | goto err; |
| 8930 | |
| 8931 | set_bit(WCD9XXX_ANC_CAL, tavil->fw_data->cal_bit); |
| 8932 | set_bit(WCD9XXX_MBHC_CAL, tavil->fw_data->cal_bit); |
| 8933 | set_bit(WCD9XXX_MAD_CAL, tavil->fw_data->cal_bit); |
| 8934 | set_bit(WCD9XXX_VBAT_CAL, tavil->fw_data->cal_bit); |
| 8935 | |
| 8936 | ret = wcd_cal_create_hwdep(tavil->fw_data, |
| 8937 | WCD9XXX_CODEC_HWDEP_NODE, codec); |
Xiaoyu Ye | 1a2d8bd9 | 2017-01-31 18:54:15 -0800 | [diff] [blame] | 8938 | if (ret < 0) { |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 8939 | dev_err(codec->dev, "%s hwdep failed %d\n", __func__, ret); |
| 8940 | goto err_hwdep; |
| 8941 | } |
| 8942 | |
| 8943 | /* Initialize MBHC module */ |
| 8944 | ret = tavil_mbhc_init(&tavil->mbhc, codec, tavil->fw_data); |
| 8945 | if (ret) { |
| 8946 | pr_err("%s: mbhc initialization failed\n", __func__); |
| 8947 | goto err_hwdep; |
| 8948 | } |
| 8949 | |
| 8950 | tavil->codec = codec; |
| 8951 | for (i = 0; i < COMPANDER_MAX; i++) |
| 8952 | tavil->comp_enabled[i] = 0; |
| 8953 | |
| 8954 | tavil_codec_init_reg(tavil); |
| 8955 | |
| 8956 | pdata = dev_get_platdata(codec->dev->parent); |
| 8957 | ret = tavil_handle_pdata(tavil, pdata); |
Xiaoyu Ye | 1a2d8bd9 | 2017-01-31 18:54:15 -0800 | [diff] [blame] | 8958 | if (ret < 0) { |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 8959 | dev_err(codec->dev, "%s: bad pdata\n", __func__); |
| 8960 | goto err_hwdep; |
| 8961 | } |
| 8962 | |
| 8963 | ptr = devm_kzalloc(codec->dev, (sizeof(tavil_rx_chs) + |
| 8964 | sizeof(tavil_tx_chs)), GFP_KERNEL); |
| 8965 | if (!ptr) { |
| 8966 | ret = -ENOMEM; |
| 8967 | goto err_hwdep; |
| 8968 | } |
| 8969 | |
| 8970 | snd_soc_dapm_add_routes(dapm, tavil_slim_audio_map, |
| 8971 | ARRAY_SIZE(tavil_slim_audio_map)); |
| 8972 | for (i = 0; i < NUM_CODEC_DAIS; i++) { |
| 8973 | INIT_LIST_HEAD(&tavil->dai[i].wcd9xxx_ch_list); |
| 8974 | init_waitqueue_head(&tavil->dai[i].dai_wait); |
| 8975 | } |
| 8976 | tavil_slimbus_slave_port_cfg.slave_dev_intfdev_la = |
| 8977 | control->slim_slave->laddr; |
| 8978 | tavil_slimbus_slave_port_cfg.slave_dev_pgd_la = |
| 8979 | control->slim->laddr; |
| 8980 | tavil_slimbus_slave_port_cfg.slave_port_mapping[0] = |
| 8981 | WCD934X_TX13; |
| 8982 | tavil_init_slim_slave_cfg(codec); |
| 8983 | |
| 8984 | control->num_rx_port = WCD934X_RX_MAX; |
| 8985 | control->rx_chs = ptr; |
| 8986 | memcpy(control->rx_chs, tavil_rx_chs, sizeof(tavil_rx_chs)); |
| 8987 | control->num_tx_port = WCD934X_TX_MAX; |
| 8988 | control->tx_chs = ptr + sizeof(tavil_rx_chs); |
| 8989 | memcpy(control->tx_chs, tavil_tx_chs, sizeof(tavil_tx_chs)); |
| 8990 | |
| 8991 | ret = tavil_setup_irqs(tavil); |
| 8992 | if (ret) { |
| 8993 | dev_err(tavil->dev, "%s: tavil irq setup failed %d\n", |
| 8994 | __func__, ret); |
| 8995 | goto err_pdata; |
| 8996 | } |
| 8997 | |
| 8998 | for (i = 0; i < WCD934X_NUM_DECIMATORS; i++) { |
| 8999 | tavil->tx_hpf_work[i].tavil = tavil; |
| 9000 | tavil->tx_hpf_work[i].decimator = i; |
| 9001 | INIT_DELAYED_WORK(&tavil->tx_hpf_work[i].dwork, |
| 9002 | tavil_tx_hpf_corner_freq_callback); |
| 9003 | |
| 9004 | tavil->tx_mute_dwork[i].tavil = tavil; |
| 9005 | tavil->tx_mute_dwork[i].decimator = i; |
| 9006 | INIT_DELAYED_WORK(&tavil->tx_mute_dwork[i].dwork, |
| 9007 | tavil_tx_mute_update_callback); |
| 9008 | } |
| 9009 | |
| 9010 | tavil->spk_anc_dwork.tavil = tavil; |
| 9011 | INIT_DELAYED_WORK(&tavil->spk_anc_dwork.dwork, |
| 9012 | tavil_spk_anc_update_callback); |
| 9013 | |
| 9014 | tavil_mclk2_reg_defaults(tavil); |
| 9015 | |
| 9016 | /* DSD initialization */ |
| 9017 | tavil->dsd_config = tavil_dsd_init(codec); |
| 9018 | if (IS_ERR_OR_NULL(tavil->dsd_config)) |
| 9019 | dev_dbg(tavil->dev, "%s: DSD init failed\n", __func__); |
| 9020 | |
| 9021 | mutex_lock(&tavil->codec_mutex); |
| 9022 | snd_soc_dapm_disable_pin(dapm, "ANC EAR PA"); |
| 9023 | snd_soc_dapm_disable_pin(dapm, "ANC EAR"); |
| 9024 | snd_soc_dapm_enable_pin(dapm, "ANC SPK1 PA"); |
| 9025 | mutex_unlock(&tavil->codec_mutex); |
| 9026 | |
| 9027 | snd_soc_dapm_ignore_suspend(dapm, "AIF1 Playback"); |
| 9028 | snd_soc_dapm_ignore_suspend(dapm, "AIF1 Capture"); |
| 9029 | snd_soc_dapm_ignore_suspend(dapm, "AIF2 Playback"); |
| 9030 | snd_soc_dapm_ignore_suspend(dapm, "AIF2 Capture"); |
| 9031 | snd_soc_dapm_ignore_suspend(dapm, "AIF3 Playback"); |
| 9032 | snd_soc_dapm_ignore_suspend(dapm, "AIF3 Capture"); |
| 9033 | snd_soc_dapm_ignore_suspend(dapm, "AIF4 Playback"); |
| 9034 | snd_soc_dapm_ignore_suspend(dapm, "VIfeed"); |
| 9035 | |
| 9036 | snd_soc_dapm_sync(dapm); |
| 9037 | |
| 9038 | tavil_wdsp_initialize(codec); |
| 9039 | |
| 9040 | /* |
| 9041 | * Once the codec initialization is completed, the svs vote |
| 9042 | * can be released allowing the codec to go to SVS2. |
| 9043 | */ |
| 9044 | tavil_vote_svs(tavil, false); |
| 9045 | |
| 9046 | return ret; |
| 9047 | |
| 9048 | err_pdata: |
| 9049 | devm_kfree(codec->dev, ptr); |
| 9050 | control->rx_chs = NULL; |
| 9051 | control->tx_chs = NULL; |
| 9052 | err_hwdep: |
| 9053 | devm_kfree(codec->dev, tavil->fw_data); |
| 9054 | tavil->fw_data = NULL; |
| 9055 | err: |
| 9056 | return ret; |
| 9057 | } |
| 9058 | |
Banajit Goswami | 2be7b48 | 2017-02-03 23:32:37 -0800 | [diff] [blame] | 9059 | static int tavil_soc_codec_remove(struct snd_soc_codec *codec) |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 9060 | { |
| 9061 | struct wcd9xxx *control; |
| 9062 | struct tavil_priv *tavil = snd_soc_codec_get_drvdata(codec); |
| 9063 | |
| 9064 | control = dev_get_drvdata(codec->dev->parent); |
| 9065 | devm_kfree(codec->dev, control->rx_chs); |
| 9066 | control->rx_chs = NULL; |
| 9067 | control->tx_chs = NULL; |
| 9068 | tavil_cleanup_irqs(tavil); |
| 9069 | |
| 9070 | if (tavil->wdsp_cntl) |
| 9071 | wcd_dsp_cntl_deinit(&tavil->wdsp_cntl); |
| 9072 | |
| 9073 | /* Deinitialize MBHC module */ |
| 9074 | tavil_mbhc_deinit(codec); |
| 9075 | tavil->mbhc = NULL; |
Banajit Goswami | e0b20e1 | 2017-02-05 18:11:11 -0800 | [diff] [blame] | 9076 | |
| 9077 | return 0; |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 9078 | } |
| 9079 | |
| 9080 | static struct regmap *tavil_get_regmap(struct device *dev) |
| 9081 | { |
| 9082 | struct wcd9xxx *control = dev_get_drvdata(dev->parent); |
| 9083 | |
| 9084 | return control->regmap; |
| 9085 | } |
| 9086 | |
| 9087 | static struct snd_soc_codec_driver soc_codec_dev_tavil = { |
Banajit Goswami | 2be7b48 | 2017-02-03 23:32:37 -0800 | [diff] [blame] | 9088 | .probe = tavil_soc_codec_probe, |
| 9089 | .remove = tavil_soc_codec_remove, |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 9090 | .get_regmap = tavil_get_regmap, |
Banajit Goswami | 8e306f0 | 2016-12-15 20:49:07 -0800 | [diff] [blame] | 9091 | .component_driver = { |
Banajit Goswami | af47211 | 2017-01-29 22:15:11 -0800 | [diff] [blame] | 9092 | .controls = tavil_snd_controls, |
| 9093 | .num_controls = ARRAY_SIZE(tavil_snd_controls), |
Banajit Goswami | 8e306f0 | 2016-12-15 20:49:07 -0800 | [diff] [blame] | 9094 | .dapm_widgets = tavil_dapm_widgets, |
| 9095 | .num_dapm_widgets = ARRAY_SIZE(tavil_dapm_widgets), |
| 9096 | .dapm_routes = tavil_audio_map, |
| 9097 | .num_dapm_routes = ARRAY_SIZE(tavil_audio_map), |
| 9098 | }, |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 9099 | }; |
| 9100 | |
| 9101 | #ifdef CONFIG_PM |
| 9102 | static int tavil_suspend(struct device *dev) |
| 9103 | { |
| 9104 | struct platform_device *pdev = to_platform_device(dev); |
| 9105 | struct tavil_priv *tavil = platform_get_drvdata(pdev); |
| 9106 | |
| 9107 | if (!tavil) { |
| 9108 | dev_err(dev, "%s: tavil private data is NULL\n", __func__); |
| 9109 | return -EINVAL; |
| 9110 | } |
| 9111 | dev_dbg(dev, "%s: system suspend\n", __func__); |
| 9112 | if (delayed_work_pending(&tavil->power_gate_work) && |
| 9113 | cancel_delayed_work_sync(&tavil->power_gate_work)) |
| 9114 | tavil_codec_power_gate_digital_core(tavil); |
| 9115 | return 0; |
| 9116 | } |
| 9117 | |
| 9118 | static int tavil_resume(struct device *dev) |
| 9119 | { |
| 9120 | struct platform_device *pdev = to_platform_device(dev); |
| 9121 | struct tavil_priv *tavil = platform_get_drvdata(pdev); |
| 9122 | |
| 9123 | if (!tavil) { |
| 9124 | dev_err(dev, "%s: tavil private data is NULL\n", __func__); |
| 9125 | return -EINVAL; |
| 9126 | } |
| 9127 | dev_dbg(dev, "%s: system resume\n", __func__); |
| 9128 | return 0; |
| 9129 | } |
| 9130 | |
| 9131 | static const struct dev_pm_ops tavil_pm_ops = { |
| 9132 | .suspend = tavil_suspend, |
| 9133 | .resume = tavil_resume, |
| 9134 | }; |
| 9135 | #endif |
| 9136 | |
| 9137 | static int tavil_swrm_read(void *handle, int reg) |
| 9138 | { |
| 9139 | struct tavil_priv *tavil; |
| 9140 | struct wcd9xxx *wcd9xxx; |
| 9141 | unsigned short swr_rd_addr_base; |
| 9142 | unsigned short swr_rd_data_base; |
| 9143 | int val, ret; |
| 9144 | |
| 9145 | if (!handle) { |
| 9146 | pr_err("%s: NULL handle\n", __func__); |
| 9147 | return -EINVAL; |
| 9148 | } |
| 9149 | tavil = (struct tavil_priv *)handle; |
| 9150 | wcd9xxx = tavil->wcd9xxx; |
| 9151 | |
| 9152 | dev_dbg(tavil->dev, "%s: Reading soundwire register, 0x%x\n", |
| 9153 | __func__, reg); |
| 9154 | swr_rd_addr_base = WCD934X_SWR_AHB_BRIDGE_RD_ADDR_0; |
| 9155 | swr_rd_data_base = WCD934X_SWR_AHB_BRIDGE_RD_DATA_0; |
| 9156 | |
| 9157 | mutex_lock(&tavil->swr.read_mutex); |
| 9158 | ret = regmap_bulk_write(wcd9xxx->regmap, swr_rd_addr_base, |
| 9159 | (u8 *)®, 4); |
| 9160 | if (ret < 0) { |
| 9161 | dev_err(tavil->dev, "%s: RD Addr Failure\n", __func__); |
| 9162 | goto done; |
| 9163 | } |
| 9164 | ret = regmap_bulk_read(wcd9xxx->regmap, swr_rd_data_base, |
| 9165 | (u8 *)&val, 4); |
| 9166 | if (ret < 0) { |
| 9167 | dev_err(tavil->dev, "%s: RD Data Failure\n", __func__); |
| 9168 | goto done; |
| 9169 | } |
| 9170 | ret = val; |
| 9171 | done: |
| 9172 | mutex_unlock(&tavil->swr.read_mutex); |
| 9173 | |
| 9174 | return ret; |
| 9175 | } |
| 9176 | |
| 9177 | static int tavil_swrm_bulk_write(void *handle, u32 *reg, u32 *val, size_t len) |
| 9178 | { |
| 9179 | struct tavil_priv *tavil; |
| 9180 | struct wcd9xxx *wcd9xxx; |
| 9181 | struct wcd9xxx_reg_val *bulk_reg; |
| 9182 | unsigned short swr_wr_addr_base; |
| 9183 | unsigned short swr_wr_data_base; |
| 9184 | int i, j, ret; |
| 9185 | |
| 9186 | if (!handle || !reg || !val) { |
| 9187 | pr_err("%s: NULL parameter\n", __func__); |
| 9188 | return -EINVAL; |
| 9189 | } |
| 9190 | if (len <= 0) { |
| 9191 | pr_err("%s: Invalid size: %zu\n", __func__, len); |
| 9192 | return -EINVAL; |
| 9193 | } |
| 9194 | tavil = (struct tavil_priv *)handle; |
| 9195 | wcd9xxx = tavil->wcd9xxx; |
| 9196 | |
| 9197 | swr_wr_addr_base = WCD934X_SWR_AHB_BRIDGE_WR_ADDR_0; |
| 9198 | swr_wr_data_base = WCD934X_SWR_AHB_BRIDGE_WR_DATA_0; |
| 9199 | |
| 9200 | bulk_reg = kzalloc((2 * len * sizeof(struct wcd9xxx_reg_val)), |
| 9201 | GFP_KERNEL); |
| 9202 | if (!bulk_reg) |
| 9203 | return -ENOMEM; |
| 9204 | |
| 9205 | for (i = 0, j = 0; i < (len * 2); i += 2, j++) { |
| 9206 | bulk_reg[i].reg = swr_wr_data_base; |
| 9207 | bulk_reg[i].buf = (u8 *)(&val[j]); |
| 9208 | bulk_reg[i].bytes = 4; |
| 9209 | bulk_reg[i+1].reg = swr_wr_addr_base; |
| 9210 | bulk_reg[i+1].buf = (u8 *)(®[j]); |
| 9211 | bulk_reg[i+1].bytes = 4; |
| 9212 | } |
| 9213 | |
| 9214 | mutex_lock(&tavil->swr.write_mutex); |
| 9215 | ret = wcd9xxx_slim_bulk_write(wcd9xxx, bulk_reg, |
| 9216 | (len * 2), false); |
| 9217 | if (ret) { |
| 9218 | dev_err(tavil->dev, "%s: swrm bulk write failed, ret: %d\n", |
| 9219 | __func__, ret); |
| 9220 | } |
| 9221 | mutex_unlock(&tavil->swr.write_mutex); |
| 9222 | |
| 9223 | kfree(bulk_reg); |
| 9224 | return ret; |
| 9225 | } |
| 9226 | |
| 9227 | static int tavil_swrm_write(void *handle, int reg, int val) |
| 9228 | { |
| 9229 | struct tavil_priv *tavil; |
| 9230 | struct wcd9xxx *wcd9xxx; |
| 9231 | unsigned short swr_wr_addr_base; |
| 9232 | unsigned short swr_wr_data_base; |
| 9233 | struct wcd9xxx_reg_val bulk_reg[2]; |
| 9234 | int ret; |
| 9235 | |
| 9236 | if (!handle) { |
| 9237 | pr_err("%s: NULL handle\n", __func__); |
| 9238 | return -EINVAL; |
| 9239 | } |
| 9240 | tavil = (struct tavil_priv *)handle; |
| 9241 | wcd9xxx = tavil->wcd9xxx; |
| 9242 | |
| 9243 | swr_wr_addr_base = WCD934X_SWR_AHB_BRIDGE_WR_ADDR_0; |
| 9244 | swr_wr_data_base = WCD934X_SWR_AHB_BRIDGE_WR_DATA_0; |
| 9245 | |
| 9246 | /* First Write the Data to register */ |
| 9247 | bulk_reg[0].reg = swr_wr_data_base; |
| 9248 | bulk_reg[0].buf = (u8 *)(&val); |
| 9249 | bulk_reg[0].bytes = 4; |
| 9250 | bulk_reg[1].reg = swr_wr_addr_base; |
| 9251 | bulk_reg[1].buf = (u8 *)(®); |
| 9252 | bulk_reg[1].bytes = 4; |
| 9253 | |
| 9254 | mutex_lock(&tavil->swr.write_mutex); |
| 9255 | ret = wcd9xxx_slim_bulk_write(wcd9xxx, bulk_reg, 2, false); |
| 9256 | if (ret < 0) |
| 9257 | dev_err(tavil->dev, "%s: WR Data Failure\n", __func__); |
| 9258 | mutex_unlock(&tavil->swr.write_mutex); |
| 9259 | |
| 9260 | return ret; |
| 9261 | } |
| 9262 | |
| 9263 | static int tavil_swrm_clock(void *handle, bool enable) |
| 9264 | { |
| 9265 | struct tavil_priv *tavil; |
| 9266 | |
| 9267 | if (!handle) { |
| 9268 | pr_err("%s: NULL handle\n", __func__); |
| 9269 | return -EINVAL; |
| 9270 | } |
| 9271 | tavil = (struct tavil_priv *)handle; |
| 9272 | |
| 9273 | mutex_lock(&tavil->swr.clk_mutex); |
| 9274 | dev_dbg(tavil->dev, "%s: swrm clock %s\n", |
| 9275 | __func__, (enable?"enable" : "disable")); |
| 9276 | if (enable) { |
| 9277 | tavil->swr.clk_users++; |
| 9278 | if (tavil->swr.clk_users == 1) { |
| 9279 | regmap_update_bits(tavil->wcd9xxx->regmap, |
| 9280 | WCD934X_TEST_DEBUG_NPL_DLY_TEST_1, |
| 9281 | 0x10, 0x00); |
| 9282 | __tavil_cdc_mclk_enable(tavil, true); |
| 9283 | regmap_update_bits(tavil->wcd9xxx->regmap, |
| 9284 | WCD934X_CDC_CLK_RST_CTRL_SWR_CONTROL, |
| 9285 | 0x01, 0x01); |
| 9286 | } |
| 9287 | } else { |
| 9288 | tavil->swr.clk_users--; |
| 9289 | if (tavil->swr.clk_users == 0) { |
| 9290 | regmap_update_bits(tavil->wcd9xxx->regmap, |
| 9291 | WCD934X_CDC_CLK_RST_CTRL_SWR_CONTROL, |
| 9292 | 0x01, 0x00); |
| 9293 | __tavil_cdc_mclk_enable(tavil, false); |
| 9294 | regmap_update_bits(tavil->wcd9xxx->regmap, |
| 9295 | WCD934X_TEST_DEBUG_NPL_DLY_TEST_1, |
| 9296 | 0x10, 0x10); |
| 9297 | } |
| 9298 | } |
| 9299 | dev_dbg(tavil->dev, "%s: swrm clock users %d\n", |
| 9300 | __func__, tavil->swr.clk_users); |
| 9301 | mutex_unlock(&tavil->swr.clk_mutex); |
| 9302 | |
| 9303 | return 0; |
| 9304 | } |
| 9305 | |
| 9306 | static int tavil_swrm_handle_irq(void *handle, |
| 9307 | irqreturn_t (*swrm_irq_handler)(int irq, |
| 9308 | void *data), |
| 9309 | void *swrm_handle, |
| 9310 | int action) |
| 9311 | { |
| 9312 | struct tavil_priv *tavil; |
| 9313 | int ret = 0; |
| 9314 | struct wcd9xxx *wcd9xxx; |
| 9315 | |
| 9316 | if (!handle) { |
| 9317 | pr_err("%s: NULL handle\n", __func__); |
| 9318 | return -EINVAL; |
| 9319 | } |
| 9320 | tavil = (struct tavil_priv *) handle; |
| 9321 | wcd9xxx = tavil->wcd9xxx; |
| 9322 | |
| 9323 | if (action) { |
| 9324 | ret = wcd9xxx_request_irq(&wcd9xxx->core_res, |
| 9325 | WCD934X_IRQ_SOUNDWIRE, |
| 9326 | swrm_irq_handler, |
| 9327 | "Tavil SWR Master", swrm_handle); |
| 9328 | if (ret) |
| 9329 | dev_err(tavil->dev, "%s: Failed to request irq %d\n", |
| 9330 | __func__, WCD934X_IRQ_SOUNDWIRE); |
| 9331 | } else |
| 9332 | wcd9xxx_free_irq(&wcd9xxx->core_res, WCD934X_IRQ_SOUNDWIRE, |
| 9333 | swrm_handle); |
| 9334 | |
| 9335 | return ret; |
| 9336 | } |
| 9337 | |
| 9338 | static void tavil_codec_add_spi_device(struct tavil_priv *tavil, |
| 9339 | struct device_node *node) |
| 9340 | { |
| 9341 | struct spi_master *master; |
| 9342 | struct spi_device *spi; |
| 9343 | u32 prop_value; |
| 9344 | int rc; |
| 9345 | |
| 9346 | /* Read the master bus num from DT node */ |
| 9347 | rc = of_property_read_u32(node, "qcom,master-bus-num", |
| 9348 | &prop_value); |
Xiaoyu Ye | 1a2d8bd9 | 2017-01-31 18:54:15 -0800 | [diff] [blame] | 9349 | if (rc < 0) { |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 9350 | dev_err(tavil->dev, "%s: prop %s not found in node %s", |
| 9351 | __func__, "qcom,master-bus-num", node->full_name); |
| 9352 | goto done; |
| 9353 | } |
| 9354 | |
| 9355 | /* Get the reference to SPI master */ |
| 9356 | master = spi_busnum_to_master(prop_value); |
| 9357 | if (!master) { |
| 9358 | dev_err(tavil->dev, "%s: Invalid spi_master for bus_num %u\n", |
| 9359 | __func__, prop_value); |
| 9360 | goto done; |
| 9361 | } |
| 9362 | |
| 9363 | /* Allocate the spi device */ |
| 9364 | spi = spi_alloc_device(master); |
| 9365 | if (!spi) { |
| 9366 | dev_err(tavil->dev, "%s: spi_alloc_device failed\n", |
| 9367 | __func__); |
| 9368 | goto err_spi_alloc_dev; |
| 9369 | } |
| 9370 | |
| 9371 | /* Initialize device properties */ |
| 9372 | if (of_modalias_node(node, spi->modalias, |
| 9373 | sizeof(spi->modalias)) < 0) { |
| 9374 | dev_err(tavil->dev, "%s: cannot find modalias for %s\n", |
| 9375 | __func__, node->full_name); |
| 9376 | goto err_dt_parse; |
| 9377 | } |
| 9378 | |
| 9379 | rc = of_property_read_u32(node, "qcom,chip-select", |
| 9380 | &prop_value); |
Xiaoyu Ye | 1a2d8bd9 | 2017-01-31 18:54:15 -0800 | [diff] [blame] | 9381 | if (rc < 0) { |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 9382 | dev_err(tavil->dev, "%s: prop %s not found in node %s", |
| 9383 | __func__, "qcom,chip-select", node->full_name); |
| 9384 | goto err_dt_parse; |
| 9385 | } |
| 9386 | spi->chip_select = prop_value; |
| 9387 | |
| 9388 | rc = of_property_read_u32(node, "qcom,max-frequency", |
| 9389 | &prop_value); |
Xiaoyu Ye | 1a2d8bd9 | 2017-01-31 18:54:15 -0800 | [diff] [blame] | 9390 | if (rc < 0) { |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 9391 | dev_err(tavil->dev, "%s: prop %s not found in node %s", |
| 9392 | __func__, "qcom,max-frequency", node->full_name); |
| 9393 | goto err_dt_parse; |
| 9394 | } |
| 9395 | spi->max_speed_hz = prop_value; |
| 9396 | |
| 9397 | spi->dev.of_node = node; |
| 9398 | |
| 9399 | rc = spi_add_device(spi); |
Xiaoyu Ye | 1a2d8bd9 | 2017-01-31 18:54:15 -0800 | [diff] [blame] | 9400 | if (rc < 0) { |
Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 9401 | dev_err(tavil->dev, "%s: spi_add_device failed\n", __func__); |
| 9402 | goto err_dt_parse; |
| 9403 | } |
| 9404 | |
| 9405 | /* Put the reference to SPI master */ |
| 9406 | put_device(&master->dev); |
| 9407 | |
| 9408 | return; |
| 9409 | |
| 9410 | err_dt_parse: |
| 9411 | spi_dev_put(spi); |
| 9412 | |
| 9413 | err_spi_alloc_dev: |
| 9414 | /* Put the reference to SPI master */ |
| 9415 | put_device(&master->dev); |
| 9416 | done: |
| 9417 | return; |
| 9418 | } |
| 9419 | |
| 9420 | static void tavil_add_child_devices(struct work_struct *work) |
| 9421 | { |
| 9422 | struct tavil_priv *tavil; |
| 9423 | struct platform_device *pdev; |
| 9424 | struct device_node *node; |
| 9425 | struct wcd9xxx *wcd9xxx; |
| 9426 | struct tavil_swr_ctrl_data *swr_ctrl_data = NULL, *temp; |
| 9427 | int ret, ctrl_num = 0; |
| 9428 | struct wcd_swr_ctrl_platform_data *platdata; |
| 9429 | char plat_dev_name[WCD934X_STRING_LEN]; |
| 9430 | |
| 9431 | tavil = container_of(work, struct tavil_priv, |
| 9432 | tavil_add_child_devices_work); |
| 9433 | if (!tavil) { |
| 9434 | pr_err("%s: Memory for WCD934X does not exist\n", |
| 9435 | __func__); |
| 9436 | return; |
| 9437 | } |
| 9438 | wcd9xxx = tavil->wcd9xxx; |
| 9439 | if (!wcd9xxx) { |
| 9440 | pr_err("%s: Memory for WCD9XXX does not exist\n", |
| 9441 | __func__); |
| 9442 | return; |
| 9443 | } |
| 9444 | if (!wcd9xxx->dev->of_node) { |
| 9445 | dev_err(wcd9xxx->dev, "%s: DT node for wcd9xxx does not exist\n", |
| 9446 | __func__); |
| 9447 | return; |
| 9448 | } |
| 9449 | |
| 9450 | platdata = &tavil->swr.plat_data; |
| 9451 | |
| 9452 | for_each_child_of_node(wcd9xxx->dev->of_node, node) { |
| 9453 | |
| 9454 | /* Parse and add the SPI device node */ |
| 9455 | if (!strcmp(node->name, "wcd_spi")) { |
| 9456 | tavil_codec_add_spi_device(tavil, node); |
| 9457 | continue; |
| 9458 | } |
| 9459 | |
| 9460 | /* Parse other child device nodes and add platform device */ |
| 9461 | if (!strcmp(node->name, "swr_master")) |
| 9462 | strlcpy(plat_dev_name, "tavil_swr_ctrl", |
| 9463 | (WCD934X_STRING_LEN - 1)); |
| 9464 | else if (strnstr(node->name, "msm_cdc_pinctrl", |
| 9465 | strlen("msm_cdc_pinctrl")) != NULL) |
| 9466 | strlcpy(plat_dev_name, node->name, |
| 9467 | (WCD934X_STRING_LEN - 1)); |
| 9468 | else |
| 9469 | continue; |
| 9470 | |
| 9471 | pdev = platform_device_alloc(plat_dev_name, -1); |
| 9472 | if (!pdev) { |
| 9473 | dev_err(wcd9xxx->dev, "%s: pdev memory alloc failed\n", |
| 9474 | __func__); |
| 9475 | ret = -ENOMEM; |
| 9476 | goto err_mem; |
| 9477 | } |
| 9478 | pdev->dev.parent = tavil->dev; |
| 9479 | pdev->dev.of_node = node; |
| 9480 | |
| 9481 | if (strcmp(node->name, "swr_master") == 0) { |
| 9482 | ret = platform_device_add_data(pdev, platdata, |
| 9483 | sizeof(*platdata)); |
| 9484 | if (ret) { |
| 9485 | dev_err(&pdev->dev, |
| 9486 | "%s: cannot add plat data ctrl:%d\n", |
| 9487 | __func__, ctrl_num); |
| 9488 | goto err_pdev_add; |
| 9489 | } |
| 9490 | } |
| 9491 | |
| 9492 | ret = platform_device_add(pdev); |
| 9493 | if (ret) { |
| 9494 | dev_err(&pdev->dev, |
| 9495 | "%s: Cannot add platform device\n", |
| 9496 | __func__); |
| 9497 | goto err_pdev_add; |
| 9498 | } |
| 9499 | |
| 9500 | if (strcmp(node->name, "swr_master") == 0) { |
| 9501 | temp = krealloc(swr_ctrl_data, |
| 9502 | (ctrl_num + 1) * sizeof( |
| 9503 | struct tavil_swr_ctrl_data), |
| 9504 | GFP_KERNEL); |
| 9505 | if (!temp) { |
| 9506 | dev_err(wcd9xxx->dev, "out of memory\n"); |
| 9507 | ret = -ENOMEM; |
| 9508 | goto err_pdev_add; |
| 9509 | } |
| 9510 | swr_ctrl_data = temp; |
| 9511 | swr_ctrl_data[ctrl_num].swr_pdev = pdev; |
| 9512 | ctrl_num++; |
| 9513 | dev_dbg(&pdev->dev, |
| 9514 | "%s: Added soundwire ctrl device(s)\n", |
| 9515 | __func__); |
| 9516 | tavil->swr.ctrl_data = swr_ctrl_data; |
| 9517 | } |
| 9518 | } |
| 9519 | |
| 9520 | return; |
| 9521 | |
| 9522 | err_pdev_add: |
| 9523 | platform_device_put(pdev); |
| 9524 | err_mem: |
| 9525 | return; |
| 9526 | } |
| 9527 | |
| 9528 | static int __tavil_enable_efuse_sensing(struct tavil_priv *tavil) |
| 9529 | { |
| 9530 | int val, rc; |
| 9531 | |
| 9532 | __tavil_cdc_mclk_enable(tavil, true); |
| 9533 | |
| 9534 | regmap_update_bits(tavil->wcd9xxx->regmap, |
| 9535 | WCD934X_CHIP_TIER_CTRL_EFUSE_CTL, 0x1E, 0x10); |
| 9536 | regmap_update_bits(tavil->wcd9xxx->regmap, |
| 9537 | WCD934X_CHIP_TIER_CTRL_EFUSE_CTL, 0x01, 0x01); |
| 9538 | |
| 9539 | /* |
| 9540 | * 5ms sleep required after enabling efuse control |
| 9541 | * before checking the status. |
| 9542 | */ |
| 9543 | usleep_range(5000, 5500); |
| 9544 | rc = regmap_read(tavil->wcd9xxx->regmap, |
| 9545 | WCD934X_CHIP_TIER_CTRL_EFUSE_STATUS, &val); |
| 9546 | if (rc || (!(val & 0x01))) |
| 9547 | WARN(1, "%s: Efuse sense is not complete val=%x, ret=%d\n", |
| 9548 | __func__, val, rc); |
| 9549 | |
| 9550 | __tavil_cdc_mclk_enable(tavil, false); |
| 9551 | |
| 9552 | return rc; |
| 9553 | } |
| 9554 | |
| 9555 | static void ___tavil_get_codec_fine_version(struct tavil_priv *tavil) |
| 9556 | { |
| 9557 | int val1, val2, version; |
| 9558 | struct regmap *regmap; |
| 9559 | u16 id_minor; |
| 9560 | u32 version_mask = 0; |
| 9561 | |
| 9562 | regmap = tavil->wcd9xxx->regmap; |
| 9563 | version = tavil->wcd9xxx->version; |
| 9564 | id_minor = tavil->wcd9xxx->codec_type->id_minor; |
| 9565 | |
| 9566 | regmap_read(regmap, WCD934X_CHIP_TIER_CTRL_EFUSE_VAL_OUT14, &val1); |
| 9567 | regmap_read(regmap, WCD934X_CHIP_TIER_CTRL_EFUSE_VAL_OUT15, &val2); |
| 9568 | |
| 9569 | dev_dbg(tavil->dev, "%s: chip version :0x%x 0x:%x\n", |
| 9570 | __func__, val1, val2); |
| 9571 | |
| 9572 | version_mask |= (!!((u8)val1 & 0x80)) << DSD_DISABLED_MASK; |
| 9573 | version_mask |= (!!((u8)val2 & 0x01)) << SLNQ_DISABLED_MASK; |
| 9574 | |
| 9575 | switch (version_mask) { |
| 9576 | case DSD_DISABLED | SLNQ_DISABLED: |
| 9577 | if (id_minor == cpu_to_le16(0)) |
| 9578 | version = TAVIL_VERSION_WCD9340_1_0; |
| 9579 | else if (id_minor == cpu_to_le16(0x01)) |
| 9580 | version = TAVIL_VERSION_WCD9340_1_1; |
| 9581 | break; |
| 9582 | case SLNQ_DISABLED: |
| 9583 | if (id_minor == cpu_to_le16(0)) |
| 9584 | version = TAVIL_VERSION_WCD9341_1_0; |
| 9585 | else if (id_minor == cpu_to_le16(0x01)) |
| 9586 | version = TAVIL_VERSION_WCD9341_1_1; |
| 9587 | break; |
| 9588 | } |
| 9589 | |
| 9590 | tavil->wcd9xxx->version = version; |
| 9591 | tavil->wcd9xxx->codec_type->version = version; |
| 9592 | } |
| 9593 | |
| 9594 | /* |
| 9595 | * tavil_get_wcd_dsp_cntl: Get the reference to wcd_dsp_cntl |
| 9596 | * @dev: Device pointer for codec device |
| 9597 | * |
| 9598 | * This API gets the reference to codec's struct wcd_dsp_cntl |
| 9599 | */ |
| 9600 | struct wcd_dsp_cntl *tavil_get_wcd_dsp_cntl(struct device *dev) |
| 9601 | { |
| 9602 | struct platform_device *pdev; |
| 9603 | struct tavil_priv *tavil; |
| 9604 | |
| 9605 | if (!dev) { |
| 9606 | pr_err("%s: Invalid device\n", __func__); |
| 9607 | return NULL; |
| 9608 | } |
| 9609 | |
| 9610 | pdev = to_platform_device(dev); |
| 9611 | tavil = platform_get_drvdata(pdev); |
| 9612 | |
| 9613 | return tavil->wdsp_cntl; |
| 9614 | } |
| 9615 | EXPORT_SYMBOL(tavil_get_wcd_dsp_cntl); |
| 9616 | |
| 9617 | static int tavil_probe(struct platform_device *pdev) |
| 9618 | { |
| 9619 | int ret = 0; |
| 9620 | struct tavil_priv *tavil; |
| 9621 | struct clk *wcd_ext_clk; |
| 9622 | struct wcd9xxx_resmgr_v2 *resmgr; |
| 9623 | struct wcd9xxx_power_region *cdc_pwr; |
| 9624 | |
| 9625 | tavil = devm_kzalloc(&pdev->dev, sizeof(struct tavil_priv), |
| 9626 | GFP_KERNEL); |
| 9627 | if (!tavil) |
| 9628 | return -ENOMEM; |
| 9629 | |
| 9630 | platform_set_drvdata(pdev, tavil); |
| 9631 | |
| 9632 | tavil->wcd9xxx = dev_get_drvdata(pdev->dev.parent); |
| 9633 | tavil->dev = &pdev->dev; |
| 9634 | INIT_DELAYED_WORK(&tavil->power_gate_work, tavil_codec_power_gate_work); |
| 9635 | mutex_init(&tavil->power_lock); |
| 9636 | INIT_WORK(&tavil->tavil_add_child_devices_work, |
| 9637 | tavil_add_child_devices); |
| 9638 | mutex_init(&tavil->micb_lock); |
| 9639 | mutex_init(&tavil->swr.read_mutex); |
| 9640 | mutex_init(&tavil->swr.write_mutex); |
| 9641 | mutex_init(&tavil->swr.clk_mutex); |
| 9642 | mutex_init(&tavil->codec_mutex); |
| 9643 | mutex_init(&tavil->svs_mutex); |
| 9644 | |
| 9645 | /* |
| 9646 | * Codec hardware by default comes up in SVS mode. |
| 9647 | * Initialize the svs_ref_cnt to 1 to reflect the hardware |
| 9648 | * state in the driver. |
| 9649 | */ |
| 9650 | tavil->svs_ref_cnt = 1; |
| 9651 | |
| 9652 | cdc_pwr = devm_kzalloc(&pdev->dev, sizeof(struct wcd9xxx_power_region), |
| 9653 | GFP_KERNEL); |
| 9654 | if (!cdc_pwr) { |
| 9655 | ret = -ENOMEM; |
| 9656 | goto err_resmgr; |
| 9657 | } |
| 9658 | tavil->wcd9xxx->wcd9xxx_pwr[WCD9XXX_DIG_CORE_REGION_1] = cdc_pwr; |
| 9659 | cdc_pwr->pwr_collapse_reg_min = WCD934X_DIG_CORE_REG_MIN; |
| 9660 | cdc_pwr->pwr_collapse_reg_max = WCD934X_DIG_CORE_REG_MAX; |
| 9661 | wcd9xxx_set_power_state(tavil->wcd9xxx, |
| 9662 | WCD_REGION_POWER_COLLAPSE_REMOVE, |
| 9663 | WCD9XXX_DIG_CORE_REGION_1); |
| 9664 | /* |
| 9665 | * Init resource manager so that if child nodes such as SoundWire |
| 9666 | * requests for clock, resource manager can honor the request |
| 9667 | */ |
| 9668 | resmgr = wcd_resmgr_init(&tavil->wcd9xxx->core_res, NULL); |
| 9669 | if (IS_ERR(resmgr)) { |
| 9670 | ret = PTR_ERR(resmgr); |
| 9671 | dev_err(&pdev->dev, "%s: Failed to initialize wcd resmgr\n", |
| 9672 | __func__); |
| 9673 | goto err_resmgr; |
| 9674 | } |
| 9675 | tavil->resmgr = resmgr; |
| 9676 | tavil->swr.plat_data.handle = (void *) tavil; |
| 9677 | tavil->swr.plat_data.read = tavil_swrm_read; |
| 9678 | tavil->swr.plat_data.write = tavil_swrm_write; |
| 9679 | tavil->swr.plat_data.bulk_write = tavil_swrm_bulk_write; |
| 9680 | tavil->swr.plat_data.clk = tavil_swrm_clock; |
| 9681 | tavil->swr.plat_data.handle_irq = tavil_swrm_handle_irq; |
| 9682 | tavil->swr.spkr_gain_offset = WCD934X_RX_GAIN_OFFSET_0_DB; |
| 9683 | |
| 9684 | /* Register for Clock */ |
| 9685 | wcd_ext_clk = clk_get(tavil->wcd9xxx->dev, "wcd_clk"); |
| 9686 | if (IS_ERR(wcd_ext_clk)) { |
| 9687 | dev_err(tavil->wcd9xxx->dev, "%s: clk get %s failed\n", |
| 9688 | __func__, "wcd_ext_clk"); |
| 9689 | goto err_clk; |
| 9690 | } |
| 9691 | tavil->wcd_ext_clk = wcd_ext_clk; |
| 9692 | set_bit(AUDIO_NOMINAL, &tavil->status_mask); |
| 9693 | /* Update codec register default values */ |
| 9694 | dev_dbg(&pdev->dev, "%s: MCLK Rate = %x\n", __func__, |
| 9695 | tavil->wcd9xxx->mclk_rate); |
| 9696 | if (tavil->wcd9xxx->mclk_rate == WCD934X_MCLK_CLK_12P288MHZ) |
| 9697 | regmap_update_bits(tavil->wcd9xxx->regmap, |
| 9698 | WCD934X_CODEC_RPM_CLK_MCLK_CFG, |
| 9699 | 0x03, 0x00); |
| 9700 | else if (tavil->wcd9xxx->mclk_rate == WCD934X_MCLK_CLK_9P6MHZ) |
| 9701 | regmap_update_bits(tavil->wcd9xxx->regmap, |
| 9702 | WCD934X_CODEC_RPM_CLK_MCLK_CFG, |
| 9703 | 0x03, 0x01); |
| 9704 | tavil_update_reg_defaults(tavil); |
| 9705 | __tavil_enable_efuse_sensing(tavil); |
| 9706 | ___tavil_get_codec_fine_version(tavil); |
| 9707 | tavil_update_cpr_defaults(tavil); |
| 9708 | |
| 9709 | /* Register with soc framework */ |
| 9710 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tavil, |
| 9711 | tavil_dai, ARRAY_SIZE(tavil_dai)); |
| 9712 | if (ret) { |
| 9713 | dev_err(&pdev->dev, "%s: Codec registration failed\n", |
| 9714 | __func__); |
| 9715 | goto err_cdc_reg; |
| 9716 | } |
| 9717 | schedule_work(&tavil->tavil_add_child_devices_work); |
| 9718 | |
| 9719 | return ret; |
| 9720 | |
| 9721 | err_cdc_reg: |
| 9722 | clk_put(tavil->wcd_ext_clk); |
| 9723 | err_clk: |
| 9724 | wcd_resmgr_remove(tavil->resmgr); |
| 9725 | err_resmgr: |
| 9726 | mutex_destroy(&tavil->micb_lock); |
| 9727 | mutex_destroy(&tavil->svs_mutex); |
| 9728 | mutex_destroy(&tavil->codec_mutex); |
| 9729 | mutex_destroy(&tavil->swr.read_mutex); |
| 9730 | mutex_destroy(&tavil->swr.write_mutex); |
| 9731 | mutex_destroy(&tavil->swr.clk_mutex); |
| 9732 | devm_kfree(&pdev->dev, tavil); |
| 9733 | |
| 9734 | return ret; |
| 9735 | } |
| 9736 | |
| 9737 | static int tavil_remove(struct platform_device *pdev) |
| 9738 | { |
| 9739 | struct tavil_priv *tavil; |
| 9740 | |
| 9741 | tavil = platform_get_drvdata(pdev); |
| 9742 | if (!tavil) |
| 9743 | return -EINVAL; |
| 9744 | |
| 9745 | mutex_destroy(&tavil->micb_lock); |
| 9746 | mutex_destroy(&tavil->svs_mutex); |
| 9747 | mutex_destroy(&tavil->codec_mutex); |
| 9748 | mutex_destroy(&tavil->swr.read_mutex); |
| 9749 | mutex_destroy(&tavil->swr.write_mutex); |
| 9750 | mutex_destroy(&tavil->swr.clk_mutex); |
| 9751 | |
| 9752 | snd_soc_unregister_codec(&pdev->dev); |
| 9753 | clk_put(tavil->wcd_ext_clk); |
| 9754 | wcd_resmgr_remove(tavil->resmgr); |
| 9755 | if (tavil->dsd_config) { |
| 9756 | tavil_dsd_deinit(tavil->dsd_config); |
| 9757 | tavil->dsd_config = NULL; |
| 9758 | } |
| 9759 | devm_kfree(&pdev->dev, tavil); |
| 9760 | return 0; |
| 9761 | } |
| 9762 | |
| 9763 | static struct platform_driver tavil_codec_driver = { |
| 9764 | .probe = tavil_probe, |
| 9765 | .remove = tavil_remove, |
| 9766 | .driver = { |
| 9767 | .name = "tavil_codec", |
| 9768 | .owner = THIS_MODULE, |
| 9769 | #ifdef CONFIG_PM |
| 9770 | .pm = &tavil_pm_ops, |
| 9771 | #endif |
| 9772 | }, |
| 9773 | }; |
| 9774 | |
| 9775 | module_platform_driver(tavil_codec_driver); |
| 9776 | |
| 9777 | MODULE_DESCRIPTION("Tavil Codec driver"); |
| 9778 | MODULE_LICENSE("GPL v2"); |