Linux Power Management development
 help / color / mirror / Atom feed
From: Linus Walleij <linusw@kernel.org>
To: Sebastian Reichel <sre@kernel.org>
Cc: linux-pm@vger.kernel.org, Linus Walleij <linusw@kernel.org>
Subject: [PATCH 13/15] power: supply: ab8500_charger: Recover inactive AB8505 charger
Date: Wed, 16 Sep 2026 08:49:35 +0200	[thread overview]
Message-ID: <20260916-ab8500-charging-v1-13-e986ed321cc6@kernel.org> (raw)
In-Reply-To: <20260916-ab8500-charging-v1-0-e986ed321cc6@kernel.org>

UsbChCtrl1.UsbChEna can remain set while UsbChStatus1.UsbChOn is
clear. The existing recovery only checks the control bit, so it considers
the charger enabled and leaves charging stopped.

The Samsung-GT-S7710-Skomer, Samsung-SGH-I407-Kyle, and
Samsung-SGH-T599-Codina-TMO product trees are reference points for
checking both bits and cycling the charger when they disagree.

Extend the USB charger check to detect this AB8505 state and enable the
check in the charging algorithm for AB8505. Only cycle the charger when
VBUS is debounced and no charger-not-OK, thermal, overvoltage, or
watchdog fault accounts for the inactive hardware.

Fixes: 4dcdf57773fd ("ab8500-bm: Quick re-attach charging behaviour")
Assisted-by: LLM
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
 drivers/power/supply/ab8500_chargalg.c |  9 ++----
 drivers/power/supply/ab8500_charger.c  | 51 +++++++++++++++++++++++++++++++++-
 2 files changed, 53 insertions(+), 7 deletions(-)

diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c
index d2b9880b0770..71d82c6c193e 100644
--- a/drivers/power/supply/ab8500_chargalg.c
+++ b/drivers/power/supply/ab8500_chargalg.c
@@ -1241,12 +1241,9 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di)
 
 	charger_status = ab8500_chargalg_check_charger_connection(di);
 
