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/input.h>
27 #include "saa7134-reg.h"
30 static unsigned int disable_ir
;
31 module_param(disable_ir
, int, 0444);
32 MODULE_PARM_DESC(disable_ir
,"disable infrared remote support");
34 static unsigned int ir_debug
;
35 module_param(ir_debug
, int, 0644);
36 MODULE_PARM_DESC(ir_debug
,"enable debug messages [IR]");
38 static int pinnacle_remote
;
39 module_param(pinnacle_remote
, int, 0644); /* Choose Pinnacle PCTV remote */
40 MODULE_PARM_DESC(pinnacle_remote
, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
42 static int ir_rc5_remote_gap
= 885;
43 module_param(ir_rc5_remote_gap
, int, 0644);
44 static int ir_rc5_key_timeout
= 115;
45 module_param(ir_rc5_key_timeout
, int, 0644);
47 static int repeat_delay
= 500;
48 module_param(repeat_delay
, int, 0644);
49 MODULE_PARM_DESC(repeat_delay
, "delay before key repeat started");
50 static int repeat_period
= 33;
51 module_param(repeat_period
, int, 0644);
52 MODULE_PARM_DESC(repeat_period
, "repeat period between "
53 "keypresses when key is down");
55 static unsigned int disable_other_ir
;
56 module_param(disable_other_ir
, int, 0644);
57 MODULE_PARM_DESC(disable_other_ir
, "disable full codes of "
58 "alternative remotes from other manufacturers");
60 #define dprintk(fmt, arg...) if (ir_debug) \
61 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
62 #define i2cdprintk(fmt, arg...) if (ir_debug) \
63 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg)
65 /* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */
66 static int saa7134_rc5_irq(struct saa7134_dev
*dev
);
67 static int saa7134_nec_irq(struct saa7134_dev
*dev
);
68 static void nec_task(unsigned long data
);
69 static void saa7134_nec_timer(unsigned long data
);
71 /* -------------------- GPIO generic keycode builder -------------------- */
73 static int build_key(struct saa7134_dev
*dev
)
75 struct card_ir
*ir
= dev
->remote
;
78 /* here comes the additional handshake steps for some cards */
80 case SAA7134_BOARD_GOTVIEW_7135
:
81 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x80);
82 saa_clearb(SAA7134_GPIO_GPSTATUS1
, 0x80);
85 /* rising SAA7134_GPIO_GPRESCAN reads the status */
86 saa_clearb(SAA7134_GPIO_GPMODE3
,SAA7134_GPIO_GPRESCAN
);
87 saa_setb(SAA7134_GPIO_GPMODE3
,SAA7134_GPIO_GPRESCAN
);
89 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
91 if (ir
->last_gpio
== gpio
)
96 data
= ir_extract_bits(gpio
, ir
->mask_keycode
);
97 dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
98 gpio
, ir
->mask_keycode
, data
);
100 switch (dev
->board
) {
101 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG
:
102 if (data
== ir
->mask_keycode
)
103 ir_input_nokey(ir
->dev
, &ir
->ir
);
105 ir_input_keydown(ir
->dev
, &ir
->ir
, data
);
110 if ((ir
->mask_keydown
&& (0 != (gpio
& ir
->mask_keydown
))) ||
111 (ir
->mask_keyup
&& (0 == (gpio
& ir
->mask_keyup
)))) {
112 ir_input_keydown(ir
->dev
, &ir
->ir
, data
);
114 ir_input_nokey(ir
->dev
, &ir
->ir
);
117 else { /* IRQ driven mode - handle key press and release in one go */
118 if ((ir
->mask_keydown
&& (0 != (gpio
& ir
->mask_keydown
))) ||
119 (ir
->mask_keyup
&& (0 == (gpio
& ir
->mask_keyup
)))) {
120 ir_input_keydown(ir
->dev
, &ir
->ir
, data
);
121 ir_input_nokey(ir
->dev
, &ir
->ir
);
128 /* --------------------- Chip specific I2C key builders ----------------- */
130 static int get_key_flydvb_trio(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
136 /* We need this to access GPI Used by the saa_readl macro. */
137 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
140 dprintk("get_key_flydvb_trio: "
141 "gir->c->adapter->algo_data is NULL!\n");
145 /* rising SAA7134_GPIGPRESCAN reads the status */
146 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
147 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
149 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
152 return 0; /* No button press */
154 /* No button press - only before first key pressed */
159 /* weak up the IR chip */
162 while (1 != i2c_master_send(ir
->c
, &b
, 1)) {
163 if ((attempt
++) < 10) {
165 * wait a bit for next attempt -
166 * I don't know how make it better
171 i2cdprintk("send wake up byte to pic16C505 (IR chip)"
172 "failed %dx\n", attempt
);
175 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
176 i2cdprintk("read error\n");
185 static int get_key_msi_tvanywhere_plus(struct IR_i2c
*ir
, u32
*ir_key
,
191 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
192 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
194 dprintk("get_key_msi_tvanywhere_plus: "
195 "gir->c->adapter->algo_data is NULL!\n");
199 /* rising SAA7134_GPIO_GPRESCAN reads the status */
201 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
202 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
204 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
206 /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
207 I2C receive if gpio&0x40 is not low. */
210 return 0; /* No button press */
212 /* GPIO says there is a button press. Get it. */
214 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
215 i2cdprintk("read error\n");
219 /* No button press */
226 dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b
);
232 static int get_key_purpletv(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
237 if (1 != i2c_master_recv(ir
->c
, &b
, 1)) {
238 i2cdprintk("read error\n");
242 /* no button press */
255 static int get_key_hvr1110(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
257 unsigned char buf
[5], cod4
, code3
, code4
;
260 if (5 != i2c_master_recv(ir
->c
, buf
, 5))
277 static int get_key_beholdm6xx(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
279 unsigned char data
[12];
282 struct saa7134_dev
*dev
= ir
->c
->adapter
->algo_data
;
284 /* rising SAA7134_GPIO_GPRESCAN reads the status */
285 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
286 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
288 gpio
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2);
290 if (0x400000 & ~gpio
)
291 return 0; /* No button press */
293 ir
->c
->addr
= 0x5a >> 1;
295 if (12 != i2c_master_recv(ir
->c
, data
, 12)) {
296 i2cdprintk("read error\n");
299 /* IR of this card normally decode signals NEC-standard from
300 * - Sven IHOO MT 5.1R remote. xxyye718
301 * - Sven DVD HD-10xx remote. xxyyf708
304 * So, skip not our, if disable full codes mode.
306 if (data
[10] != 0x6b && data
[11] != 0x86 && disable_other_ir
)
309 /* Wrong data decode fix */
310 if (data
[9] != (unsigned char)(~data
[8]))
319 /* Common (grey or coloured) pinnacle PCTV remote handling
322 static int get_key_pinnacle(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
,
323 int parity_offset
, int marker
, int code_modulo
)
326 unsigned int start
= 0,parity
= 0,code
= 0;
329 if (4 != i2c_master_recv(ir
->c
, b
, 4)) {
330 i2cdprintk("read error\n");
334 for (start
= 0; start
< ARRAY_SIZE(b
); start
++) {
335 if (b
[start
] == marker
) {
336 code
=b
[(start
+parity_offset
+ 1) % 4];
337 parity
=b
[(start
+parity_offset
) % 4];
346 if (ir
->old
== parity
)
351 /* drop special codes when a key is held down a long time for the grey controller
352 In this case, the second bit of the code is asserted */
353 if (marker
== 0xfe && (code
& 0x40))
361 i2cdprintk("Pinnacle PCTV key %02x\n", code
);
366 /* The grey pinnacle PCTV remote
368 * There are one issue with this remote:
369 * - I2c packet does not change when the same key is pressed quickly. The workaround
370 * is to hold down each key for about half a second, so that another code is generated
371 * in the i2c packet, and the function can distinguish key presses.
373 * Sylvain Pasche <sylvain.pasche@gmail.com>
375 static int get_key_pinnacle_grey(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
378 return get_key_pinnacle(ir
, ir_key
, ir_raw
, 1, 0xfe, 0xff);
382 /* The new pinnacle PCTV remote (with the colored buttons)
384 * Ricardo Cerqueira <v4l@cerqueira.org>
386 static int get_key_pinnacle_color(struct IR_i2c
*ir
, u32
*ir_key
, u32
*ir_raw
)
388 /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
390 * this is the only value that results in 42 unique
394 return get_key_pinnacle(ir
, ir_key
, ir_raw
, 2, 0x80, 0x88);
397 void saa7134_input_irq(struct saa7134_dev
*dev
)
399 struct card_ir
*ir
= dev
->remote
;
402 saa7134_nec_irq(dev
);
403 } else if (!ir
->polling
&& !ir
->rc5_gpio
) {
405 } else if (ir
->rc5_gpio
) {
406 saa7134_rc5_irq(dev
);
410 static void saa7134_input_timer(unsigned long data
)
412 struct saa7134_dev
*dev
= (struct saa7134_dev
*)data
;
413 struct card_ir
*ir
= dev
->remote
;
416 mod_timer(&ir
->timer
, jiffies
+ msecs_to_jiffies(ir
->polling
));
419 void saa7134_ir_start(struct saa7134_dev
*dev
, struct card_ir
*ir
)
422 setup_timer(&ir
->timer
, saa7134_input_timer
,
424 ir
->timer
.expires
= jiffies
+ HZ
;
425 add_timer(&ir
->timer
);
426 } else if (ir
->rc5_gpio
) {
427 /* set timer_end for code completion */
428 init_timer(&ir
->timer_end
);
429 ir
->timer_end
.function
= ir_rc5_timer_end
;
430 ir
->timer_end
.data
= (unsigned long)ir
;
431 init_timer(&ir
->timer_keyup
);
432 ir
->timer_keyup
.function
= ir_rc5_timer_keyup
;
433 ir
->timer_keyup
.data
= (unsigned long)ir
;
437 ir
->rc5_key_timeout
= ir_rc5_key_timeout
;
438 ir
->rc5_remote_gap
= ir_rc5_remote_gap
;
439 } else if (ir
->nec_gpio
) {
440 setup_timer(&ir
->timer_keyup
, saa7134_nec_timer
,
442 tasklet_init(&ir
->tlet
, nec_task
, (unsigned long)dev
);
446 void saa7134_ir_stop(struct saa7134_dev
*dev
)
448 if (dev
->remote
->polling
)
449 del_timer_sync(&dev
->remote
->timer
);
452 int saa7134_input_init1(struct saa7134_dev
*dev
)
455 struct input_dev
*input_dev
;
456 struct ir_scancode_table
*ir_codes
= NULL
;
457 u32 mask_keycode
= 0;
458 u32 mask_keydown
= 0;
463 u64 ir_type
= IR_TYPE_OTHER
;
466 if (dev
->has_remote
!= SAA7134_REMOTE_GPIO
)
471 /* detect & configure */
472 switch (dev
->board
) {
473 case SAA7134_BOARD_FLYVIDEO2000
:
474 case SAA7134_BOARD_FLYVIDEO3000
:
475 case SAA7134_BOARD_FLYTVPLATINUM_FM
:
476 case SAA7134_BOARD_FLYTVPLATINUM_MINI2
:
477 case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM
:
478 ir_codes
= &ir_codes_flyvideo_table
;
479 mask_keycode
= 0xEC00000;
480 mask_keydown
= 0x0040000;
482 case SAA7134_BOARD_CINERGY400
:
483 case SAA7134_BOARD_CINERGY600
:
484 case SAA7134_BOARD_CINERGY600_MK3
:
485 ir_codes
= &ir_codes_cinergy_table
;
486 mask_keycode
= 0x00003f;
487 mask_keyup
= 0x040000;
489 case SAA7134_BOARD_ECS_TVP3XP
:
490 case SAA7134_BOARD_ECS_TVP3XP_4CB5
:
491 ir_codes
= &ir_codes_eztv_table
;
492 mask_keycode
= 0x00017c;
493 mask_keyup
= 0x000002;
496 case SAA7134_BOARD_KWORLD_XPERT
:
497 case SAA7134_BOARD_AVACSSMARTTV
:
498 ir_codes
= &ir_codes_pixelview_table
;
499 mask_keycode
= 0x00001F;
500 mask_keyup
= 0x000020;
503 case SAA7134_BOARD_MD2819
:
504 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT
:
505 case SAA7134_BOARD_AVERMEDIA_305
:
506 case SAA7134_BOARD_AVERMEDIA_307
:
507 case SAA7134_BOARD_AVERMEDIA_STUDIO_305
:
508 case SAA7134_BOARD_AVERMEDIA_STUDIO_505
:
509 case SAA7134_BOARD_AVERMEDIA_STUDIO_307
:
510 case SAA7134_BOARD_AVERMEDIA_STUDIO_507
:
511 case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA
:
512 case SAA7134_BOARD_AVERMEDIA_GO_007_FM
:
513 case SAA7134_BOARD_AVERMEDIA_M102
:
514 case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS
:
515 ir_codes
= &ir_codes_avermedia_table
;
516 mask_keycode
= 0x0007C8;
517 mask_keydown
= 0x000010;
519 /* Set GPIO pin2 to high to enable the IR controller */
520 saa_setb(SAA7134_GPIO_GPMODE0
, 0x4);
521 saa_setb(SAA7134_GPIO_GPSTATUS0
, 0x4);
523 case SAA7134_BOARD_AVERMEDIA_M135A
:
524 ir_codes
= &ir_codes_avermedia_m135a_table
;
525 mask_keydown
= 0x0040000;
526 mask_keycode
= 0x00013f;
529 case SAA7134_BOARD_AVERMEDIA_777
:
530 case SAA7134_BOARD_AVERMEDIA_A16AR
:
531 ir_codes
= &ir_codes_avermedia_table
;
532 mask_keycode
= 0x02F200;
533 mask_keydown
= 0x000400;
535 /* Without this we won't receive key up events */
536 saa_setb(SAA7134_GPIO_GPMODE1
, 0x1);
537 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x1);
539 case SAA7134_BOARD_AVERMEDIA_A16D
:
540 ir_codes
= &ir_codes_avermedia_a16d_table
;
541 mask_keycode
= 0x02F200;
542 mask_keydown
= 0x000400;
543 polling
= 50; /* ms */
544 /* Without this we won't receive key up events */
545 saa_setb(SAA7134_GPIO_GPMODE1
, 0x1);
546 saa_setb(SAA7134_GPIO_GPSTATUS1
, 0x1);
548 case SAA7134_BOARD_KWORLD_TERMINATOR
:
549 ir_codes
= &ir_codes_pixelview_table
;
550 mask_keycode
= 0x00001f;
551 mask_keyup
= 0x000060;
554 case SAA7134_BOARD_MANLI_MTV001
:
555 case SAA7134_BOARD_MANLI_MTV002
:
556 ir_codes
= &ir_codes_manli_table
;
557 mask_keycode
= 0x001f00;
558 mask_keyup
= 0x004000;
559 polling
= 50; /* ms */
561 case SAA7134_BOARD_BEHOLD_409FM
:
562 case SAA7134_BOARD_BEHOLD_401
:
563 case SAA7134_BOARD_BEHOLD_403
:
564 case SAA7134_BOARD_BEHOLD_403FM
:
565 case SAA7134_BOARD_BEHOLD_405
:
566 case SAA7134_BOARD_BEHOLD_405FM
:
567 case SAA7134_BOARD_BEHOLD_407
:
568 case SAA7134_BOARD_BEHOLD_407FM
:
569 case SAA7134_BOARD_BEHOLD_409
:
570 case SAA7134_BOARD_BEHOLD_505FM
:
571 case SAA7134_BOARD_BEHOLD_505RDS_MK5
:
572 case SAA7134_BOARD_BEHOLD_505RDS_MK3
:
573 case SAA7134_BOARD_BEHOLD_507_9FM
:
574 case SAA7134_BOARD_BEHOLD_507RDS_MK3
:
575 case SAA7134_BOARD_BEHOLD_507RDS_MK5
:
576 ir_codes
= &ir_codes_manli_table
;
577 mask_keycode
= 0x003f00;
578 mask_keyup
= 0x004000;
579 polling
= 50; /* ms */
581 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM
:
582 ir_codes
= &ir_codes_behold_columbus_table
;
583 mask_keycode
= 0x003f00;
584 mask_keyup
= 0x004000;
587 case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS
:
588 ir_codes
= &ir_codes_pctv_sedna_table
;
589 mask_keycode
= 0x001f00;
590 mask_keyup
= 0x004000;
593 case SAA7134_BOARD_GOTVIEW_7135
:
594 ir_codes
= &ir_codes_gotview7135_table
;
595 mask_keycode
= 0x0003CC;
596 mask_keydown
= 0x000010;
597 polling
= 5; /* ms */
598 saa_setb(SAA7134_GPIO_GPMODE1
, 0x80);
600 case SAA7134_BOARD_VIDEOMATE_TV_PVR
:
601 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS
:
602 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII
:
603 ir_codes
= &ir_codes_videomate_tv_pvr_table
;
604 mask_keycode
= 0x00003F;
605 mask_keyup
= 0x400000;
608 case SAA7134_BOARD_PROTEUS_2309
:
609 ir_codes
= &ir_codes_proteus_2309_table
;
610 mask_keycode
= 0x00007F;
611 mask_keyup
= 0x000080;
614 case SAA7134_BOARD_VIDEOMATE_DVBT_300
:
615 case SAA7134_BOARD_VIDEOMATE_DVBT_200
:
616 ir_codes
= &ir_codes_videomate_tv_pvr_table
;
617 mask_keycode
= 0x003F00;
618 mask_keyup
= 0x040000;
620 case SAA7134_BOARD_FLYDVBS_LR300
:
621 case SAA7134_BOARD_FLYDVBT_LR301
:
622 case SAA7134_BOARD_FLYDVBTDUO
:
623 ir_codes
= &ir_codes_flydvb_table
;
624 mask_keycode
= 0x0001F00;
625 mask_keydown
= 0x0040000;
627 case SAA7134_BOARD_ASUSTeK_P7131_DUAL
:
628 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA
:
629 case SAA7134_BOARD_ASUSTeK_P7131_ANALOG
:
630 ir_codes
= &ir_codes_asus_pc39_table
;
631 mask_keydown
= 0x0040000;
634 case SAA7134_BOARD_ENCORE_ENLTV
:
635 case SAA7134_BOARD_ENCORE_ENLTV_FM
:
636 ir_codes
= &ir_codes_encore_enltv_table
;
637 mask_keycode
= 0x00007f;
638 mask_keyup
= 0x040000;
641 case SAA7134_BOARD_ENCORE_ENLTV_FM53
:
642 ir_codes
= &ir_codes_encore_enltv_fm53_table
;
643 mask_keydown
= 0x0040000;
644 mask_keycode
= 0x00007f;
647 case SAA7134_BOARD_10MOONSTVMASTER3
:
648 ir_codes
= &ir_codes_encore_enltv_table
;
649 mask_keycode
= 0x5f80000;
650 mask_keyup
= 0x8000000;
653 case SAA7134_BOARD_GENIUS_TVGO_A11MCE
:
654 ir_codes
= &ir_codes_genius_tvgo_a11mce_table
;
656 mask_keydown
= 0xf00000;
657 polling
= 50; /* ms */
659 case SAA7134_BOARD_REAL_ANGEL_220
:
660 ir_codes
= &ir_codes_real_audio_220_32_keys_table
;
661 mask_keycode
= 0x3f00;
663 polling
= 50; /* ms */
665 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG
:
666 ir_codes
= &ir_codes_kworld_plus_tv_analog_table
;
668 polling
= 40; /* ms */
670 case SAA7134_BOARD_VIDEOMATE_S350
:
671 ir_codes
= &ir_codes_videomate_s350_table
;
672 mask_keycode
= 0x003f00;
673 mask_keydown
= 0x040000;
675 case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S
:
676 ir_codes
= &ir_codes_winfast_table
;
677 mask_keycode
= 0x5f00;
678 mask_keyup
= 0x020000;
679 polling
= 50; /* ms */
683 if (NULL
== ir_codes
) {
684 printk("%s: Oops: IR config error [card=%d]\n",
685 dev
->name
, dev
->board
);
689 ir
= kzalloc(sizeof(*ir
), GFP_KERNEL
);
690 input_dev
= input_allocate_device();
691 if (!ir
|| !input_dev
) {
698 /* init hardware-specific stuff */
699 ir
->mask_keycode
= mask_keycode
;
700 ir
->mask_keydown
= mask_keydown
;
701 ir
->mask_keyup
= mask_keyup
;
702 ir
->polling
= polling
;
703 ir
->rc5_gpio
= rc5_gpio
;
704 ir
->nec_gpio
= nec_gpio
;
706 /* init input device */
707 snprintf(ir
->name
, sizeof(ir
->name
), "saa7134 IR (%s)",
708 saa7134_boards
[dev
->board
].name
);
709 snprintf(ir
->phys
, sizeof(ir
->phys
), "pci-%s/ir0",
712 err
= ir_input_init(input_dev
, &ir
->ir
, ir_type
);
716 input_dev
->name
= ir
->name
;
717 input_dev
->phys
= ir
->phys
;
718 input_dev
->id
.bustype
= BUS_PCI
;
719 input_dev
->id
.version
= 1;
720 if (dev
->pci
->subsystem_vendor
) {
721 input_dev
->id
.vendor
= dev
->pci
->subsystem_vendor
;
722 input_dev
->id
.product
= dev
->pci
->subsystem_device
;
724 input_dev
->id
.vendor
= dev
->pci
->vendor
;
725 input_dev
->id
.product
= dev
->pci
->device
;
727 input_dev
->dev
.parent
= &dev
->pci
->dev
;
730 saa7134_ir_start(dev
, ir
);
732 err
= ir_input_register(ir
->dev
, ir_codes
, NULL
);
736 /* the remote isn't as bouncy as a keyboard */
737 ir
->dev
->rep
[REP_DELAY
] = repeat_delay
;
738 ir
->dev
->rep
[REP_PERIOD
] = repeat_period
;
743 saa7134_ir_stop(dev
);
750 void saa7134_input_fini(struct saa7134_dev
*dev
)
752 if (NULL
== dev
->remote
)
755 saa7134_ir_stop(dev
);
756 ir_input_unregister(dev
->remote
->dev
);
761 void saa7134_probe_i2c_ir(struct saa7134_dev
*dev
)
763 struct i2c_board_info info
;
765 struct i2c_msg msg_msi
= {
775 dprintk("IR has been disabled, not probing for i2c remote\n");
779 memset(&info
, 0, sizeof(struct i2c_board_info
));
780 memset(&dev
->init_data
, 0, sizeof(dev
->init_data
));
781 strlcpy(info
.type
, "ir_video", I2C_NAME_SIZE
);
783 switch (dev
->board
) {
784 case SAA7134_BOARD_PINNACLE_PCTV_110i
:
785 case SAA7134_BOARD_PINNACLE_PCTV_310i
:
786 dev
->init_data
.name
= "Pinnacle PCTV";
787 if (pinnacle_remote
== 0) {
788 dev
->init_data
.get_key
= get_key_pinnacle_color
;
789 dev
->init_data
.ir_codes
= &ir_codes_pinnacle_color_table
;
792 dev
->init_data
.get_key
= get_key_pinnacle_grey
;
793 dev
->init_data
.ir_codes
= &ir_codes_pinnacle_grey_table
;
797 case SAA7134_BOARD_UPMOST_PURPLE_TV
:
798 dev
->init_data
.name
= "Purple TV";
799 dev
->init_data
.get_key
= get_key_purpletv
;
800 dev
->init_data
.ir_codes
= &ir_codes_purpletv_table
;
803 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS
:
804 dev
->init_data
.name
= "MSI TV@nywhere Plus";
805 dev
->init_data
.get_key
= get_key_msi_tvanywhere_plus
;
806 dev
->init_data
.ir_codes
= &ir_codes_msi_tvanywhere_plus_table
;
808 /* MSI TV@nywhere Plus controller doesn't seem to
809 respond to probes unless we read something from
810 an existing device. Weird...
811 REVISIT: might no longer be needed */
812 rc
= i2c_transfer(&dev
->i2c_adap
, &msg_msi
, 1);
813 dprintk(KERN_DEBUG
"probe 0x%02x @ %s: %s\n",
814 msg_msi
.addr
, dev
->i2c_adap
.name
,
815 (1 == rc
) ? "yes" : "no");
817 case SAA7134_BOARD_HAUPPAUGE_HVR1110
:
818 dev
->init_data
.name
= "HVR 1110";
819 dev
->init_data
.get_key
= get_key_hvr1110
;
820 dev
->init_data
.ir_codes
= &ir_codes_hauppauge_new_table
;
823 case SAA7134_BOARD_BEHOLD_607FM_MK3
:
824 case SAA7134_BOARD_BEHOLD_607FM_MK5
:
825 case SAA7134_BOARD_BEHOLD_609FM_MK3
:
826 case SAA7134_BOARD_BEHOLD_609FM_MK5
:
827 case SAA7134_BOARD_BEHOLD_607RDS_MK3
:
828 case SAA7134_BOARD_BEHOLD_607RDS_MK5
:
829 case SAA7134_BOARD_BEHOLD_609RDS_MK3
:
830 case SAA7134_BOARD_BEHOLD_609RDS_MK5
:
831 case SAA7134_BOARD_BEHOLD_M6
:
832 case SAA7134_BOARD_BEHOLD_M63
:
833 case SAA7134_BOARD_BEHOLD_M6_EXTRA
:
834 case SAA7134_BOARD_BEHOLD_H6
:
835 case SAA7134_BOARD_BEHOLD_X7
:
836 dev
->init_data
.name
= "BeholdTV";
837 dev
->init_data
.get_key
= get_key_beholdm6xx
;
838 dev
->init_data
.ir_codes
= &ir_codes_behold_table
;
841 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501
:
842 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506
:
845 case SAA7134_BOARD_FLYDVB_TRIO
:
846 dev
->init_data
.name
= "FlyDVB Trio";
847 dev
->init_data
.get_key
= get_key_flydvb_trio
;
848 dev
->init_data
.ir_codes
= &ir_codes_flydvb_table
;
852 dprintk("No I2C IR support for board %x\n", dev
->board
);
856 if (dev
->init_data
.name
)
857 info
.platform_data
= &dev
->init_data
;
858 i2c_new_device(&dev
->i2c_adap
, &info
);
861 static int saa7134_rc5_irq(struct saa7134_dev
*dev
)
863 struct card_ir
*ir
= dev
->remote
;
866 unsigned long current_jiffies
, timeout
;
868 /* get time of bit */
869 current_jiffies
= jiffies
;
870 do_gettimeofday(&tv
);
872 /* avoid overflow with gap >1s */
873 if (tv
.tv_sec
- ir
->base_time
.tv_sec
> 1) {
876 gap
= 1000000 * (tv
.tv_sec
- ir
->base_time
.tv_sec
) +
877 tv
.tv_usec
- ir
->base_time
.tv_usec
;
880 /* active code => add bit */
882 /* only if in the code (otherwise spurious IRQ or timer
884 if (ir
->last_bit
< 28) {
885 ir
->last_bit
= (gap
- ir_rc5_remote_gap
/ 2) /
887 ir
->code
|= 1 << ir
->last_bit
;
889 /* starting new code */
896 timeout
= current_jiffies
+ (500 + 30 * HZ
) / 1000;
897 mod_timer(&ir
->timer_end
, timeout
);
904 /* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
905 The first pulse (start) has 9 + 4.5 ms
908 static void saa7134_nec_timer(unsigned long data
)
910 struct saa7134_dev
*dev
= (struct saa7134_dev
*) data
;
911 struct card_ir
*ir
= dev
->remote
;
913 dprintk("Cancel key repeat\n");
915 ir_input_nokey(ir
->dev
, &ir
->ir
);
918 static void nec_task(unsigned long data
)
920 struct saa7134_dev
*dev
= (struct saa7134_dev
*) data
;
923 int count
, pulse
, oldpulse
, gap
;
924 u32 ircode
= 0, not_code
= 0;
928 printk(KERN_ERR
"saa713x/ir: Can't recover dev struct\n");
929 /* GPIO will be kept disabled */
935 /* rising SAA7134_GPIO_GPRESCAN reads the status */
936 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
937 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
939 oldpulse
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2) & ir
->mask_keydown
;
942 do_gettimeofday(&tv
);
945 /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
946 Unfortunately, using IRQ to decode pulse didn't work, since it uses
947 a pulse train of 38KHz. This means one pulse on each 52 us
950 /* Wait until the end of pulse/space or 5 ms */
951 for (count
= 0; count
< 500; count
++) {
953 /* rising SAA7134_GPIO_GPRESCAN reads the status */
954 saa_clearb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
955 saa_setb(SAA7134_GPIO_GPMODE3
, SAA7134_GPIO_GPRESCAN
);
956 pulse
= saa_readl(SAA7134_GPIO_GPSTATUS0
>> 2)
958 if (pulse
!= oldpulse
)
962 do_gettimeofday(&tv
);
963 gap
= 1000000 * (tv
.tv_sec
- ir
->base_time
.tv_sec
) +
964 tv
.tv_usec
- ir
->base_time
.tv_usec
;
967 /* Bit 0 has 560 us, while bit 1 has 1120 us.
968 Do something only if bit == 1
970 if (ngap
&& (gap
> 560 + 280)) {
971 unsigned int shift
= ngap
- 1;
973 /* Address first, then command */
976 ircode
|= 1 << shift
;
977 } else if (shift
< 16) {
978 not_code
|= 1 << shift
;
979 } else if (shift
< 24) {
981 ircode
|= 1 << shift
;
984 not_code
|= 1 << shift
;
993 /* TIMEOUT - Long pulse */
1000 /* FIXME: should check if not_code == ~ircode */
1001 ir
->code
= ir_extract_bits(ircode
, ir
->mask_keycode
);
1003 dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
1004 ir
->code
, ircode
, not_code
);
1006 ir_input_keydown(ir
->dev
, &ir
->ir
, ir
->code
);
1008 dprintk("Repeat last key\n");
1010 /* Keep repeating the last key */
1011 mod_timer(&ir
->timer_keyup
, jiffies
+ msecs_to_jiffies(150));
1013 saa_setl(SAA7134_IRQ2
, SAA7134_IRQ2_INTE_GPIO18
);
1016 static int saa7134_nec_irq(struct saa7134_dev
*dev
)
1018 struct card_ir
*ir
= dev
->remote
;
1020 saa_clearl(SAA7134_IRQ2
, SAA7134_IRQ2_INTE_GPIO18
);
1021 tasklet_schedule(&ir
->tlet
);