Skip to content

pinctrl: apple: clear bit 4 of the GPIO mode on the T6050 - #2004

Open
joshuaswarren wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
joshuaswarren:dhp4/pinctrl-mode-field
Open

joshuaswarren wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
joshuaswarren:dhp4/pinctrl-mode-field

Conversation

@joshuaswarren

@joshuaswarren joshuaswarren commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Status note: the head moved to a0609dc on 2026-11-18 (rebased onto integration/aurora 0abc2f3); CI is rerunning at that head. Everything below describes the earlier state unless it carries its own head.

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

The change adds a hw table entry for apple,t6050-pinctrl (apple_gpio_t6050_hw, mode_hi). On a T6050 block the mode is bits 1-4: 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, because bit 4 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. One file, drivers/pinctrl/pinctrl-apple-gpio.c. All three T6050 pinctrl nodes in the tree already list apple,t6050-pinctrl first.

Changed after review (RevAne421): the first form made the mode four bits wide for every SoC. It is now T6050 only.

Validated on, and reach

What ran where:

  • 14-inch M5 Max MacBook Pro (K114c, T6050): the register read-backs above, measured before the change. An earlier form of this change (every SoC, mode bits 1-4) was booted there in the HID: apple-mtp-kiwi: the K114c touch screen (needs #1568) #1605 stack: the touch firmware was accepted and Kiwi interface ready with status:0 appeared. This T6050-only form was not booted, and no finger events were checked.
  • 13-inch M1 MacBook (build only): drivers/pinctrl/pinctrl-apple-gpio.o compiles with and without the change with gcc 16.1.1 and W=1, no warnings, on a depth-1 checkout of integration/aurora (580e9119). Not a full tree build and not booted.

Not checked: any other Mac. The T6050 hw table also applies to the other two T6050 pinctrl blocks (AP and AOP); on those the mode bit 4 was not read. 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T15:37:44.376713Z
We couldn’t complete this review. Comment @codex review to try again.
729b14a PR opened
🔒 Security Review ❌ Failed 2026-11-15T15:37:50.490769Z
We couldn’t complete this review. Comment @codex security review to try again.
729b14a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

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.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

GREEN on 729b14a
Model: zai/glm-5.3

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

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

GREEN on 729b14a
Model: anthropic/claude-sonnet

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:

  1. Other SoCs are unproven, and the PR says so. In drivers/pinctrl/pinctrl-apple-gpio.c, REG_GPIOx_MODE is defined once (line 64) and every compatible shares it: apple,t8140-pinctrl, t8132, t6050, t8103 and the generic apple,pinctrl (lines 656-661). Neither the driver nor the DT binding gives per-SoC field widths, and mainline Linux and U-Boot both use GENMASK(3, 1). What I can show is that bit 4 is not claimed by any other field in the driver: PERIPH is bits 6:5 and PULL is bits 8:7. So the widening cannot overwrite a defined field. It does change behaviour on every Mac that has the driver:

    • apple_gpio_get_direction (line 227) and apple_gpio_get (line 241) now read a pin in mode 1 with bit 4 set as an input, where before it read as an output.
    • direction_input (line 261), direction_output (line 274) and the IRQ mask, unmask and set-type paths (lines 313, 325, 351) now clear bit 4 on write.

    If bit 4 carries a real function on another model, the first kernel write to that pin loses it. If someone can read one GPIO register dump from an M1 or M2 with the pins that use IRQs, that would settle it. If not, say in the commit message that only the M5 Max was checked. If you want it provable, the other option is a per-compatible mask that widens only for apple,t6050-pinctrl.

  2. Put the test line in the commit message. The commit body gives the register read-backs, but not what was run with the fix. The PR body has it (a 14-inch M5 Max MacBook Pro, touch reset takes effect with this commit in the HID: apple-mtp-kiwi: the K114c touch screen (needs #1568) #1605 stack, not booted alone, and a build-only check on a 13-inch M1 MacBook). The PR body is not part of the git history, so move one or two sentences of that into the commit.

  3. The Signed-off-by uses a users.noreply.github.com address. It matches the author, so it is consistent in this tree.

@joshuaswarren
joshuaswarren force-pushed the dhp4/pinctrl-mode-field branch from 729b14a to aea7476 Compare November 15, 2026 16:17
@joshuaswarren joshuaswarren changed the title pinctrl: apple: the GPIO mode field is four bits wide pinctrl: apple: clear bit 4 of the GPIO mode on the T6050 Nov 15, 2026
@joshuaswarren

Copy link
Copy Markdown
Contributor Author

GREEN on aea7476
Model: zai/glm-5.3

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

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

GREEN on aea7476
Model: anthropic/claude-sonnet

Re-review after my earlier notes. Both are addressed. No blocking items.

What I checked in drivers/pinctrl/pinctrl-apple-gpio.c at this head:

  • Other SoCs are unchanged. The mask is REG_GPIOx_MODE | pctl->mode_hi, and mode_hi is zero unless the hw table sets it. On those SoCs the new read test (reg & GENMASK(3,1)) == FIELD_PREP(GENMASK(3,1), OUT) is the same test as the old FIELD_GET(...) == OUT. All the mode writes use the same mask as before.
  • Every mode access goes through the mask. direction_input, direction_output, irq_mask, irq_unmask and irq_set_type clear bit 4 on the T6050, and get_direction and get read it. No other place touches REG_GPIOx_MODE.
  • The T6050 entry really is picked. In the device trees at this head, both nub_gpio0 and pinctrl_ap list "apple,t6050-pinctrl" first, so device_get_match_data() returns the new table. The entry keeps no_regcache = true, so the cache behaviour of the earlier entry is preserved.
  • The commit message now has a Tested paragraph. It names the 14-inch M5 Max MacBook Pro for the register read-backs, a build-only check on a 13-inch M1 MacBook, and says this T6050-only form was not booted.

I did not compile or boot it.

Non-blocking notes:

  1. The wider mask applies to every T6050 pin controller on every T6050 machine, not only the K114c touch pins. That includes the AP controller and the other T6050 boards (J714, J716, J775, J873, K116). The commit message says only the K114c was checked, and nobody has looked at a register dump from the others. The effect there would be the same as on the K114c: bit 4 is cleared on the first mode write. It is far narrower than the first version.
  2. A comment would help. One line in apple_gpio_mode_mask() saying why the T6050 reads the mode as bits 1-4 would save the next reader a search.

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>
@joshuaswarren
joshuaswarren force-pushed the dhp4/pinctrl-mode-field branch from aea7476 to a0609dc Compare November 18, 2026 01:12

@joshuaswarren joshuaswarren left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@RyanTheTide

Copy link
Copy Markdown
Contributor

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 (drivers/pinctrl/pinctrl-apple-gpio.c:432-436, .mode_hi = true, matched at :686). The description says the other SoCs keep three bits "because bit 4 was not checked on them". In this tree we select behaviour by a hardware property rather than by where it was tested. A gate stays only when the hardware is known to differ, for example if bit 4 has another meaning on older blocks.

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.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

[Joshua's agent] Replying to @RyanTheTide scope question.

We will keep the four-bit mode behind .mode_hi on apple,t6050-pinctrl for this series, and tighten the comment as you asked. The reason is evidence, not a known different block on older SoCs.

What is measured (T6050 only, K114c): NUB touch reset/power pins left iBoot with bit 4 set (0x474210 / 0x474212 via /dev/mem). With bit 4 set, output DATA did not latch: write 0x474213 read back 0x474212; write 0x474203 read back 0x474203. Clearing bit 4 on mode writes is what direction_output needed. A known-good output (PERST# 0x00076a03) had bit 4 clear. Modes 0–7 encodings are unchanged (only the clear mask widened).

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 (pinctrl-apple-gpio.o, gcc 16.1.1 -W1), not booted.

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.

@RyanTheTide

Copy link
Copy Markdown
Contributor

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.

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