diff options
author | Erik Andrén <erik.andren@gmail.com> | 2009-01-22 04:04:59 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-06-16 18:20:48 -0300 |
commit | c9304e43fb71ad790c5fc995de55e7c95abe5b4a (patch) | |
tree | e4abe51049299f85265f488e71a668cf41b3e363 /drivers | |
parent | 2b622e2d0022fd9220d6f712ab59bff768c098e7 (diff) | |
download | linux-c9304e43fb71ad790c5fc995de55e7c95abe5b4a.tar.gz linux-c9304e43fb71ad790c5fc995de55e7c95abe5b4a.tar.bz2 linux-c9304e43fb71ad790c5fc995de55e7c95abe5b4a.zip |
V4L/DVB (11642): gspca - m5602-ov7660: Add a gain ctrl
Signed-off-by: Erik Andrén <erik.andren@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/video/gspca/m5602/m5602_ov7660.c | 65 | ||||
-rw-r--r-- | drivers/media/video/gspca/m5602/m5602_ov7660.h | 2 |
2 files changed, 62 insertions, 5 deletions
diff --git a/drivers/media/video/gspca/m5602/m5602_ov7660.c b/drivers/media/video/gspca/m5602/m5602_ov7660.c index 1c20a3bfaaff..bfa28de6cbb0 100644 --- a/drivers/media/video/gspca/m5602/m5602_ov7660.c +++ b/drivers/media/video/gspca/m5602/m5602_ov7660.c @@ -18,7 +18,26 @@ #include "m5602_ov7660.h" -const static struct ctrl ov7660_ctrls[] = {}; +static int ov7660_get_gain(struct gspca_dev *gspca_dev, __s32 *val); +static int ov7660_set_gain(struct gspca_dev *gspca_dev, __s32 val); + +const static struct ctrl ov7660_ctrls[] = { +#define GAIN_IDX 1 + { + { + .id = V4L2_CID_GAIN, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "gain", + .minimum = 0x00, + .maximum = 0xff, + .step = 0x1, + .default_value = DEFAULT_GAIN, + .flags = V4L2_CTRL_FLAG_SLIDER + }, + .set = ov7660_set_gain, + .get = ov7660_get_gain + }, +}; static struct v4l2_pix_format ov7660_modes[] = { { @@ -85,6 +104,11 @@ int ov7660_probe(struct sd *sd) return -ENODEV; sensor_found: + sensor_settings = kmalloc( + ARRAY_SIZE(ov7660_ctrls) * sizeof(s32), GFP_KERNEL); + if (!sensor_settings) + return -ENOMEM; + sd->gspca_dev.cam.cam_mode = ov7660_modes; sd->gspca_dev.cam.nmodes = ARRAY_SIZE(ov7660_modes); sd->desc->ctrls = ov7660_ctrls; @@ -100,6 +124,7 @@ sensor_found: int ov7660_init(struct sd *sd) { int i, err = 0; + s32 *sensor_settings = sd->sensor_priv; /* Init the sensor */ for (i = 0; i < ARRAY_SIZE(init_ov7660); i++) { @@ -119,6 +144,10 @@ int ov7660_init(struct sd *sd) if (dump_sensor) ov7660_dump_registers(sd); + err = ov7660_set_gain(&sd->gspca_dev, sensor_settings[GAIN_IDX]); + if (err < 0) + return err; + return err; } @@ -132,7 +161,38 @@ int ov7660_stop(struct sd *sd) return 0; } -void ov7660_disconnect(struct sd *sd) {} +void ov7660_disconnect(struct sd *sd) +{ + ov7660_stop(sd); + + sd->sensor = NULL; + kfree(sd->sensor_priv); +} + +static int ov7660_get_gain(struct gspca_dev *gspca_dev, __s32 *val) +{ + struct sd *sd = (struct sd *) gspca_dev; + s32 *sensor_settings = sd->sensor_priv; + + *val = sensor_settings[GAIN_IDX]; + PDEBUG(D_V4L2, "Read gain %d", *val); + return 0; +} + +static int ov7660_set_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, "Setting gain to %d", val); + + sensor_settings[GAIN_IDX] = val; + + err = m5602_write_sensor(sd, OV7660_GAIN, &i2c_data, 1); + return err; +} static void ov7660_dump_registers(struct sd *sd) { @@ -165,4 +225,3 @@ static void ov7660_dump_registers(struct sd *sd) m5602_write_sensor(sd, address, &old_value, 1); } } - diff --git a/drivers/media/video/gspca/m5602/m5602_ov7660.h b/drivers/media/video/gspca/m5602/m5602_ov7660.h index 15ab706d5dd3..570715fff763 100644 --- a/drivers/media/video/gspca/m5602/m5602_ov7660.h +++ b/drivers/media/video/gspca/m5602/m5602_ov7660.h @@ -179,7 +179,6 @@ static const unsigned char init_ov7660[][4] = {SENSOR, OV7660_AECH, DEFAULT_EXPOSURE}, {SENSOR, OV7660_COM1, 0x00}, - {SENSOR, OV7660_GAIN, DEFAULT_GAIN}, {BRIDGE, M5602_XB_GPIO_DIR, 0x01}, {BRIDGE, M5602_XB_GPIO_DAT, 0x04}, @@ -262,7 +261,6 @@ static const unsigned char init_ov7660[][4] = {SENSOR, OV7660_AECH, 0x20}, {SENSOR, OV7660_COM1, 0x00}, - {SENSOR, OV7660_GAIN, DEFAULT_GAIN}, {SENSOR, OV7660_OFON, 0x0c}, {SENSOR, OV7660_COM2, 0x11}, {SENSOR, OV7660_COM7, 0x05}, |