Skip to content

power: supply: Add the Maxim MAX77779 charger - #92

Merged
derekross merged 2 commits into
derekross:omamobilefrom
W4HO-ham:tegu-max77779-charger
Oct 29, 2026
Merged

derekross merged 2 commits into
derekross:omamobilefrom
W4HO-ham:tegu-max77779-charger

Conversation

@W4HO-ham

Copy link
Copy Markdown
Contributor

A driver for the MAX77779's charger, at 0x69 beside the fuel gauge (#38, #66). The Pixel 9a runs the charger under its OTP defaults. This driver reports on it and can stop charging, nothing more:

  • Read: online (CHGIN), the charge status and type from CHG_DETAILS_01, the input current limit and the charge current.
  • Write: charge_behaviour inhibit-charge puts the charger in buck-only mode (CHG_CNFG_00 mode 4, behind CHGPROT). auto, and unbinding, put it back in charge-and-buck mode.
  • No interrupts: the interrupt registers are clear-on-read and aren't touched. The state is polled every 10 s, with power_supply_changed() on input or state changes.
  • Gauge link: the gauge names the charger in its power-supplies, so the battery's status can follow it through power_supply_get_property_from_supplier().

Tested on the Pixel 9a (7.3.0-rc6-omamobile-tegu-s2mpg15-m1-g991042e2eff3-dirty). I created the device at 0x69 through new_device in place of our out-of-tree driver:

  • online 1, Charging/Standard, input limit 1.5 A, charge current 1.93 A;
  • inhibit-charge gives "Not charging", and auto gives "Charging" again.

One honest note: buck-only isn't "battery idle" near full. At 99 % the battery still gave about 450 mA while inhibited, and our out-of-tree driver shows the same with the same register write. The message and the code comment say so.

Our out-of-tree driver also does two things this one doesn't, which can come later:

  • Type-C/BC1.2 input current: it reads the TCPC behind the charger's back, which belongs to a Type-C port driver.
  • Step charging: the battery's temperature and voltage table up to 4.5 V, which should come from the DT.

checkpatch --strict is clean on the driver commit. The binding commit gets only the MAINTAINERS question, which the driver commit's entry answers. dt_binding_check passes, and the driver builds with W=1.

@derekross

Copy link
Copy Markdown
Owner

Thanks for this. It's a careful first driver for the charger: nothing is written at probe, charge current and voltage are never touched, the write table allows only the mode and protection registers, and it's off unless someone enables it. I checked every register and field against Google's max77779_v20240115_regs.h, and they match, as do your input-limit decoding and the CHG_DTLS states. The honest note about the battery still giving about 450 mA near full is appreciated.

One thing to fix before I merge:

  • An inhibit outlives the driver. The mode is restored only on unbind. There's no .shutdown, so after inhibit-charge and a reboot the charger can come back in buck-only mode (the PMIC stays powered across a warm reboot). Probe then just warns, starts with held = false and auto, and writing auto does nothing because nothing seems to change, so the phone stays not charging until someone writes inhibit-charge and then auto. Could you take held and the behaviour from the mode you read at probe (mode 4 means inhibited, so status says "Not charging" and auto restores), and add a .shutdown that puts mode 5 back when held? It would also help to know what CHG_CNFG_00 reads after a warm reboot with inhibit set.

A question:

  • Is CHG_CNFG_00 really behind CHGPROT? Google's max77779_chg_is_protected() lists CNFG_01, 03, 07-08, 13 onwards and CHG_CUST_TM, but not CNFG_00, and their mode writes don't unlock. If the mode write works on the 9a without opening CHGPROT, I'd rather drop the two CNFG_06 writes and the "behind CHGPROT" wording, so the driver writes the charger as little as possible.

Smaller things, for the same push if you agree:

  • Teardown order: the restore action runs before the power supply is unregistered, so a charge_behaviour write in that gap would re-inhibit with no driver left. Registering the restore before devm_power_supply_register(), and the work cancel after it, closes that.
  • The poll runs on system_wq, which isn't frozen for suspend, so a poll can land after the I2C controller has marked itself suspended and log "Transfer while suspended". system_freezable_wq (or PM callbacks that stop and restart the poll) avoids it. It's the same kind of race as your touch fix.
  • Wireless: status is Discharging whenever CHGIN_OK is clear. The 9a has a wireless receiver (WCIN_OK is bit 5 of the same register), so on a pad it would read Discharging while charging, if the receiver charges without its own driver. Does it?
  • CHGCC at the ends: Google decodes 0 as 0, 1-2 as 133 mA, and caps at 4 A from 0x3c; here those read 200 mA and up to about 4.2 A. The normal range agrees.
  • The binding could allow an optional interrupts, since the charger has them through the PMIC's interrupt controller, even if the driver polls for now. A sentence in the description on why the charger is its own I2C client rather than a cell of a MAX77779 MFD (as upstream does for the MAX77759) would help later.
  • Please cite the Google files you took the fields from with a commit or blob id.

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

