[PATCH 10/10] power: supply: bq24190: Use POWER_SUPPLY_PROP_LOAD_SWITCH
From: Waqar Hameed
Date: Mon Jun 29 2026 - 12:10:19 EST
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@xxxxxxxx>
---
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