xref: /openbmc/linux/drivers/acpi/x86/utils.c (revision 6485fc18faa01e8845b1e5bb55118e633f84d1f2)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2b7ecf663SHans de Goede /*
3b7ecf663SHans de Goede  * X86 ACPI Utility Functions
4b7ecf663SHans de Goede  *
5b7ecf663SHans de Goede  * Copyright (C) 2017 Hans de Goede <hdegoede@redhat.com>
6b7ecf663SHans de Goede  *
7b7ecf663SHans de Goede  * Based on various non upstream patches to support the CHT Whiskey Cove PMIC:
8b7ecf663SHans de Goede  * Copyright (C) 2013-2015 Intel Corporation. All rights reserved.
9b7ecf663SHans de Goede  */
10b7ecf663SHans de Goede 
11b7ecf663SHans de Goede #include <linux/acpi.h>
123b6a70beSHans de Goede #include <linux/dmi.h>
13b7ecf663SHans de Goede #include <asm/cpu_device_id.h>
14b7ecf663SHans de Goede #include <asm/intel-family.h>
15b7ecf663SHans de Goede #include "../internal.h"
16b7ecf663SHans de Goede 
17b7ecf663SHans de Goede /*
18b7ecf663SHans de Goede  * Some ACPI devices are hidden (status == 0x0) in recent BIOS-es because
19b7ecf663SHans de Goede  * some recent Windows drivers bind to one device but poke at multiple
20b7ecf663SHans de Goede  * devices at the same time, so the others get hidden.
213b6a70beSHans de Goede  *
223b6a70beSHans de Goede  * Some BIOS-es (temporarily) hide specific APCI devices to work around Windows
233b6a70beSHans de Goede  * driver bugs. We use DMI matching to match known cases of this.
243b6a70beSHans de Goede  *
25b7ecf663SHans de Goede  * We work around this by always reporting ACPI_STA_DEFAULT for these
26b7ecf663SHans de Goede  * devices. Note this MUST only be done for devices where this is safe.
27b7ecf663SHans de Goede  *
28b7ecf663SHans de Goede  * This forcing of devices to be present is limited to specific CPU (SoC)
29b7ecf663SHans de Goede  * models both to avoid potentially causing trouble on other models and
30b7ecf663SHans de Goede  * because some HIDs are re-used on different SoCs for completely
31b7ecf663SHans de Goede  * different devices.
32b7ecf663SHans de Goede  */
33b7ecf663SHans de Goede struct always_present_id {
34b7ecf663SHans de Goede 	struct acpi_device_id hid[2];
35b7ecf663SHans de Goede 	struct x86_cpu_id cpu_ids[2];
363b6a70beSHans de Goede 	struct dmi_system_id dmi_ids[2]; /* Optional */
37b7ecf663SHans de Goede 	const char *uid;
38b7ecf663SHans de Goede };
39b7ecf663SHans de Goede 
40e36cf2f7SThomas Gleixner #define X86_MATCH(model)	X86_MATCH_INTEL_FAM6_MODEL(model, NULL)
41b7ecf663SHans de Goede 
423b6a70beSHans de Goede #define ENTRY(hid, uid, cpu_models, dmi...) {				\
43b7ecf663SHans de Goede 	{ { hid, }, {} },						\
44b7ecf663SHans de Goede 	{ cpu_models, {} },						\
453b6a70beSHans de Goede 	{ { .matches = dmi }, {} },					\
46b7ecf663SHans de Goede 	uid,								\
47b7ecf663SHans de Goede }
48b7ecf663SHans de Goede 
49b7ecf663SHans de Goede static const struct always_present_id always_present_ids[] = {
50b7ecf663SHans de Goede 	/*
51b7ecf663SHans de Goede 	 * Bay / Cherry Trail PWM directly poked by GPU driver in win10,
52b7ecf663SHans de Goede 	 * but Linux uses a separate PWM driver, harmless if not used.
53b7ecf663SHans de Goede 	 */
54e36cf2f7SThomas Gleixner 	ENTRY("80860F09", "1", X86_MATCH(ATOM_SILVERMONT), {}),
55e36cf2f7SThomas Gleixner 	ENTRY("80862288", "1", X86_MATCH(ATOM_AIRMONT), {}),
56ff6cdfd7SYauhen Kharuzhy 
57ff6cdfd7SYauhen Kharuzhy 	/* Lenovo Yoga Book uses PWM2 for keyboard backlight control */
58e36cf2f7SThomas Gleixner 	ENTRY("80862289", "2", X86_MATCH(ATOM_AIRMONT), {
59ff6cdfd7SYauhen Kharuzhy 			DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9"),
60ff6cdfd7SYauhen Kharuzhy 		}),
61753a448cSHans de Goede 	/*
62753a448cSHans de Goede 	 * The INT0002 device is necessary to clear wakeup interrupt sources
63753a448cSHans de Goede 	 * on Cherry Trail devices, without it we get nobody cared IRQ msgs.
64753a448cSHans de Goede 	 */
65e36cf2f7SThomas Gleixner 	ENTRY("INT0002", "1", X86_MATCH(ATOM_AIRMONT), {}),
66b5cc1699SHans de Goede 	/*
6772a361a5STristian Celestin 	 * On the Dell Venue 11 Pro 7130 and 7139, the DSDT hides
6872a361a5STristian Celestin 	 * the touchscreen ACPI device until a certain time
6972a361a5STristian Celestin 	 * after _SB.PCI0.GFX0.LCD.LCD1._ON gets called has passed
7072a361a5STristian Celestin 	 * *and* _STA has been called at least 3 times since.
71b5cc1699SHans de Goede 	 */
72e36cf2f7SThomas Gleixner 	ENTRY("SYNA7500", "1", X86_MATCH(HASWELL_L), {
73b5cc1699SHans de Goede 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
74b5cc1699SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7130"),
75b5cc1699SHans de Goede 	      }),
76e36cf2f7SThomas Gleixner 	ENTRY("SYNA7500", "1", X86_MATCH(HASWELL_L), {
7772a361a5STristian Celestin 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
7872a361a5STristian Celestin 		DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7139"),
7972a361a5STristian Celestin 	      }),
8072a361a5STristian Celestin 
81906dc284SHans de Goede 	/*
821c3b44c0SHans de Goede 	 * The GPD win BIOS dated 20170221 has disabled the accelerometer, the
83906dc284SHans de Goede 	 * drivers sometimes cause crashes under Windows and this is how the
84906dc284SHans de Goede 	 * manufacturer has solved this :| Note that the the DMI data is less
85906dc284SHans de Goede 	 * generic then it seems, a board_vendor of "AMI Corporation" is quite
86906dc284SHans de Goede 	 * rare and a board_name of "Default String" also is rare.
871c3b44c0SHans de Goede 	 *
881c3b44c0SHans de Goede 	 * Unfortunately the GPD pocket also uses these strings and its BIOS
891c3b44c0SHans de Goede 	 * was copy-pasted from the GPD win, so it has a disabled KIOX000A
901c3b44c0SHans de Goede 	 * node which we should not enable, thus we also check the BIOS date.
91906dc284SHans de Goede 	 */
92e36cf2f7SThomas Gleixner 	ENTRY("KIOX000A", "1", X86_MATCH(ATOM_AIRMONT), {
93906dc284SHans de Goede 		DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
94906dc284SHans de Goede 		DMI_MATCH(DMI_BOARD_NAME, "Default string"),
95906dc284SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
961c3b44c0SHans de Goede 		DMI_MATCH(DMI_BIOS_DATE, "02/21/2017")
971c3b44c0SHans de Goede 	      }),
98e36cf2f7SThomas Gleixner 	ENTRY("KIOX000A", "1", X86_MATCH(ATOM_AIRMONT), {
991c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
1001c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_NAME, "Default string"),
1011c3b44c0SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
102906dc284SHans de Goede 		DMI_MATCH(DMI_BIOS_DATE, "03/20/2017")
103906dc284SHans de Goede 	      }),
104e36cf2f7SThomas Gleixner 	ENTRY("KIOX000A", "1", X86_MATCH(ATOM_AIRMONT), {
1051c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
1061c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_NAME, "Default string"),
1071c3b44c0SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
1081c3b44c0SHans de Goede 		DMI_MATCH(DMI_BIOS_DATE, "05/25/2017")
1091c3b44c0SHans de Goede 	      }),
110b7ecf663SHans de Goede };
111b7ecf663SHans de Goede 
112b7ecf663SHans de Goede bool acpi_device_always_present(struct acpi_device *adev)
113b7ecf663SHans de Goede {
114b7ecf663SHans de Goede 	bool ret = false;
115b7ecf663SHans de Goede 	unsigned int i;
116b7ecf663SHans de Goede 
117b7ecf663SHans de Goede 	for (i = 0; i < ARRAY_SIZE(always_present_ids); i++) {
118b7ecf663SHans de Goede 		if (acpi_match_device_ids(adev, always_present_ids[i].hid))
119b7ecf663SHans de Goede 			continue;
120b7ecf663SHans de Goede 
121b7ecf663SHans de Goede 		if (!adev->pnp.unique_id ||
122b7ecf663SHans de Goede 		    strcmp(adev->pnp.unique_id, always_present_ids[i].uid))
123b7ecf663SHans de Goede 			continue;
124b7ecf663SHans de Goede 
125b7ecf663SHans de Goede 		if (!x86_match_cpu(always_present_ids[i].cpu_ids))
126b7ecf663SHans de Goede 			continue;
127b7ecf663SHans de Goede 
1283b6a70beSHans de Goede 		if (always_present_ids[i].dmi_ids[0].matches[0].slot &&
1293b6a70beSHans de Goede 		    !dmi_check_system(always_present_ids[i].dmi_ids))
1303b6a70beSHans de Goede 			continue;
1313b6a70beSHans de Goede 
132b7ecf663SHans de Goede 		ret = true;
133b7ecf663SHans de Goede 		break;
134b7ecf663SHans de Goede 	}
135b7ecf663SHans de Goede 
136b7ecf663SHans de Goede 	return ret;
137b7ecf663SHans de Goede }
138*6485fc18SMario Limonciello 
139*6485fc18SMario Limonciello /*
140*6485fc18SMario Limonciello  * AMD systems from Renoir and Lucienne *require* that the NVME controller
141*6485fc18SMario Limonciello  * is put into D3 over a Modern Standby / suspend-to-idle cycle.
142*6485fc18SMario Limonciello  *
143*6485fc18SMario Limonciello  * This is "typically" accomplished using the `StorageD3Enable`
144*6485fc18SMario Limonciello  * property in the _DSD that is checked via the `acpi_storage_d3` function
145*6485fc18SMario Limonciello  * but this property was introduced after many of these systems launched
146*6485fc18SMario Limonciello  * and most OEM systems don't have it in their BIOS.
147*6485fc18SMario Limonciello  *
148*6485fc18SMario Limonciello  * The Microsoft documentation for StorageD3Enable mentioned that Windows has
149*6485fc18SMario Limonciello  * a hardcoded allowlist for D3 support, which was used for these platforms.
150*6485fc18SMario Limonciello  *
151*6485fc18SMario Limonciello  * This allows quirking on Linux in a similar fashion.
152*6485fc18SMario Limonciello  */
153*6485fc18SMario Limonciello static const struct x86_cpu_id storage_d3_cpu_ids[] = {
154*6485fc18SMario Limonciello 	X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 96, NULL),	/* Renoir */
155*6485fc18SMario Limonciello 	X86_MATCH_VENDOR_FAM_MODEL(AMD, 23, 104, NULL),	/* Lucienne */
156*6485fc18SMario Limonciello 	{}
157*6485fc18SMario Limonciello };
158*6485fc18SMario Limonciello 
159*6485fc18SMario Limonciello bool force_storage_d3(void)
160*6485fc18SMario Limonciello {
161*6485fc18SMario Limonciello 	return x86_match_cpu(storage_d3_cpu_ids);
162*6485fc18SMario Limonciello }
163