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

[media] gspca - mars: 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 2e0544a8
...@@ -28,14 +28,21 @@ MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); ...@@ -28,14 +28,21 @@ MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver"); MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
/* controls */
enum e_ctrl {
BRIGHTNESS,
COLORS,
GAMMA,
SHARPNESS,
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 */
u8 brightness; struct gspca_ctrl ctrls[NCTRLS];
u8 colors;
u8 gamma;
u8 sharpness;
u8 quality; u8 quality;
#define QUALITY_MIN 40 #define QUALITY_MIN 40
#define QUALITY_MAX 70 #define QUALITY_MAX 70
...@@ -45,17 +52,13 @@ struct sd { ...@@ -45,17 +52,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 setcolors(struct gspca_dev *gspca_dev);
static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); static void setgamma(struct gspca_dev *gspca_dev);
static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); static void setsharpness(struct gspca_dev *gspca_dev);
static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val); static const struct ctrl sd_ctrls[NCTRLS] = {
static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); [BRIGHTNESS] = {
static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
static const struct ctrl sd_ctrls[] = {
{
{ {
.id = V4L2_CID_BRIGHTNESS, .id = V4L2_CID_BRIGHTNESS,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
...@@ -63,13 +66,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -63,13 +66,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 30, .maximum = 30,
.step = 1, .step = 1,
#define BRIGHTNESS_DEF 15 .default_value = 15,
.default_value = BRIGHTNESS_DEF,
}, },
.set = sd_setbrightness, .set_control = setbrightness
.get = sd_getbrightness,
}, },
{ [COLORS] = {
{ {
.id = V4L2_CID_SATURATION, .id = V4L2_CID_SATURATION,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
...@@ -77,13 +78,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -77,13 +78,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 1, .minimum = 1,
.maximum = 255, .maximum = 255,
.step = 1, .step = 1,
#define COLOR_DEF 200 .default_value = 200,
.default_value = COLOR_DEF,
}, },
.set = sd_setcolors, .set_control = setcolors
.get = sd_getcolors,
}, },
{ [GAMMA] = {
{ {
.id = V4L2_CID_GAMMA, .id = V4L2_CID_GAMMA,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
...@@ -91,13 +90,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -91,13 +90,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 3, .maximum = 3,
.step = 1, .step = 1,
#define GAMMA_DEF 1 .default_value = 1,
.default_value = GAMMA_DEF,
}, },
.set = sd_setgamma, .set_control = setgamma
.get = sd_getgamma,
}, },
{ [SHARPNESS] = {
{ {
.id = V4L2_CID_SHARPNESS, .id = V4L2_CID_SHARPNESS,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
...@@ -105,11 +102,9 @@ static const struct ctrl sd_ctrls[] = { ...@@ -105,11 +102,9 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 2, .maximum = 2,
.step = 1, .step = 1,
#define SHARPNESS_DEF 1 .default_value = 1,
.default_value = SHARPNESS_DEF,
}, },
.set = sd_setsharpness, .set_control = setsharpness
.get = sd_getsharpness,
}, },
}; };
...@@ -167,6 +162,45 @@ static void mi_w(struct gspca_dev *gspca_dev, ...@@ -167,6 +162,45 @@ static void mi_w(struct gspca_dev *gspca_dev,
reg_w(gspca_dev, 4); reg_w(gspca_dev, 4);
} }
static void setbrightness(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;
gspca_dev->usb_buf[0] = 0x61;
gspca_dev->usb_buf[1] = sd->ctrls[BRIGHTNESS].val;
reg_w(gspca_dev, 2);
}
static void setcolors(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;
s16 val;
val = sd->ctrls[COLORS].val;
gspca_dev->usb_buf[0] = 0x5f;
gspca_dev->usb_buf[1] = val << 3;
gspca_dev->usb_buf[2] = ((val >> 2) & 0xf8) | 0x04;
reg_w(gspca_dev, 3);
}
static void setgamma(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;
gspca_dev->usb_buf[0] = 0x06;
gspca_dev->usb_buf[1] = sd->ctrls[GAMMA].val * 0x40;
reg_w(gspca_dev, 2);
}
static void setsharpness(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *) gspca_dev;
gspca_dev->usb_buf[0] = 0x67;
gspca_dev->usb_buf[1] = sd->ctrls[SHARPNESS].val * 4 + 3;
reg_w(gspca_dev, 2);
}
/* this function is called at probe time */ /* this function is called at probe time */
static int sd_config(struct gspca_dev *gspca_dev, static int sd_config(struct gspca_dev *gspca_dev,
const struct usb_device_id *id) const struct usb_device_id *id)
...@@ -177,10 +211,7 @@ static int sd_config(struct gspca_dev *gspca_dev, ...@@ -177,10 +211,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
cam = &gspca_dev->cam; cam = &gspca_dev->cam;
cam->cam_mode = vga_mode; cam->cam_mode = vga_mode;
cam->nmodes = ARRAY_SIZE(vga_mode); cam->nmodes = ARRAY_SIZE(vga_mode);
sd->brightness = BRIGHTNESS_DEF; cam->ctrls = sd->ctrls;
sd->colors = COLOR_DEF;
sd->gamma = GAMMA_DEF;
sd->sharpness = SHARPNESS_DEF;
sd->quality = QUALITY_DEF; sd->quality = QUALITY_DEF;
gspca_dev->nbalt = 9; /* use the altsetting 08 */ gspca_dev->nbalt = 9; /* use the altsetting 08 */
return 0; return 0;
...@@ -223,7 +254,7 @@ static int sd_start(struct gspca_dev *gspca_dev) ...@@ -223,7 +254,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
data[5] = 0x30; /* reg 4, MI, PAS5101 : data[5] = 0x30; /* reg 4, MI, PAS5101 :
* 0x30 for 24mhz , 0x28 for 12mhz */ * 0x30 for 24mhz , 0x28 for 12mhz */
data[6] = 0x02; /* reg 5, H start - was 0x04 */ data[6] = 0x02; /* reg 5, H start - was 0x04 */
data[7] = sd->gamma * 0x40; /* reg 0x06: gamma */ data[7] = sd->ctrls[GAMMA].val * 0x40; /* reg 0x06: gamma */
data[8] = 0x01; /* reg 7, V start - was 0x03 */ data[8] = 0x01; /* reg 7, V start - was 0x03 */
/* if (h_size == 320 ) */ /* if (h_size == 320 ) */
/* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */ /* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */
...@@ -261,9 +292,9 @@ static int sd_start(struct gspca_dev *gspca_dev) ...@@ -261,9 +292,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
/* reg 0x5f/0x60 (LE) = saturation */ /* reg 0x5f/0x60 (LE) = saturation */
/* h (60): xxxx x100 /* h (60): xxxx x100
* l (5f): xxxx x000 */ * l (5f): xxxx x000 */
data[2] = sd->colors << 3; data[2] = sd->ctrls[COLORS].val << 3;
data[3] = ((sd->colors >> 2) & 0xf8) | 0x04; data[3] = ((sd->ctrls[COLORS].val >> 2) & 0xf8) | 0x04;
data[4] = sd->brightness; /* reg 0x61 = brightness */ data[4] = sd->ctrls[BRIGHTNESS].val; /* reg 0x61 = brightness */
data[5] = 0x00; data[5] = 0x00;
err_code = reg_w(gspca_dev, 6); err_code = reg_w(gspca_dev, 6);
...@@ -272,7 +303,7 @@ static int sd_start(struct gspca_dev *gspca_dev) ...@@ -272,7 +303,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
data[0] = 0x67; data[0] = 0x67;
/*jfm: from win trace*/ /*jfm: from win trace*/
data[1] = sd->sharpness * 4 + 3; data[1] = sd->ctrls[SHARPNESS].val * 4 + 3;
data[2] = 0x14; data[2] = 0x14;
err_code = reg_w(gspca_dev, 3); err_code = reg_w(gspca_dev, 3);
if (err_code < 0) if (err_code < 0)
...@@ -352,93 +383,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, ...@@ -352,93 +383,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) {
gspca_dev->usb_buf[0] = 0x61;
gspca_dev->usb_buf[1] = val;
reg_w(gspca_dev, 2);
}
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_setcolors(struct gspca_dev *gspca_dev, __s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->colors = val;
if (gspca_dev->streaming) {
/* see sd_start */
gspca_dev->usb_buf[0] = 0x5f;
gspca_dev->usb_buf[1] = sd->colors << 3;
gspca_dev->usb_buf[2] = ((sd->colors >> 2) & 0xf8) | 0x04;
reg_w(gspca_dev, 3);
}
return 0;
}
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_setgamma(struct gspca_dev *gspca_dev, __s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->gamma = val;
if (gspca_dev->streaming) {
gspca_dev->usb_buf[0] = 0x06;
gspca_dev->usb_buf[1] = val * 0x40;
reg_w(gspca_dev, 2);
}
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_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->sharpness = val;
if (gspca_dev->streaming) {
gspca_dev->usb_buf[0] = 0x67;
gspca_dev->usb_buf[1] = val * 4 + 3;
reg_w(gspca_dev, 2);
}
return 0;
}
static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->sharpness;
return 0;
}
static int sd_set_jcomp(struct gspca_dev *gspca_dev, static int sd_set_jcomp(struct gspca_dev *gspca_dev,
struct v4l2_jpegcompression *jcomp) struct v4l2_jpegcompression *jcomp)
{ {
...@@ -471,7 +415,7 @@ static int sd_get_jcomp(struct gspca_dev *gspca_dev, ...@@ -471,7 +415,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,
......
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