blob: f1c906176615640ac458f7ebf27290f0be3f7dde [file] [log] [blame]
Jiri Slabybd28ce02008-06-25 23:47:04 +02001/*
2 * HID driver for some sony "special" devices
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 Slabybd28ce02008-06-25 23:47:04 +02007 * Copyright (c) 2008 Jiri Slaby
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +02008 * Copyright (c) 2006-2008 Jiri Kosina
Colin Leitnerf04d5142013-05-27 23:41:05 +02009 * Copyright (c) 2013 Colin Leitner <colin.leitner@gmail.com>
Jiri Slabybd28ce02008-06-25 23:47:04 +020010 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Jiri Slabybd28ce02008-06-25 23:47:04 +020023#include <linux/usb.h>
Jiri Kosina40e32ee2013-05-28 11:22:09 +020024#include <linux/leds.h>
Jiri Slabybd28ce02008-06-25 23:47:04 +020025
26#include "hid-ids.h"
27
Antonio Ospite816651a2010-05-03 22:15:55 +020028#define VAIO_RDESC_CONSTANT (1 << 0)
29#define SIXAXIS_CONTROLLER_USB (1 << 1)
30#define SIXAXIS_CONTROLLER_BT (1 << 2)
Colin Leitnerf04d5142013-05-27 23:41:05 +020031#define BUZZ_CONTROLLER (1 << 3)
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +020032
Simon Wood61ab44b2011-06-10 12:00:26 +020033static const u8 sixaxis_rdesc_fixup[] = {
34 0x95, 0x13, 0x09, 0x01, 0x81, 0x02, 0x95, 0x0C,
35 0x81, 0x01, 0x75, 0x10, 0x95, 0x04, 0x26, 0xFF,
36 0x03, 0x46, 0xFF, 0x03, 0x09, 0x01, 0x81, 0x02
37};
38
Mauro Carvalho Chehabe57a67d2012-12-14 20:57:34 -020039static const u8 sixaxis_rdesc_fixup2[] = {
40 0x05, 0x01, 0x09, 0x04, 0xa1, 0x01, 0xa1, 0x02,
41 0x85, 0x01, 0x75, 0x08, 0x95, 0x01, 0x15, 0x00,
42 0x26, 0xff, 0x00, 0x81, 0x03, 0x75, 0x01, 0x95,
43 0x13, 0x15, 0x00, 0x25, 0x01, 0x35, 0x00, 0x45,
44 0x01, 0x05, 0x09, 0x19, 0x01, 0x29, 0x13, 0x81,
45 0x02, 0x75, 0x01, 0x95, 0x0d, 0x06, 0x00, 0xff,
46 0x81, 0x03, 0x15, 0x00, 0x26, 0xff, 0x00, 0x05,
47 0x01, 0x09, 0x01, 0xa1, 0x00, 0x75, 0x08, 0x95,
48 0x04, 0x35, 0x00, 0x46, 0xff, 0x00, 0x09, 0x30,
49 0x09, 0x31, 0x09, 0x32, 0x09, 0x35, 0x81, 0x02,
50 0xc0, 0x05, 0x01, 0x95, 0x13, 0x09, 0x01, 0x81,
51 0x02, 0x95, 0x0c, 0x81, 0x01, 0x75, 0x10, 0x95,
52 0x04, 0x26, 0xff, 0x03, 0x46, 0xff, 0x03, 0x09,
53 0x01, 0x81, 0x02, 0xc0, 0xa1, 0x02, 0x85, 0x02,
54 0x75, 0x08, 0x95, 0x30, 0x09, 0x01, 0xb1, 0x02,
55 0xc0, 0xa1, 0x02, 0x85, 0xee, 0x75, 0x08, 0x95,
56 0x30, 0x09, 0x01, 0xb1, 0x02, 0xc0, 0xa1, 0x02,
57 0x85, 0xef, 0x75, 0x08, 0x95, 0x30, 0x09, 0x01,
58 0xb1, 0x02, 0xc0, 0xc0,
59};
60
Colin Leitnerf04d5142013-05-27 23:41:05 +020061static const unsigned int buzz_keymap[] = {
62 /* The controller has 4 remote buzzers, each with one LED and 5
63 * buttons.
64 *
65 * We use the mapping chosen by the controller, which is:
66 *
67 * Key Offset
68 * -------------------
69 * Buzz 1
70 * Blue 5
71 * Orange 4
72 * Green 3
73 * Yellow 2
74 *
75 * So, for example, the orange button on the third buzzer is mapped to
76 * BTN_TRIGGER_HAPPY14
77 */
78 [ 1] = BTN_TRIGGER_HAPPY1,
79 [ 2] = BTN_TRIGGER_HAPPY2,
80 [ 3] = BTN_TRIGGER_HAPPY3,
81 [ 4] = BTN_TRIGGER_HAPPY4,
82 [ 5] = BTN_TRIGGER_HAPPY5,
83 [ 6] = BTN_TRIGGER_HAPPY6,
84 [ 7] = BTN_TRIGGER_HAPPY7,
85 [ 8] = BTN_TRIGGER_HAPPY8,
86 [ 9] = BTN_TRIGGER_HAPPY9,
87 [10] = BTN_TRIGGER_HAPPY10,
88 [11] = BTN_TRIGGER_HAPPY11,
89 [12] = BTN_TRIGGER_HAPPY12,
90 [13] = BTN_TRIGGER_HAPPY13,
91 [14] = BTN_TRIGGER_HAPPY14,
92 [15] = BTN_TRIGGER_HAPPY15,
93 [16] = BTN_TRIGGER_HAPPY16,
94 [17] = BTN_TRIGGER_HAPPY17,
95 [18] = BTN_TRIGGER_HAPPY18,
96 [19] = BTN_TRIGGER_HAPPY19,
97 [20] = BTN_TRIGGER_HAPPY20,
98};
99
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +0200100struct sony_sc {
101 unsigned long quirks;
Colin Leitnerf04d5142013-05-27 23:41:05 +0200102
103 void *extra;
104};
105
106struct buzz_extra {
Colin Leitnerf04d5142013-05-27 23:41:05 +0200107 int led_state;
108 struct led_classdev *leds[4];
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +0200109};
110
111/* Sony Vaio VGX has wrongly mouse pointer declared as constant */
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400112static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc,
113 unsigned int *rsize)
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +0200114{
115 struct sony_sc *sc = hid_get_drvdata(hdev);
116
Fernando Luis Vázquez Cao99d24902013-01-22 15:20:38 +0900117 /*
118 * Some Sony RF receivers wrongly declare the mouse pointer as a
119 * a constant non-data variable.
120 */
121 if ((sc->quirks & VAIO_RDESC_CONSTANT) && *rsize >= 56 &&
122 /* usage page: generic desktop controls */
123 /* rdesc[0] == 0x05 && rdesc[1] == 0x01 && */
124 /* usage: mouse */
125 rdesc[2] == 0x09 && rdesc[3] == 0x02 &&
126 /* input (usage page for x,y axes): constant, variable, relative */
127 rdesc[54] == 0x81 && rdesc[55] == 0x07) {
Fernando Luis Vázquez Caoa46491842013-01-15 19:40:48 +0900128 hid_info(hdev, "Fixing up Sony RF Receiver report descriptor\n");
Fernando Luis Vázquez Cao99d24902013-01-22 15:20:38 +0900129 /* input: data, variable, relative */
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +0200130 rdesc[55] = 0x06;
131 }
Simon Wood61ab44b2011-06-10 12:00:26 +0200132
133 /* The HID descriptor exposed over BT has a trailing zero byte */
134 if ((((sc->quirks & SIXAXIS_CONTROLLER_USB) && *rsize == 148) ||
135 ((sc->quirks & SIXAXIS_CONTROLLER_BT) && *rsize == 149)) &&
136 rdesc[83] == 0x75) {
137 hid_info(hdev, "Fixing up Sony Sixaxis report descriptor\n");
138 memcpy((void *)&rdesc[83], (void *)&sixaxis_rdesc_fixup,
139 sizeof(sixaxis_rdesc_fixup));
Mauro Carvalho Chehabe57a67d2012-12-14 20:57:34 -0200140 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB &&
141 *rsize > sizeof(sixaxis_rdesc_fixup2)) {
142 hid_info(hdev, "Sony Sixaxis clone detected. Using original report descriptor (size: %d clone; %d new)\n",
143 *rsize, (int)sizeof(sixaxis_rdesc_fixup2));
144 *rsize = sizeof(sixaxis_rdesc_fixup2);
145 memcpy(rdesc, &sixaxis_rdesc_fixup2, *rsize);
Simon Wood61ab44b2011-06-10 12:00:26 +0200146 }
Nikolai Kondrashov73e40082010-08-06 23:03:06 +0400147 return rdesc;
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +0200148}
149
Simon Woodc9e4d872011-06-10 12:00:27 +0200150static int sony_raw_event(struct hid_device *hdev, struct hid_report *report,
151 __u8 *rd, int size)
152{
153 struct sony_sc *sc = hid_get_drvdata(hdev);
154
155 /* Sixaxis HID report has acclerometers/gyro with MSByte first, this
156 * has to be BYTE_SWAPPED before passing up to joystick interface
157 */
158 if ((sc->quirks & (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT)) &&
159 rd[0] == 0x01 && size == 49) {
160 swap(rd[41], rd[42]);
161 swap(rd[43], rd[44]);
162 swap(rd[45], rd[46]);
163 swap(rd[47], rd[48]);
164 }
165
166 return 0;
167}
168
Colin Leitnerf04d5142013-05-27 23:41:05 +0200169static int sony_mapping(struct hid_device *hdev, struct hid_input *hi,
170 struct hid_field *field, struct hid_usage *usage,
171 unsigned long **bit, int *max)
172{
173 struct sony_sc *sc = hid_get_drvdata(hdev);
174
175 if (sc->quirks & BUZZ_CONTROLLER) {
176 unsigned int key = usage->hid & HID_USAGE;
177
178 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
179 return -1;
180
181 switch (usage->collection_index) {
182 case 1:
183 if (key >= ARRAY_SIZE(buzz_keymap))
184 return -1;
185
186 key = buzz_keymap[key];
187 if (!key)
188 return -1;
189 break;
190 default:
191 return -1;
192 }
193
194 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
195 return 1;
196 }
197
198 return -1;
199}
200
Antonio Ospite5710fab2011-02-20 18:26:45 +0100201/*
202 * The Sony Sixaxis does not handle HID Output Reports on the Interrupt EP
203 * like it should according to usbhid/hid-core.c::usbhid_output_raw_report()
204 * so we need to override that forcing HID Output Reports on the Control EP.
205 *
206 * There is also another issue about HID Output Reports via USB, the Sixaxis
207 * does not want the report_id as part of the data packet, so we have to
208 * discard buf[0] when sending the actual control message, even for numbered
209 * reports, humpf!
210 */
Antonio Ospite569b10a2010-10-19 16:13:10 +0200211static int sixaxis_usb_output_raw_report(struct hid_device *hid, __u8 *buf,
212 size_t count, unsigned char report_type)
213{
214 struct usb_interface *intf = to_usb_interface(hid->dev.parent);
215 struct usb_device *dev = interface_to_usbdev(intf);
216 struct usb_host_interface *interface = intf->cur_altsetting;
217 int report_id = buf[0];
218 int ret;
219
Antonio Ospite5710fab2011-02-20 18:26:45 +0100220 if (report_type == HID_OUTPUT_REPORT) {
221 /* Don't send the Report ID */
222 buf++;
223 count--;
224 }
225
Antonio Ospite569b10a2010-10-19 16:13:10 +0200226 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
227 HID_REQ_SET_REPORT,
228 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
229 ((report_type + 1) << 8) | report_id,
230 interface->desc.bInterfaceNumber, buf, count,
231 USB_CTRL_SET_TIMEOUT);
232
Antonio Ospite5710fab2011-02-20 18:26:45 +0100233 /* Count also the Report ID, in case of an Output report. */
234 if (ret > 0 && report_type == HID_OUTPUT_REPORT)
235 ret++;
236
Antonio Ospite569b10a2010-10-19 16:13:10 +0200237 return ret;
238}
239
Jiri Slabybd28ce02008-06-25 23:47:04 +0200240/*
241 * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
242 * to "operational". Without this, the ps3 controller will not report any
243 * events.
244 */
Antonio Ospite816651a2010-05-03 22:15:55 +0200245static int sixaxis_set_operational_usb(struct hid_device *hdev)
Jiri Slabybd28ce02008-06-25 23:47:04 +0200246{
247 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
248 struct usb_device *dev = interface_to_usbdev(intf);
249 __u16 ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
250 int ret;
251 char *buf = kmalloc(18, GFP_KERNEL);
252
253 if (!buf)
254 return -ENOMEM;
255
256 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
257 HID_REQ_GET_REPORT,
258 USB_DIR_IN | USB_TYPE_CLASS |
259 USB_RECIP_INTERFACE,
260 (3 << 8) | 0xf2, ifnum, buf, 17,
261 USB_CTRL_GET_TIMEOUT);
262 if (ret < 0)
Joe Perches4291ee32010-12-09 19:29:03 -0800263 hid_err(hdev, "can't set operational mode\n");
Jiri Slabybd28ce02008-06-25 23:47:04 +0200264
265 kfree(buf);
266
267 return ret;
268}
269
Antonio Ospite816651a2010-05-03 22:15:55 +0200270static int sixaxis_set_operational_bt(struct hid_device *hdev)
Bastien Noceraf9ce7c22010-01-20 12:01:53 +0000271{
Antonio Ospitefddb33f2010-05-03 17:19:03 +0200272 unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
Bastien Noceraf9ce7c22010-01-20 12:01:53 +0000273 return hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT);
274}
275
Colin Leitnerf04d5142013-05-27 23:41:05 +0200276static void buzz_set_leds(struct hid_device *hdev, int leds)
277{
278 struct list_head *report_list =
279 &hdev->report_enum[HID_OUTPUT_REPORT].report_list;
280 struct hid_report *report = list_entry(report_list->next,
281 struct hid_report, list);
282 __s32 *value = report->field[0]->value;
283
284 value[0] = 0x00;
285 value[1] = (leds & 1) ? 0xff : 0x00;
286 value[2] = (leds & 2) ? 0xff : 0x00;
287 value[3] = (leds & 4) ? 0xff : 0x00;
288 value[4] = (leds & 8) ? 0xff : 0x00;
289 value[5] = 0x00;
290 value[6] = 0x00;
291 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
292}
293
294static void buzz_led_set_brightness(struct led_classdev *led,
295 enum led_brightness value)
296{
297 struct device *dev = led->dev->parent;
298 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
299 struct sony_sc *drv_data;
300 struct buzz_extra *buzz;
301
302 int n;
303
304 drv_data = hid_get_drvdata(hdev);
305 if (!drv_data || !drv_data->extra) {
306 hid_err(hdev, "No device data\n");
307 return;
308 }
309 buzz = drv_data->extra;
310
311 for (n = 0; n < 4; n++) {
312 if (led == buzz->leds[n]) {
313 int on = !! (buzz->led_state & (1 << n));
314 if (value == LED_OFF && on) {
315 buzz->led_state &= ~(1 << n);
316 buzz_set_leds(hdev, buzz->led_state);
317 } else if (value != LED_OFF && !on) {
318 buzz->led_state |= (1 << n);
319 buzz_set_leds(hdev, buzz->led_state);
320 }
321 break;
322 }
323 }
324}
325
326static enum led_brightness buzz_led_get_brightness(struct led_classdev *led)
327{
328 struct device *dev = led->dev->parent;
329 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
330 struct sony_sc *drv_data;
331 struct buzz_extra *buzz;
332
333 int n;
334 int on = 0;
335
336 drv_data = hid_get_drvdata(hdev);
337 if (!drv_data || !drv_data->extra) {
338 hid_err(hdev, "No device data\n");
339 return LED_OFF;
340 }
341 buzz = drv_data->extra;
342
343 for (n = 0; n < 4; n++) {
344 if (led == buzz->leds[n]) {
345 on = !! (buzz->led_state & (1 << n));
346 break;
347 }
348 }
349
350 return on ? LED_FULL : LED_OFF;
351}
Colin Leitnerf04d5142013-05-27 23:41:05 +0200352
353static int buzz_init(struct hid_device *hdev)
354{
355 struct sony_sc *drv_data;
356 struct buzz_extra *buzz;
Jiri Kosina40e32ee2013-05-28 11:22:09 +0200357 int n, ret = 0;
358 struct led_classdev *led;
359 size_t name_sz;
360 char *name;
Colin Leitnerf04d5142013-05-27 23:41:05 +0200361
362 drv_data = hid_get_drvdata(hdev);
363 BUG_ON(!(drv_data->quirks & BUZZ_CONTROLLER));
364
365 buzz = kzalloc(sizeof(*buzz), GFP_KERNEL);
366 if (!buzz) {
367 hid_err(hdev, "Insufficient memory, cannot allocate driver data\n");
368 return -ENOMEM;
369 }
370 drv_data->extra = buzz;
371
372 /* Clear LEDs as we have no way of reading their initial state. This is
373 * only relevant if the driver is loaded after somebody actively set the
374 * LEDs to on */
375 buzz_set_leds(hdev, 0x00);
376
Jiri Kosina40e32ee2013-05-28 11:22:09 +0200377 name_sz = strlen(dev_name(&hdev->dev)) + strlen("::buzz#") + 1;
Colin Leitnerf04d5142013-05-27 23:41:05 +0200378
Jiri Kosina40e32ee2013-05-28 11:22:09 +0200379 for (n = 0; n < 4; n++) {
380 led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL);
381 if (!led) {
382 hid_err(hdev, "Couldn't allocate memory for LED %d\n", n);
383 goto error_leds;
Colin Leitnerf04d5142013-05-27 23:41:05 +0200384 }
Jiri Kosina40e32ee2013-05-28 11:22:09 +0200385
386 name = (void *)(&led[1]);
387 snprintf(name, name_sz, "%s::buzz%d", dev_name(&hdev->dev), n + 1);
388 led->name = name;
389 led->brightness = 0;
390 led->max_brightness = 1;
391 led->brightness_get = buzz_led_get_brightness;
392 led->brightness_set = buzz_led_set_brightness;
393
394 if (led_classdev_register(&hdev->dev, led)) {
395 hid_err(hdev, "Failed to register LED %d\n", n);
396 kfree(led);
397 goto error_leds;
398 }
399
400 buzz->leds[n] = led;
Colin Leitnerf04d5142013-05-27 23:41:05 +0200401 }
Colin Leitnerf04d5142013-05-27 23:41:05 +0200402
403 return ret;
404
Colin Leitnerf04d5142013-05-27 23:41:05 +0200405error_leds:
Jiri Kosina40e32ee2013-05-28 11:22:09 +0200406 for (n = 0; n < 4; n++) {
407 led = buzz->leds[n];
408 buzz->leds[n] = NULL;
409 if (!led)
410 continue;
411 led_classdev_unregister(led);
412 kfree(led);
Colin Leitnerf04d5142013-05-27 23:41:05 +0200413 }
414
415 kfree(drv_data->extra);
416 drv_data->extra = NULL;
417 return ret;
Colin Leitnerf04d5142013-05-27 23:41:05 +0200418}
419
420static void buzz_remove(struct hid_device *hdev)
421{
422 struct sony_sc *drv_data;
423 struct buzz_extra *buzz;
Jiri Kosina40e32ee2013-05-28 11:22:09 +0200424 struct led_classdev *led;
425 int n;
Colin Leitnerf04d5142013-05-27 23:41:05 +0200426
427 drv_data = hid_get_drvdata(hdev);
428 BUG_ON(!(drv_data->quirks & BUZZ_CONTROLLER));
429
430 buzz = drv_data->extra;
Colin Leitnerf04d5142013-05-27 23:41:05 +0200431
Jiri Kosina40e32ee2013-05-28 11:22:09 +0200432 for (n = 0; n < 4; n++) {
433 led = buzz->leds[n];
434 buzz->leds[n] = NULL;
435 if (!led)
436 continue;
437 led_classdev_unregister(led);
438 kfree(led);
Colin Leitnerf04d5142013-05-27 23:41:05 +0200439 }
Colin Leitnerf04d5142013-05-27 23:41:05 +0200440
441 kfree(drv_data->extra);
442 drv_data->extra = NULL;
443}
444
Jiri Slabybd28ce02008-06-25 23:47:04 +0200445static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
446{
447 int ret;
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +0200448 unsigned long quirks = id->driver_data;
449 struct sony_sc *sc;
Colin Leitnerf04d5142013-05-27 23:41:05 +0200450 unsigned int connect_mask = HID_CONNECT_DEFAULT;
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +0200451
452 sc = kzalloc(sizeof(*sc), GFP_KERNEL);
453 if (sc == NULL) {
Joe Perches4291ee32010-12-09 19:29:03 -0800454 hid_err(hdev, "can't alloc sony descriptor\n");
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +0200455 return -ENOMEM;
456 }
457
458 sc->quirks = quirks;
459 hid_set_drvdata(hdev, sc);
Jiri Slabybd28ce02008-06-25 23:47:04 +0200460
Jiri Slabybd28ce02008-06-25 23:47:04 +0200461 ret = hid_parse(hdev);
462 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800463 hid_err(hdev, "parse failed\n");
Jiri Slabybd28ce02008-06-25 23:47:04 +0200464 goto err_free;
465 }
466
Colin Leitnerf04d5142013-05-27 23:41:05 +0200467 if (sc->quirks & VAIO_RDESC_CONSTANT)
468 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
469 else if (sc->quirks & SIXAXIS_CONTROLLER_USB)
470 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
471 else if (sc->quirks & SIXAXIS_CONTROLLER_BT)
472 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
473
474 ret = hid_hw_start(hdev, connect_mask);
Jiri Slabybd28ce02008-06-25 23:47:04 +0200475 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800476 hid_err(hdev, "hw start failed\n");
Jiri Slabybd28ce02008-06-25 23:47:04 +0200477 goto err_free;
478 }
479
Antonio Ospite569b10a2010-10-19 16:13:10 +0200480 if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
481 hdev->hid_output_raw_report = sixaxis_usb_output_raw_report;
Antonio Ospite816651a2010-05-03 22:15:55 +0200482 ret = sixaxis_set_operational_usb(hdev);
Antonio Ospite569b10a2010-10-19 16:13:10 +0200483 }
Antonio Ospite816651a2010-05-03 22:15:55 +0200484 else if (sc->quirks & SIXAXIS_CONTROLLER_BT)
485 ret = sixaxis_set_operational_bt(hdev);
Colin Leitnerf04d5142013-05-27 23:41:05 +0200486 else if (sc->quirks & BUZZ_CONTROLLER)
487 ret = buzz_init(hdev);
Antonio Ospite816651a2010-05-03 22:15:55 +0200488 else
Bastien Noceraf9ce7c22010-01-20 12:01:53 +0000489 ret = 0;
Bastien Noceraf9ce7c22010-01-20 12:01:53 +0000490
Jiri Kosina4dfdc462008-12-30 00:49:59 +0100491 if (ret < 0)
Jiri Slabybd28ce02008-06-25 23:47:04 +0200492 goto err_stop;
493
494 return 0;
495err_stop:
496 hid_hw_stop(hdev);
497err_free:
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +0200498 kfree(sc);
Jiri Slabybd28ce02008-06-25 23:47:04 +0200499 return ret;
500}
501
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +0200502static void sony_remove(struct hid_device *hdev)
503{
Colin Leitnerf04d5142013-05-27 23:41:05 +0200504 struct sony_sc *sc = hid_get_drvdata(hdev);
505
506 if (sc->quirks & BUZZ_CONTROLLER)
507 buzz_remove(hdev);
508
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +0200509 hid_hw_stop(hdev);
Colin Leitnerf04d5142013-05-27 23:41:05 +0200510 kfree(sc);
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +0200511}
512
Jiri Slabybd28ce02008-06-25 23:47:04 +0200513static const struct hid_device_id sony_devices[] = {
Antonio Ospite816651a2010-05-03 22:15:55 +0200514 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER),
515 .driver_data = SIXAXIS_CONTROLLER_USB },
Jiri Kosina35dca5b2011-04-28 15:43:13 +0200516 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER),
517 .driver_data = SIXAXIS_CONTROLLER_USB },
Antonio Ospite816651a2010-05-03 22:15:55 +0200518 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER),
519 .driver_data = SIXAXIS_CONTROLLER_BT },
Jiri Kosinacc6e0bb2008-10-23 12:58:38 +0200520 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE),
521 .driver_data = VAIO_RDESC_CONSTANT },
Fernando Luis Vázquez Caoa46491842013-01-15 19:40:48 +0900522 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE),
523 .driver_data = VAIO_RDESC_CONSTANT },
Colin Leitnerf04d5142013-05-27 23:41:05 +0200524 /* Wired Buzz Controller. Reported as Sony Hub from its USB ID and as
525 * Logitech joystick from the device descriptor. */
526 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_BUZZ_CONTROLLER),
527 .driver_data = BUZZ_CONTROLLER },
528 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_WIRELESS_BUZZ_CONTROLLER),
529 .driver_data = BUZZ_CONTROLLER },
Jiri Slabybd28ce02008-06-25 23:47:04 +0200530 { }
531};
532MODULE_DEVICE_TABLE(hid, sony_devices);
533
534static struct hid_driver sony_driver = {
Colin Leitnerf04d5142013-05-27 23:41:05 +0200535 .name = "sony",
536 .id_table = sony_devices,
537 .input_mapping = sony_mapping,
538 .probe = sony_probe,
539 .remove = sony_remove,
540 .report_fixup = sony_report_fixup,
541 .raw_event = sony_raw_event
Jiri Slabybd28ce02008-06-25 23:47:04 +0200542};
H Hartley Sweetenf4254582012-12-17 15:28:26 -0700543module_hid_driver(sony_driver);
Jiri Slabybd28ce02008-06-25 23:47:04 +0200544
Jiri Slabybd28ce02008-06-25 23:47:04 +0200545MODULE_LICENSE("GPL");