aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/common/ir-functions.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-12-09 22:50:49 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-09 22:50:49 -0500
commit3e7468313758913c5e4d372f35b271b96bad1298 (patch)
treeeb612d252a9e2349a1173451cd779beebd18a33e /drivers/media/common/ir-functions.c
parent6825fbc4cb219f2c98bb7d157915d797cf5cb823 (diff)
parente97f4677961f68e29bd906022ebf60a6df7f530a (diff)
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6
* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6: (345 commits) V4L/DVB (13542): ir-keytable: Allow dynamic table change V4L/DVB (13541): atbm8830: replace 64-bit division and floating point usage V4L/DVB (13540): ir-common: Cleanup get key evdev code V4L/DVB (13539): ir-common: add __func__ for debug messages V4L/DVB (13538): ir-common: Use a dynamic keycode table V4L/DVB (13537): ir: Prepare the code for dynamic keycode table allocation V4L/DVB (13536): em28xx: Use the full RC5 code on HVR-950 Remote Controller V4L/DVB (13535): ir-common: Add a hauppauge new table with the complete RC5 code V4L/DVB (13534): ir-common: Remove some unused fields/structs V4L/DVB (13533): ir: use dynamic tables, instead of static ones V4L/DVB (13532): ir-common: Add infrastructure to use a dynamic keycode table V4L/DVB (13531): ir-common: rename the debug routine to allow exporting it V4L/DVB (13458): go7007: subdev conversion V4L/DVB (13457): s2250: subdev conversion V4L/DVB (13456): s2250: Change module structure V4L/DVB (13528): em28xx: add support for em2800 VC211A card em28xx: don't reduce scale to half size for em2800 em28xx: don't load audio modules when AC97 is mis-detected em28xx: em2800 chips support max width of 640 V4L/DVB (13523): dvb-bt8xx: fix compile warning ... Fix up trivial conflicts due to spelling fixes from the trivial tree in Documentation/video4linux/gspca.txt drivers/media/video/cx18/cx18-mailbox.h
Diffstat (limited to 'drivers/media/common/ir-functions.c')
-rw-r--r--drivers/media/common/ir-functions.c71
1 files changed, 31 insertions, 40 deletions
diff --git a/drivers/media/common/ir-functions.c b/drivers/media/common/ir-functions.c
index abd4791acb0e..e616f624ceaa 100644
--- a/drivers/media/common/ir-functions.c
+++ b/drivers/media/common/ir-functions.c
@@ -34,22 +34,19 @@ static int repeat = 1;
34module_param(repeat, int, 0444); 34module_param(repeat, int, 0444);
35MODULE_PARM_DESC(repeat,"auto-repeat for IR keys (default: on)"); 35MODULE_PARM_DESC(repeat,"auto-repeat for IR keys (default: on)");
36 36
37static int debug; /* debug level (0,1,2) */ 37int media_ir_debug; /* media_ir_debug level (0,1,2) */
38module_param(debug, int, 0644); 38module_param_named(debug, media_ir_debug, int, 0644);
39
40#define dprintk(level, fmt, arg...) if (debug >= level) \
41 printk(KERN_DEBUG fmt , ## arg)
42 39
43/* -------------------------------------------------------------------------- */ 40/* -------------------------------------------------------------------------- */
44 41
45static void ir_input_key_event(struct input_dev *dev, struct ir_input_state *ir) 42static void ir_input_key_event(struct input_dev *dev, struct ir_input_state *ir)
46{ 43{
47 if (KEY_RESERVED == ir->keycode) { 44 if (KEY_RESERVED == ir->keycode) {
48 printk(KERN_INFO "%s: unknown key: key=0x%02x raw=0x%02x down=%d\n", 45 printk(KERN_INFO "%s: unknown key: key=0x%02x down=%d\n",
49 dev->name,ir->ir_key,ir->ir_raw,ir->keypressed); 46 dev->name, ir->ir_key, ir->keypressed);
50 return; 47 return;
51 } 48 }
52 dprintk(1,"%s: key event code=%d down=%d\n", 49 IR_dprintk(1,"%s: key event code=%d down=%d\n",
53 dev->name,ir->keycode,ir->keypressed); 50 dev->name,ir->keycode,ir->keypressed);
54 input_report_key(dev,ir->keycode,ir->keypressed); 51 input_report_key(dev,ir->keycode,ir->keypressed);
55 input_sync(dev); 52 input_sync(dev);
@@ -57,39 +54,34 @@ static void ir_input_key_event(struct input_dev *dev, struct ir_input_state *ir)
57 54
58/* -------------------------------------------------------------------------- */ 55/* -------------------------------------------------------------------------- */
59 56
60void ir_input_init(struct input_dev *dev, struct ir_input_state *ir, 57int ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
61 int ir_type, struct ir_scancode_table *ir_codes) 58 int ir_type, struct ir_scancode_table *ir_codes)
62{ 59{
63 int i;
64
65 ir->ir_type = ir_type; 60 ir->ir_type = ir_type;
66 61
67 memset(ir->ir_codes, 0, sizeof(ir->ir_codes)); 62 ir->keytable.size = ir_roundup_tablesize(ir_codes->size);
63 ir->keytable.scan = kzalloc(ir->keytable.size *
64 sizeof(struct ir_scancode), GFP_KERNEL);
65 if (!ir->keytable.scan)
66 return -ENOMEM;
68 67
69 /* 68 IR_dprintk(1, "Allocated space for %d keycode entries (%zd bytes)\n",
70 * FIXME: This is a temporary workaround to use the new IR tables 69 ir->keytable.size,
71 * with the old approach. Later patches will replace this to a 70 ir->keytable.size * sizeof(ir->keytable.scan));
72 * proper method
73 */
74 71
75 if (ir_codes) 72 ir_copy_table(&ir->keytable, ir_codes);
76 for (i = 0; i < ir_codes->size; i++) 73 ir_set_keycode_table(dev, &ir->keytable);
77 if (ir_codes->scan[i].scancode < IR_KEYTAB_SIZE)
78 ir->ir_codes[ir_codes->scan[i].scancode] = ir_codes->scan[i].keycode;
79 74
80 dev->keycode = ir->ir_codes;
81 dev->keycodesize = sizeof(IR_KEYTAB_TYPE);
82 dev->keycodemax = IR_KEYTAB_SIZE;
83 for (i = 0; i < IR_KEYTAB_SIZE; i++)
84 set_bit(ir->ir_codes[i], dev->keybit);
85 clear_bit(0, dev->keybit); 75 clear_bit(0, dev->keybit);
86
87 set_bit(EV_KEY, dev->evbit); 76 set_bit(EV_KEY, dev->evbit);
88 if (repeat) 77 if (repeat)
89 set_bit(EV_REP, dev->evbit); 78 set_bit(EV_REP, dev->evbit);
79
80 return 0;
90} 81}
91EXPORT_SYMBOL_GPL(ir_input_init); 82EXPORT_SYMBOL_GPL(ir_input_init);
92 83
84
93void ir_input_nokey(struct input_dev *dev, struct ir_input_state *ir) 85void ir_input_nokey(struct input_dev *dev, struct ir_input_state *ir)
94{ 86{
95 if (ir->keypressed) { 87 if (ir->keypressed) {
@@ -100,9 +92,9 @@ void ir_input_nokey(struct input_dev *dev, struct ir_input_state *ir)
100EXPORT_SYMBOL_GPL(ir_input_nokey); 92EXPORT_SYMBOL_GPL(ir_input_nokey);
101 93
102void ir_input_keydown(struct input_dev *dev, struct ir_input_state *ir, 94void ir_input_keydown(struct input_dev *dev, struct ir_input_state *ir,
103 u32 ir_key, u32 ir_raw) 95 u32 ir_key)
104{ 96{
105 u32 keycode = IR_KEYCODE(ir->ir_codes, ir_key); 97 u32 keycode = ir_g_keycode_from_table(dev, ir_key);
106 98
107 if (ir->keypressed && ir->keycode != keycode) { 99 if (ir->keypressed && ir->keycode != keycode) {
108 ir->keypressed = 0; 100 ir->keypressed = 0;
@@ -110,7 +102,6 @@ void ir_input_keydown(struct input_dev *dev, struct ir_input_state *ir,
110 } 102 }
111 if (!ir->keypressed) { 103 if (!ir->keypressed) {
112 ir->ir_key = ir_key; 104 ir->ir_key = ir_key;
113 ir->ir_raw = ir_raw;
114 ir->keycode = keycode; 105 ir->keycode = keycode;
115 ir->keypressed = 1; 106 ir->keypressed = 1;
116 ir_input_key_event(dev,ir); 107 ir_input_key_event(dev,ir);
@@ -275,7 +266,7 @@ EXPORT_SYMBOL_GPL(ir_decode_biphase);
275 * saa7134 */ 266 * saa7134 */
276 267
277/* decode raw bit pattern to RC5 code */ 268/* decode raw bit pattern to RC5 code */
278static u32 ir_rc5_decode(unsigned int code) 269u32 ir_rc5_decode(unsigned int code)
279{ 270{
280 unsigned int org_code = code; 271 unsigned int org_code = code;
281 unsigned int pair; 272 unsigned int pair;
@@ -295,15 +286,16 @@ static u32 ir_rc5_decode(unsigned int code)
295 rc5 |= 1; 286 rc5 |= 1;
296 break; 287 break;
297 case 3: 288 case 3:
298 dprintk(1, "ir-common: ir_rc5_decode(%x) bad code\n", org_code); 289 IR_dprintk(1, "ir-common: ir_rc5_decode(%x) bad code\n", org_code);
299 return 0; 290 return 0;
300 } 291 }
301 } 292 }
302 dprintk(1, "ir-common: code=%x, rc5=%x, start=%x, toggle=%x, address=%x, " 293 IR_dprintk(1, "ir-common: code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
303 "instr=%x\n", rc5, org_code, RC5_START(rc5), 294 "instr=%x\n", rc5, org_code, RC5_START(rc5),
304 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5)); 295 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
305 return rc5; 296 return rc5;
306} 297}
298EXPORT_SYMBOL_GPL(ir_rc5_decode);
307 299
308void ir_rc5_timer_end(unsigned long data) 300void ir_rc5_timer_end(unsigned long data)
309{ 301{
@@ -330,20 +322,20 @@ void ir_rc5_timer_end(unsigned long data)
330 322
331 /* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */ 323 /* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
332 if (gap < 28000) { 324 if (gap < 28000) {
333 dprintk(1, "ir-common: spurious timer_end\n"); 325 IR_dprintk(1, "ir-common: spurious timer_end\n");
334 return; 326 return;
335 } 327 }
336 328
337 if (ir->last_bit < 20) { 329 if (ir->last_bit < 20) {
338 /* ignore spurious codes (caused by light/other remotes) */ 330 /* ignore spurious codes (caused by light/other remotes) */
339 dprintk(1, "ir-common: short code: %x\n", ir->code); 331 IR_dprintk(1, "ir-common: short code: %x\n", ir->code);
340 } else { 332 } else {
341 ir->code = (ir->code << ir->shift_by) | 1; 333 ir->code = (ir->code << ir->shift_by) | 1;
342 rc5 = ir_rc5_decode(ir->code); 334 rc5 = ir_rc5_decode(ir->code);
343 335
344 /* two start bits? */ 336 /* two start bits? */
345 if (RC5_START(rc5) != ir->start) { 337 if (RC5_START(rc5) != ir->start) {
346 dprintk(1, "ir-common: rc5 start bits invalid: %u\n", RC5_START(rc5)); 338 IR_dprintk(1, "ir-common: rc5 start bits invalid: %u\n", RC5_START(rc5));
347 339
348 /* right address? */ 340 /* right address? */
349 } else if (RC5_ADDR(rc5) == ir->addr) { 341 } else if (RC5_ADDR(rc5) == ir->addr) {
@@ -353,11 +345,10 @@ void ir_rc5_timer_end(unsigned long data)
353 /* Good code, decide if repeat/repress */ 345 /* Good code, decide if repeat/repress */
354 if (toggle != RC5_TOGGLE(ir->last_rc5) || 346 if (toggle != RC5_TOGGLE(ir->last_rc5) ||
355 instr != RC5_INSTR(ir->last_rc5)) { 347 instr != RC5_INSTR(ir->last_rc5)) {
356 dprintk(1, "ir-common: instruction %x, toggle %x\n", instr, 348 IR_dprintk(1, "ir-common: instruction %x, toggle %x\n", instr,
357 toggle); 349 toggle);
358 ir_input_nokey(ir->dev, &ir->ir); 350 ir_input_nokey(ir->dev, &ir->ir);
359 ir_input_keydown(ir->dev, &ir->ir, instr, 351 ir_input_keydown(ir->dev, &ir->ir, instr);
360 instr);
361 } 352 }
362 353
363 /* Set/reset key-up timer */ 354 /* Set/reset key-up timer */
@@ -376,7 +367,7 @@ void ir_rc5_timer_keyup(unsigned long data)
376{ 367{
377 struct card_ir *ir = (struct card_ir *)data; 368 struct card_ir *ir = (struct card_ir *)data;
378 369
379 dprintk(1, "ir-common: key released\n"); 370 IR_dprintk(1, "ir-common: key released\n");
380 ir_input_nokey(ir->dev, &ir->ir); 371 ir_input_nokey(ir->dev, &ir->ir);
381} 372}
382EXPORT_SYMBOL_GPL(ir_rc5_timer_keyup); 373EXPORT_SYMBOL_GPL(ir_rc5_timer_keyup);