Lines Matching +full:current +full:- +full:ramp +full:- +full:delay +full:- +full:ms
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
4 * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
12 #include <linux/delay.h>
26 #include <sound/soc-dapm.h>
31 #include "wcd-clsh-v2.h"
32 #include "wcd-mbhc-v2.h"
217 static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(ear_pa_gain, 600, -1800);
367 /* 10 msec delay as per HW requirement */ in wcd939x_io_init()
421 port_num = ch_info->port_num; in wcd939x_sdw_connect_port()
422 ch_mask = ch_info->ch_mask; in wcd939x_sdw_connect_port()
424 port_config->num = port_num; in wcd939x_sdw_connect_port()
427 port_config->ch_mask |= ch_mask; in wcd939x_sdw_connect_port()
429 port_config->ch_mask &= ~ch_mask; in wcd939x_sdw_connect_port()
436 return wcd939x_sdw_connect_port(&wcd->ch_info[ch_id], in wcd939x_connect_port()
437 &wcd->port_config[port_num - 1], in wcd939x_connect_port()
445 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd939x_codec_enable_rxclk()
505 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd939x_codec_hphl_dac_event()
520 if (wcd939x->comp1_enable) { in wcd939x_codec_hphl_dac_event()
525 /* 5msec compander delay as per HW requirement */ in wcd939x_codec_hphl_dac_event()
526 if (!wcd939x->comp2_enable || in wcd939x_codec_hphl_dac_event()
559 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd939x_codec_hphr_dac_event()
562 dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__, in wcd939x_codec_hphr_dac_event()
563 w->name, event); in wcd939x_codec_hphr_dac_event()
577 if (wcd939x->comp2_enable) { in wcd939x_codec_hphr_dac_event()
582 /* 5msec compander delay as per HW requirement */ in wcd939x_codec_hphr_dac_event()
583 if (!wcd939x->comp1_enable || in wcd939x_codec_hphr_dac_event()
615 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd939x_codec_ear_dac_event()
626 /* 5 msec delay as per HW requirement */ in wcd939x_codec_ear_dac_event()
628 wcd_clsh_ctrl_set_state(wcd939x->clsh_info, WCD_CLSH_EVENT_PRE_DAC, in wcd939x_codec_ear_dac_event()
647 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd939x_codec_enable_hphr_pa()
649 int hph_mode = wcd939x->hph_mode; in wcd939x_codec_enable_hphr_pa()
653 if (wcd939x->ldoh) in wcd939x_codec_enable_hphr_pa()
657 wcd_clsh_ctrl_set_state(wcd939x->clsh_info, WCD_CLSH_EVENT_PRE_DAC, in wcd939x_codec_enable_hphr_pa()
659 wcd_clsh_set_hph_mode(wcd939x->clsh_info, CLS_H_HIFI); in wcd939x_codec_enable_hphr_pa()
676 usleep_range(2500, 2600); /* 2.5msec delay as per HW requirement */ in wcd939x_codec_enable_hphr_pa()
678 set_bit(HPH_PA_DELAY, &wcd939x->status_mask); in wcd939x_codec_enable_hphr_pa()
684 * 7ms sleep is required if compander is enabled as per in wcd939x_codec_enable_hphr_pa()
686 * 20ms delay is required. in wcd939x_codec_enable_hphr_pa()
688 if (test_bit(HPH_PA_DELAY, &wcd939x->status_mask)) { in wcd939x_codec_enable_hphr_pa()
689 if (!wcd939x->comp2_enable) in wcd939x_codec_enable_hphr_pa()
700 clear_bit(HPH_PA_DELAY, &wcd939x->status_mask); in wcd939x_codec_enable_hphr_pa()
710 enable_irq(wcd939x->hphr_pdm_wd_int); in wcd939x_codec_enable_hphr_pa()
713 disable_irq_nosync(wcd939x->hphr_pdm_wd_int); in wcd939x_codec_enable_hphr_pa()
715 * 7ms sleep is required if compander is enabled as per in wcd939x_codec_enable_hphr_pa()
717 * 20ms delay is required. in wcd939x_codec_enable_hphr_pa()
719 if (!wcd939x->comp2_enable) in wcd939x_codec_enable_hphr_pa()
727 wcd_mbhc_event_notify(wcd939x->wcd_mbhc, in wcd939x_codec_enable_hphr_pa()
729 set_bit(HPH_PA_DELAY, &wcd939x->status_mask); in wcd939x_codec_enable_hphr_pa()
733 * 7ms sleep is required if compander is enabled as per in wcd939x_codec_enable_hphr_pa()
735 * 20ms delay is required. in wcd939x_codec_enable_hphr_pa()
737 if (test_bit(HPH_PA_DELAY, &wcd939x->status_mask)) { in wcd939x_codec_enable_hphr_pa()
738 if (!wcd939x->comp2_enable) in wcd939x_codec_enable_hphr_pa()
742 clear_bit(HPH_PA_DELAY, &wcd939x->status_mask); in wcd939x_codec_enable_hphr_pa()
744 wcd_mbhc_event_notify(wcd939x->wcd_mbhc, in wcd939x_codec_enable_hphr_pa()
752 wcd_clsh_ctrl_set_state(wcd939x->clsh_info, WCD_CLSH_EVENT_POST_PA, in wcd939x_codec_enable_hphr_pa()
754 if (wcd939x->ldoh) in wcd939x_codec_enable_hphr_pa()
767 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd939x_codec_enable_hphl_pa()
769 int hph_mode = wcd939x->hph_mode; in wcd939x_codec_enable_hphl_pa()
771 dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__, in wcd939x_codec_enable_hphl_pa()
772 w->name, event); in wcd939x_codec_enable_hphl_pa()
776 if (wcd939x->ldoh) in wcd939x_codec_enable_hphl_pa()
779 wcd_clsh_ctrl_set_state(wcd939x->clsh_info, WCD_CLSH_EVENT_PRE_DAC, in wcd939x_codec_enable_hphl_pa()
781 wcd_clsh_set_hph_mode(wcd939x->clsh_info, CLS_H_HIFI); in wcd939x_codec_enable_hphl_pa()
799 usleep_range(2500, 2600); /* 2.5msec delay as per HW requirement */ in wcd939x_codec_enable_hphl_pa()
801 set_bit(HPH_PA_DELAY, &wcd939x->status_mask); in wcd939x_codec_enable_hphl_pa()
807 * 7ms sleep is required if compander is enabled as per in wcd939x_codec_enable_hphl_pa()
809 * 20ms delay is required. in wcd939x_codec_enable_hphl_pa()
811 if (test_bit(HPH_PA_DELAY, &wcd939x->status_mask)) { in wcd939x_codec_enable_hphl_pa()
812 if (!wcd939x->comp1_enable) in wcd939x_codec_enable_hphl_pa()
822 clear_bit(HPH_PA_DELAY, &wcd939x->status_mask); in wcd939x_codec_enable_hphl_pa()
831 enable_irq(wcd939x->hphl_pdm_wd_int); in wcd939x_codec_enable_hphl_pa()
834 disable_irq_nosync(wcd939x->hphl_pdm_wd_int); in wcd939x_codec_enable_hphl_pa()
836 * 7ms sleep is required if compander is enabled as per in wcd939x_codec_enable_hphl_pa()
838 * 20ms delay is required. in wcd939x_codec_enable_hphl_pa()
840 if (!wcd939x->comp1_enable) in wcd939x_codec_enable_hphl_pa()
848 wcd_mbhc_event_notify(wcd939x->wcd_mbhc, WCD_EVENT_PRE_HPHL_PA_OFF); in wcd939x_codec_enable_hphl_pa()
849 set_bit(HPH_PA_DELAY, &wcd939x->status_mask); in wcd939x_codec_enable_hphl_pa()
853 * 7ms sleep is required if compander is enabled as per in wcd939x_codec_enable_hphl_pa()
855 * 20ms delay is required. in wcd939x_codec_enable_hphl_pa()
857 if (test_bit(HPH_PA_DELAY, &wcd939x->status_mask)) { in wcd939x_codec_enable_hphl_pa()
858 if (!wcd939x->comp1_enable) in wcd939x_codec_enable_hphl_pa()
862 clear_bit(HPH_PA_DELAY, &wcd939x->status_mask); in wcd939x_codec_enable_hphl_pa()
864 wcd_mbhc_event_notify(wcd939x->wcd_mbhc, in wcd939x_codec_enable_hphl_pa()
870 wcd_clsh_ctrl_set_state(wcd939x->clsh_info, WCD_CLSH_EVENT_POST_PA, in wcd939x_codec_enable_hphl_pa()
872 if (wcd939x->ldoh) in wcd939x_codec_enable_hphl_pa()
884 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd939x_codec_enable_ear_pa()
899 /* 6 msec delay as per HW requirement */ in wcd939x_codec_enable_ear_pa()
901 enable_irq(wcd939x->ear_pdm_wd_int); in wcd939x_codec_enable_ear_pa()
904 disable_irq_nosync(wcd939x->ear_pdm_wd_int); in wcd939x_codec_enable_ear_pa()
910 /* 7 msec delay as per HW requirement */ in wcd939x_codec_enable_ear_pa()
914 wcd_clsh_ctrl_set_state(wcd939x->clsh_info, WCD_CLSH_EVENT_POST_PA, in wcd939x_codec_enable_ear_pa()
928 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd939x_codec_enable_dmic()
934 switch (w->shift) { in wcd939x_codec_enable_dmic()
968 dev_err(component->dev, "%s: Invalid DMIC Selection\n", __func__); in wcd939x_codec_enable_dmic()
969 return -EINVAL; in wcd939x_codec_enable_dmic()
978 if (w->shift == 2) in wcd939x_codec_enable_dmic()
997 if (w->shift == 2) in wcd939x_codec_enable_dmic()
1012 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd939x_tx_swr_ctrl()
1017 bank = wcd939x_swr_get_current_bank(wcd939x->sdw_priv[AIF1_CAP]->sdev); in wcd939x_tx_swr_ctrl()
1021 if (strnstr(w->name, "ADC", sizeof("ADC"))) { in wcd939x_tx_swr_ctrl()
1024 if (test_bit(WCD_ADC1, &wcd939x->status_mask)) in wcd939x_tx_swr_ctrl()
1025 mode |= tx_mode_bit[wcd939x->tx_mode[WCD_ADC1]]; in wcd939x_tx_swr_ctrl()
1026 if (test_bit(WCD_ADC2, &wcd939x->status_mask)) in wcd939x_tx_swr_ctrl()
1027 mode |= tx_mode_bit[wcd939x->tx_mode[WCD_ADC2]]; in wcd939x_tx_swr_ctrl()
1028 if (test_bit(WCD_ADC3, &wcd939x->status_mask)) in wcd939x_tx_swr_ctrl()
1029 mode |= tx_mode_bit[wcd939x->tx_mode[WCD_ADC3]]; in wcd939x_tx_swr_ctrl()
1030 if (test_bit(WCD_ADC4, &wcd939x->status_mask)) in wcd939x_tx_swr_ctrl()
1031 mode |= tx_mode_bit[wcd939x->tx_mode[WCD_ADC4]]; in wcd939x_tx_swr_ctrl()
1034 rate = wcd939x_get_clk_rate(ffs(mode) - 1); in wcd939x_tx_swr_ctrl()
1042 if (strnstr(w->name, "ADC", sizeof("ADC"))) { in wcd939x_tx_swr_ctrl()
1080 ret = -EINVAL; in wcd939x_get_adc_mode()
1089 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd939x_codec_enable_adc()
1099 set_bit(w->shift, &wcd939x->status_mask); in wcd939x_codec_enable_adc()
1108 clear_bit(w->shift, &wcd939x->status_mask); in wcd939x_codec_enable_adc()
1147 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd939x_adc_enable_req()
1158 wcd939x_tx_channel_config(component, w->shift, true); in wcd939x_adc_enable_req()
1159 mode = wcd939x_get_adc_mode(wcd939x->tx_mode[w->shift]); in wcd939x_adc_enable_req()
1161 dev_info(component->dev, "Invalid ADC mode\n"); in wcd939x_adc_enable_req()
1162 return -EINVAL; in wcd939x_adc_enable_req()
1165 switch (w->shift) { in wcd939x_adc_enable_req()
1210 wcd939x_tx_channel_config(component, w->shift, false); in wcd939x_adc_enable_req()
1213 switch (w->shift) { in wcd939x_adc_enable_req()
1267 int micb_index = micb_num - 1; in wcd939x_micbias_control()
1284 dev_err(component->dev, "%s: Invalid micbias number: %d\n", in wcd939x_micbias_control()
1286 return -EINVAL; in wcd939x_micbias_control()
1291 wcd939x->pullup_ref[micb_index]++; in wcd939x_micbias_control()
1292 if (wcd939x->pullup_ref[micb_index] == 1 && in wcd939x_micbias_control()
1293 wcd939x->micb_ref[micb_index] == 0) in wcd939x_micbias_control()
1299 if (wcd939x->pullup_ref[micb_index] > 0) in wcd939x_micbias_control()
1300 wcd939x->pullup_ref[micb_index]--; in wcd939x_micbias_control()
1301 if (wcd939x->pullup_ref[micb_index] == 0 && in wcd939x_micbias_control()
1302 wcd939x->micb_ref[micb_index] == 0) in wcd939x_micbias_control()
1308 wcd939x->micb_ref[micb_index]++; in wcd939x_micbias_control()
1309 if (wcd939x->micb_ref[micb_index] == 1) { in wcd939x_micbias_control()
1346 wcd_mbhc_event_notify(wcd939x->wcd_mbhc, in wcd939x_micbias_control()
1350 wcd_mbhc_event_notify(wcd939x->wcd_mbhc, in wcd939x_micbias_control()
1354 if (wcd939x->micb_ref[micb_index] > 0) in wcd939x_micbias_control()
1355 wcd939x->micb_ref[micb_index]--; in wcd939x_micbias_control()
1357 if (wcd939x->micb_ref[micb_index] == 0 && in wcd939x_micbias_control()
1358 wcd939x->pullup_ref[micb_index] > 0) in wcd939x_micbias_control()
1362 else if (wcd939x->micb_ref[micb_index] == 0 && in wcd939x_micbias_control()
1363 wcd939x->pullup_ref[micb_index] == 0) { in wcd939x_micbias_control()
1365 wcd_mbhc_event_notify(wcd939x->wcd_mbhc, in wcd939x_micbias_control()
1372 wcd_mbhc_event_notify(wcd939x->wcd_mbhc, in wcd939x_micbias_control()
1376 wcd_mbhc_event_notify(wcd939x->wcd_mbhc, in wcd939x_micbias_control()
1388 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd939x_codec_enable_micbias()
1389 int micb_num = w->shift; in wcd939x_codec_enable_micbias()
1396 /* 1 msec delay as per HW requirement */ in wcd939x_codec_enable_micbias()
1411 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd939x_codec_enable_micbias_pullup()
1412 int micb_num = w->shift; in wcd939x_codec_enable_micbias_pullup()
1420 /* 1 msec delay as per HW requirement */ in wcd939x_codec_enable_micbias_pullup()
1437 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in wcd939x_tx_mode_get()
1438 int path = e->shift_l; in wcd939x_tx_mode_get()
1440 ucontrol->value.enumerated.item[0] = wcd939x->tx_mode[path]; in wcd939x_tx_mode_get()
1450 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in wcd939x_tx_mode_put()
1451 int path = e->shift_l; in wcd939x_tx_mode_put()
1453 if (wcd939x->tx_mode[path] == ucontrol->value.enumerated.item[0]) in wcd939x_tx_mode_put()
1456 wcd939x->tx_mode[path] = ucontrol->value.enumerated.item[0]; in wcd939x_tx_mode_put()
1469 ucontrol->value.integer.value[0] = wcd939x->hph_mode; in wcd939x_rx_hph_mode_get()
1481 mode_val = ucontrol->value.enumerated.item[0]; in wcd939x_rx_hph_mode_put()
1483 if (mode_val == wcd939x->hph_mode) in wcd939x_rx_hph_mode_put()
1486 if (wcd939x->variant == WCD9390) { in wcd939x_rx_hph_mode_put()
1495 wcd939x->hph_mode = mode_val; in wcd939x_rx_hph_mode_put()
1509 wcd939x->hph_mode = mode_val; in wcd939x_rx_hph_mode_put()
1514 dev_dbg(component->dev, "%s: Invalid HPH Mode\n", __func__); in wcd939x_rx_hph_mode_put()
1515 return -EINVAL; in wcd939x_rx_hph_mode_put()
1521 struct soc_mixer_control *mc = (struct soc_mixer_control *)(kcontrol->private_value); in wcd939x_get_compander()
1525 if (mc->shift) in wcd939x_get_compander()
1526 ucontrol->value.integer.value[0] = wcd939x->comp2_enable ? 1 : 0; in wcd939x_get_compander()
1528 ucontrol->value.integer.value[0] = wcd939x->comp1_enable ? 1 : 0; in wcd939x_get_compander()
1536 struct soc_mixer_control *mc = (struct soc_mixer_control *)(kcontrol->private_value); in wcd939x_set_compander()
1539 struct wcd939x_sdw_priv *wcd = wcd939x->sdw_priv[AIF1_PB]; in wcd939x_set_compander()
1540 bool value = !!ucontrol->value.integer.value[0]; in wcd939x_set_compander()
1541 int portidx = wcd->ch_info[mc->reg].port_num; in wcd939x_set_compander()
1543 if (mc->shift) in wcd939x_set_compander()
1544 wcd939x->comp2_enable = value; in wcd939x_set_compander()
1546 wcd939x->comp1_enable = value; in wcd939x_set_compander()
1549 wcd939x_connect_port(wcd, portidx, mc->reg, true); in wcd939x_set_compander()
1551 wcd939x_connect_port(wcd, portidx, mc->reg, false); in wcd939x_set_compander()
1562 ucontrol->value.integer.value[0] = wcd939x->ldoh ? 1 : 0; in wcd939x_ldoh_get()
1573 if (wcd939x->ldoh == !!ucontrol->value.integer.value[0]) in wcd939x_ldoh_put()
1576 wcd939x->ldoh = !!ucontrol->value.integer.value[0]; in wcd939x_ldoh_put()
1790 struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; in wcd939x_get_swr_port()
1793 struct wcd939x_sdw_priv *wcd = wcd939x->sdw_priv[mixer->shift]; in wcd939x_get_swr_port()
1794 unsigned int portidx = wcd->ch_info[mixer->reg].port_num; in wcd939x_get_swr_port()
1796 ucontrol->value.integer.value[0] = wcd->port_enable[portidx] ? 1 : 0; in wcd939x_get_swr_port()
1817 struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; in wcd939x_set_swr_port()
1820 struct wcd939x_sdw_priv *wcd = wcd939x->sdw_priv[mixer->shift]; in wcd939x_set_swr_port()
1821 unsigned int portidx = wcd->ch_info[mixer->reg].port_num; in wcd939x_set_swr_port()
1823 wcd->port_enable[portidx] = !!ucontrol->value.integer.value[0]; in wcd939x_set_swr_port()
1825 wcd939x_connect_port(wcd, portidx, mixer->reg, wcd->port_enable[portidx]); in wcd939x_set_swr_port()
1853 dev_err(component->dev, "%s: invalid number of buttons: %d\n", in wcd939x_mbhc_program_btn_thr()
1862 dev_dbg(component->dev, "%s: btn_high[%d]: %d, vth: %d\n", in wcd939x_mbhc_program_btn_thr()
1884 /* Default pull up current to 2uA */ in wcd939x_mbhc_hph_l_pull_up_control()
1890 dev_dbg(component->dev, "%s: HS pull up current:%d\n", in wcd939x_mbhc_hph_l_pull_up_control()
1924 return -EINVAL; in wcd939x_get_micb_vout_ctl_val()
1927 return (micb_mv - 1000) / 50; in wcd939x_get_micb_vout_ctl_val()
1952 return -EINVAL; in wcd939x_mbhc_micb_adjust_voltage()
1954 mutex_lock(&wcd939x->micb_lock); in wcd939x_mbhc_micb_adjust_voltage()
1957 * If requested micbias voltage is same as current micbias in wcd939x_mbhc_micb_adjust_voltage()
1960 * to avoid slow micbias ramp-up or down enable pull-up in wcd939x_mbhc_micb_adjust_voltage()
1961 * momentarily, change the micbias value and then re-enable in wcd939x_mbhc_micb_adjust_voltage()
1980 dev_dbg(component->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n", in wcd939x_mbhc_micb_adjust_voltage()
1997 * Add 2ms delay as per HW requirement after enabling in wcd939x_mbhc_micb_adjust_voltage()
2004 mutex_unlock(&wcd939x->micb_lock); in wcd939x_mbhc_micb_adjust_voltage()
2015 return -EINVAL; in wcd939x_mbhc_micb_ctrl_threshold_mic()
2021 if (wcd939x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV) in wcd939x_mbhc_micb_ctrl_threshold_mic()
2024 micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd939x->micb2_mv; in wcd939x_mbhc_micb_ctrl_threshold_mic()
2073 /* If ramp is not complete, give additional 5ms */ in wcd939x_mbhc_get_result_params()
2078 dev_dbg(component->dev, in wcd939x_mbhc_get_result_params()
2079 "%s: Impedance detect ramp error, c1=%d, x1=0x%x\n", in wcd939x_mbhc_get_result_params()
2085 denom = (x1 * d1) - (1 << (14 - zdet_param->noff)); in wcd939x_mbhc_get_result_params()
2088 else if (x1 < wcd939x_mbhc_mincode_param[zdet_param->noff]) in wcd939x_mbhc_get_result_params()
2091 dev_dbg(component->dev, "%s: d1=%d, c1=%d, x1=0x%x, z_val=%d(milliOhm)\n", in wcd939x_mbhc_get_result_params()
2114 WCD939X_ZDET_ANA_CTL_MAXV_CTL, zdet_param->ldo_ctl); in wcd939x_mbhc_zdet_ramp()
2116 zdet_param->btn5); in wcd939x_mbhc_zdet_ramp()
2118 zdet_param->btn6); in wcd939x_mbhc_zdet_ramp()
2120 zdet_param->btn7); in wcd939x_mbhc_zdet_ramp()
2122 WCD939X_ZDET_ANA_CTL_RANGE_CTL, zdet_param->noff); in wcd939x_mbhc_zdet_ramp()
2124 WCD939X_ZDET_RAMP_CTL_TIME_CTL, zdet_param->nshift); in wcd939x_mbhc_zdet_ramp()
2134 dev_dbg(component->dev, "%s: ramp for HPH_L, noff = %d\n", in wcd939x_mbhc_zdet_ramp()
2135 __func__, zdet_param->noff); in wcd939x_mbhc_zdet_ramp()
2149 dev_dbg(component->dev, "%s: ramp for HPH_R, noff = %d\n", in wcd939x_mbhc_zdet_ramp()
2150 __func__, zdet_param->noff); in wcd939x_mbhc_zdet_ramp()
2166 q1_cal = (10000 - ((q1 & GENMASK(6, 0)) * 10)); in wcd939x_wcd_mbhc_qfuse_cal()
2177 struct wcd939x_priv *wcd939x = dev_get_drvdata(component->dev); in wcd939x_wcd_mbhc_calc_impedance()
2196 /* For NO-jack, disable L_DET_EN before Z-det measurements */ in wcd939x_wcd_mbhc_calc_impedance()
2197 if (wcd939x->mbhc_cfg.hphl_swh) in wcd939x_wcd_mbhc_calc_impedance()
2215 /* 1ms delay needed after disable surge protection */ in wcd939x_wcd_mbhc_calc_impedance()
2226 dev_dbg(component->dev, "%s: impedance on HPH_L = %d(ohms)\n", in wcd939x_wcd_mbhc_calc_impedance()
2229 /* Start of right impedance ramp and calculation */ in wcd939x_wcd_mbhc_calc_impedance()
2237 dev_dbg(component->dev, "%s: impedance on HPH_R = %d(ohms)\n", in wcd939x_wcd_mbhc_calc_impedance()
2243 dev_dbg(component->dev, in wcd939x_wcd_mbhc_calc_impedance()
2253 dev_dbg(component->dev, in wcd939x_wcd_mbhc_calc_impedance()
2256 wcd_mbhc_set_hph_type(wcd939x->wcd_mbhc, WCD_MBHC_HPH_MONO); in wcd939x_wcd_mbhc_calc_impedance()
2275 z_diff1 = z1ls > z_mono ? z1ls - z_mono : z_mono - z1ls; in wcd939x_wcd_mbhc_calc_impedance()
2276 z_diff2 = *zl > z1ls ? *zl - z1ls : z1ls - *zl; in wcd939x_wcd_mbhc_calc_impedance()
2278 dev_dbg(component->dev, "%s: stereo plug type detected\n", in wcd939x_wcd_mbhc_calc_impedance()
2280 wcd_mbhc_set_hph_type(wcd939x->wcd_mbhc, WCD_MBHC_HPH_STEREO); in wcd939x_wcd_mbhc_calc_impedance()
2282 dev_dbg(component->dev, "%s: MONO plug type detected\n", in wcd939x_wcd_mbhc_calc_impedance()
2284 wcd_mbhc_set_hph_type(wcd939x->wcd_mbhc, WCD_MBHC_HPH_MONO); in wcd939x_wcd_mbhc_calc_impedance()
2302 /* For NO-jack, re-enable L_DET_EN after Z-det measurements */ in wcd939x_wcd_mbhc_calc_impedance()
2303 if (wcd939x->mbhc_cfg.hphl_swh) in wcd939x_wcd_mbhc_calc_impedance()
2346 if (wcd939x->mbhc_cfg.moist_rref == R_OFF || wcd939x->typec_analog_mux) { in wcd939x_mbhc_moisture_config()
2353 if (!wcd939x->mbhc_cfg.hphl_swh) { in wcd939x_mbhc_moisture_config()
2354 dev_dbg(component->dev, "%s: disable moisture detection for NC\n", in wcd939x_mbhc_moisture_config()
2362 WCD939X_CTL_2_M_RTH_CTL, wcd939x->mbhc_cfg.moist_rref); in wcd939x_mbhc_moisture_config()
2372 wcd939x->mbhc_cfg.moist_rref); in wcd939x_mbhc_moisture_detect_en()
2383 if (wcd939x->mbhc_cfg.moist_rref == R_OFF || wcd939x->typec_analog_mux) { in wcd939x_mbhc_get_moisture_status()
2390 if (!wcd939x->mbhc_cfg.hphl_swh) { in wcd939x_mbhc_get_moisture_status()
2391 dev_dbg(component->dev, "%s: disable moisture detection for NC\n", in wcd939x_mbhc_get_moisture_status()
2448 ucontrol->value.integer.value[0] = wcd_mbhc_get_hph_type(wcd939x->wcd_mbhc); in wcd939x_get_hph_type()
2456 struct soc_mixer_control *mc = (struct soc_mixer_control *)(kcontrol->private_value); in wcd939x_hph_impedance_get()
2459 bool hphr = mc->shift; in wcd939x_hph_impedance_get()
2462 wcd_mbhc_get_impedance(wcd939x->wcd_mbhc, &zl, &zr); in wcd939x_hph_impedance_get()
2463 dev_dbg(component->dev, "%s: zl=%u(ohms), zr=%u(ohms)\n", __func__, zl, zr); in wcd939x_hph_impedance_get()
2464 ucontrol->value.integer.value[0] = hphr ? zr : zl; in wcd939x_hph_impedance_get()
2484 struct wcd_mbhc_intr *intr_ids = &wcd939x->intr_ids; in wcd939x_mbhc_init()
2486 intr_ids->mbhc_sw_intr = regmap_irq_get_virq(wcd939x->irq_chip, in wcd939x_mbhc_init()
2488 intr_ids->mbhc_btn_press_intr = regmap_irq_get_virq(wcd939x->irq_chip, in wcd939x_mbhc_init()
2490 intr_ids->mbhc_btn_release_intr = regmap_irq_get_virq(wcd939x->irq_chip, in wcd939x_mbhc_init()
2492 intr_ids->mbhc_hs_ins_intr = regmap_irq_get_virq(wcd939x->irq_chip, in wcd939x_mbhc_init()
2494 intr_ids->mbhc_hs_rem_intr = regmap_irq_get_virq(wcd939x->irq_chip, in wcd939x_mbhc_init()
2496 intr_ids->hph_left_ocp = regmap_irq_get_virq(wcd939x->irq_chip, in wcd939x_mbhc_init()
2498 intr_ids->hph_right_ocp = regmap_irq_get_virq(wcd939x->irq_chip, in wcd939x_mbhc_init()
2501 wcd939x->wcd_mbhc = wcd_mbhc_init(component, &mbhc_cb, intr_ids, wcd_mbhc_fields, true); in wcd939x_mbhc_init()
2502 if (IS_ERR(wcd939x->wcd_mbhc)) in wcd939x_mbhc_init()
2503 return PTR_ERR(wcd939x->wcd_mbhc); in wcd939x_mbhc_init()
2517 wcd_mbhc_deinit(wcd939x->wcd_mbhc); in wcd939x_mbhc_deinit()
2900 vout_ctl_1 = wcd939x_get_micb_vout_ctl_val(wcd939x->micb1_mv); in wcd939x_set_micbias_data()
2901 vout_ctl_2 = wcd939x_get_micb_vout_ctl_val(wcd939x->micb2_mv); in wcd939x_set_micbias_data()
2902 vout_ctl_3 = wcd939x_get_micb_vout_ctl_val(wcd939x->micb3_mv); in wcd939x_set_micbias_data()
2903 vout_ctl_4 = wcd939x_get_micb_vout_ctl_val(wcd939x->micb4_mv); in wcd939x_set_micbias_data()
2905 return -EINVAL; in wcd939x_set_micbias_data()
2907 regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB1, in wcd939x_set_micbias_data()
2909 regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB2, in wcd939x_set_micbias_data()
2911 regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB3, in wcd939x_set_micbias_data()
2913 regmap_update_bits(wcd939x->regmap, WCD939X_ANA_MICB4, in wcd939x_set_micbias_data()
2954 * \-handle_nested_irq(0)
2955 * \- regmap_irq_thread()
2956 * \- handle_nested_irq(i)
2978 wcd->virq = irq_domain_add_linear(NULL, 1, &wcd_domain_ops, NULL); in wcd939x_irq_init()
2979 if (!(wcd->virq)) { in wcd939x_irq_init()
2981 return -EINVAL; in wcd939x_irq_init()
2984 return devm_regmap_add_irq_chip(dev, wcd->regmap, in wcd939x_irq_init()
2985 irq_create_mapping(wcd->virq, 0), in wcd939x_irq_init()
2987 &wcd->irq_chip); in wcd939x_irq_init()
2993 struct sdw_slave *tx_sdw_dev = wcd939x->tx_sdw_dev; in wcd939x_soc_codec_probe()
2994 struct device *dev = component->dev; in wcd939x_soc_codec_probe()
2998 time_left = wait_for_completion_timeout(&tx_sdw_dev->initialization_complete, in wcd939x_soc_codec_probe()
3002 return -ETIMEDOUT; in wcd939x_soc_codec_probe()
3005 snd_soc_component_init_regmap(component, wcd939x->regmap); in wcd939x_soc_codec_probe()
3011 wcd939x->variant = snd_soc_component_read_field(component, in wcd939x_soc_codec_probe()
3015 wcd939x->clsh_info = wcd_clsh_ctrl_alloc(component, WCD939X); in wcd939x_soc_codec_probe()
3016 if (IS_ERR(wcd939x->clsh_info)) { in wcd939x_soc_codec_probe()
3018 return PTR_ERR(wcd939x->clsh_info); in wcd939x_soc_codec_probe()
3025 regmap_write(wcd939x->regmap, in wcd939x_soc_codec_probe()
3031 wcd939x->hphr_pdm_wd_int = regmap_irq_get_virq(wcd939x->irq_chip, in wcd939x_soc_codec_probe()
3033 wcd939x->hphl_pdm_wd_int = regmap_irq_get_virq(wcd939x->irq_chip, in wcd939x_soc_codec_probe()
3035 wcd939x->ear_pdm_wd_int = regmap_irq_get_virq(wcd939x->irq_chip, in wcd939x_soc_codec_probe()
3038 ret = request_threaded_irq(wcd939x->hphr_pdm_wd_int, NULL, wcd939x_wd_handle_irq, in wcd939x_soc_codec_probe()
3046 ret = request_threaded_irq(wcd939x->hphl_pdm_wd_int, NULL, wcd939x_wd_handle_irq, in wcd939x_soc_codec_probe()
3054 ret = request_threaded_irq(wcd939x->ear_pdm_wd_int, NULL, wcd939x_wd_handle_irq, in wcd939x_soc_codec_probe()
3063 disable_irq_nosync(wcd939x->hphr_pdm_wd_int); in wcd939x_soc_codec_probe()
3064 disable_irq_nosync(wcd939x->hphl_pdm_wd_int); in wcd939x_soc_codec_probe()
3065 disable_irq_nosync(wcd939x->ear_pdm_wd_int); in wcd939x_soc_codec_probe()
3067 switch (wcd939x->variant) { in wcd939x_soc_codec_probe()
3072 dev_err(component->dev, in wcd939x_soc_codec_probe()
3074 __func__, wcd939x->variant); in wcd939x_soc_codec_probe()
3082 dev_err(component->dev, in wcd939x_soc_codec_probe()
3084 __func__, wcd939x->variant); in wcd939x_soc_codec_probe()
3094 dev_err(component->dev, "mbhc initialization failed\n"); in wcd939x_soc_codec_probe()
3101 free_irq(wcd939x->ear_pdm_wd_int, wcd939x); in wcd939x_soc_codec_probe()
3103 free_irq(wcd939x->hphl_pdm_wd_int, wcd939x); in wcd939x_soc_codec_probe()
3105 free_irq(wcd939x->hphr_pdm_wd_int, wcd939x); in wcd939x_soc_codec_probe()
3107 wcd_clsh_ctrl_free(wcd939x->clsh_info); in wcd939x_soc_codec_probe()
3118 free_irq(wcd939x->ear_pdm_wd_int, wcd939x); in wcd939x_soc_codec_remove()
3119 free_irq(wcd939x->hphl_pdm_wd_int, wcd939x); in wcd939x_soc_codec_remove()
3120 free_irq(wcd939x->hphr_pdm_wd_int, wcd939x); in wcd939x_soc_codec_remove()
3122 wcd_clsh_ctrl_free(wcd939x->clsh_info); in wcd939x_soc_codec_remove()
3128 struct wcd939x_priv *wcd = dev_get_drvdata(comp->dev); in wcd939x_codec_set_jack()
3131 return wcd_mbhc_start(wcd->wcd_mbhc, &wcd->mbhc_cfg, jack); in wcd939x_codec_set_jack()
3133 wcd_mbhc_stop(wcd->wcd_mbhc); in wcd939x_codec_set_jack()
3153 /* Get USB-C plug orientation to provide swap event for MBHC */
3159 wcd939x->typec_orientation = orientation; in wcd939x_typec_switch_set()
3168 unsigned int previous_mode = wcd939x->typec_mode; in wcd939x_typec_mux_set()
3170 if (!wcd939x->wcd_mbhc) in wcd939x_typec_mux_set()
3171 return -EINVAL; in wcd939x_typec_mux_set()
3173 if (wcd939x->typec_mode != state->mode) { in wcd939x_typec_mux_set()
3174 wcd939x->typec_mode = state->mode; in wcd939x_typec_mux_set()
3176 if (wcd939x->typec_mode == TYPEC_MODE_AUDIO) in wcd939x_typec_mux_set()
3177 return wcd_mbhc_typec_report_plug(wcd939x->wcd_mbhc); in wcd939x_typec_mux_set()
3179 return wcd_mbhc_typec_report_unplug(wcd939x->wcd_mbhc); in wcd939x_typec_mux_set()
3188 struct device_node *np = dev->of_node; in wcd939x_dt_parse_micbias_info()
3192 rc = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val); in wcd939x_dt_parse_micbias_info()
3194 wcd->micb1_mv = prop_val / 1000; in wcd939x_dt_parse_micbias_info()
3198 rc = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val); in wcd939x_dt_parse_micbias_info()
3200 wcd->micb2_mv = prop_val / 1000; in wcd939x_dt_parse_micbias_info()
3204 rc = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val); in wcd939x_dt_parse_micbias_info()
3206 wcd->micb3_mv = prop_val / 1000; in wcd939x_dt_parse_micbias_info()
3210 rc = of_property_read_u32(np, "qcom,micbias4-microvolt", &prop_val); in wcd939x_dt_parse_micbias_info()
3212 wcd->micb4_mv = prop_val / 1000; in wcd939x_dt_parse_micbias_info()
3222 if (!wcd939x->typec_analog_mux || !wcd939x->typec_switch) in wcd939x_swap_gnd_mic()
3226 typec_switch_set(wcd939x->typec_switch, in wcd939x_swap_gnd_mic()
3227 wcd939x->typec_orientation == TYPEC_ORIENTATION_REVERSE ? in wcd939x_swap_gnd_mic()
3236 struct wcd_mbhc_config *cfg = &wcd939x->mbhc_cfg; in wcd939x_populate_dt_data()
3242 wcd939x->reset_gpio = of_get_named_gpio(dev->of_node, "reset-gpios", 0); in wcd939x_populate_dt_data()
3243 if (wcd939x->reset_gpio < 0) in wcd939x_populate_dt_data()
3244 return dev_err_probe(dev, wcd939x->reset_gpio, in wcd939x_populate_dt_data()
3247 wcd939x->supplies[0].supply = "vdd-rxtx"; in wcd939x_populate_dt_data()
3248 wcd939x->supplies[1].supply = "vdd-io"; in wcd939x_populate_dt_data()
3249 wcd939x->supplies[2].supply = "vdd-buck"; in wcd939x_populate_dt_data()
3250 wcd939x->supplies[3].supply = "vdd-mic-bias"; in wcd939x_populate_dt_data()
3252 ret = regulator_bulk_get(dev, WCD939X_MAX_SUPPLY, wcd939x->supplies); in wcd939x_populate_dt_data()
3256 ret = regulator_bulk_enable(WCD939X_MAX_SUPPLY, wcd939x->supplies); in wcd939x_populate_dt_data()
3258 regulator_bulk_free(WCD939X_MAX_SUPPLY, wcd939x->supplies); in wcd939x_populate_dt_data()
3264 cfg->mbhc_micbias = MIC_BIAS_2; in wcd939x_populate_dt_data()
3265 cfg->anc_micbias = MIC_BIAS_2; in wcd939x_populate_dt_data()
3266 cfg->v_hs_max = WCD_MBHC_HS_V_MAX; in wcd939x_populate_dt_data()
3267 cfg->num_btn = WCD939X_MBHC_MAX_BUTTONS; in wcd939x_populate_dt_data()
3268 cfg->micb_mv = wcd939x->micb2_mv; in wcd939x_populate_dt_data()
3269 cfg->linein_th = 5000; in wcd939x_populate_dt_data()
3270 cfg->hs_thr = 1700; in wcd939x_populate_dt_data()
3271 cfg->hph_thr = 50; in wcd939x_populate_dt_data()
3280 np = of_graph_get_remote_node(dev->of_node, 0, 0); in wcd939x_populate_dt_data()
3282 wcd939x->typec_analog_mux = true; in wcd939x_populate_dt_data()
3283 cfg->typec_analog_mux = true; in wcd939x_populate_dt_data()
3284 cfg->swap_gnd_mic = wcd939x_swap_gnd_mic; in wcd939x_populate_dt_data()
3293 gpio_direction_output(wcd939x->reset_gpio, 0); in wcd939x_reset()
3296 gpio_set_value(wcd939x->reset_gpio, 1); in wcd939x_reset()
3307 struct wcd939x_priv *wcd939x = dev_get_drvdata(dai->dev); in wcd939x_codec_hw_params()
3308 struct wcd939x_sdw_priv *wcd = wcd939x->sdw_priv[dai->id]; in wcd939x_codec_hw_params()
3316 struct wcd939x_priv *wcd939x = dev_get_drvdata(dai->dev); in wcd939x_codec_free()
3317 struct wcd939x_sdw_priv *wcd = wcd939x->sdw_priv[dai->id]; in wcd939x_codec_free()
3325 struct wcd939x_priv *wcd939x = dev_get_drvdata(dai->dev); in wcd939x_codec_set_sdw_stream()
3326 struct wcd939x_sdw_priv *wcd = wcd939x->sdw_priv[dai->id]; in wcd939x_codec_set_sdw_stream()
3339 .name = "wcd939x-sdw-rx",
3352 .name = "wcd939x-sdw-tx",
3374 * Get USBSS type-c switch to send gnd/mic swap events in wcd939x_bind()
3378 if (wcd939x->typec_analog_mux) { in wcd939x_bind()
3379 wcd939x->typec_switch = fwnode_typec_switch_get(dev->fwnode); in wcd939x_bind()
3380 if (IS_ERR(wcd939x->typec_switch)) in wcd939x_bind()
3381 return dev_err_probe(dev, PTR_ERR(wcd939x->typec_switch), in wcd939x_bind()
3382 "failed to acquire orientation-switch\n"); in wcd939x_bind()
3393 wcd939x->rxdev = wcd939x_sdw_device_get(wcd939x->rxnode); in wcd939x_bind()
3394 if (!wcd939x->rxdev) { in wcd939x_bind()
3396 ret = -EINVAL; in wcd939x_bind()
3399 wcd939x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd939x->rxdev); in wcd939x_bind()
3400 wcd939x->sdw_priv[AIF1_PB]->wcd939x = wcd939x; in wcd939x_bind()
3402 wcd939x->txdev = wcd939x_sdw_device_get(wcd939x->txnode); in wcd939x_bind()
3403 if (!wcd939x->txdev) { in wcd939x_bind()
3405 ret = -EINVAL; in wcd939x_bind()
3408 wcd939x->sdw_priv[AIF1_CAP] = dev_get_drvdata(wcd939x->txdev); in wcd939x_bind()
3409 wcd939x->sdw_priv[AIF1_CAP]->wcd939x = wcd939x; in wcd939x_bind()
3410 wcd939x->tx_sdw_dev = dev_to_sdw_dev(wcd939x->txdev); in wcd939x_bind()
3416 if (!device_link_add(wcd939x->rxdev, wcd939x->txdev, DL_FLAG_STATELESS | in wcd939x_bind()
3419 ret = -EINVAL; in wcd939x_bind()
3423 if (!device_link_add(dev, wcd939x->txdev, DL_FLAG_STATELESS | in wcd939x_bind()
3426 ret = -EINVAL; in wcd939x_bind()
3430 if (!device_link_add(dev, wcd939x->rxdev, DL_FLAG_STATELESS | in wcd939x_bind()
3433 ret = -EINVAL; in wcd939x_bind()
3438 wcd939x->regmap = wcd939x_swr_get_regmap(wcd939x->sdw_priv[AIF1_CAP]); in wcd939x_bind()
3439 if (IS_ERR(wcd939x->regmap)) { in wcd939x_bind()
3441 ret = PTR_ERR(wcd939x->regmap); in wcd939x_bind()
3451 wcd939x->sdw_priv[AIF1_PB]->slave_irq = wcd939x->virq; in wcd939x_bind()
3452 wcd939x->sdw_priv[AIF1_CAP]->slave_irq = wcd939x->virq; in wcd939x_bind()
3461 regmap_read(wcd939x->regmap, WCD939X_DIGITAL_CHIP_ID1, &id1); in wcd939x_bind()
3462 regmap_read(wcd939x->regmap, WCD939X_EAR_STATUS_REG_1, &status1); in wcd939x_bind()
3482 device_link_remove(dev, wcd939x->rxdev); in wcd939x_bind()
3484 device_link_remove(dev, wcd939x->txdev); in wcd939x_bind()
3486 device_link_remove(wcd939x->rxdev, wcd939x->txdev); in wcd939x_bind()
3488 put_device(wcd939x->txdev); in wcd939x_bind()
3490 put_device(wcd939x->rxdev); in wcd939x_bind()
3495 if (wcd939x->typec_analog_mux) in wcd939x_bind()
3496 typec_switch_put(wcd939x->typec_switch); in wcd939x_bind()
3507 device_link_remove(dev, wcd939x->txdev); in wcd939x_unbind()
3508 device_link_remove(dev, wcd939x->rxdev); in wcd939x_unbind()
3509 device_link_remove(wcd939x->rxdev, wcd939x->txdev); in wcd939x_unbind()
3510 put_device(wcd939x->txdev); in wcd939x_unbind()
3511 put_device(wcd939x->rxdev); in wcd939x_unbind()
3555 if (!wcd939x->typec_analog_mux) in wcd939x_add_typec()
3586 struct device_node *np = dev->of_node; in wcd939x_add_slave_components()
3588 wcd939x->rxnode = of_parse_phandle(np, "qcom,rx-device", 0); in wcd939x_add_slave_components()
3589 if (!wcd939x->rxnode) { in wcd939x_add_slave_components()
3590 dev_err(dev, "%s: Rx-device node not defined\n", __func__); in wcd939x_add_slave_components()
3591 return -ENODEV; in wcd939x_add_slave_components()
3594 of_node_get(wcd939x->rxnode); in wcd939x_add_slave_components()
3596 component_compare_of, wcd939x->rxnode); in wcd939x_add_slave_components()
3598 wcd939x->txnode = of_parse_phandle(np, "qcom,tx-device", 0); in wcd939x_add_slave_components()
3599 if (!wcd939x->txnode) { in wcd939x_add_slave_components()
3600 dev_err(dev, "%s: Tx-device node not defined\n", __func__); in wcd939x_add_slave_components()
3601 return -ENODEV; in wcd939x_add_slave_components()
3603 of_node_get(wcd939x->txnode); in wcd939x_add_slave_components()
3605 component_compare_of, wcd939x->txnode); in wcd939x_add_slave_components()
3613 struct device *dev = &pdev->dev; in wcd939x_probe()
3619 return -ENOMEM; in wcd939x_probe()
3622 mutex_init(&wcd939x->micb_lock); in wcd939x_probe()
3627 return -EINVAL; in wcd939x_probe()
3654 regulator_bulk_disable(WCD939X_MAX_SUPPLY, wcd939x->supplies); in wcd939x_probe()
3655 regulator_bulk_free(WCD939X_MAX_SUPPLY, wcd939x->supplies); in wcd939x_probe()
3662 struct device *dev = &pdev->dev; in wcd939x_remove()
3671 regulator_bulk_disable(WCD939X_MAX_SUPPLY, wcd939x->supplies); in wcd939x_remove()
3672 regulator_bulk_free(WCD939X_MAX_SUPPLY, wcd939x->supplies); in wcd939x_remove()
3677 { .compatible = "qcom,wcd9390-codec" },
3678 { .compatible = "qcom,wcd9395-codec" },