3 * handle saa7134 IR remotes via linux kernel input layer.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/delay.h>
24 #include <linux/interrupt.h>
25 #include <linux/input.h>
27 #include "saa7134-reg.h"
30 static unsigned int disable_ir;
31 module_param(disable_ir, int, 0444);
32 MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
34 static unsigned int ir_debug;
35 module_param(ir_debug, int, 0644);
36 MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
38 static int pinnacle_remote;
39 module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */
40 MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
42 static int ir_rc5_remote_gap = 885;
43 module_param(ir_rc5_remote_gap, int, 0644);
44 static int ir_rc5_key_timeout = 115;
45 module_param(ir_rc5_key_timeout, int, 0644);
47 static int repeat_delay = 500;
48 module_param(repeat_delay, int, 0644);
49 MODULE_PARM_DESC(repeat_delay, "delay before key repeat started");
50 static int repeat_period = 33;
51 module_param(repeat_period, int, 0644);
52 MODULE_PARM_DESC(repeat_period, "repeat period between "
53 "keypresses when key is down");
55 static unsigned int disable_other_ir;
56 module_param(disable_other_ir, int, 0644);
57 MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
58 "alternative remotes from other manufacturers");
60 #define dprintk(fmt, arg...) if (ir_debug) \
61 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
62 #define i2cdprintk(fmt, arg...) if (ir_debug) \
63 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
65 /* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */
66 static int saa7134_rc5_irq(struct saa7134_dev *dev);
67 static int saa7134_nec_irq(struct saa7134_dev *dev);
68 static void nec_task(unsigned long data);
69 static void saa7134_nec_timer(unsigned long data);
71 /* -------------------- GPIO generic keycode builder -------------------- */
73 static int build_key(struct saa7134_dev *dev)
75 struct card_ir *ir = dev->remote;
78 /* here comes the additional handshake steps for some cards */
80 case SAA7134_BOARD_GOTVIEW_7135:
81 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x80);
82 saa_clearb(SAA7134_GPIO_GPSTATUS1, 0x80);
85 /* rising SAA7134_GPIO_GPRESCAN reads the status */
86 saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
87 saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
89 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
91 if (ir->last_gpio == gpio)
96 data = ir_extract_bits(gpio, ir->mask_keycode);
97 dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
98 gpio, ir->mask_keycode, data);
101 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
102 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
103 ir_input_keydown(ir->dev, &ir->ir, data, data);
105 ir_input_nokey(ir->dev, &ir->ir);
108 else { /* IRQ driven mode - handle key press and release in one go */
109 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
110 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
111 ir_input_keydown(ir->dev, &ir->ir, data, data);
112 ir_input_nokey(ir->dev, &ir->ir);
119 /* --------------------- Chip specific I2C key builders ----------------- */
121 static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
126 if (1 != i2c_master_recv(&ir->c,&b,1)) {
127 i2cdprintk("read error\n");
131 /* no button press */
144 static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
146 unsigned char buf[5], cod4, code3, code4;
149 if (5 != i2c_master_recv(&ir->c,buf,5))
166 static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
168 unsigned char data[12];
171 struct saa7134_dev *dev = ir->c.adapter->algo_data;
173 /* rising SAA7134_GPIO_GPRESCAN reads the status */
174 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
175 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
177 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
179 if (0x400000 & ~gpio)
180 return 0; /* No button press */
182 ir->c.addr = 0x5a >> 1;
184 if (12 != i2c_master_recv(&ir->c, data, 12)) {
185 i2cdprintk("read error\n");
188 /* IR of this card normally decode signals NEC-standard from
189 * - Sven IHOO MT 5.1R remote. xxyye718
190 * - Sven DVD HD-10xx remote. xxyyf708
193 * So, skip not our, if disable full codes mode.
195 if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir)
204 /* Common (grey or coloured) pinnacle PCTV remote handling
207 static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
208 int parity_offset, int marker, int code_modulo)
211 unsigned int start = 0,parity = 0,code = 0;
214 if (4 != i2c_master_recv(&ir->c, b, 4)) {
215 i2cdprintk("read error\n");
219 for (start = 0; start < ARRAY_SIZE(b); start++) {
220 if (b[start] == marker) {
221 code=b[(start+parity_offset + 1) % 4];
222 parity=b[(start+parity_offset) % 4];
231 if (ir->old == parity)
236 /* drop special codes when a key is held down a long time for the grey controller
237 In this case, the second bit of the code is asserted */
238 if (marker == 0xfe && (code & 0x40))
246 i2cdprintk("Pinnacle PCTV key %02x\n", code);
251 /* The grey pinnacle PCTV remote
253 * There are one issue with this remote:
254 * - I2c packet does not change when the same key is pressed quickly. The workaround
255 * is to hold down each key for about half a second, so that another code is generated
256 * in the i2c packet, and the function can distinguish key presses.
258 * Sylvain Pasche <sylvain.pasche@gmail.com>
260 static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
263 return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff);
267 /* The new pinnacle PCTV remote (with the colored buttons)
269 * Ricardo Cerqueira <v4l@cerqueira.org>
271 static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
273 /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
275 * this is the only value that results in 42 unique
279 return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88);
282 void saa7134_input_irq(struct saa7134_dev *dev)
284 struct card_ir *ir = dev->remote;
287 saa7134_nec_irq(dev);
288 } else if (!ir->polling && !ir->rc5_gpio) {
290 } else if (ir->rc5_gpio) {
291 saa7134_rc5_irq(dev);
295 static void saa7134_input_timer(unsigned long data)
297 struct saa7134_dev *dev = (struct saa7134_dev *)data;
298 struct card_ir *ir = dev->remote;
301 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
304 void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
307 setup_timer(&ir->timer, saa7134_input_timer,
309 ir->timer.expires = jiffies + HZ;
310 add_timer(&ir->timer);
311 } else if (ir->rc5_gpio) {
312 /* set timer_end for code completion */
313 init_timer(&ir->timer_end);
314 ir->timer_end.function = ir_rc5_timer_end;
315 ir->timer_end.data = (unsigned long)ir;
316 init_timer(&ir->timer_keyup);
317 ir->timer_keyup.function = ir_rc5_timer_keyup;
318 ir->timer_keyup.data = (unsigned long)ir;
322 ir->rc5_key_timeout = ir_rc5_key_timeout;
323 ir->rc5_remote_gap = ir_rc5_remote_gap;
324 } else if (ir->nec_gpio) {
325 setup_timer(&ir->timer_keyup, saa7134_nec_timer,
327 tasklet_init(&ir->tlet, nec_task, (unsigned long)dev);
331 void saa7134_ir_stop(struct saa7134_dev *dev)
333 if (dev->remote->polling)
334 del_timer_sync(&dev->remote->timer);
337 int saa7134_input_init1(struct saa7134_dev *dev)
340 struct input_dev *input_dev;
341 IR_KEYTAB_TYPE *ir_codes = NULL;
342 u32 mask_keycode = 0;
343 u32 mask_keydown = 0;
348 int ir_type = IR_TYPE_OTHER;
351 if (dev->has_remote != SAA7134_REMOTE_GPIO)
356 /* detect & configure */
357 switch (dev->board) {
358 case SAA7134_BOARD_FLYVIDEO2000:
359 case SAA7134_BOARD_FLYVIDEO3000:
360 case SAA7134_BOARD_FLYTVPLATINUM_FM:
361 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
362 ir_codes = ir_codes_flyvideo;
363 mask_keycode = 0xEC00000;
364 mask_keydown = 0x0040000;
366 case SAA7134_BOARD_CINERGY400:
367 case SAA7134_BOARD_CINERGY600:
368 case SAA7134_BOARD_CINERGY600_MK3:
369 ir_codes = ir_codes_cinergy;
370 mask_keycode = 0x00003f;
371 mask_keyup = 0x040000;
373 case SAA7134_BOARD_ECS_TVP3XP:
374 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
375 ir_codes = ir_codes_eztv;
376 mask_keycode = 0x00017c;
377 mask_keyup = 0x000002;
380 case SAA7134_BOARD_KWORLD_XPERT:
381 case SAA7134_BOARD_AVACSSMARTTV:
382 ir_codes = ir_codes_pixelview;
383 mask_keycode = 0x00001F;
384 mask_keyup = 0x000020;
387 case SAA7134_BOARD_MD2819:
388 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
389 case SAA7134_BOARD_AVERMEDIA_305:
390 case SAA7134_BOARD_AVERMEDIA_307:
391 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
392 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
393 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
394 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
395 case SAA7134_BOARD_AVERMEDIA_M102:
396 ir_codes = ir_codes_avermedia;
397 mask_keycode = 0x0007C8;
398 mask_keydown = 0x000010;
400 /* Set GPIO pin2 to high to enable the IR controller */
401 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
402 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
404 case SAA7134_BOARD_AVERMEDIA_777:
405 case SAA7134_BOARD_AVERMEDIA_A16AR:
406 ir_codes = ir_codes_avermedia;
407 mask_keycode = 0x02F200;
408 mask_keydown = 0x000400;
410 /* Without this we won't receive key up events */
411 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
412 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
414 case SAA7134_BOARD_AVERMEDIA_A16D:
415 ir_codes = ir_codes_avermedia_a16d;
416 mask_keycode = 0x02F200;
417 mask_keydown = 0x000400;
418 polling = 50; /* ms */
419 /* Without this we won't receive key up events */
420 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
421 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
423 case SAA7134_BOARD_KWORLD_TERMINATOR:
424 ir_codes = ir_codes_pixelview;
425 mask_keycode = 0x00001f;
426 mask_keyup = 0x000060;
429 case SAA7134_BOARD_MANLI_MTV001:
430 case SAA7134_BOARD_MANLI_MTV002:
431 ir_codes = ir_codes_manli;
432 mask_keycode = 0x001f00;
433 mask_keyup = 0x004000;
434 polling = 50; /* ms */
436 case SAA7134_BOARD_BEHOLD_409FM:
437 case SAA7134_BOARD_BEHOLD_401:
438 case SAA7134_BOARD_BEHOLD_403:
439 case SAA7134_BOARD_BEHOLD_403FM:
440 case SAA7134_BOARD_BEHOLD_405:
441 case SAA7134_BOARD_BEHOLD_405FM:
442 case SAA7134_BOARD_BEHOLD_407:
443 case SAA7134_BOARD_BEHOLD_407FM:
444 case SAA7134_BOARD_BEHOLD_409:
445 case SAA7134_BOARD_BEHOLD_505FM:
446 case SAA7134_BOARD_BEHOLD_507_9FM:
447 ir_codes = ir_codes_manli;
448 mask_keycode = 0x003f00;
449 mask_keyup = 0x004000;
450 polling = 50; /* ms */
452 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
453 ir_codes = ir_codes_behold_columbus;
454 mask_keycode = 0x003f00;
455 mask_keyup = 0x004000;
458 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
459 ir_codes = ir_codes_pctv_sedna;
460 mask_keycode = 0x001f00;
461 mask_keyup = 0x004000;
464 case SAA7134_BOARD_GOTVIEW_7135:
465 ir_codes = ir_codes_gotview7135;
466 mask_keycode = 0x0003CC;
467 mask_keydown = 0x000010;
468 polling = 5; /* ms */
469 saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
471 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
472 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
473 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
474 ir_codes = ir_codes_videomate_tv_pvr;
475 mask_keycode = 0x00003F;
476 mask_keyup = 0x400000;
479 case SAA7134_BOARD_PROTEUS_2309:
480 ir_codes = ir_codes_proteus_2309;
481 mask_keycode = 0x00007F;
482 mask_keyup = 0x000080;
485 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
486 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
487 ir_codes = ir_codes_videomate_tv_pvr;
488 mask_keycode = 0x003F00;
489 mask_keyup = 0x040000;
491 case SAA7134_BOARD_FLYDVBS_LR300:
492 case SAA7134_BOARD_FLYDVBT_LR301:
493 case SAA7134_BOARD_FLYDVBTDUO:
494 ir_codes = ir_codes_flydvb;
495 mask_keycode = 0x0001F00;
496 mask_keydown = 0x0040000;
498 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
499 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
500 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
501 ir_codes = ir_codes_asus_pc39;
502 mask_keydown = 0x0040000;
505 case SAA7134_BOARD_ENCORE_ENLTV:
506 case SAA7134_BOARD_ENCORE_ENLTV_FM:
507 ir_codes = ir_codes_encore_enltv;
508 mask_keycode = 0x00007f;
509 mask_keyup = 0x040000;
512 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
513 ir_codes = ir_codes_encore_enltv_fm53;
514 mask_keydown = 0x0040000;
515 mask_keycode = 0x00007f;
518 case SAA7134_BOARD_10MOONSTVMASTER3:
519 ir_codes = ir_codes_encore_enltv;
520 mask_keycode = 0x5f80000;
521 mask_keyup = 0x8000000;
524 case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
525 ir_codes = ir_codes_genius_tvgo_a11mce;
527 mask_keydown = 0xf00000;
528 polling = 50; /* ms */
531 if (NULL == ir_codes) {
532 printk("%s: Oops: IR config error [card=%d]\n",
533 dev->name, dev->board);
537 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
538 input_dev = input_allocate_device();
539 if (!ir || !input_dev) {
546 /* init hardware-specific stuff */
547 ir->mask_keycode = mask_keycode;
548 ir->mask_keydown = mask_keydown;
549 ir->mask_keyup = mask_keyup;
550 ir->polling = polling;
551 ir->rc5_gpio = rc5_gpio;
552 ir->nec_gpio = nec_gpio;
554 /* init input device */
555 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
556 saa7134_boards[dev->board].name);
557 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
560 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
561 input_dev->name = ir->name;
562 input_dev->phys = ir->phys;
563 input_dev->id.bustype = BUS_PCI;
564 input_dev->id.version = 1;
565 if (dev->pci->subsystem_vendor) {
566 input_dev->id.vendor = dev->pci->subsystem_vendor;
567 input_dev->id.product = dev->pci->subsystem_device;
569 input_dev->id.vendor = dev->pci->vendor;
570 input_dev->id.product = dev->pci->device;
572 input_dev->dev.parent = &dev->pci->dev;
575 saa7134_ir_start(dev, ir);
577 err = input_register_device(ir->dev);
581 /* the remote isn't as bouncy as a keyboard */
582 ir->dev->rep[REP_DELAY] = repeat_delay;
583 ir->dev->rep[REP_PERIOD] = repeat_period;
588 saa7134_ir_stop(dev);
591 input_free_device(input_dev);
596 void saa7134_input_fini(struct saa7134_dev *dev)
598 if (NULL == dev->remote)
601 saa7134_ir_stop(dev);
602 input_unregister_device(dev->remote->dev);
607 void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
610 dprintk("Found supported i2c remote, but IR has been disabled\n");
615 switch (dev->board) {
616 case SAA7134_BOARD_PINNACLE_PCTV_110i:
617 case SAA7134_BOARD_PINNACLE_PCTV_310i:
618 snprintf(ir->c.name, sizeof(ir->c.name), "Pinnacle PCTV");
619 if (pinnacle_remote == 0) {
620 ir->get_key = get_key_pinnacle_color;
621 ir->ir_codes = ir_codes_pinnacle_color;
623 ir->get_key = get_key_pinnacle_grey;
624 ir->ir_codes = ir_codes_pinnacle_grey;
627 case SAA7134_BOARD_UPMOST_PURPLE_TV:
628 snprintf(ir->c.name, sizeof(ir->c.name), "Purple TV");
629 ir->get_key = get_key_purpletv;
630 ir->ir_codes = ir_codes_purpletv;
632 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
633 snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110");
634 ir->get_key = get_key_hvr1110;
635 ir->ir_codes = ir_codes_hauppauge_new;
637 case SAA7134_BOARD_BEHOLD_607_9FM:
638 case SAA7134_BOARD_BEHOLD_M6:
639 case SAA7134_BOARD_BEHOLD_M63:
640 case SAA7134_BOARD_BEHOLD_M6_EXTRA:
641 case SAA7134_BOARD_BEHOLD_H6:
642 snprintf(ir->c.name, sizeof(ir->c.name), "BeholdTV");
643 ir->get_key = get_key_beholdm6xx;
644 ir->ir_codes = ir_codes_behold;
647 dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board);
653 static int saa7134_rc5_irq(struct saa7134_dev *dev)
655 struct card_ir *ir = dev->remote;
658 unsigned long current_jiffies, timeout;
660 /* get time of bit */
661 current_jiffies = jiffies;
662 do_gettimeofday(&tv);
664 /* avoid overflow with gap >1s */
665 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
668 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
669 tv.tv_usec - ir->base_time.tv_usec;
672 /* active code => add bit */
674 /* only if in the code (otherwise spurious IRQ or timer
676 if (ir->last_bit < 28) {
677 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
679 ir->code |= 1 << ir->last_bit;
681 /* starting new code */
688 timeout = current_jiffies + (500 + 30 * HZ) / 1000;
689 mod_timer(&ir->timer_end, timeout);
696 /* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
697 The first pulse (start) has 9 + 4.5 ms
700 static void saa7134_nec_timer(unsigned long data)
702 struct saa7134_dev *dev = (struct saa7134_dev *) data;
703 struct card_ir *ir = dev->remote;
705 dprintk("Cancel key repeat\n");
707 ir_input_nokey(ir->dev, &ir->ir);
710 static void nec_task(unsigned long data)
712 struct saa7134_dev *dev = (struct saa7134_dev *) data;
715 int count, pulse, oldpulse, gap;
716 u32 ircode = 0, not_code = 0;
720 printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n");
721 /* GPIO will be kept disabled */
727 /* rising SAA7134_GPIO_GPRESCAN reads the status */
728 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
729 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
731 oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
734 do_gettimeofday(&tv);
737 /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
738 Unfortunately, using IRQ to decode pulse didn't work, since it uses
739 a pulse train of 38KHz. This means one pulse on each 52 us
742 /* Wait until the end of pulse/space or 5 ms */
743 for (count = 0; count < 500; count++) {
745 /* rising SAA7134_GPIO_GPRESCAN reads the status */
746 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
747 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
748 pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)
750 if (pulse != oldpulse)
754 do_gettimeofday(&tv);
755 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
756 tv.tv_usec - ir->base_time.tv_usec;
759 /* Bit 0 has 560 us, while bit 1 has 1120 us.
760 Do something only if bit == 1
762 if (ngap && (gap > 560 + 280)) {
763 unsigned int shift = ngap - 1;
765 /* Address first, then command */
768 ircode |= 1 << shift;
769 } else if (shift < 16) {
770 not_code |= 1 << shift;
771 } else if (shift < 24) {
773 ircode |= 1 << shift;
776 not_code |= 1 << shift;
785 /* TIMEOUT - Long pulse */
792 /* FIXME: should check if not_code == ~ircode */
793 ir->code = ir_extract_bits(ircode, ir->mask_keycode);
795 dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
796 ir->code, ircode, not_code);
798 ir_input_keydown(ir->dev, &ir->ir, ir->code, ir->code);
800 dprintk("Repeat last key\n");
802 /* Keep repeating the last key */
803 mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150));
805 saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
808 static int saa7134_nec_irq(struct saa7134_dev *dev)
810 struct card_ir *ir = dev->remote;
812 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
813 tasklet_schedule(&ir->tlet);