Skip to content

HID: dockchannel-hid: bind afe_reset on PM2 fallback and clear starting on timeout - #3932

Merged
DjDeveloperr merged 2 commits into
mainfrom
fix/dockchannel-hid-pm2-fallback-reset
Dec 2, 2026
Merged

DjDeveloperr merged 2 commits into
mainfrom
fix/dockchannel-hid-pm2-fallback-reset

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

What: Fix two bugs in drivers/hid/dockchannel-hid/dockchannel-hid.c that break multi-touch startup on Apple MTP 27.2+ laptops (e.g., J516s / M3 Pro) when the device tree does not force apple,power-method = <2>:

  1. PM1-to-PM2 fallback left iface->reset as NULL (regression from 4e9a79628fc5): dchid_get_interface() only binds iface->reset = dchid->afe_reset when power_method == DCHID_POWER_METHOD_2 at probe time. On boards defaulting to PM1 whose MTP firmware rejects PM1 with 0xe00002c2, dchid_start_interface() switched iface->power_method to PM2, asserted dchid->afe_reset, resent firmware, and called dchid_pm2_set_power(ON) -> dchid_set_own_lines(ON) -> gpiod_direction_output(iface->reset, 0). With iface->reset == NULL, gpiod_direction_output() silently returned 0 (and skipped the 50 ms settle), leaving AFE reset asserted until the 10 s ready timeout expired. Add dchid_enter_pm2_fallback() to bind iface->reset = dchid->afe_reset when switching to PM2, and return -EINVAL from dchid_set_own_lines() if iface->reset is NULL.
  2. Stale iface->starting after ready timeout: dchid_open() left iface->starting = true when wait_for_completion_timeout(&iface->ready, ...) timed out, wedging every subsequent open of /dev/input/event* with -EINPROGRESS (Interface multi-touch is already starting). Add dchid_wait_ready() to clear iface->starting = false on both timeout and completion.

Also add two KUnit tests in drivers/hid/dockchannel-hid/dockchannel-hid-parser-test.c (dchid_pm2_fallback_binds_afe_reset_test and dchid_wait_ready_timeout_clears_starting_test).

Tested:

  • scripts/checkpatch.pl: 0 errors, 0 warnings.
  • AArch64 cross-compile with drivers/hid/dockchannel-hid/dockchannel-hid.kunitconfig (dockchannel-hid.o, dockchannel-hid-protocol-test.o): clean, 0 warnings.
  • tools/asahi/j613-mtp-s2idle-tests.py: PASS.
  • J516s (M3 Pro, T6030) hardware verification at exact head 185dc0f3991ab61406293b634e205fb7dd82d99f (7.3.0-m3-dchid+, stock cmdline, stock m1n1/boot.bin, boot_id=651dd435-84d2-4094-add9-1c2eafa210fc):
    • dmesg:
      • [ 4.195534] dockchannel-hid 37ab28000.input: output report 0x40 to iface 0 (comm) failed with err 0xe00002c2
      • [ 4.195539] dockchannel-hid 37ab28000.input: multi-touch: power method 1 rejected (0xe00002c2); retrying with power method 2
      • [ 4.499241] dockchannel-hid 37ab28000.input: Interface multi-touch is now ready
    • Pre-sleep evdev probe: all 5 input devices (event0 Force Click, event1 keyboard, event2 Apple MTP multi-touch ABS_MT_X=[-7456..7976] ABS_MT_Y=[-9283..163], event3 SMC, event4 jack) open and pass ioctl (EVDEV_ALL_OK).
    • 3x RTC-armed s2idle cycles (rtcwake -d rtc0 -m freeze -s 5): suspend_stats success 0->3, fail 0->0.
    • Post-sleep evdev probe: all 5 input devices EVDEV_ALL_OK; 0 start timed out, 0 already starting, 0 kernel WARN/BUG/Oops/GPU faults.

Risk: Two-way door, scoped to dockchannel-hid PM1->PM2 fallback and ready-wait error handling. Boards already using PM2 from DT or succeeding on PM1 keep identical behavior.

Not yet: Independent review and hosted CI on this branch; peer-board verification on another PM1-fallback MTP laptop (e.g., J414s or J613) if desired.

…lear starting on timeout

When an interface does not pin apple,power-method in DT, dchid_get_interface()
initializes it with power method 1 and leaves iface->reset NULL. On Macs whose
MTP 27.2+ firmware rejects power method 1 with 0xe00002c2 (for example J516s),
dchid_start_interface() switches iface->power_method to DCHID_POWER_METHOD_2 at
runtime, asserts dchid->afe_reset when adopting a retained MTP session, resends
the firmware, and calls dchid_pm2_set_power(iface, DCHID_POWER_STATE_ON).

Commit 4e9a796 ("HID: dockchannel-hid: bring up the kiwi (touch screen)
interface") refactored dchid_pm2_set_power() to drive iface->reset through
dchid_set_own_lines() instead of dchid->afe_reset directly, but the runtime
fallback path never assigned iface->reset = dchid->afe_reset. Because
gpiod_direction_output(NULL, 0) silently returns 0, AFE reset was never
released (and the 50 ms settle was skipped), leaving the multi-touch AFE held
in reset until start timed out after 10 s.

In addition, when wait_for_completion_timeout(&iface->ready, ...) timed out in
dchid_open(), iface->starting remained true permanently, causing every
subsequent open of the HID input device to fail with -EINPROGRESS
("Interface multi-touch is already starting").

Bind iface->reset = iface->dchid->afe_reset when falling back to power method
2, reject a NULL iface->reset in dchid_set_own_lines() with -EINVAL instead of
silently no-oping, and clear iface->starting when waiting for ready finishes or
times out. Add KUnit tests for both cases.

Fixes: 4e9a796 ("HID: dockchannel-hid: bring up the kiwi (touch screen) interface")
Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 2, 2026 12:46

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at 185dc0f. The PM2 fallback binding (dchid_enter_pm2_fallback) and clearing starting on the open() timeout both look right, and the KUnit cases cover them.

One cross-board concern before I approve: the new if (!iface->reset) return -EINVAL; in dchid_set_own_lines(). Before this PR, a NULL iface->reset went to gpiod_direction_output(NULL, ...), which is a no-op returning 0 for an optional GPIO. Now it's a hard -EINVAL. dchid_pm2_set_state() calls set_own_lines for every PM2 interface that isn't firmware_managed_reset (around line 758). So any board with a PM2 interface and no reset line in its DT (keyboard, or kiwi on another SoC) would now fail every PM2 power transition, including on suspend and resume, where it used to succeed.

Could you either:
(a) keep NULL as an explicit no-op in set_own_lines and fail only where a line is actually required (the own_lines power-cycle path in dchid_start_interface already checks that iface->reset is distinct from the AFE reset), or
(b) show that every PM2, non-firmware-managed interface on every board has a reset line, e.g. a DT scan of all apple,dockchannel-hid nodes or a probe-time WARN, plus a boot and s2idle row on one non-T6030 dockchannel Mac (J713/J616s/J700)?

With either of those I'll approve straight away.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Audit at 185dc0f3 — code fixes and KUnit tests look clean; awaiting CI + resolution of reset-line check / peer row

Reviewed drivers/hid/dockchannel-hid/dockchannel-hid.c and dockchannel-hid-parser-test.c:

  • dchid_enter_pm2_fallback() cleanly binds iface->reset = iface->dchid->afe_reset when falling back from PM1 (0xe00002c2) to PM2, and dchid_wait_ready() clears iface->starting = false on both timeout and completion so a timed-out open() no longer wedges subsequent opens with -EINPROGRESS. Both new KUnit cases cover these paths cleanly.
  • Regarding the !iface->reset check in dchid_set_own_lines(): at probe (dockchannel-hid.c:332-349), any interface configured with DCHID_POWER_METHOD_2 && !firmware_managed_reset already fails probe if !reset, so configured PM2 interfaces cannot reach dchid_set_own_lines() with iface->reset == NULL. The only path that can hit !iface->reset there is a PM1-to-PM2 fallback on a board with dchid->afe_reset == NULL — in which case dchid_start_interface() line 1036 (gpiod_direction_output(iface->reset, 1)) would still no-op before failing in dchid_set_own_lines(). If PM1-to-PM2 fallback requires afe_reset, checking dchid->afe_reset at fallback (or keeping the guard aligned with Ryan's comment) makes that invariant explicit.
  • Holding APPROVE until CI (host-tests, pr-text, readiness) finishes green and the cross-board dockchannel peer row / dchid_set_own_lines() question is resolved.

Returning -EINVAL from dchid_set_own_lines() when iface->reset is NULL
turns the old optional-GPIO no-op into a hard failure, including on
suspend and resume, for any power-method-2 interface without a DT reset
line on other boards. Drop the check and its KUnit assertion.

The power-method-2 fallback still binds iface->reset to afe_reset, so the
J516s multi-touch fix is unchanged.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Review follow-up at ea8ac57f: a NULL iface->reset is a no-op again. I dropped the -EINVAL check in dchid_set_own_lines() and its KUnit assertion, so dchid_set_own_lines() now matches the base. Boards whose power-method-2 interfaces have no DT reset line behave as before, including across suspend and resume. The J516s fix itself is unchanged: the fallback still binds afe_reset.

Tested: on main 8a42aee5 + this branch (main hasn't touched these files since the merge base), dockchannel-hid.o builds clean at W=1 with LLVM on arm64. The test-file change only deletes two lines.

Not yet: J516s boot + 3× s2idle + evdev row at ea8ac57f (M3 lead, after its current #3812 row).

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed at ea8ac57. The NULL reset is a no-op again, so dchid_set_own_lines() matches the base and other boards' PM2 interfaces without a DT reset line are unaffected. The PM2 fallback still binds afe_reset, and open() clears starting on timeout. Both are covered by KUnit. Approve.

@github-actions github-actions Bot added the door:two-way Revertible or not, from Merge risk (bot) label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Merge readiness at ea8ac57f: not ready yet

Check Detail
CI at head running running: host-tests, pr-text / pr-text
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok comment at ea8ac57f
Conflicts ok none
PR text ok Risk: two-way · scoped to dockchannel-hid PM1->PM2 fallback and ready-wait error handling. Boards already using PM2 from DT or succeeding on PM1 keep identical behavior.

Areas: none matched in CODEOWNERS

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-audit at ea8ac57f6efd — reset-line follow-up is clean; awaiting queued CI and exact-head J516s row

Checked:

  • ea8ac57f6efd drops the -EINVAL return on iface->reset == NULL in dchid_set_own_lines() and its KUnit assertion, keeping PM2 interfaces without a DT reset line as a no-op while preserving dchid_enter_pm2_fallback() (binding iface->reset = iface->dchid->afe_reset on PM1→PM2 fallback), dchid_wait_ready() (clearing iface->starting = false on both timeout and completion), and both remaining KUnit tests.

Remaining before merge:

  • Queued CI checks (host-tests, pr-text) at ea8ac57f6efd.
  • Queued J516s boot + 3× s2idle + evdev row at ea8ac57f6efd noted in #issuecomment-7346149709.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s (M3 Pro, T6030) hardware verification at exact PR head ea8ac57f6efd (7.3.0-m3-dchid-m3-dchid2, stock /boot/efi/m1n1/boot.bin, stock cmdline, boot_id=b9046b4d-da87-4a89-9aee-e6453d3439da):

  • PM1 -> PM2 fallback:
    [    4.437242] dockchannel-hid 37ab28000.input: output report 0x40 to iface 0 (comm) failed with err 0xe00002c2
    [    4.437246] dockchannel-hid 37ab28000.input: multi-touch: power method 1 rejected (0xe00002c2); retrying with power method 2
    [    4.745549] dockchannel-hid 37ab28000.input: Interface multi-touch is now ready
    
    Ready in 308 ms; 0 start timed out, 0 already starting.
  • Pre-sleep evdev probe (EVDEV_ALL_OK): all 5 input devices (event0 Force Click, event1 Apple MTP keyboard, event2 Apple MTP multi-touch with ABS_MT_X=[-7456..7976] ABS_MT_Y=[-9283..163], event3 SMC power/lid, event4 Headphone Jack) open and respond to EVIOCGNAME/EVIOCGBIT/EVIOCGABS.
  • 3x RTC-armed s2idle (rtcwake -d rtc0 -m freeze -s 5): suspend_stats: success 0->3 fail 0->0.
  • Post-sleep evdev probe (EVDEV_ALL_OK): all 5 input devices including event2 (Apple MTP multi-touch) still open and respond cleanly after all 3 cycles.
  • Kernel health: 0 WARN/BUG/Oops/GPU faults.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Local CI passed on pc. Tested main 07686fb2e4b553ade5cb8955345ba930ad4b0018 merged with this PR head, tree 84b0b8843e1b9a0e05e40139f655249389a5c977.

  • run-host-tests-local.sh pr3932-07686fb2 12 '' r1 using the workflow-pinned Ubuntu 24.04 image with networking disabled — 952/952 passed.
  • ~/bin/aurora-build linux-build/build exec -- make -C "$TREE" O="$OUT" ARCH=arm64 LLVM=1 CC='ccache clang' BINDGEN="$BINDGEN" -j8 W=1 drivers/hid/dockchannel-hid/ — 2/2 objects built with the parser KUnit tests enabled and no warnings.

@DjDeveloperr
DjDeveloperr merged commit 6d67fea into main Dec 2, 2026
3 of 6 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/dockchannel-hid-pm2-fallback-reset branch December 2, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants