2 * PlayStation 2 Trance Vibrator driver
4 * Copyright (C) 2006 Sam Hocevar <sam@zoy.org>
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.
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.
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.
21 /* Standard include files */
22 #include <linux/kernel.h>
23 #include <linux/errno.h>
24 #include <linux/init.h>
25 #include <linux/module.h>
26 #include <linux/usb.h>
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"
33 #define TRANCEVIBRATOR_VENDOR_ID 0x0b49 /* ASCII Corporation */
34 #define TRANCEVIBRATOR_PRODUCT_ID 0x064f /* Trance Vibrator */
36 static struct usb_device_id id_table
[] = {
37 { USB_DEVICE(TRANCEVIBRATOR_VENDOR_ID
, TRANCEVIBRATOR_PRODUCT_ID
) },
40 MODULE_DEVICE_TABLE (usb
, id_table
);
42 /* Driver-local specific stuff */
43 struct trancevibrator
{
44 struct usb_device
*udev
;
48 static ssize_t
show_speed(struct device
*dev
, struct device_attribute
*attr
,
51 struct usb_interface
*intf
= to_usb_interface(dev
);
52 struct trancevibrator
*tv
= usb_get_intfdata(intf
);
54 return sprintf(buf
, "%d\n", tv
->speed
);
57 static ssize_t
set_speed(struct device
*dev
, struct device_attribute
*attr
,
58 const char *buf
, size_t count
)
60 struct usb_interface
*intf
= to_usb_interface(dev
);
61 struct trancevibrator
*tv
= usb_get_intfdata(intf
);
62 int temp
, retval
, old
;
64 temp
= simple_strtoul(buf
, NULL
, 10);
72 dev_dbg(&tv
->udev
->dev
, "speed = %d\n", tv
->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
);
82 dev_dbg(&tv
->udev
->dev
, "retval = %d\n", retval
);
88 static DEVICE_ATTR(speed
, S_IWUGO
| S_IRUGO
, show_speed
, set_speed
);
90 static int tv_probe(struct usb_interface
*interface
,
91 const struct usb_device_id
*id
)
93 struct usb_device
*udev
= interface_to_usbdev(interface
);
94 struct trancevibrator
*dev
;
97 dev
= kzalloc(sizeof(struct trancevibrator
), GFP_KERNEL
);
99 dev_err(&interface
->dev
, "Out of memory\n");
104 dev
->udev
= usb_get_dev(udev
);
105 usb_set_intfdata(interface
, dev
);
106 retval
= device_create_file(&interface
->dev
, &dev_attr_speed
);
108 goto error_create_file
;
114 usb_set_intfdata(interface
, NULL
);
120 static void tv_disconnect(struct usb_interface
*interface
)
122 struct trancevibrator
*dev
;
124 dev
= usb_get_intfdata (interface
);
125 device_remove_file(&interface
->dev
, &dev_attr_speed
);
126 usb_set_intfdata(interface
, NULL
);
127 usb_put_dev(dev
->udev
);
131 /* USB subsystem object */
132 static struct usb_driver tv_driver
= {
133 .name
= "trancevibrator",
135 .disconnect
= tv_disconnect
,
136 .id_table
= id_table
,
139 static int __init
tv_init(void)
141 int retval
= usb_register(&tv_driver
);
143 err("usb_register failed. Error number %d", retval
);
147 info(DRIVER_VERSION
":" DRIVER_DESC
);
151 static void __exit
tv_exit(void)
153 usb_deregister(&tv_driver
);
156 module_init (tv_init
);
157 module_exit (tv_exit
);
159 MODULE_AUTHOR(DRIVER_AUTHOR
);
160 MODULE_DESCRIPTION(DRIVER_DESC
);
161 MODULE_LICENSE("GPL");