Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 1 | /* |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 2 | * HID driver for Sony / PS2 / PS3 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> |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * This program is free software; you can redistribute it and/or modify it |
| 15 | * under the terms of the GNU General Public License as published by the Free |
| 16 | * Software Foundation; either version 2 of the License, or (at your option) |
| 17 | * any later version. |
| 18 | */ |
| 19 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 20 | /* NOTE: in order for the Sony PS3 BD Remote Control to be found by |
| 21 | * a Bluetooth host, the key combination Start+Enter has to be kept pressed |
| 22 | * for about 7 seconds with the Bluetooth Host Controller in discovering mode. |
| 23 | * |
| 24 | * There will be no PIN request from the device. |
| 25 | */ |
| 26 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 27 | #include <linux/device.h> |
| 28 | #include <linux/hid.h> |
| 29 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 31 | #include <linux/usb.h> |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 32 | #include <linux/leds.h> |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 33 | |
| 34 | #include "hid-ids.h" |
| 35 | |
Sven Eckelmann | f1c458c | 2013-11-19 20:26:29 +0100 | [diff] [blame] | 36 | #define VAIO_RDESC_CONSTANT BIT(0) |
| 37 | #define SIXAXIS_CONTROLLER_USB BIT(1) |
| 38 | #define SIXAXIS_CONTROLLER_BT BIT(2) |
| 39 | #define BUZZ_CONTROLLER BIT(3) |
| 40 | #define PS3REMOTE BIT(4) |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 41 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 42 | #define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER_USB | BUZZ_CONTROLLER) |
| 43 | |
Simon Wood | 61ab44b | 2011-06-10 12:00:26 +0200 | [diff] [blame] | 44 | static const u8 sixaxis_rdesc_fixup[] = { |
| 45 | 0x95, 0x13, 0x09, 0x01, 0x81, 0x02, 0x95, 0x0C, |
| 46 | 0x81, 0x01, 0x75, 0x10, 0x95, 0x04, 0x26, 0xFF, |
| 47 | 0x03, 0x46, 0xFF, 0x03, 0x09, 0x01, 0x81, 0x02 |
| 48 | }; |
| 49 | |
Mauro Carvalho Chehab | e57a67d | 2012-12-14 20:57:34 -0200 | [diff] [blame] | 50 | static const u8 sixaxis_rdesc_fixup2[] = { |
| 51 | 0x05, 0x01, 0x09, 0x04, 0xa1, 0x01, 0xa1, 0x02, |
| 52 | 0x85, 0x01, 0x75, 0x08, 0x95, 0x01, 0x15, 0x00, |
| 53 | 0x26, 0xff, 0x00, 0x81, 0x03, 0x75, 0x01, 0x95, |
| 54 | 0x13, 0x15, 0x00, 0x25, 0x01, 0x35, 0x00, 0x45, |
| 55 | 0x01, 0x05, 0x09, 0x19, 0x01, 0x29, 0x13, 0x81, |
| 56 | 0x02, 0x75, 0x01, 0x95, 0x0d, 0x06, 0x00, 0xff, |
| 57 | 0x81, 0x03, 0x15, 0x00, 0x26, 0xff, 0x00, 0x05, |
| 58 | 0x01, 0x09, 0x01, 0xa1, 0x00, 0x75, 0x08, 0x95, |
| 59 | 0x04, 0x35, 0x00, 0x46, 0xff, 0x00, 0x09, 0x30, |
| 60 | 0x09, 0x31, 0x09, 0x32, 0x09, 0x35, 0x81, 0x02, |
| 61 | 0xc0, 0x05, 0x01, 0x95, 0x13, 0x09, 0x01, 0x81, |
| 62 | 0x02, 0x95, 0x0c, 0x81, 0x01, 0x75, 0x10, 0x95, |
| 63 | 0x04, 0x26, 0xff, 0x03, 0x46, 0xff, 0x03, 0x09, |
| 64 | 0x01, 0x81, 0x02, 0xc0, 0xa1, 0x02, 0x85, 0x02, |
| 65 | 0x75, 0x08, 0x95, 0x30, 0x09, 0x01, 0xb1, 0x02, |
| 66 | 0xc0, 0xa1, 0x02, 0x85, 0xee, 0x75, 0x08, 0x95, |
| 67 | 0x30, 0x09, 0x01, 0xb1, 0x02, 0xc0, 0xa1, 0x02, |
| 68 | 0x85, 0xef, 0x75, 0x08, 0x95, 0x30, 0x09, 0x01, |
| 69 | 0xb1, 0x02, 0xc0, 0xc0, |
| 70 | }; |
| 71 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 72 | static __u8 ps3remote_rdesc[] = { |
| 73 | 0x05, 0x01, /* GUsagePage Generic Desktop */ |
| 74 | 0x09, 0x05, /* LUsage 0x05 [Game Pad] */ |
| 75 | 0xA1, 0x01, /* MCollection Application (mouse, keyboard) */ |
| 76 | |
| 77 | /* Use collection 1 for joypad buttons */ |
| 78 | 0xA1, 0x02, /* MCollection Logical (interrelated data) */ |
| 79 | |
| 80 | /* Ignore the 1st byte, maybe it is used for a controller |
| 81 | * number but it's not needed for correct operation */ |
| 82 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 83 | 0x95, 0x01, /* GReportCount 0x01 [1] */ |
| 84 | 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */ |
| 85 | |
| 86 | /* Bytes from 2nd to 4th are a bitmap for joypad buttons, for these |
| 87 | * buttons multiple keypresses are allowed */ |
| 88 | 0x05, 0x09, /* GUsagePage Button */ |
| 89 | 0x19, 0x01, /* LUsageMinimum 0x01 [Button 1 (primary/trigger)] */ |
| 90 | 0x29, 0x18, /* LUsageMaximum 0x18 [Button 24] */ |
| 91 | 0x14, /* GLogicalMinimum [0] */ |
| 92 | 0x25, 0x01, /* GLogicalMaximum 0x01 [1] */ |
| 93 | 0x75, 0x01, /* GReportSize 0x01 [1] */ |
| 94 | 0x95, 0x18, /* GReportCount 0x18 [24] */ |
| 95 | 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */ |
| 96 | |
| 97 | 0xC0, /* MEndCollection */ |
| 98 | |
| 99 | /* Use collection 2 for remote control buttons */ |
| 100 | 0xA1, 0x02, /* MCollection Logical (interrelated data) */ |
| 101 | |
| 102 | /* 5th byte is used for remote control buttons */ |
| 103 | 0x05, 0x09, /* GUsagePage Button */ |
| 104 | 0x18, /* LUsageMinimum [No button pressed] */ |
| 105 | 0x29, 0xFE, /* LUsageMaximum 0xFE [Button 254] */ |
| 106 | 0x14, /* GLogicalMinimum [0] */ |
| 107 | 0x26, 0xFE, 0x00, /* GLogicalMaximum 0x00FE [254] */ |
| 108 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 109 | 0x95, 0x01, /* GReportCount 0x01 [1] */ |
| 110 | 0x80, /* MInput */ |
| 111 | |
| 112 | /* Ignore bytes from 6th to 11th, 6th to 10th are always constant at |
| 113 | * 0xff and 11th is for press indication */ |
| 114 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 115 | 0x95, 0x06, /* GReportCount 0x06 [6] */ |
| 116 | 0x81, 0x01, /* MInput 0x01 (Const[0] Arr[1] Abs[2]) */ |
| 117 | |
| 118 | /* 12th byte is for battery strength */ |
| 119 | 0x05, 0x06, /* GUsagePage Generic Device Controls */ |
| 120 | 0x09, 0x20, /* LUsage 0x20 [Battery Strength] */ |
| 121 | 0x14, /* GLogicalMinimum [0] */ |
| 122 | 0x25, 0x05, /* GLogicalMaximum 0x05 [5] */ |
| 123 | 0x75, 0x08, /* GReportSize 0x08 [8] */ |
| 124 | 0x95, 0x01, /* GReportCount 0x01 [1] */ |
| 125 | 0x81, 0x02, /* MInput 0x02 (Data[0] Var[1] Abs[2]) */ |
| 126 | |
| 127 | 0xC0, /* MEndCollection */ |
| 128 | |
| 129 | 0xC0 /* MEndCollection [Game Pad] */ |
| 130 | }; |
| 131 | |
| 132 | static const unsigned int ps3remote_keymap_joypad_buttons[] = { |
| 133 | [0x01] = KEY_SELECT, |
| 134 | [0x02] = BTN_THUMBL, /* L3 */ |
| 135 | [0x03] = BTN_THUMBR, /* R3 */ |
| 136 | [0x04] = BTN_START, |
| 137 | [0x05] = KEY_UP, |
| 138 | [0x06] = KEY_RIGHT, |
| 139 | [0x07] = KEY_DOWN, |
| 140 | [0x08] = KEY_LEFT, |
| 141 | [0x09] = BTN_TL2, /* L2 */ |
| 142 | [0x0a] = BTN_TR2, /* R2 */ |
| 143 | [0x0b] = BTN_TL, /* L1 */ |
| 144 | [0x0c] = BTN_TR, /* R1 */ |
| 145 | [0x0d] = KEY_OPTION, /* options/triangle */ |
| 146 | [0x0e] = KEY_BACK, /* back/circle */ |
| 147 | [0x0f] = BTN_0, /* cross */ |
| 148 | [0x10] = KEY_SCREEN, /* view/square */ |
| 149 | [0x11] = KEY_HOMEPAGE, /* PS button */ |
| 150 | [0x14] = KEY_ENTER, |
| 151 | }; |
| 152 | static const unsigned int ps3remote_keymap_remote_buttons[] = { |
| 153 | [0x00] = KEY_1, |
| 154 | [0x01] = KEY_2, |
| 155 | [0x02] = KEY_3, |
| 156 | [0x03] = KEY_4, |
| 157 | [0x04] = KEY_5, |
| 158 | [0x05] = KEY_6, |
| 159 | [0x06] = KEY_7, |
| 160 | [0x07] = KEY_8, |
| 161 | [0x08] = KEY_9, |
| 162 | [0x09] = KEY_0, |
| 163 | [0x0e] = KEY_ESC, /* return */ |
| 164 | [0x0f] = KEY_CLEAR, |
| 165 | [0x16] = KEY_EJECTCD, |
| 166 | [0x1a] = KEY_MENU, /* top menu */ |
| 167 | [0x28] = KEY_TIME, |
| 168 | [0x30] = KEY_PREVIOUS, |
| 169 | [0x31] = KEY_NEXT, |
| 170 | [0x32] = KEY_PLAY, |
| 171 | [0x33] = KEY_REWIND, /* scan back */ |
| 172 | [0x34] = KEY_FORWARD, /* scan forward */ |
| 173 | [0x38] = KEY_STOP, |
| 174 | [0x39] = KEY_PAUSE, |
| 175 | [0x40] = KEY_CONTEXT_MENU, /* pop up/menu */ |
| 176 | [0x60] = KEY_FRAMEBACK, /* slow/step back */ |
| 177 | [0x61] = KEY_FRAMEFORWARD, /* slow/step forward */ |
| 178 | [0x63] = KEY_SUBTITLE, |
| 179 | [0x64] = KEY_AUDIO, |
| 180 | [0x65] = KEY_ANGLE, |
| 181 | [0x70] = KEY_INFO, /* display */ |
| 182 | [0x80] = KEY_BLUE, |
| 183 | [0x81] = KEY_RED, |
| 184 | [0x82] = KEY_GREEN, |
| 185 | [0x83] = KEY_YELLOW, |
| 186 | }; |
| 187 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 188 | static const unsigned int buzz_keymap[] = { |
| 189 | /* The controller has 4 remote buzzers, each with one LED and 5 |
| 190 | * buttons. |
| 191 | * |
| 192 | * We use the mapping chosen by the controller, which is: |
| 193 | * |
| 194 | * Key Offset |
| 195 | * ------------------- |
| 196 | * Buzz 1 |
| 197 | * Blue 5 |
| 198 | * Orange 4 |
| 199 | * Green 3 |
| 200 | * Yellow 2 |
| 201 | * |
| 202 | * So, for example, the orange button on the third buzzer is mapped to |
| 203 | * BTN_TRIGGER_HAPPY14 |
| 204 | */ |
| 205 | [ 1] = BTN_TRIGGER_HAPPY1, |
| 206 | [ 2] = BTN_TRIGGER_HAPPY2, |
| 207 | [ 3] = BTN_TRIGGER_HAPPY3, |
| 208 | [ 4] = BTN_TRIGGER_HAPPY4, |
| 209 | [ 5] = BTN_TRIGGER_HAPPY5, |
| 210 | [ 6] = BTN_TRIGGER_HAPPY6, |
| 211 | [ 7] = BTN_TRIGGER_HAPPY7, |
| 212 | [ 8] = BTN_TRIGGER_HAPPY8, |
| 213 | [ 9] = BTN_TRIGGER_HAPPY9, |
| 214 | [10] = BTN_TRIGGER_HAPPY10, |
| 215 | [11] = BTN_TRIGGER_HAPPY11, |
| 216 | [12] = BTN_TRIGGER_HAPPY12, |
| 217 | [13] = BTN_TRIGGER_HAPPY13, |
| 218 | [14] = BTN_TRIGGER_HAPPY14, |
| 219 | [15] = BTN_TRIGGER_HAPPY15, |
| 220 | [16] = BTN_TRIGGER_HAPPY16, |
| 221 | [17] = BTN_TRIGGER_HAPPY17, |
| 222 | [18] = BTN_TRIGGER_HAPPY18, |
| 223 | [19] = BTN_TRIGGER_HAPPY19, |
| 224 | [20] = BTN_TRIGGER_HAPPY20, |
| 225 | }; |
| 226 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 227 | struct sony_sc { |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 228 | struct hid_device *hdev; |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 229 | struct led_classdev *leds[4]; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 230 | unsigned long quirks; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 231 | struct work_struct state_worker; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 232 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 233 | #ifdef CONFIG_SONY_FF |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 234 | __u8 left; |
| 235 | __u8 right; |
| 236 | #endif |
| 237 | |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 238 | __u8 led_state; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 239 | }; |
| 240 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 241 | static __u8 *ps3remote_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 242 | unsigned int *rsize) |
| 243 | { |
| 244 | *rsize = sizeof(ps3remote_rdesc); |
| 245 | return ps3remote_rdesc; |
| 246 | } |
| 247 | |
| 248 | static int ps3remote_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 249 | struct hid_field *field, struct hid_usage *usage, |
| 250 | unsigned long **bit, int *max) |
| 251 | { |
| 252 | unsigned int key = usage->hid & HID_USAGE; |
| 253 | |
| 254 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) |
| 255 | return -1; |
| 256 | |
| 257 | switch (usage->collection_index) { |
| 258 | case 1: |
| 259 | if (key >= ARRAY_SIZE(ps3remote_keymap_joypad_buttons)) |
| 260 | return -1; |
| 261 | |
| 262 | key = ps3remote_keymap_joypad_buttons[key]; |
| 263 | if (!key) |
| 264 | return -1; |
| 265 | break; |
| 266 | case 2: |
| 267 | if (key >= ARRAY_SIZE(ps3remote_keymap_remote_buttons)) |
| 268 | return -1; |
| 269 | |
| 270 | key = ps3remote_keymap_remote_buttons[key]; |
| 271 | if (!key) |
| 272 | return -1; |
| 273 | break; |
| 274 | default: |
| 275 | return -1; |
| 276 | } |
| 277 | |
| 278 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key); |
| 279 | return 1; |
| 280 | } |
| 281 | |
| 282 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 283 | /* Sony Vaio VGX has wrongly mouse pointer declared as constant */ |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 284 | static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 285 | unsigned int *rsize) |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 286 | { |
| 287 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 288 | |
Fernando Luis Vázquez Cao | 99d2490 | 2013-01-22 15:20:38 +0900 | [diff] [blame] | 289 | /* |
| 290 | * Some Sony RF receivers wrongly declare the mouse pointer as a |
| 291 | * a constant non-data variable. |
| 292 | */ |
| 293 | if ((sc->quirks & VAIO_RDESC_CONSTANT) && *rsize >= 56 && |
| 294 | /* usage page: generic desktop controls */ |
| 295 | /* rdesc[0] == 0x05 && rdesc[1] == 0x01 && */ |
| 296 | /* usage: mouse */ |
| 297 | rdesc[2] == 0x09 && rdesc[3] == 0x02 && |
| 298 | /* input (usage page for x,y axes): constant, variable, relative */ |
| 299 | rdesc[54] == 0x81 && rdesc[55] == 0x07) { |
Fernando Luis Vázquez Cao | a4649184 | 2013-01-15 19:40:48 +0900 | [diff] [blame] | 300 | 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] | 301 | /* input: data, variable, relative */ |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 302 | rdesc[55] = 0x06; |
| 303 | } |
Simon Wood | 61ab44b | 2011-06-10 12:00:26 +0200 | [diff] [blame] | 304 | |
| 305 | /* The HID descriptor exposed over BT has a trailing zero byte */ |
| 306 | if ((((sc->quirks & SIXAXIS_CONTROLLER_USB) && *rsize == 148) || |
| 307 | ((sc->quirks & SIXAXIS_CONTROLLER_BT) && *rsize == 149)) && |
| 308 | rdesc[83] == 0x75) { |
| 309 | hid_info(hdev, "Fixing up Sony Sixaxis report descriptor\n"); |
| 310 | memcpy((void *)&rdesc[83], (void *)&sixaxis_rdesc_fixup, |
| 311 | sizeof(sixaxis_rdesc_fixup)); |
Mauro Carvalho Chehab | e57a67d | 2012-12-14 20:57:34 -0200 | [diff] [blame] | 312 | } else if (sc->quirks & SIXAXIS_CONTROLLER_USB && |
| 313 | *rsize > sizeof(sixaxis_rdesc_fixup2)) { |
| 314 | hid_info(hdev, "Sony Sixaxis clone detected. Using original report descriptor (size: %d clone; %d new)\n", |
| 315 | *rsize, (int)sizeof(sixaxis_rdesc_fixup2)); |
| 316 | *rsize = sizeof(sixaxis_rdesc_fixup2); |
| 317 | memcpy(rdesc, &sixaxis_rdesc_fixup2, *rsize); |
Simon Wood | 61ab44b | 2011-06-10 12:00:26 +0200 | [diff] [blame] | 318 | } |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 319 | |
| 320 | if (sc->quirks & PS3REMOTE) |
| 321 | return ps3remote_fixup(hdev, rdesc, rsize); |
| 322 | |
Nikolai Kondrashov | 73e4008 | 2010-08-06 23:03:06 +0400 | [diff] [blame] | 323 | return rdesc; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 324 | } |
| 325 | |
Simon Wood | c9e4d87 | 2011-06-10 12:00:27 +0200 | [diff] [blame] | 326 | static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, |
| 327 | __u8 *rd, int size) |
| 328 | { |
| 329 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 330 | |
| 331 | /* Sixaxis HID report has acclerometers/gyro with MSByte first, this |
| 332 | * has to be BYTE_SWAPPED before passing up to joystick interface |
| 333 | */ |
| 334 | if ((sc->quirks & (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT)) && |
| 335 | rd[0] == 0x01 && size == 49) { |
| 336 | swap(rd[41], rd[42]); |
| 337 | swap(rd[43], rd[44]); |
| 338 | swap(rd[45], rd[46]); |
| 339 | swap(rd[47], rd[48]); |
| 340 | } |
| 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 345 | static int sony_mapping(struct hid_device *hdev, struct hid_input *hi, |
| 346 | struct hid_field *field, struct hid_usage *usage, |
| 347 | unsigned long **bit, int *max) |
| 348 | { |
| 349 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 350 | |
| 351 | if (sc->quirks & BUZZ_CONTROLLER) { |
| 352 | unsigned int key = usage->hid & HID_USAGE; |
| 353 | |
| 354 | if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON) |
| 355 | return -1; |
| 356 | |
| 357 | switch (usage->collection_index) { |
| 358 | case 1: |
| 359 | if (key >= ARRAY_SIZE(buzz_keymap)) |
| 360 | return -1; |
| 361 | |
| 362 | key = buzz_keymap[key]; |
| 363 | if (!key) |
| 364 | return -1; |
| 365 | break; |
| 366 | default: |
| 367 | return -1; |
| 368 | } |
| 369 | |
| 370 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key); |
| 371 | return 1; |
| 372 | } |
| 373 | |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 374 | if (sc->quirks & PS3REMOTE) |
| 375 | return ps3remote_mapping(hdev, hi, field, usage, bit, max); |
| 376 | |
Benjamin Tissoires | 6f49801 | 2013-07-24 16:53:07 +0200 | [diff] [blame] | 377 | /* Let hid-core decide for the others */ |
| 378 | return 0; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 379 | } |
| 380 | |
Antonio Ospite | 5710fab | 2011-02-20 18:26:45 +0100 | [diff] [blame] | 381 | /* |
| 382 | * The Sony Sixaxis does not handle HID Output Reports on the Interrupt EP |
| 383 | * like it should according to usbhid/hid-core.c::usbhid_output_raw_report() |
| 384 | * so we need to override that forcing HID Output Reports on the Control EP. |
| 385 | * |
| 386 | * There is also another issue about HID Output Reports via USB, the Sixaxis |
| 387 | * does not want the report_id as part of the data packet, so we have to |
| 388 | * discard buf[0] when sending the actual control message, even for numbered |
| 389 | * reports, humpf! |
| 390 | */ |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 391 | static int sixaxis_usb_output_raw_report(struct hid_device *hid, __u8 *buf, |
| 392 | size_t count, unsigned char report_type) |
| 393 | { |
| 394 | struct usb_interface *intf = to_usb_interface(hid->dev.parent); |
| 395 | struct usb_device *dev = interface_to_usbdev(intf); |
| 396 | struct usb_host_interface *interface = intf->cur_altsetting; |
| 397 | int report_id = buf[0]; |
| 398 | int ret; |
| 399 | |
Antonio Ospite | 5710fab | 2011-02-20 18:26:45 +0100 | [diff] [blame] | 400 | if (report_type == HID_OUTPUT_REPORT) { |
| 401 | /* Don't send the Report ID */ |
| 402 | buf++; |
| 403 | count--; |
| 404 | } |
| 405 | |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 406 | ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
| 407 | HID_REQ_SET_REPORT, |
| 408 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 409 | ((report_type + 1) << 8) | report_id, |
| 410 | interface->desc.bInterfaceNumber, buf, count, |
| 411 | USB_CTRL_SET_TIMEOUT); |
| 412 | |
Antonio Ospite | 5710fab | 2011-02-20 18:26:45 +0100 | [diff] [blame] | 413 | /* Count also the Report ID, in case of an Output report. */ |
| 414 | if (ret > 0 && report_type == HID_OUTPUT_REPORT) |
| 415 | ret++; |
| 416 | |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 417 | return ret; |
| 418 | } |
| 419 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 420 | /* |
| 421 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller |
| 422 | * to "operational". Without this, the ps3 controller will not report any |
| 423 | * events. |
| 424 | */ |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 425 | static int sixaxis_set_operational_usb(struct hid_device *hdev) |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 426 | { |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 427 | int ret; |
| 428 | char *buf = kmalloc(18, GFP_KERNEL); |
| 429 | |
| 430 | if (!buf) |
| 431 | return -ENOMEM; |
| 432 | |
Benjamin Tissoires | f204828a | 2013-09-11 22:12:25 +0200 | [diff] [blame] | 433 | ret = hdev->hid_get_raw_report(hdev, 0xf2, buf, 17, HID_FEATURE_REPORT); |
| 434 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 435 | if (ret < 0) |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 436 | hid_err(hdev, "can't set operational mode\n"); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 437 | |
| 438 | kfree(buf); |
| 439 | |
| 440 | return ret; |
| 441 | } |
| 442 | |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 443 | static int sixaxis_set_operational_bt(struct hid_device *hdev) |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 444 | { |
Antonio Ospite | fddb33f | 2010-05-03 17:19:03 +0200 | [diff] [blame] | 445 | unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 }; |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 446 | return hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT); |
| 447 | } |
| 448 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 449 | static void buzz_set_leds(struct hid_device *hdev, int leds) |
| 450 | { |
| 451 | struct list_head *report_list = |
| 452 | &hdev->report_enum[HID_OUTPUT_REPORT].report_list; |
| 453 | struct hid_report *report = list_entry(report_list->next, |
| 454 | struct hid_report, list); |
| 455 | __s32 *value = report->field[0]->value; |
| 456 | |
| 457 | value[0] = 0x00; |
| 458 | value[1] = (leds & 1) ? 0xff : 0x00; |
| 459 | value[2] = (leds & 2) ? 0xff : 0x00; |
| 460 | value[3] = (leds & 4) ? 0xff : 0x00; |
| 461 | value[4] = (leds & 8) ? 0xff : 0x00; |
| 462 | value[5] = 0x00; |
| 463 | value[6] = 0x00; |
| 464 | hid_hw_request(hdev, report, HID_REQ_SET_REPORT); |
| 465 | } |
| 466 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 467 | static void sony_set_leds(struct hid_device *hdev, __u8 leds) |
| 468 | { |
| 469 | struct sony_sc *drv_data = hid_get_drvdata(hdev); |
| 470 | |
| 471 | if (drv_data->quirks & BUZZ_CONTROLLER) { |
| 472 | buzz_set_leds(hdev, leds); |
| 473 | } else if (drv_data->quirks & SIXAXIS_CONTROLLER_USB) { |
| 474 | drv_data->led_state = leds; |
| 475 | schedule_work(&drv_data->state_worker); |
| 476 | } |
| 477 | } |
| 478 | |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 479 | static void sony_led_set_brightness(struct led_classdev *led, |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 480 | enum led_brightness value) |
| 481 | { |
| 482 | struct device *dev = led->dev->parent; |
| 483 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 484 | struct sony_sc *drv_data; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 485 | |
| 486 | int n; |
| 487 | |
| 488 | drv_data = hid_get_drvdata(hdev); |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 489 | if (!drv_data) { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 490 | hid_err(hdev, "No device data\n"); |
| 491 | return; |
| 492 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 493 | |
| 494 | for (n = 0; n < 4; n++) { |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 495 | if (led == drv_data->leds[n]) { |
| 496 | int on = !!(drv_data->led_state & (1 << n)); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 497 | if (value == LED_OFF && on) { |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 498 | drv_data->led_state &= ~(1 << n); |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 499 | sony_set_leds(hdev, drv_data->led_state); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 500 | } else if (value != LED_OFF && !on) { |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 501 | drv_data->led_state |= (1 << n); |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 502 | sony_set_leds(hdev, drv_data->led_state); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 503 | } |
| 504 | break; |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 509 | static enum led_brightness sony_led_get_brightness(struct led_classdev *led) |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 510 | { |
| 511 | struct device *dev = led->dev->parent; |
| 512 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 513 | struct sony_sc *drv_data; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 514 | |
| 515 | int n; |
| 516 | int on = 0; |
| 517 | |
| 518 | drv_data = hid_get_drvdata(hdev); |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 519 | if (!drv_data) { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 520 | hid_err(hdev, "No device data\n"); |
| 521 | return LED_OFF; |
| 522 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 523 | |
| 524 | for (n = 0; n < 4; n++) { |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 525 | if (led == drv_data->leds[n]) { |
| 526 | on = !!(drv_data->led_state & (1 << n)); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 527 | break; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | return on ? LED_FULL : LED_OFF; |
| 532 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 533 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 534 | static void sony_leds_remove(struct hid_device *hdev) |
| 535 | { |
| 536 | struct sony_sc *drv_data; |
| 537 | struct led_classdev *led; |
| 538 | int n; |
| 539 | |
| 540 | drv_data = hid_get_drvdata(hdev); |
| 541 | BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT)); |
| 542 | |
| 543 | for (n = 0; n < 4; n++) { |
| 544 | led = drv_data->leds[n]; |
| 545 | drv_data->leds[n] = NULL; |
| 546 | if (!led) |
| 547 | continue; |
| 548 | led_classdev_unregister(led); |
| 549 | kfree(led); |
| 550 | } |
| 551 | } |
| 552 | |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 553 | static int sony_leds_init(struct hid_device *hdev) |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 554 | { |
| 555 | struct sony_sc *drv_data; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 556 | int n, ret = 0; |
| 557 | struct led_classdev *led; |
| 558 | size_t name_sz; |
| 559 | char *name; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 560 | size_t name_len; |
| 561 | const char *name_fmt; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 562 | |
| 563 | drv_data = hid_get_drvdata(hdev); |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 564 | BUG_ON(!(drv_data->quirks & SONY_LED_SUPPORT)); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 565 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 566 | if (drv_data->quirks & BUZZ_CONTROLLER) { |
| 567 | name_len = strlen("::buzz#"); |
| 568 | name_fmt = "%s::buzz%d"; |
| 569 | /* Validate expected report characteristics. */ |
| 570 | if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 0, 0, 7)) |
| 571 | return -ENODEV; |
| 572 | } else { |
| 573 | name_len = strlen("::sony#"); |
| 574 | name_fmt = "%s::sony%d"; |
| 575 | } |
Kees Cook | 9446edb | 2013-09-11 21:56:52 +0200 | [diff] [blame] | 576 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 577 | /* Clear LEDs as we have no way of reading their initial state. This is |
| 578 | * only relevant if the driver is loaded after somebody actively set the |
| 579 | * LEDs to on */ |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 580 | sony_set_leds(hdev, 0x00); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 581 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 582 | name_sz = strlen(dev_name(&hdev->dev)) + name_len + 1; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 583 | |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 584 | for (n = 0; n < 4; n++) { |
| 585 | led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL); |
| 586 | if (!led) { |
| 587 | hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); |
Julia Lawall | 8cd5fcd | 2013-12-29 23:47:27 +0100 | [diff] [blame^] | 588 | ret = -ENOMEM; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 589 | goto error_leds; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 590 | } |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 591 | |
| 592 | name = (void *)(&led[1]); |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 593 | snprintf(name, name_sz, name_fmt, dev_name(&hdev->dev), n + 1); |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 594 | led->name = name; |
| 595 | led->brightness = 0; |
| 596 | led->max_brightness = 1; |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 597 | led->brightness_get = sony_led_get_brightness; |
| 598 | led->brightness_set = sony_led_set_brightness; |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 599 | |
Julia Lawall | 8cd5fcd | 2013-12-29 23:47:27 +0100 | [diff] [blame^] | 600 | ret = led_classdev_register(&hdev->dev, led); |
| 601 | if (ret) { |
Jiri Kosina | 40e32ee | 2013-05-28 11:22:09 +0200 | [diff] [blame] | 602 | hid_err(hdev, "Failed to register LED %d\n", n); |
| 603 | kfree(led); |
| 604 | goto error_leds; |
| 605 | } |
| 606 | |
Sven Eckelmann | 2251b85 | 2013-11-19 20:26:31 +0100 | [diff] [blame] | 607 | drv_data->leds[n] = led; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 608 | } |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 609 | |
| 610 | return ret; |
| 611 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 612 | error_leds: |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 613 | sony_leds_remove(hdev); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 614 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 615 | return ret; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 616 | } |
| 617 | |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 618 | static void sony_state_worker(struct work_struct *work) |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 619 | { |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 620 | struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 621 | unsigned char buf[] = { |
| 622 | 0x01, |
| 623 | 0x00, 0xff, 0x00, 0xff, 0x00, |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 624 | 0x00, 0x00, 0x00, 0x00, 0x00, |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 625 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 626 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 627 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 628 | 0xff, 0x27, 0x10, 0x00, 0x32, |
| 629 | 0x00, 0x00, 0x00, 0x00, 0x00 |
| 630 | }; |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 631 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 632 | #ifdef CONFIG_SONY_FF |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 633 | buf[3] = sc->right; |
| 634 | buf[5] = sc->left; |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 635 | #endif |
| 636 | |
| 637 | buf[10] |= (sc->led_state & 0xf) << 1; |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 638 | |
| 639 | sc->hdev->hid_output_raw_report(sc->hdev, buf, sizeof(buf), |
| 640 | HID_OUTPUT_REPORT); |
| 641 | } |
| 642 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 643 | #ifdef CONFIG_SONY_FF |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 644 | static int sony_play_effect(struct input_dev *dev, void *data, |
| 645 | struct ff_effect *effect) |
| 646 | { |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 647 | struct hid_device *hid = input_get_drvdata(dev); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 648 | struct sony_sc *sc = hid_get_drvdata(hid); |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 649 | |
| 650 | if (effect->type != FF_RUMBLE) |
| 651 | return 0; |
| 652 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 653 | sc->left = effect->u.rumble.strong_magnitude / 256; |
| 654 | sc->right = effect->u.rumble.weak_magnitude ? 1 : 0; |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 655 | |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 656 | schedule_work(&sc->state_worker); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 657 | return 0; |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | static int sony_init_ff(struct hid_device *hdev) |
| 661 | { |
| 662 | struct hid_input *hidinput = list_entry(hdev->inputs.next, |
| 663 | struct hid_input, list); |
| 664 | struct input_dev *input_dev = hidinput->input; |
| 665 | |
| 666 | input_set_capability(input_dev, EV_FF, FF_RUMBLE); |
| 667 | return input_ff_create_memless(input_dev, NULL, sony_play_effect); |
| 668 | } |
| 669 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 670 | static void sony_destroy_ff(struct hid_device *hdev) |
| 671 | { |
| 672 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 673 | |
Sven Eckelmann | 92b5c41 | 2013-11-19 20:26:28 +0100 | [diff] [blame] | 674 | cancel_work_sync(&sc->state_worker); |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 675 | } |
| 676 | |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 677 | #else |
| 678 | static int sony_init_ff(struct hid_device *hdev) |
| 679 | { |
| 680 | return 0; |
| 681 | } |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 682 | |
| 683 | static void sony_destroy_ff(struct hid_device *hdev) |
| 684 | { |
| 685 | } |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 686 | #endif |
| 687 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 688 | static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 689 | { |
| 690 | int ret; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 691 | unsigned long quirks = id->driver_data; |
| 692 | struct sony_sc *sc; |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 693 | unsigned int connect_mask = HID_CONNECT_DEFAULT; |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 694 | |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 695 | sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL); |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 696 | if (sc == NULL) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 697 | hid_err(hdev, "can't alloc sony descriptor\n"); |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 698 | return -ENOMEM; |
| 699 | } |
| 700 | |
| 701 | sc->quirks = quirks; |
| 702 | hid_set_drvdata(hdev, sc); |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 703 | sc->hdev = hdev; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 704 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 705 | ret = hid_parse(hdev); |
| 706 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 707 | hid_err(hdev, "parse failed\n"); |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 708 | return ret; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 709 | } |
| 710 | |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 711 | if (sc->quirks & VAIO_RDESC_CONSTANT) |
| 712 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
| 713 | else if (sc->quirks & SIXAXIS_CONTROLLER_USB) |
| 714 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
| 715 | else if (sc->quirks & SIXAXIS_CONTROLLER_BT) |
| 716 | connect_mask |= HID_CONNECT_HIDDEV_FORCE; |
| 717 | |
| 718 | ret = hid_hw_start(hdev, connect_mask); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 719 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 720 | hid_err(hdev, "hw start failed\n"); |
Benjamin Tissoires | abf832b | 2013-07-24 19:38:04 +0200 | [diff] [blame] | 721 | return ret; |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 722 | } |
| 723 | |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 724 | if (sc->quirks & SIXAXIS_CONTROLLER_USB) { |
| 725 | hdev->hid_output_raw_report = sixaxis_usb_output_raw_report; |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 726 | ret = sixaxis_set_operational_usb(hdev); |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 727 | INIT_WORK(&sc->state_worker, sony_state_worker); |
Antonio Ospite | 569b10a | 2010-10-19 16:13:10 +0200 | [diff] [blame] | 728 | } |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 729 | else if (sc->quirks & SIXAXIS_CONTROLLER_BT) |
| 730 | ret = sixaxis_set_operational_bt(hdev); |
| 731 | else |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 732 | ret = 0; |
Bastien Nocera | f9ce7c2 | 2010-01-20 12:01:53 +0000 | [diff] [blame] | 733 | |
Jiri Kosina | 4dfdc46 | 2008-12-30 00:49:59 +0100 | [diff] [blame] | 734 | if (ret < 0) |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 735 | goto err_stop; |
| 736 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 737 | if (sc->quirks & SONY_LED_SUPPORT) { |
| 738 | ret = sony_leds_init(hdev); |
| 739 | if (ret < 0) |
| 740 | goto err_stop; |
| 741 | } |
| 742 | |
Sven Eckelmann | a08c22c | 2013-11-09 19:25:57 +0100 | [diff] [blame] | 743 | ret = sony_init_ff(hdev); |
| 744 | if (ret < 0) |
| 745 | goto err_stop; |
| 746 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 747 | return 0; |
| 748 | err_stop: |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 749 | if (sc->quirks & SONY_LED_SUPPORT) |
| 750 | sony_leds_remove(hdev); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 751 | hid_hw_stop(hdev); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 752 | return ret; |
| 753 | } |
| 754 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 755 | static void sony_remove(struct hid_device *hdev) |
| 756 | { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 757 | struct sony_sc *sc = hid_get_drvdata(hdev); |
| 758 | |
Sven Eckelmann | 0a286ef | 2013-11-19 20:26:32 +0100 | [diff] [blame] | 759 | if (sc->quirks & SONY_LED_SUPPORT) |
Sven Eckelmann | c538251 | 2013-11-19 20:26:30 +0100 | [diff] [blame] | 760 | sony_leds_remove(hdev); |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 761 | |
Sven Eckelmann | 9f323b6 | 2013-11-17 20:38:21 +0100 | [diff] [blame] | 762 | sony_destroy_ff(hdev); |
| 763 | |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 764 | hid_hw_stop(hdev); |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 765 | } |
| 766 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 767 | static const struct hid_device_id sony_devices[] = { |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 768 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER), |
| 769 | .driver_data = SIXAXIS_CONTROLLER_USB }, |
Jiri Kosina | 35dca5b | 2011-04-28 15:43:13 +0200 | [diff] [blame] | 770 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER), |
| 771 | .driver_data = SIXAXIS_CONTROLLER_USB }, |
Antonio Ospite | 816651a | 2010-05-03 22:15:55 +0200 | [diff] [blame] | 772 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER), |
| 773 | .driver_data = SIXAXIS_CONTROLLER_BT }, |
Jiri Kosina | cc6e0bb | 2008-10-23 12:58:38 +0200 | [diff] [blame] | 774 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE), |
| 775 | .driver_data = VAIO_RDESC_CONSTANT }, |
Fernando Luis Vázquez Cao | a4649184 | 2013-01-15 19:40:48 +0900 | [diff] [blame] | 776 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE), |
| 777 | .driver_data = VAIO_RDESC_CONSTANT }, |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 778 | /* Wired Buzz Controller. Reported as Sony Hub from its USB ID and as |
| 779 | * Logitech joystick from the device descriptor. */ |
| 780 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER), |
| 781 | .driver_data = BUZZ_CONTROLLER }, |
| 782 | { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER), |
| 783 | .driver_data = BUZZ_CONTROLLER }, |
Jiri Kosina | 078328d | 2013-06-13 12:03:49 +0200 | [diff] [blame] | 784 | /* PS3 BD Remote Control */ |
| 785 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE), |
| 786 | .driver_data = PS3REMOTE }, |
| 787 | /* Logitech Harmony Adapter for PS3 */ |
| 788 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3), |
| 789 | .driver_data = PS3REMOTE }, |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 790 | { } |
| 791 | }; |
| 792 | MODULE_DEVICE_TABLE(hid, sony_devices); |
| 793 | |
| 794 | static struct hid_driver sony_driver = { |
Colin Leitner | f04d514 | 2013-05-27 23:41:05 +0200 | [diff] [blame] | 795 | .name = "sony", |
| 796 | .id_table = sony_devices, |
| 797 | .input_mapping = sony_mapping, |
| 798 | .probe = sony_probe, |
| 799 | .remove = sony_remove, |
| 800 | .report_fixup = sony_report_fixup, |
| 801 | .raw_event = sony_raw_event |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 802 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 803 | module_hid_driver(sony_driver); |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 804 | |
Jiri Slaby | bd28ce0 | 2008-06-25 23:47:04 +0200 | [diff] [blame] | 805 | MODULE_LICENSE("GPL"); |