Skip to content

max77759: husky DONE check, and the float raised only while the guard runs - #267

Open
Somnius wants to merge 9 commits into
derekross:omamobilefrom
Somnius:husky-charger-float-1116
Open

Somnius wants to merge 9 commits into
derekross:omamobilefrom
Somnius:husky-charger-float-1116

Conversation

@Somnius

@Somnius Somnius commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

@derekross third and last for the 92 % stop on my Pixel 8 Pro, stacked on #277 (the defender and float restore split out of #266), which sits on #266, so only the last two commits are new here. Reworked on 11-18 after your review: the device tree no longer carries 4.45 V.

  • charger, DONE: in the last tier a DONE counts as full only at vbatt >= float - 50 mV, the same rule stock's driver uses; otherwise the charger goes off and on again, at most once per 10 minutes and 5 times per plug-in, then it warns once. The last tier is the first one that reaches the float in force, so at the battery node's 4.20 V a DONE at 4.20 V is full. In a band that reaches the last tier, a DONE below it is never full; in a band capped lower, DONE is that band's limit. Only a restart that ran is counted, a plug-in gets its restarts back when the guard reads CHGIN clear (husky's Type-C node is off, so nothing else tells it), and while the check runs status reads Full only for a DONE it accepted. Husky only, only with temp_guard on, never while charging is held off.
  • charger, float: the husky battery node stays at 4.20 V. The husky guard table has its own float cap and raises the float only while the guard runs; it goes back to the node's 4.20 V when the guard is turned off (within one guard period, up to 30 s), to the bootloader's (at most 4.35 V) on unbind and shutdown, and to 4.20 V before s2idle, since the guard can't run asleep. If that can't be written and charging can't be held off either, suspend is refused. The cap is 4.45 V as I proposed; Google's files have 4.48 V and the cycle schedule down to 4.38 V, so the value is yours to pick once you have the cycle counts (mine is 143 now).

Tested: 54 KUnit cases under UML pass (50 at the first commit), the charger builds with W=1 and no warnings through tools/kernel-pr-check --build from today's main, checkpatch --strict is clean on both, no device tree is touched. The cases drive the guard run itself, the suspend and resume hooks, the restart counting and a failed mode write.

Not tested: nothing of this head ran on the phone. The runs from my first version (90 % to 100 % in about 38 minutes, a DONE at 4.43 V accepted) were at the old 4.45 V DTS, so they don't count for this head. Still owed: one attended restart on hardware, which can be done at 4.20 V, and an attended s2idle on the cable (does DONE still show right after resume, and does CHGIN stay set during a restart). The gauge temperature write waits for @gitColinX's register read, and the husky package side (charger options and sleep on the cable, inert) is derekross/omarchy-mobile#899.

@derekross

Copy link
Copy Markdown
Owner

Thank you, @Somnius, for putting the float last in the series and for saying in the description exactly what the device-tree change does when the guard is off. I checked the DONE rule against Google's driver (max77759_set_chg_term_voltage() and max77759_is_full() in kernel/google-modules/bms): the 50 mV margin and the 200 mV on top once done are as you have them. Both commits build here at W=1 with and without the tests, and CI's dtbs_check is clean on the husky tree.

I can't raise the float yet, though. In order of weight:

  1. The temperature the guard reads. On omarchy-mobile#761, gitColinX's 8 Pro on the published kernel read temp at 22.0 C in every sample, at up to 1.87 A, and you answered that any guard watching it is blind there, yours included. I agree, and it decides this PR: on that phone the guard would sit in the 20-42 C band for ever and hold 4.45 V whatever the pack is doing. The published zuma-husky.dts still says the gauge has no battery model; your phone has Google's ATL model through your own overlay. Please find out which it is (the model, or the gauge's thermistor setting), send the fix for the published tree as its own PR, and show temp following a charge on a kernel without your local patches. The float waits for that.

  2. Where 4.45 V comes from. The other boards' battery nodes take their float from the board's own data and say so. Husky's data, in Google's tree (kernel/devices/google/shusky, branch android-gs-shusky-6.1-android16), says:

    • google,fv-max-uv = <4480000> in dts/zuma-shusky-charging.dtsi, the top of google,chg-cv-limits;
    • and in dts/zuma-husky-battery.dtsi, for both pack makers, google,aafv-ref-cycles = <200 400 600 800 1000 1001> with google,aafv-ref-offset = <0 20 40 60 80 100>: the float comes down 20 mV per 200 cycles, to 4.38 V from 1000 cycles (gbms_aafv_get_offset() in google_bms.c). The kernel starts with that opted out and Android switches it on, so I can't tell from the source whether your phone had it.

    So 4.45 V is in neither list: under the maximum for a new pack, over the schedule for a pack past 400 cycles. I'll decide between the board's 4.48 V with the cycle schedule applied, a fixed 4.38 V that is right at any age, or your 4.45 V stated as a choice. For that I need your gauge's cycle_count. Whichever it is, the DTS comment and the message should name Google's files.

  3. The default. As you say, with temp_guard off this change alone is 4.45 V with no steps, no DONE check and no cutoff under 0 C or over 55 C. Of your two options I lean to the second, the float left low in the device tree and raised only by the guard with the husky table: then a driver loaded by hand, or a phone with a stale options file, never sees the higher float. I'll confirm that with the float decision. Either way the husky package's options line and its handling of sleep on the cable come first, while the driver is still blacklisted, the way omarchy-mobile#827 does it for the Pixel 7.

  4. The DONE check.

    • It only acts once the battery has reached the last tier, 4.35 V. Below that done_step() returns DONE_NONE, also in a band that can reach the last tier. Stock doesn't accept a DONE there (max77759_is_full() returns false outside the last voltage index), and Google's comment at the top-off interrupt names the case: a small adapter entering top-off far from the last tier because of the system load. That's your 500 mA port with the screen on, and your first stop was a DONE at 4.296 V.
    • The five restarts never come back. chg->done is reset only when unplugged is set, and that happens only in psy_work_item(), on a tcpm-source event. Husky's Type-C node is disabled, so on your phone it is five per boot. The defender already falls back to charger_input_valid(); this should too.
    • The restart itself (mode off, then on, with the cable in) has only run in KUnit. Please run it once attended; a weak port and the screen on should bring an early DONE.
    • A DONE the check has refused still reads Full in status.
    • The three new functions landed between stop_work() and the comment that describes it.
  5. The runs. They were on the stack plus a local commit and your own kernel, from 90 % up, at 37-39 C, on one phone. One figure I can't reconcile: 93 % at 19:00 to 100 % at 19:18 is 7 % of 4950 mAh, about 346 mAh in 18 minutes, or 1.15 A on average, against the 300 to 470 mA you measured into the battery. Could you post the log for that stretch (capacity, voltage_now, current_now, charge_full)?

