aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorRicardo Cerqueira <v4l@cerqueira.org>2006-01-09 12:25:25 -0500
committerMauro Carvalho Chehab <mchehab@brturbo.com.br>2006-01-09 12:25:25 -0500
commit4abdfed5676e5ef7f2461bb76f5929068a9cc9cf (patch)
treeff4e3e80f57f788a9cf450966f137c44b58ff1b2 /drivers/media
parente0b2d7a89bb250fb0c9068c4481c9fd26c3fb227 (diff)
V4L/DVB (3161): ir-kbd-gpio is now part of bttv
- Merged ir-kbd-gpio into bttv as bttv-input, for consistency with other input modules Signed-off-by: Ricardo Cerqueira <v4l@cerqueira.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/video/Makefile5
-rw-r--r--drivers/media/video/bttv-cards.c3
-rw-r--r--drivers/media/video/bttv-driver.c13
-rw-r--r--drivers/media/video/bttv-gpio.c18
-rw-r--r--drivers/media/video/bttv-input.c (renamed from drivers/media/video/ir-kbd-gpio.c)254
-rw-r--r--drivers/media/video/bttv.h36
-rw-r--r--drivers/media/video/bttvp.h6
7 files changed, 136 insertions, 199 deletions
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 618a08ab940a..49aae8a54aa4 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -3,7 +3,8 @@
3# 3#
4 4
5bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \ 5bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \
6 bttv-risc.o bttv-vbi.o bttv-i2c.o bttv-gpio.o 6 bttv-risc.o bttv-vbi.o bttv-i2c.o bttv-gpio.o \
7 bttv-input.o
7zoran-objs := zr36120.o zr36120_i2c.o zr36120_mem.o 8zoran-objs := zr36120.o zr36120_i2c.o zr36120_mem.o
8zr36067-objs := zoran_procfs.o zoran_device.o \ 9zr36067-objs := zoran_procfs.o zoran_device.o \
9 zoran_driver.o zoran_card.o 10 zoran_driver.o zoran_card.o
@@ -12,7 +13,7 @@ tuner-objs := tuner-core.o tuner-simple.o mt20xx.o tda8290.o tea5767.o
12obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o v4l1-compat.o compat_ioctl32.o 13obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o v4l1-compat.o compat_ioctl32.o
13 14
14obj-$(CONFIG_VIDEO_BT848) += bttv.o msp3400.o tvaudio.o \ 15obj-$(CONFIG_VIDEO_BT848) += bttv.o msp3400.o tvaudio.o \
15 tda7432.o tda9875.o ir-kbd-i2c.o ir-kbd-gpio.o 16 tda7432.o tda9875.o ir-kbd-i2c.o
16obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o 17obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o
17 18
18obj-$(CONFIG_VIDEO_ZR36120) += zoran.o 19obj-$(CONFIG_VIDEO_ZR36120) += zoran.o
diff --git a/drivers/media/video/bttv-cards.c b/drivers/media/video/bttv-cards.c
index c94092351b79..440f635e020f 100644
--- a/drivers/media/video/bttv-cards.c
+++ b/drivers/media/video/bttv-cards.c
@@ -2139,7 +2139,6 @@ struct tvcard bttv_tvcards[] = {
2139 .has_remote = 1, 2139 .has_remote = 1,
2140 .gpiomask = 0x1b, 2140 .gpiomask = 0x1b,
2141 .no_gpioirq = 1, 2141 .no_gpioirq = 1,
2142 .any_irq = 1,
2143 }, 2142 },
2144 [BTTV_BOARD_PV143] = { 2143 [BTTV_BOARD_PV143] = {
2145 /* Jorge Boncompte - DTI2 <jorge@dti2.net> */ 2144 /* Jorge Boncompte - DTI2 <jorge@dti2.net> */
@@ -3412,8 +3411,6 @@ void __devinit bttv_init_card2(struct bttv *btv)
3412 btv->has_remote=1; 3411 btv->has_remote=1;
3413 if (!bttv_tvcards[btv->c.type].no_gpioirq) 3412 if (!bttv_tvcards[btv->c.type].no_gpioirq)
3414 btv->gpioirq=1; 3413 btv->gpioirq=1;
3415 if (bttv_tvcards[btv->c.type].any_irq)
3416 btv->any_irq = 1;
3417 if (bttv_tvcards[btv->c.type].audio_hook) 3414 if (bttv_tvcards[btv->c.type].audio_hook)
3418 btv->audio_hook=bttv_tvcards[btv->c.type].audio_hook; 3415 btv->audio_hook=bttv_tvcards[btv->c.type].audio_hook;
3419 3416
diff --git a/drivers/media/video/bttv-driver.c b/drivers/media/video/bttv-driver.c
index 47347674a5e0..8bee7d5796dd 100644
--- a/drivers/media/video/bttv-driver.c
+++ b/drivers/media/video/bttv-driver.c
@@ -3702,8 +3702,8 @@ static irqreturn_t bttv_irq(int irq, void *dev_id, struct pt_regs * regs)
3702 3702
3703 btv=(struct bttv *)dev_id; 3703 btv=(struct bttv *)dev_id;
3704 3704
3705 if (btv->any_irq) 3705 if (btv->custom_irq)
3706 handled = bttv_any_irq(&btv->c); 3706 handled = btv->custom_irq(btv);
3707 3707
3708 count=0; 3708 count=0;
3709 while (1) { 3709 while (1) {
@@ -3739,9 +3739,9 @@ static irqreturn_t bttv_irq(int irq, void *dev_id, struct pt_regs * regs)
3739 if (astat&BT848_INT_VSYNC) 3739 if (astat&BT848_INT_VSYNC)
3740 btv->field_count++; 3740 btv->field_count++;
3741 3741
3742 if (astat & BT848_INT_GPINT) { 3742 if ((astat & BT848_INT_GPINT) && btv->remote) {
3743 wake_up(&btv->gpioq); 3743 wake_up(&btv->gpioq);
3744 bttv_gpio_irq(&btv->c); 3744 bttv_input_irq(btv);
3745 } 3745 }
3746 3746
3747 if (astat & BT848_INT_I2CDONE) { 3747 if (astat & BT848_INT_I2CDONE) {
@@ -4070,6 +4070,8 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4070 if (bttv_tvcards[btv->c.type].has_dvb) 4070 if (bttv_tvcards[btv->c.type].has_dvb)
4071 bttv_sub_add_device(&btv->c, "dvb"); 4071 bttv_sub_add_device(&btv->c, "dvb");
4072 4072
4073 bttv_input_init(btv);
4074
4073 /* everything is fine */ 4075 /* everything is fine */
4074 bttv_num++; 4076 bttv_num++;
4075 return 0; 4077 return 0;
@@ -4104,7 +4106,8 @@ static void __devexit bttv_remove(struct pci_dev *pci_dev)
4104 /* tell gpio modules we are leaving ... */ 4106 /* tell gpio modules we are leaving ... */
4105 btv->shutdown=1; 4107 btv->shutdown=1;
4106 wake_up(&btv->gpioq); 4108 wake_up(&btv->gpioq);
4107 bttv_sub_del_devices(&btv->c); 4109 bttv_input_fini(btv);
4110 //bttv_sub_del_devices(&btv->c);
4108 4111
4109 /* unregister i2c_bus + input */ 4112 /* unregister i2c_bus + input */
4110 fini_bttv_i2c(btv); 4113 fini_bttv_i2c(btv);
diff --git a/drivers/media/video/bttv-gpio.c b/drivers/media/video/bttv-gpio.c
index 616a5b7e510c..575ce8b8e714 100644
--- a/drivers/media/video/bttv-gpio.c
+++ b/drivers/media/video/bttv-gpio.c
@@ -113,24 +113,6 @@ void bttv_gpio_irq(struct bttv_core *core)
113 } 113 }
114} 114}
115 115
116int bttv_any_irq(struct bttv_core *core)
117{
118 struct bttv_sub_driver *drv;
119 struct bttv_sub_device *dev;
120 struct list_head *item;
121 int handled = 0;
122
123 list_for_each(item,&core->subs) {
124 dev = list_entry(item,struct bttv_sub_device,list);
125 drv = to_bttv_sub_drv(dev->dev.driver);
126 if (drv && drv->any_irq) {
127 if (drv->any_irq(dev))
128 handled = 1;
129 }
130 }
131 return handled;
132}
133
134/* ----------------------------------------------------------------------- */ 116/* ----------------------------------------------------------------------- */
135/* external: sub-driver register/unregister */ 117/* external: sub-driver register/unregister */
136 118
diff --git a/drivers/media/video/ir-kbd-gpio.c b/drivers/media/video/bttv-input.c
index 556da9ff128f..5027e10537cf 100644
--- a/drivers/media/video/ir-kbd-gpio.c
+++ b/drivers/media/video/bttv-input.c
@@ -24,10 +24,9 @@
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/input.h> 26#include <linux/input.h>
27#include <linux/pci.h>
28 27
29#include "bttv.h" 28#include "bttv.h"
30#include <media/ir-common.h> 29#include "bttvp.h"
31 30
32/* ---------------------------------------------------------------------- */ 31/* ---------------------------------------------------------------------- */
33 32
@@ -155,9 +154,6 @@ static IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = {
155 154
156/* ---------------------------------------------------------------------- */ 155/* ---------------------------------------------------------------------- */
157 156
158/* Ricardo Cerqueira <v4l@cerqueira.org> */
159/* Weird matching, since the remote has "uncommon" keys */
160
161static IR_KEYTAB_TYPE ir_codes_conceptronic[IR_KEYTAB_SIZE] = { 157static IR_KEYTAB_TYPE ir_codes_conceptronic[IR_KEYTAB_SIZE] = {
162 158
163 [ 30 ] = KEY_POWER, // power 159 [ 30 ] = KEY_POWER, // power
@@ -278,34 +274,6 @@ static IR_KEYTAB_TYPE ir_codes_nebula[IR_KEYTAB_SIZE] = {
278 [0x36] = KEY_PC 274 [0x36] = KEY_PC
279}; 275};
280 276
281struct IR {
282 struct bttv_sub_device *sub;
283 struct input_dev *input;
284 struct ir_input_state ir;
285 char name[32];
286 char phys[32];
287
288 /* Usual gpio signalling */
289
290 u32 mask_keycode;
291 u32 mask_keydown;
292 u32 mask_keyup;
293 u32 polling;
294 u32 last_gpio;
295 struct work_struct work;
296 struct timer_list timer;
297
298 /* RC5 gpio */
299 u32 rc5_gpio;
300 struct timer_list timer_end; /* timer_end for code completion */
301 struct timer_list timer_keyup; /* timer_end for key release */
302 u32 last_rc5; /* last good rc5 code */
303 u32 last_bit; /* last raw bit seen */
304 u32 code; /* raw code under construction */
305 struct timeval base_time; /* time of last seen code */
306 int active; /* building raw code */
307};
308
309static int debug; 277static int debug;
310module_param(debug, int, 0644); /* debug level (0,1,2) */ 278module_param(debug, int, 0644); /* debug level (0,1,2) */
311static int repeat_delay = 500; 279static int repeat_delay = 500;
@@ -313,31 +281,17 @@ module_param(repeat_delay, int, 0644);
313static int repeat_period = 33; 281static int repeat_period = 33;
314module_param(repeat_period, int, 0644); 282module_param(repeat_period, int, 0644);
315 283
316#define DEVNAME "ir-kbd-gpio" 284#define DEVNAME "bttv-input"
317#define dprintk(fmt, arg...) if (debug) \
318 printk(KERN_DEBUG DEVNAME ": " fmt , ## arg)
319
320static void ir_irq(struct bttv_sub_device *sub);
321static int ir_probe(struct device *dev);
322static int ir_remove(struct device *dev);
323
324static struct bttv_sub_driver driver = {
325 .drv = {
326 .name = DEVNAME,
327 .probe = ir_probe,
328 .remove = ir_remove,
329 },
330 .gpio_irq = ir_irq,
331};
332 285
333/* ---------------------------------------------------------------------- */ 286/* ---------------------------------------------------------------------- */
334 287
335static void ir_handle_key(struct IR *ir) 288static void ir_handle_key(struct bttv *btv)
336{ 289{
290 struct bttv_ir *ir = btv->remote;
337 u32 gpio,data; 291 u32 gpio,data;
338 292
339 /* read gpio value */ 293 /* read gpio value */
340 gpio = bttv_gpio_read(ir->sub->core); 294 gpio = bttv_gpio_read(&btv->c);
341 if (ir->polling) { 295 if (ir->polling) {
342 if (ir->last_gpio == gpio) 296 if (ir->last_gpio == gpio)
343 return; 297 return;
@@ -346,56 +300,36 @@ static void ir_handle_key(struct IR *ir)
346 300
347 /* extract data */ 301 /* extract data */
348 data = ir_extract_bits(gpio, ir->mask_keycode); 302 data = ir_extract_bits(gpio, ir->mask_keycode);
349 dprintk(DEVNAME ": irq gpio=0x%x code=%d | %s%s%s\n", 303 dprintk(KERN_INFO DEVNAME ": irq gpio=0x%x code=%d | %s%s%s\n",
350 gpio, data, 304 gpio, data,
351 ir->polling ? "poll" : "irq", 305 ir->polling ? "poll" : "irq",
352 (gpio & ir->mask_keydown) ? " down" : "", 306 (gpio & ir->mask_keydown) ? " down" : "",
353 (gpio & ir->mask_keyup) ? " up" : ""); 307 (gpio & ir->mask_keyup) ? " up" : "");
354 308
355 if (ir->mask_keydown) { 309 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
356 /* bit set on keydown */ 310 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
357 if (gpio & ir->mask_keydown) { 311 ir_input_keydown(ir->dev,&ir->ir,data,data);
358 ir_input_keydown(ir->input, &ir->ir, data, data);
359 } else {
360 ir_input_nokey(ir->input, &ir->ir);
361 }
362
363 } else if (ir->mask_keyup) {
364 /* bit cleared on keydown */
365 if (0 == (gpio & ir->mask_keyup)) {
366 ir_input_keydown(ir->input, &ir->ir, data, data);
367 } else {
368 ir_input_nokey(ir->input, &ir->ir);
369 }
370
371 } else { 312 } else {
372 /* can't disturgissh keydown/up :-/ */ 313 ir_input_nokey(ir->dev,&ir->ir);
373 ir_input_keydown(ir->input, &ir->ir, data, data);
374 ir_input_nokey(ir->input, &ir->ir);
375 } 314 }
376}
377 315
378static void ir_irq(struct bttv_sub_device *sub)
379{
380 struct IR *ir = dev_get_drvdata(&sub->dev);
381
382 if (!ir->polling)
383 ir_handle_key(ir);
384} 316}
385 317
386static void ir_timer(unsigned long data) 318void bttv_input_irq(struct bttv *btv)
387{ 319{
388 struct IR *ir = (struct IR*)data; 320 struct bttv_ir *ir = btv->remote;
389 321
390 schedule_work(&ir->work); 322 if (!ir->polling)
323 ir_handle_key(btv);
391} 324}
392 325
393static void ir_work(void *data) 326static void bttv_input_timer(unsigned long data)
394{ 327{
395 struct IR *ir = data; 328 struct bttv *btv = (struct bttv*)data;
329 struct bttv_ir *ir = btv->remote;
396 unsigned long timeout; 330 unsigned long timeout;
397 331
398 ir_handle_key(ir); 332 ir_handle_key(btv);
399 timeout = jiffies + (ir->polling * HZ / 1000); 333 timeout = jiffies + (ir->polling * HZ / 1000);
400 mod_timer(&ir->timer, timeout); 334 mod_timer(&ir->timer, timeout);
401} 335}
@@ -434,26 +368,26 @@ static u32 rc5_decode(unsigned int code)
434 rc5 |= 1; 368 rc5 |= 1;
435 break; 369 break;
436 case 3: 370 case 3:
437 dprintk("bad code: %x\n", org_code); 371 dprintk(KERN_WARNING "bad code: %x\n", org_code);
438 return 0; 372 return 0;
439 } 373 }
440 } 374 }
441 dprintk("code=%x, rc5=%x, start=%x, toggle=%x, address=%x, " 375 dprintk(KERN_WARNING "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
442 "instr=%x\n", rc5, org_code, RC5_START(rc5), 376 "instr=%x\n", rc5, org_code, RC5_START(rc5),
443 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5)); 377 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
444 return rc5; 378 return rc5;
445} 379}
446 380
447static int ir_rc5_irq(struct bttv_sub_device *sub) 381static int bttv_rc5_irq(struct bttv *btv)
448{ 382{
449 struct IR *ir = dev_get_drvdata(&sub->dev); 383 struct bttv_ir *ir = btv->remote;
450 struct timeval tv; 384 struct timeval tv;
451 u32 gpio; 385 u32 gpio;
452 u32 gap; 386 u32 gap;
453 unsigned long current_jiffies, timeout; 387 unsigned long current_jiffies, timeout;
454 388
455 /* read gpio port */ 389 /* read gpio port */
456 gpio = bttv_gpio_read(ir->sub->core); 390 gpio = bttv_gpio_read(&btv->c);
457 391
458 /* remote IRQ? */ 392 /* remote IRQ? */
459 if (!(gpio & 0x20)) 393 if (!(gpio & 0x20))
@@ -492,14 +426,15 @@ static int ir_rc5_irq(struct bttv_sub_device *sub)
492 } 426 }
493 427
494 /* toggle GPIO pin 4 to reset the irq */ 428 /* toggle GPIO pin 4 to reset the irq */
495 bttv_gpio_write(ir->sub->core, gpio & ~(1 << 4)); 429 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
496 bttv_gpio_write(ir->sub->core, gpio | (1 << 4)); 430 bttv_gpio_write(&btv->c, gpio | (1 << 4));
497 return 1; 431 return 1;
498} 432}
499 433
500static void ir_rc5_timer_end(unsigned long data) 434
435static void bttv_rc5_timer_end(unsigned long data)
501{ 436{
502 struct IR *ir = (struct IR *)data; 437 struct bttv_ir *ir = (struct bttv_ir *)data;
503 struct timeval tv; 438 struct timeval tv;
504 unsigned long current_jiffies, timeout; 439 unsigned long current_jiffies, timeout;
505 u32 gap; 440 u32 gap;
@@ -518,20 +453,20 @@ static void ir_rc5_timer_end(unsigned long data)
518 453
519 /* Allow some timmer jitter (RC5 is ~24ms anyway so this is ok) */ 454 /* Allow some timmer jitter (RC5 is ~24ms anyway so this is ok) */
520 if (gap < 28000) { 455 if (gap < 28000) {
521 dprintk("spurious timer_end\n"); 456 dprintk(KERN_WARNING "spurious timer_end\n");
522 return; 457 return;
523 } 458 }
524 459
525 ir->active = 0; 460 ir->active = 0;
526 if (ir->last_bit < 20) { 461 if (ir->last_bit < 20) {
527 /* ignore spurious codes (caused by light/other remotes) */ 462 /* ignore spurious codes (caused by light/other remotes) */
528 dprintk("short code: %x\n", ir->code); 463 dprintk(KERN_WARNING "short code: %x\n", ir->code);
529 } else { 464 } else {
530 u32 rc5 = rc5_decode(ir->code); 465 u32 rc5 = rc5_decode(ir->code);
531 466
532 /* two start bits? */ 467 /* two start bits? */
533 if (RC5_START(rc5) != 3) { 468 if (RC5_START(rc5) != 3) {
534 dprintk("rc5 start bits invalid: %u\n", RC5_START(rc5)); 469 dprintk(KERN_WARNING "rc5 start bits invalid: %u\n", RC5_START(rc5));
535 470
536 /* right address? */ 471 /* right address? */
537 } else if (RC5_ADDR(rc5) == 0x0) { 472 } else if (RC5_ADDR(rc5) == 0x0) {
@@ -541,10 +476,10 @@ static void ir_rc5_timer_end(unsigned long data)
541 /* Good code, decide if repeat/repress */ 476 /* Good code, decide if repeat/repress */
542 if (toggle != RC5_TOGGLE(ir->last_rc5) || 477 if (toggle != RC5_TOGGLE(ir->last_rc5) ||
543 instr != RC5_INSTR(ir->last_rc5)) { 478 instr != RC5_INSTR(ir->last_rc5)) {
544 dprintk("instruction %x, toggle %x\n", instr, 479 dprintk(KERN_WARNING "instruction %x, toggle %x\n", instr,
545 toggle); 480 toggle);
546 ir_input_nokey(ir->input, &ir->ir); 481 ir_input_nokey(ir->dev, &ir->ir);
547 ir_input_keydown(ir->input, &ir->ir, instr, 482 ir_input_keydown(ir->dev, &ir->ir, instr,
548 instr); 483 instr);
549 } 484 }
550 485
@@ -559,34 +494,37 @@ static void ir_rc5_timer_end(unsigned long data)
559 } 494 }
560} 495}
561 496
562static void ir_rc5_timer_keyup(unsigned long data) 497static void bttv_rc5_timer_keyup(unsigned long data)
563{ 498{
564 struct IR *ir = (struct IR *)data; 499 struct bttv_ir *ir = (struct bttv_ir *)data;
565 500
566 dprintk("key released\n"); 501 dprintk(KERN_DEBUG "key released\n");
567 ir_input_nokey(ir->input, &ir->ir); 502 ir_input_nokey(ir->dev, &ir->ir);
568} 503}
569 504
570/* ---------------------------------------------------------------------- */ 505/* ---------------------------------------------------------------------- */
571 506
572static int ir_probe(struct device *dev) 507int bttv_input_init(struct bttv *btv)
573{ 508{
574 struct bttv_sub_device *sub = to_bttv_sub_dev(dev); 509 struct bttv_ir *ir;
575 struct IR *ir;
576 struct input_dev *input_dev;
577 IR_KEYTAB_TYPE *ir_codes = NULL; 510 IR_KEYTAB_TYPE *ir_codes = NULL;
511 struct input_dev *input_dev;
578 int ir_type = IR_TYPE_OTHER; 512 int ir_type = IR_TYPE_OTHER;
579 513
580 ir = kzalloc(sizeof(*ir), GFP_KERNEL); 514 if (!btv->has_remote)
515 return -ENODEV;
516
517 ir = kzalloc(sizeof(*ir),GFP_KERNEL);
581 input_dev = input_allocate_device(); 518 input_dev = input_allocate_device();
582 if (!ir || !input_dev) { 519 if (!ir || !input_dev) {
583 kfree(ir); 520 kfree(ir);
584 input_free_device(input_dev); 521 input_free_device(input_dev);
585 return -ENOMEM; 522 return -ENOMEM;
586 } 523 }
524 memset(ir,0,sizeof(*ir));
587 525
588 /* detect & configure */ 526 /* detect & configure */
589 switch (sub->core->type) { 527 switch (btv->c.type) {
590 case BTTV_BOARD_AVERMEDIA: 528 case BTTV_BOARD_AVERMEDIA:
591 case BTTV_BOARD_AVPHONE98: 529 case BTTV_BOARD_AVPHONE98:
592 case BTTV_BOARD_AVERMEDIA98: 530 case BTTV_BOARD_AVERMEDIA98:
@@ -642,12 +580,12 @@ static int ir_probe(struct device *dev)
642 break; 580 break;
643 case BTTV_BOARD_NEBULA_DIGITV: 581 case BTTV_BOARD_NEBULA_DIGITV:
644 ir_codes = ir_codes_nebula; 582 ir_codes = ir_codes_nebula;
645 driver.any_irq = ir_rc5_irq; 583 btv->custom_irq = bttv_rc5_irq;
646 driver.gpio_irq = NULL;
647 ir->rc5_gpio = 1; 584 ir->rc5_gpio = 1;
648 break; 585 break;
649 } 586 }
650 if (NULL == ir_codes) { 587 if (NULL == ir_codes) {
588 dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n",btv->c.type);
651 kfree(ir); 589 kfree(ir);
652 input_free_device(input_dev); 590 input_free_device(input_dev);
653 return -ENODEV; 591 return -ENODEV;
@@ -656,108 +594,92 @@ static int ir_probe(struct device *dev)
656 if (ir->rc5_gpio) { 594 if (ir->rc5_gpio) {
657 u32 gpio; 595 u32 gpio;
658 /* enable remote irq */ 596 /* enable remote irq */
659 bttv_gpio_inout(sub->core, (1 << 4), 1 << 4); 597 bttv_gpio_inout(&btv->c, (1 << 4), 1 << 4);
660 gpio = bttv_gpio_read(sub->core); 598 gpio = bttv_gpio_read(&btv->c);
661 bttv_gpio_write(sub->core, gpio & ~(1 << 4)); 599 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
662 bttv_gpio_write(sub->core, gpio | (1 << 4)); 600 bttv_gpio_write(&btv->c, gpio | (1 << 4));
663 } else { 601 } else {
664 /* init hardware-specific stuff */ 602 /* init hardware-specific stuff */
665 bttv_gpio_inout(sub->core, ir->mask_keycode | ir->mask_keydown, 0); 603 bttv_gpio_inout(&btv->c, ir->mask_keycode | ir->mask_keydown, 0);
666 } 604 }
667 605
668 /* init input device */ 606 /* init input device */
607 ir->dev = input_dev;
608
669 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)", 609 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)",
670 sub->core->type); 610 btv->c.type);
671 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", 611 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
672 pci_name(sub->core->pci)); 612 pci_name(btv->c.pci));
673 613
674 ir->input = input_dev;
675 ir->sub = sub;
676 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes); 614 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
677 input_dev->name = ir->name; 615 input_dev->name = ir->name;
678 input_dev->phys = ir->phys; 616 input_dev->phys = ir->phys;
679 input_dev->id.bustype = BUS_PCI; 617 input_dev->id.bustype = BUS_PCI;
680 input_dev->id.version = 1; 618 input_dev->id.version = 1;
681 if (sub->core->pci->subsystem_vendor) { 619 if (btv->c.pci->subsystem_vendor) {
682 input_dev->id.vendor = sub->core->pci->subsystem_vendor; 620 input_dev->id.vendor = btv->c.pci->subsystem_vendor;
683 input_dev->id.product = sub->core->pci->subsystem_device; 621 input_dev->id.product = btv->c.pci->subsystem_device;
684 } else { 622 } else {
685 input_dev->id.vendor = sub->core->pci->vendor; 623 input_dev->id.vendor = btv->c.pci->vendor;
686 input_dev->id.product = sub->core->pci->device; 624 input_dev->id.product = btv->c.pci->device;
687 } 625 }
688 input_dev->cdev.dev = &sub->core->pci->dev; 626 input_dev->cdev.dev = &btv->c.pci->dev;
689 627
628 btv->remote = ir;
690 if (ir->polling) { 629 if (ir->polling) {
691 INIT_WORK(&ir->work, ir_work, ir);
692 init_timer(&ir->timer); 630 init_timer(&ir->timer);
693 ir->timer.function = ir_timer; 631 ir->timer.function = bttv_input_timer;
694 ir->timer.data = (unsigned long)ir; 632 ir->timer.data = (unsigned long)btv;
695 schedule_work(&ir->work); 633 ir->timer.expires = jiffies + HZ;
634 add_timer(&ir->timer);
696 } else if (ir->rc5_gpio) { 635 } else if (ir->rc5_gpio) {
697 /* set timer_end for code completion */ 636 /* set timer_end for code completion */
698 init_timer(&ir->timer_end); 637 init_timer(&ir->timer_end);
699 ir->timer_end.function = ir_rc5_timer_end; 638 ir->timer_end.function = bttv_rc5_timer_end;
700 ir->timer_end.data = (unsigned long)ir; 639 ir->timer_end.data = (unsigned long)ir;
701 640
702 init_timer(&ir->timer_keyup); 641 init_timer(&ir->timer_keyup);
703 ir->timer_keyup.function = ir_rc5_timer_keyup; 642 ir->timer_keyup.function = bttv_rc5_timer_keyup;
704 ir->timer_keyup.data = (unsigned long)ir; 643 ir->timer_keyup.data = (unsigned long)ir;
705 } 644 }
706 645
707 /* all done */ 646 /* all done */
708 dev_set_drvdata(dev, ir); 647 input_register_device(btv->remote->dev);
709 input_register_device(ir->input); 648 printk(DEVNAME ": %s detected at %s\n",ir->dev->name,ir->dev->phys);
710 649
711 /* the remote isn't as bouncy as a keyboard */ 650 /* the remote isn't as bouncy as a keyboard */
712 ir->input->rep[REP_DELAY] = repeat_delay; 651 ir->dev->rep[REP_DELAY] = repeat_delay;
713 ir->input->rep[REP_PERIOD] = repeat_period; 652 ir->dev->rep[REP_PERIOD] = repeat_period;
714 653
715 return 0; 654 return 0;
716} 655}
717 656
718static int ir_remove(struct device *dev) 657void bttv_input_fini(struct bttv *btv)
719{ 658{
720 struct IR *ir = dev_get_drvdata(dev); 659 if (btv->remote == NULL)
660 return;
721 661
722 if (ir->polling) { 662 if (btv->remote->polling) {
723 del_timer(&ir->timer); 663 del_timer_sync(&btv->remote->timer);
724 flush_scheduled_work(); 664 flush_scheduled_work();
725 } 665 }
726 666
727 if (ir->rc5_gpio) { 667
668 if (btv->remote->rc5_gpio) {
728 u32 gpio; 669 u32 gpio;
729 670
730 del_timer(&ir->timer_end); 671 del_timer(&btv->remote->timer_end);
731 flush_scheduled_work(); 672 flush_scheduled_work();
732 673
733 gpio = bttv_gpio_read(ir->sub->core); 674 gpio = bttv_gpio_read(&btv->c);
734 bttv_gpio_write(ir->sub->core, gpio & ~(1 << 4)); 675 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
735 } 676 }
736 677
737 input_unregister_device(ir->input); 678 input_unregister_device(btv->remote->dev);
738 kfree(ir); 679 kfree(btv->remote);
739 return 0; 680 btv->remote = NULL;
740} 681}
741 682
742/* ---------------------------------------------------------------------- */
743
744MODULE_AUTHOR("Gerd Knorr, Pavel Machek");
745MODULE_DESCRIPTION("input driver for bt8x8 gpio IR remote controls");
746MODULE_LICENSE("GPL");
747
748static int ir_init(void)
749{
750 return bttv_sub_register(&driver, "remote");
751}
752
753static void ir_fini(void)
754{
755 bttv_sub_unregister(&driver);
756}
757
758module_init(ir_init);
759module_exit(ir_fini);
760
761 683
762/* 684/*
763 * Local variables: 685 * Local variables:
diff --git a/drivers/media/video/bttv.h b/drivers/media/video/bttv.h
index a5f172fe9f98..9feaa6bab207 100644
--- a/drivers/media/video/bttv.h
+++ b/drivers/media/video/bttv.h
@@ -16,6 +16,8 @@
16 16
17#include <linux/videodev.h> 17#include <linux/videodev.h>
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <media/ir-common.h>
20#include <media/ir-kbd-i2c.h>
19 21
20/* ---------------------------------------------------------- */ 22/* ---------------------------------------------------------- */
21/* exported by bttv-cards.c */ 23/* exported by bttv-cards.c */
@@ -211,6 +213,34 @@ struct bttv_core {
211 213
212struct bttv; 214struct bttv;
213 215
216
217struct bttv_ir {
218 struct input_dev *dev;
219 struct ir_input_state ir;
220 char name[32];
221 char phys[32];
222
223 /* Usual gpio signalling */
224
225 u32 mask_keycode;
226 u32 mask_keydown;
227 u32 mask_keyup;
228 u32 polling;
229 u32 last_gpio;
230 struct work_struct work;
231 struct timer_list timer;
232
233 /* RC5 gpio */
234 u32 rc5_gpio;
235 struct timer_list timer_end; /* timer_end for code completion */
236 struct timer_list timer_keyup; /* timer_end for key release */
237 u32 last_rc5; /* last good rc5 code */
238 u32 last_bit; /* last raw bit seen */
239 u32 code; /* raw code under construction */
240 struct timeval base_time; /* time of last seen code */
241 int active; /* building raw code */
242};
243
214struct tvcard 244struct tvcard
215{ 245{
216 char *name; 246 char *name;
@@ -236,7 +266,6 @@ struct tvcard
236 unsigned int has_dvb:1; 266 unsigned int has_dvb:1;
237 unsigned int has_remote:1; 267 unsigned int has_remote:1;
238 unsigned int no_gpioirq:1; 268 unsigned int no_gpioirq:1;
239 unsigned int any_irq:1;
240 269
241 /* other settings */ 270 /* other settings */
242 unsigned int pll; 271 unsigned int pll;
@@ -336,7 +365,6 @@ struct bttv_sub_driver {
336 struct device_driver drv; 365 struct device_driver drv;
337 char wanted[BUS_ID_SIZE]; 366 char wanted[BUS_ID_SIZE];
338 void (*gpio_irq)(struct bttv_sub_device *sub); 367 void (*gpio_irq)(struct bttv_sub_device *sub);
339 int (*any_irq)(struct bttv_sub_device *sub);
340}; 368};
341#define to_bttv_sub_drv(x) container_of((x), struct bttv_sub_driver, drv) 369#define to_bttv_sub_drv(x) container_of((x), struct bttv_sub_driver, drv)
342 370
@@ -364,6 +392,10 @@ extern int bttv_I2CWrite(struct bttv *btv, unsigned char addr, unsigned char b1,
364 unsigned char b2, int both); 392 unsigned char b2, int both);
365extern void bttv_readee(struct bttv *btv, unsigned char *eedata, int addr); 393extern void bttv_readee(struct bttv *btv, unsigned char *eedata, int addr);
366 394
395extern int bttv_input_init(struct bttv *dev);
396extern void bttv_input_fini(struct bttv *dev);
397extern void bttv_input_irq(struct bttv *dev);
398
367#endif /* _BTTV_H_ */ 399#endif /* _BTTV_H_ */
368/* 400/*
369 * Local variables: 401 * Local variables:
diff --git a/drivers/media/video/bttvp.h b/drivers/media/video/bttvp.h
index d04d02385349..55759f698e02 100644
--- a/drivers/media/video/bttvp.h
+++ b/drivers/media/video/bttvp.h
@@ -209,7 +209,6 @@ extern struct bus_type bttv_sub_bus_type;
209int bttv_sub_add_device(struct bttv_core *core, char *name); 209int bttv_sub_add_device(struct bttv_core *core, char *name);
210int bttv_sub_del_devices(struct bttv_core *core); 210int bttv_sub_del_devices(struct bttv_core *core);
211void bttv_gpio_irq(struct bttv_core *core); 211void bttv_gpio_irq(struct bttv_core *core);
212int bttv_any_irq(struct bttv_core *core);
213 212
214 213
215/* ---------------------------------------------------------- */ 214/* ---------------------------------------------------------- */
@@ -275,7 +274,8 @@ struct bttv {
275 struct bttv_pll_info pll; 274 struct bttv_pll_info pll;
276 int triton1; 275 int triton1;
277 int gpioirq; 276 int gpioirq;
278 int any_irq; 277 int (*custom_irq)(struct bttv *btv);
278
279 int use_i2c_hw; 279 int use_i2c_hw;
280 280
281 /* old gpio interface */ 281 /* old gpio interface */
@@ -300,7 +300,7 @@ struct bttv {
300 300
301 /* infrared remote */ 301 /* infrared remote */
302 int has_remote; 302 int has_remote;
303 struct bttv_input *remote; 303 struct bttv_ir *remote;
304 304
305 /* locking */ 305 /* locking */
306 spinlock_t s_lock; 306 spinlock_t s_lock;