Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | // Copyright (c) 2018-2020, The Linux Foundation. All rights reserved. |
| 3 | |
| 4 | #include <linux/module.h> |
| 5 | #include <linux/slab.h> |
| 6 | #include <linux/platform_device.h> |
| 7 | #include <linux/device.h> |
| 8 | #include <linux/delay.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/pm_runtime.h> |
| 11 | #include <linux/component.h> |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 12 | #include <sound/tlv.h> |
| 13 | #include <linux/of_gpio.h> |
| 14 | #include <linux/of.h> |
| 15 | #include <sound/jack.h> |
| 16 | #include <sound/pcm.h> |
| 17 | #include <sound/pcm_params.h> |
| 18 | #include <linux/regmap.h> |
| 19 | #include <sound/soc.h> |
| 20 | #include <sound/soc-dapm.h> |
| 21 | #include <linux/regulator/consumer.h> |
| 22 | |
| 23 | #include "wcd-clsh-v2.h" |
| 24 | #include "wcd938x.h" |
| 25 | |
| 26 | #define WCD938X_MAX_MICBIAS (4) |
| 27 | #define WCD938X_MAX_SUPPLY (4) |
| 28 | #define WCD938X_MBHC_MAX_BUTTONS (8) |
| 29 | #define TX_ADC_MAX (4) |
| 30 | #define WCD938X_TX_MAX_SWR_PORTS (5) |
| 31 | |
| 32 | #define WCD938X_RATES_MASK (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ |
| 33 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\ |
| 34 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000) |
| 35 | /* Fractional Rates */ |
| 36 | #define WCD938X_FRAC_RATES_MASK (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\ |
| 37 | SNDRV_PCM_RATE_176400) |
| 38 | #define WCD938X_FORMATS_S16_S24_LE (SNDRV_PCM_FMTBIT_S16_LE | \ |
| 39 | SNDRV_PCM_FMTBIT_S24_LE) |
| 40 | /* Convert from vout ctl to micbias voltage in mV */ |
| 41 | #define WCD_VOUT_CTL_TO_MICB(v) (1000 + v * 50) |
| 42 | #define SWR_CLK_RATE_0P6MHZ (600000) |
| 43 | #define SWR_CLK_RATE_1P2MHZ (1200000) |
| 44 | #define SWR_CLK_RATE_2P4MHZ (2400000) |
| 45 | #define SWR_CLK_RATE_4P8MHZ (4800000) |
| 46 | #define SWR_CLK_RATE_9P6MHZ (9600000) |
| 47 | #define SWR_CLK_RATE_11P2896MHZ (1128960) |
| 48 | |
| 49 | #define WCD938X_DRV_NAME "wcd938x_codec" |
| 50 | #define WCD938X_VERSION_1_0 (1) |
| 51 | #define EAR_RX_PATH_AUX (1) |
| 52 | |
| 53 | #define ADC_MODE_VAL_HIFI 0x01 |
| 54 | #define ADC_MODE_VAL_LO_HIF 0x02 |
| 55 | #define ADC_MODE_VAL_NORMAL 0x03 |
| 56 | #define ADC_MODE_VAL_LP 0x05 |
| 57 | #define ADC_MODE_VAL_ULP1 0x09 |
| 58 | #define ADC_MODE_VAL_ULP2 0x0B |
| 59 | |
| 60 | /* Z value defined in milliohm */ |
| 61 | #define WCD938X_ZDET_VAL_32 (32000) |
| 62 | #define WCD938X_ZDET_VAL_400 (400000) |
| 63 | #define WCD938X_ZDET_VAL_1200 (1200000) |
| 64 | #define WCD938X_ZDET_VAL_100K (100000000) |
| 65 | /* Z floating defined in ohms */ |
| 66 | #define WCD938X_ZDET_FLOATING_IMPEDANCE (0x0FFFFFFE) |
| 67 | #define WCD938X_ZDET_NUM_MEASUREMENTS (900) |
| 68 | #define WCD938X_MBHC_GET_C1(c) ((c & 0xC000) >> 14) |
| 69 | #define WCD938X_MBHC_GET_X1(x) (x & 0x3FFF) |
| 70 | /* Z value compared in milliOhm */ |
| 71 | #define WCD938X_MBHC_IS_SECOND_RAMP_REQUIRED(z) ((z > 400000) || (z < 32000)) |
| 72 | #define WCD938X_MBHC_ZDET_CONST (86 * 16384) |
| 73 | #define WCD938X_MBHC_MOISTURE_RREF R_24_KOHM |
| 74 | #define WCD_MBHC_HS_V_MAX 1600 |
| 75 | |
Srinivas Kandagatla | e8ba1e0 | 2021-06-09 10:09:40 +0100 | [diff] [blame] | 76 | #define WCD938X_EAR_PA_GAIN_TLV(xname, reg, shift, max, invert, tlv_array) \ |
| 77 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 78 | .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ |
| 79 | SNDRV_CTL_ELEM_ACCESS_READWRITE,\ |
| 80 | .tlv.p = (tlv_array), \ |
| 81 | .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\ |
| 82 | .put = wcd938x_ear_pa_put_gain, \ |
| 83 | .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert, 0) } |
| 84 | |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 85 | enum { |
| 86 | WCD9380 = 0, |
| 87 | WCD9385 = 5, |
| 88 | }; |
| 89 | |
| 90 | enum { |
| 91 | TX_HDR12 = 0, |
| 92 | TX_HDR34, |
| 93 | TX_HDR_MAX, |
| 94 | }; |
| 95 | |
| 96 | enum { |
| 97 | WCD_RX1, |
| 98 | WCD_RX2, |
| 99 | WCD_RX3 |
| 100 | }; |
| 101 | |
| 102 | enum { |
| 103 | /* INTR_CTRL_INT_MASK_0 */ |
| 104 | WCD938X_IRQ_MBHC_BUTTON_PRESS_DET = 0, |
| 105 | WCD938X_IRQ_MBHC_BUTTON_RELEASE_DET, |
| 106 | WCD938X_IRQ_MBHC_ELECT_INS_REM_DET, |
| 107 | WCD938X_IRQ_MBHC_ELECT_INS_REM_LEG_DET, |
| 108 | WCD938X_IRQ_MBHC_SW_DET, |
| 109 | WCD938X_IRQ_HPHR_OCP_INT, |
| 110 | WCD938X_IRQ_HPHR_CNP_INT, |
| 111 | WCD938X_IRQ_HPHL_OCP_INT, |
| 112 | |
| 113 | /* INTR_CTRL_INT_MASK_1 */ |
| 114 | WCD938X_IRQ_HPHL_CNP_INT, |
| 115 | WCD938X_IRQ_EAR_CNP_INT, |
| 116 | WCD938X_IRQ_EAR_SCD_INT, |
| 117 | WCD938X_IRQ_AUX_CNP_INT, |
| 118 | WCD938X_IRQ_AUX_SCD_INT, |
| 119 | WCD938X_IRQ_HPHL_PDM_WD_INT, |
| 120 | WCD938X_IRQ_HPHR_PDM_WD_INT, |
| 121 | WCD938X_IRQ_AUX_PDM_WD_INT, |
| 122 | |
| 123 | /* INTR_CTRL_INT_MASK_2 */ |
| 124 | WCD938X_IRQ_LDORT_SCD_INT, |
| 125 | WCD938X_IRQ_MBHC_MOISTURE_INT, |
| 126 | WCD938X_IRQ_HPHL_SURGE_DET_INT, |
| 127 | WCD938X_IRQ_HPHR_SURGE_DET_INT, |
| 128 | WCD938X_NUM_IRQS, |
| 129 | }; |
| 130 | |
| 131 | enum { |
| 132 | WCD_ADC1 = 0, |
| 133 | WCD_ADC2, |
| 134 | WCD_ADC3, |
| 135 | WCD_ADC4, |
| 136 | ALLOW_BUCK_DISABLE, |
| 137 | HPH_COMP_DELAY, |
| 138 | HPH_PA_DELAY, |
| 139 | AMIC2_BCS_ENABLE, |
| 140 | WCD_SUPPLIES_LPM_MODE, |
| 141 | }; |
| 142 | |
| 143 | enum { |
| 144 | ADC_MODE_INVALID = 0, |
| 145 | ADC_MODE_HIFI, |
| 146 | ADC_MODE_LO_HIF, |
| 147 | ADC_MODE_NORMAL, |
| 148 | ADC_MODE_LP, |
| 149 | ADC_MODE_ULP1, |
| 150 | ADC_MODE_ULP2, |
| 151 | }; |
| 152 | |
| 153 | enum { |
| 154 | AIF1_PB = 0, |
| 155 | AIF1_CAP, |
| 156 | NUM_CODEC_DAIS, |
| 157 | }; |
| 158 | |
Srinivas Kandagatla | d5add08 | 2021-06-09 10:09:42 +0100 | [diff] [blame] | 159 | static u8 tx_mode_bit[] = { |
| 160 | [ADC_MODE_INVALID] = 0x00, |
| 161 | [ADC_MODE_HIFI] = 0x01, |
| 162 | [ADC_MODE_LO_HIF] = 0x02, |
| 163 | [ADC_MODE_NORMAL] = 0x04, |
| 164 | [ADC_MODE_LP] = 0x08, |
| 165 | [ADC_MODE_ULP1] = 0x10, |
| 166 | [ADC_MODE_ULP2] = 0x20, |
| 167 | }; |
| 168 | |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 169 | struct wcd938x_priv { |
| 170 | struct sdw_slave *tx_sdw_dev; |
| 171 | struct wcd938x_sdw_priv *sdw_priv[NUM_CODEC_DAIS]; |
| 172 | struct device *txdev; |
| 173 | struct device *rxdev; |
| 174 | struct device_node *rxnode, *txnode; |
| 175 | struct regmap *regmap; |
| 176 | struct wcd_clsh_ctrl *clsh_info; |
| 177 | struct irq_domain *virq; |
| 178 | struct regmap_irq_chip *wcd_regmap_irq_chip; |
| 179 | struct regmap_irq_chip_data *irq_chip; |
| 180 | struct regulator_bulk_data supplies[WCD938X_MAX_SUPPLY]; |
| 181 | struct snd_soc_jack *jack; |
| 182 | unsigned long status_mask; |
| 183 | s32 micb_ref[WCD938X_MAX_MICBIAS]; |
| 184 | s32 pullup_ref[WCD938X_MAX_MICBIAS]; |
| 185 | u32 hph_mode; |
| 186 | u32 tx_mode[TX_ADC_MAX]; |
| 187 | int flyback_cur_det_disable; |
| 188 | int ear_rx_path; |
| 189 | int variant; |
| 190 | int reset_gpio; |
| 191 | u32 micb1_mv; |
| 192 | u32 micb2_mv; |
| 193 | u32 micb3_mv; |
| 194 | u32 micb4_mv; |
| 195 | int hphr_pdm_wd_int; |
| 196 | int hphl_pdm_wd_int; |
| 197 | int aux_pdm_wd_int; |
| 198 | bool comp1_enable; |
| 199 | bool comp2_enable; |
| 200 | bool ldoh; |
| 201 | bool bcs_dis; |
| 202 | }; |
| 203 | |
| 204 | enum { |
| 205 | MIC_BIAS_1 = 1, |
| 206 | MIC_BIAS_2, |
| 207 | MIC_BIAS_3, |
| 208 | MIC_BIAS_4 |
| 209 | }; |
| 210 | |
| 211 | enum { |
| 212 | MICB_PULLUP_ENABLE, |
| 213 | MICB_PULLUP_DISABLE, |
| 214 | MICB_ENABLE, |
| 215 | MICB_DISABLE, |
| 216 | }; |
| 217 | |
Srinivas Kandagatla | e8ba1e0 | 2021-06-09 10:09:40 +0100 | [diff] [blame] | 218 | static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(ear_pa_gain, 600, -1800); |
| 219 | static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(line_gain, 600, -3000); |
| 220 | static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(analog_gain, 0, 3000); |
| 221 | |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 222 | static const struct reg_default wcd938x_defaults[] = { |
| 223 | {WCD938X_ANA_PAGE_REGISTER, 0x00}, |
| 224 | {WCD938X_ANA_BIAS, 0x00}, |
| 225 | {WCD938X_ANA_RX_SUPPLIES, 0x00}, |
| 226 | {WCD938X_ANA_HPH, 0x0C}, |
| 227 | {WCD938X_ANA_EAR, 0x00}, |
| 228 | {WCD938X_ANA_EAR_COMPANDER_CTL, 0x02}, |
| 229 | {WCD938X_ANA_TX_CH1, 0x20}, |
| 230 | {WCD938X_ANA_TX_CH2, 0x00}, |
| 231 | {WCD938X_ANA_TX_CH3, 0x20}, |
| 232 | {WCD938X_ANA_TX_CH4, 0x00}, |
| 233 | {WCD938X_ANA_MICB1_MICB2_DSP_EN_LOGIC, 0x00}, |
| 234 | {WCD938X_ANA_MICB3_DSP_EN_LOGIC, 0x00}, |
| 235 | {WCD938X_ANA_MBHC_MECH, 0x39}, |
| 236 | {WCD938X_ANA_MBHC_ELECT, 0x08}, |
| 237 | {WCD938X_ANA_MBHC_ZDET, 0x00}, |
| 238 | {WCD938X_ANA_MBHC_RESULT_1, 0x00}, |
| 239 | {WCD938X_ANA_MBHC_RESULT_2, 0x00}, |
| 240 | {WCD938X_ANA_MBHC_RESULT_3, 0x00}, |
| 241 | {WCD938X_ANA_MBHC_BTN0, 0x00}, |
| 242 | {WCD938X_ANA_MBHC_BTN1, 0x10}, |
| 243 | {WCD938X_ANA_MBHC_BTN2, 0x20}, |
| 244 | {WCD938X_ANA_MBHC_BTN3, 0x30}, |
| 245 | {WCD938X_ANA_MBHC_BTN4, 0x40}, |
| 246 | {WCD938X_ANA_MBHC_BTN5, 0x50}, |
| 247 | {WCD938X_ANA_MBHC_BTN6, 0x60}, |
| 248 | {WCD938X_ANA_MBHC_BTN7, 0x70}, |
| 249 | {WCD938X_ANA_MICB1, 0x10}, |
| 250 | {WCD938X_ANA_MICB2, 0x10}, |
| 251 | {WCD938X_ANA_MICB2_RAMP, 0x00}, |
| 252 | {WCD938X_ANA_MICB3, 0x10}, |
| 253 | {WCD938X_ANA_MICB4, 0x10}, |
| 254 | {WCD938X_BIAS_CTL, 0x2A}, |
| 255 | {WCD938X_BIAS_VBG_FINE_ADJ, 0x55}, |
| 256 | {WCD938X_LDOL_VDDCX_ADJUST, 0x01}, |
| 257 | {WCD938X_LDOL_DISABLE_LDOL, 0x00}, |
| 258 | {WCD938X_MBHC_CTL_CLK, 0x00}, |
| 259 | {WCD938X_MBHC_CTL_ANA, 0x00}, |
| 260 | {WCD938X_MBHC_CTL_SPARE_1, 0x00}, |
| 261 | {WCD938X_MBHC_CTL_SPARE_2, 0x00}, |
| 262 | {WCD938X_MBHC_CTL_BCS, 0x00}, |
| 263 | {WCD938X_MBHC_MOISTURE_DET_FSM_STATUS, 0x00}, |
| 264 | {WCD938X_MBHC_TEST_CTL, 0x00}, |
| 265 | {WCD938X_LDOH_MODE, 0x2B}, |
| 266 | {WCD938X_LDOH_BIAS, 0x68}, |
| 267 | {WCD938X_LDOH_STB_LOADS, 0x00}, |
| 268 | {WCD938X_LDOH_SLOWRAMP, 0x50}, |
| 269 | {WCD938X_MICB1_TEST_CTL_1, 0x1A}, |
| 270 | {WCD938X_MICB1_TEST_CTL_2, 0x00}, |
| 271 | {WCD938X_MICB1_TEST_CTL_3, 0xA4}, |
| 272 | {WCD938X_MICB2_TEST_CTL_1, 0x1A}, |
| 273 | {WCD938X_MICB2_TEST_CTL_2, 0x00}, |
| 274 | {WCD938X_MICB2_TEST_CTL_3, 0x24}, |
| 275 | {WCD938X_MICB3_TEST_CTL_1, 0x1A}, |
| 276 | {WCD938X_MICB3_TEST_CTL_2, 0x00}, |
| 277 | {WCD938X_MICB3_TEST_CTL_3, 0xA4}, |
| 278 | {WCD938X_MICB4_TEST_CTL_1, 0x1A}, |
| 279 | {WCD938X_MICB4_TEST_CTL_2, 0x00}, |
| 280 | {WCD938X_MICB4_TEST_CTL_3, 0xA4}, |
| 281 | {WCD938X_TX_COM_ADC_VCM, 0x39}, |
| 282 | {WCD938X_TX_COM_BIAS_ATEST, 0xE0}, |
| 283 | {WCD938X_TX_COM_SPARE1, 0x00}, |
| 284 | {WCD938X_TX_COM_SPARE2, 0x00}, |
| 285 | {WCD938X_TX_COM_TXFE_DIV_CTL, 0x22}, |
| 286 | {WCD938X_TX_COM_TXFE_DIV_START, 0x00}, |
| 287 | {WCD938X_TX_COM_SPARE3, 0x00}, |
| 288 | {WCD938X_TX_COM_SPARE4, 0x00}, |
| 289 | {WCD938X_TX_1_2_TEST_EN, 0xCC}, |
| 290 | {WCD938X_TX_1_2_ADC_IB, 0xE9}, |
| 291 | {WCD938X_TX_1_2_ATEST_REFCTL, 0x0A}, |
| 292 | {WCD938X_TX_1_2_TEST_CTL, 0x38}, |
| 293 | {WCD938X_TX_1_2_TEST_BLK_EN1, 0xFF}, |
| 294 | {WCD938X_TX_1_2_TXFE1_CLKDIV, 0x00}, |
| 295 | {WCD938X_TX_1_2_SAR2_ERR, 0x00}, |
| 296 | {WCD938X_TX_1_2_SAR1_ERR, 0x00}, |
| 297 | {WCD938X_TX_3_4_TEST_EN, 0xCC}, |
| 298 | {WCD938X_TX_3_4_ADC_IB, 0xE9}, |
| 299 | {WCD938X_TX_3_4_ATEST_REFCTL, 0x0A}, |
| 300 | {WCD938X_TX_3_4_TEST_CTL, 0x38}, |
| 301 | {WCD938X_TX_3_4_TEST_BLK_EN3, 0xFF}, |
| 302 | {WCD938X_TX_3_4_TXFE3_CLKDIV, 0x00}, |
| 303 | {WCD938X_TX_3_4_SAR4_ERR, 0x00}, |
| 304 | {WCD938X_TX_3_4_SAR3_ERR, 0x00}, |
| 305 | {WCD938X_TX_3_4_TEST_BLK_EN2, 0xFB}, |
| 306 | {WCD938X_TX_3_4_TXFE2_CLKDIV, 0x00}, |
| 307 | {WCD938X_TX_3_4_SPARE1, 0x00}, |
| 308 | {WCD938X_TX_3_4_TEST_BLK_EN4, 0xFB}, |
| 309 | {WCD938X_TX_3_4_TXFE4_CLKDIV, 0x00}, |
| 310 | {WCD938X_TX_3_4_SPARE2, 0x00}, |
| 311 | {WCD938X_CLASSH_MODE_1, 0x40}, |
| 312 | {WCD938X_CLASSH_MODE_2, 0x3A}, |
| 313 | {WCD938X_CLASSH_MODE_3, 0x00}, |
| 314 | {WCD938X_CLASSH_CTRL_VCL_1, 0x70}, |
| 315 | {WCD938X_CLASSH_CTRL_VCL_2, 0x82}, |
| 316 | {WCD938X_CLASSH_CTRL_CCL_1, 0x31}, |
| 317 | {WCD938X_CLASSH_CTRL_CCL_2, 0x80}, |
| 318 | {WCD938X_CLASSH_CTRL_CCL_3, 0x80}, |
| 319 | {WCD938X_CLASSH_CTRL_CCL_4, 0x51}, |
| 320 | {WCD938X_CLASSH_CTRL_CCL_5, 0x00}, |
| 321 | {WCD938X_CLASSH_BUCK_TMUX_A_D, 0x00}, |
| 322 | {WCD938X_CLASSH_BUCK_SW_DRV_CNTL, 0x77}, |
| 323 | {WCD938X_CLASSH_SPARE, 0x00}, |
| 324 | {WCD938X_FLYBACK_EN, 0x4E}, |
| 325 | {WCD938X_FLYBACK_VNEG_CTRL_1, 0x0B}, |
| 326 | {WCD938X_FLYBACK_VNEG_CTRL_2, 0x45}, |
| 327 | {WCD938X_FLYBACK_VNEG_CTRL_3, 0x74}, |
| 328 | {WCD938X_FLYBACK_VNEG_CTRL_4, 0x7F}, |
| 329 | {WCD938X_FLYBACK_VNEG_CTRL_5, 0x83}, |
| 330 | {WCD938X_FLYBACK_VNEG_CTRL_6, 0x98}, |
| 331 | {WCD938X_FLYBACK_VNEG_CTRL_7, 0xA9}, |
| 332 | {WCD938X_FLYBACK_VNEG_CTRL_8, 0x68}, |
| 333 | {WCD938X_FLYBACK_VNEG_CTRL_9, 0x64}, |
| 334 | {WCD938X_FLYBACK_VNEGDAC_CTRL_1, 0xED}, |
| 335 | {WCD938X_FLYBACK_VNEGDAC_CTRL_2, 0xF0}, |
| 336 | {WCD938X_FLYBACK_VNEGDAC_CTRL_3, 0xA6}, |
| 337 | {WCD938X_FLYBACK_CTRL_1, 0x65}, |
| 338 | {WCD938X_FLYBACK_TEST_CTL, 0x00}, |
| 339 | {WCD938X_RX_AUX_SW_CTL, 0x00}, |
| 340 | {WCD938X_RX_PA_AUX_IN_CONN, 0x01}, |
| 341 | {WCD938X_RX_TIMER_DIV, 0x32}, |
| 342 | {WCD938X_RX_OCP_CTL, 0x1F}, |
| 343 | {WCD938X_RX_OCP_COUNT, 0x77}, |
| 344 | {WCD938X_RX_BIAS_EAR_DAC, 0xA0}, |
| 345 | {WCD938X_RX_BIAS_EAR_AMP, 0xAA}, |
| 346 | {WCD938X_RX_BIAS_HPH_LDO, 0xA9}, |
| 347 | {WCD938X_RX_BIAS_HPH_PA, 0xAA}, |
| 348 | {WCD938X_RX_BIAS_HPH_RDACBUFF_CNP2, 0x8A}, |
| 349 | {WCD938X_RX_BIAS_HPH_RDAC_LDO, 0x88}, |
| 350 | {WCD938X_RX_BIAS_HPH_CNP1, 0x82}, |
| 351 | {WCD938X_RX_BIAS_HPH_LOWPOWER, 0x82}, |
| 352 | {WCD938X_RX_BIAS_AUX_DAC, 0xA0}, |
| 353 | {WCD938X_RX_BIAS_AUX_AMP, 0xAA}, |
| 354 | {WCD938X_RX_BIAS_VNEGDAC_BLEEDER, 0x50}, |
| 355 | {WCD938X_RX_BIAS_MISC, 0x00}, |
| 356 | {WCD938X_RX_BIAS_BUCK_RST, 0x08}, |
| 357 | {WCD938X_RX_BIAS_BUCK_VREF_ERRAMP, 0x44}, |
| 358 | {WCD938X_RX_BIAS_FLYB_ERRAMP, 0x40}, |
| 359 | {WCD938X_RX_BIAS_FLYB_BUFF, 0xAA}, |
| 360 | {WCD938X_RX_BIAS_FLYB_MID_RST, 0x14}, |
| 361 | {WCD938X_HPH_L_STATUS, 0x04}, |
| 362 | {WCD938X_HPH_R_STATUS, 0x04}, |
| 363 | {WCD938X_HPH_CNP_EN, 0x80}, |
| 364 | {WCD938X_HPH_CNP_WG_CTL, 0x9A}, |
| 365 | {WCD938X_HPH_CNP_WG_TIME, 0x14}, |
| 366 | {WCD938X_HPH_OCP_CTL, 0x28}, |
| 367 | {WCD938X_HPH_AUTO_CHOP, 0x16}, |
| 368 | {WCD938X_HPH_CHOP_CTL, 0x83}, |
| 369 | {WCD938X_HPH_PA_CTL1, 0x46}, |
| 370 | {WCD938X_HPH_PA_CTL2, 0x50}, |
| 371 | {WCD938X_HPH_L_EN, 0x80}, |
| 372 | {WCD938X_HPH_L_TEST, 0xE0}, |
| 373 | {WCD938X_HPH_L_ATEST, 0x50}, |
| 374 | {WCD938X_HPH_R_EN, 0x80}, |
| 375 | {WCD938X_HPH_R_TEST, 0xE0}, |
| 376 | {WCD938X_HPH_R_ATEST, 0x54}, |
| 377 | {WCD938X_HPH_RDAC_CLK_CTL1, 0x99}, |
| 378 | {WCD938X_HPH_RDAC_CLK_CTL2, 0x9B}, |
| 379 | {WCD938X_HPH_RDAC_LDO_CTL, 0x33}, |
| 380 | {WCD938X_HPH_RDAC_CHOP_CLK_LP_CTL, 0x00}, |
| 381 | {WCD938X_HPH_REFBUFF_UHQA_CTL, 0x68}, |
| 382 | {WCD938X_HPH_REFBUFF_LP_CTL, 0x0E}, |
| 383 | {WCD938X_HPH_L_DAC_CTL, 0x20}, |
| 384 | {WCD938X_HPH_R_DAC_CTL, 0x20}, |
| 385 | {WCD938X_HPH_SURGE_HPHLR_SURGE_COMP_SEL, 0x55}, |
| 386 | {WCD938X_HPH_SURGE_HPHLR_SURGE_EN, 0x19}, |
| 387 | {WCD938X_HPH_SURGE_HPHLR_SURGE_MISC1, 0xA0}, |
| 388 | {WCD938X_HPH_SURGE_HPHLR_SURGE_STATUS, 0x00}, |
| 389 | {WCD938X_EAR_EAR_EN_REG, 0x22}, |
| 390 | {WCD938X_EAR_EAR_PA_CON, 0x44}, |
| 391 | {WCD938X_EAR_EAR_SP_CON, 0xDB}, |
| 392 | {WCD938X_EAR_EAR_DAC_CON, 0x80}, |
| 393 | {WCD938X_EAR_EAR_CNP_FSM_CON, 0xB2}, |
| 394 | {WCD938X_EAR_TEST_CTL, 0x00}, |
| 395 | {WCD938X_EAR_STATUS_REG_1, 0x00}, |
| 396 | {WCD938X_EAR_STATUS_REG_2, 0x08}, |
| 397 | {WCD938X_ANA_NEW_PAGE_REGISTER, 0x00}, |
| 398 | {WCD938X_HPH_NEW_ANA_HPH2, 0x00}, |
| 399 | {WCD938X_HPH_NEW_ANA_HPH3, 0x00}, |
| 400 | {WCD938X_SLEEP_CTL, 0x16}, |
| 401 | {WCD938X_SLEEP_WATCHDOG_CTL, 0x00}, |
| 402 | {WCD938X_MBHC_NEW_ELECT_REM_CLAMP_CTL, 0x00}, |
| 403 | {WCD938X_MBHC_NEW_CTL_1, 0x02}, |
| 404 | {WCD938X_MBHC_NEW_CTL_2, 0x05}, |
| 405 | {WCD938X_MBHC_NEW_PLUG_DETECT_CTL, 0xE9}, |
| 406 | {WCD938X_MBHC_NEW_ZDET_ANA_CTL, 0x0F}, |
| 407 | {WCD938X_MBHC_NEW_ZDET_RAMP_CTL, 0x00}, |
| 408 | {WCD938X_MBHC_NEW_FSM_STATUS, 0x00}, |
| 409 | {WCD938X_MBHC_NEW_ADC_RESULT, 0x00}, |
| 410 | {WCD938X_TX_NEW_AMIC_MUX_CFG, 0x00}, |
| 411 | {WCD938X_AUX_AUXPA, 0x00}, |
| 412 | {WCD938X_LDORXTX_MODE, 0x0C}, |
| 413 | {WCD938X_LDORXTX_CONFIG, 0x10}, |
| 414 | {WCD938X_DIE_CRACK_DIE_CRK_DET_EN, 0x00}, |
| 415 | {WCD938X_DIE_CRACK_DIE_CRK_DET_OUT, 0x00}, |
| 416 | {WCD938X_HPH_NEW_INT_RDAC_GAIN_CTL, 0x40}, |
| 417 | {WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L, 0x81}, |
| 418 | {WCD938X_HPH_NEW_INT_RDAC_VREF_CTL, 0x10}, |
| 419 | {WCD938X_HPH_NEW_INT_RDAC_OVERRIDE_CTL, 0x00}, |
| 420 | {WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R, 0x81}, |
| 421 | {WCD938X_HPH_NEW_INT_PA_MISC1, 0x22}, |
| 422 | {WCD938X_HPH_NEW_INT_PA_MISC2, 0x00}, |
| 423 | {WCD938X_HPH_NEW_INT_PA_RDAC_MISC, 0x00}, |
| 424 | {WCD938X_HPH_NEW_INT_HPH_TIMER1, 0xFE}, |
| 425 | {WCD938X_HPH_NEW_INT_HPH_TIMER2, 0x02}, |
| 426 | {WCD938X_HPH_NEW_INT_HPH_TIMER3, 0x4E}, |
| 427 | {WCD938X_HPH_NEW_INT_HPH_TIMER4, 0x54}, |
| 428 | {WCD938X_HPH_NEW_INT_PA_RDAC_MISC2, 0x00}, |
| 429 | {WCD938X_HPH_NEW_INT_PA_RDAC_MISC3, 0x00}, |
| 430 | {WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L_NEW, 0x90}, |
| 431 | {WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R_NEW, 0x90}, |
| 432 | {WCD938X_RX_NEW_INT_HPH_RDAC_BIAS_LOHIFI, 0x62}, |
| 433 | {WCD938X_RX_NEW_INT_HPH_RDAC_BIAS_ULP, 0x01}, |
| 434 | {WCD938X_RX_NEW_INT_HPH_RDAC_LDO_LP, 0x11}, |
| 435 | {WCD938X_MBHC_NEW_INT_MOISTURE_DET_DC_CTRL, 0x57}, |
| 436 | {WCD938X_MBHC_NEW_INT_MOISTURE_DET_POLLING_CTRL, 0x01}, |
| 437 | {WCD938X_MBHC_NEW_INT_MECH_DET_CURRENT, 0x00}, |
| 438 | {WCD938X_MBHC_NEW_INT_SPARE_2, 0x00}, |
| 439 | {WCD938X_EAR_INT_NEW_EAR_CHOPPER_CON, 0xA8}, |
| 440 | {WCD938X_EAR_INT_NEW_CNP_VCM_CON1, 0x42}, |
| 441 | {WCD938X_EAR_INT_NEW_CNP_VCM_CON2, 0x22}, |
| 442 | {WCD938X_EAR_INT_NEW_EAR_DYNAMIC_BIAS, 0x00}, |
| 443 | {WCD938X_AUX_INT_EN_REG, 0x00}, |
| 444 | {WCD938X_AUX_INT_PA_CTRL, 0x06}, |
| 445 | {WCD938X_AUX_INT_SP_CTRL, 0xD2}, |
| 446 | {WCD938X_AUX_INT_DAC_CTRL, 0x80}, |
| 447 | {WCD938X_AUX_INT_CLK_CTRL, 0x50}, |
| 448 | {WCD938X_AUX_INT_TEST_CTRL, 0x00}, |
| 449 | {WCD938X_AUX_INT_STATUS_REG, 0x00}, |
| 450 | {WCD938X_AUX_INT_MISC, 0x00}, |
| 451 | {WCD938X_LDORXTX_INT_BIAS, 0x6E}, |
| 452 | {WCD938X_LDORXTX_INT_STB_LOADS_DTEST, 0x50}, |
| 453 | {WCD938X_LDORXTX_INT_TEST0, 0x1C}, |
| 454 | {WCD938X_LDORXTX_INT_STARTUP_TIMER, 0xFF}, |
| 455 | {WCD938X_LDORXTX_INT_TEST1, 0x1F}, |
| 456 | {WCD938X_LDORXTX_INT_STATUS, 0x00}, |
| 457 | {WCD938X_SLEEP_INT_WATCHDOG_CTL_1, 0x0A}, |
| 458 | {WCD938X_SLEEP_INT_WATCHDOG_CTL_2, 0x0A}, |
| 459 | {WCD938X_DIE_CRACK_INT_DIE_CRK_DET_INT1, 0x02}, |
| 460 | {WCD938X_DIE_CRACK_INT_DIE_CRK_DET_INT2, 0x60}, |
| 461 | {WCD938X_TX_COM_NEW_INT_TXFE_DIVSTOP_L2, 0xFF}, |
| 462 | {WCD938X_TX_COM_NEW_INT_TXFE_DIVSTOP_L1, 0x7F}, |
| 463 | {WCD938X_TX_COM_NEW_INT_TXFE_DIVSTOP_L0, 0x3F}, |
| 464 | {WCD938X_TX_COM_NEW_INT_TXFE_DIVSTOP_ULP1P2M, 0x1F}, |
| 465 | {WCD938X_TX_COM_NEW_INT_TXFE_DIVSTOP_ULP0P6M, 0x0F}, |
| 466 | {WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG1_L2L1, 0xD7}, |
| 467 | {WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG1_L0, 0xC8}, |
| 468 | {WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG1_ULP, 0xC6}, |
| 469 | {WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2MAIN_L2L1, 0xD5}, |
| 470 | {WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2MAIN_L0, 0xCA}, |
| 471 | {WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2MAIN_ULP, 0x05}, |
| 472 | {WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2CASC_L2L1L0, 0xA5}, |
| 473 | {WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2CASC_ULP, 0x13}, |
| 474 | {WCD938X_TX_COM_NEW_INT_TXADC_SCBIAS_L2L1, 0x88}, |
| 475 | {WCD938X_TX_COM_NEW_INT_TXADC_SCBIAS_L0ULP, 0x42}, |
| 476 | {WCD938X_TX_COM_NEW_INT_TXADC_INT_L2, 0xFF}, |
| 477 | {WCD938X_TX_COM_NEW_INT_TXADC_INT_L1, 0x64}, |
| 478 | {WCD938X_TX_COM_NEW_INT_TXADC_INT_L0, 0x64}, |
| 479 | {WCD938X_TX_COM_NEW_INT_TXADC_INT_ULP, 0x77}, |
| 480 | {WCD938X_DIGITAL_PAGE_REGISTER, 0x00}, |
| 481 | {WCD938X_DIGITAL_CHIP_ID0, 0x00}, |
| 482 | {WCD938X_DIGITAL_CHIP_ID1, 0x00}, |
| 483 | {WCD938X_DIGITAL_CHIP_ID2, 0x0D}, |
| 484 | {WCD938X_DIGITAL_CHIP_ID3, 0x01}, |
| 485 | {WCD938X_DIGITAL_SWR_TX_CLK_RATE, 0x00}, |
| 486 | {WCD938X_DIGITAL_CDC_RST_CTL, 0x03}, |
| 487 | {WCD938X_DIGITAL_TOP_CLK_CFG, 0x00}, |
| 488 | {WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x00}, |
| 489 | {WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0xF0}, |
| 490 | {WCD938X_DIGITAL_SWR_RST_EN, 0x00}, |
| 491 | {WCD938X_DIGITAL_CDC_PATH_MODE, 0x55}, |
| 492 | {WCD938X_DIGITAL_CDC_RX_RST, 0x00}, |
| 493 | {WCD938X_DIGITAL_CDC_RX0_CTL, 0xFC}, |
| 494 | {WCD938X_DIGITAL_CDC_RX1_CTL, 0xFC}, |
| 495 | {WCD938X_DIGITAL_CDC_RX2_CTL, 0xFC}, |
| 496 | {WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, 0x00}, |
| 497 | {WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, 0x00}, |
| 498 | {WCD938X_DIGITAL_CDC_COMP_CTL_0, 0x00}, |
| 499 | {WCD938X_DIGITAL_CDC_ANA_TX_CLK_CTL, 0x1E}, |
| 500 | {WCD938X_DIGITAL_CDC_HPH_DSM_A1_0, 0x00}, |
| 501 | {WCD938X_DIGITAL_CDC_HPH_DSM_A1_1, 0x01}, |
| 502 | {WCD938X_DIGITAL_CDC_HPH_DSM_A2_0, 0x63}, |
| 503 | {WCD938X_DIGITAL_CDC_HPH_DSM_A2_1, 0x04}, |
| 504 | {WCD938X_DIGITAL_CDC_HPH_DSM_A3_0, 0xAC}, |
| 505 | {WCD938X_DIGITAL_CDC_HPH_DSM_A3_1, 0x04}, |
| 506 | {WCD938X_DIGITAL_CDC_HPH_DSM_A4_0, 0x1A}, |
| 507 | {WCD938X_DIGITAL_CDC_HPH_DSM_A4_1, 0x03}, |
| 508 | {WCD938X_DIGITAL_CDC_HPH_DSM_A5_0, 0xBC}, |
| 509 | {WCD938X_DIGITAL_CDC_HPH_DSM_A5_1, 0x02}, |
| 510 | {WCD938X_DIGITAL_CDC_HPH_DSM_A6_0, 0xC7}, |
| 511 | {WCD938X_DIGITAL_CDC_HPH_DSM_A7_0, 0xF8}, |
| 512 | {WCD938X_DIGITAL_CDC_HPH_DSM_C_0, 0x47}, |
| 513 | {WCD938X_DIGITAL_CDC_HPH_DSM_C_1, 0x43}, |
| 514 | {WCD938X_DIGITAL_CDC_HPH_DSM_C_2, 0xB1}, |
| 515 | {WCD938X_DIGITAL_CDC_HPH_DSM_C_3, 0x17}, |
| 516 | {WCD938X_DIGITAL_CDC_HPH_DSM_R1, 0x4D}, |
| 517 | {WCD938X_DIGITAL_CDC_HPH_DSM_R2, 0x29}, |
| 518 | {WCD938X_DIGITAL_CDC_HPH_DSM_R3, 0x34}, |
| 519 | {WCD938X_DIGITAL_CDC_HPH_DSM_R4, 0x59}, |
| 520 | {WCD938X_DIGITAL_CDC_HPH_DSM_R5, 0x66}, |
| 521 | {WCD938X_DIGITAL_CDC_HPH_DSM_R6, 0x87}, |
| 522 | {WCD938X_DIGITAL_CDC_HPH_DSM_R7, 0x64}, |
| 523 | {WCD938X_DIGITAL_CDC_AUX_DSM_A1_0, 0x00}, |
| 524 | {WCD938X_DIGITAL_CDC_AUX_DSM_A1_1, 0x01}, |
| 525 | {WCD938X_DIGITAL_CDC_AUX_DSM_A2_0, 0x96}, |
| 526 | {WCD938X_DIGITAL_CDC_AUX_DSM_A2_1, 0x09}, |
| 527 | {WCD938X_DIGITAL_CDC_AUX_DSM_A3_0, 0xAB}, |
| 528 | {WCD938X_DIGITAL_CDC_AUX_DSM_A3_1, 0x05}, |
| 529 | {WCD938X_DIGITAL_CDC_AUX_DSM_A4_0, 0x1C}, |
| 530 | {WCD938X_DIGITAL_CDC_AUX_DSM_A4_1, 0x02}, |
| 531 | {WCD938X_DIGITAL_CDC_AUX_DSM_A5_0, 0x17}, |
| 532 | {WCD938X_DIGITAL_CDC_AUX_DSM_A5_1, 0x02}, |
| 533 | {WCD938X_DIGITAL_CDC_AUX_DSM_A6_0, 0xAA}, |
| 534 | {WCD938X_DIGITAL_CDC_AUX_DSM_A7_0, 0xE3}, |
| 535 | {WCD938X_DIGITAL_CDC_AUX_DSM_C_0, 0x69}, |
| 536 | {WCD938X_DIGITAL_CDC_AUX_DSM_C_1, 0x54}, |
| 537 | {WCD938X_DIGITAL_CDC_AUX_DSM_C_2, 0x02}, |
| 538 | {WCD938X_DIGITAL_CDC_AUX_DSM_C_3, 0x15}, |
| 539 | {WCD938X_DIGITAL_CDC_AUX_DSM_R1, 0xA4}, |
| 540 | {WCD938X_DIGITAL_CDC_AUX_DSM_R2, 0xB5}, |
| 541 | {WCD938X_DIGITAL_CDC_AUX_DSM_R3, 0x86}, |
| 542 | {WCD938X_DIGITAL_CDC_AUX_DSM_R4, 0x85}, |
| 543 | {WCD938X_DIGITAL_CDC_AUX_DSM_R5, 0xAA}, |
| 544 | {WCD938X_DIGITAL_CDC_AUX_DSM_R6, 0xE2}, |
| 545 | {WCD938X_DIGITAL_CDC_AUX_DSM_R7, 0x62}, |
| 546 | {WCD938X_DIGITAL_CDC_HPH_GAIN_RX_0, 0x55}, |
| 547 | {WCD938X_DIGITAL_CDC_HPH_GAIN_RX_1, 0xA9}, |
| 548 | {WCD938X_DIGITAL_CDC_HPH_GAIN_DSD_0, 0x3D}, |
| 549 | {WCD938X_DIGITAL_CDC_HPH_GAIN_DSD_1, 0x2E}, |
| 550 | {WCD938X_DIGITAL_CDC_HPH_GAIN_DSD_2, 0x01}, |
| 551 | {WCD938X_DIGITAL_CDC_AUX_GAIN_DSD_0, 0x00}, |
| 552 | {WCD938X_DIGITAL_CDC_AUX_GAIN_DSD_1, 0xFC}, |
| 553 | {WCD938X_DIGITAL_CDC_AUX_GAIN_DSD_2, 0x01}, |
| 554 | {WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x00}, |
| 555 | {WCD938X_DIGITAL_CDC_AUX_GAIN_CTL, 0x00}, |
| 556 | {WCD938X_DIGITAL_CDC_EAR_PATH_CTL, 0x00}, |
| 557 | {WCD938X_DIGITAL_CDC_SWR_CLH, 0x00}, |
| 558 | {WCD938X_DIGITAL_SWR_CLH_BYP, 0x00}, |
| 559 | {WCD938X_DIGITAL_CDC_TX0_CTL, 0x68}, |
| 560 | {WCD938X_DIGITAL_CDC_TX1_CTL, 0x68}, |
| 561 | {WCD938X_DIGITAL_CDC_TX2_CTL, 0x68}, |
| 562 | {WCD938X_DIGITAL_CDC_TX_RST, 0x00}, |
| 563 | {WCD938X_DIGITAL_CDC_REQ_CTL, 0x01}, |
| 564 | {WCD938X_DIGITAL_CDC_RST, 0x00}, |
| 565 | {WCD938X_DIGITAL_CDC_AMIC_CTL, 0x0F}, |
| 566 | {WCD938X_DIGITAL_CDC_DMIC_CTL, 0x04}, |
| 567 | {WCD938X_DIGITAL_CDC_DMIC1_CTL, 0x01}, |
| 568 | {WCD938X_DIGITAL_CDC_DMIC2_CTL, 0x01}, |
| 569 | {WCD938X_DIGITAL_CDC_DMIC3_CTL, 0x01}, |
| 570 | {WCD938X_DIGITAL_CDC_DMIC4_CTL, 0x01}, |
| 571 | {WCD938X_DIGITAL_EFUSE_PRG_CTL, 0x00}, |
| 572 | {WCD938X_DIGITAL_EFUSE_CTL, 0x2B}, |
| 573 | {WCD938X_DIGITAL_CDC_DMIC_RATE_1_2, 0x11}, |
| 574 | {WCD938X_DIGITAL_CDC_DMIC_RATE_3_4, 0x11}, |
| 575 | {WCD938X_DIGITAL_PDM_WD_CTL0, 0x00}, |
| 576 | {WCD938X_DIGITAL_PDM_WD_CTL1, 0x00}, |
| 577 | {WCD938X_DIGITAL_PDM_WD_CTL2, 0x00}, |
| 578 | {WCD938X_DIGITAL_INTR_MODE, 0x00}, |
| 579 | {WCD938X_DIGITAL_INTR_MASK_0, 0xFF}, |
| 580 | {WCD938X_DIGITAL_INTR_MASK_1, 0xFF}, |
| 581 | {WCD938X_DIGITAL_INTR_MASK_2, 0x3F}, |
| 582 | {WCD938X_DIGITAL_INTR_STATUS_0, 0x00}, |
| 583 | {WCD938X_DIGITAL_INTR_STATUS_1, 0x00}, |
| 584 | {WCD938X_DIGITAL_INTR_STATUS_2, 0x00}, |
| 585 | {WCD938X_DIGITAL_INTR_CLEAR_0, 0x00}, |
| 586 | {WCD938X_DIGITAL_INTR_CLEAR_1, 0x00}, |
| 587 | {WCD938X_DIGITAL_INTR_CLEAR_2, 0x00}, |
| 588 | {WCD938X_DIGITAL_INTR_LEVEL_0, 0x00}, |
| 589 | {WCD938X_DIGITAL_INTR_LEVEL_1, 0x00}, |
| 590 | {WCD938X_DIGITAL_INTR_LEVEL_2, 0x00}, |
| 591 | {WCD938X_DIGITAL_INTR_SET_0, 0x00}, |
| 592 | {WCD938X_DIGITAL_INTR_SET_1, 0x00}, |
| 593 | {WCD938X_DIGITAL_INTR_SET_2, 0x00}, |
| 594 | {WCD938X_DIGITAL_INTR_TEST_0, 0x00}, |
| 595 | {WCD938X_DIGITAL_INTR_TEST_1, 0x00}, |
| 596 | {WCD938X_DIGITAL_INTR_TEST_2, 0x00}, |
| 597 | {WCD938X_DIGITAL_TX_MODE_DBG_EN, 0x00}, |
| 598 | {WCD938X_DIGITAL_TX_MODE_DBG_0_1, 0x00}, |
| 599 | {WCD938X_DIGITAL_TX_MODE_DBG_2_3, 0x00}, |
| 600 | {WCD938X_DIGITAL_LB_IN_SEL_CTL, 0x00}, |
| 601 | {WCD938X_DIGITAL_LOOP_BACK_MODE, 0x00}, |
| 602 | {WCD938X_DIGITAL_SWR_DAC_TEST, 0x00}, |
| 603 | {WCD938X_DIGITAL_SWR_HM_TEST_RX_0, 0x40}, |
| 604 | {WCD938X_DIGITAL_SWR_HM_TEST_TX_0, 0x40}, |
| 605 | {WCD938X_DIGITAL_SWR_HM_TEST_RX_1, 0x00}, |
| 606 | {WCD938X_DIGITAL_SWR_HM_TEST_TX_1, 0x00}, |
| 607 | {WCD938X_DIGITAL_SWR_HM_TEST_TX_2, 0x00}, |
| 608 | {WCD938X_DIGITAL_SWR_HM_TEST_0, 0x00}, |
| 609 | {WCD938X_DIGITAL_SWR_HM_TEST_1, 0x00}, |
| 610 | {WCD938X_DIGITAL_PAD_CTL_SWR_0, 0x8F}, |
| 611 | {WCD938X_DIGITAL_PAD_CTL_SWR_1, 0x06}, |
| 612 | {WCD938X_DIGITAL_I2C_CTL, 0x00}, |
| 613 | {WCD938X_DIGITAL_CDC_TX_TANGGU_SW_MODE, 0x00}, |
| 614 | {WCD938X_DIGITAL_EFUSE_TEST_CTL_0, 0x00}, |
| 615 | {WCD938X_DIGITAL_EFUSE_TEST_CTL_1, 0x00}, |
| 616 | {WCD938X_DIGITAL_EFUSE_T_DATA_0, 0x00}, |
| 617 | {WCD938X_DIGITAL_EFUSE_T_DATA_1, 0x00}, |
| 618 | {WCD938X_DIGITAL_PAD_CTL_PDM_RX0, 0xF1}, |
| 619 | {WCD938X_DIGITAL_PAD_CTL_PDM_RX1, 0xF1}, |
| 620 | {WCD938X_DIGITAL_PAD_CTL_PDM_TX0, 0xF1}, |
| 621 | {WCD938X_DIGITAL_PAD_CTL_PDM_TX1, 0xF1}, |
| 622 | {WCD938X_DIGITAL_PAD_CTL_PDM_TX2, 0xF1}, |
| 623 | {WCD938X_DIGITAL_PAD_INP_DIS_0, 0x00}, |
| 624 | {WCD938X_DIGITAL_PAD_INP_DIS_1, 0x00}, |
| 625 | {WCD938X_DIGITAL_DRIVE_STRENGTH_0, 0x00}, |
| 626 | {WCD938X_DIGITAL_DRIVE_STRENGTH_1, 0x00}, |
| 627 | {WCD938X_DIGITAL_DRIVE_STRENGTH_2, 0x00}, |
| 628 | {WCD938X_DIGITAL_RX_DATA_EDGE_CTL, 0x1F}, |
| 629 | {WCD938X_DIGITAL_TX_DATA_EDGE_CTL, 0x80}, |
| 630 | {WCD938X_DIGITAL_GPIO_MODE, 0x00}, |
| 631 | {WCD938X_DIGITAL_PIN_CTL_OE, 0x00}, |
| 632 | {WCD938X_DIGITAL_PIN_CTL_DATA_0, 0x00}, |
| 633 | {WCD938X_DIGITAL_PIN_CTL_DATA_1, 0x00}, |
| 634 | {WCD938X_DIGITAL_PIN_STATUS_0, 0x00}, |
| 635 | {WCD938X_DIGITAL_PIN_STATUS_1, 0x00}, |
| 636 | {WCD938X_DIGITAL_DIG_DEBUG_CTL, 0x00}, |
| 637 | {WCD938X_DIGITAL_DIG_DEBUG_EN, 0x00}, |
| 638 | {WCD938X_DIGITAL_ANA_CSR_DBG_ADD, 0x00}, |
| 639 | {WCD938X_DIGITAL_ANA_CSR_DBG_CTL, 0x48}, |
| 640 | {WCD938X_DIGITAL_SSP_DBG, 0x00}, |
| 641 | {WCD938X_DIGITAL_MODE_STATUS_0, 0x00}, |
| 642 | {WCD938X_DIGITAL_MODE_STATUS_1, 0x00}, |
| 643 | {WCD938X_DIGITAL_SPARE_0, 0x00}, |
| 644 | {WCD938X_DIGITAL_SPARE_1, 0x00}, |
| 645 | {WCD938X_DIGITAL_SPARE_2, 0x00}, |
| 646 | {WCD938X_DIGITAL_EFUSE_REG_0, 0x00}, |
| 647 | {WCD938X_DIGITAL_EFUSE_REG_1, 0xFF}, |
| 648 | {WCD938X_DIGITAL_EFUSE_REG_2, 0xFF}, |
| 649 | {WCD938X_DIGITAL_EFUSE_REG_3, 0xFF}, |
| 650 | {WCD938X_DIGITAL_EFUSE_REG_4, 0xFF}, |
| 651 | {WCD938X_DIGITAL_EFUSE_REG_5, 0xFF}, |
| 652 | {WCD938X_DIGITAL_EFUSE_REG_6, 0xFF}, |
| 653 | {WCD938X_DIGITAL_EFUSE_REG_7, 0xFF}, |
| 654 | {WCD938X_DIGITAL_EFUSE_REG_8, 0xFF}, |
| 655 | {WCD938X_DIGITAL_EFUSE_REG_9, 0xFF}, |
| 656 | {WCD938X_DIGITAL_EFUSE_REG_10, 0xFF}, |
| 657 | {WCD938X_DIGITAL_EFUSE_REG_11, 0xFF}, |
| 658 | {WCD938X_DIGITAL_EFUSE_REG_12, 0xFF}, |
| 659 | {WCD938X_DIGITAL_EFUSE_REG_13, 0xFF}, |
| 660 | {WCD938X_DIGITAL_EFUSE_REG_14, 0xFF}, |
| 661 | {WCD938X_DIGITAL_EFUSE_REG_15, 0xFF}, |
| 662 | {WCD938X_DIGITAL_EFUSE_REG_16, 0xFF}, |
| 663 | {WCD938X_DIGITAL_EFUSE_REG_17, 0xFF}, |
| 664 | {WCD938X_DIGITAL_EFUSE_REG_18, 0xFF}, |
| 665 | {WCD938X_DIGITAL_EFUSE_REG_19, 0xFF}, |
| 666 | {WCD938X_DIGITAL_EFUSE_REG_20, 0x0E}, |
| 667 | {WCD938X_DIGITAL_EFUSE_REG_21, 0x00}, |
| 668 | {WCD938X_DIGITAL_EFUSE_REG_22, 0x00}, |
| 669 | {WCD938X_DIGITAL_EFUSE_REG_23, 0xF8}, |
| 670 | {WCD938X_DIGITAL_EFUSE_REG_24, 0x16}, |
| 671 | {WCD938X_DIGITAL_EFUSE_REG_25, 0x00}, |
| 672 | {WCD938X_DIGITAL_EFUSE_REG_26, 0x00}, |
| 673 | {WCD938X_DIGITAL_EFUSE_REG_27, 0x00}, |
| 674 | {WCD938X_DIGITAL_EFUSE_REG_28, 0x00}, |
| 675 | {WCD938X_DIGITAL_EFUSE_REG_29, 0x00}, |
| 676 | {WCD938X_DIGITAL_EFUSE_REG_30, 0x00}, |
| 677 | {WCD938X_DIGITAL_EFUSE_REG_31, 0x00}, |
| 678 | {WCD938X_DIGITAL_TX_REQ_FB_CTL_0, 0x88}, |
| 679 | {WCD938X_DIGITAL_TX_REQ_FB_CTL_1, 0x88}, |
| 680 | {WCD938X_DIGITAL_TX_REQ_FB_CTL_2, 0x88}, |
| 681 | {WCD938X_DIGITAL_TX_REQ_FB_CTL_3, 0x88}, |
| 682 | {WCD938X_DIGITAL_TX_REQ_FB_CTL_4, 0x88}, |
| 683 | {WCD938X_DIGITAL_DEM_BYPASS_DATA0, 0x55}, |
| 684 | {WCD938X_DIGITAL_DEM_BYPASS_DATA1, 0x55}, |
| 685 | {WCD938X_DIGITAL_DEM_BYPASS_DATA2, 0x55}, |
| 686 | {WCD938X_DIGITAL_DEM_BYPASS_DATA3, 0x01}, |
| 687 | }; |
| 688 | |
| 689 | static bool wcd938x_rdwr_register(struct device *dev, unsigned int reg) |
| 690 | { |
| 691 | switch (reg) { |
| 692 | case WCD938X_ANA_PAGE_REGISTER: |
| 693 | case WCD938X_ANA_BIAS: |
| 694 | case WCD938X_ANA_RX_SUPPLIES: |
| 695 | case WCD938X_ANA_HPH: |
| 696 | case WCD938X_ANA_EAR: |
| 697 | case WCD938X_ANA_EAR_COMPANDER_CTL: |
| 698 | case WCD938X_ANA_TX_CH1: |
| 699 | case WCD938X_ANA_TX_CH2: |
| 700 | case WCD938X_ANA_TX_CH3: |
| 701 | case WCD938X_ANA_TX_CH4: |
| 702 | case WCD938X_ANA_MICB1_MICB2_DSP_EN_LOGIC: |
| 703 | case WCD938X_ANA_MICB3_DSP_EN_LOGIC: |
| 704 | case WCD938X_ANA_MBHC_MECH: |
| 705 | case WCD938X_ANA_MBHC_ELECT: |
| 706 | case WCD938X_ANA_MBHC_ZDET: |
| 707 | case WCD938X_ANA_MBHC_BTN0: |
| 708 | case WCD938X_ANA_MBHC_BTN1: |
| 709 | case WCD938X_ANA_MBHC_BTN2: |
| 710 | case WCD938X_ANA_MBHC_BTN3: |
| 711 | case WCD938X_ANA_MBHC_BTN4: |
| 712 | case WCD938X_ANA_MBHC_BTN5: |
| 713 | case WCD938X_ANA_MBHC_BTN6: |
| 714 | case WCD938X_ANA_MBHC_BTN7: |
| 715 | case WCD938X_ANA_MICB1: |
| 716 | case WCD938X_ANA_MICB2: |
| 717 | case WCD938X_ANA_MICB2_RAMP: |
| 718 | case WCD938X_ANA_MICB3: |
| 719 | case WCD938X_ANA_MICB4: |
| 720 | case WCD938X_BIAS_CTL: |
| 721 | case WCD938X_BIAS_VBG_FINE_ADJ: |
| 722 | case WCD938X_LDOL_VDDCX_ADJUST: |
| 723 | case WCD938X_LDOL_DISABLE_LDOL: |
| 724 | case WCD938X_MBHC_CTL_CLK: |
| 725 | case WCD938X_MBHC_CTL_ANA: |
| 726 | case WCD938X_MBHC_CTL_SPARE_1: |
| 727 | case WCD938X_MBHC_CTL_SPARE_2: |
| 728 | case WCD938X_MBHC_CTL_BCS: |
| 729 | case WCD938X_MBHC_TEST_CTL: |
| 730 | case WCD938X_LDOH_MODE: |
| 731 | case WCD938X_LDOH_BIAS: |
| 732 | case WCD938X_LDOH_STB_LOADS: |
| 733 | case WCD938X_LDOH_SLOWRAMP: |
| 734 | case WCD938X_MICB1_TEST_CTL_1: |
| 735 | case WCD938X_MICB1_TEST_CTL_2: |
| 736 | case WCD938X_MICB1_TEST_CTL_3: |
| 737 | case WCD938X_MICB2_TEST_CTL_1: |
| 738 | case WCD938X_MICB2_TEST_CTL_2: |
| 739 | case WCD938X_MICB2_TEST_CTL_3: |
| 740 | case WCD938X_MICB3_TEST_CTL_1: |
| 741 | case WCD938X_MICB3_TEST_CTL_2: |
| 742 | case WCD938X_MICB3_TEST_CTL_3: |
| 743 | case WCD938X_MICB4_TEST_CTL_1: |
| 744 | case WCD938X_MICB4_TEST_CTL_2: |
| 745 | case WCD938X_MICB4_TEST_CTL_3: |
| 746 | case WCD938X_TX_COM_ADC_VCM: |
| 747 | case WCD938X_TX_COM_BIAS_ATEST: |
| 748 | case WCD938X_TX_COM_SPARE1: |
| 749 | case WCD938X_TX_COM_SPARE2: |
| 750 | case WCD938X_TX_COM_TXFE_DIV_CTL: |
| 751 | case WCD938X_TX_COM_TXFE_DIV_START: |
| 752 | case WCD938X_TX_COM_SPARE3: |
| 753 | case WCD938X_TX_COM_SPARE4: |
| 754 | case WCD938X_TX_1_2_TEST_EN: |
| 755 | case WCD938X_TX_1_2_ADC_IB: |
| 756 | case WCD938X_TX_1_2_ATEST_REFCTL: |
| 757 | case WCD938X_TX_1_2_TEST_CTL: |
| 758 | case WCD938X_TX_1_2_TEST_BLK_EN1: |
| 759 | case WCD938X_TX_1_2_TXFE1_CLKDIV: |
| 760 | case WCD938X_TX_3_4_TEST_EN: |
| 761 | case WCD938X_TX_3_4_ADC_IB: |
| 762 | case WCD938X_TX_3_4_ATEST_REFCTL: |
| 763 | case WCD938X_TX_3_4_TEST_CTL: |
| 764 | case WCD938X_TX_3_4_TEST_BLK_EN3: |
| 765 | case WCD938X_TX_3_4_TXFE3_CLKDIV: |
| 766 | case WCD938X_TX_3_4_TEST_BLK_EN2: |
| 767 | case WCD938X_TX_3_4_TXFE2_CLKDIV: |
| 768 | case WCD938X_TX_3_4_SPARE1: |
| 769 | case WCD938X_TX_3_4_TEST_BLK_EN4: |
| 770 | case WCD938X_TX_3_4_TXFE4_CLKDIV: |
| 771 | case WCD938X_TX_3_4_SPARE2: |
| 772 | case WCD938X_CLASSH_MODE_1: |
| 773 | case WCD938X_CLASSH_MODE_2: |
| 774 | case WCD938X_CLASSH_MODE_3: |
| 775 | case WCD938X_CLASSH_CTRL_VCL_1: |
| 776 | case WCD938X_CLASSH_CTRL_VCL_2: |
| 777 | case WCD938X_CLASSH_CTRL_CCL_1: |
| 778 | case WCD938X_CLASSH_CTRL_CCL_2: |
| 779 | case WCD938X_CLASSH_CTRL_CCL_3: |
| 780 | case WCD938X_CLASSH_CTRL_CCL_4: |
| 781 | case WCD938X_CLASSH_CTRL_CCL_5: |
| 782 | case WCD938X_CLASSH_BUCK_TMUX_A_D: |
| 783 | case WCD938X_CLASSH_BUCK_SW_DRV_CNTL: |
| 784 | case WCD938X_CLASSH_SPARE: |
| 785 | case WCD938X_FLYBACK_EN: |
| 786 | case WCD938X_FLYBACK_VNEG_CTRL_1: |
| 787 | case WCD938X_FLYBACK_VNEG_CTRL_2: |
| 788 | case WCD938X_FLYBACK_VNEG_CTRL_3: |
| 789 | case WCD938X_FLYBACK_VNEG_CTRL_4: |
| 790 | case WCD938X_FLYBACK_VNEG_CTRL_5: |
| 791 | case WCD938X_FLYBACK_VNEG_CTRL_6: |
| 792 | case WCD938X_FLYBACK_VNEG_CTRL_7: |
| 793 | case WCD938X_FLYBACK_VNEG_CTRL_8: |
| 794 | case WCD938X_FLYBACK_VNEG_CTRL_9: |
| 795 | case WCD938X_FLYBACK_VNEGDAC_CTRL_1: |
| 796 | case WCD938X_FLYBACK_VNEGDAC_CTRL_2: |
| 797 | case WCD938X_FLYBACK_VNEGDAC_CTRL_3: |
| 798 | case WCD938X_FLYBACK_CTRL_1: |
| 799 | case WCD938X_FLYBACK_TEST_CTL: |
| 800 | case WCD938X_RX_AUX_SW_CTL: |
| 801 | case WCD938X_RX_PA_AUX_IN_CONN: |
| 802 | case WCD938X_RX_TIMER_DIV: |
| 803 | case WCD938X_RX_OCP_CTL: |
| 804 | case WCD938X_RX_OCP_COUNT: |
| 805 | case WCD938X_RX_BIAS_EAR_DAC: |
| 806 | case WCD938X_RX_BIAS_EAR_AMP: |
| 807 | case WCD938X_RX_BIAS_HPH_LDO: |
| 808 | case WCD938X_RX_BIAS_HPH_PA: |
| 809 | case WCD938X_RX_BIAS_HPH_RDACBUFF_CNP2: |
| 810 | case WCD938X_RX_BIAS_HPH_RDAC_LDO: |
| 811 | case WCD938X_RX_BIAS_HPH_CNP1: |
| 812 | case WCD938X_RX_BIAS_HPH_LOWPOWER: |
| 813 | case WCD938X_RX_BIAS_AUX_DAC: |
| 814 | case WCD938X_RX_BIAS_AUX_AMP: |
| 815 | case WCD938X_RX_BIAS_VNEGDAC_BLEEDER: |
| 816 | case WCD938X_RX_BIAS_MISC: |
| 817 | case WCD938X_RX_BIAS_BUCK_RST: |
| 818 | case WCD938X_RX_BIAS_BUCK_VREF_ERRAMP: |
| 819 | case WCD938X_RX_BIAS_FLYB_ERRAMP: |
| 820 | case WCD938X_RX_BIAS_FLYB_BUFF: |
| 821 | case WCD938X_RX_BIAS_FLYB_MID_RST: |
| 822 | case WCD938X_HPH_CNP_EN: |
| 823 | case WCD938X_HPH_CNP_WG_CTL: |
| 824 | case WCD938X_HPH_CNP_WG_TIME: |
| 825 | case WCD938X_HPH_OCP_CTL: |
| 826 | case WCD938X_HPH_AUTO_CHOP: |
| 827 | case WCD938X_HPH_CHOP_CTL: |
| 828 | case WCD938X_HPH_PA_CTL1: |
| 829 | case WCD938X_HPH_PA_CTL2: |
| 830 | case WCD938X_HPH_L_EN: |
| 831 | case WCD938X_HPH_L_TEST: |
| 832 | case WCD938X_HPH_L_ATEST: |
| 833 | case WCD938X_HPH_R_EN: |
| 834 | case WCD938X_HPH_R_TEST: |
| 835 | case WCD938X_HPH_R_ATEST: |
| 836 | case WCD938X_HPH_RDAC_CLK_CTL1: |
| 837 | case WCD938X_HPH_RDAC_CLK_CTL2: |
| 838 | case WCD938X_HPH_RDAC_LDO_CTL: |
| 839 | case WCD938X_HPH_RDAC_CHOP_CLK_LP_CTL: |
| 840 | case WCD938X_HPH_REFBUFF_UHQA_CTL: |
| 841 | case WCD938X_HPH_REFBUFF_LP_CTL: |
| 842 | case WCD938X_HPH_L_DAC_CTL: |
| 843 | case WCD938X_HPH_R_DAC_CTL: |
| 844 | case WCD938X_HPH_SURGE_HPHLR_SURGE_COMP_SEL: |
| 845 | case WCD938X_HPH_SURGE_HPHLR_SURGE_EN: |
| 846 | case WCD938X_HPH_SURGE_HPHLR_SURGE_MISC1: |
| 847 | case WCD938X_EAR_EAR_EN_REG: |
| 848 | case WCD938X_EAR_EAR_PA_CON: |
| 849 | case WCD938X_EAR_EAR_SP_CON: |
| 850 | case WCD938X_EAR_EAR_DAC_CON: |
| 851 | case WCD938X_EAR_EAR_CNP_FSM_CON: |
| 852 | case WCD938X_EAR_TEST_CTL: |
| 853 | case WCD938X_ANA_NEW_PAGE_REGISTER: |
| 854 | case WCD938X_HPH_NEW_ANA_HPH2: |
| 855 | case WCD938X_HPH_NEW_ANA_HPH3: |
| 856 | case WCD938X_SLEEP_CTL: |
| 857 | case WCD938X_SLEEP_WATCHDOG_CTL: |
| 858 | case WCD938X_MBHC_NEW_ELECT_REM_CLAMP_CTL: |
| 859 | case WCD938X_MBHC_NEW_CTL_1: |
| 860 | case WCD938X_MBHC_NEW_CTL_2: |
| 861 | case WCD938X_MBHC_NEW_PLUG_DETECT_CTL: |
| 862 | case WCD938X_MBHC_NEW_ZDET_ANA_CTL: |
| 863 | case WCD938X_MBHC_NEW_ZDET_RAMP_CTL: |
| 864 | case WCD938X_TX_NEW_AMIC_MUX_CFG: |
| 865 | case WCD938X_AUX_AUXPA: |
| 866 | case WCD938X_LDORXTX_MODE: |
| 867 | case WCD938X_LDORXTX_CONFIG: |
| 868 | case WCD938X_DIE_CRACK_DIE_CRK_DET_EN: |
| 869 | case WCD938X_HPH_NEW_INT_RDAC_GAIN_CTL: |
| 870 | case WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L: |
| 871 | case WCD938X_HPH_NEW_INT_RDAC_VREF_CTL: |
| 872 | case WCD938X_HPH_NEW_INT_RDAC_OVERRIDE_CTL: |
| 873 | case WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R: |
| 874 | case WCD938X_HPH_NEW_INT_PA_MISC1: |
| 875 | case WCD938X_HPH_NEW_INT_PA_MISC2: |
| 876 | case WCD938X_HPH_NEW_INT_PA_RDAC_MISC: |
| 877 | case WCD938X_HPH_NEW_INT_HPH_TIMER1: |
| 878 | case WCD938X_HPH_NEW_INT_HPH_TIMER2: |
| 879 | case WCD938X_HPH_NEW_INT_HPH_TIMER3: |
| 880 | case WCD938X_HPH_NEW_INT_HPH_TIMER4: |
| 881 | case WCD938X_HPH_NEW_INT_PA_RDAC_MISC2: |
| 882 | case WCD938X_HPH_NEW_INT_PA_RDAC_MISC3: |
| 883 | case WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L_NEW: |
| 884 | case WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R_NEW: |
| 885 | case WCD938X_RX_NEW_INT_HPH_RDAC_BIAS_LOHIFI: |
| 886 | case WCD938X_RX_NEW_INT_HPH_RDAC_BIAS_ULP: |
| 887 | case WCD938X_RX_NEW_INT_HPH_RDAC_LDO_LP: |
| 888 | case WCD938X_MBHC_NEW_INT_MOISTURE_DET_DC_CTRL: |
| 889 | case WCD938X_MBHC_NEW_INT_MOISTURE_DET_POLLING_CTRL: |
| 890 | case WCD938X_MBHC_NEW_INT_MECH_DET_CURRENT: |
| 891 | case WCD938X_MBHC_NEW_INT_SPARE_2: |
| 892 | case WCD938X_EAR_INT_NEW_EAR_CHOPPER_CON: |
| 893 | case WCD938X_EAR_INT_NEW_CNP_VCM_CON1: |
| 894 | case WCD938X_EAR_INT_NEW_CNP_VCM_CON2: |
| 895 | case WCD938X_EAR_INT_NEW_EAR_DYNAMIC_BIAS: |
| 896 | case WCD938X_AUX_INT_EN_REG: |
| 897 | case WCD938X_AUX_INT_PA_CTRL: |
| 898 | case WCD938X_AUX_INT_SP_CTRL: |
| 899 | case WCD938X_AUX_INT_DAC_CTRL: |
| 900 | case WCD938X_AUX_INT_CLK_CTRL: |
| 901 | case WCD938X_AUX_INT_TEST_CTRL: |
| 902 | case WCD938X_AUX_INT_MISC: |
| 903 | case WCD938X_LDORXTX_INT_BIAS: |
| 904 | case WCD938X_LDORXTX_INT_STB_LOADS_DTEST: |
| 905 | case WCD938X_LDORXTX_INT_TEST0: |
| 906 | case WCD938X_LDORXTX_INT_STARTUP_TIMER: |
| 907 | case WCD938X_LDORXTX_INT_TEST1: |
| 908 | case WCD938X_SLEEP_INT_WATCHDOG_CTL_1: |
| 909 | case WCD938X_SLEEP_INT_WATCHDOG_CTL_2: |
| 910 | case WCD938X_DIE_CRACK_INT_DIE_CRK_DET_INT1: |
| 911 | case WCD938X_DIE_CRACK_INT_DIE_CRK_DET_INT2: |
| 912 | case WCD938X_TX_COM_NEW_INT_TXFE_DIVSTOP_L2: |
| 913 | case WCD938X_TX_COM_NEW_INT_TXFE_DIVSTOP_L1: |
| 914 | case WCD938X_TX_COM_NEW_INT_TXFE_DIVSTOP_L0: |
| 915 | case WCD938X_TX_COM_NEW_INT_TXFE_DIVSTOP_ULP1P2M: |
| 916 | case WCD938X_TX_COM_NEW_INT_TXFE_DIVSTOP_ULP0P6M: |
| 917 | case WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG1_L2L1: |
| 918 | case WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG1_L0: |
| 919 | case WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG1_ULP: |
| 920 | case WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2MAIN_L2L1: |
| 921 | case WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2MAIN_L0: |
| 922 | case WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2MAIN_ULP: |
| 923 | case WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2CASC_L2L1L0: |
| 924 | case WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2CASC_ULP: |
| 925 | case WCD938X_TX_COM_NEW_INT_TXADC_SCBIAS_L2L1: |
| 926 | case WCD938X_TX_COM_NEW_INT_TXADC_SCBIAS_L0ULP: |
| 927 | case WCD938X_TX_COM_NEW_INT_TXADC_INT_L2: |
| 928 | case WCD938X_TX_COM_NEW_INT_TXADC_INT_L1: |
| 929 | case WCD938X_TX_COM_NEW_INT_TXADC_INT_L0: |
| 930 | case WCD938X_TX_COM_NEW_INT_TXADC_INT_ULP: |
| 931 | case WCD938X_DIGITAL_PAGE_REGISTER: |
| 932 | case WCD938X_DIGITAL_SWR_TX_CLK_RATE: |
| 933 | case WCD938X_DIGITAL_CDC_RST_CTL: |
| 934 | case WCD938X_DIGITAL_TOP_CLK_CFG: |
| 935 | case WCD938X_DIGITAL_CDC_ANA_CLK_CTL: |
| 936 | case WCD938X_DIGITAL_CDC_DIG_CLK_CTL: |
| 937 | case WCD938X_DIGITAL_SWR_RST_EN: |
| 938 | case WCD938X_DIGITAL_CDC_PATH_MODE: |
| 939 | case WCD938X_DIGITAL_CDC_RX_RST: |
| 940 | case WCD938X_DIGITAL_CDC_RX0_CTL: |
| 941 | case WCD938X_DIGITAL_CDC_RX1_CTL: |
| 942 | case WCD938X_DIGITAL_CDC_RX2_CTL: |
| 943 | case WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1: |
| 944 | case WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3: |
| 945 | case WCD938X_DIGITAL_CDC_COMP_CTL_0: |
| 946 | case WCD938X_DIGITAL_CDC_ANA_TX_CLK_CTL: |
| 947 | case WCD938X_DIGITAL_CDC_HPH_DSM_A1_0: |
| 948 | case WCD938X_DIGITAL_CDC_HPH_DSM_A1_1: |
| 949 | case WCD938X_DIGITAL_CDC_HPH_DSM_A2_0: |
| 950 | case WCD938X_DIGITAL_CDC_HPH_DSM_A2_1: |
| 951 | case WCD938X_DIGITAL_CDC_HPH_DSM_A3_0: |
| 952 | case WCD938X_DIGITAL_CDC_HPH_DSM_A3_1: |
| 953 | case WCD938X_DIGITAL_CDC_HPH_DSM_A4_0: |
| 954 | case WCD938X_DIGITAL_CDC_HPH_DSM_A4_1: |
| 955 | case WCD938X_DIGITAL_CDC_HPH_DSM_A5_0: |
| 956 | case WCD938X_DIGITAL_CDC_HPH_DSM_A5_1: |
| 957 | case WCD938X_DIGITAL_CDC_HPH_DSM_A6_0: |
| 958 | case WCD938X_DIGITAL_CDC_HPH_DSM_A7_0: |
| 959 | case WCD938X_DIGITAL_CDC_HPH_DSM_C_0: |
| 960 | case WCD938X_DIGITAL_CDC_HPH_DSM_C_1: |
| 961 | case WCD938X_DIGITAL_CDC_HPH_DSM_C_2: |
| 962 | case WCD938X_DIGITAL_CDC_HPH_DSM_C_3: |
| 963 | case WCD938X_DIGITAL_CDC_HPH_DSM_R1: |
| 964 | case WCD938X_DIGITAL_CDC_HPH_DSM_R2: |
| 965 | case WCD938X_DIGITAL_CDC_HPH_DSM_R3: |
| 966 | case WCD938X_DIGITAL_CDC_HPH_DSM_R4: |
| 967 | case WCD938X_DIGITAL_CDC_HPH_DSM_R5: |
| 968 | case WCD938X_DIGITAL_CDC_HPH_DSM_R6: |
| 969 | case WCD938X_DIGITAL_CDC_HPH_DSM_R7: |
| 970 | case WCD938X_DIGITAL_CDC_AUX_DSM_A1_0: |
| 971 | case WCD938X_DIGITAL_CDC_AUX_DSM_A1_1: |
| 972 | case WCD938X_DIGITAL_CDC_AUX_DSM_A2_0: |
| 973 | case WCD938X_DIGITAL_CDC_AUX_DSM_A2_1: |
| 974 | case WCD938X_DIGITAL_CDC_AUX_DSM_A3_0: |
| 975 | case WCD938X_DIGITAL_CDC_AUX_DSM_A3_1: |
| 976 | case WCD938X_DIGITAL_CDC_AUX_DSM_A4_0: |
| 977 | case WCD938X_DIGITAL_CDC_AUX_DSM_A4_1: |
| 978 | case WCD938X_DIGITAL_CDC_AUX_DSM_A5_0: |
| 979 | case WCD938X_DIGITAL_CDC_AUX_DSM_A5_1: |
| 980 | case WCD938X_DIGITAL_CDC_AUX_DSM_A6_0: |
| 981 | case WCD938X_DIGITAL_CDC_AUX_DSM_A7_0: |
| 982 | case WCD938X_DIGITAL_CDC_AUX_DSM_C_0: |
| 983 | case WCD938X_DIGITAL_CDC_AUX_DSM_C_1: |
| 984 | case WCD938X_DIGITAL_CDC_AUX_DSM_C_2: |
| 985 | case WCD938X_DIGITAL_CDC_AUX_DSM_C_3: |
| 986 | case WCD938X_DIGITAL_CDC_AUX_DSM_R1: |
| 987 | case WCD938X_DIGITAL_CDC_AUX_DSM_R2: |
| 988 | case WCD938X_DIGITAL_CDC_AUX_DSM_R3: |
| 989 | case WCD938X_DIGITAL_CDC_AUX_DSM_R4: |
| 990 | case WCD938X_DIGITAL_CDC_AUX_DSM_R5: |
| 991 | case WCD938X_DIGITAL_CDC_AUX_DSM_R6: |
| 992 | case WCD938X_DIGITAL_CDC_AUX_DSM_R7: |
| 993 | case WCD938X_DIGITAL_CDC_HPH_GAIN_RX_0: |
| 994 | case WCD938X_DIGITAL_CDC_HPH_GAIN_RX_1: |
| 995 | case WCD938X_DIGITAL_CDC_HPH_GAIN_DSD_0: |
| 996 | case WCD938X_DIGITAL_CDC_HPH_GAIN_DSD_1: |
| 997 | case WCD938X_DIGITAL_CDC_HPH_GAIN_DSD_2: |
| 998 | case WCD938X_DIGITAL_CDC_AUX_GAIN_DSD_0: |
| 999 | case WCD938X_DIGITAL_CDC_AUX_GAIN_DSD_1: |
| 1000 | case WCD938X_DIGITAL_CDC_AUX_GAIN_DSD_2: |
| 1001 | case WCD938X_DIGITAL_CDC_HPH_GAIN_CTL: |
| 1002 | case WCD938X_DIGITAL_CDC_AUX_GAIN_CTL: |
| 1003 | case WCD938X_DIGITAL_CDC_EAR_PATH_CTL: |
| 1004 | case WCD938X_DIGITAL_CDC_SWR_CLH: |
| 1005 | case WCD938X_DIGITAL_SWR_CLH_BYP: |
| 1006 | case WCD938X_DIGITAL_CDC_TX0_CTL: |
| 1007 | case WCD938X_DIGITAL_CDC_TX1_CTL: |
| 1008 | case WCD938X_DIGITAL_CDC_TX2_CTL: |
| 1009 | case WCD938X_DIGITAL_CDC_TX_RST: |
| 1010 | case WCD938X_DIGITAL_CDC_REQ_CTL: |
| 1011 | case WCD938X_DIGITAL_CDC_RST: |
| 1012 | case WCD938X_DIGITAL_CDC_AMIC_CTL: |
| 1013 | case WCD938X_DIGITAL_CDC_DMIC_CTL: |
| 1014 | case WCD938X_DIGITAL_CDC_DMIC1_CTL: |
| 1015 | case WCD938X_DIGITAL_CDC_DMIC2_CTL: |
| 1016 | case WCD938X_DIGITAL_CDC_DMIC3_CTL: |
| 1017 | case WCD938X_DIGITAL_CDC_DMIC4_CTL: |
| 1018 | case WCD938X_DIGITAL_EFUSE_PRG_CTL: |
| 1019 | case WCD938X_DIGITAL_EFUSE_CTL: |
| 1020 | case WCD938X_DIGITAL_CDC_DMIC_RATE_1_2: |
| 1021 | case WCD938X_DIGITAL_CDC_DMIC_RATE_3_4: |
| 1022 | case WCD938X_DIGITAL_PDM_WD_CTL0: |
| 1023 | case WCD938X_DIGITAL_PDM_WD_CTL1: |
| 1024 | case WCD938X_DIGITAL_PDM_WD_CTL2: |
| 1025 | case WCD938X_DIGITAL_INTR_MODE: |
| 1026 | case WCD938X_DIGITAL_INTR_MASK_0: |
| 1027 | case WCD938X_DIGITAL_INTR_MASK_1: |
| 1028 | case WCD938X_DIGITAL_INTR_MASK_2: |
| 1029 | case WCD938X_DIGITAL_INTR_CLEAR_0: |
| 1030 | case WCD938X_DIGITAL_INTR_CLEAR_1: |
| 1031 | case WCD938X_DIGITAL_INTR_CLEAR_2: |
| 1032 | case WCD938X_DIGITAL_INTR_LEVEL_0: |
| 1033 | case WCD938X_DIGITAL_INTR_LEVEL_1: |
| 1034 | case WCD938X_DIGITAL_INTR_LEVEL_2: |
| 1035 | case WCD938X_DIGITAL_INTR_SET_0: |
| 1036 | case WCD938X_DIGITAL_INTR_SET_1: |
| 1037 | case WCD938X_DIGITAL_INTR_SET_2: |
| 1038 | case WCD938X_DIGITAL_INTR_TEST_0: |
| 1039 | case WCD938X_DIGITAL_INTR_TEST_1: |
| 1040 | case WCD938X_DIGITAL_INTR_TEST_2: |
| 1041 | case WCD938X_DIGITAL_TX_MODE_DBG_EN: |
| 1042 | case WCD938X_DIGITAL_TX_MODE_DBG_0_1: |
| 1043 | case WCD938X_DIGITAL_TX_MODE_DBG_2_3: |
| 1044 | case WCD938X_DIGITAL_LB_IN_SEL_CTL: |
| 1045 | case WCD938X_DIGITAL_LOOP_BACK_MODE: |
| 1046 | case WCD938X_DIGITAL_SWR_DAC_TEST: |
| 1047 | case WCD938X_DIGITAL_SWR_HM_TEST_RX_0: |
| 1048 | case WCD938X_DIGITAL_SWR_HM_TEST_TX_0: |
| 1049 | case WCD938X_DIGITAL_SWR_HM_TEST_RX_1: |
| 1050 | case WCD938X_DIGITAL_SWR_HM_TEST_TX_1: |
| 1051 | case WCD938X_DIGITAL_SWR_HM_TEST_TX_2: |
| 1052 | case WCD938X_DIGITAL_PAD_CTL_SWR_0: |
| 1053 | case WCD938X_DIGITAL_PAD_CTL_SWR_1: |
| 1054 | case WCD938X_DIGITAL_I2C_CTL: |
| 1055 | case WCD938X_DIGITAL_CDC_TX_TANGGU_SW_MODE: |
| 1056 | case WCD938X_DIGITAL_EFUSE_TEST_CTL_0: |
| 1057 | case WCD938X_DIGITAL_EFUSE_TEST_CTL_1: |
| 1058 | case WCD938X_DIGITAL_PAD_CTL_PDM_RX0: |
| 1059 | case WCD938X_DIGITAL_PAD_CTL_PDM_RX1: |
| 1060 | case WCD938X_DIGITAL_PAD_CTL_PDM_TX0: |
| 1061 | case WCD938X_DIGITAL_PAD_CTL_PDM_TX1: |
| 1062 | case WCD938X_DIGITAL_PAD_CTL_PDM_TX2: |
| 1063 | case WCD938X_DIGITAL_PAD_INP_DIS_0: |
| 1064 | case WCD938X_DIGITAL_PAD_INP_DIS_1: |
| 1065 | case WCD938X_DIGITAL_DRIVE_STRENGTH_0: |
| 1066 | case WCD938X_DIGITAL_DRIVE_STRENGTH_1: |
| 1067 | case WCD938X_DIGITAL_DRIVE_STRENGTH_2: |
| 1068 | case WCD938X_DIGITAL_RX_DATA_EDGE_CTL: |
| 1069 | case WCD938X_DIGITAL_TX_DATA_EDGE_CTL: |
| 1070 | case WCD938X_DIGITAL_GPIO_MODE: |
| 1071 | case WCD938X_DIGITAL_PIN_CTL_OE: |
| 1072 | case WCD938X_DIGITAL_PIN_CTL_DATA_0: |
| 1073 | case WCD938X_DIGITAL_PIN_CTL_DATA_1: |
| 1074 | case WCD938X_DIGITAL_DIG_DEBUG_CTL: |
| 1075 | case WCD938X_DIGITAL_DIG_DEBUG_EN: |
| 1076 | case WCD938X_DIGITAL_ANA_CSR_DBG_ADD: |
| 1077 | case WCD938X_DIGITAL_ANA_CSR_DBG_CTL: |
| 1078 | case WCD938X_DIGITAL_SSP_DBG: |
| 1079 | case WCD938X_DIGITAL_SPARE_0: |
| 1080 | case WCD938X_DIGITAL_SPARE_1: |
| 1081 | case WCD938X_DIGITAL_SPARE_2: |
| 1082 | case WCD938X_DIGITAL_TX_REQ_FB_CTL_0: |
| 1083 | case WCD938X_DIGITAL_TX_REQ_FB_CTL_1: |
| 1084 | case WCD938X_DIGITAL_TX_REQ_FB_CTL_2: |
| 1085 | case WCD938X_DIGITAL_TX_REQ_FB_CTL_3: |
| 1086 | case WCD938X_DIGITAL_TX_REQ_FB_CTL_4: |
| 1087 | case WCD938X_DIGITAL_DEM_BYPASS_DATA0: |
| 1088 | case WCD938X_DIGITAL_DEM_BYPASS_DATA1: |
| 1089 | case WCD938X_DIGITAL_DEM_BYPASS_DATA2: |
| 1090 | case WCD938X_DIGITAL_DEM_BYPASS_DATA3: |
| 1091 | return true; |
| 1092 | } |
| 1093 | |
| 1094 | return false; |
| 1095 | } |
| 1096 | |
| 1097 | static bool wcd938x_readonly_register(struct device *dev, unsigned int reg) |
| 1098 | { |
| 1099 | switch (reg) { |
| 1100 | case WCD938X_ANA_MBHC_RESULT_1: |
| 1101 | case WCD938X_ANA_MBHC_RESULT_2: |
| 1102 | case WCD938X_ANA_MBHC_RESULT_3: |
| 1103 | case WCD938X_MBHC_MOISTURE_DET_FSM_STATUS: |
| 1104 | case WCD938X_TX_1_2_SAR2_ERR: |
| 1105 | case WCD938X_TX_1_2_SAR1_ERR: |
| 1106 | case WCD938X_TX_3_4_SAR4_ERR: |
| 1107 | case WCD938X_TX_3_4_SAR3_ERR: |
| 1108 | case WCD938X_HPH_L_STATUS: |
| 1109 | case WCD938X_HPH_R_STATUS: |
| 1110 | case WCD938X_HPH_SURGE_HPHLR_SURGE_STATUS: |
| 1111 | case WCD938X_EAR_STATUS_REG_1: |
| 1112 | case WCD938X_EAR_STATUS_REG_2: |
| 1113 | case WCD938X_MBHC_NEW_FSM_STATUS: |
| 1114 | case WCD938X_MBHC_NEW_ADC_RESULT: |
| 1115 | case WCD938X_DIE_CRACK_DIE_CRK_DET_OUT: |
| 1116 | case WCD938X_AUX_INT_STATUS_REG: |
| 1117 | case WCD938X_LDORXTX_INT_STATUS: |
| 1118 | case WCD938X_DIGITAL_CHIP_ID0: |
| 1119 | case WCD938X_DIGITAL_CHIP_ID1: |
| 1120 | case WCD938X_DIGITAL_CHIP_ID2: |
| 1121 | case WCD938X_DIGITAL_CHIP_ID3: |
| 1122 | case WCD938X_DIGITAL_INTR_STATUS_0: |
| 1123 | case WCD938X_DIGITAL_INTR_STATUS_1: |
| 1124 | case WCD938X_DIGITAL_INTR_STATUS_2: |
| 1125 | case WCD938X_DIGITAL_SWR_HM_TEST_0: |
| 1126 | case WCD938X_DIGITAL_SWR_HM_TEST_1: |
| 1127 | case WCD938X_DIGITAL_EFUSE_T_DATA_0: |
| 1128 | case WCD938X_DIGITAL_EFUSE_T_DATA_1: |
| 1129 | case WCD938X_DIGITAL_PIN_STATUS_0: |
| 1130 | case WCD938X_DIGITAL_PIN_STATUS_1: |
| 1131 | case WCD938X_DIGITAL_MODE_STATUS_0: |
| 1132 | case WCD938X_DIGITAL_MODE_STATUS_1: |
| 1133 | case WCD938X_DIGITAL_EFUSE_REG_0: |
| 1134 | case WCD938X_DIGITAL_EFUSE_REG_1: |
| 1135 | case WCD938X_DIGITAL_EFUSE_REG_2: |
| 1136 | case WCD938X_DIGITAL_EFUSE_REG_3: |
| 1137 | case WCD938X_DIGITAL_EFUSE_REG_4: |
| 1138 | case WCD938X_DIGITAL_EFUSE_REG_5: |
| 1139 | case WCD938X_DIGITAL_EFUSE_REG_6: |
| 1140 | case WCD938X_DIGITAL_EFUSE_REG_7: |
| 1141 | case WCD938X_DIGITAL_EFUSE_REG_8: |
| 1142 | case WCD938X_DIGITAL_EFUSE_REG_9: |
| 1143 | case WCD938X_DIGITAL_EFUSE_REG_10: |
| 1144 | case WCD938X_DIGITAL_EFUSE_REG_11: |
| 1145 | case WCD938X_DIGITAL_EFUSE_REG_12: |
| 1146 | case WCD938X_DIGITAL_EFUSE_REG_13: |
| 1147 | case WCD938X_DIGITAL_EFUSE_REG_14: |
| 1148 | case WCD938X_DIGITAL_EFUSE_REG_15: |
| 1149 | case WCD938X_DIGITAL_EFUSE_REG_16: |
| 1150 | case WCD938X_DIGITAL_EFUSE_REG_17: |
| 1151 | case WCD938X_DIGITAL_EFUSE_REG_18: |
| 1152 | case WCD938X_DIGITAL_EFUSE_REG_19: |
| 1153 | case WCD938X_DIGITAL_EFUSE_REG_20: |
| 1154 | case WCD938X_DIGITAL_EFUSE_REG_21: |
| 1155 | case WCD938X_DIGITAL_EFUSE_REG_22: |
| 1156 | case WCD938X_DIGITAL_EFUSE_REG_23: |
| 1157 | case WCD938X_DIGITAL_EFUSE_REG_24: |
| 1158 | case WCD938X_DIGITAL_EFUSE_REG_25: |
| 1159 | case WCD938X_DIGITAL_EFUSE_REG_26: |
| 1160 | case WCD938X_DIGITAL_EFUSE_REG_27: |
| 1161 | case WCD938X_DIGITAL_EFUSE_REG_28: |
| 1162 | case WCD938X_DIGITAL_EFUSE_REG_29: |
| 1163 | case WCD938X_DIGITAL_EFUSE_REG_30: |
| 1164 | case WCD938X_DIGITAL_EFUSE_REG_31: |
| 1165 | return true; |
| 1166 | } |
| 1167 | return false; |
| 1168 | } |
| 1169 | |
| 1170 | static bool wcd938x_readable_register(struct device *dev, unsigned int reg) |
| 1171 | { |
| 1172 | bool ret; |
| 1173 | |
| 1174 | ret = wcd938x_readonly_register(dev, reg); |
| 1175 | if (!ret) |
| 1176 | return wcd938x_rdwr_register(dev, reg); |
| 1177 | |
| 1178 | return ret; |
| 1179 | } |
| 1180 | |
| 1181 | static bool wcd938x_writeable_register(struct device *dev, unsigned int reg) |
| 1182 | { |
| 1183 | return wcd938x_rdwr_register(dev, reg); |
| 1184 | } |
| 1185 | |
| 1186 | static bool wcd938x_volatile_register(struct device *dev, unsigned int reg) |
| 1187 | { |
| 1188 | if (reg <= WCD938X_BASE_ADDRESS) |
Yang Li | 83bd5c5 | 2021-06-16 10:45:35 +0800 | [diff] [blame] | 1189 | return false; |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 1190 | |
| 1191 | if (reg == WCD938X_DIGITAL_SWR_TX_CLK_RATE) |
| 1192 | return true; |
| 1193 | |
| 1194 | if (wcd938x_readonly_register(dev, reg)) |
| 1195 | return true; |
| 1196 | |
| 1197 | return false; |
| 1198 | } |
| 1199 | |
Srinivas Kandagatla | b90d939 | 2021-06-15 14:28:29 +0100 | [diff] [blame] | 1200 | static struct regmap_config wcd938x_regmap_config = { |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 1201 | .name = "wcd938x_csr", |
| 1202 | .reg_bits = 32, |
| 1203 | .val_bits = 8, |
| 1204 | .cache_type = REGCACHE_RBTREE, |
| 1205 | .reg_defaults = wcd938x_defaults, |
| 1206 | .num_reg_defaults = ARRAY_SIZE(wcd938x_defaults), |
| 1207 | .max_register = WCD938X_MAX_REGISTER, |
| 1208 | .readable_reg = wcd938x_readable_register, |
| 1209 | .writeable_reg = wcd938x_writeable_register, |
| 1210 | .volatile_reg = wcd938x_volatile_register, |
| 1211 | .can_multi_write = true, |
| 1212 | }; |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 1213 | |
| 1214 | static const struct regmap_irq wcd938x_irqs[WCD938X_NUM_IRQS] = { |
| 1215 | REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_BUTTON_PRESS_DET, 0, 0x01), |
| 1216 | REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_BUTTON_RELEASE_DET, 0, 0x02), |
| 1217 | REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_ELECT_INS_REM_DET, 0, 0x04), |
| 1218 | REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_ELECT_INS_REM_LEG_DET, 0, 0x08), |
| 1219 | REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_SW_DET, 0, 0x10), |
| 1220 | REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_OCP_INT, 0, 0x20), |
| 1221 | REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_CNP_INT, 0, 0x40), |
| 1222 | REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_OCP_INT, 0, 0x80), |
| 1223 | REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_CNP_INT, 1, 0x01), |
| 1224 | REGMAP_IRQ_REG(WCD938X_IRQ_EAR_CNP_INT, 1, 0x02), |
| 1225 | REGMAP_IRQ_REG(WCD938X_IRQ_EAR_SCD_INT, 1, 0x04), |
| 1226 | REGMAP_IRQ_REG(WCD938X_IRQ_AUX_CNP_INT, 1, 0x08), |
| 1227 | REGMAP_IRQ_REG(WCD938X_IRQ_AUX_SCD_INT, 1, 0x10), |
| 1228 | REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_PDM_WD_INT, 1, 0x20), |
| 1229 | REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_PDM_WD_INT, 1, 0x40), |
| 1230 | REGMAP_IRQ_REG(WCD938X_IRQ_AUX_PDM_WD_INT, 1, 0x80), |
| 1231 | REGMAP_IRQ_REG(WCD938X_IRQ_LDORT_SCD_INT, 2, 0x01), |
| 1232 | REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_MOISTURE_INT, 2, 0x02), |
| 1233 | REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_SURGE_DET_INT, 2, 0x04), |
| 1234 | REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_SURGE_DET_INT, 2, 0x08), |
| 1235 | }; |
| 1236 | |
| 1237 | static struct regmap_irq_chip wcd938x_regmap_irq_chip = { |
| 1238 | .name = "wcd938x", |
| 1239 | .irqs = wcd938x_irqs, |
| 1240 | .num_irqs = ARRAY_SIZE(wcd938x_irqs), |
| 1241 | .num_regs = 3, |
| 1242 | .status_base = WCD938X_DIGITAL_INTR_STATUS_0, |
| 1243 | .mask_base = WCD938X_DIGITAL_INTR_MASK_0, |
| 1244 | .type_base = WCD938X_DIGITAL_INTR_LEVEL_0, |
| 1245 | .ack_base = WCD938X_DIGITAL_INTR_CLEAR_0, |
| 1246 | .use_ack = 1, |
| 1247 | .runtime_pm = true, |
| 1248 | .irq_drv_data = NULL, |
| 1249 | }; |
| 1250 | |
Srinivas Kandagatla | d5add08 | 2021-06-09 10:09:42 +0100 | [diff] [blame] | 1251 | static int wcd938x_get_clk_rate(int mode) |
| 1252 | { |
| 1253 | int rate; |
| 1254 | |
| 1255 | switch (mode) { |
| 1256 | case ADC_MODE_ULP2: |
| 1257 | rate = SWR_CLK_RATE_0P6MHZ; |
| 1258 | break; |
| 1259 | case ADC_MODE_ULP1: |
| 1260 | rate = SWR_CLK_RATE_1P2MHZ; |
| 1261 | break; |
| 1262 | case ADC_MODE_LP: |
| 1263 | rate = SWR_CLK_RATE_4P8MHZ; |
| 1264 | break; |
| 1265 | case ADC_MODE_NORMAL: |
| 1266 | case ADC_MODE_LO_HIF: |
| 1267 | case ADC_MODE_HIFI: |
| 1268 | case ADC_MODE_INVALID: |
| 1269 | default: |
| 1270 | rate = SWR_CLK_RATE_9P6MHZ; |
| 1271 | break; |
| 1272 | } |
| 1273 | |
| 1274 | return rate; |
| 1275 | } |
| 1276 | |
| 1277 | static int wcd938x_set_swr_clk_rate(struct snd_soc_component *component, int rate, int bank) |
| 1278 | { |
| 1279 | u8 mask = (bank ? 0xF0 : 0x0F); |
| 1280 | u8 val = 0; |
| 1281 | |
| 1282 | switch (rate) { |
| 1283 | case SWR_CLK_RATE_0P6MHZ: |
| 1284 | val = (bank ? 0x60 : 0x06); |
| 1285 | break; |
| 1286 | case SWR_CLK_RATE_1P2MHZ: |
| 1287 | val = (bank ? 0x50 : 0x05); |
| 1288 | break; |
| 1289 | case SWR_CLK_RATE_2P4MHZ: |
| 1290 | val = (bank ? 0x30 : 0x03); |
| 1291 | break; |
| 1292 | case SWR_CLK_RATE_4P8MHZ: |
| 1293 | val = (bank ? 0x10 : 0x01); |
| 1294 | break; |
| 1295 | case SWR_CLK_RATE_9P6MHZ: |
| 1296 | default: |
| 1297 | val = 0x00; |
| 1298 | break; |
| 1299 | } |
| 1300 | snd_soc_component_update_bits(component, WCD938X_DIGITAL_SWR_TX_CLK_RATE, |
| 1301 | mask, val); |
| 1302 | |
| 1303 | return 0; |
| 1304 | } |
| 1305 | |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 1306 | static int wcd938x_io_init(struct wcd938x_priv *wcd938x) |
| 1307 | { |
| 1308 | struct regmap *rm = wcd938x->regmap; |
| 1309 | |
| 1310 | regmap_update_bits(rm, WCD938X_SLEEP_CTL, 0x0E, 0x0E); |
| 1311 | regmap_update_bits(rm, WCD938X_SLEEP_CTL, 0x80, 0x80); |
| 1312 | /* 1 msec delay as per HW requirement */ |
| 1313 | usleep_range(1000, 1010); |
| 1314 | regmap_update_bits(rm, WCD938X_SLEEP_CTL, 0x40, 0x40); |
| 1315 | /* 1 msec delay as per HW requirement */ |
| 1316 | usleep_range(1000, 1010); |
| 1317 | regmap_update_bits(rm, WCD938X_LDORXTX_CONFIG, 0x10, 0x00); |
| 1318 | regmap_update_bits(rm, WCD938X_BIAS_VBG_FINE_ADJ, |
| 1319 | 0xF0, 0x80); |
| 1320 | regmap_update_bits(rm, WCD938X_ANA_BIAS, 0x80, 0x80); |
| 1321 | regmap_update_bits(rm, WCD938X_ANA_BIAS, 0x40, 0x40); |
| 1322 | /* 10 msec delay as per HW requirement */ |
| 1323 | usleep_range(10000, 10010); |
| 1324 | |
| 1325 | regmap_update_bits(rm, WCD938X_ANA_BIAS, 0x40, 0x00); |
| 1326 | regmap_update_bits(rm, WCD938X_HPH_NEW_INT_RDAC_GAIN_CTL, |
| 1327 | 0xF0, 0x00); |
| 1328 | regmap_update_bits(rm, WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L_NEW, |
| 1329 | 0x1F, 0x15); |
| 1330 | regmap_update_bits(rm, WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R_NEW, |
| 1331 | 0x1F, 0x15); |
| 1332 | regmap_update_bits(rm, WCD938X_HPH_REFBUFF_UHQA_CTL, |
| 1333 | 0xC0, 0x80); |
| 1334 | regmap_update_bits(rm, WCD938X_DIGITAL_CDC_DMIC_CTL, |
| 1335 | 0x02, 0x02); |
| 1336 | |
| 1337 | regmap_update_bits(rm, WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2CASC_ULP, |
| 1338 | 0xFF, 0x14); |
| 1339 | regmap_update_bits(rm, WCD938X_TX_COM_NEW_INT_TXFE_ICTRL_STG2MAIN_ULP, |
| 1340 | 0x1F, 0x08); |
| 1341 | |
| 1342 | regmap_update_bits(rm, WCD938X_DIGITAL_TX_REQ_FB_CTL_0, 0xFF, 0x55); |
| 1343 | regmap_update_bits(rm, WCD938X_DIGITAL_TX_REQ_FB_CTL_1, 0xFF, 0x44); |
| 1344 | regmap_update_bits(rm, WCD938X_DIGITAL_TX_REQ_FB_CTL_2, 0xFF, 0x11); |
| 1345 | regmap_update_bits(rm, WCD938X_DIGITAL_TX_REQ_FB_CTL_3, 0xFF, 0x00); |
| 1346 | regmap_update_bits(rm, WCD938X_DIGITAL_TX_REQ_FB_CTL_4, 0xFF, 0x00); |
| 1347 | |
| 1348 | /* Set Noise Filter Resistor value */ |
| 1349 | regmap_update_bits(rm, WCD938X_MICB1_TEST_CTL_1, 0xE0, 0xE0); |
| 1350 | regmap_update_bits(rm, WCD938X_MICB2_TEST_CTL_1, 0xE0, 0xE0); |
| 1351 | regmap_update_bits(rm, WCD938X_MICB3_TEST_CTL_1, 0xE0, 0xE0); |
| 1352 | regmap_update_bits(rm, WCD938X_MICB4_TEST_CTL_1, 0xE0, 0xE0); |
| 1353 | |
| 1354 | regmap_update_bits(rm, WCD938X_TX_3_4_TEST_BLK_EN2, 0x01, 0x00); |
| 1355 | regmap_update_bits(rm, WCD938X_HPH_SURGE_HPHLR_SURGE_EN, 0xC0, 0xC0); |
| 1356 | |
| 1357 | return 0; |
| 1358 | |
| 1359 | } |
| 1360 | |
Srinivas Kandagatla | e8ba1e0 | 2021-06-09 10:09:40 +0100 | [diff] [blame] | 1361 | static int wcd938x_sdw_connect_port(struct wcd938x_sdw_ch_info *ch_info, |
| 1362 | struct sdw_port_config *port_config, |
Srinivas Kandagatla | e8ba1e0 | 2021-06-09 10:09:40 +0100 | [diff] [blame] | 1363 | u8 enable) |
| 1364 | { |
| 1365 | u8 ch_mask, port_num; |
| 1366 | |
| 1367 | port_num = ch_info->port_num; |
| 1368 | ch_mask = ch_info->ch_mask; |
| 1369 | |
| 1370 | port_config->num = port_num; |
| 1371 | |
| 1372 | if (enable) |
| 1373 | port_config->ch_mask |= ch_mask; |
| 1374 | else |
| 1375 | port_config->ch_mask &= ~ch_mask; |
| 1376 | |
| 1377 | return 0; |
| 1378 | } |
| 1379 | |
| 1380 | static int wcd938x_connect_port(struct wcd938x_sdw_priv *wcd, u8 ch_id, u8 enable) |
| 1381 | { |
Srinivas Kandagatla | d9dbe1f | 2021-07-16 11:56:12 +0100 | [diff] [blame^] | 1382 | u8 port_num; |
Srinivas Kandagatla | e8ba1e0 | 2021-06-09 10:09:40 +0100 | [diff] [blame] | 1383 | |
| 1384 | port_num = wcd->ch_info[ch_id].port_num; |
Srinivas Kandagatla | e8ba1e0 | 2021-06-09 10:09:40 +0100 | [diff] [blame] | 1385 | |
| 1386 | return wcd938x_sdw_connect_port(&wcd->ch_info[ch_id], |
| 1387 | &wcd->port_config[port_num], |
Srinivas Kandagatla | e8ba1e0 | 2021-06-09 10:09:40 +0100 | [diff] [blame] | 1388 | enable); |
| 1389 | } |
| 1390 | |
Srinivas Kandagatla | 8da9db0 | 2021-06-09 10:09:41 +0100 | [diff] [blame] | 1391 | static int wcd938x_codec_enable_rxclk(struct snd_soc_dapm_widget *w, |
| 1392 | struct snd_kcontrol *kcontrol, |
| 1393 | int event) |
| 1394 | { |
| 1395 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 1396 | |
| 1397 | switch (event) { |
| 1398 | case SND_SOC_DAPM_PRE_PMU: |
| 1399 | snd_soc_component_write_field(component, WCD938X_DIGITAL_CDC_ANA_CLK_CTL, |
| 1400 | WCD938X_ANA_RX_CLK_EN_MASK, 1); |
| 1401 | snd_soc_component_write_field(component, WCD938X_ANA_RX_SUPPLIES, |
| 1402 | WCD938X_RX_BIAS_EN_MASK, 1); |
| 1403 | snd_soc_component_write_field(component, WCD938X_DIGITAL_CDC_RX0_CTL, |
| 1404 | WCD938X_DEM_DITHER_ENABLE_MASK, 0); |
| 1405 | snd_soc_component_write_field(component, WCD938X_DIGITAL_CDC_RX1_CTL, |
| 1406 | WCD938X_DEM_DITHER_ENABLE_MASK, 0); |
| 1407 | snd_soc_component_write_field(component, WCD938X_DIGITAL_CDC_RX2_CTL, |
| 1408 | WCD938X_DEM_DITHER_ENABLE_MASK, 0); |
| 1409 | snd_soc_component_write_field(component, WCD938X_DIGITAL_CDC_ANA_CLK_CTL, |
| 1410 | WCD938X_ANA_RX_DIV2_CLK_EN_MASK, 1); |
| 1411 | snd_soc_component_write_field(component, WCD938X_AUX_AUXPA, |
| 1412 | WCD938X_AUXPA_CLK_EN_MASK, 1); |
| 1413 | break; |
| 1414 | case SND_SOC_DAPM_POST_PMD: |
| 1415 | snd_soc_component_write_field(component, WCD938X_ANA_RX_SUPPLIES, |
| 1416 | WCD938X_VNEG_EN_MASK, 0); |
| 1417 | snd_soc_component_write_field(component, WCD938X_ANA_RX_SUPPLIES, |
| 1418 | WCD938X_VPOS_EN_MASK, 0); |
| 1419 | snd_soc_component_write_field(component, WCD938X_ANA_RX_SUPPLIES, |
| 1420 | WCD938X_RX_BIAS_EN_MASK, 0); |
| 1421 | snd_soc_component_write_field(component, WCD938X_DIGITAL_CDC_ANA_CLK_CTL, |
| 1422 | WCD938X_ANA_RX_DIV2_CLK_EN_MASK, 0); |
| 1423 | snd_soc_component_write_field(component, WCD938X_DIGITAL_CDC_ANA_CLK_CTL, |
| 1424 | WCD938X_ANA_RX_CLK_EN_MASK, 0); |
| 1425 | break; |
| 1426 | } |
| 1427 | return 0; |
| 1428 | } |
| 1429 | |
| 1430 | static int wcd938x_codec_hphl_dac_event(struct snd_soc_dapm_widget *w, |
| 1431 | struct snd_kcontrol *kcontrol, |
| 1432 | int event) |
| 1433 | { |
| 1434 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 1435 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 1436 | |
| 1437 | switch (event) { |
| 1438 | case SND_SOC_DAPM_PRE_PMU: |
| 1439 | snd_soc_component_write_field(component, |
| 1440 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 1441 | WCD938X_RXD0_CLK_EN_MASK, 0x01); |
| 1442 | snd_soc_component_write_field(component, |
| 1443 | WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, |
| 1444 | WCD938X_HPHL_RX_EN_MASK, 1); |
| 1445 | snd_soc_component_write_field(component, |
| 1446 | WCD938X_HPH_RDAC_CLK_CTL1, |
| 1447 | WCD938X_CHOP_CLK_EN_MASK, 0); |
| 1448 | break; |
| 1449 | case SND_SOC_DAPM_POST_PMU: |
| 1450 | snd_soc_component_write_field(component, |
| 1451 | WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L, |
| 1452 | WCD938X_HPH_RES_DIV_MASK, 0x02); |
| 1453 | if (wcd938x->comp1_enable) { |
| 1454 | snd_soc_component_write_field(component, |
| 1455 | WCD938X_DIGITAL_CDC_COMP_CTL_0, |
| 1456 | WCD938X_HPHL_COMP_EN_MASK, 1); |
| 1457 | /* 5msec compander delay as per HW requirement */ |
| 1458 | if (!wcd938x->comp2_enable || (snd_soc_component_read(component, |
| 1459 | WCD938X_DIGITAL_CDC_COMP_CTL_0) & 0x01)) |
| 1460 | usleep_range(5000, 5010); |
| 1461 | snd_soc_component_write_field(component, WCD938X_HPH_NEW_INT_HPH_TIMER1, |
| 1462 | WCD938X_AUTOCHOP_TIMER_EN, 0); |
| 1463 | } else { |
| 1464 | snd_soc_component_write_field(component, |
| 1465 | WCD938X_DIGITAL_CDC_COMP_CTL_0, |
| 1466 | WCD938X_HPHL_COMP_EN_MASK, 0); |
| 1467 | snd_soc_component_write_field(component, |
| 1468 | WCD938X_HPH_L_EN, |
| 1469 | WCD938X_GAIN_SRC_SEL_MASK, |
| 1470 | WCD938X_GAIN_SRC_SEL_REGISTER); |
| 1471 | |
| 1472 | } |
| 1473 | break; |
| 1474 | case SND_SOC_DAPM_POST_PMD: |
| 1475 | snd_soc_component_write_field(component, |
| 1476 | WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R, |
| 1477 | WCD938X_HPH_RES_DIV_MASK, 0x1); |
| 1478 | break; |
| 1479 | } |
| 1480 | |
| 1481 | return 0; |
| 1482 | } |
| 1483 | |
| 1484 | static int wcd938x_codec_hphr_dac_event(struct snd_soc_dapm_widget *w, |
| 1485 | struct snd_kcontrol *kcontrol, |
| 1486 | int event) |
| 1487 | { |
| 1488 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 1489 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 1490 | |
| 1491 | switch (event) { |
| 1492 | case SND_SOC_DAPM_PRE_PMU: |
| 1493 | snd_soc_component_write_field(component, |
| 1494 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 1495 | WCD938X_RXD1_CLK_EN_MASK, 1); |
| 1496 | snd_soc_component_write_field(component, |
| 1497 | WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, |
| 1498 | WCD938X_HPHR_RX_EN_MASK, 1); |
| 1499 | snd_soc_component_write_field(component, |
| 1500 | WCD938X_HPH_RDAC_CLK_CTL1, |
| 1501 | WCD938X_CHOP_CLK_EN_MASK, 0); |
| 1502 | break; |
| 1503 | case SND_SOC_DAPM_POST_PMU: |
| 1504 | snd_soc_component_write_field(component, |
| 1505 | WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R, |
| 1506 | WCD938X_HPH_RES_DIV_MASK, 0x02); |
| 1507 | if (wcd938x->comp2_enable) { |
| 1508 | snd_soc_component_write_field(component, |
| 1509 | WCD938X_DIGITAL_CDC_COMP_CTL_0, |
| 1510 | WCD938X_HPHR_COMP_EN_MASK, 1); |
| 1511 | /* 5msec compander delay as per HW requirement */ |
| 1512 | if (!wcd938x->comp1_enable || |
| 1513 | (snd_soc_component_read(component, |
| 1514 | WCD938X_DIGITAL_CDC_COMP_CTL_0) & 0x02)) |
| 1515 | usleep_range(5000, 5010); |
| 1516 | snd_soc_component_write_field(component, WCD938X_HPH_NEW_INT_HPH_TIMER1, |
| 1517 | WCD938X_AUTOCHOP_TIMER_EN, 0); |
| 1518 | } else { |
| 1519 | snd_soc_component_write_field(component, |
| 1520 | WCD938X_DIGITAL_CDC_COMP_CTL_0, |
| 1521 | WCD938X_HPHR_COMP_EN_MASK, 0); |
| 1522 | snd_soc_component_write_field(component, |
| 1523 | WCD938X_HPH_R_EN, |
| 1524 | WCD938X_GAIN_SRC_SEL_MASK, |
| 1525 | WCD938X_GAIN_SRC_SEL_REGISTER); |
| 1526 | } |
| 1527 | break; |
| 1528 | case SND_SOC_DAPM_POST_PMD: |
| 1529 | snd_soc_component_write_field(component, |
| 1530 | WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R, |
| 1531 | WCD938X_HPH_RES_DIV_MASK, 0x01); |
| 1532 | break; |
| 1533 | } |
| 1534 | |
| 1535 | return 0; |
| 1536 | } |
| 1537 | |
| 1538 | static int wcd938x_codec_ear_dac_event(struct snd_soc_dapm_widget *w, |
| 1539 | struct snd_kcontrol *kcontrol, |
| 1540 | int event) |
| 1541 | { |
| 1542 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 1543 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 1544 | |
| 1545 | switch (event) { |
| 1546 | case SND_SOC_DAPM_PRE_PMU: |
| 1547 | wcd938x->ear_rx_path = |
| 1548 | snd_soc_component_read( |
| 1549 | component, WCD938X_DIGITAL_CDC_EAR_PATH_CTL); |
| 1550 | if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) { |
| 1551 | snd_soc_component_write_field(component, |
| 1552 | WCD938X_EAR_EAR_DAC_CON, |
| 1553 | WCD938X_DAC_SAMPLE_EDGE_SEL_MASK, 0); |
| 1554 | snd_soc_component_write_field(component, |
| 1555 | WCD938X_DIGITAL_CDC_AUX_GAIN_CTL, |
| 1556 | WCD938X_AUX_EN_MASK, 1); |
| 1557 | snd_soc_component_write_field(component, |
| 1558 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 1559 | WCD938X_RXD2_CLK_EN_MASK, 1); |
| 1560 | snd_soc_component_write_field(component, |
| 1561 | WCD938X_ANA_EAR_COMPANDER_CTL, |
| 1562 | WCD938X_GAIN_OVRD_REG_MASK, 1); |
| 1563 | } else { |
| 1564 | snd_soc_component_write_field(component, |
| 1565 | WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, |
| 1566 | WCD938X_HPHL_RX_EN_MASK, 1); |
| 1567 | snd_soc_component_write_field(component, |
| 1568 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 1569 | WCD938X_RXD0_CLK_EN_MASK, 1); |
| 1570 | if (wcd938x->comp1_enable) |
| 1571 | snd_soc_component_write_field(component, |
| 1572 | WCD938X_DIGITAL_CDC_COMP_CTL_0, |
| 1573 | WCD938X_HPHL_COMP_EN_MASK, 1); |
| 1574 | } |
| 1575 | /* 5 msec delay as per HW requirement */ |
| 1576 | usleep_range(5000, 5010); |
| 1577 | if (wcd938x->flyback_cur_det_disable == 0) |
| 1578 | snd_soc_component_write_field(component, WCD938X_FLYBACK_EN, |
| 1579 | WCD938X_EN_CUR_DET_MASK, 0); |
| 1580 | wcd938x->flyback_cur_det_disable++; |
| 1581 | wcd_clsh_ctrl_set_state(wcd938x->clsh_info, |
| 1582 | WCD_CLSH_EVENT_PRE_DAC, |
| 1583 | WCD_CLSH_STATE_EAR, |
| 1584 | wcd938x->hph_mode); |
| 1585 | break; |
| 1586 | case SND_SOC_DAPM_POST_PMD: |
| 1587 | if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) { |
| 1588 | snd_soc_component_write_field(component, |
| 1589 | WCD938X_DIGITAL_CDC_AUX_GAIN_CTL, |
| 1590 | WCD938X_AUX_EN_MASK, 0); |
| 1591 | snd_soc_component_write_field(component, |
| 1592 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 1593 | WCD938X_RXD2_CLK_EN_MASK, 0); |
| 1594 | } else { |
| 1595 | snd_soc_component_write_field(component, |
| 1596 | WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, |
| 1597 | WCD938X_HPHL_RX_EN_MASK, 0); |
| 1598 | snd_soc_component_write_field(component, |
| 1599 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 1600 | WCD938X_RXD0_CLK_EN_MASK, 0); |
| 1601 | if (wcd938x->comp1_enable) |
| 1602 | snd_soc_component_write_field(component, |
| 1603 | WCD938X_DIGITAL_CDC_COMP_CTL_0, |
| 1604 | WCD938X_HPHL_COMP_EN_MASK, 0); |
| 1605 | } |
| 1606 | snd_soc_component_write_field(component, WCD938X_ANA_EAR_COMPANDER_CTL, |
| 1607 | WCD938X_GAIN_OVRD_REG_MASK, 0); |
| 1608 | snd_soc_component_write_field(component, |
| 1609 | WCD938X_EAR_EAR_DAC_CON, |
| 1610 | WCD938X_DAC_SAMPLE_EDGE_SEL_MASK, 1); |
| 1611 | break; |
| 1612 | } |
| 1613 | return 0; |
| 1614 | |
| 1615 | } |
| 1616 | |
| 1617 | static int wcd938x_codec_aux_dac_event(struct snd_soc_dapm_widget *w, |
| 1618 | struct snd_kcontrol *kcontrol, |
| 1619 | int event) |
| 1620 | { |
| 1621 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 1622 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
Srinivas Kandagatla | 8da9db0 | 2021-06-09 10:09:41 +0100 | [diff] [blame] | 1623 | |
| 1624 | switch (event) { |
| 1625 | case SND_SOC_DAPM_PRE_PMU: |
| 1626 | snd_soc_component_write_field(component, |
| 1627 | WCD938X_DIGITAL_CDC_ANA_CLK_CTL, |
| 1628 | WCD938X_ANA_RX_DIV4_CLK_EN_MASK, 1); |
| 1629 | snd_soc_component_write_field(component, |
| 1630 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 1631 | WCD938X_RXD2_CLK_EN_MASK, 1); |
| 1632 | snd_soc_component_write_field(component, |
| 1633 | WCD938X_DIGITAL_CDC_AUX_GAIN_CTL, |
| 1634 | WCD938X_AUX_EN_MASK, 1); |
| 1635 | if (wcd938x->flyback_cur_det_disable == 0) |
| 1636 | snd_soc_component_write_field(component, WCD938X_FLYBACK_EN, |
| 1637 | WCD938X_EN_CUR_DET_MASK, 0); |
| 1638 | wcd938x->flyback_cur_det_disable++; |
| 1639 | wcd_clsh_ctrl_set_state(wcd938x->clsh_info, |
| 1640 | WCD_CLSH_EVENT_PRE_DAC, |
| 1641 | WCD_CLSH_STATE_AUX, |
| 1642 | wcd938x->hph_mode); |
| 1643 | break; |
| 1644 | case SND_SOC_DAPM_POST_PMD: |
| 1645 | snd_soc_component_write_field(component, |
| 1646 | WCD938X_DIGITAL_CDC_ANA_CLK_CTL, |
| 1647 | WCD938X_ANA_RX_DIV4_CLK_EN_MASK, 0); |
| 1648 | break; |
| 1649 | } |
kernel test robot | 4d0b79e | 2021-06-29 21:29:09 +0800 | [diff] [blame] | 1650 | return 0; |
Srinivas Kandagatla | 8da9db0 | 2021-06-09 10:09:41 +0100 | [diff] [blame] | 1651 | |
| 1652 | } |
| 1653 | |
| 1654 | static int wcd938x_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w, |
| 1655 | struct snd_kcontrol *kcontrol, int event) |
| 1656 | { |
| 1657 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 1658 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 1659 | int hph_mode = wcd938x->hph_mode; |
| 1660 | |
| 1661 | switch (event) { |
| 1662 | case SND_SOC_DAPM_PRE_PMU: |
| 1663 | if (wcd938x->ldoh) |
| 1664 | snd_soc_component_write_field(component, WCD938X_LDOH_MODE, |
| 1665 | WCD938X_LDOH_EN_MASK, 1); |
| 1666 | wcd_clsh_ctrl_set_state(wcd938x->clsh_info, WCD_CLSH_EVENT_PRE_DAC, |
| 1667 | WCD_CLSH_STATE_HPHR, hph_mode); |
| 1668 | wcd_clsh_set_hph_mode(wcd938x->clsh_info, CLS_H_HIFI); |
| 1669 | |
| 1670 | if (hph_mode == CLS_H_LP || hph_mode == CLS_H_LOHIFI || |
| 1671 | hph_mode == CLS_H_ULP) { |
| 1672 | snd_soc_component_write_field(component, |
| 1673 | WCD938X_HPH_REFBUFF_LP_CTL, |
| 1674 | WCD938X_PREREF_FLIT_BYPASS_MASK, 1); |
| 1675 | } |
| 1676 | snd_soc_component_write_field(component, WCD938X_ANA_HPH, |
| 1677 | WCD938X_HPHR_REF_EN_MASK, 1); |
| 1678 | wcd_clsh_set_hph_mode(wcd938x->clsh_info, hph_mode); |
| 1679 | /* 100 usec delay as per HW requirement */ |
| 1680 | usleep_range(100, 110); |
| 1681 | set_bit(HPH_PA_DELAY, &wcd938x->status_mask); |
| 1682 | snd_soc_component_write_field(component, |
| 1683 | WCD938X_DIGITAL_PDM_WD_CTL1, |
| 1684 | WCD938X_PDM_WD_EN_MASK, 0x3); |
| 1685 | break; |
| 1686 | case SND_SOC_DAPM_POST_PMU: |
| 1687 | /* |
| 1688 | * 7ms sleep is required if compander is enabled as per |
| 1689 | * HW requirement. If compander is disabled, then |
| 1690 | * 20ms delay is required. |
| 1691 | */ |
| 1692 | if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) { |
| 1693 | if (!wcd938x->comp2_enable) |
| 1694 | usleep_range(20000, 20100); |
| 1695 | else |
| 1696 | usleep_range(7000, 7100); |
| 1697 | |
| 1698 | if (hph_mode == CLS_H_LP || hph_mode == CLS_H_LOHIFI || |
| 1699 | hph_mode == CLS_H_ULP) |
| 1700 | snd_soc_component_write_field(component, |
| 1701 | WCD938X_HPH_REFBUFF_LP_CTL, |
| 1702 | WCD938X_PREREF_FLIT_BYPASS_MASK, 0); |
| 1703 | clear_bit(HPH_PA_DELAY, &wcd938x->status_mask); |
| 1704 | } |
| 1705 | snd_soc_component_write_field(component, WCD938X_HPH_NEW_INT_HPH_TIMER1, |
| 1706 | WCD938X_AUTOCHOP_TIMER_EN, 1); |
| 1707 | if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI || |
| 1708 | hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI) |
| 1709 | snd_soc_component_write_field(component, WCD938X_ANA_RX_SUPPLIES, |
| 1710 | WCD938X_REGULATOR_MODE_MASK, |
| 1711 | WCD938X_REGULATOR_MODE_CLASS_AB); |
| 1712 | enable_irq(wcd938x->hphr_pdm_wd_int); |
| 1713 | break; |
| 1714 | case SND_SOC_DAPM_PRE_PMD: |
| 1715 | disable_irq_nosync(wcd938x->hphr_pdm_wd_int); |
| 1716 | /* |
| 1717 | * 7ms sleep is required if compander is enabled as per |
| 1718 | * HW requirement. If compander is disabled, then |
| 1719 | * 20ms delay is required. |
| 1720 | */ |
| 1721 | if (!wcd938x->comp2_enable) |
| 1722 | usleep_range(20000, 20100); |
| 1723 | else |
| 1724 | usleep_range(7000, 7100); |
| 1725 | snd_soc_component_write_field(component, WCD938X_ANA_HPH, |
| 1726 | WCD938X_HPHR_EN_MASK, 0); |
| 1727 | set_bit(HPH_PA_DELAY, &wcd938x->status_mask); |
| 1728 | break; |
| 1729 | case SND_SOC_DAPM_POST_PMD: |
| 1730 | /* |
| 1731 | * 7ms sleep is required if compander is enabled as per |
| 1732 | * HW requirement. If compander is disabled, then |
| 1733 | * 20ms delay is required. |
| 1734 | */ |
| 1735 | if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) { |
| 1736 | if (!wcd938x->comp2_enable) |
| 1737 | usleep_range(20000, 20100); |
| 1738 | else |
| 1739 | usleep_range(7000, 7100); |
| 1740 | clear_bit(HPH_PA_DELAY, &wcd938x->status_mask); |
| 1741 | } |
| 1742 | snd_soc_component_write_field(component, WCD938X_ANA_HPH, |
| 1743 | WCD938X_HPHR_REF_EN_MASK, 0); |
| 1744 | snd_soc_component_write_field(component, WCD938X_DIGITAL_PDM_WD_CTL1, |
| 1745 | WCD938X_PDM_WD_EN_MASK, 0); |
| 1746 | wcd_clsh_ctrl_set_state(wcd938x->clsh_info, WCD_CLSH_EVENT_POST_PA, |
| 1747 | WCD_CLSH_STATE_HPHR, hph_mode); |
| 1748 | if (wcd938x->ldoh) |
| 1749 | snd_soc_component_write_field(component, WCD938X_LDOH_MODE, |
| 1750 | WCD938X_LDOH_EN_MASK, 0); |
| 1751 | break; |
| 1752 | } |
| 1753 | |
| 1754 | return 0; |
| 1755 | } |
| 1756 | |
| 1757 | static int wcd938x_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w, |
| 1758 | struct snd_kcontrol *kcontrol, int event) |
| 1759 | { |
| 1760 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 1761 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 1762 | int hph_mode = wcd938x->hph_mode; |
| 1763 | |
| 1764 | switch (event) { |
| 1765 | case SND_SOC_DAPM_PRE_PMU: |
| 1766 | if (wcd938x->ldoh) |
| 1767 | snd_soc_component_write_field(component, WCD938X_LDOH_MODE, |
| 1768 | WCD938X_LDOH_EN_MASK, 1); |
| 1769 | wcd_clsh_ctrl_set_state(wcd938x->clsh_info, WCD_CLSH_EVENT_PRE_DAC, |
| 1770 | WCD_CLSH_STATE_HPHL, hph_mode); |
| 1771 | wcd_clsh_set_hph_mode(wcd938x->clsh_info, CLS_H_HIFI); |
| 1772 | if (hph_mode == CLS_H_LP || hph_mode == CLS_H_LOHIFI || |
| 1773 | hph_mode == CLS_H_ULP) { |
| 1774 | snd_soc_component_write_field(component, |
| 1775 | WCD938X_HPH_REFBUFF_LP_CTL, |
| 1776 | WCD938X_PREREF_FLIT_BYPASS_MASK, 1); |
| 1777 | } |
| 1778 | snd_soc_component_write_field(component, WCD938X_ANA_HPH, |
| 1779 | WCD938X_HPHL_REF_EN_MASK, 1); |
| 1780 | wcd_clsh_set_hph_mode(wcd938x->clsh_info, hph_mode); |
| 1781 | /* 100 usec delay as per HW requirement */ |
| 1782 | usleep_range(100, 110); |
| 1783 | set_bit(HPH_PA_DELAY, &wcd938x->status_mask); |
| 1784 | snd_soc_component_write_field(component, |
| 1785 | WCD938X_DIGITAL_PDM_WD_CTL0, |
| 1786 | WCD938X_PDM_WD_EN_MASK, 0x3); |
| 1787 | break; |
| 1788 | case SND_SOC_DAPM_POST_PMU: |
| 1789 | /* |
| 1790 | * 7ms sleep is required if compander is enabled as per |
| 1791 | * HW requirement. If compander is disabled, then |
| 1792 | * 20ms delay is required. |
| 1793 | */ |
| 1794 | if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) { |
| 1795 | if (!wcd938x->comp1_enable) |
| 1796 | usleep_range(20000, 20100); |
| 1797 | else |
| 1798 | usleep_range(7000, 7100); |
| 1799 | if (hph_mode == CLS_H_LP || hph_mode == CLS_H_LOHIFI || |
| 1800 | hph_mode == CLS_H_ULP) |
| 1801 | snd_soc_component_write_field(component, |
| 1802 | WCD938X_HPH_REFBUFF_LP_CTL, |
| 1803 | WCD938X_PREREF_FLIT_BYPASS_MASK, 0); |
| 1804 | clear_bit(HPH_PA_DELAY, &wcd938x->status_mask); |
| 1805 | } |
| 1806 | |
| 1807 | snd_soc_component_write_field(component, WCD938X_HPH_NEW_INT_HPH_TIMER1, |
| 1808 | WCD938X_AUTOCHOP_TIMER_EN, 1); |
| 1809 | if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI || |
| 1810 | hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI) |
| 1811 | snd_soc_component_write_field(component, WCD938X_ANA_RX_SUPPLIES, |
| 1812 | WCD938X_REGULATOR_MODE_MASK, |
| 1813 | WCD938X_REGULATOR_MODE_CLASS_AB); |
| 1814 | enable_irq(wcd938x->hphl_pdm_wd_int); |
| 1815 | break; |
| 1816 | case SND_SOC_DAPM_PRE_PMD: |
| 1817 | disable_irq_nosync(wcd938x->hphl_pdm_wd_int); |
| 1818 | /* |
| 1819 | * 7ms sleep is required if compander is enabled as per |
| 1820 | * HW requirement. If compander is disabled, then |
| 1821 | * 20ms delay is required. |
| 1822 | */ |
| 1823 | if (!wcd938x->comp1_enable) |
| 1824 | usleep_range(20000, 20100); |
| 1825 | else |
| 1826 | usleep_range(7000, 7100); |
| 1827 | snd_soc_component_write_field(component, WCD938X_ANA_HPH, |
| 1828 | WCD938X_HPHL_EN_MASK, 0); |
| 1829 | set_bit(HPH_PA_DELAY, &wcd938x->status_mask); |
| 1830 | break; |
| 1831 | case SND_SOC_DAPM_POST_PMD: |
| 1832 | /* |
| 1833 | * 7ms sleep is required if compander is enabled as per |
| 1834 | * HW requirement. If compander is disabled, then |
| 1835 | * 20ms delay is required. |
| 1836 | */ |
| 1837 | if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) { |
| 1838 | if (!wcd938x->comp1_enable) |
| 1839 | usleep_range(21000, 21100); |
| 1840 | else |
| 1841 | usleep_range(7000, 7100); |
| 1842 | clear_bit(HPH_PA_DELAY, &wcd938x->status_mask); |
| 1843 | } |
| 1844 | snd_soc_component_write_field(component, WCD938X_ANA_HPH, |
| 1845 | WCD938X_HPHL_REF_EN_MASK, 0); |
| 1846 | snd_soc_component_write_field(component, WCD938X_DIGITAL_PDM_WD_CTL0, |
| 1847 | WCD938X_PDM_WD_EN_MASK, 0); |
| 1848 | wcd_clsh_ctrl_set_state(wcd938x->clsh_info, WCD_CLSH_EVENT_POST_PA, |
| 1849 | WCD_CLSH_STATE_HPHL, hph_mode); |
| 1850 | if (wcd938x->ldoh) |
| 1851 | snd_soc_component_write_field(component, WCD938X_LDOH_MODE, |
| 1852 | WCD938X_LDOH_EN_MASK, 0); |
| 1853 | break; |
| 1854 | } |
| 1855 | |
| 1856 | return 0; |
| 1857 | } |
| 1858 | |
| 1859 | static int wcd938x_codec_enable_aux_pa(struct snd_soc_dapm_widget *w, |
| 1860 | struct snd_kcontrol *kcontrol, int event) |
| 1861 | { |
| 1862 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 1863 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 1864 | int hph_mode = wcd938x->hph_mode; |
Srinivas Kandagatla | 8da9db0 | 2021-06-09 10:09:41 +0100 | [diff] [blame] | 1865 | |
| 1866 | switch (event) { |
| 1867 | case SND_SOC_DAPM_PRE_PMU: |
| 1868 | snd_soc_component_write_field(component, WCD938X_DIGITAL_PDM_WD_CTL2, |
| 1869 | WCD938X_AUX_PDM_WD_EN_MASK, 1); |
| 1870 | break; |
| 1871 | case SND_SOC_DAPM_POST_PMU: |
| 1872 | /* 1 msec delay as per HW requirement */ |
| 1873 | usleep_range(1000, 1010); |
| 1874 | if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI || |
| 1875 | hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI) |
| 1876 | snd_soc_component_write_field(component, WCD938X_ANA_RX_SUPPLIES, |
| 1877 | WCD938X_REGULATOR_MODE_MASK, |
| 1878 | WCD938X_REGULATOR_MODE_CLASS_AB); |
| 1879 | enable_irq(wcd938x->aux_pdm_wd_int); |
| 1880 | break; |
| 1881 | case SND_SOC_DAPM_PRE_PMD: |
| 1882 | disable_irq_nosync(wcd938x->aux_pdm_wd_int); |
| 1883 | break; |
| 1884 | case SND_SOC_DAPM_POST_PMD: |
| 1885 | /* 1 msec delay as per HW requirement */ |
| 1886 | usleep_range(1000, 1010); |
| 1887 | snd_soc_component_write_field(component, WCD938X_DIGITAL_PDM_WD_CTL2, |
| 1888 | WCD938X_AUX_PDM_WD_EN_MASK, 0); |
| 1889 | wcd_clsh_ctrl_set_state(wcd938x->clsh_info, |
| 1890 | WCD_CLSH_EVENT_POST_PA, |
| 1891 | WCD_CLSH_STATE_AUX, |
| 1892 | hph_mode); |
| 1893 | |
| 1894 | wcd938x->flyback_cur_det_disable--; |
| 1895 | if (wcd938x->flyback_cur_det_disable == 0) |
| 1896 | snd_soc_component_write_field(component, WCD938X_FLYBACK_EN, |
| 1897 | WCD938X_EN_CUR_DET_MASK, 1); |
| 1898 | break; |
| 1899 | } |
kernel test robot | 4d0b79e | 2021-06-29 21:29:09 +0800 | [diff] [blame] | 1900 | return 0; |
Srinivas Kandagatla | 8da9db0 | 2021-06-09 10:09:41 +0100 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | static int wcd938x_codec_enable_ear_pa(struct snd_soc_dapm_widget *w, |
| 1904 | struct snd_kcontrol *kcontrol, int event) |
| 1905 | { |
| 1906 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 1907 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 1908 | int hph_mode = wcd938x->hph_mode; |
| 1909 | |
| 1910 | switch (event) { |
| 1911 | case SND_SOC_DAPM_PRE_PMU: |
| 1912 | /* |
| 1913 | * Enable watchdog interrupt for HPHL or AUX |
| 1914 | * depending on mux value |
| 1915 | */ |
| 1916 | wcd938x->ear_rx_path = snd_soc_component_read(component, |
| 1917 | WCD938X_DIGITAL_CDC_EAR_PATH_CTL); |
| 1918 | if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) |
| 1919 | snd_soc_component_write_field(component, WCD938X_DIGITAL_PDM_WD_CTL2, |
| 1920 | WCD938X_AUX_PDM_WD_EN_MASK, 1); |
| 1921 | else |
| 1922 | snd_soc_component_write_field(component, |
| 1923 | WCD938X_DIGITAL_PDM_WD_CTL0, |
| 1924 | WCD938X_PDM_WD_EN_MASK, 0x3); |
| 1925 | if (!wcd938x->comp1_enable) |
| 1926 | snd_soc_component_write_field(component, |
| 1927 | WCD938X_ANA_EAR_COMPANDER_CTL, |
| 1928 | WCD938X_GAIN_OVRD_REG_MASK, 1); |
| 1929 | |
| 1930 | break; |
| 1931 | case SND_SOC_DAPM_POST_PMU: |
| 1932 | /* 6 msec delay as per HW requirement */ |
| 1933 | usleep_range(6000, 6010); |
| 1934 | if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI || |
| 1935 | hph_mode == CLS_AB_LP || hph_mode == CLS_AB_LOHIFI) |
| 1936 | snd_soc_component_write_field(component, WCD938X_ANA_RX_SUPPLIES, |
| 1937 | WCD938X_REGULATOR_MODE_MASK, |
| 1938 | WCD938X_REGULATOR_MODE_CLASS_AB); |
| 1939 | if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) |
| 1940 | enable_irq(wcd938x->aux_pdm_wd_int); |
| 1941 | else |
| 1942 | enable_irq(wcd938x->hphl_pdm_wd_int); |
| 1943 | break; |
| 1944 | case SND_SOC_DAPM_PRE_PMD: |
| 1945 | if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) |
| 1946 | disable_irq_nosync(wcd938x->aux_pdm_wd_int); |
| 1947 | else |
| 1948 | disable_irq_nosync(wcd938x->hphl_pdm_wd_int); |
| 1949 | break; |
| 1950 | case SND_SOC_DAPM_POST_PMD: |
| 1951 | if (!wcd938x->comp1_enable) |
| 1952 | snd_soc_component_write_field(component, WCD938X_ANA_EAR_COMPANDER_CTL, |
| 1953 | WCD938X_GAIN_OVRD_REG_MASK, 0); |
| 1954 | /* 7 msec delay as per HW requirement */ |
| 1955 | usleep_range(7000, 7010); |
| 1956 | if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) |
| 1957 | snd_soc_component_write_field(component, WCD938X_DIGITAL_PDM_WD_CTL2, |
| 1958 | WCD938X_AUX_PDM_WD_EN_MASK, 0); |
| 1959 | else |
| 1960 | snd_soc_component_write_field(component, WCD938X_DIGITAL_PDM_WD_CTL0, |
| 1961 | WCD938X_PDM_WD_EN_MASK, 0); |
| 1962 | |
| 1963 | wcd_clsh_ctrl_set_state(wcd938x->clsh_info, WCD_CLSH_EVENT_POST_PA, |
| 1964 | WCD_CLSH_STATE_EAR, hph_mode); |
| 1965 | |
| 1966 | wcd938x->flyback_cur_det_disable--; |
| 1967 | if (wcd938x->flyback_cur_det_disable == 0) |
| 1968 | snd_soc_component_write_field(component, WCD938X_FLYBACK_EN, |
| 1969 | WCD938X_EN_CUR_DET_MASK, 1); |
| 1970 | break; |
| 1971 | } |
| 1972 | |
| 1973 | return 0; |
| 1974 | } |
| 1975 | |
Srinivas Kandagatla | d5add08 | 2021-06-09 10:09:42 +0100 | [diff] [blame] | 1976 | static int wcd938x_codec_enable_dmic(struct snd_soc_dapm_widget *w, |
| 1977 | struct snd_kcontrol *kcontrol, |
| 1978 | int event) |
| 1979 | { |
| 1980 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 1981 | u16 dmic_clk_reg, dmic_clk_en_reg; |
| 1982 | u8 dmic_sel_mask, dmic_clk_mask; |
| 1983 | |
| 1984 | switch (w->shift) { |
| 1985 | case 0: |
| 1986 | case 1: |
| 1987 | dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_1_2; |
| 1988 | dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC1_CTL; |
| 1989 | dmic_clk_mask = WCD938X_DMIC1_RATE_MASK; |
| 1990 | dmic_sel_mask = WCD938X_AMIC1_IN_SEL_MASK; |
| 1991 | break; |
| 1992 | case 2: |
| 1993 | case 3: |
| 1994 | dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_1_2; |
| 1995 | dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC2_CTL; |
| 1996 | dmic_clk_mask = WCD938X_DMIC2_RATE_MASK; |
| 1997 | dmic_sel_mask = WCD938X_AMIC3_IN_SEL_MASK; |
| 1998 | break; |
| 1999 | case 4: |
| 2000 | case 5: |
| 2001 | dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_3_4; |
| 2002 | dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC3_CTL; |
| 2003 | dmic_clk_mask = WCD938X_DMIC3_RATE_MASK; |
| 2004 | dmic_sel_mask = WCD938X_AMIC4_IN_SEL_MASK; |
| 2005 | break; |
| 2006 | case 6: |
| 2007 | case 7: |
| 2008 | dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC_RATE_3_4; |
| 2009 | dmic_clk_en_reg = WCD938X_DIGITAL_CDC_DMIC4_CTL; |
| 2010 | dmic_clk_mask = WCD938X_DMIC4_RATE_MASK; |
| 2011 | dmic_sel_mask = WCD938X_AMIC5_IN_SEL_MASK; |
| 2012 | break; |
| 2013 | default: |
| 2014 | dev_err(component->dev, "%s: Invalid DMIC Selection\n", |
| 2015 | __func__); |
| 2016 | return -EINVAL; |
| 2017 | } |
| 2018 | |
| 2019 | switch (event) { |
| 2020 | case SND_SOC_DAPM_PRE_PMU: |
| 2021 | snd_soc_component_write_field(component, |
| 2022 | WCD938X_DIGITAL_CDC_AMIC_CTL, |
| 2023 | dmic_sel_mask, |
| 2024 | WCD938X_AMIC1_IN_SEL_DMIC); |
| 2025 | /* 250us sleep as per HW requirement */ |
| 2026 | usleep_range(250, 260); |
| 2027 | /* Setting DMIC clock rate to 2.4MHz */ |
| 2028 | snd_soc_component_write_field(component, dmic_clk_reg, |
| 2029 | dmic_clk_mask, |
| 2030 | WCD938X_DMIC4_RATE_2P4MHZ); |
| 2031 | snd_soc_component_write_field(component, dmic_clk_en_reg, |
| 2032 | WCD938X_DMIC_CLK_EN_MASK, 1); |
| 2033 | /* enable clock scaling */ |
| 2034 | snd_soc_component_write_field(component, WCD938X_DIGITAL_CDC_DMIC_CTL, |
| 2035 | WCD938X_DMIC_CLK_SCALING_EN_MASK, 0x3); |
| 2036 | break; |
| 2037 | case SND_SOC_DAPM_POST_PMD: |
| 2038 | snd_soc_component_write_field(component, |
| 2039 | WCD938X_DIGITAL_CDC_AMIC_CTL, |
| 2040 | dmic_sel_mask, WCD938X_AMIC1_IN_SEL_AMIC); |
| 2041 | snd_soc_component_write_field(component, dmic_clk_en_reg, |
| 2042 | WCD938X_DMIC_CLK_EN_MASK, 0); |
| 2043 | break; |
| 2044 | } |
| 2045 | return 0; |
| 2046 | } |
| 2047 | |
| 2048 | static int wcd938x_tx_swr_ctrl(struct snd_soc_dapm_widget *w, |
| 2049 | struct snd_kcontrol *kcontrol, int event) |
| 2050 | { |
| 2051 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 2052 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2053 | int bank; |
| 2054 | int rate; |
| 2055 | |
| 2056 | bank = (wcd938x_swr_get_current_bank(wcd938x->sdw_priv[AIF1_CAP]->sdev)) ? 0 : 1; |
| 2057 | bank = bank ? 0 : 1; |
| 2058 | |
| 2059 | switch (event) { |
| 2060 | case SND_SOC_DAPM_PRE_PMU: |
| 2061 | if (strnstr(w->name, "ADC", sizeof("ADC"))) { |
| 2062 | int i = 0, mode = 0; |
| 2063 | |
| 2064 | if (test_bit(WCD_ADC1, &wcd938x->status_mask)) |
| 2065 | mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC1]]; |
| 2066 | if (test_bit(WCD_ADC2, &wcd938x->status_mask)) |
| 2067 | mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC2]]; |
| 2068 | if (test_bit(WCD_ADC3, &wcd938x->status_mask)) |
| 2069 | mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC3]]; |
| 2070 | if (test_bit(WCD_ADC4, &wcd938x->status_mask)) |
| 2071 | mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC4]]; |
| 2072 | |
| 2073 | if (mode != 0) { |
| 2074 | for (i = 0; i < ADC_MODE_ULP2; i++) { |
| 2075 | if (mode & (1 << i)) { |
| 2076 | i++; |
| 2077 | break; |
| 2078 | } |
| 2079 | } |
| 2080 | } |
| 2081 | rate = wcd938x_get_clk_rate(i); |
| 2082 | wcd938x_set_swr_clk_rate(component, rate, bank); |
Srinivas Kandagatla | d5add08 | 2021-06-09 10:09:42 +0100 | [diff] [blame] | 2083 | /* Copy clk settings to active bank */ |
| 2084 | wcd938x_set_swr_clk_rate(component, rate, !bank); |
Srinivas Kandagatla | d245fff | 2021-06-21 14:45:02 +0100 | [diff] [blame] | 2085 | } |
Srinivas Kandagatla | d5add08 | 2021-06-09 10:09:42 +0100 | [diff] [blame] | 2086 | break; |
| 2087 | case SND_SOC_DAPM_POST_PMD: |
| 2088 | if (strnstr(w->name, "ADC", sizeof("ADC"))) { |
| 2089 | rate = wcd938x_get_clk_rate(ADC_MODE_INVALID); |
| 2090 | wcd938x_set_swr_clk_rate(component, rate, !bank); |
| 2091 | wcd938x_set_swr_clk_rate(component, rate, bank); |
| 2092 | } |
| 2093 | break; |
| 2094 | } |
| 2095 | |
| 2096 | return 0; |
| 2097 | } |
| 2098 | |
| 2099 | static int wcd938x_get_adc_mode(int val) |
| 2100 | { |
| 2101 | int ret = 0; |
| 2102 | |
| 2103 | switch (val) { |
| 2104 | case ADC_MODE_INVALID: |
| 2105 | ret = ADC_MODE_VAL_NORMAL; |
| 2106 | break; |
| 2107 | case ADC_MODE_HIFI: |
| 2108 | ret = ADC_MODE_VAL_HIFI; |
| 2109 | break; |
| 2110 | case ADC_MODE_LO_HIF: |
| 2111 | ret = ADC_MODE_VAL_LO_HIF; |
| 2112 | break; |
| 2113 | case ADC_MODE_NORMAL: |
| 2114 | ret = ADC_MODE_VAL_NORMAL; |
| 2115 | break; |
| 2116 | case ADC_MODE_LP: |
| 2117 | ret = ADC_MODE_VAL_LP; |
| 2118 | break; |
| 2119 | case ADC_MODE_ULP1: |
| 2120 | ret = ADC_MODE_VAL_ULP1; |
| 2121 | break; |
| 2122 | case ADC_MODE_ULP2: |
| 2123 | ret = ADC_MODE_VAL_ULP2; |
| 2124 | break; |
| 2125 | default: |
| 2126 | ret = -EINVAL; |
| 2127 | break; |
| 2128 | } |
| 2129 | return ret; |
| 2130 | } |
| 2131 | |
| 2132 | static int wcd938x_codec_enable_adc(struct snd_soc_dapm_widget *w, |
| 2133 | struct snd_kcontrol *kcontrol, int event) |
| 2134 | { |
| 2135 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 2136 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2137 | |
| 2138 | switch (event) { |
| 2139 | case SND_SOC_DAPM_PRE_PMU: |
| 2140 | snd_soc_component_write_field(component, |
| 2141 | WCD938X_DIGITAL_CDC_ANA_CLK_CTL, |
| 2142 | WCD938X_ANA_TX_CLK_EN_MASK, 1); |
| 2143 | snd_soc_component_write_field(component, |
| 2144 | WCD938X_DIGITAL_CDC_ANA_CLK_CTL, |
| 2145 | WCD938X_ANA_TX_DIV2_CLK_EN_MASK, 1); |
| 2146 | set_bit(w->shift, &wcd938x->status_mask); |
| 2147 | break; |
| 2148 | case SND_SOC_DAPM_POST_PMD: |
| 2149 | snd_soc_component_write_field(component, WCD938X_DIGITAL_CDC_ANA_CLK_CTL, |
| 2150 | WCD938X_ANA_TX_CLK_EN_MASK, 0); |
| 2151 | clear_bit(w->shift, &wcd938x->status_mask); |
| 2152 | break; |
| 2153 | } |
| 2154 | |
| 2155 | return 0; |
| 2156 | } |
| 2157 | |
| 2158 | static void wcd938x_tx_channel_config(struct snd_soc_component *component, |
| 2159 | int channel, int mode) |
| 2160 | { |
| 2161 | int reg, mask; |
| 2162 | |
| 2163 | switch (channel) { |
| 2164 | case 0: |
| 2165 | reg = WCD938X_ANA_TX_CH2; |
| 2166 | mask = WCD938X_HPF1_INIT_MASK; |
| 2167 | break; |
| 2168 | case 1: |
| 2169 | reg = WCD938X_ANA_TX_CH2; |
| 2170 | mask = WCD938X_HPF2_INIT_MASK; |
| 2171 | break; |
| 2172 | case 2: |
| 2173 | reg = WCD938X_ANA_TX_CH4; |
| 2174 | mask = WCD938X_HPF3_INIT_MASK; |
| 2175 | break; |
| 2176 | case 3: |
| 2177 | reg = WCD938X_ANA_TX_CH4; |
| 2178 | mask = WCD938X_HPF4_INIT_MASK; |
| 2179 | break; |
Srinivas Kandagatla | d245fff | 2021-06-21 14:45:02 +0100 | [diff] [blame] | 2180 | default: |
| 2181 | return; |
Srinivas Kandagatla | d5add08 | 2021-06-09 10:09:42 +0100 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | snd_soc_component_write_field(component, reg, mask, mode); |
| 2185 | } |
| 2186 | |
| 2187 | static int wcd938x_adc_enable_req(struct snd_soc_dapm_widget *w, |
| 2188 | struct snd_kcontrol *kcontrol, int event) |
| 2189 | { |
| 2190 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 2191 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2192 | int mode; |
| 2193 | |
| 2194 | switch (event) { |
| 2195 | case SND_SOC_DAPM_PRE_PMU: |
| 2196 | snd_soc_component_write_field(component, |
| 2197 | WCD938X_DIGITAL_CDC_REQ_CTL, |
| 2198 | WCD938X_FS_RATE_4P8_MASK, 1); |
| 2199 | snd_soc_component_write_field(component, |
| 2200 | WCD938X_DIGITAL_CDC_REQ_CTL, |
| 2201 | WCD938X_NO_NOTCH_MASK, 0); |
| 2202 | wcd938x_tx_channel_config(component, w->shift, 1); |
| 2203 | mode = wcd938x_get_adc_mode(wcd938x->tx_mode[w->shift]); |
| 2204 | if (mode < 0) { |
| 2205 | dev_info(component->dev, "Invalid ADC mode\n"); |
| 2206 | return -EINVAL; |
| 2207 | } |
| 2208 | switch (w->shift) { |
| 2209 | case 0: |
| 2210 | snd_soc_component_write_field(component, |
| 2211 | WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, |
| 2212 | WCD938X_TXD0_MODE_MASK, mode); |
| 2213 | snd_soc_component_write_field(component, |
| 2214 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 2215 | WCD938X_TXD0_CLK_EN_MASK, 1); |
| 2216 | break; |
| 2217 | case 1: |
| 2218 | snd_soc_component_write_field(component, |
| 2219 | WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, |
| 2220 | WCD938X_TXD1_MODE_MASK, mode); |
| 2221 | snd_soc_component_write_field(component, |
| 2222 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 2223 | WCD938X_TXD1_CLK_EN_MASK, 1); |
| 2224 | break; |
| 2225 | case 2: |
| 2226 | snd_soc_component_write_field(component, |
| 2227 | WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, |
| 2228 | WCD938X_TXD2_MODE_MASK, mode); |
| 2229 | snd_soc_component_write_field(component, |
| 2230 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 2231 | WCD938X_TXD2_CLK_EN_MASK, 1); |
| 2232 | break; |
| 2233 | case 3: |
| 2234 | snd_soc_component_write_field(component, |
| 2235 | WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, |
| 2236 | WCD938X_TXD3_MODE_MASK, mode); |
| 2237 | snd_soc_component_write_field(component, |
| 2238 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 2239 | WCD938X_TXD3_CLK_EN_MASK, 1); |
| 2240 | break; |
| 2241 | default: |
| 2242 | break; |
| 2243 | } |
| 2244 | |
| 2245 | wcd938x_tx_channel_config(component, w->shift, 0); |
| 2246 | break; |
| 2247 | case SND_SOC_DAPM_POST_PMD: |
| 2248 | switch (w->shift) { |
| 2249 | case 0: |
| 2250 | snd_soc_component_write_field(component, |
| 2251 | WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, |
| 2252 | WCD938X_TXD0_MODE_MASK, 0); |
| 2253 | snd_soc_component_write_field(component, |
| 2254 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 2255 | WCD938X_TXD0_CLK_EN_MASK, 0); |
| 2256 | break; |
| 2257 | case 1: |
| 2258 | snd_soc_component_write_field(component, |
| 2259 | WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, |
| 2260 | WCD938X_TXD1_MODE_MASK, 0); |
| 2261 | snd_soc_component_write_field(component, |
| 2262 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 2263 | WCD938X_TXD1_CLK_EN_MASK, 0); |
| 2264 | break; |
| 2265 | case 2: |
| 2266 | snd_soc_component_write_field(component, |
| 2267 | WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, |
| 2268 | WCD938X_TXD2_MODE_MASK, 0); |
| 2269 | snd_soc_component_write_field(component, |
| 2270 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 2271 | WCD938X_TXD2_CLK_EN_MASK, 0); |
| 2272 | break; |
| 2273 | case 3: |
| 2274 | snd_soc_component_write_field(component, |
| 2275 | WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, |
| 2276 | WCD938X_TXD3_MODE_MASK, 0); |
| 2277 | snd_soc_component_write_field(component, |
| 2278 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 2279 | WCD938X_TXD3_CLK_EN_MASK, 0); |
| 2280 | break; |
| 2281 | default: |
| 2282 | break; |
| 2283 | } |
| 2284 | snd_soc_component_write_field(component, |
| 2285 | WCD938X_DIGITAL_CDC_ANA_CLK_CTL, |
| 2286 | WCD938X_ANA_TX_DIV2_CLK_EN_MASK, 0); |
| 2287 | break; |
| 2288 | } |
| 2289 | |
| 2290 | return 0; |
| 2291 | } |
| 2292 | |
| 2293 | static int wcd938x_micbias_control(struct snd_soc_component *component, |
| 2294 | int micb_num, int req, bool is_dapm) |
| 2295 | { |
| 2296 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2297 | int micb_index = micb_num - 1; |
| 2298 | u16 micb_reg; |
| 2299 | |
| 2300 | switch (micb_num) { |
| 2301 | case MIC_BIAS_1: |
| 2302 | micb_reg = WCD938X_ANA_MICB1; |
| 2303 | break; |
| 2304 | case MIC_BIAS_2: |
| 2305 | micb_reg = WCD938X_ANA_MICB2; |
| 2306 | break; |
| 2307 | case MIC_BIAS_3: |
| 2308 | micb_reg = WCD938X_ANA_MICB3; |
| 2309 | break; |
| 2310 | case MIC_BIAS_4: |
| 2311 | micb_reg = WCD938X_ANA_MICB4; |
| 2312 | break; |
| 2313 | default: |
| 2314 | dev_err(component->dev, "%s: Invalid micbias number: %d\n", |
| 2315 | __func__, micb_num); |
| 2316 | return -EINVAL; |
| 2317 | } |
| 2318 | |
| 2319 | switch (req) { |
| 2320 | case MICB_PULLUP_ENABLE: |
| 2321 | wcd938x->pullup_ref[micb_index]++; |
| 2322 | if ((wcd938x->pullup_ref[micb_index] == 1) && |
| 2323 | (wcd938x->micb_ref[micb_index] == 0)) |
| 2324 | snd_soc_component_write_field(component, micb_reg, |
| 2325 | WCD938X_MICB_EN_MASK, |
| 2326 | WCD938X_MICB_PULL_UP); |
| 2327 | break; |
| 2328 | case MICB_PULLUP_DISABLE: |
| 2329 | if (wcd938x->pullup_ref[micb_index] > 0) |
| 2330 | wcd938x->pullup_ref[micb_index]--; |
| 2331 | |
| 2332 | if ((wcd938x->pullup_ref[micb_index] == 0) && |
| 2333 | (wcd938x->micb_ref[micb_index] == 0)) |
| 2334 | snd_soc_component_write_field(component, micb_reg, |
| 2335 | WCD938X_MICB_EN_MASK, 0); |
| 2336 | break; |
| 2337 | case MICB_ENABLE: |
| 2338 | wcd938x->micb_ref[micb_index]++; |
| 2339 | if (wcd938x->micb_ref[micb_index] == 1) { |
| 2340 | snd_soc_component_write_field(component, |
| 2341 | WCD938X_DIGITAL_CDC_DIG_CLK_CTL, |
| 2342 | WCD938X_TX_CLK_EN_MASK, 0xF); |
| 2343 | snd_soc_component_write_field(component, |
| 2344 | WCD938X_DIGITAL_CDC_ANA_CLK_CTL, |
| 2345 | WCD938X_ANA_TX_DIV2_CLK_EN_MASK, 1); |
| 2346 | snd_soc_component_write_field(component, |
| 2347 | WCD938X_DIGITAL_CDC_ANA_TX_CLK_CTL, |
| 2348 | WCD938X_TX_SC_CLK_EN_MASK, 1); |
| 2349 | |
| 2350 | snd_soc_component_write_field(component, micb_reg, |
| 2351 | WCD938X_MICB_EN_MASK, |
| 2352 | WCD938X_MICB_ENABLE); |
| 2353 | } |
| 2354 | |
| 2355 | break; |
| 2356 | case MICB_DISABLE: |
| 2357 | if (wcd938x->micb_ref[micb_index] > 0) |
| 2358 | wcd938x->micb_ref[micb_index]--; |
| 2359 | |
| 2360 | if ((wcd938x->micb_ref[micb_index] == 0) && |
| 2361 | (wcd938x->pullup_ref[micb_index] > 0)) |
| 2362 | snd_soc_component_write_field(component, micb_reg, |
| 2363 | WCD938X_MICB_EN_MASK, |
| 2364 | WCD938X_MICB_PULL_UP); |
| 2365 | else if ((wcd938x->micb_ref[micb_index] == 0) && |
| 2366 | (wcd938x->pullup_ref[micb_index] == 0)) { |
| 2367 | |
| 2368 | snd_soc_component_write_field(component, micb_reg, |
| 2369 | WCD938X_MICB_EN_MASK, 0); |
| 2370 | } |
| 2371 | break; |
| 2372 | } |
| 2373 | |
| 2374 | return 0; |
| 2375 | } |
| 2376 | |
| 2377 | static int wcd938x_codec_enable_micbias(struct snd_soc_dapm_widget *w, |
| 2378 | struct snd_kcontrol *kcontrol, |
| 2379 | int event) |
| 2380 | { |
| 2381 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 2382 | int micb_num = w->shift; |
| 2383 | |
| 2384 | switch (event) { |
| 2385 | case SND_SOC_DAPM_PRE_PMU: |
| 2386 | wcd938x_micbias_control(component, micb_num, MICB_ENABLE, true); |
| 2387 | break; |
| 2388 | case SND_SOC_DAPM_POST_PMU: |
| 2389 | /* 1 msec delay as per HW requirement */ |
| 2390 | usleep_range(1000, 1100); |
| 2391 | break; |
| 2392 | case SND_SOC_DAPM_POST_PMD: |
| 2393 | wcd938x_micbias_control(component, micb_num, MICB_DISABLE, true); |
| 2394 | break; |
| 2395 | } |
| 2396 | |
| 2397 | return 0; |
| 2398 | } |
| 2399 | |
| 2400 | static int wcd938x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w, |
| 2401 | struct snd_kcontrol *kcontrol, |
| 2402 | int event) |
| 2403 | { |
| 2404 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 2405 | int micb_num = w->shift; |
| 2406 | |
| 2407 | switch (event) { |
| 2408 | case SND_SOC_DAPM_PRE_PMU: |
| 2409 | wcd938x_micbias_control(component, micb_num, |
| 2410 | MICB_PULLUP_ENABLE, true); |
| 2411 | break; |
| 2412 | case SND_SOC_DAPM_POST_PMU: |
| 2413 | /* 1 msec delay as per HW requirement */ |
| 2414 | usleep_range(1000, 1100); |
| 2415 | break; |
| 2416 | case SND_SOC_DAPM_POST_PMD: |
| 2417 | wcd938x_micbias_control(component, micb_num, |
| 2418 | MICB_PULLUP_DISABLE, true); |
| 2419 | break; |
| 2420 | } |
| 2421 | |
| 2422 | return 0; |
| 2423 | } |
| 2424 | |
Srinivas Kandagatla | e8ba1e0 | 2021-06-09 10:09:40 +0100 | [diff] [blame] | 2425 | static int wcd938x_tx_mode_get(struct snd_kcontrol *kcontrol, |
| 2426 | struct snd_ctl_elem_value *ucontrol) |
| 2427 | { |
| 2428 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
| 2429 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2430 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 2431 | int path = e->shift_l; |
| 2432 | |
| 2433 | ucontrol->value.integer.value[0] = wcd938x->tx_mode[path]; |
| 2434 | |
| 2435 | return 0; |
| 2436 | } |
| 2437 | |
| 2438 | static int wcd938x_tx_mode_put(struct snd_kcontrol *kcontrol, |
| 2439 | struct snd_ctl_elem_value *ucontrol) |
| 2440 | { |
| 2441 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
| 2442 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2443 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 2444 | int path = e->shift_l; |
| 2445 | |
| 2446 | wcd938x->tx_mode[path] = ucontrol->value.enumerated.item[0]; |
| 2447 | |
| 2448 | return 1; |
| 2449 | } |
| 2450 | |
| 2451 | static int wcd938x_rx_hph_mode_get(struct snd_kcontrol *kcontrol, |
| 2452 | struct snd_ctl_elem_value *ucontrol) |
| 2453 | { |
| 2454 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
| 2455 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2456 | |
| 2457 | ucontrol->value.integer.value[0] = wcd938x->hph_mode; |
| 2458 | |
| 2459 | return 0; |
| 2460 | } |
| 2461 | |
| 2462 | static int wcd938x_rx_hph_mode_put(struct snd_kcontrol *kcontrol, |
| 2463 | struct snd_ctl_elem_value *ucontrol) |
| 2464 | { |
| 2465 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
| 2466 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2467 | |
| 2468 | wcd938x->hph_mode = ucontrol->value.enumerated.item[0]; |
| 2469 | |
| 2470 | return 1; |
| 2471 | } |
| 2472 | |
| 2473 | static int wcd938x_ear_pa_put_gain(struct snd_kcontrol *kcontrol, |
| 2474 | struct snd_ctl_elem_value *ucontrol) |
| 2475 | { |
| 2476 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
| 2477 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2478 | |
| 2479 | if (wcd938x->comp1_enable) { |
| 2480 | dev_err(component->dev, "Can not set EAR PA Gain, compander1 is enabled\n"); |
| 2481 | return -EINVAL; |
| 2482 | } |
| 2483 | |
| 2484 | snd_soc_component_write_field(component, WCD938X_ANA_EAR_COMPANDER_CTL, |
| 2485 | WCD938X_EAR_GAIN_MASK, |
| 2486 | ucontrol->value.integer.value[0]); |
| 2487 | |
| 2488 | return 0; |
| 2489 | } |
| 2490 | |
| 2491 | static int wcd938x_get_compander(struct snd_kcontrol *kcontrol, |
| 2492 | struct snd_ctl_elem_value *ucontrol) |
| 2493 | { |
| 2494 | |
| 2495 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
| 2496 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2497 | struct soc_mixer_control *mc; |
| 2498 | bool hphr; |
| 2499 | |
| 2500 | mc = (struct soc_mixer_control *)(kcontrol->private_value); |
| 2501 | hphr = mc->shift; |
| 2502 | |
| 2503 | if (hphr) |
| 2504 | ucontrol->value.integer.value[0] = wcd938x->comp2_enable; |
| 2505 | else |
| 2506 | ucontrol->value.integer.value[0] = wcd938x->comp1_enable; |
| 2507 | |
| 2508 | return 0; |
| 2509 | } |
| 2510 | |
| 2511 | static int wcd938x_set_compander(struct snd_kcontrol *kcontrol, |
| 2512 | struct snd_ctl_elem_value *ucontrol) |
| 2513 | { |
| 2514 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
| 2515 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2516 | struct wcd938x_sdw_priv *wcd; |
| 2517 | int value = ucontrol->value.integer.value[0]; |
| 2518 | struct soc_mixer_control *mc; |
| 2519 | bool hphr; |
| 2520 | |
| 2521 | mc = (struct soc_mixer_control *)(kcontrol->private_value); |
| 2522 | hphr = mc->shift; |
| 2523 | |
| 2524 | wcd = wcd938x->sdw_priv[AIF1_PB]; |
| 2525 | |
| 2526 | if (hphr) |
| 2527 | wcd938x->comp2_enable = value; |
| 2528 | else |
| 2529 | wcd938x->comp1_enable = value; |
| 2530 | |
| 2531 | if (value) |
| 2532 | wcd938x_connect_port(wcd, mc->reg, true); |
| 2533 | else |
| 2534 | wcd938x_connect_port(wcd, mc->reg, false); |
| 2535 | |
| 2536 | return 0; |
| 2537 | } |
| 2538 | |
| 2539 | static int wcd938x_ldoh_get(struct snd_kcontrol *kcontrol, |
| 2540 | struct snd_ctl_elem_value *ucontrol) |
| 2541 | { |
| 2542 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
| 2543 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2544 | |
| 2545 | ucontrol->value.integer.value[0] = wcd938x->ldoh; |
| 2546 | |
| 2547 | return 0; |
| 2548 | } |
| 2549 | |
| 2550 | static int wcd938x_ldoh_put(struct snd_kcontrol *kcontrol, |
| 2551 | struct snd_ctl_elem_value *ucontrol) |
| 2552 | { |
| 2553 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
| 2554 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2555 | |
| 2556 | wcd938x->ldoh = ucontrol->value.integer.value[0]; |
| 2557 | |
| 2558 | return 1; |
| 2559 | } |
| 2560 | |
| 2561 | static int wcd938x_bcs_get(struct snd_kcontrol *kcontrol, |
| 2562 | struct snd_ctl_elem_value *ucontrol) |
| 2563 | { |
| 2564 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
| 2565 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2566 | |
| 2567 | ucontrol->value.integer.value[0] = wcd938x->bcs_dis; |
| 2568 | |
| 2569 | return 0; |
| 2570 | } |
| 2571 | |
| 2572 | static int wcd938x_bcs_put(struct snd_kcontrol *kcontrol, |
| 2573 | struct snd_ctl_elem_value *ucontrol) |
| 2574 | { |
| 2575 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
| 2576 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 2577 | |
| 2578 | wcd938x->bcs_dis = ucontrol->value.integer.value[0]; |
| 2579 | |
| 2580 | return 1; |
| 2581 | } |
| 2582 | |
| 2583 | static const char * const tx_mode_mux_text_wcd9380[] = { |
| 2584 | "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP", |
| 2585 | }; |
| 2586 | |
| 2587 | static const char * const tx_mode_mux_text[] = { |
| 2588 | "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP", |
| 2589 | "ADC_ULP1", "ADC_ULP2", |
| 2590 | }; |
| 2591 | |
| 2592 | static const char * const rx_hph_mode_mux_text_wcd9380[] = { |
| 2593 | "CLS_H_INVALID", "CLS_H_INVALID_1", "CLS_H_LP", "CLS_AB", |
| 2594 | "CLS_H_LOHIFI", "CLS_H_ULP", "CLS_H_INVALID_2", "CLS_AB_LP", |
| 2595 | "CLS_AB_LOHIFI", |
| 2596 | }; |
| 2597 | |
| 2598 | static const char * const rx_hph_mode_mux_text[] = { |
| 2599 | "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI", |
| 2600 | "CLS_H_ULP", "CLS_AB_HIFI", "CLS_AB_LP", "CLS_AB_LOHIFI", |
| 2601 | }; |
| 2602 | |
Srinivas Kandagatla | 8da9db0 | 2021-06-09 10:09:41 +0100 | [diff] [blame] | 2603 | static const char * const adc2_mux_text[] = { |
| 2604 | "INP2", "INP3" |
| 2605 | }; |
| 2606 | |
| 2607 | static const char * const adc3_mux_text[] = { |
| 2608 | "INP4", "INP6" |
| 2609 | }; |
| 2610 | |
| 2611 | static const char * const adc4_mux_text[] = { |
| 2612 | "INP5", "INP7" |
| 2613 | }; |
| 2614 | |
| 2615 | static const char * const rdac3_mux_text[] = { |
| 2616 | "RX1", "RX3" |
| 2617 | }; |
| 2618 | |
| 2619 | static const char * const hdr12_mux_text[] = { |
| 2620 | "NO_HDR12", "HDR12" |
| 2621 | }; |
| 2622 | |
| 2623 | static const char * const hdr34_mux_text[] = { |
| 2624 | "NO_HDR34", "HDR34" |
| 2625 | }; |
| 2626 | |
Srinivas Kandagatla | e8ba1e0 | 2021-06-09 10:09:40 +0100 | [diff] [blame] | 2627 | static const struct soc_enum tx0_mode_enum_wcd9380 = |
| 2628 | SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, ARRAY_SIZE(tx_mode_mux_text_wcd9380), |
| 2629 | tx_mode_mux_text_wcd9380); |
| 2630 | |
| 2631 | static const struct soc_enum tx1_mode_enum_wcd9380 = |
| 2632 | SOC_ENUM_SINGLE(SND_SOC_NOPM, 1, ARRAY_SIZE(tx_mode_mux_text_wcd9380), |
| 2633 | tx_mode_mux_text_wcd9380); |
| 2634 | |
| 2635 | static const struct soc_enum tx2_mode_enum_wcd9380 = |
| 2636 | SOC_ENUM_SINGLE(SND_SOC_NOPM, 2, ARRAY_SIZE(tx_mode_mux_text_wcd9380), |
| 2637 | tx_mode_mux_text_wcd9380); |
| 2638 | |
| 2639 | static const struct soc_enum tx3_mode_enum_wcd9380 = |
| 2640 | SOC_ENUM_SINGLE(SND_SOC_NOPM, 3, ARRAY_SIZE(tx_mode_mux_text_wcd9380), |
| 2641 | tx_mode_mux_text_wcd9380); |
| 2642 | |
| 2643 | static const struct soc_enum tx0_mode_enum_wcd9385 = |
| 2644 | SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, ARRAY_SIZE(tx_mode_mux_text), |
| 2645 | tx_mode_mux_text); |
| 2646 | |
| 2647 | static const struct soc_enum tx1_mode_enum_wcd9385 = |
| 2648 | SOC_ENUM_SINGLE(SND_SOC_NOPM, 1, ARRAY_SIZE(tx_mode_mux_text), |
| 2649 | tx_mode_mux_text); |
| 2650 | |
| 2651 | static const struct soc_enum tx2_mode_enum_wcd9385 = |
| 2652 | SOC_ENUM_SINGLE(SND_SOC_NOPM, 2, ARRAY_SIZE(tx_mode_mux_text), |
| 2653 | tx_mode_mux_text); |
| 2654 | |
| 2655 | static const struct soc_enum tx3_mode_enum_wcd9385 = |
| 2656 | SOC_ENUM_SINGLE(SND_SOC_NOPM, 3, ARRAY_SIZE(tx_mode_mux_text), |
| 2657 | tx_mode_mux_text); |
| 2658 | |
| 2659 | static const struct soc_enum rx_hph_mode_mux_enum_wcd9380 = |
| 2660 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text_wcd9380), |
| 2661 | rx_hph_mode_mux_text_wcd9380); |
| 2662 | |
| 2663 | static const struct soc_enum rx_hph_mode_mux_enum = |
| 2664 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text), |
| 2665 | rx_hph_mode_mux_text); |
| 2666 | |
Srinivas Kandagatla | d5add08 | 2021-06-09 10:09:42 +0100 | [diff] [blame] | 2667 | static const struct soc_enum adc2_enum = |
| 2668 | SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 7, |
| 2669 | ARRAY_SIZE(adc2_mux_text), adc2_mux_text); |
| 2670 | |
| 2671 | static const struct soc_enum adc3_enum = |
| 2672 | SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 6, |
| 2673 | ARRAY_SIZE(adc3_mux_text), adc3_mux_text); |
| 2674 | |
| 2675 | static const struct soc_enum adc4_enum = |
| 2676 | SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 5, |
| 2677 | ARRAY_SIZE(adc4_mux_text), adc4_mux_text); |
| 2678 | |
| 2679 | static const struct soc_enum hdr12_enum = |
| 2680 | SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 4, |
| 2681 | ARRAY_SIZE(hdr12_mux_text), hdr12_mux_text); |
| 2682 | |
| 2683 | static const struct soc_enum hdr34_enum = |
| 2684 | SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 3, |
| 2685 | ARRAY_SIZE(hdr34_mux_text), hdr34_mux_text); |
| 2686 | |
Srinivas Kandagatla | 8da9db0 | 2021-06-09 10:09:41 +0100 | [diff] [blame] | 2687 | static const struct soc_enum rdac3_enum = |
| 2688 | SOC_ENUM_SINGLE(WCD938X_DIGITAL_CDC_EAR_PATH_CTL, 0, |
| 2689 | ARRAY_SIZE(rdac3_mux_text), rdac3_mux_text); |
| 2690 | |
Srinivas Kandagatla | d5add08 | 2021-06-09 10:09:42 +0100 | [diff] [blame] | 2691 | static const struct snd_kcontrol_new adc1_switch[] = { |
| 2692 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2693 | }; |
| 2694 | |
| 2695 | static const struct snd_kcontrol_new adc2_switch[] = { |
| 2696 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2697 | }; |
| 2698 | |
| 2699 | static const struct snd_kcontrol_new adc3_switch[] = { |
| 2700 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2701 | }; |
| 2702 | |
| 2703 | static const struct snd_kcontrol_new adc4_switch[] = { |
| 2704 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2705 | }; |
| 2706 | |
| 2707 | static const struct snd_kcontrol_new dmic1_switch[] = { |
| 2708 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2709 | }; |
| 2710 | |
| 2711 | static const struct snd_kcontrol_new dmic2_switch[] = { |
| 2712 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2713 | }; |
| 2714 | |
| 2715 | static const struct snd_kcontrol_new dmic3_switch[] = { |
| 2716 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2717 | }; |
| 2718 | |
| 2719 | static const struct snd_kcontrol_new dmic4_switch[] = { |
| 2720 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2721 | }; |
| 2722 | |
| 2723 | static const struct snd_kcontrol_new dmic5_switch[] = { |
| 2724 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2725 | }; |
| 2726 | |
| 2727 | static const struct snd_kcontrol_new dmic6_switch[] = { |
| 2728 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2729 | }; |
| 2730 | |
| 2731 | static const struct snd_kcontrol_new dmic7_switch[] = { |
| 2732 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2733 | }; |
| 2734 | |
| 2735 | static const struct snd_kcontrol_new dmic8_switch[] = { |
| 2736 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2737 | }; |
| 2738 | |
Srinivas Kandagatla | 8da9db0 | 2021-06-09 10:09:41 +0100 | [diff] [blame] | 2739 | static const struct snd_kcontrol_new ear_rdac_switch[] = { |
| 2740 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2741 | }; |
| 2742 | |
| 2743 | static const struct snd_kcontrol_new aux_rdac_switch[] = { |
| 2744 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2745 | }; |
| 2746 | |
| 2747 | static const struct snd_kcontrol_new hphl_rdac_switch[] = { |
| 2748 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2749 | }; |
| 2750 | |
| 2751 | static const struct snd_kcontrol_new hphr_rdac_switch[] = { |
| 2752 | SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) |
| 2753 | }; |
| 2754 | |
Srinivas Kandagatla | d5add08 | 2021-06-09 10:09:42 +0100 | [diff] [blame] | 2755 | static const struct snd_kcontrol_new tx_adc2_mux = |
| 2756 | SOC_DAPM_ENUM("ADC2 MUX Mux", adc2_enum); |
| 2757 | |
| 2758 | static const struct snd_kcontrol_new tx_adc3_mux = |
| 2759 | SOC_DAPM_ENUM("ADC3 MUX Mux", adc3_enum); |
| 2760 | |
| 2761 | static const struct snd_kcontrol_new tx_adc4_mux = |
| 2762 | SOC_DAPM_ENUM("ADC4 MUX Mux", adc4_enum); |
| 2763 | |
| 2764 | static const struct snd_kcontrol_new tx_hdr12_mux = |
| 2765 | SOC_DAPM_ENUM("HDR12 MUX Mux", hdr12_enum); |
| 2766 | |
| 2767 | static const struct snd_kcontrol_new tx_hdr34_mux = |
| 2768 | SOC_DAPM_ENUM("HDR34 MUX Mux", hdr34_enum); |
| 2769 | |
Srinivas Kandagatla | 8da9db0 | 2021-06-09 10:09:41 +0100 | [diff] [blame] | 2770 | static const struct snd_kcontrol_new rx_rdac3_mux = |
| 2771 | SOC_DAPM_ENUM("RDAC3_MUX Mux", rdac3_enum); |
| 2772 | |
Srinivas Kandagatla | e8ba1e0 | 2021-06-09 10:09:40 +0100 | [diff] [blame] | 2773 | static const struct snd_kcontrol_new wcd9380_snd_controls[] = { |
| 2774 | SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum_wcd9380, |
| 2775 | wcd938x_rx_hph_mode_get, wcd938x_rx_hph_mode_put), |
| 2776 | SOC_ENUM_EXT("TX0 MODE", tx0_mode_enum_wcd9380, |
| 2777 | wcd938x_tx_mode_get, wcd938x_tx_mode_put), |
| 2778 | SOC_ENUM_EXT("TX1 MODE", tx1_mode_enum_wcd9380, |
| 2779 | wcd938x_tx_mode_get, wcd938x_tx_mode_put), |
| 2780 | SOC_ENUM_EXT("TX2 MODE", tx2_mode_enum_wcd9380, |
| 2781 | wcd938x_tx_mode_get, wcd938x_tx_mode_put), |
| 2782 | SOC_ENUM_EXT("TX3 MODE", tx3_mode_enum_wcd9380, |
| 2783 | wcd938x_tx_mode_get, wcd938x_tx_mode_put), |
| 2784 | }; |
| 2785 | |
| 2786 | static const struct snd_kcontrol_new wcd9385_snd_controls[] = { |
| 2787 | SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum, |
| 2788 | wcd938x_rx_hph_mode_get, wcd938x_rx_hph_mode_put), |
| 2789 | SOC_ENUM_EXT("TX0 MODE", tx0_mode_enum_wcd9385, |
| 2790 | wcd938x_tx_mode_get, wcd938x_tx_mode_put), |
| 2791 | SOC_ENUM_EXT("TX1 MODE", tx1_mode_enum_wcd9385, |
| 2792 | wcd938x_tx_mode_get, wcd938x_tx_mode_put), |
| 2793 | SOC_ENUM_EXT("TX2 MODE", tx2_mode_enum_wcd9385, |
| 2794 | wcd938x_tx_mode_get, wcd938x_tx_mode_put), |
| 2795 | SOC_ENUM_EXT("TX3 MODE", tx3_mode_enum_wcd9385, |
| 2796 | wcd938x_tx_mode_get, wcd938x_tx_mode_put), |
| 2797 | }; |
| 2798 | |
| 2799 | static int wcd938x_get_swr_port(struct snd_kcontrol *kcontrol, |
| 2800 | struct snd_ctl_elem_value *ucontrol) |
| 2801 | { |
| 2802 | struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); |
| 2803 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(comp); |
| 2804 | struct wcd938x_sdw_priv *wcd; |
| 2805 | struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; |
| 2806 | int dai_id = mixer->shift; |
| 2807 | int portidx = mixer->reg; |
| 2808 | |
| 2809 | wcd = wcd938x->sdw_priv[dai_id]; |
| 2810 | |
| 2811 | ucontrol->value.integer.value[0] = wcd->port_enable[portidx]; |
| 2812 | |
| 2813 | return 0; |
| 2814 | } |
| 2815 | |
| 2816 | static int wcd938x_set_swr_port(struct snd_kcontrol *kcontrol, |
| 2817 | struct snd_ctl_elem_value *ucontrol) |
| 2818 | { |
| 2819 | struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); |
| 2820 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(comp); |
| 2821 | struct wcd938x_sdw_priv *wcd; |
| 2822 | struct soc_mixer_control *mixer = |
| 2823 | (struct soc_mixer_control *)kcontrol->private_value; |
| 2824 | int portidx = mixer->reg; |
| 2825 | int dai_id = mixer->shift; |
| 2826 | bool enable; |
| 2827 | |
| 2828 | wcd = wcd938x->sdw_priv[dai_id]; |
| 2829 | |
| 2830 | if (ucontrol->value.integer.value[0]) |
| 2831 | enable = true; |
| 2832 | else |
| 2833 | enable = false; |
| 2834 | |
| 2835 | wcd->port_enable[portidx] = enable; |
| 2836 | |
| 2837 | wcd938x_connect_port(wcd, portidx, enable); |
| 2838 | |
| 2839 | return 0; |
| 2840 | |
| 2841 | } |
| 2842 | |
| 2843 | static const struct snd_kcontrol_new wcd938x_snd_controls[] = { |
| 2844 | SOC_SINGLE_EXT("HPHL_COMP Switch", WCD938X_COMP_L, 0, 1, 0, |
| 2845 | wcd938x_get_compander, wcd938x_set_compander), |
| 2846 | SOC_SINGLE_EXT("HPHR_COMP Switch", WCD938X_COMP_R, 1, 1, 0, |
| 2847 | wcd938x_get_compander, wcd938x_set_compander), |
| 2848 | SOC_SINGLE_EXT("HPHL Switch", WCD938X_HPH_L, 0, 1, 0, |
| 2849 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2850 | SOC_SINGLE_EXT("HPHR Switch", WCD938X_HPH_R, 0, 1, 0, |
| 2851 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2852 | SOC_SINGLE_EXT("CLSH Switch", WCD938X_CLSH, 0, 1, 0, |
| 2853 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2854 | SOC_SINGLE_EXT("LO Switch", WCD938X_LO, 0, 1, 0, |
| 2855 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2856 | SOC_SINGLE_EXT("DSD_L Switch", WCD938X_DSD_L, 0, 1, 0, |
| 2857 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2858 | SOC_SINGLE_EXT("DSD_R Switch", WCD938X_DSD_R, 0, 1, 0, |
| 2859 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2860 | SOC_SINGLE_TLV("HPHL Volume", WCD938X_HPH_L_EN, 0, 0x18, 0, line_gain), |
| 2861 | SOC_SINGLE_TLV("HPHR Volume", WCD938X_HPH_R_EN, 0, 0x18, 0, line_gain), |
| 2862 | WCD938X_EAR_PA_GAIN_TLV("EAR_PA Volume", WCD938X_ANA_EAR_COMPANDER_CTL, |
| 2863 | 2, 0x10, 0, ear_pa_gain), |
| 2864 | SOC_SINGLE_EXT("ADC1 Switch", WCD938X_ADC1, 1, 1, 0, |
| 2865 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2866 | SOC_SINGLE_EXT("ADC2 Switch", WCD938X_ADC2, 1, 1, 0, |
| 2867 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2868 | SOC_SINGLE_EXT("ADC3 Switch", WCD938X_ADC3, 1, 1, 0, |
| 2869 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2870 | SOC_SINGLE_EXT("ADC4 Switch", WCD938X_ADC4, 1, 1, 0, |
| 2871 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2872 | SOC_SINGLE_EXT("DMIC0 Switch", WCD938X_DMIC0, 1, 1, 0, |
| 2873 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2874 | SOC_SINGLE_EXT("DMIC1 Switch", WCD938X_DMIC1, 1, 1, 0, |
| 2875 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2876 | SOC_SINGLE_EXT("MBHC Switch", WCD938X_MBHC, 1, 1, 0, |
| 2877 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2878 | SOC_SINGLE_EXT("DMIC2 Switch", WCD938X_DMIC2, 1, 1, 0, |
| 2879 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2880 | SOC_SINGLE_EXT("DMIC3 Switch", WCD938X_DMIC3, 1, 1, 0, |
| 2881 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2882 | SOC_SINGLE_EXT("DMIC4 Switch", WCD938X_DMIC4, 1, 1, 0, |
| 2883 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2884 | SOC_SINGLE_EXT("DMIC5 Switch", WCD938X_DMIC5, 1, 1, 0, |
| 2885 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2886 | SOC_SINGLE_EXT("DMIC6 Switch", WCD938X_DMIC6, 1, 1, 0, |
| 2887 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2888 | SOC_SINGLE_EXT("DMIC7 Switch", WCD938X_DMIC7, 1, 1, 0, |
| 2889 | wcd938x_get_swr_port, wcd938x_set_swr_port), |
| 2890 | SOC_SINGLE_EXT("LDOH Enable Switch", SND_SOC_NOPM, 0, 1, 0, |
| 2891 | wcd938x_ldoh_get, wcd938x_ldoh_put), |
| 2892 | SOC_SINGLE_EXT("ADC2_BCS Disable Switch", SND_SOC_NOPM, 0, 1, 0, |
| 2893 | wcd938x_bcs_get, wcd938x_bcs_put), |
| 2894 | |
| 2895 | SOC_SINGLE_TLV("ADC1 Volume", WCD938X_ANA_TX_CH1, 0, 20, 0, analog_gain), |
| 2896 | SOC_SINGLE_TLV("ADC2 Volume", WCD938X_ANA_TX_CH2, 0, 20, 0, analog_gain), |
| 2897 | SOC_SINGLE_TLV("ADC3 Volume", WCD938X_ANA_TX_CH3, 0, 20, 0, analog_gain), |
| 2898 | SOC_SINGLE_TLV("ADC4 Volume", WCD938X_ANA_TX_CH4, 0, 20, 0, analog_gain), |
| 2899 | }; |
| 2900 | |
Srinivas Kandagatla | 8da9db0 | 2021-06-09 10:09:41 +0100 | [diff] [blame] | 2901 | static const struct snd_soc_dapm_widget wcd938x_dapm_widgets[] = { |
Srinivas Kandagatla | d5add08 | 2021-06-09 10:09:42 +0100 | [diff] [blame] | 2902 | |
| 2903 | /*input widgets*/ |
| 2904 | SND_SOC_DAPM_INPUT("AMIC1"), |
| 2905 | SND_SOC_DAPM_INPUT("AMIC2"), |
| 2906 | SND_SOC_DAPM_INPUT("AMIC3"), |
| 2907 | SND_SOC_DAPM_INPUT("AMIC4"), |
| 2908 | SND_SOC_DAPM_INPUT("AMIC5"), |
| 2909 | SND_SOC_DAPM_INPUT("AMIC6"), |
| 2910 | SND_SOC_DAPM_INPUT("AMIC7"), |
| 2911 | SND_SOC_DAPM_MIC("Analog Mic1", NULL), |
| 2912 | SND_SOC_DAPM_MIC("Analog Mic2", NULL), |
| 2913 | SND_SOC_DAPM_MIC("Analog Mic3", NULL), |
| 2914 | SND_SOC_DAPM_MIC("Analog Mic4", NULL), |
| 2915 | SND_SOC_DAPM_MIC("Analog Mic5", NULL), |
| 2916 | |
| 2917 | /*tx widgets*/ |
| 2918 | SND_SOC_DAPM_ADC_E("ADC1", NULL, SND_SOC_NOPM, 0, 0, |
| 2919 | wcd938x_codec_enable_adc, |
| 2920 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2921 | SND_SOC_DAPM_ADC_E("ADC2", NULL, SND_SOC_NOPM, 1, 0, |
| 2922 | wcd938x_codec_enable_adc, |
| 2923 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2924 | SND_SOC_DAPM_ADC_E("ADC3", NULL, SND_SOC_NOPM, 2, 0, |
| 2925 | wcd938x_codec_enable_adc, |
| 2926 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2927 | SND_SOC_DAPM_ADC_E("ADC4", NULL, SND_SOC_NOPM, 3, 0, |
| 2928 | wcd938x_codec_enable_adc, |
| 2929 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2930 | SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0, |
| 2931 | wcd938x_codec_enable_dmic, |
| 2932 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2933 | SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 1, 0, |
| 2934 | wcd938x_codec_enable_dmic, |
| 2935 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2936 | SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 2, 0, |
| 2937 | wcd938x_codec_enable_dmic, |
| 2938 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2939 | SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 3, 0, |
| 2940 | wcd938x_codec_enable_dmic, |
| 2941 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2942 | SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 4, 0, |
| 2943 | wcd938x_codec_enable_dmic, |
| 2944 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2945 | SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 5, 0, |
| 2946 | wcd938x_codec_enable_dmic, |
| 2947 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2948 | SND_SOC_DAPM_ADC_E("DMIC7", NULL, SND_SOC_NOPM, 6, 0, |
| 2949 | wcd938x_codec_enable_dmic, |
| 2950 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2951 | SND_SOC_DAPM_ADC_E("DMIC8", NULL, SND_SOC_NOPM, 7, 0, |
| 2952 | wcd938x_codec_enable_dmic, |
| 2953 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2954 | |
| 2955 | SND_SOC_DAPM_MIXER_E("ADC1 REQ", SND_SOC_NOPM, 0, 0, |
| 2956 | NULL, 0, wcd938x_adc_enable_req, |
| 2957 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2958 | SND_SOC_DAPM_MIXER_E("ADC2 REQ", SND_SOC_NOPM, 1, 0, |
| 2959 | NULL, 0, wcd938x_adc_enable_req, |
| 2960 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2961 | SND_SOC_DAPM_MIXER_E("ADC3 REQ", SND_SOC_NOPM, 2, 0, |
| 2962 | NULL, 0, wcd938x_adc_enable_req, |
| 2963 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2964 | SND_SOC_DAPM_MIXER_E("ADC4 REQ", SND_SOC_NOPM, 3, 0, NULL, 0, |
| 2965 | wcd938x_adc_enable_req, |
| 2966 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2967 | |
| 2968 | SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0, &tx_adc2_mux), |
| 2969 | SND_SOC_DAPM_MUX("ADC3 MUX", SND_SOC_NOPM, 0, 0, &tx_adc3_mux), |
| 2970 | SND_SOC_DAPM_MUX("ADC4 MUX", SND_SOC_NOPM, 0, 0, &tx_adc4_mux), |
| 2971 | SND_SOC_DAPM_MUX("HDR12 MUX", SND_SOC_NOPM, 0, 0, &tx_hdr12_mux), |
| 2972 | SND_SOC_DAPM_MUX("HDR34 MUX", SND_SOC_NOPM, 0, 0, &tx_hdr34_mux), |
| 2973 | |
| 2974 | /*tx mixers*/ |
| 2975 | SND_SOC_DAPM_MIXER_E("ADC1_MIXER", SND_SOC_NOPM, 0, 0, adc1_switch, |
| 2976 | ARRAY_SIZE(adc1_switch), wcd938x_tx_swr_ctrl, |
| 2977 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2978 | SND_SOC_DAPM_MIXER_E("ADC2_MIXER", SND_SOC_NOPM, 0, 0, adc2_switch, |
| 2979 | ARRAY_SIZE(adc2_switch), wcd938x_tx_swr_ctrl, |
| 2980 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2981 | SND_SOC_DAPM_MIXER_E("ADC3_MIXER", SND_SOC_NOPM, 0, 0, adc3_switch, |
| 2982 | ARRAY_SIZE(adc3_switch), wcd938x_tx_swr_ctrl, |
| 2983 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2984 | SND_SOC_DAPM_MIXER_E("ADC4_MIXER", SND_SOC_NOPM, 0, 0, adc4_switch, |
| 2985 | ARRAY_SIZE(adc4_switch), wcd938x_tx_swr_ctrl, |
| 2986 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2987 | SND_SOC_DAPM_MIXER_E("DMIC1_MIXER", SND_SOC_NOPM, 0, 0, dmic1_switch, |
| 2988 | ARRAY_SIZE(dmic1_switch), wcd938x_tx_swr_ctrl, |
| 2989 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2990 | SND_SOC_DAPM_MIXER_E("DMIC2_MIXER", SND_SOC_NOPM, 0, 0, dmic2_switch, |
| 2991 | ARRAY_SIZE(dmic2_switch), wcd938x_tx_swr_ctrl, |
| 2992 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2993 | SND_SOC_DAPM_MIXER_E("DMIC3_MIXER", SND_SOC_NOPM, 0, 0, dmic3_switch, |
| 2994 | ARRAY_SIZE(dmic3_switch), wcd938x_tx_swr_ctrl, |
| 2995 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2996 | SND_SOC_DAPM_MIXER_E("DMIC4_MIXER", SND_SOC_NOPM, 0, 0, dmic4_switch, |
| 2997 | ARRAY_SIZE(dmic4_switch), wcd938x_tx_swr_ctrl, |
| 2998 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 2999 | SND_SOC_DAPM_MIXER_E("DMIC5_MIXER", SND_SOC_NOPM, 0, 0, dmic5_switch, |
| 3000 | ARRAY_SIZE(dmic5_switch), wcd938x_tx_swr_ctrl, |
| 3001 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 3002 | SND_SOC_DAPM_MIXER_E("DMIC6_MIXER", SND_SOC_NOPM, 0, 0, dmic6_switch, |
| 3003 | ARRAY_SIZE(dmic6_switch), wcd938x_tx_swr_ctrl, |
| 3004 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 3005 | SND_SOC_DAPM_MIXER_E("DMIC7_MIXER", SND_SOC_NOPM, 0, 0, dmic7_switch, |
| 3006 | ARRAY_SIZE(dmic7_switch), wcd938x_tx_swr_ctrl, |
| 3007 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 3008 | SND_SOC_DAPM_MIXER_E("DMIC8_MIXER", SND_SOC_NOPM, 0, 0, dmic8_switch, |
| 3009 | ARRAY_SIZE(dmic8_switch), wcd938x_tx_swr_ctrl, |
| 3010 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 3011 | /* micbias widgets*/ |
| 3012 | SND_SOC_DAPM_SUPPLY("MIC BIAS1", SND_SOC_NOPM, MIC_BIAS_1, 0, |
| 3013 | wcd938x_codec_enable_micbias, |
| 3014 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3015 | SND_SOC_DAPM_POST_PMD), |
| 3016 | SND_SOC_DAPM_SUPPLY("MIC BIAS2", SND_SOC_NOPM, MIC_BIAS_2, 0, |
| 3017 | wcd938x_codec_enable_micbias, |
| 3018 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3019 | SND_SOC_DAPM_POST_PMD), |
| 3020 | SND_SOC_DAPM_SUPPLY("MIC BIAS3", SND_SOC_NOPM, MIC_BIAS_3, 0, |
| 3021 | wcd938x_codec_enable_micbias, |
| 3022 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3023 | SND_SOC_DAPM_POST_PMD), |
| 3024 | SND_SOC_DAPM_SUPPLY("MIC BIAS4", SND_SOC_NOPM, MIC_BIAS_4, 0, |
| 3025 | wcd938x_codec_enable_micbias, |
| 3026 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3027 | SND_SOC_DAPM_POST_PMD), |
| 3028 | |
| 3029 | /* micbias pull up widgets*/ |
| 3030 | SND_SOC_DAPM_SUPPLY("VA MIC BIAS1", SND_SOC_NOPM, MIC_BIAS_1, 0, |
| 3031 | wcd938x_codec_enable_micbias_pullup, |
| 3032 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3033 | SND_SOC_DAPM_POST_PMD), |
| 3034 | SND_SOC_DAPM_SUPPLY("VA MIC BIAS2", SND_SOC_NOPM, MIC_BIAS_2, 0, |
| 3035 | wcd938x_codec_enable_micbias_pullup, |
| 3036 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3037 | SND_SOC_DAPM_POST_PMD), |
| 3038 | SND_SOC_DAPM_SUPPLY("VA MIC BIAS3", SND_SOC_NOPM, MIC_BIAS_3, 0, |
| 3039 | wcd938x_codec_enable_micbias_pullup, |
| 3040 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3041 | SND_SOC_DAPM_POST_PMD), |
| 3042 | SND_SOC_DAPM_SUPPLY("VA MIC BIAS4", SND_SOC_NOPM, MIC_BIAS_4, 0, |
| 3043 | wcd938x_codec_enable_micbias_pullup, |
| 3044 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3045 | SND_SOC_DAPM_POST_PMD), |
| 3046 | |
| 3047 | /*output widgets tx*/ |
| 3048 | SND_SOC_DAPM_OUTPUT("ADC1_OUTPUT"), |
| 3049 | SND_SOC_DAPM_OUTPUT("ADC2_OUTPUT"), |
| 3050 | SND_SOC_DAPM_OUTPUT("ADC3_OUTPUT"), |
| 3051 | SND_SOC_DAPM_OUTPUT("ADC4_OUTPUT"), |
| 3052 | SND_SOC_DAPM_OUTPUT("DMIC1_OUTPUT"), |
| 3053 | SND_SOC_DAPM_OUTPUT("DMIC2_OUTPUT"), |
| 3054 | SND_SOC_DAPM_OUTPUT("DMIC3_OUTPUT"), |
| 3055 | SND_SOC_DAPM_OUTPUT("DMIC4_OUTPUT"), |
| 3056 | SND_SOC_DAPM_OUTPUT("DMIC5_OUTPUT"), |
| 3057 | SND_SOC_DAPM_OUTPUT("DMIC6_OUTPUT"), |
| 3058 | SND_SOC_DAPM_OUTPUT("DMIC7_OUTPUT"), |
| 3059 | SND_SOC_DAPM_OUTPUT("DMIC8_OUTPUT"), |
| 3060 | |
Srinivas Kandagatla | 8da9db0 | 2021-06-09 10:09:41 +0100 | [diff] [blame] | 3061 | SND_SOC_DAPM_INPUT("IN1_HPHL"), |
| 3062 | SND_SOC_DAPM_INPUT("IN2_HPHR"), |
| 3063 | SND_SOC_DAPM_INPUT("IN3_AUX"), |
| 3064 | |
| 3065 | /*rx widgets*/ |
| 3066 | SND_SOC_DAPM_PGA_E("EAR PGA", WCD938X_ANA_EAR, 7, 0, NULL, 0, |
| 3067 | wcd938x_codec_enable_ear_pa, |
| 3068 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3069 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 3070 | SND_SOC_DAPM_PGA_E("AUX PGA", WCD938X_AUX_AUXPA, 7, 0, NULL, 0, |
| 3071 | wcd938x_codec_enable_aux_pa, |
| 3072 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3073 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 3074 | SND_SOC_DAPM_PGA_E("HPHL PGA", WCD938X_ANA_HPH, 7, 0, NULL, 0, |
| 3075 | wcd938x_codec_enable_hphl_pa, |
| 3076 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3077 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 3078 | SND_SOC_DAPM_PGA_E("HPHR PGA", WCD938X_ANA_HPH, 6, 0, NULL, 0, |
| 3079 | wcd938x_codec_enable_hphr_pa, |
| 3080 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3081 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 3082 | |
| 3083 | SND_SOC_DAPM_DAC_E("RDAC1", NULL, SND_SOC_NOPM, 0, 0, |
| 3084 | wcd938x_codec_hphl_dac_event, |
| 3085 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3086 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 3087 | SND_SOC_DAPM_DAC_E("RDAC2", NULL, SND_SOC_NOPM, 0, 0, |
| 3088 | wcd938x_codec_hphr_dac_event, |
| 3089 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3090 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 3091 | SND_SOC_DAPM_DAC_E("RDAC3", NULL, SND_SOC_NOPM, 0, 0, |
| 3092 | wcd938x_codec_ear_dac_event, |
| 3093 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3094 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 3095 | SND_SOC_DAPM_DAC_E("RDAC4", NULL, SND_SOC_NOPM, 0, 0, |
| 3096 | wcd938x_codec_aux_dac_event, |
| 3097 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3098 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 3099 | |
| 3100 | SND_SOC_DAPM_MUX("RDAC3_MUX", SND_SOC_NOPM, 0, 0, &rx_rdac3_mux), |
| 3101 | |
| 3102 | SND_SOC_DAPM_SUPPLY("VDD_BUCK", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 3103 | SND_SOC_DAPM_SUPPLY("RXCLK", SND_SOC_NOPM, 0, 0, |
| 3104 | wcd938x_codec_enable_rxclk, |
| 3105 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3106 | SND_SOC_DAPM_POST_PMD), |
| 3107 | |
| 3108 | SND_SOC_DAPM_SUPPLY_S("CLS_H_PORT", 1, SND_SOC_NOPM, 0, 0, NULL, 0), |
| 3109 | |
| 3110 | SND_SOC_DAPM_MIXER_E("RX1", SND_SOC_NOPM, 0, 0, NULL, 0, NULL, 0), |
| 3111 | SND_SOC_DAPM_MIXER_E("RX2", SND_SOC_NOPM, 0, 0, NULL, 0, NULL, 0), |
| 3112 | SND_SOC_DAPM_MIXER_E("RX3", SND_SOC_NOPM, 0, 0, NULL, 0, NULL, 0), |
| 3113 | |
| 3114 | /* rx mixer widgets*/ |
| 3115 | SND_SOC_DAPM_MIXER("EAR_RDAC", SND_SOC_NOPM, 0, 0, |
| 3116 | ear_rdac_switch, ARRAY_SIZE(ear_rdac_switch)), |
| 3117 | SND_SOC_DAPM_MIXER("AUX_RDAC", SND_SOC_NOPM, 0, 0, |
| 3118 | aux_rdac_switch, ARRAY_SIZE(aux_rdac_switch)), |
| 3119 | SND_SOC_DAPM_MIXER("HPHL_RDAC", SND_SOC_NOPM, 0, 0, |
| 3120 | hphl_rdac_switch, ARRAY_SIZE(hphl_rdac_switch)), |
| 3121 | SND_SOC_DAPM_MIXER("HPHR_RDAC", SND_SOC_NOPM, 0, 0, |
| 3122 | hphr_rdac_switch, ARRAY_SIZE(hphr_rdac_switch)), |
| 3123 | |
| 3124 | /*output widgets rx*/ |
| 3125 | SND_SOC_DAPM_OUTPUT("EAR"), |
| 3126 | SND_SOC_DAPM_OUTPUT("AUX"), |
| 3127 | SND_SOC_DAPM_OUTPUT("HPHL"), |
| 3128 | SND_SOC_DAPM_OUTPUT("HPHR"), |
Srinivas Kandagatla | 0454422 | 2021-06-09 10:09:43 +0100 | [diff] [blame] | 3129 | |
| 3130 | }; |
| 3131 | |
| 3132 | static const struct snd_soc_dapm_route wcd938x_audio_map[] = { |
| 3133 | {"ADC1_OUTPUT", NULL, "ADC1_MIXER"}, |
| 3134 | {"ADC1_MIXER", "Switch", "ADC1 REQ"}, |
| 3135 | {"ADC1 REQ", NULL, "ADC1"}, |
| 3136 | {"ADC1", NULL, "AMIC1"}, |
| 3137 | |
| 3138 | {"ADC2_OUTPUT", NULL, "ADC2_MIXER"}, |
| 3139 | {"ADC2_MIXER", "Switch", "ADC2 REQ"}, |
| 3140 | {"ADC2 REQ", NULL, "ADC2"}, |
| 3141 | {"ADC2", NULL, "HDR12 MUX"}, |
| 3142 | {"HDR12 MUX", "NO_HDR12", "ADC2 MUX"}, |
| 3143 | {"HDR12 MUX", "HDR12", "AMIC1"}, |
| 3144 | {"ADC2 MUX", "INP3", "AMIC3"}, |
| 3145 | {"ADC2 MUX", "INP2", "AMIC2"}, |
| 3146 | |
| 3147 | {"ADC3_OUTPUT", NULL, "ADC3_MIXER"}, |
| 3148 | {"ADC3_MIXER", "Switch", "ADC3 REQ"}, |
| 3149 | {"ADC3 REQ", NULL, "ADC3"}, |
| 3150 | {"ADC3", NULL, "HDR34 MUX"}, |
| 3151 | {"HDR34 MUX", "NO_HDR34", "ADC3 MUX"}, |
| 3152 | {"HDR34 MUX", "HDR34", "AMIC5"}, |
| 3153 | {"ADC3 MUX", "INP4", "AMIC4"}, |
| 3154 | {"ADC3 MUX", "INP6", "AMIC6"}, |
| 3155 | |
| 3156 | {"ADC4_OUTPUT", NULL, "ADC4_MIXER"}, |
| 3157 | {"ADC4_MIXER", "Switch", "ADC4 REQ"}, |
| 3158 | {"ADC4 REQ", NULL, "ADC4"}, |
| 3159 | {"ADC4", NULL, "ADC4 MUX"}, |
| 3160 | {"ADC4 MUX", "INP5", "AMIC5"}, |
| 3161 | {"ADC4 MUX", "INP7", "AMIC7"}, |
| 3162 | |
| 3163 | {"DMIC1_OUTPUT", NULL, "DMIC1_MIXER"}, |
| 3164 | {"DMIC1_MIXER", "Switch", "DMIC1"}, |
| 3165 | |
| 3166 | {"DMIC2_OUTPUT", NULL, "DMIC2_MIXER"}, |
| 3167 | {"DMIC2_MIXER", "Switch", "DMIC2"}, |
| 3168 | |
| 3169 | {"DMIC3_OUTPUT", NULL, "DMIC3_MIXER"}, |
| 3170 | {"DMIC3_MIXER", "Switch", "DMIC3"}, |
| 3171 | |
| 3172 | {"DMIC4_OUTPUT", NULL, "DMIC4_MIXER"}, |
| 3173 | {"DMIC4_MIXER", "Switch", "DMIC4"}, |
| 3174 | |
| 3175 | {"DMIC5_OUTPUT", NULL, "DMIC5_MIXER"}, |
| 3176 | {"DMIC5_MIXER", "Switch", "DMIC5"}, |
| 3177 | |
| 3178 | {"DMIC6_OUTPUT", NULL, "DMIC6_MIXER"}, |
| 3179 | {"DMIC6_MIXER", "Switch", "DMIC6"}, |
| 3180 | |
| 3181 | {"DMIC7_OUTPUT", NULL, "DMIC7_MIXER"}, |
| 3182 | {"DMIC7_MIXER", "Switch", "DMIC7"}, |
| 3183 | |
| 3184 | {"DMIC8_OUTPUT", NULL, "DMIC8_MIXER"}, |
| 3185 | {"DMIC8_MIXER", "Switch", "DMIC8"}, |
| 3186 | |
| 3187 | {"IN1_HPHL", NULL, "VDD_BUCK"}, |
| 3188 | {"IN1_HPHL", NULL, "CLS_H_PORT"}, |
| 3189 | |
| 3190 | {"RX1", NULL, "IN1_HPHL"}, |
| 3191 | {"RX1", NULL, "RXCLK"}, |
| 3192 | {"RDAC1", NULL, "RX1"}, |
| 3193 | {"HPHL_RDAC", "Switch", "RDAC1"}, |
| 3194 | {"HPHL PGA", NULL, "HPHL_RDAC"}, |
| 3195 | {"HPHL", NULL, "HPHL PGA"}, |
| 3196 | |
| 3197 | {"IN2_HPHR", NULL, "VDD_BUCK"}, |
| 3198 | {"IN2_HPHR", NULL, "CLS_H_PORT"}, |
| 3199 | {"RX2", NULL, "IN2_HPHR"}, |
| 3200 | {"RDAC2", NULL, "RX2"}, |
| 3201 | {"RX2", NULL, "RXCLK"}, |
| 3202 | {"HPHR_RDAC", "Switch", "RDAC2"}, |
| 3203 | {"HPHR PGA", NULL, "HPHR_RDAC"}, |
| 3204 | {"HPHR", NULL, "HPHR PGA"}, |
| 3205 | |
| 3206 | {"IN3_AUX", NULL, "VDD_BUCK"}, |
| 3207 | {"IN3_AUX", NULL, "CLS_H_PORT"}, |
| 3208 | {"RX3", NULL, "IN3_AUX"}, |
| 3209 | {"RDAC4", NULL, "RX3"}, |
| 3210 | {"RX3", NULL, "RXCLK"}, |
| 3211 | {"AUX_RDAC", "Switch", "RDAC4"}, |
| 3212 | {"AUX PGA", NULL, "AUX_RDAC"}, |
| 3213 | {"AUX", NULL, "AUX PGA"}, |
| 3214 | |
| 3215 | {"RDAC3_MUX", "RX3", "RX3"}, |
| 3216 | {"RDAC3_MUX", "RX1", "RX1"}, |
| 3217 | {"RDAC3", NULL, "RDAC3_MUX"}, |
| 3218 | {"EAR_RDAC", "Switch", "RDAC3"}, |
| 3219 | {"EAR PGA", NULL, "EAR_RDAC"}, |
| 3220 | {"EAR", NULL, "EAR PGA"}, |
Srinivas Kandagatla | 8da9db0 | 2021-06-09 10:09:41 +0100 | [diff] [blame] | 3221 | }; |
| 3222 | |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 3223 | static int wcd938x_get_micb_vout_ctl_val(u32 micb_mv) |
| 3224 | { |
| 3225 | /* min micbias voltage is 1V and maximum is 2.85V */ |
| 3226 | if (micb_mv < 1000 || micb_mv > 2850) |
| 3227 | return -EINVAL; |
| 3228 | |
| 3229 | return (micb_mv - 1000) / 50; |
| 3230 | } |
| 3231 | |
| 3232 | static int wcd938x_set_micbias_data(struct wcd938x_priv *wcd938x) |
| 3233 | { |
| 3234 | int vout_ctl_1, vout_ctl_2, vout_ctl_3, vout_ctl_4; |
| 3235 | |
| 3236 | /* set micbias voltage */ |
| 3237 | vout_ctl_1 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb1_mv); |
| 3238 | vout_ctl_2 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb2_mv); |
| 3239 | vout_ctl_3 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb3_mv); |
| 3240 | vout_ctl_4 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb4_mv); |
| 3241 | if (vout_ctl_1 < 0 || vout_ctl_2 < 0 || vout_ctl_3 < 0 || vout_ctl_4 < 0) |
| 3242 | return -EINVAL; |
| 3243 | |
| 3244 | regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB1, |
| 3245 | WCD938X_MICB_VOUT_MASK, vout_ctl_1); |
| 3246 | regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB2, |
| 3247 | WCD938X_MICB_VOUT_MASK, vout_ctl_2); |
| 3248 | regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB3, |
| 3249 | WCD938X_MICB_VOUT_MASK, vout_ctl_3); |
| 3250 | regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB4, |
| 3251 | WCD938X_MICB_VOUT_MASK, vout_ctl_4); |
| 3252 | |
| 3253 | return 0; |
| 3254 | } |
| 3255 | |
| 3256 | static irqreturn_t wcd938x_wd_handle_irq(int irq, void *data) |
| 3257 | { |
| 3258 | return IRQ_HANDLED; |
| 3259 | } |
| 3260 | |
| 3261 | static struct irq_chip wcd_irq_chip = { |
| 3262 | .name = "WCD938x", |
| 3263 | }; |
| 3264 | |
| 3265 | static int wcd_irq_chip_map(struct irq_domain *irqd, unsigned int virq, |
| 3266 | irq_hw_number_t hw) |
| 3267 | { |
| 3268 | irq_set_chip_and_handler(virq, &wcd_irq_chip, handle_simple_irq); |
| 3269 | irq_set_nested_thread(virq, 1); |
| 3270 | irq_set_noprobe(virq); |
| 3271 | |
| 3272 | return 0; |
| 3273 | } |
| 3274 | |
| 3275 | static const struct irq_domain_ops wcd_domain_ops = { |
| 3276 | .map = wcd_irq_chip_map, |
| 3277 | }; |
| 3278 | |
| 3279 | static int wcd938x_irq_init(struct wcd938x_priv *wcd, struct device *dev) |
| 3280 | { |
| 3281 | |
| 3282 | wcd->virq = irq_domain_add_linear(NULL, 1, &wcd_domain_ops, NULL); |
| 3283 | if (!(wcd->virq)) { |
| 3284 | dev_err(dev, "%s: Failed to add IRQ domain\n", __func__); |
| 3285 | return -EINVAL; |
| 3286 | } |
| 3287 | |
| 3288 | return devm_regmap_add_irq_chip(dev, wcd->regmap, |
| 3289 | irq_create_mapping(wcd->virq, 0), |
| 3290 | IRQF_ONESHOT, 0, &wcd938x_regmap_irq_chip, |
| 3291 | &wcd->irq_chip); |
| 3292 | } |
| 3293 | |
| 3294 | static int wcd938x_soc_codec_probe(struct snd_soc_component *component) |
| 3295 | { |
| 3296 | struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component); |
| 3297 | struct device *dev = component->dev; |
| 3298 | int ret, i; |
| 3299 | |
| 3300 | snd_soc_component_init_regmap(component, wcd938x->regmap); |
| 3301 | |
| 3302 | wcd938x->variant = snd_soc_component_read_field(component, |
| 3303 | WCD938X_DIGITAL_EFUSE_REG_0, |
| 3304 | WCD938X_ID_MASK); |
| 3305 | |
| 3306 | wcd938x->clsh_info = wcd_clsh_ctrl_alloc(component, WCD938X); |
| 3307 | |
| 3308 | wcd938x_io_init(wcd938x); |
| 3309 | /* Set all interrupts as edge triggered */ |
| 3310 | for (i = 0; i < wcd938x_regmap_irq_chip.num_regs; i++) { |
| 3311 | regmap_write(wcd938x->regmap, |
| 3312 | (WCD938X_DIGITAL_INTR_LEVEL_0 + i), 0); |
| 3313 | } |
| 3314 | |
| 3315 | ret = wcd938x_irq_init(wcd938x, component->dev); |
| 3316 | if (ret) { |
| 3317 | dev_err(component->dev, "%s: IRQ init failed: %d\n", |
| 3318 | __func__, ret); |
| 3319 | return ret; |
| 3320 | } |
| 3321 | |
| 3322 | wcd938x->hphr_pdm_wd_int = regmap_irq_get_virq(wcd938x->irq_chip, |
| 3323 | WCD938X_IRQ_HPHR_PDM_WD_INT); |
| 3324 | wcd938x->hphl_pdm_wd_int = regmap_irq_get_virq(wcd938x->irq_chip, |
| 3325 | WCD938X_IRQ_HPHL_PDM_WD_INT); |
| 3326 | wcd938x->aux_pdm_wd_int = regmap_irq_get_virq(wcd938x->irq_chip, |
| 3327 | WCD938X_IRQ_AUX_PDM_WD_INT); |
| 3328 | |
| 3329 | /* Request for watchdog interrupt */ |
| 3330 | ret = request_threaded_irq(wcd938x->hphr_pdm_wd_int, NULL, wcd938x_wd_handle_irq, |
| 3331 | IRQF_ONESHOT | IRQF_TRIGGER_RISING, |
| 3332 | "HPHR PDM WD INT", wcd938x); |
| 3333 | if (ret) |
| 3334 | dev_err(dev, "Failed to request HPHR WD interrupt (%d)\n", ret); |
| 3335 | |
| 3336 | ret = request_threaded_irq(wcd938x->hphl_pdm_wd_int, NULL, wcd938x_wd_handle_irq, |
| 3337 | IRQF_ONESHOT | IRQF_TRIGGER_RISING, |
| 3338 | "HPHL PDM WD INT", wcd938x); |
| 3339 | if (ret) |
| 3340 | dev_err(dev, "Failed to request HPHL WD interrupt (%d)\n", ret); |
| 3341 | |
| 3342 | ret = request_threaded_irq(wcd938x->aux_pdm_wd_int, NULL, wcd938x_wd_handle_irq, |
| 3343 | IRQF_ONESHOT | IRQF_TRIGGER_RISING, |
| 3344 | "AUX PDM WD INT", wcd938x); |
| 3345 | if (ret) |
| 3346 | dev_err(dev, "Failed to request Aux WD interrupt (%d)\n", ret); |
| 3347 | |
| 3348 | /* Disable watchdog interrupt for HPH and AUX */ |
| 3349 | disable_irq_nosync(wcd938x->hphr_pdm_wd_int); |
| 3350 | disable_irq_nosync(wcd938x->hphl_pdm_wd_int); |
| 3351 | disable_irq_nosync(wcd938x->aux_pdm_wd_int); |
| 3352 | |
Srinivas Kandagatla | e8ba1e0 | 2021-06-09 10:09:40 +0100 | [diff] [blame] | 3353 | switch (wcd938x->variant) { |
| 3354 | case WCD9380: |
| 3355 | ret = snd_soc_add_component_controls(component, wcd9380_snd_controls, |
| 3356 | ARRAY_SIZE(wcd9380_snd_controls)); |
| 3357 | if (ret < 0) { |
| 3358 | dev_err(component->dev, |
| 3359 | "%s: Failed to add snd ctrls for variant: %d\n", |
| 3360 | __func__, wcd938x->variant); |
| 3361 | goto err; |
| 3362 | } |
| 3363 | break; |
| 3364 | case WCD9385: |
| 3365 | ret = snd_soc_add_component_controls(component, wcd9385_snd_controls, |
| 3366 | ARRAY_SIZE(wcd9385_snd_controls)); |
| 3367 | if (ret < 0) { |
| 3368 | dev_err(component->dev, |
| 3369 | "%s: Failed to add snd ctrls for variant: %d\n", |
| 3370 | __func__, wcd938x->variant); |
| 3371 | goto err; |
| 3372 | } |
| 3373 | break; |
| 3374 | default: |
| 3375 | break; |
| 3376 | } |
| 3377 | err: |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 3378 | return ret; |
| 3379 | } |
| 3380 | |
| 3381 | static const struct snd_soc_component_driver soc_codec_dev_wcd938x = { |
| 3382 | .name = "wcd938x_codec", |
| 3383 | .probe = wcd938x_soc_codec_probe, |
Srinivas Kandagatla | e8ba1e0 | 2021-06-09 10:09:40 +0100 | [diff] [blame] | 3384 | .controls = wcd938x_snd_controls, |
| 3385 | .num_controls = ARRAY_SIZE(wcd938x_snd_controls), |
Srinivas Kandagatla | 8da9db0 | 2021-06-09 10:09:41 +0100 | [diff] [blame] | 3386 | .dapm_widgets = wcd938x_dapm_widgets, |
| 3387 | .num_dapm_widgets = ARRAY_SIZE(wcd938x_dapm_widgets), |
Srinivas Kandagatla | 0454422 | 2021-06-09 10:09:43 +0100 | [diff] [blame] | 3388 | .dapm_routes = wcd938x_audio_map, |
| 3389 | .num_dapm_routes = ARRAY_SIZE(wcd938x_audio_map), |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 3390 | }; |
| 3391 | |
| 3392 | static void wcd938x_dt_parse_micbias_info(struct device *dev, struct wcd938x_priv *wcd) |
| 3393 | { |
| 3394 | struct device_node *np = dev->of_node; |
| 3395 | u32 prop_val = 0; |
| 3396 | int rc = 0; |
| 3397 | |
| 3398 | rc = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val); |
| 3399 | if (!rc) |
| 3400 | wcd->micb1_mv = prop_val/1000; |
| 3401 | else |
| 3402 | dev_info(dev, "%s: Micbias1 DT property not found\n", __func__); |
| 3403 | |
| 3404 | rc = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val); |
| 3405 | if (!rc) |
| 3406 | wcd->micb2_mv = prop_val/1000; |
| 3407 | else |
| 3408 | dev_info(dev, "%s: Micbias2 DT property not found\n", __func__); |
| 3409 | |
| 3410 | rc = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val); |
| 3411 | if (!rc) |
| 3412 | wcd->micb3_mv = prop_val/1000; |
| 3413 | else |
| 3414 | dev_info(dev, "%s: Micbias3 DT property not found\n", __func__); |
| 3415 | |
| 3416 | rc = of_property_read_u32(np, "qcom,micbias4-microvolt", &prop_val); |
| 3417 | if (!rc) |
| 3418 | wcd->micb4_mv = prop_val/1000; |
| 3419 | else |
| 3420 | dev_info(dev, "%s: Micbias4 DT property not found\n", __func__); |
| 3421 | } |
| 3422 | |
| 3423 | static int wcd938x_populate_dt_data(struct wcd938x_priv *wcd938x, struct device *dev) |
| 3424 | { |
| 3425 | int ret; |
| 3426 | |
| 3427 | wcd938x->reset_gpio = of_get_named_gpio(dev->of_node, "reset-gpios", 0); |
| 3428 | if (wcd938x->reset_gpio < 0) { |
| 3429 | dev_err(dev, "Failed to get reset gpio: err = %d\n", |
| 3430 | wcd938x->reset_gpio); |
| 3431 | return wcd938x->reset_gpio; |
| 3432 | } |
| 3433 | |
| 3434 | wcd938x->supplies[0].supply = "vdd-rxtx"; |
| 3435 | wcd938x->supplies[1].supply = "vdd-io"; |
| 3436 | wcd938x->supplies[2].supply = "vdd-buck"; |
| 3437 | wcd938x->supplies[3].supply = "vdd-mic-bias"; |
| 3438 | |
| 3439 | ret = regulator_bulk_get(dev, WCD938X_MAX_SUPPLY, wcd938x->supplies); |
| 3440 | if (ret) { |
| 3441 | dev_err(dev, "Failed to get supplies: err = %d\n", ret); |
| 3442 | return ret; |
| 3443 | } |
| 3444 | |
| 3445 | ret = regulator_bulk_enable(WCD938X_MAX_SUPPLY, wcd938x->supplies); |
| 3446 | if (ret) { |
| 3447 | dev_err(dev, "Failed to enable supplies: err = %d\n", ret); |
| 3448 | return ret; |
| 3449 | } |
| 3450 | |
| 3451 | wcd938x_dt_parse_micbias_info(dev, wcd938x); |
| 3452 | |
| 3453 | return 0; |
| 3454 | } |
| 3455 | |
| 3456 | static int wcd938x_reset(struct wcd938x_priv *wcd938x) |
| 3457 | { |
| 3458 | gpio_direction_output(wcd938x->reset_gpio, 0); |
| 3459 | /* 20us sleep required after pulling the reset gpio to LOW */ |
| 3460 | usleep_range(20, 30); |
| 3461 | gpio_set_value(wcd938x->reset_gpio, 1); |
| 3462 | /* 20us sleep required after pulling the reset gpio to HIGH */ |
| 3463 | usleep_range(20, 30); |
| 3464 | |
| 3465 | return 0; |
| 3466 | } |
| 3467 | |
Srinivas Kandagatla | 1657252 | 2021-06-09 10:09:39 +0100 | [diff] [blame] | 3468 | static int wcd938x_codec_hw_params(struct snd_pcm_substream *substream, |
| 3469 | struct snd_pcm_hw_params *params, |
| 3470 | struct snd_soc_dai *dai) |
| 3471 | { |
| 3472 | struct wcd938x_priv *wcd938x = dev_get_drvdata(dai->dev); |
| 3473 | struct wcd938x_sdw_priv *wcd = wcd938x->sdw_priv[dai->id]; |
| 3474 | |
| 3475 | return wcd938x_sdw_hw_params(wcd, substream, params, dai); |
| 3476 | } |
| 3477 | |
| 3478 | static int wcd938x_codec_free(struct snd_pcm_substream *substream, |
| 3479 | struct snd_soc_dai *dai) |
| 3480 | { |
| 3481 | struct wcd938x_priv *wcd938x = dev_get_drvdata(dai->dev); |
| 3482 | struct wcd938x_sdw_priv *wcd = wcd938x->sdw_priv[dai->id]; |
| 3483 | |
| 3484 | return wcd938x_sdw_free(wcd, substream, dai); |
| 3485 | } |
| 3486 | |
| 3487 | static int wcd938x_codec_set_sdw_stream(struct snd_soc_dai *dai, |
| 3488 | void *stream, int direction) |
| 3489 | { |
| 3490 | struct wcd938x_priv *wcd938x = dev_get_drvdata(dai->dev); |
| 3491 | struct wcd938x_sdw_priv *wcd = wcd938x->sdw_priv[dai->id]; |
| 3492 | |
| 3493 | return wcd938x_sdw_set_sdw_stream(wcd, dai, stream, direction); |
| 3494 | |
| 3495 | } |
| 3496 | |
Pu Lehui | 355af6c | 2021-06-15 19:33:24 +0800 | [diff] [blame] | 3497 | static const struct snd_soc_dai_ops wcd938x_sdw_dai_ops = { |
Srinivas Kandagatla | 1657252 | 2021-06-09 10:09:39 +0100 | [diff] [blame] | 3498 | .hw_params = wcd938x_codec_hw_params, |
| 3499 | .hw_free = wcd938x_codec_free, |
| 3500 | .set_sdw_stream = wcd938x_codec_set_sdw_stream, |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 3501 | }; |
| 3502 | |
| 3503 | static struct snd_soc_dai_driver wcd938x_dais[] = { |
| 3504 | [0] = { |
| 3505 | .name = "wcd938x-sdw-rx", |
| 3506 | .playback = { |
| 3507 | .stream_name = "WCD AIF1 Playback", |
| 3508 | .rates = WCD938X_RATES_MASK | WCD938X_FRAC_RATES_MASK, |
| 3509 | .formats = WCD938X_FORMATS_S16_S24_LE, |
| 3510 | .rate_max = 192000, |
| 3511 | .rate_min = 8000, |
| 3512 | .channels_min = 1, |
| 3513 | .channels_max = 2, |
| 3514 | }, |
| 3515 | .ops = &wcd938x_sdw_dai_ops, |
| 3516 | }, |
| 3517 | [1] = { |
| 3518 | .name = "wcd938x-sdw-tx", |
| 3519 | .capture = { |
| 3520 | .stream_name = "WCD AIF1 Capture", |
| 3521 | .rates = WCD938X_RATES_MASK, |
| 3522 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 3523 | .rate_min = 8000, |
| 3524 | .rate_max = 192000, |
| 3525 | .channels_min = 1, |
| 3526 | .channels_max = 4, |
| 3527 | }, |
| 3528 | .ops = &wcd938x_sdw_dai_ops, |
| 3529 | }, |
| 3530 | }; |
| 3531 | |
| 3532 | static int wcd938x_bind(struct device *dev) |
| 3533 | { |
| 3534 | struct wcd938x_priv *wcd938x = dev_get_drvdata(dev); |
| 3535 | int ret; |
| 3536 | |
| 3537 | ret = component_bind_all(dev, wcd938x); |
| 3538 | if (ret) { |
| 3539 | dev_err(dev, "%s: Slave bind failed, ret = %d\n", |
| 3540 | __func__, ret); |
| 3541 | return ret; |
| 3542 | } |
| 3543 | |
Srinivas Kandagatla | 1657252 | 2021-06-09 10:09:39 +0100 | [diff] [blame] | 3544 | wcd938x->rxdev = wcd938x_sdw_device_get(wcd938x->rxnode); |
| 3545 | if (!wcd938x->rxdev) { |
| 3546 | dev_err(dev, "could not find slave with matching of node\n"); |
| 3547 | return -EINVAL; |
| 3548 | } |
| 3549 | wcd938x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd938x->rxdev); |
| 3550 | wcd938x->sdw_priv[AIF1_PB]->wcd938x = wcd938x; |
Srinivas Kandagatla | b90d939 | 2021-06-15 14:28:29 +0100 | [diff] [blame] | 3551 | wcd938x->sdw_priv[AIF1_PB]->slave_irq = wcd938x->virq; |
Srinivas Kandagatla | 1657252 | 2021-06-09 10:09:39 +0100 | [diff] [blame] | 3552 | |
| 3553 | wcd938x->txdev = wcd938x_sdw_device_get(wcd938x->txnode); |
| 3554 | if (!wcd938x->txdev) { |
| 3555 | dev_err(dev, "could not find txslave with matching of node\n"); |
| 3556 | return -EINVAL; |
| 3557 | } |
| 3558 | wcd938x->sdw_priv[AIF1_CAP] = dev_get_drvdata(wcd938x->txdev); |
| 3559 | wcd938x->sdw_priv[AIF1_CAP]->wcd938x = wcd938x; |
Srinivas Kandagatla | b90d939 | 2021-06-15 14:28:29 +0100 | [diff] [blame] | 3560 | wcd938x->sdw_priv[AIF1_CAP]->slave_irq = wcd938x->virq; |
Srinivas Kandagatla | 1657252 | 2021-06-09 10:09:39 +0100 | [diff] [blame] | 3561 | wcd938x->tx_sdw_dev = dev_to_sdw_dev(wcd938x->txdev); |
| 3562 | if (!wcd938x->tx_sdw_dev) { |
| 3563 | dev_err(dev, "could not get txslave with matching of dev\n"); |
| 3564 | return -EINVAL; |
| 3565 | } |
| 3566 | |
| 3567 | /* As TX is main CSR reg interface, which should not be suspended first. |
| 3568 | * expicilty add the dependency link */ |
| 3569 | if (!device_link_add(wcd938x->rxdev, wcd938x->txdev, DL_FLAG_STATELESS | |
| 3570 | DL_FLAG_PM_RUNTIME)) { |
| 3571 | dev_err(dev, "could not devlink tx and rx\n"); |
| 3572 | return -EINVAL; |
| 3573 | } |
| 3574 | |
| 3575 | if (!device_link_add(dev, wcd938x->txdev, DL_FLAG_STATELESS | |
| 3576 | DL_FLAG_PM_RUNTIME)) { |
| 3577 | dev_err(dev, "could not devlink wcd and tx\n"); |
| 3578 | return -EINVAL; |
| 3579 | } |
| 3580 | |
| 3581 | if (!device_link_add(dev, wcd938x->rxdev, DL_FLAG_STATELESS | |
| 3582 | DL_FLAG_PM_RUNTIME)) { |
| 3583 | dev_err(dev, "could not devlink wcd and rx\n"); |
| 3584 | return -EINVAL; |
| 3585 | } |
| 3586 | |
Srinivas Kandagatla | b90d939 | 2021-06-15 14:28:29 +0100 | [diff] [blame] | 3587 | wcd938x->regmap = devm_regmap_init_sdw(wcd938x->tx_sdw_dev, &wcd938x_regmap_config); |
| 3588 | if (IS_ERR(wcd938x->regmap)) { |
Srinivas Kandagatla | 1657252 | 2021-06-09 10:09:39 +0100 | [diff] [blame] | 3589 | dev_err(dev, "%s: tx csr regmap not found\n", __func__); |
| 3590 | return PTR_ERR(wcd938x->regmap); |
| 3591 | } |
| 3592 | |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 3593 | ret = wcd938x_set_micbias_data(wcd938x); |
| 3594 | if (ret < 0) { |
| 3595 | dev_err(dev, "%s: bad micbias pdata\n", __func__); |
| 3596 | return ret; |
| 3597 | } |
| 3598 | |
| 3599 | ret = snd_soc_register_component(dev, &soc_codec_dev_wcd938x, |
| 3600 | wcd938x_dais, ARRAY_SIZE(wcd938x_dais)); |
| 3601 | if (ret) |
| 3602 | dev_err(dev, "%s: Codec registration failed\n", |
| 3603 | __func__); |
| 3604 | |
| 3605 | return ret; |
| 3606 | |
| 3607 | } |
| 3608 | |
| 3609 | static void wcd938x_unbind(struct device *dev) |
| 3610 | { |
| 3611 | struct wcd938x_priv *wcd938x = dev_get_drvdata(dev); |
| 3612 | |
Srinivas Kandagatla | 1657252 | 2021-06-09 10:09:39 +0100 | [diff] [blame] | 3613 | device_link_remove(dev, wcd938x->txdev); |
| 3614 | device_link_remove(dev, wcd938x->rxdev); |
| 3615 | device_link_remove(wcd938x->rxdev, wcd938x->txdev); |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 3616 | snd_soc_unregister_component(dev); |
| 3617 | component_unbind_all(dev, wcd938x); |
| 3618 | } |
| 3619 | |
| 3620 | static const struct component_master_ops wcd938x_comp_ops = { |
| 3621 | .bind = wcd938x_bind, |
| 3622 | .unbind = wcd938x_unbind, |
| 3623 | }; |
| 3624 | |
| 3625 | static int wcd938x_compare_of(struct device *dev, void *data) |
| 3626 | { |
| 3627 | return dev->of_node == data; |
| 3628 | } |
| 3629 | |
| 3630 | static void wcd938x_release_of(struct device *dev, void *data) |
| 3631 | { |
| 3632 | of_node_put(data); |
| 3633 | } |
| 3634 | |
| 3635 | static int wcd938x_add_slave_components(struct wcd938x_priv *wcd938x, |
| 3636 | struct device *dev, |
| 3637 | struct component_match **matchptr) |
| 3638 | { |
| 3639 | struct device_node *np; |
| 3640 | |
| 3641 | np = dev->of_node; |
| 3642 | |
| 3643 | wcd938x->rxnode = of_parse_phandle(np, "qcom,rx-device", 0); |
| 3644 | if (!wcd938x->rxnode) { |
| 3645 | dev_err(dev, "%s: Rx-device node not defined\n", __func__); |
| 3646 | return -ENODEV; |
| 3647 | } |
| 3648 | |
| 3649 | of_node_get(wcd938x->rxnode); |
| 3650 | component_match_add_release(dev, matchptr, wcd938x_release_of, |
| 3651 | wcd938x_compare_of, wcd938x->rxnode); |
| 3652 | |
| 3653 | wcd938x->txnode = of_parse_phandle(np, "qcom,tx-device", 0); |
| 3654 | if (!wcd938x->txnode) { |
| 3655 | dev_err(dev, "%s: Tx-device node not defined\n", __func__); |
| 3656 | return -ENODEV; |
| 3657 | } |
| 3658 | of_node_get(wcd938x->txnode); |
| 3659 | component_match_add_release(dev, matchptr, wcd938x_release_of, |
| 3660 | wcd938x_compare_of, wcd938x->txnode); |
| 3661 | return 0; |
| 3662 | } |
| 3663 | |
| 3664 | static int wcd938x_probe(struct platform_device *pdev) |
| 3665 | { |
| 3666 | struct component_match *match = NULL; |
| 3667 | struct wcd938x_priv *wcd938x = NULL; |
| 3668 | struct device *dev = &pdev->dev; |
| 3669 | int ret; |
| 3670 | |
| 3671 | wcd938x = devm_kzalloc(dev, sizeof(struct wcd938x_priv), |
| 3672 | GFP_KERNEL); |
| 3673 | if (!wcd938x) |
| 3674 | return -ENOMEM; |
| 3675 | |
| 3676 | dev_set_drvdata(dev, wcd938x); |
| 3677 | |
| 3678 | ret = wcd938x_populate_dt_data(wcd938x, dev); |
| 3679 | if (ret) { |
| 3680 | dev_err(dev, "%s: Fail to obtain platform data\n", __func__); |
| 3681 | return -EINVAL; |
| 3682 | } |
| 3683 | |
| 3684 | ret = wcd938x_add_slave_components(wcd938x, dev, &match); |
| 3685 | if (ret) |
| 3686 | return ret; |
| 3687 | |
| 3688 | wcd938x_reset(wcd938x); |
| 3689 | |
| 3690 | ret = component_master_add_with_match(dev, &wcd938x_comp_ops, match); |
| 3691 | if (ret) |
| 3692 | return ret; |
| 3693 | |
| 3694 | pm_runtime_set_autosuspend_delay(dev, 1000); |
| 3695 | pm_runtime_use_autosuspend(dev); |
| 3696 | pm_runtime_mark_last_busy(dev); |
| 3697 | pm_runtime_set_active(dev); |
| 3698 | pm_runtime_enable(dev); |
| 3699 | pm_runtime_idle(dev); |
| 3700 | |
| 3701 | return ret; |
| 3702 | } |
| 3703 | |
| 3704 | static int wcd938x_remove(struct platform_device *pdev) |
| 3705 | { |
| 3706 | component_master_del(&pdev->dev, &wcd938x_comp_ops); |
| 3707 | |
| 3708 | return 0; |
| 3709 | } |
| 3710 | |
Srinivas Kandagatla | 8c4863c | 2021-06-21 14:45:01 +0100 | [diff] [blame] | 3711 | #if defined(CONFIG_OF) |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 3712 | static const struct of_device_id wcd938x_dt_match[] = { |
| 3713 | { .compatible = "qcom,wcd9380-codec" }, |
| 3714 | { .compatible = "qcom,wcd9385-codec" }, |
| 3715 | {} |
| 3716 | }; |
| 3717 | MODULE_DEVICE_TABLE(of, wcd938x_dt_match); |
Srinivas Kandagatla | 8c4863c | 2021-06-21 14:45:01 +0100 | [diff] [blame] | 3718 | #endif |
Srinivas Kandagatla | 8d78602 | 2021-06-09 10:09:37 +0100 | [diff] [blame] | 3719 | |
| 3720 | static struct platform_driver wcd938x_codec_driver = { |
| 3721 | .probe = wcd938x_probe, |
| 3722 | .remove = wcd938x_remove, |
| 3723 | .driver = { |
| 3724 | .name = "wcd938x_codec", |
| 3725 | .of_match_table = of_match_ptr(wcd938x_dt_match), |
| 3726 | .suppress_bind_attrs = true, |
| 3727 | }, |
| 3728 | }; |
| 3729 | |
| 3730 | module_platform_driver(wcd938x_codec_driver); |
| 3731 | MODULE_DESCRIPTION("WCD938X Codec driver"); |
| 3732 | MODULE_LICENSE("GPL"); |