C 如何安装简单的usb热插拔驱动程序?
据我所知,C 如何安装简单的usb热插拔驱动程序?,c,linux,linux-kernel,usb,kernel-module,C,Linux,Linux Kernel,Usb,Kernel Module,据我所知,struct usb\u驱动程序可以使用module\u usb\u driver()绑定到内核模块,这允许.probe()决定是否在设备连接时处理设备 我似乎弄错了,因为当我插入usb键盘时,下面的模块似乎没有得到probe()ed #include <linux/module.h> #include <linux/kernel.h> #include <linux/usb.h> #define USB_VENDOR_ID 0x045e /*
struct usb\u驱动程序
可以使用module\u usb\u driver()
绑定到内核模块,这允许.probe()
决定是否在设备连接时处理设备
我似乎弄错了,因为当我插入usb键盘时,下面的模块似乎没有得到probe()
ed
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/usb.h>
#define USB_VENDOR_ID 0x045e /* Microsoft */
#define USB_PRODUCT_ID 0x0750 /* Wired Keyboard 600 (model 1366) */
static int init_my_module(struct usb_interface *intf, const struct usb_device_id *id)
{
pr_debug("Hello USB probe!\n");
return -ENODEV; /* Don't actually handle the device */
}
static void cleanup_my_module(struct usb_interface *intf)
{
pr_debug("Goodbye USB!\n");
}
static const struct usb_device_id device_table[] = {
{ USB_DEVICE(USB_VENDOR_ID, USB_PRODUCT_ID) },
{ } /* Terminating entry */
};
static struct usb_driver hello_driver = {
.name = "Hello USB",
.probe = init_my_module,
.disconnect = cleanup_my_module,
.id_table = device_table
};
MODULE_DEVICE_TABLE(usb, device_table);
module_usb_driver(hello_driver);
然后Irmmod
it,它被成功删除:
will@Desk ~/code/eudypt/eudyptula5 $ dmesg | grep Hello
[44553.388256] usbcore: registered new interface driver Hello USB
[45010.513570] usbcore: deregistering interface driver Hello USB
因此,我的模块似乎正在注册到
usbcore
,但它没有探测到它。我是否误解了probe()
的工作原理?我是否必须重新编译包含此模块的新内核?相关:我查看了答案,我的/lib/udev/rules.d/80驱动程序。rules
没有他提到的删除部分。OP there刚刚在一个虚拟机上试用了它,这显然是有效的,但我特别想知道我是否使用了probe
错误,或者insmod
不适合这种类型的模块。
will@Desk ~/code/eudypt/eudyptula5 $ dmesg | grep Hello
[44553.388256] usbcore: registered new interface driver Hello USB
[45010.513570] usbcore: deregistering interface driver Hello USB