xref: /openbmc/linux/drivers/acpi/x86/utils.c (revision ff6cdfd71495e2b7995b6ec95480d15f89e3beef)
1b7ecf663SHans de Goede /*
2b7ecf663SHans de Goede  * X86 ACPI Utility Functions
3b7ecf663SHans de Goede  *
4b7ecf663SHans de Goede  * Copyright (C) 2017 Hans de Goede <hdegoede@redhat.com>
5b7ecf663SHans de Goede  *
6b7ecf663SHans de Goede  * Based on various non upstream patches to support the CHT Whiskey Cove PMIC:
7b7ecf663SHans de Goede  * Copyright (C) 2013-2015 Intel Corporation. All rights reserved.
8b7ecf663SHans de Goede  *
9b7ecf663SHans de Goede  * This program is free software; you can redistribute it and/or modify
10b7ecf663SHans de Goede  * it under the terms of the GNU General Public License version 2 as
11b7ecf663SHans de Goede  * published by the Free Software Foundation.
12b7ecf663SHans de Goede  */
13b7ecf663SHans de Goede 
14b7ecf663SHans de Goede #include <linux/acpi.h>
153b6a70beSHans de Goede #include <linux/dmi.h>
16b7ecf663SHans de Goede #include <asm/cpu_device_id.h>
17b7ecf663SHans de Goede #include <asm/intel-family.h>
18b7ecf663SHans de Goede #include "../internal.h"
19b7ecf663SHans de Goede 
20b7ecf663SHans de Goede /*
21b7ecf663SHans de Goede  * Some ACPI devices are hidden (status == 0x0) in recent BIOS-es because
22b7ecf663SHans de Goede  * some recent Windows drivers bind to one device but poke at multiple
23b7ecf663SHans de Goede  * devices at the same time, so the others get hidden.
243b6a70beSHans de Goede  *
253b6a70beSHans de Goede  * Some BIOS-es (temporarily) hide specific APCI devices to work around Windows
263b6a70beSHans de Goede  * driver bugs. We use DMI matching to match known cases of this.
273b6a70beSHans de Goede  *
28b7ecf663SHans de Goede  * We work around this by always reporting ACPI_STA_DEFAULT for these
29b7ecf663SHans de Goede  * devices. Note this MUST only be done for devices where this is safe.
30b7ecf663SHans de Goede  *
31b7ecf663SHans de Goede  * This forcing of devices to be present is limited to specific CPU (SoC)
32b7ecf663SHans de Goede  * models both to avoid potentially causing trouble on other models and
33b7ecf663SHans de Goede  * because some HIDs are re-used on different SoCs for completely
34b7ecf663SHans de Goede  * different devices.
35b7ecf663SHans de Goede  */
36b7ecf663SHans de Goede struct always_present_id {
37b7ecf663SHans de Goede 	struct acpi_device_id hid[2];
38b7ecf663SHans de Goede 	struct x86_cpu_id cpu_ids[2];
393b6a70beSHans de Goede 	struct dmi_system_id dmi_ids[2]; /* Optional */
40b7ecf663SHans de Goede 	const char *uid;
41b7ecf663SHans de Goede };
42b7ecf663SHans de Goede 
43b7ecf663SHans de Goede #define ICPU(model)	{ X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, }
44b7ecf663SHans de Goede 
453b6a70beSHans de Goede #define ENTRY(hid, uid, cpu_models, dmi...) {				\
46b7ecf663SHans de Goede 	{ { hid, }, {} },						\
47b7ecf663SHans de Goede 	{ cpu_models, {} },						\
483b6a70beSHans de Goede 	{ { .matches = dmi }, {} },					\
49b7ecf663SHans de Goede 	uid,								\
50b7ecf663SHans de Goede }
51b7ecf663SHans de Goede 
52b7ecf663SHans de Goede static const struct always_present_id always_present_ids[] = {
53b7ecf663SHans de Goede 	/*
54b7ecf663SHans de Goede 	 * Bay / Cherry Trail PWM directly poked by GPU driver in win10,
55b7ecf663SHans de Goede 	 * but Linux uses a separate PWM driver, harmless if not used.
56b7ecf663SHans de Goede 	 */
57f2c4db1bSPeter Zijlstra 	ENTRY("80860F09", "1", ICPU(INTEL_FAM6_ATOM_SILVERMONT), {}),
583b6a70beSHans de Goede 	ENTRY("80862288", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT), {}),
59*ff6cdfd7SYauhen Kharuzhy 
60*ff6cdfd7SYauhen Kharuzhy 	/* Lenovo Yoga Book uses PWM2 for keyboard backlight control */
61*ff6cdfd7SYauhen Kharuzhy 	ENTRY("80862289", "2", ICPU(INTEL_FAM6_ATOM_AIRMONT), {
62*ff6cdfd7SYauhen Kharuzhy 			DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9"),
63*ff6cdfd7SYauhen Kharuzhy 		}),
64753a448cSHans de Goede 	/*
65753a448cSHans de Goede 	 * The INT0002 device is necessary to clear wakeup interrupt sources
66753a448cSHans de Goede 	 * on Cherry Trail devices, without it we get nobody cared IRQ msgs.
67753a448cSHans de Goede 	 */
683b6a70beSHans de Goede 	ENTRY("INT0002", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT), {}),
69b5cc1699SHans de Goede 	/*
7072a361a5STristian Celestin 	 * On the Dell Venue 11 Pro 7130 and 7139, the DSDT hides
7172a361a5STristian Celestin 	 * the touchscreen ACPI device until a certain time
7272a361a5STristian Celestin 	 * after _SB.PCI0.GFX0.LCD.LCD1._ON gets called has passed
7372a361a5STristian Celestin 	 * *and* _STA has been called at least 3 times since.
74b5cc1699SHans de Goede 	 */
75b5cc1699SHans de Goede 	ENTRY("SYNA7500", "1", ICPU(INTEL_FAM6_HASWELL_ULT), {
76b5cc1699SHans de Goede 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
77b5cc1699SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7130"),
78b5cc1699SHans de Goede 	      }),
7972a361a5STristian Celestin 	ENTRY("SYNA7500", "1", ICPU(INTEL_FAM6_HASWELL_ULT), {
8072a361a5STristian Celestin 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
8172a361a5STristian Celestin 		DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7139"),
8272a361a5STristian Celestin 	      }),
8372a361a5STristian Celestin 
84906dc284SHans de Goede 	/*
851c3b44c0SHans de Goede 	 * The GPD win BIOS dated 20170221 has disabled the accelerometer, the
86906dc284SHans de Goede 	 * drivers sometimes cause crashes under Windows and this is how the
87906dc284SHans de Goede 	 * manufacturer has solved this :| Note that the the DMI data is less
88906dc284SHans de Goede 	 * generic then it seems, a board_vendor of "AMI Corporation" is quite
89906dc284SHans de Goede 	 * rare and a board_name of "Default String" also is rare.
901c3b44c0SHans de Goede 	 *
911c3b44c0SHans de Goede 	 * Unfortunately the GPD pocket also uses these strings and its BIOS
921c3b44c0SHans de Goede 	 * was copy-pasted from the GPD win, so it has a disabled KIOX000A
931c3b44c0SHans de Goede 	 * node which we should not enable, thus we also check the BIOS date.
94906dc284SHans de Goede 	 */
95906dc284SHans de Goede 	ENTRY("KIOX000A", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT), {
96906dc284SHans de Goede 		DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
97906dc284SHans de Goede 		DMI_MATCH(DMI_BOARD_NAME, "Default string"),
98906dc284SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
991c3b44c0SHans de Goede 		DMI_MATCH(DMI_BIOS_DATE, "02/21/2017")
1001c3b44c0SHans de Goede 	      }),
1011c3b44c0SHans de Goede 	ENTRY("KIOX000A", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT), {
1021c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
1031c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_NAME, "Default string"),
1041c3b44c0SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
105906dc284SHans de Goede 		DMI_MATCH(DMI_BIOS_DATE, "03/20/2017")
106906dc284SHans de Goede 	      }),
1071c3b44c0SHans de Goede 	ENTRY("KIOX000A", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT), {
1081c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
1091c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_NAME, "Default string"),
1101c3b44c0SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
1111c3b44c0SHans de Goede 		DMI_MATCH(DMI_BIOS_DATE, "05/25/2017")
1121c3b44c0SHans de Goede 	      }),
113b7ecf663SHans de Goede };
114b7ecf663SHans de Goede 
115b7ecf663SHans de Goede bool acpi_device_always_present(struct acpi_device *adev)
116b7ecf663SHans de Goede {
117b7ecf663SHans de Goede 	bool ret = false;
118b7ecf663SHans de Goede 	unsigned int i;
119b7ecf663SHans de Goede 
120b7ecf663SHans de Goede 	for (i = 0; i < ARRAY_SIZE(always_present_ids); i++) {
121b7ecf663SHans de Goede 		if (acpi_match_device_ids(adev, always_present_ids[i].hid))
122b7ecf663SHans de Goede 			continue;
123b7ecf663SHans de Goede 
124b7ecf663SHans de Goede 		if (!adev->pnp.unique_id ||
125b7ecf663SHans de Goede 		    strcmp(adev->pnp.unique_id, always_present_ids[i].uid))
126b7ecf663SHans de Goede 			continue;
127b7ecf663SHans de Goede 
128b7ecf663SHans de Goede 		if (!x86_match_cpu(always_present_ids[i].cpu_ids))
129b7ecf663SHans de Goede 			continue;
130b7ecf663SHans de Goede 
1313b6a70beSHans de Goede 		if (always_present_ids[i].dmi_ids[0].matches[0].slot &&
1323b6a70beSHans de Goede 		    !dmi_check_system(always_present_ids[i].dmi_ids))
1333b6a70beSHans de Goede 			continue;
1343b6a70beSHans de Goede 
135b7ecf663SHans de Goede 		ret = true;
136b7ecf663SHans de Goede 		break;
137b7ecf663SHans de Goede 	}
138b7ecf663SHans de Goede 
139b7ecf663SHans de Goede 	return ret;
140b7ecf663SHans de Goede }
141