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.
18 #include "saa7134-reg.h"
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/delay.h>
23 #include <linux/interrupt.h>
24 #include <linux/slab.h>
26 #define MODULE_NAME "saa7134"
28 static unsigned int disable_ir
;
29 module_param(disable_ir
, int, 0444);
30 MODULE_PARM_DESC(disable_ir
,"disable infrared remote support");
32 static unsigned int ir_debug
;
33 module_param(ir_debug
, int, 0644);
34 MODULE_PARM_DESC(ir_debug
,"enable debug messages [IR]");
36 static int pinnacle_remote
;
37 module_param(pinnacle_remote
, int, 0644); /* Choose Pinnacle PCTV remote */
38 MODULE_PARM_DESC(pinnacle_remote
, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
40 #define input_dbg(fmt, arg...) do { \
42 printk(KERN_DEBUG pr_fmt("input: " fmt), ## arg); \
44 #define ir_dbg(ir, fmt, arg...) do { \
46 printk(KERN_DEBUG pr_fmt("ir %s: " fmt), ir->rc->device_name, \
50 /* Helper function for raw decoding at GPIO16 or GPIO18 */
51 static int saa7134_raw_decode_irq(struct saa7134_dev
*dev
);
53 /* -------------------- GPIO generic keycode builder -------------------- */
55 static int build_key(struct saa7134_dev
*dev
)
57 struct saa7134_card_ir
*ir
= dev
->remote
;
60 /* here comes the additional handshake steps for some cards */
62 case SAA7134_BOARD_GOTVIEW_7135
:
63 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x80);
64 saa_clearb(SAA7134_GPIO_GPSTATUS1
, 0x80);
67 /* rising SAA7134_GPIO_GPRESCAN reads the status */
68 saa_clearb(SAA7134_GPIO_GPMODE3
,SAA7134_GPIO_GPRESCAN
);
69 saa_setb(SAA7134_GPIO_GPMODE3
,SAA7134_GPIO_GPRESCAN
);
71 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
73 if (ir
->last_gpio
== gpio
)
78 data
= ir_extract_bits(gpio
, ir
->mask_keycode
);
79 input_dbg("build_key gpio=0x%x mask=0x%x data=%d\n",
80 gpio
, ir
->mask_keycode
, data
);
83 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG
:
84 if (data
== ir
->mask_keycode
)
87 rc_keydown_notimeout(ir
->dev
, RC_PROTO_UNKNOWN
, data
,
93 if ((ir
->mask_keydown
&& (0 != (gpio
& ir
->mask_keydown
))) ||
94 (ir
->mask_keyup
&& (0 == (gpio
& ir
->mask_keyup
)))) {
95 rc_keydown_notimeout(ir
->dev
, RC_PROTO_UNKNOWN
, data
,
101 else { /* IRQ driven mode - handle key press and release in one go */
102 if ((ir
->mask_keydown
&& (0 != (gpio
& ir
->mask_keydown
))) ||
103 (ir
->mask_keyup
&& (0 == (gpio
& ir
->mask_keyup
)))) {
104 rc_keydown_notimeout(ir
->dev
, RC_PROTO_UNKNOWN
, data
,
113 /* --------------------- Chip specific I2C key builders ----------------- */
115 static int get_key_flydvb_trio(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
116 u32
*scancode
, u8
*toggle
)
122 /* We need this to access GPI Used by the saa_readl macro. */
123 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
126 ir_dbg(ir
, "get_key_flydvb_trio: ir->c->adapter->algo_data is NULL!\n");
130 /* rising SAA7134_GPIGPRESCAN reads the status */
131 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
132 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
134 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
137 return 0; /* No button press */
140 /* weak up the IR chip */
143 while (1 != i2c_master_send(ir
->c
, &b
, 1)) {
144 if ((attempt
++) < 10) {
146 * wait a bit for next attempt -
147 * I don't know how make it better
152 ir_dbg(ir
, "send wake up byte to pic16C505 (IR chip)failed %dx\n",
156 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
157 ir_dbg(ir
, "read error\n");
161 *protocol
= RC_PROTO_UNKNOWN
;
167 static int get_key_msi_tvanywhere_plus(struct IR_i2c
*ir
,
168 enum rc_proto
*protocol
,
169 u32
*scancode
, u8
*toggle
)
174 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
175 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
177 ir_dbg(ir
, "get_key_msi_tvanywhere_plus: ir->c->adapter->algo_data is NULL!\n");
181 /* rising SAA7134_GPIO_GPRESCAN reads the status */
183 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
184 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
186 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
188 /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
189 I2C receive if gpio&0x40 is not low. */
192 return 0; /* No button press */
194 /* GPIO says there is a button press. Get it. */
196 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
197 ir_dbg(ir
, "read error\n");
201 /* No button press */
208 input_dbg("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b
);
209 *protocol
= RC_PROTO_UNKNOWN
;
215 /* copied and modified from get_key_msi_tvanywhere_plus() */
216 static int get_key_kworld_pc150u(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
217 u32
*scancode
, u8
*toggle
)
222 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
223 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
225 ir_dbg(ir
, "get_key_kworld_pc150u: ir->c->adapter->algo_data is NULL!\n");
229 /* rising SAA7134_GPIO_GPRESCAN reads the status */
231 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
232 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
234 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
236 /* GPIO&0x100 is pulsed low when a button is pressed. Don't do
237 I2C receive if gpio&0x100 is not low. */
240 return 0; /* No button press */
242 /* GPIO says there is a button press. Get it. */
244 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
245 ir_dbg(ir
, "read error\n");
249 /* No button press */
256 input_dbg("get_key_kworld_pc150u: Key = 0x%02X\n", b
);
257 *protocol
= RC_PROTO_UNKNOWN
;
263 static int get_key_purpletv(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
264 u32
*scancode
, u8
*toggle
)
269 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
270 ir_dbg(ir
, "read error\n");
274 /* no button press */
282 *protocol
= RC_PROTO_UNKNOWN
;
288 static int get_key_hvr1110(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
289 u32
*scancode
, u8
*toggle
)
291 unsigned char buf
[5];
294 if (5 != i2c_master_recv(ir
->c
, buf
, 5))
297 /* Check if some key were pressed */
298 if (!(buf
[0] & 0x80))
302 * buf[3] & 0x80 is always high.
303 * buf[3] & 0x40 is a parity bit. A repeat event is marked
304 * by preserving it into two separate readings
305 * buf[4] bits 0 and 1, and buf[1] and buf[2] are always
308 * Note that the keymap which the hvr1110 uses is RC5.
310 * FIXME: start bits could maybe be used...?
312 *protocol
= RC_PROTO_RC5
;
313 *scancode
= RC_SCANCODE_RC5(buf
[3] & 0x1f, buf
[4] >> 2);
314 *toggle
= !!(buf
[3] & 0x40);
319 static int get_key_beholdm6xx(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
320 u32
*scancode
, u8
*toggle
)
322 unsigned char data
[12];
325 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
327 /* rising SAA7134_GPIO_GPRESCAN reads the status */
328 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
329 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
331 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
333 if (0x400000 & ~gpio
)
334 return 0; /* No button press */
336 ir
->c
->addr
= 0x5a >> 1;
338 if (12 != i2c_master_recv(ir
->c
, data
, 12)) {
339 ir_dbg(ir
, "read error\n");
343 if (data
[9] != (unsigned char)(~data
[8]))
346 *protocol
= RC_PROTO_NECX
;
347 *scancode
= RC_SCANCODE_NECX(data
[11] << 8 | data
[10], data
[9]);
352 /* Common (grey or coloured) pinnacle PCTV remote handling
355 static int get_key_pinnacle(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
356 u32
*scancode
, u8
*toggle
, int parity_offset
,
357 int marker
, int code_modulo
)
360 unsigned int start
= 0,parity
= 0,code
= 0;
363 if (4 != i2c_master_recv(ir
->c
, b
, 4)) {
364 ir_dbg(ir
, "read error\n");
368 for (start
= 0; start
< ARRAY_SIZE(b
); start
++) {
369 if (b
[start
] == marker
) {
370 code
=b
[(start
+parity_offset
+ 1) % 4];
371 parity
=b
[(start
+parity_offset
) % 4];
380 if (ir
->old
== parity
)
385 /* drop special codes when a key is held down a long time for the grey controller
386 In this case, the second bit of the code is asserted */
387 if (marker
== 0xfe && (code
& 0x40))
392 *protocol
= RC_PROTO_UNKNOWN
;
396 ir_dbg(ir
, "Pinnacle PCTV key %02x\n", code
);
400 /* The grey pinnacle PCTV remote
402 * There are one issue with this remote:
403 * - I2c packet does not change when the same key is pressed quickly. The workaround
404 * is to hold down each key for about half a second, so that another code is generated
405 * in the i2c packet, and the function can distinguish key presses.
407 * Sylvain Pasche <sylvain.pasche@gmail.com>
409 static int get_key_pinnacle_grey(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
410 u32
*scancode
, u8
*toggle
)
413 return get_key_pinnacle(ir
, protocol
, scancode
, toggle
, 1, 0xfe, 0xff);
417 /* The new pinnacle PCTV remote (with the colored buttons)
419 * Ricardo Cerqueira <v4l@cerqueira.org>
421 static int get_key_pinnacle_color(struct IR_i2c
*ir
, enum rc_proto
*protocol
,
422 u32
*scancode
, u8
*toggle
)
424 /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
426 * this is the only value that results in 42 unique
430 return get_key_pinnacle(ir
, protocol
, scancode
, toggle
, 2, 0x80, 0x88);
433 void saa7134_input_irq(struct saa7134_dev
*dev
)
435 struct saa7134_card_ir
*ir
;
437 if (!dev
|| !dev
->remote
)
444 if (!ir
->polling
&& !ir
->raw_decode
) {
446 } else if (ir
->raw_decode
) {
447 saa7134_raw_decode_irq(dev
);
451 static void saa7134_input_timer(struct timer_list
*t
)
453 struct saa7134_card_ir
*ir
= from_timer(ir
, t
, timer
);
454 struct saa7134_dev
*dev
= ir
->dev
->priv
;
457 mod_timer(&ir
->timer
, jiffies
+ msecs_to_jiffies(ir
->polling
));
460 static int __saa7134_ir_start(void *priv
)
462 struct saa7134_dev
*dev
= priv
;
463 struct saa7134_card_ir
*ir
;
465 if (!dev
|| !dev
->remote
)
472 /* Moved here from saa7134_input_init1() because the latter
473 * is not called on device resume */
474 switch (dev
->board
) {
475 case SAA7134_BOARD_MD2819
:
476 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT
:
477 case SAA7134_BOARD_AVERMEDIA_305
:
478 case SAA7134_BOARD_AVERMEDIA_307
:
479 case SAA7134_BOARD_AVERMEDIA_505
:
480 case SAA7134_BOARD_AVERMEDIA_STUDIO_305
:
481 case SAA7134_BOARD_AVERMEDIA_STUDIO_505
:
482 case SAA7134_BOARD_AVERMEDIA_STUDIO_307
:
483 case SAA7134_BOARD_AVERMEDIA_STUDIO_507
:
484 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA
:
485 case SAA7134_BOARD_AVERMEDIA_GO_007_FM
:
486 case SAA7134_BOARD_AVERMEDIA_M102
:
487 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS
:
488 /* Without this we won't receive key up events */
489 saa_setb(SAA7134_GPIO_GPMODE0
, 0x4);
490 saa_setb(SAA7134_GPIO_GPSTATUS0
, 0x4);
492 case SAA7134_BOARD_AVERMEDIA_777
:
493 case SAA7134_BOARD_AVERMEDIA_A16AR
:
494 /* Without this we won't receive key up events */
495 saa_setb(SAA7134_GPIO_GPMODE1
, 0x1);
496 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x1);
498 case SAA7134_BOARD_AVERMEDIA_A16D
:
499 /* Without this we won't receive key up events */
500 saa_setb(SAA7134_GPIO_GPMODE1
, 0x1);
501 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x1);
503 case SAA7134_BOARD_GOTVIEW_7135
:
504 saa_setb(SAA7134_GPIO_GPMODE1
, 0x80);
511 timer_setup(&ir
->timer
, saa7134_input_timer
, 0);
512 ir
->timer
.expires
= jiffies
+ HZ
;
513 add_timer(&ir
->timer
);
519 static void __saa7134_ir_stop(void *priv
)
521 struct saa7134_dev
*dev
= priv
;
522 struct saa7134_card_ir
*ir
;
524 if (!dev
|| !dev
->remote
)
532 del_timer_sync(&ir
->timer
);
539 int saa7134_ir_start(struct saa7134_dev
*dev
)
541 if (dev
->remote
->users
)
542 return __saa7134_ir_start(dev
);
547 void saa7134_ir_stop(struct saa7134_dev
*dev
)
549 if (dev
->remote
->users
)
550 __saa7134_ir_stop(dev
);
553 static int saa7134_ir_open(struct rc_dev
*rc
)
555 struct saa7134_dev
*dev
= rc
->priv
;
557 dev
->remote
->users
++;
558 return __saa7134_ir_start(dev
);
561 static void saa7134_ir_close(struct rc_dev
*rc
)
563 struct saa7134_dev
*dev
= rc
->priv
;
565 dev
->remote
->users
--;
566 if (!dev
->remote
->users
)
567 __saa7134_ir_stop(dev
);
570 int saa7134_input_init1(struct saa7134_dev
*dev
)
572 struct saa7134_card_ir
*ir
;
574 char *ir_codes
= NULL
;
575 u32 mask_keycode
= 0;
576 u32 mask_keydown
= 0;
578 unsigned polling
= 0;
579 bool raw_decode
= false;
582 if (dev
->has_remote
!= SAA7134_REMOTE_GPIO
)
587 /* detect & configure */
588 switch (dev
->board
) {
589 case SAA7134_BOARD_FLYVIDEO2000
:
590 case SAA7134_BOARD_FLYVIDEO3000
:
591 case SAA7134_BOARD_FLYTVPLATINUM_FM
:
592 case SAA7134_BOARD_FLYTVPLATINUM_MINI2
:
593 case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM
:
594 ir_codes
= RC_MAP_FLYVIDEO
;
595 mask_keycode
= 0xEC00000;
596 mask_keydown
= 0x0040000;
598 case SAA7134_BOARD_CINERGY400
:
599 case SAA7134_BOARD_CINERGY600
:
600 case SAA7134_BOARD_CINERGY600_MK3
:
601 ir_codes
= RC_MAP_CINERGY
;
602 mask_keycode
= 0x00003f;
603 mask_keyup
= 0x040000;
605 case SAA7134_BOARD_ECS_TVP3XP
:
606 case SAA7134_BOARD_ECS_TVP3XP_4CB5
:
607 ir_codes
= RC_MAP_EZTV
;
608 mask_keycode
= 0x00017c;
609 mask_keyup
= 0x000002;
612 case SAA7134_BOARD_KWORLD_XPERT
:
613 case SAA7134_BOARD_AVACSSMARTTV
:
614 ir_codes
= RC_MAP_PIXELVIEW
;
615 mask_keycode
= 0x00001F;
616 mask_keyup
= 0x000020;
619 case SAA7134_BOARD_MD2819
:
620 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT
:
621 case SAA7134_BOARD_AVERMEDIA_305
:
622 case SAA7134_BOARD_AVERMEDIA_307
:
623 case SAA7134_BOARD_AVERMEDIA_505
:
624 case SAA7134_BOARD_AVERMEDIA_STUDIO_305
:
625 case SAA7134_BOARD_AVERMEDIA_STUDIO_505
:
626 case SAA7134_BOARD_AVERMEDIA_STUDIO_307
:
627 case SAA7134_BOARD_AVERMEDIA_STUDIO_507
:
628 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA
:
629 case SAA7134_BOARD_AVERMEDIA_GO_007_FM
:
630 case SAA7134_BOARD_AVERMEDIA_M102
:
631 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS
:
632 ir_codes
= RC_MAP_AVERMEDIA
;
633 mask_keycode
= 0x0007C8;
634 mask_keydown
= 0x000010;
636 /* GPIO stuff moved to __saa7134_ir_start() */
638 case SAA7134_BOARD_AVERMEDIA_M135A
:
639 ir_codes
= RC_MAP_AVERMEDIA_M135A
;
640 mask_keydown
= 0x0040000; /* Enable GPIO18 line on both edges */
641 mask_keyup
= 0x0040000;
642 mask_keycode
= 0xffff;
645 case SAA7134_BOARD_AVERMEDIA_M733A
:
646 ir_codes
= RC_MAP_AVERMEDIA_M733A_RM_K6
;
647 mask_keydown
= 0x0040000;
648 mask_keyup
= 0x0040000;
649 mask_keycode
= 0xffff;
652 case SAA7134_BOARD_AVERMEDIA_777
:
653 case SAA7134_BOARD_AVERMEDIA_A16AR
:
654 ir_codes
= RC_MAP_AVERMEDIA
;
655 mask_keycode
= 0x02F200;
656 mask_keydown
= 0x000400;
658 /* GPIO stuff moved to __saa7134_ir_start() */
660 case SAA7134_BOARD_AVERMEDIA_A16D
:
661 ir_codes
= RC_MAP_AVERMEDIA_A16D
;
662 mask_keycode
= 0x02F200;
663 mask_keydown
= 0x000400;
664 polling
= 50; /* ms */
665 /* GPIO stuff moved to __saa7134_ir_start() */
667 case SAA7134_BOARD_KWORLD_TERMINATOR
:
668 ir_codes
= RC_MAP_PIXELVIEW
;
669 mask_keycode
= 0x00001f;
670 mask_keyup
= 0x000060;
673 case SAA7134_BOARD_MANLI_MTV001
:
674 case SAA7134_BOARD_MANLI_MTV002
:
675 ir_codes
= RC_MAP_MANLI
;
676 mask_keycode
= 0x001f00;
677 mask_keyup
= 0x004000;
678 polling
= 50; /* ms */
680 case SAA7134_BOARD_BEHOLD_409FM
:
681 case SAA7134_BOARD_BEHOLD_401
:
682 case SAA7134_BOARD_BEHOLD_403
:
683 case SAA7134_BOARD_BEHOLD_403FM
:
684 case SAA7134_BOARD_BEHOLD_405
:
685 case SAA7134_BOARD_BEHOLD_405FM
:
686 case SAA7134_BOARD_BEHOLD_407
:
687 case SAA7134_BOARD_BEHOLD_407FM
:
688 case SAA7134_BOARD_BEHOLD_409
:
689 case SAA7134_BOARD_BEHOLD_505FM
:
690 case SAA7134_BOARD_BEHOLD_505RDS_MK5
:
691 case SAA7134_BOARD_BEHOLD_505RDS_MK3
:
692 case SAA7134_BOARD_BEHOLD_507_9FM
:
693 case SAA7134_BOARD_BEHOLD_507RDS_MK3
:
694 case SAA7134_BOARD_BEHOLD_507RDS_MK5
:
695 ir_codes
= RC_MAP_MANLI
;
696 mask_keycode
= 0x003f00;
697 mask_keyup
= 0x004000;
698 polling
= 50; /* ms */
700 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM
:
701 ir_codes
= RC_MAP_BEHOLD_COLUMBUS
;
702 mask_keycode
= 0x003f00;
703 mask_keyup
= 0x004000;
706 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS
:
707 ir_codes
= RC_MAP_PCTV_SEDNA
;
708 mask_keycode
= 0x001f00;
709 mask_keyup
= 0x004000;
712 case SAA7134_BOARD_GOTVIEW_7135
:
713 ir_codes
= RC_MAP_GOTVIEW7135
;
714 mask_keycode
= 0x0003CC;
715 mask_keydown
= 0x000010;
716 polling
= 5; /* ms */
717 /* GPIO stuff moved to __saa7134_ir_start() */
719 case SAA7134_BOARD_VIDEOMATE_TV_PVR
:
720 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS
:
721 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII
:
722 ir_codes
= RC_MAP_VIDEOMATE_TV_PVR
;
723 mask_keycode
= 0x00003F;
724 mask_keyup
= 0x400000;
727 case SAA7134_BOARD_PROTEUS_2309
:
728 ir_codes
= RC_MAP_PROTEUS_2309
;
729 mask_keycode
= 0x00007F;
730 mask_keyup
= 0x000080;
733 case SAA7134_BOARD_VIDEOMATE_DVBT_300
:
734 case SAA7134_BOARD_VIDEOMATE_DVBT_200
:
735 ir_codes
= RC_MAP_VIDEOMATE_TV_PVR
;
736 mask_keycode
= 0x003F00;
737 mask_keyup
= 0x040000;
739 case SAA7134_BOARD_FLYDVBS_LR300
:
740 case SAA7134_BOARD_FLYDVBT_LR301
:
741 case SAA7134_BOARD_FLYDVBTDUO
:
742 ir_codes
= RC_MAP_FLYDVB
;
743 mask_keycode
= 0x0001F00;
744 mask_keydown
= 0x0040000;
746 case SAA7134_BOARD_ASUSTeK_P7131_DUAL
:
747 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA
:
748 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG
:
749 ir_codes
= RC_MAP_ASUS_PC39
;
750 mask_keydown
= 0x0040000; /* Enable GPIO18 line on both edges */
751 mask_keyup
= 0x0040000;
752 mask_keycode
= 0xffff;
755 case SAA7134_BOARD_ASUSTeK_PS3_100
:
756 ir_codes
= RC_MAP_ASUS_PS3_100
;
757 mask_keydown
= 0x0040000;
758 mask_keyup
= 0x0040000;
759 mask_keycode
= 0xffff;
762 case SAA7134_BOARD_ENCORE_ENLTV
:
763 case SAA7134_BOARD_ENCORE_ENLTV_FM
:
764 ir_codes
= RC_MAP_ENCORE_ENLTV
;
765 mask_keycode
= 0x00007f;
766 mask_keyup
= 0x040000;
769 case SAA7134_BOARD_ENCORE_ENLTV_FM53
:
770 case SAA7134_BOARD_ENCORE_ENLTV_FM3
:
771 ir_codes
= RC_MAP_ENCORE_ENLTV_FM53
;
772 mask_keydown
= 0x0040000; /* Enable GPIO18 line on both edges */
773 mask_keyup
= 0x0040000;
774 mask_keycode
= 0xffff;
777 case SAA7134_BOARD_10MOONSTVMASTER3
:
778 ir_codes
= RC_MAP_ENCORE_ENLTV
;
779 mask_keycode
= 0x5f80000;
780 mask_keyup
= 0x8000000;
783 case SAA7134_BOARD_GENIUS_TVGO_A11MCE
:
784 ir_codes
= RC_MAP_GENIUS_TVGO_A11MCE
;
786 mask_keydown
= 0xf00000;
787 polling
= 50; /* ms */
789 case SAA7134_BOARD_REAL_ANGEL_220
:
790 ir_codes
= RC_MAP_REAL_AUDIO_220_32_KEYS
;
791 mask_keycode
= 0x3f00;
793 polling
= 50; /* ms */
795 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG
:
796 ir_codes
= RC_MAP_KWORLD_PLUS_TV_ANALOG
;
798 polling
= 40; /* ms */
800 case SAA7134_BOARD_VIDEOMATE_S350
:
801 ir_codes
= RC_MAP_VIDEOMATE_S350
;
802 mask_keycode
= 0x003f00;
803 mask_keydown
= 0x040000;
805 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S
:
806 ir_codes
= RC_MAP_WINFAST
;
807 mask_keycode
= 0x5f00;
808 mask_keyup
= 0x020000;
809 polling
= 50; /* ms */
811 case SAA7134_BOARD_VIDEOMATE_M1F
:
812 ir_codes
= RC_MAP_VIDEOMATE_K100
;
813 mask_keycode
= 0x0ff00;
814 mask_keyup
= 0x040000;
816 case SAA7134_BOARD_HAUPPAUGE_HVR1150
:
817 case SAA7134_BOARD_HAUPPAUGE_HVR1120
:
818 ir_codes
= RC_MAP_HAUPPAUGE
;
819 mask_keydown
= 0x0040000; /* Enable GPIO18 line on both edges */
820 mask_keyup
= 0x0040000;
821 mask_keycode
= 0xffff;
824 case SAA7134_BOARD_LEADTEK_WINFAST_TV2100_FM
:
825 ir_codes
= RC_MAP_LEADTEK_Y04G0051
;
826 mask_keydown
= 0x0040000; /* Enable GPIO18 line on both edges */
827 mask_keyup
= 0x0040000;
828 mask_keycode
= 0xffff;
832 if (NULL
== ir_codes
) {
833 pr_err("Oops: IR config error [card=%d]\n", dev
->board
);
837 ir
= kzalloc(sizeof(*ir
), GFP_KERNEL
);
838 rc
= rc_allocate_device(RC_DRIVER_SCANCODE
);
847 /* init hardware-specific stuff */
848 ir
->mask_keycode
= mask_keycode
;
849 ir
->mask_keydown
= mask_keydown
;
850 ir
->mask_keyup
= mask_keyup
;
851 ir
->polling
= polling
;
852 ir
->raw_decode
= raw_decode
;
854 /* init input device */
855 snprintf(ir
->name
, sizeof(ir
->name
), "saa7134 IR (%s)",
856 saa7134_boards
[dev
->board
].name
);
857 snprintf(ir
->phys
, sizeof(ir
->phys
), "pci-%s/ir0",
861 rc
->open
= saa7134_ir_open
;
862 rc
->close
= saa7134_ir_close
;
864 rc
->driver_type
= RC_DRIVER_IR_RAW
;
865 rc
->allowed_protocols
= RC_PROTO_BIT_ALL_IR_DECODER
;
868 rc
->device_name
= ir
->name
;
869 rc
->input_phys
= ir
->phys
;
870 rc
->input_id
.bustype
= BUS_PCI
;
871 rc
->input_id
.version
= 1;
872 if (dev
->pci
->subsystem_vendor
) {
873 rc
->input_id
.vendor
= dev
->pci
->subsystem_vendor
;
874 rc
->input_id
.product
= dev
->pci
->subsystem_device
;
876 rc
->input_id
.vendor
= dev
->pci
->vendor
;
877 rc
->input_id
.product
= dev
->pci
->device
;
879 rc
->dev
.parent
= &dev
->pci
->dev
;
880 rc
->map_name
= ir_codes
;
881 rc
->driver_name
= MODULE_NAME
;
883 rc
->timeout
= IR_DEFAULT_TIMEOUT
;
884 rc
->max_timeout
= 10 * IR_DEFAULT_TIMEOUT
;
886 err
= rc_register_device(rc
);
899 void saa7134_input_fini(struct saa7134_dev
*dev
)
901 if (NULL
== dev
->remote
)
904 saa7134_ir_stop(dev
);
905 rc_unregister_device(dev
->remote
->dev
);
910 void saa7134_probe_i2c_ir(struct saa7134_dev
*dev
)
912 struct i2c_board_info info
;
913 struct i2c_msg msg_msi
= {
922 input_dbg("IR has been disabled, not probing for i2c remote\n");
926 memset(&info
, 0, sizeof(struct i2c_board_info
));
927 memset(&dev
->init_data
, 0, sizeof(dev
->init_data
));
928 strlcpy(info
.type
, "ir_video", I2C_NAME_SIZE
);
930 switch (dev
->board
) {
931 case SAA7134_BOARD_PINNACLE_PCTV_110i
:
932 case SAA7134_BOARD_PINNACLE_PCTV_310i
:
933 dev
->init_data
.name
= "Pinnacle PCTV";
934 if (pinnacle_remote
== 0) {
935 dev
->init_data
.get_key
= get_key_pinnacle_color
;
936 dev
->init_data
.ir_codes
= RC_MAP_PINNACLE_COLOR
;
939 dev
->init_data
.get_key
= get_key_pinnacle_grey
;
940 dev
->init_data
.ir_codes
= RC_MAP_PINNACLE_GREY
;
944 case SAA7134_BOARD_UPMOST_PURPLE_TV
:
945 dev
->init_data
.name
= "Purple TV";
946 dev
->init_data
.get_key
= get_key_purpletv
;
947 dev
->init_data
.ir_codes
= RC_MAP_PURPLETV
;
950 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS
:
951 dev
->init_data
.name
= "MSI TV@nywhere Plus";
952 dev
->init_data
.get_key
= get_key_msi_tvanywhere_plus
;
953 dev
->init_data
.ir_codes
= RC_MAP_MSI_TVANYWHERE_PLUS
;
955 * MSI TV@nyware Plus requires more frequent polling
956 * otherwise it will miss some keypresses
958 dev
->init_data
.polling_interval
= 50;
960 /* MSI TV@nywhere Plus controller doesn't seem to
961 respond to probes unless we read something from
962 an existing device. Weird...
963 REVISIT: might no longer be needed */
964 rc
= i2c_transfer(&dev
->i2c_adap
, &msg_msi
, 1);
965 input_dbg("probe 0x%02x @ %s: %s\n",
966 msg_msi
.addr
, dev
->i2c_adap
.name
,
967 (1 == rc
) ? "yes" : "no");
969 case SAA7134_BOARD_SNAZIO_TVPVR_PRO
:
970 dev
->init_data
.name
= "SnaZio* TVPVR PRO";
971 dev
->init_data
.get_key
= get_key_msi_tvanywhere_plus
;
972 dev
->init_data
.ir_codes
= RC_MAP_MSI_TVANYWHERE_PLUS
;
974 * MSI TV@nyware Plus requires more frequent polling
975 * otherwise it will miss some keypresses
977 dev
->init_data
.polling_interval
= 50;
980 * MSI TV@nywhere Plus controller doesn't seem to
981 * respond to probes unless we read something from
982 * an existing device. Weird...
983 * REVISIT: might no longer be needed
985 rc
= i2c_transfer(&dev
->i2c_adap
, &msg_msi
, 1);
986 input_dbg("probe 0x%02x @ %s: %s\n",
987 msg_msi
.addr
, dev
->i2c_adap
.name
,
988 (rc
== 1) ? "yes" : "no");
990 case SAA7134_BOARD_KWORLD_PC150U
:
991 /* copied and modified from MSI TV@nywhere Plus */
992 dev
->init_data
.name
= "Kworld PC150-U";
993 dev
->init_data
.get_key
= get_key_kworld_pc150u
;
994 dev
->init_data
.ir_codes
= RC_MAP_KWORLD_PC150U
;
996 /* MSI TV@nywhere Plus controller doesn't seem to
997 respond to probes unless we read something from
998 an existing device. Weird...
999 REVISIT: might no longer be needed */
1000 rc
= i2c_transfer(&dev
->i2c_adap
, &msg_msi
, 1);
1001 input_dbg("probe 0x%02x @ %s: %s\n",
1002 msg_msi
.addr
, dev
->i2c_adap
.name
,
1003 (1 == rc
) ? "yes" : "no");
1005 case SAA7134_BOARD_HAUPPAUGE_HVR1110
:
1006 dev
->init_data
.name
= "HVR 1110";
1007 dev
->init_data
.get_key
= get_key_hvr1110
;
1008 dev
->init_data
.ir_codes
= RC_MAP_HAUPPAUGE
;
1011 case SAA7134_BOARD_BEHOLD_607FM_MK3
:
1012 case SAA7134_BOARD_BEHOLD_607FM_MK5
:
1013 case SAA7134_BOARD_BEHOLD_609FM_MK3
:
1014 case SAA7134_BOARD_BEHOLD_609FM_MK5
:
1015 case SAA7134_BOARD_BEHOLD_607RDS_MK3
:
1016 case SAA7134_BOARD_BEHOLD_607RDS_MK5
:
1017 case SAA7134_BOARD_BEHOLD_609RDS_MK3
:
1018 case SAA7134_BOARD_BEHOLD_609RDS_MK5
:
1019 case SAA7134_BOARD_BEHOLD_M6
:
1020 case SAA7134_BOARD_BEHOLD_M63
:
1021 case SAA7134_BOARD_BEHOLD_M6_EXTRA
:
1022 case SAA7134_BOARD_BEHOLD_H6
:
1023 case SAA7134_BOARD_BEHOLD_X7
:
1024 case SAA7134_BOARD_BEHOLD_H7
:
1025 case SAA7134_BOARD_BEHOLD_A7
:
1026 dev
->init_data
.name
= "BeholdTV";
1027 dev
->init_data
.get_key
= get_key_beholdm6xx
;
1028 dev
->init_data
.ir_codes
= RC_MAP_BEHOLD
;
1029 dev
->init_data
.type
= RC_PROTO_BIT_NECX
;
1032 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501
:
1033 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506
:
1036 case SAA7134_BOARD_AVERMEDIA_A706
:
1039 case SAA7134_BOARD_FLYDVB_TRIO
:
1040 dev
->init_data
.name
= "FlyDVB Trio";
1041 dev
->init_data
.get_key
= get_key_flydvb_trio
;
1042 dev
->init_data
.ir_codes
= RC_MAP_FLYDVB
;
1046 input_dbg("No I2C IR support for board %x\n", dev
->board
);
1050 if (dev
->init_data
.name
)
1051 info
.platform_data
= &dev
->init_data
;
1052 i2c_new_device(&dev
->i2c_adap
, &info
);
1055 static int saa7134_raw_decode_irq(struct saa7134_dev
*dev
)
1057 struct saa7134_card_ir
*ir
= dev
->remote
;
1060 /* Generate initial event */
1061 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
1062 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
1063 space
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2) & ir
->mask_keydown
;
1064 ir_raw_event_store_edge(dev
->remote
->dev
, !space
);