mbox series

[0/4] power: supply: add charge_behaviour property (force-discharge, inhibit-charge)

Message ID 20211123232704.25394-1-linux@weissschuh.net (mailing list archive)
Headers show
Series power: supply: add charge_behaviour property (force-discharge, inhibit-charge) | expand

Message

Thomas Weißschuh Nov. 23, 2021, 11:27 p.m. UTC
Hi,

this series adds support for the charge_behaviour property to the power
subsystem and thinkpad_acpi driver.

As thinkpad_acpi has to use the 'struct power_supply' created by the generic
ACPI driver it has to rely on custom sysfs attributes instead of proper
power_supply properties to implement this property.

Patch 1: Adds the power_supply documentation and basic public API
Patch 2: Adds helpers to power_supply core to help drivers implement the
  charge_behaviour attribute
Patch 3: Adds support for force-discharge to thinkpad_acpi.
Patch 4: Adds support for inhibit-discharge to thinkpad_acpi.

Patch 3 and 4 are largely taken from other patches and adapted to the new API.
(Links are in the patch trailer)

Ognjen Galic:

Your S-o-b is on the original inhibit_charge and force_discharge patches.
I would like to add you as Co-developed-by but to do that it will also require
your S-o-b. Could you give your sign-offs for the new patches, so you can be
properly attributed?

Sebastian Reichel:

Currently the series does not actually support the property as a proper
powersupply property handled fully by power_supply_sysfs.c because there would
be no user for this property.

Previous discussions about the API:

https://lore.kernel.org/platform-driver-x86/20211108192852.357473-1-linux@weissschuh.net/
https://lore.kernel.org/platform-driver-x86/21569a89-8303-8573-05fb-c2fec29983d1@gmail.com/

v1: https://lore.kernel.org/lkml/20211113104225.141333-1-linux@weissschuh.net/
v1 -> v2:

* Use sysfs_emit-APIs instead of plain sprintf
* More cecks for actual feature availability
* Validation of the written values
* Read inhibit-charge via BICG instead of PSSG (peak shift state)
* Don't mangle error numbers in charge_behaviour_store()

Open points:

Thomas Koch has observed that on a T450s with two batteries
inhibit-charge on BAT0 will affect both batteries and for BAT1 it is ignored
entirely, this seems to be a bug in the EC.
On my T460s with two batteries it works correctly.

Thomas Weißschuh (4):
  power: supply: add charge_behaviour attributes
  power: supply: add helpers for charge_behaviour sysfs
  platform/x86: thinkpad_acpi: support force-discharge
  platform/x86: thinkpad_acpi: support inhibit-charge

 Documentation/ABI/testing/sysfs-class-power |  14 ++
 drivers/platform/x86/thinkpad_acpi.c        | 191 +++++++++++++++++++-
 drivers/power/supply/power_supply_sysfs.c   |  51 ++++++
 include/linux/power_supply.h                |  16 ++
 4 files changed, 268 insertions(+), 4 deletions(-)


base-commit: 66f4beaa6c1d28161f534471484b2daa2de1dce0

Comments

Kevin Locke Nov. 25, 2021, 6:04 p.m. UTC | #1
On Wed, 2021-11-24 at 00:27 +0100, Thomas Weißschuh wrote:
> this series adds support for the charge_behaviour property to the power
> subsystem and thinkpad_acpi driver.

Wonderful!  Thanks for working on this.

I can confirm inhibit-charge and force-discharge states work with
patch v2 on v5.16-rc2 on a T430 (2342-CTO) with BIOS G1ETC2WW (2.82 ),
EC G1HT36WW and a single battery.  Most behavior is as expected:

- With force-discharge, status becomes "Discharging" and energy_now
  drops over time while AC remains connected.
- With inhibit-charge, status becomes "Unknown" and energy_now is
  stable over time, even when not fully charged.
- With auto, status becomes "Charging" and energy_now rises over time.
- charge_behaviour takes precedence over
  charge_control_{start,end}_threshold: status remains
  Discharging/Unknown when below the start threshold, either due to
  discharge or threshold change.
