Skip to contentSkip to conversation

ACPI / x86: ac and battery device quirk work

PATCH Applied Hans de Goede 2 participants 7 messages Dec 30, 2021 – Jan 5, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ACPI / x86: ac and battery device quirk work

Hi Rafael,

Here are 2 patches for ACPI ac and battery device quirk handling on x86, the first one refactors the almost identical quirk handling in ac.c and battery.c out into a shared helper.

And the 2nd patch then uses the now shared code to also skip / ignore ac and battery devices on x86 Android tablets with known broken DSDTs.

Note this applies on top of my:
"[PATCH v2 0/3] ACPI / pdx86: Add support for x86 Android tablets with broken DSDTs" series which you've just merged into your bleeding edge branch.

Regards,

Hans

Hans de Goede (2):
ACPI / x86: Introduce an acpi_quirk_skip_acpi_ac_and_battery() helper ACPI / x86: Skip ac and battery devices on x86 Android tablets with
broken DSDTs

 drivers/acpi/ac.c        | 43 ++------------------
 drivers/acpi/battery.c   | 42 ++------------------
 drivers/acpi/x86/utils.c | 86 ++++++++++++++++++++++++++++++++++++----
 include/acpi/acpi_bus.h  |  5 +++
 4 files changed, 90 insertions(+), 86 deletions(-)
Signature · 1 line
2.33.1
#1 lore raw

PATCH 1/2 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.

---
 drivers/acpi/ac.c        | 43 ++--------------------
 drivers/acpi/battery.c   | 42 ++--------------------
 drivers/acpi/x86/utils.c | 77 +++++++++++++++++++++++++++++++++++++---
 include/acpi/acpi_bus.h  |  5 +++
 4 files changed, 84 insertions(+), 83 deletions(-)
drivers/acpi/ac.c +3 -40
index 81aff651a0d4..db487ff9dd1b 100644
@@ -48,19 +48,12 @@ static const struct acpi_device_id ac_device_ids[] = {
 };
 MODULE_DEVICE_TABLE(acpi, ac_device_ids);
 
-/* Lists of PMIC ACPI HIDs with an (often better) native charger driver */
-static const struct acpi_ac_bl acpi_ac_blacklist[] = {
-	{ "INT33F4", -1 }, /* X-Powers AXP288 PMIC */
-	{ "INT34D3",  3 }, /* Intel Cherrytrail Whiskey Cove PMIC */
-};
-
 #ifdef CONFIG_PM_SLEEP
 static int acpi_ac_resume(struct device *dev);
 #endif
 static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume);
 
 static int ac_sleep_before_get_state_ms;
-static int ac_check_pmic = 1;
 static int ac_only;
 
 static struct acpi_driver acpi_ac_driver = {
@@ -200,12 +193,6 @@ static int __init thinkpad_e530_quirk(const struct dmi_system_id *d)
 	return 0;
 }
 
