Lines Matching +full:vdd +full:- +full:micb +full:- +full:supply
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
20 #include <sound/soc-dapm.h>
24 #include "wcd-clsh-v2.h"
25 #include "wcd-mbhc-v2.h"
84 /* micb setup lock */
118 static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(ear_pa_gain, 600, -1800);
214 regmap_write(wcd937x->regmap, WCD937X_DIGITAL_INTR_CLEAR_0, 0); in wcd937x_handle_post_irq()
215 regmap_write(wcd937x->regmap, WCD937X_DIGITAL_INTR_CLEAR_1, 0); in wcd937x_handle_post_irq()
216 regmap_write(wcd937x->regmap, WCD937X_DIGITAL_INTR_CLEAR_2, 0); in wcd937x_handle_post_irq()
245 gpiod_set_value(wcd937x->reset_gpio, 1); in wcd937x_reset()
247 gpiod_set_value(wcd937x->reset_gpio, 0); in wcd937x_reset()
305 if (atomic_read(&wcd937x->rx_clk_cnt)) in wcd937x_rx_clk_enable()
316 atomic_inc(&wcd937x->rx_clk_cnt); in wcd937x_rx_clk_enable()
325 if (!atomic_read(&wcd937x->rx_clk_cnt)) { in wcd937x_rx_clk_disable()
326 dev_err(component->dev, "clk already disabled\n"); in wcd937x_rx_clk_disable()
330 atomic_dec(&wcd937x->rx_clk_cnt); in wcd937x_rx_clk_disable()
343 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_hphl_dac_event()
345 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_hphl_dac_event()
359 set_bit(HPH_COMP_DELAY, &wcd937x->status_mask); in wcd937x_codec_hphl_dac_event()
371 if (wcd937x->comp1_enable) { in wcd937x_codec_hphl_dac_event()
379 if (wcd937x->comp2_enable) { in wcd937x_codec_hphl_dac_event()
387 if (test_bit(HPH_COMP_DELAY, &wcd937x->status_mask)) { in wcd937x_codec_hphl_dac_event()
389 clear_bit(HPH_COMP_DELAY, &wcd937x->status_mask); in wcd937x_codec_hphl_dac_event()
418 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_hphr_dac_event()
420 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_hphr_dac_event()
431 set_bit(HPH_COMP_DELAY, &wcd937x->status_mask); in wcd937x_codec_hphr_dac_event()
442 if (wcd937x->comp2_enable) { in wcd937x_codec_hphr_dac_event()
448 if (wcd937x->comp1_enable) { in wcd937x_codec_hphr_dac_event()
457 if (test_bit(HPH_COMP_DELAY, &wcd937x->status_mask)) { in wcd937x_codec_hphr_dac_event()
459 clear_bit(HPH_COMP_DELAY, &wcd937x->status_mask); in wcd937x_codec_hphr_dac_event()
487 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_ear_dac_event()
489 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_ear_dac_event()
509 if (wcd937x->comp1_enable) in wcd937x_codec_ear_dac_event()
516 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_ear_dac_event()
528 if (wcd937x->comp1_enable) in wcd937x_codec_ear_dac_event()
542 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_aux_dac_event()
544 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_aux_dac_event()
558 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_aux_dac_event()
578 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_enable_hphr_pa()
580 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_enable_hphr_pa()
584 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_enable_hphr_pa()
591 set_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphr_pa()
597 if (test_bit(HPH_PA_DELAY, &wcd937x->status_mask)) { in wcd937x_codec_enable_hphr_pa()
598 if (wcd937x->comp2_enable) in wcd937x_codec_enable_hphr_pa()
602 clear_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphr_pa()
612 enable_irq(wcd937x->hphr_pdm_wd_int); in wcd937x_codec_enable_hphr_pa()
615 disable_irq_nosync(wcd937x->hphr_pdm_wd_int); in wcd937x_codec_enable_hphr_pa()
616 set_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphr_pa()
617 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, WCD_EVENT_PRE_HPHR_PA_OFF); in wcd937x_codec_enable_hphr_pa()
620 if (test_bit(HPH_PA_DELAY, &wcd937x->status_mask)) { in wcd937x_codec_enable_hphr_pa()
621 if (wcd937x->comp2_enable) in wcd937x_codec_enable_hphr_pa()
625 clear_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphr_pa()
628 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, WCD_EVENT_POST_HPHR_PA_OFF); in wcd937x_codec_enable_hphr_pa()
633 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_enable_hphr_pa()
647 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_enable_hphl_pa()
649 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_enable_hphl_pa()
653 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_enable_hphl_pa()
660 set_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphl_pa()
665 if (test_bit(HPH_PA_DELAY, &wcd937x->status_mask)) { in wcd937x_codec_enable_hphl_pa()
666 if (!wcd937x->comp1_enable) in wcd937x_codec_enable_hphl_pa()
670 clear_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphl_pa()
680 enable_irq(wcd937x->hphl_pdm_wd_int); in wcd937x_codec_enable_hphl_pa()
683 disable_irq_nosync(wcd937x->hphl_pdm_wd_int); in wcd937x_codec_enable_hphl_pa()
684 set_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphl_pa()
685 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, WCD_EVENT_PRE_HPHL_PA_OFF); in wcd937x_codec_enable_hphl_pa()
688 if (test_bit(HPH_PA_DELAY, &wcd937x->status_mask)) { in wcd937x_codec_enable_hphl_pa()
689 if (!wcd937x->comp1_enable) in wcd937x_codec_enable_hphl_pa()
693 clear_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphl_pa()
696 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, WCD_EVENT_POST_HPHL_PA_OFF); in wcd937x_codec_enable_hphl_pa()
701 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_enable_hphl_pa()
715 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_enable_aux_pa()
717 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_enable_aux_pa()
736 enable_irq(wcd937x->aux_pdm_wd_int); in wcd937x_codec_enable_aux_pa()
739 disable_irq_nosync(wcd937x->aux_pdm_wd_int); in wcd937x_codec_enable_aux_pa()
743 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_enable_aux_pa()
761 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_enable_ear_pa()
763 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_enable_ear_pa()
768 wcd937x->ear_rx_path = snd_soc_component_read(component, in wcd937x_codec_enable_ear_pa()
771 if (wcd937x->ear_rx_path & EAR_RX_PATH_AUX) in wcd937x_codec_enable_ear_pa()
779 if (!wcd937x->comp1_enable) in wcd937x_codec_enable_ear_pa()
791 if (wcd937x->ear_rx_path & EAR_RX_PATH_AUX) in wcd937x_codec_enable_ear_pa()
792 enable_irq(wcd937x->aux_pdm_wd_int); in wcd937x_codec_enable_ear_pa()
794 enable_irq(wcd937x->hphl_pdm_wd_int); in wcd937x_codec_enable_ear_pa()
797 if (wcd937x->ear_rx_path & EAR_RX_PATH_AUX) in wcd937x_codec_enable_ear_pa()
798 disable_irq_nosync(wcd937x->aux_pdm_wd_int); in wcd937x_codec_enable_ear_pa()
800 disable_irq_nosync(wcd937x->hphl_pdm_wd_int); in wcd937x_codec_enable_ear_pa()
803 if (!wcd937x->comp1_enable) in wcd937x_codec_enable_ear_pa()
808 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_enable_ear_pa()
815 if (wcd937x->ear_rx_path & EAR_RX_PATH_AUX) in wcd937x_codec_enable_ear_pa()
833 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_enable_rx1()
848 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_enable_rx2()
864 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_enable_rx3()
881 return -EINVAL; in wcd937x_get_micb_vout_ctl_val()
884 return (micb_mv - 1000) / 50; in wcd937x_get_micb_vout_ctl_val()
890 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_tx_swr_ctrl()
895 if (event == SND_SOC_DAPM_PRE_PMU && strnstr(w->name, "ADC", sizeof("ADC"))) in wcd937x_tx_swr_ctrl()
896 if (w->shift == 1 && !use_amic3) in wcd937x_tx_swr_ctrl()
897 set_bit(AMIC2_BCS_ENABLE, &wcd937x->status_mask); in wcd937x_tx_swr_ctrl()
905 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_enable_adc()
910 atomic_inc(&wcd937x->ana_clk_count); in wcd937x_codec_enable_adc()
919 if (w->shift == 1 && test_bit(AMIC2_BCS_ENABLE, &wcd937x->status_mask)) in wcd937x_codec_enable_adc()
920 clear_bit(AMIC2_BCS_ENABLE, &wcd937x->status_mask); in wcd937x_codec_enable_adc()
933 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_enable_req()
967 atomic_dec(&wcd937x->ana_clk_count); in wcd937x_enable_req()
968 if (atomic_read(&wcd937x->ana_clk_count) <= 0) { in wcd937x_enable_req()
972 atomic_set(&wcd937x->ana_clk_count, 0); in wcd937x_enable_req()
988 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_enable_dmic()
991 switch (w->shift) { in wcd937x_codec_enable_dmic()
1005 dev_err(component->dev, "Invalid DMIC Selection\n"); in wcd937x_codec_enable_dmic()
1006 return -EINVAL; in wcd937x_codec_enable_dmic()
1030 int micb_index = micb_num - 1; in wcd937x_micbias_control()
1033 if (micb_index < 0 || (micb_index > WCD937X_MAX_MICBIAS - 1)) { in wcd937x_micbias_control()
1034 dev_err(component->dev, "Invalid micbias index, micb_ind:%d\n", micb_index); in wcd937x_micbias_control()
1035 return -EINVAL; in wcd937x_micbias_control()
1048 dev_err(component->dev, "Invalid micbias number: %d\n", micb_num); in wcd937x_micbias_control()
1049 return -EINVAL; in wcd937x_micbias_control()
1052 mutex_lock(&wcd937x->micb_lock); in wcd937x_micbias_control()
1055 wcd937x->pullup_ref[micb_index]++; in wcd937x_micbias_control()
1056 if (wcd937x->pullup_ref[micb_index] == 1 && in wcd937x_micbias_control()
1057 wcd937x->micb_ref[micb_index] == 0) in wcd937x_micbias_control()
1062 if (wcd937x->pullup_ref[micb_index] > 0) in wcd937x_micbias_control()
1063 wcd937x->pullup_ref[micb_index]++; in wcd937x_micbias_control()
1064 if (wcd937x->pullup_ref[micb_index] == 0 && in wcd937x_micbias_control()
1065 wcd937x->micb_ref[micb_index] == 0) in wcd937x_micbias_control()
1070 wcd937x->micb_ref[micb_index]++; in wcd937x_micbias_control()
1071 atomic_inc(&wcd937x->ana_clk_count); in wcd937x_micbias_control()
1072 if (wcd937x->micb_ref[micb_index] == 1) { in wcd937x_micbias_control()
1092 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, in wcd937x_micbias_control()
1096 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, in wcd937x_micbias_control()
1101 atomic_dec(&wcd937x->ana_clk_count); in wcd937x_micbias_control()
1102 if (wcd937x->micb_ref[micb_index] > 0) in wcd937x_micbias_control()
1103 wcd937x->micb_ref[micb_index]--; in wcd937x_micbias_control()
1104 if (wcd937x->micb_ref[micb_index] == 0 && in wcd937x_micbias_control()
1105 wcd937x->pullup_ref[micb_index] > 0) in wcd937x_micbias_control()
1108 else if (wcd937x->micb_ref[micb_index] == 0 && in wcd937x_micbias_control()
1109 wcd937x->pullup_ref[micb_index] == 0) { in wcd937x_micbias_control()
1111 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, in wcd937x_micbias_control()
1117 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, in wcd937x_micbias_control()
1122 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, in wcd937x_micbias_control()
1124 if (atomic_read(&wcd937x->ana_clk_count) <= 0) { in wcd937x_micbias_control()
1128 atomic_set(&wcd937x->ana_clk_count, 0); in wcd937x_micbias_control()
1132 mutex_unlock(&wcd937x->micb_lock); in wcd937x_micbias_control()
1140 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in __wcd937x_codec_enable_micbias()
1141 int micb_num = w->shift; in __wcd937x_codec_enable_micbias()
1170 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in __wcd937x_codec_enable_micbias_pullup()
1171 int micb_num = w->shift; in __wcd937x_codec_enable_micbias_pullup()
1197 struct sdw_port_config *port_config = &wcd->port_config[port_idx - 1]; in wcd937x_connect_port()
1198 const struct wcd937x_sdw_ch_info *ch_info = &wcd->ch_info[ch_id]; in wcd937x_connect_port()
1199 u8 port_num = ch_info->port_num; in wcd937x_connect_port()
1200 u8 ch_mask = ch_info->ch_mask; in wcd937x_connect_port()
1202 port_config->num = port_num; in wcd937x_connect_port()
1205 port_config->ch_mask |= ch_mask; in wcd937x_connect_port()
1207 port_config->ch_mask &= ~ch_mask; in wcd937x_connect_port()
1218 ucontrol->value.integer.value[0] = wcd937x->hph_mode; in wcd937x_rx_hph_mode_get()
1230 mode_val = ucontrol->value.enumerated.item[0]; in wcd937x_rx_hph_mode_put()
1235 if (mode_val == wcd937x->hph_mode) in wcd937x_rx_hph_mode_put()
1247 wcd937x->hph_mode = mode_val; in wcd937x_rx_hph_mode_put()
1251 dev_dbg(component->dev, "%s: Invalid HPH Mode\n", __func__); in wcd937x_rx_hph_mode_put()
1252 return -EINVAL; in wcd937x_rx_hph_mode_put()
1263 mc = (struct soc_mixer_control *)(kcontrol->private_value); in wcd937x_get_compander()
1264 hphr = mc->shift; in wcd937x_get_compander()
1266 ucontrol->value.integer.value[0] = hphr ? wcd937x->comp2_enable : in wcd937x_get_compander()
1267 wcd937x->comp1_enable; in wcd937x_get_compander()
1276 struct wcd937x_sdw_priv *wcd = wcd937x->sdw_priv[AIF1_PB]; in wcd937x_set_compander()
1277 int value = ucontrol->value.integer.value[0]; in wcd937x_set_compander()
1282 mc = (struct soc_mixer_control *)(kcontrol->private_value); in wcd937x_set_compander()
1283 hphr = mc->shift; in wcd937x_set_compander()
1286 if (value == wcd937x->comp2_enable) in wcd937x_set_compander()
1289 wcd937x->comp2_enable = value; in wcd937x_set_compander()
1291 if (value == wcd937x->comp1_enable) in wcd937x_set_compander()
1294 wcd937x->comp1_enable = value; in wcd937x_set_compander()
1297 portidx = wcd->ch_info[mc->reg].port_num; in wcd937x_set_compander()
1300 wcd937x_connect_port(wcd, portidx, mc->reg, true); in wcd937x_set_compander()
1302 wcd937x_connect_port(wcd, portidx, mc->reg, false); in wcd937x_set_compander()
1310 struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; in wcd937x_get_swr_port()
1314 int dai_id = mixer->shift; in wcd937x_get_swr_port()
1315 int ch_idx = mixer->reg; in wcd937x_get_swr_port()
1318 wcd = wcd937x->sdw_priv[dai_id]; in wcd937x_get_swr_port()
1319 portidx = wcd->ch_info[ch_idx].port_num; in wcd937x_get_swr_port()
1321 ucontrol->value.integer.value[0] = wcd->port_enable[portidx]; in wcd937x_get_swr_port()
1329 struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; in wcd937x_set_swr_port()
1333 int dai_id = mixer->shift; in wcd937x_set_swr_port()
1334 int ch_idx = mixer->reg; in wcd937x_set_swr_port()
1338 wcd = wcd937x->sdw_priv[dai_id]; in wcd937x_set_swr_port()
1340 portidx = wcd->ch_info[ch_idx].port_num; in wcd937x_set_swr_port()
1342 enable = ucontrol->value.integer.value[0]; in wcd937x_set_swr_port()
1344 if (enable == wcd->port_enable[portidx]) { in wcd937x_set_swr_port()
1349 wcd->port_enable[portidx] = enable; in wcd937x_set_swr_port()
1385 dev_err(component->dev, "%s: invalid number of buttons: %d\n", in wcd937x_mbhc_program_btn_thr()
1462 return -EINVAL; in wcd937x_mbhc_micb_adjust_voltage()
1464 mutex_lock(&wcd937x->micb_lock); in wcd937x_mbhc_micb_adjust_voltage()
1469 * to avoid slow micbias ramp-up or down enable pull-up in wcd937x_mbhc_micb_adjust_voltage()
1470 * momentarily, change the micbias value and then re-enable in wcd937x_mbhc_micb_adjust_voltage()
1480 ret = -EINVAL; in wcd937x_mbhc_micb_adjust_voltage()
1509 mutex_unlock(&wcd937x->micb_lock); in wcd937x_mbhc_micb_adjust_voltage()
1520 return -EINVAL; in wcd937x_mbhc_micb_ctrl_threshold_mic()
1526 if (wcd937x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV) in wcd937x_mbhc_micb_ctrl_threshold_mic()
1529 micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd937x->micb2_mv; in wcd937x_mbhc_micb_ctrl_threshold_mic()
1548 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MBHC_ZDET, 0x20, 0x20); in wcd937x_mbhc_get_result_params()
1550 regmap_read(wcd937x->regmap, WCD937X_ANA_MBHC_RESULT_2, &val); in wcd937x_mbhc_get_result_params()
1555 regmap_read(wcd937x->regmap, WCD937X_ANA_MBHC_RESULT_1, &val1); in wcd937x_mbhc_get_result_params()
1557 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MBHC_ZDET, 0x20, 0x00); in wcd937x_mbhc_get_result_params()
1565 dev_err(component->dev, "Impedance detect ramp error, c1=%d, x1=0x%x\n", in wcd937x_mbhc_get_result_params()
1570 denom = (x1 * d1) - (1 << (14 - noff)); in wcd937x_mbhc_get_result_params()
1576 dev_err(component->dev, "%s: d1=%d, c1=%d, x1=0x%x, z_val=%d (milliohm)\n", in wcd937x_mbhc_get_result_params()
1581 regmap_read(wcd937x->regmap, in wcd937x_mbhc_get_result_params()
1583 regmap_read(wcd937x->regmap, in wcd937x_mbhc_get_result_params()
1602 WCD937X_ZDET_MAXV_CTL_MASK, zdet_param->ldo_ctl); in wcd937x_mbhc_zdet_ramp()
1604 WCD937X_VTH_MASK, zdet_param->btn5); in wcd937x_mbhc_zdet_ramp()
1606 WCD937X_VTH_MASK, zdet_param->btn6); in wcd937x_mbhc_zdet_ramp()
1608 WCD937X_VTH_MASK, zdet_param->btn7); in wcd937x_mbhc_zdet_ramp()
1610 WCD937X_ZDET_RANGE_CTL_MASK, zdet_param->noff); in wcd937x_mbhc_zdet_ramp()
1612 0x0F, zdet_param->nshift); in wcd937x_mbhc_zdet_ramp()
1617 regmap_update_bits(wcd937x->regmap, in wcd937x_mbhc_zdet_ramp()
1619 wcd937x_mbhc_get_result_params(component, d1_a, zdet_param->noff, &zdet); in wcd937x_mbhc_zdet_ramp()
1620 regmap_update_bits(wcd937x->regmap, in wcd937x_mbhc_zdet_ramp()
1629 regmap_update_bits(wcd937x->regmap, in wcd937x_mbhc_zdet_ramp()
1631 wcd937x_mbhc_get_result_params(component, d1_a, zdet_param->noff, &zdet); in wcd937x_mbhc_zdet_ramp()
1632 regmap_update_bits(wcd937x->regmap, in wcd937x_mbhc_zdet_ramp()
1651 q1_cal = (10000 - ((q1 & 0x7F) * 25)); in wcd937x_wcd_mbhc_qfuse_cal()
1689 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1693 /* For NO-jack, disable L_DET_EN before Z-det measurements */ in wcd937x_wcd_mbhc_calc_impedance()
1694 if (wcd937x->mbhc_cfg.hphl_swh) in wcd937x_wcd_mbhc_calc_impedance()
1695 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1699 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1705 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1747 zdet_param_ptr->noff == 0x6) || in wcd937x_wcd_mbhc_calc_impedance()
1776 dev_err(component->dev, in wcd937x_wcd_mbhc_calc_impedance()
1785 wcd_mbhc_set_hph_type(wcd937x->wcd_mbhc, WCD_MBHC_HPH_MONO); in wcd937x_wcd_mbhc_calc_impedance()
1804 z_diff1 = (z1ls > zMono) ? (z1ls - zMono) : (zMono - z1ls); in wcd937x_wcd_mbhc_calc_impedance()
1805 z_diff2 = ((*zl) > z1ls) ? ((*zl) - z1ls) : (z1ls - (*zl)); in wcd937x_wcd_mbhc_calc_impedance()
1807 wcd_mbhc_set_hph_type(wcd937x->wcd_mbhc, WCD_MBHC_HPH_STEREO); in wcd937x_wcd_mbhc_calc_impedance()
1809 wcd_mbhc_set_hph_type(wcd937x->wcd_mbhc, WCD_MBHC_HPH_MONO); in wcd937x_wcd_mbhc_calc_impedance()
1812 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1819 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1822 /* For NO-jack, re-enable L_DET_EN after Z-det measurements */ in wcd937x_wcd_mbhc_calc_impedance()
1823 if (wcd937x->mbhc_cfg.hphl_swh) in wcd937x_wcd_mbhc_calc_impedance()
1824 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1830 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1863 if (wcd937x->mbhc_cfg.moist_rref == R_OFF) { in wcd937x_mbhc_moisture_config()
1870 if (!wcd937x->mbhc_cfg.hphl_swh) { in wcd937x_mbhc_moisture_config()
1871 dev_err(component->dev, "%s: disable moisture detection for NC\n", in wcd937x_mbhc_moisture_config()
1879 WCD937X_M_RTH_CTL_MASK, wcd937x->mbhc_cfg.moist_rref); in wcd937x_mbhc_moisture_config()
1888 WCD937X_M_RTH_CTL_MASK, wcd937x->mbhc_cfg.moist_rref); in wcd937x_mbhc_moisture_detect_en()
1899 if (wcd937x->mbhc_cfg.moist_rref == R_OFF) { in wcd937x_mbhc_get_moisture_status()
1906 if (!wcd937x->mbhc_cfg.hphl_swh) { in wcd937x_mbhc_get_moisture_status()
1907 dev_err(component->dev, "%s: disable moisture detection for NC\n", in wcd937x_mbhc_get_moisture_status()
1961 ucontrol->value.integer.value[0] = wcd_mbhc_get_hph_type(wcd937x->wcd_mbhc); in wcd937x_get_hph_type()
1976 mc = (struct soc_mixer_control *)(kcontrol->private_value); in wcd937x_hph_impedance_get()
1977 hphr = mc->shift; in wcd937x_hph_impedance_get()
1978 wcd_mbhc_get_impedance(wcd937x->wcd_mbhc, &zl, &zr); in wcd937x_hph_impedance_get()
1979 ucontrol->value.integer.value[0] = hphr ? zr : zl; in wcd937x_hph_impedance_get()
1999 struct wcd_mbhc_intr *intr_ids = &wcd937x->intr_ids; in wcd937x_mbhc_init()
2001 intr_ids->mbhc_sw_intr = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2003 intr_ids->mbhc_btn_press_intr = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2005 intr_ids->mbhc_btn_release_intr = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2007 intr_ids->mbhc_hs_ins_intr = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2009 intr_ids->mbhc_hs_rem_intr = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2011 intr_ids->hph_left_ocp = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2013 intr_ids->hph_right_ocp = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2016 wcd937x->wcd_mbhc = wcd_mbhc_init(component, &mbhc_cb, intr_ids, wcd_mbhc_fields, true); in wcd937x_mbhc_init()
2017 if (IS_ERR(wcd937x->wcd_mbhc)) in wcd937x_mbhc_init()
2018 return PTR_ERR(wcd937x->wcd_mbhc); in wcd937x_mbhc_init()
2032 wcd_mbhc_deinit(wcd937x->wcd_mbhc); in wcd937x_mbhc_deinit()
2438 vout_ctl[0] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb1_mv); in wcd937x_set_micbias_data()
2439 vout_ctl[1] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb2_mv); in wcd937x_set_micbias_data()
2440 vout_ctl[2] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb3_mv); in wcd937x_set_micbias_data()
2442 return -EINVAL; in wcd937x_set_micbias_data()
2444 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB1, WCD937X_ANA_MICB_VOUT, vout_ctl[0]); in wcd937x_set_micbias_data()
2445 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB2, WCD937X_ANA_MICB_VOUT, vout_ctl[1]); in wcd937x_set_micbias_data()
2446 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB3, WCD937X_ANA_MICB_VOUT, vout_ctl[2]); in wcd937x_set_micbias_data()
2476 wcd->virq = irq_domain_add_linear(NULL, 1, &wcd_domain_ops, NULL); in wcd937x_irq_init()
2477 if (!(wcd->virq)) { in wcd937x_irq_init()
2479 return -EINVAL; in wcd937x_irq_init()
2482 return devm_regmap_add_irq_chip(dev, wcd->regmap, in wcd937x_irq_init()
2483 irq_create_mapping(wcd->virq, 0), in wcd937x_irq_init()
2485 &wcd->irq_chip); in wcd937x_irq_init()
2492 struct sdw_slave *tx_sdw_dev = wcd937x->tx_sdw_dev; in wcd937x_soc_codec_probe()
2493 struct device *dev = component->dev; in wcd937x_soc_codec_probe()
2498 time_left = wait_for_completion_timeout(&tx_sdw_dev->initialization_complete, in wcd937x_soc_codec_probe()
2502 return -ETIMEDOUT; in wcd937x_soc_codec_probe()
2505 snd_soc_component_init_regmap(component, wcd937x->regmap); in wcd937x_soc_codec_probe()
2515 return -EINVAL; in wcd937x_soc_codec_probe()
2518 wcd937x->clsh_info = wcd_clsh_ctrl_alloc(component, WCD937X); in wcd937x_soc_codec_probe()
2519 if (IS_ERR(wcd937x->clsh_info)) { in wcd937x_soc_codec_probe()
2521 return PTR_ERR(wcd937x->clsh_info); in wcd937x_soc_codec_probe()
2524 wcd937x_io_init(wcd937x->regmap); in wcd937x_soc_codec_probe()
2527 regmap_write(wcd937x->regmap, (WCD937X_DIGITAL_INTR_LEVEL_0 + i), 0); in wcd937x_soc_codec_probe()
2531 wcd937x->hphr_pdm_wd_int = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_soc_codec_probe()
2533 wcd937x->hphl_pdm_wd_int = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_soc_codec_probe()
2535 wcd937x->aux_pdm_wd_int = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_soc_codec_probe()
2539 ret = devm_request_threaded_irq(dev, wcd937x->hphr_pdm_wd_int, NULL, wcd937x_wd_handle_irq, in wcd937x_soc_codec_probe()
2545 ret = devm_request_threaded_irq(dev, wcd937x->hphl_pdm_wd_int, NULL, wcd937x_wd_handle_irq, in wcd937x_soc_codec_probe()
2551 ret = devm_request_threaded_irq(dev, wcd937x->aux_pdm_wd_int, NULL, wcd937x_wd_handle_irq, in wcd937x_soc_codec_probe()
2558 disable_irq_nosync(wcd937x->hphr_pdm_wd_int); in wcd937x_soc_codec_probe()
2559 disable_irq_nosync(wcd937x->hphl_pdm_wd_int); in wcd937x_soc_codec_probe()
2560 disable_irq_nosync(wcd937x->aux_pdm_wd_int); in wcd937x_soc_codec_probe()
2566 dev_err(component->dev, "Failed to add snd_ctls\n"); in wcd937x_soc_codec_probe()
2573 dev_err(component->dev, "Failed to add routes\n"); in wcd937x_soc_codec_probe()
2580 dev_err(component->dev, "mbhc initialization failed\n"); in wcd937x_soc_codec_probe()
2590 free_irq(wcd937x->aux_pdm_wd_int, wcd937x); in wcd937x_soc_codec_remove()
2591 free_irq(wcd937x->hphl_pdm_wd_int, wcd937x); in wcd937x_soc_codec_remove()
2592 free_irq(wcd937x->hphr_pdm_wd_int, wcd937x); in wcd937x_soc_codec_remove()
2594 wcd_clsh_ctrl_free(wcd937x->clsh_info); in wcd937x_soc_codec_remove()
2600 struct wcd937x_priv *wcd = dev_get_drvdata(comp->dev); in wcd937x_codec_set_jack()
2604 ret = wcd_mbhc_start(wcd->wcd_mbhc, &wcd->mbhc_cfg, jack); in wcd937x_codec_set_jack()
2606 wcd_mbhc_stop(wcd->wcd_mbhc); in wcd937x_codec_set_jack()
2627 struct device_node *np = dev->of_node; in wcd937x_dt_parse_micbias_info()
2631 ret = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val); in wcd937x_dt_parse_micbias_info()
2633 wcd->micb1_mv = prop_val / 1000; in wcd937x_dt_parse_micbias_info()
2637 ret = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val); in wcd937x_dt_parse_micbias_info()
2639 wcd->micb2_mv = prop_val / 1000; in wcd937x_dt_parse_micbias_info()
2643 ret = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val); in wcd937x_dt_parse_micbias_info()
2645 wcd->micb3_mv = prop_val / 1000; in wcd937x_dt_parse_micbias_info()
2657 value = gpiod_get_value(wcd937x->us_euro_gpio); in wcd937x_swap_gnd_mic()
2658 gpiod_set_value(wcd937x->us_euro_gpio, !value); in wcd937x_swap_gnd_mic()
2667 struct wcd937x_priv *wcd937x = dev_get_drvdata(dai->dev); in wcd937x_codec_hw_params()
2668 struct wcd937x_sdw_priv *wcd = wcd937x->sdw_priv[dai->id]; in wcd937x_codec_hw_params()
2676 struct wcd937x_priv *wcd937x = dev_get_drvdata(dai->dev); in wcd937x_codec_free()
2677 struct wcd937x_sdw_priv *wcd = wcd937x->sdw_priv[dai->id]; in wcd937x_codec_free()
2679 return sdw_stream_remove_slave(wcd->sdev, wcd->sruntime); in wcd937x_codec_free()
2685 struct wcd937x_priv *wcd937x = dev_get_drvdata(dai->dev); in wcd937x_codec_set_sdw_stream()
2686 struct wcd937x_sdw_priv *wcd = wcd937x->sdw_priv[dai->id]; in wcd937x_codec_set_sdw_stream()
2688 wcd->sruntime = stream; in wcd937x_codec_set_sdw_stream()
2701 .name = "wcd937x-sdw-rx",
2714 .name = "wcd937x-sdw-tx",
2742 wcd937x->rxdev = wcd937x_sdw_device_get(wcd937x->rxnode); in wcd937x_bind()
2743 if (!wcd937x->rxdev) { in wcd937x_bind()
2745 return -EINVAL; in wcd937x_bind()
2748 wcd937x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd937x->rxdev); in wcd937x_bind()
2749 wcd937x->sdw_priv[AIF1_PB]->wcd937x = wcd937x; in wcd937x_bind()
2751 wcd937x->txdev = wcd937x_sdw_device_get(wcd937x->txnode); in wcd937x_bind()
2752 if (!wcd937x->txdev) { in wcd937x_bind()
2754 return -EINVAL; in wcd937x_bind()
2757 wcd937x->sdw_priv[AIF1_CAP] = dev_get_drvdata(wcd937x->txdev); in wcd937x_bind()
2758 wcd937x->sdw_priv[AIF1_CAP]->wcd937x = wcd937x; in wcd937x_bind()
2759 wcd937x->tx_sdw_dev = dev_to_sdw_dev(wcd937x->txdev); in wcd937x_bind()
2760 if (!wcd937x->tx_sdw_dev) { in wcd937x_bind()
2762 return -EINVAL; in wcd937x_bind()
2769 if (!device_link_add(wcd937x->rxdev, wcd937x->txdev, in wcd937x_bind()
2772 return -EINVAL; in wcd937x_bind()
2775 if (!device_link_add(dev, wcd937x->txdev, in wcd937x_bind()
2778 return -EINVAL; in wcd937x_bind()
2781 if (!device_link_add(dev, wcd937x->rxdev, in wcd937x_bind()
2784 return -EINVAL; in wcd937x_bind()
2787 wcd937x->regmap = dev_get_regmap(&wcd937x->tx_sdw_dev->dev, NULL); in wcd937x_bind()
2788 if (!wcd937x->regmap) { in wcd937x_bind()
2790 return -EINVAL; in wcd937x_bind()
2799 wcd937x->sdw_priv[AIF1_PB]->slave_irq = wcd937x->virq; in wcd937x_bind()
2800 wcd937x->sdw_priv[AIF1_CAP]->slave_irq = wcd937x->virq; in wcd937x_bind()
2821 device_link_remove(dev, wcd937x->txdev); in wcd937x_unbind()
2822 device_link_remove(dev, wcd937x->rxdev); in wcd937x_unbind()
2823 device_link_remove(wcd937x->rxdev, wcd937x->txdev); in wcd937x_unbind()
2825 mutex_destroy(&wcd937x->micb_lock); in wcd937x_unbind()
2837 struct device_node *np = dev->of_node; in wcd937x_add_slave_components()
2839 wcd937x->rxnode = of_parse_phandle(np, "qcom,rx-device", 0); in wcd937x_add_slave_components()
2840 if (!wcd937x->rxnode) { in wcd937x_add_slave_components()
2841 dev_err(dev, "Couldn't parse phandle to qcom,rx-device!\n"); in wcd937x_add_slave_components()
2842 return -ENODEV; in wcd937x_add_slave_components()
2844 of_node_get(wcd937x->rxnode); in wcd937x_add_slave_components()
2846 component_compare_of, wcd937x->rxnode); in wcd937x_add_slave_components()
2848 wcd937x->txnode = of_parse_phandle(np, "qcom,tx-device", 0); in wcd937x_add_slave_components()
2849 if (!wcd937x->txnode) { in wcd937x_add_slave_components()
2850 dev_err(dev, "Couldn't parse phandle to qcom,tx-device\n"); in wcd937x_add_slave_components()
2851 return -ENODEV; in wcd937x_add_slave_components()
2853 of_node_get(wcd937x->txnode); in wcd937x_add_slave_components()
2855 component_compare_of, wcd937x->txnode); in wcd937x_add_slave_components()
2863 struct device *dev = &pdev->dev; in wcd937x_probe()
2870 return -ENOMEM; in wcd937x_probe()
2873 mutex_init(&wcd937x->micb_lock); in wcd937x_probe()
2875 wcd937x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in wcd937x_probe()
2876 if (IS_ERR(wcd937x->reset_gpio)) in wcd937x_probe()
2877 return dev_err_probe(dev, PTR_ERR(wcd937x->reset_gpio), in wcd937x_probe()
2880 wcd937x->us_euro_gpio = devm_gpiod_get_optional(dev, "us-euro", GPIOD_OUT_LOW); in wcd937x_probe()
2881 if (IS_ERR(wcd937x->us_euro_gpio)) in wcd937x_probe()
2882 return dev_err_probe(dev, PTR_ERR(wcd937x->us_euro_gpio), in wcd937x_probe()
2883 "us-euro swap Control GPIO not found\n"); in wcd937x_probe()
2885 cfg = &wcd937x->mbhc_cfg; in wcd937x_probe()
2886 cfg->swap_gnd_mic = wcd937x_swap_gnd_mic; in wcd937x_probe()
2888 wcd937x->supplies[0].supply = "vdd-rxtx"; in wcd937x_probe()
2889 wcd937x->supplies[1].supply = "vdd-px"; in wcd937x_probe()
2890 wcd937x->supplies[2].supply = "vdd-mic-bias"; in wcd937x_probe()
2891 wcd937x->supplies[3].supply = "vdd-buck"; in wcd937x_probe()
2893 ret = devm_regulator_bulk_get(dev, WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_probe()
2897 ret = regulator_bulk_enable(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_probe()
2899 regulator_bulk_free(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_probe()
2905 cfg->mbhc_micbias = MIC_BIAS_2; in wcd937x_probe()
2906 cfg->anc_micbias = MIC_BIAS_2; in wcd937x_probe()
2907 cfg->v_hs_max = WCD_MBHC_HS_V_MAX; in wcd937x_probe()
2908 cfg->num_btn = WCD937X_MBHC_MAX_BUTTONS; in wcd937x_probe()
2909 cfg->micb_mv = wcd937x->micb2_mv; in wcd937x_probe()
2910 cfg->linein_th = 5000; in wcd937x_probe()
2911 cfg->hs_thr = 1700; in wcd937x_probe()
2912 cfg->hph_thr = 50; in wcd937x_probe()
2914 wcd_dt_parse_mbhc_data(dev, &wcd937x->mbhc_cfg); in wcd937x_probe()
2936 regulator_bulk_disable(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_probe()
2937 regulator_bulk_free(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_probe()
2944 struct device *dev = &pdev->dev; in wcd937x_remove()
2947 component_master_del(&pdev->dev, &wcd937x_comp_ops); in wcd937x_remove()
2953 regulator_bulk_disable(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_remove()
2954 regulator_bulk_free(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_remove()
2959 { .compatible = "qcom,wcd9370-codec" },
2960 { .compatible = "qcom,wcd9375-codec" },