Lines Matching +full:micbias +full:- +full:pulse +full:- +full:time
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
3 // Copyright (c) 2017-2018, Linaro Limited
19 #include <sound/soc-dapm.h>
26 #include "wcd-clsh-v2.h"
28 #include <dt-bindings/sound/qcom,wcd9335.h>
99 #define WCD9335_CALCULATE_VOUT_D(req_mv) (((req_mv - 650) * 10) / 25)
405 {24000, -EINVAL},/* 24K */
547 "Class H Invalid", "Class-H Hi-Fi", "Class-H Low Power", "Class-AB",
548 "Class-H Hi-Fi Low Power"
608 static const DECLARE_TLV_DB_SCALE(digital_gain, -8400, 100, -8400);
1260 struct wcd9335_codec *wcd = dev_get_drvdata(w->dapm->dev); in slim_rx_mux_get()
1261 u32 port_id = w->shift; in slim_rx_mux_get()
1263 ucontrol->value.enumerated.item[0] = wcd->rx_port_value[port_id]; in slim_rx_mux_get()
1272 struct wcd9335_codec *wcd = dev_get_drvdata(w->dapm->dev); in slim_rx_mux_put()
1273 struct soc_enum *e = (struct soc_enum *)kc->private_value; in slim_rx_mux_put()
1275 u32 port_id = w->shift; in slim_rx_mux_put()
1277 if (wcd->rx_port_value[port_id] == ucontrol->value.enumerated.item[0]) in slim_rx_mux_put()
1280 wcd->rx_port_value[port_id] = ucontrol->value.enumerated.item[0]; in slim_rx_mux_put()
1283 list_del_init(&wcd->rx_chs[port_id].list); in slim_rx_mux_put()
1285 switch (wcd->rx_port_value[port_id]) { in slim_rx_mux_put()
1290 list_add_tail(&wcd->rx_chs[port_id].list, in slim_rx_mux_put()
1291 &wcd->dai[AIF1_PB].slim_ch_list); in slim_rx_mux_put()
1294 list_add_tail(&wcd->rx_chs[port_id].list, in slim_rx_mux_put()
1295 &wcd->dai[AIF2_PB].slim_ch_list); in slim_rx_mux_put()
1298 list_add_tail(&wcd->rx_chs[port_id].list, in slim_rx_mux_put()
1299 &wcd->dai[AIF3_PB].slim_ch_list); in slim_rx_mux_put()
1302 list_add_tail(&wcd->rx_chs[port_id].list, in slim_rx_mux_put()
1303 &wcd->dai[AIF4_PB].slim_ch_list); in slim_rx_mux_put()
1306 dev_err(wcd->dev, "Unknown AIF %d\n", wcd->rx_port_value[port_id]); in slim_rx_mux_put()
1310 snd_soc_dapm_mux_update_power(w->dapm, kc, wcd->rx_port_value[port_id], in slim_rx_mux_put()
1315 return -EINVAL; in slim_rx_mux_put()
1323 struct wcd9335_codec *wcd = dev_get_drvdata(dapm->dev); in slim_tx_mixer_get()
1326 (struct soc_mixer_control *)kc->private_value; in slim_tx_mixer_get()
1327 int dai_id = widget->shift; in slim_tx_mixer_get()
1328 int port_id = mixer->shift; in slim_tx_mixer_get()
1330 ucontrol->value.integer.value[0] = wcd->tx_port_value[port_id] == dai_id; in slim_tx_mixer_get()
1340 struct wcd9335_codec *wcd = dev_get_drvdata(widget->dapm->dev); in slim_tx_mixer_put()
1343 (struct soc_mixer_control *)kc->private_value; in slim_tx_mixer_put()
1344 int enable = ucontrol->value.integer.value[0]; in slim_tx_mixer_put()
1345 int dai_id = widget->shift; in slim_tx_mixer_put()
1346 int port_id = mixer->shift; in slim_tx_mixer_put()
1353 if (enable && wcd->tx_port_value[port_id] != dai_id) { in slim_tx_mixer_put()
1354 wcd->tx_port_value[port_id] = dai_id; in slim_tx_mixer_put()
1355 list_add_tail(&wcd->tx_chs[port_id].list, in slim_tx_mixer_put()
1356 &wcd->dai[dai_id].slim_ch_list); in slim_tx_mixer_put()
1357 } else if (!enable && wcd->tx_port_value[port_id] == dai_id) { in slim_tx_mixer_put()
1358 wcd->tx_port_value[port_id] = -1; in slim_tx_mixer_put()
1359 list_del_init(&wcd->tx_chs[port_id].list); in slim_tx_mixer_put()
1363 dev_err(wcd->dev, "Unknown AIF %d\n", dai_id); in slim_tx_mixer_put()
1364 return -EINVAL; in slim_tx_mixer_put()
1367 snd_soc_dapm_mixer_update_power(widget->dapm, kc, enable, update); in slim_tx_mixer_put()
1475 struct soc_enum *e = (struct soc_enum *)kc->private_value; in wcd9335_put_dec_enum()
1478 val = ucontrol->value.enumerated.item[0]; in wcd9335_put_dec_enum()
1480 switch (e->reg) { in wcd9335_put_dec_enum()
1509 return -EINVAL; in wcd9335_put_dec_enum()
1524 struct soc_enum *e = (struct soc_enum *)kc->private_value; in wcd9335_int_dem_inp_mux_put()
1529 val = ucontrol->value.enumerated.item[0]; in wcd9335_int_dem_inp_mux_put()
1531 if (e->reg == WCD9335_CDC_RX0_RX_PATH_SEC0) in wcd9335_int_dem_inp_mux_put()
1533 else if (e->reg == WCD9335_CDC_RX1_RX_PATH_SEC0) in wcd9335_int_dem_inp_mux_put()
1535 else if (e->reg == WCD9335_CDC_RX2_RX_PATH_SEC0) in wcd9335_int_dem_inp_mux_put()
1538 return -EINVAL; in wcd9335_int_dem_inp_mux_put()
1612 struct snd_soc_component *component = dai->component; in wcd9335_set_mix_interpolator_rate()
1613 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_set_mix_interpolator_rate()
1617 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) { in wcd9335_set_mix_interpolator_rate()
1623 if (val == (ch->shift + INTn_2_INP_SEL_RX0)) in wcd9335_set_mix_interpolator_rate()
1638 struct snd_soc_component *comp = dai->component; in wcd9335_set_prim_interpolator_rate()
1639 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_set_prim_interpolator_rate()
1644 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) { in wcd9335_set_prim_interpolator_rate()
1645 inp = ch->shift + INTn_1_MIX_INP_SEL_RX0; in wcd9335_set_prim_interpolator_rate()
1668 dev_info(wcd->dev, in wcd9335_set_prim_interpolator_rate()
1711 struct list_head *slim_ch_list = &dai_data->slim_ch_list; in wcd9335_slim_set_hw_params()
1712 struct slim_stream_config *cfg = &dai_data->sconfig; in wcd9335_slim_set_hw_params()
1717 cfg->ch_count = 0; in wcd9335_slim_set_hw_params()
1718 cfg->direction = direction; in wcd9335_slim_set_hw_params()
1719 cfg->port_mask = 0; in wcd9335_slim_set_hw_params()
1723 cfg->ch_count++; in wcd9335_slim_set_hw_params()
1724 payload |= 1 << ch->shift; in wcd9335_slim_set_hw_params()
1725 cfg->port_mask |= BIT(ch->port); in wcd9335_slim_set_hw_params()
1728 cfg->chs = kcalloc(cfg->ch_count, sizeof(unsigned int), GFP_KERNEL); in wcd9335_slim_set_hw_params()
1729 if (!cfg->chs) in wcd9335_slim_set_hw_params()
1730 return -ENOMEM; in wcd9335_slim_set_hw_params()
1734 cfg->chs[i++] = ch->ch_num; in wcd9335_slim_set_hw_params()
1737 ret = regmap_write(wcd->if_regmap, in wcd9335_slim_set_hw_params()
1738 WCD9335_SLIM_PGD_RX_PORT_MULTI_CHNL_0(ch->port), in wcd9335_slim_set_hw_params()
1745 ret = regmap_write(wcd->if_regmap, in wcd9335_slim_set_hw_params()
1746 WCD9335_SLIM_PGD_RX_PORT_CFG(ch->port), in wcd9335_slim_set_hw_params()
1751 ret = regmap_write(wcd->if_regmap, in wcd9335_slim_set_hw_params()
1752 WCD9335_SLIM_PGD_TX_PORT_MULTI_CHNL_0(ch->port), in wcd9335_slim_set_hw_params()
1758 ret = regmap_write(wcd->if_regmap, in wcd9335_slim_set_hw_params()
1759 WCD9335_SLIM_PGD_TX_PORT_MULTI_CHNL_1(ch->port), in wcd9335_slim_set_hw_params()
1765 ret = regmap_write(wcd->if_regmap, in wcd9335_slim_set_hw_params()
1766 WCD9335_SLIM_PGD_TX_PORT_CFG(ch->port), in wcd9335_slim_set_hw_params()
1774 dai_data->sruntime = slim_stream_allocate(wcd->slim, "WCD9335-SLIM"); in wcd9335_slim_set_hw_params()
1779 dev_err(wcd->dev, "Error Setting slim hw params\n"); in wcd9335_slim_set_hw_params()
1780 kfree(cfg->chs); in wcd9335_slim_set_hw_params()
1781 cfg->chs = NULL; in wcd9335_slim_set_hw_params()
1789 struct snd_soc_component *comp = dai->component; in wcd9335_set_decimator_rate()
1794 int decimator = -1; in wcd9335_set_decimator_rate()
1796 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) { in wcd9335_set_decimator_rate()
1797 tx_port = ch->port; in wcd9335_set_decimator_rate()
1799 dev_err(wcd->dev, "Invalid SLIM TX%u port DAI ID:%d\n", in wcd9335_set_decimator_rate()
1800 tx_port, dai->id); in wcd9335_set_decimator_rate()
1801 return -EINVAL; in wcd9335_set_decimator_rate()
1803 /* Find the SB TX MUX input - which decimator is connected */ in wcd9335_set_decimator_rate()
1810 shift = ((tx_port - 4) << 1); in wcd9335_set_decimator_rate()
1814 shift = ((tx_port - 8) << 1); in wcd9335_set_decimator_rate()
1838 decimator = tx_mux_sel - 1; in wcd9335_set_decimator_rate()
1851 dev_err(wcd->dev, "RX_MIX_TX%u going to SLIM TX%u\n", in wcd9335_set_decimator_rate()
1854 dev_err(wcd->dev, "ERROR: Invalid decimator: %d\n", in wcd9335_set_decimator_rate()
1856 return -EINVAL; in wcd9335_set_decimator_rate()
1870 wcd = snd_soc_component_get_drvdata(dai->component); in wcd9335_hw_params()
1872 switch (substream->stream) { in wcd9335_hw_params()
1876 dev_err(wcd->dev, "cannot set sample rate: %u\n", in wcd9335_hw_params()
1882 wcd->dai[dai->id].sconfig.bps = params_width(params); in wcd9335_hw_params()
1885 dev_err(wcd->dev, "%s: Invalid format 0x%x\n", in wcd9335_hw_params()
1887 return -EINVAL; in wcd9335_hw_params()
1915 dev_err(wcd->dev, "%s: Invalid TX sample rate: %d\n", in wcd9335_hw_params()
1917 return -EINVAL; in wcd9335_hw_params()
1924 dev_err(wcd->dev, "Cannot set TX Decimator rate\n"); in wcd9335_hw_params()
1929 wcd->dai[dai->id].sconfig.bps = params_width(params); in wcd9335_hw_params()
1932 dev_err(wcd->dev, "%s: Invalid format 0x%x\n", in wcd9335_hw_params()
1934 return -EINVAL; in wcd9335_hw_params()
1938 dev_err(wcd->dev, "Invalid stream type %d\n", in wcd9335_hw_params()
1939 substream->stream); in wcd9335_hw_params()
1940 return -EINVAL; in wcd9335_hw_params()
1943 wcd->dai[dai->id].sconfig.rate = params_rate(params); in wcd9335_hw_params()
1944 wcd9335_slim_set_hw_params(wcd, &wcd->dai[dai->id], substream->stream); in wcd9335_hw_params()
1956 wcd = snd_soc_component_get_drvdata(dai->component); in wcd9335_trigger()
1958 dai_data = &wcd->dai[dai->id]; in wcd9335_trigger()
1964 cfg = &dai_data->sconfig; in wcd9335_trigger()
1965 slim_stream_prepare(dai_data->sruntime, cfg); in wcd9335_trigger()
1966 slim_stream_enable(dai_data->sruntime); in wcd9335_trigger()
1971 slim_stream_disable(dai_data->sruntime); in wcd9335_trigger()
1972 slim_stream_unprepare(dai_data->sruntime); in wcd9335_trigger()
1990 wcd = snd_soc_component_get_drvdata(dai->component); in wcd9335_set_channel_map()
1993 dev_err(wcd->dev, "Invalid tx_slot=%p, rx_slot=%p\n", in wcd9335_set_channel_map()
1995 return -EINVAL; in wcd9335_set_channel_map()
1998 wcd->num_rx_port = rx_num; in wcd9335_set_channel_map()
2000 wcd->rx_chs[i].ch_num = rx_slot[i]; in wcd9335_set_channel_map()
2001 INIT_LIST_HEAD(&wcd->rx_chs[i].list); in wcd9335_set_channel_map()
2004 wcd->num_tx_port = tx_num; in wcd9335_set_channel_map()
2006 wcd->tx_chs[i].ch_num = tx_slot[i]; in wcd9335_set_channel_map()
2007 INIT_LIST_HEAD(&wcd->tx_chs[i].list); in wcd9335_set_channel_map()
2021 wcd = snd_soc_component_get_drvdata(dai->component); in wcd9335_get_channel_map()
2023 switch (dai->id) { in wcd9335_get_channel_map()
2029 dev_err(wcd->dev, "Invalid rx_slot %p or rx_num %p\n", in wcd9335_get_channel_map()
2031 return -EINVAL; in wcd9335_get_channel_map()
2034 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) in wcd9335_get_channel_map()
2035 rx_slot[i++] = ch->ch_num; in wcd9335_get_channel_map()
2043 dev_err(wcd->dev, "Invalid tx_slot %p or tx_num %p\n", in wcd9335_get_channel_map()
2045 return -EINVAL; in wcd9335_get_channel_map()
2047 list_for_each_entry(ch, &wcd->dai[dai->id].slim_ch_list, list) in wcd9335_get_channel_map()
2048 tx_slot[i++] = ch->ch_num; in wcd9335_get_channel_map()
2053 dev_err(wcd->dev, "Invalid DAI ID %x\n", dai->id); in wcd9335_get_channel_map()
2177 int comp = ((struct soc_mixer_control *)kc->private_value)->shift; in wcd9335_get_compander()
2178 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_get_compander()
2180 ucontrol->value.integer.value[0] = wcd->comp_enabled[comp]; in wcd9335_get_compander()
2188 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_set_compander()
2189 int comp = ((struct soc_mixer_control *) kc->private_value)->shift; in wcd9335_set_compander()
2190 int value = ucontrol->value.integer.value[0]; in wcd9335_set_compander()
2193 wcd->comp_enabled[comp] = value; in wcd9335_set_compander()
2227 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_rx_hph_mode_get()
2229 ucontrol->value.enumerated.item[0] = wcd->hph_mode; in wcd9335_rx_hph_mode_get()
2238 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_rx_hph_mode_put()
2241 mode_val = ucontrol->value.enumerated.item[0]; in wcd9335_rx_hph_mode_put()
2244 dev_err(wcd->dev, "Invalid HPH Mode, default to ClSH HiFi\n"); in wcd9335_rx_hph_mode_put()
2247 wcd->hph_mode = mode_val; in wcd9335_rx_hph_mode_put()
2253 /* -84dB min - 40dB max */
2255 -84, 40, digital_gain),
2257 -84, 40, digital_gain),
2259 -84, 40, digital_gain),
2261 -84, 40, digital_gain),
2263 -84, 40, digital_gain),
2265 -84, 40, digital_gain),
2267 -84, 40, digital_gain),
2269 -84, 40, digital_gain),
2271 -84, 40, digital_gain),
2273 -84, 40, digital_gain),
2275 -84, 40, digital_gain),
2277 -84, 40, digital_gain),
2279 -84, 40, digital_gain),
2281 -84, 40, digital_gain),
2283 -84, 40, digital_gain),
2285 -84, 40, digital_gain),
2287 -84, 40, digital_gain),
2289 -84, 40, digital_gain),
2497 int micb_index = micb_num - 1; in wcd9335_micbias_control()
2500 if ((micb_index < 0) || (micb_index > WCD9335_MAX_MICBIAS - 1)) { in wcd9335_micbias_control()
2501 dev_err(wcd->dev, "Invalid micbias index, micb_ind:%d\n", in wcd9335_micbias_control()
2503 return -EINVAL; in wcd9335_micbias_control()
2520 dev_err(component->dev, "%s: Invalid micbias number: %d\n", in wcd9335_micbias_control()
2522 return -EINVAL; in wcd9335_micbias_control()
2527 wcd->pullup_ref[micb_index]++; in wcd9335_micbias_control()
2528 if ((wcd->pullup_ref[micb_index] == 1) && in wcd9335_micbias_control()
2529 (wcd->micb_ref[micb_index] == 0)) in wcd9335_micbias_control()
2534 wcd->pullup_ref[micb_index]--; in wcd9335_micbias_control()
2535 if ((wcd->pullup_ref[micb_index] == 0) && in wcd9335_micbias_control()
2536 (wcd->micb_ref[micb_index] == 0)) in wcd9335_micbias_control()
2541 wcd->micb_ref[micb_index]++; in wcd9335_micbias_control()
2542 if (wcd->micb_ref[micb_index] == 1) in wcd9335_micbias_control()
2547 wcd->micb_ref[micb_index]--; in wcd9335_micbias_control()
2548 if ((wcd->micb_ref[micb_index] == 0) && in wcd9335_micbias_control()
2549 (wcd->pullup_ref[micb_index] > 0)) in wcd9335_micbias_control()
2552 else if ((wcd->micb_ref[micb_index] == 0) && in wcd9335_micbias_control()
2553 (wcd->pullup_ref[micb_index] == 0)) { in wcd9335_micbias_control()
2566 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in __wcd9335_codec_enable_micbias()
2569 if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1"))) in __wcd9335_codec_enable_micbias()
2571 else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2"))) in __wcd9335_codec_enable_micbias()
2573 else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3"))) in __wcd9335_codec_enable_micbias()
2575 else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4"))) in __wcd9335_codec_enable_micbias()
2578 return -EINVAL; in __wcd9335_codec_enable_micbias()
2584 * so use ref count to handle micbias pullup in __wcd9335_codec_enable_micbias()
2590 /* wait for cnp time */ in __wcd9335_codec_enable_micbias()
2636 dev_err(comp->dev, "%s: invalid amic: %d\n", in wcd9335_codec_set_tx_hold()
2645 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_adc()
2649 wcd9335_codec_set_tx_hold(comp, w->reg, true); in wcd9335_codec_enable_adc()
2673 reg = WCD9335_CDC_TX_INP_MUX_ADC_MUX4_CFG0 + adc_mux_n - 4; in wcd9335_codec_find_amic_input()
2705 dev_err(comp->dev, "invalid amic: %d\n", amic); in wcd9335_codec_get_amic_pwlvl_reg()
2715 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_dec()
2725 char *wname __free(kfree) = kmemdup_nul(w->name, 15, GFP_KERNEL); in wcd9335_codec_enable_dec()
2727 return -ENOMEM; in wcd9335_codec_enable_dec()
2732 dev_err(comp->dev, "%s: Invalid decimator = %s\n", in wcd9335_codec_enable_dec()
2733 __func__, w->name); in wcd9335_codec_enable_dec()
2734 return -EINVAL; in wcd9335_codec_enable_dec()
2740 dev_err(comp->dev, "%s: decimator index not found\n", in wcd9335_codec_enable_dec()
2742 return -EINVAL; in wcd9335_codec_enable_dec()
2747 dev_err(comp->dev, "%s: Invalid decimator = %s\n", in wcd9335_codec_enable_dec()
2749 return -EINVAL; in wcd9335_codec_enable_dec()
2856 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_dmic()
2866 wname = strpbrk(w->name, "012345"); in wcd9335_codec_enable_dmic()
2868 dev_err(comp->dev, "%s: widget not found\n", __func__); in wcd9335_codec_enable_dmic()
2869 return -EINVAL; in wcd9335_codec_enable_dmic()
2874 dev_err(comp->dev, "%s: Invalid DMIC line on the codec\n", in wcd9335_codec_enable_dmic()
2876 return -EINVAL; in wcd9335_codec_enable_dmic()
2882 dmic_clk_cnt = &(wcd->dmic_0_1_clk_cnt); in wcd9335_codec_enable_dmic()
2887 dmic_clk_cnt = &(wcd->dmic_2_3_clk_cnt); in wcd9335_codec_enable_dmic()
2892 dmic_clk_cnt = &(wcd->dmic_4_5_clk_cnt); in wcd9335_codec_enable_dmic()
2896 dev_err(comp->dev, "%s: Invalid DMIC Selection\n", in wcd9335_codec_enable_dmic()
2898 return -EINVAL; in wcd9335_codec_enable_dmic()
2903 dmic_rate_val = wcd9335_get_dmic_clk_val(comp, wcd->mclk_rate); in wcd9335_codec_enable_dmic()
2915 dmic_rate_val = wcd9335_get_dmic_clk_val(comp, wcd->mclk_rate); in wcd9335_codec_enable_dmic()
2916 (*dmic_clk_cnt)--; in wcd9335_codec_enable_dmic()
2936 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_codec_enable_int_port()
2939 list_for_each_entry(ch, &dai->slim_ch_list, list) { in wcd9335_codec_enable_int_port()
2940 if (ch->port >= WCD9335_RX_START) { in wcd9335_codec_enable_int_port()
2941 port_num = ch->port - WCD9335_RX_START; in wcd9335_codec_enable_int_port()
2944 port_num = ch->port; in wcd9335_codec_enable_int_port()
2948 regmap_read(wcd->if_regmap, reg, &val); in wcd9335_codec_enable_int_port()
2950 regmap_write(wcd->if_regmap, reg, in wcd9335_codec_enable_int_port()
2959 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_slim()
2961 struct wcd_slim_codec_dai_data *dai = &wcd->dai[w->shift]; in wcd9335_codec_enable_slim()
2968 kfree(dai->sconfig.chs); in wcd9335_codec_enable_slim()
2979 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_mix_path()
2983 switch (w->reg) { in wcd9335_codec_enable_mix_path()
3012 dev_err(comp->dev, "%s: No gain register avail for %s\n", in wcd9335_codec_enable_mix_path()
3013 __func__, w->name); in wcd9335_codec_enable_mix_path()
3128 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_enable_prim_interpolator()
3134 wcd->prim_int_users[ind]++; in wcd9335_codec_enable_prim_interpolator()
3135 if (wcd->prim_int_users[ind] == 1) { in wcd9335_codec_enable_prim_interpolator()
3153 wcd->prim_int_users[ind]--; in wcd9335_codec_enable_prim_interpolator()
3154 if (wcd->prim_int_users[ind] == 0) { in wcd9335_codec_enable_prim_interpolator()
3175 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_config_compander()
3183 comp = interp_n - 1; in wcd9335_config_compander()
3184 if (!wcd->comp_enabled[comp]) in wcd9335_config_compander()
3236 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_interpolator()
3269 dev_err(comp->dev, "%s: Interpolator reg not found\n", in wcd9335_codec_enable_interpolator()
3271 return -EINVAL; in wcd9335_codec_enable_interpolator()
3280 wcd9335_config_compander(comp, w->shift, event); in wcd9335_codec_enable_interpolator()
3285 wcd9335_config_compander(comp, w->shift, event); in wcd9335_codec_enable_interpolator()
3296 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_codec_hph_mode_gain_opt()
3320 wcd->hph_l_gain = hph_l_en & 0x1F; in wcd9335_codec_hph_mode_gain_opt()
3325 wcd->hph_r_gain = hph_r_en & 0x1F; in wcd9335_codec_hph_mode_gain_opt()
3470 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_hphl_dac_event()
3471 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_hphl_dac_event()
3472 int hph_mode = wcd->hph_mode; in wcd9335_codec_hphl_dac_event()
3482 dev_err(comp->dev, "Incorrect DEM Input\n"); in wcd9335_codec_hphl_dac_event()
3483 return -EINVAL; in wcd9335_codec_hphl_dac_event()
3485 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_PRE_DAC, in wcd9335_codec_hphl_dac_event()
3502 if (!(wcd_clsh_ctrl_get_state(wcd->clsh_ctrl) & in wcd9335_codec_hphl_dac_event()
3506 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_POST_PA, in wcd9335_codec_hphl_dac_event()
3519 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_lineout_dac_event()
3520 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_lineout_dac_event()
3524 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_PRE_DAC, in wcd9335_codec_lineout_dac_event()
3528 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_POST_PA, in wcd9335_codec_lineout_dac_event()
3539 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_ear_dac_event()
3540 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_ear_dac_event()
3544 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_PRE_DAC, in wcd9335_codec_ear_dac_event()
3549 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_POST_PA, in wcd9335_codec_ear_dac_event()
3579 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3584 if (wcd->comp_enabled[COMPANDER_1] || in wcd9335_codec_hph_post_pa_config()
3585 wcd->comp_enabled[COMPANDER_2]) { in wcd9335_codec_hph_post_pa_config()
3587 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3591 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3595 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3600 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3603 wcd->hph_l_gain); in wcd9335_codec_hph_post_pa_config()
3604 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3607 wcd->hph_r_gain); in wcd9335_codec_hph_post_pa_config()
3611 snd_soc_component_update_bits(wcd->component, in wcd9335_codec_hph_post_pa_config()
3621 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_hphr_dac_event()
3622 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_hphr_dac_event()
3623 int hph_mode = wcd->hph_mode; in wcd9335_codec_hphr_dac_event()
3635 dev_err(comp->dev, "DEM Input not set correctly, hph_mode: %d\n", in wcd9335_codec_hphr_dac_event()
3637 return -EINVAL; in wcd9335_codec_hphr_dac_event()
3640 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, in wcd9335_codec_hphr_dac_event()
3653 if (!(wcd_clsh_ctrl_get_state(wcd->clsh_ctrl) & in wcd9335_codec_hphr_dac_event()
3657 wcd_clsh_ctrl_set_state(wcd->clsh_ctrl, WCD_CLSH_EVENT_POST_PA, in wcd9335_codec_hphr_dac_event()
3670 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_hphl_pa()
3671 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_enable_hphl_pa()
3672 int hph_mode = wcd->hph_mode; in wcd9335_codec_enable_hphl_pa()
3718 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_lineout_pa()
3721 if (w->reg == WCD9335_ANA_LO_1_2) { in wcd9335_codec_enable_lineout_pa()
3722 if (w->shift == 7) { in wcd9335_codec_enable_lineout_pa()
3725 } else if (w->shift == 6) { in wcd9335_codec_enable_lineout_pa()
3729 } else if (w->reg == WCD9335_ANA_LO_3_4) { in wcd9335_codec_enable_lineout_pa()
3730 if (w->shift == 7) { in wcd9335_codec_enable_lineout_pa()
3733 } else if (w->shift == 6) { in wcd9335_codec_enable_lineout_pa()
3738 dev_err(comp->dev, "Error enabling lineout PA\n"); in wcd9335_codec_enable_lineout_pa()
3739 return -EINVAL; in wcd9335_codec_enable_lineout_pa()
3789 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_rx_bias()
3790 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_enable_rx_bias()
3794 wcd->rx_bias_count++; in wcd9335_codec_enable_rx_bias()
3795 if (wcd->rx_bias_count == 1) { in wcd9335_codec_enable_rx_bias()
3804 wcd->rx_bias_count--; in wcd9335_codec_enable_rx_bias()
3805 if (!wcd->rx_bias_count) in wcd9335_codec_enable_rx_bias()
3819 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_hphr_pa()
3820 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_enable_hphr_pa()
3821 int hph_mode = wcd->hph_mode; in wcd9335_codec_enable_hphr_pa()
3865 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_ear_pa()
3910 regmap_read(wcd->if_regmap, i, &val); in wcd9335_slimbus_irq()
3916 port_id = (tx ? j - 16 : j); in wcd9335_slimbus_irq()
3917 regmap_read(wcd->if_regmap, in wcd9335_slimbus_irq()
3927 wcd->if_regmap, reg, &int_val); in wcd9335_slimbus_irq()
3937 dev_err_ratelimited(wcd->dev, in wcd9335_slimbus_irq()
3942 dev_err_ratelimited(wcd->dev, in wcd9335_slimbus_irq()
3955 wcd->if_regmap, reg, &int_val); in wcd9335_slimbus_irq()
3958 regmap_write(wcd->if_regmap, in wcd9335_slimbus_irq()
3963 regmap_write(wcd->if_regmap, in wcd9335_slimbus_irq()
3985 irq = regmap_irq_get_virq(wcd->irq_data, wcd9335_irqs[i].irq); in wcd9335_setup_irqs()
3987 dev_err(wcd->dev, "Failed to get %s\n", in wcd9335_setup_irqs()
3992 ret = devm_request_threaded_irq(wcd->dev, irq, NULL, in wcd9335_setup_irqs()
3998 dev_err(wcd->dev, "Failed to request %s\n", in wcd9335_setup_irqs()
4006 regmap_write(wcd->if_regmap, WCD9335_SLIM_PGD_PORT_INT_EN0 + i, in wcd9335_setup_irqs()
4018 regmap_write(wcd->if_regmap, WCD9335_SLIM_PGD_PORT_INT_EN0 + i, in wcd9335_teardown_irqs()
4025 struct snd_soc_component *comp = wcd->component; in wcd9335_cdc_sido_ccl_enable()
4028 if (++wcd->sido_ccl_cnt == 1) in wcd9335_cdc_sido_ccl_enable()
4032 if (wcd->sido_ccl_cnt == 0) { in wcd9335_cdc_sido_ccl_enable()
4033 dev_err(wcd->dev, "sido_ccl already disabled\n"); in wcd9335_cdc_sido_ccl_enable()
4036 if (--wcd->sido_ccl_cnt == 0) in wcd9335_cdc_sido_ccl_enable()
4044 wcd->master_bias_users++; in wcd9335_enable_master_bias()
4045 if (wcd->master_bias_users == 1) { in wcd9335_enable_master_bias()
4046 regmap_update_bits(wcd->regmap, WCD9335_ANA_BIAS, in wcd9335_enable_master_bias()
4049 regmap_update_bits(wcd->regmap, WCD9335_ANA_BIAS, in wcd9335_enable_master_bias()
4053 * 1ms delay is required after pre-charge is enabled in wcd9335_enable_master_bias()
4057 regmap_update_bits(wcd->regmap, WCD9335_ANA_BIAS, in wcd9335_enable_master_bias()
4060 regmap_update_bits(wcd->regmap, WCD9335_ANA_BIAS, in wcd9335_enable_master_bias()
4071 if (wcd->master_bias_users <= 0) in wcd9335_enable_mclk()
4072 return -EINVAL; in wcd9335_enable_mclk()
4074 if (((wcd->clk_mclk_users == 0) && (wcd->clk_type == WCD_CLK_MCLK)) || in wcd9335_enable_mclk()
4075 ((wcd->clk_mclk_users > 0) && (wcd->clk_type != WCD_CLK_MCLK))) { in wcd9335_enable_mclk()
4076 dev_err(wcd->dev, "Error enabling MCLK, clk_type: %d\n", in wcd9335_enable_mclk()
4077 wcd->clk_type); in wcd9335_enable_mclk()
4078 return -EINVAL; in wcd9335_enable_mclk()
4081 if (++wcd->clk_mclk_users == 1) { in wcd9335_enable_mclk()
4082 regmap_update_bits(wcd->regmap, WCD9335_ANA_CLK_TOP, in wcd9335_enable_mclk()
4085 regmap_update_bits(wcd->regmap, WCD9335_ANA_CLK_TOP, in wcd9335_enable_mclk()
4088 regmap_update_bits(wcd->regmap, WCD9335_ANA_CLK_TOP, in wcd9335_enable_mclk()
4091 regmap_update_bits(wcd->regmap, in wcd9335_enable_mclk()
4095 regmap_update_bits(wcd->regmap, in wcd9335_enable_mclk()
4106 wcd->clk_type = WCD_CLK_MCLK; in wcd9335_enable_mclk()
4113 if (wcd->clk_mclk_users <= 0) in wcd9335_disable_mclk()
4114 return -EINVAL; in wcd9335_disable_mclk()
4116 if (--wcd->clk_mclk_users == 0) { in wcd9335_disable_mclk()
4117 if (wcd->clk_rco_users > 0) { in wcd9335_disable_mclk()
4119 regmap_update_bits(wcd->regmap, WCD9335_ANA_CLK_TOP, in wcd9335_disable_mclk()
4122 wcd->clk_type = WCD_CLK_RCO; in wcd9335_disable_mclk()
4124 regmap_update_bits(wcd->regmap, WCD9335_ANA_CLK_TOP, in wcd9335_disable_mclk()
4127 wcd->clk_type = WCD_CLK_OFF; in wcd9335_disable_mclk()
4130 regmap_update_bits(wcd->regmap, WCD9335_ANA_CLK_TOP, in wcd9335_disable_mclk()
4140 if (wcd->master_bias_users <= 0) in wcd9335_disable_master_bias()
4141 return -EINVAL; in wcd9335_disable_master_bias()
4143 wcd->master_bias_users--; in wcd9335_disable_master_bias()
4144 if (wcd->master_bias_users == 0) { in wcd9335_disable_master_bias()
4145 regmap_update_bits(wcd->regmap, WCD9335_ANA_BIAS, in wcd9335_disable_master_bias()
4148 regmap_update_bits(wcd->regmap, WCD9335_ANA_BIAS, in wcd9335_disable_master_bias()
4162 ret = clk_prepare_enable(wcd->mclk); in wcd9335_cdc_req_mclk_enable()
4164 dev_err(wcd->dev, "%s: ext clk enable failed\n", in wcd9335_cdc_req_mclk_enable()
4178 clk_disable_unprepare(wcd->mclk); in wcd9335_cdc_req_mclk_enable()
4188 struct snd_soc_component *comp = wcd->component; in wcd9335_codec_apply_sido_voltage()
4191 if (req_mv == wcd->sido_voltage) in wcd9335_codec_apply_sido_voltage()
4204 wcd->sido_voltage = req_mv; in wcd9335_codec_apply_sido_voltage()
4218 dev_err(wcd->dev, "Ext clk enable failed\n"); in wcd9335_codec_update_sido_voltage()
4232 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in _wcd9335_codec_enable_mclk()
4244 wcd->sido_voltage); in _wcd9335_codec_enable_mclk()
4254 struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm); in wcd9335_codec_enable_mclk()
4723 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_enable_sido_buck()
4738 wcd->sido_input_src = SIDO_SOURCE_RCO_BG; in wcd9335_enable_sido_buck()
4767 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_codec_init()
4771 regmap_update_bits(wcd->regmap, WCD9335_CODEC_RPM_CLK_GATE, in wcd9335_codec_init()
4774 regmap_update_bits(wcd->regmap, WCD9335_CODEC_RPM_CLK_MCLK_CFG, in wcd9335_codec_init()
4789 struct wcd9335_codec *wcd = dev_get_drvdata(component->dev); in wcd9335_codec_probe()
4793 snd_soc_component_init_regmap(component, wcd->regmap); in wcd9335_codec_probe()
4794 /* Class-H Init*/ in wcd9335_codec_probe()
4795 wcd->clsh_ctrl = wcd_clsh_ctrl_alloc(component, WCD9335); in wcd9335_codec_probe()
4796 if (IS_ERR(wcd->clsh_ctrl)) in wcd9335_codec_probe()
4797 return PTR_ERR(wcd->clsh_ctrl); in wcd9335_codec_probe()
4799 /* Default HPH Mode to Class-H HiFi */ in wcd9335_codec_probe()
4800 wcd->hph_mode = CLS_H_HIFI; in wcd9335_codec_probe()
4801 wcd->component = component; in wcd9335_codec_probe()
4806 INIT_LIST_HEAD(&wcd->dai[i].slim_ch_list); in wcd9335_codec_probe()
4815 wcd_clsh_ctrl_free(wcd->clsh_ctrl); in wcd9335_codec_probe()
4821 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_remove()
4823 wcd_clsh_ctrl_free(wcd->clsh_ctrl); in wcd9335_codec_remove()
4831 struct wcd9335_codec *wcd = dev_get_drvdata(comp->dev); in wcd9335_codec_set_sysclk()
4833 wcd->mclk_rate = freq; in wcd9335_codec_set_sysclk()
4835 if (wcd->mclk_rate == WCD9335_MCLK_CLK_12P288MHZ) in wcd9335_codec_set_sysclk()
4840 else if (wcd->mclk_rate == WCD9335_MCLK_CLK_9P6MHZ) in wcd9335_codec_set_sysclk()
4846 return clk_set_rate(wcd->mclk, freq); in wcd9335_codec_set_sysclk()
4864 struct device *dev = wcd->dev; in wcd9335_probe()
4866 memcpy(wcd->rx_chs, wcd9335_rx_chs, sizeof(wcd9335_rx_chs)); in wcd9335_probe()
4867 memcpy(wcd->tx_chs, wcd9335_tx_chs, sizeof(wcd9335_tx_chs)); in wcd9335_probe()
4869 wcd->sido_input_src = SIDO_SOURCE_INTERNAL; in wcd9335_probe()
4870 wcd->sido_voltage = SIDO_VOLTAGE_NOMINAL_MV; in wcd9335_probe()
4922 .name = "WCD9335-IFC-DEV",
4975 struct device *dev = wcd->dev; in wcd9335_parse_dt()
4976 struct device_node *np = dev->of_node; in wcd9335_parse_dt()
4979 wcd->reset_gpio = of_get_named_gpio(np, "reset-gpios", 0); in wcd9335_parse_dt()
4980 if (wcd->reset_gpio < 0) in wcd9335_parse_dt()
4981 return dev_err_probe(dev, wcd->reset_gpio, "Reset GPIO missing from DT\n"); in wcd9335_parse_dt()
4983 wcd->mclk = devm_clk_get(dev, "mclk"); in wcd9335_parse_dt()
4984 if (IS_ERR(wcd->mclk)) in wcd9335_parse_dt()
4985 return dev_err_probe(dev, PTR_ERR(wcd->mclk), "mclk not found\n"); in wcd9335_parse_dt()
4987 wcd->native_clk = devm_clk_get(dev, "slimbus"); in wcd9335_parse_dt()
4988 if (IS_ERR(wcd->native_clk)) in wcd9335_parse_dt()
4989 return dev_err_probe(dev, PTR_ERR(wcd->native_clk), "slimbus clock not found\n"); in wcd9335_parse_dt()
4991 wcd->supplies[0].supply = "vdd-buck"; in wcd9335_parse_dt()
4992 wcd->supplies[1].supply = "vdd-buck-sido"; in wcd9335_parse_dt()
4993 wcd->supplies[2].supply = "vdd-tx"; in wcd9335_parse_dt()
4994 wcd->supplies[3].supply = "vdd-rx"; in wcd9335_parse_dt()
4995 wcd->supplies[4].supply = "vdd-io"; in wcd9335_parse_dt()
4997 ret = regulator_bulk_get(dev, WCD9335_MAX_SUPPLY, wcd->supplies); in wcd9335_parse_dt()
5006 struct device *dev = wcd->dev; in wcd9335_power_on_reset()
5009 ret = regulator_bulk_enable(WCD9335_MAX_SUPPLY, wcd->supplies); in wcd9335_power_on_reset()
5018 * SYS_RST_N shouldn't be pulled high during this time in wcd9335_power_on_reset()
5019 * Toggle the reset line to make sure the reset pulse is in wcd9335_power_on_reset()
5024 gpio_direction_output(wcd->reset_gpio, 0); in wcd9335_power_on_reset()
5026 gpio_set_value(wcd->reset_gpio, 1); in wcd9335_power_on_reset()
5034 struct regmap *rm = wcd->regmap; in wcd9335_bring_up()
5041 dev_err(wcd->dev, "WCD9335 CODEC version detection fail!\n"); in wcd9335_bring_up()
5042 return -EINVAL; in wcd9335_bring_up()
5046 dev_info(wcd->dev, "WCD9335 CODEC version is v2.0\n"); in wcd9335_bring_up()
5056 dev_err(wcd->dev, "WCD9335 CODEC version not supported\n"); in wcd9335_bring_up()
5057 return -EINVAL; in wcd9335_bring_up()
5072 wcd->intr1 = of_irq_get_byname(wcd->dev->of_node, "intr1"); in wcd9335_irq_init()
5073 if (wcd->intr1 < 0) in wcd9335_irq_init()
5074 return dev_err_probe(wcd->dev, wcd->intr1, in wcd9335_irq_init()
5077 ret = devm_regmap_add_irq_chip(wcd->dev, wcd->regmap, wcd->intr1, in wcd9335_irq_init()
5079 &wcd9335_regmap_irq1_chip, &wcd->irq_data); in wcd9335_irq_init()
5081 return dev_err_probe(wcd->dev, ret, "Failed to register IRQ chip\n"); in wcd9335_irq_init()
5088 struct device *dev = &slim->dev; in wcd9335_slim_probe()
5094 return -ENOMEM; in wcd9335_slim_probe()
5096 wcd->dev = dev; in wcd9335_slim_probe()
5113 struct device *dev = &sdev->dev; in wcd9335_slim_status()
5120 ifc_dev_np = of_parse_phandle(dev->of_node, "slim-ifc-dev", 0); in wcd9335_slim_status()
5123 return -EINVAL; in wcd9335_slim_status()
5126 wcd->slim = sdev; in wcd9335_slim_status()
5127 wcd->slim_ifc_dev = of_slim_get_device(sdev->ctrl, ifc_dev_np); in wcd9335_slim_status()
5129 if (!wcd->slim_ifc_dev) { in wcd9335_slim_status()
5131 return -EINVAL; in wcd9335_slim_status()
5134 slim_get_logical_addr(wcd->slim_ifc_dev); in wcd9335_slim_status()
5136 wcd->regmap = regmap_init_slimbus(sdev, &wcd9335_regmap_config); in wcd9335_slim_status()
5137 if (IS_ERR(wcd->regmap)) in wcd9335_slim_status()
5138 return dev_err_probe(dev, PTR_ERR(wcd->regmap), in wcd9335_slim_status()
5141 wcd->if_regmap = regmap_init_slimbus(wcd->slim_ifc_dev, in wcd9335_slim_status()
5143 if (IS_ERR(wcd->if_regmap)) in wcd9335_slim_status()
5144 return dev_err_probe(dev, PTR_ERR(wcd->if_regmap), in wcd9335_slim_status()
5170 .name = "wcd9335-slim",