1

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!

ataraxis
  • 1,257
  • 1
  • 15
  • 30
  • 1
    I think there may be a blacklist in generic hid. Check this https://unix.stackexchange.com/questions/55495/prevent-usbhid-from-claiming-usb-device – Chris Tsui Nov 30 '17 at 02:53
  • U can use udev rules for that. Take a look at this answer: https://stackoverflow.com/questions/38786343/prevent-usbhid-from-autoloading-when-usb-hid-device-is-plugged-in – Ortwin Angermeier Dec 31 '17 at 11:00
  • @OrtwinAngermeier Thanks - but you are 3 minutes too late :D (see the second entry in my answer) – ataraxis Dec 31 '17 at 11:09

1 Answers1

0

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/

ataraxis
  • 1,257
  • 1
  • 15
  • 30