From 5333aeab6cad67b6ecdd1b718e14181734ee4fbc Mon Sep 17 00:00:00 2001
From: "shangavelan.m" <shangavelan.m@adlinktech.com>
Date: Mon, 3 Nov 2025 16:10:18 +0530
Subject: [PATCH 9/9] LECMTKI1200: sound card hdmi and tlv320 codec

Signed-off-by: shangavelan.m <shangavelan.m@adlinktech.com>
---
 sound/soc/codecs/tlv320aic3x.c         |   9 +
 sound/soc/mediatek/mt8195/mt8395-evk.c | 448 +++++++++----------------
 2 files changed, 161 insertions(+), 296 deletions(-)

diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 7731593a5509..cf3f7e2bdf2b 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -1581,6 +1581,15 @@ static int aic3x_init(struct snd_soc_component *component)
 	switch (aic3x->model) {
 	case AIC3X_MODEL_3X:
 	case AIC3X_MODEL_33:
+#ifdef CONFIG_ARCH_ADLINKTECH
+               snd_soc_component_write(component, DACL1_2_HPLOUT_VOL, 0x80);
+               snd_soc_component_write(component, DACL1_2_HPROUT_VOL, 0x80);
+               snd_soc_component_write(component, MIC3LR_2_LADC_CTRL, 0x0f);
+               snd_soc_component_write(component, LAGC_CTRL_A, 0x80);
+               snd_soc_component_write(component, RAGC_CTRL_A, 0x80);
+        break;
+#endif
+
 	case AIC3X_MODEL_3106:
 		aic3x_mono_init(component);
 		break;
diff --git a/sound/soc/mediatek/mt8195/mt8395-evk.c b/sound/soc/mediatek/mt8195/mt8395-evk.c
index 0d65677adb6c..ad8baa680e38 100644
--- a/sound/soc/mediatek/mt8195/mt8395-evk.c
+++ b/sound/soc/mediatek/mt8195/mt8395-evk.c
@@ -12,89 +12,99 @@
 #include <linux/input.h>
 #include <linux/module.h>
 #include <linux/pm_runtime.h>
-#include <linux/of_device.h>
 #include <sound/jack.h>
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
 #include "../../codecs/mt6359.h"
-#include "../../codecs/mt6359-accdet.h"
 #include "../common/mtk-afe-platform-driver.h"
-#include "../common/mtk-dsp-sof-common.h"
-#include "../common/mtk-soc-card.h"
 #include "../common/mtk-soundcard-driver.h"
 #include "mt8195-afe-clk.h"
 #include "mt8195-afe-common.h"
 
-#define SOF_DMA_DL2 "SOF_DMA_DL2"
-#define SOF_DMA_DL3 "SOF_DMA_DL3"
-#define SOF_DMA_UL4 "SOF_DMA_UL4"
-#define SOF_DMA_UL5 "SOF_DMA_UL5"
-
-struct mt8195_card_data {
-	const char *name;
-	unsigned long quirk;
-};
+#ifdef CONFIG_ARCH_ADLINKTECH 
+#define WM8960_CODEC_DAI		"wm8960-hifi"
+#define WM8960_DEV0_NAME		"wm8960.3-001a"
+#define TLV320AIC3X_CODEC_DAI	"tlv320aic3x-hifi"
+#define TLV320AIC3X_DEV0_NAME	"tlv320aic3x.3-0018"
+#endif
 
 struct mt8195_mt6359_priv {
-	struct snd_soc_jack headset_jack;
 	struct snd_soc_jack dp_jack;
 	struct snd_soc_jack hdmi_jack;
 };
 
-/* Headset jack detection DAPM pins */
-static struct snd_soc_jack_pin mt8195_headset_jack_pins[] = {
-	{
-		.pin = "Headphone Jack",
-		.mask = SND_JACK_HEADPHONE,
-	},
-	{
-		.pin = "Headset Mic",
-		.mask = SND_JACK_MICROPHONE,
-	},
-};
-
-/* HDMI jack detection DAPM pins */
-static struct snd_soc_jack_pin mt8195_hdmi_jack_pins[] = {
-	{
-		.pin = "HDMI",
-		.mask = SND_JACK_LINEOUT,
-	},
-};
-
-/* DP jack detection DAPM pins */
-static struct snd_soc_jack_pin mt8195_dp_jack_pins[] = {
-	{
-		.pin = "DP",
-		.mask = SND_JACK_LINEOUT,
-	},
-};
-
 static const struct snd_soc_dapm_widget mt8195_mt6359_widgets[] = {
+#ifdef CONFIG_ARCH_ADLINKTECH
+	SND_SOC_DAPM_HP("Headphone", NULL),
+	SND_SOC_DAPM_MIC("AMIC", NULL),
+#else
 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
-	SND_SOC_DAPM_SINK("HDMI"),
-	SND_SOC_DAPM_SINK("DP"),
-	SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0),
-	SND_SOC_DAPM_MIXER(SOF_DMA_DL3, SND_SOC_NOPM, 0, 0, NULL, 0),
-	SND_SOC_DAPM_MIXER(SOF_DMA_UL4, SND_SOC_NOPM, 0, 0, NULL, 0),
-	SND_SOC_DAPM_MIXER(SOF_DMA_UL5, SND_SOC_NOPM, 0, 0, NULL, 0),
+#endif
 };
 
 static const struct snd_soc_dapm_route mt8195_mt6359_routes[] = {
+#ifndef CONFIG_ARCH_ADLINKTECH
 	{ "Headphone Jack", NULL, "Headphone L" },
 	{ "Headphone Jack", NULL, "Headphone R" },
 	{ "AIN1", NULL, "Headset Mic" },
-	/* SOF Uplink */
-	{SOF_DMA_UL4, NULL, "O034"},
-	{SOF_DMA_UL4, NULL, "O035"},
-	{SOF_DMA_UL5, NULL, "O036"},
-	{SOF_DMA_UL5, NULL, "O037"},
-	/* SOF Downlink */
-	{"I070", NULL, SOF_DMA_DL2},
-	{"I071", NULL, SOF_DMA_DL2},
-	{"I020", NULL, SOF_DMA_DL3},
-	{"I021", NULL, SOF_DMA_DL3},
+#endif
+};
+
+#ifdef CONFIG_ARCH_ADLINKTECH
+static const struct snd_soc_dapm_route tlv320aic3x_routes[] = {
+	{ "Headphone", NULL, "HPLOUT" },
+	{ "Headphone", NULL, "HPROUT" },
+	{ "MIC3L", NULL, "AMIC" },
+	{ "MIC3R", NULL, "AMIC" },
+};
+
+static const struct snd_soc_dapm_route wm8960_routes[] = {
+	{ "Headphone", NULL, "HP_L" },
+	{ "Headphone", NULL, "HP_R" },
+	{ "LINPUT1", NULL, "AMIC" },
+	{ "RINPUT1", NULL, "AMIC" },
+};
+
+static const struct snd_kcontrol_new mt8195_mt6359_demo_controls[] = {
+	SOC_DAPM_PIN_SWITCH("Headphone"),
+	SOC_DAPM_PIN_SWITCH("AMIC"),
+};
+
+static struct snd_soc_dai_link_component tlv320aic3x_codecs = {
+	.name = TLV320AIC3X_DEV0_NAME,
+	.dai_name = TLV320AIC3X_CODEC_DAI,
+};
+static struct snd_soc_dai_link_component wm8960_codecs = {
+	.name = WM8960_DEV0_NAME,
+	.dai_name = WM8960_CODEC_DAI,
+};
+
+enum {
+    CODEC_TLV320,
+    CODEC_WM8960,
+};
+
+struct codec_config {
+    struct snd_soc_dai_link_component *codecs;
+    const struct snd_soc_dapm_route *routes;
+    int num_routes;
+};
+
+static struct codec_config codecs_config[] = {
+    [CODEC_TLV320] = {
+        .codecs = &tlv320aic3x_codecs,
+        .routes = tlv320aic3x_routes,
+        .num_routes = ARRAY_SIZE(tlv320aic3x_routes),
+    },
+    [CODEC_WM8960] = {
+        .codecs = &wm8960_codecs,
+        .routes = wm8960_routes,
+        .num_routes = ARRAY_SIZE(wm8960_routes),
+    },
+    //... add other codecs here
 };
