0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/input.h>
0011 #include <linux/module.h>
0012 #include <linux/of_device.h>
0013 #include <linux/pm_runtime.h>
0014 #include <sound/jack.h>
0015 #include <sound/pcm_params.h>
0016 #include <sound/rt5682.h>
0017 #include <sound/soc.h>
0018
0019 #include "../../codecs/mt6359.h"
0020 #include "../../codecs/rt1015.h"
0021 #include "../../codecs/rt5682.h"
0022 #include "../common/mtk-afe-platform-driver.h"
0023 #include "mt8192-afe-common.h"
0024 #include "mt8192-afe-clk.h"
0025 #include "mt8192-afe-gpio.h"
0026
0027 #define RT1015_CODEC_DAI "rt1015-aif"
0028 #define RT1015_DEV0_NAME "rt1015.1-0028"
0029 #define RT1015_DEV1_NAME "rt1015.1-0029"
0030
0031 #define RT1015_RT5682_CARD_NAME "mt8192_mt6359_rt1015_rt5682"
0032 #define RT1015P_RT5682_CARD_NAME "mt8192_mt6359_rt1015p_rt5682"
0033 #define RT1015P_RT5682S_CARD_NAME "mt8192_mt6359_rt1015p_rt5682s"
0034
0035 #define RT1015_RT5682_OF_NAME "mediatek,mt8192_mt6359_rt1015_rt5682"
0036 #define RT1015P_RT5682_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682"
0037 #define RT1015P_RT5682S_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682s"
0038
0039 struct mt8192_mt6359_priv {
0040 struct snd_soc_jack headset_jack;
0041 struct snd_soc_jack hdmi_jack;
0042 };
0043
0044 static int mt8192_rt1015_i2s_hw_params(struct snd_pcm_substream *substream,
0045 struct snd_pcm_hw_params *params)
0046 {
0047 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0048 struct snd_soc_card *card = rtd->card;
0049 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
0050 struct snd_soc_dai *codec_dai;
0051 unsigned int rate = params_rate(params);
0052 unsigned int mclk_fs_ratio = 128;
0053 unsigned int mclk_fs = rate * mclk_fs_ratio;
0054 int ret, i;
0055
0056 for_each_rtd_codec_dais(rtd, i, codec_dai) {
0057 ret = snd_soc_dai_set_pll(codec_dai, 0,
0058 RT1015_PLL_S_BCLK,
0059 params_rate(params) * 64,
0060 params_rate(params) * 256);
0061 if (ret) {
0062 dev_err(card->dev, "failed to set pll\n");
0063 return ret;
0064 }
0065
0066 ret = snd_soc_dai_set_sysclk(codec_dai,
0067 RT1015_SCLK_S_PLL,
0068 params_rate(params) * 256,
0069 SND_SOC_CLOCK_IN);
0070 if (ret) {
0071 dev_err(card->dev, "failed to set sysclk\n");
0072 return ret;
0073 }
0074 }
0075
0076 return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
0077 }
0078
0079 static int mt8192_rt5682x_i2s_hw_params(struct snd_pcm_substream *substream,
0080 struct snd_pcm_hw_params *params)
0081 {
0082 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0083 struct snd_soc_card *card = rtd->card;
0084 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
0085 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
0086 unsigned int rate = params_rate(params);
0087 unsigned int mclk_fs_ratio = 128;
0088 unsigned int mclk_fs = rate * mclk_fs_ratio;
0089 int bitwidth;
0090 int ret;
0091
0092 bitwidth = snd_pcm_format_width(params_format(params));
0093 if (bitwidth < 0) {
0094 dev_err(card->dev, "invalid bit width: %d\n", bitwidth);
0095 return bitwidth;
0096 }
0097
0098 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth);
0099 if (ret) {
0100 dev_err(card->dev, "failed to set tdm slot\n");
0101 return ret;
0102 }
0103
0104 ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1,
0105 RT5682_PLL1_S_BCLK1,
0106 params_rate(params) * 64,
0107 params_rate(params) * 512);
0108 if (ret) {
0109 dev_err(card->dev, "failed to set pll\n");
0110 return ret;
0111 }
0112
0113 ret = snd_soc_dai_set_sysclk(codec_dai,
0114 RT5682_SCLK_S_PLL1,
0115 params_rate(params) * 512,
0116 SND_SOC_CLOCK_IN);
0117 if (ret) {
0118 dev_err(card->dev, "failed to set sysclk\n");
0119 return ret;
0120 }
0121
0122 return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT);
0123 }
0124
0125 static const struct snd_soc_ops mt8192_rt1015_i2s_ops = {
0126 .hw_params = mt8192_rt1015_i2s_hw_params,
0127 };
0128
0129 static const struct snd_soc_ops mt8192_rt5682x_i2s_ops = {
0130 .hw_params = mt8192_rt5682x_i2s_hw_params,
0131 };
0132
0133 static int mt8192_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)
0134 {
0135 struct snd_soc_component *cmpnt_afe =
0136 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
0137 struct snd_soc_component *cmpnt_codec =
0138 asoc_rtd_to_codec(rtd, 0)->component;
0139 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
0140 struct mt8192_afe_private *afe_priv = afe->platform_priv;
0141 int phase;
0142 unsigned int monitor;
0143 int test_done_1, test_done_2, test_done_3;
0144 int cycle_1, cycle_2, cycle_3;
0145 int prev_cycle_1, prev_cycle_2, prev_cycle_3;
0146 int chosen_phase_1, chosen_phase_2, chosen_phase_3;
0147 int counter;
0148 int mtkaif_calib_ok;
0149
0150 dev_info(afe->dev, "%s(), start\n", __func__);
0151
0152 pm_runtime_get_sync(afe->dev);
0153 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 1);
0154 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 0);
0155 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 1);
0156 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 0);
0157
0158 mt6359_mtkaif_calibration_enable(cmpnt_codec);
0159
0160
0161 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38);
0162 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x39);
0163
0164
0165 regmap_update_bits(afe_priv->topckgen,
0166 CKSYS_AUD_TOP_CFG, 0xffff, 0x4);
0167
0168 mtkaif_calib_ok = true;
0169 afe_priv->mtkaif_calibration_num_phase = 42;
0170 afe_priv->mtkaif_chosen_phase[0] = -1;
0171 afe_priv->mtkaif_chosen_phase[1] = -1;
0172 afe_priv->mtkaif_chosen_phase[2] = -1;
0173
0174 for (phase = 0;
0175 phase <= afe_priv->mtkaif_calibration_num_phase &&
0176 mtkaif_calib_ok;
0177 phase++) {
0178 mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
0179 phase, phase, phase);
0180
0181 regmap_update_bits(afe_priv->topckgen,
0182 CKSYS_AUD_TOP_CFG, 0x1, 0x1);
0183
0184 test_done_1 = 0;
0185 test_done_2 = 0;
0186 test_done_3 = 0;
0187 cycle_1 = -1;
0188 cycle_2 = -1;
0189 cycle_3 = -1;
0190 counter = 0;
0191 while (test_done_1 == 0 ||
0192 test_done_2 == 0 ||
0193 test_done_3 == 0) {
0194 regmap_read(afe_priv->topckgen,
0195 CKSYS_AUD_TOP_MON, &monitor);
0196
0197 test_done_1 = (monitor >> 28) & 0x1;
0198 test_done_2 = (monitor >> 29) & 0x1;
0199 test_done_3 = (monitor >> 30) & 0x1;
0200 if (test_done_1 == 1)
0201 cycle_1 = monitor & 0xf;
0202
0203 if (test_done_2 == 1)
0204 cycle_2 = (monitor >> 4) & 0xf;
0205
0206 if (test_done_3 == 1)
0207 cycle_3 = (monitor >> 8) & 0xf;
0208
0209
0210 if (++counter > 10000) {
0211 dev_err(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n",
0212 __func__,
0213 cycle_1, cycle_2, cycle_3, monitor);
0214 mtkaif_calib_ok = false;
0215 break;
0216 }
0217 }
0218
0219 if (phase == 0) {
0220 prev_cycle_1 = cycle_1;
0221 prev_cycle_2 = cycle_2;
0222 prev_cycle_3 = cycle_3;
0223 }
0224
0225 if (cycle_1 != prev_cycle_1 &&
0226 afe_priv->mtkaif_chosen_phase[0] < 0) {
0227 afe_priv->mtkaif_chosen_phase[0] = phase - 1;
0228 afe_priv->mtkaif_phase_cycle[0] = prev_cycle_1;
0229 }
0230
0231 if (cycle_2 != prev_cycle_2 &&
0232 afe_priv->mtkaif_chosen_phase[1] < 0) {
0233 afe_priv->mtkaif_chosen_phase[1] = phase - 1;
0234 afe_priv->mtkaif_phase_cycle[1] = prev_cycle_2;
0235 }
0236
0237 if (cycle_3 != prev_cycle_3 &&
0238 afe_priv->mtkaif_chosen_phase[2] < 0) {
0239 afe_priv->mtkaif_chosen_phase[2] = phase - 1;
0240 afe_priv->mtkaif_phase_cycle[2] = prev_cycle_3;
0241 }
0242
0243 regmap_update_bits(afe_priv->topckgen,
0244 CKSYS_AUD_TOP_CFG, 0x1, 0x0);
0245
0246 if (afe_priv->mtkaif_chosen_phase[0] >= 0 &&
0247 afe_priv->mtkaif_chosen_phase[1] >= 0 &&
0248 afe_priv->mtkaif_chosen_phase[2] >= 0)
0249 break;
0250 }
0251
0252 if (afe_priv->mtkaif_chosen_phase[0] < 0)
0253 chosen_phase_1 = 0;
0254 else
0255 chosen_phase_1 = afe_priv->mtkaif_chosen_phase[0];
0256
0257 if (afe_priv->mtkaif_chosen_phase[1] < 0)
0258 chosen_phase_2 = 0;
0259 else
0260 chosen_phase_2 = afe_priv->mtkaif_chosen_phase[1];
0261
0262 if (afe_priv->mtkaif_chosen_phase[2] < 0)
0263 chosen_phase_3 = 0;
0264 else
0265 chosen_phase_3 = afe_priv->mtkaif_chosen_phase[2];
0266
0267 mt6359_set_mtkaif_calibration_phase(cmpnt_codec,
0268 chosen_phase_1,
0269 chosen_phase_2,
0270 chosen_phase_3);
0271
0272
0273 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38);
0274
0275 mt6359_mtkaif_calibration_disable(cmpnt_codec);
0276
0277 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 1);
0278 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 0);
0279 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 1);
0280 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 0);
0281 pm_runtime_put(afe->dev);
0282
0283 dev_info(afe->dev, "%s(), mtkaif_chosen_phase[0/1/2]:%d/%d/%d\n",
0284 __func__,
0285 afe_priv->mtkaif_chosen_phase[0],
0286 afe_priv->mtkaif_chosen_phase[1],
0287 afe_priv->mtkaif_chosen_phase[2]);
0288
0289 return 0;
0290 }
0291
0292 static int mt8192_mt6359_init(struct snd_soc_pcm_runtime *rtd)
0293 {
0294 struct snd_soc_component *cmpnt_afe =
0295 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
0296 struct snd_soc_component *cmpnt_codec =
0297 asoc_rtd_to_codec(rtd, 0)->component;
0298 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
0299 struct mt8192_afe_private *afe_priv = afe->platform_priv;
0300
0301
0302 mt6359_set_mtkaif_protocol(cmpnt_codec,
0303 MT6359_MTKAIF_PROTOCOL_2_CLK_P2);
0304 afe_priv->mtkaif_protocol = MTKAIF_PROTOCOL_2_CLK_P2;
0305
0306
0307 mt8192_mt6359_mtkaif_calibration(rtd);
0308
0309 return 0;
0310 }
0311
0312 static int mt8192_rt5682_init(struct snd_soc_pcm_runtime *rtd)
0313 {
0314 struct snd_soc_component *cmpnt_codec =
0315 asoc_rtd_to_codec(rtd, 0)->component;
0316 struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
0317 struct snd_soc_jack *jack = &priv->headset_jack;
0318 int ret;
0319
0320 ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
0321 SND_JACK_HEADSET | SND_JACK_BTN_0 |
0322 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
0323 SND_JACK_BTN_3,
0324 jack);
0325 if (ret) {
0326 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
0327 return ret;
0328 }
0329
0330 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
0331 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
0332 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
0333 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
0334
0335 return snd_soc_component_set_jack(cmpnt_codec, jack, NULL);
0336 };
0337
0338 static int mt8192_mt6359_hdmi_init(struct snd_soc_pcm_runtime *rtd)
0339 {
0340 struct snd_soc_component *cmpnt_codec =
0341 asoc_rtd_to_codec(rtd, 0)->component;
0342 struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card);
0343 int ret;
0344
0345 ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT,
0346 &priv->hdmi_jack);
0347 if (ret) {
0348 dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret);
0349 return ret;
0350 }
0351
0352 return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL);
0353 }
0354
0355 static int mt8192_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
0356 struct snd_pcm_hw_params *params)
0357 {
0358
0359 snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT),
0360 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST);
0361
0362 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
0363
0364 return 0;
0365 }
0366
0367 static int
0368 mt8192_mt6359_cap1_startup(struct snd_pcm_substream *substream)
0369 {
0370 static const unsigned int channels[] = {
0371 1, 2, 4
0372 };
0373 static const struct snd_pcm_hw_constraint_list constraints_channels = {
0374 .count = ARRAY_SIZE(channels),
0375 .list = channels,
0376 .mask = 0,
0377 };
0378 static const unsigned int rates[] = {
0379 8000, 16000, 32000, 48000, 96000, 192000
0380 };
0381 static const struct snd_pcm_hw_constraint_list constraints_rates = {
0382 .count = ARRAY_SIZE(rates),
0383 .list = rates,
0384 .mask = 0,
0385 };
0386
0387 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0388 struct snd_pcm_runtime *runtime = substream->runtime;
0389 int ret;
0390
0391 ret = snd_pcm_hw_constraint_list(runtime, 0,
0392 SNDRV_PCM_HW_PARAM_CHANNELS,
0393 &constraints_channels);
0394 if (ret < 0) {
0395 dev_err(rtd->dev, "hw_constraint_list channels failed\n");
0396 return ret;
0397 }
0398
0399 ret = snd_pcm_hw_constraint_list(runtime, 0,
0400 SNDRV_PCM_HW_PARAM_RATE,
0401 &constraints_rates);
0402 if (ret < 0) {
0403 dev_err(rtd->dev, "hw_constraint_list rate failed\n");
0404 return ret;
0405 }
0406
0407 return 0;
0408 }
0409
0410 static const struct snd_soc_ops mt8192_mt6359_capture1_ops = {
0411 .startup = mt8192_mt6359_cap1_startup,
0412 };
0413
0414 static int
0415 mt8192_mt6359_rt5682_startup(struct snd_pcm_substream *substream)
0416 {
0417 static const unsigned int channels[] = {
0418 1, 2
0419 };
0420 static const struct snd_pcm_hw_constraint_list constraints_channels = {
0421 .count = ARRAY_SIZE(channels),
0422 .list = channels,
0423 .mask = 0,
0424 };
0425 static const unsigned int rates[] = {
0426 48000
0427 };
0428 static const struct snd_pcm_hw_constraint_list constraints_rates = {
0429 .count = ARRAY_SIZE(rates),
0430 .list = rates,
0431 .mask = 0,
0432 };
0433
0434 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0435 struct snd_pcm_runtime *runtime = substream->runtime;
0436 int ret;
0437
0438 ret = snd_pcm_hw_constraint_list(runtime, 0,
0439 SNDRV_PCM_HW_PARAM_CHANNELS,
0440 &constraints_channels);
0441 if (ret < 0) {
0442 dev_err(rtd->dev, "hw_constraint_list channels failed\n");
0443 return ret;
0444 }
0445
0446 ret = snd_pcm_hw_constraint_list(runtime, 0,
0447 SNDRV_PCM_HW_PARAM_RATE,
0448 &constraints_rates);
0449 if (ret < 0) {
0450 dev_err(rtd->dev, "hw_constraint_list rate failed\n");
0451 return ret;
0452 }
0453
0454 return 0;
0455 }
0456
0457 static const struct snd_soc_ops mt8192_mt6359_rt5682_ops = {
0458 .startup = mt8192_mt6359_rt5682_startup,
0459 };
0460
0461
0462 SND_SOC_DAILINK_DEFS(playback1,
0463 DAILINK_COMP_ARRAY(COMP_CPU("DL1")),
0464 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0465 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0466
0467 SND_SOC_DAILINK_DEFS(playback12,
0468 DAILINK_COMP_ARRAY(COMP_CPU("DL12")),
0469 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0470 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0471
0472 SND_SOC_DAILINK_DEFS(playback2,
0473 DAILINK_COMP_ARRAY(COMP_CPU("DL2")),
0474 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0475 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0476
0477 SND_SOC_DAILINK_DEFS(playback3,
0478 DAILINK_COMP_ARRAY(COMP_CPU("DL3")),
0479 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0480 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0481
0482 SND_SOC_DAILINK_DEFS(playback4,
0483 DAILINK_COMP_ARRAY(COMP_CPU("DL4")),
0484 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0485 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0486
0487 SND_SOC_DAILINK_DEFS(playback5,
0488 DAILINK_COMP_ARRAY(COMP_CPU("DL5")),
0489 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0490 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0491
0492 SND_SOC_DAILINK_DEFS(playback6,
0493 DAILINK_COMP_ARRAY(COMP_CPU("DL6")),
0494 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0495 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0496
0497 SND_SOC_DAILINK_DEFS(playback7,
0498 DAILINK_COMP_ARRAY(COMP_CPU("DL7")),
0499 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0500 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0501
0502 SND_SOC_DAILINK_DEFS(playback8,
0503 DAILINK_COMP_ARRAY(COMP_CPU("DL8")),
0504 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0505 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0506
0507 SND_SOC_DAILINK_DEFS(playback9,
0508 DAILINK_COMP_ARRAY(COMP_CPU("DL9")),
0509 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0510 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0511
0512 SND_SOC_DAILINK_DEFS(capture1,
0513 DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
0514 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0515 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0516
0517 SND_SOC_DAILINK_DEFS(capture2,
0518 DAILINK_COMP_ARRAY(COMP_CPU("UL2")),
0519 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0520 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0521
0522 SND_SOC_DAILINK_DEFS(capture3,
0523 DAILINK_COMP_ARRAY(COMP_CPU("UL3")),
0524 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0525 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0526
0527 SND_SOC_DAILINK_DEFS(capture4,
0528 DAILINK_COMP_ARRAY(COMP_CPU("UL4")),
0529 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0530 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0531
0532 SND_SOC_DAILINK_DEFS(capture5,
0533 DAILINK_COMP_ARRAY(COMP_CPU("UL5")),
0534 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0535 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0536
0537 SND_SOC_DAILINK_DEFS(capture6,
0538 DAILINK_COMP_ARRAY(COMP_CPU("UL6")),
0539 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0540 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0541
0542 SND_SOC_DAILINK_DEFS(capture7,
0543 DAILINK_COMP_ARRAY(COMP_CPU("UL7")),
0544 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0545 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0546
0547 SND_SOC_DAILINK_DEFS(capture8,
0548 DAILINK_COMP_ARRAY(COMP_CPU("UL8")),
0549 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0550 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0551
0552 SND_SOC_DAILINK_DEFS(capture_mono1,
0553 DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_1")),
0554 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0555 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0556
0557 SND_SOC_DAILINK_DEFS(capture_mono2,
0558 DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_2")),
0559 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0560 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0561
0562 SND_SOC_DAILINK_DEFS(capture_mono3,
0563 DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_3")),
0564 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0565 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0566
0567 SND_SOC_DAILINK_DEFS(playback_hdmi,
0568 DAILINK_COMP_ARRAY(COMP_CPU("HDMI")),
0569 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0570 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0571
0572
0573 SND_SOC_DAILINK_DEFS(primary_codec,
0574 DAILINK_COMP_ARRAY(COMP_CPU("ADDA")),
0575 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
0576 "mt6359-snd-codec-aif1"),
0577 COMP_CODEC("dmic-codec",
0578 "dmic-hifi")),
0579 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0580
0581 SND_SOC_DAILINK_DEFS(primary_codec_ch34,
0582 DAILINK_COMP_ARRAY(COMP_CPU("ADDA_CH34")),
0583 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
0584 "mt6359-snd-codec-aif2")),
0585 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0586
0587 SND_SOC_DAILINK_DEFS(ap_dmic,
0588 DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC")),
0589 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0590 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0591
0592 SND_SOC_DAILINK_DEFS(ap_dmic_ch34,
0593 DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC_CH34")),
0594 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0595 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0596
0597 SND_SOC_DAILINK_DEFS(i2s0,
0598 DAILINK_COMP_ARRAY(COMP_CPU("I2S0")),
0599 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0600 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0601
0602 SND_SOC_DAILINK_DEFS(i2s1,
0603 DAILINK_COMP_ARRAY(COMP_CPU("I2S1")),
0604 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0605 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0606
0607 SND_SOC_DAILINK_DEFS(i2s2,
0608 DAILINK_COMP_ARRAY(COMP_CPU("I2S2")),
0609 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0610 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0611
0612 SND_SOC_DAILINK_DEFS(i2s3,
0613 DAILINK_COMP_ARRAY(COMP_CPU("I2S3")),
0614 DAILINK_COMP_ARRAY(COMP_EMPTY()),
0615 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0616
0617 SND_SOC_DAILINK_DEFS(i2s5,
0618 DAILINK_COMP_ARRAY(COMP_CPU("I2S5")),
0619 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0620 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0621
0622 SND_SOC_DAILINK_DEFS(i2s6,
0623 DAILINK_COMP_ARRAY(COMP_CPU("I2S6")),
0624 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0625 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0626
0627 SND_SOC_DAILINK_DEFS(i2s7,
0628 DAILINK_COMP_ARRAY(COMP_CPU("I2S7")),
0629 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0630 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0631
0632 SND_SOC_DAILINK_DEFS(i2s8,
0633 DAILINK_COMP_ARRAY(COMP_CPU("I2S8")),
0634 DAILINK_COMP_ARRAY(COMP_EMPTY()),
0635 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0636
0637 SND_SOC_DAILINK_DEFS(i2s9,
0638 DAILINK_COMP_ARRAY(COMP_CPU("I2S9")),
0639 DAILINK_COMP_ARRAY(COMP_EMPTY()),
0640 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0641
0642 SND_SOC_DAILINK_DEFS(connsys_i2s,
0643 DAILINK_COMP_ARRAY(COMP_CPU("CONNSYS_I2S")),
0644 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0645 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0646
0647 SND_SOC_DAILINK_DEFS(pcm1,
0648 DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")),
0649 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0650 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0651
0652 SND_SOC_DAILINK_DEFS(pcm2,
0653 DAILINK_COMP_ARRAY(COMP_CPU("PCM 2")),
0654 DAILINK_COMP_ARRAY(COMP_DUMMY()),
0655 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0656
0657 SND_SOC_DAILINK_DEFS(tdm,
0658 DAILINK_COMP_ARRAY(COMP_CPU("TDM")),
0659 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "i2s-hifi")),
0660 DAILINK_COMP_ARRAY(COMP_EMPTY()));
0661
0662 static struct snd_soc_dai_link mt8192_mt6359_dai_links[] = {
0663
0664 {
0665 .name = "Playback_1",
0666 .stream_name = "Playback_1",
0667 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0668 SND_SOC_DPCM_TRIGGER_PRE},
0669 .dynamic = 1,
0670 .dpcm_playback = 1,
0671 SND_SOC_DAILINK_REG(playback1),
0672 },
0673 {
0674 .name = "Playback_12",
0675 .stream_name = "Playback_12",
0676 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0677 SND_SOC_DPCM_TRIGGER_PRE},
0678 .dynamic = 1,
0679 .dpcm_playback = 1,
0680 SND_SOC_DAILINK_REG(playback12),
0681 },
0682 {
0683 .name = "Playback_2",
0684 .stream_name = "Playback_2",
0685 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0686 SND_SOC_DPCM_TRIGGER_PRE},
0687 .dynamic = 1,
0688 .dpcm_playback = 1,
0689 SND_SOC_DAILINK_REG(playback2),
0690 },
0691 {
0692 .name = "Playback_3",
0693 .stream_name = "Playback_3",
0694 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0695 SND_SOC_DPCM_TRIGGER_PRE},
0696 .dynamic = 1,
0697 .dpcm_playback = 1,
0698 .ops = &mt8192_mt6359_rt5682_ops,
0699 SND_SOC_DAILINK_REG(playback3),
0700 },
0701 {
0702 .name = "Playback_4",
0703 .stream_name = "Playback_4",
0704 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0705 SND_SOC_DPCM_TRIGGER_PRE},
0706 .dynamic = 1,
0707 .dpcm_playback = 1,
0708 SND_SOC_DAILINK_REG(playback4),
0709 },
0710 {
0711 .name = "Playback_5",
0712 .stream_name = "Playback_5",
0713 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0714 SND_SOC_DPCM_TRIGGER_PRE},
0715 .dynamic = 1,
0716 .dpcm_playback = 1,
0717 SND_SOC_DAILINK_REG(playback5),
0718 },
0719 {
0720 .name = "Playback_6",
0721 .stream_name = "Playback_6",
0722 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0723 SND_SOC_DPCM_TRIGGER_PRE},
0724 .dynamic = 1,
0725 .dpcm_playback = 1,
0726 SND_SOC_DAILINK_REG(playback6),
0727 },
0728 {
0729 .name = "Playback_7",
0730 .stream_name = "Playback_7",
0731 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0732 SND_SOC_DPCM_TRIGGER_PRE},
0733 .dynamic = 1,
0734 .dpcm_playback = 1,
0735 SND_SOC_DAILINK_REG(playback7),
0736 },
0737 {
0738 .name = "Playback_8",
0739 .stream_name = "Playback_8",
0740 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0741 SND_SOC_DPCM_TRIGGER_PRE},
0742 .dynamic = 1,
0743 .dpcm_playback = 1,
0744 SND_SOC_DAILINK_REG(playback8),
0745 },
0746 {
0747 .name = "Playback_9",
0748 .stream_name = "Playback_9",
0749 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0750 SND_SOC_DPCM_TRIGGER_PRE},
0751 .dynamic = 1,
0752 .dpcm_playback = 1,
0753 SND_SOC_DAILINK_REG(playback9),
0754 },
0755 {
0756 .name = "Capture_1",
0757 .stream_name = "Capture_1",
0758 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0759 SND_SOC_DPCM_TRIGGER_PRE},
0760 .dynamic = 1,
0761 .dpcm_capture = 1,
0762 .ops = &mt8192_mt6359_capture1_ops,
0763 SND_SOC_DAILINK_REG(capture1),
0764 },
0765 {
0766 .name = "Capture_2",
0767 .stream_name = "Capture_2",
0768 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0769 SND_SOC_DPCM_TRIGGER_PRE},
0770 .dynamic = 1,
0771 .dpcm_capture = 1,
0772 .ops = &mt8192_mt6359_rt5682_ops,
0773 SND_SOC_DAILINK_REG(capture2),
0774 },
0775 {
0776 .name = "Capture_3",
0777 .stream_name = "Capture_3",
0778 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0779 SND_SOC_DPCM_TRIGGER_PRE},
0780 .dynamic = 1,
0781 .dpcm_capture = 1,
0782 SND_SOC_DAILINK_REG(capture3),
0783 },
0784 {
0785 .name = "Capture_4",
0786 .stream_name = "Capture_4",
0787 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0788 SND_SOC_DPCM_TRIGGER_PRE},
0789 .dynamic = 1,
0790 .dpcm_capture = 1,
0791 SND_SOC_DAILINK_REG(capture4),
0792 },
0793 {
0794 .name = "Capture_5",
0795 .stream_name = "Capture_5",
0796 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0797 SND_SOC_DPCM_TRIGGER_PRE},
0798 .dynamic = 1,
0799 .dpcm_capture = 1,
0800 SND_SOC_DAILINK_REG(capture5),
0801 },
0802 {
0803 .name = "Capture_6",
0804 .stream_name = "Capture_6",
0805 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0806 SND_SOC_DPCM_TRIGGER_PRE},
0807 .dynamic = 1,
0808 .dpcm_capture = 1,
0809 SND_SOC_DAILINK_REG(capture6),
0810 },
0811 {
0812 .name = "Capture_7",
0813 .stream_name = "Capture_7",
0814 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0815 SND_SOC_DPCM_TRIGGER_PRE},
0816 .dynamic = 1,
0817 .dpcm_capture = 1,
0818 SND_SOC_DAILINK_REG(capture7),
0819 },
0820 {
0821 .name = "Capture_8",
0822 .stream_name = "Capture_8",
0823 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0824 SND_SOC_DPCM_TRIGGER_PRE},
0825 .dynamic = 1,
0826 .dpcm_capture = 1,
0827 SND_SOC_DAILINK_REG(capture8),
0828 },
0829 {
0830 .name = "Capture_Mono_1",
0831 .stream_name = "Capture_Mono_1",
0832 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0833 SND_SOC_DPCM_TRIGGER_PRE},
0834 .dynamic = 1,
0835 .dpcm_capture = 1,
0836 SND_SOC_DAILINK_REG(capture_mono1),
0837 },
0838 {
0839 .name = "Capture_Mono_2",
0840 .stream_name = "Capture_Mono_2",
0841 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0842 SND_SOC_DPCM_TRIGGER_PRE},
0843 .dynamic = 1,
0844 .dpcm_capture = 1,
0845 SND_SOC_DAILINK_REG(capture_mono2),
0846 },
0847 {
0848 .name = "Capture_Mono_3",
0849 .stream_name = "Capture_Mono_3",
0850 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0851 SND_SOC_DPCM_TRIGGER_PRE},
0852 .dynamic = 1,
0853 .dpcm_capture = 1,
0854 SND_SOC_DAILINK_REG(capture_mono3),
0855 },
0856 {
0857 .name = "playback_hdmi",
0858 .stream_name = "Playback_HDMI",
0859 .trigger = {SND_SOC_DPCM_TRIGGER_PRE,
0860 SND_SOC_DPCM_TRIGGER_PRE},
0861 .dynamic = 1,
0862 .dpcm_playback = 1,
0863 SND_SOC_DAILINK_REG(playback_hdmi),
0864 },
0865
0866 {
0867 .name = "Primary Codec",
0868 .no_pcm = 1,
0869 .dpcm_playback = 1,
0870 .dpcm_capture = 1,
0871 .ignore_suspend = 1,
0872 .init = mt8192_mt6359_init,
0873 SND_SOC_DAILINK_REG(primary_codec),
0874 },
0875 {
0876 .name = "Primary Codec CH34",
0877 .no_pcm = 1,
0878 .dpcm_playback = 1,
0879 .dpcm_capture = 1,
0880 .ignore_suspend = 1,
0881 SND_SOC_DAILINK_REG(primary_codec_ch34),
0882 },
0883 {
0884 .name = "AP_DMIC",
0885 .no_pcm = 1,
0886 .dpcm_capture = 1,
0887 .ignore_suspend = 1,
0888 SND_SOC_DAILINK_REG(ap_dmic),
0889 },
0890 {
0891 .name = "AP_DMIC_CH34",
0892 .no_pcm = 1,
0893 .dpcm_capture = 1,
0894 .ignore_suspend = 1,
0895 SND_SOC_DAILINK_REG(ap_dmic_ch34),
0896 },
0897 {
0898 .name = "I2S0",
0899 .no_pcm = 1,
0900 .dpcm_capture = 1,
0901 .ignore_suspend = 1,
0902 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
0903 SND_SOC_DAILINK_REG(i2s0),
0904 },
0905 {
0906 .name = "I2S1",
0907 .no_pcm = 1,
0908 .dpcm_playback = 1,
0909 .ignore_suspend = 1,
0910 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
0911 SND_SOC_DAILINK_REG(i2s1),
0912 },
0913 {
0914 .name = "I2S2",
0915 .no_pcm = 1,
0916 .dpcm_capture = 1,
0917 .ignore_suspend = 1,
0918 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
0919 SND_SOC_DAILINK_REG(i2s2),
0920 },
0921 {
0922 .name = "I2S3",
0923 .no_pcm = 1,
0924 .dpcm_playback = 1,
0925 .ignore_suspend = 1,
0926 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
0927 SND_SOC_DAILINK_REG(i2s3),
0928 },
0929 {
0930 .name = "I2S5",
0931 .no_pcm = 1,
0932 .dpcm_playback = 1,
0933 .ignore_suspend = 1,
0934 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
0935 SND_SOC_DAILINK_REG(i2s5),
0936 },
0937 {
0938 .name = "I2S6",
0939 .no_pcm = 1,
0940 .dpcm_capture = 1,
0941 .ignore_suspend = 1,
0942 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
0943 SND_SOC_DAILINK_REG(i2s6),
0944 },
0945 {
0946 .name = "I2S7",
0947 .no_pcm = 1,
0948 .dpcm_playback = 1,
0949 .ignore_suspend = 1,
0950 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
0951 SND_SOC_DAILINK_REG(i2s7),
0952 },
0953 {
0954 .name = "I2S8",
0955 .no_pcm = 1,
0956 .dpcm_capture = 1,
0957 .ignore_suspend = 1,
0958 .init = mt8192_rt5682_init,
0959 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
0960 SND_SOC_DAILINK_REG(i2s8),
0961 .ops = &mt8192_rt5682x_i2s_ops,
0962 },
0963 {
0964 .name = "I2S9",
0965 .no_pcm = 1,
0966 .dpcm_playback = 1,
0967 .ignore_suspend = 1,
0968 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup,
0969 SND_SOC_DAILINK_REG(i2s9),
0970 .ops = &mt8192_rt5682x_i2s_ops,
0971 },
0972 {
0973 .name = "CONNSYS_I2S",
0974 .no_pcm = 1,
0975 .dpcm_capture = 1,
0976 .ignore_suspend = 1,
0977 SND_SOC_DAILINK_REG(connsys_i2s),
0978 },
0979 {
0980 .name = "PCM 1",
0981 .no_pcm = 1,
0982 .dpcm_playback = 1,
0983 .dpcm_capture = 1,
0984 .ignore_suspend = 1,
0985 SND_SOC_DAILINK_REG(pcm1),
0986 },
0987 {
0988 .name = "PCM 2",
0989 .no_pcm = 1,
0990 .dpcm_playback = 1,
0991 .dpcm_capture = 1,
0992 .ignore_suspend = 1,
0993 SND_SOC_DAILINK_REG(pcm2),
0994 },
0995 {
0996 .name = "TDM",
0997 .no_pcm = 1,
0998 .dai_fmt = SND_SOC_DAIFMT_DSP_A |
0999 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
1010 static const struct snd_soc_dapm_widget
1011 mt8192_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
1019 static const struct snd_soc_dapm_route mt8192_mt6359_rt1015_rt5682_routes[] = {
1020
1021 { "Left Spk", NULL, "Left SPO" },
1022 { "Right Spk", NULL, "Right SPO" },
1023
1024 { "Headphone Jack", NULL, "HPOL" },
1025 { "Headphone Jack", NULL, "HPOR" },
1026 { "IN1P", NULL, "Headset Mic" },
1027
1028 { "TDM Out", NULL, "TDM" },
1029 };
1030
1031 static 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
1038 static 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
1049 static 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
1064 static 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
1070 static const struct snd_soc_dapm_route mt8192_mt6359_rt1015p_rt5682x_routes[] = {
1071
1072 { "Speakers", NULL, "Speaker" },
1073
1074 { "Headphone Jack", NULL, "HPOL" },
1075 { "Headphone Jack", NULL, "HPOR" },
1076 { "IN1P", NULL, "Headset Mic" },
1077 };
1078
1079 static 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
1085 static 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
1097 static 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
1115 static 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
1211 err_probe:
1212 of_node_put(headset_codec);
1213 err_headset_codec:
1214 of_node_put(speaker_codec);
1215 err_speaker_codec:
1216 of_node_put(platform_node);
1217 err_platform_node:
1218 of_node_put(hdmi_codec);
1219 return ret;
1220 }
1221
1222 #ifdef CONFIG_OF
1223 static 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
1240 static const struct dev_pm_ops mt8192_mt6359_pm_ops = {
1241 .poweroff = snd_soc_poweroff,
1242 .restore = snd_soc_resume,
1243 };
1244
1245 static 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
1256 module_platform_driver(mt8192_mt6359_driver);
1257
1258
1259 MODULE_DESCRIPTION("MT8192-MT6359 ALSA SoC machine driver");
1260 MODULE_AUTHOR("Jiaxin Yu <jiaxin.yu@mediatek.com>");
1261 MODULE_LICENSE("GPL v2");
1262 MODULE_ALIAS("mt8192_mt6359 soc card");