* [PATCH 00/10] Add sysfs entry for system load control
@ 2026-06-29 15:44 Waqar Hameed
2026-06-29 15:44 ` [PATCH 01/10] power: supply: " Waqar Hameed
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Waqar Hameed @ 2026-06-29 15:44 UTC (permalink / raw)
To: Sebastian Reichel, Shuah Khan
Cc: kernel, linux-pm, linux-kernel, linux-kselftest
During discussions of the development of a new driver [1], it was
concluded that a new `sysfs` ABI for controlling the connection from
power to system load is wanted (often called BATFET). This patchset
introduces such one.
There are already several drivers that are controlling this, but with
their own custom `sysfs` entries. The drivers in this patchset were find
with a simple `grep` for `bat\s?fet` (there might be more?), and then
converted to use this new `sysfs` ABI. The old custom ABIs are left
untouched of course, for backward compatibility.
[1] https://lore.kernel.org/lkml/cover.1772201049.git.waqar.hameed@axis.com/
Waqar Hameed (10):
power: supply: Add sysfs entry for system load control
selftests: power_supply: Add tests for load_switch ABI
power: supply: ltc4162-l: Use POWER_SUPPLY_PROP_LOAD_SWITCH
power: supply: rt9471: Remove superfluous unpacking of propval
power: supply: rt9471: Use POWER_SUPPLY_PROP_LOAD_SWITCH
power: supply: rt9467: Use POWER_SUPPLY_PROP_LOAD_SWITCH
power: supply: bq24257: Use POWER_SUPPLY_PROP_LOAD_SWITCH
power: supply: bq24190: Remove unused watchdog struct field
power: supply: bq24190: Disable watchdog with bq24190_write_mask()
power: supply: bq24190: Use POWER_SUPPLY_PROP_LOAD_SWITCH
Documentation/ABI/testing/sysfs-class-power | 24 +++++
.../ABI/testing/sysfs-class-power-ltc4162l | 2 +
.../ABI/testing/sysfs-class-power-rt9467 | 2 +
.../ABI/testing/sysfs-class-power-rt9471 | 2 +
drivers/power/supply/bq24190_charger.c | 74 +++++++++++--
drivers/power/supply/bq24257_charger.c | 41 ++++++-
drivers/power/supply/ltc4162-l-charger.c | 54 ++++++++--
drivers/power/supply/power_supply_sysfs.c | 9 ++
drivers/power/supply/rt9467-charger.c | 52 +++++++--
drivers/power/supply/rt9471.c | 101 +++++++++++++-----
include/linux/power_supply.h | 9 ++
.../test_power_supply_properties.sh | 2 +
12 files changed, 322 insertions(+), 50 deletions(-)
base-commit: ab9de95c9cf952332ab79453b4b5d1bfca8e514f
--
2.43.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 01/10] power: supply: Add sysfs entry for system load control
2026-06-29 15:44 [PATCH 00/10] Add sysfs entry for system load control Waqar Hameed
@ 2026-06-29 15:44 ` Waqar Hameed
2026-06-29 15:44 ` [PATCH 02/10] selftests: power_supply: Add tests for load_switch ABI Waqar Hameed
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Waqar Hameed @ 2026-06-29 15:44 UTC (permalink / raw)
To: Sebastian Reichel; +Cc: kernel, linux-pm, linux-kernel
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".
Signed-off-by: Waqar Hameed <waqar.hameed@axis.com>
---
Documentation/ABI/testing/sysfs-class-power | 24 +++++++++++++++++++++
drivers/power/supply/power_supply_sysfs.c | 9 ++++++++
include/linux/power_supply.h | 9 ++++++++
3 files changed, 42 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/ABI/testing/sysfs-class-power
index 32697b926cc8c..2287b207311cd 100644
--- a/Documentation/ABI/testing/sysfs-class-power
+++ b/Documentation/ABI/testing/sysfs-class-power
@@ -590,6 +590,30 @@ Description:
Valid values: 0 - 100 (percent)
+What: /sys/class/power_supply/<supply_name>/load_switch
+Date: June 2026
+Contact: linux-pm@vger.kernel.org
+Description:
+ Devices can control the connection from power to system load.
+ For example, with a field-effect transistor between a battery
+ and the system load (BATFET). This entry controls such switch.
+ 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". In these modes the switch is usually off and the
+ quiescent current quite low.
+
+ Access: Read, Write
+
+ Valid values:
+
+ ============= ==================================
+ "On" (1) Power is connected to the load.
+ "Off" (2) Power is disconnected to the load.
+ "Standby" (3) Low-power mode.
+ "Ship" (4) Ship mode.
+ ============= ==================================
+
**USB Properties**
What: /sys/class/power_supply/<supply_name>/input_current_limit
diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index f30a7b9ccd5e9..243d6e57704f6 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -148,6 +148,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),
@@ -227,6 +235,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),
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 7a5e4c3242a01..eff5de03fd2ab 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -100,6 +100,14 @@ enum {
POWER_SUPPLY_SCOPE_DEVICE,
};
+enum {
+ POWER_SUPPLY_LOAD_SWITCH_UNKNOWN = 0,
+ POWER_SUPPLY_LOAD_SWITCH_ON,
+ POWER_SUPPLY_LOAD_SWITCH_OFF,
+ POWER_SUPPLY_LOAD_SWITCH_STANDBY,
+ POWER_SUPPLY_LOAD_SWITCH_SHIP,
+};
+
enum power_supply_property {
/* Properties of type `int' */
POWER_SUPPLY_PROP_STATUS = 0,
@@ -178,6 +186,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_MANUFACTURE_DAY,
POWER_SUPPLY_PROP_INTERNAL_RESISTANCE,
POWER_SUPPLY_PROP_STATE_OF_HEALTH,
+ POWER_SUPPLY_PROP_LOAD_SWITCH,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 02/10] selftests: power_supply: Add tests for load_switch ABI
2026-06-29 15:44 [PATCH 00/10] Add sysfs entry for system load control Waqar Hameed
2026-06-29 15:44 ` [PATCH 01/10] power: supply: " Waqar Hameed
@ 2026-06-29 15:44 ` Waqar Hameed
2026-06-29 15:44 ` [PATCH 03/10] power: supply: ltc4162-l: Use POWER_SUPPLY_PROP_LOAD_SWITCH Waqar Hameed
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Waqar Hameed @ 2026-06-29 15:44 UTC (permalink / raw)
To: Sebastian Reichel, Shuah Khan
Cc: kernel, linux-pm, linux-kselftest, linux-kernel
Test the different valid values for the property.
Signed-off-by: Waqar Hameed <waqar.hameed@axis.com>
---
.../selftests/power_supply/test_power_supply_properties.sh | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/testing/selftests/power_supply/test_power_supply_properties.sh b/tools/testing/selftests/power_supply/test_power_supply_properties.sh
index a66b1313ed882..d3a546f95ae67 100755
--- a/tools/testing/selftests/power_supply/test_power_supply_properties.sh
+++ b/tools/testing/selftests/power_supply/test_power_supply_properties.sh
@@ -80,6 +80,8 @@ for DEVNAME in $supplies; do
test_sysfs_prop_optional_list scope "Unknown","System","Device"
+ test_sysfs_prop_optional_list load_switch "Unknown","On","Off","Standby","Ship"
+
test_sysfs_prop_optional input_current_limit "uA"
test_sysfs_prop_optional input_voltage_limit "uV"
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 04/10] power: supply: rt9471: Remove superfluous unpacking of propval
2026-06-29 15:44 [PATCH 00/10] Add sysfs entry for system load control Waqar Hameed
` (2 preceding siblings ...)
2026-06-29 15:44 ` [PATCH 03/10] power: supply: ltc4162-l: Use POWER_SUPPLY_PROP_LOAD_SWITCH Waqar Hameed
@ 2026-06-29 15:44 ` Waqar Hameed
2026-06-29 15:44 ` [PATCH 05/10] power: supply: rt9471: Use POWER_SUPPLY_PROP_LOAD_SWITCH Waqar Hameed
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Waqar Hameed @ 2026-06-29 15:44 UTC (permalink / raw)
To: Sebastian Reichel; +Cc: kernel, linux-pm, linux-kernel
Remove extra variable in `set/get_property`-functions that is only
supplied directly to other functions. The value is not used for anything
else.
Moreover, wrap these lines. Otherwise `checkpatch` warns about too long
lines.
Signed-off-by: Waqar Hameed <waqar.hameed@axis.com>
---
drivers/power/supply/rt9471.c | 49 +++++++++++++++++++++--------------
1 file changed, 29 insertions(+), 20 deletions(-)
diff --git a/drivers/power/supply/rt9471.c b/drivers/power/supply/rt9471.c
index e7f843f12c98e..ca3b0b57675d0 100644
--- a/drivers/power/supply/rt9471.c
+++ b/drivers/power/supply/rt9471.c
@@ -370,23 +370,28 @@ static int rt9471_charger_set_property(struct power_supply *psy,
const union power_supply_propval *val)
{
struct rt9471_chip *chip = power_supply_get_drvdata(psy);
- int value = val->intval;
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
- return regmap_field_write(chip->rm_fields[F_CHG_EN], !!value);
+ return regmap_field_write(chip->rm_fields[F_CHG_EN],
+ !!val->intval);
case POWER_SUPPLY_PROP_ONLINE:
- return regmap_field_write(chip->rm_fields[F_HZ], !value);
+ return regmap_field_write(chip->rm_fields[F_HZ], !val->intval);
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
- return rt9471_set_value_by_field_range(chip, F_ICHG_REG, RT9471_RANGE_ICHG, value);
+ return rt9471_set_value_by_field_range(
+ chip, F_ICHG_REG, RT9471_RANGE_ICHG, val->intval);
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
- return rt9471_set_value_by_field_range(chip, F_VBAT_REG, RT9471_RANGE_VCHG, value);
+ return rt9471_set_value_by_field_range(
+ chip, F_VBAT_REG, RT9471_RANGE_VCHG, val->intval);
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
- return rt9471_set_value_by_field_range(chip, F_AICR, RT9471_RANGE_AICR, value);
+ return rt9471_set_value_by_field_range(
+ chip, F_AICR, RT9471_RANGE_AICR, val->intval);
case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
- return rt9471_set_value_by_field_range(chip, F_MIVR, RT9471_RANGE_MIVR, value);
+ return rt9471_set_value_by_field_range(
+ chip, F_MIVR, RT9471_RANGE_MIVR, val->intval);
case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
- return rt9471_set_value_by_field_range(chip, F_IPRE_CHG, RT9471_RANGE_IPRE, value);
+ return rt9471_set_value_by_field_range(
+ chip, F_IPRE_CHG, RT9471_RANGE_IPRE, val->intval);
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
return rt9471_set_ieoc(chip, val->intval);
default:
@@ -402,35 +407,39 @@ static int rt9471_charger_get_property(struct power_supply *psy,
union power_supply_propval *val)
{
struct rt9471_chip *chip = power_supply_get_drvdata(psy);
- int *pvalue = &val->intval;
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
- return rt9471_get_status(chip, pvalue);
+ return rt9471_get_status(chip, &val->intval);
case POWER_SUPPLY_PROP_ONLINE:
- return rt9471_get_vbus_good(chip, pvalue);
+ return rt9471_get_vbus_good(chip, &val->intval);
case POWER_SUPPLY_PROP_CURRENT_MAX:
- return rt9471_get_usb_type_current(chip, pvalue);
+ return rt9471_get_usb_type_current(chip, &val->intval);
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
- return rt9471_get_value_by_field_range(chip, F_ICHG_REG, RT9471_RANGE_ICHG, pvalue);
+ return rt9471_get_value_by_field_range(
+ chip, F_ICHG_REG, RT9471_RANGE_ICHG, &val->intval);
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
- *pvalue = RT9471_ICHG_MAXUA;
+ val->intval = RT9471_ICHG_MAXUA;
return 0;
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
- return rt9471_get_value_by_field_range(chip, F_VBAT_REG, RT9471_RANGE_VCHG, pvalue);
+ return rt9471_get_value_by_field_range(
+ chip, F_VBAT_REG, RT9471_RANGE_VCHG, &val->intval);
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
val->intval = RT9471_VCHG_MAXUV;
return 0;
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
- return rt9471_get_value_by_field_range(chip, F_AICR, RT9471_RANGE_AICR, pvalue);
+ return rt9471_get_value_by_field_range(
+ chip, F_AICR, RT9471_RANGE_AICR, &val->intval);
case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
- return rt9471_get_value_by_field_range(chip, F_MIVR, RT9471_RANGE_MIVR, pvalue);
+ return rt9471_get_value_by_field_range(
+ chip, F_MIVR, RT9471_RANGE_MIVR, &val->intval);
case POWER_SUPPLY_PROP_USB_TYPE:
- return rt9471_get_usb_type(chip, pvalue);
+ return rt9471_get_usb_type(chip, &val->intval);
case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
- return rt9471_get_value_by_field_range(chip, F_IPRE_CHG, RT9471_RANGE_IPRE, pvalue);
+ return rt9471_get_value_by_field_range(
+ chip, F_IPRE_CHG, RT9471_RANGE_IPRE, &val->intval);
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
- return rt9471_get_ieoc(chip, pvalue);
+ return rt9471_get_ieoc(chip, &val->intval);
case POWER_SUPPLY_PROP_MODEL_NAME:
val->strval = rt9471_model;
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 03/10] power: supply: ltc4162-l: Use POWER_SUPPLY_PROP_LOAD_SWITCH
2026-06-29 15:44 [PATCH 00/10] Add sysfs entry for system load control Waqar Hameed
2026-06-29 15:44 ` [PATCH 01/10] power: supply: " Waqar Hameed
2026-06-29 15:44 ` [PATCH 02/10] selftests: power_supply: Add tests for load_switch ABI Waqar Hameed
@ 2026-06-29 15:44 ` Waqar Hameed
2026-06-29 15:44 ` [PATCH 04/10] power: supply: rt9471: Remove superfluous unpacking of propval Waqar Hameed
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Waqar Hameed @ 2026-06-29 15:44 UTC (permalink / raw)
To: Sebastian Reichel; +Cc: kernel, linux-pm, linux-kernel
The framework supports controlling system load with
`POWER_SUPPLY_PROP_LOAD_SWITCH`. Use this to select ship mode, 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@axis.com>
---
.../ABI/testing/sysfs-class-power-ltc4162l | 2 +
drivers/power/supply/ltc4162-l-charger.c | 54 ++++++++++++++++---
2 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-class-power-ltc4162l b/Documentation/ABI/testing/sysfs-class-power-ltc4162l
index ba30db93052bf..ad46ad834af05 100644
--- a/Documentation/ABI/testing/sysfs-class-power-ltc4162l
+++ b/Documentation/ABI/testing/sysfs-class-power-ltc4162l
@@ -77,6 +77,8 @@ Description:
The ship mode, when armed, activates once the input voltage
drops below 1V.
+ Note: use /sys/class/power_supply/ltc4162-l/load_switch instead.
+
Access: Read, Write
Valid values: 0 (disable) or 1 (enable)
diff --git a/drivers/power/supply/ltc4162-l-charger.c b/drivers/power/supply/ltc4162-l-charger.c
index 5c09e0368e6f0..b0ad50901290b 100644
--- a/drivers/power/supply/ltc4162-l-charger.c
+++ b/drivers/power/supply/ltc4162-l-charger.c
@@ -755,6 +755,41 @@ static int ltc4162l_set_term_current(struct ltc4162l_info *info,
BIT(2), BIT(2));
}
+static int ltc4162l_get_ship_mode(struct ltc4162l_info *info,
+ union power_supply_propval *val)
+{
+ unsigned int regval;
+ int ret;
+
+ ret = regmap_read(info->regmap, LTC4162L_ARM_SHIP_MODE, ®val);
+ if (ret < 0)
+ return ret;
+
+ val->intval = regval == LTC4162L_ARM_SHIP_MODE_MAGIC ?
+ POWER_SUPPLY_LOAD_SWITCH_SHIP :
+ POWER_SUPPLY_LOAD_SWITCH_ON;
+
+ return 0;
+}
+
+static int ltc4162l_set_ship_mode(struct ltc4162l_info *info, int value)
+{
+ unsigned int regval;
+
+ switch (value) {
+ case POWER_SUPPLY_LOAD_SWITCH_ON:
+ regval = 0;
+ break;
+ case POWER_SUPPLY_LOAD_SWITCH_SHIP:
+ regval = LTC4162L_ARM_SHIP_MODE_MAGIC;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return regmap_write(info->regmap, LTC4162L_ARM_SHIP_MODE, regval);
+}
+
/* Custom properties */
static const char * const ltc4162l_charge_status_name[] = {
"ilim_reg_active", /* 32 */
@@ -890,15 +925,15 @@ static ssize_t arm_ship_mode_show(struct device *dev,
{
struct power_supply *psy = to_power_supply(dev);
struct ltc4162l_info *info = power_supply_get_drvdata(psy);
- unsigned int regval;
+ union power_supply_propval val;
int ret;
- ret = regmap_read(info->regmap, LTC4162L_ARM_SHIP_MODE, ®val);
- if (ret)
+ ret = ltc4162l_get_ship_mode(info, &val);
+ if (ret < 0)
return ret;
return sysfs_emit(buf, "%u\n",
- regval == LTC4162L_ARM_SHIP_MODE_MAGIC ? 1 : 0);
+ val.intval == POWER_SUPPLY_LOAD_SWITCH_SHIP ? 1 : 0);
}
static ssize_t arm_ship_mode_store(struct device *dev,
@@ -915,8 +950,9 @@ static ssize_t arm_ship_mode_store(struct device *dev,
if (ret < 0)
return ret;
- ret = regmap_write(info->regmap, LTC4162L_ARM_SHIP_MODE,
- value ? LTC4162L_ARM_SHIP_MODE_MAGIC : 0);
+ ret = ltc4162l_set_ship_mode(info,
+ value ? POWER_SUPPLY_LOAD_SWITCH_SHIP :
+ POWER_SUPPLY_LOAD_SWITCH_ON);
if (ret < 0)
return ret;
@@ -981,6 +1017,8 @@ static int ltc4162l_get_property(struct power_supply *psy,
return chip_info->get_die_temp(info, val);
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
return ltc4162l_get_term_current(info, val);
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
+ return ltc4162l_get_ship_mode(info, val);
default:
return -EINVAL;
}
@@ -1003,6 +1041,8 @@ static int ltc4162l_set_property(struct power_supply *psy,
return ltc4162l_set_iin_limit(info, val->intval);
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
return ltc4162l_set_term_current(info, val->intval);
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
+ return ltc4162l_set_ship_mode(info, val->intval);
default:
return -EINVAL;
}
@@ -1016,6 +1056,7 @@ static int ltc4162l_property_is_writeable(struct power_supply *psy,
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
return 1;
default:
return 0;
@@ -1037,6 +1078,7 @@ static enum power_supply_property ltc4162l_properties[] = {
POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_TEMP,
POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
+ POWER_SUPPLY_PROP_LOAD_SWITCH,
};
static const struct power_supply_desc ltc4162l_desc = {
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 05/10] power: supply: rt9471: Use POWER_SUPPLY_PROP_LOAD_SWITCH
2026-06-29 15:44 [PATCH 00/10] Add sysfs entry for system load control Waqar Hameed
` (3 preceding siblings ...)
2026-06-29 15:44 ` [PATCH 04/10] power: supply: rt9471: Remove superfluous unpacking of propval Waqar Hameed
@ 2026-06-29 15:44 ` Waqar Hameed
2026-06-29 15:44 ` [PATCH 06/10] power: supply: rt9467: " Waqar Hameed
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Waqar Hameed @ 2026-06-29 15:44 UTC (permalink / raw)
To: Sebastian Reichel; +Cc: kernel, linux-pm, linux-kernel
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@axis.com>
---
.../ABI/testing/sysfs-class-power-rt9471 | 2 +
drivers/power/supply/rt9471.c | 52 ++++++++++++++++---
2 files changed, 48 insertions(+), 6 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-class-power-rt9471 b/Documentation/ABI/testing/sysfs-class-power-rt9471
index 0a390ee5ac21c..90cf94c1cbf6b 100644
--- a/Documentation/ABI/testing/sysfs-class-power-rt9471
+++ b/Documentation/ABI/testing/sysfs-class-power-rt9471
@@ -11,6 +11,8 @@ Description:
mode. '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/rt9471-*/load_switch instead.
+
Access: Read, Write
Valid values:
- 1: enabled
diff --git a/drivers/power/supply/rt9471.c b/drivers/power/supply/rt9471.c
index ca3b0b57675d0..6275b79d16edc 100644
--- a/drivers/power/supply/rt9471.c
+++ b/drivers/power/supply/rt9471.c
@@ -266,6 +266,39 @@ static int rt9471_get_ieoc(struct rt9471_chip *chip, int *microamp)
return rt9471_get_value_by_field_range(chip, F_IEOC_CHG, RT9471_RANGE_IEOC, microamp);
}
+static int rt9471_set_batfet(struct rt9471_chip *chip, 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(chip->rm_fields[F_BATFET_DIS], regval);
+}
+
+static int rt9471_get_batfet(struct rt9471_chip *chip, int *val)
+{
+ unsigned int regval;
+ int ret;
+
+ ret = regmap_field_read(chip->rm_fields[F_BATFET_DIS], ®val);
+ if (ret < 0)
+ return ret;
+
+ *val = regval ? POWER_SUPPLY_LOAD_SWITCH_OFF :
+ POWER_SUPPLY_LOAD_SWITCH_ON;
+
+ return 0;
+}
+
static int rt9471_get_status(struct rt9471_chip *chip, int *status)
{
unsigned int ic_stat;
@@ -343,6 +376,7 @@ static enum power_supply_property rt9471_charger_properties[] = {
POWER_SUPPLY_PROP_USB_TYPE,
POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
+ POWER_SUPPLY_PROP_LOAD_SWITCH,
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
};
@@ -359,6 +393,7 @@ static int rt9471_charger_property_is_writeable(struct power_supply *psy,
case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
return 1;
default:
return 0;
@@ -394,6 +429,8 @@ static int rt9471_charger_set_property(struct power_supply *psy,
chip, F_IPRE_CHG, RT9471_RANGE_IPRE, val->intval);
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
return rt9471_set_ieoc(chip, val->intval);
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
+ return rt9471_set_batfet(chip, val->intval);
default:
return -EINVAL;
}
@@ -440,6 +477,8 @@ static int rt9471_charger_get_property(struct power_supply *psy,
chip, F_IPRE_CHG, RT9471_RANGE_IPRE, &val->intval);
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
return rt9471_get_ieoc(chip, &val->intval);
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
+ return rt9471_get_batfet(chip, &val->intval);
case POWER_SUPPLY_PROP_MODEL_NAME:
val->strval = rt9471_model;
return 0;
@@ -651,14 +690,14 @@ static ssize_t sysoff_enable_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct rt9471_chip *chip = psy_device_to_chip(dev);
- unsigned int sysoff_enable;
+ unsigned int val;
int ret;
- ret = regmap_field_read(chip->rm_fields[F_BATFET_DIS], &sysoff_enable);
- if (ret)
+ ret = rt9471_get_batfet(chip, &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,
@@ -673,8 +712,9 @@ static ssize_t sysoff_enable_store(struct device *dev,
if (ret)
return ret;
- ret = regmap_field_write(chip->rm_fields[F_BATFET_DIS], !!tmp);
- if (ret)
+ ret = rt9471_set_batfet(chip, tmp ? POWER_SUPPLY_LOAD_SWITCH_OFF :
+ POWER_SUPPLY_LOAD_SWITCH_ON);
+ if (ret < 0)
return ret;
return count;
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 07/10] power: supply: bq24257: Use POWER_SUPPLY_PROP_LOAD_SWITCH
2026-06-29 15:44 [PATCH 00/10] Add sysfs entry for system load control Waqar Hameed
` (5 preceding siblings ...)
2026-06-29 15:44 ` [PATCH 06/10] power: supply: rt9467: " Waqar Hameed
@ 2026-06-29 15:44 ` Waqar Hameed
2026-06-29 15:44 ` [PATCH 09/10] power: supply: bq24190: Disable watchdog with bq24190_write_mask() Waqar Hameed
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Waqar Hameed @ 2026-06-29 15:44 UTC (permalink / raw)
To: Sebastian Reichel; +Cc: kernel, linux-pm, linux-kernel
The framework supports controlling system load with
`POWER_SUPPLY_PROP_LOAD_SWITCH`. Use this to control `SYSOFF`, but keep
old custom `sysfs` ABI for backward compatibility.
Signed-off-by: Waqar Hameed <waqar.hameed@axis.com>
---
drivers/power/supply/bq24257_charger.c | 41 +++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/bq24257_charger.c b/drivers/power/supply/bq24257_charger.c
index 72f1bfea8d541..0ba690e9adb7b 100644
--- a/drivers/power/supply/bq24257_charger.c
+++ b/drivers/power/supply/bq24257_charger.c
@@ -294,6 +294,40 @@ static int bq24257_set_input_current_limit(struct bq24257_device *bq,
BQ24257_IILIMIT_MAP_SIZE));
}
+static int bq24257_get_sys_switch(struct bq24257_device *bq,
+ union power_supply_propval *val)
+{
+ int ret;
+
+ ret = bq24257_field_read(bq, F_SYSOFF);
+ if (ret < 0)
+ return ret;
+
+ val->intval = ret ? POWER_SUPPLY_LOAD_SWITCH_OFF :
+ POWER_SUPPLY_LOAD_SWITCH_ON;
+
+ return 0;
+}
+
+static int bq24257_set_sys_switch(struct bq24257_device *bq,
+ const union power_supply_propval *val)
+{
+ u8 regval;
+
+ switch (val->intval) {
+ case POWER_SUPPLY_LOAD_SWITCH_ON:
+ regval = 0;
+ break;
+ case POWER_SUPPLY_LOAD_SWITCH_OFF:
+ regval = 1;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return bq24257_field_write(bq, F_SYSOFF, regval);
+}
+
static int bq24257_power_supply_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
@@ -380,7 +414,8 @@ static int bq24257_power_supply_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
return bq24257_get_input_current_limit(bq, val);
-
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
+ return bq24257_get_sys_switch(bq, val);
default:
return -EINVAL;
}
@@ -397,6 +432,8 @@ static int bq24257_power_supply_set_property(struct power_supply *psy,
switch (prop) {
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
return bq24257_set_input_current_limit(bq, val);
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
+ return bq24257_set_sys_switch(bq, val);
default:
return -EINVAL;
}
@@ -407,6 +444,7 @@ static int bq24257_power_supply_property_is_writeable(struct power_supply *psy,
{
switch (psp) {
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
return true;
default:
return false;
@@ -739,6 +777,7 @@ static enum power_supply_property bq24257_power_supply_props[] = {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
+ POWER_SUPPLY_PROP_LOAD_SWITCH,
};
static char *bq24257_charger_supplied_to[] = {
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 06/10] power: supply: rt9467: Use POWER_SUPPLY_PROP_LOAD_SWITCH
2026-06-29 15:44 [PATCH 00/10] Add sysfs entry for system load control Waqar Hameed
` (4 preceding siblings ...)
2026-06-29 15:44 ` [PATCH 05/10] power: supply: rt9471: Use POWER_SUPPLY_PROP_LOAD_SWITCH Waqar Hameed
@ 2026-06-29 15:44 ` Waqar Hameed
2026-06-29 15:44 ` [PATCH 07/10] power: supply: bq24257: " Waqar Hameed
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Waqar Hameed @ 2026-06-29 15:44 UTC (permalink / raw)
To: Sebastian Reichel; +Cc: kernel, linux-pm, linux-kernel
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@axis.com>
---
.../ABI/testing/sysfs-class-power-rt9467 | 2 +
drivers/power/supply/rt9467-charger.c | 52 ++++++++++++++++---
2 files changed, 48 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 44c26fb37a775..1ec84ec0b9153 100644
--- a/drivers/power/supply/rt9467-charger.c
+++ b/drivers/power/supply/rt9467-charger.c
@@ -634,6 +634,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,
@@ -649,6 +682,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,
@@ -712,6 +746,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;
}
@@ -748,6 +784,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;
}
@@ -765,6 +803,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;
@@ -794,14 +833,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,
@@ -816,8 +855,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
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 08/10] power: supply: bq24190: Remove unused watchdog struct field
2026-06-29 15:44 [PATCH 00/10] Add sysfs entry for system load control Waqar Hameed
` (7 preceding siblings ...)
2026-06-29 15:44 ` [PATCH 09/10] power: supply: bq24190: Disable watchdog with bq24190_write_mask() Waqar Hameed
@ 2026-06-29 15:44 ` Waqar Hameed
2026-06-29 15:44 ` [PATCH 10/10] power: supply: bq24190: Use POWER_SUPPLY_PROP_LOAD_SWITCH Waqar Hameed
9 siblings, 0 replies; 11+ messages in thread
From: Waqar Hameed @ 2026-06-29 15:44 UTC (permalink / raw)
To: Sebastian Reichel; +Cc: kernel, linux-pm, linux-kernel
The field member `watchdog` in `struct bq24190_dev_info` is only set
once in `bq24190_set_config()` during probe, and never read again.
Remove this unnecessary field.
Signed-off-by: Waqar Hameed <waqar.hameed@axis.com>
---
drivers/power/supply/bq24190_charger.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
index 6700d578a98f3..6f8000cc700e7 100644
--- a/drivers/power/supply/bq24190_charger.c
+++ b/drivers/power/supply/bq24190_charger.c
@@ -243,7 +243,6 @@ struct bq24190_dev_info {
struct mutex f_reg_lock;
u8 f_reg;
u8 ss_reg;
- u8 watchdog;
const struct bq24190_chip_info *info;
};
@@ -756,9 +755,6 @@ static int bq24190_set_config(struct bq24190_dev_info *bdi)
if (ret < 0)
return ret;
- bdi->watchdog = ((v & BQ24190_REG_CTTC_WATCHDOG_MASK) >>
- BQ24190_REG_CTTC_WATCHDOG_SHIFT);
-
/*
* According to the "Host Mode and default Mode" section of the
* manual, a write to any register causes the bq24190 to switch
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 09/10] power: supply: bq24190: Disable watchdog with bq24190_write_mask()
2026-06-29 15:44 [PATCH 00/10] Add sysfs entry for system load control Waqar Hameed
` (6 preceding siblings ...)
2026-06-29 15:44 ` [PATCH 07/10] power: supply: bq24257: " Waqar Hameed
@ 2026-06-29 15:44 ` Waqar Hameed
2026-06-29 15:44 ` [PATCH 08/10] power: supply: bq24190: Remove unused watchdog struct field Waqar Hameed
2026-06-29 15:44 ` [PATCH 10/10] power: supply: bq24190: Use POWER_SUPPLY_PROP_LOAD_SWITCH Waqar Hameed
9 siblings, 0 replies; 11+ messages in thread
From: Waqar Hameed @ 2026-06-29 15:44 UTC (permalink / raw)
To: Sebastian Reichel; +Cc: kernel, linux-pm, linux-kernel
The watchdog is disabled by updating the register field with a
`bq24190_read()` and `bq24190_write()`. Combine this instead with
`bq24190_write_mask(..., 0)`.
Signed-off-by: Waqar Hameed <waqar.hameed@axis.com>
---
drivers/power/supply/bq24190_charger.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
index 6f8000cc700e7..987ef0e29eb15 100644
--- a/drivers/power/supply/bq24190_charger.c
+++ b/drivers/power/supply/bq24190_charger.c
@@ -751,10 +751,6 @@ static int bq24190_set_config(struct bq24190_dev_info *bdi)
int ret;
u8 v;
- ret = bq24190_read(bdi, BQ24190_REG_CTTC, &v);
- if (ret < 0)
- return ret;
-
/*
* According to the "Host Mode and default Mode" section of the
* manual, a write to any register causes the bq24190 to switch
@@ -763,9 +759,9 @@ static int bq24190_set_config(struct bq24190_dev_info *bdi)
* So, by simply turning off the WDT, we accomplish both with the
* same write.
*/
- v &= ~BQ24190_REG_CTTC_WATCHDOG_MASK;
-
- ret = bq24190_write(bdi, BQ24190_REG_CTTC, v);
+ ret = bq24190_write_mask(bdi, BQ24190_REG_CTTC,
+ BQ24190_REG_CTTC_WATCHDOG_MASK,
+ BQ24190_REG_CTTC_WATCHDOG_SHIFT, 0);
if (ret < 0)
return ret;
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 10/10] power: supply: bq24190: Use POWER_SUPPLY_PROP_LOAD_SWITCH
2026-06-29 15:44 [PATCH 00/10] Add sysfs entry for system load control Waqar Hameed
` (8 preceding siblings ...)
2026-06-29 15:44 ` [PATCH 08/10] power: supply: bq24190: Remove unused watchdog struct field Waqar Hameed
@ 2026-06-29 15:44 ` Waqar Hameed
9 siblings, 0 replies; 11+ messages in thread
From: Waqar Hameed @ 2026-06-29 15:44 UTC (permalink / raw)
To: Sebastian Reichel; +Cc: kernel, linux-pm, linux-kernel
The `online`-property has historically been (ab)used for controlling the
BATFET in this driver. The framework supports controlling system load
with `POWER_SUPPLY_PROP_LOAD_SWITCH`. Use this to control the BATFET,
but keep the support for `online` in order to have ABI backward
compatibility.
Moreover, don't bother with converting the `online`-functions to use the
new `charger_get/set_batfet_ctrl()` to keep the code more readable. It's
already quite messy, e.g. `charge_set_online()` calls
`battery_set_online()`.
Signed-off-by: Waqar Hameed <waqar.hameed@axis.com>
---
drivers/power/supply/bq24190_charger.c | 60 ++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
index 987ef0e29eb15..1e77816c49a3b 100644
--- a/drivers/power/supply/bq24190_charger.c
+++ b/drivers/power/supply/bq24190_charger.c
@@ -1295,6 +1295,58 @@ static int bq24190_charger_set_iinlimit(struct bq24190_dev_info *bdi,
ARRAY_SIZE(bq24190_isc_iinlim_values), val->intval);
}
+static int bq24190_charger_get_batfet_ctrl(struct bq24190_dev_info *bdi,
+ union power_supply_propval *val)
+{
+ u8 regval;
+ int ret;
+
+ ret = bq24190_read_mask(bdi, BQ24190_REG_MOC,
+ BQ24190_REG_MOC_BATFET_DISABLE_MASK,
+ BQ24190_REG_MOC_BATFET_DISABLE_SHIFT,
+ ®val);
+ if (ret < 0)
+ return ret;
+
+ /*
+ * Datasheet defines shipping mode as BATFET off _and_ the watchdog
+ * disabled. Since the watchdog is disabled during the whole lifetime
+ * (from probe), shipping mode is the only "off" state that can be
+ * achievable.
+ */
+ val->intval = regval ? POWER_SUPPLY_LOAD_SWITCH_SHIP :
+ POWER_SUPPLY_LOAD_SWITCH_ON;
+ return 0;
+}
+
+static int
+bq24190_charger_set_batfet_ctrl(struct bq24190_dev_info *bdi,
+ const union power_supply_propval *val)
+{
+ u8 regval;
+
+ /*
+ * Datasheet defines shipping mode as BATFET off _and_ the watchdog
+ * disabled. Since the watchdog is disabled during the whole lifetime
+ * (from probe), shipping mode is the only "off" state that can be
+ * achievable.
+ */
+ switch (val->intval) {
+ case POWER_SUPPLY_LOAD_SWITCH_ON:
+ regval = 0;
+ break;
+ case POWER_SUPPLY_LOAD_SWITCH_SHIP:
+ regval = 1;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return bq24190_write_mask(bdi, BQ24190_REG_MOC,
+ BQ24190_REG_MOC_BATFET_DISABLE_MASK,
+ BQ24190_REG_MOC_BATFET_DISABLE_SHIFT, regval);
+}
+
static int bq24190_charger_get_property(struct power_supply *psy,
enum power_supply_property psp, union power_supply_propval *val)
{
@@ -1351,6 +1403,9 @@ static int bq24190_charger_get_property(struct power_supply *psy,
val->intval = POWER_SUPPLY_SCOPE_SYSTEM;
ret = 0;
break;
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
+ ret = bq24190_charger_get_batfet_ctrl(bdi, val);
+ break;
case POWER_SUPPLY_PROP_MODEL_NAME:
val->strval = bdi->model_name;
ret = 0;
@@ -1401,6 +1456,9 @@ static int bq24190_charger_set_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
ret = bq24190_charger_set_iinlimit(bdi, val);
break;
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
+ ret = bq24190_charger_set_batfet_ctrl(bdi, val);
+ break;
default:
ret = -EINVAL;
}
@@ -1421,6 +1479,7 @@ static int bq24190_charger_property_is_writeable(struct power_supply *psy,
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
+ case POWER_SUPPLY_PROP_LOAD_SWITCH:
return 1;
default:
return 0;
@@ -1481,6 +1540,7 @@ static enum power_supply_property bq24190_charger_properties[] = {
POWER_SUPPLY_PROP_SCOPE,
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
+ POWER_SUPPLY_PROP_LOAD_SWITCH,
};
static char *bq24190_charger_supplied_to[] = {
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-06-29 15:45 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-29 15:44 [PATCH 00/10] Add sysfs entry for system load control Waqar Hameed
2026-06-29 15:44 ` [PATCH 01/10] power: supply: " Waqar Hameed
2026-06-29 15:44 ` [PATCH 02/10] selftests: power_supply: Add tests for load_switch ABI Waqar Hameed
2026-06-29 15:44 ` [PATCH 03/10] power: supply: ltc4162-l: Use POWER_SUPPLY_PROP_LOAD_SWITCH Waqar Hameed
2026-06-29 15:44 ` [PATCH 04/10] power: supply: rt9471: Remove superfluous unpacking of propval Waqar Hameed
2026-06-29 15:44 ` [PATCH 05/10] power: supply: rt9471: Use POWER_SUPPLY_PROP_LOAD_SWITCH Waqar Hameed
2026-06-29 15:44 ` [PATCH 06/10] power: supply: rt9467: " Waqar Hameed
2026-06-29 15:44 ` [PATCH 07/10] power: supply: bq24257: " Waqar Hameed
2026-06-29 15:44 ` [PATCH 09/10] power: supply: bq24190: Disable watchdog with bq24190_write_mask() Waqar Hameed
2026-06-29 15:44 ` [PATCH 08/10] power: supply: bq24190: Remove unused watchdog struct field Waqar Hameed
2026-06-29 15:44 ` [PATCH 10/10] power: supply: bq24190: Use POWER_SUPPLY_PROP_LOAD_SWITCH Waqar Hameed
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox