1 /* 2 * Intel Kabylake I2S Machine Driver with MAXIM98927 3 * and RT5663 Codecs 4 * 5 * Copyright (C) 2017, Intel Corporation. All rights reserved. 6 * 7 * Modified from: 8 * Intel Skylake I2S Machine driver 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public License version 12 * 2 as published by the Free Software Foundation. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 */ 19 20 #include <linux/input.h> 21 #include <linux/module.h> 22 #include <linux/platform_device.h> 23 #include <sound/core.h> 24 #include <sound/jack.h> 25 #include <sound/pcm.h> 26 #include <sound/pcm_params.h> 27 #include <sound/soc.h> 28 #include "../../codecs/rt5663.h" 29 #include "../../codecs/hdac_hdmi.h" 30 #include "../skylake/skl.h" 31 32 #define KBL_REALTEK_CODEC_DAI "rt5663-aif" 33 #define KBL_MAXIM_CODEC_DAI "max98927-aif1" 34 #define DMIC_CH(p) p->list[p->count-1] 35 #define MAXIM_DEV0_NAME "i2c-MX98927:00" 36 #define MAXIM_DEV1_NAME "i2c-MX98927:01" 37 38 static struct snd_soc_card *kabylake_audio_card; 39 static const struct snd_pcm_hw_constraint_list *dmic_constraints; 40 static struct snd_soc_jack skylake_hdmi[3]; 41 42 struct kbl_hdmi_pcm { 43 struct list_head head; 44 struct snd_soc_dai *codec_dai; 45 int device; 46 }; 47 48 struct kbl_rt5663_private { 49 struct snd_soc_jack kabylake_headset; 50 struct list_head hdmi_pcm_list; 51 }; 52 53 enum { 54 KBL_DPCM_AUDIO_PB = 0, 55 KBL_DPCM_AUDIO_CP, 56 KBL_DPCM_AUDIO_HS_PB, 57 KBL_DPCM_AUDIO_ECHO_REF_CP, 58 KBL_DPCM_AUDIO_REF_CP, 59 KBL_DPCM_AUDIO_DMIC_CP, 60 KBL_DPCM_AUDIO_HDMI1_PB, 61 KBL_DPCM_AUDIO_HDMI2_PB, 62 KBL_DPCM_AUDIO_HDMI3_PB, 63 }; 64 65 static const struct snd_kcontrol_new kabylake_controls[] = { 66 SOC_DAPM_PIN_SWITCH("Headphone Jack"), 67 SOC_DAPM_PIN_SWITCH("Headset Mic"), 68 SOC_DAPM_PIN_SWITCH("Left Spk"), 69 SOC_DAPM_PIN_SWITCH("Right Spk"), 70 }; 71 72 static const struct snd_soc_dapm_widget kabylake_widgets[] = { 73 SND_SOC_DAPM_HP("Headphone Jack", NULL), 74 SND_SOC_DAPM_MIC("Headset Mic", NULL), 75 SND_SOC_DAPM_SPK("Left Spk", NULL), 76 SND_SOC_DAPM_SPK("Right Spk", NULL), 77 SND_SOC_DAPM_MIC("SoC DMIC", NULL), 78 SND_SOC_DAPM_SPK("HDMI1", NULL), 79 SND_SOC_DAPM_SPK("HDMI2", NULL), 80 SND_SOC_DAPM_SPK("HDMI3", NULL), 81 82 }; 83 84 static const struct snd_soc_dapm_route kabylake_map[] = { 85 /* HP jack connectors - unknown if we have jack detection */ 86 { "Headphone Jack", NULL, "HPOL" }, 87 { "Headphone Jack", NULL, "HPOR" }, 88 89 /* speaker */ 90 { "Left Spk", NULL, "Left BE_OUT" }, 91 { "Right Spk", NULL, "Right BE_OUT" }, 92 93 /* other jacks */ 94 { "IN1P", NULL, "Headset Mic" }, 95 { "IN1N", NULL, "Headset Mic" }, 96 { "DMic", NULL, "SoC DMIC" }, 97 98 /* CODEC BE connections */ 99 { "Left HiFi Playback", NULL, "ssp0 Tx" }, 100 { "Right HiFi Playback", NULL, "ssp0 Tx" }, 101 { "ssp0 Tx", NULL, "spk_out" }, 102 103 { "AIF Playback", NULL, "ssp1 Tx" }, 104 { "ssp1 Tx", NULL, "hs_out" }, 105 106 { "hs_in", NULL, "ssp1 Rx" }, 107 { "ssp1 Rx", NULL, "AIF Capture" }, 108 109 /* IV feedback path */ 110 { "codec0_fb_in", NULL, "ssp0 Rx"}, 111 { "ssp0 Rx", NULL, "Left HiFi Capture" }, 112 { "ssp0 Rx", NULL, "Right HiFi Capture" }, 113 114 /* DMIC */ 115 { "dmic01_hifi", NULL, "DMIC01 Rx" }, 116 { "DMIC01 Rx", NULL, "DMIC AIF" }, 117 118 { "hifi3", NULL, "iDisp3 Tx"}, 119 { "iDisp3 Tx", NULL, "iDisp3_out"}, 120 { "hifi2", NULL, "iDisp2 Tx"}, 121 { "iDisp2 Tx", NULL, "iDisp2_out"}, 122 { "hifi1", NULL, "iDisp1 Tx"}, 123 { "iDisp1 Tx", NULL, "iDisp1_out"}, 124 }; 125 126 enum { 127 KBL_DPCM_AUDIO_5663_PB = 0, 128 KBL_DPCM_AUDIO_5663_CP, 129 KBL_DPCM_AUDIO_5663_HDMI1_PB, 130 KBL_DPCM_AUDIO_5663_HDMI2_PB, 131 }; 132 133 static const struct snd_kcontrol_new kabylake_5663_controls[] = { 134 SOC_DAPM_PIN_SWITCH("Headphone Jack"), 135 SOC_DAPM_PIN_SWITCH("Headset Mic"), 136 }; 137 138 static const struct snd_soc_dapm_widget kabylake_5663_widgets[] = { 139 SND_SOC_DAPM_HP("Headphone Jack", NULL), 140 SND_SOC_DAPM_MIC("Headset Mic", NULL), 141 SND_SOC_DAPM_SPK("DP", NULL), 142 SND_SOC_DAPM_SPK("HDMI", NULL), 143 }; 144 145 static const struct snd_soc_dapm_route kabylake_5663_map[] = { 146 { "Headphone Jack", NULL, "HPOL" }, 147 { "Headphone Jack", NULL, "HPOR" }, 148 149 /* other jacks */ 150 { "IN1P", NULL, "Headset Mic" }, 151 { "IN1N", NULL, "Headset Mic" }, 152 153 { "HDMI", NULL, "hif5 Output" }, 154 { "DP", NULL, "hif6 Output" }, 155 156 /* CODEC BE connections */ 157 { "AIF Playback", NULL, "ssp1 Tx" }, 158 { "ssp1 Tx", NULL, "codec1_out" }, 159 160 { "codec0_in", NULL, "ssp1 Rx" }, 161 { "ssp1 Rx", NULL, "AIF Capture" }, 162 163 { "hifi2", NULL, "iDisp2 Tx"}, 164 { "iDisp2 Tx", NULL, "iDisp2_out"}, 165 { "hifi1", NULL, "iDisp1 Tx"}, 166 { "iDisp1 Tx", NULL, "iDisp1_out"}, 167 }; 168 169 static struct snd_soc_codec_conf max98927_codec_conf[] = { 170 { 171 .dev_name = MAXIM_DEV0_NAME, 172 .name_prefix = "Right", 173 }, 174 { 175 .dev_name = MAXIM_DEV1_NAME, 176 .name_prefix = "Left", 177 }, 178 }; 179 180 static struct snd_soc_dai_link_component max98927_codec_components[] = { 181 { /* Left */ 182 .name = MAXIM_DEV0_NAME, 183 .dai_name = KBL_MAXIM_CODEC_DAI, 184 }, 185 { /* Right */ 186 .name = MAXIM_DEV1_NAME, 187 .dai_name = KBL_MAXIM_CODEC_DAI, 188 }, 189 }; 190 191 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd) 192 { 193 int ret; 194 struct snd_soc_dapm_context *dapm; 195 struct snd_soc_component *component = rtd->cpu_dai->component; 196 197 dapm = snd_soc_component_get_dapm(component); 198 ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture"); 199 if (ret) { 200 dev_err(rtd->dev, "Ref Cap ignore suspend failed %d\n", ret); 201 return ret; 202 } 203 204 return ret; 205 } 206 207 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd) 208 { 209 int ret; 210 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card); 211 struct snd_soc_codec *codec = rtd->codec; 212 struct snd_soc_jack *jack; 213 214 /* 215 * Headset buttons map to the google Reference headset. 216 * These can be configured by userspace. 217 */ 218 ret = snd_soc_card_jack_new(kabylake_audio_card, "Headset Jack", 219 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 | 220 SND_JACK_BTN_2 | SND_JACK_BTN_3, &ctx->kabylake_headset, 221 NULL, 0); 222 if (ret) { 223 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret); 224 return ret; 225 } 226 227 jack = &ctx->kabylake_headset; 228 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_MEDIA); 229 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); 230 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); 231 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); 232 233 rt5663_set_jack_detect(codec, &ctx->kabylake_headset); 234 return ret; 235 } 236 237 static int kabylake_rt5663_max98927_codec_init(struct snd_soc_pcm_runtime *rtd) 238 { 239 int ret; 240 241 ret = kabylake_rt5663_codec_init(rtd); 242 if (ret) 243 return ret; 244 245 ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC"); 246 if (ret) { 247 dev_err(rtd->dev, "SoC DMIC ignore suspend failed %d\n", ret); 248 return ret; 249 } 250 251 return ret; 252 } 253 254 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device) 255 { 256 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card); 257 struct snd_soc_dai *dai = rtd->codec_dai; 258 struct kbl_hdmi_pcm *pcm; 259 260 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL); 261 if (!pcm) 262 return -ENOMEM; 263 264 pcm->device = device; 265 pcm->codec_dai = dai; 266 267 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list); 268 269 return 0; 270 } 271 272 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd) 273 { 274 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB); 275 } 276 277 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd) 278 { 279 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB); 280 } 281 282 static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd) 283 { 284 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB); 285 } 286 287 static int kabylake_5663_hdmi1_init(struct snd_soc_pcm_runtime *rtd) 288 { 289 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI1_PB); 290 } 291 292 static int kabylake_5663_hdmi2_init(struct snd_soc_pcm_runtime *rtd) 293 { 294 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI2_PB); 295 } 296 297 static unsigned int rates[] = { 298 48000, 299 }; 300 301 static const struct snd_pcm_hw_constraint_list constraints_rates = { 302 .count = ARRAY_SIZE(rates), 303 .list = rates, 304 .mask = 0, 305 }; 306 307 static unsigned int channels[] = { 308 2, 309 }; 310 311 static const struct snd_pcm_hw_constraint_list constraints_channels = { 312 .count = ARRAY_SIZE(channels), 313 .list = channels, 314 .mask = 0, 315 }; 316 317 static int kbl_fe_startup(struct snd_pcm_substream *substream) 318 { 319 struct snd_pcm_runtime *runtime = substream->runtime; 320 321 /* 322 * On this platform for PCM device we support, 323 * 48Khz 324 * stereo 325 * 16 bit audio 326 */ 327 328 runtime->hw.channels_max = 2; 329 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 330 &constraints_channels); 331 332 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; 333 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16); 334 335 snd_pcm_hw_constraint_list(runtime, 0, 336 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); 337 338 return 0; 339 } 340 341 static const struct snd_soc_ops kabylake_rt5663_fe_ops = { 342 .startup = kbl_fe_startup, 343 }; 344 345 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd, 346 struct snd_pcm_hw_params *params) 347 { 348 struct snd_interval *rate = hw_param_interval(params, 349 SNDRV_PCM_HW_PARAM_RATE); 350 struct snd_interval *channels = hw_param_interval(params, 351 SNDRV_PCM_HW_PARAM_CHANNELS); 352 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 353 354 /* The ADSP will convert the FE rate to 48k, stereo */ 355 rate->min = rate->max = 48000; 356 channels->min = channels->max = 2; 357 /* set SSP1 to 24 bit */ 358 snd_mask_none(fmt); 359 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE); 360 361 return 0; 362 } 363 364 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream, 365 struct snd_pcm_hw_params *params) 366 { 367 struct snd_soc_pcm_runtime *rtd = substream->private_data; 368 struct snd_soc_dai *codec_dai = rtd->codec_dai; 369 int ret; 370 371 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */ 372 rt5663_sel_asrc_clk_src(codec_dai->codec, 373 RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER, 374 RT5663_CLK_SEL_I2S1_ASRC); 375 376 ret = snd_soc_dai_set_sysclk(codec_dai, 377 RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN); 378 if (ret < 0) 379 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret); 380 381 return ret; 382 } 383 384 static struct snd_soc_ops kabylake_rt5663_ops = { 385 .hw_params = kabylake_rt5663_hw_params, 386 }; 387 388 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd, 389 struct snd_pcm_hw_params *params) 390 { 391 struct snd_interval *channels = hw_param_interval(params, 392 SNDRV_PCM_HW_PARAM_CHANNELS); 393 394 if (params_channels(params) == 2 || DMIC_CH(dmic_constraints) == 2) 395 channels->min = channels->max = 2; 396 else 397 channels->min = channels->max = 4; 398 399 return 0; 400 } 401 402 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream, 403 struct snd_pcm_hw_params *params) 404 { 405 struct snd_soc_pcm_runtime *rtd = substream->private_data; 406 int ret = 0, j; 407 408 for (j = 0; j < rtd->num_codecs; j++) { 409 struct snd_soc_dai *codec_dai = rtd->codec_dais[j]; 410 411 if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) { 412 /* 413 * Use channel 4 and 5 for the first amp 414 */ 415 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16); 416 if (ret < 0) { 417 dev_err(rtd->dev, "set TDM slot err:%d\n", ret); 418 return ret; 419 } 420 } 421 if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) { 422 /* 423 * Use channel 6 and 7 for the second amp 424 */ 425 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16); 426 if (ret < 0) { 427 dev_err(rtd->dev, "set TDM slot err:%d\n", ret); 428 return ret; 429 } 430 } 431 } 432 return ret; 433 } 434 435 static struct snd_soc_ops kabylake_ssp0_ops = { 436 .hw_params = kabylake_ssp0_hw_params, 437 }; 438 439 static unsigned int channels_dmic[] = { 440 2, 4, 441 }; 442 443 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = { 444 .count = ARRAY_SIZE(channels_dmic), 445 .list = channels_dmic, 446 .mask = 0, 447 }; 448 449 static const unsigned int dmic_2ch[] = { 450 2, 451 }; 452 453 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = { 454 .count = ARRAY_SIZE(dmic_2ch), 455 .list = dmic_2ch, 456 .mask = 0, 457 }; 458 459 static int kabylake_dmic_startup(struct snd_pcm_substream *substream) 460 { 461 struct snd_pcm_runtime *runtime = substream->runtime; 462 463 runtime->hw.channels_max = DMIC_CH(dmic_constraints); 464 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 465 dmic_constraints); 466 467 return snd_pcm_hw_constraint_list(substream->runtime, 0, 468 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); 469 } 470 471 static struct snd_soc_ops kabylake_dmic_ops = { 472 .startup = kabylake_dmic_startup, 473 }; 474 475 static unsigned int rates_16000[] = { 476 16000, 477 }; 478 479 static const struct snd_pcm_hw_constraint_list constraints_16000 = { 480 .count = ARRAY_SIZE(rates_16000), 481 .list = rates_16000, 482 }; 483 484 static const unsigned int ch_mono[] = { 485 1, 486 }; 487 488 static const struct snd_pcm_hw_constraint_list constraints_refcap = { 489 .count = ARRAY_SIZE(ch_mono), 490 .list = ch_mono, 491 }; 492 493 static int kabylake_refcap_startup(struct snd_pcm_substream *substream) 494 { 495 substream->runtime->hw.channels_max = 1; 496 snd_pcm_hw_constraint_list(substream->runtime, 0, 497 SNDRV_PCM_HW_PARAM_CHANNELS, 498 &constraints_refcap); 499 500 return snd_pcm_hw_constraint_list(substream->runtime, 0, 501 SNDRV_PCM_HW_PARAM_RATE, 502 &constraints_16000); 503 } 504 505 static struct snd_soc_ops skylaye_refcap_ops = { 506 .startup = kabylake_refcap_startup, 507 }; 508 509 /* kabylake digital audio interface glue - connects codec <--> CPU */ 510 static struct snd_soc_dai_link kabylake_dais[] = { 511 /* Front End DAI links */ 512 [KBL_DPCM_AUDIO_PB] = { 513 .name = "Kbl Audio Port", 514 .stream_name = "Audio", 515 .cpu_dai_name = "System Pin", 516 .platform_name = "0000:00:1f.3", 517 .dynamic = 1, 518 .codec_name = "snd-soc-dummy", 519 .codec_dai_name = "snd-soc-dummy-dai", 520 .nonatomic = 1, 521 .init = kabylake_rt5663_fe_init, 522 .trigger = { 523 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 524 .dpcm_playback = 1, 525 .ops = &kabylake_rt5663_fe_ops, 526 }, 527 [KBL_DPCM_AUDIO_CP] = { 528 .name = "Kbl Audio Capture Port", 529 .stream_name = "Audio Record", 530 .cpu_dai_name = "System Pin", 531 .platform_name = "0000:00:1f.3", 532 .dynamic = 1, 533 .codec_name = "snd-soc-dummy", 534 .codec_dai_name = "snd-soc-dummy-dai", 535 .nonatomic = 1, 536 .trigger = { 537 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 538 .dpcm_capture = 1, 539 .ops = &kabylake_rt5663_fe_ops, 540 }, 541 [KBL_DPCM_AUDIO_HS_PB] = { 542 .name = "Kbl Audio Headset Playback", 543 .stream_name = "Headset Audio", 544 .cpu_dai_name = "System Pin2", 545 .codec_name = "snd-soc-dummy", 546 .codec_dai_name = "snd-soc-dummy-dai", 547 .platform_name = "0000:00:1f.3", 548 .dpcm_playback = 1, 549 .nonatomic = 1, 550 .dynamic = 1, 551 }, 552 [KBL_DPCM_AUDIO_ECHO_REF_CP] = { 553 .name = "Kbl Audio Echo Reference cap", 554 .stream_name = "Echoreference Capture", 555 .cpu_dai_name = "Echoref Pin", 556 .codec_name = "snd-soc-dummy", 557 .codec_dai_name = "snd-soc-dummy-dai", 558 .platform_name = "0000:00:1f.3", 559 .init = NULL, 560 .capture_only = 1, 561 .nonatomic = 1, 562 }, 563 [KBL_DPCM_AUDIO_REF_CP] = { 564 .name = "Kbl Audio Reference cap", 565 .stream_name = "Wake on Voice", 566 .cpu_dai_name = "Reference Pin", 567 .codec_name = "snd-soc-dummy", 568 .codec_dai_name = "snd-soc-dummy-dai", 569 .platform_name = "0000:00:1f.3", 570 .init = NULL, 571 .dpcm_capture = 1, 572 .nonatomic = 1, 573 .dynamic = 1, 574 .ops = &skylaye_refcap_ops, 575 }, 576 [KBL_DPCM_AUDIO_DMIC_CP] = { 577 .name = "Kbl Audio DMIC cap", 578 .stream_name = "dmiccap", 579 .cpu_dai_name = "DMIC Pin", 580 .codec_name = "snd-soc-dummy", 581 .codec_dai_name = "snd-soc-dummy-dai", 582 .platform_name = "0000:00:1f.3", 583 .init = NULL, 584 .dpcm_capture = 1, 585 .nonatomic = 1, 586 .dynamic = 1, 587 .ops = &kabylake_dmic_ops, 588 }, 589 [KBL_DPCM_AUDIO_HDMI1_PB] = { 590 .name = "Kbl HDMI Port1", 591 .stream_name = "Hdmi1", 592 .cpu_dai_name = "HDMI1 Pin", 593 .codec_name = "snd-soc-dummy", 594 .codec_dai_name = "snd-soc-dummy-dai", 595 .platform_name = "0000:00:1f.3", 596 .dpcm_playback = 1, 597 .init = NULL, 598 .trigger = { 599 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 600 .nonatomic = 1, 601 .dynamic = 1, 602 }, 603 [KBL_DPCM_AUDIO_HDMI2_PB] = { 604 .name = "Kbl HDMI Port2", 605 .stream_name = "Hdmi2", 606 .cpu_dai_name = "HDMI2 Pin", 607 .codec_name = "snd-soc-dummy", 608 .codec_dai_name = "snd-soc-dummy-dai", 609 .platform_name = "0000:00:1f.3", 610 .dpcm_playback = 1, 611 .init = NULL, 612 .trigger = { 613 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 614 .nonatomic = 1, 615 .dynamic = 1, 616 }, 617 [KBL_DPCM_AUDIO_HDMI3_PB] = { 618 .name = "Kbl HDMI Port3", 619 .stream_name = "Hdmi3", 620 .cpu_dai_name = "HDMI3 Pin", 621 .codec_name = "snd-soc-dummy", 622 .codec_dai_name = "snd-soc-dummy-dai", 623 .platform_name = "0000:00:1f.3", 624 .trigger = { 625 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 626 .dpcm_playback = 1, 627 .init = NULL, 628 .nonatomic = 1, 629 .dynamic = 1, 630 }, 631 632 /* Back End DAI links */ 633 { 634 /* SSP0 - Codec */ 635 .name = "SSP0-Codec", 636 .id = 0, 637 .cpu_dai_name = "SSP0 Pin", 638 .platform_name = "0000:00:1f.3", 639 .no_pcm = 1, 640 .codecs = max98927_codec_components, 641 .num_codecs = ARRAY_SIZE(max98927_codec_components), 642 .dai_fmt = SND_SOC_DAIFMT_DSP_B | 643 SND_SOC_DAIFMT_NB_NF | 644 SND_SOC_DAIFMT_CBS_CFS, 645 .ignore_pmdown_time = 1, 646 .be_hw_params_fixup = kabylake_ssp_fixup, 647 .dpcm_playback = 1, 648 .ops = &kabylake_ssp0_ops, 649 }, 650 { 651 /* SSP1 - Codec */ 652 .name = "SSP1-Codec", 653 .id = 1, 654 .cpu_dai_name = "SSP1 Pin", 655 .platform_name = "0000:00:1f.3", 656 .no_pcm = 1, 657 .codec_name = "i2c-10EC5663:00", 658 .codec_dai_name = KBL_REALTEK_CODEC_DAI, 659 .init = kabylake_rt5663_max98927_codec_init, 660 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 661 SND_SOC_DAIFMT_CBS_CFS, 662 .ignore_pmdown_time = 1, 663 .be_hw_params_fixup = kabylake_ssp_fixup, 664 .ops = &kabylake_rt5663_ops, 665 .dpcm_playback = 1, 666 .dpcm_capture = 1, 667 }, 668 { 669 .name = "dmic01", 670 .id = 2, 671 .cpu_dai_name = "DMIC01 Pin", 672 .codec_name = "dmic-codec", 673 .codec_dai_name = "dmic-hifi", 674 .platform_name = "0000:00:1f.3", 675 .be_hw_params_fixup = kabylake_dmic_fixup, 676 .ignore_suspend = 1, 677 .dpcm_capture = 1, 678 .no_pcm = 1, 679 }, 680 { 681 .name = "iDisp1", 682 .id = 3, 683 .cpu_dai_name = "iDisp1 Pin", 684 .codec_name = "ehdaudio0D2", 685 .codec_dai_name = "intel-hdmi-hifi1", 686 .platform_name = "0000:00:1f.3", 687 .dpcm_playback = 1, 688 .init = kabylake_hdmi1_init, 689 .no_pcm = 1, 690 }, 691 { 692 .name = "iDisp2", 693 .id = 4, 694 .cpu_dai_name = "iDisp2 Pin", 695 .codec_name = "ehdaudio0D2", 696 .codec_dai_name = "intel-hdmi-hifi2", 697 .platform_name = "0000:00:1f.3", 698 .init = kabylake_hdmi2_init, 699 .dpcm_playback = 1, 700 .no_pcm = 1, 701 }, 702 { 703 .name = "iDisp3", 704 .id = 5, 705 .cpu_dai_name = "iDisp3 Pin", 706 .codec_name = "ehdaudio0D2", 707 .codec_dai_name = "intel-hdmi-hifi3", 708 .platform_name = "0000:00:1f.3", 709 .init = kabylake_hdmi3_init, 710 .dpcm_playback = 1, 711 .no_pcm = 1, 712 }, 713 }; 714 715 static struct snd_soc_dai_link kabylake_5663_dais[] = { 716 /* Front End DAI links */ 717 [KBL_DPCM_AUDIO_5663_PB] = { 718 .name = "Kbl Audio Port", 719 .stream_name = "Audio", 720 .cpu_dai_name = "System Pin", 721 .platform_name = "0000:00:1f.3", 722 .dynamic = 1, 723 .codec_name = "snd-soc-dummy", 724 .codec_dai_name = "snd-soc-dummy-dai", 725 .nonatomic = 1, 726 .trigger = { 727 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 728 .dpcm_playback = 1, 729 .ops = &kabylake_rt5663_fe_ops, 730 }, 731 [KBL_DPCM_AUDIO_5663_CP] = { 732 .name = "Kbl Audio Capture Port", 733 .stream_name = "Audio Record", 734 .cpu_dai_name = "System Pin", 735 .platform_name = "0000:00:1f.3", 736 .dynamic = 1, 737 .codec_name = "snd-soc-dummy", 738 .codec_dai_name = "snd-soc-dummy-dai", 739 .nonatomic = 1, 740 .trigger = { 741 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 742 .dpcm_capture = 1, 743 .ops = &kabylake_rt5663_fe_ops, 744 }, 745 [KBL_DPCM_AUDIO_5663_HDMI1_PB] = { 746 .name = "Kbl HDMI Port1", 747 .stream_name = "Hdmi1", 748 .cpu_dai_name = "HDMI1 Pin", 749 .codec_name = "snd-soc-dummy", 750 .codec_dai_name = "snd-soc-dummy-dai", 751 .platform_name = "0000:00:1f.3", 752 .dpcm_playback = 1, 753 .init = NULL, 754 .trigger = { 755 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 756 .nonatomic = 1, 757 .dynamic = 1, 758 }, 759 [KBL_DPCM_AUDIO_5663_HDMI2_PB] = { 760 .name = "Kbl HDMI Port2", 761 .stream_name = "Hdmi2", 762 .cpu_dai_name = "HDMI2 Pin", 763 .codec_name = "snd-soc-dummy", 764 .codec_dai_name = "snd-soc-dummy-dai", 765 .platform_name = "0000:00:1f.3", 766 .dpcm_playback = 1, 767 .init = NULL, 768 .trigger = { 769 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 770 .nonatomic = 1, 771 .dynamic = 1, 772 }, 773 774 /* Back End DAI links */ 775 { 776 /* SSP1 - Codec */ 777 .name = "SSP1-Codec", 778 .id = 0, 779 .cpu_dai_name = "SSP1 Pin", 780 .platform_name = "0000:00:1f.3", 781 .no_pcm = 1, 782 .codec_name = "i2c-10EC5663:00", 783 .codec_dai_name = KBL_REALTEK_CODEC_DAI, 784 .init = kabylake_rt5663_codec_init, 785 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 786 SND_SOC_DAIFMT_CBS_CFS, 787 .ignore_pmdown_time = 1, 788 .be_hw_params_fixup = kabylake_ssp_fixup, 789 .ops = &kabylake_rt5663_ops, 790 .dpcm_playback = 1, 791 .dpcm_capture = 1, 792 }, 793 { 794 .name = "iDisp1", 795 .id = 1, 796 .cpu_dai_name = "iDisp1 Pin", 797 .codec_name = "ehdaudio0D2", 798 .codec_dai_name = "intel-hdmi-hifi1", 799 .platform_name = "0000:00:1f.3", 800 .dpcm_playback = 1, 801 .init = kabylake_5663_hdmi1_init, 802 .no_pcm = 1, 803 }, 804 { 805 .name = "iDisp2", 806 .id = 2, 807 .cpu_dai_name = "iDisp2 Pin", 808 .codec_name = "ehdaudio0D2", 809 .codec_dai_name = "intel-hdmi-hifi2", 810 .platform_name = "0000:00:1f.3", 811 .init = kabylake_5663_hdmi2_init, 812 .dpcm_playback = 1, 813 .no_pcm = 1, 814 }, 815 }; 816 817 #define NAME_SIZE 32 818 static int kabylake_card_late_probe(struct snd_soc_card *card) 819 { 820 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(card); 821 struct kbl_hdmi_pcm *pcm; 822 struct snd_soc_codec *codec = NULL; 823 int err, i = 0; 824 char jack_name[NAME_SIZE]; 825 826 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) { 827 codec = pcm->codec_dai->codec; 828 snprintf(jack_name, sizeof(jack_name), 829 "HDMI/DP, pcm=%d Jack", pcm->device); 830 err = snd_soc_card_jack_new(card, jack_name, 831 SND_JACK_AVOUT, &skylake_hdmi[i], 832 NULL, 0); 833 834 if (err) 835 return err; 836 837 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device, 838 &skylake_hdmi[i]); 839 if (err < 0) 840 return err; 841 842 i++; 843 } 844 845 if (!codec) 846 return -EINVAL; 847 848 return hdac_hdmi_jack_port_init(codec, &card->dapm); 849 } 850 851 /* kabylake audio machine driver for SPT + RT5663 */ 852 static struct snd_soc_card kabylake_audio_card_rt5663_m98927 = { 853 .name = "kblrt5663max", 854 .owner = THIS_MODULE, 855 .dai_link = kabylake_dais, 856 .num_links = ARRAY_SIZE(kabylake_dais), 857 .controls = kabylake_controls, 858 .num_controls = ARRAY_SIZE(kabylake_controls), 859 .dapm_widgets = kabylake_widgets, 860 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets), 861 .dapm_routes = kabylake_map, 862 .num_dapm_routes = ARRAY_SIZE(kabylake_map), 863 .codec_conf = max98927_codec_conf, 864 .num_configs = ARRAY_SIZE(max98927_codec_conf), 865 .fully_routed = true, 866 .late_probe = kabylake_card_late_probe, 867 }; 868 869 /* kabylake audio machine driver for RT5663 */ 870 static struct snd_soc_card kabylake_audio_card_rt5663 = { 871 .name = "kblrt5663", 872 .owner = THIS_MODULE, 873 .dai_link = kabylake_5663_dais, 874 .num_links = ARRAY_SIZE(kabylake_5663_dais), 875 .controls = kabylake_5663_controls, 876 .num_controls = ARRAY_SIZE(kabylake_5663_controls), 877 .dapm_widgets = kabylake_5663_widgets, 878 .num_dapm_widgets = ARRAY_SIZE(kabylake_5663_widgets), 879 .dapm_routes = kabylake_5663_map, 880 .num_dapm_routes = ARRAY_SIZE(kabylake_5663_map), 881 .fully_routed = true, 882 .late_probe = kabylake_card_late_probe, 883 }; 884 885 static int kabylake_audio_probe(struct platform_device *pdev) 886 { 887 struct kbl_rt5663_private *ctx; 888 struct skl_machine_pdata *pdata; 889 890 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC); 891 if (!ctx) 892 return -ENOMEM; 893 894 INIT_LIST_HEAD(&ctx->hdmi_pcm_list); 895 896 kabylake_audio_card = 897 (struct snd_soc_card *)pdev->id_entry->driver_data; 898 899 kabylake_audio_card->dev = &pdev->dev; 900 snd_soc_card_set_drvdata(kabylake_audio_card, ctx); 901 902 pdata = dev_get_drvdata(&pdev->dev); 903 if (pdata) 904 dmic_constraints = pdata->dmic_num == 2 ? 905 &constraints_dmic_2ch : &constraints_dmic_channels; 906 907 return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card); 908 } 909 910 static const struct platform_device_id kbl_board_ids[] = { 911 { 912 .name = "kbl_rt5663", 913 .driver_data = (kernel_ulong_t)&kabylake_audio_card_rt5663, 914 }, 915 { 916 .name = "kbl_rt5663_m98927", 917 .driver_data = 918 (kernel_ulong_t)&kabylake_audio_card_rt5663_m98927, 919 }, 920 { } 921 }; 922 923 static struct platform_driver kabylake_audio = { 924 .probe = kabylake_audio_probe, 925 .driver = { 926 .name = "kbl_rt5663_m98927", 927 .pm = &snd_soc_pm_ops, 928 }, 929 .id_table = kbl_board_ids, 930 }; 931 932 module_platform_driver(kabylake_audio) 933 934 /* Module information */ 935 MODULE_DESCRIPTION("Audio Machine driver-RT5663 & MAX98927 in I2S mode"); 936 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>"); 937 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>"); 938 MODULE_LICENSE("GPL v2"); 939 MODULE_ALIAS("platform:kbl_rt5663"); 940 MODULE_ALIAS("platform:kbl_rt5663_m98927"); 941