Skip to content

Commit 57a1832

Browse files
jwrdegoederafaeljw
authored andcommitted
ACPI / x86: Introduce an acpi_quirk_skip_acpi_ac_and_battery() helper
Some x86 ACPI boards have broken AC and battery ACPI devices in their ACPI tables. This is often tied to these devices using certain PMICs where the factory OS image seems to be using native charger and fuel-gauge drivers instead. So far both the AC and battery drivers have almost identical checks for these PMICs including both of them having a DMI based mechanism to force usage of the ACPI AC and battery drivers on some boards even though one of these PMICs is present, with the same 2 boards listed in both driver's DMI tables for this. The only difference is that the AC driver checks for 2 PMICs and the battery driver only for one. This has grown this way because the other (Whiskey Cove) PMIC is only used on a few boards (3 known boards) and although some of these do have non working ACPI battery devices, their _STA method always returns 0, but that really should not be relied on. This patch factors out the shared checks into a new acpi_quirk_skip_acpi_ac_and_battery() helper and moves the AC and battery drivers over to this new helper. Note the DMI table is shared with acpi_quirk_skip_i2c_client_enumeration() and acpi_quirk_skip_serdev_enumeration(), because boards needing DMI quirks for either of these typically also have broken AC and battery ACPI devices. The ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY quirk is not set yet on boards already in this DMI table, to avoid introducing any functional changes in this refactoring patch. Besided sharing the code between the AC and battery drivers this refactoring also moves this quirk handling to under #ifdef CONFIG_X86, removing this x86 specific code from non x86 ACPI builds. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 8e0feb2 commit 57a1832

4 files changed

Lines changed: 84 additions & 83 deletions

File tree

drivers/acpi/ac.c

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,12 @@ static const struct acpi_device_id ac_device_ids[] = {
4848
};
4949
MODULE_DEVICE_TABLE(acpi, ac_device_ids);
5050

51-
/* Lists of PMIC ACPI HIDs with an (often better) native charger driver */
52-
static const struct acpi_ac_bl acpi_ac_blacklist[] = {
53-
{ "INT33F4", -1 }, /* X-Powers AXP288 PMIC */
54-
{ "INT34D3", 3 }, /* Intel Cherrytrail Whiskey Cove PMIC */
55-
};
56-
5751
#ifdef CONFIG_PM_SLEEP
5852
static int acpi_ac_resume(struct device *dev);
5953
#endif
6054
static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume);
6155

6256
static int ac_sleep_before_get_state_ms;
63-
static int ac_check_pmic = 1;
6457
static int ac_only;
6558

6659
static struct acpi_driver acpi_ac_driver = {
@@ -200,12 +193,6 @@ static int __init thinkpad_e530_quirk(const struct dmi_system_id *d)
200193
return 0;
201194
}
202195

