diff options
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/IR/ir-keytable.c | 1 | ||||
-rw-r--r-- | drivers/media/IR/ir-nec-decoder.c | 122 | ||||
-rw-r--r-- | drivers/media/IR/ir-raw-event.c | 14 | ||||
-rw-r--r-- | drivers/media/video/saa7134/saa7134-input.c | 43 |
4 files changed, 115 insertions, 65 deletions
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c index e59290febf81..fcb0f0cb1fe1 100644 --- a/drivers/media/IR/ir-keytable.c +++ b/drivers/media/IR/ir-keytable.c | |||
@@ -405,6 +405,7 @@ void ir_keyup(struct input_dev *dev) | |||
405 | if (!ir->keypressed) | 405 | if (!ir->keypressed) |
406 | return; | 406 | return; |
407 | 407 | ||
408 | IR_dprintk(1, "keyup key 0x%04x\n", ir->keycode); | ||
408 | input_report_key(dev, ir->keycode, 0); | 409 | input_report_key(dev, ir->keycode, 0); |
409 | input_sync(dev); | 410 | input_sync(dev); |
410 | ir->keypressed = 0; | 411 | ir->keypressed = 0; |
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 | */ | ||
47 | static 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 | */ |
41 | static int __ir_nec_decode(struct input_dev *input_dev, | 72 | static 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; |
125 | err: | 167 | err: |
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 | ||
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c index 9c71ac858923..0ae55433cef9 100644 --- a/drivers/media/IR/ir-raw-event.c +++ b/drivers/media/IR/ir-raw-event.c | |||
@@ -17,6 +17,13 @@ | |||
17 | /* Define the max number of bit transitions per IR keycode */ | 17 | /* Define the max number of bit transitions per IR keycode */ |
18 | #define MAX_IR_EVENT_SIZE 256 | 18 | #define MAX_IR_EVENT_SIZE 256 |
19 | 19 | ||
20 | static void ir_keyup_timer(unsigned long data) | ||
21 | { | ||
22 | struct input_dev *input_dev = (struct input_dev *)data; | ||
23 | |||
24 | ir_keyup(input_dev); | ||
25 | } | ||
26 | |||
20 | int ir_raw_event_register(struct input_dev *input_dev) | 27 | int ir_raw_event_register(struct input_dev *input_dev) |
21 | { | 28 | { |
22 | struct ir_input_dev *ir = input_get_drvdata(input_dev); | 29 | struct ir_input_dev *ir = input_get_drvdata(input_dev); |
@@ -27,6 +34,11 @@ int ir_raw_event_register(struct input_dev *input_dev) | |||
27 | size = sizeof(struct ir_raw_event) * MAX_IR_EVENT_SIZE * 2; | 34 | size = sizeof(struct ir_raw_event) * MAX_IR_EVENT_SIZE * 2; |
28 | size = roundup_pow_of_two(size); | 35 | size = roundup_pow_of_two(size); |
29 | 36 | ||
37 | init_timer(&ir->raw->timer_keyup); | ||
38 | ir->raw->timer_keyup.function = ir_keyup_timer; | ||
39 | ir->raw->timer_keyup.data = (unsigned long)input_dev; | ||
40 | set_bit(EV_REP, input_dev->evbit); | ||
41 | |||
30 | rc = kfifo_alloc(&ir->raw->kfifo, size, GFP_KERNEL); | 42 | rc = kfifo_alloc(&ir->raw->kfifo, size, GFP_KERNEL); |
31 | 43 | ||
32 | return rc; | 44 | return rc; |
@@ -40,6 +52,8 @@ void ir_raw_event_unregister(struct input_dev *input_dev) | |||
40 | if (!ir->raw) | 52 | if (!ir->raw) |
41 | return; | 53 | return; |
42 | 54 | ||
55 | del_timer_sync(&ir->raw->timer_keyup); | ||
56 | |||
43 | kfifo_free(&ir->raw->kfifo); | 57 | kfifo_free(&ir->raw->kfifo); |
44 | kfree(ir->raw); | 58 | kfree(ir->raw); |
45 | ir->raw = NULL; | 59 | ir->raw = NULL; |
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c index dff33279ab33..32859e549afa 100644 --- a/drivers/media/video/saa7134/saa7134-input.c +++ b/drivers/media/video/saa7134/saa7134-input.c | |||
@@ -425,8 +425,11 @@ static void saa7134_input_timer(unsigned long data) | |||
425 | void ir_raw_decode_timer_end(unsigned long data) | 425 | void ir_raw_decode_timer_end(unsigned long data) |
426 | { | 426 | { |
427 | struct saa7134_dev *dev = (struct saa7134_dev *)data; | 427 | struct saa7134_dev *dev = (struct saa7134_dev *)data; |
428 | struct card_ir *ir = dev->remote; | ||
428 | 429 | ||
429 | ir_raw_event_handle(dev->remote->dev); | 430 | ir_raw_event_handle(dev->remote->dev); |
431 | |||
432 | ir->active = 0; | ||
430 | } | 433 | } |
431 | 434 | ||
432 | void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir) | 435 | void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir) |
@@ -462,6 +465,7 @@ void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir) | |||
462 | init_timer(&ir->timer_end); | 465 | init_timer(&ir->timer_end); |
463 | ir->timer_end.function = ir_raw_decode_timer_end; | 466 | ir->timer_end.function = ir_raw_decode_timer_end; |
464 | ir->timer_end.data = (unsigned long)dev; | 467 | ir->timer_end.data = (unsigned long)dev; |
468 | ir->active = 0; | ||
465 | } | 469 | } |
466 | } | 470 | } |
467 | 471 | ||
@@ -477,8 +481,10 @@ void saa7134_ir_stop(struct saa7134_dev *dev) | |||
477 | del_timer_sync(&ir->timer_end); | 481 | del_timer_sync(&ir->timer_end); |
478 | else if (ir->nec_gpio) | 482 | else if (ir->nec_gpio) |
479 | tasklet_kill(&ir->tlet); | 483 | tasklet_kill(&ir->tlet); |
480 | else if (ir->raw_decode) | 484 | else if (ir->raw_decode) { |
481 | del_timer_sync(&ir->timer_end); | 485 | del_timer_sync(&ir->timer_end); |
486 | ir->active = 0; | ||
487 | } | ||
482 | 488 | ||
483 | ir->running = 0; | 489 | ir->running = 0; |
484 | } | 490 | } |
@@ -951,38 +957,23 @@ static int saa7134_raw_decode_irq(struct saa7134_dev *dev) | |||
951 | unsigned long timeout; | 957 | unsigned long timeout; |
952 | int count, pulse, oldpulse; | 958 | int count, pulse, oldpulse; |
953 | 959 | ||
954 | /* Disable IR IRQ line */ | ||
955 | saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18); | ||
956 | |||
957 | /* Generate initial event */ | 960 | /* Generate initial event */ |
958 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | 961 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
959 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | 962 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
960 | pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown; | 963 | pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown; |
961 | ir_raw_event_store(dev->remote->dev, pulse? IR_PULSE : IR_SPACE); | 964 | ir_raw_event_store(dev->remote->dev, pulse? IR_PULSE : IR_SPACE); |
962 | 965 | ||
963 | #if 1 | ||
964 | /* Wait up to 10 ms for event change */ | ||
965 | oldpulse = pulse; | ||
966 | for (count = 0; count < 1000; count++) { | ||
967 | udelay(10); | ||
968 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ | ||
969 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | ||
970 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); | ||
971 | pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) | ||
972 | & ir->mask_keydown; | ||
973 | if (pulse != oldpulse) | ||
974 | break; | ||
975 | } | ||
976 | |||
977 | /* Store final event */ | ||
978 | ir_raw_event_store(dev->remote->dev, pulse? IR_PULSE : IR_SPACE); | ||
979 | #endif | ||
980 | /* Wait 15 ms before deciding to do something else */ | ||
981 | timeout = jiffies + jiffies_to_msecs(15); | ||
982 | mod_timer(&ir->timer_end, timeout); | ||
983 | 966 | ||
984 | /* Enable IR IRQ line */ | 967 | /* |
985 | saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18); | 968 | * Wait 15 ms from the start of the first IR event before processing |
969 | * the event. This time is enough for NEC protocol. May need adjustments | ||
970 | * to work with other protocols. | ||
971 | */ | ||
972 | if (!ir->active) { | ||
973 | timeout = jiffies + jiffies_to_msecs(15); | ||
974 | mod_timer(&ir->timer_end, timeout); | ||
975 | ir->active = 1; | ||
976 | } | ||
986 | 977 | ||
987 | return 1; | 978 | return 1; |
988 | } | 979 | } |