xref: /openbmc/linux/drivers/acpi/x86/utils.c (revision 72a361a5b91c77b33ab2533674fdcec4de3278d0)
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 	 */
573b6a70beSHans de Goede 	ENTRY("80860F09", "1", ICPU(INTEL_FAM6_ATOM_SILVERMONT1), {}),
583b6a70beSHans de Goede 	ENTRY("80862288", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT), {}),
59753a448cSHans de Goede 	/*
60753a448cSHans de Goede 	 * The INT0002 device is necessary to clear wakeup interrupt sources
61753a448cSHans de Goede 	 * on Cherry Trail devices, without it we get nobody cared IRQ msgs.
62753a448cSHans de Goede 	 */
633b6a70beSHans de Goede 	ENTRY("INT0002", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT), {}),
64b5cc1699SHans de Goede 	/*
65*72a361a5STristian Celestin 	 * On the Dell Venue 11 Pro 7130 and 7139, the DSDT hides
66*72a361a5STristian Celestin 	 * the touchscreen ACPI device until a certain time
67*72a361a5STristian Celestin 	 * after _SB.PCI0.GFX0.LCD.LCD1._ON gets called has passed
68*72a361a5STristian Celestin 	 * *and* _STA has been called at least 3 times since.
69b5cc1699SHans de Goede 	 */
70b5cc1699SHans de Goede 	ENTRY("SYNA7500", "1", ICPU(INTEL_FAM6_HASWELL_ULT), {
71b5cc1699SHans de Goede 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
72b5cc1699SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7130"),
73b5cc1699SHans de Goede 	      }),
74*72a361a5STristian Celestin 	ENTRY("SYNA7500", "1", ICPU(INTEL_FAM6_HASWELL_ULT), {
75*72a361a5STristian Celestin 		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
76*72a361a5STristian Celestin 		DMI_MATCH(DMI_PRODUCT_NAME, "Venue 11 Pro 7139"),
77*72a361a5STristian Celestin 	      }),
78*72a361a5STristian Celestin 
79906dc284SHans de Goede 	/*
801c3b44c0SHans de Goede 	 * The GPD win BIOS dated 20170221 has disabled the accelerometer, the
81906dc284SHans de Goede 	 * drivers sometimes cause crashes under Windows and this is how the
82906dc284SHans de Goede 	 * manufacturer has solved this :| Note that the the DMI data is less
83906dc284SHans de Goede 	 * generic then it seems, a board_vendor of "AMI Corporation" is quite
84906dc284SHans de Goede 	 * rare and a board_name of "Default String" also is rare.
851c3b44c0SHans de Goede 	 *
861c3b44c0SHans de Goede 	 * Unfortunately the GPD pocket also uses these strings and its BIOS
871c3b44c0SHans de Goede 	 * was copy-pasted from the GPD win, so it has a disabled KIOX000A
881c3b44c0SHans de Goede 	 * node which we should not enable, thus we also check the BIOS date.
89906dc284SHans de Goede 	 */
90906dc284SHans de Goede 	ENTRY("KIOX000A", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT), {
91906dc284SHans de Goede 		DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
92906dc284SHans de Goede 		DMI_MATCH(DMI_BOARD_NAME, "Default string"),
93906dc284SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
941c3b44c0SHans de Goede 		DMI_MATCH(DMI_BIOS_DATE, "02/21/2017")
951c3b44c0SHans de Goede 	      }),
961c3b44c0SHans de Goede 	ENTRY("KIOX000A", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT), {
971c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
981c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_NAME, "Default string"),
991c3b44c0SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
100906dc284SHans de Goede 		DMI_MATCH(DMI_BIOS_DATE, "03/20/2017")
101906dc284SHans de Goede 	      }),
1021c3b44c0SHans de Goede 	ENTRY("KIOX000A", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT), {
1031c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
1041c3b44c0SHans de Goede 		DMI_MATCH(DMI_BOARD_NAME, "Default string"),
1051c3b44c0SHans de Goede 		DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
1061c3b44c0SHans de Goede 		DMI_MATCH(DMI_BIOS_DATE, "05/25/2017")
1071c3b44c0SHans de Goede 	      }),
108b7ecf663SHans de Goede };
109b7ecf663SHans de Goede 
110b7ecf663SHans de Goede bool acpi_device_always_present(struct acpi_device *adev)
111b7ecf663SHans de Goede {
112b7ecf663SHans de Goede 	u32 *status = (u32 *)&adev->status;
113b7ecf663SHans de Goede 	u32 old_status = *status;
114b7ecf663SHans de Goede 	bool ret = false;
115b7ecf663SHans de Goede 	unsigned int i;
116b7ecf663SHans de Goede 
117b7ecf663SHans de Goede 	/* acpi_match_device_ids checks status, so set it to default */
118b7ecf663SHans de Goede 	*status = ACPI_STA_DEFAULT;
119b7ecf663SHans de Goede 	for (i = 0; i < ARRAY_SIZE(always_present_ids); i++) {
120b7ecf663SHans de Goede 		if (acpi_match_device_ids(adev, always_present_ids[i].hid))
121b7ecf663SHans de Goede 			continue;
122b7ecf663SHans de Goede 
123b7ecf663SHans de Goede 		if (!adev->pnp.unique_id ||
124b7ecf663SHans de Goede 		    strcmp(adev->pnp.unique_id, always_present_ids[i].uid))
125b7ecf663SHans de Goede 			continue;
126b7ecf663SHans de Goede 
127b7ecf663SHans de Goede 		if (!x86_match_cpu(always_present_ids[i].cpu_ids))
128b7ecf663SHans de Goede 			continue;
129b7ecf663SHans de Goede 
1303b6a70beSHans de Goede 		if (always_present_ids[i].dmi_ids[0].matches[0].slot &&
1313b6a70beSHans de Goede 		    !dmi_check_system(always_present_ids[i].dmi_ids))
1323b6a70beSHans de Goede 			continue;
1333b6a70beSHans de Goede 
134b7ecf663SHans de Goede 		if (old_status != ACPI_STA_DEFAULT) /* Log only once */
135b7ecf663SHans de Goede 			dev_info(&adev->dev,
136b7ecf663SHans de Goede 				 "Device [%s] is in always present list\n",
137b7ecf663SHans de Goede 				 adev->pnp.bus_id);
138b7ecf663SHans de Goede 
139b7ecf663SHans de Goede 		ret = true;
140b7ecf663SHans de Goede 		break;
141b7ecf663SHans de Goede 	}
142b7ecf663SHans de Goede 	*status = old_status;
143b7ecf663SHans de Goede 
144b7ecf663SHans de Goede 	return ret;
145b7ecf663SHans de Goede }
146