1 // SPDX-License-Identifier: GPL-2.0-only 1 // SPDX-License-Identifier: GPL-2.0-only 2 // Copyright (c) 2023-2024 Qualcomm Innovation 2 // Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved. 3 3 4 #include <linux/component.h> 4 #include <linux/component.h> 5 #include <linux/delay.h> 5 #include <linux/delay.h> 6 #include <linux/device.h> 6 #include <linux/device.h> 7 #include <linux/gpio/consumer.h> 7 #include <linux/gpio/consumer.h> 8 #include <linux/kernel.h> 8 #include <linux/kernel.h> 9 #include <linux/module.h> 9 #include <linux/module.h> 10 #include <linux/of_gpio.h> 10 #include <linux/of_gpio.h> 11 #include <linux/of.h> 11 #include <linux/of.h> 12 #include <linux/platform_device.h> 12 #include <linux/platform_device.h> 13 #include <linux/pm_runtime.h> 13 #include <linux/pm_runtime.h> 14 #include <linux/regmap.h> 14 #include <linux/regmap.h> 15 #include <linux/regulator/consumer.h> 15 #include <linux/regulator/consumer.h> 16 #include <linux/slab.h> 16 #include <linux/slab.h> 17 #include <sound/jack.h> 17 #include <sound/jack.h> 18 #include <sound/pcm_params.h> 18 #include <sound/pcm_params.h> 19 #include <sound/pcm.h> 19 #include <sound/pcm.h> 20 #include <sound/soc-dapm.h> 20 #include <sound/soc-dapm.h> 21 #include <sound/soc.h> 21 #include <sound/soc.h> 22 #include <sound/tlv.h> 22 #include <sound/tlv.h> 23 23 24 #include "wcd-clsh-v2.h" 24 #include "wcd-clsh-v2.h" 25 #include "wcd-mbhc-v2.h" 25 #include "wcd-mbhc-v2.h" 26 #include "wcd937x.h" 26 #include "wcd937x.h" 27 27 28 enum { 28 enum { 29 CHIPID_WCD9370 = 0, 29 CHIPID_WCD9370 = 0, 30 CHIPID_WCD9375 = 5, 30 CHIPID_WCD9375 = 5, 31 }; 31 }; 32 32 33 /* Z value defined in milliohm */ 33 /* Z value defined in milliohm */ 34 #define WCD937X_ZDET_VAL_32 (32000 34 #define WCD937X_ZDET_VAL_32 (32000) 35 #define WCD937X_ZDET_VAL_400 (40000 35 #define WCD937X_ZDET_VAL_400 (400000) 36 #define WCD937X_ZDET_VAL_1200 (12000 36 #define WCD937X_ZDET_VAL_1200 (1200000) 37 #define WCD937X_ZDET_VAL_100K (10000 37 #define WCD937X_ZDET_VAL_100K (100000000) 38 /* Z floating defined in ohms */ 38 /* Z floating defined in ohms */ 39 #define WCD937X_ZDET_FLOATING_IMPEDANCE (0x0FF 39 #define WCD937X_ZDET_FLOATING_IMPEDANCE (0x0FFFFFFE) 40 #define WCD937X_ZDET_NUM_MEASUREMENTS (900) 40 #define WCD937X_ZDET_NUM_MEASUREMENTS (900) 41 #define WCD937X_MBHC_GET_C1(c) (((c) 41 #define WCD937X_MBHC_GET_C1(c) (((c) & 0xC000) >> 14) 42 #define WCD937X_MBHC_GET_X1(x) ((x) & 42 #define WCD937X_MBHC_GET_X1(x) ((x) & 0x3FFF) 43 /* Z value compared in milliOhm */ 43 /* Z value compared in milliOhm */ 44 #define WCD937X_MBHC_IS_SECOND_RAMP_REQUIRED(z 44 #define WCD937X_MBHC_IS_SECOND_RAMP_REQUIRED(z) (((z) > 400000) || ((z) < 32000)) 45 #define WCD937X_MBHC_ZDET_CONST (86 * 45 #define WCD937X_MBHC_ZDET_CONST (86 * 16384) 46 #define WCD937X_MBHC_MOISTURE_RREF R_24_K 46 #define WCD937X_MBHC_MOISTURE_RREF R_24_KOHM 47 #define WCD_MBHC_HS_V_MAX 1600 47 #define WCD_MBHC_HS_V_MAX 1600 48 #define EAR_RX_PATH_AUX 1 48 #define EAR_RX_PATH_AUX 1 49 #define WCD937X_MBHC_MAX_BUTTONS 8 49 #define WCD937X_MBHC_MAX_BUTTONS 8 50 50 51 #define WCD937X_RATES (SNDRV_PCM_RATE_8000 | S 51 #define WCD937X_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ 52 SNDRV_PCM_RATE_32000 | 52 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\ 53 SNDRV_PCM_RATE_96000 | 53 SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\ 54 SNDRV_PCM_RATE_384000) 54 SNDRV_PCM_RATE_384000) 55 55 56 /* Fractional Rates */ 56 /* Fractional Rates */ 57 #define WCD937X_FRAC_RATES (SNDRV_PCM_RATE_441 57 #define WCD937X_FRAC_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\ 58 SNDRV_PCM_RATE_176 58 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_352800) 59 59 60 #define WCD937X_FORMATS (SNDRV_PCM_FMTBIT_S16_ 60 #define WCD937X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |\ 61 SNDRV_PCM_FMTBIT_S24_ 61 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) 62 62 63 enum { 63 enum { 64 ALLOW_BUCK_DISABLE, 64 ALLOW_BUCK_DISABLE, 65 HPH_COMP_DELAY, 65 HPH_COMP_DELAY, 66 HPH_PA_DELAY, 66 HPH_PA_DELAY, 67 AMIC2_BCS_ENABLE, 67 AMIC2_BCS_ENABLE, 68 }; 68 }; 69 69 70 enum { 70 enum { 71 AIF1_PB = 0, 71 AIF1_PB = 0, 72 AIF1_CAP, 72 AIF1_CAP, 73 NUM_CODEC_DAIS, 73 NUM_CODEC_DAIS, 74 }; 74 }; 75 75 76 struct wcd937x_priv { 76 struct wcd937x_priv { 77 struct sdw_slave *tx_sdw_dev; 77 struct sdw_slave *tx_sdw_dev; 78 struct wcd937x_sdw_priv *sdw_priv[NUM_ 78 struct wcd937x_sdw_priv *sdw_priv[NUM_CODEC_DAIS]; 79 struct device *txdev; 79 struct device *txdev; 80 struct device *rxdev; 80 struct device *rxdev; 81 struct device_node *rxnode; 81 struct device_node *rxnode; 82 struct device_node *txnode; 82 struct device_node *txnode; 83 struct regmap *regmap; 83 struct regmap *regmap; 84 /* micb setup lock */ 84 /* micb setup lock */ 85 struct mutex micb_lock; 85 struct mutex micb_lock; 86 /* mbhc module */ 86 /* mbhc module */ 87 struct wcd_mbhc *wcd_mbhc; 87 struct wcd_mbhc *wcd_mbhc; 88 struct wcd_mbhc_config mbhc_cfg; 88 struct wcd_mbhc_config mbhc_cfg; 89 struct wcd_mbhc_intr intr_ids; 89 struct wcd_mbhc_intr intr_ids; 90 struct wcd_clsh_ctrl *clsh_info; 90 struct wcd_clsh_ctrl *clsh_info; 91 struct irq_domain *virq; 91 struct irq_domain *virq; 92 struct regmap_irq_chip *wcd_regmap_irq 92 struct regmap_irq_chip *wcd_regmap_irq_chip; 93 struct regmap_irq_chip_data *irq_chip; 93 struct regmap_irq_chip_data *irq_chip; 94 struct regulator_bulk_data supplies[WC 94 struct regulator_bulk_data supplies[WCD937X_MAX_BULK_SUPPLY]; 95 struct regulator *buck_supply; 95 struct regulator *buck_supply; 96 struct snd_soc_jack *jack; 96 struct snd_soc_jack *jack; 97 unsigned long status_mask; 97 unsigned long status_mask; 98 s32 micb_ref[WCD937X_MAX_MICBIAS]; 98 s32 micb_ref[WCD937X_MAX_MICBIAS]; 99 s32 pullup_ref[WCD937X_MAX_MICBIAS]; 99 s32 pullup_ref[WCD937X_MAX_MICBIAS]; 100 u32 hph_mode; 100 u32 hph_mode; 101 int ear_rx_path; 101 int ear_rx_path; 102 u32 micb1_mv; 102 u32 micb1_mv; 103 u32 micb2_mv; 103 u32 micb2_mv; 104 u32 micb3_mv; 104 u32 micb3_mv; 105 int hphr_pdm_wd_int; 105 int hphr_pdm_wd_int; 106 int hphl_pdm_wd_int; 106 int hphl_pdm_wd_int; 107 int aux_pdm_wd_int; 107 int aux_pdm_wd_int; 108 bool comp1_enable; 108 bool comp1_enable; 109 bool comp2_enable; 109 bool comp2_enable; 110 110 111 struct gpio_desc *us_euro_gpio; 111 struct gpio_desc *us_euro_gpio; 112 struct gpio_desc *reset_gpio; 112 struct gpio_desc *reset_gpio; 113 113 114 atomic_t rx_clk_cnt; 114 atomic_t rx_clk_cnt; 115 atomic_t ana_clk_count; 115 atomic_t ana_clk_count; 116 }; 116 }; 117 117 118 static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX( 118 static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(ear_pa_gain, 600, -1800); 119 static const DECLARE_TLV_DB_SCALE(line_gain, 0 119 static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1); 120 static const DECLARE_TLV_DB_SCALE(analog_gain, 120 static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1); 121 121 122 struct wcd937x_mbhc_zdet_param { 122 struct wcd937x_mbhc_zdet_param { 123 u16 ldo_ctl; 123 u16 ldo_ctl; 124 u16 noff; 124 u16 noff; 125 u16 nshift; 125 u16 nshift; 126 u16 btn5; 126 u16 btn5; 127 u16 btn6; 127 u16 btn6; 128 u16 btn7; 128 u16 btn7; 129 }; 129 }; 130 130 131 static const struct wcd_mbhc_field wcd_mbhc_fi 131 static const struct wcd_mbhc_field wcd_mbhc_fields[WCD_MBHC_REG_FUNC_MAX] = { 132 WCD_MBHC_FIELD(WCD_MBHC_L_DET_EN, WCD9 132 WCD_MBHC_FIELD(WCD_MBHC_L_DET_EN, WCD937X_ANA_MBHC_MECH, 0x80), 133 WCD_MBHC_FIELD(WCD_MBHC_GND_DET_EN, WC 133 WCD_MBHC_FIELD(WCD_MBHC_GND_DET_EN, WCD937X_ANA_MBHC_MECH, 0x40), 134 WCD_MBHC_FIELD(WCD_MBHC_MECH_DETECTION 134 WCD_MBHC_FIELD(WCD_MBHC_MECH_DETECTION_TYPE, WCD937X_ANA_MBHC_MECH, 0x20), 135 WCD_MBHC_FIELD(WCD_MBHC_MIC_CLAMP_CTL, 135 WCD_MBHC_FIELD(WCD_MBHC_MIC_CLAMP_CTL, WCD937X_MBHC_NEW_PLUG_DETECT_CTL, 0x30), 136 WCD_MBHC_FIELD(WCD_MBHC_ELECT_DETECTIO 136 WCD_MBHC_FIELD(WCD_MBHC_ELECT_DETECTION_TYPE, WCD937X_ANA_MBHC_ELECT, 0x08), 137 WCD_MBHC_FIELD(WCD_MBHC_HS_L_DET_PULL_ 137 WCD_MBHC_FIELD(WCD_MBHC_HS_L_DET_PULL_UP_CTRL, WCD937X_MBHC_NEW_INT_MECH_DET_CURRENT, 0x1F), 138 WCD_MBHC_FIELD(WCD_MBHC_HS_L_DET_PULL_ 138 WCD_MBHC_FIELD(WCD_MBHC_HS_L_DET_PULL_UP_COMP_CTRL, WCD937X_ANA_MBHC_MECH, 0x04), 139 WCD_MBHC_FIELD(WCD_MBHC_HPHL_PLUG_TYPE 139 WCD_MBHC_FIELD(WCD_MBHC_HPHL_PLUG_TYPE, WCD937X_ANA_MBHC_MECH, 0x10), 140 WCD_MBHC_FIELD(WCD_MBHC_GND_PLUG_TYPE, 140 WCD_MBHC_FIELD(WCD_MBHC_GND_PLUG_TYPE, WCD937X_ANA_MBHC_MECH, 0x08), 141 WCD_MBHC_FIELD(WCD_MBHC_SW_HPH_LP_100K 141 WCD_MBHC_FIELD(WCD_MBHC_SW_HPH_LP_100K_TO_GND, WCD937X_ANA_MBHC_MECH, 0x01), 142 WCD_MBHC_FIELD(WCD_MBHC_ELECT_SCHMT_IS 142 WCD_MBHC_FIELD(WCD_MBHC_ELECT_SCHMT_ISRC, WCD937X_ANA_MBHC_ELECT, 0x06), 143 WCD_MBHC_FIELD(WCD_MBHC_FSM_EN, WCD937 143 WCD_MBHC_FIELD(WCD_MBHC_FSM_EN, WCD937X_ANA_MBHC_ELECT, 0x80), 144 WCD_MBHC_FIELD(WCD_MBHC_INSREM_DBNC, W 144 WCD_MBHC_FIELD(WCD_MBHC_INSREM_DBNC, WCD937X_MBHC_NEW_PLUG_DETECT_CTL, 0x0F), 145 WCD_MBHC_FIELD(WCD_MBHC_BTN_DBNC, WCD9 145 WCD_MBHC_FIELD(WCD_MBHC_BTN_DBNC, WCD937X_MBHC_NEW_CTL_1, 0x03), 146 WCD_MBHC_FIELD(WCD_MBHC_HS_VREF, WCD93 146 WCD_MBHC_FIELD(WCD_MBHC_HS_VREF, WCD937X_MBHC_NEW_CTL_2, 0x03), 147 WCD_MBHC_FIELD(WCD_MBHC_HS_COMP_RESULT 147 WCD_MBHC_FIELD(WCD_MBHC_HS_COMP_RESULT, WCD937X_ANA_MBHC_RESULT_3, 0x08), 148 WCD_MBHC_FIELD(WCD_MBHC_IN2P_CLAMP_STA 148 WCD_MBHC_FIELD(WCD_MBHC_IN2P_CLAMP_STATE, WCD937X_ANA_MBHC_RESULT_3, 0x10), 149 WCD_MBHC_FIELD(WCD_MBHC_MIC_SCHMT_RESU 149 WCD_MBHC_FIELD(WCD_MBHC_MIC_SCHMT_RESULT, WCD937X_ANA_MBHC_RESULT_3, 0x20), 150 WCD_MBHC_FIELD(WCD_MBHC_HPHL_SCHMT_RES 150 WCD_MBHC_FIELD(WCD_MBHC_HPHL_SCHMT_RESULT, WCD937X_ANA_MBHC_RESULT_3, 0x80), 151 WCD_MBHC_FIELD(WCD_MBHC_HPHR_SCHMT_RES 151 WCD_MBHC_FIELD(WCD_MBHC_HPHR_SCHMT_RESULT, WCD937X_ANA_MBHC_RESULT_3, 0x40), 152 WCD_MBHC_FIELD(WCD_MBHC_OCP_FSM_EN, WC 152 WCD_MBHC_FIELD(WCD_MBHC_OCP_FSM_EN, WCD937X_HPH_OCP_CTL, 0x10), 153 WCD_MBHC_FIELD(WCD_MBHC_BTN_RESULT, WC 153 WCD_MBHC_FIELD(WCD_MBHC_BTN_RESULT, WCD937X_ANA_MBHC_RESULT_3, 0x07), 154 WCD_MBHC_FIELD(WCD_MBHC_BTN_ISRC_CTL, 154 WCD_MBHC_FIELD(WCD_MBHC_BTN_ISRC_CTL, WCD937X_ANA_MBHC_ELECT, 0x70), 155 WCD_MBHC_FIELD(WCD_MBHC_ELECT_RESULT, 155 WCD_MBHC_FIELD(WCD_MBHC_ELECT_RESULT, WCD937X_ANA_MBHC_RESULT_3, 0xFF), 156 WCD_MBHC_FIELD(WCD_MBHC_MICB_CTRL, WCD 156 WCD_MBHC_FIELD(WCD_MBHC_MICB_CTRL, WCD937X_ANA_MICB2, 0xC0), 157 WCD_MBHC_FIELD(WCD_MBHC_HPH_CNP_WG_TIM 157 WCD_MBHC_FIELD(WCD_MBHC_HPH_CNP_WG_TIME, WCD937X_HPH_CNP_WG_TIME, 0xFF), 158 WCD_MBHC_FIELD(WCD_MBHC_HPHR_PA_EN, WC 158 WCD_MBHC_FIELD(WCD_MBHC_HPHR_PA_EN, WCD937X_ANA_HPH, 0x40), 159 WCD_MBHC_FIELD(WCD_MBHC_HPHL_PA_EN, WC 159 WCD_MBHC_FIELD(WCD_MBHC_HPHL_PA_EN, WCD937X_ANA_HPH, 0x80), 160 WCD_MBHC_FIELD(WCD_MBHC_HPH_PA_EN, WCD 160 WCD_MBHC_FIELD(WCD_MBHC_HPH_PA_EN, WCD937X_ANA_HPH, 0xC0), 161 WCD_MBHC_FIELD(WCD_MBHC_SWCH_LEVEL_REM 161 WCD_MBHC_FIELD(WCD_MBHC_SWCH_LEVEL_REMOVE, WCD937X_ANA_MBHC_RESULT_3, 0x10), 162 WCD_MBHC_FIELD(WCD_MBHC_ANC_DET_EN, WC 162 WCD_MBHC_FIELD(WCD_MBHC_ANC_DET_EN, WCD937X_MBHC_CTL_BCS, 0x02), 163 WCD_MBHC_FIELD(WCD_MBHC_FSM_STATUS, WC 163 WCD_MBHC_FIELD(WCD_MBHC_FSM_STATUS, WCD937X_MBHC_NEW_FSM_STATUS, 0x01), 164 WCD_MBHC_FIELD(WCD_MBHC_MUX_CTL, WCD93 164 WCD_MBHC_FIELD(WCD_MBHC_MUX_CTL, WCD937X_MBHC_NEW_CTL_2, 0x70), 165 WCD_MBHC_FIELD(WCD_MBHC_MOISTURE_STATU 165 WCD_MBHC_FIELD(WCD_MBHC_MOISTURE_STATUS, WCD937X_MBHC_NEW_FSM_STATUS, 0x20), 166 WCD_MBHC_FIELD(WCD_MBHC_HPHR_GND, WCD9 166 WCD_MBHC_FIELD(WCD_MBHC_HPHR_GND, WCD937X_HPH_PA_CTL2, 0x40), 167 WCD_MBHC_FIELD(WCD_MBHC_HPHL_GND, WCD9 167 WCD_MBHC_FIELD(WCD_MBHC_HPHL_GND, WCD937X_HPH_PA_CTL2, 0x10), 168 WCD_MBHC_FIELD(WCD_MBHC_HPHL_OCP_DET_E 168 WCD_MBHC_FIELD(WCD_MBHC_HPHL_OCP_DET_EN, WCD937X_HPH_L_TEST, 0x01), 169 WCD_MBHC_FIELD(WCD_MBHC_HPHR_OCP_DET_E 169 WCD_MBHC_FIELD(WCD_MBHC_HPHR_OCP_DET_EN, WCD937X_HPH_R_TEST, 0x01), 170 WCD_MBHC_FIELD(WCD_MBHC_HPHL_OCP_STATU 170 WCD_MBHC_FIELD(WCD_MBHC_HPHL_OCP_STATUS, WCD937X_DIGITAL_INTR_STATUS_0, 0x80), 171 WCD_MBHC_FIELD(WCD_MBHC_HPHR_OCP_STATU 171 WCD_MBHC_FIELD(WCD_MBHC_HPHR_OCP_STATUS, WCD937X_DIGITAL_INTR_STATUS_0, 0x20), 172 WCD_MBHC_FIELD(WCD_MBHC_ADC_EN, WCD937 172 WCD_MBHC_FIELD(WCD_MBHC_ADC_EN, WCD937X_MBHC_NEW_CTL_1, 0x08), 173 WCD_MBHC_FIELD(WCD_MBHC_ADC_COMPLETE, 173 WCD_MBHC_FIELD(WCD_MBHC_ADC_COMPLETE, WCD937X_MBHC_NEW_FSM_STATUS, 0x40), 174 WCD_MBHC_FIELD(WCD_MBHC_ADC_TIMEOUT, W 174 WCD_MBHC_FIELD(WCD_MBHC_ADC_TIMEOUT, WCD937X_MBHC_NEW_FSM_STATUS, 0x80), 175 WCD_MBHC_FIELD(WCD_MBHC_ADC_RESULT, WC 175 WCD_MBHC_FIELD(WCD_MBHC_ADC_RESULT, WCD937X_MBHC_NEW_ADC_RESULT, 0xFF), 176 WCD_MBHC_FIELD(WCD_MBHC_MICB2_VOUT, WC 176 WCD_MBHC_FIELD(WCD_MBHC_MICB2_VOUT, WCD937X_ANA_MICB2, 0x3F), 177 WCD_MBHC_FIELD(WCD_MBHC_ADC_MODE, WCD9 177 WCD_MBHC_FIELD(WCD_MBHC_ADC_MODE, WCD937X_MBHC_NEW_CTL_1, 0x10), 178 WCD_MBHC_FIELD(WCD_MBHC_DETECTION_DONE 178 WCD_MBHC_FIELD(WCD_MBHC_DETECTION_DONE, WCD937X_MBHC_NEW_CTL_1, 0x04), 179 WCD_MBHC_FIELD(WCD_MBHC_ELECT_ISRC_EN, 179 WCD_MBHC_FIELD(WCD_MBHC_ELECT_ISRC_EN, WCD937X_ANA_MBHC_ZDET, 0x02), 180 }; 180 }; 181 181 182 static const struct regmap_irq wcd937x_irqs[WC 182 static const struct regmap_irq wcd937x_irqs[WCD937X_NUM_IRQS] = { 183 REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_BUTTON 183 REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_BUTTON_PRESS_DET, 0, BIT(0)), 184 REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_BUTTON 184 REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_BUTTON_RELEASE_DET, 0, BIT(1)), 185 REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_ELECT_ 185 REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_ELECT_INS_REM_DET, 0, BIT(2)), 186 REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_ELECT_ 186 REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_ELECT_INS_REM_LEG_DET, 0, BIT(3)), 187 REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_SW_DET 187 REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_SW_DET, 0, BIT(4)), 188 REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_OCP_IN 188 REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_OCP_INT, 0, BIT(5)), 189 REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_CNP_IN 189 REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_CNP_INT, 0, BIT(6)), 190 REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_OCP_IN 190 REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_OCP_INT, 0, BIT(7)), 191 REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_CNP_IN 191 REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_CNP_INT, 1, BIT(0)), 192 REGMAP_IRQ_REG(WCD937X_IRQ_EAR_CNP_INT 192 REGMAP_IRQ_REG(WCD937X_IRQ_EAR_CNP_INT, 1, BIT(1)), 193 REGMAP_IRQ_REG(WCD937X_IRQ_EAR_SCD_INT 193 REGMAP_IRQ_REG(WCD937X_IRQ_EAR_SCD_INT, 1, BIT(2)), 194 REGMAP_IRQ_REG(WCD937X_IRQ_AUX_CNP_INT 194 REGMAP_IRQ_REG(WCD937X_IRQ_AUX_CNP_INT, 1, BIT(3)), 195 REGMAP_IRQ_REG(WCD937X_IRQ_AUX_SCD_INT 195 REGMAP_IRQ_REG(WCD937X_IRQ_AUX_SCD_INT, 1, BIT(4)), 196 REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_PDM_WD 196 REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_PDM_WD_INT, 1, BIT(5)), 197 REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_PDM_WD 197 REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_PDM_WD_INT, 1, BIT(6)), 198 REGMAP_IRQ_REG(WCD937X_IRQ_AUX_PDM_WD_ 198 REGMAP_IRQ_REG(WCD937X_IRQ_AUX_PDM_WD_INT, 1, BIT(7)), 199 REGMAP_IRQ_REG(WCD937X_IRQ_LDORT_SCD_I 199 REGMAP_IRQ_REG(WCD937X_IRQ_LDORT_SCD_INT, 2, BIT(0)), 200 REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_MOISTU 200 REGMAP_IRQ_REG(WCD937X_IRQ_MBHC_MOISTURE_INT, 2, BIT(1)), 201 REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_SURGE_ 201 REGMAP_IRQ_REG(WCD937X_IRQ_HPHL_SURGE_DET_INT, 2, BIT(2)), 202 REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_SURGE_ 202 REGMAP_IRQ_REG(WCD937X_IRQ_HPHR_SURGE_DET_INT, 2, BIT(3)), 203 }; 203 }; 204 204 205 static int wcd937x_handle_post_irq(void *data) 205 static int wcd937x_handle_post_irq(void *data) 206 { 206 { 207 struct wcd937x_priv *wcd937x; 207 struct wcd937x_priv *wcd937x; 208 208 209 if (data) 209 if (data) 210 wcd937x = (struct wcd937x_priv 210 wcd937x = (struct wcd937x_priv *)data; 211 else 211 else 212 return IRQ_HANDLED; 212 return IRQ_HANDLED; 213 213 214 regmap_write(wcd937x->regmap, WCD937X_ 214 regmap_write(wcd937x->regmap, WCD937X_DIGITAL_INTR_CLEAR_0, 0); 215 regmap_write(wcd937x->regmap, WCD937X_ 215 regmap_write(wcd937x->regmap, WCD937X_DIGITAL_INTR_CLEAR_1, 0); 216 regmap_write(wcd937x->regmap, WCD937X_ 216 regmap_write(wcd937x->regmap, WCD937X_DIGITAL_INTR_CLEAR_2, 0); 217 217 218 return IRQ_HANDLED; 218 return IRQ_HANDLED; 219 } 219 } 220 220 221 static const u32 wcd937x_config_regs[] = { 221 static const u32 wcd937x_config_regs[] = { 222 WCD937X_DIGITAL_INTR_LEVEL_0, 222 WCD937X_DIGITAL_INTR_LEVEL_0, 223 }; 223 }; 224 224 225 static const struct regmap_irq_chip wcd937x_re 225 static const struct regmap_irq_chip wcd937x_regmap_irq_chip = { 226 .name = "wcd937x", 226 .name = "wcd937x", 227 .irqs = wcd937x_irqs, 227 .irqs = wcd937x_irqs, 228 .num_irqs = ARRAY_SIZE(wcd937x_irqs), 228 .num_irqs = ARRAY_SIZE(wcd937x_irqs), 229 .num_regs = 3, 229 .num_regs = 3, 230 .status_base = WCD937X_DIGITAL_INTR_ST 230 .status_base = WCD937X_DIGITAL_INTR_STATUS_0, 231 .mask_base = WCD937X_DIGITAL_INTR_MASK 231 .mask_base = WCD937X_DIGITAL_INTR_MASK_0, 232 .ack_base = WCD937X_DIGITAL_INTR_CLEAR 232 .ack_base = WCD937X_DIGITAL_INTR_CLEAR_0, 233 .use_ack = 1, 233 .use_ack = 1, 234 .clear_ack = 1, 234 .clear_ack = 1, 235 .config_base = wcd937x_config_regs, 235 .config_base = wcd937x_config_regs, 236 .num_config_bases = ARRAY_SIZE(wcd937x 236 .num_config_bases = ARRAY_SIZE(wcd937x_config_regs), 237 .num_config_regs = 1, 237 .num_config_regs = 1, 238 .runtime_pm = true, 238 .runtime_pm = true, 239 .handle_post_irq = wcd937x_handle_post 239 .handle_post_irq = wcd937x_handle_post_irq, 240 .irq_drv_data = NULL, 240 .irq_drv_data = NULL, 241 }; 241 }; 242 242 243 static void wcd937x_reset(struct wcd937x_priv 243 static void wcd937x_reset(struct wcd937x_priv *wcd937x) 244 { 244 { 245 gpiod_set_value(wcd937x->reset_gpio, 1 245 gpiod_set_value(wcd937x->reset_gpio, 1); 246 usleep_range(20, 30); 246 usleep_range(20, 30); 247 gpiod_set_value(wcd937x->reset_gpio, 0 247 gpiod_set_value(wcd937x->reset_gpio, 0); 248 usleep_range(20, 30); 248 usleep_range(20, 30); 249 } 249 } 250 250 251 static void wcd937x_io_init(struct regmap *reg 251 static void wcd937x_io_init(struct regmap *regmap) 252 { 252 { 253 u32 val = 0, temp = 0, temp1 = 0; 253 u32 val = 0, temp = 0, temp1 = 0; 254 254 255 regmap_read(regmap, WCD937X_DIGITAL_EF 255 regmap_read(regmap, WCD937X_DIGITAL_EFUSE_REG_29, &val); 256 256 257 val = val & 0x0F; 257 val = val & 0x0F; 258 258 259 regmap_read(regmap, WCD937X_DIGITAL_EF 259 regmap_read(regmap, WCD937X_DIGITAL_EFUSE_REG_16, &temp); 260 regmap_read(regmap, WCD937X_DIGITAL_EF 260 regmap_read(regmap, WCD937X_DIGITAL_EFUSE_REG_17, &temp1); 261 261 262 if (temp == 0x02 || temp1 > 0x09) 262 if (temp == 0x02 || temp1 > 0x09) 263 regmap_update_bits(regmap, WCD 263 regmap_update_bits(regmap, WCD937X_SLEEP_CTL, 0x0E, val); 264 else 264 else 265 regmap_update_bits(regmap, WCD 265 regmap_update_bits(regmap, WCD937X_SLEEP_CTL, 0x0e, 0x0e); 266 266 267 regmap_update_bits(regmap, WCD937X_SLE 267 regmap_update_bits(regmap, WCD937X_SLEEP_CTL, 0x80, 0x80); 268 usleep_range(1000, 1010); 268 usleep_range(1000, 1010); 269 269 270 regmap_update_bits(regmap, WCD937X_SLE 270 regmap_update_bits(regmap, WCD937X_SLEEP_CTL, 0x40, 0x40); 271 usleep_range(1000, 1010); 271 usleep_range(1000, 1010); 272 272 273 regmap_update_bits(regmap, WCD937X_LDO 273 regmap_update_bits(regmap, WCD937X_LDORXTX_CONFIG, BIT(4), 0x00); 274 regmap_update_bits(regmap, WCD937X_BIA 274 regmap_update_bits(regmap, WCD937X_BIAS_VBG_FINE_ADJ, 0xf0, BIT(7)); 275 regmap_update_bits(regmap, WCD937X_ANA 275 regmap_update_bits(regmap, WCD937X_ANA_BIAS, BIT(7), BIT(7)); 276 regmap_update_bits(regmap, WCD937X_ANA 276 regmap_update_bits(regmap, WCD937X_ANA_BIAS, BIT(6), BIT(6)); 277 usleep_range(10000, 10010); 277 usleep_range(10000, 10010); 278 278 279 regmap_update_bits(regmap, WCD937X_ANA 279 regmap_update_bits(regmap, WCD937X_ANA_BIAS, BIT(6), 0x00); 280 regmap_update_bits(regmap, WCD937X_HPH 280 regmap_update_bits(regmap, WCD937X_HPH_SURGE_HPHLR_SURGE_EN, 0xff, 0xd9); 281 regmap_update_bits(regmap, WCD937X_MIC 281 regmap_update_bits(regmap, WCD937X_MICB1_TEST_CTL_1, 0xff, 0xfa); 282 regmap_update_bits(regmap, WCD937X_MIC 282 regmap_update_bits(regmap, WCD937X_MICB2_TEST_CTL_1, 0xff, 0xfa); 283 regmap_update_bits(regmap, WCD937X_MIC 283 regmap_update_bits(regmap, WCD937X_MICB3_TEST_CTL_1, 0xff, 0xfa); 284 284 285 regmap_update_bits(regmap, WCD937X_MIC 285 regmap_update_bits(regmap, WCD937X_MICB1_TEST_CTL_2, 0x38, 0x00); 286 regmap_update_bits(regmap, WCD937X_MIC 286 regmap_update_bits(regmap, WCD937X_MICB2_TEST_CTL_2, 0x38, 0x00); 287 regmap_update_bits(regmap, WCD937X_MIC 287 regmap_update_bits(regmap, WCD937X_MICB3_TEST_CTL_2, 0x38, 0x00); 288 288 289 /* Set Bandgap Fine Adjustment to +5mV 289 /* Set Bandgap Fine Adjustment to +5mV for Tanggu SMIC part */ 290 regmap_read(regmap, WCD937X_DIGITAL_EF 290 regmap_read(regmap, WCD937X_DIGITAL_EFUSE_REG_16, &val); 291 if (val == 0x01) { 291 if (val == 0x01) { 292 regmap_update_bits(regmap, WCD 292 regmap_update_bits(regmap, WCD937X_BIAS_VBG_FINE_ADJ, 0xF0, 0xB0); 293 } else if (val == 0x02) { 293 } else if (val == 0x02) { 294 regmap_update_bits(regmap, WCD 294 regmap_update_bits(regmap, WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L, 0x1F, 0x04); 295 regmap_update_bits(regmap, WCD 295 regmap_update_bits(regmap, WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_R, 0x1F, 0x04); 296 regmap_update_bits(regmap, WCD 296 regmap_update_bits(regmap, WCD937X_BIAS_VBG_FINE_ADJ, 0xF0, 0xB0); 297 regmap_update_bits(regmap, WCD 297 regmap_update_bits(regmap, WCD937X_HPH_NEW_INT_RDAC_GAIN_CTL, 0xF0, 0x50); 298 } 298 } 299 } 299 } 300 300 301 static int wcd937x_rx_clk_enable(struct snd_so 301 static int wcd937x_rx_clk_enable(struct snd_soc_component *component) 302 { 302 { 303 struct wcd937x_priv *wcd937x = snd_soc 303 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 304 304 305 if (atomic_read(&wcd937x->rx_clk_cnt)) 305 if (atomic_read(&wcd937x->rx_clk_cnt)) 306 return 0; 306 return 0; 307 307 308 snd_soc_component_update_bits(componen 308 snd_soc_component_update_bits(component, WCD937X_DIGITAL_CDC_DIG_CLK_CTL, BIT(3), BIT(3)); 309 snd_soc_component_update_bits(componen 309 snd_soc_component_update_bits(component, WCD937X_DIGITAL_CDC_ANA_CLK_CTL, BIT(0), BIT(0)); 310 snd_soc_component_update_bits(componen 310 snd_soc_component_update_bits(component, WCD937X_ANA_RX_SUPPLIES, BIT(0), BIT(0)); 311 snd_soc_component_update_bits(componen 311 snd_soc_component_update_bits(component, WCD937X_DIGITAL_CDC_RX0_CTL, BIT(6), 0x00); 312 snd_soc_component_update_bits(componen 312 snd_soc_component_update_bits(component, WCD937X_DIGITAL_CDC_RX1_CTL, BIT(6), 0x00); 313 snd_soc_component_update_bits(componen 313 snd_soc_component_update_bits(component, WCD937X_DIGITAL_CDC_RX2_CTL, BIT(6), 0x00); 314 snd_soc_component_update_bits(componen 314 snd_soc_component_update_bits(component, WCD937X_DIGITAL_CDC_ANA_CLK_CTL, BIT(1), BIT(1)); 315 315 316 atomic_inc(&wcd937x->rx_clk_cnt); 316 atomic_inc(&wcd937x->rx_clk_cnt); 317 317 318 return 0; 318 return 0; 319 } 319 } 320 320 321 static int wcd937x_rx_clk_disable(struct snd_s 321 static int wcd937x_rx_clk_disable(struct snd_soc_component *component) 322 { 322 { 323 struct wcd937x_priv *wcd937x = snd_soc 323 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 324 324 325 if (!atomic_read(&wcd937x->rx_clk_cnt) 325 if (!atomic_read(&wcd937x->rx_clk_cnt)) { 326 dev_err(component->dev, "clk a 326 dev_err(component->dev, "clk already disabled\n"); 327 return 0; 327 return 0; 328 } 328 } 329 329 330 atomic_dec(&wcd937x->rx_clk_cnt); 330 atomic_dec(&wcd937x->rx_clk_cnt); 331 331 332 snd_soc_component_update_bits(componen 332 snd_soc_component_update_bits(component, WCD937X_ANA_RX_SUPPLIES, BIT(0), 0x00); 333 snd_soc_component_update_bits(componen 333 snd_soc_component_update_bits(component, WCD937X_DIGITAL_CDC_ANA_CLK_CTL, BIT(1), 0x00); 334 snd_soc_component_update_bits(componen 334 snd_soc_component_update_bits(component, WCD937X_DIGITAL_CDC_ANA_CLK_CTL, BIT(0), 0x00); 335 335 336 return 0; 336 return 0; 337 } 337 } 338 338 339 static int wcd937x_codec_hphl_dac_event(struct 339 static int wcd937x_codec_hphl_dac_event(struct snd_soc_dapm_widget *w, 340 struct 340 struct snd_kcontrol *kcontrol, 341 int ev 341 int event) 342 { 342 { 343 struct snd_soc_component *component = 343 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 344 struct wcd937x_priv *wcd937x = snd_soc 344 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 345 int hph_mode = wcd937x->hph_mode; 345 int hph_mode = wcd937x->hph_mode; 346 346 347 switch (event) { 347 switch (event) { 348 case SND_SOC_DAPM_PRE_PMU: 348 case SND_SOC_DAPM_PRE_PMU: 349 wcd937x_rx_clk_enable(componen 349 wcd937x_rx_clk_enable(component); 350 snd_soc_component_update_bits( 350 snd_soc_component_update_bits(component, 351 351 WCD937X_DIGITAL_CDC_DIG_CLK_CTL, 352 352 BIT(0), BIT(0)); 353 snd_soc_component_update_bits( 353 snd_soc_component_update_bits(component, 354 354 WCD937X_DIGITAL_CDC_HPH_GAIN_CTL, 355 355 BIT(2), BIT(2)); 356 snd_soc_component_update_bits( 356 snd_soc_component_update_bits(component, 357 357 WCD937X_HPH_RDAC_CLK_CTL1, 358 358 BIT(7), 0x00); 359 set_bit(HPH_COMP_DELAY, &wcd93 359 set_bit(HPH_COMP_DELAY, &wcd937x->status_mask); 360 break; 360 break; 361 case SND_SOC_DAPM_POST_PMU: 361 case SND_SOC_DAPM_POST_PMU: 362 if (hph_mode == CLS_AB_HIFI || 362 if (hph_mode == CLS_AB_HIFI || hph_mode == CLS_H_HIFI) 363 snd_soc_component_upda 363 snd_soc_component_update_bits(component, 364 364 WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L, 365 365 0x0f, BIT(1)); 366 else if (hph_mode == CLS_H_LOH 366 else if (hph_mode == CLS_H_LOHIFI) 367 snd_soc_component_upda 367 snd_soc_component_update_bits(component, 368 368 WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L, 369 369 0x0f, 0x06); 370 370 371 if (wcd937x->comp1_enable) { 371 if (wcd937x->comp1_enable) { 372 snd_soc_component_upda 372 snd_soc_component_update_bits(component, 373 373 WCD937X_DIGITAL_CDC_COMP_CTL_0, 374 374 BIT(1), BIT(1)); 375 snd_soc_component_upda 375 snd_soc_component_update_bits(component, 376 376 WCD937X_HPH_L_EN, 377 377 BIT(5), 0x00); 378 378 379 if (wcd937x->comp2_ena 379 if (wcd937x->comp2_enable) { 380 snd_soc_compon 380 snd_soc_component_update_bits(component, 381 381 WCD937X_DIGITAL_CDC_COMP_CTL_0, 382 382 BIT(0), BIT(0)); 383 snd_soc_compon 383 snd_soc_component_update_bits(component, 384 384 WCD937X_HPH_R_EN, BIT(5), 0x00); 385 } 385 } 386 386 387 if (test_bit(HPH_COMP_ 387 if (test_bit(HPH_COMP_DELAY, &wcd937x->status_mask)) { 388 usleep_range(5 388 usleep_range(5000, 5110); 389 clear_bit(HPH_ 389 clear_bit(HPH_COMP_DELAY, &wcd937x->status_mask); 390 } 390 } 391 } else { 391 } else { 392 snd_soc_component_upda 392 snd_soc_component_update_bits(component, 393 393 WCD937X_DIGITAL_CDC_COMP_CTL_0, 394 394 BIT(1), 0x00); 395 snd_soc_component_upda 395 snd_soc_component_update_bits(component, 396 396 WCD937X_HPH_L_EN, 397 397 BIT(5), BIT(5)); 398 } 398 } 399 399 400 snd_soc_component_update_bits( 400 snd_soc_component_update_bits(component, 401 401 WCD937X_HPH_NEW_INT_HPH_TIMER1, 402 402 BIT(1), 0x00); 403 break; 403 break; 404 case SND_SOC_DAPM_POST_PMD: 404 case SND_SOC_DAPM_POST_PMD: 405 snd_soc_component_update_bits( 405 snd_soc_component_update_bits(component, 406 406 WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L, 407 407 0x0f, BIT(0)); 408 break; 408 break; 409 } 409 } 410 410 411 return 0; 411 return 0; 412 } 412 } 413 413 414 static int wcd937x_codec_hphr_dac_event(struct 414 static int wcd937x_codec_hphr_dac_event(struct snd_soc_dapm_widget *w, 415 struct 415 struct snd_kcontrol *kcontrol, 416 int ev 416 int event) 417 { 417 { 418 struct snd_soc_component *component = 418 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 419 struct wcd937x_priv *wcd937x = snd_soc 419 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 420 int hph_mode = wcd937x->hph_mode; 420 int hph_mode = wcd937x->hph_mode; 421 421 422 switch (event) { 422 switch (event) { 423 case SND_SOC_DAPM_PRE_PMU: 423 case SND_SOC_DAPM_PRE_PMU: 424 wcd937x_rx_clk_enable(componen 424 wcd937x_rx_clk_enable(component); 425 snd_soc_component_update_bits( 425 snd_soc_component_update_bits(component, 426 426 WCD937X_DIGITAL_CDC_DIG_CLK_CTL, BIT(1), BIT(1)); 427 snd_soc_component_update_bits( 427 snd_soc_component_update_bits(component, 428 428 WCD937X_DIGITAL_CDC_HPH_GAIN_CTL, BIT(3), BIT(3)); 429 snd_soc_component_update_bits( 429 snd_soc_component_update_bits(component, 430 430 WCD937X_HPH_RDAC_CLK_CTL1, BIT(7), 0x00); 431 set_bit(HPH_COMP_DELAY, &wcd93 431 set_bit(HPH_COMP_DELAY, &wcd937x->status_mask); 432 break; 432 break; 433 case SND_SOC_DAPM_POST_PMU: 433 case SND_SOC_DAPM_POST_PMU: 434 if (hph_mode == CLS_AB_HIFI || 434 if (hph_mode == CLS_AB_HIFI || hph_mode == CLS_H_HIFI) 435 snd_soc_component_upda 435 snd_soc_component_update_bits(component, 436 436 WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_R, 437 437 0x0f, BIT(1)); 438 else if (hph_mode == CLS_H_LOH 438 else if (hph_mode == CLS_H_LOHIFI) 439 snd_soc_component_upda 439 snd_soc_component_update_bits(component, 440 440 WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_R, 441 441 0x0f, 0x06); 442 if (wcd937x->comp2_enable) { 442 if (wcd937x->comp2_enable) { 443 snd_soc_component_upda 443 snd_soc_component_update_bits(component, 444 444 WCD937X_DIGITAL_CDC_COMP_CTL_0, 445 445 BIT(0), BIT(0)); 446 snd_soc_component_upda 446 snd_soc_component_update_bits(component, 447 447 WCD937X_HPH_R_EN, BIT(5), 0x00); 448 if (wcd937x->comp1_ena 448 if (wcd937x->comp1_enable) { 449 snd_soc_compon 449 snd_soc_component_update_bits(component, 450 450 WCD937X_DIGITAL_CDC_COMP_CTL_0, 451 451 BIT(1), BIT(1)); 452 snd_soc_compon 452 snd_soc_component_update_bits(component, 453 453 WCD937X_HPH_L_EN, 454 454 BIT(5), 0x00); 455 } 455 } 456 456 457 if (test_bit(HPH_COMP_ 457 if (test_bit(HPH_COMP_DELAY, &wcd937x->status_mask)) { 458 usleep_range(5 458 usleep_range(5000, 5110); 459 clear_bit(HPH_ 459 clear_bit(HPH_COMP_DELAY, &wcd937x->status_mask); 460 } 460 } 461 } else { 461 } else { 462 snd_soc_component_upda 462 snd_soc_component_update_bits(component, 463 463 WCD937X_DIGITAL_CDC_COMP_CTL_0, 464 464 BIT(0), 0x00); 465 snd_soc_component_upda 465 snd_soc_component_update_bits(component, 466 466 WCD937X_HPH_R_EN, 467 467 BIT(5), BIT(5)); 468 } 468 } 469 snd_soc_component_update_bits( 469 snd_soc_component_update_bits(component, 470 470 WCD937X_HPH_NEW_INT_HPH_TIMER1, 471 471 BIT(1), 0x00); 472 break; 472 break; 473 case SND_SOC_DAPM_POST_PMD: 473 case SND_SOC_DAPM_POST_PMD: 474 snd_soc_component_update_bits( 474 snd_soc_component_update_bits(component, 475 475 WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_R, 476 476 0x0f, BIT(0)); 477 break; 477 break; 478 } 478 } 479 479 480 return 0; 480 return 0; 481 } 481 } 482 482 483 static int wcd937x_codec_ear_dac_event(struct 483 static int wcd937x_codec_ear_dac_event(struct snd_soc_dapm_widget *w, 484 struct 484 struct snd_kcontrol *kcontrol, 485 int eve 485 int event) 486 { 486 { 487 struct snd_soc_component *component = 487 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 488 struct wcd937x_priv *wcd937x = snd_soc 488 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 489 int hph_mode = wcd937x->hph_mode; 489 int hph_mode = wcd937x->hph_mode; 490 490 491 switch (event) { 491 switch (event) { 492 case SND_SOC_DAPM_PRE_PMU: 492 case SND_SOC_DAPM_PRE_PMU: 493 wcd937x_rx_clk_enable(componen 493 wcd937x_rx_clk_enable(component); 494 snd_soc_component_update_bits( 494 snd_soc_component_update_bits(component, 495 495 WCD937X_DIGITAL_CDC_HPH_GAIN_CTL, 496 496 BIT(2), BIT(2)); 497 snd_soc_component_update_bits( 497 snd_soc_component_update_bits(component, 498 498 WCD937X_DIGITAL_CDC_DIG_CLK_CTL, 499 499 BIT(0), BIT(0)); 500 500 501 if (hph_mode == CLS_AB_HIFI || 501 if (hph_mode == CLS_AB_HIFI || hph_mode == CLS_H_HIFI) 502 snd_soc_component_upda 502 snd_soc_component_update_bits(component, 503 503 WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L, 504 504 0x0f, BIT(1)); 505 else if (hph_mode == CLS_H_LOH 505 else if (hph_mode == CLS_H_LOHIFI) 506 snd_soc_component_upda 506 snd_soc_component_update_bits(component, 507 507 WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L, 508 508 0x0f, 0x06); 509 if (wcd937x->comp1_enable) 509 if (wcd937x->comp1_enable) 510 snd_soc_component_upda 510 snd_soc_component_update_bits(component, 511 511 WCD937X_DIGITAL_CDC_COMP_CTL_0, 512 512 BIT(1), BIT(1)); 513 usleep_range(5000, 5010); 513 usleep_range(5000, 5010); 514 514 515 snd_soc_component_update_bits( 515 snd_soc_component_update_bits(component, WCD937X_FLYBACK_EN, BIT(2), 0x00); 516 wcd_clsh_ctrl_set_state(wcd937 516 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, 517 WCD_CL 517 WCD_CLSH_EVENT_PRE_DAC, 518 WCD_CL 518 WCD_CLSH_STATE_EAR, 519 hph_mo 519 hph_mode); 520 520 521 break; 521 break; 522 case SND_SOC_DAPM_POST_PMD: 522 case SND_SOC_DAPM_POST_PMD: 523 if (hph_mode == CLS_AB_HIFI || 523 if (hph_mode == CLS_AB_HIFI || hph_mode == CLS_H_LOHIFI || 524 hph_mode == CLS_H_HIFI) 524 hph_mode == CLS_H_HIFI) 525 snd_soc_component_upda 525 snd_soc_component_update_bits(component, 526 526 WCD937X_HPH_NEW_INT_RDAC_HD2_CTL_L, 527 527 0x0f, BIT(0)); 528 if (wcd937x->comp1_enable) 528 if (wcd937x->comp1_enable) 529 snd_soc_component_upda 529 snd_soc_component_update_bits(component, 530 530 WCD937X_DIGITAL_CDC_COMP_CTL_0, 531 531 BIT(1), 0x00); 532 break; 532 break; 533 } 533 } 534 534 535 return 0; 535 return 0; 536 } 536 } 537 537 538 static int wcd937x_codec_aux_dac_event(struct 538 static int wcd937x_codec_aux_dac_event(struct snd_soc_dapm_widget *w, 539 struct 539 struct snd_kcontrol *kcontrol, 540 int eve 540 int event) 541 { 541 { 542 struct snd_soc_component *component = 542 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 543 struct wcd937x_priv *wcd937x = snd_soc 543 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 544 int hph_mode = wcd937x->hph_mode; 544 int hph_mode = wcd937x->hph_mode; 545 545 546 switch (event) { 546 switch (event) { 547 case SND_SOC_DAPM_PRE_PMU: 547 case SND_SOC_DAPM_PRE_PMU: 548 wcd937x_rx_clk_enable(componen 548 wcd937x_rx_clk_enable(component); 549 snd_soc_component_update_bits( 549 snd_soc_component_update_bits(component, 550 550 WCD937X_DIGITAL_CDC_ANA_CLK_CTL, 551 551 BIT(2), BIT(2)); 552 snd_soc_component_update_bits( 552 snd_soc_component_update_bits(component, 553 553 WCD937X_DIGITAL_CDC_DIG_CLK_CTL, 554 554 BIT(2), BIT(2)); 555 snd_soc_component_update_bits( 555 snd_soc_component_update_bits(component, 556 556 WCD937X_DIGITAL_CDC_AUX_GAIN_CTL, 557 557 BIT(0), BIT(0)); 558 wcd_clsh_ctrl_set_state(wcd937 558 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, 559 WCD_CL 559 WCD_CLSH_EVENT_PRE_DAC, 560 WCD_CL 560 WCD_CLSH_STATE_AUX, 561 hph_mo 561 hph_mode); 562 562 563 break; 563 break; 564 case SND_SOC_DAPM_POST_PMD: 564 case SND_SOC_DAPM_POST_PMD: 565 snd_soc_component_update_bits( 565 snd_soc_component_update_bits(component, 566 566 WCD937X_DIGITAL_CDC_ANA_CLK_CTL, 567 567 BIT(2), 0x00); 568 break; 568 break; 569 } 569 } 570 570 571 return 0; 571 return 0; 572 } 572 } 573 573 574 static int wcd937x_codec_enable_hphr_pa(struct 574 static int wcd937x_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w, 575 struct 575 struct snd_kcontrol *kcontrol, 576 int ev 576 int event) 577 { 577 { 578 struct snd_soc_component *component = 578 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 579 struct wcd937x_priv *wcd937x = snd_soc 579 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 580 int hph_mode = wcd937x->hph_mode; 580 int hph_mode = wcd937x->hph_mode; 581 581 582 switch (event) { 582 switch (event) { 583 case SND_SOC_DAPM_PRE_PMU: 583 case SND_SOC_DAPM_PRE_PMU: 584 wcd_clsh_ctrl_set_state(wcd937 584 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, 585 WCD_CL 585 WCD_CLSH_EVENT_PRE_DAC, 586 WCD_CL 586 WCD_CLSH_STATE_HPHR, 587 hph_mo 587 hph_mode); 588 snd_soc_component_update_bits( 588 snd_soc_component_update_bits(component, WCD937X_ANA_HPH, 589 589 BIT(4), BIT(4)); 590 usleep_range(100, 110); 590 usleep_range(100, 110); 591 set_bit(HPH_PA_DELAY, &wcd937x 591 set_bit(HPH_PA_DELAY, &wcd937x->status_mask); 592 snd_soc_component_update_bits( 592 snd_soc_component_update_bits(component, 593 593 WCD937X_DIGITAL_PDM_WD_CTL1, 594 594 0x07, 0x03); 595 break; 595 break; 596 case SND_SOC_DAPM_POST_PMU: 596 case SND_SOC_DAPM_POST_PMU: 597 if (test_bit(HPH_PA_DELAY, &wc 597 if (test_bit(HPH_PA_DELAY, &wcd937x->status_mask)) { 598 if (wcd937x->comp2_ena 598 if (wcd937x->comp2_enable) 599 usleep_range(7 599 usleep_range(7000, 7100); 600 else 600 else 601 usleep_range(2 601 usleep_range(20000, 20100); 602 clear_bit(HPH_PA_DELAY 602 clear_bit(HPH_PA_DELAY, &wcd937x->status_mask); 603 } 603 } 604 604 605 snd_soc_component_update_bits( 605 snd_soc_component_update_bits(component, 606 606 WCD937X_HPH_NEW_INT_HPH_TIMER1, 607 607 BIT(1), BIT(1)); 608 if (hph_mode == CLS_AB || hph_ 608 if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI) 609 snd_soc_component_upda 609 snd_soc_component_update_bits(component, 610 610 WCD937X_ANA_RX_SUPPLIES, 611 611 BIT(1), BIT(1)); 612 enable_irq(wcd937x->hphr_pdm_w 612 enable_irq(wcd937x->hphr_pdm_wd_int); 613 break; 613 break; 614 case SND_SOC_DAPM_PRE_PMD: 614 case SND_SOC_DAPM_PRE_PMD: 615 disable_irq_nosync(wcd937x->hp 615 disable_irq_nosync(wcd937x->hphr_pdm_wd_int); 616 set_bit(HPH_PA_DELAY, &wcd937x 616 set_bit(HPH_PA_DELAY, &wcd937x->status_mask); 617 wcd_mbhc_event_notify(wcd937x- 617 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, WCD_EVENT_PRE_HPHR_PA_OFF); 618 break; 618 break; 619 case SND_SOC_DAPM_POST_PMD: 619 case SND_SOC_DAPM_POST_PMD: 620 if (test_bit(HPH_PA_DELAY, &wc 620 if (test_bit(HPH_PA_DELAY, &wcd937x->status_mask)) { 621 if (wcd937x->comp2_ena 621 if (wcd937x->comp2_enable) 622 usleep_range(7 622 usleep_range(7000, 7100); 623 else 623 else 624 usleep_range(2 624 usleep_range(20000, 20100); 625 clear_bit(HPH_PA_DELAY 625 clear_bit(HPH_PA_DELAY, &wcd937x->status_mask); 626 } 626 } 627 627 628 wcd_mbhc_event_notify(wcd937x- 628 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, WCD_EVENT_POST_HPHR_PA_OFF); 629 snd_soc_component_update_bits( 629 snd_soc_component_update_bits(component, 630 630 WCD937X_DIGITAL_PDM_WD_CTL1, 0x07, 0x00); 631 snd_soc_component_update_bits( 631 snd_soc_component_update_bits(component, WCD937X_ANA_HPH, 632 632 BIT(4), 0x00); 633 wcd_clsh_ctrl_set_state(wcd937 633 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, 634 WCD_CL 634 WCD_CLSH_EVENT_POST_PA, 635 WCD_CL 635 WCD_CLSH_STATE_HPHR, 636 hph_mo 636 hph_mode); 637 break; 637 break; 638 } 638 } 639 639 640 return 0; 640 return 0; 641 } 641 } 642 642 643 static int wcd937x_codec_enable_hphl_pa(struct 643 static int wcd937x_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w, 644 struct 644 struct snd_kcontrol *kcontrol, 645 int ev 645 int event) 646 { 646 { 647 struct snd_soc_component *component = 647 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 648 struct wcd937x_priv *wcd937x = snd_soc 648 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 649 int hph_mode = wcd937x->hph_mode; 649 int hph_mode = wcd937x->hph_mode; 650 650 651 switch (event) { 651 switch (event) { 652 case SND_SOC_DAPM_PRE_PMU: 652 case SND_SOC_DAPM_PRE_PMU: 653 wcd_clsh_ctrl_set_state(wcd937 653 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, 654 WCD_CL 654 WCD_CLSH_EVENT_PRE_DAC, 655 WCD_CL 655 WCD_CLSH_STATE_HPHL, 656 hph_mo 656 hph_mode); 657 snd_soc_component_update_bits( 657 snd_soc_component_update_bits(component, WCD937X_ANA_HPH, 658 658 BIT(5), BIT(5)); 659 usleep_range(100, 110); 659 usleep_range(100, 110); 660 set_bit(HPH_PA_DELAY, &wcd937x 660 set_bit(HPH_PA_DELAY, &wcd937x->status_mask); 661 snd_soc_component_update_bits( 661 snd_soc_component_update_bits(component, 662 662 WCD937X_DIGITAL_PDM_WD_CTL0, 0x07, 0x03); 663 break; 663 break; 664 case SND_SOC_DAPM_POST_PMU: 664 case SND_SOC_DAPM_POST_PMU: 665 if (test_bit(HPH_PA_DELAY, &wc 665 if (test_bit(HPH_PA_DELAY, &wcd937x->status_mask)) { 666 if (!wcd937x->comp1_en 666 if (!wcd937x->comp1_enable) 667 usleep_range(2 667 usleep_range(20000, 20100); 668 else 668 else 669 usleep_range(7 669 usleep_range(7000, 7100); 670 clear_bit(HPH_PA_DELAY 670 clear_bit(HPH_PA_DELAY, &wcd937x->status_mask); 671 } 671 } 672 672 673 snd_soc_component_update_bits( 673 snd_soc_component_update_bits(component, 674 674 WCD937X_HPH_NEW_INT_HPH_TIMER1, 675 675 BIT(1), BIT(1)); 676 if (hph_mode == CLS_AB || hph_ 676 if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI) 677 snd_soc_component_upda 677 snd_soc_component_update_bits(component, 678 678 WCD937X_ANA_RX_SUPPLIES, 679 679 BIT(1), BIT(1)); 680 enable_irq(wcd937x->hphl_pdm_w 680 enable_irq(wcd937x->hphl_pdm_wd_int); 681 break; 681 break; 682 case SND_SOC_DAPM_PRE_PMD: 682 case SND_SOC_DAPM_PRE_PMD: 683 disable_irq_nosync(wcd937x->hp 683 disable_irq_nosync(wcd937x->hphl_pdm_wd_int); 684 set_bit(HPH_PA_DELAY, &wcd937x 684 set_bit(HPH_PA_DELAY, &wcd937x->status_mask); 685 wcd_mbhc_event_notify(wcd937x- 685 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, WCD_EVENT_PRE_HPHL_PA_OFF); 686 break; 686 break; 687 case SND_SOC_DAPM_POST_PMD: 687 case SND_SOC_DAPM_POST_PMD: 688 if (test_bit(HPH_PA_DELAY, &wc 688 if (test_bit(HPH_PA_DELAY, &wcd937x->status_mask)) { 689 if (!wcd937x->comp1_en 689 if (!wcd937x->comp1_enable) 690 usleep_range(2 690 usleep_range(20000, 20100); 691 else 691 else 692 usleep_range(7 692 usleep_range(7000, 7100); 693 clear_bit(HPH_PA_DELAY 693 clear_bit(HPH_PA_DELAY, &wcd937x->status_mask); 694 } 694 } 695 695 696 wcd_mbhc_event_notify(wcd937x- 696 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, WCD_EVENT_POST_HPHL_PA_OFF); 697 snd_soc_component_update_bits( 697 snd_soc_component_update_bits(component, 698 698 WCD937X_DIGITAL_PDM_WD_CTL0, 0x07, 0x00); 699 snd_soc_component_update_bits( 699 snd_soc_component_update_bits(component, 700 700 WCD937X_ANA_HPH, BIT(5), 0x00); 701 wcd_clsh_ctrl_set_state(wcd937 701 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, 702 WCD_CL 702 WCD_CLSH_EVENT_POST_PA, 703 WCD_CL 703 WCD_CLSH_STATE_HPHL, 704 hph_mo 704 hph_mode); 705 break; 705 break; 706 } 706 } 707 707 708 return 0; 708 return 0; 709 } 709 } 710 710 711 static int wcd937x_codec_enable_aux_pa(struct 711 static int wcd937x_codec_enable_aux_pa(struct snd_soc_dapm_widget *w, 712 struct 712 struct snd_kcontrol *kcontrol, 713 int eve 713 int event) 714 { 714 { 715 struct snd_soc_component *component = 715 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 716 struct wcd937x_priv *wcd937x = snd_soc 716 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 717 int hph_mode = wcd937x->hph_mode; 717 int hph_mode = wcd937x->hph_mode; 718 u8 val; << 719 718 720 switch (event) { 719 switch (event) { 721 case SND_SOC_DAPM_PRE_PMU: 720 case SND_SOC_DAPM_PRE_PMU: 722 val = WCD937X_DIGITAL_PDM_WD_C << 723 WCD937X_DIGITAL_PDM_WD_C << 724 WCD937X_DIGITAL_PDM_WD_C << 725 snd_soc_component_update_bits( 721 snd_soc_component_update_bits(component, 726 722 WCD937X_DIGITAL_PDM_WD_CTL2, 727 !! 723 BIT(0), BIT(0)); 728 << 729 break; 724 break; 730 case SND_SOC_DAPM_POST_PMU: 725 case SND_SOC_DAPM_POST_PMU: 731 usleep_range(1000, 1010); 726 usleep_range(1000, 1010); 732 if (hph_mode == CLS_AB || hph_ 727 if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI) 733 snd_soc_component_upda 728 snd_soc_component_update_bits(component, 734 729 WCD937X_ANA_RX_SUPPLIES, 735 730 BIT(1), BIT(1)); 736 enable_irq(wcd937x->aux_pdm_wd 731 enable_irq(wcd937x->aux_pdm_wd_int); 737 break; 732 break; 738 case SND_SOC_DAPM_PRE_PMD: 733 case SND_SOC_DAPM_PRE_PMD: 739 disable_irq_nosync(wcd937x->au 734 disable_irq_nosync(wcd937x->aux_pdm_wd_int); 740 break; 735 break; 741 case SND_SOC_DAPM_POST_PMD: 736 case SND_SOC_DAPM_POST_PMD: 742 usleep_range(2000, 2010); 737 usleep_range(2000, 2010); 743 wcd_clsh_ctrl_set_state(wcd937 738 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, 744 WCD_CL 739 WCD_CLSH_EVENT_POST_PA, 745 WCD_CL 740 WCD_CLSH_STATE_AUX, 746 hph_mo 741 hph_mode); 747 snd_soc_component_update_bits( 742 snd_soc_component_update_bits(component, 748 743 WCD937X_DIGITAL_PDM_WD_CTL2, 749 !! 744 BIT(0), 0x00); 750 << 751 break; 745 break; 752 } 746 } 753 747 754 return 0; 748 return 0; 755 } 749 } 756 750 757 static int wcd937x_codec_enable_ear_pa(struct 751 static int wcd937x_codec_enable_ear_pa(struct snd_soc_dapm_widget *w, 758 struct 752 struct snd_kcontrol *kcontrol, 759 int eve 753 int event) 760 { 754 { 761 struct snd_soc_component *component = 755 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 762 struct wcd937x_priv *wcd937x = snd_soc 756 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 763 int hph_mode = wcd937x->hph_mode; 757 int hph_mode = wcd937x->hph_mode; 764 758 765 switch (event) { 759 switch (event) { 766 case SND_SOC_DAPM_PRE_PMU: 760 case SND_SOC_DAPM_PRE_PMU: 767 /* Enable watchdog interrupt f 761 /* Enable watchdog interrupt for HPHL or AUX depending on mux value */ 768 wcd937x->ear_rx_path = snd_soc 762 wcd937x->ear_rx_path = snd_soc_component_read(component, 769 763 WCD937X_DIGITAL_CDC_EAR_PATH_CTL); 770 764 771 if (wcd937x->ear_rx_path & EAR 765 if (wcd937x->ear_rx_path & EAR_RX_PATH_AUX) 772 snd_soc_component_upda 766 snd_soc_component_update_bits(component, 773 767 WCD937X_DIGITAL_PDM_WD_CTL2, 774 768 BIT(0), BIT(0)); 775 else 769 else 776 snd_soc_component_upda 770 snd_soc_component_update_bits(component, 777 771 WCD937X_DIGITAL_PDM_WD_CTL0, 778 772 0x07, 0x03); 779 if (!wcd937x->comp1_enable) 773 if (!wcd937x->comp1_enable) 780 snd_soc_component_upda 774 snd_soc_component_update_bits(component, 781 775 WCD937X_ANA_EAR_COMPANDER_CTL, 782 776 BIT(7), BIT(7)); 783 break; 777 break; 784 case SND_SOC_DAPM_POST_PMU: 778 case SND_SOC_DAPM_POST_PMU: 785 usleep_range(6000, 6010); 779 usleep_range(6000, 6010); 786 if (hph_mode == CLS_AB || hph_ 780 if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI) 787 snd_soc_component_upda 781 snd_soc_component_update_bits(component, 788 782 WCD937X_ANA_RX_SUPPLIES, 789 783 BIT(1), BIT(1)); 790 784 791 if (wcd937x->ear_rx_path & EAR 785 if (wcd937x->ear_rx_path & EAR_RX_PATH_AUX) 792 enable_irq(wcd937x->au 786 enable_irq(wcd937x->aux_pdm_wd_int); 793 else 787 else 794 enable_irq(wcd937x->hp 788 enable_irq(wcd937x->hphl_pdm_wd_int); 795 break; 789 break; 796 case SND_SOC_DAPM_PRE_PMD: 790 case SND_SOC_DAPM_PRE_PMD: 797 if (wcd937x->ear_rx_path & EAR 791 if (wcd937x->ear_rx_path & EAR_RX_PATH_AUX) 798 disable_irq_nosync(wcd 792 disable_irq_nosync(wcd937x->aux_pdm_wd_int); 799 else 793 else 800 disable_irq_nosync(wcd 794 disable_irq_nosync(wcd937x->hphl_pdm_wd_int); 801 break; 795 break; 802 case SND_SOC_DAPM_POST_PMD: 796 case SND_SOC_DAPM_POST_PMD: 803 if (!wcd937x->comp1_enable) 797 if (!wcd937x->comp1_enable) 804 snd_soc_component_upda 798 snd_soc_component_update_bits(component, 805 799 WCD937X_ANA_EAR_COMPANDER_CTL, 806 800 BIT(7), 0x00); 807 usleep_range(7000, 7010); 801 usleep_range(7000, 7010); 808 wcd_clsh_ctrl_set_state(wcd937 802 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, 809 WCD_CL 803 WCD_CLSH_EVENT_POST_PA, 810 WCD_CL 804 WCD_CLSH_STATE_EAR, 811 hph_mo 805 hph_mode); 812 snd_soc_component_update_bits( 806 snd_soc_component_update_bits(component, WCD937X_FLYBACK_EN, 813 807 BIT(2), BIT(2)); 814 808 815 if (wcd937x->ear_rx_path & EAR 809 if (wcd937x->ear_rx_path & EAR_RX_PATH_AUX) 816 snd_soc_component_upda 810 snd_soc_component_update_bits(component, 817 811 WCD937X_DIGITAL_PDM_WD_CTL2, 818 812 BIT(0), 0x00); 819 else 813 else 820 snd_soc_component_upda 814 snd_soc_component_update_bits(component, 821 815 WCD937X_DIGITAL_PDM_WD_CTL0, 822 816 0x07, 0x00); 823 break; 817 break; 824 } 818 } 825 819 826 return 0; 820 return 0; 827 } 821 } 828 822 829 static int wcd937x_enable_rx1(struct snd_soc_d 823 static int wcd937x_enable_rx1(struct snd_soc_dapm_widget *w, 830 struct snd_kcont 824 struct snd_kcontrol *kcontrol, 831 int event) 825 int event) 832 { 826 { 833 struct snd_soc_component *component = 827 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 834 828 835 if (event == SND_SOC_DAPM_POST_PMD) { 829 if (event == SND_SOC_DAPM_POST_PMD) { 836 wcd937x_rx_clk_disable(compone 830 wcd937x_rx_clk_disable(component); 837 snd_soc_component_update_bits( 831 snd_soc_component_update_bits(component, 838 832 WCD937X_DIGITAL_CDC_DIG_CLK_CTL, 839 833 BIT(0), 0x00); 840 } 834 } 841 835 842 return 0; 836 return 0; 843 } 837 } 844 838 845 static int wcd937x_enable_rx2(struct snd_soc_d 839 static int wcd937x_enable_rx2(struct snd_soc_dapm_widget *w, 846 struct snd_kcont 840 struct snd_kcontrol *kcontrol, int event) 847 { 841 { 848 struct snd_soc_component *component = 842 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 849 843 850 if (event == SND_SOC_DAPM_POST_PMD) { 844 if (event == SND_SOC_DAPM_POST_PMD) { 851 wcd937x_rx_clk_disable(compone 845 wcd937x_rx_clk_disable(component); 852 snd_soc_component_update_bits( 846 snd_soc_component_update_bits(component, 853 847 WCD937X_DIGITAL_CDC_DIG_CLK_CTL, 854 848 BIT(1), 0x00); 855 } 849 } 856 850 857 return 0; 851 return 0; 858 } 852 } 859 853 860 static int wcd937x_enable_rx3(struct snd_soc_d 854 static int wcd937x_enable_rx3(struct snd_soc_dapm_widget *w, 861 struct snd_kcont 855 struct snd_kcontrol *kcontrol, 862 int event) 856 int event) 863 { 857 { 864 struct snd_soc_component *component = 858 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 865 859 866 if (event == SND_SOC_DAPM_POST_PMD) { 860 if (event == SND_SOC_DAPM_POST_PMD) { 867 usleep_range(6000, 6010); 861 usleep_range(6000, 6010); 868 wcd937x_rx_clk_disable(compone 862 wcd937x_rx_clk_disable(component); 869 snd_soc_component_update_bits( 863 snd_soc_component_update_bits(component, 870 864 WCD937X_DIGITAL_CDC_DIG_CLK_CTL, 871 865 BIT(2), 0x00); 872 } 866 } 873 867 874 return 0; 868 return 0; 875 } 869 } 876 870 877 static int wcd937x_get_micb_vout_ctl_val(u32 m 871 static int wcd937x_get_micb_vout_ctl_val(u32 micb_mv) 878 { 872 { 879 if (micb_mv < 1000 || micb_mv > 2850) 873 if (micb_mv < 1000 || micb_mv > 2850) { 880 pr_err("Unsupported micbias vo 874 pr_err("Unsupported micbias voltage (%u mV)\n", micb_mv); 881 return -EINVAL; 875 return -EINVAL; 882 } 876 } 883 877 884 return (micb_mv - 1000) / 50; 878 return (micb_mv - 1000) / 50; 885 } 879 } 886 880 887 static int wcd937x_tx_swr_ctrl(struct snd_soc_ 881 static int wcd937x_tx_swr_ctrl(struct snd_soc_dapm_widget *w, 888 struct snd_kcon 882 struct snd_kcontrol *kcontrol, int event) 889 { 883 { 890 struct snd_soc_component *component = 884 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 891 struct wcd937x_priv *wcd937x = snd_soc 885 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 892 bool use_amic3 = snd_soc_component_rea 886 bool use_amic3 = snd_soc_component_read(component, WCD937X_TX_NEW_TX_CH2_SEL) & BIT(7); 893 887 894 /* Enable BCS for Headset mic */ 888 /* Enable BCS for Headset mic */ 895 if (event == SND_SOC_DAPM_PRE_PMU && s 889 if (event == SND_SOC_DAPM_PRE_PMU && strnstr(w->name, "ADC", sizeof("ADC"))) 896 if (w->shift == 1 && !use_amic 890 if (w->shift == 1 && !use_amic3) 897 set_bit(AMIC2_BCS_ENAB 891 set_bit(AMIC2_BCS_ENABLE, &wcd937x->status_mask); 898 892 899 return 0; 893 return 0; 900 } 894 } 901 895 902 static int wcd937x_codec_enable_adc(struct snd 896 static int wcd937x_codec_enable_adc(struct snd_soc_dapm_widget *w, 903 struct snd 897 struct snd_kcontrol *kcontrol, int event) 904 { 898 { 905 struct snd_soc_component *component = 899 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 906 struct wcd937x_priv *wcd937x = snd_soc 900 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 907 901 908 switch (event) { 902 switch (event) { 909 case SND_SOC_DAPM_PRE_PMU: 903 case SND_SOC_DAPM_PRE_PMU: 910 atomic_inc(&wcd937x->ana_clk_c 904 atomic_inc(&wcd937x->ana_clk_count); 911 snd_soc_component_update_bits( 905 snd_soc_component_update_bits(component, 912 906 WCD937X_DIGITAL_CDC_DIG_CLK_CTL, BIT(7), BIT(7)); 913 snd_soc_component_update_bits( 907 snd_soc_component_update_bits(component, 914 908 WCD937X_DIGITAL_CDC_ANA_CLK_CTL, BIT(3), BIT(3)); 915 snd_soc_component_update_bits( 909 snd_soc_component_update_bits(component, 916 910 WCD937X_DIGITAL_CDC_ANA_CLK_CTL, BIT(4), BIT(4)); 917 break; 911 break; 918 case SND_SOC_DAPM_POST_PMD: 912 case SND_SOC_DAPM_POST_PMD: 919 if (w->shift == 1 && test_bit( 913 if (w->shift == 1 && test_bit(AMIC2_BCS_ENABLE, &wcd937x->status_mask)) 920 clear_bit(AMIC2_BCS_EN 914 clear_bit(AMIC2_BCS_ENABLE, &wcd937x->status_mask); 921 915 922 snd_soc_component_update_bits( 916 snd_soc_component_update_bits(component, 923 917 WCD937X_DIGITAL_CDC_ANA_CLK_CTL, BIT(3), 0x00); 924 break; 918 break; 925 } 919 } 926 920 927 return 0; 921 return 0; 928 } 922 } 929 923 930 static int wcd937x_enable_req(struct snd_soc_d 924 static int wcd937x_enable_req(struct snd_soc_dapm_widget *w, 931 struct snd_kcont 925 struct snd_kcontrol *kcontrol, int event) 932 { 926 { 933 struct snd_soc_component *component = 927 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 934 struct wcd937x_priv *wcd937x = snd_soc 928 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 935 929 936 switch (event) { 930 switch (event) { 937 case SND_SOC_DAPM_PRE_PMU: 931 case SND_SOC_DAPM_PRE_PMU: 938 snd_soc_component_update_bits( 932 snd_soc_component_update_bits(component, 939 933 WCD937X_DIGITAL_CDC_REQ_CTL, BIT(1), BIT(1)); 940 snd_soc_component_update_bits( 934 snd_soc_component_update_bits(component, 941 935 WCD937X_DIGITAL_CDC_REQ_CTL, BIT(0), 0x00); 942 snd_soc_component_update_bits( 936 snd_soc_component_update_bits(component, 943 937 WCD937X_ANA_TX_CH2, BIT(6), BIT(6)); 944 snd_soc_component_update_bits( 938 snd_soc_component_update_bits(component, 945 939 WCD937X_ANA_TX_CH3_HPF, BIT(6), BIT(6)); 946 snd_soc_component_update_bits( 940 snd_soc_component_update_bits(component, 947 941 WCD937X_DIGITAL_CDC_DIG_CLK_CTL, 0x70, 0x70); 948 snd_soc_component_update_bits( 942 snd_soc_component_update_bits(component, 949 943 WCD937X_ANA_TX_CH1, BIT(7), BIT(7)); 950 snd_soc_component_update_bits( 944 snd_soc_component_update_bits(component, 951 945 WCD937X_ANA_TX_CH2, BIT(6), 0x00); 952 snd_soc_component_update_bits( 946 snd_soc_component_update_bits(component, 953 947 WCD937X_ANA_TX_CH2, BIT(7), BIT(7)); 954 snd_soc_component_update_bits( 948 snd_soc_component_update_bits(component, 955 949 WCD937X_ANA_TX_CH3, BIT(7), BIT(7)); 956 break; 950 break; 957 case SND_SOC_DAPM_POST_PMD: 951 case SND_SOC_DAPM_POST_PMD: 958 snd_soc_component_update_bits( 952 snd_soc_component_update_bits(component, 959 953 WCD937X_ANA_TX_CH1, BIT(7), 0x00); 960 snd_soc_component_update_bits( 954 snd_soc_component_update_bits(component, 961 955 WCD937X_ANA_TX_CH2, BIT(7), 0x00); 962 snd_soc_component_update_bits( 956 snd_soc_component_update_bits(component, 963 957 WCD937X_ANA_TX_CH3, BIT(7), 0x00); 964 snd_soc_component_update_bits( 958 snd_soc_component_update_bits(component, 965 959 WCD937X_DIGITAL_CDC_DIG_CLK_CTL, BIT(4), 0x00); 966 960 967 atomic_dec(&wcd937x->ana_clk_c 961 atomic_dec(&wcd937x->ana_clk_count); 968 if (atomic_read(&wcd937x->ana_ 962 if (atomic_read(&wcd937x->ana_clk_count) <= 0) { 969 snd_soc_component_upda 963 snd_soc_component_update_bits(component, 970 964 WCD937X_DIGITAL_CDC_ANA_CLK_CTL, 971 965 BIT(4), 0x00); 972 atomic_set(&wcd937x->a 966 atomic_set(&wcd937x->ana_clk_count, 0); 973 } 967 } 974 968 975 snd_soc_component_update_bits( 969 snd_soc_component_update_bits(component, 976 970 WCD937X_DIGITAL_CDC_DIG_CLK_CTL, 977 971 BIT(7), 0x00); 978 break; 972 break; 979 } 973 } 980 974 981 return 0; 975 return 0; 982 } 976 } 983 977 984 static int wcd937x_codec_enable_dmic(struct sn 978 static int wcd937x_codec_enable_dmic(struct snd_soc_dapm_widget *w, 985 struct sn 979 struct snd_kcontrol *kcontrol, 986 int event 980 int event) 987 { 981 { 988 struct snd_soc_component *component = 982 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 989 u16 dmic_clk_reg; 983 u16 dmic_clk_reg; 990 984 991 switch (w->shift) { 985 switch (w->shift) { 992 case 0: 986 case 0: 993 case 1: 987 case 1: 994 dmic_clk_reg = WCD937X_DIGITAL 988 dmic_clk_reg = WCD937X_DIGITAL_CDC_DMIC1_CTL; 995 break; 989 break; 996 case 2: 990 case 2: 997 case 3: 991 case 3: 998 dmic_clk_reg = WCD937X_DIGITAL 992 dmic_clk_reg = WCD937X_DIGITAL_CDC_DMIC2_CTL; 999 break; 993 break; 1000 case 4: 994 case 4: 1001 case 5: 995 case 5: 1002 dmic_clk_reg = WCD937X_DIGITA 996 dmic_clk_reg = WCD937X_DIGITAL_CDC_DMIC3_CTL; 1003 break; 997 break; 1004 default: 998 default: 1005 dev_err(component->dev, "Inva 999 dev_err(component->dev, "Invalid DMIC Selection\n"); 1006 return -EINVAL; 1000 return -EINVAL; 1007 } 1001 } 1008 1002 1009 switch (event) { 1003 switch (event) { 1010 case SND_SOC_DAPM_PRE_PMU: 1004 case SND_SOC_DAPM_PRE_PMU: 1011 snd_soc_component_update_bits 1005 snd_soc_component_update_bits(component, 1012 1006 WCD937X_DIGITAL_CDC_DIG_CLK_CTL, 1013 1007 BIT(7), BIT(7)); 1014 snd_soc_component_update_bits 1008 snd_soc_component_update_bits(component, 1015 1009 dmic_clk_reg, 0x07, BIT(1)); 1016 snd_soc_component_update_bits 1010 snd_soc_component_update_bits(component, 1017 1011 dmic_clk_reg, BIT(3), BIT(3)); 1018 snd_soc_component_update_bits 1012 snd_soc_component_update_bits(component, 1019 1013 dmic_clk_reg, 0x70, BIT(5)); 1020 break; 1014 break; 1021 } 1015 } 1022 1016 1023 return 0; 1017 return 0; 1024 } 1018 } 1025 1019 1026 static int wcd937x_micbias_control(struct snd 1020 static int wcd937x_micbias_control(struct snd_soc_component *component, 1027 int micb_n 1021 int micb_num, int req, bool is_dapm) 1028 { 1022 { 1029 struct wcd937x_priv *wcd937x = snd_so 1023 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1030 int micb_index = micb_num - 1; 1024 int micb_index = micb_num - 1; 1031 u16 micb_reg; 1025 u16 micb_reg; 1032 1026 1033 if (micb_index < 0 || (micb_index > W 1027 if (micb_index < 0 || (micb_index > WCD937X_MAX_MICBIAS - 1)) { 1034 dev_err(component->dev, "Inva 1028 dev_err(component->dev, "Invalid micbias index, micb_ind:%d\n", micb_index); 1035 return -EINVAL; 1029 return -EINVAL; 1036 } 1030 } 1037 switch (micb_num) { 1031 switch (micb_num) { 1038 case MIC_BIAS_1: 1032 case MIC_BIAS_1: 1039 micb_reg = WCD937X_ANA_MICB1; 1033 micb_reg = WCD937X_ANA_MICB1; 1040 break; 1034 break; 1041 case MIC_BIAS_2: 1035 case MIC_BIAS_2: 1042 micb_reg = WCD937X_ANA_MICB2; 1036 micb_reg = WCD937X_ANA_MICB2; 1043 break; 1037 break; 1044 case MIC_BIAS_3: 1038 case MIC_BIAS_3: 1045 micb_reg = WCD937X_ANA_MICB3; 1039 micb_reg = WCD937X_ANA_MICB3; 1046 break; 1040 break; 1047 default: 1041 default: 1048 dev_err(component->dev, "Inva 1042 dev_err(component->dev, "Invalid micbias number: %d\n", micb_num); 1049 return -EINVAL; 1043 return -EINVAL; 1050 } 1044 } 1051 1045 1052 mutex_lock(&wcd937x->micb_lock); 1046 mutex_lock(&wcd937x->micb_lock); 1053 switch (req) { 1047 switch (req) { 1054 case MICB_PULLUP_ENABLE: 1048 case MICB_PULLUP_ENABLE: 1055 wcd937x->pullup_ref[micb_inde 1049 wcd937x->pullup_ref[micb_index]++; 1056 if (wcd937x->pullup_ref[micb_ 1050 if (wcd937x->pullup_ref[micb_index] == 1 && 1057 wcd937x->micb_ref[micb_in 1051 wcd937x->micb_ref[micb_index] == 0) 1058 snd_soc_component_upd 1052 snd_soc_component_update_bits(component, micb_reg, 1059 1053 0xc0, BIT(7)); 1060 break; 1054 break; 1061 case MICB_PULLUP_DISABLE: 1055 case MICB_PULLUP_DISABLE: 1062 if (wcd937x->pullup_ref[micb_ 1056 if (wcd937x->pullup_ref[micb_index] > 0) 1063 wcd937x->pullup_ref[m 1057 wcd937x->pullup_ref[micb_index]++; 1064 if (wcd937x->pullup_ref[micb_ 1058 if (wcd937x->pullup_ref[micb_index] == 0 && 1065 wcd937x->micb_ref[micb_in 1059 wcd937x->micb_ref[micb_index] == 0) 1066 snd_soc_component_upd 1060 snd_soc_component_update_bits(component, micb_reg, 1067 1061 0xc0, 0x00); 1068 break; 1062 break; 1069 case MICB_ENABLE: 1063 case MICB_ENABLE: 1070 wcd937x->micb_ref[micb_index] 1064 wcd937x->micb_ref[micb_index]++; 1071 atomic_inc(&wcd937x->ana_clk_ 1065 atomic_inc(&wcd937x->ana_clk_count); 1072 if (wcd937x->micb_ref[micb_in 1066 if (wcd937x->micb_ref[micb_index] == 1) { 1073 snd_soc_component_upd 1067 snd_soc_component_update_bits(component, 1074 1068 WCD937X_DIGITAL_CDC_DIG_CLK_CTL, 1075 1069 0xf0, 0xf0); 1076 snd_soc_component_upd 1070 snd_soc_component_update_bits(component, 1077 1071 WCD937X_DIGITAL_CDC_ANA_CLK_CTL, 1078 1072 BIT(4), BIT(4)); 1079 snd_soc_component_upd 1073 snd_soc_component_update_bits(component, 1080 1074 WCD937X_MICB1_TEST_CTL_2, 1081 1075 BIT(0), BIT(0)); 1082 snd_soc_component_upd 1076 snd_soc_component_update_bits(component, 1083 1077 WCD937X_MICB2_TEST_CTL_2, 1084 1078 BIT(0), BIT(0)); 1085 snd_soc_component_upd 1079 snd_soc_component_update_bits(component, 1086 1080 WCD937X_MICB3_TEST_CTL_2, 1087 1081 BIT(0), BIT(0)); 1088 snd_soc_component_upd 1082 snd_soc_component_update_bits(component, 1089 1083 micb_reg, 0xc0, BIT(6)); 1090 1084 1091 if (micb_num == MIC_B 1085 if (micb_num == MIC_BIAS_2) 1092 wcd_mbhc_even 1086 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, 1093 1087 WCD_EVENT_POST_MICBIAS_2_ON); 1094 1088 1095 if (micb_num == MIC_B 1089 if (micb_num == MIC_BIAS_2 && is_dapm) 1096 wcd_mbhc_even 1090 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, 1097 1091 WCD_EVENT_POST_DAPM_MICBIAS_2_ON); 1098 } 1092 } 1099 break; 1093 break; 1100 case MICB_DISABLE: 1094 case MICB_DISABLE: 1101 atomic_dec(&wcd937x->ana_clk_ 1095 atomic_dec(&wcd937x->ana_clk_count); 1102 if (wcd937x->micb_ref[micb_in 1096 if (wcd937x->micb_ref[micb_index] > 0) 1103 wcd937x->micb_ref[mic 1097 wcd937x->micb_ref[micb_index]--; 1104 if (wcd937x->micb_ref[micb_in 1098 if (wcd937x->micb_ref[micb_index] == 0 && 1105 wcd937x->pullup_ref[micb_ 1099 wcd937x->pullup_ref[micb_index] > 0) 1106 snd_soc_component_upd 1100 snd_soc_component_update_bits(component, micb_reg, 1107 1101 0xc0, BIT(7)); 1108 else if (wcd937x->micb_ref[mi 1102 else if (wcd937x->micb_ref[micb_index] == 0 && 1109 wcd937x->pullup_ref[ 1103 wcd937x->pullup_ref[micb_index] == 0) { 1110 if (micb_num == MIC_B 1104 if (micb_num == MIC_BIAS_2) 1111 wcd_mbhc_even 1105 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, 1112 1106 WCD_EVENT_PRE_MICBIAS_2_OFF); 1113 1107 1114 snd_soc_component_upd 1108 snd_soc_component_update_bits(component, micb_reg, 1115 1109 0xc0, 0x00); 1116 if (micb_num == MIC_B 1110 if (micb_num == MIC_BIAS_2) 1117 wcd_mbhc_even 1111 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, 1118 1112 WCD_EVENT_POST_MICBIAS_2_OFF); 1119 } 1113 } 1120 1114 1121 if (is_dapm && micb_num == MI 1115 if (is_dapm && micb_num == MIC_BIAS_2) 1122 wcd_mbhc_event_notify 1116 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, 1123 1117 WCD_EVENT_POST_DAPM_MICBIAS_2_OFF); 1124 if (atomic_read(&wcd937x->ana 1118 if (atomic_read(&wcd937x->ana_clk_count) <= 0) { 1125 snd_soc_component_upd 1119 snd_soc_component_update_bits(component, 1126 1120 WCD937X_DIGITAL_CDC_ANA_CLK_CTL, 1127 1121 BIT(4), 0x00); 1128 atomic_set(&wcd937x-> 1122 atomic_set(&wcd937x->ana_clk_count, 0); 1129 } 1123 } 1130 break; 1124 break; 1131 } 1125 } 1132 mutex_unlock(&wcd937x->micb_lock); 1126 mutex_unlock(&wcd937x->micb_lock); 1133 1127 1134 return 0; 1128 return 0; 1135 } 1129 } 1136 1130 1137 static int __wcd937x_codec_enable_micbias(str 1131 static int __wcd937x_codec_enable_micbias(struct snd_soc_dapm_widget *w, 1138 int 1132 int event) 1139 { 1133 { 1140 struct snd_soc_component *component = 1134 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 1141 int micb_num = w->shift; 1135 int micb_num = w->shift; 1142 1136 1143 switch (event) { 1137 switch (event) { 1144 case SND_SOC_DAPM_PRE_PMU: 1138 case SND_SOC_DAPM_PRE_PMU: 1145 wcd937x_micbias_control(compo 1139 wcd937x_micbias_control(component, micb_num, 1146 MICB_ 1140 MICB_ENABLE, true); 1147 break; 1141 break; 1148 case SND_SOC_DAPM_POST_PMU: 1142 case SND_SOC_DAPM_POST_PMU: 1149 usleep_range(1000, 1100); 1143 usleep_range(1000, 1100); 1150 break; 1144 break; 1151 case SND_SOC_DAPM_POST_PMD: 1145 case SND_SOC_DAPM_POST_PMD: 1152 wcd937x_micbias_control(compo 1146 wcd937x_micbias_control(component, micb_num, 1153 MICB_ 1147 MICB_DISABLE, true); 1154 break; 1148 break; 1155 } 1149 } 1156 1150 1157 return 0; 1151 return 0; 1158 } 1152 } 1159 1153 1160 static int wcd937x_codec_enable_micbias(struc 1154 static int wcd937x_codec_enable_micbias(struct snd_soc_dapm_widget *w, 1161 struc 1155 struct snd_kcontrol *kcontrol, 1162 int e 1156 int event) 1163 { 1157 { 1164 return __wcd937x_codec_enable_micbias 1158 return __wcd937x_codec_enable_micbias(w, event); 1165 } 1159 } 1166 1160 1167 static int __wcd937x_codec_enable_micbias_pul 1161 static int __wcd937x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w, 1168 1162 int event) 1169 { 1163 { 1170 struct snd_soc_component *component = 1164 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 1171 int micb_num = w->shift; 1165 int micb_num = w->shift; 1172 1166 1173 switch (event) { 1167 switch (event) { 1174 case SND_SOC_DAPM_PRE_PMU: 1168 case SND_SOC_DAPM_PRE_PMU: 1175 wcd937x_micbias_control(compo 1169 wcd937x_micbias_control(component, micb_num, MICB_PULLUP_ENABLE, true); 1176 break; 1170 break; 1177 case SND_SOC_DAPM_POST_PMU: 1171 case SND_SOC_DAPM_POST_PMU: 1178 usleep_range(1000, 1100); 1172 usleep_range(1000, 1100); 1179 break; 1173 break; 1180 case SND_SOC_DAPM_POST_PMD: 1174 case SND_SOC_DAPM_POST_PMD: 1181 wcd937x_micbias_control(compo 1175 wcd937x_micbias_control(component, micb_num, MICB_PULLUP_DISABLE, true); 1182 break; 1176 break; 1183 } 1177 } 1184 1178 1185 return 0; 1179 return 0; 1186 } 1180 } 1187 1181 1188 static int wcd937x_codec_enable_micbias_pullu 1182 static int wcd937x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w, 1189 1183 struct snd_kcontrol *kcontrol, 1190 1184 int event) 1191 { 1185 { 1192 return __wcd937x_codec_enable_micbias 1186 return __wcd937x_codec_enable_micbias_pullup(w, event); 1193 } 1187 } 1194 1188 1195 static int wcd937x_connect_port(struct wcd937 1189 static int wcd937x_connect_port(struct wcd937x_sdw_priv *wcd, u8 port_idx, u8 ch_id, bool enable) 1196 { 1190 { 1197 struct sdw_port_config *port_config = 1191 struct sdw_port_config *port_config = &wcd->port_config[port_idx - 1]; 1198 const struct wcd937x_sdw_ch_info *ch_ 1192 const struct wcd937x_sdw_ch_info *ch_info = &wcd->ch_info[ch_id]; 1199 u8 port_num = ch_info->port_num; 1193 u8 port_num = ch_info->port_num; 1200 u8 ch_mask = ch_info->ch_mask; 1194 u8 ch_mask = ch_info->ch_mask; 1201 1195 1202 port_config->num = port_num; 1196 port_config->num = port_num; 1203 1197 1204 if (enable) 1198 if (enable) 1205 port_config->ch_mask |= ch_ma 1199 port_config->ch_mask |= ch_mask; 1206 else 1200 else 1207 port_config->ch_mask &= ~ch_m 1201 port_config->ch_mask &= ~ch_mask; 1208 1202 1209 return 0; 1203 return 0; 1210 } 1204 } 1211 1205 1212 static int wcd937x_rx_hph_mode_get(struct snd 1206 static int wcd937x_rx_hph_mode_get(struct snd_kcontrol *kcontrol, 1213 struct snd 1207 struct snd_ctl_elem_value *ucontrol) 1214 { 1208 { 1215 struct snd_soc_component *component = 1209 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); 1216 struct wcd937x_priv *wcd937x = snd_so 1210 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1217 1211 1218 ucontrol->value.integer.value[0] = wc 1212 ucontrol->value.integer.value[0] = wcd937x->hph_mode; 1219 return 0; 1213 return 0; 1220 } 1214 } 1221 1215 1222 static int wcd937x_rx_hph_mode_put(struct snd 1216 static int wcd937x_rx_hph_mode_put(struct snd_kcontrol *kcontrol, 1223 struct snd 1217 struct snd_ctl_elem_value *ucontrol) 1224 { 1218 { 1225 struct snd_soc_component *component = 1219 struct snd_soc_component *component = 1226 snd_soc_kcont 1220 snd_soc_kcontrol_component(kcontrol); 1227 struct wcd937x_priv *wcd937x = snd_so 1221 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1228 u32 mode_val; 1222 u32 mode_val; 1229 1223 1230 mode_val = ucontrol->value.enumerated 1224 mode_val = ucontrol->value.enumerated.item[0]; 1231 1225 1232 if (!mode_val) 1226 if (!mode_val) 1233 mode_val = CLS_AB; 1227 mode_val = CLS_AB; 1234 1228 1235 if (mode_val == wcd937x->hph_mode) 1229 if (mode_val == wcd937x->hph_mode) 1236 return 0; 1230 return 0; 1237 1231 1238 switch (mode_val) { 1232 switch (mode_val) { 1239 case CLS_H_NORMAL: 1233 case CLS_H_NORMAL: 1240 case CLS_H_HIFI: 1234 case CLS_H_HIFI: 1241 case CLS_H_LP: 1235 case CLS_H_LP: 1242 case CLS_AB: 1236 case CLS_AB: 1243 case CLS_H_LOHIFI: 1237 case CLS_H_LOHIFI: 1244 case CLS_H_ULP: 1238 case CLS_H_ULP: 1245 case CLS_AB_LP: 1239 case CLS_AB_LP: 1246 case CLS_AB_HIFI: 1240 case CLS_AB_HIFI: 1247 wcd937x->hph_mode = mode_val; 1241 wcd937x->hph_mode = mode_val; 1248 return 1; 1242 return 1; 1249 } 1243 } 1250 1244 1251 dev_dbg(component->dev, "%s: Invalid 1245 dev_dbg(component->dev, "%s: Invalid HPH Mode\n", __func__); 1252 return -EINVAL; 1246 return -EINVAL; 1253 } 1247 } 1254 1248 1255 static int wcd937x_get_compander(struct snd_k 1249 static int wcd937x_get_compander(struct snd_kcontrol *kcontrol, 1256 struct snd_c 1250 struct snd_ctl_elem_value *ucontrol) 1257 { 1251 { 1258 struct snd_soc_component *component = 1252 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); 1259 struct wcd937x_priv *wcd937x = snd_so 1253 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1260 struct soc_mixer_control *mc; 1254 struct soc_mixer_control *mc; 1261 bool hphr; 1255 bool hphr; 1262 1256 1263 mc = (struct soc_mixer_control *)(kco 1257 mc = (struct soc_mixer_control *)(kcontrol->private_value); 1264 hphr = mc->shift; 1258 hphr = mc->shift; 1265 1259 1266 ucontrol->value.integer.value[0] = hp 1260 ucontrol->value.integer.value[0] = hphr ? wcd937x->comp2_enable : 1267 1261 wcd937x->comp1_enable; 1268 return 0; 1262 return 0; 1269 } 1263 } 1270 1264 1271 static int wcd937x_set_compander(struct snd_k 1265 static int wcd937x_set_compander(struct snd_kcontrol *kcontrol, 1272 struct snd_c 1266 struct snd_ctl_elem_value *ucontrol) 1273 { 1267 { 1274 struct snd_soc_component *component = 1268 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); 1275 struct wcd937x_priv *wcd937x = snd_so 1269 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1276 struct wcd937x_sdw_priv *wcd = wcd937 1270 struct wcd937x_sdw_priv *wcd = wcd937x->sdw_priv[AIF1_PB]; 1277 int value = ucontrol->value.integer.v 1271 int value = ucontrol->value.integer.value[0]; 1278 struct soc_mixer_control *mc; 1272 struct soc_mixer_control *mc; 1279 int portidx; 1273 int portidx; 1280 bool hphr; 1274 bool hphr; 1281 1275 1282 mc = (struct soc_mixer_control *)(kco 1276 mc = (struct soc_mixer_control *)(kcontrol->private_value); 1283 hphr = mc->shift; 1277 hphr = mc->shift; 1284 1278 1285 if (hphr) { 1279 if (hphr) { 1286 if (value == wcd937x->comp2_e 1280 if (value == wcd937x->comp2_enable) 1287 return 0; 1281 return 0; 1288 1282 1289 wcd937x->comp2_enable = value 1283 wcd937x->comp2_enable = value; 1290 } else { 1284 } else { 1291 if (value == wcd937x->comp1_e 1285 if (value == wcd937x->comp1_enable) 1292 return 0; 1286 return 0; 1293 1287 1294 wcd937x->comp1_enable = value 1288 wcd937x->comp1_enable = value; 1295 } 1289 } 1296 1290 1297 portidx = wcd->ch_info[mc->reg].port_ 1291 portidx = wcd->ch_info[mc->reg].port_num; 1298 1292 1299 if (value) 1293 if (value) 1300 wcd937x_connect_port(wcd, por 1294 wcd937x_connect_port(wcd, portidx, mc->reg, true); 1301 else 1295 else 1302 wcd937x_connect_port(wcd, por 1296 wcd937x_connect_port(wcd, portidx, mc->reg, false); 1303 1297 1304 return 1; 1298 return 1; 1305 } 1299 } 1306 1300 1307 static int wcd937x_get_swr_port(struct snd_kc 1301 static int wcd937x_get_swr_port(struct snd_kcontrol *kcontrol, 1308 struct snd_ct 1302 struct snd_ctl_elem_value *ucontrol) 1309 { 1303 { 1310 struct soc_mixer_control *mixer = (st 1304 struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; 1311 struct snd_soc_component *comp = snd_ 1305 struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 1312 struct wcd937x_priv *wcd937x = snd_so 1306 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(comp); 1313 struct wcd937x_sdw_priv *wcd; 1307 struct wcd937x_sdw_priv *wcd; 1314 int dai_id = mixer->shift; 1308 int dai_id = mixer->shift; 1315 int ch_idx = mixer->reg; 1309 int ch_idx = mixer->reg; 1316 int portidx; 1310 int portidx; 1317 1311 1318 wcd = wcd937x->sdw_priv[dai_id]; 1312 wcd = wcd937x->sdw_priv[dai_id]; 1319 portidx = wcd->ch_info[ch_idx].port_n 1313 portidx = wcd->ch_info[ch_idx].port_num; 1320 1314 1321 ucontrol->value.integer.value[0] = wc 1315 ucontrol->value.integer.value[0] = wcd->port_enable[portidx]; 1322 1316 1323 return 0; 1317 return 0; 1324 } 1318 } 1325 1319 1326 static int wcd937x_set_swr_port(struct snd_kc 1320 static int wcd937x_set_swr_port(struct snd_kcontrol *kcontrol, 1327 struct snd_ct 1321 struct snd_ctl_elem_value *ucontrol) 1328 { 1322 { 1329 struct soc_mixer_control *mixer = (st 1323 struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; 1330 struct snd_soc_component *comp = snd_ 1324 struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); 1331 struct wcd937x_priv *wcd937x = snd_so 1325 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(comp); 1332 struct wcd937x_sdw_priv *wcd; 1326 struct wcd937x_sdw_priv *wcd; 1333 int dai_id = mixer->shift; 1327 int dai_id = mixer->shift; 1334 int ch_idx = mixer->reg; 1328 int ch_idx = mixer->reg; 1335 int portidx; 1329 int portidx; 1336 bool enable; 1330 bool enable; 1337 1331 1338 wcd = wcd937x->sdw_priv[dai_id]; 1332 wcd = wcd937x->sdw_priv[dai_id]; 1339 1333 1340 portidx = wcd->ch_info[ch_idx].port_n 1334 portidx = wcd->ch_info[ch_idx].port_num; 1341 1335 1342 enable = ucontrol->value.integer.valu 1336 enable = ucontrol->value.integer.value[0]; 1343 1337 1344 if (enable == wcd->port_enable[portid 1338 if (enable == wcd->port_enable[portidx]) { 1345 wcd937x_connect_port(wcd, por 1339 wcd937x_connect_port(wcd, portidx, ch_idx, enable); 1346 return 0; 1340 return 0; 1347 } 1341 } 1348 1342 1349 wcd->port_enable[portidx] = enable; 1343 wcd->port_enable[portidx] = enable; 1350 wcd937x_connect_port(wcd, portidx, ch 1344 wcd937x_connect_port(wcd, portidx, ch_idx, enable); 1351 1345 1352 return 1; 1346 return 1; 1353 } 1347 } 1354 1348 1355 static const char * const rx_hph_mode_mux_tex 1349 static const char * const rx_hph_mode_mux_text[] = { 1356 "CLS_H_NORMAL", "CLS_H_INVALID", "CLS 1350 "CLS_H_NORMAL", "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", 1357 "CLS_H_LOHIFI", "CLS_H_ULP", "CLS_AB_ 1351 "CLS_H_LOHIFI", "CLS_H_ULP", "CLS_AB_LP", "CLS_AB_HIFI", 1358 }; 1352 }; 1359 1353 1360 static const struct soc_enum rx_hph_mode_mux_ 1354 static const struct soc_enum rx_hph_mode_mux_enum = 1361 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph 1355 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text), rx_hph_mode_mux_text); 1362 1356 1363 /* MBHC related */ 1357 /* MBHC related */ 1364 static void wcd937x_mbhc_clk_setup(struct snd 1358 static void wcd937x_mbhc_clk_setup(struct snd_soc_component *component, 1365 bool enabl 1359 bool enable) 1366 { 1360 { 1367 snd_soc_component_write_field(compone 1361 snd_soc_component_write_field(component, WCD937X_MBHC_NEW_CTL_1, 1368 WCD937X 1362 WCD937X_MBHC_CTL_RCO_EN_MASK, enable); 1369 } 1363 } 1370 1364 1371 static void wcd937x_mbhc_mbhc_bias_control(st 1365 static void wcd937x_mbhc_mbhc_bias_control(struct snd_soc_component *component, 1372 bo 1366 bool enable) 1373 { 1367 { 1374 snd_soc_component_write_field(compone 1368 snd_soc_component_write_field(component, WCD937X_ANA_MBHC_ELECT, 1375 WCD937X 1369 WCD937X_ANA_MBHC_BIAS_EN, enable); 1376 } 1370 } 1377 1371 1378 static void wcd937x_mbhc_program_btn_thr(stru 1372 static void wcd937x_mbhc_program_btn_thr(struct snd_soc_component *component, 1379 int 1373 int *btn_low, int *btn_high, 1380 int 1374 int num_btn, bool is_micbias) 1381 { 1375 { 1382 int i, vth; 1376 int i, vth; 1383 1377 1384 if (num_btn > WCD_MBHC_DEF_BUTTONS) { 1378 if (num_btn > WCD_MBHC_DEF_BUTTONS) { 1385 dev_err(component->dev, "%s: 1379 dev_err(component->dev, "%s: invalid number of buttons: %d\n", 1386 __func__, num_btn); 1380 __func__, num_btn); 1387 return; 1381 return; 1388 } 1382 } 1389 1383 1390 for (i = 0; i < num_btn; i++) { 1384 for (i = 0; i < num_btn; i++) { 1391 vth = ((btn_high[i] * 2) / 25 1385 vth = ((btn_high[i] * 2) / 25) & 0x3F; 1392 snd_soc_component_write_field 1386 snd_soc_component_write_field(component, WCD937X_ANA_MBHC_BTN0 + i, 1393 1387 WCD937X_MBHC_BTN_VTH_MASK, vth); 1394 } 1388 } 1395 } 1389 } 1396 1390 1397 static bool wcd937x_mbhc_micb_en_status(struc 1391 static bool wcd937x_mbhc_micb_en_status(struct snd_soc_component *component, int micb_num) 1398 { 1392 { 1399 u8 val; 1393 u8 val; 1400 1394 1401 if (micb_num == MIC_BIAS_2) { 1395 if (micb_num == MIC_BIAS_2) { 1402 val = snd_soc_component_read_ 1396 val = snd_soc_component_read_field(component, 1403 1397 WCD937X_ANA_MICB2, 1404 1398 WCD937X_ANA_MICB2_ENABLE_MASK); 1405 if (val == WCD937X_MICB_ENABL 1399 if (val == WCD937X_MICB_ENABLE) 1406 return true; 1400 return true; 1407 } 1401 } 1408 return false; 1402 return false; 1409 } 1403 } 1410 1404 1411 static void wcd937x_mbhc_hph_l_pull_up_contro 1405 static void wcd937x_mbhc_hph_l_pull_up_control(struct snd_soc_component *component, 1412 1406 int pull_up_cur) 1413 { 1407 { 1414 /* Default pull up current to 2uA */ 1408 /* Default pull up current to 2uA */ 1415 if (pull_up_cur > HS_PULLUP_I_OFF || 1409 if (pull_up_cur > HS_PULLUP_I_OFF || pull_up_cur < HS_PULLUP_I_3P0_UA) 1416 pull_up_cur = HS_PULLUP_I_2P0 1410 pull_up_cur = HS_PULLUP_I_2P0_UA; 1417 1411 1418 snd_soc_component_write_field(compone 1412 snd_soc_component_write_field(component, 1419 WCD937X 1413 WCD937X_MBHC_NEW_INT_MECH_DET_CURRENT, 1420 WCD937X 1414 WCD937X_HSDET_PULLUP_C_MASK, pull_up_cur); 1421 } 1415 } 1422 1416 1423 static int wcd937x_mbhc_request_micbias(struc 1417 static int wcd937x_mbhc_request_micbias(struct snd_soc_component *component, 1424 int m 1418 int micb_num, int req) 1425 { 1419 { 1426 return wcd937x_micbias_control(compon 1420 return wcd937x_micbias_control(component, micb_num, req, false); 1427 } 1421 } 1428 1422 1429 static void wcd937x_mbhc_micb_ramp_control(st 1423 static void wcd937x_mbhc_micb_ramp_control(struct snd_soc_component *component, 1430 bo 1424 bool enable) 1431 { 1425 { 1432 if (enable) { 1426 if (enable) { 1433 snd_soc_component_write_field 1427 snd_soc_component_write_field(component, WCD937X_ANA_MICB2_RAMP, 1434 1428 WCD937X_RAMP_SHIFT_CTRL_MASK, 0x0C); 1435 snd_soc_component_write_field 1429 snd_soc_component_write_field(component, WCD937X_ANA_MICB2_RAMP, 1436 1430 WCD937X_RAMP_EN_MASK, 1); 1437 } else { 1431 } else { 1438 snd_soc_component_write_field 1432 snd_soc_component_write_field(component, WCD937X_ANA_MICB2_RAMP, 1439 1433 WCD937X_RAMP_EN_MASK, 0); 1440 snd_soc_component_write_field 1434 snd_soc_component_write_field(component, WCD937X_ANA_MICB2_RAMP, 1441 1435 WCD937X_RAMP_SHIFT_CTRL_MASK, 0); 1442 } 1436 } 1443 } 1437 } 1444 1438 1445 static int wcd937x_mbhc_micb_adjust_voltage(s 1439 static int wcd937x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, 1446 i 1440 int req_volt, int micb_num) 1447 { 1441 { 1448 struct wcd937x_priv *wcd937x = snd_so 1442 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1449 int cur_vout_ctl, req_vout_ctl, micb_ 1443 int cur_vout_ctl, req_vout_ctl, micb_reg, micb_en, ret = 0; 1450 1444 1451 switch (micb_num) { 1445 switch (micb_num) { 1452 case MIC_BIAS_1: 1446 case MIC_BIAS_1: 1453 micb_reg = WCD937X_ANA_MICB1; 1447 micb_reg = WCD937X_ANA_MICB1; 1454 break; 1448 break; 1455 case MIC_BIAS_2: 1449 case MIC_BIAS_2: 1456 micb_reg = WCD937X_ANA_MICB2; 1450 micb_reg = WCD937X_ANA_MICB2; 1457 break; 1451 break; 1458 case MIC_BIAS_3: 1452 case MIC_BIAS_3: 1459 micb_reg = WCD937X_ANA_MICB3; 1453 micb_reg = WCD937X_ANA_MICB3; 1460 break; 1454 break; 1461 default: 1455 default: 1462 return -EINVAL; 1456 return -EINVAL; 1463 } 1457 } 1464 mutex_lock(&wcd937x->micb_lock); 1458 mutex_lock(&wcd937x->micb_lock); 1465 /* 1459 /* 1466 * If requested micbias voltage is sa 1460 * If requested micbias voltage is same as current micbias 1467 * voltage, then just return. Otherwi 1461 * voltage, then just return. Otherwise, adjust voltage as 1468 * per requested value. If micbias is 1462 * per requested value. If micbias is already enabled, then 1469 * to avoid slow micbias ramp-up or d 1463 * to avoid slow micbias ramp-up or down enable pull-up 1470 * momentarily, change the micbias va 1464 * momentarily, change the micbias value and then re-enable 1471 * micbias. 1465 * micbias. 1472 */ 1466 */ 1473 micb_en = snd_soc_component_read_fiel 1467 micb_en = snd_soc_component_read_field(component, micb_reg, 1474 1468 WCD937X_MICB_EN_MASK); 1475 cur_vout_ctl = snd_soc_component_read 1469 cur_vout_ctl = snd_soc_component_read_field(component, micb_reg, 1476 1470 WCD937X_MICB_VOUT_MASK); 1477 1471 1478 req_vout_ctl = wcd937x_get_micb_vout_ 1472 req_vout_ctl = wcd937x_get_micb_vout_ctl_val(req_volt); 1479 if (req_vout_ctl < 0) { 1473 if (req_vout_ctl < 0) { 1480 ret = -EINVAL; 1474 ret = -EINVAL; 1481 goto exit; 1475 goto exit; 1482 } 1476 } 1483 1477 1484 if (cur_vout_ctl == req_vout_ctl) { 1478 if (cur_vout_ctl == req_vout_ctl) { 1485 ret = 0; 1479 ret = 0; 1486 goto exit; 1480 goto exit; 1487 } 1481 } 1488 1482 1489 if (micb_en == WCD937X_MICB_ENABLE) 1483 if (micb_en == WCD937X_MICB_ENABLE) 1490 snd_soc_component_write_field 1484 snd_soc_component_write_field(component, micb_reg, 1491 1485 WCD937X_MICB_EN_MASK, 1492 1486 WCD937X_MICB_PULL_UP); 1493 1487 1494 snd_soc_component_write_field(compone 1488 snd_soc_component_write_field(component, micb_reg, 1495 WCD937X 1489 WCD937X_MICB_VOUT_MASK, 1496 req_vou 1490 req_vout_ctl); 1497 1491 1498 if (micb_en == WCD937X_MICB_ENABLE) { 1492 if (micb_en == WCD937X_MICB_ENABLE) { 1499 snd_soc_component_write_field 1493 snd_soc_component_write_field(component, micb_reg, 1500 1494 WCD937X_MICB_EN_MASK, 1501 1495 WCD937X_MICB_ENABLE); 1502 /* 1496 /* 1503 * Add 2ms delay as per HW re 1497 * Add 2ms delay as per HW requirement after enabling 1504 * micbias 1498 * micbias 1505 */ 1499 */ 1506 usleep_range(2000, 2100); 1500 usleep_range(2000, 2100); 1507 } 1501 } 1508 exit: 1502 exit: 1509 mutex_unlock(&wcd937x->micb_lock); 1503 mutex_unlock(&wcd937x->micb_lock); 1510 return ret; 1504 return ret; 1511 } 1505 } 1512 1506 1513 static int wcd937x_mbhc_micb_ctrl_threshold_m 1507 static int wcd937x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *component, 1514 1508 int micb_num, bool req_en) 1515 { 1509 { 1516 struct wcd937x_priv *wcd937x = snd_so 1510 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1517 int micb_mv; 1511 int micb_mv; 1518 1512 1519 if (micb_num != MIC_BIAS_2) 1513 if (micb_num != MIC_BIAS_2) 1520 return -EINVAL; 1514 return -EINVAL; 1521 /* 1515 /* 1522 * If device tree micbias level is al 1516 * If device tree micbias level is already above the minimum 1523 * voltage needed to detect threshold 1517 * voltage needed to detect threshold microphone, then do 1524 * not change the micbias, just retur 1518 * not change the micbias, just return. 1525 */ 1519 */ 1526 if (wcd937x->micb2_mv >= WCD_MBHC_THR 1520 if (wcd937x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV) 1527 return 0; 1521 return 0; 1528 1522 1529 micb_mv = req_en ? WCD_MBHC_THR_HS_MI 1523 micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd937x->micb2_mv; 1530 1524 1531 return wcd937x_mbhc_micb_adjust_volta 1525 return wcd937x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2); 1532 } 1526 } 1533 1527 1534 static void wcd937x_mbhc_get_result_params(st 1528 static void wcd937x_mbhc_get_result_params(struct snd_soc_component *component, 1535 s1 1529 s16 *d1_a, u16 noff, 1536 in 1530 int32_t *zdet) 1537 { 1531 { 1538 struct wcd937x_priv *wcd937x = snd_so 1532 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1539 int i; 1533 int i; 1540 int val, val1; 1534 int val, val1; 1541 s16 c1; 1535 s16 c1; 1542 s32 x1, d1; 1536 s32 x1, d1; 1543 s32 denom; 1537 s32 denom; 1544 static const int minCode_param[] = { 1538 static const int minCode_param[] = { 1545 3277, 1639, 820, 410, 205, 10 1539 3277, 1639, 820, 410, 205, 103, 52, 26 1546 }; 1540 }; 1547 1541 1548 regmap_update_bits(wcd937x->regmap, W 1542 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MBHC_ZDET, 0x20, 0x20); 1549 for (i = 0; i < WCD937X_ZDET_NUM_MEAS 1543 for (i = 0; i < WCD937X_ZDET_NUM_MEASUREMENTS; i++) { 1550 regmap_read(wcd937x->regmap, 1544 regmap_read(wcd937x->regmap, WCD937X_ANA_MBHC_RESULT_2, &val); 1551 if (val & 0x80) 1545 if (val & 0x80) 1552 break; 1546 break; 1553 } 1547 } 1554 val = val << 0x8; 1548 val = val << 0x8; 1555 regmap_read(wcd937x->regmap, WCD937X_ 1549 regmap_read(wcd937x->regmap, WCD937X_ANA_MBHC_RESULT_1, &val1); 1556 val |= val1; 1550 val |= val1; 1557 regmap_update_bits(wcd937x->regmap, W 1551 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MBHC_ZDET, 0x20, 0x00); 1558 x1 = WCD937X_MBHC_GET_X1(val); 1552 x1 = WCD937X_MBHC_GET_X1(val); 1559 c1 = WCD937X_MBHC_GET_C1(val); 1553 c1 = WCD937X_MBHC_GET_C1(val); 1560 /* If ramp is not complete, give addi 1554 /* If ramp is not complete, give additional 5ms */ 1561 if (c1 < 2 && x1) 1555 if (c1 < 2 && x1) 1562 usleep_range(5000, 5050); 1556 usleep_range(5000, 5050); 1563 1557 1564 if (!c1 || !x1) { 1558 if (!c1 || !x1) { 1565 dev_err(component->dev, "Impe 1559 dev_err(component->dev, "Impedance detect ramp error, c1=%d, x1=0x%x\n", 1566 c1, x1); 1560 c1, x1); 1567 goto ramp_down; 1561 goto ramp_down; 1568 } 1562 } 1569 d1 = d1_a[c1]; 1563 d1 = d1_a[c1]; 1570 denom = (x1 * d1) - (1 << (14 - noff) 1564 denom = (x1 * d1) - (1 << (14 - noff)); 1571 if (denom > 0) 1565 if (denom > 0) 1572 *zdet = (WCD937X_MBHC_ZDET_CO 1566 *zdet = (WCD937X_MBHC_ZDET_CONST * 1000) / denom; 1573 else if (x1 < minCode_param[noff]) 1567 else if (x1 < minCode_param[noff]) 1574 *zdet = WCD937X_ZDET_FLOATING 1568 *zdet = WCD937X_ZDET_FLOATING_IMPEDANCE; 1575 1569 1576 dev_err(component->dev, "%s: d1=%d, c 1570 dev_err(component->dev, "%s: d1=%d, c1=%d, x1=0x%x, z_val=%d (milliohm)\n", 1577 __func__, d1, c1, x1, *zdet); 1571 __func__, d1, c1, x1, *zdet); 1578 ramp_down: 1572 ramp_down: 1579 i = 0; 1573 i = 0; 1580 while (x1) { 1574 while (x1) { 1581 regmap_read(wcd937x->regmap, 1575 regmap_read(wcd937x->regmap, 1582 WCD937X_ANA_MBHC_ 1576 WCD937X_ANA_MBHC_RESULT_1, &val); 1583 regmap_read(wcd937x->regmap, 1577 regmap_read(wcd937x->regmap, 1584 WCD937X_ANA_MBHC_ 1578 WCD937X_ANA_MBHC_RESULT_2, &val1); 1585 val = val << 0x08; 1579 val = val << 0x08; 1586 val |= val1; 1580 val |= val1; 1587 x1 = WCD937X_MBHC_GET_X1(val) 1581 x1 = WCD937X_MBHC_GET_X1(val); 1588 i++; 1582 i++; 1589 if (i == WCD937X_ZDET_NUM_MEA 1583 if (i == WCD937X_ZDET_NUM_MEASUREMENTS) 1590 break; 1584 break; 1591 } 1585 } 1592 } 1586 } 1593 1587 1594 static void wcd937x_mbhc_zdet_ramp(struct snd 1588 static void wcd937x_mbhc_zdet_ramp(struct snd_soc_component *component, 1595 struct wcd 1589 struct wcd937x_mbhc_zdet_param *zdet_param, 1596 s32 *zl, s 1590 s32 *zl, s32 *zr, s16 *d1_a) 1597 { 1591 { 1598 struct wcd937x_priv *wcd937x = snd_so 1592 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1599 s32 zdet = 0; 1593 s32 zdet = 0; 1600 1594 1601 snd_soc_component_write_field(compone 1595 snd_soc_component_write_field(component, WCD937X_MBHC_NEW_ZDET_ANA_CTL, 1602 WCD937X 1596 WCD937X_ZDET_MAXV_CTL_MASK, zdet_param->ldo_ctl); 1603 snd_soc_component_update_bits(compone 1597 snd_soc_component_update_bits(component, WCD937X_ANA_MBHC_BTN5, 1604 WCD937X 1598 WCD937X_VTH_MASK, zdet_param->btn5); 1605 snd_soc_component_update_bits(compone 1599 snd_soc_component_update_bits(component, WCD937X_ANA_MBHC_BTN6, 1606 WCD937X 1600 WCD937X_VTH_MASK, zdet_param->btn6); 1607 snd_soc_component_update_bits(compone 1601 snd_soc_component_update_bits(component, WCD937X_ANA_MBHC_BTN7, 1608 WCD937X 1602 WCD937X_VTH_MASK, zdet_param->btn7); 1609 snd_soc_component_write_field(compone 1603 snd_soc_component_write_field(component, WCD937X_MBHC_NEW_ZDET_ANA_CTL, 1610 WCD937X 1604 WCD937X_ZDET_RANGE_CTL_MASK, zdet_param->noff); 1611 snd_soc_component_update_bits(compone 1605 snd_soc_component_update_bits(component, WCD937X_MBHC_NEW_ZDET_RAMP_CTL, 1612 0x0F, z 1606 0x0F, zdet_param->nshift); 1613 1607 1614 if (!zl) 1608 if (!zl) 1615 goto z_right; 1609 goto z_right; 1616 /* Start impedance measurement for HP 1610 /* Start impedance measurement for HPH_L */ 1617 regmap_update_bits(wcd937x->regmap, 1611 regmap_update_bits(wcd937x->regmap, 1618 WCD937X_ANA_MBHC_Z 1612 WCD937X_ANA_MBHC_ZDET, 0x80, 0x80); 1619 wcd937x_mbhc_get_result_params(compon 1613 wcd937x_mbhc_get_result_params(component, d1_a, zdet_param->noff, &zdet); 1620 regmap_update_bits(wcd937x->regmap, 1614 regmap_update_bits(wcd937x->regmap, 1621 WCD937X_ANA_MBHC_Z 1615 WCD937X_ANA_MBHC_ZDET, 0x80, 0x00); 1622 1616 1623 *zl = zdet; 1617 *zl = zdet; 1624 1618 1625 z_right: 1619 z_right: 1626 if (!zr) 1620 if (!zr) 1627 return; 1621 return; 1628 /* Start impedance measurement for HP 1622 /* Start impedance measurement for HPH_R */ 1629 regmap_update_bits(wcd937x->regmap, 1623 regmap_update_bits(wcd937x->regmap, 1630 WCD937X_ANA_MBHC_Z 1624 WCD937X_ANA_MBHC_ZDET, 0x40, 0x40); 1631 wcd937x_mbhc_get_result_params(compon 1625 wcd937x_mbhc_get_result_params(component, d1_a, zdet_param->noff, &zdet); 1632 regmap_update_bits(wcd937x->regmap, 1626 regmap_update_bits(wcd937x->regmap, 1633 WCD937X_ANA_MBHC_Z 1627 WCD937X_ANA_MBHC_ZDET, 0x40, 0x00); 1634 1628 1635 *zr = zdet; 1629 *zr = zdet; 1636 } 1630 } 1637 1631 1638 static void wcd937x_wcd_mbhc_qfuse_cal(struct 1632 static void wcd937x_wcd_mbhc_qfuse_cal(struct snd_soc_component *component, 1639 s32 *z 1633 s32 *z_val, int flag_l_r) 1640 { 1634 { 1641 s16 q1; 1635 s16 q1; 1642 int q1_cal; 1636 int q1_cal; 1643 1637 1644 if (*z_val < (WCD937X_ZDET_VAL_400 / 1638 if (*z_val < (WCD937X_ZDET_VAL_400 / 1000)) 1645 q1 = snd_soc_component_read(c 1639 q1 = snd_soc_component_read(component, 1646 W 1640 WCD937X_DIGITAL_EFUSE_REG_23 + (2 * flag_l_r)); 1647 else 1641 else 1648 q1 = snd_soc_component_read(c 1642 q1 = snd_soc_component_read(component, 1649 W 1643 WCD937X_DIGITAL_EFUSE_REG_24 + (2 * flag_l_r)); 1650 if (q1 & 0x80) 1644 if (q1 & 0x80) 1651 q1_cal = (10000 - ((q1 & 0x7F 1645 q1_cal = (10000 - ((q1 & 0x7F) * 25)); 1652 else 1646 else 1653 q1_cal = (10000 + (q1 * 25)); 1647 q1_cal = (10000 + (q1 * 25)); 1654 if (q1_cal > 0) 1648 if (q1_cal > 0) 1655 *z_val = ((*z_val) * 10000) / 1649 *z_val = ((*z_val) * 10000) / q1_cal; 1656 } 1650 } 1657 1651 1658 static void wcd937x_wcd_mbhc_calc_impedance(s 1652 static void wcd937x_wcd_mbhc_calc_impedance(struct snd_soc_component *component, 1659 u 1653 u32 *zl, u32 *zr) 1660 { 1654 { 1661 struct wcd937x_priv *wcd937x = snd_so 1655 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1662 s16 reg0, reg1, reg2, reg3, reg4; 1656 s16 reg0, reg1, reg2, reg3, reg4; 1663 s32 z1l, z1r, z1ls; 1657 s32 z1l, z1r, z1ls; 1664 int zMono, z_diff1, z_diff2; 1658 int zMono, z_diff1, z_diff2; 1665 bool is_fsm_disable = false; 1659 bool is_fsm_disable = false; 1666 struct wcd937x_mbhc_zdet_param zdet_p 1660 struct wcd937x_mbhc_zdet_param zdet_param[] = { 1667 {4, 0, 4, 0x08, 0x14, 0x18}, 1661 {4, 0, 4, 0x08, 0x14, 0x18}, /* < 32ohm */ 1668 {2, 0, 3, 0x18, 0x7C, 0x90}, 1662 {2, 0, 3, 0x18, 0x7C, 0x90}, /* 32ohm < Z < 400ohm */ 1669 {1, 4, 5, 0x18, 0x7C, 0x90}, 1663 {1, 4, 5, 0x18, 0x7C, 0x90}, /* 400ohm < Z < 1200ohm */ 1670 {1, 6, 7, 0x18, 0x7C, 0x90}, 1664 {1, 6, 7, 0x18, 0x7C, 0x90}, /* >1200ohm */ 1671 }; 1665 }; 1672 struct wcd937x_mbhc_zdet_param *zdet_ 1666 struct wcd937x_mbhc_zdet_param *zdet_param_ptr = NULL; 1673 s16 d1_a[][4] = { 1667 s16 d1_a[][4] = { 1674 {0, 30, 90, 30}, 1668 {0, 30, 90, 30}, 1675 {0, 30, 30, 5}, 1669 {0, 30, 30, 5}, 1676 {0, 30, 30, 5}, 1670 {0, 30, 30, 5}, 1677 {0, 30, 30, 5}, 1671 {0, 30, 30, 5}, 1678 }; 1672 }; 1679 s16 *d1 = NULL; 1673 s16 *d1 = NULL; 1680 1674 1681 reg0 = snd_soc_component_read(compone 1675 reg0 = snd_soc_component_read(component, WCD937X_ANA_MBHC_BTN5); 1682 reg1 = snd_soc_component_read(compone 1676 reg1 = snd_soc_component_read(component, WCD937X_ANA_MBHC_BTN6); 1683 reg2 = snd_soc_component_read(compone 1677 reg2 = snd_soc_component_read(component, WCD937X_ANA_MBHC_BTN7); 1684 reg3 = snd_soc_component_read(compone 1678 reg3 = snd_soc_component_read(component, WCD937X_MBHC_CTL_CLK); 1685 reg4 = snd_soc_component_read(compone 1679 reg4 = snd_soc_component_read(component, WCD937X_MBHC_NEW_ZDET_ANA_CTL); 1686 1680 1687 if (snd_soc_component_read(component, 1681 if (snd_soc_component_read(component, WCD937X_ANA_MBHC_ELECT) & 0x80) { 1688 is_fsm_disable = true; 1682 is_fsm_disable = true; 1689 regmap_update_bits(wcd937x->r 1683 regmap_update_bits(wcd937x->regmap, 1690 WCD937X_AN 1684 WCD937X_ANA_MBHC_ELECT, 0x80, 0x00); 1691 } 1685 } 1692 1686 1693 /* For NO-jack, disable L_DET_EN befo 1687 /* For NO-jack, disable L_DET_EN before Z-det measurements */ 1694 if (wcd937x->mbhc_cfg.hphl_swh) 1688 if (wcd937x->mbhc_cfg.hphl_swh) 1695 regmap_update_bits(wcd937x->r 1689 regmap_update_bits(wcd937x->regmap, 1696 WCD937X_AN 1690 WCD937X_ANA_MBHC_MECH, 0x80, 0x00); 1697 1691 1698 /* Turn off 100k pull down on HPHL */ 1692 /* Turn off 100k pull down on HPHL */ 1699 regmap_update_bits(wcd937x->regmap, 1693 regmap_update_bits(wcd937x->regmap, 1700 WCD937X_ANA_MBHC_M 1694 WCD937X_ANA_MBHC_MECH, 0x01, 0x00); 1701 1695 1702 /* Disable surge protection before im 1696 /* Disable surge protection before impedance detection. 1703 * This is done to give correct value 1697 * This is done to give correct value for high impedance. 1704 */ 1698 */ 1705 regmap_update_bits(wcd937x->regmap, 1699 regmap_update_bits(wcd937x->regmap, 1706 WCD937X_HPH_SURGE_ 1700 WCD937X_HPH_SURGE_HPHLR_SURGE_EN, 0xC0, 0x00); 1707 /* 1ms delay needed after disable sur 1701 /* 1ms delay needed after disable surge protection */ 1708 usleep_range(1000, 1010); 1702 usleep_range(1000, 1010); 1709 1703 1710 /* First get impedance on Left */ 1704 /* First get impedance on Left */ 1711 d1 = d1_a[1]; 1705 d1 = d1_a[1]; 1712 zdet_param_ptr = &zdet_param[1]; 1706 zdet_param_ptr = &zdet_param[1]; 1713 wcd937x_mbhc_zdet_ramp(component, zde 1707 wcd937x_mbhc_zdet_ramp(component, zdet_param_ptr, &z1l, NULL, d1); 1714 1708 1715 if (!WCD937X_MBHC_IS_SECOND_RAMP_REQU 1709 if (!WCD937X_MBHC_IS_SECOND_RAMP_REQUIRED(z1l)) 1716 goto left_ch_impedance; 1710 goto left_ch_impedance; 1717 1711 1718 /* Second ramp for left ch */ 1712 /* Second ramp for left ch */ 1719 if (z1l < WCD937X_ZDET_VAL_32) { 1713 if (z1l < WCD937X_ZDET_VAL_32) { 1720 zdet_param_ptr = &zdet_param[ 1714 zdet_param_ptr = &zdet_param[0]; 1721 d1 = d1_a[0]; 1715 d1 = d1_a[0]; 1722 } else if ((z1l > WCD937X_ZDET_VAL_40 1716 } else if ((z1l > WCD937X_ZDET_VAL_400) && 1723 (z1l <= WCD937X_ZDET_VAL_12 1717 (z1l <= WCD937X_ZDET_VAL_1200)) { 1724 zdet_param_ptr = &zdet_param[ 1718 zdet_param_ptr = &zdet_param[2]; 1725 d1 = d1_a[2]; 1719 d1 = d1_a[2]; 1726 } else if (z1l > WCD937X_ZDET_VAL_120 1720 } else if (z1l > WCD937X_ZDET_VAL_1200) { 1727 zdet_param_ptr = &zdet_param[ 1721 zdet_param_ptr = &zdet_param[3]; 1728 d1 = d1_a[3]; 1722 d1 = d1_a[3]; 1729 } 1723 } 1730 wcd937x_mbhc_zdet_ramp(component, zde 1724 wcd937x_mbhc_zdet_ramp(component, zdet_param_ptr, &z1l, NULL, d1); 1731 1725 1732 left_ch_impedance: 1726 left_ch_impedance: 1733 if (z1l == WCD937X_ZDET_FLOATING_IMPE 1727 if (z1l == WCD937X_ZDET_FLOATING_IMPEDANCE || 1734 z1l > WCD937X_ZDET_VAL_100K) { 1728 z1l > WCD937X_ZDET_VAL_100K) { 1735 *zl = WCD937X_ZDET_FLOATING_I 1729 *zl = WCD937X_ZDET_FLOATING_IMPEDANCE; 1736 zdet_param_ptr = &zdet_param[ 1730 zdet_param_ptr = &zdet_param[1]; 1737 d1 = d1_a[1]; 1731 d1 = d1_a[1]; 1738 } else { 1732 } else { 1739 *zl = z1l / 1000; 1733 *zl = z1l / 1000; 1740 wcd937x_wcd_mbhc_qfuse_cal(co 1734 wcd937x_wcd_mbhc_qfuse_cal(component, zl, 0); 1741 } 1735 } 1742 1736 1743 /* Start of right impedance ramp and 1737 /* Start of right impedance ramp and calculation */ 1744 wcd937x_mbhc_zdet_ramp(component, zde 1738 wcd937x_mbhc_zdet_ramp(component, zdet_param_ptr, NULL, &z1r, d1); 1745 if (WCD937X_MBHC_IS_SECOND_RAMP_REQUI 1739 if (WCD937X_MBHC_IS_SECOND_RAMP_REQUIRED(z1r)) { 1746 if ((z1r > WCD937X_ZDET_VAL_1 1740 if ((z1r > WCD937X_ZDET_VAL_1200 && 1747 zdet_param_ptr->noff == 1741 zdet_param_ptr->noff == 0x6) || 1748 ((*zl) != WCD937X_ZDET_F 1742 ((*zl) != WCD937X_ZDET_FLOATING_IMPEDANCE)) 1749 goto right_ch_impedan 1743 goto right_ch_impedance; 1750 /* Second ramp for right ch * 1744 /* Second ramp for right ch */ 1751 if (z1r < WCD937X_ZDET_VAL_32 1745 if (z1r < WCD937X_ZDET_VAL_32) { 1752 zdet_param_ptr = &zde 1746 zdet_param_ptr = &zdet_param[0]; 1753 d1 = d1_a[0]; 1747 d1 = d1_a[0]; 1754 } else if ((z1r > WCD937X_ZDE 1748 } else if ((z1r > WCD937X_ZDET_VAL_400) && 1755 (z1r <= WCD937X_ZDET_ 1749 (z1r <= WCD937X_ZDET_VAL_1200)) { 1756 zdet_param_ptr = &zde 1750 zdet_param_ptr = &zdet_param[2]; 1757 d1 = d1_a[2]; 1751 d1 = d1_a[2]; 1758 } else if (z1r > WCD937X_ZDET 1752 } else if (z1r > WCD937X_ZDET_VAL_1200) { 1759 zdet_param_ptr = &zde 1753 zdet_param_ptr = &zdet_param[3]; 1760 d1 = d1_a[3]; 1754 d1 = d1_a[3]; 1761 } 1755 } 1762 wcd937x_mbhc_zdet_ramp(compon 1756 wcd937x_mbhc_zdet_ramp(component, zdet_param_ptr, NULL, &z1r, d1); 1763 } 1757 } 1764 right_ch_impedance: 1758 right_ch_impedance: 1765 if (z1r == WCD937X_ZDET_FLOATING_IMPE 1759 if (z1r == WCD937X_ZDET_FLOATING_IMPEDANCE || 1766 z1r > WCD937X_ZDET_VAL_100K) { 1760 z1r > WCD937X_ZDET_VAL_100K) { 1767 *zr = WCD937X_ZDET_FLOATING_I 1761 *zr = WCD937X_ZDET_FLOATING_IMPEDANCE; 1768 } else { 1762 } else { 1769 *zr = z1r / 1000; 1763 *zr = z1r / 1000; 1770 wcd937x_wcd_mbhc_qfuse_cal(co 1764 wcd937x_wcd_mbhc_qfuse_cal(component, zr, 1); 1771 } 1765 } 1772 1766 1773 /* Mono/stereo detection */ 1767 /* Mono/stereo detection */ 1774 if ((*zl == WCD937X_ZDET_FLOATING_IMP 1768 if ((*zl == WCD937X_ZDET_FLOATING_IMPEDANCE) && 1775 (*zr == WCD937X_ZDET_FLOATING_IMP 1769 (*zr == WCD937X_ZDET_FLOATING_IMPEDANCE)) { 1776 dev_err(component->dev, 1770 dev_err(component->dev, 1777 "%s: plug type is inv 1771 "%s: plug type is invalid or extension cable\n", 1778 __func__); 1772 __func__); 1779 goto zdet_complete; 1773 goto zdet_complete; 1780 } 1774 } 1781 if ((*zl == WCD937X_ZDET_FLOATING_IMP 1775 if ((*zl == WCD937X_ZDET_FLOATING_IMPEDANCE) || 1782 (*zr == WCD937X_ZDET_FLOATING_IMP 1776 (*zr == WCD937X_ZDET_FLOATING_IMPEDANCE) || 1783 ((*zl < WCD_MONO_HS_MIN_THR) && ( 1777 ((*zl < WCD_MONO_HS_MIN_THR) && (*zr > WCD_MONO_HS_MIN_THR)) || 1784 ((*zl > WCD_MONO_HS_MIN_THR) && ( 1778 ((*zl > WCD_MONO_HS_MIN_THR) && (*zr < WCD_MONO_HS_MIN_THR))) { 1785 wcd_mbhc_set_hph_type(wcd937x 1779 wcd_mbhc_set_hph_type(wcd937x->wcd_mbhc, WCD_MBHC_HPH_MONO); 1786 goto zdet_complete; 1780 goto zdet_complete; 1787 } 1781 } 1788 snd_soc_component_write_field(compone 1782 snd_soc_component_write_field(component, WCD937X_HPH_R_ATEST, 1789 WCD937X 1783 WCD937X_HPHPA_GND_OVR_MASK, 1); 1790 snd_soc_component_write_field(compone 1784 snd_soc_component_write_field(component, WCD937X_HPH_PA_CTL2, 1791 WCD937X 1785 WCD937X_HPHPA_GND_R_MASK, 1); 1792 if (*zl < (WCD937X_ZDET_VAL_32 / 1000 1786 if (*zl < (WCD937X_ZDET_VAL_32 / 1000)) 1793 wcd937x_mbhc_zdet_ramp(compon 1787 wcd937x_mbhc_zdet_ramp(component, &zdet_param[0], &z1ls, NULL, d1); 1794 else 1788 else 1795 wcd937x_mbhc_zdet_ramp(compon 1789 wcd937x_mbhc_zdet_ramp(component, &zdet_param[1], &z1ls, NULL, d1); 1796 snd_soc_component_write_field(compone 1790 snd_soc_component_write_field(component, WCD937X_HPH_PA_CTL2, 1797 WCD937X 1791 WCD937X_HPHPA_GND_R_MASK, 0); 1798 snd_soc_component_write_field(compone 1792 snd_soc_component_write_field(component, WCD937X_HPH_R_ATEST, 1799 WCD937X 1793 WCD937X_HPHPA_GND_OVR_MASK, 0); 1800 z1ls /= 1000; 1794 z1ls /= 1000; 1801 wcd937x_wcd_mbhc_qfuse_cal(component, 1795 wcd937x_wcd_mbhc_qfuse_cal(component, &z1ls, 0); 1802 /* Parallel of left Z and 9 ohm pull 1796 /* Parallel of left Z and 9 ohm pull down resistor */ 1803 zMono = ((*zl) * 9) / ((*zl) + 9); 1797 zMono = ((*zl) * 9) / ((*zl) + 9); 1804 z_diff1 = (z1ls > zMono) ? (z1ls - zM 1798 z_diff1 = (z1ls > zMono) ? (z1ls - zMono) : (zMono - z1ls); 1805 z_diff2 = ((*zl) > z1ls) ? ((*zl) - z 1799 z_diff2 = ((*zl) > z1ls) ? ((*zl) - z1ls) : (z1ls - (*zl)); 1806 if ((z_diff1 * (*zl + z1ls)) > (z_dif 1800 if ((z_diff1 * (*zl + z1ls)) > (z_diff2 * (z1ls + zMono))) 1807 wcd_mbhc_set_hph_type(wcd937x 1801 wcd_mbhc_set_hph_type(wcd937x->wcd_mbhc, WCD_MBHC_HPH_STEREO); 1808 else 1802 else 1809 wcd_mbhc_set_hph_type(wcd937x 1803 wcd_mbhc_set_hph_type(wcd937x->wcd_mbhc, WCD_MBHC_HPH_MONO); 1810 1804 1811 /* Enable surge protection again afte 1805 /* Enable surge protection again after impedance detection */ 1812 regmap_update_bits(wcd937x->regmap, 1806 regmap_update_bits(wcd937x->regmap, 1813 WCD937X_HPH_SURGE_ 1807 WCD937X_HPH_SURGE_HPHLR_SURGE_EN, 0xC0, 0xC0); 1814 zdet_complete: 1808 zdet_complete: 1815 snd_soc_component_write(component, WC 1809 snd_soc_component_write(component, WCD937X_ANA_MBHC_BTN5, reg0); 1816 snd_soc_component_write(component, WC 1810 snd_soc_component_write(component, WCD937X_ANA_MBHC_BTN6, reg1); 1817 snd_soc_component_write(component, WC 1811 snd_soc_component_write(component, WCD937X_ANA_MBHC_BTN7, reg2); 1818 /* Turn on 100k pull down on HPHL */ 1812 /* Turn on 100k pull down on HPHL */ 1819 regmap_update_bits(wcd937x->regmap, 1813 regmap_update_bits(wcd937x->regmap, 1820 WCD937X_ANA_MBHC_M 1814 WCD937X_ANA_MBHC_MECH, 0x01, 0x01); 1821 1815 1822 /* For NO-jack, re-enable L_DET_EN af 1816 /* For NO-jack, re-enable L_DET_EN after Z-det measurements */ 1823 if (wcd937x->mbhc_cfg.hphl_swh) 1817 if (wcd937x->mbhc_cfg.hphl_swh) 1824 regmap_update_bits(wcd937x->r 1818 regmap_update_bits(wcd937x->regmap, 1825 WCD937X_AN 1819 WCD937X_ANA_MBHC_MECH, 0x80, 0x80); 1826 1820 1827 snd_soc_component_write(component, WC 1821 snd_soc_component_write(component, WCD937X_MBHC_NEW_ZDET_ANA_CTL, reg4); 1828 snd_soc_component_write(component, WC 1822 snd_soc_component_write(component, WCD937X_MBHC_CTL_CLK, reg3); 1829 if (is_fsm_disable) 1823 if (is_fsm_disable) 1830 regmap_update_bits(wcd937x->r 1824 regmap_update_bits(wcd937x->regmap, 1831 WCD937X_AN 1825 WCD937X_ANA_MBHC_ELECT, 0x80, 0x80); 1832 } 1826 } 1833 1827 1834 static void wcd937x_mbhc_gnd_det_ctrl(struct 1828 static void wcd937x_mbhc_gnd_det_ctrl(struct snd_soc_component *component, 1835 bool en 1829 bool enable) 1836 { 1830 { 1837 if (enable) { 1831 if (enable) { 1838 snd_soc_component_write_field 1832 snd_soc_component_write_field(component, WCD937X_ANA_MBHC_MECH, 1839 1833 WCD937X_MBHC_HSG_PULLUP_COMP_EN, 1); 1840 snd_soc_component_write_field 1834 snd_soc_component_write_field(component, WCD937X_ANA_MBHC_MECH, 1841 1835 WCD937X_MBHC_GND_DET_EN_MASK, 1); 1842 } else { 1836 } else { 1843 snd_soc_component_write_field 1837 snd_soc_component_write_field(component, WCD937X_ANA_MBHC_MECH, 1844 1838 WCD937X_MBHC_GND_DET_EN_MASK, 0); 1845 snd_soc_component_write_field 1839 snd_soc_component_write_field(component, WCD937X_ANA_MBHC_MECH, 1846 1840 WCD937X_MBHC_HSG_PULLUP_COMP_EN, 0); 1847 } 1841 } 1848 } 1842 } 1849 1843 1850 static void wcd937x_mbhc_hph_pull_down_ctrl(s 1844 static void wcd937x_mbhc_hph_pull_down_ctrl(struct snd_soc_component *component, 1851 b 1845 bool enable) 1852 { 1846 { 1853 snd_soc_component_write_field(compone 1847 snd_soc_component_write_field(component, WCD937X_HPH_PA_CTL2, 1854 WCD937X 1848 WCD937X_HPHPA_GND_R_MASK, enable); 1855 snd_soc_component_write_field(compone 1849 snd_soc_component_write_field(component, WCD937X_HPH_PA_CTL2, 1856 WCD937X 1850 WCD937X_HPHPA_GND_L_MASK, enable); 1857 } 1851 } 1858 1852 1859 static void wcd937x_mbhc_moisture_config(stru 1853 static void wcd937x_mbhc_moisture_config(struct snd_soc_component *component) 1860 { 1854 { 1861 struct wcd937x_priv *wcd937x = snd_so 1855 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1862 1856 1863 if (wcd937x->mbhc_cfg.moist_rref == R 1857 if (wcd937x->mbhc_cfg.moist_rref == R_OFF) { 1864 snd_soc_component_write_field 1858 snd_soc_component_write_field(component, WCD937X_MBHC_NEW_CTL_2, 1865 1859 WCD937X_M_RTH_CTL_MASK, R_OFF); 1866 return; 1860 return; 1867 } 1861 } 1868 1862 1869 /* Do not enable moisture detection i 1863 /* Do not enable moisture detection if jack type is NC */ 1870 if (!wcd937x->mbhc_cfg.hphl_swh) { 1864 if (!wcd937x->mbhc_cfg.hphl_swh) { 1871 dev_err(component->dev, "%s: 1865 dev_err(component->dev, "%s: disable moisture detection for NC\n", 1872 __func__); 1866 __func__); 1873 snd_soc_component_write_field 1867 snd_soc_component_write_field(component, WCD937X_MBHC_NEW_CTL_2, 1874 1868 WCD937X_M_RTH_CTL_MASK, R_OFF); 1875 return; 1869 return; 1876 } 1870 } 1877 1871 1878 snd_soc_component_write_field(compone 1872 snd_soc_component_write_field(component, WCD937X_MBHC_NEW_CTL_2, 1879 WCD937X 1873 WCD937X_M_RTH_CTL_MASK, wcd937x->mbhc_cfg.moist_rref); 1880 } 1874 } 1881 1875 1882 static void wcd937x_mbhc_moisture_detect_en(s 1876 static void wcd937x_mbhc_moisture_detect_en(struct snd_soc_component *component, bool enable) 1883 { 1877 { 1884 struct wcd937x_priv *wcd937x = snd_so 1878 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1885 1879 1886 if (enable) 1880 if (enable) 1887 snd_soc_component_write_field 1881 snd_soc_component_write_field(component, WCD937X_MBHC_NEW_CTL_2, 1888 1882 WCD937X_M_RTH_CTL_MASK, wcd937x->mbhc_cfg.moist_rref); 1889 else 1883 else 1890 snd_soc_component_write_field 1884 snd_soc_component_write_field(component, WCD937X_MBHC_NEW_CTL_2, 1891 1885 WCD937X_M_RTH_CTL_MASK, R_OFF); 1892 } 1886 } 1893 1887 1894 static bool wcd937x_mbhc_get_moisture_status( 1888 static bool wcd937x_mbhc_get_moisture_status(struct snd_soc_component *component) 1895 { 1889 { 1896 struct wcd937x_priv *wcd937x = snd_so 1890 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1897 bool ret = false; 1891 bool ret = false; 1898 1892 1899 if (wcd937x->mbhc_cfg.moist_rref == R 1893 if (wcd937x->mbhc_cfg.moist_rref == R_OFF) { 1900 snd_soc_component_write_field 1894 snd_soc_component_write_field(component, WCD937X_MBHC_NEW_CTL_2, 1901 1895 WCD937X_M_RTH_CTL_MASK, R_OFF); 1902 goto done; 1896 goto done; 1903 } 1897 } 1904 1898 1905 /* Do not enable moisture detection i 1899 /* Do not enable moisture detection if jack type is NC */ 1906 if (!wcd937x->mbhc_cfg.hphl_swh) { 1900 if (!wcd937x->mbhc_cfg.hphl_swh) { 1907 dev_err(component->dev, "%s: 1901 dev_err(component->dev, "%s: disable moisture detection for NC\n", 1908 __func__); 1902 __func__); 1909 snd_soc_component_write_field 1903 snd_soc_component_write_field(component, WCD937X_MBHC_NEW_CTL_2, 1910 1904 WCD937X_M_RTH_CTL_MASK, R_OFF); 1911 goto done; 1905 goto done; 1912 } 1906 } 1913 1907 1914 /* 1908 /* 1915 * If moisture_en is already enabled, 1909 * If moisture_en is already enabled, then skip to plug type 1916 * detection. 1910 * detection. 1917 */ 1911 */ 1918 if (snd_soc_component_read_field(comp 1912 if (snd_soc_component_read_field(component, WCD937X_MBHC_NEW_CTL_2, WCD937X_M_RTH_CTL_MASK)) 1919 goto done; 1913 goto done; 1920 1914 1921 wcd937x_mbhc_moisture_detect_en(compo 1915 wcd937x_mbhc_moisture_detect_en(component, true); 1922 /* Read moisture comparator status */ 1916 /* Read moisture comparator status */ 1923 ret = ((snd_soc_component_read(compon 1917 ret = ((snd_soc_component_read(component, WCD937X_MBHC_NEW_FSM_STATUS) 1924 & 0x20 1918 & 0x20) ? 0 : 1); 1925 done: 1919 done: 1926 return ret; 1920 return ret; 1927 } 1921 } 1928 1922 1929 static void wcd937x_mbhc_moisture_polling_ctr 1923 static void wcd937x_mbhc_moisture_polling_ctrl(struct snd_soc_component *component, 1930 1924 bool enable) 1931 { 1925 { 1932 snd_soc_component_write_field(compone 1926 snd_soc_component_write_field(component, 1933 WCD937X 1927 WCD937X_MBHC_NEW_INT_MOISTURE_DET_POLLING_CTRL, 1934 WCD937X 1928 WCD937X_MOISTURE_EN_POLLING_MASK, enable); 1935 } 1929 } 1936 1930 1937 static const struct wcd_mbhc_cb mbhc_cb = { 1931 static const struct wcd_mbhc_cb mbhc_cb = { 1938 .clk_setup = wcd937x_mbhc_clk_setup, 1932 .clk_setup = wcd937x_mbhc_clk_setup, 1939 .mbhc_bias = wcd937x_mbhc_mbhc_bias_c 1933 .mbhc_bias = wcd937x_mbhc_mbhc_bias_control, 1940 .set_btn_thr = wcd937x_mbhc_program_b 1934 .set_btn_thr = wcd937x_mbhc_program_btn_thr, 1941 .micbias_enable_status = wcd937x_mbhc 1935 .micbias_enable_status = wcd937x_mbhc_micb_en_status, 1942 .hph_pull_up_control_v2 = wcd937x_mbh 1936 .hph_pull_up_control_v2 = wcd937x_mbhc_hph_l_pull_up_control, 1943 .mbhc_micbias_control = wcd937x_mbhc_ 1937 .mbhc_micbias_control = wcd937x_mbhc_request_micbias, 1944 .mbhc_micb_ramp_control = wcd937x_mbh 1938 .mbhc_micb_ramp_control = wcd937x_mbhc_micb_ramp_control, 1945 .mbhc_micb_ctrl_thr_mic = wcd937x_mbh 1939 .mbhc_micb_ctrl_thr_mic = wcd937x_mbhc_micb_ctrl_threshold_mic, 1946 .compute_impedance = wcd937x_wcd_mbhc 1940 .compute_impedance = wcd937x_wcd_mbhc_calc_impedance, 1947 .mbhc_gnd_det_ctrl = wcd937x_mbhc_gnd 1941 .mbhc_gnd_det_ctrl = wcd937x_mbhc_gnd_det_ctrl, 1948 .hph_pull_down_ctrl = wcd937x_mbhc_hp 1942 .hph_pull_down_ctrl = wcd937x_mbhc_hph_pull_down_ctrl, 1949 .mbhc_moisture_config = wcd937x_mbhc_ 1943 .mbhc_moisture_config = wcd937x_mbhc_moisture_config, 1950 .mbhc_get_moisture_status = wcd937x_m 1944 .mbhc_get_moisture_status = wcd937x_mbhc_get_moisture_status, 1951 .mbhc_moisture_polling_ctrl = wcd937x 1945 .mbhc_moisture_polling_ctrl = wcd937x_mbhc_moisture_polling_ctrl, 1952 .mbhc_moisture_detect_en = wcd937x_mb 1946 .mbhc_moisture_detect_en = wcd937x_mbhc_moisture_detect_en, 1953 }; 1947 }; 1954 1948 1955 static int wcd937x_get_hph_type(struct snd_kc 1949 static int wcd937x_get_hph_type(struct snd_kcontrol *kcontrol, 1956 struct snd_ct 1950 struct snd_ctl_elem_value *ucontrol) 1957 { 1951 { 1958 struct snd_soc_component *component = 1952 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); 1959 struct wcd937x_priv *wcd937x = snd_so 1953 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1960 1954 1961 ucontrol->value.integer.value[0] = wc 1955 ucontrol->value.integer.value[0] = wcd_mbhc_get_hph_type(wcd937x->wcd_mbhc); 1962 1956 1963 return 0; 1957 return 0; 1964 } 1958 } 1965 1959 1966 static int wcd937x_hph_impedance_get(struct s 1960 static int wcd937x_hph_impedance_get(struct snd_kcontrol *kcontrol, 1967 struct s 1961 struct snd_ctl_elem_value *ucontrol) 1968 { 1962 { 1969 u32 zl, zr; 1963 u32 zl, zr; 1970 bool hphr; 1964 bool hphr; 1971 struct soc_mixer_control *mc; 1965 struct soc_mixer_control *mc; 1972 struct snd_soc_component *component = 1966 struct snd_soc_component *component = 1973 snd_s 1967 snd_soc_kcontrol_component(kcontrol); 1974 struct wcd937x_priv *wcd937x = snd_so 1968 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1975 1969 1976 mc = (struct soc_mixer_control *)(kco 1970 mc = (struct soc_mixer_control *)(kcontrol->private_value); 1977 hphr = mc->shift; 1971 hphr = mc->shift; 1978 wcd_mbhc_get_impedance(wcd937x->wcd_m 1972 wcd_mbhc_get_impedance(wcd937x->wcd_mbhc, &zl, &zr); 1979 ucontrol->value.integer.value[0] = hp 1973 ucontrol->value.integer.value[0] = hphr ? zr : zl; 1980 1974 1981 return 0; 1975 return 0; 1982 } 1976 } 1983 1977 1984 static const struct snd_kcontrol_new hph_type 1978 static const struct snd_kcontrol_new hph_type_detect_controls[] = { 1985 SOC_SINGLE_EXT("HPH Type", 0, 0, WCD_ 1979 SOC_SINGLE_EXT("HPH Type", 0, 0, WCD_MBHC_HPH_STEREO, 0, 1986 wcd937x_get_hph_type, 1980 wcd937x_get_hph_type, NULL), 1987 }; 1981 }; 1988 1982 1989 static const struct snd_kcontrol_new impedanc 1983 static const struct snd_kcontrol_new impedance_detect_controls[] = { 1990 SOC_SINGLE_EXT("HPHL Impedance", 0, 0 1984 SOC_SINGLE_EXT("HPHL Impedance", 0, 0, INT_MAX, 0, 1991 wcd937x_hph_impedance_ 1985 wcd937x_hph_impedance_get, NULL), 1992 SOC_SINGLE_EXT("HPHR Impedance", 0, 1 1986 SOC_SINGLE_EXT("HPHR Impedance", 0, 1, INT_MAX, 0, 1993 wcd937x_hph_impedance_ 1987 wcd937x_hph_impedance_get, NULL), 1994 }; 1988 }; 1995 1989 1996 static int wcd937x_mbhc_init(struct snd_soc_c 1990 static int wcd937x_mbhc_init(struct snd_soc_component *component) 1997 { 1991 { 1998 struct wcd937x_priv *wcd937x = snd_so 1992 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 1999 struct wcd_mbhc_intr *intr_ids = &wcd 1993 struct wcd_mbhc_intr *intr_ids = &wcd937x->intr_ids; 2000 1994 2001 intr_ids->mbhc_sw_intr = regmap_irq_g 1995 intr_ids->mbhc_sw_intr = regmap_irq_get_virq(wcd937x->irq_chip, 2002 1996 WCD937X_IRQ_MBHC_SW_DET); 2003 intr_ids->mbhc_btn_press_intr = regma 1997 intr_ids->mbhc_btn_press_intr = regmap_irq_get_virq(wcd937x->irq_chip, 2004 1998 WCD937X_IRQ_MBHC_BUTTON_PRESS_DET); 2005 intr_ids->mbhc_btn_release_intr = reg 1999 intr_ids->mbhc_btn_release_intr = regmap_irq_get_virq(wcd937x->irq_chip, 2006 2000 WCD937X_IRQ_MBHC_BUTTON_RELEASE_DET); 2007 intr_ids->mbhc_hs_ins_intr = regmap_i 2001 intr_ids->mbhc_hs_ins_intr = regmap_irq_get_virq(wcd937x->irq_chip, 2008 2002 WCD937X_IRQ_MBHC_ELECT_INS_REM_LEG_DET); 2009 intr_ids->mbhc_hs_rem_intr = regmap_i 2003 intr_ids->mbhc_hs_rem_intr = regmap_irq_get_virq(wcd937x->irq_chip, 2010 2004 WCD937X_IRQ_MBHC_ELECT_INS_REM_DET); 2011 intr_ids->hph_left_ocp = regmap_irq_g 2005 intr_ids->hph_left_ocp = regmap_irq_get_virq(wcd937x->irq_chip, 2012 2006 WCD937X_IRQ_HPHL_OCP_INT); 2013 intr_ids->hph_right_ocp = regmap_irq_ 2007 intr_ids->hph_right_ocp = regmap_irq_get_virq(wcd937x->irq_chip, 2014 2008 WCD937X_IRQ_HPHR_OCP_INT); 2015 2009 2016 wcd937x->wcd_mbhc = wcd_mbhc_init(com 2010 wcd937x->wcd_mbhc = wcd_mbhc_init(component, &mbhc_cb, intr_ids, wcd_mbhc_fields, true); 2017 if (IS_ERR(wcd937x->wcd_mbhc)) 2011 if (IS_ERR(wcd937x->wcd_mbhc)) 2018 return PTR_ERR(wcd937x->wcd_m 2012 return PTR_ERR(wcd937x->wcd_mbhc); 2019 2013 2020 snd_soc_add_component_controls(compon 2014 snd_soc_add_component_controls(component, impedance_detect_controls, 2021 ARRAY_ 2015 ARRAY_SIZE(impedance_detect_controls)); 2022 snd_soc_add_component_controls(compon 2016 snd_soc_add_component_controls(component, hph_type_detect_controls, 2023 ARRAY_ 2017 ARRAY_SIZE(hph_type_detect_controls)); 2024 2018 2025 return 0; 2019 return 0; 2026 } 2020 } 2027 2021 2028 static void wcd937x_mbhc_deinit(struct snd_so 2022 static void wcd937x_mbhc_deinit(struct snd_soc_component *component) 2029 { 2023 { 2030 struct wcd937x_priv *wcd937x = snd_so 2024 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 2031 2025 2032 wcd_mbhc_deinit(wcd937x->wcd_mbhc); 2026 wcd_mbhc_deinit(wcd937x->wcd_mbhc); 2033 } 2027 } 2034 2028 2035 /* END MBHC */ 2029 /* END MBHC */ 2036 2030 2037 static const struct snd_kcontrol_new wcd937x_ 2031 static const struct snd_kcontrol_new wcd937x_snd_controls[] = { 2038 SOC_SINGLE_TLV("EAR_PA Volume", WCD93 2032 SOC_SINGLE_TLV("EAR_PA Volume", WCD937X_ANA_EAR_COMPANDER_CTL, 2039 2, 0x10, 0, ear_pa_gai 2033 2, 0x10, 0, ear_pa_gain), 2040 SOC_ENUM_EXT("RX HPH Mode", rx_hph_mo 2034 SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum, 2041 wcd937x_rx_hph_mode_get, 2035 wcd937x_rx_hph_mode_get, wcd937x_rx_hph_mode_put), 2042 2036 2043 SOC_SINGLE_EXT("HPHL_COMP Switch", SN 2037 SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0, 2044 wcd937x_get_compander, 2038 wcd937x_get_compander, wcd937x_set_compander), 2045 SOC_SINGLE_EXT("HPHR_COMP Switch", SN 2039 SOC_SINGLE_EXT("HPHR_COMP Switch", SND_SOC_NOPM, 1, 1, 0, 2046 wcd937x_get_compander, 2040 wcd937x_get_compander, wcd937x_set_compander), 2047 2041 2048 SOC_SINGLE_TLV("HPHL Volume", WCD937X 2042 SOC_SINGLE_TLV("HPHL Volume", WCD937X_HPH_L_EN, 0, 20, 1, line_gain), 2049 SOC_SINGLE_TLV("HPHR Volume", WCD937X 2043 SOC_SINGLE_TLV("HPHR Volume", WCD937X_HPH_R_EN, 0, 20, 1, line_gain), 2050 SOC_SINGLE_TLV("ADC1 Volume", WCD937X 2044 SOC_SINGLE_TLV("ADC1 Volume", WCD937X_ANA_TX_CH1, 0, 20, 0, analog_gain), 2051 SOC_SINGLE_TLV("ADC2 Volume", WCD937X 2045 SOC_SINGLE_TLV("ADC2 Volume", WCD937X_ANA_TX_CH2, 0, 20, 0, analog_gain), 2052 SOC_SINGLE_TLV("ADC3 Volume", WCD937X 2046 SOC_SINGLE_TLV("ADC3 Volume", WCD937X_ANA_TX_CH3, 0, 20, 0, analog_gain), 2053 2047 2054 SOC_SINGLE_EXT("HPHL Switch", WCD937X 2048 SOC_SINGLE_EXT("HPHL Switch", WCD937X_HPH_L, 0, 1, 0, 2055 wcd937x_get_swr_port, 2049 wcd937x_get_swr_port, wcd937x_set_swr_port), 2056 SOC_SINGLE_EXT("HPHR Switch", WCD937X 2050 SOC_SINGLE_EXT("HPHR Switch", WCD937X_HPH_R, 0, 1, 0, 2057 wcd937x_get_swr_port, 2051 wcd937x_get_swr_port, wcd937x_set_swr_port), 2058 SOC_SINGLE_EXT("LO Switch", WCD937X_L << 2059 wcd937x_get_swr_port, << 2060 2052 2061 SOC_SINGLE_EXT("ADC1 Switch", WCD937X 2053 SOC_SINGLE_EXT("ADC1 Switch", WCD937X_ADC1, 1, 1, 0, 2062 wcd937x_get_swr_port, 2054 wcd937x_get_swr_port, wcd937x_set_swr_port), 2063 SOC_SINGLE_EXT("ADC2 Switch", WCD937X 2055 SOC_SINGLE_EXT("ADC2 Switch", WCD937X_ADC2, 1, 1, 0, 2064 wcd937x_get_swr_port, 2056 wcd937x_get_swr_port, wcd937x_set_swr_port), 2065 SOC_SINGLE_EXT("ADC3 Switch", WCD937X 2057 SOC_SINGLE_EXT("ADC3 Switch", WCD937X_ADC3, 1, 1, 0, 2066 wcd937x_get_swr_port, 2058 wcd937x_get_swr_port, wcd937x_set_swr_port), 2067 SOC_SINGLE_EXT("DMIC0 Switch", WCD937 2059 SOC_SINGLE_EXT("DMIC0 Switch", WCD937X_DMIC0, 1, 1, 0, 2068 wcd937x_get_swr_port, 2060 wcd937x_get_swr_port, wcd937x_set_swr_port), 2069 SOC_SINGLE_EXT("DMIC1 Switch", WCD937 2061 SOC_SINGLE_EXT("DMIC1 Switch", WCD937X_DMIC1, 1, 1, 0, 2070 wcd937x_get_swr_port, 2062 wcd937x_get_swr_port, wcd937x_set_swr_port), 2071 SOC_SINGLE_EXT("MBHC Switch", WCD937X 2063 SOC_SINGLE_EXT("MBHC Switch", WCD937X_MBHC, 1, 1, 0, 2072 wcd937x_get_swr_port, 2064 wcd937x_get_swr_port, wcd937x_set_swr_port), 2073 SOC_SINGLE_EXT("DMIC2 Switch", WCD937 2065 SOC_SINGLE_EXT("DMIC2 Switch", WCD937X_DMIC2, 1, 1, 0, 2074 wcd937x_get_swr_port, 2066 wcd937x_get_swr_port, wcd937x_set_swr_port), 2075 SOC_SINGLE_EXT("DMIC3 Switch", WCD937 2067 SOC_SINGLE_EXT("DMIC3 Switch", WCD937X_DMIC3, 1, 1, 0, 2076 wcd937x_get_swr_port, 2068 wcd937x_get_swr_port, wcd937x_set_swr_port), 2077 SOC_SINGLE_EXT("DMIC4 Switch", WCD937 2069 SOC_SINGLE_EXT("DMIC4 Switch", WCD937X_DMIC4, 1, 1, 0, 2078 wcd937x_get_swr_port, 2070 wcd937x_get_swr_port, wcd937x_set_swr_port), 2079 SOC_SINGLE_EXT("DMIC5 Switch", WCD937 2071 SOC_SINGLE_EXT("DMIC5 Switch", WCD937X_DMIC5, 1, 1, 0, 2080 wcd937x_get_swr_port, 2072 wcd937x_get_swr_port, wcd937x_set_swr_port), 2081 }; 2073 }; 2082 2074 2083 static const struct snd_kcontrol_new adc1_swi 2075 static const struct snd_kcontrol_new adc1_switch[] = { 2084 SOC_DAPM_SINGLE("Switch", SND_SOC_NOP 2076 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) 2085 }; 2077 }; 2086 2078 2087 static const struct snd_kcontrol_new adc2_swi 2079 static const struct snd_kcontrol_new adc2_switch[] = { 2088 SOC_DAPM_SINGLE("Switch", SND_SOC_NOP 2080 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) 2089 }; 2081 }; 2090 2082 2091 static const struct snd_kcontrol_new adc3_swi 2083 static const struct snd_kcontrol_new adc3_switch[] = { 2092 SOC_DAPM_SINGLE("Switch", SND_SOC_NOP 2084 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) 2093 }; 2085 }; 2094 2086 2095 static const struct snd_kcontrol_new dmic1_sw 2087 static const struct snd_kcontrol_new dmic1_switch[] = { 2096 SOC_DAPM_SINGLE("Switch", SND_SOC_NOP 2088 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) 2097 }; 2089 }; 2098 2090 2099 static const struct snd_kcontrol_new dmic2_sw 2091 static const struct snd_kcontrol_new dmic2_switch[] = { 2100 SOC_DAPM_SINGLE("Switch", SND_SOC_NOP 2092 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) 2101 }; 2093 }; 2102 2094 2103 static const struct snd_kcontrol_new dmic3_sw 2095 static const struct snd_kcontrol_new dmic3_switch[] = { 2104 SOC_DAPM_SINGLE("Switch", SND_SOC_NOP 2096 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) 2105 }; 2097 }; 2106 2098 2107 static const struct snd_kcontrol_new dmic4_sw 2099 static const struct snd_kcontrol_new dmic4_switch[] = { 2108 SOC_DAPM_SINGLE("Switch", SND_SOC_NOP 2100 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) 2109 }; 2101 }; 2110 2102 2111 static const struct snd_kcontrol_new dmic5_sw 2103 static const struct snd_kcontrol_new dmic5_switch[] = { 2112 SOC_DAPM_SINGLE("Switch", SND_SOC_NOP 2104 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) 2113 }; 2105 }; 2114 2106 2115 static const struct snd_kcontrol_new dmic6_sw 2107 static const struct snd_kcontrol_new dmic6_switch[] = { 2116 SOC_DAPM_SINGLE("Switch", SND_SOC_NOP 2108 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) 2117 }; 2109 }; 2118 2110 2119 static const struct snd_kcontrol_new ear_rdac 2111 static const struct snd_kcontrol_new ear_rdac_switch[] = { 2120 SOC_DAPM_SINGLE("Switch", SND_SOC_NOP 2112 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) 2121 }; 2113 }; 2122 2114 2123 static const struct snd_kcontrol_new aux_rdac 2115 static const struct snd_kcontrol_new aux_rdac_switch[] = { 2124 SOC_DAPM_SINGLE("Switch", SND_SOC_NOP 2116 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) 2125 }; 2117 }; 2126 2118 2127 static const struct snd_kcontrol_new hphl_rda 2119 static const struct snd_kcontrol_new hphl_rdac_switch[] = { 2128 SOC_DAPM_SINGLE("Switch", SND_SOC_NOP 2120 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) 2129 }; 2121 }; 2130 2122 2131 static const struct snd_kcontrol_new hphr_rda 2123 static const struct snd_kcontrol_new hphr_rdac_switch[] = { 2132 SOC_DAPM_SINGLE("Switch", SND_SOC_NOP 2124 SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0) 2133 }; 2125 }; 2134 2126 2135 static const char * const adc2_mux_text[] = { 2127 static const char * const adc2_mux_text[] = { 2136 "INP2", "INP3" 2128 "INP2", "INP3" 2137 }; 2129 }; 2138 2130 2139 static const char * const rdac3_mux_text[] = 2131 static const char * const rdac3_mux_text[] = { 2140 "RX1", "RX3" 2132 "RX1", "RX3" 2141 }; 2133 }; 2142 2134 2143 static const struct soc_enum adc2_enum = 2135 static const struct soc_enum adc2_enum = 2144 SOC_ENUM_SINGLE(WCD937X_TX_NEW_TX_CH2 2136 SOC_ENUM_SINGLE(WCD937X_TX_NEW_TX_CH2_SEL, 7, 2145 ARRAY_SIZE(adc2_mux_t 2137 ARRAY_SIZE(adc2_mux_text), adc2_mux_text); 2146 2138 2147 static const struct soc_enum rdac3_enum = 2139 static const struct soc_enum rdac3_enum = 2148 SOC_ENUM_SINGLE(WCD937X_DIGITAL_CDC_E 2140 SOC_ENUM_SINGLE(WCD937X_DIGITAL_CDC_EAR_PATH_CTL, 0, 2149 ARRAY_SIZE(rdac3_mux_ 2141 ARRAY_SIZE(rdac3_mux_text), rdac3_mux_text); 2150 2142 2151 static const struct snd_kcontrol_new tx_adc2_ 2143 static const struct snd_kcontrol_new tx_adc2_mux = SOC_DAPM_ENUM("ADC2 MUX Mux", adc2_enum); 2152 2144 2153 static const struct snd_kcontrol_new rx_rdac3 2145 static const struct snd_kcontrol_new rx_rdac3_mux = SOC_DAPM_ENUM("RDAC3_MUX Mux", rdac3_enum); 2154 2146 2155 static const struct snd_soc_dapm_widget wcd93 2147 static const struct snd_soc_dapm_widget wcd937x_dapm_widgets[] = { 2156 /* Input widgets */ 2148 /* Input widgets */ 2157 SND_SOC_DAPM_INPUT("AMIC1"), 2149 SND_SOC_DAPM_INPUT("AMIC1"), 2158 SND_SOC_DAPM_INPUT("AMIC2"), 2150 SND_SOC_DAPM_INPUT("AMIC2"), 2159 SND_SOC_DAPM_INPUT("AMIC3"), 2151 SND_SOC_DAPM_INPUT("AMIC3"), 2160 SND_SOC_DAPM_INPUT("IN1_HPHL"), 2152 SND_SOC_DAPM_INPUT("IN1_HPHL"), 2161 SND_SOC_DAPM_INPUT("IN2_HPHR"), 2153 SND_SOC_DAPM_INPUT("IN2_HPHR"), 2162 SND_SOC_DAPM_INPUT("IN3_AUX"), 2154 SND_SOC_DAPM_INPUT("IN3_AUX"), 2163 2155 2164 /* TX widgets */ 2156 /* TX widgets */ 2165 SND_SOC_DAPM_ADC_E("ADC1", NULL, SND_ 2157 SND_SOC_DAPM_ADC_E("ADC1", NULL, SND_SOC_NOPM, 0, 0, 2166 wcd937x_codec_enab 2158 wcd937x_codec_enable_adc, 2167 SND_SOC_DAPM_PRE_P 2159 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 2168 SND_SOC_DAPM_ADC_E("ADC2", NULL, SND_ 2160 SND_SOC_DAPM_ADC_E("ADC2", NULL, SND_SOC_NOPM, 1, 0, 2169 wcd937x_codec_enab 2161 wcd937x_codec_enable_adc, 2170 SND_SOC_DAPM_PRE_P 2162 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 2171 2163 2172 SND_SOC_DAPM_MIXER_E("ADC1 REQ", SND_ 2164 SND_SOC_DAPM_MIXER_E("ADC1 REQ", SND_SOC_NOPM, 0, 0, 2173 NULL, 0, wcd937x 2165 NULL, 0, wcd937x_enable_req, 2174 SND_SOC_DAPM_PRE 2166 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 2175 SND_SOC_DAPM_MIXER_E("ADC2 REQ", SND_ 2167 SND_SOC_DAPM_MIXER_E("ADC2 REQ", SND_SOC_NOPM, 0, 0, 2176 NULL, 0, wcd937x 2168 NULL, 0, wcd937x_enable_req, 2177 SND_SOC_DAPM_PRE 2169 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 2178 2170 2179 SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_ 2171 SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0, &tx_adc2_mux), 2180 2172 2181 /* TX mixers */ 2173 /* TX mixers */ 2182 SND_SOC_DAPM_MIXER_E("ADC1_MIXER", SN 2174 SND_SOC_DAPM_MIXER_E("ADC1_MIXER", SND_SOC_NOPM, 0, 0, 2183 adc1_switch, ARR 2175 adc1_switch, ARRAY_SIZE(adc1_switch), 2184 wcd937x_tx_swr_c 2176 wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU | 2185 SND_SOC_DAPM_POS 2177 SND_SOC_DAPM_POST_PMD), 2186 SND_SOC_DAPM_MIXER_E("ADC2_MIXER", SN 2178 SND_SOC_DAPM_MIXER_E("ADC2_MIXER", SND_SOC_NOPM, 1, 0, 2187 adc2_switch, ARR 2179 adc2_switch, ARRAY_SIZE(adc2_switch), 2188 wcd937x_tx_swr_c 2180 wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU | 2189 SND_SOC_DAPM_POS 2181 SND_SOC_DAPM_POST_PMD), 2190 2182 2191 /* MIC_BIAS widgets */ 2183 /* MIC_BIAS widgets */ 2192 SND_SOC_DAPM_SUPPLY("MIC BIAS1", SND_ 2184 SND_SOC_DAPM_SUPPLY("MIC BIAS1", SND_SOC_NOPM, MIC_BIAS_1, 0, 2193 wcd937x_codec_ena 2185 wcd937x_codec_enable_micbias, 2194 SND_SOC_DAPM_PRE_ 2186 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2195 SND_SOC_DAPM_POST 2187 SND_SOC_DAPM_POST_PMD), 2196 SND_SOC_DAPM_SUPPLY("MIC BIAS2", SND_ 2188 SND_SOC_DAPM_SUPPLY("MIC BIAS2", SND_SOC_NOPM, MIC_BIAS_2, 0, 2197 wcd937x_codec_ena 2189 wcd937x_codec_enable_micbias, 2198 SND_SOC_DAPM_PRE_ 2190 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2199 SND_SOC_DAPM_POST 2191 SND_SOC_DAPM_POST_PMD), 2200 SND_SOC_DAPM_SUPPLY("MIC BIAS3", SND_ 2192 SND_SOC_DAPM_SUPPLY("MIC BIAS3", SND_SOC_NOPM, MIC_BIAS_3, 0, 2201 wcd937x_codec_ena 2193 wcd937x_codec_enable_micbias, 2202 SND_SOC_DAPM_PRE_ 2194 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2203 SND_SOC_DAPM_POST 2195 SND_SOC_DAPM_POST_PMD), 2204 2196 2205 SND_SOC_DAPM_SUPPLY("VDD_BUCK", SND_S 2197 SND_SOC_DAPM_SUPPLY("VDD_BUCK", SND_SOC_NOPM, 0, 0, NULL, 0), 2206 SND_SOC_DAPM_SUPPLY_S("CLS_H_PORT", 1 2198 SND_SOC_DAPM_SUPPLY_S("CLS_H_PORT", 1, SND_SOC_NOPM, 0, 0, NULL, 0), 2207 2199 2208 /* RX widgets */ 2200 /* RX widgets */ 2209 SND_SOC_DAPM_PGA_E("EAR PGA", WCD937X 2201 SND_SOC_DAPM_PGA_E("EAR PGA", WCD937X_ANA_EAR, 7, 0, NULL, 0, 2210 wcd937x_codec_enab 2202 wcd937x_codec_enable_ear_pa, 2211 SND_SOC_DAPM_PRE_P 2203 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2212 SND_SOC_DAPM_PRE_P 2204 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), 2213 SND_SOC_DAPM_PGA_E("AUX PGA", WCD937X 2205 SND_SOC_DAPM_PGA_E("AUX PGA", WCD937X_AUX_AUXPA, 7, 0, NULL, 0, 2214 wcd937x_codec_enab 2206 wcd937x_codec_enable_aux_pa, 2215 SND_SOC_DAPM_PRE_P 2207 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2216 SND_SOC_DAPM_PRE_P 2208 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), 2217 SND_SOC_DAPM_PGA_E("HPHL PGA", WCD937 2209 SND_SOC_DAPM_PGA_E("HPHL PGA", WCD937X_ANA_HPH, 7, 0, NULL, 0, 2218 wcd937x_codec_enab 2210 wcd937x_codec_enable_hphl_pa, 2219 SND_SOC_DAPM_PRE_P 2211 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2220 SND_SOC_DAPM_PRE_P 2212 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), 2221 SND_SOC_DAPM_PGA_E("HPHR PGA", WCD937 2213 SND_SOC_DAPM_PGA_E("HPHR PGA", WCD937X_ANA_HPH, 6, 0, NULL, 0, 2222 wcd937x_codec_enab 2214 wcd937x_codec_enable_hphr_pa, 2223 SND_SOC_DAPM_PRE_P 2215 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2224 SND_SOC_DAPM_PRE_P 2216 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), 2225 2217 2226 SND_SOC_DAPM_DAC_E("RDAC1", NULL, SND 2218 SND_SOC_DAPM_DAC_E("RDAC1", NULL, SND_SOC_NOPM, 0, 0, 2227 wcd937x_codec_hphl 2219 wcd937x_codec_hphl_dac_event, 2228 SND_SOC_DAPM_PRE_P 2220 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2229 SND_SOC_DAPM_PRE_P 2221 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), 2230 SND_SOC_DAPM_DAC_E("RDAC2", NULL, SND 2222 SND_SOC_DAPM_DAC_E("RDAC2", NULL, SND_SOC_NOPM, 0, 0, 2231 wcd937x_codec_hphr 2223 wcd937x_codec_hphr_dac_event, 2232 SND_SOC_DAPM_PRE_P 2224 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2233 SND_SOC_DAPM_PRE_P 2225 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), 2234 SND_SOC_DAPM_DAC_E("RDAC3", NULL, SND 2226 SND_SOC_DAPM_DAC_E("RDAC3", NULL, SND_SOC_NOPM, 0, 0, 2235 wcd937x_codec_ear_ 2227 wcd937x_codec_ear_dac_event, 2236 SND_SOC_DAPM_PRE_P 2228 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2237 SND_SOC_DAPM_PRE_P 2229 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), 2238 SND_SOC_DAPM_DAC_E("RDAC4", NULL, SND 2230 SND_SOC_DAPM_DAC_E("RDAC4", NULL, SND_SOC_NOPM, 0, 0, 2239 wcd937x_codec_aux_ 2231 wcd937x_codec_aux_dac_event, 2240 SND_SOC_DAPM_PRE_P 2232 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2241 SND_SOC_DAPM_PRE_P 2233 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), 2242 2234 2243 SND_SOC_DAPM_MUX("RDAC3_MUX", SND_SOC 2235 SND_SOC_DAPM_MUX("RDAC3_MUX", SND_SOC_NOPM, 0, 0, &rx_rdac3_mux), 2244 2236 2245 SND_SOC_DAPM_MIXER_E("RX1", SND_SOC_N 2237 SND_SOC_DAPM_MIXER_E("RX1", SND_SOC_NOPM, 0, 0, NULL, 0, 2246 wcd937x_enable_r 2238 wcd937x_enable_rx1, SND_SOC_DAPM_PRE_PMU | 2247 SND_SOC_DAPM_POS 2239 SND_SOC_DAPM_POST_PMD), 2248 SND_SOC_DAPM_MIXER_E("RX2", SND_SOC_N 2240 SND_SOC_DAPM_MIXER_E("RX2", SND_SOC_NOPM, 0, 0, NULL, 0, 2249 wcd937x_enable_r 2241 wcd937x_enable_rx2, SND_SOC_DAPM_PRE_PMU | 2250 SND_SOC_DAPM_POS 2242 SND_SOC_DAPM_POST_PMD), 2251 SND_SOC_DAPM_MIXER_E("RX3", SND_SOC_N 2243 SND_SOC_DAPM_MIXER_E("RX3", SND_SOC_NOPM, 0, 0, NULL, 0, 2252 wcd937x_enable_r 2244 wcd937x_enable_rx3, SND_SOC_DAPM_PRE_PMU | 2253 SND_SOC_DAPM_POS 2245 SND_SOC_DAPM_POST_PMD), 2254 2246 2255 /* RX mixer widgets*/ 2247 /* RX mixer widgets*/ 2256 SND_SOC_DAPM_MIXER("EAR_RDAC", SND_SO 2248 SND_SOC_DAPM_MIXER("EAR_RDAC", SND_SOC_NOPM, 0, 0, 2257 ear_rdac_switch, A 2249 ear_rdac_switch, ARRAY_SIZE(ear_rdac_switch)), 2258 SND_SOC_DAPM_MIXER("AUX_RDAC", SND_SO 2250 SND_SOC_DAPM_MIXER("AUX_RDAC", SND_SOC_NOPM, 0, 0, 2259 aux_rdac_switch, A 2251 aux_rdac_switch, ARRAY_SIZE(aux_rdac_switch)), 2260 SND_SOC_DAPM_MIXER("HPHL_RDAC", SND_S 2252 SND_SOC_DAPM_MIXER("HPHL_RDAC", SND_SOC_NOPM, 0, 0, 2261 hphl_rdac_switch, 2253 hphl_rdac_switch, ARRAY_SIZE(hphl_rdac_switch)), 2262 SND_SOC_DAPM_MIXER("HPHR_RDAC", SND_S 2254 SND_SOC_DAPM_MIXER("HPHR_RDAC", SND_SOC_NOPM, 0, 0, 2263 hphr_rdac_switch, 2255 hphr_rdac_switch, ARRAY_SIZE(hphr_rdac_switch)), 2264 2256 2265 /* TX output widgets */ 2257 /* TX output widgets */ 2266 SND_SOC_DAPM_OUTPUT("ADC1_OUTPUT"), 2258 SND_SOC_DAPM_OUTPUT("ADC1_OUTPUT"), 2267 SND_SOC_DAPM_OUTPUT("ADC2_OUTPUT"), 2259 SND_SOC_DAPM_OUTPUT("ADC2_OUTPUT"), 2268 SND_SOC_DAPM_OUTPUT("ADC3_OUTPUT"), 2260 SND_SOC_DAPM_OUTPUT("ADC3_OUTPUT"), 2269 SND_SOC_DAPM_OUTPUT("WCD_TX_OUTPUT"), 2261 SND_SOC_DAPM_OUTPUT("WCD_TX_OUTPUT"), 2270 2262 2271 /* RX output widgets */ 2263 /* RX output widgets */ 2272 SND_SOC_DAPM_OUTPUT("EAR"), 2264 SND_SOC_DAPM_OUTPUT("EAR"), 2273 SND_SOC_DAPM_OUTPUT("AUX"), 2265 SND_SOC_DAPM_OUTPUT("AUX"), 2274 SND_SOC_DAPM_OUTPUT("HPHL"), 2266 SND_SOC_DAPM_OUTPUT("HPHL"), 2275 SND_SOC_DAPM_OUTPUT("HPHR"), 2267 SND_SOC_DAPM_OUTPUT("HPHR"), 2276 2268 2277 /* MIC_BIAS pull up widgets */ 2269 /* MIC_BIAS pull up widgets */ 2278 SND_SOC_DAPM_SUPPLY("VA MIC BIAS1", S 2270 SND_SOC_DAPM_SUPPLY("VA MIC BIAS1", SND_SOC_NOPM, MIC_BIAS_1, 0, 2279 wcd937x_codec_ena 2271 wcd937x_codec_enable_micbias_pullup, 2280 SND_SOC_DAPM_PRE_ 2272 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2281 SND_SOC_DAPM_POST 2273 SND_SOC_DAPM_POST_PMD), 2282 SND_SOC_DAPM_SUPPLY("VA MIC BIAS2", S 2274 SND_SOC_DAPM_SUPPLY("VA MIC BIAS2", SND_SOC_NOPM, MIC_BIAS_2, 0, 2283 wcd937x_codec_ena 2275 wcd937x_codec_enable_micbias_pullup, 2284 SND_SOC_DAPM_PRE_ 2276 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2285 SND_SOC_DAPM_POST 2277 SND_SOC_DAPM_POST_PMD), 2286 SND_SOC_DAPM_SUPPLY("VA MIC BIAS3", S 2278 SND_SOC_DAPM_SUPPLY("VA MIC BIAS3", SND_SOC_NOPM, MIC_BIAS_3, 0, 2287 wcd937x_codec_ena 2279 wcd937x_codec_enable_micbias_pullup, 2288 SND_SOC_DAPM_PRE_ 2280 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | 2289 SND_SOC_DAPM_POST 2281 SND_SOC_DAPM_POST_PMD), 2290 }; 2282 }; 2291 2283 2292 static const struct snd_soc_dapm_widget wcd93 2284 static const struct snd_soc_dapm_widget wcd9375_dapm_widgets[] = { 2293 /* Input widgets */ 2285 /* Input widgets */ 2294 SND_SOC_DAPM_INPUT("AMIC4"), 2286 SND_SOC_DAPM_INPUT("AMIC4"), 2295 2287 2296 /* TX widgets */ 2288 /* TX widgets */ 2297 SND_SOC_DAPM_ADC_E("ADC3", NULL, SND_ 2289 SND_SOC_DAPM_ADC_E("ADC3", NULL, SND_SOC_NOPM, 2, 0, 2298 wcd937x_codec_enab 2290 wcd937x_codec_enable_adc, 2299 SND_SOC_DAPM_PRE_P 2291 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 2300 2292 2301 SND_SOC_DAPM_MIXER_E("ADC3 REQ", SND_ 2293 SND_SOC_DAPM_MIXER_E("ADC3 REQ", SND_SOC_NOPM, 0, 0, 2302 NULL, 0, wcd937x 2294 NULL, 0, wcd937x_enable_req, 2303 SND_SOC_DAPM_PRE 2295 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 2304 2296 2305 SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND 2297 SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0, 2306 wcd937x_codec_enab 2298 wcd937x_codec_enable_dmic, 2307 SND_SOC_DAPM_PRE_P 2299 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 2308 SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND 2300 SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 1, 0, 2309 wcd937x_codec_enab 2301 wcd937x_codec_enable_dmic, 2310 SND_SOC_DAPM_PRE_P 2302 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 2311 SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND 2303 SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 2, 0, 2312 wcd937x_codec_enab 2304 wcd937x_codec_enable_dmic, 2313 SND_SOC_DAPM_PRE_P 2305 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 2314 SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND 2306 SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 3, 0, 2315 wcd937x_codec_enab 2307 wcd937x_codec_enable_dmic, 2316 SND_SOC_DAPM_PRE_P 2308 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 2317 SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND 2309 SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 4, 0, 2318 wcd937x_codec_enab 2310 wcd937x_codec_enable_dmic, 2319 SND_SOC_DAPM_PRE_P 2311 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 2320 SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND 2312 SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 5, 0, 2321 wcd937x_codec_enab 2313 wcd937x_codec_enable_dmic, 2322 SND_SOC_DAPM_PRE_P 2314 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 2323 2315 2324 /* TX mixer widgets */ 2316 /* TX mixer widgets */ 2325 SND_SOC_DAPM_MIXER_E("DMIC1_MIXER", S 2317 SND_SOC_DAPM_MIXER_E("DMIC1_MIXER", SND_SOC_NOPM, 0, 2326 0, dmic1_switch, 2318 0, dmic1_switch, ARRAY_SIZE(dmic1_switch), 2327 wcd937x_tx_swr_c 2319 wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU | 2328 SND_SOC_DAPM_POS 2320 SND_SOC_DAPM_POST_PMD), 2329 SND_SOC_DAPM_MIXER_E("DMIC2_MIXER", S 2321 SND_SOC_DAPM_MIXER_E("DMIC2_MIXER", SND_SOC_NOPM, 1, 2330 0, dmic2_switch, 2322 0, dmic2_switch, ARRAY_SIZE(dmic2_switch), 2331 wcd937x_tx_swr_c 2323 wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU | 2332 SND_SOC_DAPM_POS 2324 SND_SOC_DAPM_POST_PMD), 2333 SND_SOC_DAPM_MIXER_E("DMIC3_MIXER", S 2325 SND_SOC_DAPM_MIXER_E("DMIC3_MIXER", SND_SOC_NOPM, 2, 2334 0, dmic3_switch, 2326 0, dmic3_switch, ARRAY_SIZE(dmic3_switch), 2335 wcd937x_tx_swr_c 2327 wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU | 2336 SND_SOC_DAPM_POS 2328 SND_SOC_DAPM_POST_PMD), 2337 SND_SOC_DAPM_MIXER_E("DMIC4_MIXER", S 2329 SND_SOC_DAPM_MIXER_E("DMIC4_MIXER", SND_SOC_NOPM, 3, 2338 0, dmic4_switch, 2330 0, dmic4_switch, ARRAY_SIZE(dmic4_switch), 2339 wcd937x_tx_swr_c 2331 wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU | 2340 SND_SOC_DAPM_POS 2332 SND_SOC_DAPM_POST_PMD), 2341 SND_SOC_DAPM_MIXER_E("DMIC5_MIXER", S 2333 SND_SOC_DAPM_MIXER_E("DMIC5_MIXER", SND_SOC_NOPM, 4, 2342 0, dmic5_switch, 2334 0, dmic5_switch, ARRAY_SIZE(dmic5_switch), 2343 wcd937x_tx_swr_c 2335 wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU | 2344 SND_SOC_DAPM_POS 2336 SND_SOC_DAPM_POST_PMD), 2345 SND_SOC_DAPM_MIXER_E("DMIC6_MIXER", S 2337 SND_SOC_DAPM_MIXER_E("DMIC6_MIXER", SND_SOC_NOPM, 5, 2346 0, dmic6_switch, 2338 0, dmic6_switch, ARRAY_SIZE(dmic6_switch), 2347 wcd937x_tx_swr_c 2339 wcd937x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU | 2348 SND_SOC_DAPM_POS 2340 SND_SOC_DAPM_POST_PMD), 2349 SND_SOC_DAPM_MIXER_E("ADC3_MIXER", SN 2341 SND_SOC_DAPM_MIXER_E("ADC3_MIXER", SND_SOC_NOPM, 2, 0, adc3_switch, 2350 ARRAY_SIZE(adc3_ 2342 ARRAY_SIZE(adc3_switch), wcd937x_tx_swr_ctrl, 2351 SND_SOC_DAPM_PRE 2343 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 2352 2344 2353 /* Output widgets */ 2345 /* Output widgets */ 2354 SND_SOC_DAPM_OUTPUT("DMIC1_OUTPUT"), 2346 SND_SOC_DAPM_OUTPUT("DMIC1_OUTPUT"), 2355 SND_SOC_DAPM_OUTPUT("DMIC2_OUTPUT"), 2347 SND_SOC_DAPM_OUTPUT("DMIC2_OUTPUT"), 2356 SND_SOC_DAPM_OUTPUT("DMIC3_OUTPUT"), 2348 SND_SOC_DAPM_OUTPUT("DMIC3_OUTPUT"), 2357 SND_SOC_DAPM_OUTPUT("DMIC4_OUTPUT"), 2349 SND_SOC_DAPM_OUTPUT("DMIC4_OUTPUT"), 2358 SND_SOC_DAPM_OUTPUT("DMIC5_OUTPUT"), 2350 SND_SOC_DAPM_OUTPUT("DMIC5_OUTPUT"), 2359 SND_SOC_DAPM_OUTPUT("DMIC6_OUTPUT"), 2351 SND_SOC_DAPM_OUTPUT("DMIC6_OUTPUT"), 2360 }; 2352 }; 2361 2353 2362 static const struct snd_soc_dapm_route wcd937 2354 static const struct snd_soc_dapm_route wcd937x_audio_map[] = { 2363 { "ADC1_OUTPUT", NULL, "ADC1_MIXER" } 2355 { "ADC1_OUTPUT", NULL, "ADC1_MIXER" }, 2364 { "ADC1_MIXER", "Switch", "ADC1 REQ" 2356 { "ADC1_MIXER", "Switch", "ADC1 REQ" }, 2365 { "ADC1 REQ", NULL, "ADC1" }, 2357 { "ADC1 REQ", NULL, "ADC1" }, 2366 { "ADC1", NULL, "AMIC1" }, 2358 { "ADC1", NULL, "AMIC1" }, 2367 2359 2368 { "ADC2_OUTPUT", NULL, "ADC2_MIXER" } 2360 { "ADC2_OUTPUT", NULL, "ADC2_MIXER" }, 2369 { "ADC2_MIXER", "Switch", "ADC2 REQ" 2361 { "ADC2_MIXER", "Switch", "ADC2 REQ" }, 2370 { "ADC2 REQ", NULL, "ADC2" }, 2362 { "ADC2 REQ", NULL, "ADC2" }, 2371 { "ADC2", NULL, "ADC2 MUX" }, 2363 { "ADC2", NULL, "ADC2 MUX" }, 2372 { "ADC2 MUX", "INP3", "AMIC3" }, 2364 { "ADC2 MUX", "INP3", "AMIC3" }, 2373 { "ADC2 MUX", "INP2", "AMIC2" }, 2365 { "ADC2 MUX", "INP2", "AMIC2" }, 2374 2366 2375 { "IN1_HPHL", NULL, "VDD_BUCK" }, 2367 { "IN1_HPHL", NULL, "VDD_BUCK" }, 2376 { "IN1_HPHL", NULL, "CLS_H_PORT" }, 2368 { "IN1_HPHL", NULL, "CLS_H_PORT" }, 2377 { "RX1", NULL, "IN1_HPHL" }, 2369 { "RX1", NULL, "IN1_HPHL" }, 2378 { "RDAC1", NULL, "RX1" }, 2370 { "RDAC1", NULL, "RX1" }, 2379 { "HPHL_RDAC", "Switch", "RDAC1" }, 2371 { "HPHL_RDAC", "Switch", "RDAC1" }, 2380 { "HPHL PGA", NULL, "HPHL_RDAC" }, 2372 { "HPHL PGA", NULL, "HPHL_RDAC" }, 2381 { "HPHL", NULL, "HPHL PGA" }, 2373 { "HPHL", NULL, "HPHL PGA" }, 2382 2374 2383 { "IN2_HPHR", NULL, "VDD_BUCK" }, 2375 { "IN2_HPHR", NULL, "VDD_BUCK" }, 2384 { "IN2_HPHR", NULL, "CLS_H_PORT" }, 2376 { "IN2_HPHR", NULL, "CLS_H_PORT" }, 2385 { "RX2", NULL, "IN2_HPHR" }, 2377 { "RX2", NULL, "IN2_HPHR" }, 2386 { "RDAC2", NULL, "RX2" }, 2378 { "RDAC2", NULL, "RX2" }, 2387 { "HPHR_RDAC", "Switch", "RDAC2" }, 2379 { "HPHR_RDAC", "Switch", "RDAC2" }, 2388 { "HPHR PGA", NULL, "HPHR_RDAC" }, 2380 { "HPHR PGA", NULL, "HPHR_RDAC" }, 2389 { "HPHR", NULL, "HPHR PGA" }, 2381 { "HPHR", NULL, "HPHR PGA" }, 2390 2382 2391 { "IN3_AUX", NULL, "VDD_BUCK" }, 2383 { "IN3_AUX", NULL, "VDD_BUCK" }, 2392 { "IN3_AUX", NULL, "CLS_H_PORT" }, 2384 { "IN3_AUX", NULL, "CLS_H_PORT" }, 2393 { "RX3", NULL, "IN3_AUX" }, 2385 { "RX3", NULL, "IN3_AUX" }, 2394 { "RDAC4", NULL, "RX3" }, 2386 { "RDAC4", NULL, "RX3" }, 2395 { "AUX_RDAC", "Switch", "RDAC4" }, 2387 { "AUX_RDAC", "Switch", "RDAC4" }, 2396 { "AUX PGA", NULL, "AUX_RDAC" }, 2388 { "AUX PGA", NULL, "AUX_RDAC" }, 2397 { "AUX", NULL, "AUX PGA" }, 2389 { "AUX", NULL, "AUX PGA" }, 2398 2390 2399 { "RDAC3_MUX", "RX3", "RX3" }, 2391 { "RDAC3_MUX", "RX3", "RX3" }, 2400 { "RDAC3_MUX", "RX1", "RX1" }, 2392 { "RDAC3_MUX", "RX1", "RX1" }, 2401 { "RDAC3", NULL, "RDAC3_MUX" }, 2393 { "RDAC3", NULL, "RDAC3_MUX" }, 2402 { "EAR_RDAC", "Switch", "RDAC3" }, 2394 { "EAR_RDAC", "Switch", "RDAC3" }, 2403 { "EAR PGA", NULL, "EAR_RDAC" }, 2395 { "EAR PGA", NULL, "EAR_RDAC" }, 2404 { "EAR", NULL, "EAR PGA" }, 2396 { "EAR", NULL, "EAR PGA" }, 2405 }; 2397 }; 2406 2398 2407 static const struct snd_soc_dapm_route wcd937 2399 static const struct snd_soc_dapm_route wcd9375_audio_map[] = { 2408 { "ADC3_OUTPUT", NULL, "ADC3_MIXER" } 2400 { "ADC3_OUTPUT", NULL, "ADC3_MIXER" }, 2409 { "ADC3_OUTPUT", NULL, "ADC3_MIXER" } 2401 { "ADC3_OUTPUT", NULL, "ADC3_MIXER" }, 2410 { "ADC3_MIXER", "Switch", "ADC3 REQ" 2402 { "ADC3_MIXER", "Switch", "ADC3 REQ" }, 2411 { "ADC3 REQ", NULL, "ADC3" }, 2403 { "ADC3 REQ", NULL, "ADC3" }, 2412 { "ADC3", NULL, "AMIC4" }, 2404 { "ADC3", NULL, "AMIC4" }, 2413 2405 2414 { "DMIC1_OUTPUT", NULL, "DMIC1_MIXER" 2406 { "DMIC1_OUTPUT", NULL, "DMIC1_MIXER" }, 2415 { "DMIC1_MIXER", "Switch", "DMIC1" }, 2407 { "DMIC1_MIXER", "Switch", "DMIC1" }, 2416 2408 2417 { "DMIC2_OUTPUT", NULL, "DMIC2_MIXER" 2409 { "DMIC2_OUTPUT", NULL, "DMIC2_MIXER" }, 2418 { "DMIC2_MIXER", "Switch", "DMIC2" }, 2410 { "DMIC2_MIXER", "Switch", "DMIC2" }, 2419 2411 2420 { "DMIC3_OUTPUT", NULL, "DMIC3_MIXER" 2412 { "DMIC3_OUTPUT", NULL, "DMIC3_MIXER" }, 2421 { "DMIC3_MIXER", "Switch", "DMIC3" }, 2413 { "DMIC3_MIXER", "Switch", "DMIC3" }, 2422 2414 2423 { "DMIC4_OUTPUT", NULL, "DMIC4_MIXER" 2415 { "DMIC4_OUTPUT", NULL, "DMIC4_MIXER" }, 2424 { "DMIC4_MIXER", "Switch", "DMIC4" }, 2416 { "DMIC4_MIXER", "Switch", "DMIC4" }, 2425 2417 2426 { "DMIC5_OUTPUT", NULL, "DMIC5_MIXER" 2418 { "DMIC5_OUTPUT", NULL, "DMIC5_MIXER" }, 2427 { "DMIC5_MIXER", "Switch", "DMIC5" }, 2419 { "DMIC5_MIXER", "Switch", "DMIC5" }, 2428 2420 2429 { "DMIC6_OUTPUT", NULL, "DMIC6_MIXER" 2421 { "DMIC6_OUTPUT", NULL, "DMIC6_MIXER" }, 2430 { "DMIC6_MIXER", "Switch", "DMIC6" }, 2422 { "DMIC6_MIXER", "Switch", "DMIC6" }, 2431 }; 2423 }; 2432 2424 2433 static int wcd937x_set_micbias_data(struct wc 2425 static int wcd937x_set_micbias_data(struct wcd937x_priv *wcd937x) 2434 { 2426 { 2435 int vout_ctl[3]; 2427 int vout_ctl[3]; 2436 2428 2437 /* Set micbias voltage */ 2429 /* Set micbias voltage */ 2438 vout_ctl[0] = wcd937x_get_micb_vout_c 2430 vout_ctl[0] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb1_mv); 2439 vout_ctl[1] = wcd937x_get_micb_vout_c 2431 vout_ctl[1] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb2_mv); 2440 vout_ctl[2] = wcd937x_get_micb_vout_c 2432 vout_ctl[2] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb3_mv); 2441 if ((vout_ctl[0] | vout_ctl[1] | vout 2433 if ((vout_ctl[0] | vout_ctl[1] | vout_ctl[2]) < 0) 2442 return -EINVAL; 2434 return -EINVAL; 2443 2435 2444 regmap_update_bits(wcd937x->regmap, W 2436 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB1, WCD937X_ANA_MICB_VOUT, vout_ctl[0]); 2445 regmap_update_bits(wcd937x->regmap, W 2437 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB2, WCD937X_ANA_MICB_VOUT, vout_ctl[1]); 2446 regmap_update_bits(wcd937x->regmap, W 2438 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB3, WCD937X_ANA_MICB_VOUT, vout_ctl[2]); 2447 2439 2448 return 0; 2440 return 0; 2449 } 2441 } 2450 2442 2451 static irqreturn_t wcd937x_wd_handle_irq(int 2443 static irqreturn_t wcd937x_wd_handle_irq(int irq, void *data) 2452 { 2444 { 2453 return IRQ_HANDLED; 2445 return IRQ_HANDLED; 2454 } 2446 } 2455 2447 2456 static const struct irq_chip wcd_irq_chip = { 2448 static const struct irq_chip wcd_irq_chip = { 2457 .name = "WCD937x", 2449 .name = "WCD937x", 2458 }; 2450 }; 2459 2451 2460 static int wcd_irq_chip_map(struct irq_domain 2452 static int wcd_irq_chip_map(struct irq_domain *irqd, unsigned int virq, 2461 irq_hw_number_t h 2453 irq_hw_number_t hw) 2462 { 2454 { 2463 irq_set_chip_and_handler(virq, &wcd_i 2455 irq_set_chip_and_handler(virq, &wcd_irq_chip, handle_simple_irq); 2464 irq_set_nested_thread(virq, 1); 2456 irq_set_nested_thread(virq, 1); 2465 irq_set_noprobe(virq); 2457 irq_set_noprobe(virq); 2466 2458 2467 return 0; 2459 return 0; 2468 } 2460 } 2469 2461 2470 static const struct irq_domain_ops wcd_domain 2462 static const struct irq_domain_ops wcd_domain_ops = { 2471 .map = wcd_irq_chip_map, 2463 .map = wcd_irq_chip_map, 2472 }; 2464 }; 2473 2465 2474 static int wcd937x_irq_init(struct wcd937x_pr 2466 static int wcd937x_irq_init(struct wcd937x_priv *wcd, struct device *dev) 2475 { 2467 { 2476 wcd->virq = irq_domain_add_linear(NUL 2468 wcd->virq = irq_domain_add_linear(NULL, 1, &wcd_domain_ops, NULL); 2477 if (!(wcd->virq)) { 2469 if (!(wcd->virq)) { 2478 dev_err(dev, "%s: Failed to a 2470 dev_err(dev, "%s: Failed to add IRQ domain\n", __func__); 2479 return -EINVAL; 2471 return -EINVAL; 2480 } 2472 } 2481 2473 2482 return devm_regmap_add_irq_chip(dev, 2474 return devm_regmap_add_irq_chip(dev, wcd->regmap, 2483 irq_c 2475 irq_create_mapping(wcd->virq, 0), 2484 IRQF_ 2476 IRQF_ONESHOT, 0, &wcd937x_regmap_irq_chip, 2485 &wcd- 2477 &wcd->irq_chip); 2486 } 2478 } 2487 2479 2488 static int wcd937x_soc_codec_probe(struct snd 2480 static int wcd937x_soc_codec_probe(struct snd_soc_component *component) 2489 { 2481 { 2490 struct snd_soc_dapm_context *dapm = s 2482 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); 2491 struct wcd937x_priv *wcd937x = snd_so 2483 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 2492 struct sdw_slave *tx_sdw_dev = wcd937 2484 struct sdw_slave *tx_sdw_dev = wcd937x->tx_sdw_dev; 2493 struct device *dev = component->dev; 2485 struct device *dev = component->dev; 2494 unsigned long time_left; 2486 unsigned long time_left; 2495 int i, ret; 2487 int i, ret; 2496 u32 chipid; 2488 u32 chipid; 2497 2489 2498 time_left = wait_for_completion_timeo 2490 time_left = wait_for_completion_timeout(&tx_sdw_dev->initialization_complete, 2499 2491 msecs_to_jiffies(5000)); 2500 if (!time_left) { 2492 if (!time_left) { 2501 dev_err(dev, "soundwire devic 2493 dev_err(dev, "soundwire device init timeout\n"); 2502 return -ETIMEDOUT; 2494 return -ETIMEDOUT; 2503 } 2495 } 2504 2496 2505 snd_soc_component_init_regmap(compone 2497 snd_soc_component_init_regmap(component, wcd937x->regmap); 2506 ret = pm_runtime_resume_and_get(dev); 2498 ret = pm_runtime_resume_and_get(dev); 2507 if (ret < 0) 2499 if (ret < 0) 2508 return ret; 2500 return ret; 2509 2501 2510 chipid = (snd_soc_component_read(comp 2502 chipid = (snd_soc_component_read(component, 2511 WCD9 2503 WCD937X_DIGITAL_EFUSE_REG_0) & 0x1e) >> 1; 2512 if (chipid != CHIPID_WCD9370 && chipi 2504 if (chipid != CHIPID_WCD9370 && chipid != CHIPID_WCD9375) { 2513 dev_err(dev, "Got unknown chi 2505 dev_err(dev, "Got unknown chip id: 0x%x\n", chipid); 2514 pm_runtime_put(dev); 2506 pm_runtime_put(dev); 2515 return -EINVAL; 2507 return -EINVAL; 2516 } 2508 } 2517 2509 2518 wcd937x->clsh_info = wcd_clsh_ctrl_al 2510 wcd937x->clsh_info = wcd_clsh_ctrl_alloc(component, WCD937X); 2519 if (IS_ERR(wcd937x->clsh_info)) { 2511 if (IS_ERR(wcd937x->clsh_info)) { 2520 pm_runtime_put(dev); 2512 pm_runtime_put(dev); 2521 return PTR_ERR(wcd937x->clsh_ 2513 return PTR_ERR(wcd937x->clsh_info); 2522 } 2514 } 2523 2515 2524 wcd937x_io_init(wcd937x->regmap); 2516 wcd937x_io_init(wcd937x->regmap); 2525 /* Set all interrupts as edge trigger 2517 /* Set all interrupts as edge triggered */ 2526 for (i = 0; i < wcd937x_regmap_irq_ch 2518 for (i = 0; i < wcd937x_regmap_irq_chip.num_regs; i++) 2527 regmap_write(wcd937x->regmap, 2519 regmap_write(wcd937x->regmap, (WCD937X_DIGITAL_INTR_LEVEL_0 + i), 0); 2528 2520 2529 pm_runtime_put(dev); 2521 pm_runtime_put(dev); 2530 2522 2531 wcd937x->hphr_pdm_wd_int = regmap_irq 2523 wcd937x->hphr_pdm_wd_int = regmap_irq_get_virq(wcd937x->irq_chip, 2532 2524 WCD937X_IRQ_HPHR_PDM_WD_INT); 2533 wcd937x->hphl_pdm_wd_int = regmap_irq 2525 wcd937x->hphl_pdm_wd_int = regmap_irq_get_virq(wcd937x->irq_chip, 2534 2526 WCD937X_IRQ_HPHL_PDM_WD_INT); 2535 wcd937x->aux_pdm_wd_int = regmap_irq_ 2527 wcd937x->aux_pdm_wd_int = regmap_irq_get_virq(wcd937x->irq_chip, 2536 2528 WCD937X_IRQ_AUX_PDM_WD_INT); 2537 2529 2538 /* Request for watchdog interrupt */ 2530 /* Request for watchdog interrupt */ 2539 ret = devm_request_threaded_irq(dev, 2531 ret = devm_request_threaded_irq(dev, wcd937x->hphr_pdm_wd_int, NULL, wcd937x_wd_handle_irq, 2540 IRQF_ 2532 IRQF_ONESHOT | IRQF_TRIGGER_RISING, 2541 "HPHR 2533 "HPHR PDM WDOG INT", wcd937x); 2542 if (ret) 2534 if (ret) 2543 dev_err(dev, "Failed to reque 2535 dev_err(dev, "Failed to request HPHR watchdog interrupt (%d)\n", ret); 2544 2536 2545 ret = devm_request_threaded_irq(dev, 2537 ret = devm_request_threaded_irq(dev, wcd937x->hphl_pdm_wd_int, NULL, wcd937x_wd_handle_irq, 2546 IRQF_ 2538 IRQF_ONESHOT | IRQF_TRIGGER_RISING, 2547 "HPHL 2539 "HPHL PDM WDOG INT", wcd937x); 2548 if (ret) 2540 if (ret) 2549 dev_err(dev, "Failed to reque 2541 dev_err(dev, "Failed to request HPHL watchdog interrupt (%d)\n", ret); 2550 2542 2551 ret = devm_request_threaded_irq(dev, 2543 ret = devm_request_threaded_irq(dev, wcd937x->aux_pdm_wd_int, NULL, wcd937x_wd_handle_irq, 2552 IRQF_ 2544 IRQF_ONESHOT | IRQF_TRIGGER_RISING, 2553 "AUX 2545 "AUX PDM WDOG INT", wcd937x); 2554 if (ret) 2546 if (ret) 2555 dev_err(dev, "Failed to reque 2547 dev_err(dev, "Failed to request Aux watchdog interrupt (%d)\n", ret); 2556 2548 2557 /* Disable watchdog interrupt for HPH 2549 /* Disable watchdog interrupt for HPH and AUX */ 2558 disable_irq_nosync(wcd937x->hphr_pdm_ 2550 disable_irq_nosync(wcd937x->hphr_pdm_wd_int); 2559 disable_irq_nosync(wcd937x->hphl_pdm_ 2551 disable_irq_nosync(wcd937x->hphl_pdm_wd_int); 2560 disable_irq_nosync(wcd937x->aux_pdm_w 2552 disable_irq_nosync(wcd937x->aux_pdm_wd_int); 2561 2553 2562 if (chipid == CHIPID_WCD9375) { 2554 if (chipid == CHIPID_WCD9375) { 2563 ret = snd_soc_dapm_new_contro 2555 ret = snd_soc_dapm_new_controls(dapm, wcd9375_dapm_widgets, 2564 2556 ARRAY_SIZE(wcd9375_dapm_widgets)); 2565 if (ret < 0) { 2557 if (ret < 0) { 2566 dev_err(component->de 2558 dev_err(component->dev, "Failed to add snd_ctls\n"); 2567 return ret; 2559 return ret; 2568 } 2560 } 2569 2561 2570 ret = snd_soc_dapm_add_routes 2562 ret = snd_soc_dapm_add_routes(dapm, wcd9375_audio_map, 2571 2563 ARRAY_SIZE(wcd9375_audio_map)); 2572 if (ret < 0) { 2564 if (ret < 0) { 2573 dev_err(component->de 2565 dev_err(component->dev, "Failed to add routes\n"); 2574 return ret; 2566 return ret; 2575 } 2567 } 2576 } 2568 } 2577 2569 2578 ret = wcd937x_mbhc_init(component); 2570 ret = wcd937x_mbhc_init(component); 2579 if (ret) 2571 if (ret) 2580 dev_err(component->dev, "mbhc 2572 dev_err(component->dev, "mbhc initialization failed\n"); 2581 2573 2582 return ret; 2574 return ret; 2583 } 2575 } 2584 2576 2585 static void wcd937x_soc_codec_remove(struct s 2577 static void wcd937x_soc_codec_remove(struct snd_soc_component *component) 2586 { 2578 { 2587 struct wcd937x_priv *wcd937x = snd_so 2579 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component); 2588 2580 2589 wcd937x_mbhc_deinit(component); 2581 wcd937x_mbhc_deinit(component); 2590 free_irq(wcd937x->aux_pdm_wd_int, wcd 2582 free_irq(wcd937x->aux_pdm_wd_int, wcd937x); 2591 free_irq(wcd937x->hphl_pdm_wd_int, wc 2583 free_irq(wcd937x->hphl_pdm_wd_int, wcd937x); 2592 free_irq(wcd937x->hphr_pdm_wd_int, wc 2584 free_irq(wcd937x->hphr_pdm_wd_int, wcd937x); 2593 2585 2594 wcd_clsh_ctrl_free(wcd937x->clsh_info 2586 wcd_clsh_ctrl_free(wcd937x->clsh_info); 2595 } 2587 } 2596 2588 2597 static int wcd937x_codec_set_jack(struct snd_ 2589 static int wcd937x_codec_set_jack(struct snd_soc_component *comp, 2598 struct snd_ 2590 struct snd_soc_jack *jack, void *data) 2599 { 2591 { 2600 struct wcd937x_priv *wcd = dev_get_dr 2592 struct wcd937x_priv *wcd = dev_get_drvdata(comp->dev); 2601 int ret = 0; 2593 int ret = 0; 2602 2594 2603 if (jack) 2595 if (jack) 2604 ret = wcd_mbhc_start(wcd->wcd 2596 ret = wcd_mbhc_start(wcd->wcd_mbhc, &wcd->mbhc_cfg, jack); 2605 else 2597 else 2606 wcd_mbhc_stop(wcd->wcd_mbhc); 2598 wcd_mbhc_stop(wcd->wcd_mbhc); 2607 2599 2608 return ret; 2600 return ret; 2609 } 2601 } 2610 2602 2611 static const struct snd_soc_component_driver 2603 static const struct snd_soc_component_driver soc_codec_dev_wcd937x = { 2612 .name = "wcd937x_codec", 2604 .name = "wcd937x_codec", 2613 .probe = wcd937x_soc_codec_probe, 2605 .probe = wcd937x_soc_codec_probe, 2614 .remove = wcd937x_soc_codec_remove, 2606 .remove = wcd937x_soc_codec_remove, 2615 .controls = wcd937x_snd_controls, 2607 .controls = wcd937x_snd_controls, 2616 .num_controls = ARRAY_SIZE(wcd937x_sn 2608 .num_controls = ARRAY_SIZE(wcd937x_snd_controls), 2617 .dapm_widgets = wcd937x_dapm_widgets, 2609 .dapm_widgets = wcd937x_dapm_widgets, 2618 .num_dapm_widgets = ARRAY_SIZE(wcd937 2610 .num_dapm_widgets = ARRAY_SIZE(wcd937x_dapm_widgets), 2619 .dapm_routes = wcd937x_audio_map, 2611 .dapm_routes = wcd937x_audio_map, 2620 .num_dapm_routes = ARRAY_SIZE(wcd937x 2612 .num_dapm_routes = ARRAY_SIZE(wcd937x_audio_map), 2621 .set_jack = wcd937x_codec_set_jack, 2613 .set_jack = wcd937x_codec_set_jack, 2622 .endianness = 1, 2614 .endianness = 1, 2623 }; 2615 }; 2624 2616 2625 static void wcd937x_dt_parse_micbias_info(str 2617 static void wcd937x_dt_parse_micbias_info(struct device *dev, struct wcd937x_priv *wcd) 2626 { 2618 { 2627 struct device_node *np = dev->of_node 2619 struct device_node *np = dev->of_node; 2628 u32 prop_val = 0; 2620 u32 prop_val = 0; 2629 int ret = 0; 2621 int ret = 0; 2630 2622 2631 ret = of_property_read_u32(np, "qcom, 2623 ret = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val); 2632 if (!ret) 2624 if (!ret) 2633 wcd->micb1_mv = prop_val / 10 2625 wcd->micb1_mv = prop_val / 1000; 2634 else 2626 else 2635 dev_warn(dev, "Micbias1 DT pr 2627 dev_warn(dev, "Micbias1 DT property not found\n"); 2636 2628 2637 ret = of_property_read_u32(np, "qcom, 2629 ret = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val); 2638 if (!ret) 2630 if (!ret) 2639 wcd->micb2_mv = prop_val / 10 2631 wcd->micb2_mv = prop_val / 1000; 2640 else 2632 else 2641 dev_warn(dev, "Micbias2 DT pr 2633 dev_warn(dev, "Micbias2 DT property not found\n"); 2642 2634 2643 ret = of_property_read_u32(np, "qcom, 2635 ret = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val); 2644 if (!ret) 2636 if (!ret) 2645 wcd->micb3_mv = prop_val / 10 2637 wcd->micb3_mv = prop_val / 1000; 2646 else 2638 else 2647 dev_warn(dev, "Micbias3 DT pr 2639 dev_warn(dev, "Micbias3 DT property not found\n"); 2648 } 2640 } 2649 2641 2650 static bool wcd937x_swap_gnd_mic(struct snd_s 2642 static bool wcd937x_swap_gnd_mic(struct snd_soc_component *component, bool active) 2651 { 2643 { 2652 int value; 2644 int value; 2653 struct wcd937x_priv *wcd937x; 2645 struct wcd937x_priv *wcd937x; 2654 2646 2655 wcd937x = snd_soc_component_get_drvda 2647 wcd937x = snd_soc_component_get_drvdata(component); 2656 2648 2657 value = gpiod_get_value(wcd937x->us_e 2649 value = gpiod_get_value(wcd937x->us_euro_gpio); 2658 gpiod_set_value(wcd937x->us_euro_gpio 2650 gpiod_set_value(wcd937x->us_euro_gpio, !value); 2659 2651 2660 return true; 2652 return true; 2661 } 2653 } 2662 2654 2663 static int wcd937x_codec_hw_params(struct snd 2655 static int wcd937x_codec_hw_params(struct snd_pcm_substream *substream, 2664 struct snd 2656 struct snd_pcm_hw_params *params, 2665 struct snd 2657 struct snd_soc_dai *dai) 2666 { 2658 { 2667 struct wcd937x_priv *wcd937x = dev_ge 2659 struct wcd937x_priv *wcd937x = dev_get_drvdata(dai->dev); 2668 struct wcd937x_sdw_priv *wcd = wcd937 2660 struct wcd937x_sdw_priv *wcd = wcd937x->sdw_priv[dai->id]; 2669 2661 2670 return wcd937x_sdw_hw_params(wcd, sub 2662 return wcd937x_sdw_hw_params(wcd, substream, params, dai); 2671 } 2663 } 2672 2664 2673 static int wcd937x_codec_free(struct snd_pcm_ 2665 static int wcd937x_codec_free(struct snd_pcm_substream *substream, 2674 struct snd_soc_ 2666 struct snd_soc_dai *dai) 2675 { 2667 { 2676 struct wcd937x_priv *wcd937x = dev_ge 2668 struct wcd937x_priv *wcd937x = dev_get_drvdata(dai->dev); 2677 struct wcd937x_sdw_priv *wcd = wcd937 2669 struct wcd937x_sdw_priv *wcd = wcd937x->sdw_priv[dai->id]; 2678 2670 2679 return sdw_stream_remove_slave(wcd->s 2671 return sdw_stream_remove_slave(wcd->sdev, wcd->sruntime); 2680 } 2672 } 2681 2673 2682 static int wcd937x_codec_set_sdw_stream(struc 2674 static int wcd937x_codec_set_sdw_stream(struct snd_soc_dai *dai, 2683 void 2675 void *stream, int direction) 2684 { 2676 { 2685 struct wcd937x_priv *wcd937x = dev_ge 2677 struct wcd937x_priv *wcd937x = dev_get_drvdata(dai->dev); 2686 struct wcd937x_sdw_priv *wcd = wcd937 2678 struct wcd937x_sdw_priv *wcd = wcd937x->sdw_priv[dai->id]; 2687 2679 2688 wcd->sruntime = stream; 2680 wcd->sruntime = stream; 2689 2681 2690 return 0; 2682 return 0; 2691 } 2683 } 2692 2684 2693 static const struct snd_soc_dai_ops wcd937x_s 2685 static const struct snd_soc_dai_ops wcd937x_sdw_dai_ops = { 2694 .hw_params = wcd937x_codec_hw_params, 2686 .hw_params = wcd937x_codec_hw_params, 2695 .hw_free = wcd937x_codec_free, 2687 .hw_free = wcd937x_codec_free, 2696 .set_stream = wcd937x_codec_set_sdw_s 2688 .set_stream = wcd937x_codec_set_sdw_stream, 2697 }; 2689 }; 2698 2690 2699 static struct snd_soc_dai_driver wcd937x_dais 2691 static struct snd_soc_dai_driver wcd937x_dais[] = { 2700 [0] = { 2692 [0] = { 2701 .name = "wcd937x-sdw-rx", 2693 .name = "wcd937x-sdw-rx", 2702 .playback = { 2694 .playback = { 2703 .stream_name = "WCD A 2695 .stream_name = "WCD AIF Playback", 2704 .rates = WCD937X_RATE 2696 .rates = WCD937X_RATES | WCD937X_FRAC_RATES, 2705 .formats = WCD937X_FO 2697 .formats = WCD937X_FORMATS, 2706 .rate_min = 8000, 2698 .rate_min = 8000, 2707 .rate_max = 384000, 2699 .rate_max = 384000, 2708 .channels_min = 1, 2700 .channels_min = 1, 2709 .channels_max = 4, 2701 .channels_max = 4, 2710 }, 2702 }, 2711 .ops = &wcd937x_sdw_dai_ops, 2703 .ops = &wcd937x_sdw_dai_ops, 2712 }, 2704 }, 2713 [1] = { 2705 [1] = { 2714 .name = "wcd937x-sdw-tx", 2706 .name = "wcd937x-sdw-tx", 2715 .capture = { 2707 .capture = { 2716 .stream_name = "WCD A 2708 .stream_name = "WCD AIF Capture", 2717 .rates = WCD937X_RATE 2709 .rates = WCD937X_RATES, 2718 .formats = WCD937X_FO 2710 .formats = WCD937X_FORMATS, 2719 .rate_min = 8000, 2711 .rate_min = 8000, 2720 .rate_max = 192000, 2712 .rate_max = 192000, 2721 .channels_min = 1, 2713 .channels_min = 1, 2722 .channels_max = 4, 2714 .channels_max = 4, 2723 }, 2715 }, 2724 .ops = &wcd937x_sdw_dai_ops, 2716 .ops = &wcd937x_sdw_dai_ops, 2725 }, 2717 }, 2726 }; 2718 }; 2727 2719 2728 static int wcd937x_bind(struct device *dev) 2720 static int wcd937x_bind(struct device *dev) 2729 { 2721 { 2730 struct wcd937x_priv *wcd937x = dev_ge 2722 struct wcd937x_priv *wcd937x = dev_get_drvdata(dev); 2731 int ret; 2723 int ret; 2732 2724 2733 /* Give the SDW subdevices some more 2725 /* Give the SDW subdevices some more time to settle */ 2734 usleep_range(5000, 5010); 2726 usleep_range(5000, 5010); 2735 2727 2736 ret = component_bind_all(dev, wcd937x 2728 ret = component_bind_all(dev, wcd937x); 2737 if (ret) { 2729 if (ret) { 2738 dev_err(dev, "Slave bind fail 2730 dev_err(dev, "Slave bind failed, ret = %d\n", ret); 2739 return ret; 2731 return ret; 2740 } 2732 } 2741 2733 2742 wcd937x->rxdev = wcd937x_sdw_device_g 2734 wcd937x->rxdev = wcd937x_sdw_device_get(wcd937x->rxnode); 2743 if (!wcd937x->rxdev) { 2735 if (!wcd937x->rxdev) { 2744 dev_err(dev, "could not find 2736 dev_err(dev, "could not find slave with matching of node\n"); 2745 return -EINVAL; 2737 return -EINVAL; 2746 } 2738 } 2747 2739 2748 wcd937x->sdw_priv[AIF1_PB] = dev_get_ 2740 wcd937x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd937x->rxdev); 2749 wcd937x->sdw_priv[AIF1_PB]->wcd937x = 2741 wcd937x->sdw_priv[AIF1_PB]->wcd937x = wcd937x; 2750 2742 2751 wcd937x->txdev = wcd937x_sdw_device_g 2743 wcd937x->txdev = wcd937x_sdw_device_get(wcd937x->txnode); 2752 if (!wcd937x->txdev) { 2744 if (!wcd937x->txdev) { 2753 dev_err(dev, "could not find 2745 dev_err(dev, "could not find txslave with matching of node\n"); 2754 return -EINVAL; 2746 return -EINVAL; 2755 } 2747 } 2756 2748 2757 wcd937x->sdw_priv[AIF1_CAP] = dev_get 2749 wcd937x->sdw_priv[AIF1_CAP] = dev_get_drvdata(wcd937x->txdev); 2758 wcd937x->sdw_priv[AIF1_CAP]->wcd937x 2750 wcd937x->sdw_priv[AIF1_CAP]->wcd937x = wcd937x; 2759 wcd937x->tx_sdw_dev = dev_to_sdw_dev( 2751 wcd937x->tx_sdw_dev = dev_to_sdw_dev(wcd937x->txdev); 2760 if (!wcd937x->tx_sdw_dev) { 2752 if (!wcd937x->tx_sdw_dev) { 2761 dev_err(dev, "could not get t 2753 dev_err(dev, "could not get txslave with matching of dev\n"); 2762 return -EINVAL; 2754 return -EINVAL; 2763 } 2755 } 2764 2756 2765 /* 2757 /* 2766 * As TX is the main CSR reg interfac 2758 * As TX is the main CSR reg interface, which should not be suspended first. 2767 * expicilty add the dependency link 2759 * expicilty add the dependency link 2768 */ 2760 */ 2769 if (!device_link_add(wcd937x->rxdev, 2761 if (!device_link_add(wcd937x->rxdev, wcd937x->txdev, 2770 DL_FLAG_STATELES 2762 DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME)) { 2771 dev_err(dev, "Could not devli 2763 dev_err(dev, "Could not devlink TX and RX\n"); 2772 return -EINVAL; 2764 return -EINVAL; 2773 } 2765 } 2774 2766 2775 if (!device_link_add(dev, wcd937x->tx 2767 if (!device_link_add(dev, wcd937x->txdev, 2776 DL_FLAG_STATELES 2768 DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME)) { 2777 dev_err(dev, "Could not devli 2769 dev_err(dev, "Could not devlink WCD and TX\n"); 2778 return -EINVAL; 2770 return -EINVAL; 2779 } 2771 } 2780 2772 2781 if (!device_link_add(dev, wcd937x->rx 2773 if (!device_link_add(dev, wcd937x->rxdev, 2782 DL_FLAG_STATELES 2774 DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME)) { 2783 dev_err(dev, "Could not devli 2775 dev_err(dev, "Could not devlink WCD and RX\n"); 2784 return -EINVAL; 2776 return -EINVAL; 2785 } 2777 } 2786 2778 2787 wcd937x->regmap = dev_get_regmap(&wcd 2779 wcd937x->regmap = dev_get_regmap(&wcd937x->tx_sdw_dev->dev, NULL); 2788 if (!wcd937x->regmap) { 2780 if (!wcd937x->regmap) { 2789 dev_err(dev, "could not get T 2781 dev_err(dev, "could not get TX device regmap\n"); 2790 return -EINVAL; 2782 return -EINVAL; 2791 } 2783 } 2792 2784 2793 ret = wcd937x_irq_init(wcd937x, dev); 2785 ret = wcd937x_irq_init(wcd937x, dev); 2794 if (ret) { 2786 if (ret) { 2795 dev_err(dev, "IRQ init failed 2787 dev_err(dev, "IRQ init failed: %d\n", ret); 2796 return ret; 2788 return ret; 2797 } 2789 } 2798 2790 2799 wcd937x->sdw_priv[AIF1_PB]->slave_irq 2791 wcd937x->sdw_priv[AIF1_PB]->slave_irq = wcd937x->virq; 2800 wcd937x->sdw_priv[AIF1_CAP]->slave_ir 2792 wcd937x->sdw_priv[AIF1_CAP]->slave_irq = wcd937x->virq; 2801 2793 2802 ret = wcd937x_set_micbias_data(wcd937 2794 ret = wcd937x_set_micbias_data(wcd937x); 2803 if (ret < 0) { 2795 if (ret < 0) { 2804 dev_err(dev, "Bad micbias pda 2796 dev_err(dev, "Bad micbias pdata\n"); 2805 return ret; 2797 return ret; 2806 } 2798 } 2807 2799 2808 ret = snd_soc_register_component(dev, 2800 ret = snd_soc_register_component(dev, &soc_codec_dev_wcd937x, 2809 wcd9 2801 wcd937x_dais, ARRAY_SIZE(wcd937x_dais)); 2810 if (ret) 2802 if (ret) 2811 dev_err(dev, "Codec registrat 2803 dev_err(dev, "Codec registration failed\n"); 2812 2804 2813 return ret; 2805 return ret; 2814 } 2806 } 2815 2807 2816 static void wcd937x_unbind(struct device *dev 2808 static void wcd937x_unbind(struct device *dev) 2817 { 2809 { 2818 struct wcd937x_priv *wcd937x = dev_ge 2810 struct wcd937x_priv *wcd937x = dev_get_drvdata(dev); 2819 2811 2820 snd_soc_unregister_component(dev); 2812 snd_soc_unregister_component(dev); 2821 device_link_remove(dev, wcd937x->txde 2813 device_link_remove(dev, wcd937x->txdev); 2822 device_link_remove(dev, wcd937x->rxde 2814 device_link_remove(dev, wcd937x->rxdev); 2823 device_link_remove(wcd937x->rxdev, wc 2815 device_link_remove(wcd937x->rxdev, wcd937x->txdev); 2824 component_unbind_all(dev, wcd937x); 2816 component_unbind_all(dev, wcd937x); 2825 mutex_destroy(&wcd937x->micb_lock); 2817 mutex_destroy(&wcd937x->micb_lock); 2826 } 2818 } 2827 2819 2828 static const struct component_master_ops wcd9 2820 static const struct component_master_ops wcd937x_comp_ops = { 2829 .bind = wcd937x_bind, 2821 .bind = wcd937x_bind, 2830 .unbind = wcd937x_unbind, 2822 .unbind = wcd937x_unbind, 2831 }; 2823 }; 2832 2824 2833 static int wcd937x_add_slave_components(struc 2825 static int wcd937x_add_slave_components(struct wcd937x_priv *wcd937x, 2834 struc 2826 struct device *dev, 2835 struc 2827 struct component_match **matchptr) 2836 { 2828 { 2837 struct device_node *np = dev->of_node 2829 struct device_node *np = dev->of_node; 2838 2830 2839 wcd937x->rxnode = of_parse_phandle(np 2831 wcd937x->rxnode = of_parse_phandle(np, "qcom,rx-device", 0); 2840 if (!wcd937x->rxnode) { 2832 if (!wcd937x->rxnode) { 2841 dev_err(dev, "Couldn't parse 2833 dev_err(dev, "Couldn't parse phandle to qcom,rx-device!\n"); 2842 return -ENODEV; 2834 return -ENODEV; 2843 } 2835 } 2844 of_node_get(wcd937x->rxnode); 2836 of_node_get(wcd937x->rxnode); 2845 component_match_add_release(dev, matc 2837 component_match_add_release(dev, matchptr, component_release_of, 2846 component 2838 component_compare_of, wcd937x->rxnode); 2847 2839 2848 wcd937x->txnode = of_parse_phandle(np 2840 wcd937x->txnode = of_parse_phandle(np, "qcom,tx-device", 0); 2849 if (!wcd937x->txnode) { 2841 if (!wcd937x->txnode) { 2850 dev_err(dev, "Couldn't parse 2842 dev_err(dev, "Couldn't parse phandle to qcom,tx-device\n"); 2851 return -ENODEV; 2843 return -ENODEV; 2852 } 2844 } 2853 of_node_get(wcd937x->txnode); 2845 of_node_get(wcd937x->txnode); 2854 component_match_add_release(dev, matc 2846 component_match_add_release(dev, matchptr, component_release_of, 2855 component 2847 component_compare_of, wcd937x->txnode); 2856 2848 2857 return 0; 2849 return 0; 2858 } 2850 } 2859 2851 2860 static int wcd937x_probe(struct platform_devi 2852 static int wcd937x_probe(struct platform_device *pdev) 2861 { 2853 { 2862 struct component_match *match = NULL; 2854 struct component_match *match = NULL; 2863 struct device *dev = &pdev->dev; 2855 struct device *dev = &pdev->dev; 2864 struct wcd937x_priv *wcd937x; 2856 struct wcd937x_priv *wcd937x; 2865 struct wcd_mbhc_config *cfg; 2857 struct wcd_mbhc_config *cfg; 2866 int ret; 2858 int ret; 2867 2859 2868 wcd937x = devm_kzalloc(dev, sizeof(*w 2860 wcd937x = devm_kzalloc(dev, sizeof(*wcd937x), GFP_KERNEL); 2869 if (!wcd937x) 2861 if (!wcd937x) 2870 return -ENOMEM; 2862 return -ENOMEM; 2871 2863 2872 dev_set_drvdata(dev, wcd937x); 2864 dev_set_drvdata(dev, wcd937x); 2873 mutex_init(&wcd937x->micb_lock); 2865 mutex_init(&wcd937x->micb_lock); 2874 2866 2875 wcd937x->reset_gpio = devm_gpiod_get( 2867 wcd937x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); 2876 if (IS_ERR(wcd937x->reset_gpio)) 2868 if (IS_ERR(wcd937x->reset_gpio)) 2877 return dev_err_probe(dev, PTR 2869 return dev_err_probe(dev, PTR_ERR(wcd937x->reset_gpio), 2878 "failed 2870 "failed to reset wcd gpio\n"); 2879 2871 2880 wcd937x->us_euro_gpio = devm_gpiod_ge 2872 wcd937x->us_euro_gpio = devm_gpiod_get_optional(dev, "us-euro", GPIOD_OUT_LOW); 2881 if (IS_ERR(wcd937x->us_euro_gpio)) 2873 if (IS_ERR(wcd937x->us_euro_gpio)) 2882 return dev_err_probe(dev, PTR 2874 return dev_err_probe(dev, PTR_ERR(wcd937x->us_euro_gpio), 2883 "us-euro swap 2875 "us-euro swap Control GPIO not found\n"); 2884 2876 2885 cfg = &wcd937x->mbhc_cfg; 2877 cfg = &wcd937x->mbhc_cfg; 2886 cfg->swap_gnd_mic = wcd937x_swap_gnd_ 2878 cfg->swap_gnd_mic = wcd937x_swap_gnd_mic; 2887 2879 2888 wcd937x->supplies[0].supply = "vdd-rx 2880 wcd937x->supplies[0].supply = "vdd-rxtx"; 2889 wcd937x->supplies[1].supply = "vdd-px 2881 wcd937x->supplies[1].supply = "vdd-px"; 2890 wcd937x->supplies[2].supply = "vdd-mi 2882 wcd937x->supplies[2].supply = "vdd-mic-bias"; 2891 wcd937x->supplies[3].supply = "vdd-bu 2883 wcd937x->supplies[3].supply = "vdd-buck"; 2892 2884 2893 ret = devm_regulator_bulk_get(dev, WC 2885 ret = devm_regulator_bulk_get(dev, WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); 2894 if (ret) 2886 if (ret) 2895 return dev_err_probe(dev, ret 2887 return dev_err_probe(dev, ret, "Failed to get supplies\n"); 2896 2888 2897 ret = regulator_bulk_enable(WCD937X_M 2889 ret = regulator_bulk_enable(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); 2898 if (ret) { 2890 if (ret) { 2899 regulator_bulk_free(WCD937X_M 2891 regulator_bulk_free(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); 2900 return dev_err_probe(dev, ret 2892 return dev_err_probe(dev, ret, "Failed to enable supplies\n"); 2901 } 2893 } 2902 2894 2903 wcd937x_dt_parse_micbias_info(dev, wc 2895 wcd937x_dt_parse_micbias_info(dev, wcd937x); 2904 2896 2905 cfg->mbhc_micbias = MIC_BIAS_2; 2897 cfg->mbhc_micbias = MIC_BIAS_2; 2906 cfg->anc_micbias = MIC_BIAS_2; 2898 cfg->anc_micbias = MIC_BIAS_2; 2907 cfg->v_hs_max = WCD_MBHC_HS_V_MAX; 2899 cfg->v_hs_max = WCD_MBHC_HS_V_MAX; 2908 cfg->num_btn = WCD937X_MBHC_MAX_BUTTO 2900 cfg->num_btn = WCD937X_MBHC_MAX_BUTTONS; 2909 cfg->micb_mv = wcd937x->micb2_mv; 2901 cfg->micb_mv = wcd937x->micb2_mv; 2910 cfg->linein_th = 5000; 2902 cfg->linein_th = 5000; 2911 cfg->hs_thr = 1700; 2903 cfg->hs_thr = 1700; 2912 cfg->hph_thr = 50; 2904 cfg->hph_thr = 50; 2913 2905 2914 wcd_dt_parse_mbhc_data(dev, &wcd937x- 2906 wcd_dt_parse_mbhc_data(dev, &wcd937x->mbhc_cfg); 2915 2907 2916 ret = wcd937x_add_slave_components(wc 2908 ret = wcd937x_add_slave_components(wcd937x, dev, &match); 2917 if (ret) 2909 if (ret) 2918 goto err_disable_regulators; 2910 goto err_disable_regulators; 2919 2911 2920 wcd937x_reset(wcd937x); 2912 wcd937x_reset(wcd937x); 2921 2913 2922 ret = component_master_add_with_match 2914 ret = component_master_add_with_match(dev, &wcd937x_comp_ops, match); 2923 if (ret) 2915 if (ret) 2924 goto err_disable_regulators; 2916 goto err_disable_regulators; 2925 2917 2926 pm_runtime_set_autosuspend_delay(dev, 2918 pm_runtime_set_autosuspend_delay(dev, 1000); 2927 pm_runtime_use_autosuspend(dev); 2919 pm_runtime_use_autosuspend(dev); 2928 pm_runtime_mark_last_busy(dev); 2920 pm_runtime_mark_last_busy(dev); 2929 pm_runtime_set_active(dev); 2921 pm_runtime_set_active(dev); 2930 pm_runtime_enable(dev); 2922 pm_runtime_enable(dev); 2931 pm_runtime_idle(dev); 2923 pm_runtime_idle(dev); 2932 2924 2933 return 0; 2925 return 0; 2934 2926 2935 err_disable_regulators: 2927 err_disable_regulators: 2936 regulator_bulk_disable(WCD937X_MAX_BU 2928 regulator_bulk_disable(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); 2937 regulator_bulk_free(WCD937X_MAX_BULK_ 2929 regulator_bulk_free(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); 2938 2930 2939 return ret; 2931 return ret; 2940 } 2932 } 2941 2933 2942 static void wcd937x_remove(struct platform_de 2934 static void wcd937x_remove(struct platform_device *pdev) 2943 { 2935 { 2944 struct device *dev = &pdev->dev; 2936 struct device *dev = &pdev->dev; 2945 struct wcd937x_priv *wcd937x = dev_ge 2937 struct wcd937x_priv *wcd937x = dev_get_drvdata(dev); 2946 2938 2947 component_master_del(&pdev->dev, &wcd 2939 component_master_del(&pdev->dev, &wcd937x_comp_ops); 2948 2940 2949 pm_runtime_disable(dev); 2941 pm_runtime_disable(dev); 2950 pm_runtime_set_suspended(dev); 2942 pm_runtime_set_suspended(dev); 2951 pm_runtime_dont_use_autosuspend(dev); 2943 pm_runtime_dont_use_autosuspend(dev); 2952 2944 2953 regulator_bulk_disable(WCD937X_MAX_BU 2945 regulator_bulk_disable(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); 2954 regulator_bulk_free(WCD937X_MAX_BULK_ 2946 regulator_bulk_free(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); 2955 } 2947 } 2956 2948 2957 #if defined(CONFIG_OF) 2949 #if defined(CONFIG_OF) 2958 static const struct of_device_id wcd937x_of_m 2950 static const struct of_device_id wcd937x_of_match[] = { 2959 { .compatible = "qcom,wcd9370-codec" 2951 { .compatible = "qcom,wcd9370-codec" }, 2960 { .compatible = "qcom,wcd9375-codec" 2952 { .compatible = "qcom,wcd9375-codec" }, 2961 { } 2953 { } 2962 }; 2954 }; 2963 MODULE_DEVICE_TABLE(of, wcd937x_of_match); 2955 MODULE_DEVICE_TABLE(of, wcd937x_of_match); 2964 #endif 2956 #endif 2965 2957 2966 static struct platform_driver wcd937x_codec_d 2958 static struct platform_driver wcd937x_codec_driver = { 2967 .probe = wcd937x_probe, 2959 .probe = wcd937x_probe, 2968 .remove = wcd937x_remove, !! 2960 .remove_new = wcd937x_remove, 2969 .driver = { 2961 .driver = { 2970 .name = "wcd937x_codec", 2962 .name = "wcd937x_codec", 2971 .of_match_table = of_match_pt 2963 .of_match_table = of_match_ptr(wcd937x_of_match), 2972 .suppress_bind_attrs = true, 2964 .suppress_bind_attrs = true, 2973 }, 2965 }, 2974 }; 2966 }; 2975 2967 2976 module_platform_driver(wcd937x_codec_driver); 2968 module_platform_driver(wcd937x_codec_driver); 2977 MODULE_DESCRIPTION("WCD937X Codec driver"); 2969 MODULE_DESCRIPTION("WCD937X Codec driver"); 2978 MODULE_LICENSE("GPL"); 2970 MODULE_LICENSE("GPL"); 2979 2971
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.