- charge_behaviour is preserved over soft reboot.
- inhibit-charge/auto are preserved across battery removal and
  reinsertion.
- inhibit-charge/auto are preserved across s2ram (S3).
- With force-discharge, if the battery is removed, the machine
  immediately powers off.

Some behavior is a little surprising:

- charge_behaviour can not be set to force-discharge if AC is
  disconnected (EIO).  If charge_behaviour is force-discharge when AC
  is disconnected, it changes to auto, unlike inhibit-charge.
- charge_behavior force-discharge is not preserved across s2ram (S3),
  unlike inhibit-charge.
- charge_behaviour is not preserved across hard reset (unlike charge
  thresholds).  Interestingly, it appears that inhibit-charge is
  preserved across power-off (no charging is observed while powered
  off) but not power-on, even though it is preserved across soft
  reboot, as noted above.

I assume the behavior is under the control of the EC, so these aren't
criticisms of the patch.  Just some observations.

Tested-by: Kevin Locke <kevin@kevinlocke.name>

Thanks again,
Kevin
Sebastian Reichel Dec. 3, 2021, 9:33 p.m. UTC | #2
Hi,

On Wed, Nov 24, 2021 at 12:27:00AM +0100, Thomas Weißschuh wrote:
> This series adds support for the charge_behaviour property to the power
> subsystem and thinkpad_acpi driver.
> 
> As thinkpad_acpi has to use the 'struct power_supply' created by the generic
> ACPI driver it has to rely on custom sysfs attributes instead of proper
> power_supply properties to implement this property.
> 
> Patch 1: Adds the power_supply documentation and basic public API
> Patch 2: Adds helpers to power_supply core to help drivers implement the
>   charge_behaviour attribute
> Patch 3: Adds support for force-discharge to thinkpad_acpi.
> Patch 4: Adds support for inhibit-discharge to thinkpad_acpi.
> 
> Patch 3 and 4 are largely taken from other patches and adapted to the new API.
> (Links are in the patch trailer)
> 
> Ognjen Galic:
> 
> Your S-o-b is on the original inhibit_charge and force_discharge patches.
> I would like to add you as Co-developed-by but to do that it will also require
> your S-o-b. Could you give your sign-offs for the new patches, so you can be
> properly attributed?
> 
> Sebastian Reichel:
> 
> Currently the series does not actually support the property as a proper
> powersupply property handled fully by power_supply_sysfs.c because there would
> be no user for this property.

I'm not too happy how the acpi-battery hooks work, but that's not
your fault and this patchset does not really make the situation
worse. So:

Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>

-- Sebastian

> Previous discussions about the API:
> 
> https://lore.kernel.org/platform-driver-x86/20211108192852.357473-1-linux@weissschuh.net/
> https://lore.kernel.org/platform-driver-x86/21569a89-8303-8573-05fb-c2fec29983d1@gmail.com/
> 
> v1: https://lore.kernel.org/lkml/20211113104225.141333-1-linux@weissschuh.net/
> v1 -> v2:
> 
> * Use sysfs_emit-APIs instead of plain sprintf
> * More cecks for actual feature availability
> * Validation of the written values
> * Read inhibit-charge via BICG instead of PSSG (peak shift state)
> * Don't mangle error numbers in charge_behaviour_store()
> 
> Open points:
> 
> Thomas Koch has observed that on a T450s with two batteries
> inhibit-charge on BAT0 will affect both batteries and for BAT1 it is ignored
> entirely, this seems to be a bug in the EC.
> On my T460s with two batteries it works correctly.
> 
> Thomas Weißschuh (4):
>   power: supply: add charge_behaviour attributes
>   power: supply: add helpers for charge_behaviour sysfs
>   platform/x86: thinkpad_acpi: support force-discharge
>   platform/x86: thinkpad_acpi: support inhibit-charge
> 
>  Documentation/ABI/testing/sysfs-class-power |  14 ++
>  drivers/platform/x86/thinkpad_acpi.c        | 191 +++++++++++++++++++-
>  drivers/power/supply/power_supply_sysfs.c   |  51 ++++++
>  include/linux/power_supply.h                |  16 ++
>  4 files changed, 268 insertions(+), 4 deletions(-)
> 
> 
> base-commit: 66f4beaa6c1d28161f534471484b2daa2de1dce0
> -- 
> 2.34.0
>
Hans de Goede Dec. 4, 2021, 1:56 p.m. UTC | #3
Hi,

