Skip to contentSkip to conversation

battery: Add the ThinkPad "Not Charging" quirk

PATCH Superseded Ognjen Galic 3 participants 12 messages Dec 15, 2017 – Dec 19, 2017

Subsystems (3)

v6 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 2/3 battery: Add the ThinkPad "Not Charging" quirk

The EC/ACPI firmware on Lenovo ThinkPads used to report a status of "Unknown" when the battery is between the charge start and charge stop thresholds. On Windows, it reports "Not Charging" so the quirk has been added to also report correctly.

Now the "status" attribute returns "Not Charging" when the battery on ThinkPads is not physicaly charging.

---
 drivers/acpi/battery.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/acpi/battery.c +23 -0
index 2951d07..81e9b4e 100644
@@ -71,6 +71,7 @@ static async_cookie_t async_cookie;
 static bool battery_driver_registered;
 static int battery_bix_broken_package;
 static int battery_notification_delay_ms;
+static int battery_quirk_thinkpad_notcharging;
 static unsigned int cache_time = 1000;
 module_param(cache_time, uint, 0644);
 MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
@@ -222,6 +223,13 @@ static int acpi_battery_get_property(struct power_supply *psy,
 			val->intval = POWER_SUPPLY_STATUS_CHARGING;
 		else if (acpi_battery_is_charged(battery))
 			val->intval = POWER_SUPPLY_STATUS_FULL;
+		/*
+		 * On the Lenovo ThinkPad ACPI implementation, when
+		 * neither bits 0 or 1 are set, that state is
+		 * considered as "Not Charging".
+		 */
+		else if (battery_quirk_thinkpad_notcharging)
+			val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
 		else
 			val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
 		break;
@@ -1301,6 +1309,13 @@ battery_notification_delay_quirk(const struct dmi_system_id *d)
 	return 0;
 }
 
+static int __init
+battery_quirk_not_charging(const struct dmi_system_id *d)
+{
+	battery_quirk_thinkpad_notcharging = 1;
+	return 0;
+}
+
 static const struct dmi_system_id bat_dmi_table[] __initconst = {
 	{
 		.callback = battery_bix_broken_package_quirk,
@@ -1318,6 +1333,14 @@ static const struct dmi_system_id bat_dmi_table[] __initconst = {
 			DMI_MATCH(DMI_PRODUCT_NAME, "Aspire V5-573G"),
 		},
 	},
+	{
+		.callback = battery_quirk_not_charging,
+		.ident = "Lenovo ThinkPad",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+			DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad"),
+		},
+	},
 	{},
 };
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 11 lines · Ognjen Galic

The EC/ACPI firmware on Lenovo ThinkPads used to report a status of "Unknown" when the battery is between the charge start and charge stop thresholds. On Windows, it reports "Not Charging" so the quirk has been added to also report correctly.

Now the "status" attribute returns "Not Charging" when the battery on ThinkPads is not physicaly charging.

Tested-by Kevin Locke <kevin(a)kevinlocke.name>
Tested-by Christoph Böhmwalder <christoph(a)boehmwalder.at>
Signed-off-by Ognjen Galic <smclt30p(a)gmail.com>

It doesn't look like this is related to the [1/3] and [3/3], so why do you make it part of the series?

drivers/acpi/battery.c static async_cookie_t async_cookie; · line 74

Quoted 13 lines
---
 drivers/acpi/battery.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/acpi/battery.c +1 -0
index 2951d07..81e9b4e 100644
@@ -71,6 +71,7 @@ static async_cookie_t async_cookie;
 static bool battery_driver_registered;
 static int battery_bix_broken_package;
 static int battery_notification_delay_ms;
+static int battery_quirk_thinkpad_notcharging;

Drop "thinkpad" from this name as somebody may need to use the quirk for a machine from a different vendor in the future.

Quoted 18 lines
drivers/acpi/battery.c +7 -0
 static unsigned int cache_time = 1000;
 module_param(cache_time, uint, 0644);
 MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
