blob: 0b0e9be6354215319200a8a305c9db55e8b4c3dd [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>
Ville Syrjälä735b0cb2005-12-10 20:30:54 +020014
15#define DRIVER_DESC "ATI/Philips USB RF remote driver"
Ville Syrjala1971b9d2008-07-03 10:45:37 -040016#define DRIVER_VERSION "0.3"
Ville Syrjälä735b0cb2005-12-10 20:30:54 +020017
18MODULE_DESCRIPTION(DRIVER_DESC);
19MODULE_VERSION(DRIVER_VERSION);
20MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
21MODULE_LICENSE("GPL");
22
Peter Stokesa1421d32007-04-12 01:33:10 -040023/*
24 * ATI Remote Wonder II Channel Configuration
25 *
26 * The remote control can by assigned one of sixteen "channels" in order to facilitate
27 * the use of multiple remote controls within range of each other.
28 * A remote's "channel" may be altered by pressing and holding the "PC" button for
29 * approximately 3 seconds, after which the button will slowly flash the count of the
30 * currently configured "channel", using the numeric keypad enter a number between 1 and
Ville Syrjala1971b9d2008-07-03 10:45:37 -040031 * 16 and then press the "PC" button again, the button will slowly flash the count of the
Peter Stokesa1421d32007-04-12 01:33:10 -040032 * newly configured "channel".
33 */
34
Ville Syrjalad329e332009-01-29 23:42:16 -080035enum {
36 ATI_REMOTE2_MAX_CHANNEL_MASK = 0xFFFF,
37 ATI_REMOTE2_MAX_MODE_MASK = 0x1F,
38};
39
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080040static int ati_remote2_set_mask(const char *val,
Rusty Russell9bbb9e52010-08-11 23:04:12 -060041 const struct kernel_param *kp,
42 unsigned int max)
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080043{
44 unsigned long mask;
45 int ret;
46
47 if (!val)
48 return -EINVAL;
49
50 ret = strict_strtoul(val, 0, &mask);
51 if (ret)
52 return ret;
53
54 if (mask & ~max)
55 return -EINVAL;
56
57 *(unsigned int *)kp->arg = mask;
58
59 return 0;
60}
61
62static int ati_remote2_set_channel_mask(const char *val,
Rusty Russell9bbb9e52010-08-11 23:04:12 -060063 const struct kernel_param *kp)
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080064{
65 pr_debug("%s()\n", __func__);
66
67 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK);
68}
69
Rusty Russell9bbb9e52010-08-11 23:04:12 -060070static int ati_remote2_get_channel_mask(char *buffer,
71 const struct kernel_param *kp)
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080072{
73 pr_debug("%s()\n", __func__);
74
75 return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg);
76}
77
Rusty Russell9bbb9e52010-08-11 23:04:12 -060078static int ati_remote2_set_mode_mask(const char *val,
79 const struct kernel_param *kp)
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080080{
81 pr_debug("%s()\n", __func__);
82
83 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK);
84}
85
Rusty Russell9bbb9e52010-08-11 23:04:12 -060086static int ati_remote2_get_mode_mask(char *buffer,
87 const struct kernel_param *kp)
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080088{
89 pr_debug("%s()\n", __func__);
90
91 return sprintf(buffer, "0x%02x", *(unsigned int *)kp->arg);
92}
93
Ville Syrjalad329e332009-01-29 23:42:16 -080094static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK;
Ville Syrjala8a49cfa2009-01-29 23:42:16 -080095#define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
Rusty Russell9bbb9e52010-08-11 23:04:12 -060096static struct kernel_param_ops param_ops_channel_mask = {
97 .set = ati_remote2_set_channel_mask,
98 .get = ati_remote2_get_channel_mask,
99};
Ville Syrjala8a49cfa2009-01-29 23:42:16 -0800100module_param(channel_mask, channel_mask, 0644);
Peter Stokesa1421d32007-04-12 01:33:10 -0400101MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
102
Ville Syrjalad329e332009-01-29 23:42:16 -0800103static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK;
Ville Syrjala8a49cfa2009-01-29 23:42:16 -0800104#define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
Rusty Russell9bbb9e52010-08-11 23:04:12 -0600105static struct kernel_param_ops param_ops_mode_mask = {
106 .set = ati_remote2_set_mode_mask,
107 .get = ati_remote2_get_mode_mask,
108};
Ville Syrjala8a49cfa2009-01-29 23:42:16 -0800109module_param(mode_mask, mode_mask, 0644);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200110MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
111
112static struct usb_device_id ati_remote2_id_table[] = {
113 { USB_DEVICE(0x0471, 0x0602) }, /* ATI Remote Wonder II */
114 { }
115};
116MODULE_DEVICE_TABLE(usb, ati_remote2_id_table);
117
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400118static DEFINE_MUTEX(ati_remote2_mutex);
119
120enum {
121 ATI_REMOTE2_OPENED = 0x1,
122 ATI_REMOTE2_SUSPENDED = 0x2,
123};
124
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400125enum {
126 ATI_REMOTE2_AUX1,
127 ATI_REMOTE2_AUX2,
128 ATI_REMOTE2_AUX3,
129 ATI_REMOTE2_AUX4,
130 ATI_REMOTE2_PC,
131 ATI_REMOTE2_MODES,
132};
133
134static const struct {
135 u8 hw_code;
136 u16 keycode;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200137} ati_remote2_key_table[] = {
138 { 0x00, KEY_0 },
139 { 0x01, KEY_1 },
140 { 0x02, KEY_2 },
141 { 0x03, KEY_3 },
142 { 0x04, KEY_4 },
143 { 0x05, KEY_5 },
144 { 0x06, KEY_6 },
145 { 0x07, KEY_7 },
146 { 0x08, KEY_8 },
147 { 0x09, KEY_9 },
148 { 0x0c, KEY_POWER },
149 { 0x0d, KEY_MUTE },
150 { 0x10, KEY_VOLUMEUP },
151 { 0x11, KEY_VOLUMEDOWN },
152 { 0x20, KEY_CHANNELUP },
153 { 0x21, KEY_CHANNELDOWN },
154 { 0x28, KEY_FORWARD },
155 { 0x29, KEY_REWIND },
156 { 0x2c, KEY_PLAY },
157 { 0x30, KEY_PAUSE },
158 { 0x31, KEY_STOP },
159 { 0x37, KEY_RECORD },
160 { 0x38, KEY_DVD },
161 { 0x39, KEY_TV },
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400162 { 0x3f, KEY_PROG1 }, /* AUX1-AUX4 and PC */
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200163 { 0x54, KEY_MENU },
164 { 0x58, KEY_UP },
165 { 0x59, KEY_DOWN },
166 { 0x5a, KEY_LEFT },
167 { 0x5b, KEY_RIGHT },
168 { 0x5c, KEY_OK },
169 { 0x78, KEY_A },
170 { 0x79, KEY_B },
171 { 0x7a, KEY_C },
172 { 0x7b, KEY_D },
173 { 0x7c, KEY_E },
174 { 0x7d, KEY_F },
175 { 0x82, KEY_ENTER },
176 { 0x8e, KEY_VENDOR },
177 { 0x96, KEY_COFFEE },
178 { 0xa9, BTN_LEFT },
179 { 0xaa, BTN_RIGHT },
180 { 0xbe, KEY_QUESTION },
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200181 { 0xd0, KEY_EDIT },
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400182 { 0xd5, KEY_FRONT },
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200183 { 0xf9, KEY_INFO },
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200184};
185
186struct ati_remote2 {
187 struct input_dev *idev;
188 struct usb_device *udev;
189
190 struct usb_interface *intf[2];
191 struct usb_endpoint_descriptor *ep[2];
192 struct urb *urb[2];
193 void *buf[2];
194 dma_addr_t buf_dma[2];
195
196 unsigned long jiffies;
197 int mode;
198
199 char name[64];
200 char phys[64];
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400201
202 /* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
203 u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)];
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400204
205 unsigned int flags;
Ville Syrjalad329e332009-01-29 23:42:16 -0800206
207 unsigned int channel_mask;
208 unsigned int mode_mask;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200209};
210
211static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id);
212static void ati_remote2_disconnect(struct usb_interface *interface);
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400213static int ati_remote2_suspend(struct usb_interface *interface, pm_message_t message);
214static int ati_remote2_resume(struct usb_interface *interface);
Ville Syrjala169bc1e2009-01-29 23:42:16 -0800215static int ati_remote2_reset_resume(struct usb_interface *interface);
216static int ati_remote2_pre_reset(struct usb_interface *interface);
217static int ati_remote2_post_reset(struct usb_interface *interface);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200218
219static struct usb_driver ati_remote2_driver = {
220 .name = "ati_remote2",
221 .probe = ati_remote2_probe,
222 .disconnect = ati_remote2_disconnect,
223 .id_table = ati_remote2_id_table,
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400224 .suspend = ati_remote2_suspend,
225 .resume = ati_remote2_resume,
Ville Syrjala169bc1e2009-01-29 23:42:16 -0800226 .reset_resume = ati_remote2_reset_resume,
227 .pre_reset = ati_remote2_pre_reset,
228 .post_reset = ati_remote2_post_reset,
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400229 .supports_autosuspend = 1,
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200230};
231
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400232static int ati_remote2_submit_urbs(struct ati_remote2 *ar2)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200233{
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200234 int r;
235
236 r = usb_submit_urb(ar2->urb[0], GFP_KERNEL);
237 if (r) {
238 dev_err(&ar2->intf[0]->dev,
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400239 "%s(): usb_submit_urb() = %d\n", __func__, r);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200240 return r;
241 }
242 r = usb_submit_urb(ar2->urb[1], GFP_KERNEL);
243 if (r) {
244 usb_kill_urb(ar2->urb[0]);
245 dev_err(&ar2->intf[1]->dev,
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400246 "%s(): usb_submit_urb() = %d\n", __func__, r);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200247 return r;
248 }
249
250 return 0;
251}
252
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400253static void ati_remote2_kill_urbs(struct ati_remote2 *ar2)
254{
255 usb_kill_urb(ar2->urb[1]);
256 usb_kill_urb(ar2->urb[0]);
257}
258
259static int ati_remote2_open(struct input_dev *idev)
260{
261 struct ati_remote2 *ar2 = input_get_drvdata(idev);
262 int r;
263
264 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
265
266 r = usb_autopm_get_interface(ar2->intf[0]);
267 if (r) {
268 dev_err(&ar2->intf[0]->dev,
269 "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
270 goto fail1;
271 }
272
273 mutex_lock(&ati_remote2_mutex);
274
275 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) {
276 r = ati_remote2_submit_urbs(ar2);
277 if (r)
278 goto fail2;
279 }
280
281 ar2->flags |= ATI_REMOTE2_OPENED;
282
283 mutex_unlock(&ati_remote2_mutex);
284
285 usb_autopm_put_interface(ar2->intf[0]);
286
287 return 0;
288
289 fail2:
290 mutex_unlock(&ati_remote2_mutex);
291 usb_autopm_put_interface(ar2->intf[0]);
292 fail1:
293 return r;
294}
295
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200296static void ati_remote2_close(struct input_dev *idev)
297{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400298 struct ati_remote2 *ar2 = input_get_drvdata(idev);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200299
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400300 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
301
302 mutex_lock(&ati_remote2_mutex);
303
304 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED))
305 ati_remote2_kill_urbs(ar2);
306
307 ar2->flags &= ~ATI_REMOTE2_OPENED;
308
309 mutex_unlock(&ati_remote2_mutex);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200310}
311
David Howells7d12e782006-10-05 14:55:46 +0100312static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200313{
314 struct input_dev *idev = ar2->idev;
315 u8 *data = ar2->buf[0];
Peter Stokesa1421d32007-04-12 01:33:10 -0400316 int channel, mode;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200317
Peter Stokesa1421d32007-04-12 01:33:10 -0400318 channel = data[0] >> 4;
319
Ville Syrjalad329e332009-01-29 23:42:16 -0800320 if (!((1 << channel) & ar2->channel_mask))
Peter Stokesa1421d32007-04-12 01:33:10 -0400321 return;
322
323 mode = data[0] & 0x0F;
324
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400325 if (mode > ATI_REMOTE2_PC) {
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200326 dev_err(&ar2->intf[0]->dev,
327 "Unknown mode byte (%02x %02x %02x %02x)\n",
328 data[3], data[2], data[1], data[0]);
329 return;
330 }
331
Ville Syrjalad329e332009-01-29 23:42:16 -0800332 if (!((1 << mode) & ar2->mode_mask))
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200333 return;
334
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200335 input_event(idev, EV_REL, REL_X, (s8) data[1]);
336 input_event(idev, EV_REL, REL_Y, (s8) data[2]);
337 input_sync(idev);
338}
339
340static int ati_remote2_lookup(unsigned int hw_code)
341{
342 int i;
343
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400344 for (i = 0; i < ARRAY_SIZE(ati_remote2_key_table); i++)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200345 if (ati_remote2_key_table[i].hw_code == hw_code)
346 return i;
347
348 return -1;
349}
350
David Howells7d12e782006-10-05 14:55:46 +0100351static void ati_remote2_input_key(struct ati_remote2 *ar2)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200352{
353 struct input_dev *idev = ar2->idev;
354 u8 *data = ar2->buf[1];
Peter Stokesa1421d32007-04-12 01:33:10 -0400355 int channel, mode, hw_code, index;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200356
Peter Stokesa1421d32007-04-12 01:33:10 -0400357 channel = data[0] >> 4;
358
Ville Syrjalad329e332009-01-29 23:42:16 -0800359 if (!((1 << channel) & ar2->channel_mask))
Peter Stokesa1421d32007-04-12 01:33:10 -0400360 return;
361
362 mode = data[0] & 0x0F;
363
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400364 if (mode > ATI_REMOTE2_PC) {
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200365 dev_err(&ar2->intf[1]->dev,
366 "Unknown mode byte (%02x %02x %02x %02x)\n",
367 data[3], data[2], data[1], data[0]);
368 return;
369 }
370
371 hw_code = data[2];
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200372 if (hw_code == 0x3f) {
373 /*
374 * For some incomprehensible reason the mouse pad generates
375 * events which look identical to the events from the last
376 * pressed mode key. Naturally we don't want to generate key
377 * events for the mouse pad so we filter out any subsequent
378 * events from the same mode key.
379 */
Peter Stokesa1421d32007-04-12 01:33:10 -0400380 if (ar2->mode == mode)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200381 return;
382
383 if (data[1] == 0)
Peter Stokesa1421d32007-04-12 01:33:10 -0400384 ar2->mode = mode;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200385 }
386
Ville Syrjalad329e332009-01-29 23:42:16 -0800387 if (!((1 << mode) & ar2->mode_mask))
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200388 return;
389
390 index = ati_remote2_lookup(hw_code);
391 if (index < 0) {
392 dev_err(&ar2->intf[1]->dev,
393 "Unknown code byte (%02x %02x %02x %02x)\n",
394 data[3], data[2], data[1], data[0]);
395 return;
396 }
397
398 switch (data[1]) {
399 case 0: /* release */
400 break;
401 case 1: /* press */
402 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_DELAY]);
403 break;
404 case 2: /* repeat */
405
406 /* No repeat for mouse buttons. */
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400407 if (ar2->keycode[mode][index] == BTN_LEFT ||
408 ar2->keycode[mode][index] == BTN_RIGHT)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200409 return;
410
411 if (!time_after_eq(jiffies, ar2->jiffies))
412 return;
413
414 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_PERIOD]);
415 break;
416 default:
417 dev_err(&ar2->intf[1]->dev,
418 "Unknown state byte (%02x %02x %02x %02x)\n",
419 data[3], data[2], data[1], data[0]);
420 return;
421 }
422
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400423 input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200424 input_sync(idev);
425}
426
David Howells7d12e782006-10-05 14:55:46 +0100427static void ati_remote2_complete_mouse(struct urb *urb)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200428{
429 struct ati_remote2 *ar2 = urb->context;
430 int r;
431
432 switch (urb->status) {
433 case 0:
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400434 usb_mark_last_busy(ar2->udev);
David Howells7d12e782006-10-05 14:55:46 +0100435 ati_remote2_input_mouse(ar2);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200436 break;
437 case -ENOENT:
438 case -EILSEQ:
439 case -ECONNRESET:
440 case -ESHUTDOWN:
441 dev_dbg(&ar2->intf[0]->dev,
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400442 "%s(): urb status = %d\n", __func__, urb->status);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200443 return;
444 default:
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400445 usb_mark_last_busy(ar2->udev);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200446 dev_err(&ar2->intf[0]->dev,
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400447 "%s(): urb status = %d\n", __func__, urb->status);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200448 }
449
450 r = usb_submit_urb(urb, GFP_ATOMIC);
451 if (r)
452 dev_err(&ar2->intf[0]->dev,
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400453 "%s(): usb_submit_urb() = %d\n", __func__, r);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200454}
455
David Howells7d12e782006-10-05 14:55:46 +0100456static void ati_remote2_complete_key(struct urb *urb)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200457{
458 struct ati_remote2 *ar2 = urb->context;
459 int r;
460
461 switch (urb->status) {
462 case 0:
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400463 usb_mark_last_busy(ar2->udev);
David Howells7d12e782006-10-05 14:55:46 +0100464 ati_remote2_input_key(ar2);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200465 break;
466 case -ENOENT:
467 case -EILSEQ:
468 case -ECONNRESET:
469 case -ESHUTDOWN:
470 dev_dbg(&ar2->intf[1]->dev,
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400471 "%s(): urb status = %d\n", __func__, urb->status);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200472 return;
473 default:
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400474 usb_mark_last_busy(ar2->udev);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200475 dev_err(&ar2->intf[1]->dev,
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400476 "%s(): urb status = %d\n", __func__, urb->status);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200477 }
478
479 r = usb_submit_urb(urb, GFP_ATOMIC);
480 if (r)
481 dev_err(&ar2->intf[1]->dev,
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400482 "%s(): usb_submit_urb() = %d\n", __func__, r);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200483}
484
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400485static int ati_remote2_getkeycode(struct input_dev *idev,
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700486 struct input_keymap_entry *ke)
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400487{
488 struct ati_remote2 *ar2 = input_get_drvdata(idev);
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800489 unsigned int mode;
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700490 int offset;
491 unsigned int index;
492 unsigned int scancode;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400493
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700494 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
495 index = ke->index;
496 if (index >= ATI_REMOTE2_MODES *
497 ARRAY_SIZE(ati_remote2_key_table))
498 return -EINVAL;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400499
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700500 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
501 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
502 scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code;
503 } else {
504 if (input_scancode_to_scalar(ke, &scancode))
505 return -EINVAL;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400506
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700507 mode = scancode >> 8;
508 if (mode > ATI_REMOTE2_PC)
509 return -EINVAL;
510
511 offset = ati_remote2_lookup(scancode & 0xff);
512 if (offset < 0)
513 return -EINVAL;
514
515 index = mode * ARRAY_SIZE(ati_remote2_key_table) + offset;
516 }
517
518 ke->keycode = ar2->keycode[mode][offset];
519 ke->len = sizeof(scancode);
520 memcpy(&ke->scancode, &scancode, sizeof(scancode));
521 ke->index = index;
522
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400523 return 0;
524}
525
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800526static int ati_remote2_setkeycode(struct input_dev *idev,
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700527 const struct input_keymap_entry *ke,
528 unsigned int *old_keycode)
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400529{
530 struct ati_remote2 *ar2 = input_get_drvdata(idev);
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700531 unsigned int mode;
532 int offset;
533 unsigned int index;
534 unsigned int scancode;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400535
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700536 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
537 if (ke->index >= ATI_REMOTE2_MODES *
538 ARRAY_SIZE(ati_remote2_key_table))
539 return -EINVAL;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400540
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700541 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
542 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
543 } else {
544 if (input_scancode_to_scalar(ke, &scancode))
545 return -EINVAL;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400546
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700547 mode = scancode >> 8;
548 if (mode > ATI_REMOTE2_PC)
549 return -EINVAL;
550
551 offset = ati_remote2_lookup(scancode & 0xff);
552 if (offset < 0)
553 return -EINVAL;
554 }
555
556 *old_keycode = ar2->keycode[mode][offset];
557 ar2->keycode[mode][offset] = ke->keycode;
558 __set_bit(ke->keycode, idev->keybit);
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400559
560 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
561 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700562 if (ar2->keycode[mode][index] == *old_keycode)
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400563 return 0;
564 }
565 }
566
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700567 __clear_bit(*old_keycode, idev->keybit);
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400568
569 return 0;
570}
571
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200572static int ati_remote2_input_init(struct ati_remote2 *ar2)
573{
574 struct input_dev *idev;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400575 int index, mode, retval;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200576
577 idev = input_allocate_device();
578 if (!idev)
579 return -ENOMEM;
580
581 ar2->idev = idev;
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400582 input_set_drvdata(idev, ar2);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200583
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700584 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL);
585 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
586 BIT_MASK(BTN_RIGHT);
587 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400588
589 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
590 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
591 ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode;
Ville Syrjala225c9882009-05-18 16:01:25 -0700592 __set_bit(ar2->keycode[mode][index], idev->keybit);
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400593 }
594 }
595
596 /* AUX1-AUX4 and PC generate the same scancode. */
597 index = ati_remote2_lookup(0x3f);
598 ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1;
599 ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2;
600 ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3;
601 ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4;
602 ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC;
Ville Syrjala225c9882009-05-18 16:01:25 -0700603 __set_bit(KEY_PROG1, idev->keybit);
604 __set_bit(KEY_PROG2, idev->keybit);
605 __set_bit(KEY_PROG3, idev->keybit);
606 __set_bit(KEY_PROG4, idev->keybit);
607 __set_bit(KEY_PC, idev->keybit);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200608
609 idev->rep[REP_DELAY] = 250;
610 idev->rep[REP_PERIOD] = 33;
611
612 idev->open = ati_remote2_open;
613 idev->close = ati_remote2_close;
614
Dmitry Torokhov1f7930c2010-09-15 19:36:34 -0700615 idev->getkeycode_new = ati_remote2_getkeycode;
616 idev->setkeycode_new = ati_remote2_setkeycode;
Ville Syrjala1971b9d2008-07-03 10:45:37 -0400617
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200618 idev->name = ar2->name;
619 idev->phys = ar2->phys;
620
621 usb_to_input_id(ar2->udev, &idev->id);
Dmitry Torokhovc0f82d52007-04-12 01:35:03 -0400622 idev->dev.parent = &ar2->udev->dev;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200623
Dmitry Torokhov50141862007-04-12 01:33:39 -0400624 retval = input_register_device(idev);
625 if (retval)
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200626 input_free_device(idev);
627
Dmitry Torokhov50141862007-04-12 01:33:39 -0400628 return retval;
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200629}
630
631static int ati_remote2_urb_init(struct ati_remote2 *ar2)
632{
633 struct usb_device *udev = ar2->udev;
634 int i, pipe, maxp;
635
636 for (i = 0; i < 2; i++) {
Daniel Mack997ea582010-04-12 13:17:25 +0200637 ar2->buf[i] = usb_alloc_coherent(udev, 4, GFP_KERNEL, &ar2->buf_dma[i]);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200638 if (!ar2->buf[i])
639 return -ENOMEM;
640
641 ar2->urb[i] = usb_alloc_urb(0, GFP_KERNEL);
642 if (!ar2->urb[i])
643 return -ENOMEM;
644
645 pipe = usb_rcvintpipe(udev, ar2->ep[i]->bEndpointAddress);
646 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
647 maxp = maxp > 4 ? 4 : maxp;
648
649 usb_fill_int_urb(ar2->urb[i], udev, pipe, ar2->buf[i], maxp,
650 i ? ati_remote2_complete_key : ati_remote2_complete_mouse,
651 ar2, ar2->ep[i]->bInterval);
652 ar2->urb[i]->transfer_dma = ar2->buf_dma[i];
653 ar2->urb[i]->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
654 }
655
656 return 0;
657}
658
659static void ati_remote2_urb_cleanup(struct ati_remote2 *ar2)
660{
661 int i;
662
663 for (i = 0; i < 2; i++) {
Mariusz Kozlowski23815262006-11-08 15:35:50 +0100664 usb_free_urb(ar2->urb[i]);
Daniel Mack997ea582010-04-12 13:17:25 +0200665 usb_free_coherent(ar2->udev, 4, ar2->buf[i], ar2->buf_dma[i]);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200666 }
667}
668
Ville Syrjalad329e332009-01-29 23:42:16 -0800669static int ati_remote2_setup(struct ati_remote2 *ar2, unsigned int ch_mask)
Peter Stokesa1421d32007-04-12 01:33:10 -0400670{
671 int r, i, channel;
672
673 /*
674 * Configure receiver to only accept input from remote "channel"
675 * channel == 0 -> Accept input from any remote channel
676 * channel == 1 -> Only accept input from remote channel 1
677 * channel == 2 -> Only accept input from remote channel 2
678 * ...
679 * channel == 16 -> Only accept input from remote channel 16
680 */
681
682 channel = 0;
683 for (i = 0; i < 16; i++) {
Ville Syrjalad329e332009-01-29 23:42:16 -0800684 if ((1 << i) & ch_mask) {
685 if (!(~(1 << i) & ch_mask))
Peter Stokesa1421d32007-04-12 01:33:10 -0400686 channel = i + 1;
687 break;
688 }
689 }
690
691 r = usb_control_msg(ar2->udev, usb_sndctrlpipe(ar2->udev, 0),
692 0x20,
693 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
694 channel, 0x0, NULL, 0, USB_CTRL_SET_TIMEOUT);
695 if (r) {
696 dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d\n",
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400697 __func__, r);
Peter Stokesa1421d32007-04-12 01:33:10 -0400698 return r;
699 }
700
701 return 0;
702}
703
Ville Syrjalad329e332009-01-29 23:42:16 -0800704static ssize_t ati_remote2_show_channel_mask(struct device *dev,
705 struct device_attribute *attr,
706 char *buf)
707{
708 struct usb_device *udev = to_usb_device(dev);
709 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
710 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
711
712 return sprintf(buf, "0x%04x\n", ar2->channel_mask);
713}
714
715static ssize_t ati_remote2_store_channel_mask(struct device *dev,
716 struct device_attribute *attr,
717 const char *buf, size_t count)
718{
719 struct usb_device *udev = to_usb_device(dev);
720 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
721 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
722 unsigned long mask;
723 int r;
724
725 if (strict_strtoul(buf, 0, &mask))
726 return -EINVAL;
727
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
740 if (mask != ar2->channel_mask && !ati_remote2_setup(ar2, mask))
741 ar2->channel_mask = mask;
742
743 mutex_unlock(&ati_remote2_mutex);
744
745 usb_autopm_put_interface(ar2->intf[0]);
746
747 return count;
748}
749
750static ssize_t ati_remote2_show_mode_mask(struct device *dev,
751 struct device_attribute *attr,
752 char *buf)
753{
754 struct usb_device *udev = to_usb_device(dev);
755 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
756 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
757
758 return sprintf(buf, "0x%02x\n", ar2->mode_mask);
759}
760
761static ssize_t ati_remote2_store_mode_mask(struct device *dev,
762 struct device_attribute *attr,
763 const char *buf, size_t count)
764{
765 struct usb_device *udev = to_usb_device(dev);
766 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
767 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
768 unsigned long mask;
769
770 if (strict_strtoul(buf, 0, &mask))
771 return -EINVAL;
772
773 if (mask & ~ATI_REMOTE2_MAX_MODE_MASK)
774 return -EINVAL;
775
776 ar2->mode_mask = mask;
777
778 return count;
779}
780
781static DEVICE_ATTR(channel_mask, 0644, ati_remote2_show_channel_mask,
782 ati_remote2_store_channel_mask);
783
784static DEVICE_ATTR(mode_mask, 0644, ati_remote2_show_mode_mask,
785 ati_remote2_store_mode_mask);
786
787static struct attribute *ati_remote2_attrs[] = {
788 &dev_attr_channel_mask.attr,
789 &dev_attr_mode_mask.attr,
790 NULL,
791};
792
793static struct attribute_group ati_remote2_attr_group = {
794 .attrs = ati_remote2_attrs,
795};
796
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200797static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id)
798{
799 struct usb_device *udev = interface_to_usbdev(interface);
800 struct usb_host_interface *alt = interface->cur_altsetting;
801 struct ati_remote2 *ar2;
802 int r;
803
804 if (alt->desc.bInterfaceNumber)
805 return -ENODEV;
806
807 ar2 = kzalloc(sizeof (struct ati_remote2), GFP_KERNEL);
808 if (!ar2)
809 return -ENOMEM;
810
811 ar2->udev = udev;
812
813 ar2->intf[0] = interface;
814 ar2->ep[0] = &alt->endpoint[0].desc;
815
816 ar2->intf[1] = usb_ifnum_to_if(udev, 1);
817 r = usb_driver_claim_interface(&ati_remote2_driver, ar2->intf[1], ar2);
818 if (r)
819 goto fail1;
820 alt = ar2->intf[1]->cur_altsetting;
821 ar2->ep[1] = &alt->endpoint[0].desc;
822
823 r = ati_remote2_urb_init(ar2);
824 if (r)
825 goto fail2;
826
Ville Syrjala8a49cfa2009-01-29 23:42:16 -0800827 ar2->channel_mask = channel_mask;
828 ar2->mode_mask = mode_mask;
Ville Syrjalad329e332009-01-29 23:42:16 -0800829
830 r = ati_remote2_setup(ar2, ar2->channel_mask);
Peter Stokesa1421d32007-04-12 01:33:10 -0400831 if (r)
832 goto fail2;
833
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200834 usb_make_path(udev, ar2->phys, sizeof(ar2->phys));
835 strlcat(ar2->phys, "/input0", sizeof(ar2->phys));
836
837 strlcat(ar2->name, "ATI Remote Wonder II", sizeof(ar2->name));
838
Ville Syrjalad329e332009-01-29 23:42:16 -0800839 r = sysfs_create_group(&udev->dev.kobj, &ati_remote2_attr_group);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200840 if (r)
841 goto fail2;
842
Ville Syrjalad329e332009-01-29 23:42:16 -0800843 r = ati_remote2_input_init(ar2);
844 if (r)
845 goto fail3;
846
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200847 usb_set_intfdata(interface, ar2);
848
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400849 interface->needs_remote_wakeup = 1;
850
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200851 return 0;
852
Ville Syrjalad329e332009-01-29 23:42:16 -0800853 fail3:
854 sysfs_remove_group(&udev->dev.kobj, &ati_remote2_attr_group);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200855 fail2:
856 ati_remote2_urb_cleanup(ar2);
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200857 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
858 fail1:
859 kfree(ar2);
860
861 return r;
862}
863
864static void ati_remote2_disconnect(struct usb_interface *interface)
865{
866 struct ati_remote2 *ar2;
867 struct usb_host_interface *alt = interface->cur_altsetting;
868
869 if (alt->desc.bInterfaceNumber)
870 return;
871
872 ar2 = usb_get_intfdata(interface);
873 usb_set_intfdata(interface, NULL);
874
875 input_unregister_device(ar2->idev);
876
Ville Syrjalad329e332009-01-29 23:42:16 -0800877 sysfs_remove_group(&ar2->udev->dev.kobj, &ati_remote2_attr_group);
878
Ville Syrjälä735b0cb2005-12-10 20:30:54 +0200879 ati_remote2_urb_cleanup(ar2);
880
881 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
882
883 kfree(ar2);
884}
885
Ville Syrjalad6505ab2008-07-03 10:45:37 -0400886static int ati_remote2_suspend(struct usb_interface *interface,
887 pm_message_t message)
888{
889 struct ati_remote2 *ar2;
890 struct usb_host_interface *alt = interface->cur_altsetting;
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 mutex_lock(&ati_remote2_mutex);
900
901 if (ar2->flags & ATI_REMOTE2_OPENED)
902 ati_remote2_kill_urbs(ar2);
903
904 ar2->flags |= ATI_REMOTE2_SUSPENDED;
905
906 mutex_unlock(&ati_remote2_mutex);
907
908 return 0;
909}
910
911static int ati_remote2_resume(struct usb_interface *interface)
912{
913 struct ati_remote2 *ar2;
914 struct usb_host_interface *alt = interface->cur_altsetting;
915 int r = 0;
916
917 if (alt->desc.bInterfaceNumber)
918 return 0;
919
920 ar2 = usb_get_intfdata(interface);
921
922 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
923
924 mutex_lock(&ati_remote2_mutex);
925
926 if (ar2->flags & ATI_REMOTE2_OPENED)
927 r = ati_remote2_submit_urbs(ar2);
928
929 if (!r)
930 ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
931
932 mutex_unlock(&ati_remote2_mutex);
933
934 return r;
935}
936
Ville Syrjala169bc1e2009-01-29 23:42:16 -0800937static int ati_remote2_reset_resume(struct usb_interface *interface)
938{
939 struct ati_remote2 *ar2;
940 struct usb_host_interface *alt = interface->cur_altsetting;
941 int r = 0;
942
943 if (alt->desc.bInterfaceNumber)
944 return 0;
945
946 ar2 = usb_get_intfdata(interface);
947
948 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
949
950 mutex_lock(&ati_remote2_mutex);
951
Ville Syrjalad329e332009-01-29 23:42:16 -0800952 r = ati_remote2_setup(ar2, ar2->channel_mask);
Ville Syrjala169bc1e2009-01-29 23:42:16 -0800953 if (r)
954 goto out;
955
956 if (ar2->flags & ATI_REMOTE2_OPENED)
957 r = ati_remote2_submit_urbs(ar2);
958
959 if (!r)
960 ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
961
962 out:
963 mutex_unlock(&ati_remote2_mutex);
964
965 return r;
966}
967
968static int ati_remote2_pre_reset(struct usb_interface *interface)
969{
970 struct ati_remote2 *ar2;
971 struct usb_host_interface *alt = interface->cur_altsetting;
972
973 if (alt->desc.bInterfaceNumber)
974 return 0;
975
976 ar2 = usb_get_intfdata(interface);
977
978 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
979
980 mutex_lock(&ati_remote2_mutex);
981
982 if (ar2->flags == ATI_REMOTE2_OPENED)
983 ati_remote2_kill_urbs(ar2);
984
985 return 0;
986}
987
988static int ati_remote2_post_reset(struct usb_interface *interface)
989{
990 struct ati_remote2 *ar2;
991 struct usb_host_interface *alt = interface->cur_altsetting;
992 int r = 0;
993
994 if (alt->desc.bInterfaceNumber)
995 return 0;
996
997 ar2 = usb_get_intfdata(interface);
998
999 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
1000
1001 if (ar2->flags == ATI_REMOTE2_OPENED)
1002 r = ati_remote2_submit_urbs(ar2);
1003
1004 mutex_unlock(&ati_remote2_mutex);
1005
1006 return r;
1007}
1008
Ville Syrjälä735b0cb2005-12-10 20:30:54 +02001009static int __init ati_remote2_init(void)
1010{
1011 int r;
1012
1013 r = usb_register(&ati_remote2_driver);
1014 if (r)
1015 printk(KERN_ERR "ati_remote2: usb_register() = %d\n", r);
1016 else
1017 printk(KERN_INFO "ati_remote2: " DRIVER_DESC " " DRIVER_VERSION "\n");
1018
1019 return r;
1020}
1021
1022static void __exit ati_remote2_exit(void)
1023{
1024 usb_deregister(&ati_remote2_driver);
1025}
1026
1027module_init(ati_remote2_init);
1028module_exit(ati_remote2_exit);