I would like to bind a hid device to a specific driver.
Unfortunately hid-generic somehow "steals" the binding when the device is reconnected.
I know i can unbind and bind the device by hand this way:
# echo ... > /sys/bus/hid/drivers/hid-generic/unbind
# echo ... > /sys/bus/hid/drivers/customdriver/bind
But isn't there something like a priority for drivers to automatically bin a device to a driver?
Thank you in advance!
I found two ways to automatically bind a device to my driver
Adding the device to the hid_have_special_driver struct in hid-core.c.
The struct looks somthing like that:
static const struct hid_device_id hid_have_special_driver[] = {
#if IS_ENABLED(CONFIG_HID_A4TECH)
{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
{ HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
#endif
//...
{}
}
This is how it is normally done, I haven't tried it yet. You have to recompile hid-core.c (hid.ko).
Using the bind and unbind functionality inside an udev-rule.
Add a new rule to /etc/udev/rules.d/ (e.g. 99-mydriver.rules) which automatically unbinds the device from hid-generic and binds it to your driver
Under Arch Linux x86_64:
ACTION=="bind", KERNELS=="0005:<VENDOR_ID>:<PRODUCT_ID>.*", SUBSYSTEMS=="hid", DRIVERS=="hid-generic", \
RUN+="/bin/bash -c 'echo $kernel > /sys/bus/hid/drivers/$driver/unbind'", \
RUN+="/bin/bash -c 'echo $kernel > /sys/bus/hid/drivers/<MY_DRIVER>/bind'"
Under Raspbian Stretch the following works for me
ACTION=="add", KERNEL=="0005:<VENDOR_ID>:<PRODUCT_ID>.*", SUBSYSTEM=="hid", DRIVER=="hid-generic", \
RUN+="/bin/bash -c 'echo $kernel > /sys/bus/hid/drivers/hid-generic/unbind'", \
RUN+="/bin/bash -c 'echo $kernel > /sys/bus/hid/drivers/<MY_DRIVER>/bind'"
Replace <VENDOR_ID>, <PRODUCT_ID> and <MY_DRIVER> as needed
Further Information: http://0x0001.de/linux-driver-loading-registration-and-binding/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With