summaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
authorWaqar Hameed <waqar.hameed@axis.com>2026-09-01 21:35:08 +0200
committerSebastian Reichel <sebastian.reichel@collabora.com>2026-09-10 00:43:05 +0200
commit4fe4d3dc5c20c62789c718946bdb4f72a7cf363d (patch)
tree2e6665bce4ae41cd06973587bbf56e4e8f1bcef4 /drivers/power
parentf170c05e3e08aa2068601db369078bb83dc5e7e7 (diff)
downloadlinux-next-4fe4d3dc5c20c62789c718946bdb4f72a7cf363d.tar.gz
linux-next-4fe4d3dc5c20c62789c718946bdb4f72a7cf363d.zip
power: supply: Add sysfs entry for system load control
There are devices that can control the connection from power to system load. For example, with a field-effect transistor between a battery and the system load (BATFET). Drivers for these devices are currently enrolling their own custom `sysfs` property to control this. In order to unify this, add a new `sysfs` entry for controlling such switch and corresponding `power_supply_property` with `enum` values. The obvious states are "on" and "off", i.e. there is a connection or not, respectively. However, many devices can also enter special modes such as "low-power", "shipping" or "deep sleep". Since the members in `struct power_supply_desc` already are ordered, adding `load_switches` only increases the size with 4 bytes, as can be seen from `pahole`: struct power_supply_desc { const char * name; /* 0 4 */ enum power_supply_type type; /* 4 4 */ u32 charge_types; /* 8 4 */ u32 usb_types; /* 12 4 */ u32 load_switches; /* 16 4 */ const enum power_supply_property * properties; /* 20 4 */ size_t num_properties; /* 24 4 */ int (*get_property)(...); /* 28 4 */ int (*set_property)(...); /* 32 4 */ int (*property_is_writeable)(...); /* 36 4 */ void (*external_power_changed)(...); /* 40 4 */ int (*init)(struct power_supply *); /* 44 4 */ int use_for_apm; /* 48 4 */ bool no_thermal; /* 52 1 */ u8 charge_behaviours; /* 53 1 */ /* size: 56, cachelines: 1, members: 15 */ /* padding: 2 */ /* last cacheline: 56 bytes */ }; Signed-off-by: Waqar Hameed <waqar.hameed@axis.com> Link: https://patch.msgid.link/d86f528de9a058091f806d9676639239cfeaf805.1788290289.git.waqar.hameed@axis.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/supply/power_supply_sysfs.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index 9d6b24856c8b..b0f524d152cf 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -152,6 +152,14 @@ static const char * const POWER_SUPPLY_CHARGE_BEHAVIOUR_TEXT[] = {
[POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE] = "force-discharge",
};
+static const char *const POWER_SUPPLY_LOAD_SWITCH_TEXT[] = {
+ [POWER_SUPPLY_LOAD_SWITCH_UNKNOWN] = "Unknown",
+ [POWER_SUPPLY_LOAD_SWITCH_ON] = "On",
+ [POWER_SUPPLY_LOAD_SWITCH_OFF] = "Off",
+ [POWER_SUPPLY_LOAD_SWITCH_STANDBY] = "Standby",
+ [POWER_SUPPLY_LOAD_SWITCH_SHIP] = "Ship",
+};
+
static struct power_supply_attr power_supply_attrs[] __ro_after_init = {
/* Properties of type `int' */
POWER_SUPPLY_ENUM_ATTR(STATUS),
@@ -231,6 +239,7 @@ static struct power_supply_attr power_supply_attrs[] __ro_after_init = {
POWER_SUPPLY_ATTR(MANUFACTURE_DAY),
POWER_SUPPLY_ATTR(INTERNAL_RESISTANCE),
POWER_SUPPLY_ATTR(STATE_OF_HEALTH),
+ POWER_SUPPLY_ENUM_ATTR(LOAD_SWITCH),
/* Properties of type `const char *' */
POWER_SUPPLY_ATTR(MODEL_NAME),
POWER_SUPPLY_ATTR(MANUFACTURER),
@@ -400,6 +409,14 @@ static ssize_t power_supply_format_property(struct device *dev,
ret = power_supply_show_charge_types(dev, psy,
value.intval, buf);
break;
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
+ if (uevent) /* no possible values in uevents */
+ goto default_format;
+ ret = power_supply_show_enum_with_available(
+ dev, POWER_SUPPLY_LOAD_SWITCH_TEXT,
+ ARRAY_SIZE(POWER_SUPPLY_LOAD_SWITCH_TEXT),
+ psy->desc->load_switches, value.intval, buf);
+ break;
case POWER_SUPPLY_PROP_MODEL_NAME ... POWER_SUPPLY_PROP_SERIAL_NUMBER:
ret = sysfs_emit(buf, "%s\n", value.strval);
break;