V4L/DVB (10190): cx88: Fix some Kbuild troubles
[safe/jmp/linux-2.6] / drivers / media / video / cx88 / cx88-input.c
index 4bd86c4..8683d10 100644 (file)
@@ -27,7 +27,6 @@
 #include <linux/input.h>
 #include <linux/pci.h>
 #include <linux/module.h>
-#include <linux/moduleparam.h>
 
 #include "cx88.h"
 #include <media/ir-common.h>
@@ -58,7 +57,7 @@ struct cx88_IR {
        u32 mask_keyup;
 };
 
-static int ir_debug = 0;
+static int ir_debug;
 module_param(ir_debug, int, 0644);     /* debug level [IR] */
 MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
 
@@ -74,7 +73,8 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
 
        /* read gpio value */
        gpio = cx_read(ir->gpio_addr);
-       if (core->board == CX88_BOARD_NPGTECH_REALTV) {
+       switch (core->boardnr) {
+       case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
                /* This board apparently uses a combination of 2 GPIO
                   to represent the keys. Additionally, the second GPIO
                   can be used for parity.
@@ -89,10 +89,15 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
 
                auxgpio = cx_read(MO_GP1_IO);
                /* Take out the parity part */
-               gpio+=(auxgpio & 0xef);
-       } else
+               gpio=(gpio & 0x7fd) + (auxgpio & 0xef);
+               break;
+       case CX88_BOARD_WINFAST_DTV1000:
+               gpio = (gpio & 0x6ff) | ((cx_read(MO_GP1_IO) << 8) & 0x900);
                auxgpio = gpio;
-
+               break;
+       default:
+               auxgpio = gpio;
+       }
        if (ir->polling) {
                if (ir->last_gpio == auxgpio)
                        return;
@@ -107,7 +112,15 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
                   (gpio & ir->mask_keydown) ? " down" : "",
                   (gpio & ir->mask_keyup) ? " up" : "");
 
-       if (ir->mask_keydown) {
+       if (ir->core->boardnr == CX88_BOARD_NORWOOD_MICRO) {
+               u32 gpio_key = cx_read(MO_GP0_IO);
+
+               data = (data << 4) | ((gpio_key & 0xf0) >> 4);
+
+               ir_input_keydown(ir->input, &ir->ir, data, data);
+               ir_input_nokey(ir->input, &ir->ir);
+
+       } else if (ir->mask_keydown) {
                /* bit set on keydown */
                if (gpio & ir->mask_keydown) {
                        ir_input_keydown(ir->input, &ir->ir, data, data);
@@ -137,14 +150,39 @@ static void ir_timer(unsigned long data)
        schedule_work(&ir->work);
 }
 
-static void cx88_ir_work(void *data)
+static void cx88_ir_work(struct work_struct *work)
 {
-       struct cx88_IR *ir = data;
-       unsigned long timeout;
+       struct cx88_IR *ir = container_of(work, struct cx88_IR, work);
 
        cx88_ir_handle_key(ir);
-       timeout = jiffies + (ir->polling * HZ / 1000);
-       mod_timer(&ir->timer, timeout);
+       mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
+}
+
+void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir)
+{
+       if (ir->polling) {
+               setup_timer(&ir->timer, ir_timer, (unsigned long)ir);
+               INIT_WORK(&ir->work, cx88_ir_work);
+               schedule_work(&ir->work);
+       }
+       if (ir->sampling) {
+               core->pci_irqmask |= PCI_INT_IR_SMPINT;
+               cx_write(MO_DDS_IO, 0xa80a80);  /* 4 kHz sample rate */
+               cx_write(MO_DDSCFG_IO, 0x5);    /* enable */
+       }
+}
+
+void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir)
+{
+       if (ir->sampling) {
+               cx_write(MO_DDSCFG_IO, 0x0);
+               core->pci_irqmask &= ~PCI_INT_IR_SMPINT;
+       }
+
+       if (ir->polling) {
+               del_timer_sync(&ir->timer);
+               flush_scheduled_work();
+       }
 }
 
 /* ---------------------------------------------------------------------- */
@@ -155,19 +193,17 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
        struct input_dev *input_dev;
        IR_KEYTAB_TYPE *ir_codes = NULL;
        int ir_type = IR_TYPE_OTHER;
