From 456ebe4e92063b92d2672da272bfc7ac70bd8bdd Mon Sep 17 00:00:00 2001 From: Erik Andrén Date: Sat, 20 Jun 2009 09:29:00 -0300 Subject: V4L/DVB (12982): gspca - m5602-ov7660: Add auto gain ctrl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Erik Andrén Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/gspca/m5602/m5602_ov7660.c | 51 +++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'drivers/media/video/gspca/m5602') diff --git a/drivers/media/video/gspca/m5602/m5602_ov7660.c b/drivers/media/video/gspca/m5602/m5602_ov7660.c index 7d2af089ee99..855c058d5df3 100644 --- a/drivers/media/video/gspca/m5602/m5602_ov7660.c +++ b/drivers/media/video/gspca/m5602/m5602_ov7660.c @@ -28,6 +28,8 @@ static int ov7660_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val); static int ov7660_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val); +static int ov7660_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val); +static int ov7660_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val); const static struct ctrl ov7660_ctrls[] = { @@ -90,7 +92,20 @@ const static struct ctrl ov7660_ctrls[] = { .set = ov7660_set_auto_white_balance, .get = ov7660_get_auto_white_balance }, - +#define AUTO_GAIN_CTRL_IDX 5 + { + { + .id = V4L2_CID_AUTOGAIN, + .type = V4L2_CTRL_TYPE_BOOLEAN, + .name = "auto gain control", + .minimum = 0, + .maximum = 1, + .step = 1, + .default_value = 1 + }, + .set = ov7660_set_auto_gain, + .get = ov7660_get_auto_gain + }, }; static struct v4l2_pix_format ov7660_modes[] = { @@ -207,6 +222,11 @@ int ov7660_init(struct sd *sd) if (err < 0) return err; + err = ov7660_set_auto_gain(&sd->gspca_dev, + sensor_settings[AUTO_GAIN_CTRL_IDX]); + if (err < 0) + return err; + err = ov7660_set_blue_gain(&sd->gspca_dev, sensor_settings[BLUE_BALANCE_IDX]); if (err < 0) @@ -342,6 +362,35 @@ static int ov7660_set_auto_white_balance(struct gspca_dev *gspca_dev, return err; } +static int ov7660_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val) +{ + struct sd *sd = (struct sd *) gspca_dev; + s32 *sensor_settings = sd->sensor_priv; + + *val = sensor_settings[AUTO_GAIN_CTRL_IDX]; + PDEBUG(D_V4L2, "Read auto gain control %d", *val); + return 0; +} + +static int ov7660_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val) +{ + int err; + u8 i2c_data; + struct sd *sd = (struct sd *) gspca_dev; + s32 *sensor_settings = sd->sensor_priv; + + PDEBUG(D_V4L2, "Set auto gain control to %d", val); + + sensor_settings[AUTO_GAIN_CTRL_IDX] = val; + err = m5602_read_sensor(sd, OV7660_COM8, &i2c_data, 1); + if (err < 0) + return err; + + i2c_data = ((i2c_data & 0xfb) | ((val & 0x01) << 2)); + + return m5602_write_sensor(sd, OV7660_COM8, &i2c_data, 1); +} + static void ov7660_dump_registers(struct sd *sd) { int address; -- cgit v1.2.3