@@ -222,6 +223,13 @@ static int acpi_battery_get_property(struct power_supply *psy,
                        val->intval = POWER_SUPPLY_STATUS_CHARGING;
                else if (acpi_battery_is_charged(battery))
                        val->intval = POWER_SUPPLY_STATUS_FULL;
+               /*
+                * On the Lenovo ThinkPad ACPI implementation, when
+                * neither bits 0 or 1 are set, that state is
+                * considered as "Not Charging".
+                */
+               else if (battery_quirk_thinkpad_notcharging)
+                       val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
                else
                        val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
                break;

drivers/acpi/battery.c battery_notification_delay_quirk(const struct dmi_system_id *d) · line 1313

Quoted 5 lines
drivers/acpi/battery.c +2 -0
@@ -1301,6 +1309,13 @@ battery_notification_delay_quirk(const struct dmi_system_id *d)
        return 0;
 }
 
+static int __init
+battery_quirk_not_charging(const struct dmi_system_id *d)

Don't break the above line (it will be over 80 chars long, but that's fine).

drivers/acpi/battery.c static const struct dmi_system_id bat_dmi_table[] __initconst = { · line 1336

Quoted 13 lines
drivers/acpi/battery.c +6 -0
+{
+       battery_quirk_thinkpad_notcharging = 1;
+       return 0;
+}
+
 static const struct dmi_system_id bat_dmi_table[] __initconst = {
        {
                .callback = battery_bix_broken_package_quirk,
@@ -1318,6 +1333,14 @@ static const struct dmi_system_id bat_dmi_table[] __initconst = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "Aspire V5-573G"),
                },
        },
+       {

Add a comment to describe this quirk (which it is needed in the first place).

drivers/acpi/battery.c static const struct dmi_system_id bat_dmi_table[] __initconst = {

Quoted 11 lines
drivers/acpi/battery.c +7 -1
+               .callback = battery_quirk_not_charging,
+               .ident = "Lenovo ThinkPad",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+                       DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad"),
+               },
+       },
        {},
 };
 
--

Thanks,
Rafael

#2 lore raw
Quoted 59 lines · Rafael J. Wysocki
Quoted 11 lines · Ognjen Galic

The EC/ACPI firmware on Lenovo ThinkPads used to report a status of "Unknown" when the battery is between the charge start and charge stop thresholds. On Windows, it reports "Not Charging" so the quirk has been added to also report correctly.

Now the "status" attribute returns "Not Charging" when the battery on ThinkPads is not physicaly charging.

Tested-by Kevin Locke <kevin(a)kevinlocke.name>
Tested-by Christoph Böhmwalder <christoph(a)boehmwalder.at>
Signed-off-by Ognjen Galic <smclt30p(a)gmail.com>

It doesn't look like this is related to the [1/3] and [3/3], so why do you make it part of the series?

drivers/acpi/battery.c static async_cookie_t async_cookie; · line 74

Quoted 13 lines
---
 drivers/acpi/battery.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/acpi/battery.c +1 -0
index 2951d07..81e9b4e 100644
@@ -71,6 +71,7 @@ static async_cookie_t async_cookie;
 static bool battery_driver_registered;
 static int battery_bix_broken_package;
 static int battery_notification_delay_ms;
+static int battery_quirk_thinkpad_notcharging;

Drop "thinkpad" from this name as somebody may need to use the quirk for a machine from a different vendor in the future.

Quoted 18 lines
drivers/acpi/battery.c +7 -0
 static unsigned int cache_time = 1000;
 module_param(cache_time, uint, 0644);
 MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