-static int __init ac_do_not_check_pmic_quirk(const struct dmi_system_id *d)
-{
-	ac_check_pmic = 0;
-	return 0;
-}
-
 static int __init ac_only_quirk(const struct dmi_system_id *d)
 {
 	ac_only = 1;
@@ -214,13 +201,6 @@ static int __init ac_only_quirk(const struct dmi_system_id *d)
 
 /* Please keep this list alphabetically sorted */
 static const struct dmi_system_id ac_dmi_table[]  __initconst = {
-	{
-		/* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */
-		.callback = ac_do_not_check_pmic_quirk,
-		.matches = {
-			DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
-		},
-	},
 	{
 		/* Kodlix GK45 returning incorrect state */
 		.callback = ac_only_quirk,
@@ -228,15 +208,6 @@ static const struct dmi_system_id ac_dmi_table[]  __initconst = {
 			DMI_MATCH(DMI_PRODUCT_NAME, "GK45"),
 		},
 	},
-	{
-		/* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */
-		.callback = ac_do_not_check_pmic_quirk,
-		.matches = {
-			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
-			DMI_MATCH(DMI_PRODUCT_NAME, "80XF"),
-			DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
-		},
-	},
 	{
 		/* Lenovo Thinkpad e530, see comment in acpi_ac_notify() */
 		.callback = thinkpad_e530_quirk,
@@ -341,23 +312,15 @@ static int acpi_ac_remove(struct acpi_device *device)
 
 static int __init acpi_ac_init(void)
 {
-	unsigned int i;
 	int result;
 
 	if (acpi_disabled)
 		return -ENODEV;
 
-	dmi_check_system(ac_dmi_table);
+	if (acpi_quirk_skip_acpi_ac_and_battery())
+		return -ENODEV;
 
-	if (ac_check_pmic) {
-		for (i = 0; i < ARRAY_SIZE(acpi_ac_blacklist); i++)
-			if (acpi_dev_present(acpi_ac_blacklist[i].hid, "1",
-					     acpi_ac_blacklist[i].hrv)) {
-				pr_info("found native %s PMIC, not loading\n",
-					acpi_ac_blacklist[i].hid);
-				return -ENODEV;
-			}
-	}
+	dmi_check_system(ac_dmi_table);
 
 	result = acpi_bus_register_driver(&acpi_ac_driver);
 	if (result < 0)
drivers/acpi/battery.c +3 -39

75 lines not on this page · raw message

drivers/acpi/x86/utils.c +73 -4

120 lines not on this page · raw message

include/acpi/acpi_bus.h +5 -0
index 102b1cf433c7..e0fd99462ddd 100644
@@ -616,12 +616,17 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev);
 
 #ifdef CONFIG_X86
 bool acpi_device_override_status(struct acpi_device *adev, unsigned long long *status);
+bool acpi_quirk_skip_acpi_ac_and_battery(void);
 #else
 static inline bool acpi_device_override_status(struct acpi_device *adev,
 					       unsigned long long *status)
 {
 	return false;
 }
+static inline bool acpi_quirk_skip_acpi_ac_and_battery(void)
+{
+	return false;
+}
 #endif
 
 #if IS_ENABLED(CONFIG_X86_ANDROID_TABLETS)
Signature · 1 line
2.33.1
#2 lore raw

PATCH 2/2 ACPI / x86: Skip ac and battery devices on x86 Android tablets with broken DSDTs

In reply to Hans de Goede

Sofar all of the tablets for which the skip i2c-client/serdev enumeration quirks have been added also all have broken ACPI ac / battery devices extend the existing quirks for these tablets to also skip the broken ac / battery devices.

---
 drivers/acpi/x86/utils.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/acpi/x86/utils.c +6 -3
index 5411f2f1254e..ffdeed5334d6 100644
@@ -273,14 +273,16 @@ static const struct dmi_system_id acpi_quirk_skip_dmi_ids[] = {
 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
 		},
 		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
-					ACPI_QUIRK_UART1_TTY_UART2_SKIP),
+					ACPI_QUIRK_UART1_TTY_UART2_SKIP |
+					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
 	},
 	{
 		.matches = {
 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
 			DMI_MATCH(DMI_PRODUCT_NAME, "TF103C"),
 		},
-		.driver_data = (void *)ACPI_QUIRK_SKIP_I2C_CLIENTS,
+		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
+					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
 	},
 	{
 		/* Whitelabel (sold as various brands) TM800A550L */
@@ -290,7 +292,8 @@ static const struct dmi_system_id acpi_quirk_skip_dmi_ids[] = {
 			/* Above strings are too generic, also match on BIOS version */
 			DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
 		},
-		.driver_data = (void *)ACPI_QUIRK_SKIP_I2C_CLIENTS,
+		.driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
+					ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
 	},
 #endif
 	{}
Signature · 1 line
2.33.1
maintainer Applied
#3 lore raw
In reply to Hans de Goede
Quoted 24 lines · Hans de Goede

Hi Rafael,

Here are 2 patches for ACPI ac and battery device quirk handling on x86, the first one refactors the almost identical quirk handling in ac.c and battery.c out into a shared helper.

And the 2nd patch then uses the now shared code to also skip / ignore ac and battery devices on x86 Android tablets with known broken DSDTs.

Note this applies on top of my:
"[PATCH v2 0/3] ACPI / pdx86: Add support for x86 Android tablets with broken DSDTs" series which you've just merged into your bleeding edge branch.

Regards,

Hans

Hans de Goede (2):
ACPI / x86: Introduce an acpi_quirk_skip_acpi_ac_and_battery() helper ACPI / x86: Skip ac and battery devices on x86 Android tablets with
broken DSDTs

Quoted 5 lines
 drivers/acpi/ac.c        | 43 ++------------------
 drivers/acpi/battery.c   | 42 ++------------------
 drivers/acpi/x86/utils.c | 86 ++++++++++++++++++++++++++++++++++++----
 include/acpi/acpi_bus.h  |  5 +++
 4 files changed, 90 insertions(+), 86 deletions(-)

Applied as 5.17 material.

Note that the changes here clashed with some recent battery driver changes, so I needed to resolve the merge conflict. Please double check the result.

Thanks!

#4 lore raw

Hi Rafael,

Quoted 31 lines · Rafael J. Wysocki
Quoted 24 lines · Hans de Goede

Hi Rafael,

Here are 2 patches for ACPI ac and battery device quirk handling on x86, the first one refactors the almost identical quirk handling in ac.c and battery.c out into a shared helper.

And the 2nd patch then uses the now shared code to also skip / ignore ac and battery devices on x86 Android tablets with known broken DSDTs.

Note this applies on top of my:
"[PATCH v2 0/3] ACPI / pdx86: Add support for x86 Android tablets with broken DSDTs" series which you've just merged into your bleeding edge branch.

Regards,

Hans

Hans de Goede (2):
ACPI / x86: Introduce an acpi_quirk_skip_acpi_ac_and_battery() helper ACPI / x86: Skip ac and battery devices on x86 Android tablets with
broken DSDTs

Quoted 5 lines
 drivers/acpi/ac.c        | 43 ++------------------
 drivers/acpi/battery.c   | 42 ++------------------
 drivers/acpi/x86/utils.c | 86 ++++++++++++++++++++++++++++++++++++----
 include/acpi/acpi_bus.h  |  5 +++
 4 files changed, 90 insertions(+), 86 deletions(-)
Quoted 5 lines

Applied as 5.17 material.

Note that the changes here clashed with some recent battery driver changes, so I needed to resolve the merge conflict. Please double check the result.

Sorry about the conflict.

I just checked and something indeed went wrong with the merge.

Checking drivers/acpi/battery.c from your bleeding-edge branch there a bunch of now dead code still present there related to setting the now never checked battery_check_pmic global quirk flag:

Line 55: "static int battery_check_pmic = 1;"

Line 1105-1111:

"""
static int __init battery_do_not_check_pmic_quirk(const struct dmi_system_id *d)

{
	battery_check_pmic = 0;
	return 0;
}

"""

Line 1146-1161:

"""

	{
		/* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */
		.callback = battery_do_not_check_pmic_quirk,
		.matches = {
			DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
		},
	},
	{
		/* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */
		.callback = battery_do_not_check_pmic_quirk,
		.matches = {
			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
			DMI_MATCH(DMI_PRODUCT_NAME, "80XF"),
			DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
		},
	},

"""

Since this all just sets the now no longer checked battery_check_pmic flag, it is harmless, but all of this can be removed.

Regards,

Hans

#5 lore raw
Quoted 83 lines · Hans de Goede

Hi Rafael,

Quoted 31 lines · Rafael J. Wysocki
Quoted 24 lines · Hans de Goede

Hi Rafael,

Here are 2 patches for ACPI ac and battery device quirk handling on x86, the first one refactors the almost identical quirk handling in ac.c and battery.c out into a shared helper.

And the 2nd patch then uses the now shared code to also skip / ignore ac and battery devices on x86 Android tablets with known broken DSDTs.

Note this applies on top of my:
"[PATCH v2 0/3] ACPI / pdx86: Add support for x86 Android tablets with broken DSDTs" series which you've just merged into your bleeding edge branch.

Regards,

Hans

Hans de Goede (2):
ACPI / x86: Introduce an acpi_quirk_skip_acpi_ac_and_battery() helper ACPI / x86: Skip ac and battery devices on x86 Android tablets with
broken DSDTs

Quoted 5 lines
 drivers/acpi/ac.c        | 43 ++------------------
 drivers/acpi/battery.c   | 42 ++------------------
 drivers/acpi/x86/utils.c | 86 ++++++++++++++++++++++++++++++++++++----
 include/acpi/acpi_bus.h  |  5 +++
 4 files changed, 90 insertions(+), 86 deletions(-)
Quoted 5 lines

Applied as 5.17 material.

Note that the changes here clashed with some recent battery driver changes, so I needed to resolve the merge conflict. Please double check the result.

Sorry about the conflict.

I just checked and something indeed went wrong with the merge.

Checking drivers/acpi/battery.c from your bleeding-edge branch there a bunch of now dead code still present there related to setting the now never checked battery_check_pmic global quirk flag:

Line 55: "static int battery_check_pmic = 1;"

Line 1105-1111:

"""
static int __init battery_do_not_check_pmic_quirk(const struct dmi_system_id *d)

{
        battery_check_pmic = 0;
        return 0;
}

"""

Line 1146-1161:

"""

        {
                /* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */
                .callback = battery_do_not_check_pmic_quirk,
                .matches = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
                },
        },
        {
                /* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */
                .callback = battery_do_not_check_pmic_quirk,
                .matches = {
                        DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
                        DMI_MATCH(DMI_PRODUCT_NAME, "80XF"),
                        DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
                },
        },
Quoted 4 lines

"""

Since this all just sets the now no longer checked battery_check_pmic flag, it is harmless, but all of this can be removed.

OK, I redid the merge, please check again.

Thanks!

#6 lore raw

Hi,

Quoted 86 lines · Rafael J. Wysocki
Quoted 85 lines · Hans de Goede

Hi Rafael,

Quoted 31 lines · Rafael J. Wysocki
Quoted 24 lines · Hans de Goede

Hi Rafael,

Here are 2 patches for ACPI ac and battery device quirk handling on x86, the first one refactors the almost identical quirk handling in ac.c and battery.c out into a shared helper.

And the 2nd patch then uses the now shared code to also skip / ignore ac and battery devices on x86 Android tablets with known broken DSDTs.

Note this applies on top of my:
"[PATCH v2 0/3] ACPI / pdx86: Add support for x86 Android tablets with broken DSDTs" series which you've just merged into your bleeding edge branch.

Regards,

Hans

Hans de Goede (2):
ACPI / x86: Introduce an acpi_quirk_skip_acpi_ac_and_battery() helper ACPI / x86: Skip ac and battery devices on x86 Android tablets with
broken DSDTs

Quoted 5 lines
 drivers/acpi/ac.c        | 43 ++------------------
 drivers/acpi/battery.c   | 42 ++------------------
 drivers/acpi/x86/utils.c | 86 ++++++++++++++++++++++++++++++++++++----
 include/acpi/acpi_bus.h  |  5 +++
 4 files changed, 90 insertions(+), 86 deletions(-)
Quoted 5 lines

Applied as 5.17 material.

Note that the changes here clashed with some recent battery driver changes, so I needed to resolve the merge conflict. Please double check the result.

Sorry about the conflict.

I just checked and something indeed went wrong with the merge.

Checking drivers/acpi/battery.c from your bleeding-edge branch there a bunch of now dead code still present there related to setting the now never checked battery_check_pmic global quirk flag:

Line 55: "static int battery_check_pmic = 1;"

Line 1105-1111:

"""
static int __init battery_do_not_check_pmic_quirk(const struct dmi_system_id *d)

{
        battery_check_pmic = 0;
        return 0;
}

"""

Line 1146-1161:

"""

        {
                /* ECS EF20EA, AXP288 PMIC but uses separate fuel-gauge */
                .callback = battery_do_not_check_pmic_quirk,
                .matches = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "EF20EA"),
                },
        },
        {
                /* Lenovo Ideapad Miix 320, AXP288 PMIC, separate fuel-gauge */
                .callback = battery_do_not_check_pmic_quirk,
                .matches = {
                        DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
                        DMI_MATCH(DMI_PRODUCT_NAME, "80XF"),
                        DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
                },
        },

"""

Quoted 4 lines
Quoted 2 lines

Since this all just sets the now no longer checked battery_check_pmic flag, it is harmless, but all of this can be removed.

OK, I redid the merge, please check again.

This looks good now, thanks.

Regards,

Hans