aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-04-14 12:25:26 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-14 12:25:26 -0400
commit8de29a35dc840a05e451ad035bcb06e21ccf605f (patch)
treef887a98818ef7dd56c0c64c95039377931dcc903 /drivers/hid
parent31f7dc796998d2967e999a0f9229d8a50c7b348d (diff)
parent2e455c27bddbf8cf6d1039daea40de8e6865c453 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
Pull HID updates from Jiri Kosina: - quite a few firmware fixes for RMI driver by Andrew Duggan - huion and uclogic drivers have been substantially overlaping in functionality laterly. This redundancy is fixed by hid-huion driver being merged into hid-uclogic; work done by Benjamin Tissoires and Nikolai Kondrashov - i2c-hid now supports ACPI GPIO interrupts; patch from Mika Westerberg - Some of the quirks, that got separated into individual drivers, have historically had EXPERT dependency. As HID subsystem matured (as well as the individual drivers), this made less and less sense. This dependency is now being removed by patch from Jean Delvare - Logitech lg4ff driver received a couple of improvements for mode switching, by Michal MalĂ˝ - multitouch driver now supports clickpads, patches by Benjamin Tissoires and Seth Forshee - hid-sensor framework received a substantial update; namely support for Custom and Generic pages is being added; work done by Srinivas Pandruvada - wacom driver received substantial update; it now supports i2c-conntected devices (Mika Westerberg), Bamboo PADs are now properly supported (Benjamin Tissoires), much improved battery reporting (Jason Gerecke) and pen proximity cleanups (Ping Cheng) - small assorted fixes and device ID additions * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid: (68 commits) HID: sensor: Update document for custom sensor HID: sensor: Custom and Generic sensor support HID: debug: fix error handling in hid_debug_events_read() Input - mt: Fix input_mt_get_slot_by_key HID: logitech-hidpp: fix error return code HID: wacom: Add support for Cintiq 13HD Touch HID: logitech-hidpp: add a module parameter to keep firmware gestures HID: usbhid: yet another mouse with ALWAYS_POLL HID: usbhid: more mice with ALWAYS_POLL HID: wacom: set stylus_in_proximity before checking touch_down HID: wacom: use wacom_wac_finger_count_touches to set touch_down HID: wacom: remove hardcoded WACOM_QUIRK_MULTI_INPUT HID: pidff: effect can't be NULL HID: add quirk for PIXART OEM mouse used by HP HID: add HP OEM mouse to quirk ALWAYS_POLL HID: wacom: ask for a in-prox report when it was missed HID: hid-sensor-hub: Fix sparse warning HID: hid-sensor-hub: fix attribute read for logical usage id HID: plantronics: fix Kconfig default HID: pidff: support more than one concurrent effect ...
Diffstat (limited to 'drivers/hid')
-rw-r--r--drivers/hid/Kconfig48
-rw-r--r--drivers/hid/Makefile2
-rw-r--r--drivers/hid/hid-core.c21
-rw-r--r--drivers/hid/hid-debug.c4
-rw-r--r--drivers/hid/hid-huion.c290
-rw-r--r--drivers/hid/hid-ids.h10
-rw-r--r--drivers/hid/hid-input.c23
-rw-r--r--drivers/hid/hid-kye.c140
-rw-r--r--drivers/hid/hid-lg.c7
-rw-r--r--drivers/hid/hid-lg.h12
-rw-r--r--drivers/hid/hid-lg4ff.c600
-rw-r--r--drivers/hid/hid-lg4ff.h18
-rw-r--r--drivers/hid/hid-logitech-hidpp.c11
-rw-r--r--drivers/hid/hid-multitouch.c26
-rw-r--r--drivers/hid/hid-rmi.c177
-rw-r--r--drivers/hid/hid-sensor-custom.c849
-rw-r--r--drivers/hid/hid-sensor-hub.c198
-rw-r--r--drivers/hid/hid-sony.c31
-rw-r--r--drivers/hid/hid-steelseries.c1
-rw-r--r--drivers/hid/hid-uclogic.c325
-rw-r--r--drivers/hid/i2c-hid/i2c-hid.c68
-rw-r--r--drivers/hid/usbhid/hid-pidff.c6
-rw-r--r--drivers/hid/usbhid/hid-quirks.c12
-rw-r--r--drivers/hid/wacom.h8
-rw-r--r--drivers/hid/wacom_sys.c97
-rw-r--r--drivers/hid/wacom_wac.c406
-rw-r--r--drivers/hid/wacom_wac.h17
27 files changed, 2740 insertions, 667 deletions
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 152b006833cd..15338afdf7f9 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -92,7 +92,7 @@ menu "Special HID drivers"
92 depends on HID 92 depends on HID
93 93
94config HID_A4TECH 94config HID_A4TECH
95 tristate "A4 tech mice" if EXPERT 95 tristate "A4 tech mice"
96 depends on HID 96 depends on HID
97 default !EXPERT 97 default !EXPERT
98 ---help--- 98 ---help---
@@ -113,7 +113,7 @@ config HID_ACRUX_FF
113 game controllers. 113 game controllers.
114 114
115config HID_APPLE 115config HID_APPLE
116 tristate "Apple {i,Power,Mac}Books" if EXPERT 116 tristate "Apple {i,Power,Mac}Books"
117 depends on HID 117 depends on HID
118 default !EXPERT 118 default !EXPERT
119 ---help--- 119 ---help---
@@ -141,7 +141,7 @@ config HID_AUREAL
141 Support for Aureal Cy se W-01RN Remote Controller and other Aureal derived remotes. 141 Support for Aureal Cy se W-01RN Remote Controller and other Aureal derived remotes.
142 142
143config HID_BELKIN 143config HID_BELKIN
144 tristate "Belkin Flip KVM and Wireless keyboard" if EXPERT 144 tristate "Belkin Flip KVM and Wireless keyboard"
145 depends on HID 145 depends on HID
146 default !EXPERT 146 default !EXPERT
147 ---help--- 147 ---help---
@@ -158,14 +158,14 @@ config HID_BETOP_FF
158 - BETOP 2185 PC & BFM MODE 158 - BETOP 2185 PC & BFM MODE
159 159
160config HID_CHERRY 160config HID_CHERRY
161 tristate "Cherry Cymotion keyboard" if EXPERT 161 tristate "Cherry Cymotion keyboard"
162 depends on HID 162 depends on HID
163 default !EXPERT 163 default !EXPERT
164 ---help--- 164 ---help---
165 Support for Cherry Cymotion keyboard. 165 Support for Cherry Cymotion keyboard.
166 166
167config HID_CHICONY 167config HID_CHICONY
168 tristate "Chicony Tactical pad" if EXPERT 168 tristate "Chicony Tactical pad"
169 depends on HID 169 depends on HID
170 default !EXPERT 170 default !EXPERT
171 ---help--- 171 ---help---
@@ -196,7 +196,7 @@ config HID_CP2112
196 customizable USB descriptor fields are exposed as sysfs attributes. 196 customizable USB descriptor fields are exposed as sysfs attributes.
197 197
198config HID_CYPRESS 198config HID_CYPRESS
199 tristate "Cypress mouse and barcode readers" if EXPERT 199 tristate "Cypress mouse and barcode readers"
200 depends on HID 200 depends on HID
201 default !EXPERT 201 default !EXPERT
202 ---help--- 202 ---help---
@@ -245,7 +245,7 @@ config HID_ELO
245 different devices than those handled by CONFIG_TOUCHSCREEN_USB_ELO. 245 different devices than those handled by CONFIG_TOUCHSCREEN_USB_ELO.
246 246
247config HID_EZKEY 247config HID_EZKEY
248 tristate "Ezkey BTC 8193 keyboard" if EXPERT 248 tristate "Ezkey BTC 8193 keyboard"
249 depends on HID 249 depends on HID
250 default !EXPERT 250 default !EXPERT
251 ---help--- 251 ---help---
@@ -286,12 +286,6 @@ config HID_GT683R
286 Currently the following devices are know to be supported: 286 Currently the following devices are know to be supported:
287 - MSI GT683R 287 - MSI GT683R
288 288
289config HID_HUION
290 tristate "Huion tablets"
291 depends on USB_HID
292 ---help---
293 Support for Huion 580 tablet.
294
295config HID_KEYTOUCH 289config HID_KEYTOUCH
296 tristate "Keytouch HID devices" 290 tristate "Keytouch HID devices"
297 depends on HID 291 depends on HID
@@ -312,9 +306,9 @@ config HID_KYE
312 306
313config HID_UCLOGIC 307config HID_UCLOGIC
314 tristate "UC-Logic" 308 tristate "UC-Logic"
315 depends on HID 309 depends on USB_HID
316 ---help--- 310 ---help---
317 Support for UC-Logic tablets. 311 Support for UC-Logic and Huion tablets.
318 312
319config HID_WALTOP 313config HID_WALTOP
320 tristate "Waltop" 314 tristate "Waltop"
@@ -344,7 +338,7 @@ config HID_TWINHAN
344 Support for Twinhan IR remote control. 338 Support for Twinhan IR remote control.
345 339
346config HID_KENSINGTON 340config HID_KENSINGTON
347 tristate "Kensington Slimblade Trackball" if EXPERT 341 tristate "Kensington Slimblade Trackball"
348 depends on HID 342 depends on HID
349 default !EXPERT 343 default !EXPERT
350 ---help--- 344 ---help---
@@ -372,7 +366,7 @@ config HID_LENOVO
372 - ThinkPad Compact USB Keyboard with TrackPoint (supports Fn keys) 366 - ThinkPad Compact USB Keyboard with TrackPoint (supports Fn keys)
373 367
374config HID_LOGITECH 368config HID_LOGITECH
375 tristate "Logitech devices" if EXPERT 369 tristate "Logitech devices"
376 depends on HID 370 depends on HID
377 default !EXPERT 371 default !EXPERT
378 ---help--- 372 ---help---
@@ -461,14 +455,14 @@ config HID_MAGICMOUSE
461 Apple Wireless "Magic" Mouse and the Apple Wireless "Magic" Trackpad. 455 Apple Wireless "Magic" Mouse and the Apple Wireless "Magic" Trackpad.
462 456
463config HID_MICROSOFT 457config HID_MICROSOFT
464 tristate "Microsoft non-fully HID-compliant devices" if EXPERT 458 tristate "Microsoft non-fully HID-compliant devices"
465 depends on HID 459 depends on HID
466 default !EXPERT 460 default !EXPERT
467 ---help--- 461 ---help---
468 Support for Microsoft devices that are not fully compliant with HID standard. 462 Support for Microsoft devices that are not fully compliant with HID standard.
469 463
470config HID_MONTEREY 464config HID_MONTEREY
471 tristate "Monterey Genius KB29E keyboard" if EXPERT 465 tristate "Monterey Genius KB29E keyboard"
472 depends on HID 466 depends on HID
473 default !EXPERT 467 default !EXPERT
474 ---help--- 468 ---help---
@@ -638,7 +632,6 @@ config HID_PICOLCD_CIR
638 632
639config HID_PLANTRONICS 633config HID_PLANTRONICS
640 tristate "Plantronics USB HID Driver" 634 tristate "Plantronics USB HID Driver"
641 default !EXPERT
642 depends on HID 635 depends on HID
643 ---help--- 636 ---help---
644 Provides HID support for Plantronics telephony devices. 637 Provides HID support for Plantronics telephony devices.
@@ -885,6 +878,21 @@ config HID_SENSOR_HUB
885 for events and handle data streams. Each sensor driver can format 878 for events and handle data streams. Each sensor driver can format
886 data and present to user mode using input or IIO interface. 879 data and present to user mode using input or IIO interface.
887 880
881config HID_SENSOR_CUSTOM_SENSOR
882 tristate "HID Sensors hub custom sensor support"
883 depends on HID_SENSOR_HUB
884 default n
885 ---help---
886 HID Sensor hub specification allows definition of some custom and
887 generic sensors. Unlike other HID sensors, they can't be exported
888 via Linux IIO because of custom fields. This is up to the manufacturer
889 to decide how to interpret these special sensor ids and process in
890 the user space. Currently some manufacturers are using these ids for
891 sensor calibration and debugging other sensors. Manufacturers
892 should't use these special custom sensor ids to export any of the
893 standard sensors.
894 Select this config option for custom/generic sensor support.
895
888endmenu 896endmenu
889 897
890endif # HID 898endif # HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 6f19958dfc38..e4a21dfd7ef3 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -41,7 +41,6 @@ obj-$(CONFIG_HID_GYRATION) += hid-gyration.o
41obj-$(CONFIG_HID_HOLTEK) += hid-holtek-kbd.o 41obj-$(CONFIG_HID_HOLTEK) += hid-holtek-kbd.o
42obj-$(CONFIG_HID_HOLTEK) += hid-holtek-mouse.o 42obj-$(CONFIG_HID_HOLTEK) += hid-holtek-mouse.o
43obj-$(CONFIG_HID_HOLTEK) += hid-holtekff.o 43obj-$(CONFIG_HID_HOLTEK) += hid-holtekff.o
44obj-$(CONFIG_HID_HUION) += hid-huion.o
45obj-$(CONFIG_HID_HYPERV_MOUSE) += hid-hyperv.o 44obj-$(CONFIG_HID_HYPERV_MOUSE) += hid-hyperv.o
46obj-$(CONFIG_HID_ICADE) += hid-icade.o 45obj-$(CONFIG_HID_ICADE) += hid-icade.o
47obj-$(CONFIG_HID_KENSINGTON) += hid-kensington.o 46obj-$(CONFIG_HID_KENSINGTON) += hid-kensington.o
@@ -101,6 +100,7 @@ obj-$(CONFIG_HID_WACOM) += wacom.o
101obj-$(CONFIG_HID_WALTOP) += hid-waltop.o 100obj-$(CONFIG_HID_WALTOP) += hid-waltop.o
102obj-$(CONFIG_HID_WIIMOTE) += hid-wiimote.o 101obj-$(CONFIG_HID_WIIMOTE) += hid-wiimote.o
103obj-$(CONFIG_HID_SENSOR_HUB) += hid-sensor-hub.o 102obj-$(CONFIG_HID_SENSOR_HUB) += hid-sensor-hub.o
103obj-$(CONFIG_HID_SENSOR_CUSTOM_SENSOR) += hid-sensor-custom.o
104 104
105obj-$(CONFIG_USB_HID) += usbhid/ 105obj-$(CONFIG_USB_HID) += usbhid/
106obj-$(CONFIG_USB_MOUSE) += usbhid/ 106obj-$(CONFIG_USB_MOUSE) += usbhid/
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 56ce8c2b5530..722a925795a2 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1562,12 +1562,26 @@ read_report_descriptor(struct file *filp, struct kobject *kobj,
1562 return count; 1562 return count;
1563} 1563}
1564 1564
1565static ssize_t
1566show_country(struct device *dev, struct device_attribute *attr,
1567 char *buf)
1568{
1569 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1570
1571 return sprintf(buf, "%02x\n", hdev->country & 0xff);
1572}
1573
1565static struct bin_attribute dev_bin_attr_report_desc = { 1574static struct bin_attribute dev_bin_attr_report_desc = {
1566 .attr = { .name = "report_descriptor", .mode = 0444 }, 1575 .attr = { .name = "report_descriptor", .mode = 0444 },
1567 .read = read_report_descriptor, 1576 .read = read_report_descriptor,
1568 .size = HID_MAX_DESCRIPTOR_SIZE, 1577 .size = HID_MAX_DESCRIPTOR_SIZE,
1569}; 1578};
1570 1579
1580static struct device_attribute dev_attr_country = {
1581 .attr = { .name = "country", .mode = 0444 },
1582 .show = show_country,
1583};
1584
1571int hid_connect(struct hid_device *hdev, unsigned int connect_mask) 1585int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
1572{ 1586{
1573 static const char *types[] = { "Device", "Pointer", "Mouse", "Device", 1587 static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
@@ -1646,6 +1660,11 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
1646 bus = "<UNKNOWN>"; 1660 bus = "<UNKNOWN>";
1647 } 1661 }
1648 1662
1663 ret = device_create_file(&hdev->dev, &dev_attr_country);
1664 if (ret)
1665 hid_warn(hdev,
1666 "can't create sysfs country code attribute err: %d\n", ret);
1667
1649 ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc); 1668 ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
1650 if (ret) 1669 if (ret)
1651 hid_warn(hdev, 1670 hid_warn(hdev,
@@ -1661,6 +1680,7 @@ EXPORT_SYMBOL_GPL(hid_connect);
1661 1680
1662void hid_disconnect(struct hid_device *hdev) 1681void hid_disconnect(struct hid_device *hdev)
1663{ 1682{
1683 device_remove_file(&hdev->dev, &dev_attr_country);
1664 device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc); 1684 device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
1665 if (hdev->claimed & HID_CLAIMED_INPUT) 1685 if (hdev->claimed & HID_CLAIMED_INPUT)
1666 hidinput_disconnect(hdev); 1686 hidinput_disconnect(hdev);
@@ -1824,6 +1844,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1824 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) }, 1844 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
1825 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2) }, 1845 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2) },
1826 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) }, 1846 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) },
1847 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_PENSKETCH_M912) },
1827 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) }, 1848 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
1828 { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) }, 1849 { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
1829#if IS_ENABLED(CONFIG_HID_LENOVO) 1850#if IS_ENABLED(CONFIG_HID_LENOVO)
diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index 8bf61d295ffd..c785095f9f2c 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -165,6 +165,7 @@ static const struct hid_usage_entry hid_usage_table[] = {
165 {0, 0x53, "DeviceIndex"}, 165 {0, 0x53, "DeviceIndex"},
166 {0, 0x54, "ContactCount"}, 166 {0, 0x54, "ContactCount"},
167 {0, 0x55, "ContactMaximumNumber"}, 167 {0, 0x55, "ContactMaximumNumber"},
168 {0, 0x59, "ButtonType"},
168 {0, 0x5A, "SecondaryBarrelSwitch"}, 169 {0, 0x5A, "SecondaryBarrelSwitch"},
169 {0, 0x5B, "TransducerSerialNumber"}, 170 {0, 0x5B, "TransducerSerialNumber"},
170 { 15, 0, "PhysicalInterfaceDevice" }, 171 { 15, 0, "PhysicalInterfaceDevice" },
@@ -1127,7 +1128,8 @@ static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
1127 1128
1128 if (!list->hdev || !list->hdev->debug) { 1129 if (!list->hdev || !list->hdev->debug) {
1129 ret = -EIO; 1130 ret = -EIO;
1130 break; 1131 set_current_state(TASK_RUNNING);
1132 goto out;
1131 } 1133 }
1132 1134
1133 /* allow O_NONBLOCK from other threads */ 1135 /* allow O_NONBLOCK from other threads */
diff --git a/drivers/hid/hid-huion.c b/drivers/hid/hid-huion.c
deleted file mode 100644
index 61b68ca27790..000000000000
--- a/drivers/hid/hid-huion.c
+++ /dev/null
@@ -1,290 +0,0 @@
1/*
2 * HID driver for Huion devices not fully compliant with HID standard
3 *
4 * Copyright (c) 2013 Martin Rusko
5 * Copyright (c) 2014 Nikolai Kondrashov
6 */
7
8/*
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 */
14
15#include <linux/device.h>
16#include <linux/hid.h>
17#include <linux/module.h>
18#include <linux/usb.h>
19#include <asm/unaligned.h>
20#include "usbhid/usbhid.h"
21
22#include "hid-ids.h"
23
24/* Report descriptor template placeholder head */
25#define HUION_PH_HEAD 0xFE, 0xED, 0x1D
26
27/* Report descriptor template placeholder IDs */
28enum huion_ph_id {
29 HUION_PH_ID_X_LM,
30 HUION_PH_ID_X_PM,
31 HUION_PH_ID_Y_LM,
32 HUION_PH_ID_Y_PM,
33 HUION_PH_ID_PRESSURE_LM,
34 HUION_PH_ID_NUM
35};
36
37/* Report descriptor template placeholder */
38#define HUION_PH(_ID) HUION_PH_HEAD, HUION_PH_ID_##_ID
39
40/* Fixed report descriptor template */
41static const __u8 huion_tablet_rdesc_template[] = {
42 0x05, 0x0D, /* Usage Page (Digitizer), */
43 0x09, 0x02, /* Usage (Pen), */
44 0xA1, 0x01, /* Collection (Application), */
45 0x85, 0x07, /* Report ID (7), */
46 0x09, 0x20, /* Usage (Stylus), */
47 0xA0, /* Collection (Physical), */
48 0x14, /* Logical Minimum (0), */
49 0x25, 0x01, /* Logical Maximum (1), */
50 0x75, 0x01, /* Report Size (1), */
51 0x09, 0x42, /* Usage (Tip Switch), */
52 0x09, 0x44, /* Usage (Barrel Switch), */
53 0x09, 0x46, /* Usage (Tablet Pick), */
54 0x95, 0x03, /* Report Count (3), */
55 0x81, 0x02, /* Input (Variable), */
56 0x95, 0x03, /* Report Count (3), */
57 0x81, 0x03, /* Input (Constant, Variable), */
58 0x09, 0x32, /* Usage (In Range), */
59 0x95, 0x01, /* Report Count (1), */
60 0x81, 0x02, /* Input (Variable), */
61 0x95, 0x01, /* Report Count (1), */
62 0x81, 0x03, /* Input (Constant, Variable), */
63 0x75, 0x10, /* Report Size (16), */
64 0x95, 0x01, /* Report Count (1), */
65 0xA4, /* Push, */
66 0x05, 0x01, /* Usage Page (Desktop), */
67 0x65, 0x13, /* Unit (Inch), */
68 0x55, 0xFD, /* Unit Exponent (-3), */
69 0x34, /* Physical Minimum (0), */
70 0x09, 0x30, /* Usage (X), */
71 0x27, HUION_PH(X_LM), /* Logical Maximum (PLACEHOLDER), */
72 0x47, HUION_PH(X_PM), /* Physical Maximum (PLACEHOLDER), */
73 0x81, 0x02, /* Input (Variable), */
74 0x09, 0x31, /* Usage (Y), */
75 0x27, HUION_PH(Y_LM), /* Logical Maximum (PLACEHOLDER), */
76 0x47, HUION_PH(Y_PM), /* Physical Maximum (PLACEHOLDER), */
77 0x81, 0x02, /* Input (Variable), */
78 0xB4, /* Pop, */
79 0x09, 0x30, /* Usage (Tip Pressure), */
80 0x27,
81 HUION_PH(PRESSURE_LM), /* Logical Maximum (PLACEHOLDER), */
82 0x81, 0x02, /* Input (Variable), */
83 0xC0, /* End Collection, */
84 0xC0 /* End Collection */
85};
86
87/* Parameter indices */
88enum huion_prm {
89 HUION_PRM_X_LM = 1,
90 HUION_PRM_Y_LM = 2,
91 HUION_PRM_PRESSURE_LM = 4,
92 HUION_PRM_RESOLUTION = 5,
93 HUION_PRM_NUM
94};
95
96/* Driver data */
97struct huion_drvdata {
98 __u8 *rdesc;
99 unsigned int rsize;
100};
101
102static __u8 *huion_report_fixup(struct hid_device *hdev, __u8 *rdesc,
103 unsigned int *rsize)
104{
105 struct huion_drvdata *drvdata = hid_get_drvdata(hdev);
106 switch (hdev->product) {
107 case USB_DEVICE_ID_HUION_TABLET:
108 if (drvdata->rdesc != NULL) {
109 rdesc = drvdata->rdesc;
110 *rsize = drvdata->rsize;
111 }
112 break;
113 }
114 return rdesc;
115}
116
117/**
118 * Enable fully-functional tablet mode and determine device parameters.
119 *
120 * @hdev: HID device
121 */
122static int huion_tablet_enable(struct hid_device *hdev)
123{
124 int rc;
125 struct usb_device *usb_dev = hid_to_usb_dev(hdev);
126 struct huion_drvdata *drvdata = hid_get_drvdata(hdev);
127 __le16 *buf = NULL;
128 size_t len;
129 s32 params[HUION_PH_ID_NUM];
130 s32 resolution;
131 __u8 *p;
132 s32 v;
133
134 /*
135 * Read string descriptor containing tablet parameters. The specific
136 * string descriptor and data were discovered by sniffing the Windows
137 * driver traffic.
138 * NOTE: This enables fully-functional tablet mode.
139 */
140 len = HUION_PRM_NUM * sizeof(*buf);
141 buf = kmalloc(len, GFP_KERNEL);
142 if (buf == NULL) {
143 hid_err(hdev, "failed to allocate parameter buffer\n");
144 rc = -ENOMEM;
145 goto cleanup;
146 }
147 rc = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
148 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
149 (USB_DT_STRING << 8) + 0x64,
150 0x0409, buf, len,
151 USB_CTRL_GET_TIMEOUT);
152 if (rc == -EPIPE) {
153 hid_err(hdev, "device parameters not found\n");
154 rc = -ENODEV;
155 goto cleanup;
156 } else if (rc < 0) {
157 hid_err(hdev, "failed to get device parameters: %d\n", rc);
158 rc = -ENODEV;
159 goto cleanup;
160 } else if (rc != len) {
161 hid_err(hdev, "invalid device parameters\n");
162 rc = -ENODEV;
163 goto cleanup;
164 }
165
166 /* Extract device parameters */
167 params[HUION_PH_ID_X_LM] = le16_to_cpu(buf[HUION_PRM_X_LM]);
168 params[HUION_PH_ID_Y_LM] = le16_to_cpu(buf[HUION_PRM_Y_LM]);
169 params[HUION_PH_ID_PRESSURE_LM] =
170 le16_to_cpu(buf[HUION_PRM_PRESSURE_LM]);
171 resolution = le16_to_cpu(buf[HUION_PRM_RESOLUTION]);
172 if (resolution == 0) {
173 params[HUION_PH_ID_X_PM] = 0;
174 params[HUION_PH_ID_Y_PM] = 0;
175 } else {
176 params[HUION_PH_ID_X_PM] = params[HUION_PH_ID_X_LM] *
177 1000 / resolution;
178 params[HUION_PH_ID_Y_PM] = params[HUION_PH_ID_Y_LM] *
179 1000 / resolution;
180 }
181
182 /* Allocate fixed report descriptor */
183 drvdata->rdesc = devm_kmalloc(&hdev->dev,
184 sizeof(huion_tablet_rdesc_template),
185 GFP_KERNEL);
186 if (drvdata->rdesc == NULL) {
187 hid_err(hdev, "failed to allocate fixed rdesc\n");
188 rc = -ENOMEM;
189 goto cleanup;
190 }
191 drvdata->rsize = sizeof(huion_tablet_rdesc_template);
192
193 /* Format fixed report descriptor */
194 memcpy(drvdata->rdesc, huion_tablet_rdesc_template,
195 drvdata->rsize);
196 for (p = drvdata->rdesc;
197 p <= drvdata->rdesc + drvdata->rsize - 4;) {
198 if (p[0] == 0xFE && p[1] == 0xED && p[2] == 0x1D &&
199 p[3] < sizeof(params)) {
200 v = params[p[3]];
201 put_unaligned(cpu_to_le32(v), (s32 *)p);
202 p += 4;
203 } else {
204 p++;
205 }
206 }
207
208 rc = 0;
209
210cleanup:
211 kfree(buf);
212 return rc;
213}
214
215static int huion_probe(struct hid_device *hdev, const struct hid_device_id *id)
216{
217 int rc;
218 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
219 struct huion_drvdata *drvdata;
220
221 /* Allocate and assign driver data */
222 drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL);
223 if (drvdata == NULL) {
224 hid_err(hdev, "failed to allocate driver data\n");
225 return -ENOMEM;
226 }
227 hid_set_drvdata(hdev, drvdata);
228
229 switch (id->product) {
230 case USB_DEVICE_ID_HUION_TABLET:
231 /* If this is the pen interface */
232 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
233 rc = huion_tablet_enable(hdev);
234 if (rc) {
235 hid_err(hdev, "tablet enabling failed\n");
236 return rc;
237 }
238 }
239 break;
240 }
241
242 rc = hid_parse(hdev);
243 if (rc) {
244 hid_err(hdev, "parse failed\n");
245 return rc;
246 }
247
248 rc = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
249 if (rc) {
250 hid_err(hdev, "hw start failed\n");
251 return rc;
252 }
253
254 return 0;
255}
256
257static int huion_raw_event(struct hid_device *hdev, struct hid_report *report,
258 u8 *data, int size)
259{
260 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
261
262 /* If this is a pen input report */
263 if (intf->cur_altsetting->desc.bInterfaceNumber == 0 &&
264 report->type == HID_INPUT_REPORT &&
265 report->id == 0x07 && size >= 2)
266 /* Invert the in-range bit */
267 data[1] ^= 0x40;
268
269 return 0;
270}
271
272static const struct hid_device_id huion_devices[] = {
273 { HID_USB_DEVICE(USB_VENDOR_ID_HUION, USB_DEVICE_ID_HUION_TABLET) },
274 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_HUION_TABLET) },
275 { }
276};
277MODULE_DEVICE_TABLE(hid, huion_devices);
278
279static struct hid_driver huion_driver = {
280 .name = "huion",
281 .id_table = huion_devices,
282 .probe = huion_probe,
283 .report_fixup = huion_report_fixup,
284 .raw_event = huion_raw_event,
285};
286module_hid_driver(huion_driver);
287
288MODULE_AUTHOR("Martin Rusko");
289MODULE_DESCRIPTION("Huion HID driver");
290MODULE_LICENSE("GPL");
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 9c4786759f16..41f167e4d75f 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -459,6 +459,11 @@
459#define USB_DEVICE_ID_UGCI_FLYING 0x0020 459#define USB_DEVICE_ID_UGCI_FLYING 0x0020
460#define USB_DEVICE_ID_UGCI_FIGHTING 0x0030 460#define USB_DEVICE_ID_UGCI_FIGHTING 0x0030
461 461
462#define USB_VENDOR_ID_HP 0x03f0
463#define USB_PRODUCT_ID_HP_LOGITECH_OEM_USB_OPTICAL_MOUSE_0A4A 0x0a4a
464#define USB_PRODUCT_ID_HP_LOGITECH_OEM_USB_OPTICAL_MOUSE_0B4A 0x0b4a
465#define USB_PRODUCT_ID_HP_PIXART_OEM_USB_OPTICAL_MOUSE 0x134a
466
462#define USB_VENDOR_ID_HUION 0x256c 467#define USB_VENDOR_ID_HUION 0x256c
463#define USB_DEVICE_ID_HUION_TABLET 0x006e 468#define USB_DEVICE_ID_HUION_TABLET 0x006e
464 469
@@ -533,6 +538,7 @@
533#define USB_DEVICE_ID_KYE_MOUSEPEN_I608X 0x5011 538#define USB_DEVICE_ID_KYE_MOUSEPEN_I608X 0x5011
534#define USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2 0x501a 539#define USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2 0x501a
535#define USB_DEVICE_ID_KYE_EASYPEN_M610X 0x5013 540#define USB_DEVICE_ID_KYE_EASYPEN_M610X 0x5013
541#define USB_DEVICE_ID_KYE_PENSKETCH_M912 0x5015
536 542
537#define USB_VENDOR_ID_LABTEC 0x1020 543#define USB_VENDOR_ID_LABTEC 0x1020
538#define USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD 0x0006 544#define USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD 0x0006
@@ -591,6 +597,9 @@
591#define USB_DEVICE_ID_LOGITECH_HARMONY_FIRST 0xc110 597#define USB_DEVICE_ID_LOGITECH_HARMONY_FIRST 0xc110
592#define USB_DEVICE_ID_LOGITECH_HARMONY_LAST 0xc14f 598#define USB_DEVICE_ID_LOGITECH_HARMONY_LAST 0xc14f
593#define USB_DEVICE_ID_LOGITECH_HARMONY_PS3 0x0306 599#define USB_DEVICE_ID_LOGITECH_HARMONY_PS3 0x0306
600#define USB_DEVICE_ID_LOGITECH_MOUSE_C01A 0xc01a
601#define USB_DEVICE_ID_LOGITECH_MOUSE_C05A 0xc05a
602#define USB_DEVICE_ID_LOGITECH_MOUSE_C06A 0xc06a
594#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD 0xc20a 603#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD 0xc20a
595#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD 0xc211 604#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD 0xc211
596#define USB_DEVICE_ID_LOGITECH_EXTREME_3D 0xc215 605#define USB_DEVICE_ID_LOGITECH_EXTREME_3D 0xc215
@@ -1022,6 +1031,7 @@
1022#define USB_DEVICE_ID_ZYTRONIC_ZXY100 0x0005 1031#define USB_DEVICE_ID_ZYTRONIC_ZXY100 0x0005
1023 1032
1024#define USB_VENDOR_ID_PRIMAX 0x0461 1033#define USB_VENDOR_ID_PRIMAX 0x0461
1034#define USB_DEVICE_ID_PRIMAX_MOUSE_4D22 0x4d22
1025#define USB_DEVICE_ID_PRIMAX_KEYBOARD 0x4e05 1035#define USB_DEVICE_ID_PRIMAX_KEYBOARD 0x4e05
1026 1036
1027 1037
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 32c2da49bd5b..008e89bf6f3c 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -720,6 +720,29 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
720 } 720 }
721 break; 721 break;
722 722
723 case HID_UP_TELEPHONY:
724 switch (usage->hid & HID_USAGE) {
725 case 0x2f: map_key_clear(KEY_MICMUTE); break;
726 case 0xb0: map_key_clear(KEY_NUMERIC_0); break;
727 case 0xb1: map_key_clear(KEY_NUMERIC_1); break;
728 case 0xb2: map_key_clear(KEY_NUMERIC_2); break;
729 case 0xb3: map_key_clear(KEY_NUMERIC_3); break;
730 case 0xb4: map_key_clear(KEY_NUMERIC_4); break;
731 case 0xb5: map_key_clear(KEY_NUMERIC_5); break;
732 case 0xb6: map_key_clear(KEY_NUMERIC_6); break;
733 case 0xb7: map_key_clear(KEY_NUMERIC_7); break;
734 case 0xb8: map_key_clear(KEY_NUMERIC_8); break;
735 case 0xb9: map_key_clear(KEY_NUMERIC_9); break;
736 case 0xba: map_key_clear(KEY_NUMERIC_STAR); break;
737 case 0xbb: map_key_clear(KEY_NUMERIC_POUND); break;
738 case 0xbc: map_key_clear(KEY_NUMERIC_A); break;
739 case 0xbd: map_key_clear(KEY_NUMERIC_B); break;
740 case 0xbe: map_key_clear(KEY_NUMERIC_C); break;
741 case 0xbf: map_key_clear(KEY_NUMERIC_D); break;
742 default: goto ignore;
743 }
744 break;
745
723 case HID_UP_CONSUMER: /* USB HUT v1.12, pages 75-84 */ 746 case HID_UP_CONSUMER: /* USB HUT v1.12, pages 75-84 */
724 switch (usage->hid & HID_USAGE) { 747 switch (usage->hid & HID_USAGE) {
725 case 0x000: goto ignore; 748 case 0x000: goto ignore;
diff --git a/drivers/hid/hid-kye.c b/drivers/hid/hid-kye.c
index 158fcf577fae..32e6d8d9ded0 100644
--- a/drivers/hid/hid-kye.c
+++ b/drivers/hid/hid-kye.c
@@ -268,6 +268,137 @@ static __u8 easypen_m610x_rdesc_fixed[] = {
268 0xC0 /* End Collection */ 268 0xC0 /* End Collection */
269}; 269};
270 270
271
272/* Original PenSketch M912 report descriptor size */
273#define PENSKETCH_M912_RDESC_ORIG_SIZE 482
274
275/* Fixed PenSketch M912 report descriptor */
276static __u8 pensketch_m912_rdesc_fixed[] = {
277 0x05, 0x01, /* Usage Page (Desktop), */
278 0x08, /* Usage (00h), */
279 0xA1, 0x01, /* Collection (Application), */
280 0x85, 0x05, /* Report ID (5), */
281 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */
282 0x09, 0x01, /* Usage (01h), */
283 0x15, 0x81, /* Logical Minimum (-127), */
284 0x25, 0x7F, /* Logical Maximum (127), */
285 0x75, 0x08, /* Report Size (8), */
286 0x95, 0x07, /* Report Count (7), */
287 0xB1, 0x02, /* Feature (Variable), */
288 0xC0, /* End Collection, */
289 0x05, 0x0D, /* Usage Page (Digitizer), */
290 0x09, 0x02, /* Usage (Pen), */
291 0xA1, 0x01, /* Collection (Application), */
292 0x85, 0x10, /* Report ID (16), */
293 0x09, 0x20, /* Usage (Stylus), */
294 0xA0, /* Collection (Physical), */
295 0x09, 0x42, /* Usage (Tip Switch), */
296 0x09, 0x44, /* Usage (Barrel Switch), */
297 0x09, 0x46, /* Usage (Tablet Pick), */
298 0x14, /* Logical Minimum (0), */
299 0x25, 0x01, /* Logical Maximum (1), */
300 0x75, 0x01, /* Report Size (1), */
301 0x95, 0x03, /* Report Count (3), */
302 0x81, 0x02, /* Input (Variable), */
303 0x95, 0x04, /* Report Count (4), */
304 0x81, 0x03, /* Input (Constant, Variable), */
305 0x09, 0x32, /* Usage (In Range), */
306 0x95, 0x01, /* Report Count (1), */
307 0x81, 0x02, /* Input (Variable), */
308 0x75, 0x10, /* Report Size (16), */
309 0x95, 0x01, /* Report Count (1), */
310 0xA4, /* Push, */
311 0x05, 0x01, /* Usage Page (Desktop), */
312 0x55, 0xFD, /* Unit Exponent (-3), */
313 0x65, 0x13, /* Unit (Inch), */
314 0x14, /* Logical Minimum (0), */
315 0x34, /* Physical Minimum (0), */
316 0x09, 0x30, /* Usage (X), */
317 0x27, 0x00, 0xF0, 0x00, 0x00, /* Logical Maximum (61440), */
318 0x46, 0xE0, 0x2E, /* Physical Maximum (12000), */
319 0x81, 0x02, /* Input (Variable), */
320 0x09, 0x31, /* Usage (Y), */
321 0x27, 0x00, 0xB4, 0x00, 0x00, /* Logical Maximum (46080), */
322 0x46, 0x28, 0x23, /* Physical Maximum (9000), */
323 0x81, 0x02, /* Input (Variable), */
324 0xB4, /* Pop, */
325 0x09, 0x30, /* Usage (Tip Pressure), */
326 0x14, /* Logical Minimum (0), */
327 0x26, 0xFF, 0x07, /* Logical Maximum (2047), */
328 0x81, 0x02, /* Input (Variable), */
329 0xC0, /* End Collection, */
330 0xC0, /* End Collection, */
331 0x05, 0x0D, /* Usage Page (Digitizer), */
332 0x09, 0x21, /* Usage (Puck), */
333 0xA1, 0x01, /* Collection (Application), */
334 0x85, 0x11, /* Report ID (17), */
335 0x09, 0x21, /* Usage (Puck), */
336 0xA0, /* Collection (Physical), */
337 0x05, 0x09, /* Usage Page (Button), */
338 0x75, 0x01, /* Report Size (1), */
339 0x19, 0x01, /* Usage Minimum (01h), */
340 0x29, 0x03, /* Usage Maximum (03h), */
341 0x14, /* Logical Minimum (0), */
342 0x25, 0x01, /* Logical Maximum (1), */
343 0x95, 0x03, /* Report Count (3), */
344 0x81, 0x02, /* Input (Variable), */
345 0x95, 0x04, /* Report Count (4), */
346 0x81, 0x01, /* Input (Constant), */
347 0x95, 0x01, /* Report Count (1), */
348 0x0B, 0x32, 0x00, 0x0D, 0x00, /* Usage (Digitizer In Range), */
349 0x14, /* Logical Minimum (0), */
350 0x25, 0x01, /* Logical Maximum (1), */
351 0x81, 0x02, /* Input (Variable), */
352 0xA4, /* Push, */
353 0x05, 0x01, /* Usage Page (Desktop), */
354 0x75, 0x10, /* Report Size (16), */
355 0x95, 0x01, /* Report Count (1), */
356 0x55, 0xFD, /* Unit Exponent (-3), */
357 0x65, 0x13, /* Unit (Inch), */
358 0x14, /* Logical Minimum (0), */
359 0x34, /* Physical Minimum (0), */
360 0x09, 0x30, /* Usage (X), */
361 0x27, 0x00, 0xF0, 0x00, 0x00, /* Logical Maximum (61440), */
362 0x46, 0xE0, 0x2E, /* Physical Maximum (12000), */
363 0x81, 0x02, /* Input (Variable), */
364 0x09, 0x31, /* Usage (Y), */
365 0x27, 0x00, 0xB4, 0x00, 0x00, /* Logical Maximum (46080), */
366 0x46, 0x28, 0x23, /* Physical Maximum (9000), */
367 0x81, 0x02, /* Input (Variable), */
368 0x09, 0x38, /* Usage (Wheel), */
369 0x75, 0x08, /* Report Size (8), */
370 0x95, 0x01, /* Report Count (1), */
371 0x15, 0xFF, /* Logical Minimum (-1), */
372 0x25, 0x01, /* Logical Maximum (1), */
373 0x34, /* Physical Minimum (0), */
374 0x44, /* Physical Maximum (0), */
375 0x81, 0x06, /* Input (Variable, Relative), */
376 0xB4, /* Pop, */
377 0xC0, /* End Collection, */
378 0xC0, /* End Collection, */
379 0x05, 0x0C, /* Usage Page (Consumer), */
380 0x09, 0x01, /* Usage (Consumer Control), */
381 0xA1, 0x01, /* Collection (Application), */
382 0x85, 0x12, /* Report ID (18), */
383 0x14, /* Logical Minimum (0), */
384 0x25, 0x01, /* Logical Maximum (1), */
385 0x75, 0x01, /* Report Size (1), */
386 0x95, 0x08, /* Report Count (8), */
387 0x05, 0x0C, /* Usage Page (Consumer), */
388 0x0A, 0x6A, 0x02, /* Usage (AC Delete), */
389 0x0A, 0x1A, 0x02, /* Usage (AC Undo), */
390 0x0A, 0x01, 0x02, /* Usage (AC New), */
391 0x0A, 0x2F, 0x02, /* Usage (AC Zoom), */
392 0x0A, 0x25, 0x02, /* Usage (AC Forward), */
393 0x0A, 0x24, 0x02, /* Usage (AC Back), */
394 0x0A, 0x2D, 0x02, /* Usage (AC Zoom In), */
395 0x0A, 0x2E, 0x02, /* Usage (AC Zoom Out), */
396 0x81, 0x02, /* Input (Variable), */
397 0x95, 0x30, /* Report Count (48), */
398 0x81, 0x03, /* Input (Constant, Variable), */
399 0xC0 /* End Collection */
400};
401
271static __u8 *kye_consumer_control_fixup(struct hid_device *hdev, __u8 *rdesc, 402static __u8 *kye_consumer_control_fixup(struct hid_device *hdev, __u8 *rdesc,
272 unsigned int *rsize, int offset, const char *device_name) { 403 unsigned int *rsize, int offset, const char *device_name) {
273 /* 404 /*
@@ -335,6 +466,12 @@ static __u8 *kye_report_fixup(struct hid_device *hdev, __u8 *rdesc,
335 *rsize = sizeof(easypen_m610x_rdesc_fixed); 466 *rsize = sizeof(easypen_m610x_rdesc_fixed);
336 } 467 }
337 break; 468 break;
469 case USB_DEVICE_ID_KYE_PENSKETCH_M912:
470 if (*rsize == PENSKETCH_M912_RDESC_ORIG_SIZE) {
471 rdesc = pensketch_m912_rdesc_fixed;
472 *rsize = sizeof(pensketch_m912_rdesc_fixed);
473 }
474 break;
338 case USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE: 475 case USB_DEVICE_ID_GENIUS_GILA_GAMING_MOUSE:
339 rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 104, 476 rdesc = kye_consumer_control_fixup(hdev, rdesc, rsize, 104,
340 "Genius Gila Gaming Mouse"); 477 "Genius Gila Gaming Mouse");
@@ -418,6 +555,7 @@ static int kye_probe(struct hid_device *hdev, const struct hid_device_id *id)
418 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X: 555 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X:
419 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2: 556 case USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2:
420 case USB_DEVICE_ID_KYE_EASYPEN_M610X: 557 case USB_DEVICE_ID_KYE_EASYPEN_M610X:
558 case USB_DEVICE_ID_KYE_PENSKETCH_M912:
421 ret = kye_tablet_enable(hdev); 559 ret = kye_tablet_enable(hdev);
422 if (ret) { 560 if (ret) {
423 hid_err(hdev, "tablet enabling failed\n"); 561 hid_err(hdev, "tablet enabling failed\n");
@@ -457,6 +595,8 @@ static const struct hid_device_id kye_devices[] = {
457 USB_DEVICE_ID_GENIUS_GX_IMPERATOR) }, 595 USB_DEVICE_ID_GENIUS_GX_IMPERATOR) },
458 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, 596 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
459 USB_DEVICE_ID_GENIUS_MANTICORE) }, 597 USB_DEVICE_ID_GENIUS_MANTICORE) },
598 { HID_USB_DEVICE(USB_VENDOR_ID_KYE,
599 USB_DEVICE_ID_KYE_PENSKETCH_M912) },
460 { } 600 { }
461}; 601};
462MODULE_DEVICE_TABLE(hid, kye_devices); 602MODULE_DEVICE_TABLE(hid, kye_devices);
diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c
index f91ff145db9a..b86c18e651ed 100644
--- a/drivers/hid/hid-lg.c
+++ b/drivers/hid/hid-lg.c
@@ -27,6 +27,7 @@
27#include "usbhid/usbhid.h" 27#include "usbhid/usbhid.h"
28#include "hid-ids.h" 28#include "hid-ids.h"
29#include "hid-lg.h" 29#include "hid-lg.h"
30#include "hid-lg4ff.h"
30 31
31#define LG_RDESC 0x001 32#define LG_RDESC 0x001
32#define LG_BAD_RELATIVE_KEYS 0x002 33#define LG_BAD_RELATIVE_KEYS 0x002
@@ -818,4 +819,10 @@ static struct hid_driver lg_driver = {
818}; 819};
819module_hid_driver(lg_driver); 820module_hid_driver(lg_driver);
820 821
822#ifdef CONFIG_LOGIWHEELS_FF
823int lg4ff_no_autoswitch = 0;
824module_param_named(lg4ff_no_autoswitch, lg4ff_no_autoswitch, int, S_IRUGO);
825MODULE_PARM_DESC(lg4ff_no_autoswitch, "Do not switch multimode wheels to their native mode automatically");
826#endif
827
821MODULE_LICENSE("GPL"); 828MODULE_LICENSE("GPL");
diff --git a/drivers/hid/hid-lg.h b/drivers/hid/hid-lg.h
index 142ce3f5f055..10dd8f024135 100644
--- a/drivers/hid/hid-lg.h
+++ b/drivers/hid/hid-lg.h
@@ -24,16 +24,4 @@ int lg3ff_init(struct hid_device *hdev);
24static inline int lg3ff_init(struct hid_device *hdev) { return -1; } 24static inline int lg3ff_init(struct hid_device *hdev) { return -1; }
25#endif 25#endif
26 26
27#ifdef CONFIG_LOGIWHEELS_FF
28int lg4ff_adjust_input_event(struct hid_device *hid, struct hid_field *field,
29 struct hid_usage *usage, __s32 value, struct lg_drv_data *drv_data);
30int lg4ff_init(struct hid_device *hdev);
31int lg4ff_deinit(struct hid_device *hdev);
32#else
33static inline int lg4ff_adjust_input_event(struct hid_device *hid, struct hid_field *field,
34 struct hid_usage *usage, __s32 value, struct lg_drv_data *drv_data) { return 0; }
35static inline int lg4ff_init(struct hid_device *hdev) { return -1; }
36static inline int lg4ff_deinit(struct hid_device *hdev) { return -1; }
37#endif
38
39#endif 27#endif
diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
index db0dd9b17e53..1232210b1cc5 100644
--- a/drivers/hid/hid-lg4ff.c
+++ b/drivers/hid/hid-lg4ff.c
@@ -30,23 +30,44 @@
30 30
31#include "usbhid/usbhid.h" 31#include "usbhid/usbhid.h"
32#include "hid-lg.h" 32#include "hid-lg.h"
33#include "hid-lg4ff.h"
33#include "hid-ids.h" 34#include "hid-ids.h"
34 35
35#define DFGT_REV_MAJ 0x13
36#define DFGT_REV_MIN 0x22
37#define DFGT2_REV_MIN 0x26
38#define DFP_REV_MAJ 0x11
39#define DFP_REV_MIN 0x06
40#define FFEX_REV_MAJ 0x21
41#define FFEX_REV_MIN 0x00
42#define G25_REV_MAJ 0x12
43#define G25_REV_MIN 0x22
44#define G27_REV_MAJ 0x12
45#define G27_REV_MIN 0x38
46#define G27_2_REV_MIN 0x39
47
48#define to_hid_device(pdev) container_of(pdev, struct hid_device, dev) 36#define to_hid_device(pdev) container_of(pdev, struct hid_device, dev)
49 37
38#define LG4FF_MMODE_IS_MULTIMODE 0
39#define LG4FF_MMODE_SWITCHED 1
40#define LG4FF_MMODE_NOT_MULTIMODE 2
41
42#define LG4FF_MODE_NATIVE_IDX 0
43#define LG4FF_MODE_DFEX_IDX 1
44#define LG4FF_MODE_DFP_IDX 2
45#define LG4FF_MODE_G25_IDX 3
46#define LG4FF_MODE_DFGT_IDX 4
47#define LG4FF_MODE_G27_IDX 5
48#define LG4FF_MODE_MAX_IDX 6
49
50#define LG4FF_MODE_NATIVE BIT(LG4FF_MODE_NATIVE_IDX)
51#define LG4FF_MODE_DFEX BIT(LG4FF_MODE_DFEX_IDX)
52#define LG4FF_MODE_DFP BIT(LG4FF_MODE_DFP_IDX)
53#define LG4FF_MODE_G25 BIT(LG4FF_MODE_G25_IDX)
54#define LG4FF_MODE_DFGT BIT(LG4FF_MODE_DFGT_IDX)
55#define LG4FF_MODE_G27 BIT(LG4FF_MODE_G27_IDX)
56
57#define LG4FF_DFEX_TAG "DF-EX"
58#define LG4FF_DFEX_NAME "Driving Force / Formula EX"
59#define LG4FF_DFP_TAG "DFP"
60#define LG4FF_DFP_NAME "Driving Force Pro"
61#define LG4FF_G25_TAG "G25"
62#define LG4FF_G25_NAME "G25 Racing Wheel"
63#define LG4FF_G27_TAG "G27"
64#define LG4FF_G27_NAME "G27 Racing Wheel"
65#define LG4FF_DFGT_TAG "DFGT"
66#define LG4FF_DFGT_NAME "Driving Force GT"
67
68#define LG4FF_FFEX_REV_MAJ 0x21
69#define LG4FF_FFEX_REV_MIN 0x00
70
50static void hid_lg4ff_set_range_dfp(struct hid_device *hid, u16 range); 71static void hid_lg4ff_set_range_dfp(struct hid_device *hid, u16 range);
51static void hid_lg4ff_set_range_g25(struct hid_device *hid, u16 range); 72static void hid_lg4ff_set_range_g25(struct hid_device *hid, u16 range);
52 73
@@ -59,6 +80,10 @@ struct lg4ff_device_entry {
59 __u8 led_state; 80 __u8 led_state;
60 struct led_classdev *led[5]; 81 struct led_classdev *led[5];
61#endif 82#endif
83 u32 alternate_modes;
84 const char *real_tag;
85 const char *real_name;
86 u16 real_product_id;
62 struct list_head list; 87 struct list_head list;
63 void (*set_range)(struct hid_device *hid, u16 range); 88 void (*set_range)(struct hid_device *hid, u16 range);
64}; 89};
@@ -77,6 +102,35 @@ struct lg4ff_wheel {
77 void (*set_range)(struct hid_device *hid, u16 range); 102 void (*set_range)(struct hid_device *hid, u16 range);
78}; 103};
79 104
105struct lg4ff_compat_mode_switch {
106 const __u8 cmd_count; /* Number of commands to send */
107 const __u8 cmd[];
108};
109
110struct lg4ff_wheel_ident_info {
111 const u16 mask;
112 const u16 result;
113 const u16 real_product_id;
114};
115
116struct lg4ff_wheel_ident_checklist {
117 const u32 count;
118 const struct lg4ff_wheel_ident_info *models[];
119};
120
121struct lg4ff_multimode_wheel {
122 const u16 product_id;
123 const u32 alternate_modes;
124 const char *real_tag;
125 const char *real_name;
126};
127
128struct lg4ff_alternate_mode {
129 const u16 product_id;
130 const char *tag;
131 const char *name;
132};
133
80static const struct lg4ff_wheel lg4ff_devices[] = { 134static const struct lg4ff_wheel lg4ff_devices[] = {
81 {USB_DEVICE_ID_LOGITECH_WHEEL, lg4ff_wheel_effects, 40, 270, NULL}, 135 {USB_DEVICE_ID_LOGITECH_WHEEL, lg4ff_wheel_effects, 40, 270, NULL},
82 {USB_DEVICE_ID_LOGITECH_MOMO_WHEEL, lg4ff_wheel_effects, 40, 270, NULL}, 136 {USB_DEVICE_ID_LOGITECH_MOMO_WHEEL, lg4ff_wheel_effects, 40, 270, NULL},
@@ -88,46 +142,106 @@ static const struct lg4ff_wheel lg4ff_devices[] = {
88 {USB_DEVICE_ID_LOGITECH_WII_WHEEL, lg4ff_wheel_effects, 40, 270, NULL} 142 {USB_DEVICE_ID_LOGITECH_WII_WHEEL, lg4ff_wheel_effects, 40, 270, NULL}
89}; 143};
90 144
91struct lg4ff_native_cmd { 145static const struct lg4ff_multimode_wheel lg4ff_multimode_wheels[] = {
92 const __u8 cmd_num; /* Number of commands to send */ 146 {USB_DEVICE_ID_LOGITECH_DFP_WHEEL,
93 const __u8 cmd[]; 147 LG4FF_MODE_NATIVE | LG4FF_MODE_DFP | LG4FF_MODE_DFEX,
148 LG4FF_DFP_TAG, LG4FF_DFP_NAME},
149 {USB_DEVICE_ID_LOGITECH_G25_WHEEL,
150 LG4FF_MODE_NATIVE | LG4FF_MODE_G25 | LG4FF_MODE_DFP | LG4FF_MODE_DFEX,
151 LG4FF_G25_TAG, LG4FF_G25_NAME},
152 {USB_DEVICE_ID_LOGITECH_DFGT_WHEEL,
153 LG4FF_MODE_NATIVE | LG4FF_MODE_DFGT | LG4FF_MODE_DFP | LG4FF_MODE_DFEX,
154 LG4FF_DFGT_TAG, LG4FF_DFGT_NAME},
155 {USB_DEVICE_ID_LOGITECH_G27_WHEEL,
156 LG4FF_MODE_NATIVE | LG4FF_MODE_G27 | LG4FF_MODE_G25 | LG4FF_MODE_DFP | LG4FF_MODE_DFEX,
157 LG4FF_G27_TAG, LG4FF_G27_NAME},
94}; 158};
95 159
96struct lg4ff_usb_revision { 160static const struct lg4ff_alternate_mode lg4ff_alternate_modes[] = {
97 const __u16 rev_maj; 161 [LG4FF_MODE_NATIVE_IDX] = {0, "native", ""},
98 const __u16 rev_min; 162 [LG4FF_MODE_DFEX_IDX] = {USB_DEVICE_ID_LOGITECH_WHEEL, LG4FF_DFEX_TAG, LG4FF_DFEX_NAME},
99 const struct lg4ff_native_cmd *command; 163 [LG4FF_MODE_DFP_IDX] = {USB_DEVICE_ID_LOGITECH_DFP_WHEEL, LG4FF_DFP_TAG, LG4FF_DFP_NAME},
164 [LG4FF_MODE_G25_IDX] = {USB_DEVICE_ID_LOGITECH_G25_WHEEL, LG4FF_G25_TAG, LG4FF_G25_NAME},
165 [LG4FF_MODE_DFGT_IDX] = {USB_DEVICE_ID_LOGITECH_DFGT_WHEEL, LG4FF_DFGT_TAG, LG4FF_DFGT_NAME},
166 [LG4FF_MODE_G27_IDX] = {USB_DEVICE_ID_LOGITECH_G27_WHEEL, LG4FF_G27_TAG, LG4FF_G27_NAME}
100}; 167};
101 168
102static const struct lg4ff_native_cmd native_dfp = { 169/* Multimode wheel identificators */
103 1, 170static const struct lg4ff_wheel_ident_info lg4ff_dfp_ident_info = {
104 {0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00} 171 0xf000,
172 0x1000,
173 USB_DEVICE_ID_LOGITECH_DFP_WHEEL
174};
175
176static const struct lg4ff_wheel_ident_info lg4ff_g25_ident_info = {
177 0xff00,
178 0x1200,
179 USB_DEVICE_ID_LOGITECH_G25_WHEEL
180};
181
182static const struct lg4ff_wheel_ident_info lg4ff_g27_ident_info = {
183 0xfff0,
184 0x1230,
185 USB_DEVICE_ID_LOGITECH_G27_WHEEL
105}; 186};
106 187
107static const struct lg4ff_native_cmd native_dfgt = { 188static const struct lg4ff_wheel_ident_info lg4ff_dfgt_ident_info = {
189 0xff00,
190 0x1300,
191 USB_DEVICE_ID_LOGITECH_DFGT_WHEEL
192};
193
194/* Multimode wheel identification checklists */
195static const struct lg4ff_wheel_ident_checklist lg4ff_main_checklist = {
196 4,
197 {&lg4ff_dfgt_ident_info,
198 &lg4ff_g27_ident_info,
199 &lg4ff_g25_ident_info,
200 &lg4ff_dfp_ident_info}
201};
202
203/* Compatibility mode switching commands */
204/* EXT_CMD9 - Understood by G27 and DFGT */
205static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext09_dfex = {
108 2, 206 2,
109 {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1st command */ 207 {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* Revert mode upon USB reset */
110 0xf8, 0x09, 0x03, 0x01, 0x00, 0x00, 0x00} /* 2nd command */ 208 0xf8, 0x09, 0x00, 0x01, 0x00, 0x00, 0x00} /* Switch mode to DF-EX with detach */
111}; 209};
112 210
113static const struct lg4ff_native_cmd native_g25 = { 211static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext09_dfp = {
114 1, 212 2,
115 {0xf8, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00} 213 {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* Revert mode upon USB reset */
214 0xf8, 0x09, 0x01, 0x01, 0x00, 0x00, 0x00} /* Switch mode to DFP with detach */
215};
216
217static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext09_g25 = {
218 2,
219 {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* Revert mode upon USB reset */
220 0xf8, 0x09, 0x02, 0x01, 0x00, 0x00, 0x00} /* Switch mode to G25 with detach */
221};
222
223static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext09_dfgt = {
224 2,
225 {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* Revert mode upon USB reset */
226 0xf8, 0x09, 0x03, 0x01, 0x00, 0x00, 0x00} /* Switch mode to DFGT with detach */
116}; 227};
117 228
118static const struct lg4ff_native_cmd native_g27 = { 229static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext09_g27 = {
119 2, 230 2,
120 {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1st command */ 231 {0xf8, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, /* Revert mode upon USB reset */
121 0xf8, 0x09, 0x04, 0x01, 0x00, 0x00, 0x00} /* 2nd command */ 232 0xf8, 0x09, 0x04, 0x01, 0x00, 0x00, 0x00} /* Switch mode to G27 with detach */
122}; 233};
123 234
124static const struct lg4ff_usb_revision lg4ff_revs[] = { 235/* EXT_CMD1 - Understood by DFP, G25, G27 and DFGT */
125 {DFGT_REV_MAJ, DFGT_REV_MIN, &native_dfgt}, /* Driving Force GT */ 236static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext01_dfp = {
126 {DFGT_REV_MAJ, DFGT2_REV_MIN, &native_dfgt}, /* Driving Force GT v2 */ 237 1,
127 {DFP_REV_MAJ, DFP_REV_MIN, &native_dfp}, /* Driving Force Pro */ 238 {0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}
128 {G25_REV_MAJ, G25_REV_MIN, &native_g25}, /* G25 */ 239};
129 {G27_REV_MAJ, G27_REV_MIN, &native_g27}, /* G27 */ 240
130 {G27_REV_MAJ, G27_2_REV_MIN, &native_g27}, /* G27 v2 */ 241/* EXT_CMD16 - Understood by G25 and G27 */
242static const struct lg4ff_compat_mode_switch lg4ff_mode_switch_ext16_g25 = {
243 1,
244 {0xf8, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00}
131}; 245};
132 246
133/* Recalculates X axis value accordingly to currently selected range */ 247/* Recalculates X axis value accordingly to currently selected range */
@@ -396,20 +510,216 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range)
396 hid_hw_request(hid, report, HID_REQ_SET_REPORT); 510 hid_hw_request(hid, report, HID_REQ_SET_REPORT);
397} 511}
398 512
399static void hid_lg4ff_switch_native(struct hid_device *hid, const struct lg4ff_native_cmd *cmd) 513static const struct lg4ff_compat_mode_switch *lg4ff_get_mode_switch_command(const u16 real_product_id, const u16 target_product_id)
514{
515 switch (real_product_id) {
516 case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
517 switch (target_product_id) {
518 case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
519 return &lg4ff_mode_switch_ext01_dfp;
520 /* DFP can only be switched to its native mode */
521 default:
522 return NULL;
523 }
524 break;
525 case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
526 switch (target_product_id) {
527 case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
528 return &lg4ff_mode_switch_ext01_dfp;
529 case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
530 return &lg4ff_mode_switch_ext16_g25;
531 /* G25 can only be switched to DFP mode or its native mode */
532 default:
533 return NULL;
534 }
535 break;
536 case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
537 switch (target_product_id) {
538 case USB_DEVICE_ID_LOGITECH_WHEEL:
539 return &lg4ff_mode_switch_ext09_dfex;
540 case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
541 return &lg4ff_mode_switch_ext09_dfp;
542 case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
543 return &lg4ff_mode_switch_ext09_g25;
544 case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
545 return &lg4ff_mode_switch_ext09_g27;
546 /* G27 can only be switched to DF-EX, DFP, G25 or its native mode */
547 default:
548 return NULL;
549 }
550 break;
551 case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:
552 switch (target_product_id) {
553 case USB_DEVICE_ID_LOGITECH_WHEEL:
554 return &lg4ff_mode_switch_ext09_dfex;
555 case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
556 return &lg4ff_mode_switch_ext09_dfp;
557 case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:
558 return &lg4ff_mode_switch_ext09_dfgt;
559 /* DFGT can only be switched to DF-EX, DFP or its native mode */
560 default:
561 return NULL;
562 }
563 break;
564 /* No other wheels have multiple modes */
565 default:
566 return NULL;
567 }
568}
569
570static int lg4ff_switch_compatibility_mode(struct hid_device *hid, const struct lg4ff_compat_mode_switch *s)
400{ 571{
401 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 572 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
402 struct hid_report *report = list_entry(report_list->next, struct hid_report, list); 573 struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
403 __u8 i, j; 574 __s32 *value = report->field[0]->value;
575 u8 i;
404 576
405 j = 0; 577 for (i = 0; i < s->cmd_count; i++) {
406 while (j < 7*cmd->cmd_num) { 578 u8 j;
407 for (i = 0; i < 7; i++) 579
408 report->field[0]->value[i] = cmd->cmd[j++]; 580 for (j = 0; j < 7; j++)
581 value[j] = s->cmd[j + (7*i)];
409 582
410 hid_hw_request(hid, report, HID_REQ_SET_REPORT); 583 hid_hw_request(hid, report, HID_REQ_SET_REPORT);
411 } 584 }
585 hid_hw_wait(hid);
586 return 0;
587}
588
589static ssize_t lg4ff_alternate_modes_show(struct device *dev, struct device_attribute *attr, char *buf)
590{
591 struct hid_device *hid = to_hid_device(dev);
592 struct lg4ff_device_entry *entry;
593 struct lg_drv_data *drv_data;
594 ssize_t count = 0;
595 int i;
596
597 drv_data = hid_get_drvdata(hid);
598 if (!drv_data) {
599 hid_err(hid, "Private driver data not found!\n");
600 return 0;
601 }
602
603 entry = drv_data->device_props;
604 if (!entry) {
605 hid_err(hid, "Device properties not found!\n");
606 return 0;
607 }
608
609 if (!entry->real_name) {
610 hid_err(hid, "NULL pointer to string\n");
611 return 0;
612 }
613
614 for (i = 0; i < LG4FF_MODE_MAX_IDX; i++) {
615 if (entry->alternate_modes & BIT(i)) {
616 /* Print tag and full name */
617 count += scnprintf(buf + count, PAGE_SIZE - count, "%s: %s",
618 lg4ff_alternate_modes[i].tag,
619 !lg4ff_alternate_modes[i].product_id ? entry->real_name : lg4ff_alternate_modes[i].name);
620 if (count >= PAGE_SIZE - 1)
621 return count;
622
623 /* Mark the currently active mode with an asterisk */
624 if (lg4ff_alternate_modes[i].product_id == entry->product_id ||
625 (lg4ff_alternate_modes[i].product_id == 0 && entry->product_id == entry->real_product_id))
626 count += scnprintf(buf + count, PAGE_SIZE - count, " *\n");
627 else
628 count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
629
630 if (count >= PAGE_SIZE - 1)
631 return count;
632 }
633 }
634
635 return count;
636}
637
638static ssize_t lg4ff_alternate_modes_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
639{
640 struct hid_device *hid = to_hid_device(dev);
641 struct lg4ff_device_entry *entry;
642 struct lg_drv_data *drv_data;
643 const struct lg4ff_compat_mode_switch *s;
644 u16 target_product_id = 0;
645 int i, ret;
646 char *lbuf;
647
648 drv_data = hid_get_drvdata(hid);
649 if (!drv_data) {
650 hid_err(hid, "Private driver data not found!\n");
651 return -EINVAL;
652 }
653
654 entry = drv_data->device_props;
655 if (!entry) {
656 hid_err(hid, "Device properties not found!\n");
657 return -EINVAL;
658 }
659
660 /* Allow \n at the end of the input parameter */
661 lbuf = kasprintf(GFP_KERNEL, "%s", buf);
662 if (!lbuf)
663 return -ENOMEM;
664
665 i = strlen(lbuf);
666 if (lbuf[i-1] == '\n') {
667 if (i == 1) {
668 kfree(lbuf);
669 return -EINVAL;
670 }
671 lbuf[i-1] = '\0';
672 }
673
674 for (i = 0; i < LG4FF_MODE_MAX_IDX; i++) {
675 const u16 mode_product_id = lg4ff_alternate_modes[i].product_id;
676 const char *tag = lg4ff_alternate_modes[i].tag;
677
678 if (entry->alternate_modes & BIT(i)) {
679 if (!strcmp(tag, lbuf)) {
680 if (!mode_product_id)
681 target_product_id = entry->real_product_id;
682 else
683 target_product_id = mode_product_id;
684 break;
685 }
686 }
687 }
688
689 if (i == LG4FF_MODE_MAX_IDX) {
690 hid_info(hid, "Requested mode \"%s\" is not supported by the device\n", lbuf);
691 kfree(lbuf);
692 return -EINVAL;
693 }
694 kfree(lbuf); /* Not needed anymore */
695
696 if (target_product_id == entry->product_id) /* Nothing to do */
697 return count;
698
699 /* Automatic switching has to be disabled for the switch to DF-EX mode to work correctly */
700 if (target_product_id == USB_DEVICE_ID_LOGITECH_WHEEL && !lg4ff_no_autoswitch) {
701 hid_info(hid, "\"%s\" cannot be switched to \"DF-EX\" mode. Load the \"hid_logitech\" module with \"lg4ff_no_autoswitch=1\" parameter set and try again\n",
702 entry->real_name);
703 return -EINVAL;
704 }
705
706 /* Take care of hardware limitations */
707 if ((entry->real_product_id == USB_DEVICE_ID_LOGITECH_DFP_WHEEL || entry->real_product_id == USB_DEVICE_ID_LOGITECH_G25_WHEEL) &&
708 entry->product_id > target_product_id) {
709 hid_info(hid, "\"%s\" cannot be switched back into \"%s\" mode\n", entry->real_name, lg4ff_alternate_modes[i].name);
710 return -EINVAL;
711 }
712
713 s = lg4ff_get_mode_switch_command(entry->real_product_id, target_product_id);
714 if (!s) {
715 hid_err(hid, "Invalid target product ID %X\n", target_product_id);
716 return -EINVAL;
717 }
718
719 ret = lg4ff_switch_compatibility_mode(hid, s);
720 return (ret == 0 ? count : ret);
412} 721}
722static DEVICE_ATTR(alternate_modes, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, lg4ff_alternate_modes_show, lg4ff_alternate_modes_store);
413 723
414/* Read current range and display it in terminal */ 724/* Read current range and display it in terminal */
415static ssize_t range_show(struct device *dev, struct device_attribute *attr, 725static ssize_t range_show(struct device *dev, struct device_attribute *attr,
@@ -472,6 +782,41 @@ static ssize_t range_store(struct device *dev, struct device_attribute *attr,
472} 782}
473static DEVICE_ATTR_RW(range); 783static DEVICE_ATTR_RW(range);
474 784
785static ssize_t lg4ff_real_id_show(struct device *dev, struct device_attribute *attr, char *buf)
786{
787 struct hid_device *hid = to_hid_device(dev);
788 struct lg4ff_device_entry *entry;
789 struct lg_drv_data *drv_data;
790 size_t count;
791
792 drv_data = hid_get_drvdata(hid);
793 if (!drv_data) {
794 hid_err(hid, "Private driver data not found!\n");
795 return 0;
796 }
797
798 entry = drv_data->device_props;
799 if (!entry) {
800 hid_err(hid, "Device properties not found!\n");
801 return 0;
802 }
803
804 if (!entry->real_tag || !entry->real_name) {
805 hid_err(hid, "NULL pointer to string\n");
806 return 0;
807 }
808
809 count = scnprintf(buf, PAGE_SIZE, "%s: %s\n", entry->real_tag, entry->real_name);
810 return count;
811}
812
813static ssize_t lg4ff_real_id_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
814{
815 /* Real ID is a read-only value */
816 return -EPERM;
817}
818static DEVICE_ATTR(real_id, S_IRUGO, lg4ff_real_id_show, lg4ff_real_id_store);
819
475#ifdef CONFIG_LEDS_CLASS 820#ifdef CONFIG_LEDS_CLASS
476static void lg4ff_set_leds(struct hid_device *hid, __u8 leds) 821static void lg4ff_set_leds(struct hid_device *hid, __u8 leds)
477{ 822{
@@ -555,20 +900,119 @@ static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cde
555} 900}
556#endif 901#endif
557 902
903static u16 lg4ff_identify_multimode_wheel(struct hid_device *hid, const u16 reported_product_id, const u16 bcdDevice)
904{
905 const struct lg4ff_wheel_ident_checklist *checklist;
906 int i, from_idx, to_idx;
907
908 switch (reported_product_id) {
909 case USB_DEVICE_ID_LOGITECH_WHEEL:
910 case USB_DEVICE_ID_LOGITECH_DFP_WHEEL:
911 checklist = &lg4ff_main_checklist;
912 from_idx = 0;
913 to_idx = checklist->count - 1;
914 break;
915 case USB_DEVICE_ID_LOGITECH_G25_WHEEL:
916 checklist = &lg4ff_main_checklist;
917 from_idx = 0;
918 to_idx = checklist->count - 2; /* End identity check at G25 */
919 break;
920 case USB_DEVICE_ID_LOGITECH_G27_WHEEL:
921 checklist = &lg4ff_main_checklist;
922 from_idx = 1; /* Start identity check at G27 */
923 to_idx = checklist->count - 3; /* End identity check at G27 */
924 break;
925 case USB_DEVICE_ID_LOGITECH_DFGT_WHEEL:
926 checklist = &lg4ff_main_checklist;
927 from_idx = 0;
928 to_idx = checklist->count - 4; /* End identity check at DFGT */
929 break;
930 default:
931 return 0;
932 }
933
934 for (i = from_idx; i <= to_idx; i++) {
935 const u16 mask = checklist->models[i]->mask;
936 const u16 result = checklist->models[i]->result;
937 const u16 real_product_id = checklist->models[i]->real_product_id;
938
939 if ((bcdDevice & mask) == result) {
940 dbg_hid("Found wheel with real PID %X whose reported PID is %X\n", real_product_id, reported_product_id);
941 return real_product_id;
942 }
943 }
944
945 /* No match found. This is either Driving Force or an unknown
946 * wheel model, do not touch it */
947 dbg_hid("Wheel with bcdDevice %X was not recognized as multimode wheel, leaving in its current mode\n", bcdDevice);
948 return 0;
949}
950
951static int lg4ff_handle_multimode_wheel(struct hid_device *hid, u16 *real_product_id, const u16 bcdDevice)
952{
953 const u16 reported_product_id = hid->product;
954 int ret;
955
956 *real_product_id = lg4ff_identify_multimode_wheel(hid, reported_product_id, bcdDevice);
957 /* Probed wheel is not a multimode wheel */
958 if (!*real_product_id) {
959 *real_product_id = reported_product_id;
960 dbg_hid("Wheel is not a multimode wheel\n");
961 return LG4FF_MMODE_NOT_MULTIMODE;
962 }
963
964 /* Switch from "Driving Force" mode to native mode automatically.
965 * Otherwise keep the wheel in its current mode */
966 if (reported_product_id == USB_DEVICE_ID_LOGITECH_WHEEL &&
967 reported_product_id != *real_product_id &&
968 !lg4ff_no_autoswitch) {
969 const struct lg4ff_compat_mode_switch *s = lg4ff_get_mode_switch_command(*real_product_id, *real_product_id);
970
971 if (!s) {
972 hid_err(hid, "Invalid product id %X\n", *real_product_id);
973 return LG4FF_MMODE_NOT_MULTIMODE;
974 }
975
976 ret = lg4ff_switch_compatibility_mode(hid, s);
977 if (ret) {
978 /* Wheel could not have been switched to native mode,
979 * leave it in "Driving Force" mode and continue */
980 hid_err(hid, "Unable to switch wheel mode, errno %d\n", ret);
981 return LG4FF_MMODE_IS_MULTIMODE;
982 }
983 return LG4FF_MMODE_SWITCHED;
984 }
985
986 return LG4FF_MMODE_IS_MULTIMODE;
987}
988
989
558int lg4ff_init(struct hid_device *hid) 990int lg4ff_init(struct hid_device *hid)
559{ 991{
560 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); 992 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
561 struct input_dev *dev = hidinput->input; 993 struct input_dev *dev = hidinput->input;
994 const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor);
995 const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice);
562 struct lg4ff_device_entry *entry; 996 struct lg4ff_device_entry *entry;
563 struct lg_drv_data *drv_data; 997 struct lg_drv_data *drv_data;
564 struct usb_device_descriptor *udesc;
565 int error, i, j; 998 int error, i, j;
566 __u16 bcdDevice, rev_maj, rev_min; 999 int mmode_ret, mmode_idx = -1;
1000 u16 real_product_id;
567 1001
568 /* Check that the report looks ok */ 1002 /* Check that the report looks ok */
569 if (!hid_validate_values(hid, HID_OUTPUT_REPORT, 0, 0, 7)) 1003 if (!hid_validate_values(hid, HID_OUTPUT_REPORT, 0, 0, 7))
570 return -1; 1004 return -1;
571 1005
1006 /* Check if a multimode wheel has been connected and
1007 * handle it appropriately */
1008 mmode_ret = lg4ff_handle_multimode_wheel(hid, &real_product_id, bcdDevice);
1009
1010 /* Wheel has been told to switch to native mode. There is no point in going on
1011 * with the initialization as the wheel will do a USB reset when it switches mode
1012 */
1013 if (mmode_ret == LG4FF_MMODE_SWITCHED)
1014 return 0;
1015
572 /* Check what wheel has been connected */ 1016 /* Check what wheel has been connected */
573 for (i = 0; i < ARRAY_SIZE(lg4ff_devices); i++) { 1017 for (i = 0; i < ARRAY_SIZE(lg4ff_devices); i++) {
574 if (hid->product == lg4ff_devices[i].product_id) { 1018 if (hid->product == lg4ff_devices[i].product_id) {
@@ -583,25 +1027,15 @@ int lg4ff_init(struct hid_device *hid)
583 return -1; 1027 return -1;
584 } 1028 }
585 1029
586 /* Attempt to switch wheel to native mode when applicable */ 1030 if (mmode_ret == LG4FF_MMODE_IS_MULTIMODE) {
587 udesc = &(hid_to_usb_dev(hid)->descriptor); 1031 for (mmode_idx = 0; mmode_idx < ARRAY_SIZE(lg4ff_multimode_wheels); mmode_idx++) {
588 if (!udesc) { 1032 if (real_product_id == lg4ff_multimode_wheels[mmode_idx].product_id)
589 hid_err(hid, "NULL USB device descriptor\n"); 1033 break;
590 return -1; 1034 }
591 }
592 bcdDevice = le16_to_cpu(udesc->bcdDevice);
593 rev_maj = bcdDevice >> 8;
594 rev_min = bcdDevice & 0xff;
595
596 if (lg4ff_devices[i].product_id == USB_DEVICE_ID_LOGITECH_WHEEL) {
597 dbg_hid("Generic wheel detected, can it do native?\n");
598 dbg_hid("USB revision: %2x.%02x\n", rev_maj, rev_min);
599 1035
600 for (j = 0; j < ARRAY_SIZE(lg4ff_revs); j++) { 1036 if (mmode_idx == ARRAY_SIZE(lg4ff_multimode_wheels)) {
601 if (lg4ff_revs[j].rev_maj == rev_maj && lg4ff_revs[j].rev_min == rev_min) { 1037 hid_err(hid, "Device product ID %X is not listed as a multimode wheel", real_product_id);
602 hid_lg4ff_switch_native(hid, lg4ff_revs[j].command); 1038 return -1;
603 hid_info(hid, "Switched to native mode\n");
604 }
605 } 1039 }
606 } 1040 }
607 1041
@@ -630,14 +1064,23 @@ int lg4ff_init(struct hid_device *hid)
630 drv_data->device_props = entry; 1064 drv_data->device_props = entry;
631 1065
632 entry->product_id = lg4ff_devices[i].product_id; 1066 entry->product_id = lg4ff_devices[i].product_id;
1067 entry->real_product_id = real_product_id;
633 entry->min_range = lg4ff_devices[i].min_range; 1068 entry->min_range = lg4ff_devices[i].min_range;
634 entry->max_range = lg4ff_devices[i].max_range; 1069 entry->max_range = lg4ff_devices[i].max_range;
635 entry->set_range = lg4ff_devices[i].set_range; 1070 entry->set_range = lg4ff_devices[i].set_range;
1071 if (mmode_ret == LG4FF_MMODE_IS_MULTIMODE) {
1072 BUG_ON(mmode_idx == -1);
1073 entry->alternate_modes = lg4ff_multimode_wheels[mmode_idx].alternate_modes;
1074 entry->real_tag = lg4ff_multimode_wheels[mmode_idx].real_tag;
1075 entry->real_name = lg4ff_multimode_wheels[mmode_idx].real_name;
1076 }
636 1077
637 /* Check if autocentering is available and 1078 /* Check if autocentering is available and
638 * set the centering force to zero by default */ 1079 * set the centering force to zero by default */
639 if (test_bit(FF_AUTOCENTER, dev->ffbit)) { 1080 if (test_bit(FF_AUTOCENTER, dev->ffbit)) {
640 if (rev_maj == FFEX_REV_MAJ && rev_min == FFEX_REV_MIN) /* Formula Force EX expects different autocentering command */ 1081 /* Formula Force EX expects different autocentering command */
1082 if ((bcdDevice >> 8) == LG4FF_FFEX_REV_MAJ &&
1083 (bcdDevice & 0xff) == LG4FF_FFEX_REV_MIN)
641 dev->ff->set_autocenter = hid_lg4ff_set_autocenter_ffex; 1084 dev->ff->set_autocenter = hid_lg4ff_set_autocenter_ffex;
642 else 1085 else
643 dev->ff->set_autocenter = hid_lg4ff_set_autocenter_default; 1086 dev->ff->set_autocenter = hid_lg4ff_set_autocenter_default;
@@ -649,6 +1092,14 @@ int lg4ff_init(struct hid_device *hid)
649 error = device_create_file(&hid->dev, &dev_attr_range); 1092 error = device_create_file(&hid->dev, &dev_attr_range);
650 if (error) 1093 if (error)
651 return error; 1094 return error;
1095 if (mmode_ret == LG4FF_MMODE_IS_MULTIMODE) {
1096 error = device_create_file(&hid->dev, &dev_attr_real_id);
1097 if (error)
1098 return error;
1099 error = device_create_file(&hid->dev, &dev_attr_alternate_modes);
1100 if (error)
1101 return error;
1102 }
652 dbg_hid("sysfs interface created\n"); 1103 dbg_hid("sysfs interface created\n");
653 1104
654 /* Set the maximum range to start with */ 1105 /* Set the maximum range to start with */
@@ -711,24 +1162,26 @@ out:
711 return 0; 1162 return 0;
712} 1163}
713 1164
714
715
716int lg4ff_deinit(struct hid_device *hid) 1165int lg4ff_deinit(struct hid_device *hid)
717{ 1166{
718 struct lg4ff_device_entry *entry; 1167 struct lg4ff_device_entry *entry;
719 struct lg_drv_data *drv_data; 1168 struct lg_drv_data *drv_data;
720 1169
721 device_remove_file(&hid->dev, &dev_attr_range);
722
723 drv_data = hid_get_drvdata(hid); 1170 drv_data = hid_get_drvdata(hid);
724 if (!drv_data) { 1171 if (!drv_data) {
725 hid_err(hid, "Error while deinitializing device, no private driver data.\n"); 1172 hid_err(hid, "Error while deinitializing device, no private driver data.\n");
726 return -1; 1173 return -1;
727 } 1174 }
728 entry = drv_data->device_props; 1175 entry = drv_data->device_props;
729 if (!entry) { 1176 if (!entry)
730 hid_err(hid, "Error while deinitializing device, no device properties data.\n"); 1177 goto out; /* Nothing more to do */
731 return -1; 1178
1179 device_remove_file(&hid->dev, &dev_attr_range);
1180
1181 /* Multimode devices will have at least the "MODE_NATIVE" bit set */
1182 if (entry->alternate_modes) {
1183 device_remove_file(&hid->dev, &dev_attr_real_id);
1184 device_remove_file(&hid->dev, &dev_attr_alternate_modes);
732 } 1185 }
733 1186
734#ifdef CONFIG_LEDS_CLASS 1187#ifdef CONFIG_LEDS_CLASS
@@ -752,6 +1205,7 @@ int lg4ff_deinit(struct hid_device *hid)
752 /* Deallocate memory */ 1205 /* Deallocate memory */
753 kfree(entry); 1206 kfree(entry);
754 1207
1208out:
755 dbg_hid("Device successfully unregistered\n"); 1209 dbg_hid("Device successfully unregistered\n");
756 return 0; 1210 return 0;
757} 1211}
diff --git a/drivers/hid/hid-lg4ff.h b/drivers/hid/hid-lg4ff.h
new file mode 100644
index 000000000000..5b6a5086c47f
--- /dev/null
+++ b/drivers/hid/hid-lg4ff.h
@@ -0,0 +1,18 @@
1#ifndef __HID_LG4FF_H
2#define __HID_LG4FF_H
3
4#ifdef CONFIG_LOGIWHEELS_FF
5extern int lg4ff_no_autoswitch; /* From hid-lg.c */
6
7int lg4ff_adjust_input_event(struct hid_device *hid, struct hid_field *field,
8 struct hid_usage *usage, __s32 value, struct lg_drv_data *drv_data);
9int lg4ff_init(struct hid_device *hdev);
10int lg4ff_deinit(struct hid_device *hdev);
11#else
12static inline int lg4ff_adjust_input_event(struct hid_device *hid, struct hid_field *field,
13 struct hid_usage *usage, __s32 value, struct lg_drv_data *drv_data) { return 0; }
14static inline int lg4ff_init(struct hid_device *hdev) { return -1; }
15static inline int lg4ff_deinit(struct hid_device *hdev) { return -1; }
16#endif
17
18#endif
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index e77658cd037c..b3cf6fd4be96 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -28,6 +28,11 @@ MODULE_LICENSE("GPL");
28MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>"); 28MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
29MODULE_AUTHOR("Nestor Lopez Casado <nlopezcasad@logitech.com>"); 29MODULE_AUTHOR("Nestor Lopez Casado <nlopezcasad@logitech.com>");
30 30
31static bool disable_raw_mode;
32module_param(disable_raw_mode, bool, 0644);
33MODULE_PARM_DESC(disable_raw_mode,
34 "Disable Raw mode reporting for touchpads and keep firmware gestures.");
35
31#define REPORT_ID_HIDPP_SHORT 0x10 36#define REPORT_ID_HIDPP_SHORT 0x10
32#define REPORT_ID_HIDPP_LONG 0x11 37#define REPORT_ID_HIDPP_LONG 0x11
33 38
@@ -1188,6 +1193,11 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
1188 1193
1189 hidpp->quirks = id->driver_data; 1194 hidpp->quirks = id->driver_data;
1190 1195
1196 if (disable_raw_mode) {
1197 hidpp->quirks &= ~HIDPP_QUIRK_CLASS_WTP;
1198 hidpp->quirks &= ~HIDPP_QUIRK_DELAYED_INIT;
1199 }
1200
1191 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) { 1201 if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {
1192 ret = wtp_allocate(hdev, id); 1202 ret = wtp_allocate(hdev, id);
1193 if (ret) 1203 if (ret)
@@ -1210,6 +1220,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
1210 connected = hidpp_is_connected(hidpp); 1220 connected = hidpp_is_connected(hidpp);
1211 if (id->group != HID_GROUP_LOGITECH_DJ_DEVICE) { 1221 if (id->group != HID_GROUP_LOGITECH_DJ_DEVICE) {
1212 if (!connected) { 1222 if (!connected) {
1223 ret = -ENODEV;
1213 hid_err(hdev, "Device not connected"); 1224 hid_err(hdev, "Device not connected");
1214 hid_device_io_stop(hdev); 1225 hid_device_io_stop(hdev);
1215 goto hid_parse_fail; 1226 goto hid_parse_fail;
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index f65e78b46999..6a9b05b328a9 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -42,7 +42,6 @@
42#include <linux/hid.h> 42#include <linux/hid.h>
43#include <linux/module.h> 43#include <linux/module.h>
44#include <linux/slab.h> 44#include <linux/slab.h>
45#include <linux/usb.h>
46#include <linux/input/mt.h> 45#include <linux/input/mt.h>
47#include <linux/string.h> 46#include <linux/string.h>
48 47
@@ -72,6 +71,8 @@ MODULE_LICENSE("GPL");
72#define MT_INPUTMODE_TOUCHSCREEN 0x02 71#define MT_INPUTMODE_TOUCHSCREEN 0x02
73#define MT_INPUTMODE_TOUCHPAD 0x03 72#define MT_INPUTMODE_TOUCHPAD 0x03
74 73
74#define MT_BUTTONTYPE_CLICKPAD 0
75
75struct mt_slot { 76struct mt_slot {
76 __s32 x, y, cx, cy, p, w, h; 77 __s32 x, y, cx, cy, p, w, h;
77 __s32 contactid; /* the device ContactID assigned to this slot */ 78 __s32 contactid; /* the device ContactID assigned to this slot */
@@ -116,6 +117,8 @@ struct mt_device {
116 __u8 touches_by_report; /* how many touches are present in one report: 117 __u8 touches_by_report; /* how many touches are present in one report:
117 * 1 means we should use a serial protocol 118 * 1 means we should use a serial protocol
118 * > 1 means hybrid (multitouch) protocol */ 119 * > 1 means hybrid (multitouch) protocol */
120 __u8 buttons_count; /* number of physical buttons per touchpad */
121 bool is_buttonpad; /* is this device a button pad? */
119 bool serial_maybe; /* need to check for serial protocol */ 122 bool serial_maybe; /* need to check for serial protocol */
120 bool curvalid; /* is the current contact valid? */ 123 bool curvalid; /* is the current contact valid? */
121 unsigned mt_flags; /* flags to pass to input-mt */ 124 unsigned mt_flags; /* flags to pass to input-mt */
@@ -334,6 +337,16 @@ static void mt_feature_mapping(struct hid_device *hdev,
334 td->maxcontacts = td->mtclass.maxcontacts; 337 td->maxcontacts = td->mtclass.maxcontacts;
335 338
336 break; 339 break;
340 case HID_DG_BUTTONTYPE:
341 if (usage->usage_index >= field->report_count) {
342 dev_err(&hdev->dev, "HID_DG_BUTTONTYPE out of range\n");
343 break;
344 }
345
346 if (field->value[usage->usage_index] == MT_BUTTONTYPE_CLICKPAD)
347 td->is_buttonpad = true;
348
349 break;
337 } 350 }
338} 351}
339 352
@@ -379,6 +392,10 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
379 td->inputmode_value = MT_INPUTMODE_TOUCHPAD; 392 td->inputmode_value = MT_INPUTMODE_TOUCHPAD;
380 } 393 }
381 394
395 /* count the buttons on touchpads */
396 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON)
397 td->buttons_count++;
398
382 if (usage->usage_index) 399 if (usage->usage_index)
383 prev_usage = &field->usage[usage->usage_index - 1]; 400 prev_usage = &field->usage[usage->usage_index - 1];
384 401
@@ -728,6 +745,13 @@ static void mt_touch_input_configured(struct hid_device *hdev,
728 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) 745 if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
729 td->mt_flags |= INPUT_MT_DROP_UNUSED; 746 td->mt_flags |= INPUT_MT_DROP_UNUSED;
730 747
748 /* check for clickpads */
749 if ((td->mt_flags & INPUT_MT_POINTER) && (td->buttons_count == 1))
750 td->is_buttonpad = true;
751
752 if (td->is_buttonpad)
753 __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
754
731 input_mt_init_slots(input, td->maxcontacts, td->mt_flags); 755 input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
732 756
733 td->mt_flags = 0; 757 td->mt_flags = 0;
diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
index 49d4fe4f5987..368ffdf2c0a3 100644
--- a/drivers/hid/hid-rmi.c
+++ b/drivers/hid/hid-rmi.c
@@ -104,6 +104,7 @@ struct rmi_data {
104 104
105 unsigned long flags; 105 unsigned long flags;
106 106
107 struct rmi_function f01;
107 struct rmi_function f11; 108 struct rmi_function f11;
108 struct rmi_function f30; 109 struct rmi_function f30;
109 110
@@ -124,6 +125,7 @@ struct rmi_data {
124 struct hid_device *hdev; 125 struct hid_device *hdev;
125 126
126 unsigned long device_flags; 127 unsigned long device_flags;
128 unsigned long firmware_id;
127}; 129};
128 130
129#define RMI_PAGE(addr) (((addr) >> 8) & 0xff) 131#define RMI_PAGE(addr) (((addr) >> 8) & 0xff)
@@ -272,6 +274,46 @@ static inline int rmi_read(struct hid_device *hdev, u16 addr, void *buf)
272 return rmi_read_block(hdev, addr, buf, 1); 274 return rmi_read_block(hdev, addr, buf, 1);
273} 275}
274 276
277static int rmi_write_block(struct hid_device *hdev, u16 addr, void *buf,
278 const int len)
279{
280 struct rmi_data *data = hid_get_drvdata(hdev);
281 int ret;
282
283 mutex_lock(&data->page_mutex);
284
285 if (RMI_PAGE(addr) != data->page) {
286 ret = rmi_set_page(hdev, RMI_PAGE(addr));
287 if (ret < 0)
288 goto exit;
289 }
290
291 data->writeReport[0] = RMI_WRITE_REPORT_ID;
292 data->writeReport[1] = len;
293 data->writeReport[2] = addr & 0xFF;
294 data->writeReport[3] = (addr >> 8) & 0xFF;
295 memcpy(&data->writeReport[4], buf, len);
296
297 ret = rmi_write_report(hdev, data->writeReport,
298 data->output_report_size);
299 if (ret < 0) {
300 dev_err(&hdev->dev,
301 "failed to write request output report (%d)\n",
302 ret);
303 goto exit;
304 }
305 ret = 0;
306
307exit:
308 mutex_unlock(&data->page_mutex);
309 return ret;
310}
311
312static inline int rmi_write(struct hid_device *hdev, u16 addr, void *buf)
313{
314 return rmi_write_block(hdev, addr, buf, 1);
315}
316
275static void rmi_f11_process_touch(struct rmi_data *hdata, int slot, 317static void rmi_f11_process_touch(struct rmi_data *hdata, int slot,
276 u8 finger_state, u8 *touch_data) 318 u8 finger_state, u8 *touch_data)
277{ 319{
@@ -532,6 +574,9 @@ static void rmi_register_function(struct rmi_data *data,
532 u16 page_base = page << 8; 574 u16 page_base = page << 8;
533 575
534 switch (pdt_entry->function_number) { 576 switch (pdt_entry->function_number) {
577 case 0x01:
578 f = &data->f01;
579 break;
535 case 0x11: 580 case 0x11:
536 f = &data->f11; 581 f = &data->f11;
537 break; 582 break;
@@ -604,6 +649,92 @@ error_exit:
604 return retval; 649 return retval;
605} 650}
606 651
652#define RMI_DEVICE_F01_BASIC_QUERY_LEN 11
653
654static int rmi_populate_f01(struct hid_device *hdev)
655{
656 struct rmi_data *data = hid_get_drvdata(hdev);
657 u8 basic_queries[RMI_DEVICE_F01_BASIC_QUERY_LEN];
658 u8 info[3];
659 int ret;
660 bool has_query42;
661 bool has_lts;
662 bool has_sensor_id;
663 bool has_ds4_queries = false;
664 bool has_build_id_query = false;
665 bool has_package_id_query = false;
666 u16 query_offset = data->f01.query_base_addr;
667 u16 prod_info_addr;
668 u8 ds4_query_len;
669
670 ret = rmi_read_block(hdev, query_offset, basic_queries,
671 RMI_DEVICE_F01_BASIC_QUERY_LEN);
672 if (ret) {
673 hid_err(hdev, "Can not read basic queries from Function 0x1.\n");
674 return ret;
675 }
676
677 has_lts = !!(basic_queries[0] & BIT(2));
678 has_sensor_id = !!(basic_queries[1] & BIT(3));
679 has_query42 = !!(basic_queries[1] & BIT(7));
680
681 query_offset += 11;
682 prod_info_addr = query_offset + 6;
683 query_offset += 10;
684
685 if (has_lts)
686 query_offset += 20;
687
688 if (has_sensor_id)
689 query_offset++;
690
691 if (has_query42) {
692 ret = rmi_read(hdev, query_offset, info);
693 if (ret) {
694 hid_err(hdev, "Can not read query42.\n");
695 return ret;
696 }
697 has_ds4_queries = !!(info[0] & BIT(0));
698 query_offset++;
699 }
700
701 if (has_ds4_queries) {
702 ret = rmi_read(hdev, query_offset, &ds4_query_len);
703 if (ret) {
704 hid_err(hdev, "Can not read DS4 Query length.\n");
705 return ret;
706 }
707 query_offset++;
708
709 if (ds4_query_len > 0) {
710 ret = rmi_read(hdev, query_offset, info);
711 if (ret) {
712 hid_err(hdev, "Can not read DS4 query.\n");
713 return ret;
714 }
715
716 has_package_id_query = !!(info[0] & BIT(0));
717 has_build_id_query = !!(info[0] & BIT(1));
718 }
719 }
720
721 if (has_package_id_query)
722 prod_info_addr++;
723
724 if (has_build_id_query) {
725 ret = rmi_read_block(hdev, prod_info_addr, info, 3);
726 if (ret) {
727 hid_err(hdev, "Can not read product info.\n");
728 return ret;
729 }
730
731 data->firmware_id = info[1] << 8 | info[0];
732 data->firmware_id += info[2] * 65536;
733 }
734
735 return 0;
736}
737
607static int rmi_populate_f11(struct hid_device *hdev) 738static int rmi_populate_f11(struct hid_device *hdev)
608{ 739{
609 struct rmi_data *data = hid_get_drvdata(hdev); 740 struct rmi_data *data = hid_get_drvdata(hdev);
@@ -620,6 +751,8 @@ static int rmi_populate_f11(struct hid_device *hdev)
620 bool has_gestures; 751 bool has_gestures;
621 bool has_rel; 752 bool has_rel;
622 bool has_data40 = false; 753 bool has_data40 = false;
754 bool has_dribble = false;
755 bool has_palm_detect = false;
623 unsigned x_size, y_size; 756 unsigned x_size, y_size;
624 u16 query_offset; 757 u16 query_offset;
625 758
@@ -661,6 +794,14 @@ static int rmi_populate_f11(struct hid_device *hdev)
661 has_rel = !!(buf[0] & BIT(3)); 794 has_rel = !!(buf[0] & BIT(3));
662 has_gestures = !!(buf[0] & BIT(5)); 795 has_gestures = !!(buf[0] & BIT(5));
663 796
797 ret = rmi_read(hdev, data->f11.query_base_addr + 5, buf);
798 if (ret) {
799 hid_err(hdev, "can not get absolute data sources: %d.\n", ret);
800 return ret;
801 }
802
803 has_dribble = !!(buf[0] & BIT(4));
804
664 /* 805 /*
665 * At least 4 queries are guaranteed to be present in F11 806 * At least 4 queries are guaranteed to be present in F11
666 * +1 for query 5 which is present since absolute events are 807 * +1 for query 5 which is present since absolute events are
@@ -680,6 +821,7 @@ static int rmi_populate_f11(struct hid_device *hdev)
680 ret); 821 ret);
681 return ret; 822 return ret;
682 } 823 }
824 has_palm_detect = !!(buf[0] & BIT(0));
683 has_query10 = !!(buf[0] & BIT(2)); 825 has_query10 = !!(buf[0] & BIT(2));
684 826
685 query_offset += 2; /* query 7 and 8 are present */ 827 query_offset += 2; /* query 7 and 8 are present */
@@ -766,17 +908,38 @@ static int rmi_populate_f11(struct hid_device *hdev)
766 * retrieve the ctrl registers 908 * retrieve the ctrl registers
767 * the ctrl register has a size of 20 but a fw bug split it into 16 + 4, 909 * the ctrl register has a size of 20 but a fw bug split it into 16 + 4,
768 * and there is no way to know if the first 20 bytes are here or not. 910 * and there is no way to know if the first 20 bytes are here or not.
769 * We use only the first 10 bytes, so get only them. 911 * We use only the first 12 bytes, so get only them.
770 */ 912 */
771 ret = rmi_read_block(hdev, data->f11.control_base_addr, buf, 10); 913 ret = rmi_read_block(hdev, data->f11.control_base_addr, buf, 12);
772 if (ret) { 914 if (ret) {
773 hid_err(hdev, "can not read ctrl block of size 10: %d.\n", ret); 915 hid_err(hdev, "can not read ctrl block of size 11: %d.\n", ret);
774 return ret; 916 return ret;
775 } 917 }
776 918
777 data->max_x = buf[6] | (buf[7] << 8); 919 data->max_x = buf[6] | (buf[7] << 8);
778 data->max_y = buf[8] | (buf[9] << 8); 920 data->max_y = buf[8] | (buf[9] << 8);
779 921
922 if (has_dribble) {
923 buf[0] = buf[0] & ~BIT(6);
924 ret = rmi_write(hdev, data->f11.control_base_addr, buf);
925 if (ret) {
926 hid_err(hdev, "can not write to control reg 0: %d.\n",
927 ret);
928 return ret;
929 }
930 }
931
932 if (has_palm_detect) {
933 buf[11] = buf[11] & ~BIT(0);
934 ret = rmi_write(hdev, data->f11.control_base_addr + 11,
935 &buf[11]);
936 if (ret) {
937 hid_err(hdev, "can not write to control reg 11: %d.\n",
938 ret);
939 return ret;
940 }
941 }
942
780 return 0; 943 return 0;
781} 944}
782 945
@@ -858,6 +1021,12 @@ static int rmi_populate(struct hid_device *hdev)
858 return ret; 1021 return ret;
859 } 1022 }
860 1023
1024 ret = rmi_populate_f01(hdev);
1025 if (ret) {
1026 hid_err(hdev, "Error while initializing F01 (%d).\n", ret);
1027 return ret;
1028 }
1029
861 ret = rmi_populate_f11(hdev); 1030 ret = rmi_populate_f11(hdev);
862 if (ret) { 1031 if (ret) {
863 hid_err(hdev, "Error while initializing F11 (%d).\n", ret); 1032 hid_err(hdev, "Error while initializing F11 (%d).\n", ret);
@@ -907,6 +1076,8 @@ static void rmi_input_configured(struct hid_device *hdev, struct hid_input *hi)
907 if (ret) 1076 if (ret)
908 goto exit; 1077 goto exit;
909 1078
1079 hid_info(hdev, "firmware id: %ld\n", data->firmware_id);
1080
910 __set_bit(EV_ABS, input->evbit); 1081 __set_bit(EV_ABS, input->evbit);
911 input_set_abs_params(input, ABS_MT_POSITION_X, 1, data->max_x, 0, 0); 1082 input_set_abs_params(input, ABS_MT_POSITION_X, 1, data->max_x, 0, 0);
912 input_set_abs_params(input, ABS_MT_POSITION_Y, 1, data->max_y, 0, 0); 1083 input_set_abs_params(input, ABS_MT_POSITION_Y, 1, data->max_y, 0, 0);
diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c
new file mode 100644
index 000000000000..5614fee82347
--- /dev/null
+++ b/drivers/hid/hid-sensor-custom.c
@@ -0,0 +1,849 @@
1/*
2 * hid-sensor-custom.c
3 * Copyright (c) 2015, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/miscdevice.h>
19#include <linux/kfifo.h>
20#include <linux/sched.h>
21#include <linux/wait.h>
22#include <linux/poll.h>
23#include <linux/bsearch.h>
24#include <linux/platform_device.h>
25#include <linux/hid-sensor-hub.h>
26
27#define HID_CUSTOM_NAME_LENGTH 64
28#define HID_CUSTOM_MAX_CORE_ATTRS 10
29#define HID_CUSTOM_TOTAL_ATTRS (HID_CUSTOM_MAX_CORE_ATTRS + 1)
30#define HID_CUSTOM_FIFO_SIZE 4096
31#define HID_CUSTOM_MAX_FEATURE_BYTES 64
32
33struct hid_sensor_custom_field {
34 int report_id;
35 char group_name[HID_CUSTOM_NAME_LENGTH];
36 struct hid_sensor_hub_attribute_info attribute;
37 struct device_attribute sd_attrs[HID_CUSTOM_MAX_CORE_ATTRS];
38 char attr_name[HID_CUSTOM_TOTAL_ATTRS][HID_CUSTOM_NAME_LENGTH];
39 struct attribute *attrs[HID_CUSTOM_TOTAL_ATTRS];
40 struct attribute_group hid_custom_attribute_group;
41};
42
43struct hid_sensor_custom {
44 struct mutex mutex;
45 struct platform_device *pdev;
46 struct hid_sensor_hub_device *hsdev;
47 struct hid_sensor_hub_callbacks callbacks;
48 int sensor_field_count;
49 struct hid_sensor_custom_field *fields;
50 int input_field_count;
51 int input_report_size;
52 int input_report_recd_size;
53 bool input_skip_sample;
54 bool enable;
55 struct hid_sensor_custom_field *power_state;
56 struct hid_sensor_custom_field *report_state;
57 struct miscdevice custom_dev;
58 struct kfifo data_fifo;
59 unsigned long misc_opened;
60 wait_queue_head_t wait;
61};
62
63/* Header for each sample to user space via dev interface */
64struct hid_sensor_sample {
65 u32 usage_id;
66 u64 timestamp;
67 u32 raw_len;
68} __packed;
69
70static struct attribute hid_custom_attrs[] = {
71 {.name = "name", .mode = S_IRUGO},
72 {.name = "units", .mode = S_IRUGO},
73 {.name = "unit-expo", .mode = S_IRUGO},
74 {.name = "minimum", .mode = S_IRUGO},
75 {.name = "maximum", .mode = S_IRUGO},
76 {.name = "size", .mode = S_IRUGO},
77 {.name = "value", .mode = S_IWUSR | S_IRUGO},
78 {.name = NULL}
79};
80
81static const struct hid_custom_usage_desc {
82 int usage_id;
83 char *desc;
84} hid_custom_usage_desc_table[] = {
85 {0x200201, "event-sensor-state"},
86 {0x200202, "event-sensor-event"},
87 {0x200301, "property-friendly-name"},
88 {0x200302, "property-persistent-unique-id"},
89 {0x200303, "property-sensor-status"},
90 {0x200304, "property-min-report-interval"},
91 {0x200305, "property-sensor-manufacturer"},
92 {0x200306, "property-sensor-model"},
93 {0x200307, "property-sensor-serial-number"},
94 {0x200308, "property-sensor-description"},
95 {0x200309, "property-sensor-connection-type"},
96 {0x20030A, "property-sensor-device-path"},
97 {0x20030B, "property-hardware-revision"},
98 {0x20030C, "property-firmware-version"},
99 {0x20030D, "property-release-date"},
100 {0x20030E, "property-report-interval"},
101 {0x20030F, "property-change-sensitivity-absolute"},
102 {0x200310, "property-change-sensitivity-percent-range"},
103 {0x200311, "property-change-sensitivity-percent-relative"},
104 {0x200312, "property-accuracy"},
105 {0x200313, "property-resolution"},
106 {0x200314, "property-maximum"},
107 {0x200315, "property-minimum"},
108 {0x200316, "property-reporting-state"},
109 {0x200317, "property-sampling-rate"},
110 {0x200318, "property-response-curve"},
111 {0x200319, "property-power-state"},
112 {0x200540, "data-field-custom"},
113 {0x200541, "data-field-custom-usage"},
114 {0x200542, "data-field-custom-boolean-array"},
115 {0x200543, "data-field-custom-value"},
116 {0x200544, "data-field-custom-value_1"},
117 {0x200545, "data-field-custom-value_2"},
118 {0x200546, "data-field-custom-value_3"},
119 {0x200547, "data-field-custom-value_4"},
120 {0x200548, "data-field-custom-value_5"},
121 {0x200549, "data-field-custom-value_6"},
122 {0x20054A, "data-field-custom-value_7"},
123 {0x20054B, "data-field-custom-value_8"},
124 {0x20054C, "data-field-custom-value_9"},
125 {0x20054D, "data-field-custom-value_10"},
126 {0x20054E, "data-field-custom-value_11"},
127 {0x20054F, "data-field-custom-value_12"},
128 {0x200550, "data-field-custom-value_13"},
129 {0x200551, "data-field-custom-value_14"},
130 {0x200552, "data-field-custom-value_15"},
131 {0x200553, "data-field-custom-value_16"},
132 {0x200554, "data-field-custom-value_17"},
133 {0x200555, "data-field-custom-value_18"},
134 {0x200556, "data-field-custom-value_19"},
135 {0x200557, "data-field-custom-value_20"},
136 {0x200558, "data-field-custom-value_21"},
137 {0x200559, "data-field-custom-value_22"},
138 {0x20055A, "data-field-custom-value_23"},
139 {0x20055B, "data-field-custom-value_24"},
140 {0x20055C, "data-field-custom-value_25"},
141 {0x20055D, "data-field-custom-value_26"},
142 {0x20055E, "data-field-custom-value_27"},
143 {0x20055F, "data-field-custom-value_28"},
144};
145
146static int usage_id_cmp(const void *p1, const void *p2)
147{
148 if (*(int *)p1 < *(int *)p2)
149 return -1;
150
151 if (*(int *)p1 > *(int *)p2)
152 return 1;
153
154 return 0;
155}
156
157static ssize_t enable_sensor_show(struct device *dev,
158 struct device_attribute *attr, char *buf)
159{
160 struct platform_device *pdev = to_platform_device(dev);
161 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
162
163 return sprintf(buf, "%d\n", sensor_inst->enable);
164}
165
166static int set_power_report_state(struct hid_sensor_custom *sensor_inst,
167 bool state)
168{
169 int power_val = -1;
170 int report_val = -1;
171 u32 power_state_usage_id;
172 u32 report_state_usage_id;
173 int ret;
174
175 /*
176 * It is possible that the power/report state ids are not present.
177 * In this case this function will return success. But if the
178 * ids are present, then it will return error if set fails.
179 */
180 if (state) {
181 power_state_usage_id =
182 HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM;
183 report_state_usage_id =
184 HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM;
185 } else {
186 power_state_usage_id =
187 HID_USAGE_SENSOR_PROP_POWER_STATE_D4_POWER_OFF_ENUM;
188 report_state_usage_id =
189 HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM;
190 }
191
192 if (sensor_inst->power_state)
193 power_val = hid_sensor_get_usage_index(sensor_inst->hsdev,
194 sensor_inst->power_state->attribute.report_id,
195 sensor_inst->power_state->attribute.index,
196 power_state_usage_id);
197 if (sensor_inst->report_state)
198 report_val = hid_sensor_get_usage_index(sensor_inst->hsdev,
199 sensor_inst->report_state->attribute.report_id,
200 sensor_inst->report_state->attribute.index,
201 report_state_usage_id);
202
203 if (power_val >= 0) {
204 power_val +=
205 sensor_inst->power_state->attribute.logical_minimum;
206 ret = sensor_hub_set_feature(sensor_inst->hsdev,
207 sensor_inst->power_state->attribute.report_id,
208 sensor_inst->power_state->attribute.index,
209 sizeof(power_val),
210 &power_val);
211 if (ret) {
212 hid_err(sensor_inst->hsdev->hdev,
213 "Set power state failed\n");
214 return ret;
215 }
216 }
217
218 if (report_val >= 0) {
219 report_val +=
220 sensor_inst->report_state->attribute.logical_minimum;
221 ret = sensor_hub_set_feature(sensor_inst->hsdev,
222 sensor_inst->report_state->attribute.report_id,
223 sensor_inst->report_state->attribute.index,
224 sizeof(report_val),
225 &report_val);
226 if (ret) {
227 hid_err(sensor_inst->hsdev->hdev,
228 "Set report state failed\n");
229 return ret;
230 }
231 }
232
233 return 0;
234}
235
236static ssize_t enable_sensor_store(struct device *dev,
237 struct device_attribute *attr,
238 const char *buf, size_t count)
239{
240 struct platform_device *pdev = to_platform_device(dev);
241 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
242 int value;
243 int ret = -EINVAL;
244
245 if (kstrtoint(buf, 0, &value) != 0)
246 return -EINVAL;
247
248 mutex_lock(&sensor_inst->mutex);
249 if (value && !sensor_inst->enable) {
250 ret = sensor_hub_device_open(sensor_inst->hsdev);
251 if (ret)
252 goto unlock_state;
253
254 ret = set_power_report_state(sensor_inst, true);
255 if (ret) {
256 sensor_hub_device_close(sensor_inst->hsdev);
257 goto unlock_state;
258 }
259 sensor_inst->enable = true;
260 } else if (!value && sensor_inst->enable) {
261 ret = set_power_report_state(sensor_inst, false);
262 sensor_hub_device_close(sensor_inst->hsdev);
263 sensor_inst->enable = false;
264 }
265unlock_state:
266 mutex_unlock(&sensor_inst->mutex);
267 if (ret < 0)
268 return ret;
269
270 return count;
271}
272static DEVICE_ATTR_RW(enable_sensor);
273
274static struct attribute *enable_sensor_attrs[] = {
275 &dev_attr_enable_sensor.attr,
276 NULL,
277};
278
279static struct attribute_group enable_sensor_attr_group = {
280 .attrs = enable_sensor_attrs,
281};
282
283static ssize_t show_value(struct device *dev, struct device_attribute *attr,
284 char *buf)
285{
286 struct platform_device *pdev = to_platform_device(dev);
287 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
288 struct hid_sensor_hub_attribute_info *attribute;
289 int index, usage, field_index;
290 char name[HID_CUSTOM_NAME_LENGTH];
291 bool feature = false;
292 bool input = false;
293 int value = 0;
294
295 if (sscanf(attr->attr.name, "feature-%d-%x-%s", &index, &usage,
296 name) == 3) {
297 feature = true;
298 field_index = index + sensor_inst->input_field_count;
299 } else if (sscanf(attr->attr.name, "input-%d-%x-%s", &index, &usage,
300 name) == 3) {
301 input = true;
302 field_index = index;
303 } else
304 return -EINVAL;
305
306 if (!strncmp(name, "value", strlen("value"))) {
307 u32 report_id;
308 int ret;
309
310 attribute = &sensor_inst->fields[field_index].attribute;
311 report_id = attribute->report_id;
312 if (feature) {
313 u8 values[HID_CUSTOM_MAX_FEATURE_BYTES];
314 int len = 0;
315 u64 value = 0;
316 int i = 0;
317
318 ret = sensor_hub_get_feature(sensor_inst->hsdev,
319 report_id,
320 index,
321 sizeof(values), values);
322 if (ret < 0)
323 return ret;
324
325 while (i < ret) {
326 if (i + attribute->size > ret) {
327 len += snprintf(&buf[len],
328 PAGE_SIZE - len,
329 "%d ", values[i]);
330 break;
331 }
332 switch (attribute->size) {
333 case 2:
334 value = (u64) *(u16 *)&values[i];
335 i += attribute->size;
336 break;
337 case 4:
338 value = (u64) *(u32 *)&values[i];
339 i += attribute->size;
340 break;
341 case 8:
342 value = *(u64 *)&values[i];
343 i += attribute->size;
344 break;
345 default:
346 value = (u64) values[i];
347 ++i;
348 break;
349 }
350 len += snprintf(&buf[len], PAGE_SIZE - len,
351 "%lld ", value);
352 }
353 len += snprintf(&buf[len], PAGE_SIZE - len, "\n");
354
355 return len;
356 } else if (input)
357 value = sensor_hub_input_attr_get_raw_value(
358 sensor_inst->hsdev,
359 sensor_inst->hsdev->usage,
360 usage, report_id,
361 SENSOR_HUB_SYNC);
362 } else if (!strncmp(name, "units", strlen("units")))
363 value = sensor_inst->fields[field_index].attribute.units;
364 else if (!strncmp(name, "unit-expo", strlen("unit-expo")))
365 value = sensor_inst->fields[field_index].attribute.unit_expo;
366 else if (!strncmp(name, "size", strlen("size")))
367 value = sensor_inst->fields[field_index].attribute.size;
368 else if (!strncmp(name, "minimum", strlen("minimum")))
369 value = sensor_inst->fields[field_index].attribute.
370 logical_minimum;
371 else if (!strncmp(name, "maximum", strlen("maximum")))
372 value = sensor_inst->fields[field_index].attribute.
373 logical_maximum;
374 else if (!strncmp(name, "name", strlen("name"))) {
375 struct hid_custom_usage_desc *usage_desc;
376
377 usage_desc = bsearch(&usage, hid_custom_usage_desc_table,
378 ARRAY_SIZE(hid_custom_usage_desc_table),
379 sizeof(struct hid_custom_usage_desc),
380 usage_id_cmp);
381 if (usage_desc)
382 return snprintf(buf, PAGE_SIZE, "%s\n",
383 usage_desc->desc);
384 else
385 return sprintf(buf, "not-specified\n");
386 } else
387 return -EINVAL;
388
389 return sprintf(buf, "%d\n", value);
390}
391
392static ssize_t store_value(struct device *dev, struct device_attribute *attr,
393 const char *buf, size_t count)
394{
395 struct platform_device *pdev = to_platform_device(dev);
396 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
397 int index, field_index, usage;
398 char name[HID_CUSTOM_NAME_LENGTH];
399 int value;
400
401 if (sscanf(attr->attr.name, "feature-%d-%x-%s", &index, &usage,
402 name) == 3) {
403 field_index = index + sensor_inst->input_field_count;
404 } else
405 return -EINVAL;
406
407 if (!strncmp(name, "value", strlen("value"))) {
408 u32 report_id;
409 int ret;
410
411 if (kstrtoint(buf, 0, &value) != 0)
412 return -EINVAL;
413
414 report_id = sensor_inst->fields[field_index].attribute.
415 report_id;
416 ret = sensor_hub_set_feature(sensor_inst->hsdev, report_id,
417 index, sizeof(value), &value);
418 } else
419 return -EINVAL;
420
421 return count;
422}
423
424static int hid_sensor_capture_sample(struct hid_sensor_hub_device *hsdev,
425 unsigned usage_id, size_t raw_len,
426 char *raw_data, void *priv)
427{
428 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(priv);
429 struct hid_sensor_sample header;
430
431 /* If any error occurs in a sample, rest of the fields are ignored */
432 if (sensor_inst->input_skip_sample) {
433 hid_err(sensor_inst->hsdev->hdev, "Skipped remaining data\n");
434 return 0;
435 }
436
437 hid_dbg(sensor_inst->hsdev->hdev, "%s received %d of %d\n", __func__,
438 (int) (sensor_inst->input_report_recd_size + raw_len),
439 sensor_inst->input_report_size);
440
441 if (!test_bit(0, &sensor_inst->misc_opened))
442 return 0;
443
444 if (!sensor_inst->input_report_recd_size) {
445 int required_size = sizeof(struct hid_sensor_sample) +
446 sensor_inst->input_report_size;
447 header.usage_id = hsdev->usage;
448 header.raw_len = sensor_inst->input_report_size;
449 header.timestamp = ktime_get_real_ns();
450 if (kfifo_avail(&sensor_inst->data_fifo) >= required_size) {
451 kfifo_in(&sensor_inst->data_fifo,
452 (unsigned char *)&header,
453 sizeof(header));
454 } else
455 sensor_inst->input_skip_sample = true;
456 }
457 if (kfifo_avail(&sensor_inst->data_fifo) >= raw_len)
458 kfifo_in(&sensor_inst->data_fifo, (unsigned char *)raw_data,
459 raw_len);
460
461 sensor_inst->input_report_recd_size += raw_len;
462
463 return 0;
464}
465
466static int hid_sensor_send_event(struct hid_sensor_hub_device *hsdev,
467 unsigned usage_id, void *priv)
468{
469 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(priv);
470
471 if (!test_bit(0, &sensor_inst->misc_opened))
472 return 0;
473
474 sensor_inst->input_report_recd_size = 0;
475 sensor_inst->input_skip_sample = false;
476
477 wake_up(&sensor_inst->wait);
478
479 return 0;
480}
481
482static int hid_sensor_custom_add_field(struct hid_sensor_custom *sensor_inst,
483 int index, int report_type,
484 struct hid_report *report,
485 struct hid_field *field)
486{
487 struct hid_sensor_custom_field *sensor_field;
488 void *fields;
489
490 fields = krealloc(sensor_inst->fields,
491 (sensor_inst->sensor_field_count + 1) *
492 sizeof(struct hid_sensor_custom_field), GFP_KERNEL);
493 if (!fields) {
494 kfree(sensor_inst->fields);
495 return -ENOMEM;
496 }
497 sensor_inst->fields = fields;
498 sensor_field = &sensor_inst->fields[sensor_inst->sensor_field_count];
499 sensor_field->attribute.usage_id = sensor_inst->hsdev->usage;
500 if (field->logical)
501 sensor_field->attribute.attrib_id = field->logical;
502 else
503 sensor_field->attribute.attrib_id = field->usage[0].hid;
504
505 sensor_field->attribute.index = index;
506 sensor_field->attribute.report_id = report->id;
507 sensor_field->attribute.units = field->unit;
508 sensor_field->attribute.unit_expo = field->unit_exponent;
509 sensor_field->attribute.size = (field->report_size / 8);
510 sensor_field->attribute.logical_minimum = field->logical_minimum;
511 sensor_field->attribute.logical_maximum = field->logical_maximum;
512
513 if (report_type == HID_FEATURE_REPORT)
514 snprintf(sensor_field->group_name,
515 sizeof(sensor_field->group_name), "feature-%x-%x",
516 sensor_field->attribute.index,
517 sensor_field->attribute.attrib_id);
518 else if (report_type == HID_INPUT_REPORT) {
519 snprintf(sensor_field->group_name,
520 sizeof(sensor_field->group_name),
521 "input-%x-%x", sensor_field->attribute.index,
522 sensor_field->attribute.attrib_id);
523 sensor_inst->input_field_count++;
524 sensor_inst->input_report_size += (field->report_size *
525 field->report_count) / 8;
526 }
527
528 memset(&sensor_field->hid_custom_attribute_group, 0,
529 sizeof(struct attribute_group));
530 sensor_inst->sensor_field_count++;
531
532 return 0;
533}
534
535static int hid_sensor_custom_add_fields(struct hid_sensor_custom *sensor_inst,
536 struct hid_report_enum *report_enum,
537 int report_type)
538{
539 int i;
540 int ret;
541 struct hid_report *report;
542 struct hid_field *field;
543 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev;
544
545 list_for_each_entry(report, &report_enum->report_list, list) {
546 for (i = 0; i < report->maxfield; ++i) {
547 field = report->field[i];
548 if (field->maxusage &&
549 ((field->usage[0].collection_index >=
550 hsdev->start_collection_index) &&
551 (field->usage[0].collection_index <
552 hsdev->end_collection_index))) {
553
554 ret = hid_sensor_custom_add_field(sensor_inst,
555 i,
556 report_type,
557 report,
558 field);
559 if (ret)
560 return ret;
561
562 }
563 }
564 }
565
566 return 0;
567}
568
569static int hid_sensor_custom_add_attributes(struct hid_sensor_custom
570 *sensor_inst)
571{
572 struct hid_sensor_hub_device *hsdev = sensor_inst->hsdev;
573 struct hid_device *hdev = hsdev->hdev;
574 int ret = -1;
575 int i, j;
576
577 for (j = 0; j < HID_REPORT_TYPES; ++j) {
578 if (j == HID_OUTPUT_REPORT)
579 continue;
580
581 ret = hid_sensor_custom_add_fields(sensor_inst,
582 &hdev->report_enum[j], j);
583 if (ret)
584 return ret;
585
586 }
587
588 /* Create sysfs attributes */
589 for (i = 0; i < sensor_inst->sensor_field_count; ++i) {
590 j = 0;
591 while (j < HID_CUSTOM_TOTAL_ATTRS &&
592 hid_custom_attrs[j].name) {
593 struct device_attribute *device_attr;
594
595 device_attr = &sensor_inst->fields[i].sd_attrs[j];
596
597 snprintf((char *)&sensor_inst->fields[i].attr_name[j],
598 HID_CUSTOM_NAME_LENGTH, "%s-%s",
599 sensor_inst->fields[i].group_name,
600 hid_custom_attrs[j].name);
601 sysfs_attr_init(&device_attr->attr);
602 device_attr->attr.name =
603 (char *)&sensor_inst->fields[i].attr_name[j];
604 device_attr->attr.mode = hid_custom_attrs[j].mode;
605 device_attr->show = show_value;
606 if (hid_custom_attrs[j].mode & S_IWUSR)
607 device_attr->store = store_value;
608 sensor_inst->fields[i].attrs[j] = &device_attr->attr;
609 ++j;
610 }
611 sensor_inst->fields[i].attrs[j] = NULL;
612 sensor_inst->fields[i].hid_custom_attribute_group.attrs =
613 sensor_inst->fields[i].attrs;
614 sensor_inst->fields[i].hid_custom_attribute_group.name =
615 sensor_inst->fields[i].group_name;
616 ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj,
617 &sensor_inst->fields[i].
618 hid_custom_attribute_group);
619 if (ret)
620 break;
621
622 /* For power or report field store indexes */
623 if (sensor_inst->fields[i].attribute.attrib_id ==
624 HID_USAGE_SENSOR_PROY_POWER_STATE)
625 sensor_inst->power_state = &sensor_inst->fields[i];
626 else if (sensor_inst->fields[i].attribute.attrib_id ==
627 HID_USAGE_SENSOR_PROP_REPORT_STATE)
628 sensor_inst->report_state = &sensor_inst->fields[i];
629 }
630
631 return ret;
632}
633
634static void hid_sensor_custom_remove_attributes(struct hid_sensor_custom *
635 sensor_inst)
636{
637 int i;
638
639 for (i = 0; i < sensor_inst->sensor_field_count; ++i)
640 sysfs_remove_group(&sensor_inst->pdev->dev.kobj,
641 &sensor_inst->fields[i].
642 hid_custom_attribute_group);
643
644 kfree(sensor_inst->fields);
645}
646
647static ssize_t hid_sensor_custom_read(struct file *file, char __user *buf,
648 size_t count, loff_t *f_ps)
649{
650 struct hid_sensor_custom *sensor_inst;
651 unsigned int copied;
652 int ret;
653
654 sensor_inst = container_of(file->private_data,
655 struct hid_sensor_custom, custom_dev);
656
657 if (count < sizeof(struct hid_sensor_sample))
658 return -EINVAL;
659
660 do {
661 if (kfifo_is_empty(&sensor_inst->data_fifo)) {
662 if (file->f_flags & O_NONBLOCK)
663 return -EAGAIN;
664
665 ret = wait_event_interruptible(sensor_inst->wait,
666 !kfifo_is_empty(&sensor_inst->data_fifo));
667 if (ret)
668 return ret;
669 }
670 ret = kfifo_to_user(&sensor_inst->data_fifo, buf, count,
671 &copied);
672 if (ret)
673 return ret;
674
675 } while (copied == 0);
676
677 return copied;
678}
679
680static int hid_sensor_custom_release(struct inode *inode, struct file *file)
681{
682 struct hid_sensor_custom *sensor_inst;
683
684 sensor_inst = container_of(file->private_data,
685 struct hid_sensor_custom, custom_dev);
686
687 clear_bit(0, &sensor_inst->misc_opened);
688
689 return 0;
690}
691
692static int hid_sensor_custom_open(struct inode *inode, struct file *file)
693{
694 struct hid_sensor_custom *sensor_inst;
695
696 sensor_inst = container_of(file->private_data,
697 struct hid_sensor_custom, custom_dev);
698 /* We essentially have single reader and writer */
699 if (test_and_set_bit(0, &sensor_inst->misc_opened))
700 return -EBUSY;
701
702 return nonseekable_open(inode, file);
703}
704
705static unsigned int hid_sensor_custom_poll(struct file *file,
706 struct poll_table_struct *wait)
707{
708 struct hid_sensor_custom *sensor_inst;
709 unsigned int mask = 0;
710
711 sensor_inst = container_of(file->private_data,
712 struct hid_sensor_custom, custom_dev);
713
714 poll_wait(file, &sensor_inst->wait, wait);
715
716 if (!kfifo_is_empty(&sensor_inst->data_fifo))
717 mask = POLLIN | POLLRDNORM;
718
719 return mask;
720}
721
722static const struct file_operations hid_sensor_custom_fops = {
723 .open = hid_sensor_custom_open,
724 .read = hid_sensor_custom_read,
725 .release = hid_sensor_custom_release,
726 .poll = hid_sensor_custom_poll,
727 .llseek = noop_llseek,
728};
729
730static int hid_sensor_custom_dev_if_add(struct hid_sensor_custom *sensor_inst)
731{
732 int ret;
733
734 ret = kfifo_alloc(&sensor_inst->data_fifo, HID_CUSTOM_FIFO_SIZE,
735 GFP_KERNEL);
736 if (ret)
737 return ret;
738
739 init_waitqueue_head(&sensor_inst->wait);
740
741 sensor_inst->custom_dev.minor = MISC_DYNAMIC_MINOR;
742 sensor_inst->custom_dev.name = dev_name(&sensor_inst->pdev->dev);
743 sensor_inst->custom_dev.fops = &hid_sensor_custom_fops,
744 ret = misc_register(&sensor_inst->custom_dev);
745 if (ret) {
746 kfifo_free(&sensor_inst->data_fifo);
747 return ret;
748 }
749 return 0;
750}
751
752static void hid_sensor_custom_dev_if_remove(struct hid_sensor_custom
753 *sensor_inst)
754{
755 wake_up(&sensor_inst->wait);
756 misc_deregister(&sensor_inst->custom_dev);
757 kfifo_free(&sensor_inst->data_fifo);
758
759}
760
761static int hid_sensor_custom_probe(struct platform_device *pdev)
762{
763 struct hid_sensor_custom *sensor_inst;
764 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
765 int ret;
766
767 sensor_inst = devm_kzalloc(&pdev->dev, sizeof(*sensor_inst),
768 GFP_KERNEL);
769 if (!sensor_inst)
770 return -ENOMEM;
771
772 sensor_inst->callbacks.capture_sample = hid_sensor_capture_sample;
773 sensor_inst->callbacks.send_event = hid_sensor_send_event;
774 sensor_inst->callbacks.pdev = pdev;
775 sensor_inst->hsdev = hsdev;
776 sensor_inst->pdev = pdev;
777 mutex_init(&sensor_inst->mutex);
778 platform_set_drvdata(pdev, sensor_inst);
779 ret = sensor_hub_register_callback(hsdev, hsdev->usage,
780 &sensor_inst->callbacks);
781 if (ret < 0) {
782 dev_err(&pdev->dev, "callback reg failed\n");
783 return ret;
784 }
785
786 ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj,
787 &enable_sensor_attr_group);
788 if (ret)
789 goto err_remove_callback;
790
791 ret = hid_sensor_custom_add_attributes(sensor_inst);
792 if (ret)
793 goto err_remove_group;
794
795 ret = hid_sensor_custom_dev_if_add(sensor_inst);
796 if (ret)
797 goto err_remove_attributes;
798
799 return 0;
800
801err_remove_attributes:
802 hid_sensor_custom_remove_attributes(sensor_inst);
803err_remove_group:
804 sysfs_remove_group(&sensor_inst->pdev->dev.kobj,
805 &enable_sensor_attr_group);
806err_remove_callback:
807 sensor_hub_remove_callback(hsdev, hsdev->usage);
808
809 return ret;
810}
811
812static int hid_sensor_custom_remove(struct platform_device *pdev)
813{
814 struct hid_sensor_custom *sensor_inst = platform_get_drvdata(pdev);
815 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
816
817 hid_sensor_custom_dev_if_remove(sensor_inst);
818 hid_sensor_custom_remove_attributes(sensor_inst);
819 sysfs_remove_group(&sensor_inst->pdev->dev.kobj,
820 &enable_sensor_attr_group);
821 sensor_hub_remove_callback(hsdev, hsdev->usage);
822
823 return 0;
824}
825
826static struct platform_device_id hid_sensor_custom_ids[] = {
827 {
828 .name = "HID-SENSOR-2000e1",
829 },
830 {
831 .name = "HID-SENSOR-2000e2",
832 },
833 { /* sentinel */ }
834};
835MODULE_DEVICE_TABLE(platform, hid_sensor_custom_ids);
836
837static struct platform_driver hid_sensor_custom_platform_driver = {
838 .id_table = hid_sensor_custom_ids,
839 .driver = {
840 .name = KBUILD_MODNAME,
841 },
842 .probe = hid_sensor_custom_probe,
843 .remove = hid_sensor_custom_remove,
844};
845module_platform_driver(hid_sensor_custom_platform_driver);
846
847MODULE_DESCRIPTION("HID Sensor Custom and Generic sensor Driver");
848MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
849MODULE_LICENSE("GPL");
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index e54ce1097e2c..c3f6f1e311ea 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -29,29 +29,10 @@
29#define HID_SENSOR_HUB_ENUM_QUIRK 0x01 29#define HID_SENSOR_HUB_ENUM_QUIRK 0x01
30 30
31/** 31/**
32 * struct sensor_hub_pending - Synchronous read pending information
33 * @status: Pending status true/false.
34 * @ready: Completion synchronization data.
35 * @usage_id: Usage id for physical device, E.g. Gyro usage id.
36 * @attr_usage_id: Usage Id of a field, E.g. X-AXIS for a gyro.
37 * @raw_size: Response size for a read request.
38 * @raw_data: Place holder for received response.
39 */
40struct sensor_hub_pending {
41 bool status;
42 struct completion ready;
43 u32 usage_id;
44 u32 attr_usage_id;
45 int raw_size;
46 u8 *raw_data;
47};
48
49/**
50 * struct sensor_hub_data - Hold a instance data for a HID hub device 32 * struct sensor_hub_data - Hold a instance data for a HID hub device
51 * @hsdev: Stored hid instance for current hub device. 33 * @hsdev: Stored hid instance for current hub device.
52 * @mutex: Mutex to serialize synchronous request. 34 * @mutex: Mutex to serialize synchronous request.
53 * @lock: Spin lock to protect pending request structure. 35 * @lock: Spin lock to protect pending request structure.
54 * @pending: Holds information of pending sync read request.
55 * @dyn_callback_list: Holds callback function 36 * @dyn_callback_list: Holds callback function
56 * @dyn_callback_lock: spin lock to protect callback list 37 * @dyn_callback_lock: spin lock to protect callback list
57 * @hid_sensor_hub_client_devs: Stores all MFD cells for a hub instance. 38 * @hid_sensor_hub_client_devs: Stores all MFD cells for a hub instance.
@@ -61,7 +42,6 @@ struct sensor_hub_pending {
61struct sensor_hub_data { 42struct sensor_hub_data {
62 struct mutex mutex; 43 struct mutex mutex;
63 spinlock_t lock; 44 spinlock_t lock;
64 struct sensor_hub_pending pending;
65 struct list_head dyn_callback_list; 45 struct list_head dyn_callback_list;
66 spinlock_t dyn_callback_lock; 46 spinlock_t dyn_callback_lock;
67 struct mfd_cell *hid_sensor_hub_client_devs; 47 struct mfd_cell *hid_sensor_hub_client_devs;
@@ -106,7 +86,8 @@ static int sensor_hub_get_physical_device_count(struct hid_device *hdev)
106 86
107 for (i = 0; i < hdev->maxcollection; ++i) { 87 for (i = 0; i < hdev->maxcollection; ++i) {
108 struct hid_collection *collection = &hdev->collection[i]; 88 struct hid_collection *collection = &hdev->collection[i];
109 if (collection->type == HID_COLLECTION_PHYSICAL) 89 if (collection->type == HID_COLLECTION_PHYSICAL ||
90 collection->type == HID_COLLECTION_APPLICATION)
110 ++count; 91 ++count;
111 } 92 }
112 93
@@ -139,7 +120,8 @@ static struct hid_sensor_hub_callbacks *sensor_hub_get_callback(
139 120
140 spin_lock_irqsave(&pdata->dyn_callback_lock, flags); 121 spin_lock_irqsave(&pdata->dyn_callback_lock, flags);
141 list_for_each_entry(callback, &pdata->dyn_callback_list, list) 122 list_for_each_entry(callback, &pdata->dyn_callback_list, list)
142 if (callback->usage_id == usage_id && 123 if ((callback->usage_id == usage_id ||
124 callback->usage_id == HID_USAGE_SENSOR_COLLECTION) &&
143 (collection_index >= 125 (collection_index >=
144 callback->hsdev->start_collection_index) && 126 callback->hsdev->start_collection_index) &&
145 (collection_index < 127 (collection_index <
@@ -179,7 +161,18 @@ int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
179 callback->usage_callback = usage_callback; 161 callback->usage_callback = usage_callback;
180 callback->usage_id = usage_id; 162 callback->usage_id = usage_id;
181 callback->priv = NULL; 163 callback->priv = NULL;
182 list_add_tail(&callback->list, &pdata->dyn_callback_list); 164 /*
165 * If there is a handler registered for the collection type, then
166 * it will handle all reports for sensors in this collection. If
167 * there is also an individual sensor handler registration, then
168 * we want to make sure that the reports are directed to collection
169 * handler, as this may be a fusion sensor. So add collection handlers
170 * to the beginning of the list, so that they are matched first.
171 */
172 if (usage_id == HID_USAGE_SENSOR_COLLECTION)
173 list_add(&callback->list, &pdata->dyn_callback_list);
174 else
175 list_add_tail(&callback->list, &pdata->dyn_callback_list);
183 spin_unlock_irqrestore(&pdata->dyn_callback_lock, flags); 176 spin_unlock_irqrestore(&pdata->dyn_callback_lock, flags);
184 177
185 return 0; 178 return 0;
@@ -208,10 +201,14 @@ int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
208EXPORT_SYMBOL_GPL(sensor_hub_remove_callback); 201EXPORT_SYMBOL_GPL(sensor_hub_remove_callback);
209 202
210int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, 203int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
211 u32 field_index, s32 value) 204 u32 field_index, int buffer_size, void *buffer)
212{ 205{
213 struct hid_report *report; 206 struct hid_report *report;
214 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev); 207 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
208 __s32 *buf32 = buffer;
209 int i = 0;
210 int remaining_bytes;
211 __s32 value;
215 int ret = 0; 212 int ret = 0;
216 213
217 mutex_lock(&data->mutex); 214 mutex_lock(&data->mutex);
@@ -220,7 +217,21 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
220 ret = -EINVAL; 217 ret = -EINVAL;
221 goto done_proc; 218 goto done_proc;
222 } 219 }
223 hid_set_field(report->field[field_index], 0, value); 220
221 remaining_bytes = do_div(buffer_size, sizeof(__s32));
222 if (buffer_size) {
223 for (i = 0; i < buffer_size; ++i) {
224 hid_set_field(report->field[field_index], i,
225 (__force __s32)cpu_to_le32(*buf32));
226 ++buf32;
227 }
228 }
229 if (remaining_bytes) {
230 value = 0;
231 memcpy(&value, (u8 *)buf32, remaining_bytes);
232 hid_set_field(report->field[field_index], i,
233 (__force __s32)cpu_to_le32(value));
234 }
224 hid_hw_request(hsdev->hdev, report, HID_REQ_SET_REPORT); 235 hid_hw_request(hsdev->hdev, report, HID_REQ_SET_REPORT);
225 hid_hw_wait(hsdev->hdev); 236 hid_hw_wait(hsdev->hdev);
226 237
@@ -232,10 +243,11 @@ done_proc:
232EXPORT_SYMBOL_GPL(sensor_hub_set_feature); 243EXPORT_SYMBOL_GPL(sensor_hub_set_feature);
233 244
234int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, 245int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
235 u32 field_index, s32 *value) 246 u32 field_index, int buffer_size, void *buffer)
236{ 247{
237 struct hid_report *report; 248 struct hid_report *report;
238 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev); 249 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
250 int report_size;
239 int ret = 0; 251 int ret = 0;
240 252
241 mutex_lock(&data->mutex); 253 mutex_lock(&data->mutex);
@@ -247,7 +259,17 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
247 } 259 }
248 hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT); 260 hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT);
249 hid_hw_wait(hsdev->hdev); 261 hid_hw_wait(hsdev->hdev);
250 *value = report->field[field_index]->value[0]; 262
263 /* calculate number of bytes required to read this field */
264 report_size = DIV_ROUND_UP(report->field[field_index]->report_size,
265 8) *
266 report->field[field_index]->report_count;
267 if (!report_size) {
268 ret = -EINVAL;
269 goto done_proc;
270 }
271 ret = min(report_size, buffer_size);
272 memcpy(buffer, report->field[field_index]->value, ret);
251 273
252done_proc: 274done_proc:
253 mutex_unlock(&data->mutex); 275 mutex_unlock(&data->mutex);
@@ -259,47 +281,54 @@ EXPORT_SYMBOL_GPL(sensor_hub_get_feature);
259 281
260int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, 282int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
261 u32 usage_id, 283 u32 usage_id,
262 u32 attr_usage_id, u32 report_id) 284 u32 attr_usage_id, u32 report_id,
285 enum sensor_hub_read_flags flag)
263{ 286{
264 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev); 287 struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
265 unsigned long flags; 288 unsigned long flags;
266 struct hid_report *report; 289 struct hid_report *report;
267 int ret_val = 0; 290 int ret_val = 0;
268 291
269 mutex_lock(&data->mutex); 292 report = sensor_hub_report(report_id, hsdev->hdev,
270 memset(&data->pending, 0, sizeof(data->pending)); 293 HID_INPUT_REPORT);
271 init_completion(&data->pending.ready);
272 data->pending.usage_id = usage_id;
273 data->pending.attr_usage_id = attr_usage_id;
274 data->pending.raw_size = 0;
275
276 spin_lock_irqsave(&data->lock, flags);
277 data->pending.status = true;
278 spin_unlock_irqrestore(&data->lock, flags);
279 report = sensor_hub_report(report_id, hsdev->hdev, HID_INPUT_REPORT);
280 if (!report) 294 if (!report)
281 goto err_free; 295 return -EINVAL;
282 296
283 hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT); 297 mutex_lock(&hsdev->mutex);
284 wait_for_completion_interruptible_timeout(&data->pending.ready, HZ*5); 298 if (flag == SENSOR_HUB_SYNC) {
285 switch (data->pending.raw_size) { 299 memset(&hsdev->pending, 0, sizeof(hsdev->pending));
286 case 1: 300 init_completion(&hsdev->pending.ready);
287 ret_val = *(u8 *)data->pending.raw_data; 301 hsdev->pending.usage_id = usage_id;
288 break; 302 hsdev->pending.attr_usage_id = attr_usage_id;
289 case 2: 303 hsdev->pending.raw_size = 0;
290 ret_val = *(u16 *)data->pending.raw_data; 304
291 break; 305 spin_lock_irqsave(&data->lock, flags);
292 case 4: 306 hsdev->pending.status = true;
293 ret_val = *(u32 *)data->pending.raw_data; 307 spin_unlock_irqrestore(&data->lock, flags);
294 break;
295 default:
296 ret_val = 0;
297 } 308 }
298 kfree(data->pending.raw_data); 309 mutex_lock(&data->mutex);
299 310 hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT);
300err_free:
301 data->pending.status = false;
302 mutex_unlock(&data->mutex); 311 mutex_unlock(&data->mutex);
312 if (flag == SENSOR_HUB_SYNC) {
313 wait_for_completion_interruptible_timeout(
314 &hsdev->pending.ready, HZ*5);
315 switch (hsdev->pending.raw_size) {
316 case 1:
317 ret_val = *(u8 *)hsdev->pending.raw_data;
318 break;
319 case 2:
320 ret_val = *(u16 *)hsdev->pending.raw_data;
321 break;
322 case 4:
323 ret_val = *(u32 *)hsdev->pending.raw_data;
324 break;
325 default:
326 ret_val = 0;
327 }
328 kfree(hsdev->pending.raw_data);
329 hsdev->pending.status = false;
330 }
331 mutex_unlock(&hsdev->mutex);
303 332
304 return ret_val; 333 return ret_val;
305} 334}
@@ -455,16 +484,6 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
455 report->field[i]->report_count)/8); 484 report->field[i]->report_count)/8);
456 sz = (report->field[i]->report_size * 485 sz = (report->field[i]->report_size *
457 report->field[i]->report_count)/8; 486 report->field[i]->report_count)/8;
458 if (pdata->pending.status && pdata->pending.attr_usage_id ==
459 report->field[i]->usage->hid) {
460 hid_dbg(hdev, "data was pending ...\n");
461 pdata->pending.raw_data = kmemdup(ptr, sz, GFP_ATOMIC);
462 if (pdata->pending.raw_data)
463 pdata->pending.raw_size = sz;
464 else
465 pdata->pending.raw_size = 0;
466 complete(&pdata->pending.ready);
467 }
468 collection = &hdev->collection[ 487 collection = &hdev->collection[
469 report->field[i]->usage->collection_index]; 488 report->field[i]->usage->collection_index];
470 hid_dbg(hdev, "collection->usage %x\n", 489 hid_dbg(hdev, "collection->usage %x\n",
@@ -474,8 +493,23 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
474 report->field[i]->physical, 493 report->field[i]->physical,
475 report->field[i]->usage[0].collection_index, 494 report->field[i]->usage[0].collection_index,
476 &hsdev, &priv); 495 &hsdev, &priv);
477 496 if (!callback) {
478 if (callback && callback->capture_sample) { 497 ptr += sz;
498 continue;
499 }
500 if (hsdev->pending.status && (hsdev->pending.attr_usage_id ==
501 report->field[i]->usage->hid ||
502 hsdev->pending.attr_usage_id ==
503 report->field[i]->logical)) {
504 hid_dbg(hdev, "data was pending ...\n");
505 hsdev->pending.raw_data = kmemdup(ptr, sz, GFP_ATOMIC);
506 if (hsdev->pending.raw_data)
507 hsdev->pending.raw_size = sz;
508 else
509 hsdev->pending.raw_size = 0;
510 complete(&hsdev->pending.ready);
511 }
512 if (callback->capture_sample) {
479 if (report->field[i]->logical) 513 if (report->field[i]->logical)
480 callback->capture_sample(hsdev, 514 callback->capture_sample(hsdev,
481 report->field[i]->logical, sz, ptr, 515 report->field[i]->logical, sz, ptr,
@@ -572,6 +606,7 @@ static int sensor_hub_probe(struct hid_device *hdev,
572 int dev_cnt; 606 int dev_cnt;
573 struct hid_sensor_hub_device *hsdev; 607 struct hid_sensor_hub_device *hsdev;
574 struct hid_sensor_hub_device *last_hsdev = NULL; 608 struct hid_sensor_hub_device *last_hsdev = NULL;
609 struct hid_sensor_hub_device *collection_hsdev = NULL;
575 610
576 sd = devm_kzalloc(&hdev->dev, sizeof(*sd), GFP_KERNEL); 611 sd = devm_kzalloc(&hdev->dev, sizeof(*sd), GFP_KERNEL);
577 if (!sd) { 612 if (!sd) {
@@ -618,7 +653,8 @@ static int sensor_hub_probe(struct hid_device *hdev,
618 for (i = 0; i < hdev->maxcollection; ++i) { 653 for (i = 0; i < hdev->maxcollection; ++i) {
619 struct hid_collection *collection = &hdev->collection[i]; 654 struct hid_collection *collection = &hdev->collection[i];
620 655
621 if (collection->type == HID_COLLECTION_PHYSICAL) { 656 if (collection->type == HID_COLLECTION_PHYSICAL ||
657 collection->type == HID_COLLECTION_APPLICATION) {
622 658
623 hsdev = devm_kzalloc(&hdev->dev, sizeof(*hsdev), 659 hsdev = devm_kzalloc(&hdev->dev, sizeof(*hsdev),
624 GFP_KERNEL); 660 GFP_KERNEL);
@@ -630,6 +666,8 @@ static int sensor_hub_probe(struct hid_device *hdev,
630 hsdev->hdev = hdev; 666 hsdev->hdev = hdev;
631 hsdev->vendor_id = hdev->vendor; 667 hsdev->vendor_id = hdev->vendor;
632 hsdev->product_id = hdev->product; 668 hsdev->product_id = hdev->product;
669 hsdev->usage = collection->usage;
670 mutex_init(&hsdev->mutex);
633 hsdev->start_collection_index = i; 671 hsdev->start_collection_index = i;
634 if (last_hsdev) 672 if (last_hsdev)
635 last_hsdev->end_collection_index = i; 673 last_hsdev->end_collection_index = i;
@@ -653,10 +691,17 @@ static int sensor_hub_probe(struct hid_device *hdev,
653 hid_dbg(hdev, "Adding %s:%d\n", name, 691 hid_dbg(hdev, "Adding %s:%d\n", name,
654 hsdev->start_collection_index); 692 hsdev->start_collection_index);
655 sd->hid_sensor_client_cnt++; 693 sd->hid_sensor_client_cnt++;
694 if (collection_hsdev)
695 collection_hsdev->end_collection_index = i;
696 if (collection->type == HID_COLLECTION_APPLICATION &&
697 collection->usage == HID_USAGE_SENSOR_COLLECTION)
698 collection_hsdev = hsdev;
656 } 699 }
657 } 700 }
658 if (last_hsdev) 701 if (last_hsdev)
659 last_hsdev->end_collection_index = i; 702 last_hsdev->end_collection_index = i;
703 if (collection_hsdev)
704 collection_hsdev->end_collection_index = i;
660 705
661 ret = mfd_add_hotplug_devices(&hdev->dev, 706 ret = mfd_add_hotplug_devices(&hdev->dev,
662 sd->hid_sensor_hub_client_devs, 707 sd->hid_sensor_hub_client_devs,
@@ -676,13 +721,18 @@ static void sensor_hub_remove(struct hid_device *hdev)
676{ 721{
677 struct sensor_hub_data *data = hid_get_drvdata(hdev); 722 struct sensor_hub_data *data = hid_get_drvdata(hdev);
678 unsigned long flags; 723 unsigned long flags;
724 int i;
679 725
680 hid_dbg(hdev, " hardware removed\n"); 726 hid_dbg(hdev, " hardware removed\n");
681 hid_hw_close(hdev); 727 hid_hw_close(hdev);
682 hid_hw_stop(hdev); 728 hid_hw_stop(hdev);
683 spin_lock_irqsave(&data->lock, flags); 729 spin_lock_irqsave(&data->lock, flags);
684 if (data->pending.status) 730 for (i = 0; i < data->hid_sensor_client_cnt; ++i) {
685 complete(&data->pending.ready); 731 struct hid_sensor_hub_device *hsdev =
732 data->hid_sensor_hub_client_devs[i].platform_data;
733 if (hsdev->pending.status)
734 complete(&hsdev->pending.ready);
735 }
686 spin_unlock_irqrestore(&data->lock, flags); 736 spin_unlock_irqrestore(&data->lock, flags);
687 mfd_remove_devices(&hdev->dev); 737 mfd_remove_devices(&hdev->dev);
688 hid_set_drvdata(hdev, NULL); 738 hid_set_drvdata(hdev, NULL);
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index c906300cf667..6ca96cebb44c 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -802,7 +802,8 @@ union sixaxis_output_report_01 {
802#define DS4_REPORT_0x05_SIZE 32 802#define DS4_REPORT_0x05_SIZE 32
803#define DS4_REPORT_0x11_SIZE 78 803#define DS4_REPORT_0x11_SIZE 78
804#define DS4_REPORT_0x81_SIZE 7 804#define DS4_REPORT_0x81_SIZE 7
805#define SIXAXIS_REPORT_0xF2_SIZE 18 805#define SIXAXIS_REPORT_0xF2_SIZE 17
806#define SIXAXIS_REPORT_0xF5_SIZE 8
806 807
807static DEFINE_SPINLOCK(sony_dev_list_lock); 808static DEFINE_SPINLOCK(sony_dev_list_lock);
808static LIST_HEAD(sony_device_list); 809static LIST_HEAD(sony_device_list);
@@ -1131,18 +1132,38 @@ static void sony_input_configured(struct hid_device *hdev,
1131 */ 1132 */
1132static int sixaxis_set_operational_usb(struct hid_device *hdev) 1133static int sixaxis_set_operational_usb(struct hid_device *hdev)
1133{ 1134{
1135 const int buf_size =
1136 max(SIXAXIS_REPORT_0xF2_SIZE, SIXAXIS_REPORT_0xF5_SIZE);
1137 __u8 *buf;
1134 int ret; 1138 int ret;
1135 char *buf = kmalloc(18, GFP_KERNEL);
1136 1139
1140 buf = kmalloc(buf_size, GFP_KERNEL);
1137 if (!buf) 1141 if (!buf)
1138 return -ENOMEM; 1142 return -ENOMEM;
1139 1143
1140 ret = hid_hw_raw_request(hdev, 0xf2, buf, 17, HID_FEATURE_REPORT, 1144 ret = hid_hw_raw_request(hdev, 0xf2, buf, SIXAXIS_REPORT_0xF2_SIZE,
1141 HID_REQ_GET_REPORT); 1145 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
1146 if (ret < 0) {
1147 hid_err(hdev, "can't set operational mode: step 1\n");
1148 goto out;
1149 }
1150
1151 /*
1152 * Some compatible controllers like the Speedlink Strike FX and
1153 * Gasia need another query plus an USB interrupt to get operational.
1154 */
1155 ret = hid_hw_raw_request(hdev, 0xf5, buf, SIXAXIS_REPORT_0xF5_SIZE,
1156 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
1157 if (ret < 0) {
1158 hid_err(hdev, "can't set operational mode: step 2\n");
1159 goto out;
1160 }
1142 1161
1162 ret = hid_hw_output_report(hdev, buf, 1);
1143 if (ret < 0) 1163 if (ret < 0)
1144 hid_err(hdev, "can't set operational mode\n"); 1164 hid_err(hdev, "can't set operational mode: step 3\n");
1145 1165
1166out:
1146 kfree(buf); 1167 kfree(buf);
1147 1168
1148 return ret; 1169 return ret;
diff --git a/drivers/hid/hid-steelseries.c b/drivers/hid/hid-steelseries.c
index 29f328f411fb..3edd4ac36494 100644
--- a/drivers/hid/hid-steelseries.c
+++ b/drivers/hid/hid-steelseries.c
@@ -12,7 +12,6 @@
12 */ 12 */
13 13
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/usb.h>
16#include <linux/hid.h> 15#include <linux/hid.h>
17#include <linux/module.h> 16#include <linux/module.h>
18 17
diff --git a/drivers/hid/hid-uclogic.c b/drivers/hid/hid-uclogic.c
index fb8b516ff0ed..94167310e15a 100644
--- a/drivers/hid/hid-uclogic.c
+++ b/drivers/hid/hid-uclogic.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * HID driver for UC-Logic devices not fully compliant with HID standard 2 * HID driver for UC-Logic devices not fully compliant with HID standard
3 * 3 *
4 * Copyright (c) 2010 Nikolai Kondrashov 4 * Copyright (c) 2010-2014 Nikolai Kondrashov
5 * Copyright (c) 2013 Martin Rusko
5 */ 6 */
6 7
7/* 8/*
@@ -15,6 +16,8 @@
15#include <linux/hid.h> 16#include <linux/hid.h>
16#include <linux/module.h> 17#include <linux/module.h>
17#include <linux/usb.h> 18#include <linux/usb.h>
19#include <asm/unaligned.h>
20#include "usbhid/usbhid.h"
18 21
19#include "hid-ids.h" 22#include "hid-ids.h"
20 23
@@ -546,11 +549,93 @@ static __u8 twha60_rdesc_fixed1[] = {
546 0xC0 /* End Collection */ 549 0xC0 /* End Collection */
547}; 550};
548 551
552/* Report descriptor template placeholder head */
553#define UCLOGIC_PH_HEAD 0xFE, 0xED, 0x1D
554
555/* Report descriptor template placeholder IDs */
556enum uclogic_ph_id {
557 UCLOGIC_PH_ID_X_LM,
558 UCLOGIC_PH_ID_X_PM,
559 UCLOGIC_PH_ID_Y_LM,
560 UCLOGIC_PH_ID_Y_PM,
561 UCLOGIC_PH_ID_PRESSURE_LM,
562 UCLOGIC_PH_ID_NUM
563};
564
565/* Report descriptor template placeholder */
566#define UCLOGIC_PH(_ID) UCLOGIC_PH_HEAD, UCLOGIC_PH_ID_##_ID
567#define UCLOGIC_PEN_REPORT_ID 0x07
568
569/* Fixed report descriptor template */
570static const __u8 uclogic_tablet_rdesc_template[] = {
571 0x05, 0x0D, /* Usage Page (Digitizer), */
572 0x09, 0x02, /* Usage (Pen), */
573 0xA1, 0x01, /* Collection (Application), */
574 0x85, 0x07, /* Report ID (7), */
575 0x09, 0x20, /* Usage (Stylus), */
576 0xA0, /* Collection (Physical), */
577 0x14, /* Logical Minimum (0), */
578 0x25, 0x01, /* Logical Maximum (1), */
579 0x75, 0x01, /* Report Size (1), */
580 0x09, 0x42, /* Usage (Tip Switch), */
581 0x09, 0x44, /* Usage (Barrel Switch), */
582 0x09, 0x46, /* Usage (Tablet Pick), */
583 0x95, 0x03, /* Report Count (3), */
584 0x81, 0x02, /* Input (Variable), */
585 0x95, 0x03, /* Report Count (3), */
586 0x81, 0x03, /* Input (Constant, Variable), */
587 0x09, 0x32, /* Usage (In Range), */
588 0x95, 0x01, /* Report Count (1), */
589 0x81, 0x02, /* Input (Variable), */
590 0x95, 0x01, /* Report Count (1), */
591 0x81, 0x03, /* Input (Constant, Variable), */
592 0x75, 0x10, /* Report Size (16), */
593 0x95, 0x01, /* Report Count (1), */
594 0xA4, /* Push, */
595 0x05, 0x01, /* Usage Page (Desktop), */
596 0x65, 0x13, /* Unit (Inch), */
597 0x55, 0xFD, /* Unit Exponent (-3), */
598 0x34, /* Physical Minimum (0), */
599 0x09, 0x30, /* Usage (X), */
600 0x27, UCLOGIC_PH(X_LM), /* Logical Maximum (PLACEHOLDER), */
601 0x47, UCLOGIC_PH(X_PM), /* Physical Maximum (PLACEHOLDER), */
602 0x81, 0x02, /* Input (Variable), */
603 0x09, 0x31, /* Usage (Y), */
604 0x27, UCLOGIC_PH(Y_LM), /* Logical Maximum (PLACEHOLDER), */
605 0x47, UCLOGIC_PH(Y_PM), /* Physical Maximum (PLACEHOLDER), */
606 0x81, 0x02, /* Input (Variable), */
607 0xB4, /* Pop, */
608 0x09, 0x30, /* Usage (Tip Pressure), */
609 0x27,
610 UCLOGIC_PH(PRESSURE_LM),/* Logical Maximum (PLACEHOLDER), */
611 0x81, 0x02, /* Input (Variable), */
612 0xC0, /* End Collection, */
613 0xC0 /* End Collection */
614};
615
616/* Parameter indices */
617enum uclogic_prm {
618 UCLOGIC_PRM_X_LM = 1,
619 UCLOGIC_PRM_Y_LM = 2,
620 UCLOGIC_PRM_PRESSURE_LM = 4,
621 UCLOGIC_PRM_RESOLUTION = 5,
622 UCLOGIC_PRM_NUM
623};
624
625/* Driver data */
626struct uclogic_drvdata {
627 __u8 *rdesc;
628 unsigned int rsize;
629 bool invert_pen_inrange;
630 bool ignore_pen_usage;
631};
632
549static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc, 633static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc,
550 unsigned int *rsize) 634 unsigned int *rsize)
551{ 635{
552 struct usb_interface *iface = to_usb_interface(hdev->dev.parent); 636 struct usb_interface *iface = to_usb_interface(hdev->dev.parent);
553 __u8 iface_num = iface->cur_altsetting->desc.bInterfaceNumber; 637 __u8 iface_num = iface->cur_altsetting->desc.bInterfaceNumber;
638 struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev);
554 639
555 switch (hdev->product) { 640 switch (hdev->product) {
556 case USB_DEVICE_ID_UCLOGIC_TABLET_PF1209: 641 case USB_DEVICE_ID_UCLOGIC_TABLET_PF1209:
@@ -621,11 +706,241 @@ static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc,
621 break; 706 break;
622 } 707 }
623 break; 708 break;
709 default:
710 if (drvdata->rdesc != NULL) {
711 rdesc = drvdata->rdesc;
712 *rsize = drvdata->rsize;
713 }
624 } 714 }
625 715
626 return rdesc; 716 return rdesc;
627} 717}
628 718
719static int uclogic_input_mapping(struct hid_device *hdev, struct hid_input *hi,
720 struct hid_field *field, struct hid_usage *usage,
721 unsigned long **bit, int *max)
722{
723 struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev);
724
725 /* discard the unused pen interface */
726 if ((drvdata->ignore_pen_usage) &&
727 (field->application == HID_DG_PEN))
728 return -1;
729
730 /* let hid-core decide what to do */
731 return 0;
732}
733
734static void uclogic_input_configured(struct hid_device *hdev,
735 struct hid_input *hi)
736{
737 char *name;
738 const char *suffix = NULL;
739 struct hid_field *field;
740 size_t len;
741
742 /* no report associated (HID_QUIRK_MULTI_INPUT not set) */
743 if (!hi->report)
744 return;
745
746 field = hi->report->field[0];
747
748 switch (field->application) {
749 case HID_GD_KEYBOARD:
750 suffix = "Keyboard";
751 break;
752 case HID_GD_MOUSE:
753 suffix = "Mouse";
754 break;
755 case HID_GD_KEYPAD:
756 suffix = "Pad";
757 break;
758 case HID_DG_PEN:
759 suffix = "Pen";
760 break;
761 case HID_CP_CONSUMER_CONTROL:
762 suffix = "Consumer Control";
763 break;
764 case HID_GD_SYSTEM_CONTROL:
765 suffix = "System Control";
766 break;
767 }
768
769 if (suffix) {
770 len = strlen(hdev->name) + 2 + strlen(suffix);
771 name = devm_kzalloc(&hi->input->dev, len, GFP_KERNEL);
772 if (name) {
773 snprintf(name, len, "%s %s", hdev->name, suffix);
774 hi->input->name = name;
775 }
776 }
777}
778
779/**
780 * Enable fully-functional tablet mode and determine device parameters.
781 *
782 * @hdev: HID device
783 */
784static int uclogic_tablet_enable(struct hid_device *hdev)
785{
786 int rc;
787 struct usb_device *usb_dev = hid_to_usb_dev(hdev);
788 struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev);
789 __le16 *buf = NULL;
790 size_t len;
791 s32 params[UCLOGIC_PH_ID_NUM];
792 s32 resolution;
793 __u8 *p;
794 s32 v;
795
796 /*
797 * Read string descriptor containing tablet parameters. The specific
798 * string descriptor and data were discovered by sniffing the Windows
799 * driver traffic.
800 * NOTE: This enables fully-functional tablet mode.
801 */
802 len = UCLOGIC_PRM_NUM * sizeof(*buf);
803 buf = kmalloc(len, GFP_KERNEL);
804 if (buf == NULL) {
805 hid_err(hdev, "failed to allocate parameter buffer\n");
806 rc = -ENOMEM;
807 goto cleanup;
808 }
809 rc = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
810 USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
811 (USB_DT_STRING << 8) + 0x64,
812 0x0409, buf, len,
813 USB_CTRL_GET_TIMEOUT);
814 if (rc == -EPIPE) {
815 hid_err(hdev, "device parameters not found\n");
816 rc = -ENODEV;
817 goto cleanup;
818 } else if (rc < 0) {
819 hid_err(hdev, "failed to get device parameters: %d\n", rc);
820 rc = -ENODEV;
821 goto cleanup;
822 } else if (rc != len) {
823 hid_err(hdev, "invalid device parameters\n");
824 rc = -ENODEV;
825 goto cleanup;
826 }
827
828 /* Extract device parameters */
829 params[UCLOGIC_PH_ID_X_LM] = le16_to_cpu(buf[UCLOGIC_PRM_X_LM]);
830 params[UCLOGIC_PH_ID_Y_LM] = le16_to_cpu(buf[UCLOGIC_PRM_Y_LM]);
831 params[UCLOGIC_PH_ID_PRESSURE_LM] =
832 le16_to_cpu(buf[UCLOGIC_PRM_PRESSURE_LM]);
833 resolution = le16_to_cpu(buf[UCLOGIC_PRM_RESOLUTION]);
834 if (resolution == 0) {
835 params[UCLOGIC_PH_ID_X_PM] = 0;
836 params[UCLOGIC_PH_ID_Y_PM] = 0;
837 } else {
838 params[UCLOGIC_PH_ID_X_PM] = params[UCLOGIC_PH_ID_X_LM] *
839 1000 / resolution;
840 params[UCLOGIC_PH_ID_Y_PM] = params[UCLOGIC_PH_ID_Y_LM] *
841 1000 / resolution;
842 }
843
844 /* Allocate fixed report descriptor */
845 drvdata->rdesc = devm_kzalloc(&hdev->dev,
846 sizeof(uclogic_tablet_rdesc_template),
847 GFP_KERNEL);
848 if (drvdata->rdesc == NULL) {
849 hid_err(hdev, "failed to allocate fixed rdesc\n");
850 rc = -ENOMEM;
851 goto cleanup;
852 }
853 drvdata->rsize = sizeof(uclogic_tablet_rdesc_template);
854
855 /* Format fixed report descriptor */
856 memcpy(drvdata->rdesc, uclogic_tablet_rdesc_template,
857 drvdata->rsize);
858 for (p = drvdata->rdesc;
859 p <= drvdata->rdesc + drvdata->rsize - 4;) {
860 if (p[0] == 0xFE && p[1] == 0xED && p[2] == 0x1D &&
861 p[3] < sizeof(params)) {
862 v = params[p[3]];
863 put_unaligned(cpu_to_le32(v), (s32 *)p);
864 p += 4;
865 } else {
866 p++;
867 }
868 }
869
870 rc = 0;
871
872cleanup:
873 kfree(buf);
874 return rc;
875}
876
877static int uclogic_probe(struct hid_device *hdev,
878 const struct hid_device_id *id)
879{
880 int rc;
881 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
882 struct uclogic_drvdata *drvdata;
883
884 /*
885 * libinput requires the pad interface to be on a different node
886 * than the pen, so use QUIRK_MULTI_INPUT for all tablets.
887 */
888 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
889 hdev->quirks |= HID_QUIRK_NO_EMPTY_INPUT;
890
891 /* Allocate and assign driver data */
892 drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL);
893 if (drvdata == NULL)
894 return -ENOMEM;
895
896 hid_set_drvdata(hdev, drvdata);
897
898 switch (id->product) {
899 case USB_DEVICE_ID_HUION_TABLET:
900 /* If this is the pen interface */
901 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
902 rc = uclogic_tablet_enable(hdev);
903 if (rc) {
904 hid_err(hdev, "tablet enabling failed\n");
905 return rc;
906 }
907 drvdata->invert_pen_inrange = true;
908 } else {
909 drvdata->ignore_pen_usage = true;
910 }
911 break;
912 }
913
914 rc = hid_parse(hdev);
915 if (rc) {
916 hid_err(hdev, "parse failed\n");
917 return rc;
918 }
919
920 rc = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
921 if (rc) {
922 hid_err(hdev, "hw start failed\n");
923 return rc;
924 }
925
926 return 0;
927}
928
929static int uclogic_raw_event(struct hid_device *hdev, struct hid_report *report,
930 u8 *data, int size)
931{
932 struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev);
933
934 if ((drvdata->invert_pen_inrange) &&
935 (report->type == HID_INPUT_REPORT) &&
936 (report->id == UCLOGIC_PEN_REPORT_ID) &&
937 (size >= 2))
938 /* Invert the in-range bit */
939 data[1] ^= 0x40;
940
941 return 0;
942}
943
629static const struct hid_device_id uclogic_devices[] = { 944static const struct hid_device_id uclogic_devices[] = {
630 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, 945 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
631 USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) }, 946 USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
@@ -641,6 +956,8 @@ static const struct hid_device_id uclogic_devices[] = {
641 USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) }, 956 USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) },
642 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, 957 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
643 USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) }, 958 USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) },
959 { HID_USB_DEVICE(USB_VENDOR_ID_HUION, USB_DEVICE_ID_HUION_TABLET) },
960 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_HUION_TABLET) },
644 { } 961 { }
645}; 962};
646MODULE_DEVICE_TABLE(hid, uclogic_devices); 963MODULE_DEVICE_TABLE(hid, uclogic_devices);
@@ -648,8 +965,14 @@ MODULE_DEVICE_TABLE(hid, uclogic_devices);
648static struct hid_driver uclogic_driver = { 965static struct hid_driver uclogic_driver = {
649 .name = "uclogic", 966 .name = "uclogic",
650 .id_table = uclogic_devices, 967 .id_table = uclogic_devices,
968 .probe = uclogic_probe,
651 .report_fixup = uclogic_report_fixup, 969 .report_fixup = uclogic_report_fixup,
970 .raw_event = uclogic_raw_event,
971 .input_mapping = uclogic_input_mapping,
972 .input_configured = uclogic_input_configured,
652}; 973};
653module_hid_driver(uclogic_driver); 974module_hid_driver(uclogic_driver);
654 975
976MODULE_AUTHOR("Martin Rusko");
977MODULE_AUTHOR("Nikolai Kondrashov");
655MODULE_LICENSE("GPL"); 978MODULE_LICENSE("GPL");
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index 36053f33d6d9..ab4dd952b6ba 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -37,6 +37,7 @@
37#include <linux/mutex.h> 37#include <linux/mutex.h>
38#include <linux/acpi.h> 38#include <linux/acpi.h>
39#include <linux/of.h> 39#include <linux/of.h>
40#include <linux/gpio/consumer.h>
40 41
41#include <linux/i2c/i2c-hid.h> 42#include <linux/i2c/i2c-hid.h>
42 43
@@ -144,6 +145,8 @@ struct i2c_hid {
144 unsigned long flags; /* device flags */ 145 unsigned long flags; /* device flags */
145 146
146 wait_queue_head_t wait; /* For waiting the interrupt */ 147 wait_queue_head_t wait; /* For waiting the interrupt */
148 struct gpio_desc *desc;
149 int irq;
147 150
148 struct i2c_hid_platform_data pdata; 151 struct i2c_hid_platform_data pdata;
149}; 152};
@@ -785,16 +788,16 @@ static int i2c_hid_init_irq(struct i2c_client *client)
785 struct i2c_hid *ihid = i2c_get_clientdata(client); 788 struct i2c_hid *ihid = i2c_get_clientdata(client);
786 int ret; 789 int ret;
787 790
788 dev_dbg(&client->dev, "Requesting IRQ: %d\n", client->irq); 791 dev_dbg(&client->dev, "Requesting IRQ: %d\n", ihid->irq);
789 792
790 ret = request_threaded_irq(client->irq, NULL, i2c_hid_irq, 793 ret = request_threaded_irq(ihid->irq, NULL, i2c_hid_irq,
791 IRQF_TRIGGER_LOW | IRQF_ONESHOT, 794 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
792 client->name, ihid); 795 client->name, ihid);
793 if (ret < 0) { 796 if (ret < 0) {
794 dev_warn(&client->dev, 797 dev_warn(&client->dev,
795 "Could not register for %s interrupt, irq = %d," 798 "Could not register for %s interrupt, irq = %d,"
796 " ret = %d\n", 799 " ret = %d\n",
797 client->name, client->irq, ret); 800 client->name, ihid->irq, ret);
798 801
799 return ret; 802 return ret;
800 } 803 }
@@ -841,6 +844,14 @@ static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)
841} 844}
842 845
843#ifdef CONFIG_ACPI 846#ifdef CONFIG_ACPI
847
848/* Default GPIO mapping */
849static const struct acpi_gpio_params i2c_hid_irq_gpio = { 0, 0, true };
850static const struct acpi_gpio_mapping i2c_hid_acpi_gpios[] = {
851 { "gpios", &i2c_hid_irq_gpio, 1 },
852 { },
853};
854
844static int i2c_hid_acpi_pdata(struct i2c_client *client, 855static int i2c_hid_acpi_pdata(struct i2c_client *client,
845 struct i2c_hid_platform_data *pdata) 856 struct i2c_hid_platform_data *pdata)
846{ 857{
@@ -866,7 +877,7 @@ static int i2c_hid_acpi_pdata(struct i2c_client *client,
866 pdata->hid_descriptor_address = obj->integer.value; 877 pdata->hid_descriptor_address = obj->integer.value;
867 ACPI_FREE(obj); 878 ACPI_FREE(obj);
868 879
869 return 0; 880 return acpi_dev_add_driver_gpios(adev, i2c_hid_acpi_gpios);
870} 881}
871 882
872static const struct acpi_device_id i2c_hid_acpi_match[] = { 883static const struct acpi_device_id i2c_hid_acpi_match[] = {
@@ -930,12 +941,6 @@ static int i2c_hid_probe(struct i2c_client *client,
930 941
931 dbg_hid("HID probe called for i2c 0x%02x\n", client->addr); 942 dbg_hid("HID probe called for i2c 0x%02x\n", client->addr);
932 943
933 if (!client->irq) {
934 dev_err(&client->dev,
935 "HID over i2c has not been provided an Int IRQ\n");
936 return -EINVAL;
937 }
938
939 ihid = kzalloc(sizeof(struct i2c_hid), GFP_KERNEL); 944 ihid = kzalloc(sizeof(struct i2c_hid), GFP_KERNEL);
940 if (!ihid) 945 if (!ihid)
941 return -ENOMEM; 946 return -ENOMEM;
@@ -955,6 +960,23 @@ static int i2c_hid_probe(struct i2c_client *client,
955 ihid->pdata = *platform_data; 960 ihid->pdata = *platform_data;
956 } 961 }
957 962
963 if (client->irq > 0) {
964 ihid->irq = client->irq;
965 } else if (ACPI_COMPANION(&client->dev)) {
966 ihid->desc = gpiod_get(&client->dev, NULL, GPIOD_IN);
967 if (IS_ERR(ihid->desc)) {
968 dev_err(&client->dev, "Failed to get GPIO interrupt\n");
969 return PTR_ERR(ihid->desc);
970 }
971
972 ihid->irq = gpiod_to_irq(ihid->desc);
973 if (ihid->irq < 0) {
974 gpiod_put(ihid->desc);
975 dev_err(&client->dev, "Failed to convert GPIO to IRQ\n");
976 return ihid->irq;
977 }
978 }
979
958 i2c_set_clientdata(client, ihid); 980 i2c_set_clientdata(client, ihid);
959 981
960 ihid->client = client; 982 ihid->client = client;
@@ -1017,13 +1039,16 @@ err_mem_free:
1017 hid_destroy_device(hid); 1039 hid_destroy_device(hid);
1018 1040
1019err_irq: 1041err_irq:
1020 free_irq(client->irq, ihid); 1042 free_irq(ihid->irq, ihid);
1021 1043
1022err_pm: 1044err_pm:
1023 pm_runtime_put_noidle(&client->dev); 1045 pm_runtime_put_noidle(&client->dev);
1024 pm_runtime_disable(&client->dev); 1046 pm_runtime_disable(&client->dev);
1025 1047
1026err: 1048err:
1049 if (ihid->desc)
1050 gpiod_put(ihid->desc);
1051
1027 i2c_hid_free_buffers(ihid); 1052 i2c_hid_free_buffers(ihid);
1028 kfree(ihid); 1053 kfree(ihid);
1029 return ret; 1054 return ret;
@@ -1042,13 +1067,18 @@ static int i2c_hid_remove(struct i2c_client *client)
1042 hid = ihid->hid; 1067 hid = ihid->hid;
1043 hid_destroy_device(hid); 1068 hid_destroy_device(hid);
1044 1069
1045 free_irq(client->irq, ihid); 1070 free_irq(ihid->irq, ihid);
1046 1071
1047 if (ihid->bufsize) 1072 if (ihid->bufsize)
1048 i2c_hid_free_buffers(ihid); 1073 i2c_hid_free_buffers(ihid);
1049 1074
1075 if (ihid->desc)
1076 gpiod_put(ihid->desc);
1077
1050 kfree(ihid); 1078 kfree(ihid);
1051 1079
1080 acpi_dev_remove_driver_gpios(ACPI_COMPANION(&client->dev));
1081
1052 return 0; 1082 return 0;
1053} 1083}
1054 1084
@@ -1060,9 +1090,9 @@ static int i2c_hid_suspend(struct device *dev)
1060 struct hid_device *hid = ihid->hid; 1090 struct hid_device *hid = ihid->hid;
1061 int ret = 0; 1091 int ret = 0;
1062 1092
1063 disable_irq(client->irq); 1093 disable_irq(ihid->irq);
1064 if (device_may_wakeup(&client->dev)) 1094 if (device_may_wakeup(&client->dev))
1065 enable_irq_wake(client->irq); 1095 enable_irq_wake(ihid->irq);
1066 1096
1067 if (hid->driver && hid->driver->suspend) 1097 if (hid->driver && hid->driver->suspend)
1068 ret = hid->driver->suspend(hid, PMSG_SUSPEND); 1098 ret = hid->driver->suspend(hid, PMSG_SUSPEND);
@@ -1080,13 +1110,13 @@ static int i2c_hid_resume(struct device *dev)
1080 struct i2c_hid *ihid = i2c_get_clientdata(client); 1110 struct i2c_hid *ihid = i2c_get_clientdata(client);
1081 struct hid_device *hid = ihid->hid; 1111 struct hid_device *hid = ihid->hid;
1082 1112
1083 enable_irq(client->irq); 1113 enable_irq(ihid->irq);
1084 ret = i2c_hid_hwreset(client); 1114 ret = i2c_hid_hwreset(client);
1085 if (ret) 1115 if (ret)
1086 return ret; 1116 return ret;
1087 1117
1088 if (device_may_wakeup(&client->dev)) 1118 if (device_may_wakeup(&client->dev))
1089 disable_irq_wake(client->irq); 1119 disable_irq_wake(ihid->irq);
1090 1120
1091 if (hid->driver && hid->driver->reset_resume) { 1121 if (hid->driver && hid->driver->reset_resume) {
1092 ret = hid->driver->reset_resume(hid); 1122 ret = hid->driver->reset_resume(hid);
@@ -1101,17 +1131,19 @@ static int i2c_hid_resume(struct device *dev)
1101static int i2c_hid_runtime_suspend(struct device *dev) 1131static int i2c_hid_runtime_suspend(struct device *dev)
1102{ 1132{
1103 struct i2c_client *client = to_i2c_client(dev); 1133 struct i2c_client *client = to_i2c_client(dev);
1134 struct i2c_hid *ihid = i2c_get_clientdata(client);
1104 1135
1105 i2c_hid_set_power(client, I2C_HID_PWR_SLEEP); 1136 i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
1106 disable_irq(client->irq); 1137 disable_irq(ihid->irq);
1107 return 0; 1138 return 0;
1108} 1139}
1109 1140
1110static int i2c_hid_runtime_resume(struct device *dev) 1141static int i2c_hid_runtime_resume(struct device *dev)
1111{ 1142{
1112 struct i2c_client *client = to_i2c_client(dev); 1143 struct i2c_client *client = to_i2c_client(dev);
1144 struct i2c_hid *ihid = i2c_get_clientdata(client);
1113 1145
1114 enable_irq(client->irq); 1146 enable_irq(ihid->irq);
1115 i2c_hid_set_power(client, I2C_HID_PWR_ON); 1147 i2c_hid_set_power(client, I2C_HID_PWR_ON);
1116 return 0; 1148 return 0;
1117} 1149}
diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c
index 0b531c6a76a5..08174d341f4a 100644
--- a/drivers/hid/usbhid/hid-pidff.c
+++ b/drivers/hid/usbhid/hid-pidff.c
@@ -568,6 +568,12 @@ static int pidff_upload_effect(struct input_dev *dev, struct ff_effect *effect,
568 int type_id; 568 int type_id;
569 int error; 569 int error;
570 570
571 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] = 0;
572 if (old) {
573 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] =
574 pidff->pid_id[effect->id];
575 }
576
571 switch (effect->type) { 577 switch (effect->type) {
572 case FF_CONSTANT: 578 case FF_CONSTANT:
573 if (!old) { 579 if (!old) {
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index a82127753461..a775143e6265 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -78,7 +78,13 @@ static const struct hid_blacklist {
78 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET }, 78 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET },
79 { USB_VENDOR_ID_FORMOSA, USB_DEVICE_ID_FORMOSA_IR_RECEIVER, HID_QUIRK_NO_INIT_REPORTS }, 79 { USB_VENDOR_ID_FORMOSA, USB_DEVICE_ID_FORMOSA_IR_RECEIVER, HID_QUIRK_NO_INIT_REPORTS },
80 { USB_VENDOR_ID_FREESCALE, USB_DEVICE_ID_FREESCALE_MX28, HID_QUIRK_NOGET }, 80 { USB_VENDOR_ID_FREESCALE, USB_DEVICE_ID_FREESCALE_MX28, HID_QUIRK_NOGET },
81 { USB_VENDOR_ID_HP, USB_PRODUCT_ID_HP_LOGITECH_OEM_USB_OPTICAL_MOUSE_0A4A, HID_QUIRK_ALWAYS_POLL },
82 { USB_VENDOR_ID_HP, USB_PRODUCT_ID_HP_LOGITECH_OEM_USB_OPTICAL_MOUSE_0B4A, HID_QUIRK_ALWAYS_POLL },
83 { USB_VENDOR_ID_HP, USB_PRODUCT_ID_HP_PIXART_OEM_USB_OPTICAL_MOUSE, HID_QUIRK_ALWAYS_POLL },
81 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_C077, HID_QUIRK_ALWAYS_POLL }, 84 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_C077, HID_QUIRK_ALWAYS_POLL },
85 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOUSE_C01A, HID_QUIRK_ALWAYS_POLL },
86 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOUSE_C05A, HID_QUIRK_ALWAYS_POLL },
87 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOUSE_C06A, HID_QUIRK_ALWAYS_POLL },
82 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_NOGET }, 88 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_NOGET },
83 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_3, HID_QUIRK_NO_INIT_REPORTS }, 89 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_3, HID_QUIRK_NO_INIT_REPORTS },
84 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_3_JP, HID_QUIRK_NO_INIT_REPORTS }, 90 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_3_JP, HID_QUIRK_NO_INIT_REPORTS },
@@ -92,6 +98,7 @@ static const struct hid_blacklist {
92 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NO_INIT_REPORTS }, 98 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NO_INIT_REPORTS },
93 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1, HID_QUIRK_NO_INIT_REPORTS }, 99 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1, HID_QUIRK_NO_INIT_REPORTS },
94 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2, HID_QUIRK_NO_INIT_REPORTS }, 100 { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN2, HID_QUIRK_NO_INIT_REPORTS },
101 { USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_MOUSE_4D22, HID_QUIRK_ALWAYS_POLL },
95 { USB_VENDOR_ID_PRODIGE, USB_DEVICE_ID_PRODIGE_CORDLESS, HID_QUIRK_NOGET }, 102 { USB_VENDOR_ID_PRODIGE, USB_DEVICE_ID_PRODIGE_CORDLESS, HID_QUIRK_NOGET },
96 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001, HID_QUIRK_NOGET }, 103 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3001, HID_QUIRK_NOGET },
97 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008, HID_QUIRK_NOGET }, 104 { USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH_3008, HID_QUIRK_NOGET },
@@ -107,12 +114,8 @@ static const struct hid_blacklist {
107 { USB_VENDOR_ID_SYMBOL, USB_DEVICE_ID_SYMBOL_SCANNER_2, HID_QUIRK_NOGET }, 114 { USB_VENDOR_ID_SYMBOL, USB_DEVICE_ID_SYMBOL_SCANNER_2, HID_QUIRK_NOGET },
108 { USB_VENDOR_ID_TPV, USB_DEVICE_ID_TPV_OPTICAL_TOUCHSCREEN, HID_QUIRK_NOGET }, 115 { USB_VENDOR_ID_TPV, USB_DEVICE_ID_TPV_OPTICAL_TOUCHSCREEN, HID_QUIRK_NOGET },
109 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET }, 116 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET },
110 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209, HID_QUIRK_MULTI_INPUT },
111 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U, HID_QUIRK_MULTI_INPUT },
112 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_KNA5, HID_QUIRK_MULTI_INPUT }, 117 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_KNA5, HID_QUIRK_MULTI_INPUT },
113 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWA60, HID_QUIRK_MULTI_INPUT }, 118 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWA60, HID_QUIRK_MULTI_INPUT },
114 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U, HID_QUIRK_MULTI_INPUT },
115 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U, HID_QUIRK_MULTI_INPUT },
116 { USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH, HID_QUIRK_MULTI_INPUT }, 119 { USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH, HID_QUIRK_MULTI_INPUT },
117 { USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH, HID_QUIRK_MULTI_INPUT }, 120 { USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH, HID_QUIRK_MULTI_INPUT },
118 { USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET, HID_QUIRK_MULTI_INPUT }, 121 { USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET, HID_QUIRK_MULTI_INPUT },
@@ -128,6 +131,7 @@ static const struct hid_blacklist {
128 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X, HID_QUIRK_MULTI_INPUT }, 131 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X, HID_QUIRK_MULTI_INPUT },
129 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2, HID_QUIRK_MULTI_INPUT }, 132 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X_2, HID_QUIRK_MULTI_INPUT },
130 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X, HID_QUIRK_MULTI_INPUT }, 133 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X, HID_QUIRK_MULTI_INPUT },
134 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_PENSKETCH_M912, HID_QUIRK_MULTI_INPUT },
131 { USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_DUOSENSE, HID_QUIRK_NO_INIT_REPORTS }, 135 { USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_DUOSENSE, HID_QUIRK_NO_INIT_REPORTS },
132 { USB_VENDOR_ID_SEMICO, USB_DEVICE_ID_SEMICO_USB_KEYKOARD, HID_QUIRK_NO_INIT_REPORTS }, 136 { USB_VENDOR_ID_SEMICO, USB_DEVICE_ID_SEMICO_USB_KEYKOARD, HID_QUIRK_NO_INIT_REPORTS },
133 { USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_LTS1, HID_QUIRK_NO_INIT_REPORTS }, 137 { USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_LTS1, HID_QUIRK_NO_INIT_REPORTS },
diff --git a/drivers/hid/wacom.h b/drivers/hid/wacom.h
index 0d0d0dd89d17..024f4d89d579 100644
--- a/drivers/hid/wacom.h
+++ b/drivers/hid/wacom.h
@@ -131,13 +131,6 @@ static inline void wacom_schedule_work(struct wacom_wac *wacom_wac)
131 schedule_work(&wacom->work); 131 schedule_work(&wacom->work);
132} 132}
133 133
134static inline void wacom_notify_battery(struct wacom_wac *wacom_wac)
135{
136 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
137
138 power_supply_changed(wacom->battery);
139}
140
141extern const struct hid_device_id wacom_ids[]; 134extern const struct hid_device_id wacom_ids[];
142 135
143void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len); 136void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len);
@@ -151,4 +144,5 @@ void wacom_wac_usage_mapping(struct hid_device *hdev,
151int wacom_wac_event(struct hid_device *hdev, struct hid_field *field, 144int wacom_wac_event(struct hid_device *hdev, struct hid_field *field,
152 struct hid_usage *usage, __s32 value); 145 struct hid_usage *usage, __s32 value);
153void wacom_wac_report(struct hid_device *hdev, struct hid_report *report); 146void wacom_wac_report(struct hid_device *hdev, struct hid_report *report);
147void wacom_battery_work(struct work_struct *work);
154#endif 148#endif
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index ba9af470bea0..e8607d096138 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -406,6 +406,9 @@ static int wacom_query_tablet_data(struct hid_device *hdev,
406 else if (features->type == WACOM_27QHDT) { 406 else if (features->type == WACOM_27QHDT) {
407 return wacom_set_device_mode(hdev, 131, 3, 2); 407 return wacom_set_device_mode(hdev, 131, 3, 2);
408 } 408 }
409 else if (features->type == BAMBOO_PAD) {
410 return wacom_set_device_mode(hdev, 2, 2, 2);
411 }
409 } else if (features->device_type == BTN_TOOL_PEN) { 412 } else if (features->device_type == BTN_TOOL_PEN) {
410 if (features->type <= BAMBOO_PT && features->type != WIRELESS) { 413 if (features->type <= BAMBOO_PT && features->type != WIRELESS) {
411 return wacom_set_device_mode(hdev, 2, 2, 2); 414 return wacom_set_device_mode(hdev, 2, 2, 2);
@@ -524,6 +527,11 @@ static int wacom_add_shared_data(struct hid_device *hdev)
524 527
525 wacom_wac->shared = &data->shared; 528 wacom_wac->shared = &data->shared;
526 529
530 if (wacom_wac->features.device_type == BTN_TOOL_FINGER)
531 wacom_wac->shared->touch = hdev;
532 else if (wacom_wac->features.device_type == BTN_TOOL_PEN)
533 wacom_wac->shared->pen = hdev;
534
527out: 535out:
528 mutex_unlock(&wacom_udev_list_lock); 536 mutex_unlock(&wacom_udev_list_lock);
529 return retval; 537 return retval;
@@ -541,14 +549,22 @@ static void wacom_release_shared_data(struct kref *kref)
541 kfree(data); 549 kfree(data);
542} 550}
543 551
544static void wacom_remove_shared_data(struct wacom_wac *wacom) 552static void wacom_remove_shared_data(struct wacom *wacom)
545{ 553{
546 struct wacom_hdev_data *data; 554 struct wacom_hdev_data *data;
555 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
556
557 if (wacom_wac->shared) {
558 data = container_of(wacom_wac->shared, struct wacom_hdev_data,
559 shared);
560
561 if (wacom_wac->shared->touch == wacom->hdev)
562 wacom_wac->shared->touch = NULL;
563 else if (wacom_wac->shared->pen == wacom->hdev)
564 wacom_wac->shared->pen = NULL;
547 565
548 if (wacom->shared) {
549 data = container_of(wacom->shared, struct wacom_hdev_data, shared);
550 kref_put(&data->kref, wacom_release_shared_data); 566 kref_put(&data->kref, wacom_release_shared_data);
551 wacom->shared = NULL; 567 wacom_wac->shared = NULL;
552 } 568 }
553} 569}
554 570
@@ -929,6 +945,7 @@ static void wacom_destroy_leds(struct wacom *wacom)
929} 945}
930 946
931static enum power_supply_property wacom_battery_props[] = { 947static enum power_supply_property wacom_battery_props[] = {
948 POWER_SUPPLY_PROP_PRESENT,
932 POWER_SUPPLY_PROP_STATUS, 949 POWER_SUPPLY_PROP_STATUS,
933 POWER_SUPPLY_PROP_SCOPE, 950 POWER_SUPPLY_PROP_SCOPE,
934 POWER_SUPPLY_PROP_CAPACITY 951 POWER_SUPPLY_PROP_CAPACITY
@@ -948,6 +965,9 @@ static int wacom_battery_get_property(struct power_supply *psy,
948 int ret = 0; 965 int ret = 0;
949 966
950 switch (psp) { 967 switch (psp) {
968 case POWER_SUPPLY_PROP_PRESENT:
969 val->intval = wacom->wacom_wac.bat_connected;
970 break;
951 case POWER_SUPPLY_PROP_SCOPE: 971 case POWER_SUPPLY_PROP_SCOPE:
952 val->intval = POWER_SUPPLY_SCOPE_DEVICE; 972 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
953 break; 973 break;
@@ -961,6 +981,8 @@ static int wacom_battery_get_property(struct power_supply *psy,
961 else if (wacom->wacom_wac.battery_capacity == 100 && 981 else if (wacom->wacom_wac.battery_capacity == 100 &&
962 wacom->wacom_wac.ps_connected) 982 wacom->wacom_wac.ps_connected)
963 val->intval = POWER_SUPPLY_STATUS_FULL; 983 val->intval = POWER_SUPPLY_STATUS_FULL;
984 else if (wacom->wacom_wac.ps_connected)
985 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
964 else 986 else
965 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; 987 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
966 break; 988 break;
@@ -1045,8 +1067,7 @@ static int wacom_initialize_battery(struct wacom *wacom)
1045 1067
1046static void wacom_destroy_battery(struct wacom *wacom) 1068static void wacom_destroy_battery(struct wacom *wacom)
1047{ 1069{
1048 if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) && 1070 if (wacom->battery) {
1049 wacom->battery) {
1050 power_supply_unregister(wacom->battery); 1071 power_supply_unregister(wacom->battery);
1051 wacom->battery = NULL; 1072 wacom->battery = NULL;
1052 power_supply_unregister(wacom->ac); 1073 power_supply_unregister(wacom->ac);
@@ -1317,6 +1338,20 @@ fail:
1317 return; 1338 return;
1318} 1339}
1319 1340
1341void wacom_battery_work(struct work_struct *work)
1342{
1343 struct wacom *wacom = container_of(work, struct wacom, work);
1344
1345 if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
1346 !wacom->battery) {
1347 wacom_initialize_battery(wacom);
1348 }
1349 else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
1350 wacom->battery) {
1351 wacom_destroy_battery(wacom);
1352 }
1353}
1354
1320/* 1355/*
1321 * Not all devices report physical dimensions from HID. 1356 * Not all devices report physical dimensions from HID.
1322 * Compute the default from hardcoded logical dimension 1357 * Compute the default from hardcoded logical dimension
@@ -1377,6 +1412,9 @@ static int wacom_probe(struct hid_device *hdev,
1377 1412
1378 hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; 1413 hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
1379 1414
1415 /* hid-core sets this quirk for the boot interface */
1416 hdev->quirks &= ~HID_QUIRK_NOGET;
1417
1380 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL); 1418 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
1381 if (!wacom) 1419 if (!wacom)
1382 return -ENOMEM; 1420 return -ENOMEM;
@@ -1416,6 +1454,21 @@ static int wacom_probe(struct hid_device *hdev,
1416 goto fail_allocate_inputs; 1454 goto fail_allocate_inputs;
1417 } 1455 }
1418 1456
1457 /*
1458 * Bamboo Pad has a generic hid handling for the Pen, and we switch it
1459 * into debug mode for the touch part.
1460 * We ignore the other interfaces.
1461 */
1462 if (features->type == BAMBOO_PAD) {
1463 if (features->pktlen == WACOM_PKGLEN_PENABLED) {
1464 features->type = HID_GENERIC;
1465 } else if ((features->pktlen != WACOM_PKGLEN_BPAD_TOUCH) &&
1466 (features->pktlen != WACOM_PKGLEN_BPAD_TOUCH_USB)) {
1467 error = -ENODEV;
1468 goto fail_shared_data;
1469 }
1470 }
1471
1419 /* set the default size in case we do not get them from hid */ 1472 /* set the default size in case we do not get them from hid */
1420 wacom_set_default_phy(features); 1473 wacom_set_default_phy(features);
1421 1474
@@ -1450,6 +1503,12 @@ static int wacom_probe(struct hid_device *hdev,
1450 features->y_max = 4096; 1503 features->y_max = 4096;
1451 } 1504 }
1452 1505
1506 /*
1507 * Same thing for Bamboo PAD
1508 */
1509 if (features->type == BAMBOO_PAD)
1510 features->device_type = BTN_TOOL_FINGER;
1511
1453 if (hdev->bus == BUS_BLUETOOTH) 1512 if (hdev->bus == BUS_BLUETOOTH)
1454 features->quirks |= WACOM_QUIRK_BATTERY; 1513 features->quirks |= WACOM_QUIRK_BATTERY;
1455 1514
@@ -1466,19 +1525,17 @@ static int wacom_probe(struct hid_device *hdev,
1466 snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name), 1525 snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
1467 "%s Pad", features->name); 1526 "%s Pad", features->name);
1468 1527
1469 if (features->quirks & WACOM_QUIRK_MULTI_INPUT) { 1528 /* Append the device type to the name */
1470 /* Append the device type to the name */ 1529 if (features->device_type != BTN_TOOL_FINGER)
1471 if (features->device_type != BTN_TOOL_FINGER) 1530 strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX);
1472 strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX); 1531 else if (features->touch_max)
1473 else if (features->touch_max) 1532 strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX);
1474 strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX); 1533 else
1475 else 1534 strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX);
1476 strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX);
1477 1535
1478 error = wacom_add_shared_data(hdev); 1536 error = wacom_add_shared_data(hdev);
1479 if (error) 1537 if (error)
1480 goto fail_shared_data; 1538 goto fail_shared_data;
1481 }
1482 1539
1483 if (!(features->quirks & WACOM_QUIRK_MONITOR) && 1540 if (!(features->quirks & WACOM_QUIRK_MONITOR) &&
1484 (features->quirks & WACOM_QUIRK_BATTERY)) { 1541 (features->quirks & WACOM_QUIRK_BATTERY)) {
@@ -1531,7 +1588,7 @@ fail_register_inputs:
1531 wacom_clean_inputs(wacom); 1588 wacom_clean_inputs(wacom);
1532 wacom_destroy_battery(wacom); 1589 wacom_destroy_battery(wacom);
1533fail_battery: 1590fail_battery:
1534 wacom_remove_shared_data(wacom_wac); 1591 wacom_remove_shared_data(wacom);
1535fail_shared_data: 1592fail_shared_data:
1536 wacom_clean_inputs(wacom); 1593 wacom_clean_inputs(wacom);
1537fail_allocate_inputs: 1594fail_allocate_inputs:
@@ -1554,7 +1611,7 @@ static void wacom_remove(struct hid_device *hdev)
1554 if (hdev->bus == BUS_BLUETOOTH) 1611 if (hdev->bus == BUS_BLUETOOTH)
1555 device_remove_file(&hdev->dev, &dev_attr_speed); 1612 device_remove_file(&hdev->dev, &dev_attr_speed);
1556 wacom_destroy_battery(wacom); 1613 wacom_destroy_battery(wacom);
1557 wacom_remove_shared_data(&wacom->wacom_wac); 1614 wacom_remove_shared_data(wacom);
1558 1615
1559 hid_set_drvdata(hdev, NULL); 1616 hid_set_drvdata(hdev, NULL);
1560 kfree(wacom); 1617 kfree(wacom);
diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index bbe32d66e500..fa54d3290659 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -45,6 +45,27 @@ static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
45 */ 45 */
46static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 }; 46static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
47 47
48static void wacom_notify_battery(struct wacom_wac *wacom_wac,
49 int bat_capacity, bool bat_charging, bool bat_connected,
50 bool ps_connected)
51{
52 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
53 bool changed = wacom_wac->battery_capacity != bat_capacity ||
54 wacom_wac->bat_charging != bat_charging ||
55 wacom_wac->bat_connected != bat_connected ||
56 wacom_wac->ps_connected != ps_connected;
57
58 if (changed) {
59 wacom_wac->battery_capacity = bat_capacity;
60 wacom_wac->bat_charging = bat_charging;
61 wacom_wac->bat_connected = bat_connected;
62 wacom_wac->ps_connected = ps_connected;
63
64 if (wacom->battery)
65 power_supply_changed(wacom->battery);
66 }
67}
68
48static int wacom_penpartner_irq(struct wacom_wac *wacom) 69static int wacom_penpartner_irq(struct wacom_wac *wacom)
49{ 70{
50 unsigned char *data = wacom->data; 71 unsigned char *data = wacom->data;
@@ -419,17 +440,26 @@ static int wacom_graphire_irq(struct wacom_wac *wacom)
419 rw = (data[7] >> 2 & 0x07); 440 rw = (data[7] >> 2 & 0x07);
420 battery_capacity = batcap_gr[rw]; 441 battery_capacity = batcap_gr[rw];
421 ps_connected = rw == 7; 442 ps_connected = rw == 7;
422 if ((wacom->battery_capacity != battery_capacity) || 443 wacom_notify_battery(wacom, battery_capacity, ps_connected,
423 (wacom->ps_connected != ps_connected)) { 444 1, ps_connected);
424 wacom->battery_capacity = battery_capacity;
425 wacom->ps_connected = ps_connected;
426 wacom_notify_battery(wacom);
427 }
428 } 445 }
429exit: 446exit:
430 return retval; 447 return retval;
431} 448}
432 449
450static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac)
451{
452 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
453 struct hid_report *r;
454 struct hid_report_enum *re;
455
456 re = &(wacom->hdev->report_enum[HID_FEATURE_REPORT]);
457 r = re->report_id_hash[WACOM_REPORT_INTUOSREAD];
458 if (r) {
459 hid_hw_request(wacom->hdev, r, HID_REQ_GET_REPORT);
460 }
461}
462
433static int wacom_intuos_inout(struct wacom_wac *wacom) 463static int wacom_intuos_inout(struct wacom_wac *wacom)
434{ 464{
435 struct wacom_features *features = &wacom->features; 465 struct wacom_features *features = &wacom->features;
@@ -551,12 +581,9 @@ static int wacom_intuos_inout(struct wacom_wac *wacom)
551 (features->type == CINTIQ && !(data[1] & 0x40))) 581 (features->type == CINTIQ && !(data[1] & 0x40)))
552 return 1; 582 return 1;
553 583
554 if (wacom->shared) { 584 wacom->shared->stylus_in_proximity = true;
555 wacom->shared->stylus_in_proximity = true; 585 if (wacom->shared->touch_down)
556 586 return 1;
557 if (wacom->shared->touch_down)
558 return 1;
559 }
560 587
561 /* in Range while exiting */ 588 /* in Range while exiting */
562 if (((data[1] & 0xfe) == 0x20) && wacom->reporting_data) { 589 if (((data[1] & 0xfe) == 0x20) && wacom->reporting_data) {
@@ -568,8 +595,7 @@ static int wacom_intuos_inout(struct wacom_wac *wacom)
568 595
569 /* Exit report */ 596 /* Exit report */
570 if ((data[1] & 0xfe) == 0x80) { 597 if ((data[1] & 0xfe) == 0x80) {
571 if (features->quirks & WACOM_QUIRK_MULTI_INPUT) 598 wacom->shared->stylus_in_proximity = false;
572 wacom->shared->stylus_in_proximity = false;
573 wacom->reporting_data = false; 599 wacom->reporting_data = false;
574 600
575 /* don't report exit if we don't know the ID */ 601 /* don't report exit if we don't know the ID */
@@ -610,8 +636,11 @@ static int wacom_intuos_inout(struct wacom_wac *wacom)
610 } 636 }
611 637
612 /* don't report other events if we don't know the ID */ 638 /* don't report other events if we don't know the ID */
613 if (!wacom->id[idx]) 639 if (!wacom->id[idx]) {
640 /* but reschedule a read of the current tool */
641 wacom_intuos_schedule_prox_event(wacom);
614 return 1; 642 return 1;
643 }
615 644
616 return 0; 645 return 0;
617} 646}
@@ -1023,15 +1052,9 @@ static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
1023 bat_charging = (power_raw & 0x08) ? 1 : 0; 1052 bat_charging = (power_raw & 0x08) ? 1 : 0;
1024 ps_connected = (power_raw & 0x10) ? 1 : 0; 1053 ps_connected = (power_raw & 0x10) ? 1 : 0;
1025 battery_capacity = batcap_i4[power_raw & 0x07]; 1054 battery_capacity = batcap_i4[power_raw & 0x07];
1026 if ((wacom->battery_capacity != battery_capacity) || 1055 wacom_notify_battery(wacom, battery_capacity, bat_charging,
1027 (wacom->bat_charging != bat_charging) || 1056 battery_capacity || bat_charging,
1028 (wacom->ps_connected != ps_connected)) { 1057 ps_connected);
1029 wacom->battery_capacity = battery_capacity;
1030 wacom->bat_charging = bat_charging;
1031 wacom->ps_connected = ps_connected;
1032 wacom_notify_battery(wacom);
1033 }
1034
1035 break; 1058 break;
1036 default: 1059 default:
1037 dev_dbg(wacom->input->dev.parent, 1060 dev_dbg(wacom->input->dev.parent,
@@ -1042,6 +1065,28 @@ static int wacom_intuos_bt_irq(struct wacom_wac *wacom, size_t len)
1042 return 0; 1065 return 0;
1043} 1066}
1044 1067
1068static int wacom_wac_finger_count_touches(struct wacom_wac *wacom)
1069{
1070 struct input_dev *input = wacom->input;
1071 unsigned touch_max = wacom->features.touch_max;
1072 int count = 0;
1073 int i;
1074
1075 /* non-HID_GENERIC single touch input doesn't call this routine */
1076 if ((touch_max == 1) && (wacom->features.type == HID_GENERIC))
1077 return wacom->hid_data.tipswitch &&
1078 !wacom->shared->stylus_in_proximity;
1079
1080 for (i = 0; i < input->mt->num_slots; i++) {
1081 struct input_mt_slot *ps = &input->mt->slots[i];
1082 int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
1083 if (id >= 0)
1084 count++;
1085 }
1086
1087 return count;
1088}
1089
1045static int wacom_24hdt_irq(struct wacom_wac *wacom) 1090static int wacom_24hdt_irq(struct wacom_wac *wacom)
1046{ 1091{
1047 struct input_dev *input = wacom->input; 1092 struct input_dev *input = wacom->input;
@@ -1052,7 +1097,6 @@ static int wacom_24hdt_irq(struct wacom_wac *wacom)
1052 int num_contacts_left = 4; /* maximum contacts per packet */ 1097 int num_contacts_left = 4; /* maximum contacts per packet */
1053 int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET; 1098 int byte_per_packet = WACOM_BYTES_PER_24HDT_PACKET;
1054 int y_offset = 2; 1099 int y_offset = 2;
1055 static int contact_with_no_pen_down_count = 0;
1056 1100
1057 if (wacom->features.type == WACOM_27QHDT) { 1101 if (wacom->features.type == WACOM_27QHDT) {
1058 current_num_contacts = data[63]; 1102 current_num_contacts = data[63];
@@ -1065,10 +1109,8 @@ static int wacom_24hdt_irq(struct wacom_wac *wacom)
1065 * First packet resets the counter since only the first 1109 * First packet resets the counter since only the first
1066 * packet in series will have non-zero current_num_contacts. 1110 * packet in series will have non-zero current_num_contacts.
1067 */ 1111 */
1068 if (current_num_contacts) { 1112 if (current_num_contacts)
1069 wacom->num_contacts_left = current_num_contacts; 1113 wacom->num_contacts_left = current_num_contacts;
1070 contact_with_no_pen_down_count = 0;
1071 }
1072 1114
1073 contacts_to_send = min(num_contacts_left, wacom->num_contacts_left); 1115 contacts_to_send = min(num_contacts_left, wacom->num_contacts_left);
1074 1116
@@ -1101,15 +1143,14 @@ static int wacom_24hdt_irq(struct wacom_wac *wacom)
1101 input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h)); 1143 input_report_abs(input, ABS_MT_WIDTH_MINOR, min(w, h));
1102 input_report_abs(input, ABS_MT_ORIENTATION, w > h); 1144 input_report_abs(input, ABS_MT_ORIENTATION, w > h);
1103 } 1145 }
1104 contact_with_no_pen_down_count++;
1105 } 1146 }
1106 } 1147 }
1107 input_mt_report_pointer_emulation(input, true); 1148 input_mt_sync_frame(input);
1108 1149
1109 wacom->num_contacts_left -= contacts_to_send; 1150 wacom->num_contacts_left -= contacts_to_send;
1110 if (wacom->num_contacts_left <= 0) { 1151 if (wacom->num_contacts_left <= 0) {
1111 wacom->num_contacts_left = 0; 1152 wacom->num_contacts_left = 0;
1112 wacom->shared->touch_down = (contact_with_no_pen_down_count > 0); 1153 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1113 } 1154 }
1114 return 1; 1155 return 1;
1115} 1156}
@@ -1122,7 +1163,6 @@ static int wacom_mt_touch(struct wacom_wac *wacom)
1122 int current_num_contacts = data[2]; 1163 int current_num_contacts = data[2];
1123 int contacts_to_send = 0; 1164 int contacts_to_send = 0;
1124 int x_offset = 0; 1165 int x_offset = 0;
1125 static int contact_with_no_pen_down_count = 0;
1126 1166
1127 /* MTTPC does not support Height and Width */ 1167 /* MTTPC does not support Height and Width */
1128 if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B) 1168 if (wacom->features.type == MTTPC || wacom->features.type == MTTPC_B)
@@ -1132,10 +1172,8 @@ static int wacom_mt_touch(struct wacom_wac *wacom)
1132 * First packet resets the counter since only the first 1172 * First packet resets the counter since only the first
1133 * packet in series will have non-zero current_num_contacts. 1173 * packet in series will have non-zero current_num_contacts.
1134 */ 1174 */
1135 if (current_num_contacts) { 1175 if (current_num_contacts)
1136 wacom->num_contacts_left = current_num_contacts; 1176 wacom->num_contacts_left = current_num_contacts;
1137 contact_with_no_pen_down_count = 0;
1138 }
1139 1177
1140 /* There are at most 5 contacts per packet */ 1178 /* There are at most 5 contacts per packet */
1141 contacts_to_send = min(5, wacom->num_contacts_left); 1179 contacts_to_send = min(5, wacom->num_contacts_left);
@@ -1156,15 +1194,14 @@ static int wacom_mt_touch(struct wacom_wac *wacom)
1156 int y = get_unaligned_le16(&data[offset + x_offset + 9]); 1194 int y = get_unaligned_le16(&data[offset + x_offset + 9]);
1157 input_report_abs(input, ABS_MT_POSITION_X, x); 1195 input_report_abs(input, ABS_MT_POSITION_X, x);
1158 input_report_abs(input, ABS_MT_POSITION_Y, y); 1196 input_report_abs(input, ABS_MT_POSITION_Y, y);
1159 contact_with_no_pen_down_count++;
1160 } 1197 }
1161 } 1198 }
1162 input_mt_report_pointer_emulation(input, true); 1199 input_mt_sync_frame(input);
1163 1200
1164 wacom->num_contacts_left -= contacts_to_send; 1201 wacom->num_contacts_left -= contacts_to_send;
1165 if (wacom->num_contacts_left <= 0) { 1202 if (wacom->num_contacts_left <= 0) {
1166 wacom->num_contacts_left = 0; 1203 wacom->num_contacts_left = 0;
1167 wacom->shared->touch_down = (contact_with_no_pen_down_count > 0); 1204 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1168 } 1205 }
1169 return 1; 1206 return 1;
1170} 1207}
@@ -1173,7 +1210,6 @@ static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
1173{ 1210{
1174 struct input_dev *input = wacom->input; 1211 struct input_dev *input = wacom->input;
1175 unsigned char *data = wacom->data; 1212 unsigned char *data = wacom->data;
1176 int contact_with_no_pen_down_count = 0;
1177 int i; 1213 int i;
1178 1214
1179 for (i = 0; i < 2; i++) { 1215 for (i = 0; i < 2; i++) {
@@ -1188,13 +1224,12 @@ static int wacom_tpc_mt_touch(struct wacom_wac *wacom)
1188 1224
1189 input_report_abs(input, ABS_MT_POSITION_X, x); 1225 input_report_abs(input, ABS_MT_POSITION_X, x);
1190 input_report_abs(input, ABS_MT_POSITION_Y, y); 1226 input_report_abs(input, ABS_MT_POSITION_Y, y);
1191 contact_with_no_pen_down_count++;
1192 } 1227 }
1193 } 1228 }
1194 input_mt_report_pointer_emulation(input, true); 1229 input_mt_sync_frame(input);
1195 1230
1196 /* keep touch state for pen event */ 1231 /* keep touch state for pen event */
1197 wacom->shared->touch_down = (contact_with_no_pen_down_count > 0); 1232 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1198 1233
1199 return 1; 1234 return 1;
1200} 1235}
@@ -1522,29 +1557,6 @@ static int wacom_wac_finger_event(struct hid_device *hdev,
1522 return 0; 1557 return 0;
1523} 1558}
1524 1559
1525static int wacom_wac_finger_count_touches(struct hid_device *hdev)
1526{
1527 struct wacom *wacom = hid_get_drvdata(hdev);
1528 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
1529 struct input_dev *input = wacom_wac->input;
1530 unsigned touch_max = wacom_wac->features.touch_max;
1531 int count = 0;
1532 int i;
1533
1534 if (touch_max == 1)
1535 return wacom_wac->hid_data.tipswitch &&
1536 !wacom_wac->shared->stylus_in_proximity;
1537
1538 for (i = 0; i < input->mt->num_slots; i++) {
1539 struct input_mt_slot *ps = &input->mt->slots[i];
1540 int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
1541 if (id >= 0)
1542 count++;
1543 }
1544
1545 return count;
1546}
1547
1548static void wacom_wac_finger_report(struct hid_device *hdev, 1560static void wacom_wac_finger_report(struct hid_device *hdev,
1549 struct hid_report *report) 1561 struct hid_report *report)
1550{ 1562{
@@ -1559,7 +1571,7 @@ static void wacom_wac_finger_report(struct hid_device *hdev,
1559 input_sync(input); 1571 input_sync(input);
1560 1572
1561 /* keep touch state for pen event */ 1573 /* keep touch state for pen event */
1562 wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(hdev); 1574 wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac);
1563} 1575}
1564 1576
1565void wacom_wac_usage_mapping(struct hid_device *hdev, 1577void wacom_wac_usage_mapping(struct hid_device *hdev,
@@ -1619,7 +1631,6 @@ static int wacom_bpt_touch(struct wacom_wac *wacom)
1619 struct input_dev *pad_input = wacom->pad_input; 1631 struct input_dev *pad_input = wacom->pad_input;
1620 unsigned char *data = wacom->data; 1632 unsigned char *data = wacom->data;
1621 int i; 1633 int i;
1622 int contact_with_no_pen_down_count = 0;
1623 1634
1624 if (data[0] != 0x02) 1635 if (data[0] != 0x02)
1625 return 0; 1636 return 0;
@@ -1647,22 +1658,21 @@ static int wacom_bpt_touch(struct wacom_wac *wacom)
1647 } 1658 }
1648 input_report_abs(input, ABS_MT_POSITION_X, x); 1659 input_report_abs(input, ABS_MT_POSITION_X, x);
1649 input_report_abs(input, ABS_MT_POSITION_Y, y); 1660 input_report_abs(input, ABS_MT_POSITION_Y, y);
1650 contact_with_no_pen_down_count++;
1651 } 1661 }
1652 } 1662 }
1653 1663
1654 input_mt_report_pointer_emulation(input, true); 1664 input_mt_sync_frame(input);
1655 1665
1656 input_report_key(pad_input, BTN_LEFT, (data[1] & 0x08) != 0); 1666 input_report_key(pad_input, BTN_LEFT, (data[1] & 0x08) != 0);
1657 input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0); 1667 input_report_key(pad_input, BTN_FORWARD, (data[1] & 0x04) != 0);
1658 input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0); 1668 input_report_key(pad_input, BTN_BACK, (data[1] & 0x02) != 0);
1659 input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0); 1669 input_report_key(pad_input, BTN_RIGHT, (data[1] & 0x01) != 0);
1660 wacom->shared->touch_down = (contact_with_no_pen_down_count > 0); 1670 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1661 1671
1662 return 1; 1672 return 1;
1663} 1673}
1664 1674
1665static int wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data, int last_touch_count) 1675static void wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data)
1666{ 1676{
1667 struct wacom_features *features = &wacom->features; 1677 struct wacom_features *features = &wacom->features;
1668 struct input_dev *input = wacom->input; 1678 struct input_dev *input = wacom->input;
@@ -1670,7 +1680,7 @@ static int wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data, in
1670 int slot = input_mt_get_slot_by_key(input, data[0]); 1680 int slot = input_mt_get_slot_by_key(input, data[0]);
1671 1681
1672 if (slot < 0) 1682 if (slot < 0)
1673 return 0; 1683 return;
1674 1684
1675 touch = touch && !wacom->shared->stylus_in_proximity; 1685 touch = touch && !wacom->shared->stylus_in_proximity;
1676 1686
@@ -1702,9 +1712,7 @@ static int wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data, in
1702 input_report_abs(input, ABS_MT_POSITION_Y, y); 1712 input_report_abs(input, ABS_MT_POSITION_Y, y);
1703 input_report_abs(input, ABS_MT_TOUCH_MAJOR, width); 1713 input_report_abs(input, ABS_MT_TOUCH_MAJOR, width);
1704 input_report_abs(input, ABS_MT_TOUCH_MINOR, height); 1714 input_report_abs(input, ABS_MT_TOUCH_MINOR, height);
1705 last_touch_count++;
1706 } 1715 }
1707 return last_touch_count;
1708} 1716}
1709 1717
1710static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data) 1718static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data)
@@ -1729,7 +1737,6 @@ static int wacom_bpt3_touch(struct wacom_wac *wacom)
1729 unsigned char *data = wacom->data; 1737 unsigned char *data = wacom->data;
1730 int count = data[1] & 0x07; 1738 int count = data[1] & 0x07;
1731 int i; 1739 int i;
1732 int contact_with_no_pen_down_count = 0;
1733 1740
1734 if (data[0] != 0x02) 1741 if (data[0] != 0x02)
1735 return 0; 1742 return 0;
@@ -1740,15 +1747,13 @@ static int wacom_bpt3_touch(struct wacom_wac *wacom)
1740 int msg_id = data[offset]; 1747 int msg_id = data[offset];
1741 1748
1742 if (msg_id >= 2 && msg_id <= 17) 1749 if (msg_id >= 2 && msg_id <= 17)
1743 contact_with_no_pen_down_count = 1750 wacom_bpt3_touch_msg(wacom, data + offset);
1744 wacom_bpt3_touch_msg(wacom, data + offset,
1745 contact_with_no_pen_down_count);
1746 else if (msg_id == 128) 1751 else if (msg_id == 128)
1747 wacom_bpt3_button_msg(wacom, data + offset); 1752 wacom_bpt3_button_msg(wacom, data + offset);
1748 1753
1749 } 1754 }
1750 input_mt_report_pointer_emulation(input, true); 1755 input_mt_sync_frame(input);
1751 wacom->shared->touch_down = (contact_with_no_pen_down_count > 0); 1756 wacom->shared->touch_down = wacom_wac_finger_count_touches(wacom);
1752 1757
1753 return 1; 1758 return 1;
1754} 1759}
@@ -1760,23 +1765,9 @@ static int wacom_bpt_pen(struct wacom_wac *wacom)
1760 unsigned char *data = wacom->data; 1765 unsigned char *data = wacom->data;
1761 int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0; 1766 int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0;
1762 1767
1763 if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_USB) 1768 if (data[0] != WACOM_REPORT_PENABLED)
1764 return 0; 1769 return 0;
1765 1770
1766 if (data[0] == WACOM_REPORT_USB) {
1767 if (features->type == INTUOSHT &&
1768 wacom->shared->touch_input &&
1769 features->touch_max) {
1770 input_report_switch(wacom->shared->touch_input,
1771 SW_MUTE_DEVICE, data[8] & 0x40);
1772 input_sync(wacom->shared->touch_input);
1773 }
1774 return 0;
1775 }
1776
1777 if (wacom->shared->touch_down)
1778 return 0;
1779
1780 prox = (data[1] & 0x20) == 0x20; 1771 prox = (data[1] & 0x20) == 0x20;
1781 1772
1782 /* 1773 /*
@@ -1789,17 +1780,21 @@ static int wacom_bpt_pen(struct wacom_wac *wacom)
1789 * 1780 *
1790 * Hardware does report zero in most out-of-prox cases but not all. 1781 * Hardware does report zero in most out-of-prox cases but not all.
1791 */ 1782 */
1792 if (prox) { 1783 if (!wacom->shared->stylus_in_proximity) {
1793 if (!wacom->shared->stylus_in_proximity) { 1784 if (data[1] & 0x08) {
1794 if (data[1] & 0x08) { 1785 wacom->tool[0] = BTN_TOOL_RUBBER;
1795 wacom->tool[0] = BTN_TOOL_RUBBER; 1786 wacom->id[0] = ERASER_DEVICE_ID;
1796 wacom->id[0] = ERASER_DEVICE_ID; 1787 } else {
1797 } else { 1788 wacom->tool[0] = BTN_TOOL_PEN;
1798 wacom->tool[0] = BTN_TOOL_PEN; 1789 wacom->id[0] = STYLUS_DEVICE_ID;
1799 wacom->id[0] = STYLUS_DEVICE_ID;
1800 }
1801 wacom->shared->stylus_in_proximity = true;
1802 } 1790 }
1791 }
1792
1793 wacom->shared->stylus_in_proximity = prox;
1794 if (wacom->shared->touch_down)
1795 return 0;
1796
1797 if (prox) {
1803 x = le16_to_cpup((__le16 *)&data[2]); 1798 x = le16_to_cpup((__le16 *)&data[2]);
1804 y = le16_to_cpup((__le16 *)&data[4]); 1799 y = le16_to_cpup((__le16 *)&data[4]);
1805 p = le16_to_cpup((__le16 *)&data[6]); 1800 p = le16_to_cpup((__le16 *)&data[6]);
@@ -1815,6 +1810,8 @@ static int wacom_bpt_pen(struct wacom_wac *wacom)
1815 pen = data[1] & 0x01; 1810 pen = data[1] & 0x01;
1816 btn1 = data[1] & 0x02; 1811 btn1 = data[1] & 0x02;
1817 btn2 = data[1] & 0x04; 1812 btn2 = data[1] & 0x04;
1813 } else {
1814 wacom->id[0] = 0;
1818 } 1815 }
1819 1816
1820 input_report_key(input, BTN_TOUCH, pen); 1817 input_report_key(input, BTN_TOUCH, pen);
@@ -1826,11 +1823,6 @@ static int wacom_bpt_pen(struct wacom_wac *wacom)
1826 input_report_abs(input, ABS_PRESSURE, p); 1823 input_report_abs(input, ABS_PRESSURE, p);
1827 input_report_abs(input, ABS_DISTANCE, d); 1824 input_report_abs(input, ABS_DISTANCE, d);
1828 1825
1829 if (!prox) {
1830 wacom->id[0] = 0;
1831 wacom->shared->stylus_in_proximity = false;
1832 }
1833
1834 input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */ 1826 input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */
1835 input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */ 1827 input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */
1836 1828
@@ -1849,6 +1841,91 @@ static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len)
1849 return 0; 1841 return 0;
1850} 1842}
1851 1843
1844static void wacom_bamboo_pad_pen_event(struct wacom_wac *wacom,
1845 unsigned char *data)
1846{
1847 unsigned char prefix;
1848
1849 /*
1850 * We need to reroute the event from the debug interface to the
1851 * pen interface.
1852 * We need to add the report ID to the actual pen report, so we
1853 * temporary overwrite the first byte to prevent having to kzalloc/kfree
1854 * and memcpy the report.
1855 */
1856 prefix = data[0];
1857 data[0] = WACOM_REPORT_BPAD_PEN;
1858
1859 /*
1860 * actually reroute the event.
1861 * No need to check if wacom->shared->pen is valid, hid_input_report()
1862 * will check for us.
1863 */
1864 hid_input_report(wacom->shared->pen, HID_INPUT_REPORT, data,
1865 WACOM_PKGLEN_PENABLED, 1);
1866
1867 data[0] = prefix;
1868}
1869
1870static int wacom_bamboo_pad_touch_event(struct wacom_wac *wacom,
1871 unsigned char *data)
1872{
1873 struct input_dev *input = wacom->input;
1874 unsigned char *finger_data, prefix;
1875 unsigned id;
1876 int x, y;
1877 bool valid;
1878
1879 prefix = data[0];
1880
1881 for (id = 0; id < wacom->features.touch_max; id++) {
1882 valid = !!(prefix & BIT(id)) &&
1883 !wacom->shared->stylus_in_proximity;
1884
1885 input_mt_slot(input, id);
1886 input_mt_report_slot_state(input, MT_TOOL_FINGER, valid);
1887
1888 if (!valid)
1889 continue;
1890
1891 finger_data = data + 1 + id * 3;
1892 x = finger_data[0] | ((finger_data[1] & 0x0f) << 8);
1893 y = (finger_data[2] << 4) | (finger_data[1] >> 4);
1894
1895 input_report_abs(input, ABS_MT_POSITION_X, x);
1896 input_report_abs(input, ABS_MT_POSITION_Y, y);
1897 }
1898
1899 input_mt_sync_frame(input);
1900
1901 input_report_key(input, BTN_LEFT, prefix & 0x40);
1902 input_report_key(input, BTN_RIGHT, prefix & 0x80);
1903
1904 /* keep touch state for pen event */
1905 wacom->shared->touch_down = !!prefix &&
1906 !wacom->shared->stylus_in_proximity;
1907
1908 return 1;
1909}
1910
1911static int wacom_bamboo_pad_irq(struct wacom_wac *wacom, size_t len)
1912{
1913 unsigned char *data = wacom->data;
1914
1915 if (!((len == WACOM_PKGLEN_BPAD_TOUCH) ||
1916 (len == WACOM_PKGLEN_BPAD_TOUCH_USB)) ||
1917 (data[0] != WACOM_REPORT_BPAD_TOUCH))
1918 return 0;
1919
1920 if (data[1] & 0x01)
1921 wacom_bamboo_pad_pen_event(wacom, &data[1]);
1922
1923 if (data[1] & 0x02)
1924 return wacom_bamboo_pad_touch_event(wacom, &data[9]);
1925
1926 return 0;
1927}
1928
1852static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len) 1929static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
1853{ 1930{
1854 unsigned char *data = wacom->data; 1931 unsigned char *data = wacom->data;
@@ -1859,7 +1936,7 @@ static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
1859 1936
1860 connected = data[1] & 0x01; 1937 connected = data[1] & 0x01;
1861 if (connected) { 1938 if (connected) {
1862 int pid, battery, ps_connected; 1939 int pid, battery, charging;
1863 1940
1864 if ((wacom->shared->type == INTUOSHT) && 1941 if ((wacom->shared->type == INTUOSHT) &&
1865 wacom->shared->touch_input && 1942 wacom->shared->touch_input &&
@@ -1871,30 +1948,63 @@ static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len)
1871 1948
1872 pid = get_unaligned_be16(&data[6]); 1949 pid = get_unaligned_be16(&data[6]);
1873 battery = (data[5] & 0x3f) * 100 / 31; 1950 battery = (data[5] & 0x3f) * 100 / 31;
1874 ps_connected = !!(data[5] & 0x80); 1951 charging = !!(data[5] & 0x80);
1875 if (wacom->pid != pid) { 1952 if (wacom->pid != pid) {
1876 wacom->pid = pid; 1953 wacom->pid = pid;
1877 wacom_schedule_work(wacom); 1954 wacom_schedule_work(wacom);
1878 } 1955 }
1879 1956
1880 if (wacom->shared->type && 1957 if (wacom->shared->type)
1881 (battery != wacom->battery_capacity || 1958 wacom_notify_battery(wacom, battery, charging, 1, 0);
1882 ps_connected != wacom->ps_connected)) { 1959
1883 wacom->battery_capacity = battery;
1884 wacom->ps_connected = ps_connected;
1885 wacom->bat_charging = ps_connected &&
1886 wacom->battery_capacity < 100;
1887 wacom_notify_battery(wacom);
1888 }
1889 } else if (wacom->pid != 0) { 1960 } else if (wacom->pid != 0) {
1890 /* disconnected while previously connected */ 1961 /* disconnected while previously connected */
1891 wacom->pid = 0; 1962 wacom->pid = 0;
1892 wacom_schedule_work(wacom); 1963 wacom_schedule_work(wacom);
1893 wacom->battery_capacity = 0; 1964 wacom_notify_battery(wacom, 0, 0, 0, 0);
1894 wacom->bat_charging = 0; 1965 }
1895 wacom->ps_connected = 0; 1966
1967 return 0;
1968}
1969
1970static int wacom_status_irq(struct wacom_wac *wacom_wac, size_t len)
1971{
1972 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);
1973 struct wacom_features *features = &wacom_wac->features;
1974 unsigned char *data = wacom_wac->data;
1975
1976 if (data[0] != WACOM_REPORT_USB)
1977 return 0;
1978
1979 if (features->type == INTUOSHT &&
1980 wacom_wac->shared->touch_input &&
1981 features->touch_max) {
1982 input_report_switch(wacom_wac->shared->touch_input,
1983 SW_MUTE_DEVICE, data[8] & 0x40);
1984 input_sync(wacom_wac->shared->touch_input);
1896 } 1985 }
1897 1986
1987 if (data[9] & 0x02) { /* wireless module is attached */
1988 int battery = (data[8] & 0x3f) * 100 / 31;
1989 bool charging = !!(data[8] & 0x80);
1990
1991 wacom_notify_battery(wacom_wac, battery, charging,
1992 battery || charging, 1);
1993
1994 if (!wacom->battery &&
1995 !(features->quirks & WACOM_QUIRK_BATTERY)) {
1996 features->quirks |= WACOM_QUIRK_BATTERY;
1997 INIT_WORK(&wacom->work, wacom_battery_work);
1998 wacom_schedule_work(wacom_wac);
1999 }
2000 }
2001 else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
2002 wacom->battery) {
2003 features->quirks &= ~WACOM_QUIRK_BATTERY;
2004 INIT_WORK(&wacom->work, wacom_battery_work);
2005 wacom_schedule_work(wacom_wac);
2006 wacom_notify_battery(wacom_wac, 0, 0, 0, 0);
2007 }
1898 return 0; 2008 return 0;
1899} 2009}
1900 2010
@@ -1967,6 +2077,8 @@ void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
1967 case INTUOSPL: 2077 case INTUOSPL:
1968 if (len == WACOM_PKGLEN_BBTOUCH3) 2078 if (len == WACOM_PKGLEN_BBTOUCH3)
1969 sync = wacom_bpt3_touch(wacom_wac); 2079 sync = wacom_bpt3_touch(wacom_wac);
2080 else if (wacom_wac->data[0] == WACOM_REPORT_USB)
2081 sync = wacom_status_irq(wacom_wac, len);
1970 else 2082 else
1971 sync = wacom_intuos_irq(wacom_wac); 2083 sync = wacom_intuos_irq(wacom_wac);
1972 break; 2084 break;
@@ -1982,7 +2094,14 @@ void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
1982 2094
1983 case BAMBOO_PT: 2095 case BAMBOO_PT:
1984 case INTUOSHT: 2096 case INTUOSHT:
1985 sync = wacom_bpt_irq(wacom_wac, len); 2097 if (wacom_wac->data[0] == WACOM_REPORT_USB)
2098 sync = wacom_status_irq(wacom_wac, len);
2099 else
2100 sync = wacom_bpt_irq(wacom_wac, len);
2101 break;
2102
2103 case BAMBOO_PAD:
2104 sync = wacom_bamboo_pad_irq(wacom_wac, len);
1986 break; 2105 break;
1987 2106
1988 case WIRELESS: 2107 case WIRELESS:
@@ -2054,12 +2173,6 @@ void wacom_setup_device_quirks(struct wacom_features *features)
2054 features->y_max = 1023; 2173 features->y_max = 1023;
2055 } 2174 }
2056 2175
2057 /* these device have multiple inputs */
2058 if (features->type >= WIRELESS ||
2059 (features->type >= INTUOS5S && features->type <= INTUOSHT) ||
2060 (features->oVid && features->oPid))
2061 features->quirks |= WACOM_QUIRK_MULTI_INPUT;
2062
2063 /* quirk for bamboo touch with 2 low res touches */ 2176 /* quirk for bamboo touch with 2 low res touches */
2064 if (features->type == BAMBOO_PT && 2177 if (features->type == BAMBOO_PT &&
2065 features->pktlen == WACOM_PKGLEN_BBTOUCH) { 2178 features->pktlen == WACOM_PKGLEN_BBTOUCH) {
@@ -2323,6 +2436,13 @@ int wacom_setup_pentouch_input_capabilities(struct input_dev *input_dev,
2323 0, 0); 2436 0, 0);
2324 } 2437 }
2325 break; 2438 break;
2439 case BAMBOO_PAD:
2440 __clear_bit(ABS_MISC, input_dev->absbit);
2441 input_mt_init_slots(input_dev, features->touch_max,
2442 INPUT_MT_POINTER);
2443 __set_bit(BTN_LEFT, input_dev->keybit);
2444 __set_bit(BTN_RIGHT, input_dev->keybit);
2445 break;
2326 } 2446 }
2327 return 0; 2447 return 0;
2328} 2448}
@@ -2772,6 +2892,15 @@ static const struct wacom_features wacom_features_0x304 =
2772 { "Wacom Cintiq 13HD", 59152, 33448, 1023, 63, 2892 { "Wacom Cintiq 13HD", 59152, 33448, 1023, 63,
2773 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES, 2893 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
2774 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET }; 2894 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET };
2895static const struct wacom_features wacom_features_0x333 =
2896 { "Wacom Cintiq 13HD touch", 59152, 33448, 2047, 63,
2897 WACOM_13HD, WACOM_INTUOS3_RES, WACOM_INTUOS3_RES,
2898 WACOM_CINTIQ_OFFSET, WACOM_CINTIQ_OFFSET,
2899 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x335 };
2900static const struct wacom_features wacom_features_0x335 =
2901 { "Wacom Cintiq 13HD touch", .type = WACOM_24HDT, /* Touch */
2902 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x333, .touch_max = 10,
2903 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
2775static const struct wacom_features wacom_features_0xC7 = 2904static const struct wacom_features wacom_features_0xC7 =
2776 { "Wacom DTU1931", 37832, 30305, 511, 0, 2905 { "Wacom DTU1931", 37832, 30305, 511, 0,
2777 PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES }; 2906 PL, WACOM_INTUOS_RES, WACOM_INTUOS_RES };
@@ -2976,6 +3105,12 @@ static const struct wacom_features wacom_features_0x30C =
2976 { "Wacom ISDv5 30C", .type = WACOM_24HDT, /* Touch */ 3105 { "Wacom ISDv5 30C", .type = WACOM_24HDT, /* Touch */
2977 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30A, .touch_max = 10, 3106 .oVid = USB_VENDOR_ID_WACOM, .oPid = 0x30A, .touch_max = 10,
2978 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE }; 3107 .check_for_hid_type = true, .hid_type = HID_TYPE_USBNONE };
3108static const struct wacom_features wacom_features_0x318 =
3109 { "Wacom USB Bamboo PAD", 4095, 4095, /* Touch */
3110 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
3111static const struct wacom_features wacom_features_0x319 =
3112 { "Wacom Wireless Bamboo PAD", 4095, 4095, /* Touch */
3113 .type = BAMBOO_PAD, 35, 48, .touch_max = 4 };
2979static const struct wacom_features wacom_features_0x323 = 3114static const struct wacom_features wacom_features_0x323 =
2980 { "Wacom Intuos P M", 21600, 13500, 1023, 31, 3115 { "Wacom Intuos P M", 21600, 13500, 1023, 31,
2981 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES, 3116 INTUOSHT, WACOM_INTUOS_RES, WACOM_INTUOS_RES,
@@ -2992,6 +3127,10 @@ static const struct wacom_features wacom_features_HID_ANY_ID =
2992 HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\ 3127 HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
2993 .driver_data = (kernel_ulong_t)&wacom_features_##prod 3128 .driver_data = (kernel_ulong_t)&wacom_features_##prod
2994 3129
3130#define I2C_DEVICE_WACOM(prod) \
3131 HID_DEVICE(BUS_I2C, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
3132 .driver_data = (kernel_ulong_t)&wacom_features_##prod
3133
2995#define USB_DEVICE_LENOVO(prod) \ 3134#define USB_DEVICE_LENOVO(prod) \
2996 HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, prod), \ 3135 HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, prod), \
2997 .driver_data = (kernel_ulong_t)&wacom_features_##prod 3136 .driver_data = (kernel_ulong_t)&wacom_features_##prod
@@ -3124,11 +3263,15 @@ const struct hid_device_id wacom_ids[] = {
3124 { USB_DEVICE_WACOM(0x314) }, 3263 { USB_DEVICE_WACOM(0x314) },
3125 { USB_DEVICE_WACOM(0x315) }, 3264 { USB_DEVICE_WACOM(0x315) },
3126 { USB_DEVICE_WACOM(0x317) }, 3265 { USB_DEVICE_WACOM(0x317) },
3266 { USB_DEVICE_WACOM(0x318) },
3267 { USB_DEVICE_WACOM(0x319) },
3127 { USB_DEVICE_WACOM(0x323) }, 3268 { USB_DEVICE_WACOM(0x323) },
3128 { USB_DEVICE_WACOM(0x32A) }, 3269 { USB_DEVICE_WACOM(0x32A) },
3129 { USB_DEVICE_WACOM(0x32B) }, 3270 { USB_DEVICE_WACOM(0x32B) },
3130 { USB_DEVICE_WACOM(0x32C) }, 3271 { USB_DEVICE_WACOM(0x32C) },
3131 { USB_DEVICE_WACOM(0x32F) }, 3272 { USB_DEVICE_WACOM(0x32F) },
3273 { USB_DEVICE_WACOM(0x333) },
3274 { USB_DEVICE_WACOM(0x335) },
3132 { USB_DEVICE_WACOM(0x4001) }, 3275 { USB_DEVICE_WACOM(0x4001) },
3133 { USB_DEVICE_WACOM(0x4004) }, 3276 { USB_DEVICE_WACOM(0x4004) },
3134 { USB_DEVICE_WACOM(0x5000) }, 3277 { USB_DEVICE_WACOM(0x5000) },
@@ -3136,6 +3279,7 @@ const struct hid_device_id wacom_ids[] = {
3136 { USB_DEVICE_LENOVO(0x6004) }, 3279 { USB_DEVICE_LENOVO(0x6004) },
3137 3280
3138 { USB_DEVICE_WACOM(HID_ANY_ID) }, 3281 { USB_DEVICE_WACOM(HID_ANY_ID) },
3282 { I2C_DEVICE_WACOM(HID_ANY_ID) },
3139 { } 3283 { }
3140}; 3284};
3141MODULE_DEVICE_TABLE(hid, wacom_ids); 3285MODULE_DEVICE_TABLE(hid, wacom_ids);
diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h
index 021ee1c1980a..4700ac994a3b 100644
--- a/drivers/hid/wacom_wac.h
+++ b/drivers/hid/wacom_wac.h
@@ -33,6 +33,8 @@
33#define WACOM_PKGLEN_MTTPC 40 33#define WACOM_PKGLEN_MTTPC 40
34#define WACOM_PKGLEN_DTUS 68 34#define WACOM_PKGLEN_DTUS 68
35#define WACOM_PKGLEN_PENABLED 8 35#define WACOM_PKGLEN_PENABLED 8
36#define WACOM_PKGLEN_BPAD_TOUCH 32
37#define WACOM_PKGLEN_BPAD_TOUCH_USB 64
36 38
37/* wacom data size per MT contact */ 39/* wacom data size per MT contact */
38#define WACOM_BYTES_PER_MT_PACKET 11 40#define WACOM_BYTES_PER_MT_PACKET 11
@@ -67,13 +69,14 @@
67#define WACOM_REPORT_24HDT 1 69#define WACOM_REPORT_24HDT 1
68#define WACOM_REPORT_WL 128 70#define WACOM_REPORT_WL 128
69#define WACOM_REPORT_USB 192 71#define WACOM_REPORT_USB 192
72#define WACOM_REPORT_BPAD_PEN 3
73#define WACOM_REPORT_BPAD_TOUCH 16
70 74
71/* device quirks */ 75/* device quirks */
72#define WACOM_QUIRK_MULTI_INPUT 0x0001 76#define WACOM_QUIRK_BBTOUCH_LOWRES 0x0001
73#define WACOM_QUIRK_BBTOUCH_LOWRES 0x0002 77#define WACOM_QUIRK_NO_INPUT 0x0002
74#define WACOM_QUIRK_NO_INPUT 0x0004 78#define WACOM_QUIRK_MONITOR 0x0004
75#define WACOM_QUIRK_MONITOR 0x0008 79#define WACOM_QUIRK_BATTERY 0x0008
76#define WACOM_QUIRK_BATTERY 0x0010
77 80
78#define WACOM_PEN_FIELD(f) (((f)->logical == HID_DG_STYLUS) || \ 81#define WACOM_PEN_FIELD(f) (((f)->logical == HID_DG_STYLUS) || \
79 ((f)->physical == HID_DG_STYLUS) || \ 82 ((f)->physical == HID_DG_STYLUS) || \
@@ -122,6 +125,7 @@ enum {
122 BAMBOO_PT, 125 BAMBOO_PT,
123 WACOM_24HDT, 126 WACOM_24HDT,
124 WACOM_27QHDT, 127 WACOM_27QHDT,
128 BAMBOO_PAD,
125 TABLETPC, /* add new TPC below */ 129 TABLETPC, /* add new TPC below */
126 TABLETPCE, 130 TABLETPCE,
127 TABLETPC2FG, 131 TABLETPC2FG,
@@ -169,6 +173,8 @@ struct wacom_shared {
169 unsigned touch_max; 173 unsigned touch_max;
170 int type; 174 int type;
171 struct input_dev *touch_input; 175 struct input_dev *touch_input;
176 struct hid_device *pen;
177 struct hid_device *touch;
172}; 178};
173 179
174struct hid_data { 180struct hid_data {
@@ -205,6 +211,7 @@ struct wacom_wac {
205 int battery_capacity; 211 int battery_capacity;
206 int num_contacts_left; 212 int num_contacts_left;
207 int bat_charging; 213 int bat_charging;
214 int bat_connected;
208 int ps_connected; 215 int ps_connected;
209 u8 bt_features; 216 u8 bt_features;
210 u8 bt_high_speed; 217 u8 bt_high_speed;