Lines Matching +full:sm8250 +full:- +full:lpass +full:- +full:tx +full:- +full:macro
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
10 #include <linux/clk-provider.h>
12 #include <sound/soc-dapm.h>
16 #include "lpass-wsa-macro.h"
311 {24000, -EINVAL},/* 24K */
352 struct clk *macro; member
359 static const DECLARE_TLV_DB_SCALE(digital_gain, -8400, 100, -8400);
468 /* WSA Macro */
770 /* Update volatile list for rx/tx macros */ in wsa_is_volatile_register()
806 * wsa_macro_set_spkr_mode - Configures speaker compander and smartboost
812 * Returns 0 on success or -EINVAL on error.
818 wsa->spkr_mode = mode; in wsa_macro_set_spkr_mode()
851 struct snd_soc_component *component = dai->component; in wsa_macro_set_prim_interpolator_rate()
854 for_each_set_bit(port, &wsa->active_ch_mask[dai->id], WSA_MACRO_RX_MAX) { in wsa_macro_set_prim_interpolator_rate()
857 dev_err(component->dev, "%s: Invalid RX port, Dai ID is %d\n", in wsa_macro_set_prim_interpolator_rate()
858 __func__, dai->id); in wsa_macro_set_prim_interpolator_rate()
859 return -EINVAL; in wsa_macro_set_prim_interpolator_rate()
903 struct snd_soc_component *component = dai->component; in wsa_macro_set_mix_interpolator_rate()
906 for_each_set_bit(port, &wsa->active_ch_mask[dai->id], WSA_MACRO_RX_MAX) { in wsa_macro_set_mix_interpolator_rate()
909 dev_err(component->dev, "%s: Invalid RX port, Dai ID is %d\n", in wsa_macro_set_mix_interpolator_rate()
910 __func__, dai->id); in wsa_macro_set_mix_interpolator_rate()
911 return -EINVAL; in wsa_macro_set_mix_interpolator_rate()
962 return -EINVAL; in wsa_macro_set_interpolator_rate()
973 struct snd_soc_component *component = dai->component; in wsa_macro_hw_params()
976 switch (substream->stream) { in wsa_macro_hw_params()
980 dev_err(component->dev, in wsa_macro_hw_params()
996 struct snd_soc_component *component = dai->component; in wsa_macro_get_channel_map()
1000 switch (dai->id) { in wsa_macro_get_channel_map()
1002 *tx_slot = wsa->active_ch_mask[dai->id]; in wsa_macro_get_channel_map()
1003 *tx_num = wsa->active_ch_cnt[dai->id]; in wsa_macro_get_channel_map()
1007 for_each_set_bit(temp, &wsa->active_ch_mask[dai->id], in wsa_macro_get_channel_map()
1032 dev_err(component->dev, "%s: Invalid AIF\n", __func__); in wsa_macro_get_channel_map()
1104 struct regmap *regmap = wsa->regmap; in wsa_macro_mclk_enable()
1107 if (wsa->wsa_mclk_users == 0) { in wsa_macro_mclk_enable()
1121 wsa->wsa_mclk_users++; in wsa_macro_mclk_enable()
1123 if (wsa->wsa_mclk_users <= 0) { in wsa_macro_mclk_enable()
1124 dev_err(wsa->dev, "clock already disabled\n"); in wsa_macro_mclk_enable()
1125 wsa->wsa_mclk_users = 0; in wsa_macro_mclk_enable()
1128 wsa->wsa_mclk_users--; in wsa_macro_mclk_enable()
1129 if (wsa->wsa_mclk_users == 0) { in wsa_macro_mclk_enable()
1145 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_mclk_event()
1156 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_enable_vi_feedback()
1160 if (test_bit(WSA_MACRO_TX0, &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) { in wsa_macro_enable_vi_feedback()
1163 } else if (test_bit(WSA_MACRO_TX1, &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) { in wsa_macro_enable_vi_feedback()
1219 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_enable_mix_path()
1223 switch (w->shift) { in wsa_macro_enable_mix_path()
1296 if (!wsa->comp_enabled[comp]) in wsa_macro_config_compander()
1352 if (wsa->softclip_clk_users[path] == 0) { in wsa_macro_enable_softclip_clk()
1361 wsa->softclip_clk_users[path]++; in wsa_macro_enable_softclip_clk()
1363 wsa->softclip_clk_users[path]--; in wsa_macro_enable_softclip_clk()
1364 if (wsa->softclip_clk_users[path] == 0) { in wsa_macro_enable_softclip_clk()
1388 if (!wsa->is_softclip_on[softclip_path]) in wsa_macro_config_softclip()
1448 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_enable_main_path()
1451 reg = CDC_WSA_RX0_RX_PATH_CTL + WSA_MACRO_RX_PATH_OFFSET * w->shift; in wsa_macro_enable_main_path()
1454 if (wsa_macro_adie_lb(component, w->shift)) { in wsa_macro_enable_main_path()
1497 wsa->prim_int_users[ind]++; in wsa_macro_enable_prim_interpolator()
1498 if (wsa->prim_int_users[ind] == 1) { in wsa_macro_enable_prim_interpolator()
1519 wsa->prim_int_users[ind]--; in wsa_macro_enable_prim_interpolator()
1520 if (wsa->prim_int_users[ind] == 0) { in wsa_macro_enable_prim_interpolator()
1538 switch (wsa->spkr_mode) { in wsa_macro_config_ear_spkr_gain()
1541 comp_gain_offset = -12; in wsa_macro_config_ear_spkr_gain()
1545 comp_gain_offset = -15; in wsa_macro_config_ear_spkr_gain()
1552 if (wsa->comp_enabled[WSA_MACRO_COMP1] && in wsa_macro_config_ear_spkr_gain()
1554 (wsa->ear_spkr_gain != 0)) { in wsa_macro_config_ear_spkr_gain()
1555 /* For example, val is -8(-12+5-1) for 4dB of gain */ in wsa_macro_config_ear_spkr_gain()
1556 val = comp_gain_offset + wsa->ear_spkr_gain - 1; in wsa_macro_config_ear_spkr_gain()
1563 * ear_spkr_gain is non-zero. in wsa_macro_config_ear_spkr_gain()
1565 if (wsa->comp_enabled[WSA_MACRO_COMP1] && in wsa_macro_config_ear_spkr_gain()
1567 (wsa->ear_spkr_gain != 0)) { in wsa_macro_config_ear_spkr_gain()
1580 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_enable_interpolator()
1587 if (w->shift == WSA_MACRO_COMP1) { in wsa_macro_enable_interpolator()
1590 } else if (w->shift == WSA_MACRO_COMP2) { in wsa_macro_enable_interpolator()
1601 wsa_macro_config_compander(component, w->shift, event); in wsa_macro_enable_interpolator()
1602 wsa_macro_config_softclip(component, w->shift, event); in wsa_macro_enable_interpolator()
1604 if ((wsa->spkr_gain_offset == WSA_MACRO_GAIN_OFFSET_M1P5_DB) && in wsa_macro_enable_interpolator()
1605 (wsa->comp_enabled[WSA_MACRO_COMP1] || in wsa_macro_enable_interpolator()
1606 wsa->comp_enabled[WSA_MACRO_COMP2])) { in wsa_macro_enable_interpolator()
1623 offset_val = -2; 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()
1671 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_spk_boost_event()
1675 if (!strcmp(w->name, "WSA_RX INT0 CHAIN")) { in wsa_macro_spk_boost_event()
1680 } else if (!strcmp(w->name, "WSA_RX INT1 CHAIN")) { in wsa_macro_spk_boost_event()
1719 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in wsa_macro_enable_echo()
1725 switch (w->shift) { in wsa_macro_enable_echo()
1728 ec_tx = val - 1; in wsa_macro_enable_echo()
1732 ec_tx = (val >> CDC_WSA_RX_MIX_TX1_SEL_SHFT) - 1; in wsa_macro_enable_echo()
1735 dev_err(component->dev, "%s: Invalid shift %u\n", in wsa_macro_enable_echo()
1736 __func__, w->shift); in wsa_macro_enable_echo()
1737 return -EINVAL; in wsa_macro_enable_echo()
1740 if (wsa->ec_hq[ec_tx]) { in wsa_macro_enable_echo()
1760 int ec_tx = ((struct soc_mixer_control *) kcontrol->private_value)->shift; in wsa_macro_get_ec_hq()
1763 ucontrol->value.integer.value[0] = wsa->ec_hq[ec_tx]; in wsa_macro_get_ec_hq()
1772 int ec_tx = ((struct soc_mixer_control *) kcontrol->private_value)->shift; in wsa_macro_set_ec_hq()
1773 int value = ucontrol->value.integer.value[0]; in wsa_macro_set_ec_hq()
1776 wsa->ec_hq[ec_tx] = value; in wsa_macro_set_ec_hq()
1786 int comp = ((struct soc_mixer_control *) kcontrol->private_value)->shift; in wsa_macro_get_compander()
1789 ucontrol->value.integer.value[0] = wsa->comp_enabled[comp]; in wsa_macro_get_compander()
1797 int comp = ((struct soc_mixer_control *) kcontrol->private_value)->shift; in wsa_macro_set_compander()
1798 int value = ucontrol->value.integer.value[0]; in wsa_macro_set_compander()
1801 wsa->comp_enabled[comp] = value; in wsa_macro_set_compander()
1812 ucontrol->value.integer.value[0] = wsa->ear_spkr_gain; in wsa_macro_ear_spkr_pa_gain_get()
1823 wsa->ear_spkr_gain = ucontrol->value.integer.value[0]; in wsa_macro_ear_spkr_pa_gain_put()
1834 snd_soc_dapm_to_component(widget->dapm); in wsa_macro_rx_mux_get()
1837 ucontrol->value.integer.value[0] = in wsa_macro_rx_mux_get()
1838 wsa->rx_port_value[widget->shift]; in wsa_macro_rx_mux_get()
1848 snd_soc_dapm_to_component(widget->dapm); in wsa_macro_rx_mux_put()
1849 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in wsa_macro_rx_mux_put()
1851 u32 rx_port_value = ucontrol->value.integer.value[0]; in wsa_macro_rx_mux_put()
1856 aif_rst = wsa->rx_port_value[widget->shift]; in wsa_macro_rx_mux_put()
1859 dev_err(component->dev, "%s: AIF reset already\n", __func__); in wsa_macro_rx_mux_put()
1863 dev_err(component->dev, "%s: Invalid AIF reset\n", __func__); in wsa_macro_rx_mux_put()
1867 wsa->rx_port_value[widget->shift] = rx_port_value; in wsa_macro_rx_mux_put()
1869 bit_input = widget->shift; in wsa_macro_rx_mux_put()
1873 if (wsa->active_ch_cnt[aif_rst]) { in wsa_macro_rx_mux_put()
1875 &wsa->active_ch_mask[aif_rst]); in wsa_macro_rx_mux_put()
1876 wsa->active_ch_cnt[aif_rst]--; in wsa_macro_rx_mux_put()
1882 &wsa->active_ch_mask[rx_port_value]); in wsa_macro_rx_mux_put()
1883 wsa->active_ch_cnt[rx_port_value]++; in wsa_macro_rx_mux_put()
1886 dev_err(component->dev, in wsa_macro_rx_mux_put()
1889 return -EINVAL; in wsa_macro_rx_mux_put()
1892 snd_soc_dapm_mux_update_power(widget->dapm, kcontrol, in wsa_macro_rx_mux_put()
1902 int path = ((struct soc_mixer_control *)kcontrol->private_value)->shift; in wsa_macro_soft_clip_enable_get()
1904 ucontrol->value.integer.value[0] = wsa->is_softclip_on[path]; in wsa_macro_soft_clip_enable_get()
1914 int path = ((struct soc_mixer_control *) kcontrol->private_value)->shift; in wsa_macro_soft_clip_enable_put()
1916 wsa->is_softclip_on[path] = ucontrol->value.integer.value[0]; in wsa_macro_soft_clip_enable_put()
1935 -84, 40, digital_gain),
1937 -84, 40, digital_gain),
1973 struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm); in wsa_macro_vi_feed_mixer_get()
1974 struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; in wsa_macro_vi_feed_mixer_get()
1976 u32 spk_tx_id = mixer->shift; in wsa_macro_vi_feed_mixer_get()
1977 u32 dai_id = widget->shift; in wsa_macro_vi_feed_mixer_get()
1979 if (test_bit(spk_tx_id, &wsa->active_ch_mask[dai_id])) in wsa_macro_vi_feed_mixer_get()
1980 ucontrol->value.integer.value[0] = 1; in wsa_macro_vi_feed_mixer_get()
1982 ucontrol->value.integer.value[0] = 0; in wsa_macro_vi_feed_mixer_get()
1991 struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm); in wsa_macro_vi_feed_mixer_put()
1992 struct soc_mixer_control *mixer = (struct soc_mixer_control *)kcontrol->private_value; in wsa_macro_vi_feed_mixer_put()
1994 u32 enable = ucontrol->value.integer.value[0]; in wsa_macro_vi_feed_mixer_put()
1995 u32 spk_tx_id = mixer->shift; in wsa_macro_vi_feed_mixer_put()
2000 &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) { in wsa_macro_vi_feed_mixer_put()
2002 &wsa->active_ch_mask[WSA_MACRO_AIF_VI]); in wsa_macro_vi_feed_mixer_put()
2003 wsa->active_ch_cnt[WSA_MACRO_AIF_VI]++; in wsa_macro_vi_feed_mixer_put()
2007 &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) { in wsa_macro_vi_feed_mixer_put()
2009 &wsa->active_ch_mask[WSA_MACRO_AIF_VI]); in wsa_macro_vi_feed_mixer_put()
2010 wsa->active_ch_cnt[WSA_MACRO_AIF_VI]++; in wsa_macro_vi_feed_mixer_put()
2015 &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) { in wsa_macro_vi_feed_mixer_put()
2017 &wsa->active_ch_mask[WSA_MACRO_AIF_VI]); in wsa_macro_vi_feed_mixer_put()
2018 wsa->active_ch_cnt[WSA_MACRO_AIF_VI]--; in wsa_macro_vi_feed_mixer_put()
2022 &wsa->active_ch_mask[WSA_MACRO_AIF_VI])) { in wsa_macro_vi_feed_mixer_put()
2024 &wsa->active_ch_mask[WSA_MACRO_AIF_VI]); in wsa_macro_vi_feed_mixer_put()
2025 wsa->active_ch_cnt[WSA_MACRO_AIF_VI]--; in wsa_macro_vi_feed_mixer_put()
2028 snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, NULL); in wsa_macro_vi_feed_mixer_put()
2260 struct regmap *regmap = wsa->regmap; in wsa_swrm_clock()
2265 ret = clk_prepare_enable(wsa->mclk); in wsa_swrm_clock()
2267 dev_err(wsa->dev, "failed to enable mclk\n"); in wsa_swrm_clock()
2287 clk_disable_unprepare(wsa->mclk); in wsa_swrm_clock()
2297 snd_soc_component_init_regmap(comp, wsa->regmap); in wsa_macro_component_probe()
2299 wsa->spkr_gain_offset = WSA_MACRO_GAIN_OFFSET_M1P5_DB; in wsa_macro_component_probe()
2330 regmap_read(wsa->regmap, CDC_WSA_CLK_RST_CTRL_SWR_CONTROL, &val); in swclk_gate_is_enabled()
2351 struct device *dev = wsa->dev; in wsa_macro_register_mclk_output()
2358 parent_clk_name = __clk_get_name(wsa->npl); in wsa_macro_register_mclk_output()
2365 wsa->hw.init = &init; in wsa_macro_register_mclk_output()
2366 hw = &wsa->hw; in wsa_macro_register_mclk_output()
2367 ret = clk_hw_register(wsa->dev, hw); in wsa_macro_register_mclk_output()
2375 .name = "WSA MACRO",
2387 struct device *dev = &pdev->dev; in wsa_macro_probe()
2394 return -ENOMEM; in wsa_macro_probe()
2396 wsa->macro = devm_clk_get_optional(dev, "macro"); in wsa_macro_probe()
2397 if (IS_ERR(wsa->macro)) in wsa_macro_probe()
2398 return PTR_ERR(wsa->macro); in wsa_macro_probe()
2400 wsa->dcodec = devm_clk_get_optional(dev, "dcodec"); in wsa_macro_probe()
2401 if (IS_ERR(wsa->dcodec)) in wsa_macro_probe()
2402 return PTR_ERR(wsa->dcodec); in wsa_macro_probe()
2404 wsa->mclk = devm_clk_get(dev, "mclk"); in wsa_macro_probe()
2405 if (IS_ERR(wsa->mclk)) in wsa_macro_probe()
2406 return PTR_ERR(wsa->mclk); in wsa_macro_probe()
2408 wsa->npl = devm_clk_get(dev, "npl"); in wsa_macro_probe()
2409 if (IS_ERR(wsa->npl)) in wsa_macro_probe()
2410 return PTR_ERR(wsa->npl); in wsa_macro_probe()
2412 wsa->fsgen = devm_clk_get(dev, "fsgen"); in wsa_macro_probe()
2413 if (IS_ERR(wsa->fsgen)) in wsa_macro_probe()
2414 return PTR_ERR(wsa->fsgen); in wsa_macro_probe()
2420 wsa->regmap = devm_regmap_init_mmio(dev, base, &wsa_regmap_config); in wsa_macro_probe()
2421 if (IS_ERR(wsa->regmap)) in wsa_macro_probe()
2422 return PTR_ERR(wsa->regmap); in wsa_macro_probe()
2426 wsa->dev = dev; in wsa_macro_probe()
2429 clk_set_rate(wsa->mclk, WSA_MACRO_MCLK_FREQ); in wsa_macro_probe()
2430 clk_set_rate(wsa->npl, WSA_MACRO_MCLK_FREQ); in wsa_macro_probe()
2432 ret = clk_prepare_enable(wsa->macro); in wsa_macro_probe()
2436 ret = clk_prepare_enable(wsa->dcodec); in wsa_macro_probe()
2440 ret = clk_prepare_enable(wsa->mclk); in wsa_macro_probe()
2444 ret = clk_prepare_enable(wsa->npl); in wsa_macro_probe()
2448 ret = clk_prepare_enable(wsa->fsgen); in wsa_macro_probe()
2472 clk_disable_unprepare(wsa->fsgen); in wsa_macro_probe()
2474 clk_disable_unprepare(wsa->npl); in wsa_macro_probe()
2476 clk_disable_unprepare(wsa->mclk); in wsa_macro_probe()
2478 clk_disable_unprepare(wsa->dcodec); in wsa_macro_probe()
2480 clk_disable_unprepare(wsa->macro); in wsa_macro_probe()
2488 struct wsa_macro *wsa = dev_get_drvdata(&pdev->dev); in wsa_macro_remove()
2490 clk_disable_unprepare(wsa->macro); in wsa_macro_remove()
2491 clk_disable_unprepare(wsa->dcodec); in wsa_macro_remove()
2492 clk_disable_unprepare(wsa->mclk); in wsa_macro_remove()
2493 clk_disable_unprepare(wsa->npl); in wsa_macro_remove()
2494 clk_disable_unprepare(wsa->fsgen); in wsa_macro_remove()
2503 regcache_cache_only(wsa->regmap, true); in wsa_macro_runtime_suspend()
2504 regcache_mark_dirty(wsa->regmap); in wsa_macro_runtime_suspend()
2506 clk_disable_unprepare(wsa->mclk); in wsa_macro_runtime_suspend()
2507 clk_disable_unprepare(wsa->npl); in wsa_macro_runtime_suspend()
2508 clk_disable_unprepare(wsa->fsgen); in wsa_macro_runtime_suspend()
2518 ret = clk_prepare_enable(wsa->mclk); in wsa_macro_runtime_resume()
2524 ret = clk_prepare_enable(wsa->npl); in wsa_macro_runtime_resume()
2530 ret = clk_prepare_enable(wsa->fsgen); in wsa_macro_runtime_resume()
2536 regcache_cache_only(wsa->regmap, false); in wsa_macro_runtime_resume()
2537 regcache_sync(wsa->regmap); in wsa_macro_runtime_resume()
2541 clk_disable_unprepare(wsa->npl); in wsa_macro_runtime_resume()
2543 clk_disable_unprepare(wsa->mclk); in wsa_macro_runtime_resume()
2553 {.compatible = "qcom,sc7280-lpass-wsa-macro"},
2554 {.compatible = "qcom,sm8250-lpass-wsa-macro"},
2555 {.compatible = "qcom,sm8450-lpass-wsa-macro"},
2556 {.compatible = "qcom,sc8280xp-lpass-wsa-macro" },
2572 MODULE_DESCRIPTION("WSA macro driver");