1 /* 2 * Intel Skylake I2S Machine Driver 3 * 4 * Copyright (C) 2014-2015, Intel Corporation. All rights reserved. 5 * 6 * Modified from: 7 * Intel Broadwell Wildcatpoint SST Audio 8 * 9 * Copyright (C) 2013, Intel Corporation. All rights reserved. 10 * 11 * This program is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License version 13 * 2 as published by the Free Software Foundation. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 */ 20 21 #include <linux/module.h> 22 #include <linux/platform_device.h> 23 #include <sound/core.h> 24 #include <sound/pcm.h> 25 #include <sound/soc.h> 26 #include <sound/jack.h> 27 #include <sound/pcm_params.h> 28 #include "../../codecs/rt286.h" 29 #include "../../codecs/hdac_hdmi.h" 30 31 static struct snd_soc_jack skylake_headset; 32 static struct snd_soc_jack skylake_hdmi[3]; 33 34 struct skl_hdmi_pcm { 35 struct list_head head; 36 struct snd_soc_dai *codec_dai; 37 int device; 38 }; 39 40 struct skl_rt286_private { 41 struct list_head hdmi_pcm_list; 42 }; 43 44 enum { 45 SKL_DPCM_AUDIO_PB = 0, 46 SKL_DPCM_AUDIO_CP, 47 SKL_DPCM_AUDIO_REF_CP, 48 SKL_DPCM_AUDIO_DMIC_CP, 49 SKL_DPCM_AUDIO_HDMI1_PB, 50 SKL_DPCM_AUDIO_HDMI2_PB, 51 SKL_DPCM_AUDIO_HDMI3_PB, 52 }; 53 54 /* Headset jack detection DAPM pins */ 55 static struct snd_soc_jack_pin skylake_headset_pins[] = { 56 { 57 .pin = "Mic Jack", 58 .mask = SND_JACK_MICROPHONE, 59 }, 60 { 61 .pin = "Headphone Jack", 62 .mask = SND_JACK_HEADPHONE, 63 }, 64 }; 65 66 static const struct snd_kcontrol_new skylake_controls[] = { 67 SOC_DAPM_PIN_SWITCH("Speaker"), 68 SOC_DAPM_PIN_SWITCH("Headphone Jack"), 69 SOC_DAPM_PIN_SWITCH("Mic Jack"), 70 }; 71 72 static const struct snd_soc_dapm_widget skylake_widgets[] = { 73 SND_SOC_DAPM_HP("Headphone Jack", NULL), 74 SND_SOC_DAPM_SPK("Speaker", NULL), 75 SND_SOC_DAPM_MIC("Mic Jack", NULL), 76 SND_SOC_DAPM_MIC("DMIC2", NULL), 77 SND_SOC_DAPM_MIC("SoC DMIC", NULL), 78 SND_SOC_DAPM_SPK("HDMI1", NULL), 79 SND_SOC_DAPM_SPK("HDMI2", NULL), 80 SND_SOC_DAPM_SPK("HDMI3", NULL), 81 }; 82 83 static const struct snd_soc_dapm_route skylake_rt286_map[] = { 84 /* speaker */ 85 {"Speaker", NULL, "SPOR"}, 86 {"Speaker", NULL, "SPOL"}, 87 88 /* HP jack connectors - unknown if we have jack deteck */ 89 {"Headphone Jack", NULL, "HPO Pin"}, 90 91 /* other jacks */ 92 {"MIC1", NULL, "Mic Jack"}, 93 94 /* digital mics */ 95 {"DMIC1 Pin", NULL, "DMIC2"}, 96 {"DMic", NULL, "SoC DMIC"}, 97 98 /* CODEC BE connections */ 99 { "AIF1 Playback", NULL, "ssp0 Tx"}, 100 { "ssp0 Tx", NULL, "codec0_out"}, 101 { "ssp0 Tx", NULL, "codec1_out"}, 102 103 { "codec0_in", NULL, "ssp0 Rx" }, 104 { "codec1_in", NULL, "ssp0 Rx" }, 105 { "ssp0 Rx", NULL, "AIF1 Capture" }, 106 107 { "dmic01_hifi", NULL, "DMIC01 Rx" }, 108 { "DMIC01 Rx", NULL, "DMIC AIF" }, 109 110 { "hifi3", NULL, "iDisp3 Tx"}, 111 { "iDisp3 Tx", NULL, "iDisp3_out"}, 112 { "hifi2", NULL, "iDisp2 Tx"}, 113 { "iDisp2 Tx", NULL, "iDisp2_out"}, 114 { "hifi1", NULL, "iDisp1 Tx"}, 115 { "iDisp1 Tx", NULL, "iDisp1_out"}, 116 117 }; 118 119 static int skylake_rt286_fe_init(struct snd_soc_pcm_runtime *rtd) 120 { 121 struct snd_soc_dapm_context *dapm; 122 struct snd_soc_component *component = rtd->cpu_dai->component; 123 124 dapm = snd_soc_component_get_dapm(component); 125 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture"); 126 127 return 0; 128 } 129 130 static int skylake_rt286_codec_init(struct snd_soc_pcm_runtime *rtd) 131 { 132 struct snd_soc_codec *codec = rtd->codec; 133 int ret; 134 135 ret = snd_soc_card_jack_new(rtd->card, "Headset", 136 SND_JACK_HEADSET | SND_JACK_BTN_0, 137 &skylake_headset, 138 skylake_headset_pins, ARRAY_SIZE(skylake_headset_pins)); 139 140 if (ret) 141 return ret; 142 143 rt286_mic_detect(codec, &skylake_headset); 144 145 snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC"); 146 147 return 0; 148 } 149 150 static int skylake_hdmi_init(struct snd_soc_pcm_runtime *rtd) 151 { 152 struct skl_rt286_private *ctx = snd_soc_card_get_drvdata(rtd->card); 153 struct snd_soc_dai *dai = rtd->codec_dai; 154 struct skl_hdmi_pcm *pcm; 155 156 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL); 157 if (!pcm) 158 return -ENOMEM; 159 160 pcm->device = SKL_DPCM_AUDIO_HDMI1_PB + dai->id; 161 pcm->codec_dai = dai; 162 163 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list); 164 165 return 0; 166 } 167 168 static unsigned int rates[] = { 169 48000, 170 }; 171 172 static struct snd_pcm_hw_constraint_list constraints_rates = { 173 .count = ARRAY_SIZE(rates), 174 .list = rates, 175 .mask = 0, 176 }; 177 178 static unsigned int channels[] = { 179 2, 180 }; 181 182 static struct snd_pcm_hw_constraint_list constraints_channels = { 183 .count = ARRAY_SIZE(channels), 184 .list = channels, 185 .mask = 0, 186 }; 187 188 static int skl_fe_startup(struct snd_pcm_substream *substream) 189 { 190 struct snd_pcm_runtime *runtime = substream->runtime; 191 192 /* 193 * on this platform for PCM device we support, 194 * 48Khz 195 * stereo 196 * 16 bit audio 197 */ 198 199 runtime->hw.channels_max = 2; 200 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 201 &constraints_channels); 202 203 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; 204 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16); 205 206 snd_pcm_hw_constraint_list(runtime, 0, 207 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); 208 209 return 0; 210 } 211 212 static const struct snd_soc_ops skylake_rt286_fe_ops = { 213 .startup = skl_fe_startup, 214 }; 215 216 static int skylake_ssp0_fixup(struct snd_soc_pcm_runtime *rtd, 217 struct snd_pcm_hw_params *params) 218 { 219 struct snd_interval *rate = hw_param_interval(params, 220 SNDRV_PCM_HW_PARAM_RATE); 221 struct snd_interval *channels = hw_param_interval(params, 222 SNDRV_PCM_HW_PARAM_CHANNELS); 223 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 224 225 /* The output is 48KHz, stereo, 16bits */ 226 rate->min = rate->max = 48000; 227 channels->min = channels->max = 2; 228 229 /* set SSP0 to 24 bit */ 230 snd_mask_none(fmt); 231 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE); 232 return 0; 233 } 234 235 static int skylake_rt286_hw_params(struct snd_pcm_substream *substream, 236 struct snd_pcm_hw_params *params) 237 { 238 struct snd_soc_pcm_runtime *rtd = substream->private_data; 239 struct snd_soc_dai *codec_dai = rtd->codec_dai; 240 int ret; 241 242 ret = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000, 243 SND_SOC_CLOCK_IN); 244 if (ret < 0) 245 dev_err(rtd->dev, "set codec sysclk failed: %d\n", ret); 246 247 return ret; 248 } 249 250 static const struct snd_soc_ops skylake_rt286_ops = { 251 .hw_params = skylake_rt286_hw_params, 252 }; 253 254 static int skylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd, 255 struct snd_pcm_hw_params *params) 256 { 257 struct snd_interval *channels = hw_param_interval(params, 258 SNDRV_PCM_HW_PARAM_CHANNELS); 259 if (params_channels(params) == 2) 260 channels->min = channels->max = 2; 261 else 262 channels->min = channels->max = 4; 263 264 return 0; 265 } 266 267 static unsigned int channels_dmic[] = { 268 2, 4, 269 }; 270 271 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = { 272 .count = ARRAY_SIZE(channels_dmic), 273 .list = channels_dmic, 274 .mask = 0, 275 }; 276 277 static int skylake_dmic_startup(struct snd_pcm_substream *substream) 278 { 279 struct snd_pcm_runtime *runtime = substream->runtime; 280 281 runtime->hw.channels_max = 4; 282 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 283 &constraints_dmic_channels); 284 285 return snd_pcm_hw_constraint_list(substream->runtime, 0, 286 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); 287 } 288 289 static const struct snd_soc_ops skylake_dmic_ops = { 290 .startup = skylake_dmic_startup, 291 }; 292 293 /* skylake digital audio interface glue - connects codec <--> CPU */ 294 static struct snd_soc_dai_link skylake_rt286_dais[] = { 295 /* Front End DAI links */ 296 [SKL_DPCM_AUDIO_PB] = { 297 .name = "Skl Audio Port", 298 .stream_name = "Audio", 299 .cpu_dai_name = "System Pin", 300 .platform_name = "0000:00:1f.3", 301 .nonatomic = 1, 302 .dynamic = 1, 303 .codec_name = "snd-soc-dummy", 304 .codec_dai_name = "snd-soc-dummy-dai", 305 .init = skylake_rt286_fe_init, 306 .trigger = { 307 SND_SOC_DPCM_TRIGGER_POST, 308 SND_SOC_DPCM_TRIGGER_POST 309 }, 310 .dpcm_playback = 1, 311 .ops = &skylake_rt286_fe_ops, 312 }, 313 [SKL_DPCM_AUDIO_CP] = { 314 .name = "Skl Audio Capture Port", 315 .stream_name = "Audio Record", 316 .cpu_dai_name = "System Pin", 317 .platform_name = "0000:00:1f.3", 318 .nonatomic = 1, 319 .dynamic = 1, 320 .codec_name = "snd-soc-dummy", 321 .codec_dai_name = "snd-soc-dummy-dai", 322 .trigger = { 323 SND_SOC_DPCM_TRIGGER_POST, 324 SND_SOC_DPCM_TRIGGER_POST 325 }, 326 .dpcm_capture = 1, 327 .ops = &skylake_rt286_fe_ops, 328 }, 329 [SKL_DPCM_AUDIO_REF_CP] = { 330 .name = "Skl Audio Reference cap", 331 .stream_name = "refcap", 332 .cpu_dai_name = "Reference Pin", 333 .codec_name = "snd-soc-dummy", 334 .codec_dai_name = "snd-soc-dummy-dai", 335 .platform_name = "0000:00:1f.3", 336 .init = NULL, 337 .dpcm_capture = 1, 338 .nonatomic = 1, 339 .dynamic = 1, 340 }, 341 [SKL_DPCM_AUDIO_DMIC_CP] = { 342 .name = "Skl Audio DMIC cap", 343 .stream_name = "dmiccap", 344 .cpu_dai_name = "DMIC Pin", 345 .codec_name = "snd-soc-dummy", 346 .codec_dai_name = "snd-soc-dummy-dai", 347 .platform_name = "0000:00:1f.3", 348 .init = NULL, 349 .dpcm_capture = 1, 350 .nonatomic = 1, 351 .dynamic = 1, 352 .ops = &skylake_dmic_ops, 353 }, 354 [SKL_DPCM_AUDIO_HDMI1_PB] = { 355 .name = "Skl HDMI Port1", 356 .stream_name = "Hdmi1", 357 .cpu_dai_name = "HDMI1 Pin", 358 .codec_name = "snd-soc-dummy", 359 .codec_dai_name = "snd-soc-dummy-dai", 360 .platform_name = "0000:00:1f.3", 361 .dpcm_playback = 1, 362 .init = NULL, 363 .nonatomic = 1, 364 .dynamic = 1, 365 }, 366 [SKL_DPCM_AUDIO_HDMI2_PB] = { 367 .name = "Skl HDMI Port2", 368 .stream_name = "Hdmi2", 369 .cpu_dai_name = "HDMI2 Pin", 370 .codec_name = "snd-soc-dummy", 371 .codec_dai_name = "snd-soc-dummy-dai", 372 .platform_name = "0000:00:1f.3", 373 .dpcm_playback = 1, 374 .init = NULL, 375 .nonatomic = 1, 376 .dynamic = 1, 377 }, 378 [SKL_DPCM_AUDIO_HDMI3_PB] = { 379 .name = "Skl HDMI Port3", 380 .stream_name = "Hdmi3", 381 .cpu_dai_name = "HDMI3 Pin", 382 .codec_name = "snd-soc-dummy", 383 .codec_dai_name = "snd-soc-dummy-dai", 384 .platform_name = "0000:00:1f.3", 385 .dpcm_playback = 1, 386 .init = NULL, 387 .nonatomic = 1, 388 .dynamic = 1, 389 }, 390 391 /* Back End DAI links */ 392 { 393 /* SSP0 - Codec */ 394 .name = "SSP0-Codec", 395 .id = 0, 396 .cpu_dai_name = "SSP0 Pin", 397 .platform_name = "0000:00:1f.3", 398 .no_pcm = 1, 399 .codec_name = "i2c-INT343A:00", 400 .codec_dai_name = "rt286-aif1", 401 .init = skylake_rt286_codec_init, 402 .dai_fmt = SND_SOC_DAIFMT_I2S | 403 SND_SOC_DAIFMT_NB_NF | 404 SND_SOC_DAIFMT_CBS_CFS, 405 .ignore_pmdown_time = 1, 406 .be_hw_params_fixup = skylake_ssp0_fixup, 407 .ops = &skylake_rt286_ops, 408 .dpcm_playback = 1, 409 .dpcm_capture = 1, 410 }, 411 { 412 .name = "dmic01", 413 .id = 1, 414 .cpu_dai_name = "DMIC01 Pin", 415 .codec_name = "dmic-codec", 416 .codec_dai_name = "dmic-hifi", 417 .platform_name = "0000:00:1f.3", 418 .be_hw_params_fixup = skylake_dmic_fixup, 419 .ignore_suspend = 1, 420 .dpcm_capture = 1, 421 .no_pcm = 1, 422 }, 423 { 424 .name = "iDisp1", 425 .id = 2, 426 .cpu_dai_name = "iDisp1 Pin", 427 .codec_name = "ehdaudio0D2", 428 .codec_dai_name = "intel-hdmi-hifi1", 429 .platform_name = "0000:00:1f.3", 430 .init = skylake_hdmi_init, 431 .dpcm_playback = 1, 432 .no_pcm = 1, 433 }, 434 { 435 .name = "iDisp2", 436 .id = 3, 437 .cpu_dai_name = "iDisp2 Pin", 438 .codec_name = "ehdaudio0D2", 439 .codec_dai_name = "intel-hdmi-hifi2", 440 .platform_name = "0000:00:1f.3", 441 .init = skylake_hdmi_init, 442 .dpcm_playback = 1, 443 .no_pcm = 1, 444 }, 445 { 446 .name = "iDisp3", 447 .id = 4, 448 .cpu_dai_name = "iDisp3 Pin", 449 .codec_name = "ehdaudio0D2", 450 .codec_dai_name = "intel-hdmi-hifi3", 451 .platform_name = "0000:00:1f.3", 452 .init = skylake_hdmi_init, 453 .dpcm_playback = 1, 454 .no_pcm = 1, 455 }, 456 }; 457 458 #define NAME_SIZE 32 459 static int skylake_card_late_probe(struct snd_soc_card *card) 460 { 461 struct skl_rt286_private *ctx = snd_soc_card_get_drvdata(card); 462 struct skl_hdmi_pcm *pcm; 463 struct snd_soc_codec *codec = NULL; 464 int err, i = 0; 465 char jack_name[NAME_SIZE]; 466 467 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) { 468 codec = pcm->codec_dai->codec; 469 snprintf(jack_name, sizeof(jack_name), 470 "HDMI/DP, pcm=%d Jack", pcm->device); 471 err = snd_soc_card_jack_new(card, jack_name, 472 SND_JACK_AVOUT, &skylake_hdmi[i], 473 NULL, 0); 474 475 if (err) 476 return err; 477 478 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device, 479 &skylake_hdmi[i]); 480 if (err < 0) 481 return err; 482 483 i++; 484 } 485 486 if (!codec) 487 return -EINVAL; 488 489 return hdac_hdmi_jack_port_init(codec, &card->dapm); 490 } 491 492 /* skylake audio machine driver for SPT + RT286S */ 493 static struct snd_soc_card skylake_rt286 = { 494 .name = "skylake-rt286", 495 .owner = THIS_MODULE, 496 .dai_link = skylake_rt286_dais, 497 .num_links = ARRAY_SIZE(skylake_rt286_dais), 498 .controls = skylake_controls, 499 .num_controls = ARRAY_SIZE(skylake_controls), 500 .dapm_widgets = skylake_widgets, 501 .num_dapm_widgets = ARRAY_SIZE(skylake_widgets), 502 .dapm_routes = skylake_rt286_map, 503 .num_dapm_routes = ARRAY_SIZE(skylake_rt286_map), 504 .fully_routed = true, 505 .late_probe = skylake_card_late_probe, 506 }; 507 508 static int skylake_audio_probe(struct platform_device *pdev) 509 { 510 struct skl_rt286_private *ctx; 511 512 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC); 513 if (!ctx) 514 return -ENOMEM; 515 516 INIT_LIST_HEAD(&ctx->hdmi_pcm_list); 517 518 skylake_rt286.dev = &pdev->dev; 519 snd_soc_card_set_drvdata(&skylake_rt286, ctx); 520 521 return devm_snd_soc_register_card(&pdev->dev, &skylake_rt286); 522 } 523 524 static const struct platform_device_id skl_board_ids[] = { 525 { .name = "skl_alc286s_i2s" }, 526 { .name = "kbl_alc286s_i2s" }, 527 { } 528 }; 529 530 static struct platform_driver skylake_audio = { 531 .probe = skylake_audio_probe, 532 .driver = { 533 .name = "skl_alc286s_i2s", 534 .pm = &snd_soc_pm_ops, 535 }, 536 .id_table = skl_board_ids, 537 538 }; 539 540 module_platform_driver(skylake_audio) 541 542 /* Module information */ 543 MODULE_AUTHOR("Omair Mohammed Abdullah <omair.m.abdullah@intel.com>"); 544 MODULE_DESCRIPTION("Intel SST Audio for Skylake"); 545 MODULE_LICENSE("GPL v2"); 546 MODULE_ALIAS("platform:skl_alc286s_i2s"); 547 MODULE_ALIAS("platform:kbl_alc286s_i2s"); 548