xref: /linux/drivers/acpi/x86/utils.c (revision 364eeb79a213fcf9164208b53764223ad522d6b3)
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 
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  */
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 	 */
300 #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
301 	{
302 		/* Acer Iconia One 7 B1-750 */
303 		.matches = {
304 			DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
305 			DMI_MATCH(DMI_PRODUCT_NAME, "VESPA2"),
306 		},
307 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
308 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
309 					ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
310 	},
311 	{
312 		.matches = {
313 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
314 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
315 		},
316 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
317 					ACPI_QUIRK_UART1_TTY_UART2_SKIP |
318 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
319 					ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
320 	},
321 	{
322 		/* Lenovo Yoga Book X90F/L */
323 		.matches = {
324 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
325 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "CHERRYVIEW D1 PLATFORM"),
326 			DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "YETI-11"),
327 		},
328 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
329 					ACPI_QUIRK_UART1_SKIP |
330 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
331 					ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
332 	},
333 	{
334 		.matches = {
335 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
336 			DMI_MATCH(DMI_PRODUCT_NAME, "TF103C"),
337 		},
338 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
339 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
340 					ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
341 	},
342 	{
343 		/* Lenovo Yoga Tablet 2 1050F/L */
344 		.matches = {
345 			DMI_MATCH(DMI_SYS_VENDOR, "Intel Corp."),
346 			DMI_MATCH(DMI_PRODUCT_NAME, "VALLEYVIEW C0 PLATFORM"),
347 			DMI_MATCH(DMI_BOARD_NAME, "BYT-T FFD8"),
348 			/* Partial match on beginning of BIOS version */
349 			DMI_MATCH(DMI_BIOS_VERSION, "BLADE_21"),
350 		},
351 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
352 					ACPI_QUIRK_PNP_UART1_SKIP |
353 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
354 	},
355 	{
356 		/* Lenovo Yoga Tab 3 Pro X90F */
357 		.matches = {
358 			DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
359 			DMI_MATCH(DMI_PRODUCT_VERSION, "Blade3-10A-001"),
360 		},
361 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
362 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
363 	},
364 	{
365 		/* Medion Lifetab S10346 */
366 		.matches = {
367 			DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
368 			DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
369 			/* Way too generic, also match on BIOS data */
370 			DMI_MATCH(DMI_BIOS_DATE, "10/22/2015"),
371 		},
372 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
373 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
374 	},
375 	{
376 		/* Nextbook Ares 8 (BYT version)*/
377 		.matches = {
378 			DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
379 			DMI_MATCH(DMI_PRODUCT_NAME, "M890BAP"),
380 		},
381 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
382 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
383 					ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
384 	},
385 	{
386 		/* Nextbook Ares 8A (CHT version)*/
387 		.matches = {
388 			DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
389 			DMI_MATCH(DMI_PRODUCT_NAME, "CherryTrail"),
390 			DMI_MATCH(DMI_BIOS_VERSION, "M882"),
391 		},
392 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
393 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
394 	},
395 	{
396 		/* Vexia Edu Atla 10 tablet 9V version */
397 		.matches = {
398 			DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
399 			DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
400 			/* Above strings are too generic, also match on BIOS date */
401 			DMI_MATCH(DMI_BIOS_DATE, "08/25/2014"),
402 		},
403 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
404 					ACPI_QUIRK_UART1_SKIP |
405 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
406 					ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
407 	},
408 	{
409 		/* Whitelabel (sold as various brands) TM800A550L */
410 		.matches = {
411 			DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
412 			DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
413 			/* Above strings are too generic, also match on BIOS version */
414 			DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
415 		},
416 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
417 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
418 	},
419 #endif
420 	{}
421 };
422 
423 #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
424 static const struct acpi_device_id i2c_acpi_known_good_ids[] = {
425 	{ "10EC5640", 0 }, /* RealTek ALC5640 audio codec */
426 	{ "10EC5651", 0 }, /* RealTek ALC5651 audio codec */
427 	{ "INT33F4", 0 },  /* X-Powers AXP288 PMIC */
428 	{ "INT33FD", 0 },  /* Intel Crystal Cove PMIC */
429 	{ "INT34D3", 0 },  /* Intel Whiskey Cove PMIC */
430 	{ "NPCE69A", 0 },  /* Asus Transformer keyboard dock */
431 	{}
432 };
433 
434 bool acpi_quirk_skip_i2c_client_enumeration(struct acpi_device *adev)
435 {
436 	const struct dmi_system_id *dmi_id;
437 	long quirks;
438 
439 	dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
440 	if (!dmi_id)
441 		return false;
442 
443 	quirks = (unsigned long)dmi_id->driver_data;
444 	if (!(quirks & ACPI_QUIRK_SKIP_I2C_CLIENTS))
445 		return false;
446 
447 	return acpi_match_device_ids(adev, i2c_acpi_known_good_ids);
448 }
449 EXPORT_SYMBOL_GPL(acpi_quirk_skip_i2c_client_enumeration);
450 
451 static int acpi_dmi_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
452 {
453 	struct acpi_device *adev = ACPI_COMPANION(controller_parent);
454 	const struct dmi_system_id *dmi_id;
455 	long quirks = 0;
456 	u64 uid = 0;
457 
458 	dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
459 	if (!dmi_id)
460 		return 0;
461 
462 	quirks = (unsigned long)dmi_id->driver_data;
463 
464 	/* uid is left at 0 on errors and 0 is not a valid UART UID */
465 	acpi_dev_uid_to_integer(adev, &uid);
466 
467 	/* For PCI UARTs without an UID */
468 	if (!uid && dev_is_pci(controller_parent)) {
469 		struct pci_dev *pdev = to_pci_dev(controller_parent);
470 
471 		/*
472 		 * Devfn values for PCI UARTs on Bay Trail SoCs, which are
473 		 * the only devices where this fallback is necessary.
474 		 */
475 		if (pdev->devfn == PCI_DEVFN(0x1e, 3))
476 			uid = 1;
477 		else if (pdev->devfn == PCI_DEVFN(0x1e, 4))
478 			uid = 2;
479 	}
480 
481 	if (!uid)
482 		return 0;
483 
484 	if (!dev_is_platform(controller_parent) && !dev_is_pci(controller_parent)) {
485 		/* PNP enumerated UARTs */
486 		if ((quirks & ACPI_QUIRK_PNP_UART1_SKIP) && uid == 1)
487 			*skip = true;
488 
489 		return 0;
490 	}
491 
492 	if ((quirks & ACPI_QUIRK_UART1_SKIP) && uid == 1)
493 		*skip = true;
494 
495 	if (quirks & ACPI_QUIRK_UART1_TTY_UART2_SKIP) {
496 		if (uid == 1)
497 			return -ENODEV; /* Create tty cdev instead of serdev */
498 
499 		if (uid == 2)
500 			*skip = true;
501 	}
502 
503 	return 0;
504 }
505 
506 bool acpi_quirk_skip_gpio_event_handlers(void)
507 {
508 	const struct dmi_system_id *dmi_id;
509 	long quirks;
510 
511 	dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
512 	if (!dmi_id)
513 		return false;
514 
515 	quirks = (unsigned long)dmi_id->driver_data;
516 	return (quirks & ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS);
517 }
518 EXPORT_SYMBOL_GPL(acpi_quirk_skip_gpio_event_handlers);
519 #else
520 static int acpi_dmi_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
521 {
522 	return 0;
523 }
524 #endif
525 
526 int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
527 {
528 	struct acpi_device *adev = ACPI_COMPANION(controller_parent);
529 
530 	*skip = false;
531 
532 	/*
533 	 * The DELL0501 ACPI HID represents an UART (CID is set to PNP0501) with
534 	 * a backlight-controller attached. There is no separate ACPI device with
535 	 * an UartSerialBusV2() resource to model the backlight-controller.
536 	 * Set skip to true so that the tty core creates a serdev ctrl device.
537 	 * The backlight driver will manually create the serdev client device.
538 	 */
539 	if (adev && acpi_dev_hid_match(adev, "DELL0501")) {
540 		*skip = true;
541 		/*
542 		 * Create a platform dev for dell-uart-backlight to bind to.
543 		 * This is a static device, so no need to store the result.
544 		 */
545 		platform_device_register_simple("dell-uart-backlight", PLATFORM_DEVID_NONE,
546 						NULL, 0);
547 		return 0;
548 	}
549 
550 	return acpi_dmi_skip_serdev_enumeration(controller_parent, skip);
551 }
552 EXPORT_SYMBOL_GPL(acpi_quirk_skip_serdev_enumeration);
553 
554 /* Lists of PMIC ACPI HIDs with an (often better) native charger driver */
555 static const struct {
556 	const char *hid;
557 	int hrv;
558 } acpi_skip_ac_and_battery_pmic_ids[] = {
559 	{ "INT33F4", -1 }, /* X-Powers AXP288 PMIC */
560 	{ "INT34D3",  3 }, /* Intel Cherrytrail Whiskey Cove PMIC */
561 };
562 
563 bool acpi_quirk_skip_acpi_ac_and_battery(void)
564 {
565 	const struct dmi_system_id *dmi_id;
566 	long quirks = 0;
567 	int i;
568 
569 	dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
570 	if (dmi_id)
571 		quirks = (unsigned long)dmi_id->driver_data;
572 
573 	if (quirks & ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY)
574 		return true;
575 
576 	if (quirks & ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY)
577 		return false;
578 
579 	for (i = 0; i < ARRAY_SIZE(acpi_skip_ac_and_battery_pmic_ids); i++) {
580 		if (acpi_dev_present(acpi_skip_ac_and_battery_pmic_ids[i].hid, "1",
581 				     acpi_skip_ac_and_battery_pmic_ids[i].hrv)) {
582 			pr_info_once("found native %s PMIC, skipping ACPI AC and battery devices\n",
583 				     acpi_skip_ac_and_battery_pmic_ids[i].hid);
584 			return true;
585 		}
586 	}
587 
588 	return false;
589 }
590 EXPORT_SYMBOL_GPL(acpi_quirk_skip_acpi_ac_and_battery);
591 
592 /* This section provides a workaround for a specific x86 system
593  * which requires disabling of mwait to work correctly.
594  */
595 static int __init acpi_proc_quirk_set_no_mwait(const struct dmi_system_id *id)
596 {
597 	pr_notice("%s detected - disabling mwait for CPU C-states\n",
598 		  id->ident);
599 	boot_option_idle_override = IDLE_NOMWAIT;
600 	return 0;
601 }
602 
603 static const struct dmi_system_id acpi_proc_quirk_mwait_dmi_table[] __initconst = {
604 	{
605 		.callback = acpi_proc_quirk_set_no_mwait,
606 		.ident = "Extensa 5220",
607 		.matches =  {
608 			DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
609 			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
610 			DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
611 			DMI_MATCH(DMI_BOARD_NAME, "Columbia"),
612 		},
613 		.driver_data = NULL,
614 	},
615 	{}
616 };
617 
618 void __init acpi_proc_quirk_mwait_check(void)
619 {
620 	/*
621 	 * Check whether the system is DMI table. If yes, OSPM
622 	 * should not use mwait for CPU-states.
623 	 */
624 	dmi_check_system(acpi_proc_quirk_mwait_dmi_table);
625 }
626