+       int err = -ENOMEM;
 
        ir = kzalloc(sizeof(*ir), GFP_KERNEL);
        input_dev = input_allocate_device();
-       if (!ir || !input_dev) {
-               kfree(ir);
-               input_free_device(input_dev);
-               return -ENOMEM;
-       }
+       if (!ir || !input_dev)
+               goto err_out_free;
 
        ir->input = input_dev;
 
        /* detect & configure */
-       switch (core->board) {
+       switch (core->boardnr) {
        case CX88_BOARD_DNTV_LIVE_DVB_T:
        case CX88_BOARD_KWORLD_DVB_T:
        case CX88_BOARD_KWORLD_DVB_T_CX22702:
@@ -187,11 +223,22 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
        case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
        case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
        case CX88_BOARD_HAUPPAUGE_HVR1100:
+       case CX88_BOARD_HAUPPAUGE_HVR3000:
+       case CX88_BOARD_HAUPPAUGE_HVR4000:
+       case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
                ir_codes = ir_codes_hauppauge_new;
                ir_type = IR_TYPE_RC5;
                ir->sampling = 1;
                break;
+       case CX88_BOARD_WINFAST_DTV2000H:
+               ir_codes = ir_codes_winfast;
+               ir->gpio_addr = MO_GP0_IO;
+               ir->mask_keycode = 0x8f8;
+               ir->mask_keyup = 0x100;
+               ir->polling = 50; /* ms */
+               break;
        case CX88_BOARD_WINFAST2000XP_EXPERT:
+       case CX88_BOARD_WINFAST_DTV1000:
                ir_codes = ir_codes_winfast;
                ir->gpio_addr = MO_GP0_IO;
                ir->mask_keycode = 0x8f8;
@@ -205,7 +252,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
                ir->mask_keydown = 0x02;
                ir->polling = 5; /* ms */
                break;
-       case CX88_BOARD_PROLINK_PLAYTVPVR:
+       case CX88_BOARD_PROLINK_PLAYTVPVR:
        case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
                ir_codes = ir_codes_pixelview;
                ir->gpio_addr = MO_GP1_IO;
@@ -213,6 +260,14 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
                ir->mask_keyup = 0x80;
                ir->polling = 1; /* ms */
                break;
+       case CX88_BOARD_PROLINK_PV_8000GT:
+       case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
+               ir_codes = ir_codes_pixelview_new;
+               ir->gpio_addr = MO_GP1_IO;
+               ir->mask_keycode = 0x3f;
+               ir->mask_keyup = 0x80;
+               ir->polling = 1; /* ms */
+               break;
        case CX88_BOARD_KWORLD_LTV883:
                ir_codes = ir_codes_pixelview;
                ir->gpio_addr = MO_GP1_IO;
@@ -247,23 +302,39 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
                ir_type = IR_TYPE_PD;
                ir->sampling = 0xff00; /* address */
                break;
-       case CX88_BOARD_NPGTECH_REALTV:
+       case CX88_BOARD_NORWOOD_MICRO:
+               ir_codes         = ir_codes_norwood;
+               ir->gpio_addr    = MO_GP1_IO;
+               ir->mask_keycode = 0x0e;
+               ir->mask_keyup   = 0x80;
+               ir->polling      = 50; /* ms */
+               break;
+       case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
                ir_codes = ir_codes_npgtech;
                ir->gpio_addr = MO_GP0_IO;
                ir->mask_keycode = 0xfa;
                ir->polling = 50; /* ms */
                break;
+       case CX88_BOARD_PINNACLE_PCTV_HD_800i:
+               ir_codes = ir_codes_pinnacle_pctv_hd;
+               ir_type = IR_TYPE_RC5;
+               ir->sampling = 1;
+               break;
+       case CX88_BOARD_POWERCOLOR_REAL_ANGEL:
+               ir_codes = ir_codes_powercolor_real_angel;
+               ir->gpio_addr = MO_GP2_IO;
+               ir->mask_keycode = 0x7e;
+               ir->polling = 100; /* ms */
+               break;
        }
 
        if (NULL == ir_codes) {
-               kfree(ir);
-               input_free_device(input_dev);
-               return -ENODEV;
+               err = -ENODEV;
+               goto err_out_free;
        }
 
        /* init input device */
-       snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)",
-                cx88_boards[core->board].name);
+       snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", core->board.name);
        snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
 
        ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
