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/slab.h>
27 #include "saa7134-reg.h"
30 #define MODULE_NAME "saa7134"
32 static unsigned int disable_ir
;
33 module_param(disable_ir
, int, 0444);
34 MODULE_PARM_DESC(disable_ir
,"disable infrared remote support");
36 static unsigned int ir_debug
;
37 module_param(ir_debug
, int, 0644);
38 MODULE_PARM_DESC(ir_debug
,"enable debug messages [IR]");
40 static int pinnacle_remote
;
41 module_param(pinnacle_remote
, int, 0644); /* Choose Pinnacle PCTV remote */
42 MODULE_PARM_DESC(pinnacle_remote
, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
44 #define dprintk(fmt, arg...) if (ir_debug) \
45 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
46 #define i2cdprintk(fmt, arg...) if (ir_debug) \
47 printk(KERN_DEBUG "%s/ir: " 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 dprintk("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
, 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
, 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
, data
, 0);
109 /* --------------------- Chip specific I2C key builders ----------------- */
111 static int get_key_flydvb_trio(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
117 /* We need this to access GPI Used by the saa_readl macro. */
118 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
121 i2cdprintk("get_key_flydvb_trio: "
122 "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 */
135 /* No button press - only before first key pressed */
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 i2cdprintk("send wake up byte to pic16C505 (IR chip)"
153 "failed %dx\n", attempt
);
156 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
157 i2cdprintk("read error\n");
166 static int get_key_msi_tvanywhere_plus(struct IR_i2c
*ir
, u32
*ir_key
,
172 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
173 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
175 i2cdprintk("get_key_msi_tvanywhere_plus: "
176 "ir->c->adapter->algo_data is NULL!\n");
180 /* rising SAA7134_GPIO_GPRESCAN reads the status */
182 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
183 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
185 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
187 /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
188 I2C receive if gpio&0x40 is not low. */
191 return 0; /* No button press */
193 /* GPIO says there is a button press. Get it. */
195 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
196 i2cdprintk("read error\n");
200 /* No button press */
207 dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b
);
213 static int get_key_purpletv(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
218 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
219 i2cdprintk("read error\n");
223 /* no button press */
236 static int get_key_hvr1110(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
238 unsigned char buf
[5], cod4
, code3
, code4
;
241 if (5 != i2c_master_recv(ir
->c
, buf
, 5))
258 static int get_key_beholdm6xx(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
260 unsigned char data
[12];
263 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
265 /* rising SAA7134_GPIO_GPRESCAN reads the status */
266 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
267 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
269 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
271 if (0x400000 & ~gpio
)
272 return 0; /* No button press */
274 ir
->c
->addr
= 0x5a >> 1;
276 if (12 != i2c_master_recv(ir
->c
, data
, 12)) {
277 i2cdprintk("read error\n");
281 if (data
[9] != (unsigned char)(~data
[8]))
284 *ir_raw
= ((data
[10] << 16) | (data
[11] << 8) | (data
[9] << 0));
290 /* Common (grey or coloured) pinnacle PCTV remote handling
293 static int get_key_pinnacle(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
,
294 int parity_offset
, int marker
, int code_modulo
)
297 unsigned int start
= 0,parity
= 0,code
= 0;
300 if (4 != i2c_master_recv(ir
->c
, b
, 4)) {
301 i2cdprintk("read error\n");
305 for (start
= 0; start
< ARRAY_SIZE(b
); start
++) {
306 if (b
[start
] == marker
) {
307 code
=b
[(start
+parity_offset
+ 1) % 4];
308 parity
=b
[(start
+parity_offset
) % 4];
317 if (ir
->old
== parity
)
322 /* drop special codes when a key is held down a long time for the grey controller
323 In this case, the second bit of the code is asserted */
324 if (marker
== 0xfe && (code
& 0x40))
332 i2cdprintk("Pinnacle PCTV key %02x\n", code
);
337 /* The grey pinnacle PCTV remote
339 * There are one issue with this remote:
340 * - I2c packet does not change when the same key is pressed quickly. The workaround
341 * is to hold down each key for about half a second, so that another code is generated
342 * in the i2c packet, and the function can distinguish key presses.
344 * Sylvain Pasche <sylvain.pasche@gmail.com>
346 static int get_key_pinnacle_grey(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
349 return get_key_pinnacle(ir
, ir_key
, ir_raw
, 1, 0xfe, 0xff);
353 /* The new pinnacle PCTV remote (with the colored buttons)
355 * Ricardo Cerqueira <v4l@cerqueira.org>
357 static int get_key_pinnacle_color(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
359 /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
361 * this is the only value that results in 42 unique
365 return get_key_pinnacle(ir
, ir_key
, ir_raw
, 2, 0x80, 0x88);
368 void saa7134_input_irq(struct saa7134_dev
*dev
)
370 struct saa7134_card_ir
*ir
;
372 if (!dev
|| !dev
->remote
)
379 if (!ir
->polling
&& !ir
->raw_decode
) {
381 } else if (ir
->raw_decode
) {
382 saa7134_raw_decode_irq(dev
);
386 static void saa7134_input_timer(unsigned long data
)
388 struct saa7134_dev
*dev
= (struct saa7134_dev
*)data
;
389 struct saa7134_card_ir
*ir
= dev
->remote
;
392 mod_timer(&ir
->timer
, jiffies
+ msecs_to_jiffies(ir
->polling
));
395 static void ir_raw_decode_timer_end(unsigned long data
)
397 struct saa7134_dev
*dev
= (struct saa7134_dev
*)data
;
398 struct saa7134_card_ir
*ir
= dev
->remote
;
400 ir_raw_event_handle(dev
->remote
->dev
);
405 static int __saa7134_ir_start(void *priv
)
407 struct saa7134_dev
*dev
= priv
;
408 struct saa7134_card_ir
*ir
;
410 if (!dev
|| !dev
->remote
)
421 setup_timer(&ir
->timer
, saa7134_input_timer
,
423 ir
->timer
.expires
= jiffies
+ HZ
;
424 add_timer(&ir
->timer
);
425 } else if (ir
->raw_decode
) {
426 /* set timer_end for code completion */
427 setup_timer(&ir
->timer
, ir_raw_decode_timer_end
,
434 static void __saa7134_ir_stop(void *priv
)
436 struct saa7134_dev
*dev
= priv
;
437 struct saa7134_card_ir
*ir
;
439 if (!dev
|| !dev
->remote
)
446 if (ir
->polling
|| ir
->raw_decode
)
447 del_timer_sync(&ir
->timer
);
455 int saa7134_ir_start(struct saa7134_dev
*dev
)
457 if (dev
->remote
->users
)
458 return __saa7134_ir_start(dev
);
463 void saa7134_ir_stop(struct saa7134_dev
*dev
)
465 if (dev
->remote
->users
)
466 __saa7134_ir_stop(dev
);
469 static int saa7134_ir_open(struct rc_dev
*rc
)
471 struct saa7134_dev
*dev
= rc
->priv
;
473 dev
->remote
->users
++;
474 return __saa7134_ir_start(dev
);
477 static void saa7134_ir_close(struct rc_dev
*rc
)
479 struct saa7134_dev
*dev
= rc
->priv
;
481 dev
->remote
->users
--;
482 if (!dev
->remote
->users
)
483 __saa7134_ir_stop(dev
);
486 int saa7134_input_init1(struct saa7134_dev
*dev
)
488 struct saa7134_card_ir
*ir
;
490 char *ir_codes
= NULL
;
491 u32 mask_keycode
= 0;
492 u32 mask_keydown
= 0;
494 unsigned polling
= 0;
495 bool raw_decode
= false;
498 if (dev
->has_remote
!= SAA7134_REMOTE_GPIO
)
503 /* detect & configure */
504 switch (dev
->board
) {
505 case SAA7134_BOARD_FLYVIDEO2000
:
506 case SAA7134_BOARD_FLYVIDEO3000
:
507 case SAA7134_BOARD_FLYTVPLATINUM_FM
:
508 case SAA7134_BOARD_FLYTVPLATINUM_MINI2
:
509 case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM
:
510 ir_codes
= RC_MAP_FLYVIDEO
;
511 mask_keycode
= 0xEC00000;
512 mask_keydown
= 0x0040000;
514 case SAA7134_BOARD_CINERGY400
:
515 case SAA7134_BOARD_CINERGY600
:
516 case SAA7134_BOARD_CINERGY600_MK3
:
517 ir_codes
= RC_MAP_CINERGY
;
518 mask_keycode
= 0x00003f;
519 mask_keyup
= 0x040000;
521 case SAA7134_BOARD_ECS_TVP3XP
:
522 case SAA7134_BOARD_ECS_TVP3XP_4CB5
:
523 ir_codes
= RC_MAP_EZTV
;
524 mask_keycode
= 0x00017c;
525 mask_keyup
= 0x000002;
528 case SAA7134_BOARD_KWORLD_XPERT
:
529 case SAA7134_BOARD_AVACSSMARTTV
:
530 ir_codes
= RC_MAP_PIXELVIEW
;
531 mask_keycode
= 0x00001F;
532 mask_keyup
= 0x000020;
535 case SAA7134_BOARD_MD2819
:
536 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT
:
537 case SAA7134_BOARD_AVERMEDIA_305
:
538 case SAA7134_BOARD_AVERMEDIA_307
:
539 case SAA7134_BOARD_AVERMEDIA_STUDIO_305
:
540 case SAA7134_BOARD_AVERMEDIA_STUDIO_505
:
541 case SAA7134_BOARD_AVERMEDIA_STUDIO_307
:
542 case SAA7134_BOARD_AVERMEDIA_STUDIO_507
:
543 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA
:
544 case SAA7134_BOARD_AVERMEDIA_GO_007_FM
:
545 case SAA7134_BOARD_AVERMEDIA_M102
:
546 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS
:
547 ir_codes
= RC_MAP_AVERMEDIA
;
548 mask_keycode
= 0x0007C8;
549 mask_keydown
= 0x000010;
551 /* Set GPIO pin2 to high to enable the IR controller */
552 saa_setb(SAA7134_GPIO_GPMODE0
, 0x4);
553 saa_setb(SAA7134_GPIO_GPSTATUS0
, 0x4);
555 case SAA7134_BOARD_AVERMEDIA_M135A
:
556 ir_codes
= RC_MAP_AVERMEDIA_M135A
;
557 mask_keydown
= 0x0040000; /* Enable GPIO18 line on both edges */
558 mask_keyup
= 0x0040000;
559 mask_keycode
= 0xffff;
562 case SAA7134_BOARD_AVERMEDIA_M733A
:
563 ir_codes
= RC_MAP_AVERMEDIA_M733A_RM_K6
;
564 mask_keydown
= 0x0040000;
565 mask_keyup
= 0x0040000;
566 mask_keycode
= 0xffff;
569 case SAA7134_BOARD_AVERMEDIA_777
:
570 case SAA7134_BOARD_AVERMEDIA_A16AR
:
571 ir_codes
= RC_MAP_AVERMEDIA
;
572 mask_keycode
= 0x02F200;
573 mask_keydown
= 0x000400;
575 /* Without this we won't receive key up events */
576 saa_setb(SAA7134_GPIO_GPMODE1
, 0x1);
577 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x1);
579 case SAA7134_BOARD_AVERMEDIA_A16D
:
580 ir_codes
= RC_MAP_AVERMEDIA_A16D
;
581 mask_keycode
= 0x02F200;
582 mask_keydown
= 0x000400;
583 polling
= 50; /* ms */
584 /* Without this we won't receive key up events */
585 saa_setb(SAA7134_GPIO_GPMODE1
, 0x1);
586 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x1);
588 case SAA7134_BOARD_KWORLD_TERMINATOR
:
589 ir_codes
= RC_MAP_PIXELVIEW
;
590 mask_keycode
= 0x00001f;
591 mask_keyup
= 0x000060;
594 case SAA7134_BOARD_MANLI_MTV001
:
595 case SAA7134_BOARD_MANLI_MTV002
:
596 ir_codes
= RC_MAP_MANLI
;
597 mask_keycode
= 0x001f00;
598 mask_keyup
= 0x004000;
599 polling
= 50; /* ms */
601 case SAA7134_BOARD_BEHOLD_409FM
:
602 case SAA7134_BOARD_BEHOLD_401
:
603 case SAA7134_BOARD_BEHOLD_403
:
604 case SAA7134_BOARD_BEHOLD_403FM
:
605 case SAA7134_BOARD_BEHOLD_405
:
606 case SAA7134_BOARD_BEHOLD_405FM
:
607 case SAA7134_BOARD_BEHOLD_407
:
608 case SAA7134_BOARD_BEHOLD_407FM
:
609 case SAA7134_BOARD_BEHOLD_409
:
610 case SAA7134_BOARD_BEHOLD_505FM
:
611 case SAA7134_BOARD_BEHOLD_505RDS_MK5
:
612 case SAA7134_BOARD_BEHOLD_505RDS_MK3
:
613 case SAA7134_BOARD_BEHOLD_507_9FM
:
614 case SAA7134_BOARD_BEHOLD_507RDS_MK3
:
615 case SAA7134_BOARD_BEHOLD_507RDS_MK5
:
616 ir_codes
= RC_MAP_MANLI
;
617 mask_keycode
= 0x003f00;
618 mask_keyup
= 0x004000;
619 polling
= 50; /* ms */
621 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM
:
622 ir_codes
= RC_MAP_BEHOLD_COLUMBUS
;
623 mask_keycode
= 0x003f00;
624 mask_keyup
= 0x004000;
627 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS
:
628 ir_codes
= RC_MAP_PCTV_SEDNA
;
629 mask_keycode
= 0x001f00;
630 mask_keyup
= 0x004000;
633 case SAA7134_BOARD_GOTVIEW_7135
:
634 ir_codes
= RC_MAP_GOTVIEW7135
;
635 mask_keycode
= 0x0003CC;
636 mask_keydown
= 0x000010;
637 polling
= 5; /* ms */
638 saa_setb(SAA7134_GPIO_GPMODE1
, 0x80);
640 case SAA7134_BOARD_VIDEOMATE_TV_PVR
:
641 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS
:
642 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII
:
643 ir_codes
= RC_MAP_VIDEOMATE_TV_PVR
;
644 mask_keycode
= 0x00003F;
645 mask_keyup
= 0x400000;
648 case SAA7134_BOARD_PROTEUS_2309
:
649 ir_codes
= RC_MAP_PROTEUS_2309
;
650 mask_keycode
= 0x00007F;
651 mask_keyup
= 0x000080;
654 case SAA7134_BOARD_VIDEOMATE_DVBT_300
:
655 case SAA7134_BOARD_VIDEOMATE_DVBT_200
:
656 ir_codes
= RC_MAP_VIDEOMATE_TV_PVR
;
657 mask_keycode
= 0x003F00;
658 mask_keyup
= 0x040000;
660 case SAA7134_BOARD_FLYDVBS_LR300
:
661 case SAA7134_BOARD_FLYDVBT_LR301
:
662 case SAA7134_BOARD_FLYDVBTDUO
:
663 ir_codes
= RC_MAP_FLYDVB
;
664 mask_keycode
= 0x0001F00;
665 mask_keydown
= 0x0040000;
667 case SAA7134_BOARD_ASUSTeK_P7131_DUAL
:
668 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA
:
669 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG
:
670 ir_codes
= RC_MAP_ASUS_PC39
;
671 mask_keydown
= 0x0040000; /* Enable GPIO18 line on both edges */
672 mask_keyup
= 0x0040000;
673 mask_keycode
= 0xffff;
676 case SAA7134_BOARD_ENCORE_ENLTV
:
677 case SAA7134_BOARD_ENCORE_ENLTV_FM
:
678 ir_codes
= RC_MAP_ENCORE_ENLTV
;
679 mask_keycode
= 0x00007f;
680 mask_keyup
= 0x040000;
683 case SAA7134_BOARD_ENCORE_ENLTV_FM53
:
684 ir_codes
= RC_MAP_ENCORE_ENLTV_FM53
;
685 mask_keydown
= 0x0040000; /* Enable GPIO18 line on both edges */
686 mask_keyup
= 0x0040000;
687 mask_keycode
= 0xffff;
690 case SAA7134_BOARD_10MOONSTVMASTER3
:
691 ir_codes
= RC_MAP_ENCORE_ENLTV
;
692 mask_keycode
= 0x5f80000;
693 mask_keyup
= 0x8000000;
696 case SAA7134_BOARD_GENIUS_TVGO_A11MCE
:
697 ir_codes
= RC_MAP_GENIUS_TVGO_A11MCE
;
699 mask_keydown
= 0xf00000;
700 polling
= 50; /* ms */
702 case SAA7134_BOARD_REAL_ANGEL_220
:
703 ir_codes
= RC_MAP_REAL_AUDIO_220_32_KEYS
;
704 mask_keycode
= 0x3f00;
706 polling
= 50; /* ms */
708 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG
:
709 ir_codes
= RC_MAP_KWORLD_PLUS_TV_ANALOG
;
711 polling
= 40; /* ms */
713 case SAA7134_BOARD_VIDEOMATE_S350
:
714 ir_codes
= RC_MAP_VIDEOMATE_S350
;
715 mask_keycode
= 0x003f00;
716 mask_keydown
= 0x040000;
718 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S
:
719 ir_codes
= RC_MAP_WINFAST
;
720 mask_keycode
= 0x5f00;
721 mask_keyup
= 0x020000;
722 polling
= 50; /* ms */
724 case SAA7134_BOARD_VIDEOMATE_M1F
:
725 ir_codes
= RC_MAP_VIDEOMATE_M1F
;
726 mask_keycode
= 0x0ff00;
727 mask_keyup
= 0x040000;
730 if (NULL
== ir_codes
) {
731 printk("%s: Oops: IR config error [card=%d]\n",
732 dev
->name
, dev
->board
);
736 ir
= kzalloc(sizeof(*ir
), GFP_KERNEL
);
737 rc
= rc_allocate_device();
746 /* init hardware-specific stuff */
747 ir
->mask_keycode
= mask_keycode
;
748 ir
->mask_keydown
= mask_keydown
;
749 ir
->mask_keyup
= mask_keyup
;
750 ir
->polling
= polling
;
751 ir
->raw_decode
= raw_decode
;
753 /* init input device */
754 snprintf(ir
->name
, sizeof(ir
->name
), "saa7134 IR (%s)",
755 saa7134_boards
[dev
->board
].name
);
756 snprintf(ir
->phys
, sizeof(ir
->phys
), "pci-%s/ir0",
760 rc
->open
= saa7134_ir_open
;
761 rc
->close
= saa7134_ir_close
;
763 rc
->driver_type
= RC_DRIVER_IR_RAW
;
765 rc
->input_name
= ir
->name
;
766 rc
->input_phys
= ir
->phys
;
767 rc
->input_id
.bustype
= BUS_PCI
;
768 rc
->input_id
.version
= 1;
769 if (dev
->pci
->subsystem_vendor
) {
770 rc
->input_id
.vendor
= dev
->pci
->subsystem_vendor
;
771 rc
->input_id
.product
= dev
->pci
->subsystem_device
;
773 rc
->input_id
.vendor
= dev
->pci
->vendor
;
774 rc
->input_id
.product
= dev
->pci
->device
;
776 rc
->dev
.parent
= &dev
->pci
->dev
;
777 rc
->map_name
= ir_codes
;
778 rc
->driver_name
= MODULE_NAME
;
780 err
= rc_register_device(rc
);
793 void saa7134_input_fini(struct saa7134_dev
*dev
)
795 if (NULL
== dev
->remote
)
798 saa7134_ir_stop(dev
);
799 rc_unregister_device(dev
->remote
->dev
);
804 void saa7134_probe_i2c_ir(struct saa7134_dev
*dev
)
806 struct i2c_board_info info
;
807 struct i2c_msg msg_msi
= {
816 dprintk("IR has been disabled, not probing for i2c remote\n");
820 memset(&info
, 0, sizeof(struct i2c_board_info
));
821 memset(&dev
->init_data
, 0, sizeof(dev
->init_data
));
822 strlcpy(info
.type
, "ir_video", I2C_NAME_SIZE
);
824 switch (dev
->board
) {
825 case SAA7134_BOARD_PINNACLE_PCTV_110i
:
826 case SAA7134_BOARD_PINNACLE_PCTV_310i
:
827 dev
->init_data
.name
= "Pinnacle PCTV";
828 if (pinnacle_remote
== 0) {
829 dev
->init_data
.get_key
= get_key_pinnacle_color
;
830 dev
->init_data
.ir_codes
= RC_MAP_PINNACLE_COLOR
;
833 dev
->init_data
.get_key
= get_key_pinnacle_grey
;
834 dev
->init_data
.ir_codes
= RC_MAP_PINNACLE_GREY
;
838 case SAA7134_BOARD_UPMOST_PURPLE_TV
:
839 dev
->init_data
.name
= "Purple TV";
840 dev
->init_data
.get_key
= get_key_purpletv
;
841 dev
->init_data
.ir_codes
= RC_MAP_PURPLETV
;
844 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS
:
845 dev
->init_data
.name
= "MSI TV@nywhere Plus";
846 dev
->init_data
.get_key
= get_key_msi_tvanywhere_plus
;
847 dev
->init_data
.ir_codes
= RC_MAP_MSI_TVANYWHERE_PLUS
;
849 * MSI TV@nyware Plus requires more frequent polling
850 * otherwise it will miss some keypresses
852 dev
->init_data
.polling_interval
= 50;
854 /* MSI TV@nywhere Plus controller doesn't seem to
855 respond to probes unless we read something from
856 an existing device. Weird...
857 REVISIT: might no longer be needed */
858 rc
= i2c_transfer(&dev
->i2c_adap
, &msg_msi
, 1);
859 dprintk("probe 0x%02x @ %s: %s\n",
860 msg_msi
.addr
, dev
->i2c_adap
.name
,
861 (1 == rc
) ? "yes" : "no");
863 case SAA7134_BOARD_HAUPPAUGE_HVR1110
:
864 dev
->init_data
.name
= "HVR 1110";
865 dev
->init_data
.get_key
= get_key_hvr1110
;
866 dev
->init_data
.ir_codes
= RC_MAP_HAUPPAUGE_NEW
;
869 case SAA7134_BOARD_BEHOLD_607FM_MK3
:
870 case SAA7134_BOARD_BEHOLD_607FM_MK5
:
871 case SAA7134_BOARD_BEHOLD_609FM_MK3
:
872 case SAA7134_BOARD_BEHOLD_609FM_MK5
:
873 case SAA7134_BOARD_BEHOLD_607RDS_MK3
:
874 case SAA7134_BOARD_BEHOLD_607RDS_MK5
:
875 case SAA7134_BOARD_BEHOLD_609RDS_MK3
:
876 case SAA7134_BOARD_BEHOLD_609RDS_MK5
:
877 case SAA7134_BOARD_BEHOLD_M6
:
878 case SAA7134_BOARD_BEHOLD_M63
:
879 case SAA7134_BOARD_BEHOLD_M6_EXTRA
:
880 case SAA7134_BOARD_BEHOLD_H6
:
881 case SAA7134_BOARD_BEHOLD_X7
:
882 case SAA7134_BOARD_BEHOLD_H7
:
883 case SAA7134_BOARD_BEHOLD_A7
:
884 dev
->init_data
.name
= "BeholdTV";
885 dev
->init_data
.get_key
= get_key_beholdm6xx
;
886 dev
->init_data
.ir_codes
= RC_MAP_BEHOLD
;
887 dev
->init_data
.type
= RC_TYPE_NEC
;
890 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501
:
891 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506
:
894 case SAA7134_BOARD_FLYDVB_TRIO
:
895 dev
->init_data
.name
= "FlyDVB Trio";
896 dev
->init_data
.get_key
= get_key_flydvb_trio
;
897 dev
->init_data
.ir_codes
= RC_MAP_FLYDVB
;
901 dprintk("No I2C IR support for board %x\n", dev
->board
);
905 if (dev
->init_data
.name
)
906 info
.platform_data
= &dev
->init_data
;
907 i2c_new_device(&dev
->i2c_adap
, &info
);
910 static int saa7134_raw_decode_irq(struct saa7134_dev
*dev
)
912 struct saa7134_card_ir
*ir
= dev
->remote
;
913 unsigned long timeout
;
916 /* Generate initial event */
917 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
918 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
919 space
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2) & ir
->mask_keydown
;
920 ir_raw_event_store_edge(dev
->remote
->dev
, space
? IR_SPACE
: IR_PULSE
);
923 * Wait 15 ms from the start of the first IR event before processing
924 * the event. This time is enough for NEC protocol. May need adjustments
925 * to work with other protocols.
928 timeout
= jiffies
+ jiffies_to_msecs(15);
929 mod_timer(&ir
->timer
, timeout
);