我正在尝试学习USB Linux设备驱动程序。我选择了MS XBOX 360控制器。我注意到Linux有一个通用驱动程序(xpad.ko)。不用说,我的代码基于xpad.c.无论如何,我建立了我的驱动程序(360.ko)。 modprobe -r on current driver(xpad,led_class,甚至usbhid)。还列入黑名单的xpad驱动程序。 insmod在我的驱动程序上(360.ko)。 USBcore注册我的驱动程序(usbcore:注册的新接口驱动程序Microsoft Xbox 360控制器)。但是,它不会调用我的usb_360_probe()。任何线索?????
static struct usb_driver uDriver = {
.name = "Microsoft Xbox 360 Controller",
.probe = usb_360_probe,
.disconnect = usb_360_disconnect,
.id_table = skel_table,
};
#define USB_360_VENDOR_ID 0x045E
#define USB_360_PRODUCT_ID 0x0202//0x0289//0x028E //I tried all these product IDs!
static struct usb_device_id skel_table[] = {
{ USB_DEVICE(USB_360_VENDOR_ID, USB_360_PRODUCT_ID) },
{},
};
static int usb_360_probe(struct usb_interface *intf, const struct usb_device_id*id)
{
printk(KERN_INFO, "(360)usb_360_probe.\n");
}
static int __init usb_360_init(void)
{
int result;
printk(KERN_INFO, "(360)usb_360_init.\n");
/* register this driver with the USB subsystem */
result = usb_register(&uDriver);
if (result)
{
printk(KERN_INFO, "(360)usb_register failed.\n");
}
printk(KERN_INFO, "(360)usb_register succeeded.\n");
return result;
}
static void __exit usb_360_exit(void)
{
/* deregister this driver with the USB subsystem */
usb_deregister(&uDriver);
printk(KERN_INFO, "(360)usb_unregister succeeded.\n");
}
module_init(usb_360_init);
module_exit(usb_360_exit);
//我正在使用printk(KERN_INFO)来获取dmesg消息。它适用于我的其他char驱动程序。
kernel:2.6.32-21-generic
答案 0 :(得分:1)
当找到插入了具有给定供应商ID产品ID的设备时,将调用您的探测功能。你有上述设备吗?它插入了吗?
答案 1 :(得分:0)
你在哪里发起cdev结构?根据我的经验,我基本上只是创建一个cdev结构,然后告诉内核它。您的file_operations结构负责调用该函数。我在你的驱动程序中没有看到任何这些结构。现在我对编写驱动程序非常陌生,但我知道所有驱动程序都需要启动cdev结构,file_operation结构和打开文件结构来执行任何操作。一本帮助我很多的书是免费的PDF文件,你可以谷歌Linux设备驱动程序第3版。也许这有帮助。祝你好运。
答案 2 :(得分:0)
伙计们我找到了解决方案。 vedasolutions是对的。产品ID错误。一改变产品ID就调用probe()。此外,我必须提高日志记录级别以查看我的消息。为简单起见,我刚刚在printk中取出了KERN_INFO,它记录了dmesg中的所有消息。不管怎么说,多谢拉。
但是我有另一个问题:(。现在我的探测被多次调用.4次并导致空指针异常。看起来探测失败,所以它重试再次探测。 这是dmesg的日志---->
(360)usb_360_init.
[410803.812983] usbcore: registered new interface driver Microsoft Xbox 360 Controller
[410803.813017] (360)usb_register succeeded.
[410816.146730] usb 2-1: new full speed USB device using uhci_hcd and address 9
[410816.318924] usb 2-1: configuration #1 chosen from 1 choice
[410816.332264] (360)usb_360_probe.
[410816.332281] (360)usb_360_probe device found!!.
[input: 360 as /devices/pci0000:00/0000:02:00.0/usb2/2-1/2-1.0/input/input4
[410816.372435] (360)probe succeeded.
[410816.372509] Microsoft Xbox 360 Controller: probe of 2-1:1.0 failed with error 1
[410816.372624] (360)usb_360_probe.
[410816.372626] (360)usb_360_probe device found!!.
input: 360 as /devices/pci0000:00/0000:02:00.0/usb2/2-1/2- 1:1.1/input/input5
[410816.372739] (360)probe succeeded.
[410816.372748] Microsoft Xbox 360 Controller: probe of 2-1:1.1 failed with error 1
[410816.374083] (360)usb_360_probe.
[410816.374088] (360)usb_360_probe device found!!.
input: 360 as /devices/pci0000:00/0000:02:00.0/usb2/2-1/2-1:1.2/input/input6
[410816.374852] (360)probe succeeded.
[410816.374871] Microsoft Xbox 360 Controller: probe of 2-1:1.2 failed with error 1
[410816.378827] (360)usb_360_probe.
[410816.379168] (360)usb_360_probe device found!!.
[410816.380925] BUG: unable to handle kernel NULL pointer dereference at 00000006
[410816.380967] IP: [<f84ae438>] usb_360_probe+0x1a8/0x318 [360]
[410816.381485] *pde = bf838067
[410816.381601] Oops: 0000 [#1] SMP
[410816.381643] last sysfs file: [410816.382272] Pid: 44, comm: khubd Not tainted
(2.6.32-21-generic #32-Ubuntu) VMware Virtual Platform
lsusb -v显示:
/ * 总线002设备003:ID 045e:028e Microsoft Corp. Xbox360控制器
设备描述符: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 255供应商特定类 bDeviceSubClass 255供应商特定子类 bDeviceProtocol 255供应商特定协议 bMaxPacketSize0 8 idVendor 0x045e微软公司 idProduct 0x028e Xbox360控制器 bcdDevice 1.14 iManufacturer 1 iProduct 2 iSerial 3 bNumConfigurations 1 配置描述符: bLength 9 bDescriptorType 2 wTotalLength 153 bNumInterfaces 4 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xa0 (总线供电) 远程唤醒 MaxPower 500mA 接口描述符: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 255供应商特定类 bInterfaceSubClass 93 bInterfaceProtocol 1 iInterface 0 **未确认:11 21 00 01 01 25 81 14 00 00 00 00 13 01 08 00 00 (问题?????? !!!) 端点描述符: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 传输类型中断 同步类型无 使用类型数据 wMaxPacketSize 0x0020 1x 32字节 bInterval 4 * /