HID: move sony quirks
[linux-2.6.git] / drivers / hid / hid-sony.c
1 /*
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
7  *  Copyright (c) 2006-2007 Jiri Kosina
8  *  Copyright (c) 2007 Paul Walmsley
9  *  Copyright (c) 2008 Jiri Slaby
10  */
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>
22 #include <linux/usb.h>
23
24 #include "hid-ids.h"
25
26 /*
27  * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
28  * to "operational".  Without this, the ps3 controller will not report any
29  * events.
30  */
31 static int sony_set_operational(struct hid_device *hdev)
32 {
33         struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
34         struct usb_device *dev = interface_to_usbdev(intf);
35         __u16 ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
36         int ret;
37         char *buf = kmalloc(18, GFP_KERNEL);
38
39         if (!buf)
40                 return -ENOMEM;
41
42         ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
43                                  HID_REQ_GET_REPORT,
44                                  USB_DIR_IN | USB_TYPE_CLASS |
45                                  USB_RECIP_INTERFACE,
46                                  (3 << 8) | 0xf2, ifnum, buf, 17,
47                                  USB_CTRL_GET_TIMEOUT);
48         if (ret < 0)
49                 dev_err(&hdev->dev, "can't set operational mode\n");
50
51         kfree(buf);
52
53         return ret;
54 }
55
56 static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
57 {
58         int ret;
59
60         hdev->quirks |= HID_QUIRK_HIDDEV;
61
62         ret = hid_parse(hdev);
63         if (ret) {
64                 dev_err(&hdev->dev, "parse failed\n");
65                 goto err_free;
66         }
67
68         ret = hid_hw_start(hdev);
69         if (ret) {
70                 dev_err(&hdev->dev, "hw start failed\n");
71                 goto err_free;
72         }
73
74         ret = sony_set_operational(hdev);
75         if (ret)
76                 goto err_stop;
77
78         return 0;
79 err_stop:
80         hid_hw_stop(hdev);
81 err_free:
82         return ret;
83 }
84
85 static const struct hid_device_id sony_devices[] = {
86         { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
87         { }
88 };
89 MODULE_DEVICE_TABLE(hid, sony_devices);
90
91 static struct hid_driver sony_driver = {
92         .name = "sony",
93         .id_table = sony_devices,
94         .probe = sony_probe,
95 };
96
97 static int sony_init(void)
98 {
99         return hid_register_driver(&sony_driver);
100 }
101
102 static void sony_exit(void)
103 {
104         hid_unregister_driver(&sony_driver);
105 }
106
107 module_init(sony_init);
108 module_exit(sony_exit);
109 MODULE_LICENSE("GPL");
110
111 HID_COMPAT_LOAD_DRIVER(sony);