aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2010-03-21 11:24:24 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-05-17 23:52:57 -0400
commitada39630c758c5c3098f4fc1361103ea2bc1afe0 (patch)
treecfad77eb7e0f96256edc08c058ea7b39ee2d30b1 /drivers/media
parent6660de568d164e4eda6617dadcb999c96e62203f (diff)
V4L/DVB: ir-core/saa7134: Move ir keyup/keydown code to the ir-core
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/IR/ir-nec-decoder.c90
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c12
2 files changed, 59 insertions, 43 deletions
diff --git a/drivers/media/IR/ir-nec-decoder.c b/drivers/media/IR/ir-nec-decoder.c
index 16360eb4055b..a58c717ec6b0 100644
--- a/drivers/media/IR/ir-nec-decoder.c
+++ b/drivers/media/IR/ir-nec-decoder.c
@@ -30,37 +30,35 @@
30#define MIN_BIT0_TIME 360000 30#define MIN_BIT0_TIME 360000
31#define MAX_BIT0_TIME 760000 31#define MAX_BIT0_TIME 760000
32 32
33 33/**
34/** Decode NEC pulsecode. This code can take up to 76.5 ms to run. 34 * __ir_nec_decode() - Decode one NEC pulsecode
35 Unfortunately, using IRQ to decode pulse didn't work, since it uses 35 * @input_dev: the struct input_dev descriptor of the device
36 a pulse train of 38KHz. This means one pulse on each 52 us 36 * @evs: event array with type/duration of pulse/space
37*/ 37 * @len: length of the array
38 38 * @pos: position to start seeking for a code
39int ir_nec_decode(struct input_dev *input_dev, 39 * This function returns the decoded ircode or -EINVAL if no pulse got decoded
40 struct ir_raw_event *evs, 40 */
41 int len) 41static int __ir_nec_decode(struct input_dev *input_dev,
42 struct ir_raw_event *evs,
43 int len, int *pos)
42{ 44{
43 int i, count = -1; 45 int count = -1;
44 int ircode = 0, not_code = 0; 46 int ircode = 0, not_code = 0;
45#if 0
46 /* Needed only after porting the event code to the decoder */
47 struct ir_input_dev *ir = input_get_drvdata(input_dev);
48#endif
49 47
50 /* Be sure that the first event is an start one and is a pulse */ 48 /* Be sure that the first event is an start one and is a pulse */
51 for (i = 0; i < len; i++) { 49 for (; *pos < len; (*pos)++) {
52 if (evs[i].type & (IR_START_EVENT | IR_PULSE)) 50 if (evs[*pos].type & (IR_START_EVENT | IR_PULSE))
53 break; 51 break;
54 } 52 }
55 i++; /* First event doesn't contain data */ 53 (*pos)++; /* First event doesn't contain data */
56 54
57 if (i >= len) 55 if (*pos >= len)
58 return 0; 56 return 0;
59 57
60 /* First space should have 4.5 ms otherwise is not NEC protocol */ 58 /* First space should have 4.5 ms otherwise is not NEC protocol */
61 if ((evs[i].delta.tv_nsec < MIN_START_TIME) | 59 if ((evs[*pos].delta.tv_nsec < MIN_START_TIME) |
62 (evs[i].delta.tv_nsec > MAX_START_TIME) | 60 (evs[*pos].delta.tv_nsec > MAX_START_TIME) |
63 (evs[i].type != IR_SPACE)) 61 (evs[*pos].type != IR_SPACE))
64 goto err; 62 goto err;
65 63
66 /* 64 /*
@@ -68,24 +66,24 @@ int ir_nec_decode(struct input_dev *input_dev,
68 */ 66 */
69 67
70 count = 0; 68 count = 0;
71 for (i++; i < len; i++) { 69 for ((*pos)++; *pos < len; (*pos)++) {
72 int bit; 70 int bit;
73 71
74 if ((evs[i].delta.tv_nsec < MIN_PULSE_TIME) | 72 if ((evs[*pos].delta.tv_nsec < MIN_PULSE_TIME) |
75 (evs[i].delta.tv_nsec > MAX_PULSE_TIME) | 73 (evs[*pos].delta.tv_nsec > MAX_PULSE_TIME) |
76 (evs[i].type != IR_PULSE)) 74 (evs[*pos].type != IR_PULSE))
77 goto err; 75 goto err;
78 76
79 if (++i >= len) 77 if (++*pos >= len)
80 goto err; 78 goto err;
81 if (evs[i].type != IR_SPACE) 79 if (evs[*pos].type != IR_SPACE)
82 goto err; 80 goto err;
83 81
84 if ((evs[i].delta.tv_nsec > MIN_BIT1_TIME) && 82 if ((evs[*pos].delta.tv_nsec > MIN_BIT1_TIME) &&
85 (evs[i].delta.tv_nsec < MAX_BIT1_TIME)) 83 (evs[*pos].delta.tv_nsec < MAX_BIT1_TIME))
86 bit = 1; 84 bit = 1;
87 else if ((evs[i].delta.tv_nsec > MIN_BIT0_TIME) && 85 else if ((evs[*pos].delta.tv_nsec > MIN_BIT0_TIME) &&
88 (evs[i].delta.tv_nsec < MAX_BIT0_TIME)) 86 (evs[*pos].delta.tv_nsec < MAX_BIT0_TIME))
89 bit = 0; 87 bit = 0;
90 else 88 else
91 goto err; 89 goto err;
@@ -120,12 +118,40 @@ int ir_nec_decode(struct input_dev *input_dev,
120 } 118 }
121 119
122 IR_dprintk(1, "NEC scancode 0x%04x\n", ircode); 120 IR_dprintk(1, "NEC scancode 0x%04x\n", ircode);
121 ir_keydown(input_dev, ircode);
122 ir_keyup(input_dev);
123 123
124 return ircode; 124 return ircode;
125err: 125err:
126 IR_dprintk(1, "NEC decoded failed at bit %d while decoding %luus time\n", 126 IR_dprintk(1, "NEC decoded failed at bit %d while decoding %luus time\n",
127 count, (evs[i].delta.tv_nsec + 500) / 1000); 127 count, (evs[*pos].delta.tv_nsec + 500) / 1000);
128 128
129 return -EINVAL; 129 return -EINVAL;
130} 130}
131
132/**
133 * __ir_nec_decode() - Decodes all NEC pulsecodes on a given array
134 * @input_dev: the struct input_dev descriptor of the device
135 * @evs: event array with type/duration of pulse/space
136 * @len: length of the array
137 * This function returns the number of decoded pulses or -EINVAL if no
138 * pulse got decoded
139 */
140int ir_nec_decode(struct input_dev *input_dev,
141 struct ir_raw_event *evs,
142 int len)
143{
144 int pos = 0;
145 int rc = 0;
146
147 while (pos < len) {
148 if (__ir_nec_decode(input_dev, evs, len, &pos) >= 0)
149 rc++;
150 }
151
152 if (!rc)
153 return -EINVAL;
154 return rc;
155}
156
131EXPORT_SYMBOL_GPL(ir_nec_decode); 157EXPORT_SYMBOL_GPL(ir_nec_decode);
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index 1a7cf9c8c68c..dff33279ab33 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -425,18 +425,8 @@ static void saa7134_input_timer(unsigned long data)
425void ir_raw_decode_timer_end(unsigned long data) 425void 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;
429 int rc;
430 428
431 /* 429 ir_raw_event_handle(dev->remote->dev);
432 * FIXME: the IR key handling code should be called by the decoder,
433 * after implementing the repeat mode
434 */
435 rc = ir_raw_event_handle(dev->remote->dev);
436 if (rc >= 0) {
437 ir_input_keydown(ir->dev, &ir->ir, rc);
438 ir_input_nokey(ir->dev, &ir->ir);
439 }
440} 430}
441 431
442void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir) 432void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)