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

mt8192-mt6359-rt1015-rt5682.c (34722B)


      1// SPDX-License-Identifier: GPL-2.0
      2//
      3// mt8192-mt6359-rt1015-rt5682.c  --
      4//	MT8192-MT6359-RT1015-RT6358 ALSA SoC machine driver
      5//
      6// Copyright (c) 2020 MediaTek Inc.
      7// Author: Jiaxin Yu <jiaxin.yu@mediatek.com>
      8//
      9
     10#include <linux/input.h>
     11#include <linux/module.h>
     12#include <linux/of_device.h>
     13#include <linux/pm_runtime.h>
     14#include <sound/jack.h>
     15#include <sound/pcm_params.h>
     16#include <sound/rt5682.h>
     17#include <sound/soc.h>
     18
     19#include "../../codecs/mt6359.h"
     20#include "../../codecs/rt1015.h"
     21#include "../../codecs/rt5682.h"
     22#include "../common/mtk-afe-platform-driver.h"
     23#include "mt8192-afe-common.h"
     24#include "mt8192-afe-clk.h"
     25#include "mt8192-afe-gpio.h"
     26
     27#define RT1015_CODEC_DAI	"rt1015-aif"
     28#define RT1015_DEV0_NAME	"rt1015.1-0028"
     29#define RT1015_DEV1_NAME	"rt1015.1-0029"
     30
     31#define RT1015_RT5682_CARD_NAME "mt8192_mt6359_rt1015_rt5682"
     32#define RT1015P_RT5682_CARD_NAME "mt8192_mt6359_rt1015p_rt5682"
     33#define RT1015P_RT5682S_CARD_NAME "mt8192_mt6359_rt1015p_rt5682s"
     34
     35#define RT1015_RT5682_OF_NAME "mediatek,mt8192_mt6359_rt1015_rt5682"
     36#define RT1015P_RT5682_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682"
     37#define RT1015P_RT5682S_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682s"
     38
     39struct mt8192_mt6359_priv {
     40	struct snd_soc_jack headset_jack;
     41	struct snd_soc_jack hdmi_jack;
     42};
     43
     44static int mt8192_rt1015_i2s_hw_params(struct snd_pcm_substream *substream,
     45				       struct snd_pcm_hw_params *params)
     46{
     47	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
     48	struct snd_soc_card *card = rtd->card;
     49	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
     50	struct snd_soc_dai *codec_dai;
     51	unsigned int rate = params_rate(params);
     52	unsigned int mclk_fs_ratio = 128;
     53	unsigned int mclk_fs = rate * mclk_fs_ratio;
     54	int ret, i;
     55
     56	for_each_rtd_codec_dais(rtd, i, codec_dai) {
     57		ret = snd_soc_dai_set_pll(codec_dai, 0,
     58					  RT1015_PLL_S_BCLK,
     59					  params_rate(params) * 64,
     60					  params_rate(params) * 256);
     61		if (ret) {
     62			dev_err(card->dev, "failed to set pll\n");
     63			return ret;
     64		}
     65
     66		ret = snd_soc_dai_set_sysclk(codec_dai,
     67					     RT1015_SCLK_S_PLL,
     68					     params_rate(params) * 256,
     69					     SND_SOC_CLOCK_IN);
     70		if (ret) {
     71			dev_err(card->dev, "failed to set sysclk\n");
     72			return ret;
     73		}
     74	}
     75
     76	return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
     77}
     78
     79static int mt8192_rt5682x_i2s_hw_params(struct snd_pcm_substream *substream,
     80					struct snd_pcm_hw_params *params)
     81{
     82	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
     83	struct snd_soc_card *card = rtd->card;
     84	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
     85	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
     86	unsigned int rate = params_rate(params);
     87	unsigned int mclk_fs_ratio = 128;
     88	unsigned int mclk_fs = rate * mclk_fs_ratio;
     89	int bitwidth;
     90	int ret;
     91
     92	bitwidth = snd_pcm_format_width(params_format(params));
     93	if (bitwidth < 0) {
     94		dev_err(card->dev, "invalid bit width: %d\n", bitwidth);
     95		return bitwidth;
     96	}
     97
     98	ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth);
     99	if (ret) {
    100		dev_err(card->dev, "failed to set tdm slot\n");
    101		return ret;
    102	}
    103
    104	ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1,
    105				  RT5682_PLL1_S_BCLK1,
    106				  params_rate(params) * 64,
    107				  params_rate(params) * 512);
    108	if (ret) {
    109		dev_err(card->dev, "failed to set pll\n");
    110		return ret;
    111	}
    112
    113	ret = snd_soc_dai_set_sysclk(codec_dai,
    114				     RT5682_SCLK_S_PLL1,
    115				     params_rate(params) * 512,
    116				     SND_SOC_CLOCK_IN);
    117	if (ret) {
    118		dev_err(card->dev, "failed to set sysclk\n");
    119		return ret;
    120	}
    121
    122	return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
    123}
    124
    125static const struct snd_soc_ops mt8192_rt1015_i2s_ops = {
    126	.hw_params = mt8192_rt1015_i2s_hw_params,
    127};
    128
    129static const struct snd_soc_ops mt8192_rt5682x_i2s_ops = {
    130	.hw_params = mt8192_rt5682x_i2s_hw_params,
    131};
    132
    133static int mt8192_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
    134{
    135	struct snd_soc_component *cmpnt_afe =
    136		snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
    137	struct snd_soc_component *cmpnt_codec =
    138		asoc_rtd_to_codec(rtd, 0)->component;
    139	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
    140	struct mt8192_afe_private *afe_priv = afe->platform_priv;
    141	int phase;
    142	unsigned int monitor;
    143	int test_done_1, test_done_2, test_done_3;
    144	int cycle_1, cycle_2, cycle_3;
    145	int prev_cycle_1, prev_cycle_2, prev_cycle_3;
    146	int chosen_phase_1, chosen_phase_2, chosen_phase_3;
    147	int counter;
    148	int mtkaif_calib_ok;
    149
    150	dev_info(afe->dev, "%s(), start\n", __func__);
    151
    152	pm_runtime_get_sync(afe->dev);
    153	mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 1);
    154	mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 0);
    155	mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 1);
    156	mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 0);
    157
    158	mt6359_mtkaif_calibration_enable(cmpnt_codec);
    159
    160	/* set clock protocol 2 */
    161	regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38);
    162	regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x39);
    163
    164	/* set test type to synchronizer pulse */
    165	regmap_update_bits(afe_priv->topckgen,
    166			   CKSYS_AUD_TOP_CFG, 0xffff, 0x4);
    167
    168	mtkaif_calib_ok = true;
    169	afe_priv->mtkaif_calibration_num_phase = 42;	/* mt6359: 0 ~ 42 */
    170	afe_priv->mtkaif_chosen_phase[0] = -1;
    171	afe_priv->mtkaif_chosen_phase[1] = -1;
    172	afe_priv->mtkaif_chosen_phase[2] = -1;
    173
    174	for (phase = 0;
    175	     phase <= afe_priv->mtkaif_calibration_num_phase &&
    176	     mtkaif_calib_ok;
    177	     phase++) {
    178		mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
    179						    phase, phase, phase);
    180
    181		regmap_update_bits(afe_priv->topckgen,
    182				   CKSYS_AUD_TOP_CFG, 0x1, 0x1);
    183
    184		test_done_1 = 0;
    185		test_done_2 = 0;
    186		test_done_3 = 0;
    187		cycle_1 = -1;
    188		cycle_2 = -1;
    189		cycle_3 = -1;
    190		counter = 0;
    191		while (test_done_1 == 0 ||
    192		       test_done_2 == 0 ||
    193		       test_done_3 == 0) {
    194			regmap_read(afe_priv->topckgen,
    195				    CKSYS_AUD_TOP_MON, &monitor);
    196
    197			test_done_1 = (monitor >> 28) & 0x1;
    198			test_done_2 = (monitor >> 29) & 0x1;
    199			test_done_3 = (monitor >> 30) & 0x1;
    200			if (test_done_1 == 1)
    201				cycle_1 = monitor & 0xf;
    202
    203			if (test_done_2 == 1)
    204				cycle_2 = (monitor >> 4) & 0xf;
    205
    206			if (test_done_3 == 1)
    207				cycle_3 = (monitor >> 8) & 0xf;
    208
    209			/* handle if never test done */
    210			if (++counter > 10000) {
    211				dev_err(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n",
    212					__func__,
    213					cycle_1, cycle_2, cycle_3, monitor);
    214				mtkaif_calib_ok = false;
    215				break;
    216			}
    217		}
    218
    219		if (phase == 0) {
    220			prev_cycle_1 = cycle_1;
    221			prev_cycle_2 = cycle_2;
    222			prev_cycle_3 = cycle_3;
    223		}
    224
    225		if (cycle_1 != prev_cycle_1 &&
    226		    afe_priv->mtkaif_chosen_phase[0] < 0) {
    227			afe_priv->mtkaif_chosen_phase[0] = phase - 1;
    228			afe_priv->mtkaif_phase_cycle[0] = prev_cycle_1;
    229		}
    230
    231		if (cycle_2 != prev_cycle_2 &&
    232		    afe_priv->mtkaif_chosen_phase[1] < 0) {
    233			afe_priv->mtkaif_chosen_phase[1] = phase - 1;
    234			afe_priv->mtkaif_phase_cycle[1] = prev_cycle_2;
    235		}
    236
    237		if (cycle_3 != prev_cycle_3 &&
    238		    afe_priv->mtkaif_chosen_phase[2] < 0) {
    239			afe_priv->mtkaif_chosen_phase[2] = phase - 1;
    240			afe_priv->mtkaif_phase_cycle[2] = prev_cycle_3;
    241		}
    242
    243		regmap_update_bits(afe_priv->topckgen,
    244				   CKSYS_AUD_TOP_CFG, 0x1, 0x0);
    245
    246		if (afe_priv->mtkaif_chosen_phase[0] >= 0 &&
    247		    afe_priv->mtkaif_chosen_phase[1] >= 0 &&
    248		    afe_priv->mtkaif_chosen_phase[2] >= 0)
    249			break;
    250	}
    251
    252	if (afe_priv->mtkaif_chosen_phase[0] < 0)
    253		chosen_phase_1 = 0;
    254	else
    255		chosen_phase_1 = afe_priv->mtkaif_chosen_phase[0];
    256
    257	if (afe_priv->mtkaif_chosen_phase[1] < 0)
    258		chosen_phase_2 = 0;
    259	else
    260		chosen_phase_2 = afe_priv->mtkaif_chosen_phase[1];
    261
    262	if (afe_priv->mtkaif_chosen_phase[2] < 0)
    263		chosen_phase_3 = 0;
    264	else
    265		chosen_phase_3 = afe_priv->mtkaif_chosen_phase[2];
    266
    267	mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
    268					    chosen_phase_1,
    269					    chosen_phase_2,
    270					    chosen_phase_3);
    271
    272	/* disable rx fifo */
    273	regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38);
    274
    275	mt6359_mtkaif_calibration_disable(cmpnt_codec);
    276
    277	mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 1);
    278	mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 0);
    279	mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 1);
    280	mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 0);
    281	pm_runtime_put(afe->dev);
    282
    283	dev_info(afe->dev, "%s(), mtkaif_chosen_phase[0/1/2]:%d/%d/%d\n",
    284		 __func__,
    285		 afe_priv->mtkaif_chosen_phase[0],
    286		 afe_priv->mtkaif_chosen_phase[1],
    287		 afe_priv->mtkaif_chosen_phase[2]);
    288
    289	return 0;
    290}
    291
    292static int mt8192_mt6359_init(struct snd_soc_pcm_runtime *rtd)
    293{
    294	struct snd_soc_component *cmpnt_afe =
    295		snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
    296	struct snd_soc_component *cmpnt_codec =
    297		asoc_rtd_to_codec(rtd, 0)->component;
    298	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
    299	struct mt8192_afe_private *afe_priv = afe->platform_priv;
    300
    301	/* set mtkaif protocol */
    302	mt6359_set_mtkaif_protocol(cmpnt_codec,
    303				   MT6359_MTKAIF_PROTOCOL_2_CLK_P2);
    304	afe_priv->mtkaif_protocol = MTKAIF_PROTOCOL_2_CLK_P2;
    305
    306	/* mtkaif calibration */
    307	mt8192_mt6359_mtkaif_calibration(rtd);
    308
    309	return 0;
    310}
    311
    312static int mt8192_rt5682_init(struct snd_soc_pcm_runtime *rtd)
    313{
    314	struct snd_soc_component *cmpnt_codec =
    315		asoc_rtd_to_codec(rtd, 0)->component;
    316	struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
    317	struct snd_soc_jack *jack = &priv->headset_jack;
    318	int ret;
    319
    320	ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
    321				    SND_JACK_HEADSET | SND_JACK_BTN_0 |
    322				    SND_JACK_BTN_1 | SND_JACK_BTN_2 |
    323				    SND_JACK_BTN_3,
    324				    jack);
    325	if (ret) {
    326		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
    327		return ret;
    328	}
    329
    330	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
    331	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
    332	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
    333	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
    334
    335	return snd_soc_component_set_jack(cmpnt_codec, jack, NULL);
    336};
    337
    338static int mt8192_mt6359_hdmi_init(struct snd_soc_pcm_runtime *rtd)
    339{
    340	struct snd_soc_component *cmpnt_codec =
    341		asoc_rtd_to_codec(rtd, 0)->component;
    342	struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
    343	int ret;
    344
    345	ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT,
    346				    &priv->hdmi_jack);
    347	if (ret) {
    348		dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret);
    349		return ret;
    350	}
    351
    352	return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL);
    353}
    354
    355static int mt8192_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
    356				      struct snd_pcm_hw_params *params)
    357{
    358	/* fix BE i2s format to S24_LE, clean param mask first */
    359	snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
    360			     0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST);
    361
    362	params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
    363
    364	return 0;
    365}
    366
    367static int
    368mt8192_mt6359_cap1_startup(struct snd_pcm_substream *substream)
    369{
    370	static const unsigned int channels[] = {
    371		1, 2, 4
    372	};
    373	static const struct snd_pcm_hw_constraint_list constraints_channels = {
    374		.count = ARRAY_SIZE(channels),
    375		.list = channels,
    376		.mask = 0,
    377	};
    378	static const unsigned int rates[] = {
    379		8000, 16000, 32000, 48000, 96000, 192000
    380	};
    381	static const struct snd_pcm_hw_constraint_list constraints_rates = {
    382		.count = ARRAY_SIZE(rates),
    383		.list  = rates,
    384		.mask = 0,
    385	};
    386
    387	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
    388	struct snd_pcm_runtime *runtime = substream->runtime;
    389	int ret;
    390
    391	ret = snd_pcm_hw_constraint_list(runtime, 0,
    392					 SNDRV_PCM_HW_PARAM_CHANNELS,
    393					 &constraints_channels);
    394	if (ret < 0) {
    395		dev_err(rtd->dev, "hw_constraint_list channels failed\n");
    396		return ret;
    397	}
    398
    399	ret = snd_pcm_hw_constraint_list(runtime, 0,
    400					 SNDRV_PCM_HW_PARAM_RATE,
    401					 &constraints_rates);
    402	if (ret < 0) {
    403		dev_err(rtd->dev, "hw_constraint_list rate failed\n");
    404		return ret;
    405	}
    406
    407	return 0;
    408}
    409
    410static const struct snd_soc_ops mt8192_mt6359_capture1_ops = {
    411	.startup = mt8192_mt6359_cap1_startup,
    412};
    413
    414static int
    415mt8192_mt6359_rt5682_startup(struct snd_pcm_substream *substream)
    416{
    417	static const unsigned int channels[] = {
    418		1, 2
    419	};
    420	static const struct snd_pcm_hw_constraint_list constraints_channels = {
    421		.count = ARRAY_SIZE(channels),
    422		.list = channels,
    423		.mask = 0,
    424	};
    425	static const unsigned int rates[] = {
    426		48000
    427	};
    428	static const struct snd_pcm_hw_constraint_list constraints_rates = {
    429		.count = ARRAY_SIZE(rates),
    430		.list  = rates,
    431		.mask = 0,
    432	};
    433
    434	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
    435	struct snd_pcm_runtime *runtime = substream->runtime;
    436	int ret;
    437
    438	ret = snd_pcm_hw_constraint_list(runtime, 0,
    439					 SNDRV_PCM_HW_PARAM_CHANNELS,
    440					 &constraints_channels);
    441	if (ret < 0) {
    442		dev_err(rtd->dev, "hw_constraint_list channels failed\n");
    443		return ret;
    444	}
    445
    446	ret = snd_pcm_hw_constraint_list(runtime, 0,
    447					 SNDRV_PCM_HW_PARAM_RATE,
    448					 &constraints_rates);
    449	if (ret < 0) {
    450		dev_err(rtd->dev, "hw_constraint_list rate failed\n");
    451		return ret;
    452	}
    453
    454	return 0;
    455}
    456
    457static const struct snd_soc_ops mt8192_mt6359_rt5682_ops = {
    458	.startup = mt8192_mt6359_rt5682_startup,
    459};
    460
    461/* FE */
    462SND_SOC_DAILINK_DEFS(playback1,
    463		     DAILINK_COMP_ARRAY(COMP_CPU("DL1")),
    464		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    465		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    466
    467SND_SOC_DAILINK_DEFS(playback12,
    468		     DAILINK_COMP_ARRAY(COMP_CPU("DL12")),
    469		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    470		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    471
    472SND_SOC_DAILINK_DEFS(playback2,
    473		     DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
    474		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    475		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    476
    477SND_SOC_DAILINK_DEFS(playback3,
    478		     DAILINK_COMP_ARRAY(COMP_CPU("DL3")),
    479		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    480		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    481
    482SND_SOC_DAILINK_DEFS(playback4,
    483		     DAILINK_COMP_ARRAY(COMP_CPU("DL4")),
    484		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    485		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    486
    487SND_SOC_DAILINK_DEFS(playback5,
    488		     DAILINK_COMP_ARRAY(COMP_CPU("DL5")),
    489		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    490		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    491
    492SND_SOC_DAILINK_DEFS(playback6,
    493		     DAILINK_COMP_ARRAY(COMP_CPU("DL6")),
    494		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    495		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    496
    497SND_SOC_DAILINK_DEFS(playback7,
    498		     DAILINK_COMP_ARRAY(COMP_CPU("DL7")),
    499		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    500		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    501
    502SND_SOC_DAILINK_DEFS(playback8,
    503		     DAILINK_COMP_ARRAY(COMP_CPU("DL8")),
    504		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    505		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    506
    507SND_SOC_DAILINK_DEFS(playback9,
    508		     DAILINK_COMP_ARRAY(COMP_CPU("DL9")),
    509		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    510		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    511
    512SND_SOC_DAILINK_DEFS(capture1,
    513		     DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
    514		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    515		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    516
    517SND_SOC_DAILINK_DEFS(capture2,
    518		     DAILINK_COMP_ARRAY(COMP_CPU("UL2")),
    519		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    520		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    521
    522SND_SOC_DAILINK_DEFS(capture3,
    523		     DAILINK_COMP_ARRAY(COMP_CPU("UL3")),
    524		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    525		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    526
    527SND_SOC_DAILINK_DEFS(capture4,
    528		     DAILINK_COMP_ARRAY(COMP_CPU("UL4")),
    529		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    530		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    531
    532SND_SOC_DAILINK_DEFS(capture5,
    533		     DAILINK_COMP_ARRAY(COMP_CPU("UL5")),
    534		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    535		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    536
    537SND_SOC_DAILINK_DEFS(capture6,
    538		     DAILINK_COMP_ARRAY(COMP_CPU("UL6")),
    539		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    540		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    541
    542SND_SOC_DAILINK_DEFS(capture7,
    543		     DAILINK_COMP_ARRAY(COMP_CPU("UL7")),
    544		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    545		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    546
    547SND_SOC_DAILINK_DEFS(capture8,
    548		     DAILINK_COMP_ARRAY(COMP_CPU("UL8")),
    549		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    550		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    551
    552SND_SOC_DAILINK_DEFS(capture_mono1,
    553		     DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_1")),
    554		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    555		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    556
    557SND_SOC_DAILINK_DEFS(capture_mono2,
    558		     DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_2")),
    559		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    560		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    561
    562SND_SOC_DAILINK_DEFS(capture_mono3,
    563		     DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_3")),
    564		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    565		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    566
    567SND_SOC_DAILINK_DEFS(playback_hdmi,
    568		     DAILINK_COMP_ARRAY(COMP_CPU("HDMI")),
    569		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    570		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    571
    572/* BE */
    573SND_SOC_DAILINK_DEFS(primary_codec,
    574		     DAILINK_COMP_ARRAY(COMP_CPU("ADDA")),
    575		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
    576						   "mt6359-snd-codec-aif1"),
    577					COMP_CODEC("dmic-codec",
    578						   "dmic-hifi")),
    579		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    580
    581SND_SOC_DAILINK_DEFS(primary_codec_ch34,
    582		     DAILINK_COMP_ARRAY(COMP_CPU("ADDA_CH34")),
    583		     DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
    584						   "mt6359-snd-codec-aif2")),
    585		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    586
    587SND_SOC_DAILINK_DEFS(ap_dmic,
    588		     DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC")),
    589		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    590		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    591
    592SND_SOC_DAILINK_DEFS(ap_dmic_ch34,
    593		     DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC_CH34")),
    594		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    595		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    596
    597SND_SOC_DAILINK_DEFS(i2s0,
    598		     DAILINK_COMP_ARRAY(COMP_CPU("I2S0")),
    599		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    600		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    601
    602SND_SOC_DAILINK_DEFS(i2s1,
    603		     DAILINK_COMP_ARRAY(COMP_CPU("I2S1")),
    604		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    605		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    606
    607SND_SOC_DAILINK_DEFS(i2s2,
    608		     DAILINK_COMP_ARRAY(COMP_CPU("I2S2")),
    609		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    610		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    611
    612SND_SOC_DAILINK_DEFS(i2s3,
    613		     DAILINK_COMP_ARRAY(COMP_CPU("I2S3")),
    614		     DAILINK_COMP_ARRAY(COMP_EMPTY()),
    615		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    616
    617SND_SOC_DAILINK_DEFS(i2s5,
    618		     DAILINK_COMP_ARRAY(COMP_CPU("I2S5")),
    619		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    620		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    621
    622SND_SOC_DAILINK_DEFS(i2s6,
    623		     DAILINK_COMP_ARRAY(COMP_CPU("I2S6")),
    624		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    625		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    626
    627SND_SOC_DAILINK_DEFS(i2s7,
    628		     DAILINK_COMP_ARRAY(COMP_CPU("I2S7")),
    629		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    630		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    631
    632SND_SOC_DAILINK_DEFS(i2s8,
    633		     DAILINK_COMP_ARRAY(COMP_CPU("I2S8")),
    634		     DAILINK_COMP_ARRAY(COMP_EMPTY()),
    635		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    636
    637SND_SOC_DAILINK_DEFS(i2s9,
    638		     DAILINK_COMP_ARRAY(COMP_CPU("I2S9")),
    639		     DAILINK_COMP_ARRAY(COMP_EMPTY()),
    640		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    641
    642SND_SOC_DAILINK_DEFS(connsys_i2s,
    643		     DAILINK_COMP_ARRAY(COMP_CPU("CONNSYS_I2S")),
    644		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    645		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    646
    647SND_SOC_DAILINK_DEFS(pcm1,
    648		     DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")),
    649		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    650		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    651
    652SND_SOC_DAILINK_DEFS(pcm2,
    653		     DAILINK_COMP_ARRAY(COMP_CPU("PCM 2")),
    654		     DAILINK_COMP_ARRAY(COMP_DUMMY()),
    655		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    656
    657SND_SOC_DAILINK_DEFS(tdm,
    658		     DAILINK_COMP_ARRAY(COMP_CPU("TDM")),
    659		     DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "i2s-hifi")),
    660		     DAILINK_COMP_ARRAY(COMP_EMPTY()));
    661
    662static struct snd_soc_dai_link mt8192_mt6359_dai_links[] = {
    663	/* Front End DAI links */
    664	{
    665		.name = "Playback_1",
    666		.stream_name = "Playback_1",
    667		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    668			    SND_SOC_DPCM_TRIGGER_PRE},
    669		.dynamic = 1,
    670		.dpcm_playback = 1,
    671		SND_SOC_DAILINK_REG(playback1),
    672	},
    673	{
    674		.name = "Playback_12",
    675		.stream_name = "Playback_12",
    676		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    677			    SND_SOC_DPCM_TRIGGER_PRE},
    678		.dynamic = 1,
    679		.dpcm_playback = 1,
    680		SND_SOC_DAILINK_REG(playback12),
    681	},
    682	{
    683		.name = "Playback_2",
    684		.stream_name = "Playback_2",
    685		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    686			    SND_SOC_DPCM_TRIGGER_PRE},
    687		.dynamic = 1,
    688		.dpcm_playback = 1,
    689		SND_SOC_DAILINK_REG(playback2),
    690	},
    691	{
    692		.name = "Playback_3",
    693		.stream_name = "Playback_3",
    694		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    695			    SND_SOC_DPCM_TRIGGER_PRE},
    696		.dynamic = 1,
    697		.dpcm_playback = 1,
    698		.ops = &mt8192_mt6359_rt5682_ops,
    699		SND_SOC_DAILINK_REG(playback3),
    700	},
    701	{
    702		.name = "Playback_4",
    703		.stream_name = "Playback_4",
    704		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    705			    SND_SOC_DPCM_TRIGGER_PRE},
    706		.dynamic = 1,
    707		.dpcm_playback = 1,
    708		SND_SOC_DAILINK_REG(playback4),
    709	},
    710	{
    711		.name = "Playback_5",
    712		.stream_name = "Playback_5",
    713		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    714			    SND_SOC_DPCM_TRIGGER_PRE},
    715		.dynamic = 1,
    716		.dpcm_playback = 1,
    717		SND_SOC_DAILINK_REG(playback5),
    718	},
    719	{
    720		.name = "Playback_6",
    721		.stream_name = "Playback_6",
    722		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    723			    SND_SOC_DPCM_TRIGGER_PRE},
    724		.dynamic = 1,
    725		.dpcm_playback = 1,
    726		SND_SOC_DAILINK_REG(playback6),
    727	},
    728	{
    729		.name = "Playback_7",
    730		.stream_name = "Playback_7",
    731		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    732			    SND_SOC_DPCM_TRIGGER_PRE},
    733		.dynamic = 1,
    734		.dpcm_playback = 1,
    735		SND_SOC_DAILINK_REG(playback7),
    736	},
    737	{
    738		.name = "Playback_8",
    739		.stream_name = "Playback_8",
    740		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    741			    SND_SOC_DPCM_TRIGGER_PRE},
    742		.dynamic = 1,
    743		.dpcm_playback = 1,
    744		SND_SOC_DAILINK_REG(playback8),
    745	},
    746	{
    747		.name = "Playback_9",
    748		.stream_name = "Playback_9",
    749		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    750			    SND_SOC_DPCM_TRIGGER_PRE},
    751		.dynamic = 1,
    752		.dpcm_playback = 1,
    753		SND_SOC_DAILINK_REG(playback9),
    754	},
    755	{
    756		.name = "Capture_1",
    757		.stream_name = "Capture_1",
    758		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    759			    SND_SOC_DPCM_TRIGGER_PRE},
    760		.dynamic = 1,
    761		.dpcm_capture = 1,
    762		.ops = &mt8192_mt6359_capture1_ops,
    763		SND_SOC_DAILINK_REG(capture1),
    764	},
    765	{
    766		.name = "Capture_2",
    767		.stream_name = "Capture_2",
    768		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    769			    SND_SOC_DPCM_TRIGGER_PRE},
    770		.dynamic = 1,
    771		.dpcm_capture = 1,
    772		.ops = &mt8192_mt6359_rt5682_ops,
    773		SND_SOC_DAILINK_REG(capture2),
    774	},
    775	{
    776		.name = "Capture_3",
    777		.stream_name = "Capture_3",
    778		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    779			    SND_SOC_DPCM_TRIGGER_PRE},
    780		.dynamic = 1,
    781		.dpcm_capture = 1,
    782		SND_SOC_DAILINK_REG(capture3),
    783	},
    784	{
    785		.name = "Capture_4",
    786		.stream_name = "Capture_4",
    787		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    788			    SND_SOC_DPCM_TRIGGER_PRE},
    789		.dynamic = 1,
    790		.dpcm_capture = 1,
    791		SND_SOC_DAILINK_REG(capture4),
    792	},
    793	{
    794		.name = "Capture_5",
    795		.stream_name = "Capture_5",
    796		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    797			    SND_SOC_DPCM_TRIGGER_PRE},
    798		.dynamic = 1,
    799		.dpcm_capture = 1,
    800		SND_SOC_DAILINK_REG(capture5),
    801	},
    802	{
    803		.name = "Capture_6",
    804		.stream_name = "Capture_6",
    805		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    806			    SND_SOC_DPCM_TRIGGER_PRE},
    807		.dynamic = 1,
    808		.dpcm_capture = 1,
    809		SND_SOC_DAILINK_REG(capture6),
    810	},
    811	{
    812		.name = "Capture_7",
    813		.stream_name = "Capture_7",
    814		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    815			    SND_SOC_DPCM_TRIGGER_PRE},
    816		.dynamic = 1,
    817		.dpcm_capture = 1,
    818		SND_SOC_DAILINK_REG(capture7),
    819	},
    820	{
    821		.name = "Capture_8",
    822		.stream_name = "Capture_8",
    823		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    824			    SND_SOC_DPCM_TRIGGER_PRE},
    825		.dynamic = 1,
    826		.dpcm_capture = 1,
    827		SND_SOC_DAILINK_REG(capture8),
    828	},
    829	{
    830		.name = "Capture_Mono_1",
    831		.stream_name = "Capture_Mono_1",
    832		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    833			    SND_SOC_DPCM_TRIGGER_PRE},
    834		.dynamic = 1,
    835		.dpcm_capture = 1,
    836		SND_SOC_DAILINK_REG(capture_mono1),
    837	},
    838	{
    839		.name = "Capture_Mono_2",
    840		.stream_name = "Capture_Mono_2",
    841		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    842			    SND_SOC_DPCM_TRIGGER_PRE},
    843		.dynamic = 1,
    844		.dpcm_capture = 1,
    845		SND_SOC_DAILINK_REG(capture_mono2),
    846	},
    847	{
    848		.name = "Capture_Mono_3",
    849		.stream_name = "Capture_Mono_3",
    850		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    851			    SND_SOC_DPCM_TRIGGER_PRE},
    852		.dynamic = 1,
    853		.dpcm_capture = 1,
    854		SND_SOC_DAILINK_REG(capture_mono3),
    855	},
    856	{
    857		.name = "playback_hdmi",
    858		.stream_name = "Playback_HDMI",
    859		.trigger = {SND_SOC_DPCM_TRIGGER_PRE,
    860			    SND_SOC_DPCM_TRIGGER_PRE},
    861		.dynamic = 1,
    862		.dpcm_playback = 1,
    863		SND_SOC_DAILINK_REG(playback_hdmi),
    864	},
    865	/* Back End DAI links */
    866	{
    867		.name = "Primary Codec",
    868		.no_pcm = 1,
    869		.dpcm_playback = 1,
    870		.dpcm_capture = 1,
    871		.ignore_suspend = 1,
    872		.init = mt8192_mt6359_init,
    873		SND_SOC_DAILINK_REG(primary_codec),
    874	},
    875	{
    876		.name = "Primary Codec CH34",
    877		.no_pcm = 1,
    878		.dpcm_playback = 1,
    879		.dpcm_capture = 1,
    880		.ignore_suspend = 1,
    881		SND_SOC_DAILINK_REG(primary_codec_ch34),
    882	},
    883	{
    884		.name = "AP_DMIC",
    885		.no_pcm = 1,
    886		.dpcm_capture = 1,
    887		.ignore_suspend = 1,
    888		SND_SOC_DAILINK_REG(ap_dmic),
    889	},
    890	{
    891		.name = "AP_DMIC_CH34",
    892		.no_pcm = 1,
    893		.dpcm_capture = 1,
    894		.ignore_suspend = 1,
    895		SND_SOC_DAILINK_REG(ap_dmic_ch34),
    896	},
    897	{
    898		.name = "I2S0",
    899		.no_pcm = 1,
    900		.dpcm_capture = 1,
    901		.ignore_suspend = 1,
    902		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
    903		SND_SOC_DAILINK_REG(i2s0),
    904	},
    905	{
    906		.name = "I2S1",
    907		.no_pcm = 1,
    908		.dpcm_playback = 1,
    909		.ignore_suspend = 1,
    910		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
    911		SND_SOC_DAILINK_REG(i2s1),
    912	},
    913	{
    914		.name = "I2S2",
    915		.no_pcm = 1,
    916		.dpcm_capture = 1,
    917		.ignore_suspend = 1,
    918		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
    919		SND_SOC_DAILINK_REG(i2s2),
    920	},
    921	{
    922		.name = "I2S3",
    923		.no_pcm = 1,
    924		.dpcm_playback = 1,
    925		.ignore_suspend = 1,
    926		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
    927		SND_SOC_DAILINK_REG(i2s3),
    928	},
    929	{
    930		.name = "I2S5",
    931		.no_pcm = 1,
    932		.dpcm_playback = 1,
    933		.ignore_suspend = 1,
    934		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
    935		SND_SOC_DAILINK_REG(i2s5),
    936	},
    937	{
    938		.name = "I2S6",
    939		.no_pcm = 1,
    940		.dpcm_capture = 1,
    941		.ignore_suspend = 1,
    942		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
    943		SND_SOC_DAILINK_REG(i2s6),
    944	},
    945	{
    946		.name = "I2S7",
    947		.no_pcm = 1,
    948		.dpcm_playback = 1,
    949		.ignore_suspend = 1,
    950		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
    951		SND_SOC_DAILINK_REG(i2s7),
    952	},
    953	{
    954		.name = "I2S8",
    955		.no_pcm = 1,
    956		.dpcm_capture = 1,
    957		.ignore_suspend = 1,
    958		.init = mt8192_rt5682_init,
    959		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
    960		SND_SOC_DAILINK_REG(i2s8),
    961		.ops = &mt8192_rt5682x_i2s_ops,
    962	},
    963	{
    964		.name = "I2S9",
    965		.no_pcm = 1,
    966		.dpcm_playback = 1,
    967		.ignore_suspend = 1,
    968		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
    969		SND_SOC_DAILINK_REG(i2s9),
    970		.ops = &mt8192_rt5682x_i2s_ops,
    971	},
    972	{
    973		.name = "CONNSYS_I2S",
    974		.no_pcm = 1,
    975		.dpcm_capture = 1,
    976		.ignore_suspend = 1,
    977		SND_SOC_DAILINK_REG(connsys_i2s),
    978	},
    979	{
    980		.name = "PCM 1",
    981		.no_pcm = 1,
    982		.dpcm_playback = 1,
    983		.dpcm_capture = 1,
    984		.ignore_suspend = 1,
    985		SND_SOC_DAILINK_REG(pcm1),
    986	},
    987	{
    988		.name = "PCM 2",
    989		.no_pcm = 1,
    990		.dpcm_playback = 1,
    991		.dpcm_capture = 1,
    992		.ignore_suspend = 1,
    993		SND_SOC_DAILINK_REG(pcm2),
    994	},
    995	{
    996		.name = "TDM",
    997		.no_pcm = 1,
    998		.dai_fmt = SND_SOC_DAIFMT_DSP_A |
    999			   SND_SOC_DAIFMT_IB_NF |
   1000			   SND_SOC_DAIFMT_CBM_CFM,
   1001		.dpcm_playback = 1,
   1002		.ignore_suspend = 1,
   1003		.be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
   1004		.ignore = 1,
   1005		.init = mt8192_mt6359_hdmi_init,
   1006		SND_SOC_DAILINK_REG(tdm),
   1007	},
   1008};
   1009
   1010static const struct snd_soc_dapm_widget
   1011mt8192_mt6359_rt1015_rt5682_widgets[] = {
   1012	SND_SOC_DAPM_SPK("Left Spk", NULL),
   1013	SND_SOC_DAPM_SPK("Right Spk", NULL),
   1014	SND_SOC_DAPM_HP("Headphone Jack", NULL),
   1015	SND_SOC_DAPM_MIC("Headset Mic", NULL),
   1016	SND_SOC_DAPM_OUTPUT("TDM Out"),
   1017};
   1018
   1019static const struct snd_soc_dapm_route mt8192_mt6359_rt1015_rt5682_routes[] = {
   1020	/* speaker */
   1021	{ "Left Spk", NULL, "Left SPO" },
   1022	{ "Right Spk", NULL, "Right SPO" },
   1023	/* headset */
   1024	{ "Headphone Jack", NULL, "HPOL" },
   1025	{ "Headphone Jack", NULL, "HPOR" },
   1026	{ "IN1P", NULL, "Headset Mic" },
   1027	/* TDM */
   1028	{ "TDM Out", NULL, "TDM" },
   1029};
   1030
   1031static const struct snd_kcontrol_new mt8192_mt6359_rt1015_rt5682_controls[] = {
   1032	SOC_DAPM_PIN_SWITCH("Left Spk"),
   1033	SOC_DAPM_PIN_SWITCH("Right Spk"),
   1034	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
   1035	SOC_DAPM_PIN_SWITCH("Headset Mic"),
   1036};
   1037
   1038static struct snd_soc_codec_conf rt1015_amp_conf[] = {
   1039	{
   1040		.dlc = COMP_CODEC_CONF(RT1015_DEV0_NAME),
   1041		.name_prefix = "Left",
   1042	},
   1043	{
   1044		.dlc = COMP_CODEC_CONF(RT1015_DEV1_NAME),
   1045		.name_prefix = "Right",
   1046	},
   1047};
   1048
   1049static struct snd_soc_card mt8192_mt6359_rt1015_rt5682_card = {
   1050	.name = RT1015_RT5682_CARD_NAME,
   1051	.owner = THIS_MODULE,
   1052	.dai_link = mt8192_mt6359_dai_links,
   1053	.num_links = ARRAY_SIZE(mt8192_mt6359_dai_links),
   1054	.controls = mt8192_mt6359_rt1015_rt5682_controls,
   1055	.num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_controls),
   1056	.dapm_widgets = mt8192_mt6359_rt1015_rt5682_widgets,
   1057	.num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_widgets),
   1058	.dapm_routes = mt8192_mt6359_rt1015_rt5682_routes,
   1059	.num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_routes),
   1060	.codec_conf = rt1015_amp_conf,
   1061	.num_configs = ARRAY_SIZE(rt1015_amp_conf),
   1062};
   1063
   1064static const struct snd_soc_dapm_widget mt8192_mt6359_rt1015p_rt5682x_widgets[] = {
   1065	SND_SOC_DAPM_SPK("Speakers", NULL),
   1066	SND_SOC_DAPM_HP("Headphone Jack", NULL),
   1067	SND_SOC_DAPM_MIC("Headset Mic", NULL),
   1068};
   1069
   1070static const struct snd_soc_dapm_route mt8192_mt6359_rt1015p_rt5682x_routes[] = {
   1071	/* speaker */
   1072	{ "Speakers", NULL, "Speaker" },
   1073	/* headset */
   1074	{ "Headphone Jack", NULL, "HPOL" },
   1075	{ "Headphone Jack", NULL, "HPOR" },
   1076	{ "IN1P", NULL, "Headset Mic" },
   1077};
   1078
   1079static const struct snd_kcontrol_new mt8192_mt6359_rt1015p_rt5682x_controls[] = {
   1080	SOC_DAPM_PIN_SWITCH("Speakers"),
   1081	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
   1082	SOC_DAPM_PIN_SWITCH("Headset Mic"),
   1083};
   1084
   1085static struct snd_soc_card mt8192_mt6359_rt1015p_rt5682x_card = {
   1086	.owner = THIS_MODULE,
   1087	.dai_link = mt8192_mt6359_dai_links,
   1088	.num_links = ARRAY_SIZE(mt8192_mt6359_dai_links),
   1089	.controls = mt8192_mt6359_rt1015p_rt5682x_controls,
   1090	.num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_controls),
   1091	.dapm_widgets = mt8192_mt6359_rt1015p_rt5682x_widgets,
   1092	.num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_widgets),
   1093	.dapm_routes = mt8192_mt6359_rt1015p_rt5682x_routes,
   1094	.num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682x_routes),
   1095};
   1096
   1097static int mt8192_mt6359_card_set_be_link(struct snd_soc_card *card,
   1098					  struct snd_soc_dai_link *link,
   1099					  struct device_node *node,
   1100					  char *link_name)
   1101{
   1102	int ret;
   1103
   1104	if (node && strcmp(link->name, link_name) == 0) {
   1105		ret = snd_soc_of_get_dai_link_codecs(card->dev, node, link);
   1106		if (ret < 0) {
   1107			dev_err_probe(card->dev, ret, "get dai link codecs fail\n");
   1108			return ret;
   1109		}
   1110	}
   1111
   1112	return 0;
   1113}
   1114
   1115static int mt8192_mt6359_dev_probe(struct platform_device *pdev)
   1116{
   1117	struct snd_soc_card *card;
   1118	struct device_node *platform_node, *hdmi_codec, *headset_codec, *speaker_codec;
   1119	int ret, i;
   1120	struct snd_soc_dai_link *dai_link;
   1121	struct mt8192_mt6359_priv *priv;
   1122
   1123	card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev);
   1124	if (!card)
   1125		return -EINVAL;
   1126	card->dev = &pdev->dev;
   1127
   1128	if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682_OF_NAME))
   1129		card->name = RT1015P_RT5682_CARD_NAME;
   1130	else if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682S_OF_NAME))
   1131		card->name = RT1015P_RT5682S_CARD_NAME;
   1132	else
   1133		dev_dbg(&pdev->dev, "No need to set card name\n");
   1134
   1135	hdmi_codec = of_parse_phandle(pdev->dev.of_node, "mediatek,hdmi-codec", 0);
   1136	if (!hdmi_codec)
   1137		dev_dbg(&pdev->dev, "The machine has no hdmi-codec\n");
   1138
   1139	platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0);
   1140	if (!platform_node) {
   1141		ret = -EINVAL;
   1142		dev_err_probe(&pdev->dev, ret, "Property 'platform' missing or invalid\n");
   1143		goto err_platform_node;
   1144	}
   1145
   1146	speaker_codec = of_get_child_by_name(pdev->dev.of_node, "speaker-codecs");
   1147	if (!speaker_codec) {
   1148		ret = -EINVAL;
   1149		dev_err_probe(&pdev->dev, ret, "Property 'speaker-codecs' missing or invalid\n");
   1150		goto err_speaker_codec;
   1151	}
   1152
   1153	headset_codec = of_get_child_by_name(pdev->dev.of_node, "headset-codec");
   1154	if (!headset_codec) {
   1155		ret = -EINVAL;
   1156		dev_err_probe(&pdev->dev, ret, "Property 'headset-codec' missing or invalid\n");
   1157		goto err_headset_codec;
   1158	}
   1159
   1160	for_each_card_prelinks(card, i, dai_link) {
   1161		ret = mt8192_mt6359_card_set_be_link(card, dai_link, speaker_codec, "I2S3");
   1162		if (ret) {
   1163			dev_err_probe(&pdev->dev, ret, "%s set speaker_codec fail\n",
   1164				      dai_link->name);
   1165			goto err_probe;
   1166		}
   1167
   1168		ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S8");
   1169		if (ret) {
   1170			dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n",
   1171				      dai_link->name);
   1172			goto err_probe;
   1173		}
   1174
   1175		ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S9");
   1176		if (ret) {
   1177			dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n",
   1178				      dai_link->name);
   1179			goto err_probe;
   1180		}
   1181
   1182		if (hdmi_codec && strcmp(dai_link->name, "TDM") == 0) {
   1183			dai_link->codecs->of_node = hdmi_codec;
   1184			dai_link->ignore = 0;
   1185		}
   1186
   1187		if (strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) == 0)
   1188			dai_link->ops = &mt8192_rt1015_i2s_ops;
   1189
   1190		if (!dai_link->platforms->name)
   1191			dai_link->platforms->of_node = platform_node;
   1192	}
   1193
   1194	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
   1195	if (!priv) {
   1196		ret = -ENOMEM;
   1197		goto err_probe;
   1198	}
   1199	snd_soc_card_set_drvdata(card, priv);
   1200
   1201	ret = mt8192_afe_gpio_init(&pdev->dev);
   1202	if (ret) {
   1203		dev_err_probe(&pdev->dev, ret, "%s init gpio error\n", __func__);
   1204		goto err_probe;
   1205	}
   1206
   1207	ret = devm_snd_soc_register_card(&pdev->dev, card);
   1208	if (ret)
   1209		dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", __func__);
   1210
   1211err_probe:
   1212	of_node_put(headset_codec);
   1213err_headset_codec:
   1214	of_node_put(speaker_codec);
   1215err_speaker_codec:
   1216	of_node_put(platform_node);
   1217err_platform_node:
   1218	of_node_put(hdmi_codec);
   1219	return ret;
   1220}
   1221
   1222#ifdef CONFIG_OF
   1223static const struct of_device_id mt8192_mt6359_dt_match[] = {
   1224	{
   1225		.compatible = RT1015_RT5682_OF_NAME,
   1226		.data = &mt8192_mt6359_rt1015_rt5682_card,
   1227	},
   1228	{
   1229		.compatible = RT1015P_RT5682_OF_NAME,
   1230		.data = &mt8192_mt6359_rt1015p_rt5682x_card,
   1231	},
   1232	{
   1233		.compatible = RT1015P_RT5682S_OF_NAME,
   1234		.data = &mt8192_mt6359_rt1015p_rt5682x_card,
   1235	},
   1236	{}
   1237};
   1238#endif
   1239
   1240static const struct dev_pm_ops mt8192_mt6359_pm_ops = {
   1241	.poweroff = snd_soc_poweroff,
   1242	.restore = snd_soc_resume,
   1243};
   1244
   1245static struct platform_driver mt8192_mt6359_driver = {
   1246	.driver = {
   1247		.name = "mt8192_mt6359",
   1248#ifdef CONFIG_OF
   1249		.of_match_table = mt8192_mt6359_dt_match,
   1250#endif
   1251		.pm = &mt8192_mt6359_pm_ops,
   1252	},
   1253	.probe = mt8192_mt6359_dev_probe,
   1254};
   1255
   1256module_platform_driver(mt8192_mt6359_driver);
   1257
   1258/* Module information */
   1259MODULE_DESCRIPTION("MT8192-MT6359 ALSA SoC machine driver");
   1260MODULE_AUTHOR("Jiaxin Yu <jiaxin.yu@mediatek.com>");
   1261MODULE_LICENSE("GPL v2");
   1262MODULE_ALIAS("mt8192_mt6359 soc card");