aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/IR/ir-nec-decoder.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2010-03-21 12:00:55 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-05-17 23:52:58 -0400
commit9f1547829a6f39fe6b2da22653dff40502f3d568 (patch)
tree71c200ea5be13eef6b96f8e2290f0d2ba7792a09 /drivers/media/IR/ir-nec-decoder.c
parentada39630c758c5c3098f4fc1361103ea2bc1afe0 (diff)
V4L/DVB: saa7134: don't wait too much to generate an IR event on raw_decode
At raw_decode mode, the key is processed after the end of a timer. The previous code resets the timer every time something is received at the IR port. While this works fine with IR's that don't implement repeat, like Avermedia RM-JX IR, it keeps waiting until keydown, on IR's that implement NEC repeat command, like the Terratec yellow. The solution is to change the behaviour to do the timeout after the first received data. The timeout is currently set to 15 ms, as it works fine with NEC protcocol. It may need some adjustments to support other protocols and to better handle spurious detections that may happen with some IR sensors. Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/IR/ir-nec-decoder.c')
-rw-r--r--drivers/media/IR/ir-nec-decoder.c122
1 files changed, 83 insertions, 39 deletions
diff --git a/drivers/media/IR/ir-nec-decoder.c b/drivers/media/IR/ir-nec-decoder.c
index a58c717ec6b0..104482a6991e 100644
--- a/drivers/media/IR/ir-nec-decoder.c
+++ b/drivers/media/IR/ir-nec-decoder.c
@@ -14,21 +14,51 @@
14 14
15#include <media/ir-core.h> 15#include <media/ir-core.h>
16 16
17/* Start time: 4.5 ms */ 17/* Start time: 4.5 ms + 560 us of the next pulse */
18#define MIN_START_TIME 3900000 18#define MIN_START_TIME (3900000 + 560000)
19#define MAX_START_TIME 5100000 19#define MAX_START_TIME (5100000 + 560000)
20 20
21/* Pulse time: 560 us */ 21/* Bit 1 time: 2.25ms us */
22#define MIN_PULSE_TIME 460000 22#define MIN_BIT1_TIME 2050000
23#define MAX_PULSE_TIME 660000 23#define MAX_BIT1_TIME 2450000
24 24
25/* Bit 1 space time: 2.25ms-560 us */ 25/* Bit 0 time: 1.12ms us */
26#define MIN_BIT1_TIME 1490000 26#define MIN_BIT0_TIME 920000
27#define MAX_BIT1_TIME 1890000 27#define MAX_BIT0_TIME 1320000
28 28
29/* Bit 0 space time: 1.12ms-560 us */ 29/* Total IR code is 110 ms, including the 9 ms for the start pulse */
30#define MIN_BIT0_TIME 360000 30#define MAX_NEC_TIME 4000000
31#define MAX_BIT0_TIME 760000 31
32/* Total IR code is 110 ms, including the 9 ms for the start pulse */
33#define MIN_REPEAT_TIME 99000000
34#define MAX_REPEAT_TIME 112000000
35
36/* Repeat time: 2.25ms us */
37#define MIN_REPEAT_START_TIME 2050000
38#define MAX_REPEAT_START_TIME 3000000
39
40#define REPEAT_TIME 240 /* ms */
41
42/** is_repeat - Check if it is a NEC repeat event
43 * @input_dev: the struct input_dev descriptor of the device
44 * @pos: the position of the first event
45 * @len: the length of the buffer
46 */
47static int is_repeat(struct ir_raw_event *evs, int len, int pos)
48{
49 if ((evs[pos].delta.tv_nsec < MIN_REPEAT_START_TIME) ||
50 (evs[pos].delta.tv_nsec > MAX_REPEAT_START_TIME))
51 return 0;
52
53 if (++pos >= len)
54 return 0;
55
56 if ((evs[pos].delta.tv_nsec < MIN_REPEAT_TIME) ||
57 (evs[pos].delta.tv_nsec > MAX_REPEAT_TIME))
58 return 0;
59
60 return 1;
61}
32 62
33/** 63/**
34 * __ir_nec_decode() - Decode one NEC pulsecode 64 * __ir_nec_decode() - Decode one NEC pulsecode
@@ -36,49 +66,59 @@
36 * @evs: event array with type/duration of pulse/space 66 * @evs: event array with type/duration of pulse/space
37 * @len: length of the array 67 * @len: length of the array
38 * @pos: position to start seeking for a code 68 * @pos: position to start seeking for a code
39 * This function returns the decoded ircode or -EINVAL if no pulse got decoded 69 * This function returns -EINVAL if no pulse got decoded,
70 * 0 if buffer is empty and 1 if one keycode were handled.
40 */ 71 */
41static int __ir_nec_decode(struct input_dev *input_dev, 72static int __ir_nec_decode(struct input_dev *input_dev,
42 struct ir_raw_event *evs, 73 struct ir_raw_event *evs,
43 int len, int *pos) 74 int len, int *pos)
44{ 75{
76 struct ir_input_dev *ir = input_get_drvdata(input_dev);
45 int count = -1; 77 int count = -1;
46 int ircode = 0, not_code = 0; 78 int ircode = 0, not_code = 0;
47 79
48 /* Be sure that the first event is an start one and is a pulse */ 80 /* Be sure that the first event is an start one and is a pulse */
49 for (; *pos < len; (*pos)++) { 81 for (; *pos < len; (*pos)++) {
50 if (evs[*pos].type & (IR_START_EVENT | IR_PULSE)) 82 /* Very long delays are considered as start events */
83 if (evs[*pos].delta.tv_nsec > MAX_NEC_TIME)
51 break; 84 break;
52 } 85 if (evs[*pos].type & IR_START_EVENT)
53 (*pos)++; /* First event doesn't contain data */ 86 break;
87 IR_dprintk(1, "%luus: Spurious NEC %s\n",
88 (evs[*pos].delta.tv_nsec + 500) / 1000,
89 (evs[*pos].type & IR_SPACE) ? "space" : "pulse");
54 90
91 }
55 if (*pos >= len) 92 if (*pos >= len)
56 return 0; 93 return 0;
57 94
58 /* First space should have 4.5 ms otherwise is not NEC protocol */ 95 (*pos)++; /* First event doesn't contain data */
59 if ((evs[*pos].delta.tv_nsec < MIN_START_TIME) | 96
60 (evs[*pos].delta.tv_nsec > MAX_START_TIME) | 97 if (evs[*pos].type != IR_PULSE)
61 (evs[*pos].type != IR_SPACE))
62 goto err; 98 goto err;
63 99
64 /* 100 /* Check if it is a NEC repeat event */
65 * FIXME: need to implement the repeat sequence 101 if (is_repeat(evs, len, *pos)) {
66 */ 102 *pos += 2;
103 if (ir->keypressed) {
104 mod_timer(&ir->raw->timer_keyup,
105 jiffies + msecs_to_jiffies(REPEAT_TIME));
106 IR_dprintk(1, "NEC repeat event\n");
107 return 1;
108 } else {
109 IR_dprintk(1, "missing NEC repeat event\n");
110 return 0;
111 }
112 }
113
114 /* First space should have 4.5 ms otherwise is not NEC protocol */
115 if ((evs[*pos].delta.tv_nsec < MIN_START_TIME) ||
116 (evs[*pos].delta.tv_nsec > MAX_START_TIME))
117 goto err;
67 118
68 count = 0; 119 count = 0;
69 for ((*pos)++; *pos < len; (*pos)++) { 120 for ((*pos)++; *pos < len; (*pos)++) {
70 int bit; 121 int bit;
71
72 if ((evs[*pos].delta.tv_nsec < MIN_PULSE_TIME) |
73 (evs[*pos].delta.tv_nsec > MAX_PULSE_TIME) |
74 (evs[*pos].type != IR_PULSE))
75 goto err;
76
77 if (++*pos >= len)
78 goto err;
79 if (evs[*pos].type != IR_SPACE)
80 goto err;
81
82 if ((evs[*pos].delta.tv_nsec > MIN_BIT1_TIME) && 122 if ((evs[*pos].delta.tv_nsec > MIN_BIT1_TIME) &&
83 (evs[*pos].delta.tv_nsec < MAX_BIT1_TIME)) 123 (evs[*pos].delta.tv_nsec < MAX_BIT1_TIME))
84 bit = 1; 124 bit = 1;
@@ -107,6 +147,7 @@ static int __ir_nec_decode(struct input_dev *input_dev,
107 if (++count == 32) 147 if (++count == 32)
108 break; 148 break;
109 } 149 }
150 *pos++;
110 151
111 /* 152 /*
112 * Fixme: may need to accept Extended NEC protocol? 153 * Fixme: may need to accept Extended NEC protocol?
@@ -119,12 +160,15 @@ static int __ir_nec_decode(struct input_dev *input_dev,
119 160
120 IR_dprintk(1, "NEC scancode 0x%04x\n", ircode); 161 IR_dprintk(1, "NEC scancode 0x%04x\n", ircode);
121 ir_keydown(input_dev, ircode); 162 ir_keydown(input_dev, ircode);
122 ir_keyup(input_dev); 163 mod_timer(&ir->raw->timer_keyup,
164 jiffies + msecs_to_jiffies(REPEAT_TIME));
123 165
124 return ircode; 166 return 1;
125err: 167err:
126 IR_dprintk(1, "NEC decoded failed at bit %d while decoding %luus time\n", 168 IR_dprintk(1, "NEC decoded failed at bit %d (%s) while decoding %luus time\n",
127 count, (evs[*pos].delta.tv_nsec + 500) / 1000); 169 count,
170 (evs[*pos].type & IR_SPACE) ? "space" : "pulse",
171 (evs[*pos].delta.tv_nsec + 500) / 1000);
128 172
129 return -EINVAL; 173 return -EINVAL;
130} 174}
@@ -145,7 +189,7 @@ int ir_nec_decode(struct input_dev *input_dev,
145 int rc = 0; 189 int rc = 0;
146 190
147 while (pos < len) { 191 while (pos < len) {
148 if (__ir_nec_decode(input_dev, evs, len, &pos) >= 0) 192 if (__ir_nec_decode(input_dev, evs, len, &pos) > 0)
149 rc++; 193 rc++;
150 } 194 }
151 195