+#endif
 
 static int mt8195_etdm_hw_params(struct snd_pcm_substream *substream,
 				 struct snd_pcm_hw_params *params)
@@ -103,15 +113,31 @@ static int mt8195_etdm_hw_params(struct snd_pcm_substream *substream,
 	struct snd_soc_card *card = rtd->card;
 	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
 	unsigned int rate = params_rate(params);
+#ifdef CONFIG_ARCH_ADLINKTECH
+	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+	unsigned int mclk_fs_ratio = 256;
+#else
 	unsigned int mclk_fs_ratio = 128;
+#endif
 	unsigned int mclk_fs = rate * mclk_fs_ratio;
 	int ret;
 
 	ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
 	if (ret) {
+		pr_info("Failed to set clk default too");
 		dev_err(card->dev, "failed to set sysclk\n");
 		return ret;
 	}
+	pr_info("print before adlink conf\n");
+#ifdef CONFIG_ARCH_ADLINKTECH
+	pr_info("print before adlink snd_soc_dai_setclk\n");
+	ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk_fs, SND_SOC_CLOCK_IN);
+	if (ret) {
+		pr_info("Couldn't get sys clk\n");
+		dev_err(card->dev, "failed to set codec sysclk\n");
+		return ret;
+	}
+#endif
 
 	return 0;
 }