@@ -278,28 +349,27 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
                input_dev->id.vendor = pci->vendor;
                input_dev->id.product = pci->device;
        }
-       input_dev->cdev.dev = &pci->dev;
+       input_dev->dev.parent = &pci->dev;
        /* record handles to ourself */
        ir->core = core;
        core->ir = ir;
 
-       if (ir->polling) {
-               INIT_WORK(&ir->work, cx88_ir_work, ir);
-               init_timer(&ir->timer);
-               ir->timer.function = ir_timer;
-               ir->timer.data = (unsigned long)ir;
-               schedule_work(&ir->work);
-       }
-       if (ir->sampling) {
-               core->pci_irqmask |= (1 << 18); /* IR_SMP_INT */
-               cx_write(MO_DDS_IO, 0xa80a80);  /* 4 kHz sample rate */
-               cx_write(MO_DDSCFG_IO, 0x5);    /* enable */
-       }
+       cx88_ir_start(core, ir);
 
        /* all done */
-       input_register_device(ir->input);
+       err = input_register_device(ir->input);
+       if (err)
+               goto err_out_stop;
 
        return 0;
+
+ err_out_stop:
+       cx88_ir_stop(core, ir);
+       core->ir = NULL;
+ err_out_free:
+       input_free_device(input_dev);
+       kfree(ir);
+       return err;
 }
 
 int cx88_ir_fini(struct cx88_core *core)
@@ -310,15 +380,7 @@ int cx88_ir_fini(struct cx88_core *core)
        if (NULL == ir)
                return 0;
 
-       if (ir->sampling) {
-               cx_write(MO_DDSCFG_IO, 0x0);
-               core->pci_irqmask &= ~(1 << 18);
-       }
-       if (ir->polling) {
-               del_timer(&ir->timer);
-               flush_scheduled_work();
-       }
-
+       cx88_ir_stop(core, ir);
        input_unregister_device(ir->input);
        kfree(ir);
 
@@ -333,7 +395,7 @@ void cx88_ir_irq(struct cx88_core *core)
 {
        struct cx88_IR *ir = core->ir;
        u32 samples, ircode;
-       int i;
+       int i, start, range, toggle, dev, code;
 
        if (NULL == ir)
                return;
@@ -363,7 +425,7 @@ void cx88_ir_irq(struct cx88_core *core)
                ir_dump_samples(ir->samples, ir->scount);
 
        /* decode it */
-       switch (core->board) {
+       switch (core->boardnr) {
        case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
        case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
                ircode = ir_decode_pulsedistance(ir->samples, ir->scount, 1, 4);
@@ -401,6 +463,36 @@ void cx88_ir_irq(struct cx88_core *core)
        case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
        case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
        case CX88_BOARD_HAUPPAUGE_HVR1100:
+       case CX88_BOARD_HAUPPAUGE_HVR3000:
+       case CX88_BOARD_HAUPPAUGE_HVR4000:
+       case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
+               ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
+               ir_dprintk("biphase decoded: %x\n", ircode);
+               /*
+                * RC5 has an extension bit which adds a new range
+                * of available codes, this is detected here. Also
+                * hauppauge remotes (black/silver) always use
+                * specific device ids. If we do not filter the
+                * device ids then messages destined for devices
+                * such as TVs (id=0) will get through to the
+                * device causing mis-fired events.
+                */
+               /* split rc5 data block ... */
+               start = (ircode & 0x2000) >> 13;
+               range = (ircode & 0x1000) >> 12;
+               toggle= (ircode & 0x0800) >> 11;
+               dev   = (ircode & 0x07c0) >> 6;
+               code  = (ircode & 0x003f) | ((range << 6) ^ 0x0040);
+               if( start != 1)
+                       /* no key pressed */
+                       break;
+               if ( dev != 0x1e && dev != 0x1f )
+                       /* not a hauppauge remote */
+                       break;
+               ir_input_keydown(ir->input, &ir->ir, code, ircode);
+               ir->release = jiffies + msecs_to_jiffies(120);
+               break;
+       case CX88_BOARD_PINNACLE_PCTV_HD_800i:
                ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
                ir_dprintk("biphase decoded: %x\n", ircode);
                if ((ircode & 0xfffff000) != 0x3000)