Skip to content

HID: magicmouse: keep host click feedback across system sleep - #2026

Merged
DjDeveloperr merged 3 commits into
aurora-silicon:integration/aurorafrom
Isaac-Duarte:fix/2025-haptic-suspend
Nov 20, 2026
Merged

DjDeveloperr merged 3 commits into
aurora-silicon:integration/aurorafrom
Isaac-Duarte:fix/2025-haptic-suspend

Conversation

@Isaac-Duarte

@Isaac-Duarte Isaac-Duarte commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Keep host-driven click feedback working across system sleep. Closes #2025.

Behavior

DockChannel HID still delivers input reports while suspended, but refuses feature requests with EBUSY. A click worker used to hit that refusal, disable haptic_press, fail its firmware hand-back and leave the actuator in host mode while neither side produced a click.

Suspend now marks the haptic state under the actuator mutex and an IRQ-safe producer lock. Raw click and FF playback producers cannot queue after that transition. It drains the four click jobs and all FF jobs without holding the locks their workers need. Workers and firmware hand-back skip actuator I/O while suspended; uploads return EBUSY, and erasing the final effect defers its hand-back until resume.

Resume/reset-resume clear input state and assert the wanted actuator mode after the transport accepts requests: host mode for haptic_press or loaded effects, otherwise device mode. Default N with device mode already cached sends nothing. Failed restoration leaves the cache value that makes the existing paths retry; unsupported host mode is not warned about.

The producer lock closes a second race in the original fix: a report arriving after worker cancellation could queue work while suspended, then play after resume cleared the flag. The original two commits are preserved; the follow-up is e12a69972e56fc8b804b38509fec3d8d0efce3ba.

Follow-up validation

  • Production callback harness passes: suspended click/FF producers, FF cancellation/upload/erase, transport order and rollback, all-interface resume, default zero-I/O mode, loaded effects, failed host/device restoration, unsupported mode, reset-resume, null state and held multitouch-enable work.
  • Original head 62d2045d8928 compiles and fails the new suspended-report assertion at runtime. Legacy transport 4db3a5a22c43 also compiles and fails its expected runtime assertion. Both negative controls are in the host-test runner.
  • AArch64 W=1 driver object builds pass with CONFIG_HID_APPLE_MTP_HAPTIC=m and disabled, with no warnings. The enabled object references the actuator API; the disabled object does not. These are compile checks, not a new boot kit.
  • Strict checkpatch: zero errors, warnings or checks; whitespace check passes.

Hardware evidence

The original version was tested by the author on J714s with integration c33c5fd plus this PR, in-tree haptics enabled and haptic_press=Y. A devices-PM freeze while clicking reproduced the old EBUSY/silent-pad failure, while the original fix sent no suspended waveform and restored host mode. The author also reported 8-second and 4h42m lid s2idle sleeps with Y preserved and clicks/tracking working, plus device-mode hand-back after selecting N.

The follow-up has since run on the J714s: integration/aurora 0abc2f3 plus this PR's head (same patch as e12a699), haptic_press=Y. Across two s2idle wakes (1 h 24 min, ~1 s), the MTP logged the host-mode handoff from the resume path (Intercepted 0x21 click handoff: 01) after each, magicmouse logged no warnings, and a physical press gave exactly one click. A fresh devices-PM freeze while clicking has not been repeated on the follow-up.

The dockchannel transport keeps passing MTP reports on while it is
suspended, but refuses requests with -EBUSY until it resumes. A press
handled while the transport is suspended, such as one that wakes the
system, queued its click, and the press worker failed to play the
waveform. Its error path cleared haptic_press and tried to hand the
actuator back to the firmware, which failed the same way, so the
firmware stayed in host-controlled mode. Resume then assumed the
actuator was device-controlled. With haptic_press off the host no longer
clicked, and the firmware neither clicked nor reported the button: the
pad had no click until the driver was rebound.

