Skip to content

power: supply: max77779: Supply VBUS for USB host mode - #124

Open
W4HO-ham wants to merge 2 commits into
derekross:omamobilefrom
W4HO-ham:tegu-max77779-otg-vbus
Open

W4HO-ham wants to merge 2 commits into
derekross:omamobilefrom
W4HO-ham:tegu-max77779-otg-vbus

Conversation

@W4HO-ham

Copy link
Copy Markdown
Contributor

Stacked on #92 (the MAX77779 charger); only the last commit is new.

This adds a chgin-otg regulator that a Type-C controller can use as its vbus-supply. With an external boost (otg-boost-supply, the Pixel 9a's RT9470), the charger goes to standby and then the boost is enabled, the order Google's ext-otg-only use case uses. Without an external boost it uses the charger's own boost mode (0xa). Charge inhibit is refused while VBUS is out, and unbinding the driver turns VBUS off and charging back on. The binding gains otg-boost-supply and the chgin-otg-regulator child.

Tested on the Pixel 9a (7.3.0-rc6-omamobile-tegu-s2mpg15-m1-g991042e2eff3-dirty, the integration tree):

  • Setup: TCPM ran the port as dual-role (try sink, source PDO 5 V 900 mA) with vbus-supply pointing at this regulator, and a graph to dwc3's role switch.
  • Drive in: a USB flash drive attached as source (SRC_READY), VBUS held at 5.2 V, the data role went to host, and the drive enumerated at high speed (sde: sde1 sde2).
  • Laptop back in: the port was a sink again, with a PD contract and the gadget configured.
  • After a fresh boot: the same again.

The RT9470's boost needs its JEITA control and I2C watchdog off for VBUS to hold, as Google's rt9471_charger sets them on the 9a. That's for the boost's own driver and the board DT, which follow in separate PRs (the plan is mainline rt9471 with its OTG regulator).

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

A question on the boost side, before I write its PR. On the 9a, VBUS only held once the RT9470's JEITA control (0x0c bit 7) and its I2C watchdog (0x01 bits 1:0) were off. That's what Google's rt9471_charger does: no en-jeita, and the watchdog only runs while that driver kicks it.

Mainline's rt9471 already writes JEITA off in its init sequence (REG_SEQ0(RT9471_REG_JEITA, 0x38)) and has an otg-vbus regulator. But it requires an interrupt (devm_regmap_add_irq_chip on i2c->irq) and kicks the watchdog from that interrupt. On the 9a, the RT9470's INTB goes to a MAX77779 sub-GPIO (max77779_sgpio 6 in Google's DT), which nothing in our tree provides yet. The driver would also register a second charger power supply and start BC1.2 detection, on a chip that's a secondary buck charger here.

Two ways I can see:

  • (a) Make mainline rt9471's interrupt optional, writing the watchdog off when there's none. Then the board DT gets a richtek,rt9471 node with otg-vbus feeding this regulator's otg-boost-supply.
  • (b) A small OTG-only binding/driver for this use.

(a) looks more upstream-friendly to me, but it hands the RT9470's charging to Linux. Which would you prefer? Until then the palmtop runs a bring-up module that writes only OTG_EN, JEITA_EN and the watchdog bits.

@derekross

Copy link
Copy Markdown
Owner

Thanks for this, and for getting host mode working end to end on the 9a. The design follows Google's closely, and I checked it against their sources. On the 9a, zumapro-tegu-usecases.dtsi sets max77779,ext-otg-only and max77779,extbst-ctl = <&rt9471_gpio 0 …> ("RT9470 USB_OTG"). In max77779_usecase.c, leaving USB charging for OTG goes through standby (MAX77779_CHGR_MODE_ALL_OFF) whenever extbst-ctl is set, and only then raises the external boost. So your mode 0 followed by the boost is their order, and 0xa is their OTG_BOOST_ON. Only CHG_CNFG_00 is writable, inhibit is refused while VBUS is out, and the gate is clean: the merge onto today's omamobile is clean, the sign-offs and checkpatch pass, the W=1 build is clean, and CI ran dt_binding_check. Nothing changes for the Pixel 7 Pro: it's a new file whose symbol isn't in our config, and no board has the node.

There are three things I'd like changed before it merges:

  1. Unbinding with host mode on uses the boost after it's been freed. devm_add_action_or_reset(dev, max77779_charger_restore, chg) is registered before devm_regulator_get_optional(dev, "otg-boost"), and devres unwinds in reverse. On unbind, the core therefore regulator_put()s the boost first: it warns on the enable count, frees the consumer and leaves the boost on. Then max77779_charger_restore() calls regulator_disable(chg->boost) on the freed consumer and puts the charger back to mode 5 while the boost still drives CHGIN. The commit says "unbinding turns VBUS off", but your tests cover unbinding only while inhibited (power: supply: Add the Maxim MAX77779 charger #92). Could you get the boost before registering the restore action (and keep the "Unwound in reverse" comment true), then run one unbind with the drive attached? I'd expect a clean kmsg, VBUS at 0 and CHG_CNFG_00 reading 0x05 afterwards. .shutdown is fine as it is, since nothing is released there.

  2. Please put the binding change in its own commit, before the driver (dt-bindings: power: supply: maxim,max77779-charger: …). That's CONTRIBUTING §6.2's order, and checkpatch flags it too (DT_SPLIT_BINDING_PATCH).

  3. Please don't let the board DT turn VBUS on by itself. chgin-otg-regulator takes everything in regulator.yaml. With regulator-always-on or regulator-boot-on, the regulator core enables it at registration, which would boost into whatever is plugged in, outside TCPM's vSafe0V check (tcpci_maxim sets vbus_vsafe0v). Two lines in the child schema close that off:

        properties:
          regulator-always-on: false
          regulator-boot-on: false

Smaller points and questions:

  • The charger's own boost (0xa) has never run. On the 9a, Google writes 0xa only for fast role swap, and they set the OTG current limit (CHG_CNFG_05) first. I'd rather not merge a boost mode nobody has run: could the regulator refuse to enable without otg-boost-supply until a board needs the internal boost? If you'd rather keep it, please say in the message that it's untested.
  • What did online and status read while the drive was attached? If CHGIN_OK follows our own VBUS in mode 0, the supply would report an input and "Not charging" while the battery is actually feeding the drive. Reporting offline and Discharging while chg->otg is set would be more honest to upower.
  • Optional defence in depth: you could refuse to enable when CHGIN_OK is already set, meaning someone else drives VBUS. TCPM covers a normal attach; fast role swap doesn't wait for vSafe0V, though that only matters if the board enables FRS.
  • Evidence: the release is the -dirty integration tree. Please give the blob id of the max77779_charger.c you tested (git rev-parse HEAD:drivers/power/supply/max77779_charger.c there) and a tools/phone-smoke report from the 9a on that kernel. It would also help to publish the RT9470 bring-up module and the TCPC DT you tested with, on a branch or as a draft PR, so the setup can be reproduced.
  • Please add Link: lines for the use case claim (max77779_usecase.c at the commit you already cite, and tegu's zumapro-tegu-usecases.dtsi).
  • Nits: the code comment says RT9471 where the commit says RT9470 (the chip is the RT9470, run by Google's rt9471 driver). MAX77779_MODE_OTG_BOOST has one tab too many.
  • This is stacked on power: supply: Add the Maxim MAX77779 charger #92, whose driver commit still has the blank line before Signed-off-by:, so the Link: lines aren't trailers. Once power: supply: Add the Maxim MAX77779 charger #92 is amended, please rebase this onto it. I'll merge power: supply: Add the Maxim MAX77779 charger #92 first, then this.

On your RT9470 question, I'll answer (a) versus (b) separately. Here are some facts that matter for both. Mainline rt9471 already resets the chip at probe (REG_INFO 0x80) and then writes the watchdog off (REG_TOP 0xC0) and JEITA off (REG_JEITA 0x38), so with (a) the interrupt is the only thing in the way. It also requests charge-enable-gpios asserted, which would start the RT9470 charging where Google drives CE from the MAX77779's sGPIO 7. Google keeps the watchdog at 40 s (wdt = <40>) and kicks it. With the watchdog off, something else has to turn the boost off after a crash. Could you measure that, the way you did for #92? Turn host mode on, warm-reboot, then read the RT9470's OTG enable bit and ICSTAT before any driver loads. If the boost survives, VBUS stays out after the reset, and a charger plugged in then would meet it.

@W4HO-ham
W4HO-ham force-pushed the tegu-max77779-otg-vbus branch from 5bf729f to 4970bcd Compare October 29, 2026 01:53
@W4HO-ham

Copy link
Copy Markdown
Contributor Author

Thanks, all of this is in the new push, rebased onto #92's amended head (97e64a8):

  1. Unbind order: the boost is now got before the restore action is registered, and the comment above it gives the whole unwind order. I haven't yet run the unbind with the drive attached. That needs the cable swap, so it waits until W4HO is at the palmtop. I'll post kmsg, VBUS and CHG_CNFG_00 from that run here.
  2. Binding split: dt-bindings: power: supply: maxim,max77779-charger: Add the OTG VBUS regulator (467db7d) comes before the driver now.
  3. No VBUS from the board DT: the child schema sets regulator-always-on: false and regulator-boot-on: false. I also added dependentRequired: chgin-otg-regulator: [ otg-boost-supply ], because of the next point.

Smaller points:

  • Internal boost: dropped. The regulator returns -EOPNOTSUPP without otg-boost-supply, MAX77779_MODE_OTG_BOOST is gone, and the message says why.
  • online and status: I didn't record what they read while the drive was attached. While chg->otg is set, the supply now reports online 0 and Discharging.
  • Defence in depth: taken. Enable returns -EBUSY when CHGIN_OK is already set.
  • Evidence: the module on the palmtop wasn't built from this branch. It came from a superset of the driver (blob 1c71542965b0: this PR's file plus step charging, the charge thresholds and the Type-C input limit, none of them posted yet). Its OTG code is the same as the PR head before this push (f70a184098c3). The new head builds clean with W=1 against the palmtop's tree, checkpatch --strict is clean on both commits, and dt-doc-validate and yamllint pass on the schema. A full dt_binding_check here stops in dtschema 2026.04 on an unrelated schema (ti,pruss-intc.yaml), so I'm relying on CI for that. The smoke report and the unbind run will come from the palmtop on this exact source.
  • Links: both Link: lines are on the driver commit, and the use case link is also on the binding commit.
  • Nits: RT9471 is now RT9470 in the comment, and the extra tab went with the define.
  • Warm reboot with host mode on: not measured yet. Until it is, the RT9470's OTG bit after a warm reboot is unknown. I'll do it in the same attended run: host mode on, warm reboot, then read the OTG enable bit and ICSTAT before any driver loads.

The TCPC DT and the RT9470 bring-up module will go up as a draft PR with a runbook, as you asked on #131.

@derekross

Copy link
Copy Markdown
Owner

Thanks for working through all of it so quickly. I went through the new push point by point against the code:

  1. Unbind order: fixed. The boost is now got before the restore action is registered, so devres unwinds in this order: the VBUS regulator, the poll, the supply, then the restore (boost off, mode 5), and only then the boost is put. The comment matches that order. Still open: the unbind with the drive attached. As you say, that waits for the attended run.
  2. Binding split: done. 467db7d comes before the driver, and checkpatch no longer reports DT_SPLIT_BINDING_PATCH.
  3. No VBUS from the board DT: done, and dependentRequired on otg-boost-supply is a good addition.
  • Internal boost: gone. Enable returns -EOPNOTSUPP without the external boost, and the message says why.
  • online and status: while chg->otg is set, they report 0 and Discharging. Good.
  • CHGIN_OK check: taken. It also helps in a case I hadn't thought of: if a crash ever leaves the RT9470's boost on, CHGIN reads an input and host mode is refused until it's off.
  • Links and nits: all in.
  • Blob ids: f70a184098c3 is the round-one head's max77779_charger.c, as you say. 1c71542965b0 isn't in any public tree, so the 10-28 run covers the earlier OTG code only. That's fine, since you've said so.

Gate on today's omamobile: the merge is clean, the sign-offs and prefixes pass, checkpatch --strict has only the MAINTAINERS note on #92's binding commit, the W=1 build is clean, and CI ran dt_binding_check. Nothing changes for the Pixel 7 Pro.

What's left before it merges is the run on this exact source. The code now differs from what ran on 10-28 in ways that matter at runtime: the CHGIN_OK check sits in front of every enable, and the unwind order is new. From a kernel built from 4970bcd (or with its max77779_charger.c, blob 6e30a6b53130), I'd like to see:

  • one host-mode attach (the drive enumerates, and the mode field of CHG_CNFG_00 reads 0 while it's attached);
  • one unbind of the charger with the drive attached, with kmsg, VBUS and CHG_CNFG_00 afterwards. I'd expect a clean kmsg, VBUS at 0 and mode 5. If TCPM is unbound first through the vbus-supply device link, please say so: that's fine too, just a different path from the one the restore action covers;
  • a tools/phone-smoke report from that boot.

The "Tested on the Pixel 9a" paragraph will be accurate once that's in.

Two small things you can fold into the same push, neither blocking:

  • The check refuses on WCIN_OK too, so host mode is refused on a wireless charger. That's the cautious choice, and I'm happy with it, but the message says "while CHGIN already has an input" and the comment says "Something else already drives VBUS". Please mention the wireless input in one of them.
  • Enabling and disabling the regulator changes online and status without a power_supply_changed(). Upower only notices when the poll next sees CHG_INT_OK or the charge details change. One call after each chg->otg change would fix that.

Merge order: #92 goes in first (it's ready), then this one, rebased onto it, once the run above is posted. On (a) versus (b) for the RT9470, I'll answer separately, as I said.

…regulator

Describe the charger's chgin-otg regulator, VBUS out of CHGIN for a device
on the USB port, and the external boost it uses (otg-boost-supply), as on
the Pixel 9a, where Google's ext-otg-only use case puts the charger in
standby and raises an RT9470 boost.

Only the Type-C controller may turn VBUS on, after its vSafe0V check, so
the regulator may not be always-on or boot-on. The regulator needs the
external boost: the charger's own boost mode is not supported.

Link: https://android.googlesource.com/kernel/google-modules/bms/+/183509aff980610401869deca9f6ce8836980fe7/max77779_usecase.c
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
Add a chgin-otg regulator for the Type-C controller's vbus, over an
external boost (otg-boost-supply). Enabling it puts the charger in standby
(mode 0) and then enables the boost, the order Google's ext-otg-only use
case uses on the Pixel 9a, whose boost is an RT9470; disabling it reverses
that. The charger's own boost mode (0xa) is not used: Google writes it on
the 9a only for fast role swap, after setting the OTG current limit, and
nothing here has run it, so the regulator refuses to enable without the
external boost. It also refuses while CHGIN already has an input, so it
never boosts into another source.

While VBUS is out, CHGIN carries our own boost, so the supply reports no
input and Discharging rather than what CHGIN_OK says. Charge inhibit is
refused then.

The boost is got before the restore action is registered, so on unbind
the boost is turned off and charging restored before the boost consumer
is put.

Tested on the Pixel 9a: with TCPM as a dual-role port whose vbus-supply is
this regulator (over the RT9470's OTG boost), a USB flash drive attaches
as source, VBUS holds at 5.2 V, and the drive enumerates at high speed;
with the drive out and a laptop back in, the port is a sink again and
charges.

Link: https://android.googlesource.com/kernel/google-modules/bms/+/183509aff980610401869deca9f6ce8836980fe7/max77779_usecase.c
Link: https://android.googlesource.com/kernel/devices/google/tegu/+/6276884d9940694b25a6934671918ec8ac412ee8/dts/zumapro-tegu-usecases.dtsi
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
@W4HO-ham
W4HO-ham force-pushed the tegu-max77779-otg-vbus branch from 4970bcd to 66203ab Compare October 31, 2026 02:39
@W4HO-ham

Copy link
Copy Markdown
Contributor Author

Rebased onto today's omamobile. The MAX77779 charger driver and its binding are in omamobile now and dropped out; the OTG VBUS regulator binding and the VBUS commit remain, unchanged. checkpatch clean; not rebuilt here (no build container on this machine).

W4HO-ham added a commit to W4HO-ham/linux-omarchy-mobile that referenced this pull request Oct 31, 2026
…not for merge)

The setup behind the 10-28 host-mode run on the Pixel 9a, published so
the run can be reproduced; not for merge. hsi2c10 with its pins and the
RT9470 as an OTG boost (omamobile,tegu-rt9471-boost, an undocumented
bring-up compatible, which checkpatch flags), the MAX77779 charger with
its chgin-otg regulator over that boost (derekross#124),
the TCPC as a dual-role port that prefers sink with chgin-otg as
vbus-supply, and the connector's graph to dwc3, which becomes an OTG
controller with a role switch.

The source PDO (5 V, 900 mA) is the run's value; it isn't traced to a
stock file yet.

Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
W4HO-ham added a commit to W4HO-ham/linux-omarchy-mobile that referenced this pull request Oct 31, 2026
… for merge)

The Pixel 9a's RT9470 charger, run by Google's rt9471 driver on stock,
used here only as the USB OTG boost: a regulator on OTG_EN (FUNCTION
0x02 bit 1) for the MAX77779 charger's chgin-otg regulator. Bring-up
only; its upstream shape (mainline rt9471, or an OTG-only driver) is
still open on derekross#124. The compatible,
omamobile,tegu-rt9471-boost, is undocumented, which checkpatch flags.

With the RT9470's JEITA control (0x0C bit 7) or its I2C watchdog (TOP
0x01 bits 1:0) on, VBUS collapsed under the boost within about 60 ms.
Enabling turns both off just before OTG_EN, and disabling clears OTG_EN
and puts both back as probe found them, so the chip runs without its
temperature cut-off only in host mode. Probe only reads.

Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
@derekross

Copy link
Copy Markdown
Owner

Thanks for the rebase; range-diff shows it's identical to what I reviewed. It's still waiting on the run on this exact source from my 10-29 comment (attach, unbind with the drive in, phone-smoke).

@W4HO-ham

W4HO-ham commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

A partial run on this PR's exact source today, so you know where it stands. The full run (attach, unbind with the device in, the reset with host mode on) is still to come, with a lighter USB device.

The kernel was today's omamobile with #156 and #178 for Wi-Fi (so the run could continue over Tailscale with the cable out), this PR's two commits (max77779_charger.c blob 6e30a6b53130, byte-identical to the head), and #127's RT9470 boost driver and host-mode DT, release 7.3.0-rc6-omamobile-push1-gdf0e73cf73ba. With the laptop in, the charger, tcpci_maxim and the boost bound, the port came up dual role as a sink, and tools/phone-smoke had every required row ok.

The only device to hand was a USB-C powered travel router (no USB stick on this trip). With it on the port, TCPM went TOGGLING, then SRC_ATTACH_WAIT, then the try-sink round, then SRC_ATTACHED. It turned VBUS on through chgin-otg (mode 0, then the external boost) and sent Source_Capabilities. 6 ms later the charger reported VBUS off, and VBUS read 1050 mV while the battery supplied about 830 mA. The router's inrush holds the RT9470 in its current limit, so VBUS never came up and the router never started. TCPM went back to SNK_UNATTACHED and tried again. Nothing faulted. I set port_type to sink, the port stopped sourcing, and the palmtop went back to the daily kernel with nothing left over. So the attach path, the regulator chain and VBUS off on a collapse all behave. What's still missing is a device the boost can carry, for the unbind with it attached and the reset read. I'll run those as soon as W4HO has a lighter device.

@derekross

Copy link
Copy Markdown
Owner

Thank you, @W4HO-ham, for the partial run and for saying plainly what it does and doesn't cover. max77779_charger.c at this head is blob 6e30a6b53130, so the run is on the exact source, and the boot's tools/phone-smoke report is one of the three things I asked for.

The router run tells us something useful too. TCPM turned VBUS on through chgin-otg, the RT9470 held its current limit when the router's inrush pulled VBUS down to about 1 V, the charger reported VBUS off, TCPM went back to unattached, and nothing faulted. Setting port_type to sink then stopped the retries. That's the overload path behaving as it should. It doesn't stand in for the attach, though, because VBUS never came up.

I re-ran the gate on today's omamobile (2219cc6cda77, the kernel-2026.11.01 tag): it merges cleanly, both commits are signed off, checkpatch --strict is clean, the W=1 build is clean, and CI's dt_binding_check passed on this head. Nothing here can bind on the Pixel 7 Pro, which has a MAX77759.

What's still needed before merge is the same as in my 10-29 comment, with a device the boost can carry. A USB stick, a keyboard or a mouse would all do.

  • one attach where the device enumerates, with the mode field of CHG_CNFG_00 reading 0 while it's attached;
  • one unbind of the charger with the device attached: kmsg, VBUS and CHG_CNFG_00 afterwards (I'd expect VBUS at 0 and mode 5; if TCPM is unbound first through the vbus-supply link, just say so);
  • the read after a reset with host mode on, as you planned.

Then please update the "Tested on the Pixel 9a" paragraph. It still describes the 10-28 run on the earlier code.

Two small points from 10-29 are also still open, if you're pushing anyway. Neither blocks the merge:

  • the enable refuses on WCIN_OK too, but the message says "while CHGIN already has an input" and the comment says "Something else already drives VBUS". Please mention the wireless input in one of them;
  • online and status change when chg->otg does, but nothing calls power_supply_changed(), so upower only sees it at the next poll. One call after each change would fix that.

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