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