1 // SPDX-License-Identifier: GPL-2.0+
3 * PlayStation 2 Trance Vibrator driver
5 * Copyright (C) 2006 Sam Hocevar <sam@zoy.org>
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>
15 #define DRIVER_AUTHOR "Sam Hocevar, sam@zoy.org"
16 #define DRIVER_DESC "PlayStation 2 Trance Vibrator driver"
18 #define TRANCEVIBRATOR_VENDOR_ID 0x0b49 /* ASCII Corporation */
19 #define TRANCEVIBRATOR_PRODUCT_ID 0x064f /* Trance Vibrator */
21 static const struct usb_device_id id_table
[] = {
22 { USB_DEVICE(TRANCEVIBRATOR_VENDOR_ID
, TRANCEVIBRATOR_PRODUCT_ID
) },
25 MODULE_DEVICE_TABLE (usb
, id_table
);
27 /* Driver-local specific stuff */
28 struct trancevibrator
{
29 struct usb_device
*udev
;
33 static ssize_t
speed_show(struct device
*dev
, struct device_attribute
*attr
,
36 struct usb_interface
*intf
= to_usb_interface(dev
);
37 struct trancevibrator
*tv
= usb_get_intfdata(intf
);
39 return sprintf(buf
, "%d\n", tv
->speed
);
42 static ssize_t
speed_store(struct device
*dev
, struct device_attribute
*attr
,
43 const char *buf
, size_t count
)
45 struct usb_interface
*intf
= to_usb_interface(dev
);
46 struct trancevibrator
*tv
= usb_get_intfdata(intf
);
47 int temp
, retval
, old
;
49 retval
= kstrtoint(buf
, 10, &temp
);
59 dev_dbg(&tv
->udev
->dev
, "speed = %d\n", tv
->speed
);
62 retval
= usb_control_msg(tv
->udev
, usb_sndctrlpipe(tv
->udev
, 0),
63 0x01, /* vendor request: set speed */
64 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_OTHER
,
65 tv
->speed
, /* speed value */
66 0, NULL
, 0, USB_CTRL_GET_TIMEOUT
);
69 dev_dbg(&tv
->udev
->dev
, "retval = %d\n", retval
);
74 static DEVICE_ATTR_RW(speed
);
76 static struct attribute
*tv_attrs
[] = {
82 static int tv_probe(struct usb_interface
*interface
,
83 const struct usb_device_id
*id
)
85 struct usb_device
*udev
= interface_to_usbdev(interface
);
86 struct trancevibrator
*dev
;
89 dev
= kzalloc(sizeof(struct trancevibrator
), GFP_KERNEL
);
95 dev
->udev
= usb_get_dev(udev
);
96 usb_set_intfdata(interface
, dev
);
105 static void tv_disconnect(struct usb_interface
*interface
)
107 struct trancevibrator
*dev
;
109 dev
= usb_get_intfdata (interface
);
110 usb_set_intfdata(interface
, NULL
);
111 usb_put_dev(dev
->udev
);
115 /* USB subsystem object */
116 static struct usb_driver tv_driver
= {
117 .name
= "trancevibrator",
119 .disconnect
= tv_disconnect
,
120 .id_table
= id_table
,
121 .dev_groups
= tv_groups
,
124 module_usb_driver(tv_driver
);
126 MODULE_AUTHOR(DRIVER_AUTHOR
);
127 MODULE_DESCRIPTION(DRIVER_DESC
);
128 MODULE_LICENSE("GPL");