WorkStruct: make allyesconfig
[deliverable/linux.git] / drivers / media / video / ir-kbd-i2c.c
index 95bacf435414ead307c6230cd65479f42a9369dc..ab87e7bfe84f1c6afc3ab91de80a2be12f211ea3 100644 (file)
@@ -64,23 +64,32 @@ MODULE_PARM_DESC(hauppauge, "Specify Hauppauge remote: 0=black, 1=grey (defaults
 static int get_key_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
 {
        unsigned char buf[3];
-       int start, toggle, dev, code;
+       int start, range, toggle, dev, code;
 
        /* poll IR chip */
        if (3 != i2c_master_recv(&ir->c,buf,3))
                return -EIO;
 
        /* split rc5 data block ... */
-       start  = (buf[0] >> 6) &    3;
+       start  = (buf[0] >> 7) &    1;
+       range  = (buf[0] >> 6) &    1;
        toggle = (buf[0] >> 5) &    1;
        dev    =  buf[0]       & 0x1f;
        code   = (buf[1] >> 2) & 0x3f;
 
-       if (3 != start)
+       /* rc5 has two start bits
+        * the first bit must be one
+        * the second bit defines the command range (1 = 0-63, 0 = 64 - 127)
+        */
+       if (!start)
                /* no key pressed */
                return 0;
-       dprintk(1,"ir hauppauge (rc5): s%d t%d dev=%d code=%d\n",
-               start, toggle, dev, code);
+
+       if (!range)
+               code += 64;
+
+       dprintk(1,"ir hauppauge (rc5): s%d r%d t%d dev=%d code=%d\n",
+               start, range, toggle, dev, code);
 
        /* return key */
        *ir_key = code;
@@ -150,12 +159,11 @@ static int get_key_knc1(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
        return 1;
 }
 
-/* The new pinnacle PCTV remote (with the colored buttons)
+/* Common (grey or coloured) pinnacle PCTV remote handling
  *
- * Ricardo Cerqueira <v4l@cerqueira.org>
  */
-
-int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
+static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
+                           int parity_offset, int marker, int code_modulo)
 {
        unsigned char b[4];
        unsigned int start = 0,parity = 0,code = 0;
@@ -167,9 +175,9 @@ int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
        }
 
        for (start = 0; start<4; start++) {
-               if (b[start] == 0x80) {
-                       code=b[(start+3)%4];
-                       parity=b[(start+2)%4];
+               if (b[start] == marker) {
+                       code=b[(start+parity_offset+1)%4];
+                       parity=b[(start+parity_offset)%4];
                }
        }
 
@@ -181,16 +189,14 @@ int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
        if (ir->old == parity)
                return 0;
 
-
        ir->old = parity;
 
-       /* Reduce code value to fit inside IR_KEYTAB_SIZE
-        *
-        * this is the only value that results in 42 unique
-        * codes < 128
-        */
+       /* drop special codes when a key is held down a long time for the grey controller
+          In this case, the second bit of the code is asserted */
+       if (marker == 0xfe && (code & 0x40))
+               return 0;
 
-       code %= 0x88;
+       code %= code_modulo;
 
        *ir_raw = code;
        *ir_key = code;
@@ -200,7 +206,40 @@ int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
        return 1;
 }
 
-EXPORT_SYMBOL_GPL(get_key_pinnacle);
+/* The grey pinnacle PCTV remote
+ *
+ *  There are one issue with this remote:
+ *   - I2c packet does not change when the same key is pressed quickly. The workaround
+ *     is to hold down each key for about half a second, so that another code is generated
+ *     in the i2c packet, and the function can distinguish key presses.
+ *
+ * Sylvain Pasche <sylvain.pasche@gmail.com>
+ */
+int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
+{
+
+       return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff);
+}
+
+EXPORT_SYMBOL_GPL(get_key_pinnacle_grey);
+
+
+/* The new pinnacle PCTV remote (with the colored buttons)
+ *
+ * Ricardo Cerqueira <v4l@cerqueira.org>
+ */
+int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
+{
+       /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
+        *
+        * this is the only value that results in 42 unique
+        * codes < 128
+        */
+
+       return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88);
+}
+
+EXPORT_SYMBOL_GPL(get_key_pinnacle_color);
 
 /* ----------------------------------------------------------------------- */
 
@@ -229,9 +268,9 @@ static void ir_timer(unsigned long data)
        schedule_work(&ir->work);
 }
 
-static void ir_work(void *data)
+static void ir_work(struct work_struct *work)
 {
-       struct IR_i2c *ir = data;
+       struct IR_i2c *ir = container_of(work, struct IR_i2c, work);
        ir_key_poll(ir);
        mod_timer(&ir->timer, jiffies+HZ/10);
 }
@@ -361,7 +400,7 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
               ir->input->name,ir->input->phys,adap->name);
 
        /* start polling via eventd */
-       INIT_WORK(&ir->work, ir_work, ir);
+       INIT_WORK(&ir->work, ir_work);
        init_timer(&ir->timer);
        ir->timer.function = ir_timer;
        ir->timer.data     = (unsigned long)ir;
@@ -411,6 +450,9 @@ static int ir_probe(struct i2c_adapter *adap)
        case I2C_HW_B_BT848:
                probe = probe_bttv;
                break;
+       case I2C_HW_B_CX2341X:
+               probe = probe_bttv;
+               break;
        case I2C_HW_SAA7134:
                probe = probe_saa7134;
                break;
This page took 0.02734 seconds and 5 git commands to generate.