aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@redhat.com>2010-11-17 07:58:09 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-12-29 05:16:49 -0500
commitbce8d0fe4af4b3a1e46e66cd6116d6389ad0cc22 (patch)
tree8192bf86a9249e54fcc9b37da11791ae17ae401f /drivers/media
parent1697c8dfba72fd182d670a68dca157f64dd3b1f2 (diff)
[media] rc: remove ir-common module
Something weird happened with commit 740069e6e043403199dbe2b42256722fb814f6ae. Instead of dong the right thing, it got somehow corrupted and reverted the rc changes. Thanks to David Härdeman for pointing me about the problem. This patch should be merged with 740069e6e04 before sending upstream. Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/rc/Kconfig5
-rw-r--r--drivers/media/rc/Makefile2
-rw-r--r--drivers/media/rc/ir-functions.c120
-rw-r--r--drivers/media/video/bt8xx/Kconfig2
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c105
-rw-r--r--drivers/media/video/saa7134/Kconfig2
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c226
-rw-r--r--drivers/media/video/saa7134/saa7134.h2
8 files changed, 108 insertions, 356 deletions
diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 2d1546889c9b..ef19375899ec 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -10,11 +10,6 @@ menuconfig IR_CORE
10 if you don't need IR, as otherwise, you may not be able to 10 if you don't need IR, as otherwise, you may not be able to
11 compile the driver for your adapter. 11 compile the driver for your adapter.
12 12
13config IR_LEGACY
14 tristate
15 depends on IR_CORE
16 default IR_CORE
17
18if IR_CORE 13if IR_CORE
19 14
20config LIRC 15config LIRC
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index 859c12cc03ff..8c0e4cb19551 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -1,10 +1,8 @@
1ir-common-objs := ir-functions.o
2rc-core-objs := rc-main.o rc-raw.o 1rc-core-objs := rc-main.o rc-raw.o
3 2
4obj-y += keymaps/ 3obj-y += keymaps/
5 4
6obj-$(CONFIG_IR_CORE) += rc-core.o 5obj-$(CONFIG_IR_CORE) += rc-core.o
7obj-$(CONFIG_IR_LEGACY) += ir-common.o
8obj-$(CONFIG_LIRC) += lirc_dev.o 6obj-$(CONFIG_LIRC) += lirc_dev.o
9obj-$(CONFIG_IR_NEC_DECODER) += ir-nec-decoder.o 7obj-$(CONFIG_IR_NEC_DECODER) += ir-nec-decoder.o
10obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o 8obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o
diff --git a/drivers/media/rc/ir-functions.c b/drivers/media/rc/ir-functions.c
deleted file mode 100644
index 14397d0541d8..000000000000
--- a/drivers/media/rc/ir-functions.c
+++ /dev/null
@@ -1,120 +0,0 @@
1/*
2 * some common functions to handle infrared remote protocol decoding for
3 * drivers which have not yet been (or can't be) converted to use the
4 * regular protocol decoders...
5 *
6 * (c) 2003 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/module.h>
24#include <linux/string.h>
25#include <linux/jiffies.h>
26#include <media/ir-common.h>
27#include "rc-core-priv.h"
28
29/* -------------------------------------------------------------------------- */
30
31MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
32MODULE_LICENSE("GPL");
33
34/* RC5 decoding stuff, moved from bttv-input.c to share it with
35 * saa7134 */
36
37/* decode raw bit pattern to RC5 code */
38static u32 ir_rc5_decode(unsigned int code)
39{
40 unsigned int org_code = code;
41 unsigned int pair;
42 unsigned int rc5 = 0;
43 int i;
44
45 for (i = 0; i < 14; ++i) {
46 pair = code & 0x3;
47 code >>= 2;
48
49 rc5 <<= 1;
50 switch (pair) {
51 case 0:
52 case 2:
53 break;
54 case 1:
55 rc5 |= 1;
56 break;
57 case 3:
58 IR_dprintk(1, "ir-common: ir_rc5_decode(%x) bad code\n", org_code);
59 return 0;
60 }
61 }
62 IR_dprintk(1, "ir-common: code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
63 "instr=%x\n", rc5, org_code, RC5_START(rc5),
64 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
65 return rc5;
66}
67
68void ir_rc5_timer_end(unsigned long data)
69{
70 struct card_ir *ir = (struct card_ir *)data;
71 struct timeval tv;
72 unsigned long current_jiffies;
73 u32 gap;
74 u32 rc5 = 0;
75
76 /* get time */
77 current_jiffies = jiffies;
78 do_gettimeofday(&tv);
79
80 /* avoid overflow with gap >1s */
81 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
82 gap = 200000;
83 } else {
84 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
85 tv.tv_usec - ir->base_time.tv_usec;
86 }
87
88 /* signal we're ready to start a new code */
89 ir->active = 0;
90
91 /* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
92 if (gap < 28000) {
93 IR_dprintk(1, "ir-common: spurious timer_end\n");
94 return;
95 }
96
97 if (ir->last_bit < 20) {
98 /* ignore spurious codes (caused by light/other remotes) */
99 IR_dprintk(1, "ir-common: short code: %x\n", ir->code);
100 } else {
101 ir->code = (ir->code << ir->shift_by) | 1;
102 rc5 = ir_rc5_decode(ir->code);
103
104 /* two start bits? */
105 if (RC5_START(rc5) != ir->start) {
106 IR_dprintk(1, "ir-common: rc5 start bits invalid: %u\n", RC5_START(rc5));
107
108 /* right address? */
109 } else if (RC5_ADDR(rc5) == ir->addr) {
110 u32 toggle = RC5_TOGGLE(rc5);
111 u32 instr = RC5_INSTR(rc5);
112
113 /* Good code */
114 ir_keydown(ir->dev, instr, toggle);
115 IR_dprintk(1, "ir-common: instruction %x, toggle %x\n",
116 instr, toggle);
117 }
118 }
119}
120EXPORT_SYMBOL_GPL(ir_rc5_timer_end);
diff --git a/drivers/media/video/bt8xx/Kconfig b/drivers/media/video/bt8xx/Kconfig
index 659e44873440..3c7c0a572c45 100644
--- a/drivers/media/video/bt8xx/Kconfig
+++ b/drivers/media/video/bt8xx/Kconfig
@@ -4,7 +4,7 @@ config VIDEO_BT848
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select VIDEO_BTCX 5 select VIDEO_BTCX
6 select VIDEOBUF_DMA_SG 6 select VIDEOBUF_DMA_SG
7 depends on IR_LEGACY 7 depends on IR_CORE
8 select VIDEO_TUNER 8 select VIDEO_TUNER
9 select VIDEO_TVEEPROM 9 select VIDEO_TVEEPROM
10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO 10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index 4b4f6137c6c5..e8f60ab58db6 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -140,7 +140,100 @@ static void bttv_input_timer(unsigned long data)
140 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); 140 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
141} 141}
142 142
143/* ---------------------------------------------------------------*/ 143/*
144 * FIXME: Nebula digi uses the legacy way to decode RC5, instead of relying
145 * on the rc-core way. As we need to be sure that both IRQ transitions are
146 * properly triggered, Better to touch it only with this hardware for
147 * testing.
148 */
149
150/* decode raw bit pattern to RC5 code */
151static u32 bttv_rc5_decode(unsigned int code)
152{
153 unsigned int org_code = code;
154 unsigned int pair;
155 unsigned int rc5 = 0;
156 int i;
157
158 for (i = 0; i < 14; ++i) {
159 pair = code & 0x3;
160 code >>= 2;
161
162 rc5 <<= 1;
163 switch (pair) {
164 case 0:
165 case 2:
166 break;
167 case 1:
168 rc5 |= 1;
169 break;
170 case 3:
171 dprintk(KERN_INFO DEVNAME ":rc5_decode(%x) bad code\n",
172 org_code);
173 return 0;
174 }
175 }
176 dprintk(KERN_INFO DEVNAME ":"
177 "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
178 "instr=%x\n", rc5, org_code, RC5_START(rc5),
179 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
180 return rc5;
181}
182
183void bttv_rc5_timer_end(unsigned long data)
184{
185 struct card_ir *ir = (struct card_ir *)data;
186 struct timeval tv;
187 unsigned long current_jiffies;
188 u32 gap;
189 u32 rc5 = 0;
190
191 /* get time */
192 current_jiffies = jiffies;
193 do_gettimeofday(&tv);
194
195 /* avoid overflow with gap >1s */
196 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
197 gap = 200000;
198 } else {
199 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
200 tv.tv_usec - ir->base_time.tv_usec;
201 }
202
203 /* signal we're ready to start a new code */
204 ir->active = 0;
205
206 /* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
207 if (gap < 28000) {
208 dprintk(KERN_INFO DEVNAME ": spurious timer_end\n");
209 return;
210 }
211
212 if (ir->last_bit < 20) {
213 /* ignore spurious codes (caused by light/other remotes) */
214 dprintk(KERN_INFO DEVNAME ": short code: %x\n", ir->code);
215 } else {
216 ir->code = (ir->code << ir->shift_by) | 1;
217 rc5 = bttv_rc5_decode(ir->code);
218
219 /* two start bits? */
220 if (RC5_START(rc5) != ir->start) {
221 printk(KERN_INFO DEVNAME ":"
222 " rc5 start bits invalid: %u\n", RC5_START(rc5));
223
224 /* right address? */
225 } else if (RC5_ADDR(rc5) == ir->addr) {
226 u32 toggle = RC5_TOGGLE(rc5);
227 u32 instr = RC5_INSTR(rc5);
228
229 /* Good code */
230 ir_keydown(ir->dev, instr, toggle);
231 dprintk(KERN_INFO DEVNAME ":"
232 " instruction %x, toggle %x\n",
233 instr, toggle);
234 }
235 }
236}
144 237
145static int bttv_rc5_irq(struct bttv *btv) 238static int bttv_rc5_irq(struct bttv *btv)
146{ 239{
@@ -206,7 +299,7 @@ static void bttv_ir_start(struct bttv *btv, struct card_ir *ir)
206 } else if (ir->rc5_gpio) { 299 } else if (ir->rc5_gpio) {
207 /* set timer_end for code completion */ 300 /* set timer_end for code completion */
208 init_timer(&ir->timer_end); 301 init_timer(&ir->timer_end);
209 ir->timer_end.function = ir_rc5_timer_end; 302 ir->timer_end.function = bttv_rc5_timer_end;
210 ir->timer_end.data = (unsigned long)ir; 303 ir->timer_end.data = (unsigned long)ir;
211 ir->shift_by = 1; 304 ir->shift_by = 1;
212 ir->start = 3; 305 ir->start = 3;
@@ -283,10 +376,10 @@ void __devinit init_bttv_i2c_ir(struct bttv *btv)
283 default: 376 default:
284 /* 377 /*
285 * The external IR receiver is at i2c address 0x34 (0x35 for 378 * The external IR receiver is at i2c address 0x34 (0x35 for
286 * reads). Future Hauppauge cards will have an internal 379 * reads). Future Hauppauge cards will have an internal
287 * receiver at 0x30 (0x31 for reads). In theory, both can be 380 * receiver at 0x30 (0x31 for reads). In theory, both can be
288 * fitted, and Hauppauge suggest an external overrides an 381 * fitted, and Hauppauge suggest an external overrides an
289 * internal. 382 * internal.
290 * That's why we probe 0x1a (~0x34) first. CB 383 * That's why we probe 0x1a (~0x34) first. CB
291 */ 384 */
292 385
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index 32a95a2d66a1..e03bff9e4246 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -26,7 +26,7 @@ config VIDEO_SAA7134_ALSA
26 26
27config VIDEO_SAA7134_RC 27config VIDEO_SAA7134_RC
28 bool "Philips SAA7134 Remote Controller support" 28 bool "Philips SAA7134 Remote Controller support"
29 depends on IR_LEGACY 29 depends on IR_CORE
30 depends on VIDEO_SAA7134 30 depends on VIDEO_SAA7134
31 default y 31 default y
32 ---help--- 32 ---help---
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index fbb2ff171008..72562b8cf3be 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -54,11 +54,8 @@ MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
54#define i2cdprintk(fmt, arg...) if (ir_debug) \ 54#define i2cdprintk(fmt, arg...) if (ir_debug) \
55 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg) 55 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg)
56 56
57/* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */ 57/* Helper function for raw decoding at GPIO16 or GPIO18 */
58static int saa7134_rc5_irq(struct saa7134_dev *dev);
59static int saa7134_nec_irq(struct saa7134_dev *dev);
60static int saa7134_raw_decode_irq(struct saa7134_dev *dev); 58static int saa7134_raw_decode_irq(struct saa7134_dev *dev);
61static void nec_task(unsigned long data);
62 59
63/* -------------------- GPIO generic keycode builder -------------------- */ 60/* -------------------- GPIO generic keycode builder -------------------- */
64 61
@@ -397,12 +394,8 @@ void saa7134_input_irq(struct saa7134_dev *dev)
397 if (!ir->running) 394 if (!ir->running)
398 return; 395 return;
399 396
400 if (ir->nec_gpio) { 397 if (!ir->polling && !ir->raw_decode) {
401 saa7134_nec_irq(dev);
402 } else if (!ir->polling && !ir->rc5_gpio && !ir->raw_decode) {
403 build_key(dev); 398 build_key(dev);
404 } else if (ir->rc5_gpio) {
405 saa7134_rc5_irq(dev);
406 } else if (ir->raw_decode) { 399 } else if (ir->raw_decode) {
407 saa7134_raw_decode_irq(dev); 400 saa7134_raw_decode_irq(dev);
408 } 401 }
@@ -448,17 +441,6 @@ static int __saa7134_ir_start(void *priv)
448 (unsigned long)dev); 441 (unsigned long)dev);
449 ir->timer.expires = jiffies + HZ; 442 ir->timer.expires = jiffies + HZ;
450 add_timer(&ir->timer); 443 add_timer(&ir->timer);
451 } else if (ir->rc5_gpio) {
452 /* set timer_end for code completion */
453 init_timer(&ir->timer_end);
454 ir->timer_end.function = ir_rc5_timer_end;
455 ir->timer_end.data = (unsigned long)ir;
456 ir->shift_by = 2;
457 ir->start = 0x2;
458 ir->addr = 0x17;
459 ir->rc5_remote_gap = ir_rc5_remote_gap;
460 } else if (ir->nec_gpio) {
461 tasklet_init(&ir->tlet, nec_task, (unsigned long)dev);
462 } else if (ir->raw_decode) { 444 } else if (ir->raw_decode) {
463 /* set timer_end for code completion */ 445 /* set timer_end for code completion */
464 init_timer(&ir->timer_end); 446 init_timer(&ir->timer_end);
@@ -486,10 +468,6 @@ static void __saa7134_ir_stop(void *priv)
486 return; 468 return;
487 if (dev->remote->polling) 469 if (dev->remote->polling)
488 del_timer_sync(&dev->remote->timer); 470 del_timer_sync(&dev->remote->timer);
489 else if (ir->rc5_gpio)
490 del_timer_sync(&ir->timer_end);
491 else if (ir->nec_gpio)
492 tasklet_kill(&ir->tlet);
493 else if (ir->raw_decode) { 471 else if (ir->raw_decode) {
494 del_timer_sync(&ir->timer_end); 472 del_timer_sync(&ir->timer_end);
495 ir->active = 0; 473 ir->active = 0;
@@ -531,40 +509,6 @@ static void saa7134_ir_close(struct rc_dev *rc)
531 __saa7134_ir_stop(dev); 509 __saa7134_ir_stop(dev);
532} 510}
533 511
534
535static int saa7134_ir_change_protocol(struct rc_dev *rc, u64 ir_type)
536{
537 struct saa7134_dev *dev = rc->priv;
538 struct card_ir *ir = dev->remote;
539 u32 nec_gpio, rc5_gpio;
540
541 if (ir_type == IR_TYPE_RC5) {
542 dprintk("Changing protocol to RC5\n");
543 nec_gpio = 0;
544 rc5_gpio = 1;
545 } else if (ir_type == IR_TYPE_NEC) {
546 dprintk("Changing protocol to NEC\n");
547 nec_gpio = 1;
548 rc5_gpio = 0;
549 } else {
550 dprintk("IR protocol type %ud is not supported\n",
551 (unsigned)ir_type);
552 return -EINVAL;
553 }
554
555 if (ir->running) {
556 saa7134_ir_stop(dev);
557 ir->nec_gpio = nec_gpio;
558 ir->rc5_gpio = rc5_gpio;
559 saa7134_ir_start(dev);
560 } else {
561 ir->nec_gpio = nec_gpio;
562 ir->rc5_gpio = rc5_gpio;
563 }
564
565 return 0;
566}
567
568int saa7134_input_init1(struct saa7134_dev *dev) 512int saa7134_input_init1(struct saa7134_dev *dev)
569{ 513{
570 struct card_ir *ir; 514 struct card_ir *ir;
@@ -574,10 +518,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
574 u32 mask_keydown = 0; 518 u32 mask_keydown = 0;
575 u32 mask_keyup = 0; 519 u32 mask_keyup = 0;
576 int polling = 0; 520 int polling = 0;
577 int rc5_gpio = 0;
578 int nec_gpio = 0;
579 int raw_decode = 0; 521 int raw_decode = 0;
580 int allow_protocol_change = 0;
581 int err; 522 int err;
582 523
583 if (dev->has_remote != SAA7134_REMOTE_GPIO) 524 if (dev->has_remote != SAA7134_REMOTE_GPIO)
@@ -767,9 +708,10 @@ int saa7134_input_init1(struct saa7134_dev *dev)
767 break; 708 break;
768 case SAA7134_BOARD_ENCORE_ENLTV_FM53: 709 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
769 ir_codes = RC_MAP_ENCORE_ENLTV_FM53; 710 ir_codes = RC_MAP_ENCORE_ENLTV_FM53;
770 mask_keydown = 0x0040000; 711 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
771 mask_keycode = 0x00007f; 712 mask_keyup = 0x0040000;
772 nec_gpio = 1; 713 mask_keycode = 0xffff;
714 raw_decode = 1;
773 break; 715 break;
774 case SAA7134_BOARD_10MOONSTVMASTER3: 716 case SAA7134_BOARD_10MOONSTVMASTER3:
775 ir_codes = RC_MAP_ENCORE_ENLTV; 717 ir_codes = RC_MAP_ENCORE_ENLTV;
@@ -829,8 +771,6 @@ int saa7134_input_init1(struct saa7134_dev *dev)
829 ir->mask_keydown = mask_keydown; 771 ir->mask_keydown = mask_keydown;
830 ir->mask_keyup = mask_keyup; 772 ir->mask_keyup = mask_keyup;
831 ir->polling = polling; 773 ir->polling = polling;
832 ir->rc5_gpio = rc5_gpio;
833 ir->nec_gpio = nec_gpio;
834 ir->raw_decode = raw_decode; 774 ir->raw_decode = raw_decode;
835 775
836 /* init input device */ 776 /* init input device */
@@ -845,11 +785,6 @@ int saa7134_input_init1(struct saa7134_dev *dev)
845 if (raw_decode) 785 if (raw_decode)
846 rc->driver_type = RC_DRIVER_IR_RAW; 786 rc->driver_type = RC_DRIVER_IR_RAW;
847 787
848 if (!raw_decode && allow_protocol_change) {
849 rc->allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC;
850 rc->change_protocol = saa7134_ir_change_protocol;
851 }
852
853 rc->input_name = ir->name; 788 rc->input_name = ir->name;
854 rc->input_phys = ir->phys; 789 rc->input_phys = ir->phys;
855 rc->input_id.bustype = BUS_PCI; 790 rc->input_id.bustype = BUS_PCI;
@@ -1023,152 +958,3 @@ static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
1023 958
1024 return 1; 959 return 1;
1025} 960}
1026
1027static int saa7134_rc5_irq(struct saa7134_dev *dev)
1028{
1029 struct card_ir *ir = dev->remote;
1030 struct timeval tv;
1031 u32 gap;
1032 unsigned long current_jiffies, timeout;
1033
1034 /* get time of bit */
1035 current_jiffies = jiffies;
1036 do_gettimeofday(&tv);
1037
1038 /* avoid overflow with gap >1s */
1039 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
1040 gap = 200000;
1041 } else {
1042 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
1043 tv.tv_usec - ir->base_time.tv_usec;
1044 }
1045
1046 /* active code => add bit */
1047 if (ir->active) {
1048 /* only if in the code (otherwise spurious IRQ or timer
1049 late) */
1050 if (ir->last_bit < 28) {
1051 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
1052 ir_rc5_remote_gap;
1053 ir->code |= 1 << ir->last_bit;
1054 }
1055 /* starting new code */
1056 } else {
1057 ir->active = 1;
1058 ir->code = 0;
1059 ir->base_time = tv;
1060 ir->last_bit = 0;
1061
1062 timeout = current_jiffies + (500 + 30 * HZ) / 1000;
1063 mod_timer(&ir->timer_end, timeout);
1064 }
1065
1066 return 1;
1067}
1068
1069static void nec_task(unsigned long data)
1070{
1071 struct saa7134_dev *dev = (struct saa7134_dev *) data;
1072 struct card_ir *ir;
1073 struct timeval tv;
1074 int count, pulse, oldpulse, gap;
1075 u32 ircode = 0, not_code = 0;
1076 int ngap = 0;
1077
1078 if (!data) {
1079 printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n");
1080 /* GPIO will be kept disabled */
1081 return;
1082 }
1083
1084 ir = dev->remote;
1085
1086 /* rising SAA7134_GPIO_GPRESCAN reads the status */
1087 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1088 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1089
1090 oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
1091 pulse = oldpulse;
1092
1093 do_gettimeofday(&tv);
1094 ir->base_time = tv;
1095
1096 /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
1097 Unfortunately, using IRQ to decode pulse didn't work, since it uses
1098 a pulse train of 38KHz. This means one pulse on each 52 us
1099 */
1100 do {
1101 /* Wait until the end of pulse/space or 5 ms */
1102 for (count = 0; count < 500; count++) {
1103 udelay(10);
1104 /* rising SAA7134_GPIO_GPRESCAN reads the status */
1105 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1106 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1107 pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)
1108 & ir->mask_keydown;
1109 if (pulse != oldpulse)
1110 break;
1111 }
1112
1113 do_gettimeofday(&tv);
1114 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
1115 tv.tv_usec - ir->base_time.tv_usec;
1116
1117 if (!pulse) {
1118 /* Bit 0 has 560 us, while bit 1 has 1120 us.
1119 Do something only if bit == 1
1120 */
1121 if (ngap && (gap > 560 + 280)) {
1122 unsigned int shift = ngap - 1;
1123
1124 /* Address first, then command */
1125 if (shift < 8) {
1126 shift += 8;
1127 ircode |= 1 << shift;
1128 } else if (shift < 16) {
1129 not_code |= 1 << shift;
1130 } else if (shift < 24) {
1131 shift -= 16;
1132 ircode |= 1 << shift;
1133 } else {
1134 shift -= 24;
1135 not_code |= 1 << shift;
1136 }
1137 }
1138 ngap++;
1139 }
1140
1141
1142 ir->base_time = tv;
1143
1144 /* TIMEOUT - Long pulse */
1145 if (gap >= 5000)
1146 break;
1147 oldpulse = pulse;
1148 } while (ngap < 32);
1149
1150 if (ngap == 32) {
1151 /* FIXME: should check if not_code == ~ircode */
1152 ir->code = ir_extract_bits(ircode, ir->mask_keycode);
1153
1154 dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
1155 ir->code, ircode, not_code);
1156
1157 ir_keydown(ir->dev, ir->code, 0);
1158 } else {
1159 dprintk("Repeat last key\n");
1160 ir_repeat(ir->dev);
1161 }
1162
1163 saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
1164}
1165
1166static int saa7134_nec_irq(struct saa7134_dev *dev)
1167{
1168 struct card_ir *ir = dev->remote;
1169
1170 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
1171 tasklet_schedule(&ir->tlet);
1172
1173 return 1;
1174}
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 4e37b8bfb6fa..a6c726fe4c5d 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -37,7 +37,7 @@
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-device.h> 38#include <media/v4l2-device.h>
39#include <media/tuner.h> 39#include <media/tuner.h>
40#include <media/ir-common.h> 40#include <media/ir-core.h>
41#include <media/ir-kbd-i2c.h> 41#include <media/ir-kbd-i2c.h>
42#include <media/videobuf-dma-sg.h> 42#include <media/videobuf-dma-sg.h>
43#include <sound/core.h> 43#include <sound/core.h>