]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/media/video/cx88/cx88-input.c
V4L/DVB: ir: use IR_KEYTABLE where an IR table is needed
[net-next-2.6.git] / drivers / media / video / cx88 / cx88-input.c
index de180d4d5a2139c3a7c430e484724421df4e305d..48ca9805bb908649da983161f16f22ab522d66bd 100644 (file)
 #include <linux/hrtimer.h>
 #include <linux/input.h>
 #include <linux/pci.h>
+#include <linux/slab.h>
 #include <linux/module.h>
 
 #include "cx88.h"
 #include <media/ir-common.h>
 
+#define MODULE_NAME "cx88xx"
+
 /* ---------------------------------------------------------------------- */
 
 struct cx88_IR {
        struct cx88_core *core;
        struct input_dev *input;
        struct ir_input_state ir;
+       struct ir_dev_props props;
+
+       int users;
+
        char name[32];
        char phys[32];
 
@@ -158,8 +165,16 @@ static enum hrtimer_restart cx88_ir_work(struct hrtimer *timer)
        return HRTIMER_RESTART;
 }
 
-void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir)
+static int __cx88_ir_start(void *priv)
 {
+       struct cx88_core *core = priv;
+       struct cx88_IR *ir;
+
+       if (!core || !core->ir)
+               return -EINVAL;
+
+       ir = core->ir;
+
        if (ir->polling) {
                hrtimer_init(&ir->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
                ir->timer.function = cx88_ir_work;
@@ -172,10 +187,18 @@ void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir)
                cx_write(MO_DDS_IO, 0xa80a80);  /* 4 kHz sample rate */
                cx_write(MO_DDSCFG_IO, 0x5);    /* enable */
        }
+       return 0;
 }
 
-void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir)
+static void __cx88_ir_stop(void *priv)
 {
+       struct cx88_core *core = priv;
+       struct cx88_IR *ir;
+
+       if (!core || !core->ir)
+               return;
+
+       ir = core->ir;
        if (ir->sampling) {
                cx_write(MO_DDSCFG_IO, 0x0);
                core->pci_irqmask &= ~PCI_INT_IR_SMPINT;
@@ -185,6 +208,37 @@ void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir)
                hrtimer_cancel(&ir->timer);
 }
 
+int cx88_ir_start(struct cx88_core *core)
+{
+       if (core->ir->users)
+               return __cx88_ir_start(core);
+
+       return 0;
+}
+
+void cx88_ir_stop(struct cx88_core *core)
+{
+       if (core->ir->users)
+               __cx88_ir_stop(core);
+}
+
+static int cx88_ir_open(void *priv)
+{
+       struct cx88_core *core = priv;
+
+       core->ir->users++;
+       return __cx88_ir_start(core);
+}
+
+static void cx88_ir_close(void *priv)
+{
+       struct cx88_core *core = priv;
+
+       core->ir->users--;
+       if (!core->ir->users)
+               __cx88_ir_stop(core);
+}
+
 /* ---------------------------------------------------------------------- */
 
 int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
@@ -207,14 +261,14 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
        case CX88_BOARD_DNTV_LIVE_DVB_T:
        case CX88_BOARD_KWORLD_DVB_T:
        case CX88_BOARD_KWORLD_DVB_T_CX22702:
-               ir_codes = &ir_codes_dntv_live_dvb_t_table;
+               ir_codes = &IR_KEYTABLE(dntv_live_dvb_t);
                ir->gpio_addr = MO_GP1_IO;
                ir->mask_keycode = 0x1f;
                ir->mask_keyup = 0x60;
                ir->polling = 50; /* ms */
                break;
        case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
-               ir_codes = &ir_codes_cinergy_1400_table;
+               ir_codes = &IR_KEYTABLE(cinergy_1400);
                ir_type = IR_TYPE_PD;
                ir->sampling = 0xeb04; /* address */
                break;
@@ -229,14 +283,14 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
        case CX88_BOARD_PCHDTV_HD3000:
        case CX88_BOARD_PCHDTV_HD5500:
        case CX88_BOARD_HAUPPAUGE_IRONLY:
-               ir_codes = &ir_codes_hauppauge_new_table;
+               ir_codes = &IR_KEYTABLE(hauppauge_new);
                ir_type = IR_TYPE_RC5;
                ir->sampling = 1;
                break;
        case CX88_BOARD_WINFAST_DTV2000H:
        case CX88_BOARD_WINFAST_DTV2000H_J:
        case CX88_BOARD_WINFAST_DTV1800H:
-               ir_codes = &ir_codes_winfast_table;
+               ir_codes = &IR_KEYTABLE(winfast);
                ir->gpio_addr = MO_GP0_IO;
                ir->mask_keycode = 0x8f8;
                ir->mask_keyup = 0x100;
@@ -245,14 +299,14 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
        case CX88_BOARD_WINFAST2000XP_EXPERT:
        case CX88_BOARD_WINFAST_DTV1000:
        case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL:
-               ir_codes = &ir_codes_winfast_table;
+               ir_codes = &IR_KEYTABLE(winfast);
                ir->gpio_addr = MO_GP0_IO;
                ir->mask_keycode = 0x8f8;
                ir->mask_keyup = 0x100;
                ir->polling = 1; /* ms */
                break;
        case CX88_BOARD_IODATA_GVBCTV7E:
