1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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>
26
27#include "saa7134-reg.h"
28#include "saa7134.h"
29
30#define MODULE_NAME "saa7134"
31
32static unsigned int disable_ir;
33module_param(disable_ir, int, 0444);
34MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
35
36static unsigned int ir_debug;
37module_param(ir_debug, int, 0644);
38MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
39
40static int pinnacle_remote;
41module_param(pinnacle_remote, int, 0644);
42MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
43
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)
48
49
50static int saa7134_raw_decode_irq(struct saa7134_dev *dev);
51
52
53
54static int build_key(struct saa7134_dev *dev)
55{
56 struct saa7134_card_ir *ir = dev->remote;
57 u32 gpio, data;
58
59
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;
65 }
66
67 saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
68 saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
69
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;
75 }
76
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);
80
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;
88 }
89
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);
96 }
97 }
98 else {
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);
103 }
104 }
105
106 return 0;
107}
108
109
110
111static int get_key_flydvb_trio(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
112{
113 int gpio;
114 int attempt = 0;
115 unsigned char b;
116
117
118 struct saa7134_dev *dev = ir->c->adapter->algo_data;
119
120 if (dev == NULL) {
121 i2cdprintk("get_key_flydvb_trio: "
122 "ir->c->adapter->algo_data is NULL!\n");
123 return -EIO;
124 }
125
126
127 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
128 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
129
130 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
131
132 if (0x40000 & ~gpio)
133 return 0;
134
135
136 if (b == 0xFF)
137 return 0;
138
139
140
141 b = 0;
142
143 while (1 != i2c_master_send(ir->c, &b, 1)) {
144 if ((attempt++) < 10) {
145
146
147
148
149 msleep(10);
150 continue;
151 }
152 i2cdprintk("send wake up byte to pic16C505 (IR chip)"
153 "failed %dx\n", attempt);
154 return -EIO;
155 }
156 if (1 != i2c_master_recv(ir->c, &b, 1)) {
157 i2cdprintk("read error\n");
158 return -EIO;
159 }
160
161 *ir_key = b;
162 *ir_raw = b;
163 return 1;
164}
165
166static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key,
167 u32 *ir_raw)
168{
169 unsigned char b;
170 int gpio;
171
172
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;
178 }
179
180
181
182 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
183 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
184
185 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
186
187
188
189
190 if (gpio & 0x40)
191 return 0;
192
193
194
195 if (1 != i2c_master_recv(ir->c, &b, 1)) {
196 i2cdprintk("read error\n");
197 return -EIO;
198 }
199
200
201
202 if (b == 0xff)
203 return 0;
204
205
206
207 dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b);
208 *ir_key = b;
209 *ir_raw = b;
210 return 1;
211}
212
213static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
214{
215 unsigned char b;
216
217
218 if (1 != i2c_master_recv(ir->c, &b, 1)) {
219 i2cdprintk("read error\n");
220 return -EIO;
221 }
222
223
224 if (b==0)
225 return 0;
226
227
228 if (b & 0x80)
229 return 1;
230
231 *ir_key = b;
232 *ir_raw = b;
233 return 1;
234}
235
236static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
237{
238 unsigned char buf[5], cod4, code3, code4;
239
240
241 if (5 != i2c_master_recv(ir->c, buf, 5))
242 return -EIO;
243
244 cod4 = buf[4];
245 code4 = (cod4 >> 2);
246 code3 = buf[3];
247 if (code3 == 0)
248
249 return 0;
250
251
252 *ir_key = code4;
253 *ir_raw = code4;
254 return 1;
255}
256
257
258static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
259{
260 unsigned char data[12];
261 u32 gpio;
262
263 struct saa7134_dev *dev = ir->c->adapter->algo_data;
264
265
266 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
267 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
268
269 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
270
271 if (0x400000 & ~gpio)
272 return 0;
273
274 ir->c->addr = 0x5a >> 1;
275
276 if (12 != i2c_master_recv(ir->c, data, 12)) {
277 i2cdprintk("read error\n");
278 return -EIO;
279 }
280
281 if (data[9] != (unsigned char)(~data[8]))
282 return 0;
283
284 *ir_raw = ((data[10] << 16) | (data[11] << 8) | (data[9] << 0));
285 *ir_key = *ir_raw;
286
287 return 1;
288}
289
290
291
292
293static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
294 int parity_offset, int marker, int code_modulo)
295{
296 unsigned char b[4];
297 unsigned int start = 0,parity = 0,code = 0;
298
299
300 if (4 != i2c_master_recv(ir->c, b, 4)) {
301 i2cdprintk("read error\n");
302 return -EIO;
303 }
304
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];
309 }
310 }
311
312
313 if (parity == 0)
314 return 0;
315
316
317 if (ir->old == parity)
318 return 0;
319
320 ir->old = parity;
321
322
323
324 if (marker == 0xfe && (code & 0x40))
325 return 0;
326
327 code %= code_modulo;
328
329 *ir_raw = code;
330 *ir_key = code;
331
332 i2cdprintk("Pinnacle PCTV key %02x\n", code);
333
334 return 1;
335}
336
337
338
339
340
341
342
343
344
345
346static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
347{
348
349 return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff);
350}
351
352
353
354
355
356
357static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
358{
359
360
361
362
363
364
365 return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88);
366}
367
368void saa7134_input_irq(struct saa7134_dev *dev)
369{
370 struct saa7134_card_ir *ir;
371
372 if (!dev || !dev->remote)
373 return;
374
375 ir = dev->remote;
376 if (!ir->running)
377 return;
378
379 if (!ir->polling && !ir->raw_decode) {
380 build_key(dev);
381 } else if (ir->raw_decode) {
382 saa7134_raw_decode_irq(dev);
383 }
384}
385
386static void saa7134_input_timer(unsigned long data)
387{
388 struct saa7134_dev *dev = (struct saa7134_dev *)data;
389 struct saa7134_card_ir *ir = dev->remote;
390
391 build_key(dev);
392 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
393}
394
395static void ir_raw_decode_timer_end(unsigned long data)
396{
397 struct saa7134_dev *dev = (struct saa7134_dev *)data;
398 struct saa7134_card_ir *ir = dev->remote;
399
400 ir_raw_event_handle(dev->remote->dev);
401
402 ir->active = false;
403}
404
405static int __saa7134_ir_start(void *priv)
406{
407 struct saa7134_dev *dev = priv;
408 struct saa7134_card_ir *ir;
409
410 if (!dev || !dev->remote)
411 return -EINVAL;
412
413 ir = dev->remote;
414 if (ir->running)
415 return 0;
416
417 ir->running = true;
418 ir->active = false;
419
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
427 setup_timer(&ir->timer, ir_raw_decode_timer_end,
428 (unsigned long)dev);
429 }
430
431 return 0;
432}
433
434static void __saa7134_ir_stop(void *priv)
435{
436 struct saa7134_dev *dev = priv;
437 struct saa7134_card_ir *ir;
438
439 if (!dev || !dev->remote)
440 return;
441
442 ir = dev->remote;
443 if (!ir->running)
444 return;
445
446 if (ir->polling || ir->raw_decode)
447 del_timer_sync(&ir->timer);
448
449 ir->active = false;
450 ir->running = false;
451
452 return;
453}
454
455int saa7134_ir_start(struct saa7134_dev *dev)
456{
457 if (dev->remote->users)
458 return __saa7134_ir_start(dev);
459
460 return 0;
461}
462
463void saa7134_ir_stop(struct saa7134_dev *dev)
464{
465 if (dev->remote->users)
466 __saa7134_ir_stop(dev);
467}
468
469static int saa7134_ir_open(struct rc_dev *rc)
470{
471 struct saa7134_dev *dev = rc->priv;
472
473 dev->remote->users++;
474 return __saa7134_ir_start(dev);
475}
476
477static void saa7134_ir_close(struct rc_dev *rc)
478{
479 struct saa7134_dev *dev = rc->priv;
480
481 dev->remote->users--;
482 if (!dev->remote->users)
483 __saa7134_ir_stop(dev);
484}
485
486int saa7134_input_init1(struct saa7134_dev *dev)
487{
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;
497
498 if (dev->has_remote != SAA7134_REMOTE_GPIO)
499 return -ENODEV;
500 if (disable_ir)
501 return -ENODEV;
502
503
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;
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;
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;
551
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;
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;
575
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;
584
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
682 break;
683 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
684 ir_codes = RC_MAP_ENCORE_ENLTV_FM53;
685 mask_keydown = 0x0040000;
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;
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;
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;
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;
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;
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;
729 }
730 if (NULL == ir_codes) {
731 printk("%s: Oops: IR config error [card=%d]\n",
732 dev->name, dev->board);
733 return -ENODEV;
734 }
735
736 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
737 rc = rc_allocate_device();
738 if (!ir || !rc) {
739 err = -ENOMEM;
740 goto err_out_free;
741 }
742
743 ir->dev = rc;
744 dev->remote = ir;
745
746
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;
752
753
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));
758
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;
764
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;
775 }
776 rc->dev.parent = &dev->pci->dev;
777 rc->map_name = ir_codes;
778 rc->driver_name = MODULE_NAME;
779
780 err = rc_register_device(rc);
781 if (err)
782 goto err_out_free;
783
784 return 0;
785
786err_out_free:
787 rc_free_device(rc);
788 dev->remote = NULL;
789 kfree(ir);
790 return err;
791}
792
793void saa7134_input_fini(struct saa7134_dev *dev)
794{
795 if (NULL == dev->remote)
796 return;
797
798 saa7134_ir_stop(dev);
799 rc_unregister_device(dev->remote->dev);
800 kfree(dev->remote);
801 dev->remote = NULL;
802}
803
804void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
805{
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,
812 };
813 int rc;
814
815 if (disable_ir) {
816 dprintk("IR has been disabled, not probing for i2c remote\n");
817 return;
818 }
819
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);
823
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;
836 }
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;
848
849
850
851
852 dev->init_data.polling_interval = 50;
853 info.addr = 0x30;
854
855
856
857
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;
903 }
904
905 if (dev->init_data.name)
906 info.platform_data = &dev->init_data;
907 i2c_new_device(&dev->i2c_adap, &info);
908}
909
910static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
911{
912 struct saa7134_card_ir *ir = dev->remote;
913 unsigned long timeout;
914 int space;
915
916
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);
921
922
923
924
925
926
927 if (!ir->active) {
928 timeout = jiffies + jiffies_to_msecs(15);
929 mod_timer(&ir->timer, timeout);
930 ir->active = true;
931 }
932
933 return 1;
934}
935