diff mbox series

ACPI: battery: Add "Not Charging" quirk for Microsoft Surface devices

Message ID 20220429174114.1277799-1-luzmaximilian@gmail.com (mailing list archive)
State Superseded, archived
Headers show
Series ACPI: battery: Add "Not Charging" quirk for Microsoft Surface devices | expand

Commit Message

Maximilian Luz April 29, 2022, 5:41 p.m. UTC
Microsoft Surface devices have a limiter that sets a fixed maximum
charge capacity for the battery. When that maximum capacity has been
reached, charging stops. In that case, _BST returns a battery state
field with both "charging" and "discharging" bits cleared. The battery
driver, however, returns "unknown" as status.

This seems to be the same behavior as observed on the ThinkPads, so
let's use the same quirk to handle that.

Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
---

For what it's worth, I don't think the ACPI spec explicitly states that
any of the status bits need to be set, or that there are only the
"charging" and "discharging" states. As far as I can tell, ACPI only
states:

    Notice that the Charging bit and the Discharging bit are mutually
    exclusive and must not both be set at the same time. Even in
    critical state, hardware should report the corresponding
    charging/discharging state.

But that does not exclude the case that no bit is set. So, strictly
going by spec, I don't think it's necessary to put all of this behind a
quirk.

---
 drivers/acpi/battery.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Rafael J. Wysocki May 6, 2022, 6:43 p.m. UTC | #1
On Fri, Apr 29, 2022 at 7:41 PM Maximilian Luz <luzmaximilian@gmail.com> wrote:
>
> Microsoft Surface devices have a limiter that sets a fixed maximum
> charge capacity for the battery. When that maximum capacity has been
> reached, charging stops. In that case, _BST returns a battery state
> field with both "charging" and "discharging" bits cleared. The battery
> driver, however, returns "unknown" as status.
>
> This seems to be the same behavior as observed on the ThinkPads, so
> let's use the same quirk to handle that.
>
> Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
> ---
>
> For what it's worth, I don't think the ACPI spec explicitly states that
> any of the status bits need to be set, or that there are only the
> "charging" and "discharging" states. As far as I can tell, ACPI only
> states:
>
>     Notice that the Charging bit and the Discharging bit are mutually
>     exclusive and must not both be set at the same time. Even in
>     critical state, hardware should report the corresponding
>     charging/discharging state.
>
> But that does not exclude the case that no bit is set. So, strictly
> going by spec, I don't think it's necessary to put all of this behind a
> quirk.

I think that this should be covered by the patch I've just applied:

https://patchwork.kernel.org/project/linux-acpi/patch/20220427154053.499203-1-wse@tuxedocomputers.com/

Shouldn't it?

> ---
>  drivers/acpi/battery.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> index dc208f5f5a1f..1c88504aae5b 100644
> --- a/drivers/acpi/battery.c
> +++ b/drivers/acpi/battery.c
> @@ -1152,6 +1152,19 @@ static const struct dmi_system_id bat_dmi_table[] __initconst = {
>                         DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad"),
>                 },
>         },
> +       {
> +               /*
> +                * Microsoft Surface devices have an optional "battery
> +                * limiter". Due to this, there is a "Not Charging" state
> +                * similar to the one on the Lenovo ThinkPads, described above.
> +                */
> +               .callback = battery_quirk_not_charging,
> +               .ident = "Microsoft Surface",
> +               .matches = {
> +                       DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
> +                       DMI_MATCH(DMI_PRODUCT_NAME, "Surface"),
> +               },
> +       },
>         {
>                 /* Microsoft Surface Go 3 */
>                 .callback = battery_notification_delay_quirk,
> --
> 2.36.0
>
Maximilian Luz May 6, 2022, 6:47 p.m. UTC | #2
On 5/6/22 20:43, Rafael J. Wysocki wrote:
> On Fri, Apr 29, 2022 at 7:41 PM Maximilian Luz <luzmaximilian@gmail.com> wrote:
>>
>> Microsoft Surface devices have a limiter that sets a fixed maximum
>> charge capacity for the battery. When that maximum capacity has been
>> reached, charging stops. In that case, _BST returns a battery state
>> field with both "charging" and "discharging" bits cleared. The battery
>> driver, however, returns "unknown" as status.
>>
>> This seems to be the same behavior as observed on the ThinkPads, so
>> let's use the same quirk to handle that.
>>
>> Signed-off-by: Maximilian Luz <luzmaximilian@gmail.com>
>> ---
>>
>> For what it's worth, I don't think the ACPI spec explicitly states that
>> any of the status bits need to be set, or that there are only the
>> "charging" and "discharging" states. As far as I can tell, ACPI only
>> states:
>>
>>      Notice that the Charging bit and the Discharging bit are mutually
>>      exclusive and must not both be set at the same time. Even in
>>      critical state, hardware should report the corresponding
>>      charging/discharging state.
>>
>> But that does not exclude the case that no bit is set. So, strictly
>> going by spec, I don't think it's necessary to put all of this behind a
>> quirk.
> 
> I think that this should be covered by the patch I've just applied:
> 
> https://patchwork.kernel.org/project/linux-acpi/patch/20220427154053.499203-1-wse@tuxedocomputers.com/
> 
> Shouldn't it?

It does, thank you!

Sorry for having missed that one.

Regards,
Max
diff mbox series

Patch

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index dc208f5f5a1f..1c88504aae5b 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -1152,6 +1152,19 @@  static const struct dmi_system_id bat_dmi_table[] __initconst = {
 			DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad"),
 		},
 	},
+	{
+		/*
+		 * Microsoft Surface devices have an optional "battery
+		 * limiter". Due to this, there is a "Not Charging" state
+		 * similar to the one on the Lenovo ThinkPads, described above.
+		 */
+		.callback = battery_quirk_not_charging,
+		.ident = "Microsoft Surface",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Surface"),
+		},
+	},
 	{
 		/* Microsoft Surface Go 3 */
 		.callback = battery_notification_delay_quirk,