Loading...
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * PlayStation 2 Trance Vibrator driver
4 *
5 * Copyright (C) 2006 Sam Hocevar <sam@zoy.org>
6 */
7
8/* Standard include files */
9#include <linux/kernel.h>
10#include <linux/errno.h>
11#include <linux/slab.h>
12#include <linux/module.h>
13#include <linux/usb.h>
14
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
21static const struct usb_device_id id_table[] = {
22 { USB_DEVICE(TRANCEVIBRATOR_VENDOR_ID, TRANCEVIBRATOR_PRODUCT_ID) },
23 { },
24};
25MODULE_DEVICE_TABLE (usb, id_table);
26
27/* Driver-local specific stuff */
28struct trancevibrator {
29 struct usb_device *udev;
30 unsigned int speed;
31};
32
33static ssize_t speed_show(struct device *dev, struct device_attribute *attr,
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
42static ssize_t speed_store(struct device *dev, struct device_attribute *attr,
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);
47 int temp, retval, old;
48
49 retval = kstrtoint(buf, 10, &temp);
50 if (retval)
51 return retval;
52 if (temp > 255)
53 temp = 255;
54 else if (temp < 0)
55 temp = 0;
56 old = tv->speed;
57 tv->speed = temp;
58
59 dev_dbg(&tv->udev->dev, "speed = %d\n", tv->speed);
60
61 /* Set speed */
62 retval = usb_control_msg(tv->udev, usb_sndctrlpipe(tv->udev, 0),
63 0x01, /* vendor request: set speed */
64 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
65 tv->speed, /* speed value */
66 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
67 if (retval) {
68 tv->speed = old;
69 dev_dbg(&tv->udev->dev, "retval = %d\n", retval);
70 return retval;
71 }
72 return count;
73}
74static DEVICE_ATTR_RW(speed);
75
76static struct attribute *tv_attrs[] = {
77 &dev_attr_speed.attr,
78 NULL,
79};
80ATTRIBUTE_GROUPS(tv);
81
82static int tv_probe(struct usb_interface *interface,
83 const struct usb_device_id *id)
84{
85 struct usb_device *udev = interface_to_usbdev(interface);
86 struct trancevibrator *dev;
87 int retval;
88
89 dev = kzalloc(sizeof(struct trancevibrator), GFP_KERNEL);
90 if (!dev) {
91 retval = -ENOMEM;
92 goto error;
93 }
94
95 dev->udev = usb_get_dev(udev);
96 usb_set_intfdata(interface, dev);
97
98 return 0;
99
100error:
101 kfree(dev);
102 return retval;
103}
104
105static void tv_disconnect(struct usb_interface *interface)
106{
107 struct trancevibrator *dev;
108
109 dev = usb_get_intfdata (interface);
110 usb_set_intfdata(interface, NULL);
111 usb_put_dev(dev->udev);
112 kfree(dev);
113}
114
115/* USB subsystem object */
116static struct usb_driver tv_driver = {
117 .name = "trancevibrator",
118 .probe = tv_probe,
119 .disconnect = tv_disconnect,
120 .id_table = id_table,
121 .dev_groups = tv_groups,
122};
123
124module_usb_driver(tv_driver);
125
126MODULE_AUTHOR(DRIVER_AUTHOR);
127MODULE_DESCRIPTION(DRIVER_DESC);
128MODULE_LICENSE("GPL");
1/*
2 * PlayStation 2 Trance Vibrator driver
3 *
4 * Copyright (C) 2006 Sam Hocevar <sam@zoy.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21/* Standard include files */
22#include <linux/kernel.h>
23#include <linux/errno.h>
24#include <linux/slab.h>
25#include <linux/module.h>
26#include <linux/usb.h>
27
28/* Version Information */
29#define DRIVER_VERSION "v1.1"
30#define DRIVER_AUTHOR "Sam Hocevar, sam@zoy.org"
31#define DRIVER_DESC "PlayStation 2 Trance Vibrator driver"
32
33#define TRANCEVIBRATOR_VENDOR_ID 0x0b49 /* ASCII Corporation */
34#define TRANCEVIBRATOR_PRODUCT_ID 0x064f /* Trance Vibrator */
35
36static const struct usb_device_id id_table[] = {
37 { USB_DEVICE(TRANCEVIBRATOR_VENDOR_ID, TRANCEVIBRATOR_PRODUCT_ID) },
38 { },
39};
40MODULE_DEVICE_TABLE (usb, id_table);
41
42/* Driver-local specific stuff */
43struct trancevibrator {
44 struct usb_device *udev;
45 unsigned int speed;
46};
47
48static ssize_t show_speed(struct device *dev, struct device_attribute *attr,
49 char *buf)
50{
51 struct usb_interface *intf = to_usb_interface(dev);
52 struct trancevibrator *tv = usb_get_intfdata(intf);
53
54 return sprintf(buf, "%d\n", tv->speed);
55}
56
57static ssize_t set_speed(struct device *dev, struct device_attribute *attr,
58 const char *buf, size_t count)
59{
60 struct usb_interface *intf = to_usb_interface(dev);
61 struct trancevibrator *tv = usb_get_intfdata(intf);
62 int temp, retval, old;
63
64 temp = simple_strtoul(buf, NULL, 10);
65 if (temp > 255)
66 temp = 255;
67 else if (temp < 0)
68 temp = 0;
69 old = tv->speed;
70 tv->speed = temp;
71
72 dev_dbg(&tv->udev->dev, "speed = %d\n", tv->speed);
73
74 /* Set speed */
75 retval = usb_control_msg(tv->udev, usb_sndctrlpipe(tv->udev, 0),
76 0x01, /* vendor request: set speed */
77 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
78 tv->speed, /* speed value */
79 0, NULL, 0, USB_CTRL_GET_TIMEOUT);
80 if (retval) {
81 tv->speed = old;
82 dev_dbg(&tv->udev->dev, "retval = %d\n", retval);
83 return retval;
84 }
85 return count;
86}
87
88static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR, show_speed, set_speed);
89
90static int tv_probe(struct usb_interface *interface,
91 const struct usb_device_id *id)
92{
93 struct usb_device *udev = interface_to_usbdev(interface);
94 struct trancevibrator *dev;
95 int retval;
96
97 dev = kzalloc(sizeof(struct trancevibrator), GFP_KERNEL);
98 if (!dev) {
99 retval = -ENOMEM;
100 goto error;
101 }
102
103 dev->udev = usb_get_dev(udev);
104 usb_set_intfdata(interface, dev);
105 retval = device_create_file(&interface->dev, &dev_attr_speed);
106 if (retval)
107 goto error_create_file;
108
109 return 0;
110
111error_create_file:
112 usb_put_dev(udev);
113 usb_set_intfdata(interface, NULL);
114error:
115 kfree(dev);
116 return retval;
117}
118
119static void tv_disconnect(struct usb_interface *interface)
120{
121 struct trancevibrator *dev;
122
123 dev = usb_get_intfdata (interface);
124 device_remove_file(&interface->dev, &dev_attr_speed);
125 usb_set_intfdata(interface, NULL);
126 usb_put_dev(dev->udev);
127 kfree(dev);
128}
129
130/* USB subsystem object */
131static struct usb_driver tv_driver = {
132 .name = "trancevibrator",
133 .probe = tv_probe,
134 .disconnect = tv_disconnect,
135 .id_table = id_table,
136};
137
138module_usb_driver(tv_driver);
139
140MODULE_AUTHOR(DRIVER_AUTHOR);
141MODULE_DESCRIPTION(DRIVER_DESC);
142MODULE_LICENSE("GPL");