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->name, ## arg); \
49 /* Helper function for raw decoding at GPIO16 or GPIO18 */
50 static int saa7134_raw_decode_irq(struct saa7134_dev
*dev
);
52 /* -------------------- GPIO generic keycode builder -------------------- */
54 static int build_key(struct saa7134_dev
*dev
)
56 struct saa7134_card_ir
*ir
= dev
->remote
;
59 /* here comes the additional handshake steps for some cards */
61 case SAA7134_BOARD_GOTVIEW_7135
:
62 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x80);
63 saa_clearb(SAA7134_GPIO_GPSTATUS1
, 0x80);
66 /* rising SAA7134_GPIO_GPRESCAN reads the status */
67 saa_clearb(SAA7134_GPIO_GPMODE3
,SAA7134_GPIO_GPRESCAN
);
68 saa_setb(SAA7134_GPIO_GPMODE3
,SAA7134_GPIO_GPRESCAN
);
70 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
72 if (ir
->last_gpio
== gpio
)
77 data
= ir_extract_bits(gpio
, ir
->mask_keycode
);
78 input_dbg("build_key gpio=0x%x mask=0x%x data=%d\n",
79 gpio
, ir
->mask_keycode
, data
);
82 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG
:
83 if (data
== ir
->mask_keycode
)
86 rc_keydown_notimeout(ir
->dev
, RC_TYPE_UNKNOWN
, data
, 0);
91 if ((ir
->mask_keydown
&& (0 != (gpio
& ir
->mask_keydown
))) ||
92 (ir
->mask_keyup
&& (0 == (gpio
& ir
->mask_keyup
)))) {
93 rc_keydown_notimeout(ir
->dev
, RC_TYPE_UNKNOWN
, data
, 0);
98 else { /* IRQ driven mode - handle key press and release in one go */
99 if ((ir
->mask_keydown
&& (0 != (gpio
& ir
->mask_keydown
))) ||
100 (ir
->mask_keyup
&& (0 == (gpio
& ir
->mask_keyup
)))) {
101 rc_keydown_notimeout(ir
->dev
, RC_TYPE_UNKNOWN
, data
, 0);
109 /* --------------------- Chip specific I2C key builders ----------------- */
111 static int get_key_flydvb_trio(struct IR_i2c
*ir
, enum rc_type
*protocol
,
112 u32
*scancode
, u8
*toggle
)
118 /* We need this to access GPI Used by the saa_readl macro. */
119 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
122 ir_dbg(ir
, "get_key_flydvb_trio: ir->c->adapter->algo_data is NULL!\n");
126 /* rising SAA7134_GPIGPRESCAN reads the status */
127 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
128 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
130 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
133 return 0; /* No button press */
136 /* weak up the IR chip */
139 while (1 != i2c_master_send(ir
->c
, &b
, 1)) {
140 if ((attempt
++) < 10) {
142 * wait a bit for next attempt -
143 * I don't know how make it better
148 ir_dbg(ir
, "send wake up byte to pic16C505 (IR chip)failed %dx\n",
152 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
153 ir_dbg(ir
, "read error\n");
157 *protocol
= RC_TYPE_UNKNOWN
;
163 static int get_key_msi_tvanywhere_plus(struct IR_i2c
*ir
, enum rc_type
*protocol
,
164 u32
*scancode
, u8
*toggle
)
169 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
170 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
172 ir_dbg(ir
, "get_key_msi_tvanywhere_plus: ir->c->adapter->algo_data is NULL!\n");
176 /* rising SAA7134_GPIO_GPRESCAN reads the status */
178 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
179 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
181 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
183 /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
184 I2C receive if gpio&0x40 is not low. */
187 return 0; /* No button press */
189 /* GPIO says there is a button press. Get it. */
191 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
192 ir_dbg(ir
, "read error\n");
196 /* No button press */
203 input_dbg("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b
);
204 *protocol
= RC_TYPE_UNKNOWN
;
210 /* copied and modified from get_key_msi_tvanywhere_plus() */
211 static int get_key_kworld_pc150u(struct IR_i2c
*ir
, enum rc_type
*protocol
,
212 u32
*scancode
, u8
*toggle
)
217 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
218 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
220 ir_dbg(ir
, "get_key_kworld_pc150u: ir->c->adapter->algo_data is NULL!\n");
224 /* rising SAA7134_GPIO_GPRESCAN reads the status */
226 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
227 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
229 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
231 /* GPIO&0x100 is pulsed low when a button is pressed. Don't do
232 I2C receive if gpio&0x100 is not low. */
235 return 0; /* No button press */
237 /* GPIO says there is a button press. Get it. */
239 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
240 ir_dbg(ir
, "read error\n");
244 /* No button press */
251 input_dbg("get_key_kworld_pc150u: Key = 0x%02X\n", b
);
252 *protocol
= RC_TYPE_UNKNOWN
;
258 static int get_key_purpletv(struct IR_i2c
*ir
, enum rc_type
*protocol
,
259 u32
*scancode
, u8
*toggle
)
264 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
265 ir_dbg(ir
, "read error\n");
269 /* no button press */
277 *protocol
= RC_TYPE_UNKNOWN
;
283 static int get_key_hvr1110(struct IR_i2c
*ir
, enum rc_type
*protocol
,
284 u32
*scancode
, u8
*toggle
)
286 unsigned char buf
[5];
289 if (5 != i2c_master_recv(ir
->c
, buf
, 5))
292 /* Check if some key were pressed */
293 if (!(buf
[0] & 0x80))
297 * buf[3] & 0x80 is always high.
298 * buf[3] & 0x40 is a parity bit. A repeat event is marked
299 * by preserving it into two separate readings
300 * buf[4] bits 0 and 1, and buf[1] and buf[2] are always
303 * Note that the keymap which the hvr1110 uses is RC5.
305 * FIXME: start bits could maybe be used...?
307 *protocol
= RC_TYPE_RC5
;
308 *scancode
= RC_SCANCODE_RC5(buf
[3] & 0x1f, buf
[4] >> 2);
309 *toggle
= !!(buf
[3] & 0x40);
314 static int get_key_beholdm6xx(struct IR_i2c
*ir
, enum rc_type
*protocol
,
315 u32
*scancode
, u8
*toggle
)
317 unsigned char data
[12];
320 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
322 /* rising SAA7134_GPIO_GPRESCAN reads the status */
323 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
324 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
326 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
328 if (0x400000 & ~gpio
)
329 return 0; /* No button press */
331 ir
->c
->addr
= 0x5a >> 1;
333 if (12 != i2c_master_recv(ir
->c
, data
, 12)) {
334 ir_dbg(ir
, "read error\n");
338 if (data
[9] != (unsigned char)(~data
[8]))
341 *protocol
= RC_TYPE_NECX
;
342 *scancode
= RC_SCANCODE_NECX(data
[11] << 8 | data
[10], data
[9]);
347 /* Common (grey or coloured) pinnacle PCTV remote handling
350 static int get_key_pinnacle(struct IR_i2c
*ir
, enum rc_type
*protocol
,
351 u32
*scancode
, u8
*toggle
, int parity_offset
,
352 int marker
, int code_modulo
)
355 unsigned int start
= 0,parity
= 0,code
= 0;
358 if (4 != i2c_master_recv(ir
->c
, b
, 4)) {
359 ir_dbg(ir
, "read error\n");
363 for (start
= 0; start
< ARRAY_SIZE(b
); start
++) {
364 if (b
[start
] == marker
) {
365 code
=b
[(start
+parity_offset
+ 1) % 4];
366 parity
=b
[(start
+parity_offset
) % 4];
375 if (ir
->old
== parity
)
380 /* drop special codes when a key is held down a long time for the grey controller
381 In this case, the second bit of the code is asserted */
382 if (marker
== 0xfe && (code
& 0x40))
387 *protocol
= RC_TYPE_UNKNOWN
;
391 ir_dbg(ir
, "Pinnacle PCTV key %02x\n", code
);
395 /* The grey pinnacle PCTV remote
397 * There are one issue with this remote:
398 * - I2c packet does not change when the same key is pressed quickly. The workaround
399 * is to hold down each key for about half a second, so that another code is generated
400 * in the i2c packet, and the function can distinguish key presses.
402 * Sylvain Pasche <sylvain.pasche@gmail.com>
404 static int get_key_pinnacle_grey(struct IR_i2c
*ir
, enum rc_type
*protocol
,
405 u32
*scancode
, u8
*toggle
)
408 return get_key_pinnacle(ir
, protocol
, scancode
, toggle
, 1, 0xfe, 0xff);
412 /* The new pinnacle PCTV remote (with the colored buttons)
414 * Ricardo Cerqueira <v4l@cerqueira.org>
416 static int get_key_pinnacle_color(struct IR_i2c
*ir
, enum rc_type
*protocol
,
417 u32
*scancode
, u8
*toggle
)
419 /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
421 * this is the only value that results in 42 unique
425 return get_key_pinnacle(ir
, protocol
, scancode
, toggle
, 2, 0x80, 0x88);
428 void saa7134_input_irq(struct saa7134_dev
*dev
)
430 struct saa7134_card_ir
*ir
;
432 if (!dev
|| !dev
->remote
)
439 if (!ir
->polling
&& !ir
->raw_decode
) {
441 } else if (ir
->raw_decode
) {
442 saa7134_raw_decode_irq(dev
);
446 static void saa7134_input_timer(unsigned long data
)
448 struct saa7134_dev
*dev
= (struct saa7134_dev
*)data
;
449 struct saa7134_card_ir
*ir
= dev
->remote
;
452 mod_timer(&ir
->timer
, jiffies
+ msecs_to_jiffies(ir
->polling
));
455 static void ir_raw_decode_timer_end(unsigned long data
)
457 struct saa7134_dev
*dev
= (struct saa7134_dev
*)data
;
459 ir_raw_event_handle(dev
->remote
->dev
);
462 static int __saa7134_ir_start(void *priv
)
464 struct saa7134_dev
*dev
= priv
;
465 struct saa7134_card_ir
*ir
;
467 if (!dev
|| !dev
->remote
)
474 /* Moved here from saa7134_input_init1() because the latter
475 * is not called on device resume */
476 switch (dev
->board
) {
477 case SAA7134_BOARD_MD2819
:
478 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT
:
479 case SAA7134_BOARD_AVERMEDIA_305
:
480 case SAA7134_BOARD_AVERMEDIA_307
:
481 case SAA7134_BOARD_AVERMEDIA_505
:
482 case SAA7134_BOARD_AVERMEDIA_STUDIO_305
:
483 case SAA7134_BOARD_AVERMEDIA_STUDIO_505
:
484 case SAA7134_BOARD_AVERMEDIA_STUDIO_307
:
485 case SAA7134_BOARD_AVERMEDIA_STUDIO_507
:
486 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA
:
487 case SAA7134_BOARD_AVERMEDIA_GO_007_FM
:
488 case SAA7134_BOARD_AVERMEDIA_M102
:
489 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS
:
490 /* Without this we won't receive key up events */
491 saa_setb(SAA7134_GPIO_GPMODE0
, 0x4);
492 saa_setb(SAA7134_GPIO_GPSTATUS0
, 0x4);
494 case SAA7134_BOARD_AVERMEDIA_777
:
495 case SAA7134_BOARD_AVERMEDIA_A16AR
:
496 /* Without this we won't receive key up events */
497 saa_setb(SAA7134_GPIO_GPMODE1
, 0x1);
498 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x1);
500 case SAA7134_BOARD_AVERMEDIA_A16D
:
501 /* Without this we won't receive key up events */
502 saa_setb(SAA7134_GPIO_GPMODE1
, 0x1);
503 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x1);
505 case SAA7134_BOARD_GOTVIEW_7135
:
506 saa_setb(SAA7134_GPIO_GPMODE1
, 0x80);
513 setup_timer(&ir
->timer
, saa7134_input_timer
,
515 ir
->timer
.expires
= jiffies
+ HZ
;
516 add_timer(&ir
->timer
);
517 } else if (ir
->raw_decode
) {
518 /* set timer_end for code completion */
519 setup_timer(&ir
->timer
, ir_raw_decode_timer_end
,
526 static void __saa7134_ir_stop(void *priv
)
528 struct saa7134_dev
*dev
= priv
;
529 struct saa7134_card_ir
*ir
;
531 if (!dev
|| !dev
->remote
)
538 if (ir
->polling
|| ir
->raw_decode
)
539 del_timer_sync(&ir
->timer
);
546 int saa7134_ir_start(struct saa7134_dev
*dev
)
548 if (dev
->remote
->users
)
549 return __saa7134_ir_start(dev
);
554 void saa7134_ir_stop(struct saa7134_dev
*dev
)
556 if (dev
->remote
->users
)
557 __saa7134_ir_stop(dev
);
560 static int saa7134_ir_open(struct rc_dev
*rc
)
562 struct saa7134_dev
*dev
= rc
->priv
;
564 dev
->remote
->users
++;
565 return __saa7134_ir_start(dev
);
568 static void saa7134_ir_close(struct rc_dev
*rc
)
570 struct saa7134_dev
*dev
= rc
->priv
;
572 dev
->remote
->users
--;
573 if (!dev
->remote
->users
)
574 __saa7134_ir_stop(dev
);
577 int saa7134_input_init1(struct saa7134_dev
*dev
)
579 struct saa7134_card_ir
*ir
;
581 char *ir_codes
= NULL
;
582 u32 mask_keycode
= 0;
583 u32 mask_keydown
= 0;
585 unsigned polling
= 0;
586 bool raw_decode
= false;
589 if (dev
->has_remote
!= SAA7134_REMOTE_GPIO
)
594 /* detect & configure */
595 switch (dev
->board
) {
596 case SAA7134_BOARD_FLYVIDEO2000
:
597 case SAA7134_BOARD_FLYVIDEO3000
:
598 case SAA7134_BOARD_FLYTVPLATINUM_FM
:
599 case SAA7134_BOARD_FLYTVPLATINUM_MINI2
:
600 case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM
:
601 ir_codes
= RC_MAP_FLYVIDEO
;
602 mask_keycode
= 0xEC00000;
603 mask_keydown
= 0x0040000;
605 case SAA7134_BOARD_CINERGY400
:
606 case SAA7134_BOARD_CINERGY600
:
607 case SAA7134_BOARD_CINERGY600_MK3
:
608 ir_codes
= RC_MAP_CINERGY
;
609 mask_keycode
= 0x00003f;
610 mask_keyup
= 0x040000;
612 case SAA7134_BOARD_ECS_TVP3XP
:
613 case SAA7134_BOARD_ECS_TVP3XP_4CB5
:
614 ir_codes
= RC_MAP_EZTV
;
615 mask_keycode
= 0x00017c;
616 mask_keyup
= 0x000002;
619 case SAA7134_BOARD_KWORLD_XPERT
:
620 case SAA7134_BOARD_AVACSSMARTTV
:
621 ir_codes
= RC_MAP_PIXELVIEW
;
622 mask_keycode
= 0x00001F;
623 mask_keyup
= 0x000020;
626 case SAA7134_BOARD_MD2819
:
627 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT
:
628 case SAA7134_BOARD_AVERMEDIA_305
:
629 case SAA7134_BOARD_AVERMEDIA_307
:
630 case SAA7134_BOARD_AVERMEDIA_505
:
631 case SAA7134_BOARD_AVERMEDIA_STUDIO_305
:
632 case SAA7134_BOARD_AVERMEDIA_STUDIO_505
:
633 case SAA7134_BOARD_AVERMEDIA_STUDIO_307
:
634 case SAA7134_BOARD_AVERMEDIA_STUDIO_507
:
635 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA
:
636 case SAA7134_BOARD_AVERMEDIA_GO_007_FM
:
637 case SAA7134_BOARD_AVERMEDIA_M102
:
638 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS
:
639 ir_codes
= RC_MAP_AVERMEDIA
;
640 mask_keycode
= 0x0007C8;
641 mask_keydown
= 0x000010;
643 /* GPIO stuff moved to __saa7134_ir_start() */
645 case SAA7134_BOARD_AVERMEDIA_M135A
:
646 ir_codes
= RC_MAP_AVERMEDIA_M135A
;
647 mask_keydown
= 0x0040000; /* Enable GPIO18 line on both edges */
648 mask_keyup
= 0x0040000;
649 mask_keycode
= 0xffff;
652 case SAA7134_BOARD_AVERMEDIA_M733A
:
653 ir_codes
= RC_MAP_AVERMEDIA_M733A_RM_K6
;
654 mask_keydown
= 0x0040000;
655 mask_keyup
= 0x0040000;
656 mask_keycode
= 0xffff;
659 case SAA7134_BOARD_AVERMEDIA_777
:
660 case SAA7134_BOARD_AVERMEDIA_A16AR
:
661 ir_codes
= RC_MAP_AVERMEDIA
;
662 mask_keycode
= 0x02F200;
663 mask_keydown
= 0x000400;
665 /* GPIO stuff moved to __saa7134_ir_start() */
667 case SAA7134_BOARD_AVERMEDIA_A16D
:
668 ir_codes
= RC_MAP_AVERMEDIA_A16D
;
669 mask_keycode
= 0x02F200;
670 mask_keydown
= 0x000400;
671 polling
= 50; /* ms */
672 /* GPIO stuff moved to __saa7134_ir_start() */
674 case SAA7134_BOARD_KWORLD_TERMINATOR
:
675 ir_codes
= RC_MAP_PIXELVIEW
;
676 mask_keycode
= 0x00001f;
677 mask_keyup
= 0x000060;
680 case SAA7134_BOARD_MANLI_MTV001
:
681 case SAA7134_BOARD_MANLI_MTV002
:
682 ir_codes
= RC_MAP_MANLI
;
683 mask_keycode
= 0x001f00;
684 mask_keyup
= 0x004000;
685 polling
= 50; /* ms */
687 case SAA7134_BOARD_BEHOLD_409FM
:
688 case SAA7134_BOARD_BEHOLD_401
:
689 case SAA7134_BOARD_BEHOLD_403
:
690 case SAA7134_BOARD_BEHOLD_403FM
:
691 case SAA7134_BOARD_BEHOLD_405
:
692 case SAA7134_BOARD_BEHOLD_405FM
:
693 case SAA7134_BOARD_BEHOLD_407
:
694 case SAA7134_BOARD_BEHOLD_407FM
:
695 case SAA7134_BOARD_BEHOLD_409
:
696 case SAA7134_BOARD_BEHOLD_505FM
:
697 case SAA7134_BOARD_BEHOLD_505RDS_MK5
:
698 case SAA7134_BOARD_BEHOLD_505RDS_MK3
:
699 case SAA7134_BOARD_BEHOLD_507_9FM
:
700 case SAA7134_BOARD_BEHOLD_507RDS_MK3
:
701 case SAA7134_BOARD_BEHOLD_507RDS_MK5
:
702 ir_codes
= RC_MAP_MANLI
;
703 mask_keycode
= 0x003f00;
704 mask_keyup
= 0x004000;
705 polling
= 50; /* ms */
707 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM
:
708 ir_codes
= RC_MAP_BEHOLD_COLUMBUS
;
709 mask_keycode
= 0x003f00;
710 mask_keyup
= 0x004000;
713 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS
:
714 ir_codes
= RC_MAP_PCTV_SEDNA
;
715 mask_keycode
= 0x001f00;
716 mask_keyup
= 0x004000;
719 case SAA7134_BOARD_GOTVIEW_7135
:
720 ir_codes
= RC_MAP_GOTVIEW7135
;
721 mask_keycode
= 0x0003CC;
722 mask_keydown
= 0x000010;
723 polling
= 5; /* ms */
724 /* GPIO stuff moved to __saa7134_ir_start() */
726 case SAA7134_BOARD_VIDEOMATE_TV_PVR
:
727 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS
:
728 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII
:
729 ir_codes
= RC_MAP_VIDEOMATE_TV_PVR
;
730 mask_keycode
= 0x00003F;
731 mask_keyup
= 0x400000;
734 case SAA7134_BOARD_PROTEUS_2309
:
735 ir_codes
= RC_MAP_PROTEUS_2309
;
736 mask_keycode
= 0x00007F;
737 mask_keyup
= 0x000080;
740 case SAA7134_BOARD_VIDEOMATE_DVBT_300
:
741 case SAA7134_BOARD_VIDEOMATE_DVBT_200
:
742 ir_codes
= RC_MAP_VIDEOMATE_TV_PVR
;
743 mask_keycode
= 0x003F00;
744 mask_keyup
= 0x040000;
746 case SAA7134_BOARD_FLYDVBS_LR300
:
747 case SAA7134_BOARD_FLYDVBT_LR301
:
748 case SAA7134_BOARD_FLYDVBTDUO
:
749 ir_codes
= RC_MAP_FLYDVB
;
750 mask_keycode
= 0x0001F00;
751 mask_keydown
= 0x0040000;
753 case SAA7134_BOARD_ASUSTeK_P7131_DUAL
:
754 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA
:
755 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG
:
756 ir_codes
= RC_MAP_ASUS_PC39
;
757 mask_keydown
= 0x0040000; /* Enable GPIO18 line on both edges */
758 mask_keyup
= 0x0040000;
759 mask_keycode
= 0xffff;
762 case SAA7134_BOARD_ASUSTeK_PS3_100
:
763 ir_codes
= RC_MAP_ASUS_PS3_100
;
764 mask_keydown
= 0x0040000;
765 mask_keyup
= 0x0040000;
766 mask_keycode
= 0xffff;
769 case SAA7134_BOARD_ENCORE_ENLTV
:
770 case SAA7134_BOARD_ENCORE_ENLTV_FM
:
771 ir_codes
= RC_MAP_ENCORE_ENLTV
;
772 mask_keycode
= 0x00007f;
773 mask_keyup
= 0x040000;
776 case SAA7134_BOARD_ENCORE_ENLTV_FM53
:
777 case SAA7134_BOARD_ENCORE_ENLTV_FM3
:
778 ir_codes
= RC_MAP_ENCORE_ENLTV_FM53
;
779 mask_keydown
= 0x0040000; /* Enable GPIO18 line on both edges */
780 mask_keyup
= 0x0040000;
781 mask_keycode
= 0xffff;
784 case SAA7134_BOARD_10MOONSTVMASTER3
:
785 ir_codes
= RC_MAP_ENCORE_ENLTV
;
786 mask_keycode
= 0x5f80000;
787 mask_keyup
= 0x8000000;
790 case SAA7134_BOARD_GENIUS_TVGO_A11MCE
:
791 ir_codes
= RC_MAP_GENIUS_TVGO_A11MCE
;
793 mask_keydown
= 0xf00000;
794 polling
= 50; /* ms */
796 case SAA7134_BOARD_REAL_ANGEL_220
:
797 ir_codes
= RC_MAP_REAL_AUDIO_220_32_KEYS
;
798 mask_keycode
= 0x3f00;
800 polling
= 50; /* ms */
802 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG
:
803 ir_codes
= RC_MAP_KWORLD_PLUS_TV_ANALOG
;
805 polling
= 40; /* ms */
807 case SAA7134_BOARD_VIDEOMATE_S350
:
808 ir_codes
= RC_MAP_VIDEOMATE_S350
;
809 mask_keycode
= 0x003f00;
810 mask_keydown
= 0x040000;
812 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S
:
813 ir_codes
= RC_MAP_WINFAST
;
814 mask_keycode
= 0x5f00;
815 mask_keyup
= 0x020000;
816 polling
= 50; /* ms */
818 case SAA7134_BOARD_VIDEOMATE_M1F
:
819 ir_codes
= RC_MAP_VIDEOMATE_K100
;
820 mask_keycode
= 0x0ff00;
821 mask_keyup
= 0x040000;
823 case SAA7134_BOARD_HAUPPAUGE_HVR1150
:
824 case SAA7134_BOARD_HAUPPAUGE_HVR1120
:
825 ir_codes
= RC_MAP_HAUPPAUGE
;
826 mask_keydown
= 0x0040000; /* Enable GPIO18 line on both edges */
827 mask_keyup
= 0x0040000;
828 mask_keycode
= 0xffff;
831 case SAA7134_BOARD_LEADTEK_WINFAST_TV2100_FM
:
832 ir_codes
= RC_MAP_LEADTEK_Y04G0051
;
833 mask_keydown
= 0x0040000; /* Enable GPIO18 line on both edges */
834 mask_keyup
= 0x0040000;
835 mask_keycode
= 0xffff;
839 if (NULL
== ir_codes
) {
840 pr_err("Oops: IR config error [card=%d]\n", dev
->board
);
844 ir
= kzalloc(sizeof(*ir
), GFP_KERNEL
);
845 rc
= rc_allocate_device(RC_DRIVER_SCANCODE
);
854 /* init hardware-specific stuff */
855 ir
->mask_keycode
= mask_keycode
;
856 ir
->mask_keydown
= mask_keydown
;
857 ir
->mask_keyup
= mask_keyup
;
858 ir
->polling
= polling
;
859 ir
->raw_decode
= raw_decode
;
861 /* init input device */
862 snprintf(ir
->name
, sizeof(ir
->name
), "saa7134 IR (%s)",
863 saa7134_boards
[dev
->board
].name
);
864 snprintf(ir
->phys
, sizeof(ir
->phys
), "pci-%s/ir0",
868 rc
->open
= saa7134_ir_open
;
869 rc
->close
= saa7134_ir_close
;
871 rc
->driver_type
= RC_DRIVER_IR_RAW
;
873 rc
->input_name
= ir
->name
;
874 rc
->input_phys
= ir
->phys
;
875 rc
->input_id
.bustype
= BUS_PCI
;
876 rc
->input_id
.version
= 1;
877 if (dev
->pci
->subsystem_vendor
) {
878 rc
->input_id
.vendor
= dev
->pci
->subsystem_vendor
;
879 rc
->input_id
.product
= dev
->pci
->subsystem_device
;
881 rc
->input_id
.vendor
= dev
->pci
->vendor
;
882 rc
->input_id
.product
= dev
->pci
->device
;
884 rc
->dev
.parent
= &dev
->pci
->dev
;
885 rc
->map_name
= ir_codes
;
886 rc
->driver_name
= MODULE_NAME
;
888 err
= rc_register_device(rc
);
901 void saa7134_input_fini(struct saa7134_dev
*dev
)
903 if (NULL
== dev
->remote
)
906 saa7134_ir_stop(dev
);
907 rc_unregister_device(dev
->remote
->dev
);
912 void saa7134_probe_i2c_ir(struct saa7134_dev
*dev
)
914 struct i2c_board_info info
;
915 struct i2c_msg msg_msi
= {
924 input_dbg("IR has been disabled, not probing for i2c remote\n");
928 memset(&info
, 0, sizeof(struct i2c_board_info
));
929 memset(&dev
->init_data
, 0, sizeof(dev
->init_data
));
930 strlcpy(info
.type
, "ir_video", I2C_NAME_SIZE
);
932 switch (dev
->board
) {
933 case SAA7134_BOARD_PINNACLE_PCTV_110i
:
934 case SAA7134_BOARD_PINNACLE_PCTV_310i
:
935 dev
->init_data
.name
= "Pinnacle PCTV";
936 if (pinnacle_remote
== 0) {
937 dev
->init_data
.get_key
= get_key_pinnacle_color
;
938 dev
->init_data
.ir_codes
= RC_MAP_PINNACLE_COLOR
;
941 dev
->init_data
.get_key
= get_key_pinnacle_grey
;
942 dev
->init_data
.ir_codes
= RC_MAP_PINNACLE_GREY
;
946 case SAA7134_BOARD_UPMOST_PURPLE_TV
:
947 dev
->init_data
.name
= "Purple TV";
948 dev
->init_data
.get_key
= get_key_purpletv
;
949 dev
->init_data
.ir_codes
= RC_MAP_PURPLETV
;
952 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS
:
953 dev
->init_data
.name
= "MSI TV@nywhere Plus";
954 dev
->init_data
.get_key
= get_key_msi_tvanywhere_plus
;
955 dev
->init_data
.ir_codes
= RC_MAP_MSI_TVANYWHERE_PLUS
;
957 * MSI TV@nyware Plus requires more frequent polling
958 * otherwise it will miss some keypresses
960 dev
->init_data
.polling_interval
= 50;
962 /* MSI TV@nywhere Plus controller doesn't seem to
963 respond to probes unless we read something from
964 an existing device. Weird...
965 REVISIT: might no longer be needed */
966 rc
= i2c_transfer(&dev
->i2c_adap
, &msg_msi
, 1);
967 input_dbg("probe 0x%02x @ %s: %s\n",
968 msg_msi
.addr
, dev
->i2c_adap
.name
,
969 (1 == rc
) ? "yes" : "no");
971 case SAA7134_BOARD_SNAZIO_TVPVR_PRO
:
972 dev
->init_data
.name
= "SnaZio* TVPVR PRO";
973 dev
->init_data
.get_key
= get_key_msi_tvanywhere_plus
;
974 dev
->init_data
.ir_codes
= RC_MAP_MSI_TVANYWHERE_PLUS
;
976 * MSI TV@nyware Plus requires more frequent polling
977 * otherwise it will miss some keypresses
979 dev
->init_data
.polling_interval
= 50;
982 * MSI TV@nywhere Plus controller doesn't seem to
983 * respond to probes unless we read something from
984 * an existing device. Weird...
985 * REVISIT: might no longer be needed
987 rc
= i2c_transfer(&dev
->i2c_adap
, &msg_msi
, 1);
988 input_dbg("probe 0x%02x @ %s: %s\n",
989 msg_msi
.addr
, dev
->i2c_adap
.name
,
990 (rc
== 1) ? "yes" : "no");
992 case SAA7134_BOARD_KWORLD_PC150U
:
993 /* copied and modified from MSI TV@nywhere Plus */
994 dev
->init_data
.name
= "Kworld PC150-U";
995 dev
->init_data
.get_key
= get_key_kworld_pc150u
;
996 dev
->init_data
.ir_codes
= RC_MAP_KWORLD_PC150U
;
998 /* MSI TV@nywhere Plus controller doesn't seem to
999 respond to probes unless we read something from
1000 an existing device. Weird...
1001 REVISIT: might no longer be needed */
1002 rc
= i2c_transfer(&dev
->i2c_adap
, &msg_msi
, 1);
1003 input_dbg("probe 0x%02x @ %s: %s\n",
1004 msg_msi
.addr
, dev
->i2c_adap
.name
,
1005 (1 == rc
) ? "yes" : "no");
1007 case SAA7134_BOARD_HAUPPAUGE_HVR1110
:
1008 dev
->init_data
.name
= "HVR 1110";
1009 dev
->init_data
.get_key
= get_key_hvr1110
;
1010 dev
->init_data
.ir_codes
= RC_MAP_HAUPPAUGE
;
1013 case SAA7134_BOARD_BEHOLD_607FM_MK3
:
1014 case SAA7134_BOARD_BEHOLD_607FM_MK5
:
1015 case SAA7134_BOARD_BEHOLD_609FM_MK3
:
1016 case SAA7134_BOARD_BEHOLD_609FM_MK5
:
1017 case SAA7134_BOARD_BEHOLD_607RDS_MK3
:
1018 case SAA7134_BOARD_BEHOLD_607RDS_MK5
:
1019 case SAA7134_BOARD_BEHOLD_609RDS_MK3
:
1020 case SAA7134_BOARD_BEHOLD_609RDS_MK5
:
1021 case SAA7134_BOARD_BEHOLD_M6
:
1022 case SAA7134_BOARD_BEHOLD_M63
:
1023 case SAA7134_BOARD_BEHOLD_M6_EXTRA
:
1024 case SAA7134_BOARD_BEHOLD_H6
:
1025 case SAA7134_BOARD_BEHOLD_X7
:
1026 case SAA7134_BOARD_BEHOLD_H7
:
1027 case SAA7134_BOARD_BEHOLD_A7
:
1028 dev
->init_data
.name
= "BeholdTV";
1029 dev
->init_data
.get_key
= get_key_beholdm6xx
;
1030 dev
->init_data
.ir_codes
= RC_MAP_BEHOLD
;
1031 dev
->init_data
.type
= RC_BIT_NECX
;
1034 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501
:
1035 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506
:
1038 case SAA7134_BOARD_AVERMEDIA_A706
:
1041 case SAA7134_BOARD_FLYDVB_TRIO
:
1042 dev
->init_data
.name
= "FlyDVB Trio";
1043 dev
->init_data
.get_key
= get_key_flydvb_trio
;
1044 dev
->init_data
.ir_codes
= RC_MAP_FLYDVB
;
1048 input_dbg("No I2C IR support for board %x\n", dev
->board
);
1052 if (dev
->init_data
.name
)
1053 info
.platform_data
= &dev
->init_data
;
1054 i2c_new_device(&dev
->i2c_adap
, &info
);
1057 static int saa7134_raw_decode_irq(struct saa7134_dev
*dev
)
1059 struct saa7134_card_ir
*ir
= dev
->remote
;
1060 unsigned long timeout
;
1063 /* Generate initial event */
1064 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
1065 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
1066 space
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2) & ir
->mask_keydown
;
1067 ir_raw_event_store_edge(dev
->remote
->dev
, space
? IR_SPACE
: IR_PULSE
);
1070 * Wait 15 ms from the start of the first IR event before processing
1071 * the event. This time is enough for NEC protocol. May need adjustments
1072 * to work with other protocols.
1076 if (!timer_pending(&ir
->timer
)) {
1077 timeout
= jiffies
+ msecs_to_jiffies(15);
1078 mod_timer(&ir
->timer
, timeout
);