Stop sending to the actuator in the driver's suspend callback, which the
transport runs before it stops taking requests, until resume. On resume,
assert the wanted actuator mode instead of assuming the firmware went
back to device-controlled mode, which the J714s actuator does not do
across suspend-to-idle. Nothing is sent when device-controlled mode is
both wanted and already cached.

Closes: aurora-silicon#2025
Signed-off-by: Isaac Duarte <[email protected]>
…asleep

magicmouse_haptic_forget_mode() is gone: suspend now marks the
trackpad suspended and resume asserts the actuator mode itself. Paste
magicmouse_haptic_suspend(), magicmouse_haptic_resume() and
magicmouse_haptic_effects_loaded() instead, and make the actuator stub
assert that the transport is up, which is the -EBUSY failure seen on
hardware. Check that resume asserts device mode, and host mode when
haptic_press is set.

Signed-off-by: Isaac Duarte <[email protected]>
A report can queue a click after suspend canceled its worker, then run it
after resume clears the suspended flag. Serialize input and FF playback
queueing with PM state changes under an IRQ-safe lock. Set the flag before
draining both click and effect jobs, without holding either worker lock.

Refuse FF uploads and defer the final erased-effect hand-back while asleep.
Resume restores the wanted mode once the transport accepts requests again.

Exercise the production producers, FF callbacks, default mode, loaded
effects and restore failures. Keep the original head as a compiled runtime
negative control in the host-test runner.

Signed-off-by: Diljit Singh <[email protected]>

Copy link
Copy Markdown
Contributor

Pushed follow-up e12a699, preserving the original two commits.

Found a remaining queue-after-cancel window: reports and FF playback could queue while suspended, then execute after resume cleared the flag. Input producers and PM transitions now share an IRQ-safe lock, all click/FF jobs drain after producers are stopped, uploads refuse asleep transport, and erase defers the firmware hand-back.

The production callback checks pass, including loaded effects, restore failures, reset-resume and default zero-I/O behavior. The original PR head compiles and fails the new suspended-report assertion at runtime; the old transport negative control also fails as expected. Both controls are wired into CI. AArch64 W=1 driver object builds pass with haptics enabled and disabled, without warnings. Strict checkpatch and whitespace checks are clean.

No new hardware boot or physical click test was performed; the author's previous hardware evidence applies to the earlier version. Default unchanged. Current-head CI is pending.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Review against integration/aurora 0abc2f3 (the diff applies there unchanged).

The fix covers both paths in #2025: no actuator request is sent while the transport is suspended, and resume asserts the mode that is wanted instead of trusting the cache. One interaction to settle before merge:

  • HID: apple-mtp-haptic: return the actuator to device mode on resume #2100 does the opposite on resume. apple_actuator_resume() there always switches the actuator to device mode. This PR's magicmouse_haptic_resume() switches it to host mode when haptic_press is set or effects are loaded. Both run in the transport's resume, one per HID interface. If the actuator interface resumes after the trackpad, msc->haptics->mode is cached as HOST while the firmware is in device mode. Each press then gets the firmware's click and the host pulse (two clicks), which is the failure the old forget_mode comment describes. The two PRs also edit the same comment block in hid-magicmouse.c. With this PR in, HID: apple-mtp-haptic: return the actuator to device mode on resume #2100's actuator-side switch is not needed. If both land, the actuator driver should leave the mode to the trackpad driver, or the trackpad should resume after it.
  • Smaller point: outside a sleep, a waveform or mode-switch failure still clears the module-wide haptic_press in magicmouse_haptic_pulses(). That flag is set by userspace and applies to every trackpad. The suspend gate removes the -EBUSY case from hid-magicmouse: a click waveform failing during suspend (-EBUSY) leaves the J714s trackpad with no click until rebind #2025, but a transient error at any other time still turns host clicks off until the parameter is written again. A per-device flag would keep that contained. This could be a follow-up.

