Commit | Line | Data |
---|---|---|
5fd54ace | 1 | // SPDX-License-Identifier: GPL-2.0+ |
5638e4d9 SH |
2 | /* |
3 | * PlayStation 2 Trance Vibrator driver | |
4 | * | |
5 | * Copyright (C) 2006 Sam Hocevar <sam@zoy.org> | |
5638e4d9 SH |
6 | */ |
7 | ||
8 | /* Standard include files */ | |
9 | #include <linux/kernel.h> | |
10 | #include <linux/errno.h> | |
5a0e3ad6 | 11 | #include <linux/slab.h> |
5638e4d9 SH |
12 | #include <linux/module.h> |
13 | #include <linux/usb.h> | |
14 | ||
5638e4d9 SH |
15 | #define DRIVER_AUTHOR "Sam Hocevar, sam@zoy.org" |
16 | #define DRIVER_DESC "PlayStation 2 Trance Vibrator driver" | |
17 | ||
18 | #define TRANCEVIBRATOR_VENDOR_ID 0x0b49 /* ASCII Corporation */ | |
19 | #define TRANCEVIBRATOR_PRODUCT_ID 0x064f /* Trance Vibrator */ | |
20 | ||
33b9e162 | 21 | static const struct usb_device_id id_table[] = { |
5638e4d9 SH |
22 | { USB_DEVICE(TRANCEVIBRATOR_VENDOR_ID, TRANCEVIBRATOR_PRODUCT_ID) }, |
23 | { }, | |
24 | }; | |
25 | MODULE_DEVICE_TABLE (usb, id_table); | |
26 | ||
27 | /* Driver-local specific stuff */ | |
28 | struct trancevibrator { | |
29 | struct usb_device *udev; | |
30 | unsigned int speed; | |
31 | }; | |
32 | ||
ed5bd7a4 | 33 | static ssize_t speed_show(struct device *dev, struct device_attribute *attr, |
5638e4d9 SH |
34 | char *buf) |
35 | { | |
36 | struct usb_interface *intf = to_usb_interface(dev); | |
37 | struct trancevibrator *tv = usb_get_intfdata(intf); | |
38 | ||
39 | return sprintf(buf, "%d\n", tv->speed); | |
40 | } | |
41 | ||
ed5bd7a4 | 42 | static ssize_t speed_store(struct device *dev, struct device_attribute *attr, |
5638e4d9 SH |
43 | const char *buf, size_t count) |
44 | { | |
45 | struct usb_interface *intf = to_usb_interface(dev); | |
46 | struct trancevibrator *tv = usb_get_intfdata(intf); | |
0cc5e2e7 | 47 | int temp, retval, old; |
5638e4d9 SH |
48 | |
49 | temp = simple_strtoul(buf, NULL, 10); | |
50 | if (temp > 255) | |
51 | temp = 255; | |
52 | else if (temp < 0) | |
53 | temp = 0; | |
0cc5e2e7 | 54 | old = tv->speed; |
5638e4d9 SH |
55 | tv->speed = temp; |
56 | ||
57 | dev_dbg(&tv->udev->dev, "speed = %d\n", tv->speed); | |
58 | ||
59 | /* Set speed */ | |
60 | retval = usb_control_msg(tv->udev, usb_sndctrlpipe(tv->udev, 0), | |
61 | 0x01, /* vendor request: set speed */ | |
62 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, | |
63 | tv->speed, /* speed value */ | |
64 | 0, NULL, 0, USB_CTRL_GET_TIMEOUT); | |
65 | if (retval) { | |
0cc5e2e7 | 66 | tv->speed = old; |
5638e4d9 SH |
67 | dev_dbg(&tv->udev->dev, "retval = %d\n", retval); |
68 | return retval; | |
69 | } | |
70 | return count; | |
71 | } | |
72 | ||
ed5bd7a4 | 73 | static DEVICE_ATTR_RW(speed); |
5638e4d9 SH |
74 | |
75 | static int tv_probe(struct usb_interface *interface, | |
76 | const struct usb_device_id *id) | |
77 | { | |
78 | struct usb_device *udev = interface_to_usbdev(interface); | |
79 | struct trancevibrator *dev; | |
80 | int retval; | |
81 | ||
82 | dev = kzalloc(sizeof(struct trancevibrator), GFP_KERNEL); | |
58e61402 | 83 | if (!dev) { |
5638e4d9 SH |
84 | retval = -ENOMEM; |
85 | goto error; | |
86 | } | |
87 | ||
88 | dev->udev = usb_get_dev(udev); | |
89 | usb_set_intfdata(interface, dev); | |
90 | retval = device_create_file(&interface->dev, &dev_attr_speed); | |
91 | if (retval) | |
92 | goto error_create_file; | |
93 | ||
94 | return 0; | |
95 | ||
96 | error_create_file: | |
97 | usb_put_dev(udev); | |
98 | usb_set_intfdata(interface, NULL); | |
99 | error: | |
100 | kfree(dev); | |
101 | return retval; | |
102 | } | |
103 | ||
104 | static void tv_disconnect(struct usb_interface *interface) | |
105 | { | |
106 | struct trancevibrator *dev; | |
107 | ||
108 | dev = usb_get_intfdata (interface); | |
5638e4d9 | 109 | device_remove_file(&interface->dev, &dev_attr_speed); |
96ca014d | 110 | usb_set_intfdata(interface, NULL); |
5638e4d9 SH |
111 | usb_put_dev(dev->udev); |
112 | kfree(dev); | |
113 | } | |
114 | ||
115 | /* USB subsystem object */ | |
116 | static struct usb_driver tv_driver = { | |
117 | .name = "trancevibrator", | |
118 | .probe = tv_probe, | |
119 | .disconnect = tv_disconnect, | |
120 | .id_table = id_table, | |
121 | }; | |
122 | ||
65db4305 | 123 | module_usb_driver(tv_driver); |
5638e4d9 SH |
124 | |
125 | MODULE_AUTHOR(DRIVER_AUTHOR); | |
126 | MODULE_DESCRIPTION(DRIVER_DESC); | |
127 | MODULE_LICENSE("GPL"); |