@@ -222,6 +223,13 @@ static int acpi_battery_get_property(struct power_supply *psy,
                        val->intval = POWER_SUPPLY_STATUS_CHARGING;
                else if (acpi_battery_is_charged(battery))
                        val->intval = POWER_SUPPLY_STATUS_FULL;
+               /*
+                * On the Lenovo ThinkPad ACPI implementation, when
+                * neither bits 0 or 1 are set, that state is
+                * considered as "Not Charging".
+                */
+               else if (battery_quirk_thinkpad_notcharging)
+                       val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
                else
                        val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
                break;

drivers/acpi/battery.c battery_notification_delay_quirk(const struct dmi_system_id *d) · line 1313

Quoted 5 lines
drivers/acpi/battery.c +2 -0
@@ -1301,6 +1309,13 @@ battery_notification_delay_quirk(const struct dmi_system_id *d)
        return 0;
 }
 
+static int __init
+battery_quirk_not_charging(const struct dmi_system_id *d)

Don't break the above line (it will be over 80 chars long, but that's fine).

Quoted 15 lines

drivers/acpi/battery.c static const struct dmi_system_id bat_dmi_table[] __initconst = { · line 1336

Quoted 13 lines
drivers/acpi/battery.c +6 -0
+{
+       battery_quirk_thinkpad_notcharging = 1;
+       return 0;
+}
+
 static const struct dmi_system_id bat_dmi_table[] __initconst = {
        {
                .callback = battery_bix_broken_package_quirk,
@@ -1318,6 +1333,14 @@ static const struct dmi_system_id bat_dmi_table[] __initconst = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "Aspire V5-573G"),
                },
        },
+       {

Add a comment to describe this quirk (which it is needed in the first place).

s/whichj/why/

Quoted 12 lines
Quoted 12 lines
drivers/acpi/battery.c +7 -1
+               .callback = battery_quirk_not_charging,
+               .ident = "Lenovo ThinkPad",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+                       DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad"),
+               },
+       },
        {},
 };
 
--
#3 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Ognjen Galic

The EC/ACPI firmware on Lenovo ThinkPads used to report a status of "Unknown" when the battery is between the charge start and charge stop thresholds. On Windows, it reports "Not Charging" so the quirk has been added to also report correctly.

Now the "status" attribute returns "Not Charging" when the battery on ThinkPads is not physicaly charging.

Quoted 7 lines
Quoted 3 lines

It doesn't look like this is related to the [1/3] and [3/3], so why do you make it part of the series?

I made it the same series because it is practically the same feature set. Without this patch and with 1/3 and 3/3 applied, there is a bug where the status attribute would show "Unknown" for a battery that is between the start and stop thresholds while attached to AC.

Quoted 73 lines

drivers/acpi/battery.c static async_cookie_t async_cookie; · line 74

Quoted 13 lines
---
 drivers/acpi/battery.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/acpi/battery.c +1 -0
index 2951d07..81e9b4e 100644
@@ -71,6 +71,7 @@ static async_cookie_t async_cookie;
 static bool battery_driver_registered;
 static int battery_bix_broken_package;
 static int battery_notification_delay_ms;
+static int battery_quirk_thinkpad_notcharging;

Drop "thinkpad" from this name as somebody may need to use the quirk for a machine from a different vendor in the future.

Quoted 18 lines
drivers/acpi/battery.c +7 -0
 static unsigned int cache_time = 1000;
 module_param(cache_time, uint, 0644);
 MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
@@ -222,6 +223,13 @@ static int acpi_battery_get_property(struct power_supply *psy,
                        val->intval = POWER_SUPPLY_STATUS_CHARGING;
                else if (acpi_battery_is_charged(battery))
                        val->intval = POWER_SUPPLY_STATUS_FULL;
+               /*
+                * On the Lenovo ThinkPad ACPI implementation, when
+                * neither bits 0 or 1 are set, that state is
+                * considered as "Not Charging".
+                */
+               else if (battery_quirk_thinkpad_notcharging)
+                       val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
                else
                        val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
                break;

drivers/acpi/battery.c battery_notification_delay_quirk(const struct dmi_system_id *d) · line 1313

Quoted 5 lines
drivers/acpi/battery.c +2 -0
@@ -1301,6 +1309,13 @@ battery_notification_delay_quirk(const struct dmi_system_id *d)
        return 0;
 }
 
