Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Hans de Goede and committed by
Rafael J. Wysocki
57a18322 8e0feb25

+84 -83
+3 -40
drivers/acpi/ac.c
··· 48 48 }; 49 49 MODULE_DEVICE_TABLE(acpi, ac_device_ids); 50 50 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 - 57 51 #ifdef CONFIG_PM_SLEEP 58 52 static int acpi_ac_resume(struct device *dev); 59 53 #endif 60 54 static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume); 61 55 62 56 static int ac_sleep_before_get_state_ms; 63 - static int ac_check_pmic = 1; 64 57 static int ac_only; 65 58 66 59 static struct acpi_driver acpi_ac_driver = { ··· 193 200 return 0; 194 201 } 195 202 196 - static int __init ac_do_not_check_pmic_quirk(const struct dmi_system_id *d) 197 - { 198 - ac_check_pmic = 0; 199 - return 0; 200 - } 201 - 202 203 static int __init ac_only_quirk(const struct dmi_system_id *d) 203 204 { 204 205 ac_only = 1; ··· 202 215 /* Please keep this list alphabetically sorted */ 203 216 static const struct dmi_system_id ac_dmi_table[] __initconst = { 204 217 { 205 - /* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */ 206 - .callback = ac_do_not_check_pmic_quirk, 207 - .matches = { 208 - DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"), 209 - }, 210 - }, 211 - { 212 218 /* Kodlix GK45 returning incorrect state */ 213 219 .callback = ac_only_quirk, 214 220 .matches = { 215 221 DMI_MATCH(DMI_PRODUCT_NAME, "GK45"), 216 - }, 217 - }, 218 - { 219 - /* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */ 220 - .callback = ac_do_not_check_pmic_quirk, 221 - .matches = { 222 - DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 223 - DMI_MATCH(DMI_PRODUCT_NAME, "80XF"), 224 - DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"), 225 222 }, 226 223 }, 227 224 { ··· 312 341 313 342 static int __init acpi_ac_init(void) 314 343 { 315 - unsigned int i; 316 344 int result; 317 345 318 346 if (acpi_disabled) 319 347 return -ENODEV; 320 348 321 - dmi_check_system(ac_dmi_table); 349 + if (acpi_quirk_skip_acpi_ac_and_battery()) 350 + return -ENODEV; 322 351 323 - if (ac_check_pmic) { 324 - for (i = 0; i < ARRAY_SIZE(acpi_ac_blacklist); i++) 325 - if (acpi_dev_present(acpi_ac_blacklist[i].hid, "1", 326 - acpi_ac_blacklist[i].hrv)) { 327 - pr_info("found native %s PMIC, not loading\n", 328 - acpi_ac_blacklist[i].hid); 329 - return -ENODEV; 330 - } 331 - } 352 + dmi_check_system(ac_dmi_table); 332 353 333 354 result = acpi_bus_register_driver(&acpi_ac_driver); 334 355 if (result < 0)
+3 -39
drivers/acpi/battery.c
··· 52 52 static int battery_bix_broken_package; 53 53 static int battery_notification_delay_ms; 54 54 static int battery_ac_is_broken; 55 - static int battery_check_pmic = 1; 56 55 static unsigned int cache_time = 1000; 57 56 module_param(cache_time, uint, 0644); 58 57 MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); ··· 62 63 }; 63 64 64 65 MODULE_DEVICE_TABLE(acpi, battery_device_ids); 65 - 66 - /* Lists of PMIC ACPI HIDs with an (often better) native battery driver */ 67 - static const char * const acpi_battery_blacklist[] = { 68 - "INT33F4", /* X-Powers AXP288 PMIC */ 69 - }; 70 66 71 67 enum { 72 68 ACPI_BATTERY_ALARM_PRESENT, ··· 1098 1104 return 0; 1099 1105 } 1100 1106 1101 - static int __init 1102 - battery_do_not_check_pmic_quirk(const struct dmi_system_id *d) 1103 - { 1104 - battery_check_pmic = 0; 1105 - return 0; 1106 - } 1107 - 1108 1107 static const struct dmi_system_id bat_dmi_table[] __initconst = { 1109 1108 { 1110 1109 /* NEC LZ750/LS */ ··· 1124 1137 DMI_MATCH(DMI_BIOS_VERSION, "3BAIR1013"), 1125 1138 /* Above matches are too generic, add bios-date match */ 1126 1139 DMI_MATCH(DMI_BIOS_DATE, "08/22/2014"), 1127 - }, 1128 - }, 1129 - { 1130 - /* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */ 1131 - .callback = battery_do_not_check_pmic_quirk, 1132 - .matches = { 1133 - DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"), 1134 - }, 1135 - }, 1136 - { 1137 - /* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */ 1138 - .callback = battery_do_not_check_pmic_quirk, 1139 - .matches = { 1140 - DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 1141 - DMI_MATCH(DMI_PRODUCT_NAME, "80XF"), 1142 - DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"), 1143 1140 }, 1144 1141 }, 1145 1142 {}, ··· 1250 1279 1251 1280 static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie) 1252 1281 { 1253 - unsigned int i; 1254 1282 int result; 1255 1283 1256 - dmi_check_system(bat_dmi_table); 1284 + if (acpi_quirk_skip_acpi_ac_and_battery()) 1285 + return; 1257 1286 1258 - if (battery_check_pmic) { 1259 - for (i = 0; i < ARRAY_SIZE(acpi_battery_blacklist); i++) 1260 - if (acpi_dev_present(acpi_battery_blacklist[i], "1", -1)) { 1261 - pr_info("found native %s PMIC, not loading\n", 1262 - acpi_battery_blacklist[i]); 1263 - return; 1264 - } 1265 - } 1287 + dmi_check_system(bat_dmi_table); 1266 1288 1267 1289 result = acpi_bus_register_driver(&acpi_battery_driver); 1268 1290 battery_driver_registered = (result == 0);
+73 -4
drivers/acpi/x86/utils.c
··· 8 8 * Copyright (C) 2013-2015 Intel Corporation. All rights reserved. 9 9 */ 10 10 11 + #define pr_fmt(fmt) "ACPI: " fmt 12 + 11 13 #include <linux/acpi.h> 12 14 #include <linux/dmi.h> 13 15 #include <linux/platform_device.h> ··· 212 210 return x86_match_cpu(storage_d3_cpu_ids); 213 211 } 214 212 215 - #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS) 216 213 /* 217 214 * x86 ACPI boards which ship with only Android as their factory image usually 218 215 * declare a whole bunch of bogus I2C devices in their ACPI tables and sometimes ··· 237 236 */ 238 237 #define ACPI_QUIRK_SKIP_I2C_CLIENTS BIT(0) 239 238 #define ACPI_QUIRK_UART1_TTY_UART2_SKIP BIT(1) 239 + #define ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY BIT(2) 240 + #define ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY BIT(3) 240 241 241 - static const struct dmi_system_id acpi_skip_serial_bus_enumeration_ids[] = { 242 + static const struct dmi_system_id acpi_quirk_skip_dmi_ids[] = { 243 + /* 244 + * 1. Devices with only the skip / don't-skip AC and battery quirks, 245 + * sorted alphabetically. 246 + */ 247 + { 248 + /* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */ 249 + .matches = { 250 + DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"), 251 + }, 252 + .driver_data = (void *)ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY 253 + }, 254 + { 255 + /* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */ 256 + .matches = { 257 + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 258 + DMI_MATCH(DMI_PRODUCT_NAME, "80XF"), 259 + DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"), 260 + }, 261 + .driver_data = (void *)ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY 262 + }, 263 + 264 + /* 265 + * 2. Devices which also have the skip i2c/serdev quirks and which 266 + * need the x86-android-tablets module to properly work. 267 + */ 268 + #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS) 242 269 { 243 270 .matches = { 244 271 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), ··· 292 263 }, 293 264 .driver_data = (void *)ACPI_QUIRK_SKIP_I2C_CLIENTS, 294 265 }, 266 + #endif 295 267 {} 296 268 }; 297 269 270 + #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS) 298 271 static const struct acpi_device_id i2c_acpi_known_good_ids[] = { 299 272 { "10EC5640", 0 }, /* RealTek ALC5640 audio codec */ 300 273 { "INT33F4", 0 }, /* X-Powers AXP288 PMIC */ ··· 310 279 const struct dmi_system_id *dmi_id; 311 280 long quirks; 312 281 313 - dmi_id = dmi_first_match(acpi_skip_serial_bus_enumeration_ids); 282 + dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids); 314 283 if (!dmi_id) 315 284 return false; 316 285 ··· 334 303 if (!adev || !adev->pnp.unique_id || !dev_is_platform(controller_parent)) 335 304 return 0; 336 305 337 - dmi_id = dmi_first_match(acpi_skip_serial_bus_enumeration_ids); 306 + dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids); 338 307 if (dmi_id) 339 308 quirks = (unsigned long)dmi_id->driver_data; 340 309 ··· 350 319 } 351 320 EXPORT_SYMBOL_GPL(acpi_quirk_skip_serdev_enumeration); 352 321 #endif 322 + 323 + /* Lists of PMIC ACPI HIDs with an (often better) native charger driver */ 324 + static const struct { 325 + const char *hid; 326 + int hrv; 327 + } acpi_skip_ac_and_battery_pmic_ids[] = { 328 + { "INT33F4", -1 }, /* X-Powers AXP288 PMIC */ 329 + { "INT34D3", 3 }, /* Intel Cherrytrail Whiskey Cove PMIC */ 330 + }; 331 + 332 + bool acpi_quirk_skip_acpi_ac_and_battery(void) 333 + { 334 + const struct dmi_system_id *dmi_id; 335 + long quirks = 0; 336 + int i; 337 + 338 + dmi_id = dmi_first_match(acpi_quirk_skip_dmi_ids); 339 + if (dmi_id) 340 + quirks = (unsigned long)dmi_id->driver_data; 341 + 342 + if (quirks & ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY) 343 + return true; 344 + 345 + if (quirks & ACPI_QUIRK_USE_ACPI_AC_AND_BATTERY) 346 + return false; 347 + 348 + for (i = 0; i < ARRAY_SIZE(acpi_skip_ac_and_battery_pmic_ids); i++) { 349 + if (acpi_dev_present(acpi_skip_ac_and_battery_pmic_ids[i].hid, "1", 350 + acpi_skip_ac_and_battery_pmic_ids[i].hrv)) { 351 + pr_info_once("found native %s PMIC, skipping ACPI AC and battery devices\n", 352 + acpi_skip_ac_and_battery_pmic_ids[i].hid); 353 + return true; 354 + } 355 + } 356 + 357 + return false; 358 + } 359 + EXPORT_SYMBOL_GPL(acpi_quirk_skip_acpi_ac_and_battery);
+5
include/acpi/acpi_bus.h
··· 615 615 616 616 #ifdef CONFIG_X86 617 617 bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status); 618 + bool acpi_quirk_skip_acpi_ac_and_battery(void); 618 619 #else 619 620 static inline bool acpi_device_override_status(struct acpi_device *adev, 620 621 unsigned long long *status) 622 + { 623 + return false; 624 + } 625 + static inline bool acpi_quirk_skip_acpi_ac_and_battery(void) 621 626 { 622 627 return false; 623 628 }