Lines Matching +full:fe +full:- +full:dai +full:- +full:link
1 // SPDX-License-Identifier: GPL-2.0
17 #include "mt2701-afe-common.h"
18 #include "mt2701-afe-clock-ctrl.h"
19 #include "../common/mtk-afe-platform-driver.h"
20 #include "../common/mtk-afe-fe-dai.h"
84 struct mt2701_afe_private *afe_priv = afe->platform_priv; in mt2701_dai_num_to_i2s()
85 int val = num - MT2701_IO_I2S; in mt2701_dai_num_to_i2s()
87 if (val < 0 || val >= afe_priv->soc->i2s_num) { in mt2701_dai_num_to_i2s()
88 dev_err(afe->dev, "%s, num not available, num %d, val %d\n", in mt2701_dai_num_to_i2s()
90 return -EINVAL; in mt2701_dai_num_to_i2s()
103 return -EINVAL; in mt2701_afe_i2s_fs()
107 struct snd_soc_dai *dai) in mt2701_afe_i2s_startup() argument
109 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt2701_afe_i2s_startup()
110 struct mt2701_afe_private *afe_priv = afe->platform_priv; in mt2701_afe_i2s_startup()
111 int i2s_num = mt2701_dai_num_to_i2s(afe, dai->id); in mt2701_afe_i2s_startup()
112 bool mode = afe_priv->soc->has_one_heart_mode; in mt2701_afe_i2s_startup()
124 const struct mt2701_i2s_data *i2s_data = i2s_path->i2s_data[stream_dir]; in mt2701_afe_i2s_path_disable()
126 if (--i2s_path->on[stream_dir] < 0) in mt2701_afe_i2s_path_disable()
127 i2s_path->on[stream_dir] = 0; in mt2701_afe_i2s_path_disable()
129 if (i2s_path->on[stream_dir]) in mt2701_afe_i2s_path_disable()
133 regmap_update_bits(afe->regmap, i2s_data->i2s_ctrl_reg, in mt2701_afe_i2s_path_disable()
142 struct snd_soc_dai *dai) in mt2701_afe_i2s_shutdown() argument
144 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt2701_afe_i2s_shutdown()
145 struct mt2701_afe_private *afe_priv = afe->platform_priv; in mt2701_afe_i2s_shutdown()
146 int i2s_num = mt2701_dai_num_to_i2s(afe, dai->id); in mt2701_afe_i2s_shutdown()
148 bool mode = afe_priv->soc->has_one_heart_mode; in mt2701_afe_i2s_shutdown()
153 i2s_path = &afe_priv->i2s_path[i2s_num]; in mt2701_afe_i2s_shutdown()
155 if (i2s_path->occupied[substream->stream]) in mt2701_afe_i2s_shutdown()
156 i2s_path->occupied[substream->stream] = 0; in mt2701_afe_i2s_shutdown()
160 mt2701_afe_i2s_path_disable(afe, i2s_path, substream->stream); in mt2701_afe_i2s_shutdown()
162 /* need to disable i2s-out path when disable i2s-in */ in mt2701_afe_i2s_shutdown()
163 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in mt2701_afe_i2s_shutdown()
164 mt2701_afe_i2s_path_disable(afe, i2s_path, !substream->stream); in mt2701_afe_i2s_shutdown()
175 const struct mt2701_i2s_data *i2s_data = i2s_path->i2s_data[stream_dir]; in mt2701_i2s_path_enable()
176 struct mt2701_afe_private *afe_priv = afe->platform_priv; in mt2701_i2s_path_enable()
181 if (++i2s_path->on[stream_dir] != 1) in mt2701_i2s_path_enable()
200 if (afe_priv->soc->has_one_heart_mode) { in mt2701_i2s_path_enable()
207 regmap_update_bits(afe->regmap, i2s_data->i2s_ctrl_reg, mask, val); in mt2701_i2s_path_enable()
209 regmap_update_bits(afe->regmap, reg, in mt2701_i2s_path_enable()
210 i2s_data->i2s_asrc_fs_mask in mt2701_i2s_path_enable()
211 << i2s_data->i2s_asrc_fs_shift, in mt2701_i2s_path_enable()
212 fs << i2s_data->i2s_asrc_fs_shift); in mt2701_i2s_path_enable()
218 regmap_update_bits(afe->regmap, i2s_data->i2s_ctrl_reg, in mt2701_i2s_path_enable()
221 regmap_update_bits(afe->regmap, i2s_data->i2s_ctrl_reg, in mt2701_i2s_path_enable()
224 regmap_update_bits(afe->regmap, i2s_data->i2s_ctrl_reg, in mt2701_i2s_path_enable()
230 struct snd_soc_dai *dai) in mt2701_afe_i2s_prepare() argument
232 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt2701_afe_i2s_prepare()
233 struct mt2701_afe_private *afe_priv = afe->platform_priv; in mt2701_afe_i2s_prepare()
234 int ret, i2s_num = mt2701_dai_num_to_i2s(afe, dai->id); in mt2701_afe_i2s_prepare()
236 bool mode = afe_priv->soc->has_one_heart_mode; in mt2701_afe_i2s_prepare()
241 i2s_path = &afe_priv->i2s_path[i2s_num]; in mt2701_afe_i2s_prepare()
243 if (i2s_path->occupied[substream->stream]) in mt2701_afe_i2s_prepare()
244 return -EBUSY; in mt2701_afe_i2s_prepare()
250 i2s_path->occupied[substream->stream] = 1; in mt2701_afe_i2s_prepare()
252 /* need to enable i2s-out path when enable i2s-in */ in mt2701_afe_i2s_prepare()
253 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) in mt2701_afe_i2s_prepare()
254 mt2701_i2s_path_enable(afe, i2s_path, !substream->stream, in mt2701_afe_i2s_prepare()
255 substream->runtime->rate); in mt2701_afe_i2s_prepare()
257 mt2701_i2s_path_enable(afe, i2s_path, substream->stream, in mt2701_afe_i2s_prepare()
258 substream->runtime->rate); in mt2701_afe_i2s_prepare()
263 static int mt2701_afe_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id, in mt2701_afe_i2s_set_sysclk() argument
266 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt2701_afe_i2s_set_sysclk()
267 struct mt2701_afe_private *afe_priv = afe->platform_priv; in mt2701_afe_i2s_set_sysclk()
268 int i2s_num = mt2701_dai_num_to_i2s(afe, dai->id); in mt2701_afe_i2s_set_sysclk()
269 bool mode = afe_priv->soc->has_one_heart_mode; in mt2701_afe_i2s_set_sysclk()
276 dev_warn(dai->dev, "The SoCs doesn't support mclk input\n"); in mt2701_afe_i2s_set_sysclk()
277 return -EINVAL; in mt2701_afe_i2s_set_sysclk()
280 afe_priv->i2s_path[mode ? 1 : i2s_num].mclk_rate = freq; in mt2701_afe_i2s_set_sysclk()
286 struct snd_soc_dai *dai) in mt2701_btmrg_startup() argument
288 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt2701_btmrg_startup()
289 struct mt2701_afe_private *afe_priv = afe->platform_priv; in mt2701_btmrg_startup()
296 afe_priv->mrg_enable[substream->stream] = 1; in mt2701_btmrg_startup()
303 struct snd_soc_dai *dai) in mt2701_btmrg_hw_params() argument
305 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt2701_btmrg_hw_params()
312 dev_err(afe->dev, "unsupported rate %d\n", stream_fs); in mt2701_btmrg_hw_params()
313 return -EINVAL; in mt2701_btmrg_hw_params()
316 regmap_update_bits(afe->regmap, AFE_MRGIF_CON, in mt2701_btmrg_hw_params()
329 regmap_update_bits(afe->regmap, AFE_DAIBT_CON0, msk, val); in mt2701_btmrg_hw_params()
331 regmap_update_bits(afe->regmap, AFE_DAIBT_CON0, in mt2701_btmrg_hw_params()
334 regmap_update_bits(afe->regmap, AFE_MRGIF_CON, in mt2701_btmrg_hw_params()
337 regmap_update_bits(afe->regmap, AFE_MRGIF_CON, in mt2701_btmrg_hw_params()
344 struct snd_soc_dai *dai) in mt2701_btmrg_shutdown() argument
346 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt2701_btmrg_shutdown()
347 struct mt2701_afe_private *afe_priv = afe->platform_priv; in mt2701_btmrg_shutdown()
350 if (!afe_priv->mrg_enable[!substream->stream]) { in mt2701_btmrg_shutdown()
351 regmap_update_bits(afe->regmap, AFE_DAIBT_CON0, in mt2701_btmrg_shutdown()
353 regmap_update_bits(afe->regmap, AFE_MRGIF_CON, in mt2701_btmrg_shutdown()
355 regmap_update_bits(afe->regmap, AFE_MRGIF_CON, in mt2701_btmrg_shutdown()
360 afe_priv->mrg_enable[substream->stream] = 0; in mt2701_btmrg_shutdown()
364 struct snd_soc_dai *dai) in mt2701_simple_fe_startup() argument
366 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt2701_simple_fe_startup()
368 int stream_dir = substream->stream; in mt2701_simple_fe_startup()
372 memif_tmp = &afe->memif[MT2701_MEMIF_DLM]; in mt2701_simple_fe_startup()
373 if (memif_tmp->substream) { in mt2701_simple_fe_startup()
374 dev_warn(afe->dev, "memif is not available"); in mt2701_simple_fe_startup()
375 return -EBUSY; in mt2701_simple_fe_startup()
379 return mtk_afe_fe_startup(substream, dai); in mt2701_simple_fe_startup()
384 struct snd_soc_dai *dai) in mt2701_simple_fe_hw_params() argument
386 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt2701_simple_fe_hw_params()
387 int stream_dir = substream->stream; in mt2701_simple_fe_hw_params()
391 regmap_update_bits(afe->regmap, in mt2701_simple_fe_hw_params()
396 return mtk_afe_fe_hw_params(substream, params, dai); in mt2701_simple_fe_hw_params()
400 struct snd_soc_dai *dai) in mt2701_dlm_fe_startup() argument
402 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt2701_dlm_fe_startup()
408 memif_tmp = &afe->memif[i]; in mt2701_dlm_fe_startup()
409 if (memif_tmp->substream) in mt2701_dlm_fe_startup()
410 return -EBUSY; in mt2701_dlm_fe_startup()
415 memif_data = afe->memif[i].data; in mt2701_dlm_fe_startup()
416 regmap_update_bits(afe->regmap, in mt2701_dlm_fe_startup()
417 memif_data->agent_disable_reg, in mt2701_dlm_fe_startup()
418 1 << memif_data->agent_disable_shift, in mt2701_dlm_fe_startup()
419 0 << memif_data->agent_disable_shift); in mt2701_dlm_fe_startup()
422 return mtk_afe_fe_startup(substream, dai); in mt2701_dlm_fe_startup()
426 struct snd_soc_dai *dai) in mt2701_dlm_fe_shutdown() argument
428 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt2701_dlm_fe_shutdown()
433 memif_data = afe->memif[i].data; in mt2701_dlm_fe_shutdown()
434 regmap_update_bits(afe->regmap, in mt2701_dlm_fe_shutdown()
435 memif_data->agent_disable_reg, in mt2701_dlm_fe_shutdown()
436 1 << memif_data->agent_disable_shift, in mt2701_dlm_fe_shutdown()
437 1 << memif_data->agent_disable_shift); in mt2701_dlm_fe_shutdown()
440 return mtk_afe_fe_shutdown(substream, dai); in mt2701_dlm_fe_shutdown()
445 struct snd_soc_dai *dai) in mt2701_dlm_fe_hw_params() argument
447 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt2701_dlm_fe_hw_params()
450 regmap_update_bits(afe->regmap, in mt2701_dlm_fe_hw_params()
454 regmap_update_bits(afe->regmap, in mt2701_dlm_fe_hw_params()
458 regmap_update_bits(afe->regmap, in mt2701_dlm_fe_hw_params()
463 return mtk_afe_fe_hw_params(substream, params, dai); in mt2701_dlm_fe_hw_params()
467 int cmd, struct snd_soc_dai *dai) in mt2701_dlm_fe_trigger() argument
469 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); in mt2701_dlm_fe_trigger()
470 struct mtk_base_afe_memif *memif_tmp = &afe->memif[MT2701_MEMIF_DL1]; in mt2701_dlm_fe_trigger()
475 regmap_update_bits(afe->regmap, memif_tmp->data->enable_reg, in mt2701_dlm_fe_trigger()
476 1 << memif_tmp->data->enable_shift, in mt2701_dlm_fe_trigger()
477 1 << memif_tmp->data->enable_shift); in mt2701_dlm_fe_trigger()
478 mtk_afe_fe_trigger(substream, cmd, dai); in mt2701_dlm_fe_trigger()
482 mtk_afe_fe_trigger(substream, cmd, dai); in mt2701_dlm_fe_trigger()
483 regmap_update_bits(afe->regmap, memif_tmp->data->enable_reg, in mt2701_dlm_fe_trigger()
484 1 << memif_tmp->data->enable_shift, 0); in mt2701_dlm_fe_trigger()
488 return -EINVAL; in mt2701_dlm_fe_trigger()
498 if (snd_soc_rtd_to_cpu(rtd, 0)->id != MT2701_MEMIF_ULBT) in mt2701_memif_fs()
511 /* FE DAIs */
546 /* FE DAIs: memory intefaces to CPU */
835 /* inter-connections */
920 /* I02,03 link to UL2, also need to open I2S0 */
959 snd_soc_component_init_regmap(component, afe->regmap); in mt2701_afe_pcm_probe()
966 .name = "mt2701-afe-pcm-dai",
992 .msb_reg = -1,
1010 .msb_reg = -1,
1028 .msb_reg = -1,
1046 .msb_reg = -1,
1064 .msb_reg = -1,
1074 .mono_reg = -1,
1075 .mono_shift = -1,
1082 .msb_reg = -1,
1100 .msb_reg = -1,
1118 .msb_reg = -1,
1136 .msb_reg = -1,
1154 .msb_reg = -1,
1172 .msb_reg = -1,
1190 .msb_reg = -1,
1200 .mono_reg = -1,
1201 .mono_shift = -1,
1208 .msb_reg = -1,
1271 /* TODO - extend control registers supported by newer SoCs */
1282 regmap_read(afe->regmap, ASYS_IRQ_STATUS, &status); in mt2701_asys_isr()
1283 regmap_write(afe->regmap, ASYS_IRQ_CLR, status); in mt2701_asys_isr()
1286 memif = &afe->memif[id]; in mt2701_asys_isr()
1287 if (memif->irq_usage < 0) in mt2701_asys_isr()
1290 irq = &afe->irqs[memif->irq_usage]; in mt2701_asys_isr()
1291 if (status & 1 << irq->irq_data->irq_clr_shift) in mt2701_asys_isr()
1292 snd_pcm_period_elapsed(memif->substream); in mt2701_asys_isr()
1319 afe = devm_kzalloc(&pdev->dev, sizeof(*afe), GFP_KERNEL); in mt2701_afe_pcm_dev_probe()
1321 return -ENOMEM; in mt2701_afe_pcm_dev_probe()
1323 afe->platform_priv = devm_kzalloc(&pdev->dev, sizeof(*afe_priv), in mt2701_afe_pcm_dev_probe()
1325 if (!afe->platform_priv) in mt2701_afe_pcm_dev_probe()
1326 return -ENOMEM; in mt2701_afe_pcm_dev_probe()
1328 afe_priv = afe->platform_priv; in mt2701_afe_pcm_dev_probe()
1329 afe_priv->soc = of_device_get_match_data(&pdev->dev); in mt2701_afe_pcm_dev_probe()
1330 afe->dev = &pdev->dev; in mt2701_afe_pcm_dev_probe()
1331 dev = afe->dev; in mt2701_afe_pcm_dev_probe()
1333 afe_priv->i2s_path = devm_kcalloc(dev, in mt2701_afe_pcm_dev_probe()
1334 afe_priv->soc->i2s_num, in mt2701_afe_pcm_dev_probe()
1337 if (!afe_priv->i2s_path) in mt2701_afe_pcm_dev_probe()
1338 return -ENOMEM; in mt2701_afe_pcm_dev_probe()
1345 IRQF_TRIGGER_NONE, "asys-isr", (void *)afe); in mt2701_afe_pcm_dev_probe()
1347 dev_err(dev, "could not request_irq for asys-isr\n"); in mt2701_afe_pcm_dev_probe()
1351 afe->regmap = syscon_node_to_regmap(dev->parent->of_node); in mt2701_afe_pcm_dev_probe()
1352 if (IS_ERR(afe->regmap)) { in mt2701_afe_pcm_dev_probe()
1354 return PTR_ERR(afe->regmap); in mt2701_afe_pcm_dev_probe()
1357 mutex_init(&afe->irq_alloc_lock); in mt2701_afe_pcm_dev_probe()
1360 afe->memif_size = MT2701_MEMIF_NUM; in mt2701_afe_pcm_dev_probe()
1361 afe->memif = devm_kcalloc(dev, afe->memif_size, sizeof(*afe->memif), in mt2701_afe_pcm_dev_probe()
1363 if (!afe->memif) in mt2701_afe_pcm_dev_probe()
1364 return -ENOMEM; in mt2701_afe_pcm_dev_probe()
1366 for (i = 0; i < afe->memif_size; i++) { in mt2701_afe_pcm_dev_probe()
1367 afe->memif[i].data = &memif_data_array[i]; in mt2701_afe_pcm_dev_probe()
1368 afe->memif[i].irq_usage = -1; in mt2701_afe_pcm_dev_probe()
1372 afe->irqs_size = MT2701_IRQ_ASYS_END; in mt2701_afe_pcm_dev_probe()
1373 afe->irqs = devm_kcalloc(dev, afe->irqs_size, sizeof(*afe->irqs), in mt2701_afe_pcm_dev_probe()
1375 if (!afe->irqs) in mt2701_afe_pcm_dev_probe()
1376 return -ENOMEM; in mt2701_afe_pcm_dev_probe()
1378 for (i = 0; i < afe->irqs_size; i++) in mt2701_afe_pcm_dev_probe()
1379 afe->irqs[i].irq_data = &irq_data[i]; in mt2701_afe_pcm_dev_probe()
1382 for (i = 0; i < afe_priv->soc->i2s_num; i++) { in mt2701_afe_pcm_dev_probe()
1383 afe_priv->i2s_path[i].i2s_data[SNDRV_PCM_STREAM_PLAYBACK] = in mt2701_afe_pcm_dev_probe()
1385 afe_priv->i2s_path[i].i2s_data[SNDRV_PCM_STREAM_CAPTURE] = in mt2701_afe_pcm_dev_probe()
1389 afe->mtk_afe_hardware = &mt2701_afe_hardware; in mt2701_afe_pcm_dev_probe()
1390 afe->memif_fs = mt2701_memif_fs; in mt2701_afe_pcm_dev_probe()
1391 afe->irq_fs = mt2701_irq_fs; in mt2701_afe_pcm_dev_probe()
1392 afe->reg_back_up_list = mt2701_afe_backup_list; in mt2701_afe_pcm_dev_probe()
1393 afe->reg_back_up_list_num = ARRAY_SIZE(mt2701_afe_backup_list); in mt2701_afe_pcm_dev_probe()
1394 afe->runtime_resume = mt2701_afe_runtime_resume; in mt2701_afe_pcm_dev_probe()
1395 afe->runtime_suspend = mt2701_afe_runtime_suspend; in mt2701_afe_pcm_dev_probe()
1414 ret = devm_snd_soc_register_component(&pdev->dev, &mtk_afe_pcm_platform, in mt2701_afe_pcm_dev_probe()
1421 ret = devm_snd_soc_register_component(&pdev->dev, in mt2701_afe_pcm_dev_probe()
1442 pm_runtime_put_sync(&pdev->dev); in mt2701_afe_pcm_dev_remove()
1443 pm_runtime_disable(&pdev->dev); in mt2701_afe_pcm_dev_remove()
1444 if (!pm_runtime_status_suspended(&pdev->dev)) in mt2701_afe_pcm_dev_remove()
1445 mt2701_afe_runtime_suspend(&pdev->dev); in mt2701_afe_pcm_dev_remove()
1458 { .compatible = "mediatek,mt2701-audio", .data = &mt2701_soc_v1 },
1459 { .compatible = "mediatek,mt7622-audio", .data = &mt2701_soc_v2 },
1471 .name = "mt2701-audio",