V4L/DVB (9279): gspca: Correct some copyright headers
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / hid / hid-sony.c
blob3af8095a7de19639a1018bf3817118d28501081a
1 /*
2 * HID driver for some sony "special" devices
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
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.
19 #include <linux/device.h>
20 #include <linux/hid.h>
21 #include <linux/module.h>
22 #include <linux/usb.h>
24 #include "hid-ids.h"
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.
31 static int sony_set_operational(struct hid_device *hdev)
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);
39 if (!buf)
40 return -ENOMEM;
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");
51 kfree(buf);
53 return ret;
56 static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
58 int ret;
60 ret = hid_parse(hdev);
61 if (ret) {
62 dev_err(&hdev->dev, "parse failed\n");
63 goto err_free;
66 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT |
67 HID_CONNECT_HIDDEV_FORCE);
68 if (ret) {
69 dev_err(&hdev->dev, "hw start failed\n");
70 goto err_free;
73 ret = sony_set_operational(hdev);
74 if (ret)
75 goto err_stop;
77 return 0;
78 err_stop:
79 hid_hw_stop(hdev);
80 err_free:
81 return ret;
84 static const struct hid_device_id sony_devices[] = {
85 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
86 { }
88 MODULE_DEVICE_TABLE(hid, sony_devices);
90 static struct hid_driver sony_driver = {
91 .name = "sony",
92 .id_table = sony_devices,
93 .probe = sony_probe,
96 static int sony_init(void)
98 return hid_register_driver(&sony_driver);
101 static void sony_exit(void)
103 hid_unregister_driver(&sony_driver);
106 module_init(sony_init);
107 module_exit(sony_exit);
108 MODULE_LICENSE("GPL");
110 HID_COMPAT_LOAD_DRIVER(sony);