Lines Matching +full:sm8250 +full:- +full:lpass +full:- +full:rx +full:- +full:macro

1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
11 #include <linux/clk-provider.h>
13 #include <sound/soc-dapm.h>
18 #include "lpass-macro-common.h"
19 #include "lpass-wsa-macro.h"
314 {24000, -EINVAL},/* 24K */
355 struct clk *macro; member
362 static const DECLARE_TLV_DB_SCALE(digital_gain, -8400, 100, -8400);
392 /* RX INT0 */
427 /* RX INT1 */
471 /* WSA Macro */
773 /* Update volatile list for rx/tx macros */ in wsa_is_volatile_register()
809 * wsa_macro_set_spkr_mode - Configures speaker compander and smartboost
815 * Returns 0 on success or -EINVAL on error.
821 wsa->spkr_mode = mode; in wsa_macro_set_spkr_mode()
854 struct snd_soc_component *component = dai->component; in wsa_macro_set_prim_interpolator_rate()
857 for_each_set_bit(port, &wsa->active_ch_mask[dai->id], WSA_MACRO_RX_MAX) { in wsa_macro_set_prim_interpolator_rate()
860 dev_err(component->dev, "%s: Invalid RX port, Dai ID is %d\n", in wsa_macro_set_prim_interpolator_rate()
861 __func__, dai->id); in wsa_macro_set_prim_interpolator_rate()
862 return -EINVAL; in wsa_macro_set_prim_interpolator_rate()
869 * to which interpolator input, the cdc_dma rx port in wsa_macro_set_prim_interpolator_rate()
906 struct snd_soc_component *component = dai->component; in wsa_macro_set_mix_interpolator_rate()
909 for_each_set_bit(port, &wsa->active_ch_mask[dai->id], WSA_MACRO_RX_MAX) { in wsa_macro_set_mix_interpolator_rate()
912 dev_err(component->dev, "%s: Invalid RX port, Dai ID is %d\n", in wsa_macro_set_mix_interpolator_rate()
913 __func__, dai->id); in wsa_macro_set_mix_interpolator_rate()
914 return -EINVAL; in wsa_macro_set_mix_interpolator_rate()
965 return -EINVAL; in wsa_macro_set_interpolator_rate()
976 struct snd_soc_component *component = dai->component; in wsa_macro_hw_params()
979 switch (substream->stream) { in wsa_macro_hw_params()
983 dev_err(component->dev, in wsa_macro_hw_params()
999 struct snd_soc_component *component = dai->component; in wsa_macro_get_channel_map()
1003 switch (dai->id) { in wsa_macro_get_channel_map()
1005 *tx_slot = wsa->active_ch_mask[dai->id]; in wsa_macro_get_channel_map()
1006 *tx_num = wsa->active_ch_cnt[dai->id]; in wsa_macro_get_channel_map()
1010 for_each_set_bit(temp, &wsa->active_ch_mask[dai->id], in wsa_macro_get_channel_map()
1035 dev_err(component->dev, "%s: Invalid AIF\n", __func__); in wsa_macro_get_channel_map()
1107 struct regmap *regmap = wsa->regmap; in wsa_macro_mclk_enable()
1110 if (wsa->wsa_mclk_users == 0) { in wsa_macro_mclk_enable()
1124 wsa->wsa_mclk_users++; in wsa_macro_mclk_enable()
1126 if (wsa->wsa_mclk_users <= 0) { in wsa_macro_mclk_enable()
1127 dev_err(wsa->dev, "clock already disabled\n"); in wsa_macro_mclk_enable()
1128 wsa->wsa_mclk_users = 0; in wsa_macro_mclk_enable()
1131 wsa->wsa_mclk_users--; in wsa_macro_mclk_enable()
1132 if (wsa->wsa_mclk_users == 0) { in wsa_macro_mclk_enable()
1148 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_mclk_event()
1159 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_enable_vi_feedback()
1163 if (test_bit(WSA_MACRO_TX0, &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) { in wsa_macro_enable_vi_feedback()
1166 } else if (test_bit(WSA_MACRO_TX1, &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) { in wsa_macro_enable_vi_feedback()
1222 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_enable_mix_path()
1226 switch (w->shift) { in wsa_macro_enable_mix_path()
1299 if (!wsa->comp_enabled[comp]) in wsa_macro_config_compander()
1355 if (wsa->softclip_clk_users[path] == 0) { in wsa_macro_enable_softclip_clk()
1364 wsa->softclip_clk_users[path]++; in wsa_macro_enable_softclip_clk()
1366 wsa->softclip_clk_users[path]--; in wsa_macro_enable_softclip_clk()
1367 if (wsa->softclip_clk_users[path] == 0) { in wsa_macro_enable_softclip_clk()
1391 if (!wsa->is_softclip_on[softclip_path]) in wsa_macro_config_softclip()
1451 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_enable_main_path()
1454 reg = CDC_WSA_RX0_RX_PATH_CTL + WSA_MACRO_RX_PATH_OFFSET * w->shift; in wsa_macro_enable_main_path()
1457 if (wsa_macro_adie_lb(component, w->shift)) { in wsa_macro_enable_main_path()
1500 wsa->prim_int_users[ind]++; in wsa_macro_enable_prim_interpolator()
1501 if (wsa->prim_int_users[ind] == 1) { in wsa_macro_enable_prim_interpolator()
1522 wsa->prim_int_users[ind]--; in wsa_macro_enable_prim_interpolator()
1523 if (wsa->prim_int_users[ind] == 0) { in wsa_macro_enable_prim_interpolator()
1541 switch (wsa->spkr_mode) { in wsa_macro_config_ear_spkr_gain()
1544 comp_gain_offset = -12; in wsa_macro_config_ear_spkr_gain()
1548 comp_gain_offset = -15; in wsa_macro_config_ear_spkr_gain()
1555 if (wsa->comp_enabled[WSA_MACRO_COMP1] && in wsa_macro_config_ear_spkr_gain()
1557 (wsa->ear_spkr_gain != 0)) { in wsa_macro_config_ear_spkr_gain()
1558 /* For example, val is -8(-12+5-1) for 4dB of gain */ in wsa_macro_config_ear_spkr_gain()
1559 val = comp_gain_offset + wsa->ear_spkr_gain - 1; in wsa_macro_config_ear_spkr_gain()
1566 * ear_spkr_gain is non-zero. in wsa_macro_config_ear_spkr_gain()
1568 if (wsa->comp_enabled[WSA_MACRO_COMP1] && in wsa_macro_config_ear_spkr_gain()
1570 (wsa->ear_spkr_gain != 0)) { in wsa_macro_config_ear_spkr_gain()
1583 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_enable_interpolator()
1589 if (w->shift == WSA_MACRO_COMP1) { in wsa_macro_enable_interpolator()
1592 } else if (w->shift == WSA_MACRO_COMP2) { in wsa_macro_enable_interpolator()
1603 wsa_macro_config_compander(component, w->shift, event); in wsa_macro_enable_interpolator()
1604 wsa_macro_config_softclip(component, w->shift, event); in wsa_macro_enable_interpolator()
1606 if ((wsa->spkr_gain_offset == WSA_MACRO_GAIN_OFFSET_M1P5_DB) && in wsa_macro_enable_interpolator()
1607 (wsa->comp_enabled[WSA_MACRO_COMP1] || in wsa_macro_enable_interpolator()
1608 wsa->comp_enabled[WSA_MACRO_COMP2])) { in wsa_macro_enable_interpolator()
1632 wsa_macro_config_compander(component, w->shift, event); in wsa_macro_enable_interpolator()
1633 wsa_macro_config_softclip(component, w->shift, event); in wsa_macro_enable_interpolator()
1635 if ((wsa->spkr_gain_offset == WSA_MACRO_GAIN_OFFSET_M1P5_DB) && in wsa_macro_enable_interpolator()
1636 (wsa->comp_enabled[WSA_MACRO_COMP1] || in wsa_macro_enable_interpolator()
1637 wsa->comp_enabled[WSA_MACRO_COMP2])) { in wsa_macro_enable_interpolator()
1667 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_spk_boost_event()
1682 dev_warn(component->dev, "Incorrect widget name in the driver\n"); in wsa_macro_spk_boost_event()
1683 return -EINVAL; in wsa_macro_spk_boost_event()
1718 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_enable_echo()
1724 switch (w->shift) { in wsa_macro_enable_echo()
1727 ec_tx = val - 1; in wsa_macro_enable_echo()
1731 ec_tx = (val >> CDC_WSA_RX_MIX_TX1_SEL_SHFT) - 1; in wsa_macro_enable_echo()
1734 dev_err(component->dev, "%s: Invalid shift %u\n", in wsa_macro_enable_echo()
1735 __func__, w->shift); in wsa_macro_enable_echo()
1736 return -EINVAL; in wsa_macro_enable_echo()
1739 if (wsa->ec_hq[ec_tx]) { in wsa_macro_enable_echo()
1759 int ec_tx = ((struct soc_mixer_control *) kcontrol->private_value)->shift; in wsa_macro_get_ec_hq()
1762 ucontrol->value.integer.value[0] = wsa->ec_hq[ec_tx]; in wsa_macro_get_ec_hq()
1771 int ec_tx = ((struct soc_mixer_control *) kcontrol->private_value)->shift; in wsa_macro_set_ec_hq()
1772 int value = ucontrol->value.integer.value[0]; in wsa_macro_set_ec_hq()
1775 wsa->ec_hq[ec_tx] = value; in wsa_macro_set_ec_hq()
1785 int comp = ((struct soc_mixer_control *) kcontrol->private_value)->shift; in wsa_macro_get_compander()
1788 ucontrol->value.integer.value[0] = wsa->comp_enabled[comp]; in wsa_macro_get_compander()
1796 int comp = ((struct soc_mixer_control *) kcontrol->private_value)->shift; in wsa_macro_set_compander()
1797 int value = ucontrol->value.integer.value[0]; in wsa_macro_set_compander()
1800 wsa->comp_enabled[comp] = value; in wsa_macro_set_compander()
1811 ucontrol->value.integer.value[0] = wsa->ear_spkr_gain; in wsa_macro_ear_spkr_pa_gain_get()
1822 wsa->ear_spkr_gain = ucontrol->value.integer.value[0]; in wsa_macro_ear_spkr_pa_gain_put()
1833 snd_soc_dapm_to_component(widget->dapm); in wsa_macro_rx_mux_get()
1836 ucontrol->value.integer.value[0] = in wsa_macro_rx_mux_get()
1837 wsa->rx_port_value[widget->shift]; in wsa_macro_rx_mux_get()
1847 snd_soc_dapm_to_component(widget->dapm); in wsa_macro_rx_mux_put()
1848 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in wsa_macro_rx_mux_put()
1850 u32 rx_port_value = ucontrol->value.integer.value[0]; in wsa_macro_rx_mux_put()
1855 aif_rst = wsa->rx_port_value[widget->shift]; in wsa_macro_rx_mux_put()
1860 dev_err(component->dev, "%s: Invalid AIF reset\n", __func__); in wsa_macro_rx_mux_put()
1864 wsa->rx_port_value[widget->shift] = rx_port_value; in wsa_macro_rx_mux_put()
1866 bit_input = widget->shift; in wsa_macro_rx_mux_put()
1870 if (wsa->active_ch_cnt[aif_rst]) { in wsa_macro_rx_mux_put()
1872 &wsa->active_ch_mask[aif_rst]); in wsa_macro_rx_mux_put()
1873 wsa->active_ch_cnt[aif_rst]--; in wsa_macro_rx_mux_put()
1879 &wsa->active_ch_mask[rx_port_value]); in wsa_macro_rx_mux_put()
1880 wsa->active_ch_cnt[rx_port_value]++; in wsa_macro_rx_mux_put()
1883 dev_err(component->dev, in wsa_macro_rx_mux_put()
1884 "%s: Invalid AIF_ID for WSA RX MUX %d\n", in wsa_macro_rx_mux_put()
1886 return -EINVAL; in wsa_macro_rx_mux_put()
1889 snd_soc_dapm_mux_update_power(widget->dapm, kcontrol, in wsa_macro_rx_mux_put()
1899 int path = ((struct soc_mixer_control *)kcontrol->private_value)->shift; in wsa_macro_soft_clip_enable_get()
1901 ucontrol->value.integer.value[0] = wsa->is_softclip_on[path]; in wsa_macro_soft_clip_enable_get()
1911 int path = ((struct soc_mixer_control *) kcontrol->private_value)->shift; in wsa_macro_soft_clip_enable_put()
1913 wsa->is_softclip_on[path] = ucontrol->value.integer.value[0]; in wsa_macro_soft_clip_enable_put()
1932 -84, 40, digital_gain),
1934 -84, 40, digital_gain),
1970 struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm); in wsa_macro_vi_feed_mixer_get()
1971 struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; in wsa_macro_vi_feed_mixer_get()
1973 u32 spk_tx_id = mixer->shift; in wsa_macro_vi_feed_mixer_get()
1974 u32 dai_id = widget->shift; in wsa_macro_vi_feed_mixer_get()
1976 if (test_bit(spk_tx_id, &wsa->active_ch_mask[dai_id])) in wsa_macro_vi_feed_mixer_get()
1977 ucontrol->value.integer.value[0] = 1; in wsa_macro_vi_feed_mixer_get()
1979 ucontrol->value.integer.value[0] = 0; in wsa_macro_vi_feed_mixer_get()
1988 struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm); in wsa_macro_vi_feed_mixer_put()
1989 struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; in wsa_macro_vi_feed_mixer_put()
1991 u32 enable = ucontrol->value.integer.value[0]; in wsa_macro_vi_feed_mixer_put()
1992 u32 spk_tx_id = mixer->shift; in wsa_macro_vi_feed_mixer_put()
1997 &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) { in wsa_macro_vi_feed_mixer_put()
1999 &wsa->active_ch_mask[WSA_MACRO_AIF_VI]); in wsa_macro_vi_feed_mixer_put()
2000 wsa->active_ch_cnt[WSA_MACRO_AIF_VI]++; in wsa_macro_vi_feed_mixer_put()
2004 &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) { in wsa_macro_vi_feed_mixer_put()
2006 &wsa->active_ch_mask[WSA_MACRO_AIF_VI]); in wsa_macro_vi_feed_mixer_put()
2007 wsa->active_ch_cnt[WSA_MACRO_AIF_VI]++; in wsa_macro_vi_feed_mixer_put()
2012 &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) { in wsa_macro_vi_feed_mixer_put()
2014 &wsa->active_ch_mask[WSA_MACRO_AIF_VI]); in wsa_macro_vi_feed_mixer_put()
2015 wsa->active_ch_cnt[WSA_MACRO_AIF_VI]--; in wsa_macro_vi_feed_mixer_put()
2019 &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) { in wsa_macro_vi_feed_mixer_put()
2021 &wsa->active_ch_mask[WSA_MACRO_AIF_VI]); in wsa_macro_vi_feed_mixer_put()
2022 wsa->active_ch_cnt[WSA_MACRO_AIF_VI]--; in wsa_macro_vi_feed_mixer_put()
2025 snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, NULL); in wsa_macro_vi_feed_mixer_put()
2257 struct regmap *regmap = wsa->regmap; in wsa_swrm_clock()
2262 ret = clk_prepare_enable(wsa->mclk); in wsa_swrm_clock()
2264 dev_err(wsa->dev, "failed to enable mclk\n"); in wsa_swrm_clock()
2277 clk_disable_unprepare(wsa->mclk); in wsa_swrm_clock()
2287 snd_soc_component_init_regmap(comp, wsa->regmap); in wsa_macro_component_probe()
2289 wsa->spkr_gain_offset = WSA_MACRO_GAIN_OFFSET_M1P5_DB; in wsa_macro_component_probe()
2320 regmap_read(wsa->regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL, &val); in swclk_gate_is_enabled()
2341 struct device *dev = wsa->dev; in wsa_macro_register_mclk_output()
2347 if (wsa->npl) in wsa_macro_register_mclk_output()
2348 parent_clk_name = __clk_get_name(wsa->npl); in wsa_macro_register_mclk_output()
2350 parent_clk_name = __clk_get_name(wsa->mclk); in wsa_macro_register_mclk_output()
2353 of_property_read_string(dev_of_node(dev), "clock-output-names", in wsa_macro_register_mclk_output()
2359 wsa->hw.init = &init; in wsa_macro_register_mclk_output()
2360 hw = &wsa->hw; in wsa_macro_register_mclk_output()
2361 ret = clk_hw_register(wsa->dev, hw); in wsa_macro_register_mclk_output()
2369 .name = "WSA MACRO",
2381 struct device *dev = &pdev->dev; in wsa_macro_probe()
2391 return -ENOMEM; in wsa_macro_probe()
2393 wsa->macro = devm_clk_get_optional(dev, "macro"); in wsa_macro_probe()
2394 if (IS_ERR(wsa->macro)) in wsa_macro_probe()
2395 return dev_err_probe(dev, PTR_ERR(wsa->macro), "unable to get macro clock\n"); in wsa_macro_probe()
2397 wsa->dcodec = devm_clk_get_optional(dev, "dcodec"); in wsa_macro_probe()
2398 if (IS_ERR(wsa->dcodec)) in wsa_macro_probe()
2399 return dev_err_probe(dev, PTR_ERR(wsa->dcodec), "unable to get dcodec clock\n"); in wsa_macro_probe()
2401 wsa->mclk = devm_clk_get(dev, "mclk"); in wsa_macro_probe()
2402 if (IS_ERR(wsa->mclk)) in wsa_macro_probe()
2403 return dev_err_probe(dev, PTR_ERR(wsa->mclk), "unable to get mclk clock\n"); in wsa_macro_probe()
2406 wsa->npl = devm_clk_get(dev, "npl"); in wsa_macro_probe()
2407 if (IS_ERR(wsa->npl)) in wsa_macro_probe()
2408 return dev_err_probe(dev, PTR_ERR(wsa->npl), "unable to get npl clock\n"); in wsa_macro_probe()
2411 wsa->fsgen = devm_clk_get(dev, "fsgen"); in wsa_macro_probe()
2412 if (IS_ERR(wsa->fsgen)) in wsa_macro_probe()
2413 return dev_err_probe(dev, PTR_ERR(wsa->fsgen), "unable to get fsgen clock\n"); in wsa_macro_probe()
2419 wsa->regmap = devm_regmap_init_mmio(dev, base, &wsa_regmap_config); in wsa_macro_probe()
2420 if (IS_ERR(wsa->regmap)) in wsa_macro_probe()
2421 return PTR_ERR(wsa->regmap); in wsa_macro_probe()
2425 wsa->dev = dev; in wsa_macro_probe()
2428 clk_set_rate(wsa->mclk, WSA_MACRO_MCLK_FREQ); in wsa_macro_probe()
2429 clk_set_rate(wsa->npl, WSA_MACRO_MCLK_FREQ); in wsa_macro_probe()
2431 ret = clk_prepare_enable(wsa->macro); in wsa_macro_probe()
2435 ret = clk_prepare_enable(wsa->dcodec); in wsa_macro_probe()
2439 ret = clk_prepare_enable(wsa->mclk); in wsa_macro_probe()
2443 ret = clk_prepare_enable(wsa->npl); in wsa_macro_probe()
2447 ret = clk_prepare_enable(wsa->fsgen); in wsa_macro_probe()
2452 regmap_update_bits(wsa->regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL, in wsa_macro_probe()
2455 regmap_update_bits(wsa->regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL, in wsa_macro_probe()
2459 regmap_update_bits(wsa->regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL, in wsa_macro_probe()
2481 clk_disable_unprepare(wsa->fsgen); in wsa_macro_probe()
2483 clk_disable_unprepare(wsa->npl); in wsa_macro_probe()
2485 clk_disable_unprepare(wsa->mclk); in wsa_macro_probe()
2487 clk_disable_unprepare(wsa->dcodec); in wsa_macro_probe()
2489 clk_disable_unprepare(wsa->macro); in wsa_macro_probe()
2497 struct wsa_macro *wsa = dev_get_drvdata(&pdev->dev); in wsa_macro_remove()
2499 clk_disable_unprepare(wsa->macro); in wsa_macro_remove()
2500 clk_disable_unprepare(wsa->dcodec); in wsa_macro_remove()
2501 clk_disable_unprepare(wsa->mclk); in wsa_macro_remove()
2502 clk_disable_unprepare(wsa->npl); in wsa_macro_remove()
2503 clk_disable_unprepare(wsa->fsgen); in wsa_macro_remove()
2510 regcache_cache_only(wsa->regmap, true); in wsa_macro_runtime_suspend()
2511 regcache_mark_dirty(wsa->regmap); in wsa_macro_runtime_suspend()
2513 clk_disable_unprepare(wsa->fsgen); in wsa_macro_runtime_suspend()
2514 clk_disable_unprepare(wsa->npl); in wsa_macro_runtime_suspend()
2515 clk_disable_unprepare(wsa->mclk); in wsa_macro_runtime_suspend()
2525 ret = clk_prepare_enable(wsa->mclk); in wsa_macro_runtime_resume()
2531 ret = clk_prepare_enable(wsa->npl); in wsa_macro_runtime_resume()
2537 ret = clk_prepare_enable(wsa->fsgen); in wsa_macro_runtime_resume()
2543 regcache_cache_only(wsa->regmap, false); in wsa_macro_runtime_resume()
2544 regcache_sync(wsa->regmap); in wsa_macro_runtime_resume()
2548 clk_disable_unprepare(wsa->npl); in wsa_macro_runtime_resume()
2550 clk_disable_unprepare(wsa->mclk); in wsa_macro_runtime_resume()
2561 .compatible = "qcom,sc7280-lpass-wsa-macro",
2564 .compatible = "qcom,sm8250-lpass-wsa-macro",
2567 .compatible = "qcom,sm8450-lpass-wsa-macro",
2570 .compatible = "qcom,sm8550-lpass-wsa-macro",
2572 .compatible = "qcom,sc8280xp-lpass-wsa-macro",
2590 MODULE_DESCRIPTION("WSA macro driver");