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