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>
26 #include <linux/slab.h>
28 #include "saa7134-reg.h"
31 static unsigned int disable_ir
;
32 module_param(disable_ir
, int, 0444);
33 MODULE_PARM_DESC(disable_ir
,"disable infrared remote support");
35 static unsigned int ir_debug
;
36 module_param(ir_debug
, int, 0644);
37 MODULE_PARM_DESC(ir_debug
,"enable debug messages [IR]");
39 static int pinnacle_remote
;
40 module_param(pinnacle_remote
, int, 0644); /* Choose Pinnacle PCTV remote */
41 MODULE_PARM_DESC(pinnacle_remote
, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
43 static int ir_rc5_remote_gap
= 885;
44 module_param(ir_rc5_remote_gap
, int, 0644);
45 static int ir_rc5_key_timeout
= 115;
46 module_param(ir_rc5_key_timeout
, int, 0644);
48 static int repeat_delay
= 500;
49 module_param(repeat_delay
, int, 0644);
50 MODULE_PARM_DESC(repeat_delay
, "delay before key repeat started");
51 static int repeat_period
= 33;
52 module_param(repeat_period
, int, 0644);
53 MODULE_PARM_DESC(repeat_period
, "repeat period between "
54 "keypresses when key is down");
56 static unsigned int disable_other_ir
;
57 module_param(disable_other_ir
, int, 0644);
58 MODULE_PARM_DESC(disable_other_ir
, "disable full codes of "
59 "alternative remotes from other manufacturers");
61 #define dprintk(fmt, arg...) if (ir_debug) \
62 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
63 #define i2cdprintk(fmt, arg...) if (ir_debug) \
64 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg)
66 /* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */
67 static int saa7134_rc5_irq(struct saa7134_dev
*dev
);
68 static int saa7134_nec_irq(struct saa7134_dev
*dev
);
69 static void nec_task(unsigned long data
);
70 static void saa7134_nec_timer(unsigned long data
);
72 /* -------------------- GPIO generic keycode builder -------------------- */
74 static int build_key(struct saa7134_dev
*dev
)
76 struct card_ir
*ir
= dev
->remote
;
79 /* here comes the additional handshake steps for some cards */
81 case SAA7134_BOARD_GOTVIEW_7135
:
82 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x80);
83 saa_clearb(SAA7134_GPIO_GPSTATUS1
, 0x80);
86 /* rising SAA7134_GPIO_GPRESCAN reads the status */
87 saa_clearb(SAA7134_GPIO_GPMODE3
,SAA7134_GPIO_GPRESCAN
);
88 saa_setb(SAA7134_GPIO_GPMODE3
,SAA7134_GPIO_GPRESCAN
);
90 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
92 if (ir
->last_gpio
== gpio
)
97 data
= ir_extract_bits(gpio
, ir
->mask_keycode
);
98 dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
99 gpio
, ir
->mask_keycode
, data
);
101 switch (dev
->board
) {
102 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG
:
103 if (data
== ir
->mask_keycode
)
104 ir_input_nokey(ir
->dev
, &ir
->ir
);
106 ir_input_keydown(ir
->dev
, &ir
->ir
, data
);
111 if ((ir
->mask_keydown
&& (0 != (gpio
& ir
->mask_keydown
))) ||
112 (ir
->mask_keyup
&& (0 == (gpio
& ir
->mask_keyup
)))) {
113 ir_input_keydown(ir
->dev
, &ir
->ir
, data
);
115 ir_input_nokey(ir
->dev
, &ir
->ir
);
118 else { /* IRQ driven mode - handle key press and release in one go */
119 if ((ir
->mask_keydown
&& (0 != (gpio
& ir
->mask_keydown
))) ||
120 (ir
->mask_keyup
&& (0 == (gpio
& ir
->mask_keyup
)))) {
121 ir_input_keydown(ir
->dev
, &ir
->ir
, data
);
122 ir_input_nokey(ir
->dev
, &ir
->ir
);
129 /* --------------------- Chip specific I2C key builders ----------------- */
131 static int get_key_flydvb_trio(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
137 /* We need this to access GPI Used by the saa_readl macro. */
138 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
141 dprintk("get_key_flydvb_trio: "
142 "gir->c->adapter->algo_data is NULL!\n");
146 /* rising SAA7134_GPIGPRESCAN reads the status */
147 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
148 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
150 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
153 return 0; /* No button press */
155 /* No button press - only before first key pressed */
160 /* weak up the IR chip */
163 while (1 != i2c_master_send(ir
->c
, &b
, 1)) {
164 if ((attempt
++) < 10) {
166 * wait a bit for next attempt -
167 * I don't know how make it better
172 i2cdprintk("send wake up byte to pic16C505 (IR chip)"
173 "failed %dx\n", attempt
);
176 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
177 i2cdprintk("read error\n");
186 static int get_key_msi_tvanywhere_plus(struct IR_i2c
*ir
, u32
*ir_key
,
192 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
193 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
195 dprintk("get_key_msi_tvanywhere_plus: "
196 "gir->c->adapter->algo_data is NULL!\n");
200 /* rising SAA7134_GPIO_GPRESCAN reads the status */
202 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
203 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
205 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
207 /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
208 I2C receive if gpio&0x40 is not low. */
211 return 0; /* No button press */
213 /* GPIO says there is a button press. Get it. */
215 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
216 i2cdprintk("read error\n");
220 /* No button press */
227 dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b
);
233 static int get_key_purpletv(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
238 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
239 i2cdprintk("read error\n");
243 /* no button press */
256 static int get_key_hvr1110(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
258 unsigned char buf
[5], cod4
, code3
, code4
;
261 if (5 != i2c_master_recv(ir
->c
, buf
, 5))
278 static int get_key_beholdm6xx(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
280 unsigned char data
[12];
283 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
285 /* rising SAA7134_GPIO_GPRESCAN reads the status */
286 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
287 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
289 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
291 if (0x400000 & ~gpio
)
292 return 0; /* No button press */
294 ir
->c
->addr
= 0x5a >> 1;
296 if (12 != i2c_master_recv(ir
->c
, data
, 12)) {
297 i2cdprintk("read error\n");
300 /* IR of this card normally decode signals NEC-standard from
301 * - Sven IHOO MT 5.1R remote. xxyye718
302 * - Sven DVD HD-10xx remote. xxyyf708
305 * So, skip not our, if disable full codes mode.
307 if (data
[10] != 0x6b && data
[11] != 0x86 && disable_other_ir
)
310 /* Wrong data decode fix */
311 if (data
[9] != (unsigned char)(~data
[8]))
320 /* Common (grey or coloured) pinnacle PCTV remote handling
323 static int get_key_pinnacle(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
,
324 int parity_offset
, int marker
, int code_modulo
)
327 unsigned int start
= 0,parity
= 0,code
= 0;
330 if (4 != i2c_master_recv(ir
->c
, b
, 4)) {
331 i2cdprintk("read error\n");
335 for (start
= 0; start
< ARRAY_SIZE(b
); start
++) {
336 if (b
[start
] == marker
) {
337 code
=b
[(start
+parity_offset
+ 1) % 4];
338 parity
=b
[(start
+parity_offset
) % 4];
347 if (ir
->old
== parity
)
352 /* drop special codes when a key is held down a long time for the grey controller
353 In this case, the second bit of the code is asserted */
354 if (marker
== 0xfe && (code
& 0x40))
362 i2cdprintk("Pinnacle PCTV key %02x\n", code
);
367 /* The grey pinnacle PCTV remote
369 * There are one issue with this remote:
370 * - I2c packet does not change when the same key is pressed quickly. The workaround
371 * is to hold down each key for about half a second, so that another code is generated
372 * in the i2c packet, and the function can distinguish key presses.
374 * Sylvain Pasche <sylvain.pasche@gmail.com>
376 static int get_key_pinnacle_grey(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
379 return get_key_pinnacle(ir
, ir_key
, ir_raw
, 1, 0xfe, 0xff);
383 /* The new pinnacle PCTV remote (with the colored buttons)
385 * Ricardo Cerqueira <v4l@cerqueira.org>
387 static int get_key_pinnacle_color(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
389 /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
391 * this is the only value that results in 42 unique
395 return get_key_pinnacle(ir
, ir_key
, ir_raw
, 2, 0x80, 0x88);
398 void saa7134_input_irq(struct saa7134_dev
*dev
)
400 struct card_ir
*ir
= dev
->remote
;
403 saa7134_nec_irq(dev
);
404 } else if (!ir
->polling
&& !ir
->rc5_gpio
) {
406 } else if (ir
->rc5_gpio
) {
407 saa7134_rc5_irq(dev
);
411 static void saa7134_input_timer(unsigned long data
)
413 struct saa7134_dev
*dev
= (struct saa7134_dev
*)data
;
414 struct card_ir
*ir
= dev
->remote
;
417 mod_timer(&ir
->timer
, jiffies
+ msecs_to_jiffies(ir
->polling
));
420 void saa7134_ir_start(struct saa7134_dev
*dev
, struct card_ir
*ir
)
423 setup_timer(&ir
->timer
, saa7134_input_timer
,
425 ir
->timer
.expires
= jiffies
+ HZ
;
426 add_timer(&ir
->timer
);
427 } else if (ir
->rc5_gpio
) {
428 /* set timer_end for code completion */
429 init_timer(&ir
->timer_end
);
430 ir
->timer_end
.function
= ir_rc5_timer_end
;
431 ir
->timer_end
.data
= (unsigned long)ir
;
432 init_timer(&ir
->timer_keyup
);
433 ir
->timer_keyup
.function
= ir_rc5_timer_keyup
;
434 ir
->timer_keyup
.data
= (unsigned long)ir
;
438 ir
->rc5_key_timeout
= ir_rc5_key_timeout
;
439 ir
->rc5_remote_gap
= ir_rc5_remote_gap
;
440 } else if (ir
->nec_gpio
) {
441 setup_timer(&ir
->timer_keyup
, saa7134_nec_timer
,
443 tasklet_init(&ir
->tlet
, nec_task
, (unsigned long)dev
);
447 void saa7134_ir_stop(struct saa7134_dev
*dev
)
449 if (dev
->remote
->polling
)
450 del_timer_sync(&dev
->remote
->timer
);
453 int saa7134_input_init1(struct saa7134_dev
*dev
)
456 struct input_dev
*input_dev
;
457 struct ir_scancode_table
*ir_codes
= NULL
;
458 u32 mask_keycode
= 0;
459 u32 mask_keydown
= 0;
464 u64 ir_type
= IR_TYPE_OTHER
;
467 if (dev
->has_remote
!= SAA7134_REMOTE_GPIO
)
472 /* detect & configure */
473 switch (dev
->board
) {
474 case SAA7134_BOARD_FLYVIDEO2000
:
475 case SAA7134_BOARD_FLYVIDEO3000
:
476 case SAA7134_BOARD_FLYTVPLATINUM_FM
:
477 case SAA7134_BOARD_FLYTVPLATINUM_MINI2
:
478 case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM
:
479 ir_codes
= &ir_codes_flyvideo_table
;
480 mask_keycode
= 0xEC00000;
481 mask_keydown
= 0x0040000;
483 case SAA7134_BOARD_CINERGY400
:
484 case SAA7134_BOARD_CINERGY600
:
485 case SAA7134_BOARD_CINERGY600_MK3
:
486 ir_codes
= &ir_codes_cinergy_table
;
487 mask_keycode
= 0x00003f;
488 mask_keyup
= 0x040000;
490 case SAA7134_BOARD_ECS_TVP3XP
:
491 case SAA7134_BOARD_ECS_TVP3XP_4CB5
:
492 ir_codes
= &ir_codes_eztv_table
;
493 mask_keycode
= 0x00017c;
494 mask_keyup
= 0x000002;
497 case SAA7134_BOARD_KWORLD_XPERT
:
498 case SAA7134_BOARD_AVACSSMARTTV
:
499 ir_codes
= &ir_codes_pixelview_table
;
500 mask_keycode
= 0x00001F;
501 mask_keyup
= 0x000020;
504 case SAA7134_BOARD_MD2819
:
505 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT
:
506 case SAA7134_BOARD_AVERMEDIA_305
:
507 case SAA7134_BOARD_AVERMEDIA_307
:
508 case SAA7134_BOARD_AVERMEDIA_STUDIO_305
:
509 case SAA7134_BOARD_AVERMEDIA_STUDIO_505
:
510 case SAA7134_BOARD_AVERMEDIA_STUDIO_307
:
511 case SAA7134_BOARD_AVERMEDIA_STUDIO_507
:
512 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA
:
513 case SAA7134_BOARD_AVERMEDIA_GO_007_FM
:
514 case SAA7134_BOARD_AVERMEDIA_M102
:
515 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS
:
516 ir_codes
= &ir_codes_avermedia_table
;
517 mask_keycode
= 0x0007C8;
518 mask_keydown
= 0x000010;
520 /* Set GPIO pin2 to high to enable the IR controller */
521 saa_setb(SAA7134_GPIO_GPMODE0
, 0x4);
522 saa_setb(SAA7134_GPIO_GPSTATUS0
, 0x4);
524 case SAA7134_BOARD_AVERMEDIA_M135A
:
525 ir_codes
= &ir_codes_avermedia_m135a_table
;
526 mask_keydown
= 0x0040000;
527 mask_keycode
= 0x00013f;
530 case SAA7134_BOARD_AVERMEDIA_777
:
531 case SAA7134_BOARD_AVERMEDIA_A16AR
:
532 ir_codes
= &ir_codes_avermedia_table
;
533 mask_keycode
= 0x02F200;
534 mask_keydown
= 0x000400;
536 /* Without this we won't receive key up events */
537 saa_setb(SAA7134_GPIO_GPMODE1
, 0x1);
538 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x1);
540 case SAA7134_BOARD_AVERMEDIA_A16D
:
541 ir_codes
= &ir_codes_avermedia_a16d_table
;
542 mask_keycode
= 0x02F200;
543 mask_keydown
= 0x000400;
544 polling
= 50; /* ms */
545 /* Without this we won't receive key up events */
546 saa_setb(SAA7134_GPIO_GPMODE1
, 0x1);
547 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x1);
549 case SAA7134_BOARD_KWORLD_TERMINATOR
:
550 ir_codes
= &ir_codes_pixelview_table
;
551 mask_keycode
= 0x00001f;
552 mask_keyup
= 0x000060;
555 case SAA7134_BOARD_MANLI_MTV001
:
556 case SAA7134_BOARD_MANLI_MTV002
:
557 ir_codes
= &ir_codes_manli_table
;
558 mask_keycode
= 0x001f00;
559 mask_keyup
= 0x004000;
560 polling
= 50; /* ms */
562 case SAA7134_BOARD_BEHOLD_409FM
:
563 case SAA7134_BOARD_BEHOLD_401
:
564 case SAA7134_BOARD_BEHOLD_403
:
565 case SAA7134_BOARD_BEHOLD_403FM
:
566 case SAA7134_BOARD_BEHOLD_405
:
567 case SAA7134_BOARD_BEHOLD_405FM
:
568 case SAA7134_BOARD_BEHOLD_407
:
569 case SAA7134_BOARD_BEHOLD_407FM
:
570 case SAA7134_BOARD_BEHOLD_409
:
571 case SAA7134_BOARD_BEHOLD_505FM
:
572 case SAA7134_BOARD_BEHOLD_505RDS_MK5
:
573 case SAA7134_BOARD_BEHOLD_505RDS_MK3
:
574 case SAA7134_BOARD_BEHOLD_507_9FM
:
575 case SAA7134_BOARD_BEHOLD_507RDS_MK3
:
576 case SAA7134_BOARD_BEHOLD_507RDS_MK5
:
577 ir_codes
= &ir_codes_manli_table
;
578 mask_keycode
= 0x003f00;
579 mask_keyup
= 0x004000;
580 polling
= 50; /* ms */
582 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM
:
583 ir_codes
= &ir_codes_behold_columbus_table
;
584 mask_keycode
= 0x003f00;
585 mask_keyup
= 0x004000;
588 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS
:
589 ir_codes
= &ir_codes_pctv_sedna_table
;
590 mask_keycode
= 0x001f00;
591 mask_keyup
= 0x004000;
594 case SAA7134_BOARD_GOTVIEW_7135
:
595 ir_codes
= &ir_codes_gotview7135_table
;
596 mask_keycode
= 0x0003CC;
597 mask_keydown
= 0x000010;
598 polling
= 5; /* ms */
599 saa_setb(SAA7134_GPIO_GPMODE1
, 0x80);
601 case SAA7134_BOARD_VIDEOMATE_TV_PVR
:
602 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS
:
603 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII
:
604 ir_codes
= &ir_codes_videomate_tv_pvr_table
;
605 mask_keycode
= 0x00003F;
606 mask_keyup
= 0x400000;
609 case SAA7134_BOARD_PROTEUS_2309
:
610 ir_codes
= &ir_codes_proteus_2309_table
;
611 mask_keycode
= 0x00007F;
612 mask_keyup
= 0x000080;
615 case SAA7134_BOARD_VIDEOMATE_DVBT_300
:
616 case SAA7134_BOARD_VIDEOMATE_DVBT_200
:
617 ir_codes
= &ir_codes_videomate_tv_pvr_table
;
618 mask_keycode
= 0x003F00;
619 mask_keyup
= 0x040000;
621 case SAA7134_BOARD_FLYDVBS_LR300
:
622 case SAA7134_BOARD_FLYDVBT_LR301
:
623 case SAA7134_BOARD_FLYDVBTDUO
:
624 ir_codes
= &ir_codes_flydvb_table
;
625 mask_keycode
= 0x0001F00;
626 mask_keydown
= 0x0040000;
628 case SAA7134_BOARD_ASUSTeK_P7131_DUAL
:
629 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA
:
630 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG
:
631 ir_codes
= &ir_codes_asus_pc39_table
;
632 mask_keydown
= 0x0040000;
635 case SAA7134_BOARD_ENCORE_ENLTV
:
636 case SAA7134_BOARD_ENCORE_ENLTV_FM
:
637 ir_codes
= &ir_codes_encore_enltv_table
;
638 mask_keycode
= 0x00007f;
639 mask_keyup
= 0x040000;
642 case SAA7134_BOARD_ENCORE_ENLTV_FM53
:
643 ir_codes
= &ir_codes_encore_enltv_fm53_table
;
644 mask_keydown
= 0x0040000;
645 mask_keycode
= 0x00007f;
648 case SAA7134_BOARD_10MOONSTVMASTER3
:
649 ir_codes
= &ir_codes_encore_enltv_table
;
650 mask_keycode
= 0x5f80000;
651 mask_keyup
= 0x8000000;
654 case SAA7134_BOARD_GENIUS_TVGO_A11MCE
:
655 ir_codes
= &ir_codes_genius_tvgo_a11mce_table
;
657 mask_keydown
= 0xf00000;
658 polling
= 50; /* ms */
660 case SAA7134_BOARD_REAL_ANGEL_220
:
661 ir_codes
= &ir_codes_real_audio_220_32_keys_table
;
662 mask_keycode
= 0x3f00;
664 polling
= 50; /* ms */
666 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG
:
667 ir_codes
= &ir_codes_kworld_plus_tv_analog_table
;
669 polling
= 40; /* ms */
671 case SAA7134_BOARD_VIDEOMATE_S350
:
672 ir_codes
= &ir_codes_videomate_s350_table
;
673 mask_keycode
= 0x003f00;
674 mask_keydown
= 0x040000;
676 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S
:
677 ir_codes
= &ir_codes_winfast_table
;
678 mask_keycode
= 0x5f00;
679 mask_keyup
= 0x020000;
680 polling
= 50; /* ms */
684 if (NULL
== ir_codes
) {
685 printk("%s: Oops: IR config error [card=%d]\n",
686 dev
->name
, dev
->board
);
690 ir
= kzalloc(sizeof(*ir
), GFP_KERNEL
);
691 input_dev
= input_allocate_device();
692 if (!ir
|| !input_dev
) {
699 /* init hardware-specific stuff */
700 ir
->mask_keycode
= mask_keycode
;
701 ir
->mask_keydown
= mask_keydown
;
702 ir
->mask_keyup
= mask_keyup
;
703 ir
->polling
= polling
;
704 ir
->rc5_gpio
= rc5_gpio
;
705 ir
->nec_gpio
= nec_gpio
;
707 /* init input device */
708 snprintf(ir
->name
, sizeof(ir
->name
), "saa7134 IR (%s)",
709 saa7134_boards
[dev
->board
].name
);
710 snprintf(ir
->phys
, sizeof(ir
->phys
), "pci-%s/ir0",
713 err
= ir_input_init(input_dev
, &ir
->ir
, ir_type
);
717 input_dev
->name
= ir
->name
;
718 input_dev
->phys
= ir
->phys
;
719 input_dev
->id
.bustype
= BUS_PCI
;
720 input_dev
->id
.version
= 1;
721 if (dev
->pci
->subsystem_vendor
) {
722 input_dev
->id
.vendor
= dev
->pci
->subsystem_vendor
;
723 input_dev
->id
.product
= dev
->pci
->subsystem_device
;
725 input_dev
->id
.vendor
= dev
->pci
->vendor
;
726 input_dev
->id
.product
= dev
->pci
->device
;
728 input_dev
->dev
.parent
= &dev
->pci
->dev
;
731 saa7134_ir_start(dev
, ir
);
733 err
= ir_input_register(ir
->dev
, ir_codes
, NULL
);
737 /* the remote isn't as bouncy as a keyboard */
738 ir
->dev
->rep
[REP_DELAY
] = repeat_delay
;
739 ir
->dev
->rep
[REP_PERIOD
] = repeat_period
;
744 saa7134_ir_stop(dev
);
751 void saa7134_input_fini(struct saa7134_dev
*dev
)
753 if (NULL
== dev
->remote
)
756 saa7134_ir_stop(dev
);
757 ir_input_unregister(dev
->remote
->dev
);
762 void saa7134_probe_i2c_ir(struct saa7134_dev
*dev
)
764 struct i2c_board_info info
;
766 struct i2c_msg msg_msi
= {
776 dprintk("IR has been disabled, not probing for i2c remote\n");
780 memset(&info
, 0, sizeof(struct i2c_board_info
));
781 memset(&dev
->init_data
, 0, sizeof(dev
->init_data
));
782 strlcpy(info
.type
, "ir_video", I2C_NAME_SIZE
);
784 switch (dev
->board
) {
785 case SAA7134_BOARD_PINNACLE_PCTV_110i
:
786 case SAA7134_BOARD_PINNACLE_PCTV_310i
:
787 dev
->init_data
.name
= "Pinnacle PCTV";
788 if (pinnacle_remote
== 0) {
789 dev
->init_data
.get_key
= get_key_pinnacle_color
;
790 dev
->init_data
.ir_codes
= &ir_codes_pinnacle_color_table
;
793 dev
->init_data
.get_key
= get_key_pinnacle_grey
;
794 dev
->init_data
.ir_codes
= &ir_codes_pinnacle_grey_table
;
798 case SAA7134_BOARD_UPMOST_PURPLE_TV
:
799 dev
->init_data
.name
= "Purple TV";
800 dev
->init_data
.get_key
= get_key_purpletv
;
801 dev
->init_data
.ir_codes
= &ir_codes_purpletv_table
;
804 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS
:
805 dev
->init_data
.name
= "MSI TV@nywhere Plus";
806 dev
->init_data
.get_key
= get_key_msi_tvanywhere_plus
;
807 dev
->init_data
.ir_codes
= &ir_codes_msi_tvanywhere_plus_table
;
809 /* MSI TV@nywhere Plus controller doesn't seem to
810 respond to probes unless we read something from
811 an existing device. Weird...
812 REVISIT: might no longer be needed */
813 rc
= i2c_transfer(&dev
->i2c_adap
, &msg_msi
, 1);
814 dprintk(KERN_DEBUG
"probe 0x%02x @ %s: %s\n",
815 msg_msi
.addr
, dev
->i2c_adap
.name
,
816 (1 == rc
) ? "yes" : "no");
818 case SAA7134_BOARD_HAUPPAUGE_HVR1110
:
819 dev
->init_data
.name
= "HVR 1110";
820 dev
->init_data
.get_key
= get_key_hvr1110
;
821 dev
->init_data
.ir_codes
= &ir_codes_hauppauge_new_table
;
824 case SAA7134_BOARD_BEHOLD_607FM_MK3
:
825 case SAA7134_BOARD_BEHOLD_607FM_MK5
:
826 case SAA7134_BOARD_BEHOLD_609FM_MK3
:
827 case SAA7134_BOARD_BEHOLD_609FM_MK5
:
828 case SAA7134_BOARD_BEHOLD_607RDS_MK3
:
829 case SAA7134_BOARD_BEHOLD_607RDS_MK5
:
830 case SAA7134_BOARD_BEHOLD_609RDS_MK3
:
831 case SAA7134_BOARD_BEHOLD_609RDS_MK5
:
832 case SAA7134_BOARD_BEHOLD_M6
:
833 case SAA7134_BOARD_BEHOLD_M63
:
834 case SAA7134_BOARD_BEHOLD_M6_EXTRA
:
835 case SAA7134_BOARD_BEHOLD_H6
:
836 case SAA7134_BOARD_BEHOLD_X7
:
837 dev
->init_data
.name
= "BeholdTV";
838 dev
->init_data
.get_key
= get_key_beholdm6xx
;
839 dev
->init_data
.ir_codes
= &ir_codes_behold_table
;
842 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501
:
843 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506
:
846 case SAA7134_BOARD_FLYDVB_TRIO
:
847 dev
->init_data
.name
= "FlyDVB Trio";
848 dev
->init_data
.get_key
= get_key_flydvb_trio
;
849 dev
->init_data
.ir_codes
= &ir_codes_flydvb_table
;
853 dprintk("No I2C IR support for board %x\n", dev
->board
);
857 if (dev
->init_data
.name
)
858 info
.platform_data
= &dev
->init_data
;
859 i2c_new_device(&dev
->i2c_adap
, &info
);
862 static int saa7134_rc5_irq(struct saa7134_dev
*dev
)
864 struct card_ir
*ir
= dev
->remote
;
867 unsigned long current_jiffies
, timeout
;
869 /* get time of bit */
870 current_jiffies
= jiffies
;
871 do_gettimeofday(&tv
);
873 /* avoid overflow with gap >1s */
874 if (tv
.tv_sec
- ir
->base_time
.tv_sec
> 1) {
877 gap
= 1000000 * (tv
.tv_sec
- ir
->base_time
.tv_sec
) +
878 tv
.tv_usec
- ir
->base_time
.tv_usec
;
881 /* active code => add bit */
883 /* only if in the code (otherwise spurious IRQ or timer
885 if (ir
->last_bit
< 28) {
886 ir
->last_bit
= (gap
- ir_rc5_remote_gap
/ 2) /
888 ir
->code
|= 1 << ir
->last_bit
;
890 /* starting new code */
897 timeout
= current_jiffies
+ (500 + 30 * HZ
) / 1000;
898 mod_timer(&ir
->timer_end
, timeout
);
905 /* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
906 The first pulse (start) has 9 + 4.5 ms
909 static void saa7134_nec_timer(unsigned long data
)
911 struct saa7134_dev
*dev
= (struct saa7134_dev
*) data
;
912 struct card_ir
*ir
= dev
->remote
;
914 dprintk("Cancel key repeat\n");
916 ir_input_nokey(ir
->dev
, &ir
->ir
);
919 static void nec_task(unsigned long data
)
921 struct saa7134_dev
*dev
= (struct saa7134_dev
*) data
;
924 int count
, pulse
, oldpulse
, gap
;
925 u32 ircode
= 0, not_code
= 0;
929 printk(KERN_ERR
"saa713x/ir: Can't recover dev struct\n");
930 /* GPIO will be kept disabled */
936 /* rising SAA7134_GPIO_GPRESCAN reads the status */
937 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
938 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
940 oldpulse
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2) & ir
->mask_keydown
;
943 do_gettimeofday(&tv
);
946 /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
947 Unfortunately, using IRQ to decode pulse didn't work, since it uses
948 a pulse train of 38KHz. This means one pulse on each 52 us
951 /* Wait until the end of pulse/space or 5 ms */
952 for (count
= 0; count
< 500; count
++) {
954 /* rising SAA7134_GPIO_GPRESCAN reads the status */
955 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
956 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
957 pulse
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2)
959 if (pulse
!= oldpulse
)
963 do_gettimeofday(&tv
);
964 gap
= 1000000 * (tv
.tv_sec
- ir
->base_time
.tv_sec
) +
965 tv
.tv_usec
- ir
->base_time
.tv_usec
;
968 /* Bit 0 has 560 us, while bit 1 has 1120 us.
969 Do something only if bit == 1
971 if (ngap
&& (gap
> 560 + 280)) {
972 unsigned int shift
= ngap
- 1;
974 /* Address first, then command */
977 ircode
|= 1 << shift
;
978 } else if (shift
< 16) {
979 not_code
|= 1 << shift
;
980 } else if (shift
< 24) {
982 ircode
|= 1 << shift
;
985 not_code
|= 1 << shift
;
994 /* TIMEOUT - Long pulse */
1001 /* FIXME: should check if not_code == ~ircode */
1002 ir
->code
= ir_extract_bits(ircode
, ir
->mask_keycode
);
1004 dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
1005 ir
->code
, ircode
, not_code
);
1007 ir_input_keydown(ir
->dev
, &ir
->ir
, ir
->code
);
1009 dprintk("Repeat last key\n");
1011 /* Keep repeating the last key */
1012 mod_timer(&ir
->timer_keyup
, jiffies
+ msecs_to_jiffies(150));
1014 saa_setl(SAA7134_IRQ2
, SAA7134_IRQ2_INTE_GPIO18
);
1017 static int saa7134_nec_irq(struct saa7134_dev
*dev
)
1019 struct card_ir
*ir
= dev
->remote
;
1021 saa_clearl(SAA7134_IRQ2
, SAA7134_IRQ2_INTE_GPIO18
);
1022 tasklet_schedule(&ir
->tlet
);