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 rc = i2c_master_recv(ir->c, &b, 1);
158 ir_dbg(ir, "read error\n");
164 *protocol = RC_PROTO_UNKNOWN;
170 static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir,
171 enum rc_proto *protocol,
172 u32 *scancode, u8 *toggle)
177 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
178 struct saa7134_dev *dev = ir->c->adapter->algo_data;
180 ir_dbg(ir, "get_key_msi_tvanywhere_plus: ir->c->adapter->algo_data is NULL!\n");
184 /* rising SAA7134_GPIO_GPRESCAN reads the status */
186 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
187 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
189 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
191 /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
192 I2C receive if gpio&0x40 is not low. */
195 return 0; /* No button press */
197 /* GPIO says there is a button press. Get it. */
199 rc = i2c_master_recv(ir->c, &b, 1);
201 ir_dbg(ir, "read error\n");
207 /* No button press */
214 input_dbg("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b);
215 *protocol = RC_PROTO_UNKNOWN;
221 /* copied and modified from get_key_msi_tvanywhere_plus() */
222 static int get_key_kworld_pc150u(struct IR_i2c *ir, enum rc_proto *protocol,
223 u32 *scancode, u8 *toggle)
229 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
230 struct saa7134_dev *dev = ir->c->adapter->algo_data;
232 ir_dbg(ir, "get_key_kworld_pc150u: ir->c->adapter->algo_data is NULL!\n");
236 /* rising SAA7134_GPIO_GPRESCAN reads the status */
238 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
239 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
241 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
243 /* GPIO&0x100 is pulsed low when a button is pressed. Don't do
244 I2C receive if gpio&0x100 is not low. */
247 return 0; /* No button press */
249 /* GPIO says there is a button press. Get it. */
251 rc = i2c_master_recv(ir->c, &b, 1);
253 ir_dbg(ir, "read error\n");
259 /* No button press */
266 input_dbg("get_key_kworld_pc150u: Key = 0x%02X\n", b);
267 *protocol = RC_PROTO_UNKNOWN;
273 static int get_key_purpletv(struct IR_i2c *ir, enum rc_proto *protocol,
274 u32 *scancode, u8 *toggle)
280 rc = i2c_master_recv(ir->c, &b, 1);
282 ir_dbg(ir, "read error\n");
288 /* no button press */
296 *protocol = RC_PROTO_UNKNOWN;
302 static int get_key_beholdm6xx(struct IR_i2c *ir, enum rc_proto *protocol,
303 u32 *scancode, u8 *toggle)
306 unsigned char data[12];
309 struct saa7134_dev *dev = ir->c->adapter->algo_data;
311 /* rising SAA7134_GPIO_GPRESCAN reads the status */
312 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
313 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
315 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
317 if (0x400000 & ~gpio)
318 return 0; /* No button press */
320 ir->c->addr = 0x5a >> 1;
322 rc = i2c_master_recv(ir->c, data, 12);
324 ir_dbg(ir, "read error\n");
330 if (data[9] != (unsigned char)(~data[8]))
333 *protocol = RC_PROTO_NECX;
334 *scancode = RC_SCANCODE_NECX(data[11] << 8 | data[10], data[9]);
339 /* Common (grey or coloured) pinnacle PCTV remote handling
342 static int get_key_pinnacle(struct IR_i2c *ir, enum rc_proto *protocol,
343 u32 *scancode, u8 *toggle, int parity_offset,
344 int marker, int code_modulo)
348 unsigned int start = 0,parity = 0,code = 0;
351 rc = i2c_master_recv(ir->c, b, 4);
353 ir_dbg(ir, "read error\n");
359 for (start = 0; start < ARRAY_SIZE(b); start++) {
360 if (b[start] == marker) {
361 code=b[(start+parity_offset + 1) % 4];
362 parity=b[(start+parity_offset) % 4];
371 if (ir->old == parity)
376 /* drop special codes when a key is held down a long time for the grey controller
377 In this case, the second bit of the code is asserted */
378 if (marker == 0xfe && (code & 0x40))
383 *protocol = RC_PROTO_UNKNOWN;
387 ir_dbg(ir, "Pinnacle PCTV key %02x\n", code);
391 /* The grey pinnacle PCTV remote
393 * There are one issue with this remote:
394 * - I2c packet does not change when the same key is pressed quickly. The workaround
395 * is to hold down each key for about half a second, so that another code is generated
396 * in the i2c packet, and the function can distinguish key presses.
398 * Sylvain Pasche <sylvain.pasche@gmail.com>
400 static int get_key_pinnacle_grey(struct IR_i2c *ir, enum rc_proto *protocol,
401 u32 *scancode, u8 *toggle)
404 return get_key_pinnacle(ir, protocol, scancode, toggle, 1, 0xfe, 0xff);
408 /* The new pinnacle PCTV remote (with the colored buttons)
410 * Ricardo Cerqueira <v4l@cerqueira.org>
412 static int get_key_pinnacle_color(struct IR_i2c *ir, enum rc_proto *protocol,
413 u32 *scancode, u8 *toggle)
415 /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
417 * this is the only value that results in 42 unique
421 return get_key_pinnacle(ir, protocol, scancode, toggle, 2, 0x80, 0x88);
424 void saa7134_input_irq(struct saa7134_dev *dev)
426 struct saa7134_card_ir *ir;
428 if (!dev || !dev->remote)
435 if (!ir->polling && !ir->raw_decode) {
437 } else if (ir->raw_decode) {
438 saa7134_raw_decode_irq(dev);
442 static void saa7134_input_timer(struct timer_list *t)
444 struct saa7134_card_ir *ir = from_timer(ir, t, timer);
445 struct saa7134_dev *dev = ir->dev->priv;
448 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
451 int saa7134_ir_open(struct rc_dev *rc)
453 struct saa7134_dev *dev = rc->priv;
454 struct saa7134_card_ir *ir = dev->remote;
456 /* Moved here from saa7134_input_init1() because the latter
457 * is not called on device resume */
458 switch (dev->board) {
459 case SAA7134_BOARD_MD2819:
460 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
461 case SAA7134_BOARD_AVERMEDIA_305:
462 case SAA7134_BOARD_AVERMEDIA_307:
463 case SAA7134_BOARD_AVERMEDIA_505:
464 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
465 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
466 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
467 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
468 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
469 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
470 case SAA7134_BOARD_AVERMEDIA_M102:
471 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
472 /* Without this we won't receive key up events */
473 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
474 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
476 case SAA7134_BOARD_AVERMEDIA_777:
477 case SAA7134_BOARD_AVERMEDIA_A16AR:
478 /* Without this we won't receive key up events */
479 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
480 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
482 case SAA7134_BOARD_AVERMEDIA_A16D:
483 /* Without this we won't receive key up events */
484 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
485 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
487 case SAA7134_BOARD_GOTVIEW_7135:
488 saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
495 timer_setup(&ir->timer, saa7134_input_timer, 0);
496 ir->timer.expires = jiffies + HZ;
497 add_timer(&ir->timer);
503 void saa7134_ir_close(struct rc_dev *rc)
505 struct saa7134_dev *dev = rc->priv;
506 struct saa7134_card_ir *ir = dev->remote;
509 del_timer_sync(&ir->timer);
514 int saa7134_input_init1(struct saa7134_dev *dev)
516 struct saa7134_card_ir *ir;
518 char *ir_codes = NULL;
519 u32 mask_keycode = 0;
520 u32 mask_keydown = 0;
522 unsigned polling = 0;
523 bool raw_decode = false;
526 if (dev->has_remote != SAA7134_REMOTE_GPIO)
531 /* detect & configure */
532 switch (dev->board) {
533 case SAA7134_BOARD_FLYVIDEO2000:
534 case SAA7134_BOARD_FLYVIDEO3000:
535 case SAA7134_BOARD_FLYTVPLATINUM_FM:
536 case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
537 case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM:
538 ir_codes = RC_MAP_FLYVIDEO;
539 mask_keycode = 0xEC00000;
540 mask_keydown = 0x0040000;
542 case SAA7134_BOARD_CINERGY400:
543 case SAA7134_BOARD_CINERGY600:
544 case SAA7134_BOARD_CINERGY600_MK3:
545 ir_codes = RC_MAP_CINERGY;
546 mask_keycode = 0x00003f;
547 mask_keyup = 0x040000;
549 case SAA7134_BOARD_ECS_TVP3XP:
550 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
551 ir_codes = RC_MAP_EZTV;
552 mask_keycode = 0x00017c;
553 mask_keyup = 0x000002;
556 case SAA7134_BOARD_KWORLD_XPERT:
557 case SAA7134_BOARD_AVACSSMARTTV:
558 ir_codes = RC_MAP_PIXELVIEW;
559 mask_keycode = 0x00001F;
560 mask_keyup = 0x000020;
563 case SAA7134_BOARD_MD2819:
564 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
565 case SAA7134_BOARD_AVERMEDIA_305:
566 case SAA7134_BOARD_AVERMEDIA_307:
567 case SAA7134_BOARD_AVERMEDIA_505:
568 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
569 case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
570 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
571 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
572 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
573 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
574 case SAA7134_BOARD_AVERMEDIA_M102:
575 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
576 ir_codes = RC_MAP_AVERMEDIA;
577 mask_keycode = 0x0007C8;
578 mask_keydown = 0x000010;
580 /* GPIO stuff moved to saa7134_ir_open() */
582 case SAA7134_BOARD_AVERMEDIA_M135A:
583 ir_codes = RC_MAP_AVERMEDIA_M135A;
584 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
585 mask_keyup = 0x0040000;
586 mask_keycode = 0xffff;
589 case SAA7134_BOARD_AVERMEDIA_M733A:
590 ir_codes = RC_MAP_AVERMEDIA_M733A_RM_K6;
591 mask_keydown = 0x0040000;
592 mask_keyup = 0x0040000;
593 mask_keycode = 0xffff;
596 case SAA7134_BOARD_AVERMEDIA_777:
597 case SAA7134_BOARD_AVERMEDIA_A16AR:
598 ir_codes = RC_MAP_AVERMEDIA;
599 mask_keycode = 0x02F200;
600 mask_keydown = 0x000400;
602 /* GPIO stuff moved to saa7134_ir_open() */
604 case SAA7134_BOARD_AVERMEDIA_A16D:
605 ir_codes = RC_MAP_AVERMEDIA_A16D;
606 mask_keycode = 0x02F200;
607 mask_keydown = 0x000400;
608 polling = 50; /* ms */
609 /* GPIO stuff moved to saa7134_ir_open() */
611 case SAA7134_BOARD_KWORLD_TERMINATOR:
612 ir_codes = RC_MAP_PIXELVIEW;
613 mask_keycode = 0x00001f;
614 mask_keyup = 0x000060;
617 case SAA7134_BOARD_MANLI_MTV001:
618 case SAA7134_BOARD_MANLI_MTV002:
619 ir_codes = RC_MAP_MANLI;
620 mask_keycode = 0x001f00;
621 mask_keyup = 0x004000;
622 polling = 50; /* ms */
624 case SAA7134_BOARD_BEHOLD_409FM:
625 case SAA7134_BOARD_BEHOLD_401:
626 case SAA7134_BOARD_BEHOLD_403:
627 case SAA7134_BOARD_BEHOLD_403FM:
628 case SAA7134_BOARD_BEHOLD_405:
629 case SAA7134_BOARD_BEHOLD_405FM:
630 case SAA7134_BOARD_BEHOLD_407:
631 case SAA7134_BOARD_BEHOLD_407FM:
632 case SAA7134_BOARD_BEHOLD_409:
633 case SAA7134_BOARD_BEHOLD_505FM:
634 case SAA7134_BOARD_BEHOLD_505RDS_MK5:
635 case SAA7134_BOARD_BEHOLD_505RDS_MK3:
636 case SAA7134_BOARD_BEHOLD_507_9FM:
637 case SAA7134_BOARD_BEHOLD_507RDS_MK3:
638 case SAA7134_BOARD_BEHOLD_507RDS_MK5:
639 ir_codes = RC_MAP_MANLI;
640 mask_keycode = 0x003f00;
641 mask_keyup = 0x004000;
642 polling = 50; /* ms */
644 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
645 ir_codes = RC_MAP_BEHOLD_COLUMBUS;
646 mask_keycode = 0x003f00;
647 mask_keyup = 0x004000;
650 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
651 ir_codes = RC_MAP_PCTV_SEDNA;
652 mask_keycode = 0x001f00;
653 mask_keyup = 0x004000;
656 case SAA7134_BOARD_GOTVIEW_7135:
657 ir_codes = RC_MAP_GOTVIEW7135;
658 mask_keycode = 0x0003CC;
659 mask_keydown = 0x000010;
660 polling = 5; /* ms */
661 /* GPIO stuff moved to saa7134_ir_open() */
663 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
664 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
665 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
666 ir_codes = RC_MAP_VIDEOMATE_TV_PVR;
667 mask_keycode = 0x00003F;
668 mask_keyup = 0x400000;
671 case SAA7134_BOARD_PROTEUS_2309:
672 ir_codes = RC_MAP_PROTEUS_2309;
673 mask_keycode = 0x00007F;
674 mask_keyup = 0x000080;
677 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
678 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
679 ir_codes = RC_MAP_VIDEOMATE_TV_PVR;
680 mask_keycode = 0x003F00;
681 mask_keyup = 0x040000;
683 case SAA7134_BOARD_FLYDVBS_LR300:
684 case SAA7134_BOARD_FLYDVBT_LR301:
685 case SAA7134_BOARD_FLYDVBTDUO:
686 ir_codes = RC_MAP_FLYDVB;
687 mask_keycode = 0x0001F00;
688 mask_keydown = 0x0040000;
690 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
691 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
692 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
693 ir_codes = RC_MAP_ASUS_PC39;
694 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
695 mask_keyup = 0x0040000;
696 mask_keycode = 0xffff;
699 case SAA7134_BOARD_ASUSTeK_PS3_100:
700 ir_codes = RC_MAP_ASUS_PS3_100;
701 mask_keydown = 0x0040000;
702 mask_keyup = 0x0040000;
703 mask_keycode = 0xffff;
706 case SAA7134_BOARD_ENCORE_ENLTV:
707 case SAA7134_BOARD_ENCORE_ENLTV_FM:
708 ir_codes = RC_MAP_ENCORE_ENLTV;
709 mask_keycode = 0x00007f;
710 mask_keyup = 0x040000;
713 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
714 case SAA7134_BOARD_ENCORE_ENLTV_FM3:
715 ir_codes = RC_MAP_ENCORE_ENLTV_FM53;
716 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
717 mask_keyup = 0x0040000;
718 mask_keycode = 0xffff;
721 case SAA7134_BOARD_10MOONSTVMASTER3:
722 ir_codes = RC_MAP_ENCORE_ENLTV;
723 mask_keycode = 0x5f80000;
724 mask_keyup = 0x8000000;
727 case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
728 ir_codes = RC_MAP_GENIUS_TVGO_A11MCE;
730 mask_keydown = 0xf00000;
731 polling = 50; /* ms */
733 case SAA7134_BOARD_REAL_ANGEL_220:
734 ir_codes = RC_MAP_REAL_AUDIO_220_32_KEYS;
735 mask_keycode = 0x3f00;
737 polling = 50; /* ms */
739 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
740 ir_codes = RC_MAP_KWORLD_PLUS_TV_ANALOG;
742 polling = 40; /* ms */
744 case SAA7134_BOARD_VIDEOMATE_S350:
745 ir_codes = RC_MAP_VIDEOMATE_S350;
746 mask_keycode = 0x003f00;
747 mask_keydown = 0x040000;
749 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
750 ir_codes = RC_MAP_WINFAST;
751 mask_keycode = 0x5f00;
752 mask_keyup = 0x020000;
753 polling = 50; /* ms */
755 case SAA7134_BOARD_VIDEOMATE_M1F:
756 ir_codes = RC_MAP_VIDEOMATE_K100;
757 mask_keycode = 0x0ff00;
758 mask_keyup = 0x040000;
760 case SAA7134_BOARD_HAUPPAUGE_HVR1150:
761 case SAA7134_BOARD_HAUPPAUGE_HVR1120:
762 ir_codes = RC_MAP_HAUPPAUGE;
763 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
764 mask_keyup = 0x0040000;
765 mask_keycode = 0xffff;
768 case SAA7134_BOARD_LEADTEK_WINFAST_TV2100_FM:
769 ir_codes = RC_MAP_LEADTEK_Y04G0051;
770 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
771 mask_keyup = 0x0040000;
772 mask_keycode = 0xffff;
776 if (NULL == ir_codes) {
777 pr_err("Oops: IR config error [card=%d]\n", dev->board);
781 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
782 rc = rc_allocate_device(RC_DRIVER_SCANCODE);
791 /* init hardware-specific stuff */
792 ir->mask_keycode = mask_keycode;
793 ir->mask_keydown = mask_keydown;
794 ir->mask_keyup = mask_keyup;
795 ir->polling = polling;
796 ir->raw_decode = raw_decode;
798 /* init input device */
799 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
803 rc->open = saa7134_ir_open;
804 rc->close = saa7134_ir_close;
806 rc->driver_type = RC_DRIVER_IR_RAW;
807 rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
810 rc->device_name = saa7134_boards[dev->board].name;
811 rc->input_phys = ir->phys;
812 rc->input_id.bustype = BUS_PCI;
813 rc->input_id.version = 1;
814 if (dev->pci->subsystem_vendor) {
815 rc->input_id.vendor = dev->pci->subsystem_vendor;
816 rc->input_id.product = dev->pci->subsystem_device;
818 rc->input_id.vendor = dev->pci->vendor;
819 rc->input_id.product = dev->pci->device;
821 rc->dev.parent = &dev->pci->dev;
822 rc->map_name = ir_codes;
823 rc->driver_name = MODULE_NAME;
825 rc->timeout = IR_DEFAULT_TIMEOUT;
826 rc->max_timeout = 10 * IR_DEFAULT_TIMEOUT;
828 err = rc_register_device(rc);
841 void saa7134_input_fini(struct saa7134_dev *dev)
843 if (NULL == dev->remote)
846 rc_unregister_device(dev->remote->dev);
851 void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
853 struct i2c_board_info info;
854 struct i2c_msg msg_msi = {
863 input_dbg("IR has been disabled, not probing for i2c remote\n");
867 memset(&info, 0, sizeof(struct i2c_board_info));
868 memset(&dev->init_data, 0, sizeof(dev->init_data));
869 strscpy(info.type, "ir_video", I2C_NAME_SIZE);
871 switch (dev->board) {
872 case SAA7134_BOARD_PINNACLE_PCTV_110i:
873 case SAA7134_BOARD_PINNACLE_PCTV_310i:
874 dev->init_data.name = "Pinnacle PCTV";
875 if (pinnacle_remote == 0) {
876 dev->init_data.get_key = get_key_pinnacle_color;
877 dev->init_data.ir_codes = RC_MAP_PINNACLE_COLOR;
880 dev->init_data.get_key = get_key_pinnacle_grey;
881 dev->init_data.ir_codes = RC_MAP_PINNACLE_GREY;
885 case SAA7134_BOARD_UPMOST_PURPLE_TV:
886 dev->init_data.name = "Purple TV";
887 dev->init_data.get_key = get_key_purpletv;
888 dev->init_data.ir_codes = RC_MAP_PURPLETV;
891 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
892 dev->init_data.name = "MSI TV@nywhere Plus";
893 dev->init_data.get_key = get_key_msi_tvanywhere_plus;
894 dev->init_data.ir_codes = RC_MAP_MSI_TVANYWHERE_PLUS;
896 * MSI TV@nyware Plus requires more frequent polling
897 * otherwise it will miss some keypresses
899 dev->init_data.polling_interval = 50;
901 /* MSI TV@nywhere Plus controller doesn't seem to
902 respond to probes unless we read something from
903 an existing device. Weird...
904 REVISIT: might no longer be needed */
905 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
906 input_dbg("probe 0x%02x @ %s: %s\n",
907 msg_msi.addr, dev->i2c_adap.name,
908 (1 == rc) ? "yes" : "no");
910 case SAA7134_BOARD_SNAZIO_TVPVR_PRO:
911 dev->init_data.name = "SnaZio* TVPVR PRO";
912 dev->init_data.get_key = get_key_msi_tvanywhere_plus;
913 dev->init_data.ir_codes = RC_MAP_MSI_TVANYWHERE_PLUS;
915 * MSI TV@nyware Plus requires more frequent polling
916 * otherwise it will miss some keypresses
918 dev->init_data.polling_interval = 50;
921 * MSI TV@nywhere Plus controller doesn't seem to
922 * respond to probes unless we read something from
923 * an existing device. Weird...
924 * REVISIT: might no longer be needed
926 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
927 input_dbg("probe 0x%02x @ %s: %s\n",
928 msg_msi.addr, dev->i2c_adap.name,
929 (rc == 1) ? "yes" : "no");
931 case SAA7134_BOARD_KWORLD_PC150U:
932 /* copied and modified from MSI TV@nywhere Plus */
933 dev->init_data.name = "Kworld PC150-U";
934 dev->init_data.get_key = get_key_kworld_pc150u;
935 dev->init_data.ir_codes = RC_MAP_KWORLD_PC150U;
937 /* MSI TV@nywhere Plus controller doesn't seem to
938 respond to probes unless we read something from
939 an existing device. Weird...
940 REVISIT: might no longer be needed */
941 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
942 input_dbg("probe 0x%02x @ %s: %s\n",
943 msg_msi.addr, dev->i2c_adap.name,
944 (1 == rc) ? "yes" : "no");
946 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
947 dev->init_data.name = saa7134_boards[dev->board].name;
948 dev->init_data.ir_codes = RC_MAP_HAUPPAUGE;
949 dev->init_data.type = RC_PROTO_BIT_RC5 |
950 RC_PROTO_BIT_RC6_MCE | RC_PROTO_BIT_RC6_6A_32;
951 dev->init_data.internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
954 case SAA7134_BOARD_BEHOLD_607FM_MK3:
955 case SAA7134_BOARD_BEHOLD_607FM_MK5:
956 case SAA7134_BOARD_BEHOLD_609FM_MK3:
957 case SAA7134_BOARD_BEHOLD_609FM_MK5:
958 case SAA7134_BOARD_BEHOLD_607RDS_MK3:
959 case SAA7134_BOARD_BEHOLD_607RDS_MK5:
960 case SAA7134_BOARD_BEHOLD_609RDS_MK3:
961 case SAA7134_BOARD_BEHOLD_609RDS_MK5:
962 case SAA7134_BOARD_BEHOLD_M6:
963 case SAA7134_BOARD_BEHOLD_M63:
964 case SAA7134_BOARD_BEHOLD_M6_EXTRA:
965 case SAA7134_BOARD_BEHOLD_H6:
966 case SAA7134_BOARD_BEHOLD_X7:
967 case SAA7134_BOARD_BEHOLD_H7:
968 case SAA7134_BOARD_BEHOLD_A7:
969 dev->init_data.name = "BeholdTV";
970 dev->init_data.get_key = get_key_beholdm6xx;
971 dev->init_data.ir_codes = RC_MAP_BEHOLD;
972 dev->init_data.type = RC_PROTO_BIT_NECX;
975 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
976 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
979 case SAA7134_BOARD_AVERMEDIA_A706:
982 case SAA7134_BOARD_FLYDVB_TRIO:
983 dev->init_data.name = "FlyDVB Trio";
984 dev->init_data.get_key = get_key_flydvb_trio;
985 dev->init_data.ir_codes = RC_MAP_FLYDVB;
989 input_dbg("No I2C IR support for board %x\n", dev->board);
993 if (dev->init_data.name)
994 info.platform_data = &dev->init_data;
995 i2c_new_device(&dev->i2c_adap, &info);
998 static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
1000 struct saa7134_card_ir *ir = dev->remote;
1003 /* Generate initial event */
1004 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1005 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1006 space = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
1007 ir_raw_event_store_edge(dev->remote->dev, !space);