power: supply: axp20x_battery: implement writeable status to enable/disable battery charging

Message ID 20210505112902.GC5302@lemon.iwr.uni-heidelberg.de
State New
Headers show
Series
  • power: supply: axp20x_battery: implement writeable status to enable/disable battery charging
Related show

Commit Message

Hermann.Lauer@uni-heidelberg.de May 5, 2021, 11:29 a.m.
Dear Maintainers,

this patch allows enabling/disabling charging for the axp209 PMIC through a
writeable status property.

This works on the axp209 of Banana {Pi M1+,Pro}. I have no access to
the other chips the driver deals with.

Thanks to ChenYu for the idea and greetings
  Hermann

Signed-off-by: Hermann.Lauer@uni-heidelberg.de
---
 drivers/power/supply/axp20x_battery.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Comments

Chen-Yu Tsai May 9, 2021, 3:05 p.m. | #1
Hi,

On Wed, May 5, 2021 at 7:29 PM <Hermann.Lauer@uni-heidelberg.de> wrote:
>

> Dear Maintainers,

>

> this patch allows enabling/disabling charging for the axp209 PMIC through a

> writeable status property.


  ^ writable

>

> This works on the axp209 of Banana {Pi M1+,Pro}. I have no access to

> the other chips the driver deals with.


This should work on all the AXP chips, as it's the same bit that
controls the charger on all of them.

> Thanks to ChenYu for the idea and greetings

>   Hermann

>

> Signed-off-by: Hermann.Lauer@uni-heidelberg.de


The patch itself looks good, but your commit message needs a bit of
cleanup. Your commit message should only include details about the
patch, especially why the patch was done, which is kind of missing.
"What" was done is already obvious when looking at the body of the
patch.

Any pleasantries and other comments addressed to maintainers should
be included after the "---" so as not to be included in git history.


Thanks
ChenYu


> ---

>  drivers/power/supply/axp20x_battery.c | 16 ++++++++++++++--

>  1 file changed, 14 insertions(+), 2 deletions(-)

>

> diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c

> --- a/drivers/power/supply/axp20x_battery.c

> +++ b/drivers/power/supply/axp20x_battery.c

> @@ -40,6 +40,7 @@

>  #define AXP209_FG_PERCENT              GENMASK(6, 0)

>  #define AXP22X_FG_VALID                        BIT(7)

>

> +#define AXP20X_CHRG_CTRL1_ENABLE       BIT(7)

>  #define AXP20X_CHRG_CTRL1_TGT_VOLT     GENMASK(6, 5)

>  #define AXP20X_CHRG_CTRL1_TGT_4_1V     (0 << 5)

>  #define AXP20X_CHRG_CTRL1_TGT_4_15V    (1 << 5)

> @@ -468,7 +469,17 @@

>         case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:

>                 return axp20x_set_max_constant_charge_current(axp20x_batt,

>                                                               val->intval);

> +       case POWER_SUPPLY_PROP_STATUS:

> +               switch (val->intval) {

> +               case POWER_SUPPLY_STATUS_CHARGING:

> +                       return regmap_update_bits(axp20x_batt->regmap, AXP20X_CHRG_CTRL1,

> +                               AXP20X_CHRG_CTRL1_ENABLE, AXP20X_CHRG_CTRL1_ENABLE);

>

> +               case POWER_SUPPLY_STATUS_DISCHARGING:

> +               case POWER_SUPPLY_STATUS_NOT_CHARGING:

> +                       return regmap_update_bits(axp20x_batt->regmap, AXP20X_CHRG_CTRL1,

> +                               AXP20X_CHRG_CTRL1_ENABLE, 0);

> +       }

>         default:

>                 return -EINVAL;

>         }

> @@ -491,7 +502,8 @@

>  static int axp20x_battery_prop_writeable(struct power_supply *psy,

>                                          enum power_supply_property psp)

>  {

> -       return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN ||

> +       return psp == POWER_SUPPLY_PROP_STATUS ||

> +              psp == POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN ||

>                psp == POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN ||

>                psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT ||

>                psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX;

Patch

diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
--- a/drivers/power/supply/axp20x_battery.c
+++ b/drivers/power/supply/axp20x_battery.c
@@ -40,6 +40,7 @@ 
 #define AXP209_FG_PERCENT		GENMASK(6, 0)
 #define AXP22X_FG_VALID			BIT(7)
 
+#define AXP20X_CHRG_CTRL1_ENABLE	BIT(7)
 #define AXP20X_CHRG_CTRL1_TGT_VOLT	GENMASK(6, 5)
 #define AXP20X_CHRG_CTRL1_TGT_4_1V	(0 << 5)
 #define AXP20X_CHRG_CTRL1_TGT_4_15V	(1 << 5)
@@ -468,7 +469,17 @@ 
 	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
 		return axp20x_set_max_constant_charge_current(axp20x_batt,
 							      val->intval);
+	case POWER_SUPPLY_PROP_STATUS:
+		switch (val->intval) {
+		case POWER_SUPPLY_STATUS_CHARGING:
+			return regmap_update_bits(axp20x_batt->regmap, AXP20X_CHRG_CTRL1,
+				AXP20X_CHRG_CTRL1_ENABLE, AXP20X_CHRG_CTRL1_ENABLE);
 
+		case POWER_SUPPLY_STATUS_DISCHARGING:
+		case POWER_SUPPLY_STATUS_NOT_CHARGING:
+			return regmap_update_bits(axp20x_batt->regmap, AXP20X_CHRG_CTRL1,
+				AXP20X_CHRG_CTRL1_ENABLE, 0);
+	}
 	default:
 		return -EINVAL;
 	}
@@ -491,7 +502,8 @@ 
 static int axp20x_battery_prop_writeable(struct power_supply *psy,
 					 enum power_supply_property psp)
 {
-	return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN ||
+	return psp == POWER_SUPPLY_PROP_STATUS ||
+	       psp == POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN ||
 	       psp == POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN ||
 	       psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT ||
 	       psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX;