aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hid/Kconfig8
-rw-r--r--drivers/hid/Makefile1
-rw-r--r--drivers/hid/hid-a4tech.c21
-rw-r--r--drivers/hid/hid-apple.c16
-rw-r--r--drivers/hid/hid-core.c159
-rw-r--r--drivers/hid/hid-holtekff.c2
-rw-r--r--drivers/hid/hid-ids.h12
-rw-r--r--drivers/hid/hid-input.c92
-rw-r--r--drivers/hid/hid-kye.c45
-rw-r--r--drivers/hid/hid-logitech-dj.c22
-rw-r--r--drivers/hid/hid-magicmouse.c19
-rw-r--r--drivers/hid/hid-multitouch.c107
-rw-r--r--drivers/hid/hid-ntrig.c15
-rw-r--r--drivers/hid/hid-picolcd_cir.c3
-rw-r--r--drivers/hid/hid-picolcd_core.c2
-rw-r--r--drivers/hid/hid-picolcd_debugfs.c23
-rw-r--r--drivers/hid/hid-picolcd_fb.c6
-rw-r--r--drivers/hid/hid-pl.c10
-rw-r--r--drivers/hid/hid-roccat-arvo.c6
-rw-r--r--drivers/hid/hid-roccat-isku.c2
-rw-r--r--drivers/hid/hid-roccat-kone.c4
-rw-r--r--drivers/hid/hid-roccat-koneplus.c2
-rw-r--r--drivers/hid/hid-roccat-konepure.c3
-rw-r--r--drivers/hid/hid-roccat-kovaplus.c2
-rw-r--r--drivers/hid/hid-sensor-hub.c58
-rw-r--r--drivers/hid/hid-sony.c9
-rw-r--r--drivers/hid/hid-speedlink.c11
-rw-r--r--drivers/hid/hid-wiimote-core.c41
-rw-r--r--drivers/hid/hid-wiimote-modules.c392
-rw-r--r--drivers/hid/hid-wiimote.h3
-rw-r--r--drivers/hid/hid-xinmo.c61
-rw-r--r--drivers/hid/hid-zydacron.c19
-rw-r--r--drivers/hid/hidraw.c80
-rw-r--r--drivers/hid/i2c-hid/i2c-hid.c77
-rw-r--r--drivers/hid/uhid.c26
-rw-r--r--drivers/hid/usbhid/hid-core.c83
-rw-r--r--drivers/hid/usbhid/hid-quirks.c2
-rw-r--r--drivers/hid/usbhid/usbhid.h3
-rw-r--r--drivers/input/mouse/bcm5974.c6
39 files changed, 998 insertions, 455 deletions
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 14ef6ab69790..3d7c9f67b6d7 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -743,6 +743,14 @@ config HID_WIIMOTE
743 To compile this driver as a module, choose M here: the 743 To compile this driver as a module, choose M here: the
744 module will be called hid-wiimote. 744 module will be called hid-wiimote.
745 745
746config HID_XINMO
747 tristate "Xin-Mo non-fully compliant devices"
748 depends on HID
749 ---help---
750 Support for Xin-Mo devices that are not fully compliant with the HID
751 standard. Currently only supports the Xin-Mo Dual Arcade. Say Y here
752 if you have a Xin-Mo Dual Arcade controller.
753
746config HID_ZEROPLUS 754config HID_ZEROPLUS
747 tristate "Zeroplus based game controller support" 755 tristate "Zeroplus based game controller support"
748 depends on HID 756 depends on HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 6f687287e212..a959f4aecaf5 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -110,6 +110,7 @@ obj-$(CONFIG_HID_TIVO) += hid-tivo.o
110obj-$(CONFIG_HID_TOPSEED) += hid-topseed.o 110obj-$(CONFIG_HID_TOPSEED) += hid-topseed.o
111obj-$(CONFIG_HID_TWINHAN) += hid-twinhan.o 111obj-$(CONFIG_HID_TWINHAN) += hid-twinhan.o
112obj-$(CONFIG_HID_UCLOGIC) += hid-uclogic.o 112obj-$(CONFIG_HID_UCLOGIC) += hid-uclogic.o
113obj-$(CONFIG_HID_XINMO) += hid-xinmo.o
113obj-$(CONFIG_HID_ZEROPLUS) += hid-zpff.o 114obj-$(CONFIG_HID_ZEROPLUS) += hid-zpff.o
114obj-$(CONFIG_HID_ZYDACRON) += hid-zydacron.o 115obj-$(CONFIG_HID_ZYDACRON) += hid-zydacron.o
115obj-$(CONFIG_HID_WACOM) += hid-wacom.o 116obj-$(CONFIG_HID_WACOM) += hid-wacom.o
diff --git a/drivers/hid/hid-a4tech.c b/drivers/hid/hid-a4tech.c
index 7c5507e94820..9428ea7cdf8a 100644
--- a/drivers/hid/hid-a4tech.c
+++ b/drivers/hid/hid-a4tech.c
@@ -90,11 +90,10 @@ static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
90 struct a4tech_sc *a4; 90 struct a4tech_sc *a4;
91 int ret; 91 int ret;
92 92
93 a4 = kzalloc(sizeof(*a4), GFP_KERNEL); 93 a4 = devm_kzalloc(&hdev->dev, sizeof(*a4), GFP_KERNEL);
94 if (a4 == NULL) { 94 if (a4 == NULL) {
95 hid_err(hdev, "can't alloc device descriptor\n"); 95 hid_err(hdev, "can't alloc device descriptor\n");
96 ret = -ENOMEM; 96 return -ENOMEM;
97 goto err_free;
98 } 97 }
99 98
100 a4->quirks = id->driver_data; 99 a4->quirks = id->driver_data;
@@ -104,27 +103,16 @@ static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
104 ret = hid_parse(hdev); 103 ret = hid_parse(hdev);
105 if (ret) { 104 if (ret) {
106 hid_err(hdev, "parse failed\n"); 105 hid_err(hdev, "parse failed\n");
107 goto err_free; 106 return ret;
108 } 107 }
109 108
110 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 109 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
111 if (ret) { 110 if (ret) {
112 hid_err(hdev, "hw start failed\n"); 111 hid_err(hdev, "hw start failed\n");
113 goto err_free; 112 return ret;
114 } 113 }
115 114
116 return 0; 115 return 0;
117err_free:
118 kfree(a4);
119 return ret;
120}
121
122static void a4_remove(struct hid_device *hdev)
123{
124 struct a4tech_sc *a4 = hid_get_drvdata(hdev);
125
126 hid_hw_stop(hdev);
127 kfree(a4);
128} 116}
129 117
130static const struct hid_device_id a4_devices[] = { 118static const struct hid_device_id a4_devices[] = {
@@ -144,7 +132,6 @@ static struct hid_driver a4_driver = {
144 .input_mapped = a4_input_mapped, 132 .input_mapped = a4_input_mapped,
145 .event = a4_event, 133 .event = a4_event,
146 .probe = a4_probe, 134 .probe = a4_probe,
147 .remove = a4_remove,
148}; 135};
149module_hid_driver(a4_driver); 136module_hid_driver(a4_driver);
150 137
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index c7710b5c69af..881cf7b4f9a4 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -349,7 +349,7 @@ static int apple_probe(struct hid_device *hdev,
349 unsigned int connect_mask = HID_CONNECT_DEFAULT; 349 unsigned int connect_mask = HID_CONNECT_DEFAULT;
350 int ret; 350 int ret;
351 351
352 asc = kzalloc(sizeof(*asc), GFP_KERNEL); 352 asc = devm_kzalloc(&hdev->dev, sizeof(*asc), GFP_KERNEL);
353 if (asc == NULL) { 353 if (asc == NULL) {
354 hid_err(hdev, "can't alloc apple descriptor\n"); 354 hid_err(hdev, "can't alloc apple descriptor\n");
355 return -ENOMEM; 355 return -ENOMEM;
@@ -362,7 +362,7 @@ static int apple_probe(struct hid_device *hdev,
362 ret = hid_parse(hdev); 362 ret = hid_parse(hdev);
363 if (ret) { 363 if (ret) {
364 hid_err(hdev, "parse failed\n"); 364 hid_err(hdev, "parse failed\n");
365 goto err_free; 365 return ret;
366 } 366 }
367 367
368 if (quirks & APPLE_HIDDEV) 368 if (quirks & APPLE_HIDDEV)
@@ -373,19 +373,10 @@ static int apple_probe(struct hid_device *hdev,
373 ret = hid_hw_start(hdev, connect_mask); 373 ret = hid_hw_start(hdev, connect_mask);
374 if (ret) { 374 if (ret) {
375 hid_err(hdev, "hw start failed\n"); 375 hid_err(hdev, "hw start failed\n");
376 goto err_free; 376 return ret;
377 } 377 }
378 378
379 return 0; 379 return 0;
380err_free:
381 kfree(asc);
382 return ret;
383}
384
385static void apple_remove(struct hid_device *hdev)
386{
387 hid_hw_stop(hdev);
388 kfree(hid_get_drvdata(hdev));
389} 380}
390 381
391static const struct hid_device_id apple_devices[] = { 382static const struct hid_device_id apple_devices[] = {
@@ -551,7 +542,6 @@ static struct hid_driver apple_driver = {
551 .id_table = apple_devices, 542 .id_table = apple_devices,
552 .report_fixup = apple_report_fixup, 543 .report_fixup = apple_report_fixup,
553 .probe = apple_probe, 544 .probe = apple_probe,
554 .remove = apple_remove,
555 .event = apple_event, 545 .event = apple_event,
556 .input_mapping = apple_input_mapping, 546 .input_mapping = apple_input_mapping,
557 .input_mapped = apple_input_mapped, 547 .input_mapped = apple_input_mapped,
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index b8f1c77f2f77..ae88a97f976e 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -63,6 +63,8 @@ struct hid_report *hid_register_report(struct hid_device *device, unsigned type,
63 struct hid_report_enum *report_enum = device->report_enum + type; 63 struct hid_report_enum *report_enum = device->report_enum + type;
64 struct hid_report *report; 64 struct hid_report *report;
65 65
66 if (id >= HID_MAX_IDS)
67 return NULL;
66 if (report_enum->report_id_hash[id]) 68 if (report_enum->report_id_hash[id])
67 return report_enum->report_id_hash[id]; 69 return report_enum->report_id_hash[id];
68 70
@@ -404,8 +406,10 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
404 406
405 case HID_GLOBAL_ITEM_TAG_REPORT_ID: 407 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
406 parser->global.report_id = item_udata(item); 408 parser->global.report_id = item_udata(item);
407 if (parser->global.report_id == 0) { 409 if (parser->global.report_id == 0 ||
408 hid_err(parser->device, "report_id 0 is invalid\n"); 410 parser->global.report_id >= HID_MAX_IDS) {
411 hid_err(parser->device, "report_id %u is invalid\n",
412 parser->global.report_id);
409 return -1; 413 return -1;
410 } 414 }
411 return 0; 415 return 0;
@@ -450,7 +454,7 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
450 } 454 }
451 parser->local.delimiter_depth--; 455 parser->local.delimiter_depth--;
452 } 456 }
453 return 1; 457 return 0;
454 458
455 case HID_LOCAL_ITEM_TAG_USAGE: 459 case HID_LOCAL_ITEM_TAG_USAGE:
456 460
@@ -575,7 +579,7 @@ static void hid_close_report(struct hid_device *device)
575 for (i = 0; i < HID_REPORT_TYPES; i++) { 579 for (i = 0; i < HID_REPORT_TYPES; i++) {
576 struct hid_report_enum *report_enum = device->report_enum + i; 580 struct hid_report_enum *report_enum = device->report_enum + i;
577 581
578 for (j = 0; j < 256; j++) { 582 for (j = 0; j < HID_MAX_IDS; j++) {
579 struct hid_report *report = report_enum->report_id_hash[j]; 583 struct hid_report *report = report_enum->report_id_hash[j];
580 if (report) 584 if (report)
581 hid_free_report(report); 585 hid_free_report(report);
@@ -677,12 +681,61 @@ static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
677 return NULL; 681 return NULL;
678} 682}
679 683
680static void hid_scan_usage(struct hid_device *hid, u32 usage) 684static void hid_scan_input_usage(struct hid_parser *parser, u32 usage)
681{ 685{
686 struct hid_device *hid = parser->device;
687
682 if (usage == HID_DG_CONTACTID) 688 if (usage == HID_DG_CONTACTID)
683 hid->group = HID_GROUP_MULTITOUCH; 689 hid->group = HID_GROUP_MULTITOUCH;
684} 690}
685 691
692static void hid_scan_feature_usage(struct hid_parser *parser, u32 usage)
693{
694 if (usage == 0xff0000c5 && parser->global.report_count == 256 &&
695 parser->global.report_size == 8)
696 parser->scan_flags |= HID_SCAN_FLAG_MT_WIN_8;
697}
698
699static void hid_scan_collection(struct hid_parser *parser, unsigned type)
700{
701 struct hid_device *hid = parser->device;
702
703 if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
704 type == HID_COLLECTION_PHYSICAL)
705 hid->group = HID_GROUP_SENSOR_HUB;
706}
707
708static int hid_scan_main(struct hid_parser *parser, struct hid_item *item)
709{
710 __u32 data;
711 int i;
712
713 data = item_udata(item);
714
715 switch (item->tag) {
716 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
717 hid_scan_collection(parser, data & 0xff);
718 break;
719 case HID_MAIN_ITEM_TAG_END_COLLECTION:
720 break;
721 case HID_MAIN_ITEM_TAG_INPUT:
722 for (i = 0; i < parser->local.usage_index; i++)
723 hid_scan_input_usage(parser, parser->local.usage[i]);
724 break;
725 case HID_MAIN_ITEM_TAG_OUTPUT:
726 break;
727 case HID_MAIN_ITEM_TAG_FEATURE:
728 for (i = 0; i < parser->local.usage_index; i++)
729 hid_scan_feature_usage(parser, parser->local.usage[i]);
730 break;
731 }
732
733 /* Reset the local parser environment */
734 memset(&parser->local, 0, sizeof(parser->local));
735
736 return 0;
737}
738
686/* 739/*
687 * Scan a report descriptor before the device is added to the bus. 740 * Scan a report descriptor before the device is added to the bus.
688 * Sets device groups and other properties that determine what driver 741 * Sets device groups and other properties that determine what driver
@@ -690,48 +743,41 @@ static void hid_scan_usage(struct hid_device *hid, u32 usage)
690 */ 743 */
691static int hid_scan_report(struct hid_device *hid) 744static int hid_scan_report(struct hid_device *hid)
692{ 745{
693 unsigned int page = 0, delim = 0; 746 struct hid_parser *parser;
747 struct hid_item item;
694 __u8 *start = hid->dev_rdesc; 748 __u8 *start = hid->dev_rdesc;
695 __u8 *end = start + hid->dev_rsize; 749 __u8 *end = start + hid->dev_rsize;
696 unsigned int u, u_min = 0, u_max = 0; 750 static int (*dispatch_type[])(struct hid_parser *parser,
697 struct hid_item item; 751 struct hid_item *item) = {
752 hid_scan_main,
753 hid_parser_global,
754 hid_parser_local,
755 hid_parser_reserved
756 };
757
758 parser = vzalloc(sizeof(struct hid_parser));
759 if (!parser)
760 return -ENOMEM;
698 761
762 parser->device = hid;
699 hid->group = HID_GROUP_GENERIC; 763 hid->group = HID_GROUP_GENERIC;
700 while ((start = fetch_item(start, end, &item)) != NULL) {
701 if (item.format != HID_ITEM_FORMAT_SHORT)
702 return -EINVAL;
703 if (item.type == HID_ITEM_TYPE_GLOBAL) {
704 if (item.tag == HID_GLOBAL_ITEM_TAG_USAGE_PAGE)
705 page = item_udata(&item) << 16;
706 } else if (item.type == HID_ITEM_TYPE_LOCAL) {
707 if (delim > 1)
708 break;
709 u = item_udata(&item);
710 if (item.size <= 2)
711 u += page;
712 switch (item.tag) {
713 case HID_LOCAL_ITEM_TAG_DELIMITER:
714 delim += !!u;
715 break;
716 case HID_LOCAL_ITEM_TAG_USAGE:
717 hid_scan_usage(hid, u);
718 break;
719 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
720 u_min = u;
721 break;
722 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
723 u_max = u;
724 for (u = u_min; u <= u_max; u++)
725 hid_scan_usage(hid, u);
726 break;
727 }
728 } else if (page == HID_UP_SENSOR &&
729 item.type == HID_ITEM_TYPE_MAIN &&
730 item.tag == HID_MAIN_ITEM_TAG_BEGIN_COLLECTION &&
731 (item_udata(&item) & 0xff) == HID_COLLECTION_PHYSICAL)
732 hid->group = HID_GROUP_SENSOR_HUB;
733 }
734 764
765 /*
766 * The parsing is simpler than the one in hid_open_report() as we should
767 * be robust against hid errors. Those errors will be raised by
768 * hid_open_report() anyway.
769 */
770 while ((start = fetch_item(start, end, &item)) != NULL)
771 dispatch_type[item.type](parser, &item);
772
773 /*
774 * Handle special flags set during scanning.
775 */
776 if ((parser->scan_flags & HID_SCAN_FLAG_MT_WIN_8) &&
777 (hid->group == HID_GROUP_MULTITOUCH))
778 hid->group = HID_GROUP_MULTITOUCH_WIN_8;
779
780 vfree(parser);
735 return 0; 781 return 0;
736} 782}
737 783
@@ -1128,7 +1174,8 @@ static void hid_output_field(const struct hid_device *hid,
1128} 1174}
1129 1175
1130/* 1176/*
1131 * Create a report. 1177 * Create a report. 'data' has to be allocated using
1178 * hid_alloc_report_buf() so that it has proper size.
1132 */ 1179 */
1133 1180
1134void hid_output_report(struct hid_report *report, __u8 *data) 1181void hid_output_report(struct hid_report *report, __u8 *data)
@@ -1145,6 +1192,22 @@ void hid_output_report(struct hid_report *report, __u8 *data)
1145EXPORT_SYMBOL_GPL(hid_output_report); 1192EXPORT_SYMBOL_GPL(hid_output_report);
1146 1193
1147/* 1194/*
1195 * Allocator for buffer that is going to be passed to hid_output_report()
1196 */
1197u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags)
1198{
1199 /*
1200 * 7 extra bytes are necessary to achieve proper functionality
1201 * of implement() working on 8 byte chunks
1202 */
1203
1204 int len = ((report->size - 1) >> 3) + 1 + (report->id > 0) + 7;
1205
1206 return kmalloc(len, flags);
1207}
1208EXPORT_SYMBOL_GPL(hid_alloc_report_buf);
1209
1210/*
1148 * Set a field value. The report this field belongs to has to be 1211 * Set a field value. The report this field belongs to has to be
1149 * created and transferred to the device, to set this value in the 1212 * created and transferred to the device, to set this value in the
1150 * device. 1213 * device.
@@ -1152,7 +1215,12 @@ EXPORT_SYMBOL_GPL(hid_output_report);
1152 1215
1153int hid_set_field(struct hid_field *field, unsigned offset, __s32 value) 1216int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
1154{ 1217{
1155 unsigned size = field->report_size; 1218 unsigned size;
1219
1220 if (!field)
1221 return -1;
1222
1223 size = field->report_size;
1156 1224
1157 hid_dump_input(field->report->device, field->usage + offset, value); 1225 hid_dump_input(field->report->device, field->usage + offset, value);
1158 1226
@@ -1597,6 +1665,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1597 { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) }, 1665 { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
1598 { HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) }, 1666 { HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
1599 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) }, 1667 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
1668 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
1600 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) }, 1669 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
1601 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) }, 1670 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) },
1602 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) }, 1671 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
@@ -1679,6 +1748,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1679 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) }, 1748 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) },
1680 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) }, 1749 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
1681 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) }, 1750 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) },
1751 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL) },
1682 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) }, 1752 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
1683 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_LUA) }, 1753 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_LUA) },
1684 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) }, 1754 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
@@ -1736,6 +1806,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1736 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) }, 1806 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
1737 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) }, 1807 { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) },
1738 { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) }, 1808 { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
1809 { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_XIN_MO_DUAL_ARCADE) },
1739 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) }, 1810 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1740 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) }, 1811 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
1741 { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) }, 1812 { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
diff --git a/drivers/hid/hid-holtekff.c b/drivers/hid/hid-holtekff.c
index 9a8f05124525..9325545fc3ae 100644
--- a/drivers/hid/hid-holtekff.c
+++ b/drivers/hid/hid-holtekff.c
@@ -98,7 +98,7 @@ static void holtekff_send(struct holtekff_device *holtekff,
98 holtekff->field->value[i] = data[i]; 98 holtekff->field->value[i] = data[i];
99 } 99 }
100 100
101 dbg_hid("sending %*ph\n", 7, data); 101 dbg_hid("sending %7ph\n", data);
102 102
103 hid_hw_request(hid, holtekff->field->report, HID_REQ_SET_REPORT); 103 hid_hw_request(hid, holtekff->field->report, HID_REQ_SET_REPORT);
104} 104}
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index ffe4c7ae3340..e60e8d530697 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -135,9 +135,9 @@
135#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b 135#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b
136#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI 0x0255 136#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI 0x0255
137#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO 0x0256 137#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO 0x0256
138#define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0291 138#define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0290
139#define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0292 139#define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0291
140#define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0293 140#define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0292
141#define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a 141#define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a
142#define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b 142#define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b
143#define USB_DEVICE_ID_APPLE_IRCONTROL 0x8240 143#define USB_DEVICE_ID_APPLE_IRCONTROL 0x8240
@@ -482,6 +482,7 @@
482#define USB_VENDOR_ID_KYE 0x0458 482#define USB_VENDOR_ID_KYE 0x0458
483#define USB_DEVICE_ID_KYE_ERGO_525V 0x0087 483#define USB_DEVICE_ID_KYE_ERGO_525V 0x0087
484#define USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE 0x0138 484#define USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE 0x0138
485#define USB_DEVICE_ID_GENIUS_GX_IMPERATOR 0x4018
485#define USB_DEVICE_ID_KYE_GPEN_560 0x5003 486#define USB_DEVICE_ID_KYE_GPEN_560 0x5003
486#define USB_DEVICE_ID_KYE_EASYPEN_I405X 0x5010 487#define USB_DEVICE_ID_KYE_EASYPEN_I405X 0x5010
487#define USB_DEVICE_ID_KYE_MOUSEPEN_I608X 0x5011 488#define USB_DEVICE_ID_KYE_MOUSEPEN_I608X 0x5011
@@ -658,6 +659,7 @@
658#define USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16 0x0012 659#define USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16 0x0012
659#define USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17 0x0013 660#define USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17 0x0013
660#define USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18 0x0014 661#define USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18 0x0014
662#define USB_DEVICE_ID_NTRIG_DUOSENSE 0x1500
661 663
662#define USB_VENDOR_ID_ONTRAK 0x0a07 664#define USB_VENDOR_ID_ONTRAK 0x0a07
663#define USB_DEVICE_ID_ONTRAK_ADU100 0x0064 665#define USB_DEVICE_ID_ONTRAK_ADU100 0x0064
@@ -716,6 +718,7 @@
716#define USB_DEVICE_ID_ROCCAT_KONE 0x2ced 718#define USB_DEVICE_ID_ROCCAT_KONE 0x2ced
717#define USB_DEVICE_ID_ROCCAT_KONEPLUS 0x2d51 719#define USB_DEVICE_ID_ROCCAT_KONEPLUS 0x2d51
718#define USB_DEVICE_ID_ROCCAT_KONEPURE 0x2dbe 720#define USB_DEVICE_ID_ROCCAT_KONEPURE 0x2dbe
721#define USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL 0x2db4
719#define USB_DEVICE_ID_ROCCAT_KONEXTD 0x2e22 722#define USB_DEVICE_ID_ROCCAT_KONEXTD 0x2e22
720#define USB_DEVICE_ID_ROCCAT_KOVAPLUS 0x2d50 723#define USB_DEVICE_ID_ROCCAT_KOVAPLUS 0x2d50
721#define USB_DEVICE_ID_ROCCAT_LUA 0x2c2e 724#define USB_DEVICE_ID_ROCCAT_LUA 0x2c2e
@@ -887,6 +890,9 @@
887#define USB_VENDOR_ID_XAT 0x2505 890#define USB_VENDOR_ID_XAT 0x2505
888#define USB_DEVICE_ID_XAT_CSR 0x0220 891#define USB_DEVICE_ID_XAT_CSR 0x0220
889 892
893#define USB_VENDOR_ID_XIN_MO 0x16c0
894#define USB_DEVICE_ID_XIN_MO_DUAL_ARCADE 0x05e1
895
890#define USB_VENDOR_ID_XIROKU 0x1477 896#define USB_VENDOR_ID_XIROKU 0x1477
891#define USB_DEVICE_ID_XIROKU_SPX 0x1006 897#define USB_DEVICE_ID_XIROKU_SPX 0x1006
892#define USB_DEVICE_ID_XIROKU_MPX 0x1007 898#define USB_DEVICE_ID_XIROKU_MPX 0x1007
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 7480799e535c..b420f4a0fd28 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -340,7 +340,7 @@ static int hidinput_get_battery_property(struct power_supply *psy,
340{ 340{
341 struct hid_device *dev = container_of(psy, struct hid_device, battery); 341 struct hid_device *dev = container_of(psy, struct hid_device, battery);
342 int ret = 0; 342 int ret = 0;
343 __u8 buf[2] = {}; 343 __u8 *buf;
344 344
345 switch (prop) { 345 switch (prop) {
346 case POWER_SUPPLY_PROP_PRESENT: 346 case POWER_SUPPLY_PROP_PRESENT:
@@ -349,12 +349,19 @@ static int hidinput_get_battery_property(struct power_supply *psy,
349 break; 349 break;
350 350
351 case POWER_SUPPLY_PROP_CAPACITY: 351 case POWER_SUPPLY_PROP_CAPACITY:
352
353 buf = kmalloc(2 * sizeof(__u8), GFP_KERNEL);
354 if (!buf) {
355 ret = -ENOMEM;
356 break;
357 }
352 ret = dev->hid_get_raw_report(dev, dev->battery_report_id, 358 ret = dev->hid_get_raw_report(dev, dev->battery_report_id,
353 buf, sizeof(buf), 359 buf, 2,
354 dev->battery_report_type); 360 dev->battery_report_type);
355 361
356 if (ret != 2) { 362 if (ret != 2) {
357 ret = -ENODATA; 363 ret = -ENODATA;
364 kfree(buf);
358 break; 365 break;
359 } 366 }
360 ret = 0; 367 ret = 0;
@@ -364,6 +371,7 @@ static int hidinput_get_battery_property(struct power_supply *psy,
364 buf[1] <= dev->battery_max) 371 buf[1] <= dev->battery_max)
365 val->intval = (100 * (buf[1] - dev->battery_min)) / 372 val->intval = (100 * (buf[1] - dev->battery_min)) /
366 (dev->battery_max - dev->battery_min); 373 (dev->battery_max - dev->battery_min);
374 kfree(buf);
367 break; 375 break;
368 376
369 case POWER_SUPPLY_PROP_MODEL_NAME: 377 case POWER_SUPPLY_PROP_MODEL_NAME:
@@ -1137,6 +1145,74 @@ unsigned int hidinput_count_leds(struct hid_device *hid)
1137} 1145}
1138EXPORT_SYMBOL_GPL(hidinput_count_leds); 1146EXPORT_SYMBOL_GPL(hidinput_count_leds);
1139 1147
1148static void hidinput_led_worker(struct work_struct *work)
1149{
1150 struct hid_device *hid = container_of(work, struct hid_device,
1151 led_work);
1152 struct hid_field *field;
1153 struct hid_report *report;
1154 int len;
1155 __u8 *buf;
1156
1157 field = hidinput_get_led_field(hid);
1158 if (!field)
1159 return;
1160
1161 /*
1162 * field->report is accessed unlocked regarding HID core. So there might
1163 * be another incoming SET-LED request from user-space, which changes
1164 * the LED state while we assemble our outgoing buffer. However, this
1165 * doesn't matter as hid_output_report() correctly converts it into a
1166 * boolean value no matter what information is currently set on the LED
1167 * field (even garbage). So the remote device will always get a valid
1168 * request.
1169 * And in case we send a wrong value, a next led worker is spawned
1170 * for every SET-LED request so the following worker will send the
1171 * correct value, guaranteed!
1172 */
1173
1174 report = field->report;
1175
1176 /* use custom SET_REPORT request if possible (asynchronous) */
1177 if (hid->ll_driver->request)
1178 return hid->ll_driver->request(hid, report, HID_REQ_SET_REPORT);
1179
1180 /* fall back to generic raw-output-report */
1181 len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
1182 buf = kmalloc(len, GFP_KERNEL);
1183 if (!buf)
1184 return;
1185
1186 hid_output_report(report, buf);
1187 /* synchronous output report */
1188 hid->hid_output_raw_report(hid, buf, len, HID_OUTPUT_REPORT);
1189 kfree(buf);
1190}
1191
1192static int hidinput_input_event(struct input_dev *dev, unsigned int type,
1193 unsigned int code, int value)
1194{
1195 struct hid_device *hid = input_get_drvdata(dev);
1196 struct hid_field *field;
1197 int offset;
1198
1199 if (type == EV_FF)
1200 return input_ff_event(dev, type, code, value);
1201
1202 if (type != EV_LED)
1203 return -1;
1204
1205 if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) {
1206 hid_warn(dev, "event field not found\n");
1207 return -1;
1208 }
1209
1210 hid_set_field(field, offset, value);
1211
1212 schedule_work(&hid->led_work);
1213 return 0;
1214}
1215
1140static int hidinput_open(struct input_dev *dev) 1216static int hidinput_open(struct input_dev *dev)
1141{ 1217{
1142 struct hid_device *hid = input_get_drvdata(dev); 1218 struct hid_device *hid = input_get_drvdata(dev);
@@ -1183,7 +1259,10 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid)
1183 } 1259 }
1184 1260
1185 input_set_drvdata(input_dev, hid); 1261 input_set_drvdata(input_dev, hid);
1186 input_dev->event = hid->ll_driver->hidinput_input_event; 1262 if (hid->ll_driver->hidinput_input_event)
1263 input_dev->event = hid->ll_driver->hidinput_input_event;
1264 else if (hid->ll_driver->request || hid->hid_output_raw_report)
1265 input_dev->event = hidinput_input_event;
1187 input_dev->open = hidinput_open; 1266 input_dev->open = hidinput_open;
1188 input_dev->close = hidinput_close; 1267 input_dev->close = hidinput_close;
1189 input_dev->setkeycode = hidinput_setkeycode; 1268 input_dev->setkeycode = hidinput_setkeycode;
@@ -1278,6 +1357,7 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
1278 int i, j, k; 1357 int i, j, k;
1279 1358
1280 INIT_LIST_HEAD(&hid->inputs); 1359 INIT_LIST_HEAD(&hid->inputs);
1360 INIT_WORK(&hid->led_work, hidinput_led_worker);
1281 1361
1282 if (!force) { 1362 if (!force) {
1283 for (i = 0; i < hid->maxcollection; i++) { 1363 for (i = 0; i < hid->maxcollection; i++) {
@@ -1379,6 +1459,12 @@ void hidinput_disconnect(struct hid_device *hid)
1379 input_unregister_device(hidinput->input); 1459 input_unregister_device(hidinput->input);
1380 kfree(hidinput); 1460 kfree(hidinput);
1381 } 1461 }
1462
1463 /* led_work is spawned by input_dev callbacks, but doesn't access the
1464 * parent input_dev at all. Once all input devices are removed, we
1465 * know that led_work will never get restarted, so we can cancel it
1466 * synchronously and are safe. */
1467 cancel_work_sync(&hid->led_work);
1382} 1468}
1383EXPORT_SYMBOL_GPL(hidinput_disconnect); 1469EXPORT_SYMBOL_GPL(hidinput_disconnect);
1384 1470
diff --git a/drivers/hid/hid-kye.c b/drivers/hid/hid-kye.c
index 1e2ee2aa84a0..73845120295e 100644
--- a/drivers/hid/hid-kye.c
+++ b/drivers/hid/hid-kye.c
@@ -268,6 +268,26 @@ static __u8 easypen_m610x_rdesc_fixed[] = {
268 0xC0 /* End Collection */ 268 0xC0 /* End Collection */
269}; 269};
270 270
271static __u8 *kye_consumer_control_fixup(struct hid_device *hdev, __u8 *rdesc,
272 unsigned int *rsize, int offset, const char *device_name) {
273 /*
274 * the fixup that need to be done:
275 * - change Usage Maximum in the Comsumer Control
276 * (report ID 3) to a reasonable value
277 */
278 if (*rsize >= offset + 31 &&
279 /* Usage Page (Consumer Devices) */
280 rdesc[offset] == 0x05 && rdesc[offset + 1] == 0x0c &&
281 /* Usage (Consumer Control) */
282 rdesc[offset + 2] == 0x09 && rdesc[offset + 3] == 0x01 &&
283 /* Usage Maximum > 12287 */
284 rdesc[offset + 10] == 0x2a && rdesc[offset + 12] > 0x2f) {
285 hid_info(hdev, "fixing up %s report descriptor\n", device_name);
286 rdesc[offset + 12] = 0x2f;
287 }
288 return rdesc;
289}
290
271static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc, 291static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
272 unsigned int *rsize) 292 unsigned int *rsize)
273{ 293{
@@ -315,23 +335,12 @@ static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
315 } 335 }
316 break; 336 break;
317 case USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE: 337 case USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE:
318 /* 338 rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 104,
319 * the fixup that need to be done: 339 "Genius Gila Gaming Mouse");
320 * - change Usage Maximum in the Comsumer Control 340 break;
321 * (report ID 3) to a reasonable value 341 case USB_DEVICE_ID_GENIUS_GX_IMPERATOR:
322 */ 342 rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 83,
323 if (*rsize >= 135 && 343 "Genius Gx Imperator Keyboard");
324 /* Usage Page (Consumer Devices) */
325 rdesc[104] == 0x05 && rdesc[105] == 0x0c &&
326 /* Usage (Consumer Control) */
327 rdesc[106] == 0x09 && rdesc[107] == 0x01 &&
328 /* Usage Maximum > 12287 */
329 rdesc[114] == 0x2a && rdesc[116] > 0x2f) {
330 hid_info(hdev,
331 "fixing up Genius Gila Gaming Mouse "
332 "report descriptor\n");
333 rdesc[116] = 0x2f;
334 }
335 break; 344 break;
336 } 345 }
337 return rdesc; 346 return rdesc;
@@ -428,6 +437,8 @@ static const struct hid_device_id kye_devices[] = {
428 USB_DEVICE_ID_KYE_EASYPEN_M610X) }, 437 USB_DEVICE_ID_KYE_EASYPEN_M610X) },
429 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, 438 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
430 USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) }, 439 USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE) },
440 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
441 USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
431 { } 442 { }
432}; 443};
433MODULE_DEVICE_TABLE(hid, kye_devices); 444MODULE_DEVICE_TABLE(hid, kye_devices);
diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
index cd33084c7860..7800b1410562 100644
--- a/drivers/hid/hid-logitech-dj.c
+++ b/drivers/hid/hid-logitech-dj.c
@@ -619,7 +619,7 @@ static int logi_dj_ll_input_event(struct input_dev *dev, unsigned int type,
619 619
620 struct hid_field *field; 620 struct hid_field *field;
621 struct hid_report *report; 621 struct hid_report *report;
622 unsigned char data[8]; 622 unsigned char *data;
623 int offset; 623 int offset;
624 624
625 dbg_hid("%s: %s, type:%d | code:%d | value:%d\n", 625 dbg_hid("%s: %s, type:%d | code:%d | value:%d\n",
@@ -635,6 +635,13 @@ static int logi_dj_ll_input_event(struct input_dev *dev, unsigned int type,
635 return -1; 635 return -1;
636 } 636 }
637 hid_set_field(field, offset, value); 637 hid_set_field(field, offset, value);
638
639 data = hid_alloc_report_buf(field->report, GFP_ATOMIC);
640 if (!data) {
641 dev_warn(&dev->dev, "failed to allocate report buf memory\n");
642 return -1;
643 }
644
638 hid_output_report(field->report, &data[0]); 645 hid_output_report(field->report, &data[0]);
639 646
640 output_report_enum = &dj_rcv_hiddev->report_enum[HID_OUTPUT_REPORT]; 647 output_report_enum = &dj_rcv_hiddev->report_enum[HID_OUTPUT_REPORT];
@@ -645,8 +652,9 @@ static int logi_dj_ll_input_event(struct input_dev *dev, unsigned int type,
645 652
646 hid_hw_request(dj_rcv_hiddev, report, HID_REQ_SET_REPORT); 653 hid_hw_request(dj_rcv_hiddev, report, HID_REQ_SET_REPORT);
647 654
648 return 0; 655 kfree(data);
649 656
657 return 0;
650} 658}
651 659
652static int logi_dj_ll_start(struct hid_device *hid) 660static int logi_dj_ll_start(struct hid_device *hid)
@@ -801,10 +809,10 @@ static int logi_dj_probe(struct hid_device *hdev,
801 } 809 }
802 810
803 /* This is enabling the polling urb on the IN endpoint */ 811 /* This is enabling the polling urb on the IN endpoint */
804 retval = hdev->ll_driver->open(hdev); 812 retval = hid_hw_open(hdev);
805 if (retval < 0) { 813 if (retval < 0) {
806 dev_err(&hdev->dev, "%s:hdev->ll_driver->open returned " 814 dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n",
807 "error:%d\n", __func__, retval); 815 __func__, retval);
808 goto llopen_failed; 816 goto llopen_failed;
809 } 817 }
810 818
@@ -821,7 +829,7 @@ static int logi_dj_probe(struct hid_device *hdev,
821 return retval; 829 return retval;
822 830
823logi_dj_recv_query_paired_devices_failed: 831logi_dj_recv_query_paired_devices_failed:
824 hdev->ll_driver->close(hdev); 832 hid_hw_close(hdev);
825 833
826llopen_failed: 834llopen_failed:
827switch_to_dj_mode_fail: 835switch_to_dj_mode_fail:
@@ -863,7 +871,7 @@ static void logi_dj_remove(struct hid_device *hdev)
863 871
864 cancel_work_sync(&djrcv_dev->work); 872 cancel_work_sync(&djrcv_dev->work);
865 873
866 hdev->ll_driver->close(hdev); 874 hid_hw_close(hdev);
867 hid_hw_stop(hdev); 875 hid_hw_stop(hdev);
868 876
869 /* I suppose that at this point the only context that can access 877 /* I suppose that at this point the only context that can access
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index 5bc37343eb22..3b43d1cfa936 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -36,7 +36,7 @@ MODULE_PARM_DESC(emulate_scroll_wheel, "Emulate a scroll wheel");
36static unsigned int scroll_speed = 32; 36static unsigned int scroll_speed = 32;
37static int param_set_scroll_speed(const char *val, struct kernel_param *kp) { 37static int param_set_scroll_speed(const char *val, struct kernel_param *kp) {
38 unsigned long speed; 38 unsigned long speed;
39 if (!val || strict_strtoul(val, 0, &speed) || speed > 63) 39 if (!val || kstrtoul(val, 0, &speed) || speed > 63)
40 return -EINVAL; 40 return -EINVAL;
41 scroll_speed = speed; 41 scroll_speed = speed;
42 return 0; 42 return 0;
@@ -484,7 +484,7 @@ static int magicmouse_probe(struct hid_device *hdev,
484 struct hid_report *report; 484 struct hid_report *report;
485 int ret; 485 int ret;
486 486
487 msc = kzalloc(sizeof(*msc), GFP_KERNEL); 487 msc = devm_kzalloc(&hdev->dev, sizeof(*msc), GFP_KERNEL);
488 if (msc == NULL) { 488 if (msc == NULL) {
489 hid_err(hdev, "can't alloc magicmouse descriptor\n"); 489 hid_err(hdev, "can't alloc magicmouse descriptor\n");
490 return -ENOMEM; 490 return -ENOMEM;
@@ -498,13 +498,13 @@ static int magicmouse_probe(struct hid_device *hdev,
498 ret = hid_parse(hdev); 498 ret = hid_parse(hdev);
499 if (ret) { 499 if (ret) {
500 hid_err(hdev, "magicmouse hid parse failed\n"); 500 hid_err(hdev, "magicmouse hid parse failed\n");
501 goto err_free; 501 return ret;
502 } 502 }
503 503
504 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 504 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
505 if (ret) { 505 if (ret) {
506 hid_err(hdev, "magicmouse hw start failed\n"); 506 hid_err(hdev, "magicmouse hw start failed\n");
507 goto err_free; 507 return ret;
508 } 508 }
509 509
510 if (!msc->input) { 510 if (!msc->input) {
@@ -548,19 +548,9 @@ static int magicmouse_probe(struct hid_device *hdev,
548 return 0; 548 return 0;
549err_stop_hw: 549err_stop_hw:
550 hid_hw_stop(hdev); 550 hid_hw_stop(hdev);
551err_free:
552 kfree(msc);
553 return ret; 551 return ret;
554} 552}
555 553
556static void magicmouse_remove(struct hid_device *hdev)
557{
558 struct magicmouse_sc *msc = hid_get_drvdata(hdev);
559
560 hid_hw_stop(hdev);
561 kfree(msc);
562}
563
564static const struct hid_device_id magic_mice[] = { 554static const struct hid_device_id magic_mice[] = {
565 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 555 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
566 USB_DEVICE_ID_APPLE_MAGICMOUSE), .driver_data = 0 }, 556 USB_DEVICE_ID_APPLE_MAGICMOUSE), .driver_data = 0 },
@@ -574,7 +564,6 @@ static struct hid_driver magicmouse_driver = {
574 .name = "magicmouse", 564 .name = "magicmouse",
575 .id_table = magic_mice, 565 .id_table = magic_mice,
576 .probe = magicmouse_probe, 566 .probe = magicmouse_probe,
577 .remove = magicmouse_remove,
578 .raw_event = magicmouse_raw_event, 567 .raw_event = magicmouse_raw_event,
579 .input_mapping = magicmouse_input_mapping, 568 .input_mapping = magicmouse_input_mapping,
580 .input_configured = magicmouse_input_configured, 569 .input_configured = magicmouse_input_configured,
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index cb0e361d7a4b..ac28f08c3866 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -133,6 +133,7 @@ static void mt_post_parse(struct mt_device *td);
133#define MT_CLS_NSMU 0x000a 133#define MT_CLS_NSMU 0x000a
134#define MT_CLS_DUAL_CONTACT_NUMBER 0x0010 134#define MT_CLS_DUAL_CONTACT_NUMBER 0x0010
135#define MT_CLS_DUAL_CONTACT_ID 0x0011 135#define MT_CLS_DUAL_CONTACT_ID 0x0011
136#define MT_CLS_WIN_8 0x0012
136 137
137/* vendor specific classes */ 138/* vendor specific classes */
138#define MT_CLS_3M 0x0101 139#define MT_CLS_3M 0x0101
@@ -205,6 +206,11 @@ static struct mt_class mt_classes[] = {
205 MT_QUIRK_CONTACT_CNT_ACCURATE | 206 MT_QUIRK_CONTACT_CNT_ACCURATE |
206 MT_QUIRK_SLOT_IS_CONTACTID, 207 MT_QUIRK_SLOT_IS_CONTACTID,
207 .maxcontacts = 2 }, 208 .maxcontacts = 2 },
209 { .name = MT_CLS_WIN_8,
210 .quirks = MT_QUIRK_ALWAYS_VALID |
211 MT_QUIRK_IGNORE_DUPLICATES |
212 MT_QUIRK_HOVERING |
213 MT_QUIRK_CONTACT_CNT_ACCURATE },
208 214
209 /* 215 /*
210 * vendor specific classes 216 * vendor specific classes
@@ -261,17 +267,6 @@ static struct mt_class mt_classes[] = {
261 { } 267 { }
262}; 268};
263 269
264static void mt_free_input_name(struct hid_input *hi)
265{
266 struct hid_device *hdev = hi->report->device;
267 const char *name = hi->input->name;
268
269 if (name != hdev->name) {
270 hi->input->name = hdev->name;
271 kfree(name);
272 }
273}
274
275static ssize_t mt_show_quirks(struct device *dev, 270static ssize_t mt_show_quirks(struct device *dev,
276 struct device_attribute *attr, 271 struct device_attribute *attr,
277 char *buf) 272 char *buf)
@@ -343,19 +338,6 @@ static void mt_feature_mapping(struct hid_device *hdev,
343 td->maxcontacts = td->mtclass.maxcontacts; 338 td->maxcontacts = td->mtclass.maxcontacts;
344 339
345 break; 340 break;
346 case 0xff0000c5:
347 if (field->report_count == 256 && field->report_size == 8) {
348 /* Win 8 devices need special quirks */
349 __s32 *quirks = &td->mtclass.quirks;
350 *quirks |= MT_QUIRK_ALWAYS_VALID;
351 *quirks |= MT_QUIRK_IGNORE_DUPLICATES;
352 *quirks |= MT_QUIRK_HOVERING;
353 *quirks |= MT_QUIRK_CONTACT_CNT_ACCURATE;
354 *quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
355 *quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
356 *quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
357 }
358 break;
359 } 341 }
360} 342}
361 343
@@ -415,13 +397,6 @@ static void mt_pen_report(struct hid_device *hid, struct hid_report *report)
415static void mt_pen_input_configured(struct hid_device *hdev, 397static void mt_pen_input_configured(struct hid_device *hdev,
416 struct hid_input *hi) 398 struct hid_input *hi)
417{ 399{
418 char *name = kzalloc(strlen(hi->input->name) + 5, GFP_KERNEL);
419 if (name) {
420 sprintf(name, "%s Pen", hi->input->name);
421 mt_free_input_name(hi);
422 hi->input->name = name;
423 }
424
425 /* force BTN_STYLUS to allow tablet matching in udev */ 400 /* force BTN_STYLUS to allow tablet matching in udev */
426 __set_bit(BTN_STYLUS, hi->input->keybit); 401 __set_bit(BTN_STYLUS, hi->input->keybit);
427} 402}
@@ -928,16 +903,26 @@ static void mt_post_parse(struct mt_device *td)
928static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi) 903static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
929{ 904{
930 struct mt_device *td = hid_get_drvdata(hdev); 905 struct mt_device *td = hid_get_drvdata(hdev);
931 char *name = kstrdup(hdev->name, GFP_KERNEL); 906 char *name;
932 907 const char *suffix = NULL;
933 if (name)
934 hi->input->name = name;
935 908
936 if (hi->report->id == td->mt_report_id) 909 if (hi->report->id == td->mt_report_id)
937 mt_touch_input_configured(hdev, hi); 910 mt_touch_input_configured(hdev, hi);
938 911
939 if (hi->report->id == td->pen_report_id) 912 if (hi->report->field[0]->physical == HID_DG_STYLUS) {
913 suffix = "Pen";
940 mt_pen_input_configured(hdev, hi); 914 mt_pen_input_configured(hdev, hi);
915 }
916
917 if (suffix) {
918 name = devm_kzalloc(&hi->input->dev,
919 strlen(hdev->name) + strlen(suffix) + 2,
920 GFP_KERNEL);
921 if (name) {
922 sprintf(name, "%s %s", hdev->name, suffix);
923 hi->input->name = name;
924 }
925 }
941} 926}
942 927
943static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) 928static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
@@ -945,7 +930,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
945 int ret, i; 930 int ret, i;
946 struct mt_device *td; 931 struct mt_device *td;
947 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ 932 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
948 struct hid_input *hi;
949 933
950 for (i = 0; mt_classes[i].name ; i++) { 934 for (i = 0; mt_classes[i].name ; i++) {
951 if (id->driver_data == mt_classes[i].name) { 935 if (id->driver_data == mt_classes[i].name) {
@@ -967,7 +951,19 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
967 hdev->quirks |= HID_QUIRK_MULTI_INPUT; 951 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
968 hdev->quirks |= HID_QUIRK_NO_EMPTY_INPUT; 952 hdev->quirks |= HID_QUIRK_NO_EMPTY_INPUT;
969 953
970 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL); 954 /*
955 * Handle special quirks for Windows 8 certified devices.
956 */
957 if (id->group == HID_GROUP_MULTITOUCH_WIN_8)
958 /*
959 * Some multitouch screens do not like to be polled for input
960 * reports. Fortunately, the Win8 spec says that all touches
961 * should be sent during each report, making the initialization
962 * of input reports unnecessary.
963 */
964 hdev->quirks |= HID_QUIRK_NO_INIT_INPUT_REPORTS;
965
966 td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL);
971 if (!td) { 967 if (!td) {
972 dev_err(&hdev->dev, "cannot allocate multitouch data\n"); 968 dev_err(&hdev->dev, "cannot allocate multitouch data\n");
973 return -ENOMEM; 969 return -ENOMEM;
@@ -980,11 +976,11 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
980 td->pen_report_id = -1; 976 td->pen_report_id = -1;
981 hid_set_drvdata(hdev, td); 977 hid_set_drvdata(hdev, td);
982 978
983 td->fields = kzalloc(sizeof(struct mt_fields), GFP_KERNEL); 979 td->fields = devm_kzalloc(&hdev->dev, sizeof(struct mt_fields),
980 GFP_KERNEL);
984 if (!td->fields) { 981 if (!td->fields) {
985 dev_err(&hdev->dev, "cannot allocate multitouch fields data\n"); 982 dev_err(&hdev->dev, "cannot allocate multitouch fields data\n");
986 ret = -ENOMEM; 983 return -ENOMEM;
987 goto fail;
988 } 984 }
989 985
990 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID) 986 if (id->vendor == HID_ANY_ID && id->product == HID_ANY_ID)
@@ -992,29 +988,22 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
992 988
993 ret = hid_parse(hdev); 989 ret = hid_parse(hdev);
994 if (ret != 0) 990 if (ret != 0)
995 goto fail; 991 return ret;
996 992
997 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 993 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
998 if (ret) 994 if (ret)
999 goto hid_fail; 995 return ret;
1000 996
1001 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group); 997 ret = sysfs_create_group(&hdev->dev.kobj, &mt_attribute_group);
1002 998
1003 mt_set_maxcontacts(hdev); 999 mt_set_maxcontacts(hdev);
1004 mt_set_input_mode(hdev); 1000 mt_set_input_mode(hdev);
1005 1001
1006 kfree(td->fields); 1002 /* release .fields memory as it is not used anymore */
1003 devm_kfree(&hdev->dev, td->fields);
1007 td->fields = NULL; 1004 td->fields = NULL;
1008 1005
1009 return 0; 1006 return 0;
1010
1011hid_fail:
1012 list_for_each_entry(hi, &hdev->inputs, list)
1013 mt_free_input_name(hi);
1014fail:
1015 kfree(td->fields);
1016 kfree(td);
1017 return ret;
1018} 1007}
1019 1008
1020#ifdef CONFIG_PM 1009#ifdef CONFIG_PM
@@ -1039,17 +1028,8 @@ static int mt_resume(struct hid_device *hdev)
1039 1028
1040static void mt_remove(struct hid_device *hdev) 1029static void mt_remove(struct hid_device *hdev)
1041{ 1030{
1042 struct mt_device *td = hid_get_drvdata(hdev);
1043 struct hid_input *hi;
1044
1045 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group); 1031 sysfs_remove_group(&hdev->dev.kobj, &mt_attribute_group);
1046 list_for_each_entry(hi, &hdev->inputs, list)
1047 mt_free_input_name(hi);
1048
1049 hid_hw_stop(hdev); 1032 hid_hw_stop(hdev);
1050
1051 kfree(td);
1052 hid_set_drvdata(hdev, NULL);
1053} 1033}
1054 1034
1055static const struct hid_device_id mt_devices[] = { 1035static const struct hid_device_id mt_devices[] = {
@@ -1371,6 +1351,11 @@ static const struct hid_device_id mt_devices[] = {
1371 1351
1372 /* Generic MT device */ 1352 /* Generic MT device */
1373 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) }, 1353 { HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH, HID_ANY_ID, HID_ANY_ID) },
1354
1355 /* Generic Win 8 certified MT device */
1356 { .driver_data = MT_CLS_WIN_8,
1357 HID_DEVICE(HID_BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8,
1358 HID_ANY_ID, HID_ANY_ID) },
1374 { } 1359 { }
1375}; 1360};
1376MODULE_DEVICE_TABLE(hid, mt_devices); 1361MODULE_DEVICE_TABLE(hid, mt_devices);
diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
index ef95102515e4..600f2075512f 100644
--- a/drivers/hid/hid-ntrig.c
+++ b/drivers/hid/hid-ntrig.c
@@ -115,7 +115,8 @@ static inline int ntrig_get_mode(struct hid_device *hdev)
115 struct hid_report *report = hdev->report_enum[HID_FEATURE_REPORT]. 115 struct hid_report *report = hdev->report_enum[HID_FEATURE_REPORT].
116 report_id_hash[0x0d]; 116 report_id_hash[0x0d];
117 117
118 if (!report) 118 if (!report || report->maxfield < 1 ||
119 report->field[0]->report_count < 1)
119 return -EINVAL; 120 return -EINVAL;
120 121
121 hid_hw_request(hdev, report, HID_REQ_GET_REPORT); 122 hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
@@ -237,7 +238,7 @@ static ssize_t set_min_width(struct device *dev,
237 238
238 unsigned long val; 239 unsigned long val;
239 240
240 if (strict_strtoul(buf, 0, &val)) 241 if (kstrtoul(buf, 0, &val))
241 return -EINVAL; 242 return -EINVAL;
242 243
243 if (val > nd->sensor_physical_width) 244 if (val > nd->sensor_physical_width)
@@ -272,7 +273,7 @@ static ssize_t set_min_height(struct device *dev,
272 273
273 unsigned long val; 274 unsigned long val;
274 275
275 if (strict_strtoul(buf, 0, &val)) 276 if (kstrtoul(buf, 0, &val))
276 return -EINVAL; 277 return -EINVAL;
277 278
278 if (val > nd->sensor_physical_height) 279 if (val > nd->sensor_physical_height)
@@ -306,7 +307,7 @@ static ssize_t set_activate_slack(struct device *dev,
306 307
307 unsigned long val; 308 unsigned long val;
308 309
309 if (strict_strtoul(buf, 0, &val)) 310 if (kstrtoul(buf, 0, &val))
310 return -EINVAL; 311 return -EINVAL;
311 312
312 if (val > 0x7f) 313 if (val > 0x7f)
@@ -341,7 +342,7 @@ static ssize_t set_activation_width(struct device *dev,
341 342
342 unsigned long val; 343 unsigned long val;
343 344
344 if (strict_strtoul(buf, 0, &val)) 345 if (kstrtoul(buf, 0, &val))
345 return -EINVAL; 346 return -EINVAL;
346 347
347 if (val > nd->sensor_physical_width) 348 if (val > nd->sensor_physical_width)
@@ -377,7 +378,7 @@ static ssize_t set_activation_height(struct device *dev,
377 378
378 unsigned long val; 379 unsigned long val;
379 380
380 if (strict_strtoul(buf, 0, &val)) 381 if (kstrtoul(buf, 0, &val))
381 return -EINVAL; 382 return -EINVAL;
382 383
383 if (val > nd->sensor_physical_height) 384 if (val > nd->sensor_physical_height)
@@ -411,7 +412,7 @@ static ssize_t set_deactivate_slack(struct device *dev,
411 412
412 unsigned long val; 413 unsigned long val;
413 414
414 if (strict_strtoul(buf, 0, &val)) 415 if (kstrtoul(buf, 0, &val))
415 return -EINVAL; 416 return -EINVAL;
416 417
417 /* 418 /*
diff --git a/drivers/hid/hid-picolcd_cir.c b/drivers/hid/hid-picolcd_cir.c
index e346038f0f11..59d5eb1e742c 100644
--- a/drivers/hid/hid-picolcd_cir.c
+++ b/drivers/hid/hid-picolcd_cir.c
@@ -145,6 +145,7 @@ void picolcd_exit_cir(struct picolcd_data *data)
145 struct rc_dev *rdev = data->rc_dev; 145 struct rc_dev *rdev = data->rc_dev;
146 146
147 data->rc_dev = NULL; 147 data->rc_dev = NULL;
148 rc_unregister_device(rdev); 148 if (rdev)
149 rc_unregister_device(rdev);
149} 150}
150 151
diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
index b48092d0e139..acbb021065ec 100644
--- a/drivers/hid/hid-picolcd_core.c
+++ b/drivers/hid/hid-picolcd_core.c
@@ -290,7 +290,7 @@ static ssize_t picolcd_operation_mode_store(struct device *dev,
290 buf += 10; 290 buf += 10;
291 cnt -= 10; 291 cnt -= 10;
292 } 292 }
293 if (!report) 293 if (!report || report->maxfield != 1)
294 return -EINVAL; 294 return -EINVAL;
295 295
296 while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r')) 296 while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r'))
diff --git a/drivers/hid/hid-picolcd_debugfs.c b/drivers/hid/hid-picolcd_debugfs.c
index 59ab8e157e6b..024cdf3c2297 100644
--- a/drivers/hid/hid-picolcd_debugfs.c
+++ b/drivers/hid/hid-picolcd_debugfs.c
@@ -394,7 +394,7 @@ static void dump_buff_as_hex(char *dst, size_t dst_sz, const u8 *data,
394void picolcd_debug_out_report(struct picolcd_data *data, 394void picolcd_debug_out_report(struct picolcd_data *data,
395 struct hid_device *hdev, struct hid_report *report) 395 struct hid_device *hdev, struct hid_report *report)
396{ 396{
397 u8 raw_data[70]; 397 u8 *raw_data;
398 int raw_size = (report->size >> 3) + 1; 398 int raw_size = (report->size >> 3) + 1;
399 char *buff; 399 char *buff;
400#define BUFF_SZ 256 400#define BUFF_SZ 256
@@ -407,20 +407,20 @@ void picolcd_debug_out_report(struct picolcd_data *data,
407 if (!buff) 407 if (!buff)
408 return; 408 return;
409 409
410 snprintf(buff, BUFF_SZ, "\nout report %d (size %d) = ", 410 raw_data = hid_alloc_report_buf(report, GFP_ATOMIC);
411 report->id, raw_size); 411 if (!raw_data) {
412 hid_debug_event(hdev, buff);
413 if (raw_size + 5 > sizeof(raw_data)) {
414 kfree(buff); 412 kfree(buff);
415 hid_debug_event(hdev, " TOO BIG\n");
416 return; 413 return;
417 } else {
418 raw_data[0] = report->id;
419 hid_output_report(report, raw_data);
420 dump_buff_as_hex(buff, BUFF_SZ, raw_data, raw_size);
421 hid_debug_event(hdev, buff);
422 } 414 }
423 415
416 snprintf(buff, BUFF_SZ, "\nout report %d (size %d) = ",
417 report->id, raw_size);
418 hid_debug_event(hdev, buff);
419 raw_data[0] = report->id;
420 hid_output_report(report, raw_data);
421 dump_buff_as_hex(buff, BUFF_SZ, raw_data, raw_size);
422 hid_debug_event(hdev, buff);
423
424 switch (report->id) { 424 switch (report->id) {
425 case REPORT_LED_STATE: 425 case REPORT_LED_STATE:
426 /* 1 data byte with GPO state */ 426 /* 1 data byte with GPO state */
@@ -644,6 +644,7 @@ void picolcd_debug_out_report(struct picolcd_data *data,
644 break; 644 break;
645 } 645 }
646 wake_up_interruptible(&hdev->debug_wait); 646 wake_up_interruptible(&hdev->debug_wait);
647 kfree(raw_data);
647 kfree(buff); 648 kfree(buff);
648} 649}
649 650
diff --git a/drivers/hid/hid-picolcd_fb.c b/drivers/hid/hid-picolcd_fb.c
index 591f6b22aa94..c930ab8554ea 100644
--- a/drivers/hid/hid-picolcd_fb.c
+++ b/drivers/hid/hid-picolcd_fb.c
@@ -593,10 +593,14 @@ err_nomem:
593void picolcd_exit_framebuffer(struct picolcd_data *data) 593void picolcd_exit_framebuffer(struct picolcd_data *data)
594{ 594{
595 struct fb_info *info = data->fb_info; 595 struct fb_info *info = data->fb_info;
596 struct picolcd_fb_data *fbdata = info->par; 596 struct picolcd_fb_data *fbdata;
597 unsigned long flags; 597 unsigned long flags;
598 598
599 if (!info)
600 return;
601
599 device_remove_file(&data->hdev->dev, &dev_attr_fb_update_rate); 602 device_remove_file(&data->hdev->dev, &dev_attr_fb_update_rate);
603 fbdata = info->par;
600 604
601 /* disconnect framebuffer from HID dev */ 605 /* disconnect framebuffer from HID dev */
602 spin_lock_irqsave(&fbdata->lock, flags); 606 spin_lock_irqsave(&fbdata->lock, flags);
diff --git a/drivers/hid/hid-pl.c b/drivers/hid/hid-pl.c
index d29112fa5cd5..2dcd7d98dbd6 100644
--- a/drivers/hid/hid-pl.c
+++ b/drivers/hid/hid-pl.c
@@ -132,8 +132,14 @@ static int plff_init(struct hid_device *hid)
132 strong = &report->field[0]->value[2]; 132 strong = &report->field[0]->value[2];
133 weak = &report->field[0]->value[3]; 133 weak = &report->field[0]->value[3];
134 debug("detected single-field device"); 134 debug("detected single-field device");
135 } else if (report->maxfield >= 4 && report->field[0]->maxusage == 1 && 135 } else if (report->field[0]->maxusage == 1 &&
136 report->field[0]->usage[0].hid == (HID_UP_LED | 0x43)) { 136 report->field[0]->usage[0].hid ==
137 (HID_UP_LED | 0x43) &&
138 report->maxfield >= 4 &&
139 report->field[0]->report_count >= 1 &&
140 report->field[1]->report_count >= 1 &&
141 report->field[2]->report_count >= 1 &&
142 report->field[3]->report_count >= 1) {
137 report->field[0]->value[0] = 0x00; 143 report->field[0]->value[0] = 0x00;
138 report->field[1]->value[0] = 0x00; 144 report->field[1]->value[0] = 0x00;
139 strong = &report->field[2]->value[0]; 145 strong = &report->field[2]->value[0];
diff --git a/drivers/hid/hid-roccat-arvo.c b/drivers/hid/hid-roccat-arvo.c
index eed7f52084c5..1948208fe038 100644
--- a/drivers/hid/hid-roccat-arvo.c
+++ b/drivers/hid/hid-roccat-arvo.c
@@ -59,7 +59,7 @@ static ssize_t arvo_sysfs_set_mode_key(struct device *dev,
59 unsigned long state; 59 unsigned long state;
60 int retval; 60 int retval;
61 61
62 retval = strict_strtoul(buf, 10, &state); 62 retval = kstrtoul(buf, 10, &state);
63 if (retval) 63 if (retval)
64 return retval; 64 return retval;
65 65
@@ -109,7 +109,7 @@ static ssize_t arvo_sysfs_set_key_mask(struct device *dev,
109 unsigned long key_mask; 109 unsigned long key_mask;
110 int retval; 110 int retval;
111 111
112 retval = strict_strtoul(buf, 10, &key_mask); 112 retval = kstrtoul(buf, 10, &key_mask);
113 if (retval) 113 if (retval)
114 return retval; 114 return retval;
115 115
@@ -163,7 +163,7 @@ static ssize_t arvo_sysfs_set_actual_profile(struct device *dev,
163 unsigned long profile; 163 unsigned long profile;
164 int retval; 164 int retval;
165 165
166 retval = strict_strtoul(buf, 10, &profile); 166 retval = kstrtoul(buf, 10, &profile);
167 if (retval) 167 if (retval)
168 return retval; 168 return retval;
169 169
diff --git a/drivers/hid/hid-roccat-isku.c b/drivers/hid/hid-roccat-isku.c
index b7a4e10e112e..bc62ed91e451 100644
--- a/drivers/hid/hid-roccat-isku.c
+++ b/drivers/hid/hid-roccat-isku.c
@@ -82,7 +82,7 @@ static ssize_t isku_sysfs_set_actual_profile(struct device *dev,
82 isku = hid_get_drvdata(dev_get_drvdata(dev)); 82 isku = hid_get_drvdata(dev_get_drvdata(dev));
83 usb_dev = interface_to_usbdev(to_usb_interface(dev)); 83 usb_dev = interface_to_usbdev(to_usb_interface(dev));
84 84
85 retval = strict_strtoul(buf, 10, &profile); 85 retval = kstrtoul(buf, 10, &profile);
86 if (retval) 86 if (retval)
87 return retval; 87 return retval;
88 88
diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c
index 6e614a85f175..602c188e9d86 100644
--- a/drivers/hid/hid-roccat-kone.c
+++ b/drivers/hid/hid-roccat-kone.c
@@ -476,7 +476,7 @@ static ssize_t kone_sysfs_set_tcu(struct device *dev,
476 kone = hid_get_drvdata(dev_get_drvdata(dev)); 476 kone = hid_get_drvdata(dev_get_drvdata(dev));
477 usb_dev = interface_to_usbdev(to_usb_interface(dev)); 477 usb_dev = interface_to_usbdev(to_usb_interface(dev));
478 478
479 retval = strict_strtoul(buf, 10, &state); 479 retval = kstrtoul(buf, 10, &state);
480 if (retval) 480 if (retval)
481 return retval; 481 return retval;
482 482
@@ -566,7 +566,7 @@ static ssize_t kone_sysfs_set_startup_profile(struct device *dev,
566 kone = hid_get_drvdata(dev_get_drvdata(dev)); 566 kone = hid_get_drvdata(dev_get_drvdata(dev));
567 usb_dev = interface_to_usbdev(to_usb_interface(dev)); 567 usb_dev = interface_to_usbdev(to_usb_interface(dev));
568 568
569 retval = strict_strtoul(buf, 10, &new_startup_profile); 569 retval = kstrtoul(buf, 10, &new_startup_profile);
570 if (retval) 570 if (retval)
571 return retval; 571 return retval;
572 572
diff --git a/drivers/hid/hid-roccat-koneplus.c b/drivers/hid/hid-roccat-koneplus.c
index db4d8b6a2542..5ddf605b6b89 100644
--- a/drivers/hid/hid-roccat-koneplus.c
+++ b/drivers/hid/hid-roccat-koneplus.c
@@ -267,7 +267,7 @@ static ssize_t koneplus_sysfs_set_actual_profile(struct device *dev,
267 koneplus = hid_get_drvdata(dev_get_drvdata(dev)); 267 koneplus = hid_get_drvdata(dev_get_drvdata(dev));
268 usb_dev = interface_to_usbdev(to_usb_interface(dev)); 268 usb_dev = interface_to_usbdev(to_usb_interface(dev));
269 269
270 retval = strict_strtoul(buf, 10, &profile); 270 retval = kstrtoul(buf, 10, &profile);
271 if (retval) 271 if (retval)
272 return retval; 272 return retval;
273 273
diff --git a/drivers/hid/hid-roccat-konepure.c b/drivers/hid/hid-roccat-konepure.c
index fa02b1f44979..99a605ebb665 100644
--- a/drivers/hid/hid-roccat-konepure.c
+++ b/drivers/hid/hid-roccat-konepure.c
@@ -275,6 +275,7 @@ static int konepure_raw_event(struct hid_device *hdev,
275 275
276static const struct hid_device_id konepure_devices[] = { 276static const struct hid_device_id konepure_devices[] = {
277 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) }, 277 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE) },
278 { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPURE_OPTICAL) },
278 { } 279 { }
279}; 280};
280 281
@@ -313,5 +314,5 @@ module_init(konepure_init);
313module_exit(konepure_exit); 314module_exit(konepure_exit);
314 315
315MODULE_AUTHOR("Stefan Achatz"); 316MODULE_AUTHOR("Stefan Achatz");
316MODULE_DESCRIPTION("USB Roccat KonePure driver"); 317MODULE_DESCRIPTION("USB Roccat KonePure/Optical driver");
317MODULE_LICENSE("GPL v2"); 318MODULE_LICENSE("GPL v2");
diff --git a/drivers/hid/hid-roccat-kovaplus.c b/drivers/hid/hid-roccat-kovaplus.c
index 8a0f2993411f..515bc03136c0 100644
--- a/drivers/hid/hid-roccat-kovaplus.c
+++ b/drivers/hid/hid-roccat-kovaplus.c
@@ -295,7 +295,7 @@ static ssize_t kovaplus_sysfs_set_actual_profile(struct device *dev,
295 kovaplus = hid_get_drvdata(dev_get_drvdata(dev)); 295 kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
296 usb_dev = interface_to_usbdev(to_usb_interface(dev)); 296 usb_dev = interface_to_usbdev(to_usb_interface(dev));
297 297
298 retval = strict_strtoul(buf, 10, &profile); 298 retval = kstrtoul(buf, 10, &profile);
299 if (retval) 299 if (retval)
300 return retval; 300 return retval;
301 301
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index ca7498107327..10e1581022cf 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -103,8 +103,7 @@ static int sensor_hub_get_physical_device_count(
103 103
104 list_for_each_entry(report, &report_enum->report_list, list) { 104 list_for_each_entry(report, &report_enum->report_list, list) {
105 field = report->field[0]; 105 field = report->field[0];
106 if (report->maxfield && field && 106 if (report->maxfield && field && field->physical)
107 field->physical)
108 cnt++; 107 cnt++;
109 } 108 }
110 109
@@ -192,12 +191,12 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
192 u32 field_index, s32 value) 191 u32 field_index, s32 value)
193{ 192{
194 struct hid_report *report; 193 struct hid_report *report;
195 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev); 194 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
196 int ret = 0; 195 int ret = 0;
197 196
198 mutex_lock(&data->mutex); 197 mutex_lock(&data->mutex);
199 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT); 198 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
200 if (!report || (field_index >= report->maxfield)) { 199 if (!report || (field_index >= report->maxfield)) {
201 ret = -EINVAL; 200 ret = -EINVAL;
202 goto done_proc; 201 goto done_proc;
203 } 202 }
@@ -216,12 +215,13 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
216 u32 field_index, s32 *value) 215 u32 field_index, s32 *value)
217{ 216{
218 struct hid_report *report; 217 struct hid_report *report;
219 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev); 218 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
220 int ret = 0; 219 int ret = 0;
221 220
222 mutex_lock(&data->mutex); 221 mutex_lock(&data->mutex);
223 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT); 222 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
224 if (!report || (field_index >= report->maxfield)) { 223 if (!report || (field_index >= report->maxfield) ||
224 report->field[field_index]->report_count < 1) {
225 ret = -EINVAL; 225 ret = -EINVAL;
226 goto done_proc; 226 goto done_proc;
227 } 227 }
@@ -241,7 +241,7 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
241 u32 usage_id, 241 u32 usage_id,
242 u32 attr_usage_id, u32 report_id) 242 u32 attr_usage_id, u32 report_id)
243{ 243{
244 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev); 244 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
245 unsigned long flags; 245 unsigned long flags;
246 struct hid_report *report; 246 struct hid_report *report;
247 int ret_val = 0; 247 int ret_val = 0;
@@ -302,7 +302,7 @@ int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
302 302
303 /* Initialize with defaults */ 303 /* Initialize with defaults */
304 info->usage_id = usage_id; 304 info->usage_id = usage_id;
305 info->attrib_id = attr_usage_id; 305 info->attrib_id = attr_usage_id;
306 info->report_id = -1; 306 info->report_id = -1;
307 info->index = -1; 307 info->index = -1;
308 info->units = -1; 308 info->units = -1;
@@ -333,7 +333,7 @@ int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
333 if (field->usage[j].hid == 333 if (field->usage[j].hid ==
334 attr_usage_id && 334 attr_usage_id &&
335 field->usage[j].collection_index == 335 field->usage[j].collection_index ==
336 collection_index) { 336 collection_index) {
337 sensor_hub_fill_attr_info(info, 337 sensor_hub_fill_attr_info(info,
338 i, report->id, 338 i, report->id,
339 field->unit, 339 field->unit,
@@ -357,7 +357,7 @@ EXPORT_SYMBOL_GPL(sensor_hub_input_get_attribute_info);
357#ifdef CONFIG_PM 357#ifdef CONFIG_PM
358static int sensor_hub_suspend(struct hid_device *hdev, pm_message_t message) 358static int sensor_hub_suspend(struct hid_device *hdev, pm_message_t message)
359{ 359{
360 struct sensor_hub_data *pdata = hid_get_drvdata(hdev); 360 struct sensor_hub_data *pdata = hid_get_drvdata(hdev);
361 struct hid_sensor_hub_callbacks_list *callback; 361 struct hid_sensor_hub_callbacks_list *callback;
362 362
363 hid_dbg(hdev, " sensor_hub_suspend\n"); 363 hid_dbg(hdev, " sensor_hub_suspend\n");
@@ -374,7 +374,7 @@ static int sensor_hub_suspend(struct hid_device *hdev, pm_message_t message)
374 374
375static int sensor_hub_resume(struct hid_device *hdev) 375static int sensor_hub_resume(struct hid_device *hdev)
376{ 376{
377 struct sensor_hub_data *pdata = hid_get_drvdata(hdev); 377 struct sensor_hub_data *pdata = hid_get_drvdata(hdev);
378 struct hid_sensor_hub_callbacks_list *callback; 378 struct hid_sensor_hub_callbacks_list *callback;
379 379
380 hid_dbg(hdev, " sensor_hub_resume\n"); 380 hid_dbg(hdev, " sensor_hub_resume\n");
@@ -394,6 +394,7 @@ static int sensor_hub_reset_resume(struct hid_device *hdev)
394 return 0; 394 return 0;
395} 395}
396#endif 396#endif
397
397/* 398/*
398 * Handle raw report as sent by device 399 * Handle raw report as sent by device
399 */ 400 */
@@ -416,12 +417,11 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
416 return 1; 417 return 1;
417 418
418 ptr = raw_data; 419 ptr = raw_data;
419 ptr++; /*Skip report id*/ 420 ptr++; /* Skip report id */
420 421
421 spin_lock_irqsave(&pdata->lock, flags); 422 spin_lock_irqsave(&pdata->lock, flags);
422 423
423 for (i = 0; i < report->maxfield; ++i) { 424 for (i = 0; i < report->maxfield; ++i) {
424
425 hid_dbg(hdev, "%d collection_index:%x hid:%x sz:%x\n", 425 hid_dbg(hdev, "%d collection_index:%x hid:%x sz:%x\n",
426 i, report->field[i]->usage->collection_index, 426 i, report->field[i]->usage->collection_index,
427 report->field[i]->usage->hid, 427 report->field[i]->usage->hid,
@@ -431,11 +431,10 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
431 if (pdata->pending.status && pdata->pending.attr_usage_id == 431 if (pdata->pending.status && pdata->pending.attr_usage_id ==
432 report->field[i]->usage->hid) { 432 report->field[i]->usage->hid) {
433 hid_dbg(hdev, "data was pending ...\n"); 433 hid_dbg(hdev, "data was pending ...\n");
434 pdata->pending.raw_data = kmalloc(sz, GFP_ATOMIC); 434 pdata->pending.raw_data = kmemdup(ptr, sz, GFP_ATOMIC);
435 if (pdata->pending.raw_data) { 435 if (pdata->pending.raw_data)
436 memcpy(pdata->pending.raw_data, ptr, sz); 436 pdata->pending.raw_size = sz;
437 pdata->pending.raw_size = sz; 437 else
438 } else
439 pdata->pending.raw_size = 0; 438 pdata->pending.raw_size = 0;
440 complete(&pdata->pending.ready); 439 complete(&pdata->pending.ready);
441 } 440 }
@@ -478,16 +477,15 @@ static int sensor_hub_probe(struct hid_device *hdev,
478 struct hid_field *field; 477 struct hid_field *field;
479 int dev_cnt; 478 int dev_cnt;
480 479
481 sd = kzalloc(sizeof(struct sensor_hub_data), GFP_KERNEL); 480 sd = devm_kzalloc(&hdev->dev, sizeof(*sd), GFP_KERNEL);
482 if (!sd) { 481 if (!sd) {
483 hid_err(hdev, "cannot allocate Sensor data\n"); 482 hid_err(hdev, "cannot allocate Sensor data\n");
484 return -ENOMEM; 483 return -ENOMEM;
485 } 484 }
486 sd->hsdev = kzalloc(sizeof(struct hid_sensor_hub_device), GFP_KERNEL); 485 sd->hsdev = devm_kzalloc(&hdev->dev, sizeof(*sd->hsdev), GFP_KERNEL);
487 if (!sd->hsdev) { 486 if (!sd->hsdev) {
488 hid_err(hdev, "cannot allocate hid_sensor_hub_device\n"); 487 hid_err(hdev, "cannot allocate hid_sensor_hub_device\n");
489 ret = -ENOMEM; 488 return -ENOMEM;
490 goto err_free_hub;
491 } 489 }
492 hid_set_drvdata(hdev, sd); 490 hid_set_drvdata(hdev, sd);
493 sd->hsdev->hdev = hdev; 491 sd->hsdev->hdev = hdev;
@@ -499,14 +497,14 @@ static int sensor_hub_probe(struct hid_device *hdev,
499 ret = hid_parse(hdev); 497 ret = hid_parse(hdev);
500 if (ret) { 498 if (ret) {
501 hid_err(hdev, "parse failed\n"); 499 hid_err(hdev, "parse failed\n");
502 goto err_free; 500 return ret;
503 } 501 }
504 INIT_LIST_HEAD(&hdev->inputs); 502 INIT_LIST_HEAD(&hdev->inputs);
505 503
506 ret = hid_hw_start(hdev, 0); 504 ret = hid_hw_start(hdev, 0);
507 if (ret) { 505 if (ret) {
508 hid_err(hdev, "hw start failed\n"); 506 hid_err(hdev, "hw start failed\n");
509 goto err_free; 507 return ret;
510 } 508 }
511 ret = hid_hw_open(hdev); 509 ret = hid_hw_open(hdev);
512 if (ret) { 510 if (ret) {
@@ -539,7 +537,7 @@ static int sensor_hub_probe(struct hid_device *hdev,
539 field->physical) { 537 field->physical) {
540 name = kasprintf(GFP_KERNEL, "HID-SENSOR-%x", 538 name = kasprintf(GFP_KERNEL, "HID-SENSOR-%x",
541 field->physical); 539 field->physical);
542 if (name == NULL) { 540 if (name == NULL) {
543 hid_err(hdev, "Failed MFD device name\n"); 541 hid_err(hdev, "Failed MFD device name\n");
544 ret = -ENOMEM; 542 ret = -ENOMEM;
545 goto err_free_names; 543 goto err_free_names;
@@ -571,10 +569,6 @@ err_close:
571 hid_hw_close(hdev); 569 hid_hw_close(hdev);
572err_stop_hw: 570err_stop_hw:
573 hid_hw_stop(hdev); 571 hid_hw_stop(hdev);
574err_free:
575 kfree(sd->hsdev);
576err_free_hub:
577 kfree(sd);
578 572
579 return ret; 573 return ret;
580} 574}
@@ -598,8 +592,6 @@ static void sensor_hub_remove(struct hid_device *hdev)
598 kfree(data->hid_sensor_hub_client_devs); 592 kfree(data->hid_sensor_hub_client_devs);
599 hid_set_drvdata(hdev, NULL); 593 hid_set_drvdata(hdev, NULL);
600 mutex_destroy(&data->mutex); 594 mutex_destroy(&data->mutex);
601 kfree(data->hsdev);
602 kfree(data);
603} 595}
604 596
605static const struct hid_device_id sensor_hub_devices[] = { 597static const struct hid_device_id sensor_hub_devices[] = {
@@ -617,8 +609,8 @@ static struct hid_driver sensor_hub_driver = {
617 .raw_event = sensor_hub_raw_event, 609 .raw_event = sensor_hub_raw_event,
618#ifdef CONFIG_PM 610#ifdef CONFIG_PM
619 .suspend = sensor_hub_suspend, 611 .suspend = sensor_hub_suspend,
620 .resume = sensor_hub_resume, 612 .resume = sensor_hub_resume,
621 .reset_resume = sensor_hub_reset_resume, 613 .reset_resume = sensor_hub_reset_resume,
622#endif 614#endif
623}; 615};
624module_hid_driver(sensor_hub_driver); 616module_hid_driver(sensor_hub_driver);
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 87fbe2924cfa..30dbb6b40bbf 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -624,7 +624,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
624 struct sony_sc *sc; 624 struct sony_sc *sc;
625 unsigned int connect_mask = HID_CONNECT_DEFAULT; 625 unsigned int connect_mask = HID_CONNECT_DEFAULT;
626 626
627 sc = kzalloc(sizeof(*sc), GFP_KERNEL); 627 sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL);
628 if (sc == NULL) { 628 if (sc == NULL) {
629 hid_err(hdev, "can't alloc sony descriptor\n"); 629 hid_err(hdev, "can't alloc sony descriptor\n");
630 return -ENOMEM; 630 return -ENOMEM;
@@ -636,7 +636,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
636 ret = hid_parse(hdev); 636 ret = hid_parse(hdev);
637 if (ret) { 637 if (ret) {
638 hid_err(hdev, "parse failed\n"); 638 hid_err(hdev, "parse failed\n");
639 goto err_free; 639 return ret;
640 } 640 }
641 641
642 if (sc->quirks & VAIO_RDESC_CONSTANT) 642 if (sc->quirks & VAIO_RDESC_CONSTANT)
@@ -649,7 +649,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
649 ret = hid_hw_start(hdev, connect_mask); 649 ret = hid_hw_start(hdev, connect_mask);
650 if (ret) { 650 if (ret) {
651 hid_err(hdev, "hw start failed\n"); 651 hid_err(hdev, "hw start failed\n");
652 goto err_free; 652 return ret;
653 } 653 }
654 654
655 if (sc->quirks & SIXAXIS_CONTROLLER_USB) { 655 if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
@@ -669,8 +669,6 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
669 return 0; 669 return 0;
670err_stop: 670err_stop:
671 hid_hw_stop(hdev); 671 hid_hw_stop(hdev);
672err_free:
673 kfree(sc);
674 return ret; 672 return ret;
675} 673}
676 674
@@ -682,7 +680,6 @@ static void sony_remove(struct hid_device *hdev)
682 buzz_remove(hdev); 680 buzz_remove(hdev);
683 681
684 hid_hw_stop(hdev); 682 hid_hw_stop(hdev);
685 kfree(sc);
686} 683}
687 684
688static const struct hid_device_id sony_devices[] = { 685static const struct hid_device_id sony_devices[] = {
diff --git a/drivers/hid/hid-speedlink.c b/drivers/hid/hid-speedlink.c
index a2f587d004e1..7112f3e832ee 100644
--- a/drivers/hid/hid-speedlink.c
+++ b/drivers/hid/hid-speedlink.c
@@ -3,7 +3,7 @@
3 * Fixes "jumpy" cursor and removes nonexistent keyboard LEDS from 3 * Fixes "jumpy" cursor and removes nonexistent keyboard LEDS from
4 * the HID descriptor. 4 * the HID descriptor.
5 * 5 *
6 * Copyright (c) 2011 Stefan Kriwanek <mail@stefankriwanek.de> 6 * Copyright (c) 2011, 2013 Stefan Kriwanek <dev@stefankriwanek.de>
7 */ 7 */
8 8
9/* 9/*
@@ -46,8 +46,13 @@ static int speedlink_event(struct hid_device *hdev, struct hid_field *field,
46 struct hid_usage *usage, __s32 value) 46 struct hid_usage *usage, __s32 value)
47{ 47{
48 /* No other conditions due to usage_table. */ 48 /* No other conditions due to usage_table. */
49 /* Fix "jumpy" cursor (invalid events sent by device). */ 49
50 if (value == 256) 50 /* This fixes the "jumpy" cursor occuring due to invalid events sent
51 * by the device. Some devices only send them with value==+256, others
52 * don't. However, catching abs(value)>=256 is restrictive enough not
53 * to interfere with devices that were bug-free (has been tested).
54 */
55 if (abs(value) >= 256)
51 return 1; 56 return 1;
52 /* Drop useless distance 0 events (on button clicks etc.) as well */ 57 /* Drop useless distance 0 events (on button clicks etc.) as well */
53 if (value == 0) 58 if (value == 0)
diff --git a/drivers/hid/hid-wiimote-core.c b/drivers/hid/hid-wiimote-core.c
index 0c06054cab8f..bd2bc4a1f378 100644
--- a/drivers/hid/hid-wiimote-core.c
+++ b/drivers/hid/hid-wiimote-core.c
@@ -212,10 +212,12 @@ static __u8 select_drm(struct wiimote_data *wdata)
212 212
213 if (ir == WIIPROTO_FLAG_IR_BASIC) { 213 if (ir == WIIPROTO_FLAG_IR_BASIC) {
214 if (wdata->state.flags & WIIPROTO_FLAG_ACCEL) { 214 if (wdata->state.flags & WIIPROTO_FLAG_ACCEL) {
215 if (ext) 215 /* GEN10 and ealier devices bind IR formats to DRMs.
216 return WIIPROTO_REQ_DRM_KAIE; 216 * Hence, we cannot use DRM_KAI here as it might be
217 else 217 * bound to IR_EXT. Use DRM_KAIE unconditionally so we
218 return WIIPROTO_REQ_DRM_KAI; 218 * work with all devices and our parsers can use the
219 * fixed formats, too. */
220 return WIIPROTO_REQ_DRM_KAIE;
219 } else { 221 } else {
220 return WIIPROTO_REQ_DRM_KIE; 222 return WIIPROTO_REQ_DRM_KIE;
221 } 223 }
@@ -439,8 +441,7 @@ static __u8 wiimote_cmd_read_ext(struct wiimote_data *wdata, __u8 *rmem)
439 if (ret != 6) 441 if (ret != 6)
440 return WIIMOTE_EXT_NONE; 442 return WIIMOTE_EXT_NONE;
441 443
442 hid_dbg(wdata->hdev, "extension ID: %02x:%02x %02x:%02x %02x:%02x\n", 444 hid_dbg(wdata->hdev, "extension ID: %6phC\n", rmem);
443 rmem[0], rmem[1], rmem[2], rmem[3], rmem[4], rmem[5]);
444 445
445 if (rmem[0] == 0xff && rmem[1] == 0xff && rmem[2] == 0xff && 446 if (rmem[0] == 0xff && rmem[1] == 0xff && rmem[2] == 0xff &&
446 rmem[3] == 0xff && rmem[4] == 0xff && rmem[5] == 0xff) 447 rmem[3] == 0xff && rmem[4] == 0xff && rmem[5] == 0xff)
@@ -454,6 +455,12 @@ static __u8 wiimote_cmd_read_ext(struct wiimote_data *wdata, __u8 *rmem)
454 return WIIMOTE_EXT_BALANCE_BOARD; 455 return WIIMOTE_EXT_BALANCE_BOARD;
455 if (rmem[4] == 0x01 && rmem[5] == 0x20) 456 if (rmem[4] == 0x01 && rmem[5] == 0x20)
456 return WIIMOTE_EXT_PRO_CONTROLLER; 457 return WIIMOTE_EXT_PRO_CONTROLLER;
458 if (rmem[0] == 0x01 && rmem[1] == 0x00 &&
459 rmem[4] == 0x01 && rmem[5] == 0x03)
460 return WIIMOTE_EXT_GUITAR_HERO_DRUMS;
461 if (rmem[0] == 0x00 && rmem[1] == 0x00 &&
462 rmem[4] == 0x01 && rmem[5] == 0x03)
463 return WIIMOTE_EXT_GUITAR_HERO_GUITAR;
457 464
458 return WIIMOTE_EXT_UNKNOWN; 465 return WIIMOTE_EXT_UNKNOWN;
459} 466}
@@ -487,6 +494,8 @@ static bool wiimote_cmd_map_mp(struct wiimote_data *wdata, __u8 exttype)
487 /* map MP with correct pass-through mode */ 494 /* map MP with correct pass-through mode */
488 switch (exttype) { 495 switch (exttype) {
489 case WIIMOTE_EXT_CLASSIC_CONTROLLER: 496 case WIIMOTE_EXT_CLASSIC_CONTROLLER:
497 case WIIMOTE_EXT_GUITAR_HERO_DRUMS:
498 case WIIMOTE_EXT_GUITAR_HERO_GUITAR:
490 wmem = 0x07; 499 wmem = 0x07;
491 break; 500 break;
492 case WIIMOTE_EXT_NUNCHUK: 501 case WIIMOTE_EXT_NUNCHUK:
@@ -510,14 +519,12 @@ static bool wiimote_cmd_read_mp(struct wiimote_data *wdata, __u8 *rmem)
510 if (ret != 6) 519 if (ret != 6)
511 return false; 520 return false;
512 521
513 hid_dbg(wdata->hdev, "motion plus ID: %02x:%02x %02x:%02x %02x:%02x\n", 522 hid_dbg(wdata->hdev, "motion plus ID: %6phC\n", rmem);
514 rmem[0], rmem[1], rmem[2], rmem[3], rmem[4], rmem[5]);
515 523
516 if (rmem[5] == 0x05) 524 if (rmem[5] == 0x05)
517 return true; 525 return true;
518 526
519 hid_info(wdata->hdev, "unknown motion plus ID: %02x:%02x %02x:%02x %02x:%02x\n", 527 hid_info(wdata->hdev, "unknown motion plus ID: %6phC\n", rmem);
520 rmem[0], rmem[1], rmem[2], rmem[3], rmem[4], rmem[5]);
521 528
522 return false; 529 return false;
523} 530}
@@ -533,8 +540,7 @@ static __u8 wiimote_cmd_read_mp_mapped(struct wiimote_data *wdata)
533 if (ret != 6) 540 if (ret != 6)
534 return WIIMOTE_MP_NONE; 541 return WIIMOTE_MP_NONE;
535 542
536 hid_dbg(wdata->hdev, "mapped motion plus ID: %02x:%02x %02x:%02x %02x:%02x\n", 543 hid_dbg(wdata->hdev, "mapped motion plus ID: %6phC\n", rmem);
537 rmem[0], rmem[1], rmem[2], rmem[3], rmem[4], rmem[5]);
538 544
539 if (rmem[0] == 0xff && rmem[1] == 0xff && rmem[2] == 0xff && 545 if (rmem[0] == 0xff && rmem[1] == 0xff && rmem[2] == 0xff &&
540 rmem[3] == 0xff && rmem[4] == 0xff && rmem[5] == 0xff) 546 rmem[3] == 0xff && rmem[4] == 0xff && rmem[5] == 0xff)
@@ -1077,6 +1083,8 @@ static const char *wiimote_exttype_names[WIIMOTE_EXT_NUM] = {
1077 [WIIMOTE_EXT_CLASSIC_CONTROLLER] = "Nintendo Wii Classic Controller", 1083 [WIIMOTE_EXT_CLASSIC_CONTROLLER] = "Nintendo Wii Classic Controller",
1078 [WIIMOTE_EXT_BALANCE_BOARD] = "Nintendo Wii Balance Board", 1084 [WIIMOTE_EXT_BALANCE_BOARD] = "Nintendo Wii Balance Board",
1079 [WIIMOTE_EXT_PRO_CONTROLLER] = "Nintendo Wii U Pro Controller", 1085 [WIIMOTE_EXT_PRO_CONTROLLER] = "Nintendo Wii U Pro Controller",
1086 [WIIMOTE_EXT_GUITAR_HERO_DRUMS] = "Nintendo Wii Guitar Hero Drums",
1087 [WIIMOTE_EXT_GUITAR_HERO_GUITAR] = "Nintendo Wii Guitar Hero Guitar",
1080}; 1088};
1081 1089
1082/* 1090/*
@@ -1126,9 +1134,8 @@ static void wiimote_init_hotplug(struct wiimote_data *wdata)
1126 wiimote_ext_unload(wdata); 1134 wiimote_ext_unload(wdata);
1127 1135
1128 if (exttype == WIIMOTE_EXT_UNKNOWN) { 1136 if (exttype == WIIMOTE_EXT_UNKNOWN) {
1129 hid_info(wdata->hdev, "cannot detect extension; %02x:%02x %02x:%02x %02x:%02x\n", 1137 hid_info(wdata->hdev, "cannot detect extension; %6phC\n",
1130 extdata[0], extdata[1], extdata[2], 1138 extdata);
1131 extdata[3], extdata[4], extdata[5]);
1132 } else if (exttype == WIIMOTE_EXT_NONE) { 1139 } else if (exttype == WIIMOTE_EXT_NONE) {
1133 spin_lock_irq(&wdata->state.lock); 1140 spin_lock_irq(&wdata->state.lock);
1134 wdata->state.exttype = WIIMOTE_EXT_NONE; 1141 wdata->state.exttype = WIIMOTE_EXT_NONE;
@@ -1663,6 +1670,10 @@ static ssize_t wiimote_ext_show(struct device *dev,
1663 return sprintf(buf, "balanceboard\n"); 1670 return sprintf(buf, "balanceboard\n");
1664 case WIIMOTE_EXT_PRO_CONTROLLER: 1671 case WIIMOTE_EXT_PRO_CONTROLLER:
1665 return sprintf(buf, "procontroller\n"); 1672 return sprintf(buf, "procontroller\n");
1673 case WIIMOTE_EXT_GUITAR_HERO_DRUMS:
1674 return sprintf(buf, "drums\n");
1675 case WIIMOTE_EXT_GUITAR_HERO_GUITAR:
1676 return sprintf(buf, "guitar\n");
1666 case WIIMOTE_EXT_UNKNOWN: 1677 case WIIMOTE_EXT_UNKNOWN:
1667 /* fallthrough */ 1678 /* fallthrough */
1668 default: 1679 default:
diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c
index 2e7d644dba18..7e124c351e67 100644
--- a/drivers/hid/hid-wiimote-modules.c
+++ b/drivers/hid/hid-wiimote-modules.c
@@ -1834,6 +1834,396 @@ static const struct wiimod_ops wiimod_pro = {
1834}; 1834};
1835 1835
1836/* 1836/*
1837 * Drums
1838 * Guitar-Hero, Rock-Band and other games came bundled with drums which can
1839 * be plugged as extension to a Wiimote. Drum-reports are still not entirely
1840 * figured out, but the most important information is known.
1841 * We create a separate device for drums and report all information via this
1842 * input device.
1843 */
1844
1845static inline void wiimod_drums_report_pressure(struct wiimote_data *wdata,
1846 __u8 none, __u8 which,
1847 __u8 pressure, __u8 onoff,
1848 __u8 *store, __u16 code,
1849 __u8 which_code)
1850{
1851 static const __u8 default_pressure = 3;
1852
1853 if (!none && which == which_code) {
1854 *store = pressure;
1855 input_report_abs(wdata->extension.input, code, *store);
1856 } else if (onoff != !!*store) {
1857 *store = onoff ? default_pressure : 0;
1858 input_report_abs(wdata->extension.input, code, *store);
1859 }
1860}
1861
1862static void wiimod_drums_in_ext(struct wiimote_data *wdata, const __u8 *ext)
1863{
1864 __u8 pressure, which, none, hhp, sx, sy;
1865 __u8 o, r, y, g, b, bass, bm, bp;
1866
1867 /* Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
1868 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1869 * 1 | 0 | 0 | SX <5:0> |
1870 * 2 | 0 | 0 | SY <5:0> |
1871 * -----+-----+-----+-----------------------------+-----+
1872 * 3 | HPP | NON | WHICH <5:1> | ? |
1873 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1874 * 4 | SOFT <7:5> | 0 | 1 | 1 | 0 | ? |
1875 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1876 * 5 | ? | 1 | 1 | B- | 1 | B+ | 1 | ? |
1877 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1878 * 6 | O | R | Y | G | B | BSS | 1 | 1 |
1879 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1880 * All buttons are 0 if pressed
1881 *
1882 * With Motion+ enabled, the following bits will get invalid:
1883 * Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
1884 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1885 * 1 | 0 | 0 | SX <5:1> |XXXXX|
1886 * 2 | 0 | 0 | SY <5:1> |XXXXX|
1887 * -----+-----+-----+-----------------------------+-----+
1888 * 3 | HPP | NON | WHICH <5:1> | ? |
1889 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1890 * 4 | SOFT <7:5> | 0 | 1 | 1 | 0 | ? |
1891 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1892 * 5 | ? | 1 | 1 | B- | 1 | B+ | 1 |XXXXX|
1893 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1894 * 6 | O | R | Y | G | B | BSS |XXXXX|XXXXX|
1895 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1896 */
1897
1898 pressure = 7 - (ext[3] >> 5);
1899 which = (ext[2] >> 1) & 0x1f;
1900 none = !!(ext[2] & 0x40);
1901 hhp = !(ext[2] & 0x80);
1902 sx = ext[0] & 0x3f;
1903 sy = ext[1] & 0x3f;
1904 o = !(ext[5] & 0x80);
1905 r = !(ext[5] & 0x40);
1906 y = !(ext[5] & 0x20);
1907 g = !(ext[5] & 0x10);
1908 b = !(ext[5] & 0x08);
1909 bass = !(ext[5] & 0x04);
1910 bm = !(ext[4] & 0x10);
1911 bp = !(ext[4] & 0x04);
1912
1913 wiimod_drums_report_pressure(wdata, none, which, pressure,
1914 o, &wdata->state.pressure_drums[0],
1915 ABS_CYMBAL_RIGHT, 0x0e);
1916 wiimod_drums_report_pressure(wdata, none, which, pressure,
1917 r, &wdata->state.pressure_drums[1],
1918 ABS_TOM_LEFT, 0x19);
1919 wiimod_drums_report_pressure(wdata, none, which, pressure,
1920 y, &wdata->state.pressure_drums[2],
1921 ABS_CYMBAL_LEFT, 0x11);
1922 wiimod_drums_report_pressure(wdata, none, which, pressure,
1923 g, &wdata->state.pressure_drums[3],
1924 ABS_TOM_FAR_RIGHT, 0x12);
1925 wiimod_drums_report_pressure(wdata, none, which, pressure,
1926 b, &wdata->state.pressure_drums[4],
1927 ABS_TOM_RIGHT, 0x0f);
1928
1929 /* Bass shares pressure with hi-hat (set via hhp) */
1930 wiimod_drums_report_pressure(wdata, none, hhp ? 0xff : which, pressure,
1931 bass, &wdata->state.pressure_drums[5],
1932 ABS_BASS, 0x1b);
1933 /* Hi-hat has no on/off values, just pressure. Force to off/0. */
1934 wiimod_drums_report_pressure(wdata, none, hhp ? which : 0xff, pressure,
1935 0, &wdata->state.pressure_drums[6],
1936 ABS_HI_HAT, 0x0e);
1937
1938 input_report_abs(wdata->extension.input, ABS_X, sx - 0x20);
1939 input_report_abs(wdata->extension.input, ABS_Y, sy - 0x20);
1940
1941 input_report_key(wdata->extension.input, BTN_START, bp);
1942 input_report_key(wdata->extension.input, BTN_SELECT, bm);
1943
1944 input_sync(wdata->extension.input);
1945}
1946
1947static int wiimod_drums_open(struct input_dev *dev)
1948{
1949 struct wiimote_data *wdata = input_get_drvdata(dev);
1950 unsigned long flags;
1951
1952 spin_lock_irqsave(&wdata->state.lock, flags);
1953 wdata->state.flags |= WIIPROTO_FLAG_EXT_USED;
1954 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
1955 spin_unlock_irqrestore(&wdata->state.lock, flags);
1956
1957 return 0;
1958}
1959
1960static void wiimod_drums_close(struct input_dev *dev)
1961{
1962 struct wiimote_data *wdata = input_get_drvdata(dev);
1963 unsigned long flags;
1964
1965 spin_lock_irqsave(&wdata->state.lock, flags);
1966 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_USED;
1967 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
1968 spin_unlock_irqrestore(&wdata->state.lock, flags);
1969}
1970
1971static int wiimod_drums_probe(const struct wiimod_ops *ops,
1972 struct wiimote_data *wdata)
1973{
1974 int ret;
1975
1976 wdata->extension.input = input_allocate_device();
1977 if (!wdata->extension.input)
1978 return -ENOMEM;
1979
1980 input_set_drvdata(wdata->extension.input, wdata);
1981 wdata->extension.input->open = wiimod_drums_open;
1982 wdata->extension.input->close = wiimod_drums_close;
1983 wdata->extension.input->dev.parent = &wdata->hdev->dev;
1984 wdata->extension.input->id.bustype = wdata->hdev->bus;
1985 wdata->extension.input->id.vendor = wdata->hdev->vendor;
1986 wdata->extension.input->id.product = wdata->hdev->product;
1987 wdata->extension.input->id.version = wdata->hdev->version;
1988 wdata->extension.input->name = WIIMOTE_NAME " Drums";
1989
1990 set_bit(EV_KEY, wdata->extension.input->evbit);
1991 set_bit(BTN_START, wdata->extension.input->keybit);
1992 set_bit(BTN_SELECT, wdata->extension.input->keybit);
1993
1994 set_bit(EV_ABS, wdata->extension.input->evbit);
1995 set_bit(ABS_X, wdata->extension.input->absbit);
1996 set_bit(ABS_Y, wdata->extension.input->absbit);
1997 set_bit(ABS_TOM_LEFT, wdata->extension.input->absbit);
1998 set_bit(ABS_TOM_RIGHT, wdata->extension.input->absbit);
1999 set_bit(ABS_TOM_FAR_RIGHT, wdata->extension.input->absbit);
2000 set_bit(ABS_CYMBAL_LEFT, wdata->extension.input->absbit);
2001 set_bit(ABS_CYMBAL_RIGHT, wdata->extension.input->absbit);
2002 set_bit(ABS_BASS, wdata->extension.input->absbit);
2003 set_bit(ABS_HI_HAT, wdata->extension.input->absbit);
2004 input_set_abs_params(wdata->extension.input,
2005 ABS_X, -32, 31, 1, 1);
2006 input_set_abs_params(wdata->extension.input,
2007 ABS_Y, -32, 31, 1, 1);
2008 input_set_abs_params(wdata->extension.input,
2009 ABS_TOM_LEFT, 0, 7, 0, 0);
2010 input_set_abs_params(wdata->extension.input,
2011 ABS_TOM_RIGHT, 0, 7, 0, 0);
2012 input_set_abs_params(wdata->extension.input,
2013 ABS_TOM_FAR_RIGHT, 0, 7, 0, 0);
2014 input_set_abs_params(wdata->extension.input,
2015 ABS_CYMBAL_LEFT, 0, 7, 0, 0);
2016 input_set_abs_params(wdata->extension.input,
2017 ABS_CYMBAL_RIGHT, 0, 7, 0, 0);
2018 input_set_abs_params(wdata->extension.input,
2019 ABS_BASS, 0, 7, 0, 0);
2020 input_set_abs_params(wdata->extension.input,
2021 ABS_HI_HAT, 0, 7, 0, 0);
2022
2023 ret = input_register_device(wdata->extension.input);
2024 if (ret)
2025 goto err_free;
2026
2027 return 0;
2028
2029err_free:
2030 input_free_device(wdata->extension.input);
2031 wdata->extension.input = NULL;
2032 return ret;
2033}
2034
2035static void wiimod_drums_remove(const struct wiimod_ops *ops,
2036 struct wiimote_data *wdata)
2037{
2038 if (!wdata->extension.input)
2039 return;
2040
2041 input_unregister_device(wdata->extension.input);
2042 wdata->extension.input = NULL;
2043}
2044
2045static const struct wiimod_ops wiimod_drums = {
2046 .flags = 0,
2047 .arg = 0,
2048 .probe = wiimod_drums_probe,
2049 .remove = wiimod_drums_remove,
2050 .in_ext = wiimod_drums_in_ext,
2051};
2052
2053/*
2054 * Guitar
2055 * Guitar-Hero, Rock-Band and other games came bundled with guitars which can
2056 * be plugged as extension to a Wiimote.
2057 * We create a separate device for guitars and report all information via this
2058 * input device.
2059 */
2060
2061static void wiimod_guitar_in_ext(struct wiimote_data *wdata, const __u8 *ext)
2062{
2063 __u8 sx, sy, tb, wb, bd, bm, bp, bo, br, bb, bg, by, bu;
2064
2065 /* Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
2066 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
2067 * 1 | 0 | 0 | SX <5:0> |
2068 * 2 | 0 | 0 | SY <5:0> |
2069 * -----+-----+-----+-----+-----------------------------+
2070 * 3 | 0 | 0 | 0 | TB <4:0> |
2071 * -----+-----+-----+-----+-----------------------------+
2072 * 4 | 0 | 0 | 0 | WB <4:0> |
2073 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
2074 * 5 | 1 | BD | 1 | B- | 1 | B+ | 1 | 1 |
2075 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
2076 * 6 | BO | BR | BB | BG | BY | 1 | 1 | BU |
2077 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
2078 * All buttons are 0 if pressed
2079 *
2080 * With Motion+ enabled, the following bits will get invalid:
2081 * Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
2082 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
2083 * 1 | 0 | 0 | SX <5:1> |XXXXX|
2084 * 2 | 0 | 0 | SY <5:1> |XXXXX|
2085 * -----+-----+-----+-----+-----------------------+-----+
2086 * 3 | 0 | 0 | 0 | TB <4:0> |
2087 * -----+-----+-----+-----+-----------------------------+
2088 * 4 | 0 | 0 | 0 | WB <4:0> |
2089 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
2090 * 5 | 1 | BD | 1 | B- | 1 | B+ | 1 |XXXXX|
2091 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
2092 * 6 | BO | BR | BB | BG | BY | 1 |XXXXX|XXXXX|
2093 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
2094 */
2095
2096 sx = ext[0] & 0x3f;
2097 sy = ext[1] & 0x3f;
2098 tb = ext[2] & 0x1f;
2099 wb = ext[3] & 0x1f;
2100 bd = !(ext[4] & 0x40);
2101 bm = !(ext[4] & 0x10);
2102 bp = !(ext[4] & 0x04);
2103 bo = !(ext[5] & 0x80);
2104 br = !(ext[5] & 0x40);
2105 bb = !(ext[5] & 0x20);
2106 bg = !(ext[5] & 0x10);
2107 by = !(ext[5] & 0x08);
2108 bu = !(ext[5] & 0x01);
2109
2110 input_report_abs(wdata->extension.input, ABS_X, sx - 0x20);
2111 input_report_abs(wdata->extension.input, ABS_Y, sy - 0x20);
2112 input_report_abs(wdata->extension.input, ABS_FRET_BOARD, tb);
2113 input_report_abs(wdata->extension.input, ABS_WHAMMY_BAR, wb - 0x10);
2114
2115 input_report_key(wdata->extension.input, BTN_MODE, bm);
2116 input_report_key(wdata->extension.input, BTN_START, bp);
2117 input_report_key(wdata->extension.input, BTN_STRUM_BAR_UP, bu);
2118 input_report_key(wdata->extension.input, BTN_STRUM_BAR_DOWN, bd);
2119 input_report_key(wdata->extension.input, BTN_FRET_FAR_UP, bg);
2120 input_report_key(wdata->extension.input, BTN_FRET_UP, br);
2121 input_report_key(wdata->extension.input, BTN_FRET_MID, by);
2122 input_report_key(wdata->extension.input, BTN_FRET_LOW, bb);
2123 input_report_key(wdata->extension.input, BTN_FRET_FAR_LOW, bo);
2124
2125 input_sync(wdata->extension.input);
2126}
2127
2128static int wiimod_guitar_open(struct input_dev *dev)
2129{
2130 struct wiimote_data *wdata = input_get_drvdata(dev);
2131 unsigned long flags;
2132
2133 spin_lock_irqsave(&wdata->state.lock, flags);
2134 wdata->state.flags |= WIIPROTO_FLAG_EXT_USED;
2135 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
2136 spin_unlock_irqrestore(&wdata->state.lock, flags);
2137
2138 return 0;
2139}
2140
2141static void wiimod_guitar_close(struct input_dev *dev)
2142{
2143 struct wiimote_data *wdata = input_get_drvdata(dev);
2144 unsigned long flags;
2145
2146 spin_lock_irqsave(&wdata->state.lock, flags);
2147 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_USED;
2148 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
2149 spin_unlock_irqrestore(&wdata->state.lock, flags);
2150}
2151
2152static int wiimod_guitar_probe(const struct wiimod_ops *ops,
2153 struct wiimote_data *wdata)
2154{
2155 int ret;
2156
2157 wdata->extension.input = input_allocate_device();
2158 if (!wdata->extension.input)
2159 return -ENOMEM;
2160
2161 input_set_drvdata(wdata->extension.input, wdata);
2162 wdata->extension.input->open = wiimod_guitar_open;
2163 wdata->extension.input->close = wiimod_guitar_close;
2164 wdata->extension.input->dev.parent = &wdata->hdev->dev;
2165 wdata->extension.input->id.bustype = wdata->hdev->bus;
2166 wdata->extension.input->id.vendor = wdata->hdev->vendor;
2167 wdata->extension.input->id.product = wdata->hdev->product;
2168 wdata->extension.input->id.version = wdata->hdev->version;
2169 wdata->extension.input->name = WIIMOTE_NAME " Guitar";
2170
2171 set_bit(EV_KEY, wdata->extension.input->evbit);
2172 set_bit(BTN_MODE, wdata->extension.input->keybit);
2173 set_bit(BTN_START, wdata->extension.input->keybit);
2174 set_bit(BTN_FRET_FAR_UP, wdata->extension.input->keybit);
2175 set_bit(BTN_FRET_UP, wdata->extension.input->keybit);
2176 set_bit(BTN_FRET_MID, wdata->extension.input->keybit);
2177 set_bit(BTN_FRET_LOW, wdata->extension.input->keybit);
2178 set_bit(BTN_FRET_FAR_LOW, wdata->extension.input->keybit);
2179 set_bit(BTN_STRUM_BAR_UP, wdata->extension.input->keybit);
2180 set_bit(BTN_STRUM_BAR_DOWN, wdata->extension.input->keybit);
2181
2182 set_bit(EV_ABS, wdata->extension.input->evbit);
2183 set_bit(ABS_X, wdata->extension.input->absbit);
2184 set_bit(ABS_Y, wdata->extension.input->absbit);
2185 set_bit(ABS_FRET_BOARD, wdata->extension.input->absbit);
2186 set_bit(ABS_WHAMMY_BAR, wdata->extension.input->absbit);
2187 input_set_abs_params(wdata->extension.input,
2188 ABS_X, -32, 31, 1, 1);
2189 input_set_abs_params(wdata->extension.input,
2190 ABS_Y, -32, 31, 1, 1);
2191 input_set_abs_params(wdata->extension.input,
2192 ABS_FRET_BOARD, 0, 0x1f, 1, 1);
2193 input_set_abs_params(wdata->extension.input,
2194 ABS_WHAMMY_BAR, 0, 0x0f, 1, 1);
2195
2196 ret = input_register_device(wdata->extension.input);
2197 if (ret)
2198 goto err_free;
2199
2200 return 0;
2201
2202err_free:
2203 input_free_device(wdata->extension.input);
2204 wdata->extension.input = NULL;
2205 return ret;
2206}
2207
2208static void wiimod_guitar_remove(const struct wiimod_ops *ops,
2209 struct wiimote_data *wdata)
2210{
2211 if (!wdata->extension.input)
2212 return;
2213
2214 input_unregister_device(wdata->extension.input);
2215 wdata->extension.input = NULL;
2216}
2217
2218static const struct wiimod_ops wiimod_guitar = {
2219 .flags = 0,
2220 .arg = 0,
2221 .probe = wiimod_guitar_probe,
2222 .remove = wiimod_guitar_remove,
2223 .in_ext = wiimod_guitar_in_ext,
2224};
2225
2226/*
1837 * Builtin Motion Plus 2227 * Builtin Motion Plus
1838 * This module simply sets the WIIPROTO_FLAG_BUILTIN_MP protocol flag which 2228 * This module simply sets the WIIPROTO_FLAG_BUILTIN_MP protocol flag which
1839 * disables polling for Motion-Plus. This should be set only for devices which 2229 * disables polling for Motion-Plus. This should be set only for devices which
@@ -2083,4 +2473,6 @@ const struct wiimod_ops *wiimod_ext_table[WIIMOTE_EXT_NUM] = {
2083 [WIIMOTE_EXT_CLASSIC_CONTROLLER] = &wiimod_classic, 2473 [WIIMOTE_EXT_CLASSIC_CONTROLLER] = &wiimod_classic,
2084 [WIIMOTE_EXT_BALANCE_BOARD] = &wiimod_bboard, 2474 [WIIMOTE_EXT_BALANCE_BOARD] = &wiimod_bboard,
2085 [WIIMOTE_EXT_PRO_CONTROLLER] = &wiimod_pro, 2475 [WIIMOTE_EXT_PRO_CONTROLLER] = &wiimod_pro,
2476 [WIIMOTE_EXT_GUITAR_HERO_DRUMS] = &wiimod_drums,
2477 [WIIMOTE_EXT_GUITAR_HERO_GUITAR] = &wiimod_guitar,
2086}; 2478};
diff --git a/drivers/hid/hid-wiimote.h b/drivers/hid/hid-wiimote.h
index f1474f372c0b..379cdfb6bd25 100644
--- a/drivers/hid/hid-wiimote.h
+++ b/drivers/hid/hid-wiimote.h
@@ -88,6 +88,8 @@ enum wiimote_exttype {
88 WIIMOTE_EXT_CLASSIC_CONTROLLER, 88 WIIMOTE_EXT_CLASSIC_CONTROLLER,
89 WIIMOTE_EXT_BALANCE_BOARD, 89 WIIMOTE_EXT_BALANCE_BOARD,
90 WIIMOTE_EXT_PRO_CONTROLLER, 90 WIIMOTE_EXT_PRO_CONTROLLER,
91 WIIMOTE_EXT_GUITAR_HERO_DRUMS,
92 WIIMOTE_EXT_GUITAR_HERO_GUITAR,
91 WIIMOTE_EXT_NUM, 93 WIIMOTE_EXT_NUM,
92}; 94};
93 95
@@ -135,6 +137,7 @@ struct wiimote_state {
135 137
136 /* calibration data */ 138 /* calibration data */
137 __u16 calib_bboard[4][3]; 139 __u16 calib_bboard[4][3];
140 __u8 pressure_drums[7];
138}; 141};
139 142
140struct wiimote_data { 143struct wiimote_data {
diff --git a/drivers/hid/hid-xinmo.c b/drivers/hid/hid-xinmo.c
new file mode 100644
index 000000000000..7df5227a7e61
--- /dev/null
+++ b/drivers/hid/hid-xinmo.c
@@ -0,0 +1,61 @@
1/*
2 * HID driver for Xin-Mo devices, currently only the Dual Arcade controller.
3 * Fixes the negative axis event values (the devices sends -2) to match the
4 * logical axis minimum of the HID report descriptor (the report announces
5 * -1). It is needed because hid-input discards out of bounds values.
6 * (This module is based on "hid-saitek" and "hid-lg".)
7 *
8 * Copyright (c) 2013 Olivier Scherler
9 */
10
11/*
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 */
17
18#include <linux/device.h>
19#include <linux/hid.h>
20#include <linux/module.h>
21#include <linux/kernel.h>
22
23#include "hid-ids.h"
24
25/*
26 * Fix negative events that are out of bounds.
27 */
28static int xinmo_event(struct hid_device *hdev, struct hid_field *field,
29 struct hid_usage *usage, __s32 value)
30{
31 switch (usage->code) {
32 case ABS_X:
33 case ABS_Y:
34 case ABS_Z:
35 case ABS_RX:
36 if (value < -1) {
37 input_event(field->hidinput->input, usage->type,
38 usage->code, -1);
39 return 1;
40 }
41 break;
42 }
43
44 return 0;
45}
46
47static const struct hid_device_id xinmo_devices[] = {
48 { HID_USB_DEVICE(USB_VENDOR_ID_XIN_MO, USB_DEVICE_ID_XIN_MO_DUAL_ARCADE) },
49 { }
50};
51
52MODULE_DEVICE_TABLE(hid, xinmo_devices);
53
54static struct hid_driver xinmo_driver = {
55 .name = "xinmo",
56 .id_table = xinmo_devices,
57 .event = xinmo_event
58};
59
60module_hid_driver(xinmo_driver);
61MODULE_LICENSE("GPL");
diff --git a/drivers/hid/hid-zydacron.c b/drivers/hid/hid-zydacron.c
index e4cddeccd6b5..1a660bd97ab2 100644
--- a/drivers/hid/hid-zydacron.c
+++ b/drivers/hid/hid-zydacron.c
@@ -169,7 +169,7 @@ static int zc_probe(struct hid_device *hdev, const struct hid_device_id *id)
169 int ret; 169 int ret;
170 struct zc_device *zc; 170 struct zc_device *zc;
171 171
172 zc = kzalloc(sizeof(*zc), GFP_KERNEL); 172 zc = devm_kzalloc(&hdev->dev, sizeof(*zc), GFP_KERNEL);
173 if (zc == NULL) { 173 if (zc == NULL) {
174 hid_err(hdev, "can't alloc descriptor\n"); 174 hid_err(hdev, "can't alloc descriptor\n");
175 return -ENOMEM; 175 return -ENOMEM;
@@ -180,28 +180,16 @@ static int zc_probe(struct hid_device *hdev, const struct hid_device_id *id)
180 ret = hid_parse(hdev); 180 ret = hid_parse(hdev);
181 if (ret) { 181 if (ret) {
182 hid_err(hdev, "parse failed\n"); 182 hid_err(hdev, "parse failed\n");
183 goto err_free; 183 return ret;
184 } 184 }
185 185
186 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 186 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
187 if (ret) { 187 if (ret) {
188 hid_err(hdev, "hw start failed\n"); 188 hid_err(hdev, "hw start failed\n");
189 goto err_free; 189 return ret;
190 } 190 }
191 191
192 return 0; 192 return 0;
193err_free:
194 kfree(zc);
195
196 return ret;
197}
198
199static void zc_remove(struct hid_device *hdev)
200{
201 struct zc_device *zc = hid_get_drvdata(hdev);
202
203 hid_hw_stop(hdev);
204 kfree(zc);
205} 193}
206 194
207static const struct hid_device_id zc_devices[] = { 195static const struct hid_device_id zc_devices[] = {
@@ -217,7 +205,6 @@ static struct hid_driver zc_driver = {
217 .input_mapping = zc_input_mapping, 205 .input_mapping = zc_input_mapping,
218 .raw_event = zc_raw_event, 206 .raw_event = zc_raw_event,
219 .probe = zc_probe, 207 .probe = zc_probe,
220 .remove = zc_remove,
221}; 208};
222module_hid_driver(zc_driver); 209module_hid_driver(zc_driver);
223 210
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index 6f1feb2c2e97..8918dd12bb69 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -113,7 +113,7 @@ static ssize_t hidraw_send_report(struct file *file, const char __user *buffer,
113 __u8 *buf; 113 __u8 *buf;
114 int ret = 0; 114 int ret = 0;
115 115
116 if (!hidraw_table[minor]) { 116 if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
117 ret = -ENODEV; 117 ret = -ENODEV;
118 goto out; 118 goto out;
119 } 119 }
@@ -253,6 +253,7 @@ static int hidraw_open(struct inode *inode, struct file *file)
253 unsigned int minor = iminor(inode); 253 unsigned int minor = iminor(inode);
254 struct hidraw *dev; 254 struct hidraw *dev;
255 struct hidraw_list *list; 255 struct hidraw_list *list;
256 unsigned long flags;
256 int err = 0; 257 int err = 0;
257 258
258 if (!(list = kzalloc(sizeof(struct hidraw_list), GFP_KERNEL))) { 259 if (!(list = kzalloc(sizeof(struct hidraw_list), GFP_KERNEL))) {
@@ -261,16 +262,11 @@ static int hidraw_open(struct inode *inode, struct file *file)
261 } 262 }
262 263
263 mutex_lock(&minors_lock); 264 mutex_lock(&minors_lock);
264 if (!hidraw_table[minor]) { 265 if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
265 err = -ENODEV; 266 err = -ENODEV;
266 goto out_unlock; 267 goto out_unlock;
267 } 268 }
268 269
269 list->hidraw = hidraw_table[minor];
270 mutex_init(&list->read_mutex);
271 list_add_tail(&list->node, &hidraw_table[minor]->list);
272 file->private_data = list;
273
274 dev = hidraw_table[minor]; 270 dev = hidraw_table[minor];
275 if (!dev->open++) { 271 if (!dev->open++) {
276 err = hid_hw_power(dev->hid, PM_HINT_FULLON); 272 err = hid_hw_power(dev->hid, PM_HINT_FULLON);
@@ -283,9 +279,16 @@ static int hidraw_open(struct inode *inode, struct file *file)
283 if (err < 0) { 279 if (err < 0) {
284 hid_hw_power(dev->hid, PM_HINT_NORMAL); 280 hid_hw_power(dev->hid, PM_HINT_NORMAL);
285 dev->open--; 281 dev->open--;
282 goto out_unlock;
286 } 283 }
287 } 284 }
288 285
286 list->hidraw = hidraw_table[minor];
287 mutex_init(&list->read_mutex);
288 spin_lock_irqsave(&hidraw_table[minor]->list_lock, flags);
289 list_add_tail(&list->node, &hidraw_table[minor]->list);
290 spin_unlock_irqrestore(&hidraw_table[minor]->list_lock, flags);
291 file->private_data = list;
289out_unlock: 292out_unlock:
290 mutex_unlock(&minors_lock); 293 mutex_unlock(&minors_lock);
291out: 294out:
@@ -302,39 +305,41 @@ static int hidraw_fasync(int fd, struct file *file, int on)
302 return fasync_helper(fd, file, on, &list->fasync); 305 return fasync_helper(fd, file, on, &list->fasync);
303} 306}
304 307
308static void drop_ref(struct hidraw *hidraw, int exists_bit)
309{
310 if (exists_bit) {
311 hid_hw_close(hidraw->hid);
312 hidraw->exist = 0;
313 if (hidraw->open)
314 wake_up_interruptible(&hidraw->wait);
315 } else {
316 --hidraw->open;
317 }
318
319 if (!hidraw->open && !hidraw->exist) {
320 device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor));
321 hidraw_table[hidraw->minor] = NULL;
322 kfree(hidraw);
323 }
324}
325
305static int hidraw_release(struct inode * inode, struct file * file) 326static int hidraw_release(struct inode * inode, struct file * file)
306{ 327{
307 unsigned int minor = iminor(inode); 328 unsigned int minor = iminor(inode);
308 struct hidraw *dev;
309 struct hidraw_list *list = file->private_data; 329 struct hidraw_list *list = file->private_data;
310 int ret; 330 unsigned long flags;
311 int i;
312 331
313 mutex_lock(&minors_lock); 332 mutex_lock(&minors_lock);
314 if (!hidraw_table[minor]) {
315 ret = -ENODEV;
316 goto unlock;
317 }
318 333
334 spin_lock_irqsave(&hidraw_table[minor]->list_lock, flags);
319 list_del(&list->node); 335 list_del(&list->node);
320 dev = hidraw_table[minor]; 336 spin_unlock_irqrestore(&hidraw_table[minor]->list_lock, flags);
321 if (!--dev->open) {
322 if (list->hidraw->exist) {
323 hid_hw_power(dev->hid, PM_HINT_NORMAL);
324 hid_hw_close(dev->hid);
325 } else {
326 kfree(list->hidraw);
327 }
328 }
329
330 for (i = 0; i < HIDRAW_BUFFER_SIZE; ++i)
331 kfree(list->buffer[i].value);
332 kfree(list); 337 kfree(list);
333 ret = 0;
334unlock:
335 mutex_unlock(&minors_lock);
336 338
337 return ret; 339 drop_ref(hidraw_table[minor], 0);
340
341 mutex_unlock(&minors_lock);
342 return 0;
338} 343}
339 344
340static long hidraw_ioctl(struct file *file, unsigned int cmd, 345static long hidraw_ioctl(struct file *file, unsigned int cmd,
@@ -457,7 +462,9 @@ int hidraw_report_event(struct hid_device *hid, u8 *data, int len)
457 struct hidraw *dev = hid->hidraw; 462 struct hidraw *dev = hid->hidraw;
458 struct hidraw_list *list; 463 struct hidraw_list *list;
459 int ret = 0; 464 int ret = 0;
465 unsigned long flags;
460 466
467 spin_lock_irqsave(&dev->list_lock, flags);
461 list_for_each_entry(list, &dev->list, node) { 468 list_for_each_entry(list, &dev->list, node) {
462 int new_head = (list->head + 1) & (HIDRAW_BUFFER_SIZE - 1); 469 int new_head = (list->head + 1) & (HIDRAW_BUFFER_SIZE - 1);
463 470
@@ -472,6 +479,7 @@ int hidraw_report_event(struct hid_device *hid, u8 *data, int len)
472 list->head = new_head; 479 list->head = new_head;
473 kill_fasync(&list->fasync, SIGIO, POLL_IN); 480 kill_fasync(&list->fasync, SIGIO, POLL_IN);
474 } 481 }
482 spin_unlock_irqrestore(&dev->list_lock, flags);
475 483
476 wake_up_interruptible(&dev->wait); 484 wake_up_interruptible(&dev->wait);
477 return ret; 485 return ret;
@@ -519,6 +527,7 @@ int hidraw_connect(struct hid_device *hid)
519 } 527 }
520 528
521 init_waitqueue_head(&dev->wait); 529 init_waitqueue_head(&dev->wait);
530 spin_lock_init(&dev->list_lock);
522 INIT_LIST_HEAD(&dev->list); 531 INIT_LIST_HEAD(&dev->list);
523 532
524 dev->hid = hid; 533 dev->hid = hid;
@@ -539,18 +548,9 @@ void hidraw_disconnect(struct hid_device *hid)
539 struct hidraw *hidraw = hid->hidraw; 548 struct hidraw *hidraw = hid->hidraw;
540 549
541 mutex_lock(&minors_lock); 550 mutex_lock(&minors_lock);
542 hidraw->exist = 0;
543 551
544 device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor)); 552 drop_ref(hidraw, 1);
545 553
546 hidraw_table[hidraw->minor] = NULL;
547
548 if (hidraw->open) {
549 hid_hw_close(hid);
550 wake_up_interruptible(&hidraw->wait);
551 } else {
552 kfree(hidraw);
553 }
554 mutex_unlock(&minors_lock); 554 mutex_unlock(&minors_lock);
555} 555}
556EXPORT_SYMBOL_GPL(hidraw_disconnect); 556EXPORT_SYMBOL_GPL(hidraw_disconnect);
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index 879b0ed701a3..c1336193b04b 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -35,6 +35,7 @@
35#include <linux/hid.h> 35#include <linux/hid.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/acpi.h> 37#include <linux/acpi.h>
38#include <linux/of.h>
38 39
39#include <linux/i2c/i2c-hid.h> 40#include <linux/i2c/i2c-hid.h>
40 41
@@ -756,29 +757,6 @@ static int i2c_hid_power(struct hid_device *hid, int lvl)
756 return ret; 757 return ret;
757} 758}
758 759
759static int i2c_hid_hidinput_input_event(struct input_dev *dev,
760 unsigned int type, unsigned int code, int value)
761{
762 struct hid_device *hid = input_get_drvdata(dev);
763 struct hid_field *field;
764 int offset;
765
766 if (type == EV_FF)
767 return input_ff_event(dev, type, code, value);
768
769 if (type != EV_LED)
770 return -1;
771
772 offset = hidinput_find_field(hid, type, code, &field);
773
774 if (offset == -1) {
775 hid_warn(dev, "event field not found\n");
776 return -1;
777 }
778
779 return hid_set_field(field, offset, value);
780}
781
782static struct hid_ll_driver i2c_hid_ll_driver = { 760static struct hid_ll_driver i2c_hid_ll_driver = {
783 .parse = i2c_hid_parse, 761 .parse = i2c_hid_parse,
784 .start = i2c_hid_start, 762 .start = i2c_hid_start,
@@ -787,7 +765,6 @@ static struct hid_ll_driver i2c_hid_ll_driver = {
787 .close = i2c_hid_close, 765 .close = i2c_hid_close,
788 .power = i2c_hid_power, 766 .power = i2c_hid_power,
789 .request = i2c_hid_request, 767 .request = i2c_hid_request,
790 .hidinput_input_event = i2c_hid_hidinput_input_event,
791}; 768};
792 769
793static int i2c_hid_init_irq(struct i2c_client *client) 770static int i2c_hid_init_irq(struct i2c_client *client)
@@ -824,8 +801,8 @@ static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)
824 * bytes 2-3 -> bcdVersion (has to be 1.00) */ 801 * bytes 2-3 -> bcdVersion (has to be 1.00) */
825 ret = i2c_hid_command(client, &hid_descr_cmd, ihid->hdesc_buffer, 4); 802 ret = i2c_hid_command(client, &hid_descr_cmd, ihid->hdesc_buffer, 4);
826 803
827 i2c_hid_dbg(ihid, "%s, ihid->hdesc_buffer: %*ph\n", 804 i2c_hid_dbg(ihid, "%s, ihid->hdesc_buffer: %4ph\n", __func__,
828 __func__, 4, ihid->hdesc_buffer); 805 ihid->hdesc_buffer);
829 806
830 if (ret) { 807 if (ret) {
831 dev_err(&client->dev, 808 dev_err(&client->dev,
@@ -897,8 +874,9 @@ static int i2c_hid_acpi_pdata(struct i2c_client *client,
897 params[1].integer.value = 1; 874 params[1].integer.value = 1;
898 params[2].type = ACPI_TYPE_INTEGER; 875 params[2].type = ACPI_TYPE_INTEGER;
899 params[2].integer.value = 1; /* HID function */ 876 params[2].integer.value = 1; /* HID function */
900 params[3].type = ACPI_TYPE_INTEGER; 877 params[3].type = ACPI_TYPE_PACKAGE;
901 params[3].integer.value = 0; 878 params[3].package.count = 0;
879 params[3].package.elements = NULL;
902 880
903 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_DSM", &input, &buf))) { 881 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_DSM", &input, &buf))) {
904 dev_err(&client->dev, "device _DSM execution failed\n"); 882 dev_err(&client->dev, "device _DSM execution failed\n");
@@ -933,6 +911,42 @@ static inline int i2c_hid_acpi_pdata(struct i2c_client *client,
933} 911}
934#endif 912#endif
935 913
914#ifdef CONFIG_OF
915static int i2c_hid_of_probe(struct i2c_client *client,
916 struct i2c_hid_platform_data *pdata)
917{
918 struct device *dev = &client->dev;
919 u32 val;
920 int ret;
921
922 ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val);
923 if (ret) {
924 dev_err(&client->dev, "HID register address not provided\n");
925 return -ENODEV;
926 }
927 if (val >> 16) {
928 dev_err(&client->dev, "Bad HID register address: 0x%08x\n",
929 val);
930 return -EINVAL;
931 }
932 pdata->hid_descriptor_address = val;
933
934 return 0;
935}
936
937static const struct of_device_id i2c_hid_of_match[] = {
938 { .compatible = "hid-over-i2c" },
939 {},
940};
941MODULE_DEVICE_TABLE(of, i2c_hid_of_match);
942#else
943static inline int i2c_hid_of_probe(struct i2c_client *client,
944 struct i2c_hid_platform_data *pdata)
945{
946 return -ENODEV;
947}
948#endif
949
936static int i2c_hid_probe(struct i2c_client *client, 950static int i2c_hid_probe(struct i2c_client *client,
937 const struct i2c_device_id *dev_id) 951 const struct i2c_device_id *dev_id)
938{ 952{
@@ -954,7 +968,11 @@ static int i2c_hid_probe(struct i2c_client *client,
954 if (!ihid) 968 if (!ihid)
955 return -ENOMEM; 969 return -ENOMEM;
956 970
957 if (!platform_data) { 971 if (client->dev.of_node) {
972 ret = i2c_hid_of_probe(client, &ihid->pdata);
973 if (ret)
974 goto err;
975 } else if (!platform_data) {
958 ret = i2c_hid_acpi_pdata(client, &ihid->pdata); 976 ret = i2c_hid_acpi_pdata(client, &ihid->pdata);
959 if (ret) { 977 if (ret) {
960 dev_err(&client->dev, 978 dev_err(&client->dev,
@@ -1095,6 +1113,7 @@ static struct i2c_driver i2c_hid_driver = {
1095 .owner = THIS_MODULE, 1113 .owner = THIS_MODULE,
1096 .pm = &i2c_hid_pm, 1114 .pm = &i2c_hid_pm,
1097 .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match), 1115 .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match),
1116 .of_match_table = of_match_ptr(i2c_hid_of_match),
1098 }, 1117 },
1099 1118
1100 .probe = i2c_hid_probe, 1119 .probe = i2c_hid_probe,
diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
index fc307e0422af..5bf2fb785844 100644
--- a/drivers/hid/uhid.c
+++ b/drivers/hid/uhid.c
@@ -116,30 +116,6 @@ static void uhid_hid_close(struct hid_device *hid)
116 uhid_queue_event(uhid, UHID_CLOSE); 116 uhid_queue_event(uhid, UHID_CLOSE);
117} 117}
118 118
119static int uhid_hid_input(struct input_dev *input, unsigned int type,
120 unsigned int code, int value)
121{
122 struct hid_device *hid = input_get_drvdata(input);
123 struct uhid_device *uhid = hid->driver_data;
124 unsigned long flags;
125 struct uhid_event *ev;
126
127 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
128 if (!ev)
129 return -ENOMEM;
130
131 ev->type = UHID_OUTPUT_EV;
132 ev->u.output_ev.type = type;
133 ev->u.output_ev.code = code;
134 ev->u.output_ev.value = value;
135
136 spin_lock_irqsave(&uhid->qlock, flags);
137 uhid_queue(uhid, ev);
138 spin_unlock_irqrestore(&uhid->qlock, flags);
139
140 return 0;
141}
142
143static int uhid_hid_parse(struct hid_device *hid) 119static int uhid_hid_parse(struct hid_device *hid)
144{ 120{
145 struct uhid_device *uhid = hid->driver_data; 121 struct uhid_device *uhid = hid->driver_data;
@@ -273,7 +249,6 @@ static struct hid_ll_driver uhid_hid_driver = {
273 .stop = uhid_hid_stop, 249 .stop = uhid_hid_stop,
274 .open = uhid_hid_open, 250 .open = uhid_hid_open,
275 .close = uhid_hid_close, 251 .close = uhid_hid_close,
276 .hidinput_input_event = uhid_hid_input,
277 .parse = uhid_hid_parse, 252 .parse = uhid_hid_parse,
278}; 253};
279 254
@@ -659,3 +634,4 @@ module_exit(uhid_exit);
659MODULE_LICENSE("GPL"); 634MODULE_LICENSE("GPL");
660MODULE_AUTHOR("David Herrmann <dh.herrmann@gmail.com>"); 635MODULE_AUTHOR("David Herrmann <dh.herrmann@gmail.com>");
661MODULE_DESCRIPTION("User-space I/O driver support for HID subsystem"); 636MODULE_DESCRIPTION("User-space I/O driver support for HID subsystem");
637MODULE_ALIAS("devname:" UHID_NAME);
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 99418285222c..44df131d390a 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -535,7 +535,6 @@ static void __usbhid_submit_report(struct hid_device *hid, struct hid_report *re
535{ 535{
536 int head; 536 int head;
537 struct usbhid_device *usbhid = hid->driver_data; 537 struct usbhid_device *usbhid = hid->driver_data;
538 int len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
539 538
540 if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN) 539 if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN)
541 return; 540 return;
@@ -546,7 +545,7 @@ static void __usbhid_submit_report(struct hid_device *hid, struct hid_report *re
546 return; 545 return;
547 } 546 }
548 547
549 usbhid->out[usbhid->outhead].raw_report = kmalloc(len, GFP_ATOMIC); 548 usbhid->out[usbhid->outhead].raw_report = hid_alloc_report_buf(report, GFP_ATOMIC);
550 if (!usbhid->out[usbhid->outhead].raw_report) { 549 if (!usbhid->out[usbhid->outhead].raw_report) {
551 hid_warn(hid, "output queueing failed\n"); 550 hid_warn(hid, "output queueing failed\n");
552 return; 551 return;
@@ -595,7 +594,7 @@ static void __usbhid_submit_report(struct hid_device *hid, struct hid_report *re
595 } 594 }
596 595
597 if (dir == USB_DIR_OUT) { 596 if (dir == USB_DIR_OUT) {
598 usbhid->ctrl[usbhid->ctrlhead].raw_report = kmalloc(len, GFP_ATOMIC); 597 usbhid->ctrl[usbhid->ctrlhead].raw_report = hid_alloc_report_buf(report, GFP_ATOMIC);
599 if (!usbhid->ctrl[usbhid->ctrlhead].raw_report) { 598 if (!usbhid->ctrl[usbhid->ctrlhead].raw_report) {
600 hid_warn(hid, "control queueing failed\n"); 599 hid_warn(hid, "control queueing failed\n");
601 return; 600 return;
@@ -649,62 +648,6 @@ static void usbhid_submit_report(struct hid_device *hid, struct hid_report *repo
649 spin_unlock_irqrestore(&usbhid->lock, flags); 648 spin_unlock_irqrestore(&usbhid->lock, flags);
650} 649}
651 650
652/* Workqueue routine to send requests to change LEDs */
653static void hid_led(struct work_struct *work)
654{
655 struct usbhid_device *usbhid =
656 container_of(work, struct usbhid_device, led_work);
657 struct hid_device *hid = usbhid->hid;
658 struct hid_field *field;
659 unsigned long flags;
660
661 field = hidinput_get_led_field(hid);
662 if (!field) {
663 hid_warn(hid, "LED event field not found\n");
664 return;
665 }
666
667 spin_lock_irqsave(&usbhid->lock, flags);
668 if (!test_bit(HID_DISCONNECTED, &usbhid->iofl)) {
669 usbhid->ledcount = hidinput_count_leds(hid);
670 hid_dbg(usbhid->hid, "New ledcount = %u\n", usbhid->ledcount);
671 __usbhid_submit_report(hid, field->report, USB_DIR_OUT);
672 }
673 spin_unlock_irqrestore(&usbhid->lock, flags);
674}
675
676static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
677{
678 struct hid_device *hid = input_get_drvdata(dev);
679 struct usbhid_device *usbhid = hid->driver_data;
680 struct hid_field *field;
681 unsigned long flags;
682 int offset;
683
684 if (type == EV_FF)
685 return input_ff_event(dev, type, code, value);
686
687 if (type != EV_LED)
688 return -1;
689
690 if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) {
691 hid_warn(dev, "event field not found\n");
692 return -1;
693 }
694
695 spin_lock_irqsave(&usbhid->lock, flags);
696 hid_set_field(field, offset, value);
697 spin_unlock_irqrestore(&usbhid->lock, flags);
698
699 /*
700 * Defer performing requested LED action.
701 * This is more likely gather all LED changes into a single URB.
702 */
703 schedule_work(&usbhid->led_work);
704
705 return 0;
706}
707
708static int usbhid_wait_io(struct hid_device *hid) 651static int usbhid_wait_io(struct hid_device *hid)
709{ 652{
710 struct usbhid_device *usbhid = hid->driver_data; 653 struct usbhid_device *usbhid = hid->driver_data;
@@ -807,12 +750,17 @@ void usbhid_init_reports(struct hid_device *hid)
807{ 750{
808 struct hid_report *report; 751 struct hid_report *report;
809 struct usbhid_device *usbhid = hid->driver_data; 752 struct usbhid_device *usbhid = hid->driver_data;
753 struct hid_report_enum *report_enum;
810 int err, ret; 754 int err, ret;
811 755
812 list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list) 756 if (!(hid->quirks & HID_QUIRK_NO_INIT_INPUT_REPORTS)) {
813 usbhid_submit_report(hid, report, USB_DIR_IN); 757 report_enum = &hid->report_enum[HID_INPUT_REPORT];
758 list_for_each_entry(report, &report_enum->report_list, list)
759 usbhid_submit_report(hid, report, USB_DIR_IN);
760 }
814 761
815 list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list) 762 report_enum = &hid->report_enum[HID_FEATURE_REPORT];
763 list_for_each_entry(report, &report_enum->report_list, list)
816 usbhid_submit_report(hid, report, USB_DIR_IN); 764 usbhid_submit_report(hid, report, USB_DIR_IN);
817 765
818 err = 0; 766 err = 0;
@@ -857,7 +805,7 @@ static int hid_find_field_early(struct hid_device *hid, unsigned int page,
857 return -1; 805 return -1;
858} 806}
859 807
860void usbhid_set_leds(struct hid_device *hid) 808static void usbhid_set_leds(struct hid_device *hid)
861{ 809{
862 struct hid_field *field; 810 struct hid_field *field;
863 int offset; 811 int offset;
@@ -867,7 +815,6 @@ void usbhid_set_leds(struct hid_device *hid)
867 usbhid_submit_report(hid, field->report, USB_DIR_OUT); 815 usbhid_submit_report(hid, field->report, USB_DIR_OUT);
868 } 816 }
869} 817}
870EXPORT_SYMBOL_GPL(usbhid_set_leds);
871 818
872/* 819/*
873 * Traverse the supplied list of reports and find the longest 820 * Traverse the supplied list of reports and find the longest
@@ -1274,7 +1221,6 @@ static struct hid_ll_driver usb_hid_driver = {
1274 .open = usbhid_open, 1221 .open = usbhid_open,
1275 .close = usbhid_close, 1222 .close = usbhid_close,
1276 .power = usbhid_power, 1223 .power = usbhid_power,
1277 .hidinput_input_event = usb_hidinput_input_event,
1278 .request = usbhid_request, 1224 .request = usbhid_request,
1279 .wait = usbhid_wait_io, 1225 .wait = usbhid_wait_io,
1280 .idle = usbhid_idle, 1226 .idle = usbhid_idle,
@@ -1368,8 +1314,6 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id *
1368 setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid); 1314 setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid);
1369 spin_lock_init(&usbhid->lock); 1315 spin_lock_init(&usbhid->lock);
1370 1316
1371 INIT_WORK(&usbhid->led_work, hid_led);
1372
1373 ret = hid_add_device(hid); 1317 ret = hid_add_device(hid);
1374 if (ret) { 1318 if (ret) {
1375 if (ret != -ENODEV) 1319 if (ret != -ENODEV)
@@ -1402,7 +1346,6 @@ static void hid_cancel_delayed_stuff(struct usbhid_device *usbhid)
1402{ 1346{
1403 del_timer_sync(&usbhid->io_retry); 1347 del_timer_sync(&usbhid->io_retry);
1404 cancel_work_sync(&usbhid->reset_work); 1348 cancel_work_sync(&usbhid->reset_work);
1405 cancel_work_sync(&usbhid->led_work);
1406} 1349}
1407 1350
1408static void hid_cease_io(struct usbhid_device *usbhid) 1351static void hid_cease_io(struct usbhid_device *usbhid)
@@ -1522,15 +1465,17 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1522 struct usbhid_device *usbhid = hid->driver_data; 1465 struct usbhid_device *usbhid = hid->driver_data;
1523 int status = 0; 1466 int status = 0;
1524 bool driver_suspended = false; 1467 bool driver_suspended = false;
1468 unsigned int ledcount;
1525 1469
1526 if (PMSG_IS_AUTO(message)) { 1470 if (PMSG_IS_AUTO(message)) {
1471 ledcount = hidinput_count_leds(hid);
1527 spin_lock_irq(&usbhid->lock); /* Sync with error handler */ 1472 spin_lock_irq(&usbhid->lock); /* Sync with error handler */
1528 if (!test_bit(HID_RESET_PENDING, &usbhid->iofl) 1473 if (!test_bit(HID_RESET_PENDING, &usbhid->iofl)
1529 && !test_bit(HID_CLEAR_HALT, &usbhid->iofl) 1474 && !test_bit(HID_CLEAR_HALT, &usbhid->iofl)
1530 && !test_bit(HID_OUT_RUNNING, &usbhid->iofl) 1475 && !test_bit(HID_OUT_RUNNING, &usbhid->iofl)
1531 && !test_bit(HID_CTRL_RUNNING, &usbhid->iofl) 1476 && !test_bit(HID_CTRL_RUNNING, &usbhid->iofl)
1532 && !test_bit(HID_KEYS_PRESSED, &usbhid->iofl) 1477 && !test_bit(HID_KEYS_PRESSED, &usbhid->iofl)
1533 && (!usbhid->ledcount || ignoreled)) 1478 && (!ledcount || ignoreled))
1534 { 1479 {
1535 set_bit(HID_SUSPENDED, &usbhid->iofl); 1480 set_bit(HID_SUSPENDED, &usbhid->iofl);
1536 spin_unlock_irq(&usbhid->lock); 1481 spin_unlock_irq(&usbhid->lock);
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 19b8360f2330..07345521f421 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -109,6 +109,8 @@ static const struct hid_blacklist {
109 { USB_VENDOR_ID_SIGMA_MICRO, USB_DEVICE_ID_SIGMA_MICRO_KEYBOARD, HID_QUIRK_NO_INIT_REPORTS }, 109 { USB_VENDOR_ID_SIGMA_MICRO, USB_DEVICE_ID_SIGMA_MICRO_KEYBOARD, HID_QUIRK_NO_INIT_REPORTS },
110 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X, HID_QUIRK_MULTI_INPUT }, 110 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X, HID_QUIRK_MULTI_INPUT },
111 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X, HID_QUIRK_MULTI_INPUT }, 111 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X, HID_QUIRK_MULTI_INPUT },
112 { USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_DUOSENSE, HID_QUIRK_NO_INIT_REPORTS },
113
112 { 0, 0 } 114 { 0, 0 }
113}; 115};
114 116
diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h
index dbb6af699135..f633c24ce28b 100644
--- a/drivers/hid/usbhid/usbhid.h
+++ b/drivers/hid/usbhid/usbhid.h
@@ -92,9 +92,6 @@ struct usbhid_device {
92 unsigned int retry_delay; /* Delay length in ms */ 92 unsigned int retry_delay; /* Delay length in ms */
93 struct work_struct reset_work; /* Task context for resets */ 93 struct work_struct reset_work; /* Task context for resets */
94 wait_queue_head_t wait; /* For sleeping */ 94 wait_queue_head_t wait; /* For sleeping */
95 int ledcount; /* counting the number of active leds */
96
97 struct work_struct led_work; /* Task context for setting LEDs */
98}; 95};
99 96
100#define hid_to_usb_dev(hid_dev) \ 97#define hid_to_usb_dev(hid_dev) \
diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c
index 4ef4d5e198ae..a73f9618b0ad 100644
--- a/drivers/input/mouse/bcm5974.c
+++ b/drivers/input/mouse/bcm5974.c
@@ -89,9 +89,9 @@
89#define USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO 0x025a 89#define USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO 0x025a
90#define USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS 0x025b 90#define USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS 0x025b
91/* MacbookAir6,2 (unibody, June 2013) */ 91/* MacbookAir6,2 (unibody, June 2013) */
92#define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0291 92#define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0290
93#define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0292 93#define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0291
94#define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0293 94#define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0292
95 95
96#define BCM5974_DEVICE(prod) { \ 96#define BCM5974_DEVICE(prod) { \
97 .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \ 97 .match_flags = (USB_DEVICE_ID_MATCH_DEVICE | \