intel-dsp-config.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (c) 2019 Jaroslav Kysela <perex@perex.cz>
  3. #include <linux/acpi.h>
  4. #include <linux/bits.h>
  5. #include <linux/dmi.h>
  6. #include <linux/module.h>
  7. #include <linux/pci.h>
  8. #include <linux/soundwire/sdw.h>
  9. #include <linux/soundwire/sdw_intel.h>
  10. #include <sound/core.h>
  11. #include <sound/intel-dsp-config.h>
  12. #include <sound/intel-nhlt.h>
  13. static int dsp_driver;
  14. module_param(dsp_driver, int, 0444);
  15. MODULE_PARM_DESC(dsp_driver, "Force the DSP driver for Intel DSP (0=auto, 1=legacy, 2=SST, 3=SOF)");
  16. #define FLAG_SST BIT(0)
  17. #define FLAG_SOF BIT(1)
  18. #define FLAG_SST_ONLY_IF_DMIC BIT(15)
  19. #define FLAG_SOF_ONLY_IF_DMIC BIT(16)
  20. #define FLAG_SOF_ONLY_IF_SOUNDWIRE BIT(17)
  21. #define FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE (FLAG_SOF_ONLY_IF_DMIC | \
  22. FLAG_SOF_ONLY_IF_SOUNDWIRE)
  23. struct config_entry {
  24. u32 flags;
  25. u16 device;
  26. const struct dmi_system_id *dmi_table;
  27. u8 codec_hid[ACPI_ID_LEN];
  28. };
  29. /*
  30. * configuration table
  31. * - the order of similar PCI ID entries is important!
  32. * - the first successful match will win
  33. */
  34. static const struct config_entry config_table[] = {
  35. /* Merrifield */
  36. #if IS_ENABLED(CONFIG_SND_SOC_SOF_MERRIFIELD)
  37. {
  38. .flags = FLAG_SOF,
  39. .device = 0x119a,
  40. },
  41. #endif
  42. /* Broxton-T */
  43. #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
  44. {
  45. .flags = FLAG_SOF,
  46. .device = 0x1a98,
  47. },
  48. #endif
  49. /*
  50. * Apollolake (Broxton-P)
  51. * the legacy HDAudio driver is used except on Up Squared (SOF) and
  52. * Chromebooks (SST), as well as devices based on the ES8336 codec
  53. */
  54. #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
  55. {
  56. .flags = FLAG_SOF,
  57. .device = 0x5a98,
  58. .dmi_table = (const struct dmi_system_id []) {
  59. {
  60. .ident = "Up Squared",
  61. .matches = {
  62. DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
  63. DMI_MATCH(DMI_BOARD_NAME, "UP-APL01"),
  64. }
  65. },
  66. {}
  67. }
  68. },
  69. {
  70. .flags = FLAG_SOF,
  71. .device = 0x5a98,
  72. .codec_hid = "ESSX8336",
  73. },
  74. #endif
  75. #if IS_ENABLED(CONFIG_SND_SOC_INTEL_APL)
  76. {
  77. .flags = FLAG_SST,
  78. .device = 0x5a98,
  79. .dmi_table = (const struct dmi_system_id []) {
  80. {
  81. .ident = "Google Chromebooks",
  82. .matches = {
  83. DMI_MATCH(DMI_SYS_VENDOR, "Google"),
  84. }
  85. },
  86. {}
  87. }
  88. },
  89. #endif
  90. /*
  91. * Skylake and Kabylake use legacy HDAudio driver except for Google
  92. * Chromebooks (SST)
  93. */
  94. /* Sunrise Point-LP */
  95. #if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKL)
  96. {
  97. .flags = FLAG_SST,
  98. .device = 0x9d70,
  99. .dmi_table = (const struct dmi_system_id []) {
  100. {
  101. .ident = "Google Chromebooks",
  102. .matches = {
  103. DMI_MATCH(DMI_SYS_VENDOR, "Google"),
  104. }
  105. },
  106. {}
  107. }
  108. },
  109. {
  110. .flags = FLAG_SST | FLAG_SST_ONLY_IF_DMIC,
  111. .device = 0x9d70,
  112. },
  113. #endif
  114. /* Kabylake-LP */
  115. #if IS_ENABLED(CONFIG_SND_SOC_INTEL_KBL)
  116. {
  117. .flags = FLAG_SST,
  118. .device = 0x9d71,
  119. .dmi_table = (const struct dmi_system_id []) {
  120. {
  121. .ident = "Google Chromebooks",
  122. .matches = {
  123. DMI_MATCH(DMI_SYS_VENDOR, "Google"),
  124. }
  125. },
  126. {}
  127. }
  128. },
  129. {
  130. .flags = FLAG_SST | FLAG_SST_ONLY_IF_DMIC,
  131. .device = 0x9d71,
  132. },
  133. #endif
  134. /*
  135. * Geminilake uses legacy HDAudio driver except for Google
  136. * Chromebooks and devices based on the ES8336 codec
  137. */
  138. /* Geminilake */
  139. #if IS_ENABLED(CONFIG_SND_SOC_SOF_GEMINILAKE)
  140. {
  141. .flags = FLAG_SOF,
  142. .device = 0x3198,
  143. .dmi_table = (const struct dmi_system_id []) {
  144. {
  145. .ident = "Google Chromebooks",
  146. .matches = {
  147. DMI_MATCH(DMI_SYS_VENDOR, "Google"),
  148. }
  149. },
  150. {}
  151. }
  152. },
  153. {
  154. .flags = FLAG_SOF,
  155. .device = 0x3198,
  156. .codec_hid = "ESSX8336",
  157. },
  158. #endif
  159. /*
  160. * CoffeeLake, CannonLake, CometLake, IceLake, TigerLake use legacy
  161. * HDAudio driver except for Google Chromebooks and when DMICs are
  162. * present. Two cases are required since Coreboot does not expose NHLT
  163. * tables.
  164. *
  165. * When the Chromebook quirk is not present, it's based on information
  166. * that no such device exists. When the quirk is present, it could be
  167. * either based on product information or a placeholder.
  168. */
  169. /* Cannonlake */
  170. #if IS_ENABLED(CONFIG_SND_SOC_SOF_CANNONLAKE)
  171. {
  172. .flags = FLAG_SOF,
  173. .device = 0x9dc8,
  174. .dmi_table = (const struct dmi_system_id []) {
  175. {
  176. .ident = "Google Chromebooks",
  177. .matches = {
  178. DMI_MATCH(DMI_SYS_VENDOR, "Google"),
  179. }
  180. },
  181. {}
  182. }
  183. },
  184. {
  185. .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
  186. .device = 0x9dc8,
  187. },
  188. #endif
  189. /* Coffelake */
  190. #if IS_ENABLED(CONFIG_SND_SOC_SOF_COFFEELAKE)
  191. {
  192. .flags = FLAG_SOF,
  193. .device = 0xa348,
  194. .dmi_table = (const struct dmi_system_id []) {
  195. {
  196. .ident = "Google Chromebooks",
  197. .matches = {
  198. DMI_MATCH(DMI_SYS_VENDOR, "Google"),
  199. }
  200. },
  201. {}
  202. }
  203. },
  204. {
  205. .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
  206. .device = 0xa348,
  207. },
  208. #endif
  209. #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE)
  210. /* Cometlake-LP */
  211. {
  212. .flags = FLAG_SOF,
  213. .device = 0x02c8,
  214. .dmi_table = (const struct dmi_system_id []) {
  215. {
  216. .ident = "Google Chromebooks",
  217. .matches = {
  218. DMI_MATCH(DMI_SYS_VENDOR, "Google"),
  219. }
  220. },
  221. {
  222. .matches = {
  223. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
  224. DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "09C6")
  225. },
  226. },
  227. {
  228. /* early version of SKU 09C6 */
  229. .matches = {
  230. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
  231. DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0983")
  232. },
  233. },
  234. {}
  235. }
  236. },
  237. {
  238. .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
  239. .device = 0x02c8,
  240. },
  241. {
  242. .flags = FLAG_SOF,
  243. .device = 0x02c8,
  244. .codec_hid = "ESSX8336",
  245. },
  246. /* Cometlake-H */
  247. {
  248. .flags = FLAG_SOF,
  249. .device = 0x06c8,
  250. .dmi_table = (const struct dmi_system_id []) {
  251. {
  252. .matches = {
  253. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
  254. DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "098F"),
  255. },
  256. },
  257. {
  258. .matches = {
  259. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
  260. DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0990"),
  261. },
  262. },
  263. {}
  264. }
  265. },
  266. {
  267. .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
  268. .device = 0x06c8,
  269. },
  270. {
  271. .flags = FLAG_SOF,
  272. .device = 0x06c8,
  273. .codec_hid = "ESSX8336",
  274. },
  275. #endif
  276. /* Icelake */
  277. #if IS_ENABLED(CONFIG_SND_SOC_SOF_ICELAKE)
  278. {
  279. .flags = FLAG_SOF,
  280. .device = 0x34c8,
  281. .dmi_table = (const struct dmi_system_id []) {
  282. {
  283. .ident = "Google Chromebooks",
  284. .matches = {
  285. DMI_MATCH(DMI_SYS_VENDOR, "Google"),
  286. }
  287. },
  288. {}
  289. }
  290. },
  291. {
  292. .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
  293. .device = 0x34c8,
  294. },
  295. #endif
  296. /* JasperLake */
  297. #if IS_ENABLED(CONFIG_SND_SOC_SOF_JASPERLAKE)
  298. {
  299. .flags = FLAG_SOF,
  300. .device = 0x4dc8,
  301. .codec_hid = "ESSX8336",
  302. },
  303. #endif
  304. /* Tigerlake */
  305. #if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
  306. {
  307. .flags = FLAG_SOF,
  308. .device = 0xa0c8,
  309. .dmi_table = (const struct dmi_system_id []) {
  310. {
  311. .ident = "Google Chromebooks",
  312. .matches = {
  313. DMI_MATCH(DMI_SYS_VENDOR, "Google"),
  314. }
  315. },
  316. {}
  317. }
  318. },
  319. {
  320. .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
  321. .device = 0xa0c8,
  322. },
  323. {
  324. .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
  325. .device = 0x43c8,
  326. },
  327. {
  328. .flags = FLAG_SOF,
  329. .device = 0xa0c8,
  330. .codec_hid = "ESSX8336",
  331. },
  332. #endif
  333. /* Elkhart Lake */
  334. #if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
  335. {
  336. .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
  337. .device = 0x4b55,
  338. },
  339. {
  340. .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
  341. .device = 0x4b58,
  342. },
  343. #endif
  344. };
  345. static const struct config_entry *snd_intel_dsp_find_config
  346. (struct pci_dev *pci, const struct config_entry *table, u32 len)
  347. {
  348. u16 device;
  349. device = pci->device;
  350. for (; len > 0; len--, table++) {
  351. if (table->device != device)
  352. continue;
  353. if (table->dmi_table && !dmi_check_system(table->dmi_table))
  354. continue;
  355. if (table->codec_hid[0] && !acpi_dev_present(table->codec_hid, NULL, -1))
  356. continue;
  357. return table;
  358. }
  359. return NULL;
  360. }
  361. static int snd_intel_dsp_check_dmic(struct pci_dev *pci)
  362. {
  363. struct nhlt_acpi_table *nhlt;
  364. int ret = 0;
  365. nhlt = intel_nhlt_init(&pci->dev);
  366. if (nhlt) {
  367. if (intel_nhlt_get_dmic_geo(&pci->dev, nhlt))
  368. ret = 1;
  369. intel_nhlt_free(nhlt);
  370. }
  371. return ret;
  372. }
  373. #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
  374. static int snd_intel_dsp_check_soundwire(struct pci_dev *pci)
  375. {
  376. struct sdw_intel_acpi_info info;
  377. acpi_handle handle;
  378. int ret;
  379. handle = ACPI_HANDLE(&pci->dev);
  380. ret = sdw_intel_acpi_scan(handle, &info);
  381. if (ret < 0)
  382. return ret;
  383. return info.link_mask;
  384. }
  385. #else
  386. static int snd_intel_dsp_check_soundwire(struct pci_dev *pci)
  387. {
  388. return 0;
  389. }
  390. #endif
  391. int snd_intel_dsp_driver_probe(struct pci_dev *pci)
  392. {
  393. const struct config_entry *cfg;
  394. /* Intel vendor only */
  395. if (pci->vendor != 0x8086)
  396. return SND_INTEL_DSP_DRIVER_ANY;
  397. if (dsp_driver > 0 && dsp_driver <= SND_INTEL_DSP_DRIVER_LAST)
  398. return dsp_driver;
  399. /*
  400. * detect DSP by checking class/subclass/prog-id information
  401. * class=04 subclass 03 prog-if 00: no DSP, use legacy driver
  402. * class=04 subclass 01 prog-if 00: DSP is present
  403. * (and may be required e.g. for DMIC or SSP support)
  404. * class=04 subclass 03 prog-if 80: use DSP or legacy mode
  405. */
  406. if (pci->class == 0x040300)
  407. return SND_INTEL_DSP_DRIVER_LEGACY;
  408. if (pci->class != 0x040100 && pci->class != 0x040380) {
  409. dev_err(&pci->dev, "Unknown PCI class/subclass/prog-if information (0x%06x) found, selecting HDAudio legacy driver\n", pci->class);
  410. return SND_INTEL_DSP_DRIVER_LEGACY;
  411. }
  412. dev_info(&pci->dev, "DSP detected with PCI class/subclass/prog-if info 0x%06x\n", pci->class);
  413. /* find the configuration for the specific device */
  414. cfg = snd_intel_dsp_find_config(pci, config_table, ARRAY_SIZE(config_table));
  415. if (!cfg)
  416. return SND_INTEL_DSP_DRIVER_ANY;
  417. if (cfg->flags & FLAG_SOF) {
  418. if (cfg->flags & FLAG_SOF_ONLY_IF_SOUNDWIRE &&
  419. snd_intel_dsp_check_soundwire(pci) > 0) {
  420. dev_info(&pci->dev, "SoundWire enabled on CannonLake+ platform, using SOF driver\n");
  421. return SND_INTEL_DSP_DRIVER_SOF;
  422. }
  423. if (cfg->flags & FLAG_SOF_ONLY_IF_DMIC &&
  424. snd_intel_dsp_check_dmic(pci)) {
  425. dev_info(&pci->dev, "Digital mics found on Skylake+ platform, using SOF driver\n");
  426. return SND_INTEL_DSP_DRIVER_SOF;
  427. }
  428. if (!(cfg->flags & FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE))
  429. return SND_INTEL_DSP_DRIVER_SOF;
  430. }
  431. if (cfg->flags & FLAG_SST) {
  432. if (cfg->flags & FLAG_SST_ONLY_IF_DMIC) {
  433. if (snd_intel_dsp_check_dmic(pci)) {
  434. dev_info(&pci->dev, "Digital mics found on Skylake+ platform, using SST driver\n");
  435. return SND_INTEL_DSP_DRIVER_SST;
  436. }
  437. } else {
  438. return SND_INTEL_DSP_DRIVER_SST;
  439. }
  440. }
  441. return SND_INTEL_DSP_DRIVER_LEGACY;
  442. }
  443. EXPORT_SYMBOL_GPL(snd_intel_dsp_driver_probe);
  444. MODULE_LICENSE("GPL v2");
  445. MODULE_DESCRIPTION("Intel DSP config driver");
  446. MODULE_IMPORT_NS(SOUNDWIRE_INTEL_INIT);