Lines Matching +full:codec +full:- +full:aif1 +full:- +full:bclk

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")),
344 snd_soc_rtd_to_codec(rtd, 0)->component;
363 return -EINVAL;
366 afe_priv = afe->platform_priv;
367 param = &afe_priv->mtkaif_params;
369 dev_dbg(afe->dev, "%s(), start\n", __func__);
371 param->mtkaif_calibration_ok = false;
373 param->mtkaif_chosen_phase[i] = -1;
374 param->mtkaif_phase_cycle[i] = 0;
375 mtkaif_chosen_phase[i] = -1;
379 if (IS_ERR(afe_priv->topckgen)) {
380 dev_info(afe->dev, "%s() Cannot find topckgen controller\n",
385 for_each_card_widgets(rtd->card, w) {
386 if (!strcmp(w->name, "MTKAIF_PIN")) {
395 dev_dbg(afe->dev, "%s(), no pinmux widget, please check if default on\n", __func__);
397 pm_runtime_get_sync(afe->dev);
401 regmap_write(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, RG_TEST_TYPE);
411 regmap_set_bits(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, RG_TEST_ON);
416 cycle_1 = -1;
417 cycle_2 = -1;
421 regmap_read(afe_priv->topckgen,
434 dev_err(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, monitor 0x%x\n",
448 mtkaif_chosen_phase[MT8188_MTKAIF_MISO_0] = phase - 1;
454 mtkaif_chosen_phase[MT8188_MTKAIF_MISO_1] = phase - 1;
458 regmap_clear_bits(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, RG_TEST_ON);
485 pm_runtime_put(afe->dev);
487 param->mtkaif_calibration_ok = mtkaif_calibration_ok;
488 param->mtkaif_chosen_phase[MT8188_MTKAIF_MISO_0] = chosen_phase_1;
489 param->mtkaif_chosen_phase[MT8188_MTKAIF_MISO_1] = chosen_phase_2;
492 param->mtkaif_phase_cycle[i] = mtkaif_phase_cycle[i];
497 dev_dbg(afe->dev, "%s(), end, calibration ok %d\n",
498 __func__, param->mtkaif_calibration_ok);
506 snd_soc_rtd_to_codec(rtd, 0)->component;
585 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card);
586 struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_HDMI];
587 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
590 ret = snd_soc_card_jack_new_pins(rtd->card, "HDMI Jack",
595 dev_err(rtd->dev, "%s, new jack failed: %d\n", __func__, ret);
601 dev_err(rtd->dev, "%s, set jack failed on %s (ret=%d)\n",
602 __func__, component->name, ret);
611 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card);
612 struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_DP];
613 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
616 ret = snd_soc_card_jack_new_pins(rtd->card, "DP Jack", SND_JACK_LINEOUT,
620 dev_err(rtd->dev, "%s, new jack failed: %d\n", __func__, ret);
626 dev_err(rtd->dev, "%s, set jack failed on %s (ret=%d)\n",
627 __func__, component->name, ret);
636 struct snd_soc_card *card = rtd->card;
639 ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_dumb_spk_widgets,
642 dev_err(rtd->dev, "unable to add Dumb Speaker dapm, ret %d\n", ret);
649 dev_err(rtd->dev, "unable to add Dumb card controls, ret %d\n", ret);
668 if (!strcmp(codec_dai->component->name, MAX98390_DEV0_NAME))
671 if (!strcmp(codec_dai->component->name, MAX98390_DEV1_NAME))
674 if (!strcmp(codec_dai->component->name, MAX98390_DEV2_NAME))
677 if (!strcmp(codec_dai->component->name, MAX98390_DEV3_NAME))
689 struct snd_soc_card *card = rtd->card;
693 ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_dual_spk_widgets,
696 dev_err(rtd->dev, "unable to add Left/Right Speaker widget, ret %d\n", ret);
703 dev_err(rtd->dev, "unable to add Left/Right card controls, ret %d\n", ret);
707 if (rtd->dai_link->num_codecs <= 2)
711 ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_rear_spk_widgets,
714 dev_err(rtd->dev, "unable to add Rear Speaker widget, ret %d\n", ret);
722 dev_err(rtd->dev, "unable to add Rear card controls, ret %d\n", ret);
731 struct snd_soc_card *card = rtd->card;
732 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card);
733 struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_HEADSET];
734 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
735 struct mtk_platform_card_data *card_data = soc_card_data->card_data;
738 ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_nau8825_widgets,
741 dev_err(rtd->dev, "unable to add nau8825 card widget, ret %d\n", ret);
748 dev_err(rtd->dev, "unable to add nau8825 card controls, ret %d\n", ret);
752 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
760 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
764 if (card_data->flags & ES8326_HS_PRESENT) {
765 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
766 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
767 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
768 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
770 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
771 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
772 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
773 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
779 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
788 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
805 /* Configure clock for codec */
809 dev_err(codec_dai->dev, "can't set BCLK clock %d\n", ret);
813 /* Configure pll for codec */
817 dev_err(codec_dai->dev, "can't set BCLK: %d\n", ret);
832 struct snd_soc_card *card = rtd->card;
841 dev_err(card->dev, "invalid bit width: %d\n", bitwidth);
847 dev_err(card->dev, "failed to set tdm slot\n");
854 dev_err(card->dev, "failed to set pll\n");
861 dev_err(card->dev, "failed to set sysclk\n");
881 for_each_card_rtds(rtd->card, runtime) {
887 if (cmpnt_afe && !pm_runtime_active(cmpnt_afe->dev)) {
888 dev_err(rtd->dev, "afe pm runtime is not active!!\n");
889 return -EINVAL;
908 /* Configure MCLK for codec */
911 dev_err(codec_dai->dev, "can't set MCLK %d\n", ret);
1226 struct mtk_platform_card_data *card_data = soc_card_data->card_data;
1229 if (card_data->flags & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT | ES8326_HS_PRESENT)) {
1233 if (strcmp(w->name, "Headphone"))
1239 kctl = snd_ctl_find_id_mixer(card->snd_card, "Headphone Switch");
1241 snd_ctl_remove(card->snd_card, kctl);
1243 dev_warn(card->dev, "Cannot find ctl : Headphone Switch\n");
1262 struct mtk_platform_card_data *card_data = soc_card_data->card_data;
1263 struct snd_soc_card *card = soc_card_data->card_data->card;
1274 return -EINVAL;
1277 if (strcmp(dai_link->name, "DPTX_BE") == 0) {
1278 if (dai_link->num_codecs &&
1279 strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai"))
1280 dai_link->init = mt8188_dptx_codec_init;
1281 } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) {
1282 if (dai_link->num_codecs &&
1283 strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai"))
1284 dai_link->init = mt8188_hdmi_codec_init;
1285 } else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 ||
1286 strcmp(dai_link->name, "UL_SRC_BE") == 0) {
1288 dai_link->init = mt8188_mt6359_init;
1291 } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 ||
1292 strcmp(dai_link->name, "ETDM2_OUT_BE") == 0 ||
1293 strcmp(dai_link->name, "ETDM1_IN_BE") == 0 ||
1294 strcmp(dai_link->name, "ETDM2_IN_BE") == 0) {
1295 if (!dai_link->num_codecs)
1298 if (!strcmp(dai_link->codecs->dai_name, MAX98390_CODEC_DAI)) {
1302 * SOC and codec don't require TDM settings.
1304 if (!(card_data->flags & MAX98390_TWO_AMP)) {
1305 dai_link->ops = &mt8188_max98390_ops;
1308 dai_link->init = mt8188_max98390_codec_init;
1311 } else if (!strcmp(dai_link->codecs->dai_name, NAU8825_CODEC_DAI)) {
1312 dai_link->ops = &mt8188_nau8825_ops;
1314 dai_link->init = mt8188_headset_codec_init;
1315 dai_link->exit = mt8188_headset_codec_exit;
1318 } else if (!strcmp(dai_link->codecs->dai_name, RT5682S_CODEC_DAI)) {
1319 dai_link->ops = &mt8188_rt5682s_i2s_ops;
1321 dai_link->init = mt8188_headset_codec_init;
1322 dai_link->exit = mt8188_headset_codec_exit;
1325 } else if (!strcmp(dai_link->codecs->dai_name, ES8326_CODEC_DAI)) {
1326 dai_link->ops = &mt8188_es8326_ops;
1328 dai_link->init = mt8188_headset_codec_init;
1329 dai_link->exit = mt8188_headset_codec_exit;
1333 if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) {
1335 dai_link->init = mt8188_dumb_amp_init;
1395 { .compatible = "mediatek,mt8188-mt6359-evb", .data = &mt8188_evb_card, },
1396 { .compatible = "mediatek,mt8188-nau8825", .data = &mt8188_nau8825_card, },
1397 { .compatible = "mediatek,mt8188-rt5682s", .data = &mt8188_rt5682s_card, },
1398 { .compatible = "mediatek,mt8188-es8326", .data = &mt8188_es8326_card, },
1415 MODULE_DESCRIPTION("MT8188-MT6359 ALSA SoC machine driver");