Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Support for the Maxtor OneTouch USB hard drive's button
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Current development and maintenance by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	Copyright (c) 2005 Nick Sillik <n.sillik@temple.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Initial work by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *	Copyright (c) 2003 Erik Thyren <erth7411@student.uu.se>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Based on usbmouse.c (Vojtech Pavlik) and xpad.c (Marko Friedemann)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/usb/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "usb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "scsiglue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define DRV_NAME "ums-onetouch"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) MODULE_DESCRIPTION("Maxtor USB OneTouch hard drive button driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) MODULE_AUTHOR("Nick Sillik <n.sillik@temple.edu>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) MODULE_IMPORT_NS(USB_STORAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define ONETOUCH_PKT_LEN        0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define ONETOUCH_BUTTON         KEY_PROG1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static int onetouch_connect_input(struct us_data *ss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static void onetouch_release_input(void *onetouch_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) struct usb_onetouch {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	char name[128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	char phys[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct input_dev *dev;	/* input device interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct usb_device *udev;	/* usb device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct urb *irq;	/* urb for interrupt in report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	unsigned char *data;	/* input data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	dma_addr_t data_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	unsigned int is_open:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * The table of devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		    vendorName, productName, useProtocol, useTransport, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		    initFunction, flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)   .driver_info = (flags) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static struct usb_device_id onetouch_usb_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #	include "unusual_onetouch.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	{ }		/* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) MODULE_DEVICE_TABLE(usb, onetouch_usb_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #undef UNUSUAL_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * The flags table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		    vendor_name, product_name, use_protocol, use_transport, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		    init_function, Flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	.vendorName = vendor_name,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.productName = product_name,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.useProtocol = use_protocol,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.useTransport = use_transport,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	.initFunction = init_function,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static struct us_unusual_dev onetouch_unusual_dev_list[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #	include "unusual_onetouch.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	{ }		/* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #undef UNUSUAL_DEV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static void usb_onetouch_irq(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct usb_onetouch *onetouch = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	signed char *data = onetouch->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct input_dev *dev = onetouch->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	case 0:			/* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	case -ECONNRESET:	/* unlink */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	/* -EPIPE:  should clear the halt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	default:		/* error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	input_report_key(dev, ONETOUCH_BUTTON, data[0] & 0x02);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) resubmit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	retval = usb_submit_urb (urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		dev_err(&dev->dev, "can't resubmit intr, %s-%s/input0, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			"retval %d\n", onetouch->udev->bus->bus_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			onetouch->udev->devpath, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int usb_onetouch_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct usb_onetouch *onetouch = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	onetouch->is_open = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	onetouch->irq->dev = onetouch->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (usb_submit_urb(onetouch->irq, GFP_KERNEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		dev_err(&dev->dev, "usb_submit_urb failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static void usb_onetouch_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	struct usb_onetouch *onetouch = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	usb_kill_urb(onetouch->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	onetouch->is_open = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static void usb_onetouch_pm_hook(struct us_data *us, int action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct usb_onetouch *onetouch = (struct usb_onetouch *) us->extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (onetouch->is_open) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		switch (action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		case US_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			usb_kill_urb(onetouch->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		case US_RESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			if (usb_submit_urb(onetouch->irq, GFP_NOIO) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				dev_err(&onetouch->irq->dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 					"usb_submit_urb failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #endif /* CONFIG_PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static int onetouch_connect_input(struct us_data *ss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	struct usb_device *udev = ss->pusb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct usb_host_interface *interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct usb_endpoint_descriptor *endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct usb_onetouch *onetouch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	int pipe, maxp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	int error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	interface = ss->pusb_intf->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (interface->desc.bNumEndpoints != 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	endpoint = &interface->endpoint[2].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (!usb_endpoint_is_int_in(endpoint))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	maxp = min(maxp, ONETOUCH_PKT_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	onetouch = kzalloc(sizeof(struct usb_onetouch), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (!onetouch || !input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	onetouch->data = usb_alloc_coherent(udev, ONETOUCH_PKT_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 					    GFP_KERNEL, &onetouch->data_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (!onetouch->data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	onetouch->irq = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (!onetouch->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	onetouch->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	onetouch->dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (udev->manufacturer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		strlcpy(onetouch->name, udev->manufacturer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			sizeof(onetouch->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (udev->product) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (udev->manufacturer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			strlcat(onetouch->name, " ", sizeof(onetouch->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		strlcat(onetouch->name, udev->product, sizeof(onetouch->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (!strlen(onetouch->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		snprintf(onetouch->name, sizeof(onetouch->name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			 "Maxtor Onetouch %04x:%04x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			 le16_to_cpu(udev->descriptor.idVendor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			 le16_to_cpu(udev->descriptor.idProduct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	usb_make_path(udev, onetouch->phys, sizeof(onetouch->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	strlcat(onetouch->phys, "/input0", sizeof(onetouch->phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	input_dev->name = onetouch->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	input_dev->phys = onetouch->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	usb_to_input_id(udev, &input_dev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	input_dev->dev.parent = &udev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	set_bit(EV_KEY, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	set_bit(ONETOUCH_BUTTON, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	clear_bit(0, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	input_set_drvdata(input_dev, onetouch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	input_dev->open = usb_onetouch_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	input_dev->close = usb_onetouch_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	usb_fill_int_urb(onetouch->irq, udev, pipe, onetouch->data, maxp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			 usb_onetouch_irq, onetouch, endpoint->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	onetouch->irq->transfer_dma = onetouch->data_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	onetouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	ss->extra_destructor = onetouch_release_input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	ss->extra = onetouch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	ss->suspend_resume_hook = usb_onetouch_pm_hook;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	error = input_register_device(onetouch->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  fail3:	usb_free_urb(onetouch->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  fail2:	usb_free_coherent(udev, ONETOUCH_PKT_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			  onetouch->data, onetouch->data_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  fail1:	kfree(onetouch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static void onetouch_release_input(void *onetouch_)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct usb_onetouch *onetouch = (struct usb_onetouch *) onetouch_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (onetouch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		usb_kill_urb(onetouch->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		input_unregister_device(onetouch->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		usb_free_urb(onetouch->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		usb_free_coherent(onetouch->udev, ONETOUCH_PKT_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 				  onetouch->data, onetouch->data_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static struct scsi_host_template onetouch_host_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static int onetouch_probe(struct usb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			 const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct us_data *us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	result = usb_stor_probe1(&us, intf, id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			(id - onetouch_usb_ids) + onetouch_unusual_dev_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			&onetouch_host_template);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	/* Use default transport and protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	result = usb_stor_probe2(us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static struct usb_driver onetouch_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	.name =		DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	.probe =	onetouch_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	.disconnect =	usb_stor_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	.suspend =	usb_stor_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	.resume =	usb_stor_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	.reset_resume =	usb_stor_reset_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	.pre_reset =	usb_stor_pre_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	.post_reset =	usb_stor_post_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	.id_table =	onetouch_usb_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	.soft_unbind =	1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	.no_dynamic_id = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) module_usb_stor_driver(onetouch_driver, onetouch_host_template, DRV_NAME);