203-
static int __init ac_do_not_check_pmic_quirk(const struct dmi_system_id *d)
204-
{
205-
ac_check_pmic = 0;
206-
return 0;
207-
}
208-
209196
static int __init ac_only_quirk(const struct dmi_system_id *d)
210197
{
211198
ac_only = 1;
@@ -214,29 +201,13 @@ static int __init ac_only_quirk(const struct dmi_system_id *d)
214201

215202
/* Please keep this list alphabetically sorted */
216203
static const struct dmi_system_id ac_dmi_table[] __initconst = {
217-
{
218-
/* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */
219-
.callback = ac_do_not_check_pmic_quirk,
220-
.matches = {
221-
DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
222-
},
223-
},
224204
{
225205
/* Kodlix GK45 returning incorrect state */
226206
.callback = ac_only_quirk,
227207
.matches = {
228208
DMI_MATCH(DMI_PRODUCT_NAME, "GK45"),
229209
},
230210
},
231-
{
232-
/* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */
233-
.callback = ac_do_not_check_pmic_quirk,
234-
.matches = {
235-
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
236-
DMI_MATCH(DMI_PRODUCT_NAME, "80XF"),
237-
DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
238-
},
239-
},
240211
{
241212
/* Lenovo Thinkpad e530, see comment in acpi_ac_notify() */
242213
.callback = thinkpad_e530_quirk,
@@ -341,23 +312,15 @@ static int acpi_ac_remove(struct acpi_device *device)
341312

342313
static int __init acpi_ac_init(void)
343314
{
344-
unsigned int i;
345315
int result;
346316

347317
if (acpi_disabled)
348318
return -ENODEV;
349319

350-
dmi_check_system(ac_dmi_table);
320+
if (acpi_quirk_skip_acpi_ac_and_battery())
321+
return -ENODEV;
351322

352-
if (ac_check_pmic) {
353-
for (i = 0; i < ARRAY_SIZE(acpi_ac_blacklist); i++)
354-
if (acpi_dev_present(acpi_ac_blacklist[i].hid, "1",
355-
acpi_ac_blacklist[i].hrv)) {
356-
pr_info("found native %s PMIC, not loading\n",
357-
acpi_ac_blacklist[i].hid);
358-
return -ENODEV;
359-
}
360-
}
323+
dmi_check_system(ac_dmi_table);
361324

362325
result = acpi_bus_register_driver(&acpi_ac_driver);
363326
if (result < 0)

drivers/acpi/battery.c

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ static bool battery_driver_registered;
5252
static int battery_bix_broken_package;
5353
static int battery_notification_delay_ms;
5454
static int battery_ac_is_broken;
55-
static int battery_check_pmic = 1;
5655
static unsigned int cache_time = 1000;
5756
module_param(cache_time, uint, 0644);
5857
MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
@@ -64,11 +63,6 @@ static const struct acpi_device_id battery_device_ids[] = {
6463

6564
MODULE_DEVICE_TABLE(acpi, battery_device_ids);
6665

67-
/* Lists of PMIC ACPI HIDs with an (often better) native battery driver */
68-
static const char * const acpi_battery_blacklist[] = {
69-
"INT33F4", /* X-Powers AXP288 PMIC */
70-
};
71-
7266
enum {
7367
ACPI_BATTERY_ALARM_PRESENT,
7468
ACPI_BATTERY_XINFO_PRESENT,
@@ -1104,13 +1098,6 @@ battery_ac_is_broken_quirk(const struct dmi_system_id *d)
11041098
return 0;
11051099
}
11061100

1107-
static int __init
1108-
battery_do_not_check_pmic_quirk(const struct dmi_system_id *d)
1109-
{
1110-
battery_check_pmic = 0;
1111-
return 0;
1112-
}
1113-
11141101
static const struct dmi_system_id bat_dmi_table[] __initconst = {
11151102
{
11161103
/* NEC LZ750/LS */
@@ -1139,22 +1126,6 @@ static const struct dmi_system_id bat_dmi_table[] __initconst = {
11391126
DMI_MATCH(DMI_BIOS_DATE, "08/22/2014"),
11401127
},
11411128
},
1142-
{
1143-
/* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */
1144-
.callback = battery_do_not_check_pmic_quirk,
1145-
.matches = {
1146-
DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
1147-
},
1148-
},
1149-
{
1150-
/* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */
1151-
.callback = battery_do_not_check_pmic_quirk,
1152-
.matches = {
1153-
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1154-
DMI_MATCH(DMI_PRODUCT_NAME, "80XF"),
1155-
DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
1156-
},
1157-
},
11581129
{},
11591130
};
11601131

@@ -1279,19 +1250,12 @@ static struct acpi_driver acpi_battery_driver = {
12791250

12801251
static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie)
12811252
{
1282-
unsigned int i;
12831253
int result;
12841254

1285-
dmi_check_system(bat_dmi_table);
1255+
if (acpi_quirk_skip_acpi_ac_and_battery())
1256+
return;
12861257

1287-
if (battery_check_pmic) {
1288-
for (i = 0; i < ARRAY_SIZE(acpi_battery_blacklist); i++)
1289-
if (acpi_dev_present(acpi_battery_blacklist[i], "1", -1)) {
1290-
pr_info("found native %s PMIC, not loading\n",
1291-
acpi_battery_blacklist[i]);
1292-
return;
1293-
}
1294-
}
1258+
dmi_check_system(bat_dmi_table);
12951259

12961260
result = acpi_bus_register_driver(&acpi_battery_driver);
12971261
battery_driver_registered = (result == 0);

drivers/acpi/x86/utils.c

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* Copyright (C) 2013-2015 Intel Corporation. All rights reserved.
99
*/
1010

11+
#define pr_fmt(fmt) "ACPI: " fmt
12+
1113
#include <linux/acpi.h>
1214
#include <linux/dmi.h>
1315
#include <linux/platform_device.h>
@@ -210,7 +212,6 @@ bool force_storage_d3(void)
210212
return x86_match_cpu(storage_d3_cpu_ids);
211213
}
212214

213-
#if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
214215
/*
215216
* x86 ACPI boards which ship with only Android as their factory image usually
216217
* declare a whole bunch of bogus I2C devices in their ACPI tables and sometimes
@@ -236,8 +237,36 @@ bool force_storage_d3(void)
236237
*/
237238
#define ACPI_QUIRK_SKIP_I2C_CLIENTS BIT(0)
238239
#define ACPI_QUIRK_UART1_TTY_UART2_SKIP BIT(1)
240+
#define ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY BIT(2)
241+
#define ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY BIT(3)
242+
243+
static const struct dmi_system_id acpi_quirk_skip_dmi_ids[] = {
244+
/*
245+
* 1. Devices with only the skip / don't-skip AC and battery quirks,
246+
* sorted alphabetically.
247+
*/
248+
{
249+
/* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */
250+
.matches = {
251+
DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
252+
},
253+
.driver_data = (void *)ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY
254+
},
255+
{
256+
/* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */
257+
.matches = {
258+
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
259+
DMI_MATCH(DMI_PRODUCT_NAME, "80XF"),
260+
DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
261+
},
262+
.driver_data = (void *)ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY
263+
},
239264

240-
static const struct dmi_system_id acpi_skip_serial_bus_enumeration_ids[] = {
265+
/*
266+
* 2. Devices which also have the skip i2c/serdev quirks and which
267+
* need the x86-android-tablets module to properly work.
268+
*/
269+
#if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
241270
{
242271
.matches = {
243272
DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
@@ -263,9 +292,11 @@ static const struct dmi_system_id acpi_skip_serial_bus_enumeration_ids[] = {
263292
},
264293
.driver_data = (void *)ACPI_QUIRK_SKIP_I2C_CLIENTS,
265294
},
295+
#endif
266296
{}
267297
};
268298

299+
#if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
269300
static const struct acpi_device_id i2c_acpi_known_good_ids[] = {
270301
{ "10EC5640", 0 }, /* RealTek ALC5640 audio codec */
271302
{ "INT33F4", 0 }, /* X-Powers AXP288 PMIC */
@@ -279,7 +310,7 @@ bool acpi_quirk_skip_i2c_client_enumeration(struct acpi_device *adev)
279310
const struct dmi_system_id *dmi_id;
280311
long quirks;
281312

282-
dmi_id = dmi_first_match(acpi_skip_serial_bus_enumeration_ids);
313+
dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
283314
if (!dmi_id)
284315
return false;
285316

@@ -303,7 +334,7 @@ int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *s
303334
if (!adev || !adev->pnp.unique_id || !dev_is_platform(controller_parent))
304335
return 0;
305336

306-
dmi_id = dmi_first_match(acpi_skip_serial_bus_enumeration_ids);
337+
dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
307338
if (dmi_id)
308339
quirks = (unsigned long)dmi_id->driver_data;
309340

@@ -319,3 +350,41 @@ int acpi_quirk_skip_serdev_enumeration(struct device *controller_parent, bool *s
319350
}
320351
EXPORT_SYMBOL_GPL(acpi_quirk_skip_serdev_enumeration);
321352
#endif
353+
354+
/* Lists of PMIC ACPI HIDs with an (often better) native charger driver */
355+
static const struct {
356+
const char *hid;
357+
int hrv;
358+
} acpi_skip_ac_and_battery_pmic_ids[] = {
359+
{ "INT33F4", -1 }, /* X-Powers AXP288 PMIC */
360+
{ "INT34D3", 3 }, /* Intel Cherrytrail Whiskey Cove PMIC */
361+
};
362+
363+
bool acpi_quirk_skip_acpi_ac_and_battery(void)
364+
{
365+
const struct dmi_system_id *dmi_id;
366+
long quirks = 0;
367+
int i;
368+
369+
dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids);
370+
if (dmi_id)
371+
quirks = (unsigned long)dmi_id->driver_data;
372+
373+
if (quirks & ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY)
374+
return true;
375+
376+
if (quirks & ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY)
377+
return false;
378+
379+
for (i = 0; i < ARRAY_SIZE(acpi_skip_ac_and_battery_pmic_ids); i++) {
380+
if (acpi_dev_present(acpi_skip_ac_and_battery_pmic_ids[i].hid, "1",
381+
acpi_skip_ac_and_battery_pmic_ids[i].hrv)) {
382+
pr_info_once("found native %s PMIC, skipping ACPI AC and battery devices\n",
383+
acpi_skip_ac_and_battery_pmic_ids[i].hid);
384+
return true;
385+
}
386+
}
387+
388+
return false;
389+
}
390+
EXPORT_SYMBOL_GPL(acpi_quirk_skip_acpi_ac_and_battery);

include/acpi/acpi_bus.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,12 +615,17 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev);
615615

616616
#ifdef CONFIG_X86
617617
bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status);
618+
bool acpi_quirk_skip_acpi_ac_and_battery(void);
618619
#else
619620
static inline bool acpi_device_override_status(struct acpi_device *adev,
620621
unsigned long long *status)
621622
{
622623
return false;
623624
}
625+
static inline bool acpi_quirk_skip_acpi_ac_and_battery(void)
626+
{
627+
return false;
628+
}
624629
#endif
625630

626631
#if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)

0 commit comments

Comments
 (0)