aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/hid/hid-over-i2c.txt28
-rw-r--r--Documentation/hid/uhid.txt4
-rw-r--r--drivers/hid/hid-a4tech.c21
-rw-r--r--drivers/hid/hid-apple.c16
-rw-r--r--drivers/hid/hid-core.c118
-rw-r--r--drivers/hid/hid-input.c80
-rw-r--r--drivers/hid/hid-logitech-dj.c10
-rw-r--r--drivers/hid/hid-magicmouse.c17
-rw-r--r--drivers/hid/hid-multitouch.c107
-rw-r--r--drivers/hid/hid-sony.c9
-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-zydacron.c19
-rw-r--r--drivers/hid/i2c-hid/i2c-hid.c73
-rw-r--r--drivers/hid/uhid.c25
-rw-r--r--drivers/hid/usbhid/hid-core.c78
-rw-r--r--drivers/hid/usbhid/usbhid.h3
-rw-r--r--include/linux/hid.h7
-rw-r--r--include/linux/i2c/i2c-hid.h3
-rw-r--r--include/linux/mod_devicetable.h2
-rw-r--r--include/uapi/linux/input.h25
-rw-r--r--include/uapi/linux/uhid.h4
-rw-r--r--samples/uhid/uhid-example.c123
24 files changed, 874 insertions, 334 deletions
diff --git a/Documentation/devicetree/bindings/hid/hid-over-i2c.txt b/Documentation/devicetree/bindings/hid/hid-over-i2c.txt
new file mode 100644
index 000000000000..488edcb264c4
--- /dev/null
+++ b/Documentation/devicetree/bindings/hid/hid-over-i2c.txt
@@ -0,0 +1,28 @@
1* HID over I2C Device-Tree bindings
2
3HID over I2C provides support for various Human Interface Devices over the
4I2C bus. These devices can be for example touchpads, keyboards, touch screens
5or sensors.
6
7The specification has been written by Microsoft and is currently available here:
8http://msdn.microsoft.com/en-us/library/windows/hardware/hh852380.aspx
9
10If this binding is used, the kernel module i2c-hid will handle the communication
11with the device and the generic hid core layer will handle the protocol.
12
13Required properties:
14- compatible: must be "hid-over-i2c"
15- reg: i2c slave address
16- hid-descr-addr: HID descriptor address
17- interrupt-parent: the phandle for the interrupt controller
18- interrupts: interrupt line
19
20Example:
21
22 i2c-hid-dev@2c {
23 compatible = "hid-over-i2c";
24 reg = <0x2c>;
25 hid-descr-addr = <0x0020>;
26 interrupt-parent = <&gpx3>;
27 interrupts = <3 2>;
28 };
diff --git a/Documentation/hid/uhid.txt b/Documentation/hid/uhid.txt
index 3c741214dfbb..dc35a2b75eee 100644
--- a/Documentation/hid/uhid.txt
+++ b/Documentation/hid/uhid.txt
@@ -149,11 +149,13 @@ needs. Only UHID_OUTPUT and UHID_OUTPUT_EV have payloads.
149 is of type "struct uhid_data_req". 149 is of type "struct uhid_data_req".
150 This may be received even though you haven't received UHID_OPEN, yet. 150 This may be received even though you haven't received UHID_OPEN, yet.
151 151
152 UHID_OUTPUT_EV: 152 UHID_OUTPUT_EV (obsolete):
153 Same as UHID_OUTPUT but this contains a "struct input_event" as payload. This 153 Same as UHID_OUTPUT but this contains a "struct input_event" as payload. This
154 is called for force-feedback, LED or similar events which are received through 154 is called for force-feedback, LED or similar events which are received through
155 an input device by the HID subsystem. You should convert this into raw reports 155 an input device by the HID subsystem. You should convert this into raw reports
156 and send them to your device similar to events of type UHID_OUTPUT. 156 and send them to your device similar to events of type UHID_OUTPUT.
157 This is no longer sent by newer kernels. Instead, HID core converts it into a
158 raw output report and sends it via UHID_OUTPUT.
157 159
158 UHID_FEATURE: 160 UHID_FEATURE:
159 This event is sent if the kernel driver wants to perform a feature request as 161 This event is sent if the kernel driver wants to perform a feature request as
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 2ac13ca6edaa..2c778542e40d 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -681,12 +681,61 @@ static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
681 return NULL; 681 return NULL;
682} 682}
683 683
684static void hid_scan_usage(struct hid_device *hid, u32 usage) 684static void hid_scan_input_usage(struct hid_parser *parser, u32 usage)
685{ 685{
686 struct hid_device *hid = parser->device;
687
686 if (usage == HID_DG_CONTACTID) 688 if (usage == HID_DG_CONTACTID)
687 hid->group = HID_GROUP_MULTITOUCH; 689 hid->group = HID_GROUP_MULTITOUCH;
688} 690}
689 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
690/* 739/*
691 * 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.
692 * Sets device groups and other properties that determine what driver 741 * Sets device groups and other properties that determine what driver
@@ -694,48 +743,41 @@ static void hid_scan_usage(struct hid_device *hid, u32 usage)
694 */ 743 */
695static int hid_scan_report(struct hid_device *hid) 744static int hid_scan_report(struct hid_device *hid)
696{ 745{
697 unsigned int page = 0, delim = 0; 746 struct hid_parser *parser;
747 struct hid_item item;
698 __u8 *start = hid->dev_rdesc; 748 __u8 *start = hid->dev_rdesc;
699 __u8 *end = start + hid->dev_rsize; 749 __u8 *end = start + hid->dev_rsize;
700 unsigned int u, u_min = 0, u_max = 0; 750 static int (*dispatch_type[])(struct hid_parser *parser,
701 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 };
702 757
758 parser = vzalloc(sizeof(struct hid_parser));
759 if (!parser)
760 return -ENOMEM;
761
762 parser->device = hid;
703 hid->group = HID_GROUP_GENERIC; 763 hid->group = HID_GROUP_GENERIC;
704 while ((start = fetch_item(start, end, &item)) != NULL) {
705 if (item.format != HID_ITEM_FORMAT_SHORT)
706 return -EINVAL;
707 if (item.type == HID_ITEM_TYPE_GLOBAL) {
708 if (item.tag == HID_GLOBAL_ITEM_TAG_USAGE_PAGE)
709 page = item_udata(&item) << 16;
710 } else if (item.type == HID_ITEM_TYPE_LOCAL) {
711 if (delim > 1)
712 break;
713 u = item_udata(&item);
714 if (item.size <= 2)
715 u += page;
716 switch (item.tag) {
717 case HID_LOCAL_ITEM_TAG_DELIMITER:
718 delim += !!u;
719 break;
720 case HID_LOCAL_ITEM_TAG_USAGE:
721 hid_scan_usage(hid, u);
722 break;
723 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
724 u_min = u;
725 break;
726 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
727 u_max = u;
728 for (u = u_min; u <= u_max; u++)
729 hid_scan_usage(hid, u);
730 break;
731 }
732 } else if (page == HID_UP_SENSOR &&
733 item.type == HID_ITEM_TYPE_MAIN &&
734 item.tag == HID_MAIN_ITEM_TAG_BEGIN_COLLECTION &&
735 (item_udata(&item) & 0xff) == HID_COLLECTION_PHYSICAL)
736 hid->group = HID_GROUP_SENSOR_HUB;
737 }
738 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);
739 return 0; 781 return 0;
740} 782}
741 783
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 3fc4034a4367..b420f4a0fd28 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -1145,6 +1145,74 @@ unsigned int hidinput_count_leds(struct hid_device *hid)
1145} 1145}
1146EXPORT_SYMBOL_GPL(hidinput_count_leds); 1146EXPORT_SYMBOL_GPL(hidinput_count_leds);
1147 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
1148static int hidinput_open(struct input_dev *dev) 1216static int hidinput_open(struct input_dev *dev)
1149{ 1217{
1150 struct hid_device *hid = input_get_drvdata(dev); 1218 struct hid_device *hid = input_get_drvdata(dev);
@@ -1191,7 +1259,10 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid)
1191 } 1259 }
1192 1260
1193 input_set_drvdata(input_dev, hid); 1261 input_set_drvdata(input_dev, hid);
1194 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;
1195 input_dev->open = hidinput_open; 1266 input_dev->open = hidinput_open;
1196 input_dev->close = hidinput_close; 1267 input_dev->close = hidinput_close;
1197 input_dev->setkeycode = hidinput_setkeycode; 1268 input_dev->setkeycode = hidinput_setkeycode;
@@ -1286,6 +1357,7 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
1286 int i, j, k; 1357 int i, j, k;
1287 1358
1288 INIT_LIST_HEAD(&hid->inputs); 1359 INIT_LIST_HEAD(&hid->inputs);
1360 INIT_WORK(&hid->led_work, hidinput_led_worker);
1289 1361
1290 if (!force) { 1362 if (!force) {
1291 for (i = 0; i < hid->maxcollection; i++) { 1363 for (i = 0; i < hid->maxcollection; i++) {
@@ -1387,6 +1459,12 @@ void hidinput_disconnect(struct hid_device *hid)
1387 input_unregister_device(hidinput->input); 1459 input_unregister_device(hidinput->input);
1388 kfree(hidinput); 1460 kfree(hidinput);
1389 } 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);
1390} 1468}
1391EXPORT_SYMBOL_GPL(hidinput_disconnect); 1469EXPORT_SYMBOL_GPL(hidinput_disconnect);
1392 1470
diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
index d0e5963c1ba1..7800b1410562 100644
--- a/drivers/hid/hid-logitech-dj.c
+++ b/drivers/hid/hid-logitech-dj.c
@@ -809,10 +809,10 @@ static int logi_dj_probe(struct hid_device *hdev,
809 } 809 }
810 810
811 /* This is enabling the polling urb on the IN endpoint */ 811 /* This is enabling the polling urb on the IN endpoint */
812 retval = hdev->ll_driver->open(hdev); 812 retval = hid_hw_open(hdev);
813 if (retval < 0) { 813 if (retval < 0) {
814 dev_err(&hdev->dev, "%s:hdev->ll_driver->open returned " 814 dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n",
815 "error:%d\n", __func__, retval); 815 __func__, retval);
816 goto llopen_failed; 816 goto llopen_failed;
817 } 817 }
818 818
@@ -829,7 +829,7 @@ static int logi_dj_probe(struct hid_device *hdev,
829 return retval; 829 return retval;
830 830
831logi_dj_recv_query_paired_devices_failed: 831logi_dj_recv_query_paired_devices_failed:
832 hdev->ll_driver->close(hdev); 832 hid_hw_close(hdev);
833 833
834llopen_failed: 834llopen_failed:
835switch_to_dj_mode_fail: 835switch_to_dj_mode_fail:
@@ -871,7 +871,7 @@ static void logi_dj_remove(struct hid_device *hdev)
871 871
872 cancel_work_sync(&djrcv_dev->work); 872 cancel_work_sync(&djrcv_dev->work);
873 873
874 hdev->ll_driver->close(hdev); 874 hid_hw_close(hdev);
875 hid_hw_stop(hdev); 875 hid_hw_stop(hdev);
876 876
877 /* 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 a32f5a24b27c..3b43d1cfa936 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -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-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-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-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/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index 3cb7d966da9e..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)
@@ -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 9ab7dfc6c72c..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
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index ada164e1b3a1..44df131d390a 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -648,62 +648,6 @@ static void usbhid_submit_report(struct hid_device *hid, struct hid_report *repo
648 spin_unlock_irqrestore(&usbhid->lock, flags); 648 spin_unlock_irqrestore(&usbhid->lock, flags);
649} 649}
650 650
651/* Workqueue routine to send requests to change LEDs */
652static void hid_led(struct work_struct *work)
653{
654 struct usbhid_device *usbhid =
655 container_of(work, struct usbhid_device, led_work);
656 struct hid_device *hid = usbhid->hid;
657 struct hid_field *field;
658 unsigned long flags;
659
660 field = hidinput_get_led_field(hid);
661 if (!field) {
662 hid_warn(hid, "LED event field not found\n");
663 return;
664 }
665
666 spin_lock_irqsave(&usbhid->lock, flags);
667 if (!test_bit(HID_DISCONNECTED, &usbhid->iofl)) {
668 usbhid->ledcount = hidinput_count_leds(hid);
669 hid_dbg(usbhid->hid, "New ledcount = %u\n", usbhid->ledcount);
670 __usbhid_submit_report(hid, field->report, USB_DIR_OUT);
671 }
672 spin_unlock_irqrestore(&usbhid->lock, flags);
673}
674
675static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
676{
677 struct hid_device *hid = input_get_drvdata(dev);
678 struct usbhid_device *usbhid = hid->driver_data;
679 struct hid_field *field;
680 unsigned long flags;
681 int offset;
682
683 if (type == EV_FF)
684 return input_ff_event(dev, type, code, value);
685
686 if (type != EV_LED)
687 return -1;
688
689 if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) {
690 hid_warn(dev, "event field not found\n");
691 return -1;
692 }
693
694 spin_lock_irqsave(&usbhid->lock, flags);
695 hid_set_field(field, offset, value);
696 spin_unlock_irqrestore(&usbhid->lock, flags);
697
698 /*
699 * Defer performing requested LED action.
700 * This is more likely gather all LED changes into a single URB.
701 */
702 schedule_work(&usbhid->led_work);
703
704 return 0;
705}
706
707static int usbhid_wait_io(struct hid_device *hid) 651static int usbhid_wait_io(struct hid_device *hid)
708{ 652{
709 struct usbhid_device *usbhid = hid->driver_data; 653 struct usbhid_device *usbhid = hid->driver_data;
@@ -806,12 +750,17 @@ void usbhid_init_reports(struct hid_device *hid)
806{ 750{
807 struct hid_report *report; 751 struct hid_report *report;
808 struct usbhid_device *usbhid = hid->driver_data; 752 struct usbhid_device *usbhid = hid->driver_data;
753 struct hid_report_enum *report_enum;
809 int err, ret; 754 int err, ret;
810 755
811 list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list) 756 if (!(hid->quirks & HID_QUIRK_NO_INIT_INPUT_REPORTS)) {
812 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 }
813 761
814 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)
815 usbhid_submit_report(hid, report, USB_DIR_IN); 764 usbhid_submit_report(hid, report, USB_DIR_IN);
816 765
817 err = 0; 766 err = 0;
@@ -856,7 +805,7 @@ static int hid_find_field_early(struct hid_device *hid, unsigned int page,
856 return -1; 805 return -1;
857} 806}
858 807
859void usbhid_set_leds(struct hid_device *hid) 808static void usbhid_set_leds(struct hid_device *hid)
860{ 809{
861 struct hid_field *field; 810 struct hid_field *field;
862 int offset; 811 int offset;
@@ -866,7 +815,6 @@ void usbhid_set_leds(struct hid_device *hid)
866 usbhid_submit_report(hid, field->report, USB_DIR_OUT); 815 usbhid_submit_report(hid, field->report, USB_DIR_OUT);
867 } 816 }
868} 817}
869EXPORT_SYMBOL_GPL(usbhid_set_leds);
870 818
871/* 819/*
872 * Traverse the supplied list of reports and find the longest 820 * Traverse the supplied list of reports and find the longest
@@ -1273,7 +1221,6 @@ static struct hid_ll_driver usb_hid_driver = {
1273 .open = usbhid_open, 1221 .open = usbhid_open,
1274 .close = usbhid_close, 1222 .close = usbhid_close,
1275 .power = usbhid_power, 1223 .power = usbhid_power,
1276 .hidinput_input_event = usb_hidinput_input_event,
1277 .request = usbhid_request, 1224 .request = usbhid_request,
1278 .wait = usbhid_wait_io, 1225 .wait = usbhid_wait_io,
1279 .idle = usbhid_idle, 1226 .idle = usbhid_idle,
@@ -1367,8 +1314,6 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id *
1367 setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid); 1314 setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid);
1368 spin_lock_init(&usbhid->lock); 1315 spin_lock_init(&usbhid->lock);
1369 1316
1370 INIT_WORK(&usbhid->led_work, hid_led);
1371
1372 ret = hid_add_device(hid); 1317 ret = hid_add_device(hid);
1373 if (ret) { 1318 if (ret) {
1374 if (ret != -ENODEV) 1319 if (ret != -ENODEV)
@@ -1401,7 +1346,6 @@ static void hid_cancel_delayed_stuff(struct usbhid_device *usbhid)
1401{ 1346{
1402 del_timer_sync(&usbhid->io_retry); 1347 del_timer_sync(&usbhid->io_retry);
1403 cancel_work_sync(&usbhid->reset_work); 1348 cancel_work_sync(&usbhid->reset_work);
1404 cancel_work_sync(&usbhid->led_work);
1405} 1349}
1406 1350
1407static void hid_cease_io(struct usbhid_device *usbhid) 1351static void hid_cease_io(struct usbhid_device *usbhid)
@@ -1521,15 +1465,17 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1521 struct usbhid_device *usbhid = hid->driver_data; 1465 struct usbhid_device *usbhid = hid->driver_data;
1522 int status = 0; 1466 int status = 0;
1523 bool driver_suspended = false; 1467 bool driver_suspended = false;
1468 unsigned int ledcount;
1524 1469
1525 if (PMSG_IS_AUTO(message)) { 1470 if (PMSG_IS_AUTO(message)) {
1471 ledcount = hidinput_count_leds(hid);
1526 spin_lock_irq(&usbhid->lock); /* Sync with error handler */ 1472 spin_lock_irq(&usbhid->lock); /* Sync with error handler */
1527 if (!test_bit(HID_RESET_PENDING, &usbhid->iofl) 1473 if (!test_bit(HID_RESET_PENDING, &usbhid->iofl)
1528 && !test_bit(HID_CLEAR_HALT, &usbhid->iofl) 1474 && !test_bit(HID_CLEAR_HALT, &usbhid->iofl)
1529 && !test_bit(HID_OUT_RUNNING, &usbhid->iofl) 1475 && !test_bit(HID_OUT_RUNNING, &usbhid->iofl)
1530 && !test_bit(HID_CTRL_RUNNING, &usbhid->iofl) 1476 && !test_bit(HID_CTRL_RUNNING, &usbhid->iofl)
1531 && !test_bit(HID_KEYS_PRESSED, &usbhid->iofl) 1477 && !test_bit(HID_KEYS_PRESSED, &usbhid->iofl)
1532 && (!usbhid->ledcount || ignoreled)) 1478 && (!ledcount || ignoreled))
1533 { 1479 {
1534 set_bit(HID_SUSPENDED, &usbhid->iofl); 1480 set_bit(HID_SUSPENDED, &usbhid->iofl);
1535 spin_unlock_irq(&usbhid->lock); 1481 spin_unlock_irq(&usbhid->lock);
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/include/linux/hid.h b/include/linux/hid.h
index 729bf27aac8f..ee1ffc5e19c9 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -285,6 +285,7 @@ struct hid_item {
285#define HID_QUIRK_MULTI_INPUT 0x00000040 285#define HID_QUIRK_MULTI_INPUT 0x00000040
286#define HID_QUIRK_HIDINPUT_FORCE 0x00000080 286#define HID_QUIRK_HIDINPUT_FORCE 0x00000080
287#define HID_QUIRK_NO_EMPTY_INPUT 0x00000100 287#define HID_QUIRK_NO_EMPTY_INPUT 0x00000100
288#define HID_QUIRK_NO_INIT_INPUT_REPORTS 0x00000200
288#define HID_QUIRK_SKIP_OUTPUT_REPORTS 0x00010000 289#define HID_QUIRK_SKIP_OUTPUT_REPORTS 0x00010000
289#define HID_QUIRK_FULLSPEED_INTERVAL 0x10000000 290#define HID_QUIRK_FULLSPEED_INTERVAL 0x10000000
290#define HID_QUIRK_NO_INIT_REPORTS 0x20000000 291#define HID_QUIRK_NO_INIT_REPORTS 0x20000000
@@ -297,6 +298,7 @@ struct hid_item {
297#define HID_GROUP_GENERIC 0x0001 298#define HID_GROUP_GENERIC 0x0001
298#define HID_GROUP_MULTITOUCH 0x0002 299#define HID_GROUP_MULTITOUCH 0x0002
299#define HID_GROUP_SENSOR_HUB 0x0003 300#define HID_GROUP_SENSOR_HUB 0x0003
301#define HID_GROUP_MULTITOUCH_WIN_8 0x0004
300 302
301/* 303/*
302 * This is the global environment of the parser. This information is 304 * This is the global environment of the parser. This information is
@@ -458,6 +460,7 @@ struct hid_device { /* device report descriptor */
458 enum hid_type type; /* device type (mouse, kbd, ...) */ 460 enum hid_type type; /* device type (mouse, kbd, ...) */
459 unsigned country; /* HID country */ 461 unsigned country; /* HID country */
460 struct hid_report_enum report_enum[HID_REPORT_TYPES]; 462 struct hid_report_enum report_enum[HID_REPORT_TYPES];
463 struct work_struct led_work; /* delayed LED worker */
461 464
462 struct semaphore driver_lock; /* protects the current driver, except during input */ 465 struct semaphore driver_lock; /* protects the current driver, except during input */
463 struct semaphore driver_input_lock; /* protects the current driver */ 466 struct semaphore driver_input_lock; /* protects the current driver */
@@ -534,6 +537,8 @@ static inline void hid_set_drvdata(struct hid_device *hdev, void *data)
534#define HID_GLOBAL_STACK_SIZE 4 537#define HID_GLOBAL_STACK_SIZE 4
535#define HID_COLLECTION_STACK_SIZE 4 538#define HID_COLLECTION_STACK_SIZE 4
536 539
540#define HID_SCAN_FLAG_MT_WIN_8 0x00000001
541
537struct hid_parser { 542struct hid_parser {
538 struct hid_global global; 543 struct hid_global global;
539 struct hid_global global_stack[HID_GLOBAL_STACK_SIZE]; 544 struct hid_global global_stack[HID_GLOBAL_STACK_SIZE];
@@ -542,6 +547,7 @@ struct hid_parser {
542 unsigned collection_stack[HID_COLLECTION_STACK_SIZE]; 547 unsigned collection_stack[HID_COLLECTION_STACK_SIZE];
543 unsigned collection_stack_ptr; 548 unsigned collection_stack_ptr;
544 struct hid_device *device; 549 struct hid_device *device;
550 unsigned scan_flags;
545}; 551};
546 552
547struct hid_class_descriptor { 553struct hid_class_descriptor {
@@ -992,7 +998,6 @@ int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
992u32 usbhid_lookup_quirk(const u16 idVendor, const u16 idProduct); 998u32 usbhid_lookup_quirk(const u16 idVendor, const u16 idProduct);
993int usbhid_quirks_init(char **quirks_param); 999int usbhid_quirks_init(char **quirks_param);
994void usbhid_quirks_exit(void); 1000void usbhid_quirks_exit(void);
995void usbhid_set_leds(struct hid_device *hid);
996 1001
997#ifdef CONFIG_HID_PID 1002#ifdef CONFIG_HID_PID
998int hid_pidff_init(struct hid_device *hid); 1003int hid_pidff_init(struct hid_device *hid);
diff --git a/include/linux/i2c/i2c-hid.h b/include/linux/i2c/i2c-hid.h
index 60e411d764d4..7aa901d92058 100644
--- a/include/linux/i2c/i2c-hid.h
+++ b/include/linux/i2c/i2c-hid.h
@@ -19,7 +19,8 @@
19 * @hid_descriptor_address: i2c register where the HID descriptor is stored. 19 * @hid_descriptor_address: i2c register where the HID descriptor is stored.
20 * 20 *
21 * Note that it is the responsibility of the platform driver (or the acpi 5.0 21 * Note that it is the responsibility of the platform driver (or the acpi 5.0
22 * driver) to setup the irq related to the gpio in the struct i2c_board_info. 22 * driver, or the flattened device tree) to setup the irq related to the gpio in
23 * the struct i2c_board_info.
23 * The platform driver should also setup the gpio according to the device: 24 * The platform driver should also setup the gpio according to the device:
24 * 25 *
25 * A typical example is the following: 26 * A typical example is the following:
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 45e921401b06..329aa307cb77 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -277,7 +277,7 @@ struct pcmcia_device_id {
277#define INPUT_DEVICE_ID_KEY_MIN_INTERESTING 0x71 277#define INPUT_DEVICE_ID_KEY_MIN_INTERESTING 0x71
278#define INPUT_DEVICE_ID_KEY_MAX 0x2ff 278#define INPUT_DEVICE_ID_KEY_MAX 0x2ff
279#define INPUT_DEVICE_ID_REL_MAX 0x0f 279#define INPUT_DEVICE_ID_REL_MAX 0x0f
280#define INPUT_DEVICE_ID_ABS_MAX 0x3f 280#define INPUT_DEVICE_ID_ABS_MAX 0x4f
281#define INPUT_DEVICE_ID_MSC_MAX 0x07 281#define INPUT_DEVICE_ID_MSC_MAX 0x07
282#define INPUT_DEVICE_ID_LED_MAX 0x0f 282#define INPUT_DEVICE_ID_LED_MAX 0x0f
283#define INPUT_DEVICE_ID_SND_MAX 0x07 283#define INPUT_DEVICE_ID_SND_MAX 0x07
diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h
index d584047b072b..76457eef172a 100644
--- a/include/uapi/linux/input.h
+++ b/include/uapi/linux/input.h
@@ -716,6 +716,14 @@ struct input_keymap_entry {
716#define BTN_DPAD_LEFT 0x222 716#define BTN_DPAD_LEFT 0x222
717#define BTN_DPAD_RIGHT 0x223 717#define BTN_DPAD_RIGHT 0x223
718 718
719#define BTN_FRET_FAR_UP 0x224
720#define BTN_FRET_UP 0x225
721#define BTN_FRET_MID 0x226
722#define BTN_FRET_LOW 0x227
723#define BTN_FRET_FAR_LOW 0x228
724#define BTN_STRUM_BAR_UP 0x229
725#define BTN_STRUM_BAR_DOWN 0x22a
726
719#define BTN_TRIGGER_HAPPY 0x2c0 727#define BTN_TRIGGER_HAPPY 0x2c0
720#define BTN_TRIGGER_HAPPY1 0x2c0 728#define BTN_TRIGGER_HAPPY1 0x2c0
721#define BTN_TRIGGER_HAPPY2 0x2c1 729#define BTN_TRIGGER_HAPPY2 0x2c1
@@ -829,8 +837,21 @@ struct input_keymap_entry {
829#define ABS_MT_TOOL_X 0x3c /* Center X tool position */ 837#define ABS_MT_TOOL_X 0x3c /* Center X tool position */
830#define ABS_MT_TOOL_Y 0x3d /* Center Y tool position */ 838#define ABS_MT_TOOL_Y 0x3d /* Center Y tool position */
831 839
832 840/* Drums and guitars (mostly toys) */
833#define ABS_MAX 0x3f 841#define ABS_TOM_FAR_LEFT 0x40
842#define ABS_TOM_LEFT 0x41
843#define ABS_TOM_RIGHT 0x42
844#define ABS_TOM_FAR_RIGHT 0x43
845#define ABS_CYMBAL_FAR_LEFT 0x44
846#define ABS_CYMBAL_LEFT 0x45
847#define ABS_CYMBAL_RIGHT 0x46
848#define ABS_CYMBAL_FAR_RIGHT 0x47
849#define ABS_BASS 0x48
850#define ABS_HI_HAT 0x49
851#define ABS_FRET_BOARD 0x4a /* Guitar fret board, vertical pos */
852#define ABS_WHAMMY_BAR 0x4b /* Guitar whammy bar (or vibrato) */
853
854#define ABS_MAX 0x4f
834#define ABS_CNT (ABS_MAX+1) 855#define ABS_CNT (ABS_MAX+1)
835 856
836/* 857/*
diff --git a/include/uapi/linux/uhid.h b/include/uapi/linux/uhid.h
index e9ed951e2b09..414b74be4da1 100644
--- a/include/uapi/linux/uhid.h
+++ b/include/uapi/linux/uhid.h
@@ -30,7 +30,7 @@ enum uhid_event_type {
30 UHID_OPEN, 30 UHID_OPEN,
31 UHID_CLOSE, 31 UHID_CLOSE,
32 UHID_OUTPUT, 32 UHID_OUTPUT,
33 UHID_OUTPUT_EV, 33 UHID_OUTPUT_EV, /* obsolete! */
34 UHID_INPUT, 34 UHID_INPUT,
35 UHID_FEATURE, 35 UHID_FEATURE,
36 UHID_FEATURE_ANSWER, 36 UHID_FEATURE_ANSWER,
@@ -69,6 +69,8 @@ struct uhid_output_req {
69 __u8 rtype; 69 __u8 rtype;
70} __attribute__((__packed__)); 70} __attribute__((__packed__));
71 71
72/* Obsolete! Newer kernels will no longer send these events but instead convert
73 * it into raw output reports via UHID_OUTPUT. */
72struct uhid_output_ev_req { 74struct uhid_output_ev_req {
73 __u16 type; 75 __u16 type;
74 __u16 code; 76 __u16 code;
diff --git a/samples/uhid/uhid-example.c b/samples/uhid/uhid-example.c
index 03ce3c059a5e..7d58a4b8d324 100644
--- a/samples/uhid/uhid-example.c
+++ b/samples/uhid/uhid-example.c
@@ -1,14 +1,15 @@
1/* 1/*
2 * UHID Example 2 * UHID Example
3 * 3 *
4 * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com> 4 * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
5 * 5 *
6 * The code may be used by anyone for any purpose, 6 * The code may be used by anyone for any purpose,
7 * and can serve as a starting point for developing 7 * and can serve as a starting point for developing
8 * applications using uhid. 8 * applications using uhid.
9 */ 9 */
10 10
11/* UHID Example 11/*
12 * UHID Example
12 * This example emulates a basic 3 buttons mouse with wheel over UHID. Run this 13 * This example emulates a basic 3 buttons mouse with wheel over UHID. Run this
13 * program as root and then use the following keys to control the mouse: 14 * program as root and then use the following keys to control the mouse:
14 * q: Quit the application 15 * q: Quit the application
@@ -22,6 +23,11 @@
22 * r: Move wheel up 23 * r: Move wheel up
23 * f: Move wheel down 24 * f: Move wheel down
24 * 25 *
26 * Additionally to 3 button mouse, 3 keyboard LEDs are also supported (LED_NUML,
27 * LED_CAPSL and LED_SCROLLL). The device doesn't generate any related keyboard
28 * events, though. You need to manually write the EV_LED/LED_XY/1 activation
29 * input event to the evdev device to see it being sent to this device.
30 *
25 * If uhid is not available as /dev/uhid, then you can pass a different path as 31 * If uhid is not available as /dev/uhid, then you can pass a different path as
26 * first argument. 32 * first argument.
27 * If <linux/uhid.h> is not installed in /usr, then compile this with: 33 * If <linux/uhid.h> is not installed in /usr, then compile this with:
@@ -41,11 +47,12 @@
41#include <unistd.h> 47#include <unistd.h>
42#include <linux/uhid.h> 48#include <linux/uhid.h>
43 49
44/* HID Report Desciptor 50/*
45 * We emulate a basic 3 button mouse with wheel. This is the report-descriptor 51 * HID Report Desciptor
46 * as the kernel will parse it: 52 * We emulate a basic 3 button mouse with wheel and 3 keyboard LEDs. This is
53 * the report-descriptor as the kernel will parse it:
47 * 54 *
48 * INPUT[INPUT] 55 * INPUT(1)[INPUT]
49 * Field(0) 56 * Field(0)
50 * Physical(GenericDesktop.Pointer) 57 * Physical(GenericDesktop.Pointer)
51 * Application(GenericDesktop.Mouse) 58 * Application(GenericDesktop.Mouse)
@@ -72,6 +79,19 @@
72 * Report Count(3) 79 * Report Count(3)
73 * Report Offset(8) 80 * Report Offset(8)
74 * Flags( Variable Relative ) 81 * Flags( Variable Relative )
82 * OUTPUT(2)[OUTPUT]
83 * Field(0)
84 * Application(GenericDesktop.Keyboard)
85 * Usage(3)
86 * LED.NumLock
87 * LED.CapsLock
88 * LED.ScrollLock
89 * Logical Minimum(0)
90 * Logical Maximum(1)
91 * Report Size(1)
92 * Report Count(3)
93 * Report Offset(0)
94 * Flags( Variable Absolute )
75 * 95 *
76 * This is the mapping that we expect: 96 * This is the mapping that we expect:
77 * Button.0001 ---> Key.LeftBtn 97 * Button.0001 ---> Key.LeftBtn
@@ -80,19 +100,59 @@
80 * GenericDesktop.X ---> Relative.X 100 * GenericDesktop.X ---> Relative.X
81 * GenericDesktop.Y ---> Relative.Y 101 * GenericDesktop.Y ---> Relative.Y
82 * GenericDesktop.Wheel ---> Relative.Wheel 102 * GenericDesktop.Wheel ---> Relative.Wheel
103 * LED.NumLock ---> LED.NumLock
104 * LED.CapsLock ---> LED.CapsLock
105 * LED.ScrollLock ---> LED.ScrollLock
83 * 106 *
84 * This information can be verified by reading /sys/kernel/debug/hid/<dev>/rdesc 107 * This information can be verified by reading /sys/kernel/debug/hid/<dev>/rdesc
85 * This file should print the same information as showed above. 108 * This file should print the same information as showed above.
86 */ 109 */
87 110
88static unsigned char rdesc[] = { 111static unsigned char rdesc[] = {
89 0x05, 0x01, 0x09, 0x02, 0xa1, 0x01, 0x09, 0x01, 112 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
90 0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03, 113 0x09, 0x02, /* USAGE (Mouse) */
91 0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, 114 0xa1, 0x01, /* COLLECTION (Application) */
92 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01, 115 0x09, 0x01, /* USAGE (Pointer) */
93 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x09, 0x38, 116 0xa1, 0x00, /* COLLECTION (Physical) */
94 0x15, 0x80, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x03, 117 0x85, 0x01, /* REPORT_ID (1) */
95 0x81, 0x06, 0xc0, 0xc0, 118 0x05, 0x09, /* USAGE_PAGE (Button) */
119 0x19, 0x01, /* USAGE_MINIMUM (Button 1) */
120 0x29, 0x03, /* USAGE_MAXIMUM (Button 3) */
121 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
122 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
123 0x95, 0x03, /* REPORT_COUNT (3) */
124 0x75, 0x01, /* REPORT_SIZE (1) */
125 0x81, 0x02, /* INPUT (Data,Var,Abs) */
126 0x95, 0x01, /* REPORT_COUNT (1) */
127 0x75, 0x05, /* REPORT_SIZE (5) */
128 0x81, 0x01, /* INPUT (Cnst,Var,Abs) */
129 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
130 0x09, 0x30, /* USAGE (X) */
131 0x09, 0x31, /* USAGE (Y) */
132 0x09, 0x38, /* USAGE (WHEEL) */
133 0x15, 0x81, /* LOGICAL_MINIMUM (-127) */
134 0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */
135 0x75, 0x08, /* REPORT_SIZE (8) */
136 0x95, 0x03, /* REPORT_COUNT (3) */
137 0x81, 0x06, /* INPUT (Data,Var,Rel) */
138 0xc0, /* END_COLLECTION */
139 0xc0, /* END_COLLECTION */
140 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
141 0x09, 0x06, /* USAGE (Keyboard) */
142 0xa1, 0x01, /* COLLECTION (Application) */
143 0x85, 0x02, /* REPORT_ID (2) */
144 0x05, 0x08, /* USAGE_PAGE (Led) */
145 0x19, 0x01, /* USAGE_MINIMUM (1) */
146 0x29, 0x03, /* USAGE_MAXIMUM (3) */
147 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
148 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
149 0x95, 0x03, /* REPORT_COUNT (3) */
150 0x75, 0x01, /* REPORT_SIZE (1) */
151 0x91, 0x02, /* Output (Data,Var,Abs) */
152 0x95, 0x01, /* REPORT_COUNT (1) */
153 0x75, 0x05, /* REPORT_SIZE (5) */
154 0x91, 0x01, /* Output (Cnst,Var,Abs) */
155 0xc0, /* END_COLLECTION */
96}; 156};
97 157
98static int uhid_write(int fd, const struct uhid_event *ev) 158static int uhid_write(int fd, const struct uhid_event *ev)
@@ -140,6 +200,27 @@ static void destroy(int fd)
140 uhid_write(fd, &ev); 200 uhid_write(fd, &ev);
141} 201}
142 202
203/* This parses raw output reports sent by the kernel to the device. A normal
204 * uhid program shouldn't do this but instead just forward the raw report.
205 * However, for ducomentational purposes, we try to detect LED events here and
206 * print debug messages for it. */
207static void handle_output(struct uhid_event *ev)
208{
209 /* LED messages are adverised via OUTPUT reports; ignore the rest */
210 if (ev->u.output.rtype != UHID_OUTPUT_REPORT)
211 return;
212 /* LED reports have length 2 bytes */
213 if (ev->u.output.size != 2)
214 return;
215 /* first byte is report-id which is 0x02 for LEDs in our rdesc */
216 if (ev->u.output.data[0] != 0x2)
217 return;
218
219 /* print flags payload */
220 fprintf(stderr, "LED output report received with flags %x\n",
221 ev->u.output.data[1]);
222}
223
143static int event(int fd) 224static int event(int fd)
144{ 225{
145 struct uhid_event ev; 226 struct uhid_event ev;
@@ -174,6 +255,7 @@ static int event(int fd)
174 break; 255 break;
175 case UHID_OUTPUT: 256 case UHID_OUTPUT:
176 fprintf(stderr, "UHID_OUTPUT from uhid-dev\n"); 257 fprintf(stderr, "UHID_OUTPUT from uhid-dev\n");
258 handle_output(&ev);
177 break; 259 break;
178 case UHID_OUTPUT_EV: 260 case UHID_OUTPUT_EV:
179 fprintf(stderr, "UHID_OUTPUT_EV from uhid-dev\n"); 261 fprintf(stderr, "UHID_OUTPUT_EV from uhid-dev\n");
@@ -198,18 +280,19 @@ static int send_event(int fd)
198 280
199 memset(&ev, 0, sizeof(ev)); 281 memset(&ev, 0, sizeof(ev));
200 ev.type = UHID_INPUT; 282 ev.type = UHID_INPUT;
201 ev.u.input.size = 4; 283 ev.u.input.size = 5;
202 284
285 ev.u.input.data[0] = 0x1;
203 if (btn1_down) 286 if (btn1_down)
204 ev.u.input.data[0] |= 0x1; 287 ev.u.input.data[1] |= 0x1;
205 if (btn2_down) 288 if (btn2_down)
206 ev.u.input.data[0] |= 0x2; 289 ev.u.input.data[1] |= 0x2;
207 if (btn3_down) 290 if (btn3_down)
208 ev.u.input.data[0] |= 0x4; 291 ev.u.input.data[1] |= 0x4;
209 292
210 ev.u.input.data[1] = abs_hor; 293 ev.u.input.data[2] = abs_hor;
211 ev.u.input.data[2] = abs_ver; 294 ev.u.input.data[3] = abs_ver;
212 ev.u.input.data[3] = wheel; 295 ev.u.input.data[4] = wheel;
213 296
214 return uhid_write(fd, &ev); 297 return uhid_write(fd, &ev);
215} 298}