1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * X86 ACPI Utility Functions
4 *
5 * Copyright (C) 2017 Hans de Goede <hdegoede@redhat.com>
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
11 #define pr_fmt(fmt) "ACPI: " fmt
12
13 #include <linux/acpi.h>
14 #include <linux/dmi.h>
15 #include <linux/pci.h>
16 #include <linux/platform_device.h>
17 #include <asm/cpu_device_id.h>
18 #include <asm/intel-family.h>
19 #include "../internal.h"
20
21 /*
22 * Some ACPI devices are hidden (status == 0x0) in recent BIOS-es because
23 * some recent Windows drivers bind to one device but poke at multiple
24 * devices at the same time, so the others get hidden.
25 *
26 * Some BIOS-es (temporarily) hide specific APCI devices to work around Windows
27 * driver bugs. We use DMI matching to match known cases of this.
28 *
29 * Likewise sometimes some not-actually present devices are sometimes
30 * reported as present, which may cause issues.
31 *
32 * We work around this by using the below quirk list to override the status
33 * reported by the _STA method with a fixed value (ACPI_STA_DEFAULT or 0).
34 * Note this MUST only be done for devices where this is safe.
35 *
36 * This status overriding is limited to specific CPU (SoC) models both to
37 * avoid potentially causing trouble on other models and because some HIDs
38 * are re-used on different SoCs for completely different devices.
39 */
40 struct override_status_id {
41 struct acpi_device_id hid[2];
42 struct x86_cpu_id cpu_ids[2];
43 struct dmi_system_id dmi_ids[2]; /* Optional */
44 const char *uid;
45 const char *path;
46 unsigned long long status;
47 };
48
49 #define ENTRY(status, hid, uid, path, cpu_vfm, dmi...) { \
50 { { hid, }, {} }, \
51 { X86_MATCH_VFM(cpu_vfm, NULL), {} }, \
52 { { .matches = dmi }, {} }, \
53 uid, \
54 path, \
55 status, \
56 }
57
58 #define PRESENT_ENTRY_HID(hid, uid, cpu_vfm, dmi...) \
59 ENTRY(ACPI_STA_DEFAULT, hid, uid, NULL, cpu_vfm, dmi)
60
61 #define NOT_PRESENT_ENTRY_HID(hid, uid, cpu_vfm, dmi...) \
62 ENTRY(0, hid, uid, NULL, cpu_vfm, dmi)
63
64 #define PRESENT_ENTRY_PATH(path, cpu_vfm, dmi...) \
65 ENTRY(ACPI_STA_DEFAULT, "", NULL, path, cpu_vfm, dmi)
66
67 #define NOT_PRESENT_ENTRY_PATH(path, cpu_vfm, dmi...) \
68 ENTRY(0, "", NULL, path, cpu_vfm, dmi)
69
70 static const struct override_status_id override_status_ids[] = {
71 /*
72 * Bay / Cherry Trail PWM directly poked by GPU driver in win10,
73 * but Linux uses a separate PWM driver, harmless if not used.
74 */
75 PRESENT_ENTRY_HID("80860F09", "1", INTEL_ATOM_SILVERMONT, {}),
76 PRESENT_ENTRY_HID("80862288", "1", INTEL_ATOM_AIRMONT, {}),
77
78 /* The Xiaomi Mi Pad 2 uses PWM2 for touchkeys backlight control */
79 PRESENT_ENTRY_HID("80862289", "2", INTEL_ATOM_AIRMONT, {
80 DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"),
81 DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"),
82 }),
83
84 /*
85 * The INT0002 device is necessary to clear wakeup interrupt sources
86 * on Cherry Trail devices, without it we get nobody cared IRQ msgs.
87 */
88 PRESENT_ENTRY_HID("INT0002", "1", INTEL_ATOM_AIRMONT, {}),
89 /*
90 * On the Dell Venue 11 Pro 7130 and 7139, the DSDT hides
91 * the touchscreen ACPI device until a certain time
92 * after _SB.PCI0.GFX0.LCD.LCD1._ON gets called has passed
93 * *and* _STA has been called at least 3 times since.
94 */
95 PRESENT_ENTRY_HID("SYNA7500", "1", INTEL_HASWELL_L, {
96 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
97 DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7130"),
98 }),
99 PRESENT_ENTRY_HID("SYNA7500", "1", INTEL_HASWELL_L, {
100 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
101 DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7139"),
102 }),
103
104 /*
105 * The Dell XPS 15 9550 has a SMO8110 accelerometer /
106 * HDD freefall sensor which is wrongly marked as not present.
107 */
108 PRESENT_ENTRY_HID("SMO8810", "1", INTEL_SKYLAKE, {
109 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
110 DMI_MATCH(DMI_PRODUCT_NAME, "XPS 15 9550"),
111 }),
112
113 /*
114 * The GPD win BIOS dated 20170221 has disabled the accelerometer, the
115 * drivers sometimes cause crashes under Windows and this is how the
116 * manufacturer has solved this :| The DMI match may not seem unique,
117 * but it is. In the 67000+ DMI decode dumps from linux-hardware.org
118 * only 116 have board_vendor set to "AMI Corporation" and of those 116
119 * only the GPD win and pocket entries' board_name is "Default string".
120 *
121 * Unfortunately the GPD pocket also uses these strings and its BIOS
122 * was copy-pasted from the GPD win, so it has a disabled KIOX000A
123 * node which we should not enable, thus we also check the BIOS date.
124 */
125 PRESENT_ENTRY_HID("KIOX000A", "1", INTEL_ATOM_AIRMONT, {
126 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
127 DMI_MATCH(DMI_BOARD_NAME, "Default string"),
128 DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
129 DMI_MATCH(DMI_BIOS_DATE, "02/21/2017")
130 }),
131 PRESENT_ENTRY_HID("KIOX000A", "1", INTEL_ATOM_AIRMONT, {
132 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
133 DMI_MATCH(DMI_BOARD_NAME, "Default string"),
134 DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
135 DMI_MATCH(DMI_BIOS_DATE, "03/20/2017")
136 }),
137 PRESENT_ENTRY_HID("KIOX000A", "1", INTEL_ATOM_AIRMONT, {
138 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
139 DMI_MATCH(DMI_BOARD_NAME, "Default string"),
140 DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
141 DMI_MATCH(DMI_BIOS_DATE, "05/25/2017")
142 }),
143
144 /*
145 * The GPD win/pocket have a PCI wifi card, but its DSDT has the SDIO
146 * mmc controller enabled and that has a child-device which _PS3
147 * method sets a GPIO causing the PCI wifi card to turn off.
148 * See above remark about uniqueness of the DMI match.
149 */
150 NOT_PRESENT_ENTRY_PATH("\\_SB_.PCI0.SDHB.BRC1", INTEL_ATOM_AIRMONT, {
151 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
152 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
153 DMI_EXACT_MATCH(DMI_BOARD_SERIAL, "Default string"),
154 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
155 }),
156
157 /*
158 * The LSM303D on the Lenovo Yoga Tablet 2 series is present
159 * as both ACCL0001 and MAGN0001. As we can only ever register an
160 * i2c client for one of them, ignore MAGN0001.
161 */
162 NOT_PRESENT_ENTRY_HID("MAGN0001", "1", INTEL_ATOM_SILVERMONT, {
163 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
164 DMI_MATCH(DMI_PRODUCT_FAMILY, "YOGATablet2"),
165 }),
166 };
167
acpi_device_override_status(struct acpi_device * adev,unsigned long long * status)168 bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status)
169 {
170 bool ret = false;
171 unsigned int i;
172
173 for (i = 0; i < ARRAY_SIZE(override_status_ids); i++) {
174 if (!x86_match_cpu(override_status_ids[i].cpu_ids))
175 continue;
176
177 if (override_status_ids[i].dmi_ids[0].matches[0].slot &&
178 !dmi_check_system(override_status_ids[i].dmi_ids))
179 continue;
180
181 if (override_status_ids[i].path) {
182 struct acpi_buffer path = { ACPI_ALLOCATE_BUFFER, NULL };
183 bool match;
184
185 if (acpi_get_name(adev->handle, ACPI_FULL_PATHNAME, &path))
186 continue;
187
188 match = strcmp((char *)path.pointer, override_status_ids[i].path) == 0;
189 kfree(path.pointer);
190
191 if (!match)
192 continue;
193 } else {
194 if (acpi_match_device_ids(adev, override_status_ids[i].hid))
195 continue;
196
197 if (!acpi_dev_uid_match(adev, override_status_ids[i].uid))
198 continue;
199 }
200
201 *status = override_status_ids[i].status;
202 ret = true;
203 break;
204 }
205
206 return ret;
207 }
208
209 /*
210 * AMD systems from Renoir onwards *require* that the NVME controller
211 * is put into D3 over a Modern Standby / suspend-to-idle cycle.
212 *
213 * This is "typically" accomplished using the `StorageD3Enable`
214 * property in the _DSD that is checked via the `acpi_storage_d3` function
215 * but some OEM systems still don't have it in their BIOS.
216 *
217 * The Microsoft documentation for StorageD3Enable mentioned that Windows has
218 * a hardcoded allowlist for D3 support as well as a registry key to override
219 * the BIOS, which has been used for these cases.
220 *
221 * This allows quirking on Linux in a similar fashion.
222 *
223 * Cezanne systems shouldn't *normally* need this as the BIOS includes
224 * StorageD3Enable. But for two reasons we have added it.
225 * 1) The BIOS on a number of Dell systems have ambiguity
226 * between the same value used for _ADR on ACPI nodes GPP1.DEV0 and GPP1.NVME.
227 * GPP1.NVME is needed to get StorageD3Enable node set properly.
228 * https://bugzilla.kernel.org/show_bug.cgi?id=216440
229 * https://bugzilla.kernel.org/show_bug.cgi?id=216773
230 * https://bugzilla.kernel.org/show_bug.cgi?id=217003
231 * 2) On at least one HP system StorageD3Enable is missing on the second NVME
232 * disk in the system.
233 * 3) On at least one HP Rembrandt system StorageD3Enable is missing on the only
234 * NVME device.
235 */
force_storage_d3(void)236 bool force_storage_d3(void)
237 {
238 if (!cpu_feature_enabled(X86_FEATURE_ZEN))
239 return false;
240 return acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0;
241 }
242
243 /*
244 * x86 ACPI boards which ship with only Android as their factory image usually
245 * declare a whole bunch of bogus I2C devices in their ACPI tables and sometimes
246 * there are issues with serdev devices on these boards too, e.g. the resource
247 * points to the wrong serdev_controller.
248 *
249 * Instantiating I2C / serdev devs for these bogus devs causes various issues,
250 * e.g. GPIO/IRQ resource conflicts because sometimes drivers do bind to them.
251 * The Android x86 kernel fork shipped on these devices has some special code
252 * to remove the bogus I2C clients (and AFAICT serdevs are ignored completely).
253 *
254 * The acpi_quirk_skip_*_enumeration() functions below are used by the I2C or
255 * serdev code to skip instantiating any I2C or serdev devs on broken boards.
256 *
257 * In case of I2C an exception is made for HIDs on the i2c_acpi_known_good_ids
258 * list. These are known to always be correct (and in case of the audio-codecs
259 * the drivers heavily rely on the codec being enumerated through ACPI).
260 *
261 * Note these boards typically do actually have I2C and serdev devices,
262 * just different ones then the ones described in their DSDT. The devices
263 * which are actually present are manually instantiated by the
264 * drivers/platform/x86/x86-android-tablets.c kernel module.
265 */
266 #define ACPI_QUIRK_SKIP_I2C_CLIENTS BIT(0)
267 #define ACPI_QUIRK_UART1_SKIP BIT(1)
268 #define ACPI_QUIRK_UART1_TTY_UART2_SKIP BIT(2)
269 #define ACPI_QUIRK_PNP_UART1_SKIP BIT(3)
270 #define ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY BIT(4)
271 #define ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY BIT(5)
272 #define ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS BIT(6)
273
274 static const struct dmi_system_id acpi_quirk_skip_dmi_ids[] = {
275 /*
276 * 1. Devices with only the skip / don't-skip AC and battery quirks,
277 * sorted alphabetically.
278 */
279 {
280 /* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */
281 .matches = {
282 DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
283 },
284 .driver_data = (void *)ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY
285 },
286 {
287 /* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */
288 .matches = {
289 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
290 DMI_MATCH(DMI_PRODUCT_NAME, "80XF"),
291 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
292 },
293 .driver_data = (void *)ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY
294 },
295
296 /*
297 * 2. Devices which also have the skip i2c/serdev quirks and which
298 * need the x86-android-tablets module to properly work.
299 * Sorted alphabetically.
300 */
301 #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
302 {
303 /* Acer Iconia One 7 B1-750 */
304 .matches = {
305 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
306 DMI_MATCH(DMI_PRODUCT_NAME, "VESPA2"),
307 },
308 .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
309 ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
310 ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
311 },
312 {
313 /* Acer Iconia One 8 A1-840 (non FHD version) */
314 .matches = {
315 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
316 DMI_MATCH(DMI_PRODUCT_NAME, "BayTrail"),
317 /* Above strings are too generic also match BIOS date */
318 DMI_MATCH(DMI_BIOS_DATE, "04/01/2014"),
319 },
320 .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
321 ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
322 ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
323 },
324 {
325 /* Asus ME176C tablet */
326 .matches = {
327 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
328 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
329 },
330 .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
331 ACPI_QUIRK_UART1_TTY_UART2_SKIP |
332 ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
333 ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
334 },
335 {
336 /* Asus TF103C transformer 2-in-1 */
337 .matches = {
338 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
339 DMI_MATCH(DMI_PRODUCT_NAME, "TF103C"),
340 },
341 .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
342 ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
343 ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
344 },
345 {
346 /* Lenovo Yoga Book X90F/L */
347 .matches = {
348 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
349 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "CHERRYVIEW D1 PLATFORM"),
350 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "YETI-11"),
351 },
352 .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
353 ACPI_QUIRK_UART1_SKIP |
354 ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
355 ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
356 },
357 {
358 /* Lenovo Yoga Tablet 2 1050F/L */
359 .matches = {
360 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corp."),
361 DMI_MATCH(DMI_PRODUCT_NAME, "VALLEYVIEW C0 PLATFORM"),
362 DMI_MATCH(DMI_BOARD_NAME, "BYT-T FFD8"),
363 /* Partial match on beginning of BIOS version */
364 DMI_MATCH(DMI_BIOS_VERSION, "BLADE_21"),
365 },
366 .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
367 ACPI_QUIRK_PNP_UART1_SKIP |
368 ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
369 },
370 {
371 /* Lenovo Yoga Tab 3 Pro X90F */
372 .matches = {
373 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
374 DMI_MATCH(DMI_PRODUCT_VERSION, "Blade3-10A-001"),
375 },
376 .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
377 ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
378 ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
379 },
380 {
381 /* Medion Lifetab S10346 */
382 .matches = {
383 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
384 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
385 /* Way too generic, also match on BIOS data */
386 DMI_MATCH(DMI_BIOS_DATE, "10/22/2015"),
387 },
388 .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
389 ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
390 },
391 {
392 /* Nextbook Ares 8 (BYT version)*/
393 .matches = {
394 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
395 DMI_MATCH(DMI_PRODUCT_NAME, "M890BAP"),
396 },
397 .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
398 ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
399 ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
400 },
401 {
402 /* Nextbook Ares 8A (CHT version)*/
403 .matches = {
404 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
405 DMI_MATCH(DMI_PRODUCT_NAME, "CherryTrail"),
406 DMI_MATCH(DMI_BIOS_VERSION, "M882"),
407 },
408 .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
409 ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
410 },
411 {
412 /* Vexia Edu Atla 10 tablet 5V version */
413 .matches = {
414 /* Having all 3 of these not set is somewhat unique */
415 DMI_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
416 DMI_MATCH(DMI_PRODUCT_NAME, "To be filled by O.E.M."),
417 DMI_MATCH(DMI_BOARD_NAME, "To be filled by O.E.M."),
418 /* Above strings are too generic, also match on BIOS date */
419 DMI_MATCH(DMI_BIOS_DATE, "05/14/2015"),
420 },
421 .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
422 ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
423 },
424 {
425 /* Vexia Edu Atla 10 tablet 9V version */
426 .matches = {
427 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
428 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
429 /* Above strings are too generic, also match on BIOS date */
430 DMI_MATCH(DMI_BIOS_DATE, "08/25/2014"),
431 },
432 .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
433 ACPI_QUIRK_UART1_SKIP |
434 ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
435 ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
436 },
437 {
438 /* Whitelabel (sold as various brands) TM800A550L */
439 .matches = {
440 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
441 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
442 /* Above strings are too generic, also match on BIOS version */
443 DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
444 },
445 .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
446 ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
447 },
448 #endif
449 {}
450 };
451
452 #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
453 static const struct acpi_device_id i2c_acpi_known_good_ids[] = {
454 { "10EC5640", 0 }, /* RealTek ALC5640 audio codec */
455 { "10EC5651", 0 }, /* RealTek ALC5651 audio codec */
456 { "INT33F4", 0 }, /* X-Powers AXP288 PMIC */
457 { "INT33F5", 0 }, /* TI Dollar Cove PMIC */
458 { "INT33FD", 0 }, /* Intel Crystal Cove PMIC */
459 { "INT34D3", 0 }, /* Intel Whiskey Cove PMIC */
460 { "NPCE69A", 0 }, /* Asus Transformer keyboard dock */
461 {}
462 };
463
acpi_quirk_skip_i2c_client_enumeration(struct acpi_device * adev)464 bool acpi_quirk_skip_i2c_client_enumeration(struct acpi_device *adev)
465 {
466 const struct dmi_system_id *dmi_id;
467 long quirks;
468
469 dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
470 if (!dmi_id)
471 return false;
472
473 quirks = (unsigned long)dmi_id->driver_data;
474 if (!(quirks & ACPI_QUIRK_SKIP_I2C_CLIENTS))
475 return false;
476
477 return acpi_match_device_ids(adev, i2c_acpi_known_good_ids);
478 }
479 EXPORT_SYMBOL_GPL(acpi_quirk_skip_i2c_client_enumeration);
480
acpi_dmi_skip_serdev_enumeration(struct device * controller_parent,bool * skip)481 static int acpi_dmi_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
482 {
483 struct acpi_device *adev = ACPI_COMPANION(controller_parent);
484 const struct dmi_system_id *dmi_id;
485 long quirks = 0;
486 u64 uid = 0;
487
488 dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
489 if (!dmi_id)
490 return 0;
491
492 quirks = (unsigned long)dmi_id->driver_data;
493
494 /* uid is left at 0 on errors and 0 is not a valid UART UID */
495 acpi_dev_uid_to_integer(adev, &uid);
496
497 /* For PCI UARTs without an UID */
498 if (!uid && dev_is_pci(controller_parent)) {
499 struct pci_dev *pdev = to_pci_dev(controller_parent);
500
501 /*
502 * Devfn values for PCI UARTs on Bay Trail SoCs, which are
503 * the only devices where this fallback is necessary.
504 */
505 if (pdev->devfn == PCI_DEVFN(0x1e, 3))
506 uid = 1;
507 else if (pdev->devfn == PCI_DEVFN(0x1e, 4))
508 uid = 2;
509 }
510
511 if (!uid)
512 return 0;
513
514 if (!dev_is_platform(controller_parent) && !dev_is_pci(controller_parent)) {
515 /* PNP enumerated UARTs */
516 if ((quirks & ACPI_QUIRK_PNP_UART1_SKIP) && uid == 1)
517 *skip = true;
518
519 return 0;
520 }
521
522 if ((quirks & ACPI_QUIRK_UART1_SKIP) && uid == 1)
523 *skip = true;
524
525 if (quirks & ACPI_QUIRK_UART1_TTY_UART2_SKIP) {
526 if (uid == 1)
527 return -ENODEV; /* Create tty cdev instead of serdev */
528
529 if (uid == 2)
530 *skip = true;
531 }
532
533 return 0;
534 }
535
acpi_quirk_skip_gpio_event_handlers(void)536 bool acpi_quirk_skip_gpio_event_handlers(void)
537 {
538 const struct dmi_system_id *dmi_id;
539 long quirks;
540
541 dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
542 if (!dmi_id)
543 return false;
544
545 quirks = (unsigned long)dmi_id->driver_data;
546 return (quirks & ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS);
547 }
548 EXPORT_SYMBOL_GPL(acpi_quirk_skip_gpio_event_handlers);
549 #else
acpi_dmi_skip_serdev_enumeration(struct device * controller_parent,bool * skip)550 static int acpi_dmi_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
551 {
552 return 0;
553 }
554 #endif
555
acpi_quirk_skip_serdev_enumeration(struct device * controller_parent,bool * skip)556 int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
557 {
558 struct acpi_device *adev = ACPI_COMPANION(controller_parent);
559
560 *skip = false;
561
562 /*
563 * The DELL0501 ACPI HID represents an UART (CID is set to PNP0501) with
564 * a backlight-controller attached. There is no separate ACPI device with
565 * an UartSerialBusV2() resource to model the backlight-controller.
566 * Set skip to true so that the tty core creates a serdev ctrl device.
567 * The backlight driver will manually create the serdev client device.
568 */
569 if (adev && acpi_dev_hid_match(adev, "DELL0501")) {
570 *skip = true;
571 /*
572 * Create a platform dev for dell-uart-backlight to bind to.
573 * This is a static device, so no need to store the result.
574 */
575 platform_device_register_simple("dell-uart-backlight", PLATFORM_DEVID_NONE,
576 NULL, 0);
577 return 0;
578 }
579
580 return acpi_dmi_skip_serdev_enumeration(controller_parent, skip);
581 }
582 EXPORT_SYMBOL_GPL(acpi_quirk_skip_serdev_enumeration);
583
584 /* Lists of PMIC ACPI HIDs with an (often better) native charger driver */
585 static const struct {
586 const char *hid;
587 int hrv;
588 } acpi_skip_ac_and_battery_pmic_ids[] = {
589 { "INT33F4", -1 }, /* X-Powers AXP288 PMIC */
590 { "INT34D3", 3 }, /* Intel Cherrytrail Whiskey Cove PMIC */
591 };
592
acpi_quirk_skip_acpi_ac_and_battery(void)593 bool acpi_quirk_skip_acpi_ac_and_battery(void)
594 {
595 const struct dmi_system_id *dmi_id;
596 long quirks = 0;
597 int i;
598
599 dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
600 if (dmi_id)
601 quirks = (unsigned long)dmi_id->driver_data;
602
603 if (quirks & ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY)
604 return true;
605
606 if (quirks & ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY)
607 return false;
608
609 for (i = 0; i < ARRAY_SIZE(acpi_skip_ac_and_battery_pmic_ids); i++) {
610 if (acpi_dev_present(acpi_skip_ac_and_battery_pmic_ids[i].hid, "1",
611 acpi_skip_ac_and_battery_pmic_ids[i].hrv)) {
612 pr_info_once("found native %s PMIC, skipping ACPI AC and battery devices\n",
613 acpi_skip_ac_and_battery_pmic_ids[i].hid);
614 return true;
615 }
616 }
617
618 return false;
619 }
620 EXPORT_SYMBOL_GPL(acpi_quirk_skip_acpi_ac_and_battery);
621
622 /* This section provides a workaround for a specific x86 system
623 * which requires disabling of mwait to work correctly.
624 */
acpi_proc_quirk_set_no_mwait(const struct dmi_system_id * id)625 static int __init acpi_proc_quirk_set_no_mwait(const struct dmi_system_id *id)
626 {
627 pr_notice("%s detected - disabling mwait for CPU C-states\n",
628 id->ident);
629 boot_option_idle_override = IDLE_NOMWAIT;
630 return 0;
631 }
632
633 static const struct dmi_system_id acpi_proc_quirk_mwait_dmi_table[] __initconst = {
634 {
635 .callback = acpi_proc_quirk_set_no_mwait,
636 .ident = "Extensa 5220",
637 .matches = {
638 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
639 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
640 DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
641 DMI_MATCH(DMI_BOARD_NAME, "Columbia"),
642 },
643 .driver_data = NULL,
644 },
645 {}
646 };
647
acpi_proc_quirk_mwait_check(void)648 void __init acpi_proc_quirk_mwait_check(void)
649 {
650 /*
651 * Check whether the system is DMI table. If yes, OSPM
652 * should not use mwait for CPU-states.
653 */
654 dmi_check_system(acpi_proc_quirk_mwait_dmi_table);
655 }
656