| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 
 | diff -uprN a/drivers/usb/gadget/legacy/hid.c b/drivers/usb/gadget/legacy/hid.c
 
 @@ -15,15 +15,15 @@
 #include <linux/usb/composite.h>
 #include <linux/usb/g_hid.h>
 
 -#define DRIVER_DESC		"HID Gadget"
 +#define DRIVER_DESC		"Logitech USB Receiver"		// PRODUCT_IDX
 #define DRIVER_VERSION		"2010/03/16"
 
 #include "u_hid.h"
 
 /*-------------------------------------------------------------------------*/
 
 -#define HIDG_VENDOR_NUM		0x0525	/* XXX NetChip */
 -#define HIDG_PRODUCT_NUM	0xa4ac	/* Linux-USB HID gadget */
 +#define HIDG_VENDOR_NUM		0x046d	/* idVendor */
 +#define HIDG_PRODUCT_NUM	0xc53f	/* idProduct */
 
 /*-------------------------------------------------------------------------*/
 
 @@ -67,7 +67,7 @@
 
 /* string IDs are assigned dynamically */
 static struct usb_string strings_dev[] = {
 -	[USB_GADGET_MANUFACTURER_IDX].s = "",
 +	[USB_GADGET_MANUFACTURER_IDX].s = "Logitech",
 [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
 [USB_GADGET_SERIAL_IDX].s = "",
 {  } /* end of list */
 @@ -254,6 +254,107 @@
 
 /****************************** Some noise ******************************/
 
 +// 防止移除模块时报找不到release函数的错误
 +static void release_hid_dev(struct device *dev) {}
 +
 +// 添加键盘报告描述符
 +static struct hidg_func_descriptor keyboard_report_data = {
 +	.subclass		= 0,	/* No subclass */
 +	.protocol		= 1,	/* 1 Keyboard */ /* 2 Mouse*/
 +	.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 (no event indicated))
 +		0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)
 +		0x81, 0x00,                    //   INPUT (Data,Ary,Abs)
 +		0xc0                           // END_COLLECTION
 +	}
 +};
 +
 +// 定义键盘设备
 +static struct platform_device keyboard_device = {
 +	.name			= "hidg",
 +	.id			= 0,
 +	.num_resources		= 0,
 +	.resource		= 0,
 +	.dev.platform_data	= &keyboard_report_data,
 +	.dev.release 		= &release_hid_dev,
 +};
 +
 +// 添加鼠标报告描述符
 +static struct hidg_func_descriptor mouse_report_data = {
 +	.subclass		= 1,	/* No subclass */
 +	.protocol		= 2,	/* 1 Keyboard */ /* 2 Mouse*/
 +	.report_length		= 4,
 +	.report_desc_length	= 52,
 +	.report_desc		= {
 +		0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
 +		0x09, 0x02,                    // USAGE (Mouse)
 +		0xa1, 0x01,                    // COLLECTION (Application)
 +		0x09, 0x01,                    //   USAGE (Pointer)
 +		0xa1, 0x00,                    //   COLLECTION (Physical)
 +		0x05, 0x09,                    //     USAGE_PAGE (Button)
 +		0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
 +		0x29, 0x03,                    //     USAGE_MAXIMUM (Button 3)
 +		0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
 +		0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
 +		0x95, 0x03,                    //     REPORT_COUNT (3)
 +		0x75, 0x01,                    //     REPORT_SIZE (1)
 +		0x81, 0x02,                    //     INPUT (Data,Var,Abs)
 +		0x95, 0x01,                    //     REPORT_COUNT (1)
 +		0x75, 0x05,                    //     REPORT_SIZE (5)
 +		0x81, 0x03,                    //     INPUT (Cnst,Var,Abs)
 +		0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
 +		0x09, 0x30,                    //     USAGE (X)
 +		0x09, 0x31,                    //     USAGE (Y)
 +		0x09, 0x38,                    //     USAGE (Wheel)
 +		0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
 +		0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
 +		0x75, 0x08,                    //     REPORT_SIZE (8)
 +		0x95, 0x03,                    //     REPORT_COUNT (3)
 +		0x81, 0x06,                    //     INPUT (Data,Var,Rel)
 +		0xc0,                          //   END_COLLECTION
 +		0xc0                           // END_COLLECTION
 +	}
 +};
 +
 +// 定义鼠标设备
 +static struct platform_device mouse_device = {
 +	.name			= "hidg",
 +	.id			= 1,
 +	.num_resources		= 0,
 +	.resource		= 0,
 +	.dev.platform_data	= &mouse_report_data,
 +	.dev.release 		= &release_hid_dev,
 +};
 
 static struct usb_composite_driver hidg_driver = {
 .name		= "g_hid",
 @@ -280,6 +376,22 @@
 {
 int status;
 
 +	// 申请注册键盘设备
 +	status = platform_device_register(&keyboard_device);
 +	if (status < 0) {
 +		printk("Failed: Gadget HID Keyboard Device Register Failed!\n");
 +		platform_device_unregister(&keyboard_device);
 +		return status;
 +	}
 +
 +	// 申请注册鼠标设备
 +	status = platform_device_register(&mouse_device);
 +	if (status < 0) {
 +		printk("Failed: Gadget HID Mouse Device Register Failed!\n");
 +		platform_device_unregister(&mouse_device);
 +		return status;
 +	}
 +
 status = platform_driver_probe(&hidg_plat_driver,
 hidg_plat_driver_probe);
 if (status < 0)
 @@ -297,5 +409,7 @@
 {
 usb_composite_unregister(&hidg_driver);
 platform_driver_unregister(&hidg_plat_driver);
 +	platform_device_unregister(&keyboard_device);	// 销毁释放键鼠设备
 +	platform_device_unregister(&mouse_device);
 }
 module_exit(hidg_cleanup);
 
 
 |