On 12/3/21 22:33, Sebastian Reichel wrote:
> Hi,
> 
> On Wed, Nov 24, 2021 at 12:27:00AM +0100, Thomas Weißschuh wrote:
>> This series adds support for the charge_behaviour property to the power
>> subsystem and thinkpad_acpi driver.
>>
>> As thinkpad_acpi has to use the 'struct power_supply' created by the generic
>> ACPI driver it has to rely on custom sysfs attributes instead of proper
>> power_supply properties to implement this property.
>>
>> Patch 1: Adds the power_supply documentation and basic public API
>> Patch 2: Adds helpers to power_supply core to help drivers implement the
>>   charge_behaviour attribute
>> Patch 3: Adds support for force-discharge to thinkpad_acpi.
>> Patch 4: Adds support for inhibit-discharge to thinkpad_acpi.
>>
>> Patch 3 and 4 are largely taken from other patches and adapted to the new API.
>> (Links are in the patch trailer)
>>
>> Ognjen Galic:
>>
>> Your S-o-b is on the original inhibit_charge and force_discharge patches.
>> I would like to add you as Co-developed-by but to do that it will also require
>> your S-o-b. Could you give your sign-offs for the new patches, so you can be
>> properly attributed?
>>
>> Sebastian Reichel:
>>
>> Currently the series does not actually support the property as a proper
>> powersupply property handled fully by power_supply_sysfs.c because there would
>> be no user for this property.
> 
> I'm not too happy how the acpi-battery hooks work, but that's not
> your fault and this patchset does not really make the situation
> worse. So:
> 
> Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>

I haven't looked at the thinkpad_apci.c bits closely yet (for this new version),
but assuming those are ready for merging too, we need to discuss about how
to merge this.

The thinkpad_acpi code has already seen quite a lot of changes in -next,
so I would like the thinkpad_acpi changes to go upstream through the
platform-drivers-x86.git tree to avoid conflicts.

As such I think it is best if you (Sebastian) can prepare an immutable
branch with patch 1 + 2 for me to merge. Then even if patch 3 + 4 need
more work, Thomas can just respin those on top of the immutable branch.

Alternatively I can take the entire series upstream through the
platform-drivers-x86.git tree if that is ok with you (Sebastian).

Either way please let me know how you want to proceed with this.

Regards,

Hans



>> Previous discussions about the API:
>>
>> https://lore.kernel.org/platform-driver-x86/20211108192852.357473-1-linux@weissschuh.net/
>> https://lore.kernel.org/platform-driver-x86/21569a89-8303-8573-05fb-c2fec29983d1@gmail.com/
>>
>> v1: https://lore.kernel.org/lkml/20211113104225.141333-1-linux@weissschuh.net/
>> v1 -> v2:
>>
>> * Use sysfs_emit-APIs instead of plain sprintf
>> * More cecks for actual feature availability
>> * Validation of the written values
>> * Read inhibit-charge via BICG instead of PSSG (peak shift state)
>> * Don't mangle error numbers in charge_behaviour_store()
>>
>> Open points:
>>
>> Thomas Koch has observed that on a T450s with two batteries
>> inhibit-charge on BAT0 will affect both batteries and for BAT1 it is ignored
>> entirely, this seems to be a bug in the EC.
>> On my T460s with two batteries it works correctly.
>>
>> Thomas Weißschuh (4):
>>   power: supply: add charge_behaviour attributes
>>   power: supply: add helpers for charge_behaviour sysfs
>>   platform/x86: thinkpad_acpi: support force-discharge
>>   platform/x86: thinkpad_acpi: support inhibit-charge
>>
>>  Documentation/ABI/testing/sysfs-class-power |  14 ++
>>  drivers/platform/x86/thinkpad_acpi.c        | 191 +++++++++++++++++++-
>>  drivers/power/supply/power_supply_sysfs.c   |  51 ++++++
>>  include/linux/power_supply.h                |  16 ++
>>  4 files changed, 268 insertions(+), 4 deletions(-)
>>
>>
>> base-commit: 66f4beaa6c1d28161f534471484b2daa2de1dce0
>> -- 
>> 2.34.0
>>
Thomas Koch Dec. 4, 2021, 4:04 p.m. UTC | #4
Hi Thomas,

On 24.11.21 00:27, Thomas Weißschuh wrote:
> Hi,
>
> this series adds support for the charge_behaviour property to the power
> subsystem and thinkpad_acpi driver.
>
> As thinkpad_acpi has to use the 'struct power_supply' created by the generic
> ACPI driver it has to rely on custom sysfs attributes instead of proper
> power_supply properties to implement this property.
>
> Patch 1: Adds the power_supply documentation and basic public API
> Patch 2: Adds helpers to power_supply core to help drivers implement the
>    charge_behaviour attribute
> Patch 3: Adds support for force-discharge to thinkpad_acpi.
> Patch 4: Adds support for inhibit-discharge to thinkpad_acpi.
>
> Patch 3 and 4 are largely taken from other patches and adapted to the new API.
> (Links are in the patch trailer)
>
> Ognjen Galic:
>
> Your S-o-b is on the original inhibit_charge and force_discharge patches.
> I would like to add you as Co-developed-by but to do that it will also require
> your S-o-b. Could you give your sign-offs for the new patches, so you can be
> properly attributed?
>
> Sebastian Reichel:
>
> Currently the series does not actually support the property as a proper
> powersupply property handled fully by power_supply_sysfs.c because there would
> be no user for this property.
>
> Previous discussions about the API:
>
> https://lore.kernel.org/platform-driver-x86/20211108192852.357473-1-linux@weissschuh.net/
> https://lore.kernel.org/platform-driver-x86/21569a89-8303-8573-05fb-c2fec29983d1@gmail.com/
>
> v1: https://lore.kernel.org/lkml/20211113104225.141333-1-linux@weissschuh.net/
> v1 -> v2:
>
> * Use sysfs_emit-APIs instead of plain sprintf
> * More cecks for actual feature availability
> * Validation of the written values
> * Read inhibit-charge via BICG instead of PSSG (peak shift state)
> * Don't mangle error numbers in charge_behaviour_store()
>
> Open points:
>
> Thomas Koch has observed that on a T450s with two batteries
> inhibit-charge on BAT0 will affect both batteries and for BAT1 it is ignored
> entirely, this seems to be a bug in the EC.
> On my T460s with two batteries it works correctly.
>
> Thomas Weißschuh (4):
>    power: supply: add charge_behaviour attributes
>    power: supply: add helpers for charge_behaviour sysfs
>    platform/x86: thinkpad_acpi: support force-discharge
>    platform/x86: thinkpad_acpi: support inhibit-charge
>
>   Documentation/ABI/testing/sysfs-class-power |  14 ++
>   drivers/platform/x86/thinkpad_acpi.c        | 191 +++++++++++++++++++-
>   drivers/power/supply/power_supply_sysfs.c   |  51 ++++++
>   include/linux/power_supply.h                |  16 ++
>   4 files changed, 268 insertions(+), 4 deletions(-)
>
>
> base-commit: 66f4beaa6c1d28161f534471484b2daa2de1dce0
>

Reviewed-by
: Thomas Koch <linrunner@gmx.net>
Tested-by: Thomas Koch <linrunner@gmx.net>

Works well on ThinkPad X220, T450s, X1C6 with the exception mentioned above.

The new API is included in TLP already [1].

[1]
https://github.com/linrunner/TLP/commit/f0bf18f847470ae495a68f9f0e30130b96348936


--
Freundliche Grüße / Kind regards,
Thomas Koch

