Commit c5224d81 authored by Jean-François Moine's avatar Jean-François Moine Committed by Mauro Carvalho Chehab

[media] gspca - sn9c20x: Use the new video control mechanism

Signed-off-by: default avatarJean-François Moine <moinejf@free.fr>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 1f42df0d
...@@ -66,10 +66,28 @@ MODULE_LICENSE("GPL"); ...@@ -66,10 +66,28 @@ MODULE_LICENSE("GPL");
#define LED_REVERSE 0x2 /* some cameras unset gpio to turn on leds */ #define LED_REVERSE 0x2 /* some cameras unset gpio to turn on leds */
#define FLIP_DETECT 0x4 #define FLIP_DETECT 0x4
enum e_ctrl {
BRIGHTNESS,
CONTRAST,
SATURATION,
HUE,
GAMMA,
BLUE,
RED,
VFLIP,
HFLIP,
EXPOSURE,
GAIN,
AUTOGAIN,
NCTRLS /* number of controls */
};
/* specific webcam descriptor */ /* specific webcam descriptor */
struct sd { struct sd {
struct gspca_dev gspca_dev; struct gspca_dev gspca_dev;
struct gspca_ctrl ctrls[NCTRLS];
#define MIN_AVG_LUM 80 #define MIN_AVG_LUM 80
#define MAX_AVG_LUM 130 #define MAX_AVG_LUM 130
atomic_t avg_lum; atomic_t avg_lum;
...@@ -77,20 +95,6 @@ struct sd { ...@@ -77,20 +95,6 @@ struct sd {
u8 older_step; u8 older_step;
u8 exposure_step; u8 exposure_step;
u8 brightness;
u8 contrast;
u8 saturation;
s16 hue;
u8 gamma;
u8 red;
u8 blue;
u8 hflip;
u8 vflip;
u8 gain;
u16 exposure;
u8 auto_exposure;
u8 i2c_addr; u8 i2c_addr;
u8 sensor; u8 sensor;
u8 hstart; u8 hstart;
...@@ -112,31 +116,6 @@ struct i2c_reg_u16 { ...@@ -112,31 +116,6 @@ struct i2c_reg_u16 {
u16 val; u16 val;
}; };
static int sd_setbrightness(struct gspca_dev *gspca_dev, s32 val);
static int sd_getbrightness(struct gspca_dev *gspca_dev, s32 *val);
static int sd_setcontrast(struct gspca_dev *gspca_dev, s32 val);
static int sd_getcontrast(struct gspca_dev *gspca_dev, s32 *val);
static int sd_setsaturation(struct gspca_dev *gspca_dev, s32 val);
static int sd_getsaturation(struct gspca_dev *gspca_dev, s32 *val);
static int sd_sethue(struct gspca_dev *gspca_dev, s32 val);
static int sd_gethue(struct gspca_dev *gspca_dev, s32 *val);
static int sd_setgamma(struct gspca_dev *gspca_dev, s32 val);
static int sd_getgamma(struct gspca_dev *gspca_dev, s32 *val);
static int sd_setredbalance(struct gspca_dev *gspca_dev, s32 val);
static int sd_getredbalance(struct gspca_dev *gspca_dev, s32 *val);
static int sd_setbluebalance(struct gspca_dev *gspca_dev, s32 val);
static int sd_getbluebalance(struct gspca_dev *gspca_dev, s32 *val);
static int sd_setvflip(struct gspca_dev *gspca_dev, s32 val);
static int sd_getvflip(struct gspca_dev *gspca_dev, s32 *val);
static int sd_sethflip(struct gspca_dev *gspca_dev, s32 val);
static int sd_gethflip(struct gspca_dev *gspca_dev, s32 *val);
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_setexposure(struct gspca_dev *gspca_dev, s32 val);
static int sd_getexposure(struct gspca_dev *gspca_dev, s32 *val);
static int sd_setautoexposure(struct gspca_dev *gspca_dev, s32 val);
static int sd_getautoexposure(struct gspca_dev *gspca_dev, s32 *val);
static const struct dmi_system_id flip_dmi_table[] = { static const struct dmi_system_id flip_dmi_table[] = {
{ {
.ident = "MSI MS-1034", .ident = "MSI MS-1034",
...@@ -177,9 +156,15 @@ static const struct dmi_system_id flip_dmi_table[] = { ...@@ -177,9 +156,15 @@ static const struct dmi_system_id flip_dmi_table[] = {
{} {}
}; };
static const struct ctrl sd_ctrls[] = { static void set_cmatrix(struct gspca_dev *gspca_dev);
{ static void set_gamma(struct gspca_dev *gspca_dev);
#define BRIGHTNESS_IDX 0 static void set_redblue(struct gspca_dev *gspca_dev);
static void set_hvflip(struct gspca_dev *gspca_dev);
static void set_exposure(struct gspca_dev *gspca_dev);
static void set_gain(struct gspca_dev *gspca_dev);
static const struct ctrl sd_ctrls[NCTRLS] = {
[BRIGHTNESS] = {
{ {
.id = V4L2_CID_BRIGHTNESS, .id = V4L2_CID_BRIGHTNESS,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
...@@ -187,14 +172,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -187,14 +172,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 0xff, .maximum = 0xff,
.step = 1, .step = 1,
#define BRIGHTNESS_DEFAULT 0x7f .default_value = 0x7f
.default_value = BRIGHTNESS_DEFAULT,
}, },
.set = sd_setbrightness, .set_control = set_cmatrix
.get = sd_getbrightness,
}, },
{ [CONTRAST] = {
#define CONTRAST_IDX 1
{ {
.id = V4L2_CID_CONTRAST, .id = V4L2_CID_CONTRAST,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
...@@ -202,14 +184,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -202,14 +184,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 0xff, .maximum = 0xff,
.step = 1, .step = 1,
#define CONTRAST_DEFAULT 0x7f .default_value = 0x7f
.default_value = CONTRAST_DEFAULT,
}, },
.set = sd_setcontrast, .set_control = set_cmatrix
.get = sd_getcontrast,
}, },
{ [SATURATION] = {
#define SATURATION_IDX 2
{ {
.id = V4L2_CID_SATURATION, .id = V4L2_CID_SATURATION,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
...@@ -217,14 +196,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -217,14 +196,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 0xff, .maximum = 0xff,
.step = 1, .step = 1,
#define SATURATION_DEFAULT 0x7f .default_value = 0x7f
.default_value = SATURATION_DEFAULT,
}, },
.set = sd_setsaturation, .set_control = set_cmatrix
.get = sd_getsaturation,
}, },
{ [HUE] = {
#define HUE_IDX 3
{ {
.id = V4L2_CID_HUE, .id = V4L2_CID_HUE,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
...@@ -232,14 +208,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -232,14 +208,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = -180, .minimum = -180,
.maximum = 180, .maximum = 180,
.step = 1, .step = 1,
#define HUE_DEFAULT 0 .default_value = 0
.default_value = HUE_DEFAULT,
}, },
.set = sd_sethue, .set_control = set_cmatrix
.get = sd_gethue,
}, },
{ [GAMMA] = {
#define GAMMA_IDX 4
{ {
.id = V4L2_CID_GAMMA, .id = V4L2_CID_GAMMA,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
...@@ -247,14 +220,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -247,14 +220,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 0xff, .maximum = 0xff,
.step = 1, .step = 1,
#define GAMMA_DEFAULT 0x10 .default_value = 0x10
.default_value = GAMMA_DEFAULT,
}, },
.set = sd_setgamma, .set_control = set_gamma
.get = sd_getgamma,
}, },
{ [BLUE] = {
#define BLUE_IDX 5
{ {
.id = V4L2_CID_BLUE_BALANCE, .id = V4L2_CID_BLUE_BALANCE,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
...@@ -262,14 +232,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -262,14 +232,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 0x7f, .maximum = 0x7f,
.step = 1, .step = 1,
#define BLUE_DEFAULT 0x28 .default_value = 0x28
.default_value = BLUE_DEFAULT,
}, },
.set = sd_setbluebalance, .set_control = set_redblue
.get = sd_getbluebalance,
}, },
{ [RED] = {
#define RED_IDX 6
{ {
.id = V4L2_CID_RED_BALANCE, .id = V4L2_CID_RED_BALANCE,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
...@@ -277,14 +244,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -277,14 +244,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 0x7f, .maximum = 0x7f,
.step = 1, .step = 1,
#define RED_DEFAULT 0x28 .default_value = 0x28
.default_value = RED_DEFAULT,
}, },
.set = sd_setredbalance, .set_control = set_redblue
.get = sd_getredbalance,
}, },
{ [HFLIP] = {
#define HFLIP_IDX 7
{ {
.id = V4L2_CID_HFLIP, .id = V4L2_CID_HFLIP,
.type = V4L2_CTRL_TYPE_BOOLEAN, .type = V4L2_CTRL_TYPE_BOOLEAN,
...@@ -292,14 +256,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -292,14 +256,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 1, .maximum = 1,
.step = 1, .step = 1,
#define HFLIP_DEFAULT 0 .default_value = 0,
.default_value = HFLIP_DEFAULT,
}, },
.set = sd_sethflip, .set_control = set_hvflip
.get = sd_gethflip,
}, },
{ [VFLIP] = {
#define VFLIP_IDX 8
{ {
.id = V4L2_CID_VFLIP, .id = V4L2_CID_VFLIP,
.type = V4L2_CTRL_TYPE_BOOLEAN, .type = V4L2_CTRL_TYPE_BOOLEAN,
...@@ -307,14 +268,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -307,14 +268,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 1, .maximum = 1,
.step = 1, .step = 1,
#define VFLIP_DEFAULT 0 .default_value = 0,
.default_value = VFLIP_DEFAULT,
}, },
.set = sd_setvflip, .set_control = set_hvflip
.get = sd_getvflip,
}, },
{ [EXPOSURE] = {
#define EXPOSURE_IDX 9
{ {
.id = V4L2_CID_EXPOSURE, .id = V4L2_CID_EXPOSURE,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
...@@ -322,14 +280,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -322,14 +280,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 0x1780, .maximum = 0x1780,
.step = 1, .step = 1,
#define EXPOSURE_DEFAULT 0x33 .default_value = 0x33,
.default_value = EXPOSURE_DEFAULT,
}, },
.set = sd_setexposure, .set_control = set_exposure
.get = sd_getexposure,
}, },
{ [GAIN] = {
#define GAIN_IDX 10
{ {
.id = V4L2_CID_GAIN, .id = V4L2_CID_GAIN,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
...@@ -337,14 +292,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -337,14 +292,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 28, .maximum = 28,
.step = 1, .step = 1,
#define GAIN_DEFAULT 0x00 .default_value = 0,
.default_value = GAIN_DEFAULT,
}, },
.set = sd_setgain, .set_control = set_gain
.get = sd_getgain,
}, },
{ [AUTOGAIN] = {
#define AUTOGAIN_IDX 11
{ {
.id = V4L2_CID_AUTOGAIN, .id = V4L2_CID_AUTOGAIN,
.type = V4L2_CTRL_TYPE_BOOLEAN, .type = V4L2_CTRL_TYPE_BOOLEAN,
...@@ -352,11 +304,8 @@ static const struct ctrl sd_ctrls[] = { ...@@ -352,11 +304,8 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 1, .maximum = 1,
.step = 1, .step = 1,
#define AUTO_EXPOSURE_DEFAULT 1 .default_value = 1,
.default_value = AUTO_EXPOSURE_DEFAULT,
}, },
.set = sd_setautoexposure,
.get = sd_getautoexposure,
}, },
}; };
...@@ -1306,7 +1255,7 @@ static int ov9655_init_sensor(struct gspca_dev *gspca_dev) ...@@ -1306,7 +1255,7 @@ static int ov9655_init_sensor(struct gspca_dev *gspca_dev)
} }
} }
/* disable hflip and vflip */ /* disable hflip and vflip */
gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX); gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP);
sd->hstart = 1; sd->hstart = 1;
sd->vstart = 2; sd->vstart = 2;
return 0; return 0;
...@@ -1325,8 +1274,8 @@ static int soi968_init_sensor(struct gspca_dev *gspca_dev) ...@@ -1325,8 +1274,8 @@ static int soi968_init_sensor(struct gspca_dev *gspca_dev)
} }
} }
/* disable hflip and vflip */ /* disable hflip and vflip */
gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX) gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP)
| (1 << EXPOSURE_IDX); | (1 << EXPOSURE);
sd->hstart = 60; sd->hstart = 60;
sd->vstart = 11; sd->vstart = 11;
return 0; return 0;
...@@ -1362,7 +1311,7 @@ static int ov7670_init_sensor(struct gspca_dev *gspca_dev) ...@@ -1362,7 +1311,7 @@ static int ov7670_init_sensor(struct gspca_dev *gspca_dev)
} }
} }
/* disable hflip and vflip */ /* disable hflip and vflip */
gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX); gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP);
sd->hstart = 0; sd->hstart = 0;
sd->vstart = 1; sd->vstart = 1;
return 0; return 0;
...@@ -1403,9 +1352,9 @@ static int mt9v_init_sensor(struct gspca_dev *gspca_dev) ...@@ -1403,9 +1352,9 @@ static int mt9v_init_sensor(struct gspca_dev *gspca_dev)
return -ENODEV; return -ENODEV;
} }
} }
gspca_dev->ctrl_dis = (1 << EXPOSURE_IDX) gspca_dev->ctrl_dis = (1 << EXPOSURE)
| (1 << AUTOGAIN_IDX) | (1 << AUTOGAIN)
| (1 << GAIN_IDX); | (1 << GAIN);
sd->hstart = 2; sd->hstart = 2;
sd->vstart = 2; sd->vstart = 2;
sd->sensor = SENSOR_MT9V111; sd->sensor = SENSOR_MT9V111;
...@@ -1449,8 +1398,8 @@ static int mt9m112_init_sensor(struct gspca_dev *gspca_dev) ...@@ -1449,8 +1398,8 @@ static int mt9m112_init_sensor(struct gspca_dev *gspca_dev)
return -ENODEV; return -ENODEV;
} }
} }
gspca_dev->ctrl_dis = (1 << EXPOSURE_IDX) | (1 << AUTOGAIN_IDX) gspca_dev->ctrl_dis = (1 << EXPOSURE) | (1 << AUTOGAIN)
| (1 << GAIN_IDX); | (1 << GAIN);
sd->hstart = 0; sd->hstart = 0;
sd->vstart = 2; sd->vstart = 2;
return 0; return 0;
...@@ -1467,8 +1416,8 @@ static int mt9m111_init_sensor(struct gspca_dev *gspca_dev) ...@@ -1467,8 +1416,8 @@ static int mt9m111_init_sensor(struct gspca_dev *gspca_dev)
return -ENODEV; return -ENODEV;
} }
} }
gspca_dev->ctrl_dis = (1 << EXPOSURE_IDX) | (1 << AUTOGAIN_IDX) gspca_dev->ctrl_dis = (1 << EXPOSURE) | (1 << AUTOGAIN)
| (1 << GAIN_IDX); | (1 << GAIN);
sd->hstart = 0; sd->hstart = 0;
sd->vstart = 2; sd->vstart = 2;
return 0; return 0;
...@@ -1505,7 +1454,7 @@ static int mt9m001_init_sensor(struct gspca_dev *gspca_dev) ...@@ -1505,7 +1454,7 @@ static int mt9m001_init_sensor(struct gspca_dev *gspca_dev)
} }
} }
/* disable hflip and vflip */ /* disable hflip and vflip */
gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX); gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP);
sd->hstart = 1; sd->hstart = 1;
sd->vstart = 1; sd->vstart = 1;
return 0; return 0;
...@@ -1528,51 +1477,52 @@ static int hv7131r_init_sensor(struct gspca_dev *gspca_dev) ...@@ -1528,51 +1477,52 @@ static int hv7131r_init_sensor(struct gspca_dev *gspca_dev)
return 0; return 0;
} }
static int set_cmatrix(struct gspca_dev *gspca_dev) static void set_cmatrix(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
s32 hue_coord, hue_index = 180 + sd->hue; int satur;
s32 hue_coord, hue_index = 180 + sd->ctrls[HUE].val;
u8 cmatrix[21]; u8 cmatrix[21];
memset(cmatrix, 0, sizeof cmatrix); memset(cmatrix, 0, sizeof cmatrix);
cmatrix[2] = (sd->contrast * 0x25 / 0x100) + 0x26; cmatrix[2] = (sd->ctrls[CONTRAST].val * 0x25 / 0x100) + 0x26;
cmatrix[0] = 0x13 + (cmatrix[2] - 0x26) * 0x13 / 0x25; cmatrix[0] = 0x13 + (cmatrix[2] - 0x26) * 0x13 / 0x25;
cmatrix[4] = 0x07 + (cmatrix[2] - 0x26) * 0x07 / 0x25; cmatrix[4] = 0x07 + (cmatrix[2] - 0x26) * 0x07 / 0x25;
cmatrix[18] = sd->brightness - 0x80; cmatrix[18] = sd->ctrls[BRIGHTNESS].val - 0x80;
hue_coord = (hsv_red_x[hue_index] * sd->saturation) >> 8; satur = sd->ctrls[SATURATION].val;
hue_coord = (hsv_red_x[hue_index] * satur) >> 8;
cmatrix[6] = hue_coord; cmatrix[6] = hue_coord;
cmatrix[7] = (hue_coord >> 8) & 0x0f; cmatrix[7] = (hue_coord >> 8) & 0x0f;
hue_coord = (hsv_red_y[hue_index] * sd->saturation) >> 8; hue_coord = (hsv_red_y[hue_index] * satur) >> 8;
cmatrix[8] = hue_coord; cmatrix[8] = hue_coord;
cmatrix[9] = (hue_coord >> 8) & 0x0f; cmatrix[9] = (hue_coord >> 8) & 0x0f;
hue_coord = (hsv_green_x[hue_index] * sd->saturation) >> 8; hue_coord = (hsv_green_x[hue_index] * satur) >> 8;
cmatrix[10] = hue_coord; cmatrix[10] = hue_coord;
cmatrix[11] = (hue_coord >> 8) & 0x0f; cmatrix[11] = (hue_coord >> 8) & 0x0f;
hue_coord = (hsv_green_y[hue_index] * sd->saturation) >> 8; hue_coord = (hsv_green_y[hue_index] * satur) >> 8;
cmatrix[12] = hue_coord; cmatrix[12] = hue_coord;
cmatrix[13] = (hue_coord >> 8) & 0x0f; cmatrix[13] = (hue_coord >> 8) & 0x0f;
hue_coord = (hsv_blue_x[hue_index] * sd->saturation) >> 8; hue_coord = (hsv_blue_x[hue_index] * satur) >> 8;
cmatrix[14] = hue_coord; cmatrix[14] = hue_coord;
cmatrix[15] = (hue_coord >> 8) & 0x0f; cmatrix[15] = (hue_coord >> 8) & 0x0f;
hue_coord = (hsv_blue_y[hue_index] * sd->saturation) >> 8; hue_coord = (hsv_blue_y[hue_index] * satur) >> 8;
cmatrix[16] = hue_coord; cmatrix[16] = hue_coord;
cmatrix[17] = (hue_coord >> 8) & 0x0f; cmatrix[17] = (hue_coord >> 8) & 0x0f;
return reg_w(gspca_dev, 0x10e1, cmatrix, 21); reg_w(gspca_dev, 0x10e1, cmatrix, 21);
} }
static int set_gamma(struct gspca_dev *gspca_dev) static void set_gamma(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
u8 gamma[17]; u8 gamma[17];
u8 gval = sd->gamma * 0xb8 / 0x100; u8 gval = sd->ctrls[GAMMA].val * 0xb8 / 0x100;
gamma[0] = 0x0a; gamma[0] = 0x0a;
gamma[1] = 0x13 + (gval * (0xcb - 0x13) / 0xb8); gamma[1] = 0x13 + (gval * (0xcb - 0x13) / 0xb8);
...@@ -1592,29 +1542,29 @@ static int set_gamma(struct gspca_dev *gspca_dev) ...@@ -1592,29 +1542,29 @@ static int set_gamma(struct gspca_dev *gspca_dev)
gamma[15] = 0xea + (gval * (0xf9 - 0xea) / 0xb8); gamma[15] = 0xea + (gval * (0xf9 - 0xea) / 0xb8);
gamma[16] = 0xf5; gamma[16] = 0xf5;
return reg_w(gspca_dev, 0x1190, gamma, 17); reg_w(gspca_dev, 0x1190, gamma, 17);
} }
static int set_redblue(struct gspca_dev *gspca_dev) static void set_redblue(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
reg_w1(gspca_dev, 0x118c, sd->red);
reg_w1(gspca_dev, 0x118f, sd->blue); reg_w1(gspca_dev, 0x118c, sd->ctrls[RED].val);
return 0; reg_w1(gspca_dev, 0x118f, sd->ctrls[BLUE].val);
} }
static int set_hvflip(struct gspca_dev *gspca_dev) static void set_hvflip(struct gspca_dev *gspca_dev)
{ {
u8 value, tslb, hflip, vflip; u8 value, tslb, hflip, vflip;
u16 value2; u16 value2;
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
if ((sd->flags & FLIP_DETECT) && dmi_check_system(flip_dmi_table)) { if ((sd->flags & FLIP_DETECT) && dmi_check_system(flip_dmi_table)) {
hflip = !sd->hflip; hflip = !sd->ctrls[HFLIP].val;
vflip = !sd->vflip; vflip = !sd->ctrls[VFLIP].val;
} else { } else {
hflip = sd->hflip; hflip = sd->ctrls[HFLIP].val;
vflip = sd->vflip; vflip = sd->ctrls[VFLIP].val;
} }
switch (sd->sensor) { switch (sd->sensor) {
...@@ -1674,13 +1624,15 @@ static int set_hvflip(struct gspca_dev *gspca_dev) ...@@ -1674,13 +1624,15 @@ static int set_hvflip(struct gspca_dev *gspca_dev)
i2c_w1(gspca_dev, 0x01, value); i2c_w1(gspca_dev, 0x01, value);
break; break;
} }
return 0;
} }
static int set_exposure(struct gspca_dev *gspca_dev) static void set_exposure(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
u8 exp[8] = {0x81, sd->i2c_addr, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e}; u8 exp[8] = {0x81, sd->i2c_addr, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e};
int expo;
expo = sd->ctrls[EXPOSURE].val;
switch (sd->sensor) { switch (sd->sensor) {
case SENSOR_OV7660: case SENSOR_OV7660:
case SENSOR_OV7670: case SENSOR_OV7670:
...@@ -1688,35 +1640,37 @@ static int set_exposure(struct gspca_dev *gspca_dev) ...@@ -1688,35 +1640,37 @@ static int set_exposure(struct gspca_dev *gspca_dev)
case SENSOR_OV9650: case SENSOR_OV9650:
exp[0] |= (3 << 4); exp[0] |= (3 << 4);
exp[2] = 0x2d; exp[2] = 0x2d;
exp[3] = sd->exposure & 0xff; exp[3] = expo;
exp[4] = sd->exposure >> 8; exp[4] = expo >> 8;
break; break;
case SENSOR_MT9M001: case SENSOR_MT9M001:
case SENSOR_MT9V112: case SENSOR_MT9V112:
case SENSOR_MT9V011: case SENSOR_MT9V011:
exp[0] |= (3 << 4); exp[0] |= (3 << 4);
exp[2] = 0x09; exp[2] = 0x09;
exp[3] = sd->exposure >> 8; exp[3] = expo >> 8;
exp[4] = sd->exposure & 0xff; exp[4] = expo;
break; break;
case SENSOR_HV7131R: case SENSOR_HV7131R:
exp[0] |= (4 << 4); exp[0] |= (4 << 4);
exp[2] = 0x25; exp[2] = 0x25;
exp[3] = (sd->exposure >> 5) & 0xff; exp[3] = expo >> 5;
exp[4] = (sd->exposure << 3) & 0xff; exp[4] = expo << 3;
exp[5] = 0; exp[5] = 0;
break; break;
default: default:
return 0; return;
} }
i2c_w(gspca_dev, exp); i2c_w(gspca_dev, exp);
return 0;
} }
static int set_gain(struct gspca_dev *gspca_dev) static void set_gain(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
u8 gain[8] = {0x81, sd->i2c_addr, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d}; u8 gain[8] = {0x81, sd->i2c_addr, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d};
int g;
g = sd->ctrls[GAIN].val;
switch (sd->sensor) { switch (sd->sensor) {
case SENSOR_OV7660: case SENSOR_OV7660:
case SENSOR_OV7670: case SENSOR_OV7670:
...@@ -1724,238 +1678,35 @@ static int set_gain(struct gspca_dev *gspca_dev) ...@@ -1724,238 +1678,35 @@ static int set_gain(struct gspca_dev *gspca_dev)
case SENSOR_OV9655: case SENSOR_OV9655:
case SENSOR_OV9650: case SENSOR_OV9650:
gain[0] |= (2 << 4); gain[0] |= (2 << 4);
gain[3] = ov_gain[sd->gain]; gain[3] = ov_gain[g];
break; break;
case SENSOR_MT9V011: case SENSOR_MT9V011:
gain[0] |= (3 << 4); gain[0] |= (3 << 4);
gain[2] = 0x35; gain[2] = 0x35;
gain[3] = micron1_gain[sd->gain] >> 8; gain[3] = micron1_gain[g] >> 8;
gain[4] = micron1_gain[sd->gain] & 0xff; gain[4] = micron1_gain[g];
break; break;
case SENSOR_MT9V112: case SENSOR_MT9V112:
gain[0] |= (3 << 4); gain[0] |= (3 << 4);
gain[2] = 0x2f; gain[2] = 0x2f;
gain[3] = micron1_gain[sd->gain] >> 8; gain[3] = micron1_gain[g] >> 8;
gain[4] = micron1_gain[sd->gain] & 0xff; gain[4] = micron1_gain[g];
break; break;
case SENSOR_MT9M001: case SENSOR_MT9M001:
gain[0] |= (3 << 4); gain[0] |= (3 << 4);
gain[2] = 0x2f; gain[2] = 0x2f;
gain[3] = micron2_gain[sd->gain] >> 8; gain[3] = micron2_gain[g] >> 8;
gain[4] = micron2_gain[sd->gain] & 0xff; gain[4] = micron2_gain[g];
break; break;
case SENSOR_HV7131R: case SENSOR_HV7131R:
gain[0] |= (2 << 4); gain[0] |= (2 << 4);
gain[2] = 0x30; gain[2] = 0x30;
gain[3] = hv7131r_gain[sd->gain]; gain[3] = hv7131r_gain[g];
break; break;
default: default:
return 0; return;
} }
i2c_w(gspca_dev, gain); i2c_w(gspca_dev, gain);
return 0;
}
static int sd_setbrightness(struct gspca_dev *gspca_dev, s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->brightness = val;
if (gspca_dev->streaming)
return set_cmatrix(gspca_dev);
return 0;
}
static int sd_getbrightness(struct gspca_dev *gspca_dev, s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->brightness;
return 0;
}
static int sd_setcontrast(struct gspca_dev *gspca_dev, s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->contrast = val;
if (gspca_dev->streaming)
return set_cmatrix(gspca_dev);
return 0;
}
static int sd_getcontrast(struct gspca_dev *gspca_dev, s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->contrast;
return 0;
}
static int sd_setsaturation(struct gspca_dev *gspca_dev, s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->saturation = val;
if (gspca_dev->streaming)
return set_cmatrix(gspca_dev);
return 0;
}
static int sd_getsaturation(struct gspca_dev *gspca_dev, s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->saturation;
return 0;
}
static int sd_sethue(struct gspca_dev *gspca_dev, s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->hue = val;
if (gspca_dev->streaming)
return set_cmatrix(gspca_dev);
return 0;
}
static int sd_gethue(struct gspca_dev *gspca_dev, s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->hue;
return 0;
}
static int sd_setgamma(struct gspca_dev *gspca_dev, s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->gamma = val;
if (gspca_dev->streaming)
return set_gamma(gspca_dev);
return 0;
}
static int sd_getgamma(struct gspca_dev *gspca_dev, s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->gamma;
return 0;
}
static int sd_setredbalance(struct gspca_dev *gspca_dev, s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->red = val;
if (gspca_dev->streaming)
return set_redblue(gspca_dev);
return 0;
}
static int sd_getredbalance(struct gspca_dev *gspca_dev, s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->red;
return 0;
}
static int sd_setbluebalance(struct gspca_dev *gspca_dev, s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->blue = val;
if (gspca_dev->streaming)
return set_redblue(gspca_dev);
return 0;
}
static int sd_getbluebalance(struct gspca_dev *gspca_dev, s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->blue;
return 0;
}
static int sd_sethflip(struct gspca_dev *gspca_dev, s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->hflip = val;
if (gspca_dev->streaming)
return set_hvflip(gspca_dev);
return 0;
}
static int sd_gethflip(struct gspca_dev *gspca_dev, s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->hflip;
return 0;
}
static int sd_setvflip(struct gspca_dev *gspca_dev, s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->vflip = val;
if (gspca_dev->streaming)
return set_hvflip(gspca_dev);
return 0;
}
static int sd_getvflip(struct gspca_dev *gspca_dev, s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->vflip;
return 0;
}
static int sd_setexposure(struct gspca_dev *gspca_dev, s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->exposure = val;
if (gspca_dev->streaming)
return set_exposure(gspca_dev);
return 0;
}
static int sd_getexposure(struct gspca_dev *gspca_dev, s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->exposure;
return 0;
}
static int sd_setgain(struct gspca_dev *gspca_dev, s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->gain = val;
if (gspca_dev->streaming)
return set_gain(gspca_dev);
return 0;
}
static int sd_getgain(struct gspca_dev *gspca_dev, s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->gain;
return 0;
}
static int sd_setautoexposure(struct gspca_dev *gspca_dev, s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->auto_exposure = val;
return 0;
}
static int sd_getautoexposure(struct gspca_dev *gspca_dev, s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->auto_exposure;
return 0;
} }
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
...@@ -2076,19 +1827,7 @@ static int sd_config(struct gspca_dev *gspca_dev, ...@@ -2076,19 +1827,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
sd->older_step = 0; sd->older_step = 0;
sd->exposure_step = 16; sd->exposure_step = 16;
sd->brightness = BRIGHTNESS_DEFAULT; gspca_dev->cam.ctrls = sd->ctrls;
sd->contrast = CONTRAST_DEFAULT;
sd->saturation = SATURATION_DEFAULT;
sd->hue = HUE_DEFAULT;
sd->gamma = GAMMA_DEFAULT;
sd->red = RED_DEFAULT;
sd->blue = BLUE_DEFAULT;
sd->hflip = HFLIP_DEFAULT;
sd->vflip = VFLIP_DEFAULT;
sd->exposure = EXPOSURE_DEFAULT;
sd->gain = GAIN_DEFAULT;
sd->auto_exposure = AUTO_EXPOSURE_DEFAULT;
sd->quality = 95; sd->quality = 95;
...@@ -2359,15 +2098,15 @@ static void do_autoexposure(struct gspca_dev *gspca_dev, u16 avg_lum) ...@@ -2359,15 +2098,15 @@ static void do_autoexposure(struct gspca_dev *gspca_dev, u16 avg_lum)
* and exposure steps * and exposure steps
*/ */
if (avg_lum < MIN_AVG_LUM) { if (avg_lum < MIN_AVG_LUM) {
if (sd->exposure > 0x1770) if (sd->ctrls[EXPOSURE].val > 0x1770)
return; return;
new_exp = sd->exposure + sd->exposure_step; new_exp = sd->ctrls[EXPOSURE].val + sd->exposure_step;
if (new_exp > 0x1770) if (new_exp > 0x1770)
new_exp = 0x1770; new_exp = 0x1770;
if (new_exp < 0x10) if (new_exp < 0x10)
new_exp = 0x10; new_exp = 0x10;
sd->exposure = new_exp; sd->ctrls[EXPOSURE].val = new_exp;
set_exposure(gspca_dev); set_exposure(gspca_dev);
sd->older_step = sd->old_step; sd->older_step = sd->old_step;
...@@ -2379,14 +2118,14 @@ static void do_autoexposure(struct gspca_dev *gspca_dev, u16 avg_lum) ...@@ -2379,14 +2118,14 @@ static void do_autoexposure(struct gspca_dev *gspca_dev, u16 avg_lum)
sd->exposure_step += 2; sd->exposure_step += 2;
} }
if (avg_lum > MAX_AVG_LUM) { if (avg_lum > MAX_AVG_LUM) {
if (sd->exposure < 0x10) if (sd->ctrls[EXPOSURE].val < 0x10)
return; return;
new_exp = sd->exposure - sd->exposure_step; new_exp = sd->ctrls[EXPOSURE].val - sd->exposure_step;
if (new_exp > 0x1700) if (new_exp > 0x1700)
new_exp = 0x1770; new_exp = 0x1770;
if (new_exp < 0x10) if (new_exp < 0x10)
new_exp = 0x10; new_exp = 0x10;
sd->exposure = new_exp; sd->ctrls[EXPOSURE].val = new_exp;
set_exposure(gspca_dev); set_exposure(gspca_dev);
sd->older_step = sd->old_step; sd->older_step = sd->old_step;
sd->old_step = 0; sd->old_step = 0;
...@@ -2403,14 +2142,14 @@ static void do_autogain(struct gspca_dev *gspca_dev, u16 avg_lum) ...@@ -2403,14 +2142,14 @@ static void do_autogain(struct gspca_dev *gspca_dev, u16 avg_lum)
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
if (avg_lum < MIN_AVG_LUM) { if (avg_lum < MIN_AVG_LUM) {
if (sd->gain + 1 <= 28) { if (sd->ctrls[GAIN].val + 1 <= 28) {
sd->gain++; sd->ctrls[GAIN].val++;
set_gain(gspca_dev); set_gain(gspca_dev);
} }
} }
if (avg_lum > MAX_AVG_LUM) { if (avg_lum > MAX_AVG_LUM) {
if (sd->gain > 0) { if (sd->ctrls[GAIN].val > 0) {
sd->gain--; sd->ctrls[GAIN].val--;
set_gain(gspca_dev); set_gain(gspca_dev);
} }
} }
...@@ -2421,7 +2160,7 @@ static void sd_dqcallback(struct gspca_dev *gspca_dev) ...@@ -2421,7 +2160,7 @@ static void sd_dqcallback(struct gspca_dev *gspca_dev)
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
int avg_lum; int avg_lum;
if (!sd->auto_exposure) if (!sd->ctrls[AUTOGAIN].val)
return; return;
avg_lum = atomic_read(&sd->avg_lum); avg_lum = atomic_read(&sd->avg_lum);
......
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