Linux Power Management development
 help / color / mirror / Atom feed
From: Aren Moynihan <aren@peacevolution.org>
To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Ondřej Jirman" <megi@xff.cz>,
	"Hans de Goede" <j.w.r.degoede@gmail.com>,
	"Aidan MacDonald" <aidanmacdonald.0x0@gmail.com>,
	"Aren Moynihan" <aren@peacevolution.org>,
	"Chen-Yu Tsai" <wens@csie.org>,
	"Quentin Schulz" <quentin.schulz@bootlin.com>,
	"Sebastian Reichel" <sre@kernel.org>
Subject: [PATCH v2 5/5] power: supply: axp20x_usb_power: set input current limit in probe
Date: Tue, 30 Jan 2024 15:28:01 -0500	[thread overview]
Message-ID: <20240130203714.3020464-6-aren@peacevolution.org> (raw)
In-Reply-To: <20240130203714.3020464-1-aren@peacevolution.org>

axp803 sets the current limit to 3A by default if it doesn't detect a
battery. The datasheet says that register 0x2D bit 6 is used to indicate
first power on status. According to it, if that bit is 0 and the battery
is not detected, it will set the input current limit to 3A, however
setting that bit to 1 doesn't to prevent the pmic from setting the
current limit to 3A.

Waiting for USB BC detection doesn't work either, because (as far as I
can tell) USB BC detection isn't performed when there isn't a battery
detected.

Fixes: c279adafe6ab ("power: supply: axp20x_usb_power: add support for AXP813")

Signed-off-by: Aren Moynihan <aren@peacevolution.org>
---
I'm not sure if the pmic simply ignores the first power on field, or if
it needs to be set in a specific way / at a specific time. I tried
setting it in arm-trusted-firmware, and the pmic still set the input
current limit to 3A.

The datasheet for axp813 says it has the same first power on bit, but I
don't have hardware to test if it behaves the same way. This driver uses
the same platform data for axp803 and axp813.

(no changes since v1)

 drivers/power/supply/axp20x_usb_power.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c
index dae7e5cfc54e..751b9f02d36f 100644
--- a/drivers/power/supply/axp20x_usb_power.c
+++ b/drivers/power/supply/axp20x_usb_power.c
@@ -51,6 +51,7 @@ struct axp_data {
 	unsigned int			num_irq_names;
 	const int			*curr_lim_table;
 	int				curr_lim_table_size;
+	int				force_curr_lim;
 	struct reg_field		curr_lim_fld;
 	struct reg_field		vbus_valid_bit;
 	struct reg_field		vbus_mon_bit;
@@ -545,6 +546,7 @@ static const struct axp_data axp813_data = {
 	.curr_lim_table = axp813_usb_curr_lim_table,
 	.curr_lim_table_size = ARRAY_SIZE(axp813_usb_curr_lim_table),
 	.curr_lim_fld	= REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7),
+	.force_curr_lim = 500000,
 	.usb_bc_en_bit	= REG_FIELD(AXP288_BC_GLOBAL, 0, 0),
 	.usb_bc_det_fld = REG_FIELD(AXP288_BC_DET_STAT, 5, 7),
 	.vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7),
@@ -726,6 +728,17 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
 			return ret;
 	}
 
+	if (power->axp_data->force_curr_lim) {
+		/*
+		 * Some chips set the input current limit to 3A when there is no
+		 * battery connected. Normally the default is 500mA.
+		 */
+		ret = axp20x_usb_power_set_input_current_limit(power,
+				power->axp_data->force_curr_lim);
+		if (ret)
+			return ret;
+	}
+
 	if (power->usb_bc_en_bit) {
 		/* Enable USB Battery Charging specification detection */
 		ret = regmap_field_write(power->usb_bc_en_bit, 1);
-- 
2.43.0


  parent reply	other threads:[~2024-01-30 20:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30 20:27 [PATCH v2 0/5] power: supply: axp20x_usb_power: cleanup input current limit handling Aren Moynihan
2024-01-30 20:27 ` [PATCH v2 1/5] power: supply: axp20x_usb_power: replace current_max with input_current_limit Aren Moynihan
2024-01-30 20:27 ` [PATCH v2 2/5] power: supply: axp20x_usb_power: use correct register for input current limit Aren Moynihan
2024-01-30 20:27 ` [PATCH v2 3/5] power: supply: axp20x_usb_power: fix race condition with usb bc Aren Moynihan
2024-01-30 20:28 ` [PATCH v2 4/5] power: supply: axp20x_usb_power: enable usb_type reporting Aren Moynihan
2024-01-30 20:28 ` Aren Moynihan [this message]
2024-01-30 21:13   ` [PATCH v2 5/5] power: supply: axp20x_usb_power: set input current limit in probe Ondřej Jirman
2024-01-31  4:20     ` Aren
2024-02-10 23:27       ` Ondřej Jirman
2024-03-14 22:39         ` Aren
2024-03-20  0:12           ` Ondřej Jirman
2024-03-23 21:36             ` Aren

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=20240130203714.3020464-6-aren@peacevolution.org \
    --to=aren@peacevolution.org \
    --cc=aidanmacdonald.0x0@gmail.com \
    --cc=j.w.r.degoede@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=megi@xff.cz \
    --cc=quentin.schulz@bootlin.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox