Seeking Assistance: Implementing USB Device Suspend/Resume in User Space Driver

Alan Stern stern at rowland.harvard.edu
Mon May 6 15:50:15 EDT 2024


On Mon, May 06, 2024 at 09:44:52PM +0530, Muni Sekhar wrote:
> On Mon, May 6, 2024 at 7:59 PM Alan Stern <stern at rowland.harvard.edu> wrote:
> >
> > On Mon, May 06, 2024 at 04:44:30PM +0530, Muni Sekhar wrote:
> > > While we have successfully converted most of the USB device driver
> > > functionality from kernel space to user space using libusb, we are now
> > > seeking guidance on how to implement USB device suspend/resume in user
> > > space. Specifically, we would like to know if libusb provides support
> > > for achieving the suspend/resume functionality mentioned above.
> > > Additionally, any insights or suggestions on how to accomplish this
> > > task would be greatly appreciated.
> >
> > Your question is about libusb, right?  So you'll get better answers if
> > you post it on the libusb mailing list rather than the linux-usb mailing
> > list.
> Can USB device suspend\resume  be implemented in user space driver
> using software other than libusb?

Yes, a userspace driver can use the usbfs interface and can employ the 
ioctl commands listed in /usr/include/linux/usbdevfs.h.  It's possible 
that libusb also provides facilities for controlling suspend and resume; 
I don't know whether it does.

> If so, what are those methods or techniques to achieve USB device
> suspend\resume , can you please provide clarity on this.

As far as I know, these usbfs ioctl commands are not documented 
anywhere.

The USBDEVFS_FORBID_SUSPEND ioctl prevents the device from being 
suspended, and wakes it up if it is currently suspended.

The USBDEVFS_ALLOW_SUSPEND ioctl allows the device to be suspended.  The 
suspend may not happen immediately; it is controlled by the settings in 
the device's power/control and power/autosuspend (or 
power/autosuspend_delay_ms) sysfs attribute files.

The USBDEVFS_WAIT_FOR_RESUME ioctl waits until the device resumes, 
whether because of a remote wakeup or because another process has 
resumed it, and then forbids the device from suspending again until 
you perform another USBDEVFS_ALLOW_SUSPEND ioctl.

Alan Stern



More information about the Kernelnewbies mailing list