-               ir_codes = &ir_codes_iodata_bctv7e_table;
+               ir_codes = &IR_KEYTABLE(iodata_bctv7e);
                ir->gpio_addr = MO_GP0_IO;
                ir->mask_keycode = 0xfd;
                ir->mask_keydown = 0x02;
@@ -260,7 +314,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
                break;
        case CX88_BOARD_PROLINK_PLAYTVPVR:
        case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
-               ir_codes = &ir_codes_pixelview_table;
+               ir_codes = &IR_KEYTABLE(pixelview);
                ir->gpio_addr = MO_GP1_IO;
                ir->mask_keycode = 0x1f;
                ir->mask_keyup = 0x80;
@@ -268,28 +322,28 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
                break;
        case CX88_BOARD_PROLINK_PV_8000GT:
        case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
-               ir_codes = &ir_codes_pixelview_new_table;
+               ir_codes = &IR_KEYTABLE(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_table;
+               ir_codes = &IR_KEYTABLE(pixelview);
                ir->gpio_addr = MO_GP1_IO;
                ir->mask_keycode = 0x1f;
                ir->mask_keyup = 0x60;
                ir->polling = 1; /* ms */
                break;
        case CX88_BOARD_ADSTECH_DVB_T_PCI:
-               ir_codes = &ir_codes_adstech_dvb_t_pci_table;
+               ir_codes = &IR_KEYTABLE(adstech_dvb_t_pci);
                ir->gpio_addr = MO_GP1_IO;
                ir->mask_keycode = 0xbf;
                ir->mask_keyup = 0x40;
                ir->polling = 50; /* ms */
                break;
        case CX88_BOARD_MSI_TVANYWHERE_MASTER:
-               ir_codes = &ir_codes_msi_tvanywhere_table;
+               ir_codes = &IR_KEYTABLE(msi_tvanywhere);
                ir->gpio_addr = MO_GP1_IO;
                ir->mask_keycode = 0x1f;
                ir->mask_keyup = 0x40;
@@ -297,7 +351,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
                break;
        case CX88_BOARD_AVERTV_303:
        case CX88_BOARD_AVERTV_STUDIO_303:
-               ir_codes         = &ir_codes_avertv_303_table;
+               ir_codes         = &IR_KEYTABLE(avertv_303);
                ir->gpio_addr    = MO_GP2_IO;
                ir->mask_keycode = 0xfb;
                ir->mask_keydown = 0x02;
@@ -310,41 +364,41 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
        case CX88_BOARD_PROF_7300:
        case CX88_BOARD_PROF_7301:
        case CX88_BOARD_PROF_6200:
-               ir_codes = &ir_codes_tbs_nec_table;
+               ir_codes = &IR_KEYTABLE(tbs_nec);
                ir_type = IR_TYPE_PD;
                ir->sampling = 0xff00; /* address */
                break;
        case CX88_BOARD_TEVII_S460:
        case CX88_BOARD_TEVII_S420:
-               ir_codes = &ir_codes_tevii_nec_table;
+               ir_codes = &IR_KEYTABLE(tevii_nec);
                ir_type = IR_TYPE_PD;
                ir->sampling = 0xff00; /* address */
                break;
        case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
-               ir_codes         = &ir_codes_dntv_live_dvbt_pro_table;
+               ir_codes         = &IR_KEYTABLE(dntv_live_dvbt_pro);
                ir_type          = IR_TYPE_PD;
                ir->sampling     = 0xff00; /* address */
                break;
        case CX88_BOARD_NORWOOD_MICRO:
-               ir_codes         = &ir_codes_norwood_table;
+               ir_codes         = &IR_KEYTABLE(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_table;
+               ir_codes         = &IR_KEYTABLE(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_table;
+               ir_codes         = &IR_KEYTABLE(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_table;
+               ir_codes         = &IR_KEYTABLE(powercolor_real_angel);
                ir->gpio_addr    = MO_GP2_IO;
                ir->mask_keycode = 0x7e;
                ir->polling      = 100; /* ms */
@@ -380,19 +434,19 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
        ir->core = core;
        core->ir = ir;
 
-       cx88_ir_start(core, ir);
+       ir->props.priv = core;
+       ir->props.open = cx88_ir_open;
+       ir->props.close = cx88_ir_close;
 
        /* all done */
-       err = ir_input_register(ir->input, ir_codes, NULL);
+       err = ir_input_register(ir->input, ir_codes, &ir->props, MODULE_NAME);
        if (err)
-               goto err_out_stop;
+               goto err_out_free;
 
        return 0;
 
- err_out_stop:
-       cx88_ir_stop(core, ir);
-       core->ir = NULL;
  err_out_free:
+       core->ir = NULL;
        kfree(ir);
        return err;
 }
@@ -405,7 +459,7 @@ int cx88_ir_fini(struct cx88_core *core)
        if (NULL == ir)
                return 0;
 
-       cx88_ir_stop(core, ir);
+       cx88_ir_stop(core);
        ir_input_unregister(ir->input);
        kfree(ir);