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