我正在为 Kernel 4.1.0-rc8 的 Logitech G110 USB 键盘编写驱动程序。
我的驱动程序完全可以使用 insmod 加载(调试消息打印到dmesg
它已通过 初始化module_init
)。
modprobe
显示列表中的模块就好了(有 0 个设备使用它)
但是,当我插入键盘时,内核似乎识别了制造商和类型,并加载了特定的驱动程序:
[ 3611.699275] usb 6-5: new high-speed USB device number 11 using ehci-pci
[ 3611.815794] usb 6-5: New USB device found, idVendor=05e3, idProduct=0607
[ 3611.815803] usb 6-5: New USB device strings: Mfr=0, Product=1, SerialNumber=0
[ 3611.815807] usb 6-5: Product: USB2.0 Hub
[ 3611.817753] hub 6-5:1.0: USB hub found
[ 3611.818776] hub 6-5:1.0: 4 ports detected
[ 3612.086996] usb 6-5.1: new low-speed USB device number 12 using ehci-pci
[ 3612.171428] usb 6-5.1: New USB device found, idVendor=046d, idProduct=c22b
[ 3612.171436] usb 6-5.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 3612.171441] usb 6-5.1: Product: G110 G-keys
[ 3612.171445] usb 6-5.1: Manufacturer: LOGITECH
[ 3612.179099] input: LOGITECH G110 G-keys as /devices/pci0000:00/0000:00:13.2/usb6/6-5/6-5.1/6-5.1:1.0/0003:046D:C22B.0014/input/input32
[ 3612.230502] hid-generic 0003:046D:C22B.0014: input,hiddev0,hidraw0: USB HID v1.00 Keypad [LOGITECH G110 G-keys] on usb-0000:00:13.2-5.1/input0
[ 3612.230768] usbhid 6-5.1:1.1: couldn't find an input interrupt endpoint
[ 3612.294146] usb 6-5.3: new low-speed USB device number 13 using ehci-pci
[ 3612.377583] usb 6-5.3: New USB device found, idVendor=046d, idProduct=c22a
[ 3612.377591] usb 6-5.3: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 3612.377596] usb 6-5.3: Product: Gaming Keyboard G110
[ 3612.384673] input: Gaming Keyboard G110 as /devices/pci0000:00/0000:00:13.2/usb6/6-5/6-5.3/6-5.3:1.0/0003:046D:C22A.0015/input/input33
[ 3612.435649] hid-generic 0003:046D:C22A.0015: input,hidraw1: USB HID v1.10 Keyboard [Gaming Keyboard G110] on usb-0000:00:13.2-5.3/input0
[ 3612.443182] input: Gaming Keyboard G110 as /devices/pci0000:00/0000:00:13.2/usb6/6-5/6-5.3/6-5.3:1.1/0003:046D:C22A.0016/input/input34
[ 3612.494710] hid-generic 0003:046D:C22A.0016: input,hiddev0,hidraw2: USB HID v1.10 Device [Gaming Keyboard G110] on usb-0000:00:13.2-5.3/input1
即使接口注册得很好:
[ 4024.380949] usbcore: registered new interface driver usbkeyboard
该表具体规定如下:
struct usb_device_id custom_usb_table[] = {
{ USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID,
USB_INTERFACE_SUBCLASS_BOOT, USB_INTERFACE_PROTOCOL_KEYBOARD)},
{ }
};
MODULE_DEVICE_TABLE(usb, custom_usb_table);
司机:
static struct usb_driver usb_keyboard_driver = {
.name = "usbkeyboard",
.probe = usb_probe,
.disconnect = usb_disconnect,
.id_table = custom_usb_table
};
功能usb_probe
:
static int usb_probe(struct usb_interface *usb_iface,
const struct usb_device_id *usb_devid)
{
printk(KERN_DEBUG "CUSTOM-MODULE: USB device was plugged in!\n");
return 0;
}
和module_init
触发器:
static int initialize(void)
{
int retVal = 0;
retVal = usb_register(&usb_keyboard_driver);
printk(KERN_DEBUG "CUSTOM-MODULE: initialize() called!\n");
if (retVal)
printk(KERN_DEBUG "CUSTOM-MODULE: Error %d registering driver!\n", retVal);
return 0;
}
(我知道 printk 是迄今为止打印此调试信息的最丑陋的方式,并且有很多选项更好,但这不是现在的重点)。
我的问题是:
- 我在上面假设内核“更喜欢”特定的 Logitech 驱动程序而不是我编写的通用键盘接口。它是否正确?
- 有没有一种方法可以告诉内核在下次重新启动之前不要使用 Logitech 驱动程序,而是使用通用接口驱动程序?