@@ -125,12 +151,13 @@ static const struct snd_soc_ops mt8195_etdm_ops = {
 
 static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
 {
-	struct snd_soc_component *cmpnt_afe;
+	struct snd_soc_component *cmpnt_afe =
+		snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
 	struct snd_soc_component *cmpnt_codec =
 		asoc_rtd_to_codec(rtd, 0)->component;
-	struct mtk_base_afe *afe;
-	struct mt8195_afe_private *afe_priv;
-	struct mtkaif_param *param;
+	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
+	struct mt8195_afe_private *afe_priv = afe->platform_priv;
+	struct mtkaif_param *param = &afe_priv->mtkaif_params;
 	int phase;
 	unsigned int monitor = 0;
 	int mtkaif_calibration_num_phase;
@@ -144,14 +171,6 @@ static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
 	int mtkaif_phase_cycle[MT8195_MTKAIF_MISO_NUM];
 	int i;
 
-	cmpnt_afe = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
-	if (!cmpnt_afe)
-		return -EINVAL;
-
-	afe = snd_soc_component_get_drvdata(cmpnt_afe);
-	afe_priv = afe->platform_priv;
-	param = &afe_priv->mtkaif_params;
-
 	dev_info(afe->dev, "%s(), start\n", __func__);
 
 	param->mtkaif_calibration_ok = false;
@@ -295,42 +314,15 @@ static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
 
 static int mt8195_mt6359_init(struct snd_soc_pcm_runtime *rtd)
 {
-	struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card);
-	struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv;
-	struct snd_soc_component *cmpnt;
-	struct snd_soc_dai *codec_dai;
-	int i, ret;
-
-	for_each_rtd_codec_dais(rtd, i, codec_dai) {
-		cmpnt = codec_dai->component;
-		if (strcmp(cmpnt->name, "mt6359-sound") == 0) {
-			/* set mtkaif protocol */
-			mt6359_set_mtkaif_protocol(cmpnt,
-						MT6359_MTKAIF_PROTOCOL_2_CLK_P2);
-
-			/* mtkaif calibration */
-			mt8195_mt6359_mtkaif_calibration(rtd);
-		} else if (strcmp(cmpnt->name, "mt6359-accdet") == 0) {
-			ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
-						    SND_JACK_HEADSET | SND_JACK_BTN_0 |
-						    SND_JACK_BTN_1 | SND_JACK_BTN_2 |
-						    SND_JACK_BTN_3,
-						    &priv->headset_jack, mt8195_headset_jack_pins,
-						    ARRAY_SIZE(mt8195_headset_jack_pins));
-			if (ret) {
-				dev_err(rtd->dev, "Headset Jack create failed: %d\n", ret);
-				return ret;
-			}
+	struct snd_soc_component *cmpnt_codec =
+		asoc_rtd_to_codec(rtd, 0)->component;
 
-			ret = mt6359_accdet_enable_jack_detect(cmpnt, &priv->headset_jack);
-			if (ret) {
-				dev_err(rtd->dev, "Headset Jack enable failed: %d\n", ret);
-				return ret;
-			}
-		} else {
-			dev_err(rtd->dev, "Component '%s' is invalid.\n", cmpnt->name);
-		}
-	}
+	/* set mtkaif protocol */
+	mt6359_set_mtkaif_protocol(cmpnt_codec,
+				   MT6359_MTKAIF_PROTOCOL_2_CLK_P2);
+
+	/* mtkaif calibration */
+	mt8195_mt6359_mtkaif_calibration(rtd);
 
 	return 0;
 }
