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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  USB ATI Remote support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *                Copyright (c) 2011, 2012 Anssi Hannula <anssi.hannula@iki.fi>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Version 2.2.0 Copyright (c) 2004 Torrey Hoffman <thoffman@arnor.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Version 2.1.1 Copyright (c) 2002 Vladimir Dergachev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  This 2.2.0 version is a rewrite / cleanup of the 2.1.1 driver, including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  porting to the 2.6 kernel interfaces, along with other modification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  to better match the style of the existing usb/input drivers.  However, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  protocol and hardware handling is essentially unchanged from 2.1.1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *  The 2.1.1 driver was derived from the usbati_remote and usbkbd drivers by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *  Vojtech Pavlik.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *  Changes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *  Feb 2004: Torrey Hoffman <thoffman@arnor.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *            Version 2.2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *  Jun 2004: Torrey Hoffman <thoffman@arnor.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *            Version 2.2.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *            Added key repeat support contributed by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *                Vincent Vanackere <vanackere@lif.univ-mrs.fr>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *            Added support for the "Lola" remote contributed by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *                Seth Cohn <sethcohn@yahoo.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * Hardware & software notes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * These remote controls are distributed by ATI as part of their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * "All-In-Wonder" video card packages.  The receiver self-identifies as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * "USB Receiver" with manufacturer "X10 Wireless Technology Inc".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * The "Lola" remote is available from X10.  See:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *    http://www.x10.com/products/lola_sg1.htm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * The Lola is similar to the ATI remote but has no mouse support, and slightly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * different keys.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * It is possible to use multiple receivers and remotes on multiple computers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * simultaneously by configuring them to use specific channels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * The RF protocol used by the remote supports 16 distinct channels, 1 to 16.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * Actually, it may even support more, at least in some revisions of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * Each remote can be configured to transmit on one channel as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *   - Press and hold the "hand icon" button.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *   - When the red LED starts to blink, let go of the "hand icon" button.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *   - When it stops blinking, input the channel code as two digits, from 01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *     to 16, and press the hand icon again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * The timing can be a little tricky.  Try loading the module with debug=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * to have the kernel print out messages about the remote control number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * and mask.  Note: debugging prints remote numbers as zero-based hexadecimal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * The driver has a "channel_mask" parameter. This bitmask specifies which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * channels will be ignored by the module.  To mask out channels, just add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * all the 2^channel_number values together.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * For instance, set channel_mask = 2^4 = 16 (binary 10000) to make ati_remote
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * ignore signals coming from remote controls transmitting on channel 4, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * accept all other channels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * Or, set channel_mask = 65533, (0xFFFD), and all channels except 1 will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * The default is 0 (respond to all channels). Bit 0 and bits 17-32 of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * parameter are unused.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #include <linux/usb/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #include <media/rc-core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * Module and Version Information, Module Parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) #define ATI_REMOTE_VENDOR_ID		0x0bc7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) #define LOLA_REMOTE_PRODUCT_ID		0x0002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) #define LOLA2_REMOTE_PRODUCT_ID		0x0003
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) #define ATI_REMOTE_PRODUCT_ID		0x0004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #define NVIDIA_REMOTE_PRODUCT_ID	0x0005
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #define MEDION_REMOTE_PRODUCT_ID	0x0006
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #define FIREFLY_REMOTE_PRODUCT_ID	0x0008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) #define DRIVER_VERSION		"2.2.1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #define DRIVER_AUTHOR           "Torrey Hoffman <thoffman@arnor.net>"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define DRIVER_DESC             "ATI/X10 RF USB Remote Control"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define NAME_BUFSIZE      80    /* size of product name, path buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define DATA_BUFSIZE      63    /* size of URB data buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * Duplicate event filtering time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * Sequential, identical KIND_FILTERED inputs with less than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * FILTER_TIME milliseconds between them are considered as repeat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * events. The hardware generates 5 events for the first keypress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * and we have to take this into account for an accurate repeat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * behaviour.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define FILTER_TIME	60 /* msec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define REPEAT_DELAY	500 /* msec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static unsigned long channel_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) module_param(channel_mask, ulong, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static int debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) module_param(debug, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) MODULE_PARM_DESC(debug, "Enable extra debug messages and information");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static int repeat_filter = FILTER_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) module_param(repeat_filter, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) MODULE_PARM_DESC(repeat_filter, "Repeat filter time, default = 60 msec");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int repeat_delay = REPEAT_DELAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) module_param(repeat_delay, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) MODULE_PARM_DESC(repeat_delay, "Delay before sending repeats, default = 500 msec");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static bool mouse = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) module_param(mouse, bool, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) MODULE_PARM_DESC(mouse, "Enable mouse device, default = yes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #define dbginfo(dev, format, arg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	do { if (debug) dev_info(dev , format , ## arg); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #undef err
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #define err(format, arg...) printk(KERN_ERR format , ## arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct ati_receiver_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	/* either default_keymap or get_default_keymap should be set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	const char *default_keymap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	const char *(*get_default_keymap)(struct usb_interface *interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static const char *get_medion_keymap(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct usb_device *udev = interface_to_usbdev(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	 * There are many different Medion remotes shipped with a receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	 * with the same usb id, but the receivers have subtle differences
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	 * in the USB descriptors allowing us to detect them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (udev->manufacturer && udev->product) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		if (udev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_WAKEUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			if (!strcmp(udev->manufacturer, "X10 Wireless Technology Inc")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			    && !strcmp(udev->product, "USB Receiver"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 				return RC_MAP_MEDION_X10_DIGITAINER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			if (!strcmp(udev->manufacturer, "X10 WTI")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			    && !strcmp(udev->product, "RF receiver"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 				return RC_MAP_MEDION_X10_OR2X;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			 if (!strcmp(udev->manufacturer, "X10 Wireless Technology Inc")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			    && !strcmp(udev->product, "USB Receiver"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 				return RC_MAP_MEDION_X10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	dev_info(&interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		 "Unknown Medion X10 receiver, using default ati_remote Medion keymap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return RC_MAP_MEDION_X10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static const struct ati_receiver_type type_ati		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	.default_keymap = RC_MAP_ATI_X10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static const struct ati_receiver_type type_medion	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	.get_default_keymap = get_medion_keymap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static const struct ati_receiver_type type_firefly	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	.default_keymap = RC_MAP_SNAPSTREAM_FIREFLY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static const struct usb_device_id ati_remote_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA_REMOTE_PRODUCT_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		.driver_info = (unsigned long)&type_ati
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA2_REMOTE_PRODUCT_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		.driver_info = (unsigned long)&type_ati
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		USB_DEVICE(ATI_REMOTE_VENDOR_ID, ATI_REMOTE_PRODUCT_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		.driver_info = (unsigned long)&type_ati
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		USB_DEVICE(ATI_REMOTE_VENDOR_ID, NVIDIA_REMOTE_PRODUCT_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		.driver_info = (unsigned long)&type_ati
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		USB_DEVICE(ATI_REMOTE_VENDOR_ID, MEDION_REMOTE_PRODUCT_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		.driver_info = (unsigned long)&type_medion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		USB_DEVICE(ATI_REMOTE_VENDOR_ID, FIREFLY_REMOTE_PRODUCT_ID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		.driver_info = (unsigned long)&type_firefly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	{}	/* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) MODULE_DEVICE_TABLE(usb, ati_remote_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* Get hi and low bytes of a 16-bits int */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) #define HI(a)	((unsigned char)((a) >> 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #define LO(a)	((unsigned char)((a) & 0xff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #define SEND_FLAG_IN_PROGRESS	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #define SEND_FLAG_COMPLETE	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* Device initialization strings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static char init1[] = { 0x01, 0x00, 0x20, 0x14 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct ati_remote {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct input_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct rc_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct usb_interface *interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct urb *irq_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct urb *out_urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct usb_endpoint_descriptor *endpoint_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	struct usb_endpoint_descriptor *endpoint_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	unsigned char *inbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	unsigned char *outbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	dma_addr_t inbuf_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	dma_addr_t outbuf_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	unsigned char old_data;     /* Detect duplicate events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	unsigned long old_jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	unsigned long acc_jiffies;  /* handle acceleration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	unsigned long first_jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	unsigned int repeat_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	char rc_name[NAME_BUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	char rc_phys[NAME_BUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	char mouse_name[NAME_BUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	char mouse_phys[NAME_BUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	wait_queue_head_t wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	int send_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	int users; /* 0-2, users are rc and input */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	struct mutex open_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* "Kinds" of messages sent from the hardware to the driver. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) #define KIND_END        0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #define KIND_LITERAL    1   /* Simply pass to input system as EV_KEY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) #define KIND_FILTERED   2   /* Add artificial key-up events, drop keyrepeats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #define KIND_ACCEL      3   /* Translate to EV_REL mouse-move events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /* Translation table from hardware messages to input events. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static const struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	unsigned char kind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	unsigned char data;	/* Raw key code from remote */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	unsigned short code;	/* Input layer translation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }  ati_remote_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	/* Directional control pad axes.  Code is xxyy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	{KIND_ACCEL,    0x70, 0xff00},	/* left */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	{KIND_ACCEL,    0x71, 0x0100},	/* right */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	{KIND_ACCEL,    0x72, 0x00ff},	/* up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	{KIND_ACCEL,    0x73, 0x0001},	/* down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	/* Directional control pad diagonals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	{KIND_ACCEL,    0x74, 0xffff},	/* left up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	{KIND_ACCEL,    0x75, 0x01ff},	/* right up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	{KIND_ACCEL,    0x77, 0xff01},	/* left down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	{KIND_ACCEL,    0x76, 0x0101},	/* right down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	/* "Mouse button" buttons.  The code below uses the fact that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	 * lsbit of the raw code is a down/up indicator. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	{KIND_LITERAL,  0x78, BTN_LEFT}, /* left btn down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	{KIND_LITERAL,  0x79, BTN_LEFT}, /* left btn up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	{KIND_LITERAL,  0x7c, BTN_RIGHT},/* right btn down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	{KIND_LITERAL,  0x7d, BTN_RIGHT},/* right btn up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	/* Artificial "double-click" events are generated by the hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	 * They are mapped to the "side" and "extra" mouse buttons here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	{KIND_FILTERED, 0x7a, BTN_SIDE}, /* left dblclick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	{KIND_FILTERED, 0x7e, BTN_EXTRA},/* right dblclick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	/* Non-mouse events are handled by rc-core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	{KIND_END, 0x00, 0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) };
^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)  * ati_remote_dump_input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static void ati_remote_dump(struct device *dev, unsigned char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			    unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (len == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		if (data[0] != (unsigned char)0xff && data[0] != 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			dev_warn(dev, "Weird byte 0x%02x\n", data[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	} else if (len == 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		dev_warn(dev, "Weird key %*ph\n", 4, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		dev_warn(dev, "Weird data, len=%d %*ph ...\n", len, 6, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * ati_remote_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static int ati_remote_open(struct ati_remote *ati_remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	mutex_lock(&ati_remote->open_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (ati_remote->users++ != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		goto out; /* one was already active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	/* On first open, submit the read urb which was set up previously. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	ati_remote->irq_urb->dev = ati_remote->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	if (usb_submit_urb(ati_remote->irq_urb, GFP_KERNEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		dev_err(&ati_remote->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			"%s: usb_submit_urb failed!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) out:	mutex_unlock(&ati_remote->open_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)  * ati_remote_close
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static void ati_remote_close(struct ati_remote *ati_remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	mutex_lock(&ati_remote->open_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	if (--ati_remote->users == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		usb_kill_urb(ati_remote->irq_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	mutex_unlock(&ati_remote->open_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static int ati_remote_input_open(struct input_dev *inputdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	struct ati_remote *ati_remote = input_get_drvdata(inputdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	return ati_remote_open(ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) static void ati_remote_input_close(struct input_dev *inputdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	struct ati_remote *ati_remote = input_get_drvdata(inputdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	ati_remote_close(ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static int ati_remote_rc_open(struct rc_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	struct ati_remote *ati_remote = rdev->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	return ati_remote_open(ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static void ati_remote_rc_close(struct rc_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	struct ati_remote *ati_remote = rdev->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	ati_remote_close(ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)  * ati_remote_irq_out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static void ati_remote_irq_out(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	struct ati_remote *ati_remote = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		dev_dbg(&ati_remote->interface->dev, "%s: status %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			__func__, urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	ati_remote->send_flags |= SEND_FLAG_COMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	wake_up(&ati_remote->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)  * ati_remote_sendpacket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  * Used to send device initialization strings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	unsigned char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	/* Set up out_urb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	memcpy(ati_remote->out_urb->transfer_buffer + 1, data, LO(cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	((char *) ati_remote->out_urb->transfer_buffer)[0] = HI(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	ati_remote->out_urb->transfer_buffer_length = LO(cmd) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	ati_remote->out_urb->dev = ati_remote->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	ati_remote->send_flags = SEND_FLAG_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	retval = usb_submit_urb(ati_remote->out_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		dev_dbg(&ati_remote->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			 "sendpacket: usb_submit_urb failed: %d\n", retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	wait_event_timeout(ati_remote->wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		((ati_remote->out_urb->status != -EINPROGRESS) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			(ati_remote->send_flags & SEND_FLAG_COMPLETE)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	usb_kill_urb(ati_remote->out_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct accel_times {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	const char	value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	unsigned int	msecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static const struct accel_times accel[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	{  1,  125 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	{  2,  250 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	{  4,  500 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	{  6, 1000 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	{  9, 1500 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	{ 13, 2000 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	{ 20,    0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  * ati_remote_compute_accel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)  * Implements acceleration curve for directional control pad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)  * If elapsed time since last event is > 1/4 second, user "stopped",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)  * so reset acceleration. Otherwise, user is probably holding the control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)  * pad down, so we increase acceleration, ramping up over two seconds to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)  * a maximum speed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static int ati_remote_compute_accel(struct ati_remote *ati_remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	unsigned long now = jiffies, reset_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	reset_time = msecs_to_jiffies(250);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	if (time_after(now, ati_remote->old_jiffies + reset_time)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		ati_remote->acc_jiffies = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	for (i = 0; i < ARRAY_SIZE(accel) - 1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		unsigned long timeout = msecs_to_jiffies(accel[i].msecs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		if (time_before(now, ati_remote->acc_jiffies + timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 			return accel[i].value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	return accel[i].value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)  * ati_remote_report_input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static void ati_remote_input_report(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	struct ati_remote *ati_remote = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	unsigned char *data= ati_remote->inbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	struct input_dev *dev = ati_remote->idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	int index = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	int remote_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	unsigned char scancode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	u32 wheel_keycode = KEY_RESERVED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	 * data[0] = 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	 * data[1] = data[2] + data[3] + 0xd5 (a checksum byte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	 * data[2] = the key code (with toggle bit in MSB with some models)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	 * data[3] = channel << 4 (the low 4 bits must be zero)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	/* Deal with strange looking inputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	if ( urb->actual_length != 4 || data[0] != 0x14 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	     data[1] != (unsigned char)(data[2] + data[3] + 0xD5) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	     (data[3] & 0x0f) != 0x00) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		ati_remote_dump(&urb->dev->dev, data, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	if (data[1] != ((data[2] + data[3] + 0xd5) & 0xff)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		dbginfo(&ati_remote->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 			"wrong checksum in input: %*ph\n", 4, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	/* Mask unwanted remote channels.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	/* note: remote_num is 0-based, channel 1 on remote == 0 here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	remote_num = (data[3] >> 4) & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	if (channel_mask & (1 << (remote_num + 1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		dbginfo(&ati_remote->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 			"Masked input from channel 0x%02x: data %02x, mask= 0x%02lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 			remote_num, data[2], channel_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	 * MSB is a toggle code, though only used by some devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	 * (e.g. SnapStream Firefly)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	scancode = data[2] & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	dbginfo(&ati_remote->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		"channel 0x%02x; key data %02x, scancode %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		remote_num, data[2], scancode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	if (scancode >= 0x70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		 * This is either a mouse or scrollwheel event, depending on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		 * the remote/keymap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		 * Get the keycode assigned to scancode 0x78/0x70. If it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		 * set, assume this is a scrollwheel up/down event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		wheel_keycode = rc_g_keycode_from_table(ati_remote->rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 							scancode & 0x78);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		if (wheel_keycode == KEY_RESERVED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 			/* scrollwheel was not mapped, assume mouse */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 			/* Look up event code index in the mouse translation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 			 * table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 			for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 				if (scancode == ati_remote_tbl[i].data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 					index = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	if (index >= 0 && ati_remote_tbl[index].kind == KIND_LITERAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		 * The lsbit of the raw key code is a down/up flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		 * Invert it to match the input layer's conventions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		input_event(dev, EV_KEY, ati_remote_tbl[index].code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 			!(data[2] & 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		ati_remote->old_jiffies = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	} else if (index < 0 || ati_remote_tbl[index].kind == KIND_FILTERED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 		unsigned long now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		/* Filter duplicate events which happen "too close" together. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 		if (ati_remote->old_data == data[2] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		    time_before(now, ati_remote->old_jiffies +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 				     msecs_to_jiffies(repeat_filter))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 			ati_remote->repeat_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 			ati_remote->repeat_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 			ati_remote->first_jiffies = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		ati_remote->old_jiffies = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		/* Ensure we skip at least the 4 first duplicate events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		 * (generated by a single keypress), and continue skipping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 		 * until repeat_delay msecs have passed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 		if (ati_remote->repeat_count > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 		    (ati_remote->repeat_count < 5 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		     time_before(now, ati_remote->first_jiffies +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 				      msecs_to_jiffies(repeat_delay))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		if (index >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 			input_event(dev, EV_KEY, ati_remote_tbl[index].code, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 			input_event(dev, EV_KEY, ati_remote_tbl[index].code, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 			/* Not a mouse event, hand it to rc-core. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 			int count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 			if (wheel_keycode != KEY_RESERVED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 				 * This is a scrollwheel event, send the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 				 * scroll up (0x78) / down (0x70) scancode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 				 * repeatedly as many times as indicated by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 				 * rest of the scancode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 				count = (scancode & 0x07) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 				scancode &= 0x78;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 			while (count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 				* We don't use the rc-core repeat handling yet as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 				* it would cause ghost repeats which would be a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 				* regression for this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 				*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 				rc_keydown_notimeout(ati_remote->rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 						     RC_PROTO_OTHER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 						     scancode, data[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 				rc_keyup(ati_remote->rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 			goto nosync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	} else if (ati_remote_tbl[index].kind == KIND_ACCEL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		signed char dx = ati_remote_tbl[index].code >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 		signed char dy = ati_remote_tbl[index].code & 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 		 * Other event kinds are from the directional control pad, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		 * have an acceleration factor applied to them.  Without this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 		 * acceleration, the control pad is mostly unusable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		int acc = ati_remote_compute_accel(ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		if (dx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 			input_report_rel(dev, REL_X, dx * acc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 		if (dy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 			input_report_rel(dev, REL_Y, dy * acc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 		ati_remote->old_jiffies = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 		dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 			ati_remote_tbl[index].kind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) nosync:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	ati_remote->old_data = data[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)  * ati_remote_irq_in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static void ati_remote_irq_in(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	struct ati_remote *ati_remote = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	case 0:			/* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 		ati_remote_input_report(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	case -ECONNRESET:	/* unlink */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		dev_dbg(&ati_remote->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 			"%s: urb error status, unlink?\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 			__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	default:		/* error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 		dev_dbg(&ati_remote->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 			"%s: Nonzero urb status %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 			__func__, urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	retval = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		dev_err(&ati_remote->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 			"%s: usb_submit_urb()=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 			__func__, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)  * ati_remote_alloc_buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) static int ati_remote_alloc_buffers(struct usb_device *udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 				    struct ati_remote *ati_remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	ati_remote->inbuf = usb_alloc_coherent(udev, DATA_BUFSIZE, GFP_ATOMIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 					       &ati_remote->inbuf_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	if (!ati_remote->inbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	ati_remote->outbuf = usb_alloc_coherent(udev, DATA_BUFSIZE, GFP_ATOMIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 						&ati_remote->outbuf_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	if (!ati_remote->outbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	ati_remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	if (!ati_remote->irq_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	ati_remote->out_urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	if (!ati_remote->out_urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)  * ati_remote_free_buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) static void ati_remote_free_buffers(struct ati_remote *ati_remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	usb_free_urb(ati_remote->irq_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	usb_free_urb(ati_remote->out_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	usb_free_coherent(ati_remote->udev, DATA_BUFSIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 		ati_remote->inbuf, ati_remote->inbuf_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	usb_free_coherent(ati_remote->udev, DATA_BUFSIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 		ati_remote->outbuf, ati_remote->outbuf_dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) static void ati_remote_input_init(struct ati_remote *ati_remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	struct input_dev *idev = ati_remote->idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 		BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 		if (ati_remote_tbl[i].kind == KIND_LITERAL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 		    ati_remote_tbl[i].kind == KIND_FILTERED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 			__set_bit(ati_remote_tbl[i].code, idev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	input_set_drvdata(idev, ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	idev->open = ati_remote_input_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	idev->close = ati_remote_input_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	idev->name = ati_remote->mouse_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	idev->phys = ati_remote->mouse_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	usb_to_input_id(ati_remote->udev, &idev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	idev->dev.parent = &ati_remote->interface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) static void ati_remote_rc_init(struct ati_remote *ati_remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	struct rc_dev *rdev = ati_remote->rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	rdev->priv = ati_remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	rdev->allowed_protocols = RC_PROTO_BIT_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	rdev->driver_name = "ati_remote";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 	rdev->open = ati_remote_rc_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	rdev->close = ati_remote_rc_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 	rdev->device_name = ati_remote->rc_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 	rdev->input_phys = ati_remote->rc_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	usb_to_input_id(ati_remote->udev, &rdev->input_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	rdev->dev.parent = &ati_remote->interface->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) static int ati_remote_initialize(struct ati_remote *ati_remote)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 	struct usb_device *udev = ati_remote->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	int pipe, maxp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	init_waitqueue_head(&ati_remote->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 	/* Set up irq_urb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	pipe = usb_rcvintpipe(udev, ati_remote->endpoint_in->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 	maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	usb_fill_int_urb(ati_remote->irq_urb, udev, pipe, ati_remote->inbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 			 maxp, ati_remote_irq_in, ati_remote,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 			 ati_remote->endpoint_in->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	ati_remote->irq_urb->transfer_dma = ati_remote->inbuf_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 	ati_remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	/* Set up out_urb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	pipe = usb_sndintpipe(udev, ati_remote->endpoint_out->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 	maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 	maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	usb_fill_int_urb(ati_remote->out_urb, udev, pipe, ati_remote->outbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 			 maxp, ati_remote_irq_out, ati_remote,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 			 ati_remote->endpoint_out->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 	ati_remote->out_urb->transfer_dma = ati_remote->outbuf_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 	ati_remote->out_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 	/* send initialization strings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	if ((ati_remote_sendpacket(ati_remote, 0x8004, init1)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 	    (ati_remote_sendpacket(ati_remote, 0x8007, init2))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 		dev_err(&ati_remote->interface->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 			 "Initializing ati_remote hardware failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)  * ati_remote_probe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) static int ati_remote_probe(struct usb_interface *interface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 	const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 	struct usb_device *udev = interface_to_usbdev(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	struct usb_host_interface *iface_host = interface->cur_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	struct usb_endpoint_descriptor *endpoint_in, *endpoint_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 	struct ati_receiver_type *type = (struct ati_receiver_type *)id->driver_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	struct ati_remote *ati_remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 	struct rc_dev *rc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 	int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 	if (iface_host->desc.bNumEndpoints != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 		err("%s: Unexpected desc.bNumEndpoints\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	endpoint_in = &iface_host->endpoint[0].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 	endpoint_out = &iface_host->endpoint[1].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	if (!usb_endpoint_is_int_in(endpoint_in)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 		err("%s: Unexpected endpoint_in\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 	if (le16_to_cpu(endpoint_in->wMaxPacketSize) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 		err("%s: endpoint_in message size==0? \n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	if (!usb_endpoint_is_int_out(endpoint_out)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 		err("%s: Unexpected endpoint_out\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 	ati_remote = kzalloc(sizeof (struct ati_remote), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	rc_dev = rc_allocate_device(RC_DRIVER_SCANCODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 	if (!ati_remote || !rc_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 		goto exit_free_dev_rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	/* Allocate URB buffers, URBs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 	if (ati_remote_alloc_buffers(udev, ati_remote))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 		goto exit_free_buffers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 	ati_remote->endpoint_in = endpoint_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	ati_remote->endpoint_out = endpoint_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 	ati_remote->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 	ati_remote->rdev = rc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 	ati_remote->interface = interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 	usb_make_path(udev, ati_remote->rc_phys, sizeof(ati_remote->rc_phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 	strscpy(ati_remote->mouse_phys, ati_remote->rc_phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 		sizeof(ati_remote->mouse_phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 	strlcat(ati_remote->rc_phys, "/input0", sizeof(ati_remote->rc_phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 	strlcat(ati_remote->mouse_phys, "/input1", sizeof(ati_remote->mouse_phys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 	snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name), "%s%s%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 		udev->manufacturer ?: "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 		udev->manufacturer && udev->product ? " " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 		udev->product ?: "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 	if (!strlen(ati_remote->rc_name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 		snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 			DRIVER_DESC "(%04x,%04x)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 			le16_to_cpu(ati_remote->udev->descriptor.idVendor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 			le16_to_cpu(ati_remote->udev->descriptor.idProduct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 	snprintf(ati_remote->mouse_name, sizeof(ati_remote->mouse_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 		 "%s mouse", ati_remote->rc_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 	rc_dev->map_name = RC_MAP_ATI_X10; /* default map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 	/* set default keymap according to receiver model */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 	if (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 		if (type->default_keymap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 			rc_dev->map_name = type->default_keymap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 		else if (type->get_default_keymap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 			rc_dev->map_name = type->get_default_keymap(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 	ati_remote_rc_init(ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 	mutex_init(&ati_remote->open_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 	/* Device Hardware Initialization - fills in ati_remote->idev from udev. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) 	err = ati_remote_initialize(ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) 		goto exit_kill_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) 	/* Set up and register rc device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) 	err = rc_register_device(ati_remote->rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) 		goto exit_kill_urbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) 	/* Set up and register mouse input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) 	if (mouse) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 		input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) 		if (!input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) 			err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) 			goto exit_unregister_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) 		ati_remote->idev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) 		ati_remote_input_init(ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) 		err = input_register_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 			goto exit_free_input_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) 	usb_set_intfdata(interface, ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)  exit_free_input_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) 	input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)  exit_unregister_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) 	rc_unregister_device(rc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) 	rc_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)  exit_kill_urbs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) 	usb_kill_urb(ati_remote->irq_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) 	usb_kill_urb(ati_remote->out_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)  exit_free_buffers:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) 	ati_remote_free_buffers(ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)  exit_free_dev_rdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) 	 rc_free_device(rc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) 	kfree(ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)  * ati_remote_disconnect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) static void ati_remote_disconnect(struct usb_interface *interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) 	struct ati_remote *ati_remote;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) 	ati_remote = usb_get_intfdata(interface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) 	usb_set_intfdata(interface, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) 	if (!ati_remote) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) 		dev_warn(&interface->dev, "%s - null device?\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) 	usb_kill_urb(ati_remote->irq_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) 	usb_kill_urb(ati_remote->out_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) 	if (ati_remote->idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) 		input_unregister_device(ati_remote->idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) 	rc_unregister_device(ati_remote->rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) 	ati_remote_free_buffers(ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) 	kfree(ati_remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) /* usb specific object to register with the usb subsystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) static struct usb_driver ati_remote_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) 	.name         = "ati_remote",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) 	.probe        = ati_remote_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) 	.disconnect   = ati_remote_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) 	.id_table     = ati_remote_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) module_usb_driver(ati_remote_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) MODULE_AUTHOR(DRIVER_AUTHOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) MODULE_LICENSE("GPL");