Commit a5340ce5 authored by Hans de Goede's avatar Hans de Goede Committed by Mauro Carvalho Chehab

[media] gspca_pac7311: Switch to new gspca control mechanism

Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent c894d26c
...@@ -50,20 +50,26 @@ ...@@ -50,20 +50,26 @@
#include <linux/input.h> #include <linux/input.h>
#include "gspca.h" #include "gspca.h"
/* Include pac common sof detection functions */
#include "pac_common.h"
MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li"); MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li");
MODULE_DESCRIPTION("Pixart PAC7311"); MODULE_DESCRIPTION("Pixart PAC7311");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
enum e_ctrl {
CONTRAST,
GAIN,
EXPOSURE,
AUTOGAIN,
HFLIP,
VFLIP,
NCTRLS /* number of controls */
};
struct sd { struct sd {
struct gspca_dev gspca_dev; /* !! must be the first item */ struct gspca_dev gspca_dev; /* !! must be the first item */
struct gspca_ctrl ctrls[NCTRLS];
unsigned char contrast;
unsigned char gain;
unsigned char exposure;
unsigned char autogain;
__u8 hflip;
__u8 vflip;
u8 sof_read; u8 sof_read;
u8 autogain_ignore_frames; u8 autogain_ignore_frames;
...@@ -72,68 +78,52 @@ struct sd { ...@@ -72,68 +78,52 @@ struct sd {
}; };
/* V4L2 controls supported by the driver */ /* V4L2 controls supported by the driver */
static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); static void setcontrast(struct gspca_dev *gspca_dev);
static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); static void setgain(struct gspca_dev *gspca_dev);
static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); static void setexposure(struct gspca_dev *gspca_dev);
static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); static void setautogain(struct gspca_dev *gspca_dev);
static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val); static void sethvflip(struct gspca_dev *gspca_dev);
static int sd_gethflip(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_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 const struct ctrl sd_ctrls[] = { static const struct ctrl sd_ctrls[] = {
{ [CONTRAST] = {
{ {
.id = V4L2_CID_CONTRAST, .id = V4L2_CID_CONTRAST,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
.name = "Contrast", .name = "Contrast",
.minimum = 0, .minimum = 0,
#define CONTRAST_MAX 15 .maximum = 15,
.maximum = CONTRAST_MAX,
.step = 1, .step = 1,
#define CONTRAST_DEF 7 .default_value = 7,
.default_value = CONTRAST_DEF,
}, },
.set = sd_setcontrast, .set_control = setcontrast
.get = sd_getcontrast,
}, },
{ [GAIN] = {
{ {
.id = V4L2_CID_GAIN, .id = V4L2_CID_GAIN,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
.name = "Gain", .name = "Gain",
.minimum = 0, .minimum = 0,
#define GAIN_MAX 244 .maximum = 244,
.maximum = GAIN_MAX,
.step = 1, .step = 1,
#define GAIN_DEF 122 .default_value = 122,
#define GAIN_KNEE GAIN_MAX /* Gain seems to cause little noise on the 7311 */ #define GAIN_KNEE 244 /* Gain seems to cause little noise on the 7311 */
.default_value = GAIN_DEF,
}, },
.set = sd_setgain, .set_control = setgain,
.get = sd_getgain,
}, },
{ [EXPOSURE] = {
{ {
.id = V4L2_CID_EXPOSURE, .id = V4L2_CID_EXPOSURE,
.type = V4L2_CTRL_TYPE_INTEGER, .type = V4L2_CTRL_TYPE_INTEGER,
.name = "Exposure", .name = "Exposure",
.minimum = 2, .minimum = 2,
#define EXPOSURE_MAX 63 .maximum = 63,
.maximum = EXPOSURE_MAX,
.step = 1, .step = 1,
#define EXPOSURE_DEF 2 /* 30 fps */ .default_value = 2, /* 30 fps */
#define EXPOSURE_KNEE 6 /* 10 fps */ #define EXPOSURE_KNEE 6 /* 10 fps */
.default_value = EXPOSURE_DEF,
}, },
.set = sd_setexposure, .set_control = setexposure,
.get = sd_getexposure,
}, },
{ [AUTOGAIN] = {
{ {
.id = V4L2_CID_AUTOGAIN, .id = V4L2_CID_AUTOGAIN,
.type = V4L2_CTRL_TYPE_BOOLEAN, .type = V4L2_CTRL_TYPE_BOOLEAN,
...@@ -141,13 +131,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -141,13 +131,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 1, .maximum = 1,
.step = 1, .step = 1,
#define AUTOGAIN_DEF 1 .default_value = 1,
.default_value = AUTOGAIN_DEF,
}, },
.set = sd_setautogain, .set_control = setautogain,
.get = sd_getautogain,
}, },
{ [HFLIP] = {
{ {
.id = V4L2_CID_HFLIP, .id = V4L2_CID_HFLIP,
.type = V4L2_CTRL_TYPE_BOOLEAN, .type = V4L2_CTRL_TYPE_BOOLEAN,
...@@ -155,13 +143,11 @@ static const struct ctrl sd_ctrls[] = { ...@@ -155,13 +143,11 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 1, .maximum = 1,
.step = 1, .step = 1,
#define HFLIP_DEF 0 .default_value = 0,
.default_value = HFLIP_DEF,
}, },
.set = sd_sethflip, .set_control = sethvflip,
.get = sd_gethflip,
}, },
{ [VFLIP] = {
{ {
.id = V4L2_CID_VFLIP, .id = V4L2_CID_VFLIP,
.type = V4L2_CTRL_TYPE_BOOLEAN, .type = V4L2_CTRL_TYPE_BOOLEAN,
...@@ -169,11 +155,9 @@ static const struct ctrl sd_ctrls[] = { ...@@ -169,11 +155,9 @@ static const struct ctrl sd_ctrls[] = {
.minimum = 0, .minimum = 0,
.maximum = 1, .maximum = 1,
.step = 1, .step = 1,
#define VFLIP_DEF 0 .default_value = 0,
.default_value = VFLIP_DEF,
}, },
.set = sd_setvflip, .set_control = sethvflip,
.get = sd_getvflip,
}, },
}; };
...@@ -379,19 +363,13 @@ static int sd_config(struct gspca_dev *gspca_dev, ...@@ -379,19 +363,13 @@ static int sd_config(struct gspca_dev *gspca_dev,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
struct cam *cam; struct cam *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->contrast = CONTRAST_DEF; gspca_dev->cam.ctrls = sd->ctrls;
sd->gain = GAIN_DEF;
sd->exposure = EXPOSURE_DEF;
sd->autogain = AUTOGAIN_DEF;
sd->hflip = HFLIP_DEF;
sd->vflip = VFLIP_DEF;
return 0; return 0;
} }
...@@ -400,7 +378,7 @@ static void setcontrast(struct gspca_dev *gspca_dev) ...@@ -400,7 +378,7 @@ static void setcontrast(struct gspca_dev *gspca_dev)
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
reg_w(gspca_dev, 0xff, 0x04); reg_w(gspca_dev, 0xff, 0x04);
reg_w(gspca_dev, 0x10, sd->contrast); reg_w(gspca_dev, 0x10, sd->ctrls[CONTRAST].val);
/* load registers to sensor (Bit 0, auto clear) */ /* load registers to sensor (Bit 0, auto clear) */
reg_w(gspca_dev, 0x11, 0x01); reg_w(gspca_dev, 0x11, 0x01);
} }
...@@ -411,7 +389,7 @@ static void setgain(struct gspca_dev *gspca_dev) ...@@ -411,7 +389,7 @@ static void setgain(struct gspca_dev *gspca_dev)
reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ reg_w(gspca_dev, 0xff, 0x04); /* page 4 */
reg_w(gspca_dev, 0x0e, 0x00); reg_w(gspca_dev, 0x0e, 0x00);
reg_w(gspca_dev, 0x0f, GAIN_MAX - sd->gain + 1); reg_w(gspca_dev, 0x0f, sd->ctrls[GAIN].max - sd->ctrls[GAIN].val + 1);
/* load registers to sensor (Bit 0, auto clear) */ /* load registers to sensor (Bit 0, auto clear) */
reg_w(gspca_dev, 0x11, 0x01); reg_w(gspca_dev, 0x11, 0x01);
...@@ -422,7 +400,7 @@ static void setexposure(struct gspca_dev *gspca_dev) ...@@ -422,7 +400,7 @@ static void setexposure(struct gspca_dev *gspca_dev)
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ reg_w(gspca_dev, 0xff, 0x04); /* page 4 */
reg_w(gspca_dev, 0x02, sd->exposure); reg_w(gspca_dev, 0x02, sd->ctrls[EXPOSURE].val);
/* load registers to sensor (Bit 0, auto clear) */ /* load registers to sensor (Bit 0, auto clear) */
reg_w(gspca_dev, 0x11, 0x01); reg_w(gspca_dev, 0x11, 0x01);
...@@ -431,7 +409,7 @@ static void setexposure(struct gspca_dev *gspca_dev) ...@@ -431,7 +409,7 @@ static void setexposure(struct gspca_dev *gspca_dev)
640x480 mode and page 4 reg 2 <= 3 then it must be 9 */ 640x480 mode and page 4 reg 2 <= 3 then it must be 9 */
reg_w(gspca_dev, 0xff, 0x01); reg_w(gspca_dev, 0xff, 0x01);
if (gspca_dev->cam.cam_mode[(int)gspca_dev->curr_mode].priv && if (gspca_dev->cam.cam_mode[(int)gspca_dev->curr_mode].priv &&
sd->exposure <= 3) { sd->ctrls[EXPOSURE].val <= 3) {
reg_w(gspca_dev, 0x08, 0x09); reg_w(gspca_dev, 0x08, 0x09);
} else { } else {
reg_w(gspca_dev, 0x08, 0x08); reg_w(gspca_dev, 0x08, 0x08);
...@@ -447,7 +425,8 @@ static void sethvflip(struct gspca_dev *gspca_dev) ...@@ -447,7 +425,8 @@ static void sethvflip(struct gspca_dev *gspca_dev)
__u8 data; __u8 data;
reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ reg_w(gspca_dev, 0xff, 0x04); /* page 4 */
data = (sd->hflip ? 0x04 : 0x00) | (sd->vflip ? 0x08 : 0x00); data = (sd->ctrls[HFLIP].val ? 0x04 : 0x00) |
(sd->ctrls[VFLIP].val ? 0x08 : 0x00);
reg_w(gspca_dev, 0x21, data); reg_w(gspca_dev, 0x21, data);
/* load registers to sensor (Bit 0, auto clear) */ /* load registers to sensor (Bit 0, auto clear) */
...@@ -518,8 +497,8 @@ static void sd_stopN(struct gspca_dev *gspca_dev) ...@@ -518,8 +497,8 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */ reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
} }
/* Include pac common sof detection functions */ #define WANT_REGULAR_AUTOGAIN
#include "pac_common.h" #include "autogain_functions.h"
static void do_autogain(struct gspca_dev *gspca_dev) static void do_autogain(struct gspca_dev *gspca_dev)
{ {
...@@ -527,7 +506,7 @@ static void do_autogain(struct gspca_dev *gspca_dev) ...@@ -527,7 +506,7 @@ static void do_autogain(struct gspca_dev *gspca_dev)
int avg_lum = atomic_read(&sd->avg_lum); int avg_lum = atomic_read(&sd->avg_lum);
int desired_lum, deadzone; int desired_lum, deadzone;
if (avg_lum == -1) if (sd->ctrls[AUTOGAIN].val == 0 || avg_lum == -1)
return; return;
desired_lum = 200; desired_lum = 200;
...@@ -535,7 +514,7 @@ static void do_autogain(struct gspca_dev *gspca_dev) ...@@ -535,7 +514,7 @@ static void do_autogain(struct gspca_dev *gspca_dev)
if (sd->autogain_ignore_frames > 0) if (sd->autogain_ignore_frames > 0)
sd->autogain_ignore_frames--; sd->autogain_ignore_frames--;
else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum, desired_lum, else if (auto_gain_n_exposure(gspca_dev, avg_lum, desired_lum,
deadzone, GAIN_KNEE, EXPOSURE_KNEE)) deadzone, GAIN_KNEE, EXPOSURE_KNEE))
sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES; sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES;
} }
...@@ -640,72 +619,13 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, ...@@ -640,72 +619,13 @@ 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_setcontrast(struct gspca_dev *gspca_dev, __s32 val) static void setautogain(struct gspca_dev *gspca_dev)
{
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_setgain(struct gspca_dev *gspca_dev, __s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->gain = val;
if (gspca_dev->streaming)
setgain(gspca_dev);
return gspca_dev->usb_err;
}
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_setexposure(struct gspca_dev *gspca_dev, __s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->exposure = val;
if (gspca_dev->streaming)
setexposure(gspca_dev);
return gspca_dev->usb_err;
}
static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
*val = sd->exposure; if (sd->ctrls[AUTOGAIN].val) {
return 0; sd->ctrls[EXPOSURE].val = 2;
} sd->ctrls[GAIN].val = 122;
static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->autogain = val;
/* when switching to autogain set defaults to make sure
we are on a valid point of the autogain gain /
exposure knee graph, and give this change time to
take effect before doing autogain. */
if (sd->autogain) {
sd->exposure = EXPOSURE_DEF;
sd->gain = GAIN_DEF;
if (gspca_dev->streaming) { if (gspca_dev->streaming) {
sd->autogain_ignore_frames = sd->autogain_ignore_frames =
PAC_AUTOGAIN_IGNORE_FRAMES; PAC_AUTOGAIN_IGNORE_FRAMES;
...@@ -713,52 +633,6 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) ...@@ -713,52 +633,6 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
setgain(gspca_dev); setgain(gspca_dev);
} }
} }
return gspca_dev->usb_err;
}
static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->autogain;
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)
sethvflip(gspca_dev);
return gspca_dev->usb_err;
}
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)
sethvflip(gspca_dev);
return gspca_dev->usb_err;
}
static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
{
struct sd *sd = (struct sd *) gspca_dev;
*val = sd->vflip;
return 0;
} }
#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
......
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