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_CP, 56 KBL_DPCM_AUDIO_ECHO_REF_CP, 57 KBL_DPCM_AUDIO_REF_CP, 58 KBL_DPCM_AUDIO_DMIC_CP, 59 KBL_DPCM_AUDIO_HDMI1_PB, 60 KBL_DPCM_AUDIO_HDMI2_PB, 61 KBL_DPCM_AUDIO_HDMI3_PB, 62 KBL_DPCM_AUDIO_HS_PB, 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 ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC"); 315 if (ret) 316 dev_err(rtd->dev, "SoC DMIC - Ignore suspend failed %d\n", ret); 317 318 return ret; 319 } 320 321 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device) 322 { 323 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card); 324 struct snd_soc_dai *dai = rtd->codec_dai; 325 struct kbl_hdmi_pcm *pcm; 326 327 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL); 328 if (!pcm) 329 return -ENOMEM; 330 331 pcm->device = device; 332 pcm->codec_dai = dai; 333 334 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list); 335 336 return 0; 337 } 338 339 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd) 340 { 341 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB); 342 } 343 344 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd) 345 { 346 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB); 347 } 348 349 static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd) 350 { 351 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB); 352 } 353 354 static int kabylake_da7219_fe_init(struct snd_soc_pcm_runtime *rtd) 355 { 356 struct snd_soc_dapm_context *dapm; 357 struct snd_soc_component *component = rtd->cpu_dai->component; 358 359 dapm = snd_soc_component_get_dapm(component); 360 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture"); 361 362 return 0; 363 } 364 365 static const unsigned int rates[] = { 366 48000, 367 }; 368 369 static const struct snd_pcm_hw_constraint_list constraints_rates = { 370 .count = ARRAY_SIZE(rates), 371 .list = rates, 372 .mask = 0, 373 }; 374 375 static const unsigned int channels[] = { 376 DUAL_CHANNEL, 377 }; 378 379 static const struct snd_pcm_hw_constraint_list constraints_channels = { 380 .count = ARRAY_SIZE(channels), 381 .list = channels, 382 .mask = 0, 383 }; 384 385 static unsigned int channels_quad[] = { 386 QUAD_CHANNEL, 387 }; 388 389 static struct snd_pcm_hw_constraint_list constraints_channels_quad = { 390 .count = ARRAY_SIZE(channels_quad), 391 .list = channels_quad, 392 .mask = 0, 393 }; 394 395 static int kbl_fe_startup(struct snd_pcm_substream *substream) 396 { 397 struct snd_pcm_runtime *runtime = substream->runtime; 398 struct snd_soc_pcm_runtime *soc_rt = substream->private_data; 399 400 /* 401 * On this platform for PCM device we support, 402 * 48Khz 403 * stereo 404 */ 405 406 runtime->hw.channels_max = DUAL_CHANNEL; 407 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 408 &constraints_channels); 409 /* 410 * Setup S24_LE (32 bit container and 24 bit valid data) for 411 * kblda7219m98373 & kblmax98373. For kblda7219m98927 & 412 * kblmax98927 keeping it as 16/16 due to topology FW dependency. 413 */ 414 if (!strcmp(soc_rt->card->name, "kblda7219m98373") || 415 !strcmp(soc_rt->card->name, "kblmax98373")) { 416 runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_LE; 417 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); 418 419 } else { 420 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; 421 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16); 422 } 423 424 snd_pcm_hw_constraint_list(runtime, 0, 425 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); 426 427 return 0; 428 } 429 430 static const struct snd_soc_ops kabylake_da7219_fe_ops = { 431 .startup = kbl_fe_startup, 432 }; 433 434 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd, 435 struct snd_pcm_hw_params *params) 436 { 437 struct snd_interval *channels = hw_param_interval(params, 438 SNDRV_PCM_HW_PARAM_CHANNELS); 439 440 /* 441 * set BE channel constraint as user FE channels 442 */ 443 444 if (params_channels(params) == 2) 445 channels->min = channels->max = 2; 446 else 447 channels->min = channels->max = 4; 448 449 return 0; 450 } 451 452 static int kabylake_dmic_startup(struct snd_pcm_substream *substream) 453 { 454 struct snd_pcm_runtime *runtime = substream->runtime; 455 struct snd_soc_pcm_runtime *soc_rt = substream->private_data; 456 457 runtime->hw.channels_min = runtime->hw.channels_max = QUAD_CHANNEL; 458 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 459 &constraints_channels_quad); 460 461 /* 462 * Topology for kblda7219m98373 & kblmax98373 supports only S24_LE. 463 * The DMIC also configured for S24_LE. Forcing the DMIC format to 464 * S24_LE due to the topology FW dependency. 465 */ 466 if (!strcmp(soc_rt->card->name, "kblda7219m98373") || 467 !strcmp(soc_rt->card->name, "kblmax98373")) { 468 runtime->hw.formats = SNDRV_PCM_FMTBIT_S24_LE; 469 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); 470 } 471 472 return snd_pcm_hw_constraint_list(substream->runtime, 0, 473 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); 474 } 475 476 static struct snd_soc_ops kabylake_dmic_ops = { 477 .startup = kabylake_dmic_startup, 478 }; 479 480 static const unsigned int rates_16000[] = { 481 16000, 482 }; 483 484 static const struct snd_pcm_hw_constraint_list constraints_16000 = { 485 .count = ARRAY_SIZE(rates_16000), 486 .list = rates_16000, 487 }; 488 489 static const unsigned int ch_mono[] = { 490 1, 491 }; 492 static const struct snd_pcm_hw_constraint_list constraints_refcap = { 493 .count = ARRAY_SIZE(ch_mono), 494 .list = ch_mono, 495 }; 496 497 static int kabylake_refcap_startup(struct snd_pcm_substream *substream) 498 { 499 substream->runtime->hw.channels_max = 1; 500 snd_pcm_hw_constraint_list(substream->runtime, 0, 501 SNDRV_PCM_HW_PARAM_CHANNELS, 502 &constraints_refcap); 503 504 return snd_pcm_hw_constraint_list(substream->runtime, 0, 505 SNDRV_PCM_HW_PARAM_RATE, 506 &constraints_16000); 507 } 508 509 510 static struct snd_soc_ops skylake_refcap_ops = { 511 .startup = kabylake_refcap_startup, 512 }; 513 514 static struct snd_soc_codec_conf max98927_codec_conf[] = { 515 516 { 517 .dev_name = MAX98927_DEV0_NAME, 518 .name_prefix = "Right", 519 }, 520 521 { 522 .dev_name = MAX98927_DEV1_NAME, 523 .name_prefix = "Left", 524 }, 525 }; 526 527 static struct snd_soc_codec_conf max98373_codec_conf[] = { 528 529 { 530 .dev_name = MAX98373_DEV0_NAME, 531 .name_prefix = "Right", 532 }, 533 534 { 535 .dev_name = MAX98373_DEV1_NAME, 536 .name_prefix = "Left", 537 }, 538 }; 539 540 static struct snd_soc_dai_link_component max98927_ssp0_codec_components[] = { 541 { /* Left */ 542 .name = MAX98927_DEV0_NAME, 543 .dai_name = MAX98927_CODEC_DAI, 544 }, 545 546 { /* For Right */ 547 .name = MAX98927_DEV1_NAME, 548 .dai_name = MAX98927_CODEC_DAI, 549 }, 550 551 }; 552 553 static struct snd_soc_dai_link_component max98373_ssp0_codec_components[] = { 554 { /* Left */ 555 .name = MAX98373_DEV0_NAME, 556 .dai_name = MAX98373_CODEC_DAI, 557 }, 558 559 { /* For Right */ 560 .name = MAX98373_DEV1_NAME, 561 .dai_name = MAX98373_CODEC_DAI, 562 }, 563 564 }; 565 566 /* kabylake digital audio interface glue - connects codec <--> CPU */ 567 static struct snd_soc_dai_link kabylake_dais[] = { 568 /* Front End DAI links */ 569 [KBL_DPCM_AUDIO_PB] = { 570 .name = "Kbl Audio Port", 571 .stream_name = "Audio", 572 .cpu_dai_name = "System Pin", 573 .platform_name = "0000:00:1f.3", 574 .dynamic = 1, 575 .codec_name = "snd-soc-dummy", 576 .codec_dai_name = "snd-soc-dummy-dai", 577 .nonatomic = 1, 578 .init = kabylake_da7219_fe_init, 579 .trigger = { 580 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 581 .dpcm_playback = 1, 582 .ops = &kabylake_da7219_fe_ops, 583 }, 584 [KBL_DPCM_AUDIO_CP] = { 585 .name = "Kbl Audio Capture Port", 586 .stream_name = "Audio Record", 587 .cpu_dai_name = "System Pin", 588 .platform_name = "0000:00:1f.3", 589 .dynamic = 1, 590 .codec_name = "snd-soc-dummy", 591 .codec_dai_name = "snd-soc-dummy-dai", 592 .nonatomic = 1, 593 .trigger = { 594 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 595 .dpcm_capture = 1, 596 .ops = &kabylake_da7219_fe_ops, 597 }, 598 [KBL_DPCM_AUDIO_ECHO_REF_CP] = { 599 .name = "Kbl Audio Echo Reference cap", 600 .stream_name = "Echoreference Capture", 601 .cpu_dai_name = "Echoref Pin", 602 .codec_name = "snd-soc-dummy", 603 .codec_dai_name = "snd-soc-dummy-dai", 604 .platform_name = "0000:00:1f.3", 605 .init = NULL, 606 .capture_only = 1, 607 .nonatomic = 1, 608 }, 609 [KBL_DPCM_AUDIO_REF_CP] = { 610 .name = "Kbl Audio Reference cap", 611 .stream_name = "Wake on Voice", 612 .cpu_dai_name = "Reference Pin", 613 .codec_name = "snd-soc-dummy", 614 .codec_dai_name = "snd-soc-dummy-dai", 615 .platform_name = "0000:00:1f.3", 616 .init = NULL, 617 .dpcm_capture = 1, 618 .nonatomic = 1, 619 .dynamic = 1, 620 .ops = &skylake_refcap_ops, 621 }, 622 [KBL_DPCM_AUDIO_DMIC_CP] = { 623 .name = "Kbl Audio DMIC cap", 624 .stream_name = "dmiccap", 625 .cpu_dai_name = "DMIC Pin", 626 .codec_name = "snd-soc-dummy", 627 .codec_dai_name = "snd-soc-dummy-dai", 628 .platform_name = "0000:00:1f.3", 629 .init = NULL, 630 .dpcm_capture = 1, 631 .nonatomic = 1, 632 .dynamic = 1, 633 .ops = &kabylake_dmic_ops, 634 }, 635 [KBL_DPCM_AUDIO_HDMI1_PB] = { 636 .name = "Kbl HDMI Port1", 637 .stream_name = "Hdmi1", 638 .cpu_dai_name = "HDMI1 Pin", 639 .codec_name = "snd-soc-dummy", 640 .codec_dai_name = "snd-soc-dummy-dai", 641 .platform_name = "0000:00:1f.3", 642 .dpcm_playback = 1, 643 .init = NULL, 644 .trigger = { 645 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 646 .nonatomic = 1, 647 .dynamic = 1, 648 }, 649 [KBL_DPCM_AUDIO_HDMI2_PB] = { 650 .name = "Kbl HDMI Port2", 651 .stream_name = "Hdmi2", 652 .cpu_dai_name = "HDMI2 Pin", 653 .codec_name = "snd-soc-dummy", 654 .codec_dai_name = "snd-soc-dummy-dai", 655 .platform_name = "0000:00:1f.3", 656 .dpcm_playback = 1, 657 .init = NULL, 658 .trigger = { 659 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 660 .nonatomic = 1, 661 .dynamic = 1, 662 }, 663 [KBL_DPCM_AUDIO_HDMI3_PB] = { 664 .name = "Kbl HDMI Port3", 665 .stream_name = "Hdmi3", 666 .cpu_dai_name = "HDMI3 Pin", 667 .codec_name = "snd-soc-dummy", 668 .codec_dai_name = "snd-soc-dummy-dai", 669 .platform_name = "0000:00:1f.3", 670 .trigger = { 671 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 672 .dpcm_playback = 1, 673 .init = NULL, 674 .nonatomic = 1, 675 .dynamic = 1, 676 }, 677 [KBL_DPCM_AUDIO_HS_PB] = { 678 .name = "Kbl Audio Headset Playback", 679 .stream_name = "Headset Audio", 680 .cpu_dai_name = "System Pin2", 681 .codec_name = "snd-soc-dummy", 682 .codec_dai_name = "snd-soc-dummy-dai", 683 .platform_name = "0000:00:1f.3", 684 .dpcm_playback = 1, 685 .nonatomic = 1, 686 .dynamic = 1, 687 .init = kabylake_da7219_fe_init, 688 .trigger = { 689 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 690 .ops = &kabylake_da7219_fe_ops, 691 692 }, 693 694 /* Back End DAI links */ 695 { 696 /* SSP0 - Codec */ 697 .name = "SSP0-Codec", 698 .id = 0, 699 .cpu_dai_name = "SSP0 Pin", 700 .platform_name = "0000:00:1f.3", 701 .no_pcm = 1, 702 .codecs = max98927_ssp0_codec_components, 703 .num_codecs = ARRAY_SIZE(max98927_ssp0_codec_components), 704 .dai_fmt = SND_SOC_DAIFMT_DSP_B | 705 SND_SOC_DAIFMT_NB_NF | 706 SND_SOC_DAIFMT_CBS_CFS, 707 .dpcm_playback = 1, 708 .dpcm_capture = 1, 709 .ignore_pmdown_time = 1, 710 .be_hw_params_fixup = kabylake_ssp_fixup, 711 .ops = &kabylake_ssp0_ops, 712 }, 713 { 714 /* SSP1 - Codec */ 715 .name = "SSP1-Codec", 716 .id = 1, 717 .cpu_dai_name = "SSP1 Pin", 718 .platform_name = "0000:00:1f.3", 719 .no_pcm = 1, 720 .codec_name = "i2c-DLGS7219:00", 721 .codec_dai_name = KBL_DIALOG_CODEC_DAI, 722 .init = kabylake_da7219_codec_init, 723 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 724 SND_SOC_DAIFMT_CBS_CFS, 725 .ignore_pmdown_time = 1, 726 .be_hw_params_fixup = kabylake_ssp_fixup, 727 .dpcm_playback = 1, 728 .dpcm_capture = 1, 729 }, 730 { 731 .name = "dmic01", 732 .id = 2, 733 .cpu_dai_name = "DMIC01 Pin", 734 .codec_name = "dmic-codec", 735 .codec_dai_name = "dmic-hifi", 736 .platform_name = "0000:00:1f.3", 737 .be_hw_params_fixup = kabylake_dmic_fixup, 738 .ignore_suspend = 1, 739 .dpcm_capture = 1, 740 .no_pcm = 1, 741 }, 742 { 743 .name = "iDisp1", 744 .id = 3, 745 .cpu_dai_name = "iDisp1 Pin", 746 .codec_name = "ehdaudio0D2", 747 .codec_dai_name = "intel-hdmi-hifi1", 748 .platform_name = "0000:00:1f.3", 749 .dpcm_playback = 1, 750 .init = kabylake_hdmi1_init, 751 .no_pcm = 1, 752 }, 753 { 754 .name = "iDisp2", 755 .id = 4, 756 .cpu_dai_name = "iDisp2 Pin", 757 .codec_name = "ehdaudio0D2", 758 .codec_dai_name = "intel-hdmi-hifi2", 759 .platform_name = "0000:00:1f.3", 760 .init = kabylake_hdmi2_init, 761 .dpcm_playback = 1, 762 .no_pcm = 1, 763 }, 764 { 765 .name = "iDisp3", 766 .id = 5, 767 .cpu_dai_name = "iDisp3 Pin", 768 .codec_name = "ehdaudio0D2", 769 .codec_dai_name = "intel-hdmi-hifi3", 770 .platform_name = "0000:00:1f.3", 771 .init = kabylake_hdmi3_init, 772 .dpcm_playback = 1, 773 .no_pcm = 1, 774 }, 775 }; 776 777 /* kabylake digital audio interface glue - connects codec <--> CPU */ 778 static struct snd_soc_dai_link kabylake_max98_927_373_dais[] = { 779 /* Front End DAI links */ 780 [KBL_DPCM_AUDIO_PB] = { 781 .name = "Kbl Audio Port", 782 .stream_name = "Audio", 783 .cpu_dai_name = "System Pin", 784 .platform_name = "0000:00:1f.3", 785 .dynamic = 1, 786 .codec_name = "snd-soc-dummy", 787 .codec_dai_name = "snd-soc-dummy-dai", 788 .nonatomic = 1, 789 .init = kabylake_da7219_fe_init, 790 .trigger = { 791 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 792 .dpcm_playback = 1, 793 .ops = &kabylake_da7219_fe_ops, 794 }, 795 [KBL_DPCM_AUDIO_CP] = { 796 .name = "Kbl Audio Capture Port", 797 .stream_name = "Audio Record", 798 .cpu_dai_name = "System Pin", 799 .platform_name = "0000:00:1f.3", 800 .dynamic = 1, 801 .codec_name = "snd-soc-dummy", 802 .codec_dai_name = "snd-soc-dummy-dai", 803 .nonatomic = 1, 804 .trigger = { 805 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 806 .dpcm_capture = 1, 807 .ops = &kabylake_da7219_fe_ops, 808 }, 809 [KBL_DPCM_AUDIO_ECHO_REF_CP] = { 810 .name = "Kbl Audio Echo Reference cap", 811 .stream_name = "Echoreference Capture", 812 .cpu_dai_name = "Echoref Pin", 813 .codec_name = "snd-soc-dummy", 814 .codec_dai_name = "snd-soc-dummy-dai", 815 .platform_name = "0000:00:1f.3", 816 .init = NULL, 817 .capture_only = 1, 818 .nonatomic = 1, 819 }, 820 [KBL_DPCM_AUDIO_REF_CP] = { 821 .name = "Kbl Audio Reference cap", 822 .stream_name = "Wake on Voice", 823 .cpu_dai_name = "Reference Pin", 824 .codec_name = "snd-soc-dummy", 825 .codec_dai_name = "snd-soc-dummy-dai", 826 .platform_name = "0000:00:1f.3", 827 .init = NULL, 828 .dpcm_capture = 1, 829 .nonatomic = 1, 830 .dynamic = 1, 831 .ops = &skylake_refcap_ops, 832 }, 833 [KBL_DPCM_AUDIO_DMIC_CP] = { 834 .name = "Kbl Audio DMIC cap", 835 .stream_name = "dmiccap", 836 .cpu_dai_name = "DMIC Pin", 837 .codec_name = "snd-soc-dummy", 838 .codec_dai_name = "snd-soc-dummy-dai", 839 .platform_name = "0000:00:1f.3", 840 .init = NULL, 841 .dpcm_capture = 1, 842 .nonatomic = 1, 843 .dynamic = 1, 844 .ops = &kabylake_dmic_ops, 845 }, 846 [KBL_DPCM_AUDIO_HDMI1_PB] = { 847 .name = "Kbl HDMI Port1", 848 .stream_name = "Hdmi1", 849 .cpu_dai_name = "HDMI1 Pin", 850 .codec_name = "snd-soc-dummy", 851 .codec_dai_name = "snd-soc-dummy-dai", 852 .platform_name = "0000:00:1f.3", 853 .dpcm_playback = 1, 854 .init = NULL, 855 .trigger = { 856 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 857 .nonatomic = 1, 858 .dynamic = 1, 859 }, 860 [KBL_DPCM_AUDIO_HDMI2_PB] = { 861 .name = "Kbl HDMI Port2", 862 .stream_name = "Hdmi2", 863 .cpu_dai_name = "HDMI2 Pin", 864 .codec_name = "snd-soc-dummy", 865 .codec_dai_name = "snd-soc-dummy-dai", 866 .platform_name = "0000:00:1f.3", 867 .dpcm_playback = 1, 868 .init = NULL, 869 .trigger = { 870 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 871 .nonatomic = 1, 872 .dynamic = 1, 873 }, 874 [KBL_DPCM_AUDIO_HDMI3_PB] = { 875 .name = "Kbl HDMI Port3", 876 .stream_name = "Hdmi3", 877 .cpu_dai_name = "HDMI3 Pin", 878 .codec_name = "snd-soc-dummy", 879 .codec_dai_name = "snd-soc-dummy-dai", 880 .platform_name = "0000:00:1f.3", 881 .trigger = { 882 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 883 .dpcm_playback = 1, 884 .init = NULL, 885 .nonatomic = 1, 886 .dynamic = 1, 887 }, 888 889 /* Back End DAI links */ 890 { 891 /* SSP0 - Codec */ 892 .name = "SSP0-Codec", 893 .id = 0, 894 .cpu_dai_name = "SSP0 Pin", 895 .platform_name = "0000:00:1f.3", 896 .no_pcm = 1, 897 .codecs = max98927_ssp0_codec_components, 898 .num_codecs = ARRAY_SIZE(max98927_ssp0_codec_components), 899 .dai_fmt = SND_SOC_DAIFMT_DSP_B | 900 SND_SOC_DAIFMT_NB_NF | 901 SND_SOC_DAIFMT_CBS_CFS, 902 .dpcm_playback = 1, 903 .dpcm_capture = 1, 904 .ignore_pmdown_time = 1, 905 .be_hw_params_fixup = kabylake_ssp_fixup, 906 .ops = &kabylake_ssp0_ops, 907 }, 908 { 909 .name = "dmic01", 910 .id = 1, 911 .cpu_dai_name = "DMIC01 Pin", 912 .codec_name = "dmic-codec", 913 .codec_dai_name = "dmic-hifi", 914 .platform_name = "0000:00:1f.3", 915 .be_hw_params_fixup = kabylake_dmic_fixup, 916 .ignore_suspend = 1, 917 .dpcm_capture = 1, 918 .no_pcm = 1, 919 }, 920 { 921 .name = "iDisp1", 922 .id = 2, 923 .cpu_dai_name = "iDisp1 Pin", 924 .codec_name = "ehdaudio0D2", 925 .codec_dai_name = "intel-hdmi-hifi1", 926 .platform_name = "0000:00:1f.3", 927 .dpcm_playback = 1, 928 .init = kabylake_hdmi1_init, 929 .no_pcm = 1, 930 }, 931 { 932 .name = "iDisp2", 933 .id = 3, 934 .cpu_dai_name = "iDisp2 Pin", 935 .codec_name = "ehdaudio0D2", 936 .codec_dai_name = "intel-hdmi-hifi2", 937 .platform_name = "0000:00:1f.3", 938 .init = kabylake_hdmi2_init, 939 .dpcm_playback = 1, 940 .no_pcm = 1, 941 }, 942 { 943 .name = "iDisp3", 944 .id = 4, 945 .cpu_dai_name = "iDisp3 Pin", 946 .codec_name = "ehdaudio0D2", 947 .codec_dai_name = "intel-hdmi-hifi3", 948 .platform_name = "0000:00:1f.3", 949 .init = kabylake_hdmi3_init, 950 .dpcm_playback = 1, 951 .no_pcm = 1, 952 }, 953 }; 954 955 static int kabylake_card_late_probe(struct snd_soc_card *card) 956 { 957 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card); 958 struct kbl_hdmi_pcm *pcm; 959 struct snd_soc_component *component = NULL; 960 int err, i = 0; 961 char jack_name[NAME_SIZE]; 962 963 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) { 964 component = pcm->codec_dai->component; 965 snprintf(jack_name, sizeof(jack_name), 966 "HDMI/DP, pcm=%d Jack", pcm->device); 967 err = snd_soc_card_jack_new(card, jack_name, 968 SND_JACK_AVOUT, &kabylake_hdmi[i], 969 NULL, 0); 970 971 if (err) 972 return err; 973 974 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device, 975 &kabylake_hdmi[i]); 976 if (err < 0) 977 return err; 978 979 i++; 980 } 981 982 if (!component) 983 return -EINVAL; 984 985 return hdac_hdmi_jack_port_init(component, &card->dapm); 986 987 return 0; 988 } 989 990 /* kabylake audio machine driver for SPT + DA7219 */ 991 static struct snd_soc_card kbl_audio_card_da7219_m98927 = { 992 .name = "kblda7219m98927", 993 .owner = THIS_MODULE, 994 .dai_link = kabylake_dais, 995 .num_links = ARRAY_SIZE(kabylake_dais), 996 .controls = kabylake_controls, 997 .num_controls = ARRAY_SIZE(kabylake_controls), 998 .dapm_widgets = kabylake_widgets, 999 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets), 1000 .dapm_routes = kabylake_map, 1001 .num_dapm_routes = ARRAY_SIZE(kabylake_map), 1002 .codec_conf = max98927_codec_conf, 1003 .num_configs = ARRAY_SIZE(max98927_codec_conf), 1004 .fully_routed = true, 1005 .late_probe = kabylake_card_late_probe, 1006 }; 1007 1008 /* kabylake audio machine driver for Maxim98927 */ 1009 static struct snd_soc_card kbl_audio_card_max98927 = { 1010 .name = "kblmax98927", 1011 .owner = THIS_MODULE, 1012 .dai_link = kabylake_max98_927_373_dais, 1013 .num_links = ARRAY_SIZE(kabylake_max98_927_373_dais), 1014 .controls = kabylake_controls, 1015 .num_controls = ARRAY_SIZE(kabylake_controls), 1016 .dapm_widgets = kabylake_widgets, 1017 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets), 1018 .dapm_routes = kabylake_map, 1019 .num_dapm_routes = ARRAY_SIZE(kabylake_map), 1020 .codec_conf = max98927_codec_conf, 1021 .num_configs = ARRAY_SIZE(max98927_codec_conf), 1022 .fully_routed = true, 1023 .late_probe = kabylake_card_late_probe, 1024 }; 1025 1026 static struct snd_soc_card kbl_audio_card_da7219_m98373 = { 1027 .name = "kblda7219m98373", 1028 .owner = THIS_MODULE, 1029 .dai_link = kabylake_dais, 1030 .num_links = ARRAY_SIZE(kabylake_dais), 1031 .controls = kabylake_controls, 1032 .num_controls = ARRAY_SIZE(kabylake_controls), 1033 .dapm_widgets = kabylake_widgets, 1034 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets), 1035 .dapm_routes = kabylake_map, 1036 .num_dapm_routes = ARRAY_SIZE(kabylake_map), 1037 .codec_conf = max98373_codec_conf, 1038 .num_configs = ARRAY_SIZE(max98373_codec_conf), 1039 .fully_routed = true, 1040 .late_probe = kabylake_card_late_probe, 1041 }; 1042 1043 static struct snd_soc_card kbl_audio_card_max98373 = { 1044 .name = "kblmax98373", 1045 .owner = THIS_MODULE, 1046 .dai_link = kabylake_max98_927_373_dais, 1047 .num_links = ARRAY_SIZE(kabylake_max98_927_373_dais), 1048 .controls = kabylake_controls, 1049 .num_controls = ARRAY_SIZE(kabylake_controls), 1050 .dapm_widgets = kabylake_widgets, 1051 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets), 1052 .dapm_routes = kabylake_map, 1053 .num_dapm_routes = ARRAY_SIZE(kabylake_map), 1054 .codec_conf = max98373_codec_conf, 1055 .num_configs = ARRAY_SIZE(max98373_codec_conf), 1056 .fully_routed = true, 1057 .late_probe = kabylake_card_late_probe, 1058 }; 1059 1060 static int kabylake_audio_probe(struct platform_device *pdev) 1061 { 1062 struct kbl_codec_private *ctx; 1063 struct snd_soc_dai_link *kbl_dai_link; 1064 struct snd_soc_dai_link_component **codecs; 1065 int i = 0; 1066 1067 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); 1068 if (!ctx) 1069 return -ENOMEM; 1070 1071 INIT_LIST_HEAD(&ctx->hdmi_pcm_list); 1072 1073 kabylake_audio_card = 1074 (struct snd_soc_card *)pdev->id_entry->driver_data; 1075 1076 kbl_dai_link = kabylake_audio_card->dai_link; 1077 1078 /* Update codecs for SSP0 with max98373 codec info */ 1079 if (!strcmp(pdev->name, "kbl_da7219_max98373") || 1080 (!strcmp(pdev->name, "kbl_max98373"))) { 1081 for (i = 0; i < kabylake_audio_card->num_links; ++i) { 1082 if (strcmp(kbl_dai_link[i].name, "SSP0-Codec")) 1083 continue; 1084 1085 codecs = &(kbl_dai_link[i].codecs); 1086 *codecs = max98373_ssp0_codec_components; 1087 kbl_dai_link[i].num_codecs = 1088 ARRAY_SIZE(max98373_ssp0_codec_components); 1089 break; 1090 } 1091 } 1092 kabylake_audio_card->dev = &pdev->dev; 1093 snd_soc_card_set_drvdata(kabylake_audio_card, ctx); 1094 1095 return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card); 1096 } 1097 1098 static const struct platform_device_id kbl_board_ids[] = { 1099 { 1100 .name = "kbl_da7219_max98927", 1101 .driver_data = 1102 (kernel_ulong_t)&kbl_audio_card_da7219_m98927, 1103 }, 1104 { 1105 .name = "kbl_max98927", 1106 .driver_data = 1107 (kernel_ulong_t)&kbl_audio_card_max98927, 1108 }, 1109 { 1110 .name = "kbl_da7219_max98373", 1111 .driver_data = 1112 (kernel_ulong_t)&kbl_audio_card_da7219_m98373, 1113 }, 1114 { 1115 .name = "kbl_max98373", 1116 .driver_data = 1117 (kernel_ulong_t)&kbl_audio_card_max98373, 1118 }, 1119 { } 1120 }; 1121 1122 static struct platform_driver kabylake_audio = { 1123 .probe = kabylake_audio_probe, 1124 .driver = { 1125 .name = "kbl_da7219_max98_927_373", 1126 .pm = &snd_soc_pm_ops, 1127 }, 1128 .id_table = kbl_board_ids, 1129 }; 1130 1131 module_platform_driver(kabylake_audio) 1132 1133 /* Module information */ 1134 MODULE_DESCRIPTION("Audio KabyLake Machine driver for MAX98927/MAX98373 & DA7219"); 1135 MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>"); 1136 MODULE_LICENSE("GPL v2"); 1137 MODULE_ALIAS("platform:kbl_da7219_max98927"); 1138 MODULE_ALIAS("platform:kbl_max98927"); 1139 MODULE_ALIAS("platform:kbl_da7219_max98373"); 1140 MODULE_ALIAS("platform:kbl_max98373"); 1141