Lines Matching +full:aif2 +full:- +full:pins

1 // SPDX-License-Identifier: GPL-2.0
3 * mt8195-mt6359.c --
4 * MT8195-MT6359 ALSA SoC machine driver code
22 #include "../common/mtk-afe-platform-driver.h"
23 #include "../common/mtk-dsp-sof-common.h"
24 #include "../common/mtk-soc-card.h"
25 #include "mt8195-afe-clk.h"
26 #include "mt8195-afe-common.h"
32 #define RT1011_CODEC_DAI "rt1011-aif"
33 #define RT1011_DEV0_NAME "rt1011.2-0038"
34 #define RT1011_DEV1_NAME "rt1011.2-0039"
39 #define MAX98390_CODEC_DAI "max98390-aif1"
40 #define MAX98390_DEV0_NAME "max98390.2-0038" /* right */
41 #define MAX98390_DEV1_NAME "max98390.2-0039" /* left */
43 #define RT5682_CODEC_DAI "rt5682-aif1"
44 #define RT5682_DEV0_NAME "rt5682.2-001a"
46 #define RT5682S_CODEC_DAI "rt5682s-aif1"
47 #define RT5682S_DEV0_NAME "rt5682s.2-001a"
66 /* Headset jack detection DAPM pins */
149 asoc_rtd_to_codec(rtd, 0)->component; in mt8195_mt6359_mtkaif_calibration()
151 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_mt6359_mtkaif_calibration()
152 struct mtkaif_param *param = &afe_priv->mtkaif_params; in mt8195_mt6359_mtkaif_calibration()
166 dev_dbg(afe->dev, "%s(), start\n", __func__); in mt8195_mt6359_mtkaif_calibration()
168 param->mtkaif_calibration_ok = false; in mt8195_mt6359_mtkaif_calibration()
170 param->mtkaif_chosen_phase[i] = -1; in mt8195_mt6359_mtkaif_calibration()
171 param->mtkaif_phase_cycle[i] = 0; in mt8195_mt6359_mtkaif_calibration()
172 mtkaif_chosen_phase[i] = -1; in mt8195_mt6359_mtkaif_calibration()
176 if (IS_ERR(afe_priv->topckgen)) { in mt8195_mt6359_mtkaif_calibration()
177 dev_info(afe->dev, "%s() Cannot find topckgen controller\n", in mt8195_mt6359_mtkaif_calibration()
182 pm_runtime_get_sync(afe->dev); in mt8195_mt6359_mtkaif_calibration()
186 regmap_update_bits(afe_priv->topckgen, in mt8195_mt6359_mtkaif_calibration()
197 regmap_update_bits(afe_priv->topckgen, in mt8195_mt6359_mtkaif_calibration()
203 cycle_1 = -1; in mt8195_mt6359_mtkaif_calibration()
204 cycle_2 = -1; in mt8195_mt6359_mtkaif_calibration()
205 cycle_3 = -1; in mt8195_mt6359_mtkaif_calibration()
208 regmap_read(afe_priv->topckgen, in mt8195_mt6359_mtkaif_calibration()
224 dev_info(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n", in mt8195_mt6359_mtkaif_calibration()
240 mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] = phase - 1; in mt8195_mt6359_mtkaif_calibration()
246 mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] = phase - 1; in mt8195_mt6359_mtkaif_calibration()
252 mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] = phase - 1; in mt8195_mt6359_mtkaif_calibration()
256 regmap_update_bits(afe_priv->topckgen, in mt8195_mt6359_mtkaif_calibration()
292 pm_runtime_put(afe->dev); in mt8195_mt6359_mtkaif_calibration()
294 param->mtkaif_calibration_ok = mtkaif_calibration_ok; in mt8195_mt6359_mtkaif_calibration()
295 param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] = chosen_phase_1; in mt8195_mt6359_mtkaif_calibration()
296 param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] = chosen_phase_2; in mt8195_mt6359_mtkaif_calibration()
297 param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] = chosen_phase_3; in mt8195_mt6359_mtkaif_calibration()
299 param->mtkaif_phase_cycle[i] = mtkaif_phase_cycle[i]; in mt8195_mt6359_mtkaif_calibration()
301 dev_info(afe->dev, "%s(), end, calibration ok %d\n", in mt8195_mt6359_mtkaif_calibration()
302 __func__, param->mtkaif_calibration_ok); in mt8195_mt6359_mtkaif_calibration()
310 asoc_rtd_to_codec(rtd, 0)->component; in mt8195_mt6359_init()
342 struct snd_pcm_runtime *runtime = substream->runtime; in mt8195_hdmitx_dptx_startup()
349 dev_err(rtd->dev, "hw_constraint_list rate failed\n"); in mt8195_hdmitx_dptx_startup()
357 dev_err(rtd->dev, "hw_constraint_list channel failed\n"); in mt8195_hdmitx_dptx_startup()
371 struct snd_soc_pcm_runtime *rtd = substream->private_data; in mt8195_dptx_hw_params()
384 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); in mt8195_dptx_codec_init()
385 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; in mt8195_dptx_codec_init()
387 asoc_rtd_to_codec(rtd, 0)->component; in mt8195_dptx_codec_init()
390 ret = snd_soc_card_jack_new(rtd->card, "DP Jack", SND_JACK_LINEOUT, in mt8195_dptx_codec_init()
391 &priv->dp_jack); in mt8195_dptx_codec_init()
395 return snd_soc_component_set_jack(cmpnt_codec, &priv->dp_jack, NULL); in mt8195_dptx_codec_init()
400 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); in mt8195_hdmi_codec_init()
401 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; in mt8195_hdmi_codec_init()
403 asoc_rtd_to_codec(rtd, 0)->component; in mt8195_hdmi_codec_init()
406 ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, in mt8195_hdmi_codec_init()
407 &priv->hdmi_jack); in mt8195_hdmi_codec_init()
411 return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); in mt8195_hdmi_codec_init()
446 struct snd_pcm_runtime *runtime = substream->runtime; in mt8195_playback_startup()
453 dev_err(rtd->dev, "hw_constraint_list rate failed\n"); in mt8195_playback_startup()
461 dev_err(rtd->dev, "hw_constraint_list channel failed\n"); in mt8195_playback_startup()
492 struct snd_pcm_runtime *runtime = substream->runtime; in mt8195_capture_startup()
499 dev_err(rtd->dev, "hw_constraint_list rate failed\n"); in mt8195_capture_startup()
507 dev_err(rtd->dev, "hw_constraint_list channel failed\n"); in mt8195_capture_startup()
521 struct snd_soc_pcm_runtime *rtd = substream->private_data; in mt8195_rt5682_etdm_hw_params()
522 struct snd_soc_card *card = rtd->card; in mt8195_rt5682_etdm_hw_params()
531 dev_err(card->dev, "invalid bit width: %d\n", bitwidth); in mt8195_rt5682_etdm_hw_params()
537 dev_err(card->dev, "failed to set tdm slot\n"); in mt8195_rt5682_etdm_hw_params()
544 dev_err(card->dev, "failed to set pll\n"); in mt8195_rt5682_etdm_hw_params()
551 dev_err(card->dev, "failed to set sysclk\n"); in mt8195_rt5682_etdm_hw_params()
566 asoc_rtd_to_codec(rtd, 0)->component; in mt8195_rt5682_init()
567 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); in mt8195_rt5682_init()
568 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; in mt8195_rt5682_init()
569 struct snd_soc_jack *jack = &priv->headset_jack; in mt8195_rt5682_init()
573 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_rt5682_init()
576 priv->i2so1_mclk = afe_priv->clk[MT8195_CLK_TOP_APLL12_DIV2]; in mt8195_rt5682_init()
578 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack", in mt8195_rt5682_init()
585 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); in mt8195_rt5682_init()
589 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); in mt8195_rt5682_init()
590 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); in mt8195_rt5682_init()
591 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); in mt8195_rt5682_init()
592 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); in mt8195_rt5682_init()
596 dev_err(rtd->dev, "Headset Jack set failed: %d\n", ret); in mt8195_rt5682_init()
608 struct snd_soc_card *card = rtd->card; in mt8195_rt1011_etdm_hw_params()
617 dev_err(card->dev, "codec_dai clock not set\n"); in mt8195_rt1011_etdm_hw_params()
625 dev_err(card->dev, "codec_dai clock not set\n"); in mt8195_rt1011_etdm_hw_params()
638 struct snd_soc_card *card = rtd->card; in mt8195_rt1011_init()
641 ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets, in mt8195_rt1011_init()
644 dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); in mt8195_rt1011_init()
652 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); in mt8195_rt1011_init()
656 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1011_routes, in mt8195_rt1011_init()
659 dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); in mt8195_rt1011_init()
666 struct snd_soc_card *card = rtd->card; in mt8195_rt1019_init()
669 ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_speaker_widgets, in mt8195_rt1019_init()
672 dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); in mt8195_rt1019_init()
680 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); in mt8195_rt1019_init()
684 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1019_routes, in mt8195_rt1019_init()
687 dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); in mt8195_rt1019_init()
694 struct snd_soc_card *card = rtd->card; in mt8195_max98390_init()
697 ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets, in mt8195_max98390_init()
700 dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); in mt8195_max98390_init()
708 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); in mt8195_max98390_init()
712 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_max98390_routes, in mt8195_max98390_init()
715 dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); in mt8195_max98390_init()
735 struct snd_soc_component *component = dapm->component; in mt8195_set_bias_level_post()
737 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; in mt8195_set_bias_level_post()
746 (strcmp(component->name, RT5682_DEV0_NAME) && in mt8195_set_bias_level_post()
747 strcmp(component->name, RT5682S_DEV0_NAME))) in mt8195_set_bias_level_post()
752 if (!__clk_is_enabled(priv->i2so1_mclk)) in mt8195_set_bias_level_post()
755 clk_disable_unprepare(priv->i2so1_mclk); in mt8195_set_bias_level_post()
756 dev_dbg(card->dev, "Disable i2so1 mclk\n"); in mt8195_set_bias_level_post()
759 ret = clk_prepare_enable(priv->i2so1_mclk); in mt8195_set_bias_level_post()
761 dev_err(card->dev, "Can't enable i2so1 mclk: %d\n", ret); in mt8195_set_bias_level_post()
764 dev_dbg(card->dev, "Enable i2so1 mclk\n"); in mt8195_set_bias_level_post()
895 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
896 "mt6359-snd-codec-aif1")),
936 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
937 "mt6359-snd-codec-aif1"),
938 COMP_CODEC("dmic-codec",
939 "dmic-hifi")),
944 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
945 "mt6359-snd-codec-aif2")),
1340 if (!strcmp(rtd->dai_link->name, "ETDM2_IN_BE") || in mt8195_dai_link_fixup()
1341 !strcmp(rtd->dai_link->name, "ETDM1_OUT_BE")) { in mt8195_dai_link_fixup()
1361 card_data = (struct mt8195_card_data *)of_device_get_match_data(&pdev->dev); in mt8195_mt6359_dev_probe()
1362 card->dev = &pdev->dev; in mt8195_mt6359_dev_probe()
1366 dev_err(&pdev->dev, "%s new card name parsing error %d\n", in mt8195_mt6359_dev_probe()
1371 if (!card->name) in mt8195_mt6359_dev_probe()
1372 card->name = card_data->name; in mt8195_mt6359_dev_probe()
1374 if (strstr(card->name, "_5682s")) in mt8195_mt6359_dev_probe()
1376 soc_card_data = devm_kzalloc(&pdev->dev, sizeof(*card_data), GFP_KERNEL); in mt8195_mt6359_dev_probe()
1378 return -ENOMEM; in mt8195_mt6359_dev_probe()
1380 mach_priv = devm_kzalloc(&pdev->dev, sizeof(*mach_priv), GFP_KERNEL); in mt8195_mt6359_dev_probe()
1382 return -ENOMEM; in mt8195_mt6359_dev_probe()
1384 soc_card_data->mach_priv = mach_priv; in mt8195_mt6359_dev_probe()
1386 adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); in mt8195_mt6359_dev_probe()
1390 sof_priv = devm_kzalloc(&pdev->dev, sizeof(*sof_priv), GFP_KERNEL); in mt8195_mt6359_dev_probe()
1392 ret = -ENOMEM; in mt8195_mt6359_dev_probe()
1395 sof_priv->conn_streams = g_sof_conn_streams; in mt8195_mt6359_dev_probe()
1396 sof_priv->num_streams = ARRAY_SIZE(g_sof_conn_streams); in mt8195_mt6359_dev_probe()
1397 sof_priv->sof_dai_link_fixup = mt8195_dai_link_fixup; in mt8195_mt6359_dev_probe()
1398 soc_card_data->sof_priv = sof_priv; in mt8195_mt6359_dev_probe()
1399 card->probe = mtk_sof_card_probe; in mt8195_mt6359_dev_probe()
1400 card->late_probe = mtk_sof_card_late_probe; in mt8195_mt6359_dev_probe()
1401 if (!card->topology_shortname_created) { in mt8195_mt6359_dev_probe()
1402 snprintf(card->topology_shortname, 32, "sof-%s", card->name); in mt8195_mt6359_dev_probe()
1403 card->topology_shortname_created = true; in mt8195_mt6359_dev_probe()
1405 card->name = card->topology_shortname; in mt8195_mt6359_dev_probe()
1409 if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) { in mt8195_mt6359_dev_probe()
1410 ret = mtk_sof_dailink_parse_of(card, pdev->dev.of_node, in mt8195_mt6359_dev_probe()
1411 "mediatek,dai-link", in mt8195_mt6359_dev_probe()
1415 dev_dbg(&pdev->dev, "Parse dai-link fail\n"); in mt8195_mt6359_dev_probe()
1420 card->num_links = DAI_LINK_REGULAR_NUM; in mt8195_mt6359_dev_probe()
1423 platform_node = of_parse_phandle(pdev->dev.of_node, in mt8195_mt6359_dev_probe()
1426 dev_dbg(&pdev->dev, "Property 'platform' missing or invalid\n"); in mt8195_mt6359_dev_probe()
1427 ret = -EINVAL; in mt8195_mt6359_dev_probe()
1431 dp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,dptx-codec", 0); in mt8195_mt6359_dev_probe()
1432 hdmi_node = of_parse_phandle(pdev->dev.of_node, in mt8195_mt6359_dev_probe()
1433 "mediatek,hdmi-codec", 0); in mt8195_mt6359_dev_probe()
1436 if (!dai_link->platforms->name) { in mt8195_mt6359_dev_probe()
1437 if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && sof_on) in mt8195_mt6359_dev_probe()
1438 dai_link->platforms->of_node = adsp_node; in mt8195_mt6359_dev_probe()
1440 dai_link->platforms->of_node = platform_node; in mt8195_mt6359_dev_probe()
1443 if (strcmp(dai_link->name, "DPTX_BE") == 0) { in mt8195_mt6359_dev_probe()
1445 dev_dbg(&pdev->dev, "No property 'dptx-codec'\n"); in mt8195_mt6359_dev_probe()
1447 dai_link->codecs->of_node = dp_node; in mt8195_mt6359_dev_probe()
1448 dai_link->codecs->name = NULL; in mt8195_mt6359_dev_probe()
1449 dai_link->codecs->dai_name = "i2s-hifi"; in mt8195_mt6359_dev_probe()
1450 dai_link->init = mt8195_dptx_codec_init; in mt8195_mt6359_dev_probe()
1452 } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) { in mt8195_mt6359_dev_probe()
1454 dev_dbg(&pdev->dev, "No property 'hdmi-codec'\n"); in mt8195_mt6359_dev_probe()
1456 dai_link->codecs->of_node = hdmi_node; in mt8195_mt6359_dev_probe()
1457 dai_link->codecs->name = NULL; in mt8195_mt6359_dev_probe()
1458 dai_link->codecs->dai_name = "i2s-hifi"; in mt8195_mt6359_dev_probe()
1459 dai_link->init = mt8195_hdmi_codec_init; in mt8195_mt6359_dev_probe()
1461 } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 || in mt8195_mt6359_dev_probe()
1462 strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { in mt8195_mt6359_dev_probe()
1463 dai_link->codecs->name = in mt8195_mt6359_dev_probe()
1465 dai_link->codecs->dai_name = in mt8195_mt6359_dev_probe()
1467 } else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 || in mt8195_mt6359_dev_probe()
1468 strcmp(dai_link->name, "UL_SRC1_BE") == 0 || in mt8195_mt6359_dev_probe()
1469 strcmp(dai_link->name, "UL_SRC2_BE") == 0) { in mt8195_mt6359_dev_probe()
1471 dai_link->init = mt8195_mt6359_init; in mt8195_mt6359_dev_probe()
1474 } else if (strcmp(dai_link->name, "ETDM2_OUT_BE") == 0) { in mt8195_mt6359_dev_probe()
1475 switch (card_data->quirk) { in mt8195_mt6359_dev_probe()
1477 dai_link->codecs = rt1011_comps; in mt8195_mt6359_dev_probe()
1478 dai_link->num_codecs = ARRAY_SIZE(rt1011_comps); in mt8195_mt6359_dev_probe()
1479 dai_link->init = mt8195_rt1011_init; in mt8195_mt6359_dev_probe()
1480 dai_link->ops = &mt8195_rt1011_etdm_ops; in mt8195_mt6359_dev_probe()
1481 dai_link->be_hw_params_fixup = mt8195_etdm_hw_params_fixup; in mt8195_mt6359_dev_probe()
1482 card->codec_conf = rt1011_codec_conf; in mt8195_mt6359_dev_probe()
1483 card->num_configs = ARRAY_SIZE(rt1011_codec_conf); in mt8195_mt6359_dev_probe()
1486 dai_link->codecs = rt1019_comps; in mt8195_mt6359_dev_probe()
1487 dai_link->num_codecs = ARRAY_SIZE(rt1019_comps); in mt8195_mt6359_dev_probe()
1488 dai_link->init = mt8195_rt1019_init; in mt8195_mt6359_dev_probe()
1491 dai_link->codecs = max98390_comps; in mt8195_mt6359_dev_probe()
1492 dai_link->num_codecs = ARRAY_SIZE(max98390_comps); in mt8195_mt6359_dev_probe()
1493 dai_link->init = mt8195_max98390_init; in mt8195_mt6359_dev_probe()
1494 card->codec_conf = max98390_codec_conf; in mt8195_mt6359_dev_probe()
1495 card->num_configs = ARRAY_SIZE(max98390_codec_conf); in mt8195_mt6359_dev_probe()
1505 ret = devm_snd_soc_register_card(&pdev->dev, card); in mt8195_mt6359_dev_probe()
1560 MODULE_DESCRIPTION("MT8195-MT6359 ALSA SoC machine driver");