What I'd need to merge it, once 1 to 4 are settled, attended, on this branch's head on the published base:

  • a charge from 20 % or below to full on a source that gives 1.5 A or more, logged every 30 s (temp, voltage_now, current_now, the float register, the guard's band lines);
  • the same on a 500 mA port with the screen on, to show the restart, its count, and the count starting again after a replug;
  • a reboot and a shutdown at the raised float, with 0xbd read on the next boot before the driver loads;
  • one run on a second unit once its gauge reads a real temperature.

And as on #266: please, no more runs at a raised float until we've been through the dead-man limits on omarchy-mobile#761. This merges after #265 and #266.

The temperature guard takes its voltage tiers and its charge currents
from three constant arrays, the step-charging table of the gs201 phones.
The Pixel 8 Pro (husky) has another battery and another table: four
tiers, 4.20/4.30/4.35/4.48 V, instead of three.

Put the tiers and the currents in a struct guard_table, with the number
of tiers in use, and let the driver pick the table at probe. The default
table holds the numbers the arrays held, so nothing changes for the
Pixel 7 Pro, the Pixel 6 Pro and every other board. A machine compatible
with "google,zuma-husky" gets the husky table: the chg-cv-limits and
chg-cc-limits of the google,battery node in Google's tree
(kernel/devices/google/shusky, branch android-gs-shusky-6.1-android16):
dts/zuma-shusky-battery.dtsi for the temperature and voltage limits,
dts/zuma-husky-battery.dtsi for the 4950 mAh and the six rows, in
percent of that design capacity. The temperature bands are the same in
both and stay as they are.

The tier and limit arithmetic of the guard work moves into two functions
without side effects, guard_next_tier() and guard_limits(), so that it
can be tested. The limits from the battery description still cap the
float voltage and the charge current, and temp_guard is still off by
default.

With the husky battery node as it is today, 4.20 V and 1.485 A, the
float stays 4.20 V in every band and the current 1.485 A, the lowest
row of the husky table being 30 % of 4950 mAh. One case differs from
the default table on that board: from 0 to 10 C with the battery at
4.20 V or more the current limit was 495 mA and is 1.485 A now, as the
Google table has it.

With the battery node's 1.485 A cap, every cell of the husky table
that charges comes out at the cap, so the current does not change from
band to band. What the table changes is the float per band (4.30 V at
0-10 C and 46-48 C, 4.20 V at 48-55 C), which only shows once the
battery node asks for more than 4.20 V, and the one cold cell above.

The same Google file also ages the table: google,aact-cc-limits lowers
the 20-42 C row with use, and google,aafv-ref-offset lowers the float
by up to 100 mV with cycles. That is not done here; it doesn't matter
at 4.20 V and 0.3 C.

Add KUnit tests, built into the driver with
CHARGER_MAX77759_KUNIT_TEST: each band edge, the hysteresis, the tier
steps of both tables, both tables against their numbers, and the
limits with and without the caps of the battery description. They pass
under UML (10 of 10), and the driver builds and links as an arm64
module, W=1 clean, with and without the tests.

The MAINTAINERS entry of the driver now matches the test file too.

Not run on a phone, neither a Pixel 8 Pro nor a Pixel 7 Pro. The choice
of the table by the machine compatible is not covered by the tests.

Signed-off-by: Lef <me@lefteros.com>
@Somnius
Somnius force-pushed the husky-charger-float-1116 branch from 6fbd312 to 0323623 Compare November 18, 2026 08:52
@Somnius

Somnius commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@derekross answers to the open points here, not the DONE fixes yet (those come with the next push of this PR).

cycle_count on my unit: max170xx_battery reads 134 (2026-11-18).

93 to 100 % in 18 minutes. You're right that it doesn't add up, and the log shows why: the percent isn't following the charge there. From 19:00:48 (93 %) to 19:18:54 (100 %) I integrated current_now over the 10 s samples and get 103.6 mAh in, about 2 % of 4950 mAh, not 7 %. The current stayed at 60 to 460 mA the whole time and the voltage went 4.380 to 4.404 V. The percent went 93 to 94 in 7.5 min, then about one step every 1.5 to 2 min up to 100. So near the top the gauge's percent runs ahead of the coulombs, which is the gauge (my phone has Google's ATL model through my overlay), not the charger putting in 1.15 A. I didn't log charge_full in that run, sorry, so I can't show that column; the next run logs it.

the stretch, 10 s samples (capacity, voltage_now, ocv, current_now, temp)
time,capacity,voltage_uV,ocv_uV,current_uA,batt_dC
19:00:48,93,4380468,4362812,408125,377
19:00:58,93,4379843,4363125,418125,377
19:01:08,93,4362031,4363359,95312,378
19:01:18,93,4367500,4363359,266562,377
19:01:28,93,4368281,4363437,262812,377
19:01:39,93,4365468,4363515,207187,378
19:01:49,93,4365625,4363437,155312,378
19:01:59,93,4361718,4363359,61562,378
19:02:09,93,4365937,4363437,115625,379
19:02:19,93,4367187,4363437,158437,380
19:02:29,93,4365468,4363437,90000,380
19:02:39,93,4366406,4363515,137187,380
19:02:50,93,4364687,4363515,202187,381
19:03:00,93,4366093,4363593,205312,381
19:03:10,93,4366718,4363593,181875,382
19:03:20,93,4367500,4363671,240625,383
19:03:30,93,4367187,4363671,245937,383
19:03:40,93,4368125,4363750,234062,384
19:03:50,93,4367187,4363750,252187,385
19:04:01,93,4366562,4363750,185000,385
19:04:11,93,4379218,4363906,411250,385
19:04:21,93,4378437,4364218,451875,386
19:04:31,93,4380312,4364453,430625,387
19:04:41,93,4380937,4364765,413125,386
19:04:51,93,4382500,4365078,458125,386
19:05:02,93,4375312,4365390,310312,386
19:05:12,93,4378906,4365703,401875,387
19:05:22,93,4380000,4365937,372812,386
19:05:32,93,4382187,4366171,450000,386
19:05:42,93,4384531,4366484,454687,386
19:05:52,93,4383125,4366796,454062,386
19:06:02,93,4383281,4367109,427812,387
19:06:13,93,4381093,4367421,395625,386
19:06:23,93,4386250,4367812,460000,386
19:06:33,93,4380781,4368125,310312,386
19:06:43,93,4386562,4368437,436562,385
19:06:53,93,4385781,4368750,436562,386
19:07:03,93,4387812,4369140,432812,386
19:07:14,93,4388125,4369453,464375,386
19:07:24,93,4386406,4369765,391875,385
19:07:34,93,4386406,4370000,327500,385
19:07:44,93,4384687,4370312,345937,385
19:07:54,93,4376250,4370546,261562,386
19:08:04,93,4384218,4370859,268437,385
19:08:14,93,4383437,4371093,306250,385
19:08:25,94,4387812,4371406,313125,385
19:08:35,94,4387968,4371718,315312,384
19:08:45,94,4390156,4372031,326562,384
19:08:55,94,4389687,4372343,332812,383
19:09:05,94,4387343,4372656,325625,384
19:09:15,94,4390000,4372968,321562,384
19:09:26,94,4385937,4373281,282812,383
19:09:36,94,4388593,4373515,402187,383
19:09:46,94,4389218,4373828,412500,383
19:09:56,95,4387343,4374062,374375,383
19:10:06,95,4390625,4374296,441562,383
19:10:16,95,4392343,4374609,415937,383
19:10:26,95,4392812,4374921,432500,383
19:10:37,95,4389218,4375234,396250,383
19:10:47,95,4392968,4375468,399687,382
19:10:57,95,4389062,4375781,373125,382
19:11:07,95,4392031,4376093,409375,382
19:11:17,95,4387656,4376406,309375,383
19:11:27,96,4392968,4376718,422500,382
19:11:37,96,4394218,4377031,435625,382
19:11:48,96,4391406,4377343,411250,381
19:11:58,96,4392500,4377578,382812,382
19:12:08,96,4395000,4377890,422187,382
19:12:18,96,4391875,4378203,361250,382
19:12:28,96,4389218,4378437,433437,382
19:12:38,96,4395000,4378750,398750,380
19:12:48,97,4383281,4378906,236875,382
19:12:59,97,4394375,4379062,366875,381
19:13:09,97,4392812,4379375,350000,381
19:13:19,97,4396562,4379609,283437,381
19:13:29,97,4396718,4379921,306250,381
19:13:39,97,4397343,4380234,319375,380
19:13:49,97,4391875,4380546,339062,381
19:14:00,97,4396406,4380859,227812,381
19:14:10,97,4396718,4381171,287187,380
19:14:20,97,4396718,4381484,318125,381
19:14:30,98,4397187,4381718,301250,381
19:14:40,98,4399062,4382031,249062,381
19:14:50,98,4396875,4382265,274375,380
19:15:00,98,4397812,4382500,284687,381
19:15:11,98,4397656,4382812,312187,380
19:15:21,98,4396718,4383046,443750,380
19:15:31,98,4398906,4383359,408125,380
19:15:41,98,4399062,4383593,440312,380
19:15:51,98,4398906,4383828,422500,380
19:16:01,98,4398906,4384140,446875,380
19:16:11,98,4397656,4384375,378750,381
19:16:22,98,4397968,4384687,380000,380
19:16:32,98,4398906,4384921,413125,380
19:16:42,98,4399062,4385234,426562,380
19:16:52,99,4400156,4385468,428437,380
19:17:02,99,4399687,4385781,385000,380
19:17:12,99,4400000,4386015,411562,380
19:17:23,99,4401875,4386328,410937,380
19:17:33,99,4387812,4386328,226875,380
19:17:43,99,4400156,4386562,409687,380
19:17:53,99,4401093,4386796,419375,380
19:18:03,99,4400781,4387031,380625,380
19:18:13,99,4400781,4387343,417187,379
19:18:23,99,4400937,4387578,400937,379
19:18:34,99,4401093,4387812,421562,380
19:18:44,99,4403906,4388046,381562,379
19:18:54,100,4403906,4388359,420625,379

Why temp sits at 22.0 on the published kernel (Colin's 2450 rows). From reading the source, not run yet:

  • zuma-husky.dts gives fuel-gauge@36 no maxim,fg-model and no maxim,fg-params (on purpose, the comment says there's no battery model yet).
  • max17042_get_temperature() just reads the Temp register (0x08) and scales it, so 220 means the register holds 0x1600.
  • Nothing on that path ever writes Config (0x1D), TGain (0x2C) or TOff (0x2D): the model load only runs with maxim,fg-model, and max17042_override_por_values() only runs with config_data, which a DT node only gets on the MAX17055.
  • Google's husky battery data sets Config 0x4217, TGain 0xED51, TOff 0x1EBA for every pack, and my overlay's fg-params carry those same three values. That fits my phone reading real temperatures and Colin's not.

So on the published tree the gauge reads whatever thermistor setup it already holds. Why exactly 22.0 isn't settled until someone reads the registers on a unit like Colin's; one read-only line would do it: grep -E '^(08|1d|2c|2d):' /sys/kernel/debug/regmap/*-0036/registers. @gitColinX could you run that on yours? If Config is missing the thermistor bit or TGain/TOff aren't ED51/1EBA, that's it.

For the fix I'd rather not put the whole pack model in the published tree, since the packs' models differ. The smaller fix is a driver patch that writes only Config, TGain and TOff from DT on the max77759 path when there's no model, with Google's three values in husky's node. I'll send that as its own PR as you asked, and show temp following a charge on a kernel without my local patches.

And noted on the float: nothing at a raised float until we've been through the limits on #761.

@Somnius
Somnius force-pushed the husky-charger-float-1116 branch from 0323623 to bbd1992 Compare November 18, 2026 10:14
@derekross

Copy link
Copy Markdown
Owner

Thank you, @Somnius, for the answers, and for moving the DONE functions out from under stop_work()'s comment.

  • The 93 to 100 % stretch. I recomputed it from your rows: 103.6 mAh, 62 to 464 mA, so about 2 % of the pack shown as 7 %. That settles my question: it's the gauge's percent running ahead near the top, not the charger. Please log charge_full next time. It also means the DONE rule's "recharge at 95 %" rests on a number that isn't linear up there; the 250 mV half of that rule is the one to trust.
  • Cycle count 134. Under Google's schedule that's offset 0, so stock's float for your pack is 4.48 V and your 4.45 V is under it. I still have to choose between the schedule, a fixed 4.38 V and your 4.45 V for every 8 Pro, and I don't know the other two packs' counts. @gitColinX, could you post your gauge's cycle_count?
  • The 22.0 C. I read max17042_battery.c on the branch and it's as you say: maxim,fg-params is only read together with a model, and nothing else writes Config, TGain or TOff. So your explanation is likely, but it's from source. The read you ask Colin for is fine with me (the gauge's regmap in debugfs is how the 7 Pro's plan reads the same chip): once, phone idle, and post the four lines. For the patch, please:
    • gate the write on a property only husky's node sets, and show the 7 Pro's path unchanged; that file is shared;
    • say which bits of Config 0x4217 differ from what the bootloader left, from Colin's read, and change only those;
    • one boot for the read, another for the write.

Everything else from my last comment stands, and I know the DONE fixes are coming: a DONE below the last tier, the restart count that never comes back on husky (the defender now reads CHGIN itself, the DONE state doesn't), Full for a DONE the check refused, one attended restart on hardware, and a "Tested"/"Not tested" part in the DONE commit's message like the ones you added on #266.

On where the higher float should live: this morning's accident decides it for me. A device tree that carries 4.45 V goes wherever that kernel is booted, guard or no guard. Please leave the battery node at 4.20 V and let the husky table raise the float only while the guard runs; I'll confirm the value itself once I have the cycle counts. The husky package change (loading the charger with temp_guard=1, and sleep on the cable) comes before any of it, inert, the way omarchy-mobile#827 did it for the Pixel 7.

Thank you for reporting this morning straight away. I've written about it on #266. No charge at a raised float until we've been through the limits on omarchy-mobile#761; that review is mine to do and I'll do it next.

@Somnius
Somnius force-pushed the husky-charger-float-1116 branch from bbd1992 to da8aa6c Compare November 18, 2026 17:41
@Somnius Somnius changed the title max77759: husky float 4.45 V with a DONE check max77759: husky DONE check, and the float raised only while the guard runs Nov 18, 2026
@Somnius

Somnius commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@derekross reworked and force-pushed as da8aa6c, now on #266's new head (1244cde):

  • The float: the husky battery node stays at 4.20 V and no device tree carries 4.45 V. The husky guard table raises the float only while the guard runs. It comes back down when the guard is turned off, on unbind or shutdown, and before s2idle, since the guard can't run asleep. If it can't be lowered there and charging can't be held off either, suspend is refused. The cap stays 4.45 V until you pick the value; my cycle count is 143 now.
  • The DONE fixes from your list:
    • A DONE below the last tier is never full when the band can reach the last tier. The last tier follows the float in force, so at 4.20 V a DONE at 4.20 V is full and not restarted.
    • The restart count comes back when the guard reads CHGIN clear, and only a restart that actually ran is counted.
    • Full shows only for a DONE the check accepted.
    • If the mode can't be put back after a restart, the next guard run writes it again.
    • The DONE commit now has Tested / Not tested parts.
  • The husky package change you wanted first, inert while the charger stays blacklisted: omamobile-device-husky 0.1.18: the charger's options and sleep on the cable, inert omarchy-mobile#899 (charger options, and a sleep blocker while the charger is online, which is the "keep awake on the cable" option. Easy to swap once you decide.)
  • The gauge Config/TGain/TOff write: left out until @gitColinX's read.

54 KUnit cases pass, and tools/kernel-pr-check --build from today's main is clean, with 0 checkpatch warnings and the W=1 build ok. Nothing of this head ran on the phone yet. The attended restart can be done at 4.20 V, and I'll post it with an attended s2idle on the cable.

I also updated the description and title, since the old text was about the 4.45 V DTS.

@Somnius

Somnius commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@derekross one thing I should have put here before proposing a patch that writes only Config, TGain and TOff. I tried exactly those three by hand on 2026-11-01, and they're not enough.

From my notes and logs that day, gauge TEMP register 0x08, no second sensor, phone on USB:

  • No model, stock state (Status 0x0002, Config 0x2354, TGAIN 0xeb8d, TOFF 0x20aa): 22.0 C, stuck.
  • Config 0x4217 alone: 66.5 C at room temperature.
  • TGAIN 0xed51 and TOFF 0x1eba too, Config with only TEX cleared: 53.5 C on the first sample, and the script aborted and restored.
  • All three of Google's values: 46.8 to 47.2 C idle near room temperature, 47.4 to 49.3 C under load. So it tracks heat, but sits about 15 to 20 C above what my hand says.
  • Google's full model load (default-a1-0k through a local overlay, later the ATL model: fg-model, fg-params, DesignCap, TaskPeriod and the three): POR cleared, 34.4 C and drifting down after boot, which is plausible. That's what my phone runs now, still through my overlay.

Logs: logs-gauge-temp-test.txt, logs-gauge-temp-test-stock.txt, logs-gauge-cooldown.txt. All by hand over i2c and restored after each test, except the model load, which was the overlay.

So a probe-time write of only those three would likely give a temperature that's 15 to 20 C high, which is worse than a stuck 22.0 for the guard. The working path on my phone is the whole model load, like #171 for the Pixel 7. I haven't tested whether a write at probe behaves like my hand writes. Colin's read is still worth having to see if his unit sits in the same power-on state. But I'd change the plan from "write the three registers" to "load the model on husky", and the pack question (which model for which pack) comes with it. I'll hold the gauge patch until you say which way.

@gitColinX

Copy link
Copy Markdown
Contributor

@derekross, @Somnius, both reads from my unit: published omamobile at 82f31d3a7, device-husky 0.1.13, phone idle on USB, read once.

08: 1600
1d: 2354
2c: eb8d
2d: 20aa

Status (00) read 0002. So it is in the same power-on state Somnius logged on 11-01: Temp 0x1600 (22.0 °C), Config 0x2354, TGain 0xeb8d, TOff 0x20aa.

cycle_count reads 120. That is the raw sysfs value, and this gauge has no battery model loaded, so I don't know how it compares with Somnius's.

@Somnius

Somnius commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@gitColinX thank you, that's the read I was hoping for: your gauge is in the same power-on state mine was on 11-01 (Status 0x0002, Config 0x2354, TGain 0xeb8d, TOff 0x20aa, Temp stuck at 22.0 °C). So it's the port, not my unit.

@derekross together with what I posted here last night: Colin's unit matches the power-on state mine was in on 11-01, and on mine writing only Google's three values gave a temperature 15 to 20 °C high, while the full model load gave a plausible one. So the fix I'd propose is loading the model on husky (as #171 does for the Pixel 7), not the three-register write. I'm holding the gauge patch until you say which way.

set_fast_charge_current_limit() and set_float_voltage_limit() pick the
step at or above the requested value
(linear_range_get_selector_high_array()), so a request between two
steps is written as the next step up. On husky the battery node's
1485000 uA becomes 1533400 uA, 48 mA above the battery's limit.

Take the step at or below the request instead, for both, as Google's
driver does (max77759_set_charger_current_max_ua() in
google-modules/bms rounds down too).

The current, at probe: cheetah and raven ask for 1466730 uA, an exact
step, so probe writes the same value as before. akita's 1320000 uA goes
from 1333390 uA to 1266720 uA. husky's 1485000 uA becomes 1466730 uA.
A request above the highest step (4000190 uA) or below the lowest is
still -EINVAL, through a new cc_selector() like the float's: a battery
node without constant-charge-current-max-microamp leaves -EINVAL in the
field, and max77759_charger_init() copies it into a u32, which must stay
a failed probe and not become a 4 A current with no cap.

The current, under the temperature guard (temp_guard=1), this changes
the Pixel 7 Pro, the 6 Pro and the Pixel 7 too: every guard current
that falls between two steps is now one step lower. At 0-10 C between
4.20 and 4.30 V the default table asks for 10 % of the capacity, 492.6
mA on the 7 Pro, which was written as 533 mA and is now 467 mA (the 6
Pro's 490.5 mA the same); on the Pixel 7, 427.7 mA was 467 mA and is now
400 mA. Stock rounds down there, so this is a fix for those phones as
well.

The float: a new fv_selector() takes the step at or below the request,
3900 mV between the two ranges, and still refuses a request below the
lowest step or above the highest (4500 mV) with -EINVAL rather than
clamping it. Every float in use (4200, 4300, 4450 mV and the guard
table's) is a multiple of 10 mV, an exact step, so no written float
changes today on any board.

Tested: KUnit under UML (new cases for the float steps, the range gap
and the limits, and for the current: 1485000, 4000190, 4000191 and
(u32)-EINVAL); arm64 objects at W=1 with and without the KUnit option.
On a Pixel 8 Pro, 2026-11-18, slot B, kernel
7.3.0-rc6-omamobile-push1-gc4d94a1c1fe5 (an earlier head of this series,
linux-omarchy-mobile#266, which still had the charge defender and the
husky float restore, now in their own PR, before the -EINVAL above the
top current step and the read-back values in the dev_err, which KUnit
covers, on the published base, nothing else on top; the charger options
from /etc/modprobe.d, temp_guard=1 charge_defender=1
default_ilim_ua=500000; a 500 mA desktop USB port):
the probe logged "fast charge 1466730 uA" for husky's 1485000 uA (the
bootloader had left 1933420 uA). The float written at probe, 4200 mV, is
an exact step, so the float rounding is covered by KUnit only.

Not tested: anything on a Pixel 7 Pro, 6 Pro, Pixel 7 or akita; a guard
current between two steps on hardware.

Signed-off-by: Lef <me@lefteros.com>
Add charge_control_end_threshold and charge_control_start_threshold to
the charger. At 100 / 0, the default, they do nothing and the guard work
reads and writes nothing more than before. With a lower end, charging
stops (buck only, as the temperature guard does) once the battery's
capacity reaches it, and resumes at the start threshold, or 5 % below
the end when start is 0 or not below the end.

Each threshold is checked on its own, so the order of two writes does
not matter: an end at or below the start sets the start back to 0.
charge_control_start_threshold reads back the value in force, so with
an end of 80 and a start of 0 it reads 75, the level charging resumes
at. With the end at 100 it reads the stored start.

The two inhibits, the temperature guard's and the threshold's, are kept
apart so that neither clears the other. The thresholds run first in each
guard run, so a stop is in place before the guard clears its own
inhibit, and a flag only changes once the mode write has worked, so a
failed write is tried again at the next run. The thresholds are checked
by the guard work, at most 30 s after a change in capacity. On unbind,
after the guard work is cancelled, a threshold stop is cleared before
charging is left on.

While either inhibit holds the charge with the cable in (buck only, the
chip reports CHG_DTLS off and CHGIN valid), status now reads Not
charging instead of Discharging. With no input it reads Discharging,
whatever the flags and the last mode written. This reaches the Pixel 7
Pro, the 6 Pro and the Pixel 7 too when they run with temp_guard=1:
while the temperature guard inhibits charging with the cable in, their
status changes from Discharging to Not charging. One more change for
them with temp_guard=1: the guard's inhibit flag is now rolled back when
its mode write fails, and the write is tried again at the next run,
where before the flag stayed set with the chip still charging.

The guard work is delayed work and s2idle stops it, so the thresholds
are only checked while the phone is awake: asleep on the charger, the
chip carries on to the float, and a stop already in place stays in
place. temp_guard's description now says the guard work only runs while
the phone is awake.

The rules are side-effect free functions with KUnit tests; the two
inhibits, the status and the stop and resume on a fake capacity are
tested on a regmap backed by an array, and the tests read their own
fake battery and register their charger supply under a test name, so
they leave guard_psy and the real max77759-charger alone.

Tested: KUnit under UML; arm64 objects at W=1 with and without the KUnit
option.
On a Pixel 8 Pro, 2026-11-18, slot B, kernel
7.3.0-rc6-omamobile-push1-gc4d94a1c1fe5 (an earlier head of this series,
linux-omarchy-mobile#266, which still had the charge defender and the
husky float restore, now in their own PR, before the -EINVAL above the
top current step and the read-back values in the dev_err, which KUnit
covers, on the published base, nothing else on top; the charger options
from /etc/modprobe.d, temp_guard=1 charge_defender=1
default_ilim_ua=500000; a 500 mA desktop USB port):
an end of 90, saved by the Settings unit and applied at boot, stopped
charging 36 s after boot ("charge stopped at 90 %"), status read Not
charging with the cable in and the start read back 85. Unplugged,
online read 0 and status Discharging; plugged back in at 89 %, status
stayed Not charging (resume at 85 % or less). An end of 100 read the
start back as 0, logged "charge resumed: no limit" and status read
Charging; an end of 90 again at 89 % did not stop it (the stop is at
90 % or more) and the start read 85. After a reboot the bootloader had
put the charger mode back (a threshold stop does not survive a reboot)
and the saved end of 90 and start of 85 came back. Status read Full at
89 % once, with the battery at 4.26 V above the 4.20 V float.

Not tested: a stop that reaches the start and resumes on its own,
suspend while plugged in, poweroff (that base lacks the rtc fix, so
reboots only), anything on a Pixel 7 Pro, 6 Pro or Pixel 7.

Signed-off-by: Lef <me@lefteros.com>
…atile

The charger regmap caches every register but the interrupt and status
ones. CHG_CNFG_00 to CHG_CNFG_04 hold the charger mode, the fast charge
current and the float voltage. The charger driver is going to read
them back after it writes them, to make sure the chip holds what was
asked, and a cached read would only return the value it just wrote.

Mark 0xb9-0xbd volatile so reads go to the chip. Writes are the same as
before; regmap_update_bits() now reads the chip instead of the cache
first, one more i2c read per update.

This reaches every board with the MAX77759, the Pixel 7 Pro, the 6 Pro
and the Pixel 7 too: every read of these registers, the sysfs reads of
the current and the float and every update of them, now goes to the
chip, and with temp_guard=1 every guard run talks to the chip. The MFD
has no cache sync or cache-only path on suspend, so no resume path
changes.

Tested: arm64 objects at W=1 with and without the KUnit option; the
charger's KUnit tests under UML.
On a Pixel 8 Pro, 2026-11-18, slot B, kernel
7.3.0-rc6-omamobile-push1-gc4d94a1c1fe5 (an earlier head of this series,
linux-omarchy-mobile#266, which still had the charge defender and the
husky float restore, now in their own PR, before the -EINVAL above the
top current step and the read-back values in the dev_err, which KUnit
covers, on the published base, nothing else on top; the charger options
from /etc/modprobe.d, temp_guard=1 charge_defender=1
default_ilim_ua=500000; a 500 mA desktop USB port):
probe, the thresholds and the guard ran with no visible change from
this; read-only through regmap debugfs the charger registers matched
what the driver logged (a 4200 mV float written over the bootloader's
4350 mV, again after a reboot). On 2026-11-16, on an earlier form of
this series, 0xbd read 0x2d after probe and 0x23 after unbind (the float
restore, since moved to its own PR), the values the driver wrote.

Not tested: anything on a Pixel 7 Pro, 6 Pro or Pixel 7.

Signed-off-by: Lef <me@lefteros.com>
The temperature guard writes the float voltage and the charge current
and has so far ignored a failed write. Read both back from the chip
after writing them (the registers are volatile since the previous
patch) and keep charging inhibited when the chip does not hold the
step the request maps to, or when a write or a read fails. The next
guard run tries again; the error is logged once, when it starts, with
the float and current asked for and what the chip holds. The
release back to the battery's own limits does the same and stays
active until the chip is seen to hold them. The write order is
unchanged: float, then current.

This runs on every board with temp_guard=1, the Pixel 7 Pro, the 6 Pro
and the Pixel 7 too: each guard run now writes and reads the two
registers on the chip, and a mismatch or a failed read now stops
charging (buck only) where a failed write used to be ignored. With
temp_guard=0, the default, nothing changes.

The expected values come from the same step rounding the setters use,
at or below the request for both, so a request between two steps is
no mismatch.

Tested on a regmap backed by an array: the write order and values, a
wrong read-back of the float and of the current gives -EIO with the
values the chip holds and puts the chip in buck-only mode, a request
refused before the write reads nothing back, and a good one resumes
charging. KUnit under
UML; arm64 objects at W=1 with and without the KUnit option.
On a Pixel 8 Pro, 2026-11-18, slot B, kernel
7.3.0-rc6-omamobile-push1-gc4d94a1c1fe5 (an earlier head of this series,
linux-omarchy-mobile#266, which still had the charge defender and the
husky float restore, now in their own PR, before the -EINVAL above the
top current step and the read-back values in the dev_err, which KUnit
covers, on the published base, nothing else on top; the charger options
from /etc/modprobe.d, temp_guard=1 charge_defender=1
default_ilim_ua=500000; a 500 mA desktop USB port):
the guard logged "battery 38.6 C, 4308 mV: band 20-42 C, float 4200 mV,
charge 1485000 uA", and no read-back error or inhibit was logged through
the run and a reboot.

Not tested: a real mismatch or failed read on hardware (the failure path
is KUnit only), anything on a Pixel 7 Pro, 6 Pro or Pixel 7.

Signed-off-by: Lef <me@lefteros.com>
Add the charge defender of the stock Pixel 8 Pro charger driver, behind
a new charge_defender module parameter that is off by default and only
acts on husky: plugged in at 4.27 V or more, time at 35.0 C or more is
counted, and after 6 h charging stops at 80 % and resumes at 79 %
until the cable comes out. It only stops charging (buck only); nothing
drains the battery, so one already above 80 % when it latches stays
there until use brings it down. A voltage below 4.27 V starts the count
again; a lower temperature only pauses it. A user end threshold below
80 % stays in force. While it is latched, charge_control_end_threshold
and charge_control_start_threshold read back the values in force, 80
and 79 (or the user's lower ones), as the start threshold already reads
75 for an end of 80.

The numbers are the stock ones from zuma-shusky-charging.dtsi
(kernel/devices/google/shusky, branch android-gs-shusky-6.1-android16):
google,bd-trigger-voltage 4270000, bd-trigger-temp 350, bd-trigger-time
21600, bd-drainto-soc 80 and bd-recharge-soc 79. Stock's resume
conditions (google,bd-resume-abs-temp, bd-resume-soc, bd-resume-time,
bd-resume-temp) are not copied: here the stop lasts until unplugged.

Each guard run reads CHGIN itself and an input gone clears the
defender. On husky that read is what sees an unplug: no TCPM supply
notifies this driver there, so the psy work does not run. An unplug
and replug that both fall between two guard runs (30 s apart) is
missed. On boards where the psy work runs, an unplug it sees is kept
for the next guard run, so a quick replug still counts there.

The same dtsi also sets google,bd-temp-dry-run. With it,
google_charger.c (google-modules/bms) still counts and, on trigger,
still calls bd_batt_set_state(), but bd_recharge_logic() returns before
it turns charging off, so stock only stops charging once dry run is
cleared at run time (its bd_temp_dry_run sysfs file or vote). Whether
Android clears it on the 8 Pro is not known here. This driver has no dry
run: with charge_defender=1 it stops charging.

It uses the threshold stop of the earlier patch, so it is buck
only with the cable in and status reads Not charging.

The defender runs in the guard work, which is delayed work: s2idle
stops it. Each run counts at most 60 s, so time asleep never counts
toward the six hours. While the phone sleeps on the charger, a stop
already in place stays (buck only), but a charge below 80 % goes on to
the float with nothing to stop it at 80 %. The parameter's description
says so too.

Nothing changes on other boards, with the parameter on or off.

The defender step and the choice of thresholds are side-effect free
functions with KUnit tests (21599 s does not latch, 21600 s does, the
latch holds until unplugged, 4.269 V resets, 34.9 C pauses, one long
gap counts at most 60 s); an unplug seen by the psy work, an unplug
seen only by the guard run's CHGIN read, and the read-back while
latched are tested on a regmap backed by an array.

Tested: KUnit under UML; arm64 objects at W=1 with and without the KUnit
option.
On a Pixel 8 Pro, 2026-11-18, slot B, kernel
7.3.0-rc6-omamobile-push1-gc4d94a1c1fe5 (an earlier head of this series,
linux-omarchy-mobile#266, before the -EINVAL above the top current
step and the read-back values in the dev_err, which KUnit covers, on
the published
base, nothing else on top; the charger options from /etc/modprobe.d,
temp_guard=1 charge_defender=1 default_ilim_ua=500000; a 500 mA desktop
USB port):
the charger loaded and charged normally with charge_defender=1, and the
threshold stop it uses worked (see the thresholds patch). The defender
itself was not exercised: with the husky float at 4.20 V the battery
never reaches 4.27 V, so it cannot latch.

Not tested: the defender firing on the phone (it needs a float above
4.27 V and 6 h plugged in at 35 C or more), suspend while plugged in,
the unplug seen by the guard run while latched. Until a float above
4.27 V it is covered by KUnit only.

Signed-off-by: Lef <me@lefteros.com>
On husky, unbind and a new .shutdown put back the float the bootloader
left (read at probe before the battery's float replaces it, and capped
at the 4.35 V the husky bootloader sets, so a float left by an earlier
driver run is not taken for the bootloader's, and taken to be 4.35 V
when it cannot be read), but only when the chip's float is above it, so
this never raises the float. The restore is read back. When the float
cannot be read, or the chip does not hold the restored one, that is
logged and charging is stopped (buck only); unbind then leaves it
stopped instead of clearing the stop, so the phone does not charge on
what may be the raised float. Charging comes back when the driver is
bound again, or at the next boot when the bootloader rewrites the
charger mode.

On unbind the order is: the guard work is cancelled, the float is
restored, a threshold stop is cleared (unless the restore failed), and
only then is charging left on, so charging never resumes on the raised
float.

.shutdown disables the guard work on every board, the Pixel 7 Pro, the
6 Pro and the Pixel 7 too, so no guard run, not even one the notifier
kicks, writes to the chip after it; the float restore that follows acts
on husky only. .shutdown does not clear a threshold or defender stop: a
stop in place at shutdown (buck only) stays until the bootloader
rewrites the charger mode.

With the husky battery node at 4.20 V and the bootloader at 4.35 V the
restore does nothing today; it matters once the float is raised.

The restore rule is a side-effect free function with KUnit tests
(4200 / 4350 and 4350 / 4350 leave it, 4360 / 4350 lowers it, an
unknown boot float leaves it), as is the boot float (husky caps it at
4350 mV and falls back to 4350 mV); the restore on husky, the untouched
other boards, and a failed read and a failed read-back (charging stays
stopped through unbind) are tested on a regmap backed by an array.

Tested: KUnit under UML; arm64 objects at W=1 with and without the KUnit
option.
On a Pixel 8 Pro, 2026-11-18, slot B, kernel
7.3.0-rc6-omamobile-push1-gc4d94a1c1fe5 (an earlier head of this series,
linux-omarchy-mobile#266, before the -EINVAL above the top current
step and the read-back values in the dev_err, which KUnit covers, on
the published
base, nothing else on top; the charger options from /etc/modprobe.d,
temp_guard=1 charge_defender=1 default_ilim_ua=500000; a 500 mA desktop
USB port):
the probe read the bootloader's 4350 mV and wrote 4200 mV, so nothing
was raised and the restore had nothing to do; a reboot went through
.shutdown and the next boot found the bootloader's mode 0x5 and 4350 mV
again. On 2026-11-16, on an earlier form of this series with the float
raised to 4.45 V, unbinding put it back to 4.35 V (0xbd 0x2d to 0x23).

Not tested: a restore that lowers the float on the head of this
series (unbind or .shutdown), a failed restore on hardware, poweroff,
anything on a Pixel 7 Pro, 6 Pro or Pixel 7.

Signed-off-by: Lef <me@lefteros.com>
The chip can report DONE below the float: on a husky left at the
bootloader's 4.35 V float, CHG_DTLS read DONE with the gauge at 4.296 V
and 92 %. The stock husky charger (max77759_is_full()) only takes that
as full in the last voltage tier and within 50 mV of the float;
otherwise it turns the charger off and on again so the charge goes on.

Do the same in the temperature guard, on husky only. The last tier is
the first one whose voltage reaches the float the guard applies: at the
battery node's 4.20 V that is the first tier, so a DONE at 4.20 V is
full there and does not restart.

- in the last tier, DONE at vbatt >= float - 50 mV is full, and
  stays full until the capacity falls to 95 % or the voltage 250 mV
  below the float;
- in a band that reaches the last tier, DONE in a lower tier is never
  full (a small adapter under load can reach top-off there, as Google's
  comment at the top-off interrupt says);
- otherwise set the mode off and back to charging, at most once per
  10 minutes and 5 times per plug-in, then warn once. Only a restart
  that ran counts: none while charging is held off or when the off
  write fails. Putting the mode back is tried three times; then an
  error is logged and the next guard run, with temp_guard on or off,
  writes the mode again;
- in a band capped below the last tier, DONE is that band's limit and
  nothing is done, and a full found earlier is cleared.

A plug-in gets its restarts back when the psy work sees the source go
or, since husky's Type-C node is disabled and no TCPM supply notifies,
when the guard run reads CHGIN clear, as the defender does. An unplug
and replug that both fall between two runs is missed.

While the check runs, status reads Full only for a DONE it accepted;
a DONE it restarts, refuses or takes as a band's limit, has not looked
at yet (up to one guard period), or sees while the guard has no
reading or holds charging off, reads Not charging.

It runs only with temp_guard on (off by default), and never while the
guard or a charge threshold holds charging off. Other boards are
unchanged.

The guard run after the gauge read is split out as guard_run(), so
KUnit can drive it whole. The rule is a side-effect free function with
tests for the full margin, a DONE below the last tier, the tier in
force, the recharge levels and the rate limit; the restart writes (off
then on), the CHGIN reset, the status and whole guard runs are tested
on the array-backed regmap.

Tested: KUnit under UML (50 cases pass); an arm64 W=1 build of the
driver without the KUnit option.

Not tested: anything on hardware at this head. The restart (mode off,
then on, with the cable in), its count, and the count coming back
after a replug have only run in KUnit; they need one attended run on
a weak port with the screen on, at the 4.20 V float, which is not a
raised one. Whether CHGIN stays set in CHG_INT_OK across the off/on
restart is not known; if it drops, a guard run that sees it clear
gives the count back. Nothing on a Pixel 7 Pro, 6 Pro or Pixel 7.

Signed-off-by: Lef <me@lefteros.com>
The husky battery node asks for a 4.20 V float, and stays at that: a
device tree that carries a higher float applies wherever that kernel
is booted, guard or no guard, and so does a driver loaded by hand or
with a stale options file.

Give the guard table its own float cap, used in place of the battery
description's while the guard runs, and set it to 4.45 V for husky.
With temp_guard on, the guard takes the battery through the stock
tiers up to 4.45 V, with the DONE check, whose last tier follows the
cap. When temp_guard is set to 0 at run time, the next guard run puts
the node's 4.20 V back, so the raised float can hold for up to one
guard period (30 s) after. On unbind or shutdown the float is put
back to the bootloader's (at most 4.35 V). With temp_guard off from
boot (the default) nothing changes: 4.20 V at probe. Other boards'
tables have no cap of their own and keep their node's float.

No guard runs while the phone sleeps, so add suspend and resume
hooks: suspend stops the guard work and, when the guard has raised
the float, puts the node's 4.20 V back and reads it; if the chip does
not take it, charging is inhibited instead, and if that write fails
too the sleep is refused with -EIO. Resume starts the guard work
again, and its first run raises the float if the band allows.

Google's husky data (kernel/devices/google/shusky, branch
android-gs-shusky-6.1-android16) has google,fv-max-uv = <4480000> in
dts/zuma-shusky-charging.dtsi, lowered by google,aafv-ref-cycles and
google,aafv-ref-offset in dts/zuma-husky-battery.dtsi by 20 mV per 200
cycles, to 4.38 V from 1000 cycles. 4.45 V is in neither: it is a
choice, under the maximum for a new pack and over the schedule past
400 cycles, and stays open until the float is decided.

Tested: KUnit under UML (54 cases pass), with cases for the cap the
guard run uses on husky and on the default table, a whole guard run
raising the float and taking a DONE at 4.42 V as full, a 46-48 C run
whose DONE is the band's limit only under the husky cap, the sleep
float (lowered, left alone at 4.20 V, raised again by the next run,
inhibit when the write fails), and the suspend and resume hooks
(float lowered, sleep refused when both writes fail, work queued
again on resume).

Not tested: anything on hardware, including the suspend and resume
hooks on a real s2idle. Whether the chip still reports DONE right
after a resume from a sleep at 4.20 V is not known: if it does, the
first run after resume, back at 4.45 V, can spend one restart on it.
An attended s2idle on the cable settles it. Nothing has charged at
this float on this head, and nothing will until the limits on
omarchy-mobile#761 are reviewed.

Signed-off-by: Lef <me@lefteros.com>
@Somnius

Somnius commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@derekross heads up: after the #266 split this one stacks on the new defender PR (#277) instead of #266, because its two commits need the defender code and don't apply on #266's five alone. The code didn't change, only the hashes below it moved: head is now c4aca6f (was da8aa6c). KUnit is 54/54 and the gate passes. Like the defender, it waits for the gauge temperature fix and for derekross/omarchy-mobile#761.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants