Merge branch 'v6v7' into devel
[linux/fpc-iii.git] / drivers / media / video / saa7134 / saa7134-input.c
blobdc646e65edb7bdf3fd77e12423c166316e11e863
1 /*
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"
28 #include "saa7134.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;
57 u32 gpio, data;
59 /* here comes the additional handshake steps for some cards */
60 switch (dev->board) {
61 case SAA7134_BOARD_GOTVIEW_7135:
62 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x80);
63 saa_clearb(SAA7134_GPIO_GPSTATUS1, 0x80);
64 break;
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);
71 if (ir->polling) {
72 if (ir->last_gpio == gpio)
73 return 0;
74 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);
81 switch (dev->board) {
82 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
83 if (data == ir->mask_keycode)
84 rc_keyup(ir->dev);
85 else
86 rc_keydown_notimeout(ir->dev, data, 0);
87 return 0;
90 if (ir->polling) {
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);
94 } else {
95 rc_keyup(ir->dev);
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);
102 rc_keyup(ir->dev);
106 return 0;
109 /* --------------------- Chip specific I2C key builders ----------------- */
111 static int get_key_flydvb_trio(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
113 int gpio;
114 int attempt = 0;
115 unsigned char b;
117 /* We need this to access GPI Used by the saa_readl macro. */
118 struct saa7134_dev *dev = ir->c->adapter->algo_data;
120 if (dev == NULL) {
121 i2cdprintk("get_key_flydvb_trio: "
122 "ir->c->adapter->algo_data is NULL!\n");
123 return -EIO;
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);
132 if (0x40000 & ~gpio)
133 return 0; /* No button press */
135 /* No button press - only before first key pressed */
136 if (b == 0xFF)
137 return 0;
139 /* poll IR chip */
140 /* weak up the IR chip */
141 b = 0;
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
149 msleep(10);
150 continue;
152 i2cdprintk("send wake up byte to pic16C505 (IR chip)"
153 "failed %dx\n", attempt);
154 return -EIO;
156 if (1 != i2c_master_recv(ir->c, &b, 1)) {
157 i2cdprintk("read error\n");
158 return -EIO;
161 *ir_key = b;
162 *ir_raw = b;
163 return 1;
166 static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key,
167 u32 *ir_raw)
169 unsigned char b;
170 int gpio;
172 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
173 struct saa7134_dev *dev = ir->c->adapter->algo_data;
174 if (dev == NULL) {
175 i2cdprintk("get_key_msi_tvanywhere_plus: "
176 "ir->c->adapter->algo_data is NULL!\n");
177 return -EIO;
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. */
190 if (gpio & 0x40)
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");
197 return -EIO;
200 /* No button press */
202 if (b == 0xff)
203 return 0;
205 /* Button pressed */
207 dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b);
208 *ir_key = b;
209 *ir_raw = b;
210 return 1;
213 static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
215 unsigned char b;
217 /* poll IR chip */
218 if (1 != i2c_master_recv(ir->c, &b, 1)) {
219 i2cdprintk("read error\n");
220 return -EIO;
223 /* no button press */
224 if (b==0)
225 return 0;
227 /* repeating */
228 if (b & 0x80)
229 return 1;
231 *ir_key = b;
232 *ir_raw = b;
233 return 1;
236 static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
238 unsigned char buf[5], cod4, code3, code4;
240 /* poll IR chip */
241 if (5 != i2c_master_recv(ir->c, buf, 5))
242 return -EIO;
244 cod4 = buf[4];
245 code4 = (cod4 >> 2);
246 code3 = buf[3];
247 if (code3 == 0)
248 /* no key pressed */
249 return 0;
251 /* return key */
252 *ir_key = code4;
253 *ir_raw = code4;
254 return 1;
258 static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
260 unsigned char data[12];
261 u32 gpio;
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");
278 return -EIO;
281 if (data[9] != (unsigned char)(~data[8]))
282 return 0;
284 *ir_raw = ((data[10] << 16) | (data[11] << 8) | (data[9] << 0));
285 *ir_key = *ir_raw;
287 return 1;
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)
296 unsigned char b[4];
297 unsigned int start = 0,parity = 0,code = 0;
299 /* poll IR chip */
300 if (4 != i2c_master_recv(ir->c, b, 4)) {
301 i2cdprintk("read error\n");
302 return -EIO;
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];
312 /* Empty Request */
313 if (parity == 0)
314 return 0;
316 /* Repeating... */
317 if (ir->old == parity)
318 return 0;
320 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))
325 return 0;
327 code %= code_modulo;
329 *ir_raw = code;
330 *ir_key = code;
332 i2cdprintk("Pinnacle PCTV key %02x\n", code);
334 return 1;
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
362 * codes < 128
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)
373 return;
375 ir = dev->remote;
376 if (!ir->running)
377 return;
379 if (!ir->polling && !ir->raw_decode) {
380 build_key(dev);
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;
391 build_key(dev);
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);
402 ir->active = false;
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)
411 return -EINVAL;
413 ir = dev->remote;
414 if (ir->running)
415 return 0;
417 ir->running = true;
418 ir->active = false;
420 if (ir->polling) {
421 setup_timer(&ir->timer, saa7134_input_timer,
422 (unsigned long)dev);
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,
428 (unsigned long)dev);
431 return 0;
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)
440 return;
442 ir = dev->remote;
443 if (!ir->running)
444 return;
446 if (ir->polling || ir->raw_decode)
447 del_timer_sync(&ir->timer);
449 ir->active = false;
450 ir->running = false;
452 return;
455 int saa7134_ir_start(struct saa7134_dev *dev)
457 if (dev->remote->users)
458 return __saa7134_ir_start(dev);
460 return 0;
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;
489 struct rc_dev *rc;
490 char *ir_codes = NULL;
491 u32 mask_keycode = 0;
492 u32 mask_keydown = 0;
493 u32 mask_keyup = 0;
494 unsigned polling = 0;
495 bool raw_decode = false;
496 int err;
498 if (dev->has_remote != SAA7134_REMOTE_GPIO)
499 return -ENODEV;
500 if (disable_ir)
501 return -ENODEV;
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;
513 break;
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;
520 break;
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;
526 polling = 50; // ms
527 break;
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;
533 polling = 50; // ms
534 break;
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;
550 polling = 50; // ms
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);
554 break;
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;
560 raw_decode = true;
561 break;
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;
567 raw_decode = true;
568 break;
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;
574 polling = 50; // ms
575 /* Without this we won't receive key up events */
576 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
577 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
578 break;
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);
587 break;
588 case SAA7134_BOARD_KWORLD_TERMINATOR:
589 ir_codes = RC_MAP_PIXELVIEW;
590 mask_keycode = 0x00001f;
591 mask_keyup = 0x000060;
592 polling = 50; // ms
593 break;
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 */
600 break;
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 */
620 break;
621 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
622 ir_codes = RC_MAP_BEHOLD_COLUMBUS;
623 mask_keycode = 0x003f00;
624 mask_keyup = 0x004000;
625 polling = 50; // ms
626 break;
627 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
628 ir_codes = RC_MAP_PCTV_SEDNA;
629 mask_keycode = 0x001f00;
630 mask_keyup = 0x004000;
631 polling = 50; // ms
632 break;
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);
639 break;
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;
646 polling = 50; // ms
647 break;
648 case SAA7134_BOARD_PROTEUS_2309:
649 ir_codes = RC_MAP_PROTEUS_2309;
650 mask_keycode = 0x00007F;
651 mask_keyup = 0x000080;
652 polling = 50; // ms
653 break;
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;
659 break;
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;
666 break;
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;
674 raw_decode = true;
675 break;
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;
681 polling = 50; // ms
682 break;
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;
688 raw_decode = true;
689 break;
690 case SAA7134_BOARD_10MOONSTVMASTER3:
691 ir_codes = RC_MAP_ENCORE_ENLTV;
692 mask_keycode = 0x5f80000;
693 mask_keyup = 0x8000000;
694 polling = 50; //ms
695 break;
696 case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
697 ir_codes = RC_MAP_GENIUS_TVGO_A11MCE;
698 mask_keycode = 0xff;
699 mask_keydown = 0xf00000;
700 polling = 50; /* ms */
701 break;
702 case SAA7134_BOARD_REAL_ANGEL_220:
703 ir_codes = RC_MAP_REAL_AUDIO_220_32_KEYS;
704 mask_keycode = 0x3f00;
705 mask_keyup = 0x4000;
706 polling = 50; /* ms */
707 break;
708 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
709 ir_codes = RC_MAP_KWORLD_PLUS_TV_ANALOG;
710 mask_keycode = 0x7f;
711 polling = 40; /* ms */
712 break;
713 case SAA7134_BOARD_VIDEOMATE_S350:
714 ir_codes = RC_MAP_VIDEOMATE_S350;
715 mask_keycode = 0x003f00;
716 mask_keydown = 0x040000;
717 break;
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 */
723 break;
724 case SAA7134_BOARD_VIDEOMATE_M1F:
725 ir_codes = RC_MAP_VIDEOMATE_M1F;
726 mask_keycode = 0x0ff00;
727 mask_keyup = 0x040000;
728 break;
730 if (NULL == ir_codes) {
731 printk("%s: Oops: IR config error [card=%d]\n",
732 dev->name, dev->board);
733 return -ENODEV;
736 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
737 rc = rc_allocate_device();
738 if (!ir || !rc) {
739 err = -ENOMEM;
740 goto err_out_free;
743 ir->dev = rc;
744 dev->remote = ir;
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",
757 pci_name(dev->pci));
759 rc->priv = dev;
760 rc->open = saa7134_ir_open;
761 rc->close = saa7134_ir_close;
762 if (raw_decode)
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;
772 } else {
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);
781 if (err)
782 goto err_out_free;
784 return 0;
786 err_out_free:
787 rc_free_device(rc);
788 dev->remote = NULL;
789 kfree(ir);
790 return err;
793 void saa7134_input_fini(struct saa7134_dev *dev)
795 if (NULL == dev->remote)
796 return;
798 saa7134_ir_stop(dev);
799 rc_unregister_device(dev->remote->dev);
800 kfree(dev->remote);
801 dev->remote = NULL;
804 void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
806 struct i2c_board_info info;
807 struct i2c_msg msg_msi = {
808 .addr = 0x50,
809 .flags = I2C_M_RD,
810 .len = 0,
811 .buf = NULL,
813 int rc;
815 if (disable_ir) {
816 dprintk("IR has been disabled, not probing for i2c remote\n");
817 return;
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;
831 info.addr = 0x47;
832 } else {
833 dev->init_data.get_key = get_key_pinnacle_grey;
834 dev->init_data.ir_codes = RC_MAP_PINNACLE_GREY;
835 info.addr = 0x47;
837 break;
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;
842 info.addr = 0x7a;
843 break;
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;
853 info.addr = 0x30;
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");
862 break;
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;
867 info.addr = 0x71;
868 break;
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;
888 info.addr = 0x2d;
889 break;
890 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
891 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
892 info.addr = 0x40;
893 break;
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;
898 info.addr = 0x0b;
899 break;
900 default:
901 dprintk("No I2C IR support for board %x\n", dev->board);
902 return;
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;
914 int space;
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.
927 if (!ir->active) {
928 timeout = jiffies + jiffies_to_msecs(15);
929 mod_timer(&ir->timer, timeout);
930 ir->active = true;
933 return 1;