Index: drivers/usb/hid-core.c =================================================================== RCS file: /home/scm/linux-2.4/drivers/usb/hid-core.c,v retrieving revision 1.16 diff -u -r1.16 hid-core.c --- drivers/usb/hid-core.c 31 Mar 2003 22:12:23 -0000 1.16 +++ drivers/usb/hid-core.c 28 Apr 2003 20:35:15 -0000 @@ -621,6 +621,8 @@ for (i = 0; i < HID_REPORT_TYPES; i++) INIT_LIST_HEAD(&device->report_enum[i].report_list); + INIT_LIST_HEAD(&device->inputs); + if (!(device->rdesc = (__u8 *)kmalloc(size, GFP_KERNEL))) { kfree(device); return NULL; @@ -1291,8 +1300,20 @@ hid->claimed |= HID_CLAIMED_HIDDEV; printk(KERN_INFO); - if (hid->claimed & HID_CLAIMED_INPUT) - printk("input%d", hid->input.number); + if (hid->claimed & HID_CLAIMED_INPUT) { + struct list_head *lh; + struct hid_input *hidinput; + int count = 0; + + list_for_each (lh, &hid->inputs) { + hidinput = list_entry(lh, struct hid_input, list); + + if (count++) + printk(","); + + printk("input%d", hidinput->input.number); + } + } if (hid->claimed == (HID_CLAIMED_INPUT | HID_CLAIMED_HIDDEV)) printk(","); if (hid->claimed & HID_CLAIMED_HIDDEV) Index: drivers/usb/hid-input.c =================================================================== RCS file: /home/scm/linux-2.4/drivers/usb/hid-input.c,v retrieving revision 1.7 diff -u -r1.7 hid-input.c --- drivers/usb/hid-input.c 5 Dec 2002 21:51:39 -0000 1.7 +++ drivers/usb/hid-input.c 28 Apr 2003 20:35:15 -0000 @@ -63,9 +63,29 @@ __s32 y; } hid_hat_to_axis[] = {{0, 0}, { 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1,-1}}; -static void hidinput_configure_usage(struct hid_device *device, struct hid_field *field, struct hid_usage *usage) +static struct input_dev *find_input(struct hid_device *hid, struct hid_field *field) { - struct input_dev *input = &device->input; + struct list_head *lh; + struct hid_input *hidinput; + + list_for_each (lh, &hid->inputs) { + int i; + + hidinput = list_entry(lh, struct hid_input, list); + + for (i = 0; i < hidinput->maxfield; i++) + if (hidinput->fields[i] == field) + return &hidinput->input; + } + + return NULL; +} + +static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_field *field, + struct hid_usage *usage) +{ + struct input_dev *input = &hidinput->input; + struct hid_device *device = hidinput->input.private; int max; unsigned long *bit; @@ -300,9 +327,12 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value) { - struct input_dev *input = &hid->input; + struct input_dev *input = find_input(hid, field); int *quirks = &hid->quirks; + if (!input) + return; + if (usage->hat_min != usage->hat_max) { value = (value - usage->hat_min) * 8 / (usage->hat_max - usage->hat_min + 1) + 1; if (value < 0 || value > 8) value = 0; @@ -382,7 +412,7 @@ struct hid_report_enum *report_enum; struct hid_report *report; struct list_head *list; - int i, j, k; + int i, j; for (i = 0; i < hid->maxapplication; i++) if (IS_INPUT_APPLICATION(hid->application[i])) @@ -391,35 +421,61 @@ if (i == hid->maxapplication) return -1; - hid->input.private = hid; - hid->input.event = hidinput_input_event; - hid->input.open = hidinput_open; - hid->input.close = hidinput_close; - - hid->input.name = hid->name; - hid->input.idbus = BUS_USB; - hid->input.idvendor = dev->descriptor.idVendor; - hid->input.idproduct = dev->descriptor.idProduct; - hid->input.idversion = dev->descriptor.bcdDevice; - - for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) { - report_enum = hid->report_enum + k; - list = report_enum->report_list.next; - while (list != &report_enum->report_list) { - report = (struct hid_report *) list; - for (i = 0; i < report->maxfield; i++) - for (j = 0; j < report->field[i]->maxusage; j++) - hidinput_configure_usage(hid, report->field[i], report->field[i]->usage + j); - list = list->next; + report_enum = hid->report_enum + HID_INPUT_REPORT; + list = report_enum->report_list.next; + while (list != &report_enum->report_list) { + struct hid_input *hidinput; + + report = (struct hid_report *) list; + + if (!report->maxfield) + continue; + + hidinput = kmalloc(sizeof(*hidinput), GFP_KERNEL); + if (!hidinput) { + err("Out of memory during hid input probe"); + return -1; } - } - input_register_device(&hid->input); + memset(hidinput, 0, sizeof(*hidinput)); + + hidinput->input.private = hid; + hidinput->input.event = hidinput_input_event; + hidinput->input.open = hidinput_open; + hidinput->input.close = hidinput_close; + + hidinput->input.name = hid->name; + hidinput->input.idbus = BUS_USB; + hidinput->input.idvendor = dev->descriptor.idVendor; + hidinput->input.idproduct = dev->descriptor.idProduct; + hidinput->input.idversion = dev->descriptor.bcdDevice; + + hidinput->fields = report->field; + hidinput->maxfield = report->maxfield; + + for (i = 0; i < report->maxfield; i++) + for (j = 0; j < report->field[i]->maxusage; j++) + hidinput_configure_usage(hidinput, report->field[i], + report->field[i]->usage + j); + + list_add_tail(&hidinput->list, &hid->inputs); + + input_register_device(&hidinput->input); + + list = list->next; + } return 0; } void hidinput_disconnect(struct hid_device *hid) { - input_unregister_device(&hid->input); + struct list_head *lh, *next; + struct hid_input *hidinput; + + list_for_each_safe (lh, next, &hid->inputs) { + hidinput = list_entry(lh, struct hid_input, list); + input_unregister_device(&hidinput->input); + list_del(&hidinput->list); + } } Index: drivers/usb/hid.h =================================================================== RCS file: /home/scm/linux-2.4/drivers/usb/hid.h,v retrieving revision 1.10 diff -u -r1.10 hid.h --- drivers/usb/hid.h 6 Aug 2002 14:38:00 -0000 1.10 +++ drivers/usb/hid.h 28 Apr 2003 20:35:15 -0000 @@ -294,6 +294,13 @@ #define HID_CLAIMED_INPUT 1 #define HID_CLAIMED_HIDDEV 2 +struct hid_input { + struct list_head list; + struct hid_field **fields; + int maxfield; + struct input_dev input; +}; + struct hid_device { /* device report descriptor */ __u8 *rdesc; unsigned rsize; @@ -316,7 +323,7 @@ unsigned claimed; /* Claimed by hidinput, hiddev? */ unsigned quirks; /* Various quirks the device can pull on us */ - struct input_dev input; /* The input structure */ + struct list_head inputs; /* The list of inputs */ void *hiddev; /* The hiddev structure */ int minor; /* Hiddev minor number */