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 | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 4 | * Copyright (c) 2011 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Anssi Hannula | 9688efd | 2011-08-06 18:18:07 -0300 | [diff] [blame] | 111 | #define DRIVER_VERSION "2.2.1" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | #define DRIVER_AUTHOR "Torrey Hoffman <thoffman@arnor.net>" |
| 113 | #define DRIVER_DESC "ATI/X10 RF USB Remote Control" |
| 114 | |
| 115 | #define NAME_BUFSIZE 80 /* size of product name, path buffers */ |
| 116 | #define DATA_BUFSIZE 63 /* size of URB data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Edwin Huffstutler | c669869 | 2006-08-04 22:53:02 -0400 | [diff] [blame] | 118 | /* |
| 119 | * Duplicate event filtering time. |
| 120 | * Sequential, identical KIND_FILTERED inputs with less than |
| 121 | * FILTER_TIME milliseconds between them are considered as repeat |
| 122 | * events. The hardware generates 5 events for the first keypress |
| 123 | * and we have to take this into account for an accurate repeat |
| 124 | * behaviour. |
| 125 | */ |
| 126 | #define FILTER_TIME 60 /* msec */ |
Karl Pickett | 0de9550 | 2007-04-12 01:35:59 -0400 | [diff] [blame] | 127 | #define REPEAT_DELAY 500 /* msec */ |
Edwin Huffstutler | c669869 | 2006-08-04 22:53:02 -0400 | [diff] [blame] | 128 | |
Dmitry Torokhov | 65cde54 | 2005-05-29 02:29:38 -0500 | [diff] [blame] | 129 | static unsigned long channel_mask; |
Dmitry Torokhov | c605b67 | 2006-08-04 22:53:15 -0400 | [diff] [blame] | 130 | module_param(channel_mask, ulong, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore"); |
| 132 | |
Dmitry Torokhov | 65cde54 | 2005-05-29 02:29:38 -0500 | [diff] [blame] | 133 | static int debug; |
Dmitry Torokhov | c605b67 | 2006-08-04 22:53:15 -0400 | [diff] [blame] | 134 | module_param(debug, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | MODULE_PARM_DESC(debug, "Enable extra debug messages and information"); |
| 136 | |
Edwin Huffstutler | c669869 | 2006-08-04 22:53:02 -0400 | [diff] [blame] | 137 | static int repeat_filter = FILTER_TIME; |
| 138 | module_param(repeat_filter, int, 0644); |
| 139 | MODULE_PARM_DESC(repeat_filter, "Repeat filter time, default = 60 msec"); |
| 140 | |
Karl Pickett | 0de9550 | 2007-04-12 01:35:59 -0400 | [diff] [blame] | 141 | static int repeat_delay = REPEAT_DELAY; |
| 142 | module_param(repeat_delay, int, 0644); |
| 143 | MODULE_PARM_DESC(repeat_delay, "Delay before sending repeats, default = 500 msec"); |
| 144 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 145 | static bool mouse = true; |
| 146 | module_param(mouse, bool, 0444); |
| 147 | MODULE_PARM_DESC(mouse, "Enable mouse device, default = yes"); |
| 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | #define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0) |
| 150 | #undef err |
| 151 | #define err(format, arg...) printk(KERN_ERR format , ## arg) |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | static struct usb_device_id ati_remote_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA_REMOTE_PRODUCT_ID) }, |
Jarod Wilson | 5132088 | 2010-05-03 23:30:32 -0700 | [diff] [blame] | 155 | { USB_DEVICE(ATI_REMOTE_VENDOR_ID, LOLA2_REMOTE_PRODUCT_ID) }, |
| 156 | { USB_DEVICE(ATI_REMOTE_VENDOR_ID, ATI_REMOTE_PRODUCT_ID) }, |
| 157 | { USB_DEVICE(ATI_REMOTE_VENDOR_ID, NVIDIA_REMOTE_PRODUCT_ID) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { USB_DEVICE(ATI_REMOTE_VENDOR_ID, MEDION_REMOTE_PRODUCT_ID) }, |
| 159 | {} /* Terminating entry */ |
| 160 | }; |
| 161 | |
| 162 | MODULE_DEVICE_TABLE(usb, ati_remote_table); |
| 163 | |
| 164 | /* Get hi and low bytes of a 16-bits int */ |
| 165 | #define HI(a) ((unsigned char)((a) >> 8)) |
| 166 | #define LO(a) ((unsigned char)((a) & 0xff)) |
| 167 | |
| 168 | #define SEND_FLAG_IN_PROGRESS 1 |
| 169 | #define SEND_FLAG_COMPLETE 2 |
| 170 | |
| 171 | /* Device initialization strings */ |
| 172 | static char init1[] = { 0x01, 0x00, 0x20, 0x14 }; |
| 173 | static char init2[] = { 0x01, 0x00, 0x20, 0x14, 0x20, 0x20, 0x20 }; |
| 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | struct ati_remote { |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 176 | struct input_dev *idev; |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 177 | struct rc_dev *rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | struct usb_device *udev; |
| 179 | struct usb_interface *interface; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | struct urb *irq_urb; |
| 182 | struct urb *out_urb; |
| 183 | struct usb_endpoint_descriptor *endpoint_in; |
| 184 | struct usb_endpoint_descriptor *endpoint_out; |
| 185 | unsigned char *inbuf; |
| 186 | unsigned char *outbuf; |
| 187 | dma_addr_t inbuf_dma; |
| 188 | dma_addr_t outbuf_dma; |
| 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | unsigned char old_data[2]; /* Detect duplicate events */ |
| 191 | unsigned long old_jiffies; |
| 192 | unsigned long acc_jiffies; /* handle acceleration */ |
Karl Pickett | 0de9550 | 2007-04-12 01:35:59 -0400 | [diff] [blame] | 193 | unsigned long first_jiffies; |
| 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | unsigned int repeat_count; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 196 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 197 | char rc_name[NAME_BUFSIZE]; |
| 198 | char rc_phys[NAME_BUFSIZE]; |
| 199 | char mouse_name[NAME_BUFSIZE]; |
| 200 | char mouse_phys[NAME_BUFSIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | wait_queue_head_t wait; |
| 203 | int send_flags; |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 204 | |
| 205 | int users; /* 0-2, users are rc and input */ |
| 206 | struct mutex open_mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | /* "Kinds" of messages sent from the hardware to the driver. */ |
| 210 | #define KIND_END 0 |
| 211 | #define KIND_LITERAL 1 /* Simply pass to input system */ |
| 212 | #define KIND_FILTERED 2 /* Add artificial key-up events, drop keyrepeats */ |
| 213 | #define KIND_LU 3 /* Directional keypad diagonals - left up, */ |
| 214 | #define KIND_RU 4 /* right up, */ |
| 215 | #define KIND_LD 5 /* left down, */ |
| 216 | #define KIND_RD 6 /* right down */ |
| 217 | #define KIND_ACCEL 7 /* Directional keypad - left, right, up, down.*/ |
| 218 | |
| 219 | /* Translation table from hardware messages to input events. */ |
Arjan van de Ven | 4c4c943 | 2005-11-29 09:43:42 +0100 | [diff] [blame] | 220 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | short kind; |
| 222 | unsigned char data1, data2; |
| 223 | int type; |
| 224 | unsigned int code; |
| 225 | int value; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 226 | } ati_remote_tbl[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* Directional control pad axes */ |
| 228 | {KIND_ACCEL, 0x35, 0x70, EV_REL, REL_X, -1}, /* left */ |
| 229 | {KIND_ACCEL, 0x36, 0x71, EV_REL, REL_X, 1}, /* right */ |
| 230 | {KIND_ACCEL, 0x37, 0x72, EV_REL, REL_Y, -1}, /* up */ |
| 231 | {KIND_ACCEL, 0x38, 0x73, EV_REL, REL_Y, 1}, /* down */ |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 232 | /* Directional control pad diagonals */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | {KIND_LU, 0x39, 0x74, EV_REL, 0, 0}, /* left up */ |
| 234 | {KIND_RU, 0x3a, 0x75, EV_REL, 0, 0}, /* right up */ |
| 235 | {KIND_LD, 0x3c, 0x77, EV_REL, 0, 0}, /* left down */ |
| 236 | {KIND_RD, 0x3b, 0x76, EV_REL, 0, 0}, /* right down */ |
| 237 | |
| 238 | /* "Mouse button" buttons */ |
| 239 | {KIND_LITERAL, 0x3d, 0x78, EV_KEY, BTN_LEFT, 1}, /* left btn down */ |
| 240 | {KIND_LITERAL, 0x3e, 0x79, EV_KEY, BTN_LEFT, 0}, /* left btn up */ |
| 241 | {KIND_LITERAL, 0x41, 0x7c, EV_KEY, BTN_RIGHT, 1},/* right btn down */ |
| 242 | {KIND_LITERAL, 0x42, 0x7d, EV_KEY, BTN_RIGHT, 0},/* right btn up */ |
| 243 | |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 244 | /* Artificial "doubleclick" events are generated by the hardware. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | * They are mapped to the "side" and "extra" mouse buttons here. */ |
| 246 | {KIND_FILTERED, 0x3f, 0x7a, EV_KEY, BTN_SIDE, 1}, /* left dblclick */ |
| 247 | {KIND_FILTERED, 0x43, 0x7e, EV_KEY, BTN_EXTRA, 1},/* right dblclick */ |
| 248 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 249 | /* Non-mouse events are handled by rc-core */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | {KIND_END, 0x00, 0x00, EV_MAX + 1, 0, 0} |
| 251 | }; |
| 252 | |
| 253 | /* Local function prototypes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | static int ati_remote_sendpacket (struct ati_remote *ati_remote, u16 cmd, unsigned char *data); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 255 | static void ati_remote_irq_out (struct urb *urb); |
| 256 | static void ati_remote_irq_in (struct urb *urb); |
| 257 | static void ati_remote_input_report (struct urb *urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | static int ati_remote_initialize (struct ati_remote *ati_remote); |
| 259 | static int ati_remote_probe (struct usb_interface *interface, const struct usb_device_id *id); |
| 260 | static void ati_remote_disconnect (struct usb_interface *interface); |
| 261 | |
| 262 | /* usb specific object to register with the usb subsystem */ |
| 263 | static struct usb_driver ati_remote_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | .name = "ati_remote", |
| 265 | .probe = ati_remote_probe, |
| 266 | .disconnect = ati_remote_disconnect, |
| 267 | .id_table = ati_remote_table, |
| 268 | }; |
| 269 | |
| 270 | /* |
| 271 | * ati_remote_dump_input |
| 272 | */ |
Greg Kroah-Hartman | 1817b16 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 273 | static void ati_remote_dump(struct device *dev, unsigned char *data, |
| 274 | unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | { |
Anssi Hannula | 0224e04 | 2011-08-06 18:18:10 -0300 | [diff] [blame^] | 276 | if (len == 1) { |
| 277 | if (data[0] != (unsigned char)0xff && data[0] != 0x00) |
| 278 | dev_warn(dev, "Weird byte 0x%02x\n", data[0]); |
| 279 | } else if (len == 4) |
Greg Kroah-Hartman | 1817b16 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 280 | dev_warn(dev, "Weird key %02x %02x %02x %02x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | data[0], data[1], data[2], data[3]); |
| 282 | else |
Greg Kroah-Hartman | 1817b16 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 283 | dev_warn(dev, "Weird data, len=%d %02x %02x %02x %02x %02x %02x ...\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | len, data[0], data[1], data[2], data[3], data[4], data[5]); |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | * ati_remote_open |
| 289 | */ |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 290 | static int ati_remote_open(struct ati_remote *ati_remote) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | { |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 292 | int err = 0; |
| 293 | |
| 294 | mutex_lock(&ati_remote->open_mutex); |
| 295 | |
| 296 | if (ati_remote->users++ != 0) |
| 297 | goto out; /* one was already active */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | /* On first open, submit the read urb which was set up previously. */ |
| 300 | ati_remote->irq_urb->dev = ati_remote->udev; |
| 301 | if (usb_submit_urb(ati_remote->irq_urb, GFP_KERNEL)) { |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 302 | dev_err(&ati_remote->interface->dev, |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 303 | "%s: usb_submit_urb failed!\n", __func__); |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 304 | err = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 307 | out: mutex_unlock(&ati_remote->open_mutex); |
| 308 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | /* |
| 312 | * ati_remote_close |
| 313 | */ |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 314 | static void ati_remote_close(struct ati_remote *ati_remote) |
| 315 | { |
| 316 | mutex_lock(&ati_remote->open_mutex); |
| 317 | if (--ati_remote->users == 0) |
| 318 | usb_kill_urb(ati_remote->irq_urb); |
| 319 | mutex_unlock(&ati_remote->open_mutex); |
| 320 | } |
| 321 | |
| 322 | static int ati_remote_input_open(struct input_dev *inputdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 324 | struct ati_remote *ati_remote = input_get_drvdata(inputdev); |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 325 | return ati_remote_open(ati_remote); |
| 326 | } |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 327 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 328 | static void ati_remote_input_close(struct input_dev *inputdev) |
| 329 | { |
| 330 | struct ati_remote *ati_remote = input_get_drvdata(inputdev); |
| 331 | ati_remote_close(ati_remote); |
| 332 | } |
| 333 | |
| 334 | static int ati_remote_rc_open(struct rc_dev *rdev) |
| 335 | { |
| 336 | struct ati_remote *ati_remote = rdev->priv; |
| 337 | return ati_remote_open(ati_remote); |
| 338 | } |
| 339 | |
| 340 | static void ati_remote_rc_close(struct rc_dev *rdev) |
| 341 | { |
| 342 | struct ati_remote *ati_remote = rdev->priv; |
| 343 | ati_remote_close(ati_remote); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /* |
| 347 | * ati_remote_irq_out |
| 348 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 349 | static void ati_remote_irq_out(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | { |
| 351 | struct ati_remote *ati_remote = urb->context; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (urb->status) { |
| 354 | dev_dbg(&ati_remote->interface->dev, "%s: status %d\n", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 355 | __func__, urb->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | return; |
| 357 | } |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | ati_remote->send_flags |= SEND_FLAG_COMPLETE; |
| 360 | wmb(); |
| 361 | wake_up(&ati_remote->wait); |
| 362 | } |
| 363 | |
| 364 | /* |
| 365 | * ati_remote_sendpacket |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 366 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | * Used to send device initialization strings |
| 368 | */ |
| 369 | static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd, unsigned char *data) |
| 370 | { |
| 371 | int retval = 0; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | /* Set up out_urb */ |
| 374 | memcpy(ati_remote->out_urb->transfer_buffer + 1, data, LO(cmd)); |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 375 | ((char *) ati_remote->out_urb->transfer_buffer)[0] = HI(cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
| 377 | ati_remote->out_urb->transfer_buffer_length = LO(cmd) + 1; |
| 378 | ati_remote->out_urb->dev = ati_remote->udev; |
| 379 | ati_remote->send_flags = SEND_FLAG_IN_PROGRESS; |
| 380 | |
| 381 | retval = usb_submit_urb(ati_remote->out_urb, GFP_ATOMIC); |
| 382 | if (retval) { |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 383 | dev_dbg(&ati_remote->interface->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | "sendpacket: usb_submit_urb failed: %d\n", retval); |
| 385 | return retval; |
| 386 | } |
| 387 | |
| 388 | wait_event_timeout(ati_remote->wait, |
| 389 | ((ati_remote->out_urb->status != -EINPROGRESS) || |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 390 | (ati_remote->send_flags & SEND_FLAG_COMPLETE)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | HZ); |
| 392 | usb_kill_urb(ati_remote->out_urb); |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | return retval; |
| 395 | } |
| 396 | |
| 397 | /* |
| 398 | * ati_remote_event_lookup |
| 399 | */ |
| 400 | static int ati_remote_event_lookup(int rem, unsigned char d1, unsigned char d2) |
| 401 | { |
| 402 | int i; |
| 403 | |
| 404 | for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) { |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 405 | /* |
| 406 | * Decide if the table entry matches the remote input. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | */ |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 408 | if (ati_remote_tbl[i].data1 == d1 && |
| 409 | ati_remote_tbl[i].data2 == d2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | return i; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | return -1; |
| 414 | } |
| 415 | |
| 416 | /* |
Dmitry Torokhov | 2ffc1cc | 2006-08-04 22:53:37 -0400 | [diff] [blame] | 417 | * ati_remote_compute_accel |
| 418 | * |
| 419 | * Implements acceleration curve for directional control pad |
| 420 | * If elapsed time since last event is > 1/4 second, user "stopped", |
| 421 | * so reset acceleration. Otherwise, user is probably holding the control |
| 422 | * pad down, so we increase acceleration, ramping up over two seconds to |
| 423 | * a maximum speed. |
| 424 | */ |
| 425 | static int ati_remote_compute_accel(struct ati_remote *ati_remote) |
| 426 | { |
| 427 | static const char accel[] = { 1, 2, 4, 6, 9, 13, 20 }; |
| 428 | unsigned long now = jiffies; |
| 429 | int acc; |
| 430 | |
| 431 | if (time_after(now, ati_remote->old_jiffies + msecs_to_jiffies(250))) { |
| 432 | acc = 1; |
| 433 | ati_remote->acc_jiffies = now; |
| 434 | } |
| 435 | else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(125))) |
| 436 | acc = accel[0]; |
| 437 | else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(250))) |
| 438 | acc = accel[1]; |
| 439 | else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(500))) |
| 440 | acc = accel[2]; |
| 441 | else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(1000))) |
| 442 | acc = accel[3]; |
| 443 | else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(1500))) |
| 444 | acc = accel[4]; |
| 445 | else if (time_before(now, ati_remote->acc_jiffies + msecs_to_jiffies(2000))) |
| 446 | acc = accel[5]; |
| 447 | else |
| 448 | acc = accel[6]; |
| 449 | |
| 450 | return acc; |
| 451 | } |
| 452 | |
| 453 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | * ati_remote_report_input |
| 455 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 456 | static void ati_remote_input_report(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | { |
| 458 | struct ati_remote *ati_remote = urb->context; |
| 459 | unsigned char *data= ati_remote->inbuf; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 460 | struct input_dev *dev = ati_remote->idev; |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 461 | int index = -1; |
| 462 | int acc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | int remote_num; |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 464 | unsigned char scancode[2]; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | /* Deal with strange looking inputs */ |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 467 | if ( (urb->actual_length != 4) || (data[0] != 0x14) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | ((data[3] & 0x0f) != 0x00) ) { |
Greg Kroah-Hartman | 1817b16 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 469 | ati_remote_dump(&urb->dev->dev, data, urb->actual_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | return; |
| 471 | } |
| 472 | |
| 473 | /* Mask unwanted remote channels. */ |
| 474 | /* note: remote_num is 0-based, channel 1 on remote == 0 here */ |
| 475 | remote_num = (data[3] >> 4) & 0x0f; |
Anssi Hannula | 9688efd | 2011-08-06 18:18:07 -0300 | [diff] [blame] | 476 | if (channel_mask & (1 << (remote_num + 1))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | dbginfo(&ati_remote->interface->dev, |
| 478 | "Masked input from channel 0x%02x: data %02x,%02x, mask= 0x%02lx\n", |
| 479 | remote_num, data[1], data[2], channel_mask); |
| 480 | return; |
| 481 | } |
| 482 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 483 | scancode[0] = (((data[1] - ((remote_num + 1) << 4)) & 0xf0) | (data[1] & 0x0f)); |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 484 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 485 | scancode[1] = data[2]; |
| 486 | |
| 487 | /* Look up event code index in mouse translation table. */ |
| 488 | index = ati_remote_event_lookup(remote_num, scancode[0], scancode[1]); |
| 489 | |
| 490 | if (index >= 0) { |
| 491 | dbginfo(&ati_remote->interface->dev, |
| 492 | "channel 0x%02x; mouse data %02x,%02x; index %d; keycode %d\n", |
| 493 | remote_num, data[1], data[2], index, ati_remote_tbl[index].code); |
| 494 | if (!dev) |
| 495 | return; /* no mouse device */ |
| 496 | } else |
| 497 | dbginfo(&ati_remote->interface->dev, |
| 498 | "channel 0x%02x; key data %02x,%02x, scancode %02x,%02x\n", |
| 499 | remote_num, data[1], data[2], scancode[0], scancode[1]); |
| 500 | |
| 501 | |
| 502 | if (index >= 0 && ati_remote_tbl[index].kind == KIND_LITERAL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | input_event(dev, ati_remote_tbl[index].type, |
| 504 | ati_remote_tbl[index].code, |
| 505 | ati_remote_tbl[index].value); |
| 506 | input_sync(dev); |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | ati_remote->old_jiffies = jiffies; |
| 509 | return; |
| 510 | } |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 511 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 512 | if (index < 0 || ati_remote_tbl[index].kind == KIND_FILTERED) { |
Karl Pickett | 0de9550 | 2007-04-12 01:35:59 -0400 | [diff] [blame] | 513 | unsigned long now = jiffies; |
| 514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | /* Filter duplicate events which happen "too close" together. */ |
Edwin Huffstutler | c669869 | 2006-08-04 22:53:02 -0400 | [diff] [blame] | 516 | if (ati_remote->old_data[0] == data[1] && |
| 517 | ati_remote->old_data[1] == data[2] && |
Karl Pickett | 0de9550 | 2007-04-12 01:35:59 -0400 | [diff] [blame] | 518 | time_before(now, ati_remote->old_jiffies + |
| 519 | msecs_to_jiffies(repeat_filter))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | ati_remote->repeat_count++; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 521 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | ati_remote->repeat_count = 0; |
Karl Pickett | 0de9550 | 2007-04-12 01:35:59 -0400 | [diff] [blame] | 523 | ati_remote->first_jiffies = now; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | } |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | ati_remote->old_data[0] = data[1]; |
| 527 | ati_remote->old_data[1] = data[2]; |
Karl Pickett | 0de9550 | 2007-04-12 01:35:59 -0400 | [diff] [blame] | 528 | ati_remote->old_jiffies = now; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
Karl Pickett | 0de9550 | 2007-04-12 01:35:59 -0400 | [diff] [blame] | 530 | /* Ensure we skip at least the 4 first duplicate events (generated |
| 531 | * by a single keypress), and continue skipping until repeat_delay |
| 532 | * msecs have passed |
| 533 | */ |
Edwin Huffstutler | c669869 | 2006-08-04 22:53:02 -0400 | [diff] [blame] | 534 | if (ati_remote->repeat_count > 0 && |
Karl Pickett | 0de9550 | 2007-04-12 01:35:59 -0400 | [diff] [blame] | 535 | (ati_remote->repeat_count < 5 || |
| 536 | time_before(now, ati_remote->first_jiffies + |
| 537 | msecs_to_jiffies(repeat_delay)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | return; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 539 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 540 | if (index < 0) { |
| 541 | /* Not a mouse event, hand it to rc-core. */ |
| 542 | u32 rc_code = (scancode[0] << 8) | scancode[1]; |
| 543 | |
| 544 | /* |
| 545 | * We don't use the rc-core repeat handling yet as |
| 546 | * it would cause ghost repeats which would be a |
| 547 | * regression for this driver. |
| 548 | */ |
| 549 | rc_keydown_notimeout(ati_remote->rdev, rc_code, 0); |
| 550 | rc_keyup(ati_remote->rdev); |
| 551 | return; |
| 552 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | input_event(dev, ati_remote_tbl[index].type, |
| 555 | ati_remote_tbl[index].code, 1); |
Dmitry Torokhov | c3c38fb | 2006-08-04 22:53:24 -0400 | [diff] [blame] | 556 | input_sync(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | input_event(dev, ati_remote_tbl[index].type, |
| 558 | ati_remote_tbl[index].code, 0); |
| 559 | input_sync(dev); |
| 560 | |
Dmitry Torokhov | 2ffc1cc | 2006-08-04 22:53:37 -0400 | [diff] [blame] | 561 | } else { |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 562 | |
Dmitry Torokhov | 2ffc1cc | 2006-08-04 22:53:37 -0400 | [diff] [blame] | 563 | /* |
| 564 | * Other event kinds are from the directional control pad, and have an |
| 565 | * acceleration factor applied to them. Without this acceleration, the |
| 566 | * control pad is mostly unusable. |
| 567 | */ |
| 568 | acc = ati_remote_compute_accel(ati_remote); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Dmitry Torokhov | 2ffc1cc | 2006-08-04 22:53:37 -0400 | [diff] [blame] | 570 | switch (ati_remote_tbl[index].kind) { |
| 571 | case KIND_ACCEL: |
| 572 | input_event(dev, ati_remote_tbl[index].type, |
| 573 | ati_remote_tbl[index].code, |
| 574 | ati_remote_tbl[index].value * acc); |
| 575 | break; |
| 576 | case KIND_LU: |
| 577 | input_report_rel(dev, REL_X, -acc); |
| 578 | input_report_rel(dev, REL_Y, -acc); |
| 579 | break; |
| 580 | case KIND_RU: |
| 581 | input_report_rel(dev, REL_X, acc); |
| 582 | input_report_rel(dev, REL_Y, -acc); |
| 583 | break; |
| 584 | case KIND_LD: |
| 585 | input_report_rel(dev, REL_X, -acc); |
| 586 | input_report_rel(dev, REL_Y, acc); |
| 587 | break; |
| 588 | case KIND_RD: |
| 589 | input_report_rel(dev, REL_X, acc); |
| 590 | input_report_rel(dev, REL_Y, acc); |
| 591 | break; |
| 592 | default: |
| 593 | dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n", |
| 594 | ati_remote_tbl[index].kind); |
| 595 | } |
| 596 | input_sync(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Dmitry Torokhov | 2ffc1cc | 2006-08-04 22:53:37 -0400 | [diff] [blame] | 598 | ati_remote->old_jiffies = jiffies; |
| 599 | ati_remote->old_data[0] = data[1]; |
| 600 | ati_remote->old_data[1] = data[2]; |
| 601 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /* |
| 605 | * ati_remote_irq_in |
| 606 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 607 | static void ati_remote_irq_in(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | { |
| 609 | struct ati_remote *ati_remote = urb->context; |
| 610 | int retval; |
| 611 | |
| 612 | switch (urb->status) { |
| 613 | case 0: /* success */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 614 | ati_remote_input_report(urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | break; |
| 616 | case -ECONNRESET: /* unlink */ |
| 617 | case -ENOENT: |
| 618 | case -ESHUTDOWN: |
| 619 | dev_dbg(&ati_remote->interface->dev, "%s: urb error status, unlink? \n", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 620 | __func__); |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 621 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | default: /* error */ |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 623 | dev_dbg(&ati_remote->interface->dev, "%s: Nonzero urb status %d\n", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 624 | __func__, urb->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | } |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 626 | |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 627 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | if (retval) |
| 629 | dev_err(&ati_remote->interface->dev, "%s: usb_submit_urb()=%d\n", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 630 | __func__, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /* |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 634 | * ati_remote_alloc_buffers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | */ |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 636 | static int ati_remote_alloc_buffers(struct usb_device *udev, |
| 637 | struct ati_remote *ati_remote) |
| 638 | { |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 639 | ati_remote->inbuf = usb_alloc_coherent(udev, DATA_BUFSIZE, GFP_ATOMIC, |
| 640 | &ati_remote->inbuf_dma); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 641 | if (!ati_remote->inbuf) |
| 642 | return -1; |
| 643 | |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 644 | ati_remote->outbuf = usb_alloc_coherent(udev, DATA_BUFSIZE, GFP_ATOMIC, |
Anssi Hannula | 9688efd | 2011-08-06 18:18:07 -0300 | [diff] [blame] | 645 | &ati_remote->outbuf_dma); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 646 | if (!ati_remote->outbuf) |
| 647 | return -1; |
| 648 | |
| 649 | ati_remote->irq_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 650 | if (!ati_remote->irq_urb) |
| 651 | return -1; |
| 652 | |
| 653 | ati_remote->out_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 654 | if (!ati_remote->out_urb) |
| 655 | return -1; |
| 656 | |
| 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | /* |
| 661 | * ati_remote_free_buffers |
| 662 | */ |
| 663 | static void ati_remote_free_buffers(struct ati_remote *ati_remote) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | { |
Mariusz Kozlowski | 459f836 | 2006-11-08 15:35:46 +0100 | [diff] [blame] | 665 | usb_free_urb(ati_remote->irq_urb); |
| 666 | usb_free_urb(ati_remote->out_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 668 | usb_free_coherent(ati_remote->udev, DATA_BUFSIZE, |
Mariusz Kozlowski | 9dce447 | 2006-11-25 11:09:38 -0800 | [diff] [blame] | 669 | ati_remote->inbuf, ati_remote->inbuf_dma); |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 670 | |
Daniel Mack | 997ea58 | 2010-04-12 13:17:25 +0200 | [diff] [blame] | 671 | usb_free_coherent(ati_remote->udev, DATA_BUFSIZE, |
Mariusz Kozlowski | 9dce447 | 2006-11-25 11:09:38 -0800 | [diff] [blame] | 672 | ati_remote->outbuf, ati_remote->outbuf_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | static void ati_remote_input_init(struct ati_remote *ati_remote) |
| 676 | { |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 677 | struct input_dev *idev = ati_remote->idev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | int i; |
| 679 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 680 | idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
| 681 | idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | |
| 682 | BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA); |
| 683 | idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) |
| 685 | if (ati_remote_tbl[i].type == EV_KEY) |
| 686 | set_bit(ati_remote_tbl[i].code, idev->keybit); |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 687 | |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 688 | input_set_drvdata(idev, ati_remote); |
| 689 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 690 | idev->open = ati_remote_input_open; |
| 691 | idev->close = ati_remote_input_close; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 692 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 693 | idev->name = ati_remote->mouse_name; |
| 694 | idev->phys = ati_remote->mouse_phys; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 695 | |
Dmitry Torokhov | 16a334c | 2005-06-30 00:49:08 -0500 | [diff] [blame] | 696 | usb_to_input_id(ati_remote->udev, &idev->id); |
Anssi Hannula | 44fd0b6 | 2011-08-06 18:18:09 -0300 | [diff] [blame] | 697 | idev->dev.parent = &ati_remote->interface->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | } |
| 699 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 700 | static void ati_remote_rc_init(struct ati_remote *ati_remote) |
| 701 | { |
| 702 | struct rc_dev *rdev = ati_remote->rdev; |
| 703 | |
| 704 | rdev->priv = ati_remote; |
| 705 | rdev->driver_type = RC_DRIVER_SCANCODE; |
| 706 | rdev->allowed_protos = RC_TYPE_OTHER; |
| 707 | rdev->driver_name = "ati_remote"; |
| 708 | |
| 709 | rdev->open = ati_remote_rc_open; |
| 710 | rdev->close = ati_remote_rc_close; |
| 711 | |
| 712 | rdev->input_name = ati_remote->rc_name; |
| 713 | rdev->input_phys = ati_remote->rc_phys; |
| 714 | |
| 715 | usb_to_input_id(ati_remote->udev, &rdev->input_id); |
Anssi Hannula | 44fd0b6 | 2011-08-06 18:18:09 -0300 | [diff] [blame] | 716 | rdev->dev.parent = &ati_remote->interface->dev; |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 717 | |
| 718 | rdev->map_name = RC_MAP_ATI_X10; |
| 719 | } |
| 720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | static int ati_remote_initialize(struct ati_remote *ati_remote) |
| 722 | { |
| 723 | struct usb_device *udev = ati_remote->udev; |
| 724 | int pipe, maxp; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | init_waitqueue_head(&ati_remote->wait); |
| 727 | |
| 728 | /* Set up irq_urb */ |
| 729 | pipe = usb_rcvintpipe(udev, ati_remote->endpoint_in->bEndpointAddress); |
| 730 | maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); |
| 731 | maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 732 | |
| 733 | usb_fill_int_urb(ati_remote->irq_urb, udev, pipe, ati_remote->inbuf, |
| 734 | maxp, ati_remote_irq_in, ati_remote, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | ati_remote->endpoint_in->bInterval); |
| 736 | ati_remote->irq_urb->transfer_dma = ati_remote->inbuf_dma; |
| 737 | ati_remote->irq_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | /* Set up out_urb */ |
| 740 | pipe = usb_sndintpipe(udev, ati_remote->endpoint_out->bEndpointAddress); |
| 741 | maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); |
| 742 | maxp = (maxp > DATA_BUFSIZE) ? DATA_BUFSIZE : maxp; |
| 743 | |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 744 | usb_fill_int_urb(ati_remote->out_urb, udev, pipe, ati_remote->outbuf, |
| 745 | maxp, ati_remote_irq_out, ati_remote, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | ati_remote->endpoint_out->bInterval); |
| 747 | ati_remote->out_urb->transfer_dma = ati_remote->outbuf_dma; |
| 748 | ati_remote->out_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 749 | |
| 750 | /* send initialization strings */ |
| 751 | if ((ati_remote_sendpacket(ati_remote, 0x8004, init1)) || |
| 752 | (ati_remote_sendpacket(ati_remote, 0x8007, init2))) { |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 753 | dev_err(&ati_remote->interface->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | "Initializing ati_remote hardware failed.\n"); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 755 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | /* |
| 762 | * ati_remote_probe |
| 763 | */ |
| 764 | static int ati_remote_probe(struct usb_interface *interface, const struct usb_device_id *id) |
| 765 | { |
| 766 | struct usb_device *udev = interface_to_usbdev(interface); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 767 | struct usb_host_interface *iface_host = interface->cur_altsetting; |
| 768 | struct usb_endpoint_descriptor *endpoint_in, *endpoint_out; |
| 769 | struct ati_remote *ati_remote; |
| 770 | struct input_dev *input_dev; |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 771 | struct rc_dev *rc_dev; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 772 | int err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | if (iface_host->desc.bNumEndpoints != 2) { |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 775 | err("%s: Unexpected desc.bNumEndpoints\n", __func__); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 776 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 779 | endpoint_in = &iface_host->endpoint[0].desc; |
| 780 | endpoint_out = &iface_host->endpoint[1].desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
Luiz Fernando N. Capitulino | 96642a2 | 2006-09-27 11:58:53 -0700 | [diff] [blame] | 782 | if (!usb_endpoint_is_int_in(endpoint_in)) { |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 783 | err("%s: Unexpected endpoint_in\n", __func__); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 784 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | } |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 786 | if (le16_to_cpu(endpoint_in->wMaxPacketSize) == 0) { |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 787 | err("%s: endpoint_in message size==0? \n", __func__); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 788 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 791 | ati_remote = kzalloc(sizeof (struct ati_remote), GFP_KERNEL); |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 792 | rc_dev = rc_allocate_device(); |
| 793 | if (!ati_remote || !rc_dev) |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 794 | goto fail1; |
| 795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | /* Allocate URB buffers, URBs */ |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 797 | if (ati_remote_alloc_buffers(udev, ati_remote)) |
| 798 | goto fail2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 800 | ati_remote->endpoint_in = endpoint_in; |
| 801 | ati_remote->endpoint_out = endpoint_out; |
| 802 | ati_remote->udev = udev; |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 803 | ati_remote->rdev = rc_dev; |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 804 | ati_remote->interface = interface; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 806 | usb_make_path(udev, ati_remote->rc_phys, sizeof(ati_remote->rc_phys)); |
| 807 | strlcpy(ati_remote->mouse_phys, ati_remote->rc_phys, |
| 808 | sizeof(ati_remote->mouse_phys)); |
| 809 | |
| 810 | strlcat(ati_remote->rc_phys, "/input0", sizeof(ati_remote->rc_phys)); |
| 811 | strlcat(ati_remote->mouse_phys, "/input1", sizeof(ati_remote->mouse_phys)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | if (udev->manufacturer) |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 814 | strlcpy(ati_remote->rc_name, udev->manufacturer, |
| 815 | sizeof(ati_remote->rc_name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | |
| 817 | if (udev->product) |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 818 | snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name), |
| 819 | "%s %s", ati_remote->rc_name, udev->product); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 821 | if (!strlen(ati_remote->rc_name)) |
| 822 | snprintf(ati_remote->rc_name, sizeof(ati_remote->rc_name), |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 823 | DRIVER_DESC "(%04x,%04x)", |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 824 | le16_to_cpu(ati_remote->udev->descriptor.idVendor), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | le16_to_cpu(ati_remote->udev->descriptor.idProduct)); |
| 826 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 827 | snprintf(ati_remote->mouse_name, sizeof(ati_remote->mouse_name), |
| 828 | "%s mouse", ati_remote->rc_name); |
| 829 | |
| 830 | ati_remote_rc_init(ati_remote); |
| 831 | mutex_init(&ati_remote->open_mutex); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | /* Device Hardware Initialization - fills in ati_remote->idev from udev. */ |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 834 | err = ati_remote_initialize(ati_remote); |
| 835 | if (err) |
| 836 | goto fail3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 838 | /* Set up and register rc device */ |
| 839 | err = rc_register_device(ati_remote->rdev); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 840 | if (err) |
| 841 | goto fail3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 843 | /* use our delay for rc_dev */ |
| 844 | ati_remote->rdev->input_dev->rep[REP_DELAY] = repeat_delay; |
| 845 | |
| 846 | /* Set up and register mouse input device */ |
| 847 | if (mouse) { |
| 848 | input_dev = input_allocate_device(); |
| 849 | if (!input_dev) |
| 850 | goto fail4; |
| 851 | |
| 852 | ati_remote->idev = input_dev; |
| 853 | ati_remote_input_init(ati_remote); |
| 854 | err = input_register_device(input_dev); |
| 855 | |
| 856 | if (err) |
| 857 | goto fail5; |
| 858 | } |
| 859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | usb_set_intfdata(interface, ati_remote); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 861 | return 0; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 862 | |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 863 | fail5: input_free_device(input_dev); |
| 864 | fail4: rc_unregister_device(rc_dev); |
| 865 | rc_dev = NULL; |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 866 | fail3: usb_kill_urb(ati_remote->irq_urb); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 867 | usb_kill_urb(ati_remote->out_urb); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 868 | fail2: ati_remote_free_buffers(ati_remote); |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 869 | fail1: rc_free_device(rc_dev); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 870 | kfree(ati_remote); |
| 871 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | /* |
| 875 | * ati_remote_disconnect |
| 876 | */ |
| 877 | static void ati_remote_disconnect(struct usb_interface *interface) |
| 878 | { |
| 879 | struct ati_remote *ati_remote; |
| 880 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | ati_remote = usb_get_intfdata(interface); |
| 882 | usb_set_intfdata(interface, NULL); |
| 883 | if (!ati_remote) { |
Greg Kroah-Hartman | 1817b16 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 884 | dev_warn(&interface->dev, "%s - null device?\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | return; |
| 886 | } |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 887 | |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 888 | usb_kill_urb(ati_remote->irq_urb); |
| 889 | usb_kill_urb(ati_remote->out_urb); |
Anssi Hannula | c34516e | 2011-08-06 18:18:08 -0300 | [diff] [blame] | 890 | if (ati_remote->idev) |
| 891 | input_unregister_device(ati_remote->idev); |
| 892 | rc_unregister_device(ati_remote->rdev); |
Dmitry Torokhov | c5b7c7c | 2005-09-15 02:01:47 -0500 | [diff] [blame] | 893 | ati_remote_free_buffers(ati_remote); |
| 894 | kfree(ati_remote); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | /* |
| 898 | * ati_remote_init |
| 899 | */ |
| 900 | static int __init ati_remote_init(void) |
| 901 | { |
| 902 | int result; |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | result = usb_register(&ati_remote_driver); |
| 905 | if (result) |
Greg Kroah-Hartman | 899ef6e | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 906 | printk(KERN_ERR KBUILD_MODNAME |
| 907 | ": usb_register error #%d\n", result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | else |
Greg Kroah-Hartman | 899ef6e | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 909 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
| 910 | DRIVER_DESC "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | |
| 912 | return result; |
| 913 | } |
| 914 | |
| 915 | /* |
| 916 | * ati_remote_exit |
| 917 | */ |
| 918 | static void __exit ati_remote_exit(void) |
| 919 | { |
| 920 | usb_deregister(&ati_remote_driver); |
| 921 | } |
| 922 | |
Dmitry Torokhov | 05f091ab | 2005-05-29 02:29:01 -0500 | [diff] [blame] | 923 | /* |
| 924 | * module specification |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | */ |
| 926 | |
| 927 | module_init(ati_remote_init); |
| 928 | module_exit(ati_remote_exit); |
| 929 | |
| 930 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 931 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 932 | MODULE_LICENSE("GPL"); |