Lines Matching +full:mt8188 +full:- +full:afe
1 // SPDX-License-Identifier: GPL-2.0
3 * mt8188-mt6359.c -- MT8188-MT6359 ALSA SoC machine driver
17 #include "mt8188-afe-common.h"
21 #include "../common/mtk-afe-platform-driver.h"
22 #include "../common/mtk-soundcard-driver.h"
23 #include "../common/mtk-dsp-sof-common.h"
24 #include "../common/mtk-soc-card.h"
42 #define MAX98390_CODEC_DAI "max98390-aif1"
43 #define MAX98390_DEV0_NAME "max98390.0-0038" /* rear right */
44 #define MAX98390_DEV1_NAME "max98390.0-0039" /* rear left */
45 #define MAX98390_DEV2_NAME "max98390.0-003a" /* front right */
46 #define MAX98390_DEV3_NAME "max98390.0-003b" /* front left */
51 #define NAU8825_CODEC_DAI "nau8825-hifi"
63 #define RT5682S_CODEC_DAI "rt5682s-aif1"
149 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
150 "mt6359-snd-codec-aif1")),
190 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
191 "mt6359-snd-codec-aif1"),
192 COMP_CODEC("dmic-codec",
193 "dmic-hifi")),
346 snd_soc_rtd_to_codec(rtd, 0)->component; in mt8188_mt6359_mtkaif_calibration()
348 struct mtk_base_afe *afe; in mt8188_mt6359_mtkaif_calibration() local
365 return -EINVAL; in mt8188_mt6359_mtkaif_calibration()
367 afe = snd_soc_component_get_drvdata(cmpnt_afe); in mt8188_mt6359_mtkaif_calibration()
368 afe_priv = afe->platform_priv; in mt8188_mt6359_mtkaif_calibration()
369 param = &afe_priv->mtkaif_params; in mt8188_mt6359_mtkaif_calibration()
371 dev_dbg(afe->dev, "%s(), start\n", __func__); in mt8188_mt6359_mtkaif_calibration()
373 param->mtkaif_calibration_ok = false; in mt8188_mt6359_mtkaif_calibration()
375 param->mtkaif_chosen_phase[i] = -1; in mt8188_mt6359_mtkaif_calibration()
376 param->mtkaif_phase_cycle[i] = 0; in mt8188_mt6359_mtkaif_calibration()
377 mtkaif_chosen_phase[i] = -1; in mt8188_mt6359_mtkaif_calibration()
381 if (IS_ERR(afe_priv->topckgen)) { in mt8188_mt6359_mtkaif_calibration()
382 dev_info(afe->dev, "%s() Cannot find topckgen controller\n", in mt8188_mt6359_mtkaif_calibration()
387 for_each_card_widgets(rtd->card, w) { in mt8188_mt6359_mtkaif_calibration()
388 if (!strcmp(w->name, "MTKAIF_PIN")) { in mt8188_mt6359_mtkaif_calibration()
397 dev_dbg(afe->dev, "%s(), no pinmux widget, please check if default on\n", __func__); in mt8188_mt6359_mtkaif_calibration()
399 pm_runtime_get_sync(afe->dev); in mt8188_mt6359_mtkaif_calibration()
403 regmap_write(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, RG_TEST_TYPE); in mt8188_mt6359_mtkaif_calibration()
413 regmap_set_bits(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, RG_TEST_ON); in mt8188_mt6359_mtkaif_calibration()
418 cycle_1 = -1; in mt8188_mt6359_mtkaif_calibration()
419 cycle_2 = -1; in mt8188_mt6359_mtkaif_calibration()
423 regmap_read(afe_priv->topckgen, in mt8188_mt6359_mtkaif_calibration()
436 dev_err(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, monitor 0x%x\n", in mt8188_mt6359_mtkaif_calibration()
450 mtkaif_chosen_phase[MT8188_MTKAIF_MISO_0] = phase - 1; in mt8188_mt6359_mtkaif_calibration()
456 mtkaif_chosen_phase[MT8188_MTKAIF_MISO_1] = phase - 1; in mt8188_mt6359_mtkaif_calibration()
460 regmap_clear_bits(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, RG_TEST_ON); in mt8188_mt6359_mtkaif_calibration()
487 pm_runtime_put(afe->dev); in mt8188_mt6359_mtkaif_calibration()
489 param->mtkaif_calibration_ok = mtkaif_calibration_ok; in mt8188_mt6359_mtkaif_calibration()
490 param->mtkaif_chosen_phase[MT8188_MTKAIF_MISO_0] = chosen_phase_1; in mt8188_mt6359_mtkaif_calibration()
491 param->mtkaif_chosen_phase[MT8188_MTKAIF_MISO_1] = chosen_phase_2; in mt8188_mt6359_mtkaif_calibration()
494 param->mtkaif_phase_cycle[i] = mtkaif_phase_cycle[i]; in mt8188_mt6359_mtkaif_calibration()
499 dev_dbg(afe->dev, "%s(), end, calibration ok %d\n", in mt8188_mt6359_mtkaif_calibration()
500 __func__, param->mtkaif_calibration_ok); in mt8188_mt6359_mtkaif_calibration()
508 snd_soc_rtd_to_codec(rtd, 0)->component; in mt8188_mt6359_init()
587 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); in mt8188_hdmi_codec_init()
588 struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_HDMI]; in mt8188_hdmi_codec_init()
589 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; in mt8188_hdmi_codec_init()
592 ret = snd_soc_card_jack_new_pins(rtd->card, "HDMI Jack", in mt8188_hdmi_codec_init()
597 dev_err(rtd->dev, "%s, new jack failed: %d\n", __func__, ret); in mt8188_hdmi_codec_init()
603 dev_err(rtd->dev, "%s, set jack failed on %s (ret=%d)\n", in mt8188_hdmi_codec_init()
604 __func__, component->name, ret); in mt8188_hdmi_codec_init()
613 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); in mt8188_dptx_codec_init()
614 struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_DP]; in mt8188_dptx_codec_init()
615 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; in mt8188_dptx_codec_init()
618 ret = snd_soc_card_jack_new_pins(rtd->card, "DP Jack", SND_JACK_LINEOUT, in mt8188_dptx_codec_init()
622 dev_err(rtd->dev, "%s, new jack failed: %d\n", __func__, ret); in mt8188_dptx_codec_init()
628 dev_err(rtd->dev, "%s, set jack failed on %s (ret=%d)\n", in mt8188_dptx_codec_init()
629 __func__, component->name, ret); in mt8188_dptx_codec_init()
638 struct snd_soc_card *card = rtd->card; in mt8188_dumb_amp_init()
641 ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_dumb_spk_widgets, in mt8188_dumb_amp_init()
644 dev_err(rtd->dev, "unable to add Dumb Speaker dapm, ret %d\n", ret); in mt8188_dumb_amp_init()
651 dev_err(rtd->dev, "unable to add Dumb card controls, ret %d\n", ret); in mt8188_dumb_amp_init()
670 if (!strcmp(codec_dai->component->name, MAX98390_DEV0_NAME)) in mt8188_max98390_hw_params()
673 if (!strcmp(codec_dai->component->name, MAX98390_DEV1_NAME)) in mt8188_max98390_hw_params()
676 if (!strcmp(codec_dai->component->name, MAX98390_DEV2_NAME)) in mt8188_max98390_hw_params()
679 if (!strcmp(codec_dai->component->name, MAX98390_DEV3_NAME)) in mt8188_max98390_hw_params()
691 struct snd_soc_card *card = rtd->card; in mt8188_max98390_codec_init()
695 ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_dual_spk_widgets, in mt8188_max98390_codec_init()
698 dev_err(rtd->dev, "unable to add Left/Right Speaker widget, ret %d\n", ret); in mt8188_max98390_codec_init()
705 dev_err(rtd->dev, "unable to add Left/Right card controls, ret %d\n", ret); in mt8188_max98390_codec_init()
709 if (rtd->dai_link->num_codecs <= 2) in mt8188_max98390_codec_init()
713 ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_rear_spk_widgets, in mt8188_max98390_codec_init()
716 dev_err(rtd->dev, "unable to add Rear Speaker widget, ret %d\n", ret); in mt8188_max98390_codec_init()
724 dev_err(rtd->dev, "unable to add Rear card controls, ret %d\n", ret); in mt8188_max98390_codec_init()
733 struct snd_soc_card *card = rtd->card; in mt8188_headset_codec_init()
734 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); in mt8188_headset_codec_init()
735 struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_HEADSET]; in mt8188_headset_codec_init()
736 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; in mt8188_headset_codec_init()
737 struct mtk_platform_card_data *card_data = soc_card_data->card_data; in mt8188_headset_codec_init()
740 ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_nau8825_widgets, in mt8188_headset_codec_init()
743 dev_err(rtd->dev, "unable to add nau8825 card widget, ret %d\n", ret); in mt8188_headset_codec_init()
750 dev_err(rtd->dev, "unable to add nau8825 card controls, ret %d\n", ret); in mt8188_headset_codec_init()
754 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack", in mt8188_headset_codec_init()
762 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); in mt8188_headset_codec_init()
766 if (card_data->flags & ES8326_HS_PRESENT) { in mt8188_headset_codec_init()
767 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); in mt8188_headset_codec_init()
768 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP); in mt8188_headset_codec_init()
769 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); in mt8188_headset_codec_init()
770 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); in mt8188_headset_codec_init()
772 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); in mt8188_headset_codec_init()
773 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); in mt8188_headset_codec_init()
774 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); in mt8188_headset_codec_init()
775 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); in mt8188_headset_codec_init()
781 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret); in mt8188_headset_codec_init()
790 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; in mt8188_headset_codec_exit()
811 dev_err(codec_dai->dev, "can't set BCLK clock %d\n", ret); in mt8188_nau8825_hw_params()
819 dev_err(codec_dai->dev, "can't set BCLK: %d\n", ret); in mt8188_nau8825_hw_params()
834 struct snd_soc_card *card = rtd->card; in mt8188_rt5682s_i2s_hw_params()
843 dev_err(card->dev, "invalid bit width: %d\n", bitwidth); in mt8188_rt5682s_i2s_hw_params()
849 dev_err(card->dev, "failed to set tdm slot\n"); in mt8188_rt5682s_i2s_hw_params()
856 dev_err(card->dev, "failed to set pll\n"); in mt8188_rt5682s_i2s_hw_params()
863 dev_err(card->dev, "failed to set sysclk\n"); in mt8188_rt5682s_i2s_hw_params()
882 /* find afe component */ in mt8188_sof_be_hw_params()
883 for_each_card_rtds(rtd->card, runtime) { in mt8188_sof_be_hw_params()
889 if (cmpnt_afe && !pm_runtime_active(cmpnt_afe->dev)) { in mt8188_sof_be_hw_params()
890 dev_err(rtd->dev, "afe pm runtime is not active!!\n"); in mt8188_sof_be_hw_params()
891 return -EINVAL; in mt8188_sof_be_hw_params()
913 dev_err(codec_dai->dev, "can't set MCLK %d\n", ret); in mt8188_es8326_hw_params()
1230 struct mtk_platform_card_data *card_data = soc_card_data->card_data; in mt8188_fixup_controls()
1233 if (card_data->flags & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT | ES8326_HS_PRESENT)) { in mt8188_fixup_controls()
1237 if (strcmp(w->name, "Headphone")) in mt8188_fixup_controls()
1243 kctl = snd_ctl_find_id_mixer(card->snd_card, "Headphone Switch"); in mt8188_fixup_controls()
1245 snd_ctl_remove(card->snd_card, kctl); in mt8188_fixup_controls()
1247 dev_warn(card->dev, "Cannot find ctl : Headphone Switch\n"); in mt8188_fixup_controls()
1266 struct mtk_platform_card_data *card_data = soc_card_data->card_data; in mt8188_mt6359_soc_card_probe()
1267 struct snd_soc_card *card = soc_card_data->card_data->card; in mt8188_mt6359_soc_card_probe()
1278 return -EINVAL; in mt8188_mt6359_soc_card_probe()
1281 if (strcmp(dai_link->name, "DPTX_BE") == 0) { in mt8188_mt6359_soc_card_probe()
1282 if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) in mt8188_mt6359_soc_card_probe()
1283 dai_link->init = mt8188_dptx_codec_init; in mt8188_mt6359_soc_card_probe()
1284 } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) { in mt8188_mt6359_soc_card_probe()
1285 if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) in mt8188_mt6359_soc_card_probe()
1286 dai_link->init = mt8188_hdmi_codec_init; in mt8188_mt6359_soc_card_probe()
1287 } else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 || in mt8188_mt6359_soc_card_probe()
1288 strcmp(dai_link->name, "UL_SRC_BE") == 0) { in mt8188_mt6359_soc_card_probe()
1290 dai_link->init = mt8188_mt6359_init; in mt8188_mt6359_soc_card_probe()
1293 } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 || in mt8188_mt6359_soc_card_probe()
1294 strcmp(dai_link->name, "ETDM2_OUT_BE") == 0 || in mt8188_mt6359_soc_card_probe()
1295 strcmp(dai_link->name, "ETDM1_IN_BE") == 0 || in mt8188_mt6359_soc_card_probe()
1296 strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { in mt8188_mt6359_soc_card_probe()
1297 if (!strcmp(dai_link->codecs->dai_name, MAX98390_CODEC_DAI)) { in mt8188_mt6359_soc_card_probe()
1303 if (!(card_data->flags & MAX98390_TWO_AMP)) { in mt8188_mt6359_soc_card_probe()
1304 dai_link->ops = &mt8188_max98390_ops; in mt8188_mt6359_soc_card_probe()
1307 dai_link->init = mt8188_max98390_codec_init; in mt8188_mt6359_soc_card_probe()
1310 } else if (!strcmp(dai_link->codecs->dai_name, NAU8825_CODEC_DAI)) { in mt8188_mt6359_soc_card_probe()
1311 dai_link->ops = &mt8188_nau8825_ops; in mt8188_mt6359_soc_card_probe()
1313 dai_link->init = mt8188_headset_codec_init; in mt8188_mt6359_soc_card_probe()
1314 dai_link->exit = mt8188_headset_codec_exit; in mt8188_mt6359_soc_card_probe()
1317 } else if (!strcmp(dai_link->codecs->dai_name, RT5682S_CODEC_DAI)) { in mt8188_mt6359_soc_card_probe()
1318 dai_link->ops = &mt8188_rt5682s_i2s_ops; in mt8188_mt6359_soc_card_probe()
1320 dai_link->init = mt8188_headset_codec_init; in mt8188_mt6359_soc_card_probe()
1321 dai_link->exit = mt8188_headset_codec_exit; in mt8188_mt6359_soc_card_probe()
1324 } else if (!strcmp(dai_link->codecs->dai_name, ES8326_CODEC_DAI)) { in mt8188_mt6359_soc_card_probe()
1325 dai_link->ops = &mt8188_es8326_ops; in mt8188_mt6359_soc_card_probe()
1327 dai_link->init = mt8188_headset_codec_init; in mt8188_mt6359_soc_card_probe()
1328 dai_link->exit = mt8188_headset_codec_exit; in mt8188_mt6359_soc_card_probe()
1332 if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) { in mt8188_mt6359_soc_card_probe()
1334 dai_link->init = mt8188_dumb_amp_init; in mt8188_mt6359_soc_card_probe()
1394 { .compatible = "mediatek,mt8188-mt6359-evb", .data = &mt8188_evb_card, },
1395 { .compatible = "mediatek,mt8188-nau8825", .data = &mt8188_nau8825_card, },
1396 { .compatible = "mediatek,mt8188-rt5682s", .data = &mt8188_rt5682s_card, },
1397 { .compatible = "mediatek,mt8188-es8326", .data = &mt8188_es8326_card, },
1414 MODULE_DESCRIPTION("MT8188-MT6359 ALSA SoC machine driver");
1417 MODULE_ALIAS("mt8188 mt6359 soc card");