Skip to content

D21: touch starts reliably (32 kHz touch clock, IRQ masked through boot, d9 retry) - #234

Closed
ryzensnyper wants to merge 4 commits into
OrchardLinux:mainfrom
ryzensnyper:pr/d21-touch-reliable
Closed

ryzensnyper wants to merge 4 commits into
OrchardLinux:mainfrom
ryzensnyper:pr/d21-touch-reliable

Conversation

@ryzensnyper

Copy link
Copy Markdown

Problem

On the iPhone 8 Plus (D21), touch with the shared apple_z2 D21 backend was a lottery:

Changes, one commit each

  1. arm64: dts: apple: t8015-d21: Run the touch clock at 32768 Hz (devices/t8015/0020)
    • The D21 ADT asks for function-clock_enable = KLCT(0x08, 0x64, 0x8000), a 32768 Hz reference, and the C1F5E firmware sets up the controller FLL for it.
    • t8015-pmgr.dtsi carries the iPhone X's 24 MHz, so on D21 the divider was 1 (PMGR 0x78000 = 0x00080001). Now it reads back 32786 Hz (divider 732).
    • D21 is the only iPhone 8-class board with a touchscreen node so far, so the override is in its .dts. It should move to a shared iPhone 8 dtsi when D20/D201/D211 touch is described, as the iPhone 7 boards do in t8010.
  2. Input: apple_z2: D21: Keep ATN masked until boot completes (drivers/input/0046)
    • Re-masks the touch IRQ after the firmware wait-IRQ step, and unmasks it once after the first post-boot read.
  3. Input: apple_z2: D21: Retry the surface descriptor query (drivers/input/0047)
    • Once in 76 logged starts, a streaming touch frame landed in the 0xd9 read (rx e1 56 00 …). Descriptor validation failed (-EPROTO), init only logged it, and every touch packet was then dropped for the session ("touch packet without surface descriptor").
    • Now retried up to 5 times, 10 ms apart, with a warning if all attempts fail.
  4. devices: d21: touch works; changelog
    • touch = "working", a CHANGELOG entry, and the regenerated docs/compatibility.md.

Both driver changes sit behind apple_z2_d21_is_d21(), the existing D21 backend check, so no other board's behaviour changes.

Tested on device

  • Build: orchard build <project> --device d21 from eab974c + these patches + pinctrl: apple: do not arm a masked interrupt in set_type #233, with no debug patches. Payload sha256 c39e6e0e43ca8e52…, booted over checkm8 → PongoOS → bootm, default IRQ affinities.
  • Fresh first boots (re-pwned each time): 5 of 5 delivered touch (57,960 / 68,496 / 61,968 / 71,448 / 74,472 bytes from /dev/input/event1 while tapping).
  • Module reloads (rmmod apple_z2; modprobe apple_z2): 10 of 10 delivered touch, with no hangs, RCU stalls or recovery restarts.
  • d9 retry: the descriptor stored on attempt 1 in all 16 starts, so the retry path was not exercised. It guards the 1-in-76 case.
  • Not verified: the first-boot DEAD went away together with the clock change, but I have not proven the cause. 5 of 5 against the earlier ~3 of 4 is encouraging, not conclusive.

Without #233, reloads still hang (5 of 8 in my runs). First boots don't depend on it.

Tests

python -m unittest discover -s tests: 930 tests. The only failures are the 4 test_ram CLI errors, which also fail on unmodified main on my host (free-disk check). The device runs were on a build from eab974c. main has moved since, but not in drivers/input, devices/t8015 or the apple-16k series.

🤖 Generated with Claude Code

dugsau1 and others added 4 commits November 25, 2026 02:25
The D21 ADT asks for a 32768 Hz touch reference (KLCT 0x8000); the t8015
dtsi gives the iPhone X's 24 MHz. D21 is the only iPhone 8-class board
with a touchscreen node yet, so the override sits in its .dts; it moves to
a shared dtsi when D20/D201/D211 touch is described.

Assisted-by: LLM
Signed-off-by: Dugs <dugahol@protonmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pletes

Assisted-by: LLM
Signed-off-by: Dugs <dugahol@protonmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A streaming frame colliding with the 0xd9 read (1 in 76 starts) left the
descriptor unset and dropped every touch for the session.

Assisted-by: LLM
Signed-off-by: Dugs <dugahol@protonmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured on payload built from this branch's patches plus the Apple GPIO
masked-IRQ fix: 5 of 5 fresh boots and 10 of 10 module reloads delivered
touch on the iPhone 8 Plus.

Assisted-by: LLM
Signed-off-by: Dugs <dugahol@protonmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ryzensnyper

Copy link
Copy Markdown
Author

Retest on the exact submitted revisions: #234 head e3827d8 with #233 60fd37c on top, on current main (9cb4066).

  • Build: orchard build <project> --device d21, payload sha256 075b48e6bdf746a7…. I checked in the built source tree and DTB that all four patches are present (touchclk 0x8000, the set_type mask check, P2, the d9 retry), and that no debug patches are.
  • Fresh boot: touch GOOD (69,864 bytes from /dev/input/event1).
  • 3 reloads (rmmod apple_z2; modprobe apple_z2), default IRQ affinities: all clean, and touch GOOD after each (50,568 / 63,648 / 93,912 bytes). The descriptor stored on attempt 1 every time.
  • Kernel log: no RCU stalls, BUG/WARNING, recovery restarts or "touch packet without surface descriptor".

This matches the earlier runs on eab974c (5/5 boots, 10/10 + 10/10 reloads).

@henrikklee

Copy link
Copy Markdown
Contributor

Thanks @ryzensnyper! This is on main unchanged, with you as author, in 06e093e (tag contrib/ryzensnyper-d21-touch), so I'm closing the PR as you suggested. The GPIO fix helps every board with Apple's GPIO controller, not just the 8 Plus.

@henrikklee henrikklee closed this Nov 24, 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.

3 participants