A second report on a J415 (M2, linux-aurora 7.3.0.aurora1-40) in #2025 shows the same click waveform failed (-16) after an s2idle wake. So the fix matters on the T8112 transport as well as T6050.

@Isaac-Duarte

Copy link
Copy Markdown
Contributor Author

The #2100 conflict is real on J714s, and the bad order is the one this machine has. Multi-touch is DockChannel interface 1, the actuator interface 4, and dockchannel_hid_resume() resumes them in index order. With both PRs and haptic_press=Y (set by the distro rule, per the J415 report), every wake would leave host mode cached with the firmware in device mode: two clicks per press.

I'd keep the mode in the trackpad driver, the only one holding the cache. This PR covers #2100's case too: with effects loaded, resume asserts host mode and caches it, so the button is derived on the host instead of waiting for a firmware button that host mode never reports. That's from the code and the loaded-effects harness case; I have no J614c to test it on. If this lands, #2100's actuator-side switch can go; I've noted it there.

Agreed on haptic_press: the module-wide clear predates this PR. Keeping this one on #2025; the per-device flag can be a follow-up.

Hardware: the J714s now runs integration/aurora 0abc2f3 plus this PR's head (same patch as e12a699), haptic_press=Y. Two s2idle wakes today (1 h 24 min, ~1 s). After each, the MTP logged the host-mode handoff from the resume path (Intercepted 0x21 click handoff: 01), there were no magicmouse warnings, and a physical press gave exactly one click.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Review (merge lane), head e12a69972e56:

The suspend/resume handling holds up.

  • Lock order: it is always actuator mutex, then haptic_lock. Nothing sleeps under the spinlock, and cancel_work_sync/flush_workqueue never run while holding a lock the workers take.
  • No I/O while suspended: every path that talks to the actuator checks haptic_suspended under the mutex: pulses, release, upload, the playback worker and erase. The flag's window covers the transport's whole refusal window.
  • Default behaviour: with haptic_press=N and no effects loaded, suspend and resume send nothing.
  • Other trackpads: USB/Bluetooth Magic Mouse/Trackpad, and other paths without haptics, return before touching the new state.
  • Drift: nothing under drivers/hid changed between the merge-base and the tip, so the merged driver is byte-identical to this branch.

Local checks on the merge into integration/aurora 1473d156d6ca, rechecked on the current tip 4c4cbf086071:

  • hid-magicmouse.o builds with W=1.
  • The mtp host tests pass (6/6), including both negative controls.

Follow-ups, none blocking:

  • Lockdep false positive: magicmouse_force_key() now runs under haptic_lock, and apple_taptic_playback() takes haptic_lock inside ff-core's event_lock. All input event_locks share one lockdep class, so a lockdep kernel with haptic_deep_keycode set reports a cycle. It can't really deadlock, because they are different devices. Deciding the key release under the lock and reporting it after unlocking would silence it.
  • CONFIG_PM=n: magicmouse_haptic_suspend/_resume are unused there, which is -Wunused-function and an error with CONFIG_WERROR. forget_mode had the same issue before this PR. __maybe_unused fixes it.
  • Resume cost: with haptic_press=Y, resume now sends the 0x21 mode request synchronously. That is one DockChannel round trip, or up to the command timeout if the MTP stalls. It's fine, just noting it for the sleep timings.
  • The negative control reads 62d2045d8928 by hash, so this must land as a merge commit, which is how we merge.

#2100: with this in, its actuator-side switch to device mode on resume conflicts with this resume path. On J714s the trackpad (interface 1) resumes before the actuator (interface 4), so haptic_press=Y would cache host mode while the firmware is in device mode, and every press would click twice. #2100 should drop that switch; I'll note it there.

Merging. The J714s sleep row (default N and haptic_press=Y, short and long s2idle/deep sleep, one click per press, no late pulse, no stuck button) is post-merge.

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.

hid-magicmouse: a click waveform failing during suspend (-EBUSY) leaves the J714s trackpad with no click until rebind

3 participants