blob: d8fd58fdf05086efaef0d58b0d6676e0e69916cf [file] [log] [blame]
Ville Syrjälä735b0cb2005-12-10 20:30:54 +02001/*
2 * ati_remote2 - ATI/Philips USB RF remote driver
3 *
Ville Syrjala1971b9d2008-07-03 10:45:37 -04004 * Copyright (C) 2005-2008 Ville Syrjala <syrjala@sci.fi>
5 * Copyright (C) 2007-2008 Peter Stokes <linux@dadeos.co.uk>
Ville Syrjälä735b0cb2005-12-10 20:30:54 +02006 *
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 Brownellae0dadc2006-06-13 10:04:34 -070012#include <linux/usb/input.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Paul Gortmakerd2d84422011-07-03 13:53:48 -040014#include <linux/module.h>
Ville Syrjälä735b0cb2005-12-10 20:30:54 +020015
16#define DRIVER_DESC "ATI/Philips USB RF remote driver"
Ville Syrjälä735b0cb2005-12-10 20:30:54 +020017
18MODULE_DESCRIPTION(DRIVER_DESC);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +020019MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
20MODULE_LICENSE("GPL");
21
Peter Stokesa1421d32007-04-12 01:33:10 -040022/*
23 * ATI Remote Wonder II Channel Configuration
24 *
Wolfram Sangff7242a2018-05-08 15:39:31 -070025 * The remote control can be assigned one of sixteen "channels" in order to facilitate
Peter Stokesa1421d32007-04-12 01:33:10 -040026 * 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 Syrjala1971b9d2008-07-03 10:45:37 -040030 * 16 and then press the "PC" button again, the button will slowly flash the count of the
Peter Stokesa1421d32007-04-12 01:33:10 -040031 * newly configured "channel".
32 */
33
Ville Syrjalad329e332009-01-29 23:42:16 -080034enum {
35 ATI_REMOTE2_MAX_CHANNEL_MASK = 0xFFFF,
36 ATI_REMOTE2_MAX_MODE_MASK = 0x1F,
37};
38
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080039static int ati_remote2_set_mask(const char *val,
Rusty Russell9bbb9e52010-08-11 23:04:12 -060040 const struct kernel_param *kp,
41 unsigned int max)
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080042{
JJ Ding76496e72011-11-09 10:20:14 -080043 unsigned int mask;
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080044 int ret;
45
46 if (!val)
47 return -EINVAL;
48
JJ Ding76496e72011-11-09 10:20:14 -080049 ret = kstrtouint(val, 0, &mask);
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080050 if (ret)
51 return ret;
52
53 if (mask & ~max)
54 return -EINVAL;
55
56 *(unsigned int *)kp->arg = mask;
57
58 return 0;
59}
60
61static int ati_remote2_set_channel_mask(const char *val,
Rusty Russell9bbb9e52010-08-11 23:04:12 -060062 const struct kernel_param *kp)
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080063{
64 pr_debug("%s()\n", __func__);
65
66 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK);
67}
68
Rusty Russell9bbb9e52010-08-11 23:04:12 -060069static int ati_remote2_get_channel_mask(char *buffer,
70 const struct kernel_param *kp)
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080071{
72 pr_debug("%s()\n", __func__);
73
74 return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg);
75}
76
Rusty Russell9bbb9e52010-08-11 23:04:12 -060077static int ati_remote2_set_mode_mask(const char *val,
78 const struct kernel_param *kp)
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080079{
80 pr_debug("%s()\n", __func__);
81
82 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK);
83}
84
Rusty Russell9bbb9e52010-08-11 23:04:12 -060085static int ati_remote2_get_mode_mask(char *buffer,
86 const struct kernel_param *kp)
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080087{
88 pr_debug("%s()\n", __func__);
89
90 return sprintf(buffer, "0x%02x", *(unsigned int *)kp->arg);
91}
92
Ville Syrjalad329e332009-01-29 23:42:16 -080093static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK;
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080094#define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
Luis R. Rodriguez9c278472015-05-27 11:09:38 +093095static const struct kernel_param_ops param_ops_channel_mask = {
Rusty Russell9bbb9e52010-08-11 23:04:12 -060096 .set = ati_remote2_set_channel_mask,
97 .get = ati_remote2_get_channel_mask,
98};
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080099module_param(channel_mask, channel_mask, 0644);
Peter Stokesa1421d32007-04-12 01:33:10 -0400100MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
101
Ville Syrjalad329e332009-01-29 23:42:16 -0800102static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK;
Ville Syrjala8a49cfa2009-01-29 23:42:16 -0800103#define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
Luis R. Rodriguez9c278472015-05-27 11:09:38 +0930104static const struct kernel_param_ops param_ops_mode_mask = {
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600105 .set = ati_remote2_set_mode_mask,
106 .get = ati_remote2_get_mode_mask,
107};
Ville Syrjala8a49cfa2009-01-29 23:42:16 -0800108module_param(mode_mask, mode_mask, 0644);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200109MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
110
Arvind Yadav64954e32017-08-14 22:10:55 -0700111static const struct usb_device_id ati_remote2_id_table[] = {
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200112 { USB_DEVICE(0x0471, 0x0602) }, /* ATI Remote Wonder II */
113 { }
114};
115MODULE_DEVICE_TABLE(usb, ati_remote2_id_table);
116
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400117static DEFINE_MUTEX(ati_remote2_mutex);
118
119enum {
120 ATI_REMOTE2_OPENED = 0x1,
121 ATI_REMOTE2_SUSPENDED = 0x2,
122};
123
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400124enum {
125 ATI_REMOTE2_AUX1,
126 ATI_REMOTE2_AUX2,
127 ATI_REMOTE2_AUX3,
128 ATI_REMOTE2_AUX4,
129 ATI_REMOTE2_PC,
130 ATI_REMOTE2_MODES,
131};
132
133static const struct {
134 u8 hw_code;
135 u16 keycode;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200136} ati_remote2_key_table[] = {
137 { 0x00, KEY_0 },
138 { 0x01, KEY_1 },
139 { 0x02, KEY_2 },
140 { 0x03, KEY_3 },
141 { 0x04, KEY_4 },
142 { 0x05, KEY_5 },
143 { 0x06, KEY_6 },
144 { 0x07, KEY_7 },
145 { 0x08, KEY_8 },
146 { 0x09, KEY_9 },
147 { 0x0c, KEY_POWER },
148 { 0x0d, KEY_MUTE },
149 { 0x10, KEY_VOLUMEUP },
150 { 0x11, KEY_VOLUMEDOWN },
151 { 0x20, KEY_CHANNELUP },
152 { 0x21, KEY_CHANNELDOWN },
153 { 0x28, KEY_FORWARD },
154 { 0x29, KEY_REWIND },
155 { 0x2c, KEY_PLAY },
156 { 0x30, KEY_PAUSE },
157 { 0x31, KEY_STOP },
158 { 0x37, KEY_RECORD },
159 { 0x38, KEY_DVD },
160 { 0x39, KEY_TV },
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400161 { 0x3f, KEY_PROG1 }, /* AUX1-AUX4 and PC */
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200162 { 0x54, KEY_MENU },
163 { 0x58, KEY_UP },
164 { 0x59, KEY_DOWN },
165 { 0x5a, KEY_LEFT },
166 { 0x5b, KEY_RIGHT },
167 { 0x5c, KEY_OK },
168 { 0x78, KEY_A },
169 { 0x79, KEY_B },
170 { 0x7a, KEY_C },
171 { 0x7b, KEY_D },
172 { 0x7c, KEY_E },
173 { 0x7d, KEY_F },
174 { 0x82, KEY_ENTER },
175 { 0x8e, KEY_VENDOR },
176 { 0x96, KEY_COFFEE },
177 { 0xa9, BTN_LEFT },
178 { 0xaa, BTN_RIGHT },
179 { 0xbe, KEY_QUESTION },
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200180 { 0xd0, KEY_EDIT },
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400181 { 0xd5, KEY_FRONT },
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200182 { 0xf9, KEY_INFO },
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200183};
184
185struct ati_remote2 {
186 struct input_dev *idev;
187 struct usb_device *udev;
188
189 struct usb_interface *intf[2];
190 struct usb_endpoint_descriptor *ep[2];
191 struct urb *urb[2];
192 void *buf[2];
193 dma_addr_t buf_dma[2];
194
195 unsigned long jiffies;
196 int mode;
197
198 char name[64];
199 char phys[64];
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400200
201 /* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
202 u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)];
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400203
204 unsigned int flags;
Ville Syrjalad329e332009-01-29 23:42:16 -0800205
206 unsigned int channel_mask;
207 unsigned int mode_mask;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200208};
209
210static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id);
211static void ati_remote2_disconnect(struct usb_interface *interface);
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400212static int ati_remote2_suspend(struct usb_interface *interface, pm_message_t message);
213static int ati_remote2_resume(struct usb_interface *interface);
Ville Syrjala169bc1e2009-01-29 23:42:16 -0800214static int ati_remote2_reset_resume(struct usb_interface *interface);
215static int ati_remote2_pre_reset(struct usb_interface *interface);
216static int ati_remote2_post_reset(struct usb_interface *interface);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200217
218static struct usb_driver ati_remote2_driver = {
219 .name = "ati_remote2",
220 .probe = ati_remote2_probe,
221 .disconnect = ati_remote2_disconnect,
222 .id_table = ati_remote2_id_table,
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400223 .suspend = ati_remote2_suspend,
224 .resume = ati_remote2_resume,
Ville Syrjala169bc1e2009-01-29 23:42:16 -0800225 .reset_resume = ati_remote2_reset_resume,
226 .pre_reset = ati_remote2_pre_reset,
227 .post_reset = ati_remote2_post_reset,
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400228 .supports_autosuspend = 1,
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200229};
230
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400231static int ati_remote2_submit_urbs(struct ati_remote2 *ar2)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200232{
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200233 int r;
234
235 r = usb_submit_urb(ar2->urb[0], GFP_KERNEL);
236 if (r) {
237 dev_err(&ar2->intf[0]->dev,
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400238 "%s(): usb_submit_urb() = %d\n", __func__, r);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200239 return r;
240 }
241 r = usb_submit_urb(ar2->urb[1], GFP_KERNEL);
242 if (r) {
243 usb_kill_urb(ar2->urb[0]);
244 dev_err(&ar2->intf[1]->dev,
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400245 "%s(): usb_submit_urb() = %d\n", __func__, r);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200246 return r;
247 }
248
249 return 0;
250}
251
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400252static void ati_remote2_kill_urbs(struct ati_remote2 *ar2)
253{
254 usb_kill_urb(ar2->urb[1]);
255 usb_kill_urb(ar2->urb[0]);
256}
257
258static int ati_remote2_open(struct input_dev *idev)
259{
260 struct ati_remote2 *ar2 = input_get_drvdata(idev);
261 int r;
262
263 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
264
265 r = usb_autopm_get_interface(ar2->intf[0]);
266 if (r) {
267 dev_err(&ar2->intf[0]->dev,
268 "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
269 goto fail1;
270 }
271
272 mutex_lock(&ati_remote2_mutex);
273
274 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) {
275 r = ati_remote2_submit_urbs(ar2);
276 if (r)
277 goto fail2;
278 }
279
280 ar2->flags |= ATI_REMOTE2_OPENED;
281
282 mutex_unlock(&ati_remote2_mutex);
283
284 usb_autopm_put_interface(ar2->intf[0]);
285
286 return 0;
287
288 fail2:
289 mutex_unlock(&ati_remote2_mutex);
290 usb_autopm_put_interface(ar2->intf[0]);
291 fail1:
292 return r;
293}
294
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200295static void ati_remote2_close(struct input_dev *idev)
296{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400297 struct ati_remote2 *ar2 = input_get_drvdata(idev);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200298
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400299 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
300
301 mutex_lock(&ati_remote2_mutex);
302
303 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED))
304 ati_remote2_kill_urbs(ar2);
305
306 ar2->flags &= ~ATI_REMOTE2_OPENED;
307
308 mutex_unlock(&ati_remote2_mutex);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200309}
310
David Howells7d12e782006-10-05 14:55:46 +0100311static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200312{
313 struct input_dev *idev = ar2->idev;
314 u8 *data = ar2->buf[0];
Peter Stokesa1421d32007-04-12 01:33:10 -0400315 int channel, mode;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200316
Peter Stokesa1421d32007-04-12 01:33:10 -0400317 channel = data[0] >> 4;
318
Ville Syrjalad329e332009-01-29 23:42:16 -0800319 if (!((1 << channel) & ar2->channel_mask))
Peter Stokesa1421d32007-04-12 01:33:10 -0400320 return;
321
322 mode = data[0] & 0x0F;
323
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400324 if (mode > ATI_REMOTE2_PC) {
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200325 dev_err(&ar2->intf[0]->dev,
326 "Unknown mode byte (%02x %02x %02x %02x)\n",
327 data[3], data[2], data[1], data[0]);
328 return;
329 }
330
Ville Syrjalad329e332009-01-29 23:42:16 -0800331 if (!((1 << mode) & ar2->mode_mask))
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200332 return;
333
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200334 input_event(idev, EV_REL, REL_X, (s8) data[1]);
335 input_event(idev, EV_REL, REL_Y, (s8) data[2]);
336 input_sync(idev);
337}
338
339static int ati_remote2_lookup(unsigned int hw_code)
340{
341 int i;
342
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400343 for (i = 0; i < ARRAY_SIZE(ati_remote2_key_table); i++)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200344 if (ati_remote2_key_table[i].hw_code == hw_code)
345 return i;
346
347 return -1;
348}
349
David Howells7d12e782006-10-05 14:55:46 +0100350static void ati_remote2_input_key(struct ati_remote2 *ar2)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200351{
352 struct input_dev *idev = ar2->idev;
353 u8 *data = ar2->buf[1];
Peter Stokesa1421d32007-04-12 01:33:10 -0400354 int channel, mode, hw_code, index;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200355
Peter Stokesa1421d32007-04-12 01:33:10 -0400356 channel = data[0] >> 4;
357
Ville Syrjalad329e332009-01-29 23:42:16 -0800358 if (!((1 << channel) & ar2->channel_mask))
Peter Stokesa1421d32007-04-12 01:33:10 -0400359 return;
360
361 mode = data[0] & 0x0F;
362
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400363 if (mode > ATI_REMOTE2_PC) {
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200364 dev_err(&ar2->intf[1]->dev,
365 "Unknown mode byte (%02x %02x %02x %02x)\n",
366 data[3], data[2], data[1], data[0]);
367 return;
368 }
369
370 hw_code = data[2];
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200371 if (hw_code == 0x3f) {
372 /*
373 * For some incomprehensible reason the mouse pad generates
374 * events which look identical to the events from the last
375 * pressed mode key. Naturally we don't want to generate key
376 * events for the mouse pad so we filter out any subsequent
377 * events from the same mode key.
378 */
Peter Stokesa1421d32007-04-12 01:33:10 -0400379 if (ar2->mode == mode)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200380 return;
381
382 if (data[1] == 0)
Peter Stokesa1421d32007-04-12 01:33:10 -0400383 ar2->mode = mode;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200384 }
385
Ville Syrjalad329e332009-01-29 23:42:16 -0800386 if (!((1 << mode) & ar2->mode_mask))
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200387 return;
388
389 index = ati_remote2_lookup(hw_code);
390 if (index < 0) {
391 dev_err(&ar2->intf[1]->dev,
392 "Unknown code byte (%02x %02x %02x %02x)\n",
393 data[3], data[2], data[1], data[0]);
394 return;
395 }
396
397 switch (data[1]) {
398 case 0: /* release */
399 break;
400 case 1: /* press */
401 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_DELAY]);
402 break;
403 case 2: /* repeat */
404
405 /* No repeat for mouse buttons. */
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400406 if (ar2->keycode[mode][index] == BTN_LEFT ||
407 ar2->keycode[mode][index] == BTN_RIGHT)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200408 return;
409
410 if (!time_after_eq(jiffies, ar2->jiffies))
411 return;
412
413 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_PERIOD]);
414 break;
415 default:
416 dev_err(&ar2->intf[1]->dev,
417 "Unknown state byte (%02x %02x %02x %02x)\n",
418 data[3], data[2], data[1], data[0]);
419 return;
420 }
421
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400422 input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200423 input_sync(idev);
424}
425
David Howells7d12e782006-10-05 14:55:46 +0100426static void ati_remote2_complete_mouse(struct urb *urb)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200427{
428 struct ati_remote2 *ar2 = urb->context;
429 int r;
430
431 switch (urb->status) {
432 case 0:
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400433 usb_mark_last_busy(ar2->udev);
David Howells7d12e782006-10-05 14:55:46 +0100434 ati_remote2_input_mouse(ar2);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200435 break;
436 case -ENOENT:
437 case -EILSEQ:
438 case -ECONNRESET:
439 case -ESHUTDOWN:
440 dev_dbg(&ar2->intf[0]->dev,
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400441 "%s(): urb status = %d\n", __func__, urb->status);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200442 return;
443 default:
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400444 usb_mark_last_busy(ar2->udev);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200445 dev_err(&ar2->intf[0]->dev,
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400446 "%s(): urb status = %d\n", __func__, urb->status);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200447 }
448
449 r = usb_submit_urb(urb, GFP_ATOMIC);
450 if (r)
451 dev_err(&ar2->intf[0]->dev,
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400452 "%s(): usb_submit_urb() = %d\n", __func__, r);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200453}
454
David Howells7d12e782006-10-05 14:55:46 +0100455static void ati_remote2_complete_key(struct urb *urb)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200456{
457 struct ati_remote2 *ar2 = urb->context;
458 int r;
459
460 switch (urb->status) {
461 case 0:
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400462 usb_mark_last_busy(ar2->udev);
David Howells7d12e782006-10-05 14:55:46 +0100463 ati_remote2_input_key(ar2);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200464 break;
465 case -ENOENT:
466 case -EILSEQ:
467 case -ECONNRESET:
468 case -ESHUTDOWN:
469 dev_dbg(&ar2->intf[1]->dev,
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400470 "%s(): urb status = %d\n", __func__, urb->status);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200471 return;
472 default:
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400473 usb_mark_last_busy(ar2->udev);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200474 dev_err(&ar2->intf[1]->dev,
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400475 "%s(): urb status = %d\n", __func__, urb->status);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200476 }
477
478 r = usb_submit_urb(urb, GFP_ATOMIC);
479 if (r)
480 dev_err(&ar2->intf[1]->dev,
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400481 "%s(): usb_submit_urb() = %d\n", __func__, r);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200482}
483
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400484static int ati_remote2_getkeycode(struct input_dev *idev,
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700485 struct input_keymap_entry *ke)
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400486{
487 struct ati_remote2 *ar2 = input_get_drvdata(idev);
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800488 unsigned int mode;
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700489 int offset;
490 unsigned int index;
491 unsigned int scancode;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400492
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700493 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
494 index = ke->index;
495 if (index >= ATI_REMOTE2_MODES *
496 ARRAY_SIZE(ati_remote2_key_table))
497 return -EINVAL;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400498
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700499 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
500 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
501 scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code;
502 } else {
503 if (input_scancode_to_scalar(ke, &scancode))
504 return -EINVAL;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400505
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700506 mode = scancode >> 8;
507 if (mode > ATI_REMOTE2_PC)
508 return -EINVAL;
509
510 offset = ati_remote2_lookup(scancode & 0xff);
511 if (offset < 0)
512 return -EINVAL;
513
514 index = mode * ARRAY_SIZE(ati_remote2_key_table) + offset;
515 }
516
517 ke->keycode = ar2->keycode[mode][offset];
518 ke->len = sizeof(scancode);
519 memcpy(&ke->scancode, &scancode, sizeof(scancode));
520 ke->index = index;
521
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400522 return 0;
523}
524
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800525static int ati_remote2_setkeycode(struct input_dev *idev,
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700526 const struct input_keymap_entry *ke,
527 unsigned int *old_keycode)
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400528{
529 struct ati_remote2 *ar2 = input_get_drvdata(idev);
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700530 unsigned int mode;
531 int offset;
532 unsigned int index;
533 unsigned int scancode;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400534
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700535 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
536 if (ke->index >= ATI_REMOTE2_MODES *
537 ARRAY_SIZE(ati_remote2_key_table))
538 return -EINVAL;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400539
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700540 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
541 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
542 } else {
543 if (input_scancode_to_scalar(ke, &scancode))
544 return -EINVAL;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400545
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700546 mode = scancode >> 8;
547 if (mode > ATI_REMOTE2_PC)
548 return -EINVAL;
549
550 offset = ati_remote2_lookup(scancode & 0xff);
551 if (offset < 0)
552 return -EINVAL;
553 }
554
555 *old_keycode = ar2->keycode[mode][offset];
556 ar2->keycode[mode][offset] = ke->keycode;
557 __set_bit(ke->keycode, idev->keybit);
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400558
559 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
560 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700561 if (ar2->keycode[mode][index] == *old_keycode)
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400562 return 0;
563 }
564 }
565
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700566 __clear_bit(*old_keycode, idev->keybit);
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400567
568 return 0;
569}
570
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200571static int ati_remote2_input_init(struct ati_remote2 *ar2)
572{
573 struct input_dev *idev;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400574 int index, mode, retval;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200575
576 idev = input_allocate_device();
577 if (!idev)
578 return -ENOMEM;
579
580 ar2->idev = idev;
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400581 input_set_drvdata(idev, ar2);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200582
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700583 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL);
584 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
585 BIT_MASK(BTN_RIGHT);
586 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400587
588 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
589 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
590 ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode;
Ville Syrjala225c9882009-05-18 16:01:25 -0700591 __set_bit(ar2->keycode[mode][index], idev->keybit);
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400592 }
593 }
594
595 /* AUX1-AUX4 and PC generate the same scancode. */
596 index = ati_remote2_lookup(0x3f);
597 ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1;
598 ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2;
599 ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3;
600 ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4;
601 ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC;
Ville Syrjala225c9882009-05-18 16:01:25 -0700602 __set_bit(KEY_PROG1, idev->keybit);
603 __set_bit(KEY_PROG2, idev->keybit);
604 __set_bit(KEY_PROG3, idev->keybit);
605 __set_bit(KEY_PROG4, idev->keybit);
606 __set_bit(KEY_PC, idev->keybit);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200607
608 idev->rep[REP_DELAY] = 250;
609 idev->rep[REP_PERIOD] = 33;
610
611 idev->open = ati_remote2_open;
612 idev->close = ati_remote2_close;
613
Dmitry Torokhovaebd6362011-01-31 21:06:39 -0800614 idev->getkeycode = ati_remote2_getkeycode;
615 idev->setkeycode = ati_remote2_setkeycode;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400616
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200617 idev->name = ar2->name;
618 idev->phys = ar2->phys;
619
620 usb_to_input_id(ar2->udev, &idev->id);
Dmitry Torokhovc0f82d52007-04-12 01:35:03 -0400621 idev->dev.parent = &ar2->udev->dev;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200622
Dmitry Torokhov50141862007-04-12 01:33:39 -0400623 retval = input_register_device(idev);
624 if (retval)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200625 input_free_device(idev);
626
Dmitry Torokhov50141862007-04-12 01:33:39 -0400627 return retval;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200628}
629
630static int ati_remote2_urb_init(struct ati_remote2 *ar2)
631{
632 struct usb_device *udev = ar2->udev;
633 int i, pipe, maxp;
634
635 for (i = 0; i < 2; i++) {
Daniel Mack997ea582010-04-12 13:17:25 +0200636 ar2->buf[i] = usb_alloc_coherent(udev, 4, GFP_KERNEL, &ar2->buf_dma[i]);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200637 if (!ar2->buf[i])
638 return -ENOMEM;
639
640 ar2->urb[i] = usb_alloc_urb(0, GFP_KERNEL);
641 if (!ar2->urb[i])
642 return -ENOMEM;
643
644 pipe = usb_rcvintpipe(udev, ar2->ep[i]->bEndpointAddress);
645 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
646 maxp = maxp > 4 ? 4 : maxp;
647
648 usb_fill_int_urb(ar2->urb[i], udev, pipe, ar2->buf[i], maxp,
649 i ? ati_remote2_complete_key : ati_remote2_complete_mouse,
650 ar2, ar2->ep[i]->bInterval);
651 ar2->urb[i]->transfer_dma = ar2->buf_dma[i];
652 ar2->urb[i]->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
653 }
654
655 return 0;
656}
657
658static void ati_remote2_urb_cleanup(struct ati_remote2 *ar2)
659{
660 int i;
661
662 for (i = 0; i < 2; i++) {
Mariusz Kozlowski23815262006-11-08 15:35:50 +0100663 usb_free_urb(ar2->urb[i]);
Daniel Mack997ea582010-04-12 13:17:25 +0200664 usb_free_coherent(ar2->udev, 4, ar2->buf[i], ar2->buf_dma[i]);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200665 }
666}
667
Ville Syrjalad329e332009-01-29 23:42:16 -0800668static int ati_remote2_setup(struct ati_remote2 *ar2, unsigned int ch_mask)
Peter Stokesa1421d32007-04-12 01:33:10 -0400669{
670 int r, i, channel;
671
672 /*
673 * Configure receiver to only accept input from remote "channel"
674 * channel == 0 -> Accept input from any remote channel
675 * channel == 1 -> Only accept input from remote channel 1
676 * channel == 2 -> Only accept input from remote channel 2
677 * ...
678 * channel == 16 -> Only accept input from remote channel 16
679 */
680
681 channel = 0;
682 for (i = 0; i < 16; i++) {
Ville Syrjalad329e332009-01-29 23:42:16 -0800683 if ((1 << i) & ch_mask) {
684 if (!(~(1 << i) & ch_mask))
Peter Stokesa1421d32007-04-12 01:33:10 -0400685 channel = i + 1;
686 break;
687 }
688 }
689
690 r = usb_control_msg(ar2->udev, usb_sndctrlpipe(ar2->udev, 0),
691 0x20,
692 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
693 channel, 0x0, NULL, 0, USB_CTRL_SET_TIMEOUT);
694 if (r) {
695 dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d\n",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400696 __func__, r);
Peter Stokesa1421d32007-04-12 01:33:10 -0400697 return r;
698 }
699
700 return 0;
701}
702
Ville Syrjalad329e332009-01-29 23:42:16 -0800703static ssize_t ati_remote2_show_channel_mask(struct device *dev,
704 struct device_attribute *attr,
705 char *buf)
706{
707 struct usb_device *udev = to_usb_device(dev);
708 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
709 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
710
711 return sprintf(buf, "0x%04x\n", ar2->channel_mask);
712}
713
714static ssize_t ati_remote2_store_channel_mask(struct device *dev,
715 struct device_attribute *attr,
716 const char *buf, size_t count)
717{
718 struct usb_device *udev = to_usb_device(dev);
719 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
720 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
JJ Ding76496e72011-11-09 10:20:14 -0800721 unsigned int mask;
Ville Syrjalad329e332009-01-29 23:42:16 -0800722 int r;
723
JJ Ding76496e72011-11-09 10:20:14 -0800724 r = kstrtouint(buf, 0, &mask);
725 if (r)
726 return r;
Ville Syrjalad329e332009-01-29 23:42:16 -0800727
728 if (mask & ~ATI_REMOTE2_MAX_CHANNEL_MASK)
729 return -EINVAL;
730
731 r = usb_autopm_get_interface(ar2->intf[0]);
732 if (r) {
733 dev_err(&ar2->intf[0]->dev,
734 "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
735 return r;
736 }
737
738 mutex_lock(&ati_remote2_mutex);
739
Ville Syrjala73887542011-05-04 20:54:27 -0700740 if (mask != ar2->channel_mask) {
741 r = ati_remote2_setup(ar2, mask);
742 if (!r)
743 ar2->channel_mask = mask;
744 }
Ville Syrjalad329e332009-01-29 23:42:16 -0800745
746 mutex_unlock(&ati_remote2_mutex);
747
748 usb_autopm_put_interface(ar2->intf[0]);
749
Ville Syrjala73887542011-05-04 20:54:27 -0700750 return r ? r : count;
Ville Syrjalad329e332009-01-29 23:42:16 -0800751}
752
753static ssize_t ati_remote2_show_mode_mask(struct device *dev,
754 struct device_attribute *attr,
755 char *buf)
756{
757 struct usb_device *udev = to_usb_device(dev);
758 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
759 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
760
761 return sprintf(buf, "0x%02x\n", ar2->mode_mask);
762}
763
764static ssize_t ati_remote2_store_mode_mask(struct device *dev,
765 struct device_attribute *attr,
766 const char *buf, size_t count)
767{
768 struct usb_device *udev = to_usb_device(dev);
769 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
770 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
JJ Ding76496e72011-11-09 10:20:14 -0800771 unsigned int mask;
772 int err;
Ville Syrjalad329e332009-01-29 23:42:16 -0800773
JJ Ding76496e72011-11-09 10:20:14 -0800774 err = kstrtouint(buf, 0, &mask);
775 if (err)
776 return err;
Ville Syrjalad329e332009-01-29 23:42:16 -0800777
778 if (mask & ~ATI_REMOTE2_MAX_MODE_MASK)
779 return -EINVAL;
780
781 ar2->mode_mask = mask;
782
783 return count;
784}
785
786static DEVICE_ATTR(channel_mask, 0644, ati_remote2_show_channel_mask,
787 ati_remote2_store_channel_mask);
788
789static DEVICE_ATTR(mode_mask, 0644, ati_remote2_show_mode_mask,
790 ati_remote2_store_mode_mask);
791
792static struct attribute *ati_remote2_attrs[] = {
793 &dev_attr_channel_mask.attr,
794 &dev_attr_mode_mask.attr,
795 NULL,
796};
797
798static struct attribute_group ati_remote2_attr_group = {
799 .attrs = ati_remote2_attrs,
800};
801
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200802static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id)
803{
804 struct usb_device *udev = interface_to_usbdev(interface);
805 struct usb_host_interface *alt = interface->cur_altsetting;
806 struct ati_remote2 *ar2;
807 int r;
808
809 if (alt->desc.bInterfaceNumber)
810 return -ENODEV;
811
812 ar2 = kzalloc(sizeof (struct ati_remote2), GFP_KERNEL);
813 if (!ar2)
814 return -ENOMEM;
815
816 ar2->udev = udev;
817
Vladis Dronov950336b2016-03-23 11:53:46 -0700818 /* Sanity check, first interface must have an endpoint */
819 if (alt->desc.bNumEndpoints < 1 || !alt->endpoint) {
820 dev_err(&interface->dev,
821 "%s(): interface 0 must have an endpoint\n", __func__);
822 r = -ENODEV;
823 goto fail1;
824 }
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200825 ar2->intf[0] = interface;
826 ar2->ep[0] = &alt->endpoint[0].desc;
827
Vladis Dronov950336b2016-03-23 11:53:46 -0700828 /* Sanity check, the device must have two interfaces */
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200829 ar2->intf[1] = usb_ifnum_to_if(udev, 1);
Vladis Dronov950336b2016-03-23 11:53:46 -0700830 if ((udev->actconfig->desc.bNumInterfaces < 2) || !ar2->intf[1]) {
831 dev_err(&interface->dev, "%s(): need 2 interfaces, found %d\n",
832 __func__, udev->actconfig->desc.bNumInterfaces);
833 r = -ENODEV;
834 goto fail1;
835 }
836
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200837 r = usb_driver_claim_interface(&ati_remote2_driver, ar2->intf[1], ar2);
838 if (r)
839 goto fail1;
Vladis Dronov950336b2016-03-23 11:53:46 -0700840
841 /* Sanity check, second interface must have an endpoint */
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200842 alt = ar2->intf[1]->cur_altsetting;
Vladis Dronov950336b2016-03-23 11:53:46 -0700843 if (alt->desc.bNumEndpoints < 1 || !alt->endpoint) {
844 dev_err(&interface->dev,
845 "%s(): interface 1 must have an endpoint\n", __func__);
846 r = -ENODEV;
847 goto fail2;
848 }
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200849 ar2->ep[1] = &alt->endpoint[0].desc;
850
851 r = ati_remote2_urb_init(ar2);
852 if (r)
Vladis Dronov950336b2016-03-23 11:53:46 -0700853 goto fail3;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200854
Ville Syrjala8a49cfa2009-01-29 23:42:16 -0800855 ar2->channel_mask = channel_mask;
856 ar2->mode_mask = mode_mask;
Ville Syrjalad329e332009-01-29 23:42:16 -0800857
858 r = ati_remote2_setup(ar2, ar2->channel_mask);
Peter Stokesa1421d32007-04-12 01:33:10 -0400859 if (r)
Vladis Dronov950336b2016-03-23 11:53:46 -0700860 goto fail3;
Peter Stokesa1421d32007-04-12 01:33:10 -0400861
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200862 usb_make_path(udev, ar2->phys, sizeof(ar2->phys));
863 strlcat(ar2->phys, "/input0", sizeof(ar2->phys));
864
865 strlcat(ar2->name, "ATI Remote Wonder II", sizeof(ar2->name));
866
Ville Syrjalad329e332009-01-29 23:42:16 -0800867 r = sysfs_create_group(&udev->dev.kobj, &ati_remote2_attr_group);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200868 if (r)
Vladis Dronov950336b2016-03-23 11:53:46 -0700869 goto fail3;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200870
Ville Syrjalad329e332009-01-29 23:42:16 -0800871 r = ati_remote2_input_init(ar2);
872 if (r)
Vladis Dronov950336b2016-03-23 11:53:46 -0700873 goto fail4;
Ville Syrjalad329e332009-01-29 23:42:16 -0800874
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200875 usb_set_intfdata(interface, ar2);
876
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400877 interface->needs_remote_wakeup = 1;
878
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200879 return 0;
880
Vladis Dronov950336b2016-03-23 11:53:46 -0700881 fail4:
Ville Syrjalad329e332009-01-29 23:42:16 -0800882 sysfs_remove_group(&udev->dev.kobj, &ati_remote2_attr_group);
Vladis Dronov950336b2016-03-23 11:53:46 -0700883 fail3:
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200884 ati_remote2_urb_cleanup(ar2);
Vladis Dronov950336b2016-03-23 11:53:46 -0700885 fail2:
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200886 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
887 fail1:
888 kfree(ar2);
889
890 return r;
891}
892
893static void ati_remote2_disconnect(struct usb_interface *interface)
894{
895 struct ati_remote2 *ar2;
896 struct usb_host_interface *alt = interface->cur_altsetting;
897
898 if (alt->desc.bInterfaceNumber)
899 return;
900
901 ar2 = usb_get_intfdata(interface);
902 usb_set_intfdata(interface, NULL);
903
904 input_unregister_device(ar2->idev);
905
Ville Syrjalad329e332009-01-29 23:42:16 -0800906 sysfs_remove_group(&ar2->udev->dev.kobj, &ati_remote2_attr_group);
907
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200908 ati_remote2_urb_cleanup(ar2);
909
910 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
911
912 kfree(ar2);
913}
914
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400915static int ati_remote2_suspend(struct usb_interface *interface,
916 pm_message_t message)
917{
918 struct ati_remote2 *ar2;
919 struct usb_host_interface *alt = interface->cur_altsetting;
920
921 if (alt->desc.bInterfaceNumber)
922 return 0;
923
924 ar2 = usb_get_intfdata(interface);
925
926 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
927
928 mutex_lock(&ati_remote2_mutex);
929
930 if (ar2->flags & ATI_REMOTE2_OPENED)
931 ati_remote2_kill_urbs(ar2);
932
933 ar2->flags |= ATI_REMOTE2_SUSPENDED;
934
935 mutex_unlock(&ati_remote2_mutex);
936
937 return 0;
938}
939
940static int ati_remote2_resume(struct usb_interface *interface)
941{
942 struct ati_remote2 *ar2;
943 struct usb_host_interface *alt = interface->cur_altsetting;
944 int r = 0;
945
946 if (alt->desc.bInterfaceNumber)
947 return 0;
948
949 ar2 = usb_get_intfdata(interface);
950
951 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
952
953 mutex_lock(&ati_remote2_mutex);
954
955 if (ar2->flags & ATI_REMOTE2_OPENED)
956 r = ati_remote2_submit_urbs(ar2);
957
958 if (!r)
959 ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
960
961 mutex_unlock(&ati_remote2_mutex);
962
963 return r;
964}
965
Ville Syrjala169bc1e2009-01-29 23:42:16 -0800966static int ati_remote2_reset_resume(struct usb_interface *interface)
967{
968 struct ati_remote2 *ar2;
969 struct usb_host_interface *alt = interface->cur_altsetting;
970 int r = 0;
971
972 if (alt->desc.bInterfaceNumber)
973 return 0;
974
975 ar2 = usb_get_intfdata(interface);
976
977 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
978
979 mutex_lock(&ati_remote2_mutex);
980
Ville Syrjalad329e332009-01-29 23:42:16 -0800981 r = ati_remote2_setup(ar2, ar2->channel_mask);
Ville Syrjala169bc1e2009-01-29 23:42:16 -0800982 if (r)
983 goto out;
984
985 if (ar2->flags & ATI_REMOTE2_OPENED)
986 r = ati_remote2_submit_urbs(ar2);
987
988 if (!r)
989 ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
990
991 out:
992 mutex_unlock(&ati_remote2_mutex);
993
994 return r;
995}
996
997static int ati_remote2_pre_reset(struct usb_interface *interface)
998{
999 struct ati_remote2 *ar2;
1000 struct usb_host_interface *alt = interface->cur_altsetting;
1001
1002 if (alt->desc.bInterfaceNumber)
1003 return 0;
1004
1005 ar2 = usb_get_intfdata(interface);
1006
1007 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
1008
1009 mutex_lock(&ati_remote2_mutex);
1010
1011 if (ar2->flags == ATI_REMOTE2_OPENED)
1012 ati_remote2_kill_urbs(ar2);
1013
1014 return 0;
1015}
1016
1017static int ati_remote2_post_reset(struct usb_interface *interface)
1018{
1019 struct ati_remote2 *ar2;
1020 struct usb_host_interface *alt = interface->cur_altsetting;
1021 int r = 0;
1022
1023 if (alt->desc.bInterfaceNumber)
1024 return 0;
1025
1026 ar2 = usb_get_intfdata(interface);
1027
1028 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
1029
1030 if (ar2->flags == ATI_REMOTE2_OPENED)
1031 r = ati_remote2_submit_urbs(ar2);
1032
1033 mutex_unlock(&ati_remote2_mutex);
1034
1035 return r;
1036}
1037
Greg Kroah-Hartman08642e72011-11-18 09:48:31 -08001038module_usb_driver(ati_remote2_driver);