1 // SPDX-License-Identifier: GPL-2.0-only 2 // Copyright (c) 2020 Intel Corporation 3 4 /* 5 * sof_sdw - ASOC Machine driver for Intel SoundWire platforms 6 */ 7 8 #include <linux/acpi.h> 9 #include <linux/bitmap.h> 10 #include <linux/device.h> 11 #include <linux/dmi.h> 12 #include <linux/module.h> 13 #include <linux/soundwire/sdw.h> 14 #include <linux/soundwire/sdw_type.h> 15 #include <linux/soundwire/sdw_intel.h> 16 #include <sound/core.h> 17 #include <sound/soc-acpi.h> 18 #include "sof_sdw_common.h" 19 #include "../../codecs/rt711.h" 20 21 static unsigned long sof_sdw_quirk = RT711_JD1; 22 static int quirk_override = -1; 23 module_param_named(quirk, quirk_override, int, 0444); 24 MODULE_PARM_DESC(quirk, "Board-specific quirk override"); 25 26 #define DMIC_DEFAULT_CHANNELS 2 27 28 static void log_quirks(struct device *dev) 29 { 30 if (SOC_SDW_JACK_JDSRC(sof_sdw_quirk)) 31 dev_dbg(dev, "quirk realtek,jack-detect-source %ld\n", 32 SOC_SDW_JACK_JDSRC(sof_sdw_quirk)); 33 if (sof_sdw_quirk & SOC_SDW_FOUR_SPK) 34 dev_err(dev, "quirk SOC_SDW_FOUR_SPK enabled but no longer supported\n"); 35 if (sof_sdw_quirk & SOF_SDW_TGL_HDMI) 36 dev_dbg(dev, "quirk SOF_SDW_TGL_HDMI enabled\n"); 37 if (sof_sdw_quirk & SOC_SDW_PCH_DMIC) 38 dev_dbg(dev, "quirk SOC_SDW_PCH_DMIC enabled\n"); 39 if (SOF_SSP_GET_PORT(sof_sdw_quirk)) 40 dev_dbg(dev, "SSP port %ld\n", 41 SOF_SSP_GET_PORT(sof_sdw_quirk)); 42 if (sof_sdw_quirk & SOC_SDW_NO_AGGREGATION) 43 dev_err(dev, "quirk SOC_SDW_NO_AGGREGATION enabled but no longer supported\n"); 44 if (sof_sdw_quirk & SOC_SDW_CODEC_SPKR) 45 dev_dbg(dev, "quirk SOC_SDW_CODEC_SPKR enabled\n"); 46 if (sof_sdw_quirk & SOC_SDW_SIDECAR_AMPS) 47 dev_dbg(dev, "quirk SOC_SDW_SIDECAR_AMPS enabled\n"); 48 if (sof_sdw_quirk & SOC_SDW_CODEC_MIC) 49 dev_dbg(dev, "quirk SOC_SDW_CODEC_MIC enabled\n"); 50 } 51 52 static int sof_sdw_quirk_cb(const struct dmi_system_id *id) 53 { 54 sof_sdw_quirk = (unsigned long)id->driver_data; 55 return 1; 56 } 57 58 static const struct dmi_system_id sof_sdw_quirk_table[] = { 59 /* CometLake devices */ 60 { 61 .callback = sof_sdw_quirk_cb, 62 .matches = { 63 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"), 64 DMI_MATCH(DMI_PRODUCT_NAME, "CometLake Client"), 65 }, 66 .driver_data = (void *)SOC_SDW_PCH_DMIC, 67 }, 68 { 69 .callback = sof_sdw_quirk_cb, 70 .matches = { 71 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 72 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "09C6") 73 }, 74 .driver_data = (void *)RT711_JD2, 75 }, 76 { 77 /* early version of SKU 09C6 */ 78 .callback = sof_sdw_quirk_cb, 79 .matches = { 80 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 81 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0983") 82 }, 83 .driver_data = (void *)RT711_JD2, 84 }, 85 { 86 .callback = sof_sdw_quirk_cb, 87 .matches = { 88 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 89 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "098F"), 90 }, 91 .driver_data = (void *)(RT711_JD2), 92 }, 93 { 94 .callback = sof_sdw_quirk_cb, 95 .matches = { 96 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 97 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0990"), 98 }, 99 .driver_data = (void *)(RT711_JD2), 100 }, 101 /* IceLake devices */ 102 { 103 .callback = sof_sdw_quirk_cb, 104 .matches = { 105 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"), 106 DMI_MATCH(DMI_PRODUCT_NAME, "Ice Lake Client"), 107 }, 108 .driver_data = (void *)SOC_SDW_PCH_DMIC, 109 }, 110 /* TigerLake devices */ 111 { 112 .callback = sof_sdw_quirk_cb, 113 .matches = { 114 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"), 115 DMI_MATCH(DMI_PRODUCT_NAME, 116 "Tiger Lake Client Platform"), 117 }, 118 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 119 RT711_JD1 | 120 SOC_SDW_PCH_DMIC | 121 SOF_SSP_PORT(SOF_I2S_SSP2)), 122 }, 123 { 124 .callback = sof_sdw_quirk_cb, 125 .matches = { 126 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 127 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0A3E") 128 }, 129 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 130 RT711_JD2), 131 }, 132 { 133 /* another SKU of Dell Latitude 9520 */ 134 .callback = sof_sdw_quirk_cb, 135 .matches = { 136 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 137 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0A3F") 138 }, 139 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 140 RT711_JD2), 141 }, 142 { 143 /* Dell XPS 9710 */ 144 .callback = sof_sdw_quirk_cb, 145 .matches = { 146 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 147 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0A5D") 148 }, 149 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 150 RT711_JD2), 151 }, 152 { 153 .callback = sof_sdw_quirk_cb, 154 .matches = { 155 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 156 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0A5E") 157 }, 158 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 159 RT711_JD2), 160 }, 161 { 162 .callback = sof_sdw_quirk_cb, 163 .matches = { 164 DMI_MATCH(DMI_SYS_VENDOR, "Google"), 165 DMI_MATCH(DMI_PRODUCT_NAME, "Volteer"), 166 }, 167 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 168 SOC_SDW_PCH_DMIC | 169 SOF_BT_OFFLOAD_SSP(2) | 170 SOF_SSP_BT_OFFLOAD_PRESENT), 171 }, 172 { 173 .callback = sof_sdw_quirk_cb, 174 .matches = { 175 DMI_MATCH(DMI_SYS_VENDOR, "Google"), 176 DMI_MATCH(DMI_PRODUCT_NAME, "Ripto"), 177 }, 178 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 179 SOC_SDW_PCH_DMIC), 180 }, 181 { 182 /* 183 * this entry covers multiple HP SKUs. The family name 184 * does not seem robust enough, so we use a partial 185 * match that ignores the product name suffix 186 * (e.g. 15-eb1xxx, 14t-ea000 or 13-aw2xxx) 187 */ 188 .callback = sof_sdw_quirk_cb, 189 .matches = { 190 DMI_MATCH(DMI_SYS_VENDOR, "HP"), 191 DMI_MATCH(DMI_PRODUCT_NAME, "HP Spectre x360 Conv"), 192 }, 193 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 194 SOC_SDW_PCH_DMIC | 195 RT711_JD1), 196 }, 197 { 198 /* 199 * this entry covers HP Spectre x360 where the DMI information 200 * changed somehow 201 */ 202 .callback = sof_sdw_quirk_cb, 203 .matches = { 204 DMI_MATCH(DMI_SYS_VENDOR, "HP"), 205 DMI_MATCH(DMI_BOARD_NAME, "8709"), 206 }, 207 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 208 SOC_SDW_PCH_DMIC | 209 RT711_JD1), 210 }, 211 { 212 /* NUC15 'Bishop County' LAPBC510 and LAPBC710 skews */ 213 .callback = sof_sdw_quirk_cb, 214 .matches = { 215 DMI_MATCH(DMI_SYS_VENDOR, "Intel(R) Client Systems"), 216 DMI_MATCH(DMI_PRODUCT_NAME, "LAPBC"), 217 }, 218 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 219 SOC_SDW_PCH_DMIC | 220 RT711_JD1), 221 }, 222 { 223 /* NUC15 LAPBC710 skews */ 224 .callback = sof_sdw_quirk_cb, 225 .matches = { 226 DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"), 227 DMI_MATCH(DMI_BOARD_NAME, "LAPBC710"), 228 }, 229 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 230 SOC_SDW_PCH_DMIC | 231 RT711_JD1), 232 }, 233 { 234 /* 235 * Avell B.ON (OEM rebrand of NUC15 'Bishop County' LAPBC510 and 236 * LAPBC710) 237 */ 238 .callback = sof_sdw_quirk_cb, 239 .matches = { 240 DMI_MATCH(DMI_SYS_VENDOR, "Avell High Performance"), 241 DMI_MATCH(DMI_PRODUCT_NAME, "B.ON"), 242 }, 243 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 244 SOC_SDW_PCH_DMIC | 245 RT711_JD1), 246 }, 247 { 248 /* NUC15 'Rooks County' LAPRC510 and LAPRC710 skews */ 249 .callback = sof_sdw_quirk_cb, 250 .matches = { 251 DMI_MATCH(DMI_SYS_VENDOR, "Intel(R) Client Systems"), 252 DMI_MATCH(DMI_PRODUCT_NAME, "LAPRC"), 253 }, 254 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 255 SOC_SDW_PCH_DMIC | 256 RT711_JD2_100K), 257 }, 258 { 259 /* NUC15 LAPRC710 skews */ 260 .callback = sof_sdw_quirk_cb, 261 .matches = { 262 DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"), 263 DMI_MATCH(DMI_BOARD_NAME, "LAPRC710"), 264 }, 265 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 266 SOC_SDW_PCH_DMIC | 267 RT711_JD2_100K), 268 }, 269 /* TigerLake-SDCA devices */ 270 { 271 .callback = sof_sdw_quirk_cb, 272 .matches = { 273 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 274 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0A32") 275 }, 276 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 277 RT711_JD2), 278 }, 279 { 280 .callback = sof_sdw_quirk_cb, 281 .matches = { 282 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 283 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0A45") 284 }, 285 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 286 RT711_JD2), 287 }, 288 /* AlderLake devices */ 289 { 290 .callback = sof_sdw_quirk_cb, 291 .matches = { 292 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"), 293 DMI_MATCH(DMI_PRODUCT_NAME, "Alder Lake Client Platform"), 294 }, 295 .driver_data = (void *)(RT711_JD2_100K | 296 SOF_SDW_TGL_HDMI | 297 SOF_BT_OFFLOAD_SSP(2) | 298 SOF_SSP_BT_OFFLOAD_PRESENT), 299 }, 300 { 301 .callback = sof_sdw_quirk_cb, 302 .matches = { 303 DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"), 304 DMI_MATCH(DMI_PRODUCT_SKU, "0000000000070000"), 305 }, 306 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 307 RT711_JD2_100K), 308 }, 309 { 310 .callback = sof_sdw_quirk_cb, 311 .matches = { 312 DMI_MATCH(DMI_SYS_VENDOR, "Google"), 313 DMI_MATCH(DMI_PRODUCT_NAME, "Brya"), 314 }, 315 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 316 SOC_SDW_PCH_DMIC | 317 SOF_BT_OFFLOAD_SSP(2) | 318 SOF_SSP_BT_OFFLOAD_PRESENT), 319 }, 320 { 321 .callback = sof_sdw_quirk_cb, 322 .matches = { 323 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 324 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0AF0") 325 }, 326 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 327 RT711_JD2), 328 }, 329 { 330 .callback = sof_sdw_quirk_cb, 331 .matches = { 332 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 333 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0AF3"), 334 }, 335 /* No Jack */ 336 .driver_data = (void *)(SOF_SDW_TGL_HDMI), 337 }, 338 { 339 .callback = sof_sdw_quirk_cb, 340 .matches = { 341 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 342 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0AFE") 343 }, 344 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 345 RT711_JD2), 346 }, 347 { 348 .callback = sof_sdw_quirk_cb, 349 .matches = { 350 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 351 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0AFF") 352 }, 353 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 354 RT711_JD2), 355 }, 356 { 357 .callback = sof_sdw_quirk_cb, 358 .matches = { 359 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 360 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B00") 361 }, 362 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 363 RT711_JD2), 364 }, 365 { 366 .callback = sof_sdw_quirk_cb, 367 .matches = { 368 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 369 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B01") 370 }, 371 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 372 RT711_JD2), 373 }, 374 { 375 .callback = sof_sdw_quirk_cb, 376 .matches = { 377 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 378 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B11") 379 }, 380 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 381 RT711_JD2), 382 }, 383 { 384 .callback = sof_sdw_quirk_cb, 385 .matches = { 386 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 387 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B12") 388 }, 389 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 390 RT711_JD2), 391 }, 392 { 393 .callback = sof_sdw_quirk_cb, 394 .matches = { 395 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 396 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B13"), 397 }, 398 /* No Jack */ 399 .driver_data = (void *)SOF_SDW_TGL_HDMI, 400 }, 401 { 402 .callback = sof_sdw_quirk_cb, 403 .matches = { 404 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 405 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B14"), 406 }, 407 /* No Jack */ 408 .driver_data = (void *)SOF_SDW_TGL_HDMI, 409 }, 410 411 { 412 .callback = sof_sdw_quirk_cb, 413 .matches = { 414 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 415 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B29"), 416 }, 417 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 418 RT711_JD2), 419 }, 420 { 421 .callback = sof_sdw_quirk_cb, 422 .matches = { 423 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 424 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B34"), 425 }, 426 /* No Jack */ 427 .driver_data = (void *)SOF_SDW_TGL_HDMI, 428 }, 429 { 430 .callback = sof_sdw_quirk_cb, 431 .matches = { 432 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 433 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B8C"), 434 }, 435 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 436 RT711_JD2), 437 }, 438 { 439 .callback = sof_sdw_quirk_cb, 440 .matches = { 441 DMI_MATCH(DMI_SYS_VENDOR, "HP"), 442 DMI_MATCH(DMI_PRODUCT_NAME, "OMEN by HP Gaming Laptop 16"), 443 }, 444 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 445 RT711_JD2), 446 }, 447 /* RaptorLake devices */ 448 { 449 .callback = sof_sdw_quirk_cb, 450 .matches = { 451 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 452 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0BDA") 453 }, 454 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 455 RT711_JD2), 456 }, 457 { 458 .callback = sof_sdw_quirk_cb, 459 .matches = { 460 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 461 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0C0F") 462 }, 463 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 464 RT711_JD2), 465 }, 466 { 467 .callback = sof_sdw_quirk_cb, 468 .matches = { 469 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 470 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0C10"), 471 }, 472 /* No Jack */ 473 .driver_data = (void *)(SOF_SDW_TGL_HDMI), 474 }, 475 { 476 .callback = sof_sdw_quirk_cb, 477 .matches = { 478 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 479 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0C11") 480 }, 481 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 482 RT711_JD2), 483 }, 484 { 485 .callback = sof_sdw_quirk_cb, 486 .matches = { 487 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 488 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0C40") 489 }, 490 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 491 RT711_JD2), 492 }, 493 { 494 .callback = sof_sdw_quirk_cb, 495 .matches = { 496 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 497 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0C4F") 498 }, 499 .driver_data = (void *)(SOF_SDW_TGL_HDMI | 500 RT711_JD2), 501 }, 502 { 503 .callback = sof_sdw_quirk_cb, 504 .matches = { 505 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 506 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CF6") 507 }, 508 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 509 }, 510 { 511 .callback = sof_sdw_quirk_cb, 512 .matches = { 513 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 514 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CF9") 515 }, 516 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 517 }, 518 { 519 .callback = sof_sdw_quirk_cb, 520 .matches = { 521 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 522 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CFA") 523 }, 524 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 525 }, 526 /* MeteorLake devices */ 527 { 528 .callback = sof_sdw_quirk_cb, 529 .matches = { 530 DMI_MATCH(DMI_PRODUCT_FAMILY, "Intel_mtlrvp"), 531 }, 532 .driver_data = (void *)(RT711_JD1), 533 }, 534 { 535 .callback = sof_sdw_quirk_cb, 536 .matches = { 537 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"), 538 DMI_MATCH(DMI_PRODUCT_NAME, "Meteor Lake Client Platform"), 539 }, 540 .driver_data = (void *)(RT711_JD2_100K), 541 }, 542 { 543 .callback = sof_sdw_quirk_cb, 544 .matches = { 545 DMI_MATCH(DMI_SYS_VENDOR, "Google"), 546 DMI_MATCH(DMI_PRODUCT_NAME, "Rex"), 547 }, 548 .driver_data = (void *)(SOC_SDW_PCH_DMIC | 549 SOF_BT_OFFLOAD_SSP(1) | 550 SOF_SSP_BT_OFFLOAD_PRESENT), 551 }, 552 { 553 .callback = sof_sdw_quirk_cb, 554 .matches = { 555 DMI_MATCH(DMI_SYS_VENDOR, "HP"), 556 DMI_MATCH(DMI_PRODUCT_NAME, "OMEN Transcend Gaming Laptop"), 557 }, 558 .driver_data = (void *)(RT711_JD2), 559 }, 560 561 /* LunarLake devices */ 562 { 563 .callback = sof_sdw_quirk_cb, 564 .matches = { 565 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"), 566 DMI_MATCH(DMI_PRODUCT_NAME, "Lunar Lake Client Platform"), 567 }, 568 .driver_data = (void *)(RT711_JD2), 569 }, 570 { 571 .callback = sof_sdw_quirk_cb, 572 .matches = { 573 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 574 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CE3") 575 }, 576 .driver_data = (void *)(SOC_SDW_SIDECAR_AMPS), 577 }, 578 { 579 .callback = sof_sdw_quirk_cb, 580 .matches = { 581 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 582 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CE4") 583 }, 584 .driver_data = (void *)(SOC_SDW_SIDECAR_AMPS), 585 }, 586 { 587 .callback = sof_sdw_quirk_cb, 588 .matches = { 589 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 590 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CDB") 591 }, 592 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 593 }, 594 { 595 .callback = sof_sdw_quirk_cb, 596 .matches = { 597 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 598 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CDC") 599 }, 600 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 601 }, 602 { 603 .callback = sof_sdw_quirk_cb, 604 .matches = { 605 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 606 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CDD") 607 }, 608 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 609 }, 610 { 611 .callback = sof_sdw_quirk_cb, 612 .matches = { 613 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 614 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0D36") 615 }, 616 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 617 }, 618 { 619 .callback = sof_sdw_quirk_cb, 620 .matches = { 621 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 622 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CF8") 623 }, 624 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 625 }, 626 { 627 .callback = sof_sdw_quirk_cb, 628 .matches = { 629 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 630 DMI_MATCH(DMI_PRODUCT_NAME, "83JX") 631 }, 632 .driver_data = (void *)(SOC_SDW_SIDECAR_AMPS | SOC_SDW_CODEC_MIC), 633 }, 634 { 635 .callback = sof_sdw_quirk_cb, 636 .matches = { 637 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 638 DMI_MATCH(DMI_PRODUCT_NAME, "83LC") 639 }, 640 .driver_data = (void *)(SOC_SDW_SIDECAR_AMPS | SOC_SDW_CODEC_MIC), 641 }, 642 { 643 .callback = sof_sdw_quirk_cb, 644 .matches = { 645 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 646 DMI_MATCH(DMI_PRODUCT_NAME, "83MC") 647 }, 648 .driver_data = (void *)(SOC_SDW_SIDECAR_AMPS | SOC_SDW_CODEC_MIC), 649 }, { 650 .callback = sof_sdw_quirk_cb, 651 .matches = { 652 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 653 DMI_MATCH(DMI_PRODUCT_NAME, "83NM") 654 }, 655 .driver_data = (void *)(SOC_SDW_SIDECAR_AMPS | SOC_SDW_CODEC_MIC), 656 }, 657 { 658 .callback = sof_sdw_quirk_cb, 659 .matches = { 660 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 661 DMI_MATCH(DMI_PRODUCT_NAME, "83HM") 662 }, 663 .driver_data = (void *)(SOC_SDW_SIDECAR_AMPS | 664 SOC_SDW_CODEC_MIC), 665 }, 666 { 667 .callback = sof_sdw_quirk_cb, 668 .matches = { 669 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 670 DMI_MATCH(DMI_PRODUCT_NAME, "21QB") 671 }, 672 /* Note this quirk excludes the CODEC mic */ 673 .driver_data = (void *)(SOC_SDW_CODEC_MIC), 674 }, 675 { 676 .callback = sof_sdw_quirk_cb, 677 .matches = { 678 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 679 DMI_MATCH(DMI_PRODUCT_NAME, "21QA") 680 }, 681 /* Note this quirk excludes the CODEC mic */ 682 .driver_data = (void *)(SOC_SDW_CODEC_MIC), 683 }, 684 { 685 .callback = sof_sdw_quirk_cb, 686 .matches = { 687 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 688 DMI_MATCH(DMI_PRODUCT_NAME, "21Q6") 689 }, 690 .driver_data = (void *)(SOC_SDW_SIDECAR_AMPS | SOC_SDW_CODEC_MIC), 691 }, 692 { 693 .callback = sof_sdw_quirk_cb, 694 .matches = { 695 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 696 DMI_MATCH(DMI_PRODUCT_NAME, "21Q7") 697 }, 698 .driver_data = (void *)(SOC_SDW_SIDECAR_AMPS | SOC_SDW_CODEC_MIC), 699 }, 700 701 /* ArrowLake devices */ 702 { 703 .callback = sof_sdw_quirk_cb, 704 .matches = { 705 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 706 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CE8") 707 }, 708 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 709 }, 710 { 711 .callback = sof_sdw_quirk_cb, 712 .matches = { 713 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 714 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CF1") 715 }, 716 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 717 }, 718 { 719 .callback = sof_sdw_quirk_cb, 720 .matches = { 721 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 722 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CF7") 723 }, 724 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 725 }, 726 { 727 .callback = sof_sdw_quirk_cb, 728 .matches = { 729 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 730 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CF0") 731 }, 732 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 733 }, 734 { 735 .callback = sof_sdw_quirk_cb, 736 .matches = { 737 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 738 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CF3") 739 }, 740 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 741 }, 742 { 743 .callback = sof_sdw_quirk_cb, 744 .matches = { 745 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 746 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CF4") 747 }, 748 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 749 }, 750 { 751 .callback = sof_sdw_quirk_cb, 752 .matches = { 753 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), 754 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CF5") 755 }, 756 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 757 }, 758 { 759 .callback = sof_sdw_quirk_cb, 760 .matches = { 761 DMI_MATCH(DMI_SYS_VENDOR, "Alienware"), 762 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0CCC") 763 }, 764 .driver_data = (void *)(SOC_SDW_CODEC_SPKR), 765 }, 766 /* Pantherlake devices*/ 767 { 768 .callback = sof_sdw_quirk_cb, 769 .matches = { 770 DMI_MATCH(DMI_PRODUCT_FAMILY, "Intel_ptlrvp"), 771 }, 772 .driver_data = (void *)(SOC_SDW_PCH_DMIC), 773 }, 774 { 775 .callback = sof_sdw_quirk_cb, 776 .matches = { 777 DMI_MATCH(DMI_SYS_VENDOR, "Google"), 778 DMI_MATCH(DMI_PRODUCT_NAME, "Lapis"), 779 }, 780 .driver_data = (void *)(SOC_SDW_CODEC_SPKR | 781 SOC_SDW_PCH_DMIC | 782 SOF_BT_OFFLOAD_SSP(2) | 783 SOF_SSP_BT_OFFLOAD_PRESENT), 784 }, 785 { 786 .callback = sof_sdw_quirk_cb, 787 .matches = { 788 DMI_MATCH(DMI_SYS_VENDOR, "Google"), 789 DMI_MATCH(DMI_PRODUCT_NAME, "Francka"), 790 }, 791 .driver_data = (void *)(SOC_SDW_CODEC_SPKR | 792 SOC_SDW_PCH_DMIC | 793 SOF_BT_OFFLOAD_SSP(2) | 794 SOF_SSP_BT_OFFLOAD_PRESENT), 795 }, 796 { 797 .callback = sof_sdw_quirk_cb, 798 .matches = { 799 DMI_MATCH(DMI_SYS_VENDOR, "Google"), 800 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Fatcat"), 801 }, 802 .driver_data = (void *)(SOC_SDW_PCH_DMIC | 803 SOF_BT_OFFLOAD_SSP(2) | 804 SOF_SSP_BT_OFFLOAD_PRESENT), 805 }, 806 /* Wildcatlake devices*/ 807 { 808 .callback = sof_sdw_quirk_cb, 809 .matches = { 810 DMI_MATCH(DMI_PRODUCT_FAMILY, "Intel_wclrvp"), 811 }, 812 .driver_data = (void *)(SOC_SDW_PCH_DMIC), 813 }, 814 { 815 .callback = sof_sdw_quirk_cb, 816 .matches = { 817 DMI_MATCH(DMI_SYS_VENDOR, "Google"), 818 DMI_MATCH(DMI_PRODUCT_NAME, "Ocelot"), 819 }, 820 .driver_data = (void *)(SOC_SDW_PCH_DMIC | 821 SOF_BT_OFFLOAD_SSP(2) | 822 SOF_SSP_BT_OFFLOAD_PRESENT), 823 }, 824 {} 825 }; 826 827 static const struct snd_pci_quirk sof_sdw_ssid_quirk_table[] = { 828 SND_PCI_QUIRK(0x1043, 0x1e13, "ASUS Zenbook S14", SOC_SDW_CODEC_MIC), 829 SND_PCI_QUIRK(0x1043, 0x1f43, "ASUS Zenbook S16", SOC_SDW_CODEC_MIC), 830 SND_PCI_QUIRK(0x17aa, 0x2347, "Lenovo P16", SOC_SDW_CODEC_MIC), 831 SND_PCI_QUIRK(0x17aa, 0x2348, "Lenovo P16", SOC_SDW_CODEC_MIC), 832 SND_PCI_QUIRK(0x17aa, 0x2349, "Lenovo P1", SOC_SDW_CODEC_MIC), 833 {} 834 }; 835 836 static void sof_sdw_check_ssid_quirk(const struct snd_soc_acpi_mach *mach) 837 { 838 const struct snd_pci_quirk *quirk_entry; 839 840 quirk_entry = snd_pci_quirk_lookup_id(mach->mach_params.subsystem_vendor, 841 mach->mach_params.subsystem_device, 842 sof_sdw_ssid_quirk_table); 843 844 if (quirk_entry) 845 sof_sdw_quirk = quirk_entry->value; 846 } 847 848 static const struct snd_soc_ops sdw_ops = { 849 .startup = asoc_sdw_startup, 850 .prepare = asoc_sdw_prepare, 851 .trigger = asoc_sdw_trigger, 852 .hw_params = asoc_sdw_hw_params, 853 .hw_free = asoc_sdw_hw_free, 854 .shutdown = asoc_sdw_shutdown, 855 }; 856 857 static const char * const type_strings[] = {"SimpleJack", "SmartAmp", "SmartMic"}; 858 859 static int create_sdw_dailink(struct snd_soc_card *card, 860 struct asoc_sdw_dailink *sof_dai, 861 struct snd_soc_dai_link **dai_links, 862 int *be_id, struct snd_soc_codec_conf **codec_conf) 863 { 864 struct device *dev = card->dev; 865 struct snd_soc_acpi_mach *mach = dev_get_platdata(card->dev); 866 struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); 867 struct snd_soc_acpi_mach_params *mach_params = &mach->mach_params; 868 struct intel_mc_ctx *intel_ctx = (struct intel_mc_ctx *)ctx->private; 869 struct asoc_sdw_endpoint *sof_end; 870 int stream; 871 int ret; 872 873 list_for_each_entry(sof_end, &sof_dai->endpoints, list) { 874 if (sof_end->name_prefix) { 875 (*codec_conf)->dlc.name = sof_end->codec_name; 876 (*codec_conf)->name_prefix = sof_end->name_prefix; 877 (*codec_conf)++; 878 } 879 880 if (sof_end->include_sidecar && sof_end->codec_info->add_sidecar) { 881 ret = sof_end->codec_info->add_sidecar(card, dai_links, codec_conf); 882 if (ret) 883 return ret; 884 } 885 } 886 887 for_each_pcm_streams(stream) { 888 static const char * const sdw_stream_name[] = { 889 "SDW%d-Playback", 890 "SDW%d-Capture", 891 "SDW%d-Playback-%s", 892 "SDW%d-Capture-%s", 893 }; 894 struct snd_soc_dai_link_ch_map *codec_maps; 895 struct snd_soc_dai_link_component *codecs; 896 struct snd_soc_dai_link_component *cpus; 897 struct snd_soc_dai_link_component *platform; 898 int num_cpus = hweight32(sof_dai->link_mask[stream]); 899 int num_codecs = sof_dai->num_devs[stream]; 900 int playback, capture; 901 int cur_link = 0; 902 int i = 0, j = 0; 903 char *name; 904 905 if (!sof_dai->num_devs[stream]) 906 continue; 907 908 sof_end = list_first_entry(&sof_dai->endpoints, 909 struct asoc_sdw_endpoint, list); 910 911 *be_id = sof_end->dai_info->dailink[stream]; 912 if (*be_id < 0) { 913 dev_err(dev, "Invalid dailink id %d\n", *be_id); 914 return -EINVAL; 915 } 916 917 /* create stream name according to first link id */ 918 if (ctx->append_dai_type) 919 name = devm_kasprintf(dev, GFP_KERNEL, 920 sdw_stream_name[stream + 2], 921 ffs(sof_end->link_mask) - 1, 922 type_strings[sof_end->dai_info->dai_type]); 923 else 924 name = devm_kasprintf(dev, GFP_KERNEL, 925 sdw_stream_name[stream], 926 ffs(sof_end->link_mask) - 1); 927 if (!name) 928 return -ENOMEM; 929 930 cpus = devm_kcalloc(dev, num_cpus, sizeof(*cpus), GFP_KERNEL); 931 if (!cpus) 932 return -ENOMEM; 933 934 codecs = devm_kcalloc(dev, num_codecs, sizeof(*codecs), GFP_KERNEL); 935 if (!codecs) 936 return -ENOMEM; 937 938 platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); 939 if (!platform) 940 return -ENOMEM; 941 942 codec_maps = devm_kcalloc(dev, num_codecs, sizeof(*codec_maps), GFP_KERNEL); 943 if (!codec_maps) 944 return -ENOMEM; 945 946 list_for_each_entry(sof_end, &sof_dai->endpoints, list) { 947 if (!sof_end->dai_info->direction[stream]) 948 continue; 949 950 if (cur_link != sof_end->link_mask) { 951 int link_num = ffs(sof_end->link_mask) - 1; 952 int pin_num = intel_ctx->sdw_pin_index[link_num]++; 953 954 cur_link = sof_end->link_mask; 955 956 cpus[i].dai_name = devm_kasprintf(dev, GFP_KERNEL, 957 "SDW%d Pin%d", 958 link_num, pin_num); 959 if (!cpus[i].dai_name) 960 return -ENOMEM; 961 i++; 962 } 963 964 codec_maps[j].cpu = i - 1; 965 codec_maps[j].codec = j; 966 967 codecs[j].name = sof_end->codec_name; 968 codecs[j].dai_name = sof_end->dai_info->dai_name; 969 if (sof_end->dai_info->dai_type == SOC_SDW_DAI_TYPE_MIC && 970 mach_params->dmic_num > 0) { 971 dev_warn(dev, 972 "Both SDW DMIC and PCH DMIC are present, if incorrect, please set kernel params snd_sof_intel_hda_generic dmic_num=0 to disable PCH DMIC\n"); 973 } 974 j++; 975 } 976 977 WARN_ON(i != num_cpus || j != num_codecs); 978 979 playback = (stream == SNDRV_PCM_STREAM_PLAYBACK); 980 capture = (stream == SNDRV_PCM_STREAM_CAPTURE); 981 982 asoc_sdw_init_dai_link(dev, *dai_links, be_id, name, playback, capture, 983 cpus, num_cpus, platform, 1, codecs, num_codecs, 984 1, asoc_sdw_rtd_init, &sdw_ops); 985 986 /* 987 * SoundWire DAILINKs use 'stream' functions and Bank Switch operations 988 * based on wait_for_completion(), tag them as 'nonatomic'. 989 */ 990 (*dai_links)->nonatomic = true; 991 (*dai_links)->ch_maps = codec_maps; 992 993 list_for_each_entry(sof_end, &sof_dai->endpoints, list) { 994 if (sof_end->dai_info->init) 995 sof_end->dai_info->init(card, *dai_links, 996 sof_end->codec_info, 997 playback); 998 } 999 1000 (*dai_links)++; 1001 } 1002 1003 return 0; 1004 } 1005 1006 static int create_sdw_dailinks(struct snd_soc_card *card, 1007 struct snd_soc_dai_link **dai_links, int *be_id, 1008 struct asoc_sdw_dailink *sof_dais, 1009 struct snd_soc_codec_conf **codec_conf) 1010 { 1011 struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); 1012 struct intel_mc_ctx *intel_ctx = (struct intel_mc_ctx *)ctx->private; 1013 int ret, i; 1014 1015 for (i = 0; i < SDW_INTEL_MAX_LINKS; i++) 1016 intel_ctx->sdw_pin_index[i] = SOC_SDW_INTEL_BIDIR_PDI_BASE; 1017 1018 /* generate DAI links by each sdw link */ 1019 while (sof_dais->initialised) { 1020 int current_be_id = 0; 1021 1022 ret = create_sdw_dailink(card, sof_dais, dai_links, 1023 ¤t_be_id, codec_conf); 1024 if (ret) 1025 return ret; 1026 1027 /* Update the be_id to match the highest ID used for SDW link */ 1028 if (*be_id < current_be_id) 1029 *be_id = current_be_id; 1030 1031 sof_dais++; 1032 } 1033 1034 return 0; 1035 } 1036 1037 static int create_ssp_dailinks(struct snd_soc_card *card, 1038 struct snd_soc_dai_link **dai_links, int *be_id, 1039 struct asoc_sdw_codec_info *ssp_info, 1040 unsigned long ssp_mask) 1041 { 1042 struct device *dev = card->dev; 1043 int i, j = 0; 1044 int ret; 1045 1046 for_each_set_bit(i, &ssp_mask, BITS_PER_TYPE(ssp_mask)) { 1047 char *name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", i); 1048 char *cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", i); 1049 char *codec_name = devm_kasprintf(dev, GFP_KERNEL, "i2c-%s:0%d", 1050 ssp_info->acpi_id, j++); 1051 if (!name || !cpu_dai_name || !codec_name) 1052 return -ENOMEM; 1053 1054 int playback = ssp_info->dais[0].direction[SNDRV_PCM_STREAM_PLAYBACK]; 1055 int capture = ssp_info->dais[0].direction[SNDRV_PCM_STREAM_CAPTURE]; 1056 1057 ret = asoc_sdw_init_simple_dai_link(dev, *dai_links, be_id, name, 1058 playback, capture, cpu_dai_name, 1059 "dummy", codec_name, 1060 ssp_info->dais[0].dai_name, 1, NULL, 1061 ssp_info->ops); 1062 if (ret) 1063 return ret; 1064 1065 ret = ssp_info->dais[0].init(card, *dai_links, ssp_info, 0); 1066 if (ret < 0) 1067 return ret; 1068 1069 (*dai_links)++; 1070 } 1071 1072 return 0; 1073 } 1074 1075 static int create_dmic_dailinks(struct snd_soc_card *card, 1076 struct snd_soc_dai_link **dai_links, int *be_id) 1077 { 1078 struct device *dev = card->dev; 1079 int ret; 1080 1081 ret = asoc_sdw_init_simple_dai_link(dev, *dai_links, be_id, "dmic01", 1082 0, 1, // DMIC only supports capture 1083 "DMIC01 Pin", "dummy", 1084 "dmic-codec", "dmic-hifi", 1, 1085 asoc_sdw_dmic_init, NULL); 1086 if (ret) 1087 return ret; 1088 1089 (*dai_links)++; 1090 1091 ret = asoc_sdw_init_simple_dai_link(dev, *dai_links, be_id, "dmic16k", 1092 0, 1, // DMIC only supports capture 1093 "DMIC16k Pin", "dummy", 1094 "dmic-codec", "dmic-hifi", 1, 1095 /* don't call asoc_sdw_dmic_init() twice */ 1096 NULL, NULL); 1097 if (ret) 1098 return ret; 1099 1100 (*dai_links)++; 1101 1102 return 0; 1103 } 1104 1105 static int create_hdmi_dailinks(struct snd_soc_card *card, 1106 struct snd_soc_dai_link **dai_links, int *be_id, 1107 int hdmi_num) 1108 { 1109 struct device *dev = card->dev; 1110 struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); 1111 struct intel_mc_ctx *intel_ctx = (struct intel_mc_ctx *)ctx->private; 1112 int i, ret; 1113 1114 for (i = 0; i < hdmi_num; i++) { 1115 char *name = devm_kasprintf(dev, GFP_KERNEL, "iDisp%d", i + 1); 1116 char *cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL, "iDisp%d Pin", i + 1); 1117 if (!name || !cpu_dai_name) 1118 return -ENOMEM; 1119 1120 char *codec_name, *codec_dai_name; 1121 1122 if (intel_ctx->hdmi.idisp_codec) { 1123 codec_name = "ehdaudio0D2"; 1124 codec_dai_name = devm_kasprintf(dev, GFP_KERNEL, 1125 "intel-hdmi-hifi%d", i + 1); 1126 } else { 1127 codec_name = "snd-soc-dummy"; 1128 codec_dai_name = "snd-soc-dummy-dai"; 1129 } 1130 1131 if (!codec_dai_name) 1132 return -ENOMEM; 1133 1134 ret = asoc_sdw_init_simple_dai_link(dev, *dai_links, be_id, name, 1135 1, 0, // HDMI only supports playback 1136 cpu_dai_name, "dummy", 1137 codec_name, codec_dai_name, 1, 1138 i == 0 ? sof_sdw_hdmi_init : NULL, NULL); 1139 if (ret) 1140 return ret; 1141 1142 (*dai_links)++; 1143 } 1144 1145 return 0; 1146 } 1147 1148 static int create_bt_dailinks(struct snd_soc_card *card, 1149 struct snd_soc_dai_link **dai_links, int *be_id) 1150 { 1151 struct device *dev = card->dev; 1152 struct snd_soc_acpi_mach *mach = dev_get_platdata(dev); 1153 char *cpu_dai_name; 1154 char *name; 1155 int port; 1156 int ret; 1157 1158 if (sof_sdw_quirk & SOF_SSP_BT_OFFLOAD_PRESENT) 1159 port = (sof_sdw_quirk & SOF_BT_OFFLOAD_SSP_MASK) >> SOF_BT_OFFLOAD_SSP_SHIFT; 1160 else 1161 port = fls(mach->mach_params.bt_link_mask) - 1; 1162 1163 name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-BT", port); 1164 cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", port); 1165 if (!name || !cpu_dai_name) 1166 return -ENOMEM; 1167 1168 ret = asoc_sdw_init_simple_dai_link(dev, *dai_links, be_id, name, 1169 1, 1, cpu_dai_name, "dummy", 1170 snd_soc_dummy_dlc.name, snd_soc_dummy_dlc.dai_name, 1171 1, NULL, NULL); 1172 if (ret) 1173 return ret; 1174 1175 (*dai_links)++; 1176 1177 return 0; 1178 } 1179 1180 static int sof_card_dai_links_create(struct snd_soc_card *card) 1181 { 1182 struct device *dev = card->dev; 1183 struct snd_soc_acpi_mach *mach = dev_get_platdata(card->dev); 1184 int sdw_be_num = 0, ssp_num = 0, dmic_num = 0, bt_num = 0; 1185 struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); 1186 struct intel_mc_ctx *intel_ctx = (struct intel_mc_ctx *)ctx->private; 1187 struct snd_soc_acpi_mach_params *mach_params = &mach->mach_params; 1188 struct snd_soc_codec_conf *codec_conf; 1189 struct asoc_sdw_codec_info *ssp_info; 1190 struct asoc_sdw_endpoint *sof_ends; 1191 struct asoc_sdw_dailink *sof_dais; 1192 struct snd_soc_aux_dev *sof_aux; 1193 int num_devs = 0; 1194 int num_ends = 0; 1195 int num_aux = 0; 1196 int num_confs; 1197 struct snd_soc_dai_link *dai_links; 1198 int num_links; 1199 int be_id = 0; 1200 int hdmi_num; 1201 unsigned long ssp_mask; 1202 int ret; 1203 1204 ret = asoc_sdw_count_sdw_endpoints(card, &num_devs, &num_ends, &num_aux); 1205 if (ret < 0) { 1206 dev_err(dev, "failed to count devices/endpoints: %d\n", ret); 1207 return ret; 1208 } 1209 1210 num_confs = num_ends; 1211 1212 /* 1213 * One per DAI link, worst case is a DAI link for every endpoint, also 1214 * add one additional to act as a terminator such that code can iterate 1215 * until it hits an uninitialised DAI. 1216 */ 1217 sof_dais = kcalloc(num_ends + 1, sizeof(*sof_dais), GFP_KERNEL); 1218 if (!sof_dais) 1219 return -ENOMEM; 1220 1221 /* One per endpoint, ie. each DAI on each codec/amp */ 1222 sof_ends = kcalloc(num_ends, sizeof(*sof_ends), GFP_KERNEL); 1223 if (!sof_ends) { 1224 ret = -ENOMEM; 1225 goto err_dai; 1226 } 1227 1228 sof_aux = devm_kcalloc(dev, num_aux, sizeof(*sof_aux), GFP_KERNEL); 1229 if (!sof_aux) { 1230 ret = -ENOMEM; 1231 goto err_dai; 1232 } 1233 1234 ret = asoc_sdw_parse_sdw_endpoints(card, sof_aux, sof_dais, sof_ends, &num_confs); 1235 if (ret < 0) 1236 goto err_end; 1237 1238 sdw_be_num = ret; 1239 1240 /* 1241 * on generic tgl platform, I2S or sdw mode is supported 1242 * based on board rework. A ACPI device is registered in 1243 * system only when I2S mode is supported, not sdw mode. 1244 * Here check ACPI ID to confirm I2S is supported. 1245 */ 1246 ssp_info = asoc_sdw_find_codec_info_acpi(mach->id); 1247 if (ssp_info) { 1248 ssp_mask = SOF_SSP_GET_PORT(sof_sdw_quirk); 1249 ssp_num = hweight_long(ssp_mask); 1250 } 1251 1252 if (mach_params->codec_mask & IDISP_CODEC_MASK) 1253 intel_ctx->hdmi.idisp_codec = true; 1254 1255 if (sof_sdw_quirk & SOF_SDW_TGL_HDMI) 1256 hdmi_num = SOF_TGL_HDMI_COUNT; 1257 else 1258 hdmi_num = SOF_PRE_TGL_HDMI_COUNT; 1259 1260 /* enable dmic01 & dmic16k */ 1261 if (ctx->ignore_internal_dmic) { 1262 dev_dbg(dev, "SoundWire DMIC is used, ignoring internal DMIC\n"); 1263 mach_params->dmic_num = 0; 1264 } else if (mach_params->dmic_num) { 1265 dmic_num = 2; 1266 } else if (sof_sdw_quirk & SOC_SDW_PCH_DMIC) { 1267 dmic_num = 2; 1268 /* 1269 * mach_params->dmic_num will be used to set the cfg-mics value of 1270 * card->components string. Set it to the default value. 1271 */ 1272 mach_params->dmic_num = DMIC_DEFAULT_CHANNELS; 1273 } 1274 1275 if (sof_sdw_quirk & SOF_SSP_BT_OFFLOAD_PRESENT || mach_params->bt_link_mask) 1276 bt_num = 1; 1277 1278 dev_dbg(dev, "DAI link numbers: sdw %d, ssp %d, dmic %d, hdmi %d, bt: %d\n", 1279 sdw_be_num, ssp_num, dmic_num, 1280 intel_ctx->hdmi.idisp_codec ? hdmi_num : 0, bt_num); 1281 1282 codec_conf = devm_kcalloc(dev, num_confs, sizeof(*codec_conf), GFP_KERNEL); 1283 if (!codec_conf) { 1284 ret = -ENOMEM; 1285 goto err_end; 1286 } 1287 1288 /* allocate BE dailinks */ 1289 num_links = sdw_be_num + ssp_num + dmic_num + hdmi_num + bt_num; 1290 dai_links = devm_kcalloc(dev, num_links, sizeof(*dai_links), GFP_KERNEL); 1291 if (!dai_links) { 1292 ret = -ENOMEM; 1293 goto err_end; 1294 } 1295 1296 card->codec_conf = codec_conf; 1297 card->num_configs = num_confs; 1298 card->dai_link = dai_links; 1299 card->num_links = num_links; 1300 card->aux_dev = sof_aux; 1301 card->num_aux_devs = num_aux; 1302 1303 /* SDW */ 1304 if (sdw_be_num) { 1305 ret = create_sdw_dailinks(card, &dai_links, &be_id, 1306 sof_dais, &codec_conf); 1307 if (ret) 1308 goto err_end; 1309 } 1310 1311 /* SSP */ 1312 if (ssp_num) { 1313 ret = create_ssp_dailinks(card, &dai_links, &be_id, 1314 ssp_info, ssp_mask); 1315 if (ret) 1316 goto err_end; 1317 } 1318 1319 /* dmic */ 1320 if (dmic_num) { 1321 ret = create_dmic_dailinks(card, &dai_links, &be_id); 1322 if (ret) 1323 goto err_end; 1324 } 1325 1326 /* HDMI */ 1327 ret = create_hdmi_dailinks(card, &dai_links, &be_id, hdmi_num); 1328 if (ret) 1329 goto err_end; 1330 1331 /* BT */ 1332 if (bt_num) { 1333 ret = create_bt_dailinks(card, &dai_links, &be_id); 1334 if (ret) 1335 goto err_end; 1336 } 1337 1338 WARN_ON(codec_conf != card->codec_conf + card->num_configs); 1339 WARN_ON(dai_links != card->dai_link + card->num_links); 1340 1341 err_end: 1342 kfree(sof_ends); 1343 err_dai: 1344 kfree(sof_dais); 1345 1346 return ret; 1347 } 1348 1349 static int sof_sdw_card_late_probe(struct snd_soc_card *card) 1350 { 1351 struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); 1352 struct intel_mc_ctx *intel_ctx = (struct intel_mc_ctx *)ctx->private; 1353 int ret = 0; 1354 1355 ret = asoc_sdw_card_late_probe(card); 1356 if (ret < 0) 1357 return ret; 1358 1359 if (intel_ctx->hdmi.idisp_codec) 1360 ret = sof_sdw_hdmi_card_late_probe(card); 1361 1362 return ret; 1363 } 1364 1365 static int sof_sdw_add_dai_link(struct snd_soc_card *card, 1366 struct snd_soc_dai_link *link) 1367 { 1368 struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); 1369 struct intel_mc_ctx *intel_ctx = (struct intel_mc_ctx *)ctx->private; 1370 1371 /* Ignore the HDMI PCM link if iDisp is not present */ 1372 if (strstr(link->stream_name, "HDMI") && !intel_ctx->hdmi.idisp_codec) 1373 link->ignore = true; 1374 1375 return 0; 1376 } 1377 1378 static int mc_probe(struct platform_device *pdev) 1379 { 1380 struct snd_soc_acpi_mach *mach = dev_get_platdata(&pdev->dev); 1381 struct snd_soc_card *card; 1382 struct asoc_sdw_mc_private *ctx; 1383 struct intel_mc_ctx *intel_ctx; 1384 int amp_num = 0, i; 1385 int ret; 1386 1387 dev_dbg(&pdev->dev, "Entry\n"); 1388 1389 intel_ctx = devm_kzalloc(&pdev->dev, sizeof(*intel_ctx), GFP_KERNEL); 1390 if (!intel_ctx) 1391 return -ENOMEM; 1392 1393 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); 1394 if (!ctx) 1395 return -ENOMEM; 1396 1397 ctx->private = intel_ctx; 1398 ctx->codec_info_list_count = asoc_sdw_get_codec_info_list_count(); 1399 card = &ctx->card; 1400 card->dev = &pdev->dev; 1401 card->name = "soundwire"; 1402 card->owner = THIS_MODULE; 1403 card->late_probe = sof_sdw_card_late_probe; 1404 card->add_dai_link = sof_sdw_add_dai_link; 1405 1406 snd_soc_card_set_drvdata(card, ctx); 1407 1408 if (mach->mach_params.subsystem_id_set) { 1409 snd_soc_card_set_pci_ssid(card, 1410 mach->mach_params.subsystem_vendor, 1411 mach->mach_params.subsystem_device); 1412 sof_sdw_check_ssid_quirk(mach); 1413 } 1414 1415 dmi_check_system(sof_sdw_quirk_table); 1416 1417 if (quirk_override != -1) { 1418 dev_info(card->dev, "Overriding quirk 0x%lx => 0x%x\n", 1419 sof_sdw_quirk, quirk_override); 1420 sof_sdw_quirk = quirk_override; 1421 } 1422 1423 log_quirks(card->dev); 1424 1425 ctx->mc_quirk = sof_sdw_quirk; 1426 /* reset amp_num to ensure amp_num++ starts from 0 in each probe */ 1427 for (i = 0; i < ctx->codec_info_list_count; i++) 1428 codec_info_list[i].amp_num = 0; 1429 1430 ret = sof_card_dai_links_create(card); 1431 if (ret < 0) 1432 return ret; 1433 1434 /* 1435 * the default amp_num is zero for each codec and 1436 * amp_num will only be increased for active amp 1437 * codecs on used platform 1438 */ 1439 for (i = 0; i < ctx->codec_info_list_count; i++) 1440 amp_num += codec_info_list[i].amp_num; 1441 1442 card->components = devm_kasprintf(card->dev, GFP_KERNEL, 1443 " cfg-amp:%d", amp_num); 1444 if (!card->components) 1445 return -ENOMEM; 1446 1447 if (mach->mach_params.dmic_num) { 1448 card->components = devm_kasprintf(card->dev, GFP_KERNEL, 1449 "%s mic:dmic cfg-mics:%d", 1450 card->components, 1451 mach->mach_params.dmic_num); 1452 if (!card->components) 1453 return -ENOMEM; 1454 } 1455 1456 /* Register the card */ 1457 ret = devm_snd_soc_register_card(card->dev, card); 1458 if (ret) { 1459 dev_err_probe(card->dev, ret, "snd_soc_register_card failed %d\n", ret); 1460 asoc_sdw_mc_dailink_exit_loop(card); 1461 return ret; 1462 } 1463 1464 platform_set_drvdata(pdev, card); 1465 1466 return ret; 1467 } 1468 1469 static void mc_remove(struct platform_device *pdev) 1470 { 1471 struct snd_soc_card *card = platform_get_drvdata(pdev); 1472 1473 asoc_sdw_mc_dailink_exit_loop(card); 1474 } 1475 1476 static const struct platform_device_id mc_id_table[] = { 1477 { "sof_sdw", }, 1478 {} 1479 }; 1480 MODULE_DEVICE_TABLE(platform, mc_id_table); 1481 1482 static struct platform_driver sof_sdw_driver = { 1483 .driver = { 1484 .name = "sof_sdw", 1485 .pm = &snd_soc_pm_ops, 1486 }, 1487 .probe = mc_probe, 1488 .remove = mc_remove, 1489 .id_table = mc_id_table, 1490 }; 1491 1492 module_platform_driver(sof_sdw_driver); 1493 1494 MODULE_DESCRIPTION("ASoC SoundWire Generic Machine driver"); 1495 MODULE_AUTHOR("Bard Liao <yung-chuan.liao@linux.intel.com>"); 1496 MODULE_AUTHOR("Rander Wang <rander.wang@linux.intel.com>"); 1497 MODULE_AUTHOR("Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>"); 1498 MODULE_LICENSE("GPL v2"); 1499 MODULE_IMPORT_NS("SND_SOC_INTEL_HDA_DSP_COMMON"); 1500 MODULE_IMPORT_NS("SND_SOC_SDW_UTILS"); 1501