Skip to content

Commit 4e61f1e

Browse files
t-8chsre
authored andcommitted
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 1b0b6cc ("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: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/r/20240303-power_supply-charge_behaviour_prop-v2-3-8ebb0a7c2409@weissschuh.net Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 521d75b commit 4e61f1e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

drivers/power/supply/power_supply_sysfs.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,23 @@ static ssize_t power_supply_show_usb_type(struct device *dev,
271271
return count;
272272
}
273273

274+
static ssize_t power_supply_show_charge_behaviour(struct device *dev,
275+
struct power_supply *psy,
276+
union power_supply_propval *value,
277+
char *buf)
278+
{
279+
int ret;
280+
281+
ret = power_supply_get_property(psy,
282+
POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR,
283+
value);
284+
if (ret < 0)
285+
return ret;
286+
287+
return power_supply_charge_behaviour_show(dev, psy->desc->charge_behaviours,
288+
value->intval, buf);
289+
}
290+
274291
static ssize_t power_supply_show_property(struct device *dev,
275292
struct device_attribute *attr,
276293
char *buf) {
@@ -303,6 +320,9 @@ static ssize_t power_supply_show_property(struct device *dev,
303320
ret = power_supply_show_usb_type(dev, psy->desc,
304321
&value, buf);
305322
break;
323+
case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
324+
ret = power_supply_show_charge_behaviour(dev, psy, &value, buf);
325+
break;
306326
case POWER_SUPPLY_PROP_MODEL_NAME ... POWER_SUPPLY_PROP_SERIAL_NUMBER:
307327
ret = sysfs_emit(buf, "%s\n", value.strval);
308328
break;

include/linux/power_supply.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ struct power_supply_config {
242242
struct power_supply_desc {
243243
const char *name;
244244
enum power_supply_type type;
245+
u8 charge_behaviours;
245246
const enum power_supply_usb_type *usb_types;
246247
size_t num_usb_types;
247248
const enum power_supply_property *properties;

0 commit comments

Comments
 (0)