Skip to content

touchpad: Drop the reports the pad queued while suspended (HW-8311) - #3

Open
eclecticc wants to merge 1 commit into
passthroughfrom
tp-resume-drop-stale
Open

eclecticc wants to merge 1 commit into
passthroughfrom
tp-resume-drop-stale

Conversation

@eclecticc

@eclecticc eclecticc commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Doing state machine analysis on the source, Claude found a race between bluetooth connection and keyboard powering on where a TP could get stuck in a dead state. We haven't seen this reported by dogfooders yet, though it could also have been hidden by some of the other connection issues that we recently fixed. The patch is fairly contained, and I did some regression testing on it, so probably makes sense to take it in early before we do our heavy DVT2 dogfooding.


Claude-generated details

Module half of HW-8311. The board half, which needs this, is FrameworkComputer/zmk-private#181.

touchpad: Drop the reports the pad queued while suspended

  • A touch while the driver is PM-suspended still makes the pad raise a report. With nobody reading it, the pad keeps DR asserted, and PM resume used to drain it like a fresh report.
  • With the zmk-private change, host-follow resumes the driver when it puts the pad in touch-detect standby on a suspended USB bus (OFF -> SLEEP), so touch-to-wake works from OFF. The stale report then reached the USB passthrough on the suspended bus and became a remote wakeup. On DVT1, touching the "off" pad before suspending the laptop woke it again about 1 s into suspend.
  • PM resume now reads and drops whatever is queued, into a local buffer, since a drain in flight at suspend may still be dispatching from report_buf.
    • A reset signal among the dropped reports still restores the retained features.
    • tp_arm_dr() still drains a report that goes ready after that.
  • It also stops a tap made while the pad was off from being delivered when the host reconnects (OFF -> ON).

Testing (DVT1, Fedora 44 KDE, cherry-picked onto #2's head ba720a92 with latest zmk-private + open PRs + the board half):

  • Wired, touchpad off, touched while off, then laptop suspend: stayed asleep 29 s and woke on a touch. Without this patch it woke itself about 1 s in.
  • Touch-to-wake from on and from off, BLE reconnects, factory touchpad power, and boot all pass. Full table in HW-8311.

Other branches: applies cleanly on #2 (hw8252-mac-trackpad) and on the local hw-tp-read-retry branch.

🤖 Generated with Claude Code

A touch while the driver is PM-suspended still makes the pad raise a
report, and with nobody reading it the pad keeps DR asserted. PM resume
then drained it like a fresh one. The board resumes the driver when
it turns the pad back on (OFF -> ON) and, for touch-to-wake, when it
puts the pad in modern standby on a suspended USB bus (OFF -> SLEEP).
In the second case the stale report reached the USB passthrough while
the bus was suspended and became a remote wakeup: on DVT1, a touch on
the "off" pad before suspending the laptop woke it again about a second
into suspend.

Read and drop whatever is queued at resume, into a local buffer since
a drain in flight at suspend may still be dispatching from report_buf.
A reset signal among them still restores the retained features.
tp_arm_dr() still drains a report that goes ready after that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Normal report delivery can still process stale touchpad reports after an I2C read failure or through queued or running work during suspend/resume, potentially triggering unwanted USB remote wakeup.

2 open issues
What changed in this PR

This PR updates touchpad PM resume handling to discard reports queued while suspended, preventing stale touches from reaching reconnected hosts or causing unwanted USB wakeups.

Changes:

  • Adds a bounded discard loop before rearming the data-ready interrupt.
  • Uses a local buffer to avoid interfering with in-flight report dispatch.
  • Preserves retained-feature restoration when discarded reports indicate a pad reset.
File Description
drivers/​input/​hid_touchpad.c Adds pending-report discard handling to the PM resume path.

Review effort: Balanced

Comment on lines +759 to +763
for (int i = 0; i < TP_DRAIN_BURST && gpio_pin_get_dt(&config->dr) > 0; i++) {
if (tp_lock(data)) {
return;
}
int err = i2c_read_dt(&config->i2c_bus, buf, data->max_input_len);
Comment on lines +765 to +768
if (err) {
/* tp_arm_dr() sees DR still asserted and reads it the usual
* way. */
return;
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