Mail : linrunner@gmx.net
Web  : https://linrunner.de/tlp
Hans de Goede Dec. 16, 2021, 3:41 p.m. UTC | #5
Hi,

On 12/3/21 22:33, Sebastian Reichel wrote:
> Hi,
> 
> On Wed, Nov 24, 2021 at 12:27:00AM +0100, Thomas Weißschuh wrote:
>> This series adds support for the charge_behaviour property to the power
>> subsystem and thinkpad_acpi driver.
>>
>> As thinkpad_acpi has to use the 'struct power_supply' created by the generic
>> ACPI driver it has to rely on custom sysfs attributes instead of proper
>> power_supply properties to implement this property.
>>
>> Patch 1: Adds the power_supply documentation and basic public API
>> Patch 2: Adds helpers to power_supply core to help drivers implement the
>>   charge_behaviour attribute
>> Patch 3: Adds support for force-discharge to thinkpad_acpi.
>> Patch 4: Adds support for inhibit-discharge to thinkpad_acpi.
>>
>> Patch 3 and 4 are largely taken from other patches and adapted to the new API.
>> (Links are in the patch trailer)
>>
>> Ognjen Galic:
>>
>> Your S-o-b is on the original inhibit_charge and force_discharge patches.
>> I would like to add you as Co-developed-by but to do that it will also require
>> your S-o-b. Could you give your sign-offs for the new patches, so you can be
>> properly attributed?
>>
>> Sebastian Reichel:
>>
>> Currently the series does not actually support the property as a proper
>> powersupply property handled fully by power_supply_sysfs.c because there would
>> be no user for this property.
> 
> I'm not too happy how the acpi-battery hooks work, but that's not
> your fault and this patchset does not really make the situation
> worse. So:
> 
> Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>

Sebastian, what is the plan for taking this upstream ? Does your ack mean that
you are ok with me taking the entire series upstream through the pdx86 tree?

Or do you plan to apply patches 1-2 through linux-power-supply.git; and in that
case can you provide an inmmutable branch with those patches for me to merge
into pdx86/for-next so that I can then apply patches 3 + 4 there ?

Note merging everything through the linux-power-supply.git tree is non ideal
in this case because the thinkpad_acpi.c code already has a lot of changes
in pdx86/for-next.

Regards,

Hans


>> Previous discussions about the API:
>>
>> https://lore.kernel.org/platform-driver-x86/20211108192852.357473-1-linux@weissschuh.net/
>> https://lore.kernel.org/platform-driver-x86/21569a89-8303-8573-05fb-c2fec29983d1@gmail.com/
>>
>> v1: https://lore.kernel.org/lkml/20211113104225.141333-1-linux@weissschuh.net/
>> v1 -> v2:
>>
>> * Use sysfs_emit-APIs instead of plain sprintf
>> * More cecks for actual feature availability
>> * Validation of the written values
>> * Read inhibit-charge via BICG instead of PSSG (peak shift state)
>> * Don't mangle error numbers in charge_behaviour_store()
>>
>> Open points:
>>
>> Thomas Koch has observed that on a T450s with two batteries
>> inhibit-charge on BAT0 will affect both batteries and for BAT1 it is ignored
>> entirely, this seems to be a bug in the EC.
>> On my T460s with two batteries it works correctly.
>>
>> Thomas Weißschuh (4):
>>   power: supply: add charge_behaviour attributes
>>   power: supply: add helpers for charge_behaviour sysfs
>>   platform/x86: thinkpad_acpi: support force-discharge
>>   platform/x86: thinkpad_acpi: support inhibit-charge
>>
>>  Documentation/ABI/testing/sysfs-class-power |  14 ++
>>  drivers/platform/x86/thinkpad_acpi.c        | 191 +++++++++++++++++++-
>>  drivers/power/supply/power_supply_sysfs.c   |  51 ++++++
>>  include/linux/power_supply.h                |  16 ++
>>  4 files changed, 268 insertions(+), 4 deletions(-)
>>
>>
>> base-commit: 66f4beaa6c1d28161f534471484b2daa2de1dce0
>> -- 
>> 2.34.0
>>
Hans de Goede Dec. 21, 2021, 4:06 p.m. UTC | #6
Hi,