Thanks, all of it is in. Force-pushed, rebased onto today's omamobile:

  • Inhibit vs reboot: probe takes held and the behaviour from the mode it reads, so mode 4 gives inhibit-charge and "Not charging", and auto restores mode 5. A .shutdown puts mode 5 back when held. On the 9a I set mode 4 by hand and probed: it read inhibited, and auto gave mode 5. Unbinding while inhibited leaves mode 5. I'll post what CNFG_00 reads after a warm reboot with mode 4 set at my next reboot.
  • CHGPROT: you're right. On the 9a a mode write with CHGPROT closed (CNFG_06 0x00) took effect (0x05 to 0x04, then back). Both CNFG_06 writes are gone, CNFG_00 is the only writeable register, and the wording is fixed.
  • Teardown: the restore action is registered before devm_power_supply_register() and the poll cancel after it, so the unwind is poll stopped, then supply gone, then charging back.
  • Workqueue: the poll is on system_freezable_wq.
  • Wireless: WCIN_OK counts as an input next to CHGIN_OK for online, status and type. I have no Qi pad here, so that's from the register, untested.
  • CHGCC: decoded as Google's driver does: 0 off, 1-2 133 mA, then 66.67 mA steps, and 4 A from 0x3c.
  • Binding: an optional interrupts, and a sentence on why the charger is its own I2C device.
  • Sources: Link: lines to max77779_charger.c and max77779_v20240115_regs.h at bms 183509aff980.

checkpatch --strict: the driver commit is clean, and the binding commit has only the MAINTAINERS note. The driver builds with W=1, and dt_binding_check passes.

@W4HO-ham
W4HO-ham force-pushed the tegu-max77779-charger branch from 7c996ff to fedd32b Compare October 27, 2026 20:14
@derekross

Copy link
Copy Markdown
Owner

Thanks for working through all of it so quickly. I went through the new diff point by point. Probe takes the inhibit from the mode it reads, .shutdown puts charging back, the CHGPROT writes are gone (and Google's max77779_chg_is_protected() agrees that CNFG_00 isn't protected), the teardown order and the freezable workqueue are right, WCIN_OK counts as an input, and the CHGCC decoding now matches Google's getter exactly. The binding change and the Link: lines are there too. The warm-reboot read of CNFG_00 is welcome whenever you reboot next, but with the shutdown restore it no longer holds anything up.

One small fix to the message before I merge: in the driver commit there's a blank line between the two Link: lines and Signed-off-by:, so git treats only the sign-off as a trailer and the links land as body text (git log -1 --format=%B | git interpret-trailers --parse shows it). Dropping that blank line is all it needs.

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

