Skip to content

feat(usb): gadget: f_hid: add wakeup_on_write support#57

Open
jlian wants to merge 1 commit intojetkvm:devfrom
jlian:feat/usb-hid-wakeup-on-write
Open

feat(usb): gadget: f_hid: add wakeup_on_write support#57
jlian wants to merge 1 commit intojetkvm:devfrom
jlian:feat/usb-hid-wakeup-on-write

Conversation

@jlian
Copy link

@jlian jlian commented Mar 2, 2026

Summary

Add a wakeup_on_write configfs attribute to the USB HID gadget function driver (f_hid). When enabled, the driver calls usb_gadget_wakeup() before writing each HID report, allowing the gadget to wake a suspended host via USB remote wakeup.

This is the kernel-side prerequisite for USB remote wakeup on JetKVM. The companion Go app change sets bmAttributes = 0xa0 and enables wakeup_on_write on all HID functions during gadget setup. The Go app side changed, required to make this feature work end to end, are at jetkvm/kvm#1235.

Related: jetkvm/kvm#120, jetkvm/kvm#674.

How it works

  • New wakeup_on_write boolean attribute in the HID function's configfs directory
  • Default: 0 (off). Must be set to 1 before the function is allocated (same lifecycle as no_out_endpoint)
  • When enabled, f_hidg_write() calls usb_gadget_wakeup() at the top of each write. If the host hasn't negotiated remote wakeup or the bus isn't suspended, the call returns an error that is safely ignored
  • Zero impact on existing behavior when disabled

Changes

  • f_hid.c: Add wakeup_on_write field to f_hidg, call usb_gadget_wakeup() in f_hidg_write(), register configfs attribute via F_HID_OPT macro
  • u_hid.h: Add wakeup_on_write field to f_hid_opts

Testing

Tested on JetKVM v2 (RV1106, DWC3 v3.30a, kernel 5.10.160). Host: Windows 11 (S3 sleep), Intel Z390 xHCI.

  1. wakeup_on_write attribute appears in configfs for all HID functions
  2. Host enumerates with remote wakeup capability (bmAttributes = 0xa0)
  3. Host enters S3 sleep, USB link enters L2 suspend
  4. HID write triggers usb_gadget_wakeup() → DWC3 sends Recovery on the bus → host wakes
  5. powercfg /lastwake confirms wake source: Intel USB 3.1 eXtensible Host Controller

More testing details at jetkvm/kvm#1235.

@CLAassistant
Copy link

CLAassistant commented Mar 2, 2026

CLA assistant check
All committers have signed the CLA.

Add an opt-in wakeup_on_write configfs attribute to the HID function
driver.  When enabled, each write to /dev/hidgN calls
usb_gadget_wakeup() before queuing the USB request, allowing HID input
to wake a suspended host.

The configuration descriptor must also advertise remote wakeup capability
(bmAttributes bit 5) for the host to arm the feature during enumeration.

This is useful for KVM-over-IP devices that need to wake a sleeping host
machine by sending keyboard or mouse input.

Tested on JetKVM v2 (RV1106 SoC, DWC3 v3.30a) waking a Windows 11 host
from S3 sleep via Intel xHCI USB 3.1 controller.  Host wakes in ~4
seconds from HID keystroke.

Closes: jetkvm/kvm#120
Closes: jetkvm/kvm#674
@jlian jlian force-pushed the feat/usb-hid-wakeup-on-write branch from 6761342 to 900c018 Compare March 2, 2026 05:20
@jlian jlian changed the title usb: gadget: f_hid: add wakeup_on_write support feat(usb): gadget: f_hid: add wakeup_on_write support Mar 2, 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.

2 participants