Lines Matching +full:micbias1 +full:- +full:microvolt

1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
21 #include <sound/soc-dapm.h>
24 #include "wcd-clsh-v2.h"
25 #include "wcd-mbhc-v2.h"
212 static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(ear_pa_gain, 600, -1800);
213 static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(line_gain, 600, -3000);
1364 struct regmap *rm = wcd938x->regmap; in wcd938x_io_init()
1423 port_num = ch_info->port_num; in wcd938x_sdw_connect_port()
1424 ch_mask = ch_info->ch_mask; in wcd938x_sdw_connect_port()
1426 port_config->num = port_num; in wcd938x_sdw_connect_port()
1429 port_config->ch_mask |= ch_mask; in wcd938x_sdw_connect_port()
1431 port_config->ch_mask &= ~ch_mask; in wcd938x_sdw_connect_port()
1438 return wcd938x_sdw_connect_port(&wcd->ch_info[ch_id], in wcd938x_connect_port()
1439 &wcd->port_config[port_num - 1], in wcd938x_connect_port()
1447 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_codec_enable_rxclk()
1486 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_codec_hphl_dac_event()
1505 if (wcd938x->comp1_enable) { in wcd938x_codec_hphl_dac_event()
1510 if (!wcd938x->comp2_enable || (snd_soc_component_read(component, in wcd938x_codec_hphl_dac_event()
1540 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_codec_hphr_dac_event()
1559 if (wcd938x->comp2_enable) { in wcd938x_codec_hphr_dac_event()
1564 if (!wcd938x->comp1_enable || in wcd938x_codec_hphr_dac_event()
1594 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_codec_ear_dac_event()
1599 wcd938x->ear_rx_path = in wcd938x_codec_ear_dac_event()
1602 if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) { in wcd938x_codec_ear_dac_event()
1622 if (wcd938x->comp1_enable) in wcd938x_codec_ear_dac_event()
1629 if (wcd938x->flyback_cur_det_disable == 0) in wcd938x_codec_ear_dac_event()
1632 wcd938x->flyback_cur_det_disable++; in wcd938x_codec_ear_dac_event()
1633 wcd_clsh_ctrl_set_state(wcd938x->clsh_info, in wcd938x_codec_ear_dac_event()
1636 wcd938x->hph_mode); in wcd938x_codec_ear_dac_event()
1639 if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) { in wcd938x_codec_ear_dac_event()
1653 if (wcd938x->comp1_enable) in wcd938x_codec_ear_dac_event()
1673 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_codec_aux_dac_event()
1687 if (wcd938x->flyback_cur_det_disable == 0) in wcd938x_codec_aux_dac_event()
1690 wcd938x->flyback_cur_det_disable++; in wcd938x_codec_aux_dac_event()
1691 wcd_clsh_ctrl_set_state(wcd938x->clsh_info, in wcd938x_codec_aux_dac_event()
1694 wcd938x->hph_mode); in wcd938x_codec_aux_dac_event()
1709 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_codec_enable_hphr_pa()
1711 int hph_mode = wcd938x->hph_mode; in wcd938x_codec_enable_hphr_pa()
1715 if (wcd938x->ldoh) in wcd938x_codec_enable_hphr_pa()
1718 wcd_clsh_ctrl_set_state(wcd938x->clsh_info, WCD_CLSH_EVENT_PRE_DAC, in wcd938x_codec_enable_hphr_pa()
1720 wcd_clsh_set_hph_mode(wcd938x->clsh_info, CLS_H_HIFI); in wcd938x_codec_enable_hphr_pa()
1730 wcd_clsh_set_hph_mode(wcd938x->clsh_info, hph_mode); in wcd938x_codec_enable_hphr_pa()
1733 set_bit(HPH_PA_DELAY, &wcd938x->status_mask); in wcd938x_codec_enable_hphr_pa()
1744 if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) { in wcd938x_codec_enable_hphr_pa()
1745 if (!wcd938x->comp2_enable) in wcd938x_codec_enable_hphr_pa()
1755 clear_bit(HPH_PA_DELAY, &wcd938x->status_mask); in wcd938x_codec_enable_hphr_pa()
1764 enable_irq(wcd938x->hphr_pdm_wd_int); in wcd938x_codec_enable_hphr_pa()
1767 disable_irq_nosync(wcd938x->hphr_pdm_wd_int); in wcd938x_codec_enable_hphr_pa()
1773 if (!wcd938x->comp2_enable) in wcd938x_codec_enable_hphr_pa()
1779 wcd_mbhc_event_notify(wcd938x->wcd_mbhc, in wcd938x_codec_enable_hphr_pa()
1781 set_bit(HPH_PA_DELAY, &wcd938x->status_mask); in wcd938x_codec_enable_hphr_pa()
1789 if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) { in wcd938x_codec_enable_hphr_pa()
1790 if (!wcd938x->comp2_enable) in wcd938x_codec_enable_hphr_pa()
1794 clear_bit(HPH_PA_DELAY, &wcd938x->status_mask); in wcd938x_codec_enable_hphr_pa()
1796 wcd_mbhc_event_notify(wcd938x->wcd_mbhc, in wcd938x_codec_enable_hphr_pa()
1802 wcd_clsh_ctrl_set_state(wcd938x->clsh_info, WCD_CLSH_EVENT_POST_PA, in wcd938x_codec_enable_hphr_pa()
1804 if (wcd938x->ldoh) in wcd938x_codec_enable_hphr_pa()
1816 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_codec_enable_hphl_pa()
1818 int hph_mode = wcd938x->hph_mode; in wcd938x_codec_enable_hphl_pa()
1822 if (wcd938x->ldoh) in wcd938x_codec_enable_hphl_pa()
1825 wcd_clsh_ctrl_set_state(wcd938x->clsh_info, WCD_CLSH_EVENT_PRE_DAC, in wcd938x_codec_enable_hphl_pa()
1827 wcd_clsh_set_hph_mode(wcd938x->clsh_info, CLS_H_HIFI); in wcd938x_codec_enable_hphl_pa()
1836 wcd_clsh_set_hph_mode(wcd938x->clsh_info, hph_mode); in wcd938x_codec_enable_hphl_pa()
1839 set_bit(HPH_PA_DELAY, &wcd938x->status_mask); in wcd938x_codec_enable_hphl_pa()
1850 if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) { in wcd938x_codec_enable_hphl_pa()
1851 if (!wcd938x->comp1_enable) in wcd938x_codec_enable_hphl_pa()
1860 clear_bit(HPH_PA_DELAY, &wcd938x->status_mask); in wcd938x_codec_enable_hphl_pa()
1870 enable_irq(wcd938x->hphl_pdm_wd_int); in wcd938x_codec_enable_hphl_pa()
1873 disable_irq_nosync(wcd938x->hphl_pdm_wd_int); in wcd938x_codec_enable_hphl_pa()
1879 if (!wcd938x->comp1_enable) in wcd938x_codec_enable_hphl_pa()
1885 wcd_mbhc_event_notify(wcd938x->wcd_mbhc, WCD_EVENT_PRE_HPHL_PA_OFF); in wcd938x_codec_enable_hphl_pa()
1886 set_bit(HPH_PA_DELAY, &wcd938x->status_mask); in wcd938x_codec_enable_hphl_pa()
1894 if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) { in wcd938x_codec_enable_hphl_pa()
1895 if (!wcd938x->comp1_enable) in wcd938x_codec_enable_hphl_pa()
1899 clear_bit(HPH_PA_DELAY, &wcd938x->status_mask); in wcd938x_codec_enable_hphl_pa()
1901 wcd_mbhc_event_notify(wcd938x->wcd_mbhc, in wcd938x_codec_enable_hphl_pa()
1907 wcd_clsh_ctrl_set_state(wcd938x->clsh_info, WCD_CLSH_EVENT_POST_PA, in wcd938x_codec_enable_hphl_pa()
1909 if (wcd938x->ldoh) in wcd938x_codec_enable_hphl_pa()
1921 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_codec_enable_aux_pa()
1923 int hph_mode = wcd938x->hph_mode; in wcd938x_codec_enable_aux_pa()
1938 enable_irq(wcd938x->aux_pdm_wd_int); in wcd938x_codec_enable_aux_pa()
1941 disable_irq_nosync(wcd938x->aux_pdm_wd_int); in wcd938x_codec_enable_aux_pa()
1948 wcd_clsh_ctrl_set_state(wcd938x->clsh_info, in wcd938x_codec_enable_aux_pa()
1953 wcd938x->flyback_cur_det_disable--; in wcd938x_codec_enable_aux_pa()
1954 if (wcd938x->flyback_cur_det_disable == 0) in wcd938x_codec_enable_aux_pa()
1965 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_codec_enable_ear_pa()
1967 int hph_mode = wcd938x->hph_mode; in wcd938x_codec_enable_ear_pa()
1975 wcd938x->ear_rx_path = snd_soc_component_read(component, in wcd938x_codec_enable_ear_pa()
1977 if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) in wcd938x_codec_enable_ear_pa()
1984 if (!wcd938x->comp1_enable) in wcd938x_codec_enable_ear_pa()
1998 if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) in wcd938x_codec_enable_ear_pa()
1999 enable_irq(wcd938x->aux_pdm_wd_int); in wcd938x_codec_enable_ear_pa()
2001 enable_irq(wcd938x->hphl_pdm_wd_int); in wcd938x_codec_enable_ear_pa()
2004 if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) in wcd938x_codec_enable_ear_pa()
2005 disable_irq_nosync(wcd938x->aux_pdm_wd_int); in wcd938x_codec_enable_ear_pa()
2007 disable_irq_nosync(wcd938x->hphl_pdm_wd_int); in wcd938x_codec_enable_ear_pa()
2010 if (!wcd938x->comp1_enable) in wcd938x_codec_enable_ear_pa()
2015 if (wcd938x->ear_rx_path & EAR_RX_PATH_AUX) in wcd938x_codec_enable_ear_pa()
2022 wcd_clsh_ctrl_set_state(wcd938x->clsh_info, WCD_CLSH_EVENT_POST_PA, in wcd938x_codec_enable_ear_pa()
2025 wcd938x->flyback_cur_det_disable--; in wcd938x_codec_enable_ear_pa()
2026 if (wcd938x->flyback_cur_det_disable == 0) in wcd938x_codec_enable_ear_pa()
2039 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_codec_enable_dmic()
2043 switch (w->shift) { in wcd938x_codec_enable_dmic()
2073 dev_err(component->dev, "%s: Invalid DMIC Selection\n", in wcd938x_codec_enable_dmic()
2075 return -EINVAL; in wcd938x_codec_enable_dmic()
2110 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_tx_swr_ctrl()
2115 bank = (wcd938x_swr_get_current_bank(wcd938x->sdw_priv[AIF1_CAP]->sdev)) ? 0 : 1; in wcd938x_tx_swr_ctrl()
2120 if (strnstr(w->name, "ADC", sizeof("ADC"))) { in wcd938x_tx_swr_ctrl()
2123 if (test_bit(WCD_ADC1, &wcd938x->status_mask)) in wcd938x_tx_swr_ctrl()
2124 mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC1]]; in wcd938x_tx_swr_ctrl()
2125 if (test_bit(WCD_ADC2, &wcd938x->status_mask)) in wcd938x_tx_swr_ctrl()
2126 mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC2]]; in wcd938x_tx_swr_ctrl()
2127 if (test_bit(WCD_ADC3, &wcd938x->status_mask)) in wcd938x_tx_swr_ctrl()
2128 mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC3]]; in wcd938x_tx_swr_ctrl()
2129 if (test_bit(WCD_ADC4, &wcd938x->status_mask)) in wcd938x_tx_swr_ctrl()
2130 mode |= tx_mode_bit[wcd938x->tx_mode[WCD_ADC4]]; in wcd938x_tx_swr_ctrl()
2147 if (strnstr(w->name, "ADC", sizeof("ADC"))) { in wcd938x_tx_swr_ctrl()
2185 ret = -EINVAL; in wcd938x_get_adc_mode()
2194 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_codec_enable_adc()
2205 set_bit(w->shift, &wcd938x->status_mask); in wcd938x_codec_enable_adc()
2210 clear_bit(w->shift, &wcd938x->status_mask); in wcd938x_codec_enable_adc()
2249 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_adc_enable_req()
2261 wcd938x_tx_channel_config(component, w->shift, 1); in wcd938x_adc_enable_req()
2262 mode = wcd938x_get_adc_mode(wcd938x->tx_mode[w->shift]); in wcd938x_adc_enable_req()
2264 dev_info(component->dev, "Invalid ADC mode\n"); in wcd938x_adc_enable_req()
2265 return -EINVAL; in wcd938x_adc_enable_req()
2267 switch (w->shift) { in wcd938x_adc_enable_req()
2304 wcd938x_tx_channel_config(component, w->shift, 0); in wcd938x_adc_enable_req()
2307 switch (w->shift) { in wcd938x_adc_enable_req()
2356 int micb_index = micb_num - 1; in wcd938x_micbias_control()
2373 dev_err(component->dev, "%s: Invalid micbias number: %d\n", in wcd938x_micbias_control()
2375 return -EINVAL; in wcd938x_micbias_control()
2380 wcd938x->pullup_ref[micb_index]++; in wcd938x_micbias_control()
2381 if ((wcd938x->pullup_ref[micb_index] == 1) && in wcd938x_micbias_control()
2382 (wcd938x->micb_ref[micb_index] == 0)) in wcd938x_micbias_control()
2388 if (wcd938x->pullup_ref[micb_index] > 0) in wcd938x_micbias_control()
2389 wcd938x->pullup_ref[micb_index]--; in wcd938x_micbias_control()
2391 if ((wcd938x->pullup_ref[micb_index] == 0) && in wcd938x_micbias_control()
2392 (wcd938x->micb_ref[micb_index] == 0)) in wcd938x_micbias_control()
2397 wcd938x->micb_ref[micb_index]++; in wcd938x_micbias_control()
2398 if (wcd938x->micb_ref[micb_index] == 1) { in wcd938x_micbias_control()
2413 wcd_mbhc_event_notify(wcd938x->wcd_mbhc, in wcd938x_micbias_control()
2417 wcd_mbhc_event_notify(wcd938x->wcd_mbhc, in wcd938x_micbias_control()
2423 if (wcd938x->micb_ref[micb_index] > 0) in wcd938x_micbias_control()
2424 wcd938x->micb_ref[micb_index]--; in wcd938x_micbias_control()
2426 if ((wcd938x->micb_ref[micb_index] == 0) && in wcd938x_micbias_control()
2427 (wcd938x->pullup_ref[micb_index] > 0)) in wcd938x_micbias_control()
2431 else if ((wcd938x->micb_ref[micb_index] == 0) && in wcd938x_micbias_control()
2432 (wcd938x->pullup_ref[micb_index] == 0)) { in wcd938x_micbias_control()
2434 wcd_mbhc_event_notify(wcd938x->wcd_mbhc, in wcd938x_micbias_control()
2440 wcd_mbhc_event_notify(wcd938x->wcd_mbhc, in wcd938x_micbias_control()
2444 wcd_mbhc_event_notify(wcd938x->wcd_mbhc, in wcd938x_micbias_control()
2456 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_codec_enable_micbias()
2457 int micb_num = w->shift; in wcd938x_codec_enable_micbias()
2479 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd938x_codec_enable_micbias_pullup()
2480 int micb_num = w->shift; in wcd938x_codec_enable_micbias_pullup()
2505 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in wcd938x_tx_mode_get()
2506 int path = e->shift_l; in wcd938x_tx_mode_get()
2508 ucontrol->value.enumerated.item[0] = wcd938x->tx_mode[path]; in wcd938x_tx_mode_get()
2518 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in wcd938x_tx_mode_put()
2519 int path = e->shift_l; in wcd938x_tx_mode_put()
2521 if (wcd938x->tx_mode[path] == ucontrol->value.enumerated.item[0]) in wcd938x_tx_mode_put()
2524 wcd938x->tx_mode[path] = ucontrol->value.enumerated.item[0]; in wcd938x_tx_mode_put()
2535 ucontrol->value.enumerated.item[0] = wcd938x->hph_mode; in wcd938x_rx_hph_mode_get()
2546 if (wcd938x->hph_mode == ucontrol->value.enumerated.item[0]) in wcd938x_rx_hph_mode_put()
2549 wcd938x->hph_mode = ucontrol->value.enumerated.item[0]; in wcd938x_rx_hph_mode_put()
2560 if (wcd938x->comp1_enable) { in wcd938x_ear_pa_put_gain()
2561 dev_err(component->dev, "Can not set EAR PA Gain, compander1 is enabled\n"); in wcd938x_ear_pa_put_gain()
2562 return -EINVAL; in wcd938x_ear_pa_put_gain()
2567 ucontrol->value.integer.value[0]); in wcd938x_ear_pa_put_gain()
2581 mc = (struct soc_mixer_control *)(kcontrol->private_value); in wcd938x_get_compander()
2582 hphr = mc->shift; in wcd938x_get_compander()
2585 ucontrol->value.integer.value[0] = wcd938x->comp2_enable; in wcd938x_get_compander()
2587 ucontrol->value.integer.value[0] = wcd938x->comp1_enable; in wcd938x_get_compander()
2598 int value = ucontrol->value.integer.value[0]; in wcd938x_set_compander()
2603 mc = (struct soc_mixer_control *)(kcontrol->private_value); in wcd938x_set_compander()
2604 hphr = mc->shift; in wcd938x_set_compander()
2606 wcd = wcd938x->sdw_priv[AIF1_PB]; in wcd938x_set_compander()
2609 wcd938x->comp2_enable = value; in wcd938x_set_compander()
2611 wcd938x->comp1_enable = value; in wcd938x_set_compander()
2613 portidx = wcd->ch_info[mc->reg].port_num; in wcd938x_set_compander()
2616 wcd938x_connect_port(wcd, portidx, mc->reg, true); in wcd938x_set_compander()
2618 wcd938x_connect_port(wcd, portidx, mc->reg, false); in wcd938x_set_compander()
2629 ucontrol->value.integer.value[0] = wcd938x->ldoh; in wcd938x_ldoh_get()
2640 if (wcd938x->ldoh == ucontrol->value.integer.value[0]) in wcd938x_ldoh_put()
2643 wcd938x->ldoh = ucontrol->value.integer.value[0]; in wcd938x_ldoh_put()
2654 ucontrol->value.integer.value[0] = wcd938x->bcs_dis; in wcd938x_bcs_get()
2665 if (wcd938x->bcs_dis == ucontrol->value.integer.value[0]) in wcd938x_bcs_put()
2668 wcd938x->bcs_dis = ucontrol->value.integer.value[0]; in wcd938x_bcs_put()
2895 struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; in wcd938x_get_swr_port()
2896 int dai_id = mixer->shift; in wcd938x_get_swr_port()
2897 int portidx, ch_idx = mixer->reg; in wcd938x_get_swr_port()
2900 wcd = wcd938x->sdw_priv[dai_id]; in wcd938x_get_swr_port()
2901 portidx = wcd->ch_info[ch_idx].port_num; in wcd938x_get_swr_port()
2903 ucontrol->value.integer.value[0] = wcd->port_enable[portidx]; in wcd938x_get_swr_port()
2915 (struct soc_mixer_control *)kcontrol->private_value; in wcd938x_set_swr_port()
2916 int ch_idx = mixer->reg; in wcd938x_set_swr_port()
2918 int dai_id = mixer->shift; in wcd938x_set_swr_port()
2921 wcd = wcd938x->sdw_priv[dai_id]; in wcd938x_set_swr_port()
2923 portidx = wcd->ch_info[ch_idx].port_num; in wcd938x_set_swr_port()
2924 if (ucontrol->value.integer.value[0]) in wcd938x_set_swr_port()
2929 wcd->port_enable[portidx] = enable; in wcd938x_set_swr_port()
2959 dev_err(component->dev, "%s: invalid number of buttons: %d\n", in wcd938x_mbhc_program_btn_thr()
2968 dev_dbg(component->dev, "%s: btn_high[%d]: %d, vth: %d\n", in wcd938x_mbhc_program_btn_thr()
3025 return -EINVAL; in wcd938x_get_micb_vout_ctl_val()
3027 return (micb_mv - 1000) / 50; in wcd938x_get_micb_vout_ctl_val()
3050 return -EINVAL; in wcd938x_mbhc_micb_adjust_voltage()
3052 mutex_lock(&wcd938x->micb_lock); in wcd938x_mbhc_micb_adjust_voltage()
3057 * to avoid slow micbias ramp-up or down enable pull-up in wcd938x_mbhc_micb_adjust_voltage()
3058 * momentarily, change the micbias value and then re-enable in wcd938x_mbhc_micb_adjust_voltage()
3068 ret = -EINVAL; in wcd938x_mbhc_micb_adjust_voltage()
3097 mutex_unlock(&wcd938x->micb_lock); in wcd938x_mbhc_micb_adjust_voltage()
3108 return -EINVAL; in wcd938x_mbhc_micb_ctrl_threshold_mic()
3114 if (wcd938x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV) in wcd938x_mbhc_micb_ctrl_threshold_mic()
3117 micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd938x->micb2_mv; in wcd938x_mbhc_micb_ctrl_threshold_mic()
3135 regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MBHC_ZDET, 0x20, 0x20); in wcd938x_mbhc_get_result_params()
3137 regmap_read(wcd938x->regmap, WCD938X_ANA_MBHC_RESULT_2, &val); in wcd938x_mbhc_get_result_params()
3142 regmap_read(wcd938x->regmap, WCD938X_ANA_MBHC_RESULT_1, &val1); in wcd938x_mbhc_get_result_params()
3144 regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MBHC_ZDET, 0x20, 0x00); in wcd938x_mbhc_get_result_params()
3157 denom = (x1 * d1) - (1 << (14 - noff)); in wcd938x_mbhc_get_result_params()
3168 regmap_read(wcd938x->regmap, in wcd938x_mbhc_get_result_params()
3170 regmap_read(wcd938x->regmap, in wcd938x_mbhc_get_result_params()
3189 WCD938X_ZDET_MAXV_CTL_MASK, zdet_param->ldo_ctl); in wcd938x_mbhc_zdet_ramp()
3191 WCD938X_VTH_MASK, zdet_param->btn5); in wcd938x_mbhc_zdet_ramp()
3193 WCD938X_VTH_MASK, zdet_param->btn6); in wcd938x_mbhc_zdet_ramp()
3195 WCD938X_VTH_MASK, zdet_param->btn7); in wcd938x_mbhc_zdet_ramp()
3197 WCD938X_ZDET_RANGE_CTL_MASK, zdet_param->noff); in wcd938x_mbhc_zdet_ramp()
3199 0x0F, zdet_param->nshift); in wcd938x_mbhc_zdet_ramp()
3204 regmap_update_bits(wcd938x->regmap, in wcd938x_mbhc_zdet_ramp()
3206 dev_dbg(component->dev, "%s: ramp for HPH_L, noff = %d\n", in wcd938x_mbhc_zdet_ramp()
3207 __func__, zdet_param->noff); in wcd938x_mbhc_zdet_ramp()
3208 wcd938x_mbhc_get_result_params(wcd938x, d1_a, zdet_param->noff, &zdet); in wcd938x_mbhc_zdet_ramp()
3209 regmap_update_bits(wcd938x->regmap, in wcd938x_mbhc_zdet_ramp()
3218 regmap_update_bits(wcd938x->regmap, in wcd938x_mbhc_zdet_ramp()
3220 dev_dbg(component->dev, "%s: ramp for HPH_R, noff = %d\n", in wcd938x_mbhc_zdet_ramp()
3221 __func__, zdet_param->noff); in wcd938x_mbhc_zdet_ramp()
3222 wcd938x_mbhc_get_result_params(wcd938x, d1_a, zdet_param->noff, &zdet); in wcd938x_mbhc_zdet_ramp()
3223 regmap_update_bits(wcd938x->regmap, in wcd938x_mbhc_zdet_ramp()
3242 q1_cal = (10000 - ((q1 & 0x7F) * 25)); in wcd938x_wcd_mbhc_qfuse_cal()
3280 regmap_update_bits(wcd938x->regmap, in wcd938x_wcd_mbhc_calc_impedance()
3284 /* For NO-jack, disable L_DET_EN before Z-det measurements */ in wcd938x_wcd_mbhc_calc_impedance()
3285 if (wcd938x->mbhc_cfg.hphl_swh) in wcd938x_wcd_mbhc_calc_impedance()
3286 regmap_update_bits(wcd938x->regmap, in wcd938x_wcd_mbhc_calc_impedance()
3290 regmap_update_bits(wcd938x->regmap, in wcd938x_wcd_mbhc_calc_impedance()
3296 regmap_update_bits(wcd938x->regmap, in wcd938x_wcd_mbhc_calc_impedance()
3333 dev_dbg(component->dev, "%s: impedance on HPH_L = %d(ohms)\n", in wcd938x_wcd_mbhc_calc_impedance()
3340 (zdet_param_ptr->noff == 0x6)) || in wcd938x_wcd_mbhc_calc_impedance()
3365 dev_dbg(component->dev, "%s: impedance on HPH_R = %d(ohms)\n", in wcd938x_wcd_mbhc_calc_impedance()
3371 dev_dbg(component->dev, in wcd938x_wcd_mbhc_calc_impedance()
3380 dev_dbg(component->dev, in wcd938x_wcd_mbhc_calc_impedance()
3383 wcd_mbhc_set_hph_type(wcd938x->wcd_mbhc, WCD_MBHC_HPH_MONO); in wcd938x_wcd_mbhc_calc_impedance()
3402 z_diff1 = (z1Ls > zMono) ? (z1Ls - zMono) : (zMono - z1Ls); in wcd938x_wcd_mbhc_calc_impedance()
3403 z_diff2 = ((*zl) > z1Ls) ? ((*zl) - z1Ls) : (z1Ls - (*zl)); in wcd938x_wcd_mbhc_calc_impedance()
3405 dev_dbg(component->dev, "%s: stereo plug type detected\n", in wcd938x_wcd_mbhc_calc_impedance()
3407 wcd_mbhc_set_hph_type(wcd938x->wcd_mbhc, WCD_MBHC_HPH_STEREO); in wcd938x_wcd_mbhc_calc_impedance()
3409 dev_dbg(component->dev, "%s: MONO plug type detected\n", in wcd938x_wcd_mbhc_calc_impedance()
3411 wcd_mbhc_set_hph_type(wcd938x->wcd_mbhc, WCD_MBHC_HPH_MONO); in wcd938x_wcd_mbhc_calc_impedance()
3415 regmap_update_bits(wcd938x->regmap, in wcd938x_wcd_mbhc_calc_impedance()
3422 regmap_update_bits(wcd938x->regmap, in wcd938x_wcd_mbhc_calc_impedance()
3425 /* For NO-jack, re-enable L_DET_EN after Z-det measurements */ in wcd938x_wcd_mbhc_calc_impedance()
3426 if (wcd938x->mbhc_cfg.hphl_swh) in wcd938x_wcd_mbhc_calc_impedance()
3427 regmap_update_bits(wcd938x->regmap, in wcd938x_wcd_mbhc_calc_impedance()
3433 regmap_update_bits(wcd938x->regmap, in wcd938x_wcd_mbhc_calc_impedance()
3466 if (wcd938x->mbhc_cfg.moist_rref == R_OFF) { in wcd938x_mbhc_moisture_config()
3473 if (!wcd938x->mbhc_cfg.hphl_swh) { in wcd938x_mbhc_moisture_config()
3474 dev_dbg(component->dev, "%s: disable moisture detection for NC\n", in wcd938x_mbhc_moisture_config()
3482 WCD938X_M_RTH_CTL_MASK, wcd938x->mbhc_cfg.moist_rref); in wcd938x_mbhc_moisture_config()
3491 WCD938X_M_RTH_CTL_MASK, wcd938x->mbhc_cfg.moist_rref); in wcd938x_mbhc_moisture_detect_en()
3502 if (wcd938x->mbhc_cfg.moist_rref == R_OFF) { in wcd938x_mbhc_get_moisture_status()
3509 if (!wcd938x->mbhc_cfg.hphl_swh) { in wcd938x_mbhc_get_moisture_status()
3510 dev_dbg(component->dev, "%s: disable moisture detection for NC\n", in wcd938x_mbhc_get_moisture_status()
3566 ucontrol->value.integer.value[0] = wcd_mbhc_get_hph_type(wcd938x->wcd_mbhc); in wcd938x_get_hph_type()
3581 mc = (struct soc_mixer_control *)(kcontrol->private_value); in wcd938x_hph_impedance_get()
3582 hphr = mc->shift; in wcd938x_hph_impedance_get()
3583 wcd_mbhc_get_impedance(wcd938x->wcd_mbhc, &zl, &zr); in wcd938x_hph_impedance_get()
3584 dev_dbg(component->dev, "%s: zl=%u(ohms), zr=%u(ohms)\n", __func__, zl, zr); in wcd938x_hph_impedance_get()
3585 ucontrol->value.integer.value[0] = hphr ? zr : zl; in wcd938x_hph_impedance_get()
3605 struct wcd_mbhc_intr *intr_ids = &wcd938x->intr_ids; in wcd938x_mbhc_init()
3607 intr_ids->mbhc_sw_intr = regmap_irq_get_virq(wcd938x->irq_chip, in wcd938x_mbhc_init()
3609 intr_ids->mbhc_btn_press_intr = regmap_irq_get_virq(wcd938x->irq_chip, in wcd938x_mbhc_init()
3611 intr_ids->mbhc_btn_release_intr = regmap_irq_get_virq(wcd938x->irq_chip, in wcd938x_mbhc_init()
3613 intr_ids->mbhc_hs_ins_intr = regmap_irq_get_virq(wcd938x->irq_chip, in wcd938x_mbhc_init()
3615 intr_ids->mbhc_hs_rem_intr = regmap_irq_get_virq(wcd938x->irq_chip, in wcd938x_mbhc_init()
3617 intr_ids->hph_left_ocp = regmap_irq_get_virq(wcd938x->irq_chip, in wcd938x_mbhc_init()
3619 intr_ids->hph_right_ocp = regmap_irq_get_virq(wcd938x->irq_chip, in wcd938x_mbhc_init()
3622 wcd938x->wcd_mbhc = wcd_mbhc_init(component, &mbhc_cb, intr_ids, wcd_mbhc_fields, true); in wcd938x_mbhc_init()
4018 vout_ctl_1 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb1_mv); in wcd938x_set_micbias_data()
4019 vout_ctl_2 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb2_mv); in wcd938x_set_micbias_data()
4020 vout_ctl_3 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb3_mv); in wcd938x_set_micbias_data()
4021 vout_ctl_4 = wcd938x_get_micb_vout_ctl_val(wcd938x->micb4_mv); in wcd938x_set_micbias_data()
4023 return -EINVAL; in wcd938x_set_micbias_data()
4025 regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB1, in wcd938x_set_micbias_data()
4027 regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB2, in wcd938x_set_micbias_data()
4029 regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB3, in wcd938x_set_micbias_data()
4031 regmap_update_bits(wcd938x->regmap, WCD938X_ANA_MICB4, in wcd938x_set_micbias_data()
4063 wcd->virq = irq_domain_add_linear(NULL, 1, &wcd_domain_ops, NULL); in wcd938x_irq_init()
4064 if (!(wcd->virq)) { in wcd938x_irq_init()
4066 return -EINVAL; in wcd938x_irq_init()
4069 return devm_regmap_add_irq_chip(dev, wcd->regmap, in wcd938x_irq_init()
4070 irq_create_mapping(wcd->virq, 0), in wcd938x_irq_init()
4072 &wcd->irq_chip); in wcd938x_irq_init()
4078 struct device *dev = component->dev; in wcd938x_soc_codec_probe()
4081 snd_soc_component_init_regmap(component, wcd938x->regmap); in wcd938x_soc_codec_probe()
4083 wcd938x->variant = snd_soc_component_read_field(component, in wcd938x_soc_codec_probe()
4087 wcd938x->clsh_info = wcd_clsh_ctrl_alloc(component, WCD938X); in wcd938x_soc_codec_probe()
4092 regmap_write(wcd938x->regmap, in wcd938x_soc_codec_probe()
4096 wcd938x->hphr_pdm_wd_int = regmap_irq_get_virq(wcd938x->irq_chip, in wcd938x_soc_codec_probe()
4098 wcd938x->hphl_pdm_wd_int = regmap_irq_get_virq(wcd938x->irq_chip, in wcd938x_soc_codec_probe()
4100 wcd938x->aux_pdm_wd_int = regmap_irq_get_virq(wcd938x->irq_chip, in wcd938x_soc_codec_probe()
4104 ret = request_threaded_irq(wcd938x->hphr_pdm_wd_int, NULL, wcd938x_wd_handle_irq, in wcd938x_soc_codec_probe()
4110 ret = request_threaded_irq(wcd938x->hphl_pdm_wd_int, NULL, wcd938x_wd_handle_irq, in wcd938x_soc_codec_probe()
4116 ret = request_threaded_irq(wcd938x->aux_pdm_wd_int, NULL, wcd938x_wd_handle_irq, in wcd938x_soc_codec_probe()
4123 disable_irq_nosync(wcd938x->hphr_pdm_wd_int); in wcd938x_soc_codec_probe()
4124 disable_irq_nosync(wcd938x->hphl_pdm_wd_int); in wcd938x_soc_codec_probe()
4125 disable_irq_nosync(wcd938x->aux_pdm_wd_int); in wcd938x_soc_codec_probe()
4127 switch (wcd938x->variant) { in wcd938x_soc_codec_probe()
4132 dev_err(component->dev, in wcd938x_soc_codec_probe()
4134 __func__, wcd938x->variant); in wcd938x_soc_codec_probe()
4142 dev_err(component->dev, in wcd938x_soc_codec_probe()
4144 __func__, wcd938x->variant); in wcd938x_soc_codec_probe()
4154 dev_err(component->dev, "mbhc initialization failed\n"); in wcd938x_soc_codec_probe()
4162 struct wcd938x_priv *wcd = dev_get_drvdata(comp->dev); in wcd938x_codec_set_jack()
4165 return wcd_mbhc_start(wcd->wcd_mbhc, &wcd->mbhc_cfg, jack); in wcd938x_codec_set_jack()
4167 wcd_mbhc_stop(wcd->wcd_mbhc); in wcd938x_codec_set_jack()
4187 struct device_node *np = dev->of_node; in wcd938x_dt_parse_micbias_info()
4191 rc = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val); in wcd938x_dt_parse_micbias_info()
4193 wcd->micb1_mv = prop_val/1000; in wcd938x_dt_parse_micbias_info()
4195 dev_info(dev, "%s: Micbias1 DT property not found\n", __func__); in wcd938x_dt_parse_micbias_info()
4197 rc = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val); in wcd938x_dt_parse_micbias_info()
4199 wcd->micb2_mv = prop_val/1000; in wcd938x_dt_parse_micbias_info()
4203 rc = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val); in wcd938x_dt_parse_micbias_info()
4205 wcd->micb3_mv = prop_val/1000; in wcd938x_dt_parse_micbias_info()
4209 rc = of_property_read_u32(np, "qcom,micbias4-microvolt", &prop_val); in wcd938x_dt_parse_micbias_info()
4211 wcd->micb4_mv = prop_val/1000; in wcd938x_dt_parse_micbias_info()
4224 value = gpiod_get_value(wcd938x->us_euro_gpio); in wcd938x_swap_gnd_mic()
4226 gpiod_set_value(wcd938x->us_euro_gpio, !value); in wcd938x_swap_gnd_mic()
4234 struct wcd_mbhc_config *cfg = &wcd938x->mbhc_cfg; in wcd938x_populate_dt_data()
4237 wcd938x->reset_gpio = of_get_named_gpio(dev->of_node, "reset-gpios", 0); in wcd938x_populate_dt_data()
4238 if (wcd938x->reset_gpio < 0) { in wcd938x_populate_dt_data()
4240 wcd938x->reset_gpio); in wcd938x_populate_dt_data()
4241 return wcd938x->reset_gpio; in wcd938x_populate_dt_data()
4244 wcd938x->us_euro_gpio = devm_gpiod_get_optional(dev, "us-euro", in wcd938x_populate_dt_data()
4246 if (IS_ERR(wcd938x->us_euro_gpio)) { in wcd938x_populate_dt_data()
4247 dev_err(dev, "us-euro swap Control GPIO not found\n"); in wcd938x_populate_dt_data()
4248 return PTR_ERR(wcd938x->us_euro_gpio); in wcd938x_populate_dt_data()
4251 cfg->swap_gnd_mic = wcd938x_swap_gnd_mic; in wcd938x_populate_dt_data()
4253 wcd938x->supplies[0].supply = "vdd-rxtx"; in wcd938x_populate_dt_data()
4254 wcd938x->supplies[1].supply = "vdd-io"; in wcd938x_populate_dt_data()
4255 wcd938x->supplies[2].supply = "vdd-buck"; in wcd938x_populate_dt_data()
4256 wcd938x->supplies[3].supply = "vdd-mic-bias"; in wcd938x_populate_dt_data()
4258 ret = regulator_bulk_get(dev, WCD938X_MAX_SUPPLY, wcd938x->supplies); in wcd938x_populate_dt_data()
4264 ret = regulator_bulk_enable(WCD938X_MAX_SUPPLY, wcd938x->supplies); in wcd938x_populate_dt_data()
4272 cfg->mbhc_micbias = MIC_BIAS_2; in wcd938x_populate_dt_data()
4273 cfg->anc_micbias = MIC_BIAS_2; in wcd938x_populate_dt_data()
4274 cfg->v_hs_max = WCD_MBHC_HS_V_MAX; in wcd938x_populate_dt_data()
4275 cfg->num_btn = WCD938X_MBHC_MAX_BUTTONS; in wcd938x_populate_dt_data()
4276 cfg->micb_mv = wcd938x->micb2_mv; in wcd938x_populate_dt_data()
4277 cfg->linein_th = 5000; in wcd938x_populate_dt_data()
4278 cfg->hs_thr = 1700; in wcd938x_populate_dt_data()
4279 cfg->hph_thr = 50; in wcd938x_populate_dt_data()
4288 gpio_direction_output(wcd938x->reset_gpio, 0); in wcd938x_reset()
4291 gpio_set_value(wcd938x->reset_gpio, 1); in wcd938x_reset()
4302 struct wcd938x_priv *wcd938x = dev_get_drvdata(dai->dev); in wcd938x_codec_hw_params()
4303 struct wcd938x_sdw_priv *wcd = wcd938x->sdw_priv[dai->id]; in wcd938x_codec_hw_params()
4311 struct wcd938x_priv *wcd938x = dev_get_drvdata(dai->dev); in wcd938x_codec_free()
4312 struct wcd938x_sdw_priv *wcd = wcd938x->sdw_priv[dai->id]; in wcd938x_codec_free()
4320 struct wcd938x_priv *wcd938x = dev_get_drvdata(dai->dev); in wcd938x_codec_set_sdw_stream()
4321 struct wcd938x_sdw_priv *wcd = wcd938x->sdw_priv[dai->id]; in wcd938x_codec_set_sdw_stream()
4335 .name = "wcd938x-sdw-rx",
4348 .name = "wcd938x-sdw-tx",
4374 wcd938x->rxdev = wcd938x_sdw_device_get(wcd938x->rxnode); in wcd938x_bind()
4375 if (!wcd938x->rxdev) { in wcd938x_bind()
4377 return -EINVAL; in wcd938x_bind()
4379 wcd938x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd938x->rxdev); in wcd938x_bind()
4380 wcd938x->sdw_priv[AIF1_PB]->wcd938x = wcd938x; in wcd938x_bind()
4382 wcd938x->txdev = wcd938x_sdw_device_get(wcd938x->txnode); in wcd938x_bind()
4383 if (!wcd938x->txdev) { in wcd938x_bind()
4385 return -EINVAL; in wcd938x_bind()
4387 wcd938x->sdw_priv[AIF1_CAP] = dev_get_drvdata(wcd938x->txdev); in wcd938x_bind()
4388 wcd938x->sdw_priv[AIF1_CAP]->wcd938x = wcd938x; in wcd938x_bind()
4389 wcd938x->tx_sdw_dev = dev_to_sdw_dev(wcd938x->txdev); in wcd938x_bind()
4390 if (!wcd938x->tx_sdw_dev) { in wcd938x_bind()
4392 return -EINVAL; in wcd938x_bind()
4397 if (!device_link_add(wcd938x->rxdev, wcd938x->txdev, DL_FLAG_STATELESS | in wcd938x_bind()
4400 return -EINVAL; in wcd938x_bind()
4403 if (!device_link_add(dev, wcd938x->txdev, DL_FLAG_STATELESS | in wcd938x_bind()
4406 return -EINVAL; in wcd938x_bind()
4409 if (!device_link_add(dev, wcd938x->rxdev, DL_FLAG_STATELESS | in wcd938x_bind()
4412 return -EINVAL; in wcd938x_bind()
4415 wcd938x->regmap = devm_regmap_init_sdw(wcd938x->tx_sdw_dev, &wcd938x_regmap_config); in wcd938x_bind()
4416 if (IS_ERR(wcd938x->regmap)) { in wcd938x_bind()
4418 return PTR_ERR(wcd938x->regmap); in wcd938x_bind()
4427 wcd938x->sdw_priv[AIF1_PB]->slave_irq = wcd938x->virq; in wcd938x_bind()
4428 wcd938x->sdw_priv[AIF1_CAP]->slave_irq = wcd938x->virq; in wcd938x_bind()
4450 device_link_remove(dev, wcd938x->txdev); in wcd938x_unbind()
4451 device_link_remove(dev, wcd938x->rxdev); in wcd938x_unbind()
4452 device_link_remove(wcd938x->rxdev, wcd938x->txdev); in wcd938x_unbind()
4468 np = dev->of_node; in wcd938x_add_slave_components()
4470 wcd938x->rxnode = of_parse_phandle(np, "qcom,rx-device", 0); in wcd938x_add_slave_components()
4471 if (!wcd938x->rxnode) { in wcd938x_add_slave_components()
4472 dev_err(dev, "%s: Rx-device node not defined\n", __func__); in wcd938x_add_slave_components()
4473 return -ENODEV; in wcd938x_add_slave_components()
4476 of_node_get(wcd938x->rxnode); in wcd938x_add_slave_components()
4478 component_compare_of, wcd938x->rxnode); in wcd938x_add_slave_components()
4480 wcd938x->txnode = of_parse_phandle(np, "qcom,tx-device", 0); in wcd938x_add_slave_components()
4481 if (!wcd938x->txnode) { in wcd938x_add_slave_components()
4482 dev_err(dev, "%s: Tx-device node not defined\n", __func__); in wcd938x_add_slave_components()
4483 return -ENODEV; in wcd938x_add_slave_components()
4485 of_node_get(wcd938x->txnode); in wcd938x_add_slave_components()
4487 component_compare_of, wcd938x->txnode); in wcd938x_add_slave_components()
4495 struct device *dev = &pdev->dev; in wcd938x_probe()
4501 return -ENOMEM; in wcd938x_probe()
4504 mutex_init(&wcd938x->micb_lock); in wcd938x_probe()
4509 return -EINVAL; in wcd938x_probe()
4534 component_master_del(&pdev->dev, &wcd938x_comp_ops); in wcd938x_remove()
4541 { .compatible = "qcom,wcd9380-codec" },
4542 { .compatible = "qcom,wcd9385-codec" },