Lines Matching +full:int +full:- +full:comp +full:- +full:resistor
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
19 #include <sound/soc-dapm.h>
23 #include "wcd-clsh-v2.h"
24 #include "wcd-mbhc-v2.h"
100 int ear_rx_path;
104 int hphr_pdm_wd_int;
105 int hphl_pdm_wd_int;
106 int aux_pdm_wd_int;
117 static const SNDRV_CTL_TLVD_DECLARE_DB_MINMAX(ear_pa_gain, 600, -1800);
204 static int wcd937x_handle_post_irq(void *data) in wcd937x_handle_post_irq()
213 regmap_write(wcd937x->regmap, WCD937X_DIGITAL_INTR_CLEAR_0, 0); in wcd937x_handle_post_irq()
214 regmap_write(wcd937x->regmap, WCD937X_DIGITAL_INTR_CLEAR_1, 0); in wcd937x_handle_post_irq()
215 regmap_write(wcd937x->regmap, WCD937X_DIGITAL_INTR_CLEAR_2, 0); in wcd937x_handle_post_irq()
244 gpiod_set_value(wcd937x->reset_gpio, 1); in wcd937x_reset()
246 gpiod_set_value(wcd937x->reset_gpio, 0); in wcd937x_reset()
300 static int wcd937x_rx_clk_enable(struct snd_soc_component *component) in wcd937x_rx_clk_enable()
304 if (atomic_read(&wcd937x->rx_clk_cnt)) in wcd937x_rx_clk_enable()
315 atomic_inc(&wcd937x->rx_clk_cnt); in wcd937x_rx_clk_enable()
320 static int wcd937x_rx_clk_disable(struct snd_soc_component *component) in wcd937x_rx_clk_disable()
324 if (!atomic_read(&wcd937x->rx_clk_cnt)) { in wcd937x_rx_clk_disable()
325 dev_err(component->dev, "clk already disabled\n"); in wcd937x_rx_clk_disable()
329 atomic_dec(&wcd937x->rx_clk_cnt); in wcd937x_rx_clk_disable()
338 static int wcd937x_codec_hphl_dac_event(struct snd_soc_dapm_widget *w, in wcd937x_codec_hphl_dac_event()
340 int event) in wcd937x_codec_hphl_dac_event()
342 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_hphl_dac_event()
344 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_hphl_dac_event()
358 set_bit(HPH_COMP_DELAY, &wcd937x->status_mask); in wcd937x_codec_hphl_dac_event()
370 if (wcd937x->comp1_enable) { in wcd937x_codec_hphl_dac_event()
378 if (wcd937x->comp2_enable) { in wcd937x_codec_hphl_dac_event()
386 if (test_bit(HPH_COMP_DELAY, &wcd937x->status_mask)) { in wcd937x_codec_hphl_dac_event()
388 clear_bit(HPH_COMP_DELAY, &wcd937x->status_mask); in wcd937x_codec_hphl_dac_event()
413 static int wcd937x_codec_hphr_dac_event(struct snd_soc_dapm_widget *w, in wcd937x_codec_hphr_dac_event()
415 int event) in wcd937x_codec_hphr_dac_event()
417 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_hphr_dac_event()
419 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_hphr_dac_event()
430 set_bit(HPH_COMP_DELAY, &wcd937x->status_mask); in wcd937x_codec_hphr_dac_event()
441 if (wcd937x->comp2_enable) { in wcd937x_codec_hphr_dac_event()
447 if (wcd937x->comp1_enable) { in wcd937x_codec_hphr_dac_event()
456 if (test_bit(HPH_COMP_DELAY, &wcd937x->status_mask)) { in wcd937x_codec_hphr_dac_event()
458 clear_bit(HPH_COMP_DELAY, &wcd937x->status_mask); in wcd937x_codec_hphr_dac_event()
482 static int wcd937x_codec_ear_dac_event(struct snd_soc_dapm_widget *w, in wcd937x_codec_ear_dac_event()
484 int event) in wcd937x_codec_ear_dac_event()
486 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_ear_dac_event()
488 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_ear_dac_event()
508 if (wcd937x->comp1_enable) in wcd937x_codec_ear_dac_event()
515 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_ear_dac_event()
527 if (wcd937x->comp1_enable) in wcd937x_codec_ear_dac_event()
537 static int wcd937x_codec_aux_dac_event(struct snd_soc_dapm_widget *w, in wcd937x_codec_aux_dac_event()
539 int event) in wcd937x_codec_aux_dac_event()
541 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_aux_dac_event()
543 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_aux_dac_event()
557 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_aux_dac_event()
573 static int wcd937x_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w, in wcd937x_codec_enable_hphr_pa()
575 int event) in wcd937x_codec_enable_hphr_pa()
577 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_enable_hphr_pa()
579 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_enable_hphr_pa()
583 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_enable_hphr_pa()
590 set_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphr_pa()
596 if (test_bit(HPH_PA_DELAY, &wcd937x->status_mask)) { in wcd937x_codec_enable_hphr_pa()
597 if (wcd937x->comp2_enable) in wcd937x_codec_enable_hphr_pa()
601 clear_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphr_pa()
611 enable_irq(wcd937x->hphr_pdm_wd_int); in wcd937x_codec_enable_hphr_pa()
614 disable_irq_nosync(wcd937x->hphr_pdm_wd_int); in wcd937x_codec_enable_hphr_pa()
615 set_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphr_pa()
616 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, WCD_EVENT_PRE_HPHR_PA_OFF); in wcd937x_codec_enable_hphr_pa()
619 if (test_bit(HPH_PA_DELAY, &wcd937x->status_mask)) { in wcd937x_codec_enable_hphr_pa()
620 if (wcd937x->comp2_enable) in wcd937x_codec_enable_hphr_pa()
624 clear_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphr_pa()
627 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, WCD_EVENT_POST_HPHR_PA_OFF); in wcd937x_codec_enable_hphr_pa()
632 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_enable_hphr_pa()
642 static int wcd937x_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w, in wcd937x_codec_enable_hphl_pa()
644 int event) in wcd937x_codec_enable_hphl_pa()
646 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_enable_hphl_pa()
648 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_enable_hphl_pa()
652 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_enable_hphl_pa()
659 set_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphl_pa()
664 if (test_bit(HPH_PA_DELAY, &wcd937x->status_mask)) { in wcd937x_codec_enable_hphl_pa()
665 if (!wcd937x->comp1_enable) in wcd937x_codec_enable_hphl_pa()
669 clear_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphl_pa()
679 enable_irq(wcd937x->hphl_pdm_wd_int); in wcd937x_codec_enable_hphl_pa()
682 disable_irq_nosync(wcd937x->hphl_pdm_wd_int); in wcd937x_codec_enable_hphl_pa()
683 set_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphl_pa()
684 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, WCD_EVENT_PRE_HPHL_PA_OFF); in wcd937x_codec_enable_hphl_pa()
687 if (test_bit(HPH_PA_DELAY, &wcd937x->status_mask)) { in wcd937x_codec_enable_hphl_pa()
688 if (!wcd937x->comp1_enable) in wcd937x_codec_enable_hphl_pa()
692 clear_bit(HPH_PA_DELAY, &wcd937x->status_mask); in wcd937x_codec_enable_hphl_pa()
695 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, WCD_EVENT_POST_HPHL_PA_OFF); in wcd937x_codec_enable_hphl_pa()
700 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_enable_hphl_pa()
710 static int wcd937x_codec_enable_aux_pa(struct snd_soc_dapm_widget *w, in wcd937x_codec_enable_aux_pa()
712 int event) in wcd937x_codec_enable_aux_pa()
714 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_enable_aux_pa()
716 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_enable_aux_pa()
735 enable_irq(wcd937x->aux_pdm_wd_int); in wcd937x_codec_enable_aux_pa()
738 disable_irq_nosync(wcd937x->aux_pdm_wd_int); in wcd937x_codec_enable_aux_pa()
742 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_enable_aux_pa()
756 static int wcd937x_codec_enable_ear_pa(struct snd_soc_dapm_widget *w, in wcd937x_codec_enable_ear_pa()
758 int event) in wcd937x_codec_enable_ear_pa()
760 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_enable_ear_pa()
762 int hph_mode = wcd937x->hph_mode; in wcd937x_codec_enable_ear_pa()
767 wcd937x->ear_rx_path = snd_soc_component_read(component, in wcd937x_codec_enable_ear_pa()
770 if (wcd937x->ear_rx_path & EAR_RX_PATH_AUX) in wcd937x_codec_enable_ear_pa()
778 if (!wcd937x->comp1_enable) in wcd937x_codec_enable_ear_pa()
790 if (wcd937x->ear_rx_path & EAR_RX_PATH_AUX) in wcd937x_codec_enable_ear_pa()
791 enable_irq(wcd937x->aux_pdm_wd_int); in wcd937x_codec_enable_ear_pa()
793 enable_irq(wcd937x->hphl_pdm_wd_int); in wcd937x_codec_enable_ear_pa()
796 if (wcd937x->ear_rx_path & EAR_RX_PATH_AUX) in wcd937x_codec_enable_ear_pa()
797 disable_irq_nosync(wcd937x->aux_pdm_wd_int); in wcd937x_codec_enable_ear_pa()
799 disable_irq_nosync(wcd937x->hphl_pdm_wd_int); in wcd937x_codec_enable_ear_pa()
802 if (!wcd937x->comp1_enable) in wcd937x_codec_enable_ear_pa()
807 wcd_clsh_ctrl_set_state(wcd937x->clsh_info, in wcd937x_codec_enable_ear_pa()
814 if (wcd937x->ear_rx_path & EAR_RX_PATH_AUX) in wcd937x_codec_enable_ear_pa()
828 static int wcd937x_enable_rx1(struct snd_soc_dapm_widget *w, in wcd937x_enable_rx1()
830 int event) in wcd937x_enable_rx1()
832 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_enable_rx1()
844 static int wcd937x_enable_rx2(struct snd_soc_dapm_widget *w, in wcd937x_enable_rx2()
845 struct snd_kcontrol *kcontrol, int event) in wcd937x_enable_rx2()
847 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_enable_rx2()
859 static int wcd937x_enable_rx3(struct snd_soc_dapm_widget *w, in wcd937x_enable_rx3()
861 int event) in wcd937x_enable_rx3()
863 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_enable_rx3()
876 static int wcd937x_get_micb_vout_ctl_val(u32 micb_mv) in wcd937x_get_micb_vout_ctl_val()
880 return -EINVAL; in wcd937x_get_micb_vout_ctl_val()
883 return (micb_mv - 1000) / 50; in wcd937x_get_micb_vout_ctl_val()
886 static int wcd937x_tx_swr_ctrl(struct snd_soc_dapm_widget *w, in wcd937x_tx_swr_ctrl()
887 struct snd_kcontrol *kcontrol, int event) in wcd937x_tx_swr_ctrl()
889 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_tx_swr_ctrl()
894 if (event == SND_SOC_DAPM_PRE_PMU && strnstr(w->name, "ADC", sizeof("ADC"))) in wcd937x_tx_swr_ctrl()
895 if (w->shift == 1 && !use_amic3) in wcd937x_tx_swr_ctrl()
896 set_bit(AMIC2_BCS_ENABLE, &wcd937x->status_mask); in wcd937x_tx_swr_ctrl()
901 static int wcd937x_codec_enable_adc(struct snd_soc_dapm_widget *w, in wcd937x_codec_enable_adc()
902 struct snd_kcontrol *kcontrol, int event) in wcd937x_codec_enable_adc()
904 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_enable_adc()
909 atomic_inc(&wcd937x->ana_clk_count); in wcd937x_codec_enable_adc()
918 if (w->shift == 1 && test_bit(AMIC2_BCS_ENABLE, &wcd937x->status_mask)) in wcd937x_codec_enable_adc()
919 clear_bit(AMIC2_BCS_ENABLE, &wcd937x->status_mask); in wcd937x_codec_enable_adc()
929 static int wcd937x_enable_req(struct snd_soc_dapm_widget *w, in wcd937x_enable_req()
930 struct snd_kcontrol *kcontrol, int event) in wcd937x_enable_req()
932 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_enable_req()
966 atomic_dec(&wcd937x->ana_clk_count); in wcd937x_enable_req()
967 if (atomic_read(&wcd937x->ana_clk_count) <= 0) { in wcd937x_enable_req()
971 atomic_set(&wcd937x->ana_clk_count, 0); in wcd937x_enable_req()
983 static int wcd937x_codec_enable_dmic(struct snd_soc_dapm_widget *w, in wcd937x_codec_enable_dmic()
985 int event) in wcd937x_codec_enable_dmic()
987 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wcd937x_codec_enable_dmic()
990 switch (w->shift) { in wcd937x_codec_enable_dmic()
1004 dev_err(component->dev, "Invalid DMIC Selection\n"); in wcd937x_codec_enable_dmic()
1005 return -EINVAL; in wcd937x_codec_enable_dmic()
1025 static int wcd937x_micbias_control(struct snd_soc_component *component, in wcd937x_micbias_control()
1026 int micb_num, int req, bool is_dapm) in wcd937x_micbias_control()
1029 int micb_index = micb_num - 1; in wcd937x_micbias_control()
1032 if (micb_index < 0 || (micb_index > WCD937X_MAX_MICBIAS - 1)) { in wcd937x_micbias_control()
1033 dev_err(component->dev, "Invalid micbias index, micb_ind:%d\n", micb_index); in wcd937x_micbias_control()
1034 return -EINVAL; in wcd937x_micbias_control()
1047 dev_err(component->dev, "Invalid micbias number: %d\n", micb_num); in wcd937x_micbias_control()
1048 return -EINVAL; in wcd937x_micbias_control()
1051 mutex_lock(&wcd937x->micb_lock); in wcd937x_micbias_control()
1054 wcd937x->pullup_ref[micb_index]++; in wcd937x_micbias_control()
1055 if (wcd937x->pullup_ref[micb_index] == 1 && in wcd937x_micbias_control()
1056 wcd937x->micb_ref[micb_index] == 0) in wcd937x_micbias_control()
1061 if (wcd937x->pullup_ref[micb_index] > 0) in wcd937x_micbias_control()
1062 wcd937x->pullup_ref[micb_index]++; in wcd937x_micbias_control()
1063 if (wcd937x->pullup_ref[micb_index] == 0 && in wcd937x_micbias_control()
1064 wcd937x->micb_ref[micb_index] == 0) in wcd937x_micbias_control()
1069 wcd937x->micb_ref[micb_index]++; in wcd937x_micbias_control()
1070 atomic_inc(&wcd937x->ana_clk_count); in wcd937x_micbias_control()
1071 if (wcd937x->micb_ref[micb_index] == 1) { in wcd937x_micbias_control()
1091 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, in wcd937x_micbias_control()
1095 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, in wcd937x_micbias_control()
1100 atomic_dec(&wcd937x->ana_clk_count); in wcd937x_micbias_control()
1101 if (wcd937x->micb_ref[micb_index] > 0) in wcd937x_micbias_control()
1102 wcd937x->micb_ref[micb_index]--; in wcd937x_micbias_control()
1103 if (wcd937x->micb_ref[micb_index] == 0 && in wcd937x_micbias_control()
1104 wcd937x->pullup_ref[micb_index] > 0) in wcd937x_micbias_control()
1107 else if (wcd937x->micb_ref[micb_index] == 0 && in wcd937x_micbias_control()
1108 wcd937x->pullup_ref[micb_index] == 0) { in wcd937x_micbias_control()
1110 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, in wcd937x_micbias_control()
1116 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, in wcd937x_micbias_control()
1121 wcd_mbhc_event_notify(wcd937x->wcd_mbhc, in wcd937x_micbias_control()
1123 if (atomic_read(&wcd937x->ana_clk_count) <= 0) { in wcd937x_micbias_control()
1127 atomic_set(&wcd937x->ana_clk_count, 0); in wcd937x_micbias_control()
1131 mutex_unlock(&wcd937x->micb_lock); in wcd937x_micbias_control()
1136 static int __wcd937x_codec_enable_micbias(struct snd_soc_dapm_widget *w, in __wcd937x_codec_enable_micbias()
1137 int event) in __wcd937x_codec_enable_micbias()
1139 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in __wcd937x_codec_enable_micbias()
1140 int micb_num = w->shift; in __wcd937x_codec_enable_micbias()
1159 static int wcd937x_codec_enable_micbias(struct snd_soc_dapm_widget *w, in wcd937x_codec_enable_micbias()
1161 int event) in wcd937x_codec_enable_micbias()
1166 static int __wcd937x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w, in __wcd937x_codec_enable_micbias_pullup()
1167 int event) in __wcd937x_codec_enable_micbias_pullup()
1169 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in __wcd937x_codec_enable_micbias_pullup()
1170 int micb_num = w->shift; in __wcd937x_codec_enable_micbias_pullup()
1187 static int wcd937x_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w, in wcd937x_codec_enable_micbias_pullup()
1189 int event) in wcd937x_codec_enable_micbias_pullup()
1194 static int wcd937x_connect_port(struct wcd937x_sdw_priv *wcd, u8 port_idx, u8 ch_id, bool enable) in wcd937x_connect_port()
1196 struct sdw_port_config *port_config = &wcd->port_config[port_idx - 1]; in wcd937x_connect_port()
1197 const struct wcd937x_sdw_ch_info *ch_info = &wcd->ch_info[ch_id]; in wcd937x_connect_port()
1198 u8 port_num = ch_info->port_num; in wcd937x_connect_port()
1199 u8 ch_mask = ch_info->ch_mask; in wcd937x_connect_port()
1201 port_config->num = port_num; in wcd937x_connect_port()
1204 port_config->ch_mask |= ch_mask; in wcd937x_connect_port()
1206 port_config->ch_mask &= ~ch_mask; in wcd937x_connect_port()
1211 static int wcd937x_rx_hph_mode_get(struct snd_kcontrol *kcontrol, in wcd937x_rx_hph_mode_get()
1217 ucontrol->value.integer.value[0] = wcd937x->hph_mode; in wcd937x_rx_hph_mode_get()
1221 static int wcd937x_rx_hph_mode_put(struct snd_kcontrol *kcontrol, in wcd937x_rx_hph_mode_put()
1229 mode_val = ucontrol->value.enumerated.item[0]; in wcd937x_rx_hph_mode_put()
1234 if (mode_val == wcd937x->hph_mode) in wcd937x_rx_hph_mode_put()
1246 wcd937x->hph_mode = mode_val; in wcd937x_rx_hph_mode_put()
1250 dev_dbg(component->dev, "%s: Invalid HPH Mode\n", __func__); in wcd937x_rx_hph_mode_put()
1251 return -EINVAL; in wcd937x_rx_hph_mode_put()
1254 static int wcd937x_get_compander(struct snd_kcontrol *kcontrol, in wcd937x_get_compander()
1262 mc = (struct soc_mixer_control *)(kcontrol->private_value); in wcd937x_get_compander()
1263 hphr = mc->shift; in wcd937x_get_compander()
1265 ucontrol->value.integer.value[0] = hphr ? wcd937x->comp2_enable : in wcd937x_get_compander()
1266 wcd937x->comp1_enable; in wcd937x_get_compander()
1270 static int wcd937x_set_compander(struct snd_kcontrol *kcontrol, in wcd937x_set_compander()
1275 struct wcd937x_sdw_priv *wcd = wcd937x->sdw_priv[AIF1_PB]; in wcd937x_set_compander()
1276 int value = ucontrol->value.integer.value[0]; in wcd937x_set_compander()
1278 int portidx; in wcd937x_set_compander()
1281 mc = (struct soc_mixer_control *)(kcontrol->private_value); in wcd937x_set_compander()
1282 hphr = mc->shift; in wcd937x_set_compander()
1285 if (value == wcd937x->comp2_enable) in wcd937x_set_compander()
1288 wcd937x->comp2_enable = value; in wcd937x_set_compander()
1290 if (value == wcd937x->comp1_enable) in wcd937x_set_compander()
1293 wcd937x->comp1_enable = value; in wcd937x_set_compander()
1296 portidx = wcd->ch_info[mc->reg].port_num; in wcd937x_set_compander()
1299 wcd937x_connect_port(wcd, portidx, mc->reg, true); in wcd937x_set_compander()
1301 wcd937x_connect_port(wcd, portidx, mc->reg, false); in wcd937x_set_compander()
1306 static int wcd937x_get_swr_port(struct snd_kcontrol *kcontrol, in wcd937x_get_swr_port()
1309 struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; in wcd937x_get_swr_port()
1310 struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); in wcd937x_get_swr_port() local
1311 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(comp); in wcd937x_get_swr_port()
1313 int dai_id = mixer->shift; in wcd937x_get_swr_port()
1314 int ch_idx = mixer->reg; in wcd937x_get_swr_port()
1315 int portidx; in wcd937x_get_swr_port()
1317 wcd = wcd937x->sdw_priv[dai_id]; in wcd937x_get_swr_port()
1318 portidx = wcd->ch_info[ch_idx].port_num; in wcd937x_get_swr_port()
1320 ucontrol->value.integer.value[0] = wcd->port_enable[portidx]; in wcd937x_get_swr_port()
1325 static int wcd937x_set_swr_port(struct snd_kcontrol *kcontrol, in wcd937x_set_swr_port()
1328 struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; in wcd937x_set_swr_port()
1329 struct snd_soc_component *comp = snd_soc_kcontrol_component(kcontrol); in wcd937x_set_swr_port() local
1330 struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(comp); in wcd937x_set_swr_port()
1332 int dai_id = mixer->shift; in wcd937x_set_swr_port()
1333 int ch_idx = mixer->reg; in wcd937x_set_swr_port()
1334 int portidx; in wcd937x_set_swr_port()
1337 wcd = wcd937x->sdw_priv[dai_id]; in wcd937x_set_swr_port()
1339 portidx = wcd->ch_info[ch_idx].port_num; in wcd937x_set_swr_port()
1341 enable = ucontrol->value.integer.value[0]; in wcd937x_set_swr_port()
1343 if (enable == wcd->port_enable[portidx]) { in wcd937x_set_swr_port()
1348 wcd->port_enable[portidx] = enable; in wcd937x_set_swr_port()
1378 int *btn_low, int *btn_high, in wcd937x_mbhc_program_btn_thr()
1379 int num_btn, bool is_micbias) in wcd937x_mbhc_program_btn_thr()
1381 int i, vth; in wcd937x_mbhc_program_btn_thr()
1384 dev_err(component->dev, "%s: invalid number of buttons: %d\n", in wcd937x_mbhc_program_btn_thr()
1396 static bool wcd937x_mbhc_micb_en_status(struct snd_soc_component *component, int micb_num) in wcd937x_mbhc_micb_en_status()
1411 int pull_up_cur) in wcd937x_mbhc_hph_l_pull_up_control()
1422 static int wcd937x_mbhc_request_micbias(struct snd_soc_component *component, in wcd937x_mbhc_request_micbias()
1423 int micb_num, int req) in wcd937x_mbhc_request_micbias()
1444 static int wcd937x_mbhc_micb_adjust_voltage(struct snd_soc_component *component, in wcd937x_mbhc_micb_adjust_voltage()
1445 int req_volt, int micb_num) in wcd937x_mbhc_micb_adjust_voltage()
1448 int cur_vout_ctl, req_vout_ctl, micb_reg, micb_en, ret = 0; in wcd937x_mbhc_micb_adjust_voltage()
1461 return -EINVAL; in wcd937x_mbhc_micb_adjust_voltage()
1463 mutex_lock(&wcd937x->micb_lock); in wcd937x_mbhc_micb_adjust_voltage()
1468 * to avoid slow micbias ramp-up or down enable pull-up in wcd937x_mbhc_micb_adjust_voltage()
1469 * momentarily, change the micbias value and then re-enable in wcd937x_mbhc_micb_adjust_voltage()
1479 ret = -EINVAL; in wcd937x_mbhc_micb_adjust_voltage()
1508 mutex_unlock(&wcd937x->micb_lock); in wcd937x_mbhc_micb_adjust_voltage()
1512 static int wcd937x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_component *component, in wcd937x_mbhc_micb_ctrl_threshold_mic()
1513 int micb_num, bool req_en) in wcd937x_mbhc_micb_ctrl_threshold_mic()
1516 int micb_mv; in wcd937x_mbhc_micb_ctrl_threshold_mic()
1519 return -EINVAL; in wcd937x_mbhc_micb_ctrl_threshold_mic()
1525 if (wcd937x->micb2_mv >= WCD_MBHC_THR_HS_MICB_MV) in wcd937x_mbhc_micb_ctrl_threshold_mic()
1528 micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : wcd937x->micb2_mv; in wcd937x_mbhc_micb_ctrl_threshold_mic()
1538 int i; in wcd937x_mbhc_get_result_params()
1539 int val, val1; in wcd937x_mbhc_get_result_params()
1543 static const int minCode_param[] = { in wcd937x_mbhc_get_result_params()
1547 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MBHC_ZDET, 0x20, 0x20); in wcd937x_mbhc_get_result_params()
1549 regmap_read(wcd937x->regmap, WCD937X_ANA_MBHC_RESULT_2, &val); in wcd937x_mbhc_get_result_params()
1554 regmap_read(wcd937x->regmap, WCD937X_ANA_MBHC_RESULT_1, &val1); in wcd937x_mbhc_get_result_params()
1556 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MBHC_ZDET, 0x20, 0x00); in wcd937x_mbhc_get_result_params()
1564 dev_err(component->dev, "Impedance detect ramp error, c1=%d, x1=0x%x\n", in wcd937x_mbhc_get_result_params()
1569 denom = (x1 * d1) - (1 << (14 - noff)); in wcd937x_mbhc_get_result_params()
1575 dev_err(component->dev, "%s: d1=%d, c1=%d, x1=0x%x, z_val=%d (milliohm)\n", in wcd937x_mbhc_get_result_params()
1580 regmap_read(wcd937x->regmap, in wcd937x_mbhc_get_result_params()
1582 regmap_read(wcd937x->regmap, in wcd937x_mbhc_get_result_params()
1601 WCD937X_ZDET_MAXV_CTL_MASK, zdet_param->ldo_ctl); in wcd937x_mbhc_zdet_ramp()
1603 WCD937X_VTH_MASK, zdet_param->btn5); in wcd937x_mbhc_zdet_ramp()
1605 WCD937X_VTH_MASK, zdet_param->btn6); in wcd937x_mbhc_zdet_ramp()
1607 WCD937X_VTH_MASK, zdet_param->btn7); in wcd937x_mbhc_zdet_ramp()
1609 WCD937X_ZDET_RANGE_CTL_MASK, zdet_param->noff); in wcd937x_mbhc_zdet_ramp()
1611 0x0F, zdet_param->nshift); in wcd937x_mbhc_zdet_ramp()
1616 regmap_update_bits(wcd937x->regmap, in wcd937x_mbhc_zdet_ramp()
1618 wcd937x_mbhc_get_result_params(component, d1_a, zdet_param->noff, &zdet); in wcd937x_mbhc_zdet_ramp()
1619 regmap_update_bits(wcd937x->regmap, in wcd937x_mbhc_zdet_ramp()
1628 regmap_update_bits(wcd937x->regmap, in wcd937x_mbhc_zdet_ramp()
1630 wcd937x_mbhc_get_result_params(component, d1_a, zdet_param->noff, &zdet); in wcd937x_mbhc_zdet_ramp()
1631 regmap_update_bits(wcd937x->regmap, in wcd937x_mbhc_zdet_ramp()
1638 s32 *z_val, int flag_l_r) in wcd937x_wcd_mbhc_qfuse_cal()
1641 int q1_cal; in wcd937x_wcd_mbhc_qfuse_cal()
1650 q1_cal = (10000 - ((q1 & 0x7F) * 25)); in wcd937x_wcd_mbhc_qfuse_cal()
1663 int zMono, z_diff1, z_diff2; in wcd937x_wcd_mbhc_calc_impedance()
1688 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1692 /* For NO-jack, disable L_DET_EN before Z-det measurements */ in wcd937x_wcd_mbhc_calc_impedance()
1693 if (wcd937x->mbhc_cfg.hphl_swh) in wcd937x_wcd_mbhc_calc_impedance()
1694 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1698 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1704 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1746 zdet_param_ptr->noff == 0x6) || in wcd937x_wcd_mbhc_calc_impedance()
1775 dev_err(component->dev, in wcd937x_wcd_mbhc_calc_impedance()
1784 wcd_mbhc_set_hph_type(wcd937x->wcd_mbhc, WCD_MBHC_HPH_MONO); in wcd937x_wcd_mbhc_calc_impedance()
1801 /* Parallel of left Z and 9 ohm pull down resistor */ in wcd937x_wcd_mbhc_calc_impedance()
1803 z_diff1 = (z1ls > zMono) ? (z1ls - zMono) : (zMono - z1ls); in wcd937x_wcd_mbhc_calc_impedance()
1804 z_diff2 = ((*zl) > z1ls) ? ((*zl) - z1ls) : (z1ls - (*zl)); in wcd937x_wcd_mbhc_calc_impedance()
1806 wcd_mbhc_set_hph_type(wcd937x->wcd_mbhc, WCD_MBHC_HPH_STEREO); in wcd937x_wcd_mbhc_calc_impedance()
1808 wcd_mbhc_set_hph_type(wcd937x->wcd_mbhc, WCD_MBHC_HPH_MONO); in wcd937x_wcd_mbhc_calc_impedance()
1811 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1818 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1821 /* For NO-jack, re-enable L_DET_EN after Z-det measurements */ in wcd937x_wcd_mbhc_calc_impedance()
1822 if (wcd937x->mbhc_cfg.hphl_swh) in wcd937x_wcd_mbhc_calc_impedance()
1823 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1829 regmap_update_bits(wcd937x->regmap, in wcd937x_wcd_mbhc_calc_impedance()
1862 if (wcd937x->mbhc_cfg.moist_rref == R_OFF) { in wcd937x_mbhc_moisture_config()
1869 if (!wcd937x->mbhc_cfg.hphl_swh) { in wcd937x_mbhc_moisture_config()
1870 dev_err(component->dev, "%s: disable moisture detection for NC\n", in wcd937x_mbhc_moisture_config()
1878 WCD937X_M_RTH_CTL_MASK, wcd937x->mbhc_cfg.moist_rref); in wcd937x_mbhc_moisture_config()
1887 WCD937X_M_RTH_CTL_MASK, wcd937x->mbhc_cfg.moist_rref); in wcd937x_mbhc_moisture_detect_en()
1898 if (wcd937x->mbhc_cfg.moist_rref == R_OFF) { in wcd937x_mbhc_get_moisture_status()
1905 if (!wcd937x->mbhc_cfg.hphl_swh) { in wcd937x_mbhc_get_moisture_status()
1906 dev_err(component->dev, "%s: disable moisture detection for NC\n", in wcd937x_mbhc_get_moisture_status()
1954 static int wcd937x_get_hph_type(struct snd_kcontrol *kcontrol, in wcd937x_get_hph_type()
1960 ucontrol->value.integer.value[0] = wcd_mbhc_get_hph_type(wcd937x->wcd_mbhc); in wcd937x_get_hph_type()
1965 static int wcd937x_hph_impedance_get(struct snd_kcontrol *kcontrol, in wcd937x_hph_impedance_get()
1975 mc = (struct soc_mixer_control *)(kcontrol->private_value); in wcd937x_hph_impedance_get()
1976 hphr = mc->shift; in wcd937x_hph_impedance_get()
1977 wcd_mbhc_get_impedance(wcd937x->wcd_mbhc, &zl, &zr); in wcd937x_hph_impedance_get()
1978 ucontrol->value.integer.value[0] = hphr ? zr : zl; in wcd937x_hph_impedance_get()
1995 static int wcd937x_mbhc_init(struct snd_soc_component *component) in wcd937x_mbhc_init()
1998 struct wcd_mbhc_intr *intr_ids = &wcd937x->intr_ids; in wcd937x_mbhc_init()
2000 intr_ids->mbhc_sw_intr = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2002 intr_ids->mbhc_btn_press_intr = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2004 intr_ids->mbhc_btn_release_intr = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2006 intr_ids->mbhc_hs_ins_intr = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2008 intr_ids->mbhc_hs_rem_intr = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2010 intr_ids->hph_left_ocp = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2012 intr_ids->hph_right_ocp = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_mbhc_init()
2015 wcd937x->wcd_mbhc = wcd_mbhc_init(component, &mbhc_cb, intr_ids, wcd_mbhc_fields, true); in wcd937x_mbhc_init()
2016 if (IS_ERR(wcd937x->wcd_mbhc)) in wcd937x_mbhc_init()
2017 return PTR_ERR(wcd937x->wcd_mbhc); in wcd937x_mbhc_init()
2031 wcd_mbhc_deinit(wcd937x->wcd_mbhc); in wcd937x_mbhc_deinit()
2432 static int wcd937x_set_micbias_data(struct wcd937x_priv *wcd937x) in wcd937x_set_micbias_data()
2434 int vout_ctl[3]; in wcd937x_set_micbias_data()
2437 vout_ctl[0] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb1_mv); in wcd937x_set_micbias_data()
2438 vout_ctl[1] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb2_mv); in wcd937x_set_micbias_data()
2439 vout_ctl[2] = wcd937x_get_micb_vout_ctl_val(wcd937x->micb3_mv); in wcd937x_set_micbias_data()
2441 return -EINVAL; in wcd937x_set_micbias_data()
2443 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB1, WCD937X_ANA_MICB_VOUT, vout_ctl[0]); in wcd937x_set_micbias_data()
2444 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB2, WCD937X_ANA_MICB_VOUT, vout_ctl[1]); in wcd937x_set_micbias_data()
2445 regmap_update_bits(wcd937x->regmap, WCD937X_ANA_MICB3, WCD937X_ANA_MICB_VOUT, vout_ctl[2]); in wcd937x_set_micbias_data()
2450 static irqreturn_t wcd937x_wd_handle_irq(int irq, void *data) in wcd937x_wd_handle_irq()
2459 static int wcd_irq_chip_map(struct irq_domain *irqd, unsigned int virq, in wcd_irq_chip_map()
2473 static int wcd937x_irq_init(struct wcd937x_priv *wcd, struct device *dev) in wcd937x_irq_init()
2475 wcd->virq = irq_domain_add_linear(NULL, 1, &wcd_domain_ops, NULL); in wcd937x_irq_init()
2476 if (!(wcd->virq)) { in wcd937x_irq_init()
2478 return -EINVAL; in wcd937x_irq_init()
2481 return devm_regmap_add_irq_chip(dev, wcd->regmap, in wcd937x_irq_init()
2482 irq_create_mapping(wcd->virq, 0), in wcd937x_irq_init()
2484 &wcd->irq_chip); in wcd937x_irq_init()
2487 static int wcd937x_soc_codec_probe(struct snd_soc_component *component) in wcd937x_soc_codec_probe()
2491 struct sdw_slave *tx_sdw_dev = wcd937x->tx_sdw_dev; in wcd937x_soc_codec_probe()
2492 struct device *dev = component->dev; in wcd937x_soc_codec_probe()
2494 int i, ret; in wcd937x_soc_codec_probe()
2497 time_left = wait_for_completion_timeout(&tx_sdw_dev->initialization_complete, in wcd937x_soc_codec_probe()
2501 return -ETIMEDOUT; in wcd937x_soc_codec_probe()
2504 snd_soc_component_init_regmap(component, wcd937x->regmap); in wcd937x_soc_codec_probe()
2514 return -EINVAL; in wcd937x_soc_codec_probe()
2517 wcd937x->clsh_info = wcd_clsh_ctrl_alloc(component, WCD937X); in wcd937x_soc_codec_probe()
2518 if (IS_ERR(wcd937x->clsh_info)) { in wcd937x_soc_codec_probe()
2520 return PTR_ERR(wcd937x->clsh_info); in wcd937x_soc_codec_probe()
2523 wcd937x_io_init(wcd937x->regmap); in wcd937x_soc_codec_probe()
2526 regmap_write(wcd937x->regmap, (WCD937X_DIGITAL_INTR_LEVEL_0 + i), 0); in wcd937x_soc_codec_probe()
2530 wcd937x->hphr_pdm_wd_int = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_soc_codec_probe()
2532 wcd937x->hphl_pdm_wd_int = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_soc_codec_probe()
2534 wcd937x->aux_pdm_wd_int = regmap_irq_get_virq(wcd937x->irq_chip, in wcd937x_soc_codec_probe()
2538 ret = devm_request_threaded_irq(dev, wcd937x->hphr_pdm_wd_int, NULL, wcd937x_wd_handle_irq, in wcd937x_soc_codec_probe()
2540 "HPHR PDM WDOG INT", wcd937x); in wcd937x_soc_codec_probe()
2544 ret = devm_request_threaded_irq(dev, wcd937x->hphl_pdm_wd_int, NULL, wcd937x_wd_handle_irq, in wcd937x_soc_codec_probe()
2546 "HPHL PDM WDOG INT", wcd937x); in wcd937x_soc_codec_probe()
2550 ret = devm_request_threaded_irq(dev, wcd937x->aux_pdm_wd_int, NULL, wcd937x_wd_handle_irq, in wcd937x_soc_codec_probe()
2552 "AUX PDM WDOG INT", wcd937x); in wcd937x_soc_codec_probe()
2557 disable_irq_nosync(wcd937x->hphr_pdm_wd_int); in wcd937x_soc_codec_probe()
2558 disable_irq_nosync(wcd937x->hphl_pdm_wd_int); in wcd937x_soc_codec_probe()
2559 disable_irq_nosync(wcd937x->aux_pdm_wd_int); in wcd937x_soc_codec_probe()
2565 dev_err(component->dev, "Failed to add snd_ctls\n"); in wcd937x_soc_codec_probe()
2572 dev_err(component->dev, "Failed to add routes\n"); in wcd937x_soc_codec_probe()
2579 dev_err(component->dev, "mbhc initialization failed\n"); in wcd937x_soc_codec_probe()
2589 free_irq(wcd937x->aux_pdm_wd_int, wcd937x); in wcd937x_soc_codec_remove()
2590 free_irq(wcd937x->hphl_pdm_wd_int, wcd937x); in wcd937x_soc_codec_remove()
2591 free_irq(wcd937x->hphr_pdm_wd_int, wcd937x); in wcd937x_soc_codec_remove()
2593 wcd_clsh_ctrl_free(wcd937x->clsh_info); in wcd937x_soc_codec_remove()
2596 static int wcd937x_codec_set_jack(struct snd_soc_component *comp, in wcd937x_codec_set_jack() argument
2599 struct wcd937x_priv *wcd = dev_get_drvdata(comp->dev); in wcd937x_codec_set_jack()
2600 int ret = 0; in wcd937x_codec_set_jack()
2603 ret = wcd_mbhc_start(wcd->wcd_mbhc, &wcd->mbhc_cfg, jack); in wcd937x_codec_set_jack()
2605 wcd_mbhc_stop(wcd->wcd_mbhc); in wcd937x_codec_set_jack()
2626 struct device_node *np = dev->of_node; in wcd937x_dt_parse_micbias_info()
2628 int ret = 0; in wcd937x_dt_parse_micbias_info()
2630 ret = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val); in wcd937x_dt_parse_micbias_info()
2632 wcd->micb1_mv = prop_val / 1000; in wcd937x_dt_parse_micbias_info()
2636 ret = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val); in wcd937x_dt_parse_micbias_info()
2638 wcd->micb2_mv = prop_val / 1000; in wcd937x_dt_parse_micbias_info()
2642 ret = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val); in wcd937x_dt_parse_micbias_info()
2644 wcd->micb3_mv = prop_val / 1000; in wcd937x_dt_parse_micbias_info()
2651 int value; in wcd937x_swap_gnd_mic()
2656 value = gpiod_get_value(wcd937x->us_euro_gpio); in wcd937x_swap_gnd_mic()
2657 gpiod_set_value(wcd937x->us_euro_gpio, !value); in wcd937x_swap_gnd_mic()
2662 static int wcd937x_codec_hw_params(struct snd_pcm_substream *substream, in wcd937x_codec_hw_params()
2666 struct wcd937x_priv *wcd937x = dev_get_drvdata(dai->dev); in wcd937x_codec_hw_params()
2667 struct wcd937x_sdw_priv *wcd = wcd937x->sdw_priv[dai->id]; in wcd937x_codec_hw_params()
2672 static int wcd937x_codec_free(struct snd_pcm_substream *substream, in wcd937x_codec_free()
2675 struct wcd937x_priv *wcd937x = dev_get_drvdata(dai->dev); in wcd937x_codec_free()
2676 struct wcd937x_sdw_priv *wcd = wcd937x->sdw_priv[dai->id]; in wcd937x_codec_free()
2678 return sdw_stream_remove_slave(wcd->sdev, wcd->sruntime); in wcd937x_codec_free()
2681 static int wcd937x_codec_set_sdw_stream(struct snd_soc_dai *dai, in wcd937x_codec_set_sdw_stream()
2682 void *stream, int direction) in wcd937x_codec_set_sdw_stream()
2684 struct wcd937x_priv *wcd937x = dev_get_drvdata(dai->dev); in wcd937x_codec_set_sdw_stream()
2685 struct wcd937x_sdw_priv *wcd = wcd937x->sdw_priv[dai->id]; in wcd937x_codec_set_sdw_stream()
2687 wcd->sruntime = stream; in wcd937x_codec_set_sdw_stream()
2700 .name = "wcd937x-sdw-rx",
2713 .name = "wcd937x-sdw-tx",
2727 static int wcd937x_bind(struct device *dev) in wcd937x_bind()
2730 int ret; in wcd937x_bind()
2741 wcd937x->rxdev = wcd937x_sdw_device_get(wcd937x->rxnode); in wcd937x_bind()
2742 if (!wcd937x->rxdev) { in wcd937x_bind()
2744 return -EINVAL; in wcd937x_bind()
2747 wcd937x->sdw_priv[AIF1_PB] = dev_get_drvdata(wcd937x->rxdev); in wcd937x_bind()
2748 wcd937x->sdw_priv[AIF1_PB]->wcd937x = wcd937x; in wcd937x_bind()
2750 wcd937x->txdev = wcd937x_sdw_device_get(wcd937x->txnode); in wcd937x_bind()
2751 if (!wcd937x->txdev) { in wcd937x_bind()
2753 return -EINVAL; in wcd937x_bind()
2756 wcd937x->sdw_priv[AIF1_CAP] = dev_get_drvdata(wcd937x->txdev); in wcd937x_bind()
2757 wcd937x->sdw_priv[AIF1_CAP]->wcd937x = wcd937x; in wcd937x_bind()
2758 wcd937x->tx_sdw_dev = dev_to_sdw_dev(wcd937x->txdev); in wcd937x_bind()
2759 if (!wcd937x->tx_sdw_dev) { in wcd937x_bind()
2761 return -EINVAL; in wcd937x_bind()
2768 if (!device_link_add(wcd937x->rxdev, wcd937x->txdev, in wcd937x_bind()
2771 return -EINVAL; in wcd937x_bind()
2774 if (!device_link_add(dev, wcd937x->txdev, in wcd937x_bind()
2777 return -EINVAL; in wcd937x_bind()
2780 if (!device_link_add(dev, wcd937x->rxdev, in wcd937x_bind()
2783 return -EINVAL; in wcd937x_bind()
2786 wcd937x->regmap = dev_get_regmap(&wcd937x->tx_sdw_dev->dev, NULL); in wcd937x_bind()
2787 if (!wcd937x->regmap) { in wcd937x_bind()
2789 return -EINVAL; in wcd937x_bind()
2798 wcd937x->sdw_priv[AIF1_PB]->slave_irq = wcd937x->virq; in wcd937x_bind()
2799 wcd937x->sdw_priv[AIF1_CAP]->slave_irq = wcd937x->virq; in wcd937x_bind()
2820 device_link_remove(dev, wcd937x->txdev); in wcd937x_unbind()
2821 device_link_remove(dev, wcd937x->rxdev); in wcd937x_unbind()
2822 device_link_remove(wcd937x->rxdev, wcd937x->txdev); in wcd937x_unbind()
2824 mutex_destroy(&wcd937x->micb_lock); in wcd937x_unbind()
2832 static int wcd937x_add_slave_components(struct wcd937x_priv *wcd937x, in wcd937x_add_slave_components()
2836 struct device_node *np = dev->of_node; in wcd937x_add_slave_components()
2838 wcd937x->rxnode = of_parse_phandle(np, "qcom,rx-device", 0); in wcd937x_add_slave_components()
2839 if (!wcd937x->rxnode) { in wcd937x_add_slave_components()
2840 dev_err(dev, "Couldn't parse phandle to qcom,rx-device!\n"); in wcd937x_add_slave_components()
2841 return -ENODEV; in wcd937x_add_slave_components()
2843 of_node_get(wcd937x->rxnode); in wcd937x_add_slave_components()
2845 component_compare_of, wcd937x->rxnode); in wcd937x_add_slave_components()
2847 wcd937x->txnode = of_parse_phandle(np, "qcom,tx-device", 0); in wcd937x_add_slave_components()
2848 if (!wcd937x->txnode) { in wcd937x_add_slave_components()
2849 dev_err(dev, "Couldn't parse phandle to qcom,tx-device\n"); in wcd937x_add_slave_components()
2850 return -ENODEV; in wcd937x_add_slave_components()
2852 of_node_get(wcd937x->txnode); in wcd937x_add_slave_components()
2854 component_compare_of, wcd937x->txnode); in wcd937x_add_slave_components()
2859 static int wcd937x_probe(struct platform_device *pdev) in wcd937x_probe()
2862 struct device *dev = &pdev->dev; in wcd937x_probe()
2865 int ret; in wcd937x_probe()
2869 return -ENOMEM; in wcd937x_probe()
2872 mutex_init(&wcd937x->micb_lock); in wcd937x_probe()
2874 wcd937x->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in wcd937x_probe()
2875 if (IS_ERR(wcd937x->reset_gpio)) in wcd937x_probe()
2876 return dev_err_probe(dev, PTR_ERR(wcd937x->reset_gpio), in wcd937x_probe()
2879 wcd937x->us_euro_gpio = devm_gpiod_get_optional(dev, "us-euro", GPIOD_OUT_LOW); in wcd937x_probe()
2880 if (IS_ERR(wcd937x->us_euro_gpio)) in wcd937x_probe()
2881 return dev_err_probe(dev, PTR_ERR(wcd937x->us_euro_gpio), in wcd937x_probe()
2882 "us-euro swap Control GPIO not found\n"); in wcd937x_probe()
2884 cfg = &wcd937x->mbhc_cfg; in wcd937x_probe()
2885 cfg->swap_gnd_mic = wcd937x_swap_gnd_mic; in wcd937x_probe()
2887 wcd937x->supplies[0].supply = "vdd-rxtx"; in wcd937x_probe()
2888 wcd937x->supplies[1].supply = "vdd-px"; in wcd937x_probe()
2889 wcd937x->supplies[2].supply = "vdd-mic-bias"; in wcd937x_probe()
2890 wcd937x->supplies[3].supply = "vdd-buck"; in wcd937x_probe()
2892 ret = devm_regulator_bulk_get(dev, WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_probe()
2896 ret = regulator_bulk_enable(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_probe()
2898 regulator_bulk_free(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_probe()
2904 cfg->mbhc_micbias = MIC_BIAS_2; in wcd937x_probe()
2905 cfg->anc_micbias = MIC_BIAS_2; in wcd937x_probe()
2906 cfg->v_hs_max = WCD_MBHC_HS_V_MAX; in wcd937x_probe()
2907 cfg->num_btn = WCD937X_MBHC_MAX_BUTTONS; in wcd937x_probe()
2908 cfg->micb_mv = wcd937x->micb2_mv; in wcd937x_probe()
2909 cfg->linein_th = 5000; in wcd937x_probe()
2910 cfg->hs_thr = 1700; in wcd937x_probe()
2911 cfg->hph_thr = 50; in wcd937x_probe()
2913 wcd_dt_parse_mbhc_data(dev, &wcd937x->mbhc_cfg); in wcd937x_probe()
2935 regulator_bulk_disable(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_probe()
2936 regulator_bulk_free(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_probe()
2943 struct device *dev = &pdev->dev; in wcd937x_remove()
2946 component_master_del(&pdev->dev, &wcd937x_comp_ops); in wcd937x_remove()
2952 regulator_bulk_disable(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_remove()
2953 regulator_bulk_free(WCD937X_MAX_BULK_SUPPLY, wcd937x->supplies); in wcd937x_remove()
2958 { .compatible = "qcom,wcd9370-codec" },
2959 { .compatible = "qcom,wcd9375-codec" },