22

I am writing a USB device drive for linux. it's for a joystick. every time plug it in, linux loads a hid driver. is there a way to tell Linux to load mine when I plug it in? or at least not load the default one?

I can echo the id in unbind of the default driver and echo it in bind of my driver; but I would like something more automatic.. thanks

pvinis
  • 3,855
  • 5
  • 33
  • 55
  • What does "linux lad a hid driver" mean? – Marcelo Cantos Oct 16 '10 at 00:06
  • @Marcelo Cantos: I think he meant to write "Linux loads an HID driver." HID = Human Interface Device. – Amardeep AC9MF Oct 16 '10 at 02:19
  • If you have full access to the kernel source tree, you can add the driver to the `hid_have_special_driver` array in `drivers/hid/hid-core.c`. That will cause `hid-generic` to ignore the device. But I very much hope that there is a solution which can work without modifying existing modules, and which would therefore be suitable for extra modules added via DKMS or similar. Unfortunately there appears to be no `usbhid` quirk for this use case. – MvG May 06 '15 at 22:16

3 Answers3

12

Own USB driver taking precedence over usbhid

If you want to prevent binding to the usbhid driver, you can use its HID_QUIRK_IGNORE (= 4) setting. To stick with the example Karl Bielefeldt used, add

options usbhid quirks=0x15c2:0x0043:0x04

to some /etc/modprobe.d/*.conf file (and perhaps recreate your initramfs). That will tell hid-core to ignore that device. So usbhid will have a look at it but leave it for some other driver instead.

Own HID driver taking precedence over hid-generic

However, if your other driver is a HID driver not an USB driver, then you need usbhid to bind to the driver on the USB level, and you need your own HID driver to take precedence over hid-generic. This is the problem I'm facing my self, and for which I haven't found a solution yet, short of unbinding and rebinding the device later on.

MvG
  • 51,562
  • 13
  • 126
  • 251
  • This hid-generic rebinding is such a hassle. I wonder how nobody found a better solution. And there is SO LITTLE information in the Internet, that I wonder if anyone actually writes drivers for Linux in the first place. – Vladius Oct 13 '18 at 12:17
4

Here's a thread with a fix for a similar problem. To summarize, you add something like the following to one of your /etc/udev/rules.d files:

SYSFS{idVendor}=="15c2", SYSFS{idProduct}=="0043", MODE="0666", PROGRAM="/bin/sh -c 'echo -n $id:1.0 >/sys/bus/usb/drivers/usbhid/unbind;\
echo -n $id:1.1 >/sys/bus/usb/drivers/usbhid/unbind'"
Karl Bielefeldt
  • 42,558
  • 9
  • 56
  • 88
1

http://lwn.net/Articles/143397/ is very similar to the above answer, maybe some more details.

Matteo Gamboz
  • 335
  • 2
  • 10
  • Link-only answers are discouraged on StackOverflow. The answer itself should contain the essential useful information. Links are good as references. – Craig McQueen Jan 20 '16 at 23:10