@@ -341,9 +333,11 @@ static int mt8195_etdm_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
 	/* fix BE i2s format to 32bit, clean param mask first */
 	snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
 			     0, SNDRV_PCM_FORMAT_LAST);
-
+#ifdef CONFIG_ARCH_ADLINKTECH
+	params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
+#else
 	params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
-
+#endif
 	return 0;
 }
 
@@ -355,7 +349,7 @@ static int mt8195_dptx_hw_params(struct snd_pcm_substream *substream,
 	unsigned int rate = params_rate(params);
 	unsigned int mclk_fs_ratio = 256;
 	unsigned int mclk_fs = rate * mclk_fs_ratio;
-
+	pr_info("dptx param hw called .. only cpu dai returned\n");
 	return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs,
 				      SND_SOC_CLOCK_OUT);
 }
@@ -366,15 +360,13 @@ static const struct snd_soc_ops mt8195_dptx_ops = {
 
 static int mt8195_dptx_codec_init(struct snd_soc_pcm_runtime *rtd)
 {
-	struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card);
-	struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv;
+	struct mt8195_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
 	struct snd_soc_component *cmpnt_codec =
 		asoc_rtd_to_codec(rtd, 0)->component;
 	int ret;
 
 	ret = snd_soc_card_jack_new(rtd->card, "DP Jack", SND_JACK_LINEOUT,
-				    &priv->dp_jack, mt8195_dp_jack_pins,
-				    ARRAY_SIZE(mt8195_dp_jack_pins));
+				    &priv->dp_jack, NULL, 0);
 	if (ret)
 		return ret;
 
@@ -383,15 +375,13 @@ static int mt8195_dptx_codec_init(struct snd_soc_pcm_runtime *rtd)
 
 static int mt8195_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd)
 {
-	struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card);
-	struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv;
+	struct mt8195_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
 	struct snd_soc_component *cmpnt_codec =
 		asoc_rtd_to_codec(rtd, 0)->component;
 	int ret;
 
 	ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT,
-				    &priv->hdmi_jack, mt8195_hdmi_jack_pins,
-				    ARRAY_SIZE(mt8195_hdmi_jack_pins));
+				    &priv->hdmi_jack, NULL, 0);
 	if (ret)
 		return ret;
 
@@ -421,33 +411,6 @@ static int mt8195_multi_in_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
 	return 0;
 }
 