The warm-reboot measurement you asked for: with CHG_CNFG_00 set to mode 4 by hand (0x04, read back), then a warm reboot of the 9a, CHG_CNFG_00 read 0x05 at 56 s of uptime, before any charger driver was loaded. So on this palmtop something before Linux (the bootloader or the PMIC's reset) puts the charger back to charge and buck across a warm reboot. The .shutdown restore and taking the hold from the mode found at probe stay, for a kernel-only reset (kexec) or another bootloader.

The MAX77779 power management IC's switching charger sits on the same
I2C bus as its fuel gauge (maxim,max77779-fg), at 0x69. It charges the
battery from USB and powers the system; the gauge names it in its
power-supplies.

Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
@W4HO-ham
W4HO-ham force-pushed the tegu-max77779-charger branch from fedd32b to 47dd225 Compare October 28, 2026 01:03
@derekross

Copy link
Copy Markdown
Owner

Thanks for the warm-reboot measurement. Reading 0x05 at 56 s, before any charger driver loaded, settles it: on the 9a something before Linux puts the charger back into charge-and-buck mode. Keeping the .shutdown restore and the probe-time hold for kexec or another bootloader is the right call.

The blank line is still there in last night's rebase, though. The driver commit's message is unchanged, so git log -1 --format=%B 47dd22519e51 | git interpret-trailers --parse still lists only the Signed-off-by:, and the two Link: lines would land as body text. Dropping that one blank line is all it needs, and then I'll merge. If it's easier, I can drop it myself and push to your branch, since the PR allows maintainer edits. Just say which you prefer.

Add a driver for the MAX77779's charger, which the Pixel 9a runs under
its OTP defaults. It reports whether an input (USB or the wireless
receiver) is present, the charge status and type from CHG_DETAILS_01,
the input current limit and the charge current, and supplies the fuel
gauge, so the battery's status follows the charger.

charge_behaviour inhibit-charge stops charging: the charger goes to
buck-only mode (CHG_CNFG_00 mode 4; that register isn't behind CHGPROT)
and USB powers the system, though near full the battery still supplies
part of the load; auto, unbinding and shutdown put it back in charge-
and-buck mode. An inhibit survives a warm reboot, since the PMIC stays
powered, so probe takes the inhibit state from the mode it finds.
Nothing else is written, and the interrupt registers (clear on read) are
not read: the state is polled every 10 s.

Tested on the Pixel 9a, with the device created at 0x69 by hand in place
of the out-of-tree driver it replaces: online, status, charge type,
input current limit (1.5 A) and charge current read as the chip reports
them; inhibit-charge gives "Not charging" (mode 4) and auto "Charging"
(mode 5) again; unbinding while inhibited leaves mode 5; and probing
with the charger found in mode 4 reports inhibit-charge and "Not
charging", and auto then restores mode 5. At 99 % the battery still gave
about 450 mA while inhibited, measured the same way with the out-of-tree
driver. The gauge's link to the charger comes from the DT and was not
part of this test.

Register fields from Google's MAX77779 charger driver and register
header.

Link: https://android.googlesource.com/kernel/google-modules/bms/+/183509aff980610401869deca9f6ce8836980fe7/max77779_charger.c
Link: https://android.googlesource.com/kernel/google-modules/bms/+/183509aff980610401869deca9f6ce8836980fe7/max77779_v20240115_regs.h
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
@W4HO-ham

Copy link
Copy Markdown
Contributor Author

Thanks, I dropped the blank line myself (97e64a8). git interpret-trailers --parse now lists both Link: lines and the Signed-off-by:. The tree is unchanged.

@W4HO-ham
W4HO-ham force-pushed the tegu-max77779-charger branch from 47dd225 to 97e64a8 Compare October 29, 2026 01:49
@derekross

Copy link
Copy Markdown
Owner

Thanks, that's it. git interpret-trailers --parse on 97e64a8 now lists both Link: lines and the Signed-off-by:, and the tree is identical to the one I reviewed last time (same tree object as 47dd225). The gate is clean on today's omamobile: it merges cleanly, the sign-offs, prefixes and checkpatch pass (the one MAINTAINERS warning on the binding commit is expected, since the driver commit adds the entry), the W=1 build is clean, and CI ran dt_binding_check. Nothing changes for the Pixel 7 Pro: it's a new driver whose symbol isn't in our config, and no board has the node.

I'll rebase-merge this now. #124 carries these two commits, so once this lands, it needs a rebase onto omamobile before it can merge. I can do that myself through maintainer edits if you prefer.

@derekross
derekross merged commit 2a318a9 into derekross:omamobile Oct 29, 2026
1 check passed
derekross added a commit to derekross/omarchy-mobile that referenced this pull request Oct 29, 2026
The matrix after the merges since #118, with each cell going by the
merged notes:

- Pixel 7 (panther): the board file (derekross/linux-omarchy-mobile#108) and the
  FT3658 touch driver (derekross/linux-omarchy-mobile#109) have merged
  into the published kernel, so Boot, Storage, Buttons and USB net say
  "in the published kernel" instead of "in review". Touch stays "no":
  the driver and the touch rails are published, but the board file has
  no touch node, and panther's notes end at boot 8 with the controller
  not answering. BRINGUP-M1's status and NOTES' header say the same.
- Pixel 6 Pro (raven), Charging: no -> works. device-raven 0.1.26 (#112,
  #126) loads the MAX77759 charger at boot with its temperature guard;
  USB-PLAN section 4 records C0-C5 passed on 2026-10-28, a full charge to
  100 % included. The battery node is derekross/linux-omarchy-mobile#112;
  the runs were on an unpublished integration kernel, and the cell says so.
- raven, Torch: still works; the LED's node is now in the published
  kernel (derekross/linux-omarchy-mobile#113), tested on
  omamobile-gs101-torch and not yet run from the published kernel.
- Pixel 9a (tegu), Fingerprint: no -> WIP. FINGERPRINT-PLAN records F0
  and F2-F6b passed on an unpublished kernel: Trusty's TA runs and the HAL
  sees the sensor; enrollment waits for the factory calibration (F6c).
  omamobile-fingerprint 0.1.10 (#101) maps Trusty's stores for it.

Left as they were: tegu's Charging (the MAX77779 charger driver,
derekross/linux-omarchy-mobile#92, is published, but tegu's notes record
no run of it), the gs201 HSI2 pin controller
(derekross/linux-omarchy-mobile#123, no cell), felix (#35 is a plan) and
cheetah (nothing merged for it).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.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.

2 participants