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?
我正在为linux编写USB设备驱动器。这是一个操纵杆。每次插入时,linux都会加载一个hid驱动程序。有什么方法可以告诉Linux在插入时加载我的?或者至少不加载默认值?
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
我可以在默认驱动程序的unbind中回显id,并在我的驱动程序绑定中回显它;但我想要更自动的东西..谢谢
3 个解决方案
#1
10
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
如果要阻止绑定到usbhid驱动程序,可以使用其HID_QUIRK_IGNORE(= 4)设置。坚持使用Karl Bielefeldt的例子,加上
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.
到一些/etc/modprobe.d/*.conf文件(也许重新创建你的initramfs)。这将告诉hid-core忽略该设备。所以usbhid会看一下它,但留给其他司机代替。
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.
但是,如果您的其他驱动程序是HID驱动程序而不是USB驱动程序,那么您需要usbhid绑定到USB级别的驱动程序,并且您需要自己的HID驱动程序优先于hid-generic。这是我面临的问题,我还没有找到解决方案,缺少解绑和重新绑定设备。
#2
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:
这是一个修复类似问题的线程。总而言之,您可以在/etc/udev/rules.d文件中添加以下内容:
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'"
#3
1
http://lwn.net/Articles/143397/ is very similar to the above answer, maybe some more details.
http://lwn.net/Articles/143397/与上面的答案非常相似,可能还有一些细节。
#1
10
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
如果要阻止绑定到usbhid驱动程序,可以使用其HID_QUIRK_IGNORE(= 4)设置。坚持使用Karl Bielefeldt的例子,加上
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.
到一些/etc/modprobe.d/*.conf文件(也许重新创建你的initramfs)。这将告诉hid-core忽略该设备。所以usbhid会看一下它,但留给其他司机代替。
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.
但是,如果您的其他驱动程序是HID驱动程序而不是USB驱动程序,那么您需要usbhid绑定到USB级别的驱动程序,并且您需要自己的HID驱动程序优先于hid-generic。这是我面临的问题,我还没有找到解决方案,缺少解绑和重新绑定设备。
#2
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:
这是一个修复类似问题的线程。总而言之,您可以在/etc/udev/rules.d文件中添加以下内容:
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'"
#3
1
http://lwn.net/Articles/143397/ is very similar to the above answer, maybe some more details.
http://lwn.net/Articles/143397/与上面的答案非常相似,可能还有一些细节。