question

SunWane-4376 avatar image
0 Votes"
SunWane-4376 asked SunWane-4376 commented

How to implement S0 idle for HID mini-driver

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-hardwarewindows-hardware-wdkwindows-hardware-code-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DoronHolan avatar image
0 Votes"
DoronHolan answered SunWane-4376 commented

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

Selective suspend for HID over USB devices: https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/selective-suspend-for-hid-over-usb-devices
IOCTL_HID_SEND_IDLE_NOTIFICATION_REQUEST IOCTL: https://docs.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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for your answer. My driver is for the HID over I2C device, but selective suspend is for HID over USB. The hidusbfx2 sample is also a driver for HID over USB devices. So can I use this for HID over I2C?

0 Votes 0 ·
DoronHolan avatar image
0 Votes"
DoronHolan answered SunWane-4376 commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

OK, Thanks very much! I will try it.

0 Votes 0 ·