-	if (is_ab8500(di->parent)) {
-		ret = ab8500_chargalg_check_charger_enable(di);
-		if (ret < 0)
-			dev_err(di->dev, "Checking charger is enabled error"
-					": Returned Value %d\n", ret);
-	}
+	ret = ab8500_chargalg_check_charger_enable(di);
+	if (ret < 0)
+		dev_err(di->dev, "Checking charger enable failed: %d\n", ret);
 
 	/*
 	 * First check if we have a charger connected.
diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c
index 8430bc247df7..19cc56624ee4 100644
--- a/drivers/power/supply/ab8500_charger.c
+++ b/drivers/power/supply/ab8500_charger.c
@@ -52,6 +52,7 @@
 #define MAIN_CH_DET			0x01
 #define MAIN_CH_CV_ON			0x04
 #define USB_CH_CV_ON			0x08
+#define USB_CH_ON			0x04
 #define VBUS_DET_DBNC_LONG		0x02
 #define VBUS_DET_DBNC1			0x01
 #define OTP_ENABLE_WD			0x01
@@ -1877,6 +1878,9 @@ static int ab8500_charger_usb_check_enable(struct ux500_charger *charger,
 	int vset_uv, int iset_ua)
 {
 	u8 usbch_ctrl1 = 0;
+	u8 usbch_status1;
+	u8 usbch_status2;
+	bool reenable;
 	int ret = 0;
 
 	struct ab8500_charger *di = to_ab8500_charger_usb_device_info(charger);
@@ -1892,7 +1896,52 @@ static int ab8500_charger_usb_check_enable(struct ux500_charger *charger,
 	}
 	dev_dbg(di->dev, "USB charger ctrl: 0x%02x\n", usbch_ctrl1);
 
-	if (!(usbch_ctrl1 & USB_CH_ENA)) {
+	reenable = !(usbch_ctrl1 & USB_CH_ENA);
+	if (is_ab8505(di->parent)) {
+		ret = abx500_get_register_interruptible(di->dev,
+							AB8500_CHARGER,
+							AB8500_CH_USBCH_STAT1_REG,
+							&usbch_status1);
+		if (ret < 0) {
+			dev_err(di->dev, "USB charger status read failed\n");
+			return ret;
+		}
+
+		if (!reenable && (usbch_status1 & USB_CH_ON))
+			return 0;
+
+		if (!(usbch_status1 & VBUS_DET_DBNC_LONG))
+			return 0;
+
+		ret = abx500_get_register_interruptible(di->dev,
+							AB8500_CHARGER,
+							AB8500_CH_USBCH_STAT2_REG,
+							&usbch_status2);
+		if (ret < 0) {
+			dev_err(di->dev, "USB charger fault status read failed\n");
+			return ret;
+		}
+
+		if ((usbch_status2 &
+		     (VBUS_CH_NOK | USB_CH_TH_PROT | VBUS_OVV_TH)) ||
+		    di->flags.usbchargernotok || di->flags.usb_thermal_prot ||
+		    di->flags.vbus_ovv || di->usb.wd_expired)
+			return 0;
+
+		if (!reenable) {
+			dev_info(di->dev,
+				 "USB charger enabled but inactive, cycling it\n");
+			ret = abx500_mask_and_set_register_interruptible(di->dev,
+									 AB8500_CHARGER,
+									 AB8500_USBCH_CTRL1_REG,
+									 USB_CH_ENA, 0);
+			if (ret < 0)
+				return ret;
+			reenable = true;
+		}
+	}
+
+	if (reenable) {
 		dev_info(di->dev, "Charging has been disabled abnormally and will be re-enabled\n");
 
 		ret = abx500_mask_and_set_register_interruptible(di->dev,

-- 
2.55.0


  parent reply	other threads:[~2026-09-16  6:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16  6:49 [PATCH 00/15] power: supply: Fix AB8500 and AB8505 charging Linus Walleij
2026-09-16  6:49 ` [PATCH 01/15] power: supply: ab8500_fg: Accept status from supplied power Linus Walleij
2026-09-16  6:49 ` [PATCH 02/15] power: supply: ab8500_fg: Report sub-percent charge changes Linus Walleij
2026-09-16  6:49 ` [PATCH 03/15] power: supply: ab8500: Correct register definitions Linus Walleij
2026-09-16  6:49 ` [PATCH 04/15] power: supply: ab8500_fg: Drop nonexistent AB8505 controls Linus Walleij
2026-09-16  6:49 ` [PATCH 05/15] power: supply: ab8500_btemp: Fix event temperature reporting Linus Walleij
2026-09-16  6:49 ` [PATCH 06/15] power: supply: ab8500: Preserve battery termination current Linus Walleij
2026-09-16  6:49 ` [PATCH 07/15] power: supply: ab8500_charger: Fix AC charger re-enable Linus Walleij
2026-09-16  6:49 ` [PATCH 08/15] power: supply: ab8500_charger: Decode AB8505 USB status Linus Walleij
2026-09-16  6:49 ` [PATCH 09/15] power: supply: ab8500_charger: Respect AB8505 register layout Linus Walleij
2026-09-16  6:49 ` [PATCH 10/15] power: supply: ab8500_charger: Handle detection errors Linus Walleij
2026-09-16  6:49 ` [PATCH 11/15] power: supply: ab8500_charger: Skip absent AB8505 main charger Linus Walleij
2026-09-16  6:49 ` [PATCH 12/15] power: supply: ab8500_charger: Retry AB8505 USB detection Linus Walleij
2026-09-16  6:49 ` Linus Walleij [this message]
2026-09-16  6:49 ` [PATCH 14/15] power: supply: ab8500_fg: Finalize current measurements Linus Walleij
2026-09-16  6:49 ` [PATCH 15/15] power: supply: ab8500_fg: Avoid reserved AB8505 CCConf bit Linus Walleij
2026-10-02 22:07 ` [PATCH 00/15] power: supply: Fix AB8500 and AB8505 charging Linus Walleij
2026-10-04 19:33 ` 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=20260916-ab8500-charging-v1-13-e986ed321cc6@kernel.org \
    --to=linusw@kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.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