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 "../common/mtk-soundcard-driver.h"
26 #include "mt8195-afe-clk.h"
27 #include "mt8195-afe-common.h"
40 #define RT1011_CODEC_DAI "rt1011-aif"
41 #define RT1011_DEV0_NAME "rt1011.2-0038"
42 #define RT1011_DEV1_NAME "rt1011.2-0039"
47 #define MAX98390_CODEC_DAI "max98390-aif1"
48 #define MAX98390_DEV0_NAME "max98390.2-0038" /* right */
49 #define MAX98390_DEV1_NAME "max98390.2-0039" /* left */
51 #define RT5682_CODEC_DAI "rt5682-aif1"
52 #define RT5682_DEV0_NAME "rt5682.2-001a"
54 #define RT5682S_CODEC_DAI "rt5682s-aif1"
55 #define RT5682S_DEV0_NAME "rt5682s.2-001a"
73 /* Headset jack detection DAPM pins */
156 snd_soc_rtd_to_codec(rtd, 0)->component; in mt8195_mt6359_mtkaif_calibration()
158 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_mt6359_mtkaif_calibration()
159 struct mtkaif_param *param = &afe_priv->mtkaif_params; in mt8195_mt6359_mtkaif_calibration()
173 dev_dbg(afe->dev, "%s(), start\n", __func__); in mt8195_mt6359_mtkaif_calibration()
175 param->mtkaif_calibration_ok = false; in mt8195_mt6359_mtkaif_calibration()
177 param->mtkaif_chosen_phase[i] = -1; in mt8195_mt6359_mtkaif_calibration()
178 param->mtkaif_phase_cycle[i] = 0; in mt8195_mt6359_mtkaif_calibration()
179 mtkaif_chosen_phase[i] = -1; in mt8195_mt6359_mtkaif_calibration()
183 if (IS_ERR(afe_priv->topckgen)) { in mt8195_mt6359_mtkaif_calibration()
184 dev_info(afe->dev, "%s() Cannot find topckgen controller\n", in mt8195_mt6359_mtkaif_calibration()
189 pm_runtime_get_sync(afe->dev); in mt8195_mt6359_mtkaif_calibration()
193 regmap_update_bits(afe_priv->topckgen, in mt8195_mt6359_mtkaif_calibration()
204 regmap_update_bits(afe_priv->topckgen, in mt8195_mt6359_mtkaif_calibration()
210 cycle_1 = -1; in mt8195_mt6359_mtkaif_calibration()
211 cycle_2 = -1; in mt8195_mt6359_mtkaif_calibration()
212 cycle_3 = -1; in mt8195_mt6359_mtkaif_calibration()
215 regmap_read(afe_priv->topckgen, in mt8195_mt6359_mtkaif_calibration()
231 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()
247 mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] = phase - 1; in mt8195_mt6359_mtkaif_calibration()
253 mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] = phase - 1; in mt8195_mt6359_mtkaif_calibration()
259 mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] = phase - 1; in mt8195_mt6359_mtkaif_calibration()
263 regmap_update_bits(afe_priv->topckgen, in mt8195_mt6359_mtkaif_calibration()
299 pm_runtime_put(afe->dev); in mt8195_mt6359_mtkaif_calibration()
301 param->mtkaif_calibration_ok = mtkaif_calibration_ok; in mt8195_mt6359_mtkaif_calibration()
302 param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] = chosen_phase_1; in mt8195_mt6359_mtkaif_calibration()
303 param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] = chosen_phase_2; in mt8195_mt6359_mtkaif_calibration()
304 param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] = chosen_phase_3; in mt8195_mt6359_mtkaif_calibration()
306 param->mtkaif_phase_cycle[i] = mtkaif_phase_cycle[i]; in mt8195_mt6359_mtkaif_calibration()
308 dev_info(afe->dev, "%s(), end, calibration ok %d\n", in mt8195_mt6359_mtkaif_calibration()
309 __func__, param->mtkaif_calibration_ok); in mt8195_mt6359_mtkaif_calibration()
317 snd_soc_rtd_to_codec(rtd, 0)->component; in mt8195_mt6359_init()
354 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); in mt8195_dptx_codec_init()
355 struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_DP]; in mt8195_dptx_codec_init()
357 snd_soc_rtd_to_codec(rtd, 0)->component; in mt8195_dptx_codec_init()
360 ret = snd_soc_card_jack_new(rtd->card, "DP Jack", SND_JACK_LINEOUT, jack); in mt8195_dptx_codec_init()
369 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); in mt8195_hdmi_codec_init()
370 struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_HDMI]; in mt8195_hdmi_codec_init()
372 snd_soc_rtd_to_codec(rtd, 0)->component; in mt8195_hdmi_codec_init()
375 ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, jack); in mt8195_hdmi_codec_init()
398 struct snd_soc_card *card = rtd->card; in mt8195_rt5682_etdm_hw_params()
407 dev_err(card->dev, "invalid bit width: %d\n", bitwidth); in mt8195_rt5682_etdm_hw_params()
413 dev_err(card->dev, "failed to set tdm slot\n"); in mt8195_rt5682_etdm_hw_params()
420 dev_err(card->dev, "failed to set pll\n"); in mt8195_rt5682_etdm_hw_params()
427 dev_err(card->dev, "failed to set sysclk\n"); in mt8195_rt5682_etdm_hw_params()
442 snd_soc_rtd_to_codec(rtd, 0)->component; in mt8195_rt5682_init()
443 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); in mt8195_rt5682_init()
444 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; in mt8195_rt5682_init()
445 struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_HEADSET]; in mt8195_rt5682_init()
449 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_rt5682_init()
452 priv->i2so1_mclk = afe_priv->clk[MT8195_CLK_TOP_APLL12_DIV2]; in mt8195_rt5682_init()
454 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack", in mt8195_rt5682_init()
461 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); in mt8195_rt5682_init()
465 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); in mt8195_rt5682_init()
466 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); in mt8195_rt5682_init()
467 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); in mt8195_rt5682_init()
468 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); in mt8195_rt5682_init()
472 dev_err(rtd->dev, "Headset Jack set failed: %d\n", ret); in mt8195_rt5682_init()
484 struct snd_soc_card *card = rtd->card; in mt8195_rt1011_etdm_hw_params()
493 dev_err(card->dev, "codec_dai clock not set\n"); in mt8195_rt1011_etdm_hw_params()
501 dev_err(card->dev, "codec_dai clock not set\n"); in mt8195_rt1011_etdm_hw_params()
520 for_each_card_rtds(rtd->card, runtime) { in mt8195_sof_be_hw_params()
526 if (cmpnt_afe && !pm_runtime_active(cmpnt_afe->dev)) { in mt8195_sof_be_hw_params()
527 dev_err(rtd->dev, "afe pm runtime is not active!!\n"); in mt8195_sof_be_hw_params()
528 return -EINVAL; in mt8195_sof_be_hw_params()
540 struct snd_soc_card *card = rtd->card; in mt8195_rt1011_init()
543 ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets, in mt8195_rt1011_init()
546 dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); in mt8195_rt1011_init()
554 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); in mt8195_rt1011_init()
558 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1011_routes, in mt8195_rt1011_init()
561 dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); in mt8195_rt1011_init()
568 struct snd_soc_card *card = rtd->card; in mt8195_dumb_amp_init()
571 ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_speaker_widgets, in mt8195_dumb_amp_init()
574 dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); in mt8195_dumb_amp_init()
582 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); in mt8195_dumb_amp_init()
591 struct snd_soc_card *card = rtd->card; in mt8195_rt1019_init()
598 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1019_routes, in mt8195_rt1019_init()
601 dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); in mt8195_rt1019_init()
608 struct snd_soc_card *card = rtd->card; in mt8195_max98390_init()
611 ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets, in mt8195_max98390_init()
614 dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); in mt8195_max98390_init()
622 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); in mt8195_max98390_init()
626 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_max98390_routes, in mt8195_max98390_init()
629 dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); in mt8195_max98390_init()
649 struct snd_soc_component *component = dapm->component; in mt8195_set_bias_level_post()
651 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; in mt8195_set_bias_level_post()
660 (strcmp(component->name, RT5682_DEV0_NAME) && in mt8195_set_bias_level_post()
661 strcmp(component->name, RT5682S_DEV0_NAME))) in mt8195_set_bias_level_post()
666 if (!__clk_is_enabled(priv->i2so1_mclk)) in mt8195_set_bias_level_post()
669 clk_disable_unprepare(priv->i2so1_mclk); in mt8195_set_bias_level_post()
670 dev_dbg(card->dev, "Disable i2so1 mclk\n"); in mt8195_set_bias_level_post()
673 ret = clk_prepare_enable(priv->i2so1_mclk); in mt8195_set_bias_level_post()
675 dev_err(card->dev, "Can't enable i2so1 mclk: %d\n", ret); in mt8195_set_bias_level_post()
678 dev_dbg(card->dev, "Enable i2so1 mclk\n"); in mt8195_set_bias_level_post()
809 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
810 "mt6359-snd-codec-aif1")),
850 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
851 "mt6359-snd-codec-aif1"),
852 COMP_CODEC("dmic-codec",
853 "dmic-hifi")),
858 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
859 "mt6359-snd-codec-aif2")),
1255 if (!strcmp(rtd->dai_link->name, "ETDM2_IN_BE") || in mt8195_dai_link_fixup()
1256 !strcmp(rtd->dai_link->name, "ETDM1_OUT_BE")) { in mt8195_dai_link_fixup()
1265 struct mtk_platform_card_data *card_data = soc_card_data->card_data; in mt8195_mt6359_legacy_probe()
1266 struct snd_soc_card *card = card_data->card; in mt8195_mt6359_legacy_probe()
1269 struct device *dev = card->dev; in mt8195_mt6359_legacy_probe()
1273 if (strstr(card->name, "_5682s")) { in mt8195_mt6359_legacy_probe()
1281 dp_node = of_parse_phandle(dev->of_node, "mediatek,dptx-codec", 0); in mt8195_mt6359_legacy_probe()
1282 hdmi_node = of_parse_phandle(dev->of_node, "mediatek,hdmi-codec", 0); in mt8195_mt6359_legacy_probe()
1285 if (strcmp(dai_link->name, "DPTX_BE") == 0) { in mt8195_mt6359_legacy_probe()
1287 dev_dbg(dev, "No property 'dptx-codec'\n"); in mt8195_mt6359_legacy_probe()
1289 dai_link->codecs->of_node = dp_node; in mt8195_mt6359_legacy_probe()
1290 dai_link->codecs->name = NULL; in mt8195_mt6359_legacy_probe()
1291 dai_link->codecs->dai_name = "i2s-hifi"; in mt8195_mt6359_legacy_probe()
1292 dai_link->init = mt8195_dptx_codec_init; in mt8195_mt6359_legacy_probe()
1294 } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) { in mt8195_mt6359_legacy_probe()
1296 dev_dbg(dev, "No property 'hdmi-codec'\n"); in mt8195_mt6359_legacy_probe()
1298 dai_link->codecs->of_node = hdmi_node; in mt8195_mt6359_legacy_probe()
1299 dai_link->codecs->name = NULL; in mt8195_mt6359_legacy_probe()
1300 dai_link->codecs->dai_name = "i2s-hifi"; in mt8195_mt6359_legacy_probe()
1301 dai_link->init = mt8195_hdmi_codec_init; in mt8195_mt6359_legacy_probe()
1303 } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0) { in mt8195_mt6359_legacy_probe()
1307 dai_link->codecs->of_node = codec_node; in mt8195_mt6359_legacy_probe()
1308 dai_link->codecs->name = NULL; in mt8195_mt6359_legacy_probe()
1309 dai_link->codecs->dai_name = in mt8195_mt6359_legacy_probe()
1311 dai_link->init = mt8195_rt5682_init; in mt8195_mt6359_legacy_probe()
1312 dai_link->ops = &mt8195_rt5682_etdm_ops; in mt8195_mt6359_legacy_probe()
1314 } else if (strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { in mt8195_mt6359_legacy_probe()
1318 dai_link->codecs->of_node = codec_node; in mt8195_mt6359_legacy_probe()
1319 dai_link->codecs->name = NULL; in mt8195_mt6359_legacy_probe()
1320 dai_link->codecs->dai_name = in mt8195_mt6359_legacy_probe()
1322 dai_link->ops = &mt8195_rt5682_etdm_ops; in mt8195_mt6359_legacy_probe()
1324 } else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 || in mt8195_mt6359_legacy_probe()
1325 strcmp(dai_link->name, "UL_SRC1_BE") == 0 || in mt8195_mt6359_legacy_probe()
1326 strcmp(dai_link->name, "UL_SRC2_BE") == 0) { in mt8195_mt6359_legacy_probe()
1328 dai_link->init = mt8195_mt6359_init; in mt8195_mt6359_legacy_probe()
1331 } else if (strcmp(dai_link->name, "ETDM2_OUT_BE") == 0) { in mt8195_mt6359_legacy_probe()
1332 switch (card_data->flags) { in mt8195_mt6359_legacy_probe()
1334 dai_link->codecs = rt1011_comps; in mt8195_mt6359_legacy_probe()
1335 dai_link->num_codecs = ARRAY_SIZE(rt1011_comps); in mt8195_mt6359_legacy_probe()
1336 dai_link->init = mt8195_rt1011_init; in mt8195_mt6359_legacy_probe()
1337 dai_link->ops = &mt8195_rt1011_etdm_ops; in mt8195_mt6359_legacy_probe()
1338 dai_link->be_hw_params_fixup = mt8195_etdm_hw_params_fixup; in mt8195_mt6359_legacy_probe()
1339 card->codec_conf = rt1011_codec_conf; in mt8195_mt6359_legacy_probe()
1340 card->num_configs = ARRAY_SIZE(rt1011_codec_conf); in mt8195_mt6359_legacy_probe()
1343 dai_link->codecs = rt1019_comps; in mt8195_mt6359_legacy_probe()
1344 dai_link->num_codecs = ARRAY_SIZE(rt1019_comps); in mt8195_mt6359_legacy_probe()
1345 dai_link->init = mt8195_rt1019_init; in mt8195_mt6359_legacy_probe()
1348 dai_link->codecs = max98390_comps; in mt8195_mt6359_legacy_probe()
1349 dai_link->num_codecs = ARRAY_SIZE(max98390_comps); in mt8195_mt6359_legacy_probe()
1350 dai_link->init = mt8195_max98390_init; in mt8195_mt6359_legacy_probe()
1351 card->codec_conf = max98390_codec_conf; in mt8195_mt6359_legacy_probe()
1352 card->num_configs = ARRAY_SIZE(max98390_codec_conf); in mt8195_mt6359_legacy_probe()
1365 struct mtk_platform_card_data *card_data = soc_card_data->card_data; in mt8195_mt6359_soc_card_probe()
1366 struct snd_soc_card *card = card_data->card; in mt8195_mt6359_soc_card_probe()
1372 mach_priv = devm_kzalloc(card->dev, sizeof(*mach_priv), GFP_KERNEL); in mt8195_mt6359_soc_card_probe()
1374 return -ENOMEM; in mt8195_mt6359_soc_card_probe()
1376 soc_card_data->mach_priv = mach_priv; in mt8195_mt6359_soc_card_probe()
1382 if (strcmp(dai_link->name, "DPTX_BE") == 0) { in mt8195_mt6359_soc_card_probe()
1383 if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) in mt8195_mt6359_soc_card_probe()
1384 dai_link->init = mt8195_dptx_codec_init; in mt8195_mt6359_soc_card_probe()
1385 } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) { in mt8195_mt6359_soc_card_probe()
1386 if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) in mt8195_mt6359_soc_card_probe()
1387 dai_link->init = mt8195_hdmi_codec_init; in mt8195_mt6359_soc_card_probe()
1388 } else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 || in mt8195_mt6359_soc_card_probe()
1389 strcmp(dai_link->name, "UL_SRC1_BE") == 0 || in mt8195_mt6359_soc_card_probe()
1390 strcmp(dai_link->name, "UL_SRC2_BE") == 0) { in mt8195_mt6359_soc_card_probe()
1392 dai_link->init = mt8195_mt6359_init; in mt8195_mt6359_soc_card_probe()
1395 } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 || in mt8195_mt6359_soc_card_probe()
1396 strcmp(dai_link->name, "ETDM2_OUT_BE") == 0 || in mt8195_mt6359_soc_card_probe()
1397 strcmp(dai_link->name, "ETDM1_IN_BE") == 0 || in mt8195_mt6359_soc_card_probe()
1398 strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { in mt8195_mt6359_soc_card_probe()
1399 if (!strcmp(dai_link->codecs->dai_name, MAX98390_CODEC_DAI)) { in mt8195_mt6359_soc_card_probe()
1401 dai_link->init = mt8195_max98390_init; in mt8195_mt6359_soc_card_probe()
1404 } else if (!strcmp(dai_link->codecs->dai_name, RT1011_CODEC_DAI)) { in mt8195_mt6359_soc_card_probe()
1405 dai_link->ops = &mt8195_rt1011_etdm_ops; in mt8195_mt6359_soc_card_probe()
1407 dai_link->init = mt8195_rt1011_init; in mt8195_mt6359_soc_card_probe()
1410 } else if (!strcmp(dai_link->codecs->dai_name, RT1019_CODEC_DAI)) { in mt8195_mt6359_soc_card_probe()
1412 dai_link->init = mt8195_rt1019_init; in mt8195_mt6359_soc_card_probe()
1415 } else if (!strcmp(dai_link->codecs->dai_name, RT5682_CODEC_DAI) || in mt8195_mt6359_soc_card_probe()
1416 !strcmp(dai_link->codecs->dai_name, RT5682S_CODEC_DAI)) { in mt8195_mt6359_soc_card_probe()
1417 dai_link->ops = &mt8195_rt5682_etdm_ops; in mt8195_mt6359_soc_card_probe()
1419 dai_link->init = mt8195_rt5682_init; in mt8195_mt6359_soc_card_probe()
1423 if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) { in mt8195_mt6359_soc_card_probe()
1425 dai_link->init = mt8195_dumb_amp_init; in mt8195_mt6359_soc_card_probe()
1544 MODULE_DESCRIPTION("MT8195-MT6359 ALSA SoC machine driver");