aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorVille Syrjala <syrjala@sci.fi>2008-07-03 10:45:37 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2008-07-30 00:41:38 -0400
commit1971b9d56fce9d8903e623b953c5e2fffe3a878e (patch)
tree01879778c0cb857e2a84092f951695cec885199a /drivers/input
parent8c4b3c29329eb7ffded3023e6d65bc415cb4e215 (diff)
Input: ati_remote2 - add loadable keymap support
Support for loadable keymaps. The driver now supports individual keymaps for each of the five modes (AUX1-AUX4 and PC) of the remote. To achieve this the keymap scancode is interpreted as a combination of the mode and actual button scancode. The original keycode patches were done by Peter Stokes <linux@dadeos.co.uk> but I modified it quite a lot. Signed-off-by: Ville Syrjala <syrjala@sci.fi> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/misc/ati_remote2.c130
1 files changed, 101 insertions, 29 deletions
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index a7fabafbd94c..f4918b9bb949 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,18 @@ 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 { 48enum {
49 int hw_code; 49 ATI_REMOTE2_AUX1,
50 int key_code; 50 ATI_REMOTE2_AUX2,
51 ATI_REMOTE2_AUX3,
52 ATI_REMOTE2_AUX4,
53 ATI_REMOTE2_PC,
54 ATI_REMOTE2_MODES,
55};
56
57static const struct {
58 u8 hw_code;
59 u16 keycode;
51} ati_remote2_key_table[] = { 60} ati_remote2_key_table[] = {
52 { 0x00, KEY_0 }, 61 { 0x00, KEY_0 },
53 { 0x01, KEY_1 }, 62 { 0x01, KEY_1 },
@@ -73,6 +82,7 @@ static struct {
73 { 0x37, KEY_RECORD }, 82 { 0x37, KEY_RECORD },
74 { 0x38, KEY_DVD }, 83 { 0x38, KEY_DVD },
75 { 0x39, KEY_TV }, 84 { 0x39, KEY_TV },
85 { 0x3f, KEY_PROG1 }, /* AUX1-AUX4 and PC */
76 { 0x54, KEY_MENU }, 86 { 0x54, KEY_MENU },
77 { 0x58, KEY_UP }, 87 { 0x58, KEY_UP },
78 { 0x59, KEY_DOWN }, 88 { 0x59, KEY_DOWN },
@@ -91,15 +101,9 @@ static struct {
91 { 0xa9, BTN_LEFT }, 101 { 0xa9, BTN_LEFT },
92 { 0xaa, BTN_RIGHT }, 102 { 0xaa, BTN_RIGHT },
93 { 0xbe, KEY_QUESTION }, 103 { 0xbe, KEY_QUESTION },
94 { 0xd5, KEY_FRONT },
95 { 0xd0, KEY_EDIT }, 104 { 0xd0, KEY_EDIT },
105 { 0xd5, KEY_FRONT },
96 { 0xf9, KEY_INFO }, 106 { 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}; 107};
104 108
105struct ati_remote2 { 109struct ati_remote2 {
@@ -117,6 +121,9 @@ struct ati_remote2 {
117 121
118 char name[64]; 122 char name[64];
119 char phys[64]; 123 char phys[64];
124
125 /* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
126 u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)];
120}; 127};
121 128
122static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id); 129static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id);
@@ -172,7 +179,7 @@ static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
172 179
173 mode = data[0] & 0x0F; 180 mode = data[0] & 0x0F;
174 181
175 if (mode > 4) { 182 if (mode > ATI_REMOTE2_PC) {
176 dev_err(&ar2->intf[0]->dev, 183 dev_err(&ar2->intf[0]->dev,
177 "Unknown mode byte (%02x %02x %02x %02x)\n", 184 "Unknown mode byte (%02x %02x %02x %02x)\n",
178 data[3], data[2], data[1], data[0]); 185 data[3], data[2], data[1], data[0]);
@@ -191,7 +198,7 @@ static int ati_remote2_lookup(unsigned int hw_code)
191{ 198{
192 int i; 199 int i;
193 200
194 for (i = 0; ati_remote2_key_table[i].key_code != KEY_RESERVED; i++) 201 for (i = 0; i < ARRAY_SIZE(ati_remote2_key_table); i++)
195 if (ati_remote2_key_table[i].hw_code == hw_code) 202 if (ati_remote2_key_table[i].hw_code == hw_code)
196 return i; 203 return i;
197 204
@@ -211,7 +218,7 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
211 218
212 mode = data[0] & 0x0F; 219 mode = data[0] & 0x0F;
213 220
214 if (mode > 4) { 221 if (mode > ATI_REMOTE2_PC) {
215 dev_err(&ar2->intf[1]->dev, 222 dev_err(&ar2->intf[1]->dev,
216 "Unknown mode byte (%02x %02x %02x %02x)\n", 223 "Unknown mode byte (%02x %02x %02x %02x)\n",
217 data[3], data[2], data[1], data[0]); 224 data[3], data[2], data[1], data[0]);
@@ -219,10 +226,6 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
219 } 226 }
220 227
221 hw_code = data[2]; 228 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) { 229 if (hw_code == 0x3f) {
227 /* 230 /*
228 * For some incomprehensible reason the mouse pad generates 231 * For some incomprehensible reason the mouse pad generates
@@ -236,8 +239,6 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
236 239
237 if (data[1] == 0) 240 if (data[1] == 0)
238 ar2->mode = mode; 241 ar2->mode = mode;
239
240 hw_code |= mode << 8;
241 } 242 }
242 243
243 if (!((1 << mode) & mode_mask)) 244 if (!((1 << mode) & mode_mask))
@@ -260,8 +261,8 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
260 case 2: /* repeat */ 261 case 2: /* repeat */
261 262
262 /* No repeat for mouse buttons. */ 263 /* No repeat for mouse buttons. */
263 if (ati_remote2_key_table[index].key_code == BTN_LEFT || 264 if (ar2->keycode[mode][index] == BTN_LEFT ||
264 ati_remote2_key_table[index].key_code == BTN_RIGHT) 265 ar2->keycode[mode][index] == BTN_RIGHT)
265 return; 266 return;
266 267
267 if (!time_after_eq(jiffies, ar2->jiffies)) 268 if (!time_after_eq(jiffies, ar2->jiffies))
@@ -276,7 +277,7 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
276 return; 277 return;
277 } 278 }
278 279
279 input_event(idev, EV_KEY, ati_remote2_key_table[index].key_code, data[1]); 280 input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]);
280 input_sync(idev); 281 input_sync(idev);
281} 282}
282 283
@@ -334,10 +335,60 @@ static void ati_remote2_complete_key(struct urb *urb)
334 "%s(): usb_submit_urb() = %d\n", __func__, r); 335 "%s(): usb_submit_urb() = %d\n", __func__, r);
335} 336}
336 337
338static int ati_remote2_getkeycode(struct input_dev *idev,
339 int scancode, int *keycode)
340{
341 struct ati_remote2 *ar2 = input_get_drvdata(idev);
342 int index, mode;
343
344 mode = scancode >> 8;
345 if (mode > ATI_REMOTE2_PC || !((1 << mode) & mode_mask))
346 return -EINVAL;
347
348 index = ati_remote2_lookup(scancode & 0xFF);
349 if (index < 0)
350 return -EINVAL;
351
352 *keycode = ar2->keycode[mode][index];
353 return 0;
354}
355
356static int ati_remote2_setkeycode(struct input_dev *idev, int scancode, int keycode)
357{
358 struct ati_remote2 *ar2 = input_get_drvdata(idev);
359 int index, mode, old_keycode;
360
361 mode = scancode >> 8;
362 if (mode > ATI_REMOTE2_PC || !((1 << mode) & mode_mask))
363 return -EINVAL;
364
365 index = ati_remote2_lookup(scancode & 0xFF);
366 if (index < 0)
367 return -EINVAL;
368
369 if (keycode < KEY_RESERVED || keycode > KEY_MAX)
370 return -EINVAL;
371
372 old_keycode = ar2->keycode[mode][index];
373 ar2->keycode[mode][index] = keycode;
374 set_bit(keycode, idev->keybit);
375
376 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
377 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
378 if (ar2->keycode[mode][index] == old_keycode)
379 return 0;
380 }
381 }
382
383 clear_bit(old_keycode, idev->keybit);
384
385 return 0;
386}
387
337static int ati_remote2_input_init(struct ati_remote2 *ar2) 388static int ati_remote2_input_init(struct ati_remote2 *ar2)
338{ 389{
339 struct input_dev *idev; 390 struct input_dev *idev;
340 int i, retval; 391 int index, mode, retval;
341 392
342 idev = input_allocate_device(); 393 idev = input_allocate_device();
343 if (!idev) 394 if (!idev)
@@ -350,8 +401,26 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2)
350 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | 401 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
351 BIT_MASK(BTN_RIGHT); 402 BIT_MASK(BTN_RIGHT);
352 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); 403 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++) 404
354 set_bit(ati_remote2_key_table[i].key_code, idev->keybit); 405 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
406 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
407 ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode;
408 set_bit(ar2->keycode[mode][index], idev->keybit);
409 }
410 }
411
412 /* AUX1-AUX4 and PC generate the same scancode. */
413 index = ati_remote2_lookup(0x3f);
414 ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1;
415 ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2;
416 ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3;
417 ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4;
418 ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC;
419 set_bit(KEY_PROG1, idev->keybit);
420 set_bit(KEY_PROG2, idev->keybit);
421 set_bit(KEY_PROG3, idev->keybit);
422 set_bit(KEY_PROG4, idev->keybit);
423 set_bit(KEY_PC, idev->keybit);
355 424
356 idev->rep[REP_DELAY] = 250; 425 idev->rep[REP_DELAY] = 250;
357 idev->rep[REP_PERIOD] = 33; 426 idev->rep[REP_PERIOD] = 33;
@@ -359,6 +428,9 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2)
359 idev->open = ati_remote2_open; 428 idev->open = ati_remote2_open;
360 idev->close = ati_remote2_close; 429 idev->close = ati_remote2_close;
361 430
431 idev->getkeycode = ati_remote2_getkeycode;
432 idev->setkeycode = ati_remote2_setkeycode;
433
362 idev->name = ar2->name; 434 idev->name = ar2->name;
363 idev->phys = ar2->phys; 435 idev->phys = ar2->phys;
364 436