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

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

Pull HID updates from Jiri Kosina:

- support for "Unified Battery" feature on Logitech devices from Filipe
Laíns

- power management improvements for intel-ish driver from Zhang Lixu

- support for Goodix devices from Douglas Anderson

- improved handling of generic HID keyboard in order to make it easier
for userspace to figure out the details of the device, from Dmitry
Torokhov

- Playstation DualSense support from Roderick Colenbrander

- other assorted small fixes and device ID additions.

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid: (49 commits)
HID: playstation: add DualSense player LED support.
HID: playstation: add microphone mute support for DualSense.
HID: playstation: add initial DualSense lightbar support.
HID: wacom: Ignore attempts to overwrite the touch_max value from HID
HID: playstation: fix array size comparison (off-by-one)
HID: playstation: fix unused variable in ps_battery_get_property.
HID: playstation: report DualSense hardware and firmware version.
HID: playstation: add DualSense classic rumble support.
HID: playstation: add DualSense Bluetooth support.
HID: playstation: track devices in list.
HID: playstation: add DualSense accelerometer and gyroscope support.
HID: playstation: add DualSense touchpad support.
HID: playstation: add DualSense battery support.
HID: playstation: use DualSense MAC address as unique identifier.
HID: playstation: initial DualSense USB support.
HID: ite: Enable QUIRK_TOUCHPAD_ON_OFF_REPORT on Acer Aspire Switch 10E
HID: Ignore battery for Elan touchscreen on HP Spectre X360 15-df0xxx
HID: logitech-dj: add support for the new lightspeed connection iteration
HID: intel-ish-hid: ipc: Add Tiger Lake H PCI device ID
HID: logitech-dj: add support for keyboard events in eQUAD step 4 Gaming
...

