2012-03-26 55 views
0

我想學習USB Linux設備驅動程序。我選擇了MS XBOX 360控制器。我注意到有一個用於Linux的通用驅動程序(xpad.ko)。不用說,我的代碼是基於xpad.c.無論如何,我建立了我的司機(360.ko)。 modprobe -r當前驅動程序(xpad,led_class,甚至usbhid)。也列入黑名單xpad驅動程序。在我的司機(360.ko)上做了insmod。 USBcore註冊我的驅動程序(usbcore:註冊的新接口驅動程序Microsoft Xbox 360控制器)。但是,它不會調用我的usb_360_probe()。任何線索?????360遊戲控制器Linux設備驅動程序問題調用我的探測功能

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消息。它適用於我的其他字符驅動程序。

內核:2.6.32-21-通用

回答

0

你在哪裏發起的cdev結構?根據我的經驗,我基本上只是製作一個cdev結構,然後告訴內核。你的file_operations結構負責調用該函數。我在驅動程序中沒有看到任何這些結構。現在,我在寫入驅動程序方面很新穎,但我知道所有驅動程序都需要啓動cdev結構體,file_operation結構體和打開文件結構體來執行任何操作。一本能夠幫助我很多的書是一本免費的pdf,你可以在谷歌linux設備驅動程序第3版。也許這有幫助。祝你好運。

+0

探針通常在打開,關閉和其他文件操作之前發生。另外,我不需要用戶應用程序來打開,關閉等系統調用。在探測器內部,它使用USB-中斷來捕獲按鈕按下等事件。該代碼在探針內部進入,我將所有代碼截斷。我的問題是probe()沒有調用。 – user1294023 2012-03-27 21:46:56

1

當找到插入了給定供應商ID產品ID的設備時,將調用您的探測功能。你有上述設備嗎?它是否被插入?

+0

當然是插入設備。 dmesg顯示:(360)usb_360_init。 usbcore:註冊新的界面驅動程序Microsoft Xbox 360控制器。 (36)usb_register成功。但沒有調查()電話!另外,dmesg顯示:usb 2-1:使用uhci_hcd和地址5的全速USB設備。usb 2-1:從1個選項中選擇的配置1。 – user1294023 2012-03-28 17:02:57

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 

-v的lsusb表示:

/* 總線002的設備003:ID 045E:028E微軟公司的Xbox360控制器

設備描述符: bLeng第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 的bConfiguration Value 1 iConfiguration 0 bmAttributes 0XA0 (總線供電) 遠程喚醒 MAXPOWER500毫安 接口描述符: bLength 9 bDescriptorType 4 b接口編號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端點0×81 EP 1 IN bmAttributes 3 傳輸類型中斷 同步類型無 用法類型數據 wMaxPacketSize 0×0020 1×32 BYT es b間隔4 */

相關問題