Commit 4e61f1e9 authored by Thomas Weißschuh's avatar Thomas Weißschuh Committed by Sebastian Reichel

power: supply: core: fix charge_behaviour formatting

This property is documented to have a special format which exposes all
available behaviours and the currently active one at the same time. For
this special format some helpers are provided.

When the charge_behaviour property was added in
1b0b6cc8 ("power: supply: add charge_behaviour attributes"), it did
not update the default logic in in power_supply_sysfs.c to use the
format helpers. Thus by default only the currently active behaviour
is printed. This fixes the default logic to follow the documented
format.

There is currently only one in-tree drivers exposing charge behaviours -
thinkpad_acpi, which is not affected by the change, as it directly uses
the helpers and does not use the power_supply_sysfs.c logic.
Signed-off-by: default avatarThomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20240303-power_supply-charge_behaviour_prop-v2-3-8ebb0a7c2409@weissschuh.netSigned-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 521d75b4
...@@ -271,6 +271,23 @@ static ssize_t power_supply_show_usb_type(struct device *dev, ...@@ -271,6 +271,23 @@ static ssize_t power_supply_show_usb_type(struct device *dev,
return count; return count;
} }
static ssize_t power_supply_show_charge_behaviour(struct device *dev,
struct power_supply *psy,
union power_supply_propval *value,
char *buf)
{
int ret;
ret = power_supply_get_property(psy,
POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR,
value);
if (ret < 0)
return ret;
return power_supply_charge_behaviour_show(dev, psy->desc->charge_behaviours,
value->intval, buf);
}
static ssize_t power_supply_show_property(struct device *dev, static ssize_t power_supply_show_property(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) { char *buf) {
...@@ -303,6 +320,9 @@ static ssize_t power_supply_show_property(struct device *dev, ...@@ -303,6 +320,9 @@ static ssize_t power_supply_show_property(struct device *dev,
ret = power_supply_show_usb_type(dev, psy->desc, ret = power_supply_show_usb_type(dev, psy->desc,
&value, buf); &value, buf);
break; break;
case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
ret = power_supply_show_charge_behaviour(dev, psy, &value, buf);
break;
case POWER_SUPPLY_PROP_MODEL_NAME ... POWER_SUPPLY_PROP_SERIAL_NUMBER: case POWER_SUPPLY_PROP_MODEL_NAME ... POWER_SUPPLY_PROP_SERIAL_NUMBER:
ret = sysfs_emit(buf, "%s\n", value.strval); ret = sysfs_emit(buf, "%s\n", value.strval);
break; break;
......
...@@ -242,6 +242,7 @@ struct power_supply_config { ...@@ -242,6 +242,7 @@ struct power_supply_config {
struct power_supply_desc { struct power_supply_desc {
const char *name; const char *name;
enum power_supply_type type; enum power_supply_type type;
u8 charge_behaviours;
const enum power_supply_usb_type *usb_types; const enum power_supply_usb_type *usb_types;
size_t num_usb_types; size_t num_usb_types;
const enum power_supply_property *properties; const enum power_supply_property *properties;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment