V4L/DVB (11523): gspca - m5602-po1030: Add private green balance control
authorErik Andr?n <erik.andren@gmail.com>
Tue, 13 Jan 2009 16:55:52 +0000 (13:55 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 16 Jun 2009 21:20:32 +0000 (18:20 -0300)
Signed-off-by: Erik Andr?n <erik.andren@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/gspca/m5602/m5602_po1030.c
drivers/media/video/gspca/m5602/m5602_po1030.h
drivers/media/video/gspca/m5602/m5602_sensor.h

index e32d03a..ee8e496 100644 (file)
@@ -26,6 +26,8 @@ static int po1030_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val);
 static int po1030_set_red_balance(struct gspca_dev *gspca_dev, __s32 val);
 static int po1030_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val);
 static int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val);
+static int po1030_get_green_balance(struct gspca_dev *gspca_dev, __s32 *val);
+static int po1030_set_green_balance(struct gspca_dev *gspca_dev, __s32 val);
 static int po1030_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
 static int po1030_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
 static int po1030_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
@@ -169,7 +171,21 @@ const static struct ctrl po1030_ctrls[] = {
                .set = po1030_set_auto_exposure,
                .get = po1030_get_auto_exposure
        },
-
+#define GREEN_BALANCE_IDX 8
+       {
+               {
+                       .id             = M5602_V4L2_CID_GREEN_BALANCE,
+                       .type           = V4L2_CTRL_TYPE_INTEGER,
+                       .name           = "green balance",
+                       .minimum        = 0x00,
+                       .maximum        = 0xff,
+                       .step           = 0x1,
+                       .default_value  = PO1030_GREEN_GAIN_DEFAULT,
+                       .flags          = V4L2_CTRL_FLAG_SLIDER
+               },
+               .set = po1030_set_green_balance,
+               .get = po1030_get_green_balance
+       },
 };
 
 static void po1030_dump_registers(struct sd *sd);
@@ -288,6 +304,11 @@ int po1030_init(struct sd *sd)
        if (err < 0)
                return err;
 
+       err = po1030_set_green_balance(&sd->gspca_dev,
+                                      sensor_settings[GREEN_BALANCE_IDX]);
+       if (err < 0)
+               return err;
+
        err = po1030_set_auto_white_balance(&sd->gspca_dev,
                                sensor_settings[AUTO_WHITE_BALANCE_IDX]);
        if (err < 0)
@@ -499,6 +520,37 @@ static int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
        return err;
 }
 
+static int po1030_get_green_balance(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       s32 *sensor_settings = sd->sensor_priv;
+
+       *val = sensor_settings[GREEN_BALANCE_IDX];
+       PDEBUG(D_V4L2, "Read green gain %d", *val);
+
+       return 0;
+}
+
+static int po1030_set_green_balance(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       s32 *sensor_settings = sd->sensor_priv;
+       u8 i2c_data;
+       int err;
+
+       sensor_settings[GREEN_BALANCE_IDX] = val;
+       i2c_data = val & 0xff;
+       PDEBUG(D_V4L2, "Set green gain to %d", i2c_data);
+
+       err = m5602_write_sensor(sd, PO1030_GREEN_1_GAIN,
+                          &i2c_data, 1);
+       if (err < 0)
+               return err;
+
+       return m5602_write_sensor(sd, PO1030_GREEN_2_GAIN,
+                                &i2c_data, 1);
+}
+
 static int po1030_get_auto_white_balance(struct gspca_dev *gspca_dev,
                                         __s32 *val)
 {
index 3ecacf0..0b2dab0 100644 (file)
 #define PO1030_EXPOSURE_DEFAULT                0x0085
 #define PO1030_BLUE_GAIN_DEFAULT       0x36
 #define PO1030_RED_GAIN_DEFAULT        0x36
+#define PO1030_GREEN_GAIN_DEFAULT      0x40
 
 /*****************************************************************************/
 
index 987dcb2..5b76b6b 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "m5602_bridge.h"
 
+#define M5602_V4L2_CID_GREEN_BALANCE   (V4L2_CID_PRIVATE_BASE + 0)
+
 /* Enumerates all supported sensors */
 enum sensors {
        OV9650_SENSOR   = 1,