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 RT5682_CODEC_DAI "rt5682-aif1" 32 #define RT5682_DEV0_NAME "rt5682.1-001a" 33 34 static struct snd_soc_jack headset_jack; 35 36 static int mt8192_rt1015_i2s_hw_params(struct snd_pcm_substream *substream, 37 struct snd_pcm_hw_params *params) 38 { 39 struct snd_soc_pcm_runtime *rtd = substream->private_data; 40 struct snd_soc_card *card = rtd->card; 41 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); 42 struct snd_soc_dai *codec_dai; 43 unsigned int rate = params_rate(params); 44 unsigned int mclk_fs_ratio = 128; 45 unsigned int mclk_fs = rate * mclk_fs_ratio; 46 int ret, i; 47 48 for_each_rtd_codec_dais(rtd, i, codec_dai) { 49 ret = snd_soc_dai_set_bclk_ratio(codec_dai, 64); 50 if (ret) { 51 dev_err(card->dev, "failed to set bclk ratio\n"); 52 return ret; 53 } 54 55 ret = snd_soc_dai_set_pll(codec_dai, 0, 56 RT1015_PLL_S_BCLK, 57 params_rate(params) * 64, 58 params_rate(params) * 256); 59 if (ret) { 60 dev_err(card->dev, "failed to set pll\n"); 61 return ret; 62 } 63 64 ret = snd_soc_dai_set_sysclk(codec_dai, 65 RT1015_SCLK_S_PLL, 66 params_rate(params) * 256, 67 SND_SOC_CLOCK_IN); 68 if (ret) { 69 dev_err(card->dev, "failed to set sysclk\n"); 70 return ret; 71 } 72 } 73 74 return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT); 75 } 76 77 static int mt8192_rt5682_i2s_hw_params(struct snd_pcm_substream *substream, 78 struct snd_pcm_hw_params *params) 79 { 80 struct snd_soc_pcm_runtime *rtd = substream->private_data; 81 struct snd_soc_card *card = rtd->card; 82 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); 83 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 84 unsigned int rate = params_rate(params); 85 unsigned int mclk_fs_ratio = 128; 86 unsigned int mclk_fs = rate * mclk_fs_ratio; 87 int bitwidth; 88 int ret; 89 90 bitwidth = snd_pcm_format_width(params_format(params)); 91 if (bitwidth < 0) { 92 dev_err(card->dev, "invalid bit width: %d\n", bitwidth); 93 return bitwidth; 94 } 95 96 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth); 97 if (ret) { 98 dev_err(card->dev, "failed to set tdm slot\n"); 99 return ret; 100 } 101 102 ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1, 103 RT5682_PLL1_S_BCLK1, 104 params_rate(params) * 64, 105 params_rate(params) * 512); 106 if (ret) { 107 dev_err(card->dev, "failed to set pll\n"); 108 return ret; 109 } 110 111 ret = snd_soc_dai_set_sysclk(codec_dai, 112 RT5682_SCLK_S_PLL1, 113 params_rate(params) * 512, 114 SND_SOC_CLOCK_IN); 115 if (ret) { 116 dev_err(card->dev, "failed to set sysclk\n"); 117 return ret; 118 } 119 120 return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT); 121 } 122 123 static const struct snd_soc_ops mt8192_rt1015_i2s_ops = { 124 .hw_params = mt8192_rt1015_i2s_hw_params, 125 }; 126 127 static const struct snd_soc_ops mt8192_rt5682_i2s_ops = { 128 .hw_params = mt8192_rt5682_i2s_hw_params, 129 }; 130 131 static int mt8192_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd) 132 { 133 struct snd_soc_component *cmpnt_afe = 134 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 135 struct snd_soc_component *cmpnt_codec = 136 asoc_rtd_to_codec(rtd, 0)->component; 137 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 138 struct mt8192_afe_private *afe_priv = afe->platform_priv; 139 int phase; 140 unsigned int monitor; 141 int test_done_1, test_done_2, test_done_3; 142 int cycle_1, cycle_2, cycle_3; 143 int prev_cycle_1, prev_cycle_2, prev_cycle_3; 144 int chosen_phase_1, chosen_phase_2, chosen_phase_3; 145 int counter; 146 int mtkaif_calib_ok; 147 148 dev_info(afe->dev, "%s(), start\n", __func__); 149 150 pm_runtime_get_sync(afe->dev); 151 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 1); 152 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 0); 153 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 1); 154 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 0); 155 156 mt6359_mtkaif_calibration_enable(cmpnt_codec); 157 158 /* set clock protocol 2 */ 159 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38); 160 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x39); 161 162 /* set test type to synchronizer pulse */ 163 regmap_update_bits(afe_priv->topckgen, 164 CKSYS_AUD_TOP_CFG, 0xffff, 0x4); 165 166 mtkaif_calib_ok = true; 167 afe_priv->mtkaif_calibration_num_phase = 42; /* mt6359: 0 ~ 42 */ 168 afe_priv->mtkaif_chosen_phase[0] = -1; 169 afe_priv->mtkaif_chosen_phase[1] = -1; 170 afe_priv->mtkaif_chosen_phase[2] = -1; 171 172 for (phase = 0; 173 phase <= afe_priv->mtkaif_calibration_num_phase && 174 mtkaif_calib_ok; 175 phase++) { 176 mt6359_set_mtkaif_calibration_phase(cmpnt_codec, 177 phase, phase, phase); 178 179 regmap_update_bits(afe_priv->topckgen, 180 CKSYS_AUD_TOP_CFG, 0x1, 0x1); 181 182 test_done_1 = 0; 183 test_done_2 = 0; 184 test_done_3 = 0; 185 cycle_1 = -1; 186 cycle_2 = -1; 187 cycle_3 = -1; 188 counter = 0; 189 while (test_done_1 == 0 || 190 test_done_2 == 0 || 191 test_done_3 == 0) { 192 regmap_read(afe_priv->topckgen, 193 CKSYS_AUD_TOP_MON, &monitor); 194 195 test_done_1 = (monitor >> 28) & 0x1; 196 test_done_2 = (monitor >> 29) & 0x1; 197 test_done_3 = (monitor >> 30) & 0x1; 198 if (test_done_1 == 1) 199 cycle_1 = monitor & 0xf; 200 201 if (test_done_2 == 1) 202 cycle_2 = (monitor >> 4) & 0xf; 203 204 if (test_done_3 == 1) 205 cycle_3 = (monitor >> 8) & 0xf; 206 207 /* handle if never test done */ 208 if (++counter > 10000) { 209 dev_err(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n", 210 __func__, 211 cycle_1, cycle_2, cycle_3, monitor); 212 mtkaif_calib_ok = false; 213 break; 214 } 215 } 216 217 if (phase == 0) { 218 prev_cycle_1 = cycle_1; 219 prev_cycle_2 = cycle_2; 220 prev_cycle_3 = cycle_3; 221 } 222 223 if (cycle_1 != prev_cycle_1 && 224 afe_priv->mtkaif_chosen_phase[0] < 0) { 225 afe_priv->mtkaif_chosen_phase[0] = phase - 1; 226 afe_priv->mtkaif_phase_cycle[0] = prev_cycle_1; 227 } 228 229 if (cycle_2 != prev_cycle_2 && 230 afe_priv->mtkaif_chosen_phase[1] < 0) { 231 afe_priv->mtkaif_chosen_phase[1] = phase - 1; 232 afe_priv->mtkaif_phase_cycle[1] = prev_cycle_2; 233 } 234 235 if (cycle_3 != prev_cycle_3 && 236 afe_priv->mtkaif_chosen_phase[2] < 0) { 237 afe_priv->mtkaif_chosen_phase[2] = phase - 1; 238 afe_priv->mtkaif_phase_cycle[2] = prev_cycle_3; 239 } 240 241 regmap_update_bits(afe_priv->topckgen, 242 CKSYS_AUD_TOP_CFG, 0x1, 0x0); 243 244 if (afe_priv->mtkaif_chosen_phase[0] >= 0 && 245 afe_priv->mtkaif_chosen_phase[1] >= 0 && 246 afe_priv->mtkaif_chosen_phase[2] >= 0) 247 break; 248 } 249 250 if (afe_priv->mtkaif_chosen_phase[0] < 0) 251 chosen_phase_1 = 0; 252 else 253 chosen_phase_1 = afe_priv->mtkaif_chosen_phase[0]; 254 255 if (afe_priv->mtkaif_chosen_phase[1] < 0) 256 chosen_phase_2 = 0; 257 else 258 chosen_phase_2 = afe_priv->mtkaif_chosen_phase[1]; 259 260 if (afe_priv->mtkaif_chosen_phase[2] < 0) 261 chosen_phase_3 = 0; 262 else 263 chosen_phase_3 = afe_priv->mtkaif_chosen_phase[2]; 264 265 mt6359_set_mtkaif_calibration_phase(cmpnt_codec, 266 chosen_phase_1, 267 chosen_phase_2, 268 chosen_phase_3); 269 270 /* disable rx fifo */ 271 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38); 272 273 mt6359_mtkaif_calibration_disable(cmpnt_codec); 274 275 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 1); 276 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 0); 277 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 1); 278 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 0); 279 pm_runtime_put(afe->dev); 280 281 dev_info(afe->dev, "%s(), mtkaif_chosen_phase[0/1/2]:%d/%d/%d\n", 282 __func__, 283 afe_priv->mtkaif_chosen_phase[0], 284 afe_priv->mtkaif_chosen_phase[1], 285 afe_priv->mtkaif_chosen_phase[2]); 286 287 return 0; 288 } 289 290 static int mt8192_mt6359_init(struct snd_soc_pcm_runtime *rtd) 291 { 292 struct snd_soc_component *cmpnt_afe = 293 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 294 struct snd_soc_component *cmpnt_codec = 295 asoc_rtd_to_codec(rtd, 0)->component; 296 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 297 struct mt8192_afe_private *afe_priv = afe->platform_priv; 298 299 /* set mtkaif protocol */ 300 mt6359_set_mtkaif_protocol(cmpnt_codec, 301 MT6359_MTKAIF_PROTOCOL_2_CLK_P2); 302 afe_priv->mtkaif_protocol = MTKAIF_PROTOCOL_2_CLK_P2; 303 304 /* mtkaif calibration */ 305 mt8192_mt6359_mtkaif_calibration(rtd); 306 307 return 0; 308 } 309 310 static int mt8192_rt5682_init(struct snd_soc_pcm_runtime *rtd) 311 { 312 struct snd_soc_component *cmpnt_codec = 313 asoc_rtd_to_codec(rtd, 0)->component; 314 struct snd_soc_jack *jack = &headset_jack; 315 int ret; 316 317 ret = snd_soc_card_jack_new(rtd->card, "Headset Jack", 318 SND_JACK_HEADSET | SND_JACK_BTN_0 | 319 SND_JACK_BTN_1 | SND_JACK_BTN_2 | 320 SND_JACK_BTN_3, 321 jack, NULL, 0); 322 if (ret) { 323 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); 324 return ret; 325 } 326 327 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); 328 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); 329 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); 330 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); 331 332 ret = snd_soc_component_set_jack(cmpnt_codec, jack, NULL); 333 if (ret) { 334 dev_err(rtd->dev, "Headset Jack set failed: %d\n", ret); 335 return ret; 336 } 337 338 return 0; 339 }; 340 341 static int mt8192_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, 342 struct snd_pcm_hw_params *params) 343 { 344 /* fix BE i2s format to 32bit, clean param mask first */ 345 snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), 346 0, SNDRV_PCM_FORMAT_LAST); 347 348 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); 349 350 return 0; 351 } 352 353 static int 354 mt8192_mt6359_rt1015_rt5682_cap1_startup(struct snd_pcm_substream *substream) 355 { 356 struct snd_soc_pcm_runtime *rtd = substream->private_data; 357 struct snd_soc_component *component = 358 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 359 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component); 360 int ret; 361 362 static const unsigned int channels[] = { 363 1, 2, 4 364 }; 365 static const struct snd_pcm_hw_constraint_list constraints_channels = { 366 .count = ARRAY_SIZE(channels), 367 .list = channels, 368 .mask = 0, 369 }; 370 static const unsigned int rates[] = { 371 8000, 16000, 32000, 48000, 96000, 192000 372 }; 373 static const struct snd_pcm_hw_constraint_list constraints_rates = { 374 .count = ARRAY_SIZE(rates), 375 .list = rates, 376 .mask = 0, 377 }; 378 379 struct snd_pcm_runtime *runtime = substream->runtime; 380 381 ret = snd_pcm_hw_constraint_list(runtime, 0, 382 SNDRV_PCM_HW_PARAM_CHANNELS, 383 &constraints_channels); 384 if (ret < 0) { 385 dev_err(afe->dev, "hw_constraint_list channels failed\n"); 386 return ret; 387 } 388 389 ret = snd_pcm_hw_constraint_list(runtime, 0, 390 SNDRV_PCM_HW_PARAM_RATE, 391 &constraints_rates); 392 if (ret < 0) { 393 dev_err(afe->dev, "hw_constraint_list rate failed\n"); 394 return ret; 395 } 396 397 return 0; 398 } 399 400 static const struct snd_soc_ops mt8192_mt6359_rt1015_rt5682_capture1_ops = { 401 .startup = mt8192_mt6359_rt1015_rt5682_cap1_startup, 402 }; 403 404 static int 405 mt8192_mt6359_rt5682_startup(struct snd_pcm_substream *substream) 406 { 407 static const unsigned int channels[] = { 408 1, 2 409 }; 410 static const struct snd_pcm_hw_constraint_list constraints_channels = { 411 .count = ARRAY_SIZE(channels), 412 .list = channels, 413 .mask = 0, 414 }; 415 static const unsigned int rates[] = { 416 48000 417 }; 418 static const struct snd_pcm_hw_constraint_list constraints_rates = { 419 .count = ARRAY_SIZE(rates), 420 .list = rates, 421 .mask = 0, 422 }; 423 424 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 425 struct snd_pcm_runtime *runtime = substream->runtime; 426 int ret; 427 428 ret = snd_pcm_hw_constraint_list(runtime, 0, 429 SNDRV_PCM_HW_PARAM_CHANNELS, 430 &constraints_channels); 431 if (ret < 0) { 432 dev_err(rtd->dev, "hw_constraint_list channels failed\n"); 433 return ret; 434 } 435 436 ret = snd_pcm_hw_constraint_list(runtime, 0, 437 SNDRV_PCM_HW_PARAM_RATE, 438 &constraints_rates); 439 if (ret < 0) { 440 dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 441 return ret; 442 } 443 444 return 0; 445 } 446 447 static const struct snd_soc_ops mt8192_mt6359_rt5682_ops = { 448 .startup = mt8192_mt6359_rt5682_startup, 449 }; 450 451 /* FE */ 452 SND_SOC_DAILINK_DEFS(playback1, 453 DAILINK_COMP_ARRAY(COMP_CPU("DL1")), 454 DAILINK_COMP_ARRAY(COMP_DUMMY()), 455 DAILINK_COMP_ARRAY(COMP_EMPTY())); 456 457 SND_SOC_DAILINK_DEFS(playback12, 458 DAILINK_COMP_ARRAY(COMP_CPU("DL12")), 459 DAILINK_COMP_ARRAY(COMP_DUMMY()), 460 DAILINK_COMP_ARRAY(COMP_EMPTY())); 461 462 SND_SOC_DAILINK_DEFS(playback2, 463 DAILINK_COMP_ARRAY(COMP_CPU("DL2")), 464 DAILINK_COMP_ARRAY(COMP_DUMMY()), 465 DAILINK_COMP_ARRAY(COMP_EMPTY())); 466 467 SND_SOC_DAILINK_DEFS(playback3, 468 DAILINK_COMP_ARRAY(COMP_CPU("DL3")), 469 DAILINK_COMP_ARRAY(COMP_DUMMY()), 470 DAILINK_COMP_ARRAY(COMP_EMPTY())); 471 472 SND_SOC_DAILINK_DEFS(playback4, 473 DAILINK_COMP_ARRAY(COMP_CPU("DL4")), 474 DAILINK_COMP_ARRAY(COMP_DUMMY()), 475 DAILINK_COMP_ARRAY(COMP_EMPTY())); 476 477 SND_SOC_DAILINK_DEFS(playback5, 478 DAILINK_COMP_ARRAY(COMP_CPU("DL5")), 479 DAILINK_COMP_ARRAY(COMP_DUMMY()), 480 DAILINK_COMP_ARRAY(COMP_EMPTY())); 481 482 SND_SOC_DAILINK_DEFS(playback6, 483 DAILINK_COMP_ARRAY(COMP_CPU("DL6")), 484 DAILINK_COMP_ARRAY(COMP_DUMMY()), 485 DAILINK_COMP_ARRAY(COMP_EMPTY())); 486 487 SND_SOC_DAILINK_DEFS(playback7, 488 DAILINK_COMP_ARRAY(COMP_CPU("DL7")), 489 DAILINK_COMP_ARRAY(COMP_DUMMY()), 490 DAILINK_COMP_ARRAY(COMP_EMPTY())); 491 492 SND_SOC_DAILINK_DEFS(playback8, 493 DAILINK_COMP_ARRAY(COMP_CPU("DL8")), 494 DAILINK_COMP_ARRAY(COMP_DUMMY()), 495 DAILINK_COMP_ARRAY(COMP_EMPTY())); 496 497 SND_SOC_DAILINK_DEFS(playback9, 498 DAILINK_COMP_ARRAY(COMP_CPU("DL9")), 499 DAILINK_COMP_ARRAY(COMP_DUMMY()), 500 DAILINK_COMP_ARRAY(COMP_EMPTY())); 501 502 SND_SOC_DAILINK_DEFS(capture1, 503 DAILINK_COMP_ARRAY(COMP_CPU("UL1")), 504 DAILINK_COMP_ARRAY(COMP_DUMMY()), 505 DAILINK_COMP_ARRAY(COMP_EMPTY())); 506 507 SND_SOC_DAILINK_DEFS(capture2, 508 DAILINK_COMP_ARRAY(COMP_CPU("UL2")), 509 DAILINK_COMP_ARRAY(COMP_DUMMY()), 510 DAILINK_COMP_ARRAY(COMP_EMPTY())); 511 512 SND_SOC_DAILINK_DEFS(capture3, 513 DAILINK_COMP_ARRAY(COMP_CPU("UL3")), 514 DAILINK_COMP_ARRAY(COMP_DUMMY()), 515 DAILINK_COMP_ARRAY(COMP_EMPTY())); 516 517 SND_SOC_DAILINK_DEFS(capture4, 518 DAILINK_COMP_ARRAY(COMP_CPU("UL4")), 519 DAILINK_COMP_ARRAY(COMP_DUMMY()), 520 DAILINK_COMP_ARRAY(COMP_EMPTY())); 521 522 SND_SOC_DAILINK_DEFS(capture5, 523 DAILINK_COMP_ARRAY(COMP_CPU("UL5")), 524 DAILINK_COMP_ARRAY(COMP_DUMMY()), 525 DAILINK_COMP_ARRAY(COMP_EMPTY())); 526 527 SND_SOC_DAILINK_DEFS(capture6, 528 DAILINK_COMP_ARRAY(COMP_CPU("UL6")), 529 DAILINK_COMP_ARRAY(COMP_DUMMY()), 530 DAILINK_COMP_ARRAY(COMP_EMPTY())); 531 532 SND_SOC_DAILINK_DEFS(capture7, 533 DAILINK_COMP_ARRAY(COMP_CPU("UL7")), 534 DAILINK_COMP_ARRAY(COMP_DUMMY()), 535 DAILINK_COMP_ARRAY(COMP_EMPTY())); 536 537 SND_SOC_DAILINK_DEFS(capture8, 538 DAILINK_COMP_ARRAY(COMP_CPU("UL8")), 539 DAILINK_COMP_ARRAY(COMP_DUMMY()), 540 DAILINK_COMP_ARRAY(COMP_EMPTY())); 541 542 SND_SOC_DAILINK_DEFS(capture_mono1, 543 DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_1")), 544 DAILINK_COMP_ARRAY(COMP_DUMMY()), 545 DAILINK_COMP_ARRAY(COMP_EMPTY())); 546 547 SND_SOC_DAILINK_DEFS(capture_mono2, 548 DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_2")), 549 DAILINK_COMP_ARRAY(COMP_DUMMY()), 550 DAILINK_COMP_ARRAY(COMP_EMPTY())); 551 552 SND_SOC_DAILINK_DEFS(capture_mono3, 553 DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_3")), 554 DAILINK_COMP_ARRAY(COMP_DUMMY()), 555 DAILINK_COMP_ARRAY(COMP_EMPTY())); 556 557 SND_SOC_DAILINK_DEFS(playback_hdmi, 558 DAILINK_COMP_ARRAY(COMP_CPU("HDMI")), 559 DAILINK_COMP_ARRAY(COMP_DUMMY()), 560 DAILINK_COMP_ARRAY(COMP_EMPTY())); 561 562 /* BE */ 563 SND_SOC_DAILINK_DEFS(primary_codec, 564 DAILINK_COMP_ARRAY(COMP_CPU("ADDA")), 565 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound", 566 "mt6359-snd-codec-aif1"), 567 COMP_CODEC("dmic-codec", 568 "dmic-hifi")), 569 DAILINK_COMP_ARRAY(COMP_EMPTY())); 570 571 SND_SOC_DAILINK_DEFS(primary_codec_ch34, 572 DAILINK_COMP_ARRAY(COMP_CPU("ADDA_CH34")), 573 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound", 574 "mt6359-snd-codec-aif2")), 575 DAILINK_COMP_ARRAY(COMP_EMPTY())); 576 577 SND_SOC_DAILINK_DEFS(ap_dmic, 578 DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC")), 579 DAILINK_COMP_ARRAY(COMP_DUMMY()), 580 DAILINK_COMP_ARRAY(COMP_EMPTY())); 581 582 SND_SOC_DAILINK_DEFS(ap_dmic_ch34, 583 DAILINK_COMP_ARRAY(COMP_CPU("AP_DMIC_CH34")), 584 DAILINK_COMP_ARRAY(COMP_DUMMY()), 585 DAILINK_COMP_ARRAY(COMP_EMPTY())); 586 587 SND_SOC_DAILINK_DEFS(i2s0, 588 DAILINK_COMP_ARRAY(COMP_CPU("I2S0")), 589 DAILINK_COMP_ARRAY(COMP_DUMMY()), 590 DAILINK_COMP_ARRAY(COMP_EMPTY())); 591 592 SND_SOC_DAILINK_DEFS(i2s1, 593 DAILINK_COMP_ARRAY(COMP_CPU("I2S1")), 594 DAILINK_COMP_ARRAY(COMP_DUMMY()), 595 DAILINK_COMP_ARRAY(COMP_EMPTY())); 596 597 SND_SOC_DAILINK_DEFS(i2s2, 598 DAILINK_COMP_ARRAY(COMP_CPU("I2S2")), 599 DAILINK_COMP_ARRAY(COMP_DUMMY()), 600 DAILINK_COMP_ARRAY(COMP_EMPTY())); 601 602 SND_SOC_DAILINK_DEFS(i2s3_rt1015, 603 DAILINK_COMP_ARRAY(COMP_CPU("I2S3")), 604 DAILINK_COMP_ARRAY(COMP_CODEC(RT1015_DEV0_NAME, 605 RT1015_CODEC_DAI), 606 COMP_CODEC(RT1015_DEV1_NAME, 607 RT1015_CODEC_DAI)), 608 DAILINK_COMP_ARRAY(COMP_EMPTY())); 609 610 SND_SOC_DAILINK_DEFS(i2s3_rt1015p, 611 DAILINK_COMP_ARRAY(COMP_CPU("I2S3")), 612 DAILINK_COMP_ARRAY(COMP_CODEC("rt1015p", "HiFi")), 613 DAILINK_COMP_ARRAY(COMP_EMPTY())); 614 615 SND_SOC_DAILINK_DEFS(i2s5, 616 DAILINK_COMP_ARRAY(COMP_CPU("I2S5")), 617 DAILINK_COMP_ARRAY(COMP_DUMMY()), 618 DAILINK_COMP_ARRAY(COMP_EMPTY())); 619 620 SND_SOC_DAILINK_DEFS(i2s6, 621 DAILINK_COMP_ARRAY(COMP_CPU("I2S6")), 622 DAILINK_COMP_ARRAY(COMP_DUMMY()), 623 DAILINK_COMP_ARRAY(COMP_EMPTY())); 624 625 SND_SOC_DAILINK_DEFS(i2s7, 626 DAILINK_COMP_ARRAY(COMP_CPU("I2S7")), 627 DAILINK_COMP_ARRAY(COMP_DUMMY()), 628 DAILINK_COMP_ARRAY(COMP_EMPTY())); 629 630 SND_SOC_DAILINK_DEFS(i2s8, 631 DAILINK_COMP_ARRAY(COMP_CPU("I2S8")), 632 DAILINK_COMP_ARRAY(COMP_CODEC(RT5682_DEV0_NAME, 633 RT5682_CODEC_DAI)), 634 DAILINK_COMP_ARRAY(COMP_EMPTY())); 635 636 SND_SOC_DAILINK_DEFS(i2s9, 637 DAILINK_COMP_ARRAY(COMP_CPU("I2S9")), 638 DAILINK_COMP_ARRAY(COMP_CODEC(RT5682_DEV0_NAME, 639 RT5682_CODEC_DAI)), 640 DAILINK_COMP_ARRAY(COMP_EMPTY())); 641 642 SND_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 647 SND_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 652 SND_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 657 SND_SOC_DAILINK_DEFS(tdm, 658 DAILINK_COMP_ARRAY(COMP_CPU("TDM")), 659 DAILINK_COMP_ARRAY(COMP_DUMMY()), 660 DAILINK_COMP_ARRAY(COMP_EMPTY())); 661 662 static 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_rt1015_rt5682_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 }, 928 { 929 .name = "I2S5", 930 .no_pcm = 1, 931 .dpcm_playback = 1, 932 .ignore_suspend = 1, 933 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup, 934 SND_SOC_DAILINK_REG(i2s5), 935 }, 936 { 937 .name = "I2S6", 938 .no_pcm = 1, 939 .dpcm_capture = 1, 940 .ignore_suspend = 1, 941 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup, 942 SND_SOC_DAILINK_REG(i2s6), 943 }, 944 { 945 .name = "I2S7", 946 .no_pcm = 1, 947 .dpcm_playback = 1, 948 .ignore_suspend = 1, 949 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup, 950 SND_SOC_DAILINK_REG(i2s7), 951 }, 952 { 953 .name = "I2S8", 954 .no_pcm = 1, 955 .dpcm_capture = 1, 956 .ignore_suspend = 1, 957 .init = mt8192_rt5682_init, 958 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup, 959 SND_SOC_DAILINK_REG(i2s8), 960 .ops = &mt8192_rt5682_i2s_ops, 961 }, 962 { 963 .name = "I2S9", 964 .no_pcm = 1, 965 .dpcm_playback = 1, 966 .ignore_suspend = 1, 967 .be_hw_params_fixup = mt8192_i2s_hw_params_fixup, 968 SND_SOC_DAILINK_REG(i2s9), 969 .ops = &mt8192_rt5682_i2s_ops, 970 }, 971 { 972 .name = "CONNSYS_I2S", 973 .no_pcm = 1, 974 .dpcm_capture = 1, 975 .ignore_suspend = 1, 976 SND_SOC_DAILINK_REG(connsys_i2s), 977 }, 978 { 979 .name = "PCM 1", 980 .no_pcm = 1, 981 .dpcm_playback = 1, 982 .dpcm_capture = 1, 983 .ignore_suspend = 1, 984 SND_SOC_DAILINK_REG(pcm1), 985 }, 986 { 987 .name = "PCM 2", 988 .no_pcm = 1, 989 .dpcm_playback = 1, 990 .dpcm_capture = 1, 991 .ignore_suspend = 1, 992 SND_SOC_DAILINK_REG(pcm2), 993 }, 994 { 995 .name = "TDM", 996 .no_pcm = 1, 997 .dpcm_playback = 1, 998 .ignore_suspend = 1, 999 SND_SOC_DAILINK_REG(tdm), 1000 }, 1001 }; 1002 1003 static const struct snd_soc_dapm_widget 1004 mt8192_mt6359_rt1015_rt5682_widgets[] = { 1005 SND_SOC_DAPM_SPK("Left Spk", NULL), 1006 SND_SOC_DAPM_SPK("Right Spk", NULL), 1007 SND_SOC_DAPM_HP("Headphone Jack", NULL), 1008 SND_SOC_DAPM_MIC("Headset Mic", NULL), 1009 }; 1010 1011 static const struct snd_soc_dapm_route mt8192_mt6359_rt1015_rt5682_routes[] = { 1012 /* speaker */ 1013 { "Left Spk", NULL, "Left SPO" }, 1014 { "Right Spk", NULL, "Right SPO" }, 1015 /* headset */ 1016 { "Headphone Jack", NULL, "HPOL" }, 1017 { "Headphone Jack", NULL, "HPOR" }, 1018 { "IN1P", NULL, "Headset Mic" }, 1019 }; 1020 1021 static const struct snd_kcontrol_new mt8192_mt6359_rt1015_rt5682_controls[] = { 1022 SOC_DAPM_PIN_SWITCH("Left Spk"), 1023 SOC_DAPM_PIN_SWITCH("Right Spk"), 1024 SOC_DAPM_PIN_SWITCH("Headphone Jack"), 1025 SOC_DAPM_PIN_SWITCH("Headset Mic"), 1026 }; 1027 1028 static struct snd_soc_codec_conf rt1015_amp_conf[] = { 1029 { 1030 .dlc = COMP_CODEC_CONF(RT1015_DEV0_NAME), 1031 .name_prefix = "Left", 1032 }, 1033 { 1034 .dlc = COMP_CODEC_CONF(RT1015_DEV1_NAME), 1035 .name_prefix = "Right", 1036 }, 1037 }; 1038 1039 static struct snd_soc_card mt8192_mt6359_rt1015_rt5682_card = { 1040 .name = "mt8192_mt6359_rt1015_rt5682", 1041 .owner = THIS_MODULE, 1042 .dai_link = mt8192_mt6359_dai_links, 1043 .num_links = ARRAY_SIZE(mt8192_mt6359_dai_links), 1044 .controls = mt8192_mt6359_rt1015_rt5682_controls, 1045 .num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_controls), 1046 .dapm_widgets = mt8192_mt6359_rt1015_rt5682_widgets, 1047 .num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_widgets), 1048 .dapm_routes = mt8192_mt6359_rt1015_rt5682_routes, 1049 .num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015_rt5682_routes), 1050 .codec_conf = rt1015_amp_conf, 1051 .num_configs = ARRAY_SIZE(rt1015_amp_conf), 1052 }; 1053 1054 static const struct snd_soc_dapm_widget 1055 mt8192_mt6359_rt1015p_rt5682_widgets[] = { 1056 SND_SOC_DAPM_SPK("Speakers", NULL), 1057 SND_SOC_DAPM_HP("Headphone Jack", NULL), 1058 SND_SOC_DAPM_MIC("Headset Mic", NULL), 1059 }; 1060 1061 static const struct snd_soc_dapm_route mt8192_mt6359_rt1015p_rt5682_routes[] = { 1062 /* speaker */ 1063 { "Speakers", NULL, "Speaker" }, 1064 /* headset */ 1065 { "Headphone Jack", NULL, "HPOL" }, 1066 { "Headphone Jack", NULL, "HPOR" }, 1067 { "IN1P", NULL, "Headset Mic" }, 1068 }; 1069 1070 static const struct snd_kcontrol_new mt8192_mt6359_rt1015p_rt5682_controls[] = { 1071 SOC_DAPM_PIN_SWITCH("Speakers"), 1072 SOC_DAPM_PIN_SWITCH("Headphone Jack"), 1073 SOC_DAPM_PIN_SWITCH("Headset Mic"), 1074 }; 1075 1076 static struct snd_soc_card mt8192_mt6359_rt1015p_rt5682_card = { 1077 .name = "mt8192_mt6359_rt1015p_rt5682", 1078 .owner = THIS_MODULE, 1079 .dai_link = mt8192_mt6359_dai_links, 1080 .num_links = ARRAY_SIZE(mt8192_mt6359_dai_links), 1081 .controls = mt8192_mt6359_rt1015p_rt5682_controls, 1082 .num_controls = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682_controls), 1083 .dapm_widgets = mt8192_mt6359_rt1015p_rt5682_widgets, 1084 .num_dapm_widgets = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682_widgets), 1085 .dapm_routes = mt8192_mt6359_rt1015p_rt5682_routes, 1086 .num_dapm_routes = ARRAY_SIZE(mt8192_mt6359_rt1015p_rt5682_routes), 1087 }; 1088 1089 static int mt8192_mt6359_dev_probe(struct platform_device *pdev) 1090 { 1091 struct snd_soc_card *card; 1092 struct device_node *platform_node; 1093 int ret, i; 1094 struct snd_soc_dai_link *dai_link; 1095 const struct of_device_id *match; 1096 1097 platform_node = of_parse_phandle(pdev->dev.of_node, 1098 "mediatek,platform", 0); 1099 if (!platform_node) { 1100 dev_err(&pdev->dev, "Property 'platform' missing or invalid\n"); 1101 return -EINVAL; 1102 } 1103 1104 match = of_match_device(pdev->dev.driver->of_match_table, &pdev->dev); 1105 if (!match || !match->data) 1106 return -EINVAL; 1107 1108 card = (struct snd_soc_card *)match->data; 1109 card->dev = &pdev->dev; 1110 1111 for_each_card_prelinks(card, i, dai_link) { 1112 if (strcmp(dai_link->name, "I2S3") == 0) { 1113 if (card == &mt8192_mt6359_rt1015_rt5682_card) { 1114 dai_link->ops = &mt8192_rt1015_i2s_ops; 1115 dai_link->cpus = i2s3_rt1015_cpus; 1116 dai_link->num_cpus = 1117 ARRAY_SIZE(i2s3_rt1015_cpus); 1118 dai_link->codecs = i2s3_rt1015_codecs; 1119 dai_link->num_codecs = 1120 ARRAY_SIZE(i2s3_rt1015_codecs); 1121 dai_link->platforms = i2s3_rt1015_platforms; 1122 dai_link->num_platforms = 1123 ARRAY_SIZE(i2s3_rt1015_platforms); 1124 } else if (card == &mt8192_mt6359_rt1015p_rt5682_card) { 1125 dai_link->cpus = i2s3_rt1015p_cpus; 1126 dai_link->num_cpus = 1127 ARRAY_SIZE(i2s3_rt1015p_cpus); 1128 dai_link->codecs = i2s3_rt1015p_codecs; 1129 dai_link->num_codecs = 1130 ARRAY_SIZE(i2s3_rt1015p_codecs); 1131 dai_link->platforms = i2s3_rt1015p_platforms; 1132 dai_link->num_platforms = 1133 ARRAY_SIZE(i2s3_rt1015p_platforms); 1134 } 1135 } 1136 1137 if (!dai_link->platforms->name) 1138 dai_link->platforms->of_node = platform_node; 1139 } 1140 1141 ret = mt8192_afe_gpio_init(&pdev->dev); 1142 if (ret) { 1143 dev_err(&pdev->dev, "init gpio error %d\n", ret); 1144 return ret; 1145 } 1146 1147 return devm_snd_soc_register_card(&pdev->dev, card); 1148 } 1149 1150 #ifdef CONFIG_OF 1151 static const struct of_device_id mt8192_mt6359_dt_match[] = { 1152 { 1153 .compatible = "mediatek,mt8192_mt6359_rt1015_rt5682", 1154 .data = &mt8192_mt6359_rt1015_rt5682_card, 1155 }, 1156 { 1157 .compatible = "mediatek,mt8192_mt6359_rt1015p_rt5682", 1158 .data = &mt8192_mt6359_rt1015p_rt5682_card, 1159 }, 1160 {} 1161 }; 1162 #endif 1163 1164 static const struct dev_pm_ops mt8192_mt6359_pm_ops = { 1165 .poweroff = snd_soc_poweroff, 1166 .restore = snd_soc_resume, 1167 }; 1168 1169 static struct platform_driver mt8192_mt6359_driver = { 1170 .driver = { 1171 .name = "mt8192_mt6359", 1172 #ifdef CONFIG_OF 1173 .of_match_table = mt8192_mt6359_dt_match, 1174 #endif 1175 .pm = &mt8192_mt6359_pm_ops, 1176 }, 1177 .probe = mt8192_mt6359_dev_probe, 1178 }; 1179 1180 module_platform_driver(mt8192_mt6359_driver); 1181 1182 /* Module information */ 1183 MODULE_DESCRIPTION("MT8192-MT6359 ALSA SoC machine driver"); 1184 MODULE_AUTHOR("Jiaxin Yu <jiaxin.yu@mediatek.com>"); 1185 MODULE_LICENSE("GPL v2"); 1186 MODULE_ALIAS("mt8192_mt6359 soc card"); 1187