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