Merge branch 'sched/urgent' into sched/clock
[linux-2.6] / drivers / media / video / saa7134 / saa7134-input.c
1 /*
2  *
3  * handle saa7134 IR remotes via linux kernel input layer.
4  *
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.
9  *
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.
14  *
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
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/input.h>
26
27 #include "saa7134-reg.h"
28 #include "saa7134.h"
29
30 static unsigned int disable_ir;
31 module_param(disable_ir, int, 0444);
32 MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
33
34 static unsigned int ir_debug;
35 module_param(ir_debug, int, 0644);
36 MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
37
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)");
41
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);
46
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");
54
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");
59
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->c.name , ## arg)
64
65 /** rc5 functions */
66 static int saa7134_rc5_irq(struct saa7134_dev *dev);
67
68 /* -------------------- GPIO generic keycode builder -------------------- */
69
70 static int build_key(struct saa7134_dev *dev)
71 {
72         struct card_ir *ir = dev->remote;
73         u32 gpio, data;
74
75         /* here comes the additional handshake steps for some cards */
76         switch (dev->board) {
77         case SAA7134_BOARD_GOTVIEW_7135:
78                 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x80);
79                 saa_clearb(SAA7134_GPIO_GPSTATUS1, 0x80);
80                 break;
81         }
82         /* rising SAA7134_GPIO_GPRESCAN reads the status */
83         saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
84         saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
85
86         gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
87         if (ir->polling) {
88                 if (ir->last_gpio == gpio)
89                         return 0;
90                 ir->last_gpio = gpio;
91         }
92
93         data = ir_extract_bits(gpio, ir->mask_keycode);
94         dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
95                 gpio, ir->mask_keycode, data);
96
97         if (ir->polling) {
98                 if ((ir->mask_keydown  &&  (0 != (gpio & ir->mask_keydown))) ||
99                     (ir->mask_keyup    &&  (0 == (gpio & ir->mask_keyup)))) {
100                         ir_input_keydown(ir->dev, &ir->ir, data, data);
101                 } else {
102                         ir_input_nokey(ir->dev, &ir->ir);
103                 }
104         }
105         else {  /* IRQ driven mode - handle key press and release in one go */
106                 if ((ir->mask_keydown  &&  (0 != (gpio & ir->mask_keydown))) ||
107                     (ir->mask_keyup    &&  (0 == (gpio & ir->mask_keyup)))) {
108                         ir_input_keydown(ir->dev, &ir->ir, data, data);
109                         ir_input_nokey(ir->dev, &ir->ir);
110                 }
111         }
112
113         return 0;
114 }
115
116 /* --------------------- Chip specific I2C key builders ----------------- */
117
118 static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
119 {
120         unsigned char b;
121
122         /* poll IR chip */
123         if (1 != i2c_master_recv(&ir->c,&b,1)) {
124                 i2cdprintk("read error\n");
125                 return -EIO;
126         }
127
128         /* no button press */
129         if (b==0)
130                 return 0;
131
132         /* repeating */
133         if (b & 0x80)
134                 return 1;
135
136         *ir_key = b;
137         *ir_raw = b;
138         return 1;
139 }
140
141 static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
142 {
143         unsigned char buf[5], cod4, code3, code4;
144
145         /* poll IR chip */
146         if (5 != i2c_master_recv(&ir->c,buf,5))
147                 return -EIO;
148
149         cod4    = buf[4];
150         code4   = (cod4 >> 2);
151         code3   = buf[3];
152         if (code3 == 0)
153                 /* no key pressed */
154                 return 0;
155
156         /* return key */
157         *ir_key = code4;
158         *ir_raw = code4;
159         return 1;
160 }
161
162
163 static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
164 {
165         unsigned char data[12];
166         u32 gpio;
167
168         struct saa7134_dev *dev = ir->c.adapter->algo_data;
169
170         /* rising SAA7134_GPIO_GPRESCAN reads the status */
171         saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
172         saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
173
174         gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
175
176         if (0x400000 & ~gpio)
177                 return 0; /* No button press */
178
179         ir->c.addr = 0x5a >> 1;
180
181         if (12 != i2c_master_recv(&ir->c, data, 12)) {
182                 i2cdprintk("read error\n");
183                 return -EIO;
184         }
185         /* IR of this card normally decode signals NEC-standard from
186          * - Sven IHOO MT 5.1R remote. xxyye718
187          * - Sven DVD HD-10xx remote. xxyyf708
188          * - BBK ...
189          * - mayby others
190          * So, skip not our, if disable full codes mode.
191          */
192         if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir)
193                 return 0;
194
195         *ir_key = data[9];
196         *ir_raw = data[9];
197
198         return 1;
199 }
200
201 /* Common (grey or coloured) pinnacle PCTV remote handling
202  *
203  */
204 static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
205                             int parity_offset, int marker, int code_modulo)
206 {
207         unsigned char b[4];
208         unsigned int start = 0,parity = 0,code = 0;
209
210         /* poll IR chip */
211         if (4 != i2c_master_recv(&ir->c, b, 4)) {
212                 i2cdprintk("read error\n");
213                 return -EIO;
214         }
215
216         for (start = 0; start < ARRAY_SIZE(b); start++) {
217                 if (b[start] == marker) {
218                         code=b[(start+parity_offset + 1) % 4];
219                         parity=b[(start+parity_offset) % 4];
220                 }
221         }
222
223         /* Empty Request */
224         if (parity == 0)
225                 return 0;
226
227         /* Repeating... */
228         if (ir->old == parity)
229                 return 0;
230
231         ir->old = parity;
232
233         /* drop special codes when a key is held down a long time for the grey controller
234            In this case, the second bit of the code is asserted */
235         if (marker == 0xfe && (code & 0x40))
236                 return 0;
237
238         code %= code_modulo;
239
240         *ir_raw = code;
241         *ir_key = code;
242
243         i2cdprintk("Pinnacle PCTV key %02x\n", code);
244
245         return 1;
246 }
247
248 /* The grey pinnacle PCTV remote
249  *
250  *  There are one issue with this remote:
251  *   - I2c packet does not change when the same key is pressed quickly. The workaround
252  *     is to hold down each key for about half a second, so that another code is generated
253  *     in the i2c packet, and the function can distinguish key presses.
254  *
255  * Sylvain Pasche <sylvain.pasche@gmail.com>
256  */
257 static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
258 {
259
260         return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff);
261 }
262
263
264 /* The new pinnacle PCTV remote (with the colored buttons)
265  *
266  * Ricardo Cerqueira <v4l@cerqueira.org>
267  */
268 static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
269 {
270         /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
271          *
272          * this is the only value that results in 42 unique
273          * codes < 128
274          */
275
276         return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88);
277 }
278
279 void saa7134_input_irq(struct saa7134_dev *dev)
280 {
281         struct card_ir *ir = dev->remote;
282
283         if (!ir->polling && !ir->rc5_gpio) {
284                 build_key(dev);
285         } else if (ir->rc5_gpio) {
286                 saa7134_rc5_irq(dev);
287         }
288 }
289
290 static void saa7134_input_timer(unsigned long data)
291 {
292         struct saa7134_dev *dev = (struct saa7134_dev *)data;
293         struct card_ir *ir = dev->remote;
294
295         build_key(dev);
296         mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
297 }
298
299 void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
300 {
301         if (ir->polling) {
302                 setup_timer(&ir->timer, saa7134_input_timer,
303                             (unsigned long)dev);
304                 ir->timer.expires  = jiffies + HZ;
305                 add_timer(&ir->timer);
306         } else if (ir->rc5_gpio) {
307                 /* set timer_end for code completion */
308                 init_timer(&ir->timer_end);
309                 ir->timer_end.function = ir_rc5_timer_end;
310                 ir->timer_end.data = (unsigned long)ir;
311                 init_timer(&ir->timer_keyup);
312                 ir->timer_keyup.function = ir_rc5_timer_keyup;
313                 ir->timer_keyup.data = (unsigned long)ir;
314                 ir->shift_by = 2;
315                 ir->start = 0x2;
316                 ir->addr = 0x17;
317                 ir->rc5_key_timeout = ir_rc5_key_timeout;
318                 ir->rc5_remote_gap = ir_rc5_remote_gap;
319         }
320 }
321
322 void saa7134_ir_stop(struct saa7134_dev *dev)
323 {
324         if (dev->remote->polling)
325                 del_timer_sync(&dev->remote->timer);
326 }
327
328 int saa7134_input_init1(struct saa7134_dev *dev)
329 {
330         struct card_ir *ir;
331         struct input_dev *input_dev;
332         IR_KEYTAB_TYPE *ir_codes = NULL;
333         u32 mask_keycode = 0;
334         u32 mask_keydown = 0;
335         u32 mask_keyup   = 0;
336         int polling      = 0;
337         int rc5_gpio     = 0;
338         int ir_type      = IR_TYPE_OTHER;
339         int err;
340
341         if (dev->has_remote != SAA7134_REMOTE_GPIO)
342                 return -ENODEV;
343         if (disable_ir)
344                 return -ENODEV;
345
346         /* detect & configure */
347         switch (dev->board) {
348         case SAA7134_BOARD_FLYVIDEO2000:
349         case SAA7134_BOARD_FLYVIDEO3000:
350         case SAA7134_BOARD_FLYTVPLATINUM_FM:
351         case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
352                 ir_codes     = ir_codes_flyvideo;
353                 mask_keycode = 0xEC00000;
354                 mask_keydown = 0x0040000;
355                 break;
356         case SAA7134_BOARD_CINERGY400:
357         case SAA7134_BOARD_CINERGY600:
358         case SAA7134_BOARD_CINERGY600_MK3:
359                 ir_codes     = ir_codes_cinergy;
360                 mask_keycode = 0x00003f;
361                 mask_keyup   = 0x040000;
362                 break;
363         case SAA7134_BOARD_ECS_TVP3XP:
364         case SAA7134_BOARD_ECS_TVP3XP_4CB5:
365                 ir_codes     = ir_codes_eztv;
366                 mask_keycode = 0x00017c;
367                 mask_keyup   = 0x000002;
368                 polling      = 50; // ms
369                 break;
370         case SAA7134_BOARD_KWORLD_XPERT:
371         case SAA7134_BOARD_AVACSSMARTTV:
372                 ir_codes     = ir_codes_pixelview;
373                 mask_keycode = 0x00001F;
374                 mask_keyup   = 0x000020;
375                 polling      = 50; // ms
376                 break;
377         case SAA7134_BOARD_MD2819:
378         case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
379         case SAA7134_BOARD_AVERMEDIA_305:
380         case SAA7134_BOARD_AVERMEDIA_307:
381         case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
382         case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
383         case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
384         case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
385         case SAA7134_BOARD_AVERMEDIA_M102:
386                 ir_codes     = ir_codes_avermedia;
387                 mask_keycode = 0x0007C8;
388                 mask_keydown = 0x000010;
389                 polling      = 50; // ms
390                 /* Set GPIO pin2 to high to enable the IR controller */
391                 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
392                 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
393                 break;
394         case SAA7134_BOARD_AVERMEDIA_777:
395         case SAA7134_BOARD_AVERMEDIA_A16AR:
396                 ir_codes     = ir_codes_avermedia;
397                 mask_keycode = 0x02F200;
398                 mask_keydown = 0x000400;
399                 polling      = 50; // ms
400                 /* Without this we won't receive key up events */
401                 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
402                 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
403                 break;
404         case SAA7134_BOARD_AVERMEDIA_A16D:
405                 ir_codes     = ir_codes_avermedia_a16d;
406                 mask_keycode = 0x02F200;
407                 mask_keydown = 0x000400;
408                 polling      = 50; /* ms */
409                 /* Without this we won't receive key up events */
410                 saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
411                 saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
412                 break;
413         case SAA7134_BOARD_KWORLD_TERMINATOR:
414                 ir_codes     = ir_codes_pixelview;
415                 mask_keycode = 0x00001f;
416                 mask_keyup   = 0x000060;
417                 polling      = 50; // ms
418                 break;
419         case SAA7134_BOARD_MANLI_MTV001:
420         case SAA7134_BOARD_MANLI_MTV002:
421                 ir_codes     = ir_codes_manli;
422                 mask_keycode = 0x001f00;
423                 mask_keyup   = 0x004000;
424                 polling      = 50; /* ms */
425                 break;
426         case SAA7134_BOARD_BEHOLD_409FM:
427         case SAA7134_BOARD_BEHOLD_401:
428         case SAA7134_BOARD_BEHOLD_403:
429         case SAA7134_BOARD_BEHOLD_403FM:
430         case SAA7134_BOARD_BEHOLD_405:
431         case SAA7134_BOARD_BEHOLD_405FM:
432         case SAA7134_BOARD_BEHOLD_407:
433         case SAA7134_BOARD_BEHOLD_407FM:
434         case SAA7134_BOARD_BEHOLD_409:
435         case SAA7134_BOARD_BEHOLD_505FM:
436         case SAA7134_BOARD_BEHOLD_507_9FM:
437                 ir_codes     = ir_codes_manli;
438                 mask_keycode = 0x003f00;
439                 mask_keyup   = 0x004000;
440                 polling      = 50; /* ms */
441                 break;
442         case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
443                 ir_codes     = ir_codes_behold_columbus;
444                 mask_keycode = 0x003f00;
445                 mask_keyup   = 0x004000;
446                 polling      = 50; // ms
447                 break;
448         case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
449                 ir_codes     = ir_codes_pctv_sedna;
450                 mask_keycode = 0x001f00;
451                 mask_keyup   = 0x004000;
452                 polling      = 50; // ms
453                 break;
454         case SAA7134_BOARD_GOTVIEW_7135:
455                 ir_codes     = ir_codes_gotview7135;
456                 mask_keycode = 0x0003CC;
457                 mask_keydown = 0x000010;
458                 polling      = 5; /* ms */
459                 saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
460                 break;
461         case SAA7134_BOARD_VIDEOMATE_TV_PVR:
462         case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
463         case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
464                 ir_codes     = ir_codes_videomate_tv_pvr;
465                 mask_keycode = 0x00003F;
466                 mask_keyup   = 0x400000;
467                 polling      = 50; // ms
468                 break;
469         case SAA7134_BOARD_PROTEUS_2309:
470                 ir_codes     = ir_codes_proteus_2309;
471                 mask_keycode = 0x00007F;
472                 mask_keyup   = 0x000080;
473                 polling      = 50; // ms
474                 break;
475         case SAA7134_BOARD_VIDEOMATE_DVBT_300:
476         case SAA7134_BOARD_VIDEOMATE_DVBT_200:
477                 ir_codes     = ir_codes_videomate_tv_pvr;
478                 mask_keycode = 0x003F00;
479                 mask_keyup   = 0x040000;
480                 break;
481         case SAA7134_BOARD_FLYDVBS_LR300:
482         case SAA7134_BOARD_FLYDVBT_LR301:
483         case SAA7134_BOARD_FLYDVBTDUO:
484                 ir_codes     = ir_codes_flydvb;
485                 mask_keycode = 0x0001F00;
486                 mask_keydown = 0x0040000;
487                 break;
488         case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
489         case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
490        case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
491                 ir_codes     = ir_codes_asus_pc39;
492                 mask_keydown = 0x0040000;
493                 rc5_gpio = 1;
494                 break;
495         case SAA7134_BOARD_ENCORE_ENLTV:
496         case SAA7134_BOARD_ENCORE_ENLTV_FM:
497                 ir_codes     = ir_codes_encore_enltv;
498                 mask_keycode = 0x00007f;
499                 mask_keyup   = 0x040000;
500                 polling      = 50; // ms
501                 break;
502         case SAA7134_BOARD_10MOONSTVMASTER3:
503                 ir_codes     = ir_codes_encore_enltv;
504                 mask_keycode = 0x5f80000;
505                 mask_keyup   = 0x8000000;
506                 polling      = 50; //ms
507                 break;
508         case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
509                 ir_codes     = ir_codes_genius_tvgo_a11mce;
510                 mask_keycode = 0xff;
511                 mask_keydown = 0xf00000;
512                 polling = 50; /* ms */
513                 break;
514         }
515         if (NULL == ir_codes) {
516                 printk("%s: Oops: IR config error [card=%d]\n",
517                        dev->name, dev->board);
518                 return -ENODEV;
519         }
520
521         ir = kzalloc(sizeof(*ir), GFP_KERNEL);
522         input_dev = input_allocate_device();
523         if (!ir || !input_dev) {
524                 err = -ENOMEM;
525                 goto err_out_free;
526         }
527
528         ir->dev = input_dev;
529
530         /* init hardware-specific stuff */
531         ir->mask_keycode = mask_keycode;
532         ir->mask_keydown = mask_keydown;
533         ir->mask_keyup   = mask_keyup;
534         ir->polling      = polling;
535         ir->rc5_gpio     = rc5_gpio;
536
537         /* init input device */
538         snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
539                  saa7134_boards[dev->board].name);
540         snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
541                  pci_name(dev->pci));
542
543         ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
544         input_dev->name = ir->name;
545         input_dev->phys = ir->phys;
546         input_dev->id.bustype = BUS_PCI;
547         input_dev->id.version = 1;
548         if (dev->pci->subsystem_vendor) {
549                 input_dev->id.vendor  = dev->pci->subsystem_vendor;
550                 input_dev->id.product = dev->pci->subsystem_device;
551         } else {
552                 input_dev->id.vendor  = dev->pci->vendor;
553                 input_dev->id.product = dev->pci->device;
554         }
555         input_dev->dev.parent = &dev->pci->dev;
556
557         dev->remote = ir;
558         saa7134_ir_start(dev, ir);
559
560         err = input_register_device(ir->dev);
561         if (err)
562                 goto err_out_stop;
563
564         /* the remote isn't as bouncy as a keyboard */
565         ir->dev->rep[REP_DELAY] = repeat_delay;
566         ir->dev->rep[REP_PERIOD] = repeat_period;
567
568         return 0;
569
570  err_out_stop:
571         saa7134_ir_stop(dev);
572         dev->remote = NULL;
573  err_out_free:
574         input_free_device(input_dev);
575         kfree(ir);
576         return err;
577 }
578
579 void saa7134_input_fini(struct saa7134_dev *dev)
580 {
581         if (NULL == dev->remote)
582                 return;
583
584         saa7134_ir_stop(dev);
585         input_unregister_device(dev->remote->dev);
586         kfree(dev->remote);
587         dev->remote = NULL;
588 }
589
590 void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
591 {
592         if (disable_ir) {
593                 dprintk("Found supported i2c remote, but IR has been disabled\n");
594                 ir->get_key=NULL;
595                 return;
596         }
597
598         switch (dev->board) {
599         case SAA7134_BOARD_PINNACLE_PCTV_110i:
600         case SAA7134_BOARD_PINNACLE_PCTV_310i:
601                 snprintf(ir->c.name, sizeof(ir->c.name), "Pinnacle PCTV");
602                 if (pinnacle_remote == 0) {
603                         ir->get_key   = get_key_pinnacle_color;
604                         ir->ir_codes = ir_codes_pinnacle_color;
605                 } else {
606                         ir->get_key   = get_key_pinnacle_grey;
607                         ir->ir_codes = ir_codes_pinnacle_grey;
608                 }
609                 break;
610         case SAA7134_BOARD_UPMOST_PURPLE_TV:
611                 snprintf(ir->c.name, sizeof(ir->c.name), "Purple TV");
612                 ir->get_key   = get_key_purpletv;
613                 ir->ir_codes  = ir_codes_purpletv;
614                 break;
615         case SAA7134_BOARD_HAUPPAUGE_HVR1110:
616                 snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110");
617                 ir->get_key   = get_key_hvr1110;
618                 ir->ir_codes  = ir_codes_hauppauge_new;
619                 break;
620         case SAA7134_BOARD_BEHOLD_607_9FM:
621         case SAA7134_BOARD_BEHOLD_M6:
622         case SAA7134_BOARD_BEHOLD_M63:
623         case SAA7134_BOARD_BEHOLD_M6_EXTRA:
624         case SAA7134_BOARD_BEHOLD_H6:
625                 snprintf(ir->c.name, sizeof(ir->c.name), "BeholdTV");
626                 ir->get_key   = get_key_beholdm6xx;
627                 ir->ir_codes  = ir_codes_behold;
628                 break;
629         default:
630                 dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board);
631                 break;
632         }
633
634 }
635
636 static int saa7134_rc5_irq(struct saa7134_dev *dev)
637 {
638         struct card_ir *ir = dev->remote;
639         struct timeval tv;
640         u32 gap;
641         unsigned long current_jiffies, timeout;
642
643         /* get time of bit */
644         current_jiffies = jiffies;
645         do_gettimeofday(&tv);
646
647         /* avoid overflow with gap >1s */
648         if (tv.tv_sec - ir->base_time.tv_sec > 1) {
649                 gap = 200000;
650         } else {
651                 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
652                     tv.tv_usec - ir->base_time.tv_usec;
653         }
654
655         /* active code => add bit */
656         if (ir->active) {
657                 /* only if in the code (otherwise spurious IRQ or timer
658                    late) */
659                 if (ir->last_bit < 28) {
660                         ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
661                             ir_rc5_remote_gap;
662                         ir->code |= 1 << ir->last_bit;
663                 }
664                 /* starting new code */
665         } else {
666                 ir->active = 1;
667                 ir->code = 0;
668                 ir->base_time = tv;
669                 ir->last_bit = 0;
670
671                 timeout = current_jiffies + (500 + 30 * HZ) / 1000;
672                 mod_timer(&ir->timer_end, timeout);
673         }
674
675         return 1;
676 }
677
678 /* ----------------------------------------------------------------------
679  * Local variables:
680  * c-basic-offset: 8
681  * End:
682  */