On 12/3/21 22:33, Sebastian Reichel wrote:
> Hi,
> 
> On Wed, Nov 24, 2021 at 12:27:00AM +0100, Thomas Weißschuh wrote:
>> This series adds support for the charge_behaviour property to the power
>> subsystem and thinkpad_acpi driver.
>>
>> As thinkpad_acpi has to use the 'struct power_supply' created by the generic
>> ACPI driver it has to rely on custom sysfs attributes instead of proper
>> power_supply properties to implement this property.
>>
>> Patch 1: Adds the power_supply documentation and basic public API
>> Patch 2: Adds helpers to power_supply core to help drivers implement the
>>   charge_behaviour attribute
>> Patch 3: Adds support for force-discharge to thinkpad_acpi.
>> Patch 4: Adds support for inhibit-discharge to thinkpad_acpi.
>>
>> Patch 3 and 4 are largely taken from other patches and adapted to the new API.
>> (Links are in the patch trailer)
>>
>> Ognjen Galic:
>>
>> Your S-o-b is on the original inhibit_charge and force_discharge patches.
>> I would like to add you as Co-developed-by but to do that it will also require
>> your S-o-b. Could you give your sign-offs for the new patches, so you can be
>> properly attributed?
>>
>> Sebastian Reichel:
>>
>> Currently the series does not actually support the property as a proper
>> powersupply property handled fully by power_supply_sysfs.c because there would
>> be no user for this property.
> 
> I'm not too happy how the acpi-battery hooks work, but that's not
> your fault and this patchset does not really make the situation
> worse. So:
> 
> Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>

Sebastian, I have taken the liberty to assume that this means that you are
ok with merging the entire series through the pdx86 tree (I've done a test-merge
with linux-power-supply/for-next and there are no conflicts).

Thomas, Thank you for your patch-series, I've applied the series
to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Once I've run some tests on this branch the patches there will be
added to the platform-drivers-x86/for-next branch and eventually
will be included in the pdx86 pull-request to Linus for the next
merge-window.

Regards,

Hans





> 
> -- Sebastian
> 
>> Previous discussions about the API:
>>
>> https://lore.kernel.org/platform-driver-x86/20211108192852.357473-1-linux@weissschuh.net/
>> https://lore.kernel.org/platform-driver-x86/21569a89-8303-8573-05fb-c2fec29983d1@gmail.com/
>>
>> v1: https://lore.kernel.org/lkml/20211113104225.141333-1-linux@weissschuh.net/
>> v1 -> v2:
>>
>> * Use sysfs_emit-APIs instead of plain sprintf
>> * More cecks for actual feature availability
>> * Validation of the written values
>> * Read inhibit-charge via BICG instead of PSSG (peak shift state)
>> * Don't mangle error numbers in charge_behaviour_store()
>>
>> Open points:
>>
>> Thomas Koch has observed that on a T450s with two batteries
>> inhibit-charge on BAT0 will affect both batteries and for BAT1 it is ignored
>> entirely, this seems to be a bug in the EC.
>> On my T460s with two batteries it works correctly.
>>
>> Thomas Weißschuh (4):
>>   power: supply: add charge_behaviour attributes
>>   power: supply: add helpers for charge_behaviour sysfs
>>   platform/x86: thinkpad_acpi: support force-discharge
>>   platform/x86: thinkpad_acpi: support inhibit-charge
>>
>>  Documentation/ABI/testing/sysfs-class-power |  14 ++
>>  drivers/platform/x86/thinkpad_acpi.c        | 191 +++++++++++++++++++-
>>  drivers/power/supply/power_supply_sysfs.c   |  51 ++++++
>>  include/linux/power_supply.h                |  16 ++
>>  4 files changed, 268 insertions(+), 4 deletions(-)
>>
>>
>> base-commit: 66f4beaa6c1d28161f534471484b2daa2de1dce0
>> -- 
>> 2.34.0
>>