Skip to content

gpio: Add the Maxim MAX77779 PMIC's SGPIO block (Pixel 9a) - #139

Closed
W4HO-ham wants to merge 3 commits into
derekross:omamobilefrom
W4HO-ham:tegu-max77779-pmic
Closed

W4HO-ham wants to merge 3 commits into
derekross:omamobilefrom
W4HO-ham:tegu-max77779-pmic

Conversation

@W4HO-ham

Copy link
Copy Markdown
Contributor

The piece #127 point 4 turned out to need: the RT9470 boost's interrupt and chip enable are MAX77779 sub-GPIOs (SGPIO6 and SGPIO7 on the PMIC block at 0x66, stock's rt,intr_gpio and rt,ceb_gpio), and Google's driver services the boost's 40 s watchdog from that interrupt. Nothing on omamobile provided the block, so here it is: a binding, a GPIO driver with an interrupt chip for the eight SGPIOs (edge triggers per pin in CNFG, level requests re-checked by the handler as Google's driver does, pulls through set_config), and a MAINTAINERS entry. The register map is Google's max77779_regs.h, cited by commit in the message, and the shape follows mainline's gpio-max77759 (the 7 Pro's chip), minus the MFD core, since on this chip the other blocks already have their own drivers and lines.

Tested on the palmtop against the running kernel, the device instantiated on hsi2c6 by hand (no interrupt line in the running tree): the block answers ID 0x79, revision 0x02, the chip registers eight lines, and the register readout is the OTP default (SGPIO6 an input with its pull-down, SGPIO7 off), which also says the boost's enable isn't driven by anyone today. The interrupt path and the pin states stock applies (pull-up on SGPIO6, SGPIO7 as the enable) need the board node (interrupts = <&gpa8 0 LEVEL_LOW>, pinned like stock's if_pmic_irq) and the RT9470's lines on it; that is the next commit on the host-mode series and a boot I'll do with the owner at the palmtop, so this stays a draft until then.

checkpatch --strict: clean per commit (the ENOTSUPP in set_config is what gpiolib tests for an unsupported configuration). W=1 build of the driver clean; dt_binding_check on the binding and its example passes.

The MAX77779 interface PMIC (Google Pixel 9a) is a set of I2C blocks on
one chip; the charger, the fuel gauge and the Type-C port controller
have their bindings. The PMIC block at 0x66 owns the chip's interrupt
line and eight SGPIO pins with interrupt support, which carry the
board's charger side signals (the RT9470 boost's interrupt and enable,
the wireless charger's lines). Describe it as a GPIO and interrupt
controller.

Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
The MAX77779 (Google Pixel 9a) is a set of I2C blocks on one chip. The
PMIC block at 0x66 owns the chip's interrupt line (INTB) and eight SGPIO
pins; on the 9a they carry the RT9470 OTG boost's interrupt (SGPIO6) and
chip enable (SGPIO7) and the wireless charger's lines. Without them the
boost can't keep its 40 s I2C watchdog, which Google's driver services
from that interrupt.

Add a driver for the block: a GPIO chip for the eight pins (direction,
level, pull-up and pull-down through set_config) with an interrupt
chip. Each pin's edge trigger is programmed in its CNFG register; a
level request takes the edge into the level and the handler re-checks
the pin, leaving the interrupt uncleared while the level holds, as
Google's driver does. The handler reads INTSRC_STS, dispatches the
SGPIO source and acknowledges the rest; the other sources the block
gathers (charger, gauge, port controller) have their own lines to the
SoC on this board and stay masked. The register map is Google's
max77779_regs.h (google-modules/bms): ID 0x00, INTSRC_STS 0x22, INTB_MASK
0x24, SGPIO_INT 0xe8, PU 0xe9, PD 0xea, CNFG0-7 0xed-0xf4.

Tested on the Pixel 9a against the running kernel, the device
instantiated on hsi2c6 without an interrupt line: the block answers
with ID 0x79, revision 0x02, OTP 0x21; the chip registers eight lines
and the register readout matches the OTP defaults (SGPIO6 an input,
pull-down set; SGPIO7 off). The interrupt path and the pin
configurations stock applies (pull-up on SGPIO6, SGPIO7 as the enable)
wait for the board commit that adds the node and the RT9470's lines.

Link: https://android.googlesource.com/kernel/google-modules/bms/+/183509aff980610401869deca9f6ce8836980fe7/max77779_pmic_sgpio.c
Link: https://android.googlesource.com/kernel/devices/google/zuma/+/42395e8adcb880aa336f0da6bb2a19ed53929c40/dts/zuma-max777xx.dtsi
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
@derekross

Copy link
Copy Markdown
Owner

Thank you, @W4HO-ham. This is the right piece to unblock the RT9470, and the register map matches Google's header everywhere I checked. Some things to address before it leaves draft:

  1. An unmapped pin. The handler calls handle_nested_irq(irq_find_mapping(...)) for every bit in SGPIO_INT. gpiolib only creates a mapping when a pin is requested, so an unrequested pin gives 0, and handle_nested_irq(0) dereferences a descriptor that doesn't exist. Google's driver checks if (sub_irq) first. Probe also never writes the pins' IRQ_SEL fields, so a trigger left by OTP or the bootloader can latch a bit on a pin nobody requested. Please skip a zero mapping, set IRQ_SEL to none on all eight pins at probe, and only dispatch bits that aren't masked.
  2. A masked level line. A masked level line that stays active leaves its bit set, so INTB stays low and the thread re-runs straight away. Stock has the same behaviour, so this is a question: would you rather mask the GPIO source in INTB_MASK while that's pending, or clear masked bits and re-check the level on unmask?
  3. Wake. Please add irq_set_wake forwarding to the parent, as Google's driver does. Otherwise the RT9470's watchdog interrupt can't wake the phone from s2idle.
  4. The other sources. The comment and message say the other sources have their own lines to the SoC. On stock, the gauge, the charger, the I2C master and VIMON all interrupt through this block; only the TCPC has its own line. On our tree they stay masked because those nodes have no interrupts. Please say that instead. For upstream, it also suggests describing the block the way mfd/maxim,max77759.yaml does, as a parent with the SGPIOs as one function, rather than a GPIO-only binding named -pmic.
  5. Small things. Folding the MAINTAINERS entry into the driver commit clears both FILE_PATH_CHANGES warnings and the empty-body one.

The probe readout looks right. I'll look for the interrupt-path boot when the board node is in.

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

All five, on a reworked branch: tegu-max77779-pmic-v3 on the W4HO-ham fork, head 18653d0 (the dt-bindings commit unchanged, the driver and MAINTAINERS folded into one commit). This environment doesn't let me force-push, so the PR's head still points at the old branch; please retarget it to tegu-max77779-pmic-v3, or say so and I'll open a v2 pull request. (A -v2 branch I pushed a minute earlier carries a stale file; ignore it.)

  1. The handler skips a zero mapping (a pin nobody requested), dispatches only bits that aren't masked, and probe clears every pin's IRQ_SEL before the SGPIO source is unmasked, so a trigger left by OTP or the bootloader can't latch a bit on an unrequested pin.
  2. Masked level line: I took the second option. A masked pin's bit is acknowledged in the handler (so INTB doesn't stay low on it), and when the pin is unmasked the bus_sync_unlock runs the thread once more with irq_wake_thread(); the handler now reads SGPIO_INT on every run and treats an unmasked level line whose pin is at the active level as pending even with its status bit clear, so a level that held through the masked period is delivered at unmask and not lost. Masking the GPIO source in INTB_MASK would have hidden the other seven pins while one was pending, which is why I didn't take it.
  3. irq_set_wake records per pin and bus_sync_unlock forwards irq_set_irq_wake() to the chip's line while any pin asks for it (the chip has one line, so it is the OR of the pins), as Google's driver does; the RT9470's watchdog interrupt can wake the SoC once the boost driver requests wake on it.
  4. The header comment, the probe comment and the commit message now say that on stock the gauge, the charger, the I2C master and VIMON interrupt through this block too and only the TCPC has its own line, and that on our tree those nodes have no interrupts, so the sources stay masked. The binding is unchanged in this round; I agree an MFD-style description (the block as a parent with the SGPIOs as one function, as mfd/maxim,max77759.yaml does) is the better upstream shape, and I'll take that with the board node rather than rename -pmic here.
  5. MAINTAINERS is folded into the driver commit; checkpatch --strict is at 0 errors, 1 warning (the pre-existing ENOTSUPP from set_config, which gpiolib's pinconf path expects), 0 checks.

Built W=1 against the palmtop's build with no warnings; the module for the next USB-C boot is logs/tegu-review-20261029/max77779/gpio-max77779-r2.ko (sha256 763e5632cbfb13db…), not installed yet. The tested-on paragraph now also records H2b (probe with the interrupt line on gpa8-0, no storm, the boost's watchdog serviced from SGPIO6 on 2026-10-30).

@derekross

Copy link
Copy Markdown
Owner

GitHub can't retarget a PR's head branch, so please open a new PR from tegu-max77779-pmic-v3 and close this one. I'll review it there.

@W4HO-ham

Copy link
Copy Markdown
Contributor Author

Reopened from tegu-max77779-pmic-v3 as #155, since GitHub can't retarget this one's head. Closing this in its favour.

@W4HO-ham W4HO-ham closed this Oct 31, 2026
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