Skip to contentSkip to conversation

RFC: Extending charge_type power-supply property to show valid values

DISCUSSION Hans de Goede 2 participants 2 messages Aug 26, 2024 – Sep 3, 2024

lore
Share & tools
lore
#0 lore raw

<resend with Thomas who implemented the charge-behavior code added to the Cc>

Hi Sebastian,

Jelle (in the Cc) is looking into adding a UI to GNOME to allow users to enable battery long-life mode. The initial plan was to use the charge start and stop thresholds but not all laptop models support these, some only have a single toggle to turn long-life mode on/off.

At first look it seems that charge_type is the right userspace API to use for these single toggle only laptop models, offering "Standard" and "Long Life" as valid options.

However we don't want userspace to have to write charge_type just to find out which values are supported.

My proposal for this is to have a new POWER_SUPPLY_PROP_CHARGE_TYPES properties which behaves like USB_TYPE / CHARGE_BEHAVIOR, e.g. :

[hans@x1 linux]$ cat /sys/class/power_supply/ucsi-source-psy-USBC000\:001/usb_type
[C] PD PD_PPS

The idea would be to copy the charge_behavior model and add a charge_types bitmask to struct power_supply_desc mirroring the u8 charge_behaviours; bitmask. This will also allow re-using power_supply_charge_behaviour_show() turning it into a generic show function for usb_type / charge_behavior style properties.

Other then having the usb_type / charge_behavior style show() output the new charge_types which I'm suggesting would behave exactly the same as the old charge_type and drivers can use the same code paths to implement both. To get support for the new charge_types drivers just need to set a power_supply_desc.charge_types bitmap and add POWER_SUPPLY_PROP_CHARGE_TYPES to their list of supported properties.

The idea is for charge_types to basically superseed charge_type offering the same functionality while advertising which values are valid for writing, while keeping charge_type around for backward compatibility.

If this sounds good to you I can write a patch-set implementing the suggestion, + converting one or 2 drivers which already support writing charge_type atm.

Regards,

Hans

#1 lore raw

Hi,

Quoted 36 lines · Hans de Goede

<resend with Thomas who implemented the charge-behavior code added to the Cc>

Hi Sebastian,

Jelle (in the Cc) is looking into adding a UI to GNOME to allow users to enable battery long-life mode. The initial plan was to use the charge start and stop thresholds but not all laptop models support these, some only have a single toggle to turn long-life mode on/off.

At first look it seems that charge_type is the right userspace API to use for these single toggle only laptop models, offering "Standard" and "Long Life" as valid options.

However we don't want userspace to have to write charge_type just to find out which values are supported.

My proposal for this is to have a new POWER_SUPPLY_PROP_CHARGE_TYPES properties which behaves like USB_TYPE / CHARGE_BEHAVIOR, e.g. :

[hans@x1 linux]$ cat /sys/class/power_supply/ucsi-source-psy-USBC000\:001/usb_type
[C] PD PD_PPS

The idea would be to copy the charge_behavior model and add a charge_types bitmask to struct power_supply_desc mirroring the u8 charge_behaviours; bitmask. This will also allow re-using power_supply_charge_behaviour_show() turning it into a generic show function for usb_type / charge_behavior style properties.

Other then having the usb_type / charge_behavior style show() output the new charge_types which I'm suggesting would behave exactly the same as the old charge_type and drivers can use the same code paths to implement both. To get support for the new charge_types drivers just need to set a power_supply_desc.charge_types bitmap and add POWER_SUPPLY_PROP_CHARGE_TYPES to their list of supported properties.

Quoted 8 lines

The idea is for charge_types to basically superseed charge_type offering the same functionality while advertising which values are valid for writing, while keeping charge_type around for backward compatibility.

If this sounds good to you I can write a patch-set implementing the suggestion, + converting one or 2 drivers which already support writing charge_type atm.

Yes, this plan sounds good to me.

-- Sebastian