Repository navigation
Conversation
|
Thank you, @Somnius. This is careful work: the two inhibits kept apart, the restore that only ever lowers, the devm order, the tests on an array-backed regmap, and above all the plain list of what you didn't test. I checked the rounding against Google's driver ( It can't go in as it is, for these reasons:
Your questions:
Smaller things:
Two things from omarchy-mobile#761 that bear on this:
The Pixel 7 is about to start running this guard (#259 and omarchy-mobile#827, #788), so I'll keep this out of the kernel its first attended run uses, or make sure it's in it: one change at a time there. |
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>
bf42640 to
c4d94a1
Compare
|
@derekross thanks for the careful read. Reworked and force-pushed (head c4d94a1), on #265's new head: The last commit is split as you asked, so the series is now: the current/float rounding, the thresholds, the MFD volatile registers, the read-back, the defender, and the float restore with From your list:
Two things I found reading Google's side that you may want to know: What's still open, honestly: each message's "Tested" part still describes my runs on the earlier one-commit form plus a local test commit, not this head on the published base with the guard switched on by the module parameters. Those re-runs are next. On #266 alone the husky float stays at 4.20 V, so the defender can't latch on the phone and the float restore has nothing to restore; both are KUnit-only for now, and the messages say so. Nothing will run at a raised float until we've been through the limits on #761. |
c4d94a1 to
9c1af39
Compare
|
@derekross the re-run on this head, and the results are now in each commit's message (head 9c1af39, code unchanged from c4d94a1, only the Tested parts). My 8 Pro, slot B, kernel
Not run, and the messages say so: the defender latch (4.20 V never reaches its 4.27 V), the float restore actually lowering something, a read-back mismatch on hardware, sleep on the cable, poweroff (the base doesn't have the S2MPG14 rtc fix yet, so reboots only), and of course nothing on a 7 Pro. Logs (30 s CSV, dmesg) are on my side if you want them attached. |
|
Thank you, @Somnius. This is the rework I asked for, point by point: the split into four, the messages saying what changes on the 7 Pro, 6 Pro and Pixel 7, the "Tested" and "Not tested" parts, and a run of this branch's own tree on the published base with the guard switched on by the module options (I checked that One change, in the rounding commit:
Smaller:
What happens next is on my side:
About your note on omarchy-mobile#761 this morning: thank you for catching it and saying so within the hour. It wasn't a decision this time but a leftover kernel, which is the kind of thing a rule alone doesn't stop. Two requests. Until your daily kernel is rebuilt, read |
|
@derekross thanks, and point taken on the two minutes of sleep for #836, I hadn't connected that to the float. The daily kernel is rebuilt without the raised float: I'll do the current clamp (-EINVAL above the last range, with tests for 4000190, 4000191 and |
9c1af39 to
1244cde
Compare
|
@derekross pushed as 1244cde (force-push, same base
KUnit under UML: 37 of 37 pass. |
derekross
left a comment
There was a problem hiding this comment.
Thank you, @Somnius. All three are done as asked, and I checked each in the code. cc_selector() refuses a current above 4000190 uA or below the first step, max77759_charger_init() passes the error on, so a battery node without the property is a failed probe again; the test covers 4000190, 4000191 and (u32)-EINVAL, through charger_apply_limits() too. The dev_err now says what the chip holds. The messages name the series. CI is green, and since its W=1 step skips the test file I built every commit here with and without the KUnit option: 14 builds, no warnings. I haven't run the KUnit suite myself.
Thank you also for rebuilding the daily kernel and for the habit of reading the float before the cable goes in.
One small thing for whenever you next push, not worth a push on its own: in the rounding commit's "Tested" part the sentence about the earlier head breaks in mid-phrase ("… which KUnit covers, on the published / base, nothing else on top") and reads as if KUnit ran on the published base.
Nothing else is open on your side for the five shared commits. What's left is mine:
- The run on my 7 Pro: a charge from under 80 % with the guard on, a threshold stop and resume, unplug and replug, a sleep on the charger, a reboot.
- The decision on a limit that doesn't hold while the phone sleeps. Your omarchy-mobile#899 gives it a concrete form for husky; I've said there which way I lean.
- The defender and the float restore still wait for the gauge temperature. If you'd like the five shared commits in first, move those two to their own PR; otherwise the series waits as one.
I saw your question on omarchy-mobile#761 about 4.20 V against the bootloader's 4.35 V. I'll answer it there together with the limits.
|
Decided on point 3: please split it. The five shared commits stay here and can go in after my 7 Pro run; the defender and the float restore move to a PR of their own and wait there for the gauge temperature fix. On point 2, keeping the phone awake on the cable (omarchy-mobile#899) is the 8 Pro's answer for now. |
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>
1244cde to
6a78515
Compare
|
@derekross done, I split it. This PR now has only the five shared commits, head 6a78515 (it was 1244cde), so it's ready for your 7 Pro run. What changed:
No code changed besides that comment. KUnit is 26/26 on this head and the kernel-pr-check gate passes. The defender PR head is 9a079c7 and #267 is now c4aca6f. |
The two husky commits (the Pixel 8 Pro charge defender and the husky float restore) moved to #277, where they wait for the gauge temperature fix. This PR has only the five shared commits.
@derekross second of three for the 92 % stop on my Pixel 8 Pro, on top of #265 (its commit is the first one here, so review that one there).
Three commits:
charge_control_end_thresholdandcharge_control_start_threshold(100 / 0 by default, which does nothing), a husky onlycharge_defenderparameter like stock's (6 h plugged at 4.27 V and 35 C or more, then hold at 79-80 % until unplug, off by default), a read-back of float and current after every guard write that stops charging on a mismatch, and on husky the bootloader's float put back on unbind and shutdown, only ever downwards.Tested: 28 KUnit cases pass under UML, the charger and MFD objects build for arm64 with W=1 and no warnings, checkpatch --strict is clean on all three, and kernel-pr-check is all ok with the fix from derekross/omarchy-mobile#851.
On the phone today, with this plus the third PR (float 4.45 V on husky) built into a test kernel, the charger loaded by hand with
temp_guard=1 charge_defender=1 default_ilim_ua=500000, attended and with a guard script on the phone:Not tested: suspend while plugged in (the guard is delayed work and pauses in s2idle while the chip keeps charging, so for now I don't leave it sleeping on the cable), the defender actually firing (needs 6 h), and anything on a 7 Pro.
Questions for you:
temp_guardoff by default, the next PR's device tree change alone would charge husky straight to 4.45 V with no steps. Keep the switches off in the driver and turn them on from the husky package like cheetah's charger conf, or keep the husky float at 4.20 V in the device tree and let the guard raise it?This merges cleanly with #261 (checked with a test merge). Husky boots with 0xc2 = 0x13, NO_AUTOIBUS clear, so the charger already picks its own input current there; that fits what I saw, the battery took up to about 470 mA on top of the phone's own load with
default_ilim_ua=500000.The husky package still blacklists
max77759_charger, so none of this runs on a stock install until that changes. I'll send that after the kernel side is in, since on today's kernel unblocking it would set the float to 4.20 V.