如何安装简单的usb hotplug驱动程序?

时间:2016-01-17 21:18:17

标签: c linux linux-kernel usb kernel-module

我的理解是struct usb_driver可以使用module_usb_driver()绑定到内核模块,这允许.probe()决定是否在连接时处理设备。< / p>

我似乎错了,因为当我插入USB键盘时,以下模块似乎没有得到probe()

#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);

我正在尝试通过使用make进行编译来安装它,然后insmod进行编译。然后我插入我的MS600键盘(并重复拔掉它),但我的probe永远不会被调用。

will@Desk ~/code/eudypt/eudyptula5 $ dmesg | grep Hello
[44553.388256] usbcore: registered new interface driver Hello USB

然后我rmmod,然后成功删除:

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()的工作原理吗?我是否必须使用此模块重新编译新内核?

0 个答案:

没有答案
相关问题