How to implement S0 idle for HID mini-driver

Sun Wane 41 Reputation points
2022-04-14T11:06:57.007+00:00

Hi, All:
I need to write a HID mini-driver for a HID device. I reference to the windows sample: vhidmini2. I have implemented the basic functions and it works well. Now I want to implement S0 idle for my device, but because the mini-driver is not the power policy owner (default the hid class driver is), so WdfDeviceAssignS0IdleSettings fails with 0xC0000010.
I notices that there are two IOCTLs named IOCTL_HID_ACTIVATE_DEVICE and IOCTL_HID_DEACTIVATE_DEVICE, and I think that maybe I can sleep and wake my device when I receive the two IOCTLs. But no matter how long I wait (not use my device, no interrupts and other IOCTLs), I can not receive IOCTL_HID_ACTIVATE_DEVICE and IOCTL_HID_DEACTIVATE_DEVICE.
My question is: How to implement S0 idle for my HID mini-driver and device?
Should I call WdfDeviceInitSetPowerPolicyOwnership to set the mini-driver as the power policy owner or something else?

Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,551 questions
0 comments No comments
{count} votes

Accepted answer
  1. Doron Holan 1,801 Reputation points
    2022-05-17T05:55:45.407+00:00

    Hidclass the port driver doesn’t know about the miniport’s transport. That means hidclass manages selective suspend (s0 idle) state without knowing how to turn the device off, it relies on the mini port driver to turn off when told.

    The INF settings for hidusbfx2 tell hidclass that selective suspend is supported. You need to copy these to your inf. Your mini port then needs to properly handle IOCTL_HID_SEND_IDLE_NOTIFICATION_REQUEST. When it receives this ioctl you need to turn off the device with your custom logic over i2c.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Doron Holan 1,801 Reputation points
    2022-04-20T21:04:24.393+00:00

    You need to tell hidclass that you support s0 idle (called selective suspend)

    Selective suspend for HID over USB devices: https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/selective-suspend-for-hid-over-usb-devices
    IOCTL_HID_SEND_IDLE_NOTIFICATION_REQUEST IOCTL: https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/hidport/ni-hidport-ioctl_hid_send_idle_notification_request

    the docs show how to enable it, but not really how to handle it in a driver. the hidusbfx2 sample does show how to handle IOCTL_HID_SEND_IDLE_NOTIFICATION_REQUEST,
    https://github.com/microsoft/Windows-driver-samples/blob/main/hid/hidusbfx2/sys/hid.c