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> 13094e30efSTrevor Wu #include <linux/of_device.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" 23094e30efSTrevor Wu #include "mt8195-afe-clk.h" 24094e30efSTrevor Wu #include "mt8195-afe-common.h" 25094e30efSTrevor Wu 26094e30efSTrevor Wu #define RT1011_SPEAKER_AMP_PRESENT BIT(0) 27094e30efSTrevor Wu #define RT1019_SPEAKER_AMP_PRESENT BIT(1) 28094e30efSTrevor Wu 29094e30efSTrevor Wu #define RT1011_CODEC_DAI "rt1011-aif" 30094e30efSTrevor Wu #define RT1011_DEV0_NAME "rt1011.2-0038" 31094e30efSTrevor Wu #define RT1011_DEV1_NAME "rt1011.2-0039" 32094e30efSTrevor Wu 33094e30efSTrevor Wu #define RT1019_CODEC_DAI "HiFi" 34094e30efSTrevor Wu #define RT1019_DEV0_NAME "rt1019p" 35094e30efSTrevor Wu 36094e30efSTrevor Wu #define RT5682_CODEC_DAI "rt5682-aif1" 37094e30efSTrevor Wu #define RT5682_DEV0_NAME "rt5682.2-001a" 38094e30efSTrevor Wu 39094e30efSTrevor Wu #define RT5682S_CODEC_DAI "rt5682s-aif1" 40094e30efSTrevor Wu #define RT5682S_DEV0_NAME "rt5682s.2-001a" 41094e30efSTrevor Wu 42094e30efSTrevor Wu #define SOF_DMA_DL2 "SOF_DMA_DL2" 43094e30efSTrevor Wu #define SOF_DMA_DL3 "SOF_DMA_DL3" 44094e30efSTrevor Wu #define SOF_DMA_UL4 "SOF_DMA_UL4" 45094e30efSTrevor Wu #define SOF_DMA_UL5 "SOF_DMA_UL5" 46094e30efSTrevor Wu 47094e30efSTrevor Wu struct mt8195_card_data { 48094e30efSTrevor Wu const char *name; 49094e30efSTrevor Wu unsigned long quirk; 50094e30efSTrevor Wu }; 51094e30efSTrevor Wu 52094e30efSTrevor Wu struct sof_conn_stream { 53094e30efSTrevor Wu const char *normal_link; 54094e30efSTrevor Wu const char *sof_link; 55094e30efSTrevor Wu const char *sof_dma; 56094e30efSTrevor Wu int stream_dir; 57094e30efSTrevor Wu }; 58094e30efSTrevor Wu 59094e30efSTrevor Wu struct mt8195_mt6359_priv { 60094e30efSTrevor Wu struct snd_soc_jack headset_jack; 61094e30efSTrevor Wu struct snd_soc_jack dp_jack; 62094e30efSTrevor Wu struct snd_soc_jack hdmi_jack; 63094e30efSTrevor Wu struct clk *i2so1_mclk; 64094e30efSTrevor Wu }; 65094e30efSTrevor Wu 66094e30efSTrevor Wu static const struct snd_soc_dapm_widget mt8195_mt6359_widgets[] = { 67*3a0323c2STrevor Wu SND_SOC_DAPM_HP("Headphone", NULL), 68094e30efSTrevor Wu SND_SOC_DAPM_MIC("Headset Mic", NULL), 69094e30efSTrevor Wu SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0), 70094e30efSTrevor Wu SND_SOC_DAPM_MIXER(SOF_DMA_DL3, SND_SOC_NOPM, 0, 0, NULL, 0), 71094e30efSTrevor Wu SND_SOC_DAPM_MIXER(SOF_DMA_UL4, SND_SOC_NOPM, 0, 0, NULL, 0), 72094e30efSTrevor Wu SND_SOC_DAPM_MIXER(SOF_DMA_UL5, SND_SOC_NOPM, 0, 0, NULL, 0), 73094e30efSTrevor Wu }; 74094e30efSTrevor Wu 75094e30efSTrevor Wu static const struct snd_soc_dapm_route mt8195_mt6359_routes[] = { 76094e30efSTrevor Wu /* headset */ 77*3a0323c2STrevor Wu { "Headphone", NULL, "HPOL" }, 78*3a0323c2STrevor Wu { "Headphone", NULL, "HPOR" }, 79094e30efSTrevor Wu { "IN1P", NULL, "Headset Mic" }, 80094e30efSTrevor Wu /* SOF Uplink */ 81094e30efSTrevor Wu {SOF_DMA_UL4, NULL, "O034"}, 82094e30efSTrevor Wu {SOF_DMA_UL4, NULL, "O035"}, 83094e30efSTrevor Wu {SOF_DMA_UL5, NULL, "O036"}, 84094e30efSTrevor Wu {SOF_DMA_UL5, NULL, "O037"}, 85094e30efSTrevor Wu /* SOF Downlink */ 86094e30efSTrevor Wu {"I070", NULL, SOF_DMA_DL2}, 87094e30efSTrevor Wu {"I071", NULL, SOF_DMA_DL2}, 88094e30efSTrevor Wu {"I020", NULL, SOF_DMA_DL3}, 89094e30efSTrevor Wu {"I021", NULL, SOF_DMA_DL3}, 90094e30efSTrevor Wu }; 91094e30efSTrevor Wu 92094e30efSTrevor Wu static const struct snd_kcontrol_new mt8195_mt6359_controls[] = { 93*3a0323c2STrevor Wu SOC_DAPM_PIN_SWITCH("Headphone"), 94094e30efSTrevor Wu SOC_DAPM_PIN_SWITCH("Headset Mic"), 95094e30efSTrevor Wu }; 96094e30efSTrevor Wu 97094e30efSTrevor Wu static const struct snd_soc_dapm_widget mt8195_dual_speaker_widgets[] = { 98*3a0323c2STrevor Wu SND_SOC_DAPM_SPK("Left Spk", NULL), 99*3a0323c2STrevor Wu SND_SOC_DAPM_SPK("Right Spk", NULL), 100094e30efSTrevor Wu }; 101094e30efSTrevor Wu 102094e30efSTrevor Wu static const struct snd_kcontrol_new mt8195_dual_speaker_controls[] = { 103*3a0323c2STrevor Wu SOC_DAPM_PIN_SWITCH("Left Spk"), 104*3a0323c2STrevor Wu SOC_DAPM_PIN_SWITCH("Right Spk"), 105094e30efSTrevor Wu }; 106094e30efSTrevor Wu 107094e30efSTrevor Wu static const struct snd_soc_dapm_widget mt8195_speaker_widgets[] = { 108*3a0323c2STrevor Wu SND_SOC_DAPM_SPK("Ext Spk", NULL), 109094e30efSTrevor Wu }; 110094e30efSTrevor Wu 111094e30efSTrevor Wu static const struct snd_kcontrol_new mt8195_speaker_controls[] = { 112*3a0323c2STrevor Wu SOC_DAPM_PIN_SWITCH("Ext Spk"), 113094e30efSTrevor Wu }; 114094e30efSTrevor Wu 115094e30efSTrevor Wu static const struct snd_soc_dapm_route mt8195_rt1011_routes[] = { 116*3a0323c2STrevor Wu { "Left Spk", NULL, "Left SPO" }, 117*3a0323c2STrevor Wu { "Right Spk", NULL, "Right SPO" }, 118094e30efSTrevor Wu }; 119094e30efSTrevor Wu 120094e30efSTrevor Wu static const struct snd_soc_dapm_route mt8195_rt1019_routes[] = { 121*3a0323c2STrevor Wu { "Ext Spk", NULL, "Speaker" }, 122094e30efSTrevor Wu }; 123094e30efSTrevor Wu 124094e30efSTrevor Wu #define CKSYS_AUD_TOP_CFG 0x032c 125094e30efSTrevor Wu #define CKSYS_AUD_TOP_MON 0x0330 126094e30efSTrevor Wu 127094e30efSTrevor Wu static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd) 128094e30efSTrevor Wu { 129094e30efSTrevor Wu struct snd_soc_component *cmpnt_afe = 130094e30efSTrevor Wu snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 131094e30efSTrevor Wu struct snd_soc_component *cmpnt_codec = 132094e30efSTrevor Wu asoc_rtd_to_codec(rtd, 0)->component; 133094e30efSTrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 134094e30efSTrevor Wu struct mt8195_afe_private *afe_priv = afe->platform_priv; 135094e30efSTrevor Wu struct mtkaif_param *param = &afe_priv->mtkaif_params; 136094e30efSTrevor Wu int chosen_phase_1, chosen_phase_2, chosen_phase_3; 137094e30efSTrevor Wu int prev_cycle_1, prev_cycle_2, prev_cycle_3; 138094e30efSTrevor Wu int test_done_1, test_done_2, test_done_3; 139094e30efSTrevor Wu int cycle_1, cycle_2, cycle_3; 140094e30efSTrevor Wu int mtkaif_chosen_phase[MT8195_MTKAIF_MISO_NUM]; 141094e30efSTrevor Wu int mtkaif_phase_cycle[MT8195_MTKAIF_MISO_NUM]; 142094e30efSTrevor Wu int mtkaif_calibration_num_phase; 143094e30efSTrevor Wu bool mtkaif_calibration_ok; 144094e30efSTrevor Wu unsigned int monitor; 145094e30efSTrevor Wu int counter; 146094e30efSTrevor Wu int phase; 147094e30efSTrevor Wu int i; 148094e30efSTrevor Wu 149094e30efSTrevor Wu dev_dbg(afe->dev, "%s(), start\n", __func__); 150094e30efSTrevor Wu 151094e30efSTrevor Wu param->mtkaif_calibration_ok = false; 152094e30efSTrevor Wu for (i = 0; i < MT8195_MTKAIF_MISO_NUM; i++) { 153094e30efSTrevor Wu param->mtkaif_chosen_phase[i] = -1; 154094e30efSTrevor Wu param->mtkaif_phase_cycle[i] = 0; 155094e30efSTrevor Wu mtkaif_chosen_phase[i] = -1; 156094e30efSTrevor Wu mtkaif_phase_cycle[i] = 0; 157094e30efSTrevor Wu } 158094e30efSTrevor Wu 159094e30efSTrevor Wu if (IS_ERR(afe_priv->topckgen)) { 160094e30efSTrevor Wu dev_info(afe->dev, "%s() Cannot find topckgen controller\n", 161094e30efSTrevor Wu __func__); 162094e30efSTrevor Wu return 0; 163094e30efSTrevor Wu } 164094e30efSTrevor Wu 165094e30efSTrevor Wu pm_runtime_get_sync(afe->dev); 166094e30efSTrevor Wu mt6359_mtkaif_calibration_enable(cmpnt_codec); 167094e30efSTrevor Wu 168094e30efSTrevor Wu /* set test type to synchronizer pulse */ 169094e30efSTrevor Wu regmap_update_bits(afe_priv->topckgen, 170094e30efSTrevor Wu CKSYS_AUD_TOP_CFG, 0xffff, 0x4); 171094e30efSTrevor Wu mtkaif_calibration_num_phase = 42; /* mt6359: 0 ~ 42 */ 172094e30efSTrevor Wu mtkaif_calibration_ok = true; 173094e30efSTrevor Wu 174094e30efSTrevor Wu for (phase = 0; 175094e30efSTrevor Wu phase <= mtkaif_calibration_num_phase && mtkaif_calibration_ok; 176094e30efSTrevor Wu phase++) { 177094e30efSTrevor Wu mt6359_set_mtkaif_calibration_phase(cmpnt_codec, 178094e30efSTrevor Wu phase, phase, phase); 179094e30efSTrevor Wu 180094e30efSTrevor Wu regmap_update_bits(afe_priv->topckgen, 181094e30efSTrevor Wu CKSYS_AUD_TOP_CFG, 0x1, 0x1); 182094e30efSTrevor Wu 183094e30efSTrevor Wu test_done_1 = 0; 184094e30efSTrevor Wu test_done_2 = 0; 185094e30efSTrevor Wu test_done_3 = 0; 186094e30efSTrevor Wu cycle_1 = -1; 187094e30efSTrevor Wu cycle_2 = -1; 188094e30efSTrevor Wu cycle_3 = -1; 189094e30efSTrevor Wu counter = 0; 190094e30efSTrevor Wu while (!(test_done_1 & test_done_2 & test_done_3)) { 191094e30efSTrevor Wu regmap_read(afe_priv->topckgen, 192094e30efSTrevor Wu CKSYS_AUD_TOP_MON, &monitor); 193094e30efSTrevor Wu test_done_1 = (monitor >> 28) & 0x1; 194094e30efSTrevor Wu test_done_2 = (monitor >> 29) & 0x1; 195094e30efSTrevor Wu test_done_3 = (monitor >> 30) & 0x1; 196094e30efSTrevor Wu if (test_done_1 == 1) 197094e30efSTrevor Wu cycle_1 = monitor & 0xf; 198094e30efSTrevor Wu 199094e30efSTrevor Wu if (test_done_2 == 1) 200094e30efSTrevor Wu cycle_2 = (monitor >> 4) & 0xf; 201094e30efSTrevor Wu 202094e30efSTrevor Wu if (test_done_3 == 1) 203094e30efSTrevor Wu cycle_3 = (monitor >> 8) & 0xf; 204094e30efSTrevor Wu 205094e30efSTrevor Wu /* handle if never test done */ 206094e30efSTrevor Wu if (++counter > 10000) { 207094e30efSTrevor Wu dev_info(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n", 208094e30efSTrevor Wu __func__, 209094e30efSTrevor Wu cycle_1, cycle_2, cycle_3, monitor); 210094e30efSTrevor Wu mtkaif_calibration_ok = false; 211094e30efSTrevor Wu break; 212094e30efSTrevor Wu } 213094e30efSTrevor Wu } 214094e30efSTrevor Wu 215094e30efSTrevor Wu if (phase == 0) { 216094e30efSTrevor Wu prev_cycle_1 = cycle_1; 217094e30efSTrevor Wu prev_cycle_2 = cycle_2; 218094e30efSTrevor Wu prev_cycle_3 = cycle_3; 219094e30efSTrevor Wu } 220094e30efSTrevor Wu 221094e30efSTrevor Wu if (cycle_1 != prev_cycle_1 && 222094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] < 0) { 223094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] = phase - 1; 224094e30efSTrevor Wu mtkaif_phase_cycle[MT8195_MTKAIF_MISO_0] = prev_cycle_1; 225094e30efSTrevor Wu } 226094e30efSTrevor Wu 227094e30efSTrevor Wu if (cycle_2 != prev_cycle_2 && 228094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] < 0) { 229094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] = phase - 1; 230094e30efSTrevor Wu mtkaif_phase_cycle[MT8195_MTKAIF_MISO_1] = prev_cycle_2; 231094e30efSTrevor Wu } 232094e30efSTrevor Wu 233094e30efSTrevor Wu if (cycle_3 != prev_cycle_3 && 234094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] < 0) { 235094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] = phase - 1; 236094e30efSTrevor Wu mtkaif_phase_cycle[MT8195_MTKAIF_MISO_2] = prev_cycle_3; 237094e30efSTrevor Wu } 238094e30efSTrevor Wu 239094e30efSTrevor Wu regmap_update_bits(afe_priv->topckgen, 240094e30efSTrevor Wu CKSYS_AUD_TOP_CFG, 0x1, 0x0); 241094e30efSTrevor Wu 242094e30efSTrevor Wu if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] >= 0 && 243094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] >= 0 && 244094e30efSTrevor Wu mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] >= 0) 245094e30efSTrevor Wu break; 246094e30efSTrevor Wu } 247094e30efSTrevor Wu 248094e30efSTrevor Wu if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] < 0) { 249094e30efSTrevor Wu mtkaif_calibration_ok = false; 250094e30efSTrevor Wu chosen_phase_1 = 0; 251094e30efSTrevor Wu } else { 252094e30efSTrevor Wu chosen_phase_1 = mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0]; 253094e30efSTrevor Wu } 254094e30efSTrevor Wu 255094e30efSTrevor Wu if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] < 0) { 256094e30efSTrevor Wu mtkaif_calibration_ok = false; 257094e30efSTrevor Wu chosen_phase_2 = 0; 258094e30efSTrevor Wu } else { 259094e30efSTrevor Wu chosen_phase_2 = mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1]; 260094e30efSTrevor Wu } 261094e30efSTrevor Wu 262094e30efSTrevor Wu if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] < 0) { 263094e30efSTrevor Wu mtkaif_calibration_ok = false; 264094e30efSTrevor Wu chosen_phase_3 = 0; 265094e30efSTrevor Wu } else { 266094e30efSTrevor Wu chosen_phase_3 = mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2]; 267094e30efSTrevor Wu } 268094e30efSTrevor Wu 269094e30efSTrevor Wu mt6359_set_mtkaif_calibration_phase(cmpnt_codec, 270094e30efSTrevor Wu chosen_phase_1, 271094e30efSTrevor Wu chosen_phase_2, 272094e30efSTrevor Wu chosen_phase_3); 273094e30efSTrevor Wu 274094e30efSTrevor Wu mt6359_mtkaif_calibration_disable(cmpnt_codec); 275094e30efSTrevor Wu pm_runtime_put(afe->dev); 276094e30efSTrevor Wu 277094e30efSTrevor Wu param->mtkaif_calibration_ok = mtkaif_calibration_ok; 278094e30efSTrevor Wu param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] = chosen_phase_1; 279094e30efSTrevor Wu param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] = chosen_phase_2; 280094e30efSTrevor Wu param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] = chosen_phase_3; 281094e30efSTrevor Wu for (i = 0; i < MT8195_MTKAIF_MISO_NUM; i++) 282094e30efSTrevor Wu param->mtkaif_phase_cycle[i] = mtkaif_phase_cycle[i]; 283094e30efSTrevor Wu 284094e30efSTrevor Wu dev_info(afe->dev, "%s(), end, calibration ok %d\n", 285094e30efSTrevor Wu __func__, param->mtkaif_calibration_ok); 286094e30efSTrevor Wu 287094e30efSTrevor Wu return 0; 288094e30efSTrevor Wu } 289094e30efSTrevor Wu 290094e30efSTrevor Wu static int mt8195_mt6359_init(struct snd_soc_pcm_runtime *rtd) 291094e30efSTrevor Wu { 292094e30efSTrevor Wu struct snd_soc_component *cmpnt_codec = 293094e30efSTrevor Wu asoc_rtd_to_codec(rtd, 0)->component; 294094e30efSTrevor Wu 295094e30efSTrevor Wu /* set mtkaif protocol */ 296094e30efSTrevor Wu mt6359_set_mtkaif_protocol(cmpnt_codec, 297094e30efSTrevor Wu MT6359_MTKAIF_PROTOCOL_2_CLK_P2); 298094e30efSTrevor Wu 299094e30efSTrevor Wu /* mtkaif calibration */ 300094e30efSTrevor Wu mt8195_mt6359_mtkaif_calibration(rtd); 301094e30efSTrevor Wu 302094e30efSTrevor Wu return 0; 303094e30efSTrevor Wu } 304094e30efSTrevor Wu 305094e30efSTrevor Wu static int mt8195_hdmitx_dptx_startup(struct snd_pcm_substream *substream) 306094e30efSTrevor Wu { 307094e30efSTrevor Wu static const unsigned int rates[] = { 308094e30efSTrevor Wu 48000 309094e30efSTrevor Wu }; 310094e30efSTrevor Wu static const unsigned int channels[] = { 311094e30efSTrevor Wu 2, 4, 6, 8 312094e30efSTrevor Wu }; 313094e30efSTrevor Wu static const struct snd_pcm_hw_constraint_list constraints_rates = { 314094e30efSTrevor Wu .count = ARRAY_SIZE(rates), 315094e30efSTrevor Wu .list = rates, 316094e30efSTrevor Wu .mask = 0, 317094e30efSTrevor Wu }; 318094e30efSTrevor Wu static const struct snd_pcm_hw_constraint_list constraints_channels = { 319094e30efSTrevor Wu .count = ARRAY_SIZE(channels), 320094e30efSTrevor Wu .list = channels, 321094e30efSTrevor Wu .mask = 0, 322094e30efSTrevor Wu }; 323094e30efSTrevor Wu 324094e30efSTrevor Wu struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 325094e30efSTrevor Wu struct snd_pcm_runtime *runtime = substream->runtime; 326094e30efSTrevor Wu int ret; 327094e30efSTrevor Wu 328094e30efSTrevor Wu ret = snd_pcm_hw_constraint_list(runtime, 0, 329094e30efSTrevor Wu SNDRV_PCM_HW_PARAM_RATE, 330094e30efSTrevor Wu &constraints_rates); 331094e30efSTrevor Wu if (ret < 0) { 332094e30efSTrevor Wu dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 333094e30efSTrevor Wu return ret; 334094e30efSTrevor Wu } 335094e30efSTrevor Wu 336094e30efSTrevor Wu ret = snd_pcm_hw_constraint_list(runtime, 0, 337094e30efSTrevor Wu SNDRV_PCM_HW_PARAM_CHANNELS, 338094e30efSTrevor Wu &constraints_channels); 339094e30efSTrevor Wu if (ret < 0) { 340094e30efSTrevor Wu dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 341094e30efSTrevor Wu return ret; 342094e30efSTrevor Wu } 343094e30efSTrevor Wu 344094e30efSTrevor Wu return 0; 345094e30efSTrevor Wu } 346094e30efSTrevor Wu 347094e30efSTrevor Wu static const struct snd_soc_ops mt8195_hdmitx_dptx_playback_ops = { 348094e30efSTrevor Wu .startup = mt8195_hdmitx_dptx_startup, 349094e30efSTrevor Wu }; 350094e30efSTrevor Wu 351094e30efSTrevor Wu static int mt8195_dptx_hw_params(struct snd_pcm_substream *substream, 352094e30efSTrevor Wu struct snd_pcm_hw_params *params) 353094e30efSTrevor Wu { 354094e30efSTrevor Wu struct snd_soc_pcm_runtime *rtd = substream->private_data; 355094e30efSTrevor Wu struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); 356094e30efSTrevor Wu 357094e30efSTrevor Wu return snd_soc_dai_set_sysclk(cpu_dai, 0, params_rate(params) * 256, 358094e30efSTrevor Wu SND_SOC_CLOCK_OUT); 359094e30efSTrevor Wu } 360094e30efSTrevor Wu 361094e30efSTrevor Wu static const struct snd_soc_ops mt8195_dptx_ops = { 362094e30efSTrevor Wu .hw_params = mt8195_dptx_hw_params, 363094e30efSTrevor Wu }; 364094e30efSTrevor Wu 365094e30efSTrevor Wu static int mt8195_dptx_codec_init(struct snd_soc_pcm_runtime *rtd) 366094e30efSTrevor Wu { 367094e30efSTrevor Wu struct mt8195_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card); 368094e30efSTrevor Wu struct snd_soc_component *cmpnt_codec = 369094e30efSTrevor Wu asoc_rtd_to_codec(rtd, 0)->component; 370094e30efSTrevor Wu int ret; 371094e30efSTrevor Wu 372094e30efSTrevor Wu ret = snd_soc_card_jack_new(rtd->card, "DP Jack", SND_JACK_LINEOUT, 373094e30efSTrevor Wu &priv->dp_jack, NULL, 0); 374094e30efSTrevor Wu if (ret) 375094e30efSTrevor Wu return ret; 376094e30efSTrevor Wu 377094e30efSTrevor Wu return snd_soc_component_set_jack(cmpnt_codec, &priv->dp_jack, NULL); 378094e30efSTrevor Wu } 379094e30efSTrevor Wu 380094e30efSTrevor Wu static int mt8195_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd) 381094e30efSTrevor Wu { 382094e30efSTrevor Wu struct mt8195_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card); 383094e30efSTrevor Wu struct snd_soc_component *cmpnt_codec = 384094e30efSTrevor Wu asoc_rtd_to_codec(rtd, 0)->component; 385094e30efSTrevor Wu int ret; 386094e30efSTrevor Wu 387094e30efSTrevor Wu ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, 388094e30efSTrevor Wu &priv->hdmi_jack, NULL, 0); 389094e30efSTrevor Wu if (ret) 390094e30efSTrevor Wu return ret; 391094e30efSTrevor Wu 392094e30efSTrevor Wu return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); 393094e30efSTrevor Wu } 394094e30efSTrevor Wu 395094e30efSTrevor Wu static int mt8195_dptx_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, 396094e30efSTrevor Wu struct snd_pcm_hw_params *params) 397094e30efSTrevor Wu { 398094e30efSTrevor Wu /* fix BE i2s format to S24_LE, clean param mask first */ 399094e30efSTrevor Wu snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), 400094e30efSTrevor Wu 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); 401094e30efSTrevor Wu 402094e30efSTrevor Wu params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); 403094e30efSTrevor Wu 404094e30efSTrevor Wu return 0; 405094e30efSTrevor Wu } 406094e30efSTrevor Wu 407094e30efSTrevor Wu static int mt8195_playback_startup(struct snd_pcm_substream *substream) 408094e30efSTrevor Wu { 409094e30efSTrevor Wu static const unsigned int rates[] = { 410094e30efSTrevor Wu 48000 411094e30efSTrevor Wu }; 412094e30efSTrevor Wu static const unsigned int channels[] = { 413094e30efSTrevor Wu 2 414094e30efSTrevor Wu }; 415094e30efSTrevor Wu static const struct snd_pcm_hw_constraint_list constraints_rates = { 416094e30efSTrevor Wu .count = ARRAY_SIZE(rates), 417094e30efSTrevor Wu .list = rates, 418094e30efSTrevor Wu .mask = 0, 419094e30efSTrevor Wu }; 420094e30efSTrevor Wu static const struct snd_pcm_hw_constraint_list constraints_channels = { 421094e30efSTrevor Wu .count = ARRAY_SIZE(channels), 422094e30efSTrevor Wu .list = channels, 423094e30efSTrevor Wu .mask = 0, 424094e30efSTrevor Wu }; 425094e30efSTrevor Wu 426094e30efSTrevor Wu struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 427094e30efSTrevor Wu struct snd_pcm_runtime *runtime = substream->runtime; 428094e30efSTrevor Wu int ret; 429094e30efSTrevor Wu 430094e30efSTrevor Wu ret = snd_pcm_hw_constraint_list(runtime, 0, 431094e30efSTrevor Wu SNDRV_PCM_HW_PARAM_RATE, 432094e30efSTrevor Wu &constraints_rates); 433094e30efSTrevor Wu if (ret < 0) { 434094e30efSTrevor Wu dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 435094e30efSTrevor Wu return ret; 436094e30efSTrevor Wu } 437094e30efSTrevor Wu 438094e30efSTrevor Wu ret = snd_pcm_hw_constraint_list(runtime, 0, 439094e30efSTrevor Wu SNDRV_PCM_HW_PARAM_CHANNELS, 440094e30efSTrevor Wu &constraints_channels); 441094e30efSTrevor Wu if (ret < 0) { 442094e30efSTrevor Wu dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 443094e30efSTrevor Wu return ret; 444094e30efSTrevor Wu } 445094e30efSTrevor Wu 446094e30efSTrevor Wu return 0; 447094e30efSTrevor Wu } 448094e30efSTrevor Wu 449094e30efSTrevor Wu static const struct snd_soc_ops mt8195_playback_ops = { 450094e30efSTrevor Wu .startup = mt8195_playback_startup, 451094e30efSTrevor Wu }; 452094e30efSTrevor Wu 453094e30efSTrevor Wu static int mt8195_capture_startup(struct snd_pcm_substream *substream) 454094e30efSTrevor Wu { 455094e30efSTrevor Wu static const unsigned int rates[] = { 456094e30efSTrevor Wu 48000 457094e30efSTrevor Wu }; 458094e30efSTrevor Wu static const unsigned int channels[] = { 459094e30efSTrevor Wu 1, 2 460094e30efSTrevor Wu }; 461094e30efSTrevor Wu static const struct snd_pcm_hw_constraint_list constraints_rates = { 462094e30efSTrevor Wu .count = ARRAY_SIZE(rates), 463094e30efSTrevor Wu .list = rates, 464094e30efSTrevor Wu .mask = 0, 465094e30efSTrevor Wu }; 466094e30efSTrevor Wu static const struct snd_pcm_hw_constraint_list constraints_channels = { 467094e30efSTrevor Wu .count = ARRAY_SIZE(channels), 468094e30efSTrevor Wu .list = channels, 469094e30efSTrevor Wu .mask = 0, 470094e30efSTrevor Wu }; 471094e30efSTrevor Wu 472094e30efSTrevor Wu struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 473094e30efSTrevor Wu struct snd_pcm_runtime *runtime = substream->runtime; 474094e30efSTrevor Wu int ret; 475094e30efSTrevor Wu 476094e30efSTrevor Wu ret = snd_pcm_hw_constraint_list(runtime, 0, 477094e30efSTrevor Wu SNDRV_PCM_HW_PARAM_RATE, 478094e30efSTrevor Wu &constraints_rates); 479094e30efSTrevor Wu if (ret < 0) { 480094e30efSTrevor Wu dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 481094e30efSTrevor Wu return ret; 482094e30efSTrevor Wu } 483094e30efSTrevor Wu 484094e30efSTrevor Wu ret = snd_pcm_hw_constraint_list(runtime, 0, 485094e30efSTrevor Wu SNDRV_PCM_HW_PARAM_CHANNELS, 486094e30efSTrevor Wu &constraints_channels); 487094e30efSTrevor Wu if (ret < 0) { 488094e30efSTrevor Wu dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 489094e30efSTrevor Wu return ret; 490094e30efSTrevor Wu } 491094e30efSTrevor Wu 492094e30efSTrevor Wu return 0; 493094e30efSTrevor Wu } 494094e30efSTrevor Wu 495094e30efSTrevor Wu static const struct snd_soc_ops mt8195_capture_ops = { 496094e30efSTrevor Wu .startup = mt8195_capture_startup, 497094e30efSTrevor Wu }; 498094e30efSTrevor Wu 499094e30efSTrevor Wu static int mt8195_rt5682_etdm_hw_params(struct snd_pcm_substream *substream, 500094e30efSTrevor Wu struct snd_pcm_hw_params *params) 501094e30efSTrevor Wu { 502094e30efSTrevor Wu struct snd_soc_pcm_runtime *rtd = substream->private_data; 503094e30efSTrevor Wu struct snd_soc_card *card = rtd->card; 504094e30efSTrevor Wu struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); 505094e30efSTrevor Wu struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 506094e30efSTrevor Wu unsigned int rate = params_rate(params); 507094e30efSTrevor Wu int bitwidth; 508094e30efSTrevor Wu int ret; 509094e30efSTrevor Wu 510094e30efSTrevor Wu bitwidth = snd_pcm_format_width(params_format(params)); 511094e30efSTrevor Wu if (bitwidth < 0) { 512094e30efSTrevor Wu dev_err(card->dev, "invalid bit width: %d\n", bitwidth); 513094e30efSTrevor Wu return bitwidth; 514094e30efSTrevor Wu } 515094e30efSTrevor Wu 516094e30efSTrevor Wu ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth); 517094e30efSTrevor Wu if (ret) { 518094e30efSTrevor Wu dev_err(card->dev, "failed to set tdm slot\n"); 519094e30efSTrevor Wu return ret; 520094e30efSTrevor Wu } 521094e30efSTrevor Wu 522094e30efSTrevor Wu ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1, RT5682_PLL1_S_MCLK, 523094e30efSTrevor Wu rate * 256, rate * 512); 524094e30efSTrevor Wu if (ret) { 525094e30efSTrevor Wu dev_err(card->dev, "failed to set pll\n"); 526094e30efSTrevor Wu return ret; 527094e30efSTrevor Wu } 528094e30efSTrevor Wu 529094e30efSTrevor Wu ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL1, 530094e30efSTrevor Wu rate * 512, SND_SOC_CLOCK_IN); 531094e30efSTrevor Wu if (ret) { 532094e30efSTrevor Wu dev_err(card->dev, "failed to set sysclk\n"); 533094e30efSTrevor Wu return ret; 534094e30efSTrevor Wu } 535094e30efSTrevor Wu 536094e30efSTrevor Wu return snd_soc_dai_set_sysclk(cpu_dai, 0, rate * 256, 537094e30efSTrevor Wu SND_SOC_CLOCK_OUT); 538094e30efSTrevor Wu } 539094e30efSTrevor Wu 540094e30efSTrevor Wu static const struct snd_soc_ops mt8195_rt5682_etdm_ops = { 541094e30efSTrevor Wu .hw_params = mt8195_rt5682_etdm_hw_params, 542094e30efSTrevor Wu }; 543094e30efSTrevor Wu 544094e30efSTrevor Wu static int mt8195_rt5682_init(struct snd_soc_pcm_runtime *rtd) 545094e30efSTrevor Wu { 546094e30efSTrevor Wu struct snd_soc_component *cmpnt_codec = 547094e30efSTrevor Wu asoc_rtd_to_codec(rtd, 0)->component; 548094e30efSTrevor Wu struct mt8195_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card); 549094e30efSTrevor Wu struct snd_soc_jack *jack = &priv->headset_jack; 550094e30efSTrevor Wu struct snd_soc_component *cmpnt_afe = 551094e30efSTrevor Wu snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 552094e30efSTrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 553094e30efSTrevor Wu struct mt8195_afe_private *afe_priv = afe->platform_priv; 554094e30efSTrevor Wu int ret; 555094e30efSTrevor Wu 556094e30efSTrevor Wu priv->i2so1_mclk = afe_priv->clk[MT8195_CLK_TOP_APLL12_DIV2]; 557094e30efSTrevor Wu 558094e30efSTrevor Wu ret = snd_soc_card_jack_new(rtd->card, "Headset Jack", 559094e30efSTrevor Wu SND_JACK_HEADSET | SND_JACK_BTN_0 | 560094e30efSTrevor Wu SND_JACK_BTN_1 | SND_JACK_BTN_2 | 561094e30efSTrevor Wu SND_JACK_BTN_3, 562094e30efSTrevor Wu jack, NULL, 0); 563094e30efSTrevor Wu if (ret) { 564094e30efSTrevor Wu dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); 565094e30efSTrevor Wu return ret; 566094e30efSTrevor Wu } 567094e30efSTrevor Wu 568094e30efSTrevor Wu snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); 569094e30efSTrevor Wu snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); 570094e30efSTrevor Wu snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); 571094e30efSTrevor Wu snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); 572094e30efSTrevor Wu 573094e30efSTrevor Wu ret = snd_soc_component_set_jack(cmpnt_codec, jack, NULL); 574094e30efSTrevor Wu if (ret) { 575094e30efSTrevor Wu dev_err(rtd->dev, "Headset Jack set failed: %d\n", ret); 576094e30efSTrevor Wu return ret; 577094e30efSTrevor Wu } 578094e30efSTrevor Wu 579094e30efSTrevor Wu return 0; 580094e30efSTrevor Wu }; 581094e30efSTrevor Wu 582094e30efSTrevor Wu static int mt8195_rt1011_etdm_hw_params(struct snd_pcm_substream *substream, 583094e30efSTrevor Wu struct snd_pcm_hw_params *params) 584094e30efSTrevor Wu { 585094e30efSTrevor Wu struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 586094e30efSTrevor Wu struct snd_soc_dai *codec_dai; 587094e30efSTrevor Wu struct snd_soc_card *card = rtd->card; 588094e30efSTrevor Wu int srate, i, ret; 589094e30efSTrevor Wu 590094e30efSTrevor Wu srate = params_rate(params); 591094e30efSTrevor Wu 592094e30efSTrevor Wu for_each_rtd_codec_dais(rtd, i, codec_dai) { 593094e30efSTrevor Wu ret = snd_soc_dai_set_pll(codec_dai, 0, RT1011_PLL1_S_BCLK, 594094e30efSTrevor Wu 64 * srate, 256 * srate); 595094e30efSTrevor Wu if (ret < 0) { 596094e30efSTrevor Wu dev_err(card->dev, "codec_dai clock not set\n"); 597094e30efSTrevor Wu return ret; 598094e30efSTrevor Wu } 599094e30efSTrevor Wu 600094e30efSTrevor Wu ret = snd_soc_dai_set_sysclk(codec_dai, 601094e30efSTrevor Wu RT1011_FS_SYS_PRE_S_PLL1, 602094e30efSTrevor Wu 256 * srate, SND_SOC_CLOCK_IN); 603094e30efSTrevor Wu if (ret < 0) { 604094e30efSTrevor Wu dev_err(card->dev, "codec_dai clock not set\n"); 605094e30efSTrevor Wu return ret; 606094e30efSTrevor Wu } 607094e30efSTrevor Wu } 608094e30efSTrevor Wu return 0; 609094e30efSTrevor Wu } 610094e30efSTrevor Wu 611094e30efSTrevor Wu static const struct snd_soc_ops mt8195_rt1011_etdm_ops = { 612094e30efSTrevor Wu .hw_params = mt8195_rt1011_etdm_hw_params, 613094e30efSTrevor Wu }; 614094e30efSTrevor Wu 615094e30efSTrevor Wu static int mt8195_rt1011_init(struct snd_soc_pcm_runtime *rtd) 616094e30efSTrevor Wu { 617094e30efSTrevor Wu struct snd_soc_card *card = rtd->card; 618094e30efSTrevor Wu int ret; 619094e30efSTrevor Wu 620094e30efSTrevor Wu ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets, 621094e30efSTrevor Wu ARRAY_SIZE(mt8195_dual_speaker_widgets)); 622094e30efSTrevor Wu if (ret) { 623094e30efSTrevor Wu dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); 624094e30efSTrevor Wu /* Don't need to add routes if widget addition failed */ 625094e30efSTrevor Wu return ret; 626094e30efSTrevor Wu } 627094e30efSTrevor Wu 628094e30efSTrevor Wu ret = snd_soc_add_card_controls(card, mt8195_dual_speaker_controls, 629094e30efSTrevor Wu ARRAY_SIZE(mt8195_dual_speaker_controls)); 630094e30efSTrevor Wu if (ret) { 631094e30efSTrevor Wu dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); 632094e30efSTrevor Wu return ret; 633094e30efSTrevor Wu } 634094e30efSTrevor Wu 635094e30efSTrevor Wu ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1011_routes, 636094e30efSTrevor Wu ARRAY_SIZE(mt8195_rt1011_routes)); 637094e30efSTrevor Wu if (ret) 638094e30efSTrevor Wu dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); 639094e30efSTrevor Wu 640094e30efSTrevor Wu return ret; 641094e30efSTrevor Wu } 642094e30efSTrevor Wu 643094e30efSTrevor Wu static int mt8195_rt1019_init(struct snd_soc_pcm_runtime *rtd) 644094e30efSTrevor Wu { 645094e30efSTrevor Wu struct snd_soc_card *card = rtd->card; 646094e30efSTrevor Wu int ret; 647094e30efSTrevor Wu 648094e30efSTrevor Wu ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_speaker_widgets, 649094e30efSTrevor Wu ARRAY_SIZE(mt8195_speaker_widgets)); 650094e30efSTrevor Wu if (ret) { 651094e30efSTrevor Wu dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret); 652094e30efSTrevor Wu /* Don't need to add routes if widget addition failed */ 653094e30efSTrevor Wu return ret; 654094e30efSTrevor Wu } 655094e30efSTrevor Wu 656094e30efSTrevor Wu ret = snd_soc_add_card_controls(card, mt8195_speaker_controls, 657094e30efSTrevor Wu ARRAY_SIZE(mt8195_speaker_controls)); 658094e30efSTrevor Wu if (ret) { 659094e30efSTrevor Wu dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); 660094e30efSTrevor Wu return ret; 661094e30efSTrevor Wu } 662094e30efSTrevor Wu 663094e30efSTrevor Wu ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1019_routes, 664094e30efSTrevor Wu ARRAY_SIZE(mt8195_rt1019_routes)); 665094e30efSTrevor Wu if (ret) 666094e30efSTrevor Wu dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret); 667094e30efSTrevor Wu 668094e30efSTrevor Wu return ret; 669094e30efSTrevor Wu } 670094e30efSTrevor Wu 671094e30efSTrevor Wu static int mt8195_etdm_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, 672094e30efSTrevor Wu struct snd_pcm_hw_params *params) 673094e30efSTrevor Wu { 674094e30efSTrevor Wu /* fix BE i2s format to S24_LE, clean param mask first */ 675094e30efSTrevor Wu snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), 676094e30efSTrevor Wu 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); 677094e30efSTrevor Wu 678094e30efSTrevor Wu params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); 679094e30efSTrevor Wu 680094e30efSTrevor Wu return 0; 681094e30efSTrevor Wu } 682094e30efSTrevor Wu 683094e30efSTrevor Wu static int mt8195_set_bias_level_post(struct snd_soc_card *card, 684094e30efSTrevor Wu struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level) 685094e30efSTrevor Wu { 686094e30efSTrevor Wu struct snd_soc_component *component = dapm->component; 687094e30efSTrevor Wu struct mt8195_mt6359_priv *priv = snd_soc_card_get_drvdata(card); 688094e30efSTrevor Wu int ret; 689094e30efSTrevor Wu 690094e30efSTrevor Wu /* 691094e30efSTrevor Wu * It's required to control mclk directly in the set_bias_level_post 692094e30efSTrevor Wu * function for rt5682 and rt5682s codec, or the unexpected pop happens 693094e30efSTrevor Wu * at the end of playback. 694094e30efSTrevor Wu */ 695094e30efSTrevor Wu if (!component || 696094e30efSTrevor Wu (strcmp(component->name, RT5682_DEV0_NAME) && 697094e30efSTrevor Wu strcmp(component->name, RT5682S_DEV0_NAME))) 698094e30efSTrevor Wu return 0; 699094e30efSTrevor Wu 700094e30efSTrevor Wu switch (level) { 701094e30efSTrevor Wu case SND_SOC_BIAS_OFF: 702094e30efSTrevor Wu if (!__clk_is_enabled(priv->i2so1_mclk)) 703094e30efSTrevor Wu return 0; 704094e30efSTrevor Wu 705094e30efSTrevor Wu clk_disable_unprepare(priv->i2so1_mclk); 706094e30efSTrevor Wu dev_dbg(card->dev, "Disable i2so1 mclk\n"); 707094e30efSTrevor Wu break; 708094e30efSTrevor Wu case SND_SOC_BIAS_ON: 709094e30efSTrevor Wu ret = clk_prepare_enable(priv->i2so1_mclk); 710094e30efSTrevor Wu if (ret) { 711094e30efSTrevor Wu dev_err(card->dev, "Can't enable i2so1 mclk: %d\n", ret); 712094e30efSTrevor Wu return ret; 713094e30efSTrevor Wu } 714094e30efSTrevor Wu dev_dbg(card->dev, "Enable i2so1 mclk\n"); 715094e30efSTrevor Wu break; 716094e30efSTrevor Wu default: 717094e30efSTrevor Wu break; 718094e30efSTrevor Wu } 719094e30efSTrevor Wu 720094e30efSTrevor Wu return 0; 721094e30efSTrevor Wu } 722094e30efSTrevor Wu 723094e30efSTrevor Wu enum { 724094e30efSTrevor Wu DAI_LINK_DL2_FE, 725094e30efSTrevor Wu DAI_LINK_DL3_FE, 726094e30efSTrevor Wu DAI_LINK_DL6_FE, 727094e30efSTrevor Wu DAI_LINK_DL7_FE, 728094e30efSTrevor Wu DAI_LINK_DL8_FE, 729094e30efSTrevor Wu DAI_LINK_DL10_FE, 730094e30efSTrevor Wu DAI_LINK_DL11_FE, 731094e30efSTrevor Wu DAI_LINK_UL1_FE, 732094e30efSTrevor Wu DAI_LINK_UL2_FE, 733094e30efSTrevor Wu DAI_LINK_UL3_FE, 734094e30efSTrevor Wu DAI_LINK_UL4_FE, 735094e30efSTrevor Wu DAI_LINK_UL5_FE, 736094e30efSTrevor Wu DAI_LINK_UL6_FE, 737094e30efSTrevor Wu DAI_LINK_UL8_FE, 738094e30efSTrevor Wu DAI_LINK_UL9_FE, 739094e30efSTrevor Wu DAI_LINK_UL10_FE, 740094e30efSTrevor Wu DAI_LINK_DL_SRC_BE, 741094e30efSTrevor Wu DAI_LINK_DPTX_BE, 742094e30efSTrevor Wu DAI_LINK_ETDM1_IN_BE, 743094e30efSTrevor Wu DAI_LINK_ETDM2_IN_BE, 744094e30efSTrevor Wu DAI_LINK_ETDM1_OUT_BE, 745094e30efSTrevor Wu DAI_LINK_ETDM2_OUT_BE, 746094e30efSTrevor Wu DAI_LINK_ETDM3_OUT_BE, 747094e30efSTrevor Wu DAI_LINK_PCM1_BE, 748094e30efSTrevor Wu DAI_LINK_UL_SRC1_BE, 749094e30efSTrevor Wu DAI_LINK_UL_SRC2_BE, 750094e30efSTrevor Wu DAI_LINK_REGULAR_LAST = DAI_LINK_UL_SRC2_BE, 751094e30efSTrevor Wu DAI_LINK_SOF_START, 752094e30efSTrevor Wu DAI_LINK_SOF_DL2_BE = DAI_LINK_SOF_START, 753094e30efSTrevor Wu DAI_LINK_SOF_DL3_BE, 754094e30efSTrevor Wu DAI_LINK_SOF_UL4_BE, 755094e30efSTrevor Wu DAI_LINK_SOF_UL5_BE, 756094e30efSTrevor Wu DAI_LINK_SOF_END = DAI_LINK_SOF_UL5_BE, 757094e30efSTrevor Wu }; 758094e30efSTrevor Wu 759094e30efSTrevor Wu #define DAI_LINK_REGULAR_NUM (DAI_LINK_REGULAR_LAST + 1) 760094e30efSTrevor Wu 761094e30efSTrevor Wu /* FE */ 762094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL2_FE, 763094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL2")), 764094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 765094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 766094e30efSTrevor Wu 767094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL3_FE, 768094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL3")), 769094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 770094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 771094e30efSTrevor Wu 772094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL6_FE, 773094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL6")), 774094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 775094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 776094e30efSTrevor Wu 777094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL7_FE, 778094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL7")), 779094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 780094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 781094e30efSTrevor Wu 782094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL8_FE, 783094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL8")), 784094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 785094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 786094e30efSTrevor Wu 787094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL10_FE, 788094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL10")), 789094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 790094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 791094e30efSTrevor Wu 792094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL11_FE, 793094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL11")), 794094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 795094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 796094e30efSTrevor Wu 797094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL1_FE, 798094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL1")), 799094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 800094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 801094e30efSTrevor Wu 802094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL2_FE, 803094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL2")), 804094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 805094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 806094e30efSTrevor Wu 807094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL3_FE, 808094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL3")), 809094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 810094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 811094e30efSTrevor Wu 812094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL4_FE, 813094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL4")), 814094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 815094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 816094e30efSTrevor Wu 817094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL5_FE, 818094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL5")), 819094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 820094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 821094e30efSTrevor Wu 822094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL6_FE, 823094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL6")), 824094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 825094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 826094e30efSTrevor Wu 827094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL8_FE, 828094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL8")), 829094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 830094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 831094e30efSTrevor Wu 832094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL9_FE, 833094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL9")), 834094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 835094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 836094e30efSTrevor Wu 837094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL10_FE, 838094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL10")), 839094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 840094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 841094e30efSTrevor Wu 842094e30efSTrevor Wu /* BE */ 843094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DL_SRC_BE, 844094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DL_SRC")), 845094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound", 846094e30efSTrevor Wu "mt6359-snd-codec-aif1")), 847094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 848094e30efSTrevor Wu 849094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(DPTX_BE, 850094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("DPTX")), 851094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 852094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 853094e30efSTrevor Wu 854094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(ETDM1_IN_BE, 855094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_IN")), 856094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 857094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 858094e30efSTrevor Wu 859094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(ETDM2_IN_BE, 860094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_IN")), 861094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 862094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 863094e30efSTrevor Wu 864094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(ETDM1_OUT_BE, 865094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_OUT")), 866094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 867094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 868094e30efSTrevor Wu 869094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(ETDM2_OUT_BE, 870094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_OUT")), 871094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 872094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 873094e30efSTrevor Wu 874094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(ETDM3_OUT_BE, 875094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("ETDM3_OUT")), 876094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 877094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 878094e30efSTrevor Wu 879094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(PCM1_BE, 880094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("PCM1")), 881094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 882094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 883094e30efSTrevor Wu 884094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL_SRC1_BE, 885094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC1")), 886094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound", 887094e30efSTrevor Wu "mt6359-snd-codec-aif1"), 888094e30efSTrevor Wu COMP_CODEC("dmic-codec", 889094e30efSTrevor Wu "dmic-hifi")), 890094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 891094e30efSTrevor Wu 892094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(UL_SRC2_BE, 893094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC2")), 894094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound", 895094e30efSTrevor Wu "mt6359-snd-codec-aif2")), 896094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 897094e30efSTrevor Wu 898094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(AFE_SOF_DL2, 899094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL2")), 900094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 901094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 902094e30efSTrevor Wu 903094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(AFE_SOF_DL3, 904094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL3")), 905094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 906094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 907094e30efSTrevor Wu 908094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(AFE_SOF_UL4, 909094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL4")), 910094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 911094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 912094e30efSTrevor Wu 913094e30efSTrevor Wu SND_SOC_DAILINK_DEFS(AFE_SOF_UL5, 914094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL5")), 915094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_DUMMY()), 916094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_EMPTY())); 917094e30efSTrevor Wu 918094e30efSTrevor Wu /* codec */ 919094e30efSTrevor Wu SND_SOC_DAILINK_DEF(rt1019_comps, 920094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CODEC(RT1019_DEV0_NAME, 921094e30efSTrevor Wu RT1019_CODEC_DAI))); 922094e30efSTrevor Wu 923094e30efSTrevor Wu SND_SOC_DAILINK_DEF(rt1011_comps, 924094e30efSTrevor Wu DAILINK_COMP_ARRAY(COMP_CODEC(RT1011_DEV0_NAME, 925094e30efSTrevor Wu RT1011_CODEC_DAI), 926094e30efSTrevor Wu COMP_CODEC(RT1011_DEV1_NAME, 927094e30efSTrevor Wu RT1011_CODEC_DAI))); 928094e30efSTrevor Wu 929094e30efSTrevor Wu static const struct sof_conn_stream g_sof_conn_streams[] = { 930094e30efSTrevor Wu { "ETDM2_OUT_BE", "AFE_SOF_DL2", SOF_DMA_DL2, SNDRV_PCM_STREAM_PLAYBACK}, 931094e30efSTrevor Wu { "ETDM1_OUT_BE", "AFE_SOF_DL3", SOF_DMA_DL3, SNDRV_PCM_STREAM_PLAYBACK}, 932094e30efSTrevor Wu { "UL_SRC1_BE", "AFE_SOF_UL4", SOF_DMA_UL4, SNDRV_PCM_STREAM_CAPTURE}, 933094e30efSTrevor Wu { "ETDM2_IN_BE", "AFE_SOF_UL5", SOF_DMA_UL5, SNDRV_PCM_STREAM_CAPTURE}, 934094e30efSTrevor Wu }; 935094e30efSTrevor Wu 936094e30efSTrevor Wu static struct snd_soc_dai_link mt8195_mt6359_dai_links[] = { 937094e30efSTrevor Wu /* FE */ 938094e30efSTrevor Wu [DAI_LINK_DL2_FE] = { 939094e30efSTrevor Wu .name = "DL2_FE", 940094e30efSTrevor Wu .stream_name = "DL2 Playback", 941094e30efSTrevor Wu .trigger = { 942094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 943094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 944094e30efSTrevor Wu }, 945094e30efSTrevor Wu .dynamic = 1, 946094e30efSTrevor Wu .dpcm_playback = 1, 947094e30efSTrevor Wu .ops = &mt8195_playback_ops, 948094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL2_FE), 949094e30efSTrevor Wu }, 950094e30efSTrevor Wu [DAI_LINK_DL3_FE] = { 951094e30efSTrevor Wu .name = "DL3_FE", 952094e30efSTrevor Wu .stream_name = "DL3 Playback", 953094e30efSTrevor Wu .trigger = { 954094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 955094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 956094e30efSTrevor Wu }, 957094e30efSTrevor Wu .dynamic = 1, 958094e30efSTrevor Wu .dpcm_playback = 1, 959094e30efSTrevor Wu .ops = &mt8195_playback_ops, 960094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL3_FE), 961094e30efSTrevor Wu }, 962094e30efSTrevor Wu [DAI_LINK_DL6_FE] = { 963094e30efSTrevor Wu .name = "DL6_FE", 964094e30efSTrevor Wu .stream_name = "DL6 Playback", 965094e30efSTrevor Wu .trigger = { 966094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 967094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 968094e30efSTrevor Wu }, 969094e30efSTrevor Wu .dynamic = 1, 970094e30efSTrevor Wu .dpcm_playback = 1, 971094e30efSTrevor Wu .ops = &mt8195_playback_ops, 972094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL6_FE), 973094e30efSTrevor Wu }, 974094e30efSTrevor Wu [DAI_LINK_DL7_FE] = { 975094e30efSTrevor Wu .name = "DL7_FE", 976094e30efSTrevor Wu .stream_name = "DL7 Playback", 977094e30efSTrevor Wu .trigger = { 978094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_PRE, 979094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_PRE, 980094e30efSTrevor Wu }, 981094e30efSTrevor Wu .dynamic = 1, 982094e30efSTrevor Wu .dpcm_playback = 1, 983094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL7_FE), 984094e30efSTrevor Wu }, 985094e30efSTrevor Wu [DAI_LINK_DL8_FE] = { 986094e30efSTrevor Wu .name = "DL8_FE", 987094e30efSTrevor Wu .stream_name = "DL8 Playback", 988094e30efSTrevor Wu .trigger = { 989094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 990094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 991094e30efSTrevor Wu }, 992094e30efSTrevor Wu .dynamic = 1, 993094e30efSTrevor Wu .dpcm_playback = 1, 994094e30efSTrevor Wu .ops = &mt8195_playback_ops, 995094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL8_FE), 996094e30efSTrevor Wu }, 997094e30efSTrevor Wu [DAI_LINK_DL10_FE] = { 998094e30efSTrevor Wu .name = "DL10_FE", 999094e30efSTrevor Wu .stream_name = "DL10 Playback", 1000094e30efSTrevor Wu .trigger = { 1001094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1002094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1003094e30efSTrevor Wu }, 1004094e30efSTrevor Wu .dynamic = 1, 1005094e30efSTrevor Wu .dpcm_playback = 1, 1006094e30efSTrevor Wu .ops = &mt8195_hdmitx_dptx_playback_ops, 1007094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL10_FE), 1008094e30efSTrevor Wu }, 1009094e30efSTrevor Wu [DAI_LINK_DL11_FE] = { 1010094e30efSTrevor Wu .name = "DL11_FE", 1011094e30efSTrevor Wu .stream_name = "DL11 Playback", 1012094e30efSTrevor Wu .trigger = { 1013094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1014094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1015094e30efSTrevor Wu }, 1016094e30efSTrevor Wu .dynamic = 1, 1017094e30efSTrevor Wu .dpcm_playback = 1, 1018094e30efSTrevor Wu .ops = &mt8195_playback_ops, 1019094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL11_FE), 1020094e30efSTrevor Wu }, 1021094e30efSTrevor Wu [DAI_LINK_UL1_FE] = { 1022094e30efSTrevor Wu .name = "UL1_FE", 1023094e30efSTrevor Wu .stream_name = "UL1 Capture", 1024094e30efSTrevor Wu .trigger = { 1025094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_PRE, 1026094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_PRE, 1027094e30efSTrevor Wu }, 1028094e30efSTrevor Wu .dynamic = 1, 1029094e30efSTrevor Wu .dpcm_capture = 1, 1030094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL1_FE), 1031094e30efSTrevor Wu }, 1032094e30efSTrevor Wu [DAI_LINK_UL2_FE] = { 1033094e30efSTrevor Wu .name = "UL2_FE", 1034094e30efSTrevor Wu .stream_name = "UL2 Capture", 1035094e30efSTrevor Wu .trigger = { 1036094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1037094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1038094e30efSTrevor Wu }, 1039094e30efSTrevor Wu .dynamic = 1, 1040094e30efSTrevor Wu .dpcm_capture = 1, 1041094e30efSTrevor Wu .ops = &mt8195_capture_ops, 1042094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL2_FE), 1043094e30efSTrevor Wu }, 1044094e30efSTrevor Wu [DAI_LINK_UL3_FE] = { 1045094e30efSTrevor Wu .name = "UL3_FE", 1046094e30efSTrevor Wu .stream_name = "UL3 Capture", 1047094e30efSTrevor Wu .trigger = { 1048094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1049094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1050094e30efSTrevor Wu }, 1051094e30efSTrevor Wu .dynamic = 1, 1052094e30efSTrevor Wu .dpcm_capture = 1, 1053094e30efSTrevor Wu .ops = &mt8195_capture_ops, 1054094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL3_FE), 1055094e30efSTrevor Wu }, 1056094e30efSTrevor Wu [DAI_LINK_UL4_FE] = { 1057094e30efSTrevor Wu .name = "UL4_FE", 1058094e30efSTrevor Wu .stream_name = "UL4 Capture", 1059094e30efSTrevor Wu .trigger = { 1060094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1061094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1062094e30efSTrevor Wu }, 1063094e30efSTrevor Wu .dynamic = 1, 1064094e30efSTrevor Wu .dpcm_capture = 1, 1065094e30efSTrevor Wu .ops = &mt8195_capture_ops, 1066094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL4_FE), 1067094e30efSTrevor Wu }, 1068094e30efSTrevor Wu [DAI_LINK_UL5_FE] = { 1069094e30efSTrevor Wu .name = "UL5_FE", 1070094e30efSTrevor Wu .stream_name = "UL5 Capture", 1071094e30efSTrevor Wu .trigger = { 1072094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1073094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1074094e30efSTrevor Wu }, 1075094e30efSTrevor Wu .dynamic = 1, 1076094e30efSTrevor Wu .dpcm_capture = 1, 1077094e30efSTrevor Wu .ops = &mt8195_capture_ops, 1078094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL5_FE), 1079094e30efSTrevor Wu }, 1080094e30efSTrevor Wu [DAI_LINK_UL6_FE] = { 1081094e30efSTrevor Wu .name = "UL6_FE", 1082094e30efSTrevor Wu .stream_name = "UL6 Capture", 1083094e30efSTrevor Wu .trigger = { 1084094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_PRE, 1085094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_PRE, 1086094e30efSTrevor Wu }, 1087094e30efSTrevor Wu .dynamic = 1, 1088094e30efSTrevor Wu .dpcm_capture = 1, 1089094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL6_FE), 1090094e30efSTrevor Wu }, 1091094e30efSTrevor Wu [DAI_LINK_UL8_FE] = { 1092094e30efSTrevor Wu .name = "UL8_FE", 1093094e30efSTrevor Wu .stream_name = "UL8 Capture", 1094094e30efSTrevor Wu .trigger = { 1095094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1096094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1097094e30efSTrevor Wu }, 1098094e30efSTrevor Wu .dynamic = 1, 1099094e30efSTrevor Wu .dpcm_capture = 1, 1100094e30efSTrevor Wu .ops = &mt8195_capture_ops, 1101094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL8_FE), 1102094e30efSTrevor Wu }, 1103094e30efSTrevor Wu [DAI_LINK_UL9_FE] = { 1104094e30efSTrevor Wu .name = "UL9_FE", 1105094e30efSTrevor Wu .stream_name = "UL9 Capture", 1106094e30efSTrevor Wu .trigger = { 1107094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1108094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1109094e30efSTrevor Wu }, 1110094e30efSTrevor Wu .dynamic = 1, 1111094e30efSTrevor Wu .dpcm_capture = 1, 1112094e30efSTrevor Wu .ops = &mt8195_capture_ops, 1113094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL9_FE), 1114094e30efSTrevor Wu }, 1115094e30efSTrevor Wu [DAI_LINK_UL10_FE] = { 1116094e30efSTrevor Wu .name = "UL10_FE", 1117094e30efSTrevor Wu .stream_name = "UL10 Capture", 1118094e30efSTrevor Wu .trigger = { 1119094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1120094e30efSTrevor Wu SND_SOC_DPCM_TRIGGER_POST, 1121094e30efSTrevor Wu }, 1122094e30efSTrevor Wu .dynamic = 1, 1123094e30efSTrevor Wu .dpcm_capture = 1, 1124094e30efSTrevor Wu .ops = &mt8195_capture_ops, 1125094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL10_FE), 1126094e30efSTrevor Wu }, 1127094e30efSTrevor Wu /* BE */ 1128094e30efSTrevor Wu [DAI_LINK_DL_SRC_BE] = { 1129094e30efSTrevor Wu .name = "DL_SRC_BE", 1130094e30efSTrevor Wu .no_pcm = 1, 1131094e30efSTrevor Wu .dpcm_playback = 1, 1132094e30efSTrevor Wu SND_SOC_DAILINK_REG(DL_SRC_BE), 1133094e30efSTrevor Wu }, 1134094e30efSTrevor Wu [DAI_LINK_DPTX_BE] = { 1135094e30efSTrevor Wu .name = "DPTX_BE", 1136094e30efSTrevor Wu .no_pcm = 1, 1137094e30efSTrevor Wu .dpcm_playback = 1, 1138094e30efSTrevor Wu .ops = &mt8195_dptx_ops, 1139094e30efSTrevor Wu .be_hw_params_fixup = mt8195_dptx_hw_params_fixup, 1140094e30efSTrevor Wu SND_SOC_DAILINK_REG(DPTX_BE), 1141094e30efSTrevor Wu }, 1142094e30efSTrevor Wu [DAI_LINK_ETDM1_IN_BE] = { 1143094e30efSTrevor Wu .name = "ETDM1_IN_BE", 1144094e30efSTrevor Wu .no_pcm = 1, 1145094e30efSTrevor Wu .dai_fmt = SND_SOC_DAIFMT_I2S | 1146094e30efSTrevor Wu SND_SOC_DAIFMT_NB_NF | 1147094e30efSTrevor Wu SND_SOC_DAIFMT_CBS_CFS, 1148094e30efSTrevor Wu .dpcm_capture = 1, 1149094e30efSTrevor Wu SND_SOC_DAILINK_REG(ETDM1_IN_BE), 1150094e30efSTrevor Wu }, 1151094e30efSTrevor Wu [DAI_LINK_ETDM2_IN_BE] = { 1152094e30efSTrevor Wu .name = "ETDM2_IN_BE", 1153094e30efSTrevor Wu .no_pcm = 1, 1154094e30efSTrevor Wu .dai_fmt = SND_SOC_DAIFMT_I2S | 1155094e30efSTrevor Wu SND_SOC_DAIFMT_NB_NF | 1156094e30efSTrevor Wu SND_SOC_DAIFMT_CBS_CFS, 1157094e30efSTrevor Wu .dpcm_capture = 1, 1158094e30efSTrevor Wu .init = mt8195_rt5682_init, 1159094e30efSTrevor Wu .ops = &mt8195_rt5682_etdm_ops, 1160094e30efSTrevor Wu .be_hw_params_fixup = mt8195_etdm_hw_params_fixup, 1161094e30efSTrevor Wu SND_SOC_DAILINK_REG(ETDM2_IN_BE), 1162094e30efSTrevor Wu }, 1163094e30efSTrevor Wu [DAI_LINK_ETDM1_OUT_BE] = { 1164094e30efSTrevor Wu .name = "ETDM1_OUT_BE", 1165094e30efSTrevor Wu .no_pcm = 1, 1166094e30efSTrevor Wu .dai_fmt = SND_SOC_DAIFMT_I2S | 1167094e30efSTrevor Wu SND_SOC_DAIFMT_NB_NF | 1168094e30efSTrevor Wu SND_SOC_DAIFMT_CBS_CFS, 1169094e30efSTrevor Wu .dpcm_playback = 1, 1170094e30efSTrevor Wu .ops = &mt8195_rt5682_etdm_ops, 1171094e30efSTrevor Wu .be_hw_params_fixup = mt8195_etdm_hw_params_fixup, 1172094e30efSTrevor Wu SND_SOC_DAILINK_REG(ETDM1_OUT_BE), 1173094e30efSTrevor Wu }, 1174094e30efSTrevor Wu [DAI_LINK_ETDM2_OUT_BE] = { 1175094e30efSTrevor Wu .name = "ETDM2_OUT_BE", 1176094e30efSTrevor Wu .no_pcm = 1, 1177094e30efSTrevor Wu .dai_fmt = SND_SOC_DAIFMT_I2S | 1178094e30efSTrevor Wu SND_SOC_DAIFMT_NB_NF | 1179094e30efSTrevor Wu SND_SOC_DAIFMT_CBS_CFS, 1180094e30efSTrevor Wu .dpcm_playback = 1, 1181094e30efSTrevor Wu SND_SOC_DAILINK_REG(ETDM2_OUT_BE), 1182094e30efSTrevor Wu }, 1183094e30efSTrevor Wu [DAI_LINK_ETDM3_OUT_BE] = { 1184094e30efSTrevor Wu .name = "ETDM3_OUT_BE", 1185094e30efSTrevor Wu .no_pcm = 1, 1186094e30efSTrevor Wu .dai_fmt = SND_SOC_DAIFMT_I2S | 1187094e30efSTrevor Wu SND_SOC_DAIFMT_NB_NF | 1188094e30efSTrevor Wu SND_SOC_DAIFMT_CBS_CFS, 1189094e30efSTrevor Wu .dpcm_playback = 1, 1190094e30efSTrevor Wu SND_SOC_DAILINK_REG(ETDM3_OUT_BE), 1191094e30efSTrevor Wu }, 1192094e30efSTrevor Wu [DAI_LINK_PCM1_BE] = { 1193094e30efSTrevor Wu .name = "PCM1_BE", 1194094e30efSTrevor Wu .no_pcm = 1, 1195094e30efSTrevor Wu .dai_fmt = SND_SOC_DAIFMT_I2S | 1196094e30efSTrevor Wu SND_SOC_DAIFMT_NB_NF | 1197094e30efSTrevor Wu SND_SOC_DAIFMT_CBS_CFS, 1198094e30efSTrevor Wu .dpcm_playback = 1, 1199094e30efSTrevor Wu .dpcm_capture = 1, 1200094e30efSTrevor Wu SND_SOC_DAILINK_REG(PCM1_BE), 1201094e30efSTrevor Wu }, 1202094e30efSTrevor Wu [DAI_LINK_UL_SRC1_BE] = { 1203094e30efSTrevor Wu .name = "UL_SRC1_BE", 1204094e30efSTrevor Wu .no_pcm = 1, 1205094e30efSTrevor Wu .dpcm_capture = 1, 1206094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL_SRC1_BE), 1207094e30efSTrevor Wu }, 1208094e30efSTrevor Wu [DAI_LINK_UL_SRC2_BE] = { 1209094e30efSTrevor Wu .name = "UL_SRC2_BE", 1210094e30efSTrevor Wu .no_pcm = 1, 1211094e30efSTrevor Wu .dpcm_capture = 1, 1212094e30efSTrevor Wu SND_SOC_DAILINK_REG(UL_SRC2_BE), 1213094e30efSTrevor Wu }, 1214094e30efSTrevor Wu /* SOF BE */ 1215094e30efSTrevor Wu [DAI_LINK_SOF_DL2_BE] = { 1216094e30efSTrevor Wu .name = "AFE_SOF_DL2", 1217094e30efSTrevor Wu .no_pcm = 1, 1218094e30efSTrevor Wu .dpcm_playback = 1, 1219094e30efSTrevor Wu SND_SOC_DAILINK_REG(AFE_SOF_DL2), 1220094e30efSTrevor Wu }, 1221094e30efSTrevor Wu [DAI_LINK_SOF_DL3_BE] = { 1222094e30efSTrevor Wu .name = "AFE_SOF_DL3", 1223094e30efSTrevor Wu .no_pcm = 1, 1224094e30efSTrevor Wu .dpcm_playback = 1, 1225094e30efSTrevor Wu SND_SOC_DAILINK_REG(AFE_SOF_DL3), 1226094e30efSTrevor Wu }, 1227094e30efSTrevor Wu [DAI_LINK_SOF_UL4_BE] = { 1228094e30efSTrevor Wu .name = "AFE_SOF_UL4", 1229094e30efSTrevor Wu .no_pcm = 1, 1230094e30efSTrevor Wu .dpcm_capture = 1, 1231094e30efSTrevor Wu SND_SOC_DAILINK_REG(AFE_SOF_UL4), 1232094e30efSTrevor Wu }, 1233094e30efSTrevor Wu [DAI_LINK_SOF_UL5_BE] = { 1234094e30efSTrevor Wu .name = "AFE_SOF_UL5", 1235094e30efSTrevor Wu .no_pcm = 1, 1236094e30efSTrevor Wu .dpcm_capture = 1, 1237094e30efSTrevor Wu SND_SOC_DAILINK_REG(AFE_SOF_UL5), 1238094e30efSTrevor Wu }, 1239094e30efSTrevor Wu }; 1240094e30efSTrevor Wu 1241094e30efSTrevor Wu static struct snd_soc_codec_conf rt1011_codec_conf[] = { 1242094e30efSTrevor Wu { 1243094e30efSTrevor Wu .dlc = COMP_CODEC_CONF(RT1011_DEV0_NAME), 1244094e30efSTrevor Wu .name_prefix = "Left", 1245094e30efSTrevor Wu }, 1246094e30efSTrevor Wu { 1247094e30efSTrevor Wu .dlc = COMP_CODEC_CONF(RT1011_DEV1_NAME), 1248094e30efSTrevor Wu .name_prefix = "Right", 1249094e30efSTrevor Wu }, 1250094e30efSTrevor Wu }; 1251094e30efSTrevor Wu 1252094e30efSTrevor Wu static struct snd_soc_card mt8195_mt6359_soc_card = { 1253094e30efSTrevor Wu .owner = THIS_MODULE, 1254094e30efSTrevor Wu .dai_link = mt8195_mt6359_dai_links, 1255094e30efSTrevor Wu .num_links = ARRAY_SIZE(mt8195_mt6359_dai_links), 1256094e30efSTrevor Wu .controls = mt8195_mt6359_controls, 1257094e30efSTrevor Wu .num_controls = ARRAY_SIZE(mt8195_mt6359_controls), 1258094e30efSTrevor Wu .dapm_widgets = mt8195_mt6359_widgets, 1259094e30efSTrevor Wu .num_dapm_widgets = ARRAY_SIZE(mt8195_mt6359_widgets), 1260094e30efSTrevor Wu .dapm_routes = mt8195_mt6359_routes, 1261094e30efSTrevor Wu .num_dapm_routes = ARRAY_SIZE(mt8195_mt6359_routes), 1262094e30efSTrevor Wu .set_bias_level_post = mt8195_set_bias_level_post, 1263094e30efSTrevor Wu }; 1264094e30efSTrevor Wu 1265094e30efSTrevor Wu /* fixup the BE DAI link to match any values from topology */ 1266094e30efSTrevor Wu static int mt8195_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, 1267094e30efSTrevor Wu struct snd_pcm_hw_params *params) 1268094e30efSTrevor Wu { 1269094e30efSTrevor Wu struct snd_soc_card *card = rtd->card; 1270094e30efSTrevor Wu struct snd_soc_dai_link *sof_dai_link = NULL; 1271094e30efSTrevor Wu struct snd_soc_pcm_runtime *runtime; 1272094e30efSTrevor Wu struct snd_soc_dai *cpu_dai; 1273094e30efSTrevor Wu int i, j, ret = 0; 1274094e30efSTrevor Wu 1275094e30efSTrevor Wu for (i = 0; i < ARRAY_SIZE(g_sof_conn_streams); i++) { 1276094e30efSTrevor Wu const struct sof_conn_stream *conn = &g_sof_conn_streams[i]; 1277094e30efSTrevor Wu 1278094e30efSTrevor Wu if (strcmp(rtd->dai_link->name, conn->normal_link)) 1279094e30efSTrevor Wu continue; 1280094e30efSTrevor Wu 1281094e30efSTrevor Wu for_each_card_rtds(card, runtime) { 1282094e30efSTrevor Wu if (strcmp(runtime->dai_link->name, conn->sof_link)) 1283094e30efSTrevor Wu continue; 1284094e30efSTrevor Wu 1285094e30efSTrevor Wu for_each_rtd_cpu_dais(runtime, j, cpu_dai) { 1286094e30efSTrevor Wu if (cpu_dai->stream_active[conn->stream_dir] > 0) { 1287094e30efSTrevor Wu sof_dai_link = runtime->dai_link; 1288094e30efSTrevor Wu break; 1289094e30efSTrevor Wu } 1290094e30efSTrevor Wu } 1291094e30efSTrevor Wu break; 1292094e30efSTrevor Wu } 1293094e30efSTrevor Wu 1294094e30efSTrevor Wu if (sof_dai_link && sof_dai_link->be_hw_params_fixup) 1295094e30efSTrevor Wu ret = sof_dai_link->be_hw_params_fixup(runtime, params); 1296094e30efSTrevor Wu 1297094e30efSTrevor Wu break; 1298094e30efSTrevor Wu } 1299094e30efSTrevor Wu 1300094e30efSTrevor Wu if (!strcmp(rtd->dai_link->name, "ETDM2_IN_BE") || 1301094e30efSTrevor Wu !strcmp(rtd->dai_link->name, "ETDM1_OUT_BE")) { 1302094e30efSTrevor Wu mt8195_etdm_hw_params_fixup(runtime, params); 1303094e30efSTrevor Wu } 1304094e30efSTrevor Wu 1305094e30efSTrevor Wu return ret; 1306094e30efSTrevor Wu } 1307094e30efSTrevor Wu 1308094e30efSTrevor Wu static int mt8195_mt6359_card_late_probe(struct snd_soc_card *card) 1309094e30efSTrevor Wu { 1310094e30efSTrevor Wu struct snd_soc_pcm_runtime *runtime; 1311094e30efSTrevor Wu struct snd_soc_component *sof_comp = NULL; 1312094e30efSTrevor Wu int i; 1313094e30efSTrevor Wu 1314094e30efSTrevor Wu /* 1. find sof component */ 1315094e30efSTrevor Wu for_each_card_rtds(card, runtime) { 1316094e30efSTrevor Wu for (i = 0; i < runtime->num_components; i++) { 1317094e30efSTrevor Wu if (!runtime->components[i]->driver->name) 1318094e30efSTrevor Wu continue; 1319094e30efSTrevor Wu if (!strcmp(runtime->components[i]->driver->name, "sof-audio-component")) { 1320094e30efSTrevor Wu sof_comp = runtime->components[i]; 1321094e30efSTrevor Wu break; 1322094e30efSTrevor Wu } 1323094e30efSTrevor Wu } 1324094e30efSTrevor Wu } 1325094e30efSTrevor Wu 1326094e30efSTrevor Wu if (!sof_comp) { 1327094e30efSTrevor Wu dev_info(card->dev, " probe without component\n"); 1328094e30efSTrevor Wu return 0; 1329094e30efSTrevor Wu } 1330094e30efSTrevor Wu /* 2. add route path and fixup callback */ 1331094e30efSTrevor Wu for (i = 0; i < ARRAY_SIZE(g_sof_conn_streams); i++) { 1332094e30efSTrevor Wu const struct sof_conn_stream *conn = &g_sof_conn_streams[i]; 1333094e30efSTrevor Wu struct snd_soc_pcm_runtime *sof_rtd = NULL; 1334094e30efSTrevor Wu struct snd_soc_pcm_runtime *normal_rtd = NULL; 1335094e30efSTrevor Wu struct snd_soc_pcm_runtime *rtd = NULL; 1336094e30efSTrevor Wu 1337094e30efSTrevor Wu for_each_card_rtds(card, rtd) { 1338094e30efSTrevor Wu if (!strcmp(rtd->dai_link->name, conn->sof_link)) { 1339094e30efSTrevor Wu sof_rtd = rtd; 1340094e30efSTrevor Wu continue; 1341094e30efSTrevor Wu } 1342094e30efSTrevor Wu if (!strcmp(rtd->dai_link->name, conn->normal_link)) { 1343094e30efSTrevor Wu normal_rtd = rtd; 1344094e30efSTrevor Wu continue; 1345094e30efSTrevor Wu } 1346094e30efSTrevor Wu if (normal_rtd && sof_rtd) 1347094e30efSTrevor Wu break; 1348094e30efSTrevor Wu } 1349094e30efSTrevor Wu if (normal_rtd && sof_rtd) { 1350094e30efSTrevor Wu int j; 1351094e30efSTrevor Wu struct snd_soc_dai *cpu_dai; 1352094e30efSTrevor Wu 1353094e30efSTrevor Wu for_each_rtd_cpu_dais(sof_rtd, j, cpu_dai) { 1354094e30efSTrevor Wu struct snd_soc_dapm_route route; 1355094e30efSTrevor Wu struct snd_soc_dapm_path *p = NULL; 1356094e30efSTrevor Wu struct snd_soc_dapm_widget *play_widget = 1357094e30efSTrevor Wu cpu_dai->playback_widget; 1358094e30efSTrevor Wu struct snd_soc_dapm_widget *cap_widget = 1359094e30efSTrevor Wu cpu_dai->capture_widget; 1360094e30efSTrevor Wu memset(&route, 0, sizeof(route)); 1361094e30efSTrevor Wu if (conn->stream_dir == SNDRV_PCM_STREAM_CAPTURE && 1362094e30efSTrevor Wu cap_widget) { 1363094e30efSTrevor Wu snd_soc_dapm_widget_for_each_sink_path(cap_widget, p) { 1364094e30efSTrevor Wu route.source = conn->sof_dma; 1365094e30efSTrevor Wu route.sink = p->sink->name; 1366094e30efSTrevor Wu snd_soc_dapm_add_routes(&card->dapm, &route, 1); 1367094e30efSTrevor Wu } 1368094e30efSTrevor Wu } else if (conn->stream_dir == SNDRV_PCM_STREAM_PLAYBACK && 1369094e30efSTrevor Wu play_widget){ 1370094e30efSTrevor Wu snd_soc_dapm_widget_for_each_source_path(play_widget, p) { 1371094e30efSTrevor Wu route.source = p->source->name; 1372094e30efSTrevor Wu route.sink = conn->sof_dma; 1373094e30efSTrevor Wu snd_soc_dapm_add_routes(&card->dapm, &route, 1); 1374094e30efSTrevor Wu } 1375094e30efSTrevor Wu } else { 1376094e30efSTrevor Wu dev_err(cpu_dai->dev, "stream dir and widget not pair\n"); 1377094e30efSTrevor Wu } 1378094e30efSTrevor Wu } 1379094e30efSTrevor Wu normal_rtd->dai_link->be_hw_params_fixup = mt8195_dai_link_fixup; 1380094e30efSTrevor Wu } 1381094e30efSTrevor Wu } 1382094e30efSTrevor Wu 1383094e30efSTrevor Wu return 0; 1384094e30efSTrevor Wu } 1385094e30efSTrevor Wu 1386094e30efSTrevor Wu static int mt8195_dailink_parse_of(struct snd_soc_card *card, struct device_node *np, 1387094e30efSTrevor Wu const char *propname) 1388094e30efSTrevor Wu { 1389094e30efSTrevor Wu struct device *dev = card->dev; 1390094e30efSTrevor Wu struct snd_soc_dai_link *link; 1391094e30efSTrevor Wu const char *dai_name = NULL; 1392094e30efSTrevor Wu int i, j, ret, num_links; 1393094e30efSTrevor Wu 1394094e30efSTrevor Wu num_links = of_property_count_strings(np, "mediatek,dai-link"); 1395094e30efSTrevor Wu 1396094e30efSTrevor Wu if (num_links < 0 || num_links > ARRAY_SIZE(mt8195_mt6359_dai_links)) { 1397094e30efSTrevor Wu dev_dbg(dev, "number of dai-link is invalid\n"); 1398094e30efSTrevor Wu return -EINVAL; 1399094e30efSTrevor Wu } 1400094e30efSTrevor Wu 1401094e30efSTrevor Wu card->dai_link = devm_kcalloc(dev, num_links, sizeof(*link), GFP_KERNEL); 1402094e30efSTrevor Wu if (!card->dai_link) 1403094e30efSTrevor Wu return -ENOMEM; 1404094e30efSTrevor Wu 1405094e30efSTrevor Wu card->num_links = 0; 1406094e30efSTrevor Wu link = card->dai_link; 1407094e30efSTrevor Wu 1408094e30efSTrevor Wu for (i = 0; i < num_links; i++) { 1409094e30efSTrevor Wu ret = of_property_read_string_index(np, propname, i, &dai_name); 1410094e30efSTrevor Wu if (ret) { 1411094e30efSTrevor Wu dev_dbg(dev, "ASoC: Property '%s' index %d could not be read: %d\n", 1412094e30efSTrevor Wu propname, i, ret); 1413094e30efSTrevor Wu return -EINVAL; 1414094e30efSTrevor Wu } 1415094e30efSTrevor Wu 1416094e30efSTrevor Wu for (j = 0; j < ARRAY_SIZE(mt8195_mt6359_dai_links); j++) { 1417094e30efSTrevor Wu if (!strcmp(dai_name, mt8195_mt6359_dai_links[j].name)) { 1418094e30efSTrevor Wu memcpy(link, &mt8195_mt6359_dai_links[j], 1419094e30efSTrevor Wu sizeof(struct snd_soc_dai_link)); 1420094e30efSTrevor Wu link++; 1421094e30efSTrevor Wu card->num_links++; 1422094e30efSTrevor Wu break; 1423094e30efSTrevor Wu } 1424094e30efSTrevor Wu } 1425094e30efSTrevor Wu } 1426094e30efSTrevor Wu 1427094e30efSTrevor Wu if (card->num_links != num_links) 1428094e30efSTrevor Wu return -EINVAL; 1429094e30efSTrevor Wu 1430094e30efSTrevor Wu return 0; 1431094e30efSTrevor Wu } 1432094e30efSTrevor Wu 1433094e30efSTrevor Wu static int mt8195_mt6359_dev_probe(struct platform_device *pdev) 1434094e30efSTrevor Wu { 1435094e30efSTrevor Wu struct snd_soc_card *card = &mt8195_mt6359_soc_card; 1436094e30efSTrevor Wu struct snd_soc_dai_link *dai_link; 1437094e30efSTrevor Wu struct mt8195_mt6359_priv *priv; 1438094e30efSTrevor Wu struct device_node *platform_node, *adsp_node, *dp_node, *hdmi_node; 1439094e30efSTrevor Wu struct mt8195_card_data *card_data; 1440094e30efSTrevor Wu int is5682s = 0; 1441094e30efSTrevor Wu int init6359 = 0; 1442094e30efSTrevor Wu int sof_on = 0; 1443094e30efSTrevor Wu int ret, i; 1444094e30efSTrevor Wu 1445094e30efSTrevor Wu card_data = (struct mt8195_card_data *)of_device_get_match_data(&pdev->dev); 1446094e30efSTrevor Wu card->dev = &pdev->dev; 1447094e30efSTrevor Wu 1448094e30efSTrevor Wu ret = snd_soc_of_parse_card_name(card, "model"); 1449094e30efSTrevor Wu if (ret) { 1450094e30efSTrevor Wu dev_err(&pdev->dev, "%s new card name parsing error %d\n", 1451094e30efSTrevor Wu __func__, ret); 1452094e30efSTrevor Wu return ret; 1453094e30efSTrevor Wu } 1454094e30efSTrevor Wu 1455094e30efSTrevor Wu if (!card->name) 1456094e30efSTrevor Wu card->name = card_data->name; 1457094e30efSTrevor Wu 1458094e30efSTrevor Wu if (strstr(card->name, "_5682s")) 1459094e30efSTrevor Wu is5682s = 1; 1460094e30efSTrevor Wu 1461094e30efSTrevor Wu priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 1462094e30efSTrevor Wu if (!priv) 1463094e30efSTrevor Wu return -ENOMEM; 1464094e30efSTrevor Wu 1465094e30efSTrevor Wu if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) { 1466094e30efSTrevor Wu ret = mt8195_dailink_parse_of(card, pdev->dev.of_node, 1467094e30efSTrevor Wu "mediatek,dai-link"); 1468094e30efSTrevor Wu if (ret) { 1469094e30efSTrevor Wu dev_dbg(&pdev->dev, "Parse dai-link fail\n"); 1470094e30efSTrevor Wu return -EINVAL; 1471094e30efSTrevor Wu } 1472094e30efSTrevor Wu } else { 1473094e30efSTrevor Wu if (!sof_on) 1474094e30efSTrevor Wu card->num_links = DAI_LINK_REGULAR_NUM; 1475094e30efSTrevor Wu } 1476094e30efSTrevor Wu 1477094e30efSTrevor Wu platform_node = of_parse_phandle(pdev->dev.of_node, 1478094e30efSTrevor Wu "mediatek,platform", 0); 1479094e30efSTrevor Wu if (!platform_node) { 1480094e30efSTrevor Wu dev_dbg(&pdev->dev, "Property 'platform' missing or invalid\n"); 1481094e30efSTrevor Wu return -EINVAL; 1482094e30efSTrevor Wu } 1483094e30efSTrevor Wu 1484094e30efSTrevor Wu adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); 1485094e30efSTrevor Wu if (adsp_node) 1486094e30efSTrevor Wu sof_on = 1; 1487094e30efSTrevor Wu 1488094e30efSTrevor Wu dp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,dptx-codec", 0); 1489094e30efSTrevor Wu hdmi_node = of_parse_phandle(pdev->dev.of_node, 1490094e30efSTrevor Wu "mediatek,hdmi-codec", 0); 1491094e30efSTrevor Wu 1492094e30efSTrevor Wu for_each_card_prelinks(card, i, dai_link) { 1493094e30efSTrevor Wu if (!dai_link->platforms->name) { 1494094e30efSTrevor Wu if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && sof_on) 1495094e30efSTrevor Wu dai_link->platforms->of_node = adsp_node; 1496094e30efSTrevor Wu else 1497094e30efSTrevor Wu dai_link->platforms->of_node = platform_node; 1498094e30efSTrevor Wu } 1499094e30efSTrevor Wu 1500094e30efSTrevor Wu if (strcmp(dai_link->name, "DPTX_BE") == 0) { 1501094e30efSTrevor Wu if (!dp_node) { 1502094e30efSTrevor Wu dev_dbg(&pdev->dev, "No property 'dptx-codec'\n"); 1503094e30efSTrevor Wu } else { 1504094e30efSTrevor Wu dai_link->codecs->of_node = dp_node; 1505094e30efSTrevor Wu dai_link->codecs->name = NULL; 1506094e30efSTrevor Wu dai_link->codecs->dai_name = "i2s-hifi"; 1507094e30efSTrevor Wu dai_link->init = mt8195_dptx_codec_init; 1508094e30efSTrevor Wu } 1509094e30efSTrevor Wu } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) { 1510094e30efSTrevor Wu if (!hdmi_node) { 1511094e30efSTrevor Wu dev_dbg(&pdev->dev, "No property 'hdmi-codec'\n"); 1512094e30efSTrevor Wu } else { 1513094e30efSTrevor Wu dai_link->codecs->of_node = hdmi_node; 1514094e30efSTrevor Wu dai_link->codecs->name = NULL; 1515094e30efSTrevor Wu dai_link->codecs->dai_name = "i2s-hifi"; 1516094e30efSTrevor Wu dai_link->init = mt8195_hdmi_codec_init; 1517094e30efSTrevor Wu } 1518094e30efSTrevor Wu } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 || 1519094e30efSTrevor Wu strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { 1520094e30efSTrevor Wu dai_link->codecs->name = 1521094e30efSTrevor Wu is5682s ? RT5682S_DEV0_NAME : RT5682_DEV0_NAME; 1522094e30efSTrevor Wu dai_link->codecs->dai_name = 1523094e30efSTrevor Wu is5682s ? RT5682S_CODEC_DAI : RT5682_CODEC_DAI; 1524094e30efSTrevor Wu } else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 || 1525094e30efSTrevor Wu strcmp(dai_link->name, "UL_SRC1_BE") == 0 || 1526094e30efSTrevor Wu strcmp(dai_link->name, "UL_SRC2_BE") == 0) { 1527094e30efSTrevor Wu if (!init6359) { 1528094e30efSTrevor Wu dai_link->init = mt8195_mt6359_init; 1529094e30efSTrevor Wu init6359 = 1; 1530094e30efSTrevor Wu } 1531094e30efSTrevor Wu } else if (strcmp(dai_link->name, "ETDM2_OUT_BE") == 0) { 1532094e30efSTrevor Wu switch (card_data->quirk) { 1533094e30efSTrevor Wu case RT1011_SPEAKER_AMP_PRESENT: 1534094e30efSTrevor Wu dai_link->codecs = rt1011_comps; 1535094e30efSTrevor Wu dai_link->num_codecs = ARRAY_SIZE(rt1011_comps); 1536094e30efSTrevor Wu dai_link->init = mt8195_rt1011_init; 1537094e30efSTrevor Wu dai_link->ops = &mt8195_rt1011_etdm_ops; 1538094e30efSTrevor Wu dai_link->be_hw_params_fixup = mt8195_etdm_hw_params_fixup; 1539094e30efSTrevor Wu card->codec_conf = rt1011_codec_conf; 1540094e30efSTrevor Wu card->num_configs = ARRAY_SIZE(rt1011_codec_conf); 1541094e30efSTrevor Wu break; 1542094e30efSTrevor Wu case RT1019_SPEAKER_AMP_PRESENT: 1543094e30efSTrevor Wu dai_link->codecs = rt1019_comps; 1544094e30efSTrevor Wu dai_link->num_codecs = ARRAY_SIZE(rt1019_comps); 1545094e30efSTrevor Wu dai_link->init = mt8195_rt1019_init; 1546094e30efSTrevor Wu break; 1547094e30efSTrevor Wu default: 1548094e30efSTrevor Wu break; 1549094e30efSTrevor Wu } 1550094e30efSTrevor Wu } 1551094e30efSTrevor Wu } 1552094e30efSTrevor Wu 1553094e30efSTrevor Wu if (sof_on) 1554094e30efSTrevor Wu card->late_probe = mt8195_mt6359_card_late_probe; 1555094e30efSTrevor Wu 1556094e30efSTrevor Wu snd_soc_card_set_drvdata(card, priv); 1557094e30efSTrevor Wu 1558094e30efSTrevor Wu ret = devm_snd_soc_register_card(&pdev->dev, card); 1559094e30efSTrevor Wu 1560094e30efSTrevor Wu of_node_put(platform_node); 1561094e30efSTrevor Wu of_node_put(adsp_node); 1562094e30efSTrevor Wu of_node_put(dp_node); 1563094e30efSTrevor Wu of_node_put(hdmi_node); 1564094e30efSTrevor Wu return ret; 1565094e30efSTrevor Wu } 1566094e30efSTrevor Wu 1567094e30efSTrevor Wu static struct mt8195_card_data mt8195_mt6359_rt1019_rt5682_card = { 1568094e30efSTrevor Wu .name = "mt8195_r1019_5682", 1569094e30efSTrevor Wu .quirk = RT1019_SPEAKER_AMP_PRESENT, 1570094e30efSTrevor Wu }; 1571094e30efSTrevor Wu 1572094e30efSTrevor Wu static struct mt8195_card_data mt8195_mt6359_rt1011_rt5682_card = { 1573094e30efSTrevor Wu .name = "mt8195_r1011_5682", 1574094e30efSTrevor Wu .quirk = RT1011_SPEAKER_AMP_PRESENT, 1575094e30efSTrevor Wu }; 1576094e30efSTrevor Wu 1577094e30efSTrevor Wu #ifdef CONFIG_OF 1578094e30efSTrevor Wu static const struct of_device_id mt8195_mt6359_dt_match[] = { 1579094e30efSTrevor Wu { 1580094e30efSTrevor Wu .compatible = "mediatek,mt8195_mt6359_rt1019_rt5682", 1581094e30efSTrevor Wu .data = &mt8195_mt6359_rt1019_rt5682_card, 1582094e30efSTrevor Wu }, 1583094e30efSTrevor Wu { 1584094e30efSTrevor Wu .compatible = "mediatek,mt8195_mt6359_rt1011_rt5682", 1585094e30efSTrevor Wu .data = &mt8195_mt6359_rt1011_rt5682_card, 1586094e30efSTrevor Wu }, 1587094e30efSTrevor Wu }; 1588094e30efSTrevor Wu #endif 1589094e30efSTrevor Wu 1590094e30efSTrevor Wu static const struct dev_pm_ops mt8195_mt6359_pm_ops = { 1591094e30efSTrevor Wu .poweroff = snd_soc_poweroff, 1592094e30efSTrevor Wu .restore = snd_soc_resume, 1593094e30efSTrevor Wu }; 1594094e30efSTrevor Wu 1595094e30efSTrevor Wu static struct platform_driver mt8195_mt6359_driver = { 1596094e30efSTrevor Wu .driver = { 1597094e30efSTrevor Wu .name = "mt8195_mt6359", 1598094e30efSTrevor Wu #ifdef CONFIG_OF 1599094e30efSTrevor Wu .of_match_table = mt8195_mt6359_dt_match, 1600094e30efSTrevor Wu #endif 1601094e30efSTrevor Wu .pm = &mt8195_mt6359_pm_ops, 1602094e30efSTrevor Wu }, 1603094e30efSTrevor Wu .probe = mt8195_mt6359_dev_probe, 1604094e30efSTrevor Wu }; 1605094e30efSTrevor Wu 1606094e30efSTrevor Wu module_platform_driver(mt8195_mt6359_driver); 1607094e30efSTrevor Wu 1608094e30efSTrevor Wu /* Module information */ 1609094e30efSTrevor Wu MODULE_DESCRIPTION("MT8195-MT6359 ALSA SoC machine driver"); 1610094e30efSTrevor Wu MODULE_AUTHOR("Trevor Wu <trevor.wu@mediatek.com>"); 1611094e30efSTrevor Wu MODULE_AUTHOR("YC Hung <yc.hung@mediatek.com>"); 1612094e30efSTrevor Wu MODULE_LICENSE("GPL"); 1613094e30efSTrevor Wu MODULE_ALIAS("mt8195_mt6359 soc card"); 1614