18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * PlayStation 2 Trance Vibrator driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2006 Sam Hocevar <sam@zoy.org> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* Standard include files */ 98c2ecf20Sopenharmony_ci#include <linux/kernel.h> 108c2ecf20Sopenharmony_ci#include <linux/errno.h> 118c2ecf20Sopenharmony_ci#include <linux/slab.h> 128c2ecf20Sopenharmony_ci#include <linux/module.h> 138c2ecf20Sopenharmony_ci#include <linux/usb.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define DRIVER_AUTHOR "Sam Hocevar, sam@zoy.org" 168c2ecf20Sopenharmony_ci#define DRIVER_DESC "PlayStation 2 Trance Vibrator driver" 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define TRANCEVIBRATOR_VENDOR_ID 0x0b49 /* ASCII Corporation */ 198c2ecf20Sopenharmony_ci#define TRANCEVIBRATOR_PRODUCT_ID 0x064f /* Trance Vibrator */ 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistatic const struct usb_device_id id_table[] = { 228c2ecf20Sopenharmony_ci { USB_DEVICE(TRANCEVIBRATOR_VENDOR_ID, TRANCEVIBRATOR_PRODUCT_ID) }, 238c2ecf20Sopenharmony_ci { }, 248c2ecf20Sopenharmony_ci}; 258c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE (usb, id_table); 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* Driver-local specific stuff */ 288c2ecf20Sopenharmony_cistruct trancevibrator { 298c2ecf20Sopenharmony_ci struct usb_device *udev; 308c2ecf20Sopenharmony_ci unsigned int speed; 318c2ecf20Sopenharmony_ci}; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistatic ssize_t speed_show(struct device *dev, struct device_attribute *attr, 348c2ecf20Sopenharmony_ci char *buf) 358c2ecf20Sopenharmony_ci{ 368c2ecf20Sopenharmony_ci struct usb_interface *intf = to_usb_interface(dev); 378c2ecf20Sopenharmony_ci struct trancevibrator *tv = usb_get_intfdata(intf); 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci return sprintf(buf, "%d\n", tv->speed); 408c2ecf20Sopenharmony_ci} 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistatic ssize_t speed_store(struct device *dev, struct device_attribute *attr, 438c2ecf20Sopenharmony_ci const char *buf, size_t count) 448c2ecf20Sopenharmony_ci{ 458c2ecf20Sopenharmony_ci struct usb_interface *intf = to_usb_interface(dev); 468c2ecf20Sopenharmony_ci struct trancevibrator *tv = usb_get_intfdata(intf); 478c2ecf20Sopenharmony_ci int temp, retval, old; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci retval = kstrtoint(buf, 10, &temp); 508c2ecf20Sopenharmony_ci if (retval) 518c2ecf20Sopenharmony_ci return retval; 528c2ecf20Sopenharmony_ci if (temp > 255) 538c2ecf20Sopenharmony_ci temp = 255; 548c2ecf20Sopenharmony_ci else if (temp < 0) 558c2ecf20Sopenharmony_ci temp = 0; 568c2ecf20Sopenharmony_ci old = tv->speed; 578c2ecf20Sopenharmony_ci tv->speed = temp; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci dev_dbg(&tv->udev->dev, "speed = %d\n", tv->speed); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci /* Set speed */ 628c2ecf20Sopenharmony_ci retval = usb_control_msg(tv->udev, usb_sndctrlpipe(tv->udev, 0), 638c2ecf20Sopenharmony_ci 0x01, /* vendor request: set speed */ 648c2ecf20Sopenharmony_ci USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 658c2ecf20Sopenharmony_ci tv->speed, /* speed value */ 668c2ecf20Sopenharmony_ci 0, NULL, 0, USB_CTRL_SET_TIMEOUT); 678c2ecf20Sopenharmony_ci if (retval) { 688c2ecf20Sopenharmony_ci tv->speed = old; 698c2ecf20Sopenharmony_ci dev_dbg(&tv->udev->dev, "retval = %d\n", retval); 708c2ecf20Sopenharmony_ci return retval; 718c2ecf20Sopenharmony_ci } 728c2ecf20Sopenharmony_ci return count; 738c2ecf20Sopenharmony_ci} 748c2ecf20Sopenharmony_cistatic DEVICE_ATTR_RW(speed); 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_cistatic struct attribute *tv_attrs[] = { 778c2ecf20Sopenharmony_ci &dev_attr_speed.attr, 788c2ecf20Sopenharmony_ci NULL, 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ciATTRIBUTE_GROUPS(tv); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cistatic int tv_probe(struct usb_interface *interface, 838c2ecf20Sopenharmony_ci const struct usb_device_id *id) 848c2ecf20Sopenharmony_ci{ 858c2ecf20Sopenharmony_ci struct usb_device *udev = interface_to_usbdev(interface); 868c2ecf20Sopenharmony_ci struct trancevibrator *dev; 878c2ecf20Sopenharmony_ci int retval; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci dev = kzalloc(sizeof(struct trancevibrator), GFP_KERNEL); 908c2ecf20Sopenharmony_ci if (!dev) { 918c2ecf20Sopenharmony_ci retval = -ENOMEM; 928c2ecf20Sopenharmony_ci goto error; 938c2ecf20Sopenharmony_ci } 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci dev->udev = usb_get_dev(udev); 968c2ecf20Sopenharmony_ci usb_set_intfdata(interface, dev); 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci return 0; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_cierror: 1018c2ecf20Sopenharmony_ci kfree(dev); 1028c2ecf20Sopenharmony_ci return retval; 1038c2ecf20Sopenharmony_ci} 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_cistatic void tv_disconnect(struct usb_interface *interface) 1068c2ecf20Sopenharmony_ci{ 1078c2ecf20Sopenharmony_ci struct trancevibrator *dev; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci dev = usb_get_intfdata (interface); 1108c2ecf20Sopenharmony_ci usb_set_intfdata(interface, NULL); 1118c2ecf20Sopenharmony_ci usb_put_dev(dev->udev); 1128c2ecf20Sopenharmony_ci kfree(dev); 1138c2ecf20Sopenharmony_ci} 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/* USB subsystem object */ 1168c2ecf20Sopenharmony_cistatic struct usb_driver tv_driver = { 1178c2ecf20Sopenharmony_ci .name = "trancevibrator", 1188c2ecf20Sopenharmony_ci .probe = tv_probe, 1198c2ecf20Sopenharmony_ci .disconnect = tv_disconnect, 1208c2ecf20Sopenharmony_ci .id_table = id_table, 1218c2ecf20Sopenharmony_ci .dev_groups = tv_groups, 1228c2ecf20Sopenharmony_ci}; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cimodule_usb_driver(tv_driver); 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ciMODULE_AUTHOR(DRIVER_AUTHOR); 1278c2ecf20Sopenharmony_ciMODULE_DESCRIPTION(DRIVER_DESC); 1288c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 129