diff options
31 files changed, 2783 insertions, 494 deletions
diff --git a/Documentation/hid/hid-transport.txt b/Documentation/hid/hid-transport.txt new file mode 100644 index 000000000000..3dcba9fd4a3a --- /dev/null +++ b/Documentation/hid/hid-transport.txt | |||
@@ -0,0 +1,317 @@ | |||
1 | HID I/O Transport Drivers | ||
2 | =========================== | ||
3 | |||
4 | The HID subsystem is independent of the underlying transport driver. Initially, | ||
5 | only USB was supported, but other specifications adopted the HID design and | ||
6 | provided new transport drivers. The kernel includes at least support for USB, | ||
7 | Bluetooth, I2C and user-space I/O drivers. | ||
8 | |||
9 | 1) HID Bus | ||
10 | ========== | ||
11 | |||
12 | The HID subsystem is designed as a bus. Any I/O subsystem may provide HID | ||
13 | devices and register them with the HID bus. HID core then loads generic device | ||
14 | drivers on top of it. The transport drivers are responsible of raw data | ||
15 | transport and device setup/management. HID core is responsible of | ||
16 | report-parsing, report interpretation and the user-space API. Device specifics | ||
17 | and quirks are handled by all layers depending on the quirk. | ||
18 | |||
19 | +-----------+ +-----------+ +-----------+ +-----------+ | ||
20 | | Device #1 | | Device #i | | Device #j | | Device #k | | ||
21 | +-----------+ +-----------+ +-----------+ +-----------+ | ||
22 | \\ // \\ // | ||
23 | +------------+ +------------+ | ||
24 | | I/O Driver | | I/O Driver | | ||
25 | +------------+ +------------+ | ||
26 | || || | ||
27 | +------------------+ +------------------+ | ||
28 | | Transport Driver | | Transport Driver | | ||
29 | +------------------+ +------------------+ | ||
30 | \___ ___/ | ||
31 | \ / | ||
32 | +----------------+ | ||
33 | | HID Core | | ||
34 | +----------------+ | ||
35 | / | | \ | ||
36 | / | | \ | ||
37 | ____________/ | | \_________________ | ||
38 | / | | \ | ||
39 | / | | \ | ||
40 | +----------------+ +-----------+ +------------------+ +------------------+ | ||
41 | | Generic Driver | | MT Driver | | Custom Driver #1 | | Custom Driver #2 | | ||
42 | +----------------+ +-----------+ +------------------+ +------------------+ | ||
43 | |||
44 | Example Drivers: | ||
45 | I/O: USB, I2C, Bluetooth-l2cap | ||
46 | Transport: USB-HID, I2C-HID, BT-HIDP | ||
47 | |||
48 | Everything below "HID Core" is simplified in this graph as it is only of | ||
49 | interest to HID device drivers. Transport drivers do not need to know the | ||
50 | specifics. | ||
51 | |||
52 | 1.1) Device Setup | ||
53 | ----------------- | ||
54 | |||
55 | I/O drivers normally provide hotplug detection or device enumeration APIs to the | ||
56 | transport drivers. Transport drivers use this to find any suitable HID device. | ||
57 | They allocate HID device objects and register them with HID core. Transport | ||
58 | drivers are not required to register themselves with HID core. HID core is never | ||
59 | aware of which transport drivers are available and is not interested in it. It | ||
60 | is only interested in devices. | ||
61 | |||
62 | Transport drivers attach a constant "struct hid_ll_driver" object with each | ||
63 | device. Once a device is registered with HID core, the callbacks provided via | ||
64 | this struct are used by HID core to communicate with the device. | ||
65 | |||
66 | Transport drivers are responsible of detecting device failures and unplugging. | ||
67 | HID core will operate a device as long as it is registered regardless of any | ||
68 | device failures. Once transport drivers detect unplug or failure events, they | ||
69 | must unregister the device from HID core and HID core will stop using the | ||
70 | provided callbacks. | ||
71 | |||
72 | 1.2) Transport Driver Requirements | ||
73 | ---------------------------------- | ||
74 | |||
75 | The terms "asynchronous" and "synchronous" in this document describe the | ||
76 | transmission behavior regarding acknowledgements. An asynchronous channel must | ||
77 | not perform any synchronous operations like waiting for acknowledgements or | ||
78 | verifications. Generally, HID calls operating on asynchronous channels must be | ||
79 | running in atomic-context just fine. | ||
80 | On the other hand, synchronous channels can be implemented by the transport | ||
81 | driver in whatever way they like. They might just be the same as asynchronous | ||
82 | channels, but they can also provide acknowledgement reports, automatic | ||
83 | retransmission on failure, etc. in a blocking manner. If such functionality is | ||
84 | required on asynchronous channels, a transport-driver must implement that via | ||
85 | its own worker threads. | ||
86 | |||
87 | HID core requires transport drivers to follow a given design. A Transport | ||
88 | driver must provide two bi-directional I/O channels to each HID device. These | ||
89 | channels must not necessarily be bi-directional in the hardware itself. A | ||
90 | transport driver might just provide 4 uni-directional channels. Or it might | ||
91 | multiplex all four on a single physical channel. However, in this document we | ||
92 | will describe them as two bi-directional channels as they have several | ||
93 | properties in common. | ||
94 | |||
95 | - Interrupt Channel (intr): The intr channel is used for asynchronous data | ||
96 | reports. No management commands or data acknowledgements are sent on this | ||
97 | channel. Any unrequested incoming or outgoing data report must be sent on | ||
98 | this channel and is never acknowledged by the remote side. Devices usually | ||
99 | send their input events on this channel. Outgoing events are normally | ||
100 | not send via intr, except if high throughput is required. | ||
101 | - Control Channel (ctrl): The ctrl channel is used for synchronous requests and | ||
102 | device management. Unrequested data input events must not be sent on this | ||
103 | channel and are normally ignored. Instead, devices only send management | ||
104 | events or answers to host requests on this channel. | ||
105 | The control-channel is used for direct blocking queries to the device | ||
106 | independent of any events on the intr-channel. | ||
107 | Outgoing reports are usually sent on the ctrl channel via synchronous | ||
108 | SET_REPORT requests. | ||
109 | |||
110 | Communication between devices and HID core is mostly done via HID reports. A | ||
111 | report can be of one of three types: | ||
112 | |||
113 | - INPUT Report: Input reports provide data from device to host. This | ||
114 | data may include button events, axis events, battery status or more. This | ||
115 | data is generated by the device and sent to the host with or without | ||
116 | requiring explicit requests. Devices can choose to send data continuously or | ||
117 | only on change. | ||
118 | - OUTPUT Report: Output reports change device states. They are sent from host | ||
119 | to device and may include LED requests, rumble requests or more. Output | ||
120 | reports are never sent from device to host, but a host can retrieve their | ||
121 | current state. | ||
122 | Hosts may choose to send output reports either continuously or only on | ||
123 | change. | ||
124 | - FEATURE Report: Feature reports are used for specific static device features | ||
125 | and never reported spontaneously. A host can read and/or write them to access | ||
126 | data like battery-state or device-settings. | ||
127 | Feature reports are never sent without requests. A host must explicitly set | ||
128 | or retrieve a feature report. This also means, feature reports are never sent | ||
129 | on the intr channel as this channel is asynchronous. | ||
130 | |||
131 | INPUT and OUTPUT reports can be sent as pure data reports on the intr channel. | ||
132 | For INPUT reports this is the usual operational mode. But for OUTPUT reports, | ||
133 | this is rarely done as OUTPUT reports are normally quite scarce. But devices are | ||
134 | free to make excessive use of asynchronous OUTPUT reports (for instance, custom | ||
135 | HID audio speakers make great use of it). | ||
136 | |||
137 | Plain reports must not be sent on the ctrl channel, though. Instead, the ctrl | ||
138 | channel provides synchronous GET/SET_REPORT requests. Plain reports are only | ||
139 | allowed on the intr channel and are the only means of data there. | ||
140 | |||
141 | - GET_REPORT: A GET_REPORT request has a report ID as payload and is sent | ||
142 | from host to device. The device must answer with a data report for the | ||
143 | requested report ID on the ctrl channel as a synchronous acknowledgement. | ||
144 | Only one GET_REPORT request can be pending for each device. This restriction | ||
145 | is enforced by HID core as several transport drivers don't allow multiple | ||
146 | simultaneous GET_REPORT requests. | ||
147 | Note that data reports which are sent as answer to a GET_REPORT request are | ||
148 | not handled as generic device events. That is, if a device does not operate | ||
149 | in continuous data reporting mode, an answer to GET_REPORT does not replace | ||
150 | the raw data report on the intr channel on state change. | ||
151 | GET_REPORT is only used by custom HID device drivers to query device state. | ||
152 | Normally, HID core caches any device state so this request is not necessary | ||
153 | on devices that follow the HID specs except during device initialization to | ||
154 | retrieve the current state. | ||
155 | GET_REPORT requests can be sent for any of the 3 report types and shall | ||
156 | return the current report state of the device. However, OUTPUT reports as | ||
157 | payload may be blocked by the underlying transport driver if the | ||
158 | specification does not allow them. | ||
159 | - SET_REPORT: A SET_REPORT request has a report ID plus data as payload. It is | ||
160 | sent from host to device and a device must update it's current report state | ||
161 | according to the given data. Any of the 3 report types can be used. However, | ||
162 | INPUT reports as payload might be blocked by the underlying transport driver | ||
163 | if the specification does not allow them. | ||
164 | A device must answer with a synchronous acknowledgement. However, HID core | ||
165 | does not require transport drivers to forward this acknowledgement to HID | ||
166 | core. | ||
167 | Same as for GET_REPORT, only one SET_REPORT can be pending at a time. This | ||
168 | restriction is enforced by HID core as some transport drivers do not support | ||
169 | multiple synchronous SET_REPORT requests. | ||
170 | |||
171 | Other ctrl-channel requests are supported by USB-HID but are not available | ||
172 | (or deprecated) in most other transport level specifications: | ||
173 | |||
174 | - GET/SET_IDLE: Only used by USB-HID and I2C-HID. | ||
175 | - GET/SET_PROTOCOL: Not used by HID core. | ||
176 | - RESET: Used by I2C-HID, not hooked up in HID core. | ||
177 | - SET_POWER: Used by I2C-HID, not hooked up in HID core. | ||
178 | |||
179 | 2) HID API | ||
180 | ========== | ||
181 | |||
182 | 2.1) Initialization | ||
183 | ------------------- | ||
184 | |||
185 | Transport drivers normally use the following procedure to register a new device | ||
186 | with HID core: | ||
187 | |||
188 | struct hid_device *hid; | ||
189 | int ret; | ||
190 | |||
191 | hid = hid_allocate_device(); | ||
192 | if (IS_ERR(hid)) { | ||
193 | ret = PTR_ERR(hid); | ||
194 | goto err_<...>; | ||
195 | } | ||
196 | |||
197 | strlcpy(hid->name, <device-name-src>, 127); | ||
198 | strlcpy(hid->phys, <device-phys-src>, 63); | ||
199 | strlcpy(hid->uniq, <device-uniq-src>, 63); | ||
200 | |||
201 | hid->ll_driver = &custom_ll_driver; | ||
202 | hid->bus = <device-bus>; | ||
203 | hid->vendor = <device-vendor>; | ||
204 | hid->product = <device-product>; | ||
205 | hid->version = <device-version>; | ||
206 | hid->country = <device-country>; | ||
207 | hid->dev.parent = <pointer-to-parent-device>; | ||
208 | hid->driver_data = <transport-driver-data-field>; | ||
209 | |||
210 | ret = hid_add_device(hid); | ||
211 | if (ret) | ||
212 | goto err_<...>; | ||
213 | |||
214 | Once hid_add_device() is entered, HID core might use the callbacks provided in | ||
215 | "custom_ll_driver". Note that fields like "country" can be ignored by underlying | ||
216 | transport-drivers if not supported. | ||
217 | |||
218 | To unregister a device, use: | ||
219 | |||
220 | hid_destroy_device(hid); | ||
221 | |||
222 | Once hid_destroy_device() returns, HID core will no longer make use of any | ||
223 | driver callbacks. | ||
224 | |||
225 | 2.2) hid_ll_driver operations | ||
226 | ----------------------------- | ||
227 | |||
228 | The available HID callbacks are: | ||
229 | - int (*start) (struct hid_device *hdev) | ||
230 | Called from HID device drivers once they want to use the device. Transport | ||
231 | drivers can choose to setup their device in this callback. However, normally | ||
232 | devices are already set up before transport drivers register them to HID core | ||
233 | so this is mostly only used by USB-HID. | ||
234 | |||
235 | - void (*stop) (struct hid_device *hdev) | ||
236 | Called from HID device drivers once they are done with a device. Transport | ||
237 | drivers can free any buffers and deinitialize the device. But note that | ||
238 | ->start() might be called again if another HID device driver is loaded on the | ||
239 | device. | ||
240 | Transport drivers are free to ignore it and deinitialize devices after they | ||
241 | destroyed them via hid_destroy_device(). | ||
242 | |||
243 | - int (*open) (struct hid_device *hdev) | ||
244 | Called from HID device drivers once they are interested in data reports. | ||
245 | Usually, while user-space didn't open any input API/etc., device drivers are | ||
246 | not interested in device data and transport drivers can put devices asleep. | ||
247 | However, once ->open() is called, transport drivers must be ready for I/O. | ||
248 | ->open() calls are nested for each client that opens the HID device. | ||
249 | |||
250 | - void (*close) (struct hid_device *hdev) | ||
251 | Called from HID device drivers after ->open() was called but they are no | ||
252 | longer interested in device reports. (Usually if user-space closed any input | ||
253 | devices of the driver). | ||
254 | Transport drivers can put devices asleep and terminate any I/O of all | ||
255 | ->open() calls have been followed by a ->close() call. However, ->start() may | ||
256 | be called again if the device driver is interested in input reports again. | ||
257 | |||
258 | - int (*parse) (struct hid_device *hdev) | ||
259 | Called once during device setup after ->start() has been called. Transport | ||
260 | drivers must read the HID report-descriptor from the device and tell HID core | ||
261 | about it via hid_parse_report(). | ||
262 | |||
263 | - int (*power) (struct hid_device *hdev, int level) | ||
264 | Called by HID core to give PM hints to transport drivers. Usually this is | ||
265 | analogical to the ->open() and ->close() hints and redundant. | ||
266 | |||
267 | - void (*request) (struct hid_device *hdev, struct hid_report *report, | ||
268 | int reqtype) | ||
269 | Send an HID request on the ctrl channel. "report" contains the report that | ||
270 | should be sent and "reqtype" the request type. Request-type can be | ||
271 | HID_REQ_SET_REPORT or HID_REQ_GET_REPORT. | ||
272 | This callback is optional. If not provided, HID core will assemble a raw | ||
273 | report following the HID specs and send it via the ->raw_request() callback. | ||
274 | The transport driver is free to implement this asynchronously. | ||
275 | |||
276 | - int (*wait) (struct hid_device *hdev) | ||
277 | Used by HID core before calling ->request() again. A transport driver can use | ||
278 | it to wait for any pending requests to complete if only one request is | ||
279 | allowed at a time. | ||
280 | |||
281 | - int (*raw_request) (struct hid_device *hdev, unsigned char reportnum, | ||
282 | __u8 *buf, size_t count, unsigned char rtype, | ||
283 | int reqtype) | ||
284 | Same as ->request() but provides the report as raw buffer. This request shall | ||
285 | be synchronous. A transport driver must not use ->wait() to complete such | ||
286 | requests. This request is mandatory and hid core will reject the device if | ||
287 | it is missing. | ||
288 | |||
289 | - int (*output_report) (struct hid_device *hdev, __u8 *buf, size_t len) | ||
290 | Send raw output report via intr channel. Used by some HID device drivers | ||
291 | which require high throughput for outgoing requests on the intr channel. This | ||
292 | must not cause SET_REPORT calls! This must be implemented as asynchronous | ||
293 | output report on the intr channel! | ||
294 | |||
295 | - int (*idle) (struct hid_device *hdev, int report, int idle, int reqtype) | ||
296 | Perform SET/GET_IDLE request. Only used by USB-HID, do not implement! | ||
297 | |||
298 | 2.3) Data Path | ||
299 | -------------- | ||
300 | |||
301 | Transport drivers are responsible of reading data from I/O devices. They must | ||
302 | handle any I/O-related state-tracking themselves. HID core does not implement | ||
303 | protocol handshakes or other management commands which can be required by the | ||
304 | given HID transport specification. | ||
305 | |||
306 | Every raw data packet read from a device must be fed into HID core via | ||
307 | hid_input_report(). You must specify the channel-type (intr or ctrl) and report | ||
308 | type (input/output/feature). Under normal conditions, only input reports are | ||
309 | provided via this API. | ||
310 | |||
311 | Responses to GET_REPORT requests via ->request() must also be provided via this | ||
312 | API. Responses to ->raw_request() are synchronous and must be intercepted by the | ||
313 | transport driver and not passed to hid_input_report(). | ||
314 | Acknowledgements to SET_REPORT requests are not of interest to HID core. | ||
315 | |||
316 | ---------------------------------------------------- | ||
317 | Written 2013, David Herrmann <dh.herrmann@gmail.com> | ||
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index f7220011a00b..7af9d0b5dea1 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig | |||
@@ -175,6 +175,15 @@ config HID_PRODIKEYS | |||
175 | multimedia keyboard, but will lack support for the musical keyboard | 175 | multimedia keyboard, but will lack support for the musical keyboard |
176 | and some additional multimedia keys. | 176 | and some additional multimedia keys. |
177 | 177 | ||
178 | config HID_CP2112 | ||
179 | tristate "Silicon Labs CP2112 HID USB-to-SMBus Bridge support" | ||
180 | depends on USB_HID && I2C && GPIOLIB | ||
181 | ---help--- | ||
182 | Support for Silicon Labs CP2112 HID USB to SMBus Master Bridge. | ||
183 | This is a HID device driver which registers as an i2c adapter | ||
184 | and gpiochip to expose these functions of the CP2112. The | ||
185 | customizable USB descriptor fields are exposed as sysfs attributes. | ||
186 | |||
178 | config HID_CYPRESS | 187 | config HID_CYPRESS |
179 | tristate "Cypress mouse and barcode readers" if EXPERT | 188 | tristate "Cypress mouse and barcode readers" if EXPERT |
180 | depends on HID | 189 | depends on HID |
@@ -608,25 +617,27 @@ config HID_SAMSUNG | |||
608 | Support for Samsung InfraRed remote control or keyboards. | 617 | Support for Samsung InfraRed remote control or keyboards. |
609 | 618 | ||
610 | config HID_SONY | 619 | config HID_SONY |
611 | tristate "Sony PS2/3 accessories" | 620 | tristate "Sony PS2/3/4 accessories" |
612 | depends on USB_HID | 621 | depends on USB_HID |
613 | depends on NEW_LEDS | 622 | depends on NEW_LEDS |
614 | depends on LEDS_CLASS | 623 | depends on LEDS_CLASS |
624 | select POWER_SUPPLY | ||
615 | ---help--- | 625 | ---help--- |
616 | Support for | 626 | Support for |
617 | 627 | ||
618 | * Sony PS3 6-axis controllers | 628 | * Sony PS3 6-axis controllers |
629 | * Sony PS4 DualShock 4 controllers | ||
619 | * Buzz controllers | 630 | * Buzz controllers |
620 | * Sony PS3 Blue-ray Disk Remote Control (Bluetooth) | 631 | * Sony PS3 Blue-ray Disk Remote Control (Bluetooth) |
621 | * Logitech Harmony adapter for Sony Playstation 3 (Bluetooth) | 632 | * Logitech Harmony adapter for Sony Playstation 3 (Bluetooth) |
622 | 633 | ||
623 | config SONY_FF | 634 | config SONY_FF |
624 | bool "Sony PS2/3 accessories force feedback support" | 635 | bool "Sony PS2/3/4 accessories force feedback support" |
625 | depends on HID_SONY | 636 | depends on HID_SONY |
626 | select INPUT_FF_MEMLESS | 637 | select INPUT_FF_MEMLESS |
627 | ---help--- | 638 | ---help--- |
628 | Say Y here if you have a Sony PS2/3 accessory and want to enable force | 639 | Say Y here if you have a Sony PS2/3/4 accessory and want to enable |
629 | feedback support for it. | 640 | force feedback support for it. |
630 | 641 | ||
631 | config HID_SPEEDLINK | 642 | config HID_SPEEDLINK |
632 | tristate "Speedlink VAD Cezanne mouse support" | 643 | tristate "Speedlink VAD Cezanne mouse support" |
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index 30e44318f87f..fc712dde02a4 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile | |||
@@ -41,6 +41,7 @@ obj-$(CONFIG_HID_AUREAL) += hid-aureal.o | |||
41 | obj-$(CONFIG_HID_BELKIN) += hid-belkin.o | 41 | obj-$(CONFIG_HID_BELKIN) += hid-belkin.o |
42 | obj-$(CONFIG_HID_CHERRY) += hid-cherry.o | 42 | obj-$(CONFIG_HID_CHERRY) += hid-cherry.o |
43 | obj-$(CONFIG_HID_CHICONY) += hid-chicony.o | 43 | obj-$(CONFIG_HID_CHICONY) += hid-chicony.o |
44 | obj-$(CONFIG_HID_CP2112) += hid-cp2112.o | ||
44 | obj-$(CONFIG_HID_CYPRESS) += hid-cypress.o | 45 | obj-$(CONFIG_HID_CYPRESS) += hid-cypress.o |
45 | obj-$(CONFIG_HID_DRAGONRISE) += hid-dr.o | 46 | obj-$(CONFIG_HID_DRAGONRISE) += hid-dr.o |
46 | obj-$(CONFIG_HID_EMS_FF) += hid-emsff.o | 47 | obj-$(CONFIG_HID_EMS_FF) += hid-emsff.o |
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c index 497558127bb3..f822fd2a1ada 100644 --- a/drivers/hid/hid-apple.c +++ b/drivers/hid/hid-apple.c | |||
@@ -469,6 +469,9 @@ static const struct hid_device_id apple_devices[] = { | |||
469 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, | 469 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, |
470 | USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI), | 470 | USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI), |
471 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, | 471 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
472 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, | ||
473 | USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS), | ||
474 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, | ||
472 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS), | 475 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS), |
473 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, | 476 | .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, |
474 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI), | 477 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI), |
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index cd33ec66133e..dbe548b22b2a 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c | |||
@@ -1248,6 +1248,11 @@ void hid_output_report(struct hid_report *report, __u8 *data) | |||
1248 | } | 1248 | } |
1249 | EXPORT_SYMBOL_GPL(hid_output_report); | 1249 | EXPORT_SYMBOL_GPL(hid_output_report); |
1250 | 1250 | ||
1251 | static int hid_report_len(struct hid_report *report) | ||
1252 | { | ||
1253 | return ((report->size - 1) >> 3) + 1 + (report->id > 0) + 7; | ||
1254 | } | ||
1255 | |||
1251 | /* | 1256 | /* |
1252 | * Allocator for buffer that is going to be passed to hid_output_report() | 1257 | * Allocator for buffer that is going to be passed to hid_output_report() |
1253 | */ | 1258 | */ |
@@ -1258,7 +1263,7 @@ u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags) | |||
1258 | * of implement() working on 8 byte chunks | 1263 | * of implement() working on 8 byte chunks |
1259 | */ | 1264 | */ |
1260 | 1265 | ||
1261 | int len = ((report->size - 1) >> 3) + 1 + (report->id > 0) + 7; | 1266 | int len = hid_report_len(report); |
1262 | 1267 | ||
1263 | return kmalloc(len, flags); | 1268 | return kmalloc(len, flags); |
1264 | } | 1269 | } |
@@ -1314,6 +1319,41 @@ static struct hid_report *hid_get_report(struct hid_report_enum *report_enum, | |||
1314 | return report; | 1319 | return report; |
1315 | } | 1320 | } |
1316 | 1321 | ||
1322 | /* | ||
1323 | * Implement a generic .request() callback, using .raw_request() | ||
1324 | * DO NOT USE in hid drivers directly, but through hid_hw_request instead. | ||
1325 | */ | ||
1326 | void __hid_request(struct hid_device *hid, struct hid_report *report, | ||
1327 | int reqtype) | ||
1328 | { | ||
1329 | char *buf; | ||
1330 | int ret; | ||
1331 | int len; | ||
1332 | |||
1333 | buf = hid_alloc_report_buf(report, GFP_KERNEL); | ||
1334 | if (!buf) | ||
1335 | return; | ||
1336 | |||
1337 | len = hid_report_len(report); | ||
1338 | |||
1339 | if (reqtype == HID_REQ_SET_REPORT) | ||
1340 | hid_output_report(report, buf); | ||
1341 | |||
1342 | ret = hid->ll_driver->raw_request(hid, report->id, buf, len, | ||
1343 | report->type, reqtype); | ||
1344 | if (ret < 0) { | ||
1345 | dbg_hid("unable to complete request: %d\n", ret); | ||
1346 | goto out; | ||
1347 | } | ||
1348 | |||
1349 | if (reqtype == HID_REQ_GET_REPORT) | ||
1350 | hid_input_report(hid, report->type, buf, ret, 0); | ||
1351 | |||
1352 | out: | ||
1353 | kfree(buf); | ||
1354 | } | ||
1355 | EXPORT_SYMBOL_GPL(__hid_request); | ||
1356 | |||
1317 | int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, | 1357 | int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, |
1318 | int interrupt) | 1358 | int interrupt) |
1319 | { | 1359 | { |
@@ -1679,6 +1719,7 @@ static const struct hid_device_id hid_have_special_driver[] = { | |||
1679 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) }, | 1719 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) }, |
1680 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) }, | 1720 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) }, |
1681 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) }, | 1721 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) }, |
1722 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS) }, | ||
1682 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, | 1723 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, |
1683 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, | 1724 | { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, |
1684 | { HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) }, | 1725 | { HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) }, |
@@ -1692,6 +1733,7 @@ static const struct hid_device_id hid_have_special_driver[] = { | |||
1692 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) }, | 1733 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) }, |
1693 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) }, | 1734 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) }, |
1694 | { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) }, | 1735 | { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) }, |
1736 | { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_CP2112) }, | ||
1695 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) }, | 1737 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) }, |
1696 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) }, | 1738 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) }, |
1697 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) }, | 1739 | { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) }, |
@@ -1779,6 +1821,8 @@ static const struct hid_device_id hid_have_special_driver[] = { | |||
1779 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) }, | 1821 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) }, |
1780 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) }, | 1822 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) }, |
1781 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) }, | 1823 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) }, |
1824 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_2) }, | ||
1825 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TOUCH_COVER_2) }, | ||
1782 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB) }, | 1826 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB) }, |
1783 | { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) }, | 1827 | { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) }, |
1784 | { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) }, | 1828 | { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) }, |
@@ -2430,6 +2474,14 @@ int hid_add_device(struct hid_device *hdev) | |||
2430 | return -ENODEV; | 2474 | return -ENODEV; |
2431 | 2475 | ||
2432 | /* | 2476 | /* |
2477 | * Check for the mandatory transport channel. | ||
2478 | */ | ||
2479 | if (!hdev->ll_driver->raw_request) { | ||
2480 | hid_err(hdev, "transport driver missing .raw_request()\n"); | ||
2481 | return -EINVAL; | ||
2482 | } | ||
2483 | |||
2484 | /* | ||
2433 | * Read the device report descriptor once and use as template | 2485 | * Read the device report descriptor once and use as template |
2434 | * for the driver-specific modifications. | 2486 | * for the driver-specific modifications. |
2435 | */ | 2487 | */ |
diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c new file mode 100644 index 000000000000..56be85a9a77c --- /dev/null +++ b/drivers/hid/hid-cp2112.c | |||
@@ -0,0 +1,1073 @@ | |||
1 | /* | ||
2 | * hid-cp2112.c - Silicon Labs HID USB to SMBus master bridge | ||
3 | * Copyright (c) 2013,2014 Uplogix, Inc. | ||
4 | * David Barksdale <dbarksdale@uplogix.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | */ | ||
15 | |||
16 | /* | ||
17 | * The Silicon Labs CP2112 chip is a USB HID device which provides an | ||
18 | * SMBus controller for talking to slave devices and 8 GPIO pins. The | ||
19 | * host communicates with the CP2112 via raw HID reports. | ||
20 | * | ||
21 | * Data Sheet: | ||
22 | * http://www.silabs.com/Support%20Documents/TechnicalDocs/CP2112.pdf | ||
23 | * Programming Interface Specification: | ||
24 | * http://www.silabs.com/Support%20Documents/TechnicalDocs/AN495.pdf | ||
25 | */ | ||
26 | |||
27 | #include <linux/gpio.h> | ||
28 | #include <linux/hid.h> | ||
29 | #include <linux/i2c.h> | ||
30 | #include <linux/module.h> | ||
31 | #include <linux/nls.h> | ||
32 | #include <linux/usb/ch9.h> | ||
33 | #include "hid-ids.h" | ||
34 | |||
35 | enum { | ||
36 | CP2112_GPIO_CONFIG = 0x02, | ||
37 | CP2112_GPIO_GET = 0x03, | ||
38 | CP2112_GPIO_SET = 0x04, | ||
39 | CP2112_GET_VERSION_INFO = 0x05, | ||
40 | CP2112_SMBUS_CONFIG = 0x06, | ||
41 | CP2112_DATA_READ_REQUEST = 0x10, | ||
42 | CP2112_DATA_WRITE_READ_REQUEST = 0x11, | ||
43 | CP2112_DATA_READ_FORCE_SEND = 0x12, | ||
44 | CP2112_DATA_READ_RESPONSE = 0x13, | ||
45 | CP2112_DATA_WRITE_REQUEST = 0x14, | ||
46 | CP2112_TRANSFER_STATUS_REQUEST = 0x15, | ||
47 | CP2112_TRANSFER_STATUS_RESPONSE = 0x16, | ||
48 | CP2112_CANCEL_TRANSFER = 0x17, | ||
49 | CP2112_LOCK_BYTE = 0x20, | ||
50 | CP2112_USB_CONFIG = 0x21, | ||
51 | CP2112_MANUFACTURER_STRING = 0x22, | ||
52 | CP2112_PRODUCT_STRING = 0x23, | ||
53 | CP2112_SERIAL_STRING = 0x24, | ||
54 | }; | ||
55 | |||
56 | enum { | ||
57 | STATUS0_IDLE = 0x00, | ||
58 | STATUS0_BUSY = 0x01, | ||
59 | STATUS0_COMPLETE = 0x02, | ||
60 | STATUS0_ERROR = 0x03, | ||
61 | }; | ||
62 | |||
63 | enum { | ||
64 | STATUS1_TIMEOUT_NACK = 0x00, | ||
65 | STATUS1_TIMEOUT_BUS = 0x01, | ||
66 | STATUS1_ARBITRATION_LOST = 0x02, | ||
67 | STATUS1_READ_INCOMPLETE = 0x03, | ||
68 | STATUS1_WRITE_INCOMPLETE = 0x04, | ||
69 | STATUS1_SUCCESS = 0x05, | ||
70 | }; | ||
71 | |||
72 | struct cp2112_smbus_config_report { | ||
73 | u8 report; /* CP2112_SMBUS_CONFIG */ | ||
74 | __be32 clock_speed; /* Hz */ | ||
75 | u8 device_address; /* Stored in the upper 7 bits */ | ||
76 | u8 auto_send_read; /* 1 = enabled, 0 = disabled */ | ||
77 | __be16 write_timeout; /* ms, 0 = no timeout */ | ||
78 | __be16 read_timeout; /* ms, 0 = no timeout */ | ||
79 | u8 scl_low_timeout; /* 1 = enabled, 0 = disabled */ | ||
80 | __be16 retry_time; /* # of retries, 0 = no limit */ | ||
81 | } __packed; | ||
82 | |||
83 | struct cp2112_usb_config_report { | ||
84 | u8 report; /* CP2112_USB_CONFIG */ | ||
85 | __le16 vid; /* Vendor ID */ | ||
86 | __le16 pid; /* Product ID */ | ||
87 | u8 max_power; /* Power requested in 2mA units */ | ||
88 | u8 power_mode; /* 0x00 = bus powered | ||
89 | 0x01 = self powered & regulator off | ||
90 | 0x02 = self powered & regulator on */ | ||
91 | u8 release_major; | ||
92 | u8 release_minor; | ||
93 | u8 mask; /* What fields to program */ | ||
94 | } __packed; | ||
95 | |||
96 | struct cp2112_read_req_report { | ||
97 | u8 report; /* CP2112_DATA_READ_REQUEST */ | ||
98 | u8 slave_address; | ||
99 | __be16 length; | ||
100 | } __packed; | ||
101 | |||
102 | struct cp2112_write_read_req_report { | ||
103 | u8 report; /* CP2112_DATA_WRITE_READ_REQUEST */ | ||
104 | u8 slave_address; | ||
105 | __be16 length; | ||
106 | u8 target_address_length; | ||
107 | u8 target_address[16]; | ||
108 | } __packed; | ||
109 | |||
110 | struct cp2112_write_req_report { | ||
111 | u8 report; /* CP2112_DATA_WRITE_REQUEST */ | ||
112 | u8 slave_address; | ||
113 | u8 length; | ||
114 | u8 data[61]; | ||
115 | } __packed; | ||
116 | |||
117 | struct cp2112_force_read_report { | ||
118 | u8 report; /* CP2112_DATA_READ_FORCE_SEND */ | ||
119 | __be16 length; | ||
120 | } __packed; | ||
121 | |||
122 | struct cp2112_xfer_status_report { | ||
123 | u8 report; /* CP2112_TRANSFER_STATUS_RESPONSE */ | ||
124 | u8 status0; /* STATUS0_* */ | ||
125 | u8 status1; /* STATUS1_* */ | ||
126 | __be16 retries; | ||
127 | __be16 length; | ||
128 | } __packed; | ||
129 | |||
130 | struct cp2112_string_report { | ||
131 | u8 dummy; /* force .string to be aligned */ | ||
132 | u8 report; /* CP2112_*_STRING */ | ||
133 | u8 length; /* length in bytes of everyting after .report */ | ||
134 | u8 type; /* USB_DT_STRING */ | ||
135 | wchar_t string[30]; /* UTF16_LITTLE_ENDIAN string */ | ||
136 | } __packed; | ||
137 | |||
138 | /* Number of times to request transfer status before giving up waiting for a | ||
139 | transfer to complete. This may need to be changed if SMBUS clock, retries, | ||
140 | or read/write/scl_low timeout settings are changed. */ | ||
141 | static const int XFER_STATUS_RETRIES = 10; | ||
142 | |||
143 | /* Time in ms to wait for a CP2112_DATA_READ_RESPONSE or | ||
144 | CP2112_TRANSFER_STATUS_RESPONSE. */ | ||
145 | static const int RESPONSE_TIMEOUT = 50; | ||
146 | |||
147 | static const struct hid_device_id cp2112_devices[] = { | ||
148 | { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_CP2112) }, | ||
149 | { } | ||
150 | }; | ||
151 | MODULE_DEVICE_TABLE(hid, cp2112_devices); | ||
152 | |||
153 | struct cp2112_device { | ||
154 | struct i2c_adapter adap; | ||
155 | struct hid_device *hdev; | ||
156 | wait_queue_head_t wait; | ||
157 | u8 read_data[61]; | ||
158 | u8 read_length; | ||
159 | int xfer_status; | ||
160 | atomic_t read_avail; | ||
161 | atomic_t xfer_avail; | ||
162 | struct gpio_chip gc; | ||
163 | }; | ||
164 | |||
165 | static int gpio_push_pull = 0xFF; | ||
166 | module_param(gpio_push_pull, int, S_IRUGO | S_IWUSR); | ||
167 | MODULE_PARM_DESC(gpio_push_pull, "GPIO push-pull configuration bitmask"); | ||
168 | |||
169 | static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset) | ||
170 | { | ||
171 | struct cp2112_device *dev = container_of(chip, struct cp2112_device, | ||
172 | gc); | ||
173 | struct hid_device *hdev = dev->hdev; | ||
174 | u8 buf[5]; | ||
175 | int ret; | ||
176 | |||
177 | ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, | ||
178 | sizeof(buf), HID_FEATURE_REPORT, | ||
179 | HID_REQ_GET_REPORT); | ||
180 | if (ret != sizeof(buf)) { | ||
181 | hid_err(hdev, "error requesting GPIO config: %d\n", ret); | ||
182 | return ret; | ||
183 | } | ||
184 | |||
185 | buf[1] &= ~(1 << offset); | ||
186 | buf[2] = gpio_push_pull; | ||
187 | |||
188 | ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, sizeof(buf), | ||
189 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | ||
190 | if (ret < 0) { | ||
191 | hid_err(hdev, "error setting GPIO config: %d\n", ret); | ||
192 | return ret; | ||
193 | } | ||
194 | |||
195 | return 0; | ||
196 | } | ||
197 | |||
198 | static void cp2112_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
199 | { | ||
200 | struct cp2112_device *dev = container_of(chip, struct cp2112_device, | ||
201 | gc); | ||
202 | struct hid_device *hdev = dev->hdev; | ||
203 | u8 buf[3]; | ||
204 | int ret; | ||
205 | |||
206 | buf[0] = CP2112_GPIO_SET; | ||
207 | buf[1] = value ? 0xff : 0; | ||
208 | buf[2] = 1 << offset; | ||
209 | |||
210 | ret = hid_hw_raw_request(hdev, CP2112_GPIO_SET, buf, sizeof(buf), | ||
211 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | ||
212 | if (ret < 0) | ||
213 | hid_err(hdev, "error setting GPIO values: %d\n", ret); | ||
214 | } | ||
215 | |||
216 | static int cp2112_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
217 | { | ||
218 | struct cp2112_device *dev = container_of(chip, struct cp2112_device, | ||
219 | gc); | ||
220 | struct hid_device *hdev = dev->hdev; | ||
221 | u8 buf[2]; | ||
222 | int ret; | ||
223 | |||
224 | ret = hid_hw_raw_request(hdev, CP2112_GPIO_GET, buf, sizeof(buf), | ||
225 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); | ||
226 | if (ret != sizeof(buf)) { | ||
227 | hid_err(hdev, "error requesting GPIO values: %d\n", ret); | ||
228 | return ret; | ||
229 | } | ||
230 | |||
231 | return (buf[1] >> offset) & 1; | ||
232 | } | ||
233 | |||
234 | static int cp2112_gpio_direction_output(struct gpio_chip *chip, | ||
235 | unsigned offset, int value) | ||
236 | { | ||
237 | struct cp2112_device *dev = container_of(chip, struct cp2112_device, | ||
238 | gc); | ||
239 | struct hid_device *hdev = dev->hdev; | ||
240 | u8 buf[5]; | ||
241 | int ret; | ||
242 | |||
243 | cp2112_gpio_set(chip, offset, value); | ||
244 | |||
245 | ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, | ||
246 | sizeof(buf), HID_FEATURE_REPORT, | ||
247 | HID_REQ_GET_REPORT); | ||
248 | if (ret != sizeof(buf)) { | ||
249 | hid_err(hdev, "error requesting GPIO config: %d\n", ret); | ||
250 | return ret; | ||
251 | } | ||
252 | |||
253 | buf[1] |= 1 << offset; | ||
254 | buf[2] = gpio_push_pull; | ||
255 | |||
256 | ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, sizeof(buf), | ||
257 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | ||
258 | if (ret < 0) { | ||
259 | hid_err(hdev, "error setting GPIO config: %d\n", ret); | ||
260 | return ret; | ||
261 | } | ||
262 | |||
263 | return 0; | ||
264 | } | ||
265 | |||
266 | static int cp2112_hid_get(struct hid_device *hdev, unsigned char report_number, | ||
267 | u8 *data, size_t count, unsigned char report_type) | ||
268 | { | ||
269 | u8 *buf; | ||
270 | int ret; | ||
271 | |||
272 | buf = kmalloc(count, GFP_KERNEL); | ||
273 | if (!buf) | ||
274 | return -ENOMEM; | ||
275 | |||
276 | ret = hid_hw_raw_request(hdev, report_number, buf, count, | ||
277 | report_type, HID_REQ_GET_REPORT); | ||
278 | memcpy(data, buf, count); | ||
279 | kfree(buf); | ||
280 | return ret; | ||
281 | } | ||
282 | |||
283 | static int cp2112_hid_output(struct hid_device *hdev, u8 *data, size_t count, | ||
284 | unsigned char report_type) | ||
285 | { | ||
286 | u8 *buf; | ||
287 | int ret; | ||
288 | |||
289 | buf = kmemdup(data, count, GFP_KERNEL); | ||
290 | if (!buf) | ||
291 | return -ENOMEM; | ||
292 | |||
293 | if (report_type == HID_OUTPUT_REPORT) | ||
294 | ret = hid_hw_output_report(hdev, buf, count); | ||
295 | else | ||
296 | ret = hid_hw_raw_request(hdev, buf[0], buf, count, report_type, | ||
297 | HID_REQ_SET_REPORT); | ||
298 | |||
299 | kfree(buf); | ||
300 | return ret; | ||
301 | } | ||
302 | |||
303 | static int cp2112_wait(struct cp2112_device *dev, atomic_t *avail) | ||
304 | { | ||
305 | int ret = 0; | ||
306 | |||
307 | /* We have sent either a CP2112_TRANSFER_STATUS_REQUEST or a | ||
308 | * CP2112_DATA_READ_FORCE_SEND and we are waiting for the response to | ||
309 | * come in cp2112_raw_event or timeout. There will only be one of these | ||
310 | * in flight at any one time. The timeout is extremely large and is a | ||
311 | * last resort if the CP2112 has died. If we do timeout we don't expect | ||
312 | * to receive the response which would cause data races, it's not like | ||
313 | * we can do anything about it anyway. | ||
314 | */ | ||
315 | ret = wait_event_interruptible_timeout(dev->wait, | ||
316 | atomic_read(avail), msecs_to_jiffies(RESPONSE_TIMEOUT)); | ||
317 | if (-ERESTARTSYS == ret) | ||
318 | return ret; | ||
319 | if (!ret) | ||
320 | return -ETIMEDOUT; | ||
321 | |||
322 | atomic_set(avail, 0); | ||
323 | return 0; | ||
324 | } | ||
325 | |||
326 | static int cp2112_xfer_status(struct cp2112_device *dev) | ||
327 | { | ||
328 | struct hid_device *hdev = dev->hdev; | ||
329 | u8 buf[2]; | ||
330 | int ret; | ||
331 | |||
332 | buf[0] = CP2112_TRANSFER_STATUS_REQUEST; | ||
333 | buf[1] = 0x01; | ||
334 | atomic_set(&dev->xfer_avail, 0); | ||
335 | |||
336 | ret = cp2112_hid_output(hdev, buf, 2, HID_OUTPUT_REPORT); | ||
337 | if (ret < 0) { | ||
338 | hid_warn(hdev, "Error requesting status: %d\n", ret); | ||
339 | return ret; | ||
340 | } | ||
341 | |||
342 | ret = cp2112_wait(dev, &dev->xfer_avail); | ||
343 | if (ret) | ||
344 | return ret; | ||
345 | |||
346 | return dev->xfer_status; | ||
347 | } | ||
348 | |||
349 | static int cp2112_read(struct cp2112_device *dev, u8 *data, size_t size) | ||
350 | { | ||
351 | struct hid_device *hdev = dev->hdev; | ||
352 | struct cp2112_force_read_report report; | ||
353 | int ret; | ||
354 | |||
355 | report.report = CP2112_DATA_READ_FORCE_SEND; | ||
356 | report.length = cpu_to_be16(size); | ||
357 | |||
358 | atomic_set(&dev->read_avail, 0); | ||
359 | |||
360 | ret = cp2112_hid_output(hdev, &report.report, sizeof(report), | ||
361 | HID_OUTPUT_REPORT); | ||
362 | if (ret < 0) { | ||
363 | hid_warn(hdev, "Error requesting data: %d\n", ret); | ||
364 | return ret; | ||
365 | } | ||
366 | |||
367 | ret = cp2112_wait(dev, &dev->read_avail); | ||
368 | if (ret) | ||
369 | return ret; | ||
370 | |||
371 | hid_dbg(hdev, "read %d of %zd bytes requested\n", | ||
372 | dev->read_length, size); | ||
373 | |||
374 | if (size > dev->read_length) | ||
375 | size = dev->read_length; | ||
376 | |||
377 | memcpy(data, dev->read_data, size); | ||
378 | return dev->read_length; | ||
379 | } | ||
380 | |||
381 | static int cp2112_read_req(void *buf, u8 slave_address, u16 length) | ||
382 | { | ||
383 | struct cp2112_read_req_report *report = buf; | ||
384 | |||
385 | if (length < 1 || length > 512) | ||
386 | return -EINVAL; | ||
387 | |||
388 | report->report = CP2112_DATA_READ_REQUEST; | ||
389 | report->slave_address = slave_address << 1; | ||
390 | report->length = cpu_to_be16(length); | ||
391 | return sizeof(*report); | ||
392 | } | ||
393 | |||
394 | static int cp2112_write_read_req(void *buf, u8 slave_address, u16 length, | ||
395 | u8 command, u8 *data, u8 data_length) | ||
396 | { | ||
397 | struct cp2112_write_read_req_report *report = buf; | ||
398 | |||
399 | if (length < 1 || length > 512 | ||
400 | || data_length > sizeof(report->target_address) - 1) | ||
401 | return -EINVAL; | ||
402 | |||
403 | report->report = CP2112_DATA_WRITE_READ_REQUEST; | ||
404 | report->slave_address = slave_address << 1; | ||
405 | report->length = cpu_to_be16(length); | ||
406 | report->target_address_length = data_length + 1; | ||
407 | report->target_address[0] = command; | ||
408 | memcpy(&report->target_address[1], data, data_length); | ||
409 | return data_length + 6; | ||
410 | } | ||
411 | |||
412 | static int cp2112_write_req(void *buf, u8 slave_address, u8 command, u8 *data, | ||
413 | u8 data_length) | ||
414 | { | ||
415 | struct cp2112_write_req_report *report = buf; | ||
416 | |||
417 | if (data_length > sizeof(report->data) - 1) | ||
418 | return -EINVAL; | ||
419 | |||
420 | report->report = CP2112_DATA_WRITE_REQUEST; | ||
421 | report->slave_address = slave_address << 1; | ||
422 | report->length = data_length + 1; | ||
423 | report->data[0] = command; | ||
424 | memcpy(&report->data[1], data, data_length); | ||
425 | return data_length + 4; | ||
426 | } | ||
427 | |||
428 | static int cp2112_xfer(struct i2c_adapter *adap, u16 addr, | ||
429 | unsigned short flags, char read_write, u8 command, | ||
430 | int size, union i2c_smbus_data *data) | ||
431 | { | ||
432 | struct cp2112_device *dev = (struct cp2112_device *)adap->algo_data; | ||
433 | struct hid_device *hdev = dev->hdev; | ||
434 | u8 buf[64]; | ||
435 | __be16 word; | ||
436 | ssize_t count; | ||
437 | size_t read_length = 0; | ||
438 | unsigned int retries; | ||
439 | int ret; | ||
440 | |||
441 | hid_dbg(hdev, "%s addr 0x%x flags 0x%x cmd 0x%x size %d\n", | ||
442 | read_write == I2C_SMBUS_WRITE ? "write" : "read", | ||
443 | addr, flags, command, size); | ||
444 | |||
445 | switch (size) { | ||
446 | case I2C_SMBUS_BYTE: | ||
447 | read_length = 1; | ||
448 | |||
449 | if (I2C_SMBUS_READ == read_write) | ||
450 | count = cp2112_read_req(buf, addr, read_length); | ||
451 | else | ||
452 | count = cp2112_write_req(buf, addr, data->byte, NULL, | ||
453 | 0); | ||
454 | break; | ||
455 | case I2C_SMBUS_BYTE_DATA: | ||
456 | read_length = 1; | ||
457 | |||
458 | if (I2C_SMBUS_READ == read_write) | ||
459 | count = cp2112_write_read_req(buf, addr, read_length, | ||
460 | command, NULL, 0); | ||
461 | else | ||
462 | count = cp2112_write_req(buf, addr, command, | ||
463 | &data->byte, 1); | ||
464 | break; | ||
465 | case I2C_SMBUS_WORD_DATA: | ||
466 | read_length = 2; | ||
467 | word = cpu_to_be16(data->word); | ||
468 | |||
469 | if (I2C_SMBUS_READ == read_write) | ||
470 | count = cp2112_write_read_req(buf, addr, read_length, | ||
471 | command, NULL, 0); | ||
472 | else | ||
473 | count = cp2112_write_req(buf, addr, command, | ||
474 | (u8 *)&word, 2); | ||
475 | break; | ||
476 | case I2C_SMBUS_PROC_CALL: | ||
477 | size = I2C_SMBUS_WORD_DATA; | ||
478 | read_write = I2C_SMBUS_READ; | ||
479 | read_length = 2; | ||
480 | word = cpu_to_be16(data->word); | ||
481 | |||
482 | count = cp2112_write_read_req(buf, addr, read_length, command, | ||
483 | (u8 *)&word, 2); | ||
484 | break; | ||
485 | case I2C_SMBUS_I2C_BLOCK_DATA: | ||
486 | size = I2C_SMBUS_BLOCK_DATA; | ||
487 | /* fallthrough */ | ||
488 | case I2C_SMBUS_BLOCK_DATA: | ||
489 | if (I2C_SMBUS_READ == read_write) { | ||
490 | count = cp2112_write_read_req(buf, addr, | ||
491 | I2C_SMBUS_BLOCK_MAX, | ||
492 | command, NULL, 0); | ||
493 | } else { | ||
494 | count = cp2112_write_req(buf, addr, command, | ||
495 | data->block, | ||
496 | data->block[0] + 1); | ||
497 | } | ||
498 | break; | ||
499 | case I2C_SMBUS_BLOCK_PROC_CALL: | ||
500 | size = I2C_SMBUS_BLOCK_DATA; | ||
501 | read_write = I2C_SMBUS_READ; | ||
502 | |||
503 | count = cp2112_write_read_req(buf, addr, I2C_SMBUS_BLOCK_MAX, | ||
504 | command, data->block, | ||
505 | data->block[0] + 1); | ||
506 | break; | ||
507 | default: | ||
508 | hid_warn(hdev, "Unsupported transaction %d\n", size); | ||
509 | return -EOPNOTSUPP; | ||
510 | } | ||
511 | |||
512 | if (count < 0) | ||
513 | return count; | ||
514 | |||
515 | ret = hid_hw_power(hdev, PM_HINT_FULLON); | ||
516 | if (ret < 0) { | ||
517 | hid_err(hdev, "power management error: %d\n", ret); | ||
518 | return ret; | ||
519 | } | ||
520 | |||
521 | ret = cp2112_hid_output(hdev, buf, count, HID_OUTPUT_REPORT); | ||
522 | if (ret < 0) { | ||
523 | hid_warn(hdev, "Error starting transaction: %d\n", ret); | ||
524 | goto power_normal; | ||
525 | } | ||
526 | |||
527 | for (retries = 0; retries < XFER_STATUS_RETRIES; ++retries) { | ||
528 | ret = cp2112_xfer_status(dev); | ||
529 | if (-EBUSY == ret) | ||
530 | continue; | ||
531 | if (ret < 0) | ||
532 | goto power_normal; | ||
533 | break; | ||
534 | } | ||
535 | |||
536 | if (XFER_STATUS_RETRIES <= retries) { | ||
537 | hid_warn(hdev, "Transfer timed out, cancelling.\n"); | ||
538 | buf[0] = CP2112_CANCEL_TRANSFER; | ||
539 | buf[1] = 0x01; | ||
540 | |||
541 | ret = cp2112_hid_output(hdev, buf, 2, HID_OUTPUT_REPORT); | ||
542 | if (ret < 0) | ||
543 | hid_warn(hdev, "Error cancelling transaction: %d\n", | ||
544 | ret); | ||
545 | |||
546 | ret = -ETIMEDOUT; | ||
547 | goto power_normal; | ||
548 | } | ||
549 | |||
550 | if (I2C_SMBUS_WRITE == read_write) { | ||
551 | ret = 0; | ||
552 | goto power_normal; | ||
553 | } | ||
554 | |||
555 | if (I2C_SMBUS_BLOCK_DATA == size) | ||
556 | read_length = ret; | ||
557 | |||
558 | ret = cp2112_read(dev, buf, read_length); | ||
559 | if (ret < 0) | ||
560 | goto power_normal; | ||
561 | if (ret != read_length) { | ||
562 | hid_warn(hdev, "short read: %d < %zd\n", ret, read_length); | ||
563 | ret = -EIO; | ||
564 | goto power_normal; | ||
565 | } | ||
566 | |||
567 | switch (size) { | ||
568 | case I2C_SMBUS_BYTE: | ||
569 | case I2C_SMBUS_BYTE_DATA: | ||
570 | data->byte = buf[0]; | ||
571 | break; | ||
572 | case I2C_SMBUS_WORD_DATA: | ||
573 | data->word = be16_to_cpup((__be16 *)buf); | ||
574 | break; | ||
575 | case I2C_SMBUS_BLOCK_DATA: | ||
576 | if (read_length > I2C_SMBUS_BLOCK_MAX) { | ||
577 | ret = -EPROTO; | ||
578 | goto power_normal; | ||
579 | } | ||
580 | |||
581 | memcpy(data->block, buf, read_length); | ||
582 | break; | ||
583 | } | ||
584 | |||
585 | ret = 0; | ||
586 | power_normal: | ||
587 | hid_hw_power(hdev, PM_HINT_NORMAL); | ||
588 | hid_dbg(hdev, "transfer finished: %d\n", ret); | ||
589 | return ret; | ||
590 | } | ||
591 | |||
592 | static u32 cp2112_functionality(struct i2c_adapter *adap) | ||
593 | { | ||
594 | return I2C_FUNC_SMBUS_BYTE | | ||
595 | I2C_FUNC_SMBUS_BYTE_DATA | | ||
596 | I2C_FUNC_SMBUS_WORD_DATA | | ||
597 | I2C_FUNC_SMBUS_BLOCK_DATA | | ||
598 | I2C_FUNC_SMBUS_I2C_BLOCK | | ||
599 | I2C_FUNC_SMBUS_PROC_CALL | | ||
600 | I2C_FUNC_SMBUS_BLOCK_PROC_CALL; | ||
601 | } | ||
602 | |||
603 | static const struct i2c_algorithm smbus_algorithm = { | ||
604 | .smbus_xfer = cp2112_xfer, | ||
605 | .functionality = cp2112_functionality, | ||
606 | }; | ||
607 | |||
608 | static int cp2112_get_usb_config(struct hid_device *hdev, | ||
609 | struct cp2112_usb_config_report *cfg) | ||
610 | { | ||
611 | int ret; | ||
612 | |||
613 | ret = cp2112_hid_get(hdev, CP2112_USB_CONFIG, (u8 *)cfg, sizeof(*cfg), | ||
614 | HID_FEATURE_REPORT); | ||
615 | if (ret != sizeof(*cfg)) { | ||
616 | hid_err(hdev, "error reading usb config: %d\n", ret); | ||
617 | if (ret < 0) | ||
618 | return ret; | ||
619 | return -EIO; | ||
620 | } | ||
621 | |||
622 | return 0; | ||
623 | } | ||
624 | |||
625 | static int cp2112_set_usb_config(struct hid_device *hdev, | ||
626 | struct cp2112_usb_config_report *cfg) | ||
627 | { | ||
628 | int ret; | ||
629 | |||
630 | BUG_ON(cfg->report != CP2112_USB_CONFIG); | ||
631 | |||
632 | ret = cp2112_hid_output(hdev, (u8 *)cfg, sizeof(*cfg), | ||
633 | HID_FEATURE_REPORT); | ||
634 | if (ret != sizeof(*cfg)) { | ||
635 | hid_err(hdev, "error writing usb config: %d\n", ret); | ||
636 | if (ret < 0) | ||
637 | return ret; | ||
638 | return -EIO; | ||
639 | } | ||
640 | |||
641 | return 0; | ||
642 | } | ||
643 | |||
644 | static void chmod_sysfs_attrs(struct hid_device *hdev); | ||
645 | |||
646 | #define CP2112_CONFIG_ATTR(name, store, format, ...) \ | ||
647 | static ssize_t name##_store(struct device *kdev, \ | ||
648 | struct device_attribute *attr, const char *buf, \ | ||
649 | size_t count) \ | ||
650 | { \ | ||
651 | struct hid_device *hdev = container_of(kdev, struct hid_device, dev); \ | ||
652 | struct cp2112_usb_config_report cfg; \ | ||
653 | int ret = cp2112_get_usb_config(hdev, &cfg); \ | ||
654 | if (ret) \ | ||
655 | return ret; \ | ||
656 | store; \ | ||
657 | ret = cp2112_set_usb_config(hdev, &cfg); \ | ||
658 | if (ret) \ | ||
659 | return ret; \ | ||
660 | chmod_sysfs_attrs(hdev); \ | ||
661 | return count; \ | ||
662 | } \ | ||
663 | static ssize_t name##_show(struct device *kdev, \ | ||
664 | struct device_attribute *attr, char *buf) \ | ||
665 | { \ | ||
666 | struct hid_device *hdev = container_of(kdev, struct hid_device, dev); \ | ||
667 | struct cp2112_usb_config_report cfg; \ | ||
668 | int ret = cp2112_get_usb_config(hdev, &cfg); \ | ||
669 | if (ret) \ | ||
670 | return ret; \ | ||
671 | return scnprintf(buf, PAGE_SIZE, format, ##__VA_ARGS__); \ | ||
672 | } \ | ||
673 | static DEVICE_ATTR_RW(name); | ||
674 | |||
675 | CP2112_CONFIG_ATTR(vendor_id, ({ | ||
676 | u16 vid; | ||
677 | |||
678 | if (sscanf(buf, "%hi", &vid) != 1) | ||
679 | return -EINVAL; | ||
680 | |||
681 | cfg.vid = cpu_to_le16(vid); | ||
682 | cfg.mask = 0x01; | ||
683 | }), "0x%04x\n", le16_to_cpu(cfg.vid)); | ||
684 | |||
685 | CP2112_CONFIG_ATTR(product_id, ({ | ||
686 | u16 pid; | ||
687 | |||
688 | if (sscanf(buf, "%hi", &pid) != 1) | ||
689 | return -EINVAL; | ||
690 | |||
691 | cfg.pid = cpu_to_le16(pid); | ||
692 | cfg.mask = 0x02; | ||
693 | }), "0x%04x\n", le16_to_cpu(cfg.pid)); | ||
694 | |||
695 | CP2112_CONFIG_ATTR(max_power, ({ | ||
696 | int mA; | ||
697 | |||
698 | if (sscanf(buf, "%i", &mA) != 1) | ||
699 | return -EINVAL; | ||
700 | |||
701 | cfg.max_power = (mA + 1) / 2; | ||
702 | cfg.mask = 0x04; | ||
703 | }), "%u mA\n", cfg.max_power * 2); | ||
704 | |||
705 | CP2112_CONFIG_ATTR(power_mode, ({ | ||
706 | if (sscanf(buf, "%hhi", &cfg.power_mode) != 1) | ||
707 | return -EINVAL; | ||
708 | |||
709 | cfg.mask = 0x08; | ||
710 | }), "%u\n", cfg.power_mode); | ||
711 | |||
712 | CP2112_CONFIG_ATTR(release_version, ({ | ||
713 | if (sscanf(buf, "%hhi.%hhi", &cfg.release_major, &cfg.release_minor) | ||
714 | != 2) | ||
715 | return -EINVAL; | ||
716 | |||
717 | cfg.mask = 0x10; | ||
718 | }), "%u.%u\n", cfg.release_major, cfg.release_minor); | ||
719 | |||
720 | #undef CP2112_CONFIG_ATTR | ||
721 | |||
722 | struct cp2112_pstring_attribute { | ||
723 | struct device_attribute attr; | ||
724 | unsigned char report; | ||
725 | }; | ||
726 | |||
727 | static ssize_t pstr_store(struct device *kdev, | ||
728 | struct device_attribute *kattr, const char *buf, | ||
729 | size_t count) | ||
730 | { | ||
731 | struct hid_device *hdev = container_of(kdev, struct hid_device, dev); | ||
732 | struct cp2112_pstring_attribute *attr = | ||
733 | container_of(kattr, struct cp2112_pstring_attribute, attr); | ||
734 | struct cp2112_string_report report; | ||
735 | int ret; | ||
736 | |||
737 | memset(&report, 0, sizeof(report)); | ||
738 | |||
739 | ret = utf8s_to_utf16s(buf, count, UTF16_LITTLE_ENDIAN, | ||
740 | report.string, ARRAY_SIZE(report.string)); | ||
741 | report.report = attr->report; | ||
742 | report.length = ret * sizeof(report.string[0]) + 2; | ||
743 | report.type = USB_DT_STRING; | ||
744 | |||
745 | ret = cp2112_hid_output(hdev, &report.report, report.length + 1, | ||
746 | HID_FEATURE_REPORT); | ||
747 | if (ret != report.length + 1) { | ||
748 | hid_err(hdev, "error writing %s string: %d\n", kattr->attr.name, | ||
749 | ret); | ||
750 | if (ret < 0) | ||
751 | return ret; | ||
752 | return -EIO; | ||
753 | } | ||
754 | |||
755 | chmod_sysfs_attrs(hdev); | ||
756 | return count; | ||
757 | } | ||
758 | |||
759 | static ssize_t pstr_show(struct device *kdev, | ||
760 | struct device_attribute *kattr, char *buf) | ||
761 | { | ||
762 | struct hid_device *hdev = container_of(kdev, struct hid_device, dev); | ||
763 | struct cp2112_pstring_attribute *attr = | ||
764 | container_of(kattr, struct cp2112_pstring_attribute, attr); | ||
765 | struct cp2112_string_report report; | ||
766 | u8 length; | ||
767 | int ret; | ||
768 | |||
769 | ret = cp2112_hid_get(hdev, attr->report, &report.report, | ||
770 | sizeof(report) - 1, HID_FEATURE_REPORT); | ||
771 | if (ret < 3) { | ||
772 | hid_err(hdev, "error reading %s string: %d\n", kattr->attr.name, | ||
773 | ret); | ||
774 | if (ret < 0) | ||
775 | return ret; | ||
776 | return -EIO; | ||
777 | } | ||
778 | |||
779 | if (report.length < 2) { | ||
780 | hid_err(hdev, "invalid %s string length: %d\n", | ||
781 | kattr->attr.name, report.length); | ||
782 | return -EIO; | ||
783 | } | ||
784 | |||
785 | length = report.length > ret - 1 ? ret - 1 : report.length; | ||
786 | length = (length - 2) / sizeof(report.string[0]); | ||
787 | ret = utf16s_to_utf8s(report.string, length, UTF16_LITTLE_ENDIAN, buf, | ||
788 | PAGE_SIZE - 1); | ||
789 | buf[ret++] = '\n'; | ||
790 | return ret; | ||
791 | } | ||
792 | |||
793 | #define CP2112_PSTR_ATTR(name, _report) \ | ||
794 | static struct cp2112_pstring_attribute dev_attr_##name = { \ | ||
795 | .attr = __ATTR(name, (S_IWUSR | S_IRUGO), pstr_show, pstr_store), \ | ||
796 | .report = _report, \ | ||
797 | }; | ||
798 | |||
799 | CP2112_PSTR_ATTR(manufacturer, CP2112_MANUFACTURER_STRING); | ||
800 | CP2112_PSTR_ATTR(product, CP2112_PRODUCT_STRING); | ||
801 | CP2112_PSTR_ATTR(serial, CP2112_SERIAL_STRING); | ||
802 | |||
803 | #undef CP2112_PSTR_ATTR | ||
804 | |||
805 | static const struct attribute_group cp2112_attr_group = { | ||
806 | .attrs = (struct attribute *[]){ | ||
807 | &dev_attr_vendor_id.attr, | ||
808 | &dev_attr_product_id.attr, | ||
809 | &dev_attr_max_power.attr, | ||
810 | &dev_attr_power_mode.attr, | ||
811 | &dev_attr_release_version.attr, | ||
812 | &dev_attr_manufacturer.attr.attr, | ||
813 | &dev_attr_product.attr.attr, | ||
814 | &dev_attr_serial.attr.attr, | ||
815 | NULL | ||
816 | } | ||
817 | }; | ||
818 | |||
819 | /* Chmoding our sysfs attributes is simply a way to expose which fields in the | ||
820 | * PROM have already been programmed. We do not depend on this preventing | ||
821 | * writing to these attributes since the CP2112 will simply ignore writes to | ||
822 | * already-programmed fields. This is why there is no sense in fixing this | ||
823 | * racy behaviour. | ||
824 | */ | ||
825 | static void chmod_sysfs_attrs(struct hid_device *hdev) | ||
826 | { | ||
827 | struct attribute **attr; | ||
828 | u8 buf[2]; | ||
829 | int ret; | ||
830 | |||
831 | ret = cp2112_hid_get(hdev, CP2112_LOCK_BYTE, buf, sizeof(buf), | ||
832 | HID_FEATURE_REPORT); | ||
833 | if (ret != sizeof(buf)) { | ||
834 | hid_err(hdev, "error reading lock byte: %d\n", ret); | ||
835 | return; | ||
836 | } | ||
837 | |||
838 | for (attr = cp2112_attr_group.attrs; *attr; ++attr) { | ||
839 | umode_t mode = (buf[1] & 1) ? S_IWUSR | S_IRUGO : S_IRUGO; | ||
840 | ret = sysfs_chmod_file(&hdev->dev.kobj, *attr, mode); | ||
841 | if (ret < 0) | ||
842 | hid_err(hdev, "error chmoding sysfs file %s\n", | ||
843 | (*attr)->name); | ||
844 | buf[1] >>= 1; | ||
845 | } | ||
846 | } | ||
847 | |||
848 | static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
849 | { | ||
850 | struct cp2112_device *dev; | ||
851 | u8 buf[3]; | ||
852 | struct cp2112_smbus_config_report config; | ||
853 | int ret; | ||
854 | |||
855 | ret = hid_parse(hdev); | ||
856 | if (ret) { | ||
857 | hid_err(hdev, "parse failed\n"); | ||
858 | return ret; | ||
859 | } | ||
860 | |||
861 | ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); | ||
862 | if (ret) { | ||
863 | hid_err(hdev, "hw start failed\n"); | ||
864 | return ret; | ||
865 | } | ||
866 | |||
867 | ret = hid_hw_open(hdev); | ||
868 | if (ret) { | ||
869 | hid_err(hdev, "hw open failed\n"); | ||
870 | goto err_hid_stop; | ||
871 | } | ||
872 | |||
873 | ret = hid_hw_power(hdev, PM_HINT_FULLON); | ||
874 | if (ret < 0) { | ||
875 | hid_err(hdev, "power management error: %d\n", ret); | ||
876 | goto err_hid_close; | ||
877 | } | ||
878 | |||
879 | ret = cp2112_hid_get(hdev, CP2112_GET_VERSION_INFO, buf, sizeof(buf), | ||
880 | HID_FEATURE_REPORT); | ||
881 | if (ret != sizeof(buf)) { | ||
882 | hid_err(hdev, "error requesting version\n"); | ||
883 | if (ret >= 0) | ||
884 | ret = -EIO; | ||
885 | goto err_power_normal; | ||
886 | } | ||
887 | |||
888 | hid_info(hdev, "Part Number: 0x%02X Device Version: 0x%02X\n", | ||
889 | buf[1], buf[2]); | ||
890 | |||
891 | ret = cp2112_hid_get(hdev, CP2112_SMBUS_CONFIG, (u8 *)&config, | ||
892 | sizeof(config), HID_FEATURE_REPORT); | ||
893 | if (ret != sizeof(config)) { | ||
894 | hid_err(hdev, "error requesting SMBus config\n"); | ||
895 | if (ret >= 0) | ||
896 | ret = -EIO; | ||
897 | goto err_power_normal; | ||
898 | } | ||
899 | |||
900 | config.retry_time = cpu_to_be16(1); | ||
901 | |||
902 | ret = cp2112_hid_output(hdev, (u8 *)&config, sizeof(config), | ||
903 | HID_FEATURE_REPORT); | ||
904 | if (ret != sizeof(config)) { | ||
905 | hid_err(hdev, "error setting SMBus config\n"); | ||
906 | if (ret >= 0) | ||
907 | ret = -EIO; | ||
908 | goto err_power_normal; | ||
909 | } | ||
910 | |||
911 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
912 | if (!dev) { | ||
913 | ret = -ENOMEM; | ||
914 | goto err_power_normal; | ||
915 | } | ||
916 | |||
917 | hid_set_drvdata(hdev, (void *)dev); | ||
918 | dev->hdev = hdev; | ||
919 | dev->adap.owner = THIS_MODULE; | ||
920 | dev->adap.class = I2C_CLASS_HWMON; | ||
921 | dev->adap.algo = &smbus_algorithm; | ||
922 | dev->adap.algo_data = dev; | ||
923 | dev->adap.dev.parent = &hdev->dev; | ||
924 | snprintf(dev->adap.name, sizeof(dev->adap.name), | ||
925 | "CP2112 SMBus Bridge on hiddev%d", hdev->minor); | ||
926 | init_waitqueue_head(&dev->wait); | ||
927 | |||
928 | hid_device_io_start(hdev); | ||
929 | ret = i2c_add_adapter(&dev->adap); | ||
930 | hid_device_io_stop(hdev); | ||
931 | |||
932 | if (ret) { | ||
933 | hid_err(hdev, "error registering i2c adapter\n"); | ||
934 | goto err_free_dev; | ||
935 | } | ||
936 | |||
937 | hid_dbg(hdev, "adapter registered\n"); | ||
938 | |||
939 | dev->gc.label = "cp2112_gpio"; | ||
940 | dev->gc.direction_input = cp2112_gpio_direction_input; | ||
941 | dev->gc.direction_output = cp2112_gpio_direction_output; | ||
942 | dev->gc.set = cp2112_gpio_set; | ||
943 | dev->gc.get = cp2112_gpio_get; | ||
944 | dev->gc.base = -1; | ||
945 | dev->gc.ngpio = 8; | ||
946 | dev->gc.can_sleep = 1; | ||
947 | dev->gc.dev = &hdev->dev; | ||
948 | |||
949 | ret = gpiochip_add(&dev->gc); | ||
950 | if (ret < 0) { | ||
951 | hid_err(hdev, "error registering gpio chip\n"); | ||
952 | goto err_free_i2c; | ||
953 | } | ||
954 | |||
955 | ret = sysfs_create_group(&hdev->dev.kobj, &cp2112_attr_group); | ||
956 | if (ret < 0) { | ||
957 | hid_err(hdev, "error creating sysfs attrs\n"); | ||
958 | goto err_gpiochip_remove; | ||
959 | } | ||
960 | |||
961 | chmod_sysfs_attrs(hdev); | ||
962 | hid_hw_power(hdev, PM_HINT_NORMAL); | ||
963 | |||
964 | return ret; | ||
965 | |||
966 | err_gpiochip_remove: | ||
967 | if (gpiochip_remove(&dev->gc) < 0) | ||
968 | hid_err(hdev, "error removing gpio chip\n"); | ||
969 | err_free_i2c: | ||
970 | i2c_del_adapter(&dev->adap); | ||
971 | err_free_dev: | ||
972 | kfree(dev); | ||
973 | err_power_normal: | ||
974 | hid_hw_power(hdev, PM_HINT_NORMAL); | ||
975 | err_hid_close: | ||
976 | hid_hw_close(hdev); | ||
977 | err_hid_stop: | ||
978 | hid_hw_stop(hdev); | ||
979 | return ret; | ||
980 | } | ||
981 | |||
982 | static void cp2112_remove(struct hid_device *hdev) | ||
983 | { | ||
984 | struct cp2112_device *dev = hid_get_drvdata(hdev); | ||
985 | |||
986 | sysfs_remove_group(&hdev->dev.kobj, &cp2112_attr_group); | ||
987 | if (gpiochip_remove(&dev->gc)) | ||
988 | hid_err(hdev, "unable to remove gpio chip\n"); | ||
989 | i2c_del_adapter(&dev->adap); | ||
990 | /* i2c_del_adapter has finished removing all i2c devices from our | ||
991 | * adapter. Well behaved devices should no longer call our cp2112_xfer | ||
992 | * and should have waited for any pending calls to finish. It has also | ||
993 | * waited for device_unregister(&adap->dev) to complete. Therefore we | ||
994 | * can safely free our struct cp2112_device. | ||
995 | */ | ||
996 | hid_hw_close(hdev); | ||
997 | hid_hw_stop(hdev); | ||
998 | kfree(dev); | ||
999 | } | ||
1000 | |||
1001 | static int cp2112_raw_event(struct hid_device *hdev, struct hid_report *report, | ||
1002 | u8 *data, int size) | ||
1003 | { | ||
1004 | struct cp2112_device *dev = hid_get_drvdata(hdev); | ||
1005 | struct cp2112_xfer_status_report *xfer = (void *)data; | ||
1006 | |||
1007 | switch (data[0]) { | ||
1008 | case CP2112_TRANSFER_STATUS_RESPONSE: | ||
1009 | hid_dbg(hdev, "xfer status: %02x %02x %04x %04x\n", | ||
1010 | xfer->status0, xfer->status1, | ||
1011 | be16_to_cpu(xfer->retries), be16_to_cpu(xfer->length)); | ||
1012 | |||
1013 | switch (xfer->status0) { | ||
1014 | case STATUS0_IDLE: | ||
1015 | dev->xfer_status = -EAGAIN; | ||
1016 | break; | ||
1017 | case STATUS0_BUSY: | ||
1018 | dev->xfer_status = -EBUSY; | ||
1019 | break; | ||
1020 | case STATUS0_COMPLETE: | ||
1021 | dev->xfer_status = be16_to_cpu(xfer->length); | ||
1022 | break; | ||
1023 | case STATUS0_ERROR: | ||
1024 | switch (xfer->status1) { | ||
1025 | case STATUS1_TIMEOUT_NACK: | ||
1026 | case STATUS1_TIMEOUT_BUS: | ||
1027 | dev->xfer_status = -ETIMEDOUT; | ||
1028 | break; | ||
1029 | default: | ||
1030 | dev->xfer_status = -EIO; | ||
1031 | break; | ||
1032 | } | ||
1033 | break; | ||
1034 | default: | ||
1035 | dev->xfer_status = -EINVAL; | ||
1036 | break; | ||
1037 | } | ||
1038 | |||
1039 | atomic_set(&dev->xfer_avail, 1); | ||
1040 | break; | ||
1041 | case CP2112_DATA_READ_RESPONSE: | ||
1042 | hid_dbg(hdev, "read response: %02x %02x\n", data[1], data[2]); | ||
1043 | |||
1044 | dev->read_length = data[2]; | ||
1045 | if (dev->read_length > sizeof(dev->read_data)) | ||
1046 | dev->read_length = sizeof(dev->read_data); | ||
1047 | |||
1048 | memcpy(dev->read_data, &data[3], dev->read_length); | ||
1049 | atomic_set(&dev->read_avail, 1); | ||
1050 | break; | ||
1051 | default: | ||
1052 | hid_err(hdev, "unknown report\n"); | ||
1053 | |||
1054 | return 0; | ||
1055 | } | ||
1056 | |||
1057 | wake_up_interruptible(&dev->wait); | ||
1058 | return 1; | ||
1059 | } | ||
1060 | |||
1061 | static struct hid_driver cp2112_driver = { | ||
1062 | .name = "cp2112", | ||
1063 | .id_table = cp2112_devices, | ||
1064 | .probe = cp2112_probe, | ||
1065 | .remove = cp2112_remove, | ||
1066 | .raw_event = cp2112_raw_event, | ||
1067 | }; | ||
1068 | |||
1069 | module_hid_driver(cp2112_driver); | ||
1070 | MODULE_DESCRIPTION("Silicon Labs HID USB to SMBus master bridge"); | ||
1071 | MODULE_AUTHOR("David Barksdale <dbarksdale@uplogix.com>"); | ||
1072 | MODULE_LICENSE("GPL"); | ||
1073 | |||
diff --git a/drivers/hid/hid-hyperv.c b/drivers/hid/hid-hyperv.c index 8fae6d1414cc..f52dbcb7133b 100644 --- a/drivers/hid/hid-hyperv.c +++ b/drivers/hid/hid-hyperv.c | |||
@@ -157,6 +157,7 @@ struct mousevsc_dev { | |||
157 | u32 report_desc_size; | 157 | u32 report_desc_size; |
158 | struct hv_input_dev_info hid_dev_info; | 158 | struct hv_input_dev_info hid_dev_info; |
159 | struct hid_device *hid_device; | 159 | struct hid_device *hid_device; |
160 | u8 input_buf[HID_MAX_BUFFER_SIZE]; | ||
160 | }; | 161 | }; |
161 | 162 | ||
162 | 163 | ||
@@ -256,6 +257,7 @@ static void mousevsc_on_receive(struct hv_device *device, | |||
256 | struct synthhid_msg *hid_msg; | 257 | struct synthhid_msg *hid_msg; |
257 | struct mousevsc_dev *input_dev = hv_get_drvdata(device); | 258 | struct mousevsc_dev *input_dev = hv_get_drvdata(device); |
258 | struct synthhid_input_report *input_report; | 259 | struct synthhid_input_report *input_report; |
260 | size_t len; | ||
259 | 261 | ||
260 | pipe_msg = (struct pipe_prt_msg *)((unsigned long)packet + | 262 | pipe_msg = (struct pipe_prt_msg *)((unsigned long)packet + |
261 | (packet->offset8 << 3)); | 263 | (packet->offset8 << 3)); |
@@ -300,9 +302,12 @@ static void mousevsc_on_receive(struct hv_device *device, | |||
300 | (struct synthhid_input_report *)pipe_msg->data; | 302 | (struct synthhid_input_report *)pipe_msg->data; |
301 | if (!input_dev->init_complete) | 303 | if (!input_dev->init_complete) |
302 | break; | 304 | break; |
303 | hid_input_report(input_dev->hid_device, | 305 | |
304 | HID_INPUT_REPORT, input_report->buffer, | 306 | len = min(input_report->header.size, |
305 | input_report->header.size, 1); | 307 | (u32)sizeof(input_dev->input_buf)); |
308 | memcpy(input_dev->input_buf, input_report->buffer, len); | ||
309 | hid_input_report(input_dev->hid_device, HID_INPUT_REPORT, | ||
310 | input_dev->input_buf, len, 1); | ||
306 | break; | 311 | break; |
307 | default: | 312 | default: |
308 | pr_err("unsupported hid msg type - type %d len %d", | 313 | pr_err("unsupported hid msg type - type %d len %d", |
@@ -455,12 +460,22 @@ static void mousevsc_hid_stop(struct hid_device *hid) | |||
455 | { | 460 | { |
456 | } | 461 | } |
457 | 462 | ||
463 | static int mousevsc_hid_raw_request(struct hid_device *hid, | ||
464 | unsigned char report_num, | ||
465 | __u8 *buf, size_t len, | ||
466 | unsigned char rtype, | ||
467 | int reqtype) | ||
468 | { | ||
469 | return 0; | ||
470 | } | ||
471 | |||
458 | static struct hid_ll_driver mousevsc_ll_driver = { | 472 | static struct hid_ll_driver mousevsc_ll_driver = { |
459 | .parse = mousevsc_hid_parse, | 473 | .parse = mousevsc_hid_parse, |
460 | .open = mousevsc_hid_open, | 474 | .open = mousevsc_hid_open, |
461 | .close = mousevsc_hid_close, | 475 | .close = mousevsc_hid_close, |
462 | .start = mousevsc_hid_start, | 476 | .start = mousevsc_hid_start, |
463 | .stop = mousevsc_hid_stop, | 477 | .stop = mousevsc_hid_stop, |
478 | .raw_request = mousevsc_hid_raw_request, | ||
464 | }; | 479 | }; |
465 | 480 | ||
466 | static struct hid_driver mousevsc_hid_driver; | 481 | static struct hid_driver mousevsc_hid_driver; |
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index 6f1c97bfbd26..af15a631bb24 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h | |||
@@ -135,6 +135,7 @@ | |||
135 | #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b | 135 | #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b |
136 | #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI 0x0255 | 136 | #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI 0x0255 |
137 | #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO 0x0256 | 137 | #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO 0x0256 |
138 | #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS 0x0257 | ||
138 | #define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0290 | 139 | #define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI 0x0290 |
139 | #define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0291 | 140 | #define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO 0x0291 |
140 | #define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0292 | 141 | #define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS 0x0292 |
@@ -240,6 +241,8 @@ | |||
240 | 241 | ||
241 | #define USB_VENDOR_ID_CYGNAL 0x10c4 | 242 | #define USB_VENDOR_ID_CYGNAL 0x10c4 |
242 | #define USB_DEVICE_ID_CYGNAL_RADIO_SI470X 0x818a | 243 | #define USB_DEVICE_ID_CYGNAL_RADIO_SI470X 0x818a |
244 | #define USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH 0x81b9 | ||
245 | #define USB_DEVICE_ID_CYGNAL_CP2112 0xea90 | ||
243 | 246 | ||
244 | #define USB_VENDOR_ID_CYPRESS 0x04b4 | 247 | #define USB_VENDOR_ID_CYPRESS 0x04b4 |
245 | #define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001 | 248 | #define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001 |
@@ -449,6 +452,9 @@ | |||
449 | #define USB_VENDOR_ID_INTEL_1 0x8087 | 452 | #define USB_VENDOR_ID_INTEL_1 0x8087 |
450 | #define USB_DEVICE_ID_INTEL_HID_SENSOR 0x09fa | 453 | #define USB_DEVICE_ID_INTEL_HID_SENSOR 0x09fa |
451 | 454 | ||
455 | #define USB_VENDOR_ID_STM_0 0x0483 | ||
456 | #define USB_DEVICE_ID_STM_HID_SENSOR 0x91d1 | ||
457 | |||
452 | #define USB_VENDOR_ID_ION 0x15e4 | 458 | #define USB_VENDOR_ID_ION 0x15e4 |
453 | #define USB_DEVICE_ID_ICADE 0x0132 | 459 | #define USB_DEVICE_ID_ICADE 0x0132 |
454 | 460 | ||
@@ -618,6 +624,8 @@ | |||
618 | #define USB_DEVICE_ID_MS_PRESENTER_8K_USB 0x0713 | 624 | #define USB_DEVICE_ID_MS_PRESENTER_8K_USB 0x0713 |
619 | #define USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K 0x0730 | 625 | #define USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K 0x0730 |
620 | #define USB_DEVICE_ID_MS_COMFORT_MOUSE_4500 0x076c | 626 | #define USB_DEVICE_ID_MS_COMFORT_MOUSE_4500 0x076c |
627 | #define USB_DEVICE_ID_MS_TOUCH_COVER_2 0x07a7 | ||
628 | #define USB_DEVICE_ID_MS_TYPE_COVER_2 0x07a9 | ||
621 | 629 | ||
622 | #define USB_VENDOR_ID_MOJO 0x8282 | 630 | #define USB_VENDOR_ID_MOJO 0x8282 |
623 | #define USB_DEVICE_ID_RETRO_ADAPTER 0x3201 | 631 | #define USB_DEVICE_ID_RETRO_ADAPTER 0x3201 |
@@ -643,6 +651,7 @@ | |||
643 | 651 | ||
644 | #define USB_VENDOR_ID_NEXIO 0x1870 | 652 | #define USB_VENDOR_ID_NEXIO 0x1870 |
645 | #define USB_DEVICE_ID_NEXIO_MULTITOUCH_420 0x010d | 653 | #define USB_DEVICE_ID_NEXIO_MULTITOUCH_420 0x010d |
654 | #define USB_DEVICE_ID_NEXIO_MULTITOUCH_PTI0750 0x0110 | ||
646 | 655 | ||
647 | #define USB_VENDOR_ID_NEXTWINDOW 0x1926 | 656 | #define USB_VENDOR_ID_NEXTWINDOW 0x1926 |
648 | #define USB_DEVICE_ID_NEXTWINDOW_TOUCHSCREEN 0x0003 | 657 | #define USB_DEVICE_ID_NEXTWINDOW_TOUCHSCREEN 0x0003 |
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 1f0d49c6feef..e7e8b19a9284 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c | |||
@@ -350,9 +350,9 @@ static int hidinput_get_battery_property(struct power_supply *psy, | |||
350 | ret = -ENOMEM; | 350 | ret = -ENOMEM; |
351 | break; | 351 | break; |
352 | } | 352 | } |
353 | ret = dev->hid_get_raw_report(dev, dev->battery_report_id, | 353 | ret = hid_hw_raw_request(dev, dev->battery_report_id, buf, 2, |
354 | buf, 2, | 354 | dev->battery_report_type, |
355 | dev->battery_report_type); | 355 | HID_REQ_GET_REPORT); |
356 | 356 | ||
357 | if (ret != 2) { | 357 | if (ret != 2) { |
358 | ret = -ENODATA; | 358 | ret = -ENODATA; |
@@ -1153,7 +1153,7 @@ static void hidinput_led_worker(struct work_struct *work) | |||
1153 | led_work); | 1153 | led_work); |
1154 | struct hid_field *field; | 1154 | struct hid_field *field; |
1155 | struct hid_report *report; | 1155 | struct hid_report *report; |
1156 | int len; | 1156 | int len, ret; |
1157 | __u8 *buf; | 1157 | __u8 *buf; |
1158 | 1158 | ||
1159 | field = hidinput_get_led_field(hid); | 1159 | field = hidinput_get_led_field(hid); |
@@ -1181,13 +1181,16 @@ static void hidinput_led_worker(struct work_struct *work) | |||
1181 | 1181 | ||
1182 | /* fall back to generic raw-output-report */ | 1182 | /* fall back to generic raw-output-report */ |
1183 | len = ((report->size - 1) >> 3) + 1 + (report->id > 0); | 1183 | len = ((report->size - 1) >> 3) + 1 + (report->id > 0); |
1184 | buf = kmalloc(len, GFP_KERNEL); | 1184 | buf = hid_alloc_report_buf(report, GFP_KERNEL); |
1185 | if (!buf) | 1185 | if (!buf) |
1186 | return; | 1186 | return; |
1187 | 1187 | ||
1188 | hid_output_report(report, buf); | 1188 | hid_output_report(report, buf); |
1189 | /* synchronous output report */ | 1189 | /* synchronous output report */ |
1190 | hid->hid_output_raw_report(hid, buf, len, HID_OUTPUT_REPORT); | 1190 | ret = hid_hw_output_report(hid, buf, len); |
1191 | if (ret == -ENOSYS) | ||
1192 | hid_hw_raw_request(hid, report->id, buf, len, HID_OUTPUT_REPORT, | ||
1193 | HID_REQ_SET_REPORT); | ||
1191 | kfree(buf); | 1194 | kfree(buf); |
1192 | } | 1195 | } |
1193 | 1196 | ||
@@ -1266,10 +1269,7 @@ static struct hid_input *hidinput_allocate(struct hid_device *hid) | |||
1266 | } | 1269 | } |
1267 | 1270 | ||
1268 | input_set_drvdata(input_dev, hid); | 1271 | input_set_drvdata(input_dev, hid); |
1269 | if (hid->ll_driver->hidinput_input_event) | 1272 | input_dev->event = hidinput_input_event; |
1270 | input_dev->event = hid->ll_driver->hidinput_input_event; | ||
1271 | else if (hid->ll_driver->request || hid->hid_output_raw_report) | ||
1272 | input_dev->event = hidinput_input_event; | ||
1273 | input_dev->open = hidinput_open; | 1273 | input_dev->open = hidinput_open; |
1274 | input_dev->close = hidinput_close; | 1274 | input_dev->close = hidinput_close; |
1275 | input_dev->setkeycode = hidinput_setkeycode; | 1275 | input_dev->setkeycode = hidinput_setkeycode; |
diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c index 9fe9d4ac3114..a976f48263f6 100644 --- a/drivers/hid/hid-lg.c +++ b/drivers/hid/hid-lg.c | |||
@@ -692,7 +692,8 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
692 | if (hdev->product == USB_DEVICE_ID_LOGITECH_WII_WHEEL) { | 692 | if (hdev->product == USB_DEVICE_ID_LOGITECH_WII_WHEEL) { |
693 | unsigned char buf[] = { 0x00, 0xAF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; | 693 | unsigned char buf[] = { 0x00, 0xAF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
694 | 694 | ||
695 | ret = hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT); | 695 | ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf), |
696 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | ||
696 | 697 | ||
697 | if (ret >= 0) { | 698 | if (ret >= 0) { |
698 | /* insert a little delay of 10 jiffies ~ 40ms */ | 699 | /* insert a little delay of 10 jiffies ~ 40ms */ |
@@ -704,7 +705,8 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
704 | buf[1] = 0xB2; | 705 | buf[1] = 0xB2; |
705 | get_random_bytes(&buf[2], 2); | 706 | get_random_bytes(&buf[2], 2); |
706 | 707 | ||
707 | ret = hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT); | 708 | ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf), |
709 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | ||
708 | } | 710 | } |
709 | } | 711 | } |
710 | 712 | ||
diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c index befe0e336471..24883b4d1a49 100644 --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c | |||
@@ -43,6 +43,7 @@ | |||
43 | #define G25_REV_MIN 0x22 | 43 | #define G25_REV_MIN 0x22 |
44 | #define G27_REV_MAJ 0x12 | 44 | #define G27_REV_MAJ 0x12 |
45 | #define G27_REV_MIN 0x38 | 45 | #define G27_REV_MIN 0x38 |
46 | #define G27_2_REV_MIN 0x39 | ||
46 | 47 | ||
47 | #define to_hid_device(pdev) container_of(pdev, struct hid_device, dev) | 48 | #define to_hid_device(pdev) container_of(pdev, struct hid_device, dev) |
48 | 49 | ||
@@ -130,6 +131,7 @@ static const struct lg4ff_usb_revision lg4ff_revs[] = { | |||
130 | {DFP_REV_MAJ, DFP_REV_MIN, &native_dfp}, /* Driving Force Pro */ | 131 | {DFP_REV_MAJ, DFP_REV_MIN, &native_dfp}, /* Driving Force Pro */ |
131 | {G25_REV_MAJ, G25_REV_MIN, &native_g25}, /* G25 */ | 132 | {G25_REV_MAJ, G25_REV_MIN, &native_g25}, /* G25 */ |
132 | {G27_REV_MAJ, G27_REV_MIN, &native_g27}, /* G27 */ | 133 | {G27_REV_MAJ, G27_REV_MIN, &native_g27}, /* G27 */ |
134 | {G27_REV_MAJ, G27_2_REV_MIN, &native_g27}, /* G27 v2 */ | ||
133 | }; | 135 | }; |
134 | 136 | ||
135 | /* Recalculates X axis value accordingly to currently selected range */ | 137 | /* Recalculates X axis value accordingly to currently selected range */ |
diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c index f45279c3b11a..486dbde2ba2d 100644 --- a/drivers/hid/hid-logitech-dj.c +++ b/drivers/hid/hid-logitech-dj.c | |||
@@ -44,14 +44,6 @@ static const char kbd_descriptor[] = { | |||
44 | 0x19, 0xE0, /* USAGE_MINIMUM (Left Control) */ | 44 | 0x19, 0xE0, /* USAGE_MINIMUM (Left Control) */ |
45 | 0x29, 0xE7, /* USAGE_MAXIMUM (Right GUI) */ | 45 | 0x29, 0xE7, /* USAGE_MAXIMUM (Right GUI) */ |
46 | 0x81, 0x02, /* INPUT (Data,Var,Abs) */ | 46 | 0x81, 0x02, /* INPUT (Data,Var,Abs) */ |
47 | 0x95, 0x05, /* REPORT COUNT (5) */ | ||
48 | 0x05, 0x08, /* USAGE PAGE (LED page) */ | ||
49 | 0x19, 0x01, /* USAGE MINIMUM (1) */ | ||
50 | 0x29, 0x05, /* USAGE MAXIMUM (5) */ | ||
51 | 0x91, 0x02, /* OUTPUT (Data, Variable, Absolute) */ | ||
52 | 0x95, 0x01, /* REPORT COUNT (1) */ | ||
53 | 0x75, 0x03, /* REPORT SIZE (3) */ | ||
54 | 0x91, 0x01, /* OUTPUT (Constant) */ | ||
55 | 0x95, 0x06, /* REPORT_COUNT (6) */ | 47 | 0x95, 0x06, /* REPORT_COUNT (6) */ |
56 | 0x75, 0x08, /* REPORT_SIZE (8) */ | 48 | 0x75, 0x08, /* REPORT_SIZE (8) */ |
57 | 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ | 49 | 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ |
@@ -60,6 +52,18 @@ static const char kbd_descriptor[] = { | |||
60 | 0x19, 0x00, /* USAGE_MINIMUM (no event) */ | 52 | 0x19, 0x00, /* USAGE_MINIMUM (no event) */ |
61 | 0x2A, 0xFF, 0x00, /* USAGE_MAXIMUM (reserved) */ | 53 | 0x2A, 0xFF, 0x00, /* USAGE_MAXIMUM (reserved) */ |
62 | 0x81, 0x00, /* INPUT (Data,Ary,Abs) */ | 54 | 0x81, 0x00, /* INPUT (Data,Ary,Abs) */ |
55 | 0x85, 0x0e, /* REPORT_ID (14) */ | ||
56 | 0x05, 0x08, /* USAGE PAGE (LED page) */ | ||
57 | 0x95, 0x05, /* REPORT COUNT (5) */ | ||
58 | 0x75, 0x01, /* REPORT SIZE (1) */ | ||
59 | 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ | ||
60 | 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ | ||
61 | 0x19, 0x01, /* USAGE MINIMUM (1) */ | ||
62 | 0x29, 0x05, /* USAGE MAXIMUM (5) */ | ||
63 | 0x91, 0x02, /* OUTPUT (Data, Variable, Absolute) */ | ||
64 | 0x95, 0x01, /* REPORT COUNT (1) */ | ||
65 | 0x75, 0x03, /* REPORT SIZE (3) */ | ||
66 | 0x91, 0x01, /* OUTPUT (Constant) */ | ||
63 | 0xC0 | 67 | 0xC0 |
64 | }; | 68 | }; |
65 | 69 | ||
@@ -189,9 +193,6 @@ static const u8 hid_reportid_size_map[NUMBER_OF_HID_REPORTS] = { | |||
189 | 193 | ||
190 | static struct hid_ll_driver logi_dj_ll_driver; | 194 | static struct hid_ll_driver logi_dj_ll_driver; |
191 | 195 | ||
192 | static int logi_dj_output_hidraw_report(struct hid_device *hid, u8 * buf, | ||
193 | size_t count, | ||
194 | unsigned char report_type); | ||
195 | static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev); | 196 | static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev); |
196 | 197 | ||
197 | static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev, | 198 | static void logi_dj_recv_destroy_djhid_device(struct dj_receiver_dev *djrcv_dev, |
@@ -258,7 +259,6 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev, | |||
258 | } | 259 | } |
259 | 260 | ||
260 | dj_hiddev->ll_driver = &logi_dj_ll_driver; | 261 | dj_hiddev->ll_driver = &logi_dj_ll_driver; |
261 | dj_hiddev->hid_output_raw_report = logi_dj_output_hidraw_report; | ||
262 | 262 | ||
263 | dj_hiddev->dev.parent = &djrcv_hdev->dev; | 263 | dj_hiddev->dev.parent = &djrcv_hdev->dev; |
264 | dj_hiddev->bus = BUS_USB; | 264 | dj_hiddev->bus = BUS_USB; |
@@ -540,14 +540,35 @@ static void logi_dj_ll_close(struct hid_device *hid) | |||
540 | dbg_hid("%s:%s\n", __func__, hid->phys); | 540 | dbg_hid("%s:%s\n", __func__, hid->phys); |
541 | } | 541 | } |
542 | 542 | ||
543 | static int logi_dj_output_hidraw_report(struct hid_device *hid, u8 * buf, | 543 | static int logi_dj_ll_raw_request(struct hid_device *hid, |
544 | size_t count, | 544 | unsigned char reportnum, __u8 *buf, |
545 | unsigned char report_type) | 545 | size_t count, unsigned char report_type, |
546 | int reqtype) | ||
546 | { | 547 | { |
547 | /* Called by hid raw to send data */ | 548 | struct dj_device *djdev = hid->driver_data; |
548 | dbg_hid("%s\n", __func__); | 549 | struct dj_receiver_dev *djrcv_dev = djdev->dj_receiver_dev; |
550 | u8 *out_buf; | ||
551 | int ret; | ||
549 | 552 | ||
550 | return 0; | 553 | if (buf[0] != REPORT_TYPE_LEDS) |
554 | return -EINVAL; | ||
555 | |||
556 | out_buf = kzalloc(DJREPORT_SHORT_LENGTH, GFP_ATOMIC); | ||
557 | if (!out_buf) | ||
558 | return -ENOMEM; | ||
559 | |||
560 | if (count < DJREPORT_SHORT_LENGTH - 2) | ||
561 | count = DJREPORT_SHORT_LENGTH - 2; | ||
562 | |||
563 | out_buf[0] = REPORT_ID_DJ_SHORT; | ||
564 | out_buf[1] = djdev->device_index; | ||
565 | memcpy(out_buf + 2, buf, count); | ||
566 | |||
567 | ret = hid_hw_raw_request(djrcv_dev->hdev, out_buf[0], out_buf, | ||
568 | DJREPORT_SHORT_LENGTH, report_type, reqtype); | ||
569 | |||
570 | kfree(out_buf); | ||
571 | return ret; | ||
551 | } | 572 | } |
552 | 573 | ||
553 | static void rdcat(char *rdesc, unsigned int *rsize, const char *data, unsigned int size) | 574 | static void rdcat(char *rdesc, unsigned int *rsize, const char *data, unsigned int size) |
@@ -613,58 +634,6 @@ static int logi_dj_ll_parse(struct hid_device *hid) | |||
613 | return retval; | 634 | return retval; |
614 | } | 635 | } |
615 | 636 | ||
616 | static int logi_dj_ll_input_event(struct input_dev *dev, unsigned int type, | ||
617 | unsigned int code, int value) | ||
618 | { | ||
619 | /* Sent by the input layer to handle leds and Force Feedback */ | ||
620 | struct hid_device *dj_hiddev = input_get_drvdata(dev); | ||
621 | struct dj_device *dj_dev = dj_hiddev->driver_data; | ||
622 | |||
623 | struct dj_receiver_dev *djrcv_dev = | ||
624 | dev_get_drvdata(dj_hiddev->dev.parent); | ||
625 | struct hid_device *dj_rcv_hiddev = djrcv_dev->hdev; | ||
626 | struct hid_report_enum *output_report_enum; | ||
627 | |||
628 | struct hid_field *field; | ||
629 | struct hid_report *report; | ||
630 | unsigned char *data; | ||
631 | int offset; | ||
632 | |||
633 | dbg_hid("%s: %s, type:%d | code:%d | value:%d\n", | ||
634 | __func__, dev->phys, type, code, value); | ||
635 | |||
636 | if (type != EV_LED) | ||
637 | return -1; | ||
638 | |||
639 | offset = hidinput_find_field(dj_hiddev, type, code, &field); | ||
640 | |||
641 | if (offset == -1) { | ||
642 | dev_warn(&dev->dev, "event field not found\n"); | ||
643 | return -1; | ||
644 | } | ||
645 | hid_set_field(field, offset, value); | ||
646 | |||
647 | data = hid_alloc_report_buf(field->report, GFP_ATOMIC); | ||
648 | if (!data) { | ||
649 | dev_warn(&dev->dev, "failed to allocate report buf memory\n"); | ||
650 | return -1; | ||
651 | } | ||
652 | |||
653 | hid_output_report(field->report, &data[0]); | ||
654 | |||
655 | output_report_enum = &dj_rcv_hiddev->report_enum[HID_OUTPUT_REPORT]; | ||
656 | report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT]; | ||
657 | hid_set_field(report->field[0], 0, dj_dev->device_index); | ||
658 | hid_set_field(report->field[0], 1, REPORT_TYPE_LEDS); | ||
659 | hid_set_field(report->field[0], 2, data[1]); | ||
660 | |||
661 | hid_hw_request(dj_rcv_hiddev, report, HID_REQ_SET_REPORT); | ||
662 | |||
663 | kfree(data); | ||
664 | |||
665 | return 0; | ||
666 | } | ||
667 | |||
668 | static int logi_dj_ll_start(struct hid_device *hid) | 637 | static int logi_dj_ll_start(struct hid_device *hid) |
669 | { | 638 | { |
670 | dbg_hid("%s\n", __func__); | 639 | dbg_hid("%s\n", __func__); |
@@ -683,7 +652,7 @@ static struct hid_ll_driver logi_dj_ll_driver = { | |||
683 | .stop = logi_dj_ll_stop, | 652 | .stop = logi_dj_ll_stop, |
684 | .open = logi_dj_ll_open, | 653 | .open = logi_dj_ll_open, |
685 | .close = logi_dj_ll_close, | 654 | .close = logi_dj_ll_close, |
686 | .hidinput_input_event = logi_dj_ll_input_event, | 655 | .raw_request = logi_dj_ll_raw_request, |
687 | }; | 656 | }; |
688 | 657 | ||
689 | 658 | ||
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index 3b43d1cfa936..ecc2cbf300cc 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c | |||
@@ -538,8 +538,8 @@ static int magicmouse_probe(struct hid_device *hdev, | |||
538 | * but there seems to be no other way of switching the mode. | 538 | * but there seems to be no other way of switching the mode. |
539 | * Thus the super-ugly hacky success check below. | 539 | * Thus the super-ugly hacky success check below. |
540 | */ | 540 | */ |
541 | ret = hdev->hid_output_raw_report(hdev, feature, sizeof(feature), | 541 | ret = hid_hw_raw_request(hdev, feature[0], feature, sizeof(feature), |
542 | HID_FEATURE_REPORT); | 542 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
543 | if (ret != -EIO && ret != sizeof(feature)) { | 543 | if (ret != -EIO && ret != sizeof(feature)) { |
544 | hid_err(hdev, "unable to request touch data (%d)\n", ret); | 544 | hid_err(hdev, "unable to request touch data (%d)\n", ret); |
545 | goto err_stop_hw; | 545 | goto err_stop_hw; |
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c index 8ba17a946f2a..6fd58175a291 100644 --- a/drivers/hid/hid-microsoft.c +++ b/drivers/hid/hid-microsoft.c | |||
@@ -274,6 +274,10 @@ static const struct hid_device_id ms_devices[] = { | |||
274 | .driver_data = MS_NOGET }, | 274 | .driver_data = MS_NOGET }, |
275 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500), | 275 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500), |
276 | .driver_data = MS_DUPLICATE_USAGES }, | 276 | .driver_data = MS_DUPLICATE_USAGES }, |
277 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TYPE_COVER_2), | ||
278 | .driver_data = 0 }, | ||
279 | { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_TOUCH_COVER_2), | ||
280 | .driver_data = 0 }, | ||
277 | 281 | ||
278 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT), | 282 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT), |
279 | .driver_data = MS_PRESENTER }, | 283 | .driver_data = MS_PRESENTER }, |
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index f134d73beca1..221d503f1c24 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c | |||
@@ -1166,6 +1166,11 @@ static const struct hid_device_id mt_devices[] = { | |||
1166 | MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG, | 1166 | MT_USB_DEVICE(USB_VENDOR_ID_FLATFROG, |
1167 | USB_DEVICE_ID_MULTITOUCH_3200) }, | 1167 | USB_DEVICE_ID_MULTITOUCH_3200) }, |
1168 | 1168 | ||
1169 | /* FocalTech Panels */ | ||
1170 | { .driver_data = MT_CLS_SERIAL, | ||
1171 | MT_USB_DEVICE(USB_VENDOR_ID_CYGNAL, | ||
1172 | USB_DEVICE_ID_FOCALTECH_FTXXXX_MULTITOUCH) }, | ||
1173 | |||
1169 | /* GeneralTouch panel */ | 1174 | /* GeneralTouch panel */ |
1170 | { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS, | 1175 | { .driver_data = MT_CLS_GENERALTOUCH_TWOFINGERS, |
1171 | MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, | 1176 | MT_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, |
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c index 46f4480035bc..5182031f7b52 100644 --- a/drivers/hid/hid-sensor-hub.c +++ b/drivers/hid/hid-sensor-hub.c | |||
@@ -56,9 +56,9 @@ struct sensor_hub_pending { | |||
56 | * @dyn_callback_lock: spin lock to protect callback list | 56 | * @dyn_callback_lock: spin lock to protect callback list |
57 | * @hid_sensor_hub_client_devs: Stores all MFD cells for a hub instance. | 57 | * @hid_sensor_hub_client_devs: Stores all MFD cells for a hub instance. |
58 | * @hid_sensor_client_cnt: Number of MFD cells, (no of sensors attached). | 58 | * @hid_sensor_client_cnt: Number of MFD cells, (no of sensors attached). |
59 | * @ref_cnt: Number of MFD clients have opened this device | ||
59 | */ | 60 | */ |
60 | struct sensor_hub_data { | 61 | struct sensor_hub_data { |
61 | struct hid_sensor_hub_device *hsdev; | ||
62 | struct mutex mutex; | 62 | struct mutex mutex; |
63 | spinlock_t lock; | 63 | spinlock_t lock; |
64 | struct sensor_hub_pending pending; | 64 | struct sensor_hub_pending pending; |
@@ -67,6 +67,7 @@ struct sensor_hub_data { | |||
67 | struct mfd_cell *hid_sensor_hub_client_devs; | 67 | struct mfd_cell *hid_sensor_hub_client_devs; |
68 | int hid_sensor_client_cnt; | 68 | int hid_sensor_client_cnt; |
69 | unsigned long quirks; | 69 | unsigned long quirks; |
70 | int ref_cnt; | ||
70 | }; | 71 | }; |
71 | 72 | ||
72 | /** | 73 | /** |
@@ -79,6 +80,7 @@ struct sensor_hub_data { | |||
79 | struct hid_sensor_hub_callbacks_list { | 80 | struct hid_sensor_hub_callbacks_list { |
80 | struct list_head list; | 81 | struct list_head list; |
81 | u32 usage_id; | 82 | u32 usage_id; |
83 | struct hid_sensor_hub_device *hsdev; | ||
82 | struct hid_sensor_hub_callbacks *usage_callback; | 84 | struct hid_sensor_hub_callbacks *usage_callback; |
83 | void *priv; | 85 | void *priv; |
84 | }; | 86 | }; |
@@ -97,20 +99,18 @@ static struct hid_report *sensor_hub_report(int id, struct hid_device *hdev, | |||
97 | return NULL; | 99 | return NULL; |
98 | } | 100 | } |
99 | 101 | ||
100 | static int sensor_hub_get_physical_device_count( | 102 | static int sensor_hub_get_physical_device_count(struct hid_device *hdev) |
101 | struct hid_report_enum *report_enum) | ||
102 | { | 103 | { |
103 | struct hid_report *report; | 104 | int i; |
104 | struct hid_field *field; | 105 | int count = 0; |
105 | int cnt = 0; | ||
106 | 106 | ||
107 | list_for_each_entry(report, &report_enum->report_list, list) { | 107 | for (i = 0; i < hdev->maxcollection; ++i) { |
108 | field = report->field[0]; | 108 | struct hid_collection *collection = &hdev->collection[i]; |
109 | if (report->maxfield && field && field->physical) | 109 | if (collection->type == HID_COLLECTION_PHYSICAL) |
110 | cnt++; | 110 | ++count; |
111 | } | 111 | } |
112 | 112 | ||
113 | return cnt; | 113 | return count; |
114 | } | 114 | } |
115 | 115 | ||
116 | static void sensor_hub_fill_attr_info( | 116 | static void sensor_hub_fill_attr_info( |
@@ -128,15 +128,23 @@ static void sensor_hub_fill_attr_info( | |||
128 | 128 | ||
129 | static struct hid_sensor_hub_callbacks *sensor_hub_get_callback( | 129 | static struct hid_sensor_hub_callbacks *sensor_hub_get_callback( |
130 | struct hid_device *hdev, | 130 | struct hid_device *hdev, |
131 | u32 usage_id, void **priv) | 131 | u32 usage_id, |
132 | int collection_index, | ||
133 | struct hid_sensor_hub_device **hsdev, | ||
134 | void **priv) | ||
132 | { | 135 | { |
133 | struct hid_sensor_hub_callbacks_list *callback; | 136 | struct hid_sensor_hub_callbacks_list *callback; |
134 | struct sensor_hub_data *pdata = hid_get_drvdata(hdev); | 137 | struct sensor_hub_data *pdata = hid_get_drvdata(hdev); |
135 | 138 | ||
136 | spin_lock(&pdata->dyn_callback_lock); | 139 | spin_lock(&pdata->dyn_callback_lock); |
137 | list_for_each_entry(callback, &pdata->dyn_callback_list, list) | 140 | list_for_each_entry(callback, &pdata->dyn_callback_list, list) |
138 | if (callback->usage_id == usage_id) { | 141 | if (callback->usage_id == usage_id && |
142 | (collection_index >= | ||
143 | callback->hsdev->start_collection_index) && | ||
144 | (collection_index < | ||
145 | callback->hsdev->end_collection_index)) { | ||
139 | *priv = callback->priv; | 146 | *priv = callback->priv; |
147 | *hsdev = callback->hsdev; | ||
140 | spin_unlock(&pdata->dyn_callback_lock); | 148 | spin_unlock(&pdata->dyn_callback_lock); |
141 | return callback->usage_callback; | 149 | return callback->usage_callback; |
142 | } | 150 | } |
@@ -154,7 +162,8 @@ int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev, | |||
154 | 162 | ||
155 | spin_lock(&pdata->dyn_callback_lock); | 163 | spin_lock(&pdata->dyn_callback_lock); |
156 | list_for_each_entry(callback, &pdata->dyn_callback_list, list) | 164 | list_for_each_entry(callback, &pdata->dyn_callback_list, list) |
157 | if (callback->usage_id == usage_id) { | 165 | if (callback->usage_id == usage_id && |
166 | callback->hsdev == hsdev) { | ||
158 | spin_unlock(&pdata->dyn_callback_lock); | 167 | spin_unlock(&pdata->dyn_callback_lock); |
159 | return -EINVAL; | 168 | return -EINVAL; |
160 | } | 169 | } |
@@ -163,6 +172,7 @@ int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev, | |||
163 | spin_unlock(&pdata->dyn_callback_lock); | 172 | spin_unlock(&pdata->dyn_callback_lock); |
164 | return -ENOMEM; | 173 | return -ENOMEM; |
165 | } | 174 | } |
175 | callback->hsdev = hsdev; | ||
166 | callback->usage_callback = usage_callback; | 176 | callback->usage_callback = usage_callback; |
167 | callback->usage_id = usage_id; | 177 | callback->usage_id = usage_id; |
168 | callback->priv = NULL; | 178 | callback->priv = NULL; |
@@ -181,7 +191,8 @@ int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev, | |||
181 | 191 | ||
182 | spin_lock(&pdata->dyn_callback_lock); | 192 | spin_lock(&pdata->dyn_callback_lock); |
183 | list_for_each_entry(callback, &pdata->dyn_callback_list, list) | 193 | list_for_each_entry(callback, &pdata->dyn_callback_list, list) |
184 | if (callback->usage_id == usage_id) { | 194 | if (callback->usage_id == usage_id && |
195 | callback->hsdev == hsdev) { | ||
185 | list_del(&callback->list); | 196 | list_del(&callback->list); |
186 | kfree(callback); | 197 | kfree(callback); |
187 | break; | 198 | break; |
@@ -260,13 +271,12 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, | |||
260 | 271 | ||
261 | spin_lock_irqsave(&data->lock, flags); | 272 | spin_lock_irqsave(&data->lock, flags); |
262 | data->pending.status = true; | 273 | data->pending.status = true; |
274 | spin_unlock_irqrestore(&data->lock, flags); | ||
263 | report = sensor_hub_report(report_id, hsdev->hdev, HID_INPUT_REPORT); | 275 | report = sensor_hub_report(report_id, hsdev->hdev, HID_INPUT_REPORT); |
264 | if (!report) { | 276 | if (!report) |
265 | spin_unlock_irqrestore(&data->lock, flags); | ||
266 | goto err_free; | 277 | goto err_free; |
267 | } | 278 | |
268 | hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT); | 279 | hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT); |
269 | spin_unlock_irqrestore(&data->lock, flags); | ||
270 | wait_for_completion_interruptible_timeout(&data->pending.ready, HZ*5); | 280 | wait_for_completion_interruptible_timeout(&data->pending.ready, HZ*5); |
271 | switch (data->pending.raw_size) { | 281 | switch (data->pending.raw_size) { |
272 | case 1: | 282 | case 1: |
@@ -291,6 +301,28 @@ err_free: | |||
291 | } | 301 | } |
292 | EXPORT_SYMBOL_GPL(sensor_hub_input_attr_get_raw_value); | 302 | EXPORT_SYMBOL_GPL(sensor_hub_input_attr_get_raw_value); |
293 | 303 | ||
304 | int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev, | ||
305 | u32 report_id, int field_index, u32 usage_id) | ||
306 | { | ||
307 | struct hid_report *report; | ||
308 | struct hid_field *field; | ||
309 | int i; | ||
310 | |||
311 | report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT); | ||
312 | if (!report || (field_index >= report->maxfield)) | ||
313 | goto done_proc; | ||
314 | |||
315 | field = report->field[field_index]; | ||
316 | for (i = 0; i < field->maxusage; ++i) { | ||
317 | if (field->usage[i].hid == usage_id) | ||
318 | return field->usage[i].usage_index; | ||
319 | } | ||
320 | |||
321 | done_proc: | ||
322 | return -EINVAL; | ||
323 | } | ||
324 | EXPORT_SYMBOL_GPL(hid_sensor_get_usage_index); | ||
325 | |||
294 | int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev, | 326 | int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev, |
295 | u8 type, | 327 | u8 type, |
296 | u32 usage_id, | 328 | u32 usage_id, |
@@ -298,8 +330,7 @@ int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev, | |||
298 | struct hid_sensor_hub_attribute_info *info) | 330 | struct hid_sensor_hub_attribute_info *info) |
299 | { | 331 | { |
300 | int ret = -1; | 332 | int ret = -1; |
301 | int i, j; | 333 | int i; |
302 | int collection_index = -1; | ||
303 | struct hid_report *report; | 334 | struct hid_report *report; |
304 | struct hid_field *field; | 335 | struct hid_field *field; |
305 | struct hid_report_enum *report_enum; | 336 | struct hid_report_enum *report_enum; |
@@ -313,44 +344,31 @@ int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev, | |||
313 | info->units = -1; | 344 | info->units = -1; |
314 | info->unit_expo = -1; | 345 | info->unit_expo = -1; |
315 | 346 | ||
316 | for (i = 0; i < hdev->maxcollection; ++i) { | ||
317 | struct hid_collection *collection = &hdev->collection[i]; | ||
318 | if (usage_id == collection->usage) { | ||
319 | collection_index = i; | ||
320 | break; | ||
321 | } | ||
322 | } | ||
323 | if (collection_index == -1) | ||
324 | goto err_ret; | ||
325 | |||
326 | report_enum = &hdev->report_enum[type]; | 347 | report_enum = &hdev->report_enum[type]; |
327 | list_for_each_entry(report, &report_enum->report_list, list) { | 348 | list_for_each_entry(report, &report_enum->report_list, list) { |
328 | for (i = 0; i < report->maxfield; ++i) { | 349 | for (i = 0; i < report->maxfield; ++i) { |
329 | field = report->field[i]; | 350 | field = report->field[i]; |
330 | if (field->physical == usage_id && | 351 | if (field->maxusage) { |
331 | field->logical == attr_usage_id) { | 352 | if (field->physical == usage_id && |
332 | sensor_hub_fill_attr_info(info, i, report->id, | 353 | (field->logical == attr_usage_id || |
333 | field); | 354 | field->usage[0].hid == |
334 | ret = 0; | 355 | attr_usage_id) && |
335 | } else { | 356 | (field->usage[0].collection_index >= |
336 | for (j = 0; j < field->maxusage; ++j) { | 357 | hsdev->start_collection_index) && |
337 | if (field->usage[j].hid == | 358 | (field->usage[0].collection_index < |
338 | attr_usage_id && | 359 | hsdev->end_collection_index)) { |
339 | field->usage[j].collection_index == | 360 | |
340 | collection_index) { | 361 | sensor_hub_fill_attr_info(info, i, |
341 | sensor_hub_fill_attr_info(info, | 362 | report->id, |
342 | i, report->id, field); | 363 | field); |
343 | ret = 0; | 364 | ret = 0; |
344 | break; | 365 | break; |
345 | } | ||
346 | } | 366 | } |
347 | } | 367 | } |
348 | if (ret == 0) | ||
349 | break; | ||
350 | } | 368 | } |
369 | |||
351 | } | 370 | } |
352 | 371 | ||
353 | err_ret: | ||
354 | return ret; | 372 | return ret; |
355 | } | 373 | } |
356 | EXPORT_SYMBOL_GPL(sensor_hub_input_get_attribute_info); | 374 | EXPORT_SYMBOL_GPL(sensor_hub_input_get_attribute_info); |
@@ -366,7 +384,7 @@ static int sensor_hub_suspend(struct hid_device *hdev, pm_message_t message) | |||
366 | list_for_each_entry(callback, &pdata->dyn_callback_list, list) { | 384 | list_for_each_entry(callback, &pdata->dyn_callback_list, list) { |
367 | if (callback->usage_callback->suspend) | 385 | if (callback->usage_callback->suspend) |
368 | callback->usage_callback->suspend( | 386 | callback->usage_callback->suspend( |
369 | pdata->hsdev, callback->priv); | 387 | callback->hsdev, callback->priv); |
370 | } | 388 | } |
371 | spin_unlock(&pdata->dyn_callback_lock); | 389 | spin_unlock(&pdata->dyn_callback_lock); |
372 | 390 | ||
@@ -383,7 +401,7 @@ static int sensor_hub_resume(struct hid_device *hdev) | |||
383 | list_for_each_entry(callback, &pdata->dyn_callback_list, list) { | 401 | list_for_each_entry(callback, &pdata->dyn_callback_list, list) { |
384 | if (callback->usage_callback->resume) | 402 | if (callback->usage_callback->resume) |
385 | callback->usage_callback->resume( | 403 | callback->usage_callback->resume( |
386 | pdata->hsdev, callback->priv); | 404 | callback->hsdev, callback->priv); |
387 | } | 405 | } |
388 | spin_unlock(&pdata->dyn_callback_lock); | 406 | spin_unlock(&pdata->dyn_callback_lock); |
389 | 407 | ||
@@ -410,6 +428,7 @@ static int sensor_hub_raw_event(struct hid_device *hdev, | |||
410 | struct hid_sensor_hub_callbacks *callback = NULL; | 428 | struct hid_sensor_hub_callbacks *callback = NULL; |
411 | struct hid_collection *collection = NULL; | 429 | struct hid_collection *collection = NULL; |
412 | void *priv = NULL; | 430 | void *priv = NULL; |
431 | struct hid_sensor_hub_device *hsdev = NULL; | ||
413 | 432 | ||
414 | hid_dbg(hdev, "sensor_hub_raw_event report id:0x%x size:%d type:%d\n", | 433 | hid_dbg(hdev, "sensor_hub_raw_event report id:0x%x size:%d type:%d\n", |
415 | report->id, size, report->type); | 434 | report->id, size, report->type); |
@@ -444,23 +463,26 @@ static int sensor_hub_raw_event(struct hid_device *hdev, | |||
444 | report->field[i]->usage->collection_index]; | 463 | report->field[i]->usage->collection_index]; |
445 | hid_dbg(hdev, "collection->usage %x\n", | 464 | hid_dbg(hdev, "collection->usage %x\n", |
446 | collection->usage); | 465 | collection->usage); |
447 | callback = sensor_hub_get_callback(pdata->hsdev->hdev, | 466 | |
448 | report->field[i]->physical, | 467 | callback = sensor_hub_get_callback(hdev, |
449 | &priv); | 468 | report->field[i]->physical, |
469 | report->field[i]->usage[0].collection_index, | ||
470 | &hsdev, &priv); | ||
471 | |||
450 | if (callback && callback->capture_sample) { | 472 | if (callback && callback->capture_sample) { |
451 | if (report->field[i]->logical) | 473 | if (report->field[i]->logical) |
452 | callback->capture_sample(pdata->hsdev, | 474 | callback->capture_sample(hsdev, |
453 | report->field[i]->logical, sz, ptr, | 475 | report->field[i]->logical, sz, ptr, |
454 | callback->pdev); | 476 | callback->pdev); |
455 | else | 477 | else |
456 | callback->capture_sample(pdata->hsdev, | 478 | callback->capture_sample(hsdev, |
457 | report->field[i]->usage->hid, sz, ptr, | 479 | report->field[i]->usage->hid, sz, ptr, |
458 | callback->pdev); | 480 | callback->pdev); |
459 | } | 481 | } |
460 | ptr += sz; | 482 | ptr += sz; |
461 | } | 483 | } |
462 | if (callback && collection && callback->send_event) | 484 | if (callback && collection && callback->send_event) |
463 | callback->send_event(pdata->hsdev, collection->usage, | 485 | callback->send_event(hsdev, collection->usage, |
464 | callback->pdev); | 486 | callback->pdev); |
465 | spin_unlock_irqrestore(&pdata->lock, flags); | 487 | spin_unlock_irqrestore(&pdata->lock, flags); |
466 | 488 | ||
@@ -473,7 +495,7 @@ int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev) | |||
473 | struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev); | 495 | struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev); |
474 | 496 | ||
475 | mutex_lock(&data->mutex); | 497 | mutex_lock(&data->mutex); |
476 | if (!hsdev->ref_cnt) { | 498 | if (!data->ref_cnt) { |
477 | ret = hid_hw_open(hsdev->hdev); | 499 | ret = hid_hw_open(hsdev->hdev); |
478 | if (ret) { | 500 | if (ret) { |
479 | hid_err(hsdev->hdev, "failed to open hid device\n"); | 501 | hid_err(hsdev->hdev, "failed to open hid device\n"); |
@@ -481,7 +503,7 @@ int sensor_hub_device_open(struct hid_sensor_hub_device *hsdev) | |||
481 | return ret; | 503 | return ret; |
482 | } | 504 | } |
483 | } | 505 | } |
484 | hsdev->ref_cnt++; | 506 | data->ref_cnt++; |
485 | mutex_unlock(&data->mutex); | 507 | mutex_unlock(&data->mutex); |
486 | 508 | ||
487 | return ret; | 509 | return ret; |
@@ -493,8 +515,8 @@ void sensor_hub_device_close(struct hid_sensor_hub_device *hsdev) | |||
493 | struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev); | 515 | struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev); |
494 | 516 | ||
495 | mutex_lock(&data->mutex); | 517 | mutex_lock(&data->mutex); |
496 | hsdev->ref_cnt--; | 518 | data->ref_cnt--; |
497 | if (!hsdev->ref_cnt) | 519 | if (!data->ref_cnt) |
498 | hid_hw_close(hsdev->hdev); | 520 | hid_hw_close(hsdev->hdev); |
499 | mutex_unlock(&data->mutex); | 521 | mutex_unlock(&data->mutex); |
500 | } | 522 | } |
@@ -541,26 +563,19 @@ static int sensor_hub_probe(struct hid_device *hdev, | |||
541 | struct sensor_hub_data *sd; | 563 | struct sensor_hub_data *sd; |
542 | int i; | 564 | int i; |
543 | char *name; | 565 | char *name; |
544 | struct hid_report *report; | ||
545 | struct hid_report_enum *report_enum; | ||
546 | struct hid_field *field; | ||
547 | int dev_cnt; | 566 | int dev_cnt; |
567 | struct hid_sensor_hub_device *hsdev; | ||
568 | struct hid_sensor_hub_device *last_hsdev = NULL; | ||
548 | 569 | ||
549 | sd = devm_kzalloc(&hdev->dev, sizeof(*sd), GFP_KERNEL); | 570 | sd = devm_kzalloc(&hdev->dev, sizeof(*sd), GFP_KERNEL); |
550 | if (!sd) { | 571 | if (!sd) { |
551 | hid_err(hdev, "cannot allocate Sensor data\n"); | 572 | hid_err(hdev, "cannot allocate Sensor data\n"); |
552 | return -ENOMEM; | 573 | return -ENOMEM; |
553 | } | 574 | } |
554 | sd->hsdev = devm_kzalloc(&hdev->dev, sizeof(*sd->hsdev), GFP_KERNEL); | 575 | |
555 | if (!sd->hsdev) { | ||
556 | hid_err(hdev, "cannot allocate hid_sensor_hub_device\n"); | ||
557 | return -ENOMEM; | ||
558 | } | ||
559 | hid_set_drvdata(hdev, sd); | 576 | hid_set_drvdata(hdev, sd); |
560 | sd->quirks = id->driver_data; | 577 | sd->quirks = id->driver_data; |
561 | sd->hsdev->hdev = hdev; | 578 | |
562 | sd->hsdev->vendor_id = hdev->vendor; | ||
563 | sd->hsdev->product_id = hdev->product; | ||
564 | spin_lock_init(&sd->lock); | 579 | spin_lock_init(&sd->lock); |
565 | spin_lock_init(&sd->dyn_callback_lock); | 580 | spin_lock_init(&sd->dyn_callback_lock); |
566 | mutex_init(&sd->mutex); | 581 | mutex_init(&sd->mutex); |
@@ -578,9 +593,8 @@ static int sensor_hub_probe(struct hid_device *hdev, | |||
578 | } | 593 | } |
579 | INIT_LIST_HEAD(&sd->dyn_callback_list); | 594 | INIT_LIST_HEAD(&sd->dyn_callback_list); |
580 | sd->hid_sensor_client_cnt = 0; | 595 | sd->hid_sensor_client_cnt = 0; |
581 | report_enum = &hdev->report_enum[HID_INPUT_REPORT]; | ||
582 | 596 | ||
583 | dev_cnt = sensor_hub_get_physical_device_count(report_enum); | 597 | dev_cnt = sensor_hub_get_physical_device_count(hdev); |
584 | if (dev_cnt > HID_MAX_PHY_DEVICES) { | 598 | if (dev_cnt > HID_MAX_PHY_DEVICES) { |
585 | hid_err(hdev, "Invalid Physical device count\n"); | 599 | hid_err(hdev, "Invalid Physical device count\n"); |
586 | ret = -EINVAL; | 600 | ret = -EINVAL; |
@@ -594,42 +608,63 @@ static int sensor_hub_probe(struct hid_device *hdev, | |||
594 | ret = -ENOMEM; | 608 | ret = -ENOMEM; |
595 | goto err_stop_hw; | 609 | goto err_stop_hw; |
596 | } | 610 | } |
597 | list_for_each_entry(report, &report_enum->report_list, list) { | 611 | |
598 | hid_dbg(hdev, "Report id:%x\n", report->id); | 612 | for (i = 0; i < hdev->maxcollection; ++i) { |
599 | field = report->field[0]; | 613 | struct hid_collection *collection = &hdev->collection[i]; |
600 | if (report->maxfield && field && | 614 | |
601 | field->physical) { | 615 | if (collection->type == HID_COLLECTION_PHYSICAL) { |
616 | |||
617 | hsdev = kzalloc(sizeof(*hsdev), GFP_KERNEL); | ||
618 | if (!hsdev) { | ||
619 | hid_err(hdev, "cannot allocate hid_sensor_hub_device\n"); | ||
620 | ret = -ENOMEM; | ||
621 | goto err_no_mem; | ||
622 | } | ||
623 | hsdev->hdev = hdev; | ||
624 | hsdev->vendor_id = hdev->vendor; | ||
625 | hsdev->product_id = hdev->product; | ||
626 | hsdev->start_collection_index = i; | ||
627 | if (last_hsdev) | ||
628 | last_hsdev->end_collection_index = i; | ||
629 | last_hsdev = hsdev; | ||
602 | name = kasprintf(GFP_KERNEL, "HID-SENSOR-%x", | 630 | name = kasprintf(GFP_KERNEL, "HID-SENSOR-%x", |
603 | field->physical); | 631 | collection->usage); |
604 | if (name == NULL) { | 632 | if (name == NULL) { |
605 | hid_err(hdev, "Failed MFD device name\n"); | 633 | hid_err(hdev, "Failed MFD device name\n"); |
606 | ret = -ENOMEM; | 634 | ret = -ENOMEM; |
607 | goto err_free_names; | 635 | goto err_no_mem; |
608 | } | 636 | } |
609 | sd->hid_sensor_hub_client_devs[ | 637 | sd->hid_sensor_hub_client_devs[ |
610 | sd->hid_sensor_client_cnt].id = PLATFORM_DEVID_AUTO; | 638 | sd->hid_sensor_client_cnt].id = |
639 | PLATFORM_DEVID_AUTO; | ||
611 | sd->hid_sensor_hub_client_devs[ | 640 | sd->hid_sensor_hub_client_devs[ |
612 | sd->hid_sensor_client_cnt].name = name; | 641 | sd->hid_sensor_client_cnt].name = name; |
613 | sd->hid_sensor_hub_client_devs[ | 642 | sd->hid_sensor_hub_client_devs[ |
614 | sd->hid_sensor_client_cnt].platform_data = | 643 | sd->hid_sensor_client_cnt].platform_data = |
615 | sd->hsdev; | 644 | hsdev; |
616 | sd->hid_sensor_hub_client_devs[ | 645 | sd->hid_sensor_hub_client_devs[ |
617 | sd->hid_sensor_client_cnt].pdata_size = | 646 | sd->hid_sensor_client_cnt].pdata_size = |
618 | sizeof(*sd->hsdev); | 647 | sizeof(*hsdev); |
619 | hid_dbg(hdev, "Adding %s:%p\n", name, sd); | 648 | hid_dbg(hdev, "Adding %s:%d\n", name, |
649 | hsdev->start_collection_index); | ||
620 | sd->hid_sensor_client_cnt++; | 650 | sd->hid_sensor_client_cnt++; |
621 | } | 651 | } |
622 | } | 652 | } |
653 | if (last_hsdev) | ||
654 | last_hsdev->end_collection_index = i; | ||
655 | |||
623 | ret = mfd_add_devices(&hdev->dev, 0, sd->hid_sensor_hub_client_devs, | 656 | ret = mfd_add_devices(&hdev->dev, 0, sd->hid_sensor_hub_client_devs, |
624 | sd->hid_sensor_client_cnt, NULL, 0, NULL); | 657 | sd->hid_sensor_client_cnt, NULL, 0, NULL); |
625 | if (ret < 0) | 658 | if (ret < 0) |
626 | goto err_free_names; | 659 | goto err_no_mem; |
627 | 660 | ||
628 | return ret; | 661 | return ret; |
629 | 662 | ||
630 | err_free_names: | 663 | err_no_mem: |
631 | for (i = 0; i < sd->hid_sensor_client_cnt ; ++i) | 664 | for (i = 0; i < sd->hid_sensor_client_cnt; ++i) { |
632 | kfree(sd->hid_sensor_hub_client_devs[i].name); | 665 | kfree(sd->hid_sensor_hub_client_devs[i].name); |
666 | kfree(sd->hid_sensor_hub_client_devs[i].platform_data); | ||
667 | } | ||
633 | kfree(sd->hid_sensor_hub_client_devs); | 668 | kfree(sd->hid_sensor_hub_client_devs); |
634 | err_stop_hw: | 669 | err_stop_hw: |
635 | hid_hw_stop(hdev); | 670 | hid_hw_stop(hdev); |
@@ -651,8 +686,10 @@ static void sensor_hub_remove(struct hid_device *hdev) | |||
651 | complete(&data->pending.ready); | 686 | complete(&data->pending.ready); |
652 | spin_unlock_irqrestore(&data->lock, flags); | 687 | spin_unlock_irqrestore(&data->lock, flags); |
653 | mfd_remove_devices(&hdev->dev); | 688 | mfd_remove_devices(&hdev->dev); |
654 | for (i = 0; i < data->hid_sensor_client_cnt ; ++i) | 689 | for (i = 0; i < data->hid_sensor_client_cnt; ++i) { |
655 | kfree(data->hid_sensor_hub_client_devs[i].name); | 690 | kfree(data->hid_sensor_hub_client_devs[i].name); |
691 | kfree(data->hid_sensor_hub_client_devs[i].platform_data); | ||
692 | } | ||
656 | kfree(data->hid_sensor_hub_client_devs); | 693 | kfree(data->hid_sensor_hub_client_devs); |
657 | hid_set_drvdata(hdev, NULL); | 694 | hid_set_drvdata(hdev, NULL); |
658 | mutex_destroy(&data->mutex); | 695 | mutex_destroy(&data->mutex); |
@@ -665,6 +702,9 @@ static const struct hid_device_id sensor_hub_devices[] = { | |||
665 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_INTEL_1, | 702 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_INTEL_1, |
666 | USB_DEVICE_ID_INTEL_HID_SENSOR), | 703 | USB_DEVICE_ID_INTEL_HID_SENSOR), |
667 | .driver_data = HID_SENSOR_HUB_ENUM_QUIRK}, | 704 | .driver_data = HID_SENSOR_HUB_ENUM_QUIRK}, |
705 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, USB_VENDOR_ID_STM_0, | ||
706 | USB_DEVICE_ID_STM_HID_SENSOR), | ||
707 | .driver_data = HID_SENSOR_HUB_ENUM_QUIRK}, | ||
668 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, HID_ANY_ID, | 708 | { HID_DEVICE(HID_BUS_ANY, HID_GROUP_SENSOR_HUB, HID_ANY_ID, |
669 | HID_ANY_ID) }, | 709 | HID_ANY_ID) }, |
670 | { } | 710 | { } |
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 12354055d474..b3e82585309e 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c | |||
@@ -17,7 +17,8 @@ | |||
17 | * any later version. | 17 | * any later version. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | /* NOTE: in order for the Sony PS3 BD Remote Control to be found by | 20 | /* |
21 | * NOTE: in order for the Sony PS3 BD Remote Control to be found by | ||
21 | * a Bluetooth host, the key combination Start+Enter has to be kept pressed | 22 | * a Bluetooth host, the key combination Start+Enter has to be kept pressed |
22 | * for about 7 seconds with the Bluetooth Host Controller in discovering mode. | 23 | * for about 7 seconds with the Bluetooth Host Controller in discovering mode. |
23 | * | 24 | * |
@@ -28,8 +29,11 @@ | |||
28 | #include <linux/hid.h> | 29 | #include <linux/hid.h> |
29 | #include <linux/module.h> | 30 | #include <linux/module.h> |
30 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
31 | #include <linux/usb.h> | ||
32 | #include <linux/leds.h> | 32 | #include <linux/leds.h> |
33 | #include <linux/power_supply.h> | ||
34 | #include <linux/spinlock.h> | ||
35 | #include <linux/list.h> | ||
36 | #include <linux/input/mt.h> | ||
33 | 37 | ||
34 | #include "hid-ids.h" | 38 | #include "hid-ids.h" |
35 | 39 | ||
@@ -41,7 +45,13 @@ | |||
41 | #define DUALSHOCK4_CONTROLLER_USB BIT(5) | 45 | #define DUALSHOCK4_CONTROLLER_USB BIT(5) |
42 | #define DUALSHOCK4_CONTROLLER_BT BIT(6) | 46 | #define DUALSHOCK4_CONTROLLER_BT BIT(6) |
43 | 47 | ||
44 | #define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER_USB | BUZZ_CONTROLLER | DUALSHOCK4_CONTROLLER_USB) | 48 | #define SIXAXIS_CONTROLLER (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT) |
49 | #define DUALSHOCK4_CONTROLLER (DUALSHOCK4_CONTROLLER_USB |\ | ||
50 | DUALSHOCK4_CONTROLLER_BT) | ||
51 | #define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER | BUZZ_CONTROLLER |\ | ||
52 | DUALSHOCK4_CONTROLLER) | ||
53 | #define SONY_BATTERY_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER) | ||
54 | #define SONY_FF_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER) | ||
45 | 55 | ||
46 | #define MAX_LEDS 4 | 56 | #define MAX_LEDS 4 |
47 | 57 | ||
@@ -73,7 +83,8 @@ static const u8 sixaxis_rdesc_fixup2[] = { | |||
73 | 0xb1, 0x02, 0xc0, 0xc0, | 83 | 0xb1, 0x02, 0xc0, 0xc0, |
74 | }; | 84 | }; |
75 | 85 | ||
76 | /* The default descriptor doesn't provide mapping for the accelerometers | 86 | /* |
87 | * The default descriptor doesn't provide mapping for the accelerometers | ||
77 | * or orientation sensors. This fixed descriptor maps the accelerometers | 88 | * or orientation sensors. This fixed descriptor maps the accelerometers |
78 | * to usage values 0x40, 0x41 and 0x42 and maps the orientation sensors | 89 | * to usage values 0x40, 0x41 and 0x42 and maps the orientation sensors |
79 | * to usage values 0x43, 0x44 and 0x45. | 90 | * to usage values 0x43, 0x44 and 0x45. |
@@ -332,6 +343,217 @@ static u8 dualshock4_usb_rdesc[] = { | |||
332 | 0xC0 /* End Collection */ | 343 | 0xC0 /* End Collection */ |
333 | }; | 344 | }; |
334 | 345 | ||
346 | /* | ||
347 | * The default behavior of the Dualshock 4 is to send reports using report | ||
348 | * type 1 when running over Bluetooth. However, as soon as it receives a | ||
349 | * report of type 17 to set the LEDs or rumble it starts returning it's state | ||
350 | * in report 17 instead of 1. Since report 17 is undefined in the default HID | ||
351 | * descriptor the button and axis definitions must be moved to report 17 or | ||
352 | * the HID layer won't process the received input once a report is sent. | ||
353 | */ | ||
354 | static u8 dualshock4_bt_rdesc[] = { | ||
355 | 0x05, 0x01, /* Usage Page (Desktop), */ | ||
356 | 0x09, 0x05, /* Usage (Gamepad), */ | ||
357 | 0xA1, 0x01, /* Collection (Application), */ | ||
358 | 0x85, 0x01, /* Report ID (1), */ | ||
359 | 0x75, 0x08, /* Report Size (8), */ | ||
360 | 0x95, 0x0A, /* Report Count (9), */ | ||
361 | 0x81, 0x02, /* Input (Variable), */ | ||
362 | 0x06, 0x04, 0xFF, /* Usage Page (FF04h), */ | ||
363 | 0x85, 0x02, /* Report ID (2), */ | ||
364 | 0x09, 0x24, /* Usage (24h), */ | ||
365 | 0x95, 0x24, /* Report Count (36), */ | ||
366 | 0xB1, 0x02, /* Feature (Variable), */ | ||
367 | 0x85, 0xA3, /* Report ID (163), */ | ||
368 | 0x09, 0x25, /* Usage (25h), */ | ||
369 | 0x95, 0x30, /* Report Count (48), */ | ||
370 | 0xB1, 0x02, /* Feature (Variable), */ | ||
371 | 0x85, 0x05, /* Report ID (5), */ | ||
372 | 0x09, 0x26, /* Usage (26h), */ | ||
373 | 0x95, 0x28, /* Report Count (40), */ | ||
374 | 0xB1, 0x02, /* Feature (Variable), */ | ||
375 | 0x85, 0x06, /* Report ID (6), */ | ||
376 | 0x09, 0x27, /* Usage (27h), */ | ||
377 | 0x95, 0x34, /* Report Count (52), */ | ||
378 | 0xB1, 0x02, /* Feature (Variable), */ | ||
379 | 0x85, 0x07, /* Report ID (7), */ | ||
380 | 0x09, 0x28, /* Usage (28h), */ | ||
381 | 0x95, 0x30, /* Report Count (48), */ | ||
382 | 0xB1, 0x02, /* Feature (Variable), */ | ||
383 | 0x85, 0x08, /* Report ID (8), */ | ||
384 | 0x09, 0x29, /* Usage (29h), */ | ||
385 | 0x95, 0x2F, /* Report Count (47), */ | ||
386 | 0xB1, 0x02, /* Feature (Variable), */ | ||
387 | 0x06, 0x03, 0xFF, /* Usage Page (FF03h), */ | ||
388 | 0x85, 0x03, /* Report ID (3), */ | ||
389 | 0x09, 0x21, /* Usage (21h), */ | ||
390 | 0x95, 0x26, /* Report Count (38), */ | ||
391 | 0xB1, 0x02, /* Feature (Variable), */ | ||
392 | 0x85, 0x04, /* Report ID (4), */ | ||
393 | 0x09, 0x22, /* Usage (22h), */ | ||
394 | 0x95, 0x2E, /* Report Count (46), */ | ||
395 | 0xB1, 0x02, /* Feature (Variable), */ | ||
396 | 0x85, 0xF0, /* Report ID (240), */ | ||
397 | 0x09, 0x47, /* Usage (47h), */ | ||
398 | 0x95, 0x3F, /* Report Count (63), */ | ||
399 | 0xB1, 0x02, /* Feature (Variable), */ | ||
400 | 0x85, 0xF1, /* Report ID (241), */ | ||
401 | 0x09, 0x48, /* Usage (48h), */ | ||
402 | 0x95, 0x3F, /* Report Count (63), */ | ||
403 | 0xB1, 0x02, /* Feature (Variable), */ | ||
404 | 0x85, 0xF2, /* Report ID (242), */ | ||
405 | 0x09, 0x49, /* Usage (49h), */ | ||
406 | 0x95, 0x0F, /* Report Count (15), */ | ||
407 | 0xB1, 0x02, /* Feature (Variable), */ | ||
408 | 0x85, 0x11, /* Report ID (17), */ | ||
409 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ | ||
410 | 0x09, 0x20, /* Usage (20h), */ | ||
411 | 0x95, 0x02, /* Report Count (2), */ | ||
412 | 0x81, 0x02, /* Input (Variable), */ | ||
413 | 0x05, 0x01, /* Usage Page (Desktop), */ | ||
414 | 0x09, 0x30, /* Usage (X), */ | ||
415 | 0x09, 0x31, /* Usage (Y), */ | ||
416 | 0x09, 0x32, /* Usage (Z), */ | ||
417 | 0x09, 0x35, /* Usage (Rz), */ | ||
418 | 0x15, 0x00, /* Logical Minimum (0), */ | ||
419 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ | ||
420 | 0x75, 0x08, /* Report Size (8), */ | ||
421 | 0x95, 0x04, /* Report Count (4), */ | ||
422 | 0x81, 0x02, /* Input (Variable), */ | ||
423 | 0x09, 0x39, /* Usage (Hat Switch), */ | ||
424 | 0x15, 0x00, /* Logical Minimum (0), */ | ||
425 | 0x25, 0x07, /* Logical Maximum (7), */ | ||
426 | 0x75, 0x04, /* Report Size (4), */ | ||
427 | 0x95, 0x01, /* Report Count (1), */ | ||
428 | 0x81, 0x42, /* Input (Variable, Null State), */ | ||
429 | 0x05, 0x09, /* Usage Page (Button), */ | ||
430 | 0x19, 0x01, /* Usage Minimum (01h), */ | ||
431 | 0x29, 0x0E, /* Usage Maximum (0Eh), */ | ||
432 | 0x15, 0x00, /* Logical Minimum (0), */ | ||
433 | 0x25, 0x01, /* Logical Maximum (1), */ | ||
434 | 0x75, 0x01, /* Report Size (1), */ | ||
435 | 0x95, 0x0E, /* Report Count (14), */ | ||
436 | 0x81, 0x02, /* Input (Variable), */ | ||
437 | 0x75, 0x06, /* Report Size (6), */ | ||
438 | 0x95, 0x01, /* Report Count (1), */ | ||
439 | 0x81, 0x01, /* Input (Constant), */ | ||
440 | 0x05, 0x01, /* Usage Page (Desktop), */ | ||
441 | 0x09, 0x33, /* Usage (Rx), */ | ||
442 | 0x09, 0x34, /* Usage (Ry), */ | ||
443 | 0x15, 0x00, /* Logical Minimum (0), */ | ||
444 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ | ||
445 | 0x75, 0x08, /* Report Size (8), */ | ||
446 | 0x95, 0x02, /* Report Count (2), */ | ||
447 | 0x81, 0x02, /* Input (Variable), */ | ||
448 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ | ||
449 | 0x09, 0x20, /* Usage (20h), */ | ||
450 | 0x95, 0x03, /* Report Count (3), */ | ||
451 | 0x81, 0x02, /* Input (Variable), */ | ||
452 | 0x05, 0x01, /* Usage Page (Desktop), */ | ||
453 | 0x19, 0x40, /* Usage Minimum (40h), */ | ||
454 | 0x29, 0x42, /* Usage Maximum (42h), */ | ||
455 | 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */ | ||
456 | 0x26, 0x00, 0x7F, /* Logical Maximum (32767), */ | ||
457 | 0x75, 0x10, /* Report Size (16), */ | ||
458 | 0x95, 0x03, /* Report Count (3), */ | ||
459 | 0x81, 0x02, /* Input (Variable), */ | ||
460 | 0x19, 0x43, /* Usage Minimum (43h), */ | ||
461 | 0x29, 0x45, /* Usage Maximum (45h), */ | ||
462 | 0x16, 0xFF, 0xBF, /* Logical Minimum (-16385), */ | ||
463 | 0x26, 0x00, 0x40, /* Logical Maximum (16384), */ | ||
464 | 0x95, 0x03, /* Report Count (3), */ | ||
465 | 0x81, 0x02, /* Input (Variable), */ | ||
466 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ | ||
467 | 0x09, 0x20, /* Usage (20h), */ | ||
468 | 0x15, 0x00, /* Logical Minimum (0), */ | ||
469 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ | ||
470 | 0x75, 0x08, /* Report Size (8), */ | ||
471 | 0x95, 0x31, /* Report Count (51), */ | ||
472 | 0x81, 0x02, /* Input (Variable), */ | ||
473 | 0x09, 0x21, /* Usage (21h), */ | ||
474 | 0x75, 0x08, /* Report Size (8), */ | ||
475 | 0x95, 0x4D, /* Report Count (77), */ | ||
476 | 0x91, 0x02, /* Output (Variable), */ | ||
477 | 0x85, 0x12, /* Report ID (18), */ | ||
478 | 0x09, 0x22, /* Usage (22h), */ | ||
479 | 0x95, 0x8D, /* Report Count (141), */ | ||
480 | 0x81, 0x02, /* Input (Variable), */ | ||
481 | 0x09, 0x23, /* Usage (23h), */ | ||
482 | 0x91, 0x02, /* Output (Variable), */ | ||
483 | 0x85, 0x13, /* Report ID (19), */ | ||
484 | 0x09, 0x24, /* Usage (24h), */ | ||
485 | 0x95, 0xCD, /* Report Count (205), */ | ||
486 | 0x81, 0x02, /* Input (Variable), */ | ||
487 | 0x09, 0x25, /* Usage (25h), */ | ||
488 | 0x91, 0x02, /* Output (Variable), */ | ||
489 | 0x85, 0x14, /* Report ID (20), */ | ||
490 | 0x09, 0x26, /* Usage (26h), */ | ||
491 | 0x96, 0x0D, 0x01, /* Report Count (269), */ | ||
492 | 0x81, 0x02, /* Input (Variable), */ | ||
493 | 0x09, 0x27, /* Usage (27h), */ | ||
494 | 0x91, 0x02, /* Output (Variable), */ | ||
495 | 0x85, 0x15, /* Report ID (21), */ | ||
496 | 0x09, 0x28, /* Usage (28h), */ | ||
497 | 0x96, 0x4D, 0x01, /* Report Count (333), */ | ||
498 | 0x81, 0x02, /* Input (Variable), */ | ||
499 | 0x09, 0x29, /* Usage (29h), */ | ||
500 | 0x91, 0x02, /* Output (Variable), */ | ||
501 | 0x85, 0x16, /* Report ID (22), */ | ||
502 | 0x09, 0x2A, /* Usage (2Ah), */ | ||
503 | 0x96, 0x8D, 0x01, /* Report Count (397), */ | ||
504 | 0x81, 0x02, /* Input (Variable), */ | ||
505 | 0x09, 0x2B, /* Usage (2Bh), */ | ||
506 | 0x91, 0x02, /* Output (Variable), */ | ||
507 | 0x85, 0x17, /* Report ID (23), */ | ||
508 | 0x09, 0x2C, /* Usage (2Ch), */ | ||
509 | 0x96, 0xCD, 0x01, /* Report Count (461), */ | ||
510 | 0x81, 0x02, /* Input (Variable), */ | ||
511 | 0x09, 0x2D, /* Usage (2Dh), */ | ||
512 | 0x91, 0x02, /* Output (Variable), */ | ||
513 | 0x85, 0x18, /* Report ID (24), */ | ||
514 | 0x09, 0x2E, /* Usage (2Eh), */ | ||
515 | 0x96, 0x0D, 0x02, /* Report Count (525), */ | ||
516 | 0x81, 0x02, /* Input (Variable), */ | ||
517 | 0x09, 0x2F, /* Usage (2Fh), */ | ||
518 | 0x91, 0x02, /* Output (Variable), */ | ||
519 | 0x85, 0x19, /* Report ID (25), */ | ||
520 | 0x09, 0x30, /* Usage (30h), */ | ||
521 | 0x96, 0x22, 0x02, /* Report Count (546), */ | ||
522 | 0x81, 0x02, /* Input (Variable), */ | ||
523 | 0x09, 0x31, /* Usage (31h), */ | ||
524 | 0x91, 0x02, /* Output (Variable), */ | ||
525 | 0x06, 0x80, 0xFF, /* Usage Page (FF80h), */ | ||
526 | 0x85, 0x82, /* Report ID (130), */ | ||
527 | 0x09, 0x22, /* Usage (22h), */ | ||
528 | 0x95, 0x3F, /* Report Count (63), */ | ||
529 | 0xB1, 0x02, /* Feature (Variable), */ | ||
530 | 0x85, 0x83, /* Report ID (131), */ | ||
531 | 0x09, 0x23, /* Usage (23h), */ | ||
532 | 0xB1, 0x02, /* Feature (Variable), */ | ||
533 | 0x85, 0x84, /* Report ID (132), */ | ||
534 | 0x09, 0x24, /* Usage (24h), */ | ||
535 | 0xB1, 0x02, /* Feature (Variable), */ | ||
536 | 0x85, 0x90, /* Report ID (144), */ | ||
537 | 0x09, 0x30, /* Usage (30h), */ | ||
538 | 0xB1, 0x02, /* Feature (Variable), */ | ||
539 | 0x85, 0x91, /* Report ID (145), */ | ||
540 | 0x09, 0x31, /* Usage (31h), */ | ||
541 | 0xB1, 0x02, /* Feature (Variable), */ | ||
542 | 0x85, 0x92, /* Report ID (146), */ | ||
543 | 0x09, 0x32, /* Usage (32h), */ | ||
544 | 0xB1, 0x02, /* Feature (Variable), */ | ||
545 | 0x85, 0x93, /* Report ID (147), */ | ||
546 | 0x09, 0x33, /* Usage (33h), */ | ||
547 | 0xB1, 0x02, /* Feature (Variable), */ | ||
548 | 0x85, 0xA0, /* Report ID (160), */ | ||
549 | 0x09, 0x40, /* Usage (40h), */ | ||
550 | 0xB1, 0x02, /* Feature (Variable), */ | ||
551 | 0x85, 0xA4, /* Report ID (164), */ | ||
552 | 0x09, 0x44, /* Usage (44h), */ | ||
553 | 0xB1, 0x02, /* Feature (Variable), */ | ||
554 | 0xC0 /* End Collection */ | ||
555 | }; | ||
556 | |||
335 | static __u8 ps3remote_rdesc[] = { | 557 | static __u8 ps3remote_rdesc[] = { |
336 | 0x05, 0x01, /* GUsagePage Generic Desktop */ | 558 | 0x05, 0x01, /* GUsagePage Generic Desktop */ |
337 | 0x09, 0x05, /* LUsage 0x05 [Game Pad] */ | 559 | 0x09, 0x05, /* LUsage 0x05 [Game Pad] */ |
@@ -449,7 +671,8 @@ static const unsigned int ps3remote_keymap_remote_buttons[] = { | |||
449 | }; | 671 | }; |
450 | 672 | ||
451 | static const unsigned int buzz_keymap[] = { | 673 | static const unsigned int buzz_keymap[] = { |
452 | /* The controller has 4 remote buzzers, each with one LED and 5 | 674 | /* |
675 | * The controller has 4 remote buzzers, each with one LED and 5 | ||
453 | * buttons. | 676 | * buttons. |
454 | * | 677 | * |
455 | * We use the mapping chosen by the controller, which is: | 678 | * We use the mapping chosen by the controller, which is: |
@@ -487,18 +710,35 @@ static const unsigned int buzz_keymap[] = { | |||
487 | [20] = BTN_TRIGGER_HAPPY20, | 710 | [20] = BTN_TRIGGER_HAPPY20, |
488 | }; | 711 | }; |
489 | 712 | ||
713 | static enum power_supply_property sony_battery_props[] = { | ||
714 | POWER_SUPPLY_PROP_PRESENT, | ||
715 | POWER_SUPPLY_PROP_CAPACITY, | ||
716 | POWER_SUPPLY_PROP_SCOPE, | ||
717 | POWER_SUPPLY_PROP_STATUS, | ||
718 | }; | ||
719 | |||
720 | static spinlock_t sony_dev_list_lock; | ||
721 | static LIST_HEAD(sony_device_list); | ||
722 | |||
490 | struct sony_sc { | 723 | struct sony_sc { |
724 | spinlock_t lock; | ||
725 | struct list_head list_node; | ||
491 | struct hid_device *hdev; | 726 | struct hid_device *hdev; |
492 | struct led_classdev *leds[MAX_LEDS]; | 727 | struct led_classdev *leds[MAX_LEDS]; |
493 | struct hid_report *output_report; | ||
494 | unsigned long quirks; | 728 | unsigned long quirks; |
495 | struct work_struct state_worker; | 729 | struct work_struct state_worker; |
730 | struct power_supply battery; | ||
496 | 731 | ||
497 | #ifdef CONFIG_SONY_FF | 732 | #ifdef CONFIG_SONY_FF |
498 | __u8 left; | 733 | __u8 left; |
499 | __u8 right; | 734 | __u8 right; |
500 | #endif | 735 | #endif |
501 | 736 | ||
737 | __u8 mac_address[6]; | ||
738 | __u8 worker_initialized; | ||
739 | __u8 cable_state; | ||
740 | __u8 battery_charging; | ||
741 | __u8 battery_capacity; | ||
502 | __u8 led_state[MAX_LEDS]; | 742 | __u8 led_state[MAX_LEDS]; |
503 | __u8 led_count; | 743 | __u8 led_count; |
504 | }; | 744 | }; |
@@ -576,6 +816,10 @@ static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc, | |||
576 | hid_info(hdev, "Using modified Dualshock 4 report descriptor with gyroscope axes\n"); | 816 | hid_info(hdev, "Using modified Dualshock 4 report descriptor with gyroscope axes\n"); |
577 | rdesc = dualshock4_usb_rdesc; | 817 | rdesc = dualshock4_usb_rdesc; |
578 | *rsize = sizeof(dualshock4_usb_rdesc); | 818 | *rsize = sizeof(dualshock4_usb_rdesc); |
819 | } else if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) && *rsize == 357) { | ||
820 | hid_info(hdev, "Using modified Dualshock 4 Bluetooth report descriptor\n"); | ||
821 | rdesc = dualshock4_bt_rdesc; | ||
822 | *rsize = sizeof(dualshock4_bt_rdesc); | ||
579 | } | 823 | } |
580 | 824 | ||
581 | /* The HID descriptor exposed over BT has a trailing zero byte */ | 825 | /* The HID descriptor exposed over BT has a trailing zero byte */ |
@@ -599,20 +843,127 @@ static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc, | |||
599 | return rdesc; | 843 | return rdesc; |
600 | } | 844 | } |
601 | 845 | ||
846 | static void sixaxis_parse_report(struct sony_sc *sc, __u8 *rd, int size) | ||
847 | { | ||
848 | static const __u8 sixaxis_battery_capacity[] = { 0, 1, 25, 50, 75, 100 }; | ||
849 | unsigned long flags; | ||
850 | __u8 cable_state, battery_capacity, battery_charging; | ||
851 | |||
852 | /* | ||
853 | * The sixaxis is charging if the battery value is 0xee | ||
854 | * and it is fully charged if the value is 0xef. | ||
855 | * It does not report the actual level while charging so it | ||
856 | * is set to 100% while charging is in progress. | ||
857 | */ | ||
858 | if (rd[30] >= 0xee) { | ||
859 | battery_capacity = 100; | ||
860 | battery_charging = !(rd[30] & 0x01); | ||
861 | } else { | ||
862 | __u8 index = rd[30] <= 5 ? rd[30] : 5; | ||
863 | battery_capacity = sixaxis_battery_capacity[index]; | ||
864 | battery_charging = 0; | ||
865 | } | ||
866 | cable_state = !((rd[31] >> 4) & 0x01); | ||
867 | |||
868 | spin_lock_irqsave(&sc->lock, flags); | ||
869 | sc->cable_state = cable_state; | ||
870 | sc->battery_capacity = battery_capacity; | ||
871 | sc->battery_charging = battery_charging; | ||
872 | spin_unlock_irqrestore(&sc->lock, flags); | ||
873 | } | ||
874 | |||
875 | static void dualshock4_parse_report(struct sony_sc *sc, __u8 *rd, int size) | ||
876 | { | ||
877 | struct hid_input *hidinput = list_entry(sc->hdev->inputs.next, | ||
878 | struct hid_input, list); | ||
879 | struct input_dev *input_dev = hidinput->input; | ||
880 | unsigned long flags; | ||
881 | int n, offset; | ||
882 | __u8 cable_state, battery_capacity, battery_charging; | ||
883 | |||
884 | /* | ||
885 | * Battery and touchpad data starts at byte 30 in the USB report and | ||
886 | * 32 in Bluetooth report. | ||
887 | */ | ||
888 | offset = (sc->quirks & DUALSHOCK4_CONTROLLER_USB) ? 30 : 32; | ||
889 | |||
890 | /* | ||
891 | * The lower 4 bits of byte 30 contain the battery level | ||
892 | * and the 5th bit contains the USB cable state. | ||
893 | */ | ||
894 | cable_state = (rd[offset] >> 4) & 0x01; | ||
895 | battery_capacity = rd[offset] & 0x0F; | ||
896 | |||
897 | /* | ||
898 | * When a USB power source is connected the battery level ranges from | ||
899 | * 0 to 10, and when running on battery power it ranges from 0 to 9. | ||
900 | * A battery level above 10 when plugged in means charge completed. | ||
901 | */ | ||
902 | if (!cable_state || battery_capacity > 10) | ||
903 | battery_charging = 0; | ||
904 | else | ||
905 | battery_charging = 1; | ||
906 | |||
907 | if (!cable_state) | ||
908 | battery_capacity++; | ||
909 | if (battery_capacity > 10) | ||
910 | battery_capacity = 10; | ||
911 | |||
912 | battery_capacity *= 10; | ||
913 | |||
914 | spin_lock_irqsave(&sc->lock, flags); | ||
915 | sc->cable_state = cable_state; | ||
916 | sc->battery_capacity = battery_capacity; | ||
917 | sc->battery_charging = battery_charging; | ||
918 | spin_unlock_irqrestore(&sc->lock, flags); | ||
919 | |||
920 | offset += 5; | ||
921 | |||
922 | /* | ||
923 | * The Dualshock 4 multi-touch trackpad data starts at offset 35 on USB | ||
924 | * and 37 on Bluetooth. | ||
925 | * The first 7 bits of the first byte is a counter and bit 8 is a touch | ||
926 | * indicator that is 0 when pressed and 1 when not pressed. | ||
927 | * The next 3 bytes are two 12 bit touch coordinates, X and Y. | ||
928 | * The data for the second touch is in the same format and immediatly | ||
929 | * follows the data for the first. | ||
930 | */ | ||
931 | for (n = 0; n < 2; n++) { | ||
932 | __u16 x, y; | ||
933 | |||
934 | x = rd[offset+1] | ((rd[offset+2] & 0xF) << 8); | ||
935 | y = ((rd[offset+2] & 0xF0) >> 4) | (rd[offset+3] << 4); | ||
936 | |||
937 | input_mt_slot(input_dev, n); | ||
938 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, | ||
939 | !(rd[offset] >> 7)); | ||
940 | input_report_abs(input_dev, ABS_MT_POSITION_X, x); | ||
941 | input_report_abs(input_dev, ABS_MT_POSITION_Y, y); | ||
942 | |||
943 | offset += 4; | ||
944 | } | ||
945 | } | ||
946 | |||
602 | static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, | 947 | static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, |
603 | __u8 *rd, int size) | 948 | __u8 *rd, int size) |
604 | { | 949 | { |
605 | struct sony_sc *sc = hid_get_drvdata(hdev); | 950 | struct sony_sc *sc = hid_get_drvdata(hdev); |
606 | 951 | ||
607 | /* Sixaxis HID report has acclerometers/gyro with MSByte first, this | 952 | /* |
953 | * Sixaxis HID report has acclerometers/gyro with MSByte first, this | ||
608 | * has to be BYTE_SWAPPED before passing up to joystick interface | 954 | * has to be BYTE_SWAPPED before passing up to joystick interface |
609 | */ | 955 | */ |
610 | if ((sc->quirks & (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT)) && | 956 | if ((sc->quirks & SIXAXIS_CONTROLLER) && rd[0] == 0x01 && size == 49) { |
611 | rd[0] == 0x01 && size == 49) { | ||
612 | swap(rd[41], rd[42]); | 957 | swap(rd[41], rd[42]); |
613 | swap(rd[43], rd[44]); | 958 | swap(rd[43], rd[44]); |
614 | swap(rd[45], rd[46]); | 959 | swap(rd[45], rd[46]); |
615 | swap(rd[47], rd[48]); | 960 | swap(rd[47], rd[48]); |
961 | |||
962 | sixaxis_parse_report(sc, rd, size); | ||
963 | } else if (((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && rd[0] == 0x01 && | ||
964 | size == 64) || ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) | ||
965 | && rd[0] == 0x11 && size == 78)) { | ||
966 | dualshock4_parse_report(sc, rd, size); | ||
616 | } | 967 | } |
617 | 968 | ||
618 | return 0; | 969 | return 0; |
@@ -655,45 +1006,6 @@ static int sony_mapping(struct hid_device *hdev, struct hid_input *hi, | |||
655 | } | 1006 | } |
656 | 1007 | ||
657 | /* | 1008 | /* |
658 | * The Sony Sixaxis does not handle HID Output Reports on the Interrupt EP | ||
659 | * like it should according to usbhid/hid-core.c::usbhid_output_raw_report() | ||
660 | * so we need to override that forcing HID Output Reports on the Control EP. | ||
661 | * | ||
662 | * There is also another issue about HID Output Reports via USB, the Sixaxis | ||
663 | * does not want the report_id as part of the data packet, so we have to | ||
664 | * discard buf[0] when sending the actual control message, even for numbered | ||
665 | * reports, humpf! | ||
666 | */ | ||
667 | static int sixaxis_usb_output_raw_report(struct hid_device *hid, __u8 *buf, | ||
668 | size_t count, unsigned char report_type) | ||
669 | { | ||
670 | struct usb_interface *intf = to_usb_interface(hid->dev.parent); | ||
671 | struct usb_device *dev = interface_to_usbdev(intf); | ||
672 | struct usb_host_interface *interface = intf->cur_altsetting; | ||
673 | int report_id = buf[0]; | ||
674 | int ret; | ||
675 | |||
676 | if (report_type == HID_OUTPUT_REPORT) { | ||
677 | /* Don't send the Report ID */ | ||
678 | buf++; | ||
679 | count--; | ||
680 | } | ||
681 | |||
682 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | ||
683 | HID_REQ_SET_REPORT, | ||
684 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | ||
685 | ((report_type + 1) << 8) | report_id, | ||
686 | interface->desc.bInterfaceNumber, buf, count, | ||
687 | USB_CTRL_SET_TIMEOUT); | ||
688 | |||
689 | /* Count also the Report ID, in case of an Output report. */ | ||
690 | if (ret > 0 && report_type == HID_OUTPUT_REPORT) | ||
691 | ret++; | ||
692 | |||
693 | return ret; | ||
694 | } | ||
695 | |||
696 | /* | ||
697 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller | 1009 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller |
698 | * to "operational". Without this, the ps3 controller will not report any | 1010 | * to "operational". Without this, the ps3 controller will not report any |
699 | * events. | 1011 | * events. |
@@ -706,7 +1018,8 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev) | |||
706 | if (!buf) | 1018 | if (!buf) |
707 | return -ENOMEM; | 1019 | return -ENOMEM; |
708 | 1020 | ||
709 | ret = hdev->hid_get_raw_report(hdev, 0xf2, buf, 17, HID_FEATURE_REPORT); | 1021 | ret = hid_hw_raw_request(hdev, 0xf2, buf, 17, HID_FEATURE_REPORT, |
1022 | HID_REQ_GET_REPORT); | ||
710 | 1023 | ||
711 | if (ret < 0) | 1024 | if (ret < 0) |
712 | hid_err(hdev, "can't set operational mode\n"); | 1025 | hid_err(hdev, "can't set operational mode\n"); |
@@ -719,7 +1032,20 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev) | |||
719 | static int sixaxis_set_operational_bt(struct hid_device *hdev) | 1032 | static int sixaxis_set_operational_bt(struct hid_device *hdev) |
720 | { | 1033 | { |
721 | unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 }; | 1034 | unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 }; |
722 | return hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT); | 1035 | return hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf), |
1036 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | ||
1037 | } | ||
1038 | |||
1039 | /* | ||
1040 | * Requesting feature report 0x02 in Bluetooth mode changes the state of the | ||
1041 | * controller so that it sends full input reports of type 0x11. | ||
1042 | */ | ||
1043 | static int dualshock4_set_operational_bt(struct hid_device *hdev) | ||
1044 | { | ||
1045 | __u8 buf[37] = { 0 }; | ||
1046 | |||
1047 | return hid_hw_raw_request(hdev, 0x02, buf, sizeof(buf), | ||
1048 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); | ||
723 | } | 1049 | } |
724 | 1050 | ||
725 | static void buzz_set_leds(struct hid_device *hdev, const __u8 *leds) | 1051 | static void buzz_set_leds(struct hid_device *hdev, const __u8 *leds) |
@@ -749,8 +1075,7 @@ static void sony_set_leds(struct hid_device *hdev, const __u8 *leds, int count) | |||
749 | 1075 | ||
750 | if (drv_data->quirks & BUZZ_CONTROLLER && count == 4) { | 1076 | if (drv_data->quirks & BUZZ_CONTROLLER && count == 4) { |
751 | buzz_set_leds(hdev, leds); | 1077 | buzz_set_leds(hdev, leds); |
752 | } else if ((drv_data->quirks & SIXAXIS_CONTROLLER_USB) || | 1078 | } else { |
753 | (drv_data->quirks & DUALSHOCK4_CONTROLLER_USB)) { | ||
754 | for (n = 0; n < count; n++) | 1079 | for (n = 0; n < count; n++) |
755 | drv_data->led_state[n] = leds[n]; | 1080 | drv_data->led_state[n] = leds[n]; |
756 | schedule_work(&drv_data->state_worker); | 1081 | schedule_work(&drv_data->state_worker); |
@@ -790,7 +1115,6 @@ static enum led_brightness sony_led_get_brightness(struct led_classdev *led) | |||
790 | struct sony_sc *drv_data; | 1115 | struct sony_sc *drv_data; |
791 | 1116 | ||
792 | int n; | 1117 | int n; |
793 | int on = 0; | ||
794 | 1118 | ||
795 | drv_data = hid_get_drvdata(hdev); | 1119 | drv_data = hid_get_drvdata(hdev); |
796 | if (!drv_data) { | 1120 | if (!drv_data) { |
@@ -799,13 +1123,11 @@ static enum led_brightness sony_led_get_brightness(struct led_classdev *led) | |||
799 | } | 1123 | } |
800 | 1124 | ||
801 | for (n = 0; n < drv_data->led_count; n++) { | 1125 | for (n = 0; n < drv_data->led_count; n++) { |
802 | if (led == drv_data->leds[n]) { | 1126 | if (led == drv_data->leds[n]) |
803 | on = !!(drv_data->led_state[n]); | 1127 | return drv_data->led_state[n]; |
804 | break; | ||
805 | } | ||
806 | } | 1128 | } |
807 | 1129 | ||
808 | return on ? LED_FULL : LED_OFF; | 1130 | return LED_OFF; |
809 | } | 1131 | } |
810 | 1132 | ||
811 | static void sony_leds_remove(struct hid_device *hdev) | 1133 | static void sony_leds_remove(struct hid_device *hdev) |
@@ -855,7 +1177,7 @@ static int sony_leds_init(struct hid_device *hdev) | |||
855 | /* Validate expected report characteristics. */ | 1177 | /* Validate expected report characteristics. */ |
856 | if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7)) | 1178 | if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7)) |
857 | return -ENODEV; | 1179 | return -ENODEV; |
858 | } else if (drv_data->quirks & DUALSHOCK4_CONTROLLER_USB) { | 1180 | } else if (drv_data->quirks & DUALSHOCK4_CONTROLLER) { |
859 | drv_data->led_count = 3; | 1181 | drv_data->led_count = 3; |
860 | max_brightness = 255; | 1182 | max_brightness = 255; |
861 | use_colors = 1; | 1183 | use_colors = 1; |
@@ -869,9 +1191,11 @@ static int sony_leds_init(struct hid_device *hdev) | |||
869 | name_fmt = "%s::sony%d"; | 1191 | name_fmt = "%s::sony%d"; |
870 | } | 1192 | } |
871 | 1193 | ||
872 | /* Clear LEDs as we have no way of reading their initial state. This is | 1194 | /* |
1195 | * Clear LEDs as we have no way of reading their initial state. This is | ||
873 | * only relevant if the driver is loaded after somebody actively set the | 1196 | * only relevant if the driver is loaded after somebody actively set the |
874 | * LEDs to on */ | 1197 | * LEDs to on |
1198 | */ | ||
875 | sony_set_leds(hdev, initial_values, drv_data->led_count); | 1199 | sony_set_leds(hdev, initial_values, drv_data->led_count); |
876 | 1200 | ||
877 | name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1; | 1201 | name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1; |
@@ -941,29 +1265,45 @@ static void sixaxis_state_worker(struct work_struct *work) | |||
941 | buf[10] |= sc->led_state[2] << 3; | 1265 | buf[10] |= sc->led_state[2] << 3; |
942 | buf[10] |= sc->led_state[3] << 4; | 1266 | buf[10] |= sc->led_state[3] << 4; |
943 | 1267 | ||
944 | sc->hdev->hid_output_raw_report(sc->hdev, buf, sizeof(buf), | 1268 | hid_hw_raw_request(sc->hdev, 0x01, buf, sizeof(buf), HID_OUTPUT_REPORT, |
945 | HID_OUTPUT_REPORT); | 1269 | HID_REQ_SET_REPORT); |
946 | } | 1270 | } |
947 | 1271 | ||
948 | static void dualshock4_state_worker(struct work_struct *work) | 1272 | static void dualshock4_state_worker(struct work_struct *work) |
949 | { | 1273 | { |
950 | struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); | 1274 | struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); |
951 | struct hid_device *hdev = sc->hdev; | 1275 | struct hid_device *hdev = sc->hdev; |
952 | struct hid_report *report = sc->output_report; | 1276 | int offset; |
953 | __s32 *value = report->field[0]->value; | ||
954 | 1277 | ||
955 | value[0] = 0x03; | 1278 | __u8 buf[78] = { 0 }; |
1279 | |||
1280 | if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) { | ||
1281 | buf[0] = 0x05; | ||
1282 | buf[1] = 0x03; | ||
1283 | offset = 4; | ||
1284 | } else { | ||
1285 | buf[0] = 0x11; | ||
1286 | buf[1] = 0xB0; | ||
1287 | buf[3] = 0x0F; | ||
1288 | offset = 6; | ||
1289 | } | ||
956 | 1290 | ||
957 | #ifdef CONFIG_SONY_FF | 1291 | #ifdef CONFIG_SONY_FF |
958 | value[3] = sc->right; | 1292 | buf[offset++] = sc->right; |
959 | value[4] = sc->left; | 1293 | buf[offset++] = sc->left; |
1294 | #else | ||
1295 | offset += 2; | ||
960 | #endif | 1296 | #endif |
961 | 1297 | ||
962 | value[5] = sc->led_state[0]; | 1298 | buf[offset++] = sc->led_state[0]; |
963 | value[6] = sc->led_state[1]; | 1299 | buf[offset++] = sc->led_state[1]; |
964 | value[7] = sc->led_state[2]; | 1300 | buf[offset++] = sc->led_state[2]; |
965 | 1301 | ||
966 | hid_hw_request(hdev, report, HID_REQ_SET_REPORT); | 1302 | if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) |
1303 | hid_hw_output_report(hdev, buf, 32); | ||
1304 | else | ||
1305 | hid_hw_raw_request(hdev, 0x11, buf, 78, | ||
1306 | HID_OUTPUT_REPORT, HID_REQ_SET_REPORT); | ||
967 | } | 1307 | } |
968 | 1308 | ||
969 | #ifdef CONFIG_SONY_FF | 1309 | #ifdef CONFIG_SONY_FF |
@@ -993,51 +1333,252 @@ static int sony_init_ff(struct hid_device *hdev) | |||
993 | return input_ff_create_memless(input_dev, NULL, sony_play_effect); | 1333 | return input_ff_create_memless(input_dev, NULL, sony_play_effect); |
994 | } | 1334 | } |
995 | 1335 | ||
996 | static void sony_destroy_ff(struct hid_device *hdev) | 1336 | #else |
1337 | static int sony_init_ff(struct hid_device *hdev) | ||
997 | { | 1338 | { |
998 | struct sony_sc *sc = hid_get_drvdata(hdev); | 1339 | return 0; |
1340 | } | ||
1341 | |||
1342 | #endif | ||
1343 | |||
1344 | static int sony_battery_get_property(struct power_supply *psy, | ||
1345 | enum power_supply_property psp, | ||
1346 | union power_supply_propval *val) | ||
1347 | { | ||
1348 | struct sony_sc *sc = container_of(psy, struct sony_sc, battery); | ||
1349 | unsigned long flags; | ||
1350 | int ret = 0; | ||
1351 | u8 battery_charging, battery_capacity, cable_state; | ||
1352 | |||
1353 | spin_lock_irqsave(&sc->lock, flags); | ||
1354 | battery_charging = sc->battery_charging; | ||
1355 | battery_capacity = sc->battery_capacity; | ||
1356 | cable_state = sc->cable_state; | ||
1357 | spin_unlock_irqrestore(&sc->lock, flags); | ||
1358 | |||
1359 | switch (psp) { | ||
1360 | case POWER_SUPPLY_PROP_PRESENT: | ||
1361 | val->intval = 1; | ||
1362 | break; | ||
1363 | case POWER_SUPPLY_PROP_SCOPE: | ||
1364 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; | ||
1365 | break; | ||
1366 | case POWER_SUPPLY_PROP_CAPACITY: | ||
1367 | val->intval = battery_capacity; | ||
1368 | break; | ||
1369 | case POWER_SUPPLY_PROP_STATUS: | ||
1370 | if (battery_charging) | ||
1371 | val->intval = POWER_SUPPLY_STATUS_CHARGING; | ||
1372 | else | ||
1373 | if (battery_capacity == 100 && cable_state) | ||
1374 | val->intval = POWER_SUPPLY_STATUS_FULL; | ||
1375 | else | ||
1376 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; | ||
1377 | break; | ||
1378 | default: | ||
1379 | ret = -EINVAL; | ||
1380 | break; | ||
1381 | } | ||
1382 | return ret; | ||
1383 | } | ||
1384 | |||
1385 | static int sony_battery_probe(struct sony_sc *sc) | ||
1386 | { | ||
1387 | static atomic_t power_id_seq = ATOMIC_INIT(0); | ||
1388 | unsigned long power_id; | ||
1389 | struct hid_device *hdev = sc->hdev; | ||
1390 | int ret; | ||
1391 | |||
1392 | /* | ||
1393 | * Set the default battery level to 100% to avoid low battery warnings | ||
1394 | * if the battery is polled before the first device report is received. | ||
1395 | */ | ||
1396 | sc->battery_capacity = 100; | ||
1397 | |||
1398 | power_id = (unsigned long)atomic_inc_return(&power_id_seq); | ||
1399 | |||
1400 | sc->battery.properties = sony_battery_props; | ||
1401 | sc->battery.num_properties = ARRAY_SIZE(sony_battery_props); | ||
1402 | sc->battery.get_property = sony_battery_get_property; | ||
1403 | sc->battery.type = POWER_SUPPLY_TYPE_BATTERY; | ||
1404 | sc->battery.use_for_apm = 0; | ||
1405 | sc->battery.name = kasprintf(GFP_KERNEL, "sony_controller_battery_%lu", | ||
1406 | power_id); | ||
1407 | if (!sc->battery.name) | ||
1408 | return -ENOMEM; | ||
1409 | |||
1410 | ret = power_supply_register(&hdev->dev, &sc->battery); | ||
1411 | if (ret) { | ||
1412 | hid_err(hdev, "Unable to register battery device\n"); | ||
1413 | goto err_free; | ||
1414 | } | ||
1415 | |||
1416 | power_supply_powers(&sc->battery, &hdev->dev); | ||
1417 | return 0; | ||
999 | 1418 | ||
1000 | cancel_work_sync(&sc->state_worker); | 1419 | err_free: |
1420 | kfree(sc->battery.name); | ||
1421 | sc->battery.name = NULL; | ||
1422 | return ret; | ||
1001 | } | 1423 | } |
1002 | 1424 | ||
1003 | #else | 1425 | static void sony_battery_remove(struct sony_sc *sc) |
1004 | static int sony_init_ff(struct hid_device *hdev) | 1426 | { |
1427 | if (!sc->battery.name) | ||
1428 | return; | ||
1429 | |||
1430 | power_supply_unregister(&sc->battery); | ||
1431 | kfree(sc->battery.name); | ||
1432 | sc->battery.name = NULL; | ||
1433 | } | ||
1434 | |||
1435 | static int sony_register_touchpad(struct sony_sc *sc, int touch_count, | ||
1436 | int w, int h) | ||
1005 | { | 1437 | { |
1438 | struct hid_input *hidinput = list_entry(sc->hdev->inputs.next, | ||
1439 | struct hid_input, list); | ||
1440 | struct input_dev *input_dev = hidinput->input; | ||
1441 | int ret; | ||
1442 | |||
1443 | ret = input_mt_init_slots(input_dev, touch_count, 0); | ||
1444 | if (ret < 0) { | ||
1445 | hid_err(sc->hdev, "Unable to initialize multi-touch slots\n"); | ||
1446 | return ret; | ||
1447 | } | ||
1448 | |||
1449 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, w, 0, 0); | ||
1450 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, h, 0, 0); | ||
1451 | |||
1006 | return 0; | 1452 | return 0; |
1007 | } | 1453 | } |
1008 | 1454 | ||
1009 | static void sony_destroy_ff(struct hid_device *hdev) | 1455 | /* |
1456 | * If a controller is plugged in via USB while already connected via Bluetooth | ||
1457 | * it will show up as two devices. A global list of connected controllers and | ||
1458 | * their MAC addresses is maintained to ensure that a device is only connected | ||
1459 | * once. | ||
1460 | */ | ||
1461 | static int sony_check_add_dev_list(struct sony_sc *sc) | ||
1010 | { | 1462 | { |
1463 | struct sony_sc *entry; | ||
1464 | unsigned long flags; | ||
1465 | int ret; | ||
1466 | |||
1467 | spin_lock_irqsave(&sony_dev_list_lock, flags); | ||
1468 | |||
1469 | list_for_each_entry(entry, &sony_device_list, list_node) { | ||
1470 | ret = memcmp(sc->mac_address, entry->mac_address, | ||
1471 | sizeof(sc->mac_address)); | ||
1472 | if (!ret) { | ||
1473 | ret = -EEXIST; | ||
1474 | hid_info(sc->hdev, "controller with MAC address %pMR already connected\n", | ||
1475 | sc->mac_address); | ||
1476 | goto unlock; | ||
1477 | } | ||
1478 | } | ||
1479 | |||
1480 | ret = 0; | ||
1481 | list_add(&(sc->list_node), &sony_device_list); | ||
1482 | |||
1483 | unlock: | ||
1484 | spin_unlock_irqrestore(&sony_dev_list_lock, flags); | ||
1485 | return ret; | ||
1011 | } | 1486 | } |
1012 | #endif | ||
1013 | 1487 | ||
1014 | static int sony_set_output_report(struct sony_sc *sc, int req_id, int req_size) | 1488 | static void sony_remove_dev_list(struct sony_sc *sc) |
1015 | { | 1489 | { |
1016 | struct list_head *head, *list; | 1490 | unsigned long flags; |
1017 | struct hid_report *report; | ||
1018 | struct hid_device *hdev = sc->hdev; | ||
1019 | 1491 | ||
1020 | list = &hdev->report_enum[HID_OUTPUT_REPORT].report_list; | 1492 | if (sc->list_node.next) { |
1493 | spin_lock_irqsave(&sony_dev_list_lock, flags); | ||
1494 | list_del(&(sc->list_node)); | ||
1495 | spin_unlock_irqrestore(&sony_dev_list_lock, flags); | ||
1496 | } | ||
1497 | } | ||
1498 | |||
1499 | static int sony_get_bt_devaddr(struct sony_sc *sc) | ||
1500 | { | ||
1501 | int ret; | ||
1021 | 1502 | ||
1022 | list_for_each(head, list) { | 1503 | /* HIDP stores the device MAC address as a string in the uniq field. */ |
1023 | report = list_entry(head, struct hid_report, list); | 1504 | ret = strlen(sc->hdev->uniq); |
1505 | if (ret != 17) | ||
1506 | return -EINVAL; | ||
1024 | 1507 | ||
1025 | if (report->id == req_id) { | 1508 | ret = sscanf(sc->hdev->uniq, |
1026 | if (report->size < req_size) { | 1509 | "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", |
1027 | hid_err(hdev, "Output report 0x%02x (%i bits) is smaller than requested size (%i bits)\n", | 1510 | &sc->mac_address[5], &sc->mac_address[4], &sc->mac_address[3], |
1028 | req_id, report->size, req_size); | 1511 | &sc->mac_address[2], &sc->mac_address[1], &sc->mac_address[0]); |
1029 | return -EINVAL; | 1512 | |
1030 | } | 1513 | if (ret != 6) |
1031 | sc->output_report = report; | 1514 | return -EINVAL; |
1515 | |||
1516 | return 0; | ||
1517 | } | ||
1518 | |||
1519 | static int sony_check_add(struct sony_sc *sc) | ||
1520 | { | ||
1521 | int n, ret; | ||
1522 | |||
1523 | if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) || | ||
1524 | (sc->quirks & SIXAXIS_CONTROLLER_BT)) { | ||
1525 | /* | ||
1526 | * sony_get_bt_devaddr() attempts to parse the Bluetooth MAC | ||
1527 | * address from the uniq string where HIDP stores it. | ||
1528 | * As uniq cannot be guaranteed to be a MAC address in all cases | ||
1529 | * a failure of this function should not prevent the connection. | ||
1530 | */ | ||
1531 | if (sony_get_bt_devaddr(sc) < 0) { | ||
1532 | hid_warn(sc->hdev, "UNIQ does not contain a MAC address; duplicate check skipped\n"); | ||
1032 | return 0; | 1533 | return 0; |
1033 | } | 1534 | } |
1034 | } | 1535 | } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) { |
1536 | __u8 buf[7]; | ||
1537 | |||
1538 | /* | ||
1539 | * The MAC address of a DS4 controller connected via USB can be | ||
1540 | * retrieved with feature report 0x81. The address begins at | ||
1541 | * offset 1. | ||
1542 | */ | ||
1543 | ret = hid_hw_raw_request(sc->hdev, 0x81, buf, sizeof(buf), | ||
1544 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); | ||
1545 | |||
1546 | if (ret != 7) { | ||
1547 | hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n"); | ||
1548 | return ret < 0 ? ret : -EINVAL; | ||
1549 | } | ||
1035 | 1550 | ||
1036 | hid_err(hdev, "Unable to locate output report 0x%02x\n", req_id); | 1551 | memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address)); |
1552 | } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) { | ||
1553 | __u8 buf[18]; | ||
1554 | |||
1555 | /* | ||
1556 | * The MAC address of a Sixaxis controller connected via USB can | ||
1557 | * be retrieved with feature report 0xf2. The address begins at | ||
1558 | * offset 4. | ||
1559 | */ | ||
1560 | ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, sizeof(buf), | ||
1561 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); | ||
1562 | |||
1563 | if (ret != 18) { | ||
1564 | hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n"); | ||
1565 | return ret < 0 ? ret : -EINVAL; | ||
1566 | } | ||
1037 | 1567 | ||
1038 | return -EINVAL; | 1568 | /* |
1569 | * The Sixaxis device MAC in the report is big-endian and must | ||
1570 | * be byte-swapped. | ||
1571 | */ | ||
1572 | for (n = 0; n < 6; n++) | ||
1573 | sc->mac_address[5-n] = buf[4+n]; | ||
1574 | } else { | ||
1575 | return 0; | ||
1576 | } | ||
1577 | |||
1578 | return sony_check_add_dev_list(sc); | ||
1039 | } | 1579 | } |
1040 | 1580 | ||
1581 | |||
1041 | static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) | 1582 | static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) |
1042 | { | 1583 | { |
1043 | int ret; | 1584 | int ret; |
@@ -1075,18 +1616,42 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
1075 | } | 1616 | } |
1076 | 1617 | ||
1077 | if (sc->quirks & SIXAXIS_CONTROLLER_USB) { | 1618 | if (sc->quirks & SIXAXIS_CONTROLLER_USB) { |
1078 | hdev->hid_output_raw_report = sixaxis_usb_output_raw_report; | 1619 | /* |
1620 | * The Sony Sixaxis does not handle HID Output Reports on the | ||
1621 | * Interrupt EP like it could, so we need to force HID Output | ||
1622 | * Reports to use HID_REQ_SET_REPORT on the Control EP. | ||
1623 | * | ||
1624 | * There is also another issue about HID Output Reports via USB, | ||
1625 | * the Sixaxis does not want the report_id as part of the data | ||
1626 | * packet, so we have to discard buf[0] when sending the actual | ||
1627 | * control message, even for numbered reports, humpf! | ||
1628 | */ | ||
1629 | hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; | ||
1630 | hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID; | ||
1079 | ret = sixaxis_set_operational_usb(hdev); | 1631 | ret = sixaxis_set_operational_usb(hdev); |
1632 | sc->worker_initialized = 1; | ||
1080 | INIT_WORK(&sc->state_worker, sixaxis_state_worker); | 1633 | INIT_WORK(&sc->state_worker, sixaxis_state_worker); |
1081 | } | 1634 | } else if (sc->quirks & SIXAXIS_CONTROLLER_BT) { |
1082 | else if (sc->quirks & SIXAXIS_CONTROLLER_BT) | ||
1083 | ret = sixaxis_set_operational_bt(hdev); | 1635 | ret = sixaxis_set_operational_bt(hdev); |
1084 | else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) { | 1636 | sc->worker_initialized = 1; |
1085 | /* Report 5 (31 bytes) is used to send data to the controller via USB */ | 1637 | INIT_WORK(&sc->state_worker, sixaxis_state_worker); |
1086 | ret = sony_set_output_report(sc, 0x05, 248); | 1638 | } else if (sc->quirks & DUALSHOCK4_CONTROLLER) { |
1639 | if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) { | ||
1640 | ret = dualshock4_set_operational_bt(hdev); | ||
1641 | if (ret < 0) { | ||
1642 | hid_err(hdev, "failed to set the Dualshock 4 operational mode\n"); | ||
1643 | goto err_stop; | ||
1644 | } | ||
1645 | } | ||
1646 | /* | ||
1647 | * The Dualshock 4 touchpad supports 2 touches and has a | ||
1648 | * resolution of 1920x940. | ||
1649 | */ | ||
1650 | ret = sony_register_touchpad(sc, 2, 1920, 940); | ||
1087 | if (ret < 0) | 1651 | if (ret < 0) |
1088 | goto err_stop; | 1652 | goto err_stop; |
1089 | 1653 | ||
1654 | sc->worker_initialized = 1; | ||
1090 | INIT_WORK(&sc->state_worker, dualshock4_state_worker); | 1655 | INIT_WORK(&sc->state_worker, dualshock4_state_worker); |
1091 | } else { | 1656 | } else { |
1092 | ret = 0; | 1657 | ret = 0; |
@@ -1095,20 +1660,50 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
1095 | if (ret < 0) | 1660 | if (ret < 0) |
1096 | goto err_stop; | 1661 | goto err_stop; |
1097 | 1662 | ||
1663 | ret = sony_check_add(sc); | ||
1664 | if (ret < 0) | ||
1665 | goto err_stop; | ||
1666 | |||
1098 | if (sc->quirks & SONY_LED_SUPPORT) { | 1667 | if (sc->quirks & SONY_LED_SUPPORT) { |
1099 | ret = sony_leds_init(hdev); | 1668 | ret = sony_leds_init(hdev); |
1100 | if (ret < 0) | 1669 | if (ret < 0) |
1101 | goto err_stop; | 1670 | goto err_stop; |
1102 | } | 1671 | } |
1103 | 1672 | ||
1104 | ret = sony_init_ff(hdev); | 1673 | if (sc->quirks & SONY_FF_SUPPORT) { |
1105 | if (ret < 0) | 1674 | ret = sony_init_ff(hdev); |
1106 | goto err_stop; | 1675 | if (ret < 0) |
1676 | goto err_stop; | ||
1677 | if (sc->quirks & SONY_BATTERY_SUPPORT) { | ||
1678 | ret = sony_battery_probe(sc); | ||
1679 | if (ret < 0) | ||
1680 | goto err_stop; | ||
1681 | |||
1682 | /* Open the device to receive reports with battery info */ | ||
1683 | ret = hid_hw_open(hdev); | ||
1684 | if (ret < 0) { | ||
1685 | hid_err(hdev, "hw open failed\n"); | ||
1686 | goto err_stop; | ||
1687 | } | ||
1688 | } | ||
1689 | |||
1690 | if (sc->quirks & SONY_FF_SUPPORT) { | ||
1691 | ret = sony_init_ff(hdev); | ||
1692 | if (ret < 0) | ||
1693 | goto err_close; | ||
1694 | } | ||
1107 | 1695 | ||
1108 | return 0; | 1696 | return 0; |
1697 | err_close: | ||
1698 | hid_hw_close(hdev); | ||
1109 | err_stop: | 1699 | err_stop: |
1110 | if (sc->quirks & SONY_LED_SUPPORT) | 1700 | if (sc->quirks & SONY_LED_SUPPORT) |
1111 | sony_leds_remove(hdev); | 1701 | sony_leds_remove(hdev); |
1702 | if (sc->quirks & SONY_BATTERY_SUPPORT) | ||
1703 | sony_battery_remove(sc); | ||
1704 | if (sc->worker_initialized) | ||
1705 | cancel_work_sync(&sc->state_worker); | ||
1706 | sony_remove_dev_list(sc); | ||
1112 | hid_hw_stop(hdev); | 1707 | hid_hw_stop(hdev); |
1113 | return ret; | 1708 | return ret; |
1114 | } | 1709 | } |
@@ -1120,7 +1715,17 @@ static void sony_remove(struct hid_device *hdev) | |||
1120 | if (sc->quirks & SONY_LED_SUPPORT) | 1715 | if (sc->quirks & SONY_LED_SUPPORT) |
1121 | sony_leds_remove(hdev); | 1716 | sony_leds_remove(hdev); |
1122 | 1717 | ||
1123 | sony_destroy_ff(hdev); | 1718 | if (sc->worker_initialized) |
1719 | cancel_work_sync(&sc->state_worker); | ||
1720 | if (sc->quirks & SONY_BATTERY_SUPPORT) { | ||
1721 | hid_hw_close(hdev); | ||
1722 | sony_battery_remove(sc); | ||
1723 | } | ||
1724 | |||
1725 | if (sc->worker_initialized) | ||
1726 | cancel_work_sync(&sc->state_worker); | ||
1727 | |||
1728 | sony_remove_dev_list(sc); | ||
1124 | 1729 | ||
1125 | hid_hw_stop(hdev); | 1730 | hid_hw_stop(hdev); |
1126 | } | 1731 | } |
diff --git a/drivers/hid/hid-thingm.c b/drivers/hid/hid-thingm.c index 99342cfa0ea2..a97c78845f7b 100644 --- a/drivers/hid/hid-thingm.c +++ b/drivers/hid/hid-thingm.c | |||
@@ -48,8 +48,8 @@ static int blink1_send_command(struct blink1_data *data, | |||
48 | buf[0], buf[1], buf[2], buf[3], buf[4], | 48 | buf[0], buf[1], buf[2], buf[3], buf[4], |
49 | buf[5], buf[6], buf[7], buf[8]); | 49 | buf[5], buf[6], buf[7], buf[8]); |
50 | 50 | ||
51 | ret = data->hdev->hid_output_raw_report(data->hdev, buf, | 51 | ret = hid_hw_raw_request(data->hdev, buf[0], buf, BLINK1_CMD_SIZE, |
52 | BLINK1_CMD_SIZE, HID_FEATURE_REPORT); | 52 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
53 | 53 | ||
54 | return ret < 0 ? ret : 0; | 54 | return ret < 0 ? ret : 0; |
55 | } | 55 | } |
diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c index 60c75dcbbdb8..902013ec041b 100644 --- a/drivers/hid/hid-wacom.c +++ b/drivers/hid/hid-wacom.c | |||
@@ -128,8 +128,8 @@ static void wacom_set_image(struct hid_device *hdev, const char *image, | |||
128 | 128 | ||
129 | rep_data[0] = WAC_CMD_ICON_START_STOP; | 129 | rep_data[0] = WAC_CMD_ICON_START_STOP; |
130 | rep_data[1] = 0; | 130 | rep_data[1] = 0; |
131 | ret = hdev->hid_output_raw_report(hdev, rep_data, 2, | 131 | ret = hid_hw_raw_request(hdev, rep_data[0], rep_data, 2, |
132 | HID_FEATURE_REPORT); | 132 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
133 | if (ret < 0) | 133 | if (ret < 0) |
134 | goto err; | 134 | goto err; |
135 | 135 | ||
@@ -143,15 +143,15 @@ static void wacom_set_image(struct hid_device *hdev, const char *image, | |||
143 | rep_data[j + 3] = p[(i << 6) + j]; | 143 | rep_data[j + 3] = p[(i << 6) + j]; |
144 | 144 | ||
145 | rep_data[2] = i; | 145 | rep_data[2] = i; |
146 | ret = hdev->hid_output_raw_report(hdev, rep_data, 67, | 146 | ret = hid_hw_raw_request(hdev, rep_data[0], rep_data, 67, |
147 | HID_FEATURE_REPORT); | 147 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
148 | } | 148 | } |
149 | 149 | ||
150 | rep_data[0] = WAC_CMD_ICON_START_STOP; | 150 | rep_data[0] = WAC_CMD_ICON_START_STOP; |
151 | rep_data[1] = 0; | 151 | rep_data[1] = 0; |
152 | 152 | ||
153 | ret = hdev->hid_output_raw_report(hdev, rep_data, 2, | 153 | ret = hid_hw_raw_request(hdev, rep_data[0], rep_data, 2, |
154 | HID_FEATURE_REPORT); | 154 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
155 | 155 | ||
156 | err: | 156 | err: |
157 | return; | 157 | return; |
@@ -183,7 +183,8 @@ static void wacom_leds_set_brightness(struct led_classdev *led_dev, | |||
183 | buf[3] = value; | 183 | buf[3] = value; |
184 | /* use fixed brightness for OLEDs */ | 184 | /* use fixed brightness for OLEDs */ |
185 | buf[4] = 0x08; | 185 | buf[4] = 0x08; |
186 | hdev->hid_output_raw_report(hdev, buf, 9, HID_FEATURE_REPORT); | 186 | hid_hw_raw_request(hdev, buf[0], buf, 9, HID_FEATURE_REPORT, |
187 | HID_REQ_SET_REPORT); | ||
187 | kfree(buf); | 188 | kfree(buf); |
188 | } | 189 | } |
189 | 190 | ||
@@ -339,8 +340,8 @@ static void wacom_set_features(struct hid_device *hdev, u8 speed) | |||
339 | rep_data[0] = 0x03 ; rep_data[1] = 0x00; | 340 | rep_data[0] = 0x03 ; rep_data[1] = 0x00; |
340 | limit = 3; | 341 | limit = 3; |
341 | do { | 342 | do { |
342 | ret = hdev->hid_output_raw_report(hdev, rep_data, 2, | 343 | ret = hid_hw_raw_request(hdev, rep_data[0], rep_data, 2, |
343 | HID_FEATURE_REPORT); | 344 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
344 | } while (ret < 0 && limit-- > 0); | 345 | } while (ret < 0 && limit-- > 0); |
345 | 346 | ||
346 | if (ret >= 0) { | 347 | if (ret >= 0) { |
@@ -352,8 +353,9 @@ static void wacom_set_features(struct hid_device *hdev, u8 speed) | |||
352 | rep_data[1] = 0x00; | 353 | rep_data[1] = 0x00; |
353 | limit = 3; | 354 | limit = 3; |
354 | do { | 355 | do { |
355 | ret = hdev->hid_output_raw_report(hdev, | 356 | ret = hid_hw_raw_request(hdev, rep_data[0], |
356 | rep_data, 2, HID_FEATURE_REPORT); | 357 | rep_data, 2, HID_FEATURE_REPORT, |
358 | HID_REQ_SET_REPORT); | ||
357 | } while (ret < 0 && limit-- > 0); | 359 | } while (ret < 0 && limit-- > 0); |
358 | 360 | ||
359 | if (ret >= 0) { | 361 | if (ret >= 0) { |
@@ -378,8 +380,8 @@ static void wacom_set_features(struct hid_device *hdev, u8 speed) | |||
378 | rep_data[0] = 0x03; | 380 | rep_data[0] = 0x03; |
379 | rep_data[1] = wdata->features; | 381 | rep_data[1] = wdata->features; |
380 | 382 | ||
381 | ret = hdev->hid_output_raw_report(hdev, rep_data, 2, | 383 | ret = hid_hw_raw_request(hdev, rep_data[0], rep_data, 2, |
382 | HID_FEATURE_REPORT); | 384 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
383 | if (ret >= 0) | 385 | if (ret >= 0) |
384 | wdata->high_speed = speed; | 386 | wdata->high_speed = speed; |
385 | break; | 387 | break; |
diff --git a/drivers/hid/hid-wiimote-core.c b/drivers/hid/hid-wiimote-core.c index abb20db2b443..d00391418d1a 100644 --- a/drivers/hid/hid-wiimote-core.c +++ b/drivers/hid/hid-wiimote-core.c | |||
@@ -28,14 +28,14 @@ static int wiimote_hid_send(struct hid_device *hdev, __u8 *buffer, | |||
28 | __u8 *buf; | 28 | __u8 *buf; |
29 | int ret; | 29 | int ret; |
30 | 30 | ||
31 | if (!hdev->hid_output_raw_report) | 31 | if (!hdev->ll_driver->output_report) |
32 | return -ENODEV; | 32 | return -ENODEV; |
33 | 33 | ||
34 | buf = kmemdup(buffer, count, GFP_KERNEL); | 34 | buf = kmemdup(buffer, count, GFP_KERNEL); |
35 | if (!buf) | 35 | if (!buf) |
36 | return -ENOMEM; | 36 | return -ENOMEM; |
37 | 37 | ||
38 | ret = hdev->hid_output_raw_report(hdev, buf, count, HID_OUTPUT_REPORT); | 38 | ret = hid_hw_output_report(hdev, buf, count); |
39 | 39 | ||
40 | kfree(buf); | 40 | kfree(buf); |
41 | return ret; | 41 | return ret; |
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c index cb0137b3718d..9c2d7c23f296 100644 --- a/drivers/hid/hidraw.c +++ b/drivers/hid/hidraw.c | |||
@@ -123,10 +123,6 @@ static ssize_t hidraw_send_report(struct file *file, const char __user *buffer, | |||
123 | 123 | ||
124 | dev = hidraw_table[minor]->hid; | 124 | dev = hidraw_table[minor]->hid; |
125 | 125 | ||
126 | if (!dev->hid_output_raw_report) { | ||
127 | ret = -ENODEV; | ||
128 | goto out; | ||
129 | } | ||
130 | 126 | ||
131 | if (count > HID_MAX_BUFFER_SIZE) { | 127 | if (count > HID_MAX_BUFFER_SIZE) { |
132 | hid_warn(dev, "pid %d passed too large report\n", | 128 | hid_warn(dev, "pid %d passed too large report\n", |
@@ -153,7 +149,21 @@ static ssize_t hidraw_send_report(struct file *file, const char __user *buffer, | |||
153 | goto out_free; | 149 | goto out_free; |
154 | } | 150 | } |
155 | 151 | ||
156 | ret = dev->hid_output_raw_report(dev, buf, count, report_type); | 152 | if ((report_type == HID_OUTPUT_REPORT) && |
153 | !(dev->quirks & HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP)) { | ||
154 | ret = hid_hw_output_report(dev, buf, count); | ||
155 | /* | ||
156 | * compatibility with old implementation of USB-HID and I2C-HID: | ||
157 | * if the device does not support receiving output reports, | ||
158 | * on an interrupt endpoint, fallback to SET_REPORT HID command. | ||
159 | */ | ||
160 | if (ret != -ENOSYS) | ||
161 | goto out_free; | ||
162 | } | ||
163 | |||
164 | ret = hid_hw_raw_request(dev, buf[0], buf, count, report_type, | ||
165 | HID_REQ_SET_REPORT); | ||
166 | |||
157 | out_free: | 167 | out_free: |
158 | kfree(buf); | 168 | kfree(buf); |
159 | out: | 169 | out: |
@@ -189,7 +199,7 @@ static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t | |||
189 | 199 | ||
190 | dev = hidraw_table[minor]->hid; | 200 | dev = hidraw_table[minor]->hid; |
191 | 201 | ||
192 | if (!dev->hid_get_raw_report) { | 202 | if (!dev->ll_driver->raw_request) { |
193 | ret = -ENODEV; | 203 | ret = -ENODEV; |
194 | goto out; | 204 | goto out; |
195 | } | 205 | } |
@@ -216,14 +226,15 @@ static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t | |||
216 | 226 | ||
217 | /* | 227 | /* |
218 | * Read the first byte from the user. This is the report number, | 228 | * Read the first byte from the user. This is the report number, |
219 | * which is passed to dev->hid_get_raw_report(). | 229 | * which is passed to hid_hw_raw_request(). |
220 | */ | 230 | */ |
221 | if (copy_from_user(&report_number, buffer, 1)) { | 231 | if (copy_from_user(&report_number, buffer, 1)) { |
222 | ret = -EFAULT; | 232 | ret = -EFAULT; |
223 | goto out_free; | 233 | goto out_free; |
224 | } | 234 | } |
225 | 235 | ||
226 | ret = dev->hid_get_raw_report(dev, report_number, buf, count, report_type); | 236 | ret = hid_hw_raw_request(dev, report_number, buf, count, report_type, |
237 | HID_REQ_GET_REPORT); | ||
227 | 238 | ||
228 | if (ret < 0) | 239 | if (ret < 0) |
229 | goto out_free; | 240 | goto out_free; |
@@ -320,13 +331,13 @@ static void drop_ref(struct hidraw *hidraw, int exists_bit) | |||
320 | hid_hw_close(hidraw->hid); | 331 | hid_hw_close(hidraw->hid); |
321 | wake_up_interruptible(&hidraw->wait); | 332 | wake_up_interruptible(&hidraw->wait); |
322 | } | 333 | } |
334 | device_destroy(hidraw_class, | ||
335 | MKDEV(hidraw_major, hidraw->minor)); | ||
323 | } else { | 336 | } else { |
324 | --hidraw->open; | 337 | --hidraw->open; |
325 | } | 338 | } |
326 | if (!hidraw->open) { | 339 | if (!hidraw->open) { |
327 | if (!hidraw->exist) { | 340 | if (!hidraw->exist) { |
328 | device_destroy(hidraw_class, | ||
329 | MKDEV(hidraw_major, hidraw->minor)); | ||
330 | hidraw_table[hidraw->minor] = NULL; | 341 | hidraw_table[hidraw->minor] = NULL; |
331 | kfree(hidraw); | 342 | kfree(hidraw); |
332 | } else { | 343 | } else { |
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index e914f2755491..8c52a07d5652 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
27 | #include <linux/pm.h> | 27 | #include <linux/pm.h> |
28 | #include <linux/pm_runtime.h> | ||
28 | #include <linux/device.h> | 29 | #include <linux/device.h> |
29 | #include <linux/wait.h> | 30 | #include <linux/wait.h> |
30 | #include <linux/err.h> | 31 | #include <linux/err.h> |
@@ -256,18 +257,27 @@ static int i2c_hid_get_report(struct i2c_client *client, u8 reportType, | |||
256 | return 0; | 257 | return 0; |
257 | } | 258 | } |
258 | 259 | ||
259 | static int i2c_hid_set_report(struct i2c_client *client, u8 reportType, | 260 | /** |
260 | u8 reportID, unsigned char *buf, size_t data_len) | 261 | * i2c_hid_set_or_send_report: forward an incoming report to the device |
262 | * @client: the i2c_client of the device | ||
263 | * @reportType: 0x03 for HID_FEATURE_REPORT ; 0x02 for HID_OUTPUT_REPORT | ||
264 | * @reportID: the report ID | ||
265 | * @buf: the actual data to transfer, without the report ID | ||
266 | * @len: size of buf | ||
267 | * @use_data: true: use SET_REPORT HID command, false: send plain OUTPUT report | ||
268 | */ | ||
269 | static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType, | ||
270 | u8 reportID, unsigned char *buf, size_t data_len, bool use_data) | ||
261 | { | 271 | { |
262 | struct i2c_hid *ihid = i2c_get_clientdata(client); | 272 | struct i2c_hid *ihid = i2c_get_clientdata(client); |
263 | u8 *args = ihid->argsbuf; | 273 | u8 *args = ihid->argsbuf; |
264 | const struct i2c_hid_cmd * hidcmd = &hid_set_report_cmd; | 274 | const struct i2c_hid_cmd *hidcmd; |
265 | int ret; | 275 | int ret; |
266 | u16 dataRegister = le16_to_cpu(ihid->hdesc.wDataRegister); | 276 | u16 dataRegister = le16_to_cpu(ihid->hdesc.wDataRegister); |
267 | u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister); | 277 | u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister); |
268 | u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength); | 278 | u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength); |
269 | 279 | ||
270 | /* hidraw already checked that data_len < HID_MAX_BUFFER_SIZE */ | 280 | /* hid_hw_* already checked that data_len < HID_MAX_BUFFER_SIZE */ |
271 | u16 size = 2 /* size */ + | 281 | u16 size = 2 /* size */ + |
272 | (reportID ? 1 : 0) /* reportID */ + | 282 | (reportID ? 1 : 0) /* reportID */ + |
273 | data_len /* buf */; | 283 | data_len /* buf */; |
@@ -278,6 +288,9 @@ static int i2c_hid_set_report(struct i2c_client *client, u8 reportType, | |||
278 | 288 | ||
279 | i2c_hid_dbg(ihid, "%s\n", __func__); | 289 | i2c_hid_dbg(ihid, "%s\n", __func__); |
280 | 290 | ||
291 | if (!use_data && maxOutputLength == 0) | ||
292 | return -ENOSYS; | ||
293 | |||
281 | if (reportID >= 0x0F) { | 294 | if (reportID >= 0x0F) { |
282 | args[index++] = reportID; | 295 | args[index++] = reportID; |
283 | reportID = 0x0F; | 296 | reportID = 0x0F; |
@@ -287,9 +300,10 @@ static int i2c_hid_set_report(struct i2c_client *client, u8 reportType, | |||
287 | * use the data register for feature reports or if the device does not | 300 | * use the data register for feature reports or if the device does not |
288 | * support the output register | 301 | * support the output register |
289 | */ | 302 | */ |
290 | if (reportType == 0x03 || maxOutputLength == 0) { | 303 | if (use_data) { |
291 | args[index++] = dataRegister & 0xFF; | 304 | args[index++] = dataRegister & 0xFF; |
292 | args[index++] = dataRegister >> 8; | 305 | args[index++] = dataRegister >> 8; |
306 | hidcmd = &hid_set_report_cmd; | ||
293 | } else { | 307 | } else { |
294 | args[index++] = outputRegister & 0xFF; | 308 | args[index++] = outputRegister & 0xFF; |
295 | args[index++] = outputRegister >> 8; | 309 | args[index++] = outputRegister >> 8; |
@@ -454,10 +468,18 @@ static void i2c_hid_init_reports(struct hid_device *hid) | |||
454 | return; | 468 | return; |
455 | } | 469 | } |
456 | 470 | ||
471 | /* | ||
472 | * The device must be powered on while we fetch initial reports | ||
473 | * from it. | ||
474 | */ | ||
475 | pm_runtime_get_sync(&client->dev); | ||
476 | |||
457 | list_for_each_entry(report, | 477 | list_for_each_entry(report, |
458 | &hid->report_enum[HID_FEATURE_REPORT].report_list, list) | 478 | &hid->report_enum[HID_FEATURE_REPORT].report_list, list) |
459 | i2c_hid_init_report(report, inbuf, ihid->bufsize); | 479 | i2c_hid_init_report(report, inbuf, ihid->bufsize); |
460 | 480 | ||
481 | pm_runtime_put(&client->dev); | ||
482 | |||
461 | kfree(inbuf); | 483 | kfree(inbuf); |
462 | } | 484 | } |
463 | 485 | ||
@@ -550,7 +572,7 @@ static int i2c_hid_get_raw_report(struct hid_device *hid, | |||
550 | } | 572 | } |
551 | 573 | ||
552 | static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf, | 574 | static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf, |
553 | size_t count, unsigned char report_type) | 575 | size_t count, unsigned char report_type, bool use_data) |
554 | { | 576 | { |
555 | struct i2c_client *client = hid->driver_data; | 577 | struct i2c_client *client = hid->driver_data; |
556 | int report_id = buf[0]; | 578 | int report_id = buf[0]; |
@@ -564,9 +586,9 @@ static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf, | |||
564 | count--; | 586 | count--; |
565 | } | 587 | } |
566 | 588 | ||
567 | ret = i2c_hid_set_report(client, | 589 | ret = i2c_hid_set_or_send_report(client, |
568 | report_type == HID_FEATURE_REPORT ? 0x03 : 0x02, | 590 | report_type == HID_FEATURE_REPORT ? 0x03 : 0x02, |
569 | report_id, buf, count); | 591 | report_id, buf, count, use_data); |
570 | 592 | ||
571 | if (report_id && ret >= 0) | 593 | if (report_id && ret >= 0) |
572 | ret++; /* add report_id to the number of transfered bytes */ | 594 | ret++; /* add report_id to the number of transfered bytes */ |
@@ -574,34 +596,27 @@ static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf, | |||
574 | return ret; | 596 | return ret; |
575 | } | 597 | } |
576 | 598 | ||
577 | static void i2c_hid_request(struct hid_device *hid, struct hid_report *rep, | 599 | static int i2c_hid_output_report(struct hid_device *hid, __u8 *buf, |
578 | int reqtype) | 600 | size_t count) |
579 | { | 601 | { |
580 | struct i2c_client *client = hid->driver_data; | 602 | return i2c_hid_output_raw_report(hid, buf, count, HID_OUTPUT_REPORT, |
581 | char *buf; | 603 | false); |
582 | int ret; | 604 | } |
583 | int len = i2c_hid_get_report_length(rep) - 2; | ||
584 | |||
585 | buf = kzalloc(len, GFP_KERNEL); | ||
586 | if (!buf) | ||
587 | return; | ||
588 | 605 | ||
606 | static int i2c_hid_raw_request(struct hid_device *hid, unsigned char reportnum, | ||
607 | __u8 *buf, size_t len, unsigned char rtype, | ||
608 | int reqtype) | ||
609 | { | ||
589 | switch (reqtype) { | 610 | switch (reqtype) { |
590 | case HID_REQ_GET_REPORT: | 611 | case HID_REQ_GET_REPORT: |
591 | ret = i2c_hid_get_raw_report(hid, rep->id, buf, len, rep->type); | 612 | return i2c_hid_get_raw_report(hid, reportnum, buf, len, rtype); |
592 | if (ret < 0) | ||
593 | dev_err(&client->dev, "%s: unable to get report: %d\n", | ||
594 | __func__, ret); | ||
595 | else | ||
596 | hid_input_report(hid, rep->type, buf, ret, 0); | ||
597 | break; | ||
598 | case HID_REQ_SET_REPORT: | 613 | case HID_REQ_SET_REPORT: |
599 | hid_output_report(rep, buf); | 614 | if (buf[0] != reportnum) |
600 | i2c_hid_output_raw_report(hid, buf, len, rep->type); | 615 | return -EINVAL; |
601 | break; | 616 | return i2c_hid_output_raw_report(hid, buf, len, rtype, true); |
617 | default: | ||
618 | return -EIO; | ||
602 | } | 619 | } |
603 | |||
604 | kfree(buf); | ||
605 | } | 620 | } |
606 | 621 | ||
607 | static int i2c_hid_parse(struct hid_device *hid) | 622 | static int i2c_hid_parse(struct hid_device *hid) |
@@ -703,8 +718,8 @@ static int i2c_hid_open(struct hid_device *hid) | |||
703 | 718 | ||
704 | mutex_lock(&i2c_hid_open_mut); | 719 | mutex_lock(&i2c_hid_open_mut); |
705 | if (!hid->open++) { | 720 | if (!hid->open++) { |
706 | ret = i2c_hid_set_power(client, I2C_HID_PWR_ON); | 721 | ret = pm_runtime_get_sync(&client->dev); |
707 | if (ret) { | 722 | if (ret < 0) { |
708 | hid->open--; | 723 | hid->open--; |
709 | goto done; | 724 | goto done; |
710 | } | 725 | } |
@@ -712,7 +727,7 @@ static int i2c_hid_open(struct hid_device *hid) | |||
712 | } | 727 | } |
713 | done: | 728 | done: |
714 | mutex_unlock(&i2c_hid_open_mut); | 729 | mutex_unlock(&i2c_hid_open_mut); |
715 | return ret; | 730 | return ret < 0 ? ret : 0; |
716 | } | 731 | } |
717 | 732 | ||
718 | static void i2c_hid_close(struct hid_device *hid) | 733 | static void i2c_hid_close(struct hid_device *hid) |
@@ -729,7 +744,7 @@ static void i2c_hid_close(struct hid_device *hid) | |||
729 | clear_bit(I2C_HID_STARTED, &ihid->flags); | 744 | clear_bit(I2C_HID_STARTED, &ihid->flags); |
730 | 745 | ||
731 | /* Save some power */ | 746 | /* Save some power */ |
732 | i2c_hid_set_power(client, I2C_HID_PWR_SLEEP); | 747 | pm_runtime_put(&client->dev); |
733 | } | 748 | } |
734 | mutex_unlock(&i2c_hid_open_mut); | 749 | mutex_unlock(&i2c_hid_open_mut); |
735 | } | 750 | } |
@@ -738,19 +753,18 @@ static int i2c_hid_power(struct hid_device *hid, int lvl) | |||
738 | { | 753 | { |
739 | struct i2c_client *client = hid->driver_data; | 754 | struct i2c_client *client = hid->driver_data; |
740 | struct i2c_hid *ihid = i2c_get_clientdata(client); | 755 | struct i2c_hid *ihid = i2c_get_clientdata(client); |
741 | int ret = 0; | ||
742 | 756 | ||
743 | i2c_hid_dbg(ihid, "%s lvl:%d\n", __func__, lvl); | 757 | i2c_hid_dbg(ihid, "%s lvl:%d\n", __func__, lvl); |
744 | 758 | ||
745 | switch (lvl) { | 759 | switch (lvl) { |
746 | case PM_HINT_FULLON: | 760 | case PM_HINT_FULLON: |
747 | ret = i2c_hid_set_power(client, I2C_HID_PWR_ON); | 761 | pm_runtime_get_sync(&client->dev); |
748 | break; | 762 | break; |
749 | case PM_HINT_NORMAL: | 763 | case PM_HINT_NORMAL: |
750 | ret = i2c_hid_set_power(client, I2C_HID_PWR_SLEEP); | 764 | pm_runtime_put(&client->dev); |
751 | break; | 765 | break; |
752 | } | 766 | } |
753 | return ret; | 767 | return 0; |
754 | } | 768 | } |
755 | 769 | ||
756 | static struct hid_ll_driver i2c_hid_ll_driver = { | 770 | static struct hid_ll_driver i2c_hid_ll_driver = { |
@@ -760,7 +774,8 @@ static struct hid_ll_driver i2c_hid_ll_driver = { | |||
760 | .open = i2c_hid_open, | 774 | .open = i2c_hid_open, |
761 | .close = i2c_hid_close, | 775 | .close = i2c_hid_close, |
762 | .power = i2c_hid_power, | 776 | .power = i2c_hid_power, |
763 | .request = i2c_hid_request, | 777 | .output_report = i2c_hid_output_report, |
778 | .raw_request = i2c_hid_raw_request, | ||
764 | }; | 779 | }; |
765 | 780 | ||
766 | static int i2c_hid_init_irq(struct i2c_client *client) | 781 | static int i2c_hid_init_irq(struct i2c_client *client) |
@@ -987,13 +1002,17 @@ static int i2c_hid_probe(struct i2c_client *client, | |||
987 | if (ret < 0) | 1002 | if (ret < 0) |
988 | goto err; | 1003 | goto err; |
989 | 1004 | ||
1005 | pm_runtime_get_noresume(&client->dev); | ||
1006 | pm_runtime_set_active(&client->dev); | ||
1007 | pm_runtime_enable(&client->dev); | ||
1008 | |||
990 | ret = i2c_hid_fetch_hid_descriptor(ihid); | 1009 | ret = i2c_hid_fetch_hid_descriptor(ihid); |
991 | if (ret < 0) | 1010 | if (ret < 0) |
992 | goto err; | 1011 | goto err_pm; |
993 | 1012 | ||
994 | ret = i2c_hid_init_irq(client); | 1013 | ret = i2c_hid_init_irq(client); |
995 | if (ret < 0) | 1014 | if (ret < 0) |
996 | goto err; | 1015 | goto err_pm; |
997 | 1016 | ||
998 | hid = hid_allocate_device(); | 1017 | hid = hid_allocate_device(); |
999 | if (IS_ERR(hid)) { | 1018 | if (IS_ERR(hid)) { |
@@ -1005,8 +1024,6 @@ static int i2c_hid_probe(struct i2c_client *client, | |||
1005 | 1024 | ||
1006 | hid->driver_data = client; | 1025 | hid->driver_data = client; |
1007 | hid->ll_driver = &i2c_hid_ll_driver; | 1026 | hid->ll_driver = &i2c_hid_ll_driver; |
1008 | hid->hid_get_raw_report = i2c_hid_get_raw_report; | ||
1009 | hid->hid_output_raw_report = i2c_hid_output_raw_report; | ||
1010 | hid->dev.parent = &client->dev; | 1027 | hid->dev.parent = &client->dev; |
1011 | ACPI_COMPANION_SET(&hid->dev, ACPI_COMPANION(&client->dev)); | 1028 | ACPI_COMPANION_SET(&hid->dev, ACPI_COMPANION(&client->dev)); |
1012 | hid->bus = BUS_I2C; | 1029 | hid->bus = BUS_I2C; |
@@ -1024,6 +1041,7 @@ static int i2c_hid_probe(struct i2c_client *client, | |||
1024 | goto err_mem_free; | 1041 | goto err_mem_free; |
1025 | } | 1042 | } |
1026 | 1043 | ||
1044 | pm_runtime_put(&client->dev); | ||
1027 | return 0; | 1045 | return 0; |
1028 | 1046 | ||
1029 | err_mem_free: | 1047 | err_mem_free: |
@@ -1032,6 +1050,10 @@ err_mem_free: | |||
1032 | err_irq: | 1050 | err_irq: |
1033 | free_irq(client->irq, ihid); | 1051 | free_irq(client->irq, ihid); |
1034 | 1052 | ||
1053 | err_pm: | ||
1054 | pm_runtime_put_noidle(&client->dev); | ||
1055 | pm_runtime_disable(&client->dev); | ||
1056 | |||
1035 | err: | 1057 | err: |
1036 | i2c_hid_free_buffers(ihid); | 1058 | i2c_hid_free_buffers(ihid); |
1037 | kfree(ihid); | 1059 | kfree(ihid); |
@@ -1043,6 +1065,11 @@ static int i2c_hid_remove(struct i2c_client *client) | |||
1043 | struct i2c_hid *ihid = i2c_get_clientdata(client); | 1065 | struct i2c_hid *ihid = i2c_get_clientdata(client); |
1044 | struct hid_device *hid; | 1066 | struct hid_device *hid; |
1045 | 1067 | ||
1068 | pm_runtime_get_sync(&client->dev); | ||
1069 | pm_runtime_disable(&client->dev); | ||
1070 | pm_runtime_set_suspended(&client->dev); | ||
1071 | pm_runtime_put_noidle(&client->dev); | ||
1072 | |||
1046 | hid = ihid->hid; | 1073 | hid = ihid->hid; |
1047 | hid_destroy_device(hid); | 1074 | hid_destroy_device(hid); |
1048 | 1075 | ||
@@ -1088,7 +1115,31 @@ static int i2c_hid_resume(struct device *dev) | |||
1088 | } | 1115 | } |
1089 | #endif | 1116 | #endif |
1090 | 1117 | ||
1091 | static SIMPLE_DEV_PM_OPS(i2c_hid_pm, i2c_hid_suspend, i2c_hid_resume); | 1118 | #ifdef CONFIG_PM_RUNTIME |
1119 | static int i2c_hid_runtime_suspend(struct device *dev) | ||
1120 | { | ||
1121 | struct i2c_client *client = to_i2c_client(dev); | ||
1122 | |||
1123 | i2c_hid_set_power(client, I2C_HID_PWR_SLEEP); | ||
1124 | disable_irq(client->irq); | ||
1125 | return 0; | ||
1126 | } | ||
1127 | |||
1128 | static int i2c_hid_runtime_resume(struct device *dev) | ||
1129 | { | ||
1130 | struct i2c_client *client = to_i2c_client(dev); | ||
1131 | |||
1132 | enable_irq(client->irq); | ||
1133 | i2c_hid_set_power(client, I2C_HID_PWR_ON); | ||
1134 | return 0; | ||
1135 | } | ||
1136 | #endif | ||
1137 | |||
1138 | static const struct dev_pm_ops i2c_hid_pm = { | ||
1139 | SET_SYSTEM_SLEEP_PM_OPS(i2c_hid_suspend, i2c_hid_resume) | ||
1140 | SET_RUNTIME_PM_OPS(i2c_hid_runtime_suspend, i2c_hid_runtime_resume, | ||
1141 | NULL) | ||
1142 | }; | ||
1092 | 1143 | ||
1093 | static const struct i2c_device_id i2c_hid_id_table[] = { | 1144 | static const struct i2c_device_id i2c_hid_id_table[] = { |
1094 | { "hid", 0 }, | 1145 | { "hid", 0 }, |
diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c index cedc6da93c19..7ed79be2686a 100644 --- a/drivers/hid/uhid.c +++ b/drivers/hid/uhid.c | |||
@@ -244,12 +244,35 @@ static int uhid_hid_output_raw(struct hid_device *hid, __u8 *buf, size_t count, | |||
244 | return count; | 244 | return count; |
245 | } | 245 | } |
246 | 246 | ||
247 | static int uhid_hid_output_report(struct hid_device *hid, __u8 *buf, | ||
248 | size_t count) | ||
249 | { | ||
250 | return uhid_hid_output_raw(hid, buf, count, HID_OUTPUT_REPORT); | ||
251 | } | ||
252 | |||
253 | static int uhid_raw_request(struct hid_device *hid, unsigned char reportnum, | ||
254 | __u8 *buf, size_t len, unsigned char rtype, | ||
255 | int reqtype) | ||
256 | { | ||
257 | switch (reqtype) { | ||
258 | case HID_REQ_GET_REPORT: | ||
259 | return uhid_hid_get_raw(hid, reportnum, buf, len, rtype); | ||
260 | case HID_REQ_SET_REPORT: | ||
261 | /* TODO: implement proper SET_REPORT functionality */ | ||
262 | return -ENOSYS; | ||
263 | default: | ||
264 | return -EIO; | ||
265 | } | ||
266 | } | ||
267 | |||
247 | static struct hid_ll_driver uhid_hid_driver = { | 268 | static struct hid_ll_driver uhid_hid_driver = { |
248 | .start = uhid_hid_start, | 269 | .start = uhid_hid_start, |
249 | .stop = uhid_hid_stop, | 270 | .stop = uhid_hid_stop, |
250 | .open = uhid_hid_open, | 271 | .open = uhid_hid_open, |
251 | .close = uhid_hid_close, | 272 | .close = uhid_hid_close, |
252 | .parse = uhid_hid_parse, | 273 | .parse = uhid_hid_parse, |
274 | .output_report = uhid_hid_output_report, | ||
275 | .raw_request = uhid_raw_request, | ||
253 | }; | 276 | }; |
254 | 277 | ||
255 | #ifdef CONFIG_COMPAT | 278 | #ifdef CONFIG_COMPAT |
@@ -377,8 +400,6 @@ static int uhid_dev_create(struct uhid_device *uhid, | |||
377 | hid->uniq[63] = 0; | 400 | hid->uniq[63] = 0; |
378 | 401 | ||
379 | hid->ll_driver = &uhid_hid_driver; | 402 | hid->ll_driver = &uhid_hid_driver; |
380 | hid->hid_get_raw_report = uhid_hid_get_raw; | ||
381 | hid->hid_output_raw_report = uhid_hid_output_raw; | ||
382 | hid->bus = ev->u.create.bus; | 403 | hid->bus = ev->u.create.bus; |
383 | hid->vendor = ev->u.create.vendor; | 404 | hid->vendor = ev->u.create.vendor; |
384 | hid->product = ev->u.create.product; | 405 | hid->product = ev->u.create.product; |
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 44df131d390a..7b88f4cb9902 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c | |||
@@ -884,52 +884,66 @@ static int usbhid_get_raw_report(struct hid_device *hid, | |||
884 | return ret; | 884 | return ret; |
885 | } | 885 | } |
886 | 886 | ||
887 | static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t count, | 887 | static int usbhid_set_raw_report(struct hid_device *hid, unsigned int reportnum, |
888 | unsigned char report_type) | 888 | __u8 *buf, size_t count, unsigned char rtype) |
889 | { | 889 | { |
890 | struct usbhid_device *usbhid = hid->driver_data; | 890 | struct usbhid_device *usbhid = hid->driver_data; |
891 | struct usb_device *dev = hid_to_usb_dev(hid); | 891 | struct usb_device *dev = hid_to_usb_dev(hid); |
892 | struct usb_interface *intf = usbhid->intf; | 892 | struct usb_interface *intf = usbhid->intf; |
893 | struct usb_host_interface *interface = intf->cur_altsetting; | 893 | struct usb_host_interface *interface = intf->cur_altsetting; |
894 | int ret; | 894 | int ret, skipped_report_id = 0; |
895 | 895 | ||
896 | if (usbhid->urbout && report_type != HID_FEATURE_REPORT) { | 896 | /* Byte 0 is the report number. Report data starts at byte 1.*/ |
897 | int actual_length; | 897 | if ((rtype == HID_OUTPUT_REPORT) && |
898 | int skipped_report_id = 0; | 898 | (hid->quirks & HID_QUIRK_SKIP_OUTPUT_REPORT_ID)) |
899 | buf[0] = 0; | ||
900 | else | ||
901 | buf[0] = reportnum; | ||
902 | |||
903 | if (buf[0] == 0x0) { | ||
904 | /* Don't send the Report ID */ | ||
905 | buf++; | ||
906 | count--; | ||
907 | skipped_report_id = 1; | ||
908 | } | ||
899 | 909 | ||
900 | if (buf[0] == 0x0) { | 910 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
901 | /* Don't send the Report ID */ | ||
902 | buf++; | ||
903 | count--; | ||
904 | skipped_report_id = 1; | ||
905 | } | ||
906 | ret = usb_interrupt_msg(dev, usbhid->urbout->pipe, | ||
907 | buf, count, &actual_length, | ||
908 | USB_CTRL_SET_TIMEOUT); | ||
909 | /* return the number of bytes transferred */ | ||
910 | if (ret == 0) { | ||
911 | ret = actual_length; | ||
912 | /* count also the report id */ | ||
913 | if (skipped_report_id) | ||
914 | ret++; | ||
915 | } | ||
916 | } else { | ||
917 | int skipped_report_id = 0; | ||
918 | int report_id = buf[0]; | ||
919 | if (buf[0] == 0x0) { | ||
920 | /* Don't send the Report ID */ | ||
921 | buf++; | ||
922 | count--; | ||
923 | skipped_report_id = 1; | ||
924 | } | ||
925 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | ||
926 | HID_REQ_SET_REPORT, | 911 | HID_REQ_SET_REPORT, |
927 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | 912 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
928 | ((report_type + 1) << 8) | report_id, | 913 | ((rtype + 1) << 8) | reportnum, |
929 | interface->desc.bInterfaceNumber, buf, count, | 914 | interface->desc.bInterfaceNumber, buf, count, |
930 | USB_CTRL_SET_TIMEOUT); | 915 | USB_CTRL_SET_TIMEOUT); |
931 | /* count also the report id, if this was a numbered report. */ | 916 | /* count also the report id, if this was a numbered report. */ |
932 | if (ret > 0 && skipped_report_id) | 917 | if (ret > 0 && skipped_report_id) |
918 | ret++; | ||
919 | |||
920 | return ret; | ||
921 | } | ||
922 | |||
923 | static int usbhid_output_report(struct hid_device *hid, __u8 *buf, size_t count) | ||
924 | { | ||
925 | struct usbhid_device *usbhid = hid->driver_data; | ||
926 | struct usb_device *dev = hid_to_usb_dev(hid); | ||
927 | int actual_length, skipped_report_id = 0, ret; | ||
928 | |||
929 | if (!usbhid->urbout) | ||
930 | return -ENOSYS; | ||
931 | |||
932 | if (buf[0] == 0x0) { | ||
933 | /* Don't send the Report ID */ | ||
934 | buf++; | ||
935 | count--; | ||
936 | skipped_report_id = 1; | ||
937 | } | ||
938 | |||
939 | ret = usb_interrupt_msg(dev, usbhid->urbout->pipe, | ||
940 | buf, count, &actual_length, | ||
941 | USB_CTRL_SET_TIMEOUT); | ||
942 | /* return the number of bytes transferred */ | ||
943 | if (ret == 0) { | ||
944 | ret = actual_length; | ||
945 | /* count also the report id */ | ||
946 | if (skipped_report_id) | ||
933 | ret++; | 947 | ret++; |
934 | } | 948 | } |
935 | 949 | ||
@@ -1200,6 +1214,20 @@ static void usbhid_request(struct hid_device *hid, struct hid_report *rep, int r | |||
1200 | } | 1214 | } |
1201 | } | 1215 | } |
1202 | 1216 | ||
1217 | static int usbhid_raw_request(struct hid_device *hid, unsigned char reportnum, | ||
1218 | __u8 *buf, size_t len, unsigned char rtype, | ||
1219 | int reqtype) | ||
1220 | { | ||
1221 | switch (reqtype) { | ||
1222 | case HID_REQ_GET_REPORT: | ||
1223 | return usbhid_get_raw_report(hid, reportnum, buf, len, rtype); | ||
1224 | case HID_REQ_SET_REPORT: | ||
1225 | return usbhid_set_raw_report(hid, reportnum, buf, len, rtype); | ||
1226 | default: | ||
1227 | return -EIO; | ||
1228 | } | ||
1229 | } | ||
1230 | |||
1203 | static int usbhid_idle(struct hid_device *hid, int report, int idle, | 1231 | static int usbhid_idle(struct hid_device *hid, int report, int idle, |
1204 | int reqtype) | 1232 | int reqtype) |
1205 | { | 1233 | { |
@@ -1223,6 +1251,8 @@ static struct hid_ll_driver usb_hid_driver = { | |||
1223 | .power = usbhid_power, | 1251 | .power = usbhid_power, |
1224 | .request = usbhid_request, | 1252 | .request = usbhid_request, |
1225 | .wait = usbhid_wait_io, | 1253 | .wait = usbhid_wait_io, |
1254 | .raw_request = usbhid_raw_request, | ||
1255 | .output_report = usbhid_output_report, | ||
1226 | .idle = usbhid_idle, | 1256 | .idle = usbhid_idle, |
1227 | }; | 1257 | }; |
1228 | 1258 | ||
@@ -1253,8 +1283,6 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id * | |||
1253 | 1283 | ||
1254 | usb_set_intfdata(intf, hid); | 1284 | usb_set_intfdata(intf, hid); |
1255 | hid->ll_driver = &usb_hid_driver; | 1285 | hid->ll_driver = &usb_hid_driver; |
1256 | hid->hid_get_raw_report = usbhid_get_raw_report; | ||
1257 | hid->hid_output_raw_report = usbhid_output_raw_report; | ||
1258 | hid->ff_init = hid_pidff_init; | 1286 | hid->ff_init = hid_pidff_init; |
1259 | #ifdef CONFIG_USB_HIDDEV | 1287 | #ifdef CONFIG_USB_HIDDEV |
1260 | hid->hiddev_connect = hiddev_connect; | 1288 | hid->hiddev_connect = hiddev_connect; |
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c index 175ec0afb70c..dbd83878ff99 100644 --- a/drivers/hid/usbhid/hid-quirks.c +++ b/drivers/hid/usbhid/hid-quirks.c | |||
@@ -74,6 +74,7 @@ static const struct hid_blacklist { | |||
74 | { USB_VENDOR_ID_FREESCALE, USB_DEVICE_ID_FREESCALE_MX28, HID_QUIRK_NOGET }, | 74 | { USB_VENDOR_ID_FREESCALE, USB_DEVICE_ID_FREESCALE_MX28, HID_QUIRK_NOGET }, |
75 | { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_NOGET }, | 75 | { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_NOGET }, |
76 | { USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GX680R_LED_PANEL, HID_QUIRK_NO_INIT_REPORTS }, | 76 | { USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GX680R_LED_PANEL, HID_QUIRK_NO_INIT_REPORTS }, |
77 | { USB_VENDOR_ID_NEXIO, USB_DEVICE_ID_NEXIO_MULTITOUCH_PTI0750, HID_QUIRK_NO_INIT_REPORTS }, | ||
77 | { USB_VENDOR_ID_NOVATEK, USB_DEVICE_ID_NOVATEK_MOUSE, HID_QUIRK_NO_INIT_REPORTS }, | 78 | { USB_VENDOR_ID_NOVATEK, USB_DEVICE_ID_NOVATEK_MOUSE, HID_QUIRK_NO_INIT_REPORTS }, |
78 | { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NO_INIT_REPORTS }, | 79 | { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN, HID_QUIRK_NO_INIT_REPORTS }, |
79 | { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1, HID_QUIRK_NO_INIT_REPORTS }, | 80 | { USB_VENDOR_ID_PIXART, USB_DEVICE_ID_PIXART_OPTICAL_TOUCH_SCREEN1, HID_QUIRK_NO_INIT_REPORTS }, |
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c index 7dcf83998e6f..dbefbdaf7cd1 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c | |||
@@ -38,29 +38,40 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, | |||
38 | if (state) { | 38 | if (state) { |
39 | if (sensor_hub_device_open(st->hsdev)) | 39 | if (sensor_hub_device_open(st->hsdev)) |
40 | return -EIO; | 40 | return -EIO; |
41 | state_val = | 41 | state_val = hid_sensor_get_usage_index(st->hsdev, |
42 | HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM; | 42 | st->power_state.report_id, |
43 | report_val = | 43 | st->power_state.index, |
44 | HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM; | 44 | HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM); |
45 | 45 | report_val = hid_sensor_get_usage_index(st->hsdev, | |
46 | st->report_state.report_id, | ||
47 | st->report_state.index, | ||
48 | HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM); | ||
46 | } else { | 49 | } else { |
47 | sensor_hub_device_close(st->hsdev); | 50 | sensor_hub_device_close(st->hsdev); |
48 | state_val = | 51 | state_val = hid_sensor_get_usage_index(st->hsdev, |
49 | HID_USAGE_SENSOR_PROP_POWER_STATE_D4_POWER_OFF_ENUM; | 52 | st->power_state.report_id, |
50 | report_val = | 53 | st->power_state.index, |
51 | HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM; | 54 | HID_USAGE_SENSOR_PROP_POWER_STATE_D4_POWER_OFF_ENUM); |
55 | report_val = hid_sensor_get_usage_index(st->hsdev, | ||
56 | st->report_state.report_id, | ||
57 | st->report_state.index, | ||
58 | HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM); | ||
52 | } | 59 | } |
53 | |||
54 | st->data_ready = state; | 60 | st->data_ready = state; |
55 | state_val += st->power_state.logical_minimum; | 61 | |
56 | report_val += st->report_state.logical_minimum; | 62 | if (state_val >= 0) { |
57 | sensor_hub_set_feature(st->hsdev, st->power_state.report_id, | 63 | state_val += st->power_state.logical_minimum; |
64 | sensor_hub_set_feature(st->hsdev, st->power_state.report_id, | ||
58 | st->power_state.index, | 65 | st->power_state.index, |
59 | (s32)state_val); | 66 | (s32)state_val); |
67 | } | ||
60 | 68 | ||
61 | sensor_hub_set_feature(st->hsdev, st->report_state.report_id, | 69 | if (report_val >= 0) { |
70 | report_val += st->report_state.logical_minimum; | ||
71 | sensor_hub_set_feature(st->hsdev, st->report_state.report_id, | ||
62 | st->report_state.index, | 72 | st->report_state.index, |
63 | (s32)report_val); | 73 | (s32)report_val); |
74 | } | ||
64 | 75 | ||
65 | return 0; | 76 | return 0; |
66 | } | 77 | } |
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h index b914ca3f57ba..b70cfd7ff29c 100644 --- a/include/linux/hid-sensor-hub.h +++ b/include/linux/hid-sensor-hub.h | |||
@@ -51,13 +51,15 @@ struct hid_sensor_hub_attribute_info { | |||
51 | * @hdev: Stores the hid instance. | 51 | * @hdev: Stores the hid instance. |
52 | * @vendor_id: Vendor id of hub device. | 52 | * @vendor_id: Vendor id of hub device. |
53 | * @product_id: Product id of hub device. | 53 | * @product_id: Product id of hub device. |
54 | * @ref_cnt: Number of MFD clients have opened this device | 54 | * @start_collection_index: Starting index for a phy type collection |
55 | * @end_collection_index: Last index for a phy type collection | ||
55 | */ | 56 | */ |
56 | struct hid_sensor_hub_device { | 57 | struct hid_sensor_hub_device { |
57 | struct hid_device *hdev; | 58 | struct hid_device *hdev; |
58 | u32 vendor_id; | 59 | u32 vendor_id; |
59 | u32 product_id; | 60 | u32 product_id; |
60 | int ref_cnt; | 61 | int start_collection_index; |
62 | int end_collection_index; | ||
61 | }; | 63 | }; |
62 | 64 | ||
63 | /** | 65 | /** |
@@ -218,4 +220,7 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st, | |||
218 | int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, | 220 | int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, |
219 | int *val1, int *val2); | 221 | int *val1, int *val2); |
220 | 222 | ||
223 | int hid_sensor_get_usage_index(struct hid_sensor_hub_device *hsdev, | ||
224 | u32 report_id, int field_index, u32 usage_id); | ||
225 | |||
221 | #endif | 226 | #endif |
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h index beaf965621c1..f8607605a31c 100644 --- a/include/linux/hid-sensor-ids.h +++ b/include/linux/hid-sensor-ids.h | |||
@@ -130,15 +130,15 @@ | |||
130 | #define HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS 0x1000 | 130 | #define HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS 0x1000 |
131 | 131 | ||
132 | /* Power state enumerations */ | 132 | /* Power state enumerations */ |
133 | #define HID_USAGE_SENSOR_PROP_POWER_STATE_UNDEFINED_ENUM 0x00 | 133 | #define HID_USAGE_SENSOR_PROP_POWER_STATE_UNDEFINED_ENUM 0x200850 |
134 | #define HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM 0x01 | 134 | #define HID_USAGE_SENSOR_PROP_POWER_STATE_D0_FULL_POWER_ENUM 0x200851 |
135 | #define HID_USAGE_SENSOR_PROP_POWER_STATE_D1_LOW_POWER_ENUM 0x02 | 135 | #define HID_USAGE_SENSOR_PROP_POWER_STATE_D1_LOW_POWER_ENUM 0x200852 |
136 | #define HID_USAGE_SENSOR_PROP_POWER_STATE_D2_STANDBY_WITH_WAKE_ENUM 0x03 | 136 | #define HID_USAGE_SENSOR_PROP_POWER_STATE_D2_STANDBY_WITH_WAKE_ENUM 0x200853 |
137 | #define HID_USAGE_SENSOR_PROP_POWER_STATE_D3_SLEEP_WITH_WAKE_ENUM 0x04 | 137 | #define HID_USAGE_SENSOR_PROP_POWER_STATE_D3_SLEEP_WITH_WAKE_ENUM 0x200854 |
138 | #define HID_USAGE_SENSOR_PROP_POWER_STATE_D4_POWER_OFF_ENUM 0x05 | 138 | #define HID_USAGE_SENSOR_PROP_POWER_STATE_D4_POWER_OFF_ENUM 0x200855 |
139 | 139 | ||
140 | /* Report State enumerations */ | 140 | /* Report State enumerations */ |
141 | #define HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM 0x00 | 141 | #define HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM 0x200840 |
142 | #define HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM 0x01 | 142 | #define HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM 0x200841 |
143 | 143 | ||
144 | #endif | 144 | #endif |
diff --git a/include/linux/hid.h b/include/linux/hid.h index 31b9d299ef6c..01a90b8d53bb 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h | |||
@@ -287,6 +287,8 @@ struct hid_item { | |||
287 | #define HID_QUIRK_NO_EMPTY_INPUT 0x00000100 | 287 | #define HID_QUIRK_NO_EMPTY_INPUT 0x00000100 |
288 | #define HID_QUIRK_NO_INIT_INPUT_REPORTS 0x00000200 | 288 | #define HID_QUIRK_NO_INIT_INPUT_REPORTS 0x00000200 |
289 | #define HID_QUIRK_SKIP_OUTPUT_REPORTS 0x00010000 | 289 | #define HID_QUIRK_SKIP_OUTPUT_REPORTS 0x00010000 |
290 | #define HID_QUIRK_SKIP_OUTPUT_REPORT_ID 0x00020000 | ||
291 | #define HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP 0x00040000 | ||
290 | #define HID_QUIRK_FULLSPEED_INTERVAL 0x10000000 | 292 | #define HID_QUIRK_FULLSPEED_INTERVAL 0x10000000 |
291 | #define HID_QUIRK_NO_INIT_REPORTS 0x20000000 | 293 | #define HID_QUIRK_NO_INIT_REPORTS 0x20000000 |
292 | #define HID_QUIRK_NO_IGNORE 0x40000000 | 294 | #define HID_QUIRK_NO_IGNORE 0x40000000 |
@@ -508,12 +510,6 @@ struct hid_device { /* device report descriptor */ | |||
508 | struct hid_usage *, __s32); | 510 | struct hid_usage *, __s32); |
509 | void (*hiddev_report_event) (struct hid_device *, struct hid_report *); | 511 | void (*hiddev_report_event) (struct hid_device *, struct hid_report *); |
510 | 512 | ||
511 | /* handler for raw input (Get_Report) data, used by hidraw */ | ||
512 | int (*hid_get_raw_report) (struct hid_device *, unsigned char, __u8 *, size_t, unsigned char); | ||
513 | |||
514 | /* handler for raw output data, used by hidraw */ | ||
515 | int (*hid_output_raw_report) (struct hid_device *, __u8 *, size_t, unsigned char); | ||
516 | |||
517 | /* debugging support via debugfs */ | 513 | /* debugging support via debugfs */ |
518 | unsigned short debug; | 514 | unsigned short debug; |
519 | struct dentry *debug_dir; | 515 | struct dentry *debug_dir; |
@@ -675,11 +671,12 @@ struct hid_driver { | |||
675 | * @stop: called on remove | 671 | * @stop: called on remove |
676 | * @open: called by input layer on open | 672 | * @open: called by input layer on open |
677 | * @close: called by input layer on close | 673 | * @close: called by input layer on close |
678 | * @hidinput_input_event: event input event (e.g. ff or leds) | ||
679 | * @parse: this method is called only once to parse the device data, | 674 | * @parse: this method is called only once to parse the device data, |
680 | * shouldn't allocate anything to not leak memory | 675 | * shouldn't allocate anything to not leak memory |
681 | * @request: send report request to device (e.g. feature report) | 676 | * @request: send report request to device (e.g. feature report) |
682 | * @wait: wait for buffered io to complete (send/recv reports) | 677 | * @wait: wait for buffered io to complete (send/recv reports) |
678 | * @raw_request: send raw report request to device (e.g. feature report) | ||
679 | * @output_report: send output report to device | ||
683 | * @idle: send idle request to device | 680 | * @idle: send idle request to device |
684 | */ | 681 | */ |
685 | struct hid_ll_driver { | 682 | struct hid_ll_driver { |
@@ -691,17 +688,20 @@ struct hid_ll_driver { | |||
691 | 688 | ||
692 | int (*power)(struct hid_device *hdev, int level); | 689 | int (*power)(struct hid_device *hdev, int level); |
693 | 690 | ||
694 | int (*hidinput_input_event) (struct input_dev *idev, unsigned int type, | ||
695 | unsigned int code, int value); | ||
696 | |||
697 | int (*parse)(struct hid_device *hdev); | 691 | int (*parse)(struct hid_device *hdev); |
698 | 692 | ||
699 | void (*request)(struct hid_device *hdev, | 693 | void (*request)(struct hid_device *hdev, |
700 | struct hid_report *report, int reqtype); | 694 | struct hid_report *report, int reqtype); |
701 | 695 | ||
702 | int (*wait)(struct hid_device *hdev); | 696 | int (*wait)(struct hid_device *hdev); |
703 | int (*idle)(struct hid_device *hdev, int report, int idle, int reqtype); | ||
704 | 697 | ||
698 | int (*raw_request) (struct hid_device *hdev, unsigned char reportnum, | ||
699 | __u8 *buf, size_t len, unsigned char rtype, | ||
700 | int reqtype); | ||
701 | |||
702 | int (*output_report) (struct hid_device *hdev, __u8 *buf, size_t len); | ||
703 | |||
704 | int (*idle)(struct hid_device *hdev, int report, int idle, int reqtype); | ||
705 | }; | 705 | }; |
706 | 706 | ||
707 | #define PM_HINT_FULLON 1<<5 | 707 | #define PM_HINT_FULLON 1<<5 |
@@ -752,6 +752,7 @@ struct hid_field *hidinput_get_led_field(struct hid_device *hid); | |||
752 | unsigned int hidinput_count_leds(struct hid_device *hid); | 752 | unsigned int hidinput_count_leds(struct hid_device *hid); |
753 | __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code); | 753 | __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code); |
754 | void hid_output_report(struct hid_report *report, __u8 *data); | 754 | void hid_output_report(struct hid_report *report, __u8 *data); |
755 | void __hid_request(struct hid_device *hid, struct hid_report *rep, int reqtype); | ||
755 | u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags); | 756 | u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags); |
756 | struct hid_device *hid_allocate_device(void); | 757 | struct hid_device *hid_allocate_device(void); |
757 | struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id); | 758 | struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id); |
@@ -964,7 +965,55 @@ static inline void hid_hw_request(struct hid_device *hdev, | |||
964 | struct hid_report *report, int reqtype) | 965 | struct hid_report *report, int reqtype) |
965 | { | 966 | { |
966 | if (hdev->ll_driver->request) | 967 | if (hdev->ll_driver->request) |
967 | hdev->ll_driver->request(hdev, report, reqtype); | 968 | return hdev->ll_driver->request(hdev, report, reqtype); |
969 | |||
970 | __hid_request(hdev, report, reqtype); | ||
971 | } | ||
972 | |||
973 | /** | ||
974 | * hid_hw_raw_request - send report request to device | ||
975 | * | ||
976 | * @hdev: hid device | ||
977 | * @reportnum: report ID | ||
978 | * @buf: in/out data to transfer | ||
979 | * @len: length of buf | ||
980 | * @rtype: HID report type | ||
981 | * @reqtype: HID_REQ_GET_REPORT or HID_REQ_SET_REPORT | ||
982 | * | ||
983 | * @return: count of data transfered, negative if error | ||
984 | * | ||
985 | * Same behavior as hid_hw_request, but with raw buffers instead. | ||
986 | */ | ||
987 | static inline int hid_hw_raw_request(struct hid_device *hdev, | ||
988 | unsigned char reportnum, __u8 *buf, | ||
989 | size_t len, unsigned char rtype, int reqtype) | ||
990 | { | ||
991 | if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf) | ||
992 | return -EINVAL; | ||
993 | |||
994 | return hdev->ll_driver->raw_request(hdev, reportnum, buf, len, | ||
995 | rtype, reqtype); | ||
996 | } | ||
997 | |||
998 | /** | ||
999 | * hid_hw_output_report - send output report to device | ||
1000 | * | ||
1001 | * @hdev: hid device | ||
1002 | * @buf: raw data to transfer | ||
1003 | * @len: length of buf | ||
1004 | * | ||
1005 | * @return: count of data transfered, negative if error | ||
1006 | */ | ||
1007 | static inline int hid_hw_output_report(struct hid_device *hdev, __u8 *buf, | ||
1008 | size_t len) | ||
1009 | { | ||
1010 | if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf) | ||
1011 | return -EINVAL; | ||
1012 | |||
1013 | if (hdev->ll_driver->output_report) | ||
1014 | return hdev->ll_driver->output_report(hdev, buf, len); | ||
1015 | |||
1016 | return -ENOSYS; | ||
968 | } | 1017 | } |
969 | 1018 | ||
970 | /** | 1019 | /** |
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c index 292e619db896..8181ea4bc2f2 100644 --- a/net/bluetooth/hidp/core.c +++ b/net/bluetooth/hidp/core.c | |||
@@ -223,51 +223,6 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb) | |||
223 | input_sync(dev); | 223 | input_sync(dev); |
224 | } | 224 | } |
225 | 225 | ||
226 | static int hidp_send_report(struct hidp_session *session, struct hid_report *report) | ||
227 | { | ||
228 | unsigned char hdr; | ||
229 | u8 *buf; | ||
230 | int rsize, ret; | ||
231 | |||
232 | buf = hid_alloc_report_buf(report, GFP_ATOMIC); | ||
233 | if (!buf) | ||
234 | return -EIO; | ||
235 | |||
236 | hid_output_report(report, buf); | ||
237 | hdr = HIDP_TRANS_DATA | HIDP_DATA_RTYPE_OUPUT; | ||
238 | |||
239 | rsize = ((report->size - 1) >> 3) + 1 + (report->id > 0); | ||
240 | ret = hidp_send_intr_message(session, hdr, buf, rsize); | ||
241 | |||
242 | kfree(buf); | ||
243 | return ret; | ||
244 | } | ||
245 | |||
246 | static int hidp_hidinput_event(struct input_dev *dev, unsigned int type, | ||
247 | unsigned int code, int value) | ||
248 | { | ||
249 | struct hid_device *hid = input_get_drvdata(dev); | ||
250 | struct hidp_session *session = hid->driver_data; | ||
251 | struct hid_field *field; | ||
252 | int offset; | ||
253 | |||
254 | BT_DBG("session %p type %d code %d value %d", | ||
255 | session, type, code, value); | ||
256 | |||
257 | if (type != EV_LED) | ||
258 | return -1; | ||
259 | |||
260 | offset = hidinput_find_field(hid, type, code, &field); | ||
261 | if (offset == -1) { | ||
262 | hid_warn(dev, "event field not found\n"); | ||
263 | return -1; | ||
264 | } | ||
265 | |||
266 | hid_set_field(field, offset, value); | ||
267 | |||
268 | return hidp_send_report(session, field->report); | ||
269 | } | ||
270 | |||
271 | static int hidp_get_raw_report(struct hid_device *hid, | 226 | static int hidp_get_raw_report(struct hid_device *hid, |
272 | unsigned char report_number, | 227 | unsigned char report_number, |
273 | unsigned char *data, size_t count, | 228 | unsigned char *data, size_t count, |
@@ -353,17 +308,24 @@ err: | |||
353 | return ret; | 308 | return ret; |
354 | } | 309 | } |
355 | 310 | ||
356 | static int hidp_output_raw_report(struct hid_device *hid, unsigned char *data, size_t count, | 311 | static int hidp_set_raw_report(struct hid_device *hid, unsigned char reportnum, |
357 | unsigned char report_type) | 312 | unsigned char *data, size_t count, |
313 | unsigned char report_type) | ||
358 | { | 314 | { |
359 | struct hidp_session *session = hid->driver_data; | 315 | struct hidp_session *session = hid->driver_data; |
360 | int ret; | 316 | int ret; |
361 | 317 | ||
362 | if (report_type == HID_OUTPUT_REPORT) { | 318 | switch (report_type) { |
363 | report_type = HIDP_TRANS_DATA | HIDP_DATA_RTYPE_OUPUT; | 319 | case HID_FEATURE_REPORT: |
364 | return hidp_send_intr_message(session, report_type, | 320 | report_type = HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE; |
365 | data, count); | 321 | break; |
366 | } else if (report_type != HID_FEATURE_REPORT) { | 322 | case HID_INPUT_REPORT: |
323 | report_type = HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_INPUT; | ||
324 | break; | ||
325 | case HID_OUTPUT_REPORT: | ||
326 | report_type = HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_OUPUT; | ||
327 | break; | ||
328 | default: | ||
367 | return -EINVAL; | 329 | return -EINVAL; |
368 | } | 330 | } |
369 | 331 | ||
@@ -371,8 +333,8 @@ static int hidp_output_raw_report(struct hid_device *hid, unsigned char *data, s | |||
371 | return -ERESTARTSYS; | 333 | return -ERESTARTSYS; |
372 | 334 | ||
373 | /* Set up our wait, and send the report request to the device. */ | 335 | /* Set up our wait, and send the report request to the device. */ |
336 | data[0] = reportnum; | ||
374 | set_bit(HIDP_WAITING_FOR_SEND_ACK, &session->flags); | 337 | set_bit(HIDP_WAITING_FOR_SEND_ACK, &session->flags); |
375 | report_type = HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE; | ||
376 | ret = hidp_send_ctrl_message(session, report_type, data, count); | 338 | ret = hidp_send_ctrl_message(session, report_type, data, count); |
377 | if (ret) | 339 | if (ret) |
378 | goto err; | 340 | goto err; |
@@ -411,6 +373,29 @@ err: | |||
411 | return ret; | 373 | return ret; |
412 | } | 374 | } |
413 | 375 | ||
376 | static int hidp_output_report(struct hid_device *hid, __u8 *data, size_t count) | ||
377 | { | ||
378 | struct hidp_session *session = hid->driver_data; | ||
379 | |||
380 | return hidp_send_intr_message(session, | ||
381 | HIDP_TRANS_DATA | HIDP_DATA_RTYPE_OUPUT, | ||
382 | data, count); | ||
383 | } | ||
384 | |||
385 | static int hidp_raw_request(struct hid_device *hid, unsigned char reportnum, | ||
386 | __u8 *buf, size_t len, unsigned char rtype, | ||
387 | int reqtype) | ||
388 | { | ||
389 | switch (reqtype) { | ||
390 | case HID_REQ_GET_REPORT: | ||
391 | return hidp_get_raw_report(hid, reportnum, buf, len, rtype); | ||
392 | case HID_REQ_SET_REPORT: | ||
393 | return hidp_set_raw_report(hid, reportnum, buf, len, rtype); | ||
394 | default: | ||
395 | return -EIO; | ||
396 | } | ||
397 | } | ||
398 | |||
414 | static void hidp_idle_timeout(unsigned long arg) | 399 | static void hidp_idle_timeout(unsigned long arg) |
415 | { | 400 | { |
416 | struct hidp_session *session = (struct hidp_session *) arg; | 401 | struct hidp_session *session = (struct hidp_session *) arg; |
@@ -430,6 +415,16 @@ static void hidp_del_timer(struct hidp_session *session) | |||
430 | del_timer(&session->timer); | 415 | del_timer(&session->timer); |
431 | } | 416 | } |
432 | 417 | ||
418 | static void hidp_process_report(struct hidp_session *session, | ||
419 | int type, const u8 *data, int len, int intr) | ||
420 | { | ||
421 | if (len > HID_MAX_BUFFER_SIZE) | ||
422 | len = HID_MAX_BUFFER_SIZE; | ||
423 | |||
424 | memcpy(session->input_buf, data, len); | ||
425 | hid_input_report(session->hid, type, session->input_buf, len, intr); | ||
426 | } | ||
427 | |||
433 | static void hidp_process_handshake(struct hidp_session *session, | 428 | static void hidp_process_handshake(struct hidp_session *session, |
434 | unsigned char param) | 429 | unsigned char param) |
435 | { | 430 | { |
@@ -502,7 +497,8 @@ static int hidp_process_data(struct hidp_session *session, struct sk_buff *skb, | |||
502 | hidp_input_report(session, skb); | 497 | hidp_input_report(session, skb); |
503 | 498 | ||
504 | if (session->hid) | 499 | if (session->hid) |
505 | hid_input_report(session->hid, HID_INPUT_REPORT, skb->data, skb->len, 0); | 500 | hidp_process_report(session, HID_INPUT_REPORT, |
501 | skb->data, skb->len, 0); | ||
506 | break; | 502 | break; |
507 | 503 | ||
508 | case HIDP_DATA_RTYPE_OTHER: | 504 | case HIDP_DATA_RTYPE_OTHER: |
@@ -584,7 +580,8 @@ static void hidp_recv_intr_frame(struct hidp_session *session, | |||
584 | hidp_input_report(session, skb); | 580 | hidp_input_report(session, skb); |
585 | 581 | ||
586 | if (session->hid) { | 582 | if (session->hid) { |
587 | hid_input_report(session->hid, HID_INPUT_REPORT, skb->data, skb->len, 1); | 583 | hidp_process_report(session, HID_INPUT_REPORT, |
584 | skb->data, skb->len, 1); | ||
588 | BT_DBG("report len %d", skb->len); | 585 | BT_DBG("report len %d", skb->len); |
589 | } | 586 | } |
590 | } else { | 587 | } else { |
@@ -727,7 +724,8 @@ static struct hid_ll_driver hidp_hid_driver = { | |||
727 | .stop = hidp_stop, | 724 | .stop = hidp_stop, |
728 | .open = hidp_open, | 725 | .open = hidp_open, |
729 | .close = hidp_close, | 726 | .close = hidp_close, |
730 | .hidinput_input_event = hidp_hidinput_event, | 727 | .raw_request = hidp_raw_request, |
728 | .output_report = hidp_output_report, | ||
731 | }; | 729 | }; |
732 | 730 | ||
733 | /* This function sets up the hid device. It does not add it | 731 | /* This function sets up the hid device. It does not add it |
@@ -769,15 +767,15 @@ static int hidp_setup_hid(struct hidp_session *session, | |||
769 | snprintf(hid->phys, sizeof(hid->phys), "%pMR", | 767 | snprintf(hid->phys, sizeof(hid->phys), "%pMR", |
770 | &l2cap_pi(session->ctrl_sock->sk)->chan->src); | 768 | &l2cap_pi(session->ctrl_sock->sk)->chan->src); |
771 | 769 | ||
770 | /* NOTE: Some device modules depend on the dst address being stored in | ||
771 | * uniq. Please be aware of this before making changes to this behavior. | ||
772 | */ | ||
772 | snprintf(hid->uniq, sizeof(hid->uniq), "%pMR", | 773 | snprintf(hid->uniq, sizeof(hid->uniq), "%pMR", |
773 | &l2cap_pi(session->ctrl_sock->sk)->chan->dst); | 774 | &l2cap_pi(session->ctrl_sock->sk)->chan->dst); |
774 | 775 | ||
775 | hid->dev.parent = &session->conn->hcon->dev; | 776 | hid->dev.parent = &session->conn->hcon->dev; |
776 | hid->ll_driver = &hidp_hid_driver; | 777 | hid->ll_driver = &hidp_hid_driver; |
777 | 778 | ||
778 | hid->hid_get_raw_report = hidp_get_raw_report; | ||
779 | hid->hid_output_raw_report = hidp_output_raw_report; | ||
780 | |||
781 | /* True if device is blacklisted in drivers/hid/hid-core.c */ | 779 | /* True if device is blacklisted in drivers/hid/hid-core.c */ |
782 | if (hid_ignore(hid)) { | 780 | if (hid_ignore(hid)) { |
783 | hid_destroy_device(session->hid); | 781 | hid_destroy_device(session->hid); |
diff --git a/net/bluetooth/hidp/hidp.h b/net/bluetooth/hidp/hidp.h index ab5241400cf7..8798492a6e99 100644 --- a/net/bluetooth/hidp/hidp.h +++ b/net/bluetooth/hidp/hidp.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #define __HIDP_H | 24 | #define __HIDP_H |
25 | 25 | ||
26 | #include <linux/types.h> | 26 | #include <linux/types.h> |
27 | #include <linux/hid.h> | ||
27 | #include <linux/kref.h> | 28 | #include <linux/kref.h> |
28 | #include <net/bluetooth/bluetooth.h> | 29 | #include <net/bluetooth/bluetooth.h> |
29 | #include <net/bluetooth/l2cap.h> | 30 | #include <net/bluetooth/l2cap.h> |
@@ -179,6 +180,9 @@ struct hidp_session { | |||
179 | 180 | ||
180 | /* Used in hidp_output_raw_report() */ | 181 | /* Used in hidp_output_raw_report() */ |
181 | int output_report_success; /* boolean */ | 182 | int output_report_success; /* boolean */ |
183 | |||
184 | /* temporary input buffer */ | ||
185 | u8 input_buf[HID_MAX_BUFFER_SIZE]; | ||
182 | }; | 186 | }; |
183 | 187 | ||
184 | /* HIDP init defines */ | 188 | /* HIDP init defines */ |