-static int mt8195_sof_be_hw_params(struct snd_pcm_substream *substream,
-				   struct snd_pcm_hw_params *params)
-{
-	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
-	struct snd_soc_component *cmpnt_afe = NULL;
-	struct snd_soc_pcm_runtime *runtime;
-
-	/* find afe component */
-	for_each_card_rtds(rtd->card, runtime) {
-		cmpnt_afe = snd_soc_rtdcom_lookup(runtime, AFE_PCM_NAME);
-		if (cmpnt_afe)
-			break;
-	}
-
-	if (cmpnt_afe && !pm_runtime_active(cmpnt_afe->dev)) {
-		dev_err(rtd->dev, "afe pm runtime is not active!!\n");
-		return -EINVAL;
-	}
-
-
-	return 0;
-}
-
-static const struct snd_soc_ops mt8195_sof_be_ops = {
-	.hw_params = mt8195_sof_be_hw_params,
-};
-
 enum {
 	DAI_LINK_DL2_FE,
 	DAI_LINK_DL3_FE,
@@ -478,17 +441,8 @@ enum {
 	DAI_LINK_UL_SRC1_BE,
 	DAI_LINK_UL_SRC2_BE,
 	DAI_LINK_DMIC_BE,
-	DAI_LINK_REGULAR_LAST = DAI_LINK_DMIC_BE,
-	DAI_LINK_SOF_START,
-	DAI_LINK_SOF_DL2_BE = DAI_LINK_SOF_START,
-	DAI_LINK_SOF_DL3_BE,
-	DAI_LINK_SOF_UL4_BE,
-	DAI_LINK_SOF_UL5_BE,
-	DAI_LINK_SOF_END = DAI_LINK_SOF_UL5_BE,
 };
 
-#define	DAI_LINK_REGULAR_NUM	(DAI_LINK_REGULAR_LAST + 1)
-
 /* FE */
 SND_SOC_DAILINK_DEFS(DL2_FE,
 		     DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
@@ -636,50 +590,6 @@ SND_SOC_DAILINK_DEFS(DMIC_BE,
 		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
 		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
 
-/* SOF */
-SND_SOC_DAILINK_DEFS(AFE_SOF_DL2,
-		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL2")),
-		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
-		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
-
-SND_SOC_DAILINK_DEFS(AFE_SOF_DL3,
-		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL3")),
-		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
-		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
-
-SND_SOC_DAILINK_DEFS(AFE_SOF_UL4,
-		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL4")),
-		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
-		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
-
-SND_SOC_DAILINK_DEFS(AFE_SOF_UL5,
-		     DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL5")),
-		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
-		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
-
-static const struct sof_conn_stream g_sof_conn_streams[] = {
-	{
-		.sof_link = "AFE_SOF_DL2",
-		.sof_dma = SOF_DMA_DL2,
-		.stream_dir = SNDRV_PCM_STREAM_PLAYBACK
-	},
-	{
-		.sof_link = "AFE_SOF_DL3",
-		.sof_dma = SOF_DMA_DL3,
-		.stream_dir = SNDRV_PCM_STREAM_PLAYBACK
-	},
-	{
-		.sof_link = "AFE_SOF_UL4",
-		.sof_dma = SOF_DMA_UL4,
-		.stream_dir = SNDRV_PCM_STREAM_CAPTURE
-	},
-	{
-		.sof_link = "AFE_SOF_UL5",
-		.sof_dma = SOF_DMA_UL5,
-		.stream_dir = SNDRV_PCM_STREAM_CAPTURE
-	},
-};
-
 static struct snd_soc_dai_link mt8195_mt6359_dai_links[] = {
 	/* FE */
 	[DAI_LINK_DL2_FE] = {
@@ -973,35 +883,6 @@ static struct snd_soc_dai_link mt8195_mt6359_dai_links[] = {
 		.dpcm_capture = 1,
 		SND_SOC_DAILINK_REG(DMIC_BE),
 	},
-	/* SOF BE */
-	[DAI_LINK_SOF_DL2_BE] = {
-		.name = "AFE_SOF_DL2",
-		.no_pcm = 1,
-		.dpcm_playback = 1,
-		.ops = &mt8195_sof_be_ops,
-		SND_SOC_DAILINK_REG(AFE_SOF_DL2),
-	},
-	[DAI_LINK_SOF_DL3_BE] = {
-		.name = "AFE_SOF_DL3",
-		.no_pcm = 1,
-		.dpcm_playback = 1,
-		.ops = &mt8195_sof_be_ops,
-		SND_SOC_DAILINK_REG(AFE_SOF_DL3),
-	},
-	[DAI_LINK_SOF_UL4_BE] = {
-		.name = "AFE_SOF_UL4",
-		.no_pcm = 1,
-		.dpcm_capture = 1,
-		.ops = &mt8195_sof_be_ops,
-		SND_SOC_DAILINK_REG(AFE_SOF_UL4),
-	},
-	[DAI_LINK_SOF_UL5_BE] = {
-		.name = "AFE_SOF_UL5",
-		.no_pcm = 1,
-		.dpcm_capture = 1,
-		.ops = &mt8195_sof_be_ops,
-		SND_SOC_DAILINK_REG(AFE_SOF_UL5),
-	},
 };
 
 static struct snd_soc_card mt8195_mt6359_soc_card = {
@@ -1011,28 +892,56 @@ static struct snd_soc_card mt8195_mt6359_soc_card = {
 	.num_links = ARRAY_SIZE(mt8195_mt6359_dai_links),
 	.dapm_widgets = mt8195_mt6359_widgets,
 	.num_dapm_widgets = ARRAY_SIZE(mt8195_mt6359_widgets),
+#ifndef CONFIG_ARCH_ADLINKTECH
 	.dapm_routes = mt8195_mt6359_routes,
 	.num_dapm_routes = ARRAY_SIZE(mt8195_mt6359_routes),
+#endif
 };
 
 static int mt8195_mt6359_dev_probe(struct platform_device *pdev)
 {
 	struct snd_soc_card *card = &mt8195_mt6359_soc_card;
+	struct device_node *platform_node;
 	struct snd_soc_dai_link *dai_link;
-	struct mtk_soc_card_data *soc_card_data;
-	struct mt8195_mt6359_priv *mach_priv;
-	struct device_node *platform_node, *adsp_node;
-	struct mt8195_card_data *card_data;
+	struct mt8195_mt6359_priv *priv;
 	int init6359 = 0;
-	int sof_on = 0;
 	int ret, i;
-
-	card_data = (struct mt8195_card_data *)of_device_get_match_data(&pdev->dev);
+#ifdef CONFIG_ARCH_ADLINKTECH
+	struct device_node *np = pdev->dev.of_node;
+	struct device_node *tlv320_node, *wm8960_node;
+	bool tlv320_available, wm8960_available;
+	tlv320_node = of_find_node_by_name(NULL, "tlv320aic310x");
+	wm8960_node = of_find_node_by_name(NULL, "wm8960");
+	tlv320_available = of_device_is_available(tlv320_node);
+	wm8960_available = of_device_is_available(wm8960_node);
+#endif
 	card->dev = &pdev->dev;
+#ifdef CONFIG_ARCH_ADLINKTECH
+    struct codec_config *config = NULL;
+
+    if (tlv320_available) {
+        config = &codecs_config[CODEC_TLV320];
+    } else if (wm8960_available) {
+        config = &codecs_config[CODEC_WM8960];
+    } else {
+        // error handling
+    }
+    if(config != NULL) {
+        mt8195_mt6359_dai_links[DAI_LINK_DL_SRC_BE].codecs = config->codecs;
+        mt8195_mt6359_dai_links[DAI_LINK_DL_SRC_BE].num_codecs = 1;
+        mt8195_mt6359_dai_links[DAI_LINK_ETDM2_IN_BE].codecs = config->codecs;
+        mt8195_mt6359_dai_links[DAI_LINK_ETDM2_IN_BE].num_codecs = 1;
+
+        card->dapm_routes = config->routes;
+        card->num_dapm_routes = config->num_routes;
+    }
+#endif
+	
 	ret = set_card_codec_info(card);
 	if (ret) {
-		return dev_err_probe(&pdev->dev, ret, "%s set_card_codec_info failed\n",
-				     __func__);
+		dev_err_probe(&pdev->dev, ret, "%s set_card_codec_info failed\n",
+			     __func__);
+		return ret;
 	}
 
 	ret = snd_soc_of_parse_card_name(card, "model");
@@ -1042,71 +951,21 @@ static int mt8195_mt6359_dev_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	if (!card->name)
-		card->name = card_data->name;
-
-	soc_card_data = devm_kzalloc(&pdev->dev, sizeof(*soc_card_data), GFP_KERNEL);
-	if (!soc_card_data)
+	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
 		return -ENOMEM;
 
-	mach_priv = devm_kzalloc(&pdev->dev, sizeof(*mach_priv), GFP_KERNEL);
-	if (!mach_priv)
-		return -ENOMEM;
-
-	soc_card_data->mach_priv = mach_priv;
-
-	adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0);
-	if (adsp_node) {
-		struct mtk_sof_priv *sof_priv;
-
-		sof_priv = devm_kzalloc(&pdev->dev, sizeof(*sof_priv), GFP_KERNEL);
-		if (!sof_priv) {
-			ret = -ENOMEM;
-			goto err_kzalloc;
-		}
-		sof_priv->conn_streams = g_sof_conn_streams;
-		sof_priv->num_streams = ARRAY_SIZE(g_sof_conn_streams);
-		soc_card_data->sof_priv = sof_priv;
-		card->probe = mtk_sof_card_probe;
-		card->late_probe = mtk_sof_card_late_probe;
-		if (!card->topology_shortname_created) {
-			snprintf(card->topology_shortname, 32, "sof-%s", card->name);
-			card->topology_shortname_created = true;
-		}
-		card->name = card->topology_shortname;
-		sof_on = 1;
-	}
-
-	if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) {
-		ret = mtk_sof_dailink_parse_of(card, pdev->dev.of_node,
-					       "mediatek,dai-link",
-					       mt8195_mt6359_dai_links,
-					       ARRAY_SIZE(mt8195_mt6359_dai_links));
-		if (ret) {
-			dev_dbg(&pdev->dev, "Parse dai-link fail\n");
-			goto err_parse_of;
-		}
-	} else {
-		if (!sof_on)
-			card->num_links = DAI_LINK_REGULAR_NUM;
-	}
-
 	platform_node = of_parse_phandle(pdev->dev.of_node,
 					 "mediatek,platform", 0);
 
 	if (!platform_node) {
 		dev_dbg(&pdev->dev, "Property 'platform' missing or invalid\n");
-		ret = -EINVAL;
-		goto err_platform_node;
+		return -EINVAL;
 	}
 
 	for_each_card_prelinks(card, i, dai_link) {
-		if (!dai_link->platforms->name) {
-			if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && sof_on)
-				dai_link->platforms->of_node = adsp_node;
-			else
-				dai_link->platforms->of_node = platform_node;
-		}
+		if (!dai_link->platforms->name)
+			dai_link->platforms->of_node = platform_node;
 
 		if (strcmp(dai_link->name, "DPTX_BE") == 0) {
 			if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai"))
@@ -1126,15 +985,12 @@ static int mt8195_mt6359_dev_probe(struct platform_device *pdev)
 		}
 	}
 
-	snd_soc_card_set_drvdata(card, soc_card_data);
+	snd_soc_card_set_drvdata(card, priv);
 
 	ret = devm_snd_soc_register_card(&pdev->dev, card);
-
-	of_node_put(platform_node);
-err_kzalloc:
-err_parse_of:
-err_platform_node:
-	of_node_put(adsp_node);
+	if (ret)
+		dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n",
+			     __func__);
 	return ret;
 }
 
-- 
2.43.0

