Skip to content

Commit 6a0fcc8

Browse files
hlauer0sre
authored andcommitted
power: supply: axp20x_battery: allow disabling battery charging
Allow disabling and re-enabling battery charging of an axp209 PMIC through a writable status property. With the current driver code charging is always on. This works on the axp209 of Banana {Pi M1+,Pro} and should work on all AXP chips. Signed-off-by: [email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent cd70c85 commit 6a0fcc8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

drivers/power/supply/axp20x_battery.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define AXP209_FG_PERCENT GENMASK(6, 0)
4141
#define AXP22X_FG_VALID BIT(7)
4242

43+
#define AXP20X_CHRG_CTRL1_ENABLE BIT(7)
4344
#define AXP20X_CHRG_CTRL1_TGT_VOLT GENMASK(6, 5)
4445
#define AXP20X_CHRG_CTRL1_TGT_4_1V (0 << 5)
4546
#define AXP20X_CHRG_CTRL1_TGT_4_15V (1 << 5)
@@ -468,7 +469,18 @@ static int axp20x_battery_set_prop(struct power_supply *psy,
468469
case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
469470
return axp20x_set_max_constant_charge_current(axp20x_batt,
470471
val->intval);
471-
472+
case POWER_SUPPLY_PROP_STATUS:
473+
switch (val->intval) {
474+
case POWER_SUPPLY_STATUS_CHARGING:
475+
return regmap_update_bits(axp20x_batt->regmap, AXP20X_CHRG_CTRL1,
476+
AXP20X_CHRG_CTRL1_ENABLE, AXP20X_CHRG_CTRL1_ENABLE);
477+
478+
case POWER_SUPPLY_STATUS_DISCHARGING:
479+
case POWER_SUPPLY_STATUS_NOT_CHARGING:
480+
return regmap_update_bits(axp20x_batt->regmap, AXP20X_CHRG_CTRL1,
481+
AXP20X_CHRG_CTRL1_ENABLE, 0);
482+
}
483+
fallthrough;
472484
default:
473485
return -EINVAL;
474486
}
@@ -491,7 +503,8 @@ static enum power_supply_property axp20x_battery_props[] = {
491503
static int axp20x_battery_prop_writeable(struct power_supply *psy,
492504
enum power_supply_property psp)
493505
{
494-
return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN ||
506+
return psp == POWER_SUPPLY_PROP_STATUS ||
507+
psp == POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN ||
495508
psp == POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN ||
496509
psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT ||
497510
psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX;

0 commit comments

Comments
 (0)