All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hermann.Lauer@uni-heidelberg.de
To: sre@kernel.org, wens@csie.org
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH] axp209 PMIC: setting constant_charge_current to 0 disables battery charging
Date: Wed, 21 Apr 2021 11:03:54 +0200	[thread overview]
Message-ID: <20210421090354.GF19953@lemon.iwr.uni-heidelberg.de> (raw)

Dear Maintainers,

this proposed patch allows setting constant_charge_current to 0 on axp209
PMIC to disable charging. constant_charge_current_max with a value of 0 makes
no sense and should still report the maximum allowed value, so the getter code
is unrolled for the POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT case.

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

Thanks for comments and greetings
  Hermann

Signed-off-by: Hermann.Lauer@uni-heidelberg.de
---
 patches/axp209-charge-current0.patchl | 18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 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)
@@ -249,11 +250,18 @@
 		break;
 
 	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
-		ret = axp20x_get_constant_charge_current(axp20x_batt,
-							 &val->intval);
+		ret = regmap_read(axp20x_batt->regmap, AXP20X_CHRG_CTRL1, &val->intval);
 		if (ret)
 			return ret;
-		break;
+
+		if (val->intval & AXP20X_CHRG_CTRL1_ENABLE) {
+			val->intval &= AXP20X_CHRG_CTRL1_TGT_CURR;
+			val->intval = val->intval * axp20x_batt->data->ccc_scale +
+					axp20x_batt->data->ccc_offset;
+		} else
+			val->intval = 0;
+
+		return 0;
 
 	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
 		val->intval = axp20x_batt->max_ccc;
@@ -392,6 +400,10 @@
 static int axp20x_set_constant_charge_current(struct axp20x_batt_ps *axp_batt,
 					      int charge_current)
 {
+	if (charge_current == 0)
+		return regmap_update_bits(axp_batt->regmap, AXP20X_CHRG_CTRL1,
+				  AXP20X_CHRG_CTRL1_ENABLE, 0);
+
 	if (charge_current > axp_batt->max_ccc)
 		return -EINVAL;
 
@@ -402,7 +414,8 @@
 		return -EINVAL;
 
 	return regmap_update_bits(axp_batt->regmap, AXP20X_CHRG_CTRL1,
-				  AXP20X_CHRG_CTRL1_TGT_CURR, charge_current);
+				  AXP20X_CHRG_CTRL1_TGT_CURR | AXP20X_CHRG_CTRL1_ENABLE,
+				  charge_current | AXP20X_CHRG_CTRL1_ENABLE);
 }
 
 static int axp20x_set_max_constant_charge_current(struct axp20x_batt_ps *axp,

             reply	other threads:[~2021-04-21  9:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-21  9:03 Hermann.Lauer [this message]
2021-04-26  8:40 ` [RFC PATCH] axp209 PMIC: setting constant_charge_current to 0 disables battery charging Chen-Yu Tsai
2021-05-05 11:29   ` [PATCH] power: supply: axp20x_battery: implement writeable status to enable/disable " Hermann.Lauer
2021-05-09 15:05     ` Chen-Yu Tsai
2021-05-10 13:18       ` [PATCH v2] " Hermann Lauer
2021-05-12 10:58         ` [PATCH v3] " Hermann Lauer
2021-06-04 12:20           ` Sebastian Reichel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210421090354.GF19953@lemon.iwr.uni-heidelberg.de \
    --to=hermann.lauer@uni-heidelberg.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.