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 /* copied and modified from get_key_msi_tvanywhere_plus() */
214 static int get_key_kworld_pc150u(struct IR_i2c *ir, u32 *ir_key,
220 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
221 struct saa7134_dev *dev = ir->c->adapter->algo_data;
223 i2cdprintk("get_key_kworld_pc150u: "
224 "ir->c->adapter->algo_data is NULL!\n");
228 /* rising SAA7134_GPIO_GPRESCAN reads the status */
230 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
231 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
233 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
235 /* GPIO&0x100 is pulsed low when a button is pressed. Don't do
236 I2C receive if gpio&0x100 is not low. */
239 return 0; /* No button press */
241 /* GPIO says there is a button press. Get it. */
243 if (1 != i2c_master_recv(ir->c, &b, 1)) {
244 i2cdprintk("read error\n");
248 /* No button press */
255 dprintk("get_key_kworld_pc150u: Key = 0x%02X\n", b);
261 static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
266 if (1 != i2c_master_recv(ir->c, &b, 1)) {
267 i2cdprintk("read error\n");
271 /* no button press */
284 static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
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 *ir_key = 0x1fff & ((buf[3] << 8) | (buf[4] >> 2));
309 static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
311 unsigned char data[12];
314 struct saa7134_dev *dev = ir->c->adapter->algo_data;
316 /* rising SAA7134_GPIO_GPRESCAN reads the status */
317 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
318 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
320 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
322 if (0x400000 & ~gpio)
323 return 0; /* No button press */
325 ir->c->addr = 0x5a >> 1;
327 if (12 != i2c_master_recv(ir->c, data, 12)) {
328 i2cdprintk("read error\n");
332 if (data[9] != (unsigned char)(~data[8]))
335 *ir_raw = ((data[10] << 16) | (data[11] << 8) | (data[9] << 0));
341 /* Common (grey or coloured) pinnacle PCTV remote handling
344 static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
345 int parity_offset, int marker, int code_modulo)
348 unsigned int start = 0,parity = 0,code = 0;
351 if (4 != i2c_master_recv(ir->c, b, 4)) {
352 i2cdprintk("read error\n");
356 for (start = 0; start < ARRAY_SIZE(b); start++) {
357 if (b[start] == marker) {
358 code=b[(start+parity_offset + 1) % 4];
359 parity=b[(start+parity_offset) % 4];
368 if (ir->old == parity)
373 /* drop special codes when a key is held down a long time for the grey controller
374 In this case, the second bit of the code is asserted */
375 if (marker == 0xfe && (code & 0x40))
383 i2cdprintk("Pinnacle PCTV key %02x\n", code);
388 /* The grey pinnacle PCTV remote
390 * There are one issue with this remote:
391 * - I2c packet does not change when the same key is pressed quickly. The workaround
392 * is to hold down each key for about half a second, so that another code is generated
393 * in the i2c packet, and the function can distinguish key presses.
395 * Sylvain Pasche <sylvain.pasche@gmail.com>
397 static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
400 return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff);
404 /* The new pinnacle PCTV remote (with the colored buttons)
406 * Ricardo Cerqueira <v4l@cerqueira.org>
408 static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
410 /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
412 * this is the only value that results in 42 unique
416 return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88);
419 void saa7134_input_irq(struct saa7134_dev *dev)
421 struct saa7134_card_ir *ir;
423 if (!dev || !dev->remote)
430 if (!ir->polling && !ir->raw_decode) {
432 } else if (ir->raw_decode) {
433 saa7134_raw_decode_irq(dev);
437 static void saa7134_input_timer(unsigned long data)
439 struct saa7134_dev *dev = (struct saa7134_dev *)data;
440 struct saa7134_card_ir *ir = dev->remote;
443 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
446 static void ir_raw_decode_timer_end(unsigned long data)
448 struct saa7134_dev *dev = (struct saa7134_dev *)data;
449 struct saa7134_card_ir *ir = dev->remote;
451 ir_raw_event_handle(dev->remote->dev);
456 static int __saa7134_ir_start(void *priv)
458 struct saa7134_dev *dev = priv;
459 struct saa7134_card_ir *ir;
461 if (!dev || !dev->remote)
468 /* Moved here from saa7134_input_init1() because the latter
469 * is not called on device resume */
470 switch (dev->board) {
471 case SAA7134_BOARD_MD2819:
472 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
473 case SAA7134_BOARD_AVERMEDIA_305:
474 case SAA7134_BOARD_AVERMEDIA_307:
475 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
476 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
477 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
478 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
479 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
480 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
481 case SAA7134_BOARD_AVERMEDIA_M102:
482 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
483 /* Without this we won't receive key up events */
484 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
485 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
487 case SAA7134_BOARD_AVERMEDIA_777:
488 case SAA7134_BOARD_AVERMEDIA_A16AR:
489 /* Without this we won't receive key up events */
490 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
491 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
493 case SAA7134_BOARD_AVERMEDIA_A16D:
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_GOTVIEW_7135:
499 saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
507 setup_timer(&ir->timer, saa7134_input_timer,
509 ir->timer.expires = jiffies + HZ;
510 add_timer(&ir->timer);
511 } else if (ir->raw_decode) {
512 /* set timer_end for code completion */
513 setup_timer(&ir->timer, ir_raw_decode_timer_end,
520 static void __saa7134_ir_stop(void *priv)
522 struct saa7134_dev *dev = priv;
523 struct saa7134_card_ir *ir;
525 if (!dev || !dev->remote)
532 if (ir->polling || ir->raw_decode)
533 del_timer_sync(&ir->timer);
541 int saa7134_ir_start(struct saa7134_dev *dev)
543 if (dev->remote->users)
544 return __saa7134_ir_start(dev);
549 void saa7134_ir_stop(struct saa7134_dev *dev)
551 if (dev->remote->users)
552 __saa7134_ir_stop(dev);
555 static int saa7134_ir_open(struct rc_dev *rc)
557 struct saa7134_dev *dev = rc->priv;
559 dev->remote->users++;
560 return __saa7134_ir_start(dev);
563 static void saa7134_ir_close(struct rc_dev *rc)
565 struct saa7134_dev *dev = rc->priv;
567 dev->remote->users--;
568 if (!dev->remote->users)
569 __saa7134_ir_stop(dev);
572 int saa7134_input_init1(struct saa7134_dev *dev)
574 struct saa7134_card_ir *ir;
576 char *ir_codes = NULL;
577 u32 mask_keycode = 0;
578 u32 mask_keydown = 0;
580 unsigned polling = 0;
581 bool raw_decode = false;
584 if (dev->has_remote != SAA7134_REMOTE_GPIO)
589 /* detect & configure */
590 switch (dev->board) {
591 case SAA7134_BOARD_FLYVIDEO2000:
592 case SAA7134_BOARD_FLYVIDEO3000:
593 case SAA7134_BOARD_FLYTVPLATINUM_FM:
594 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
595 case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM:
596 ir_codes = RC_MAP_FLYVIDEO;
597 mask_keycode = 0xEC00000;
598 mask_keydown = 0x0040000;
600 case SAA7134_BOARD_CINERGY400:
601 case SAA7134_BOARD_CINERGY600:
602 case SAA7134_BOARD_CINERGY600_MK3:
603 ir_codes = RC_MAP_CINERGY;
604 mask_keycode = 0x00003f;
605 mask_keyup = 0x040000;
607 case SAA7134_BOARD_ECS_TVP3XP:
608 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
609 ir_codes = RC_MAP_EZTV;
610 mask_keycode = 0x00017c;
611 mask_keyup = 0x000002;
614 case SAA7134_BOARD_KWORLD_XPERT:
615 case SAA7134_BOARD_AVACSSMARTTV:
616 ir_codes = RC_MAP_PIXELVIEW;
617 mask_keycode = 0x00001F;
618 mask_keyup = 0x000020;
621 case SAA7134_BOARD_MD2819:
622 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
623 case SAA7134_BOARD_AVERMEDIA_305:
624 case SAA7134_BOARD_AVERMEDIA_307:
625 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
626 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
627 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
628 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
629 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
630 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
631 case SAA7134_BOARD_AVERMEDIA_M102:
632 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
633 ir_codes = RC_MAP_AVERMEDIA;
634 mask_keycode = 0x0007C8;
635 mask_keydown = 0x000010;
637 /* GPIO stuff moved to __saa7134_ir_start() */
639 case SAA7134_BOARD_AVERMEDIA_M135A:
640 ir_codes = RC_MAP_AVERMEDIA_M135A;
641 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
642 mask_keyup = 0x0040000;
643 mask_keycode = 0xffff;
646 case SAA7134_BOARD_AVERMEDIA_M733A:
647 ir_codes = RC_MAP_AVERMEDIA_M733A_RM_K6;
648 mask_keydown = 0x0040000;
649 mask_keyup = 0x0040000;
650 mask_keycode = 0xffff;
653 case SAA7134_BOARD_AVERMEDIA_777:
654 case SAA7134_BOARD_AVERMEDIA_A16AR:
655 ir_codes = RC_MAP_AVERMEDIA;
656 mask_keycode = 0x02F200;
657 mask_keydown = 0x000400;
659 /* GPIO stuff moved to __saa7134_ir_start() */
661 case SAA7134_BOARD_AVERMEDIA_A16D:
662 ir_codes = RC_MAP_AVERMEDIA_A16D;
663 mask_keycode = 0x02F200;
664 mask_keydown = 0x000400;
665 polling = 50; /* ms */
666 /* GPIO stuff moved to __saa7134_ir_start() */
668 case SAA7134_BOARD_KWORLD_TERMINATOR:
669 ir_codes = RC_MAP_PIXELVIEW;
670 mask_keycode = 0x00001f;
671 mask_keyup = 0x000060;
674 case SAA7134_BOARD_MANLI_MTV001:
675 case SAA7134_BOARD_MANLI_MTV002:
676 ir_codes = RC_MAP_MANLI;
677 mask_keycode = 0x001f00;
678 mask_keyup = 0x004000;
679 polling = 50; /* ms */
681 case SAA7134_BOARD_BEHOLD_409FM:
682 case SAA7134_BOARD_BEHOLD_401:
683 case SAA7134_BOARD_BEHOLD_403:
684 case SAA7134_BOARD_BEHOLD_403FM:
685 case SAA7134_BOARD_BEHOLD_405:
686 case SAA7134_BOARD_BEHOLD_405FM:
687 case SAA7134_BOARD_BEHOLD_407:
688 case SAA7134_BOARD_BEHOLD_407FM:
689 case SAA7134_BOARD_BEHOLD_409:
690 case SAA7134_BOARD_BEHOLD_505FM:
691 case SAA7134_BOARD_BEHOLD_505RDS_MK5:
692 case SAA7134_BOARD_BEHOLD_505RDS_MK3:
693 case SAA7134_BOARD_BEHOLD_507_9FM:
694 case SAA7134_BOARD_BEHOLD_507RDS_MK3:
695 case SAA7134_BOARD_BEHOLD_507RDS_MK5:
696 ir_codes = RC_MAP_MANLI;
697 mask_keycode = 0x003f00;
698 mask_keyup = 0x004000;
699 polling = 50; /* ms */
701 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
702 ir_codes = RC_MAP_BEHOLD_COLUMBUS;
703 mask_keycode = 0x003f00;
704 mask_keyup = 0x004000;
707 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
708 ir_codes = RC_MAP_PCTV_SEDNA;
709 mask_keycode = 0x001f00;
710 mask_keyup = 0x004000;
713 case SAA7134_BOARD_GOTVIEW_7135:
714 ir_codes = RC_MAP_GOTVIEW7135;
715 mask_keycode = 0x0003CC;
716 mask_keydown = 0x000010;
717 polling = 5; /* ms */
718 /* GPIO stuff moved to __saa7134_ir_start() */
720 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
721 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
722 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
723 ir_codes = RC_MAP_VIDEOMATE_TV_PVR;
724 mask_keycode = 0x00003F;
725 mask_keyup = 0x400000;
728 case SAA7134_BOARD_PROTEUS_2309:
729 ir_codes = RC_MAP_PROTEUS_2309;
730 mask_keycode = 0x00007F;
731 mask_keyup = 0x000080;
734 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
735 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
736 ir_codes = RC_MAP_VIDEOMATE_TV_PVR;
737 mask_keycode = 0x003F00;
738 mask_keyup = 0x040000;
740 case SAA7134_BOARD_FLYDVBS_LR300:
741 case SAA7134_BOARD_FLYDVBT_LR301:
742 case SAA7134_BOARD_FLYDVBTDUO:
743 ir_codes = RC_MAP_FLYDVB;
744 mask_keycode = 0x0001F00;
745 mask_keydown = 0x0040000;
747 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
748 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
749 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
750 ir_codes = RC_MAP_ASUS_PC39;
751 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
752 mask_keyup = 0x0040000;
753 mask_keycode = 0xffff;
756 case SAA7134_BOARD_ASUSTeK_PS3_100:
757 ir_codes = RC_MAP_ASUS_PS3_100;
758 mask_keydown = 0x0040000;
759 mask_keyup = 0x0040000;
760 mask_keycode = 0xffff;
763 case SAA7134_BOARD_ENCORE_ENLTV:
764 case SAA7134_BOARD_ENCORE_ENLTV_FM:
765 ir_codes = RC_MAP_ENCORE_ENLTV;
766 mask_keycode = 0x00007f;
767 mask_keyup = 0x040000;
770 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
771 case SAA7134_BOARD_ENCORE_ENLTV_FM3:
772 ir_codes = RC_MAP_ENCORE_ENLTV_FM53;
773 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
774 mask_keyup = 0x0040000;
775 mask_keycode = 0xffff;
778 case SAA7134_BOARD_10MOONSTVMASTER3:
779 ir_codes = RC_MAP_ENCORE_ENLTV;
780 mask_keycode = 0x5f80000;
781 mask_keyup = 0x8000000;
784 case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
785 ir_codes = RC_MAP_GENIUS_TVGO_A11MCE;
787 mask_keydown = 0xf00000;
788 polling = 50; /* ms */
790 case SAA7134_BOARD_REAL_ANGEL_220:
791 ir_codes = RC_MAP_REAL_AUDIO_220_32_KEYS;
792 mask_keycode = 0x3f00;
794 polling = 50; /* ms */
796 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
797 ir_codes = RC_MAP_KWORLD_PLUS_TV_ANALOG;
799 polling = 40; /* ms */
801 case SAA7134_BOARD_VIDEOMATE_S350:
802 ir_codes = RC_MAP_VIDEOMATE_S350;
803 mask_keycode = 0x003f00;
804 mask_keydown = 0x040000;
806 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
807 ir_codes = RC_MAP_WINFAST;
808 mask_keycode = 0x5f00;
809 mask_keyup = 0x020000;
810 polling = 50; /* ms */
812 case SAA7134_BOARD_VIDEOMATE_M1F:
813 ir_codes = RC_MAP_VIDEOMATE_K100;
814 mask_keycode = 0x0ff00;
815 mask_keyup = 0x040000;
817 case SAA7134_BOARD_HAUPPAUGE_HVR1150:
818 case SAA7134_BOARD_HAUPPAUGE_HVR1120:
819 ir_codes = RC_MAP_HAUPPAUGE;
820 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
821 mask_keyup = 0x0040000;
822 mask_keycode = 0xffff;
826 if (NULL == ir_codes) {
827 printk("%s: Oops: IR config error [card=%d]\n",
828 dev->name, dev->board);
832 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
833 rc = rc_allocate_device();
842 /* init hardware-specific stuff */
843 ir->mask_keycode = mask_keycode;
844 ir->mask_keydown = mask_keydown;
845 ir->mask_keyup = mask_keyup;
846 ir->polling = polling;
847 ir->raw_decode = raw_decode;
849 /* init input device */
850 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
851 saa7134_boards[dev->board].name);
852 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
856 rc->open = saa7134_ir_open;
857 rc->close = saa7134_ir_close;
859 rc->driver_type = RC_DRIVER_IR_RAW;
861 rc->input_name = ir->name;
862 rc->input_phys = ir->phys;
863 rc->input_id.bustype = BUS_PCI;
864 rc->input_id.version = 1;
865 if (dev->pci->subsystem_vendor) {
866 rc->input_id.vendor = dev->pci->subsystem_vendor;
867 rc->input_id.product = dev->pci->subsystem_device;
869 rc->input_id.vendor = dev->pci->vendor;
870 rc->input_id.product = dev->pci->device;
872 rc->dev.parent = &dev->pci->dev;
873 rc->map_name = ir_codes;
874 rc->driver_name = MODULE_NAME;
876 err = rc_register_device(rc);
889 void saa7134_input_fini(struct saa7134_dev *dev)
891 if (NULL == dev->remote)
894 saa7134_ir_stop(dev);
895 rc_unregister_device(dev->remote->dev);
900 void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
902 struct i2c_board_info info;
903 struct i2c_msg msg_msi = {
912 dprintk("IR has been disabled, not probing for i2c remote\n");
916 memset(&info, 0, sizeof(struct i2c_board_info));
917 memset(&dev->init_data, 0, sizeof(dev->init_data));
918 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
920 switch (dev->board) {
921 case SAA7134_BOARD_PINNACLE_PCTV_110i:
922 case SAA7134_BOARD_PINNACLE_PCTV_310i:
923 dev->init_data.name = "Pinnacle PCTV";
924 if (pinnacle_remote == 0) {
925 dev->init_data.get_key = get_key_pinnacle_color;
926 dev->init_data.ir_codes = RC_MAP_PINNACLE_COLOR;
929 dev->init_data.get_key = get_key_pinnacle_grey;
930 dev->init_data.ir_codes = RC_MAP_PINNACLE_GREY;
934 case SAA7134_BOARD_UPMOST_PURPLE_TV:
935 dev->init_data.name = "Purple TV";
936 dev->init_data.get_key = get_key_purpletv;
937 dev->init_data.ir_codes = RC_MAP_PURPLETV;
940 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
941 dev->init_data.name = "MSI TV@nywhere Plus";
942 dev->init_data.get_key = get_key_msi_tvanywhere_plus;
943 dev->init_data.ir_codes = RC_MAP_MSI_TVANYWHERE_PLUS;
945 * MSI TV@nyware Plus requires more frequent polling
946 * otherwise it will miss some keypresses
948 dev->init_data.polling_interval = 50;
950 /* MSI TV@nywhere Plus controller doesn't seem to
951 respond to probes unless we read something from
952 an existing device. Weird...
953 REVISIT: might no longer be needed */
954 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
955 dprintk("probe 0x%02x @ %s: %s\n",
956 msg_msi.addr, dev->i2c_adap.name,
957 (1 == rc) ? "yes" : "no");
959 case SAA7134_BOARD_KWORLD_PC150U:
960 /* copied and modified from MSI TV@nywhere Plus */
961 dev->init_data.name = "Kworld PC150-U";
962 dev->init_data.get_key = get_key_kworld_pc150u;
963 dev->init_data.ir_codes = RC_MAP_KWORLD_PC150U;
965 /* MSI TV@nywhere Plus controller doesn't seem to
966 respond to probes unless we read something from
967 an existing device. Weird...
968 REVISIT: might no longer be needed */
969 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
970 dprintk("probe 0x%02x @ %s: %s\n",
971 msg_msi.addr, dev->i2c_adap.name,
972 (1 == rc) ? "yes" : "no");
974 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
975 dev->init_data.name = "HVR 1110";
976 dev->init_data.get_key = get_key_hvr1110;
977 dev->init_data.ir_codes = RC_MAP_HAUPPAUGE;
980 case SAA7134_BOARD_BEHOLD_607FM_MK3:
981 case SAA7134_BOARD_BEHOLD_607FM_MK5:
982 case SAA7134_BOARD_BEHOLD_609FM_MK3:
983 case SAA7134_BOARD_BEHOLD_609FM_MK5:
984 case SAA7134_BOARD_BEHOLD_607RDS_MK3:
985 case SAA7134_BOARD_BEHOLD_607RDS_MK5:
986 case SAA7134_BOARD_BEHOLD_609RDS_MK3:
987 case SAA7134_BOARD_BEHOLD_609RDS_MK5:
988 case SAA7134_BOARD_BEHOLD_M6:
989 case SAA7134_BOARD_BEHOLD_M63:
990 case SAA7134_BOARD_BEHOLD_M6_EXTRA:
991 case SAA7134_BOARD_BEHOLD_H6:
992 case SAA7134_BOARD_BEHOLD_X7:
993 case SAA7134_BOARD_BEHOLD_H7:
994 case SAA7134_BOARD_BEHOLD_A7:
995 dev->init_data.name = "BeholdTV";
996 dev->init_data.get_key = get_key_beholdm6xx;
997 dev->init_data.ir_codes = RC_MAP_BEHOLD;
998 dev->init_data.type = RC_TYPE_NEC;
1001 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
1002 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
1005 case SAA7134_BOARD_FLYDVB_TRIO:
1006 dev->init_data.name = "FlyDVB Trio";
1007 dev->init_data.get_key = get_key_flydvb_trio;
1008 dev->init_data.ir_codes = RC_MAP_FLYDVB;
1012 dprintk("No I2C IR support for board %x\n", dev->board);
1016 if (dev->init_data.name)
1017 info.platform_data = &dev->init_data;
1018 i2c_new_device(&dev->i2c_adap, &info);
1021 static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
1023 struct saa7134_card_ir *ir = dev->remote;
1024 unsigned long timeout;
1027 /* Generate initial event */
1028 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1029 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1030 space = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
1031 ir_raw_event_store_edge(dev->remote->dev, space ? IR_SPACE : IR_PULSE);
1034 * Wait 15 ms from the start of the first IR event before processing
1035 * the event. This time is enough for NEC protocol. May need adjustments
1036 * to work with other protocols.
1039 timeout = jiffies + msecs_to_jiffies(15);
1040 mod_timer(&ir->timer, timeout);