Merge branch 'drm-intel-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/ickle...
[pandora-kernel.git] / drivers / media / video / bt8xx / bttv-input.c
index aa153a9..6bf05a7 100644 (file)
@@ -49,6 +49,8 @@ module_param(ir_rc5_key_timeout, int, 0644);
 
 #define DEVNAME "bttv-input"
 
+#define MODULE_NAME "bttv"
+
 /* ---------------------------------------------------------------------- */
 
 static void ir_handle_key(struct bttv *btv)
@@ -243,10 +245,87 @@ static void bttv_ir_stop(struct bttv *btv)
        }
 }
 
+/*
+ * Get_key functions used by I2C remotes
+ */
+
+static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
+{
+       unsigned char b;
+
+       /* poll IR chip */
+       if (1 != i2c_master_recv(ir->c, &b, 1)) {
+               dprintk(KERN_INFO DEVNAME ": read error\n");
+               return -EIO;
+       }
+
+       /* ignore 0xaa */
+       if (b==0xaa)
+               return 0;
+       dprintk(KERN_INFO DEVNAME ": key %02x\n", b);
+
+       *ir_key = b;
+       *ir_raw = b;
+       return 1;
+}
+
+/* Instantiate the I2C IR receiver device, if present */
+void __devinit init_bttv_i2c_ir(struct bttv *btv)
+{
+       const unsigned short addr_list[] = {
+               0x1a, 0x18, 0x64, 0x30, 0x71,
+               I2C_CLIENT_END
+       };
+       struct i2c_board_info info;
+
+       if (0 != btv->i2c_rc)
+               return;
+
+       memset(&info, 0, sizeof(struct i2c_board_info));
+       memset(&btv->init_data, 0, sizeof(btv->init_data));
+       strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
+
+       switch (btv->c.type) {
+       case BTTV_BOARD_PV951:
+               btv->init_data.name = "PV951";
+               btv->init_data.get_key = get_key_pv951;
+               btv->init_data.ir_codes = RC_MAP_PV951;
+               btv->init_data.type = IR_TYPE_OTHER;
+               info.addr = 0x4b;
+               break;
+       default:
+               /*
+                * The external IR receiver is at i2c address 0x34 (0x35 for
+                 * reads).  Future Hauppauge cards will have an internal
+                 * receiver at 0x30 (0x31 for reads).  In theory, both can be
+                 * fitted, and Hauppauge suggest an external overrides an
+                 * internal.
+                * That's why we probe 0x1a (~0x34) first. CB
+                */
+
+               i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL);
+               return;
+       }
+
+       if (btv->init_data.name)
+               info.platform_data = &btv->init_data;
+       i2c_new_device(&btv->c.i2c_adap, &info);
+
+       return;
+}
+
+int __devexit fini_bttv_i2c(struct bttv *btv)
+{
+       if (0 != btv->i2c_rc)
+               return 0;
+
+       return i2c_del_adapter(&btv->c.i2c_adap);
+}
+
 int bttv_input_init(struct bttv *btv)
 {
        struct card_ir *ir;
-       struct ir_scancode_table *ir_codes = NULL;
+       char *ir_codes = NULL;
        struct input_dev *input_dev;
        u64 ir_type = IR_TYPE_OTHER;
        int err = -ENOMEM;
@@ -264,7 +343,7 @@ int bttv_input_init(struct bttv *btv)
        case BTTV_BOARD_AVERMEDIA:
        case BTTV_BOARD_AVPHONE98:
        case BTTV_BOARD_AVERMEDIA98:
-               ir_codes         = &ir_codes_avermedia_table;
+               ir_codes         = RC_MAP_AVERMEDIA;
                ir->mask_keycode = 0xf88000;
                ir->mask_keydown = 0x010000;
                ir->polling      = 50; // ms
@@ -272,14 +351,14 @@ int bttv_input_init(struct bttv *btv)
 
        case BTTV_BOARD_AVDVBT_761:
        case BTTV_BOARD_AVDVBT_771:
-               ir_codes         = &ir_codes_avermedia_dvbt_table;
+               ir_codes         = RC_MAP_AVERMEDIA_DVBT;
                ir->mask_keycode = 0x0f00c0;
                ir->mask_keydown = 0x000020;
                ir->polling      = 50; // ms
                break;
 
        case BTTV_BOARD_PXELVWPLTVPAK:
-               ir_codes         = &ir_codes_pixelview_table;
+               ir_codes         = RC_MAP_PIXELVIEW;
                ir->mask_keycode = 0x003e00;
                ir->mask_keyup   = 0x010000;
                ir->polling      = 50; // ms
@@ -287,24 +366,24 @@ int bttv_input_init(struct bttv *btv)
        case BTTV_BOARD_PV_M4900:
        case BTTV_BOARD_PV_BT878P_9B:
        case BTTV_BOARD_PV_BT878P_PLUS:
-               ir_codes         = &ir_codes_pixelview_table;
+               ir_codes         = RC_MAP_PIXELVIEW;
                ir->mask_keycode = 0x001f00;
                ir->mask_keyup   = 0x008000;
                ir->polling      = 50; // ms
                break;
 
        case BTTV_BOARD_WINFAST2000:
-               ir_codes         = &ir_codes_winfast_table;
+               ir_codes         = RC_MAP_WINFAST;
                ir->mask_keycode = 0x1f8;
                break;
        case BTTV_BOARD_MAGICTVIEW061:
        case BTTV_BOARD_MAGICTVIEW063:
-               ir_codes         = &ir_codes_winfast_table;
+               ir_codes         = RC_MAP_WINFAST;
                ir->mask_keycode = 0x0008e000;
                ir->mask_keydown = 0x00200000;
                break;
        case BTTV_BOARD_APAC_VIEWCOMP:
-               ir_codes         = &ir_codes_apac_viewcomp_table;
+               ir_codes         = RC_MAP_APAC_VIEWCOMP;
                ir->mask_keycode = 0x001f00;
                ir->mask_keyup   = 0x008000;
                ir->polling      = 50; // ms
@@ -312,30 +391,30 @@ int bttv_input_init(struct bttv *btv)
        case BTTV_BOARD_ASKEY_CPH03X:
        case BTTV_BOARD_CONCEPTRONIC_CTVFMI2:
        case BTTV_BOARD_CONTVFMI:
-               ir_codes         = &ir_codes_pixelview_table;
+               ir_codes         = RC_MAP_PIXELVIEW;
                ir->mask_keycode = 0x001F00;
                ir->mask_keyup   = 0x006000;
                ir->polling      = 50; // ms
                break;
        case BTTV_BOARD_NEBULA_DIGITV:
-               ir_codes = &ir_codes_nebula_table;
+               ir_codes = RC_MAP_NEBULA;
                btv->custom_irq = bttv_rc5_irq;
                ir->rc5_gpio = 1;
                break;
        case BTTV_BOARD_MACHTV_MAGICTV:
-               ir_codes         = &ir_codes_apac_viewcomp_table;
+               ir_codes         = RC_MAP_APAC_VIEWCOMP;
                ir->mask_keycode = 0x001F00;
                ir->mask_keyup   = 0x004000;
                ir->polling      = 50; /* ms */
                break;
        case BTTV_BOARD_KOZUMI_KTV_01C:
-               ir_codes         = &ir_codes_pctv_sedna_table;
+               ir_codes         = RC_MAP_PCTV_SEDNA;
                ir->mask_keycode = 0x001f00;
                ir->mask_keyup   = 0x006000;
                ir->polling      = 50; /* ms */
                break;
        case BTTV_BOARD_ENLTV_FM_2:
-               ir_codes         = &ir_codes_encore_enltv2_table;
+               ir_codes         = RC_MAP_ENCORE_ENLTV2;
                ir->mask_keycode = 0x00fd00;
                ir->mask_keyup   = 0x000080;
                ir->polling      = 1; /* ms */
@@ -390,7 +469,7 @@ int bttv_input_init(struct bttv *btv)
        bttv_ir_start(btv, ir);
 
        /* all done */
-       err = ir_input_register(btv->remote->dev, ir_codes, NULL);
+       err = ir_input_register(btv->remote->dev, ir_codes, NULL, MODULE_NAME);
        if (err)
                goto err_out_stop;
 
@@ -418,10 +497,3 @@ void bttv_input_fini(struct bttv *btv)
        kfree(btv->remote);
        btv->remote = NULL;
 }
-
-
-/*
- * Local variables:
- * c-basic-offset: 8
- * End:
- */