接上文,配置编译gadget HID模块
make modules后在driver/usb/gadget目录下生成g_hid.ko
执行加载命令:
root@XXX:/mnt# insmod g_hid.ko insmod: can't insert 'g_hid.ko': No such device
提示错误。
在TI 技术论坛上看到相关技术回复:
-
The error message you had before 'error inserting 'g_hid.ko': -1 No such device.' is due to incomplete hid gadget driver. You can followDocumentation/usb/gadget_hid.txt
to add your own platform device portion.For your reference, the following patch is what I tried and it works with the 3.3 kernel from the link I provided above with SD card boot.
下载提及的补丁
From 6363b29be2c2b477a723b74e52025511be280979 Mon Sep 17 00:00:00 2001 From: Bin Liu <b-liu@ti.com> Date: Fri, 18 Jan 2013 10:27:57 -0600 Subject: [PATCH] patched hid gadget --- drivers/usb/gadget/hid.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 61 insertions(+), 0 deletions(-) diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c index f888c3e..c037039 100644 --- a/drivers/usb/gadget/hid.c +++ b/drivers/usb/gadget/hid.c @@ -16,6 +16,8 @@ #include <linux/platform_device.h> #include <linux/list.h> +#include <linux/usb/g_hid.h> + #define DRIVER_DESC "HID Gadget" #define DRIVER_VERSION "2010/03/16" @@ -49,6 +51,57 @@ struct hidg_func_node { static LIST_HEAD(hidg_func_list); + +/* hid descriptor for a keyboard */ +static struct hidg_func_descriptor my_hid_data = { + .subclass = 0, /* No subclass */ + .protocol = 1, /* Keyboard */ + .report_length = 8, + .report_desc_length = 63, + .report_desc = { + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ + 0x09, 0x06, /* USAGE (Keyboard) */ + 0xa1, 0x01, /* COLLECTION (Application) */ + 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ + 0x19, 0xe0, /* USAGE_MINIMUM (Keyboard LeftControl) */ + 0x29, 0xe7, /* USAGE_MAXIMUM (Keyboard Right GUI) */ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ + 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ + 0x75, 0x01, /* REPORT_SIZE (1) */ + 0x95, 0x08, /* REPORT_COUNT (8) */ + 0x81, 0x02, /* INPUT (Data,Var,Abs) */ + 0x95, 0x01, /* REPORT_COUNT (1) */ + 0x75, 0x08, /* REPORT_SIZE (8) */ + 0x81, 0x03, /* INPUT (Cnst,Var,Abs) */ + 0x95, 0x05, /* REPORT_COUNT (5) */ + 0x75, 0x01, /* REPORT_SIZE (1) */ + 0x05, 0x08, /* USAGE_PAGE (LEDs) */ + 0x19, 0x01, /* USAGE_MINIMUM (Num Lock) */ + 0x29, 0x05, /* USAGE_MAXIMUM (Kana) */ + 0x91, 0x02, /* OUTPUT (Data,Var,Abs) */ + 0x95, 0x01, /* REPORT_COUNT (1) */ + 0x75, 0x03, /* REPORT_SIZE (3) */ + 0x91, 0x03, /* OUTPUT (Cnst,Var,Abs) */ + 0x95, 0x06, /* REPORT_COUNT (6) */ + 0x75, 0x08, /* REPORT_SIZE (8) */ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ + 0x25, 0x65, /* LOGICAL_MAXIMUM (101) */ + 0x05, 0x07, /* USAGE_PAGE (Keyboard) */ + 0x19, 0x00, /* USAGE_MINIMUM (Reserved) */ + 0x29, 0x65, /* USAGE_MAXIMUM (Keyboard Application) */ + 0x81, 0x00, /* INPUT (Data,Ary,Abs) */ + 0xc0 /* END_COLLECTION */ + } +}; + +static struct platform_device my_hid = { + .name = "hidg", + .id = 0, + .num_resources = 0, + .resource = 0, + .dev.platform_data = &my_hid_data, +}; + /*-------------------------------------------------------------------------*/ static struct usb_device_descriptor device_desc = { @@ -267,6 +320,13 @@ static int __init hidg_init(void) { int status; + status = platform_device_register(&my_hid); + if (status < 0) { + printk("____ reg failed\n"); + platform_device_unregister(&my_hid); + return status; + } + status = platform_driver_probe(&hidg_plat_driver, hidg_plat_driver_probe); if (status < 0) @@ -283,6 +343,7 @@ module_init(hidg_init); static void __exit hidg_cleanup(void) { platform_driver_unregister(&hidg_plat_driver); + platform_device_unregister(&my_hid); usb_composite_unregister(&hidg_driver); } module_exit(hidg_cleanup); -- 1.7.0.4
继续尝试。。。