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