utils.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * X86 ACPI Utility Functions
  4. *
  5. * Copyright (C) 2017 Hans de Goede <[email protected]>
  6. *
  7. * Based on various non upstream patches to support the CHT Whiskey Cove PMIC:
  8. * Copyright (C) 2013-2015 Intel Corporation. All rights reserved.
  9. */
  10. #define pr_fmt(fmt) "ACPI: " fmt
  11. #include <linux/acpi.h>
  12. #include <linux/dmi.h>
  13. #include <linux/platform_device.h>
  14. #include <asm/cpu_device_id.h>
  15. #include <asm/intel-family.h>
  16. #include "../internal.h"
  17. /*
  18. * Some ACPI devices are hidden (status == 0x0) in recent BIOS-es because
  19. * some recent Windows drivers bind to one device but poke at multiple
  20. * devices at the same time, so the others get hidden.
  21. *
  22. * Some BIOS-es (temporarily) hide specific APCI devices to work around Windows
  23. * driver bugs. We use DMI matching to match known cases of this.
  24. *
  25. * Likewise sometimes some not-actually present devices are sometimes
  26. * reported as present, which may cause issues.
  27. *
  28. * We work around this by using the below quirk list to override the status
  29. * reported by the _STA method with a fixed value (ACPI_STA_DEFAULT or 0).
  30. * Note this MUST only be done for devices where this is safe.
  31. *
  32. * This status overriding is limited to specific CPU (SoC) models both to
  33. * avoid potentially causing trouble on other models and because some HIDs
  34. * are re-used on different SoCs for completely different devices.
  35. */
  36. struct override_status_id {
  37. struct acpi_device_id hid[2];
  38. struct x86_cpu_id cpu_ids[2];
  39. struct dmi_system_id dmi_ids[2]; /* Optional */
  40. const char *uid;
  41. const char *path;
  42. unsigned long long status;
  43. };
  44. #define ENTRY(status, hid, uid, path, cpu_model, dmi...) { \
  45. { { hid, }, {} }, \
  46. { X86_MATCH_INTEL_FAM6_MODEL(cpu_model, NULL), {} }, \
  47. { { .matches = dmi }, {} }, \
  48. uid, \
  49. path, \
  50. status, \
  51. }
  52. #define PRESENT_ENTRY_HID(hid, uid, cpu_model, dmi...) \
  53. ENTRY(ACPI_STA_DEFAULT, hid, uid, NULL, cpu_model, dmi)
  54. #define NOT_PRESENT_ENTRY_HID(hid, uid, cpu_model, dmi...) \
  55. ENTRY(0, hid, uid, NULL, cpu_model, dmi)
  56. #define PRESENT_ENTRY_PATH(path, cpu_model, dmi...) \
  57. ENTRY(ACPI_STA_DEFAULT, "", NULL, path, cpu_model, dmi)
  58. #define NOT_PRESENT_ENTRY_PATH(path, cpu_model, dmi...) \
  59. ENTRY(0, "", NULL, path, cpu_model, dmi)
  60. static const struct override_status_id override_status_ids[] = {
  61. /*
  62. * Bay / Cherry Trail PWM directly poked by GPU driver in win10,
  63. * but Linux uses a separate PWM driver, harmless if not used.
  64. */
  65. PRESENT_ENTRY_HID("80860F09", "1", ATOM_SILVERMONT, {}),
  66. PRESENT_ENTRY_HID("80862288", "1", ATOM_AIRMONT, {}),
  67. /* The Xiaomi Mi Pad 2 uses PWM2 for touchkeys backlight control */
  68. PRESENT_ENTRY_HID("80862289", "2", ATOM_AIRMONT, {
  69. DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"),
  70. DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"),
  71. }),
  72. /*
  73. * The INT0002 device is necessary to clear wakeup interrupt sources
  74. * on Cherry Trail devices, without it we get nobody cared IRQ msgs.
  75. */
  76. PRESENT_ENTRY_HID("INT0002", "1", ATOM_AIRMONT, {}),
  77. /*
  78. * On the Dell Venue 11 Pro 7130 and 7139, the DSDT hides
  79. * the touchscreen ACPI device until a certain time
  80. * after _SB.PCI0.GFX0.LCD.LCD1._ON gets called has passed
  81. * *and* _STA has been called at least 3 times since.
  82. */
  83. PRESENT_ENTRY_HID("SYNA7500", "1", HASWELL_L, {
  84. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  85. DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7130"),
  86. }),
  87. PRESENT_ENTRY_HID("SYNA7500", "1", HASWELL_L, {
  88. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  89. DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7139"),
  90. }),
  91. /*
  92. * The GPD win BIOS dated 20170221 has disabled the accelerometer, the
  93. * drivers sometimes cause crashes under Windows and this is how the
  94. * manufacturer has solved this :| The DMI match may not seem unique,
  95. * but it is. In the 67000+ DMI decode dumps from linux-hardware.org
  96. * only 116 have board_vendor set to "AMI Corporation" and of those 116
  97. * only the GPD win and pocket entries' board_name is "Default string".
  98. *
  99. * Unfortunately the GPD pocket also uses these strings and its BIOS
  100. * was copy-pasted from the GPD win, so it has a disabled KIOX000A
  101. * node which we should not enable, thus we also check the BIOS date.
  102. */
  103. PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, {
  104. DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  105. DMI_MATCH(DMI_BOARD_NAME, "Default string"),
  106. DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
  107. DMI_MATCH(DMI_BIOS_DATE, "02/21/2017")
  108. }),
  109. PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, {
  110. DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  111. DMI_MATCH(DMI_BOARD_NAME, "Default string"),
  112. DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
  113. DMI_MATCH(DMI_BIOS_DATE, "03/20/2017")
  114. }),
  115. PRESENT_ENTRY_HID("KIOX000A", "1", ATOM_AIRMONT, {
  116. DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  117. DMI_MATCH(DMI_BOARD_NAME, "Default string"),
  118. DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
  119. DMI_MATCH(DMI_BIOS_DATE, "05/25/2017")
  120. }),
  121. /*
  122. * The GPD win/pocket have a PCI wifi card, but its DSDT has the SDIO
  123. * mmc controller enabled and that has a child-device which _PS3
  124. * method sets a GPIO causing the PCI wifi card to turn off.
  125. * See above remark about uniqueness of the DMI match.
  126. */
  127. NOT_PRESENT_ENTRY_PATH("\\_SB_.PCI0.SDHB.BRC1", ATOM_AIRMONT, {
  128. DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  129. DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
  130. DMI_EXACT_MATCH(DMI_BOARD_SERIAL, "Default string"),
  131. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
  132. }),
  133. };
  134. bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status)
  135. {
  136. bool ret = false;
  137. unsigned int i;
  138. for (i = 0; i < ARRAY_SIZE(override_status_ids); i++) {
  139. if (!x86_match_cpu(override_status_ids[i].cpu_ids))
  140. continue;
  141. if (override_status_ids[i].dmi_ids[0].matches[0].slot &&
  142. !dmi_check_system(override_status_ids[i].dmi_ids))
  143. continue;
  144. if (override_status_ids[i].path) {
  145. struct acpi_buffer path = { ACPI_ALLOCATE_BUFFER, NULL };
  146. bool match;
  147. if (acpi_get_name(adev->handle, ACPI_FULL_PATHNAME, &path))
  148. continue;
  149. match = strcmp((char *)path.pointer, override_status_ids[i].path) == 0;
  150. kfree(path.pointer);
  151. if (!match)
  152. continue;
  153. } else {
  154. if (acpi_match_device_ids(adev, override_status_ids[i].hid))
  155. continue;
  156. if (!adev->pnp.unique_id ||
  157. strcmp(adev->pnp.unique_id, override_status_ids[i].uid))
  158. continue;
  159. }
  160. *status = override_status_ids[i].status;
  161. ret = true;
  162. break;
  163. }
  164. return ret;
  165. }
  166. /*
  167. * AMD systems from Renoir and Lucienne *require* that the NVME controller
  168. * is put into D3 over a Modern Standby / suspend-to-idle cycle.
  169. *
  170. * This is "typically" accomplished using the `StorageD3Enable`
  171. * property in the _DSD that is checked via the `acpi_storage_d3` function
  172. * but this property was introduced after many of these systems launched
  173. * and most OEM systems don't have it in their BIOS.
  174. *
  175. * The Microsoft documentation for StorageD3Enable mentioned that Windows has
  176. * a hardcoded allowlist for D3 support, which was used for these platforms.
  177. *
  178. * This allows quirking on Linux in a similar fashion.
  179. *
  180. * Cezanne systems shouldn't *normally* need this as the BIOS includes
  181. * StorageD3Enable. But for two reasons we have added it.
  182. * 1) The BIOS on a number of Dell systems have ambiguity
  183. * between the same value used for _ADR on ACPI nodes GPP1.DEV0 and GPP1.NVME.
  184. * GPP1.NVME is needed to get StorageD3Enable node set properly.
  185. * https://bugzilla.kernel.org/show_bug.cgi?id=216440
  186. * https://bugzilla.kernel.org/show_bug.cgi?id=216773
  187. * https://bugzilla.kernel.org/show_bug.cgi?id=217003
  188. * 2) On at least one HP system StorageD3Enable is missing on the second NVME
  189. disk in the system.
  190. */
  191. static const struct x86_cpu_id storage_d3_cpu_ids[] = {
  192. X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 96, NULL), /* Renoir */
  193. X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 104, NULL), /* Lucienne */
  194. X86_MATCH_VENDOR_FAM_MODEL(AMD, 25, 80, NULL), /* Cezanne */
  195. {}
  196. };
  197. bool force_storage_d3(void)
  198. {
  199. return x86_match_cpu(storage_d3_cpu_ids);
  200. }
  201. /*
  202. * x86 ACPI boards which ship with only Android as their factory image usually
  203. * declare a whole bunch of bogus I2C devices in their ACPI tables and sometimes
  204. * there are issues with serdev devices on these boards too, e.g. the resource
  205. * points to the wrong serdev_controller.
  206. *
  207. * Instantiating I2C / serdev devs for these bogus devs causes various issues,
  208. * e.g. GPIO/IRQ resource conflicts because sometimes drivers do bind to them.
  209. * The Android x86 kernel fork shipped on these devices has some special code
  210. * to remove the bogus I2C clients (and AFAICT serdevs are ignored completely).
  211. *
  212. * The acpi_quirk_skip_*_enumeration() functions below are used by the I2C or
  213. * serdev code to skip instantiating any I2C or serdev devs on broken boards.
  214. *
  215. * In case of I2C an exception is made for HIDs on the i2c_acpi_known_good_ids
  216. * list. These are known to always be correct (and in case of the audio-codecs
  217. * the drivers heavily rely on the codec being enumerated through ACPI).
  218. *
  219. * Note these boards typically do actually have I2C and serdev devices,
  220. * just different ones then the ones described in their DSDT. The devices
  221. * which are actually present are manually instantiated by the
  222. * drivers/platform/x86/x86-android-tablets.c kernel module.
  223. */
  224. #define ACPI_QUIRK_SKIP_I2C_CLIENTS BIT(0)
  225. #define ACPI_QUIRK_UART1_TTY_UART2_SKIP BIT(1)
  226. #define ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY BIT(2)
  227. #define ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY BIT(3)
  228. static const struct dmi_system_id acpi_quirk_skip_dmi_ids[] = {
  229. /*
  230. * 1. Devices with only the skip / don't-skip AC and battery quirks,
  231. * sorted alphabetically.
  232. */
  233. {
  234. /* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */
  235. .matches = {
  236. DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
  237. },
  238. .driver_data = (void *)ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY
  239. },
  240. {
  241. /* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */
  242. .matches = {
  243. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  244. DMI_MATCH(DMI_PRODUCT_NAME, "80XF"),
  245. DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
  246. },
  247. .driver_data = (void *)ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY
  248. },
  249. /*
  250. * 2. Devices which also have the skip i2c/serdev quirks and which
  251. * need the x86-android-tablets module to properly work.
  252. */
  253. #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
  254. {
  255. .matches = {
  256. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  257. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
  258. },
  259. .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
  260. ACPI_QUIRK_UART1_TTY_UART2_SKIP |
  261. ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
  262. },
  263. {
  264. .matches = {
  265. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  266. DMI_MATCH(DMI_PRODUCT_NAME, "TF103C"),
  267. },
  268. .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
  269. ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
  270. },
  271. {
  272. /* Lenovo Yoga Tablet 2 1050F/L */
  273. .matches = {
  274. DMI_MATCH(DMI_SYS_VENDOR, "Intel Corp."),
  275. DMI_MATCH(DMI_PRODUCT_NAME, "VALLEYVIEW C0 PLATFORM"),
  276. DMI_MATCH(DMI_BOARD_NAME, "BYT-T FFD8"),
  277. /* Partial match on beginning of BIOS version */
  278. DMI_MATCH(DMI_BIOS_VERSION, "BLADE_21"),
  279. },
  280. .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
  281. ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
  282. },
  283. {
  284. /* Lenovo Yoga Tab 3 Pro X90F */
  285. .matches = {
  286. DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
  287. DMI_MATCH(DMI_PRODUCT_NAME, "CHERRYVIEW D1 PLATFORM"),
  288. DMI_MATCH(DMI_PRODUCT_VERSION, "Blade3-10A-001"),
  289. },
  290. .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
  291. ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
  292. },
  293. {
  294. /* Medion Lifetab S10346 */
  295. .matches = {
  296. DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  297. DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
  298. /* Way too generic, also match on BIOS data */
  299. DMI_MATCH(DMI_BIOS_DATE, "10/22/2015"),
  300. },
  301. .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
  302. ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
  303. },
  304. {
  305. /* Nextbook Ares 8 */
  306. .matches = {
  307. DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
  308. DMI_MATCH(DMI_PRODUCT_NAME, "M890BAP"),
  309. },
  310. .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
  311. ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
  312. },
  313. {
  314. /* Whitelabel (sold as various brands) TM800A550L */
  315. .matches = {
  316. DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
  317. DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
  318. /* Above strings are too generic, also match on BIOS version */
  319. DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
  320. },
  321. .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
  322. ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
  323. },
  324. #endif
  325. {}
  326. };
  327. #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
  328. static const struct acpi_device_id i2c_acpi_known_good_ids[] = {
  329. { "10EC5640", 0 }, /* RealTek ALC5640 audio codec */
  330. { "INT33F4", 0 }, /* X-Powers AXP288 PMIC */
  331. { "INT33FD", 0 }, /* Intel Crystal Cove PMIC */
  332. { "INT34D3", 0 }, /* Intel Whiskey Cove PMIC */
  333. { "NPCE69A", 0 }, /* Asus Transformer keyboard dock */
  334. {}
  335. };
  336. bool acpi_quirk_skip_i2c_client_enumeration(struct acpi_device *adev)
  337. {
  338. const struct dmi_system_id *dmi_id;
  339. long quirks;
  340. dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
  341. if (!dmi_id)
  342. return false;
  343. quirks = (unsigned long)dmi_id->driver_data;
  344. if (!(quirks & ACPI_QUIRK_SKIP_I2C_CLIENTS))
  345. return false;
  346. return acpi_match_device_ids(adev, i2c_acpi_known_good_ids);
  347. }
  348. EXPORT_SYMBOL_GPL(acpi_quirk_skip_i2c_client_enumeration);
  349. int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
  350. {
  351. struct acpi_device *adev = ACPI_COMPANION(controller_parent);
  352. const struct dmi_system_id *dmi_id;
  353. long quirks = 0;
  354. u64 uid;
  355. int ret;
  356. *skip = false;
  357. ret = acpi_dev_uid_to_integer(adev, &uid);
  358. if (ret)
  359. return 0;
  360. /* to not match on PNP enumerated debug UARTs */
  361. if (!dev_is_platform(controller_parent))
  362. return 0;
  363. dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
  364. if (dmi_id)
  365. quirks = (unsigned long)dmi_id->driver_data;
  366. if (quirks & ACPI_QUIRK_UART1_TTY_UART2_SKIP) {
  367. if (uid == 1)
  368. return -ENODEV; /* Create tty cdev instead of serdev */
  369. if (uid == 2)
  370. *skip = true;
  371. }
  372. return 0;
  373. }
  374. EXPORT_SYMBOL_GPL(acpi_quirk_skip_serdev_enumeration);
  375. #endif
  376. /* Lists of PMIC ACPI HIDs with an (often better) native charger driver */
  377. static const struct {
  378. const char *hid;
  379. int hrv;
  380. } acpi_skip_ac_and_battery_pmic_ids[] = {
  381. { "INT33F4", -1 }, /* X-Powers AXP288 PMIC */
  382. { "INT34D3", 3 }, /* Intel Cherrytrail Whiskey Cove PMIC */
  383. };
  384. bool acpi_quirk_skip_acpi_ac_and_battery(void)
  385. {
  386. const struct dmi_system_id *dmi_id;
  387. long quirks = 0;
  388. int i;
  389. dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
  390. if (dmi_id)
  391. quirks = (unsigned long)dmi_id->driver_data;
  392. if (quirks & ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY)
  393. return true;
  394. if (quirks & ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY)
  395. return false;
  396. for (i = 0; i < ARRAY_SIZE(acpi_skip_ac_and_battery_pmic_ids); i++) {
  397. if (acpi_dev_present(acpi_skip_ac_and_battery_pmic_ids[i].hid, "1",
  398. acpi_skip_ac_and_battery_pmic_ids[i].hrv)) {
  399. pr_info_once("found native %s PMIC, skipping ACPI AC and battery devices\n",
  400. acpi_skip_ac_and_battery_pmic_ids[i].hid);
  401. return true;
  402. }
  403. }
  404. return false;
  405. }
  406. EXPORT_SYMBOL_GPL(acpi_quirk_skip_acpi_ac_and_battery);