Repository navigation
pinctrl: apple: use a four-bit GPIO mode on all SoCs - #2004
DjDeveloperr merged 2 commits into
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins. |
|
GREEN on 729b14a Checked the one-line diff against the file at this head and the claims against the code. Modes 0 to 7 unchanged: verified arithmetically - FIELD_PREP of any value 0-7 into GENMASK(4,1) produces the same v<<1 bit pattern as into GENMASK(3,1) (bit 4 is only reachable by values >= 8), so the written mode encodings are identical; the change affects only the clear side, where direction_input, direction_output and the IRQ-type setter now also clear bit 4 in the read-modify-write. The get_direction effect on a bit-4-set pin is exactly what the Not-checked section says: FIELD_GET over the widened mask returns a value that no longer equals REG_GPIOx_OUT (0x12 reads 9, not 1), so such a pin now reports not-output - and given the register evidence that DATA does not latch with the bit set, reading it as not a working output is the truthful direction. apple_gpio_get correspondingly takes the live-register path for such pins. The K114c read-backs in the commit message are self-consistent (0x474212 has bit 4 set and reads back unchanged when DATA is written; 0x474203 without the bit latches). The Validated-on section claims nothing beyond the register reads and the in-stack validation, and says plainly that the commit was not booted alone and no other Mac was run. Model: zai/glm-5.3 (live from lane_models.py this turn). |
|
GREEN on 729b14a Independent review. This is one fix in one file, and the commit and the PR text are clean: no hostnames, home paths or lab names. I read the driver at this head. I did not compile it: the local tree I had lacked the generated headers, and the PR already reports an object build. I did not boot anything. Whether the width is right on other SoCs is not something a reader can prove, so that is the first note. No blocking items. Non-blocking notes:
|
729b14a to
aea7476
Compare
|
GREEN on aea7476 Re-review at the scoped head, read against the file at this commit. The redesign addresses the reach concern from the earlier all-SoCs form the right way: bit 4 joins the mode mask only through a per-hw mode_hi flag on the new apple,t6050-pinctrl entry (a new of_match row with its own hw struct), so every other SoC keeps the exact three-bit behavior - the set of machines the bit was never checked on is no longer exposed. The mask helper (REG_GPIOx_MODE | mode_hi) feeds the same comparison and write paths as before, so the semantics I verified earlier carry: writes clear bit 4 on t6050, get_direction/get read a bit-4-set pin as not-output, and FIELD_PREP of modes 0-7 is unchanged. The commit message now carries the Tested line in the honest form: build-only on the M1 with and without the change, register read-backs from the K114c, the earlier all-SoCs form booted in the touch stack, and this T6050-only form explicitly not booted. Model: zai/glm-5.3 (live from lane_models.py this turn). |
|
GREEN on aea7476 Re-review after my earlier notes. Both are addressed. No blocking items. What I checked in
I did not compile or boot it. Non-blocking notes:
|
On the K114c the NUB GPIO block comes out of iBoot with bit 4 of the touch-screen reset and power pins set (0x474210, 0x474212 as read through /dev/mem). With that bit set, the DATA bit does not latch in output mode: writing 0x474213 reads back 0x474212, writing 0x474203 reads back 0x474203. direction_output wrote only bits 1-3 of the mode, so the pin stayed in a state where the driver's output value never took effect. Add a hw table entry for apple,t6050-pinctrl that treats bits 1-4 as the mode: direction_input, direction_output and the interrupt mode writes clear bit 4, and get_direction and get read it. Every other SoC keeps the three-bit mode, since the bit was not checked on them. Modes 0-7 are unchanged, and a working output (the PERST# pin of the K114c, register 0x00076a03) has the bit clear. Tested: drivers/pinctrl/pinctrl-apple-gpio.o builds with gcc 16.1.1 and W=1, no warnings, with and without the change, on a depth-1 checkout of integration/aurora (580e911) on a 13-inch M1 MacBook. The register read-backs above are from the 14-inch M5 Max MacBook Pro (K114c). An earlier form of this change (all SoCs, mode bits 1-4) was booted there in the touch screen stack; this T6050-only form was not booted. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
aea7476 to
a0609dc
Compare
joshuaswarren
left a comment
There was a problem hiding this comment.
GREEN on a0609dc
Model: cognition/swe-2-flash-medium
Full-file read at head. The mode_hi design is correct: pctl->mode_hi is set only when the hw table says so (t6050 gets apple_gpio_t6050_hw with no_regcache preserved; t8140/t8132 keep uncached_hw, t8103/pinctrl get NULL hw so the guard if (hw && hw->mode_hi) leaves mode_hi 0 and the mask is bit-identical to the old GENMASK(3,1)).
Every mode access now goes through apple_gpio_mode_mask: get_direction and get compare (reg & mask) == FIELD_PREP(REG_GPIOx_MODE, OUT) - for non-T6050 this is exactly the old FIELD_GET==1; for T6050 a set bit 4 reads as not-OUT, which matches the measured wedge (output value cannot latch while bit 4 is set). direction_input, direction_output, irq_mask, irq_unmask and irq_set_type all pass the widened mask to apple_gpio_set_reg -> regmap_update_bits, so bit 4 is cleared on every mode write while FIELD_PREP(REG_GPIOx_MODE, ...) still only sets bits 1-3. pinmux_set touches only PERIPH|INPUT_ENABLE, correctly outside the mode field.
Resume path checked: saved_valid only covers touched pins and regmap_write restores the full saved word; since driver writes now clear bit 4 before the value is saved, restore cannot resurrect the wedge on a pin the driver configured. Untouched pins are never saved or restored.
No other REG_GPIOx_MODE mask position remains unconverted (grep at head: all mask args use apple_gpio_mode_mask; remaining bare uses are FIELD_PREP values, correct). Disclosed risk stands: the T6050-only form was compile-checked, not booted - acceptable for review, the boot evidence belongs to the PR thread.
|
Thanks for the precise register read-backs. They make the touch-screen problem very clear. One request on scope. The four-bit mode is enabled only on T6050 match data ( The fix itself, clearing bit 4 when setting a pin's mode, looks harmless wherever bit 4 is part of the mode field. Could you either make the four-bit mode the default for every SoC, or keep the flag with a comment naming a known hardware difference on the older blocks? We are happy to run GPIO and boot rows on our M1 Pro, M2, M4 Pro and A18 Pro to check the wider change. |
|
[Joshua's agent] Replying to @RyanTheTide scope question. We will keep the four-bit mode behind What is measured (T6050 only, K114c): NUB touch reset/power pins left iBoot with bit 4 set (0x474210 / 0x474212 via What is not measured: GPIO mode read-backs on M1/M2/M3/M4/M5 Pro, or on the AP/AOP T6050 pinctrl nodes, for whether bit 4 is spare or re-used. We do not have a documented alternate meaning of bit 4 on older blocks—only absence of data. M1 was compile-only ( Why not default four-bit for every compatible yet: Making four-bit the default would apply bit-4 clear/read to every Mac that loads this driver without the read-backs above. The clearing operation is likely harmless if bit 4 is part of the mode field on those blocks, but we will not widen on that inference alone. Plan: Revise the PR text to say the flag marks where we have register proof, not "older SoCs differ." If your M1 Pro / M2 / M4 Pro / A18 Pro GPIO rows show bit 4 unused or matching this layout, we will either drop the flag or promote four-bit default in a follow-up with your numbers attached—whichever matches what you measure. This T6050-only head still needs a boot + touch check on K114c; read-backs above are from before the scoped patch landed. |
|
Thanks for separating what was measured from what was not. Under the convention here, a gate stays only for a known hardware difference (another meaning of bit 4, a different block revision, measured breakage); missing data on the other SoCs is not one. Since you are open to widening once there is data, we will take the bit-4 GPIO mode read-backs on our M1 Pro, M2, M4 Pro and A18 Pro and post them here. If they match your layout, could the four-bit mode become the default in this PR rather than a follow-up? If one differs, that result is the comment the flag needs. The K114c boot and touch check on this head is still open. |
|
[Joshua's agent] Replying to the 16:21 UTC question about scope. Yes. If your bit-4 mode read-backs on M1 Pro, M2, M4 Pro and A18 Pro match the T6050 layout (bit 1-4 mode field, PERPH at 6:5, PULL at 8:7, DATA does not latch while bit 4 is set), we will drop Status on our side: the K114c boot and touch check on aea7476 is still open; we will post the result here before widening, so the default-flip commit carries its own Tested line. |
|
Thanks, that plan works for us. Our bit-4 GPIO mode read-backs on the M1 Pro, M2, M4 Pro and A18 Pro are queued, and we will post them here. For each pin controller we will dump the mode word of every pin as iBoot left it, so it is clear where bit 4 is set. On one pin that is safe to toggle, we will check whether DATA latches with bit 4 set and with it clear. If they match, please flip the default in this PR as you describe. Please also update the description and commit text, which still say the other SoCs keep three bits "because bit 4 was not checked on them". On your side, the K114c boot and touch check should run on the head that gets merged. That means |
|
Bit-4 read-backs: config word of every pin on every enabled pin controller, read-only. On M1 Pro and M4 Pro the words come from the probe read-back; on A18 Pro they are live and match regmap. We skipped the DATA-latch toggle for safety: no bit-4 pin is a spare output.
No output-mode pin and no pin with a GPIO consumer has bit 4 set. PERIPH and PULL decode normally. Nothing shows bit 4 with another meaning, so this supports the four-bit default. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Thanks for the precise read-backs. The fix is right, and what's left is the gate.
Ryan's read-backs (04:25) cover T6000, T6040 and T8140:
- no pin with an output mode or a GPIO consumer has bit 4 set;
- nothing shows bit 4 with another meaning;
- the SMC pins at four-bit mode 15 still read as inputs under either mask.
That's the data your plan was waiting for. So please flip the four-bit mode to the default in this PR:
- drop
.mode_hiandapple_gpio_t6050_hw; - keep
apple_gpio_uncached_hwforapple,t6050-pinctrl; - update the commit text that says the other SoCs keep three bits because bit 4 wasn't checked.
The M2 read-back can come after the merge.
With that pushed and CI green, it merges, and #1605 follows it. These rows come after the merge, with a revert ready:
- the K114c boot and touch check on the merged head;
- the M2 read-back.
On the K114c (T6050) iBoot leaves bit 4 of the GPIO mode field set on the touch-screen pins, and while it is set the DATA bit does not latch in output mode. The previous commit handled that on the T6050 only, because bit 4 had not been read on other SoCs. Aurora has now read the mode word back on more parts (see the PR discussion): T6000 (M1 Pro) has 18 pins with bits 4:1 = 0b1111, all on the SMC block; T6040 (M4 Pro) has 9 pins with bit 4 set across NUB, AOP and AP blocks; T8140 (A18 Pro) has 19 AP pins with bit 4 set, four of them reading 0x00474210, the same word shape as the K114c touch pins. No read showed bit 4 used for anything but the mode field, and no output-mode or GPIO-consumer pin had it set, so clearing it is safe on every block this driver loads. T8112 (M2) is still unmeasured; the field reads as four bits on every SoC checked so far, so make that the default rather than a per-compatible flag. No DATA-latch toggles were performed on Aurora hardware to gather this evidence. Drop the mode_hi flag and the T6050 hw table entry; the mode mask is bits 1-4 unconditionally. The mode encoding is unchanged: values 0-7 still occupy bits 1-3. Tested: drivers/pinctrl/pinctrl-apple-gpio.o builds with clang 22.1.8, no warnings, on aarch64 against the PR tree. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Thanks. 5a1250e does what I asked:
.mode_hiandapple_gpio_t6050_hware gone, and the mode mask is bits 1-4 on every block;apple,t6050-pinctrlkeepsapple_gpio_uncached_hw;- the commit text now cites Ryan's T6000, T6040 and T8140 read-backs instead of saying bit 4 wasn't checked.
I checked every mode access in pinctrl-apple-gpio.c at this head. The input, output and three IRQ writes clear bit 4, and get_direction() and get() compare bits 1-4. Modes 0-7 encode as before, and bit 4 doesn't overlap PERIPH (6:5) or PULL (8:7). host-tests is green on this head, and the base hasn't touched the file since your merge base.
One optional follow-up: apple_gpio_mode_mask() now always returns the same value, so it could just become REG_GPIOx_MODE GENMASK(4, 1).
Merging. #1605 follows it. After the merge, with a revert ready:
- the K114c boot and touch check on the merged head;
- the M2 (T8112) read-back.
a96a64b
into
aurora-silicon:integration/aurora
|
Merged as a96a64b. The post-merge rows are in my review above, and a revert is ready if one of them fails. |
|
Late fourth row for the record (this PR is merged; nothing to change): M2 MacBook Air (J413, T8112), fleet kernel, pin config read through regmap debugfs. 309 pins over 4 controllers (24a820000: 54, 23e820000: 18, 23c100000: 213, 23d1f0000: 24). Bit 4 is set on 0 pins; only modes 0/1/3/7 appear and bits 31:24 are all 0. So the bit-4 decode has nothing to act on there, which matches the M1 Pro, M4 Pro and A18 Pro read-backs posted earlier. |
[Joshua's agent]
Split out of #1605 (the K114c touch screen), one fix per PR. #1605 lists this PR as a dependency.
On the K114c the NUB GPIO block comes out of iBoot with bit 4 of the touch-screen reset and power pins set (0x474210 and 0x474212, read through
/dev/mem). With that bit set the DATA bit does not latch in output mode: writing 0x474213 reads back 0x474212, while writing 0x474203 reads back 0x474203.direction_outputwrote only bits 1-3 of the mode, so the pin stayed in a state where the driver's output value never took effect.The mode field is bits 1-4 on every block this driver loads:
direction_input,direction_outputand the interrupt mode writes clear bit 4, andget_directionandgetread it. Modes 0-7 are unchanged, and a working output (the PERST# pin of the K114c, register 0x00076a03) has the bit clear. One file,drivers/pinctrl/pinctrl-apple-gpio.c.Changed after review: the first form made the mode four bits wide for every SoC; for a while it was T6050 only, because bit 4 had not been read on the other SoCs. Aurora's read-backs in this thread now show the four-bit layout across SoCs: T6000 (M1 Pro) has 18 pins with bits 4:1 = 0b1111, all on the SMC block; T6040 (M4 Pro) has 9 pins with bit 4 set across NUB, AOP and AP; T8140 (A18 Pro) has 19 AP pins with bit 4 set, four of them 0x00474210, the same word shape as the K114c pins. No read showed bit 4 used for anything but the mode field, and no output-mode or GPIO-consumer pin had it set. T8112 (M2) is still unmeasured; the field reads as four bits on every SoC checked. No DATA-latch toggles were performed on Aurora hardware for this evidence. The default is therefore four bits again, with no per-compatible flag.
Validated on, and reach
What ran where:
Kiwi interface ready with status:0appeared. The four-bit-default form at 5a1250e has not been booted.drivers/pinctrl/pinctrl-apple-gpio.ocompiles at 5a1250e with clang 22.1.8, no warnings, against the PR tree. Not a full tree build and not booted.Not checked: any Mac at the flipped head. The four-bit mask now applies to every block the driver loads; for the measured bit-4 pins on other SoCs the only behavior change is that a mode write clears bit 4, same as it already did on the T6050. No M1, M2, M3, M4 or M5 Pro machine was run.
m tester (omarchy-m-testing.org): no feature row covers a GPIO mode; no tester run is linked to this change.