Linux Audio

Check our new training course

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