add standardized attributes for force_discharge and inhibit_charge
Subsystems (2)
RFC 1/1 add standardized attributes for force_discharge and inhibit_charge
Hi Sebastian,
this is a proposal to introduce separate and standardized attributes for force_discharge and inhibit_charge of a battery. These are simpler than using status from a user-space perspective, as discussed on the platform-driver-x86 mail list.
Regards,
Nicolò
--- Documentation/ABI/testing/sysfs-class-power | 27 +++++++++++++++++++++ drivers/power/supply/power_supply_sysfs.c | 2 ++ include/linux/power_supply.h | 2 ++ 3 files changed, 31 insertions(+)
Documentation/ABI/testing/sysfs-class-power +27 -0
@@ -455,6 +455,33 @@ Description: "Unknown", "Charging", "Discharging", "Not charging", "Full" +What: /sys/class/power_supply/<supply_name>/force_discharge +Date: September 2021 +Contact: [email protected] +Description: + Represents the forced discharging status of the battery. + + Access: Read, Write + + Valid values: + == ==================================== + 0: Force discharge while AC is attached + 1: Terminate forced discharging + +What: /sys/class/power_supply/<supply_name>/inhibit_charge +Date: September 2021 +Contact: [email protected] +Description: + Represents the presence of a manual override over the threshold + attributes of the battery, thus inhibiting battery charge. + + Access: Read, Write + + Valid values: + == ====================== + 1: Stop charging + 0: Terminate the override + What: /sys/class/power_supply/<supply_name>/technology Date: May 2007 Contact: [email protected]
drivers/power/supply/power_supply_sysfs.c +2 -0
@@ -136,6 +136,8 @@ static const char * const POWER_SUPPLY_SCOPE_TEXT[] = {static struct power_supply_attr power_supply_attrs[] = {/* Properties of type `int' */ POWER_SUPPLY_ENUM_ATTR (STATUS ), +POWER_SUPPLY_ENUM_ATTR (FORCE_DISCHARGE ), +POWER_SUPPLY_ENUM_ATTR (INHIBIT_CHARGE ),POWER_SUPPLY_ENUM_ATTR (CHARGE_TYPE ),POWER_SUPPLY_ENUM_ATTR (HEALTH ),POWER_SUPPLY_ATTR (PRESENT ),
include/linux/power_supply.h +2 -0
@@ -96,6 +96,8 @@ enum {enum power_supply_property {/* Properties of type `int' */ POWER_SUPPLY_PROP_STATUS =0 , +POWER_SUPPLY_PROP_FORCE_DISCHARGE , +POWER_SUPPLY_PROP_INHIBIT_CHARGE ,POWER_SUPPLY_PROP_CHARGE_TYPE ,POWER_SUPPLY_PROP_HEALTH ,POWER_SUPPLY_PROP_PRESENT ,
Signature · 1 line
2.33.0
Hi,
Quoted 6 lines · Nicolò Piazzalunga
Hi Sebastian,
this is a proposal to introduce separate and standardized attributes for
force_dischargeandinhibit_chargeof a battery. These are simpler than using status from a user-space perspective, as discussed on the platform-driver-x86 mail list.
To clarify things a bit here, the reasons for not using status for this are:
1. This would require adding new status-es which so far have never been seen by userspace, which will likely cause confusion of e.g. upower. IOW I believe that adding new status-es for this would be a userspace ABI break.
2. The devices where we currently want to use this functionality use the ACPI battery interface, which is standardized between vendors and dealt with by drivers/apci/battery.c but this kinda extra functionality is vendor specific. The drivers/apci/battery.c has code allowing vendor drivers to "hook" ACPI batteries and get add/remove calls for them. Then in these calls currently the vendor drivers do:
device_add_groups(&battery->dev, my_prop_group))
Which allows them to register extra sysfs_attributes for for example charge_control_start_threshold and charge_control_end_threshold.
This works well, but having vendor drivers somehow intercept / muck with the status handling in drivers/apci/battery.c is a non trival problem. Where as with new separate attributes this is already a solved problem.
Quoted 17 lines
--- Documentation/ABI/testing/sysfs-class-power | 27 +++++++++++++++++++++ drivers/power/supply/power_supply_sysfs.c | 2 ++ include/linux/power_supply.h | 2 ++ 3 files changed, 31 insertions(+)Documentation/ABI/testing/sysfs-class-power +3
-0@@ -455,6 +455,33 @@ Description: "Unknown", "Charging", "Discharging", "Not charging", "Full" +What: /sys/class/power_supply/<supply_name>/force_discharge +Date: September 2021 +Contact: [email protected]
Documentation/ABI/testing/sysfs-class-power Description: · line 470
Quoted 10 lines
Documentation/ABI/testing/sysfs-class-power +10
-0+Description: + Represents the forced discharging status of the battery. + + Access: Read, Write + + Valid values: + == ==================================== + 0: Force discharge while AC is attached + 1: Terminate forced discharging +
I think you have 0 and 1 swapped here? I would expect 1 to be enable forced discharging and 0 be normal operation, iow only discharge when not on AC.
Quoted 36 lines
Documentation/ABI/testing/sysfs-class-power +14
-0+What: /sys/class/power_supply/<supply_name>/inhibit_charge +Date: September 2021 +Contact: [email protected] +Description: + Represents the presence of a manual override over the threshold + attributes of the battery, thus inhibiting battery charge. + + Access: Read, Write + + Valid values: + == ====================== + 1: Stop charging + 0: Terminate the override + What: /sys/class/power_supply/<supply_name>/technology Date: May 2007 Contact: [email protected]drivers/power/supply/power_supply_sysfs.c +2
-0@@ -136,6 +136,8 @@ static const char * const POWER_SUPPLY_SCOPE_TEXT[] = {static struct power_supply_attr power_supply_attrs[] = {/* Properties of type `int' */ POWER_SUPPLY_ENUM_ATTR (STATUS ), +POWER_SUPPLY_ENUM_ATTR (FORCE_DISCHARGE ), +POWER_SUPPLY_ENUM_ATTR (INHIBIT_CHARGE ),POWER_SUPPLY_ENUM_ATTR (CHARGE_TYPE ),POWER_SUPPLY_ENUM_ATTR (HEALTH ),POWER_SUPPLY_ATTR (PRESENT ),include/linux/power_supply.h +0
-0
include/linux/power_supply.h enum { · line 103
Quoted 8 lines
include/linux/power_supply.h +2
-0@@ -96,6 +96,8 @@ enum {enum power_supply_property {/* Properties of type `int' */ POWER_SUPPLY_PROP_STATUS =0 , +POWER_SUPPLY_PROP_FORCE_DISCHARGE , +POWER_SUPPLY_PROP_INHIBIT_CHARGE ,POWER_SUPPLY_PROP_CHARGE_TYPE ,POWER_SUPPLY_PROP_HEALTH ,POWER_SUPPLY_PROP_PRESENT ,
Regards,
Hans
Hi,
Quoted 6 lines · Hans de Goede
Quoted 4 lines · Nicolò Piazzalunga
this is a proposal to introduce separate and standardized attributes for
force_dischargeandinhibit_chargeof a battery. These are simpler than using status from a user-space perspective, as discussed on the platform-driver-x86 mail list.
Quoted 7 lines
To clarify things a bit here, the reasons for not using status for this are:
1. This would require adding new status-es which so far have never been seen by userspace, which will likely cause confusion of e.g. upower. IOW I believe that adding new status-es for this would be a userspace ABI break.
Some embedded devices have status writable and use existing status and reset when adapter is replugged. That's why there are no extra status already.
Quoted 10 lines
2. The devices where we currently want to use this functionality use the ACPI battery interface, which is standardized between vendors and dealt with by
drivers/apci/battery.cbut this kinda extra functionality is vendor specific. Thedrivers/apci/battery.chas code allowing vendor drivers to "hook" ACPI batteries and get add/remove calls for them. Then in these calls currently the vendor drivers do:device_add_groups(&battery->dev, my_prop_group))
Quoted 8 lines
Which allows them to register extra
sysfs_attributesfor for examplecharge_control_start_thresholdandcharge_control_end_threshold.This works well, but having vendor drivers somehow intercept / muck with the status handling in
drivers/apci/battery.cis a non trival problem. Where as with new separate attributes this is already a solved problem.
The second argument is a very weak one. We do not accept bad userspace API to avoid restructuring a driver. FWIW adding attributes that way is already racy and a bug:
http://kroah.com/log/blog/2013/06/26/how-to-create-a-sysfs-file-correctly/
The power-supply subsystem offers registering custom sysfs files since a few kernel releases by setting up the following:
/* Run-time specific power supply configuration */
struct power_supply_config {
...
/* Device specific sysfs attributes */
const struct attribute_group **attr_grp;
...
}All drivers in drivers/power/supply/ have been converted and the ACPI is one of the last drivers not using this.
Quoted 14 lines
Quoted 14 lines
--- Documentation/ABI/testing/sysfs-class-power | 27 +++++++++++++++++++++ drivers/power/supply/power_supply_sysfs.c | 2 ++ include/linux/power_supply.h | 2 ++ 3 files changed, 31 insertions(+)Documentation/ABI/testing/sysfs-class-power +0
-0@@ -455,6 +455,33 @@ Description: "Unknown", "Charging", "Discharging", "Not charging", "Full"
Quoted 16 lines
Documentation/ABI/testing/sysfs-class-power Description: · line 470
Quoted 13 lines
Documentation/ABI/testing/sysfs-class-power +13
-0+What: /sys/class/power_supply/<supply_name>/force_discharge +Date: September 2021 +Contact: [email protected] +Description: + Represents the forced discharging status of the battery. + + Access: Read, Write + + Valid values: + == ==================================== + 0: Force discharge while AC is attached + 1: Terminate forced discharging +I think you have 0 and 1 swapped here? I would expect 1 to be enable forced discharging and 0 be normal operation, iow only discharge when not on AC.
Considering some Thinkpads have two batteries the naming and description of this is quite bad. Only the valid values part suggests that this is just about AC.
Quoted 6 lines
Documentation/ABI/testing/sysfs-class-power Description: · line 476
Quoted 6 lines
Documentation/ABI/testing/sysfs-class-power +6
-0+What: /sys/class/power_supply/<supply_name>/inhibit_charge +Date: September 2021 +Contact: [email protected] +Description: + Represents the presence of a manual override over the threshold + attributes of the battery, thus inhibiting battery charge.
The first part is specific to thinkpad implementation.
Quoted 8 lines
Documentation/ABI/testing/sysfs-class-power Description: · line 484
Quoted 8 lines
Documentation/ABI/testing/sysfs-class-power +8
-0+ + Access: Read, Write + + Valid values: + == ====================== + 1: Stop charging + 0: Terminate the override +
I wonder if its better to put both into the same file, considering that the only logical options are
* 0 = no override (= charge when possible)
* 1 = force idle
* 2 = force discharge
I.e. forced discharge implies battery not being charged.
-- Sebastian
Quoted 35 lines
Quoted 22 lines
Documentation/ABI/testing/sysfs-class-power +0
-0What: /sys/class/power_supply/<supply_name>/technology Date: May 2007 Contact: [email protected]drivers/power/supply/power_supply_sysfs.c +2
-0@@ -136,6 +136,8 @@ static const char * const POWER_SUPPLY_SCOPE_TEXT[] = {static struct power_supply_attr power_supply_attrs[] = {/* Properties of type `int' */ POWER_SUPPLY_ENUM_ATTR (STATUS ), +POWER_SUPPLY_ENUM_ATTR (FORCE_DISCHARGE ), +POWER_SUPPLY_ENUM_ATTR (INHIBIT_CHARGE ),POWER_SUPPLY_ENUM_ATTR (CHARGE_TYPE ),POWER_SUPPLY_ENUM_ATTR (HEALTH ),POWER_SUPPLY_ATTR (PRESENT ),include/linux/power_supply.h +0
-0include/linux/power_supply.h enum { · line 103
Quoted 8 lines
include/linux/power_supply.h +2
-0@@ -96,6 +96,8 @@ enum {enum power_supply_property {/* Properties of type `int' */ POWER_SUPPLY_PROP_STATUS =0 , +POWER_SUPPLY_PROP_FORCE_DISCHARGE , +POWER_SUPPLY_PROP_INHIBIT_CHARGE ,POWER_SUPPLY_PROP_CHARGE_TYPE ,POWER_SUPPLY_PROP_HEALTH ,POWER_SUPPLY_PROP_PRESENT ,Regards,
Hans
Hi,
Quoted 12 lines · Sebastian Reichel
Hi,
Quoted 9 lines · Hans de Goede
Quoted 4 lines · Nicolò Piazzalunga
this is a proposal to introduce separate and standardized attributes for
force_dischargeandinhibit_chargeof a battery. These are simpler than using status from a user-space perspective, as discussed on the platform-driver-x86 mail list.To clarify things a bit here, the reasons for not using status for this are:
Quoted 8 lines
Quoted 4 lines
1. This would require adding new status-es which so far have never been seen by userspace, which will likely cause confusion of e.g. upower. IOW I believe that adding new status-es for this would be a userspace ABI break.
Some embedded devices have status writable and use existing status and reset when adapter is replugged. That's why there are no extra status already.
Right, so then a userspace process can write "Discharging" to the status property to enable "forced discharge" mode, I get that.
And from then on any reads of status will read "Discharging" but how does (another) userspace process now differentiate this forced "Discharging" from normal discharging ? It cannot differentiate the 2 unless we add a new "Forced Discharging" status string which comes with the problem of current userspace not being prepared to deal with this status string.
Which IMHO makes this idea of overloading / adding this new usage to status a not so great API, this seems like something which the status attribute was never intended for.
Quoted 14 lines
Quoted 14 lines
2. The devices where we currently want to use this functionality use the ACPI battery interface, which is standardized between vendors and dealt with by
drivers/apci/battery.cbut this kinda extra functionality is vendor specific. Thedrivers/apci/battery.chas code allowing vendor drivers to "hook" ACPI batteries and get add/remove calls for them. Then in these calls currently the vendor drivers do:device_add_groups(&battery->dev, my_prop_group))Which allows them to register extra
sysfs_attributesfor for examplecharge_control_start_thresholdandcharge_control_end_threshold.
Quoted 7 lines
Quoted 4 lines
This works well, but having vendor drivers somehow intercept / muck with the status handling in
drivers/apci/battery.cis a non trival problem. Where as with new separate attributes this is already a solved problem.The second argument is a very weak one. We do not accept bad userspace API to avoid restructuring a driver.
I agree that this is a weak argument, but when possible solutions are otherwise mostly equal, then easy and especially also cleanliness of implementation definitely comes into play. We don't have an infinite amount of developer time (the opposite actually).
Quoted 75 lines
FWIW adding
attributes that way is already racy and a bug:http://kroah.com/log/blog/2013/06/26/how-to-create-a-sysfs-file-correctly/
The power-supply subsystem offers registering custom sysfs files since a few kernel releases by setting up the following:
/* Run-time specific power supply configuration */
struct power_supply_config { ... /* Device specific sysfs attributes */ const struct attribute_group **attr_grp; ... }All drivers in
drivers/power/supply/have been converted and the ACPI is one of the last drivers not using this.Quoted 14 lines
Quoted 14 lines
--- Documentation/ABI/testing/sysfs-class-power | 27 +++++++++++++++++++++ drivers/power/supply/power_supply_sysfs.c | 2 ++ include/linux/power_supply.h | 2 ++ 3 files changed, 31 insertions(+)Documentation/ABI/testing/sysfs-class-power +0
-0@@ -455,6 +455,33 @@ Description: "Unknown", "Charging", "Discharging", "Not charging", "Full"Quoted 16 lines
Documentation/ABI/testing/sysfs-class-power Description: · line 470
Quoted 13 lines
Documentation/ABI/testing/sysfs-class-power +13
-0+What: /sys/class/power_supply/<supply_name>/force_discharge +Date: September 2021 +Contact: [email protected] +Description: + Represents the forced discharging status of the battery. + + Access: Read, Write + + Valid values: + == ==================================== + 0: Force discharge while AC is attached + 1: Terminate forced discharging +I think you have 0 and 1 swapped here? I would expect 1 to be enable forced discharging and 0 be normal operation, iow only discharge when not on AC.
Considering some Thinkpads have two batteries the naming and description of this is quite bad. Only the valid values part suggests that this is just about AC.
Quoted 6 lines
Documentation/ABI/testing/sysfs-class-power Description: · line 476
Quoted 6 lines
Documentation/ABI/testing/sysfs-class-power +6
-0+What: /sys/class/power_supply/<supply_name>/inhibit_charge +Date: September 2021 +Contact: [email protected] +Description: + Represents the presence of a manual override over the threshold + attributes of the battery, thus inhibiting battery charge.The first part is specific to thinkpad implementation.
Quoted 8 lines
Documentation/ABI/testing/sysfs-class-power Description: · line 484
Quoted 8 lines
Documentation/ABI/testing/sysfs-class-power +8
-0+ + Access: Read, Write + + Valid values: + == ====================== + 1: Stop charging + 0: Terminate the override +I wonder if its better to put both into the same file, considering that the only logical options are
Quoted 5 lines
* 0 = no override (= charge when possible)
* 1 = force idle
* 2 = force dischargeI.e. forced discharge implies battery not being charged.
Right, force-discharge automatically implies charging is being inhibited, so putting this in one file makes sense.
Any suggestion for the name of the file ?
Regards,
Hans
Quoted 35 lines
Quoted 35 lines
Quoted 22 lines
Documentation/ABI/testing/sysfs-class-power +0
-0What: /sys/class/power_supply/<supply_name>/technology Date: May 2007 Contact: [email protected]drivers/power/supply/power_supply_sysfs.c +2
-0@@ -136,6 +136,8 @@ static const char * const POWER_SUPPLY_SCOPE_TEXT[] = {static struct power_supply_attr power_supply_attrs[] = {/* Properties of type `int' */ POWER_SUPPLY_ENUM_ATTR (STATUS ), +POWER_SUPPLY_ENUM_ATTR (FORCE_DISCHARGE ), +POWER_SUPPLY_ENUM_ATTR (INHIBIT_CHARGE ),POWER_SUPPLY_ENUM_ATTR (CHARGE_TYPE ),POWER_SUPPLY_ENUM_ATTR (HEALTH ),POWER_SUPPLY_ATTR (PRESENT ),include/linux/power_supply.h +0
-0include/linux/power_supply.h enum { · line 103
Quoted 8 lines
include/linux/power_supply.h +2
-0@@ -96,6 +96,8 @@ enum {enum power_supply_property {/* Properties of type `int' */ POWER_SUPPLY_PROP_STATUS =0 , +POWER_SUPPLY_PROP_FORCE_DISCHARGE , +POWER_SUPPLY_PROP_INHIBIT_CHARGE ,POWER_SUPPLY_PROP_CHARGE_TYPE ,POWER_SUPPLY_PROP_HEALTH ,POWER_SUPPLY_PROP_PRESENT ,Regards,
Hans
Hi,
Quoted 4 lines · Hans de Goede
Right, force-discharge automatically implies charging is being inhibited, so putting this in one file makes sense.
Any suggestion for the name of the file?
Maybe like this?
---------------------------------------------------------------------
What: /sys/class/power_supply/<supply_name>/charge_behaviour
Date: October 2021
Contact: [email protected]
Description:
Configure battery behaviour when a charger is being connected.
Access: Read, Write
Valid values:
0: auto / no override
When charger is connected battery should be charged
1: force idle
When charger is connected the battery should neither be charged nor discharged.
2: force discharge
When charger is connected the battery should be discharged anyways.
---------------------------------------------------------------------
-- Sebastian
Hi,
Quoted 21 lines · Sebastian Reichel
Hi,
Quoted 4 lines · Hans de Goede
Right, force-discharge automatically implies charging is being inhibited, so putting this in one file makes sense.
Any suggestion for the name of the file?
Maybe like this?
---------------------------------------------------------------------
What: /sys/class/power_supply/<supply_name>/charge_behaviour
Date: October 2021
Contact: [email protected]
Description:
Configure battery behaviour when a charger is being connected.Access: Read, Write
Valid values:
Quoted 9 lines
0: auto / no override
When charger is connected battery should be charged
1: force idle
When charger is connected the battery should neither be charged nor discharged.
2: force discharge
When charger is connected the battery should be discharged anyways.
---------------------------------------------------------------------
That looks good to me. Although I just realized that some hw may only support 1. or 2. maybe explicitly document this and that EOPNOTSUPP will be reported when the value is not supported (vs EINVAL for plain invalid values) ?
Regards,
Hans
Hi Hans,
Quoted 30 lines · Hans de Goede
Quoted 19 lines · Sebastian Reichel
Quoted 4 lines · Hans de Goede
Right, force-discharge automatically implies charging is being inhibited, so putting this in one file makes sense.
Any suggestion for the name of the file?
Maybe like this?
---------------------------------------------------------------------
What: /sys/class/power_supply/<supply_name>/charge_behaviour
Date: October 2021
Contact: [email protected]
Description:
Configure battery behaviour when a charger is being connected.Access: Read, Write
Valid values:
Quoted 9 lines
0: auto / no override
When charger is connected battery should be charged
1: force idle
When charger is connected the battery should neither be charged nor discharged.
2: force discharge
When charger is connected the battery should be discharged anyways.
---------------------------------------------------------------------
Quoted 4 lines
That looks good to me. Although I just realized that some hw may only support 1. or 2. maybe explicitly document this and that EOPNOTSUPP will be reported when the value is not supported (vs EINVAL for plain invalid values)?
Sounds good to me.
-- Sebastian
Quoted 34 lines · Hans de Goede
Hi,
Quoted 21 lines · Sebastian Reichel
Hi,
Quoted 4 lines · Hans de Goede
Right, force-discharge automatically implies charging is being inhibited, so putting this in one file makes sense.
Any suggestion for the name of the file?
Maybe like this?
---------------------------------------------------------------------
What: /sys/class/power_supply/<supply_name>/charge_behaviour
Date: October 2021
Contact: [email protected]
Description:
Configure battery behaviour when a charger is being connected.Access: Read, Write
Valid values:
Quoted 9 lines
0: auto / no override
When charger is connected battery should be charged
1: force idle
When charger is connected the battery should neither be charged nor discharged.
2: force discharge
When charger is connected the battery should be discharged anyways.
---------------------------------------------------------------------
Quoted 4 lines
That looks good to me. Although I just realized that some hw may only support 1. or 2. maybe explicitly document this and that EOPNOTSUPP will be reported when the value is not supported (vs EINVAL for plain invalid values) ?
Would that not force a userspace applications to offer all possibilities to the user only to tell them that it's not supported?
If the driver knows what is supported and what not it should make this discoverable without actually performing the operation.
Maybe something along the lines of /sys/power/mem_sleep.
Thomas
Hi,
Quoted 40 lines · Thomas Weißschuh
Quoted 34 lines · Hans de Goede
Hi,
Quoted 21 lines · Sebastian Reichel
Hi,
Quoted 4 lines · Hans de Goede
Right, force-discharge automatically implies charging is being inhibited, so putting this in one file makes sense.
Any suggestion for the name of the file?
Maybe like this?
---------------------------------------------------------------------
What: /sys/class/power_supply/<supply_name>/charge_behaviour
Date: October 2021
Contact: [email protected]
Description:
Configure battery behaviour when a charger is being connected.Access: Read, Write
Valid values:
Quoted 9 lines
0: auto / no override
When charger is connected battery should be charged
1: force idle
When charger is connected the battery should neither be charged nor discharged.
2: force discharge
When charger is connected the battery should be discharged anyways.
---------------------------------------------------------------------Quoted 4 lines
That looks good to me. Although I just realized that some hw may only support 1. or 2. maybe explicitly document this and that EOPNOTSUPP will be reported when the value is not supported (vs EINVAL for plain invalid values) ?
Quoted 6 lines
Would that not force a userspace applications to offer all possibilities to the user only to tell them that it's not supported?
If the driver knows what is supported and what not it should make this discoverable without actually performing the operation.Maybe something along the lines of
/sys/power/mem_sleep.
Good point, but something like /sys/power/mem_sleep works very differently then how all the other power_supply properties work.
In general if something is supported or not on a psy class device is communicated by the presence / absence of attributes.
So I think we should move back to having 2 separate attributes for this after all; and group the 2 together in the doc and document that enabling (setting to 1) one of force_charge / inhibit_charge automatically clears the setting of the other.
Then the availability of the features can simply be probed by checking for the presence of the property files.
Regards,
Hans
Hi,
Quoted 42 lines · Hans de Goede
Quoted 41 lines · Thomas Weißschuh
Quoted 30 lines · Hans de Goede
Quoted 19 lines · Sebastian Reichel
Quoted 4 lines · Hans de Goede
Right, force-discharge automatically implies charging is being inhibited, so putting this in one file makes sense.
Any suggestion for the name of the file?
Maybe like this?
---------------------------------------------------------------------
What: /sys/class/power_supply/<supply_name>/charge_behaviour
Date: October 2021
Contact: [email protected]
Description:
Configure battery behaviour when a charger is being connected.Access: Read, Write
Valid values:
Quoted 9 lines
0: auto / no override
When charger is connected battery should be charged
1: force idle
When charger is connected the battery should neither be charged nor discharged.
2: force discharge
When charger is connected the battery should be discharged anyways.
---------------------------------------------------------------------Quoted 4 lines
That looks good to me. Although I just realized that some hw may only support 1. or 2. maybe explicitly document this and that EOPNOTSUPP will be reported when the value is not supported (vs EINVAL for plain invalid values) ?
Would that not force a userspace applications to offer all possibilities to the user only to tell them that it's not supported?
If the driver knows what is supported and what not it should make this discoverable without actually performing the operation.
Quoted 4 lines
Quoted 1 line
Maybe something along the lines of
/sys/power/mem_sleep.Good point, but something like
/sys/power/mem_sleepworks very differently then how all the otherpower_supplyproperties work.
Actually we already use this format in power-supply for USB types, implemented in power_supply_show_usb_type().
Quoted 10 lines
In general if something is supported or not on a psy class device is communicated by the presence / absence of attributes.
So I think we should move back to having 2 separate attributes for this after all; and group the 2 together in the doc and document that enabling (setting to 1) one of
force_charge/inhibit_chargeautomatically clears the setting of the other.Then the availability of the features can simply be probed by checking for the presence of the property files.
If it's two files, then somebody needs to come up with proper names. Things like 'force_discharge' look sensible in this context, but on a system with two batteries (like some Thinkpads have) it is easy to confuse with "I want to discharge this battery before the other one (while no AC is connected)".
-- Sebastian
Hi,
Quoted 61 lines · Sebastian Reichel
Hi,
Quoted 42 lines · Hans de Goede
Quoted 41 lines · Thomas Weißschuh
Quoted 30 lines · Hans de Goede
Quoted 19 lines · Sebastian Reichel
Quoted 4 lines · Hans de Goede
Right, force-discharge automatically implies charging is being inhibited, so putting this in one file makes sense.
Any suggestion for the name of the file?
Maybe like this?
---------------------------------------------------------------------
What: /sys/class/power_supply/<supply_name>/charge_behaviour
Date: October 2021
Contact: [email protected]
Description:
Configure battery behaviour when a charger is being connected.Access: Read, Write
Valid values:
Quoted 9 lines
0: auto / no override
When charger is connected battery should be charged
1: force idle
When charger is connected the battery should neither be charged nor discharged.
2: force discharge
When charger is connected the battery should be discharged anyways.
---------------------------------------------------------------------Quoted 4 lines
That looks good to me. Although I just realized that some hw may only support 1. or 2. maybe explicitly document this and that EOPNOTSUPP will be reported when the value is not supported (vs EINVAL for plain invalid values) ?
Would that not force a userspace applications to offer all possibilities to the user only to tell them that it's not supported?
If the driver knows what is supported and what not it should make this discoverable without actually performing the operation.Quoted 4 lines
Quoted 1 line
Maybe something along the lines of
/sys/power/mem_sleep.Good point, but something like
/sys/power/mem_sleepworks very differently then how all the otherpower_supplyproperties work.Actually we already use this format in power-supply for USB types, implemented in
power_supply_show_usb_type().Quoted 8 lines
In general if something is supported or not on a psy class device is communicated by the presence / absence of attributes.
So I think we should move back to having 2 separate attributes for this after all; and group the 2 together in the doc and document that enabling (setting to 1) one of
force_charge/inhibit_chargeautomatically clears the setting of the other.
Quoted 8 lines
Quoted 2 lines
Then the availability of the features can simply be probed by checking for the presence of the property files.
If it's two files, then somebody needs to come up with proper names. Things like '
force_discharge' look sensible in this context, but on a system with two batteries (like some Thinkpads have) it is easy to confuse with "I want to discharge this battery before the other one (while no AC is connected)".
Ah I did not realize there was already some (read-only) precedence for this in the psy subsystem.
Since there is precedence for this using /sys/class/power_supply/<supply_name>/charge_behaviour
with an example contents of say:
[auto] inhibit-charge force-discharge
Works for me and having 1 file instead of 2 is better then because this clearly encapsulates that inhibit-charge and force-discharge are mutually exclusive.
Regards,
Hans
Hi,
Quoted 77 lines · Hans de Goede
Hi,
Quoted 61 lines · Sebastian Reichel
Hi,
Quoted 42 lines · Hans de Goede
Quoted 41 lines · Thomas Weißschuh
Quoted 30 lines · Hans de Goede
Quoted 19 lines · Sebastian Reichel
Quoted 4 lines · Hans de Goede
Right, force-discharge automatically implies charging is being inhibited, so putting this in one file makes sense.
Any suggestion for the name of the file?
Maybe like this?
---------------------------------------------------------------------
What: /sys/class/power_supply/<supply_name>/charge_behaviour
Date: October 2021
Contact: [email protected]
Description:
Configure battery behaviour when a charger is being connected.Access: Read, Write
Valid values:
Quoted 9 lines
0: auto / no override
When charger is connected battery should be charged
1: force idle
When charger is connected the battery should neither be charged nor discharged.
2: force discharge
When charger is connected the battery should be discharged anyways.
---------------------------------------------------------------------Quoted 4 lines
That looks good to me. Although I just realized that some hw may only support 1. or 2. maybe explicitly document this and that EOPNOTSUPP will be reported when the value is not supported (vs EINVAL for plain invalid values) ?
Would that not force a userspace applications to offer all possibilities to the user only to tell them that it's not supported?
If the driver knows what is supported and what not it should make this discoverable without actually performing the operation.Quoted 4 lines
Quoted 1 line
Maybe something along the lines of
/sys/power/mem_sleep.Good point, but something like
/sys/power/mem_sleepworks very differently then how all the otherpower_supplyproperties work.Actually we already use this format in power-supply for USB types, implemented in
power_supply_show_usb_type().Quoted 8 lines
In general if something is supported or not on a psy class device is communicated by the presence / absence of attributes.
So I think we should move back to having 2 separate attributes for this after all; and group the 2 together in the doc and document that enabling (setting to 1) one of
force_charge/inhibit_chargeautomatically clears the setting of the other.Quoted 8 lines
Quoted 2 lines
Then the availability of the features can simply be probed by checking for the presence of the property files.
If it's two files, then somebody needs to come up with proper
names. Things like 'force_discharge' look sensible in this context,
but on a system with two batteries (like some Thinkpads have) it
is easy to confuse with "I want to discharge this battery before
the other one (while no AC is connected)". > Ah I did not realize there was already some (read-only) precedencefor this in the psy subsystem.
Since there is precedence for this using /sys/class/power_supply/<supply_name>/charge_behaviour
Quoted 7 lines
with an example contents of say:
[auto] inhibit-charge force-discharge
Works for me and having 1 file instead of 2 is better then because this clearly encapsulates that inhibit-charge and force-discharge are mutually exclusive.
In fact they do not reset each other on ThinkPads. It's possible to
1. set force_discharge=1 -- discharging commences
2. set inhibit_charge=1 -- discharging continues, force_discharge remains 1
3. set force_discharge=0 -- battery does not charge, inhibit_charge remains 1
Quoted 6 lines
Regards,
Hans
Freundliche Grüße / Kind regards,
Thomas Koch
Mail : [email protected]
Web : https://linrunner.de/tlp
Quoted 101 lines · Thomas Koch
Date: Wed, 6 Oct 2021 21:24:14 +0200
From: Thomas Koch <[email protected]>
To: Hans de Goede <[email protected]>, Sebastian Reichel
<[email protected]>
Cc: Thomas Weißschuh <[email protected]>, Nicolò Piazzalunga
<[email protected]>, [email protected], "[email protected]" <[email protected]>, "[email protected]" <[email protected]>
Subject: Re: [RFC] add standardized attributes forforce_dischargeand
inhibit_charge
User-Agent: Mozilla/5.0 (X11; Linuxx86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0Hi,
Quoted 77 lines · Hans de Goede
Hi,
Quoted 61 lines · Sebastian Reichel
Hi,
Quoted 42 lines · Hans de Goede
Quoted 41 lines · Thomas Weißschuh
Quoted 30 lines · Hans de Goede
Quoted 19 lines · Sebastian Reichel
Quoted 4 lines · Hans de Goede
Right, force-discharge automatically implies charging is being inhibited, so putting this in one file makes sense.
Any suggestion for the name of the file?
Maybe like this?
---------------------------------------------------------------------
What: /sys/class/power_supply/<supply_name>/charge_behaviour
Date: October 2021
Contact: [email protected]
Description:
Configure battery behaviour when a charger is being connected.Access: Read, Write
Valid values:
Quoted 9 lines
0: auto / no override
When charger is connected battery should be charged
1: force idle
When charger is connected the battery should neither be charged nor discharged.
2: force discharge
When charger is connected the battery should be discharged anyways.
---------------------------------------------------------------------Quoted 4 lines
That looks good to me. Although I just realized that some hw may only support 1. or 2. maybe explicitly document this and that EOPNOTSUPP will be reported when the value is not supported (vs EINVAL for plain invalid values) ?
Would that not force a userspace applications to offer all possibilities to the user only to tell them that it's not supported?
If the driver knows what is supported and what not it should make this discoverable without actually performing the operation.Quoted 4 lines
Quoted 1 line
Maybe something along the lines of
/sys/power/mem_sleep.Good point, but something like
/sys/power/mem_sleepworks very differently then how all the otherpower_supplyproperties work.Actually we already use this format in power-supply for USB types, implemented in
power_supply_show_usb_type().Quoted 8 lines
In general if something is supported or not on a psy class device is communicated by the presence / absence of attributes.
So I think we should move back to having 2 separate attributes for this after all; and group the 2 together in the doc and document that enabling (setting to 1) one of
force_charge/inhibit_chargeautomatically clears the setting of the other.Quoted 8 lines
Quoted 2 lines
Then the availability of the features can simply be probed by checking for the presence of the property files.
If it's two files, then somebody needs to come up with proper
names. Things like 'force_discharge' look sensible in this context,
but on a system with two batteries (like some Thinkpads have) it
is easy to confuse with "I want to discharge this battery before
the other one (while no AC is connected)". > Ah I did not realize there was already some (read-only) precedencefor this in the psy subsystem.
Since there is precedence for this using /sys/class/power_supply/<supply_name>/charge_behaviour
Quoted 7 lines
with an example contents of say:
[auto] inhibit-charge force-discharge
Works for me and having 1 file instead of 2 is better then because this clearly encapsulates that inhibit-charge and force-discharge are mutually exclusive.
Quoted 6 lines
In fact they do not reset each other on ThinkPads. It's possible to
1. set force_discharge=1 -- discharging commences
2. set inhibit_charge=1 -- discharging continues,force_dischargeremains 1
3. set force_discharge=0 -- battery does not charge,inhibit_chargeremains 1
But in the end there are only three states the user cares about, or? (inhibit, force_discharge and normal)
So when selecting inhibit or force_discharge the driver itself can reset the other option so the users do not have to care about the internal state of the EC.
Thomas
Hi,
Quoted 109 lines · Thomas Weißschuh
Quoted 101 lines · Thomas Koch
Date: Wed, 6 Oct 2021 21:24:14 +0200
From: Thomas Koch <[email protected]>
To: Hans de Goede <[email protected]>, Sebastian Reichel
<[email protected]>
Cc: Thomas Weißschuh <[email protected]>, Nicolò Piazzalunga
<[email protected]>, [email protected], "[email protected]" <[email protected]>, "[email protected]" <[email protected]>
Subject: Re: [RFC] add standardized attributes forforce_dischargeand
inhibit_charge
User-Agent: Mozilla/5.0 (X11; Linuxx86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0Hi,
Quoted 77 lines · Hans de Goede
Hi,
Quoted 61 lines · Sebastian Reichel
Hi,
Quoted 42 lines · Hans de Goede
Quoted 41 lines · Thomas Weißschuh
Quoted 30 lines · Hans de Goede
Quoted 19 lines · Sebastian Reichel
Quoted 4 lines · Hans de Goede
Right, force-discharge automatically implies charging is being inhibited, so putting this in one file makes sense.
Any suggestion for the name of the file?
Maybe like this?
---------------------------------------------------------------------
What: /sys/class/power_supply/<supply_name>/charge_behaviour
Date: October 2021
Contact: [email protected]
Description:
Configure battery behaviour when a charger is being connected.Access: Read, Write
Valid values:
Quoted 9 lines
0: auto / no override
When charger is connected battery should be charged
1: force idle
When charger is connected the battery should neither be charged nor discharged.
2: force discharge
When charger is connected the battery should be discharged anyways.
---------------------------------------------------------------------Quoted 4 lines
That looks good to me. Although I just realized that some hw may only support 1. or 2. maybe explicitly document this and that EOPNOTSUPP will be reported when the value is not supported (vs EINVAL for plain invalid values) ?
Would that not force a userspace applications to offer all possibilities to the user only to tell them that it's not supported?
If the driver knows what is supported and what not it should make this discoverable without actually performing the operation.Quoted 4 lines
Quoted 1 line
Maybe something along the lines of
/sys/power/mem_sleep.Good point, but something like
/sys/power/mem_sleepworks very differently then how all the otherpower_supplyproperties work.Actually we already use this format in power-supply for USB types, implemented in
power_supply_show_usb_type().Quoted 8 lines
In general if something is supported or not on a psy class device is communicated by the presence / absence of attributes.
So I think we should move back to having 2 separate attributes for this after all; and group the 2 together in the doc and document that enabling (setting to 1) one of
force_charge/inhibit_chargeautomatically clears the setting of the other.Quoted 8 lines
Quoted 2 lines
Then the availability of the features can simply be probed by checking for the presence of the property files.
If it's two files, then somebody needs to come up with proper
names. Things like 'force_discharge' look sensible in this context,
but on a system with two batteries (like some Thinkpads have) it
is easy to confuse with "I want to discharge this battery before
the other one (while no AC is connected)". > Ah I did not realize there was already some (read-only) precedencefor this in the psy subsystem.
Since there is precedence for this using /sys/class/power_supply/<supply_name>/charge_behaviour
Quoted 7 lines
with an example contents of say:
[auto] inhibit-charge force-discharge
Works for me and having 1 file instead of 2 is better then because this clearly encapsulates that inhibit-charge and force-discharge are mutually exclusive.
Quoted 6 lines
In fact they do not reset each other on ThinkPads. It's possible to
1. set force_discharge=1 -- discharging commences
2. set inhibit_charge=1 -- discharging continues,force_dischargeremains 1
3. set force_discharge=0 -- battery does not charge,inhibit_chargeremains 1
Quoted 6 lines
But in the end there are only three states the user cares about, or? (inhibit,
force_dischargeand normal)So when selecting inhibit or
force_dischargethe driver itself can reset the other option so the users do not have to care about the internal state of the EC.
Correct. It works with the three states Sebastian suggested because force_discharge overrules inhibit_charge.
Whereby for user-friendliness I would prefer Hans' strings
Quoted 1 line
Quoted 1 line
Quoted 1 line
[auto] inhibit-charge force-discharge
to Sebastian's numbered states.
Quoted 3 lines
Thomas
Freundliche Grüße / Kind regards,
Thomas Koch
Mail : [email protected]
Web : https://linrunner.de/tlp
Hi,
Quoted 92 lines · Thomas Koch
Quoted 86 lines
Quoted 79 lines
Quoted 72 lines
Quoted 59 lines · Hans de Goede
Quoted 42 lines · Thomas Weißschuh
Quoted 41 lines · Hans de Goede
Quoted 30 lines
On 10/6/21 12:06 AM, Sebastian Reichel wrote:Ack
Quoted 19 lines · Hans de Goede
Quoted 4 lines
Right, force-discharge automatically implies charging is being inhibited, so putting this in one file makes sense.
Any suggestion for the name of the file?
Maybe like this?
---------------------------------------------------------------------
What: /sys/class/power_supply/<supply_name>/charge_behaviour
Date: October 2021
Contact: [email protected]
Description:
Configure battery behaviour when a charger is being connected.Access: Read, Write
Valid values:
Quoted 9 lines
0: auto / no override
When charger is connected battery should be charged
1: force idle
When charger is connected the battery should neither be charged nor discharged.
2: force discharge
When charger is connected the battery should be discharged anyways.
---------------------------------------------------------------------Quoted 4 lines
That looks good to me. Although I just realized that some hw may only support 1. or 2. maybe explicitly document this and that EOPNOTSUPP will be reported when the value is not supported (vs EINVAL for plain invalid values) ?
Would that not force a userspace applications to offer all possibilities to the user only to tell them that it's not supported?
If the driver knows what is supported and what not it should make this discoverable without actually performing the operation.Quoted 4 lines
Quoted 1 line
Maybe something along the lines of
/sys/power/mem_sleep.Good point, but something like
/sys/power/mem_sleepworks very differently then how all the otherpower_supplyproperties work.Actually we already use this format in power-supply for USB types, implemented in
power_supply_show_usb_type().Quoted 8 lines
In general if something is supported or not on a psy class device is communicated by the presence / absence of attributes.
So I think we should move back to having 2 separate attributes for this after all; and group the 2 together in the doc and document that enabling (setting to 1) one of
force_charge/inhibit_chargeautomatically clears the setting of the other.Quoted 8 lines
Quoted 2 lines
Then the availability of the features can simply be probed by checking for the presence of the property files.
If it's two files, then somebody needs to come up with proper
names. Things like 'force_discharge' look sensible in this context,
but on a system with two batteries (like some Thinkpads have) it
is easy to confuse with "I want to discharge this battery before
the other one (while no AC is connected)". > Ah I did not realize there was already some (read-only) precedencefor this in the psy subsystem.
Since there is precedence for this using /sys/class/power_supply/<supply_name>/charge_behaviour
Quoted 7 lines
with an example contents of say:
[auto] inhibit-charge force-discharge
Works for me and having 1 file instead of 2 is better then because this clearly encapsulates that inhibit-charge and force-discharge are mutually exclusive.
Quoted 6 lines
In fact they do not reset each other on ThinkPads. It's possible to
1. set force_discharge=1 -- discharging commences
2. set inhibit_charge=1 -- discharging continues,force_dischargeremains 1
3. set force_discharge=0 -- battery does not charge,inhibit_chargeremains 1Quoted 6 lines
But in the end there are only three states the user cares about, or? (inhibit,
force_dischargeand normal)So when selecting inhibit or
force_dischargethe driver itself can reset the other option so the users do not have to care about the internal state of the EC.
Quoted 8 lines
Correct. It works with the three states Sebastian suggested because
force_dischargeoverrulesinhibit_charge.Whereby for user-friendliness I would prefer Hans' strings
Quoted 1 line
Quoted 1 line
Quoted 1 line
[auto] inhibit-charge force-discharge
to Sebastian's numbered states.
LGTM.
-- Sebastian
Hi Hans,
you are right, I swapped 1 and 0 there of course, my mistake.
Nicolò