Lines Matching +full:asrc +full:- +full:rate

1 // SPDX-License-Identifier: GPL-2.0
11 #include "mt8186-afe-clk.h"
12 #include "mt8186-afe-common.h"
13 #include "mt8186-afe-gpio.h"
14 #include "mt8186-interconnection.h"
43 int rate; /* for determine which apll to use */ member
88 return -EINVAL; in get_i2s_id_by_name()
94 struct mt8186_afe_private *afe_priv = afe->platform_priv; in get_i2s_priv_by_name()
100 return afe_priv->dai_priv[dai_id]; in get_i2s_priv_by_name()
120 i2s_priv = get_i2s_priv_by_name(afe, kcontrol->id.name); in mt8186_i2s_hd_get()
121 ucontrol->value.integer.value[0] = i2s_priv->low_jitter_en; in mt8186_i2s_hd_get()
132 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in mt8186_i2s_hd_set()
135 if (ucontrol->value.enumerated.item[0] >= e->items) in mt8186_i2s_hd_set()
136 return -EINVAL; in mt8186_i2s_hd_set()
138 hd_en = ucontrol->value.integer.value[0]; in mt8186_i2s_hd_set()
140 dev_dbg(afe->dev, "%s(), kcontrol name %s, hd_en %d\n", in mt8186_i2s_hd_set()
141 __func__, kcontrol->id.name, hd_en); in mt8186_i2s_hd_set()
143 i2s_priv = get_i2s_priv_by_name(afe, kcontrol->id.name); in mt8186_i2s_hd_set()
144 if (i2s_priv->low_jitter_en == hd_en) in mt8186_i2s_hd_set()
147 i2s_priv->low_jitter_en = hd_en; in mt8186_i2s_hd_set()
361 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_i2s_en_event()
365 i2s_priv = get_i2s_priv_by_name(afe, w->name); in mtk_i2s_en_event()
367 dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n", in mtk_i2s_en_event()
368 __func__, w->name, event); in mtk_i2s_en_event()
372 mt8186_afe_gpio_request(afe->dev, true, i2s_priv->id, 0); in mtk_i2s_en_event()
375 mt8186_afe_gpio_request(afe->dev, false, i2s_priv->id, 0); in mtk_i2s_en_event()
388 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_apll_event()
391 dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n", in mtk_apll_event()
392 __func__, w->name, event); in mtk_apll_event()
418 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_mclk_en_event()
422 dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n", in mtk_mclk_en_event()
423 __func__, w->name, event); in mtk_mclk_en_event()
425 i2s_priv = get_i2s_priv_by_name(afe, w->name); in mtk_mclk_en_event()
429 mt8186_mck_enable(afe, i2s_priv->mclk_id, i2s_priv->mclk_rate); in mtk_mclk_en_event()
432 i2s_priv->mclk_rate = 0; in mtk_mclk_en_event()
433 mt8186_mck_disable(afe, i2s_priv->mclk_id); in mtk_mclk_en_event()
541 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_afe_i2s_share_connect()
545 i2s_priv = get_i2s_priv_by_name(afe, sink->name); in mtk_afe_i2s_share_connect()
546 if (i2s_priv->share_i2s_id < 0) in mtk_afe_i2s_share_connect()
549 return i2s_priv->share_i2s_id == get_i2s_id_by_name(afe, source->name); in mtk_afe_i2s_share_connect()
556 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_afe_i2s_hd_connect()
560 i2s_priv = get_i2s_priv_by_name(afe, sink->name); in mtk_afe_i2s_hd_connect()
561 if (get_i2s_id_by_name(afe, sink->name) == in mtk_afe_i2s_hd_connect()
562 get_i2s_id_by_name(afe, source->name)) in mtk_afe_i2s_hd_connect()
563 return i2s_priv->low_jitter_en; in mtk_afe_i2s_hd_connect()
566 if (i2s_priv->share_i2s_id < 0) in mtk_afe_i2s_hd_connect()
569 if (i2s_priv->share_i2s_id == get_i2s_id_by_name(afe, source->name)) in mtk_afe_i2s_hd_connect()
570 return i2s_priv->low_jitter_en; in mtk_afe_i2s_hd_connect()
579 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_afe_i2s_apll_connect()
585 i2s_priv = get_i2s_priv_by_name(afe, w->name); in mtk_afe_i2s_apll_connect()
587 cur_apll = mt8186_get_apll_by_name(afe, source->name); in mtk_afe_i2s_apll_connect()
588 /* choose APLL from i2s rate */ in mtk_afe_i2s_apll_connect()
589 i2s_need_apll = mt8186_get_apll_by_rate(afe, i2s_priv->rate); in mtk_afe_i2s_apll_connect()
598 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_afe_i2s_mclk_connect()
602 i2s_priv = get_i2s_priv_by_name(afe, sink->name); in mtk_afe_i2s_mclk_connect()
603 if (get_i2s_id_by_name(afe, sink->name) == in mtk_afe_i2s_mclk_connect()
604 get_i2s_id_by_name(afe, source->name)) in mtk_afe_i2s_mclk_connect()
605 return (i2s_priv->mclk_rate > 0) ? 1 : 0; in mtk_afe_i2s_mclk_connect()
608 if (i2s_priv->share_i2s_id < 0) in mtk_afe_i2s_mclk_connect()
611 if (i2s_priv->share_i2s_id == get_i2s_id_by_name(afe, source->name)) in mtk_afe_i2s_mclk_connect()
612 return (i2s_priv->mclk_rate > 0) ? 1 : 0; in mtk_afe_i2s_mclk_connect()
621 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_afe_mclk_apll_connect()
626 i2s_priv = get_i2s_priv_by_name(afe, w->name); in mtk_afe_mclk_apll_connect()
628 cur_apll = mt8186_get_apll_by_name(afe, source->name); in mtk_afe_mclk_apll_connect()
630 return (i2s_priv->mclk_apll == cur_apll) ? 1 : 0; in mtk_afe_mclk_apll_connect()
814 unsigned int rate = params_rate(params); in mtk_dai_connsys_i2s_hw_params() local
815 unsigned int rate_reg = mt8186_rate_transform(afe->dev, in mtk_dai_connsys_i2s_hw_params()
816 rate, dai->id); in mtk_dai_connsys_i2s_hw_params()
819 dev_dbg(afe->dev, "%s(), id %d, stream %d, rate %d\n", in mtk_dai_connsys_i2s_hw_params()
820 __func__, dai->id, substream->stream, rate); in mtk_dai_connsys_i2s_hw_params()
822 /* non-inverse, i2s mode, slave, 16bits, from connsys */ in mtk_dai_connsys_i2s_hw_params()
828 regmap_write(afe->regmap, AFE_CONNSYS_I2S_CON, i2s_con); in mtk_dai_connsys_i2s_hw_params()
830 /* use asrc */ in mtk_dai_connsys_i2s_hw_params()
831 regmap_update_bits(afe->regmap, AFE_CONNSYS_I2S_CON, in mtk_dai_connsys_i2s_hw_params()
834 /* slave mode, set i2s for asrc */ in mtk_dai_connsys_i2s_hw_params()
835 regmap_update_bits(afe->regmap, AFE_CONNSYS_I2S_CON, in mtk_dai_connsys_i2s_hw_params()
838 if (rate == 44100) in mtk_dai_connsys_i2s_hw_params()
839 regmap_write(afe->regmap, AFE_ASRC_2CH_CON3, 0x1b9000); in mtk_dai_connsys_i2s_hw_params()
840 else if (rate == 32000) in mtk_dai_connsys_i2s_hw_params()
841 regmap_write(afe->regmap, AFE_ASRC_2CH_CON3, 0x140000); in mtk_dai_connsys_i2s_hw_params()
843 regmap_write(afe->regmap, AFE_ASRC_2CH_CON3, 0x1e0000); in mtk_dai_connsys_i2s_hw_params()
846 regmap_write(afe->regmap, AFE_ASRC_2CH_CON4, 0x140000); in mtk_dai_connsys_i2s_hw_params()
847 regmap_write(afe->regmap, AFE_ASRC_2CH_CON9, 0x36000); in mtk_dai_connsys_i2s_hw_params()
848 regmap_write(afe->regmap, AFE_ASRC_2CH_CON10, 0x2fc00); in mtk_dai_connsys_i2s_hw_params()
849 regmap_write(afe->regmap, AFE_ASRC_2CH_CON6, 0x7ef4); in mtk_dai_connsys_i2s_hw_params()
850 regmap_write(afe->regmap, AFE_ASRC_2CH_CON5, 0xff5986); in mtk_dai_connsys_i2s_hw_params()
853 regmap_update_bits(afe->regmap, AFE_ASRC_2CH_CON2, in mtk_dai_connsys_i2s_hw_params()
863 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mtk_dai_connsys_i2s_trigger()
865 dev_dbg(afe->dev, "%s(), cmd %d, stream %d\n", in mtk_dai_connsys_i2s_trigger()
866 __func__, cmd, substream->stream); in mtk_dai_connsys_i2s_trigger()
872 regmap_update_bits(afe->regmap, in mtk_dai_connsys_i2s_trigger()
878 regmap_update_bits(afe->regmap, in mtk_dai_connsys_i2s_trigger()
883 /* asrc enable */ in mtk_dai_connsys_i2s_trigger()
884 regmap_update_bits(afe->regmap, in mtk_dai_connsys_i2s_trigger()
888 regmap_update_bits(afe->regmap, in mtk_dai_connsys_i2s_trigger()
893 afe_priv->dai_on[dai->id] = true; in mtk_dai_connsys_i2s_trigger()
897 regmap_update_bits(afe->regmap, AFE_ASRC_2CH_CON0, in mtk_dai_connsys_i2s_trigger()
899 regmap_update_bits(afe->regmap, AFE_ASRC_2CH_CON5, in mtk_dai_connsys_i2s_trigger()
903 regmap_update_bits(afe->regmap, AFE_CONNSYS_I2S_CON, in mtk_dai_connsys_i2s_trigger()
906 /* bypass asrc */ in mtk_dai_connsys_i2s_trigger()
907 regmap_update_bits(afe->regmap, AFE_CONNSYS_I2S_CON, in mtk_dai_connsys_i2s_trigger()
910 afe_priv->dai_on[dai->id] = false; in mtk_dai_connsys_i2s_trigger()
913 return -EINVAL; in mtk_dai_connsys_i2s_trigger()
928 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mtk_dai_i2s_config()
929 struct mtk_afe_i2s_priv *i2s_priv = afe_priv->dai_priv[i2s_id]; in mtk_dai_i2s_config()
931 unsigned int rate = params_rate(params); in mtk_dai_i2s_config() local
932 unsigned int rate_reg = mt8186_rate_transform(afe->dev, in mtk_dai_i2s_config()
933 rate, i2s_id); in mtk_dai_i2s_config()
938 dev_dbg(afe->dev, "%s(), id %d, rate %d, format %d\n", in mtk_dai_i2s_config()
939 __func__, i2s_id, rate, format); in mtk_dai_i2s_config()
941 i2s_priv->rate = rate; in mtk_dai_i2s_config()
949 regmap_update_bits(afe->regmap, AFE_I2S_CON, in mtk_dai_i2s_config()
957 regmap_update_bits(afe->regmap, AFE_I2S_CON1, in mtk_dai_i2s_config()
965 regmap_update_bits(afe->regmap, AFE_I2S_CON2, in mtk_dai_i2s_config()
972 regmap_update_bits(afe->regmap, AFE_I2S_CON3, in mtk_dai_i2s_config()
976 dev_err(afe->dev, "%s(), id %d not support\n", in mtk_dai_i2s_config()
978 return -EINVAL; in mtk_dai_i2s_config()
982 if (i2s_priv->share_i2s_id >= 0) { in mtk_dai_i2s_config()
983 ret = mtk_dai_i2s_config(afe, params, i2s_priv->share_i2s_id); in mtk_dai_i2s_config()
997 return mtk_dai_i2s_config(afe, params, dai->id); in mtk_dai_i2s_hw_params()
1003 struct mtk_base_afe *afe = dev_get_drvdata(dai->dev); in mtk_dai_i2s_set_sysclk()
1004 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mtk_dai_i2s_set_sysclk()
1005 struct mtk_afe_i2s_priv *i2s_priv = afe_priv->dai_priv[dai->id]; in mtk_dai_i2s_set_sysclk()
1010 dev_err(afe->dev, "%s(), dir != SND_SOC_CLOCK_OUT", __func__); in mtk_dai_i2s_set_sysclk()
1011 return -EINVAL; in mtk_dai_i2s_set_sysclk()
1014 dev_dbg(afe->dev, "%s(), freq %d\n", __func__, freq); in mtk_dai_i2s_set_sysclk()
1020 dev_err(afe->dev, "%s(), freq > apll rate", __func__); in mtk_dai_i2s_set_sysclk()
1021 return -EINVAL; in mtk_dai_i2s_set_sysclk()
1025 dev_err(afe->dev, "%s(), APLL cannot generate freq Hz", __func__); in mtk_dai_i2s_set_sysclk()
1026 return -EINVAL; in mtk_dai_i2s_set_sysclk()
1029 i2s_priv->mclk_rate = freq; in mtk_dai_i2s_set_sysclk()
1030 i2s_priv->mclk_apll = apll; in mtk_dai_i2s_set_sysclk()
1032 if (i2s_priv->share_i2s_id > 0) { in mtk_dai_i2s_set_sysclk()
1035 share_i2s_priv = afe_priv->dai_priv[i2s_priv->share_i2s_id]; in mtk_dai_i2s_set_sysclk()
1037 dev_err(afe->dev, "%s(), share_i2s_priv == NULL", __func__); in mtk_dai_i2s_set_sysclk()
1038 return -EINVAL; in mtk_dai_i2s_set_sysclk()
1041 share_i2s_priv->mclk_rate = i2s_priv->mclk_rate; in mtk_dai_i2s_set_sysclk()
1042 share_i2s_priv->mclk_apll = i2s_priv->mclk_apll; in mtk_dai_i2s_set_sysclk()
1142 .share_i2s_id = -1,
1147 .share_i2s_id = -1,
1152 .share_i2s_id = -1,
1158 .share_i2s_id = -1,
1163 * mt8186_dai_i2s_set_share() - Set up I2S ports to share a single clock.
1176 return -EINVAL; in mt8186_dai_i2s_set_share()
1182 secondary_i2s_priv->share_i2s_id = main_i2s_id; in mt8186_dai_i2s_set_share()
1209 dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); in mt8186_dai_i2s_register()
1211 return -ENOMEM; in mt8186_dai_i2s_register()
1213 list_add(&dai->list, &afe->sub_dais); in mt8186_dai_i2s_register()
1215 dai->dai_drivers = mtk_dai_i2s_driver; in mt8186_dai_i2s_register()
1216 dai->num_dai_drivers = ARRAY_SIZE(mtk_dai_i2s_driver); in mt8186_dai_i2s_register()
1218 dai->controls = mtk_dai_i2s_controls; in mt8186_dai_i2s_register()
1219 dai->num_controls = ARRAY_SIZE(mtk_dai_i2s_controls); in mt8186_dai_i2s_register()
1220 dai->dapm_widgets = mtk_dai_i2s_widgets; in mt8186_dai_i2s_register()
1221 dai->num_dapm_widgets = ARRAY_SIZE(mtk_dai_i2s_widgets); in mt8186_dai_i2s_register()
1222 dai->dapm_routes = mtk_dai_i2s_routes; in mt8186_dai_i2s_register()
1223 dai->num_dapm_routes = ARRAY_SIZE(mtk_dai_i2s_routes); in mt8186_dai_i2s_register()