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.
12 #include <sound/soc-dapm.h>
15 #include <linux/clk-provider.h>
17 #include "lpass-macro-common.h"
199 #define TX_ADC_TO_DMIC(n) ((n - TX_ADC_MAX)/2)
267 struct clk *macro; member
281 static const DECLARE_TLV_DB_SCALE(digital_gain, -8400, 100, -8400);
284 /* TX Macro */
604 struct regmap *regmap = tx->regmap; in tx_macro_mclk_enable()
607 if (tx->tx_mclk_users == 0) { in tx_macro_mclk_enable()
619 tx->tx_mclk_users++; in tx_macro_mclk_enable()
621 if (tx->tx_mclk_users <= 0) { in tx_macro_mclk_enable()
622 dev_err(tx->dev, "clock already disabled\n"); in tx_macro_mclk_enable()
623 tx->tx_mclk_users = 0; in tx_macro_mclk_enable()
626 tx->tx_mclk_users--; in tx_macro_mclk_enable()
627 if (tx->tx_mclk_users == 0) { in tx_macro_mclk_enable()
666 tx = hpf_work->tx; in tx_macro_tx_hpf_corner_freq_callback()
667 component = tx->component; in tx_macro_tx_hpf_corner_freq_callback()
668 hpf_cut_off_freq = hpf_work->hpf_cut_off_freq; in tx_macro_tx_hpf_corner_freq_callback()
670 dec_cfg_reg = CDC_TXn_TX_PATH_CFG0(hpf_work->decimator); in tx_macro_tx_hpf_corner_freq_callback()
671 hpf_gate_reg = CDC_TXn_TX_PATH_SEC2(hpf_work->decimator); in tx_macro_tx_hpf_corner_freq_callback()
673 if (is_amic_enabled(component, hpf_work->decimator)) { in tx_macro_tx_hpf_corner_freq_callback()
709 tx = tx_mute_dwork->tx; in tx_macro_mute_update_callback()
710 component = tx->component; in tx_macro_mute_update_callback()
711 decimator = tx_mute_dwork->decimator; in tx_macro_mute_update_callback()
720 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in tx_macro_mclk_event()
741 struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm); in tx_macro_put_dec_enum()
742 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in tx_macro_put_dec_enum()
748 val = ucontrol->value.enumerated.item[0]; in tx_macro_put_dec_enum()
749 if (val >= e->items) in tx_macro_put_dec_enum()
750 return -EINVAL; in tx_macro_put_dec_enum()
752 switch (e->reg) { in tx_macro_put_dec_enum()
778 dev_err(component->dev, "Error in configuration!!\n"); in tx_macro_put_dec_enum()
779 return -EINVAL; in tx_macro_put_dec_enum()
783 if (widget->shift) { /* MSM DMIC */ in tx_macro_put_dec_enum()
796 tx->dmic_clk_div); in tx_macro_put_dec_enum()
807 struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm); in tx_macro_tx_mixer_get()
808 struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; in tx_macro_tx_mixer_get()
809 u32 dai_id = widget->shift; in tx_macro_tx_mixer_get()
810 u32 dec_id = mc->shift; in tx_macro_tx_mixer_get()
813 if (test_bit(dec_id, &tx->active_ch_mask[dai_id])) in tx_macro_tx_mixer_get()
814 ucontrol->value.integer.value[0] = 1; in tx_macro_tx_mixer_get()
816 ucontrol->value.integer.value[0] = 0; in tx_macro_tx_mixer_get()
825 struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm); in tx_macro_tx_mixer_put()
827 struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; in tx_macro_tx_mixer_put()
828 u32 dai_id = widget->shift; in tx_macro_tx_mixer_put()
829 u32 dec_id = mc->shift; in tx_macro_tx_mixer_put()
830 u32 enable = ucontrol->value.integer.value[0]; in tx_macro_tx_mixer_put()
834 if (tx->active_decimator[dai_id] == dec_id) in tx_macro_tx_mixer_put()
837 set_bit(dec_id, &tx->active_ch_mask[dai_id]); in tx_macro_tx_mixer_put()
838 tx->active_ch_cnt[dai_id]++; in tx_macro_tx_mixer_put()
839 tx->active_decimator[dai_id] = dec_id; in tx_macro_tx_mixer_put()
841 if (tx->active_decimator[dai_id] == -1) in tx_macro_tx_mixer_put()
844 tx->active_ch_cnt[dai_id]--; in tx_macro_tx_mixer_put()
845 clear_bit(dec_id, &tx->active_ch_mask[dai_id]); in tx_macro_tx_mixer_put()
846 tx->active_decimator[dai_id] = -1; in tx_macro_tx_mixer_put()
848 snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update); in tx_macro_tx_mixer_put()
856 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in tx_macro_enable_dec()
866 decimator = w->shift; in tx_macro_enable_dec()
885 tx->dmic_clk_div); in tx_macro_enable_dec()
890 tx->dec_mode[decimator]); in tx_macro_enable_dec()
906 tx->tx_hpf_work[decimator].hpf_cut_off_freq = in tx_macro_enable_dec()
920 &tx->tx_mute_dwork[decimator].dwork, in tx_macro_enable_dec()
922 if (tx->tx_hpf_work[decimator].hpf_cut_off_freq != CF_MIN_3DB_150HZ) { in tx_macro_enable_dec()
924 &tx->tx_hpf_work[decimator].dwork, in tx_macro_enable_dec()
949 if (tx->bcs_enable) { in tx_macro_enable_dec()
952 tx->bcs_clk_en = true; in tx_macro_enable_dec()
957 tx->tx_hpf_work[decimator].hpf_cut_off_freq; in tx_macro_enable_dec()
961 &tx->tx_hpf_work[decimator].dwork)) { in tx_macro_enable_dec()
991 cancel_delayed_work_sync(&tx->tx_mute_dwork[decimator].dwork); in tx_macro_enable_dec()
1000 if (tx->bcs_enable) { in tx_macro_enable_dec()
1007 tx->bcs_clk_en = false; in tx_macro_enable_dec()
1019 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in tx_macro_dec_mode_get()
1020 int path = e->shift_l; in tx_macro_dec_mode_get()
1022 ucontrol->value.integer.value[0] = tx->dec_mode[path]; in tx_macro_dec_mode_get()
1031 int value = ucontrol->value.integer.value[0]; in tx_macro_dec_mode_put()
1032 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in tx_macro_dec_mode_put()
1033 int path = e->shift_l; in tx_macro_dec_mode_put()
1036 if (tx->dec_mode[path] == value) in tx_macro_dec_mode_put()
1039 tx->dec_mode[path] = value; in tx_macro_dec_mode_put()
1050 ucontrol->value.integer.value[0] = tx->bcs_enable; in tx_macro_get_bcs()
1059 int value = ucontrol->value.integer.value[0]; in tx_macro_set_bcs()
1062 tx->bcs_enable = value; in tx_macro_set_bcs()
1071 struct snd_soc_component *component = dai->component; in tx_macro_hw_params()
1101 dev_err(component->dev, "%s: Invalid TX sample rate: %d\n", in tx_macro_hw_params()
1103 return -EINVAL; in tx_macro_hw_params()
1106 for_each_set_bit(decimator, &tx->active_ch_mask[dai->id], TX_MACRO_DEC_MAX) in tx_macro_hw_params()
1117 struct snd_soc_component *component = dai->component; in tx_macro_get_channel_map()
1120 switch (dai->id) { in tx_macro_get_channel_map()
1124 *tx_slot = tx->active_ch_mask[dai->id]; in tx_macro_get_channel_map()
1125 *tx_num = tx->active_ch_cnt[dai->id]; in tx_macro_get_channel_map()
1135 struct snd_soc_component *component = dai->component; in tx_macro_digital_mute()
1140 if (tx->active_decimator[dai->id] == -1) in tx_macro_digital_mute()
1143 decimator = tx->active_decimator[dai->id]; in tx_macro_digital_mute()
1775 -84, 40, digital_gain),
1778 -84, 40, digital_gain),
1781 -84, 40, digital_gain),
1784 -84, 40, digital_gain),
1787 -84, 40, digital_gain),
1790 -84, 40, digital_gain),
1793 -84, 40, digital_gain),
1796 -84, 40, digital_gain),
1831 snd_soc_component_init_regmap(comp, tx->regmap); in tx_macro_component_probe()
1834 tx->tx_hpf_work[i].tx = tx; in tx_macro_component_probe()
1835 tx->tx_hpf_work[i].decimator = i; in tx_macro_component_probe()
1836 INIT_DELAYED_WORK(&tx->tx_hpf_work[i].dwork, in tx_macro_component_probe()
1841 tx->tx_mute_dwork[i].tx = tx; in tx_macro_component_probe()
1842 tx->tx_mute_dwork[i].decimator = i; in tx_macro_component_probe()
1843 INIT_DELAYED_WORK(&tx->tx_mute_dwork[i].dwork, in tx_macro_component_probe()
1846 tx->component = comp; in tx_macro_component_probe()
1860 struct regmap *regmap = tx->regmap; in swclk_gate_enable()
1863 ret = clk_prepare_enable(tx->mclk); in swclk_gate_enable()
1865 dev_err(tx->dev, "failed to enable mclk\n"); in swclk_gate_enable()
1880 struct regmap *regmap = tx->regmap; in swclk_gate_disable()
1886 clk_disable_unprepare(tx->mclk); in swclk_gate_disable()
1894 regmap_read(tx->regmap, CDC_TX_CLK_RST_CTRL_SWR_CONTROL, &val); in swclk_gate_is_enabled()
1916 struct device *dev = tx->dev; in tx_macro_register_mclk_output()
1918 const char *clk_name = "lpass-tx-mclk"; in tx_macro_register_mclk_output()
1923 if (tx->npl) in tx_macro_register_mclk_output()
1924 parent_clk_name = __clk_get_name(tx->npl); in tx_macro_register_mclk_output()
1926 parent_clk_name = __clk_get_name(tx->mclk); in tx_macro_register_mclk_output()
1933 tx->hw.init = &init; in tx_macro_register_mclk_output()
1934 hw = &tx->hw; in tx_macro_register_mclk_output()
1943 .name = "RX-MACRO",
1955 struct device *dev = &pdev->dev; in tx_macro_probe()
1956 struct device_node *np = dev->of_node; in tx_macro_probe()
1966 return -ENOMEM; in tx_macro_probe()
1968 tx->macro = devm_clk_get_optional(dev, "macro"); in tx_macro_probe()
1969 if (IS_ERR(tx->macro)) in tx_macro_probe()
1970 return dev_err_probe(dev, PTR_ERR(tx->macro), "unable to get macro clock\n"); in tx_macro_probe()
1972 tx->dcodec = devm_clk_get_optional(dev, "dcodec"); in tx_macro_probe()
1973 if (IS_ERR(tx->dcodec)) in tx_macro_probe()
1974 return dev_err_probe(dev, PTR_ERR(tx->dcodec), "unable to get dcodec clock\n"); in tx_macro_probe()
1976 tx->mclk = devm_clk_get(dev, "mclk"); in tx_macro_probe()
1977 if (IS_ERR(tx->mclk)) in tx_macro_probe()
1978 return dev_err_probe(dev, PTR_ERR(tx->mclk), "unable to get mclk clock\n"); in tx_macro_probe()
1981 tx->npl = devm_clk_get(dev, "npl"); in tx_macro_probe()
1982 if (IS_ERR(tx->npl)) in tx_macro_probe()
1983 return dev_err_probe(dev, PTR_ERR(tx->npl), "unable to get npl clock\n"); in tx_macro_probe()
1986 tx->fsgen = devm_clk_get(dev, "fsgen"); in tx_macro_probe()
1987 if (IS_ERR(tx->fsgen)) in tx_macro_probe()
1988 return dev_err_probe(dev, PTR_ERR(tx->fsgen), "unable to get fsgen clock\n"); in tx_macro_probe()
1990 tx->pds = lpass_macro_pds_init(dev); in tx_macro_probe()
1991 if (IS_ERR(tx->pds)) in tx_macro_probe()
1992 return PTR_ERR(tx->pds); in tx_macro_probe()
2000 /* Update defaults for lpass sc7280 */ in tx_macro_probe()
2001 if (of_device_is_compatible(np, "qcom,sc7280-lpass-tx-macro")) { in tx_macro_probe()
2014 tx->regmap = devm_regmap_init_mmio(dev, base, &tx_regmap_config); in tx_macro_probe()
2015 if (IS_ERR(tx->regmap)) { in tx_macro_probe()
2016 ret = PTR_ERR(tx->regmap); in tx_macro_probe()
2022 tx->dev = dev; in tx_macro_probe()
2025 tx->active_decimator[TX_MACRO_AIF1_CAP] = -1; in tx_macro_probe()
2026 tx->active_decimator[TX_MACRO_AIF2_CAP] = -1; in tx_macro_probe()
2027 tx->active_decimator[TX_MACRO_AIF3_CAP] = -1; in tx_macro_probe()
2030 clk_set_rate(tx->mclk, MCLK_FREQ); in tx_macro_probe()
2031 clk_set_rate(tx->npl, MCLK_FREQ); in tx_macro_probe()
2033 ret = clk_prepare_enable(tx->macro); in tx_macro_probe()
2037 ret = clk_prepare_enable(tx->dcodec); in tx_macro_probe()
2041 ret = clk_prepare_enable(tx->mclk); in tx_macro_probe()
2045 ret = clk_prepare_enable(tx->npl); in tx_macro_probe()
2049 ret = clk_prepare_enable(tx->fsgen); in tx_macro_probe()
2056 regmap_update_bits(tx->regmap, CDC_TX_CLK_RST_CTRL_SWR_CONTROL, in tx_macro_probe()
2059 regmap_update_bits(tx->regmap, CDC_TX_CLK_RST_CTRL_SWR_CONTROL, in tx_macro_probe()
2064 regmap_update_bits(tx->regmap, CDC_TX_CLK_RST_CTRL_SWR_CONTROL, in tx_macro_probe()
2086 clk_disable_unprepare(tx->fsgen); in tx_macro_probe()
2088 clk_disable_unprepare(tx->npl); in tx_macro_probe()
2090 clk_disable_unprepare(tx->mclk); in tx_macro_probe()
2092 clk_disable_unprepare(tx->dcodec); in tx_macro_probe()
2094 clk_disable_unprepare(tx->macro); in tx_macro_probe()
2096 lpass_macro_pds_exit(tx->pds); in tx_macro_probe()
2103 struct tx_macro *tx = dev_get_drvdata(&pdev->dev); in tx_macro_remove()
2105 clk_disable_unprepare(tx->macro); in tx_macro_remove()
2106 clk_disable_unprepare(tx->dcodec); in tx_macro_remove()
2107 clk_disable_unprepare(tx->mclk); in tx_macro_remove()
2108 clk_disable_unprepare(tx->npl); in tx_macro_remove()
2109 clk_disable_unprepare(tx->fsgen); in tx_macro_remove()
2111 lpass_macro_pds_exit(tx->pds); in tx_macro_remove()
2118 regcache_cache_only(tx->regmap, true); in tx_macro_runtime_suspend()
2119 regcache_mark_dirty(tx->regmap); in tx_macro_runtime_suspend()
2121 clk_disable_unprepare(tx->fsgen); in tx_macro_runtime_suspend()
2122 clk_disable_unprepare(tx->npl); in tx_macro_runtime_suspend()
2123 clk_disable_unprepare(tx->mclk); in tx_macro_runtime_suspend()
2133 ret = clk_prepare_enable(tx->mclk); in tx_macro_runtime_resume()
2139 ret = clk_prepare_enable(tx->npl); in tx_macro_runtime_resume()
2145 ret = clk_prepare_enable(tx->fsgen); in tx_macro_runtime_resume()
2151 regcache_cache_only(tx->regmap, false); in tx_macro_runtime_resume()
2152 regcache_sync(tx->regmap); in tx_macro_runtime_resume()
2156 clk_disable_unprepare(tx->npl); in tx_macro_runtime_resume()
2158 clk_disable_unprepare(tx->mclk); in tx_macro_runtime_resume()
2169 .compatible = "qcom,sc7280-lpass-tx-macro",
2172 .compatible = "qcom,sm6115-lpass-tx-macro",
2175 .compatible = "qcom,sm8250-lpass-tx-macro",
2178 .compatible = "qcom,sm8450-lpass-tx-macro",
2181 .compatible = "qcom,sm8550-lpass-tx-macro",
2184 .compatible = "qcom,sc8280xp-lpass-tx-macro",
2203 MODULE_DESCRIPTION("TX macro driver");