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 struct snd_soc_dpcm *dpcm = container_of( 354 params, struct snd_soc_dpcm, hw_params); 355 struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link; 356 struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link; 357 358 /* 359 * The ADSP will convert the FE rate to 48k, stereo, 24 bit 360 */ 361 if (!strcmp(fe_dai_link->name, "Kbl Audio Port") || 362 !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") || 363 !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) { 364 rate->min = rate->max = 48000; 365 channels->min = channels->max = 2; 366 snd_mask_none(fmt); 367 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE); 368 } 369 /* 370 * The speaker on the SSP0 supports S16_LE and not S24_LE. 371 * thus changing the mask here 372 */ 373 if (!strcmp(be_dai_link->name, "SSP0-Codec")) 374 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S16_LE); 375 376 return 0; 377 } 378 379 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream, 380 struct snd_pcm_hw_params *params) 381 { 382 struct snd_soc_pcm_runtime *rtd = substream->private_data; 383 struct snd_soc_dai *codec_dai = rtd->codec_dai; 384 int ret; 385 386 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */ 387 rt5663_sel_asrc_clk_src(codec_dai->codec, 388 RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER, 389 RT5663_CLK_SEL_I2S1_ASRC); 390 391 ret = snd_soc_dai_set_sysclk(codec_dai, 392 RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN); 393 if (ret < 0) 394 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret); 395 396 return ret; 397 } 398 399 static struct snd_soc_ops kabylake_rt5663_ops = { 400 .hw_params = kabylake_rt5663_hw_params, 401 }; 402 403 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd, 404 struct snd_pcm_hw_params *params) 405 { 406 struct snd_interval *channels = hw_param_interval(params, 407 SNDRV_PCM_HW_PARAM_CHANNELS); 408 409 if (params_channels(params) == 2 || DMIC_CH(dmic_constraints) == 2) 410 channels->min = channels->max = 2; 411 else 412 channels->min = channels->max = 4; 413 414 return 0; 415 } 416 417 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream, 418 struct snd_pcm_hw_params *params) 419 { 420 struct snd_soc_pcm_runtime *rtd = substream->private_data; 421 int ret = 0, j; 422 423 for (j = 0; j < rtd->num_codecs; j++) { 424 struct snd_soc_dai *codec_dai = rtd->codec_dais[j]; 425 426 if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) { 427 /* 428 * Use channel 4 and 5 for the first amp 429 */ 430 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16); 431 if (ret < 0) { 432 dev_err(rtd->dev, "set TDM slot err:%d\n", ret); 433 return ret; 434 } 435 } 436 if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) { 437 /* 438 * Use channel 6 and 7 for the second amp 439 */ 440 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16); 441 if (ret < 0) { 442 dev_err(rtd->dev, "set TDM slot err:%d\n", ret); 443 return ret; 444 } 445 } 446 } 447 return ret; 448 } 449 450 static struct snd_soc_ops kabylake_ssp0_ops = { 451 .hw_params = kabylake_ssp0_hw_params, 452 }; 453 454 static unsigned int channels_dmic[] = { 455 2, 4, 456 }; 457 458 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = { 459 .count = ARRAY_SIZE(channels_dmic), 460 .list = channels_dmic, 461 .mask = 0, 462 }; 463 464 static const unsigned int dmic_2ch[] = { 465 2, 466 }; 467 468 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = { 469 .count = ARRAY_SIZE(dmic_2ch), 470 .list = dmic_2ch, 471 .mask = 0, 472 }; 473 474 static int kabylake_dmic_startup(struct snd_pcm_substream *substream) 475 { 476 struct snd_pcm_runtime *runtime = substream->runtime; 477 478 runtime->hw.channels_max = DMIC_CH(dmic_constraints); 479 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 480 dmic_constraints); 481 482 return snd_pcm_hw_constraint_list(substream->runtime, 0, 483 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); 484 } 485 486 static struct snd_soc_ops kabylake_dmic_ops = { 487 .startup = kabylake_dmic_startup, 488 }; 489 490 static unsigned int rates_16000[] = { 491 16000, 492 }; 493 494 static const struct snd_pcm_hw_constraint_list constraints_16000 = { 495 .count = ARRAY_SIZE(rates_16000), 496 .list = rates_16000, 497 }; 498 499 static const unsigned int ch_mono[] = { 500 1, 501 }; 502 503 static const struct snd_pcm_hw_constraint_list constraints_refcap = { 504 .count = ARRAY_SIZE(ch_mono), 505 .list = ch_mono, 506 }; 507 508 static int kabylake_refcap_startup(struct snd_pcm_substream *substream) 509 { 510 substream->runtime->hw.channels_max = 1; 511 snd_pcm_hw_constraint_list(substream->runtime, 0, 512 SNDRV_PCM_HW_PARAM_CHANNELS, 513 &constraints_refcap); 514 515 return snd_pcm_hw_constraint_list(substream->runtime, 0, 516 SNDRV_PCM_HW_PARAM_RATE, 517 &constraints_16000); 518 } 519 520 static struct snd_soc_ops skylaye_refcap_ops = { 521 .startup = kabylake_refcap_startup, 522 }; 523 524 /* kabylake digital audio interface glue - connects codec <--> CPU */ 525 static struct snd_soc_dai_link kabylake_dais[] = { 526 /* Front End DAI links */ 527 [KBL_DPCM_AUDIO_PB] = { 528 .name = "Kbl Audio Port", 529 .stream_name = "Audio", 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 .init = kabylake_rt5663_fe_init, 537 .trigger = { 538 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 539 .dpcm_playback = 1, 540 .ops = &kabylake_rt5663_fe_ops, 541 }, 542 [KBL_DPCM_AUDIO_CP] = { 543 .name = "Kbl Audio Capture Port", 544 .stream_name = "Audio Record", 545 .cpu_dai_name = "System Pin", 546 .platform_name = "0000:00:1f.3", 547 .dynamic = 1, 548 .codec_name = "snd-soc-dummy", 549 .codec_dai_name = "snd-soc-dummy-dai", 550 .nonatomic = 1, 551 .trigger = { 552 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 553 .dpcm_capture = 1, 554 .ops = &kabylake_rt5663_fe_ops, 555 }, 556 [KBL_DPCM_AUDIO_HS_PB] = { 557 .name = "Kbl Audio Headset Playback", 558 .stream_name = "Headset Audio", 559 .cpu_dai_name = "System Pin2", 560 .codec_name = "snd-soc-dummy", 561 .codec_dai_name = "snd-soc-dummy-dai", 562 .platform_name = "0000:00:1f.3", 563 .dpcm_playback = 1, 564 .nonatomic = 1, 565 .dynamic = 1, 566 }, 567 [KBL_DPCM_AUDIO_ECHO_REF_CP] = { 568 .name = "Kbl Audio Echo Reference cap", 569 .stream_name = "Echoreference Capture", 570 .cpu_dai_name = "Echoref Pin", 571 .codec_name = "snd-soc-dummy", 572 .codec_dai_name = "snd-soc-dummy-dai", 573 .platform_name = "0000:00:1f.3", 574 .init = NULL, 575 .capture_only = 1, 576 .nonatomic = 1, 577 }, 578 [KBL_DPCM_AUDIO_REF_CP] = { 579 .name = "Kbl Audio Reference cap", 580 .stream_name = "Wake on Voice", 581 .cpu_dai_name = "Reference Pin", 582 .codec_name = "snd-soc-dummy", 583 .codec_dai_name = "snd-soc-dummy-dai", 584 .platform_name = "0000:00:1f.3", 585 .init = NULL, 586 .dpcm_capture = 1, 587 .nonatomic = 1, 588 .dynamic = 1, 589 .ops = &skylaye_refcap_ops, 590 }, 591 [KBL_DPCM_AUDIO_DMIC_CP] = { 592 .name = "Kbl Audio DMIC cap", 593 .stream_name = "dmiccap", 594 .cpu_dai_name = "DMIC Pin", 595 .codec_name = "snd-soc-dummy", 596 .codec_dai_name = "snd-soc-dummy-dai", 597 .platform_name = "0000:00:1f.3", 598 .init = NULL, 599 .dpcm_capture = 1, 600 .nonatomic = 1, 601 .dynamic = 1, 602 .ops = &kabylake_dmic_ops, 603 }, 604 [KBL_DPCM_AUDIO_HDMI1_PB] = { 605 .name = "Kbl HDMI Port1", 606 .stream_name = "Hdmi1", 607 .cpu_dai_name = "HDMI1 Pin", 608 .codec_name = "snd-soc-dummy", 609 .codec_dai_name = "snd-soc-dummy-dai", 610 .platform_name = "0000:00:1f.3", 611 .dpcm_playback = 1, 612 .init = NULL, 613 .trigger = { 614 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 615 .nonatomic = 1, 616 .dynamic = 1, 617 }, 618 [KBL_DPCM_AUDIO_HDMI2_PB] = { 619 .name = "Kbl HDMI Port2", 620 .stream_name = "Hdmi2", 621 .cpu_dai_name = "HDMI2 Pin", 622 .codec_name = "snd-soc-dummy", 623 .codec_dai_name = "snd-soc-dummy-dai", 624 .platform_name = "0000:00:1f.3", 625 .dpcm_playback = 1, 626 .init = NULL, 627 .trigger = { 628 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 629 .nonatomic = 1, 630 .dynamic = 1, 631 }, 632 [KBL_DPCM_AUDIO_HDMI3_PB] = { 633 .name = "Kbl HDMI Port3", 634 .stream_name = "Hdmi3", 635 .cpu_dai_name = "HDMI3 Pin", 636 .codec_name = "snd-soc-dummy", 637 .codec_dai_name = "snd-soc-dummy-dai", 638 .platform_name = "0000:00:1f.3", 639 .trigger = { 640 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 641 .dpcm_playback = 1, 642 .init = NULL, 643 .nonatomic = 1, 644 .dynamic = 1, 645 }, 646 647 /* Back End DAI links */ 648 { 649 /* SSP0 - Codec */ 650 .name = "SSP0-Codec", 651 .id = 0, 652 .cpu_dai_name = "SSP0 Pin", 653 .platform_name = "0000:00:1f.3", 654 .no_pcm = 1, 655 .codecs = max98927_codec_components, 656 .num_codecs = ARRAY_SIZE(max98927_codec_components), 657 .dai_fmt = SND_SOC_DAIFMT_DSP_B | 658 SND_SOC_DAIFMT_NB_NF | 659 SND_SOC_DAIFMT_CBS_CFS, 660 .ignore_pmdown_time = 1, 661 .be_hw_params_fixup = kabylake_ssp_fixup, 662 .dpcm_playback = 1, 663 .ops = &kabylake_ssp0_ops, 664 }, 665 { 666 /* SSP1 - Codec */ 667 .name = "SSP1-Codec", 668 .id = 1, 669 .cpu_dai_name = "SSP1 Pin", 670 .platform_name = "0000:00:1f.3", 671 .no_pcm = 1, 672 .codec_name = "i2c-10EC5663:00", 673 .codec_dai_name = KBL_REALTEK_CODEC_DAI, 674 .init = kabylake_rt5663_max98927_codec_init, 675 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 676 SND_SOC_DAIFMT_CBS_CFS, 677 .ignore_pmdown_time = 1, 678 .be_hw_params_fixup = kabylake_ssp_fixup, 679 .ops = &kabylake_rt5663_ops, 680 .dpcm_playback = 1, 681 .dpcm_capture = 1, 682 }, 683 { 684 .name = "dmic01", 685 .id = 2, 686 .cpu_dai_name = "DMIC01 Pin", 687 .codec_name = "dmic-codec", 688 .codec_dai_name = "dmic-hifi", 689 .platform_name = "0000:00:1f.3", 690 .be_hw_params_fixup = kabylake_dmic_fixup, 691 .ignore_suspend = 1, 692 .dpcm_capture = 1, 693 .no_pcm = 1, 694 }, 695 { 696 .name = "iDisp1", 697 .id = 3, 698 .cpu_dai_name = "iDisp1 Pin", 699 .codec_name = "ehdaudio0D2", 700 .codec_dai_name = "intel-hdmi-hifi1", 701 .platform_name = "0000:00:1f.3", 702 .dpcm_playback = 1, 703 .init = kabylake_hdmi1_init, 704 .no_pcm = 1, 705 }, 706 { 707 .name = "iDisp2", 708 .id = 4, 709 .cpu_dai_name = "iDisp2 Pin", 710 .codec_name = "ehdaudio0D2", 711 .codec_dai_name = "intel-hdmi-hifi2", 712 .platform_name = "0000:00:1f.3", 713 .init = kabylake_hdmi2_init, 714 .dpcm_playback = 1, 715 .no_pcm = 1, 716 }, 717 { 718 .name = "iDisp3", 719 .id = 5, 720 .cpu_dai_name = "iDisp3 Pin", 721 .codec_name = "ehdaudio0D2", 722 .codec_dai_name = "intel-hdmi-hifi3", 723 .platform_name = "0000:00:1f.3", 724 .init = kabylake_hdmi3_init, 725 .dpcm_playback = 1, 726 .no_pcm = 1, 727 }, 728 }; 729 730 static struct snd_soc_dai_link kabylake_5663_dais[] = { 731 /* Front End DAI links */ 732 [KBL_DPCM_AUDIO_5663_PB] = { 733 .name = "Kbl Audio Port", 734 .stream_name = "Audio", 735 .cpu_dai_name = "System Pin", 736 .platform_name = "0000:00:1f.3", 737 .dynamic = 1, 738 .codec_name = "snd-soc-dummy", 739 .codec_dai_name = "snd-soc-dummy-dai", 740 .nonatomic = 1, 741 .trigger = { 742 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 743 .dpcm_playback = 1, 744 .ops = &kabylake_rt5663_fe_ops, 745 }, 746 [KBL_DPCM_AUDIO_5663_CP] = { 747 .name = "Kbl Audio Capture Port", 748 .stream_name = "Audio Record", 749 .cpu_dai_name = "System Pin", 750 .platform_name = "0000:00:1f.3", 751 .dynamic = 1, 752 .codec_name = "snd-soc-dummy", 753 .codec_dai_name = "snd-soc-dummy-dai", 754 .nonatomic = 1, 755 .trigger = { 756 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 757 .dpcm_capture = 1, 758 .ops = &kabylake_rt5663_fe_ops, 759 }, 760 [KBL_DPCM_AUDIO_5663_HDMI1_PB] = { 761 .name = "Kbl HDMI Port1", 762 .stream_name = "Hdmi1", 763 .cpu_dai_name = "HDMI1 Pin", 764 .codec_name = "snd-soc-dummy", 765 .codec_dai_name = "snd-soc-dummy-dai", 766 .platform_name = "0000:00:1f.3", 767 .dpcm_playback = 1, 768 .init = NULL, 769 .trigger = { 770 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 771 .nonatomic = 1, 772 .dynamic = 1, 773 }, 774 [KBL_DPCM_AUDIO_5663_HDMI2_PB] = { 775 .name = "Kbl HDMI Port2", 776 .stream_name = "Hdmi2", 777 .cpu_dai_name = "HDMI2 Pin", 778 .codec_name = "snd-soc-dummy", 779 .codec_dai_name = "snd-soc-dummy-dai", 780 .platform_name = "0000:00:1f.3", 781 .dpcm_playback = 1, 782 .init = NULL, 783 .trigger = { 784 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 785 .nonatomic = 1, 786 .dynamic = 1, 787 }, 788 789 /* Back End DAI links */ 790 { 791 /* SSP1 - Codec */ 792 .name = "SSP1-Codec", 793 .id = 0, 794 .cpu_dai_name = "SSP1 Pin", 795 .platform_name = "0000:00:1f.3", 796 .no_pcm = 1, 797 .codec_name = "i2c-10EC5663:00", 798 .codec_dai_name = KBL_REALTEK_CODEC_DAI, 799 .init = kabylake_rt5663_codec_init, 800 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 801 SND_SOC_DAIFMT_CBS_CFS, 802 .ignore_pmdown_time = 1, 803 .be_hw_params_fixup = kabylake_ssp_fixup, 804 .ops = &kabylake_rt5663_ops, 805 .dpcm_playback = 1, 806 .dpcm_capture = 1, 807 }, 808 { 809 .name = "iDisp1", 810 .id = 1, 811 .cpu_dai_name = "iDisp1 Pin", 812 .codec_name = "ehdaudio0D2", 813 .codec_dai_name = "intel-hdmi-hifi1", 814 .platform_name = "0000:00:1f.3", 815 .dpcm_playback = 1, 816 .init = kabylake_5663_hdmi1_init, 817 .no_pcm = 1, 818 }, 819 { 820 .name = "iDisp2", 821 .id = 2, 822 .cpu_dai_name = "iDisp2 Pin", 823 .codec_name = "ehdaudio0D2", 824 .codec_dai_name = "intel-hdmi-hifi2", 825 .platform_name = "0000:00:1f.3", 826 .init = kabylake_5663_hdmi2_init, 827 .dpcm_playback = 1, 828 .no_pcm = 1, 829 }, 830 }; 831 832 #define NAME_SIZE 32 833 static int kabylake_card_late_probe(struct snd_soc_card *card) 834 { 835 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(card); 836 struct kbl_hdmi_pcm *pcm; 837 struct snd_soc_codec *codec = NULL; 838 int err, i = 0; 839 char jack_name[NAME_SIZE]; 840 841 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) { 842 codec = pcm->codec_dai->codec; 843 snprintf(jack_name, sizeof(jack_name), 844 "HDMI/DP, pcm=%d Jack", pcm->device); 845 err = snd_soc_card_jack_new(card, jack_name, 846 SND_JACK_AVOUT, &skylake_hdmi[i], 847 NULL, 0); 848 849 if (err) 850 return err; 851 852 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device, 853 &skylake_hdmi[i]); 854 if (err < 0) 855 return err; 856 857 i++; 858 } 859 860 if (!codec) 861 return -EINVAL; 862 863 return hdac_hdmi_jack_port_init(codec, &card->dapm); 864 } 865 866 /* kabylake audio machine driver for SPT + RT5663 */ 867 static struct snd_soc_card kabylake_audio_card_rt5663_m98927 = { 868 .name = "kblrt5663max", 869 .owner = THIS_MODULE, 870 .dai_link = kabylake_dais, 871 .num_links = ARRAY_SIZE(kabylake_dais), 872 .controls = kabylake_controls, 873 .num_controls = ARRAY_SIZE(kabylake_controls), 874 .dapm_widgets = kabylake_widgets, 875 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets), 876 .dapm_routes = kabylake_map, 877 .num_dapm_routes = ARRAY_SIZE(kabylake_map), 878 .codec_conf = max98927_codec_conf, 879 .num_configs = ARRAY_SIZE(max98927_codec_conf), 880 .fully_routed = true, 881 .late_probe = kabylake_card_late_probe, 882 }; 883 884 /* kabylake audio machine driver for RT5663 */ 885 static struct snd_soc_card kabylake_audio_card_rt5663 = { 886 .name = "kblrt5663", 887 .owner = THIS_MODULE, 888 .dai_link = kabylake_5663_dais, 889 .num_links = ARRAY_SIZE(kabylake_5663_dais), 890 .controls = kabylake_5663_controls, 891 .num_controls = ARRAY_SIZE(kabylake_5663_controls), 892 .dapm_widgets = kabylake_5663_widgets, 893 .num_dapm_widgets = ARRAY_SIZE(kabylake_5663_widgets), 894 .dapm_routes = kabylake_5663_map, 895 .num_dapm_routes = ARRAY_SIZE(kabylake_5663_map), 896 .fully_routed = true, 897 .late_probe = kabylake_card_late_probe, 898 }; 899 900 static int kabylake_audio_probe(struct platform_device *pdev) 901 { 902 struct kbl_rt5663_private *ctx; 903 struct skl_machine_pdata *pdata; 904 905 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC); 906 if (!ctx) 907 return -ENOMEM; 908 909 INIT_LIST_HEAD(&ctx->hdmi_pcm_list); 910 911 kabylake_audio_card = 912 (struct snd_soc_card *)pdev->id_entry->driver_data; 913 914 kabylake_audio_card->dev = &pdev->dev; 915 snd_soc_card_set_drvdata(kabylake_audio_card, ctx); 916 917 pdata = dev_get_drvdata(&pdev->dev); 918 if (pdata) 919 dmic_constraints = pdata->dmic_num == 2 ? 920 &constraints_dmic_2ch : &constraints_dmic_channels; 921 922 return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card); 923 } 924 925 static const struct platform_device_id kbl_board_ids[] = { 926 { 927 .name = "kbl_rt5663", 928 .driver_data = (kernel_ulong_t)&kabylake_audio_card_rt5663, 929 }, 930 { 931 .name = "kbl_rt5663_m98927", 932 .driver_data = 933 (kernel_ulong_t)&kabylake_audio_card_rt5663_m98927, 934 }, 935 { } 936 }; 937 938 static struct platform_driver kabylake_audio = { 939 .probe = kabylake_audio_probe, 940 .driver = { 941 .name = "kbl_rt5663_m98927", 942 .pm = &snd_soc_pm_ops, 943 }, 944 .id_table = kbl_board_ids, 945 }; 946 947 module_platform_driver(kabylake_audio) 948 949 /* Module information */ 950 MODULE_DESCRIPTION("Audio Machine driver-RT5663 & MAX98927 in I2S mode"); 951 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>"); 952 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>"); 953 MODULE_LICENSE("GPL v2"); 954 MODULE_ALIAS("platform:kbl_rt5663"); 955 MODULE_ALIAS("platform:kbl_rt5663_m98927"); 956