Skip to content

power: supply: max77759: Pixel 8 Pro charge defender and husky float restore - #277

Draft
Somnius wants to merge 7 commits into
derekross:omamobilefrom
Somnius:husky-charger-defender-1119
Draft

Somnius wants to merge 7 commits into
derekross:omamobilefrom
Somnius:husky-charger-defender-1119

Conversation

@Somnius

@Somnius Somnius commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

@derekross this is the split you asked for on #266 (#266 (comment)). The two husky commits come out of #266 and wait here for the gauge temperature fix. Until that lands the defender would read 22.0 C forever on a published kernel and never count, so please don't merge this before it.

It's stacked on #266, so the first five commits here are #266's and only the last two are new:

  • power: supply: max77759: add the Pixel 8 Pro charge defender
  • power: supply: max77759: put the husky float back on unbind and shutdown

The code is the same as at #266's old head 1244cde. The only change in the series is in #266's commits: a test comment and the tested notes now say the earlier head had these two commits. This tip is 9a079c7. #267 (#267) now stacks on this one, since its two commits don't apply without the defender.

Tested: KUnit under UML on this tip, 37 tests pass (26 on #266 alone, 54 with #267 on top). The kernel-pr-check gate passes on the two new commits: checkpatch --strict clean, policy clean, W=1 build. On the phone, only what's in the commit messages: the 2026-11-18 run of an earlier head of #266 with charge_defender=1.

Not tested: the defender against a real gauge temperature, because that fix isn't in yet. Nothing with the float raised, and there won't be any of that until the limits on #761 (derekross/omarchy-mobile#761) are reviewed. Nothing on a 7 Pro, 6 Pro or Pixel 7. For now, keeping the phone awake on the cable (derekross/omarchy-mobile#899) is the 8 Pro's answer.

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>
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>
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.

1 participant