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