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