Lines Matching +full:mt8188 +full:- +full:afe
1 // SPDX-License-Identifier: GPL-2.0
8 * Chun-Chia Chiu <chun-chia.chiu@mediatek.com>
14 #include "mt8188-afe-clk.h"
15 #include "mt8188-afe-common.h"
16 #include "mt8188-reg.h"
17 #include "../common/mtk-dai-adda-common.h"
32 static int mt8188_adda_mtkaif_init(struct mtk_base_afe *afe) in mt8188_adda_mtkaif_init() argument
34 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mt8188_adda_mtkaif_init()
35 struct mtkaif_param *param = &afe_priv->mtkaif_params; in mt8188_adda_mtkaif_init()
42 regmap_set_bits(afe->regmap, AFE_ADDA_MTKAIF_CFG0, in mt8188_adda_mtkaif_init()
45 regmap_set_bits(afe->regmap, AFE_AUD_PAD_TOP, RG_RX_PROTOCOL2); in mt8188_adda_mtkaif_init()
47 if (!param->mtkaif_calibration_ok) { in mt8188_adda_mtkaif_init()
48 dev_info(afe->dev, "%s(), calibration fail\n", __func__); in mt8188_adda_mtkaif_init()
53 if (param->mtkaif_phase_cycle[MT8188_MTKAIF_MISO_0] >= in mt8188_adda_mtkaif_init()
54 param->mtkaif_phase_cycle[MT8188_MTKAIF_MISO_1]) { in mt8188_adda_mtkaif_init()
57 param->mtkaif_phase_cycle[MT8188_MTKAIF_MISO_0] - in mt8188_adda_mtkaif_init()
58 param->mtkaif_phase_cycle[MT8188_MTKAIF_MISO_1]; in mt8188_adda_mtkaif_init()
62 param->mtkaif_phase_cycle[MT8188_MTKAIF_MISO_1] - in mt8188_adda_mtkaif_init()
63 param->mtkaif_phase_cycle[MT8188_MTKAIF_MISO_0]; in mt8188_adda_mtkaif_init()
70 regmap_update_bits(afe->regmap, AFE_ADDA_MTKAIF_RX_CFG2, mask, val); in mt8188_adda_mtkaif_init()
79 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_adda_mtkaif_cfg_event()
80 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt); in mtk_adda_mtkaif_cfg_event() local
82 dev_dbg(afe->dev, "%s(), name %s, event 0x%x\n", in mtk_adda_mtkaif_cfg_event()
83 __func__, w->name, event); in mtk_adda_mtkaif_cfg_event()
87 mt8188_adda_mtkaif_init(afe); in mtk_adda_mtkaif_cfg_event()
100 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_adda_dl_event()
101 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt); in mtk_adda_dl_event() local
103 dev_dbg(afe->dev, "%s(), name %s, event 0x%x\n", in mtk_adda_dl_event()
104 __func__, w->name, event); in mtk_adda_dl_event()
108 /* should delayed 1/fs(smallest is 8k) = 125us before afe off */ in mtk_adda_dl_event()
118 static void mtk_adda_ul_mictype(struct mtk_base_afe *afe, bool dmic) in mtk_adda_ul_mictype() argument
128 regmap_set_bits(afe->regmap, reg, val); in mtk_adda_ul_mictype()
130 regmap_clear_bits(afe->regmap, reg, val); in mtk_adda_ul_mictype()
137 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_adda_ul_event()
138 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt); in mtk_adda_ul_event() local
139 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_adda_ul_event()
140 struct mtkaif_param *param = &afe_priv->mtkaif_params; in mtk_adda_ul_event()
142 dev_dbg(afe->dev, "%s(), name %s, event 0x%x\n", in mtk_adda_ul_event()
143 __func__, w->name, event); in mtk_adda_ul_event()
147 mtk_adda_ul_mictype(afe, param->mtkaif_dmic_on); in mtk_adda_ul_event()
150 /* should delayed 1/fs(smallest is 8k) = 125us before afe off */ in mtk_adda_ul_event()
160 static struct mtk_dai_adda_priv *get_adda_priv_by_name(struct mtk_base_afe *afe, in get_adda_priv_by_name() argument
163 struct mt8188_afe_private *afe_priv = afe->platform_priv; in get_adda_priv_by_name()
166 return afe_priv->dai_priv[MT8188_AFE_IO_UL_SRC]; in get_adda_priv_by_name()
168 return afe_priv->dai_priv[MT8188_AFE_IO_DL_SRC]; in get_adda_priv_by_name()
177 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_afe_adda_hires_connect()
178 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt); in mtk_afe_adda_hires_connect() local
181 adda_priv = get_adda_priv_by_name(afe, w->name); in mtk_afe_adda_hires_connect()
184 dev_dbg(afe->dev, "adda_priv == NULL"); in mtk_afe_adda_hires_connect()
188 return (adda_priv->hires_required) ? 1 : 0; in mtk_afe_adda_hires_connect()
315 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt); in mt8188_adda_dmic_get() local
316 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mt8188_adda_dmic_get()
317 struct mtkaif_param *param = &afe_priv->mtkaif_params; in mt8188_adda_dmic_get()
319 ucontrol->value.integer.value[0] = param->mtkaif_dmic_on; in mt8188_adda_dmic_get()
327 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt); in mt8188_adda_dmic_set() local
328 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mt8188_adda_dmic_set()
329 struct mtkaif_param *param = &afe_priv->mtkaif_params; in mt8188_adda_dmic_set()
332 dmic_on = !!ucontrol->value.integer.value[0]; in mt8188_adda_dmic_set()
334 dev_dbg(afe->dev, "%s(), kcontrol name %s, dmic_on %d\n", in mt8188_adda_dmic_set()
335 __func__, kcontrol->id.name, dmic_on); in mt8188_adda_dmic_set()
337 if (param->mtkaif_dmic_on == dmic_on) in mt8188_adda_dmic_set()
340 param->mtkaif_dmic_on = dmic_on; in mt8188_adda_dmic_set()
351 static int mtk_dai_da_configure(struct mtk_base_afe *afe, in mtk_dai_da_configure() argument
360 mtk_adda_dl_rate_transform(afe, rate)); in mtk_dai_da_configure()
377 regmap_update_bits(afe->regmap, AFE_ADDA_DL_SRC2_CON0, mask, val); in mtk_dai_da_configure()
380 regmap_set_bits(afe->regmap, AFE_ADDA_DL_SDM_DCCOMP_CON, in mtk_dai_da_configure()
386 static int mtk_dai_ad_configure(struct mtk_base_afe *afe, in mtk_dai_ad_configure() argument
394 mtk_adda_ul_rate_transform(afe, rate)); in mtk_dai_ad_configure()
396 regmap_update_bits(afe->regmap, AFE_ADDA_UL_SRC_CON0, in mtk_dai_ad_configure()
405 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mtk_dai_adda_hw_params() local
406 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_dai_adda_hw_params()
407 struct mtk_dai_adda_priv *adda_priv = afe_priv->dai_priv[dai->id]; in mtk_dai_adda_hw_params()
409 int id = dai->id; in mtk_dai_adda_hw_params()
412 dev_dbg(afe->dev, "%s(), id %d, stream %d, rate %u\n", in mtk_dai_adda_hw_params()
413 __func__, id, substream->stream, rate); in mtk_dai_adda_hw_params()
415 adda_priv->hires_required = (rate > ADDA_HIRES_THRES); in mtk_dai_adda_hw_params()
417 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in mtk_dai_adda_hw_params()
418 ret = mtk_dai_da_configure(afe, rate, id); in mtk_dai_adda_hw_params()
420 ret = mtk_dai_ad_configure(afe, rate, id); in mtk_dai_adda_hw_params()
472 static int init_adda_priv_data(struct mtk_base_afe *afe) in init_adda_priv_data() argument
474 struct mt8188_afe_private *afe_priv = afe->platform_priv; in init_adda_priv_data()
480 adda_priv = devm_kzalloc(afe->dev, in init_adda_priv_data()
484 return -ENOMEM; in init_adda_priv_data()
486 afe_priv->dai_priv[adda_dai_list[i]] = adda_priv; in init_adda_priv_data()
492 int mt8188_dai_adda_register(struct mtk_base_afe *afe) in mt8188_dai_adda_register() argument
496 dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); in mt8188_dai_adda_register()
498 return -ENOMEM; in mt8188_dai_adda_register()
500 list_add(&dai->list, &afe->sub_dais); in mt8188_dai_adda_register()
502 dai->dai_drivers = mtk_dai_adda_driver; in mt8188_dai_adda_register()
503 dai->num_dai_drivers = ARRAY_SIZE(mtk_dai_adda_driver); in mt8188_dai_adda_register()
505 dai->dapm_widgets = mtk_dai_adda_widgets; in mt8188_dai_adda_register()
506 dai->num_dapm_widgets = ARRAY_SIZE(mtk_dai_adda_widgets); in mt8188_dai_adda_register()
507 dai->dapm_routes = mtk_dai_adda_routes; in mt8188_dai_adda_register()
508 dai->num_dapm_routes = ARRAY_SIZE(mtk_dai_adda_routes); in mt8188_dai_adda_register()
509 dai->controls = mtk_dai_adda_controls; in mt8188_dai_adda_register()
510 dai->num_controls = ARRAY_SIZE(mtk_dai_adda_controls); in mt8188_dai_adda_register()
512 return init_adda_priv_data(afe); in mt8188_dai_adda_register()