From 0b8cbcea7a2d7489f2185fa6bedc2ad5b25272d8 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Wed, 28 Oct 2026 22:39:14 -0400 Subject: [PATCH 1/5] power: supply: max17042_battery: use dSOCi for MAX77759 SOC alerts The MAX77759 fuel gauge has the same Config2.dSOCen / Status.dSOCi 1 % change alert as the MAX17055, and the battery model loaded on POR enables it (Config2 0x0090 on the Pixel 7 Pro). The driver still treated the MAX77759 like the older gauges and also armed a SALRT window of +/-1 % around the current SOC, re-armed from the integer part of RepSOC on every alert. Both alerts then watch the same whole-percent boundary. On a Pixel 7 Pro (gs201) the gauge interrupt fires in bursts of 300 to 460 interrupts within about a second, each time RepSOC crosses a whole percent, while charging and while discharging; one boot counted 43960 gauge interrupts before the battery ran flat. SALRT read the window around the new percent (0x1412 at 19.00 %) at every burst. Use the MAX17055 scheme on the MAX77759: dSOCi for the 1 % steps and SALRT only for the critical SOC threshold. Google's driver for this gauge does the same; it enables dSOCen through the model's Config2 and never programs SALRT. It also drops the 1 % window during suspend, so a suspended phone is no longer woken on every percent, which is what the MAX17055 path already does. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/power/supply/max17042_battery.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index 3f251034cd..ef78fc0bf9 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -1193,9 +1193,19 @@ static void max17042_set_critical_soc_threshold(struct max17042_chip *chip) 0xff00 + MAX17042_CRITICAL_SOC : 0xff00); } +/* + * The MAX17055 and the MAX77759 raise Status.dSOCi on every whole-percent + * change of the SOC, so they don't need a SALRT window around the current SOC. + */ +static bool max17042_has_dsoci(struct max17042_chip *chip) +{ + return chip->chip_type == MAXIM_DEVICE_TYPE_MAX17055 || + chip->chip_type == MAXIM_DEVICE_TYPE_MAX77759; +} + static void max17042_enable_soc_alerts(struct max17042_chip *chip) { - if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17055) { + if (max17042_has_dsoci(chip)) { regmap_update_bits(chip->regmap, MAX17055_Config2, CFG2_DSOCI_BIT_ENBL, CFG2_DSOCI_BIT_ENBL); @@ -1208,7 +1218,7 @@ static void max17042_enable_soc_alerts(struct max17042_chip *chip) static void max17042_suspend_soc_alerts(struct max17042_chip *chip) { - if (chip->chip_type != MAXIM_DEVICE_TYPE_MAX17055) + if (!max17042_has_dsoci(chip)) return; regmap_update_bits(chip->regmap, MAX17055_Config2, From 7fb7e6e53ee45dfd831cad6a167b82aba836b6ca Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Wed, 28 Oct 2026 22:39:50 -0400 Subject: [PATCH 2/5] power: supply: max17042_battery: wait for the MAX77759 to release ALRT The MAX77759 fuel gauge doesn't release its ALRT output when the host clears Status; it does so at a later fuel-gauge update, up to one task period afterwards. Google's driver for this gauge says so ("gauge will take up to 351 ms to clear ALRM1") and sleeps 500 ms at the end of its threaded handler for that reason. This driver requests the interrupt oneshot and the line is level-low, so the interrupt is unmasked as soon as the handler returns and taken again while ALRT is still asserted. On a Pixel 7 Pro (gs201, TaskPeriod 0x2d00, 351.6 ms) every whole-percent change produced a burst of 300 to 460 interrupts within about a second, and Status read 0x0000 around the bursts. Each pass reads Status over I2C and sends a power_supply uevent, which also wakes userspace hundreds of times per percent. Keep the interrupt masked for one and a half task periods after a pass on the MAX77759. The period is read from the gauge, so a battery model that changes TaskPeriod changes the wait too. An alert that is still pending afterwards keeps the line low and is taken on the next pass, so none is lost. Other gauges are unchanged. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/power/supply/max17042_battery.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index ef78fc0bf9..e6eff5f1a3 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -1226,6 +1226,24 @@ static void max17042_suspend_soc_alerts(struct max17042_chip *chip) max17042_set_critical_soc_threshold(chip); } +/* + * The MAX77759 releases ALRT only at a fuel-gauge update after Status was + * cleared, up to one task period later. The interrupt is level-triggered and + * oneshot, so it would be taken again every few milliseconds until then, each + * time with Status already clear. Keep it masked until the gauge has updated. + */ +static void max17042_alert_holdoff(struct max17042_chip *chip) +{ + unsigned int period_ms; + + if (chip->chip_type != MAXIM_DEVICE_TYPE_MAX77759) + return; + + /* TaskPeriod counts 1/32768 s; allow half a period of margin */ + period_ms = DIV_ROUND_UP(READ_ONCE(chip->task_period) * 1000, 32768); + msleep(period_ms + period_ms / 2); +} + static irqreturn_t max17042_thread_handler(int id, void *dev) { struct max17042_chip *chip = dev; @@ -1247,6 +1265,7 @@ static irqreturn_t max17042_thread_handler(int id, void *dev) 0xFFFF & ~(STATUS_POR_BIT | STATUS_BST_BIT)); power_supply_changed(chip->battery); + max17042_alert_holdoff(chip); return IRQ_HANDLED; } From 9b6d8ed3a0edb6654a2f47410a27a5a53c530210 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Wed, 28 Oct 2026 22:40:01 -0400 Subject: [PATCH 3/5] power: supply: max17042_battery: ignore interrupts with no status bit set The threaded handler reports a power supply change on every interrupt, even when Status has no bit set. The interrupt is requested shared, so such an interrupt may belong to another device; on a gauge that is slow to release ALRT it is the same alert taken again. On a Pixel 7 Pro (MAX77759) the second case sent hundreds of power_supply uevents per whole-percent change, each read again by userspace. Return IRQ_NONE without a uevent when Status reads zero, so a shared line is reported correctly and a line that stays asserted with nothing latched is caught by the spurious interrupt detector instead of turning into a stream of uevents. On the MAX77759 the alert hold-off applies on this path too. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/power/supply/max17042_battery.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index e6eff5f1a3..2c7186c686 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -1254,6 +1254,12 @@ static irqreturn_t max17042_thread_handler(int id, void *dev) if (ret) return IRQ_HANDLED; + /* Nothing latched: not our interrupt, or ALRT not released yet */ + if (!val) { + max17042_alert_holdoff(chip); + return IRQ_NONE; + } + if ((val & STATUS_SMN_BIT) || (val & STATUS_SMX_BIT) || (val & STATUS_DSOCI_BIT)) { dev_dbg(chip->dev, "SOC threshold INTR\n"); From 006e9ff656fa3bfafa22b5ea59ba15cec3dd9a7f Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Thu, 29 Oct 2026 14:08:43 -0400 Subject: [PATCH 4/5] power: supply: max77759: disable the fast-charge safety timer The driver leaves CHG_CNFG_01's FCHGTIME at the value it finds, so the charger's fast-charge safety timer stays armed. With the input limited to 500 mA a charge from empty takes longer than that timer: on a Pixel 7 Pro charging from 0 % on a laptop port, the charger stopped after about 12 hours at 92 %, reading offline and "Not charging" with the cable in and USB still working, until a reboot started it again. Google's max77759_charger.c clears FCHGTIME at probe ("disable fast charge safety timer"), leaving charge termination to the charger's own done detection and the battery's temperature limits. Do the same in init, inside the window where the protected registers are unlocked. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/power/supply/max77759_charger.c | 10 ++++++++++ include/linux/mfd/max77759.h | 1 + 2 files changed, 11 insertions(+) diff --git a/drivers/power/supply/max77759_charger.c b/drivers/power/supply/max77759_charger.c index 572279b060..7764ac15d2 100644 --- a/drivers/power/supply/max77759_charger.c +++ b/drivers/power/supply/max77759_charger.c @@ -654,6 +654,16 @@ static int max77759_charger_init(struct max77759_charger *chg) if (ret) goto relock; + /* + * Disable the fast-charge safety timer. At a low input limit a full + * charge outlasts it, and the charger then stops in a timer fault + * with the cable still in, until it is replugged or reset. + */ + ret = regmap_update_bits(chg->regmap, MAX77759_CHGR_REG_CHG_CNFG_01, + MAX77759_CHGR_REG_CHG_CNFG_01_FCHGTIME, 0); + if (ret) + goto relock; + return unlock_prot_regs(chg, false); relock: diff --git a/include/linux/mfd/max77759.h b/include/linux/mfd/max77759.h index 10f400e97c..4c04a600a6 100644 --- a/include/linux/mfd/max77759.h +++ b/include/linux/mfd/max77759.h @@ -91,6 +91,7 @@ #define MAX77759_CHGR_REG_CHG_CNFG_00 0xb9 #define MAX77759_CHGR_REG_CHG_CNFG_00_MODE GENMASK(3, 0) #define MAX77759_CHGR_REG_CHG_CNFG_01 0xba +#define MAX77759_CHGR_REG_CHG_CNFG_01_FCHGTIME GENMASK(2, 0) #define MAX77759_CHGR_REG_CHG_CNFG_02 0xbb #define MAX77759_CHGR_REG_CHG_CNFG_02_CHGCC GENMASK(5, 0) #define MAX77759_CHGR_REG_CHG_CNFG_03 0xbc From 479c3e0e05d894caaa6adfb2f058c2d289e472b7 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Fri, 30 Oct 2026 03:27:23 -0400 Subject: [PATCH 5/5] power: supply: max77759: stay online while a full battery is on the charger charger_input_valid() required both CHGIN_OK and CHG_OK in CHG_INT_OK. CHG_OK clears when the charge is done: on a Pixel 7 Pro on a laptop port, CHG_INT_OK went from 0xdd to 0xcd as CHG_DETAILS_01 reached DONE (0x4), and online and present dropped to 0 with the cable in and the mode still CHG_BUCK_ON. Userspace then counts a full phone on the charger as running on battery (upower applies its battery policy). Report the input from CHGIN_OK alone; the status property already says Full, and charger faults through status and health. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/power/supply/max77759_charger.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/max77759_charger.c b/drivers/power/supply/max77759_charger.c index 7764ac15d2..61e118fd95 100644 --- a/drivers/power/supply/max77759_charger.c +++ b/drivers/power/supply/max77759_charger.c @@ -158,8 +158,12 @@ static int charger_input_valid(struct max77759_charger *chg) if (ret) return ret; - return (val & MAX77759_CHGR_REG_CHG_INT_CHG) && - (val & MAX77759_CHGR_REG_CHG_INT_CHGIN); + /* + * CHGIN alone says whether the input is there. CHG_OK clears when a + * charge is done (and on charger faults), which the status property + * already reports. + */ + return !!(val & MAX77759_CHGR_REG_CHG_INT_CHGIN); } static int get_online(struct max77759_charger *chg)