1094e30efSTrevor Wu // SPDX-License-Identifier: GPL-2.0 2094e30efSTrevor Wu /* 3094e30efSTrevor Wu * mt8195-mt6359.c -- 4094e30efSTrevor Wu * MT8195-MT6359 ALSA SoC machine driver code 5094e30efSTrevor Wu * 6094e30efSTrevor Wu * Copyright (c) 2022 MediaTek Inc. 7094e30efSTrevor Wu * Author: Trevor Wu <trevor.wu@mediatek.com> 8094e30efSTrevor Wu * YC Hung <yc.hung@mediatek.com> 9094e30efSTrevor Wu */ 10094e30efSTrevor Wu 11094e30efSTrevor Wu #include <linux/input.h> 12094e30efSTrevor Wu #include <linux/module.h> 13340d79a1SRob Herring #include <linux/of.h> 14094e30efSTrevor Wu #include <linux/pm_runtime.h> 15094e30efSTrevor Wu #include <sound/jack.h> 16094e30efSTrevor Wu #include <sound/pcm_params.h> 17094e30efSTrevor Wu #include <sound/rt5682.h> 18094e30efSTrevor Wu #include <sound/soc.h> 19094e30efSTrevor Wu #include "../../codecs/mt6359.h" 20094e30efSTrevor Wu #include "../../codecs/rt1011.h" 21094e30efSTrevor Wu #include "../../codecs/rt5682.h" 22094e30efSTrevor Wu #include "../common/mtk-afe-platform-driver.h" 230caf1120SChunxu Li #include "../common/mtk-dsp-sof-common.h" 240caf1120SChunxu Li #include "../common/mtk-soc-card.h" 256718e1edSAngeloGioacchino Del Regno #include "../common/mtk-soundcard-driver.h" 26094e30efSTrevor Wu #include "mt8195-afe-clk.h" 27094e30efSTrevor Wu #include "mt8195-afe-common.h" 28094e30efSTrevor Wu 29094e30efSTrevor Wu #define RT1011_SPEAKER_AMP_PRESENT BIT(0) 30094e30efSTrevor Wu #define RT1019_SPEAKER_AMP_PRESENT BIT(1) 3186a6b9c9STrevor Wu #define MAX98390_SPEAKER_AMP_PRESENT BIT(2) 32094e30efSTrevor Wu 336718e1edSAngeloGioacchino Del Regno #define DUMB_CODEC_INIT BIT(0) 346718e1edSAngeloGioacchino Del Regno #define MT6359_CODEC_INIT BIT(1) 356718e1edSAngeloGioacchino Del Regno #define RT1011_CODEC_INIT BIT(2) 366718e1edSAngeloGioacchino Del Regno #define RT1019_CODEC_INIT BIT(3) 376718e1edSAngeloGioacchino Del Regno #define MAX98390_CODEC_INIT BIT(4) 386718e1edSAngeloGioacchino Del Regno #define RT5682_CODEC_INIT BIT(5) 396718e1edSAngeloGioacchino Del Regno 40094e30efSTrevor Wu #define RT1011_CODEC_DAI "rt1011-aif" 41094e30efSTrevor Wu #define RT1011_DEV0_NAME "rt1011.2-0038" 42094e30efSTrevor Wu #define RT1011_DEV1_NAME "rt1011.2-0039" 43094e30efSTrevor Wu 44094e30efSTrevor Wu #define RT1019_CODEC_DAI "HiFi" 45094e30efSTrevor Wu #define RT1019_DEV0_NAME "rt1019p" 46094e30efSTrevor Wu 4786a6b9c9STrevor Wu #define MAX98390_CODEC_DAI "max98390-aif1" 4886a6b9c9STrevor Wu #define MAX98390_DEV0_NAME "max98390.2-0038" /* right */ 4986a6b9c9STrevor Wu #define MAX98390_DEV1_NAME "max98390.2-0039" /* left */ 5086a6b9c9STrevor Wu 51094e30efSTrevor Wu #define RT5682_CODEC_DAI "rt5682-aif1" 52094e30efSTrevor Wu #define RT5682_DEV0_NAME "rt5682.2-001a" 53094e30efSTrevor Wu 54094e30efSTrevor Wu #define RT5682S_CODEC_DAI "rt5682s-aif1" 55094e30efSTrevor Wu #define RT5682S_DEV0_NAME "rt5682s.2-001a" 56094e30efSTrevor Wu 57094e30efSTrevor Wu #define SOF_DMA_DL2 "SOF_DMA_DL2" 58094e30efSTrevor Wu #define SOF_DMA_DL3 "SOF_DMA_DL3" 59094e30efSTrevor Wu #define SOF_DMA_UL4 "SOF_DMA_UL4" 60094e30efSTrevor Wu #define SOF_DMA_UL5 "SOF_DMA_UL5" 61094e30efSTrevor Wu 626718e1edSAngeloGioacchino Del Regno struct mt8195_mt6359_priv { 636718e1edSAngeloGioacchino Del Regno struct clk *i2so1_mclk; 64094e30efSTrevor Wu }; 65094e30efSTrevor Wu 666718e1edSAngeloGioacchino Del Regno enum mt8195_jacks { 676718e1edSAngeloGioacchino Del Regno MT8195_JACK_HEADSET, 686718e1edSAngeloGioacchino Del Regno MT8195_JACK_DP, 696718e1edSAngeloGioacchino Del Regno MT8195_JACK_HDMI, 706718e1edSAngeloGioacchino Del Regno MT8195_JACK_MAX, 71094e30efSTrevor Wu }; 72094e30efSTrevor Wu 73aa51e3c1SNícolas F. R. A. Prado /* Headset jack detection DAPM pins */ 74aa51e3c1SNícolas F. R. A. Prado static struct snd_soc_jack_pin mt8195_jack_pins[] = { 75aa51e3c1SNícolas F. R. A. Prado { 76aa51e3c1SNícolas F. R. A. Prado .pin = "Headphone", 77aa51e3c1SNícolas F. R. A. Prado .mask = SND_JACK_HEADPHONE, 78aa51e3c1SNícolas F. R. A. Prado }, 79aa51e3c1SNícolas F. R. A. Prado { 80aa51e3c1SNícolas F. R. A. Prado .pin = "Headset Mic", 81aa51e3c1SNícolas F. R. A. Prado .mask = SND_JACK_MICROPHONE, 82aa51e3c1SNícolas F. R. A. Prado }, 83aa51e3c1SNícolas F. R. A. Prado }; 84aa51e3c1SNícolas F. R. A. Prado 85094e30efSTrevor Wu static const struct snd_soc_dapm_widget mt8195_mt6359_widgets[] = { 863a0323c2STrevor Wu SND_SOC_DAPM_HP("Headphone", NULL), 87094e30efSTrevor Wu SND_SOC_DAPM_MIC("Headset Mic", NULL), 88094e30efSTrevor Wu SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0), 89094e30efSTrevor Wu SND_SOC_DAPM_MIXER(SOF_DMA_DL3, SND_SOC_NOPM, 0, 0, NULL, 0), 90094e30efSTrevor Wu SND_SOC_DAPM_MIXER(SOF_DMA_UL4, SND_SOC_NOPM, 0, 0, NULL, 0), 91094e30efSTrevor Wu SND_SOC_DAPM_MIXER(SOF_DMA_UL5, SND_SOC_NOPM, 0, 0, NULL, 0), 92094e30efSTrevor Wu }; 93094e30efSTrevor Wu 94094e30efSTrevor Wu static const struct snd_soc_dapm_route mt8195_mt6359_routes[] = { 95094e30efSTrevor Wu /* headset */ 963a0323c2STrevor Wu { "Headphone", NULL, "HPOL" }, 973a0323c2STrevor Wu { "Headphone", NULL, "HPOR" }, 98094e30efSTrevor Wu { "IN1P", NULL, "Headset Mic" }, 99094e30efSTrevor Wu /* SOF Uplink */ 100094e30efSTrevor Wu {SOF_DMA_UL4, NULL, "O034"}, 101094e30efSTrevor Wu {SOF_DMA_UL4, NULL, "O035"}, 102094e30efSTrevor Wu {SOF_DMA_UL5, NULL, "O036"}, 103094e30efSTrevor Wu {SOF_DMA_UL5, NULL, "O037"}, 104094e30efSTrevor Wu /* SOF Downlink */ 105094e30efSTrevor Wu {"I070", NULL, SOF_DMA_DL2}, 106094e30efSTrevor Wu {"I071", NULL, SOF_DMA_DL2}, 107094e30efSTrevor Wu {"I020", NULL, SOF_DMA_DL3}, 108094e30efSTrevor Wu {"I021", NULL, SOF_DMA_DL3}, 109094e30efSTrevor Wu }; 110094e30efSTrevor Wu 111094e30efSTrevor Wu static const struct snd_kcontrol_new mt8195_mt6359_controls[] = { 1123a0323c2STrevor Wu SOC_DAPM_PIN_SWITCH("Headphone"), 113094e30efSTrevor Wu SOC_DAPM_PIN_SWITCH("Headset Mic"), 114094e30efSTrevor Wu }; 115094e30efSTrevor Wu 116094e30efSTrevor Wu static const struct snd_soc_dapm_widget mt8195_dual_speaker_widgets[] = { 1173a0323c2STrevor Wu SND_SOC_DAPM_SPK("Left Spk", NULL), 1183a0323c2STrevor Wu SND_SOC_DAPM_SPK("Right Spk", NULL), 119094e30efSTrevor Wu }; 120094e30efSTrevor Wu 121094e30efSTrevor Wu static const struct snd_kcontrol_new mt8195_dual_speaker_controls[] = { 1223a0323c2STrevor Wu SOC_DAPM_PIN_SWITCH("Left Spk"), 1233a0323c2STrevor Wu SOC_DAPM_PIN_SWITCH("Right Spk"), 124094e30efSTrevor Wu }; 125094e30efSTrevor Wu 126094e30efSTrevor Wu static const struct snd_soc_dapm_widget mt8195_speaker_widgets[] = { 1273a0323c2STrevor Wu SND_SOC_DAPM_SPK("Ext Spk", NULL), 128094e30efSTrevor Wu }; 129094e30efSTrevor Wu 130094e30efSTrevor Wu static const struct snd_kcontrol_new mt8195_speaker_controls[] = { 1313a0323c2STrevor Wu SOC_DAPM_PIN_SWITCH("Ext Spk"), 132094e30efSTrevor Wu }; 133094e30efSTrevor Wu 134094e30efSTrevor Wu static const struct snd_soc_dapm_route mt8195_rt1011_routes[] = { 1353a0323c2STrevor Wu { "Left Spk", NULL, "Left SPO" }, 1363a0323c2STrevor Wu { "Right Spk", NULL, "Right SPO" }, 137094e30efSTrevor Wu }; 138094e30efSTrevor Wu 139094e30efSTrevor Wu static const struct snd_soc_dapm_route mt8195_rt1019_routes[] = { 1403a0323c2STrevor Wu { "Ext Spk", NULL, "Speaker" }, 141094e30efSTrevor Wu }; 142094e30efSTrevor Wu 14386a6b9c9STrevor Wu static const struct snd_soc_dapm_route mt8195_max98390_routes[] = { 14486a6b9c9STrevor Wu { "Left Spk", NULL, "Left BE_OUT" }, 14586a6b9c9STrevor Wu { "Right Spk", NULL, "Right BE_OUT" }, 14686a6b9c9STrevor Wu }; 14786a6b9c9STrevor Wu 148094e30efSTrevor Wu #define CKSYS_AUD_TOP_CFG 0x032c 149094e30efSTrevor Wu #define CKSYS_AUD_TOP_MON 0x0330 150094e30efSTrevor Wu 151094e30efSTrevor Wu static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd) 152094e30efSTrevor Wu { 153094e30efSTrevor Wu struct snd_soc_component *cmpnt_afe = 154094e30efSTrevor Wu snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 155094e30efSTrevor Wu struct snd_soc_component *cmpnt_codec = 156de9e7013SKuninori Morimoto snd_soc_rtd_to_codec(rtd, 0)->component; 157094e30efSTrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 158094e30efSTrevor Wu struct mt8195_afe_private *afe_priv = afe->platform_priv; 159094e30efSTrevor Wu struct mtkaif_param *param = &afe_priv->mtkaif_params; 160094e30efSTrevor Wu int chosen_phase_1, chosen_phase_2, chosen_phase_3; 161094e30efSTrevor Wu int prev_cycle_1, prev_cycle_2, prev_cycle_3; 162094e30efSTrevor Wu int test_done_1, test_done_2, test_done_3; 163094e30efSTrevor Wu int cycle_1, cycle_2, cycle_3; 164094e30efSTrevor Wu int mtkaif_chosen_phase[MT8195_MTKAIF_MISO_NUM]; 165094e30efSTrevor Wu int mtkaif_phase_cycle[MT8195_MTKAIF_MISO_NUM]; 166094e30efSTrevor Wu int mtkaif_calibration_num_phase; 167094e30efSTrevor Wu bool mtkaif_calibration_ok; 1681a3f0116STrevor Wu unsigned int monitor = 0; 169094e30efSTrevor Wu int counter; 170094e30efSTrevor Wu int phase; 171094e30efSTrevor Wu int i; 172094e30efSTrevor Wu 173094e30efSTrevor Wu dev_dbg(afe->dev, "%s(), start\n", __func__); 174094e30efSTrevor Wu 175094e30efSTrevor Wu param->mtkaif_calibration_ok = false; 176094e30efSTrevor Wu for (i = 0; i < MT8195_MTKAIF_MISO_NUM; i++) { 177094e30efSTrevor Wu param->mtkaif_chosen_phase[i] = -1; 178094e30efSTrevor Wu param->mtkaif_phase_cycle[i] = 0; 179094e30efSTrevor Wu mtkaif_chosen_phase[i] = -1; 180094e30efSTrevor Wu mtkaif_phase_cycle[i] = 0; 181094e30efSTrevor Wu } 182094e30efSTrevor Wu 183094e30efSTrevor Wu if (IS_ERR(afe_priv->topckgen)) { 184094e30efSTrevor Wu dev_info(afe->dev, "%s() Cannot find topckgen controller\n", 185094e30efSTrevor Wu __func__); 186094e30efSTrevor Wu return 0; 187094e30efSTrevor Wu } 188094e30efSTrevor Wu 189094e30efSTrevor Wu pm_runtime_get_sync(afe->dev); 190094e30efSTrevor Wu mt6359_mtkaif_calibration_enable(cmpnt_codec); 191094e30efSTrevor Wu 192094e30efSTrevor Wu /* set test type to synchronizer pulse */ 193094e30efSTrevor Wu regmap_update_bits(afe_priv->topckgen, 194094e30efSTrevor Wu CKSYS_AUD_TOP_CFG, 0xffff, 0x4); 195094e30efSTrevor Wu mtkaif_calibration_num_phase = 42; /* mt6359: 0 ~ 42 */ 196094e30efSTrevor Wu mtkaif_calibration_ok = true; 197094e30efSTrevor Wu 198094e30efSTrevor Wu for (phase = 0; 199094e30efSTrevor Wu phase <= mtkaif_calibration_num_phase && mtkaif_calibration_ok; 200094e30efSTrevor Wu phase++) { 201094e30efSTrevor Wu mt6359_set_mtkaif_calibration_phase(cmpnt_codec, 202094e30efSTrevor Wu phase, phase, phase); 203094e30efSTrevor Wu 204094e30efSTrevor Wu regmap_update_bits(afe_priv->topckgen, 205094e30efSTrevor Wu CKSYS_AUD_TOP_CFG, 0x1, 0x1); 206094e30efSTrevor Wu 207094e30efSTrevor Wu test_done_1 = 0; 208094e30efSTrevor Wu test_done_2 = 0; 209094e30efSTrevor Wu test_done_3 = 0; 210094e30efSTrevor Wu cycle_1 = -1; 211094e30efSTrevor Wu cycle_2 = -1; 212094e30efSTrevor Wu cycle_3 = -1; 213094e30efSTrevor Wu counter = 0; 214094e30efSTrevor Wu while (!(test_done_1 & test_done_2 & test_done_3)) { 215094e30efSTrevor Wu regmap_read(afe_priv->topckgen, 216094e30efSTrevor Wu CKSYS_AUD_TOP_MON, &monitor); 217094e30efSTrevor Wu test_done_1 = (monitor >> 28) & 0x1; 218094e30efSTrevor Wu test_done_2 = (monitor >> 29) & 0x1; 219094e30efSTrevor Wu test_done_3 = (monitor >> 30) & 0x1; 220094e30efSTrevor Wu if (test_done_1 == 1) 221094e30efSTrevor Wu cycle_1 = monitor & 0xf; 222094e30efSTrevor Wu 223094e30efSTrevor Wu if (test_done_2 == 1) 224094e30efSTrevor Wu cycle_2 = (monitor >> 4) & 0xf; 225094e30efSTrevor Wu 226094e30efSTrevor Wu if (test_done_3 == 1) 227094e30efSTrevor Wu cycle_3 = (monitor >> 8) & 0xf; 228094e30efSTrevor Wu 229094e30efSTrevor Wu /* handle if never test done */ 230094e30efSTrevor Wu if (++counter > 10000) { 231094e30efSTrevor Wu dev_info(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n", 232094e30efSTrevor Wu __func__, 233094e30efSTrevor Wu cycle_1, cycle_2, cycle_3, monitor); 234094e30efSTrevor Wu mtkaif_calibration_ok = false; 235094e30efSTrevor Wu break; 236094e30efSTrevor Wu } 237094e30efSTrevor Wu } 238094e30efSTrevor Wu 239094e30efSTrevor Wu if (phase == 0) { 240094e30efSTrevor Wu prev_cycle_1 = cycle_1; 241094e30efSTrevor Wu prev_cycle_2 = cycle_2; 242094e30efSTrevor Wu prev_cycle_3 = cycle_3; 243094e30efSTrevor Wu } 244094e30efSTrevor Wu 245094e30efSTrevor Wu if (cycle_1 != prev_cycle_1 && 246094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] < 0) { 247094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] = phase - 1; 248094e30efSTrevor Wu mtkaif_phase_cycle[MT8195_MTKAIF_MISO_0] = prev_cycle_1; 249094e30efSTrevor Wu } 250094e30efSTrevor Wu 251094e30efSTrevor Wu if (cycle_2 != prev_cycle_2 && 252094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] < 0) { 253094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] = phase - 1; 254094e30efSTrevor Wu mtkaif_phase_cycle[MT8195_MTKAIF_MISO_1] = prev_cycle_2; 255094e30efSTrevor Wu } 256094e30efSTrevor Wu 257094e30efSTrevor Wu if (cycle_3 != prev_cycle_3 && 258094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] < 0) { 259094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] = phase - 1; 260094e30efSTrevor Wu mtkaif_phase_cycle[MT8195_MTKAIF_MISO_2] = prev_cycle_3; 261094e30efSTrevor Wu } 262094e30efSTrevor Wu 263094e30efSTrevor Wu regmap_update_bits(afe_priv->topckgen, 264094e30efSTrevor Wu CKSYS_AUD_TOP_CFG, 0x1, 0x0); 265094e30efSTrevor Wu 266094e30efSTrevor Wu if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] >= 0 && 267094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] >= 0 && 268094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] >= 0) 269094e30efSTrevor Wu break; 270094e30efSTrevor Wu } 271094e30efSTrevor Wu 272094e30efSTrevor Wu if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] < 0) { 273094e30efSTrevor Wu mtkaif_calibration_ok = false; 274094e30efSTrevor Wu chosen_phase_1 = 0; 275094e30efSTrevor Wu } else { 276094e30efSTrevor Wu chosen_phase_1 = mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0]; 277094e30efSTrevor Wu } 278094e30efSTrevor Wu 279094e30efSTrevor Wu if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] < 0) { 280094e30efSTrevor Wu mtkaif_calibration_ok = false; 281094e30efSTrevor Wu chosen_phase_2 = 0; 282094e30efSTrevor Wu } else { 283094e30efSTrevor Wu chosen_phase_2 = mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1]; 284094e30efSTrevor Wu } 285094e30efSTrevor Wu 286094e30efSTrevor Wu if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] < 0) { 287094e30efSTrevor Wu mtkaif_calibration_ok = false; 288094e30efSTrevor Wu chosen_phase_3 = 0; 289094e30efSTrevor Wu } else { 290094e30efSTrevor Wu chosen_phase_3 = mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2]; 291094e30efSTrevor Wu } 292094e30efSTrevor Wu 293094e30efSTrevor Wu mt6359_set_mtkaif_calibration_phase(cmpnt_codec, 294094e30efSTrevor Wu chosen_phase_1, 295094e30efSTrevor Wu chosen_phase_2, 296094e30efSTrevor Wu chosen_phase_3); 297094e30efSTrevor Wu 298094e30efSTrevor Wu mt6359_mtkaif_calibration_disable(cmpnt_codec); 299094e30efSTrevor Wu pm_runtime_put(afe->dev); 300094e30efSTrevor Wu 301094e30efSTrevor Wu param->mtkaif_calibration_ok = mtkaif_calibration_ok; 302094e30efSTrevor Wu param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] = chosen_phase_1; 303094e30efSTrevor Wu param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] = chosen_phase_2; 304094e30efSTrevor Wu param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] = chosen_phase_3; 305094e30efSTrevor Wu for (i = 0; i < MT8195_MTKAIF_MISO_NUM; i++) 306094e30efSTrevor Wu param->mtkaif_phase_cycle[i] = mtkaif_phase_cycle[i]; 307094e30efSTrevor Wu 308094e30efSTrevor Wu dev_info(afe->dev, "%s(), end, calibration ok %d\n", 309094e30efSTrevor Wu __func__, param->mtkaif_calibration_ok); 310094e30efSTrevor Wu 311094e30efSTrevor Wu return 0; 312094e30efSTrevor Wu } 313094e30efSTrevor Wu 314094e30efSTrevor Wu static int mt8195_mt6359_init(struct snd_soc_pcm_runtime *rtd) 315094e30efSTrevor Wu { 316094e30efSTrevor Wu struct snd_soc_component *cmpnt_codec = 317de9e7013SKuninori Morimoto snd_soc_rtd_to_codec(rtd, 0)->component; 318094e30efSTrevor Wu 319094e30efSTrevor Wu /* set mtkaif protocol */ 320094e30efSTrevor Wu mt6359_set_mtkaif_protocol(cmpnt_codec, 321094e30efSTrevor Wu MT6359_MTKAIF_PROTOCOL_2_CLK_P2); 322094e30efSTrevor Wu 323094e30efSTrevor Wu /* mtkaif calibration */ 324094e30efSTrevor Wu mt8195_mt6359_mtkaif_calibration(rtd); 325094e30efSTrevor Wu 326094e30efSTrevor Wu return 0; 327094e30efSTrevor Wu } 328094e30efSTrevor Wu 329094e30efSTrevor Wu static int mt8195_hdmitx_dptx_startup(struct snd_pcm_substream *substream) 330094e30efSTrevor Wu { 331386fe4ceSAngeloGioacchino Del Regno return mtk_soundcard_startup(substream, MTK_CONSTRAINT_HDMIDP); 332094e30efSTrevor Wu } 333094e30efSTrevor Wu 334094e30efSTrevor Wu static const struct snd_soc_ops mt8195_hdmitx_dptx_playback_ops = { 335094e30efSTrevor Wu .startup = mt8195_hdmitx_dptx_startup, 336094e30efSTrevor Wu }; 337094e30efSTrevor Wu 338094e30efSTrevor Wu static int mt8195_dptx_hw_params(struct snd_pcm_substream *substream, 339094e30efSTrevor Wu struct snd_pcm_hw_params *params) 340094e30efSTrevor Wu { 341410a4514SKrzysztof Kozlowski struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 342de9e7013SKuninori Morimoto struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); 343094e30efSTrevor Wu 344094e30efSTrevor Wu return snd_soc_dai_set_sysclk(cpu_dai, 0, params_rate(params) * 256, 345094e30efSTrevor Wu SND_SOC_CLOCK_OUT); 346094e30efSTrevor Wu } 347094e30efSTrevor Wu 348094e30efSTrevor Wu static const struct snd_soc_ops mt8195_dptx_ops = { 349094e30efSTrevor Wu .hw_params = mt8195_dptx_hw_params, 350094e30efSTrevor Wu }; 351094e30efSTrevor Wu 352094e30efSTrevor Wu static int mt8195_dptx_codec_init(struct snd_soc_pcm_runtime *rtd) 353094e30efSTrevor Wu { 3540caf1120SChunxu Li struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 3556718e1edSAngeloGioacchino Del Regno struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_DP]; 356094e30efSTrevor Wu struct snd_soc_component *cmpnt_codec = 357de9e7013SKuninori Morimoto snd_soc_rtd_to_codec(rtd, 0)->component; 358094e30efSTrevor Wu int ret; 359094e30efSTrevor Wu 3606718e1edSAngeloGioacchino Del Regno ret = snd_soc_card_jack_new(rtd->card, "DP Jack", SND_JACK_LINEOUT, jack); 361094e30efSTrevor Wu if (ret) 362094e30efSTrevor Wu return ret; 363094e30efSTrevor Wu 3646718e1edSAngeloGioacchino Del Regno return snd_soc_component_set_jack(cmpnt_codec, jack, NULL); 365094e30efSTrevor Wu } 366094e30efSTrevor Wu 367094e30efSTrevor Wu static int mt8195_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd) 368094e30efSTrevor Wu { 3690caf1120SChunxu Li struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 3706718e1edSAngeloGioacchino Del Regno struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_HDMI]; 371094e30efSTrevor Wu struct snd_soc_component *cmpnt_codec = 372de9e7013SKuninori Morimoto snd_soc_rtd_to_codec(rtd, 0)->component; 373094e30efSTrevor Wu int ret; 374094e30efSTrevor Wu 3756718e1edSAngeloGioacchino Del Regno ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, jack); 376094e30efSTrevor Wu if (ret) 377094e30efSTrevor Wu return ret; 378094e30efSTrevor Wu 3796718e1edSAngeloGioacchino Del Regno return snd_soc_component_set_jack(cmpnt_codec, jack, NULL); 380094e30efSTrevor Wu } 381094e30efSTrevor Wu 382094e30efSTrevor Wu static int mt8195_dptx_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, 383094e30efSTrevor Wu struct snd_pcm_hw_params *params) 384094e30efSTrevor Wu { 385094e30efSTrevor Wu /* fix BE i2s format to S24_LE, clean param mask first */ 386094e30efSTrevor Wu snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), 387094e30efSTrevor Wu 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); 388094e30efSTrevor Wu 389094e30efSTrevor Wu params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); 390094e30efSTrevor Wu 391094e30efSTrevor Wu return 0; 392094e30efSTrevor Wu } 393094e30efSTrevor Wu 394094e30efSTrevor Wu static int mt8195_rt5682_etdm_hw_params(struct snd_pcm_substream *substream, 395094e30efSTrevor Wu struct snd_pcm_hw_params *params) 396094e30efSTrevor Wu { 397410a4514SKrzysztof Kozlowski struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 398094e30efSTrevor Wu struct snd_soc_card *card = rtd->card; 399de9e7013SKuninori Morimoto struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); 400de9e7013SKuninori Morimoto struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); 401094e30efSTrevor Wu unsigned int rate = params_rate(params); 402094e30efSTrevor Wu int bitwidth; 403094e30efSTrevor Wu int ret; 404094e30efSTrevor Wu 405094e30efSTrevor Wu bitwidth = snd_pcm_format_width(params_format(params)); 406094e30efSTrevor Wu if (bitwidth < 0) { 407094e30efSTrevor Wu dev_err(card->dev, "invalid bit width: %d\n", bitwidth); 408094e30efSTrevor Wu return bitwidth; 409094e30efSTrevor Wu } 410094e30efSTrevor Wu 411094e30efSTrevor Wu ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth); 412094e30efSTrevor Wu if (ret) { 413094e30efSTrevor Wu dev_err(card->dev, "failed to set tdm slot\n"); 414094e30efSTrevor Wu return ret; 415094e30efSTrevor Wu } 416094e30efSTrevor Wu 417094e30efSTrevor Wu ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1, RT5682_PLL1_S_MCLK, 418094e30efSTrevor Wu rate * 256, rate * 512); 419094e30efSTrevor Wu if (ret) { 420094e30efSTrevor Wu dev_err(card->dev, "failed to set pll\n"); 421094e30efSTrevor Wu return ret; 422094e30efSTrevor Wu } 423094e30efSTrevor Wu 424094e30efSTrevor Wu ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL1, 425094e30efSTrevor Wu rate * 512, SND_SOC_CLOCK_IN); 426094e30efSTrevor Wu if (ret) { 427094e30efSTrevor Wu dev_err(card->dev, "failed to set sysclk\n"); 428094e30efSTrevor Wu return ret; 429094e30efSTrevor Wu } 430094e30efSTrevor Wu 431094e30efSTrevor Wu return snd_soc_dai_set_sysclk(cpu_dai, 0, rate * 256, 432094e30efSTrevor Wu SND_SOC_CLOCK_OUT); 433094e30efSTrevor Wu } 434094e30efSTrevor Wu 435094e30efSTrevor Wu static const struct snd_soc_ops mt8195_rt5682_etdm_ops = { 436094e30efSTrevor Wu .hw_params = mt8195_rt5682_etdm_hw_params, 437094e30efSTrevor Wu }; 438094e30efSTrevor Wu 439094e30efSTrevor Wu static int mt8195_rt5682_init(struct snd_soc_pcm_runtime *rtd) 440094e30efSTrevor Wu { 441094e30efSTrevor Wu struct snd_soc_component *cmpnt_codec = 442de9e7013SKuninori Morimoto snd_soc_rtd_to_codec(rtd, 0)->component; 4430caf1120SChunxu Li struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 4440caf1120SChunxu Li struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 4456718e1edSAngeloGioacchino Del Regno struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_HEADSET]; 446094e30efSTrevor Wu struct snd_soc_component *cmpnt_afe = 447094e30efSTrevor Wu snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 448094e30efSTrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 449094e30efSTrevor Wu struct mt8195_afe_private *afe_priv = afe->platform_priv; 450094e30efSTrevor Wu int ret; 451094e30efSTrevor Wu 452094e30efSTrevor Wu priv->i2so1_mclk = afe_priv->clk[MT8195_CLK_TOP_APLL12_DIV2]; 453094e30efSTrevor Wu 454aa51e3c1SNícolas F. R. A. Prado ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack", 455094e30efSTrevor Wu SND_JACK_HEADSET | SND_JACK_BTN_0 | 456094e30efSTrevor Wu SND_JACK_BTN_1 | SND_JACK_BTN_2 | 457094e30efSTrevor Wu SND_JACK_BTN_3, 458aa51e3c1SNícolas F. R. A. Prado jack, mt8195_jack_pins, 459aa51e3c1SNícolas F. R. A. Prado ARRAY_SIZE(mt8195_jack_pins)); 460094e30efSTrevor Wu if (ret) { 461094e30efSTrevor Wu dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); 462094e30efSTrevor Wu return ret; 463094e30efSTrevor Wu } 464094e30efSTrevor Wu 465094e30efSTrevor Wu snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); 466094e30efSTrevor Wu snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); 467094e30efSTrevor Wu snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); 468094e30efSTrevor Wu snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); 469094e30efSTrevor Wu 470094e30efSTrevor Wu ret = snd_soc_component_set_jack(cmpnt_codec, jack, NULL); 471094e30efSTrevor Wu if (ret) { 472094e30efSTrevor Wu dev_err(rtd->dev, "Headset Jack set failed: %d\n", ret); 473094e30efSTrevor Wu return ret; 474094e30efSTrevor Wu } 475094e30efSTrevor Wu 476094e30efSTrevor Wu return 0; 477094e30efSTrevor Wu }; 478094e30efSTrevor Wu 479094e30efSTrevor Wu static int mt8195_rt1011_etdm_hw_params(struct snd_pcm_substream *substream, 480094e30efSTrevor Wu struct snd_pcm_hw_params *params) 481094e30efSTrevor Wu { 482de9e7013SKuninori Morimoto struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 483094e30efSTrevor Wu struct snd_soc_dai *codec_dai; 484094e30efSTrevor Wu struct snd_soc_card *card = rtd->card; 485094e30efSTrevor Wu int srate, i, ret; 486094e30efSTrevor Wu 487094e30efSTrevor Wu srate = params_rate(params); 488094e30efSTrevor Wu 489094e30efSTrevor Wu for_each_rtd_codec_dais(rtd, i, codec_dai) { 490094e30efSTrevor Wu ret = snd_soc_dai_set_pll(codec_dai, 0, RT1011_PLL1_S_BCLK, 491094e30efSTrevor Wu 64 * srate, 256 * srate); 492094e30efSTrevor Wu if (ret < 0) { 493094e30efSTrevor Wu dev_err(card->dev, "codec_dai clock not set\n"); 494094e30efSTrevor Wu return ret; 495094e30efSTrevor Wu } 496094e30efSTrevor Wu 497094e30efSTrevor Wu ret = snd_soc_dai_set_sysclk(codec_dai, 498094e30efSTrevor Wu RT1011_FS_SYS_PRE_S_PLL1, 499094e30efSTrevor Wu 256 * srate, SND_SOC_CLOCK_IN); 500094e30efSTrevor Wu if (ret < 0) { 501094e30efSTrevor Wu dev_err(card->dev, "codec_dai clock not set\n"); 502094e30efSTrevor Wu return ret; 503094e30efSTrevor Wu } 504094e30efSTrevor Wu } 505094e30efSTrevor Wu return 0; 506094e30efSTrevor Wu } 507094e30efSTrevor Wu 508094e30efSTrevor Wu static const struct snd_soc_ops mt8195_rt1011_etdm_ops = { 509094e30efSTrevor Wu .hw_params = mt8195_rt1011_etdm_hw_params, 510094e30efSTrevor Wu }; 511094e30efSTrevor Wu 51283f1b7f3SYC Hung static int mt8195_sof_be_hw_params(struct snd_pcm_substream *substream, 51383f1b7f3SYC Hung struct snd_pcm_hw_params *params) 51483f1b7f3SYC Hung { 515de9e7013SKuninori Morimoto struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 51683f1b7f3SYC Hung struct snd_soc_component *cmpnt_afe = NULL; 51783f1b7f3SYC Hung struct snd_soc_pcm_runtime *runtime; 51883f1b7f3SYC Hung 51983f1b7f3SYC Hung /* find afe component */ 52083f1b7f3SYC Hung for_each_card_rtds(rtd->card, runtime) { 52183f1b7f3SYC Hung cmpnt_afe = snd_soc_rtdcom_lookup(runtime, AFE_PCM_NAME); 52283f1b7f3SYC Hung if (cmpnt_afe) 52383f1b7f3SYC Hung break; 52483f1b7f3SYC Hung } 52583f1b7f3SYC Hung 52683f1b7f3SYC Hung if (cmpnt_afe && !pm_runtime_active(cmpnt_afe->dev)) { 52783f1b7f3SYC Hung dev_err(rtd->dev, "afe pm runtime is not active!!\n"); 52883f1b7f3SYC Hung return -EINVAL; 52983f1b7f3SYC Hung } 53083f1b7f3SYC Hung 53183f1b7f3SYC Hung return 0; 53283f1b7f3SYC Hung } 53383f1b7f3SYC Hung 53483f1b7f3SYC Hung static const struct snd_soc_ops mt8195_sof_be_ops = { 53583f1b7f3SYC Hung .hw_params = mt8195_sof_be_hw_params, 53683f1b7f3SYC Hung }; 53783f1b7f3SYC Hung 538094e30efSTrevor Wu static int mt8195_rt1011_init(struct snd_soc_pcm_runtime *rtd) 539094e30efSTrevor Wu { 540094e30efSTrevor Wu struct snd_soc_card *card = rtd->card; 541094e30efSTrevor Wu int ret; 542094e30efSTrevor Wu 543094e30efSTrevor Wu ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets, 544094e30efSTrevor Wu ARRAY_SIZE(mt8195_dual_speaker_widgets)); 545094e30efSTrevor Wu if (ret) { 546094e30efSTrevor Wu dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); 547094e30efSTrevor Wu /* Don't need to add routes if widget addition failed */ 548094e30efSTrevor Wu return ret; 549094e30efSTrevor Wu } 550094e30efSTrevor Wu 551094e30efSTrevor Wu ret = snd_soc_add_card_controls(card, mt8195_dual_speaker_controls, 552094e30efSTrevor Wu ARRAY_SIZE(mt8195_dual_speaker_controls)); 553094e30efSTrevor Wu if (ret) { 554094e30efSTrevor Wu dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); 555094e30efSTrevor Wu return ret; 556094e30efSTrevor Wu } 557094e30efSTrevor Wu 558094e30efSTrevor Wu ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1011_routes, 559094e30efSTrevor Wu ARRAY_SIZE(mt8195_rt1011_routes)); 560094e30efSTrevor Wu if (ret) 561094e30efSTrevor Wu dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); 562094e30efSTrevor Wu 563094e30efSTrevor Wu return ret; 564094e30efSTrevor Wu } 565094e30efSTrevor Wu 5666718e1edSAngeloGioacchino Del Regno static int mt8195_dumb_amp_init(struct snd_soc_pcm_runtime *rtd) 567094e30efSTrevor Wu { 568094e30efSTrevor Wu struct snd_soc_card *card = rtd->card; 569094e30efSTrevor Wu int ret; 570094e30efSTrevor Wu 571094e30efSTrevor Wu ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_speaker_widgets, 572094e30efSTrevor Wu ARRAY_SIZE(mt8195_speaker_widgets)); 573094e30efSTrevor Wu if (ret) { 574094e30efSTrevor Wu dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); 575094e30efSTrevor Wu /* Don't need to add routes if widget addition failed */ 576094e30efSTrevor Wu return ret; 577094e30efSTrevor Wu } 578094e30efSTrevor Wu 579094e30efSTrevor Wu ret = snd_soc_add_card_controls(card, mt8195_speaker_controls, 580094e30efSTrevor Wu ARRAY_SIZE(mt8195_speaker_controls)); 581094e30efSTrevor Wu if (ret) { 582094e30efSTrevor Wu dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); 583094e30efSTrevor Wu return ret; 584094e30efSTrevor Wu } 585094e30efSTrevor Wu 5866718e1edSAngeloGioacchino Del Regno return 0; 5876718e1edSAngeloGioacchino Del Regno } 5886718e1edSAngeloGioacchino Del Regno 5896718e1edSAngeloGioacchino Del Regno static int mt8195_rt1019_init(struct snd_soc_pcm_runtime *rtd) 5906718e1edSAngeloGioacchino Del Regno { 5916718e1edSAngeloGioacchino Del Regno struct snd_soc_card *card = rtd->card; 5926718e1edSAngeloGioacchino Del Regno int ret; 5936718e1edSAngeloGioacchino Del Regno 5946718e1edSAngeloGioacchino Del Regno ret = mt8195_dumb_amp_init(rtd); 5956718e1edSAngeloGioacchino Del Regno if (ret) 5966718e1edSAngeloGioacchino Del Regno return ret; 5976718e1edSAngeloGioacchino Del Regno 598094e30efSTrevor Wu ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1019_routes, 599094e30efSTrevor Wu ARRAY_SIZE(mt8195_rt1019_routes)); 600094e30efSTrevor Wu if (ret) 601094e30efSTrevor Wu dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); 602094e30efSTrevor Wu 603094e30efSTrevor Wu return ret; 604094e30efSTrevor Wu } 605094e30efSTrevor Wu 60686a6b9c9STrevor Wu static int mt8195_max98390_init(struct snd_soc_pcm_runtime *rtd) 60786a6b9c9STrevor Wu { 60886a6b9c9STrevor Wu struct snd_soc_card *card = rtd->card; 60986a6b9c9STrevor Wu int ret; 61086a6b9c9STrevor Wu 61186a6b9c9STrevor Wu ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets, 61286a6b9c9STrevor Wu ARRAY_SIZE(mt8195_dual_speaker_widgets)); 61386a6b9c9STrevor Wu if (ret) { 61486a6b9c9STrevor Wu dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); 61586a6b9c9STrevor Wu /* Don't need to add routes if widget addition failed */ 61686a6b9c9STrevor Wu return ret; 61786a6b9c9STrevor Wu } 61886a6b9c9STrevor Wu 61986a6b9c9STrevor Wu ret = snd_soc_add_card_controls(card, mt8195_dual_speaker_controls, 62086a6b9c9STrevor Wu ARRAY_SIZE(mt8195_dual_speaker_controls)); 62186a6b9c9STrevor Wu if (ret) { 62286a6b9c9STrevor Wu dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); 62386a6b9c9STrevor Wu return ret; 62486a6b9c9STrevor Wu } 62586a6b9c9STrevor Wu 62686a6b9c9STrevor Wu ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_max98390_routes, 62786a6b9c9STrevor Wu ARRAY_SIZE(mt8195_max98390_routes)); 62886a6b9c9STrevor Wu if (ret) 62986a6b9c9STrevor Wu dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); 63086a6b9c9STrevor Wu 63186a6b9c9STrevor Wu return ret; 63286a6b9c9STrevor Wu } 63386a6b9c9STrevor Wu 634094e30efSTrevor Wu static int mt8195_etdm_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, 635094e30efSTrevor Wu struct snd_pcm_hw_params *params) 636094e30efSTrevor Wu { 637094e30efSTrevor Wu /* fix BE i2s format to S24_LE, clean param mask first */ 638094e30efSTrevor Wu snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), 639094e30efSTrevor Wu 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); 640094e30efSTrevor Wu 641094e30efSTrevor Wu params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); 642094e30efSTrevor Wu 643094e30efSTrevor Wu return 0; 644094e30efSTrevor Wu } 645094e30efSTrevor Wu 646094e30efSTrevor Wu static int mt8195_set_bias_level_post(struct snd_soc_card *card, 647094e30efSTrevor Wu struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level) 648094e30efSTrevor Wu { 649094e30efSTrevor Wu struct snd_soc_component *component = dapm->component; 6500caf1120SChunxu Li struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card); 6510caf1120SChunxu Li struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 652094e30efSTrevor Wu int ret; 653094e30efSTrevor Wu 654094e30efSTrevor Wu /* 655094e30efSTrevor Wu * It's required to control mclk directly in the set_bias_level_post 656094e30efSTrevor Wu * function for rt5682 and rt5682s codec, or the unexpected pop happens 657094e30efSTrevor Wu * at the end of playback. 658094e30efSTrevor Wu */ 659094e30efSTrevor Wu if (!component || 660094e30efSTrevor Wu (strcmp(component->name, RT5682_DEV0_NAME) && 661094e30efSTrevor Wu strcmp(component->name, RT5682S_DEV0_NAME))) 662094e30efSTrevor Wu return 0; 663094e30efSTrevor Wu 664094e30efSTrevor Wu switch (level) { 665094e30efSTrevor Wu case SND_SOC_BIAS_OFF: 666094e30efSTrevor Wu if (!__clk_is_enabled(priv->i2so1_mclk)) 667094e30efSTrevor Wu return 0; 668094e30efSTrevor Wu 669094e30efSTrevor Wu clk_disable_unprepare(priv->i2so1_mclk); 670094e30efSTrevor Wu dev_dbg(card->dev, "Disable i2so1 mclk\n"); 671094e30efSTrevor Wu break; 672094e30efSTrevor Wu case SND_SOC_BIAS_ON: 673094e30efSTrevor Wu ret = clk_prepare_enable(priv->i2so1_mclk); 674094e30efSTrevor Wu if (ret) { 675094e30efSTrevor Wu dev_err(card->dev, "Can't enable i2so1 mclk: %d\n", ret); 676094e30efSTrevor Wu return ret; 677094e30efSTrevor Wu } 678094e30efSTrevor Wu dev_dbg(card->dev, "Enable i2so1 mclk\n"); 679094e30efSTrevor Wu break; 680094e30efSTrevor Wu default: 681094e30efSTrevor Wu break; 682094e30efSTrevor Wu } 683094e30efSTrevor Wu 684094e30efSTrevor Wu return 0; 685094e30efSTrevor Wu } 686094e30efSTrevor Wu 687094e30efSTrevor Wu enum { 688094e30efSTrevor Wu DAI_LINK_DL2_FE, 689094e30efSTrevor Wu DAI_LINK_DL3_FE, 690094e30efSTrevor Wu DAI_LINK_DL6_FE, 691094e30efSTrevor Wu DAI_LINK_DL7_FE, 692094e30efSTrevor Wu DAI_LINK_DL8_FE, 693094e30efSTrevor Wu DAI_LINK_DL10_FE, 694094e30efSTrevor Wu DAI_LINK_DL11_FE, 695094e30efSTrevor Wu DAI_LINK_UL1_FE, 696094e30efSTrevor Wu DAI_LINK_UL2_FE, 697094e30efSTrevor Wu DAI_LINK_UL3_FE, 698094e30efSTrevor Wu DAI_LINK_UL4_FE, 699094e30efSTrevor Wu DAI_LINK_UL5_FE, 700094e30efSTrevor Wu DAI_LINK_UL6_FE, 701094e30efSTrevor Wu DAI_LINK_UL8_FE, 702094e30efSTrevor Wu DAI_LINK_UL9_FE, 703094e30efSTrevor Wu DAI_LINK_UL10_FE, 704094e30efSTrevor Wu DAI_LINK_DL_SRC_BE, 705094e30efSTrevor Wu DAI_LINK_DPTX_BE, 706094e30efSTrevor Wu DAI_LINK_ETDM1_IN_BE, 707094e30efSTrevor Wu DAI_LINK_ETDM2_IN_BE, 708094e30efSTrevor Wu DAI_LINK_ETDM1_OUT_BE, 709094e30efSTrevor Wu DAI_LINK_ETDM2_OUT_BE, 710094e30efSTrevor Wu DAI_LINK_ETDM3_OUT_BE, 711094e30efSTrevor Wu DAI_LINK_PCM1_BE, 712094e30efSTrevor Wu DAI_LINK_UL_SRC1_BE, 713094e30efSTrevor Wu DAI_LINK_UL_SRC2_BE, 714094e30efSTrevor Wu DAI_LINK_REGULAR_LAST = DAI_LINK_UL_SRC2_BE, 715094e30efSTrevor Wu DAI_LINK_SOF_START, 716094e30efSTrevor Wu DAI_LINK_SOF_DL2_BE = DAI_LINK_SOF_START, 717094e30efSTrevor Wu DAI_LINK_SOF_DL3_BE, 718094e30efSTrevor Wu DAI_LINK_SOF_UL4_BE, 719094e30efSTrevor Wu DAI_LINK_SOF_UL5_BE, 720094e30efSTrevor Wu DAI_LINK_SOF_END = DAI_LINK_SOF_UL5_BE, 721094e30efSTrevor Wu }; 722094e30efSTrevor Wu 723094e30efSTrevor Wu #define DAI_LINK_REGULAR_NUM (DAI_LINK_REGULAR_LAST + 1) 724094e30efSTrevor Wu 725094e30efSTrevor Wu /* FE */ 726094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL2_FE, 727094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL2")), 728094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 729094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 730094e30efSTrevor Wu 731094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL3_FE, 732094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL3")), 733094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 734094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 735094e30efSTrevor Wu 736094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL6_FE, 737094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL6")), 738094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 739094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 740094e30efSTrevor Wu 741094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL7_FE, 742094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL7")), 743094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 744094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 745094e30efSTrevor Wu 746094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL8_FE, 747094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL8")), 748094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 749094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 750094e30efSTrevor Wu 751094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL10_FE, 752094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL10")), 753094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 754094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 755094e30efSTrevor Wu 756094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL11_FE, 757094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL11")), 758094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 759094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 760094e30efSTrevor Wu 761094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL1_FE, 762094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL1")), 763094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 764094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 765094e30efSTrevor Wu 766094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL2_FE, 767094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL2")), 768094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 769094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 770094e30efSTrevor Wu 771094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL3_FE, 772094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL3")), 773094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 774094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 775094e30efSTrevor Wu 776094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL4_FE, 777094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL4")), 778094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 779094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 780094e30efSTrevor Wu 781094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL5_FE, 782094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL5")), 783094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 784094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 785094e30efSTrevor Wu 786094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL6_FE, 787094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL6")), 788094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 789094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 790094e30efSTrevor Wu 791094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL8_FE, 792094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL8")), 793094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 794094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 795094e30efSTrevor Wu 796094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL9_FE, 797094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL9")), 798094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 799094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 800094e30efSTrevor Wu 801094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL10_FE, 802094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL10")), 803094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 804094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 805094e30efSTrevor Wu 806094e30efSTrevor Wu /* BE */ 807094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL_SRC_BE, 808094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL_SRC")), 809094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound", 810094e30efSTrevor Wu "mt6359-snd-codec-aif1")), 811094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 812094e30efSTrevor Wu 813094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DPTX_BE, 814094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DPTX")), 815094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 816094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 817094e30efSTrevor Wu 818094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(ETDM1_IN_BE, 819094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_IN")), 820094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 821094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 822094e30efSTrevor Wu 823094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(ETDM2_IN_BE, 824094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_IN")), 825e70b8dd2SAngeloGioacchino Del Regno DAILINK_COMP_ARRAY(COMP_EMPTY()), 826094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 827094e30efSTrevor Wu 828094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(ETDM1_OUT_BE, 829094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_OUT")), 830*282a4482SChen-Yu Tsai DAILINK_COMP_ARRAY(COMP_EMPTY()), 831094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 832094e30efSTrevor Wu 833094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(ETDM2_OUT_BE, 834094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_OUT")), 835094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 836094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 837094e30efSTrevor Wu 838094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(ETDM3_OUT_BE, 839094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("ETDM3_OUT")), 840094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 841094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 842094e30efSTrevor Wu 843094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(PCM1_BE, 844094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("PCM1")), 845094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 846094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 847094e30efSTrevor Wu 848094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL_SRC1_BE, 849094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC1")), 850094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound", 851094e30efSTrevor Wu "mt6359-snd-codec-aif1"), 852094e30efSTrevor Wu COMP_CODEC("dmic-codec", 853094e30efSTrevor Wu "dmic-hifi")), 854094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 855094e30efSTrevor Wu 856094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL_SRC2_BE, 857094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC2")), 858094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound", 859094e30efSTrevor Wu "mt6359-snd-codec-aif2")), 860094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 861094e30efSTrevor Wu 862094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(AFE_SOF_DL2, 863094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL2")), 864094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 865094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 866094e30efSTrevor Wu 867094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(AFE_SOF_DL3, 868094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL3")), 869094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 870094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 871094e30efSTrevor Wu 872094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(AFE_SOF_UL4, 873094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL4")), 874094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 875094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 876094e30efSTrevor Wu 877094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(AFE_SOF_UL5, 878094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL5")), 879094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 880094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 881094e30efSTrevor Wu 882094e30efSTrevor Wu /* codec */ 883094e30efSTrevor Wu SND_SOC_DAILINK_DEF(rt1019_comps, 884094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CODEC(RT1019_DEV0_NAME, 885094e30efSTrevor Wu RT1019_CODEC_DAI))); 886094e30efSTrevor Wu 887094e30efSTrevor Wu SND_SOC_DAILINK_DEF(rt1011_comps, 888094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CODEC(RT1011_DEV0_NAME, 889094e30efSTrevor Wu RT1011_CODEC_DAI), 890094e30efSTrevor Wu COMP_CODEC(RT1011_DEV1_NAME, 891094e30efSTrevor Wu RT1011_CODEC_DAI))); 892094e30efSTrevor Wu 89386a6b9c9STrevor Wu SND_SOC_DAILINK_DEF(max98390_comps, 89486a6b9c9STrevor Wu DAILINK_COMP_ARRAY(COMP_CODEC(MAX98390_DEV0_NAME, 89586a6b9c9STrevor Wu MAX98390_CODEC_DAI), 89686a6b9c9STrevor Wu COMP_CODEC(MAX98390_DEV1_NAME, 89786a6b9c9STrevor Wu MAX98390_CODEC_DAI))); 89886a6b9c9STrevor Wu 899094e30efSTrevor Wu static const struct sof_conn_stream g_sof_conn_streams[] = { 900094e30efSTrevor Wu { "ETDM2_OUT_BE", "AFE_SOF_DL2", SOF_DMA_DL2, SNDRV_PCM_STREAM_PLAYBACK}, 901094e30efSTrevor Wu { "ETDM1_OUT_BE", "AFE_SOF_DL3", SOF_DMA_DL3, SNDRV_PCM_STREAM_PLAYBACK}, 902094e30efSTrevor Wu { "UL_SRC1_BE", "AFE_SOF_UL4", SOF_DMA_UL4, SNDRV_PCM_STREAM_CAPTURE}, 903094e30efSTrevor Wu { "ETDM2_IN_BE", "AFE_SOF_UL5", SOF_DMA_UL5, SNDRV_PCM_STREAM_CAPTURE}, 904094e30efSTrevor Wu }; 905094e30efSTrevor Wu 906094e30efSTrevor Wu static struct snd_soc_dai_link mt8195_mt6359_dai_links[] = { 907094e30efSTrevor Wu /* FE */ 908094e30efSTrevor Wu [DAI_LINK_DL2_FE] = { 909094e30efSTrevor Wu .name = "DL2_FE", 910094e30efSTrevor Wu .stream_name = "DL2 Playback", 911094e30efSTrevor Wu .trigger = { 912094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 913094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 914094e30efSTrevor Wu }, 915094e30efSTrevor Wu .dynamic = 1, 916094e30efSTrevor Wu .dpcm_playback = 1, 917386fe4ceSAngeloGioacchino Del Regno .ops = &mtk_soundcard_common_playback_ops, 918094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL2_FE), 919094e30efSTrevor Wu }, 920094e30efSTrevor Wu [DAI_LINK_DL3_FE] = { 921094e30efSTrevor Wu .name = "DL3_FE", 922094e30efSTrevor Wu .stream_name = "DL3 Playback", 923094e30efSTrevor Wu .trigger = { 924094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 925094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 926094e30efSTrevor Wu }, 927094e30efSTrevor Wu .dynamic = 1, 928094e30efSTrevor Wu .dpcm_playback = 1, 929386fe4ceSAngeloGioacchino Del Regno .ops = &mtk_soundcard_common_playback_ops, 930094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL3_FE), 931094e30efSTrevor Wu }, 932094e30efSTrevor Wu [DAI_LINK_DL6_FE] = { 933094e30efSTrevor Wu .name = "DL6_FE", 934094e30efSTrevor Wu .stream_name = "DL6 Playback", 935094e30efSTrevor Wu .trigger = { 936094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 937094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 938094e30efSTrevor Wu }, 939094e30efSTrevor Wu .dynamic = 1, 940094e30efSTrevor Wu .dpcm_playback = 1, 941386fe4ceSAngeloGioacchino Del Regno .ops = &mtk_soundcard_common_playback_ops, 942094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL6_FE), 943094e30efSTrevor Wu }, 944094e30efSTrevor Wu [DAI_LINK_DL7_FE] = { 945094e30efSTrevor Wu .name = "DL7_FE", 946094e30efSTrevor Wu .stream_name = "DL7 Playback", 947094e30efSTrevor Wu .trigger = { 948094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_PRE, 949094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_PRE, 950094e30efSTrevor Wu }, 951094e30efSTrevor Wu .dynamic = 1, 952094e30efSTrevor Wu .dpcm_playback = 1, 953094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL7_FE), 954094e30efSTrevor Wu }, 955094e30efSTrevor Wu [DAI_LINK_DL8_FE] = { 956094e30efSTrevor Wu .name = "DL8_FE", 957094e30efSTrevor Wu .stream_name = "DL8 Playback", 958094e30efSTrevor Wu .trigger = { 959094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 960094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 961094e30efSTrevor Wu }, 962094e30efSTrevor Wu .dynamic = 1, 963094e30efSTrevor Wu .dpcm_playback = 1, 964386fe4ceSAngeloGioacchino Del Regno .ops = &mtk_soundcard_common_playback_ops, 965094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL8_FE), 966094e30efSTrevor Wu }, 967094e30efSTrevor Wu [DAI_LINK_DL10_FE] = { 968094e30efSTrevor Wu .name = "DL10_FE", 969094e30efSTrevor Wu .stream_name = "DL10 Playback", 970094e30efSTrevor Wu .trigger = { 971094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 972094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 973094e30efSTrevor Wu }, 974094e30efSTrevor Wu .dynamic = 1, 975094e30efSTrevor Wu .dpcm_playback = 1, 976094e30efSTrevor Wu .ops = &mt8195_hdmitx_dptx_playback_ops, 977094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL10_FE), 978094e30efSTrevor Wu }, 979094e30efSTrevor Wu [DAI_LINK_DL11_FE] = { 980094e30efSTrevor Wu .name = "DL11_FE", 981094e30efSTrevor Wu .stream_name = "DL11 Playback", 982094e30efSTrevor Wu .trigger = { 983094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 984094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 985094e30efSTrevor Wu }, 986094e30efSTrevor Wu .dynamic = 1, 987094e30efSTrevor Wu .dpcm_playback = 1, 988386fe4ceSAngeloGioacchino Del Regno .ops = &mtk_soundcard_common_playback_ops, 989094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL11_FE), 990094e30efSTrevor Wu }, 991094e30efSTrevor Wu [DAI_LINK_UL1_FE] = { 992094e30efSTrevor Wu .name = "UL1_FE", 993094e30efSTrevor Wu .stream_name = "UL1 Capture", 994094e30efSTrevor Wu .trigger = { 995094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_PRE, 996094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_PRE, 997094e30efSTrevor Wu }, 998094e30efSTrevor Wu .dynamic = 1, 999094e30efSTrevor Wu .dpcm_capture = 1, 1000094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL1_FE), 1001094e30efSTrevor Wu }, 1002094e30efSTrevor Wu [DAI_LINK_UL2_FE] = { 1003094e30efSTrevor Wu .name = "UL2_FE", 1004094e30efSTrevor Wu .stream_name = "UL2 Capture", 1005094e30efSTrevor Wu .trigger = { 1006094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1007094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1008094e30efSTrevor Wu }, 1009094e30efSTrevor Wu .dynamic = 1, 1010094e30efSTrevor Wu .dpcm_capture = 1, 1011386fe4ceSAngeloGioacchino Del Regno .ops = &mtk_soundcard_common_capture_ops, 1012094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL2_FE), 1013094e30efSTrevor Wu }, 1014094e30efSTrevor Wu [DAI_LINK_UL3_FE] = { 1015094e30efSTrevor Wu .name = "UL3_FE", 1016094e30efSTrevor Wu .stream_name = "UL3 Capture", 1017094e30efSTrevor Wu .trigger = { 1018094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1019094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1020094e30efSTrevor Wu }, 1021094e30efSTrevor Wu .dynamic = 1, 1022094e30efSTrevor Wu .dpcm_capture = 1, 1023386fe4ceSAngeloGioacchino Del Regno .ops = &mtk_soundcard_common_capture_ops, 1024094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL3_FE), 1025094e30efSTrevor Wu }, 1026094e30efSTrevor Wu [DAI_LINK_UL4_FE] = { 1027094e30efSTrevor Wu .name = "UL4_FE", 1028094e30efSTrevor Wu .stream_name = "UL4 Capture", 1029094e30efSTrevor Wu .trigger = { 1030094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1031094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1032094e30efSTrevor Wu }, 1033094e30efSTrevor Wu .dynamic = 1, 1034094e30efSTrevor Wu .dpcm_capture = 1, 1035386fe4ceSAngeloGioacchino Del Regno .ops = &mtk_soundcard_common_capture_ops, 1036094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL4_FE), 1037094e30efSTrevor Wu }, 1038094e30efSTrevor Wu [DAI_LINK_UL5_FE] = { 1039094e30efSTrevor Wu .name = "UL5_FE", 1040094e30efSTrevor Wu .stream_name = "UL5 Capture", 1041094e30efSTrevor Wu .trigger = { 1042094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1043094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1044094e30efSTrevor Wu }, 1045094e30efSTrevor Wu .dynamic = 1, 1046094e30efSTrevor Wu .dpcm_capture = 1, 1047386fe4ceSAngeloGioacchino Del Regno .ops = &mtk_soundcard_common_capture_ops, 1048094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL5_FE), 1049094e30efSTrevor Wu }, 1050094e30efSTrevor Wu [DAI_LINK_UL6_FE] = { 1051094e30efSTrevor Wu .name = "UL6_FE", 1052094e30efSTrevor Wu .stream_name = "UL6 Capture", 1053094e30efSTrevor Wu .trigger = { 1054094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_PRE, 1055094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_PRE, 1056094e30efSTrevor Wu }, 1057094e30efSTrevor Wu .dynamic = 1, 1058094e30efSTrevor Wu .dpcm_capture = 1, 1059094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL6_FE), 1060094e30efSTrevor Wu }, 1061094e30efSTrevor Wu [DAI_LINK_UL8_FE] = { 1062094e30efSTrevor Wu .name = "UL8_FE", 1063094e30efSTrevor Wu .stream_name = "UL8 Capture", 1064094e30efSTrevor Wu .trigger = { 1065094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1066094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1067094e30efSTrevor Wu }, 1068094e30efSTrevor Wu .dynamic = 1, 1069094e30efSTrevor Wu .dpcm_capture = 1, 1070386fe4ceSAngeloGioacchino Del Regno .ops = &mtk_soundcard_common_capture_ops, 1071094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL8_FE), 1072094e30efSTrevor Wu }, 1073094e30efSTrevor Wu [DAI_LINK_UL9_FE] = { 1074094e30efSTrevor Wu .name = "UL9_FE", 1075094e30efSTrevor Wu .stream_name = "UL9 Capture", 1076094e30efSTrevor Wu .trigger = { 1077094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1078094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1079094e30efSTrevor Wu }, 1080094e30efSTrevor Wu .dynamic = 1, 1081094e30efSTrevor Wu .dpcm_capture = 1, 1082386fe4ceSAngeloGioacchino Del Regno .ops = &mtk_soundcard_common_capture_ops, 1083094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL9_FE), 1084094e30efSTrevor Wu }, 1085094e30efSTrevor Wu [DAI_LINK_UL10_FE] = { 1086094e30efSTrevor Wu .name = "UL10_FE", 1087094e30efSTrevor Wu .stream_name = "UL10 Capture", 1088094e30efSTrevor Wu .trigger = { 1089094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1090094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1091094e30efSTrevor Wu }, 1092094e30efSTrevor Wu .dynamic = 1, 1093094e30efSTrevor Wu .dpcm_capture = 1, 1094386fe4ceSAngeloGioacchino Del Regno .ops = &mtk_soundcard_common_capture_ops, 1095094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL10_FE), 1096094e30efSTrevor Wu }, 1097094e30efSTrevor Wu /* BE */ 1098094e30efSTrevor Wu [DAI_LINK_DL_SRC_BE] = { 1099094e30efSTrevor Wu .name = "DL_SRC_BE", 1100094e30efSTrevor Wu .no_pcm = 1, 1101094e30efSTrevor Wu .dpcm_playback = 1, 1102094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL_SRC_BE), 1103094e30efSTrevor Wu }, 1104094e30efSTrevor Wu [DAI_LINK_DPTX_BE] = { 1105094e30efSTrevor Wu .name = "DPTX_BE", 1106094e30efSTrevor Wu .no_pcm = 1, 1107094e30efSTrevor Wu .dpcm_playback = 1, 1108094e30efSTrevor Wu .ops = &mt8195_dptx_ops, 1109094e30efSTrevor Wu .be_hw_params_fixup = mt8195_dptx_hw_params_fixup, 1110094e30efSTrevor Wu SND_SOC_DAILINK_REG(DPTX_BE), 1111094e30efSTrevor Wu }, 1112094e30efSTrevor Wu [DAI_LINK_ETDM1_IN_BE] = { 1113094e30efSTrevor Wu .name = "ETDM1_IN_BE", 1114094e30efSTrevor Wu .no_pcm = 1, 1115094e30efSTrevor Wu .dai_fmt = SND_SOC_DAIFMT_I2S | 1116094e30efSTrevor Wu SND_SOC_DAIFMT_NB_NF | 1117094e30efSTrevor Wu SND_SOC_DAIFMT_CBS_CFS, 1118094e30efSTrevor Wu .dpcm_capture = 1, 1119094e30efSTrevor Wu SND_SOC_DAILINK_REG(ETDM1_IN_BE), 1120094e30efSTrevor Wu }, 1121094e30efSTrevor Wu [DAI_LINK_ETDM2_IN_BE] = { 1122094e30efSTrevor Wu .name = "ETDM2_IN_BE", 1123094e30efSTrevor Wu .no_pcm = 1, 1124094e30efSTrevor Wu .dai_fmt = SND_SOC_DAIFMT_I2S | 1125094e30efSTrevor Wu SND_SOC_DAIFMT_NB_NF | 1126094e30efSTrevor Wu SND_SOC_DAIFMT_CBS_CFS, 1127094e30efSTrevor Wu .dpcm_capture = 1, 1128094e30efSTrevor Wu .be_hw_params_fixup = mt8195_etdm_hw_params_fixup, 1129094e30efSTrevor Wu SND_SOC_DAILINK_REG(ETDM2_IN_BE), 1130094e30efSTrevor Wu }, 1131094e30efSTrevor Wu [DAI_LINK_ETDM1_OUT_BE] = { 1132094e30efSTrevor Wu .name = "ETDM1_OUT_BE", 1133094e30efSTrevor Wu .no_pcm = 1, 1134094e30efSTrevor Wu .dai_fmt = SND_SOC_DAIFMT_I2S | 1135094e30efSTrevor Wu SND_SOC_DAIFMT_NB_NF | 1136094e30efSTrevor Wu SND_SOC_DAIFMT_CBS_CFS, 1137094e30efSTrevor Wu .dpcm_playback = 1, 1138094e30efSTrevor Wu .be_hw_params_fixup = mt8195_etdm_hw_params_fixup, 1139094e30efSTrevor Wu SND_SOC_DAILINK_REG(ETDM1_OUT_BE), 1140094e30efSTrevor Wu }, 1141094e30efSTrevor Wu [DAI_LINK_ETDM2_OUT_BE] = { 1142094e30efSTrevor Wu .name = "ETDM2_OUT_BE", 1143094e30efSTrevor Wu .no_pcm = 1, 1144094e30efSTrevor Wu .dai_fmt = SND_SOC_DAIFMT_I2S | 1145094e30efSTrevor Wu SND_SOC_DAIFMT_NB_NF | 1146094e30efSTrevor Wu SND_SOC_DAIFMT_CBS_CFS, 1147094e30efSTrevor Wu .dpcm_playback = 1, 1148094e30efSTrevor Wu SND_SOC_DAILINK_REG(ETDM2_OUT_BE), 1149094e30efSTrevor Wu }, 1150094e30efSTrevor Wu [DAI_LINK_ETDM3_OUT_BE] = { 1151094e30efSTrevor Wu .name = "ETDM3_OUT_BE", 1152094e30efSTrevor Wu .no_pcm = 1, 1153094e30efSTrevor Wu .dai_fmt = SND_SOC_DAIFMT_I2S | 1154094e30efSTrevor Wu SND_SOC_DAIFMT_NB_NF | 1155094e30efSTrevor Wu SND_SOC_DAIFMT_CBS_CFS, 1156094e30efSTrevor Wu .dpcm_playback = 1, 1157094e30efSTrevor Wu SND_SOC_DAILINK_REG(ETDM3_OUT_BE), 1158094e30efSTrevor Wu }, 1159094e30efSTrevor Wu [DAI_LINK_PCM1_BE] = { 1160094e30efSTrevor Wu .name = "PCM1_BE", 1161094e30efSTrevor Wu .no_pcm = 1, 1162094e30efSTrevor Wu .dai_fmt = SND_SOC_DAIFMT_I2S | 1163094e30efSTrevor Wu SND_SOC_DAIFMT_NB_NF | 1164094e30efSTrevor Wu SND_SOC_DAIFMT_CBS_CFS, 1165094e30efSTrevor Wu .dpcm_playback = 1, 1166094e30efSTrevor Wu .dpcm_capture = 1, 1167094e30efSTrevor Wu SND_SOC_DAILINK_REG(PCM1_BE), 1168094e30efSTrevor Wu }, 1169094e30efSTrevor Wu [DAI_LINK_UL_SRC1_BE] = { 1170094e30efSTrevor Wu .name = "UL_SRC1_BE", 1171094e30efSTrevor Wu .no_pcm = 1, 1172094e30efSTrevor Wu .dpcm_capture = 1, 1173094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL_SRC1_BE), 1174094e30efSTrevor Wu }, 1175094e30efSTrevor Wu [DAI_LINK_UL_SRC2_BE] = { 1176094e30efSTrevor Wu .name = "UL_SRC2_BE", 1177094e30efSTrevor Wu .no_pcm = 1, 1178094e30efSTrevor Wu .dpcm_capture = 1, 1179094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL_SRC2_BE), 1180094e30efSTrevor Wu }, 1181094e30efSTrevor Wu /* SOF BE */ 1182094e30efSTrevor Wu [DAI_LINK_SOF_DL2_BE] = { 1183094e30efSTrevor Wu .name = "AFE_SOF_DL2", 1184094e30efSTrevor Wu .no_pcm = 1, 1185094e30efSTrevor Wu .dpcm_playback = 1, 118683f1b7f3SYC Hung .ops = &mt8195_sof_be_ops, 1187094e30efSTrevor Wu SND_SOC_DAILINK_REG(AFE_SOF_DL2), 1188094e30efSTrevor Wu }, 1189094e30efSTrevor Wu [DAI_LINK_SOF_DL3_BE] = { 1190094e30efSTrevor Wu .name = "AFE_SOF_DL3", 1191094e30efSTrevor Wu .no_pcm = 1, 1192094e30efSTrevor Wu .dpcm_playback = 1, 119383f1b7f3SYC Hung .ops = &mt8195_sof_be_ops, 1194094e30efSTrevor Wu SND_SOC_DAILINK_REG(AFE_SOF_DL3), 1195094e30efSTrevor Wu }, 1196094e30efSTrevor Wu [DAI_LINK_SOF_UL4_BE] = { 1197094e30efSTrevor Wu .name = "AFE_SOF_UL4", 1198094e30efSTrevor Wu .no_pcm = 1, 1199094e30efSTrevor Wu .dpcm_capture = 1, 120083f1b7f3SYC Hung .ops = &mt8195_sof_be_ops, 1201094e30efSTrevor Wu SND_SOC_DAILINK_REG(AFE_SOF_UL4), 1202094e30efSTrevor Wu }, 1203094e30efSTrevor Wu [DAI_LINK_SOF_UL5_BE] = { 1204094e30efSTrevor Wu .name = "AFE_SOF_UL5", 1205094e30efSTrevor Wu .no_pcm = 1, 1206094e30efSTrevor Wu .dpcm_capture = 1, 120783f1b7f3SYC Hung .ops = &mt8195_sof_be_ops, 1208094e30efSTrevor Wu SND_SOC_DAILINK_REG(AFE_SOF_UL5), 1209094e30efSTrevor Wu }, 1210094e30efSTrevor Wu }; 1211094e30efSTrevor Wu 1212094e30efSTrevor Wu static struct snd_soc_codec_conf rt1011_codec_conf[] = { 1213094e30efSTrevor Wu { 1214094e30efSTrevor Wu .dlc = COMP_CODEC_CONF(RT1011_DEV0_NAME), 1215094e30efSTrevor Wu .name_prefix = "Left", 1216094e30efSTrevor Wu }, 1217094e30efSTrevor Wu { 1218094e30efSTrevor Wu .dlc = COMP_CODEC_CONF(RT1011_DEV1_NAME), 1219094e30efSTrevor Wu .name_prefix = "Right", 1220094e30efSTrevor Wu }, 1221094e30efSTrevor Wu }; 1222094e30efSTrevor Wu 122386a6b9c9STrevor Wu static struct snd_soc_codec_conf max98390_codec_conf[] = { 122486a6b9c9STrevor Wu { 122586a6b9c9STrevor Wu .dlc = COMP_CODEC_CONF(MAX98390_DEV0_NAME), 122686a6b9c9STrevor Wu .name_prefix = "Right", 122786a6b9c9STrevor Wu }, 122886a6b9c9STrevor Wu { 122986a6b9c9STrevor Wu .dlc = COMP_CODEC_CONF(MAX98390_DEV1_NAME), 123086a6b9c9STrevor Wu .name_prefix = "Left", 123186a6b9c9STrevor Wu }, 123286a6b9c9STrevor Wu }; 123386a6b9c9STrevor Wu 1234094e30efSTrevor Wu static struct snd_soc_card mt8195_mt6359_soc_card = { 1235094e30efSTrevor Wu .owner = THIS_MODULE, 1236094e30efSTrevor Wu .dai_link = mt8195_mt6359_dai_links, 1237094e30efSTrevor Wu .num_links = ARRAY_SIZE(mt8195_mt6359_dai_links), 1238094e30efSTrevor Wu .controls = mt8195_mt6359_controls, 1239094e30efSTrevor Wu .num_controls = ARRAY_SIZE(mt8195_mt6359_controls), 1240094e30efSTrevor Wu .dapm_widgets = mt8195_mt6359_widgets, 1241094e30efSTrevor Wu .num_dapm_widgets = ARRAY_SIZE(mt8195_mt6359_widgets), 1242094e30efSTrevor Wu .dapm_routes = mt8195_mt6359_routes, 1243094e30efSTrevor Wu .num_dapm_routes = ARRAY_SIZE(mt8195_mt6359_routes), 1244094e30efSTrevor Wu .set_bias_level_post = mt8195_set_bias_level_post, 1245094e30efSTrevor Wu }; 1246094e30efSTrevor Wu 1247094e30efSTrevor Wu /* fixup the BE DAI link to match any values from topology */ 1248094e30efSTrevor Wu static int mt8195_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, 1249094e30efSTrevor Wu struct snd_pcm_hw_params *params) 1250094e30efSTrevor Wu { 12510caf1120SChunxu Li int ret; 1252094e30efSTrevor Wu 12530caf1120SChunxu Li ret = mtk_sof_dai_link_fixup(rtd, params); 1254094e30efSTrevor Wu 1255094e30efSTrevor Wu if (!strcmp(rtd->dai_link->name, "ETDM2_IN_BE") || 1256094e30efSTrevor Wu !strcmp(rtd->dai_link->name, "ETDM1_OUT_BE")) { 12570caf1120SChunxu Li mt8195_etdm_hw_params_fixup(rtd, params); 1258094e30efSTrevor Wu } 1259094e30efSTrevor Wu 1260094e30efSTrevor Wu return ret; 1261094e30efSTrevor Wu } 1262094e30efSTrevor Wu 12636718e1edSAngeloGioacchino Del Regno static int mt8195_mt6359_legacy_probe(struct mtk_soc_card_data *soc_card_data) 1264094e30efSTrevor Wu { 12656718e1edSAngeloGioacchino Del Regno struct mtk_platform_card_data *card_data = soc_card_data->card_data; 12666718e1edSAngeloGioacchino Del Regno struct snd_soc_card *card = card_data->card; 12676718e1edSAngeloGioacchino Del Regno struct device_node *codec_node, *dp_node, *hdmi_node; 1268094e30efSTrevor Wu struct snd_soc_dai_link *dai_link; 12696718e1edSAngeloGioacchino Del Regno struct device *dev = card->dev; 12706718e1edSAngeloGioacchino Del Regno bool is5682s, init6359 = false; 12716718e1edSAngeloGioacchino Del Regno int i; 1272094e30efSTrevor Wu 1273e70b8dd2SAngeloGioacchino Del Regno if (strstr(card->name, "_5682s")) { 1274e70b8dd2SAngeloGioacchino Del Regno codec_node = of_find_compatible_node(NULL, NULL, "realtek,rt5682s"); 12756718e1edSAngeloGioacchino Del Regno is5682s = true; 1276094e30efSTrevor Wu } else { 12776718e1edSAngeloGioacchino Del Regno codec_node = of_find_compatible_node(NULL, NULL, "realtek,rt5682i"); 12786718e1edSAngeloGioacchino Del Regno is5682s = false; 1279094e30efSTrevor Wu } 1280094e30efSTrevor Wu 12816718e1edSAngeloGioacchino Del Regno dp_node = of_parse_phandle(dev->of_node, "mediatek,dptx-codec", 0); 12826718e1edSAngeloGioacchino Del Regno hdmi_node = of_parse_phandle(dev->of_node, "mediatek,hdmi-codec", 0); 1283094e30efSTrevor Wu 1284094e30efSTrevor Wu for_each_card_prelinks(card, i, dai_link) { 1285094e30efSTrevor Wu if (strcmp(dai_link->name, "DPTX_BE") == 0) { 1286094e30efSTrevor Wu if (!dp_node) { 12876718e1edSAngeloGioacchino Del Regno dev_dbg(dev, "No property 'dptx-codec'\n"); 1288094e30efSTrevor Wu } else { 1289094e30efSTrevor Wu dai_link->codecs->of_node = dp_node; 1290094e30efSTrevor Wu dai_link->codecs->name = NULL; 1291094e30efSTrevor Wu dai_link->codecs->dai_name = "i2s-hifi"; 1292094e30efSTrevor Wu dai_link->init = mt8195_dptx_codec_init; 1293094e30efSTrevor Wu } 1294094e30efSTrevor Wu } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) { 1295094e30efSTrevor Wu if (!hdmi_node) { 12966718e1edSAngeloGioacchino Del Regno dev_dbg(dev, "No property 'hdmi-codec'\n"); 1297094e30efSTrevor Wu } else { 1298094e30efSTrevor Wu dai_link->codecs->of_node = hdmi_node; 1299094e30efSTrevor Wu dai_link->codecs->name = NULL; 1300094e30efSTrevor Wu dai_link->codecs->dai_name = "i2s-hifi"; 1301094e30efSTrevor Wu dai_link->init = mt8195_hdmi_codec_init; 1302094e30efSTrevor Wu } 1303e70b8dd2SAngeloGioacchino Del Regno } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0) { 1304e70b8dd2SAngeloGioacchino Del Regno if (!codec_node) { 13056718e1edSAngeloGioacchino Del Regno dev_err(dev, "Codec not found!\n"); 1306e70b8dd2SAngeloGioacchino Del Regno } else { 1307e70b8dd2SAngeloGioacchino Del Regno dai_link->codecs->of_node = codec_node; 1308e70b8dd2SAngeloGioacchino Del Regno dai_link->codecs->name = NULL; 1309094e30efSTrevor Wu dai_link->codecs->dai_name = 1310094e30efSTrevor Wu is5682s ? RT5682S_CODEC_DAI : RT5682_CODEC_DAI; 1311e70b8dd2SAngeloGioacchino Del Regno dai_link->init = mt8195_rt5682_init; 1312e70b8dd2SAngeloGioacchino Del Regno dai_link->ops = &mt8195_rt5682_etdm_ops; 1313e70b8dd2SAngeloGioacchino Del Regno } 1314e70b8dd2SAngeloGioacchino Del Regno } else if (strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { 1315e70b8dd2SAngeloGioacchino Del Regno if (!codec_node) { 13166718e1edSAngeloGioacchino Del Regno dev_err(dev, "Codec not found!\n"); 1317e70b8dd2SAngeloGioacchino Del Regno } else { 1318e70b8dd2SAngeloGioacchino Del Regno dai_link->codecs->of_node = codec_node; 1319e70b8dd2SAngeloGioacchino Del Regno dai_link->codecs->name = NULL; 1320e70b8dd2SAngeloGioacchino Del Regno dai_link->codecs->dai_name = 1321e70b8dd2SAngeloGioacchino Del Regno is5682s ? RT5682S_CODEC_DAI : RT5682_CODEC_DAI; 1322e70b8dd2SAngeloGioacchino Del Regno dai_link->ops = &mt8195_rt5682_etdm_ops; 1323e70b8dd2SAngeloGioacchino Del Regno } 1324094e30efSTrevor Wu } else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 || 1325094e30efSTrevor Wu strcmp(dai_link->name, "UL_SRC1_BE") == 0 || 1326094e30efSTrevor Wu strcmp(dai_link->name, "UL_SRC2_BE") == 0) { 1327094e30efSTrevor Wu if (!init6359) { 1328094e30efSTrevor Wu dai_link->init = mt8195_mt6359_init; 13296718e1edSAngeloGioacchino Del Regno init6359 = true; 1330094e30efSTrevor Wu } 1331094e30efSTrevor Wu } else if (strcmp(dai_link->name, "ETDM2_OUT_BE") == 0) { 13326718e1edSAngeloGioacchino Del Regno switch (card_data->flags) { 1333094e30efSTrevor Wu case RT1011_SPEAKER_AMP_PRESENT: 1334094e30efSTrevor Wu dai_link->codecs = rt1011_comps; 1335094e30efSTrevor Wu dai_link->num_codecs = ARRAY_SIZE(rt1011_comps); 1336094e30efSTrevor Wu dai_link->init = mt8195_rt1011_init; 1337094e30efSTrevor Wu dai_link->ops = &mt8195_rt1011_etdm_ops; 1338094e30efSTrevor Wu dai_link->be_hw_params_fixup = mt8195_etdm_hw_params_fixup; 1339094e30efSTrevor Wu card->codec_conf = rt1011_codec_conf; 1340094e30efSTrevor Wu card->num_configs = ARRAY_SIZE(rt1011_codec_conf); 1341094e30efSTrevor Wu break; 1342094e30efSTrevor Wu case RT1019_SPEAKER_AMP_PRESENT: 1343094e30efSTrevor Wu dai_link->codecs = rt1019_comps; 1344094e30efSTrevor Wu dai_link->num_codecs = ARRAY_SIZE(rt1019_comps); 1345094e30efSTrevor Wu dai_link->init = mt8195_rt1019_init; 1346094e30efSTrevor Wu break; 134786a6b9c9STrevor Wu case MAX98390_SPEAKER_AMP_PRESENT: 134886a6b9c9STrevor Wu dai_link->codecs = max98390_comps; 134986a6b9c9STrevor Wu dai_link->num_codecs = ARRAY_SIZE(max98390_comps); 135086a6b9c9STrevor Wu dai_link->init = mt8195_max98390_init; 135186a6b9c9STrevor Wu card->codec_conf = max98390_codec_conf; 135286a6b9c9STrevor Wu card->num_configs = ARRAY_SIZE(max98390_codec_conf); 135386a6b9c9STrevor Wu break; 1354094e30efSTrevor Wu default: 1355094e30efSTrevor Wu break; 1356094e30efSTrevor Wu } 1357094e30efSTrevor Wu } 1358094e30efSTrevor Wu } 1359094e30efSTrevor Wu 13606718e1edSAngeloGioacchino Del Regno return 0; 1361094e30efSTrevor Wu } 1362094e30efSTrevor Wu 13636718e1edSAngeloGioacchino Del Regno static int mt8195_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy) 13646718e1edSAngeloGioacchino Del Regno { 13656718e1edSAngeloGioacchino Del Regno struct mtk_platform_card_data *card_data = soc_card_data->card_data; 13666718e1edSAngeloGioacchino Del Regno struct snd_soc_card *card = card_data->card; 13676718e1edSAngeloGioacchino Del Regno struct mt8195_mt6359_priv *mach_priv; 13686718e1edSAngeloGioacchino Del Regno struct snd_soc_dai_link *dai_link; 13696718e1edSAngeloGioacchino Del Regno u8 codec_init = 0; 13706718e1edSAngeloGioacchino Del Regno int i; 13716718e1edSAngeloGioacchino Del Regno 13726718e1edSAngeloGioacchino Del Regno mach_priv = devm_kzalloc(card->dev, sizeof(*mach_priv), GFP_KERNEL); 13736718e1edSAngeloGioacchino Del Regno if (!mach_priv) 13746718e1edSAngeloGioacchino Del Regno return -ENOMEM; 13756718e1edSAngeloGioacchino Del Regno 13766718e1edSAngeloGioacchino Del Regno soc_card_data->mach_priv = mach_priv; 13776718e1edSAngeloGioacchino Del Regno 13786718e1edSAngeloGioacchino Del Regno if (legacy) 13796718e1edSAngeloGioacchino Del Regno return mt8195_mt6359_legacy_probe(soc_card_data); 13806718e1edSAngeloGioacchino Del Regno 13816718e1edSAngeloGioacchino Del Regno for_each_card_prelinks(card, i, dai_link) { 13826718e1edSAngeloGioacchino Del Regno if (strcmp(dai_link->name, "DPTX_BE") == 0) { 13836718e1edSAngeloGioacchino Del Regno if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) 13846718e1edSAngeloGioacchino Del Regno dai_link->init = mt8195_dptx_codec_init; 13856718e1edSAngeloGioacchino Del Regno } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) { 13866718e1edSAngeloGioacchino Del Regno if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) 13876718e1edSAngeloGioacchino Del Regno dai_link->init = mt8195_hdmi_codec_init; 13886718e1edSAngeloGioacchino Del Regno } else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 || 13896718e1edSAngeloGioacchino Del Regno strcmp(dai_link->name, "UL_SRC1_BE") == 0 || 13906718e1edSAngeloGioacchino Del Regno strcmp(dai_link->name, "UL_SRC2_BE") == 0) { 13916718e1edSAngeloGioacchino Del Regno if (!(codec_init & MT6359_CODEC_INIT)) { 13926718e1edSAngeloGioacchino Del Regno dai_link->init = mt8195_mt6359_init; 13936718e1edSAngeloGioacchino Del Regno codec_init |= MT6359_CODEC_INIT; 13946718e1edSAngeloGioacchino Del Regno } 13956718e1edSAngeloGioacchino Del Regno } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 || 13966718e1edSAngeloGioacchino Del Regno strcmp(dai_link->name, "ETDM2_OUT_BE") == 0 || 13976718e1edSAngeloGioacchino Del Regno strcmp(dai_link->name, "ETDM1_IN_BE") == 0 || 13986718e1edSAngeloGioacchino Del Regno strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { 13996718e1edSAngeloGioacchino Del Regno if (!strcmp(dai_link->codecs->dai_name, MAX98390_CODEC_DAI)) { 14006718e1edSAngeloGioacchino Del Regno if (!(codec_init & MAX98390_CODEC_INIT)) { 14016718e1edSAngeloGioacchino Del Regno dai_link->init = mt8195_max98390_init; 14026718e1edSAngeloGioacchino Del Regno codec_init |= MAX98390_CODEC_INIT; 14036718e1edSAngeloGioacchino Del Regno } 14046718e1edSAngeloGioacchino Del Regno } else if (!strcmp(dai_link->codecs->dai_name, RT1011_CODEC_DAI)) { 14056718e1edSAngeloGioacchino Del Regno dai_link->ops = &mt8195_rt1011_etdm_ops; 14066718e1edSAngeloGioacchino Del Regno if (!(codec_init & RT1011_CODEC_INIT)) { 14076718e1edSAngeloGioacchino Del Regno dai_link->init = mt8195_rt1011_init; 14086718e1edSAngeloGioacchino Del Regno codec_init |= RT1011_CODEC_INIT; 14096718e1edSAngeloGioacchino Del Regno } 14106718e1edSAngeloGioacchino Del Regno } else if (!strcmp(dai_link->codecs->dai_name, RT1019_CODEC_DAI)) { 14116718e1edSAngeloGioacchino Del Regno if (!(codec_init & RT1019_CODEC_INIT)) { 14126718e1edSAngeloGioacchino Del Regno dai_link->init = mt8195_rt1019_init; 14136718e1edSAngeloGioacchino Del Regno codec_init |= RT1019_CODEC_INIT; 14146718e1edSAngeloGioacchino Del Regno } 14156718e1edSAngeloGioacchino Del Regno } else if (!strcmp(dai_link->codecs->dai_name, RT5682_CODEC_DAI) || 14166718e1edSAngeloGioacchino Del Regno !strcmp(dai_link->codecs->dai_name, RT5682S_CODEC_DAI)) { 14176718e1edSAngeloGioacchino Del Regno dai_link->ops = &mt8195_rt5682_etdm_ops; 14186718e1edSAngeloGioacchino Del Regno if (!(codec_init & RT5682_CODEC_INIT)) { 14196718e1edSAngeloGioacchino Del Regno dai_link->init = mt8195_rt5682_init; 14206718e1edSAngeloGioacchino Del Regno codec_init |= RT5682_CODEC_INIT; 14216718e1edSAngeloGioacchino Del Regno } 14226718e1edSAngeloGioacchino Del Regno } else { 14236718e1edSAngeloGioacchino Del Regno if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) { 14246718e1edSAngeloGioacchino Del Regno if (!(codec_init & DUMB_CODEC_INIT)) { 14256718e1edSAngeloGioacchino Del Regno dai_link->init = mt8195_dumb_amp_init; 14266718e1edSAngeloGioacchino Del Regno codec_init |= DUMB_CODEC_INIT; 14276718e1edSAngeloGioacchino Del Regno } 14286718e1edSAngeloGioacchino Del Regno } 14296718e1edSAngeloGioacchino Del Regno } 14306718e1edSAngeloGioacchino Del Regno } 14316718e1edSAngeloGioacchino Del Regno } 14326718e1edSAngeloGioacchino Del Regno 14336718e1edSAngeloGioacchino Del Regno return 0; 14346718e1edSAngeloGioacchino Del Regno } 14356718e1edSAngeloGioacchino Del Regno 1436386fe4ceSAngeloGioacchino Del Regno static const unsigned int mt8195_pcm_playback_channels[] = { 2 }; 1437386fe4ceSAngeloGioacchino Del Regno static const unsigned int mt8195_pcm_capture_channels[] = { 1, 2 }; 1438386fe4ceSAngeloGioacchino Del Regno static const unsigned int mt8195_pcm_hdmidp_channels[] = { 2, 4, 6, 8 }; 1439386fe4ceSAngeloGioacchino Del Regno static const unsigned int mt8195_pcm_rates[] = { 48000 }; 1440386fe4ceSAngeloGioacchino Del Regno 1441386fe4ceSAngeloGioacchino Del Regno static const struct snd_pcm_hw_constraint_list mt8195_rate_constraint = { 1442386fe4ceSAngeloGioacchino Del Regno .list = mt8195_pcm_rates, 1443386fe4ceSAngeloGioacchino Del Regno .count = ARRAY_SIZE(mt8195_pcm_rates) 1444386fe4ceSAngeloGioacchino Del Regno }; 1445386fe4ceSAngeloGioacchino Del Regno 1446386fe4ceSAngeloGioacchino Del Regno static const struct mtk_pcm_constraints_data mt8195_pcm_constraints[MTK_CONSTRAINT_HDMIDP + 1] = { 1447386fe4ceSAngeloGioacchino Del Regno [MTK_CONSTRAINT_PLAYBACK] = { 1448386fe4ceSAngeloGioacchino Del Regno .channels = &(const struct snd_pcm_hw_constraint_list) { 1449386fe4ceSAngeloGioacchino Del Regno .list = mt8195_pcm_playback_channels, 1450386fe4ceSAngeloGioacchino Del Regno .count = ARRAY_SIZE(mt8195_pcm_playback_channels) 1451386fe4ceSAngeloGioacchino Del Regno }, 1452386fe4ceSAngeloGioacchino Del Regno .rates = &mt8195_rate_constraint, 1453386fe4ceSAngeloGioacchino Del Regno }, 1454386fe4ceSAngeloGioacchino Del Regno [MTK_CONSTRAINT_CAPTURE] = { 1455386fe4ceSAngeloGioacchino Del Regno .channels = &(const struct snd_pcm_hw_constraint_list) { 1456386fe4ceSAngeloGioacchino Del Regno .list = mt8195_pcm_capture_channels, 1457386fe4ceSAngeloGioacchino Del Regno .count = ARRAY_SIZE(mt8195_pcm_capture_channels) 1458386fe4ceSAngeloGioacchino Del Regno }, 1459386fe4ceSAngeloGioacchino Del Regno .rates = &mt8195_rate_constraint, 1460386fe4ceSAngeloGioacchino Del Regno }, 1461386fe4ceSAngeloGioacchino Del Regno [MTK_CONSTRAINT_HDMIDP] = { 1462386fe4ceSAngeloGioacchino Del Regno .channels = &(const struct snd_pcm_hw_constraint_list) { 1463386fe4ceSAngeloGioacchino Del Regno .list = mt8195_pcm_hdmidp_channels, 1464386fe4ceSAngeloGioacchino Del Regno .count = ARRAY_SIZE(mt8195_pcm_hdmidp_channels) 1465386fe4ceSAngeloGioacchino Del Regno }, 1466386fe4ceSAngeloGioacchino Del Regno .rates = &mt8195_rate_constraint, 1467386fe4ceSAngeloGioacchino Del Regno }, 1468386fe4ceSAngeloGioacchino Del Regno }; 1469386fe4ceSAngeloGioacchino Del Regno 14706718e1edSAngeloGioacchino Del Regno static const struct mtk_sof_priv mt8195_sof_priv = { 14716718e1edSAngeloGioacchino Del Regno .conn_streams = g_sof_conn_streams, 14726718e1edSAngeloGioacchino Del Regno .num_streams = ARRAY_SIZE(g_sof_conn_streams), 14736718e1edSAngeloGioacchino Del Regno .sof_dai_link_fixup = mt8195_dai_link_fixup 1474094e30efSTrevor Wu }; 1475094e30efSTrevor Wu 14766718e1edSAngeloGioacchino Del Regno static const struct mtk_soundcard_pdata mt8195_mt6359_rt1019_rt5682_card = { 14776718e1edSAngeloGioacchino Del Regno .card_name = "mt8195_r1019_5682", 14786718e1edSAngeloGioacchino Del Regno .card_data = &(struct mtk_platform_card_data) { 14796718e1edSAngeloGioacchino Del Regno .card = &mt8195_mt6359_soc_card, 14806718e1edSAngeloGioacchino Del Regno .num_jacks = MT8195_JACK_MAX, 1481386fe4ceSAngeloGioacchino Del Regno .pcm_constraints = mt8195_pcm_constraints, 1482386fe4ceSAngeloGioacchino Del Regno .num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints), 14836718e1edSAngeloGioacchino Del Regno .flags = RT1019_SPEAKER_AMP_PRESENT 14846718e1edSAngeloGioacchino Del Regno }, 14856718e1edSAngeloGioacchino Del Regno .sof_priv = &mt8195_sof_priv, 14866718e1edSAngeloGioacchino Del Regno .soc_probe = mt8195_mt6359_soc_card_probe 1487094e30efSTrevor Wu }; 1488094e30efSTrevor Wu 14896718e1edSAngeloGioacchino Del Regno static const struct mtk_soundcard_pdata mt8195_mt6359_rt1011_rt5682_card = { 14906718e1edSAngeloGioacchino Del Regno .card_name = "mt8195_r1011_5682", 14916718e1edSAngeloGioacchino Del Regno .card_data = &(struct mtk_platform_card_data) { 14926718e1edSAngeloGioacchino Del Regno .card = &mt8195_mt6359_soc_card, 14936718e1edSAngeloGioacchino Del Regno .num_jacks = MT8195_JACK_MAX, 1494386fe4ceSAngeloGioacchino Del Regno .pcm_constraints = mt8195_pcm_constraints, 1495386fe4ceSAngeloGioacchino Del Regno .num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints), 14966718e1edSAngeloGioacchino Del Regno .flags = RT1011_SPEAKER_AMP_PRESENT 14976718e1edSAngeloGioacchino Del Regno }, 14986718e1edSAngeloGioacchino Del Regno .sof_priv = &mt8195_sof_priv, 14996718e1edSAngeloGioacchino Del Regno .soc_probe = mt8195_mt6359_soc_card_probe 15006718e1edSAngeloGioacchino Del Regno }; 15016718e1edSAngeloGioacchino Del Regno 15026718e1edSAngeloGioacchino Del Regno static const struct mtk_soundcard_pdata mt8195_mt6359_max98390_rt5682_card = { 15036718e1edSAngeloGioacchino Del Regno .card_name = "mt8195_m98390_r5682", 15046718e1edSAngeloGioacchino Del Regno .card_data = &(struct mtk_platform_card_data) { 15056718e1edSAngeloGioacchino Del Regno .card = &mt8195_mt6359_soc_card, 15066718e1edSAngeloGioacchino Del Regno .num_jacks = MT8195_JACK_MAX, 1507386fe4ceSAngeloGioacchino Del Regno .pcm_constraints = mt8195_pcm_constraints, 1508386fe4ceSAngeloGioacchino Del Regno .num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints), 15096718e1edSAngeloGioacchino Del Regno .flags = MAX98390_SPEAKER_AMP_PRESENT 15106718e1edSAngeloGioacchino Del Regno }, 15116718e1edSAngeloGioacchino Del Regno .sof_priv = &mt8195_sof_priv, 15126718e1edSAngeloGioacchino Del Regno .soc_probe = mt8195_mt6359_soc_card_probe 151386a6b9c9STrevor Wu }; 151486a6b9c9STrevor Wu 1515094e30efSTrevor Wu static const struct of_device_id mt8195_mt6359_dt_match[] = { 1516094e30efSTrevor Wu { 1517094e30efSTrevor Wu .compatible = "mediatek,mt8195_mt6359_rt1019_rt5682", 1518094e30efSTrevor Wu .data = &mt8195_mt6359_rt1019_rt5682_card, 1519094e30efSTrevor Wu }, 1520094e30efSTrevor Wu { 1521094e30efSTrevor Wu .compatible = "mediatek,mt8195_mt6359_rt1011_rt5682", 1522094e30efSTrevor Wu .data = &mt8195_mt6359_rt1011_rt5682_card, 1523094e30efSTrevor Wu }, 152486a6b9c9STrevor Wu { 152586a6b9c9STrevor Wu .compatible = "mediatek,mt8195_mt6359_max98390_rt5682", 152686a6b9c9STrevor Wu .data = &mt8195_mt6359_max98390_rt5682_card, 152786a6b9c9STrevor Wu }, 1528a2c11c5bSLv Ruyi {}, 1529094e30efSTrevor Wu }; 15306bd8ddf0SNícolas F. R. A. Prado MODULE_DEVICE_TABLE(of, mt8195_mt6359_dt_match); 1531094e30efSTrevor Wu 1532094e30efSTrevor Wu static struct platform_driver mt8195_mt6359_driver = { 1533094e30efSTrevor Wu .driver = { 1534094e30efSTrevor Wu .name = "mt8195_mt6359", 1535094e30efSTrevor Wu .of_match_table = mt8195_mt6359_dt_match, 153614ed837bSAngeloGioacchino Del Regno .pm = &snd_soc_pm_ops, 1537094e30efSTrevor Wu }, 15386718e1edSAngeloGioacchino Del Regno .probe = mtk_soundcard_common_probe, 1539094e30efSTrevor Wu }; 1540094e30efSTrevor Wu 1541094e30efSTrevor Wu module_platform_driver(mt8195_mt6359_driver); 1542094e30efSTrevor Wu 1543094e30efSTrevor Wu /* Module information */ 1544094e30efSTrevor Wu MODULE_DESCRIPTION("MT8195-MT6359 ALSA SoC machine driver"); 1545094e30efSTrevor Wu MODULE_AUTHOR("Trevor Wu <trevor.wu@mediatek.com>"); 1546094e30efSTrevor Wu MODULE_AUTHOR("YC Hung <yc.hung@mediatek.com>"); 1547094e30efSTrevor Wu MODULE_LICENSE("GPL"); 1548094e30efSTrevor Wu MODULE_ALIAS("mt8195_mt6359 soc card"); 1549