xref: /openbmc/linux/drivers/acpi/x86/utils.c (revision fd5e9fccbd504c5179ab57ff695c610bca8809d6)
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 	},
372 	{
373 		/* Medion Lifetab S10346 */
374 		.matches = {
375 			DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
376 			DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
377 			/* Way too generic, also match on BIOS data */
378 			DMI_MATCH(DMI_BIOS_DATE, "10/22/2015"),
379 		},
380 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
381 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
382 	},
383 	{
384 		/* Nextbook Ares 8 (BYT version)*/
385 		.matches = {
386 			DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
387 			DMI_MATCH(DMI_PRODUCT_NAME, "M890BAP"),
388 		},
389 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
390 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
391 					ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
392 	},
393 	{
394 		/* Nextbook Ares 8A (CHT version)*/
395 		.matches = {
396 			DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
397 			DMI_MATCH(DMI_PRODUCT_NAME, "CherryTrail"),
398 			DMI_MATCH(DMI_BIOS_VERSION, "M882"),
399 		},
400 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
401 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
402 	},
403 	{
404 		/* Vexia Edu Atla 10 tablet 5V version */
405 		.matches = {
406 			/* Having all 3 of these not set is somewhat unique */
407 			DMI_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
408 			DMI_MATCH(DMI_PRODUCT_NAME, "To be filled by O.E.M."),
409 			DMI_MATCH(DMI_BOARD_NAME, "To be filled by O.E.M."),
410 			/* Above strings are too generic, also match on BIOS date */
411 			DMI_MATCH(DMI_BIOS_DATE, "05/14/2015"),
412 		},
413 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
414 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
415 	},
416 	{
417 		/* Vexia Edu Atla 10 tablet 9V version */
418 		.matches = {
419 			DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
420 			DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
421 			/* Above strings are too generic, also match on BIOS date */
422 			DMI_MATCH(DMI_BIOS_DATE, "08/25/2014"),
423 		},
424 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
425 					ACPI_QUIRK_UART1_SKIP |
426 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY |
427 					ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS),
428 	},
429 	{
430 		/* Whitelabel (sold as various brands) TM800A550L */
431 		.matches = {
432 			DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
433 			DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
434 			/* Above strings are too generic, also match on BIOS version */
435 			DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
436 		},
437 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
438 					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
439 	},
440 #endif
441 	{}
442 };
443 
444 #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
445 static const struct acpi_device_id i2c_acpi_known_good_ids[] = {
446 	{ "10EC5640", 0 }, /* RealTek ALC5640 audio codec */
447 	{ "10EC5651", 0 }, /* RealTek ALC5651 audio codec */
448 	{ "INT33F4", 0 },  /* X-Powers AXP288 PMIC */
449 	{ "INT33F5", 0 },  /* TI Dollar Cove PMIC */
450 	{ "INT33FD", 0 },  /* Intel Crystal Cove PMIC */
451 	{ "INT34D3", 0 },  /* Intel Whiskey Cove PMIC */
452 	{ "NPCE69A", 0 },  /* Asus Transformer keyboard dock */
453 	{}
454 };
455 
acpi_quirk_skip_i2c_client_enumeration(struct acpi_device * adev)456 bool acpi_quirk_skip_i2c_client_enumeration(struct acpi_device *adev)
457 {
458 	const struct dmi_system_id *dmi_id;
459 	long quirks;
460 
461 	dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
462 	if (!dmi_id)
463 		return false;
464 
465 	quirks = (unsigned long)dmi_id->driver_data;
466 	if (!(quirks & ACPI_QUIRK_SKIP_I2C_CLIENTS))
467 		return false;
468 
469 	return acpi_match_device_ids(adev, i2c_acpi_known_good_ids);
470 }
471 EXPORT_SYMBOL_GPL(acpi_quirk_skip_i2c_client_enumeration);
472 
acpi_dmi_skip_serdev_enumeration(struct device * controller_parent,bool * skip)473 static int acpi_dmi_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
474 {
475 	struct acpi_device *adev = ACPI_COMPANION(controller_parent);
476 	const struct dmi_system_id *dmi_id;
477 	long quirks = 0;
478 	u64 uid = 0;
479 
480 	dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
481 	if (!dmi_id)
482 		return 0;
483 
484 	quirks = (unsigned long)dmi_id->driver_data;
485 
486 	/* uid is left at 0 on errors and 0 is not a valid UART UID */
487 	acpi_dev_uid_to_integer(adev, &uid);
488 
489 	/* For PCI UARTs without an UID */
490 	if (!uid && dev_is_pci(controller_parent)) {
491 		struct pci_dev *pdev = to_pci_dev(controller_parent);
492 
493 		/*
494 		 * Devfn values for PCI UARTs on Bay Trail SoCs, which are
495 		 * the only devices where this fallback is necessary.
496 		 */
497 		if (pdev->devfn == PCI_DEVFN(0x1e, 3))
498 			uid = 1;
499 		else if (pdev->devfn == PCI_DEVFN(0x1e, 4))
500 			uid = 2;
501 	}
502 
503 	if (!uid)
504 		return 0;
505 
506 	if (!dev_is_platform(controller_parent) && !dev_is_pci(controller_parent)) {
507 		/* PNP enumerated UARTs */
508 		if ((quirks & ACPI_QUIRK_PNP_UART1_SKIP) && uid == 1)
509 			*skip = true;
510 
511 		return 0;
512 	}
513 
514 	if ((quirks & ACPI_QUIRK_UART1_SKIP) && uid == 1)
515 		*skip = true;
516 
517 	if (quirks & ACPI_QUIRK_UART1_TTY_UART2_SKIP) {
518 		if (uid == 1)
519 			return -ENODEV; /* Create tty cdev instead of serdev */
520 
521 		if (uid == 2)
522 			*skip = true;
523 	}
524 
525 	return 0;
526 }
527 
acpi_quirk_skip_gpio_event_handlers(void)528 bool acpi_quirk_skip_gpio_event_handlers(void)
529 {
530 	const struct dmi_system_id *dmi_id;
531 	long quirks;
532 
533 	dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
534 	if (!dmi_id)
535 		return false;
536 
537 	quirks = (unsigned long)dmi_id->driver_data;
538 	return (quirks & ACPI_QUIRK_SKIP_GPIO_EVENT_HANDLERS);
539 }
540 EXPORT_SYMBOL_GPL(acpi_quirk_skip_gpio_event_handlers);
541 #else
acpi_dmi_skip_serdev_enumeration(struct device * controller_parent,bool * skip)542 static int acpi_dmi_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
543 {
544 	return 0;
545 }
546 #endif
547 
acpi_quirk_skip_serdev_enumeration(struct device * controller_parent,bool * skip)548 int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *skip)
549 {
550 	*skip = false;
551 
552 	return acpi_dmi_skip_serdev_enumeration(controller_parent, skip);
553 }
554 EXPORT_SYMBOL_GPL(acpi_quirk_skip_serdev_enumeration);
555 
556 /* Lists of PMIC ACPI HIDs with an (often better) native charger driver */
557 static const struct {
558 	const char *hid;
559 	int hrv;
560 } acpi_skip_ac_and_battery_pmic_ids[] = {
561 	{ "INT33F4", -1 }, /* X-Powers AXP288 PMIC */
562 	{ "INT34D3",  3 }, /* Intel Cherrytrail Whiskey Cove PMIC */
563 };
564 
acpi_quirk_skip_acpi_ac_and_battery(void)565 bool acpi_quirk_skip_acpi_ac_and_battery(void)
566 {
567 	const struct dmi_system_id *dmi_id;
568 	long quirks = 0;
569 	int i;
570 
571 	dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
572 	if (dmi_id)
573 		quirks = (unsigned long)dmi_id->driver_data;
574 
575 	if (quirks & ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY)
576 		return true;
577 
578 	if (quirks & ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY)
579 		return false;
580 
581 	for (i = 0; i < ARRAY_SIZE(acpi_skip_ac_and_battery_pmic_ids); i++) {
582 		if (acpi_dev_present(acpi_skip_ac_and_battery_pmic_ids[i].hid, "1",
583 				     acpi_skip_ac_and_battery_pmic_ids[i].hrv)) {
584 			pr_info_once("found native %s PMIC, skipping ACPI AC and battery devices\n",
585 				     acpi_skip_ac_and_battery_pmic_ids[i].hid);
586 			return true;
587 		}
588 	}
589 
590 	return false;
591 }
592 EXPORT_SYMBOL_GPL(acpi_quirk_skip_acpi_ac_and_battery);
593 
594 /* This section provides a workaround for a specific x86 system
595  * which requires disabling of mwait to work correctly.
596  */
acpi_proc_quirk_set_no_mwait(const struct dmi_system_id * id)597 static int __init acpi_proc_quirk_set_no_mwait(const struct dmi_system_id *id)
598 {
599 	pr_notice("%s detected - disabling mwait for CPU C-states\n",
600 		  id->ident);
601 	boot_option_idle_override = IDLE_NOMWAIT;
602 	return 0;
603 }
604 
605 static const struct dmi_system_id acpi_proc_quirk_mwait_dmi_table[] __initconst = {
606 	{
607 		.callback = acpi_proc_quirk_set_no_mwait,
608 		.ident = "Extensa 5220",
609 		.matches =  {
610 			DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
611 			DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
612 			DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
613 			DMI_MATCH(DMI_BOARD_NAME, "Columbia"),
614 		},
615 		.driver_data = NULL,
616 	},
617 	{}
618 };
619 
acpi_proc_quirk_mwait_check(void)620 void __init acpi_proc_quirk_mwait_check(void)
621 {
622 	/*
623 	 * Check whether the system is DMI table. If yes, OSPM
624 	 * should not use mwait for CPU-states.
625 	 */
626 	dmi_check_system(acpi_proc_quirk_mwait_dmi_table);
627 }
628