+2608 -421
+65
Documentation/devicetree/bindings/input/goodix,gt7375p.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/goodix,gt7375p.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Goodix GT7375P touchscreen 8 + 9 + maintainers: 10 + - Douglas Anderson <dianders@chromium.org> 11 + 12 + description: 13 + Supports the Goodix GT7375P touchscreen. 14 + This touchscreen uses the i2c-hid protocol but has some non-standard 15 + power sequencing required. 16 + 17 + properties: 18 + compatible: 19 + items: 20 + - const: goodix,gt7375p 21 + 22 + reg: 23 + enum: 24 + - 0x5d 25 + - 0x14 26 + 27 + interrupts: 28 + maxItems: 1 29 + 30 + reset-gpios: 31 + true 32 + 33 + vdd-supply: 34 + description: The 3.3V supply to the touchscreen. 35 + 36 + required: 37 + - compatible 38 + - reg 39 + - interrupts 40 + - reset-gpios 41 + - vdd-supply 42 + 43 + additionalProperties: false 44 + 45 + examples: 46 + - | 47 + #include <dt-bindings/clock/qcom,rpmh.h> 48 + #include <dt-bindings/gpio/gpio.h> 49 + #include <dt-bindings/interrupt-controller/irq.h> 50 + 51 + i2c { 52 + #address-cells = <1>; 53 + #size-cells = <0>; 54 + 55 + ap_ts: touchscreen@5d { 56 + compatible = "goodix,gt7375p"; 57 + reg = <0x5d>; 58 + 59 + interrupt-parent = <&tlmm>; 60 + interrupts = <9 IRQ_TYPE_LEVEL_LOW>; 61 + 62 + reset-gpios = <&tlmm 8 GPIO_ACTIVE_LOW>; 63 + vdd-supply = <&pp3300_ts>; 64 + }; 65 + };
+11 -11
Documentation/hid/amd-sfh-hid.rst
··· 3 3 4 4 AMD Sensor Fusion Hub 5 5 ===================== 6 - AMD Sensor Fusion Hub (SFH) is part of an SOC starting from Ryzen based platforms. 6 + AMD Sensor Fusion Hub (SFH) is part of an SOC starting from Ryzen-based platforms. 7 7 The solution is working well on several OEM products. AMD SFH uses HID over PCIe bus. 8 8 In terms of architecture it resembles ISH, however the major difference is all 9 9 the HID reports are generated as part of the kernel driver. 10 10 11 - 1. Block Diagram 12 - ================ 11 + Block Diagram 12 + ------------- 13 13 14 14 :: 15 15 ··· 45 45 AMD HID Transport Layer 46 46 ----------------------- 47 47 AMD SFH transport is also implemented as a bus. Each client application executing in the AMD MP2 is 48 - registered as a device on this bus. Here: MP2 which is an ARM core connected to x86 for processing 48 + registered as a device on this bus. Here, MP2 is an ARM core connected to x86 for processing 49 49 sensor data. The layer, which binds each device (AMD SFH HID driver) identifies the device type and 50 - registers with the hid core. Transport layer attach a constant "struct hid_ll_driver" object with 50 + registers with the HID core. Transport layer attaches a constant "struct hid_ll_driver" object with 51 51 each device. Once a device is registered with HID core, the callbacks provided via this struct are 52 52 used by HID core to communicate with the device. AMD HID Transport layer implements the synchronous calls. 53 53 54 54 AMD HID Client Layer 55 55 -------------------- 56 - This layer is responsible to implement HID request and descriptors. As firmware is OS agnostic, HID 56 + This layer is responsible to implement HID requests and descriptors. As firmware is OS agnostic, HID 57 57 client layer fills the HID request structure and descriptors. HID client layer is complex as it is 58 - interface between MP2 PCIe layer and HID. HID client layer initialized the MP2 PCIe layer and holds 59 - the instance of MP2 layer. It identifies the number of sensors connected using MP2-PCIe layer. Base 60 - on that allocates the DRAM address for each and every sensor and pass it to MP2-PCIe driver.On 61 - enumeration of each the sensor, client layer fills the HID Descriptor structure and HID input repor 58 + interface between MP2 PCIe layer and HID. HID client layer initializes the MP2 PCIe layer and holds 59 + the instance of MP2 layer. It identifies the number of sensors connected using MP2-PCIe layer. Based 60 + on that allocates the DRAM address for each and every sensor and passes it to MP2-PCIe driver. On 61 + enumeration of each sensor, client layer fills the HID Descriptor structure and HID input report 62 62 structure. HID Feature report structure is optional. The report descriptor structure varies from 63 63 sensor to sensor. 64 64 ··· 72 72 2. Data transfer via DRAM. 73 73 3. Supported sensor info via P2C registers. 74 74 75 - Commands are sent to MP2 using C2P Mailbox registers. Writing into C2P Message registers generate 75 + Commands are sent to MP2 using C2P Mailbox registers. Writing into C2P Message registers generates 76 76 interrupt to MP2. The client layer allocates the physical memory and the same is sent to MP2 via 77 77 the PCI layer. MP2 firmware writes the command output to the access DRAM memory which the client 78 78 layer has allocated. Firmware always writes minimum of 32 bytes into DRAM. So as a protocol driver
+2 -2
Documentation/hid/hid-alps.rst
··· 64 64 65 65 Command Read/Write 66 66 ------------------ 67 - To read/write to RAM, need to send a commands to the device. 67 + To read/write to RAM, need to send a command to the device. 68 68 69 69 The command format is as below. 70 70 ··· 80 80 Byte7 Checksum 81 81 ===== ====================== 82 82 83 - Command Byte is read=0xD1/write=0xD2 . 83 + Command Byte is read=0xD1/write=0xD2. 84 84 85 85 Address is read/write RAM address. 86 86
+9 -9
Documentation/hid/hid-sensor.rst
··· 48 48 an ambient light sensor can send illumination data. 49 49 So the implementation has two parts: 50 50 51 - - Core hid driver 51 + - Core HID driver 52 52 - Individual sensor processing part (sensor drivers) 53 53 54 54 Core driver 55 55 ----------- 56 - The core driver registers (hid-sensor-hub) registers as a HID driver. It parses 56 + The core driver (hid-sensor-hub) registers as a HID driver. It parses 57 57 report descriptors and identifies all the sensors present. It adds an MFD device 58 58 with name HID-SENSOR-xxxx (where xxxx is usage id from the specification). 59 59 ··· 95 95 u32 usage_id, 96 96 struct hid_sensor_hub_callbacks *usage_callback): 97 97 98 - Registers callbacks for an usage id. The callback functions are not allowed 98 + Registers callbacks for a usage id. The callback functions are not allowed 99 99 to sleep:: 100 100 101 101 102 102 int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev, 103 103 u32 usage_id): 104 104 105 - Removes callbacks for an usage id. 105 + Removes callbacks for a usage id. 106 106 107 107 108 108 Parsing function:: ··· 166 166 Some common use cases are debug other sensors or to provide some events like 167 167 keyboard attached/detached or lid open/close. 168 168 169 - To allow application to utilize these sensors, here they are exported uses sysfs 169 + To allow application to utilize these sensors, here they are exported using sysfs 170 170 attribute groups, attributes and misc device interface. 171 171 172 172 An example of this representation on sysfs:: ··· 207 207 │   │   │   ├── input-1-200202-units 208 208 │   │   │   ├── input-1-200202-value 209 209 210 - Here there is a custom sensors with four fields, two feature and two inputs. 210 + Here there is a custom sensor with four fields: two feature and two inputs. 211 211 Each field is represented by a set of attributes. All fields except the "value" 212 - are read only. The value field is a RW field. 212 + are read only. The value field is a read-write field. 213 213 214 214 Example:: 215 215 ··· 237 237 │   │   │   ├── 10:53 -> ../HID-SENSOR-2000e1.6.auto 238 238 │   ├── HID-SENSOR-2000e1.6.auto 239 239 240 - Each reports can be of variable length preceded by a header. This header 241 - consist of a 32 bit usage id, 64 bit time stamp and 32 bit length field of raw 240 + Each report can be of variable length preceded by a header. This header 241 + consists of a 32-bit usage id, 64-bit time stamp and 32-bit length field of raw 242 242 data.
+6 -6
Documentation/hid/hid-transport.rst
··· 12 12 13 13 The HID subsystem is designed as a bus. Any I/O subsystem may provide HID 14 14 devices and register them with the HID bus. HID core then loads generic device 15 - drivers on top of it. The transport drivers are responsible of raw data 16 - transport and device setup/management. HID core is responsible of 15 + drivers on top of it. The transport drivers are responsible for raw data 16 + transport and device setup/management. HID core is responsible for 17 17 report-parsing, report interpretation and the user-space API. Device specifics 18 18 and quirks are handled by all layers depending on the quirk. 19 19 ··· 67 67 device. Once a device is registered with HID core, the callbacks provided via 68 68 this struct are used by HID core to communicate with the device. 69 69 70 - Transport drivers are responsible of detecting device failures and unplugging. 70 + Transport drivers are responsible for detecting device failures and unplugging. 71 71 HID core will operate a device as long as it is registered regardless of any 72 72 device failures. Once transport drivers detect unplug or failure events, they 73 73 must unregister the device from HID core and HID core will stop using the ··· 101 101 channel. Any unrequested incoming or outgoing data report must be sent on 102 102 this channel and is never acknowledged by the remote side. Devices usually 103 103 send their input events on this channel. Outgoing events are normally 104 - not send via intr, except if high throughput is required. 104 + not sent via intr, except if high throughput is required. 105 105 - Control Channel (ctrl): The ctrl channel is used for synchronous requests and 106 106 device management. Unrequested data input events must not be sent on this 107 107 channel and are normally ignored. Instead, devices only send management ··· 161 161 payload may be blocked by the underlying transport driver if the 162 162 specification does not allow them. 163 163 - SET_REPORT: A SET_REPORT request has a report ID plus data as payload. It is 164 - sent from host to device and a device must update it's current report state 164 + sent from host to device and a device must update its current report state 165 165 according to the given data. Any of the 3 report types can be used. However, 166 166 INPUT reports as payload might be blocked by the underlying transport driver 167 167 if the specification does not allow them. ··· 294 294 void (*request) (struct hid_device *hdev, struct hid_report *report, 295 295 int reqtype) 296 296 297 - Send an HID request on the ctrl channel. "report" contains the report that 297 + Send a HID request on the ctrl channel. "report" contains the report that 298 298 should be sent and "reqtype" the request type. Request-type can be 299 299 HID_REQ_SET_REPORT or HID_REQ_GET_REPORT. 300 300
+5 -5
Documentation/hid/hiddev.rst
··· 27 27 --> hiddev.c ----> POWER / MONITOR CONTROL 28 28 29 29 In addition, other subsystems (apart from USB) can potentially feed 30 - events into the input subsystem, but these have no effect on the hid 30 + events into the input subsystem, but these have no effect on the HID 31 31 device interface. 32 32 33 33 Using the HID Device Interface ··· 73 73 HID devices exchange data with the host computer using data 74 74 bundles called "reports". Each report is divided into "fields", 75 75 each of which can have one or more "usages". In the hid-core, 76 - each one of these usages has a single signed 32 bit value. 76 + each one of these usages has a single signed 32-bit value. 77 77 78 78 read(): 79 79 ------- ··· 113 113 - (none) 114 114 115 115 This ioctl call returns the HID application usage associated with the 116 - hid device. The third argument to ioctl() specifies which application 116 + HID device. The third argument to ioctl() specifies which application 117 117 index to get. This is useful when the device has more than one 118 118 application collection. If the index is invalid (greater or equal to 119 119 the number of application collections this device has) the ioctl ··· 181 181 must be filled in by the user. The ID can be absolute -- the actual 182 182 report id as reported by the device -- or relative -- 183 183 HID_REPORT_ID_FIRST for the first report, and (HID_REPORT_ID_NEXT | 184 - report_id) for the next report after report_id. Without a-priori 184 + report_id) for the next report after report_id. Without a priori 185 185 information about report ids, the right way to use this ioctl is to 186 186 use the relative IDs above to enumerate the valid IDs. The ioctl 187 187 returns non-zero when there is no more next ID. The real report ID is ··· 200 200 - struct hiddev_usage_ref (read/write) 201 201 202 202 Returns the usage_code in a hiddev_usage_ref structure, given that 203 - given its report type, report id, field index, and index within the 203 + its report type, report id, field index, and index within the 204 204 field have already been filled into the structure. 205 205 206 206 HIDIOCGUSAGE
+3 -2
Documentation/hid/hidraw.rst
··· 21 21 these non-conformant devices. 22 22 23 23 A benefit of hidraw is that its use by userspace applications is independent 24 - of the underlying hardware type. Currently, Hidraw is implemented for USB 24 + of the underlying hardware type. Currently, hidraw is implemented for USB 25 25 and Bluetooth. In the future, as new hardware bus types are developed which 26 26 use the HID specification, hidraw will be expanded to add support for these 27 27 new bus types. ··· 31 31 directly under /dev (eg: /dev/hidraw0). As this location is distribution- 32 32 and udev rule-dependent, applications should use libudev to locate hidraw 33 33 devices attached to the system. There is a tutorial on libudev with a 34 - working example at: 34 + working example at:: 35 35 36 36 http://www.signal11.us/oss/udev/ 37 + https://web.archive.org/web/2019*/www.signal11.us 37 38 38 39 The HIDRAW API 39 40 ---------------
+40 -38
Documentation/hid/intel-ish-hid.rst
··· 4 4 5 5 A sensor hub enables the ability to offload sensor polling and algorithm 6 6 processing to a dedicated low power co-processor. This allows the core 7 - processor to go into low power modes more often, resulting in the increased 7 + processor to go into low power modes more often, resulting in increased 8 8 battery life. 9 9 10 - There are many vendors providing external sensor hubs confirming to HID 11 - Sensor usage tables, and used in several tablets, 2 in 1 convertible laptops 12 - and embedded products. Linux had this support since Linux 3.9. 10 + There are many vendors providing external sensor hubs conforming to HID 11 + Sensor usage tables. These may be found in tablets, 2-in-1 convertible laptops 12 + and embedded products. Linux has had this support since Linux 3.9. 13 13 14 14 Intel® introduced integrated sensor hubs as a part of the SoC starting from 15 15 Cherry Trail and now supported on multiple generations of CPU packages. There 16 16 are many commercial devices already shipped with Integrated Sensor Hubs (ISH). 17 - These ISH also comply to HID sensor specification, but the difference is the 17 + These ISH also comply to HID sensor specification, but the difference is the 18 18 transport protocol used for communication. The current external sensor hubs 19 - mainly use HID over i2C or USB. But ISH doesn't use either i2c or USB. 19 + mainly use HID over I2C or USB. But ISH doesn't use either I2C or USB. 20 20 21 21 1. Overview 22 22 =========== ··· 35 35 ----------------- ---------------------- 36 36 PCI PCI 37 37 ----------------- ---------------------- 38 - |Host controller| --> | ISH processor | 38 + |Host controller| --> | ISH processor | 39 39 ----------------- ---------------------- 40 40 USB Link 41 41 ----------------- ---------------------- ··· 50 50 The ISH allows multiple sensor management applications executing in the 51 51 firmware. Like USB endpoints the messaging can be to/from a client. As part of 52 52 enumeration process, these clients are identified. These clients can be simple 53 - HID sensor applications, sensor calibration application or senor firmware 54 - update application. 53 + HID sensor applications, sensor calibration applications or sensor firmware 54 + update applications. 55 55 56 56 The implementation model is similar, like USB bus, ISH transport is also 57 57 implemented as a bus. Each client application executing in the ISH processor 58 58 is registered as a device on this bus. The driver, which binds each device 59 - (ISH HID driver) identifies the device type and registers with the hid core. 59 + (ISH HID driver) identifies the device type and registers with the HID core. 60 60 61 61 2. ISH Implementation: Block Diagram 62 62 ==================================== ··· 104 104 105 105 The ISH is exposed as "Non-VGA unclassified PCI device" to the host. The PCI 106 106 product and vendor IDs are changed from different generations of processors. So 107 - the source code which enumerate drivers needs to update from generation to 107 + the source code which enumerates drivers needs to update from generation to 108 108 generation. 109 109 110 110 3.2 Inter Processor Communication (IPC) driver ··· 112 112 113 113 Location: drivers/hid/intel-ish-hid/ipc 114 114 115 - The IPC message used memory mapped I/O. The registers are defined in 115 + The IPC message uses memory mapped I/O. The registers are defined in 116 116 hw-ish-regs.h. 117 117 118 118 3.2.1 IPC/FW message types 119 119 ^^^^^^^^^^^^^^^^^^^^^^^^^^ 120 120 121 - There are two types of messages, one for management of link and other messages 122 - are to and from transport layers. 121 + There are two types of messages, one for management of link and another for 122 + messages to and from transport layers. 123 123 124 124 TX and RX of Transport messages 125 125 ............................... 126 126 127 - A set of memory mapped register offers support of multi byte messages TX and 128 - RX (E.g.IPC_REG_ISH2HOST_MSG, IPC_REG_HOST2ISH_MSG). The IPC layer maintains 129 - internal queues to sequence messages and send them in order to the FW. 127 + A set of memory mapped register offers support of multi-byte messages TX and 128 + RX (e.g. IPC_REG_ISH2HOST_MSG, IPC_REG_HOST2ISH_MSG). The IPC layer maintains 129 + internal queues to sequence messages and send them in order to the firmware. 130 130 Optionally the caller can register handler to get notification of completion. 131 - A door bell mechanism is used in messaging to trigger processing in host and 131 + A doorbell mechanism is used in messaging to trigger processing in host and 132 132 client firmware side. When ISH interrupt handler is called, the ISH2HOST 133 133 doorbell register is used by host drivers to determine that the interrupt 134 134 is for ISH. 135 135 136 136 Each side has 32 32-bit message registers and a 32-bit doorbell. Doorbell 137 - register has the following format: 138 - Bits 0..6: fragment length (7 bits are used) 139 - Bits 10..13: encapsulated protocol 140 - Bits 16..19: management command (for IPC management protocol) 141 - Bit 31: doorbell trigger (signal H/W interrupt to the other side) 142 - Other bits are reserved, should be 0. 137 + register has the following format:: 138 + 139 + Bits 0..6: fragment length (7 bits are used) 140 + Bits 10..13: encapsulated protocol 141 + Bits 16..19: management command (for IPC management protocol) 142 + Bit 31: doorbell trigger (signal H/W interrupt to the other side) 143 + Other bits are reserved, should be 0. 143 144 144 145 3.2.2 Transport layer interface 145 146 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 146 147 147 - To abstract HW level IPC communication, a set of callbacks are registered. 148 + To abstract HW level IPC communication, a set of callbacks is registered. 148 149 The transport layer uses them to send and receive messages. 149 - Refer to struct ishtp_hw_ops for callbacks. 150 + Refer to struct ishtp_hw_ops for callbacks. 150 151 151 152 3.3 ISH Transport layer 152 153 ----------------------- ··· 159 158 160 159 The transport layer is a bi-directional protocol, which defines: 161 160 - Set of commands to start, stop, connect, disconnect and flow control 162 - (ishtp/hbm.h) for details 161 + (see ishtp/hbm.h for details) 163 162 - A flow control mechanism to avoid buffer overflows 164 163 165 164 This protocol resembles bus messages described in the following document: ··· 169 168 3.3.2 Connection and Flow Control Mechanism 170 169 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 171 170 172 - Each FW client and a protocol is identified by an UUID. In order to communicate 171 + Each FW client and a protocol is identified by a UUID. In order to communicate 173 172 to a FW client, a connection must be established using connect request and 174 173 response bus messages. If successful, a pair (host_client_id and fw_client_id) 175 174 will identify the connection. 176 175 177 176 Once connection is established, peers send each other flow control bus messages 178 177 independently. Every peer may send a message only if it has received a 179 - flow-control credit before. Once it sent a message, it may not send another one 178 + flow-control credit before. Once it has sent a message, it may not send another one 180 179 before receiving the next flow control credit. 181 180 Either side can send disconnect request bus message to end communication. Also 182 181 the link will be dropped if major FW reset occurs. ··· 210 209 At initial state all outgoing memory belongs to the sender (TX to host, RX to 211 210 FW), DMA_XFER transfers ownership on the region that contains ISHTP message to 212 211 the receiving side, DMA_XFER_ACK returns ownership to the sender. A sender 213 - needs not wait for previous DMA_XFER to be ack'ed, and may send another message 212 + need not wait for previous DMA_XFER to be ack'ed, and may send another message 214 213 as long as remaining continuous memory in its ownership is enough. 215 214 In principle, multiple DMA_XFER and DMA_XFER_ACK messages may be sent at once 216 215 (up to IPC MTU), thus allowing for interrupt throttling. ··· 220 219 3.3.4 Ring Buffers 221 220 ^^^^^^^^^^^^^^^^^^ 222 221 223 - When a client initiate a connection, a ring or RX and TX buffers are allocated. 224 - The size of ring can be specified by the client. HID client set 16 and 32 for 222 + When a client initiates a connection, a ring of RX and TX buffers is allocated. 223 + The size of ring can be specified by the client. HID client sets 16 and 32 for 225 224 TX and RX buffers respectively. On send request from client, the data to be 226 225 sent is copied to one of the send ring buffer and scheduled to be sent using 227 226 bus message protocol. These buffers are required because the FW may have not ··· 231 230 3.3.5 Host Enumeration 232 231 ^^^^^^^^^^^^^^^^^^^^^^ 233 232 234 - The host enumeration bus command allow discovery of clients present in the FW. 233 + The host enumeration bus command allows discovery of clients present in the FW. 235 234 There can be multiple sensor clients and clients for calibration function. 236 235 237 - To ease in implantation and allow independent driver handle each client 236 + To ease implementation and allow independent drivers to handle each client, 238 237 this transport layer takes advantage of Linux Bus driver model. Each 239 238 client is registered as device on the transport bus (ishtp bus). 240 239 ··· 271 270 The functionality in these drivers is the same as an external sensor hub. 272 271 Refer to 273 272 Documentation/hid/hid-sensor.rst for HID sensor 274 - Documentation/ABI/testing/sysfs-bus-iio for IIO ABIs to user space 273 + Documentation/ABI/testing/sysfs-bus-iio for IIO ABIs to user space. 275 274 276 275 3.6 End to End HID transport Sequence Diagram 277 276 --------------------------------------------- ··· 342 341 3.7 ISH Debugging 343 342 ----------------- 344 343 345 - To debug ISH, event tracing mechanism is used. To enable debug logs 346 - echo 1 > /sys/kernel/debug/tracing/events/intel_ish/enable 347 - cat sys/kernel/debug/tracing/trace 344 + To debug ISH, event tracing mechanism is used. To enable debug logs:: 345 + 346 + echo 1 > /sys/kernel/debug/tracing/events/intel_ish/enable 347 + cat sys/kernel/debug/tracing/trace 348 348 349 349 3.8 ISH IIO sysfs Example on Lenovo thinkpad Yoga 260 350 350 -----------------------------------------------------
+17 -17
Documentation/hid/uhid.rst
··· 3 3 ====================================================== 4 4 5 5 UHID allows user-space to implement HID transport drivers. Please see 6 - hid-transport.txt for an introduction into HID transport drivers. This document 6 + hid-transport.rst for an introduction into HID transport drivers. This document 7 7 relies heavily on the definitions declared there. 8 8 9 9 With UHID, a user-space transport driver can create kernel hid-devices for each ··· 15 15 The UHID API 16 16 ------------ 17 17 18 - UHID is accessed through a character misc-device. The minor-number is allocated 18 + UHID is accessed through a character misc-device. The minor number is allocated 19 19 dynamically so you need to rely on udev (or similar) to create the device node. 20 20 This is /dev/uhid by default. 21 21 ··· 45 45 payload-structure available in the union "u" (except for empty payloads). This 46 46 payload contains management and/or device data. 47 47 48 - The first thing you should do is sending an UHID_CREATE2 event. This will 49 - register the device. UHID will respond with an UHID_START event. You can now 48 + The first thing you should do is send a UHID_CREATE2 event. This will 49 + register the device. UHID will respond with a UHID_START event. You can now 50 50 start sending data to and reading data from UHID. However, unless UHID sends the 51 51 UHID_OPEN event, the internally attached HID Device Driver has no user attached. 52 52 That is, you might put your device asleep unless you receive the UHID_OPEN 53 53 event. If you receive the UHID_OPEN event, you should start I/O. If the last 54 - user closes the HID device, you will receive an UHID_CLOSE event. This may be 55 - followed by an UHID_OPEN event again and so on. There is no need to perform 54 + user closes the HID device, you will receive a UHID_CLOSE event. This may be 55 + followed by a UHID_OPEN event again and so on. There is no need to perform 56 56 reference-counting in user-space. That is, you will never receive multiple 57 - UHID_OPEN events without an UHID_CLOSE event. The HID subsystem performs 57 + UHID_OPEN events without a UHID_CLOSE event. The HID subsystem performs 58 58 ref-counting for you. 59 59 You may decide to ignore UHID_OPEN/UHID_CLOSE, though. I/O is allowed even 60 60 though the device may have no users. 61 61 62 62 If you want to send data on the interrupt channel to the HID subsystem, you send 63 - an HID_INPUT2 event with your raw data payload. If the kernel wants to send data 64 - on the interrupt channel to the device, you will read an UHID_OUTPUT event. 63 + a HID_INPUT2 event with your raw data payload. If the kernel wants to send data 64 + on the interrupt channel to the device, you will read a UHID_OUTPUT event. 65 65 Data requests on the control channel are currently limited to GET_REPORT and 66 66 SET_REPORT (no other data reports on the control channel are defined so far). 67 67 Those requests are always synchronous. That means, the kernel sends ··· 71 71 The kernel blocks internal driver-execution during such round-trips (times out 72 72 after a hard-coded period). 73 73 74 - If your device disconnects, you should send an UHID_DESTROY event. This will 74 + If your device disconnects, you should send a UHID_DESTROY event. This will 75 75 unregister the device. You can now send UHID_CREATE2 again to register a new 76 76 device. 77 77 If you close() the fd, the device is automatically unregistered and destroyed ··· 125 125 This is sent when the HID device is started. Consider this as an answer to 126 126 UHID_CREATE2. This is always the first event that is sent. Note that this 127 127 event might not be available immediately after write(UHID_CREATE2) returns. 128 - Device drivers might required delayed setups. 128 + Device drivers might require delayed setups. 129 129 This event contains a payload of type uhid_start_req. The "dev_flags" field 130 130 describes special behaviors of a device. The following flags are defined: 131 131 ··· 149 149 reloaded/changed the device driver loaded on your HID device (or some other 150 150 maintenance actions happened). 151 151 152 - You can usually ignored any UHID_STOP events safely. 152 + You can usually ignore any UHID_STOP events safely. 153 153 154 154 UHID_OPEN: 155 155 This is sent when the HID device is opened. That is, the data that the HID ··· 166 166 This is sent if the HID device driver wants to send raw data to the I/O 167 167 device on the interrupt channel. You should read the payload and forward it to 168 168 the device. The payload is of type "struct uhid_output_req". 169 - This may be received even though you haven't received UHID_OPEN, yet. 169 + This may be received even though you haven't received UHID_OPEN yet. 170 170 171 171 UHID_GET_REPORT: 172 172 This event is sent if the kernel driver wants to perform a GET_REPORT request 173 - on the control channeld as described in the HID specs. The report-type and 173 + on the control channel as described in the HID specs. The report-type and 174 174 report-number are available in the payload. 175 175 The kernel serializes GET_REPORT requests so there will never be two in 176 176 parallel. However, if you fail to respond with a UHID_GET_REPORT_REPLY, the 177 177 request might silently time out. 178 - Once you read a GET_REPORT request, you shall forward it to the hid device and 179 - remember the "id" field in the payload. Once your hid device responds to the 178 + Once you read a GET_REPORT request, you shall forward it to the HID device and 179 + remember the "id" field in the payload. Once your HID device responds to the 180 180 GET_REPORT (or if it fails), you must send a UHID_GET_REPORT_REPLY to the 181 181 kernel with the exact same "id" as in the request. If the request already 182 182 timed out, the kernel will ignore the response silently. The "id" field is ··· 184 184 185 185 UHID_SET_REPORT: 186 186 This is the SET_REPORT equivalent of UHID_GET_REPORT. On receipt, you shall 187 - send a SET_REPORT request to your hid device. Once it replies, you must tell 187 + send a SET_REPORT request to your HID device. Once it replies, you must tell 188 188 the kernel about it via UHID_SET_REPORT_REPLY. 189 189 The same restrictions as for UHID_GET_REPORT apply. 190 190
+6
MAINTAINERS
··· 7908 7908 F: include/linux/hid* 7909 7909 F: include/uapi/linux/hid* 7910 7910 7911 + HID PLAYSTATION DRIVER 7912 + M: Roderick Colenbrander <roderick.colenbrander@sony.com> 7913 + L: linux-input@vger.kernel.org 7914 + S: Supported 7915 + F: drivers/hid/hid-playstation.c 7916 + 7911 7917 HID SENSOR HUB DRIVERS 7912 7918 M: Jiri Kosina <jikos@kernel.org> 7913 7919 M: Jonathan Cameron <jic23@kernel.org>
+2 -1
arch/arm64/configs/defconfig
··· 770 770 CONFIG_SND_SIMPLE_CARD=m 771 771 CONFIG_SND_AUDIO_GRAPH_CARD=m 772 772 CONFIG_HID_MULTITOUCH=m 773 - CONFIG_I2C_HID=m 773 + CONFIG_I2C_HID_ACPI=m 774 + CONFIG_I2C_HID_OF=m 774 775 CONFIG_USB_CONN_GPIO=m 775 776 CONFIG_USB=y 776 777 CONFIG_USB_OTG=y
+19
drivers/hid/Kconfig
··· 853 853 854 854 Say M here if you may ever plug in a Plantronics USB audio device. 855 855 856 + config HID_PLAYSTATION 857 + tristate "PlayStation HID Driver" 858 + depends on HID 859 + select CRC32 860 + select POWER_SUPPLY 861 + help 862 + Provides support for Sony PS5 controllers including support for 863 + its special functionalities e.g. touchpad, lights and motion 864 + sensors. 865 + 866 + config PLAYSTATION_FF 867 + bool "PlayStation force feedback support" 868 + depends on HID_PLAYSTATION 869 + select INPUT_FF_MEMLESS 870 + help 871 + Say Y here if you would like to enable force feedback support for 872 + PlayStation game controllers. 873 + 856 874 config HID_PRIMAX 857 875 tristate "Primax non-fully HID-compliant devices" 858 876 depends on HID ··· 927 909 * Sony PS3 Blue-ray Disk Remote Control (Bluetooth) 928 910 * Logitech Harmony adapter for Sony Playstation 3 (Bluetooth) 929 911 * Guitar Hero Live PS3 and Wii U guitar dongles 912 + * Guitar Hero PS3 and PC guitar dongles 930 913 931 914 config SONY_FF 932 915 bool "Sony PS2/3/4 accessories force feedback support"
+2 -1
drivers/hid/Makefile
··· 94 94 hid-picolcd-$(CONFIG_DEBUG_FS) += hid-picolcd_debugfs.o 95 95 96 96 obj-$(CONFIG_HID_PLANTRONICS) += hid-plantronics.o 97 + obj-$(CONFIG_HID_PLAYSTATION) += hid-playstation.o 97 98 obj-$(CONFIG_HID_PRIMAX) += hid-primax.o 98 99 obj-$(CONFIG_HID_REDRAGON) += hid-redragon.o 99 100 obj-$(CONFIG_HID_RETRODE) += hid-retrode.o ··· 139 138 obj-$(CONFIG_USB_MOUSE) += usbhid/ 140 139 obj-$(CONFIG_USB_KBD) += usbhid/ 141 140 142 - obj-$(CONFIG_I2C_HID) += i2c-hid/ 141 + obj-$(CONFIG_I2C_HID_CORE) += i2c-hid/ 143 142 144 143 obj-$(CONFIG_INTEL_ISH_HID) += intel-ish-hid/ 145 144 obj-$(INTEL_ISH_FIRMWARE_DOWNLOADER) += intel-ish-hid/
+55
drivers/hid/hid-chicony.c
··· 21 21 22 22 #include "hid-ids.h" 23 23 24 + #define CH_WIRELESS_CTL_REPORT_ID 0x11 25 + 26 + static int ch_report_wireless(struct hid_report *report, u8 *data, int size) 27 + { 28 + struct hid_device *hdev = report->device; 29 + struct input_dev *input; 30 + 31 + if (report->id != CH_WIRELESS_CTL_REPORT_ID || report->maxfield != 1) 32 + return 0; 33 + 34 + input = report->field[0]->hidinput->input; 35 + if (!input) { 36 + hid_warn(hdev, "can't find wireless radio control's input"); 37 + return 0; 38 + } 39 + 40 + input_report_key(input, KEY_RFKILL, 1); 41 + input_sync(input); 42 + input_report_key(input, KEY_RFKILL, 0); 43 + input_sync(input); 44 + 45 + return 1; 46 + } 47 + 48 + static int ch_raw_event(struct hid_device *hdev, 49 + struct hid_report *report, u8 *data, int size) 50 + { 51 + if (report->application == HID_GD_WIRELESS_RADIO_CTLS) 52 + return ch_report_wireless(report, data, size); 53 + 54 + return 0; 55 + } 56 + 24 57 #define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ 25 58 EV_KEY, (c)) 26 59 static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi, ··· 110 77 return rdesc; 111 78 } 112 79 80 + static int ch_probe(struct hid_device *hdev, const struct hid_device_id *id) 81 + { 82 + int ret; 83 + 84 + hdev->quirks |= HID_QUIRK_INPUT_PER_APP; 85 + ret = hid_parse(hdev); 86 + if (ret) { 87 + hid_err(hdev, "Chicony hid parse failed: %d\n", ret); 88 + return ret; 89 + } 90 + 91 + ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 92 + if (ret) { 93 + hid_err(hdev, "Chicony hw start failed: %d\n", ret); 94 + return ret; 95 + } 96 + 97 + return 0; 98 + } 113 99 114 100 static const struct hid_device_id ch_devices[] = { 115 101 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, 116 102 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) }, 103 + { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS3) }, 117 104 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_ACER_SWITCH12) }, 118 105 { } 119 106 }; ··· 144 91 .id_table = ch_devices, 145 92 .report_fixup = ch_switch12_report_fixup, 146 93 .input_mapping = ch_input_mapping, 94 + .probe = ch_probe, 95 + .raw_event = ch_raw_event, 147 96 }; 148 97 module_hid_driver(ch_driver); 149 98
+6 -3
drivers/hid/hid-core.c
··· 90 90 * Register a new field for this report. 91 91 */ 92 92 93 - static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values) 93 + static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages) 94 94 { 95 95 struct hid_field *field; 96 96 ··· 101 101 102 102 field = kzalloc((sizeof(struct hid_field) + 103 103 usages * sizeof(struct hid_usage) + 104 - values * sizeof(unsigned)), GFP_KERNEL); 104 + usages * sizeof(unsigned)), GFP_KERNEL); 105 105 if (!field) 106 106 return NULL; 107 107 ··· 300 300 usages = max_t(unsigned, parser->local.usage_index, 301 301 parser->global.report_count); 302 302 303 - field = hid_register_field(report, usages, parser->global.report_count); 303 + field = hid_register_field(report, usages); 304 304 if (!field) 305 305 return 0; 306 306 ··· 1307 1307 1308 1308 static s32 snto32(__u32 value, unsigned n) 1309 1309 { 1310 + if (!value || !n) 1311 + return 0; 1312 + 1310 1313 switch (n) { 1311 1314 case 8: return ((__s8)value); 1312 1315 case 16: return ((__s16)value);
+67 -20
drivers/hid/hid-google-hammer.c
··· 392 392 return 0; 393 393 } 394 394 395 - static int hammer_event(struct hid_device *hid, struct hid_field *field, 396 - struct hid_usage *usage, __s32 value) 395 + static void hammer_folded_event(struct hid_device *hdev, bool folded) 397 396 { 398 397 unsigned long flags; 399 398 399 + spin_lock_irqsave(&cbas_ec_lock, flags); 400 + 401 + /* 402 + * If we are getting events from Whiskers that means that it 403 + * is attached to the lid. 404 + */ 405 + cbas_ec.base_present = true; 406 + cbas_ec.base_folded = folded; 407 + hid_dbg(hdev, "%s: base: %d, folded: %d\n", __func__, 408 + cbas_ec.base_present, cbas_ec.base_folded); 409 + 410 + if (cbas_ec.input) { 411 + input_report_switch(cbas_ec.input, SW_TABLET_MODE, folded); 412 + input_sync(cbas_ec.input); 413 + } 414 + 415 + spin_unlock_irqrestore(&cbas_ec_lock, flags); 416 + } 417 + 418 + static int hammer_event(struct hid_device *hid, struct hid_field *field, 419 + struct hid_usage *usage, __s32 value) 420 + { 400 421 if (usage->hid == HID_USAGE_KBD_FOLDED) { 401 - spin_lock_irqsave(&cbas_ec_lock, flags); 402 - 403 - /* 404 - * If we are getting events from Whiskers that means that it 405 - * is attached to the lid. 406 - */ 407 - cbas_ec.base_present = true; 408 - cbas_ec.base_folded = value; 409 - hid_dbg(hid, "%s: base: %d, folded: %d\n", __func__, 410 - cbas_ec.base_present, cbas_ec.base_folded); 411 - 412 - if (cbas_ec.input) { 413 - input_report_switch(cbas_ec.input, 414 - SW_TABLET_MODE, value); 415 - input_sync(cbas_ec.input); 416 - } 417 - 418 - spin_unlock_irqrestore(&cbas_ec_lock, flags); 422 + hammer_folded_event(hid, value); 419 423 return 1; /* We handled this event */ 420 424 } 421 425 ··· 461 457 HID_GD_KEYBOARD, HID_AD_BRIGHTNESS); 462 458 } 463 459 460 + static void hammer_get_folded_state(struct hid_device *hdev) 461 + { 462 + struct hid_report *report; 463 + char *buf; 464 + int len, rlen; 465 + int a; 466 + 467 + report = hdev->report_enum[HID_INPUT_REPORT].report_id_hash[0x0]; 468 + 469 + if (!report || report->maxfield < 1) 470 + return; 471 + 472 + len = hid_report_len(report) + 1; 473 + 474 + buf = kmalloc(len, GFP_KERNEL); 475 + if (!buf) 476 + return; 477 + 478 + rlen = hid_hw_raw_request(hdev, report->id, buf, len, report->type, HID_REQ_GET_REPORT); 479 + 480 + if (rlen != len) { 481 + hid_warn(hdev, "Unable to read base folded state: %d (expected %d)\n", rlen, len); 482 + goto out; 483 + } 484 + 485 + for (a = 0; a < report->maxfield; a++) { 486 + struct hid_field *field = report->field[a]; 487 + 488 + if (field->usage->hid == HID_USAGE_KBD_FOLDED) { 489 + u32 value = hid_field_extract(hdev, buf+1, 490 + field->report_offset, field->report_size); 491 + 492 + hammer_folded_event(hdev, value); 493 + break; 494 + } 495 + } 496 + 497 + out: 498 + kfree(buf); 499 + } 500 + 464 501 static int hammer_probe(struct hid_device *hdev, 465 502 const struct hid_device_id *id) 466 503 { ··· 526 481 error = hid_hw_open(hdev); 527 482 if (error) 528 483 return error; 484 + 485 + hammer_get_folded_state(hdev); 529 486 } 530 487 531 488 if (hammer_has_backlight_control(hdev)) {
+10 -1
drivers/hid/hid-ids.h
··· 40 40 #define USB_VENDOR_ID_ACTIONSTAR 0x2101 41 41 #define USB_DEVICE_ID_ACTIONSTAR_1011 0x1011 42 42 43 + #define USB_VENDOR_ID_ACTIVISION 0x1430 44 + #define USB_DEVICE_ID_ACTIVISION_GUITAR_DONGLE 0x474c 45 + 43 46 #define USB_VENDOR_ID_ADS_TECH 0x06e1 44 47 #define USB_DEVICE_ID_ADS_TECH_RADIO_SI470X 0xa155 45 48 ··· 273 270 #define USB_DEVICE_ID_CHICONY_PIXART_USB_OPTICAL_MOUSE 0x1053 274 271 #define USB_DEVICE_ID_CHICONY_PIXART_USB_OPTICAL_MOUSE2 0x0939 275 272 #define USB_DEVICE_ID_CHICONY_WIRELESS2 0x1123 273 + #define USB_DEVICE_ID_CHICONY_WIRELESS3 0x1236 276 274 #define USB_DEVICE_ID_ASUS_AK1D 0x1125 277 275 #define USB_DEVICE_ID_CHICONY_TOSHIBA_WT10A 0x1408 278 276 #define USB_DEVICE_ID_CHICONY_ACER_SWITCH12 0x1421 ··· 393 389 #define USB_DEVICE_ID_TOSHIBA_CLICK_L9W 0x0401 394 390 #define USB_DEVICE_ID_HP_X2 0x074d 395 391 #define USB_DEVICE_ID_HP_X2_10_COVER 0x0755 392 + #define I2C_DEVICE_ID_HP_SPECTRE_X360_15 0x2817 396 393 #define USB_DEVICE_ID_ASUS_UX550_TOUCHSCREEN 0x2706 397 394 398 395 #define USB_VENDOR_ID_ELECOM 0x056e ··· 646 641 #define USB_DEVICE_ID_INNEX_GENESIS_ATARI 0x4745 647 642 648 643 #define USB_VENDOR_ID_ITE 0x048d 644 + #define I2C_VENDOR_ID_ITE 0x103c 645 + #define I2C_DEVICE_ID_ITE_VOYO_WINPAD_A15 0x184f 649 646 #define USB_DEVICE_ID_ITE_LENOVO_YOGA 0x8386 650 647 #define USB_DEVICE_ID_ITE_LENOVO_YOGA2 0x8350 651 648 #define I2C_DEVICE_ID_ITE_LENOVO_LEGION_Y720 0x837a ··· 1080 1073 #define USB_DEVICE_ID_SONY_PS4_CONTROLLER 0x05c4 1081 1074 #define USB_DEVICE_ID_SONY_PS4_CONTROLLER_2 0x09cc 1082 1075 #define USB_DEVICE_ID_SONY_PS4_CONTROLLER_DONGLE 0x0ba0 1076 + #define USB_DEVICE_ID_SONY_PS5_CONTROLLER 0x0ce6 1083 1077 #define USB_DEVICE_ID_SONY_MOTION_CONTROLLER 0x03d5 1084 1078 #define USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER 0x042f 1085 1079 #define USB_DEVICE_ID_SONY_BUZZ_CONTROLLER 0x0002 1086 1080 #define USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER 0x1000 1087 1081 1088 - #define USB_VENDOR_ID_SONY_GHLIVE 0x12ba 1082 + #define USB_VENDOR_ID_SONY_RHYTHM 0x12ba 1089 1083 #define USB_DEVICE_ID_SONY_PS3WIIU_GHLIVE_DONGLE 0x074b 1084 + #define USB_DEVICE_ID_SONY_PS3_GUITAR_DONGLE 0x0100 1090 1085 1091 1086 #define USB_VENDOR_ID_SINO_LITE 0x1345 1092 1087 #define USB_DEVICE_ID_SINO_LITE_CONTROLLER 0x3008
+12
drivers/hid/hid-input.c
··· 324 324 HID_BATTERY_QUIRK_IGNORE }, 325 325 { HID_USB_DEVICE(USB_VENDOR_ID_ELAN, USB_DEVICE_ID_ASUS_UX550_TOUCHSCREEN), 326 326 HID_BATTERY_QUIRK_IGNORE }, 327 + { HID_I2C_DEVICE(USB_VENDOR_ID_ELAN, I2C_DEVICE_ID_HP_SPECTRE_X360_15), 328 + HID_BATTERY_QUIRK_IGNORE }, 327 329 {} 328 330 }; 329 331 ··· 1856 1854 list_for_each_entry(hidinput, &hid->inputs, list) { 1857 1855 if (hidinput->application == report->application) 1858 1856 return hidinput; 1857 + 1858 + /* 1859 + * Keep SystemControl and ConsumerControl applications together 1860 + * with the main keyboard, if present. 1861 + */ 1862 + if ((report->application == HID_GD_SYSTEM_CONTROL || 1863 + report->application == HID_CP_CONSUMER_CONTROL) && 1864 + hidinput->application == HID_GD_KEYBOARD) { 1865 + return hidinput; 1866 + } 1859 1867 } 1860 1868 1861 1869 return NULL;
+9 -3
drivers/hid/hid-ite.c
··· 23 23 hid_info(hdev, "Fixing up Acer Sw5-012 ITE keyboard report descriptor\n"); 24 24 rdesc[163] = HID_MAIN_ITEM_RELATIVE; 25 25 } 26 - /* For Acer One S1002 keyboard-dock */ 26 + /* For Acer One S1002/S1003 keyboard-dock */ 27 27 if (*rsize == 188 && rdesc[185] == 0x81 && rdesc[186] == 0x02) { 28 - hid_info(hdev, "Fixing up Acer S1002 ITE keyboard report descriptor\n"); 28 + hid_info(hdev, "Fixing up Acer S1002/S1003 ITE keyboard report descriptor\n"); 29 29 rdesc[186] = HID_MAIN_ITEM_RELATIVE; 30 + } 31 + /* For Acer Aspire Switch 10E (SW3-016) keyboard-dock */ 32 + if (*rsize == 210 && rdesc[184] == 0x81 && rdesc[185] == 0x02) { 33 + hid_info(hdev, "Fixing up Acer Aspire Switch 10E (SW3-016) ITE keyboard report descriptor\n"); 34 + rdesc[185] = HID_MAIN_ITEM_RELATIVE; 30 35 } 31 36 } 32 37 ··· 119 114 /* ITE8910 USB kbd ctlr, with Synaptics touchpad connected to it. */ 120 115 { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, 121 116 USB_VENDOR_ID_SYNAPTICS, 122 - USB_DEVICE_ID_SYNAPTICS_ACER_ONE_S1003) }, 117 + USB_DEVICE_ID_SYNAPTICS_ACER_ONE_S1003), 118 + .driver_data = QUIRK_TOUCHPAD_ON_OFF_REPORT }, 123 119 { } 124 120 }; 125 121 MODULE_DEVICE_TABLE(hid, ite_devices);
+1 -1
drivers/hid/hid-lg-g15.c
··· 647 647 648 648 static int lg_g15_register_led(struct lg_g15_data *g15, int i) 649 649 { 650 - const char * const led_names[] = { 650 + static const char * const led_names[] = { 651 651 "g15::kbd_backlight", 652 652 "g15::lcd_backlight", 653 653 "g15::macro_preset1",
+7 -1
drivers/hid/hid-logitech-dj.c
··· 980 980 case 0x07: 981 981 device_type = "eQUAD step 4 Gaming"; 982 982 logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); 983 + workitem.reports_supported |= STD_KEYBOARD; 983 984 break; 984 985 case 0x08: 985 986 device_type = "eQUAD step 4 for gamepads"; ··· 995 994 workitem.reports_supported |= STD_KEYBOARD; 996 995 break; 997 996 case 0x0d: 998 - device_type = "eQUAD Lightspeed 1_1"; 997 + device_type = "eQUAD Lightspeed 1.1"; 998 + logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); 999 + workitem.reports_supported |= STD_KEYBOARD; 1000 + break; 1001 + case 0x0f: 1002 + device_type = "eQUAD Lightspeed 1.2"; 999 1003 logi_hidpp_dev_conn_notif_equad(hdev, hidpp_report, &workitem); 1000 1004 workitem.reports_supported |= STD_KEYBOARD; 1001 1005 break;
+239 -7
drivers/hid/hid-logitech-hidpp.c
··· 92 92 #define HIDPP_CAPABILITY_BATTERY_MILEAGE BIT(2) 93 93 #define HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS BIT(3) 94 94 #define HIDPP_CAPABILITY_BATTERY_VOLTAGE BIT(4) 95 + #define HIDPP_CAPABILITY_BATTERY_PERCENTAGE BIT(5) 96 + #define HIDPP_CAPABILITY_UNIFIED_BATTERY BIT(6) 95 97 96 98 #define lg_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c)) 97 99 ··· 154 152 int voltage; 155 153 int charge_type; 156 154 bool online; 155 + u8 supported_levels_1004; 157 156 }; 158 157 159 158 /** ··· 1174 1171 return 0; 1175 1172 } 1176 1173 1177 - static int hidpp20_query_battery_info(struct hidpp_device *hidpp) 1174 + static int hidpp20_query_battery_info_1000(struct hidpp_device *hidpp) 1178 1175 { 1179 1176 u8 feature_type; 1180 1177 int ret; ··· 1211 1208 return 0; 1212 1209 } 1213 1210 1214 - static int hidpp20_battery_event(struct hidpp_device *hidpp, 1211 + static int hidpp20_battery_event_1000(struct hidpp_device *hidpp, 1215 1212 u8 *data, int size) 1216 1213 { 1217 1214 struct hidpp_report *report = (struct hidpp_report *)data; ··· 1382 1379 } 1383 1380 return 0; 1384 1381 } 1382 + 1383 + /* -------------------------------------------------------------------------- */ 1384 + /* 0x1004: Unified battery */ 1385 + /* -------------------------------------------------------------------------- */ 1386 + 1387 + #define HIDPP_PAGE_UNIFIED_BATTERY 0x1004 1388 + 1389 + #define CMD_UNIFIED_BATTERY_GET_CAPABILITIES 0x00 1390 + #define CMD_UNIFIED_BATTERY_GET_STATUS 0x10 1391 + 1392 + #define EVENT_UNIFIED_BATTERY_STATUS_EVENT 0x00 1393 + 1394 + #define FLAG_UNIFIED_BATTERY_LEVEL_CRITICAL BIT(0) 1395 + #define FLAG_UNIFIED_BATTERY_LEVEL_LOW BIT(1) 1396 + #define FLAG_UNIFIED_BATTERY_LEVEL_GOOD BIT(2) 1397 + #define FLAG_UNIFIED_BATTERY_LEVEL_FULL BIT(3) 1398 + 1399 + #define FLAG_UNIFIED_BATTERY_FLAGS_RECHARGEABLE BIT(0) 1400 + #define FLAG_UNIFIED_BATTERY_FLAGS_STATE_OF_CHARGE BIT(1) 1401 + 1402 + static int hidpp20_unifiedbattery_get_capabilities(struct hidpp_device *hidpp, 1403 + u8 feature_index) 1404 + { 1405 + struct hidpp_report response; 1406 + int ret; 1407 + u8 *params = (u8 *)response.fap.params; 1408 + 1409 + if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS || 1410 + hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_PERCENTAGE) { 1411 + /* we have already set the device capabilities, so let's skip */ 1412 + return 0; 1413 + } 1414 + 1415 + ret = hidpp_send_fap_command_sync(hidpp, feature_index, 1416 + CMD_UNIFIED_BATTERY_GET_CAPABILITIES, 1417 + NULL, 0, &response); 1418 + /* Ignore these intermittent errors */ 1419 + if (ret == HIDPP_ERROR_RESOURCE_ERROR) 1420 + return -EIO; 1421 + if (ret > 0) { 1422 + hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", 1423 + __func__, ret); 1424 + return -EPROTO; 1425 + } 1426 + if (ret) 1427 + return ret; 1428 + 1429 + /* 1430 + * If the device supports state of charge (battery percentage) we won't 1431 + * export the battery level information. there are 4 possible battery 1432 + * levels and they all are optional, this means that the device might 1433 + * not support any of them, we are just better off with the battery 1434 + * percentage. 1435 + */ 1436 + if (params[1] & FLAG_UNIFIED_BATTERY_FLAGS_STATE_OF_CHARGE) { 1437 + hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_PERCENTAGE; 1438 + hidpp->battery.supported_levels_1004 = 0; 1439 + } else { 1440 + hidpp->capabilities |= HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS; 1441 + hidpp->battery.supported_levels_1004 = params[0]; 1442 + } 1443 + 1444 + return 0; 1445 + } 1446 + 1447 + static int hidpp20_unifiedbattery_map_status(struct hidpp_device *hidpp, 1448 + u8 charging_status, 1449 + u8 external_power_status) 1450 + { 1451 + int status; 1452 + 1453 + switch (charging_status) { 1454 + case 0: /* discharging */ 1455 + status = POWER_SUPPLY_STATUS_DISCHARGING; 1456 + break; 1457 + case 1: /* charging */ 1458 + case 2: /* charging slow */ 1459 + status = POWER_SUPPLY_STATUS_CHARGING; 1460 + break; 1461 + case 3: /* complete */ 1462 + status = POWER_SUPPLY_STATUS_FULL; 1463 + break; 1464 + case 4: /* error */ 1465 + status = POWER_SUPPLY_STATUS_NOT_CHARGING; 1466 + hid_info(hidpp->hid_dev, "%s: charging error", 1467 + hidpp->name); 1468 + break; 1469 + default: 1470 + status = POWER_SUPPLY_STATUS_NOT_CHARGING; 1471 + break; 1472 + } 1473 + 1474 + return status; 1475 + } 1476 + 1477 + static int hidpp20_unifiedbattery_map_level(struct hidpp_device *hidpp, 1478 + u8 battery_level) 1479 + { 1480 + /* cler unsupported level bits */ 1481 + battery_level &= hidpp->battery.supported_levels_1004; 1482 + 1483 + if (battery_level & FLAG_UNIFIED_BATTERY_LEVEL_FULL) 1484 + return POWER_SUPPLY_CAPACITY_LEVEL_FULL; 1485 + else if (battery_level & FLAG_UNIFIED_BATTERY_LEVEL_GOOD) 1486 + return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; 1487 + else if (battery_level & FLAG_UNIFIED_BATTERY_LEVEL_LOW) 1488 + return POWER_SUPPLY_CAPACITY_LEVEL_LOW; 1489 + else if (battery_level & FLAG_UNIFIED_BATTERY_LEVEL_CRITICAL) 1490 + return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; 1491 + 1492 + return POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN; 1493 + } 1494 + 1495 + static int hidpp20_unifiedbattery_get_status(struct hidpp_device *hidpp, 1496 + u8 feature_index, 1497 + u8 *state_of_charge, 1498 + int *status, 1499 + int *level) 1500 + { 1501 + struct hidpp_report response; 1502 + int ret; 1503 + u8 *params = (u8 *)response.fap.params; 1504 + 1505 + ret = hidpp_send_fap_command_sync(hidpp, feature_index, 1506 + CMD_UNIFIED_BATTERY_GET_STATUS, 1507 + NULL, 0, &response); 1508 + /* Ignore these intermittent errors */ 1509 + if (ret == HIDPP_ERROR_RESOURCE_ERROR) 1510 + return -EIO; 1511 + if (ret > 0) { 1512 + hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", 1513 + __func__, ret); 1514 + return -EPROTO; 1515 + } 1516 + if (ret) 1517 + return ret; 1518 + 1519 + *state_of_charge = params[0]; 1520 + *status = hidpp20_unifiedbattery_map_status(hidpp, params[2], params[3]); 1521 + *level = hidpp20_unifiedbattery_map_level(hidpp, params[1]); 1522 + 1523 + return 0; 1524 + } 1525 + 1526 + static int hidpp20_query_battery_info_1004(struct hidpp_device *hidpp) 1527 + { 1528 + u8 feature_type; 1529 + int ret; 1530 + u8 state_of_charge; 1531 + int status, level; 1532 + 1533 + if (hidpp->battery.feature_index == 0xff) { 1534 + ret = hidpp_root_get_feature(hidpp, 1535 + HIDPP_PAGE_UNIFIED_BATTERY, 1536 + &hidpp->battery.feature_index, 1537 + &feature_type); 1538 + if (ret) 1539 + return ret; 1540 + } 1541 + 1542 + ret = hidpp20_unifiedbattery_get_capabilities(hidpp, 1543 + hidpp->battery.feature_index); 1544 + if (ret) 1545 + return ret; 1546 + 1547 + ret = hidpp20_unifiedbattery_get_status(hidpp, 1548 + hidpp->battery.feature_index, 1549 + &state_of_charge, 1550 + &status, 1551 + &level); 1552 + if (ret) 1553 + return ret; 1554 + 1555 + hidpp->capabilities |= HIDPP_CAPABILITY_UNIFIED_BATTERY; 1556 + hidpp->battery.capacity = state_of_charge; 1557 + hidpp->battery.status = status; 1558 + hidpp->battery.level = level; 1559 + hidpp->battery.online = true; 1560 + 1561 + return 0; 1562 + } 1563 + 1564 + static int hidpp20_battery_event_1004(struct hidpp_device *hidpp, 1565 + u8 *data, int size) 1566 + { 1567 + struct hidpp_report *report = (struct hidpp_report *)data; 1568 + u8 *params = (u8 *)report->fap.params; 1569 + int state_of_charge, status, level; 1570 + bool changed; 1571 + 1572 + if (report->fap.feature_index != hidpp->battery.feature_index || 1573 + report->fap.funcindex_clientid != EVENT_UNIFIED_BATTERY_STATUS_EVENT) 1574 + return 0; 1575 + 1576 + state_of_charge = params[0]; 1577 + status = hidpp20_unifiedbattery_map_status(hidpp, params[2], params[3]); 1578 + level = hidpp20_unifiedbattery_map_level(hidpp, params[1]); 1579 + 1580 + changed = status != hidpp->battery.status || 1581 + (state_of_charge != hidpp->battery.capacity && 1582 + hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_PERCENTAGE) || 1583 + (level != hidpp->battery.level && 1584 + hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_LEVEL_STATUS); 1585 + 1586 + if (changed) { 1587 + hidpp->battery.capacity = state_of_charge; 1588 + hidpp->battery.status = status; 1589 + hidpp->battery.level = level; 1590 + if (hidpp->battery.ps) 1591 + power_supply_changed(hidpp->battery.ps); 1592 + } 1593 + 1594 + return 0; 1595 + } 1596 + 1597 + /* -------------------------------------------------------------------------- */ 1598 + /* Battery feature helpers */ 1599 + /* -------------------------------------------------------------------------- */ 1385 1600 1386 1601 static enum power_supply_property hidpp_battery_props[] = { 1387 1602 POWER_SUPPLY_PROP_ONLINE, ··· 3528 3307 } 3529 3308 3530 3309 if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) { 3531 - ret = hidpp20_battery_event(hidpp, data, size); 3310 + ret = hidpp20_battery_event_1000(hidpp, data, size); 3311 + if (ret != 0) 3312 + return ret; 3313 + ret = hidpp20_battery_event_1004(hidpp, data, size); 3532 3314 if (ret != 0) 3533 3315 return ret; 3534 3316 ret = hidpp_solar_battery_event(hidpp, data, size); ··· 3667 3443 if (hidpp->quirks & HIDPP_QUIRK_CLASS_K750) 3668 3444 ret = hidpp_solar_request_battery_event(hidpp); 3669 3445 else { 3670 - ret = hidpp20_query_battery_voltage_info(hidpp); 3446 + /* we only support one battery feature right now, so let's 3447 + first check the ones that support battery level first 3448 + and leave voltage for last */ 3449 + ret = hidpp20_query_battery_info_1000(hidpp); 3671 3450 if (ret) 3672 - ret = hidpp20_query_battery_info(hidpp); 3451 + ret = hidpp20_query_battery_info_1004(hidpp); 3452 + if (ret) 3453 + ret = hidpp20_query_battery_voltage_info(hidpp); 3673 3454 } 3674 3455 3675 3456 if (ret) ··· 3702 3473 3703 3474 num_battery_props = ARRAY_SIZE(hidpp_battery_props) - 3; 3704 3475 3705 - if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE) 3476 + if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_MILEAGE || 3477 + hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_PERCENTAGE) 3706 3478 battery_props[num_battery_props++] = 3707 3479 POWER_SUPPLY_PROP_CAPACITY; 3708 3480 ··· 3880 3650 } else if (hidpp->capabilities & HIDPP_CAPABILITY_HIDPP20_BATTERY) { 3881 3651 if (hidpp->capabilities & HIDPP_CAPABILITY_BATTERY_VOLTAGE) 3882 3652 hidpp20_query_battery_voltage_info(hidpp); 3653 + else if (hidpp->capabilities & HIDPP_CAPABILITY_UNIFIED_BATTERY) 3654 + hidpp20_query_battery_info_1004(hidpp); 3883 3655 else 3884 - hidpp20_query_battery_info(hidpp); 3656 + hidpp20_query_battery_info_1000(hidpp); 3885 3657 } 3886 3658 if (hidpp->battery.ps) 3887 3659 power_supply_changed(hidpp->battery.ps);
+10
drivers/hid/hid-multitouch.c
··· 1747 1747 } 1748 1748 1749 1749 #ifdef CONFIG_PM 1750 + static int mt_suspend(struct hid_device *hdev, pm_message_t state) 1751 + { 1752 + /* High latency is desirable for power savings during S3/S0ix */ 1753 + mt_set_modes(hdev, HID_LATENCY_HIGH, true, true); 1754 + return 0; 1755 + } 1756 + 1750 1757 static int mt_reset_resume(struct hid_device *hdev) 1751 1758 { 1752 1759 mt_release_contacts(hdev); ··· 1768 1761 * Tested on 3M, Stantum, Cypress, Zytronic, eGalax, and Elan panels. */ 1769 1762 1770 1763 hid_hw_idle(hdev, 0, 0, HID_REQ_SET_IDLE); 1764 + 1765 + mt_set_modes(hdev, HID_LATENCY_NORMAL, true, true); 1771 1766 1772 1767 return 0; 1773 1768 } ··· 2164 2155 .event = mt_event, 2165 2156 .report = mt_report, 2166 2157 #ifdef CONFIG_PM 2158 + .suspend = mt_suspend, 2167 2159 .reset_resume = mt_reset_resume, 2168 2160 .resume = mt_resume, 2169 2161 #endif
+1351
drivers/hid/hid-playstation.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * HID driver for Sony DualSense(TM) controller. 4 + * 5 + * Copyright (c) 2020 Sony Interactive Entertainment 6 + */ 7 + 8 + #include <linux/bits.h> 9 + #include <linux/crc32.h> 10 + #include <linux/device.h> 11 + #include <linux/hid.h> 12 + #include <linux/idr.h> 13 + #include <linux/input/mt.h> 14 + #include <linux/module.h> 15 + 16 + #include <asm/unaligned.h> 17 + 18 + #include "hid-ids.h" 19 + 20 + /* List of connected playstation devices. */ 21 + static DEFINE_MUTEX(ps_devices_lock); 22 + static LIST_HEAD(ps_devices_list); 23 + 24 + static DEFINE_IDA(ps_player_id_allocator); 25 + 26 + #define HID_PLAYSTATION_VERSION_PATCH 0x8000 27 + 28 + /* Base class for playstation devices. */ 29 + struct ps_device { 30 + struct list_head list; 31 + struct hid_device *hdev; 32 + spinlock_t lock; 33 + 34 + uint32_t player_id; 35 + 36 + struct power_supply_desc battery_desc; 37 + struct power_supply *battery; 38 + uint8_t battery_capacity; 39 + int battery_status; 40 + 41 + uint8_t mac_address[6]; /* Note: stored in little endian order. */ 42 + uint32_t hw_version; 43 + uint32_t fw_version; 44 + 45 + int (*parse_report)(struct ps_device *dev, struct hid_report *report, u8 *data, int size); 46 + }; 47 + 48 + /* Calibration data for playstation motion sensors. */ 49 + struct ps_calibration_data { 50 + int abs_code; 51 + short bias; 52 + int sens_numer; 53 + int sens_denom; 54 + }; 55 + 56 + /* Seed values for DualShock4 / DualSense CRC32 for different report types. */ 57 + #define PS_INPUT_CRC32_SEED 0xA1 58 + #define PS_OUTPUT_CRC32_SEED 0xA2 59 + #define PS_FEATURE_CRC32_SEED 0xA3 60 + 61 + #define DS_INPUT_REPORT_USB 0x01 62 + #define DS_INPUT_REPORT_USB_SIZE 64 63 + #define DS_INPUT_REPORT_BT 0x31 64 + #define DS_INPUT_REPORT_BT_SIZE 78 65 + #define DS_OUTPUT_REPORT_USB 0x02 66 + #define DS_OUTPUT_REPORT_USB_SIZE 63 67 + #define DS_OUTPUT_REPORT_BT 0x31 68 + #define DS_OUTPUT_REPORT_BT_SIZE 78 69 + 70 + #define DS_FEATURE_REPORT_CALIBRATION 0x05 71 + #define DS_FEATURE_REPORT_CALIBRATION_SIZE 41 72 + #define DS_FEATURE_REPORT_PAIRING_INFO 0x09 73 + #define DS_FEATURE_REPORT_PAIRING_INFO_SIZE 20 74 + #define DS_FEATURE_REPORT_FIRMWARE_INFO 0x20 75 + #define DS_FEATURE_REPORT_FIRMWARE_INFO_SIZE 64 76 + 77 + /* Button masks for DualSense input report. */ 78 + #define DS_BUTTONS0_HAT_SWITCH GENMASK(3, 0) 79 + #define DS_BUTTONS0_SQUARE BIT(4) 80 + #define DS_BUTTONS0_CROSS BIT(5) 81 + #define DS_BUTTONS0_CIRCLE BIT(6) 82 + #define DS_BUTTONS0_TRIANGLE BIT(7) 83 + #define DS_BUTTONS1_L1 BIT(0) 84 + #define DS_BUTTONS1_R1 BIT(1) 85 + #define DS_BUTTONS1_L2 BIT(2) 86 + #define DS_BUTTONS1_R2 BIT(3) 87 + #define DS_BUTTONS1_CREATE BIT(4) 88 + #define DS_BUTTONS1_OPTIONS BIT(5) 89 + #define DS_BUTTONS1_L3 BIT(6) 90 + #define DS_BUTTONS1_R3 BIT(7) 91 + #define DS_BUTTONS2_PS_HOME BIT(0) 92 + #define DS_BUTTONS2_TOUCHPAD BIT(1) 93 + #define DS_BUTTONS2_MIC_MUTE BIT(2) 94 + 95 + /* Status field of DualSense input report. */ 96 + #define DS_STATUS_BATTERY_CAPACITY GENMASK(3, 0) 97 + #define DS_STATUS_CHARGING GENMASK(7, 4) 98 + #define DS_STATUS_CHARGING_SHIFT 4 99 + 100 + /* 101 + * Status of a DualSense touch point contact. 102 + * Contact IDs, with highest bit set are 'inactive' 103 + * and any associated data is then invalid. 104 + */ 105 + #define DS_TOUCH_POINT_INACTIVE BIT(7) 106 + 107 + /* Magic value required in tag field of Bluetooth output report. */ 108 + #define DS_OUTPUT_TAG 0x10 109 + /* Flags for DualSense output report. */ 110 + #define DS_OUTPUT_VALID_FLAG0_COMPATIBLE_VIBRATION BIT(0) 111 + #define DS_OUTPUT_VALID_FLAG0_HAPTICS_SELECT BIT(1) 112 + #define DS_OUTPUT_VALID_FLAG1_MIC_MUTE_LED_CONTROL_ENABLE BIT(0) 113 + #define DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE BIT(1) 114 + #define DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE BIT(2) 115 + #define DS_OUTPUT_VALID_FLAG1_RELEASE_LEDS BIT(3) 116 + #define DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE BIT(4) 117 + #define DS_OUTPUT_VALID_FLAG2_LIGHTBAR_SETUP_CONTROL_ENABLE BIT(1) 118 + #define DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE BIT(4) 119 + #define DS_OUTPUT_LIGHTBAR_SETUP_LIGHT_OUT BIT(1) 120 + 121 + /* DualSense hardware limits */ 122 + #define DS_ACC_RES_PER_G 8192 123 + #define DS_ACC_RANGE (4*DS_ACC_RES_PER_G) 124 + #define DS_GYRO_RES_PER_DEG_S 1024 125 + #define DS_GYRO_RANGE (2048*DS_GYRO_RES_PER_DEG_S) 126 + #define DS_TOUCHPAD_WIDTH 1920 127 + #define DS_TOUCHPAD_HEIGHT 1080 128 + 129 + struct dualsense { 130 + struct ps_device base; 131 + struct input_dev *gamepad; 132 + struct input_dev *sensors; 133 + struct input_dev *touchpad; 134 + 135 + /* Calibration data for accelerometer and gyroscope. */ 136 + struct ps_calibration_data accel_calib_data[3]; 137 + struct ps_calibration_data gyro_calib_data[3]; 138 + 139 + /* Timestamp for sensor data */ 140 + bool sensor_timestamp_initialized; 141 + uint32_t prev_sensor_timestamp; 142 + uint32_t sensor_timestamp_us; 143 + 144 + /* Compatible rumble state */ 145 + bool update_rumble; 146 + uint8_t motor_left; 147 + uint8_t motor_right; 148 + 149 + /* RGB lightbar */ 150 + bool update_lightbar; 151 + uint8_t lightbar_red; 152 + uint8_t lightbar_green; 153 + uint8_t lightbar_blue; 154 + 155 + /* Microphone */ 156 + bool update_mic_mute; 157 + bool mic_muted; 158 + bool last_btn_mic_state; 159 + 160 + /* Player leds */ 161 + bool update_player_leds; 162 + uint8_t player_leds_state; 163 + struct led_classdev player_leds[5]; 164 + 165 + struct work_struct output_worker; 166 + void *output_report_dmabuf; 167 + uint8_t output_seq; /* Sequence number for output report. */ 168 + }; 169 + 170 + struct dualsense_touch_point { 171 + uint8_t contact; 172 + uint8_t x_lo; 173 + uint8_t x_hi:4, y_lo:4; 174 + uint8_t y_hi; 175 + } __packed; 176 + static_assert(sizeof(struct dualsense_touch_point) == 4); 177 + 178 + /* Main DualSense input report excluding any BT/USB specific headers. */ 179 + struct dualsense_input_report { 180 + uint8_t x, y; 181 + uint8_t rx, ry; 182 + uint8_t z, rz; 183 + uint8_t seq_number; 184 + uint8_t buttons[4]; 185 + uint8_t reserved[4]; 186 + 187 + /* Motion sensors */ 188 + __le16 gyro[3]; /* x, y, z */ 189 + __le16 accel[3]; /* x, y, z */ 190 + __le32 sensor_timestamp; 191 + uint8_t reserved2; 192 + 193 + /* Touchpad */ 194 + struct dualsense_touch_point points[2]; 195 + 196 + uint8_t reserved3[12]; 197 + uint8_t status; 198 + uint8_t reserved4[10]; 199 + } __packed; 200 + /* Common input report size shared equals the size of the USB report minus 1 byte for ReportID. */ 201 + static_assert(sizeof(struct dualsense_input_report) == DS_INPUT_REPORT_USB_SIZE - 1); 202 + 203 + /* Common data between DualSense BT/USB main output report. */ 204 + struct dualsense_output_report_common { 205 + uint8_t valid_flag0; 206 + uint8_t valid_flag1; 207 + 208 + /* For DualShock 4 compatibility mode. */ 209 + uint8_t motor_right; 210 + uint8_t motor_left; 211 + 212 + /* Audio controls */ 213 + uint8_t reserved[4]; 214 + uint8_t mute_button_led; 215 + 216 + uint8_t power_save_control; 217 + uint8_t reserved2[28]; 218 + 219 + /* LEDs and lightbar */ 220 + uint8_t valid_flag2; 221 + uint8_t reserved3[2]; 222 + uint8_t lightbar_setup; 223 + uint8_t led_brightness; 224 + uint8_t player_leds; 225 + uint8_t lightbar_red; 226 + uint8_t lightbar_green; 227 + uint8_t lightbar_blue; 228 + } __packed; 229 + static_assert(sizeof(struct dualsense_output_report_common) == 47); 230 + 231 + struct dualsense_output_report_bt { 232 + uint8_t report_id; /* 0x31 */ 233 + uint8_t seq_tag; 234 + uint8_t tag; 235 + struct dualsense_output_report_common common; 236 + uint8_t reserved[24]; 237 + __le32 crc32; 238 + } __packed; 239 + static_assert(sizeof(struct dualsense_output_report_bt) == DS_OUTPUT_REPORT_BT_SIZE); 240 + 241 + struct dualsense_output_report_usb { 242 + uint8_t report_id; /* 0x02 */ 243 + struct dualsense_output_report_common common; 244 + uint8_t reserved[15]; 245 + } __packed; 246 + static_assert(sizeof(struct dualsense_output_report_usb) == DS_OUTPUT_REPORT_USB_SIZE); 247 + 248 + /* 249 + * The DualSense has a main output report used to control most features. It is 250 + * largely the same between Bluetooth and USB except for different headers and CRC. 251 + * This structure hide the differences between the two to simplify sending output reports. 252 + */ 253 + struct dualsense_output_report { 254 + uint8_t *data; /* Start of data */ 255 + uint8_t len; /* Size of output report */ 256 + 257 + /* Points to Bluetooth data payload in case for a Bluetooth report else NULL. */ 258 + struct dualsense_output_report_bt *bt; 259 + /* Points to USB data payload in case for a USB report else NULL. */ 260 + struct dualsense_output_report_usb *usb; 261 + /* Points to common section of report, so past any headers. */ 262 + struct dualsense_output_report_common *common; 263 + }; 264 + 265 + /* 266 + * Common gamepad buttons across DualShock 3 / 4 and DualSense. 267 + * Note: for device with a touchpad, touchpad button is not included 268 + * as it will be part of the touchpad device. 269 + */ 270 + static const int ps_gamepad_buttons[] = { 271 + BTN_WEST, /* Square */ 272 + BTN_NORTH, /* Triangle */ 273 + BTN_EAST, /* Circle */ 274 + BTN_SOUTH, /* Cross */ 275 + BTN_TL, /* L1 */ 276 + BTN_TR, /* R1 */ 277 + BTN_TL2, /* L2 */ 278 + BTN_TR2, /* R2 */ 279 + BTN_SELECT, /* Create (PS5) / Share (PS4) */ 280 + BTN_START, /* Option */ 281 + BTN_THUMBL, /* L3 */ 282 + BTN_THUMBR, /* R3 */ 283 + BTN_MODE, /* PS Home */ 284 + }; 285 + 286 + static const struct {int x; int y; } ps_gamepad_hat_mapping[] = { 287 + {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, 288 + {0, 0}, 289 + }; 290 + 291 + /* 292 + * Add a new ps_device to ps_devices if it doesn't exist. 293 + * Return error on duplicate device, which can happen if the same 294 + * device is connected using both Bluetooth and USB. 295 + */ 296 + static int ps_devices_list_add(struct ps_device *dev) 297 + { 298 + struct ps_device *entry; 299 + 300 + mutex_lock(&ps_devices_lock); 301 + list_for_each_entry(entry, &ps_devices_list, list) { 302 + if (!memcmp(entry->mac_address, dev->mac_address, sizeof(dev->mac_address))) { 303 + hid_err(dev->hdev, "Duplicate device found for MAC address %pMR.\n", 304 + dev->mac_address); 305 + mutex_unlock(&ps_devices_lock); 306 + return -EEXIST; 307 + } 308 + } 309 + 310 + list_add_tail(&dev->list, &ps_devices_list); 311 + mutex_unlock(&ps_devices_lock); 312 + return 0; 313 + } 314 + 315 + static int ps_devices_list_remove(struct ps_device *dev) 316 + { 317 + mutex_lock(&ps_devices_lock); 318 + list_del(&dev->list); 319 + mutex_unlock(&ps_devices_lock); 320 + return 0; 321 + } 322 + 323 + static int ps_device_set_player_id(struct ps_device *dev) 324 + { 325 + int ret = ida_alloc(&ps_player_id_allocator, GFP_KERNEL); 326 + 327 + if (ret < 0) 328 + return ret; 329 + 330 + dev->player_id = ret; 331 + return 0; 332 + } 333 + 334 + static void ps_device_release_player_id(struct ps_device *dev) 335 + { 336 + ida_free(&ps_player_id_allocator, dev->player_id); 337 + 338 + dev->player_id = U32_MAX; 339 + } 340 + 341 + static struct input_dev *ps_allocate_input_dev(struct hid_device *hdev, const char *name_suffix) 342 + { 343 + struct input_dev *input_dev; 344 + 345 + input_dev = devm_input_allocate_device(&hdev->dev); 346 + if (!input_dev) 347 + return ERR_PTR(-ENOMEM); 348 + 349 + input_dev->id.bustype = hdev->bus; 350 + input_dev->id.vendor = hdev->vendor; 351 + input_dev->id.product = hdev->product; 352 + input_dev->id.version = hdev->version; 353 + input_dev->uniq = hdev->uniq; 354 + 355 + if (name_suffix) { 356 + input_dev->name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "%s %s", hdev->name, 357 + name_suffix); 358 + if (!input_dev->name) 359 + return ERR_PTR(-ENOMEM); 360 + } else { 361 + input_dev->name = hdev->name; 362 + } 363 + 364 + input_set_drvdata(input_dev, hdev); 365 + 366 + return input_dev; 367 + } 368 + 369 + static enum power_supply_property ps_power_supply_props[] = { 370 + POWER_SUPPLY_PROP_STATUS, 371 + POWER_SUPPLY_PROP_PRESENT, 372 + POWER_SUPPLY_PROP_CAPACITY, 373 + POWER_SUPPLY_PROP_SCOPE, 374 + }; 375 + 376 + static int ps_battery_get_property(struct power_supply *psy, 377 + enum power_supply_property psp, 378 + union power_supply_propval *val) 379 + { 380 + struct ps_device *dev = power_supply_get_drvdata(psy); 381 + uint8_t battery_capacity; 382 + int battery_status; 383 + unsigned long flags; 384 + int ret = 0; 385 + 386 + spin_lock_irqsave(&dev->lock, flags); 387 + battery_capacity = dev->battery_capacity; 388 + battery_status = dev->battery_status; 389 + spin_unlock_irqrestore(&dev->lock, flags); 390 + 391 + switch (psp) { 392 + case POWER_SUPPLY_PROP_STATUS: 393 + val->intval = battery_status; 394 + break; 395 + case POWER_SUPPLY_PROP_PRESENT: 396 + val->intval = 1; 397 + break; 398 + case POWER_SUPPLY_PROP_CAPACITY: 399 + val->intval = battery_capacity; 400 + break; 401 + case POWER_SUPPLY_PROP_SCOPE: 402 + val->intval = POWER_SUPPLY_SCOPE_DEVICE; 403 + break; 404 + default: 405 + ret = -EINVAL; 406 + break; 407 + } 408 + 409 + return ret; 410 + } 411 + 412 + static int ps_device_register_battery(struct ps_device *dev) 413 + { 414 + struct power_supply *battery; 415 + struct power_supply_config battery_cfg = { .drv_data = dev }; 416 + int ret; 417 + 418 + dev->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; 419 + dev->battery_desc.properties = ps_power_supply_props; 420 + dev->battery_desc.num_properties = ARRAY_SIZE(ps_power_supply_props); 421 + dev->battery_desc.get_property = ps_battery_get_property; 422 + dev->battery_desc.name = devm_kasprintf(&dev->hdev->dev, GFP_KERNEL, 423 + "ps-controller-battery-%pMR", dev->mac_address); 424 + if (!dev->battery_desc.name) 425 + return -ENOMEM; 426 + 427 + battery = devm_power_supply_register(&dev->hdev->dev, &dev->battery_desc, &battery_cfg); 428 + if (IS_ERR(battery)) { 429 + ret = PTR_ERR(battery); 430 + hid_err(dev->hdev, "Unable to register battery device: %d\n", ret); 431 + return ret; 432 + } 433 + dev->battery = battery; 434 + 435 + ret = power_supply_powers(dev->battery, &dev->hdev->dev); 436 + if (ret) { 437 + hid_err(dev->hdev, "Unable to activate battery device: %d\n", ret); 438 + return ret; 439 + } 440 + 441 + return 0; 442 + } 443 + 444 + /* Compute crc32 of HID data and compare against expected CRC. */ 445 + static bool ps_check_crc32(uint8_t seed, uint8_t *data, size_t len, uint32_t report_crc) 446 + { 447 + uint32_t crc; 448 + 449 + crc = crc32_le(0xFFFFFFFF, &seed, 1); 450 + crc = ~crc32_le(crc, data, len); 451 + 452 + return crc == report_crc; 453 + } 454 + 455 + static struct input_dev *ps_gamepad_create(struct hid_device *hdev, 456 + int (*play_effect)(struct input_dev *, void *, struct ff_effect *)) 457 + { 458 + struct input_dev *gamepad; 459 + unsigned int i; 460 + int ret; 461 + 462 + gamepad = ps_allocate_input_dev(hdev, NULL); 463 + if (IS_ERR(gamepad)) 464 + return ERR_CAST(gamepad); 465 + 466 + input_set_abs_params(gamepad, ABS_X, 0, 255, 0, 0); 467 + input_set_abs_params(gamepad, ABS_Y, 0, 255, 0, 0); 468 + input_set_abs_params(gamepad, ABS_Z, 0, 255, 0, 0); 469 + input_set_abs_params(gamepad, ABS_RX, 0, 255, 0, 0); 470 + input_set_abs_params(gamepad, ABS_RY, 0, 255, 0, 0); 471 + input_set_abs_params(gamepad, ABS_RZ, 0, 255, 0, 0); 472 + 473 + input_set_abs_params(gamepad, ABS_HAT0X, -1, 1, 0, 0); 474 + input_set_abs_params(gamepad, ABS_HAT0Y, -1, 1, 0, 0); 475 + 476 + for (i = 0; i < ARRAY_SIZE(ps_gamepad_buttons); i++) 477 + input_set_capability(gamepad, EV_KEY, ps_gamepad_buttons[i]); 478 + 479 + #if IS_ENABLED(CONFIG_PLAYSTATION_FF) 480 + if (play_effect) { 481 + input_set_capability(gamepad, EV_FF, FF_RUMBLE); 482 + input_ff_create_memless(gamepad, NULL, play_effect); 483 + } 484 + #endif 485 + 486 + ret = input_register_device(gamepad); 487 + if (ret) 488 + return ERR_PTR(ret); 489 + 490 + return gamepad; 491 + } 492 + 493 + static int ps_get_report(struct hid_device *hdev, uint8_t report_id, uint8_t *buf, size_t size) 494 + { 495 + int ret; 496 + 497 + ret = hid_hw_raw_request(hdev, report_id, buf, size, HID_FEATURE_REPORT, 498 + HID_REQ_GET_REPORT); 499 + if (ret < 0) { 500 + hid_err(hdev, "Failed to retrieve feature with reportID %d: %d\n", report_id, ret); 501 + return ret; 502 + } 503 + 504 + if (ret != size) { 505 + hid_err(hdev, "Invalid byte count transferred, expected %zu got %d\n", size, ret); 506 + return -EINVAL; 507 + } 508 + 509 + if (buf[0] != report_id) { 510 + hid_err(hdev, "Invalid reportID received, expected %d got %d\n", report_id, buf[0]); 511 + return -EINVAL; 512 + } 513 + 514 + if (hdev->bus == BUS_BLUETOOTH) { 515 + /* Last 4 bytes contains crc32. */ 516 + uint8_t crc_offset = size - 4; 517 + uint32_t report_crc = get_unaligned_le32(&buf[crc_offset]); 518 + 519 + if (!ps_check_crc32(PS_FEATURE_CRC32_SEED, buf, crc_offset, report_crc)) { 520 + hid_err(hdev, "CRC check failed for reportID=%d\n", report_id); 521 + return -EILSEQ; 522 + } 523 + } 524 + 525 + return 0; 526 + } 527 + 528 + static struct input_dev *ps_sensors_create(struct hid_device *hdev, int accel_range, int accel_res, 529 + int gyro_range, int gyro_res) 530 + { 531 + struct input_dev *sensors; 532 + int ret; 533 + 534 + sensors = ps_allocate_input_dev(hdev, "Motion Sensors"); 535 + if (IS_ERR(sensors)) 536 + return ERR_CAST(sensors); 537 + 538 + __set_bit(INPUT_PROP_ACCELEROMETER, sensors->propbit); 539 + __set_bit(EV_MSC, sensors->evbit); 540 + __set_bit(MSC_TIMESTAMP, sensors->mscbit); 541 + 542 + /* Accelerometer */ 543 + input_set_abs_params(sensors, ABS_X, -accel_range, accel_range, 16, 0); 544 + input_set_abs_params(sensors, ABS_Y, -accel_range, accel_range, 16, 0); 545 + input_set_abs_params(sensors, ABS_Z, -accel_range, accel_range, 16, 0); 546 + input_abs_set_res(sensors, ABS_X, accel_res); 547 + input_abs_set_res(sensors, ABS_Y, accel_res); 548 + input_abs_set_res(sensors, ABS_Z, accel_res); 549 + 550 + /* Gyroscope */ 551 + input_set_abs_params(sensors, ABS_RX, -gyro_range, gyro_range, 16, 0); 552 + input_set_abs_params(sensors, ABS_RY, -gyro_range, gyro_range, 16, 0); 553 + input_set_abs_params(sensors, ABS_RZ, -gyro_range, gyro_range, 16, 0); 554 + input_abs_set_res(sensors, ABS_RX, gyro_res); 555 + input_abs_set_res(sensors, ABS_RY, gyro_res); 556 + input_abs_set_res(sensors, ABS_RZ, gyro_res); 557 + 558 + ret = input_register_device(sensors); 559 + if (ret) 560 + return ERR_PTR(ret); 561 + 562 + return sensors; 563 + } 564 + 565 + static struct input_dev *ps_touchpad_create(struct hid_device *hdev, int width, int height, 566 + unsigned int num_contacts) 567 + { 568 + struct input_dev *touchpad; 569 + int ret; 570 + 571 + touchpad = ps_allocate_input_dev(hdev, "Touchpad"); 572 + if (IS_ERR(touchpad)) 573 + return ERR_CAST(touchpad); 574 + 575 + /* Map button underneath touchpad to BTN_LEFT. */ 576 + input_set_capability(touchpad, EV_KEY, BTN_LEFT); 577 + __set_bit(INPUT_PROP_BUTTONPAD, touchpad->propbit); 578 + 579 + input_set_abs_params(touchpad, ABS_MT_POSITION_X, 0, width - 1, 0, 0); 580 + input_set_abs_params(touchpad, ABS_MT_POSITION_Y, 0, height - 1, 0, 0); 581 + 582 + ret = input_mt_init_slots(touchpad, num_contacts, INPUT_MT_POINTER); 583 + if (ret) 584 + return ERR_PTR(ret); 585 + 586 + ret = input_register_device(touchpad); 587 + if (ret) 588 + return ERR_PTR(ret); 589 + 590 + return touchpad; 591 + } 592 + 593 + static ssize_t firmware_version_show(struct device *dev, 594 + struct device_attribute 595 + *attr, char *buf) 596 + { 597 + struct hid_device *hdev = to_hid_device(dev); 598 + struct ps_device *ps_dev = hid_get_drvdata(hdev); 599 + 600 + return sysfs_emit(buf, "0x%08x\n", ps_dev->fw_version); 601 + } 602 + 603 + static DEVICE_ATTR_RO(firmware_version); 604 + 605 + static ssize_t hardware_version_show(struct device *dev, 606 + struct device_attribute 607 + *attr, char *buf) 608 + { 609 + struct hid_device *hdev = to_hid_device(dev); 610 + struct ps_device *ps_dev = hid_get_drvdata(hdev); 611 + 612 + return sysfs_emit(buf, "0x%08x\n", ps_dev->hw_version); 613 + } 614 + 615 + static DEVICE_ATTR_RO(hardware_version); 616 + 617 + static struct attribute *ps_device_attributes[] = { 618 + &dev_attr_firmware_version.attr, 619 + &dev_attr_hardware_version.attr, 620 + NULL 621 + }; 622 + 623 + static const struct attribute_group ps_device_attribute_group = { 624 + .attrs = ps_device_attributes, 625 + }; 626 + 627 + static int dualsense_get_calibration_data(struct dualsense *ds) 628 + { 629 + short gyro_pitch_bias, gyro_pitch_plus, gyro_pitch_minus; 630 + short gyro_yaw_bias, gyro_yaw_plus, gyro_yaw_minus; 631 + short gyro_roll_bias, gyro_roll_plus, gyro_roll_minus; 632 + short gyro_speed_plus, gyro_speed_minus; 633 + short acc_x_plus, acc_x_minus; 634 + short acc_y_plus, acc_y_minus; 635 + short acc_z_plus, acc_z_minus; 636 + int speed_2x; 637 + int range_2g; 638 + int ret = 0; 639 + uint8_t *buf; 640 + 641 + buf = kzalloc(DS_FEATURE_REPORT_CALIBRATION_SIZE, GFP_KERNEL); 642 + if (!buf) 643 + return -ENOMEM; 644 + 645 + ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_CALIBRATION, buf, 646 + DS_FEATURE_REPORT_CALIBRATION_SIZE); 647 + if (ret) { 648 + hid_err(ds->base.hdev, "Failed to retrieve DualSense calibration info: %d\n", ret); 649 + goto err_free; 650 + } 651 + 652 + gyro_pitch_bias = get_unaligned_le16(&buf[1]); 653 + gyro_yaw_bias = get_unaligned_le16(&buf[3]); 654 + gyro_roll_bias = get_unaligned_le16(&buf[5]); 655 + gyro_pitch_plus = get_unaligned_le16(&buf[7]); 656 + gyro_pitch_minus = get_unaligned_le16(&buf[9]); 657 + gyro_yaw_plus = get_unaligned_le16(&buf[11]); 658 + gyro_yaw_minus = get_unaligned_le16(&buf[13]); 659 + gyro_roll_plus = get_unaligned_le16(&buf[15]); 660 + gyro_roll_minus = get_unaligned_le16(&buf[17]); 661 + gyro_speed_plus = get_unaligned_le16(&buf[19]); 662 + gyro_speed_minus = get_unaligned_le16(&buf[21]); 663 + acc_x_plus = get_unaligned_le16(&buf[23]); 664 + acc_x_minus = get_unaligned_le16(&buf[25]); 665 + acc_y_plus = get_unaligned_le16(&buf[27]); 666 + acc_y_minus = get_unaligned_le16(&buf[29]); 667 + acc_z_plus = get_unaligned_le16(&buf[31]); 668 + acc_z_minus = get_unaligned_le16(&buf[33]); 669 + 670 + /* 671 + * Set gyroscope calibration and normalization parameters. 672 + * Data values will be normalized to 1/DS_GYRO_RES_PER_DEG_S degree/s. 673 + */ 674 + speed_2x = (gyro_speed_plus + gyro_speed_minus); 675 + ds->gyro_calib_data[0].abs_code = ABS_RX; 676 + ds->gyro_calib_data[0].bias = gyro_pitch_bias; 677 + ds->gyro_calib_data[0].sens_numer = speed_2x*DS_GYRO_RES_PER_DEG_S; 678 + ds->gyro_calib_data[0].sens_denom = gyro_pitch_plus - gyro_pitch_minus; 679 + 680 + ds->gyro_calib_data[1].abs_code = ABS_RY; 681 + ds->gyro_calib_data[1].bias = gyro_yaw_bias; 682 + ds->gyro_calib_data[1].sens_numer = speed_2x*DS_GYRO_RES_PER_DEG_S; 683 + ds->gyro_calib_data[1].sens_denom = gyro_yaw_plus - gyro_yaw_minus; 684 + 685 + ds->gyro_calib_data[2].abs_code = ABS_RZ; 686 + ds->gyro_calib_data[2].bias = gyro_roll_bias; 687 + ds->gyro_calib_data[2].sens_numer = speed_2x*DS_GYRO_RES_PER_DEG_S; 688 + ds->gyro_calib_data[2].sens_denom = gyro_roll_plus - gyro_roll_minus; 689 + 690 + /* 691 + * Set accelerometer calibration and normalization parameters. 692 + * Data values will be normalized to 1/DS_ACC_RES_PER_G g. 693 + */ 694 + range_2g = acc_x_plus - acc_x_minus; 695 + ds->accel_calib_data[0].abs_code = ABS_X; 696 + ds->accel_calib_data[0].bias = acc_x_plus - range_2g / 2; 697 + ds->accel_calib_data[0].sens_numer = 2*DS_ACC_RES_PER_G; 698 + ds->accel_calib_data[0].sens_denom = range_2g; 699 + 700 + range_2g = acc_y_plus - acc_y_minus; 701 + ds->accel_calib_data[1].abs_code = ABS_Y; 702 + ds->accel_calib_data[1].bias = acc_y_plus - range_2g / 2; 703 + ds->accel_calib_data[1].sens_numer = 2*DS_ACC_RES_PER_G; 704 + ds->accel_calib_data[1].sens_denom = range_2g; 705 + 706 + range_2g = acc_z_plus - acc_z_minus; 707 + ds->accel_calib_data[2].abs_code = ABS_Z; 708 + ds->accel_calib_data[2].bias = acc_z_plus - range_2g / 2; 709 + ds->accel_calib_data[2].sens_numer = 2*DS_ACC_RES_PER_G; 710 + ds->accel_calib_data[2].sens_denom = range_2g; 711 + 712 + err_free: 713 + kfree(buf); 714 + return ret; 715 + } 716 + 717 + static int dualsense_get_firmware_info(struct dualsense *ds) 718 + { 719 + uint8_t *buf; 720 + int ret; 721 + 722 + buf = kzalloc(DS_FEATURE_REPORT_FIRMWARE_INFO_SIZE, GFP_KERNEL); 723 + if (!buf) 724 + return -ENOMEM; 725 + 726 + ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_FIRMWARE_INFO, buf, 727 + DS_FEATURE_REPORT_FIRMWARE_INFO_SIZE); 728 + if (ret) { 729 + hid_err(ds->base.hdev, "Failed to retrieve DualSense firmware info: %d\n", ret); 730 + goto err_free; 731 + } 732 + 733 + ds->base.hw_version = get_unaligned_le32(&buf[24]); 734 + ds->base.fw_version = get_unaligned_le32(&buf[28]); 735 + 736 + err_free: 737 + kfree(buf); 738 + return ret; 739 + } 740 + 741 + static int dualsense_get_mac_address(struct dualsense *ds) 742 + { 743 + uint8_t *buf; 744 + int ret = 0; 745 + 746 + buf = kzalloc(DS_FEATURE_REPORT_PAIRING_INFO_SIZE, GFP_KERNEL); 747 + if (!buf) 748 + return -ENOMEM; 749 + 750 + ret = ps_get_report(ds->base.hdev, DS_FEATURE_REPORT_PAIRING_INFO, buf, 751 + DS_FEATURE_REPORT_PAIRING_INFO_SIZE); 752 + if (ret) { 753 + hid_err(ds->base.hdev, "Failed to retrieve DualSense pairing info: %d\n", ret); 754 + goto err_free; 755 + } 756 + 757 + memcpy(ds->base.mac_address, &buf[1], sizeof(ds->base.mac_address)); 758 + 759 + err_free: 760 + kfree(buf); 761 + return ret; 762 + } 763 + 764 + static void dualsense_init_output_report(struct dualsense *ds, struct dualsense_output_report *rp, 765 + void *buf) 766 + { 767 + struct hid_device *hdev = ds->base.hdev; 768 + 769 + if (hdev->bus == BUS_BLUETOOTH) { 770 + struct dualsense_output_report_bt *bt = buf; 771 + 772 + memset(bt, 0, sizeof(*bt)); 773 + bt->report_id = DS_OUTPUT_REPORT_BT; 774 + bt->tag = DS_OUTPUT_TAG; /* Tag must be set. Exact meaning is unclear. */ 775 + 776 + /* 777 + * Highest 4-bit is a sequence number, which needs to be increased 778 + * every report. Lowest 4-bit is tag and can be zero for now. 779 + */ 780 + bt->seq_tag = (ds->output_seq << 4) | 0x0; 781 + if (++ds->output_seq == 16) 782 + ds->output_seq = 0; 783 + 784 + rp->data = buf; 785 + rp->len = sizeof(*bt); 786 + rp->bt = bt; 787 + rp->usb = NULL; 788 + rp->common = &bt->common; 789 + } else { /* USB */ 790 + struct dualsense_output_report_usb *usb = buf; 791 + 792 + memset(usb, 0, sizeof(*usb)); 793 + usb->report_id = DS_OUTPUT_REPORT_USB; 794 + 795 + rp->data = buf; 796 + rp->len = sizeof(*usb); 797 + rp->bt = NULL; 798 + rp->usb = usb; 799 + rp->common = &usb->common; 800 + } 801 + } 802 + 803 + /* 804 + * Helper function to send DualSense output reports. Applies a CRC at the end of a report 805 + * for Bluetooth reports. 806 + */ 807 + static void dualsense_send_output_report(struct dualsense *ds, 808 + struct dualsense_output_report *report) 809 + { 810 + struct hid_device *hdev = ds->base.hdev; 811 + 812 + /* Bluetooth packets need to be signed with a CRC in the last 4 bytes. */ 813 + if (report->bt) { 814 + uint32_t crc; 815 + uint8_t seed = PS_OUTPUT_CRC32_SEED; 816 + 817 + crc = crc32_le(0xFFFFFFFF, &seed, 1); 818 + crc = ~crc32_le(crc, report->data, report->len - 4); 819 + 820 + report->bt->crc32 = cpu_to_le32(crc); 821 + } 822 + 823 + hid_hw_output_report(hdev, report->data, report->len); 824 + } 825 + 826 + static void dualsense_output_worker(struct work_struct *work) 827 + { 828 + struct dualsense *ds = container_of(work, struct dualsense, output_worker); 829 + struct dualsense_output_report report; 830 + struct dualsense_output_report_common *common; 831 + unsigned long flags; 832 + 833 + dualsense_init_output_report(ds, &report, ds->output_report_dmabuf); 834 + common = report.common; 835 + 836 + spin_lock_irqsave(&ds->base.lock, flags); 837 + 838 + if (ds->update_rumble) { 839 + /* Select classic rumble style haptics and enable it. */ 840 + common->valid_flag0 |= DS_OUTPUT_VALID_FLAG0_HAPTICS_SELECT; 841 + common->valid_flag0 |= DS_OUTPUT_VALID_FLAG0_COMPATIBLE_VIBRATION; 842 + common->motor_left = ds->motor_left; 843 + common->motor_right = ds->motor_right; 844 + ds->update_rumble = false; 845 + } 846 + 847 + if (ds->update_lightbar) { 848 + common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_LIGHTBAR_CONTROL_ENABLE; 849 + common->lightbar_red = ds->lightbar_red; 850 + common->lightbar_green = ds->lightbar_green; 851 + common->lightbar_blue = ds->lightbar_blue; 852 + 853 + ds->update_lightbar = false; 854 + } 855 + 856 + if (ds->update_player_leds) { 857 + common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_PLAYER_INDICATOR_CONTROL_ENABLE; 858 + common->player_leds = ds->player_leds_state; 859 + 860 + ds->update_player_leds = false; 861 + } 862 + 863 + if (ds->update_mic_mute) { 864 + common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_MIC_MUTE_LED_CONTROL_ENABLE; 865 + common->mute_button_led = ds->mic_muted; 866 + 867 + if (ds->mic_muted) { 868 + /* Disable microphone */ 869 + common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE; 870 + common->power_save_control |= DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE; 871 + } else { 872 + /* Enable microphone */ 873 + common->valid_flag1 |= DS_OUTPUT_VALID_FLAG1_POWER_SAVE_CONTROL_ENABLE; 874 + common->power_save_control &= ~DS_OUTPUT_POWER_SAVE_CONTROL_MIC_MUTE; 875 + } 876 + 877 + ds->update_mic_mute = false; 878 + } 879 + 880 + spin_unlock_irqrestore(&ds->base.lock, flags); 881 + 882 + dualsense_send_output_report(ds, &report); 883 + } 884 + 885 + static int dualsense_parse_report(struct ps_device *ps_dev, struct hid_report *report, 886 + u8 *data, int size) 887 + { 888 + struct hid_device *hdev = ps_dev->hdev; 889 + struct dualsense *ds = container_of(ps_dev, struct dualsense, base); 890 + struct dualsense_input_report *ds_report; 891 + uint8_t battery_data, battery_capacity, charging_status, value; 892 + int battery_status; 893 + uint32_t sensor_timestamp; 894 + bool btn_mic_state; 895 + unsigned long flags; 896 + int i; 897 + 898 + /* 899 + * DualSense in USB uses the full HID report for reportID 1, but 900 + * Bluetooth uses a minimal HID report for reportID 1 and reports 901 + * the full report using reportID 49. 902 + */ 903 + if (hdev->bus == BUS_USB && report->id == DS_INPUT_REPORT_USB && 904 + size == DS_INPUT_REPORT_USB_SIZE) { 905 + ds_report = (struct dualsense_input_report *)&data[1]; 906 + } else if (hdev->bus == BUS_BLUETOOTH && report->id == DS_INPUT_REPORT_BT && 907 + size == DS_INPUT_REPORT_BT_SIZE) { 908 + /* Last 4 bytes of input report contain crc32 */ 909 + uint32_t report_crc = get_unaligned_le32(&data[size - 4]); 910 + 911 + if (!ps_check_crc32(PS_INPUT_CRC32_SEED, data, size - 4, report_crc)) { 912 + hid_err(hdev, "DualSense input CRC's check failed\n"); 913 + return -EILSEQ; 914 + } 915 + 916 + ds_report = (struct dualsense_input_report *)&data[2]; 917 + } else { 918 + hid_err(hdev, "Unhandled reportID=%d\n", report->id); 919 + return -1; 920 + } 921 + 922 + input_report_abs(ds->gamepad, ABS_X, ds_report->x); 923 + input_report_abs(ds->gamepad, ABS_Y, ds_report->y); 924 + input_report_abs(ds->gamepad, ABS_RX, ds_report->rx); 925 + input_report_abs(ds->gamepad, ABS_RY, ds_report->ry); 926 + input_report_abs(ds->gamepad, ABS_Z, ds_report->z); 927 + input_report_abs(ds->gamepad, ABS_RZ, ds_report->rz); 928 + 929 + value = ds_report->buttons[0] & DS_BUTTONS0_HAT_SWITCH; 930 + if (value >= ARRAY_SIZE(ps_gamepad_hat_mapping)) 931 + value = 8; /* center */ 932 + input_report_abs(ds->gamepad, ABS_HAT0X, ps_gamepad_hat_mapping[value].x); 933 + input_report_abs(ds->gamepad, ABS_HAT0Y, ps_gamepad_hat_mapping[value].y); 934 + 935 + input_report_key(ds->gamepad, BTN_WEST, ds_report->buttons[0] & DS_BUTTONS0_SQUARE); 936 + input_report_key(ds->gamepad, BTN_SOUTH, ds_report->buttons[0] & DS_BUTTONS0_CROSS); 937 + input_report_key(ds->gamepad, BTN_EAST, ds_report->buttons[0] & DS_BUTTONS0_CIRCLE); 938 + input_report_key(ds->gamepad, BTN_NORTH, ds_report->buttons[0] & DS_BUTTONS0_TRIANGLE); 939 + input_report_key(ds->gamepad, BTN_TL, ds_report->buttons[1] & DS_BUTTONS1_L1); 940 + input_report_key(ds->gamepad, BTN_TR, ds_report->buttons[1] & DS_BUTTONS1_R1); 941 + input_report_key(ds->gamepad, BTN_TL2, ds_report->buttons[1] & DS_BUTTONS1_L2); 942 + input_report_key(ds->gamepad, BTN_TR2, ds_report->buttons[1] & DS_BUTTONS1_R2); 943 + input_report_key(ds->gamepad, BTN_SELECT, ds_report->buttons[1] & DS_BUTTONS1_CREATE); 944 + input_report_key(ds->gamepad, BTN_START, ds_report->buttons[1] & DS_BUTTONS1_OPTIONS); 945 + input_report_key(ds->gamepad, BTN_THUMBL, ds_report->buttons[1] & DS_BUTTONS1_L3); 946 + input_report_key(ds->gamepad, BTN_THUMBR, ds_report->buttons[1] & DS_BUTTONS1_R3); 947 + input_report_key(ds->gamepad, BTN_MODE, ds_report->buttons[2] & DS_BUTTONS2_PS_HOME); 948 + input_sync(ds->gamepad); 949 + 950 + /* 951 + * The DualSense has an internal microphone, which can be muted through a mute button 952 + * on the device. The driver is expected to read the button state and program the device 953 + * to mute/unmute audio at the hardware level. 954 + */ 955 + btn_mic_state = !!(ds_report->buttons[2] & DS_BUTTONS2_MIC_MUTE); 956 + if (btn_mic_state && !ds->last_btn_mic_state) { 957 + spin_lock_irqsave(&ps_dev->lock, flags); 958 + ds->update_mic_mute = true; 959 + ds->mic_muted = !ds->mic_muted; /* toggle */ 960 + spin_unlock_irqrestore(&ps_dev->lock, flags); 961 + 962 + /* Schedule updating of microphone state at hardware level. */ 963 + schedule_work(&ds->output_worker); 964 + } 965 + ds->last_btn_mic_state = btn_mic_state; 966 + 967 + /* Parse and calibrate gyroscope data. */ 968 + for (i = 0; i < ARRAY_SIZE(ds_report->gyro); i++) { 969 + int raw_data = (short)le16_to_cpu(ds_report->gyro[i]); 970 + int calib_data = mult_frac(ds->gyro_calib_data[i].sens_numer, 971 + raw_data - ds->gyro_calib_data[i].bias, 972 + ds->gyro_calib_data[i].sens_denom); 973 + 974 + input_report_abs(ds->sensors, ds->gyro_calib_data[i].abs_code, calib_data); 975 + } 976 + 977 + /* Parse and calibrate accelerometer data. */ 978 + for (i = 0; i < ARRAY_SIZE(ds_report->accel); i++) { 979 + int raw_data = (short)le16_to_cpu(ds_report->accel[i]); 980 + int calib_data = mult_frac(ds->accel_calib_data[i].sens_numer, 981 + raw_data - ds->accel_calib_data[i].bias, 982 + ds->accel_calib_data[i].sens_denom); 983 + 984 + input_report_abs(ds->sensors, ds->accel_calib_data[i].abs_code, calib_data); 985 + } 986 + 987 + /* Convert timestamp (in 0.33us unit) to timestamp_us */ 988 + sensor_timestamp = le32_to_cpu(ds_report->sensor_timestamp); 989 + if (!ds->sensor_timestamp_initialized) { 990 + ds->sensor_timestamp_us = DIV_ROUND_CLOSEST(sensor_timestamp, 3); 991 + ds->sensor_timestamp_initialized = true; 992 + } else { 993 + uint32_t delta; 994 + 995 + if (ds->prev_sensor_timestamp > sensor_timestamp) 996 + delta = (U32_MAX - ds->prev_sensor_timestamp + sensor_timestamp + 1); 997 + else 998 + delta = sensor_timestamp - ds->prev_sensor_timestamp; 999 + ds->sensor_timestamp_us += DIV_ROUND_CLOSEST(delta, 3); 1000 + } 1001 + ds->prev_sensor_timestamp = sensor_timestamp; 1002 + input_event(ds->sensors, EV_MSC, MSC_TIMESTAMP, ds->sensor_timestamp_us); 1003 + input_sync(ds->sensors); 1004 + 1005 + for (i = 0; i < ARRAY_SIZE(ds_report->points); i++) { 1006 + struct dualsense_touch_point *point = &ds_report->points[i]; 1007 + bool active = (point->contact & DS_TOUCH_POINT_INACTIVE) ? false : true; 1008 + 1009 + input_mt_slot(ds->touchpad, i); 1010 + input_mt_report_slot_state(ds->touchpad, MT_TOOL_FINGER, active); 1011 + 1012 + if (active) { 1013 + int x = (point->x_hi << 8) | point->x_lo; 1014 + int y = (point->y_hi << 4) | point->y_lo; 1015 + 1016 + input_report_abs(ds->touchpad, ABS_MT_POSITION_X, x); 1017 + input_report_abs(ds->touchpad, ABS_MT_POSITION_Y, y); 1018 + } 1019 + } 1020 + input_mt_sync_frame(ds->touchpad); 1021 + input_report_key(ds->touchpad, BTN_LEFT, ds_report->buttons[2] & DS_BUTTONS2_TOUCHPAD); 1022 + input_sync(ds->touchpad); 1023 + 1024 + battery_data = ds_report->status & DS_STATUS_BATTERY_CAPACITY; 1025 + charging_status = (ds_report->status & DS_STATUS_CHARGING) >> DS_STATUS_CHARGING_SHIFT; 1026 + 1027 + switch (charging_status) { 1028 + case 0x0: 1029 + /* 1030 + * Each unit of battery data corresponds to 10% 1031 + * 0 = 0-9%, 1 = 10-19%, .. and 10 = 100% 1032 + */ 1033 + battery_capacity = min(battery_data * 10 + 5, 100); 1034 + battery_status = POWER_SUPPLY_STATUS_DISCHARGING; 1035 + break; 1036 + case 0x1: 1037 + battery_capacity = min(battery_data * 10 + 5, 100); 1038 + battery_status = POWER_SUPPLY_STATUS_CHARGING; 1039 + break; 1040 + case 0x2: 1041 + battery_capacity = 100; 1042 + battery_status = POWER_SUPPLY_STATUS_FULL; 1043 + break; 1044 + case 0xa: /* voltage or temperature out of range */ 1045 + case 0xb: /* temperature error */ 1046 + battery_capacity = 0; 1047 + battery_status = POWER_SUPPLY_STATUS_NOT_CHARGING; 1048 + break; 1049 + case 0xf: /* charging error */ 1050 + default: 1051 + battery_capacity = 0; 1052 + battery_status = POWER_SUPPLY_STATUS_UNKNOWN; 1053 + } 1054 + 1055 + spin_lock_irqsave(&ps_dev->lock, flags); 1056 + ps_dev->battery_capacity = battery_capacity; 1057 + ps_dev->battery_status = battery_status; 1058 + spin_unlock_irqrestore(&ps_dev->lock, flags); 1059 + 1060 + return 0; 1061 + } 1062 + 1063 + static int dualsense_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect) 1064 + { 1065 + struct hid_device *hdev = input_get_drvdata(dev); 1066 + struct dualsense *ds = hid_get_drvdata(hdev); 1067 + unsigned long flags; 1068 + 1069 + if (effect->type != FF_RUMBLE) 1070 + return 0; 1071 + 1072 + spin_lock_irqsave(&ds->base.lock, flags); 1073 + ds->update_rumble = true; 1074 + ds->motor_left = effect->u.rumble.strong_magnitude / 256; 1075 + ds->motor_right = effect->u.rumble.weak_magnitude / 256; 1076 + spin_unlock_irqrestore(&ds->base.lock, flags); 1077 + 1078 + schedule_work(&ds->output_worker); 1079 + return 0; 1080 + } 1081 + 1082 + static int dualsense_reset_leds(struct dualsense *ds) 1083 + { 1084 + struct dualsense_output_report report; 1085 + uint8_t *buf; 1086 + 1087 + buf = kzalloc(sizeof(struct dualsense_output_report_bt), GFP_KERNEL); 1088 + if (!buf) 1089 + return -ENOMEM; 1090 + 1091 + dualsense_init_output_report(ds, &report, buf); 1092 + /* 1093 + * On Bluetooth the DualSense outputs an animation on the lightbar 1094 + * during startup and maintains a color afterwards. We need to explicitly 1095 + * reconfigure the lightbar before we can do any programming later on. 1096 + * In USB the lightbar is not on by default, but redoing the setup there 1097 + * doesn't hurt. 1098 + */ 1099 + report.common->valid_flag2 = DS_OUTPUT_VALID_FLAG2_LIGHTBAR_SETUP_CONTROL_ENABLE; 1100 + report.common->lightbar_setup = DS_OUTPUT_LIGHTBAR_SETUP_LIGHT_OUT; /* Fade light out. */ 1101 + dualsense_send_output_report(ds, &report); 1102 + 1103 + kfree(buf); 1104 + return 0; 1105 + } 1106 + 1107 + static void dualsense_set_lightbar(struct dualsense *ds, uint8_t red, uint8_t green, uint8_t blue) 1108 + { 1109 + ds->update_lightbar = true; 1110 + ds->lightbar_red = red; 1111 + ds->lightbar_green = green; 1112 + ds->lightbar_blue = blue; 1113 + 1114 + schedule_work(&ds->output_worker); 1115 + } 1116 + 1117 + static void dualsense_set_player_leds(struct dualsense *ds) 1118 + { 1119 + /* 1120 + * The DualSense controller has a row of 5 LEDs used for player ids. 1121 + * Behavior on the PlayStation 5 console is to center the player id 1122 + * across the LEDs, so e.g. player 1 would be "--x--" with x being 'on'. 1123 + * Follow a similar mapping here. 1124 + */ 1125 + static const int player_ids[5] = { 1126 + BIT(2), 1127 + BIT(3) | BIT(1), 1128 + BIT(4) | BIT(2) | BIT(0), 1129 + BIT(4) | BIT(3) | BIT(1) | BIT(0), 1130 + BIT(4) | BIT(3) | BIT(2) | BIT(1) | BIT(0) 1131 + }; 1132 + 1133 + uint8_t player_id = ds->base.player_id % ARRAY_SIZE(player_ids); 1134 + 1135 + ds->update_player_leds = true; 1136 + ds->player_leds_state = player_ids[player_id]; 1137 + schedule_work(&ds->output_worker); 1138 + } 1139 + 1140 + static struct ps_device *dualsense_create(struct hid_device *hdev) 1141 + { 1142 + struct dualsense *ds; 1143 + struct ps_device *ps_dev; 1144 + uint8_t max_output_report_size; 1145 + int ret; 1146 + 1147 + ds = devm_kzalloc(&hdev->dev, sizeof(*ds), GFP_KERNEL); 1148 + if (!ds) 1149 + return ERR_PTR(-ENOMEM); 1150 + 1151 + /* 1152 + * Patch version to allow userspace to distinguish between 1153 + * hid-generic vs hid-playstation axis and button mapping. 1154 + */ 1155 + hdev->version |= HID_PLAYSTATION_VERSION_PATCH; 1156 + 1157 + ps_dev = &ds->base; 1158 + ps_dev->hdev = hdev; 1159 + spin_lock_init(&ps_dev->lock); 1160 + ps_dev->battery_capacity = 100; /* initial value until parse_report. */ 1161 + ps_dev->battery_status = POWER_SUPPLY_STATUS_UNKNOWN; 1162 + ps_dev->parse_report = dualsense_parse_report; 1163 + INIT_WORK(&ds->output_worker, dualsense_output_worker); 1164 + hid_set_drvdata(hdev, ds); 1165 + 1166 + max_output_report_size = sizeof(struct dualsense_output_report_bt); 1167 + ds->output_report_dmabuf = devm_kzalloc(&hdev->dev, max_output_report_size, GFP_KERNEL); 1168 + if (!ds->output_report_dmabuf) 1169 + return ERR_PTR(-ENOMEM); 1170 + 1171 + ret = dualsense_get_mac_address(ds); 1172 + if (ret) { 1173 + hid_err(hdev, "Failed to get MAC address from DualSense\n"); 1174 + return ERR_PTR(ret); 1175 + } 1176 + snprintf(hdev->uniq, sizeof(hdev->uniq), "%pMR", ds->base.mac_address); 1177 + 1178 + ret = dualsense_get_firmware_info(ds); 1179 + if (ret) { 1180 + hid_err(hdev, "Failed to get firmware info from DualSense\n"); 1181 + return ERR_PTR(ret); 1182 + } 1183 + 1184 + ret = ps_devices_list_add(ps_dev); 1185 + if (ret) 1186 + return ERR_PTR(ret); 1187 + 1188 + ret = dualsense_get_calibration_data(ds); 1189 + if (ret) { 1190 + hid_err(hdev, "Failed to get calibration data from DualSense\n"); 1191 + goto err; 1192 + } 1193 + 1194 + ds->gamepad = ps_gamepad_create(hdev, dualsense_play_effect); 1195 + if (IS_ERR(ds->gamepad)) { 1196 + ret = PTR_ERR(ds->gamepad); 1197 + goto err; 1198 + } 1199 + 1200 + ds->sensors = ps_sensors_create(hdev, DS_ACC_RANGE, DS_ACC_RES_PER_G, 1201 + DS_GYRO_RANGE, DS_GYRO_RES_PER_DEG_S); 1202 + if (IS_ERR(ds->sensors)) { 1203 + ret = PTR_ERR(ds->sensors); 1204 + goto err; 1205 + } 1206 + 1207 + ds->touchpad = ps_touchpad_create(hdev, DS_TOUCHPAD_WIDTH, DS_TOUCHPAD_HEIGHT, 2); 1208 + if (IS_ERR(ds->touchpad)) { 1209 + ret = PTR_ERR(ds->touchpad); 1210 + goto err; 1211 + } 1212 + 1213 + ret = ps_device_register_battery(ps_dev); 1214 + if (ret) 1215 + goto err; 1216 + 1217 + /* 1218 + * The hardware may have control over the LEDs (e.g. in Bluetooth on startup). 1219 + * Reset the LEDs (lightbar, mute, player leds), so we can control them 1220 + * from software. 1221 + */ 1222 + ret = dualsense_reset_leds(ds); 1223 + if (ret) 1224 + goto err; 1225 + 1226 + dualsense_set_lightbar(ds, 0, 0, 128); /* blue */ 1227 + 1228 + ret = ps_device_set_player_id(ps_dev); 1229 + if (ret) { 1230 + hid_err(hdev, "Failed to assign player id for DualSense: %d\n", ret); 1231 + goto err; 1232 + } 1233 + 1234 + /* Set player LEDs to our player id. */ 1235 + dualsense_set_player_leds(ds); 1236 + 1237 + /* 1238 + * Reporting hardware and firmware is important as there are frequent updates, which 1239 + * can change behavior. 1240 + */ 1241 + hid_info(hdev, "Registered DualSense controller hw_version=0x%08x fw_version=0x%08x\n", 1242 + ds->base.hw_version, ds->base.fw_version); 1243 + 1244 + return &ds->base; 1245 + 1246 + err: 1247 + ps_devices_list_remove(ps_dev); 1248 + return ERR_PTR(ret); 1249 + } 1250 + 1251 + static int ps_raw_event(struct hid_device *hdev, struct hid_report *report, 1252 + u8 *data, int size) 1253 + { 1254 + struct ps_device *dev = hid_get_drvdata(hdev); 1255 + 1256 + if (dev && dev->parse_report) 1257 + return dev->parse_report(dev, report, data, size); 1258 + 1259 + return 0; 1260 + } 1261 + 1262 + static int ps_probe(struct hid_device *hdev, const struct hid_device_id *id) 1263 + { 1264 + struct ps_device *dev; 1265 + int ret; 1266 + 1267 + ret = hid_parse(hdev); 1268 + if (ret) { 1269 + hid_err(hdev, "Parse failed\n"); 1270 + return ret; 1271 + } 1272 + 1273 + ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW); 1274 + if (ret) { 1275 + hid_err(hdev, "Failed to start HID device\n"); 1276 + return ret; 1277 + } 1278 + 1279 + ret = hid_hw_open(hdev); 1280 + if (ret) { 1281 + hid_err(hdev, "Failed to open HID device\n"); 1282 + goto err_stop; 1283 + } 1284 + 1285 + if (hdev->product == USB_DEVICE_ID_SONY_PS5_CONTROLLER) { 1286 + dev = dualsense_create(hdev); 1287 + if (IS_ERR(dev)) { 1288 + hid_err(hdev, "Failed to create dualsense.\n"); 1289 + ret = PTR_ERR(dev); 1290 + goto err_close; 1291 + } 1292 + } 1293 + 1294 + ret = devm_device_add_group(&hdev->dev, &ps_device_attribute_group); 1295 + if (ret) { 1296 + hid_err(hdev, "Failed to register sysfs nodes.\n"); 1297 + goto err_close; 1298 + } 1299 + 1300 + return ret; 1301 + 1302 + err_close: 1303 + hid_hw_close(hdev); 1304 + err_stop: 1305 + hid_hw_stop(hdev); 1306 + return ret; 1307 + } 1308 + 1309 + static void ps_remove(struct hid_device *hdev) 1310 + { 1311 + struct ps_device *dev = hid_get_drvdata(hdev); 1312 + 1313 + ps_devices_list_remove(dev); 1314 + ps_device_release_player_id(dev); 1315 + 1316 + hid_hw_close(hdev); 1317 + hid_hw_stop(hdev); 1318 + } 1319 + 1320 + static const struct hid_device_id ps_devices[] = { 1321 + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER) }, 1322 + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER) }, 1323 + { } 1324 + }; 1325 + MODULE_DEVICE_TABLE(hid, ps_devices); 1326 + 1327 + static struct hid_driver ps_driver = { 1328 + .name = "playstation", 1329 + .id_table = ps_devices, 1330 + .probe = ps_probe, 1331 + .remove = ps_remove, 1332 + .raw_event = ps_raw_event, 1333 + }; 1334 + 1335 + static int __init ps_init(void) 1336 + { 1337 + return hid_register_driver(&ps_driver); 1338 + } 1339 + 1340 + static void __exit ps_exit(void) 1341 + { 1342 + hid_unregister_driver(&ps_driver); 1343 + ida_destroy(&ps_player_id_allocator); 1344 + } 1345 + 1346 + module_init(ps_init); 1347 + module_exit(ps_exit); 1348 + 1349 + MODULE_AUTHOR("Sony Interactive Entertainment"); 1350 + MODULE_DESCRIPTION("HID Driver for PlayStation peripherals."); 1351 + MODULE_LICENSE("GPL");
+14 -12
drivers/hid/hid-quirks.c
··· 180 180 { HID_USB_DEVICE(USB_VENDOR_ID_TOUCHPACK, USB_DEVICE_ID_TOUCHPACK_RTS), HID_QUIRK_MULTI_INPUT }, 181 181 { HID_USB_DEVICE(USB_VENDOR_ID_TPV, USB_DEVICE_ID_TPV_OPTICAL_TOUCHSCREEN_8882), HID_QUIRK_NOGET }, 182 182 { HID_USB_DEVICE(USB_VENDOR_ID_TPV, USB_DEVICE_ID_TPV_OPTICAL_TOUCHSCREEN_8883), HID_QUIRK_NOGET }, 183 - { HID_USB_DEVICE(USB_VENDOR_ID_TRUST, USB_DEVICE_ID_TRUST_PANORA_TABLET), HID_QUIRK_MULTI_INPUT | HID_QUIRK_HIDINPUT_FORCE }, 184 183 { HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD), HID_QUIRK_NOGET }, 185 184 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_KNA5), HID_QUIRK_MULTI_INPUT }, 186 185 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWA60), HID_QUIRK_MULTI_INPUT }, ··· 1028 1029 /* Runtime ("dynamic") quirks manipulation functions */ 1029 1030 1030 1031 /** 1031 - * hid_exists_dquirk: find any dynamic quirks for a HID device 1032 + * hid_exists_dquirk - find any dynamic quirks for a HID device 1032 1033 * @hdev: the HID device to match 1033 1034 * 1034 1035 * Description: ··· 1036 1037 * the pointer to the relevant struct hid_device_id if found. 1037 1038 * Must be called with a read lock held on dquirks_lock. 1038 1039 * 1039 - * Returns: NULL if no quirk found, struct hid_device_id * if found. 1040 + * Return: NULL if no quirk found, struct hid_device_id * if found. 1040 1041 */ 1041 1042 static struct hid_device_id *hid_exists_dquirk(const struct hid_device *hdev) 1042 1043 { ··· 1060 1061 1061 1062 1062 1063 /** 1063 - * hid_modify_dquirk: add/replace a HID quirk 1064 + * hid_modify_dquirk - add/replace a HID quirk 1064 1065 * @id: the HID device to match 1065 1066 * @quirks: the unsigned long quirks value to add/replace 1066 1067 * ··· 1069 1070 * quirks value with what was provided. Otherwise, add the quirk 1070 1071 * to the dynamic quirks list. 1071 1072 * 1072 - * Returns: 0 OK, -error on failure. 1073 + * Return: 0 OK, -error on failure. 1073 1074 */ 1074 1075 static int hid_modify_dquirk(const struct hid_device_id *id, 1075 1076 const unsigned long quirks) ··· 1121 1122 } 1122 1123 1123 1124 /** 1124 - * hid_remove_all_dquirks: remove all runtime HID quirks from memory 1125 + * hid_remove_all_dquirks - remove all runtime HID quirks from memory 1125 1126 * @bus: bus to match against. Use HID_BUS_ANY if all need to be removed. 1126 1127 * 1127 1128 * Description: ··· 1145 1146 } 1146 1147 1147 1148 /** 1148 - * hid_quirks_init: apply HID quirks specified at module load time 1149 + * hid_quirks_init - apply HID quirks specified at module load time 1150 + * @quirks_param: array of quirks strings (vendor:product:quirks) 1151 + * @bus: bus type 1152 + * @count: number of quirks to check 1149 1153 */ 1150 1154 int hid_quirks_init(char **quirks_param, __u16 bus, int count) 1151 1155 { ··· 1179 1177 EXPORT_SYMBOL_GPL(hid_quirks_init); 1180 1178 1181 1179 /** 1182 - * hid_quirks_exit: release memory associated with dynamic_quirks 1180 + * hid_quirks_exit - release memory associated with dynamic_quirks 1183 1181 * @bus: a bus to match against 1184 1182 * 1185 1183 * Description: ··· 1196 1194 EXPORT_SYMBOL_GPL(hid_quirks_exit); 1197 1195 1198 1196 /** 1199 - * hid_gets_squirk: return any static quirks for a HID device 1197 + * hid_gets_squirk - return any static quirks for a HID device 1200 1198 * @hdev: the HID device to match 1201 1199 * 1202 1200 * Description: 1203 1201 * Given a HID device, return a pointer to the quirked hid_device_id entry 1204 1202 * associated with that device. 1205 1203 * 1206 - * Returns: the quirks. 1204 + * Return: the quirks. 1207 1205 */ 1208 1206 static unsigned long hid_gets_squirk(const struct hid_device *hdev) 1209 1207 { ··· 1227 1225 } 1228 1226 1229 1227 /** 1230 - * hid_lookup_quirk: return any quirks associated with a HID device 1228 + * hid_lookup_quirk - return any quirks associated with a HID device 1231 1229 * @hdev: the HID device to look for 1232 1230 * 1233 1231 * Description: 1234 1232 * Given a HID device, return any quirks associated with that device. 1235 1233 * 1236 - * Returns: an unsigned long quirks value. 1234 + * Return: an unsigned long quirks value. 1237 1235 */ 1238 1236 unsigned long hid_lookup_quirk(const struct hid_device *hdev) 1239 1237 {
+3 -3
drivers/hid/hid-roccat-arvo.c
··· 42 42 if (retval) 43 43 return retval; 44 44 45 - return snprintf(buf, PAGE_SIZE, "%d\n", temp_buf.state); 45 + return sysfs_emit(buf, "%d\n", temp_buf.state); 46 46 } 47 47 48 48 static ssize_t arvo_sysfs_set_mode_key(struct device *dev, ··· 92 92 if (retval) 93 93 return retval; 94 94 95 - return snprintf(buf, PAGE_SIZE, "%d\n", temp_buf.key_mask); 95 + return sysfs_emit(buf, "%d\n", temp_buf.key_mask); 96 96 } 97 97 98 98 static ssize_t arvo_sysfs_set_key_mask(struct device *dev, ··· 146 146 struct arvo_device *arvo = 147 147 hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); 148 148 149 - return snprintf(buf, PAGE_SIZE, "%d\n", arvo->actual_profile); 149 + return sysfs_emit(buf, "%d\n", arvo->actual_profile); 150 150 } 151 151 152 152 static ssize_t arvo_sysfs_set_actual_profile(struct device *dev,
+14 -6
drivers/hid/hid-sony.c
··· 12 12 * Copyright (c) 2014-2016 Frank Praznik <frank.praznik@gmail.com> 13 13 * Copyright (c) 2018 Todd Kelner 14 14 * Copyright (c) 2020 Pascal Giard <pascal.giard@etsmtl.ca> 15 + * Copyright (c) 2020 Sanjay Govind <sanjay.govind9@gmail.com> 15 16 */ 16 17 17 18 /* ··· 60 59 #define NSG_MR5U_REMOTE_BT BIT(14) 61 60 #define NSG_MR7U_REMOTE_BT BIT(15) 62 61 #define SHANWAN_GAMEPAD BIT(16) 63 - #define GHL_GUITAR_PS3WIIU BIT(17) 62 + #define GH_GUITAR_CONTROLLER BIT(17) 63 + #define GHL_GUITAR_PS3WIIU BIT(18) 64 64 65 65 #define SIXAXIS_CONTROLLER (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT) 66 66 #define MOTION_CONTROLLER (MOTION_CONTROLLER_USB | MOTION_CONTROLLER_BT) ··· 86 84 #define NSG_MRXU_MAX_Y 1868 87 85 88 86 #define GHL_GUITAR_POKE_INTERVAL 10 /* In seconds */ 89 - #define GHL_GUITAR_TILT_USAGE 44 87 + #define GUITAR_TILT_USAGE 44 90 88 91 89 /* Magic value and data taken from GHLtarUtility: 92 90 * https://github.com/ghlre/GHLtarUtility/blob/master/PS3Guitar.cs ··· 694 692 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR) { 695 693 unsigned int abs = usage->hid & HID_USAGE; 696 694 697 - if (abs == GHL_GUITAR_TILT_USAGE) { 695 + if (abs == GUITAR_TILT_USAGE) { 698 696 hid_map_usage_clear(hi, usage, bit, max, EV_ABS, ABS_RY); 699 697 return 1; 700 698 } ··· 1483 1481 if (sc->quirks & DUALSHOCK4_CONTROLLER) 1484 1482 return ds4_mapping(hdev, hi, field, usage, bit, max); 1485 1483 1486 - if (sc->quirks & GHL_GUITAR_PS3WIIU) 1484 + if (sc->quirks & GH_GUITAR_CONTROLLER) 1487 1485 return guitar_mapping(hdev, hi, field, usage, bit, max); 1488 1486 1489 1487 /* Let hid-core decide for the others */ ··· 3169 3167 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_NSG_MR7U_REMOTE), 3170 3168 .driver_data = NSG_MR7U_REMOTE_BT }, 3171 3169 /* Guitar Hero Live PS3 and Wii U guitar dongles */ 3172 - { HID_USB_DEVICE(USB_VENDOR_ID_SONY_GHLIVE, USB_DEVICE_ID_SONY_PS3WIIU_GHLIVE_DONGLE), 3173 - .driver_data = GHL_GUITAR_PS3WIIU}, 3170 + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3WIIU_GHLIVE_DONGLE), 3171 + .driver_data = GHL_GUITAR_PS3WIIU | GH_GUITAR_CONTROLLER }, 3172 + /* Guitar Hero PC Guitar Dongle */ 3173 + { HID_USB_DEVICE(USB_VENDOR_ID_ACTIVISION, USB_DEVICE_ID_ACTIVISION_GUITAR_DONGLE), 3174 + .driver_data = GH_GUITAR_CONTROLLER }, 3175 + /* Guitar Hero PS3 World Tour Guitar Dongle */ 3176 + { HID_USB_DEVICE(USB_VENDOR_ID_SONY_RHYTHM, USB_DEVICE_ID_SONY_PS3_GUITAR_DONGLE), 3177 + .driver_data = GH_GUITAR_CONTROLLER }, 3174 3178 { } 3175 3179 }; 3176 3180 MODULE_DEVICE_TABLE(hid, sony_devices);
+2
drivers/hid/hid-uclogic-core.c
··· 371 371 USB_DEVICE_ID_HUION_TABLET) }, 372 372 { HID_USB_DEVICE(USB_VENDOR_ID_HUION, 373 373 USB_DEVICE_ID_HUION_HS64) }, 374 + { HID_USB_DEVICE(USB_VENDOR_ID_TRUST, 375 + USB_DEVICE_ID_TRUST_PANORA_TABLET) }, 374 376 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, 375 377 USB_DEVICE_ID_HUION_TABLET) }, 376 378 { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC,
+2
drivers/hid/hid-uclogic-params.c
··· 1045 1045 uclogic_params_init_with_pen_unused(&p); 1046 1046 } 1047 1047 break; 1048 + case VID_PID(USB_VENDOR_ID_TRUST, 1049 + USB_DEVICE_ID_TRUST_PANORA_TABLET): 1048 1050 case VID_PID(USB_VENDOR_ID_UGEE, 1049 1051 USB_DEVICE_ID_UGEE_TABLET_G5): 1050 1052 /* Ignore non-pen interfaces */
+42 -5
drivers/hid/i2c-hid/Kconfig
··· 2 2 menu "I2C HID support" 3 3 depends on I2C 4 4 5 - config I2C_HID 6 - tristate "HID over I2C transport layer" 5 + config I2C_HID_ACPI 6 + tristate "HID over I2C transport layer ACPI driver" 7 7 default n 8 - depends on I2C && INPUT 9 - select HID 8 + depends on I2C && INPUT && ACPI 10 9 help 11 10 Say Y here if you use a keyboard, a touchpad, a touchscreen, or any 12 11 other HID based devices which is connected to your computer via I2C. 12 + This driver supports ACPI-based systems. 13 13 14 14 If unsure, say N. 15 15 16 16 This support is also available as a module. If so, the module 17 - will be called i2c-hid. 17 + will be called i2c-hid-acpi. It will also build/depend on the 18 + module i2c-hid. 19 + 20 + config I2C_HID_OF 21 + tristate "HID over I2C transport layer Open Firmware driver" 22 + default n 23 + depends on I2C && INPUT && OF 24 + help 25 + Say Y here if you use a keyboard, a touchpad, a touchscreen, or any 26 + other HID based devices which is connected to your computer via I2C. 27 + This driver supports Open Firmware (Device Tree)-based systems. 28 + 29 + If unsure, say N. 30 + 31 + This support is also available as a module. If so, the module 32 + will be called i2c-hid-of. It will also build/depend on the 33 + module i2c-hid. 34 + 35 + config I2C_HID_OF_GOODIX 36 + tristate "Driver for Goodix hid-i2c based devices on OF systems" 37 + default n 38 + depends on I2C && INPUT && OF 39 + help 40 + Say Y here if you want support for Goodix i2c devices that use 41 + the i2c-hid protocol on Open Firmware (Device Tree)-based 42 + systems. 43 + 44 + If unsure, say N. 45 + 46 + This support is also available as a module. If so, the module 47 + will be called i2c-hid-of-goodix. It will also build/depend on 48 + the module i2c-hid. 18 49 19 50 endmenu 51 + 52 + config I2C_HID_CORE 53 + tristate 54 + default y if I2C_HID_ACPI=y || I2C_HID_OF=y || I2C_HID_OF_GOODIX=y 55 + default m if I2C_HID_ACPI=m || I2C_HID_OF=m || I2C_HID_OF_GOODIX=m 56 + select HID
+5 -1
drivers/hid/i2c-hid/Makefile
··· 3 3 # Makefile for the I2C input drivers 4 4 # 5 5 6 - obj-$(CONFIG_I2C_HID) += i2c-hid.o 6 + obj-$(CONFIG_I2C_HID_CORE) += i2c-hid.o 7 7 8 8 i2c-hid-objs = i2c-hid-core.o 9 9 i2c-hid-$(CONFIG_DMI) += i2c-hid-dmi-quirks.o 10 + 11 + obj-$(CONFIG_I2C_HID_ACPI) += i2c-hid-acpi.o 12 + obj-$(CONFIG_I2C_HID_OF) += i2c-hid-of.o 13 + obj-$(CONFIG_I2C_HID_OF_GOODIX) += i2c-hid-of-goodix.o
+143
drivers/hid/i2c-hid/i2c-hid-acpi.c
··· 1 + /* 2 + * HID over I2C ACPI Subclass 3 + * 4 + * Copyright (c) 2012 Benjamin Tissoires <benjamin.tissoires@gmail.com> 5 + * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France 6 + * Copyright (c) 2012 Red Hat, Inc 7 + * 8 + * This code was forked out of the core code, which was partly based on 9 + * "USB HID support for Linux": 10 + * 11 + * Copyright (c) 1999 Andreas Gal 12 + * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 13 + * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 14 + * Copyright (c) 2007-2008 Oliver Neukum 15 + * Copyright (c) 2006-2010 Jiri Kosina 16 + * 17 + * This file is subject to the terms and conditions of the GNU General Public 18 + * License. See the file COPYING in the main directory of this archive for 19 + * more details. 20 + */ 21 + 22 + #include <linux/acpi.h> 23 + #include <linux/device.h> 24 + #include <linux/i2c.h> 25 + #include <linux/kernel.h> 26 + #include <linux/module.h> 27 + #include <linux/pm.h> 28 + 29 + #include "i2c-hid.h" 30 + 31 + struct i2c_hid_acpi { 32 + struct i2chid_ops ops; 33 + struct i2c_client *client; 34 + }; 35 + 36 + static const struct acpi_device_id i2c_hid_acpi_blacklist[] = { 37 + /* 38 + * The CHPN0001 ACPI device, which is used to describe the Chipone 39 + * ICN8505 controller, has a _CID of PNP0C50 but is not HID compatible. 40 + */ 41 + {"CHPN0001", 0 }, 42 + { }, 43 + }; 44 + 45 + static int i2c_hid_acpi_get_descriptor(struct i2c_client *client) 46 + { 47 + static guid_t i2c_hid_guid = 48 + GUID_INIT(0x3CDFF6F7, 0x4267, 0x4555, 49 + 0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE); 50 + union acpi_object *obj; 51 + struct acpi_device *adev; 52 + acpi_handle handle; 53 + u16 hid_descriptor_address; 54 + 55 + handle = ACPI_HANDLE(&client->dev); 56 + if (!handle || acpi_bus_get_device(handle, &adev)) { 57 + dev_err(&client->dev, "Error could not get ACPI device\n"); 58 + return -ENODEV; 59 + } 60 + 61 + if (acpi_match_device_ids(adev, i2c_hid_acpi_blacklist) == 0) 62 + return -ENODEV; 63 + 64 + obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL, 65 + ACPI_TYPE_INTEGER); 66 + if (!obj) { 67 + dev_err(&client->dev, "Error _DSM call to get HID descriptor address failed\n"); 68 + return -ENODEV; 69 + } 70 + 71 + hid_descriptor_address = obj->integer.value; 72 + ACPI_FREE(obj); 73 + 74 + return hid_descriptor_address; 75 + } 76 + 77 + static void i2c_hid_acpi_shutdown_tail(struct i2chid_ops *ops) 78 + { 79 + struct i2c_hid_acpi *ihid_acpi = 80 + container_of(ops, struct i2c_hid_acpi, ops); 81 + struct device *dev = &ihid_acpi->client->dev; 82 + acpi_device_set_power(ACPI_COMPANION(dev), ACPI_STATE_D3_COLD); 83 + } 84 + 85 + static int i2c_hid_acpi_probe(struct i2c_client *client, 86 + const struct i2c_device_id *dev_id) 87 + { 88 + struct device *dev = &client->dev; 89 + struct i2c_hid_acpi *ihid_acpi; 90 + struct acpi_device *adev; 91 + u16 hid_descriptor_address; 92 + int ret; 93 + 94 + ihid_acpi = devm_kzalloc(&client->dev, sizeof(*ihid_acpi), GFP_KERNEL); 95 + if (!ihid_acpi) 96 + return -ENOMEM; 97 + 98 + ihid_acpi->client = client; 99 + ihid_acpi->ops.shutdown_tail = i2c_hid_acpi_shutdown_tail; 100 + 101 + ret = i2c_hid_acpi_get_descriptor(client); 102 + if (ret < 0) 103 + return ret; 104 + hid_descriptor_address = ret; 105 + 106 + adev = ACPI_COMPANION(dev); 107 + if (adev) 108 + acpi_device_fix_up_power(adev); 109 + 110 + if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0) { 111 + device_set_wakeup_capable(dev, true); 112 + device_set_wakeup_enable(dev, false); 113 + } 114 + 115 + return i2c_hid_core_probe(client, &ihid_acpi->ops, 116 + hid_descriptor_address); 117 + } 118 + 119 + static const struct acpi_device_id i2c_hid_acpi_match[] = { 120 + {"ACPI0C50", 0 }, 121 + {"PNP0C50", 0 }, 122 + { }, 123 + }; 124 + MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match); 125 + 126 + static struct i2c_driver i2c_hid_acpi_driver = { 127 + .driver = { 128 + .name = "i2c_hid_acpi", 129 + .pm = &i2c_hid_core_pm, 130 + .probe_type = PROBE_PREFER_ASYNCHRONOUS, 131 + .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match), 132 + }, 133 + 134 + .probe = i2c_hid_acpi_probe, 135 + .remove = i2c_hid_core_remove, 136 + .shutdown = i2c_hid_core_shutdown, 137 + }; 138 + 139 + module_i2c_driver(i2c_hid_acpi_driver); 140 + 141 + MODULE_DESCRIPTION("HID over I2C ACPI driver"); 142 + MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>"); 143 + MODULE_LICENSE("GPL");
+42 -214
drivers/hid/i2c-hid/i2c-hid-core.c
··· 35 35 #include <linux/kernel.h> 36 36 #include <linux/hid.h> 37 37 #include <linux/mutex.h> 38 - #include <linux/acpi.h> 39 - #include <linux/of.h> 40 - #include <linux/regulator/consumer.h> 41 - 42 - #include <linux/platform_data/i2c-hid.h> 43 38 44 39 #include "../hid-ids.h" 45 40 #include "i2c-hid.h" ··· 151 156 152 157 wait_queue_head_t wait; /* For waiting the interrupt */ 153 158 154 - struct i2c_hid_platform_data pdata; 155 - 156 159 bool irq_wake_enabled; 157 160 struct mutex reset_lock; 161 + 162 + struct i2chid_ops *ops; 158 163 }; 159 164 160 165 static const struct i2c_hid_quirks { ··· 165 170 { USB_VENDOR_ID_WEIDA, HID_ANY_ID, 166 171 I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV }, 167 172 { I2C_VENDOR_ID_HANTICK, I2C_PRODUCT_ID_HANTICK_5288, 173 + I2C_HID_QUIRK_NO_IRQ_AFTER_RESET }, 174 + { I2C_VENDOR_ID_ITE, I2C_DEVICE_ID_ITE_VOYO_WINPAD_A15, 168 175 I2C_HID_QUIRK_NO_IRQ_AFTER_RESET }, 169 176 { I2C_VENDOR_ID_RAYDIUM, I2C_PRODUCT_ID_RAYDIUM_3118, 170 177 I2C_HID_QUIRK_NO_IRQ_AFTER_RESET }, ··· 881 884 return 0; 882 885 } 883 886 884 - #ifdef CONFIG_ACPI 885 - static const struct acpi_device_id i2c_hid_acpi_blacklist[] = { 886 - /* 887 - * The CHPN0001 ACPI device, which is used to describe the Chipone 888 - * ICN8505 controller, has a _CID of PNP0C50 but is not HID compatible. 889 - */ 890 - {"CHPN0001", 0 }, 891 - { }, 892 - }; 893 - 894 - static int i2c_hid_acpi_pdata(struct i2c_client *client, 895 - struct i2c_hid_platform_data *pdata) 887 + static int i2c_hid_core_power_up(struct i2c_hid *ihid) 896 888 { 897 - static guid_t i2c_hid_guid = 898 - GUID_INIT(0x3CDFF6F7, 0x4267, 0x4555, 899 - 0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE); 900 - union acpi_object *obj; 901 - struct acpi_device *adev; 902 - acpi_handle handle; 889 + if (!ihid->ops->power_up) 890 + return 0; 903 891 904 - handle = ACPI_HANDLE(&client->dev); 905 - if (!handle || acpi_bus_get_device(handle, &adev)) { 906 - dev_err(&client->dev, "Error could not get ACPI device\n"); 907 - return -ENODEV; 908 - } 909 - 910 - if (acpi_match_device_ids(adev, i2c_hid_acpi_blacklist) == 0) 911 - return -ENODEV; 912 - 913 - obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL, 914 - ACPI_TYPE_INTEGER); 915 - if (!obj) { 916 - dev_err(&client->dev, "Error _DSM call to get HID descriptor address failed\n"); 917 - return -ENODEV; 918 - } 919 - 920 - pdata->hid_descriptor_address = obj->integer.value; 921 - ACPI_FREE(obj); 922 - 923 - return 0; 892 + return ihid->ops->power_up(ihid->ops); 924 893 } 925 894 926 - static void i2c_hid_acpi_fix_up_power(struct device *dev) 895 + static void i2c_hid_core_power_down(struct i2c_hid *ihid) 927 896 { 928 - struct acpi_device *adev; 897 + if (!ihid->ops->power_down) 898 + return; 929 899 930 - adev = ACPI_COMPANION(dev); 931 - if (adev) 932 - acpi_device_fix_up_power(adev); 900 + ihid->ops->power_down(ihid->ops); 933 901 } 934 902 935 - static void i2c_hid_acpi_enable_wakeup(struct device *dev) 903 + static void i2c_hid_core_shutdown_tail(struct i2c_hid *ihid) 936 904 { 937 - if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0) { 938 - device_set_wakeup_capable(dev, true); 939 - device_set_wakeup_enable(dev, false); 940 - } 905 + if (!ihid->ops->shutdown_tail) 906 + return; 907 + 908 + ihid->ops->shutdown_tail(ihid->ops); 941 909 } 942 910 943 - static void i2c_hid_acpi_shutdown(struct device *dev) 944 - { 945 - acpi_device_set_power(ACPI_COMPANION(dev), ACPI_STATE_D3_COLD); 946 - } 947 - 948 - static const struct acpi_device_id i2c_hid_acpi_match[] = { 949 - {"ACPI0C50", 0 }, 950 - {"PNP0C50", 0 }, 951 - { }, 952 - }; 953 - MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match); 954 - #else 955 - static inline int i2c_hid_acpi_pdata(struct i2c_client *client, 956 - struct i2c_hid_platform_data *pdata) 957 - { 958 - return -ENODEV; 959 - } 960 - 961 - static inline void i2c_hid_acpi_fix_up_power(struct device *dev) {} 962 - 963 - static inline void i2c_hid_acpi_enable_wakeup(struct device *dev) {} 964 - 965 - static inline void i2c_hid_acpi_shutdown(struct device *dev) {} 966 - #endif 967 - 968 - #ifdef CONFIG_OF 969 - static int i2c_hid_of_probe(struct i2c_client *client, 970 - struct i2c_hid_platform_data *pdata) 971 - { 972 - struct device *dev = &client->dev; 973 - u32 val; 974 - int ret; 975 - 976 - ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val); 977 - if (ret) { 978 - dev_err(&client->dev, "HID register address not provided\n"); 979 - return -ENODEV; 980 - } 981 - if (val >> 16) { 982 - dev_err(&client->dev, "Bad HID register address: 0x%08x\n", 983 - val); 984 - return -EINVAL; 985 - } 986 - pdata->hid_descriptor_address = val; 987 - 988 - return 0; 989 - } 990 - 991 - static const struct of_device_id i2c_hid_of_match[] = { 992 - { .compatible = "hid-over-i2c" }, 993 - {}, 994 - }; 995 - MODULE_DEVICE_TABLE(of, i2c_hid_of_match); 996 - #else 997 - static inline int i2c_hid_of_probe(struct i2c_client *client, 998 - struct i2c_hid_platform_data *pdata) 999 - { 1000 - return -ENODEV; 1001 - } 1002 - #endif 1003 - 1004 - static void i2c_hid_fwnode_probe(struct i2c_client *client, 1005 - struct i2c_hid_platform_data *pdata) 1006 - { 1007 - u32 val; 1008 - 1009 - if (!device_property_read_u32(&client->dev, "post-power-on-delay-ms", 1010 - &val)) 1011 - pdata->post_power_delay_ms = val; 1012 - } 1013 - 1014 - static int i2c_hid_probe(struct i2c_client *client, 1015 - const struct i2c_device_id *dev_id) 911 + int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops, 912 + u16 hid_descriptor_address) 1016 913 { 1017 914 int ret; 1018 915 struct i2c_hid *ihid; 1019 916 struct hid_device *hid; 1020 - __u16 hidRegister; 1021 - struct i2c_hid_platform_data *platform_data = client->dev.platform_data; 1022 917 1023 918 dbg_hid("HID probe called for i2c 0x%02x\n", client->addr); 1024 919 ··· 931 1042 if (!ihid) 932 1043 return -ENOMEM; 933 1044 934 - if (client->dev.of_node) { 935 - ret = i2c_hid_of_probe(client, &ihid->pdata); 936 - if (ret) 937 - return ret; 938 - } else if (!platform_data) { 939 - ret = i2c_hid_acpi_pdata(client, &ihid->pdata); 940 - if (ret) 941 - return ret; 942 - } else { 943 - ihid->pdata = *platform_data; 944 - } 1045 + ihid->ops = ops; 945 1046 946 - /* Parse platform agnostic common properties from ACPI / device tree */ 947 - i2c_hid_fwnode_probe(client, &ihid->pdata); 948 - 949 - ihid->pdata.supplies[0].supply = "vdd"; 950 - ihid->pdata.supplies[1].supply = "vddl"; 951 - 952 - ret = devm_regulator_bulk_get(&client->dev, 953 - ARRAY_SIZE(ihid->pdata.supplies), 954 - ihid->pdata.supplies); 1047 + ret = i2c_hid_core_power_up(ihid); 955 1048 if (ret) 956 1049 return ret; 957 - 958 - ret = regulator_bulk_enable(ARRAY_SIZE(ihid->pdata.supplies), 959 - ihid->pdata.supplies); 960 - if (ret < 0) 961 - return ret; 962 - 963 - if (ihid->pdata.post_power_delay_ms) 964 - msleep(ihid->pdata.post_power_delay_ms); 965 1050 966 1051 i2c_set_clientdata(client, ihid); 967 1052 968 1053 ihid->client = client; 969 1054 970 - hidRegister = ihid->pdata.hid_descriptor_address; 971 - ihid->wHIDDescRegister = cpu_to_le16(hidRegister); 1055 + ihid->wHIDDescRegister = cpu_to_le16(hid_descriptor_address); 972 1056 973 1057 init_waitqueue_head(&ihid->wait); 974 1058 mutex_init(&ihid->reset_lock); ··· 951 1089 * real computation later. */ 952 1090 ret = i2c_hid_alloc_buffers(ihid, HID_MIN_BUFFER_SIZE); 953 1091 if (ret < 0) 954 - goto err_regulator; 955 - 956 - i2c_hid_acpi_fix_up_power(&client->dev); 957 - 958 - i2c_hid_acpi_enable_wakeup(&client->dev); 1092 + goto err_powered; 959 1093 960 1094 device_enable_async_suspend(&client->dev); 961 1095 ··· 960 1102 if (ret < 0) { 961 1103 dev_dbg(&client->dev, "nothing at this address: %d\n", ret); 962 1104 ret = -ENXIO; 963 - goto err_regulator; 1105 + goto err_powered; 964 1106 } 965 1107 966 1108 ret = i2c_hid_fetch_hid_descriptor(ihid); 967 1109 if (ret < 0) { 968 1110 dev_err(&client->dev, 969 1111 "Failed to fetch the HID Descriptor\n"); 970 - goto err_regulator; 1112 + goto err_powered; 971 1113 } 972 1114 973 1115 ret = i2c_hid_init_irq(client); 974 1116 if (ret < 0) 975 - goto err_regulator; 1117 + goto err_powered; 976 1118 977 1119 hid = hid_allocate_device(); 978 1120 if (IS_ERR(hid)) { ··· 1011 1153 err_irq: 1012 1154 free_irq(client->irq, ihid); 1013 1155 1014 - err_regulator: 1015 - regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies), 1016 - ihid->pdata.supplies); 1156 + err_powered: 1157 + i2c_hid_core_power_down(ihid); 1017 1158 i2c_hid_free_buffers(ihid); 1018 1159 return ret; 1019 1160 } 1161 + EXPORT_SYMBOL_GPL(i2c_hid_core_probe); 1020 1162 1021 - static int i2c_hid_remove(struct i2c_client *client) 1163 + int i2c_hid_core_remove(struct i2c_client *client) 1022 1164 { 1023 1165 struct i2c_hid *ihid = i2c_get_clientdata(client); 1024 1166 struct hid_device *hid; ··· 1031 1173 if (ihid->bufsize) 1032 1174 i2c_hid_free_buffers(ihid); 1033 1175 1034 - regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies), 1035 - ihid->pdata.supplies); 1176 + i2c_hid_core_power_down(ihid); 1036 1177 1037 1178 return 0; 1038 1179 } 1180 + EXPORT_SYMBOL_GPL(i2c_hid_core_remove); 1039 1181 1040 - static void i2c_hid_shutdown(struct i2c_client *client) 1182 + void i2c_hid_core_shutdown(struct i2c_client *client) 1041 1183 { 1042 1184 struct i2c_hid *ihid = i2c_get_clientdata(client); 1043 1185 1044 1186 i2c_hid_set_power(client, I2C_HID_PWR_SLEEP); 1045 1187 free_irq(client->irq, ihid); 1046 1188 1047 - i2c_hid_acpi_shutdown(&client->dev); 1189 + i2c_hid_core_shutdown_tail(ihid); 1048 1190 } 1191 + EXPORT_SYMBOL_GPL(i2c_hid_core_shutdown); 1049 1192 1050 1193 #ifdef CONFIG_PM_SLEEP 1051 - static int i2c_hid_suspend(struct device *dev) 1194 + static int i2c_hid_core_suspend(struct device *dev) 1052 1195 { 1053 1196 struct i2c_client *client = to_i2c_client(dev); 1054 1197 struct i2c_hid *ihid = i2c_get_clientdata(client); ··· 1076 1217 hid_warn(hid, "Failed to enable irq wake: %d\n", 1077 1218 wake_status); 1078 1219 } else { 1079 - regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies), 1080 - ihid->pdata.supplies); 1220 + i2c_hid_core_power_down(ihid); 1081 1221 } 1082 1222 1083 1223 return 0; 1084 1224 } 1085 1225 1086 - static int i2c_hid_resume(struct device *dev) 1226 + static int i2c_hid_core_resume(struct device *dev) 1087 1227 { 1088 1228 int ret; 1089 1229 struct i2c_client *client = to_i2c_client(dev); ··· 1091 1233 int wake_status; 1092 1234 1093 1235 if (!device_may_wakeup(&client->dev)) { 1094 - ret = regulator_bulk_enable(ARRAY_SIZE(ihid->pdata.supplies), 1095 - ihid->pdata.supplies); 1096 - if (ret) 1097 - hid_warn(hid, "Failed to enable supplies: %d\n", ret); 1098 - 1099 - if (ihid->pdata.post_power_delay_ms) 1100 - msleep(ihid->pdata.post_power_delay_ms); 1236 + i2c_hid_core_power_up(ihid); 1101 1237 } else if (ihid->irq_wake_enabled) { 1102 1238 wake_status = disable_irq_wake(client->irq); 1103 1239 if (!wake_status) ··· 1128 1276 } 1129 1277 #endif 1130 1278 1131 - static const struct dev_pm_ops i2c_hid_pm = { 1132 - SET_SYSTEM_SLEEP_PM_OPS(i2c_hid_suspend, i2c_hid_resume) 1279 + const struct dev_pm_ops i2c_hid_core_pm = { 1280 + SET_SYSTEM_SLEEP_PM_OPS(i2c_hid_core_suspend, i2c_hid_core_resume) 1133 1281 }; 1134 - 1135 - static const struct i2c_device_id i2c_hid_id_table[] = { 1136 - { "hid", 0 }, 1137 - { "hid-over-i2c", 0 }, 1138 - { }, 1139 - }; 1140 - MODULE_DEVICE_TABLE(i2c, i2c_hid_id_table); 1141 - 1142 - 1143 - static struct i2c_driver i2c_hid_driver = { 1144 - .driver = { 1145 - .name = "i2c_hid", 1146 - .pm = &i2c_hid_pm, 1147 - .probe_type = PROBE_PREFER_ASYNCHRONOUS, 1148 - .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match), 1149 - .of_match_table = of_match_ptr(i2c_hid_of_match), 1150 - }, 1151 - 1152 - .probe = i2c_hid_probe, 1153 - .remove = i2c_hid_remove, 1154 - .shutdown = i2c_hid_shutdown, 1155 - .id_table = i2c_hid_id_table, 1156 - }; 1157 - 1158 - module_i2c_driver(i2c_hid_driver); 1282 + EXPORT_SYMBOL_GPL(i2c_hid_core_pm); 1159 1283 1160 1284 MODULE_DESCRIPTION("HID over I2C core driver"); 1161 1285 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
+116
drivers/hid/i2c-hid/i2c-hid-of-goodix.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Driver for Goodix touchscreens that use the i2c-hid protocol. 4 + * 5 + * Copyright 2020 Google LLC 6 + */ 7 + 8 + #include <linux/delay.h> 9 + #include <linux/device.h> 10 + #include <linux/gpio/consumer.h> 11 + #include <linux/i2c.h> 12 + #include <linux/kernel.h> 13 + #include <linux/module.h> 14 + #include <linux/of.h> 15 + #include <linux/pm.h> 16 + #include <linux/regulator/consumer.h> 17 + 18 + #include "i2c-hid.h" 19 + 20 + struct goodix_i2c_hid_timing_data { 21 + unsigned int post_gpio_reset_delay_ms; 22 + unsigned int post_power_delay_ms; 23 + }; 24 + 25 + struct i2c_hid_of_goodix { 26 + struct i2chid_ops ops; 27 + 28 + struct regulator *vdd; 29 + struct gpio_desc *reset_gpio; 30 + const struct goodix_i2c_hid_timing_data *timings; 31 + }; 32 + 33 + static int goodix_i2c_hid_power_up(struct i2chid_ops *ops) 34 + { 35 + struct i2c_hid_of_goodix *ihid_goodix = 36 + container_of(ops, struct i2c_hid_of_goodix, ops); 37 + int ret; 38 + 39 + ret = regulator_enable(ihid_goodix->vdd); 40 + if (ret) 41 + return ret; 42 + 43 + if (ihid_goodix->timings->post_power_delay_ms) 44 + msleep(ihid_goodix->timings->post_power_delay_ms); 45 + 46 + gpiod_set_value_cansleep(ihid_goodix->reset_gpio, 0); 47 + if (ihid_goodix->timings->post_gpio_reset_delay_ms) 48 + msleep(ihid_goodix->timings->post_gpio_reset_delay_ms); 49 + 50 + return 0; 51 + } 52 + 53 + static void goodix_i2c_hid_power_down(struct i2chid_ops *ops) 54 + { 55 + struct i2c_hid_of_goodix *ihid_goodix = 56 + container_of(ops, struct i2c_hid_of_goodix, ops); 57 + 58 + gpiod_set_value_cansleep(ihid_goodix->reset_gpio, 1); 59 + regulator_disable(ihid_goodix->vdd); 60 + } 61 + 62 + static int i2c_hid_of_goodix_probe(struct i2c_client *client, 63 + const struct i2c_device_id *id) 64 + { 65 + struct i2c_hid_of_goodix *ihid_goodix; 66 + 67 + ihid_goodix = devm_kzalloc(&client->dev, sizeof(*ihid_goodix), 68 + GFP_KERNEL); 69 + if (!ihid_goodix) 70 + return -ENOMEM; 71 + 72 + ihid_goodix->ops.power_up = goodix_i2c_hid_power_up; 73 + ihid_goodix->ops.power_down = goodix_i2c_hid_power_down; 74 + 75 + /* Start out with reset asserted */ 76 + ihid_goodix->reset_gpio = 77 + devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH); 78 + if (IS_ERR(ihid_goodix->reset_gpio)) 79 + return PTR_ERR(ihid_goodix->reset_gpio); 80 + 81 + ihid_goodix->vdd = devm_regulator_get(&client->dev, "vdd"); 82 + if (IS_ERR(ihid_goodix->vdd)) 83 + return PTR_ERR(ihid_goodix->vdd); 84 + 85 + ihid_goodix->timings = device_get_match_data(&client->dev); 86 + 87 + return i2c_hid_core_probe(client, &ihid_goodix->ops, 0x0001); 88 + } 89 + 90 + static const struct goodix_i2c_hid_timing_data goodix_gt7375p_timing_data = { 91 + .post_power_delay_ms = 10, 92 + .post_gpio_reset_delay_ms = 180, 93 + }; 94 + 95 + static const struct of_device_id goodix_i2c_hid_of_match[] = { 96 + { .compatible = "goodix,gt7375p", .data = &goodix_gt7375p_timing_data }, 97 + { } 98 + }; 99 + MODULE_DEVICE_TABLE(of, goodix_i2c_hid_of_match); 100 + 101 + static struct i2c_driver goodix_i2c_hid_ts_driver = { 102 + .driver = { 103 + .name = "i2c_hid_of_goodix", 104 + .pm = &i2c_hid_core_pm, 105 + .probe_type = PROBE_PREFER_ASYNCHRONOUS, 106 + .of_match_table = of_match_ptr(goodix_i2c_hid_of_match), 107 + }, 108 + .probe = i2c_hid_of_goodix_probe, 109 + .remove = i2c_hid_core_remove, 110 + .shutdown = i2c_hid_core_shutdown, 111 + }; 112 + module_i2c_driver(goodix_i2c_hid_ts_driver); 113 + 114 + MODULE_AUTHOR("Douglas Anderson <dianders@chromium.org>"); 115 + MODULE_DESCRIPTION("Goodix i2c-hid touchscreen driver"); 116 + MODULE_LICENSE("GPL v2");
+143
drivers/hid/i2c-hid/i2c-hid-of.c
··· 1 + /* 2 + * HID over I2C Open Firmware Subclass 3 + * 4 + * Copyright (c) 2012 Benjamin Tissoires <benjamin.tissoires@gmail.com> 5 + * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France 6 + * Copyright (c) 2012 Red Hat, Inc 7 + * 8 + * This code was forked out of the core code, which was partly based on 9 + * "USB HID support for Linux": 10 + * 11 + * Copyright (c) 1999 Andreas Gal 12 + * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 13 + * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 14 + * Copyright (c) 2007-2008 Oliver Neukum 15 + * Copyright (c) 2006-2010 Jiri Kosina 16 + * 17 + * This file is subject to the terms and conditions of the GNU General Public 18 + * License. See the file COPYING in the main directory of this archive for 19 + * more details. 20 + */ 21 + 22 + #include <linux/delay.h> 23 + #include <linux/device.h> 24 + #include <linux/i2c.h> 25 + #include <linux/kernel.h> 26 + #include <linux/module.h> 27 + #include <linux/of.h> 28 + #include <linux/pm.h> 29 + #include <linux/regulator/consumer.h> 30 + 31 + #include "i2c-hid.h" 32 + 33 + struct i2c_hid_of { 34 + struct i2chid_ops ops; 35 + 36 + struct i2c_client *client; 37 + struct regulator_bulk_data supplies[2]; 38 + int post_power_delay_ms; 39 + }; 40 + 41 + static int i2c_hid_of_power_up(struct i2chid_ops *ops) 42 + { 43 + struct i2c_hid_of *ihid_of = container_of(ops, struct i2c_hid_of, ops); 44 + struct device *dev = &ihid_of->client->dev; 45 + int ret; 46 + 47 + ret = regulator_bulk_enable(ARRAY_SIZE(ihid_of->supplies), 48 + ihid_of->supplies); 49 + if (ret) { 50 + dev_warn(dev, "Failed to enable supplies: %d\n", ret); 51 + return ret; 52 + } 53 + 54 + if (ihid_of->post_power_delay_ms) 55 + msleep(ihid_of->post_power_delay_ms); 56 + 57 + return 0; 58 + } 59 + 60 + static void i2c_hid_of_power_down(struct i2chid_ops *ops) 61 + { 62 + struct i2c_hid_of *ihid_of = container_of(ops, struct i2c_hid_of, ops); 63 + 64 + regulator_bulk_disable(ARRAY_SIZE(ihid_of->supplies), 65 + ihid_of->supplies); 66 + } 67 + 68 + static int i2c_hid_of_probe(struct i2c_client *client, 69 + const struct i2c_device_id *dev_id) 70 + { 71 + struct device *dev = &client->dev; 72 + struct i2c_hid_of *ihid_of; 73 + u16 hid_descriptor_address; 74 + int ret; 75 + u32 val; 76 + 77 + ihid_of = devm_kzalloc(&client->dev, sizeof(*ihid_of), GFP_KERNEL); 78 + if (!ihid_of) 79 + return -ENOMEM; 80 + 81 + ihid_of->ops.power_up = i2c_hid_of_power_up; 82 + ihid_of->ops.power_down = i2c_hid_of_power_down; 83 + 84 + ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val); 85 + if (ret) { 86 + dev_err(&client->dev, "HID register address not provided\n"); 87 + return -ENODEV; 88 + } 89 + if (val >> 16) { 90 + dev_err(&client->dev, "Bad HID register address: 0x%08x\n", 91 + val); 92 + return -EINVAL; 93 + } 94 + hid_descriptor_address = val; 95 + 96 + if (!device_property_read_u32(&client->dev, "post-power-on-delay-ms", 97 + &val)) 98 + ihid_of->post_power_delay_ms = val; 99 + 100 + ihid_of->supplies[0].supply = "vdd"; 101 + ihid_of->supplies[1].supply = "vddl"; 102 + ret = devm_regulator_bulk_get(&client->dev, 103 + ARRAY_SIZE(ihid_of->supplies), 104 + ihid_of->supplies); 105 + if (ret) 106 + return ret; 107 + 108 + return i2c_hid_core_probe(client, &ihid_of->ops, 109 + hid_descriptor_address); 110 + } 111 + 112 + static const struct of_device_id i2c_hid_of_match[] = { 113 + { .compatible = "hid-over-i2c" }, 114 + {}, 115 + }; 116 + MODULE_DEVICE_TABLE(of, i2c_hid_of_match); 117 + 118 + static const struct i2c_device_id i2c_hid_of_id_table[] = { 119 + { "hid", 0 }, 120 + { "hid-over-i2c", 0 }, 121 + { }, 122 + }; 123 + MODULE_DEVICE_TABLE(i2c, i2c_hid_of_id_table); 124 + 125 + static struct i2c_driver i2c_hid_of_driver = { 126 + .driver = { 127 + .name = "i2c_hid_of", 128 + .pm = &i2c_hid_core_pm, 129 + .probe_type = PROBE_PREFER_ASYNCHRONOUS, 130 + .of_match_table = of_match_ptr(i2c_hid_of_match), 131 + }, 132 + 133 + .probe = i2c_hid_of_probe, 134 + .remove = i2c_hid_core_remove, 135 + .shutdown = i2c_hid_core_shutdown, 136 + .id_table = i2c_hid_of_id_table, 137 + }; 138 + 139 + module_i2c_driver(i2c_hid_of_driver); 140 + 141 + MODULE_DESCRIPTION("HID over I2C OF driver"); 142 + MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>"); 143 + MODULE_LICENSE("GPL");
+22
drivers/hid/i2c-hid/i2c-hid.h
··· 3 3 #ifndef I2C_HID_H 4 4 #define I2C_HID_H 5 5 6 + #include <linux/i2c.h> 6 7 7 8 #ifdef CONFIG_DMI 8 9 struct i2c_hid_desc *i2c_hid_get_dmi_i2c_hid_desc_override(uint8_t *i2c_name); ··· 17 16 unsigned int *size) 18 17 { return NULL; } 19 18 #endif 19 + 20 + /** 21 + * struct i2chid_ops - Ops provided to the core. 22 + * 23 + * @power_up: do sequencing to power up the device. 24 + * @power_down: do sequencing to power down the device. 25 + * @shutdown_tail: called at the end of shutdown. 26 + */ 27 + struct i2chid_ops { 28 + int (*power_up)(struct i2chid_ops *ops); 29 + void (*power_down)(struct i2chid_ops *ops); 30 + void (*shutdown_tail)(struct i2chid_ops *ops); 31 + }; 32 + 33 + int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops, 34 + u16 hid_descriptor_address); 35 + int i2c_hid_core_remove(struct i2c_client *client); 36 + 37 + void i2c_hid_core_shutdown(struct i2c_client *client); 38 + 39 + extern const struct dev_pm_ops i2c_hid_core_pm; 20 40 21 41 #endif
+2
drivers/hid/intel-ish-hid/ipc/hw-ish.h
··· 27 27 #define CMP_H_DEVICE_ID 0x06FC 28 28 #define EHL_Ax_DEVICE_ID 0x4BB3 29 29 #define TGL_LP_DEVICE_ID 0xA0FC 30 + #define TGL_H_DEVICE_ID 0x43FC 30 31 31 32 #define REVISION_ID_CHT_A0 0x6 32 33 #define REVISION_ID_CHT_Ax_SI 0x0 ··· 82 81 int ish_hw_start(struct ishtp_device *dev); 83 82 void ish_device_disable(struct ishtp_device *dev); 84 83 int ish_disable_dma(struct ishtp_device *dev); 84 + void ish_set_host_ready(struct ishtp_device *dev); 85 85 86 86 #endif /* _ISHTP_HW_ISH_H_ */
+27
drivers/hid/intel-ish-hid/ipc/ipc.c
··· 193 193 ish_reg_write(dev, IPC_REG_HOST_COMM, host_status); 194 194 } 195 195 196 + static bool ish_chk_host_rdy(struct ishtp_device *dev) 197 + { 198 + uint32_t host_status = ish_reg_read(dev, IPC_REG_HOST_COMM); 199 + 200 + return (host_status & IPC_HOSTCOMM_READY_BIT); 201 + } 202 + 203 + /** 204 + * ish_set_host_ready() - reconfig ipc host registers 205 + * @dev: ishtp device pointer 206 + * 207 + * Set host to ready state 208 + * This API is called in some case: 209 + * fw is still on, but ipc is powered down. 210 + * such as OOB case. 211 + * 212 + * Return: 0 for success else error fault code 213 + */ 214 + void ish_set_host_ready(struct ishtp_device *dev) 215 + { 216 + if (ish_chk_host_rdy(dev)) 217 + return; 218 + 219 + ish_set_host_rdy(dev); 220 + set_host_ready(dev); 221 + } 222 + 196 223 /** 197 224 * _ishtp_read_hdr() - Read message header 198 225 * @dev: ISHTP device pointer
+54 -1
drivers/hid/intel-ish-hid/ipc/pci-ish.c
··· 5 5 * Copyright (c) 2014-2016, Intel Corporation. 6 6 */ 7 7 8 + #include <linux/acpi.h> 8 9 #include <linux/module.h> 9 10 #include <linux/moduleparam.h> 10 11 #include <linux/kernel.h> ··· 38 37 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, CMP_H_DEVICE_ID)}, 39 38 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, EHL_Ax_DEVICE_ID)}, 40 39 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, TGL_LP_DEVICE_ID)}, 40 + {PCI_DEVICE(PCI_VENDOR_ID_INTEL, TGL_H_DEVICE_ID)}, 41 41 {0, } 42 42 }; 43 43 MODULE_DEVICE_TABLE(pci, ish_pci_tbl); ··· 113 111 return !pm_resume_via_firmware() || pdev->device == CHV_DEVICE_ID; 114 112 } 115 113 114 + static int enable_gpe(struct device *dev) 115 + { 116 + #ifdef CONFIG_ACPI 117 + acpi_status acpi_sts; 118 + struct acpi_device *adev; 119 + struct acpi_device_wakeup *wakeup; 120 + 121 + adev = ACPI_COMPANION(dev); 122 + if (!adev) { 123 + dev_err(dev, "get acpi handle failed\n"); 124 + return -ENODEV; 125 + } 126 + wakeup = &adev->wakeup; 127 + 128 + acpi_sts = acpi_enable_gpe(wakeup->gpe_device, wakeup->gpe_number); 129 + if (ACPI_FAILURE(acpi_sts)) { 130 + dev_err(dev, "enable ose_gpe failed\n"); 131 + return -EIO; 132 + } 133 + 134 + return 0; 135 + #else 136 + return -ENODEV; 137 + #endif 138 + } 139 + 140 + static void enable_pme_wake(struct pci_dev *pdev) 141 + { 142 + if ((pci_pme_capable(pdev, PCI_D0) || 143 + pci_pme_capable(pdev, PCI_D3hot) || 144 + pci_pme_capable(pdev, PCI_D3cold)) && !enable_gpe(&pdev->dev)) { 145 + pci_pme_active(pdev, true); 146 + dev_dbg(&pdev->dev, "ish ipc driver pme wake enabled\n"); 147 + } 148 + } 149 + 116 150 /** 117 151 * ish_probe() - PCI driver probe callback 118 152 * @pdev: pci device ··· 217 179 init_waitqueue_head(&ishtp->suspend_wait); 218 180 init_waitqueue_head(&ishtp->resume_wait); 219 181 182 + /* Enable PME for EHL */ 183 + if (pdev->device == EHL_Ax_DEVICE_ID) 184 + enable_pme_wake(pdev); 185 + 220 186 ret = ish_init(ishtp); 221 187 if (ret) 222 188 return ret; ··· 260 218 { 261 219 struct pci_dev *pdev = to_pci_dev(ish_resume_device); 262 220 struct ishtp_device *dev = pci_get_drvdata(pdev); 221 + uint32_t fwsts = dev->ops->get_fw_status(dev); 263 222 int ret; 264 223 265 - if (ish_should_leave_d0i3(pdev) && !dev->suspend_flag) { 224 + if (ish_should_leave_d0i3(pdev) && !dev->suspend_flag 225 + && IPC_IS_ISH_ILUP(fwsts)) { 266 226 disable_irq_wake(pdev->irq); 227 + 228 + ish_set_host_ready(dev); 267 229 268 230 ishtp_send_resume(dev); 269 231 ··· 362 316 { 363 317 struct pci_dev *pdev = to_pci_dev(device); 364 318 struct ishtp_device *dev = pci_get_drvdata(pdev); 319 + 320 + /* add this to finish power flow for EHL */ 321 + if (dev->pdev->device == EHL_Ax_DEVICE_ID) { 322 + pci_set_power_state(pdev, PCI_D0); 323 + enable_pme_wake(pdev); 324 + dev_dbg(dev->devc, "set power state to D0 for ehl\n"); 325 + } 365 326 366 327 ish_resume_device = device; 367 328 dev->resume_flag = 1;
+1 -1
drivers/hid/wacom_sys.c
··· 1825 1825 struct hid_device *hdev = to_hid_device(dev); 1826 1826 struct wacom *wacom = hid_get_drvdata(hdev); 1827 1827 1828 - return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed); 1828 + return sysfs_emit(buf, "%i\n", wacom->wacom_wac.bt_high_speed); 1829 1829 } 1830 1830 1831 1831 static ssize_t wacom_store_speed(struct device *dev,
+6 -1
drivers/hid/wacom_wac.c
··· 2600 2600 wacom_wac->is_invalid_bt_frame = !value; 2601 2601 return; 2602 2602 case HID_DG_CONTACTMAX: 2603 - features->touch_max = value; 2603 + if (!features->touch_max) { 2604 + features->touch_max = value; 2605 + } else { 2606 + hid_warn(hdev, "%s: ignoring attempt to overwrite non-zero touch_max " 2607 + "%d -> %d\n", __func__, features->touch_max, value); 2608 + } 2604 2609 return; 2605 2610 } 2606 2611
+5 -4
include/linux/hid-sensor-hub.h
··· 150 150 * @info: return information about attribute after parsing report 151 151 * 152 152 * Parses report and returns the attribute information such as report id, 153 - * field index, units and exponet etc. 153 + * field index, units and exponent etc. 154 154 */ 155 155 int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev, 156 156 u8 type, ··· 167 167 * @is_signed: If true then fields < 32 bits will be sign-extended 168 168 * 169 169 * Issues a synchronous or asynchronous read request for an input attribute. 170 - * Returns data upto 32 bits. 170 + * Return: data up to 32 bits. 171 171 */ 172 172 173 173 enum sensor_hub_read_flags { ··· 205 205 * @buffer: buffer to copy output 206 206 * 207 207 * Used to get a field in feature report. For example this can get polling 208 - * interval, sensitivity, activate/deactivate state. On success it returns 209 - * number of bytes copied to buffer. On failure, it returns value < 0. 208 + * interval, sensitivity, activate/deactivate state. 209 + * Return: On success, it returns the number of bytes copied to buffer. 210 + * On failure, it returns value < 0. 210 211 */ 211 212 int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, 212 213 u32 field_index, int buffer_size, void *buffer);
+11 -4
include/linux/hid.h
··· 918 918 /** 919 919 * hid_device_io_start - enable HID input during probe, remove 920 920 * 921 - * @hid - the device 921 + * @hid: the device 922 922 * 923 923 * This should only be called during probe or remove and only be 924 924 * called by the thread calling probe or remove. It will allow ··· 936 936 /** 937 937 * hid_device_io_stop - disable HID input during probe, remove 938 938 * 939 - * @hid - the device 939 + * @hid: the device 940 940 * 941 941 * Should only be called after hid_device_io_start. It will prevent 942 942 * incoming packets from going to the driver for the duration of ··· 1009 1009 1010 1010 /** 1011 1011 * hid_map_usage_clear - map usage input bits and clear the input bit 1012 + * 1013 + * @hidinput: hidinput which we are interested in 1014 + * @usage: usage to fill in 1015 + * @bit: pointer to input->{}bit (out parameter) 1016 + * @max: maximal valid usage->code to consider later (out parameter) 1017 + * @type: input event type (EV_KEY, EV_REL, ...) 1018 + * @c: code which corresponds to this usage and type 1012 1019 * 1013 1020 * The same as hid_map_usage, except the @c bit is also cleared in supported 1014 1021 * bits (@bit). ··· 1091 1084 * @rtype: HID report type 1092 1085 * @reqtype: HID_REQ_GET_REPORT or HID_REQ_SET_REPORT 1093 1086 * 1094 - * @return: count of data transfered, negative if error 1087 + * Return: count of data transferred, negative if error 1095 1088 * 1096 1089 * Same behavior as hid_hw_request, but with raw buffers instead. 1097 1090 */ ··· 1113 1106 * @buf: raw data to transfer 1114 1107 * @len: length of buf 1115 1108 * 1116 - * @return: count of data transfered, negative if error 1109 + * Return: count of data transferred, negative if error 1117 1110 */ 1118 1111 static inline int hid_hw_output_report(struct hid_device *hdev, __u8 *buf, 1119 1112 size_t len)
-41
include/linux/platform_data/i2c-hid.h
··· 1 - /* 2 - * HID over I2C protocol implementation 3 - * 4 - * Copyright (c) 2012 Benjamin Tissoires <benjamin.tissoires@gmail.com> 5 - * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France 6 - * 7 - * This file is subject to the terms and conditions of the GNU General Public 8 - * License. See the file COPYING in the main directory of this archive for 9 - * more details. 10 - */ 11 - 12 - #ifndef __LINUX_I2C_HID_H 13 - #define __LINUX_I2C_HID_H 14 - 15 - #include <linux/regulator/consumer.h> 16 - #include <linux/types.h> 17 - 18 - /** 19 - * struct i2chid_platform_data - used by hid over i2c implementation. 20 - * @hid_descriptor_address: i2c register where the HID descriptor is stored. 21 - * @supplies: regulators for powering on the device. 22 - * @post_power_delay_ms: delay after powering on before device is usable. 23 - * 24 - * Note that it is the responsibility of the platform driver (or the acpi 5.0 25 - * driver, or the flattened device tree) to setup the irq related to the gpio in 26 - * the struct i2c_board_info. 27 - * The platform driver should also setup the gpio according to the device: 28 - * 29 - * A typical example is the following: 30 - * irq = gpio_to_irq(intr_gpio); 31 - * hkdk4412_i2c_devs5[0].irq = irq; // store the irq in i2c_board_info 32 - * gpio_request(intr_gpio, "elan-irq"); 33 - * s3c_gpio_setpull(intr_gpio, S3C_GPIO_PULL_UP); 34 - */ 35 - struct i2c_hid_platform_data { 36 - u16 hid_descriptor_address; 37 - struct regulator_bulk_data supplies[2]; 38 - int post_power_delay_ms; 39 - }; 40 - 41 - #endif /* __LINUX_I2C_HID_H */