1 // SPDX-License-Identifier: GPL-2.0 2 // Copyright(c) 2018 Intel Corporation. 3 4 /* 5 * Intel Kabylake I2S Machine Driver with MAX98927, MAX98373 & DA7219 Codecs 6 * 7 * Modified from: 8 * Intel Kabylake I2S Machine driver supporting MAX98927 and 9 * RT5663 codecs 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 "../../codecs/da7219.h" 21 #include "../../codecs/hdac_hdmi.h" 22 #include "../skylake/skl.h" 23 #include "../../codecs/da7219-aad.h" 24 25 #define KBL_DIALOG_CODEC_DAI "da7219-hifi" 26 #define MAX98927_CODEC_DAI "max98927-aif1" 27 #define MAX98927_DEV0_NAME "i2c-MX98927:00" 28 #define MAX98927_DEV1_NAME "i2c-MX98927:01" 29 30 #define MAX98373_CODEC_DAI "max98373-aif1" 31 #define MAX98373_DEV0_NAME "i2c-MX98373:00" 32 #define MAX98373_DEV1_NAME "i2c-MX98373:01" 33 34 35 #define DUAL_CHANNEL 2 36 #define QUAD_CHANNEL 4 37 #define NAME_SIZE 32 38 39 static struct snd_soc_card *kabylake_audio_card; 40 static struct snd_soc_jack kabylake_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_codec_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_ECHO_REF_CP, 56 KBL_DPCM_AUDIO_REF_CP, 57 KBL_DPCM_AUDIO_DMIC_CP, 58 KBL_DPCM_AUDIO_HDMI1_PB, 59 KBL_DPCM_AUDIO_HDMI2_PB, 60 KBL_DPCM_AUDIO_HDMI3_PB, 61 KBL_DPCM_AUDIO_HS_PB, 62 KBL_DPCM_AUDIO_CP, 63 }; 64 65 static int platform_clock_control(struct snd_soc_dapm_widget *w, 66 struct snd_kcontrol *k, int event) 67 { 68 struct snd_soc_dapm_context *dapm = w->dapm; 69 struct snd_soc_card *card = dapm->card; 70 struct snd_soc_dai *codec_dai; 71 int ret = 0; 72 73 codec_dai = snd_soc_card_get_codec_dai(card, KBL_DIALOG_CODEC_DAI); 74 if (!codec_dai) { 75 dev_err(card->dev, "Codec dai not found; Unable to set/unset codec pll\n"); 76 return -EIO; 77 } 78 79 /* Configure sysclk for codec */ 80 ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, 24576000, 81 SND_SOC_CLOCK_IN); 82 if (ret) { 83 dev_err(card->dev, "can't set codec sysclk configuration\n"); 84 return ret; 85 } 86 87 if (SND_SOC_DAPM_EVENT_OFF(event)) { 88 ret = snd_soc_dai_set_pll(codec_dai, 0, 89 DA7219_SYSCLK_MCLK, 0, 0); 90 if (ret) 91 dev_err(card->dev, "failed to stop PLL: %d\n", ret); 92 } else if (SND_SOC_DAPM_EVENT_ON(event)) { 93 ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL_SRM, 94 0, DA7219_PLL_FREQ_OUT_98304); 95 if (ret) 96 dev_err(card->dev, "failed to start PLL: %d\n", ret); 97 } 98 99 return ret; 100 } 101 102 static const struct snd_kcontrol_new kabylake_controls[] = { 103 SOC_DAPM_PIN_SWITCH("Headphone Jack"), 104 SOC_DAPM_PIN_SWITCH("Headset Mic"), 105 SOC_DAPM_PIN_SWITCH("Left Spk"), 106 SOC_DAPM_PIN_SWITCH("Right Spk"), 107 }; 108 109 static const struct snd_soc_dapm_widget kabylake_widgets[] = { 110 SND_SOC_DAPM_HP("Headphone Jack", NULL), 111 SND_SOC_DAPM_MIC("Headset Mic", NULL), 112 SND_SOC_DAPM_SPK("Left Spk", NULL), 113 SND_SOC_DAPM_SPK("Right Spk", NULL), 114 SND_SOC_DAPM_MIC("SoC DMIC", NULL), 115 SND_SOC_DAPM_SPK("DP", NULL), 116 SND_SOC_DAPM_SPK("HDMI", NULL), 117 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, 118 platform_clock_control, SND_SOC_DAPM_PRE_PMU | 119 SND_SOC_DAPM_POST_PMD), 120 }; 121 122 static const struct snd_soc_dapm_route kabylake_map[] = { 123 /* speaker */ 124 { "Left Spk", NULL, "Left BE_OUT" }, 125 { "Right Spk", NULL, "Right BE_OUT" }, 126 127 /* other jacks */ 128 { "DMic", NULL, "SoC DMIC" }, 129 130 { "HDMI", NULL, "hif5 Output" }, 131 { "DP", NULL, "hif6 Output" }, 132 133 /* CODEC BE connections */ 134 { "Left HiFi Playback", NULL, "ssp0 Tx" }, 135 { "Right HiFi Playback", NULL, "ssp0 Tx" }, 136 { "ssp0 Tx", NULL, "spk_out" }, 137 138 /* IV feedback path */ 139 { "codec0_fb_in", NULL, "ssp0 Rx"}, 140 { "ssp0 Rx", NULL, "Left HiFi Capture" }, 141 { "ssp0 Rx", NULL, "Right HiFi Capture" }, 142 143 /* AEC capture path */ 144 { "echo_ref_out", NULL, "ssp0 Rx" }, 145 146 /* DMIC */ 147 { "dmic01_hifi", NULL, "DMIC01 Rx" }, 148 { "DMIC01 Rx", NULL, "DMIC AIF" }, 149 150 { "hifi1", NULL, "iDisp1 Tx" }, 151 { "iDisp1 Tx", NULL, "iDisp1_out" }, 152 { "hifi2", NULL, "iDisp2 Tx" }, 153 { "iDisp2 Tx", NULL, "iDisp2_out" }, 154 { "hifi3", NULL, "iDisp3 Tx"}, 155 { "iDisp3 Tx", NULL, "iDisp3_out"}, 156 }; 157 158 static const struct snd_soc_dapm_route kabylake_ssp1_map[] = { 159 { "Headphone Jack", NULL, "HPL" }, 160 { "Headphone Jack", NULL, "HPR" }, 161 162 /* other jacks */ 163 { "MIC", NULL, "Headset Mic" }, 164 165 /* CODEC BE connections */ 166 { "Playback", NULL, "ssp1 Tx" }, 167 { "ssp1 Tx", NULL, "codec1_out" }, 168 169 { "hs_in", NULL, "ssp1 Rx" }, 170 { "ssp1 Rx", NULL, "Capture" }, 171 172 { "Headphone Jack", NULL, "Platform Clock" }, 173 { "Headset Mic", NULL, "Platform Clock" }, 174 }; 175 176 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream, 177 struct snd_pcm_hw_params *params) 178 { 179 struct snd_soc_pcm_runtime *runtime = substream->private_data; 180 int ret = 0, j; 181 182 for (j = 0; j < runtime->num_codecs; j++) { 183 struct snd_soc_dai *codec_dai = runtime->codec_dais[j]; 184 185 if (!strcmp(codec_dai->component->name, MAX98927_DEV0_NAME)) { 186 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16); 187 if (ret < 0) { 188 dev_err(runtime->dev, "DEV0 TDM slot err:%d\n", ret); 189 return ret; 190 } 191 } 192 if (!strcmp(codec_dai->component->name, MAX98927_DEV1_NAME)) { 193 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16); 194 if (ret < 0) { 195 dev_err(runtime->dev, "DEV1 TDM slot err:%d\n", ret); 196 return ret; 197 } 198 } 199 if (!strcmp(codec_dai->component->name, MAX98373_DEV0_NAME)) { 200 ret = snd_soc_dai_set_tdm_slot(codec_dai, 201 0x03, 3, 8, 24); 202 if (ret < 0) { 203 dev_err(runtime->dev, 204 "DEV0 TDM slot err:%d\n", ret); 205 return ret; 206 } 207 } 208 if (!strcmp(codec_dai->component->name, MAX98373_DEV1_NAME)) { 209 ret = snd_soc_dai_set_tdm_slot(codec_dai, 210 0x0C, 3, 8, 24); 211 if (ret < 0) { 212 dev_err(runtime->dev, 213 "DEV0 TDM slot err:%d\n", ret); 214 return ret; 215 } 216 } 217 } 218 219 return 0; 220 } 221 222 static struct snd_soc_ops kabylake_ssp0_ops = { 223 .hw_params = kabylake_ssp0_hw_params, 224 }; 225 226 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd, 227 struct snd_pcm_hw_params *params) 228 { 229 struct snd_interval *rate = hw_param_interval(params, 230 SNDRV_PCM_HW_PARAM_RATE); 231 struct snd_interval *channels = hw_param_interval(params, 232 SNDRV_PCM_HW_PARAM_CHANNELS); 233 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 234 struct snd_soc_dpcm *dpcm = container_of( 235 params, struct snd_soc_dpcm, hw_params); 236 struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link; 237 struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link; 238 239 /* 240 * Topology for kblda7219m98373 & kblmax98373 supports only S24_LE, 241 * where as kblda7219m98927 & kblmax98927 supports S16_LE by default. 242 * Skipping the port wise FE and BE configuration for kblda7219m98373 & 243 * kblmax98373 as the topology (FE & BE) supports S24_LE only. 244 */ 245 246 if (!strcmp(rtd->card->name, "kblda7219m98373") || 247 !strcmp(rtd->card->name, "kblmax98373")) { 248 /* The ADSP will convert the FE rate to 48k, stereo */ 249 rate->min = rate->max = 48000; 250 channels->min = channels->max = DUAL_CHANNEL; 251 252 /* set SSP to 24 bit */ 253 snd_mask_none(fmt); 254 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE); 255 return 0; 256 } 257 258 /* 259 * The ADSP will convert the FE rate to 48k, stereo, 24 bit 260 */ 261 if (!strcmp(fe_dai_link->name, "Kbl Audio Port") || 262 !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") || 263 !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) { 264 rate->min = rate->max = 48000; 265 channels->min = channels->max = 2; 266 snd_mask_none(fmt); 267 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE); 268 } 269 270 /* 271 * The speaker on the SSP0 supports S16_LE and not S24_LE. 272 * thus changing the mask here 273 */ 274 if (!strcmp(be_dai_link->name, "SSP0-Codec")) 275 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE); 276 277 return 0; 278 } 279 280 static int kabylake_da7219_codec_init(struct snd_soc_pcm_runtime *rtd) 281 { 282 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card); 283 struct snd_soc_component *component = rtd->codec_dai->component; 284 struct snd_soc_jack *jack; 285 struct snd_soc_card *card = rtd->card; 286 int ret; 287 288 289 ret = snd_soc_dapm_add_routes(&card->dapm, 290 kabylake_ssp1_map, 291 ARRAY_SIZE(kabylake_ssp1_map)); 292 293 /* 294 * Headset buttons map to the google Reference headset. 295 * These can be configured by userspace. 296 */ 297 ret = snd_soc_card_jack_new(kabylake_audio_card, "Headset Jack", 298 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 | 299 SND_JACK_BTN_2 | SND_JACK_BTN_3 | SND_JACK_LINEOUT, 300 &ctx->kabylake_headset, NULL, 0); 301 if (ret) { 302 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); 303 return ret; 304 } 305 306 jack = &ctx->kabylake_headset; 307 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); 308 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP); 309 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); 310 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); 311 312 da7219_aad_jack_det(component, &ctx->kabylake_headset); 313 314 return 0; 315 } 316 317 static int kabylake_dmic_init(struct snd_soc_pcm_runtime *rtd) 318 { 319 int ret; 320 ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC"); 321 if (ret) 322 dev_err(rtd->dev, "SoC DMIC - Ignore suspend failed %d\n", ret); 323 324 return ret; 325 } 326 327 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device) 328 { 329 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card); 330 struct snd_soc_dai *dai = rtd->codec_dai; 331 struct kbl_hdmi_pcm *pcm; 332 333 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL); 334 if (!pcm) 335 return -ENOMEM; 336 337 pcm->device = device; 338 pcm->codec_dai = dai; 339 340 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list); 341 342 return 0; 343 } 344 345 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd) 346 { 347 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB); 348 } 349 350 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd) 351 { 352 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB); 353 } 354 355 static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd) 356 { 357 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB); 358 } 359 360 static int kabylake_da7219_fe_init(struct snd_soc_pcm_runtime *rtd) 361 { 362 struct snd_soc_dapm_context *dapm; 363 struct snd_soc_component *component = rtd->cpu_dai->component; 364 365 dapm = snd_soc_component_get_dapm(component); 366 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture"); 367 368 return 0; 369 } 370 371 static const unsigned int rates[] = { 372 48000, 373 }; 374 375 static const struct snd_pcm_hw_constraint_list constraints_rates = { 376 .count = ARRAY_SIZE(rates), 377 .list = rates, 378 .mask = 0, 379 }; 380 381 static const unsigned int channels[] = { 382 DUAL_CHANNEL, 383 }; 384 385 static const struct snd_pcm_hw_constraint_list constraints_channels = { 386 .count = ARRAY_SIZE(channels), 387 .list = channels, 388 .mask = 0, 389 }; 390 391 static unsigned int channels_quad[] = { 392 QUAD_CHANNEL, 393 }; 394 395 static struct snd_pcm_hw_constraint_list constraints_channels_quad = { 396 .count = ARRAY_SIZE(channels_quad), 397 .list = channels_quad, 398 .mask = 0, 399 }; 400 401 static int kbl_fe_startup(struct snd_pcm_substream *substream) 402 { 403 struct snd_pcm_runtime *runtime = substream->runtime; 404 struct snd_soc_pcm_runtime *soc_rt = substream->private_data; 405 406 /* 407 * On this platform for PCM device we support, 408 * 48Khz 409 * stereo 410 */ 411 412 runtime->hw.channels_max = DUAL_CHANNEL; 413 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 414 &constraints_channels); 415 /* 416 * Setup S24_LE (32 bit container and 24 bit valid data) for 417 * kblda7219m98373 & kblmax98373. For kblda7219m98927 & 418 * kblmax98927 keeping it as 16/16 due to topology FW dependency. 419 */ 420 if (!strcmp(soc_rt->card->name, "kblda7219m98373") || 421 !strcmp(soc_rt->card->name, "kblmax98373")) { 422 runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_LE; 423 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); 424 425 } else { 426 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; 427 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16); 428 } 429 430 snd_pcm_hw_constraint_list(runtime, 0, 431 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); 432 433 return 0; 434 } 435 436 static const struct snd_soc_ops kabylake_da7219_fe_ops = { 437 .startup = kbl_fe_startup, 438 }; 439 440 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd, 441 struct snd_pcm_hw_params *params) 442 { 443 struct snd_interval *channels = hw_param_interval(params, 444 SNDRV_PCM_HW_PARAM_CHANNELS); 445 446 /* 447 * set BE channel constraint as user FE channels 448 */ 449 450 if (params_channels(params) == 2) 451 channels->min = channels->max = 2; 452 else 453 channels->min = channels->max = 4; 454 455 return 0; 456 } 457 458 static int kabylake_dmic_startup(struct snd_pcm_substream *substream) 459 { 460 struct snd_pcm_runtime *runtime = substream->runtime; 461 struct snd_soc_pcm_runtime *soc_rt = substream->private_data; 462 463 runtime->hw.channels_min = runtime->hw.channels_max = QUAD_CHANNEL; 464 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 465 &constraints_channels_quad); 466 467 /* 468 * Topology for kblda7219m98373 & kblmax98373 supports only S24_LE. 469 * The DMIC also configured for S24_LE. Forcing the DMIC format to 470 * S24_LE due to the topology FW dependency. 471 */ 472 if (!strcmp(soc_rt->card->name, "kblda7219m98373") || 473 !strcmp(soc_rt->card->name, "kblmax98373")) { 474 runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_LE; 475 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); 476 } 477 478 return snd_pcm_hw_constraint_list(substream->runtime, 0, 479 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); 480 } 481 482 static struct snd_soc_ops kabylake_dmic_ops = { 483 .startup = kabylake_dmic_startup, 484 }; 485 486 static const unsigned int rates_16000[] = { 487 16000, 488 }; 489 490 static const struct snd_pcm_hw_constraint_list constraints_16000 = { 491 .count = ARRAY_SIZE(rates_16000), 492 .list = rates_16000, 493 }; 494 495 static const unsigned int ch_mono[] = { 496 1, 497 }; 498 static const struct snd_pcm_hw_constraint_list constraints_refcap = { 499 .count = ARRAY_SIZE(ch_mono), 500 .list = ch_mono, 501 }; 502 503 static int kabylake_refcap_startup(struct snd_pcm_substream *substream) 504 { 505 substream->runtime->hw.channels_max = 1; 506 snd_pcm_hw_constraint_list(substream->runtime, 0, 507 SNDRV_PCM_HW_PARAM_CHANNELS, 508 &constraints_refcap); 509 510 return snd_pcm_hw_constraint_list(substream->runtime, 0, 511 SNDRV_PCM_HW_PARAM_RATE, 512 &constraints_16000); 513 } 514 515 516 static struct snd_soc_ops skylake_refcap_ops = { 517 .startup = kabylake_refcap_startup, 518 }; 519 520 static struct snd_soc_codec_conf max98927_codec_conf[] = { 521 522 { 523 .dev_name = MAX98927_DEV0_NAME, 524 .name_prefix = "Right", 525 }, 526 527 { 528 .dev_name = MAX98927_DEV1_NAME, 529 .name_prefix = "Left", 530 }, 531 }; 532 533 static struct snd_soc_codec_conf max98373_codec_conf[] = { 534 535 { 536 .dev_name = MAX98373_DEV0_NAME, 537 .name_prefix = "Right", 538 }, 539 540 { 541 .dev_name = MAX98373_DEV1_NAME, 542 .name_prefix = "Left", 543 }, 544 }; 545 546 static struct snd_soc_dai_link_component max98927_ssp0_codec_components[] = { 547 { /* Left */ 548 .name = MAX98927_DEV0_NAME, 549 .dai_name = MAX98927_CODEC_DAI, 550 }, 551 552 { /* For Right */ 553 .name = MAX98927_DEV1_NAME, 554 .dai_name = MAX98927_CODEC_DAI, 555 }, 556 557 }; 558 559 static struct snd_soc_dai_link_component max98373_ssp0_codec_components[] = { 560 { /* Left */ 561 .name = MAX98373_DEV0_NAME, 562 .dai_name = MAX98373_CODEC_DAI, 563 }, 564 565 { /* For Right */ 566 .name = MAX98373_DEV1_NAME, 567 .dai_name = MAX98373_CODEC_DAI, 568 }, 569 570 }; 571 572 /* kabylake digital audio interface glue - connects codec <--> CPU */ 573 static struct snd_soc_dai_link kabylake_dais[] = { 574 /* Front End DAI links */ 575 [KBL_DPCM_AUDIO_PB] = { 576 .name = "Kbl Audio Port", 577 .stream_name = "Audio", 578 .cpu_dai_name = "System Pin", 579 .platform_name = "0000:00:1f.3", 580 .dynamic = 1, 581 .codec_name = "snd-soc-dummy", 582 .codec_dai_name = "snd-soc-dummy-dai", 583 .nonatomic = 1, 584 .init = kabylake_da7219_fe_init, 585 .trigger = { 586 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 587 .dpcm_playback = 1, 588 .ops = &kabylake_da7219_fe_ops, 589 }, 590 [KBL_DPCM_AUDIO_ECHO_REF_CP] = { 591 .name = "Kbl Audio Echo Reference cap", 592 .stream_name = "Echoreference Capture", 593 .cpu_dai_name = "Echoref Pin", 594 .codec_name = "snd-soc-dummy", 595 .codec_dai_name = "snd-soc-dummy-dai", 596 .platform_name = "0000:00:1f.3", 597 .init = NULL, 598 .capture_only = 1, 599 .nonatomic = 1, 600 }, 601 [KBL_DPCM_AUDIO_REF_CP] = { 602 .name = "Kbl Audio Reference cap", 603 .stream_name = "Wake on Voice", 604 .cpu_dai_name = "Reference Pin", 605 .codec_name = "snd-soc-dummy", 606 .codec_dai_name = "snd-soc-dummy-dai", 607 .platform_name = "0000:00:1f.3", 608 .init = NULL, 609 .dpcm_capture = 1, 610 .nonatomic = 1, 611 .dynamic = 1, 612 .ops = &skylake_refcap_ops, 613 }, 614 [KBL_DPCM_AUDIO_DMIC_CP] = { 615 .name = "Kbl Audio DMIC cap", 616 .stream_name = "dmiccap", 617 .cpu_dai_name = "DMIC Pin", 618 .codec_name = "snd-soc-dummy", 619 .codec_dai_name = "snd-soc-dummy-dai", 620 .platform_name = "0000:00:1f.3", 621 .init = NULL, 622 .dpcm_capture = 1, 623 .nonatomic = 1, 624 .dynamic = 1, 625 .ops = &kabylake_dmic_ops, 626 }, 627 [KBL_DPCM_AUDIO_HDMI1_PB] = { 628 .name = "Kbl HDMI Port1", 629 .stream_name = "Hdmi1", 630 .cpu_dai_name = "HDMI1 Pin", 631 .codec_name = "snd-soc-dummy", 632 .codec_dai_name = "snd-soc-dummy-dai", 633 .platform_name = "0000:00:1f.3", 634 .dpcm_playback = 1, 635 .init = NULL, 636 .trigger = { 637 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 638 .nonatomic = 1, 639 .dynamic = 1, 640 }, 641 [KBL_DPCM_AUDIO_HDMI2_PB] = { 642 .name = "Kbl HDMI Port2", 643 .stream_name = "Hdmi2", 644 .cpu_dai_name = "HDMI2 Pin", 645 .codec_name = "snd-soc-dummy", 646 .codec_dai_name = "snd-soc-dummy-dai", 647 .platform_name = "0000:00:1f.3", 648 .dpcm_playback = 1, 649 .init = NULL, 650 .trigger = { 651 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 652 .nonatomic = 1, 653 .dynamic = 1, 654 }, 655 [KBL_DPCM_AUDIO_HDMI3_PB] = { 656 .name = "Kbl HDMI Port3", 657 .stream_name = "Hdmi3", 658 .cpu_dai_name = "HDMI3 Pin", 659 .codec_name = "snd-soc-dummy", 660 .codec_dai_name = "snd-soc-dummy-dai", 661 .platform_name = "0000:00:1f.3", 662 .trigger = { 663 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 664 .dpcm_playback = 1, 665 .init = NULL, 666 .nonatomic = 1, 667 .dynamic = 1, 668 }, 669 [KBL_DPCM_AUDIO_HS_PB] = { 670 .name = "Kbl Audio Headset Playback", 671 .stream_name = "Headset Audio", 672 .cpu_dai_name = "System Pin2", 673 .codec_name = "snd-soc-dummy", 674 .codec_dai_name = "snd-soc-dummy-dai", 675 .platform_name = "0000:00:1f.3", 676 .dpcm_playback = 1, 677 .nonatomic = 1, 678 .dynamic = 1, 679 .init = kabylake_da7219_fe_init, 680 .trigger = { 681 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 682 .ops = &kabylake_da7219_fe_ops, 683 684 }, 685 [KBL_DPCM_AUDIO_CP] = { 686 .name = "Kbl Audio Capture Port", 687 .stream_name = "Audio Record", 688 .cpu_dai_name = "System Pin", 689 .platform_name = "0000:00:1f.3", 690 .dynamic = 1, 691 .codec_name = "snd-soc-dummy", 692 .codec_dai_name = "snd-soc-dummy-dai", 693 .nonatomic = 1, 694 .trigger = { 695 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 696 .dpcm_capture = 1, 697 .ops = &kabylake_da7219_fe_ops, 698 }, 699 700 /* Back End DAI links */ 701 { 702 /* SSP0 - Codec */ 703 .name = "SSP0-Codec", 704 .id = 0, 705 .cpu_dai_name = "SSP0 Pin", 706 .platform_name = "0000:00:1f.3", 707 .no_pcm = 1, 708 .codecs = max98927_ssp0_codec_components, 709 .num_codecs = ARRAY_SIZE(max98927_ssp0_codec_components), 710 .dai_fmt = SND_SOC_DAIFMT_DSP_B | 711 SND_SOC_DAIFMT_NB_NF | 712 SND_SOC_DAIFMT_CBS_CFS, 713 .dpcm_playback = 1, 714 .dpcm_capture = 1, 715 .ignore_pmdown_time = 1, 716 .be_hw_params_fixup = kabylake_ssp_fixup, 717 .ops = &kabylake_ssp0_ops, 718 }, 719 { 720 /* SSP1 - Codec */ 721 .name = "SSP1-Codec", 722 .id = 1, 723 .cpu_dai_name = "SSP1 Pin", 724 .platform_name = "0000:00:1f.3", 725 .no_pcm = 1, 726 .codec_name = "i2c-DLGS7219:00", 727 .codec_dai_name = KBL_DIALOG_CODEC_DAI, 728 .init = kabylake_da7219_codec_init, 729 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 730 SND_SOC_DAIFMT_CBS_CFS, 731 .ignore_pmdown_time = 1, 732 .be_hw_params_fixup = kabylake_ssp_fixup, 733 .dpcm_playback = 1, 734 .dpcm_capture = 1, 735 }, 736 { 737 .name = "dmic01", 738 .id = 2, 739 .cpu_dai_name = "DMIC01 Pin", 740 .codec_name = "dmic-codec", 741 .codec_dai_name = "dmic-hifi", 742 .init = kabylake_dmic_init, 743 .platform_name = "0000:00:1f.3", 744 .be_hw_params_fixup = kabylake_dmic_fixup, 745 .ignore_suspend = 1, 746 .dpcm_capture = 1, 747 .no_pcm = 1, 748 }, 749 { 750 .name = "iDisp1", 751 .id = 3, 752 .cpu_dai_name = "iDisp1 Pin", 753 .codec_name = "ehdaudio0D2", 754 .codec_dai_name = "intel-hdmi-hifi1", 755 .platform_name = "0000:00:1f.3", 756 .dpcm_playback = 1, 757 .init = kabylake_hdmi1_init, 758 .no_pcm = 1, 759 }, 760 { 761 .name = "iDisp2", 762 .id = 4, 763 .cpu_dai_name = "iDisp2 Pin", 764 .codec_name = "ehdaudio0D2", 765 .codec_dai_name = "intel-hdmi-hifi2", 766 .platform_name = "0000:00:1f.3", 767 .init = kabylake_hdmi2_init, 768 .dpcm_playback = 1, 769 .no_pcm = 1, 770 }, 771 { 772 .name = "iDisp3", 773 .id = 5, 774 .cpu_dai_name = "iDisp3 Pin", 775 .codec_name = "ehdaudio0D2", 776 .codec_dai_name = "intel-hdmi-hifi3", 777 .platform_name = "0000:00:1f.3", 778 .init = kabylake_hdmi3_init, 779 .dpcm_playback = 1, 780 .no_pcm = 1, 781 }, 782 }; 783 784 /* kabylake digital audio interface glue - connects codec <--> CPU */ 785 static struct snd_soc_dai_link kabylake_max98_927_373_dais[] = { 786 /* Front End DAI links */ 787 [KBL_DPCM_AUDIO_PB] = { 788 .name = "Kbl Audio Port", 789 .stream_name = "Audio", 790 .cpu_dai_name = "System Pin", 791 .platform_name = "0000:00:1f.3", 792 .dynamic = 1, 793 .codec_name = "snd-soc-dummy", 794 .codec_dai_name = "snd-soc-dummy-dai", 795 .nonatomic = 1, 796 .init = kabylake_da7219_fe_init, 797 .trigger = { 798 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 799 .dpcm_playback = 1, 800 .ops = &kabylake_da7219_fe_ops, 801 }, 802 [KBL_DPCM_AUDIO_ECHO_REF_CP] = { 803 .name = "Kbl Audio Echo Reference cap", 804 .stream_name = "Echoreference Capture", 805 .cpu_dai_name = "Echoref Pin", 806 .codec_name = "snd-soc-dummy", 807 .codec_dai_name = "snd-soc-dummy-dai", 808 .platform_name = "0000:00:1f.3", 809 .init = NULL, 810 .capture_only = 1, 811 .nonatomic = 1, 812 }, 813 [KBL_DPCM_AUDIO_REF_CP] = { 814 .name = "Kbl Audio Reference cap", 815 .stream_name = "Wake on Voice", 816 .cpu_dai_name = "Reference Pin", 817 .codec_name = "snd-soc-dummy", 818 .codec_dai_name = "snd-soc-dummy-dai", 819 .platform_name = "0000:00:1f.3", 820 .init = NULL, 821 .dpcm_capture = 1, 822 .nonatomic = 1, 823 .dynamic = 1, 824 .ops = &skylake_refcap_ops, 825 }, 826 [KBL_DPCM_AUDIO_DMIC_CP] = { 827 .name = "Kbl Audio DMIC cap", 828 .stream_name = "dmiccap", 829 .cpu_dai_name = "DMIC Pin", 830 .codec_name = "snd-soc-dummy", 831 .codec_dai_name = "snd-soc-dummy-dai", 832 .platform_name = "0000:00:1f.3", 833 .init = NULL, 834 .dpcm_capture = 1, 835 .nonatomic = 1, 836 .dynamic = 1, 837 .ops = &kabylake_dmic_ops, 838 }, 839 [KBL_DPCM_AUDIO_HDMI1_PB] = { 840 .name = "Kbl HDMI Port1", 841 .stream_name = "Hdmi1", 842 .cpu_dai_name = "HDMI1 Pin", 843 .codec_name = "snd-soc-dummy", 844 .codec_dai_name = "snd-soc-dummy-dai", 845 .platform_name = "0000:00:1f.3", 846 .dpcm_playback = 1, 847 .init = NULL, 848 .trigger = { 849 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 850 .nonatomic = 1, 851 .dynamic = 1, 852 }, 853 [KBL_DPCM_AUDIO_HDMI2_PB] = { 854 .name = "Kbl HDMI Port2", 855 .stream_name = "Hdmi2", 856 .cpu_dai_name = "HDMI2 Pin", 857 .codec_name = "snd-soc-dummy", 858 .codec_dai_name = "snd-soc-dummy-dai", 859 .platform_name = "0000:00:1f.3", 860 .dpcm_playback = 1, 861 .init = NULL, 862 .trigger = { 863 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 864 .nonatomic = 1, 865 .dynamic = 1, 866 }, 867 [KBL_DPCM_AUDIO_HDMI3_PB] = { 868 .name = "Kbl HDMI Port3", 869 .stream_name = "Hdmi3", 870 .cpu_dai_name = "HDMI3 Pin", 871 .codec_name = "snd-soc-dummy", 872 .codec_dai_name = "snd-soc-dummy-dai", 873 .platform_name = "0000:00:1f.3", 874 .trigger = { 875 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 876 .dpcm_playback = 1, 877 .init = NULL, 878 .nonatomic = 1, 879 .dynamic = 1, 880 }, 881 882 /* Back End DAI links */ 883 { 884 /* SSP0 - Codec */ 885 .name = "SSP0-Codec", 886 .id = 0, 887 .cpu_dai_name = "SSP0 Pin", 888 .platform_name = "0000:00:1f.3", 889 .no_pcm = 1, 890 .codecs = max98927_ssp0_codec_components, 891 .num_codecs = ARRAY_SIZE(max98927_ssp0_codec_components), 892 .dai_fmt = SND_SOC_DAIFMT_DSP_B | 893 SND_SOC_DAIFMT_NB_NF | 894 SND_SOC_DAIFMT_CBS_CFS, 895 .dpcm_playback = 1, 896 .dpcm_capture = 1, 897 .ignore_pmdown_time = 1, 898 .be_hw_params_fixup = kabylake_ssp_fixup, 899 .ops = &kabylake_ssp0_ops, 900 }, 901 { 902 .name = "dmic01", 903 .id = 1, 904 .cpu_dai_name = "DMIC01 Pin", 905 .codec_name = "dmic-codec", 906 .codec_dai_name = "dmic-hifi", 907 .init = kabylake_dmic_init, 908 .platform_name = "0000:00:1f.3", 909 .be_hw_params_fixup = kabylake_dmic_fixup, 910 .ignore_suspend = 1, 911 .dpcm_capture = 1, 912 .no_pcm = 1, 913 }, 914 { 915 .name = "iDisp1", 916 .id = 2, 917 .cpu_dai_name = "iDisp1 Pin", 918 .codec_name = "ehdaudio0D2", 919 .codec_dai_name = "intel-hdmi-hifi1", 920 .platform_name = "0000:00:1f.3", 921 .dpcm_playback = 1, 922 .init = kabylake_hdmi1_init, 923 .no_pcm = 1, 924 }, 925 { 926 .name = "iDisp2", 927 .id = 3, 928 .cpu_dai_name = "iDisp2 Pin", 929 .codec_name = "ehdaudio0D2", 930 .codec_dai_name = "intel-hdmi-hifi2", 931 .platform_name = "0000:00:1f.3", 932 .init = kabylake_hdmi2_init, 933 .dpcm_playback = 1, 934 .no_pcm = 1, 935 }, 936 { 937 .name = "iDisp3", 938 .id = 4, 939 .cpu_dai_name = "iDisp3 Pin", 940 .codec_name = "ehdaudio0D2", 941 .codec_dai_name = "intel-hdmi-hifi3", 942 .platform_name = "0000:00:1f.3", 943 .init = kabylake_hdmi3_init, 944 .dpcm_playback = 1, 945 .no_pcm = 1, 946 }, 947 }; 948 949 static int kabylake_card_late_probe(struct snd_soc_card *card) 950 { 951 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card); 952 struct kbl_hdmi_pcm *pcm; 953 struct snd_soc_component *component = NULL; 954 int err, i = 0; 955 char jack_name[NAME_SIZE]; 956 957 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) { 958 component = pcm->codec_dai->component; 959 snprintf(jack_name, sizeof(jack_name), 960 "HDMI/DP, pcm=%d Jack", pcm->device); 961 err = snd_soc_card_jack_new(card, jack_name, 962 SND_JACK_AVOUT, &kabylake_hdmi[i], 963 NULL, 0); 964 965 if (err) 966 return err; 967 968 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device, 969 &kabylake_hdmi[i]); 970 if (err < 0) 971 return err; 972 973 i++; 974 } 975 976 if (!component) 977 return -EINVAL; 978 979 return hdac_hdmi_jack_port_init(component, &card->dapm); 980 981 return 0; 982 } 983 984 /* kabylake audio machine driver for SPT + DA7219 */ 985 static struct snd_soc_card kbl_audio_card_da7219_m98927 = { 986 .name = "kblda7219m98927", 987 .owner = THIS_MODULE, 988 .dai_link = kabylake_dais, 989 .num_links = ARRAY_SIZE(kabylake_dais), 990 .controls = kabylake_controls, 991 .num_controls = ARRAY_SIZE(kabylake_controls), 992 .dapm_widgets = kabylake_widgets, 993 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets), 994 .dapm_routes = kabylake_map, 995 .num_dapm_routes = ARRAY_SIZE(kabylake_map), 996 .codec_conf = max98927_codec_conf, 997 .num_configs = ARRAY_SIZE(max98927_codec_conf), 998 .fully_routed = true, 999 .late_probe = kabylake_card_late_probe, 1000 }; 1001 1002 /* kabylake audio machine driver for Maxim98927 */ 1003 static struct snd_soc_card kbl_audio_card_max98927 = { 1004 .name = "kblmax98927", 1005 .owner = THIS_MODULE, 1006 .dai_link = kabylake_max98_927_373_dais, 1007 .num_links = ARRAY_SIZE(kabylake_max98_927_373_dais), 1008 .controls = kabylake_controls, 1009 .num_controls = ARRAY_SIZE(kabylake_controls), 1010 .dapm_widgets = kabylake_widgets, 1011 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets), 1012 .dapm_routes = kabylake_map, 1013 .num_dapm_routes = ARRAY_SIZE(kabylake_map), 1014 .codec_conf = max98927_codec_conf, 1015 .num_configs = ARRAY_SIZE(max98927_codec_conf), 1016 .fully_routed = true, 1017 .late_probe = kabylake_card_late_probe, 1018 }; 1019 1020 static struct snd_soc_card kbl_audio_card_da7219_m98373 = { 1021 .name = "kblda7219m98373", 1022 .owner = THIS_MODULE, 1023 .dai_link = kabylake_dais, 1024 .num_links = ARRAY_SIZE(kabylake_dais), 1025 .controls = kabylake_controls, 1026 .num_controls = ARRAY_SIZE(kabylake_controls), 1027 .dapm_widgets = kabylake_widgets, 1028 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets), 1029 .dapm_routes = kabylake_map, 1030 .num_dapm_routes = ARRAY_SIZE(kabylake_map), 1031 .codec_conf = max98373_codec_conf, 1032 .num_configs = ARRAY_SIZE(max98373_codec_conf), 1033 .fully_routed = true, 1034 .late_probe = kabylake_card_late_probe, 1035 }; 1036 1037 static struct snd_soc_card kbl_audio_card_max98373 = { 1038 .name = "kblmax98373", 1039 .owner = THIS_MODULE, 1040 .dai_link = kabylake_max98_927_373_dais, 1041 .num_links = ARRAY_SIZE(kabylake_max98_927_373_dais), 1042 .controls = kabylake_controls, 1043 .num_controls = ARRAY_SIZE(kabylake_controls), 1044 .dapm_widgets = kabylake_widgets, 1045 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets), 1046 .dapm_routes = kabylake_map, 1047 .num_dapm_routes = ARRAY_SIZE(kabylake_map), 1048 .codec_conf = max98373_codec_conf, 1049 .num_configs = ARRAY_SIZE(max98373_codec_conf), 1050 .fully_routed = true, 1051 .late_probe = kabylake_card_late_probe, 1052 }; 1053 1054 static int kabylake_audio_probe(struct platform_device *pdev) 1055 { 1056 struct kbl_codec_private *ctx; 1057 struct snd_soc_dai_link *kbl_dai_link; 1058 struct snd_soc_dai_link_component **codecs; 1059 int i = 0; 1060 1061 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); 1062 if (!ctx) 1063 return -ENOMEM; 1064 1065 INIT_LIST_HEAD(&ctx->hdmi_pcm_list); 1066 1067 kabylake_audio_card = 1068 (struct snd_soc_card *)pdev->id_entry->driver_data; 1069 1070 kbl_dai_link = kabylake_audio_card->dai_link; 1071 1072 /* Update codecs for SSP0 with max98373 codec info */ 1073 if (!strcmp(pdev->name, "kbl_da7219_max98373") || 1074 (!strcmp(pdev->name, "kbl_max98373"))) { 1075 for (i = 0; i < kabylake_audio_card->num_links; ++i) { 1076 if (strcmp(kbl_dai_link[i].name, "SSP0-Codec")) 1077 continue; 1078 1079 codecs = &(kbl_dai_link[i].codecs); 1080 *codecs = max98373_ssp0_codec_components; 1081 kbl_dai_link[i].num_codecs = 1082 ARRAY_SIZE(max98373_ssp0_codec_components); 1083 break; 1084 } 1085 } 1086 kabylake_audio_card->dev = &pdev->dev; 1087 snd_soc_card_set_drvdata(kabylake_audio_card, ctx); 1088 1089 return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card); 1090 } 1091 1092 static const struct platform_device_id kbl_board_ids[] = { 1093 { 1094 .name = "kbl_da7219_max98927", 1095 .driver_data = 1096 (kernel_ulong_t)&kbl_audio_card_da7219_m98927, 1097 }, 1098 { 1099 .name = "kbl_max98927", 1100 .driver_data = 1101 (kernel_ulong_t)&kbl_audio_card_max98927, 1102 }, 1103 { 1104 .name = "kbl_da7219_max98373", 1105 .driver_data = 1106 (kernel_ulong_t)&kbl_audio_card_da7219_m98373, 1107 }, 1108 { 1109 .name = "kbl_max98373", 1110 .driver_data = 1111 (kernel_ulong_t)&kbl_audio_card_max98373, 1112 }, 1113 { } 1114 }; 1115 1116 static struct platform_driver kabylake_audio = { 1117 .probe = kabylake_audio_probe, 1118 .driver = { 1119 .name = "kbl_da7219_max98_927_373", 1120 .pm = &snd_soc_pm_ops, 1121 }, 1122 .id_table = kbl_board_ids, 1123 }; 1124 1125 module_platform_driver(kabylake_audio) 1126 1127 /* Module information */ 1128 MODULE_DESCRIPTION("Audio KabyLake Machine driver for MAX98927/MAX98373 & DA7219"); 1129 MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>"); 1130 MODULE_LICENSE("GPL v2"); 1131 MODULE_ALIAS("platform:kbl_da7219_max98927"); 1132 MODULE_ALIAS("platform:kbl_max98927"); 1133 MODULE_ALIAS("platform:kbl_da7219_max98373"); 1134 MODULE_ALIAS("platform:kbl_max98373"); 1135