+static int __init
+battery_quirk_not_charging(const struct dmi_system_id *d)

Don't break the above line (it will be over 80 chars long, but that's fine).

drivers/acpi/battery.c static const struct dmi_system_id bat_dmi_table[] __initconst = { · line 1336

Quoted 13 lines
drivers/acpi/battery.c +6 -0
+{
+       battery_quirk_thinkpad_notcharging = 1;
+       return 0;
+}
+
 static const struct dmi_system_id bat_dmi_table[] __initconst = {
        {
                .callback = battery_bix_broken_package_quirk,
@@ -1318,6 +1333,14 @@ static const struct dmi_system_id bat_dmi_table[] __initconst = {
                        DMI_MATCH(DMI_PRODUCT_NAME, "Aspire V5-573G"),
                },
        },
+       {

Add a comment to describe this quirk (which it is needed in the first place).

drivers/acpi/battery.c static const struct dmi_system_id bat_dmi_table[] __initconst = {

Quoted 11 lines
drivers/acpi/battery.c +7 -1
+               .callback = battery_quirk_not_charging,
+               .ident = "Lenovo ThinkPad",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+                       DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad"),
+               },
+       },
        {},
 };
 
--

Thanks,
Rafael

#4 lore raw
Quoted 14 lines · Ognjen Galic
Quoted 13 lines · Rafael J. Wysocki
Quoted 11 lines · Ognjen Galic

The EC/ACPI firmware on Lenovo ThinkPads used to report a status of "Unknown" when the battery is between the charge start and charge stop thresholds. On Windows, it reports "Not Charging" so the quirk has been added to also report correctly.

Now the "status" attribute returns "Not Charging" when the battery on ThinkPads is not physicaly charging.

Tested-by Kevin Locke <kevin(a)kevinlocke.name>
Tested-by Christoph Böhmwalder <christoph(a)boehmwalder.at>
Signed-off-by Ognjen Galic <smclt30p(a)gmail.com>
Quoted 8 lines
Quoted 3 lines

It doesn't look like this is related to the [1/3] and [3/3], so why do you make it part of the series?

I made it the same series because it is practically the same feature set. Without this patch and with 1/3 and 3/3 applied, there is a bug where the status attribute would show "Unknown" for a battery that is between the start and stop thresholds while attached to AC.

OK, fair enough.

I would reorder it as the first patch in the series, then, because the other two are more related to each other.

Thanks,
Rafael

#5 lore raw
Quoted 25 lines · Rafael J. Wysocki
Quoted 15 lines · Ognjen Galic
Quoted 14 lines · Rafael J. Wysocki
Quoted 11 lines · Ognjen Galic

The EC/ACPI firmware on Lenovo ThinkPads used to report a status of "Unknown" when the battery is between the charge start and charge stop thresholds. On Windows, it reports "Not Charging" so the quirk has been added to also report correctly.

Now the "status" attribute returns "Not Charging" when the battery on ThinkPads is not physicaly charging.

Quoted 8 lines
Quoted 3 lines

It doesn't look like this is related to the [1/3] and [3/3], so why do you make it part of the series?

I made it the same series because it is practically the same feature set. Without this patch and with 1/3 and 3/3 applied, there is a bug where the status attribute would show "Unknown" for a battery that is between the start and stop thresholds while attached to AC.

Quoted 8 lines

OK, fair enough.

I would reorder it as the first patch in the series, then, because the other two are more related to each other.

Thanks,
Rafael

Do I really need now to re-order and re-send the whole patchset for it to get merged?

Thanks.

#6 lore raw
Quoted 7 lines · Ognjen Galić
Quoted 2 lines · Rafael J. Wysocki

I would reorder it as the first patch in the series, then, because the other two are more related to each other.

Do I really need now to re-order and re-send the whole patchset for it to get merged?

Through which tree it's supposed to go?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Ognjen Galić
Quoted 2 lines · Rafael J. Wysocki

I would reorder it as the first patch in the series, then, because the other two are more related to each other.

Quoted 9 lines
Quoted 2 lines

Do I really need now to re-order and re-send the whole patchset for it to get merged?

Through which tree it's supposed to go?

--
With Best Regards,
Andy Shevchenko

I'm afraid I don't understand the question. If you mean by Linux tree, it was written while 4.15-rc2 was active.

Thanks,
Gala

#8 lore raw
In reply to Andy Shevchenko
Quoted 10 lines · Andy Shevchenko
Quoted 7 lines · Ognjen Galić
Quoted 2 lines · Rafael J. Wysocki

I would reorder it as the first patch in the series, then, because the other two are more related to each other.

Do I really need now to re-order and re-send the whole patchset for it to get merged?

Through which tree it's supposed to go?

Wait, wait. I haven't commented patches [1,3/3] yet, so no ACKs assumed, please.

Thanks,
Rafael

#9 lore raw
Quoted 8 lines · Rafael J. Wysocki
Quoted 6 lines · Andy Shevchenko
Quoted 4 lines · Ognjen Galić
Quoted 2 lines · Rafael J. Wysocki

I would reorder it as the first patch in the series, then, because the other two are more related to each other.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Do I really need now to re-order and re-send the whole patchset for it to get merged?

Through which tree it's supposed to go?

Wait, wait. I haven't commented patches [1,3/3] yet, so no ACKs assumed, please.

I would prefer if you can take it through linux-pm.

Whenever you are okay with the series let me know I would review PDx86 bits.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#10 lore raw
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines · Rafael J. Wysocki
Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Ognjen Galić
Quoted 2 lines · Rafael J. Wysocki

I would reorder it as the first patch in the series, then, because the other two are more related to each other.

Do I really need now to re-order and re-send the whole patchset for it to get merged?

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Through which tree it's supposed to go?

Wait, wait. I haven't commented patches [1,3/3] yet, so no ACKs assumed, please.

I would prefer if you can take it through linux-pm.

No problem.

Quoted 1 line

Whenever you are okay with the series let me know I would review PDx86 bits.

OK

Thanks,
Rafael

#11 lore raw
In reply to Ognjen Galić
Quoted 31 lines · Ognjen Galić
Quoted 30 lines · Rafael J. Wysocki
Quoted 15 lines · Ognjen Galic
Quoted 14 lines · Rafael J. Wysocki
Quoted 11 lines · Ognjen Galic

The EC/ACPI firmware on Lenovo ThinkPads used to report a status of "Unknown" when the battery is between the charge start and charge stop thresholds. On Windows, it reports "Not Charging" so the quirk has been added to also report correctly.

Now the "status" attribute returns "Not Charging" when the battery on ThinkPads is not physicaly charging.

Tested-by Kevin Locke <kevin(a)kevinlocke.name>
Tested-by Christoph Böhmwalder <christoph(a)boehmwalder.at>
Signed-off-by Ognjen Galic <smclt30p(a)gmail.com>
Quoted 8 lines
Quoted 3 lines

It doesn't look like this is related to the [1/3] and [3/3], so why do you make it part of the series?

I made it the same series because it is practically the same feature set. Without this patch and with 1/3 and 3/3 applied, there is a bug where the status attribute would show "Unknown" for a battery that is between the start and stop thresholds while attached to AC.

OK, fair enough.

I would reorder it as the first patch in the series, then, because the other two are more related to each other.

Quoted 6 lines
Quoted 3 lines

Thanks,
Rafael

Do I really need now to re-order and re-send the whole patchset for it to get merged?

I'm not sure I will take anything of it at this time.

Thanks,
Rafael