cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

mt8195-mt6359.c (45834B)


      1// SPDX-License-Identifier: GPL-2.0
      2/*
      3 * mt8195-mt6359.c  --
      4 *	MT8195-MT6359 ALSA SoC machine driver code
      5 *
      6 * Copyright (c) 2022 MediaTek Inc.
      7 * Author: Trevor Wu <trevor.wu@mediatek.com>
      8 *	   YC Hung <yc.hung@mediatek.com>
      9 */
     10
     11#include <linux/input.h>
     12#include <linux/module.h>
     13#include <linux/of_device.h>
     14#include <linux/pm_runtime.h>
     15#include <sound/jack.h>
     16#include <sound/pcm_params.h>
     17#include <sound/rt5682.h>
     18#include <sound/soc.h>
     19#include "../../codecs/mt6359.h"
     20#include "../../codecs/rt1011.h"
     21#include "../../codecs/rt5682.h"
     22#include "../common/mtk-afe-platform-driver.h"
     23#include "mt8195-afe-clk.h"
     24#include "mt8195-afe-common.h"
     25
     26#define RT1011_SPEAKER_AMP_PRESENT		BIT(0)
     27#define RT1019_SPEAKER_AMP_PRESENT		BIT(1)
     28#define MAX98390_SPEAKER_AMP_PRESENT		BIT(2)
     29
     30#define RT1011_CODEC_DAI	"rt1011-aif"
     31#define RT1011_DEV0_NAME	"rt1011.2-0038"
     32#define RT1011_DEV1_NAME	"rt1011.2-0039"
     33
     34#define RT1019_CODEC_DAI	"HiFi"
     35#define RT1019_DEV0_NAME	"rt1019p"
     36
     37#define MAX98390_CODEC_DAI	"max98390-aif1"
     38#define MAX98390_DEV0_NAME	"max98390.2-0038" /* right */
     39#define MAX98390_DEV1_NAME	"max98390.2-0039" /* left */
     40
     41#define RT5682_CODEC_DAI	"rt5682-aif1"
     42#define RT5682_DEV0_NAME	"rt5682.2-001a"
     43
     44#define RT5682S_CODEC_DAI	"rt5682s-aif1"
     45#define RT5682S_DEV0_NAME	"rt5682s.2-001a"
     46
     47#define SOF_DMA_DL2 "SOF_DMA_DL2"
     48#define SOF_DMA_DL3 "SOF_DMA_DL3"
     49#define SOF_DMA_UL4 "SOF_DMA_UL4"
     50#define SOF_DMA_UL5 "SOF_DMA_UL5"
     51
     52struct mt8195_card_data {
     53	const char *name;
     54	unsigned long quirk;
     55};
     56
     57struct sof_conn_stream {
     58	const char *normal_link;
     59	const char *sof_link;
     60	const char *sof_dma;
     61	int stream_dir;
     62};
     63
     64struct mt8195_mt6359_priv {
     65	struct snd_soc_jack headset_jack;
     66	struct snd_soc_jack dp_jack;
     67	struct snd_soc_jack hdmi_jack;
     68	struct clk *i2so1_mclk;
     69};
     70
     71static const struct snd_soc_dapm_widget mt8195_mt6359_widgets[] = {
     72	SND_SOC_DAPM_HP("Headphone", NULL),
     73	SND_SOC_DAPM_MIC("Headset Mic", NULL),
     74	SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0),
     75	SND_SOC_DAPM_MIXER(SOF_DMA_DL3, SND_SOC_NOPM, 0, 0, NULL, 0),
     76	SND_SOC_DAPM_MIXER(SOF_DMA_UL4, SND_SOC_NOPM, 0, 0, NULL, 0),
     77	SND_SOC_DAPM_MIXER(SOF_DMA_UL5, SND_SOC_NOPM, 0, 0, NULL, 0),
     78};
     79
     80static const struct snd_soc_dapm_route mt8195_mt6359_routes[] = {
     81	/* headset */
     82	{ "Headphone", NULL, "HPOL" },
     83	{ "Headphone", NULL, "HPOR" },
     84	{ "IN1P", NULL, "Headset Mic" },
     85	/* SOF Uplink */
     86	{SOF_DMA_UL4, NULL, "O034"},
     87	{SOF_DMA_UL4, NULL, "O035"},
     88	{SOF_DMA_UL5, NULL, "O036"},
     89	{SOF_DMA_UL5, NULL, "O037"},
     90	/* SOF Downlink */
     91	{"I070", NULL, SOF_DMA_DL2},
     92	{"I071", NULL, SOF_DMA_DL2},
     93	{"I020", NULL, SOF_DMA_DL3},
     94	{"I021", NULL, SOF_DMA_DL3},
     95};
     96
     97static const struct snd_kcontrol_new mt8195_mt6359_controls[] = {
     98	SOC_DAPM_PIN_SWITCH("Headphone"),
     99	SOC_DAPM_PIN_SWITCH("Headset Mic"),
    100};
    101
    102static const struct snd_soc_dapm_widget mt8195_dual_speaker_widgets[] = {
    103	SND_SOC_DAPM_SPK("Left Spk", NULL),
    104	SND_SOC_DAPM_SPK("Right Spk", NULL),
    105};
    106
    107static const struct snd_kcontrol_new mt8195_dual_speaker_controls[] = {
    108	SOC_DAPM_PIN_SWITCH("Left Spk"),
    109	SOC_DAPM_PIN_SWITCH("Right Spk"),
    110};
    111
    112static const struct snd_soc_dapm_widget mt8195_speaker_widgets[] = {
    113	SND_SOC_DAPM_SPK("Ext Spk", NULL),
    114};
    115
    116static const struct snd_kcontrol_new mt8195_speaker_controls[] = {
    117	SOC_DAPM_PIN_SWITCH("Ext Spk"),
    118};
    119
    120static const struct snd_soc_dapm_route mt8195_rt1011_routes[] = {
    121	{ "Left Spk", NULL, "Left SPO" },
    122	{ "Right Spk", NULL, "Right SPO" },
    123};
    124
    125static const struct snd_soc_dapm_route mt8195_rt1019_routes[] = {
    126	{ "Ext Spk", NULL, "Speaker" },
    127};
    128
    129static const struct snd_soc_dapm_route mt8195_max98390_routes[] = {
    130	{ "Left Spk", NULL, "Left BE_OUT" },
    131	{ "Right Spk", NULL, "Right BE_OUT" },
    132};
    133
    134#define CKSYS_AUD_TOP_CFG 0x032c
    135#define CKSYS_AUD_TOP_MON 0x0330
    136
    137static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
    138{
    139	struct snd_soc_component *cmpnt_afe =
    140		snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
    141	struct snd_soc_component *cmpnt_codec =
    142		asoc_rtd_to_codec(rtd, 0)->component;
    143	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
    144	struct mt8195_afe_private *afe_priv = afe->platform_priv;
    145	struct mtkaif_param *param = &afe_priv->mtkaif_params;
    146	int chosen_phase_1, chosen_phase_2, chosen_phase_3;
    147	int prev_cycle_1, prev_cycle_2, prev_cycle_3;
    148	int test_done_1, test_done_2, test_done_3;
    149	int cycle_1, cycle_2, cycle_3;
    150	int mtkaif_chosen_phase[MT8195_MTKAIF_MISO_NUM];
    151	int mtkaif_phase_cycle[MT8195_MTKAIF_MISO_NUM];
    152	int mtkaif_calibration_num_phase;
    153	bool mtkaif_calibration_ok;
    154	unsigned int monitor;
    155	int counter;
    156	int phase;
    157	int i;
    158
    159	dev_dbg(afe->dev, "%s(), start\n", __func__);
    160
    161	param->mtkaif_calibration_ok = false;
    162	for (i = 0; i < MT8195_MTKAIF_MISO_NUM; i++) {
    163		param->mtkaif_chosen_phase[i] = -1;
    164		param->mtkaif_phase_cycle[i] = 0;
    165		mtkaif_chosen_phase[i] = -1;
    166		mtkaif_phase_cycle[i] = 0;
    167	}
    168
    169	if (IS_ERR(afe_priv->topckgen)) {
    170		dev_info(afe->dev, "%s() Cannot find topckgen controller\n",
    171			 __func__);
    172		return 0;
    173	}
    174
    175	pm_runtime_get_sync(afe->dev);
    176	mt6359_mtkaif_calibration_enable(cmpnt_codec);
    177
    178	/* set test type to synchronizer pulse */
    179	regmap_update_bits(afe_priv->topckgen,
    180			   CKSYS_AUD_TOP_CFG, 0xffff, 0x4);
    181	mtkaif_calibration_num_phase = 42;	/* mt6359: 0 ~ 42 */
    182	mtkaif_calibration_ok = true;
    183
    184	for (phase = 0;
    185	     phase <= mtkaif_calibration_num_phase && mtkaif_calibration_ok;
    186	     phase++) {
    187		mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
    188						    phase, phase, phase);
    189
    190		regmap_update_bits(afe_priv->topckgen,
    191				   CKSYS_AUD_TOP_CFG, 0x1, 0x1);
    192
    193		test_done_1 = 0;
    194		test_done_2 = 0;
    195		test_done_3 = 0;
    196		cycle_1 = -1;
    197		cycle_2 = -1;
    198		cycle_3 = -1;
    199		counter = 0;
    200		while (!(test_done_1 & test_done_2 & test_done_3)) {
    201			regmap_read(afe_priv->topckgen,
    202				    CKSYS_AUD_TOP_MON, &monitor);
    203			test_done_1 = (monitor >> 28) & 0x1;
    204			test_done_2 = (monitor >> 29) & 0x1;
    205			test_done_3 = (monitor >> 30) & 0x1;
    206			if (test_done_1 == 1)
    207				cycle_1 = monitor & 0xf;
    208
    209			if (test_done_2 == 1)
    210				cycle_2 = (monitor >> 4) & 0xf;
    211
    212			if (test_done_3 == 1)
    213				cycle_3 = (monitor >> 8) & 0xf;
    214
    215			/* handle if never test done */
    216			if (++counter > 10000) {
    217				dev_info(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n",
    218					 __func__,
    219					 cycle_1, cycle_2, cycle_3, monitor);
    220				mtkaif_calibration_ok = false;
    221				break;
    222			}
    223		}
    224
    225		if (phase == 0) {
    226			prev_cycle_1 = cycle_1;
    227			prev_cycle_2 = cycle_2;
    228			prev_cycle_3 = cycle_3;
    229		}
    230
    231		if (cycle_1 != prev_cycle_1 &&
    232		    mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] < 0) {
    233			mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] = phase - 1;
    234			mtkaif_phase_cycle[MT8195_MTKAIF_MISO_0] = prev_cycle_1;
    235		}
    236
    237		if (cycle_2 != prev_cycle_2 &&
    238		    mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] < 0) {
    239			mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] = phase - 1;
    240			mtkaif_phase_cycle[MT8195_MTKAIF_MISO_1] = prev_cycle_2;
    241		}
    242
    243		if (cycle_3 != prev_cycle_3 &&
    244		    mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] < 0) {
    245			mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] = phase - 1;
    246			mtkaif_phase_cycle[MT8195_MTKAIF_MISO_2] = prev_cycle_3;
    247		}
    248
    249		regmap_update_bits(afe_priv->topckgen,
    250				   CKSYS_AUD_TOP_CFG, 0x1, 0x0);
    251
    252		if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] >= 0 &&
    253		    mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] >= 0 &&
    254		    mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] >= 0)
    255			break;
    256	}
    257
    258	if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] < 0) {
    259		mtkaif_calibration_ok = false;
    260		chosen_phase_1 = 0;
    261	} else {
    262		chosen_phase_1 = mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0];
    263	}
    264
    265	if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] < 0) {
    266		mtkaif_calibration_ok = false;
    267		chosen_phase_2 = 0;
    268	} else {
    269		chosen_phase_2 = mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1];
    270	}
    271
    272	if (mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] < 0) {
    273		mtkaif_calibration_ok = false;
    274		chosen_phase_3 = 0;
    275	} else {
    276		chosen_phase_3 = mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2];
    277	}
    278
    279	mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
    280					    chosen_phase_1,
    281					    chosen_phase_2,
    282					    chosen_phase_3);
    283
    284	mt6359_mtkaif_calibration_disable(cmpnt_codec);
    285	pm_runtime_put(afe->dev);
    286
    287	param->mtkaif_calibration_ok = mtkaif_calibration_ok;
    288	param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_0] = chosen_phase_1;
    289	param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_1] = chosen_phase_2;
    290	param->mtkaif_chosen_phase[MT8195_MTKAIF_MISO_2] = chosen_phase_3;
    291	for (i = 0; i < MT8195_MTKAIF_MISO_NUM; i++)
    292		param->mtkaif_phase_cycle[i] = mtkaif_phase_cycle[i];
    293
    294	dev_info(afe->dev, "%s(), end, calibration ok %d\n",
    295		 __func__, param->mtkaif_calibration_ok);
    296
    297	return 0;
    298}
    299
    300static int mt8195_mt6359_init(struct snd_soc_pcm_runtime *rtd)
    301{
    302	struct snd_soc_component *cmpnt_codec =
    303		asoc_rtd_to_codec(rtd, 0)->component;
    304
    305	/* set mtkaif protocol */
    306	mt6359_set_mtkaif_protocol(cmpnt_codec,
    307				   MT6359_MTKAIF_PROTOCOL_2_CLK_P2);
    308
    309	/* mtkaif calibration */
    310	mt8195_mt6359_mtkaif_calibration(rtd);
    311
    312	return 0;
    313}
    314
    315static int mt8195_hdmitx_dptx_startup(struct snd_pcm_substream *substream)
    316{
    317	static const unsigned int rates[] = {
    318		48000
    319	};
    320	static const unsigned int channels[] = {
    321		2, 4, 6, 8
    322	};
    323	static const struct snd_pcm_hw_constraint_list constraints_rates = {
    324		.count = ARRAY_SIZE(rates),
    325		.list  = rates,
    326		.mask = 0,
    327	};
    328	static const struct snd_pcm_hw_constraint_list constraints_channels = {
    329		.count = ARRAY_SIZE(channels),
    330		.list  = channels,
    331		.mask = 0,
    332	};
    333
    334	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
    335	struct snd_pcm_runtime *runtime = substream->runtime;
    336	int ret;
    337
    338	ret = snd_pcm_hw_constraint_list(runtime, 0,
    339					 SNDRV_PCM_HW_PARAM_RATE,
    340					 &constraints_rates);
    341	if (ret < 0) {
    342		dev_err(rtd->dev, "hw_constraint_list rate failed\n");
    343		return ret;
    344	}
    345
    346	ret = snd_pcm_hw_constraint_list(runtime, 0,
    347					 SNDRV_PCM_HW_PARAM_CHANNELS,
    348					 &constraints_channels);
    349	if (ret < 0) {
    350		dev_err(rtd->dev, "hw_constraint_list channel failed\n");
    351		return ret;
    352	}
    353
    354	return 0;
    355}
    356
    357static const struct snd_soc_ops mt8195_hdmitx_dptx_playback_ops = {
    358	.startup = mt8195_hdmitx_dptx_startup,
    359};
    360
    361static int mt8195_dptx_hw_params(struct snd_pcm_substream *substream,
    362				 struct snd_pcm_hw_params *params)
    363{
    364	struct snd_soc_pcm_runtime *rtd = substream->private_data;
    365	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
    366
    367	return snd_soc_dai_set_sysclk(cpu_dai, 0, params_rate(params) * 256,
    368				      SND_SOC_CLOCK_OUT);
    369}
    370
    371static const struct snd_soc_ops mt8195_dptx_ops = {
    372	.hw_params = mt8195_dptx_hw_params,
    373};
    374
    375static int mt8195_dptx_codec_init(struct snd_soc_pcm_runtime *rtd)
    376{
    377	struct mt8195_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
    378	struct snd_soc_component *cmpnt_codec =
    379		asoc_rtd_to_codec(rtd, 0)->component;
    380	int ret;
    381
    382	ret = snd_soc_card_jack_new(rtd->card, "DP Jack", SND_JACK_LINEOUT,
    383				    &priv->dp_jack);
    384	if (ret)
    385		return ret;
    386
    387	return snd_soc_component_set_jack(cmpnt_codec, &priv->dp_jack, NULL);
    388}
    389
    390static int mt8195_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd)
    391{
    392	struct mt8195_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
    393	struct snd_soc_component *cmpnt_codec =
    394		asoc_rtd_to_codec(rtd, 0)->component;
    395	int ret;
    396
    397	ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT,
    398				    &priv->hdmi_jack);
    399	if (ret)
    400		return ret;
    401
    402	return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL);
    403}
    404
    405static int mt8195_dptx_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
    406				       struct snd_pcm_hw_params *params)
    407{
    408	/* fix BE i2s format to S24_LE, clean param mask first */
    409	snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
    410			     0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST);
    411
    412	params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
    413
    414	return 0;
    415}
    416
    417static int mt8195_playback_startup(struct snd_pcm_substream *substream)
    418{
    419	static const unsigned int rates[] = {
    420		48000
    421	};
    422	static const unsigned int channels[] = {
    423		2
    424	};
    425	static const struct snd_pcm_hw_constraint_list constraints_rates = {
    426		.count = ARRAY_SIZE(rates),
    427		.list  = rates,
    428		.mask = 0,
    429	};
    430	static const struct snd_pcm_hw_constraint_list constraints_channels = {
    431		.count = ARRAY_SIZE(channels),
    432		.list  = channels,
    433		.mask = 0,
    434	};
    435
    436	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
    437	struct snd_pcm_runtime *runtime = substream->runtime;
    438	int ret;
    439
    440	ret = snd_pcm_hw_constraint_list(runtime, 0,
    441					 SNDRV_PCM_HW_PARAM_RATE,
    442					 &constraints_rates);
    443	if (ret < 0) {
    444		dev_err(rtd->dev, "hw_constraint_list rate failed\n");
    445		return ret;
    446	}
    447
    448	ret = snd_pcm_hw_constraint_list(runtime, 0,
    449					 SNDRV_PCM_HW_PARAM_CHANNELS,
    450					 &constraints_channels);
    451	if (ret < 0) {
    452		dev_err(rtd->dev, "hw_constraint_list channel failed\n");
    453		return ret;
    454	}
    455
    456	return 0;
    457}
    458
    459static const struct snd_soc_ops mt8195_playback_ops = {
    460	.startup = mt8195_playback_startup,
    461};
    462
    463static int mt8195_capture_startup(struct snd_pcm_substream *substream)
    464{
    465	static const unsigned int rates[] = {
    466		48000
    467	};
    468	static const unsigned int channels[] = {
    469		1, 2
    470	};
    471	static const struct snd_pcm_hw_constraint_list constraints_rates = {
    472		.count = ARRAY_SIZE(rates),
    473		.list  = rates,
    474		.mask = 0,
    475	};
    476	static const struct snd_pcm_hw_constraint_list constraints_channels = {
    477		.count = ARRAY_SIZE(channels),
    478		.list  = channels,
    479		.mask = 0,
    480	};
    481
    482	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
    483	struct snd_pcm_runtime *runtime = substream->runtime;
    484	int ret;
    485
    486	ret = snd_pcm_hw_constraint_list(runtime, 0,
    487					 SNDRV_PCM_HW_PARAM_RATE,
    488					 &constraints_rates);
    489	if (ret < 0) {
    490		dev_err(rtd->dev, "hw_constraint_list rate failed\n");
    491		return ret;
    492	}
    493
    494	ret = snd_pcm_hw_constraint_list(runtime, 0,
    495					 SNDRV_PCM_HW_PARAM_CHANNELS,
    496					 &constraints_channels);
    497	if (ret < 0) {
    498		dev_err(rtd->dev, "hw_constraint_list channel failed\n");
    499		return ret;
    500	}
    501
    502	return 0;
    503}
    504
    505static const struct snd_soc_ops mt8195_capture_ops = {
    506	.startup = mt8195_capture_startup,
    507};
    508
    509static int mt8195_rt5682_etdm_hw_params(struct snd_pcm_substream *substream,
    510					struct snd_pcm_hw_params *params)
    511{
    512	struct snd_soc_pcm_runtime *rtd = substream->private_data;
    513	struct snd_soc_card *card = rtd->card;
    514	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
    515	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
    516	unsigned int rate = params_rate(params);
    517	int bitwidth;
    518	int ret;
    519
    520	bitwidth = snd_pcm_format_width(params_format(params));
    521	if (bitwidth < 0) {
    522		dev_err(card->dev, "invalid bit width: %d\n", bitwidth);
    523		return bitwidth;
    524	}
    525
    526	ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth);
    527	if (ret) {
    528		dev_err(card->dev, "failed to set tdm slot\n");
    529		return ret;
    530	}
    531
    532	ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1, RT5682_PLL1_S_MCLK,
    533				  rate * 256, rate * 512);
    534	if (ret) {
    535		dev_err(card->dev, "failed to set pll\n");
    536		return ret;
    537	}
    538
    539	ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL1,
    540				     rate * 512, SND_SOC_CLOCK_IN);
    541	if (ret) {
    542		dev_err(card->dev, "failed to set sysclk\n");
    543		return ret;
    544	}
    545
    546	return snd_soc_dai_set_sysclk(cpu_dai, 0, rate * 256,
    547				      SND_SOC_CLOCK_OUT);
    548}
    549
    550static const struct snd_soc_ops mt8195_rt5682_etdm_ops = {
    551	.hw_params = mt8195_rt5682_etdm_hw_params,
    552};
    553
    554static int mt8195_rt5682_init(struct snd_soc_pcm_runtime *rtd)
    555{
    556	struct snd_soc_component *cmpnt_codec =
    557		asoc_rtd_to_codec(rtd, 0)->component;
    558	struct mt8195_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
    559	struct snd_soc_jack *jack = &priv->headset_jack;
    560	struct snd_soc_component *cmpnt_afe =
    561		snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
    562	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
    563	struct mt8195_afe_private *afe_priv = afe->platform_priv;
    564	int ret;
    565
    566	priv->i2so1_mclk = afe_priv->clk[MT8195_CLK_TOP_APLL12_DIV2];
    567
    568	ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
    569				    SND_JACK_HEADSET | SND_JACK_BTN_0 |
    570				    SND_JACK_BTN_1 | SND_JACK_BTN_2 |
    571				    SND_JACK_BTN_3,
    572				    jack);
    573	if (ret) {
    574		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
    575		return ret;
    576	}
    577
    578	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
    579	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
    580	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
    581	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
    582
    583	ret = snd_soc_component_set_jack(cmpnt_codec, jack, NULL);
    584	if (ret) {
    585		dev_err(rtd->dev, "Headset Jack set failed: %d\n", ret);
    586		return ret;
    587	}
    588
    589	return 0;
    590};
    591
    592static int mt8195_rt1011_etdm_hw_params(struct snd_pcm_substream *substream,
    593					struct snd_pcm_hw_params *params)
    594{
    595	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
    596	struct snd_soc_dai *codec_dai;
    597	struct snd_soc_card *card = rtd->card;
    598	int srate, i, ret;
    599
    600	srate = params_rate(params);
    601
    602	for_each_rtd_codec_dais(rtd, i, codec_dai) {
    603		ret = snd_soc_dai_set_pll(codec_dai, 0, RT1011_PLL1_S_BCLK,
    604					  64 * srate, 256 * srate);
    605		if (ret < 0) {
    606			dev_err(card->dev, "codec_dai clock not set\n");
    607			return ret;
    608		}
    609
    610		ret = snd_soc_dai_set_sysclk(codec_dai,
    611					     RT1011_FS_SYS_PRE_S_PLL1,
    612					     256 * srate, SND_SOC_CLOCK_IN);
    613		if (ret < 0) {
    614			dev_err(card->dev, "codec_dai clock not set\n");
    615			return ret;
    616		}
    617	}
    618	return 0;
    619}
    620
    621static const struct snd_soc_ops mt8195_rt1011_etdm_ops = {
    622	.hw_params = mt8195_rt1011_etdm_hw_params,
    623};
    624
    625static int mt8195_rt1011_init(struct snd_soc_pcm_runtime *rtd)
    626{
    627	struct snd_soc_card *card = rtd->card;
    628	int ret;
    629
    630	ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets,
    631					ARRAY_SIZE(mt8195_dual_speaker_widgets));
    632	if (ret) {
    633		dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret);
    634		/* Don't need to add routes if widget addition failed */
    635		return ret;
    636	}
    637
    638	ret = snd_soc_add_card_controls(card, mt8195_dual_speaker_controls,
    639					ARRAY_SIZE(mt8195_dual_speaker_controls));
    640	if (ret) {
    641		dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
    642		return ret;
    643	}
    644
    645	ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1011_routes,
    646				      ARRAY_SIZE(mt8195_rt1011_routes));
    647	if (ret)
    648		dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret);
    649
    650	return ret;
    651}
    652
    653static int mt8195_rt1019_init(struct snd_soc_pcm_runtime *rtd)
    654{
    655	struct snd_soc_card *card = rtd->card;
    656	int ret;
    657
    658	ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_speaker_widgets,
    659					ARRAY_SIZE(mt8195_speaker_widgets));
    660	if (ret) {
    661		dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret);
    662		/* Don't need to add routes if widget addition failed */
    663		return ret;
    664	}
    665
    666	ret = snd_soc_add_card_controls(card, mt8195_speaker_controls,
    667					ARRAY_SIZE(mt8195_speaker_controls));
    668	if (ret) {
    669		dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
    670		return ret;
    671	}
    672
    673	ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1019_routes,
    674				      ARRAY_SIZE(mt8195_rt1019_routes));
    675	if (ret)
    676		dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret);
    677
    678	return ret;
    679}
    680
    681static int mt8195_max98390_init(struct snd_soc_pcm_runtime *rtd)
    682{
    683	struct snd_soc_card *card = rtd->card;
    684	int ret;
    685
    686	ret = snd_soc_dapm_new_controls(&card->dapm, mt8195_dual_speaker_widgets,
    687					ARRAY_SIZE(mt8195_dual_speaker_widgets));
    688	if (ret) {
    689		dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret);
    690		/* Don't need to add routes if widget addition failed */
    691		return ret;
    692	}
    693
    694	ret = snd_soc_add_card_controls(card, mt8195_dual_speaker_controls,
    695					ARRAY_SIZE(mt8195_dual_speaker_controls));
    696	if (ret) {
    697		dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
    698		return ret;
    699	}
    700
    701	ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_max98390_routes,
    702				      ARRAY_SIZE(mt8195_max98390_routes));
    703	if (ret)
    704		dev_err(rtd->dev, "unable to add dapm routes, ret %d\n", ret);
    705
    706	return ret;
    707}
    708
    709static int mt8195_etdm_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
    710				       struct snd_pcm_hw_params *params)
    711{
    712	/* fix BE i2s format to S24_LE, clean param mask first */
    713	snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
    714			     0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST);
    715
    716	params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
    717
    718	return 0;
    719}
    720
    721static int mt8195_set_bias_level_post(struct snd_soc_card *card,
    722	struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
    723{
    724	struct snd_soc_component *component = dapm->component;
    725	struct mt8195_mt6359_priv *priv = snd_soc_card_get_drvdata(card);
    726	int ret;
    727
    728	/*
    729	 * It's required to control mclk directly in the set_bias_level_post
    730	 * function for rt5682 and rt5682s codec, or the unexpected pop happens
    731	 * at the end of playback.
    732	 */
    733	if (!component ||
    734	    (strcmp(component->name, RT5682_DEV0_NAME) &&
    735	    strcmp(component->name, RT5682S_DEV0_NAME)))
    736		return 0;
    737
    738	switch (level) {
    739	case SND_SOC_BIAS_OFF:
    740		if (!__clk_is_enabled(priv->i2so1_mclk))
    741			return 0;
    742
    743		clk_disable_unprepare(priv->i2so1_mclk);
    744		dev_dbg(card->dev, "Disable i2so1 mclk\n");
    745		break;
    746	case SND_SOC_BIAS_ON:
    747		ret = clk_prepare_enable(priv->i2so1_mclk);
    748		if (ret) {
    749			dev_err(card->dev, "Can't enable i2so1 mclk: %d\n", ret);
    750			return ret;
    751		}
    752		dev_dbg(card->dev, "Enable i2so1 mclk\n");
    753		break;
    754	default:
    755		break;
    756	}
    757
    758	return 0;
    759}
    760
    761enum {
    762	DAI_LINK_DL2_FE,
    763	DAI_LINK_DL3_FE,
    764	DAI_LINK_DL6_FE,
    765	DAI_LINK_DL7_FE,
    766	DAI_LINK_DL8_FE,
    767	DAI_LINK_DL10_FE,
    768	DAI_LINK_DL11_FE,
    769	DAI_LINK_UL1_FE,
    770	DAI_LINK_UL2_FE,
    771	DAI_LINK_UL3_FE,
    772	DAI_LINK_UL4_FE,
    773	DAI_LINK_UL5_FE,
    774	DAI_LINK_UL6_FE,
    775	DAI_LINK_UL8_FE,
    776	DAI_LINK_UL9_FE,
    777	DAI_LINK_UL10_FE,
    778	DAI_LINK_DL_SRC_BE,
    779	DAI_LINK_DPTX_BE,
    780	DAI_LINK_ETDM1_IN_BE,
    781	DAI_LINK_ETDM2_IN_BE,
    782	DAI_LINK_ETDM1_OUT_BE,
    783	DAI_LINK_ETDM2_OUT_BE,
    784	DAI_LINK_ETDM3_OUT_BE,
    785	DAI_LINK_PCM1_BE,
    786	DAI_LINK_UL_SRC1_BE,
    787	DAI_LINK_UL_SRC2_BE,
    788	DAI_LINK_REGULAR_LAST = DAI_LINK_UL_SRC2_BE,
    789	DAI_LINK_SOF_START,
    790	DAI_LINK_SOF_DL2_BE = DAI_LINK_SOF_START,
    791	DAI_LINK_SOF_DL3_BE,
    792	DAI_LINK_SOF_UL4_BE,
    793	DAI_LINK_SOF_UL5_BE,
    794	DAI_LINK_SOF_END = DAI_LINK_SOF_UL5_BE,
    795};
    796
    797#define	DAI_LINK_REGULAR_NUM	(DAI_LINK_REGULAR_LAST + 1)
    798
    799/* FE */
    800SND_SOC_DAILINK_DEFS(DL2_FE,
    801		     DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
    802		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    803		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    804
    805SND_SOC_DAILINK_DEFS(DL3_FE,
    806		     DAILINK_COMP_ARRAY(COMP_CPU("DL3")),
    807		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    808		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    809
    810SND_SOC_DAILINK_DEFS(DL6_FE,
    811		     DAILINK_COMP_ARRAY(COMP_CPU("DL6")),
    812		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    813		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    814
    815SND_SOC_DAILINK_DEFS(DL7_FE,
    816		     DAILINK_COMP_ARRAY(COMP_CPU("DL7")),
    817		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    818		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    819
    820SND_SOC_DAILINK_DEFS(DL8_FE,
    821		     DAILINK_COMP_ARRAY(COMP_CPU("DL8")),
    822		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    823		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    824
    825SND_SOC_DAILINK_DEFS(DL10_FE,
    826		     DAILINK_COMP_ARRAY(COMP_CPU("DL10")),
    827		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    828		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    829
    830SND_SOC_DAILINK_DEFS(DL11_FE,
    831		     DAILINK_COMP_ARRAY(COMP_CPU("DL11")),
    832		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    833		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    834
    835SND_SOC_DAILINK_DEFS(UL1_FE,
    836		     DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
    837		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    838		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    839
    840SND_SOC_DAILINK_DEFS(UL2_FE,
    841		     DAILINK_COMP_ARRAY(COMP_CPU("UL2")),
    842		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    843		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    844
    845SND_SOC_DAILINK_DEFS(UL3_FE,
    846		     DAILINK_COMP_ARRAY(COMP_CPU("UL3")),
    847		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    848		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    849
    850SND_SOC_DAILINK_DEFS(UL4_FE,
    851		     DAILINK_COMP_ARRAY(COMP_CPU("UL4")),
    852		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    853		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    854
    855SND_SOC_DAILINK_DEFS(UL5_FE,
    856		     DAILINK_COMP_ARRAY(COMP_CPU("UL5")),
    857		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    858		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    859
    860SND_SOC_DAILINK_DEFS(UL6_FE,
    861		     DAILINK_COMP_ARRAY(COMP_CPU("UL6")),
    862		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    863		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    864
    865SND_SOC_DAILINK_DEFS(UL8_FE,
    866		     DAILINK_COMP_ARRAY(COMP_CPU("UL8")),
    867		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    868		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    869
    870SND_SOC_DAILINK_DEFS(UL9_FE,
    871		     DAILINK_COMP_ARRAY(COMP_CPU("UL9")),
    872		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    873		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    874
    875SND_SOC_DAILINK_DEFS(UL10_FE,
    876		     DAILINK_COMP_ARRAY(COMP_CPU("UL10")),
    877		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    878		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    879
    880/* BE */
    881SND_SOC_DAILINK_DEFS(DL_SRC_BE,
    882		     DAILINK_COMP_ARRAY(COMP_CPU("DL_SRC")),
    883		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
    884						   "mt6359-snd-codec-aif1")),
    885		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    886
    887SND_SOC_DAILINK_DEFS(DPTX_BE,
    888		     DAILINK_COMP_ARRAY(COMP_CPU("DPTX")),
    889		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    890		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    891
    892SND_SOC_DAILINK_DEFS(ETDM1_IN_BE,
    893		     DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_IN")),
    894		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    895		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    896
    897SND_SOC_DAILINK_DEFS(ETDM2_IN_BE,
    898		     DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_IN")),
    899		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    900		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    901
    902SND_SOC_DAILINK_DEFS(ETDM1_OUT_BE,
    903		     DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_OUT")),
    904		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    905		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    906
    907SND_SOC_DAILINK_DEFS(ETDM2_OUT_BE,
    908		     DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_OUT")),
    909		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    910		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    911
    912SND_SOC_DAILINK_DEFS(ETDM3_OUT_BE,
    913		     DAILINK_COMP_ARRAY(COMP_CPU("ETDM3_OUT")),
    914		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    915		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    916
    917SND_SOC_DAILINK_DEFS(PCM1_BE,
    918		     DAILINK_COMP_ARRAY(COMP_CPU("PCM1")),
    919		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    920		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    921
    922SND_SOC_DAILINK_DEFS(UL_SRC1_BE,
    923		     DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC1")),
    924		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
    925						   "mt6359-snd-codec-aif1"),
    926					COMP_CODEC("dmic-codec",
    927						   "dmic-hifi")),
    928		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    929
    930SND_SOC_DAILINK_DEFS(UL_SRC2_BE,
    931		     DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC2")),
    932		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
    933						   "mt6359-snd-codec-aif2")),
    934		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    935
    936SND_SOC_DAILINK_DEFS(AFE_SOF_DL2,
    937		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL2")),
    938		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    939		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    940
    941SND_SOC_DAILINK_DEFS(AFE_SOF_DL3,
    942		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL3")),
    943		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    944		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    945
    946SND_SOC_DAILINK_DEFS(AFE_SOF_UL4,
    947		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL4")),
    948		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    949		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    950
    951SND_SOC_DAILINK_DEFS(AFE_SOF_UL5,
    952		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL5")),
    953		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    954		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    955
    956/* codec */
    957SND_SOC_DAILINK_DEF(rt1019_comps,
    958		    DAILINK_COMP_ARRAY(COMP_CODEC(RT1019_DEV0_NAME,
    959						  RT1019_CODEC_DAI)));
    960
    961SND_SOC_DAILINK_DEF(rt1011_comps,
    962		    DAILINK_COMP_ARRAY(COMP_CODEC(RT1011_DEV0_NAME,
    963						  RT1011_CODEC_DAI),
    964				       COMP_CODEC(RT1011_DEV1_NAME,
    965						  RT1011_CODEC_DAI)));
    966
    967SND_SOC_DAILINK_DEF(max98390_comps,
    968		    DAILINK_COMP_ARRAY(COMP_CODEC(MAX98390_DEV0_NAME,
    969						  MAX98390_CODEC_DAI),
    970				       COMP_CODEC(MAX98390_DEV1_NAME,
    971						  MAX98390_CODEC_DAI)));
    972
    973static const struct sof_conn_stream g_sof_conn_streams[] = {
    974	{ "ETDM2_OUT_BE", "AFE_SOF_DL2", SOF_DMA_DL2, SNDRV_PCM_STREAM_PLAYBACK},
    975	{ "ETDM1_OUT_BE", "AFE_SOF_DL3", SOF_DMA_DL3, SNDRV_PCM_STREAM_PLAYBACK},
    976	{ "UL_SRC1_BE", "AFE_SOF_UL4", SOF_DMA_UL4, SNDRV_PCM_STREAM_CAPTURE},
    977	{ "ETDM2_IN_BE", "AFE_SOF_UL5", SOF_DMA_UL5, SNDRV_PCM_STREAM_CAPTURE},
    978};
    979
    980static struct snd_soc_dai_link mt8195_mt6359_dai_links[] = {
    981	/* FE */
    982	[DAI_LINK_DL2_FE] = {
    983		.name = "DL2_FE",
    984		.stream_name = "DL2 Playback",
    985		.trigger = {
    986			SND_SOC_DPCM_TRIGGER_POST,
    987			SND_SOC_DPCM_TRIGGER_POST,
    988		},
    989		.dynamic = 1,
    990		.dpcm_playback = 1,
    991		.ops = &mt8195_playback_ops,
    992		SND_SOC_DAILINK_REG(DL2_FE),
    993	},
    994	[DAI_LINK_DL3_FE] = {
    995		.name = "DL3_FE",
    996		.stream_name = "DL3 Playback",
    997		.trigger = {
    998			SND_SOC_DPCM_TRIGGER_POST,
    999			SND_SOC_DPCM_TRIGGER_POST,
   1000		},
   1001		.dynamic = 1,
   1002		.dpcm_playback = 1,
   1003		.ops = &mt8195_playback_ops,
   1004		SND_SOC_DAILINK_REG(DL3_FE),
   1005	},
   1006	[DAI_LINK_DL6_FE] = {
   1007		.name = "DL6_FE",
   1008		.stream_name = "DL6 Playback",
   1009		.trigger = {
   1010			SND_SOC_DPCM_TRIGGER_POST,
   1011			SND_SOC_DPCM_TRIGGER_POST,
   1012		},
   1013		.dynamic = 1,
   1014		.dpcm_playback = 1,
   1015		.ops = &mt8195_playback_ops,
   1016		SND_SOC_DAILINK_REG(DL6_FE),
   1017	},
   1018	[DAI_LINK_DL7_FE] = {
   1019		.name = "DL7_FE",
   1020		.stream_name = "DL7 Playback",
   1021		.trigger = {
   1022			SND_SOC_DPCM_TRIGGER_PRE,
   1023			SND_SOC_DPCM_TRIGGER_PRE,
   1024		},
   1025		.dynamic = 1,
   1026		.dpcm_playback = 1,
   1027		SND_SOC_DAILINK_REG(DL7_FE),
   1028	},
   1029	[DAI_LINK_DL8_FE] = {
   1030		.name = "DL8_FE",
   1031		.stream_name = "DL8 Playback",
   1032		.trigger = {
   1033			SND_SOC_DPCM_TRIGGER_POST,
   1034			SND_SOC_DPCM_TRIGGER_POST,
   1035		},
   1036		.dynamic = 1,
   1037		.dpcm_playback = 1,
   1038		.ops = &mt8195_playback_ops,
   1039		SND_SOC_DAILINK_REG(DL8_FE),
   1040	},
   1041	[DAI_LINK_DL10_FE] = {
   1042		.name = "DL10_FE",
   1043		.stream_name = "DL10 Playback",
   1044		.trigger = {
   1045			SND_SOC_DPCM_TRIGGER_POST,
   1046			SND_SOC_DPCM_TRIGGER_POST,
   1047		},
   1048		.dynamic = 1,
   1049		.dpcm_playback = 1,
   1050		.ops = &mt8195_hdmitx_dptx_playback_ops,
   1051		SND_SOC_DAILINK_REG(DL10_FE),
   1052	},
   1053	[DAI_LINK_DL11_FE] = {
   1054		.name = "DL11_FE",
   1055		.stream_name = "DL11 Playback",
   1056		.trigger = {
   1057			SND_SOC_DPCM_TRIGGER_POST,
   1058			SND_SOC_DPCM_TRIGGER_POST,
   1059		},
   1060		.dynamic = 1,
   1061		.dpcm_playback = 1,
   1062		.ops = &mt8195_playback_ops,
   1063		SND_SOC_DAILINK_REG(DL11_FE),
   1064	},
   1065	[DAI_LINK_UL1_FE] = {
   1066		.name = "UL1_FE",
   1067		.stream_name = "UL1 Capture",
   1068		.trigger = {
   1069			SND_SOC_DPCM_TRIGGER_PRE,
   1070			SND_SOC_DPCM_TRIGGER_PRE,
   1071		},
   1072		.dynamic = 1,
   1073		.dpcm_capture = 1,
   1074		SND_SOC_DAILINK_REG(UL1_FE),
   1075	},
   1076	[DAI_LINK_UL2_FE] = {
   1077		.name = "UL2_FE",
   1078		.stream_name = "UL2 Capture",
   1079		.trigger = {
   1080			SND_SOC_DPCM_TRIGGER_POST,
   1081			SND_SOC_DPCM_TRIGGER_POST,
   1082		},
   1083		.dynamic = 1,
   1084		.dpcm_capture = 1,
   1085		.ops = &mt8195_capture_ops,
   1086		SND_SOC_DAILINK_REG(UL2_FE),
   1087	},
   1088	[DAI_LINK_UL3_FE] = {
   1089		.name = "UL3_FE",
   1090		.stream_name = "UL3 Capture",
   1091		.trigger = {
   1092			SND_SOC_DPCM_TRIGGER_POST,
   1093			SND_SOC_DPCM_TRIGGER_POST,
   1094		},
   1095		.dynamic = 1,
   1096		.dpcm_capture = 1,
   1097		.ops = &mt8195_capture_ops,
   1098		SND_SOC_DAILINK_REG(UL3_FE),
   1099	},
   1100	[DAI_LINK_UL4_FE] = {
   1101		.name = "UL4_FE",
   1102		.stream_name = "UL4 Capture",
   1103		.trigger = {
   1104			SND_SOC_DPCM_TRIGGER_POST,
   1105			SND_SOC_DPCM_TRIGGER_POST,
   1106		},
   1107		.dynamic = 1,
   1108		.dpcm_capture = 1,
   1109		.ops = &mt8195_capture_ops,
   1110		SND_SOC_DAILINK_REG(UL4_FE),
   1111	},
   1112	[DAI_LINK_UL5_FE] = {
   1113		.name = "UL5_FE",
   1114		.stream_name = "UL5 Capture",
   1115		.trigger = {
   1116			SND_SOC_DPCM_TRIGGER_POST,
   1117			SND_SOC_DPCM_TRIGGER_POST,
   1118		},
   1119		.dynamic = 1,
   1120		.dpcm_capture = 1,
   1121		.ops = &mt8195_capture_ops,
   1122		SND_SOC_DAILINK_REG(UL5_FE),
   1123	},
   1124	[DAI_LINK_UL6_FE] = {
   1125		.name = "UL6_FE",
   1126		.stream_name = "UL6 Capture",
   1127		.trigger = {
   1128			SND_SOC_DPCM_TRIGGER_PRE,
   1129			SND_SOC_DPCM_TRIGGER_PRE,
   1130		},
   1131		.dynamic = 1,
   1132		.dpcm_capture = 1,
   1133		SND_SOC_DAILINK_REG(UL6_FE),
   1134	},
   1135	[DAI_LINK_UL8_FE] = {
   1136		.name = "UL8_FE",
   1137		.stream_name = "UL8 Capture",
   1138		.trigger = {
   1139			SND_SOC_DPCM_TRIGGER_POST,
   1140			SND_SOC_DPCM_TRIGGER_POST,
   1141		},
   1142		.dynamic = 1,
   1143		.dpcm_capture = 1,
   1144		.ops = &mt8195_capture_ops,
   1145		SND_SOC_DAILINK_REG(UL8_FE),
   1146	},
   1147	[DAI_LINK_UL9_FE] = {
   1148		.name = "UL9_FE",
   1149		.stream_name = "UL9 Capture",
   1150		.trigger = {
   1151			SND_SOC_DPCM_TRIGGER_POST,
   1152			SND_SOC_DPCM_TRIGGER_POST,
   1153		},
   1154		.dynamic = 1,
   1155		.dpcm_capture = 1,
   1156		.ops = &mt8195_capture_ops,
   1157		SND_SOC_DAILINK_REG(UL9_FE),
   1158	},
   1159	[DAI_LINK_UL10_FE] = {
   1160		.name = "UL10_FE",
   1161		.stream_name = "UL10 Capture",
   1162		.trigger = {
   1163			SND_SOC_DPCM_TRIGGER_POST,
   1164			SND_SOC_DPCM_TRIGGER_POST,
   1165		},
   1166		.dynamic = 1,
   1167		.dpcm_capture = 1,
   1168		.ops = &mt8195_capture_ops,
   1169		SND_SOC_DAILINK_REG(UL10_FE),
   1170	},
   1171	/* BE */
   1172	[DAI_LINK_DL_SRC_BE] = {
   1173		.name = "DL_SRC_BE",
   1174		.no_pcm = 1,
   1175		.dpcm_playback = 1,
   1176		SND_SOC_DAILINK_REG(DL_SRC_BE),
   1177	},
   1178	[DAI_LINK_DPTX_BE] = {
   1179		.name = "DPTX_BE",
   1180		.no_pcm = 1,
   1181		.dpcm_playback = 1,
   1182		.ops = &mt8195_dptx_ops,
   1183		.be_hw_params_fixup = mt8195_dptx_hw_params_fixup,
   1184		SND_SOC_DAILINK_REG(DPTX_BE),
   1185	},
   1186	[DAI_LINK_ETDM1_IN_BE] = {
   1187		.name = "ETDM1_IN_BE",
   1188		.no_pcm = 1,
   1189		.dai_fmt = SND_SOC_DAIFMT_I2S |
   1190			SND_SOC_DAIFMT_NB_NF |
   1191			SND_SOC_DAIFMT_CBS_CFS,
   1192		.dpcm_capture = 1,
   1193		SND_SOC_DAILINK_REG(ETDM1_IN_BE),
   1194	},
   1195	[DAI_LINK_ETDM2_IN_BE] = {
   1196		.name = "ETDM2_IN_BE",
   1197		.no_pcm = 1,
   1198		.dai_fmt = SND_SOC_DAIFMT_I2S |
   1199			SND_SOC_DAIFMT_NB_NF |
   1200			SND_SOC_DAIFMT_CBS_CFS,
   1201		.dpcm_capture = 1,
   1202		.init = mt8195_rt5682_init,
   1203		.ops = &mt8195_rt5682_etdm_ops,
   1204		.be_hw_params_fixup = mt8195_etdm_hw_params_fixup,
   1205		SND_SOC_DAILINK_REG(ETDM2_IN_BE),
   1206	},
   1207	[DAI_LINK_ETDM1_OUT_BE] = {
   1208		.name = "ETDM1_OUT_BE",
   1209		.no_pcm = 1,
   1210		.dai_fmt = SND_SOC_DAIFMT_I2S |
   1211			SND_SOC_DAIFMT_NB_NF |
   1212			SND_SOC_DAIFMT_CBS_CFS,
   1213		.dpcm_playback = 1,
   1214		.ops = &mt8195_rt5682_etdm_ops,
   1215		.be_hw_params_fixup = mt8195_etdm_hw_params_fixup,
   1216		SND_SOC_DAILINK_REG(ETDM1_OUT_BE),
   1217	},
   1218	[DAI_LINK_ETDM2_OUT_BE] = {
   1219		.name = "ETDM2_OUT_BE",
   1220		.no_pcm = 1,
   1221		.dai_fmt = SND_SOC_DAIFMT_I2S |
   1222			SND_SOC_DAIFMT_NB_NF |
   1223			SND_SOC_DAIFMT_CBS_CFS,
   1224		.dpcm_playback = 1,
   1225		SND_SOC_DAILINK_REG(ETDM2_OUT_BE),
   1226	},
   1227	[DAI_LINK_ETDM3_OUT_BE] = {
   1228		.name = "ETDM3_OUT_BE",
   1229		.no_pcm = 1,
   1230		.dai_fmt = SND_SOC_DAIFMT_I2S |
   1231			SND_SOC_DAIFMT_NB_NF |
   1232			SND_SOC_DAIFMT_CBS_CFS,
   1233		.dpcm_playback = 1,
   1234		SND_SOC_DAILINK_REG(ETDM3_OUT_BE),
   1235	},
   1236	[DAI_LINK_PCM1_BE] = {
   1237		.name = "PCM1_BE",
   1238		.no_pcm = 1,
   1239		.dai_fmt = SND_SOC_DAIFMT_I2S |
   1240			SND_SOC_DAIFMT_NB_NF |
   1241			SND_SOC_DAIFMT_CBS_CFS,
   1242		.dpcm_playback = 1,
   1243		.dpcm_capture = 1,
   1244		SND_SOC_DAILINK_REG(PCM1_BE),
   1245	},
   1246	[DAI_LINK_UL_SRC1_BE] = {
   1247		.name = "UL_SRC1_BE",
   1248		.no_pcm = 1,
   1249		.dpcm_capture = 1,
   1250		SND_SOC_DAILINK_REG(UL_SRC1_BE),
   1251	},
   1252	[DAI_LINK_UL_SRC2_BE] = {
   1253		.name = "UL_SRC2_BE",
   1254		.no_pcm = 1,
   1255		.dpcm_capture = 1,
   1256		SND_SOC_DAILINK_REG(UL_SRC2_BE),
   1257	},
   1258	/* SOF BE */
   1259	[DAI_LINK_SOF_DL2_BE] = {
   1260		.name = "AFE_SOF_DL2",
   1261		.no_pcm = 1,
   1262		.dpcm_playback = 1,
   1263		SND_SOC_DAILINK_REG(AFE_SOF_DL2),
   1264	},
   1265	[DAI_LINK_SOF_DL3_BE] = {
   1266		.name = "AFE_SOF_DL3",
   1267		.no_pcm = 1,
   1268		.dpcm_playback = 1,
   1269		SND_SOC_DAILINK_REG(AFE_SOF_DL3),
   1270	},
   1271	[DAI_LINK_SOF_UL4_BE] = {
   1272		.name = "AFE_SOF_UL4",
   1273		.no_pcm = 1,
   1274		.dpcm_capture = 1,
   1275		SND_SOC_DAILINK_REG(AFE_SOF_UL4),
   1276	},
   1277	[DAI_LINK_SOF_UL5_BE] = {
   1278		.name = "AFE_SOF_UL5",
   1279		.no_pcm = 1,
   1280		.dpcm_capture = 1,
   1281		SND_SOC_DAILINK_REG(AFE_SOF_UL5),
   1282	},
   1283};
   1284
   1285static struct snd_soc_codec_conf rt1011_codec_conf[] = {
   1286	{
   1287		.dlc = COMP_CODEC_CONF(RT1011_DEV0_NAME),
   1288		.name_prefix = "Left",
   1289	},
   1290	{
   1291		.dlc = COMP_CODEC_CONF(RT1011_DEV1_NAME),
   1292		.name_prefix = "Right",
   1293	},
   1294};
   1295
   1296static struct snd_soc_codec_conf max98390_codec_conf[] = {
   1297	{
   1298		.dlc = COMP_CODEC_CONF(MAX98390_DEV0_NAME),
   1299		.name_prefix = "Right",
   1300	},
   1301	{
   1302		.dlc = COMP_CODEC_CONF(MAX98390_DEV1_NAME),
   1303		.name_prefix = "Left",
   1304	},
   1305};
   1306
   1307static struct snd_soc_card mt8195_mt6359_soc_card = {
   1308	.owner = THIS_MODULE,
   1309	.dai_link = mt8195_mt6359_dai_links,
   1310	.num_links = ARRAY_SIZE(mt8195_mt6359_dai_links),
   1311	.controls = mt8195_mt6359_controls,
   1312	.num_controls = ARRAY_SIZE(mt8195_mt6359_controls),
   1313	.dapm_widgets = mt8195_mt6359_widgets,
   1314	.num_dapm_widgets = ARRAY_SIZE(mt8195_mt6359_widgets),
   1315	.dapm_routes = mt8195_mt6359_routes,
   1316	.num_dapm_routes = ARRAY_SIZE(mt8195_mt6359_routes),
   1317	.set_bias_level_post = mt8195_set_bias_level_post,
   1318};
   1319
   1320/* fixup the BE DAI link to match any values from topology */
   1321static int mt8195_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
   1322				 struct snd_pcm_hw_params *params)
   1323{
   1324	struct snd_soc_card *card = rtd->card;
   1325	struct snd_soc_dai_link *sof_dai_link = NULL;
   1326	struct snd_soc_pcm_runtime *runtime;
   1327	struct snd_soc_dai *cpu_dai;
   1328	int i, j, ret = 0;
   1329
   1330	for (i = 0; i < ARRAY_SIZE(g_sof_conn_streams); i++) {
   1331		const struct sof_conn_stream *conn = &g_sof_conn_streams[i];
   1332
   1333		if (strcmp(rtd->dai_link->name, conn->normal_link))
   1334			continue;
   1335
   1336		for_each_card_rtds(card, runtime) {
   1337			if (strcmp(runtime->dai_link->name, conn->sof_link))
   1338				continue;
   1339
   1340			for_each_rtd_cpu_dais(runtime, j, cpu_dai) {
   1341				if (cpu_dai->stream_active[conn->stream_dir] > 0) {
   1342					sof_dai_link = runtime->dai_link;
   1343					break;
   1344				}
   1345			}
   1346			break;
   1347		}
   1348
   1349		if (sof_dai_link && sof_dai_link->be_hw_params_fixup)
   1350			ret = sof_dai_link->be_hw_params_fixup(runtime, params);
   1351
   1352		break;
   1353	}
   1354
   1355	if (!strcmp(rtd->dai_link->name, "ETDM2_IN_BE") ||
   1356	    !strcmp(rtd->dai_link->name, "ETDM1_OUT_BE")) {
   1357		mt8195_etdm_hw_params_fixup(runtime, params);
   1358	}
   1359
   1360	return ret;
   1361}
   1362
   1363static int mt8195_mt6359_card_late_probe(struct snd_soc_card *card)
   1364{
   1365	struct snd_soc_pcm_runtime *runtime;
   1366	struct snd_soc_component *sof_comp = NULL;
   1367	int i;
   1368
   1369	/* 1. find sof component */
   1370	for_each_card_rtds(card, runtime) {
   1371		for (i = 0; i < runtime->num_components; i++) {
   1372			if (!runtime->components[i]->driver->name)
   1373				continue;
   1374			if (!strcmp(runtime->components[i]->driver->name, "sof-audio-component")) {
   1375				sof_comp = runtime->components[i];
   1376				break;
   1377			}
   1378		}
   1379	}
   1380
   1381	if (!sof_comp) {
   1382		dev_info(card->dev, " probe without component\n");
   1383		return 0;
   1384	}
   1385	/* 2. add route path and fixup callback */
   1386	for (i = 0; i < ARRAY_SIZE(g_sof_conn_streams); i++) {
   1387		const struct sof_conn_stream *conn = &g_sof_conn_streams[i];
   1388		struct snd_soc_pcm_runtime *sof_rtd = NULL;
   1389		struct snd_soc_pcm_runtime *normal_rtd = NULL;
   1390		struct snd_soc_pcm_runtime *rtd = NULL;
   1391
   1392		for_each_card_rtds(card, rtd) {
   1393			if (!strcmp(rtd->dai_link->name, conn->sof_link)) {
   1394				sof_rtd = rtd;
   1395				continue;
   1396			}
   1397			if (!strcmp(rtd->dai_link->name, conn->normal_link)) {
   1398				normal_rtd = rtd;
   1399				continue;
   1400			}
   1401			if (normal_rtd && sof_rtd)
   1402				break;
   1403		}
   1404		if (normal_rtd && sof_rtd) {
   1405			int j;
   1406			struct snd_soc_dai *cpu_dai;
   1407
   1408			for_each_rtd_cpu_dais(sof_rtd, j, cpu_dai) {
   1409				struct snd_soc_dapm_route route;
   1410				struct snd_soc_dapm_path *p = NULL;
   1411				struct snd_soc_dapm_widget *play_widget =
   1412					cpu_dai->playback_widget;
   1413				struct snd_soc_dapm_widget *cap_widget =
   1414					cpu_dai->capture_widget;
   1415				memset(&route, 0, sizeof(route));
   1416				if (conn->stream_dir == SNDRV_PCM_STREAM_CAPTURE &&
   1417				    cap_widget) {
   1418					snd_soc_dapm_widget_for_each_sink_path(cap_widget, p) {
   1419						route.source = conn->sof_dma;
   1420						route.sink = p->sink->name;
   1421						snd_soc_dapm_add_routes(&card->dapm, &route, 1);
   1422					}
   1423				} else if (conn->stream_dir == SNDRV_PCM_STREAM_PLAYBACK &&
   1424						play_widget){
   1425					snd_soc_dapm_widget_for_each_source_path(play_widget, p) {
   1426						route.source = p->source->name;
   1427						route.sink = conn->sof_dma;
   1428						snd_soc_dapm_add_routes(&card->dapm, &route, 1);
   1429					}
   1430				} else {
   1431					dev_err(cpu_dai->dev, "stream dir and widget not pair\n");
   1432				}
   1433			}
   1434			normal_rtd->dai_link->be_hw_params_fixup = mt8195_dai_link_fixup;
   1435		}
   1436	}
   1437
   1438	return 0;
   1439}
   1440
   1441static int mt8195_dailink_parse_of(struct snd_soc_card *card, struct device_node *np,
   1442				   const char *propname)
   1443{
   1444	struct device *dev = card->dev;
   1445	struct snd_soc_dai_link *link;
   1446	const char *dai_name = NULL;
   1447	int i, j, ret, num_links;
   1448
   1449	num_links = of_property_count_strings(np, "mediatek,dai-link");
   1450
   1451	if (num_links < 0 || num_links > ARRAY_SIZE(mt8195_mt6359_dai_links)) {
   1452		dev_dbg(dev, "number of dai-link is invalid\n");
   1453		return -EINVAL;
   1454	}
   1455
   1456	card->dai_link = devm_kcalloc(dev, num_links, sizeof(*link), GFP_KERNEL);
   1457	if (!card->dai_link)
   1458		return -ENOMEM;
   1459
   1460	card->num_links = 0;
   1461	link = card->dai_link;
   1462
   1463	for (i = 0; i < num_links; i++) {
   1464		ret = of_property_read_string_index(np, propname, i, &dai_name);
   1465		if (ret) {
   1466			dev_dbg(dev, "ASoC: Property '%s' index %d could not be read: %d\n",
   1467				propname, i, ret);
   1468			return -EINVAL;
   1469		}
   1470
   1471		for (j = 0; j < ARRAY_SIZE(mt8195_mt6359_dai_links); j++) {
   1472			if (!strcmp(dai_name, mt8195_mt6359_dai_links[j].name)) {
   1473				memcpy(link, &mt8195_mt6359_dai_links[j],
   1474				       sizeof(struct snd_soc_dai_link));
   1475				link++;
   1476				card->num_links++;
   1477				break;
   1478			}
   1479		}
   1480	}
   1481
   1482	if (card->num_links != num_links)
   1483		return -EINVAL;
   1484
   1485	return 0;
   1486}
   1487
   1488static int mt8195_mt6359_dev_probe(struct platform_device *pdev)
   1489{
   1490	struct snd_soc_card *card = &mt8195_mt6359_soc_card;
   1491	struct snd_soc_dai_link *dai_link;
   1492	struct mt8195_mt6359_priv *priv;
   1493	struct device_node *platform_node, *adsp_node, *dp_node, *hdmi_node;
   1494	struct mt8195_card_data *card_data;
   1495	int is5682s = 0;
   1496	int init6359 = 0;
   1497	int sof_on = 0;
   1498	int ret, i;
   1499
   1500	card_data = (struct mt8195_card_data *)of_device_get_match_data(&pdev->dev);
   1501	card->dev = &pdev->dev;
   1502
   1503	ret = snd_soc_of_parse_card_name(card, "model");
   1504	if (ret) {
   1505		dev_err(&pdev->dev, "%s new card name parsing error %d\n",
   1506			__func__, ret);
   1507		return ret;
   1508	}
   1509
   1510	if (!card->name)
   1511		card->name = card_data->name;
   1512
   1513	if (strstr(card->name, "_5682s"))
   1514		is5682s = 1;
   1515
   1516	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
   1517	if (!priv)
   1518		return -ENOMEM;
   1519
   1520	if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) {
   1521		ret = mt8195_dailink_parse_of(card, pdev->dev.of_node,
   1522					      "mediatek,dai-link");
   1523		if (ret) {
   1524			dev_dbg(&pdev->dev, "Parse dai-link fail\n");
   1525			return -EINVAL;
   1526		}
   1527	} else {
   1528		if (!sof_on)
   1529			card->num_links = DAI_LINK_REGULAR_NUM;
   1530	}
   1531
   1532	platform_node = of_parse_phandle(pdev->dev.of_node,
   1533					 "mediatek,platform", 0);
   1534	if (!platform_node) {
   1535		dev_dbg(&pdev->dev, "Property 'platform' missing or invalid\n");
   1536		return -EINVAL;
   1537	}
   1538
   1539	adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0);
   1540	if (adsp_node)
   1541		sof_on = 1;
   1542
   1543	dp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,dptx-codec", 0);
   1544	hdmi_node = of_parse_phandle(pdev->dev.of_node,
   1545				     "mediatek,hdmi-codec", 0);
   1546
   1547	for_each_card_prelinks(card, i, dai_link) {
   1548		if (!dai_link->platforms->name) {
   1549			if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && sof_on)
   1550				dai_link->platforms->of_node = adsp_node;
   1551			else
   1552				dai_link->platforms->of_node = platform_node;
   1553		}
   1554
   1555		if (strcmp(dai_link->name, "DPTX_BE") == 0) {
   1556			if (!dp_node) {
   1557				dev_dbg(&pdev->dev, "No property 'dptx-codec'\n");
   1558			} else {
   1559				dai_link->codecs->of_node = dp_node;
   1560				dai_link->codecs->name = NULL;
   1561				dai_link->codecs->dai_name = "i2s-hifi";
   1562				dai_link->init = mt8195_dptx_codec_init;
   1563			}
   1564		} else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) {
   1565			if (!hdmi_node) {
   1566				dev_dbg(&pdev->dev, "No property 'hdmi-codec'\n");
   1567			} else {
   1568				dai_link->codecs->of_node = hdmi_node;
   1569				dai_link->codecs->name = NULL;
   1570				dai_link->codecs->dai_name = "i2s-hifi";
   1571				dai_link->init = mt8195_hdmi_codec_init;
   1572			}
   1573		} else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 ||
   1574			   strcmp(dai_link->name, "ETDM2_IN_BE") == 0) {
   1575			dai_link->codecs->name =
   1576				is5682s ? RT5682S_DEV0_NAME : RT5682_DEV0_NAME;
   1577			dai_link->codecs->dai_name =
   1578				is5682s ? RT5682S_CODEC_DAI : RT5682_CODEC_DAI;
   1579		} else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 ||
   1580			   strcmp(dai_link->name, "UL_SRC1_BE") == 0 ||
   1581			   strcmp(dai_link->name, "UL_SRC2_BE") == 0) {
   1582			if (!init6359) {
   1583				dai_link->init = mt8195_mt6359_init;
   1584				init6359 = 1;
   1585			}
   1586		} else if (strcmp(dai_link->name, "ETDM2_OUT_BE") == 0) {
   1587			switch (card_data->quirk) {
   1588			case RT1011_SPEAKER_AMP_PRESENT:
   1589				dai_link->codecs = rt1011_comps;
   1590				dai_link->num_codecs = ARRAY_SIZE(rt1011_comps);
   1591				dai_link->init = mt8195_rt1011_init;
   1592				dai_link->ops = &mt8195_rt1011_etdm_ops;
   1593				dai_link->be_hw_params_fixup = mt8195_etdm_hw_params_fixup;
   1594				card->codec_conf = rt1011_codec_conf;
   1595				card->num_configs = ARRAY_SIZE(rt1011_codec_conf);
   1596				break;
   1597			case RT1019_SPEAKER_AMP_PRESENT:
   1598				dai_link->codecs = rt1019_comps;
   1599				dai_link->num_codecs = ARRAY_SIZE(rt1019_comps);
   1600				dai_link->init = mt8195_rt1019_init;
   1601				break;
   1602			case MAX98390_SPEAKER_AMP_PRESENT:
   1603				dai_link->codecs = max98390_comps;
   1604				dai_link->num_codecs = ARRAY_SIZE(max98390_comps);
   1605				dai_link->init = mt8195_max98390_init;
   1606				card->codec_conf = max98390_codec_conf;
   1607				card->num_configs = ARRAY_SIZE(max98390_codec_conf);
   1608				break;
   1609			default:
   1610				break;
   1611			}
   1612		}
   1613	}
   1614
   1615	if (sof_on)
   1616		card->late_probe = mt8195_mt6359_card_late_probe;
   1617
   1618	snd_soc_card_set_drvdata(card, priv);
   1619
   1620	ret = devm_snd_soc_register_card(&pdev->dev, card);
   1621
   1622	of_node_put(platform_node);
   1623	of_node_put(adsp_node);
   1624	of_node_put(dp_node);
   1625	of_node_put(hdmi_node);
   1626	return ret;
   1627}
   1628
   1629static struct mt8195_card_data mt8195_mt6359_rt1019_rt5682_card = {
   1630	.name = "mt8195_r1019_5682",
   1631	.quirk = RT1019_SPEAKER_AMP_PRESENT,
   1632};
   1633
   1634static struct mt8195_card_data mt8195_mt6359_rt1011_rt5682_card = {
   1635	.name = "mt8195_r1011_5682",
   1636	.quirk = RT1011_SPEAKER_AMP_PRESENT,
   1637};
   1638
   1639static struct mt8195_card_data mt8195_mt6359_max98390_rt5682_card = {
   1640	.name = "mt8195_m98390_r5682",
   1641	.quirk = MAX98390_SPEAKER_AMP_PRESENT,
   1642};
   1643
   1644static const struct of_device_id mt8195_mt6359_dt_match[] = {
   1645	{
   1646		.compatible = "mediatek,mt8195_mt6359_rt1019_rt5682",
   1647		.data = &mt8195_mt6359_rt1019_rt5682_card,
   1648	},
   1649	{
   1650		.compatible = "mediatek,mt8195_mt6359_rt1011_rt5682",
   1651		.data = &mt8195_mt6359_rt1011_rt5682_card,
   1652	},
   1653	{
   1654		.compatible = "mediatek,mt8195_mt6359_max98390_rt5682",
   1655		.data = &mt8195_mt6359_max98390_rt5682_card,
   1656	},
   1657	{},
   1658};
   1659
   1660static const struct dev_pm_ops mt8195_mt6359_pm_ops = {
   1661	.poweroff = snd_soc_poweroff,
   1662	.restore = snd_soc_resume,
   1663};
   1664
   1665static struct platform_driver mt8195_mt6359_driver = {
   1666	.driver = {
   1667		.name = "mt8195_mt6359",
   1668		.of_match_table = mt8195_mt6359_dt_match,
   1669		.pm = &mt8195_mt6359_pm_ops,
   1670	},
   1671	.probe = mt8195_mt6359_dev_probe,
   1672};
   1673
   1674module_platform_driver(mt8195_mt6359_driver);
   1675
   1676/* Module information */
   1677MODULE_DESCRIPTION("MT8195-MT6359 ALSA SoC machine driver");
   1678MODULE_AUTHOR("Trevor Wu <trevor.wu@mediatek.com>");
   1679MODULE_AUTHOR("YC Hung <yc.hung@mediatek.com>");
   1680MODULE_LICENSE("GPL");
   1681MODULE_ALIAS("mt8195_mt6359 soc card");