[PATCH v2 5/8] power: supply: rt9467: Use POWER_SUPPLY_PROP_LOAD_SWITCH
From: Waqar Hameed
Date: Tue Sep 01 2026 - 15:41:28 EST
The framework supports controlling system load with
`POWER_SUPPLY_PROP_LOAD_SWITCH`. Use this to control the BATFET, but
keep old custom `sysfs` ABI for backward compatibility. However, add a
note in ABI documentation that one should prefer the property
`load_switch` instead.
Signed-off-by: Waqar Hameed <waqar.hameed@xxxxxxxx>
---
.../ABI/testing/sysfs-class-power-rt9467 | 2 +
drivers/power/supply/rt9467-charger.c | 54 ++++++++++++++++---
2 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-class-power-rt9467 b/Documentation/ABI/testing/sysfs-class-power-rt9467
index 619b7c45d145d..bfbfd78ec1c19 100644
--- a/Documentation/ABI/testing/sysfs-class-power-rt9467
+++ b/Documentation/ABI/testing/sysfs-class-power-rt9467
@@ -13,6 +13,8 @@ Description:
'Disable' also can help to leave it, but it's more like to
abort the action before the device really enter shipping mode.
+ Note: use /sys/class/power_supply/rt9467-*/load_switch instead.
+
Access: Read, Write
Valid values:
- 1: enabled
diff --git a/drivers/power/supply/rt9467-charger.c b/drivers/power/supply/rt9467-charger.c
index a9a83b263e187..f0d10f44b1090 100644
--- a/drivers/power/supply/rt9467-charger.c
+++ b/drivers/power/supply/rt9467-charger.c
@@ -633,6 +633,39 @@ static int rt9467_psy_set_ieoc(struct rt9467_chg_data *data, int microamp)
return ret;
}
+static int rt9467_set_batfet(struct rt9467_chg_data *data, int val)
+{
+ unsigned int regval;
+
+ switch (val) {
+ case POWER_SUPPLY_LOAD_SWITCH_ON:
+ regval = 0;
+ break;
+ case POWER_SUPPLY_LOAD_SWITCH_OFF:
+ regval = 1;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return regmap_field_write(data->rm_field[F_SHIP_MODE], regval);
+}
+
+static int rt9467_get_batfet(struct rt9467_chg_data *data, int *val)
+{
+ unsigned int regval;
+ int ret;
+
+ ret = regmap_field_read(data->rm_field[F_SHIP_MODE], ®val);
+ if (ret < 0)
+ return ret;
+
+ *val = regval ? POWER_SUPPLY_LOAD_SWITCH_OFF :
+ POWER_SUPPLY_LOAD_SWITCH_ON;
+
+ return 0;
+}
+
static const enum power_supply_property rt9467_chg_properties[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_ONLINE,
@@ -648,6 +681,7 @@ static const enum power_supply_property rt9467_chg_properties[] = {
POWER_SUPPLY_PROP_USB_TYPE,
POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
+ POWER_SUPPLY_PROP_LOAD_SWITCH,
};
static int rt9467_psy_get_property(struct power_supply *psy,
@@ -711,6 +745,8 @@ static int rt9467_psy_get_property(struct power_supply *psy,
val->intval = data->ieoc_ua;
mutex_unlock(&data->ichg_ieoc_lock);
return 0;
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
+ return rt9467_get_batfet(data, &val->intval);
default:
return -ENODATA;
}
@@ -747,6 +783,8 @@ static int rt9467_psy_set_property(struct power_supply *psy,
RT9467_RANGE_IPREC, val->intval);
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
return rt9467_psy_set_ieoc(data, val->intval);
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
+ return rt9467_set_batfet(data, val->intval);
default:
return -EINVAL;
}
@@ -764,6 +802,7 @@ static int rt9467_chg_prop_is_writeable(struct power_supply *psy,
case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
return 1;
default:
return 0;
@@ -777,6 +816,8 @@ static const struct power_supply_desc rt9467_chg_psy_desc = {
BIT(POWER_SUPPLY_USB_TYPE_CDP) |
BIT(POWER_SUPPLY_USB_TYPE_DCP) |
BIT(POWER_SUPPLY_USB_TYPE_UNKNOWN),
+ .load_switches = BIT(POWER_SUPPLY_LOAD_SWITCH_ON) |
+ BIT(POWER_SUPPLY_LOAD_SWITCH_OFF),
.properties = rt9467_chg_properties,
.num_properties = ARRAY_SIZE(rt9467_chg_properties),
.property_is_writeable = rt9467_chg_prop_is_writeable,
@@ -793,14 +834,14 @@ static ssize_t sysoff_enable_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct rt9467_chg_data *data = psy_device_to_chip(dev);
- unsigned int sysoff_enable;
+ int val;
int ret;
- ret = regmap_field_read(data->rm_field[F_SHIP_MODE], &sysoff_enable);
- if (ret)
+ ret = rt9467_get_batfet(data, &val);
+ if (ret < 0)
return ret;
- return sysfs_emit(buf, "%d\n", sysoff_enable);
+ return sysfs_emit(buf, "%d\n", val == POWER_SUPPLY_LOAD_SWITCH_OFF);
}
static ssize_t sysoff_enable_store(struct device *dev,
@@ -815,8 +856,9 @@ static ssize_t sysoff_enable_store(struct device *dev,
if (ret)
return ret;
- ret = regmap_field_write(data->rm_field[F_SHIP_MODE], !!tmp);
- if (ret)
+ ret = rt9467_set_batfet(data, tmp ? POWER_SUPPLY_LOAD_SWITCH_OFF :
+ POWER_SUPPLY_LOAD_SWITCH_ON);
+ if (ret < 0)
return ret;
return count;
--
2.43.0