Commit 8b7fbda4 authored by Max Thrun's avatar Max Thrun Committed by Mauro Carvalho Chehab

V4L/DVB: gspca - ov534: Fix autogain control, enable it by default

* Use 'agc' instead of 'autogain' in the code so to align the naming
    as in AEC/AWB.
  * Tweak brightness and contrast default values.
  * Fix setting/resetting registers values for AGC.
  * Set actual gain back when disabling AGC.
  * Skip setting GAIN register when AGC is enabled.
  * Enable AGC by default.

Note that as Auto Gain Control is now enabled by default, if you are
using the driver for visual computing applications you might need to
disable it explicitly in your software.
Signed-off-by: default avatarMax Thrun <bear24rw@gmail.com>
Signed-off-by: default avatarAntonio Ospite <ospite@studenti.unina.it>
Signed-off-by: default avatarJean-François Moine <moinejf@free.fr>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 0c41acf1
...@@ -60,7 +60,7 @@ struct sd { ...@@ -60,7 +60,7 @@ struct sd {
u8 contrast; u8 contrast;
u8 gain; u8 gain;
u8 exposure; u8 exposure;
u8 autogain; u8 agc;
u8 awb; u8 awb;
s8 sharpness; s8 sharpness;
u8 hflip; u8 hflip;
...@@ -73,8 +73,8 @@ static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val); ...@@ -73,8 +73,8 @@ static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val); static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
...@@ -97,7 +97,7 @@ static const struct ctrl sd_ctrls[] = { ...@@ -97,7 +97,7 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 255, .maximum = 255,
.step = 1, .step = 1,
#define BRIGHTNESS_DEF 20 #define BRIGHTNESS_DEF 0
.default_value = BRIGHTNESS_DEF, .default_value = BRIGHTNESS_DEF,
}, },
.set = sd_setbrightness, .set = sd_setbrightness,
...@@ -111,7 +111,7 @@ static const struct ctrl sd_ctrls[] = { ...@@ -111,7 +111,7 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 255, .maximum = 255,
.step = 1, .step = 1,
#define CONTRAST_DEF 37 #define CONTRAST_DEF 32
.default_value = CONTRAST_DEF, .default_value = CONTRAST_DEF,
}, },
.set = sd_setcontrast, .set = sd_setcontrast,
...@@ -149,15 +149,15 @@ static const struct ctrl sd_ctrls[] = { ...@@ -149,15 +149,15 @@ static const struct ctrl sd_ctrls[] = {
{ {
.id = V4L2_CID_AUTOGAIN, .id = V4L2_CID_AUTOGAIN,
.type = V4L2_CTRL_TYPE_BOOLEAN, .type = V4L2_CTRL_TYPE_BOOLEAN,
.name = "Autogain", .name = "Auto Gain",
.minimum = 0, .minimum = 0,
.maximum = 1, .maximum = 1,
.step = 1, .step = 1,
#define AUTOGAIN_DEF 0 #define AGC_DEF 1
.default_value = AUTOGAIN_DEF, .default_value = AGC_DEF,
}, },
.set = sd_setautogain, .set = sd_setagc,
.get = sd_getautogain, .get = sd_getagc,
}, },
#define AWB_IDX 5 #define AWB_IDX 5
{ /* 5 */ { /* 5 */
...@@ -639,6 +639,9 @@ static void setgain(struct gspca_dev *gspca_dev) ...@@ -639,6 +639,9 @@ static void setgain(struct gspca_dev *gspca_dev)
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
u8 val; u8 val;
if (sd->agc)
return;
val = sd->gain; val = sd->gain;
switch (val & 0x30) { switch (val & 0x30) {
case 0x00: case 0x00:
...@@ -671,18 +674,22 @@ static void setexposure(struct gspca_dev *gspca_dev) ...@@ -671,18 +674,22 @@ static void setexposure(struct gspca_dev *gspca_dev)
sccb_reg_write(gspca_dev, 0x10, val << 1); sccb_reg_write(gspca_dev, 0x10, val << 1);
} }
static void setautogain(struct gspca_dev *gspca_dev) static void setagc(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
if (sd->autogain) { if (sd->agc) {
sccb_reg_write(gspca_dev, 0x13, 0xf7); /* AGC,AEC,AWB ON */ sccb_reg_write(gspca_dev, 0x13,
sccb_reg_read(gspca_dev, 0x13) | 0x04);
sccb_reg_write(gspca_dev, 0x64, sccb_reg_write(gspca_dev, 0x64,
sccb_reg_read(gspca_dev, 0x64) | 0x03); sccb_reg_read(gspca_dev, 0x64) | 0x03);
} else { } else {
sccb_reg_write(gspca_dev, 0x13, 0xf0); /* AGC,AEC,AWB OFF */ sccb_reg_write(gspca_dev, 0x13,
sccb_reg_read(gspca_dev, 0x13) & ~0x04);
sccb_reg_write(gspca_dev, 0x64, sccb_reg_write(gspca_dev, 0x64,
sccb_reg_read(gspca_dev, 0x64) & 0xfc); sccb_reg_read(gspca_dev, 0x64) & ~0x03);
setgain(gspca_dev);
} }
} }
...@@ -753,8 +760,8 @@ static int sd_config(struct gspca_dev *gspca_dev, ...@@ -753,8 +760,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
sd->contrast = CONTRAST_DEF; sd->contrast = CONTRAST_DEF;
sd->gain = GAIN_DEF; sd->gain = GAIN_DEF;
sd->exposure = EXPO_DEF; sd->exposure = EXPO_DEF;
#if AUTOGAIN_DEF != 0 #if AGC_DEF != 0
sd->autogain = AUTOGAIN_DEF; sd->agc = AGC_DEF;
#else #else
gspca_dev->ctrl_inac |= (1 << AWB_IDX); gspca_dev->ctrl_inac |= (1 << AWB_IDX);
#endif #endif
...@@ -829,7 +836,7 @@ static int sd_start(struct gspca_dev *gspca_dev) ...@@ -829,7 +836,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
} }
set_frame_rate(gspca_dev); set_frame_rate(gspca_dev);
setautogain(gspca_dev); setagc(gspca_dev);
setawb(gspca_dev); setawb(gspca_dev);
setgain(gspca_dev); setgain(gspca_dev);
setexposure(gspca_dev); setexposure(gspca_dev);
...@@ -1014,11 +1021,11 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) ...@@ -1014,11 +1021,11 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
return 0; return 0;
} }
static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
sd->autogain = val; sd->agc = val;
if (gspca_dev->streaming) { if (gspca_dev->streaming) {
...@@ -1028,16 +1035,16 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) ...@@ -1028,16 +1035,16 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
gspca_dev->ctrl_inac &= ~(1 << AWB_IDX); gspca_dev->ctrl_inac &= ~(1 << AWB_IDX);
else else
gspca_dev->ctrl_inac |= (1 << AWB_IDX); gspca_dev->ctrl_inac |= (1 << AWB_IDX);
setautogain(gspca_dev); setagc(gspca_dev);
} }
return 0; return 0;
} }
static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
*val = sd->autogain; *val = sd->agc;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment