Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1 | /* |
Frank Praznik | 077147a | 2014-09-14 11:56:39 -0400 | [diff] [blame] | 2 | * HID driver for Sony / PS2 / PS3 / PS4 BD devices. |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 1999 Andreas Gal |
| 5 | * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> |
| 6 | * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 7 | * Copyright (c) 2008 Jiri Slaby |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 8 | * Copyright (c) 2012 David Dillow <dave@thedillows.org> |
| 9 | * Copyright (c) 2006-2013 Jiri Kosina |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 10 | * Copyright (c) 2013 Colin Leitner <colin.leitner@gmail.com> |
Frank Praznik | 077147a | 2014-09-14 11:56:39 -0400 | [diff] [blame] | 11 | * Copyright (c) 2014 Frank Praznik <frank.praznik@gmail.com> |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * This program is free software; you can redistribute it and/or modify it |
| 16 | * under the terms of the GNU General Public License as published by the Free |
| 17 | * Software Foundation; either version 2 of the License, or (at your option) |
| 18 | * any later version. |
| 19 | */ |
| 20 | |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 21 | /* |
| 22 | * NOTE: in order for the Sony PS3 BD Remote Control to be found by |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 23 | * a Bluetooth host, the key combination Start+Enter has to be kept pressed |
| 24 | * for about 7 seconds with the Bluetooth Host Controller in discovering mode. |
| 25 | * |
| 26 | * There will be no PIN request from the device. |
| 27 | */ |
| 28 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 29 | #include <linux/device.h> |
| 30 | #include <linux/hid.h> |
| 31 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 33 | #include <linux/leds.h> |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 34 | #include <linux/power_supply.h> |
| 35 | #include <linux/spinlock.h> |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 36 | #include <linux/list.h> |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 37 | #include <linux/idr.h> |
Frank Praznik | e560623 | 2014-01-27 10:17:37 -0500 | [diff] [blame] | 38 | #include <linux/input/mt.h> |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 39 | |
| 40 | #include "hid-ids.h" |
| 41 | |
Frank Praznik | 6c79c18 | 2014-01-16 21:43:03 -0500 | [diff] [blame] | 42 | #define VAIO_RDESC_CONSTANT BIT(0) |
| 43 | #define SIXAXIS_CONTROLLER_USB BIT(1) |
| 44 | #define SIXAXIS_CONTROLLER_BT BIT(2) |
| 45 | #define BUZZ_CONTROLLER BIT(3) |
| 46 | #define PS3REMOTE BIT(4) |
Frank Praznik | 8ab1676 | 2014-01-16 21:42:31 -0500 | [diff] [blame] | 47 | #define DUALSHOCK4_CONTROLLER_USB BIT(5) |
| 48 | #define DUALSHOCK4_CONTROLLER_BT BIT(6) |
Simon Wood | b3bca32 | 2015-06-09 21:27:04 -0600 | [diff] [blame] | 49 | #define MOTION_CONTROLLER_USB BIT(7) |
| 50 | #define MOTION_CONTROLLER_BT BIT(8) |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 51 | #define NAVIGATION_CONTROLLER_USB BIT(9) |
| 52 | #define NAVIGATION_CONTROLLER_BT BIT(10) |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 53 | |
Frank Praznik | fee4e2d | 2014-02-18 17:22:01 -0500 | [diff] [blame] | 54 | #define SIXAXIS_CONTROLLER (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT) |
Simon Wood | b3bca32 | 2015-06-09 21:27:04 -0600 | [diff] [blame] | 55 | #define MOTION_CONTROLLER (MOTION_CONTROLLER_USB | MOTION_CONTROLLER_BT) |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 56 | #define NAVIGATION_CONTROLLER (NAVIGATION_CONTROLLER_USB |\ |
| 57 | NAVIGATION_CONTROLLER_BT) |
Frank Praznik | 68330d8 | 2014-02-05 20:03:49 -0500 | [diff] [blame] | 58 | #define DUALSHOCK4_CONTROLLER (DUALSHOCK4_CONTROLLER_USB |\ |
| 59 | DUALSHOCK4_CONTROLLER_BT) |
Frank Praznik | fee4e2d | 2014-02-18 17:22:01 -0500 | [diff] [blame] | 60 | #define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER | BUZZ_CONTROLLER |\ |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 61 | DUALSHOCK4_CONTROLLER | MOTION_CONTROLLER |\ |
| 62 | NAVIGATION_CONTROLLER) |
Simon Wood | 12e9a6d7 | 2015-06-09 21:27:05 -0600 | [diff] [blame] | 63 | #define SONY_BATTERY_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER |\ |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 64 | MOTION_CONTROLLER_BT | NAVIGATION_CONTROLLER) |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 65 | #define SONY_FF_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER |\ |
| 66 | MOTION_CONTROLLER) |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 67 | |
| 68 | #define MAX_LEDS 4 |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 69 | |
Frank Praznik | 4c3e829 | 2015-05-05 20:47:33 -0400 | [diff] [blame] | 70 | /* |
| 71 | * The Sixaxis reports both digital and analog values for each button on the |
| 72 | * controller except for Start, Select and the PS button. The controller ends |
| 73 | * up reporting 27 axes which causes them to spill over into the multi-touch |
| 74 | * axis values. Additionally, the controller only has 20 actual, physical axes |
| 75 | * so there are several unused axes in between the used ones. |
| 76 | */ |
Antonio Ospite | c607fb8 | 2014-06-24 13:28:41 +0200 | [diff] [blame] | 77 | static __u8 sixaxis_rdesc[] = { |
Antonio Ospite | fb705a6 | 2014-06-24 13:28:42 +0200 | [diff] [blame] | 78 | 0x05, 0x01, /* Usage Page (Desktop), */ |
Frank Praznik | 4c3e829 | 2015-05-05 20:47:33 -0400 | [diff] [blame] | 79 | 0x09, 0x04, /* Usage (Joystick), */ |
Antonio Ospite | fb705a6 | 2014-06-24 13:28:42 +0200 | [diff] [blame] | 80 | 0xA1, 0x01, /* Collection (Application), */ |
| 81 | 0xA1, 0x02, /* Collection (Logical), */ |
| 82 | 0x85, 0x01, /* Report ID (1), */ |
| 83 | 0x75, 0x08, /* Report Size (8), */ |
| 84 | 0x95, 0x01, /* Report Count (1), */ |
| 85 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 86 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
| 87 | 0x81, 0x03, /* Input (Constant, Variable), */ |
| 88 | 0x75, 0x01, /* Report Size (1), */ |
| 89 | 0x95, 0x13, /* Report Count (19), */ |
| 90 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 91 | 0x25, 0x01, /* Logical Maximum (1), */ |
| 92 | 0x35, 0x00, /* Physical Minimum (0), */ |
| 93 | 0x45, 0x01, /* Physical Maximum (1), */ |
| 94 | 0x05, 0x09, /* Usage Page (Button), */ |
| 95 | 0x19, 0x01, /* Usage Minimum (01h), */ |
| 96 | 0x29, 0x13, /* Usage Maximum (13h), */ |
| 97 | 0x81, 0x02, /* Input (Variable), */ |
| 98 | 0x75, 0x01, /* Report Size (1), */ |
| 99 | 0x95, 0x0D, /* Report Count (13), */ |
| 100 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 101 | 0x81, 0x03, /* Input (Constant, Variable), */ |
| 102 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 103 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
| 104 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 105 | 0x09, 0x01, /* Usage (Pointer), */ |
| 106 | 0xA1, 0x00, /* Collection (Physical), */ |
| 107 | 0x75, 0x08, /* Report Size (8), */ |
| 108 | 0x95, 0x04, /* Report Count (4), */ |
| 109 | 0x35, 0x00, /* Physical Minimum (0), */ |
| 110 | 0x46, 0xFF, 0x00, /* Physical Maximum (255), */ |
| 111 | 0x09, 0x30, /* Usage (X), */ |
| 112 | 0x09, 0x31, /* Usage (Y), */ |
| 113 | 0x09, 0x32, /* Usage (Z), */ |
| 114 | 0x09, 0x35, /* Usage (Rz), */ |
| 115 | 0x81, 0x02, /* Input (Variable), */ |
| 116 | 0xC0, /* End Collection, */ |
| 117 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 118 | 0x95, 0x13, /* Report Count (19), */ |
| 119 | 0x09, 0x01, /* Usage (Pointer), */ |
| 120 | 0x81, 0x02, /* Input (Variable), */ |
| 121 | 0x95, 0x0C, /* Report Count (12), */ |
| 122 | 0x81, 0x01, /* Input (Constant), */ |
| 123 | 0x75, 0x10, /* Report Size (16), */ |
| 124 | 0x95, 0x04, /* Report Count (4), */ |
| 125 | 0x26, 0xFF, 0x03, /* Logical Maximum (1023), */ |
| 126 | 0x46, 0xFF, 0x03, /* Physical Maximum (1023), */ |
| 127 | 0x09, 0x01, /* Usage (Pointer), */ |
| 128 | 0x81, 0x02, /* Input (Variable), */ |
| 129 | 0xC0, /* End Collection, */ |
| 130 | 0xA1, 0x02, /* Collection (Logical), */ |
| 131 | 0x85, 0x02, /* Report ID (2), */ |
| 132 | 0x75, 0x08, /* Report Size (8), */ |
| 133 | 0x95, 0x30, /* Report Count (48), */ |
| 134 | 0x09, 0x01, /* Usage (Pointer), */ |
| 135 | 0xB1, 0x02, /* Feature (Variable), */ |
| 136 | 0xC0, /* End Collection, */ |
| 137 | 0xA1, 0x02, /* Collection (Logical), */ |
| 138 | 0x85, 0xEE, /* Report ID (238), */ |
| 139 | 0x75, 0x08, /* Report Size (8), */ |
| 140 | 0x95, 0x30, /* Report Count (48), */ |
| 141 | 0x09, 0x01, /* Usage (Pointer), */ |
| 142 | 0xB1, 0x02, /* Feature (Variable), */ |
| 143 | 0xC0, /* End Collection, */ |
| 144 | 0xA1, 0x02, /* Collection (Logical), */ |
| 145 | 0x85, 0xEF, /* Report ID (239), */ |
| 146 | 0x75, 0x08, /* Report Size (8), */ |
| 147 | 0x95, 0x30, /* Report Count (48), */ |
| 148 | 0x09, 0x01, /* Usage (Pointer), */ |
| 149 | 0xB1, 0x02, /* Feature (Variable), */ |
| 150 | 0xC0, /* End Collection, */ |
| 151 | 0xC0 /* End Collection */ |
Mauro Carvalho Chehab | e57a67d | 2012-12-14 20:57:34 -0200 | [diff] [blame] | 152 | }; |
| 153 | |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 154 | /* PS/3 Motion controller */ |
| 155 | static __u8 motion_rdesc[] = { |
| 156 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 157 | 0x09, 0x04, /* Usage (Joystick), */ |
| 158 | 0xA1, 0x01, /* Collection (Application), */ |
| 159 | 0xA1, 0x02, /* Collection (Logical), */ |
| 160 | 0x85, 0x01, /* Report ID (1), */ |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 161 | 0x75, 0x01, /* Report Size (1), */ |
Simon Wood | 8b2513c | 2015-06-09 21:27:07 -0600 | [diff] [blame] | 162 | 0x95, 0x15, /* Report Count (21), */ |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 163 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 164 | 0x25, 0x01, /* Logical Maximum (1), */ |
| 165 | 0x35, 0x00, /* Physical Minimum (0), */ |
| 166 | 0x45, 0x01, /* Physical Maximum (1), */ |
| 167 | 0x05, 0x09, /* Usage Page (Button), */ |
| 168 | 0x19, 0x01, /* Usage Minimum (01h), */ |
Simon Wood | 8b2513c | 2015-06-09 21:27:07 -0600 | [diff] [blame] | 169 | 0x29, 0x15, /* Usage Maximum (15h), */ |
| 170 | 0x81, 0x02, /* Input (Variable), * Buttons */ |
| 171 | 0x95, 0x0B, /* Report Count (11), */ |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 172 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
Simon Wood | 8b2513c | 2015-06-09 21:27:07 -0600 | [diff] [blame] | 173 | 0x81, 0x03, /* Input (Constant, Variable), * Padding */ |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 174 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 175 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
| 176 | 0x05, 0x01, /* Usage Page (Desktop), */ |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 177 | 0xA1, 0x00, /* Collection (Physical), */ |
| 178 | 0x75, 0x08, /* Report Size (8), */ |
Simon Wood | 8b2513c | 2015-06-09 21:27:07 -0600 | [diff] [blame] | 179 | 0x95, 0x01, /* Report Count (1), */ |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 180 | 0x35, 0x00, /* Physical Minimum (0), */ |
| 181 | 0x46, 0xFF, 0x00, /* Physical Maximum (255), */ |
| 182 | 0x09, 0x30, /* Usage (X), */ |
Simon Wood | 8b2513c | 2015-06-09 21:27:07 -0600 | [diff] [blame] | 183 | 0x81, 0x02, /* Input (Variable), * Trigger */ |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 184 | 0xC0, /* End Collection, */ |
Simon Wood | 8b2513c | 2015-06-09 21:27:07 -0600 | [diff] [blame] | 185 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 186 | 0x75, 0x08, /* Report Size (8), */ |
| 187 | 0x95, 0x07, /* Report Count (7), * skip 7 bytes */ |
| 188 | 0x81, 0x02, /* Input (Variable), */ |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 189 | 0x05, 0x01, /* Usage Page (Desktop), */ |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 190 | 0x75, 0x10, /* Report Size (16), */ |
Simon Wood | 8b2513c | 2015-06-09 21:27:07 -0600 | [diff] [blame] | 191 | 0x46, 0xFF, 0xFF, /* Physical Maximum (65535), */ |
| 192 | 0x27, 0xFF, 0xFF, 0x00, 0x00, /* Logical Maximum (65535), */ |
| 193 | 0x95, 0x03, /* Report Count (3), * 3x Accels */ |
| 194 | 0x09, 0x33, /* Usage (rX), */ |
| 195 | 0x09, 0x34, /* Usage (rY), */ |
| 196 | 0x09, 0x35, /* Usage (rZ), */ |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 197 | 0x81, 0x02, /* Input (Variable), */ |
Simon Wood | 8b2513c | 2015-06-09 21:27:07 -0600 | [diff] [blame] | 198 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 199 | 0x95, 0x03, /* Report Count (3), * Skip Accels 2nd frame */ |
| 200 | 0x81, 0x02, /* Input (Variable), */ |
| 201 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 202 | 0x09, 0x01, /* Usage (Pointer), */ |
| 203 | 0x95, 0x03, /* Report Count (3), * 3x Gyros */ |
| 204 | 0x81, 0x02, /* Input (Variable), */ |
| 205 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 206 | 0x95, 0x03, /* Report Count (3), * Skip Gyros 2nd frame */ |
| 207 | 0x81, 0x02, /* Input (Variable), */ |
| 208 | 0x75, 0x0C, /* Report Size (12), */ |
| 209 | 0x46, 0xFF, 0x0F, /* Physical Maximum (4095), */ |
| 210 | 0x26, 0xFF, 0x0F, /* Logical Maximum (4095), */ |
| 211 | 0x95, 0x04, /* Report Count (4), * Skip Temp and Magnetometers */ |
| 212 | 0x81, 0x02, /* Input (Variable), */ |
| 213 | 0x75, 0x08, /* Report Size (8), */ |
| 214 | 0x46, 0xFF, 0x00, /* Physical Maximum (255), */ |
| 215 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
| 216 | 0x95, 0x06, /* Report Count (6), * Skip Timestamp and Extension Bytes */ |
| 217 | 0x81, 0x02, /* Input (Variable), */ |
| 218 | 0x75, 0x08, /* Report Size (8), */ |
| 219 | 0x95, 0x30, /* Report Count (48), */ |
| 220 | 0x09, 0x01, /* Usage (Pointer), */ |
| 221 | 0x91, 0x02, /* Output (Variable), */ |
| 222 | 0x75, 0x08, /* Report Size (8), */ |
| 223 | 0x95, 0x30, /* Report Count (48), */ |
| 224 | 0x09, 0x01, /* Usage (Pointer), */ |
| 225 | 0xB1, 0x02, /* Feature (Variable), */ |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 226 | 0xC0, /* End Collection, */ |
| 227 | 0xA1, 0x02, /* Collection (Logical), */ |
| 228 | 0x85, 0x02, /* Report ID (2), */ |
| 229 | 0x75, 0x08, /* Report Size (8), */ |
| 230 | 0x95, 0x30, /* Report Count (48), */ |
| 231 | 0x09, 0x01, /* Usage (Pointer), */ |
| 232 | 0xB1, 0x02, /* Feature (Variable), */ |
| 233 | 0xC0, /* End Collection, */ |
| 234 | 0xA1, 0x02, /* Collection (Logical), */ |
| 235 | 0x85, 0xEE, /* Report ID (238), */ |
| 236 | 0x75, 0x08, /* Report Size (8), */ |
| 237 | 0x95, 0x30, /* Report Count (48), */ |
| 238 | 0x09, 0x01, /* Usage (Pointer), */ |
| 239 | 0xB1, 0x02, /* Feature (Variable), */ |
| 240 | 0xC0, /* End Collection, */ |
| 241 | 0xA1, 0x02, /* Collection (Logical), */ |
| 242 | 0x85, 0xEF, /* Report ID (239), */ |
| 243 | 0x75, 0x08, /* Report Size (8), */ |
| 244 | 0x95, 0x30, /* Report Count (48), */ |
| 245 | 0x09, 0x01, /* Usage (Pointer), */ |
| 246 | 0xB1, 0x02, /* Feature (Variable), */ |
| 247 | 0xC0, /* End Collection, */ |
| 248 | 0xC0 /* End Collection */ |
| 249 | }; |
| 250 | |
Simon Wood | b2723eb | 2015-06-17 00:08:53 -0600 | [diff] [blame] | 251 | /* PS/3 Navigation controller */ |
| 252 | static __u8 navigation_rdesc[] = { |
| 253 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 254 | 0x09, 0x04, /* Usage (Joystik), */ |
| 255 | 0xA1, 0x01, /* Collection (Application), */ |
| 256 | 0xA1, 0x02, /* Collection (Logical), */ |
| 257 | 0x85, 0x01, /* Report ID (1), */ |
| 258 | 0x75, 0x08, /* Report Size (8), */ |
| 259 | 0x95, 0x01, /* Report Count (1), */ |
| 260 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 261 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
| 262 | 0x81, 0x03, /* Input (Constant, Variable), */ |
| 263 | 0x75, 0x01, /* Report Size (1), */ |
| 264 | 0x95, 0x13, /* Report Count (19), */ |
| 265 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 266 | 0x25, 0x01, /* Logical Maximum (1), */ |
| 267 | 0x35, 0x00, /* Physical Minimum (0), */ |
| 268 | 0x45, 0x01, /* Physical Maximum (1), */ |
| 269 | 0x05, 0x09, /* Usage Page (Button), */ |
| 270 | 0x19, 0x01, /* Usage Minimum (01h), */ |
| 271 | 0x29, 0x13, /* Usage Maximum (13h), */ |
| 272 | 0x81, 0x02, /* Input (Variable), */ |
| 273 | 0x75, 0x01, /* Report Size (1), */ |
| 274 | 0x95, 0x0D, /* Report Count (13), */ |
| 275 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 276 | 0x81, 0x03, /* Input (Constant, Variable), */ |
| 277 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 278 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
| 279 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 280 | 0x09, 0x01, /* Usage (Pointer), */ |
| 281 | 0xA1, 0x00, /* Collection (Physical), */ |
| 282 | 0x75, 0x08, /* Report Size (8), */ |
| 283 | 0x95, 0x02, /* Report Count (2), */ |
| 284 | 0x35, 0x00, /* Physical Minimum (0), */ |
| 285 | 0x46, 0xFF, 0x00, /* Physical Maximum (255), */ |
| 286 | 0x09, 0x30, /* Usage (X), */ |
| 287 | 0x09, 0x31, /* Usage (Y), */ |
| 288 | 0x81, 0x02, /* Input (Variable), */ |
| 289 | 0xC0, /* End Collection, */ |
| 290 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 291 | 0x95, 0x06, /* Report Count (6), */ |
| 292 | 0x81, 0x03, /* Input (Constant, Variable), */ |
| 293 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 294 | 0x75, 0x08, /* Report Size (8), */ |
| 295 | 0x95, 0x05, /* Report Count (5), */ |
| 296 | 0x09, 0x01, /* Usage (Pointer), */ |
| 297 | 0x81, 0x02, /* Input (Variable), */ |
| 298 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
Simon Wood | 2259b5bb | 2015-07-10 00:10:21 -0600 | [diff] [blame] | 299 | 0x95, 0x01, /* Report Count (1), */ |
| 300 | 0x81, 0x02, /* Input (Variable), */ |
| 301 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 302 | 0x95, 0x01, /* Report Count (1), */ |
| 303 | 0x09, 0x01, /* Usage (Pointer), */ |
| 304 | 0x81, 0x02, /* Input (Variable), */ |
| 305 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 306 | 0x95, 0x1E, /* Report Count (24), */ |
Simon Wood | b2723eb | 2015-06-17 00:08:53 -0600 | [diff] [blame] | 307 | 0x81, 0x02, /* Input (Variable), */ |
| 308 | 0x75, 0x08, /* Report Size (8), */ |
| 309 | 0x95, 0x30, /* Report Count (48), */ |
| 310 | 0x09, 0x01, /* Usage (Pointer), */ |
| 311 | 0x91, 0x02, /* Output (Variable), */ |
| 312 | 0x75, 0x08, /* Report Size (8), */ |
| 313 | 0x95, 0x30, /* Report Count (48), */ |
| 314 | 0x09, 0x01, /* Usage (Pointer), */ |
| 315 | 0xB1, 0x02, /* Feature (Variable), */ |
| 316 | 0xC0, /* End Collection, */ |
| 317 | 0xA1, 0x02, /* Collection (Logical), */ |
| 318 | 0x85, 0x02, /* Report ID (2), */ |
| 319 | 0x75, 0x08, /* Report Size (8), */ |
| 320 | 0x95, 0x30, /* Report Count (48), */ |
| 321 | 0x09, 0x01, /* Usage (Pointer), */ |
| 322 | 0xB1, 0x02, /* Feature (Variable), */ |
| 323 | 0xC0, /* End Collection, */ |
| 324 | 0xA1, 0x02, /* Collection (Logical), */ |
| 325 | 0x85, 0xEE, /* Report ID (238), */ |
| 326 | 0x75, 0x08, /* Report Size (8), */ |
| 327 | 0x95, 0x30, /* Report Count (48), */ |
| 328 | 0x09, 0x01, /* Usage (Pointer), */ |
| 329 | 0xB1, 0x02, /* Feature (Variable), */ |
| 330 | 0xC0, /* End Collection, */ |
| 331 | 0xA1, 0x02, /* Collection (Logical), */ |
| 332 | 0x85, 0xEF, /* Report ID (239), */ |
| 333 | 0x75, 0x08, /* Report Size (8), */ |
| 334 | 0x95, 0x30, /* Report Count (48), */ |
| 335 | 0x09, 0x01, /* Usage (Pointer), */ |
| 336 | 0xB1, 0x02, /* Feature (Variable), */ |
| 337 | 0xC0, /* End Collection, */ |
| 338 | 0xC0 /* End Collection */ |
| 339 | }; |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 340 | |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 341 | /* |
| 342 | * The default descriptor doesn't provide mapping for the accelerometers |
Frank Praznik | 58d7027 | 2014-01-20 12:27:01 -0500 | [diff] [blame] | 343 | * or orientation sensors. This fixed descriptor maps the accelerometers |
| 344 | * to usage values 0x40, 0x41 and 0x42 and maps the orientation sensors |
| 345 | * to usage values 0x43, 0x44 and 0x45. |
| 346 | */ |
Frank Praznik | ed19d8c | 2014-01-16 21:43:12 -0500 | [diff] [blame] | 347 | static u8 dualshock4_usb_rdesc[] = { |
Frank Praznik | 58d7027 | 2014-01-20 12:27:01 -0500 | [diff] [blame] | 348 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 349 | 0x09, 0x05, /* Usage (Gamepad), */ |
| 350 | 0xA1, 0x01, /* Collection (Application), */ |
| 351 | 0x85, 0x01, /* Report ID (1), */ |
| 352 | 0x09, 0x30, /* Usage (X), */ |
| 353 | 0x09, 0x31, /* Usage (Y), */ |
| 354 | 0x09, 0x32, /* Usage (Z), */ |
| 355 | 0x09, 0x35, /* Usage (Rz), */ |
| 356 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 357 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
| 358 | 0x75, 0x08, /* Report Size (8), */ |
| 359 | 0x95, 0x04, /* Report Count (4), */ |
| 360 | 0x81, 0x02, /* Input (Variable), */ |
| 361 | 0x09, 0x39, /* Usage (Hat Switch), */ |
| 362 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 363 | 0x25, 0x07, /* Logical Maximum (7), */ |
| 364 | 0x35, 0x00, /* Physical Minimum (0), */ |
| 365 | 0x46, 0x3B, 0x01, /* Physical Maximum (315), */ |
| 366 | 0x65, 0x14, /* Unit (Degrees), */ |
| 367 | 0x75, 0x04, /* Report Size (4), */ |
| 368 | 0x95, 0x01, /* Report Count (1), */ |
| 369 | 0x81, 0x42, /* Input (Variable, Null State), */ |
| 370 | 0x65, 0x00, /* Unit, */ |
| 371 | 0x05, 0x09, /* Usage Page (Button), */ |
| 372 | 0x19, 0x01, /* Usage Minimum (01h), */ |
| 373 | 0x29, 0x0E, /* Usage Maximum (0Eh), */ |
| 374 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 375 | 0x25, 0x01, /* Logical Maximum (1), */ |
| 376 | 0x75, 0x01, /* Report Size (1), */ |
| 377 | 0x95, 0x0E, /* Report Count (14), */ |
| 378 | 0x81, 0x02, /* Input (Variable), */ |
| 379 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 380 | 0x09, 0x20, /* Usage (20h), */ |
| 381 | 0x75, 0x06, /* Report Size (6), */ |
| 382 | 0x95, 0x01, /* Report Count (1), */ |
| 383 | 0x15, 0x00, /* Logical Minimum (0), */ |
Frank Praznik | fb291cb | 2014-09-14 11:56:38 -0400 | [diff] [blame] | 384 | 0x25, 0x3F, /* Logical Maximum (63), */ |
Frank Praznik | 58d7027 | 2014-01-20 12:27:01 -0500 | [diff] [blame] | 385 | 0x81, 0x02, /* Input (Variable), */ |
| 386 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 387 | 0x09, 0x33, /* Usage (Rx), */ |
| 388 | 0x09, 0x34, /* Usage (Ry), */ |
| 389 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 390 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
| 391 | 0x75, 0x08, /* Report Size (8), */ |
| 392 | 0x95, 0x02, /* Report Count (2), */ |
| 393 | 0x81, 0x02, /* Input (Variable), */ |
| 394 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 395 | 0x09, 0x21, /* Usage (21h), */ |
| 396 | 0x95, 0x03, /* Report Count (3), */ |
| 397 | 0x81, 0x02, /* Input (Variable), */ |
| 398 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 399 | 0x19, 0x40, /* Usage Minimum (40h), */ |
| 400 | 0x29, 0x42, /* Usage Maximum (42h), */ |
| 401 | 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */ |
| 402 | 0x26, 0x00, 0x7F, /* Logical Maximum (32767), */ |
| 403 | 0x75, 0x10, /* Report Size (16), */ |
| 404 | 0x95, 0x03, /* Report Count (3), */ |
| 405 | 0x81, 0x02, /* Input (Variable), */ |
| 406 | 0x19, 0x43, /* Usage Minimum (43h), */ |
| 407 | 0x29, 0x45, /* Usage Maximum (45h), */ |
Frank Praznik | fb291cb | 2014-09-14 11:56:38 -0400 | [diff] [blame] | 408 | 0x16, 0x00, 0xE0, /* Logical Minimum (-8192), */ |
| 409 | 0x26, 0xFF, 0x1F, /* Logical Maximum (8191), */ |
Frank Praznik | 58d7027 | 2014-01-20 12:27:01 -0500 | [diff] [blame] | 410 | 0x95, 0x03, /* Report Count (3), */ |
| 411 | 0x81, 0x02, /* Input (Variable), */ |
| 412 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 413 | 0x09, 0x21, /* Usage (21h), */ |
| 414 | 0x15, 0x00, /* Logical Minimum (0), */ |
Frank Praznik | fb291cb | 2014-09-14 11:56:38 -0400 | [diff] [blame] | 415 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
Frank Praznik | 58d7027 | 2014-01-20 12:27:01 -0500 | [diff] [blame] | 416 | 0x75, 0x08, /* Report Size (8), */ |
| 417 | 0x95, 0x27, /* Report Count (39), */ |
| 418 | 0x81, 0x02, /* Input (Variable), */ |
| 419 | 0x85, 0x05, /* Report ID (5), */ |
| 420 | 0x09, 0x22, /* Usage (22h), */ |
| 421 | 0x95, 0x1F, /* Report Count (31), */ |
| 422 | 0x91, 0x02, /* Output (Variable), */ |
| 423 | 0x85, 0x04, /* Report ID (4), */ |
| 424 | 0x09, 0x23, /* Usage (23h), */ |
| 425 | 0x95, 0x24, /* Report Count (36), */ |
| 426 | 0xB1, 0x02, /* Feature (Variable), */ |
| 427 | 0x85, 0x02, /* Report ID (2), */ |
| 428 | 0x09, 0x24, /* Usage (24h), */ |
| 429 | 0x95, 0x24, /* Report Count (36), */ |
| 430 | 0xB1, 0x02, /* Feature (Variable), */ |
| 431 | 0x85, 0x08, /* Report ID (8), */ |
| 432 | 0x09, 0x25, /* Usage (25h), */ |
| 433 | 0x95, 0x03, /* Report Count (3), */ |
| 434 | 0xB1, 0x02, /* Feature (Variable), */ |
| 435 | 0x85, 0x10, /* Report ID (16), */ |
| 436 | 0x09, 0x26, /* Usage (26h), */ |
| 437 | 0x95, 0x04, /* Report Count (4), */ |
| 438 | 0xB1, 0x02, /* Feature (Variable), */ |
| 439 | 0x85, 0x11, /* Report ID (17), */ |
| 440 | 0x09, 0x27, /* Usage (27h), */ |
| 441 | 0x95, 0x02, /* Report Count (2), */ |
| 442 | 0xB1, 0x02, /* Feature (Variable), */ |
| 443 | 0x85, 0x12, /* Report ID (18), */ |
| 444 | 0x06, 0x02, 0xFF, /* Usage Page (FF02h), */ |
| 445 | 0x09, 0x21, /* Usage (21h), */ |
| 446 | 0x95, 0x0F, /* Report Count (15), */ |
| 447 | 0xB1, 0x02, /* Feature (Variable), */ |
| 448 | 0x85, 0x13, /* Report ID (19), */ |
| 449 | 0x09, 0x22, /* Usage (22h), */ |
| 450 | 0x95, 0x16, /* Report Count (22), */ |
| 451 | 0xB1, 0x02, /* Feature (Variable), */ |
| 452 | 0x85, 0x14, /* Report ID (20), */ |
| 453 | 0x06, 0x05, 0xFF, /* Usage Page (FF05h), */ |
| 454 | 0x09, 0x20, /* Usage (20h), */ |
| 455 | 0x95, 0x10, /* Report Count (16), */ |
| 456 | 0xB1, 0x02, /* Feature (Variable), */ |
| 457 | 0x85, 0x15, /* Report ID (21), */ |
| 458 | 0x09, 0x21, /* Usage (21h), */ |
| 459 | 0x95, 0x2C, /* Report Count (44), */ |
| 460 | 0xB1, 0x02, /* Feature (Variable), */ |
| 461 | 0x06, 0x80, 0xFF, /* Usage Page (FF80h), */ |
| 462 | 0x85, 0x80, /* Report ID (128), */ |
| 463 | 0x09, 0x20, /* Usage (20h), */ |
| 464 | 0x95, 0x06, /* Report Count (6), */ |
| 465 | 0xB1, 0x02, /* Feature (Variable), */ |
| 466 | 0x85, 0x81, /* Report ID (129), */ |
| 467 | 0x09, 0x21, /* Usage (21h), */ |
| 468 | 0x95, 0x06, /* Report Count (6), */ |
| 469 | 0xB1, 0x02, /* Feature (Variable), */ |
| 470 | 0x85, 0x82, /* Report ID (130), */ |
| 471 | 0x09, 0x22, /* Usage (22h), */ |
| 472 | 0x95, 0x05, /* Report Count (5), */ |
| 473 | 0xB1, 0x02, /* Feature (Variable), */ |
| 474 | 0x85, 0x83, /* Report ID (131), */ |
| 475 | 0x09, 0x23, /* Usage (23h), */ |
| 476 | 0x95, 0x01, /* Report Count (1), */ |
| 477 | 0xB1, 0x02, /* Feature (Variable), */ |
| 478 | 0x85, 0x84, /* Report ID (132), */ |
| 479 | 0x09, 0x24, /* Usage (24h), */ |
| 480 | 0x95, 0x04, /* Report Count (4), */ |
| 481 | 0xB1, 0x02, /* Feature (Variable), */ |
| 482 | 0x85, 0x85, /* Report ID (133), */ |
| 483 | 0x09, 0x25, /* Usage (25h), */ |
| 484 | 0x95, 0x06, /* Report Count (6), */ |
| 485 | 0xB1, 0x02, /* Feature (Variable), */ |
| 486 | 0x85, 0x86, /* Report ID (134), */ |
| 487 | 0x09, 0x26, /* Usage (26h), */ |
| 488 | 0x95, 0x06, /* Report Count (6), */ |
| 489 | 0xB1, 0x02, /* Feature (Variable), */ |
| 490 | 0x85, 0x87, /* Report ID (135), */ |
| 491 | 0x09, 0x27, /* Usage (27h), */ |
| 492 | 0x95, 0x23, /* Report Count (35), */ |
| 493 | 0xB1, 0x02, /* Feature (Variable), */ |
| 494 | 0x85, 0x88, /* Report ID (136), */ |
| 495 | 0x09, 0x28, /* Usage (28h), */ |
| 496 | 0x95, 0x22, /* Report Count (34), */ |
| 497 | 0xB1, 0x02, /* Feature (Variable), */ |
| 498 | 0x85, 0x89, /* Report ID (137), */ |
| 499 | 0x09, 0x29, /* Usage (29h), */ |
| 500 | 0x95, 0x02, /* Report Count (2), */ |
| 501 | 0xB1, 0x02, /* Feature (Variable), */ |
| 502 | 0x85, 0x90, /* Report ID (144), */ |
| 503 | 0x09, 0x30, /* Usage (30h), */ |
| 504 | 0x95, 0x05, /* Report Count (5), */ |
| 505 | 0xB1, 0x02, /* Feature (Variable), */ |
| 506 | 0x85, 0x91, /* Report ID (145), */ |
| 507 | 0x09, 0x31, /* Usage (31h), */ |
| 508 | 0x95, 0x03, /* Report Count (3), */ |
| 509 | 0xB1, 0x02, /* Feature (Variable), */ |
| 510 | 0x85, 0x92, /* Report ID (146), */ |
| 511 | 0x09, 0x32, /* Usage (32h), */ |
| 512 | 0x95, 0x03, /* Report Count (3), */ |
| 513 | 0xB1, 0x02, /* Feature (Variable), */ |
| 514 | 0x85, 0x93, /* Report ID (147), */ |
| 515 | 0x09, 0x33, /* Usage (33h), */ |
| 516 | 0x95, 0x0C, /* Report Count (12), */ |
| 517 | 0xB1, 0x02, /* Feature (Variable), */ |
| 518 | 0x85, 0xA0, /* Report ID (160), */ |
| 519 | 0x09, 0x40, /* Usage (40h), */ |
| 520 | 0x95, 0x06, /* Report Count (6), */ |
| 521 | 0xB1, 0x02, /* Feature (Variable), */ |
| 522 | 0x85, 0xA1, /* Report ID (161), */ |
| 523 | 0x09, 0x41, /* Usage (41h), */ |
| 524 | 0x95, 0x01, /* Report Count (1), */ |
| 525 | 0xB1, 0x02, /* Feature (Variable), */ |
| 526 | 0x85, 0xA2, /* Report ID (162), */ |
| 527 | 0x09, 0x42, /* Usage (42h), */ |
| 528 | 0x95, 0x01, /* Report Count (1), */ |
| 529 | 0xB1, 0x02, /* Feature (Variable), */ |
| 530 | 0x85, 0xA3, /* Report ID (163), */ |
| 531 | 0x09, 0x43, /* Usage (43h), */ |
| 532 | 0x95, 0x30, /* Report Count (48), */ |
| 533 | 0xB1, 0x02, /* Feature (Variable), */ |
| 534 | 0x85, 0xA4, /* Report ID (164), */ |
| 535 | 0x09, 0x44, /* Usage (44h), */ |
| 536 | 0x95, 0x0D, /* Report Count (13), */ |
| 537 | 0xB1, 0x02, /* Feature (Variable), */ |
| 538 | 0x85, 0xA5, /* Report ID (165), */ |
| 539 | 0x09, 0x45, /* Usage (45h), */ |
| 540 | 0x95, 0x15, /* Report Count (21), */ |
| 541 | 0xB1, 0x02, /* Feature (Variable), */ |
| 542 | 0x85, 0xA6, /* Report ID (166), */ |
| 543 | 0x09, 0x46, /* Usage (46h), */ |
| 544 | 0x95, 0x15, /* Report Count (21), */ |
| 545 | 0xB1, 0x02, /* Feature (Variable), */ |
| 546 | 0x85, 0xF0, /* Report ID (240), */ |
| 547 | 0x09, 0x47, /* Usage (47h), */ |
| 548 | 0x95, 0x3F, /* Report Count (63), */ |
| 549 | 0xB1, 0x02, /* Feature (Variable), */ |
| 550 | 0x85, 0xF1, /* Report ID (241), */ |
| 551 | 0x09, 0x48, /* Usage (48h), */ |
| 552 | 0x95, 0x3F, /* Report Count (63), */ |
| 553 | 0xB1, 0x02, /* Feature (Variable), */ |
| 554 | 0x85, 0xF2, /* Report ID (242), */ |
| 555 | 0x09, 0x49, /* Usage (49h), */ |
| 556 | 0x95, 0x0F, /* Report Count (15), */ |
| 557 | 0xB1, 0x02, /* Feature (Variable), */ |
| 558 | 0x85, 0xA7, /* Report ID (167), */ |
| 559 | 0x09, 0x4A, /* Usage (4Ah), */ |
| 560 | 0x95, 0x01, /* Report Count (1), */ |
| 561 | 0xB1, 0x02, /* Feature (Variable), */ |
| 562 | 0x85, 0xA8, /* Report ID (168), */ |
| 563 | 0x09, 0x4B, /* Usage (4Bh), */ |
| 564 | 0x95, 0x01, /* Report Count (1), */ |
| 565 | 0xB1, 0x02, /* Feature (Variable), */ |
| 566 | 0x85, 0xA9, /* Report ID (169), */ |
| 567 | 0x09, 0x4C, /* Usage (4Ch), */ |
| 568 | 0x95, 0x08, /* Report Count (8), */ |
| 569 | 0xB1, 0x02, /* Feature (Variable), */ |
| 570 | 0x85, 0xAA, /* Report ID (170), */ |
| 571 | 0x09, 0x4E, /* Usage (4Eh), */ |
| 572 | 0x95, 0x01, /* Report Count (1), */ |
| 573 | 0xB1, 0x02, /* Feature (Variable), */ |
| 574 | 0x85, 0xAB, /* Report ID (171), */ |
| 575 | 0x09, 0x4F, /* Usage (4Fh), */ |
| 576 | 0x95, 0x39, /* Report Count (57), */ |
| 577 | 0xB1, 0x02, /* Feature (Variable), */ |
| 578 | 0x85, 0xAC, /* Report ID (172), */ |
| 579 | 0x09, 0x50, /* Usage (50h), */ |
| 580 | 0x95, 0x39, /* Report Count (57), */ |
| 581 | 0xB1, 0x02, /* Feature (Variable), */ |
| 582 | 0x85, 0xAD, /* Report ID (173), */ |
| 583 | 0x09, 0x51, /* Usage (51h), */ |
| 584 | 0x95, 0x0B, /* Report Count (11), */ |
| 585 | 0xB1, 0x02, /* Feature (Variable), */ |
| 586 | 0x85, 0xAE, /* Report ID (174), */ |
| 587 | 0x09, 0x52, /* Usage (52h), */ |
| 588 | 0x95, 0x01, /* Report Count (1), */ |
| 589 | 0xB1, 0x02, /* Feature (Variable), */ |
| 590 | 0x85, 0xAF, /* Report ID (175), */ |
| 591 | 0x09, 0x53, /* Usage (53h), */ |
| 592 | 0x95, 0x02, /* Report Count (2), */ |
| 593 | 0xB1, 0x02, /* Feature (Variable), */ |
| 594 | 0x85, 0xB0, /* Report ID (176), */ |
| 595 | 0x09, 0x54, /* Usage (54h), */ |
| 596 | 0x95, 0x3F, /* Report Count (63), */ |
| 597 | 0xB1, 0x02, /* Feature (Variable), */ |
| 598 | 0xC0 /* End Collection */ |
Frank Praznik | ed19d8c | 2014-01-16 21:43:12 -0500 | [diff] [blame] | 599 | }; |
| 600 | |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 601 | /* |
| 602 | * The default behavior of the Dualshock 4 is to send reports using report |
Frank Praznik | 077147a | 2014-09-14 11:56:39 -0400 | [diff] [blame] | 603 | * type 1 when running over Bluetooth. However, when feature report 2 is |
| 604 | * requested during the controller initialization it starts sending input |
| 605 | * reports in report 17. Since report 17 is undefined in the default HID |
Frank Praznik | d829674 | 2014-02-05 20:03:45 -0500 | [diff] [blame] | 606 | * descriptor the button and axis definitions must be moved to report 17 or |
Frank Praznik | 077147a | 2014-09-14 11:56:39 -0400 | [diff] [blame] | 607 | * the HID layer won't process the received input. |
Frank Praznik | d829674 | 2014-02-05 20:03:45 -0500 | [diff] [blame] | 608 | */ |
| 609 | static u8 dualshock4_bt_rdesc[] = { |
| 610 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 611 | 0x09, 0x05, /* Usage (Gamepad), */ |
| 612 | 0xA1, 0x01, /* Collection (Application), */ |
| 613 | 0x85, 0x01, /* Report ID (1), */ |
| 614 | 0x75, 0x08, /* Report Size (8), */ |
| 615 | 0x95, 0x0A, /* Report Count (9), */ |
| 616 | 0x81, 0x02, /* Input (Variable), */ |
| 617 | 0x06, 0x04, 0xFF, /* Usage Page (FF04h), */ |
| 618 | 0x85, 0x02, /* Report ID (2), */ |
| 619 | 0x09, 0x24, /* Usage (24h), */ |
| 620 | 0x95, 0x24, /* Report Count (36), */ |
| 621 | 0xB1, 0x02, /* Feature (Variable), */ |
| 622 | 0x85, 0xA3, /* Report ID (163), */ |
| 623 | 0x09, 0x25, /* Usage (25h), */ |
| 624 | 0x95, 0x30, /* Report Count (48), */ |
| 625 | 0xB1, 0x02, /* Feature (Variable), */ |
| 626 | 0x85, 0x05, /* Report ID (5), */ |
| 627 | 0x09, 0x26, /* Usage (26h), */ |
| 628 | 0x95, 0x28, /* Report Count (40), */ |
| 629 | 0xB1, 0x02, /* Feature (Variable), */ |
| 630 | 0x85, 0x06, /* Report ID (6), */ |
| 631 | 0x09, 0x27, /* Usage (27h), */ |
| 632 | 0x95, 0x34, /* Report Count (52), */ |
| 633 | 0xB1, 0x02, /* Feature (Variable), */ |
| 634 | 0x85, 0x07, /* Report ID (7), */ |
| 635 | 0x09, 0x28, /* Usage (28h), */ |
| 636 | 0x95, 0x30, /* Report Count (48), */ |
| 637 | 0xB1, 0x02, /* Feature (Variable), */ |
| 638 | 0x85, 0x08, /* Report ID (8), */ |
| 639 | 0x09, 0x29, /* Usage (29h), */ |
| 640 | 0x95, 0x2F, /* Report Count (47), */ |
| 641 | 0xB1, 0x02, /* Feature (Variable), */ |
| 642 | 0x06, 0x03, 0xFF, /* Usage Page (FF03h), */ |
| 643 | 0x85, 0x03, /* Report ID (3), */ |
| 644 | 0x09, 0x21, /* Usage (21h), */ |
| 645 | 0x95, 0x26, /* Report Count (38), */ |
| 646 | 0xB1, 0x02, /* Feature (Variable), */ |
| 647 | 0x85, 0x04, /* Report ID (4), */ |
| 648 | 0x09, 0x22, /* Usage (22h), */ |
| 649 | 0x95, 0x2E, /* Report Count (46), */ |
| 650 | 0xB1, 0x02, /* Feature (Variable), */ |
| 651 | 0x85, 0xF0, /* Report ID (240), */ |
| 652 | 0x09, 0x47, /* Usage (47h), */ |
| 653 | 0x95, 0x3F, /* Report Count (63), */ |
| 654 | 0xB1, 0x02, /* Feature (Variable), */ |
| 655 | 0x85, 0xF1, /* Report ID (241), */ |
| 656 | 0x09, 0x48, /* Usage (48h), */ |
| 657 | 0x95, 0x3F, /* Report Count (63), */ |
| 658 | 0xB1, 0x02, /* Feature (Variable), */ |
| 659 | 0x85, 0xF2, /* Report ID (242), */ |
| 660 | 0x09, 0x49, /* Usage (49h), */ |
| 661 | 0x95, 0x0F, /* Report Count (15), */ |
| 662 | 0xB1, 0x02, /* Feature (Variable), */ |
| 663 | 0x85, 0x11, /* Report ID (17), */ |
| 664 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 665 | 0x09, 0x20, /* Usage (20h), */ |
| 666 | 0x95, 0x02, /* Report Count (2), */ |
| 667 | 0x81, 0x02, /* Input (Variable), */ |
| 668 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 669 | 0x09, 0x30, /* Usage (X), */ |
| 670 | 0x09, 0x31, /* Usage (Y), */ |
| 671 | 0x09, 0x32, /* Usage (Z), */ |
| 672 | 0x09, 0x35, /* Usage (Rz), */ |
| 673 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 674 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
| 675 | 0x75, 0x08, /* Report Size (8), */ |
| 676 | 0x95, 0x04, /* Report Count (4), */ |
| 677 | 0x81, 0x02, /* Input (Variable), */ |
| 678 | 0x09, 0x39, /* Usage (Hat Switch), */ |
| 679 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 680 | 0x25, 0x07, /* Logical Maximum (7), */ |
| 681 | 0x75, 0x04, /* Report Size (4), */ |
| 682 | 0x95, 0x01, /* Report Count (1), */ |
| 683 | 0x81, 0x42, /* Input (Variable, Null State), */ |
| 684 | 0x05, 0x09, /* Usage Page (Button), */ |
| 685 | 0x19, 0x01, /* Usage Minimum (01h), */ |
| 686 | 0x29, 0x0E, /* Usage Maximum (0Eh), */ |
| 687 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 688 | 0x25, 0x01, /* Logical Maximum (1), */ |
| 689 | 0x75, 0x01, /* Report Size (1), */ |
| 690 | 0x95, 0x0E, /* Report Count (14), */ |
| 691 | 0x81, 0x02, /* Input (Variable), */ |
| 692 | 0x75, 0x06, /* Report Size (6), */ |
| 693 | 0x95, 0x01, /* Report Count (1), */ |
| 694 | 0x81, 0x01, /* Input (Constant), */ |
| 695 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 696 | 0x09, 0x33, /* Usage (Rx), */ |
| 697 | 0x09, 0x34, /* Usage (Ry), */ |
| 698 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 699 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
| 700 | 0x75, 0x08, /* Report Size (8), */ |
| 701 | 0x95, 0x02, /* Report Count (2), */ |
| 702 | 0x81, 0x02, /* Input (Variable), */ |
| 703 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 704 | 0x09, 0x20, /* Usage (20h), */ |
| 705 | 0x95, 0x03, /* Report Count (3), */ |
| 706 | 0x81, 0x02, /* Input (Variable), */ |
| 707 | 0x05, 0x01, /* Usage Page (Desktop), */ |
| 708 | 0x19, 0x40, /* Usage Minimum (40h), */ |
| 709 | 0x29, 0x42, /* Usage Maximum (42h), */ |
| 710 | 0x16, 0x00, 0x80, /* Logical Minimum (-32768), */ |
| 711 | 0x26, 0x00, 0x7F, /* Logical Maximum (32767), */ |
| 712 | 0x75, 0x10, /* Report Size (16), */ |
| 713 | 0x95, 0x03, /* Report Count (3), */ |
| 714 | 0x81, 0x02, /* Input (Variable), */ |
| 715 | 0x19, 0x43, /* Usage Minimum (43h), */ |
| 716 | 0x29, 0x45, /* Usage Maximum (45h), */ |
Frank Praznik | fb291cb | 2014-09-14 11:56:38 -0400 | [diff] [blame] | 717 | 0x16, 0x00, 0xE0, /* Logical Minimum (-8192), */ |
| 718 | 0x26, 0xFF, 0x1F, /* Logical Maximum (8191), */ |
Frank Praznik | d829674 | 2014-02-05 20:03:45 -0500 | [diff] [blame] | 719 | 0x95, 0x03, /* Report Count (3), */ |
| 720 | 0x81, 0x02, /* Input (Variable), */ |
| 721 | 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ |
| 722 | 0x09, 0x20, /* Usage (20h), */ |
| 723 | 0x15, 0x00, /* Logical Minimum (0), */ |
| 724 | 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ |
| 725 | 0x75, 0x08, /* Report Size (8), */ |
| 726 | 0x95, 0x31, /* Report Count (51), */ |
| 727 | 0x81, 0x02, /* Input (Variable), */ |
| 728 | 0x09, 0x21, /* Usage (21h), */ |
| 729 | 0x75, 0x08, /* Report Size (8), */ |
| 730 | 0x95, 0x4D, /* Report Count (77), */ |
| 731 | 0x91, 0x02, /* Output (Variable), */ |
| 732 | 0x85, 0x12, /* Report ID (18), */ |
| 733 | 0x09, 0x22, /* Usage (22h), */ |
| 734 | 0x95, 0x8D, /* Report Count (141), */ |
| 735 | 0x81, 0x02, /* Input (Variable), */ |
| 736 | 0x09, 0x23, /* Usage (23h), */ |
| 737 | 0x91, 0x02, /* Output (Variable), */ |
| 738 | 0x85, 0x13, /* Report ID (19), */ |
| 739 | 0x09, 0x24, /* Usage (24h), */ |
| 740 | 0x95, 0xCD, /* Report Count (205), */ |
| 741 | 0x81, 0x02, /* Input (Variable), */ |
| 742 | 0x09, 0x25, /* Usage (25h), */ |
| 743 | 0x91, 0x02, /* Output (Variable), */ |
| 744 | 0x85, 0x14, /* Report ID (20), */ |
| 745 | 0x09, 0x26, /* Usage (26h), */ |
| 746 | 0x96, 0x0D, 0x01, /* Report Count (269), */ |
| 747 | 0x81, 0x02, /* Input (Variable), */ |
| 748 | 0x09, 0x27, /* Usage (27h), */ |
| 749 | 0x91, 0x02, /* Output (Variable), */ |
| 750 | 0x85, 0x15, /* Report ID (21), */ |
| 751 | 0x09, 0x28, /* Usage (28h), */ |
| 752 | 0x96, 0x4D, 0x01, /* Report Count (333), */ |
| 753 | 0x81, 0x02, /* Input (Variable), */ |
| 754 | 0x09, 0x29, /* Usage (29h), */ |
| 755 | 0x91, 0x02, /* Output (Variable), */ |
| 756 | 0x85, 0x16, /* Report ID (22), */ |
| 757 | 0x09, 0x2A, /* Usage (2Ah), */ |
| 758 | 0x96, 0x8D, 0x01, /* Report Count (397), */ |
| 759 | 0x81, 0x02, /* Input (Variable), */ |
| 760 | 0x09, 0x2B, /* Usage (2Bh), */ |
| 761 | 0x91, 0x02, /* Output (Variable), */ |
| 762 | 0x85, 0x17, /* Report ID (23), */ |
| 763 | 0x09, 0x2C, /* Usage (2Ch), */ |
| 764 | 0x96, 0xCD, 0x01, /* Report Count (461), */ |
| 765 | 0x81, 0x02, /* Input (Variable), */ |
| 766 | 0x09, 0x2D, /* Usage (2Dh), */ |
| 767 | 0x91, 0x02, /* Output (Variable), */ |
| 768 | 0x85, 0x18, /* Report ID (24), */ |
| 769 | 0x09, 0x2E, /* Usage (2Eh), */ |
| 770 | 0x96, 0x0D, 0x02, /* Report Count (525), */ |
| 771 | 0x81, 0x02, /* Input (Variable), */ |
| 772 | 0x09, 0x2F, /* Usage (2Fh), */ |
| 773 | 0x91, 0x02, /* Output (Variable), */ |
| 774 | 0x85, 0x19, /* Report ID (25), */ |
| 775 | 0x09, 0x30, /* Usage (30h), */ |
| 776 | 0x96, 0x22, 0x02, /* Report Count (546), */ |
| 777 | 0x81, 0x02, /* Input (Variable), */ |
| 778 | 0x09, 0x31, /* Usage (31h), */ |
| 779 | 0x91, 0x02, /* Output (Variable), */ |
| 780 | 0x06, 0x80, 0xFF, /* Usage Page (FF80h), */ |
| 781 | 0x85, 0x82, /* Report ID (130), */ |
| 782 | 0x09, 0x22, /* Usage (22h), */ |
| 783 | 0x95, 0x3F, /* Report Count (63), */ |
| 784 | 0xB1, 0x02, /* Feature (Variable), */ |
| 785 | 0x85, 0x83, /* Report ID (131), */ |
| 786 | 0x09, 0x23, /* Usage (23h), */ |
| 787 | 0xB1, 0x02, /* Feature (Variable), */ |
| 788 | 0x85, 0x84, /* Report ID (132), */ |
| 789 | 0x09, 0x24, /* Usage (24h), */ |
| 790 | 0xB1, 0x02, /* Feature (Variable), */ |
| 791 | 0x85, 0x90, /* Report ID (144), */ |
| 792 | 0x09, 0x30, /* Usage (30h), */ |
| 793 | 0xB1, 0x02, /* Feature (Variable), */ |
| 794 | 0x85, 0x91, /* Report ID (145), */ |
| 795 | 0x09, 0x31, /* Usage (31h), */ |
| 796 | 0xB1, 0x02, /* Feature (Variable), */ |
| 797 | 0x85, 0x92, /* Report ID (146), */ |
| 798 | 0x09, 0x32, /* Usage (32h), */ |
| 799 | 0xB1, 0x02, /* Feature (Variable), */ |
| 800 | 0x85, 0x93, /* Report ID (147), */ |
| 801 | 0x09, 0x33, /* Usage (33h), */ |
| 802 | 0xB1, 0x02, /* Feature (Variable), */ |
| 803 | 0x85, 0xA0, /* Report ID (160), */ |
| 804 | 0x09, 0x40, /* Usage (40h), */ |
| 805 | 0xB1, 0x02, /* Feature (Variable), */ |
| 806 | 0x85, 0xA4, /* Report ID (164), */ |
| 807 | 0x09, 0x44, /* Usage (44h), */ |
| 808 | 0xB1, 0x02, /* Feature (Variable), */ |
| 809 | 0xC0 /* End Collection */ |
| 810 | }; |
| 811 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 812 | static __u8 ps3remote_rdesc[] = { |
| 813 | 0x05, 0x01, /* GUsagePage Generic Desktop */ |
| 814 | 0x09, 0x05, /* LUsage 0x05 [Game Pad] */ |
| 815 | 0xA1, 0x01, /* MCollection Application (mouse, keyboard) */ |
| 816 | |
| 817 | /* Use collection 1 for joypad buttons */ |
| 818 | 0xA1, 0x02, /* MCollection Logical (interrelated data) */ |
| 819 | |
| 820 | /* Ignore the 1st byte, maybe it is used for a controller |
| 821 | * number but it's not needed for correct operation */ |
| 822 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 823 | 0x95, 0x01, /* GReportCount 0x01 [1] */ |
| 824 | 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */ |
| 825 | |
| 826 | /* Bytes from 2nd to 4th are a bitmap for joypad buttons, for these |
| 827 | * buttons multiple keypresses are allowed */ |
| 828 | 0x05, 0x09, /* GUsagePage Button */ |
| 829 | 0x19, 0x01, /* LUsageMinimum 0x01 [Button 1 (primary/trigger)] */ |
| 830 | 0x29, 0x18, /* LUsageMaximum 0x18 [Button 24] */ |
| 831 | 0x14, /* GLogicalMinimum [0] */ |
| 832 | 0x25, 0x01, /* GLogicalMaximum 0x01 [1] */ |
| 833 | 0x75, 0x01, /* GReportSize 0x01 [1] */ |
| 834 | 0x95, 0x18, /* GReportCount 0x18 [24] */ |
| 835 | 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */ |
| 836 | |
| 837 | 0xC0, /* MEndCollection */ |
| 838 | |
| 839 | /* Use collection 2 for remote control buttons */ |
| 840 | 0xA1, 0x02, /* MCollection Logical (interrelated data) */ |
| 841 | |
| 842 | /* 5th byte is used for remote control buttons */ |
| 843 | 0x05, 0x09, /* GUsagePage Button */ |
| 844 | 0x18, /* LUsageMinimum [No button pressed] */ |
| 845 | 0x29, 0xFE, /* LUsageMaximum 0xFE [Button 254] */ |
| 846 | 0x14, /* GLogicalMinimum [0] */ |
| 847 | 0x26, 0xFE, 0x00, /* GLogicalMaximum 0x00FE [254] */ |
| 848 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 849 | 0x95, 0x01, /* GReportCount 0x01 [1] */ |
| 850 | 0x80, /* MInput */ |
| 851 | |
| 852 | /* Ignore bytes from 6th to 11th, 6th to 10th are always constant at |
| 853 | * 0xff and 11th is for press indication */ |
| 854 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 855 | 0x95, 0x06, /* GReportCount 0x06 [6] */ |
| 856 | 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */ |
| 857 | |
| 858 | /* 12th byte is for battery strength */ |
| 859 | 0x05, 0x06, /* GUsagePage Generic Device Controls */ |
| 860 | 0x09, 0x20, /* LUsage 0x20 [Battery Strength] */ |
| 861 | 0x14, /* GLogicalMinimum [0] */ |
| 862 | 0x25, 0x05, /* GLogicalMaximum 0x05 [5] */ |
| 863 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 864 | 0x95, 0x01, /* GReportCount 0x01 [1] */ |
| 865 | 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */ |
| 866 | |
| 867 | 0xC0, /* MEndCollection */ |
| 868 | |
| 869 | 0xC0 /* MEndCollection [Game Pad] */ |
| 870 | }; |
| 871 | |
| 872 | static const unsigned int ps3remote_keymap_joypad_buttons[] = { |
| 873 | [0x01] = KEY_SELECT, |
| 874 | [0x02] = BTN_THUMBL, /* L3 */ |
| 875 | [0x03] = BTN_THUMBR, /* R3 */ |
| 876 | [0x04] = BTN_START, |
| 877 | [0x05] = KEY_UP, |
| 878 | [0x06] = KEY_RIGHT, |
| 879 | [0x07] = KEY_DOWN, |
| 880 | [0x08] = KEY_LEFT, |
| 881 | [0x09] = BTN_TL2, /* L2 */ |
| 882 | [0x0a] = BTN_TR2, /* R2 */ |
| 883 | [0x0b] = BTN_TL, /* L1 */ |
| 884 | [0x0c] = BTN_TR, /* R1 */ |
| 885 | [0x0d] = KEY_OPTION, /* options/triangle */ |
| 886 | [0x0e] = KEY_BACK, /* back/circle */ |
| 887 | [0x0f] = BTN_0, /* cross */ |
| 888 | [0x10] = KEY_SCREEN, /* view/square */ |
| 889 | [0x11] = KEY_HOMEPAGE, /* PS button */ |
| 890 | [0x14] = KEY_ENTER, |
| 891 | }; |
| 892 | static const unsigned int ps3remote_keymap_remote_buttons[] = { |
| 893 | [0x00] = KEY_1, |
| 894 | [0x01] = KEY_2, |
| 895 | [0x02] = KEY_3, |
| 896 | [0x03] = KEY_4, |
| 897 | [0x04] = KEY_5, |
| 898 | [0x05] = KEY_6, |
| 899 | [0x06] = KEY_7, |
| 900 | [0x07] = KEY_8, |
| 901 | [0x08] = KEY_9, |
| 902 | [0x09] = KEY_0, |
| 903 | [0x0e] = KEY_ESC, /* return */ |
| 904 | [0x0f] = KEY_CLEAR, |
| 905 | [0x16] = KEY_EJECTCD, |
| 906 | [0x1a] = KEY_MENU, /* top menu */ |
| 907 | [0x28] = KEY_TIME, |
| 908 | [0x30] = KEY_PREVIOUS, |
| 909 | [0x31] = KEY_NEXT, |
| 910 | [0x32] = KEY_PLAY, |
| 911 | [0x33] = KEY_REWIND, /* scan back */ |
| 912 | [0x34] = KEY_FORWARD, /* scan forward */ |
| 913 | [0x38] = KEY_STOP, |
| 914 | [0x39] = KEY_PAUSE, |
| 915 | [0x40] = KEY_CONTEXT_MENU, /* pop up/menu */ |
| 916 | [0x60] = KEY_FRAMEBACK, /* slow/step back */ |
| 917 | [0x61] = KEY_FRAMEFORWARD, /* slow/step forward */ |
| 918 | [0x63] = KEY_SUBTITLE, |
| 919 | [0x64] = KEY_AUDIO, |
| 920 | [0x65] = KEY_ANGLE, |
| 921 | [0x70] = KEY_INFO, /* display */ |
| 922 | [0x80] = KEY_BLUE, |
| 923 | [0x81] = KEY_RED, |
| 924 | [0x82] = KEY_GREEN, |
| 925 | [0x83] = KEY_YELLOW, |
| 926 | }; |
| 927 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 928 | static const unsigned int buzz_keymap[] = { |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 929 | /* |
| 930 | * The controller has 4 remote buzzers, each with one LED and 5 |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 931 | * buttons. |
| 932 | * |
| 933 | * We use the mapping chosen by the controller, which is: |
| 934 | * |
| 935 | * Key Offset |
| 936 | * ------------------- |
| 937 | * Buzz 1 |
| 938 | * Blue 5 |
| 939 | * Orange 4 |
| 940 | * Green 3 |
| 941 | * Yellow 2 |
| 942 | * |
| 943 | * So, for example, the orange button on the third buzzer is mapped to |
| 944 | * BTN_TRIGGER_HAPPY14 |
| 945 | */ |
| 946 | [ 1] = BTN_TRIGGER_HAPPY1, |
| 947 | [ 2] = BTN_TRIGGER_HAPPY2, |
| 948 | [ 3] = BTN_TRIGGER_HAPPY3, |
| 949 | [ 4] = BTN_TRIGGER_HAPPY4, |
| 950 | [ 5] = BTN_TRIGGER_HAPPY5, |
| 951 | [ 6] = BTN_TRIGGER_HAPPY6, |
| 952 | [ 7] = BTN_TRIGGER_HAPPY7, |
| 953 | [ 8] = BTN_TRIGGER_HAPPY8, |
| 954 | [ 9] = BTN_TRIGGER_HAPPY9, |
| 955 | [10] = BTN_TRIGGER_HAPPY10, |
| 956 | [11] = BTN_TRIGGER_HAPPY11, |
| 957 | [12] = BTN_TRIGGER_HAPPY12, |
| 958 | [13] = BTN_TRIGGER_HAPPY13, |
| 959 | [14] = BTN_TRIGGER_HAPPY14, |
| 960 | [15] = BTN_TRIGGER_HAPPY15, |
| 961 | [16] = BTN_TRIGGER_HAPPY16, |
| 962 | [17] = BTN_TRIGGER_HAPPY17, |
| 963 | [18] = BTN_TRIGGER_HAPPY18, |
| 964 | [19] = BTN_TRIGGER_HAPPY19, |
| 965 | [20] = BTN_TRIGGER_HAPPY20, |
| 966 | }; |
| 967 | |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 968 | static enum power_supply_property sony_battery_props[] = { |
| 969 | POWER_SUPPLY_PROP_PRESENT, |
| 970 | POWER_SUPPLY_PROP_CAPACITY, |
| 971 | POWER_SUPPLY_PROP_SCOPE, |
| 972 | POWER_SUPPLY_PROP_STATUS, |
| 973 | }; |
| 974 | |
Frank Praznik | 55d3b66 | 2014-04-14 10:11:32 -0400 | [diff] [blame] | 975 | struct sixaxis_led { |
| 976 | __u8 time_enabled; /* the total time the led is active (0xff means forever) */ |
| 977 | __u8 duty_length; /* how long a cycle is in deciseconds (0 means "really fast") */ |
| 978 | __u8 enabled; |
| 979 | __u8 duty_off; /* % of duty_length the led is off (0xff means 100%) */ |
| 980 | __u8 duty_on; /* % of duty_length the led is on (0xff mean 100%) */ |
| 981 | } __packed; |
| 982 | |
| 983 | struct sixaxis_rumble { |
| 984 | __u8 padding; |
| 985 | __u8 right_duration; /* Right motor duration (0xff means forever) */ |
| 986 | __u8 right_motor_on; /* Right (small) motor on/off, only supports values of 0 or 1 (off/on) */ |
| 987 | __u8 left_duration; /* Left motor duration (0xff means forever) */ |
| 988 | __u8 left_motor_force; /* left (large) motor, supports force values from 0 to 255 */ |
| 989 | } __packed; |
| 990 | |
| 991 | struct sixaxis_output_report { |
| 992 | __u8 report_id; |
| 993 | struct sixaxis_rumble rumble; |
| 994 | __u8 padding[4]; |
| 995 | __u8 leds_bitmap; /* bitmap of enabled LEDs: LED_1 = 0x02, LED_2 = 0x04, ... */ |
| 996 | struct sixaxis_led led[4]; /* LEDx at (4 - x) */ |
| 997 | struct sixaxis_led _reserved; /* LED5, not actually soldered */ |
| 998 | } __packed; |
| 999 | |
| 1000 | union sixaxis_output_report_01 { |
| 1001 | struct sixaxis_output_report data; |
| 1002 | __u8 buf[36]; |
| 1003 | }; |
| 1004 | |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 1005 | struct motion_output_report_02 { |
| 1006 | u8 type, zero; |
| 1007 | u8 r, g, b; |
| 1008 | u8 zero2; |
| 1009 | u8 rumble; |
| 1010 | }; |
| 1011 | |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1012 | #define DS4_REPORT_0x02_SIZE 37 |
| 1013 | #define DS4_REPORT_0x05_SIZE 32 |
| 1014 | #define DS4_REPORT_0x11_SIZE 78 |
| 1015 | #define DS4_REPORT_0x81_SIZE 7 |
Antonio Ospite | 29b691a | 2015-02-16 18:12:21 +0100 | [diff] [blame] | 1016 | #define SIXAXIS_REPORT_0xF2_SIZE 17 |
Antonio Ospite | a85d67b | 2015-02-16 18:12:22 +0100 | [diff] [blame] | 1017 | #define SIXAXIS_REPORT_0xF5_SIZE 8 |
Simon Wood | 41d2d42 | 2015-06-09 21:27:06 -0600 | [diff] [blame] | 1018 | #define MOTION_REPORT_0x02_SIZE 49 |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1019 | |
Jiri Kosina | 8b402c9 | 2015-02-23 11:15:44 +0100 | [diff] [blame] | 1020 | static DEFINE_SPINLOCK(sony_dev_list_lock); |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 1021 | static LIST_HEAD(sony_device_list); |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 1022 | static DEFINE_IDA(sony_device_id_allocator); |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 1023 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1024 | struct sony_sc { |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1025 | spinlock_t lock; |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 1026 | struct list_head list_node; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1027 | struct hid_device *hdev; |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 1028 | struct led_classdev *leds[MAX_LEDS]; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1029 | unsigned long quirks; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1030 | struct work_struct state_worker; |
Frank Praznik | d8aaccd | 2015-11-11 09:49:37 -0500 | [diff] [blame] | 1031 | void(*send_output_report)(struct sony_sc*); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1032 | struct power_supply *battery; |
| 1033 | struct power_supply_desc battery_desc; |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 1034 | int device_id; |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1035 | __u8 *output_report_dmabuf; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1036 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 1037 | #ifdef CONFIG_SONY_FF |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 1038 | __u8 left; |
| 1039 | __u8 right; |
| 1040 | #endif |
| 1041 | |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 1042 | __u8 mac_address[6]; |
Frank Praznik | 5f5750d | 2014-02-19 13:09:22 -0500 | [diff] [blame] | 1043 | __u8 worker_initialized; |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1044 | __u8 cable_state; |
| 1045 | __u8 battery_charging; |
| 1046 | __u8 battery_capacity; |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 1047 | __u8 led_state[MAX_LEDS]; |
Frank Praznik | decd946 | 2015-11-11 09:49:38 -0500 | [diff] [blame] | 1048 | __u8 resume_led_state[MAX_LEDS]; |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1049 | __u8 led_delay_on[MAX_LEDS]; |
| 1050 | __u8 led_delay_off[MAX_LEDS]; |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 1051 | __u8 led_count; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1052 | }; |
| 1053 | |
Antonio Ospite | c607fb8 | 2014-06-24 13:28:41 +0200 | [diff] [blame] | 1054 | static __u8 *sixaxis_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 1055 | unsigned int *rsize) |
| 1056 | { |
| 1057 | *rsize = sizeof(sixaxis_rdesc); |
| 1058 | return sixaxis_rdesc; |
| 1059 | } |
| 1060 | |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 1061 | static u8 *motion_fixup(struct hid_device *hdev, u8 *rdesc, |
| 1062 | unsigned int *rsize) |
| 1063 | { |
| 1064 | *rsize = sizeof(motion_rdesc); |
| 1065 | return motion_rdesc; |
| 1066 | } |
| 1067 | |
Simon Wood | b2723eb | 2015-06-17 00:08:53 -0600 | [diff] [blame] | 1068 | static u8 *navigation_fixup(struct hid_device *hdev, u8 *rdesc, |
| 1069 | unsigned int *rsize) |
| 1070 | { |
| 1071 | *rsize = sizeof(navigation_rdesc); |
| 1072 | return navigation_rdesc; |
| 1073 | } |
| 1074 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 1075 | static __u8 *ps3remote_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 1076 | unsigned int *rsize) |
| 1077 | { |
| 1078 | *rsize = sizeof(ps3remote_rdesc); |
| 1079 | return ps3remote_rdesc; |
| 1080 | } |
| 1081 | |
| 1082 | static int ps3remote_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 1083 | struct hid_field *field, struct hid_usage *usage, |
| 1084 | unsigned long **bit, int *max) |
| 1085 | { |
| 1086 | unsigned int key = usage->hid & HID_USAGE; |
| 1087 | |
| 1088 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) |
| 1089 | return -1; |
| 1090 | |
| 1091 | switch (usage->collection_index) { |
| 1092 | case 1: |
| 1093 | if (key >= ARRAY_SIZE(ps3remote_keymap_joypad_buttons)) |
| 1094 | return -1; |
| 1095 | |
| 1096 | key = ps3remote_keymap_joypad_buttons[key]; |
| 1097 | if (!key) |
| 1098 | return -1; |
| 1099 | break; |
| 1100 | case 2: |
| 1101 | if (key >= ARRAY_SIZE(ps3remote_keymap_remote_buttons)) |
| 1102 | return -1; |
| 1103 | |
| 1104 | key = ps3remote_keymap_remote_buttons[key]; |
| 1105 | if (!key) |
| 1106 | return -1; |
| 1107 | break; |
| 1108 | default: |
| 1109 | return -1; |
| 1110 | } |
| 1111 | |
| 1112 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key); |
| 1113 | return 1; |
| 1114 | } |
| 1115 | |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 1116 | static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 1117 | unsigned int *rsize) |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1118 | { |
| 1119 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 1120 | |
Fernando Luis Vázquez Cao | 99d2490 | 2013-01-22 15:20:38 +0900 | [diff] [blame] | 1121 | /* |
| 1122 | * Some Sony RF receivers wrongly declare the mouse pointer as a |
| 1123 | * a constant non-data variable. |
| 1124 | */ |
| 1125 | if ((sc->quirks & VAIO_RDESC_CONSTANT) && *rsize >= 56 && |
| 1126 | /* usage page: generic desktop controls */ |
| 1127 | /* rdesc[0] == 0x05 && rdesc[1] == 0x01 && */ |
| 1128 | /* usage: mouse */ |
| 1129 | rdesc[2] == 0x09 && rdesc[3] == 0x02 && |
| 1130 | /* input (usage page for x,y axes): constant, variable, relative */ |
| 1131 | rdesc[54] == 0x81 && rdesc[55] == 0x07) { |
Fernando Luis Vázquez Cao | a4649184 | 2013-01-15 19:40:48 +0900 | [diff] [blame] | 1132 | hid_info(hdev, "Fixing up Sony RF Receiver report descriptor\n"); |
Fernando Luis Vázquez Cao | 99d2490 | 2013-01-22 15:20:38 +0900 | [diff] [blame] | 1133 | /* input: data, variable, relative */ |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1134 | rdesc[55] = 0x06; |
| 1135 | } |
Simon Wood | 61ab44b | 2011-06-10 12:00:26 +0200 | [diff] [blame] | 1136 | |
Frank Praznik | ed19d8c | 2014-01-16 21:43:12 -0500 | [diff] [blame] | 1137 | /* |
| 1138 | * The default Dualshock 4 USB descriptor doesn't assign |
| 1139 | * the gyroscope values to corresponding axes so we need a |
| 1140 | * modified one. |
| 1141 | */ |
Frank Praznik | b71b557 | 2015-11-06 15:35:53 -0500 | [diff] [blame] | 1142 | if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) { |
Frank Praznik | ed19d8c | 2014-01-16 21:43:12 -0500 | [diff] [blame] | 1143 | hid_info(hdev, "Using modified Dualshock 4 report descriptor with gyroscope axes\n"); |
| 1144 | rdesc = dualshock4_usb_rdesc; |
| 1145 | *rsize = sizeof(dualshock4_usb_rdesc); |
Frank Praznik | b71b557 | 2015-11-06 15:35:53 -0500 | [diff] [blame] | 1146 | } else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) { |
Frank Praznik | d829674 | 2014-02-05 20:03:45 -0500 | [diff] [blame] | 1147 | hid_info(hdev, "Using modified Dualshock 4 Bluetooth report descriptor\n"); |
| 1148 | rdesc = dualshock4_bt_rdesc; |
| 1149 | *rsize = sizeof(dualshock4_bt_rdesc); |
Frank Praznik | ed19d8c | 2014-01-16 21:43:12 -0500 | [diff] [blame] | 1150 | } |
| 1151 | |
Antonio Ospite | c607fb8 | 2014-06-24 13:28:41 +0200 | [diff] [blame] | 1152 | if (sc->quirks & SIXAXIS_CONTROLLER) |
| 1153 | return sixaxis_fixup(hdev, rdesc, rsize); |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 1154 | |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 1155 | if (sc->quirks & MOTION_CONTROLLER) |
| 1156 | return motion_fixup(hdev, rdesc, rsize); |
| 1157 | |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 1158 | if (sc->quirks & NAVIGATION_CONTROLLER) |
Simon Wood | b2723eb | 2015-06-17 00:08:53 -0600 | [diff] [blame] | 1159 | return navigation_fixup(hdev, rdesc, rsize); |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 1160 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 1161 | if (sc->quirks & PS3REMOTE) |
| 1162 | return ps3remote_fixup(hdev, rdesc, rsize); |
| 1163 | |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 1164 | return rdesc; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 1165 | } |
| 1166 | |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1167 | static void sixaxis_parse_report(struct sony_sc *sc, __u8 *rd, int size) |
| 1168 | { |
| 1169 | static const __u8 sixaxis_battery_capacity[] = { 0, 1, 25, 50, 75, 100 }; |
| 1170 | unsigned long flags; |
Simon Wood | 12e9a6d7 | 2015-06-09 21:27:05 -0600 | [diff] [blame] | 1171 | int offset; |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1172 | __u8 cable_state, battery_capacity, battery_charging; |
| 1173 | |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 1174 | /* |
| 1175 | * The sixaxis is charging if the battery value is 0xee |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1176 | * and it is fully charged if the value is 0xef. |
| 1177 | * It does not report the actual level while charging so it |
| 1178 | * is set to 100% while charging is in progress. |
| 1179 | */ |
Simon Wood | 12e9a6d7 | 2015-06-09 21:27:05 -0600 | [diff] [blame] | 1180 | offset = (sc->quirks & MOTION_CONTROLLER) ? 12 : 30; |
| 1181 | |
| 1182 | if (rd[offset] >= 0xee) { |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1183 | battery_capacity = 100; |
Simon Wood | 12e9a6d7 | 2015-06-09 21:27:05 -0600 | [diff] [blame] | 1184 | battery_charging = !(rd[offset] & 0x01); |
Frank Praznik | 9fddd74 | 2014-08-29 13:11:52 -0400 | [diff] [blame] | 1185 | cable_state = 1; |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1186 | } else { |
Simon Wood | 12e9a6d7 | 2015-06-09 21:27:05 -0600 | [diff] [blame] | 1187 | __u8 index = rd[offset] <= 5 ? rd[offset] : 5; |
Frank Praznik | ac3c9a9 | 2014-02-20 11:36:02 -0500 | [diff] [blame] | 1188 | battery_capacity = sixaxis_battery_capacity[index]; |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1189 | battery_charging = 0; |
Frank Praznik | 9fddd74 | 2014-08-29 13:11:52 -0400 | [diff] [blame] | 1190 | cable_state = 0; |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1191 | } |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1192 | |
| 1193 | spin_lock_irqsave(&sc->lock, flags); |
| 1194 | sc->cable_state = cable_state; |
| 1195 | sc->battery_capacity = battery_capacity; |
| 1196 | sc->battery_charging = battery_charging; |
| 1197 | spin_unlock_irqrestore(&sc->lock, flags); |
| 1198 | } |
| 1199 | |
| 1200 | static void dualshock4_parse_report(struct sony_sc *sc, __u8 *rd, int size) |
| 1201 | { |
Frank Praznik | e560623 | 2014-01-27 10:17:37 -0500 | [diff] [blame] | 1202 | struct hid_input *hidinput = list_entry(sc->hdev->inputs.next, |
| 1203 | struct hid_input, list); |
| 1204 | struct input_dev *input_dev = hidinput->input; |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1205 | unsigned long flags; |
Frank Praznik | 6c5f860 | 2014-02-05 20:03:47 -0500 | [diff] [blame] | 1206 | int n, offset; |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1207 | __u8 cable_state, battery_capacity, battery_charging; |
| 1208 | |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 1209 | /* |
| 1210 | * Battery and touchpad data starts at byte 30 in the USB report and |
Frank Praznik | 6c5f860 | 2014-02-05 20:03:47 -0500 | [diff] [blame] | 1211 | * 32 in Bluetooth report. |
| 1212 | */ |
| 1213 | offset = (sc->quirks & DUALSHOCK4_CONTROLLER_USB) ? 30 : 32; |
| 1214 | |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 1215 | /* |
| 1216 | * The lower 4 bits of byte 30 contain the battery level |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1217 | * and the 5th bit contains the USB cable state. |
| 1218 | */ |
Frank Praznik | 6c5f860 | 2014-02-05 20:03:47 -0500 | [diff] [blame] | 1219 | cable_state = (rd[offset] >> 4) & 0x01; |
| 1220 | battery_capacity = rd[offset] & 0x0F; |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1221 | |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 1222 | /* |
| 1223 | * When a USB power source is connected the battery level ranges from |
Frank Praznik | 6c5f860 | 2014-02-05 20:03:47 -0500 | [diff] [blame] | 1224 | * 0 to 10, and when running on battery power it ranges from 0 to 9. |
| 1225 | * A battery level above 10 when plugged in means charge completed. |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1226 | */ |
Frank Praznik | 6c5f860 | 2014-02-05 20:03:47 -0500 | [diff] [blame] | 1227 | if (!cable_state || battery_capacity > 10) |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1228 | battery_charging = 0; |
| 1229 | else |
| 1230 | battery_charging = 1; |
| 1231 | |
Frank Praznik | 6c5f860 | 2014-02-05 20:03:47 -0500 | [diff] [blame] | 1232 | if (!cable_state) |
| 1233 | battery_capacity++; |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1234 | if (battery_capacity > 10) |
Frank Praznik | 6c5f860 | 2014-02-05 20:03:47 -0500 | [diff] [blame] | 1235 | battery_capacity = 10; |
| 1236 | |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1237 | battery_capacity *= 10; |
| 1238 | |
| 1239 | spin_lock_irqsave(&sc->lock, flags); |
| 1240 | sc->cable_state = cable_state; |
| 1241 | sc->battery_capacity = battery_capacity; |
| 1242 | sc->battery_charging = battery_charging; |
| 1243 | spin_unlock_irqrestore(&sc->lock, flags); |
Frank Praznik | e560623 | 2014-01-27 10:17:37 -0500 | [diff] [blame] | 1244 | |
Frank Praznik | 6c5f860 | 2014-02-05 20:03:47 -0500 | [diff] [blame] | 1245 | offset += 5; |
| 1246 | |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 1247 | /* |
| 1248 | * The Dualshock 4 multi-touch trackpad data starts at offset 35 on USB |
Frank Praznik | 6c5f860 | 2014-02-05 20:03:47 -0500 | [diff] [blame] | 1249 | * and 37 on Bluetooth. |
Frank Praznik | e560623 | 2014-01-27 10:17:37 -0500 | [diff] [blame] | 1250 | * The first 7 bits of the first byte is a counter and bit 8 is a touch |
| 1251 | * indicator that is 0 when pressed and 1 when not pressed. |
| 1252 | * The next 3 bytes are two 12 bit touch coordinates, X and Y. |
| 1253 | * The data for the second touch is in the same format and immediatly |
| 1254 | * follows the data for the first. |
| 1255 | */ |
| 1256 | for (n = 0; n < 2; n++) { |
| 1257 | __u16 x, y; |
| 1258 | |
| 1259 | x = rd[offset+1] | ((rd[offset+2] & 0xF) << 8); |
| 1260 | y = ((rd[offset+2] & 0xF0) >> 4) | (rd[offset+3] << 4); |
| 1261 | |
| 1262 | input_mt_slot(input_dev, n); |
| 1263 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, |
| 1264 | !(rd[offset] >> 7)); |
| 1265 | input_report_abs(input_dev, ABS_MT_POSITION_X, x); |
| 1266 | input_report_abs(input_dev, ABS_MT_POSITION_Y, y); |
| 1267 | |
| 1268 | offset += 4; |
| 1269 | } |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1270 | } |
| 1271 | |
Simon Wood | c9e4d87 | 2011-06-10 12:00:27 +0200 | [diff] [blame] | 1272 | static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, |
| 1273 | __u8 *rd, int size) |
| 1274 | { |
| 1275 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 1276 | |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 1277 | /* |
| 1278 | * Sixaxis HID report has acclerometers/gyro with MSByte first, this |
Simon Wood | c9e4d87 | 2011-06-10 12:00:27 +0200 | [diff] [blame] | 1279 | * has to be BYTE_SWAPPED before passing up to joystick interface |
| 1280 | */ |
Frank Praznik | fee4e2d | 2014-02-18 17:22:01 -0500 | [diff] [blame] | 1281 | if ((sc->quirks & SIXAXIS_CONTROLLER) && rd[0] == 0x01 && size == 49) { |
Frank Praznik | 8f5f0bc | 2015-07-23 19:01:16 -0400 | [diff] [blame] | 1282 | /* |
| 1283 | * When connected via Bluetooth the Sixaxis occasionally sends |
| 1284 | * a report with the second byte 0xff and the rest zeroed. |
| 1285 | * |
| 1286 | * This report does not reflect the actual state of the |
| 1287 | * controller must be ignored to avoid generating false input |
| 1288 | * events. |
| 1289 | */ |
| 1290 | if (rd[1] == 0xff) |
| 1291 | return -EINVAL; |
| 1292 | |
Simon Wood | c9e4d87 | 2011-06-10 12:00:27 +0200 | [diff] [blame] | 1293 | swap(rd[41], rd[42]); |
| 1294 | swap(rd[43], rd[44]); |
| 1295 | swap(rd[45], rd[46]); |
| 1296 | swap(rd[47], rd[48]); |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1297 | |
| 1298 | sixaxis_parse_report(sc, rd, size); |
Simon Wood | 12e9a6d7 | 2015-06-09 21:27:05 -0600 | [diff] [blame] | 1299 | } else if ((sc->quirks & MOTION_CONTROLLER_BT) && rd[0] == 0x01 && size == 49) { |
| 1300 | sixaxis_parse_report(sc, rd, size); |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 1301 | } else if ((sc->quirks & NAVIGATION_CONTROLLER) && rd[0] == 0x01 && |
| 1302 | size == 49) { |
| 1303 | sixaxis_parse_report(sc, rd, size); |
Frank Praznik | 68330d8 | 2014-02-05 20:03:49 -0500 | [diff] [blame] | 1304 | } else if (((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && rd[0] == 0x01 && |
| 1305 | size == 64) || ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) |
| 1306 | && rd[0] == 0x11 && size == 78)) { |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1307 | dualshock4_parse_report(sc, rd, size); |
Simon Wood | c9e4d87 | 2011-06-10 12:00:27 +0200 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | return 0; |
| 1311 | } |
| 1312 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1313 | static int sony_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 1314 | struct hid_field *field, struct hid_usage *usage, |
| 1315 | unsigned long **bit, int *max) |
| 1316 | { |
| 1317 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 1318 | |
| 1319 | if (sc->quirks & BUZZ_CONTROLLER) { |
| 1320 | unsigned int key = usage->hid & HID_USAGE; |
| 1321 | |
| 1322 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) |
| 1323 | return -1; |
| 1324 | |
| 1325 | switch (usage->collection_index) { |
| 1326 | case 1: |
| 1327 | if (key >= ARRAY_SIZE(buzz_keymap)) |
| 1328 | return -1; |
| 1329 | |
| 1330 | key = buzz_keymap[key]; |
| 1331 | if (!key) |
| 1332 | return -1; |
| 1333 | break; |
| 1334 | default: |
| 1335 | return -1; |
| 1336 | } |
| 1337 | |
| 1338 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key); |
| 1339 | return 1; |
| 1340 | } |
| 1341 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 1342 | if (sc->quirks & PS3REMOTE) |
| 1343 | return ps3remote_mapping(hdev, hi, field, usage, bit, max); |
| 1344 | |
Benjamin Tissoires | 6f49801 | 2013-07-24 16:53:07 +0200 | [diff] [blame] | 1345 | /* Let hid-core decide for the others */ |
| 1346 | return 0; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1347 | } |
| 1348 | |
Frank Praznik | ce8efc3 | 2014-09-18 21:15:01 -0400 | [diff] [blame] | 1349 | static int sony_register_touchpad(struct hid_input *hi, int touch_count, |
| 1350 | int w, int h) |
| 1351 | { |
| 1352 | struct input_dev *input_dev = hi->input; |
| 1353 | int ret; |
| 1354 | |
| 1355 | ret = input_mt_init_slots(input_dev, touch_count, 0); |
| 1356 | if (ret < 0) |
| 1357 | return ret; |
| 1358 | |
| 1359 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, w, 0, 0); |
| 1360 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, h, 0, 0); |
| 1361 | |
| 1362 | return 0; |
| 1363 | } |
| 1364 | |
Dmitry Torokhov | 9154301 | 2015-09-29 15:52:59 -0700 | [diff] [blame] | 1365 | static int sony_input_configured(struct hid_device *hdev, |
Frank Praznik | ce8efc3 | 2014-09-18 21:15:01 -0400 | [diff] [blame] | 1366 | struct hid_input *hidinput) |
| 1367 | { |
| 1368 | struct sony_sc *sc = hid_get_drvdata(hdev); |
Dmitry Torokhov | 9154301 | 2015-09-29 15:52:59 -0700 | [diff] [blame] | 1369 | int ret; |
Frank Praznik | ce8efc3 | 2014-09-18 21:15:01 -0400 | [diff] [blame] | 1370 | |
| 1371 | /* |
| 1372 | * The Dualshock 4 touchpad supports 2 touches and has a |
Frank Praznik | 981c5b4 | 2014-09-24 09:38:19 -0400 | [diff] [blame] | 1373 | * resolution of 1920x942 (44.86 dots/mm). |
Frank Praznik | ce8efc3 | 2014-09-18 21:15:01 -0400 | [diff] [blame] | 1374 | */ |
| 1375 | if (sc->quirks & DUALSHOCK4_CONTROLLER) { |
Dmitry Torokhov | 9154301 | 2015-09-29 15:52:59 -0700 | [diff] [blame] | 1376 | ret = sony_register_touchpad(hidinput, 2, 1920, 942); |
| 1377 | if (ret) { |
Frank Praznik | ce8efc3 | 2014-09-18 21:15:01 -0400 | [diff] [blame] | 1378 | hid_err(sc->hdev, |
Dmitry Torokhov | 9154301 | 2015-09-29 15:52:59 -0700 | [diff] [blame] | 1379 | "Unable to initialize multi-touch slots: %d\n", |
| 1380 | ret); |
| 1381 | return ret; |
| 1382 | } |
Frank Praznik | ce8efc3 | 2014-09-18 21:15:01 -0400 | [diff] [blame] | 1383 | } |
Dmitry Torokhov | 9154301 | 2015-09-29 15:52:59 -0700 | [diff] [blame] | 1384 | |
| 1385 | return 0; |
Frank Praznik | ce8efc3 | 2014-09-18 21:15:01 -0400 | [diff] [blame] | 1386 | } |
| 1387 | |
Antonio Ospite | 5710fab | 2011-02-20 18:26:45 +0100 | [diff] [blame] | 1388 | /* |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1389 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller |
| 1390 | * to "operational". Without this, the ps3 controller will not report any |
| 1391 | * events. |
| 1392 | */ |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 1393 | static int sixaxis_set_operational_usb(struct hid_device *hdev) |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1394 | { |
Antonio Ospite | a85d67b | 2015-02-16 18:12:22 +0100 | [diff] [blame] | 1395 | const int buf_size = |
| 1396 | max(SIXAXIS_REPORT_0xF2_SIZE, SIXAXIS_REPORT_0xF5_SIZE); |
Antonio Ospite | 2e701a3 | 2015-02-16 18:12:24 +0100 | [diff] [blame] | 1397 | __u8 *buf; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1398 | int ret; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1399 | |
Antonio Ospite | 2e701a3 | 2015-02-16 18:12:24 +0100 | [diff] [blame] | 1400 | buf = kmalloc(buf_size, GFP_KERNEL); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1401 | if (!buf) |
| 1402 | return -ENOMEM; |
| 1403 | |
Antonio Ospite | a85d67b | 2015-02-16 18:12:22 +0100 | [diff] [blame] | 1404 | ret = hid_hw_raw_request(hdev, 0xf2, buf, SIXAXIS_REPORT_0xF2_SIZE, |
| 1405 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); |
Lauri Kasanen | a7de9b8 | 2015-02-16 15:06:59 +0200 | [diff] [blame] | 1406 | if (ret < 0) { |
| 1407 | hid_err(hdev, "can't set operational mode: step 1\n"); |
| 1408 | goto out; |
| 1409 | } |
Benjamin Tissoires | f204828a | 2013-09-11 22:12:25 +0200 | [diff] [blame] | 1410 | |
Lauri Kasanen | a7de9b8 | 2015-02-16 15:06:59 +0200 | [diff] [blame] | 1411 | /* |
| 1412 | * Some compatible controllers like the Speedlink Strike FX and |
| 1413 | * Gasia need another query plus an USB interrupt to get operational. |
| 1414 | */ |
Antonio Ospite | a85d67b | 2015-02-16 18:12:22 +0100 | [diff] [blame] | 1415 | ret = hid_hw_raw_request(hdev, 0xf5, buf, SIXAXIS_REPORT_0xF5_SIZE, |
| 1416 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); |
Lauri Kasanen | a7de9b8 | 2015-02-16 15:06:59 +0200 | [diff] [blame] | 1417 | if (ret < 0) { |
| 1418 | hid_err(hdev, "can't set operational mode: step 2\n"); |
| 1419 | goto out; |
| 1420 | } |
| 1421 | |
| 1422 | ret = hid_hw_output_report(hdev, buf, 1); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1423 | if (ret < 0) |
Lauri Kasanen | a7de9b8 | 2015-02-16 15:06:59 +0200 | [diff] [blame] | 1424 | hid_err(hdev, "can't set operational mode: step 3\n"); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1425 | |
Lauri Kasanen | a7de9b8 | 2015-02-16 15:06:59 +0200 | [diff] [blame] | 1426 | out: |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1427 | kfree(buf); |
| 1428 | |
| 1429 | return ret; |
| 1430 | } |
| 1431 | |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 1432 | static int sixaxis_set_operational_bt(struct hid_device *hdev) |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 1433 | { |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1434 | static const __u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 }; |
| 1435 | __u8 *buf; |
| 1436 | int ret; |
| 1437 | |
| 1438 | buf = kmemdup(report, sizeof(report), GFP_KERNEL); |
| 1439 | if (!buf) |
| 1440 | return -ENOMEM; |
| 1441 | |
| 1442 | ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report), |
Benjamin Tissoires | b0dd72a | 2014-02-10 12:58:54 -0500 | [diff] [blame] | 1443 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1444 | |
| 1445 | kfree(buf); |
| 1446 | |
| 1447 | return ret; |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 1450 | /* |
| 1451 | * Requesting feature report 0x02 in Bluetooth mode changes the state of the |
Frank Praznik | 68330d8 | 2014-02-05 20:03:49 -0500 | [diff] [blame] | 1452 | * controller so that it sends full input reports of type 0x11. |
| 1453 | */ |
| 1454 | static int dualshock4_set_operational_bt(struct hid_device *hdev) |
| 1455 | { |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1456 | __u8 *buf; |
| 1457 | int ret; |
Frank Praznik | 68330d8 | 2014-02-05 20:03:49 -0500 | [diff] [blame] | 1458 | |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1459 | buf = kmalloc(DS4_REPORT_0x02_SIZE, GFP_KERNEL); |
| 1460 | if (!buf) |
| 1461 | return -ENOMEM; |
| 1462 | |
| 1463 | ret = hid_hw_raw_request(hdev, 0x02, buf, DS4_REPORT_0x02_SIZE, |
Frank Praznik | 68330d8 | 2014-02-05 20:03:49 -0500 | [diff] [blame] | 1464 | HID_FEATURE_REPORT, HID_REQ_GET_REPORT); |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1465 | |
| 1466 | kfree(buf); |
| 1467 | |
| 1468 | return ret; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1469 | } |
| 1470 | |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1471 | static void sixaxis_set_leds_from_id(struct sony_sc *sc) |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 1472 | { |
| 1473 | static const __u8 sixaxis_leds[10][4] = { |
| 1474 | { 0x01, 0x00, 0x00, 0x00 }, |
| 1475 | { 0x00, 0x01, 0x00, 0x00 }, |
| 1476 | { 0x00, 0x00, 0x01, 0x00 }, |
| 1477 | { 0x00, 0x00, 0x00, 0x01 }, |
| 1478 | { 0x01, 0x00, 0x00, 0x01 }, |
| 1479 | { 0x00, 0x01, 0x00, 0x01 }, |
| 1480 | { 0x00, 0x00, 0x01, 0x01 }, |
| 1481 | { 0x01, 0x00, 0x01, 0x01 }, |
| 1482 | { 0x00, 0x01, 0x01, 0x01 }, |
| 1483 | { 0x01, 0x01, 0x01, 0x01 } |
| 1484 | }; |
| 1485 | |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1486 | int id = sc->device_id; |
| 1487 | |
| 1488 | BUILD_BUG_ON(MAX_LEDS < ARRAY_SIZE(sixaxis_leds[0])); |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 1489 | |
| 1490 | if (id < 0) |
| 1491 | return; |
| 1492 | |
| 1493 | id %= 10; |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1494 | memcpy(sc->led_state, sixaxis_leds[id], sizeof(sixaxis_leds[id])); |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 1495 | } |
| 1496 | |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1497 | static void dualshock4_set_leds_from_id(struct sony_sc *sc) |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 1498 | { |
| 1499 | /* The first 4 color/index entries match what the PS4 assigns */ |
| 1500 | static const __u8 color_code[7][3] = { |
| 1501 | /* Blue */ { 0x00, 0x00, 0x01 }, |
| 1502 | /* Red */ { 0x01, 0x00, 0x00 }, |
| 1503 | /* Green */ { 0x00, 0x01, 0x00 }, |
| 1504 | /* Pink */ { 0x02, 0x00, 0x01 }, |
| 1505 | /* Orange */ { 0x02, 0x01, 0x00 }, |
| 1506 | /* Teal */ { 0x00, 0x01, 0x01 }, |
| 1507 | /* White */ { 0x01, 0x01, 0x01 } |
| 1508 | }; |
| 1509 | |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1510 | int id = sc->device_id; |
| 1511 | |
| 1512 | BUILD_BUG_ON(MAX_LEDS < ARRAY_SIZE(color_code[0])); |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 1513 | |
| 1514 | if (id < 0) |
| 1515 | return; |
| 1516 | |
| 1517 | id %= 7; |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1518 | memcpy(sc->led_state, color_code[id], sizeof(color_code[id])); |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 1519 | } |
| 1520 | |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1521 | static void buzz_set_leds(struct sony_sc *sc) |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1522 | { |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1523 | struct hid_device *hdev = sc->hdev; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1524 | struct list_head *report_list = |
| 1525 | &hdev->report_enum[HID_OUTPUT_REPORT].report_list; |
| 1526 | struct hid_report *report = list_entry(report_list->next, |
| 1527 | struct hid_report, list); |
| 1528 | __s32 *value = report->field[0]->value; |
| 1529 | |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1530 | BUILD_BUG_ON(MAX_LEDS < 4); |
| 1531 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1532 | value[0] = 0x00; |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1533 | value[1] = sc->led_state[0] ? 0xff : 0x00; |
| 1534 | value[2] = sc->led_state[1] ? 0xff : 0x00; |
| 1535 | value[3] = sc->led_state[2] ? 0xff : 0x00; |
| 1536 | value[4] = sc->led_state[3] ? 0xff : 0x00; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1537 | value[5] = 0x00; |
| 1538 | value[6] = 0x00; |
| 1539 | hid_hw_request(hdev, report, HID_REQ_SET_REPORT); |
| 1540 | } |
| 1541 | |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1542 | static void sony_set_leds(struct sony_sc *sc) |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1543 | { |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1544 | if (!(sc->quirks & BUZZ_CONTROLLER)) |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1545 | schedule_work(&sc->state_worker); |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1546 | else |
| 1547 | buzz_set_leds(sc); |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1548 | } |
| 1549 | |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 1550 | static void sony_led_set_brightness(struct led_classdev *led, |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1551 | enum led_brightness value) |
| 1552 | { |
| 1553 | struct device *dev = led->dev->parent; |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1554 | struct hid_device *hdev = to_hid_device(dev); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1555 | struct sony_sc *drv_data; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1556 | |
| 1557 | int n; |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1558 | int force_update; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1559 | |
| 1560 | drv_data = hid_get_drvdata(hdev); |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 1561 | if (!drv_data) { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1562 | hid_err(hdev, "No device data\n"); |
| 1563 | return; |
| 1564 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1565 | |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1566 | /* |
| 1567 | * The Sixaxis on USB will override any LED settings sent to it |
| 1568 | * and keep flashing all of the LEDs until the PS button is pressed. |
| 1569 | * Updates, even if redundant, must be always be sent to the |
| 1570 | * controller to avoid having to toggle the state of an LED just to |
| 1571 | * stop the flashing later on. |
| 1572 | */ |
| 1573 | force_update = !!(drv_data->quirks & SIXAXIS_CONTROLLER_USB); |
| 1574 | |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 1575 | for (n = 0; n < drv_data->led_count; n++) { |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1576 | if (led == drv_data->leds[n] && (force_update || |
| 1577 | (value != drv_data->led_state[n] || |
| 1578 | drv_data->led_delay_on[n] || |
| 1579 | drv_data->led_delay_off[n]))) { |
| 1580 | |
| 1581 | drv_data->led_state[n] = value; |
| 1582 | |
| 1583 | /* Setting the brightness stops the blinking */ |
| 1584 | drv_data->led_delay_on[n] = 0; |
| 1585 | drv_data->led_delay_off[n] = 0; |
| 1586 | |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1587 | sony_set_leds(drv_data); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1588 | break; |
| 1589 | } |
| 1590 | } |
| 1591 | } |
| 1592 | |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 1593 | static enum led_brightness sony_led_get_brightness(struct led_classdev *led) |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1594 | { |
| 1595 | struct device *dev = led->dev->parent; |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1596 | struct hid_device *hdev = to_hid_device(dev); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1597 | struct sony_sc *drv_data; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1598 | |
| 1599 | int n; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1600 | |
| 1601 | drv_data = hid_get_drvdata(hdev); |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 1602 | if (!drv_data) { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1603 | hid_err(hdev, "No device data\n"); |
| 1604 | return LED_OFF; |
| 1605 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1606 | |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 1607 | for (n = 0; n < drv_data->led_count; n++) { |
Simon Wood | 7db7504 | 2014-02-05 12:34:18 -0700 | [diff] [blame] | 1608 | if (led == drv_data->leds[n]) |
| 1609 | return drv_data->led_state[n]; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1610 | } |
| 1611 | |
Simon Wood | 7db7504 | 2014-02-05 12:34:18 -0700 | [diff] [blame] | 1612 | return LED_OFF; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1613 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1614 | |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1615 | static int sony_led_blink_set(struct led_classdev *led, unsigned long *delay_on, |
| 1616 | unsigned long *delay_off) |
| 1617 | { |
| 1618 | struct device *dev = led->dev->parent; |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1619 | struct hid_device *hdev = to_hid_device(dev); |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1620 | struct sony_sc *drv_data = hid_get_drvdata(hdev); |
| 1621 | int n; |
| 1622 | __u8 new_on, new_off; |
| 1623 | |
| 1624 | if (!drv_data) { |
| 1625 | hid_err(hdev, "No device data\n"); |
| 1626 | return -EINVAL; |
| 1627 | } |
| 1628 | |
| 1629 | /* Max delay is 255 deciseconds or 2550 milliseconds */ |
| 1630 | if (*delay_on > 2550) |
| 1631 | *delay_on = 2550; |
| 1632 | if (*delay_off > 2550) |
| 1633 | *delay_off = 2550; |
| 1634 | |
| 1635 | /* Blink at 1 Hz if both values are zero */ |
| 1636 | if (!*delay_on && !*delay_off) |
| 1637 | *delay_on = *delay_off = 500; |
| 1638 | |
| 1639 | new_on = *delay_on / 10; |
| 1640 | new_off = *delay_off / 10; |
| 1641 | |
| 1642 | for (n = 0; n < drv_data->led_count; n++) { |
| 1643 | if (led == drv_data->leds[n]) |
| 1644 | break; |
| 1645 | } |
| 1646 | |
| 1647 | /* This LED is not registered on this device */ |
| 1648 | if (n >= drv_data->led_count) |
| 1649 | return -EINVAL; |
| 1650 | |
| 1651 | /* Don't schedule work if the values didn't change */ |
| 1652 | if (new_on != drv_data->led_delay_on[n] || |
| 1653 | new_off != drv_data->led_delay_off[n]) { |
| 1654 | drv_data->led_delay_on[n] = new_on; |
| 1655 | drv_data->led_delay_off[n] = new_off; |
| 1656 | schedule_work(&drv_data->state_worker); |
| 1657 | } |
| 1658 | |
| 1659 | return 0; |
| 1660 | } |
| 1661 | |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1662 | static void sony_leds_remove(struct sony_sc *sc) |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1663 | { |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1664 | struct led_classdev *led; |
| 1665 | int n; |
| 1666 | |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1667 | BUG_ON(!(sc->quirks & SONY_LED_SUPPORT)); |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1668 | |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1669 | for (n = 0; n < sc->led_count; n++) { |
| 1670 | led = sc->leds[n]; |
| 1671 | sc->leds[n] = NULL; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1672 | if (!led) |
| 1673 | continue; |
| 1674 | led_classdev_unregister(led); |
| 1675 | kfree(led); |
| 1676 | } |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 1677 | |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1678 | sc->led_count = 0; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1679 | } |
| 1680 | |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1681 | static int sony_leds_init(struct sony_sc *sc) |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1682 | { |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1683 | struct hid_device *hdev = sc->hdev; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 1684 | int n, ret = 0; |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1685 | int use_ds4_names; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 1686 | struct led_classdev *led; |
| 1687 | size_t name_sz; |
| 1688 | char *name; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1689 | size_t name_len; |
| 1690 | const char *name_fmt; |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1691 | static const char * const ds4_name_str[] = { "red", "green", "blue", |
| 1692 | "global" }; |
Frank Praznik | 5607c89 | 2014-07-29 19:55:48 -0700 | [diff] [blame] | 1693 | __u8 max_brightness[MAX_LEDS] = { [0 ... (MAX_LEDS - 1)] = 1 }; |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1694 | __u8 use_hw_blink[MAX_LEDS] = { 0 }; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1695 | |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1696 | BUG_ON(!(sc->quirks & SONY_LED_SUPPORT)); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1697 | |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1698 | if (sc->quirks & BUZZ_CONTROLLER) { |
| 1699 | sc->led_count = 4; |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1700 | use_ds4_names = 0; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1701 | name_len = strlen("::buzz#"); |
| 1702 | name_fmt = "%s::buzz%d"; |
| 1703 | /* Validate expected report characteristics. */ |
| 1704 | if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7)) |
| 1705 | return -ENODEV; |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1706 | } else if (sc->quirks & DUALSHOCK4_CONTROLLER) { |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1707 | dualshock4_set_leds_from_id(sc); |
| 1708 | sc->led_state[3] = 1; |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1709 | sc->led_count = 4; |
| 1710 | memset(max_brightness, 255, 3); |
| 1711 | use_hw_blink[3] = 1; |
| 1712 | use_ds4_names = 1; |
Frank Praznik | 61ebca9 | 2014-01-20 12:27:02 -0500 | [diff] [blame] | 1713 | name_len = 0; |
| 1714 | name_fmt = "%s:%s"; |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 1715 | } else if (sc->quirks & MOTION_CONTROLLER) { |
| 1716 | sc->led_count = 3; |
| 1717 | memset(max_brightness, 255, 3); |
| 1718 | use_ds4_names = 1; |
| 1719 | name_len = 0; |
| 1720 | name_fmt = "%s:%s"; |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 1721 | } else if (sc->quirks & NAVIGATION_CONTROLLER) { |
| 1722 | static const __u8 navigation_leds[4] = {0x01, 0x00, 0x00, 0x00}; |
| 1723 | |
| 1724 | memcpy(sc->led_state, navigation_leds, sizeof(navigation_leds)); |
| 1725 | sc->led_count = 1; |
| 1726 | memset(use_hw_blink, 1, 4); |
| 1727 | use_ds4_names = 0; |
| 1728 | name_len = strlen("::sony#"); |
| 1729 | name_fmt = "%s::sony%d"; |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 1730 | } else { |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1731 | sixaxis_set_leds_from_id(sc); |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1732 | sc->led_count = 4; |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1733 | memset(use_hw_blink, 1, 4); |
| 1734 | use_ds4_names = 0; |
Frank Praznik | 61ebca9 | 2014-01-20 12:27:02 -0500 | [diff] [blame] | 1735 | name_len = strlen("::sony#"); |
| 1736 | name_fmt = "%s::sony%d"; |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 1737 | } |
| 1738 | |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 1739 | /* |
| 1740 | * Clear LEDs as we have no way of reading their initial state. This is |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1741 | * only relevant if the driver is loaded after somebody actively set the |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 1742 | * LEDs to on |
| 1743 | */ |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1744 | sony_set_leds(sc); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1745 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1746 | name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1747 | |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1748 | for (n = 0; n < sc->led_count; n++) { |
Frank Praznik | 61ebca9 | 2014-01-20 12:27:02 -0500 | [diff] [blame] | 1749 | |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1750 | if (use_ds4_names) |
| 1751 | name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2; |
Frank Praznik | 61ebca9 | 2014-01-20 12:27:02 -0500 | [diff] [blame] | 1752 | |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 1753 | led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL); |
| 1754 | if (!led) { |
| 1755 | hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); |
Julia Lawall | 8cd5fcd | 2013-12-29 23:47:27 +0100 | [diff] [blame] | 1756 | ret = -ENOMEM; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 1757 | goto error_leds; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1758 | } |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 1759 | |
| 1760 | name = (void *)(&led[1]); |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1761 | if (use_ds4_names) |
| 1762 | snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), |
| 1763 | ds4_name_str[n]); |
Frank Praznik | 61ebca9 | 2014-01-20 12:27:02 -0500 | [diff] [blame] | 1764 | else |
| 1765 | snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1); |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 1766 | led->name = name; |
Frank Praznik | 221399b | 2015-05-05 20:47:32 -0400 | [diff] [blame] | 1767 | led->brightness = sc->led_state[n]; |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1768 | led->max_brightness = max_brightness[n]; |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 1769 | led->brightness_get = sony_led_get_brightness; |
| 1770 | led->brightness_set = sony_led_set_brightness; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 1771 | |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1772 | if (use_hw_blink[n]) |
| 1773 | led->blink_set = sony_led_blink_set; |
| 1774 | |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 1775 | sc->leds[n] = led; |
| 1776 | |
Julia Lawall | 8cd5fcd | 2013-12-29 23:47:27 +0100 | [diff] [blame] | 1777 | ret = led_classdev_register(&hdev->dev, led); |
| 1778 | if (ret) { |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 1779 | hid_err(hdev, "Failed to register LED %d\n", n); |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 1780 | sc->leds[n] = NULL; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 1781 | kfree(led); |
| 1782 | goto error_leds; |
| 1783 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1784 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1785 | |
| 1786 | return ret; |
| 1787 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1788 | error_leds: |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1789 | sony_leds_remove(sc); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1790 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1791 | return ret; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 1792 | } |
| 1793 | |
Frank Praznik | d8aaccd | 2015-11-11 09:49:37 -0500 | [diff] [blame] | 1794 | static void sixaxis_send_output_report(struct sony_sc *sc) |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 1795 | { |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1796 | static const union sixaxis_output_report_01 default_report = { |
Frank Praznik | 55d3b66 | 2014-04-14 10:11:32 -0400 | [diff] [blame] | 1797 | .buf = { |
| 1798 | 0x01, |
| 1799 | 0x00, 0xff, 0x00, 0xff, 0x00, |
| 1800 | 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1801 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 1802 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 1803 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 1804 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 1805 | 0x00, 0x00, 0x00, 0x00, 0x00 |
| 1806 | } |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 1807 | }; |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1808 | struct sixaxis_output_report *report = |
| 1809 | (struct sixaxis_output_report *)sc->output_report_dmabuf; |
| 1810 | int n; |
| 1811 | |
| 1812 | /* Initialize the report with default values */ |
| 1813 | memcpy(report, &default_report, sizeof(struct sixaxis_output_report)); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 1814 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1815 | #ifdef CONFIG_SONY_FF |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1816 | report->rumble.right_motor_on = sc->right ? 1 : 0; |
| 1817 | report->rumble.left_motor_force = sc->left; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1818 | #endif |
| 1819 | |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1820 | report->leds_bitmap |= sc->led_state[0] << 1; |
| 1821 | report->leds_bitmap |= sc->led_state[1] << 2; |
| 1822 | report->leds_bitmap |= sc->led_state[2] << 3; |
| 1823 | report->leds_bitmap |= sc->led_state[3] << 4; |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 1824 | |
Simon Wood | 88f6576 | 2014-04-14 10:11:37 -0400 | [diff] [blame] | 1825 | /* Set flag for all leds off, required for 3rd party INTEC controller */ |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1826 | if ((report->leds_bitmap & 0x1E) == 0) |
| 1827 | report->leds_bitmap |= 0x20; |
Simon Wood | 88f6576 | 2014-04-14 10:11:37 -0400 | [diff] [blame] | 1828 | |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1829 | /* |
| 1830 | * The LEDs in the report are indexed in reverse order to their |
| 1831 | * corresponding light on the controller. |
| 1832 | * Index 0 = LED 4, index 1 = LED 3, etc... |
| 1833 | * |
| 1834 | * In the case of both delay values being zero (blinking disabled) the |
| 1835 | * default report values should be used or the controller LED will be |
| 1836 | * always off. |
| 1837 | */ |
| 1838 | for (n = 0; n < 4; n++) { |
| 1839 | if (sc->led_delay_on[n] || sc->led_delay_off[n]) { |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1840 | report->led[3 - n].duty_off = sc->led_delay_off[n]; |
| 1841 | report->led[3 - n].duty_on = sc->led_delay_on[n]; |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1842 | } |
| 1843 | } |
| 1844 | |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1845 | hid_hw_raw_request(sc->hdev, report->report_id, (__u8 *)report, |
| 1846 | sizeof(struct sixaxis_output_report), |
| 1847 | HID_OUTPUT_REPORT, HID_REQ_SET_REPORT); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 1848 | } |
| 1849 | |
Frank Praznik | d8aaccd | 2015-11-11 09:49:37 -0500 | [diff] [blame] | 1850 | static void dualshock4_send_output_report(struct sony_sc *sc) |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 1851 | { |
Frank Praznik | 0da8ea6 | 2014-01-16 21:42:51 -0500 | [diff] [blame] | 1852 | struct hid_device *hdev = sc->hdev; |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1853 | __u8 *buf = sc->output_report_dmabuf; |
Frank Praznik | 4822023 | 2014-02-05 20:03:44 -0500 | [diff] [blame] | 1854 | int offset; |
Frank Praznik | 0da8ea6 | 2014-01-16 21:42:51 -0500 | [diff] [blame] | 1855 | |
Frank Praznik | fdcf105d | 2014-02-05 20:03:46 -0500 | [diff] [blame] | 1856 | if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) { |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1857 | memset(buf, 0, DS4_REPORT_0x05_SIZE); |
Frank Praznik | fdcf105d | 2014-02-05 20:03:46 -0500 | [diff] [blame] | 1858 | buf[0] = 0x05; |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1859 | buf[1] = 0xFF; |
Frank Praznik | fdcf105d | 2014-02-05 20:03:46 -0500 | [diff] [blame] | 1860 | offset = 4; |
| 1861 | } else { |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1862 | memset(buf, 0, DS4_REPORT_0x11_SIZE); |
Frank Praznik | fdcf105d | 2014-02-05 20:03:46 -0500 | [diff] [blame] | 1863 | buf[0] = 0x11; |
Rostislav Pehlivanov | 824deff | 2015-07-28 08:38:47 +0100 | [diff] [blame] | 1864 | buf[1] = 0x80; |
Frank Praznik | fdcf105d | 2014-02-05 20:03:46 -0500 | [diff] [blame] | 1865 | buf[3] = 0x0F; |
| 1866 | offset = 6; |
| 1867 | } |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 1868 | |
| 1869 | #ifdef CONFIG_SONY_FF |
Frank Praznik | 4822023 | 2014-02-05 20:03:44 -0500 | [diff] [blame] | 1870 | buf[offset++] = sc->right; |
| 1871 | buf[offset++] = sc->left; |
| 1872 | #else |
| 1873 | offset += 2; |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 1874 | #endif |
| 1875 | |
Frank Praznik | b3ed458 | 2014-04-14 10:11:36 -0400 | [diff] [blame] | 1876 | /* LED 3 is the global control */ |
| 1877 | if (sc->led_state[3]) { |
| 1878 | buf[offset++] = sc->led_state[0]; |
| 1879 | buf[offset++] = sc->led_state[1]; |
| 1880 | buf[offset++] = sc->led_state[2]; |
| 1881 | } else { |
| 1882 | offset += 3; |
| 1883 | } |
| 1884 | |
| 1885 | /* If both delay values are zero the DualShock 4 disables blinking. */ |
| 1886 | buf[offset++] = sc->led_delay_on[3]; |
| 1887 | buf[offset++] = sc->led_delay_off[3]; |
Frank Praznik | 60781cf | 2014-01-11 15:13:15 -0500 | [diff] [blame] | 1888 | |
Frank Praznik | fdcf105d | 2014-02-05 20:03:46 -0500 | [diff] [blame] | 1889 | if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1890 | hid_hw_output_report(hdev, buf, DS4_REPORT_0x05_SIZE); |
Frank Praznik | fdcf105d | 2014-02-05 20:03:46 -0500 | [diff] [blame] | 1891 | else |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1892 | hid_hw_raw_request(hdev, 0x11, buf, DS4_REPORT_0x11_SIZE, |
Frank Praznik | fdcf105d | 2014-02-05 20:03:46 -0500 | [diff] [blame] | 1893 | HID_OUTPUT_REPORT, HID_REQ_SET_REPORT); |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 1894 | } |
| 1895 | |
Frank Praznik | d8aaccd | 2015-11-11 09:49:37 -0500 | [diff] [blame] | 1896 | static void motion_send_output_report(struct sony_sc *sc) |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 1897 | { |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 1898 | struct hid_device *hdev = sc->hdev; |
| 1899 | struct motion_output_report_02 *report = |
| 1900 | (struct motion_output_report_02 *)sc->output_report_dmabuf; |
| 1901 | |
Simon Wood | 41d2d42 | 2015-06-09 21:27:06 -0600 | [diff] [blame] | 1902 | memset(report, 0, MOTION_REPORT_0x02_SIZE); |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 1903 | |
| 1904 | report->type = 0x02; /* set leds */ |
| 1905 | report->r = sc->led_state[0]; |
| 1906 | report->g = sc->led_state[1]; |
| 1907 | report->b = sc->led_state[2]; |
| 1908 | |
| 1909 | #ifdef CONFIG_SONY_FF |
| 1910 | report->rumble = max(sc->right, sc->left); |
| 1911 | #endif |
| 1912 | |
Simon Wood | 41d2d42 | 2015-06-09 21:27:06 -0600 | [diff] [blame] | 1913 | hid_hw_output_report(hdev, (__u8 *)report, MOTION_REPORT_0x02_SIZE); |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 1914 | } |
| 1915 | |
Frank Praznik | decd946 | 2015-11-11 09:49:38 -0500 | [diff] [blame] | 1916 | static inline void sony_send_output_report(struct sony_sc *sc) |
| 1917 | { |
| 1918 | if (sc->send_output_report) |
| 1919 | sc->send_output_report(sc); |
| 1920 | } |
| 1921 | |
Frank Praznik | d8aaccd | 2015-11-11 09:49:37 -0500 | [diff] [blame] | 1922 | static void sony_state_worker(struct work_struct *work) |
| 1923 | { |
| 1924 | struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); |
| 1925 | sc->send_output_report(sc); |
| 1926 | } |
| 1927 | |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1928 | static int sony_allocate_output_report(struct sony_sc *sc) |
| 1929 | { |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 1930 | if ((sc->quirks & SIXAXIS_CONTROLLER) || |
| 1931 | (sc->quirks & NAVIGATION_CONTROLLER)) |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1932 | sc->output_report_dmabuf = |
| 1933 | kmalloc(sizeof(union sixaxis_output_report_01), |
| 1934 | GFP_KERNEL); |
| 1935 | else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) |
| 1936 | sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x11_SIZE, |
| 1937 | GFP_KERNEL); |
| 1938 | else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) |
| 1939 | sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x05_SIZE, |
| 1940 | GFP_KERNEL); |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 1941 | else if (sc->quirks & MOTION_CONTROLLER) |
Simon Wood | 41d2d42 | 2015-06-09 21:27:06 -0600 | [diff] [blame] | 1942 | sc->output_report_dmabuf = kmalloc(MOTION_REPORT_0x02_SIZE, |
| 1943 | GFP_KERNEL); |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 1944 | else |
| 1945 | return 0; |
| 1946 | |
| 1947 | if (!sc->output_report_dmabuf) |
| 1948 | return -ENOMEM; |
| 1949 | |
| 1950 | return 0; |
| 1951 | } |
| 1952 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 1953 | #ifdef CONFIG_SONY_FF |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 1954 | static int sony_play_effect(struct input_dev *dev, void *data, |
| 1955 | struct ff_effect *effect) |
| 1956 | { |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 1957 | struct hid_device *hid = input_get_drvdata(dev); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 1958 | struct sony_sc *sc = hid_get_drvdata(hid); |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 1959 | |
| 1960 | if (effect->type != FF_RUMBLE) |
| 1961 | return 0; |
| 1962 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 1963 | sc->left = effect->u.rumble.strong_magnitude / 256; |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 1964 | sc->right = effect->u.rumble.weak_magnitude / 256; |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 1965 | |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 1966 | schedule_work(&sc->state_worker); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 1967 | return 0; |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 1968 | } |
| 1969 | |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1970 | static int sony_init_ff(struct sony_sc *sc) |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 1971 | { |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1972 | struct hid_input *hidinput = list_entry(sc->hdev->inputs.next, |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 1973 | struct hid_input, list); |
| 1974 | struct input_dev *input_dev = hidinput->input; |
| 1975 | |
| 1976 | input_set_capability(input_dev, EV_FF, FF_RUMBLE); |
| 1977 | return input_ff_create_memless(input_dev, NULL, sony_play_effect); |
| 1978 | } |
| 1979 | |
| 1980 | #else |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 1981 | static int sony_init_ff(struct sony_sc *sc) |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 1982 | { |
| 1983 | return 0; |
| 1984 | } |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 1985 | |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 1986 | #endif |
| 1987 | |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1988 | static int sony_battery_get_property(struct power_supply *psy, |
| 1989 | enum power_supply_property psp, |
| 1990 | union power_supply_propval *val) |
Frank Praznik | c4e1ddf | 2014-01-17 14:46:26 -0500 | [diff] [blame] | 1991 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1992 | struct sony_sc *sc = power_supply_get_drvdata(psy); |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 1993 | unsigned long flags; |
| 1994 | int ret = 0; |
| 1995 | u8 battery_charging, battery_capacity, cable_state; |
| 1996 | |
| 1997 | spin_lock_irqsave(&sc->lock, flags); |
| 1998 | battery_charging = sc->battery_charging; |
| 1999 | battery_capacity = sc->battery_capacity; |
| 2000 | cable_state = sc->cable_state; |
| 2001 | spin_unlock_irqrestore(&sc->lock, flags); |
| 2002 | |
| 2003 | switch (psp) { |
| 2004 | case POWER_SUPPLY_PROP_PRESENT: |
| 2005 | val->intval = 1; |
| 2006 | break; |
| 2007 | case POWER_SUPPLY_PROP_SCOPE: |
| 2008 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 2009 | break; |
| 2010 | case POWER_SUPPLY_PROP_CAPACITY: |
| 2011 | val->intval = battery_capacity; |
| 2012 | break; |
| 2013 | case POWER_SUPPLY_PROP_STATUS: |
| 2014 | if (battery_charging) |
| 2015 | val->intval = POWER_SUPPLY_STATUS_CHARGING; |
| 2016 | else |
| 2017 | if (battery_capacity == 100 && cable_state) |
| 2018 | val->intval = POWER_SUPPLY_STATUS_FULL; |
| 2019 | else |
| 2020 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; |
| 2021 | break; |
| 2022 | default: |
| 2023 | ret = -EINVAL; |
| 2024 | break; |
| 2025 | } |
| 2026 | return ret; |
| 2027 | } |
| 2028 | |
| 2029 | static int sony_battery_probe(struct sony_sc *sc) |
| 2030 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 2031 | struct power_supply_config psy_cfg = { .drv_data = sc, }; |
Frank Praznik | c4e1ddf | 2014-01-17 14:46:26 -0500 | [diff] [blame] | 2032 | struct hid_device *hdev = sc->hdev; |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 2033 | int ret; |
Frank Praznik | c4e1ddf | 2014-01-17 14:46:26 -0500 | [diff] [blame] | 2034 | |
Frank Praznik | ad142b9 | 2014-02-20 11:36:00 -0500 | [diff] [blame] | 2035 | /* |
| 2036 | * Set the default battery level to 100% to avoid low battery warnings |
Frank Praznik | d9a293a | 2014-02-05 20:03:48 -0500 | [diff] [blame] | 2037 | * if the battery is polled before the first device report is received. |
| 2038 | */ |
| 2039 | sc->battery_capacity = 100; |
Frank Praznik | c4e1ddf | 2014-01-17 14:46:26 -0500 | [diff] [blame] | 2040 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 2041 | sc->battery_desc.properties = sony_battery_props; |
| 2042 | sc->battery_desc.num_properties = ARRAY_SIZE(sony_battery_props); |
| 2043 | sc->battery_desc.get_property = sony_battery_get_property; |
| 2044 | sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; |
| 2045 | sc->battery_desc.use_for_apm = 0; |
| 2046 | sc->battery_desc.name = kasprintf(GFP_KERNEL, |
| 2047 | "sony_controller_battery_%pMR", |
| 2048 | sc->mac_address); |
| 2049 | if (!sc->battery_desc.name) |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 2050 | return -ENOMEM; |
| 2051 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 2052 | sc->battery = power_supply_register(&hdev->dev, &sc->battery_desc, |
| 2053 | &psy_cfg); |
| 2054 | if (IS_ERR(sc->battery)) { |
| 2055 | ret = PTR_ERR(sc->battery); |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 2056 | hid_err(hdev, "Unable to register battery device\n"); |
| 2057 | goto err_free; |
| 2058 | } |
| 2059 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 2060 | power_supply_powers(sc->battery, &hdev->dev); |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 2061 | return 0; |
| 2062 | |
| 2063 | err_free: |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 2064 | kfree(sc->battery_desc.name); |
| 2065 | sc->battery_desc.name = NULL; |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 2066 | return ret; |
| 2067 | } |
| 2068 | |
| 2069 | static void sony_battery_remove(struct sony_sc *sc) |
| 2070 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 2071 | if (!sc->battery_desc.name) |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 2072 | return; |
| 2073 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 2074 | power_supply_unregister(sc->battery); |
| 2075 | kfree(sc->battery_desc.name); |
| 2076 | sc->battery_desc.name = NULL; |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 2077 | } |
| 2078 | |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2079 | /* |
| 2080 | * If a controller is plugged in via USB while already connected via Bluetooth |
| 2081 | * it will show up as two devices. A global list of connected controllers and |
| 2082 | * their MAC addresses is maintained to ensure that a device is only connected |
| 2083 | * once. |
| 2084 | */ |
| 2085 | static int sony_check_add_dev_list(struct sony_sc *sc) |
| 2086 | { |
| 2087 | struct sony_sc *entry; |
| 2088 | unsigned long flags; |
| 2089 | int ret; |
| 2090 | |
| 2091 | spin_lock_irqsave(&sony_dev_list_lock, flags); |
| 2092 | |
| 2093 | list_for_each_entry(entry, &sony_device_list, list_node) { |
| 2094 | ret = memcmp(sc->mac_address, entry->mac_address, |
| 2095 | sizeof(sc->mac_address)); |
| 2096 | if (!ret) { |
| 2097 | ret = -EEXIST; |
| 2098 | hid_info(sc->hdev, "controller with MAC address %pMR already connected\n", |
| 2099 | sc->mac_address); |
| 2100 | goto unlock; |
Frank Praznik | c4e1ddf | 2014-01-17 14:46:26 -0500 | [diff] [blame] | 2101 | } |
| 2102 | } |
| 2103 | |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2104 | ret = 0; |
| 2105 | list_add(&(sc->list_node), &sony_device_list); |
Frank Praznik | c4e1ddf | 2014-01-17 14:46:26 -0500 | [diff] [blame] | 2106 | |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2107 | unlock: |
| 2108 | spin_unlock_irqrestore(&sony_dev_list_lock, flags); |
| 2109 | return ret; |
Frank Praznik | c4e1ddf | 2014-01-17 14:46:26 -0500 | [diff] [blame] | 2110 | } |
| 2111 | |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2112 | static void sony_remove_dev_list(struct sony_sc *sc) |
| 2113 | { |
| 2114 | unsigned long flags; |
| 2115 | |
| 2116 | if (sc->list_node.next) { |
| 2117 | spin_lock_irqsave(&sony_dev_list_lock, flags); |
| 2118 | list_del(&(sc->list_node)); |
| 2119 | spin_unlock_irqrestore(&sony_dev_list_lock, flags); |
| 2120 | } |
| 2121 | } |
| 2122 | |
| 2123 | static int sony_get_bt_devaddr(struct sony_sc *sc) |
| 2124 | { |
| 2125 | int ret; |
| 2126 | |
| 2127 | /* HIDP stores the device MAC address as a string in the uniq field. */ |
| 2128 | ret = strlen(sc->hdev->uniq); |
| 2129 | if (ret != 17) |
| 2130 | return -EINVAL; |
| 2131 | |
| 2132 | ret = sscanf(sc->hdev->uniq, |
| 2133 | "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", |
| 2134 | &sc->mac_address[5], &sc->mac_address[4], &sc->mac_address[3], |
| 2135 | &sc->mac_address[2], &sc->mac_address[1], &sc->mac_address[0]); |
| 2136 | |
| 2137 | if (ret != 6) |
| 2138 | return -EINVAL; |
| 2139 | |
| 2140 | return 0; |
| 2141 | } |
| 2142 | |
| 2143 | static int sony_check_add(struct sony_sc *sc) |
| 2144 | { |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 2145 | __u8 *buf = NULL; |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2146 | int n, ret; |
| 2147 | |
| 2148 | if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) || |
Simon Wood | 12e9a6d7 | 2015-06-09 21:27:05 -0600 | [diff] [blame] | 2149 | (sc->quirks & MOTION_CONTROLLER_BT) || |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 2150 | (sc->quirks & NAVIGATION_CONTROLLER_BT) || |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2151 | (sc->quirks & SIXAXIS_CONTROLLER_BT)) { |
| 2152 | /* |
| 2153 | * sony_get_bt_devaddr() attempts to parse the Bluetooth MAC |
| 2154 | * address from the uniq string where HIDP stores it. |
| 2155 | * As uniq cannot be guaranteed to be a MAC address in all cases |
| 2156 | * a failure of this function should not prevent the connection. |
| 2157 | */ |
| 2158 | if (sony_get_bt_devaddr(sc) < 0) { |
| 2159 | hid_warn(sc->hdev, "UNIQ does not contain a MAC address; duplicate check skipped\n"); |
| 2160 | return 0; |
| 2161 | } |
| 2162 | } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) { |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 2163 | buf = kmalloc(DS4_REPORT_0x81_SIZE, GFP_KERNEL); |
| 2164 | if (!buf) |
| 2165 | return -ENOMEM; |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2166 | |
| 2167 | /* |
| 2168 | * The MAC address of a DS4 controller connected via USB can be |
| 2169 | * retrieved with feature report 0x81. The address begins at |
| 2170 | * offset 1. |
| 2171 | */ |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 2172 | ret = hid_hw_raw_request(sc->hdev, 0x81, buf, |
| 2173 | DS4_REPORT_0x81_SIZE, HID_FEATURE_REPORT, |
| 2174 | HID_REQ_GET_REPORT); |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2175 | |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 2176 | if (ret != DS4_REPORT_0x81_SIZE) { |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2177 | hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n"); |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 2178 | ret = ret < 0 ? ret : -EINVAL; |
| 2179 | goto out_free; |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address)); |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 2183 | } else if ((sc->quirks & SIXAXIS_CONTROLLER_USB) || |
| 2184 | (sc->quirks & NAVIGATION_CONTROLLER_USB)) { |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 2185 | buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL); |
| 2186 | if (!buf) |
| 2187 | return -ENOMEM; |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2188 | |
| 2189 | /* |
| 2190 | * The MAC address of a Sixaxis controller connected via USB can |
| 2191 | * be retrieved with feature report 0xf2. The address begins at |
| 2192 | * offset 4. |
| 2193 | */ |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 2194 | ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, |
| 2195 | SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT, |
| 2196 | HID_REQ_GET_REPORT); |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2197 | |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 2198 | if (ret != SIXAXIS_REPORT_0xF2_SIZE) { |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2199 | hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n"); |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 2200 | ret = ret < 0 ? ret : -EINVAL; |
| 2201 | goto out_free; |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | /* |
| 2205 | * The Sixaxis device MAC in the report is big-endian and must |
| 2206 | * be byte-swapped. |
| 2207 | */ |
| 2208 | for (n = 0; n < 6; n++) |
| 2209 | sc->mac_address[5-n] = buf[4+n]; |
| 2210 | } else { |
| 2211 | return 0; |
| 2212 | } |
| 2213 | |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 2214 | ret = sony_check_add_dev_list(sc); |
| 2215 | |
| 2216 | out_free: |
| 2217 | |
| 2218 | kfree(buf); |
| 2219 | |
| 2220 | return ret; |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2221 | } |
| 2222 | |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 2223 | static int sony_set_device_id(struct sony_sc *sc) |
| 2224 | { |
| 2225 | int ret; |
| 2226 | |
| 2227 | /* |
| 2228 | * Only DualShock 4 or Sixaxis controllers get an id. |
| 2229 | * All others are set to -1. |
| 2230 | */ |
| 2231 | if ((sc->quirks & SIXAXIS_CONTROLLER) || |
| 2232 | (sc->quirks & DUALSHOCK4_CONTROLLER)) { |
| 2233 | ret = ida_simple_get(&sony_device_id_allocator, 0, 0, |
| 2234 | GFP_KERNEL); |
| 2235 | if (ret < 0) { |
| 2236 | sc->device_id = -1; |
| 2237 | return ret; |
| 2238 | } |
| 2239 | sc->device_id = ret; |
| 2240 | } else { |
| 2241 | sc->device_id = -1; |
| 2242 | } |
| 2243 | |
| 2244 | return 0; |
| 2245 | } |
| 2246 | |
| 2247 | static void sony_release_device_id(struct sony_sc *sc) |
| 2248 | { |
| 2249 | if (sc->device_id >= 0) { |
| 2250 | ida_simple_remove(&sony_device_id_allocator, sc->device_id); |
| 2251 | sc->device_id = -1; |
| 2252 | } |
| 2253 | } |
| 2254 | |
Frank Praznik | d8aaccd | 2015-11-11 09:49:37 -0500 | [diff] [blame] | 2255 | static inline void sony_init_output_report(struct sony_sc *sc, |
| 2256 | void(*send_output_report)(struct sony_sc*)) |
Frank Praznik | 4626204 | 2014-04-14 10:11:31 -0400 | [diff] [blame] | 2257 | { |
Frank Praznik | d8aaccd | 2015-11-11 09:49:37 -0500 | [diff] [blame] | 2258 | sc->send_output_report = send_output_report; |
| 2259 | |
Frank Praznik | 4626204 | 2014-04-14 10:11:31 -0400 | [diff] [blame] | 2260 | if (!sc->worker_initialized) |
Frank Praznik | d8aaccd | 2015-11-11 09:49:37 -0500 | [diff] [blame] | 2261 | INIT_WORK(&sc->state_worker, sony_state_worker); |
Frank Praznik | 4626204 | 2014-04-14 10:11:31 -0400 | [diff] [blame] | 2262 | |
| 2263 | sc->worker_initialized = 1; |
| 2264 | } |
| 2265 | |
| 2266 | static inline void sony_cancel_work_sync(struct sony_sc *sc) |
| 2267 | { |
| 2268 | if (sc->worker_initialized) |
| 2269 | cancel_work_sync(&sc->state_worker); |
| 2270 | } |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2271 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2272 | static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 2273 | { |
| 2274 | int ret; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 2275 | unsigned long quirks = id->driver_data; |
| 2276 | struct sony_sc *sc; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 2277 | unsigned int connect_mask = HID_CONNECT_DEFAULT; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 2278 | |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 2279 | sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL); |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 2280 | if (sc == NULL) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 2281 | hid_err(hdev, "can't alloc sony descriptor\n"); |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 2282 | return -ENOMEM; |
| 2283 | } |
| 2284 | |
Frank Praznik | b94993f | 2015-02-22 20:42:46 -0500 | [diff] [blame] | 2285 | spin_lock_init(&sc->lock); |
| 2286 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 2287 | sc->quirks = quirks; |
| 2288 | hid_set_drvdata(hdev, sc); |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 2289 | sc->hdev = hdev; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2290 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2291 | ret = hid_parse(hdev); |
| 2292 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 2293 | hid_err(hdev, "parse failed\n"); |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 2294 | return ret; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2295 | } |
| 2296 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 2297 | if (sc->quirks & VAIO_RDESC_CONSTANT) |
| 2298 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
Antonio Ospite | 5076465 | 2014-06-24 13:28:40 +0200 | [diff] [blame] | 2299 | else if (sc->quirks & SIXAXIS_CONTROLLER) |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 2300 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
| 2301 | |
| 2302 | ret = hid_hw_start(hdev, connect_mask); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2303 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 2304 | hid_err(hdev, "hw start failed\n"); |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 2305 | return ret; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2306 | } |
| 2307 | |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 2308 | ret = sony_set_device_id(sc); |
| 2309 | if (ret < 0) { |
| 2310 | hid_err(hdev, "failed to allocate the device id\n"); |
| 2311 | goto err_stop; |
| 2312 | } |
| 2313 | |
Frank Praznik | 131a8a9 | 2015-05-05 20:47:28 -0400 | [diff] [blame] | 2314 | ret = sony_allocate_output_report(sc); |
| 2315 | if (ret < 0) { |
| 2316 | hid_err(hdev, "failed to allocate the output report buffer\n"); |
| 2317 | goto err_stop; |
| 2318 | } |
| 2319 | |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 2320 | if ((sc->quirks & SIXAXIS_CONTROLLER_USB) || |
| 2321 | (sc->quirks & NAVIGATION_CONTROLLER_USB)) { |
Benjamin Tissoires | e534a93 | 2014-03-08 22:52:42 -0500 | [diff] [blame] | 2322 | /* |
| 2323 | * The Sony Sixaxis does not handle HID Output Reports on the |
| 2324 | * Interrupt EP like it could, so we need to force HID Output |
| 2325 | * Reports to use HID_REQ_SET_REPORT on the Control EP. |
| 2326 | * |
| 2327 | * There is also another issue about HID Output Reports via USB, |
| 2328 | * the Sixaxis does not want the report_id as part of the data |
| 2329 | * packet, so we have to discard buf[0] when sending the actual |
| 2330 | * control message, even for numbered reports, humpf! |
| 2331 | */ |
| 2332 | hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; |
| 2333 | hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID; |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 2334 | ret = sixaxis_set_operational_usb(hdev); |
Frank Praznik | d8aaccd | 2015-11-11 09:49:37 -0500 | [diff] [blame] | 2335 | sony_init_output_report(sc, sixaxis_send_output_report); |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 2336 | } else if ((sc->quirks & SIXAXIS_CONTROLLER_BT) || |
| 2337 | (sc->quirks & NAVIGATION_CONTROLLER_BT)) { |
Frank Praznik | 2078b9bb | 2014-03-15 09:41:16 -0400 | [diff] [blame] | 2338 | /* |
| 2339 | * The Sixaxis wants output reports sent on the ctrl endpoint |
| 2340 | * when connected via Bluetooth. |
| 2341 | */ |
| 2342 | hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 2343 | ret = sixaxis_set_operational_bt(hdev); |
Frank Praznik | d8aaccd | 2015-11-11 09:49:37 -0500 | [diff] [blame] | 2344 | sony_init_output_report(sc, sixaxis_send_output_report); |
Frank Praznik | fee4e2d | 2014-02-18 17:22:01 -0500 | [diff] [blame] | 2345 | } else if (sc->quirks & DUALSHOCK4_CONTROLLER) { |
Frank Praznik | 68330d8 | 2014-02-05 20:03:49 -0500 | [diff] [blame] | 2346 | if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) { |
Frank Praznik | 2078b9bb | 2014-03-15 09:41:16 -0400 | [diff] [blame] | 2347 | /* |
| 2348 | * The DualShock 4 wants output reports sent on the ctrl |
| 2349 | * endpoint when connected via Bluetooth. |
| 2350 | */ |
| 2351 | hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; |
Frank Praznik | 68330d8 | 2014-02-05 20:03:49 -0500 | [diff] [blame] | 2352 | ret = dualshock4_set_operational_bt(hdev); |
| 2353 | if (ret < 0) { |
| 2354 | hid_err(hdev, "failed to set the Dualshock 4 operational mode\n"); |
| 2355 | goto err_stop; |
| 2356 | } |
| 2357 | } |
Frank Praznik | c4e1ddf | 2014-01-17 14:46:26 -0500 | [diff] [blame] | 2358 | |
Frank Praznik | d8aaccd | 2015-11-11 09:49:37 -0500 | [diff] [blame] | 2359 | sony_init_output_report(sc, dualshock4_send_output_report); |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 2360 | } else if (sc->quirks & MOTION_CONTROLLER) { |
Frank Praznik | d8aaccd | 2015-11-11 09:49:37 -0500 | [diff] [blame] | 2361 | sony_init_output_report(sc, motion_send_output_report); |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 2362 | } else { |
| 2363 | ret = 0; |
| 2364 | } |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 2365 | |
Jiri Kosina | 4dfdc46 | 2008-12-30 00:49:59 +0100 | [diff] [blame] | 2366 | if (ret < 0) |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2367 | goto err_stop; |
| 2368 | |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2369 | ret = sony_check_add(sc); |
| 2370 | if (ret < 0) |
| 2371 | goto err_stop; |
| 2372 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 2373 | if (sc->quirks & SONY_LED_SUPPORT) { |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 2374 | ret = sony_leds_init(sc); |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 2375 | if (ret < 0) |
| 2376 | goto err_stop; |
| 2377 | } |
| 2378 | |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 2379 | if (sc->quirks & SONY_BATTERY_SUPPORT) { |
| 2380 | ret = sony_battery_probe(sc); |
| 2381 | if (ret < 0) |
| 2382 | goto err_stop; |
| 2383 | |
| 2384 | /* Open the device to receive reports with battery info */ |
| 2385 | ret = hid_hw_open(hdev); |
| 2386 | if (ret < 0) { |
| 2387 | hid_err(hdev, "hw open failed\n"); |
| 2388 | goto err_stop; |
| 2389 | } |
| 2390 | } |
| 2391 | |
Frank Praznik | c8de9db | 2014-02-20 11:36:01 -0500 | [diff] [blame] | 2392 | if (sc->quirks & SONY_FF_SUPPORT) { |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 2393 | ret = sony_init_ff(sc); |
Frank Praznik | c8de9db | 2014-02-20 11:36:01 -0500 | [diff] [blame] | 2394 | if (ret < 0) |
| 2395 | goto err_close; |
Frank Praznik | 5f5750d | 2014-02-19 13:09:22 -0500 | [diff] [blame] | 2396 | } |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 2397 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2398 | return 0; |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 2399 | err_close: |
| 2400 | hid_hw_close(hdev); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2401 | err_stop: |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 2402 | if (sc->quirks & SONY_LED_SUPPORT) |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 2403 | sony_leds_remove(sc); |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 2404 | if (sc->quirks & SONY_BATTERY_SUPPORT) |
| 2405 | sony_battery_remove(sc); |
Frank Praznik | 4626204 | 2014-04-14 10:11:31 -0400 | [diff] [blame] | 2406 | sony_cancel_work_sync(sc); |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 2407 | kfree(sc->output_report_dmabuf); |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2408 | sony_remove_dev_list(sc); |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 2409 | sony_release_device_id(sc); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2410 | hid_hw_stop(hdev); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2411 | return ret; |
| 2412 | } |
| 2413 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 2414 | static void sony_remove(struct hid_device *hdev) |
| 2415 | { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 2416 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 2417 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 2418 | if (sc->quirks & SONY_LED_SUPPORT) |
Frank Praznik | fa57a81 | 2014-04-14 10:11:33 -0400 | [diff] [blame] | 2419 | sony_leds_remove(sc); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 2420 | |
Frank Praznik | d902f47 | 2014-01-27 10:17:36 -0500 | [diff] [blame] | 2421 | if (sc->quirks & SONY_BATTERY_SUPPORT) { |
| 2422 | hid_hw_close(hdev); |
| 2423 | sony_battery_remove(sc); |
| 2424 | } |
| 2425 | |
Frank Praznik | 4626204 | 2014-04-14 10:11:31 -0400 | [diff] [blame] | 2426 | sony_cancel_work_sync(sc); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 2427 | |
Frank Praznik | 9b2b5c9 | 2014-11-12 14:10:09 -0500 | [diff] [blame] | 2428 | kfree(sc->output_report_dmabuf); |
| 2429 | |
Frank Praznik | d2d782f | 2014-02-20 11:36:03 -0500 | [diff] [blame] | 2430 | sony_remove_dev_list(sc); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2431 | |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 2432 | sony_release_device_id(sc); |
| 2433 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2434 | hid_hw_stop(hdev); |
| 2435 | } |
| 2436 | |
Frank Praznik | decd946 | 2015-11-11 09:49:38 -0500 | [diff] [blame] | 2437 | #ifdef CONFIG_PM |
| 2438 | |
| 2439 | static int sony_suspend(struct hid_device *hdev, pm_message_t message) |
| 2440 | { |
| 2441 | /* |
| 2442 | * On suspend save the current LED state, |
| 2443 | * stop running force-feedback and blank the LEDS. |
| 2444 | */ |
| 2445 | if (SONY_LED_SUPPORT || SONY_FF_SUPPORT) { |
| 2446 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 2447 | |
| 2448 | #ifdef CONFIG_SONY_FF |
| 2449 | sc->left = sc->right = 0; |
| 2450 | #endif |
| 2451 | |
| 2452 | memcpy(sc->resume_led_state, sc->led_state, |
| 2453 | sizeof(sc->resume_led_state)); |
| 2454 | memset(sc->led_state, 0, sizeof(sc->led_state)); |
| 2455 | |
| 2456 | sony_send_output_report(sc); |
| 2457 | } |
| 2458 | |
| 2459 | return 0; |
| 2460 | } |
| 2461 | |
| 2462 | static int sony_resume(struct hid_device *hdev) |
| 2463 | { |
| 2464 | /* Restore the state of controller LEDs on resume */ |
| 2465 | if (SONY_LED_SUPPORT) { |
| 2466 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 2467 | |
| 2468 | memcpy(sc->led_state, sc->resume_led_state, |
| 2469 | sizeof(sc->led_state)); |
| 2470 | |
| 2471 | /* |
| 2472 | * The Sixaxis and navigation controllers on USB need to be |
| 2473 | * reinitialized on resume or they won't behave properly. |
| 2474 | */ |
| 2475 | if ((sc->quirks & SIXAXIS_CONTROLLER_USB) || |
| 2476 | (sc->quirks & NAVIGATION_CONTROLLER_USB)) |
| 2477 | sixaxis_set_operational_usb(sc->hdev); |
| 2478 | |
| 2479 | sony_set_leds(sc); |
| 2480 | } |
| 2481 | |
| 2482 | return 0; |
| 2483 | } |
| 2484 | |
| 2485 | #endif |
| 2486 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2487 | static const struct hid_device_id sony_devices[] = { |
| 2488 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER), |
| 2489 | .driver_data = SIXAXIS_CONTROLLER_USB }, |
| 2490 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER), |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 2491 | .driver_data = NAVIGATION_CONTROLLER_USB }, |
Simon Wood | 6eabaaa | 2015-06-17 00:08:51 -0600 | [diff] [blame] | 2492 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER), |
Simon Wood | 4545ee0 | 2015-06-17 00:08:52 -0600 | [diff] [blame] | 2493 | .driver_data = NAVIGATION_CONTROLLER_BT }, |
Frank Praznik | c5e0c1c | 2015-05-05 20:47:30 -0400 | [diff] [blame] | 2494 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER), |
Simon Wood | b3bca32 | 2015-06-09 21:27:04 -0600 | [diff] [blame] | 2495 | .driver_data = MOTION_CONTROLLER_USB }, |
Simon Wood | a4afa85 | 2015-06-03 09:45:19 -0600 | [diff] [blame] | 2496 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_MOTION_CONTROLLER), |
Simon Wood | b3bca32 | 2015-06-09 21:27:04 -0600 | [diff] [blame] | 2497 | .driver_data = MOTION_CONTROLLER_BT }, |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2498 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER), |
| 2499 | .driver_data = SIXAXIS_CONTROLLER_BT }, |
| 2500 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE), |
| 2501 | .driver_data = VAIO_RDESC_CONSTANT }, |
| 2502 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE), |
| 2503 | .driver_data = VAIO_RDESC_CONSTANT }, |
| 2504 | /* Wired Buzz Controller. Reported as Sony Hub from its USB ID and as |
| 2505 | * Logitech joystick from the device descriptor. */ |
| 2506 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER), |
| 2507 | .driver_data = BUZZ_CONTROLLER }, |
| 2508 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER), |
| 2509 | .driver_data = BUZZ_CONTROLLER }, |
| 2510 | /* PS3 BD Remote Control */ |
| 2511 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE), |
| 2512 | .driver_data = PS3REMOTE }, |
| 2513 | /* Logitech Harmony Adapter for PS3 */ |
| 2514 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3), |
| 2515 | .driver_data = PS3REMOTE }, |
Frank Praznik | 68a49e5 | 2014-11-12 14:52:28 -0500 | [diff] [blame] | 2516 | /* SMK-Link PS3 BD Remote Control */ |
| 2517 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SMK, USB_DEVICE_ID_SMK_PS3_BDREMOTE), |
| 2518 | .driver_data = PS3REMOTE }, |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 2519 | /* Sony Dualshock 4 controllers for PS4 */ |
| 2520 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER), |
Frank Praznik | 8ab1676 | 2014-01-16 21:42:31 -0500 | [diff] [blame] | 2521 | .driver_data = DUALSHOCK4_CONTROLLER_USB }, |
Frank Praznik | 0bd88dd | 2014-01-11 15:12:42 -0500 | [diff] [blame] | 2522 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER), |
Frank Praznik | 8ab1676 | 2014-01-16 21:42:31 -0500 | [diff] [blame] | 2523 | .driver_data = DUALSHOCK4_CONTROLLER_BT }, |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2524 | { } |
| 2525 | }; |
| 2526 | MODULE_DEVICE_TABLE(hid, sony_devices); |
| 2527 | |
| 2528 | static struct hid_driver sony_driver = { |
Frank Praznik | ce8efc3 | 2014-09-18 21:15:01 -0400 | [diff] [blame] | 2529 | .name = "sony", |
| 2530 | .id_table = sony_devices, |
| 2531 | .input_mapping = sony_mapping, |
| 2532 | .input_configured = sony_input_configured, |
| 2533 | .probe = sony_probe, |
| 2534 | .remove = sony_remove, |
| 2535 | .report_fixup = sony_report_fixup, |
Frank Praznik | decd946 | 2015-11-11 09:49:38 -0500 | [diff] [blame] | 2536 | .raw_event = sony_raw_event, |
| 2537 | |
| 2538 | #ifdef CONFIG_PM |
| 2539 | .suspend = sony_suspend, |
| 2540 | .resume = sony_resume, |
| 2541 | .reset_resume = sony_resume, |
| 2542 | #endif |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2543 | }; |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 2544 | |
| 2545 | static int __init sony_init(void) |
| 2546 | { |
| 2547 | dbg_hid("Sony:%s\n", __func__); |
| 2548 | |
| 2549 | return hid_register_driver(&sony_driver); |
| 2550 | } |
| 2551 | |
| 2552 | static void __exit sony_exit(void) |
| 2553 | { |
| 2554 | dbg_hid("Sony:%s\n", __func__); |
| 2555 | |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 2556 | hid_unregister_driver(&sony_driver); |
Antonio Ospite | 6c40065 | 2015-02-16 22:58:24 +0100 | [diff] [blame] | 2557 | ida_destroy(&sony_device_id_allocator); |
Frank Praznik | 8025087 | 2014-04-14 10:11:35 -0400 | [diff] [blame] | 2558 | } |
| 2559 | module_init(sony_init); |
| 2560 | module_exit(sony_exit); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 2561 | |
| 2562 | MODULE_LICENSE("GPL"); |