Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-linus-2023083101' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid

Pull HID updates from Benjamin Tissoires:

- devm fixes for problems that caused use-after-free reports (Rahul
Rameshbabu)

- Some extensive HID docs (Marco Morandini)

- Constification of struct class (Ivan Orlov and Greg Kroah-Hartman)

- Google Stadia Force Feedback support (Fabio Baltieri)

- Various fixes and new device ID support

* tag 'for-linus-2023083101' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid: (42 commits)
HID: logitech-hidpp: rework one more time the retries attempts
HID: nvidia-shield: Reference hid_device devm allocation of input_dev name
HID: multitouch: Correct devm device reference for hidinput input_dev name
HID: uclogic: Correct devm device reference for hidinput input_dev name
HID: logitech-dj: Fix error handling in logi_dj_recv_switch_to_dj_mode()
HID: i2c-hid: elan: Add ili9882t timing
dt-bindings: input: i2c-hid: Introduce Ilitek ili9882t
HID: apple: Add "Hailuck" to the list of non-apple keyboards
HID: steelseries: arctis_1_battery_request[] should be static
MAINTAINERS: update my email address
HID: logitech-hidpp: Add support for Logitech MX Anywhere 3 mouse
HID: wacom: struct name cleanup
HID: wacom: remove unnecessary 'connected' variable from EKR
HID: wacom: remove the battery when the EKR is off
HID: nvidia-shield: Update Thunderstrike LED instance name to use id
HID: nvidia-shield: Add battery support for Thunderstrike
HID: nvidia-shield: Remove led_classdev_unregister in thunderstrike_create
HID: hid-google-stadiaff: add support for Stadia force feedback
HID: logitech-dj: Add support for a new lightspeed receiver iteration
HID: logitech-hidpp: Add support for the Pro X Superlight
...

+1802 -266
+3
.mailmap
··· 139 139 Daniel Borkmann <daniel@iogearbox.net> <dxchgb@gmail.com> 140 140 David Brownell <david-b@pacbell.net> 141 141 David Collins <quic_collinsd@quicinc.com> <collinsd@codeaurora.org> 142 + David Rheinsberg <david@readahead.eu> <dh.herrmann@gmail.com> 143 + David Rheinsberg <david@readahead.eu> <dh.herrmann@googlemail.com> 144 + David Rheinsberg <david@readahead.eu> <david.rheinsberg@gmail.com> 142 145 David Woodhouse <dwmw2@shinybook.infradead.org> 143 146 Dedy Lansky <quic_dlansky@quicinc.com> <dlansky@codeaurora.org> 144 147 Deepak Kumar Singh <quic_deesin@quicinc.com> <deesin@codeaurora.org>
+67
Documentation/devicetree/bindings/input/ilitek,ili9882t.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/input/ilitek,ili9882t.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Ilitek ili9882t touchscreen controller 8 + 9 + maintainers: 10 + - Cong Yang <yangcong5@huaqin.corp-partner.google.com> 11 + 12 + description: 13 + Supports the Ilitek ili9882t touchscreen controller. 14 + This touchscreen controller uses the i2c-hid protocol with a reset GPIO. 15 + 16 + allOf: 17 + - $ref: /schemas/input/touchscreen/touchscreen.yaml# 18 + 19 + properties: 20 + compatible: 21 + const: ilitek,ili9882t 22 + 23 + reg: 24 + const: 0x41 25 + 26 + interrupts: 27 + maxItems: 1 28 + 29 + panel: true 30 + 31 + reset-gpios: 32 + maxItems: 1 33 + description: Reset GPIO. 34 + 35 + vccio-supply: 36 + description: The 1.8V supply to the touchscreen. 37 + 38 + required: 39 + - compatible 40 + - reg 41 + - interrupts 42 + - panel 43 + - vccio-supply 44 + 45 + additionalProperties: false 46 + 47 + examples: 48 + - | 49 + #include <dt-bindings/gpio/gpio.h> 50 + #include <dt-bindings/interrupt-controller/irq.h> 51 + 52 + i2c { 53 + #address-cells = <1>; 54 + #size-cells = <0>; 55 + 56 + touchscreen: touchscreen@41 { 57 + compatible = "ilitek,ili9882t"; 58 + reg = <0x41>; 59 + 60 + interrupt-parent = <&pio>; 61 + interrupts = <12 IRQ_TYPE_LEVEL_LOW>; 62 + 63 + panel = <&panel>; 64 + reset-gpios = <&pio 60 GPIO_ACTIVE_LOW>; 65 + vccio-supply = <&mt6366_vio18_reg>; 66 + }; 67 + };
+524
Documentation/hid/hidintro.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + ====================================== 4 + Introduction to HID report descriptors 5 + ====================================== 6 + 7 + This chapter is meant to give a broad overview of what HID report 8 + descriptors are, and of how a casual (non-kernel) programmer can deal 9 + with HID devices that are not working well with Linux. 10 + 11 + .. contents:: 12 + :local: 13 + :depth: 2 14 + 15 + .. toctree:: 16 + :maxdepth: 2 17 + 18 + hidreport-parsing 19 + 20 + 21 + Introduction 22 + ============ 23 + 24 + HID stands for Human Interface Device, and can be whatever device you 25 + are using to interact with a computer, be it a mouse, a touchpad, a 26 + tablet, a microphone. 27 + 28 + Many HID devices work out the box, even if their hardware is different. 29 + For example, mice can have any number of buttons; they may have a 30 + wheel; movement sensitivity differs between different models, and so 31 + on. Nonetheless, most of the time everything just works, without the 32 + need to have specialized code in the kernel for every mouse model 33 + developed since 1970. 34 + 35 + This is because modern HID devices do advertise their capabilities 36 + through the *HID report descriptor*, a fixed set of bytes describing 37 + exactly what *HID reports* may be sent between the device and the host 38 + and the meaning of each individual bit in those reports. For example, 39 + a HID Report Descriptor may specify that "in a report with ID 3 the 40 + bits from 8 to 15 is the delta x coordinate of a mouse". 41 + 42 + The HID report itself then merely carries the actual data values 43 + without any extra meta information. Note that HID reports may be sent 44 + from the device ("Input Reports", i.e. input events), to the device 45 + ("Output Reports" to e.g. change LEDs) or used for device configuration 46 + ("Feature reports"). A device may support one or more HID reports. 47 + 48 + The HID subsystem is in charge of parsing the HID report descriptors, 49 + and converts HID events into normal input device interfaces (see 50 + Documentation/hid/hid-transport.rst). Devices may misbehave because the 51 + HID report descriptor provided by the device is wrong, or because it 52 + needs to be dealt with in a special way, or because some special 53 + device or interaction mode is not handled by the default code. 54 + 55 + The format of HID report descriptors is described by two documents, 56 + available from the `USB Implementers Forum <https://www.usb.org/>`_ 57 + `HID web page <https://www.usb.org/hid>`_ address: 58 + 59 + * the `HID USB Device Class Definition 60 + <https://www.usb.org/document-library/device-class-definition-hid-111>`_ (HID Spec from now on) 61 + * the `HID Usage Tables <https://usb.org/document-library/hid-usage-tables-14>`_ (HUT from now on) 62 + 63 + The HID subsystem can deal with different transport drivers 64 + (USB, I2C, Bluetooth, etc.). See Documentation/hid/hid-transport.rst. 65 + 66 + Parsing HID report descriptors 67 + ============================== 68 + 69 + The current list of HID devices can be found at ``/sys/bus/hid/devices/``. 70 + For each device, say ``/sys/bus/hid/devices/0003\:093A\:2510.0002/``, 71 + one can read the corresponding report descriptor:: 72 + 73 + $ hexdump -C /sys/bus/hid/devices/0003\:093A\:2510.0002/report_descriptor 74 + 00000000 05 01 09 02 a1 01 09 01 a1 00 05 09 19 01 29 03 |..............).| 75 + 00000010 15 00 25 01 75 01 95 03 81 02 75 05 95 01 81 01 |..%.u.....u.....| 76 + 00000020 05 01 09 30 09 31 09 38 15 81 25 7f 75 08 95 03 |...0.1.8..%.u...| 77 + 00000030 81 06 c0 c0 |....| 78 + 00000034 79 + 80 + Optional: the HID report descriptor can be read also by 81 + directly accessing the hidraw driver [#hidraw]_. 82 + 83 + The basic structure of HID report descriptors is defined in the HID 84 + spec, while HUT "defines constants that can be interpreted by an 85 + application to identify the purpose and meaning of a data field in a 86 + HID report". Each entry is defined by at least two bytes, where the 87 + first one defines what type of value is following and is described in 88 + the HID spec, while the second one carries the actual value and is 89 + described in the HUT. 90 + 91 + HID report descriptors can, in principle, be painstakingly parsed by 92 + hand, byte by byte. 93 + 94 + A short introduction on how to do this is sketched in 95 + Documentation/hid/hidreport-parsing.rst; you only need to understand it 96 + if you need to patch HID report descriptors. 97 + 98 + In practice you should not parse HID report descriptors by hand; rather, 99 + you should use an existing parser. Among all the available ones 100 + 101 + * the online `USB Descriptor and Request Parser 102 + <http://eleccelerator.com/usbdescreqparser/>`_; 103 + * `hidrdd <https://github.com/abend0c1/hidrdd>`_, 104 + that provides very detailed and somewhat verbose descriptions 105 + (verbosity can be useful if you are not familiar with HID report 106 + descriptors); 107 + * `hid-tools <https://gitlab.freedesktop.org/libevdev/hid-tools>`_, 108 + a complete utility set that allows, among other things, 109 + to record and replay the raw HID reports and to debug 110 + and replay HID devices. 111 + It is being actively developed by the Linux HID subsystem maintainers. 112 + 113 + Parsing the mouse HID report descriptor with `hid-tools 114 + <https://gitlab.freedesktop.org/libevdev/hid-tools>`_ leads to 115 + (explanations interposed):: 116 + 117 + $ ./hid-decode /sys/bus/hid/devices/0003\:093A\:2510.0002/report_descriptor 118 + # device 0:0 119 + # 0x05, 0x01, // Usage Page (Generic Desktop) 0 120 + # 0x09, 0x02, // Usage (Mouse) 2 121 + # 0xa1, 0x01, // Collection (Application) 4 122 + # 0x09, 0x01, // Usage (Pointer) 6 123 + # 0xa1, 0x00, // Collection (Physical) 8 124 + # 0x05, 0x09, // Usage Page (Button) 10 125 + 126 + what follows is a button :: 127 + 128 + # 0x19, 0x01, // Usage Minimum (1) 12 129 + # 0x29, 0x03, // Usage Maximum (3) 14 130 + 131 + first button is button number 1, last button is button number 3 :: 132 + 133 + # 0x15, 0x00, // Logical Minimum (0) 16 134 + # 0x25, 0x01, // Logical Maximum (1) 18 135 + 136 + each button can send values from 0 up to including 1 137 + (i.e. they are binary buttons) :: 138 + 139 + # 0x75, 0x01, // Report Size (1) 20 140 + 141 + each button is sent as exactly one bit :: 142 + 143 + # 0x95, 0x03, // Report Count (3) 22 144 + 145 + and there are three of those bits (matching the three buttons) :: 146 + 147 + # 0x81, 0x02, // Input (Data,Var,Abs) 24 148 + 149 + it's actual Data (not constant padding), they represent 150 + a single variable (Var) and their values are Absolute (not relative); 151 + See HID spec Sec. 6.2.2.5 "Input, Output, and Feature Items" :: 152 + 153 + # 0x75, 0x05, // Report Size (5) 26 154 + 155 + five additional padding bits, needed to reach a byte :: 156 + 157 + # 0x95, 0x01, // Report Count (1) 28 158 + 159 + those five bits are repeated only once :: 160 + 161 + # 0x81, 0x01, // Input (Cnst,Arr,Abs) 30 162 + 163 + and take Constant (Cnst) values i.e. they can be ignored. :: 164 + 165 + # 0x05, 0x01, // Usage Page (Generic Desktop) 32 166 + # 0x09, 0x30, // Usage (X) 34 167 + # 0x09, 0x31, // Usage (Y) 36 168 + # 0x09, 0x38, // Usage (Wheel) 38 169 + 170 + The mouse has also two physical positions (Usage (X), Usage (Y)) 171 + and a wheel (Usage (Wheel)) :: 172 + 173 + # 0x15, 0x81, // Logical Minimum (-127) 40 174 + # 0x25, 0x7f, // Logical Maximum (127) 42 175 + 176 + each of them can send values ranging from -127 up to including 127 :: 177 + 178 + # 0x75, 0x08, // Report Size (8) 44 179 + 180 + which is represented by eight bits :: 181 + 182 + # 0x95, 0x03, // Report Count (3) 46 183 + 184 + and there are three of those eight bits, matching X, Y and Wheel. :: 185 + 186 + # 0x81, 0x06, // Input (Data,Var,Rel) 48 187 + 188 + This time the data values are Relative (Rel), i.e. they represent 189 + the change from the previously sent report (event) :: 190 + 191 + # 0xc0, // End Collection 50 192 + # 0xc0, // End Collection 51 193 + # 194 + R: 52 05 01 09 02 a1 01 09 01 a1 00 05 09 19 01 29 03 15 00 25 01 75 01 95 03 81 02 75 05 95 01 81 01 05 01 09 30 09 31 09 38 15 81 25 7f 75 08 95 03 81 06 c0 c0 195 + N: device 0:0 196 + I: 3 0001 0001 197 + 198 + 199 + This Report Descriptor tells us that the mouse input will be 200 + transmitted using four bytes: the first one for the buttons (three 201 + bits used, five for padding), the last three for the mouse X, Y and 202 + wheel changes, respectively. 203 + 204 + Indeed, for any event, the mouse will send a *report* of four bytes. 205 + We can check the values sent by resorting e.g. to the `hid-recorder` 206 + tool, from `hid-tools <https://gitlab.freedesktop.org/libevdev/hid-tools>`_: 207 + The sequence of bytes sent by clicking and releasing button 1, then button 2, then button 3 is:: 208 + 209 + $ sudo ./hid-recorder /dev/hidraw1 210 + 211 + .... 212 + output of hid-decode 213 + .... 214 + 215 + # Button: 1 0 0 | # | X: 0 | Y: 0 | Wheel: 0 216 + E: 000000.000000 4 01 00 00 00 217 + # Button: 0 0 0 | # | X: 0 | Y: 0 | Wheel: 0 218 + E: 000000.183949 4 00 00 00 00 219 + # Button: 0 1 0 | # | X: 0 | Y: 0 | Wheel: 0 220 + E: 000001.959698 4 02 00 00 00 221 + # Button: 0 0 0 | # | X: 0 | Y: 0 | Wheel: 0 222 + E: 000002.103899 4 00 00 00 00 223 + # Button: 0 0 1 | # | X: 0 | Y: 0 | Wheel: 0 224 + E: 000004.855799 4 04 00 00 00 225 + # Button: 0 0 0 | # | X: 0 | Y: 0 | Wheel: 0 226 + E: 000005.103864 4 00 00 00 00 227 + 228 + This example shows that when button 2 is clicked, 229 + the bytes ``02 00 00 00`` are sent, and the immediately subsequent 230 + event (``00 00 00 00``) is the release of button 2 (no buttons are 231 + pressed, remember that the data values are *absolute*). 232 + 233 + If instead one clicks and holds button 1, then clicks and holds button 234 + 2, releases button 1, and finally releases button 2, the reports are:: 235 + 236 + # Button: 1 0 0 | # | X: 0 | Y: 0 | Wheel: 0 237 + E: 000044.175830 4 01 00 00 00 238 + # Button: 1 1 0 | # | X: 0 | Y: 0 | Wheel: 0 239 + E: 000045.975997 4 03 00 00 00 240 + # Button: 0 1 0 | # | X: 0 | Y: 0 | Wheel: 0 241 + E: 000047.407930 4 02 00 00 00 242 + # Button: 0 0 0 | # | X: 0 | Y: 0 | Wheel: 0 243 + E: 000049.199919 4 00 00 00 00 244 + 245 + where with ``03 00 00 00`` both buttons are pressed, and with the 246 + subsequent ``02 00 00 00`` button 1 is released while button 2 is still 247 + active. 248 + 249 + Output, Input and Feature Reports 250 + --------------------------------- 251 + 252 + HID devices can have Input Reports, like in the mouse example, Output 253 + Reports, and Feature Reports. "Output" means that the information is 254 + sent to the device. For example, a joystick with force feedback will 255 + have some output; the led of a keyboard would need an output as well. 256 + "Input" means that data come from the device. 257 + 258 + "Feature"s are not meant to be consumed by the end user and define 259 + configuration options for the device. They can be queried from the host; 260 + when declared as *Volatile* they should be changed by the host. 261 + 262 + 263 + Collections, Report IDs and Evdev events 264 + ======================================== 265 + 266 + A single device can logically group data into different independent 267 + sets, called a *Collection*. Collections can be nested and there are 268 + different types of collections (see the HID spec 6.2.2.6 269 + "Collection, End Collection Items" for details). 270 + 271 + Different reports are identified by means of different *Report ID* 272 + fields, i.e. a number identifying the structure of the immediately 273 + following report. 274 + Whenever a Report ID is needed it is transmitted as the first byte of 275 + any report. A device with only one supported HID report (like the mouse 276 + example above) may omit the report ID. 277 + 278 + Consider the following HID report descriptor:: 279 + 280 + 05 01 09 02 A1 01 85 01 05 09 19 01 29 05 15 00 281 + 25 01 95 05 75 01 81 02 95 01 75 03 81 01 05 01 282 + 09 30 09 31 16 00 F8 26 FF 07 75 0C 95 02 81 06 283 + 09 38 15 80 25 7F 75 08 95 01 81 06 05 0C 0A 38 284 + 02 15 80 25 7F 75 08 95 01 81 06 C0 05 01 09 02 285 + A1 01 85 02 05 09 19 01 29 05 15 00 25 01 95 05 286 + 75 01 81 02 95 01 75 03 81 01 05 01 09 30 09 31 287 + 16 00 F8 26 FF 07 75 0C 95 02 81 06 09 38 15 80 288 + 25 7F 75 08 95 01 81 06 05 0C 0A 38 02 15 80 25 289 + 7F 75 08 95 01 81 06 C0 05 01 09 07 A1 01 85 05 290 + 05 07 15 00 25 01 09 29 09 3E 09 4B 09 4E 09 E3 291 + 09 E8 09 E8 09 E8 75 01 95 08 81 02 95 00 81 01 292 + C0 05 0C 09 01 A1 01 85 06 15 00 25 01 75 01 95 293 + 01 09 3F 81 06 09 3F 81 06 09 3F 81 06 09 3F 81 294 + 06 09 3F 81 06 09 3F 81 06 09 3F 81 06 09 3F 81 295 + 06 C0 05 0C 09 01 A1 01 85 03 09 05 15 00 26 FF 296 + 00 75 08 95 02 B1 02 C0 297 + 298 + After parsing it (try to parse it on your own using the suggested 299 + tools!) one can see that the device presents two ``Mouse`` Application 300 + Collections (with reports identified by Reports IDs 1 and 2, 301 + respectively), a ``Keypad`` Application Collection (whose report is 302 + identified by the Report ID 5) and two ``Consumer Controls`` Application 303 + Collections, (with Report IDs 6 and 3, respectively). Note, however, 304 + that a device can have different Report IDs for the same Application 305 + Collection. 306 + 307 + The data sent will begin with the Report ID byte, and will be followed 308 + by the corresponding information. For example, the data transmitted for 309 + the last consumer control:: 310 + 311 + 0x05, 0x0C, // Usage Page (Consumer) 312 + 0x09, 0x01, // Usage (Consumer Control) 313 + 0xA1, 0x01, // Collection (Application) 314 + 0x85, 0x03, // Report ID (3) 315 + 0x09, 0x05, // Usage (Headphone) 316 + 0x15, 0x00, // Logical Minimum (0) 317 + 0x26, 0xFF, 0x00, // Logical Maximum (255) 318 + 0x75, 0x08, // Report Size (8) 319 + 0x95, 0x02, // Report Count (2) 320 + 0xB1, 0x02, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) 321 + 0xC0, // End Collection 322 + 323 + will be of three bytes: the first for the Report ID (3), the next two 324 + for the headphone, with two (``Report Count (2)``) bytes 325 + (``Report Size (8)``), each ranging from 0 (``Logical Minimum (0)``) 326 + to 255 (``Logical Maximum (255)``). 327 + 328 + All the Input data sent by the device should be translated into 329 + corresponding Evdev events, so that the remaining part of the stack can 330 + know what is going on, e.g. the bit for the first button translates into 331 + the ``EV_KEY/BTN_LEFT`` evdev event and relative X movement translates 332 + into the ``EV_REL/REL_X`` evdev event". 333 + 334 + Events 335 + ====== 336 + 337 + In Linux, one ``/dev/input/event*`` is created for each ``Application 338 + Collection``. Going back to the mouse example, and repeating the 339 + sequence where one clicks and holds button 1, then clicks and holds 340 + button 2, releases button 1, and finally releases button 2, one gets:: 341 + 342 + $ sudo libinput record /dev/input/event1 343 + # libinput record 344 + version: 1 345 + ndevices: 1 346 + libinput: 347 + version: "1.23.0" 348 + git: "unknown" 349 + system: 350 + os: "opensuse-tumbleweed:20230619" 351 + kernel: "6.3.7-1-default" 352 + dmi: "dmi:bvnHP:bvrU77Ver.01.05.00:bd03/24/2022:br5.0:efr20.29:svnHP:pnHPEliteBook64514inchG9NotebookPC:pvr:rvnHP:rn89D2:rvrKBCVersion14.1D.00:cvnHP:ct10:cvr:sku5Y3J1EA#ABZ:" 353 + devices: 354 + - node: /dev/input/event1 355 + evdev: 356 + # Name: PixArt HP USB Optical Mouse 357 + # ID: bus 0x3 vendor 0x3f0 product 0x94a version 0x111 358 + # Supported Events: 359 + # Event type 0 (EV_SYN) 360 + # Event type 1 (EV_KEY) 361 + # Event code 272 (BTN_LEFT) 362 + # Event code 273 (BTN_RIGHT) 363 + # Event code 274 (BTN_MIDDLE) 364 + # Event type 2 (EV_REL) 365 + # Event code 0 (REL_X) 366 + # Event code 1 (REL_Y) 367 + # Event code 8 (REL_WHEEL) 368 + # Event code 11 (REL_WHEEL_HI_RES) 369 + # Event type 4 (EV_MSC) 370 + # Event code 4 (MSC_SCAN) 371 + # Properties: 372 + name: "PixArt HP USB Optical Mouse" 373 + id: [3, 1008, 2378, 273] 374 + codes: 375 + 0: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] # EV_SYN 376 + 1: [272, 273, 274] # EV_KEY 377 + 2: [0, 1, 8, 11] # EV_REL 378 + 4: [4] # EV_MSC 379 + properties: [] 380 + hid: [ 381 + 0x05, 0x01, 0x09, 0x02, 0xa1, 0x01, 0x09, 0x01, 0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03, 382 + 0x15, 0x00, 0x25, 0x01, 0x95, 0x08, 0x75, 0x01, 0x81, 0x02, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 383 + 0x09, 0x38, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x03, 0x81, 0x06, 0xc0, 0xc0 384 + ] 385 + udev: 386 + properties: 387 + - ID_INPUT=1 388 + - ID_INPUT_MOUSE=1 389 + - LIBINPUT_DEVICE_GROUP=3/3f0/94a:usb-0000:05:00.3-2 390 + quirks: 391 + events: 392 + # Current time is 12:31:56 393 + - evdev: 394 + - [ 0, 0, 4, 4, 30] # EV_MSC / MSC_SCAN 30 (obfuscated) 395 + - [ 0, 0, 1, 272, 1] # EV_KEY / BTN_LEFT 1 396 + - [ 0, 0, 0, 0, 0] # ------------ SYN_REPORT (0) ---------- +0ms 397 + - evdev: 398 + - [ 1, 207892, 4, 4, 30] # EV_MSC / MSC_SCAN 30 (obfuscated) 399 + - [ 1, 207892, 1, 273, 1] # EV_KEY / BTN_RIGHT 1 400 + - [ 1, 207892, 0, 0, 0] # ------------ SYN_REPORT (0) ---------- +1207ms 401 + - evdev: 402 + - [ 2, 367823, 4, 4, 30] # EV_MSC / MSC_SCAN 30 (obfuscated) 403 + - [ 2, 367823, 1, 272, 0] # EV_KEY / BTN_LEFT 0 404 + - [ 2, 367823, 0, 0, 0] # ------------ SYN_REPORT (0) ---------- +1160ms 405 + # Current time is 12:32:00 406 + - evdev: 407 + - [ 3, 247617, 4, 4, 30] # EV_MSC / MSC_SCAN 30 (obfuscated) 408 + - [ 3, 247617, 1, 273, 0] # EV_KEY / BTN_RIGHT 0 409 + - [ 3, 247617, 0, 0, 0] # ------------ SYN_REPORT (0) ---------- +880ms 410 + 411 + Note: if ``libinput record`` is not available on your system try using 412 + ``evemu-record``. 413 + 414 + When something does not work 415 + ============================ 416 + 417 + There can be a number of reasons why a device does not behave 418 + correctly. For example 419 + 420 + * The HID report descriptor provided by the HID device may be wrong 421 + because e.g. 422 + 423 + * it does not follow the standard, so that the kernel 424 + will not able to make sense of the HID report descriptor; 425 + * the HID report descriptor *does not match* what is actually 426 + sent by the device (this can be verified by reading the raw HID 427 + data); 428 + * the HID report descriptor may need some "quirks" (see later on). 429 + 430 + As a consequence, a ``/dev/input/event*`` may not be created 431 + for each Application Collection, and/or the events 432 + there may not match what you would expect. 433 + 434 + 435 + Quirks 436 + ------ 437 + 438 + There are some known peculiarities of HID devices that the kernel 439 + knows how to fix - these are called the HID quirks and a list of those 440 + is available in `include/linux/hid.h`. 441 + 442 + Should this be the case, it should be enough to add the required quirk 443 + in the kernel, for the HID device at hand. This can be done in the file 444 + `drivers/hid/hid-quirks.c`. How to do it should be relatively 445 + straightforward after looking into the file. 446 + 447 + The list of currently defined quirks, from `include/linux/hid.h`, is 448 + 449 + .. kernel-doc:: include/linux/hid.h 450 + :doc: HID quirks 451 + 452 + Quirks for USB devices can be specified while loading the usbhid module, 453 + see ``modinfo usbhid``, although the proper fix should go into 454 + hid-quirks.c and **be submitted upstream**. 455 + See Documentation/process/submitting-patches.rst for guidelines on how 456 + to submit a patch. Quirks for other busses need to go into hid-quirks.c. 457 + 458 + Fixing HID report descriptors 459 + ----------------------------- 460 + 461 + Should you need to patch HID report descriptors the easiest way is to 462 + resort to eBPF, as described in Documentation/hid/hid-bpf.rst. 463 + 464 + Basically, you can change any byte of the original HID report 465 + descriptor. The examples in samples/hid should be a good starting point 466 + for your code, see e.g. `samples/hid/hid_mouse.bpf.c`:: 467 + 468 + SEC("fmod_ret/hid_bpf_rdesc_fixup") 469 + int BPF_PROG(hid_rdesc_fixup, struct hid_bpf_ctx *hctx) 470 + { 471 + .... 472 + data[39] = 0x31; 473 + data[41] = 0x30; 474 + return 0; 475 + } 476 + 477 + Of course this can be also done within the kernel source code, see e.g. 478 + `drivers/hid/hid-aureal.c` or `drivers/hid/hid-samsung.c` for a slightly 479 + more complex file. 480 + 481 + Check Documentation/hid/hidreport-parsing.rst if you need any help 482 + navigating the HID manuals and understanding the exact meaning of 483 + the HID report descriptor hex numbers. 484 + 485 + Whatever solution you come up with, please remember to **submit the 486 + fix to the HID maintainers**, so that it can be directly integrated in 487 + the kernel and that particular HID device will start working for 488 + everyone else. See Documentation/process/submitting-patches.rst for 489 + guidelines on how to do this. 490 + 491 + 492 + Modifying the transmitted data on the fly 493 + ----------------------------------------- 494 + 495 + Using eBPF it is also possible to modify the data exchanged with the 496 + device. See again the examples in `samples/hid`. 497 + 498 + Again, **please post your fix**, so that it can be integrated in the 499 + kernel! 500 + 501 + Writing a specialized driver 502 + ---------------------------- 503 + 504 + This should really be your last resort. 505 + 506 + 507 + .. rubric:: Footnotes 508 + 509 + .. [#hidraw] read hidraw: see Documentation/hid/hidraw.rst and 510 + file `samples/hidraw/hid-example.c` for an example. 511 + The output of ``hid-example`` would be, for the same mouse:: 512 + 513 + $ sudo ./hid-example 514 + Report Descriptor Size: 52 515 + Report Descriptor: 516 + 5 1 9 2 a1 1 9 1 a1 0 5 9 19 1 29 3 15 0 25 1 75 1 95 3 81 2 75 5 95 1 81 1 5 1 9 30 9 31 9 38 15 81 25 7f 75 8 95 3 81 6 c0 c0 517 + 518 + Raw Name: PixArt USB Optical Mouse 519 + Raw Phys: usb-0000:05:00.4-2.3/input0 520 + Raw Info: 521 + bustype: 3 (USB) 522 + vendor: 0x093a 523 + product: 0x2510 524 + ...
+49
Documentation/hid/hidreport-parsing.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + ======================================== 4 + Manual parsing of HID report descriptors 5 + ======================================== 6 + 7 + Consider again the mouse HID report descriptor 8 + introduced in Documentation/hid/hidintro.rst:: 9 + 10 + $ hexdump -C /sys/bus/hid/devices/0003\:093A\:2510.0002/report_descriptor 11 + 00000000 05 01 09 02 a1 01 09 01 a1 00 05 09 19 01 29 03 |..............).| 12 + 00000010 15 00 25 01 75 01 95 03 81 02 75 05 95 01 81 01 |..%.u.....u.....| 13 + 00000020 05 01 09 30 09 31 09 38 15 81 25 7f 75 08 95 03 |...0.1.8..%.u...| 14 + 00000030 81 06 c0 c0 |....| 15 + 00000034 16 + 17 + and try to parse it by hand. 18 + 19 + Start with the first number, 0x05: it carries 2 bits for the 20 + length of the item, 2 bits for the type of the item and 4 bits for the 21 + function:: 22 + 23 + +----------+ 24 + | 00000101 | 25 + +----------+ 26 + ^^ 27 + ---- Length of data (see HID spec 6.2.2.2) 28 + ^^ 29 + ------ Type of the item (see HID spec 6.2.2.2, then jump to 6.2.2.7) 30 + ^^^^ 31 + --------- Function of the item (see HID spec 6.2.2.7, then HUT Sec 3) 32 + 33 + In our case, the length is 1 byte, the type is ``Global`` and the 34 + function is ``Usage Page``, thus for parsing the value 0x01 in the second byte 35 + we need to refer to HUT Sec 3. 36 + 37 + The second number is the actual data, and its meaning can be found in 38 + the HUT. We have a ``Usage Page``, thus we need to refer to HUT 39 + Sec. 3, "Usage Pages"; from there, one sees that ``0x01`` stands for 40 + ``Generic Desktop Page``. 41 + 42 + Moving now to the second two bytes, and following the same scheme, 43 + ``0x09`` (i.e. ``00001001``) will be followed by one byte (``01``) 44 + and is a ``Local`` item (``10``). Thus, the meaning of the remaining four bits 45 + (``0000``) is given in the HID spec Sec. 6.2.2.8 "Local Items", so that 46 + we have a ``Usage``. From HUT, Sec. 4, "Generic Desktop Page", we see that 47 + 0x02 stands for ``Mouse``. 48 + 49 + The following numbers can be parsed in the same way.
+1
Documentation/hid/index.rst
··· 7 7 .. toctree:: 8 8 :maxdepth: 1 9 9 10 + hidintro 10 11 hiddev 11 12 hidraw 12 13 hid-sensor
+2 -2
MAINTAINERS
··· 21987 21987 F: fs/ufs/ 21988 21988 21989 21989 UHID USERSPACE HID IO DRIVER 21990 - M: David Rheinsberg <david.rheinsberg@gmail.com> 21990 + M: David Rheinsberg <david@readahead.eu> 21991 21991 L: linux-input@vger.kernel.org 21992 21992 S: Maintained 21993 21993 F: drivers/hid/uhid.c ··· 23159 23159 F: drivers/rtc/rtc-sd3078.c 23160 23160 23161 23161 WIIMOTE HID DRIVER 23162 - M: David Rheinsberg <david.rheinsberg@gmail.com> 23162 + M: David Rheinsberg <david@readahead.eu> 23163 23163 L: linux-input@vger.kernel.org 23164 23164 S: Maintained 23165 23165 F: drivers/hid/hid-wiimote*
+11 -2
drivers/hid/Kconfig
··· 412 412 help 413 413 Say Y here if you have a Google Hammer device. 414 414 415 + config HID_GOOGLE_STADIA_FF 416 + tristate "Google Stadia force feedback" 417 + select INPUT_FF_MEMLESS 418 + help 419 + Say Y here if you want to enable force feedback support for the Google 420 + Stadia controller. 421 + 415 422 config HID_VIVALDI 416 423 tristate "Vivaldi Keyboard" 417 424 select HID_VIVALDI_COMMON ··· 1073 1066 Deck. 1074 1067 1075 1068 config HID_STEELSERIES 1076 - tristate "Steelseries SRW-S1 steering wheel support" 1069 + tristate "Steelseries devices support" 1070 + depends on USB_HID 1077 1071 help 1078 - Support for Steelseries SRW-S1 steering wheel 1072 + Support for Steelseries SRW-S1 steering wheel, and the Steelseries 1073 + Arctis 1 Wireless for XBox headset. 1079 1074 1080 1075 config HID_SUNPLUS 1081 1076 tristate "Sunplus wireless desktop"
+1
drivers/hid/Makefile
··· 55 55 obj-$(CONFIG_HID_GLORIOUS) += hid-glorious.o 56 56 obj-$(CONFIG_HID_VIVALDI_COMMON) += hid-vivaldi-common.o 57 57 obj-$(CONFIG_HID_GOOGLE_HAMMER) += hid-google-hammer.o 58 + obj-$(CONFIG_HID_GOOGLE_STADIA_FF) += hid-google-stadiaff.o 58 59 obj-$(CONFIG_HID_VIVALDI) += hid-vivaldi.o 59 60 obj-$(CONFIG_HID_GT683R) += hid-gt683r.o 60 61 obj-$(CONFIG_HID_GYRATION) += hid-gyration.o
+2 -1
drivers/hid/hid-apple.c
··· 343 343 { "SONiX USB DEVICE" }, 344 344 { "Keychron" }, 345 345 { "AONE" }, 346 - { "GANSS" } 346 + { "GANSS" }, 347 + { "Hailuck" }, 347 348 }; 348 349 349 350 static bool apple_is_non_apple_keyboard(struct hid_device *hdev)
+57 -112
drivers/hid/hid-cp2112.c
··· 16 16 * https://www.silabs.com/documents/public/application-notes/an495-cp2112-interface-specification.pdf 17 17 */ 18 18 19 - #include <linux/gpio/consumer.h> 20 - #include <linux/gpio/machine.h> 19 + #include <linux/bitops.h> 21 20 #include <linux/gpio/driver.h> 22 21 #include <linux/hid.h> 23 22 #include <linux/hidraw.h> 24 23 #include <linux/i2c.h> 25 24 #include <linux/module.h> 26 25 #include <linux/nls.h> 26 + #include <linux/string_choices.h> 27 27 #include <linux/usb/ch9.h> 28 28 #include "hid-ids.h" 29 29 ··· 31 31 #define CP2112_GPIO_CONFIG_LENGTH 5 32 32 #define CP2112_GPIO_GET_LENGTH 2 33 33 #define CP2112_GPIO_SET_LENGTH 3 34 + #define CP2112_GPIO_MAX_GPIO 8 35 + #define CP2112_GPIO_ALL_GPIO_MASK GENMASK(7, 0) 34 36 35 37 enum { 36 38 CP2112_GPIO_CONFIG = 0x02, ··· 165 163 atomic_t read_avail; 166 164 atomic_t xfer_avail; 167 165 struct gpio_chip gc; 168 - struct irq_chip irq; 169 166 u8 *in_out_buffer; 170 167 struct mutex lock; 171 168 172 - struct gpio_desc *desc[8]; 173 169 bool gpio_poll; 174 170 struct delayed_work gpio_poll_worker; 175 171 unsigned long irq_mask; 176 172 u8 gpio_prev_state; 177 173 }; 178 174 179 - static int gpio_push_pull = 0xFF; 180 - module_param(gpio_push_pull, int, S_IRUGO | S_IWUSR); 175 + static int gpio_push_pull = CP2112_GPIO_ALL_GPIO_MASK; 176 + module_param(gpio_push_pull, int, 0644); 181 177 MODULE_PARM_DESC(gpio_push_pull, "GPIO push-pull configuration bitmask"); 182 178 183 179 static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset) ··· 197 197 goto exit; 198 198 } 199 199 200 - buf[1] &= ~(1 << offset); 200 + buf[1] &= ~BIT(offset); 201 201 buf[2] = gpio_push_pull; 202 202 203 203 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, ··· 227 227 mutex_lock(&dev->lock); 228 228 229 229 buf[0] = CP2112_GPIO_SET; 230 - buf[1] = value ? 0xff : 0; 231 - buf[2] = 1 << offset; 230 + buf[1] = value ? CP2112_GPIO_ALL_GPIO_MASK : 0; 231 + buf[2] = BIT(offset); 232 232 233 233 ret = hid_hw_raw_request(hdev, CP2112_GPIO_SET, buf, 234 234 CP2112_GPIO_SET_LENGTH, HID_FEATURE_REPORT, ··· 532 532 hid_dbg(hdev, "I2C %d messages\n", num); 533 533 534 534 if (num == 1) { 535 + hid_dbg(hdev, "I2C %s %#04x len %d\n", 536 + str_read_write(msgs->flags & I2C_M_RD), msgs->addr, msgs->len); 535 537 if (msgs->flags & I2C_M_RD) { 536 - hid_dbg(hdev, "I2C read %#04x len %d\n", 537 - msgs->addr, msgs->len); 538 538 read_length = msgs->len; 539 539 read_buf = msgs->buf; 540 540 count = cp2112_read_req(buf, msgs->addr, msgs->len); 541 541 } else { 542 - hid_dbg(hdev, "I2C write %#04x len %d\n", 543 - msgs->addr, msgs->len); 544 542 count = cp2112_i2c_write_req(buf, msgs->addr, 545 543 msgs->buf, msgs->len); 546 544 } ··· 646 648 int ret; 647 649 648 650 hid_dbg(hdev, "%s addr 0x%x flags 0x%x cmd 0x%x size %d\n", 649 - read_write == I2C_SMBUS_WRITE ? "write" : "read", 651 + str_write_read(read_write == I2C_SMBUS_WRITE), 650 652 addr, flags, command, size); 651 653 652 654 switch (size) { ··· 893 895 int ret = cp2112_get_usb_config(hdev, &cfg); \ 894 896 if (ret) \ 895 897 return ret; \ 896 - return scnprintf(buf, PAGE_SIZE, format, ##__VA_ARGS__); \ 898 + return sysfs_emit(buf, format, ##__VA_ARGS__); \ 897 899 } \ 898 900 static DEVICE_ATTR_RW(name); 899 901 ··· 944 946 945 947 #undef CP2112_CONFIG_ATTR 946 948 947 - struct cp2112_pstring_attribute { 948 - struct device_attribute attr; 949 - unsigned char report; 950 - }; 951 - 952 - static ssize_t pstr_store(struct device *kdev, 953 - struct device_attribute *kattr, const char *buf, 954 - size_t count) 949 + static ssize_t pstr_store(struct device *kdev, struct device_attribute *kattr, 950 + const char *buf, size_t count, int number) 955 951 { 956 952 struct hid_device *hdev = to_hid_device(kdev); 957 - struct cp2112_pstring_attribute *attr = 958 - container_of(kattr, struct cp2112_pstring_attribute, attr); 959 953 struct cp2112_string_report report; 960 954 int ret; 961 955 ··· 955 965 956 966 ret = utf8s_to_utf16s(buf, count, UTF16_LITTLE_ENDIAN, 957 967 report.string, ARRAY_SIZE(report.string)); 958 - report.report = attr->report; 968 + report.report = number; 959 969 report.length = ret * sizeof(report.string[0]) + 2; 960 970 report.type = USB_DT_STRING; 961 971 ··· 973 983 return count; 974 984 } 975 985 976 - static ssize_t pstr_show(struct device *kdev, 977 - struct device_attribute *kattr, char *buf) 986 + static ssize_t pstr_show(struct device *kdev, struct device_attribute *kattr, 987 + char *buf, int number) 978 988 { 979 989 struct hid_device *hdev = to_hid_device(kdev); 980 - struct cp2112_pstring_attribute *attr = 981 - container_of(kattr, struct cp2112_pstring_attribute, attr); 982 990 struct cp2112_string_report report; 983 991 u8 length; 984 992 int ret; 985 993 986 - ret = cp2112_hid_get(hdev, attr->report, (u8 *)&report.contents, 994 + ret = cp2112_hid_get(hdev, number, (u8 *)&report.contents, 987 995 sizeof(report.contents), HID_FEATURE_REPORT); 988 996 if (ret < 3) { 989 997 hid_err(hdev, "error reading %s string: %d\n", kattr->attr.name, ··· 1006 1018 } 1007 1019 1008 1020 #define CP2112_PSTR_ATTR(name, _report) \ 1009 - static struct cp2112_pstring_attribute dev_attr_##name = { \ 1010 - .attr = __ATTR(name, (S_IWUSR | S_IRUGO), pstr_show, pstr_store), \ 1011 - .report = _report, \ 1012 - }; 1021 + static ssize_t name##_store(struct device *kdev, struct device_attribute *kattr, \ 1022 + const char *buf, size_t count) \ 1023 + { \ 1024 + return pstr_store(kdev, kattr, buf, count, _report); \ 1025 + } \ 1026 + static ssize_t name##_show(struct device *kdev, struct device_attribute *kattr, char *buf) \ 1027 + { \ 1028 + return pstr_show(kdev, kattr, buf, _report); \ 1029 + } \ 1030 + static DEVICE_ATTR_RW(name); 1013 1031 1014 1032 CP2112_PSTR_ATTR(manufacturer, CP2112_MANUFACTURER_STRING); 1015 1033 CP2112_PSTR_ATTR(product, CP2112_PRODUCT_STRING); ··· 1030 1036 &dev_attr_max_power.attr, 1031 1037 &dev_attr_power_mode.attr, 1032 1038 &dev_attr_release_version.attr, 1033 - &dev_attr_manufacturer.attr.attr, 1034 - &dev_attr_product.attr.attr, 1035 - &dev_attr_serial.attr.attr, 1039 + &dev_attr_manufacturer.attr, 1040 + &dev_attr_product.attr, 1041 + &dev_attr_serial.attr, 1036 1042 NULL 1037 1043 } 1038 1044 }; ··· 1057 1063 } 1058 1064 1059 1065 for (attr = cp2112_attr_group.attrs; *attr; ++attr) { 1060 - umode_t mode = (buf[1] & 1) ? S_IWUSR | S_IRUGO : S_IRUGO; 1066 + umode_t mode = (buf[1] & 1) ? 0644 : 0444; 1061 1067 ret = sysfs_chmod_file(&hdev->dev.kobj, *attr, mode); 1062 1068 if (ret < 0) 1063 1069 hid_err(hdev, "error chmoding sysfs file %s\n", ··· 1074 1080 { 1075 1081 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1076 1082 struct cp2112_device *dev = gpiochip_get_data(gc); 1083 + irq_hw_number_t hwirq = irqd_to_hwirq(d); 1077 1084 1078 - __clear_bit(d->hwirq, &dev->irq_mask); 1085 + __clear_bit(hwirq, &dev->irq_mask); 1086 + gpiochip_disable_irq(gc, hwirq); 1079 1087 } 1080 1088 1081 1089 static void cp2112_gpio_irq_unmask(struct irq_data *d) 1082 1090 { 1083 1091 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1084 1092 struct cp2112_device *dev = gpiochip_get_data(gc); 1093 + irq_hw_number_t hwirq = irqd_to_hwirq(d); 1085 1094 1086 - __set_bit(d->hwirq, &dev->irq_mask); 1095 + gpiochip_enable_irq(gc, hwirq); 1096 + __set_bit(hwirq, &dev->irq_mask); 1087 1097 } 1088 1098 1089 1099 static void cp2112_gpio_poll_callback(struct work_struct *work) ··· 1096 1098 gpio_poll_worker.work); 1097 1099 struct irq_data *d; 1098 1100 u8 gpio_mask; 1099 - u8 virqs = (u8)dev->irq_mask; 1100 1101 u32 irq_type; 1101 1102 int irq, virq, ret; 1102 1103 ··· 1106 1109 goto exit; 1107 1110 1108 1111 gpio_mask = ret; 1109 - 1110 - while (virqs) { 1111 - virq = ffs(virqs) - 1; 1112 - virqs &= ~BIT(virq); 1113 - 1114 - if (!dev->gc.to_irq) 1115 - break; 1116 - 1117 - irq = dev->gc.to_irq(&dev->gc, virq); 1112 + for_each_set_bit(virq, &dev->irq_mask, CP2112_GPIO_MAX_GPIO) { 1113 + irq = irq_find_mapping(dev->gc.irq.domain, virq); 1114 + if (!irq) 1115 + continue; 1118 1116 1119 1117 d = irq_get_irq_data(irq); 1120 1118 if (!d) ··· 1167 1175 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1168 1176 struct cp2112_device *dev = gpiochip_get_data(gc); 1169 1177 1178 + cp2112_gpio_irq_mask(d); 1170 1179 cancel_delayed_work_sync(&dev->gpio_poll_worker); 1171 1180 } 1172 1181 ··· 1176 1183 return 0; 1177 1184 } 1178 1185 1179 - static int __maybe_unused cp2112_allocate_irq(struct cp2112_device *dev, 1180 - int pin) 1181 - { 1182 - int ret; 1183 - 1184 - if (dev->desc[pin]) 1185 - return -EINVAL; 1186 - 1187 - dev->desc[pin] = gpiochip_request_own_desc(&dev->gc, pin, 1188 - "HID/I2C:Event", 1189 - GPIO_ACTIVE_HIGH, 1190 - GPIOD_IN); 1191 - if (IS_ERR(dev->desc[pin])) { 1192 - dev_err(dev->gc.parent, "Failed to request GPIO\n"); 1193 - return PTR_ERR(dev->desc[pin]); 1194 - } 1195 - 1196 - ret = cp2112_gpio_direction_input(&dev->gc, pin); 1197 - if (ret < 0) { 1198 - dev_err(dev->gc.parent, "Failed to set GPIO to input dir\n"); 1199 - goto err_desc; 1200 - } 1201 - 1202 - ret = gpiochip_lock_as_irq(&dev->gc, pin); 1203 - if (ret) { 1204 - dev_err(dev->gc.parent, "Failed to lock GPIO as interrupt\n"); 1205 - goto err_desc; 1206 - } 1207 - 1208 - ret = gpiod_to_irq(dev->desc[pin]); 1209 - if (ret < 0) { 1210 - dev_err(dev->gc.parent, "Failed to translate GPIO to IRQ\n"); 1211 - goto err_lock; 1212 - } 1213 - 1214 - return ret; 1215 - 1216 - err_lock: 1217 - gpiochip_unlock_as_irq(&dev->gc, pin); 1218 - err_desc: 1219 - gpiochip_free_own_desc(dev->desc[pin]); 1220 - dev->desc[pin] = NULL; 1221 - return ret; 1222 - } 1186 + static const struct irq_chip cp2112_gpio_irqchip = { 1187 + .name = "cp2112-gpio", 1188 + .irq_startup = cp2112_gpio_irq_startup, 1189 + .irq_shutdown = cp2112_gpio_irq_shutdown, 1190 + .irq_ack = cp2112_gpio_irq_ack, 1191 + .irq_mask = cp2112_gpio_irq_mask, 1192 + .irq_unmask = cp2112_gpio_irq_unmask, 1193 + .irq_set_type = cp2112_gpio_irq_type, 1194 + .flags = IRQCHIP_MASK_ON_SUSPEND | IRQCHIP_IMMUTABLE, 1195 + GPIOCHIP_IRQ_RESOURCE_HELPERS, 1196 + }; 1223 1197 1224 1198 static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id) 1225 1199 { ··· 1293 1333 dev->gc.set = cp2112_gpio_set; 1294 1334 dev->gc.get = cp2112_gpio_get; 1295 1335 dev->gc.base = -1; 1296 - dev->gc.ngpio = 8; 1336 + dev->gc.ngpio = CP2112_GPIO_MAX_GPIO; 1297 1337 dev->gc.can_sleep = 1; 1298 1338 dev->gc.parent = &hdev->dev; 1299 1339 1300 - dev->irq.name = "cp2112-gpio"; 1301 - dev->irq.irq_startup = cp2112_gpio_irq_startup; 1302 - dev->irq.irq_shutdown = cp2112_gpio_irq_shutdown; 1303 - dev->irq.irq_ack = cp2112_gpio_irq_ack; 1304 - dev->irq.irq_mask = cp2112_gpio_irq_mask; 1305 - dev->irq.irq_unmask = cp2112_gpio_irq_unmask; 1306 - dev->irq.irq_set_type = cp2112_gpio_irq_type; 1307 - dev->irq.flags = IRQCHIP_MASK_ON_SUSPEND; 1308 - 1309 1340 girq = &dev->gc.irq; 1310 - girq->chip = &dev->irq; 1341 + gpio_irq_chip_set_chip(girq, &cp2112_gpio_irqchip); 1311 1342 /* The event comes from the outside so no parent handler */ 1312 1343 girq->parent_handler = NULL; 1313 1344 girq->num_parents = 0; ··· 1340 1389 static void cp2112_remove(struct hid_device *hdev) 1341 1390 { 1342 1391 struct cp2112_device *dev = hid_get_drvdata(hdev); 1343 - int i; 1344 1392 1345 1393 sysfs_remove_group(&hdev->dev.kobj, &cp2112_attr_group); 1346 1394 i2c_del_adapter(&dev->adap); ··· 1347 1397 if (dev->gpio_poll) { 1348 1398 dev->gpio_poll = false; 1349 1399 cancel_delayed_work_sync(&dev->gpio_poll_worker); 1350 - } 1351 - 1352 - for (i = 0; i < ARRAY_SIZE(dev->desc); i++) { 1353 - gpiochip_unlock_as_irq(&dev->gc, i); 1354 - gpiochip_free_own_desc(dev->desc[i]); 1355 1400 } 1356 1401 1357 1402 gpiochip_remove(&dev->gc);
+158
drivers/hid/hid-google-stadiaff.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Stadia controller rumble support. 4 + * 5 + * Copyright 2023 Google LLC 6 + */ 7 + 8 + #include <linux/hid.h> 9 + #include <linux/input.h> 10 + #include <linux/slab.h> 11 + #include <linux/module.h> 12 + 13 + #include "hid-ids.h" 14 + 15 + #define STADIA_FF_REPORT_ID 5 16 + 17 + struct stadiaff_device { 18 + struct hid_device *hid; 19 + struct hid_report *report; 20 + spinlock_t lock; 21 + bool removed; 22 + uint16_t strong_magnitude; 23 + uint16_t weak_magnitude; 24 + struct work_struct work; 25 + }; 26 + 27 + static void stadiaff_work(struct work_struct *work) 28 + { 29 + struct stadiaff_device *stadiaff = 30 + container_of(work, struct stadiaff_device, work); 31 + struct hid_field *rumble_field = stadiaff->report->field[0]; 32 + unsigned long flags; 33 + 34 + spin_lock_irqsave(&stadiaff->lock, flags); 35 + rumble_field->value[0] = stadiaff->strong_magnitude; 36 + rumble_field->value[1] = stadiaff->weak_magnitude; 37 + spin_unlock_irqrestore(&stadiaff->lock, flags); 38 + 39 + hid_hw_request(stadiaff->hid, stadiaff->report, HID_REQ_SET_REPORT); 40 + } 41 + 42 + static int stadiaff_play(struct input_dev *dev, void *data, 43 + struct ff_effect *effect) 44 + { 45 + struct hid_device *hid = input_get_drvdata(dev); 46 + struct stadiaff_device *stadiaff = hid_get_drvdata(hid); 47 + unsigned long flags; 48 + 49 + spin_lock_irqsave(&stadiaff->lock, flags); 50 + if (!stadiaff->removed) { 51 + stadiaff->strong_magnitude = effect->u.rumble.strong_magnitude; 52 + stadiaff->weak_magnitude = effect->u.rumble.weak_magnitude; 53 + schedule_work(&stadiaff->work); 54 + } 55 + spin_unlock_irqrestore(&stadiaff->lock, flags); 56 + 57 + return 0; 58 + } 59 + 60 + static int stadiaff_init(struct hid_device *hid) 61 + { 62 + struct stadiaff_device *stadiaff; 63 + struct hid_report *report; 64 + struct hid_input *hidinput; 65 + struct input_dev *dev; 66 + int error; 67 + 68 + if (list_empty(&hid->inputs)) { 69 + hid_err(hid, "no inputs found\n"); 70 + return -ENODEV; 71 + } 72 + hidinput = list_entry(hid->inputs.next, struct hid_input, list); 73 + dev = hidinput->input; 74 + 75 + report = hid_validate_values(hid, HID_OUTPUT_REPORT, 76 + STADIA_FF_REPORT_ID, 0, 2); 77 + if (!report) 78 + return -ENODEV; 79 + 80 + stadiaff = devm_kzalloc(&hid->dev, sizeof(struct stadiaff_device), 81 + GFP_KERNEL); 82 + if (!stadiaff) 83 + return -ENOMEM; 84 + 85 + hid_set_drvdata(hid, stadiaff); 86 + 87 + input_set_capability(dev, EV_FF, FF_RUMBLE); 88 + 89 + error = input_ff_create_memless(dev, NULL, stadiaff_play); 90 + if (error) 91 + return error; 92 + 93 + stadiaff->removed = false; 94 + stadiaff->hid = hid; 95 + stadiaff->report = report; 96 + INIT_WORK(&stadiaff->work, stadiaff_work); 97 + spin_lock_init(&stadiaff->lock); 98 + 99 + hid_info(hid, "Force Feedback for Google Stadia controller\n"); 100 + 101 + return 0; 102 + } 103 + 104 + static int stadia_probe(struct hid_device *hdev, const struct hid_device_id *id) 105 + { 106 + int ret; 107 + 108 + ret = hid_parse(hdev); 109 + if (ret) { 110 + hid_err(hdev, "parse failed\n"); 111 + return ret; 112 + } 113 + 114 + ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); 115 + if (ret) { 116 + hid_err(hdev, "hw start failed\n"); 117 + return ret; 118 + } 119 + 120 + ret = stadiaff_init(hdev); 121 + if (ret) { 122 + hid_err(hdev, "force feedback init failed\n"); 123 + hid_hw_stop(hdev); 124 + return ret; 125 + } 126 + 127 + return 0; 128 + } 129 + 130 + static void stadia_remove(struct hid_device *hid) 131 + { 132 + struct stadiaff_device *stadiaff = hid_get_drvdata(hid); 133 + unsigned long flags; 134 + 135 + spin_lock_irqsave(&stadiaff->lock, flags); 136 + stadiaff->removed = true; 137 + spin_unlock_irqrestore(&stadiaff->lock, flags); 138 + 139 + cancel_work_sync(&stadiaff->work); 140 + hid_hw_stop(hid); 141 + } 142 + 143 + static const struct hid_device_id stadia_devices[] = { 144 + { HID_USB_DEVICE(USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_STADIA) }, 145 + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_STADIA) }, 146 + { } 147 + }; 148 + MODULE_DEVICE_TABLE(hid, stadia_devices); 149 + 150 + static struct hid_driver stadia_driver = { 151 + .name = "stadia", 152 + .id_table = stadia_devices, 153 + .probe = stadia_probe, 154 + .remove = stadia_remove, 155 + }; 156 + module_hid_driver(stadia_driver); 157 + 158 + MODULE_LICENSE("GPL");
+2
drivers/hid/hid-ids.h
··· 531 531 #define USB_DEVICE_ID_GOOGLE_DON 0x5050 532 532 #define USB_DEVICE_ID_GOOGLE_EEL 0x5057 533 533 #define USB_DEVICE_ID_GOOGLE_JEWEL 0x5061 534 + #define USB_DEVICE_ID_GOOGLE_STADIA 0x9400 534 535 535 536 #define USB_VENDOR_ID_GOTOP 0x08f2 536 537 #define USB_DEVICE_ID_SUPER_Q2 0x007f ··· 867 866 #define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_2 0xc534 868 867 #define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1 0xc539 869 868 #define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_1 0xc53f 869 + #define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_2 0xc547 870 870 #define USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_POWERPLAY 0xc53a 871 871 #define USB_DEVICE_ID_SPACETRAVELLER 0xc623 872 872 #define USB_DEVICE_ID_SPACENAVIGATOR 0xc626
+19 -2
drivers/hid/hid-input.c
··· 358 358 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 359 359 USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI), 360 360 HID_BATTERY_QUIRK_PERCENT | HID_BATTERY_QUIRK_FEATURE }, 361 + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 362 + USB_DEVICE_ID_APPLE_MAGICTRACKPAD), 363 + HID_BATTERY_QUIRK_IGNORE }, 361 364 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, 362 365 USB_DEVICE_ID_ELECOM_BM084), 363 366 HID_BATTERY_QUIRK_IGNORE }, ··· 991 988 return; 992 989 993 990 case 0x3c: /* Invert */ 991 + device->quirks &= ~HID_QUIRK_NOINVERT; 994 992 map_key_clear(BTN_TOOL_RUBBER); 995 993 break; 996 994 ··· 1017 1013 case 0x45: /* ERASER */ 1018 1014 /* 1019 1015 * This event is reported when eraser tip touches the surface. 1020 - * Actual eraser (BTN_TOOL_RUBBER) is set by Invert usage when 1021 - * tool gets in proximity. 1016 + * Actual eraser (BTN_TOOL_RUBBER) is set and released either 1017 + * by Invert if tool reports proximity or by Eraser directly. 1022 1018 */ 1019 + if (!test_bit(BTN_TOOL_RUBBER, input->keybit)) { 1020 + device->quirks |= HID_QUIRK_NOINVERT; 1021 + set_bit(BTN_TOOL_RUBBER, input->keybit); 1022 + } 1023 1023 map_key_clear(BTN_TOUCH); 1024 1024 break; 1025 1025 ··· 1588 1580 else if (report->tool != BTN_TOOL_RUBBER) 1589 1581 /* value is off, tool is not rubber, ignore */ 1590 1582 return; 1583 + else if (*quirks & HID_QUIRK_NOINVERT && 1584 + !test_bit(BTN_TOUCH, input->key)) { 1585 + /* 1586 + * There is no invert to release the tool, let hid_input 1587 + * send BTN_TOUCH with scancode and release the tool after. 1588 + */ 1589 + hid_report_release_tool(report, input, BTN_TOOL_RUBBER); 1590 + return; 1591 + } 1591 1592 1592 1593 /* let hid-input set BTN_TOUCH */ 1593 1594 break;
+12 -4
drivers/hid/hid-logitech-dj.c
··· 1285 1285 * 50 msec should gives enough time to the receiver to be ready. 1286 1286 */ 1287 1287 msleep(50); 1288 + 1289 + if (retval) 1290 + return retval; 1288 1291 } 1289 1292 1290 1293 /* ··· 1309 1306 buf[5] = 0x09; 1310 1307 buf[6] = 0x00; 1311 1308 1312 - hid_hw_raw_request(hdev, REPORT_ID_HIDPP_SHORT, buf, 1309 + retval = hid_hw_raw_request(hdev, REPORT_ID_HIDPP_SHORT, buf, 1313 1310 HIDPP_REPORT_SHORT_LENGTH, HID_OUTPUT_REPORT, 1314 1311 HID_REQ_SET_REPORT); 1315 1312 ··· 1695 1692 } 1696 1693 /* 1697 1694 * Mouse-only receivers send unnumbered mouse data. The 27 MHz 1698 - * receiver uses 6 byte packets, the nano receiver 8 bytes. 1695 + * receiver uses 6 byte packets, the nano receiver 8 bytes, 1696 + * the lightspeed receiver (Pro X Superlight) 13 bytes. 1699 1697 */ 1700 1698 if (djrcv_dev->unnumbered_application == HID_GD_MOUSE && 1701 - size <= 8) { 1702 - u8 mouse_report[9]; 1699 + size <= 13){ 1700 + u8 mouse_report[14]; 1703 1701 1704 1702 /* Prepend report id */ 1705 1703 mouse_report[0] = REPORT_TYPE_MOUSE; ··· 1983 1979 { /* Logitech lightspeed receiver (0xc53f) */ 1984 1980 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 1985 1981 USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_1), 1982 + .driver_data = recvr_type_gaming_hidpp}, 1983 + { /* Logitech lightspeed receiver (0xc547) */ 1984 + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 1985 + USB_DEVICE_ID_LOGITECH_NANO_RECEIVER_LIGHTSPEED_1_2), 1986 1986 .driver_data = recvr_type_gaming_hidpp}, 1987 1987 1988 1988 { /* Logitech 27 MHz HID++ 1.0 receiver (0xc513) */
+84 -45
drivers/hid/hid-logitech-hidpp.c
··· 228 228 #define HIDPP20_ERROR_INVALID_ARGS 0x02 229 229 #define HIDPP20_ERROR_OUT_OF_RANGE 0x03 230 230 #define HIDPP20_ERROR_HW_ERROR 0x04 231 - #define HIDPP20_ERROR_LOGITECH_INTERNAL 0x05 231 + #define HIDPP20_ERROR_NOT_ALLOWED 0x05 232 232 #define HIDPP20_ERROR_INVALID_FEATURE_INDEX 0x06 233 233 #define HIDPP20_ERROR_INVALID_FUNCTION_ID 0x07 234 234 #define HIDPP20_ERROR_BUSY 0x08 ··· 275 275 } 276 276 277 277 /* 278 - * hidpp_send_message_sync() returns 0 in case of success, and something else 279 - * in case of a failure. 280 - * - If ' something else' is positive, that means that an error has been raised 281 - * by the protocol itself. 282 - * - If ' something else' is negative, that means that we had a classic error 283 - * (-ENOMEM, -EPIPE, etc...) 278 + * Effectively send the message to the device, waiting for its answer. 279 + * 280 + * Must be called with hidpp->send_mutex locked 281 + * 282 + * Same return protocol than hidpp_send_message_sync(): 283 + * - success on 0 284 + * - negative error means transport error 285 + * - positive value means protocol error 284 286 */ 285 - static int hidpp_send_message_sync(struct hidpp_device *hidpp, 287 + static int __do_hidpp_send_message_sync(struct hidpp_device *hidpp, 286 288 struct hidpp_report *message, 287 289 struct hidpp_report *response) 288 290 { 289 - int ret = -1; 290 - int max_retries = 3; 291 + int ret; 291 292 292 - mutex_lock(&hidpp->send_mutex); 293 + __must_hold(&hidpp->send_mutex); 293 294 294 295 hidpp->send_receive_buf = response; 295 296 hidpp->answer_available = false; ··· 301 300 */ 302 301 *response = *message; 303 302 304 - for (; max_retries != 0 && ret; max_retries--) { 305 - ret = __hidpp_send_report(hidpp->hid_dev, message); 306 - 307 - if (ret) { 308 - dbg_hid("__hidpp_send_report returned err: %d\n", ret); 309 - memset(response, 0, sizeof(struct hidpp_report)); 310 - break; 311 - } 312 - 313 - if (!wait_event_timeout(hidpp->wait, hidpp->answer_available, 314 - 5*HZ)) { 315 - dbg_hid("%s:timeout waiting for response\n", __func__); 316 - memset(response, 0, sizeof(struct hidpp_report)); 317 - ret = -ETIMEDOUT; 318 - break; 319 - } 320 - 321 - if (response->report_id == REPORT_ID_HIDPP_SHORT && 322 - response->rap.sub_id == HIDPP_ERROR) { 323 - ret = response->rap.params[1]; 324 - dbg_hid("%s:got hidpp error %02X\n", __func__, ret); 325 - break; 326 - } 327 - 328 - if ((response->report_id == REPORT_ID_HIDPP_LONG || 329 - response->report_id == REPORT_ID_HIDPP_VERY_LONG) && 330 - response->fap.feature_index == HIDPP20_ERROR) { 331 - ret = response->fap.params[1]; 332 - if (ret != HIDPP20_ERROR_BUSY) { 333 - dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret); 334 - break; 335 - } 336 - dbg_hid("%s:got busy hidpp 2.0 error %02X, retrying\n", __func__, ret); 337 - } 303 + ret = __hidpp_send_report(hidpp->hid_dev, message); 304 + if (ret) { 305 + dbg_hid("__hidpp_send_report returned err: %d\n", ret); 306 + memset(response, 0, sizeof(struct hidpp_report)); 307 + return ret; 338 308 } 309 + 310 + if (!wait_event_timeout(hidpp->wait, hidpp->answer_available, 311 + 5*HZ)) { 312 + dbg_hid("%s:timeout waiting for response\n", __func__); 313 + memset(response, 0, sizeof(struct hidpp_report)); 314 + return -ETIMEDOUT; 315 + } 316 + 317 + if (response->report_id == REPORT_ID_HIDPP_SHORT && 318 + response->rap.sub_id == HIDPP_ERROR) { 319 + ret = response->rap.params[1]; 320 + dbg_hid("%s:got hidpp error %02X\n", __func__, ret); 321 + return ret; 322 + } 323 + 324 + if ((response->report_id == REPORT_ID_HIDPP_LONG || 325 + response->report_id == REPORT_ID_HIDPP_VERY_LONG) && 326 + response->fap.feature_index == HIDPP20_ERROR) { 327 + ret = response->fap.params[1]; 328 + dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret); 329 + return ret; 330 + } 331 + 332 + return 0; 333 + } 334 + 335 + /* 336 + * hidpp_send_message_sync() returns 0 in case of success, and something else 337 + * in case of a failure. 338 + * 339 + * See __do_hidpp_send_message_sync() for a detailed explanation of the returned 340 + * value. 341 + */ 342 + static int hidpp_send_message_sync(struct hidpp_device *hidpp, 343 + struct hidpp_report *message, 344 + struct hidpp_report *response) 345 + { 346 + int ret; 347 + int max_retries = 3; 348 + 349 + mutex_lock(&hidpp->send_mutex); 350 + 351 + do { 352 + ret = __do_hidpp_send_message_sync(hidpp, message, response); 353 + if (ret != HIDPP20_ERROR_BUSY) 354 + break; 355 + 356 + dbg_hid("%s:got busy hidpp 2.0 error %02X, retrying\n", __func__, ret); 357 + } while (--max_retries); 339 358 340 359 mutex_unlock(&hidpp->send_mutex); 341 360 return ret; 342 361 343 362 } 344 363 364 + /* 365 + * hidpp_send_fap_command_sync() returns 0 in case of success, and something else 366 + * in case of a failure. 367 + * 368 + * See __do_hidpp_send_message_sync() for a detailed explanation of the returned 369 + * value. 370 + */ 345 371 static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp, 346 372 u8 feat_index, u8 funcindex_clientid, u8 *params, int param_count, 347 373 struct hidpp_report *response) ··· 401 373 return ret; 402 374 } 403 375 376 + /* 377 + * hidpp_send_rap_command_sync() returns 0 in case of success, and something else 378 + * in case of a failure. 379 + * 380 + * See __do_hidpp_send_message_sync() for a detailed explanation of the returned 381 + * value. 382 + */ 404 383 static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev, 405 384 u8 report_id, u8 sub_id, u8 reg_address, u8 *params, int param_count, 406 385 struct hidpp_report *response) ··· 4655 4620 .driver_data = HIDPP_QUIRK_CLASS_G920 | HIDPP_QUIRK_FORCE_OUTPUT_REPORTS }, 4656 4621 { /* Logitech G Pro Gaming Mouse over USB */ 4657 4622 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC088) }, 4623 + { /* Logitech G Pro X Superlight Gaming Mouse over USB */ 4624 + HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0xC094) }, 4658 4625 4659 4626 { /* G935 Gaming Headset */ 4660 4627 HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, 0x0a87), ··· 4684 4647 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb02a) }, 4685 4648 { /* MX Master 3 mouse over Bluetooth */ 4686 4649 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb023) }, 4650 + { /* MX Anywhere 3 mouse over Bluetooth */ 4651 + HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb025) }, 4687 4652 { /* MX Master 3S mouse over Bluetooth */ 4688 4653 HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb034) }, 4689 4654 {}
+3 -10
drivers/hid/hid-multitouch.c
··· 1594 1594 static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi) 1595 1595 { 1596 1596 struct mt_device *td = hid_get_drvdata(hdev); 1597 - char *name; 1598 1597 const char *suffix = NULL; 1599 1598 struct mt_report_data *rdata; 1600 1599 struct mt_application *mt_application = NULL; ··· 1644 1645 break; 1645 1646 } 1646 1647 1647 - if (suffix) { 1648 - name = devm_kzalloc(&hi->input->dev, 1649 - strlen(hdev->name) + strlen(suffix) + 2, 1650 - GFP_KERNEL); 1651 - if (name) { 1652 - sprintf(name, "%s %s", hdev->name, suffix); 1653 - hi->input->name = name; 1654 - } 1655 - } 1648 + if (suffix) 1649 + hi->input->name = devm_kasprintf(&hdev->dev, GFP_KERNEL, 1650 + "%s %s", hdev->name, suffix); 1656 1651 1657 1652 return 0; 1658 1653 }
+407 -21
drivers/hid/hid-nvidia-shield.c
··· 6 6 */ 7 7 8 8 #include <linux/hid.h> 9 + #include <linux/idr.h> 9 10 #include <linux/input-event-codes.h> 10 11 #include <linux/input.h> 12 + #include <linux/jiffies.h> 11 13 #include <linux/leds.h> 12 14 #include <linux/module.h> 15 + #include <linux/power_supply.h> 13 16 #include <linux/spinlock.h> 17 + #include <linux/timer.h> 14 18 #include <linux/workqueue.h> 15 19 16 20 #include "hid-ids.h" ··· 34 30 enum { 35 31 SHIELD_FW_VERSION_INITIALIZED = 0, 36 32 SHIELD_BOARD_INFO_INITIALIZED, 33 + SHIELD_BATTERY_STATS_INITIALIZED, 34 + SHIELD_CHARGER_STATE_INITIALIZED, 37 35 }; 38 36 39 37 enum { ··· 43 37 THUNDERSTRIKE_BOARD_INFO_UPDATE, 44 38 THUNDERSTRIKE_HAPTICS_UPDATE, 45 39 THUNDERSTRIKE_LED_UPDATE, 40 + THUNDERSTRIKE_POWER_SUPPLY_STATS_UPDATE, 46 41 }; 47 42 48 43 enum { ··· 55 48 enum { 56 49 THUNDERSTRIKE_HOSTCMD_ID_FW_VERSION = 1, 57 50 THUNDERSTRIKE_HOSTCMD_ID_LED = 6, 51 + THUNDERSTRIKE_HOSTCMD_ID_BATTERY, 58 52 THUNDERSTRIKE_HOSTCMD_ID_BOARD_INFO = 16, 59 53 THUNDERSTRIKE_HOSTCMD_ID_USB_INIT = 53, 60 54 THUNDERSTRIKE_HOSTCMD_ID_HAPTICS = 57, 61 - THUNDERSTRIKE_HOSTCMD_ID_BLUETOOTH_INIT = 58, 55 + THUNDERSTRIKE_HOSTCMD_ID_CHARGER, 56 + }; 57 + 58 + struct power_supply_dev { 59 + struct power_supply *psy; 60 + struct power_supply_desc desc; 61 + }; 62 + 63 + struct thunderstrike_psy_prop_values { 64 + int voltage_min; 65 + int voltage_now; 66 + int voltage_avg; 67 + int voltage_boot; 68 + int capacity; 69 + int status; 70 + int charge_type; 71 + int temp; 72 + }; 73 + 74 + static const enum power_supply_property thunderstrike_battery_props[] = { 75 + POWER_SUPPLY_PROP_STATUS, 76 + POWER_SUPPLY_PROP_CHARGE_TYPE, 77 + POWER_SUPPLY_PROP_PRESENT, 78 + POWER_SUPPLY_PROP_VOLTAGE_MIN, 79 + POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 80 + POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 81 + POWER_SUPPLY_PROP_VOLTAGE_NOW, 82 + POWER_SUPPLY_PROP_VOLTAGE_AVG, 83 + POWER_SUPPLY_PROP_VOLTAGE_BOOT, 84 + POWER_SUPPLY_PROP_CAPACITY, 85 + POWER_SUPPLY_PROP_SCOPE, 86 + POWER_SUPPLY_PROP_TEMP, 87 + POWER_SUPPLY_PROP_TEMP_MIN, 88 + POWER_SUPPLY_PROP_TEMP_MAX, 89 + POWER_SUPPLY_PROP_TEMP_ALERT_MIN, 90 + POWER_SUPPLY_PROP_TEMP_ALERT_MAX, 62 91 }; 63 92 64 93 enum thunderstrike_led_state { ··· 102 59 THUNDERSTRIKE_LED_ON = 8, 103 60 } __packed; 104 61 static_assert(sizeof(enum thunderstrike_led_state) == 1); 62 + 63 + struct thunderstrike_hostcmd_battery { 64 + __le16 voltage_avg; 65 + u8 reserved_at_10; 66 + __le16 thermistor; 67 + __le16 voltage_min; 68 + __le16 voltage_boot; 69 + __le16 voltage_now; 70 + u8 capacity; 71 + } __packed; 72 + 73 + enum thunderstrike_charger_type { 74 + THUNDERSTRIKE_CHARGER_TYPE_NONE = 0, 75 + THUNDERSTRIKE_CHARGER_TYPE_TRICKLE, 76 + THUNDERSTRIKE_CHARGER_TYPE_NORMAL, 77 + } __packed; 78 + static_assert(sizeof(enum thunderstrike_charger_type) == 1); 79 + 80 + enum thunderstrike_charger_state { 81 + THUNDERSTRIKE_CHARGER_STATE_UNKNOWN = 0, 82 + THUNDERSTRIKE_CHARGER_STATE_DISABLED, 83 + THUNDERSTRIKE_CHARGER_STATE_CHARGING, 84 + THUNDERSTRIKE_CHARGER_STATE_FULL, 85 + THUNDERSTRIKE_CHARGER_STATE_FAILED = 8, 86 + } __packed; 87 + static_assert(sizeof(enum thunderstrike_charger_state) == 1); 88 + 89 + struct thunderstrike_hostcmd_charger { 90 + u8 connected; 91 + enum thunderstrike_charger_type type; 92 + enum thunderstrike_charger_state state; 93 + } __packed; 105 94 106 95 struct thunderstrike_hostcmd_board_info { 107 96 __le16 revision; ··· 155 80 struct thunderstrike_hostcmd_haptics motors; 156 81 __le16 fw_version; 157 82 enum thunderstrike_led_state led_state; 83 + struct thunderstrike_hostcmd_battery battery; 84 + struct thunderstrike_hostcmd_charger charger; 158 85 u8 payload[30]; 159 86 } __packed; 160 87 } __packed; ··· 186 109 /* Common struct for shield accessories. */ 187 110 struct shield_device { 188 111 struct hid_device *hdev; 112 + struct power_supply_dev battery_dev; 189 113 190 114 unsigned long initialized_flags; 191 115 const char *codename; ··· 197 119 } board_info; 198 120 }; 199 121 122 + /* 123 + * Non-trivial to uniquely identify Thunderstrike controllers at initialization 124 + * time. Use an ID allocator to help with this. 125 + */ 126 + static DEFINE_IDA(thunderstrike_ida); 127 + 200 128 struct thunderstrike { 201 129 struct shield_device base; 130 + 131 + int id; 202 132 203 133 /* Sub-devices */ 204 134 struct input_dev *haptics_dev; ··· 219 133 spinlock_t haptics_update_lock; 220 134 u8 led_state : 1; 221 135 enum thunderstrike_led_state led_value; 136 + struct thunderstrike_psy_prop_values psy_stats; 137 + spinlock_t psy_stats_lock; 138 + struct timer_list psy_stats_timer; 222 139 struct work_struct hostcmd_req_work; 223 140 }; 224 141 ··· 253 164 idev->id.product = hdev->product; 254 165 idev->id.version = hdev->version; 255 166 idev->uniq = hdev->uniq; 256 - idev->name = devm_kasprintf(&idev->dev, GFP_KERNEL, "%s %s", hdev->name, 167 + idev->name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "%s %s", hdev->name, 257 168 name_suffix); 258 169 if (!idev->name) 259 170 goto err_name; ··· 333 244 thunderstrike_hostcmd_req_report_init(report, THUNDERSTRIKE_HOSTCMD_ID_LED); 334 245 report->led.update = 1; 335 246 report->led.state = ts->led_value; 247 + thunderstrike_send_hostcmd_request(ts); 248 + } 249 + 250 + if (test_and_clear_bit(THUNDERSTRIKE_POWER_SUPPLY_STATS_UPDATE, &ts->update_flags)) { 251 + thunderstrike_hostcmd_req_report_init( 252 + report, THUNDERSTRIKE_HOSTCMD_ID_BATTERY); 253 + thunderstrike_send_hostcmd_request(ts); 254 + 255 + thunderstrike_hostcmd_req_report_init( 256 + report, THUNDERSTRIKE_HOSTCMD_ID_CHARGER); 336 257 thunderstrike_send_hostcmd_request(ts); 337 258 } 338 259 ··· 451 352 schedule_work(&ts->hostcmd_req_work); 452 353 } 453 354 355 + static int thunderstrike_battery_get_property(struct power_supply *psy, 356 + enum power_supply_property psp, 357 + union power_supply_propval *val) 358 + { 359 + struct shield_device *shield_dev = power_supply_get_drvdata(psy); 360 + struct thunderstrike_psy_prop_values prop_values; 361 + struct thunderstrike *ts; 362 + int ret = 0; 363 + 364 + ts = container_of(shield_dev, struct thunderstrike, base); 365 + spin_lock(&ts->psy_stats_lock); 366 + prop_values = ts->psy_stats; 367 + spin_unlock(&ts->psy_stats_lock); 368 + 369 + switch (psp) { 370 + case POWER_SUPPLY_PROP_STATUS: 371 + val->intval = prop_values.status; 372 + break; 373 + case POWER_SUPPLY_PROP_CHARGE_TYPE: 374 + val->intval = prop_values.charge_type; 375 + break; 376 + case POWER_SUPPLY_PROP_PRESENT: 377 + val->intval = 1; 378 + break; 379 + case POWER_SUPPLY_PROP_VOLTAGE_MIN: 380 + val->intval = prop_values.voltage_min; 381 + break; 382 + case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: 383 + val->intval = 2900000; /* 2.9 V */ 384 + break; 385 + case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: 386 + val->intval = 2200000; /* 2.2 V */ 387 + break; 388 + case POWER_SUPPLY_PROP_VOLTAGE_NOW: 389 + val->intval = prop_values.voltage_now; 390 + break; 391 + case POWER_SUPPLY_PROP_VOLTAGE_AVG: 392 + val->intval = prop_values.voltage_avg; 393 + break; 394 + case POWER_SUPPLY_PROP_VOLTAGE_BOOT: 395 + val->intval = prop_values.voltage_boot; 396 + break; 397 + case POWER_SUPPLY_PROP_CAPACITY: 398 + val->intval = prop_values.capacity; 399 + break; 400 + case POWER_SUPPLY_PROP_SCOPE: 401 + val->intval = POWER_SUPPLY_SCOPE_DEVICE; 402 + break; 403 + case POWER_SUPPLY_PROP_TEMP: 404 + val->intval = prop_values.temp; 405 + break; 406 + case POWER_SUPPLY_PROP_TEMP_MIN: 407 + val->intval = 0; /* 0 C */ 408 + break; 409 + case POWER_SUPPLY_PROP_TEMP_MAX: 410 + val->intval = 400; /* 40 C */ 411 + break; 412 + case POWER_SUPPLY_PROP_TEMP_ALERT_MIN: 413 + val->intval = 15; /* 1.5 C */ 414 + break; 415 + case POWER_SUPPLY_PROP_TEMP_ALERT_MAX: 416 + val->intval = 380; /* 38 C */ 417 + break; 418 + default: 419 + ret = -EINVAL; 420 + break; 421 + } 422 + 423 + return ret; 424 + } 425 + 426 + static inline void thunderstrike_request_psy_stats(struct thunderstrike *ts) 427 + { 428 + set_bit(THUNDERSTRIKE_POWER_SUPPLY_STATS_UPDATE, &ts->update_flags); 429 + schedule_work(&ts->hostcmd_req_work); 430 + } 431 + 432 + static void thunderstrike_psy_stats_timer_handler(struct timer_list *timer) 433 + { 434 + struct thunderstrike *ts = 435 + container_of(timer, struct thunderstrike, psy_stats_timer); 436 + 437 + thunderstrike_request_psy_stats(ts); 438 + /* Query battery statistics from device every five minutes */ 439 + mod_timer(timer, jiffies + 300 * HZ); 440 + } 441 + 454 442 static void 455 443 thunderstrike_parse_fw_version_payload(struct shield_device *shield_dev, 456 444 __le16 fw_version) ··· 602 416 hid_dbg(shield_dev->hdev, "Thunderstrike led HOSTCMD response, 0x%02X\n", led_state); 603 417 } 604 418 419 + static void thunderstrike_parse_battery_payload( 420 + struct shield_device *shield_dev, 421 + struct thunderstrike_hostcmd_battery *battery) 422 + { 423 + struct thunderstrike *ts = container_of(shield_dev, struct thunderstrike, base); 424 + u16 hostcmd_voltage_boot = le16_to_cpu(battery->voltage_boot); 425 + u16 hostcmd_voltage_avg = le16_to_cpu(battery->voltage_avg); 426 + u16 hostcmd_voltage_min = le16_to_cpu(battery->voltage_min); 427 + u16 hostcmd_voltage_now = le16_to_cpu(battery->voltage_now); 428 + u16 hostcmd_thermistor = le16_to_cpu(battery->thermistor); 429 + int voltage_boot, voltage_avg, voltage_min, voltage_now; 430 + struct hid_device *hdev = shield_dev->hdev; 431 + u8 capacity = battery->capacity; 432 + int temp; 433 + 434 + /* Convert thunderstrike device values to µV and tenths of degree Celsius */ 435 + voltage_boot = hostcmd_voltage_boot * 1000; 436 + voltage_avg = hostcmd_voltage_avg * 1000; 437 + voltage_min = hostcmd_voltage_min * 1000; 438 + voltage_now = hostcmd_voltage_now * 1000; 439 + temp = (1378 - (int)hostcmd_thermistor) * 10 / 19; 440 + 441 + /* Copy converted values */ 442 + spin_lock(&ts->psy_stats_lock); 443 + ts->psy_stats.voltage_boot = voltage_boot; 444 + ts->psy_stats.voltage_avg = voltage_avg; 445 + ts->psy_stats.voltage_min = voltage_min; 446 + ts->psy_stats.voltage_now = voltage_now; 447 + ts->psy_stats.capacity = capacity; 448 + ts->psy_stats.temp = temp; 449 + spin_unlock(&ts->psy_stats_lock); 450 + 451 + set_bit(SHIELD_BATTERY_STATS_INITIALIZED, &shield_dev->initialized_flags); 452 + 453 + hid_dbg(hdev, 454 + "Thunderstrike battery HOSTCMD response, voltage_avg: %u voltage_now: %u\n", 455 + hostcmd_voltage_avg, hostcmd_voltage_now); 456 + hid_dbg(hdev, 457 + "Thunderstrike battery HOSTCMD response, voltage_boot: %u voltage_min: %u\n", 458 + hostcmd_voltage_boot, hostcmd_voltage_min); 459 + hid_dbg(hdev, 460 + "Thunderstrike battery HOSTCMD response, thermistor: %u\n", 461 + hostcmd_thermistor); 462 + hid_dbg(hdev, 463 + "Thunderstrike battery HOSTCMD response, capacity: %u%%\n", 464 + capacity); 465 + } 466 + 467 + static void thunderstrike_parse_charger_payload( 468 + struct shield_device *shield_dev, 469 + struct thunderstrike_hostcmd_charger *charger) 470 + { 471 + struct thunderstrike *ts = container_of(shield_dev, struct thunderstrike, base); 472 + int charge_type = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; 473 + struct hid_device *hdev = shield_dev->hdev; 474 + int status = POWER_SUPPLY_STATUS_UNKNOWN; 475 + 476 + switch (charger->type) { 477 + case THUNDERSTRIKE_CHARGER_TYPE_NONE: 478 + charge_type = POWER_SUPPLY_CHARGE_TYPE_NONE; 479 + break; 480 + case THUNDERSTRIKE_CHARGER_TYPE_TRICKLE: 481 + charge_type = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; 482 + break; 483 + case THUNDERSTRIKE_CHARGER_TYPE_NORMAL: 484 + charge_type = POWER_SUPPLY_CHARGE_TYPE_STANDARD; 485 + break; 486 + default: 487 + hid_warn(hdev, "Unhandled Thunderstrike charger HOSTCMD type, %u\n", 488 + charger->type); 489 + break; 490 + } 491 + 492 + switch (charger->state) { 493 + case THUNDERSTRIKE_CHARGER_STATE_UNKNOWN: 494 + status = POWER_SUPPLY_STATUS_UNKNOWN; 495 + break; 496 + case THUNDERSTRIKE_CHARGER_STATE_DISABLED: 497 + /* Indicates charger is disconnected */ 498 + break; 499 + case THUNDERSTRIKE_CHARGER_STATE_CHARGING: 500 + status = POWER_SUPPLY_STATUS_CHARGING; 501 + break; 502 + case THUNDERSTRIKE_CHARGER_STATE_FULL: 503 + status = POWER_SUPPLY_STATUS_FULL; 504 + break; 505 + case THUNDERSTRIKE_CHARGER_STATE_FAILED: 506 + status = POWER_SUPPLY_STATUS_NOT_CHARGING; 507 + hid_err(hdev, "Thunderstrike device failed to charge\n"); 508 + break; 509 + default: 510 + hid_warn(hdev, "Unhandled Thunderstrike charger HOSTCMD state, %u\n", 511 + charger->state); 512 + break; 513 + } 514 + 515 + if (!charger->connected) 516 + status = POWER_SUPPLY_STATUS_DISCHARGING; 517 + 518 + spin_lock(&ts->psy_stats_lock); 519 + ts->psy_stats.charge_type = charge_type; 520 + ts->psy_stats.status = status; 521 + spin_unlock(&ts->psy_stats_lock); 522 + 523 + set_bit(SHIELD_CHARGER_STATE_INITIALIZED, &shield_dev->initialized_flags); 524 + 525 + hid_dbg(hdev, 526 + "Thunderstrike charger HOSTCMD response, connected: %u, type: %u, state: %u\n", 527 + charger->connected, charger->type, charger->state); 528 + } 529 + 530 + static inline void thunderstrike_device_init_info(struct shield_device *shield_dev) 531 + { 532 + struct thunderstrike *ts = 533 + container_of(shield_dev, struct thunderstrike, base); 534 + 535 + if (!test_bit(SHIELD_FW_VERSION_INITIALIZED, &shield_dev->initialized_flags)) 536 + thunderstrike_request_firmware_version(ts); 537 + 538 + if (!test_bit(SHIELD_BOARD_INFO_INITIALIZED, &shield_dev->initialized_flags)) 539 + thunderstrike_request_board_info(ts); 540 + 541 + if (!test_bit(SHIELD_BATTERY_STATS_INITIALIZED, &shield_dev->initialized_flags) || 542 + !test_bit(SHIELD_CHARGER_STATE_INITIALIZED, &shield_dev->initialized_flags)) 543 + thunderstrike_psy_stats_timer_handler(&ts->psy_stats_timer); 544 + } 545 + 605 546 static int thunderstrike_parse_report(struct shield_device *shield_dev, 606 547 struct hid_report *report, u8 *data, 607 548 int size) 608 549 { 609 550 struct thunderstrike_hostcmd_resp_report *hostcmd_resp_report; 610 - struct thunderstrike *ts = 611 - container_of(shield_dev, struct thunderstrike, base); 612 551 struct hid_device *hdev = shield_dev->hdev; 613 552 614 553 switch (report->id) { ··· 756 445 case THUNDERSTRIKE_HOSTCMD_ID_LED: 757 446 thunderstrike_parse_led_payload(shield_dev, hostcmd_resp_report->led_state); 758 447 break; 448 + case THUNDERSTRIKE_HOSTCMD_ID_BATTERY: 449 + thunderstrike_parse_battery_payload(shield_dev, 450 + &hostcmd_resp_report->battery); 451 + break; 759 452 case THUNDERSTRIKE_HOSTCMD_ID_BOARD_INFO: 760 453 thunderstrike_parse_board_info_payload( 761 454 shield_dev, &hostcmd_resp_report->board_info); ··· 768 453 thunderstrike_parse_haptics_payload( 769 454 shield_dev, &hostcmd_resp_report->motors); 770 455 break; 771 - 772 456 case THUNDERSTRIKE_HOSTCMD_ID_USB_INIT: 773 - case THUNDERSTRIKE_HOSTCMD_ID_BLUETOOTH_INIT: 774 457 /* May block HOSTCMD requests till received initially */ 775 - thunderstrike_request_firmware_version(ts); 776 - thunderstrike_request_board_info(ts); 777 - /* Only HOSTCMD that can be triggered without a request */ 778 - return 0; 458 + thunderstrike_device_init_info(shield_dev); 459 + break; 460 + case THUNDERSTRIKE_HOSTCMD_ID_CHARGER: 461 + /* May block HOSTCMD requests till received initially */ 462 + thunderstrike_device_init_info(shield_dev); 463 + 464 + thunderstrike_parse_charger_payload( 465 + shield_dev, &hostcmd_resp_report->charger); 466 + break; 779 467 default: 780 468 hid_warn(hdev, 781 469 "Unhandled Thunderstrike HOSTCMD id %d\n", ··· 798 480 { 799 481 struct led_classdev *led = &ts->led_dev; 800 482 801 - led->name = "thunderstrike:blue:led"; 483 + led->name = devm_kasprintf(&ts->base.hdev->dev, GFP_KERNEL, 484 + "thunderstrike%d:blue:led", ts->id); 802 485 led->max_brightness = 1; 803 486 led->flags = LED_CORE_SUSPENDRESUME; 804 487 led->brightness_get = &thunderstrike_led_get_brightness; 805 488 led->brightness_set = &thunderstrike_led_set_brightness; 806 489 807 490 return led_classdev_register(&ts->base.hdev->dev, led); 491 + } 492 + 493 + static inline int thunderstrike_psy_create(struct shield_device *shield_dev) 494 + { 495 + struct thunderstrike *ts = container_of(shield_dev, struct thunderstrike, base); 496 + struct power_supply_config psy_cfg = { .drv_data = shield_dev, }; 497 + struct hid_device *hdev = shield_dev->hdev; 498 + int ret; 499 + 500 + /* 501 + * Set an initial capacity and temperature value to avoid prematurely 502 + * triggering alerts. Will be replaced by values queried from initial 503 + * HOSTCMD requests. 504 + */ 505 + ts->psy_stats.capacity = 100; 506 + ts->psy_stats.temp = 182; 507 + 508 + shield_dev->battery_dev.desc.properties = thunderstrike_battery_props; 509 + shield_dev->battery_dev.desc.num_properties = 510 + ARRAY_SIZE(thunderstrike_battery_props); 511 + shield_dev->battery_dev.desc.get_property = thunderstrike_battery_get_property; 512 + shield_dev->battery_dev.desc.type = POWER_SUPPLY_TYPE_BATTERY; 513 + shield_dev->battery_dev.desc.name = 514 + devm_kasprintf(&ts->base.hdev->dev, GFP_KERNEL, 515 + "thunderstrike_%d", ts->id); 516 + 517 + shield_dev->battery_dev.psy = power_supply_register( 518 + &hdev->dev, &shield_dev->battery_dev.desc, &psy_cfg); 519 + if (IS_ERR(shield_dev->battery_dev.psy)) { 520 + hid_err(hdev, "Failed to register Thunderstrike battery device\n"); 521 + return PTR_ERR(shield_dev->battery_dev.psy); 522 + } 523 + 524 + ret = power_supply_powers(shield_dev->battery_dev.psy, &hdev->dev); 525 + if (ret) { 526 + hid_err(hdev, "Failed to associate battery device to Thunderstrike\n"); 527 + goto err; 528 + } 529 + 530 + return 0; 531 + 532 + err: 533 + power_supply_unregister(shield_dev->battery_dev.psy); 534 + return ret; 808 535 } 809 536 810 537 static struct shield_device *thunderstrike_create(struct hid_device *hdev) ··· 872 509 shield_dev->codename = "Thunderstrike"; 873 510 874 511 spin_lock_init(&ts->haptics_update_lock); 512 + spin_lock_init(&ts->psy_stats_lock); 875 513 INIT_WORK(&ts->hostcmd_req_work, thunderstrike_hostcmd_req_work_handler); 876 514 877 515 hid_set_drvdata(hdev, shield_dev); 878 516 517 + ts->id = ida_alloc(&thunderstrike_ida, GFP_KERNEL); 518 + if (ts->id < 0) 519 + return ERR_PTR(ts->id); 520 + 521 + ts->haptics_dev = shield_haptics_create(shield_dev, thunderstrike_play_effect); 522 + if (IS_ERR(ts->haptics_dev)) { 523 + hid_err(hdev, "Failed to create Thunderstrike haptics instance\n"); 524 + ret = PTR_ERR(ts->haptics_dev); 525 + goto err_id; 526 + } 527 + 528 + ret = thunderstrike_psy_create(shield_dev); 529 + if (ret) { 530 + hid_err(hdev, "Failed to create Thunderstrike power supply instance\n"); 531 + goto err_haptics; 532 + } 533 + 879 534 ret = thunderstrike_led_create(ts); 880 535 if (ret) { 881 536 hid_err(hdev, "Failed to create Thunderstrike LED instance\n"); 882 - return ERR_PTR(ret); 537 + goto err_psy; 883 538 } 884 539 885 - ts->haptics_dev = shield_haptics_create(shield_dev, thunderstrike_play_effect); 886 - if (IS_ERR(ts->haptics_dev)) 887 - goto err; 540 + timer_setup(&ts->psy_stats_timer, thunderstrike_psy_stats_timer_handler, 0); 888 541 889 542 hid_info(hdev, "Registered Thunderstrike controller\n"); 890 543 return shield_dev; 891 544 892 - err: 893 - led_classdev_unregister(&ts->led_dev); 894 - return ERR_CAST(ts->haptics_dev); 545 + err_psy: 546 + power_supply_unregister(shield_dev->battery_dev.psy); 547 + err_haptics: 548 + if (ts->haptics_dev) 549 + input_unregister_device(ts->haptics_dev); 550 + err_id: 551 + ida_free(&thunderstrike_ida, ts->id); 552 + return ERR_PTR(ret); 895 553 } 896 554 897 555 static int android_input_mapping(struct hid_device *hdev, struct hid_input *hi, ··· 1067 683 goto err_stop; 1068 684 } 1069 685 1070 - thunderstrike_request_firmware_version(ts); 1071 - thunderstrike_request_board_info(ts); 686 + thunderstrike_device_init_info(shield_dev); 1072 687 1073 688 return ret; 1074 689 ··· 1087 704 ts = container_of(dev, struct thunderstrike, base); 1088 705 1089 706 hid_hw_close(hdev); 1090 - led_classdev_unregister(&ts->led_dev); 707 + power_supply_unregister(dev->battery_dev.psy); 1091 708 if (ts->haptics_dev) 1092 709 input_unregister_device(ts->haptics_dev); 710 + led_classdev_unregister(&ts->led_dev); 711 + ida_free(&thunderstrike_ida, ts->id); 712 + del_timer_sync(&ts->psy_stats_timer); 1093 713 cancel_work_sync(&ts->hostcmd_req_work); 1094 714 hid_hw_stop(hdev); 1095 715 }
+1 -1
drivers/hid/hid-sensor-hub.c
··· 632 632 } 633 633 INIT_LIST_HEAD(&hdev->inputs); 634 634 635 - ret = hid_hw_start(hdev, 0); 635 + ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 636 636 if (ret) { 637 637 hid_err(hdev, "hw start failed\n"); 638 638 return ret;
+295 -14
drivers/hid/hid-steelseries.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 2 /* 3 - * HID driver for Steelseries SRW-S1 3 + * HID driver for Steelseries devices 4 4 * 5 5 * Copyright (c) 2013 Simon Wood 6 + * Copyright (c) 2023 Bastien Nocera 6 7 */ 7 8 8 9 /* ··· 12 11 #include <linux/device.h> 13 12 #include <linux/hid.h> 14 13 #include <linux/module.h> 14 + #include <linux/usb.h> 15 15 #include <linux/leds.h> 16 16 17 17 #include "hid-ids.h" 18 + 19 + #define STEELSERIES_SRWS1 BIT(0) 20 + #define STEELSERIES_ARCTIS_1 BIT(1) 21 + 22 + struct steelseries_device { 23 + struct hid_device *hdev; 24 + unsigned long quirks; 25 + 26 + struct delayed_work battery_work; 27 + spinlock_t lock; 28 + bool removed; 29 + 30 + struct power_supply_desc battery_desc; 31 + struct power_supply *battery; 32 + uint8_t battery_capacity; 33 + bool headset_connected; 34 + }; 18 35 19 36 #if IS_BUILTIN(CONFIG_LEDS_CLASS) || \ 20 37 (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES)) ··· 372 353 } 373 354 #endif 374 355 356 + #define STEELSERIES_HEADSET_BATTERY_TIMEOUT_MS 3000 357 + 358 + #define ARCTIS_1_BATTERY_RESPONSE_LEN 8 359 + static const char arctis_1_battery_request[] = { 0x06, 0x12 }; 360 + 361 + static int steelseries_headset_arctis_1_fetch_battery(struct hid_device *hdev) 362 + { 363 + u8 *write_buf; 364 + int ret; 365 + 366 + /* Request battery information */ 367 + write_buf = kmemdup(arctis_1_battery_request, sizeof(arctis_1_battery_request), GFP_KERNEL); 368 + if (!write_buf) 369 + return -ENOMEM; 370 + 371 + ret = hid_hw_raw_request(hdev, arctis_1_battery_request[0], 372 + write_buf, sizeof(arctis_1_battery_request), 373 + HID_OUTPUT_REPORT, HID_REQ_SET_REPORT); 374 + if (ret < sizeof(arctis_1_battery_request)) { 375 + hid_err(hdev, "hid_hw_raw_request() failed with %d\n", ret); 376 + ret = -ENODATA; 377 + } 378 + kfree(write_buf); 379 + return ret; 380 + } 381 + 382 + static void steelseries_headset_fetch_battery(struct hid_device *hdev) 383 + { 384 + struct steelseries_device *sd = hid_get_drvdata(hdev); 385 + int ret = 0; 386 + 387 + if (sd->quirks & STEELSERIES_ARCTIS_1) 388 + ret = steelseries_headset_arctis_1_fetch_battery(hdev); 389 + 390 + if (ret < 0) 391 + hid_dbg(hdev, 392 + "Battery query failed (err: %d)\n", ret); 393 + } 394 + 395 + static void steelseries_headset_battery_timer_tick(struct work_struct *work) 396 + { 397 + struct steelseries_device *sd = container_of(work, 398 + struct steelseries_device, battery_work.work); 399 + struct hid_device *hdev = sd->hdev; 400 + 401 + steelseries_headset_fetch_battery(hdev); 402 + } 403 + 404 + static int steelseries_headset_battery_get_property(struct power_supply *psy, 405 + enum power_supply_property psp, 406 + union power_supply_propval *val) 407 + { 408 + struct steelseries_device *sd = power_supply_get_drvdata(psy); 409 + int ret = 0; 410 + 411 + switch (psp) { 412 + case POWER_SUPPLY_PROP_PRESENT: 413 + val->intval = 1; 414 + break; 415 + case POWER_SUPPLY_PROP_STATUS: 416 + val->intval = sd->headset_connected ? 417 + POWER_SUPPLY_STATUS_DISCHARGING : 418 + POWER_SUPPLY_STATUS_UNKNOWN; 419 + break; 420 + case POWER_SUPPLY_PROP_SCOPE: 421 + val->intval = POWER_SUPPLY_SCOPE_DEVICE; 422 + break; 423 + case POWER_SUPPLY_PROP_CAPACITY: 424 + val->intval = sd->battery_capacity; 425 + break; 426 + default: 427 + ret = -EINVAL; 428 + break; 429 + } 430 + return ret; 431 + } 432 + 433 + static void 434 + steelseries_headset_set_wireless_status(struct hid_device *hdev, 435 + bool connected) 436 + { 437 + struct usb_interface *intf; 438 + 439 + if (!hid_is_usb(hdev)) 440 + return; 441 + 442 + intf = to_usb_interface(hdev->dev.parent); 443 + usb_set_wireless_status(intf, connected ? 444 + USB_WIRELESS_STATUS_CONNECTED : 445 + USB_WIRELESS_STATUS_DISCONNECTED); 446 + } 447 + 448 + static enum power_supply_property steelseries_headset_battery_props[] = { 449 + POWER_SUPPLY_PROP_PRESENT, 450 + POWER_SUPPLY_PROP_STATUS, 451 + POWER_SUPPLY_PROP_SCOPE, 452 + POWER_SUPPLY_PROP_CAPACITY, 453 + }; 454 + 455 + static int steelseries_headset_battery_register(struct steelseries_device *sd) 456 + { 457 + static atomic_t battery_no = ATOMIC_INIT(0); 458 + struct power_supply_config battery_cfg = { .drv_data = sd, }; 459 + unsigned long n; 460 + int ret; 461 + 462 + sd->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; 463 + sd->battery_desc.properties = steelseries_headset_battery_props; 464 + sd->battery_desc.num_properties = ARRAY_SIZE(steelseries_headset_battery_props); 465 + sd->battery_desc.get_property = steelseries_headset_battery_get_property; 466 + sd->battery_desc.use_for_apm = 0; 467 + n = atomic_inc_return(&battery_no) - 1; 468 + sd->battery_desc.name = devm_kasprintf(&sd->hdev->dev, GFP_KERNEL, 469 + "steelseries_headset_battery_%ld", n); 470 + if (!sd->battery_desc.name) 471 + return -ENOMEM; 472 + 473 + /* avoid the warning of 0% battery while waiting for the first info */ 474 + steelseries_headset_set_wireless_status(sd->hdev, false); 475 + sd->battery_capacity = 100; 476 + 477 + sd->battery = devm_power_supply_register(&sd->hdev->dev, 478 + &sd->battery_desc, &battery_cfg); 479 + if (IS_ERR(sd->battery)) { 480 + ret = PTR_ERR(sd->battery); 481 + hid_err(sd->hdev, 482 + "%s:power_supply_register failed with error %d\n", 483 + __func__, ret); 484 + return ret; 485 + } 486 + power_supply_powers(sd->battery, &sd->hdev->dev); 487 + 488 + INIT_DELAYED_WORK(&sd->battery_work, steelseries_headset_battery_timer_tick); 489 + steelseries_headset_fetch_battery(sd->hdev); 490 + 491 + return 0; 492 + } 493 + 494 + static int steelseries_probe(struct hid_device *hdev, const struct hid_device_id *id) 495 + { 496 + struct steelseries_device *sd; 497 + int ret; 498 + 499 + sd = devm_kzalloc(&hdev->dev, sizeof(*sd), GFP_KERNEL); 500 + if (!sd) 501 + return -ENOMEM; 502 + hid_set_drvdata(hdev, sd); 503 + sd->hdev = hdev; 504 + sd->quirks = id->driver_data; 505 + 506 + if (sd->quirks & STEELSERIES_SRWS1) { 507 + #if IS_BUILTIN(CONFIG_LEDS_CLASS) || \ 508 + (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES)) 509 + return steelseries_srws1_probe(hdev, id); 510 + #else 511 + return -ENODEV; 512 + #endif 513 + } 514 + 515 + ret = hid_parse(hdev); 516 + if (ret) 517 + return ret; 518 + 519 + spin_lock_init(&sd->lock); 520 + 521 + ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 522 + if (ret) 523 + return ret; 524 + 525 + if (steelseries_headset_battery_register(sd) < 0) 526 + hid_err(sd->hdev, 527 + "Failed to register battery for headset\n"); 528 + 529 + return ret; 530 + } 531 + 532 + static void steelseries_remove(struct hid_device *hdev) 533 + { 534 + struct steelseries_device *sd = hid_get_drvdata(hdev); 535 + unsigned long flags; 536 + 537 + if (sd->quirks & STEELSERIES_SRWS1) { 538 + #if IS_BUILTIN(CONFIG_LEDS_CLASS) || \ 539 + (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES)) 540 + steelseries_srws1_remove(hdev); 541 + #endif 542 + return; 543 + } 544 + 545 + spin_lock_irqsave(&sd->lock, flags); 546 + sd->removed = true; 547 + spin_unlock_irqrestore(&sd->lock, flags); 548 + 549 + cancel_delayed_work_sync(&sd->battery_work); 550 + 551 + hid_hw_stop(hdev); 552 + } 553 + 375 554 static __u8 *steelseries_srws1_report_fixup(struct hid_device *hdev, __u8 *rdesc, 376 555 unsigned int *rsize) 377 556 { 557 + if (hdev->vendor != USB_VENDOR_ID_STEELSERIES || 558 + hdev->product != USB_DEVICE_ID_STEELSERIES_SRWS1) 559 + return rdesc; 560 + 378 561 if (*rsize >= 115 && rdesc[11] == 0x02 && rdesc[13] == 0xc8 379 562 && rdesc[29] == 0xbb && rdesc[40] == 0xc5) { 380 563 hid_info(hdev, "Fixing up Steelseries SRW-S1 report descriptor\n"); ··· 586 365 return rdesc; 587 366 } 588 367 589 - static const struct hid_device_id steelseries_srws1_devices[] = { 590 - { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) }, 368 + static int steelseries_headset_raw_event(struct hid_device *hdev, 369 + struct hid_report *report, u8 *read_buf, 370 + int size) 371 + { 372 + struct steelseries_device *sd = hid_get_drvdata(hdev); 373 + int capacity = sd->battery_capacity; 374 + bool connected = sd->headset_connected; 375 + unsigned long flags; 376 + 377 + /* Not a headset */ 378 + if (sd->quirks & STEELSERIES_SRWS1) 379 + return 0; 380 + 381 + if (sd->quirks & STEELSERIES_ARCTIS_1) { 382 + hid_dbg(sd->hdev, 383 + "Parsing raw event for Arctis 1 headset (%*ph)\n", size, read_buf); 384 + if (size < ARCTIS_1_BATTERY_RESPONSE_LEN || 385 + memcmp (read_buf, arctis_1_battery_request, sizeof(arctis_1_battery_request))) 386 + return 0; 387 + if (read_buf[2] == 0x01) { 388 + connected = false; 389 + capacity = 100; 390 + } else { 391 + connected = true; 392 + capacity = read_buf[3]; 393 + } 394 + } 395 + 396 + if (connected != sd->headset_connected) { 397 + hid_dbg(sd->hdev, 398 + "Connected status changed from %sconnected to %sconnected\n", 399 + sd->headset_connected ? "" : "not ", 400 + connected ? "" : "not "); 401 + sd->headset_connected = connected; 402 + steelseries_headset_set_wireless_status(hdev, connected); 403 + } 404 + 405 + if (capacity != sd->battery_capacity) { 406 + hid_dbg(sd->hdev, 407 + "Battery capacity changed from %d%% to %d%%\n", 408 + sd->battery_capacity, capacity); 409 + sd->battery_capacity = capacity; 410 + power_supply_changed(sd->battery); 411 + } 412 + 413 + spin_lock_irqsave(&sd->lock, flags); 414 + if (!sd->removed) 415 + schedule_delayed_work(&sd->battery_work, 416 + msecs_to_jiffies(STEELSERIES_HEADSET_BATTERY_TIMEOUT_MS)); 417 + spin_unlock_irqrestore(&sd->lock, flags); 418 + 419 + return 0; 420 + } 421 + 422 + static const struct hid_device_id steelseries_devices[] = { 423 + { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1), 424 + .driver_data = STEELSERIES_SRWS1 }, 425 + 426 + { /* SteelSeries Arctis 1 Wireless for XBox */ 427 + HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, 0x12b6), 428 + .driver_data = STEELSERIES_ARCTIS_1 }, 429 + 591 430 { } 592 431 }; 593 - MODULE_DEVICE_TABLE(hid, steelseries_srws1_devices); 432 + MODULE_DEVICE_TABLE(hid, steelseries_devices); 594 433 595 - static struct hid_driver steelseries_srws1_driver = { 596 - .name = "steelseries_srws1", 597 - .id_table = steelseries_srws1_devices, 598 - #if IS_BUILTIN(CONFIG_LEDS_CLASS) || \ 599 - (IS_MODULE(CONFIG_LEDS_CLASS) && IS_MODULE(CONFIG_HID_STEELSERIES)) 600 - .probe = steelseries_srws1_probe, 601 - .remove = steelseries_srws1_remove, 602 - #endif 603 - .report_fixup = steelseries_srws1_report_fixup 434 + static struct hid_driver steelseries_driver = { 435 + .name = "steelseries", 436 + .id_table = steelseries_devices, 437 + .probe = steelseries_probe, 438 + .remove = steelseries_remove, 439 + .report_fixup = steelseries_srws1_report_fixup, 440 + .raw_event = steelseries_headset_raw_event, 604 441 }; 605 442 606 - module_hid_driver(steelseries_srws1_driver); 443 + module_hid_driver(steelseries_driver); 607 444 MODULE_LICENSE("GPL"); 445 + MODULE_AUTHOR("Bastien Nocera <hadess@hadess.net>"); 446 + MODULE_AUTHOR("Simon Wood <simon@mungewell.org>");
+3 -10
drivers/hid/hid-uclogic-core.c
··· 85 85 { 86 86 struct uclogic_drvdata *drvdata = hid_get_drvdata(hdev); 87 87 struct uclogic_params *params = &drvdata->params; 88 - char *name; 89 88 const char *suffix = NULL; 90 89 struct hid_field *field; 91 - size_t len; 92 90 size_t i; 93 91 const struct uclogic_params_frame *frame; 94 92 ··· 144 146 } 145 147 } 146 148 147 - if (suffix) { 148 - len = strlen(hdev->name) + 2 + strlen(suffix); 149 - name = devm_kzalloc(&hi->input->dev, len, GFP_KERNEL); 150 - if (name) { 151 - snprintf(name, len, "%s %s", hdev->name, suffix); 152 - hi->input->name = name; 153 - } 154 - } 149 + if (suffix) 150 + hi->input->name = devm_kasprintf(&hdev->dev, GFP_KERNEL, 151 + "%s %s", hdev->name, suffix); 155 152 156 153 return 0; 157 154 }
-10
drivers/hid/hid-wiimote-debug.c
··· 173 173 { 174 174 struct wiimote_debug *dbg; 175 175 unsigned long flags; 176 - int ret = -ENOMEM; 177 176 178 177 dbg = kzalloc(sizeof(*dbg), GFP_KERNEL); 179 178 if (!dbg) ··· 182 183 183 184 dbg->eeprom = debugfs_create_file("eeprom", S_IRUSR, 184 185 dbg->wdata->hdev->debug_dir, dbg, &wiidebug_eeprom_fops); 185 - if (!dbg->eeprom) 186 - goto err; 187 186 188 187 dbg->drm = debugfs_create_file("drm", S_IRUSR, 189 188 dbg->wdata->hdev->debug_dir, dbg, &wiidebug_drm_fops); 190 - if (!dbg->drm) 191 - goto err_drm; 192 189 193 190 spin_lock_irqsave(&wdata->state.lock, flags); 194 191 wdata->debug = dbg; ··· 192 197 193 198 return 0; 194 199 195 - err_drm: 196 - debugfs_remove(dbg->eeprom); 197 - err: 198 - kfree(dbg); 199 - return ret; 200 200 } 201 201 202 202 void wiidebug_deinit(struct wiimote_data *wdata)
+38 -12
drivers/hid/i2c-hid/i2c-hid-of-elan.c
··· 18 18 #include "i2c-hid.h" 19 19 20 20 struct elan_i2c_hid_chip_data { 21 - unsigned int post_gpio_reset_delay_ms; 21 + unsigned int post_gpio_reset_on_delay_ms; 22 + unsigned int post_gpio_reset_off_delay_ms; 22 23 unsigned int post_power_delay_ms; 23 24 u16 hid_descriptor_address; 25 + const char *main_supply_name; 24 26 }; 25 27 26 28 struct i2c_hid_of_elan { ··· 40 38 container_of(ops, struct i2c_hid_of_elan, ops); 41 39 int ret; 42 40 43 - ret = regulator_enable(ihid_elan->vcc33); 44 - if (ret) 45 - return ret; 41 + if (ihid_elan->vcc33) { 42 + ret = regulator_enable(ihid_elan->vcc33); 43 + if (ret) 44 + return ret; 45 + } 46 46 47 47 ret = regulator_enable(ihid_elan->vccio); 48 48 if (ret) { ··· 56 52 msleep(ihid_elan->chip_data->post_power_delay_ms); 57 53 58 54 gpiod_set_value_cansleep(ihid_elan->reset_gpio, 0); 59 - if (ihid_elan->chip_data->post_gpio_reset_delay_ms) 60 - msleep(ihid_elan->chip_data->post_gpio_reset_delay_ms); 55 + if (ihid_elan->chip_data->post_gpio_reset_on_delay_ms) 56 + msleep(ihid_elan->chip_data->post_gpio_reset_on_delay_ms); 61 57 62 58 return 0; 63 59 } ··· 68 64 container_of(ops, struct i2c_hid_of_elan, ops); 69 65 70 66 gpiod_set_value_cansleep(ihid_elan->reset_gpio, 1); 67 + if (ihid_elan->chip_data->post_gpio_reset_off_delay_ms) 68 + msleep(ihid_elan->chip_data->post_gpio_reset_off_delay_ms); 69 + 71 70 regulator_disable(ihid_elan->vccio); 72 - regulator_disable(ihid_elan->vcc33); 71 + if (ihid_elan->vcc33) 72 + regulator_disable(ihid_elan->vcc33); 73 73 } 74 74 75 75 static int i2c_hid_of_elan_probe(struct i2c_client *client) ··· 97 89 if (IS_ERR(ihid_elan->vccio)) 98 90 return PTR_ERR(ihid_elan->vccio); 99 91 100 - ihid_elan->vcc33 = devm_regulator_get(&client->dev, "vcc33"); 101 - if (IS_ERR(ihid_elan->vcc33)) 102 - return PTR_ERR(ihid_elan->vcc33); 103 - 104 92 ihid_elan->chip_data = device_get_match_data(&client->dev); 93 + 94 + if (ihid_elan->chip_data->main_supply_name) { 95 + ihid_elan->vcc33 = devm_regulator_get(&client->dev, 96 + ihid_elan->chip_data->main_supply_name); 97 + if (IS_ERR(ihid_elan->vcc33)) 98 + return PTR_ERR(ihid_elan->vcc33); 99 + } 105 100 106 101 return i2c_hid_core_probe(client, &ihid_elan->ops, 107 102 ihid_elan->chip_data->hid_descriptor_address, 0); ··· 112 101 113 102 static const struct elan_i2c_hid_chip_data elan_ekth6915_chip_data = { 114 103 .post_power_delay_ms = 1, 115 - .post_gpio_reset_delay_ms = 300, 104 + .post_gpio_reset_on_delay_ms = 300, 116 105 .hid_descriptor_address = 0x0001, 106 + .main_supply_name = "vcc33", 107 + }; 108 + 109 + static const struct elan_i2c_hid_chip_data ilitek_ili9882t_chip_data = { 110 + .post_power_delay_ms = 1, 111 + .post_gpio_reset_on_delay_ms = 200, 112 + .post_gpio_reset_off_delay_ms = 65, 113 + .hid_descriptor_address = 0x0001, 114 + /* 115 + * this touchscreen is tightly integrated with the panel and assumes 116 + * that the relevant power rails (other than the IO rail) have already 117 + * been turned on by the panel driver because we're a panel follower. 118 + */ 119 + .main_supply_name = NULL, 117 120 }; 118 121 119 122 static const struct of_device_id elan_i2c_hid_of_match[] = { 120 123 { .compatible = "elan,ekth6915", .data = &elan_ekth6915_chip_data }, 124 + { .compatible = "ilitek,ili9882t", .data = &ilitek_ili9882t_chip_data }, 121 125 { } 122 126 }; 123 127 MODULE_DEVICE_TABLE(of, elan_i2c_hid_of_match);
+1
drivers/hid/wacom.h
··· 150 150 struct input_dev *input; 151 151 bool registered; 152 152 struct wacom_battery battery; 153 + ktime_t active_time; 153 154 } remotes[WACOM_MAX_REMOTES]; 154 155 }; 155 156
+31 -13
drivers/hid/wacom_sys.c
··· 1997 1997 spin_lock_init(&remote->remote_lock); 1998 1998 1999 1999 error = kfifo_alloc(&remote->remote_fifo, 2000 - 5 * sizeof(struct wacom_remote_data), 2000 + 5 * sizeof(struct wacom_remote_work_data), 2001 2001 GFP_KERNEL); 2002 2002 if (error) { 2003 2003 hid_err(wacom->hdev, "failed allocating remote_fifo\n"); ··· 2523 2523 return; 2524 2524 } 2525 2525 2526 + static void wacom_remote_destroy_battery(struct wacom *wacom, int index) 2527 + { 2528 + struct wacom_remote *remote = wacom->remote; 2529 + 2530 + if (remote->remotes[index].battery.battery) { 2531 + devres_release_group(&wacom->hdev->dev, 2532 + &remote->remotes[index].battery.bat_desc); 2533 + remote->remotes[index].battery.battery = NULL; 2534 + remote->remotes[index].active_time = 0; 2535 + } 2536 + } 2537 + 2526 2538 static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index) 2527 2539 { 2528 2540 struct wacom_remote *remote = wacom->remote; ··· 2549 2537 remote->remotes[i].registered = false; 2550 2538 spin_unlock_irqrestore(&remote->remote_lock, flags); 2551 2539 2552 - if (remote->remotes[i].battery.battery) 2553 - devres_release_group(&wacom->hdev->dev, 2554 - &remote->remotes[i].battery.bat_desc); 2540 + wacom_remote_destroy_battery(wacom, i); 2555 2541 2556 2542 if (remote->remotes[i].group.name) 2557 2543 devres_release_group(&wacom->hdev->dev, ··· 2557 2547 2558 2548 remote->remotes[i].serial = 0; 2559 2549 remote->remotes[i].group.name = NULL; 2560 - remote->remotes[i].battery.battery = NULL; 2561 2550 wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN; 2562 2551 } 2563 2552 } ··· 2641 2632 if (remote->remotes[index].battery.battery) 2642 2633 return 0; 2643 2634 2635 + if (!remote->remotes[index].active_time) 2636 + return 0; 2637 + 2644 2638 if (wacom->led.groups[index].select == WACOM_STATUS_UNKNOWN) 2645 2639 return 0; 2646 2640 ··· 2659 2647 { 2660 2648 struct wacom *wacom = container_of(work, struct wacom, remote_work); 2661 2649 struct wacom_remote *remote = wacom->remote; 2662 - struct wacom_remote_data data; 2650 + ktime_t kt = ktime_get(); 2651 + struct wacom_remote_work_data remote_work_data; 2663 2652 unsigned long flags; 2664 2653 unsigned int count; 2665 - u32 serial; 2654 + u32 work_serial; 2666 2655 int i; 2667 2656 2668 2657 spin_lock_irqsave(&remote->remote_lock, flags); 2669 2658 2670 - count = kfifo_out(&remote->remote_fifo, &data, sizeof(data)); 2659 + count = kfifo_out(&remote->remote_fifo, &remote_work_data, 2660 + sizeof(remote_work_data)); 2671 2661 2672 - if (count != sizeof(data)) { 2662 + if (count != sizeof(remote_work_data)) { 2673 2663 hid_err(wacom->hdev, 2674 2664 "workitem triggered without status available\n"); 2675 2665 spin_unlock_irqrestore(&remote->remote_lock, flags); ··· 2684 2670 spin_unlock_irqrestore(&remote->remote_lock, flags); 2685 2671 2686 2672 for (i = 0; i < WACOM_MAX_REMOTES; i++) { 2687 - serial = data.remote[i].serial; 2688 - if (data.remote[i].connected) { 2673 + work_serial = remote_work_data.remote[i].serial; 2674 + if (work_serial) { 2689 2675 2690 - if (remote->remotes[i].serial == serial) { 2676 + if (kt - remote->remotes[i].active_time > WACOM_REMOTE_BATTERY_TIMEOUT 2677 + && remote->remotes[i].active_time != 0) 2678 + wacom_remote_destroy_battery(wacom, i); 2679 + 2680 + if (remote->remotes[i].serial == work_serial) { 2691 2681 wacom_remote_attach_battery(wacom, i); 2692 2682 continue; 2693 2683 } ··· 2699 2681 if (remote->remotes[i].serial) 2700 2682 wacom_remote_destroy_one(wacom, i); 2701 2683 2702 - wacom_remote_create_one(wacom, serial, i); 2684 + wacom_remote_create_one(wacom, work_serial, i); 2703 2685 2704 2686 } else if (remote->remotes[i].serial) { 2705 2687 wacom_remote_destroy_one(wacom, i);
+3 -4
drivers/hid/wacom_wac.c
··· 1134 1134 if (index < 0 || !remote->remotes[index].registered) 1135 1135 goto out; 1136 1136 1137 + remote->remotes[i].active_time = ktime_get(); 1137 1138 input = remote->remotes[index].input; 1138 1139 1139 1140 input_report_key(input, BTN_0, (data[9] & 0x01)); ··· 1197 1196 struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac); 1198 1197 unsigned char *data = wacom_wac->data; 1199 1198 struct wacom_remote *remote = wacom->remote; 1200 - struct wacom_remote_data remote_data; 1199 + struct wacom_remote_work_data remote_data; 1201 1200 unsigned long flags; 1202 1201 int i, ret; 1203 1202 1204 1203 if (data[0] != WACOM_REPORT_DEVICE_LIST) 1205 1204 return; 1206 1205 1207 - memset(&remote_data, 0, sizeof(struct wacom_remote_data)); 1206 + memset(&remote_data, 0, sizeof(struct wacom_remote_work_data)); 1208 1207 1209 1208 for (i = 0; i < WACOM_MAX_REMOTES; i++) { 1210 1209 int j = i * 6; 1211 1210 int serial = (data[j+6] << 16) + (data[j+5] << 8) + data[j+4]; 1212 - bool connected = data[j+2]; 1213 1211 1214 1212 remote_data.remote[i].serial = serial; 1215 - remote_data.remote[i].connected = connected; 1216 1213 } 1217 1214 1218 1215 spin_lock_irqsave(&remote->remote_lock, flags);
+2 -2
drivers/hid/wacom_wac.h
··· 13 13 #define WACOM_NAME_MAX 64 14 14 #define WACOM_MAX_REMOTES 5 15 15 #define WACOM_STATUS_UNKNOWN 255 16 + #define WACOM_REMOTE_BATTERY_TIMEOUT 21000000000ll 16 17 17 18 /* packet length for individual models */ 18 19 #define WACOM_PKGLEN_BBFUN 9 ··· 328 327 ktime_t time_delayed; 329 328 }; 330 329 331 - struct wacom_remote_data { 330 + struct wacom_remote_work_data { 332 331 struct { 333 332 u32 serial; 334 - bool connected; 335 333 } remote[WACOM_MAX_REMOTES]; 336 334 }; 337 335
+25 -1
include/linux/hid.h
··· 341 341 */ 342 342 #define MAX_USBHID_BOOT_QUIRKS 4 343 343 344 + /** 345 + * DOC: HID quirks 346 + * | @HID_QUIRK_NOTOUCH: 347 + * | @HID_QUIRK_IGNORE: ignore this device 348 + * | @HID_QUIRK_NOGET: 349 + * | @HID_QUIRK_HIDDEV_FORCE: 350 + * | @HID_QUIRK_BADPAD: 351 + * | @HID_QUIRK_MULTI_INPUT: 352 + * | @HID_QUIRK_HIDINPUT_FORCE: 353 + * | @HID_QUIRK_ALWAYS_POLL: 354 + * | @HID_QUIRK_INPUT_PER_APP: 355 + * | @HID_QUIRK_X_INVERT: 356 + * | @HID_QUIRK_Y_INVERT: 357 + * | @HID_QUIRK_SKIP_OUTPUT_REPORTS: 358 + * | @HID_QUIRK_SKIP_OUTPUT_REPORT_ID: 359 + * | @HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP: 360 + * | @HID_QUIRK_HAVE_SPECIAL_DRIVER: 361 + * | @HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE: 362 + * | @HID_QUIRK_FULLSPEED_INTERVAL: 363 + * | @HID_QUIRK_NO_INIT_REPORTS: 364 + * | @HID_QUIRK_NO_IGNORE: 365 + * | @HID_QUIRK_NO_INPUT_SYNC: 366 + */ 344 367 /* BIT(0) reserved for backward compatibility, was HID_QUIRK_INVERT */ 345 368 #define HID_QUIRK_NOTOUCH BIT(1) 346 369 #define HID_QUIRK_IGNORE BIT(2) ··· 383 360 #define HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP BIT(18) 384 361 #define HID_QUIRK_HAVE_SPECIAL_DRIVER BIT(19) 385 362 #define HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE BIT(20) 363 + #define HID_QUIRK_NOINVERT BIT(21) 386 364 #define HID_QUIRK_FULLSPEED_INTERVAL BIT(28) 387 365 #define HID_QUIRK_NO_INIT_REPORTS BIT(29) 388 366 #define HID_QUIRK_NO_IGNORE BIT(30) ··· 579 555 struct hid_report *report; 580 556 struct input_dev *input; 581 557 const char *name; 582 - bool registered; 583 558 struct list_head reports; /* the list of reports */ 584 559 unsigned int application; /* application usage for this input */ 560 + bool registered; 585 561 }; 586 562 587 563 enum hid_type {
+1
include/linux/string_choices.h
··· 30 30 { 31 31 return v ? "read" : "write"; 32 32 } 33 + #define str_write_read(v) str_read_write(!(v)) 33 34 34 35 static inline const char *str_on_off(bool v) 35 36 {