aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/misc/ati_remote2.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/misc/ati_remote2.c')
-rw-r--r--drivers/input/misc/ati_remote2.c263
1 files changed, 228 insertions, 35 deletions
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index a7fabafbd94c..3c9988dc0e9f 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * ati_remote2 - ATI/Philips USB RF remote driver 2 * ati_remote2 - ATI/Philips USB RF remote driver
3 * 3 *
4 * Copyright (C) 2005 Ville Syrjala <syrjala@sci.fi> 4 * Copyright (C) 2005-2008 Ville Syrjala <syrjala@sci.fi>
5 * Copyright (C) 2007 Peter Stokes <linux@dadeos.freeserve.co.uk> 5 * Copyright (C) 2007-2008 Peter Stokes <linux@dadeos.co.uk>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 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 8 * it under the terms of the GNU General Public License version 2
@@ -12,7 +12,7 @@
12#include <linux/usb/input.h> 12#include <linux/usb/input.h>
13 13
14#define DRIVER_DESC "ATI/Philips USB RF remote driver" 14#define DRIVER_DESC "ATI/Philips USB RF remote driver"
15#define DRIVER_VERSION "0.2" 15#define DRIVER_VERSION "0.3"
16 16
17MODULE_DESCRIPTION(DRIVER_DESC); 17MODULE_DESCRIPTION(DRIVER_DESC);
18MODULE_VERSION(DRIVER_VERSION); 18MODULE_VERSION(DRIVER_VERSION);
@@ -27,7 +27,7 @@ MODULE_LICENSE("GPL");
27 * A remote's "channel" may be altered by pressing and holding the "PC" button for 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 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 29 * currently configured "channel", using the numeric keypad enter a number between 1 and
30 * 16 and then the "PC" button again, the button will slowly flash the count of the 30 * 16 and then press the "PC" button again, the button will slowly flash the count of the
31 * newly configured "channel". 31 * newly configured "channel".
32 */ 32 */
33 33
@@ -45,9 +45,25 @@ static struct usb_device_id ati_remote2_id_table[] = {
45}; 45};
46MODULE_DEVICE_TABLE(usb, ati_remote2_id_table); 46MODULE_DEVICE_TABLE(usb, ati_remote2_id_table);
47 47
48static struct { 48static DEFINE_MUTEX(ati_remote2_mutex);
49 int hw_code; 49
50 int key_code; 50enum {
51 ATI_REMOTE2_OPENED = 0x1,
52 ATI_REMOTE2_SUSPENDED = 0x2,
53};
54
55enum {
56 ATI_REMOTE2_AUX1,
57 ATI_REMOTE2_AUX2,
58 ATI_REMOTE2_AUX3,
59 ATI_REMOTE2_AUX4,
60 ATI_REMOTE2_PC,
61 ATI_REMOTE2_MODES,
62};
63
64static const struct {
65 u8 hw_code;
66 u16 keycode;
51} ati_remote2_key_table[] = { 67} ati_remote2_key_table[] = {
52 { 0x00, KEY_0 }, 68 { 0x00, KEY_0 },
53 { 0x01, KEY_1 }, 69 { 0x01, KEY_1 },
@@ -73,6 +89,7 @@ static struct {
73 { 0x37, KEY_RECORD }, 89 { 0x37, KEY_RECORD },
74 { 0x38, KEY_DVD }, 90 { 0x38, KEY_DVD },
75 { 0x39, KEY_TV }, 91 { 0x39, KEY_TV },
92 { 0x3f, KEY_PROG1 }, /* AUX1-AUX4 and PC */
76 { 0x54, KEY_MENU }, 93 { 0x54, KEY_MENU },
77 { 0x58, KEY_UP }, 94 { 0x58, KEY_UP },
78 { 0x59, KEY_DOWN }, 95 { 0x59, KEY_DOWN },
@@ -91,15 +108,9 @@ static struct {
91 { 0xa9, BTN_LEFT }, 108 { 0xa9, BTN_LEFT },
92 { 0xaa, BTN_RIGHT }, 109 { 0xaa, BTN_RIGHT },
93 { 0xbe, KEY_QUESTION }, 110 { 0xbe, KEY_QUESTION },
94 { 0xd5, KEY_FRONT },
95 { 0xd0, KEY_EDIT }, 111 { 0xd0, KEY_EDIT },
112 { 0xd5, KEY_FRONT },
96 { 0xf9, KEY_INFO }, 113 { 0xf9, KEY_INFO },
97 { (0x00 << 8) | 0x3f, KEY_PROG1 },
98 { (0x01 << 8) | 0x3f, KEY_PROG2 },
99 { (0x02 << 8) | 0x3f, KEY_PROG3 },
100 { (0x03 << 8) | 0x3f, KEY_PROG4 },
101 { (0x04 << 8) | 0x3f, KEY_PC },
102 { 0, KEY_RESERVED }
103}; 114};
104 115
105struct ati_remote2 { 116struct ati_remote2 {
@@ -117,46 +128,106 @@ struct ati_remote2 {
117 128
118 char name[64]; 129 char name[64];
119 char phys[64]; 130 char phys[64];
131
132 /* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
133 u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)];
134
135 unsigned int flags;
120}; 136};
121 137
122static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id); 138static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id);
123static void ati_remote2_disconnect(struct usb_interface *interface); 139static void ati_remote2_disconnect(struct usb_interface *interface);
140static int ati_remote2_suspend(struct usb_interface *interface, pm_message_t message);
141static int ati_remote2_resume(struct usb_interface *interface);
124 142
125static struct usb_driver ati_remote2_driver = { 143static struct usb_driver ati_remote2_driver = {
126 .name = "ati_remote2", 144 .name = "ati_remote2",
127 .probe = ati_remote2_probe, 145 .probe = ati_remote2_probe,
128 .disconnect = ati_remote2_disconnect, 146 .disconnect = ati_remote2_disconnect,
129 .id_table = ati_remote2_id_table, 147 .id_table = ati_remote2_id_table,
148 .suspend = ati_remote2_suspend,
149 .resume = ati_remote2_resume,
150 .supports_autosuspend = 1,
130}; 151};
131 152
132static int ati_remote2_open(struct input_dev *idev) 153static int ati_remote2_submit_urbs(struct ati_remote2 *ar2)
133{ 154{
134 struct ati_remote2 *ar2 = input_get_drvdata(idev);
135 int r; 155 int r;
136 156
137 r = usb_submit_urb(ar2->urb[0], GFP_KERNEL); 157 r = usb_submit_urb(ar2->urb[0], GFP_KERNEL);
138 if (r) { 158 if (r) {
139 dev_err(&ar2->intf[0]->dev, 159 dev_err(&ar2->intf[0]->dev,
140 "%s: usb_submit_urb() = %d\n", __func__, r); 160 "%s(): usb_submit_urb() = %d\n", __func__, r);
141 return r; 161 return r;
142 } 162 }
143 r = usb_submit_urb(ar2->urb[1], GFP_KERNEL); 163 r = usb_submit_urb(ar2->urb[1], GFP_KERNEL);
144 if (r) { 164 if (r) {
145 usb_kill_urb(ar2->urb[0]); 165 usb_kill_urb(ar2->urb[0]);
146 dev_err(&ar2->intf[1]->dev, 166 dev_err(&ar2->intf[1]->dev,
147 "%s: usb_submit_urb() = %d\n", __func__, r); 167 "%s(): usb_submit_urb() = %d\n", __func__, r);
148 return r; 168 return r;
149 } 169 }
150 170
151 return 0; 171 return 0;
152} 172}
153 173
174static void ati_remote2_kill_urbs(struct ati_remote2 *ar2)
175{
176 usb_kill_urb(ar2->urb[1]);
177 usb_kill_urb(ar2->urb[0]);
178}
179
180static int ati_remote2_open(struct input_dev *idev)
181{
182 struct ati_remote2 *ar2 = input_get_drvdata(idev);
183 int r;
184
185 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
186
187 r = usb_autopm_get_interface(ar2->intf[0]);
188 if (r) {
189 dev_err(&ar2->intf[0]->dev,
190 "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
191 goto fail1;
192 }
193
194 mutex_lock(&ati_remote2_mutex);
195
196 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) {
197 r = ati_remote2_submit_urbs(ar2);
198 if (r)
199 goto fail2;
200 }
201
202 ar2->flags |= ATI_REMOTE2_OPENED;
203
204 mutex_unlock(&ati_remote2_mutex);
205
206 usb_autopm_put_interface(ar2->intf[0]);
207
208 return 0;
209
210 fail2:
211 mutex_unlock(&ati_remote2_mutex);
212 usb_autopm_put_interface(ar2->intf[0]);
213 fail1:
214 return r;
215}
216
154static void ati_remote2_close(struct input_dev *idev) 217static void ati_remote2_close(struct input_dev *idev)
155{ 218{
156 struct ati_remote2 *ar2 = input_get_drvdata(idev); 219 struct ati_remote2 *ar2 = input_get_drvdata(idev);
157 220
158 usb_kill_urb(ar2->urb[0]); 221 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
159 usb_kill_urb(ar2->urb[1]); 222
223 mutex_lock(&ati_remote2_mutex);
224
225 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED))
226 ati_remote2_kill_urbs(ar2);
227
228 ar2->flags &= ~ATI_REMOTE2_OPENED;
229
230 mutex_unlock(&ati_remote2_mutex);
160} 231}
161 232
162static void ati_remote2_input_mouse(struct ati_remote2 *ar2) 233static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
@@ -172,7 +243,7 @@ static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
172 243
173 mode = data[0] & 0x0F; 244 mode = data[0] & 0x0F;
174 245
175 if (mode > 4) { 246 if (mode > ATI_REMOTE2_PC) {
176 dev_err(&ar2->intf[0]->dev, 247 dev_err(&ar2->intf[0]->dev,
177 "Unknown mode byte (%02x %02x %02x %02x)\n", 248 "Unknown mode byte (%02x %02x %02x %02x)\n",
178 data[3], data[2], data[1], data[0]); 249 data[3], data[2], data[1], data[0]);
@@ -191,7 +262,7 @@ static int ati_remote2_lookup(unsigned int hw_code)
191{ 262{
192 int i; 263 int i;
193 264
194 for (i = 0; ati_remote2_key_table[i].key_code != KEY_RESERVED; i++) 265 for (i = 0; i < ARRAY_SIZE(ati_remote2_key_table); i++)
195 if (ati_remote2_key_table[i].hw_code == hw_code) 266 if (ati_remote2_key_table[i].hw_code == hw_code)
196 return i; 267 return i;
197 268
@@ -211,7 +282,7 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
211 282
212 mode = data[0] & 0x0F; 283 mode = data[0] & 0x0F;
213 284
214 if (mode > 4) { 285 if (mode > ATI_REMOTE2_PC) {
215 dev_err(&ar2->intf[1]->dev, 286 dev_err(&ar2->intf[1]->dev,
216 "Unknown mode byte (%02x %02x %02x %02x)\n", 287 "Unknown mode byte (%02x %02x %02x %02x)\n",
217 data[3], data[2], data[1], data[0]); 288 data[3], data[2], data[1], data[0]);
@@ -219,10 +290,6 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
219 } 290 }
220 291
221 hw_code = data[2]; 292 hw_code = data[2];
222 /*
223 * Mode keys (AUX1-AUX4, PC) all generate the same code byte.
224 * Use the mode byte to figure out which one was pressed.
225 */
226 if (hw_code == 0x3f) { 293 if (hw_code == 0x3f) {
227 /* 294 /*
228 * For some incomprehensible reason the mouse pad generates 295 * For some incomprehensible reason the mouse pad generates
@@ -236,8 +303,6 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
236 303
237 if (data[1] == 0) 304 if (data[1] == 0)
238 ar2->mode = mode; 305 ar2->mode = mode;
239
240 hw_code |= mode << 8;
241 } 306 }
242 307
243 if (!((1 << mode) & mode_mask)) 308 if (!((1 << mode) & mode_mask))
@@ -260,8 +325,8 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
260 case 2: /* repeat */ 325 case 2: /* repeat */
261 326
262 /* No repeat for mouse buttons. */ 327 /* No repeat for mouse buttons. */
263 if (ati_remote2_key_table[index].key_code == BTN_LEFT || 328 if (ar2->keycode[mode][index] == BTN_LEFT ||
264 ati_remote2_key_table[index].key_code == BTN_RIGHT) 329 ar2->keycode[mode][index] == BTN_RIGHT)
265 return; 330 return;
266 331
267 if (!time_after_eq(jiffies, ar2->jiffies)) 332 if (!time_after_eq(jiffies, ar2->jiffies))
@@ -276,7 +341,7 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
276 return; 341 return;
277 } 342 }
278 343
279 input_event(idev, EV_KEY, ati_remote2_key_table[index].key_code, data[1]); 344 input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]);
280 input_sync(idev); 345 input_sync(idev);
281} 346}
282 347
@@ -287,6 +352,7 @@ static void ati_remote2_complete_mouse(struct urb *urb)
287 352
288 switch (urb->status) { 353 switch (urb->status) {
289 case 0: 354 case 0:
355 usb_mark_last_busy(ar2->udev);
290 ati_remote2_input_mouse(ar2); 356 ati_remote2_input_mouse(ar2);
291 break; 357 break;
292 case -ENOENT: 358 case -ENOENT:
@@ -297,6 +363,7 @@ static void ati_remote2_complete_mouse(struct urb *urb)
297 "%s(): urb status = %d\n", __func__, urb->status); 363 "%s(): urb status = %d\n", __func__, urb->status);
298 return; 364 return;
299 default: 365 default:
366 usb_mark_last_busy(ar2->udev);
300 dev_err(&ar2->intf[0]->dev, 367 dev_err(&ar2->intf[0]->dev,
301 "%s(): urb status = %d\n", __func__, urb->status); 368 "%s(): urb status = %d\n", __func__, urb->status);
302 } 369 }
@@ -314,6 +381,7 @@ static void ati_remote2_complete_key(struct urb *urb)
314 381
315 switch (urb->status) { 382 switch (urb->status) {
316 case 0: 383 case 0:
384 usb_mark_last_busy(ar2->udev);
317 ati_remote2_input_key(ar2); 385 ati_remote2_input_key(ar2);
318 break; 386 break;
319 case -ENOENT: 387 case -ENOENT:
@@ -324,6 +392,7 @@ static void ati_remote2_complete_key(struct urb *urb)
324 "%s(): urb status = %d\n", __func__, urb->status); 392 "%s(): urb status = %d\n", __func__, urb->status);
325 return; 393 return;
326 default: 394 default:
395 usb_mark_last_busy(ar2->udev);
327 dev_err(&ar2->intf[1]->dev, 396 dev_err(&ar2->intf[1]->dev,
328 "%s(): urb status = %d\n", __func__, urb->status); 397 "%s(): urb status = %d\n", __func__, urb->status);
329 } 398 }
@@ -334,10 +403,60 @@ static void ati_remote2_complete_key(struct urb *urb)
334 "%s(): usb_submit_urb() = %d\n", __func__, r); 403 "%s(): usb_submit_urb() = %d\n", __func__, r);
335} 404}
336 405
406static int ati_remote2_getkeycode(struct input_dev *idev,
407 int scancode, int *keycode)
408{
409 struct ati_remote2 *ar2 = input_get_drvdata(idev);
410 int index, mode;
411
412 mode = scancode >> 8;
413 if (mode > ATI_REMOTE2_PC || !((1 << mode) & mode_mask))
414 return -EINVAL;
415
416 index = ati_remote2_lookup(scancode & 0xFF);
417 if (index < 0)
418 return -EINVAL;
419
420 *keycode = ar2->keycode[mode][index];
421 return 0;
422}
423
424static int ati_remote2_setkeycode(struct input_dev *idev, int scancode, int keycode)
425{
426 struct ati_remote2 *ar2 = input_get_drvdata(idev);
427 int index, mode, old_keycode;
428
429 mode = scancode >> 8;
430 if (mode > ATI_REMOTE2_PC || !((1 << mode) & mode_mask))
431 return -EINVAL;
432
433 index = ati_remote2_lookup(scancode & 0xFF);
434 if (index < 0)
435 return -EINVAL;
436
437 if (keycode < KEY_RESERVED || keycode > KEY_MAX)
438 return -EINVAL;
439
440 old_keycode = ar2->keycode[mode][index];
441 ar2->keycode[mode][index] = keycode;
442 set_bit(keycode, idev->keybit);
443
444 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
445 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
446 if (ar2->keycode[mode][index] == old_keycode)
447 return 0;
448 }
449 }
450
451 clear_bit(old_keycode, idev->keybit);
452
453 return 0;
454}
455
337static int ati_remote2_input_init(struct ati_remote2 *ar2) 456static int ati_remote2_input_init(struct ati_remote2 *ar2)
338{ 457{
339 struct input_dev *idev; 458 struct input_dev *idev;
340 int i, retval; 459 int index, mode, retval;
341 460
342 idev = input_allocate_device(); 461 idev = input_allocate_device();
343 if (!idev) 462 if (!idev)
@@ -350,8 +469,26 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2)
350 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | 469 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
351 BIT_MASK(BTN_RIGHT); 470 BIT_MASK(BTN_RIGHT);
352 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); 471 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
353 for (i = 0; ati_remote2_key_table[i].key_code != KEY_RESERVED; i++) 472
354 set_bit(ati_remote2_key_table[i].key_code, idev->keybit); 473 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
474 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
475 ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode;
476 set_bit(ar2->keycode[mode][index], idev->keybit);
477 }
478 }
479
480 /* AUX1-AUX4 and PC generate the same scancode. */
481 index = ati_remote2_lookup(0x3f);
482 ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1;
483 ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2;
484 ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3;
485 ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4;
486 ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC;
487 set_bit(KEY_PROG1, idev->keybit);
488 set_bit(KEY_PROG2, idev->keybit);
489 set_bit(KEY_PROG3, idev->keybit);
490 set_bit(KEY_PROG4, idev->keybit);
491 set_bit(KEY_PC, idev->keybit);
355 492
356 idev->rep[REP_DELAY] = 250; 493 idev->rep[REP_DELAY] = 250;
357 idev->rep[REP_PERIOD] = 33; 494 idev->rep[REP_PERIOD] = 33;
@@ -359,6 +496,9 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2)
359 idev->open = ati_remote2_open; 496 idev->open = ati_remote2_open;
360 idev->close = ati_remote2_close; 497 idev->close = ati_remote2_close;
361 498
499 idev->getkeycode = ati_remote2_getkeycode;
500 idev->setkeycode = ati_remote2_setkeycode;
501
362 idev->name = ar2->name; 502 idev->name = ar2->name;
363 idev->phys = ar2->phys; 503 idev->phys = ar2->phys;
364 504
@@ -490,6 +630,8 @@ static int ati_remote2_probe(struct usb_interface *interface, const struct usb_d
490 630
491 usb_set_intfdata(interface, ar2); 631 usb_set_intfdata(interface, ar2);
492 632
633 interface->needs_remote_wakeup = 1;
634
493 return 0; 635 return 0;
494 636
495 fail2: 637 fail2:
@@ -522,6 +664,57 @@ static void ati_remote2_disconnect(struct usb_interface *interface)
522 kfree(ar2); 664 kfree(ar2);
523} 665}
524 666
667static int ati_remote2_suspend(struct usb_interface *interface,
668 pm_message_t message)
669{
670 struct ati_remote2 *ar2;
671 struct usb_host_interface *alt = interface->cur_altsetting;
672
673 if (alt->desc.bInterfaceNumber)
674 return 0;
675
676 ar2 = usb_get_intfdata(interface);
677
678 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
679
680 mutex_lock(&ati_remote2_mutex);
681
682 if (ar2->flags & ATI_REMOTE2_OPENED)
683 ati_remote2_kill_urbs(ar2);
684
685 ar2->flags |= ATI_REMOTE2_SUSPENDED;
686
687 mutex_unlock(&ati_remote2_mutex);
688
689 return 0;
690}
691
692static int ati_remote2_resume(struct usb_interface *interface)
693{
694 struct ati_remote2 *ar2;
695 struct usb_host_interface *alt = interface->cur_altsetting;
696 int r = 0;
697
698 if (alt->desc.bInterfaceNumber)
699 return 0;
700
701 ar2 = usb_get_intfdata(interface);
702
703 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
704
705 mutex_lock(&ati_remote2_mutex);
706
707 if (ar2->flags & ATI_REMOTE2_OPENED)
708 r = ati_remote2_submit_urbs(ar2);
709
710 if (!r)
711 ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
712
713 mutex_unlock(&ati_remote2_mutex);
714
715 return r;
716}
717
525static int __init ati_remote2_init(void) 718static int __init ati_remote2_init(void)
526{ 719{
527 int r; 720 int r;