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