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