diff options
47 files changed, 2980 insertions, 706 deletions
diff --git a/Documentation/ABI/testing/sysfs-driver-hid b/Documentation/ABI/testing/sysfs-driver-hid index b6490e14fe83..48942cacb0bf 100644 --- a/Documentation/ABI/testing/sysfs-driver-hid +++ b/Documentation/ABI/testing/sysfs-driver-hid | |||
@@ -8,3 +8,13 @@ Description: When read, this file returns the device's raw binary HID | |||
8 | report descriptor. | 8 | report descriptor. |
9 | This file cannot be written. | 9 | This file cannot be written. |
10 | Users: HIDAPI library (http://www.signal11.us/oss/hidapi) | 10 | Users: HIDAPI library (http://www.signal11.us/oss/hidapi) |
11 | |||
12 | What: For USB devices : /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/country | ||
13 | For BT devices : /sys/class/bluetooth/hci<addr>/<hid-bus>:<vendor-id>:<product-id>.<num>/country | ||
14 | Symlink : /sys/class/hidraw/hidraw<num>/device/country | ||
15 | Date: February 2015 | ||
16 | KernelVersion: 3.19 | ||
17 | Contact: Olivier Gay <ogay@logitech.com> | ||
18 | Description: When read, this file returns the hex integer value in ASCII | ||
19 | of the device's HID country code (e.g. 21 for US). | ||
20 | This file cannot be written. | ||
diff --git a/Documentation/ABI/testing/sysfs-driver-hid-logitech-lg4ff b/Documentation/ABI/testing/sysfs-driver-hid-logitech-lg4ff index 167d9032b970..b3f6a2ac5007 100644 --- a/Documentation/ABI/testing/sysfs-driver-hid-logitech-lg4ff +++ b/Documentation/ABI/testing/sysfs-driver-hid-logitech-lg4ff | |||
@@ -5,3 +5,48 @@ Contact: Michal Malý <madcatxster@gmail.com> | |||
5 | Description: Display minimum, maximum and current range of the steering | 5 | Description: Display minimum, maximum and current range of the steering |
6 | wheel. Writing a value within min and max boundaries sets the | 6 | wheel. Writing a value within min and max boundaries sets the |
7 | range of the wheel. | 7 | range of the wheel. |
8 | |||
9 | What: /sys/bus/hid/drivers/logitech/<dev>/alternate_modes | ||
10 | Date: Feb 2015 | ||
11 | KernelVersion: 4.1 | ||
12 | Contact: Michal Malý <madcatxster@gmail.com> | ||
13 | Description: Displays a set of alternate modes supported by a wheel. Each | ||
14 | mode is listed as follows: | ||
15 | Tag: Mode Name | ||
16 | Currently active mode is marked with an asterisk. List also | ||
17 | contains an abstract item "native" which always denotes the | ||
18 | native mode of the wheel. Echoing the mode tag switches the | ||
19 | wheel into the corresponding mode. Depending on the exact model | ||
20 | of the wheel not all listed modes might always be selectable. | ||
21 | If a wheel cannot be switched into the desired mode, -EINVAL | ||
22 | is returned accompanied with an explanatory message in the | ||
23 | kernel log. | ||
24 | This entry is not created for devices that have only one mode. | ||
25 | |||
26 | Currently supported mode switches: | ||
27 | Driving Force Pro: | ||
28 | DF-EX --> DFP | ||
29 | |||
30 | G25: | ||
31 | DF-EX --> DFP --> G25 | ||
32 | |||
33 | G27: | ||
34 | DF-EX <*> DFP <-> G25 <-> G27 | ||
35 | DF-EX <*--------> G25 <-> G27 | ||
36 | DF-EX <*----------------> G27 | ||
37 | |||
38 | DFGT: | ||
39 | DF-EX <*> DFP <-> DFGT | ||
40 | DF-EX <*--------> DFGT | ||
41 | |||
42 | * hid_logitech module must be loaded with lg4ff_no_autoswitch=1 | ||
43 | parameter set in order for the switch to DF-EX mode to work. | ||
44 | |||
45 | What: /sys/bus/hid/drivers/logitech/<dev>/real_id | ||
46 | Date: Feb 2015 | ||
47 | KernelVersion: 4.1 | ||
48 | Contact: Michal Malý <madcatxster@gmail.com> | ||
49 | Description: Displays the real model of the wheel regardless of any | ||
50 | alternate mode the wheel might be switched to. | ||
51 | It is a read-only value. | ||
52 | This entry is not created for devices that have only one mode. | ||
diff --git a/Documentation/hid/hid-sensor.txt b/Documentation/hid/hid-sensor.txt index 948b0989c433..b287752a31cd 100644 --- a/Documentation/hid/hid-sensor.txt +++ b/Documentation/hid/hid-sensor.txt | |||
@@ -138,3 +138,87 @@ accelerometer wants to poll X axis value, then it can call this function with | |||
138 | the usage id of X axis. HID sensors can provide events, so this is not necessary | 138 | the usage id of X axis. HID sensors can provide events, so this is not necessary |
139 | to poll for any field. If there is some new sample, the core driver will call | 139 | to poll for any field. If there is some new sample, the core driver will call |
140 | registered callback function to process the sample. | 140 | registered callback function to process the sample. |
141 | |||
142 | |||
143 | ---------- | ||
144 | |||
145 | HID Custom and generic Sensors | ||
146 | |||
147 | HID Sensor specification defines two special sensor usage types. Since they | ||
148 | don't represent a standard sensor, it is not possible to define using Linux IIO | ||
149 | type interfaces. | ||
150 | The purpose of these sensors is to extend the functionality or provide a | ||
151 | way to obfuscate the data being communicated by a sensor. Without knowing the | ||
152 | mapping between the data and its encapsulated form, it is difficult for | ||
153 | an application/driver to determine what data is being communicated by the sensor. | ||
154 | This allows some differentiating use cases, where vendor can provide applications. | ||
155 | Some common use cases are debug other sensors or to provide some events like | ||
156 | keyboard attached/detached or lid open/close. | ||
157 | |||
158 | To allow application to utilize these sensors, here they are exported uses sysfs | ||
159 | attribute groups, attributes and misc device interface. | ||
160 | |||
161 | An example of this representation on sysfs: | ||
162 | /sys/devices/pci0000:00/INT33C2:00/i2c-0/i2c-INT33D1:00/0018:8086:09FA.0001/HID-SENSOR-2000e1.6.auto$ tree -R | ||
163 | . | ||
164 | ????????? enable_sensor | ||
165 | ????????? feature-0-200316 | ||
166 | ??????? ????????? feature-0-200316-maximum | ||
167 | ??????? ????????? feature-0-200316-minimum | ||
168 | ??????? ????????? feature-0-200316-name | ||
169 | ??????? ????????? feature-0-200316-size | ||
170 | ??????? ????????? feature-0-200316-unit-expo | ||
171 | ??????? ????????? feature-0-200316-units | ||
172 | ??????? ????????? feature-0-200316-value | ||
173 | ????????? feature-1-200201 | ||
174 | ??????? ????????? feature-1-200201-maximum | ||
175 | ??????? ????????? feature-1-200201-minimum | ||
176 | ??????? ????????? feature-1-200201-name | ||
177 | ??????? ????????? feature-1-200201-size | ||
178 | ??????? ????????? feature-1-200201-unit-expo | ||
179 | ??????? ????????? feature-1-200201-units | ||
180 | ??????? ????????? feature-1-200201-value | ||
181 | ????????? input-0-200201 | ||
182 | ??????? ????????? input-0-200201-maximum | ||
183 | ??????? ????????? input-0-200201-minimum | ||
184 | ??????? ????????? input-0-200201-name | ||
185 | ??????? ????????? input-0-200201-size | ||
186 | ??????? ????????? input-0-200201-unit-expo | ||
187 | ??????? ????????? input-0-200201-units | ||
188 | ??????? ????????? input-0-200201-value | ||
189 | ????????? input-1-200202 | ||
190 | ??????? ????????? input-1-200202-maximum | ||
191 | ??????? ????????? input-1-200202-minimum | ||
192 | ??????? ????????? input-1-200202-name | ||
193 | ??????? ????????? input-1-200202-size | ||
194 | ??????? ????????? input-1-200202-unit-expo | ||
195 | ??????? ????????? input-1-200202-units | ||
196 | ??????? ????????? input-1-200202-value | ||
197 | |||
198 | Here there is a custom sensors with four fields, two feature and two inputs. | ||
199 | Each field is represented by a set of attributes. All fields except the "value" | ||
200 | are read only. The value field is a RW field. | ||
201 | Example | ||
202 | /sys/bus/platform/devices/HID-SENSOR-2000e1.6.auto/feature-0-200316$ grep -r . * | ||
203 | feature-0-200316-maximum:6 | ||
204 | feature-0-200316-minimum:0 | ||
205 | feature-0-200316-name:property-reporting-state | ||
206 | feature-0-200316-size:1 | ||
207 | feature-0-200316-unit-expo:0 | ||
208 | feature-0-200316-units:25 | ||
209 | feature-0-200316-value:1 | ||
210 | |||
211 | How to enable such sensor? | ||
212 | By default sensor can be power gated. To enable sysfs attribute "enable" can be | ||
213 | used. | ||
214 | $ echo 1 > enable_sensor | ||
215 | |||
216 | Once enabled and powered on, sensor can report value using HID reports. | ||
217 | These reports are pushed using misc device interface in a FIFO order. | ||
218 | /dev$ tree | grep HID-SENSOR-2000e1.6.auto | ||
219 | ??????? ????????? 10:53 -> ../HID-SENSOR-2000e1.6.auto | ||
220 | ????????? HID-SENSOR-2000e1.6.auto | ||
221 | |||
222 | Each reports can be of variable length preceded by a header. This header | ||
223 | consist of a 32 bit usage id, 64 bit time stamp and 32 bit length field of raw | ||
224 | data. | ||
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 | ||
94 | config HID_A4TECH | 94 | config 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 | ||
115 | config HID_APPLE | 115 | config 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 | ||
143 | config HID_BELKIN | 143 | config 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 | ||
160 | config HID_CHERRY | 160 | config 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 | ||
167 | config HID_CHICONY | 167 | config 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 | ||
198 | config HID_CYPRESS | 198 | config 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 | ||
247 | config HID_EZKEY | 247 | config 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 | ||
289 | config HID_HUION | ||
290 | tristate "Huion tablets" | ||
291 | depends on USB_HID | ||
292 | ---help--- | ||
293 | Support for Huion 580 tablet. | ||
294 | |||
295 | config HID_KEYTOUCH | 289 | config 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 | ||
313 | config HID_UCLOGIC | 307 | config 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 | ||
319 | config HID_WALTOP | 313 | config 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 | ||
346 | config HID_KENSINGTON | 340 | config 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 | ||
374 | config HID_LOGITECH | 368 | config 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 | ||
463 | config HID_MICROSOFT | 457 | config 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 | ||
470 | config HID_MONTEREY | 464 | config 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 | ||
639 | config HID_PLANTRONICS | 633 | config 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 | ||
881 | config 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 | |||
888 | endmenu | 896 | endmenu |
889 | 897 | ||
890 | endif # HID | 898 | endif # 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 | |||
41 | obj-$(CONFIG_HID_HOLTEK) += hid-holtek-kbd.o | 41 | obj-$(CONFIG_HID_HOLTEK) += hid-holtek-kbd.o |
42 | obj-$(CONFIG_HID_HOLTEK) += hid-holtek-mouse.o | 42 | obj-$(CONFIG_HID_HOLTEK) += hid-holtek-mouse.o |
43 | obj-$(CONFIG_HID_HOLTEK) += hid-holtekff.o | 43 | obj-$(CONFIG_HID_HOLTEK) += hid-holtekff.o |
44 | obj-$(CONFIG_HID_HUION) += hid-huion.o | ||
45 | obj-$(CONFIG_HID_HYPERV_MOUSE) += hid-hyperv.o | 44 | obj-$(CONFIG_HID_HYPERV_MOUSE) += hid-hyperv.o |
46 | obj-$(CONFIG_HID_ICADE) += hid-icade.o | 45 | obj-$(CONFIG_HID_ICADE) += hid-icade.o |
47 | obj-$(CONFIG_HID_KENSINGTON) += hid-kensington.o | 46 | obj-$(CONFIG_HID_KENSINGTON) += hid-kensington.o |
@@ -101,6 +100,7 @@ obj-$(CONFIG_HID_WACOM) += wacom.o | |||
101 | obj-$(CONFIG_HID_WALTOP) += hid-waltop.o | 100 | obj-$(CONFIG_HID_WALTOP) += hid-waltop.o |
102 | obj-$(CONFIG_HID_WIIMOTE) += hid-wiimote.o | 101 | obj-$(CONFIG_HID_WIIMOTE) += hid-wiimote.o |
103 | obj-$(CONFIG_HID_SENSOR_HUB) += hid-sensor-hub.o | 102 | obj-$(CONFIG_HID_SENSOR_HUB) += hid-sensor-hub.o |
103 | obj-$(CONFIG_HID_SENSOR_CUSTOM_SENSOR) += hid-sensor-custom.o | ||
104 | 104 | ||
105 | obj-$(CONFIG_USB_HID) += usbhid/ | 105 | obj-$(CONFIG_USB_HID) += usbhid/ |
106 | obj-$(CONFIG_USB_MOUSE) += usbhid/ | 106 | obj-$(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 | ||
1565 | static ssize_t | ||
1566 | show_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 | |||
1565 | static struct bin_attribute dev_bin_attr_report_desc = { | 1574 | static 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 | ||
1580 | static struct device_attribute dev_attr_country = { | ||
1581 | .attr = { .name = "country", .mode = 0444 }, | ||
1582 | .show = show_country, | ||
1583 | }; | ||
1584 | |||
1571 | int hid_connect(struct hid_device *hdev, unsigned int connect_mask) | 1585 | int 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 | ||
1662 | void hid_disconnect(struct hid_device *hdev) | 1681 | void 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 */ | ||
28 | enum 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 */ | ||
41 | static 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 */ | ||
88 | enum 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 */ | ||
97 | struct huion_drvdata { | ||
98 | __u8 *rdesc; | ||
99 | unsigned int rsize; | ||
100 | }; | ||
101 | |||
102 | static __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 | */ | ||
122 | static 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 | |||
210 | cleanup: | ||
211 | kfree(buf); | ||
212 | return rc; | ||
213 | } | ||
214 | |||
215 | static 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 | |||
257 | static 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 | |||
272 | static 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 | }; | ||
277 | MODULE_DEVICE_TABLE(hid, huion_devices); | ||
278 | |||
279 | static 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 | }; | ||
286 | module_hid_driver(huion_driver); | ||
287 | |||
288 | MODULE_AUTHOR("Martin Rusko"); | ||
289 | MODULE_DESCRIPTION("Huion HID driver"); | ||
290 | MODULE_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 */ | ||
276 | static __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 | |||
271 | static __u8 *kye_consumer_control_fixup(struct hid_device *hdev, __u8 *rdesc, | 402 | static __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 | }; |
462 | MODULE_DEVICE_TABLE(hid, kye_devices); | 602 | MODULE_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 | }; |
819 | module_hid_driver(lg_driver); | 820 | module_hid_driver(lg_driver); |
820 | 821 | ||
822 | #ifdef CONFIG_LOGIWHEELS_FF | ||
823 | int lg4ff_no_autoswitch = 0; | ||
824 | module_param_named(lg4ff_no_autoswitch, lg4ff_no_autoswitch, int, S_IRUGO); | ||
825 | MODULE_PARM_DESC(lg4ff_no_autoswitch, "Do not switch multimode wheels to their native mode automatically"); | ||
826 | #endif | ||
827 | |||
821 | MODULE_LICENSE("GPL"); | 828 | MODULE_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); | |||
24 | static inline int lg3ff_init(struct hid_device *hdev) { return -1; } | 24 | static inline int lg3ff_init(struct hid_device *hdev) { return -1; } |
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | #ifdef CONFIG_LOGIWHEELS_FF | ||
28 | int 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); | ||
30 | int lg4ff_init(struct hid_device *hdev); | ||
31 | int lg4ff_deinit(struct hid_device *hdev); | ||
32 | #else | ||
33 | static 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; } | ||
35 | static inline int lg4ff_init(struct hid_device *hdev) { return -1; } | ||
36 | static 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 | |||
50 | static void hid_lg4ff_set_range_dfp(struct hid_device *hid, u16 range); | 71 | static void hid_lg4ff_set_range_dfp(struct hid_device *hid, u16 range); |
51 | static void hid_lg4ff_set_range_g25(struct hid_device *hid, u16 range); | 72 | static 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 | ||
105 | struct lg4ff_compat_mode_switch { | ||
106 | const __u8 cmd_count; /* Number of commands to send */ | ||
107 | const __u8 cmd[]; | ||
108 | }; | ||
109 | |||
110 | struct lg4ff_wheel_ident_info { | ||
111 | const u16 mask; | ||
112 | const u16 result; | ||
113 | const u16 real_product_id; | ||
114 | }; | ||
115 | |||
116 | struct lg4ff_wheel_ident_checklist { | ||
117 | const u32 count; | ||
118 | const struct lg4ff_wheel_ident_info *models[]; | ||
119 | }; | ||
120 | |||
121 | struct 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 | |||
128 | struct lg4ff_alternate_mode { | ||
129 | const u16 product_id; | ||
130 | const char *tag; | ||
131 | const char *name; | ||
132 | }; | ||
133 | |||
80 | static const struct lg4ff_wheel lg4ff_devices[] = { | 134 | static 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 | ||
91 | struct lg4ff_native_cmd { | 145 | static 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 | ||
96 | struct lg4ff_usb_revision { | 160 | static 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 | ||
102 | static const struct lg4ff_native_cmd native_dfp = { | 169 | /* Multimode wheel identificators */ |
103 | 1, | 170 | static 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 | |||
176 | static const struct lg4ff_wheel_ident_info lg4ff_g25_ident_info = { | ||
177 | 0xff00, | ||
178 | 0x1200, | ||
179 | USB_DEVICE_ID_LOGITECH_G25_WHEEL | ||
180 | }; | ||
181 | |||
182 | static 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 | ||
107 | static const struct lg4ff_native_cmd native_dfgt = { | 188 | static 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 */ | ||
195 | static 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 */ | ||
205 | static 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 | ||
113 | static const struct lg4ff_native_cmd native_g25 = { | 211 | static 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 | |||
217 | static 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 | |||
223 | static 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 | ||
118 | static const struct lg4ff_native_cmd native_g27 = { | 229 | static 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 | ||
124 | static 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 */ | 236 | static 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 */ |
242 | static 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 | ||
399 | static void hid_lg4ff_switch_native(struct hid_device *hid, const struct lg4ff_native_cmd *cmd) | 513 | static 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 | |||
570 | static 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 | |||
589 | static 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 | |||
638 | static 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 | } |
722 | static 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 */ |
415 | static ssize_t range_show(struct device *dev, struct device_attribute *attr, | 725 | static 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 | } |
473 | static DEVICE_ATTR_RW(range); | 783 | static DEVICE_ATTR_RW(range); |
474 | 784 | ||
785 | static 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 | |||
813 | static 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 | } | ||
818 | static 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 |
476 | static void lg4ff_set_leds(struct hid_device *hid, __u8 leds) | 821 | static 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 | ||
903 | static 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 | |||
951 | static 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 | |||
558 | int lg4ff_init(struct hid_device *hid) | 990 | int 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 | |||
716 | int lg4ff_deinit(struct hid_device *hid) | 1165 | int 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 | ||
1208 | out: | ||
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 | ||
5 | extern int lg4ff_no_autoswitch; /* From hid-lg.c */ | ||
6 | |||
7 | int 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); | ||
9 | int lg4ff_init(struct hid_device *hdev); | ||
10 | int lg4ff_deinit(struct hid_device *hdev); | ||
11 | #else | ||
12 | static 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; } | ||
14 | static inline int lg4ff_init(struct hid_device *hdev) { return -1; } | ||
15 | static 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"); | |||
28 | MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>"); | 28 | MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>"); |
29 | MODULE_AUTHOR("Nestor Lopez Casado <nlopezcasad@logitech.com>"); | 29 | MODULE_AUTHOR("Nestor Lopez Casado <nlopezcasad@logitech.com>"); |
30 | 30 | ||
31 | static bool disable_raw_mode; | ||
32 | module_param(disable_raw_mode, bool, 0644); | ||
33 | MODULE_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 | |||
75 | struct mt_slot { | 76 | struct 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 | ||
277 | static 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 | |||
307 | exit: | ||
308 | mutex_unlock(&data->page_mutex); | ||
309 | return ret; | ||
310 | } | ||
311 | |||
312 | static inline int rmi_write(struct hid_device *hdev, u16 addr, void *buf) | ||
313 | { | ||
314 | return rmi_write_block(hdev, addr, buf, 1); | ||
315 | } | ||
316 | |||
275 | static void rmi_f11_process_touch(struct rmi_data *hdata, int slot, | 317 | static 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 | |||
654 | static 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 | |||
607 | static int rmi_populate_f11(struct hid_device *hdev) | 738 | static 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 | |||
33 | struct 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 | |||
43 | struct 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 */ | ||
64 | struct hid_sensor_sample { | ||
65 | u32 usage_id; | ||
66 | u64 timestamp; | ||
67 | u32 raw_len; | ||
68 | } __packed; | ||
69 | |||
70 | static 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 | |||
81 | static 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 | |||
146 | static 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 | |||
157 | static 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 | |||
166 | static 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 | |||
236 | static 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 | } | ||
265 | unlock_state: | ||
266 | mutex_unlock(&sensor_inst->mutex); | ||
267 | if (ret < 0) | ||
268 | return ret; | ||
269 | |||
270 | return count; | ||
271 | } | ||
272 | static DEVICE_ATTR_RW(enable_sensor); | ||
273 | |||
274 | static struct attribute *enable_sensor_attrs[] = { | ||
275 | &dev_attr_enable_sensor.attr, | ||
276 | NULL, | ||
277 | }; | ||
278 | |||
279 | static struct attribute_group enable_sensor_attr_group = { | ||
280 | .attrs = enable_sensor_attrs, | ||
281 | }; | ||
282 | |||
283 | static 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 | |||
392 | static 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 | |||
424 | static 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 | |||
466 | static 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 | |||
482 | static 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 | |||
535 | static 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 | |||
569 | static 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 | |||
634 | static 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 | |||
647 | static 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 | |||
680 | static 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 | |||
692 | static 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 | |||
705 | static 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 | |||
722 | static 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 | |||
730 | static 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 | |||
752 | static 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 | |||
761 | static 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 | |||
801 | err_remove_attributes: | ||
802 | hid_sensor_custom_remove_attributes(sensor_inst); | ||
803 | err_remove_group: | ||
804 | sysfs_remove_group(&sensor_inst->pdev->dev.kobj, | ||
805 | &enable_sensor_attr_group); | ||
806 | err_remove_callback: | ||
807 | sensor_hub_remove_callback(hsdev, hsdev->usage); | ||
808 | |||
809 | return ret; | ||
810 | } | ||
811 | |||
812 | static 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 | |||
826 | static 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 | }; | ||
835 | MODULE_DEVICE_TABLE(platform, hid_sensor_custom_ids); | ||
836 | |||
837 | static 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 | }; | ||
845 | module_platform_driver(hid_sensor_custom_platform_driver); | ||
846 | |||
847 | MODULE_DESCRIPTION("HID Sensor Custom and Generic sensor Driver"); | ||
848 | MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); | ||
849 | MODULE_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 | */ | ||
40 | struct 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 { | |||
61 | struct sensor_hub_data { | 42 | struct 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, | |||
208 | EXPORT_SYMBOL_GPL(sensor_hub_remove_callback); | 201 | EXPORT_SYMBOL_GPL(sensor_hub_remove_callback); |
209 | 202 | ||
210 | int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, | 203 | int 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: | |||
232 | EXPORT_SYMBOL_GPL(sensor_hub_set_feature); | 243 | EXPORT_SYMBOL_GPL(sensor_hub_set_feature); |
233 | 244 | ||
234 | int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, | 245 | int 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 | ||
252 | done_proc: | 274 | done_proc: |
253 | mutex_unlock(&data->mutex); | 275 | mutex_unlock(&data->mutex); |
@@ -259,47 +281,54 @@ EXPORT_SYMBOL_GPL(sensor_hub_get_feature); | |||
259 | 281 | ||
260 | int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, | 282 | int 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); | |
300 | err_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 | ||
807 | static DEFINE_SPINLOCK(sony_dev_list_lock); | 808 | static DEFINE_SPINLOCK(sony_dev_list_lock); |
808 | static LIST_HEAD(sony_device_list); | 809 | static LIST_HEAD(sony_device_list); |
@@ -1131,18 +1132,38 @@ static void sony_input_configured(struct hid_device *hdev, | |||
1131 | */ | 1132 | */ |
1132 | static int sixaxis_set_operational_usb(struct hid_device *hdev) | 1133 | static 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 | ||
1166 | out: | ||
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 */ | ||
556 | enum 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 */ | ||
570 | static 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 */ | ||
617 | enum 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 */ | ||
626 | struct uclogic_drvdata { | ||
627 | __u8 *rdesc; | ||
628 | unsigned int rsize; | ||
629 | bool invert_pen_inrange; | ||
630 | bool ignore_pen_usage; | ||
631 | }; | ||
632 | |||
549 | static __u8 *uclogic_report_fixup(struct hid_device *hdev, __u8 *rdesc, | 633 | static __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 | ||
719 | static 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 | |||
734 | static 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 | */ | ||
784 | static 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 | |||
872 | cleanup: | ||
873 | kfree(buf); | ||
874 | return rc; | ||
875 | } | ||
876 | |||
877 | static 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 | |||
929 | static 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 | |||
629 | static const struct hid_device_id uclogic_devices[] = { | 944 | static 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 | }; |
646 | MODULE_DEVICE_TABLE(hid, uclogic_devices); | 963 | MODULE_DEVICE_TABLE(hid, uclogic_devices); |
@@ -648,8 +965,14 @@ MODULE_DEVICE_TABLE(hid, uclogic_devices); | |||
648 | static struct hid_driver uclogic_driver = { | 965 | static 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 | }; |
653 | module_hid_driver(uclogic_driver); | 974 | module_hid_driver(uclogic_driver); |
654 | 975 | ||
976 | MODULE_AUTHOR("Martin Rusko"); | ||
977 | MODULE_AUTHOR("Nikolai Kondrashov"); | ||
655 | MODULE_LICENSE("GPL"); | 978 | MODULE_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 */ | ||
849 | static const struct acpi_gpio_params i2c_hid_irq_gpio = { 0, 0, true }; | ||
850 | static const struct acpi_gpio_mapping i2c_hid_acpi_gpios[] = { | ||
851 | { "gpios", &i2c_hid_irq_gpio, 1 }, | ||
852 | { }, | ||
853 | }; | ||
854 | |||
844 | static int i2c_hid_acpi_pdata(struct i2c_client *client, | 855 | static 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 | ||
872 | static const struct acpi_device_id i2c_hid_acpi_match[] = { | 883 | static 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 | ||
1019 | err_irq: | 1041 | err_irq: |
1020 | free_irq(client->irq, ihid); | 1042 | free_irq(ihid->irq, ihid); |
1021 | 1043 | ||
1022 | err_pm: | 1044 | err_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 | ||
1026 | err: | 1048 | err: |
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) | |||
1101 | static int i2c_hid_runtime_suspend(struct device *dev) | 1131 | static 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 | ||
1110 | static int i2c_hid_runtime_resume(struct device *dev) | 1141 | static 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 | ||
134 | static 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 | |||
141 | extern const struct hid_device_id wacom_ids[]; | 134 | extern const struct hid_device_id wacom_ids[]; |
142 | 135 | ||
143 | void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len); | 136 | void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len); |
@@ -151,4 +144,5 @@ void wacom_wac_usage_mapping(struct hid_device *hdev, | |||
151 | int wacom_wac_event(struct hid_device *hdev, struct hid_field *field, | 144 | int 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); |
153 | void wacom_wac_report(struct hid_device *hdev, struct hid_report *report); | 146 | void wacom_wac_report(struct hid_device *hdev, struct hid_report *report); |
147 | void 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 | |||
527 | out: | 535 | out: |
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 | ||
544 | static void wacom_remove_shared_data(struct wacom_wac *wacom) | 552 | static 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 | ||
931 | static enum power_supply_property wacom_battery_props[] = { | 947 | static 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 | ||
1046 | static void wacom_destroy_battery(struct wacom *wacom) | 1068 | static 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 | ||
1341 | void 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); |
1533 | fail_battery: | 1590 | fail_battery: |
1534 | wacom_remove_shared_data(wacom_wac); | 1591 | wacom_remove_shared_data(wacom); |
1535 | fail_shared_data: | 1592 | fail_shared_data: |
1536 | wacom_clean_inputs(wacom); | 1593 | wacom_clean_inputs(wacom); |
1537 | fail_allocate_inputs: | 1594 | fail_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 | */ |
46 | static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 }; | 46 | static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 }; |
47 | 47 | ||
48 | static 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 | |||
48 | static int wacom_penpartner_irq(struct wacom_wac *wacom) | 69 | static 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 | } |
429 | exit: | 446 | exit: |
430 | return retval; | 447 | return retval; |
431 | } | 448 | } |
432 | 449 | ||
450 | static 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 | |||
433 | static int wacom_intuos_inout(struct wacom_wac *wacom) | 463 | static 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 | ||
1068 | static 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 | |||
1045 | static int wacom_24hdt_irq(struct wacom_wac *wacom) | 1090 | static 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 | ||
1525 | static 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 | |||
1548 | static void wacom_wac_finger_report(struct hid_device *hdev, | 1560 | static 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 | ||
1565 | void wacom_wac_usage_mapping(struct hid_device *hdev, | 1577 | void 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 | ||
1665 | static int wacom_bpt3_touch_msg(struct wacom_wac *wacom, unsigned char *data, int last_touch_count) | 1675 | static 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 | ||
1710 | static void wacom_bpt3_button_msg(struct wacom_wac *wacom, unsigned char *data) | 1718 | static 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 | ||
1844 | static 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 | |||
1870 | static 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 | |||
1911 | static 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 | |||
1852 | static int wacom_wireless_irq(struct wacom_wac *wacom, size_t len) | 1929 | static 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 | |||
1970 | static 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 }; |
2895 | static 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 }; | ||
2900 | static 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 }; | ||
2775 | static const struct wacom_features wacom_features_0xC7 = | 2904 | static 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 }; |
3108 | static const struct wacom_features wacom_features_0x318 = | ||
3109 | { "Wacom USB Bamboo PAD", 4095, 4095, /* Touch */ | ||
3110 | .type = BAMBOO_PAD, 35, 48, .touch_max = 4 }; | ||
3111 | static const struct wacom_features wacom_features_0x319 = | ||
3112 | { "Wacom Wireless Bamboo PAD", 4095, 4095, /* Touch */ | ||
3113 | .type = BAMBOO_PAD, 35, 48, .touch_max = 4 }; | ||
2979 | static const struct wacom_features wacom_features_0x323 = | 3114 | static 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 | }; |
3141 | MODULE_DEVICE_TABLE(hid, wacom_ids); | 3285 | MODULE_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 | ||
174 | struct hid_data { | 180 | struct 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; |
diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c index df6a593bd4bd..2b4fad6998c1 100644 --- a/drivers/iio/accel/hid-sensor-accel-3d.c +++ b/drivers/iio/accel/hid-sensor-accel-3d.c | |||
@@ -123,7 +123,8 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev, | |||
123 | *val = sensor_hub_input_attr_get_raw_value( | 123 | *val = sensor_hub_input_attr_get_raw_value( |
124 | accel_state->common_attributes.hsdev, | 124 | accel_state->common_attributes.hsdev, |
125 | HID_USAGE_SENSOR_ACCEL_3D, address, | 125 | HID_USAGE_SENSOR_ACCEL_3D, address, |
126 | report_id); | 126 | report_id, |
127 | SENSOR_HUB_SYNC); | ||
127 | else { | 128 | else { |
128 | *val = 0; | 129 | *val = 0; |
129 | hid_sensor_power_state(&accel_state->common_attributes, | 130 | hid_sensor_power_state(&accel_state->common_attributes, |
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c index 25b01e156d82..e81f434760f4 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c | |||
@@ -153,8 +153,8 @@ s32 hid_sensor_read_poll_value(struct hid_sensor_common *st) | |||
153 | int ret; | 153 | int ret; |
154 | 154 | ||
155 | ret = sensor_hub_get_feature(st->hsdev, | 155 | ret = sensor_hub_get_feature(st->hsdev, |
156 | st->poll.report_id, | 156 | st->poll.report_id, |
157 | st->poll.index, &value); | 157 | st->poll.index, sizeof(value), &value); |
158 | 158 | ||
159 | if (ret < 0 || value < 0) { | 159 | if (ret < 0 || value < 0) { |
160 | return -EINVAL; | 160 | return -EINVAL; |
@@ -174,8 +174,8 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, | |||
174 | int ret; | 174 | int ret; |
175 | 175 | ||
176 | ret = sensor_hub_get_feature(st->hsdev, | 176 | ret = sensor_hub_get_feature(st->hsdev, |
177 | st->poll.report_id, | 177 | st->poll.report_id, |
178 | st->poll.index, &value); | 178 | st->poll.index, sizeof(value), &value); |
179 | if (ret < 0 || value < 0) { | 179 | if (ret < 0 || value < 0) { |
180 | *val1 = *val2 = 0; | 180 | *val1 = *val2 = 0; |
181 | return -EINVAL; | 181 | return -EINVAL; |
@@ -212,9 +212,8 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st, | |||
212 | else | 212 | else |
213 | value = 0; | 213 | value = 0; |
214 | } | 214 | } |
215 | ret = sensor_hub_set_feature(st->hsdev, | 215 | ret = sensor_hub_set_feature(st->hsdev, st->poll.report_id, |
216 | st->poll.report_id, | 216 | st->poll.index, sizeof(value), &value); |
217 | st->poll.index, value); | ||
218 | if (ret < 0 || value < 0) | 217 | if (ret < 0 || value < 0) |
219 | ret = -EINVAL; | 218 | ret = -EINVAL; |
220 | 219 | ||
@@ -229,8 +228,9 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st, | |||
229 | int ret; | 228 | int ret; |
230 | 229 | ||
231 | ret = sensor_hub_get_feature(st->hsdev, | 230 | ret = sensor_hub_get_feature(st->hsdev, |
232 | st->sensitivity.report_id, | 231 | st->sensitivity.report_id, |
233 | st->sensitivity.index, &value); | 232 | st->sensitivity.index, sizeof(value), |
233 | &value); | ||
234 | if (ret < 0 || value < 0) { | 234 | if (ret < 0 || value < 0) { |
235 | *val1 = *val2 = 0; | 235 | *val1 = *val2 = 0; |
236 | return -EINVAL; | 236 | return -EINVAL; |
@@ -253,9 +253,9 @@ int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st, | |||
253 | value = convert_to_vtf_format(st->sensitivity.size, | 253 | value = convert_to_vtf_format(st->sensitivity.size, |
254 | st->sensitivity.unit_expo, | 254 | st->sensitivity.unit_expo, |
255 | val1, val2); | 255 | val1, val2); |
256 | ret = sensor_hub_set_feature(st->hsdev, | 256 | ret = sensor_hub_set_feature(st->hsdev, st->sensitivity.report_id, |
257 | st->sensitivity.report_id, | 257 | st->sensitivity.index, sizeof(value), |
258 | st->sensitivity.index, value); | 258 | &value); |
259 | if (ret < 0 || value < 0) | 259 | if (ret < 0 || value < 0) |
260 | ret = -EINVAL; | 260 | ret = -EINVAL; |
261 | 261 | ||
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c index 2f1d535b94c4..610fc98f88ef 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c | |||
@@ -68,20 +68,21 @@ static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state) | |||
68 | if (state_val >= 0) { | 68 | if (state_val >= 0) { |
69 | state_val += st->power_state.logical_minimum; | 69 | state_val += st->power_state.logical_minimum; |
70 | sensor_hub_set_feature(st->hsdev, st->power_state.report_id, | 70 | sensor_hub_set_feature(st->hsdev, st->power_state.report_id, |
71 | st->power_state.index, | 71 | st->power_state.index, sizeof(state_val), |
72 | (s32)state_val); | 72 | &state_val); |
73 | } | 73 | } |
74 | 74 | ||
75 | if (report_val >= 0) { | 75 | if (report_val >= 0) { |
76 | report_val += st->report_state.logical_minimum; | 76 | report_val += st->report_state.logical_minimum; |
77 | sensor_hub_set_feature(st->hsdev, st->report_state.report_id, | 77 | sensor_hub_set_feature(st->hsdev, st->report_state.report_id, |
78 | st->report_state.index, | 78 | st->report_state.index, |
79 | (s32)report_val); | 79 | sizeof(report_val), |
80 | &report_val); | ||
80 | } | 81 | } |
81 | 82 | ||
82 | sensor_hub_get_feature(st->hsdev, st->power_state.report_id, | 83 | sensor_hub_get_feature(st->hsdev, st->power_state.report_id, |
83 | st->power_state.index, | 84 | st->power_state.index, |
84 | &state_val); | 85 | sizeof(state_val), &state_val); |
85 | if (state && poll_value) | 86 | if (state && poll_value) |
86 | msleep_interruptible(poll_value * 2); | 87 | msleep_interruptible(poll_value * 2); |
87 | 88 | ||
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c index a3c3e19de527..b5883b6f4e50 100644 --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c | |||
@@ -123,7 +123,8 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev, | |||
123 | *val = sensor_hub_input_attr_get_raw_value( | 123 | *val = sensor_hub_input_attr_get_raw_value( |
124 | gyro_state->common_attributes.hsdev, | 124 | gyro_state->common_attributes.hsdev, |
125 | HID_USAGE_SENSOR_GYRO_3D, address, | 125 | HID_USAGE_SENSOR_GYRO_3D, address, |
126 | report_id); | 126 | report_id, |
127 | SENSOR_HUB_SYNC); | ||
127 | else { | 128 | else { |
128 | *val = 0; | 129 | *val = 0; |
129 | hid_sensor_power_state(&gyro_state->common_attributes, | 130 | hid_sensor_power_state(&gyro_state->common_attributes, |
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index 948acfc38b8c..1609ecdd01b0 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c | |||
@@ -101,7 +101,8 @@ static int als_read_raw(struct iio_dev *indio_dev, | |||
101 | *val = sensor_hub_input_attr_get_raw_value( | 101 | *val = sensor_hub_input_attr_get_raw_value( |
102 | als_state->common_attributes.hsdev, | 102 | als_state->common_attributes.hsdev, |
103 | HID_USAGE_SENSOR_ALS, address, | 103 | HID_USAGE_SENSOR_ALS, address, |
104 | report_id); | 104 | report_id, |
105 | SENSOR_HUB_SYNC); | ||
105 | hid_sensor_power_state(&als_state->common_attributes, | 106 | hid_sensor_power_state(&als_state->common_attributes, |
106 | false); | 107 | false); |
107 | } else { | 108 | } else { |
diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c index 3ecf79ed08ac..91ecc46ffeaa 100644 --- a/drivers/iio/light/hid-sensor-prox.c +++ b/drivers/iio/light/hid-sensor-prox.c | |||
@@ -96,7 +96,8 @@ static int prox_read_raw(struct iio_dev *indio_dev, | |||
96 | *val = sensor_hub_input_attr_get_raw_value( | 96 | *val = sensor_hub_input_attr_get_raw_value( |
97 | prox_state->common_attributes.hsdev, | 97 | prox_state->common_attributes.hsdev, |
98 | HID_USAGE_SENSOR_PROX, address, | 98 | HID_USAGE_SENSOR_PROX, address, |
99 | report_id); | 99 | report_id, |
100 | SENSOR_HUB_SYNC); | ||
100 | hid_sensor_power_state(&prox_state->common_attributes, | 101 | hid_sensor_power_state(&prox_state->common_attributes, |
101 | false); | 102 | false); |
102 | } else { | 103 | } else { |
diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c index d22993b4066a..4f9c0be24451 100644 --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c | |||
@@ -170,7 +170,8 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev, | |||
170 | *val = sensor_hub_input_attr_get_raw_value( | 170 | *val = sensor_hub_input_attr_get_raw_value( |
171 | magn_state->common_attributes.hsdev, | 171 | magn_state->common_attributes.hsdev, |
172 | HID_USAGE_SENSOR_COMPASS_3D, address, | 172 | HID_USAGE_SENSOR_COMPASS_3D, address, |
173 | report_id); | 173 | report_id, |
174 | SENSOR_HUB_SYNC); | ||
174 | else { | 175 | else { |
175 | *val = 0; | 176 | *val = 0; |
176 | hid_sensor_power_state(&magn_state->common_attributes, | 177 | hid_sensor_power_state(&magn_state->common_attributes, |
diff --git a/drivers/iio/orientation/hid-sensor-incl-3d.c b/drivers/iio/orientation/hid-sensor-incl-3d.c index 73854460bb2c..5930fa32a2ab 100644 --- a/drivers/iio/orientation/hid-sensor-incl-3d.c +++ b/drivers/iio/orientation/hid-sensor-incl-3d.c | |||
@@ -124,7 +124,8 @@ static int incl_3d_read_raw(struct iio_dev *indio_dev, | |||
124 | *val = sensor_hub_input_attr_get_raw_value( | 124 | *val = sensor_hub_input_attr_get_raw_value( |
125 | incl_state->common_attributes.hsdev, | 125 | incl_state->common_attributes.hsdev, |
126 | HID_USAGE_SENSOR_INCLINOMETER_3D, address, | 126 | HID_USAGE_SENSOR_INCLINOMETER_3D, address, |
127 | report_id); | 127 | report_id, |
128 | SENSOR_HUB_SYNC); | ||
128 | else { | 129 | else { |
129 | hid_sensor_power_state(&incl_state->common_attributes, | 130 | hid_sensor_power_state(&incl_state->common_attributes, |
130 | false); | 131 | false); |
diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c index 1af314926ebd..7bb8d4c1f7df 100644 --- a/drivers/iio/pressure/hid-sensor-press.c +++ b/drivers/iio/pressure/hid-sensor-press.c | |||
@@ -100,7 +100,8 @@ static int press_read_raw(struct iio_dev *indio_dev, | |||
100 | *val = sensor_hub_input_attr_get_raw_value( | 100 | *val = sensor_hub_input_attr_get_raw_value( |
101 | press_state->common_attributes.hsdev, | 101 | press_state->common_attributes.hsdev, |
102 | HID_USAGE_SENSOR_PRESSURE, address, | 102 | HID_USAGE_SENSOR_PRESSURE, address, |
103 | report_id); | 103 | report_id, |
104 | SENSOR_HUB_SYNC); | ||
104 | hid_sensor_power_state(&press_state->common_attributes, | 105 | hid_sensor_power_state(&press_state->common_attributes, |
105 | false); | 106 | false); |
106 | } else { | 107 | } else { |
diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c index cb150a1dbaff..34feb3e1127b 100644 --- a/drivers/input/input-mt.c +++ b/drivers/input/input-mt.c | |||
@@ -88,10 +88,13 @@ int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots, | |||
88 | goto err_mem; | 88 | goto err_mem; |
89 | } | 89 | } |
90 | 90 | ||
91 | /* Mark slots as 'unused' */ | 91 | /* Mark slots as 'inactive' */ |
92 | for (i = 0; i < num_slots; i++) | 92 | for (i = 0; i < num_slots; i++) |
93 | input_mt_set_value(&mt->slots[i], ABS_MT_TRACKING_ID, -1); | 93 | input_mt_set_value(&mt->slots[i], ABS_MT_TRACKING_ID, -1); |
94 | 94 | ||
95 | /* Mark slots as 'unused' */ | ||
96 | mt->frame = 1; | ||
97 | |||
95 | dev->mt = mt; | 98 | dev->mt = mt; |
96 | return 0; | 99 | return 0; |
97 | err_mem: | 100 | err_mem: |
@@ -439,6 +442,8 @@ EXPORT_SYMBOL(input_mt_assign_slots); | |||
439 | * set the key on the first unused slot and return. | 442 | * set the key on the first unused slot and return. |
440 | * | 443 | * |
441 | * If no available slot can be found, -1 is returned. | 444 | * If no available slot can be found, -1 is returned. |
445 | * Note that for this function to work properly, input_mt_sync_frame() has | ||
446 | * to be called at each frame. | ||
442 | */ | 447 | */ |
443 | int input_mt_get_slot_by_key(struct input_dev *dev, int key) | 448 | int input_mt_get_slot_by_key(struct input_dev *dev, int key) |
444 | { | 449 | { |
@@ -453,7 +458,7 @@ int input_mt_get_slot_by_key(struct input_dev *dev, int key) | |||
453 | return s - mt->slots; | 458 | return s - mt->slots; |
454 | 459 | ||
455 | for (s = mt->slots; s != mt->slots + mt->num_slots; s++) | 460 | for (s = mt->slots; s != mt->slots + mt->num_slots; s++) |
456 | if (!input_mt_is_active(s)) { | 461 | if (!input_mt_is_active(s) && !input_mt_is_used(mt, s)) { |
457 | s->key = key; | 462 | s->key = key; |
458 | return s - mt->slots; | 463 | return s - mt->slots; |
459 | } | 464 | } |
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c index ae7c2ba440cf..af4f85a66b39 100644 --- a/drivers/rtc/rtc-hid-sensor-time.c +++ b/drivers/rtc/rtc-hid-sensor-time.c | |||
@@ -213,7 +213,7 @@ static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm) | |||
213 | /* get a report with all values through requesting one value */ | 213 | /* get a report with all values through requesting one value */ |
214 | sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev, | 214 | sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev, |
215 | HID_USAGE_SENSOR_TIME, hid_time_addresses[0], | 215 | HID_USAGE_SENSOR_TIME, hid_time_addresses[0], |
216 | time_state->info[0].report_id); | 216 | time_state->info[0].report_id, SENSOR_HUB_SYNC); |
217 | /* wait for all values (event) */ | 217 | /* wait for all values (event) */ |
218 | ret = wait_for_completion_killable_timeout( | 218 | ret = wait_for_completion_killable_timeout( |
219 | &time_state->comp_last_time, HZ*6); | 219 | &time_state->comp_last_time, HZ*6); |
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h index 4173a8fdad9e..0408421d885f 100644 --- a/include/linux/hid-sensor-hub.h +++ b/include/linux/hid-sensor-hub.h | |||
@@ -49,19 +49,43 @@ struct hid_sensor_hub_attribute_info { | |||
49 | }; | 49 | }; |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * struct sensor_hub_pending - Synchronous read pending information | ||
53 | * @status: Pending status true/false. | ||
54 | * @ready: Completion synchronization data. | ||
55 | * @usage_id: Usage id for physical device, E.g. Gyro usage id. | ||
56 | * @attr_usage_id: Usage Id of a field, E.g. X-AXIS for a gyro. | ||
57 | * @raw_size: Response size for a read request. | ||
58 | * @raw_data: Place holder for received response. | ||
59 | */ | ||
60 | struct sensor_hub_pending { | ||
61 | bool status; | ||
62 | struct completion ready; | ||
63 | u32 usage_id; | ||
64 | u32 attr_usage_id; | ||
65 | int raw_size; | ||
66 | u8 *raw_data; | ||
67 | }; | ||
68 | |||
69 | /** | ||
52 | * struct hid_sensor_hub_device - Stores the hub instance data | 70 | * struct hid_sensor_hub_device - Stores the hub instance data |
53 | * @hdev: Stores the hid instance. | 71 | * @hdev: Stores the hid instance. |
54 | * @vendor_id: Vendor id of hub device. | 72 | * @vendor_id: Vendor id of hub device. |
55 | * @product_id: Product id of hub device. | 73 | * @product_id: Product id of hub device. |
74 | * @usage: Usage id for this hub device instance. | ||
56 | * @start_collection_index: Starting index for a phy type collection | 75 | * @start_collection_index: Starting index for a phy type collection |
57 | * @end_collection_index: Last index for a phy type collection | 76 | * @end_collection_index: Last index for a phy type collection |
77 | * @mutex: synchronizing mutex. | ||
78 | * @pending: Holds information of pending sync read request. | ||
58 | */ | 79 | */ |
59 | struct hid_sensor_hub_device { | 80 | struct hid_sensor_hub_device { |
60 | struct hid_device *hdev; | 81 | struct hid_device *hdev; |
61 | u32 vendor_id; | 82 | u32 vendor_id; |
62 | u32 product_id; | 83 | u32 product_id; |
84 | u32 usage; | ||
63 | int start_collection_index; | 85 | int start_collection_index; |
64 | int end_collection_index; | 86 | int end_collection_index; |
87 | struct mutex mutex; | ||
88 | struct sensor_hub_pending pending; | ||
65 | }; | 89 | }; |
66 | 90 | ||
67 | /** | 91 | /** |
@@ -152,40 +176,51 @@ int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev, | |||
152 | * @usage_id: Attribute usage id of parent physical device as per spec | 176 | * @usage_id: Attribute usage id of parent physical device as per spec |
153 | * @attr_usage_id: Attribute usage id as per spec | 177 | * @attr_usage_id: Attribute usage id as per spec |
154 | * @report_id: Report id to look for | 178 | * @report_id: Report id to look for |
179 | * @flag: Synchronous or asynchronous read | ||
155 | * | 180 | * |
156 | * Issues a synchronous read request for an input attribute. Returns | 181 | * Issues a synchronous or asynchronous read request for an input attribute. |
157 | * data upto 32 bits. Since client can get events, so this call should | 182 | * Returns data upto 32 bits. |
158 | * not be used for data paths, this will impact performance. | ||
159 | */ | 183 | */ |
160 | 184 | ||
185 | enum sensor_hub_read_flags { | ||
186 | SENSOR_HUB_SYNC, | ||
187 | SENSOR_HUB_ASYNC, | ||
188 | }; | ||
189 | |||
161 | int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, | 190 | int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, |
162 | u32 usage_id, | 191 | u32 usage_id, |
163 | u32 attr_usage_id, u32 report_id); | 192 | u32 attr_usage_id, u32 report_id, |
193 | enum sensor_hub_read_flags flag | ||
194 | ); | ||
195 | |||
164 | /** | 196 | /** |
165 | * sensor_hub_set_feature() - Feature set request | 197 | * sensor_hub_set_feature() - Feature set request |
166 | * @hsdev: Hub device instance. | 198 | * @hsdev: Hub device instance. |
167 | * @report_id: Report id to look for | 199 | * @report_id: Report id to look for |
168 | * @field_index: Field index inside a report | 200 | * @field_index: Field index inside a report |
169 | * @value: Value to set | 201 | * @buffer_size: size of the buffer |
202 | * @buffer: buffer to use in the feature set | ||
170 | * | 203 | * |
171 | * Used to set a field in feature report. For example this can set polling | 204 | * Used to set a field in feature report. For example this can set polling |
172 | * interval, sensitivity, activate/deactivate state. | 205 | * interval, sensitivity, activate/deactivate state. |
173 | */ | 206 | */ |
174 | int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, | 207 | int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, |
175 | u32 field_index, s32 value); | 208 | u32 field_index, int buffer_size, void *buffer); |
176 | 209 | ||
177 | /** | 210 | /** |
178 | * sensor_hub_get_feature() - Feature get request | 211 | * sensor_hub_get_feature() - Feature get request |
179 | * @hsdev: Hub device instance. | 212 | * @hsdev: Hub device instance. |
180 | * @report_id: Report id to look for | 213 | * @report_id: Report id to look for |
181 | * @field_index: Field index inside a report | 214 | * @field_index: Field index inside a report |
182 | * @value: Place holder for return value | 215 | * @buffer_size: size of the buffer |
216 | * @buffer: buffer to copy output | ||
183 | * | 217 | * |
184 | * Used to get a field in feature report. For example this can get polling | 218 | * Used to get a field in feature report. For example this can get polling |
185 | * interval, sensitivity, activate/deactivate state. | 219 | * interval, sensitivity, activate/deactivate state. On success it returns |
220 | * number of bytes copied to buffer. On failure, it returns value < 0. | ||
186 | */ | 221 | */ |
187 | int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, | 222 | int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, |
188 | u32 field_index, s32 *value); | 223 | u32 field_index, int buffer_size, void *buffer); |
189 | 224 | ||
190 | /* hid-sensor-attributes */ | 225 | /* hid-sensor-attributes */ |
191 | 226 | ||
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h index 109f0e633e01..f2ee90aed0c2 100644 --- a/include/linux/hid-sensor-ids.h +++ b/include/linux/hid-sensor-ids.h | |||
@@ -21,6 +21,8 @@ | |||
21 | 21 | ||
22 | #define HID_MAX_PHY_DEVICES 0xFF | 22 | #define HID_MAX_PHY_DEVICES 0xFF |
23 | 23 | ||
24 | #define HID_USAGE_SENSOR_COLLECTION 0x200001 | ||
25 | |||
24 | /* Accel 3D (200073) */ | 26 | /* Accel 3D (200073) */ |
25 | #define HID_USAGE_SENSOR_ACCEL_3D 0x200073 | 27 | #define HID_USAGE_SENSOR_ACCEL_3D 0x200073 |
26 | #define HID_USAGE_SENSOR_DATA_ACCELERATION 0x200452 | 28 | #define HID_USAGE_SENSOR_DATA_ACCELERATION 0x200452 |
diff --git a/include/linux/hid.h b/include/linux/hid.h index f94cf28e4b7c..176b43670e5d 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h | |||
@@ -159,6 +159,7 @@ struct hid_item { | |||
159 | #define HID_UP_LED 0x00080000 | 159 | #define HID_UP_LED 0x00080000 |
160 | #define HID_UP_BUTTON 0x00090000 | 160 | #define HID_UP_BUTTON 0x00090000 |
161 | #define HID_UP_ORDINAL 0x000a0000 | 161 | #define HID_UP_ORDINAL 0x000a0000 |
162 | #define HID_UP_TELEPHONY 0x000b0000 | ||
162 | #define HID_UP_CONSUMER 0x000c0000 | 163 | #define HID_UP_CONSUMER 0x000c0000 |
163 | #define HID_UP_DIGITIZER 0x000d0000 | 164 | #define HID_UP_DIGITIZER 0x000d0000 |
164 | #define HID_UP_PID 0x000f0000 | 165 | #define HID_UP_PID 0x000f0000 |
@@ -269,6 +270,7 @@ struct hid_item { | |||
269 | #define HID_DG_DEVICEINDEX 0x000d0053 | 270 | #define HID_DG_DEVICEINDEX 0x000d0053 |
270 | #define HID_DG_CONTACTCOUNT 0x000d0054 | 271 | #define HID_DG_CONTACTCOUNT 0x000d0054 |
271 | #define HID_DG_CONTACTMAX 0x000d0055 | 272 | #define HID_DG_CONTACTMAX 0x000d0055 |
273 | #define HID_DG_BUTTONTYPE 0x000d0059 | ||
272 | #define HID_DG_BARRELSWITCH2 0x000d005a | 274 | #define HID_DG_BARRELSWITCH2 0x000d005a |
273 | #define HID_DG_TOOLSERIALNUMBER 0x000d005b | 275 | #define HID_DG_TOOLSERIALNUMBER 0x000d005b |
274 | 276 | ||
diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h index 2f62ab2d7bf9..8038e9aa3b95 100644 --- a/include/uapi/linux/input.h +++ b/include/uapi/linux/input.h | |||
@@ -702,6 +702,10 @@ struct input_keymap_entry { | |||
702 | #define KEY_NUMERIC_9 0x209 | 702 | #define KEY_NUMERIC_9 0x209 |
703 | #define KEY_NUMERIC_STAR 0x20a | 703 | #define KEY_NUMERIC_STAR 0x20a |
704 | #define KEY_NUMERIC_POUND 0x20b | 704 | #define KEY_NUMERIC_POUND 0x20b |
705 | #define KEY_NUMERIC_A 0x20c /* Phone key A - HUT Telephony 0xb9 */ | ||
706 | #define KEY_NUMERIC_B 0x20d | ||
707 | #define KEY_NUMERIC_C 0x20e | ||
708 | #define KEY_NUMERIC_D 0x20f | ||
705 | 709 | ||
706 | #define KEY_CAMERA_FOCUS 0x210 | 710 | #define KEY_CAMERA_FOCUS 0x210 |
707 | #define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */ | 711 | #define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */ |
diff --git a/samples/hidraw/Makefile b/samples/hidraw/Makefile index 382eeae77bd6..a9ab96188fbe 100644 --- a/samples/hidraw/Makefile +++ b/samples/hidraw/Makefile | |||
@@ -8,3 +8,5 @@ hostprogs-y := hid-example | |||
8 | always := $(hostprogs-y) | 8 | always := $(hostprogs-y) |
9 | 9 | ||
10 | HOSTCFLAGS_hid-example.o += -I$(objtree)/usr/include | 10 | HOSTCFLAGS_hid-example.o += -I$(objtree)/usr/include |
11 | |||
12 | all: hid-example | ||
diff --git a/samples/hidraw/hid-example.c b/samples/hidraw/hid-example.c index 512a7e50bcae..92e6c1511910 100644 --- a/samples/hidraw/hid-example.c +++ b/samples/hidraw/hid-example.c | |||
@@ -46,10 +46,14 @@ int main(int argc, char **argv) | |||
46 | char buf[256]; | 46 | char buf[256]; |
47 | struct hidraw_report_descriptor rpt_desc; | 47 | struct hidraw_report_descriptor rpt_desc; |
48 | struct hidraw_devinfo info; | 48 | struct hidraw_devinfo info; |
49 | char *device = "/dev/hidraw0"; | ||
50 | |||
51 | if (argc > 1) | ||
52 | device = argv[1]; | ||
49 | 53 | ||
50 | /* Open the Device with non-blocking reads. In real life, | 54 | /* Open the Device with non-blocking reads. In real life, |
51 | don't use a hard coded path; use libudev instead. */ | 55 | don't use a hard coded path; use libudev instead. */ |
52 | fd = open("/dev/hidraw0", O_RDWR|O_NONBLOCK); | 56 | fd = open(device, O_RDWR|O_NONBLOCK); |
53 | 57 | ||
54 | if (fd < 0) { | 58 | if (fd < 0) { |
55 | perror("Unable to open device"); | 59 | perror("Unable to open device"); |