1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Intel Kabylake I2S Machine Driver with MAXIM98927 4 * RT5514 and RT5663 Codecs 5 * 6 * Copyright (C) 2017, Intel Corporation. All rights reserved. 7 * 8 * Modified from: 9 * Intel Kabylake I2S Machine driver supporting MAXIM98927 and 10 * RT5663 codecs 11 */ 12 13 #include <linux/input.h> 14 #include <linux/module.h> 15 #include <linux/platform_device.h> 16 #include <sound/core.h> 17 #include <sound/jack.h> 18 #include <sound/pcm.h> 19 #include <sound/pcm_params.h> 20 #include <sound/soc.h> 21 #include <sound/soc-acpi.h> 22 #include "../../codecs/rt5514.h" 23 #include "../../codecs/rt5663.h" 24 #include "../../codecs/hdac_hdmi.h" 25 #include <linux/clk.h> 26 #include <linux/clk-provider.h> 27 #include <linux/clkdev.h> 28 29 #define KBL_REALTEK_CODEC_DAI "rt5663-aif" 30 #define KBL_REALTEK_DMIC_CODEC_DAI "rt5514-aif1" 31 #define KBL_MAXIM_CODEC_DAI "max98927-aif1" 32 #define MAXIM_DEV0_NAME "i2c-MX98927:00" 33 #define MAXIM_DEV1_NAME "i2c-MX98927:01" 34 #define RT5514_DEV_NAME "i2c-10EC5514:00" 35 #define RT5663_DEV_NAME "i2c-10EC5663:00" 36 #define RT5514_AIF1_BCLK_FREQ (48000 * 8 * 16) 37 #define RT5514_AIF1_SYSCLK_FREQ 12288000 38 #define NAME_SIZE 32 39 40 #define DMIC_CH(p) p->list[p->count-1] 41 42 43 static struct snd_soc_card kabylake_audio_card; 44 static const struct snd_pcm_hw_constraint_list *dmic_constraints; 45 46 struct kbl_hdmi_pcm { 47 struct list_head head; 48 struct snd_soc_dai *codec_dai; 49 int device; 50 }; 51 52 struct kbl_codec_private { 53 struct snd_soc_jack kabylake_headset; 54 struct list_head hdmi_pcm_list; 55 struct snd_soc_jack kabylake_hdmi[2]; 56 struct clk *mclk; 57 struct clk *sclk; 58 }; 59 60 enum { 61 KBL_DPCM_AUDIO_PB = 0, 62 KBL_DPCM_AUDIO_CP, 63 KBL_DPCM_AUDIO_HS_PB, 64 KBL_DPCM_AUDIO_ECHO_REF_CP, 65 KBL_DPCM_AUDIO_DMIC_CP, 66 KBL_DPCM_AUDIO_RT5514_DSP, 67 KBL_DPCM_AUDIO_HDMI1_PB, 68 KBL_DPCM_AUDIO_HDMI2_PB, 69 }; 70 71 static const struct snd_kcontrol_new kabylake_controls[] = { 72 SOC_DAPM_PIN_SWITCH("Headphone Jack"), 73 SOC_DAPM_PIN_SWITCH("Headset Mic"), 74 SOC_DAPM_PIN_SWITCH("Left Spk"), 75 SOC_DAPM_PIN_SWITCH("Right Spk"), 76 SOC_DAPM_PIN_SWITCH("DMIC"), 77 }; 78 79 static int platform_clock_control(struct snd_soc_dapm_widget *w, 80 struct snd_kcontrol *k, int event) 81 { 82 struct snd_soc_dapm_context *dapm = w->dapm; 83 struct snd_soc_card *card = dapm->card; 84 struct kbl_codec_private *priv = snd_soc_card_get_drvdata(card); 85 int ret = 0; 86 87 /* 88 * MCLK/SCLK need to be ON early for a successful synchronization of 89 * codec internal clock. And the clocks are turned off during 90 * POST_PMD after the stream is stopped. 91 */ 92 switch (event) { 93 case SND_SOC_DAPM_PRE_PMU: 94 /* Enable MCLK */ 95 ret = clk_set_rate(priv->mclk, 24000000); 96 if (ret < 0) { 97 dev_err(card->dev, "Can't set rate for mclk, err: %d\n", 98 ret); 99 return ret; 100 } 101 102 ret = clk_prepare_enable(priv->mclk); 103 if (ret < 0) { 104 dev_err(card->dev, "Can't enable mclk, err: %d\n", ret); 105 return ret; 106 } 107 108 /* Enable SCLK */ 109 ret = clk_set_rate(priv->sclk, 3072000); 110 if (ret < 0) { 111 dev_err(card->dev, "Can't set rate for sclk, err: %d\n", 112 ret); 113 clk_disable_unprepare(priv->mclk); 114 return ret; 115 } 116 117 ret = clk_prepare_enable(priv->sclk); 118 if (ret < 0) { 119 dev_err(card->dev, "Can't enable sclk, err: %d\n", ret); 120 clk_disable_unprepare(priv->mclk); 121 } 122 break; 123 case SND_SOC_DAPM_POST_PMD: 124 clk_disable_unprepare(priv->mclk); 125 clk_disable_unprepare(priv->sclk); 126 break; 127 default: 128 return 0; 129 } 130 131 return 0; 132 } 133 134 static const struct snd_soc_dapm_widget kabylake_widgets[] = { 135 SND_SOC_DAPM_HP("Headphone Jack", NULL), 136 SND_SOC_DAPM_MIC("Headset Mic", NULL), 137 SND_SOC_DAPM_SPK("Left Spk", NULL), 138 SND_SOC_DAPM_SPK("Right Spk", NULL), 139 SND_SOC_DAPM_MIC("DMIC", NULL), 140 SND_SOC_DAPM_SPK("HDMI1", NULL), 141 SND_SOC_DAPM_SPK("HDMI2", NULL), 142 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, 143 platform_clock_control, SND_SOC_DAPM_PRE_PMU | 144 SND_SOC_DAPM_POST_PMD), 145 146 }; 147 148 static const struct snd_soc_dapm_route kabylake_map[] = { 149 /* Headphones */ 150 { "Headphone Jack", NULL, "Platform Clock" }, 151 { "Headphone Jack", NULL, "HPOL" }, 152 { "Headphone Jack", NULL, "HPOR" }, 153 154 /* speaker */ 155 { "Left Spk", NULL, "Left BE_OUT" }, 156 { "Right Spk", NULL, "Right BE_OUT" }, 157 158 /* other jacks */ 159 { "Headset Mic", NULL, "Platform Clock" }, 160 { "IN1P", NULL, "Headset Mic" }, 161 { "IN1N", NULL, "Headset Mic" }, 162 163 /* CODEC BE connections */ 164 { "Left HiFi Playback", NULL, "ssp0 Tx" }, 165 { "Right HiFi Playback", NULL, "ssp0 Tx" }, 166 { "ssp0 Tx", NULL, "spk_out" }, 167 168 { "AIF Playback", NULL, "ssp1 Tx" }, 169 { "ssp1 Tx", NULL, "codec1_out" }, 170 171 { "hs_in", NULL, "ssp1 Rx" }, 172 { "ssp1 Rx", NULL, "AIF Capture" }, 173 174 { "codec1_in", NULL, "ssp0 Rx" }, 175 { "ssp0 Rx", NULL, "AIF1 Capture" }, 176 177 /* IV feedback path */ 178 { "codec0_fb_in", NULL, "ssp0 Rx"}, 179 { "ssp0 Rx", NULL, "Left HiFi Capture" }, 180 { "ssp0 Rx", NULL, "Right HiFi Capture" }, 181 182 /* DMIC */ 183 { "DMIC1L", NULL, "DMIC" }, 184 { "DMIC1R", NULL, "DMIC" }, 185 { "DMIC2L", NULL, "DMIC" }, 186 { "DMIC2R", NULL, "DMIC" }, 187 188 { "hifi2", NULL, "iDisp2 Tx" }, 189 { "iDisp2 Tx", NULL, "iDisp2_out" }, 190 { "hifi1", NULL, "iDisp1 Tx" }, 191 { "iDisp1 Tx", NULL, "iDisp1_out" }, 192 }; 193 194 static struct snd_soc_codec_conf max98927_codec_conf[] = { 195 { 196 .dlc = COMP_CODEC_CONF(MAXIM_DEV0_NAME), 197 .name_prefix = "Right", 198 }, 199 { 200 .dlc = COMP_CODEC_CONF(MAXIM_DEV1_NAME), 201 .name_prefix = "Left", 202 }, 203 }; 204 205 206 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd) 207 { 208 struct snd_soc_dapm_context *dapm; 209 struct snd_soc_component *component = asoc_rtd_to_cpu(rtd, 0)->component; 210 int ret; 211 212 dapm = snd_soc_component_get_dapm(component); 213 ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture"); 214 if (ret) 215 dev_err(rtd->dev, "Ref Cap -Ignore suspend failed = %d\n", ret); 216 217 return ret; 218 } 219 220 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd) 221 { 222 int ret; 223 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card); 224 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component; 225 struct snd_soc_jack *jack; 226 227 /* 228 * Headset buttons map to the google Reference headset. 229 * These can be configured by userspace. 230 */ 231 ret = snd_soc_card_jack_new(&kabylake_audio_card, "Headset Jack", 232 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 | 233 SND_JACK_BTN_2 | SND_JACK_BTN_3, &ctx->kabylake_headset, 234 NULL, 0); 235 if (ret) { 236 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret); 237 return ret; 238 } 239 240 jack = &ctx->kabylake_headset; 241 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); 242 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); 243 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); 244 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); 245 246 snd_soc_component_set_jack(component, &ctx->kabylake_headset, NULL); 247 248 ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "DMIC"); 249 if (ret) 250 dev_err(rtd->dev, "DMIC - Ignore suspend failed = %d\n", ret); 251 252 return ret; 253 } 254 255 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device) 256 { 257 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card); 258 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0); 259 struct kbl_hdmi_pcm *pcm; 260 261 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL); 262 if (!pcm) 263 return -ENOMEM; 264 265 pcm->device = device; 266 pcm->codec_dai = dai; 267 268 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list); 269 270 return 0; 271 } 272 273 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd) 274 { 275 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB); 276 } 277 278 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd) 279 { 280 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB); 281 } 282 283 static const unsigned int rates[] = { 284 48000, 285 }; 286 287 static const struct snd_pcm_hw_constraint_list constraints_rates = { 288 .count = ARRAY_SIZE(rates), 289 .list = rates, 290 .mask = 0, 291 }; 292 293 static const unsigned int channels[] = { 294 2, 295 }; 296 297 static const struct snd_pcm_hw_constraint_list constraints_channels = { 298 .count = ARRAY_SIZE(channels), 299 .list = channels, 300 .mask = 0, 301 }; 302 303 static int kbl_fe_startup(struct snd_pcm_substream *substream) 304 { 305 struct snd_pcm_runtime *runtime = substream->runtime; 306 307 /* 308 * On this platform for PCM device we support, 309 * 48Khz 310 * stereo 311 * 16 bit audio 312 */ 313 314 runtime->hw.channels_max = 2; 315 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 316 &constraints_channels); 317 318 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; 319 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16); 320 321 snd_pcm_hw_constraint_list(runtime, 0, 322 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); 323 324 return 0; 325 } 326 327 static const struct snd_soc_ops kabylake_rt5663_fe_ops = { 328 .startup = kbl_fe_startup, 329 }; 330 331 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd, 332 struct snd_pcm_hw_params *params) 333 { 334 struct snd_interval *rate = hw_param_interval(params, 335 SNDRV_PCM_HW_PARAM_RATE); 336 struct snd_interval *chan = hw_param_interval(params, 337 SNDRV_PCM_HW_PARAM_CHANNELS); 338 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 339 struct snd_soc_dpcm *dpcm = container_of( 340 params, struct snd_soc_dpcm, hw_params); 341 struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link; 342 struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link; 343 344 /* 345 * The ADSP will convert the FE rate to 48k, stereo, 24 bit 346 */ 347 if (!strcmp(fe_dai_link->name, "Kbl Audio Port") || 348 !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") || 349 !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) { 350 rate->min = rate->max = 48000; 351 chan->min = chan->max = 2; 352 snd_mask_none(fmt); 353 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE); 354 } else if (!strcmp(fe_dai_link->name, "Kbl Audio DMIC cap")) { 355 if (params_channels(params) == 2 || 356 DMIC_CH(dmic_constraints) == 2) 357 chan->min = chan->max = 2; 358 else 359 chan->min = chan->max = 4; 360 } 361 /* 362 * The speaker on the SSP0 supports S16_LE and not S24_LE. 363 * thus changing the mask here 364 */ 365 if (!strcmp(be_dai_link->name, "SSP0-Codec")) 366 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE); 367 368 return 0; 369 } 370 371 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream, 372 struct snd_pcm_hw_params *params) 373 { 374 struct snd_soc_pcm_runtime *rtd = substream->private_data; 375 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 376 int ret; 377 378 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */ 379 rt5663_sel_asrc_clk_src(codec_dai->component, 380 RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER, 381 RT5663_CLK_SEL_I2S1_ASRC); 382 383 ret = snd_soc_dai_set_sysclk(codec_dai, 384 RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN); 385 if (ret < 0) 386 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret); 387 388 return ret; 389 } 390 391 static struct snd_soc_ops kabylake_rt5663_ops = { 392 .hw_params = kabylake_rt5663_hw_params, 393 }; 394 395 static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream, 396 struct snd_pcm_hw_params *params) 397 { 398 struct snd_soc_pcm_runtime *rtd = substream->private_data; 399 struct snd_soc_dai *codec_dai; 400 int ret = 0, j; 401 402 for_each_rtd_codec_dais(rtd, j, codec_dai) { 403 if (!strcmp(codec_dai->component->name, RT5514_DEV_NAME)) { 404 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0, 8, 16); 405 if (ret < 0) { 406 dev_err(rtd->dev, "set TDM slot err:%d\n", ret); 407 return ret; 408 } 409 410 ret = snd_soc_dai_set_sysclk(codec_dai, 411 RT5514_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN); 412 if (ret < 0) { 413 dev_err(rtd->dev, "set sysclk err: %d\n", ret); 414 return ret; 415 } 416 } 417 if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) { 418 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16); 419 if (ret < 0) { 420 dev_err(rtd->dev, "DEV0 TDM slot err:%d\n", ret); 421 return ret; 422 } 423 } 424 425 if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) { 426 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16); 427 if (ret < 0) { 428 dev_err(rtd->dev, "DEV1 TDM slot err:%d\n", ret); 429 return ret; 430 } 431 } 432 } 433 return ret; 434 } 435 436 static struct snd_soc_ops kabylake_ssp0_ops = { 437 .hw_params = kabylake_ssp0_hw_params, 438 }; 439 440 static const unsigned int channels_dmic[] = { 441 4, 442 }; 443 444 static const struct snd_pcm_hw_constraint_list constraints_dmic_channels = { 445 .count = ARRAY_SIZE(channels_dmic), 446 .list = channels_dmic, 447 .mask = 0, 448 }; 449 450 static const unsigned int dmic_2ch[] = { 451 2, 452 }; 453 454 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = { 455 .count = ARRAY_SIZE(dmic_2ch), 456 .list = dmic_2ch, 457 .mask = 0, 458 }; 459 460 static int kabylake_dmic_startup(struct snd_pcm_substream *substream) 461 { 462 struct snd_pcm_runtime *runtime = substream->runtime; 463 464 runtime->hw.channels_max = DMIC_CH(dmic_constraints); 465 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 466 dmic_constraints); 467 468 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; 469 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16); 470 471 return snd_pcm_hw_constraint_list(substream->runtime, 0, 472 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); 473 } 474 475 static struct snd_soc_ops kabylake_dmic_ops = { 476 .startup = kabylake_dmic_startup, 477 }; 478 479 SND_SOC_DAILINK_DEF(dummy, 480 DAILINK_COMP_ARRAY(COMP_DUMMY())); 481 482 SND_SOC_DAILINK_DEF(system, 483 DAILINK_COMP_ARRAY(COMP_CPU("System Pin"))); 484 485 SND_SOC_DAILINK_DEF(system2, 486 DAILINK_COMP_ARRAY(COMP_CPU("System Pin2"))); 487 488 SND_SOC_DAILINK_DEF(echoref, 489 DAILINK_COMP_ARRAY(COMP_CPU("Echoref Pin"))); 490 491 SND_SOC_DAILINK_DEF(spi_cpu, 492 DAILINK_COMP_ARRAY(COMP_CPU("spi-PRP0001:00"))); 493 SND_SOC_DAILINK_DEF(spi_platform, 494 DAILINK_COMP_ARRAY(COMP_PLATFORM("spi-PRP0001:00"))); 495 496 SND_SOC_DAILINK_DEF(dmic, 497 DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin"))); 498 499 SND_SOC_DAILINK_DEF(hdmi1, 500 DAILINK_COMP_ARRAY(COMP_CPU("HDMI1 Pin"))); 501 502 SND_SOC_DAILINK_DEF(hdmi2, 503 DAILINK_COMP_ARRAY(COMP_CPU("HDMI2 Pin"))); 504 505 SND_SOC_DAILINK_DEF(ssp0_pin, 506 DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin"))); 507 SND_SOC_DAILINK_DEF(ssp0_codec, 508 DAILINK_COMP_ARRAY( 509 /* Left */ COMP_CODEC(MAXIM_DEV0_NAME, KBL_MAXIM_CODEC_DAI), 510 /* Right */COMP_CODEC(MAXIM_DEV1_NAME, KBL_MAXIM_CODEC_DAI), 511 /* dmic */ COMP_CODEC(RT5514_DEV_NAME, KBL_REALTEK_DMIC_CODEC_DAI))); 512 513 SND_SOC_DAILINK_DEF(ssp1_pin, 514 DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin"))); 515 SND_SOC_DAILINK_DEF(ssp1_codec, 516 DAILINK_COMP_ARRAY(COMP_CODEC(RT5663_DEV_NAME, KBL_REALTEK_CODEC_DAI))); 517 518 SND_SOC_DAILINK_DEF(idisp1_pin, 519 DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin"))); 520 SND_SOC_DAILINK_DEF(idisp1_codec, 521 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1"))); 522 523 SND_SOC_DAILINK_DEF(idisp2_pin, 524 DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin"))); 525 SND_SOC_DAILINK_DEF(idisp2_codec, 526 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2"))); 527 528 SND_SOC_DAILINK_DEF(platform, 529 DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3"))); 530 531 /* kabylake digital audio interface glue - connects codec <--> CPU */ 532 static struct snd_soc_dai_link kabylake_dais[] = { 533 /* Front End DAI links */ 534 [KBL_DPCM_AUDIO_PB] = { 535 .name = "Kbl Audio Port", 536 .stream_name = "Audio", 537 .dynamic = 1, 538 .nonatomic = 1, 539 .init = kabylake_rt5663_fe_init, 540 .trigger = { 541 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 542 .dpcm_playback = 1, 543 .ops = &kabylake_rt5663_fe_ops, 544 SND_SOC_DAILINK_REG(system, dummy, platform), 545 }, 546 [KBL_DPCM_AUDIO_CP] = { 547 .name = "Kbl Audio Capture Port", 548 .stream_name = "Audio Record", 549 .dynamic = 1, 550 .nonatomic = 1, 551 .trigger = { 552 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 553 .dpcm_capture = 1, 554 .ops = &kabylake_rt5663_fe_ops, 555 SND_SOC_DAILINK_REG(system, dummy, platform), 556 }, 557 [KBL_DPCM_AUDIO_HS_PB] = { 558 .name = "Kbl Audio Headset Playback", 559 .stream_name = "Headset Audio", 560 .dpcm_playback = 1, 561 .nonatomic = 1, 562 .dynamic = 1, 563 SND_SOC_DAILINK_REG(system2, dummy, platform), 564 }, 565 [KBL_DPCM_AUDIO_ECHO_REF_CP] = { 566 .name = "Kbl Audio Echo Reference cap", 567 .stream_name = "Echoreference Capture", 568 .init = NULL, 569 .capture_only = 1, 570 .nonatomic = 1, 571 SND_SOC_DAILINK_REG(echoref, dummy, platform), 572 }, 573 [KBL_DPCM_AUDIO_RT5514_DSP] = { 574 .name = "rt5514 dsp", 575 .stream_name = "Wake on Voice", 576 SND_SOC_DAILINK_REG(spi_cpu, dummy, spi_platform), 577 }, 578 [KBL_DPCM_AUDIO_DMIC_CP] = { 579 .name = "Kbl Audio DMIC cap", 580 .stream_name = "dmiccap", 581 .init = NULL, 582 .dpcm_capture = 1, 583 .nonatomic = 1, 584 .dynamic = 1, 585 .ops = &kabylake_dmic_ops, 586 SND_SOC_DAILINK_REG(dmic, dummy, platform), 587 }, 588 [KBL_DPCM_AUDIO_HDMI1_PB] = { 589 .name = "Kbl HDMI Port1", 590 .stream_name = "Hdmi1", 591 .dpcm_playback = 1, 592 .init = NULL, 593 .trigger = { 594 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 595 .nonatomic = 1, 596 .dynamic = 1, 597 SND_SOC_DAILINK_REG(hdmi1, dummy, platform), 598 }, 599 [KBL_DPCM_AUDIO_HDMI2_PB] = { 600 .name = "Kbl HDMI Port2", 601 .stream_name = "Hdmi2", 602 .dpcm_playback = 1, 603 .init = NULL, 604 .trigger = { 605 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 606 .nonatomic = 1, 607 .dynamic = 1, 608 SND_SOC_DAILINK_REG(hdmi2, dummy, platform), 609 }, 610 /* Back End DAI links */ 611 /* single Back end dai for both max speakers and dmic */ 612 { 613 /* SSP0 - Codec */ 614 .name = "SSP0-Codec", 615 .id = 0, 616 .no_pcm = 1, 617 .dai_fmt = SND_SOC_DAIFMT_DSP_B | 618 SND_SOC_DAIFMT_NB_NF | 619 SND_SOC_DAIFMT_CBS_CFS, 620 .ignore_pmdown_time = 1, 621 .be_hw_params_fixup = kabylake_ssp_fixup, 622 .dpcm_playback = 1, 623 .dpcm_capture = 1, 624 .ops = &kabylake_ssp0_ops, 625 SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform), 626 }, 627 { 628 .name = "SSP1-Codec", 629 .id = 1, 630 .no_pcm = 1, 631 .init = kabylake_rt5663_codec_init, 632 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 633 SND_SOC_DAIFMT_CBS_CFS, 634 .ignore_pmdown_time = 1, 635 .be_hw_params_fixup = kabylake_ssp_fixup, 636 .ops = &kabylake_rt5663_ops, 637 .dpcm_playback = 1, 638 .dpcm_capture = 1, 639 SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec, platform), 640 }, 641 { 642 .name = "iDisp1", 643 .id = 3, 644 .dpcm_playback = 1, 645 .init = kabylake_hdmi1_init, 646 .no_pcm = 1, 647 SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform), 648 }, 649 { 650 .name = "iDisp2", 651 .id = 4, 652 .init = kabylake_hdmi2_init, 653 .dpcm_playback = 1, 654 .no_pcm = 1, 655 SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform), 656 }, 657 }; 658 659 static int kabylake_set_bias_level(struct snd_soc_card *card, 660 struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level) 661 { 662 struct snd_soc_component *component = dapm->component; 663 struct kbl_codec_private *priv = snd_soc_card_get_drvdata(card); 664 int ret = 0; 665 666 if (!component || strcmp(component->name, RT5514_DEV_NAME)) 667 return 0; 668 669 if (IS_ERR(priv->mclk)) 670 return 0; 671 672 /* 673 * It's required to control mclk directly in the set_bias_level 674 * function for rt5514 codec or the recording function could 675 * break. 676 */ 677 switch (level) { 678 case SND_SOC_BIAS_PREPARE: 679 if (dapm->bias_level == SND_SOC_BIAS_ON) { 680 dev_dbg(card->dev, "Disable mclk"); 681 clk_disable_unprepare(priv->mclk); 682 } else { 683 dev_dbg(card->dev, "Enable mclk"); 684 ret = clk_set_rate(priv->mclk, 24000000); 685 if (ret) { 686 dev_err(card->dev, "Can't set rate for mclk, err: %d\n", 687 ret); 688 return ret; 689 } 690 691 ret = clk_prepare_enable(priv->mclk); 692 if (ret) { 693 dev_err(card->dev, "Can't enable mclk, err: %d\n", 694 ret); 695 696 /* mclk is already enabled in FW */ 697 ret = 0; 698 } 699 } 700 break; 701 default: 702 break; 703 } 704 705 return ret; 706 } 707 708 static int kabylake_card_late_probe(struct snd_soc_card *card) 709 { 710 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card); 711 struct kbl_hdmi_pcm *pcm; 712 struct snd_soc_component *component = NULL; 713 int err, i = 0; 714 char jack_name[NAME_SIZE]; 715 716 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) { 717 component = pcm->codec_dai->component; 718 snprintf(jack_name, sizeof(jack_name), 719 "HDMI/DP,pcm=%d Jack", pcm->device); 720 err = snd_soc_card_jack_new(card, jack_name, 721 SND_JACK_AVOUT, &ctx->kabylake_hdmi[i], 722 NULL, 0); 723 724 if (err) 725 return err; 726 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device, 727 &ctx->kabylake_hdmi[i]); 728 if (err < 0) 729 return err; 730 i++; 731 } 732 733 if (!component) 734 return -EINVAL; 735 736 return hdac_hdmi_jack_port_init(component, &card->dapm); 737 } 738 739 /* 740 * kabylake audio machine driver for MAX98927 + RT5514 + RT5663 741 */ 742 static struct snd_soc_card kabylake_audio_card = { 743 .name = "kbl-r5514-5663-max", 744 .owner = THIS_MODULE, 745 .dai_link = kabylake_dais, 746 .num_links = ARRAY_SIZE(kabylake_dais), 747 .set_bias_level = kabylake_set_bias_level, 748 .controls = kabylake_controls, 749 .num_controls = ARRAY_SIZE(kabylake_controls), 750 .dapm_widgets = kabylake_widgets, 751 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets), 752 .dapm_routes = kabylake_map, 753 .num_dapm_routes = ARRAY_SIZE(kabylake_map), 754 .codec_conf = max98927_codec_conf, 755 .num_configs = ARRAY_SIZE(max98927_codec_conf), 756 .fully_routed = true, 757 .late_probe = kabylake_card_late_probe, 758 }; 759 760 static int kabylake_audio_probe(struct platform_device *pdev) 761 { 762 struct kbl_codec_private *ctx; 763 struct snd_soc_acpi_mach *mach; 764 int ret; 765 766 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); 767 if (!ctx) 768 return -ENOMEM; 769 770 INIT_LIST_HEAD(&ctx->hdmi_pcm_list); 771 772 kabylake_audio_card.dev = &pdev->dev; 773 snd_soc_card_set_drvdata(&kabylake_audio_card, ctx); 774 775 mach = pdev->dev.platform_data; 776 if (mach) 777 dmic_constraints = mach->mach_params.dmic_num == 2 ? 778 &constraints_dmic_2ch : &constraints_dmic_channels; 779 780 ctx->mclk = devm_clk_get(&pdev->dev, "ssp1_mclk"); 781 if (IS_ERR(ctx->mclk)) { 782 ret = PTR_ERR(ctx->mclk); 783 if (ret == -ENOENT) { 784 dev_info(&pdev->dev, 785 "Failed to get ssp1_mclk, defer probe\n"); 786 return -EPROBE_DEFER; 787 } 788 789 dev_err(&pdev->dev, "Failed to get ssp1_mclk with err:%d\n", 790 ret); 791 return ret; 792 } 793 794 ctx->sclk = devm_clk_get(&pdev->dev, "ssp1_sclk"); 795 if (IS_ERR(ctx->sclk)) { 796 ret = PTR_ERR(ctx->sclk); 797 if (ret == -ENOENT) { 798 dev_info(&pdev->dev, 799 "Failed to get ssp1_sclk, defer probe\n"); 800 return -EPROBE_DEFER; 801 } 802 803 dev_err(&pdev->dev, "Failed to get ssp1_sclk with err:%d\n", 804 ret); 805 return ret; 806 } 807 808 return devm_snd_soc_register_card(&pdev->dev, &kabylake_audio_card); 809 } 810 811 static const struct platform_device_id kbl_board_ids[] = { 812 { .name = "kbl_r5514_5663_max" }, 813 { } 814 }; 815 816 static struct platform_driver kabylake_audio = { 817 .probe = kabylake_audio_probe, 818 .driver = { 819 .name = "kbl_r5514_5663_max", 820 .pm = &snd_soc_pm_ops, 821 }, 822 .id_table = kbl_board_ids, 823 }; 824 825 module_platform_driver(kabylake_audio) 826 827 /* Module information */ 828 MODULE_DESCRIPTION("Audio Machine driver-RT5663 RT5514 & MAX98927"); 829 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>"); 830 MODULE_LICENSE("GPL v2"); 831 MODULE_ALIAS("platform:kbl_r5514_5663_max"); 832