Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 1 | /* |
| 2 | * ati_remote2 - ATI/Philips USB RF remote driver |
| 3 | * |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 4 | * Copyright (C) 2005-2008 Ville Syrjala <syrjala@sci.fi> |
| 5 | * Copyright (C) 2007-2008 Peter Stokes <linux@dadeos.co.uk> |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 |
| 9 | * as published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
David Brownell | ae0dadc | 2006-06-13 10:04:34 -0700 | [diff] [blame] | 12 | #include <linux/usb/input.h> |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 13 | |
| 14 | #define DRIVER_DESC "ATI/Philips USB RF remote driver" |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 15 | #define DRIVER_VERSION "0.3" |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 16 | |
| 17 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 18 | MODULE_VERSION(DRIVER_VERSION); |
| 19 | MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>"); |
| 20 | MODULE_LICENSE("GPL"); |
| 21 | |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 22 | /* |
| 23 | * ATI Remote Wonder II Channel Configuration |
| 24 | * |
| 25 | * The remote control can by assigned one of sixteen "channels" in order to facilitate |
| 26 | * the use of multiple remote controls within range of each other. |
| 27 | * A remote's "channel" may be altered by pressing and holding the "PC" button for |
| 28 | * approximately 3 seconds, after which the button will slowly flash the count of the |
| 29 | * currently configured "channel", using the numeric keypad enter a number between 1 and |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 30 | * 16 and then press the "PC" button again, the button will slowly flash the count of the |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 31 | * newly configured "channel". |
| 32 | */ |
| 33 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 34 | enum { |
| 35 | ATI_REMOTE2_MAX_CHANNEL_MASK = 0xFFFF, |
| 36 | ATI_REMOTE2_MAX_MODE_MASK = 0x1F, |
| 37 | }; |
| 38 | |
| 39 | static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK; |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 40 | module_param(channel_mask, uint, 0644); |
| 41 | MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>"); |
| 42 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 43 | static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK; |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 44 | module_param(mode_mask, uint, 0644); |
| 45 | MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>"); |
| 46 | |
| 47 | static struct usb_device_id ati_remote2_id_table[] = { |
| 48 | { USB_DEVICE(0x0471, 0x0602) }, /* ATI Remote Wonder II */ |
| 49 | { } |
| 50 | }; |
| 51 | MODULE_DEVICE_TABLE(usb, ati_remote2_id_table); |
| 52 | |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 53 | static DEFINE_MUTEX(ati_remote2_mutex); |
| 54 | |
| 55 | enum { |
| 56 | ATI_REMOTE2_OPENED = 0x1, |
| 57 | ATI_REMOTE2_SUSPENDED = 0x2, |
| 58 | }; |
| 59 | |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 60 | enum { |
| 61 | ATI_REMOTE2_AUX1, |
| 62 | ATI_REMOTE2_AUX2, |
| 63 | ATI_REMOTE2_AUX3, |
| 64 | ATI_REMOTE2_AUX4, |
| 65 | ATI_REMOTE2_PC, |
| 66 | ATI_REMOTE2_MODES, |
| 67 | }; |
| 68 | |
| 69 | static const struct { |
| 70 | u8 hw_code; |
| 71 | u16 keycode; |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 72 | } ati_remote2_key_table[] = { |
| 73 | { 0x00, KEY_0 }, |
| 74 | { 0x01, KEY_1 }, |
| 75 | { 0x02, KEY_2 }, |
| 76 | { 0x03, KEY_3 }, |
| 77 | { 0x04, KEY_4 }, |
| 78 | { 0x05, KEY_5 }, |
| 79 | { 0x06, KEY_6 }, |
| 80 | { 0x07, KEY_7 }, |
| 81 | { 0x08, KEY_8 }, |
| 82 | { 0x09, KEY_9 }, |
| 83 | { 0x0c, KEY_POWER }, |
| 84 | { 0x0d, KEY_MUTE }, |
| 85 | { 0x10, KEY_VOLUMEUP }, |
| 86 | { 0x11, KEY_VOLUMEDOWN }, |
| 87 | { 0x20, KEY_CHANNELUP }, |
| 88 | { 0x21, KEY_CHANNELDOWN }, |
| 89 | { 0x28, KEY_FORWARD }, |
| 90 | { 0x29, KEY_REWIND }, |
| 91 | { 0x2c, KEY_PLAY }, |
| 92 | { 0x30, KEY_PAUSE }, |
| 93 | { 0x31, KEY_STOP }, |
| 94 | { 0x37, KEY_RECORD }, |
| 95 | { 0x38, KEY_DVD }, |
| 96 | { 0x39, KEY_TV }, |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 97 | { 0x3f, KEY_PROG1 }, /* AUX1-AUX4 and PC */ |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 98 | { 0x54, KEY_MENU }, |
| 99 | { 0x58, KEY_UP }, |
| 100 | { 0x59, KEY_DOWN }, |
| 101 | { 0x5a, KEY_LEFT }, |
| 102 | { 0x5b, KEY_RIGHT }, |
| 103 | { 0x5c, KEY_OK }, |
| 104 | { 0x78, KEY_A }, |
| 105 | { 0x79, KEY_B }, |
| 106 | { 0x7a, KEY_C }, |
| 107 | { 0x7b, KEY_D }, |
| 108 | { 0x7c, KEY_E }, |
| 109 | { 0x7d, KEY_F }, |
| 110 | { 0x82, KEY_ENTER }, |
| 111 | { 0x8e, KEY_VENDOR }, |
| 112 | { 0x96, KEY_COFFEE }, |
| 113 | { 0xa9, BTN_LEFT }, |
| 114 | { 0xaa, BTN_RIGHT }, |
| 115 | { 0xbe, KEY_QUESTION }, |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 116 | { 0xd0, KEY_EDIT }, |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 117 | { 0xd5, KEY_FRONT }, |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 118 | { 0xf9, KEY_INFO }, |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | struct ati_remote2 { |
| 122 | struct input_dev *idev; |
| 123 | struct usb_device *udev; |
| 124 | |
| 125 | struct usb_interface *intf[2]; |
| 126 | struct usb_endpoint_descriptor *ep[2]; |
| 127 | struct urb *urb[2]; |
| 128 | void *buf[2]; |
| 129 | dma_addr_t buf_dma[2]; |
| 130 | |
| 131 | unsigned long jiffies; |
| 132 | int mode; |
| 133 | |
| 134 | char name[64]; |
| 135 | char phys[64]; |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 136 | |
| 137 | /* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */ |
| 138 | u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)]; |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 139 | |
| 140 | unsigned int flags; |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 141 | |
| 142 | unsigned int channel_mask; |
| 143 | unsigned int mode_mask; |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id); |
| 147 | static void ati_remote2_disconnect(struct usb_interface *interface); |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 148 | static int ati_remote2_suspend(struct usb_interface *interface, pm_message_t message); |
| 149 | static int ati_remote2_resume(struct usb_interface *interface); |
Ville Syrjala | 169bc1e | 2009-01-29 23:42:16 -0800 | [diff] [blame] | 150 | static int ati_remote2_reset_resume(struct usb_interface *interface); |
| 151 | static int ati_remote2_pre_reset(struct usb_interface *interface); |
| 152 | static int ati_remote2_post_reset(struct usb_interface *interface); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 153 | |
| 154 | static struct usb_driver ati_remote2_driver = { |
| 155 | .name = "ati_remote2", |
| 156 | .probe = ati_remote2_probe, |
| 157 | .disconnect = ati_remote2_disconnect, |
| 158 | .id_table = ati_remote2_id_table, |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 159 | .suspend = ati_remote2_suspend, |
| 160 | .resume = ati_remote2_resume, |
Ville Syrjala | 169bc1e | 2009-01-29 23:42:16 -0800 | [diff] [blame] | 161 | .reset_resume = ati_remote2_reset_resume, |
| 162 | .pre_reset = ati_remote2_pre_reset, |
| 163 | .post_reset = ati_remote2_post_reset, |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 164 | .supports_autosuspend = 1, |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 165 | }; |
| 166 | |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 167 | static int ati_remote2_submit_urbs(struct ati_remote2 *ar2) |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 168 | { |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 169 | int r; |
| 170 | |
| 171 | r = usb_submit_urb(ar2->urb[0], GFP_KERNEL); |
| 172 | if (r) { |
| 173 | dev_err(&ar2->intf[0]->dev, |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 174 | "%s(): usb_submit_urb() = %d\n", __func__, r); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 175 | return r; |
| 176 | } |
| 177 | r = usb_submit_urb(ar2->urb[1], GFP_KERNEL); |
| 178 | if (r) { |
| 179 | usb_kill_urb(ar2->urb[0]); |
| 180 | dev_err(&ar2->intf[1]->dev, |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 181 | "%s(): usb_submit_urb() = %d\n", __func__, r); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 182 | return r; |
| 183 | } |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 188 | static void ati_remote2_kill_urbs(struct ati_remote2 *ar2) |
| 189 | { |
| 190 | usb_kill_urb(ar2->urb[1]); |
| 191 | usb_kill_urb(ar2->urb[0]); |
| 192 | } |
| 193 | |
| 194 | static int ati_remote2_open(struct input_dev *idev) |
| 195 | { |
| 196 | struct ati_remote2 *ar2 = input_get_drvdata(idev); |
| 197 | int r; |
| 198 | |
| 199 | dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); |
| 200 | |
| 201 | r = usb_autopm_get_interface(ar2->intf[0]); |
| 202 | if (r) { |
| 203 | dev_err(&ar2->intf[0]->dev, |
| 204 | "%s(): usb_autopm_get_interface() = %d\n", __func__, r); |
| 205 | goto fail1; |
| 206 | } |
| 207 | |
| 208 | mutex_lock(&ati_remote2_mutex); |
| 209 | |
| 210 | if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) { |
| 211 | r = ati_remote2_submit_urbs(ar2); |
| 212 | if (r) |
| 213 | goto fail2; |
| 214 | } |
| 215 | |
| 216 | ar2->flags |= ATI_REMOTE2_OPENED; |
| 217 | |
| 218 | mutex_unlock(&ati_remote2_mutex); |
| 219 | |
| 220 | usb_autopm_put_interface(ar2->intf[0]); |
| 221 | |
| 222 | return 0; |
| 223 | |
| 224 | fail2: |
| 225 | mutex_unlock(&ati_remote2_mutex); |
| 226 | usb_autopm_put_interface(ar2->intf[0]); |
| 227 | fail1: |
| 228 | return r; |
| 229 | } |
| 230 | |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 231 | static void ati_remote2_close(struct input_dev *idev) |
| 232 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 233 | struct ati_remote2 *ar2 = input_get_drvdata(idev); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 234 | |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 235 | dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); |
| 236 | |
| 237 | mutex_lock(&ati_remote2_mutex); |
| 238 | |
| 239 | if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) |
| 240 | ati_remote2_kill_urbs(ar2); |
| 241 | |
| 242 | ar2->flags &= ~ATI_REMOTE2_OPENED; |
| 243 | |
| 244 | mutex_unlock(&ati_remote2_mutex); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 245 | } |
| 246 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 247 | static void ati_remote2_input_mouse(struct ati_remote2 *ar2) |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 248 | { |
| 249 | struct input_dev *idev = ar2->idev; |
| 250 | u8 *data = ar2->buf[0]; |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 251 | int channel, mode; |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 252 | |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 253 | channel = data[0] >> 4; |
| 254 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 255 | if (!((1 << channel) & ar2->channel_mask)) |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 256 | return; |
| 257 | |
| 258 | mode = data[0] & 0x0F; |
| 259 | |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 260 | if (mode > ATI_REMOTE2_PC) { |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 261 | dev_err(&ar2->intf[0]->dev, |
| 262 | "Unknown mode byte (%02x %02x %02x %02x)\n", |
| 263 | data[3], data[2], data[1], data[0]); |
| 264 | return; |
| 265 | } |
| 266 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 267 | if (!((1 << mode) & ar2->mode_mask)) |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 268 | return; |
| 269 | |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 270 | input_event(idev, EV_REL, REL_X, (s8) data[1]); |
| 271 | input_event(idev, EV_REL, REL_Y, (s8) data[2]); |
| 272 | input_sync(idev); |
| 273 | } |
| 274 | |
| 275 | static int ati_remote2_lookup(unsigned int hw_code) |
| 276 | { |
| 277 | int i; |
| 278 | |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 279 | for (i = 0; i < ARRAY_SIZE(ati_remote2_key_table); i++) |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 280 | if (ati_remote2_key_table[i].hw_code == hw_code) |
| 281 | return i; |
| 282 | |
| 283 | return -1; |
| 284 | } |
| 285 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 286 | static void ati_remote2_input_key(struct ati_remote2 *ar2) |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 287 | { |
| 288 | struct input_dev *idev = ar2->idev; |
| 289 | u8 *data = ar2->buf[1]; |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 290 | int channel, mode, hw_code, index; |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 291 | |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 292 | channel = data[0] >> 4; |
| 293 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 294 | if (!((1 << channel) & ar2->channel_mask)) |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 295 | return; |
| 296 | |
| 297 | mode = data[0] & 0x0F; |
| 298 | |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 299 | if (mode > ATI_REMOTE2_PC) { |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 300 | dev_err(&ar2->intf[1]->dev, |
| 301 | "Unknown mode byte (%02x %02x %02x %02x)\n", |
| 302 | data[3], data[2], data[1], data[0]); |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | hw_code = data[2]; |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 307 | if (hw_code == 0x3f) { |
| 308 | /* |
| 309 | * For some incomprehensible reason the mouse pad generates |
| 310 | * events which look identical to the events from the last |
| 311 | * pressed mode key. Naturally we don't want to generate key |
| 312 | * events for the mouse pad so we filter out any subsequent |
| 313 | * events from the same mode key. |
| 314 | */ |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 315 | if (ar2->mode == mode) |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 316 | return; |
| 317 | |
| 318 | if (data[1] == 0) |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 319 | ar2->mode = mode; |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 320 | } |
| 321 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 322 | if (!((1 << mode) & ar2->mode_mask)) |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 323 | return; |
| 324 | |
| 325 | index = ati_remote2_lookup(hw_code); |
| 326 | if (index < 0) { |
| 327 | dev_err(&ar2->intf[1]->dev, |
| 328 | "Unknown code byte (%02x %02x %02x %02x)\n", |
| 329 | data[3], data[2], data[1], data[0]); |
| 330 | return; |
| 331 | } |
| 332 | |
| 333 | switch (data[1]) { |
| 334 | case 0: /* release */ |
| 335 | break; |
| 336 | case 1: /* press */ |
| 337 | ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_DELAY]); |
| 338 | break; |
| 339 | case 2: /* repeat */ |
| 340 | |
| 341 | /* No repeat for mouse buttons. */ |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 342 | if (ar2->keycode[mode][index] == BTN_LEFT || |
| 343 | ar2->keycode[mode][index] == BTN_RIGHT) |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 344 | return; |
| 345 | |
| 346 | if (!time_after_eq(jiffies, ar2->jiffies)) |
| 347 | return; |
| 348 | |
| 349 | ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_PERIOD]); |
| 350 | break; |
| 351 | default: |
| 352 | dev_err(&ar2->intf[1]->dev, |
| 353 | "Unknown state byte (%02x %02x %02x %02x)\n", |
| 354 | data[3], data[2], data[1], data[0]); |
| 355 | return; |
| 356 | } |
| 357 | |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 358 | input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 359 | input_sync(idev); |
| 360 | } |
| 361 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 362 | static void ati_remote2_complete_mouse(struct urb *urb) |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 363 | { |
| 364 | struct ati_remote2 *ar2 = urb->context; |
| 365 | int r; |
| 366 | |
| 367 | switch (urb->status) { |
| 368 | case 0: |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 369 | usb_mark_last_busy(ar2->udev); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 370 | ati_remote2_input_mouse(ar2); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 371 | break; |
| 372 | case -ENOENT: |
| 373 | case -EILSEQ: |
| 374 | case -ECONNRESET: |
| 375 | case -ESHUTDOWN: |
| 376 | dev_dbg(&ar2->intf[0]->dev, |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 377 | "%s(): urb status = %d\n", __func__, urb->status); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 378 | return; |
| 379 | default: |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 380 | usb_mark_last_busy(ar2->udev); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 381 | dev_err(&ar2->intf[0]->dev, |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 382 | "%s(): urb status = %d\n", __func__, urb->status); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | r = usb_submit_urb(urb, GFP_ATOMIC); |
| 386 | if (r) |
| 387 | dev_err(&ar2->intf[0]->dev, |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 388 | "%s(): usb_submit_urb() = %d\n", __func__, r); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 389 | } |
| 390 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 391 | static void ati_remote2_complete_key(struct urb *urb) |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 392 | { |
| 393 | struct ati_remote2 *ar2 = urb->context; |
| 394 | int r; |
| 395 | |
| 396 | switch (urb->status) { |
| 397 | case 0: |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 398 | usb_mark_last_busy(ar2->udev); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 399 | ati_remote2_input_key(ar2); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 400 | break; |
| 401 | case -ENOENT: |
| 402 | case -EILSEQ: |
| 403 | case -ECONNRESET: |
| 404 | case -ESHUTDOWN: |
| 405 | dev_dbg(&ar2->intf[1]->dev, |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 406 | "%s(): urb status = %d\n", __func__, urb->status); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 407 | return; |
| 408 | default: |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 409 | usb_mark_last_busy(ar2->udev); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 410 | dev_err(&ar2->intf[1]->dev, |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 411 | "%s(): urb status = %d\n", __func__, urb->status); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | r = usb_submit_urb(urb, GFP_ATOMIC); |
| 415 | if (r) |
| 416 | dev_err(&ar2->intf[1]->dev, |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 417 | "%s(): usb_submit_urb() = %d\n", __func__, r); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 418 | } |
| 419 | |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 420 | static int ati_remote2_getkeycode(struct input_dev *idev, |
| 421 | int scancode, int *keycode) |
| 422 | { |
| 423 | struct ati_remote2 *ar2 = input_get_drvdata(idev); |
| 424 | int index, mode; |
| 425 | |
| 426 | mode = scancode >> 8; |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 427 | if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask)) |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 428 | return -EINVAL; |
| 429 | |
| 430 | index = ati_remote2_lookup(scancode & 0xFF); |
| 431 | if (index < 0) |
| 432 | return -EINVAL; |
| 433 | |
| 434 | *keycode = ar2->keycode[mode][index]; |
| 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | static int ati_remote2_setkeycode(struct input_dev *idev, int scancode, int keycode) |
| 439 | { |
| 440 | struct ati_remote2 *ar2 = input_get_drvdata(idev); |
| 441 | int index, mode, old_keycode; |
| 442 | |
| 443 | mode = scancode >> 8; |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 444 | if (mode > ATI_REMOTE2_PC || !((1 << mode) & ar2->mode_mask)) |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 445 | return -EINVAL; |
| 446 | |
| 447 | index = ati_remote2_lookup(scancode & 0xFF); |
| 448 | if (index < 0) |
| 449 | return -EINVAL; |
| 450 | |
| 451 | if (keycode < KEY_RESERVED || keycode > KEY_MAX) |
| 452 | return -EINVAL; |
| 453 | |
| 454 | old_keycode = ar2->keycode[mode][index]; |
| 455 | ar2->keycode[mode][index] = keycode; |
| 456 | set_bit(keycode, idev->keybit); |
| 457 | |
| 458 | for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) { |
| 459 | for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) { |
| 460 | if (ar2->keycode[mode][index] == old_keycode) |
| 461 | return 0; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | clear_bit(old_keycode, idev->keybit); |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 470 | static int ati_remote2_input_init(struct ati_remote2 *ar2) |
| 471 | { |
| 472 | struct input_dev *idev; |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 473 | int index, mode, retval; |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 474 | |
| 475 | idev = input_allocate_device(); |
| 476 | if (!idev) |
| 477 | return -ENOMEM; |
| 478 | |
| 479 | ar2->idev = idev; |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 480 | input_set_drvdata(idev, ar2); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 481 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 482 | idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL); |
| 483 | idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | |
| 484 | BIT_MASK(BTN_RIGHT); |
| 485 | idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 486 | |
| 487 | for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) { |
| 488 | for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) { |
| 489 | ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode; |
| 490 | set_bit(ar2->keycode[mode][index], idev->keybit); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | /* AUX1-AUX4 and PC generate the same scancode. */ |
| 495 | index = ati_remote2_lookup(0x3f); |
| 496 | ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1; |
| 497 | ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2; |
| 498 | ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3; |
| 499 | ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4; |
| 500 | ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC; |
| 501 | set_bit(KEY_PROG1, idev->keybit); |
| 502 | set_bit(KEY_PROG2, idev->keybit); |
| 503 | set_bit(KEY_PROG3, idev->keybit); |
| 504 | set_bit(KEY_PROG4, idev->keybit); |
| 505 | set_bit(KEY_PC, idev->keybit); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 506 | |
| 507 | idev->rep[REP_DELAY] = 250; |
| 508 | idev->rep[REP_PERIOD] = 33; |
| 509 | |
| 510 | idev->open = ati_remote2_open; |
| 511 | idev->close = ati_remote2_close; |
| 512 | |
Ville Syrjala | 1971b9d | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 513 | idev->getkeycode = ati_remote2_getkeycode; |
| 514 | idev->setkeycode = ati_remote2_setkeycode; |
| 515 | |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 516 | idev->name = ar2->name; |
| 517 | idev->phys = ar2->phys; |
| 518 | |
| 519 | usb_to_input_id(ar2->udev, &idev->id); |
Dmitry Torokhov | c0f82d5 | 2007-04-12 01:35:03 -0400 | [diff] [blame] | 520 | idev->dev.parent = &ar2->udev->dev; |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 521 | |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 522 | retval = input_register_device(idev); |
| 523 | if (retval) |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 524 | input_free_device(idev); |
| 525 | |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 526 | return retval; |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static int ati_remote2_urb_init(struct ati_remote2 *ar2) |
| 530 | { |
| 531 | struct usb_device *udev = ar2->udev; |
| 532 | int i, pipe, maxp; |
| 533 | |
| 534 | for (i = 0; i < 2; i++) { |
| 535 | ar2->buf[i] = usb_buffer_alloc(udev, 4, GFP_KERNEL, &ar2->buf_dma[i]); |
| 536 | if (!ar2->buf[i]) |
| 537 | return -ENOMEM; |
| 538 | |
| 539 | ar2->urb[i] = usb_alloc_urb(0, GFP_KERNEL); |
| 540 | if (!ar2->urb[i]) |
| 541 | return -ENOMEM; |
| 542 | |
| 543 | pipe = usb_rcvintpipe(udev, ar2->ep[i]->bEndpointAddress); |
| 544 | maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); |
| 545 | maxp = maxp > 4 ? 4 : maxp; |
| 546 | |
| 547 | usb_fill_int_urb(ar2->urb[i], udev, pipe, ar2->buf[i], maxp, |
| 548 | i ? ati_remote2_complete_key : ati_remote2_complete_mouse, |
| 549 | ar2, ar2->ep[i]->bInterval); |
| 550 | ar2->urb[i]->transfer_dma = ar2->buf_dma[i]; |
| 551 | ar2->urb[i]->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 552 | } |
| 553 | |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | static void ati_remote2_urb_cleanup(struct ati_remote2 *ar2) |
| 558 | { |
| 559 | int i; |
| 560 | |
| 561 | for (i = 0; i < 2; i++) { |
Mariusz Kozlowski | 2381526 | 2006-11-08 15:35:50 +0100 | [diff] [blame] | 562 | usb_free_urb(ar2->urb[i]); |
Dmitry Torokhov | e37a97d | 2007-05-03 00:57:29 -0400 | [diff] [blame] | 563 | usb_buffer_free(ar2->udev, 4, ar2->buf[i], ar2->buf_dma[i]); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 567 | static int ati_remote2_setup(struct ati_remote2 *ar2, unsigned int ch_mask) |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 568 | { |
| 569 | int r, i, channel; |
| 570 | |
| 571 | /* |
| 572 | * Configure receiver to only accept input from remote "channel" |
| 573 | * channel == 0 -> Accept input from any remote channel |
| 574 | * channel == 1 -> Only accept input from remote channel 1 |
| 575 | * channel == 2 -> Only accept input from remote channel 2 |
| 576 | * ... |
| 577 | * channel == 16 -> Only accept input from remote channel 16 |
| 578 | */ |
| 579 | |
| 580 | channel = 0; |
| 581 | for (i = 0; i < 16; i++) { |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 582 | if ((1 << i) & ch_mask) { |
| 583 | if (!(~(1 << i) & ch_mask)) |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 584 | channel = i + 1; |
| 585 | break; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | r = usb_control_msg(ar2->udev, usb_sndctrlpipe(ar2->udev, 0), |
| 590 | 0x20, |
| 591 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, |
| 592 | channel, 0x0, NULL, 0, USB_CTRL_SET_TIMEOUT); |
| 593 | if (r) { |
| 594 | dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d\n", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 595 | __func__, r); |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 596 | return r; |
| 597 | } |
| 598 | |
| 599 | return 0; |
| 600 | } |
| 601 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 602 | static ssize_t ati_remote2_show_channel_mask(struct device *dev, |
| 603 | struct device_attribute *attr, |
| 604 | char *buf) |
| 605 | { |
| 606 | struct usb_device *udev = to_usb_device(dev); |
| 607 | struct usb_interface *intf = usb_ifnum_to_if(udev, 0); |
| 608 | struct ati_remote2 *ar2 = usb_get_intfdata(intf); |
| 609 | |
| 610 | return sprintf(buf, "0x%04x\n", ar2->channel_mask); |
| 611 | } |
| 612 | |
| 613 | static ssize_t ati_remote2_store_channel_mask(struct device *dev, |
| 614 | struct device_attribute *attr, |
| 615 | const char *buf, size_t count) |
| 616 | { |
| 617 | struct usb_device *udev = to_usb_device(dev); |
| 618 | struct usb_interface *intf = usb_ifnum_to_if(udev, 0); |
| 619 | struct ati_remote2 *ar2 = usb_get_intfdata(intf); |
| 620 | unsigned long mask; |
| 621 | int r; |
| 622 | |
| 623 | if (strict_strtoul(buf, 0, &mask)) |
| 624 | return -EINVAL; |
| 625 | |
| 626 | if (mask & ~ATI_REMOTE2_MAX_CHANNEL_MASK) |
| 627 | return -EINVAL; |
| 628 | |
| 629 | r = usb_autopm_get_interface(ar2->intf[0]); |
| 630 | if (r) { |
| 631 | dev_err(&ar2->intf[0]->dev, |
| 632 | "%s(): usb_autopm_get_interface() = %d\n", __func__, r); |
| 633 | return r; |
| 634 | } |
| 635 | |
| 636 | mutex_lock(&ati_remote2_mutex); |
| 637 | |
| 638 | if (mask != ar2->channel_mask && !ati_remote2_setup(ar2, mask)) |
| 639 | ar2->channel_mask = mask; |
| 640 | |
| 641 | mutex_unlock(&ati_remote2_mutex); |
| 642 | |
| 643 | usb_autopm_put_interface(ar2->intf[0]); |
| 644 | |
| 645 | return count; |
| 646 | } |
| 647 | |
| 648 | static ssize_t ati_remote2_show_mode_mask(struct device *dev, |
| 649 | struct device_attribute *attr, |
| 650 | char *buf) |
| 651 | { |
| 652 | struct usb_device *udev = to_usb_device(dev); |
| 653 | struct usb_interface *intf = usb_ifnum_to_if(udev, 0); |
| 654 | struct ati_remote2 *ar2 = usb_get_intfdata(intf); |
| 655 | |
| 656 | return sprintf(buf, "0x%02x\n", ar2->mode_mask); |
| 657 | } |
| 658 | |
| 659 | static ssize_t ati_remote2_store_mode_mask(struct device *dev, |
| 660 | struct device_attribute *attr, |
| 661 | const char *buf, size_t count) |
| 662 | { |
| 663 | struct usb_device *udev = to_usb_device(dev); |
| 664 | struct usb_interface *intf = usb_ifnum_to_if(udev, 0); |
| 665 | struct ati_remote2 *ar2 = usb_get_intfdata(intf); |
| 666 | unsigned long mask; |
| 667 | |
| 668 | if (strict_strtoul(buf, 0, &mask)) |
| 669 | return -EINVAL; |
| 670 | |
| 671 | if (mask & ~ATI_REMOTE2_MAX_MODE_MASK) |
| 672 | return -EINVAL; |
| 673 | |
| 674 | ar2->mode_mask = mask; |
| 675 | |
| 676 | return count; |
| 677 | } |
| 678 | |
| 679 | static DEVICE_ATTR(channel_mask, 0644, ati_remote2_show_channel_mask, |
| 680 | ati_remote2_store_channel_mask); |
| 681 | |
| 682 | static DEVICE_ATTR(mode_mask, 0644, ati_remote2_show_mode_mask, |
| 683 | ati_remote2_store_mode_mask); |
| 684 | |
| 685 | static struct attribute *ati_remote2_attrs[] = { |
| 686 | &dev_attr_channel_mask.attr, |
| 687 | &dev_attr_mode_mask.attr, |
| 688 | NULL, |
| 689 | }; |
| 690 | |
| 691 | static struct attribute_group ati_remote2_attr_group = { |
| 692 | .attrs = ati_remote2_attrs, |
| 693 | }; |
| 694 | |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 695 | static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id) |
| 696 | { |
| 697 | struct usb_device *udev = interface_to_usbdev(interface); |
| 698 | struct usb_host_interface *alt = interface->cur_altsetting; |
| 699 | struct ati_remote2 *ar2; |
| 700 | int r; |
| 701 | |
| 702 | if (alt->desc.bInterfaceNumber) |
| 703 | return -ENODEV; |
| 704 | |
| 705 | ar2 = kzalloc(sizeof (struct ati_remote2), GFP_KERNEL); |
| 706 | if (!ar2) |
| 707 | return -ENOMEM; |
| 708 | |
| 709 | ar2->udev = udev; |
| 710 | |
| 711 | ar2->intf[0] = interface; |
| 712 | ar2->ep[0] = &alt->endpoint[0].desc; |
| 713 | |
| 714 | ar2->intf[1] = usb_ifnum_to_if(udev, 1); |
| 715 | r = usb_driver_claim_interface(&ati_remote2_driver, ar2->intf[1], ar2); |
| 716 | if (r) |
| 717 | goto fail1; |
| 718 | alt = ar2->intf[1]->cur_altsetting; |
| 719 | ar2->ep[1] = &alt->endpoint[0].desc; |
| 720 | |
| 721 | r = ati_remote2_urb_init(ar2); |
| 722 | if (r) |
| 723 | goto fail2; |
| 724 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 725 | ar2->channel_mask = channel_mask & ATI_REMOTE2_MAX_CHANNEL_MASK; |
| 726 | ar2->mode_mask = mode_mask & ATI_REMOTE2_MAX_MODE_MASK; |
| 727 | |
| 728 | r = ati_remote2_setup(ar2, ar2->channel_mask); |
Peter Stokes | a1421d3 | 2007-04-12 01:33:10 -0400 | [diff] [blame] | 729 | if (r) |
| 730 | goto fail2; |
| 731 | |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 732 | usb_make_path(udev, ar2->phys, sizeof(ar2->phys)); |
| 733 | strlcat(ar2->phys, "/input0", sizeof(ar2->phys)); |
| 734 | |
| 735 | strlcat(ar2->name, "ATI Remote Wonder II", sizeof(ar2->name)); |
| 736 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 737 | r = sysfs_create_group(&udev->dev.kobj, &ati_remote2_attr_group); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 738 | if (r) |
| 739 | goto fail2; |
| 740 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 741 | r = ati_remote2_input_init(ar2); |
| 742 | if (r) |
| 743 | goto fail3; |
| 744 | |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 745 | usb_set_intfdata(interface, ar2); |
| 746 | |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 747 | interface->needs_remote_wakeup = 1; |
| 748 | |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 749 | return 0; |
| 750 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 751 | fail3: |
| 752 | sysfs_remove_group(&udev->dev.kobj, &ati_remote2_attr_group); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 753 | fail2: |
| 754 | ati_remote2_urb_cleanup(ar2); |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 755 | usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]); |
| 756 | fail1: |
| 757 | kfree(ar2); |
| 758 | |
| 759 | return r; |
| 760 | } |
| 761 | |
| 762 | static void ati_remote2_disconnect(struct usb_interface *interface) |
| 763 | { |
| 764 | struct ati_remote2 *ar2; |
| 765 | struct usb_host_interface *alt = interface->cur_altsetting; |
| 766 | |
| 767 | if (alt->desc.bInterfaceNumber) |
| 768 | return; |
| 769 | |
| 770 | ar2 = usb_get_intfdata(interface); |
| 771 | usb_set_intfdata(interface, NULL); |
| 772 | |
| 773 | input_unregister_device(ar2->idev); |
| 774 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 775 | sysfs_remove_group(&ar2->udev->dev.kobj, &ati_remote2_attr_group); |
| 776 | |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 777 | ati_remote2_urb_cleanup(ar2); |
| 778 | |
| 779 | usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]); |
| 780 | |
| 781 | kfree(ar2); |
| 782 | } |
| 783 | |
Ville Syrjala | d6505ab | 2008-07-03 10:45:37 -0400 | [diff] [blame] | 784 | static int ati_remote2_suspend(struct usb_interface *interface, |
| 785 | pm_message_t message) |
| 786 | { |
| 787 | struct ati_remote2 *ar2; |
| 788 | struct usb_host_interface *alt = interface->cur_altsetting; |
| 789 | |
| 790 | if (alt->desc.bInterfaceNumber) |
| 791 | return 0; |
| 792 | |
| 793 | ar2 = usb_get_intfdata(interface); |
| 794 | |
| 795 | dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); |
| 796 | |
| 797 | mutex_lock(&ati_remote2_mutex); |
| 798 | |
| 799 | if (ar2->flags & ATI_REMOTE2_OPENED) |
| 800 | ati_remote2_kill_urbs(ar2); |
| 801 | |
| 802 | ar2->flags |= ATI_REMOTE2_SUSPENDED; |
| 803 | |
| 804 | mutex_unlock(&ati_remote2_mutex); |
| 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | static int ati_remote2_resume(struct usb_interface *interface) |
| 810 | { |
| 811 | struct ati_remote2 *ar2; |
| 812 | struct usb_host_interface *alt = interface->cur_altsetting; |
| 813 | int r = 0; |
| 814 | |
| 815 | if (alt->desc.bInterfaceNumber) |
| 816 | return 0; |
| 817 | |
| 818 | ar2 = usb_get_intfdata(interface); |
| 819 | |
| 820 | dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); |
| 821 | |
| 822 | mutex_lock(&ati_remote2_mutex); |
| 823 | |
| 824 | if (ar2->flags & ATI_REMOTE2_OPENED) |
| 825 | r = ati_remote2_submit_urbs(ar2); |
| 826 | |
| 827 | if (!r) |
| 828 | ar2->flags &= ~ATI_REMOTE2_SUSPENDED; |
| 829 | |
| 830 | mutex_unlock(&ati_remote2_mutex); |
| 831 | |
| 832 | return r; |
| 833 | } |
| 834 | |
Ville Syrjala | 169bc1e | 2009-01-29 23:42:16 -0800 | [diff] [blame] | 835 | static int ati_remote2_reset_resume(struct usb_interface *interface) |
| 836 | { |
| 837 | struct ati_remote2 *ar2; |
| 838 | struct usb_host_interface *alt = interface->cur_altsetting; |
| 839 | int r = 0; |
| 840 | |
| 841 | if (alt->desc.bInterfaceNumber) |
| 842 | return 0; |
| 843 | |
| 844 | ar2 = usb_get_intfdata(interface); |
| 845 | |
| 846 | dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); |
| 847 | |
| 848 | mutex_lock(&ati_remote2_mutex); |
| 849 | |
Ville Syrjala | d329e33 | 2009-01-29 23:42:16 -0800 | [diff] [blame^] | 850 | r = ati_remote2_setup(ar2, ar2->channel_mask); |
Ville Syrjala | 169bc1e | 2009-01-29 23:42:16 -0800 | [diff] [blame] | 851 | if (r) |
| 852 | goto out; |
| 853 | |
| 854 | if (ar2->flags & ATI_REMOTE2_OPENED) |
| 855 | r = ati_remote2_submit_urbs(ar2); |
| 856 | |
| 857 | if (!r) |
| 858 | ar2->flags &= ~ATI_REMOTE2_SUSPENDED; |
| 859 | |
| 860 | out: |
| 861 | mutex_unlock(&ati_remote2_mutex); |
| 862 | |
| 863 | return r; |
| 864 | } |
| 865 | |
| 866 | static int ati_remote2_pre_reset(struct usb_interface *interface) |
| 867 | { |
| 868 | struct ati_remote2 *ar2; |
| 869 | struct usb_host_interface *alt = interface->cur_altsetting; |
| 870 | |
| 871 | if (alt->desc.bInterfaceNumber) |
| 872 | return 0; |
| 873 | |
| 874 | ar2 = usb_get_intfdata(interface); |
| 875 | |
| 876 | dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); |
| 877 | |
| 878 | mutex_lock(&ati_remote2_mutex); |
| 879 | |
| 880 | if (ar2->flags == ATI_REMOTE2_OPENED) |
| 881 | ati_remote2_kill_urbs(ar2); |
| 882 | |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | static int ati_remote2_post_reset(struct usb_interface *interface) |
| 887 | { |
| 888 | struct ati_remote2 *ar2; |
| 889 | struct usb_host_interface *alt = interface->cur_altsetting; |
| 890 | int r = 0; |
| 891 | |
| 892 | if (alt->desc.bInterfaceNumber) |
| 893 | return 0; |
| 894 | |
| 895 | ar2 = usb_get_intfdata(interface); |
| 896 | |
| 897 | dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); |
| 898 | |
| 899 | if (ar2->flags == ATI_REMOTE2_OPENED) |
| 900 | r = ati_remote2_submit_urbs(ar2); |
| 901 | |
| 902 | mutex_unlock(&ati_remote2_mutex); |
| 903 | |
| 904 | return r; |
| 905 | } |
| 906 | |
Ville Syrjälä | 735b0cb | 2005-12-10 20:30:54 +0200 | [diff] [blame] | 907 | static int __init ati_remote2_init(void) |
| 908 | { |
| 909 | int r; |
| 910 | |
| 911 | r = usb_register(&ati_remote2_driver); |
| 912 | if (r) |
| 913 | printk(KERN_ERR "ati_remote2: usb_register() = %d\n", r); |
| 914 | else |
| 915 | printk(KERN_INFO "ati_remote2: " DRIVER_DESC " " DRIVER_VERSION "\n"); |
| 916 | |
| 917 | return r; |
| 918 | } |
| 919 | |
| 920 | static void __exit ati_remote2_exit(void) |
| 921 | { |
| 922 | usb_deregister(&ati_remote2_driver); |
| 923 | } |
| 924 | |
| 925 | module_init(ati_remote2_init); |
| 926 | module_exit(ati_remote2_exit); |