Lines Matching +full:mt8195 +full:- +full:topckgen
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"
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()
644 for_each_card_rtds(rtd->card, runtime) { in mt8195_sof_be_hw_params()
650 if (cmpnt_afe && !pm_runtime_active(cmpnt_afe->dev)) { in mt8195_sof_be_hw_params()
651 dev_err(rtd->dev, "afe pm runtime is not active!!\n"); in mt8195_sof_be_hw_params()
652 return -EINVAL; in mt8195_sof_be_hw_params()
664 struct snd_soc_card *card = rtd->card; in mt8195_rt1011_init()
667 ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets, in mt8195_rt1011_init()
670 dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); in mt8195_rt1011_init()
678 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); in mt8195_rt1011_init()
682 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1011_routes, in mt8195_rt1011_init()
685 dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); in mt8195_rt1011_init()
692 struct snd_soc_card *card = rtd->card; in mt8195_rt1019_init()
695 ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_speaker_widgets, in mt8195_rt1019_init()
698 dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); in mt8195_rt1019_init()
706 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); in mt8195_rt1019_init()
710 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1019_routes, in mt8195_rt1019_init()
713 dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); in mt8195_rt1019_init()
720 struct snd_soc_card *card = rtd->card; in mt8195_max98390_init()
723 ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets, in mt8195_max98390_init()
726 dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); in mt8195_max98390_init()
734 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); in mt8195_max98390_init()
738 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_max98390_routes, in mt8195_max98390_init()
741 dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); in mt8195_max98390_init()
761 struct snd_soc_component *component = dapm->component; in mt8195_set_bias_level_post()
763 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; in mt8195_set_bias_level_post()
772 (strcmp(component->name, RT5682_DEV0_NAME) && in mt8195_set_bias_level_post()
773 strcmp(component->name, RT5682S_DEV0_NAME))) in mt8195_set_bias_level_post()
778 if (!__clk_is_enabled(priv->i2so1_mclk)) in mt8195_set_bias_level_post()
781 clk_disable_unprepare(priv->i2so1_mclk); in mt8195_set_bias_level_post()
782 dev_dbg(card->dev, "Disable i2so1 mclk\n"); in mt8195_set_bias_level_post()
785 ret = clk_prepare_enable(priv->i2so1_mclk); in mt8195_set_bias_level_post()
787 dev_err(card->dev, "Can't enable i2so1 mclk: %d\n", ret); in mt8195_set_bias_level_post()
790 dev_dbg(card->dev, "Enable i2so1 mclk\n"); in mt8195_set_bias_level_post()
921 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
922 "mt6359-snd-codec-aif1")),
962 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
963 "mt6359-snd-codec-aif1"),
964 COMP_CODEC("dmic-codec",
965 "dmic-hifi")),
970 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
971 "mt6359-snd-codec-aif2")),
1370 if (!strcmp(rtd->dai_link->name, "ETDM2_IN_BE") || in mt8195_dai_link_fixup()
1371 !strcmp(rtd->dai_link->name, "ETDM1_OUT_BE")) { in mt8195_dai_link_fixup()
1391 card_data = (struct mt8195_card_data *)of_device_get_match_data(&pdev->dev); in mt8195_mt6359_dev_probe()
1392 card->dev = &pdev->dev; in mt8195_mt6359_dev_probe()
1396 dev_err(&pdev->dev, "%s new card name parsing error %d\n", in mt8195_mt6359_dev_probe()
1401 if (!card->name) in mt8195_mt6359_dev_probe()
1402 card->name = card_data->name; in mt8195_mt6359_dev_probe()
1404 if (strstr(card->name, "_5682s")) in mt8195_mt6359_dev_probe()
1406 soc_card_data = devm_kzalloc(&pdev->dev, sizeof(*card_data), GFP_KERNEL); in mt8195_mt6359_dev_probe()
1408 return -ENOMEM; in mt8195_mt6359_dev_probe()
1410 mach_priv = devm_kzalloc(&pdev->dev, sizeof(*mach_priv), GFP_KERNEL); in mt8195_mt6359_dev_probe()
1412 return -ENOMEM; in mt8195_mt6359_dev_probe()
1414 soc_card_data->mach_priv = mach_priv; in mt8195_mt6359_dev_probe()
1416 adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); in mt8195_mt6359_dev_probe()
1420 sof_priv = devm_kzalloc(&pdev->dev, sizeof(*sof_priv), GFP_KERNEL); in mt8195_mt6359_dev_probe()
1422 ret = -ENOMEM; in mt8195_mt6359_dev_probe()
1425 sof_priv->conn_streams = g_sof_conn_streams; in mt8195_mt6359_dev_probe()
1426 sof_priv->num_streams = ARRAY_SIZE(g_sof_conn_streams); in mt8195_mt6359_dev_probe()
1427 sof_priv->sof_dai_link_fixup = mt8195_dai_link_fixup; in mt8195_mt6359_dev_probe()
1428 soc_card_data->sof_priv = sof_priv; in mt8195_mt6359_dev_probe()
1429 card->probe = mtk_sof_card_probe; in mt8195_mt6359_dev_probe()
1430 card->late_probe = mtk_sof_card_late_probe; in mt8195_mt6359_dev_probe()
1431 if (!card->topology_shortname_created) { in mt8195_mt6359_dev_probe()
1432 snprintf(card->topology_shortname, 32, "sof-%s", card->name); in mt8195_mt6359_dev_probe()
1433 card->topology_shortname_created = true; in mt8195_mt6359_dev_probe()
1435 card->name = card->topology_shortname; in mt8195_mt6359_dev_probe()
1439 if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) { in mt8195_mt6359_dev_probe()
1440 ret = mtk_sof_dailink_parse_of(card, pdev->dev.of_node, in mt8195_mt6359_dev_probe()
1441 "mediatek,dai-link", in mt8195_mt6359_dev_probe()
1445 dev_dbg(&pdev->dev, "Parse dai-link fail\n"); in mt8195_mt6359_dev_probe()
1450 card->num_links = DAI_LINK_REGULAR_NUM; in mt8195_mt6359_dev_probe()
1453 platform_node = of_parse_phandle(pdev->dev.of_node, in mt8195_mt6359_dev_probe()
1456 dev_dbg(&pdev->dev, "Property 'platform' missing or invalid\n"); in mt8195_mt6359_dev_probe()
1457 ret = -EINVAL; in mt8195_mt6359_dev_probe()
1461 dp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,dptx-codec", 0); in mt8195_mt6359_dev_probe()
1462 hdmi_node = of_parse_phandle(pdev->dev.of_node, in mt8195_mt6359_dev_probe()
1463 "mediatek,hdmi-codec", 0); in mt8195_mt6359_dev_probe()
1466 if (!dai_link->platforms->name) { in mt8195_mt6359_dev_probe()
1467 if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && sof_on) in mt8195_mt6359_dev_probe()
1468 dai_link->platforms->of_node = adsp_node; in mt8195_mt6359_dev_probe()
1470 dai_link->platforms->of_node = platform_node; in mt8195_mt6359_dev_probe()
1473 if (strcmp(dai_link->name, "DPTX_BE") == 0) { in mt8195_mt6359_dev_probe()
1475 dev_dbg(&pdev->dev, "No property 'dptx-codec'\n"); in mt8195_mt6359_dev_probe()
1477 dai_link->codecs->of_node = dp_node; in mt8195_mt6359_dev_probe()
1478 dai_link->codecs->name = NULL; in mt8195_mt6359_dev_probe()
1479 dai_link->codecs->dai_name = "i2s-hifi"; in mt8195_mt6359_dev_probe()
1480 dai_link->init = mt8195_dptx_codec_init; in mt8195_mt6359_dev_probe()
1482 } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) { in mt8195_mt6359_dev_probe()
1484 dev_dbg(&pdev->dev, "No property 'hdmi-codec'\n"); in mt8195_mt6359_dev_probe()
1486 dai_link->codecs->of_node = hdmi_node; in mt8195_mt6359_dev_probe()
1487 dai_link->codecs->name = NULL; in mt8195_mt6359_dev_probe()
1488 dai_link->codecs->dai_name = "i2s-hifi"; in mt8195_mt6359_dev_probe()
1489 dai_link->init = mt8195_hdmi_codec_init; in mt8195_mt6359_dev_probe()
1491 } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 || in mt8195_mt6359_dev_probe()
1492 strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { in mt8195_mt6359_dev_probe()
1493 dai_link->codecs->name = in mt8195_mt6359_dev_probe()
1495 dai_link->codecs->dai_name = in mt8195_mt6359_dev_probe()
1497 } else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 || in mt8195_mt6359_dev_probe()
1498 strcmp(dai_link->name, "UL_SRC1_BE") == 0 || in mt8195_mt6359_dev_probe()
1499 strcmp(dai_link->name, "UL_SRC2_BE") == 0) { in mt8195_mt6359_dev_probe()
1501 dai_link->init = mt8195_mt6359_init; in mt8195_mt6359_dev_probe()
1504 } else if (strcmp(dai_link->name, "ETDM2_OUT_BE") == 0) { in mt8195_mt6359_dev_probe()
1505 switch (card_data->quirk) { in mt8195_mt6359_dev_probe()
1507 dai_link->codecs = rt1011_comps; in mt8195_mt6359_dev_probe()
1508 dai_link->num_codecs = ARRAY_SIZE(rt1011_comps); in mt8195_mt6359_dev_probe()
1509 dai_link->init = mt8195_rt1011_init; in mt8195_mt6359_dev_probe()
1510 dai_link->ops = &mt8195_rt1011_etdm_ops; in mt8195_mt6359_dev_probe()
1511 dai_link->be_hw_params_fixup = mt8195_etdm_hw_params_fixup; in mt8195_mt6359_dev_probe()
1512 card->codec_conf = rt1011_codec_conf; in mt8195_mt6359_dev_probe()
1513 card->num_configs = ARRAY_SIZE(rt1011_codec_conf); in mt8195_mt6359_dev_probe()
1516 dai_link->codecs = rt1019_comps; in mt8195_mt6359_dev_probe()
1517 dai_link->num_codecs = ARRAY_SIZE(rt1019_comps); in mt8195_mt6359_dev_probe()
1518 dai_link->init = mt8195_rt1019_init; in mt8195_mt6359_dev_probe()
1521 dai_link->codecs = max98390_comps; in mt8195_mt6359_dev_probe()
1522 dai_link->num_codecs = ARRAY_SIZE(max98390_comps); in mt8195_mt6359_dev_probe()
1523 dai_link->init = mt8195_max98390_init; in mt8195_mt6359_dev_probe()
1524 card->codec_conf = max98390_codec_conf; in mt8195_mt6359_dev_probe()
1525 card->num_configs = ARRAY_SIZE(max98390_codec_conf); in mt8195_mt6359_dev_probe()
1535 ret = devm_snd_soc_register_card(&pdev->dev, card); in mt8195_mt6359_dev_probe()
1591 MODULE_DESCRIPTION("MT8195-MT6359 ALSA SoC machine driver");