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

Signed-off-by: Jean-François Moine <moinejf@free.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Jean-François Moine 2010-10-02 04:17:38 -03:00 committed by Mauro Carvalho Chehab
parent 6a33091f13
commit 016f236227
1 changed files with 36 additions and 116 deletions

View File

@ -27,14 +27,21 @@ MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
MODULE_DESCRIPTION("Syntek DV4000 (STK014) USB Camera Driver"); MODULE_DESCRIPTION("Syntek DV4000 (STK014) USB Camera Driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
/* controls */
enum e_ctrl {
BRIGHTNESS,
CONTRAST,
COLORS,
LIGHTFREQ,
NCTRLS /* number of controls */
};
/* specific webcam descriptor */ /* specific webcam descriptor */
struct sd { struct sd {
struct gspca_dev gspca_dev; /* !! must be the first item */ struct gspca_dev gspca_dev; /* !! must be the first item */
unsigned char brightness; struct gspca_ctrl ctrls[NCTRLS];
unsigned char contrast;
unsigned char colors;
unsigned char lightfreq;
u8 quality; u8 quality;
#define QUALITY_MIN 70 #define QUALITY_MIN 70
#define QUALITY_MAX 95 #define QUALITY_MAX 95
@ -44,17 +51,13 @@ struct sd {
}; };
/* V4L2 controls supported by the driver */ /* V4L2 controls supported by the driver */
static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); static void setbrightness(struct gspca_dev *gspca_dev);
static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); static void setcontrast(struct gspca_dev *gspca_dev);
static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); static void setcolors(struct gspca_dev *gspca_dev);
static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); static void setlightfreq(struct gspca_dev *gspca_dev);
static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
static const struct ctrl sd_ctrls[] = { 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,
@ -62,13 +65,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 255, .maximum = 255,
.step = 1, .step = 1,
#define BRIGHTNESS_DEF 127 .default_value = 127,
.default_value = BRIGHTNESS_DEF,
}, },
.set = sd_setbrightness, .set_control = setbrightness
.get = sd_getbrightness,
}, },
{ [CONTRAST] = {
{ {
.id = V4L2_CID_CONTRAST, .id = V4L2_CID_CONTRAST,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
@ -76,13 +77,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 255, .maximum = 255,
.step = 1, .step = 1,
#define CONTRAST_DEF 127 .default_value = 127,
.default_value = CONTRAST_DEF,
}, },
.set = sd_setcontrast, .set_control = setcontrast
.get = sd_getcontrast,
}, },
{ [COLORS] = {
{ {
.id = V4L2_CID_SATURATION, .id = V4L2_CID_SATURATION,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
@ -90,13 +89,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 255, .maximum = 255,
.step = 1, .step = 1,
#define COLOR_DEF 127 .default_value = 127,
.default_value = COLOR_DEF,
}, },
.set = sd_setcolors, .set_control = setcolors
.get = sd_getcolors,
}, },
{ [LIGHTFREQ] = {
{ {
.id = V4L2_CID_POWER_LINE_FREQUENCY, .id = V4L2_CID_POWER_LINE_FREQUENCY,
.type = V4L2_CTRL_TYPE_MENU, .type = V4L2_CTRL_TYPE_MENU,
@ -104,11 +101,9 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 1, .minimum = 1,
.maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
.step = 1, .step = 1,
#define FREQ_DEF 1 .default_value = 1,
.default_value = FREQ_DEF,
}, },
.set = sd_setfreq, .set_control = setlightfreq
.get = sd_getfreq,
}, },
}; };
@ -264,7 +259,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
int parval; int parval;
parval = 0x06000000 /* whiteness */ parval = 0x06000000 /* whiteness */
+ (sd->brightness << 16); + (sd->ctrls[BRIGHTNESS].val << 16);
set_par(gspca_dev, parval); set_par(gspca_dev, parval);
} }
@ -274,7 +269,7 @@ static void setcontrast(struct gspca_dev *gspca_dev)
int parval; int parval;
parval = 0x07000000 /* contrast */ parval = 0x07000000 /* contrast */
+ (sd->contrast << 16); + (sd->ctrls[CONTRAST].val << 16);
set_par(gspca_dev, parval); set_par(gspca_dev, parval);
} }
@ -284,15 +279,15 @@ static void setcolors(struct gspca_dev *gspca_dev)
int parval; int parval;
parval = 0x08000000 /* saturation */ parval = 0x08000000 /* saturation */
+ (sd->colors << 16); + (sd->ctrls[COLORS].val << 16);
set_par(gspca_dev, parval); set_par(gspca_dev, parval);
} }
static void setfreq(struct gspca_dev *gspca_dev) static void setlightfreq(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
set_par(gspca_dev, sd->lightfreq == 1 set_par(gspca_dev, sd->ctrls[LIGHTFREQ].val == 1
? 0x33640000 /* 50 Hz */ ? 0x33640000 /* 50 Hz */
: 0x33780000); /* 60 Hz */ : 0x33780000); /* 60 Hz */
} }
@ -305,10 +300,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
gspca_dev->cam.cam_mode = vga_mode; gspca_dev->cam.cam_mode = vga_mode;
gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode); gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode);
sd->brightness = BRIGHTNESS_DEF; gspca_dev->cam.ctrls = sd->ctrls;
sd->contrast = CONTRAST_DEF;
sd->colors = COLOR_DEF;
sd->lightfreq = FREQ_DEF;
sd->quality = QUALITY_DEF; sd->quality = QUALITY_DEF;
return 0; return 0;
} }
@ -378,7 +370,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
set_par(gspca_dev, 0x0a800000); /* Green ? */ set_par(gspca_dev, 0x0a800000); /* Green ? */
set_par(gspca_dev, 0x0b800000); /* Blue ? */ set_par(gspca_dev, 0x0b800000); /* Blue ? */
set_par(gspca_dev, 0x0d030000); /* Gamma ? */ set_par(gspca_dev, 0x0d030000); /* Gamma ? */
setfreq(gspca_dev); /* light frequency */ setlightfreq(gspca_dev);
/* start the video flow */ /* start the video flow */
set_par(gspca_dev, 0x01000000); set_par(gspca_dev, 0x01000000);
@ -441,78 +433,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
gspca_frame_add(gspca_dev, INTER_PACKET, data, len); gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
} }
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)
setbrightness(gspca_dev);
return gspca_dev->usb_err;
}
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)
setcontrast(gspca_dev);
return gspca_dev->usb_err;
}
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_setcolors(struct gspca_dev *gspca_dev, __s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->colors = val;
if (gspca_dev->streaming)
setcolors(gspca_dev);
return gspca_dev->usb_err;
}
static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->colors;
return 0;
}
static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->lightfreq = val;
if (gspca_dev->streaming)
setfreq(gspca_dev);
return gspca_dev->usb_err;
}
static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->lightfreq;
return 0;
}
static int sd_querymenu(struct gspca_dev *gspca_dev, static int sd_querymenu(struct gspca_dev *gspca_dev,
struct v4l2_querymenu *menu) struct v4l2_querymenu *menu)
{ {
@ -563,7 +483,7 @@ static int sd_get_jcomp(struct gspca_dev *gspca_dev,
static const struct sd_desc sd_desc = { static const struct sd_desc sd_desc = {
.name = MODULE_NAME, .name = MODULE_NAME,
.ctrls = sd_ctrls, .ctrls = sd_ctrls,
.nctrls = ARRAY_SIZE(sd_ctrls), .nctrls = NCTRLS,
.config = sd_config, .config = sd_config,
.init = sd_init, .init = sd_init,
.start = sd_start, .start = sd_start,