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

[media] gscpa_gl860: Convert to the control framework

Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent c1f07ab2
...@@ -58,115 +58,135 @@ MODULE_PARM_DESC(sensor, ...@@ -58,115 +58,135 @@ MODULE_PARM_DESC(sensor,
/*============================ webcam controls =============================*/ /*============================ webcam controls =============================*/
/* Functions to get and set a control value */ static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
#define SD_SETGET(thename) \ {
static int sd_set_##thename(struct gspca_dev *gspca_dev, s32 val)\ struct gspca_dev *gspca_dev =
{\ container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
struct sd *sd = (struct sd *) gspca_dev;\ struct sd *sd = (struct sd *) gspca_dev;
\
sd->vcur.thename = val;\
if (gspca_dev->streaming)\
sd->waitSet = 1;\
return 0;\
} \
static int sd_get_##thename(struct gspca_dev *gspca_dev, s32 *val)\
{\
struct sd *sd = (struct sd *) gspca_dev;\
\
*val = sd->vcur.thename;\
return 0;\
}
SD_SETGET(mirror) switch (ctrl->id) {
SD_SETGET(flip) case V4L2_CID_BRIGHTNESS:
SD_SETGET(AC50Hz) sd->vcur.brightness = ctrl->val;
SD_SETGET(backlight) break;
SD_SETGET(brightness) case V4L2_CID_CONTRAST:
SD_SETGET(gamma) sd->vcur.contrast = ctrl->val;
SD_SETGET(hue) break;
SD_SETGET(saturation) case V4L2_CID_SATURATION:
SD_SETGET(sharpness) sd->vcur.saturation = ctrl->val;
SD_SETGET(whitebal) break;
SD_SETGET(contrast) case V4L2_CID_HUE:
sd->vcur.hue = ctrl->val;
#define GL860_NCTRLS 11 break;
case V4L2_CID_GAMMA:
/* control table */ sd->vcur.gamma = ctrl->val;
static struct ctrl sd_ctrls_mi1320[GL860_NCTRLS]; break;
static struct ctrl sd_ctrls_mi2020[GL860_NCTRLS]; case V4L2_CID_HFLIP:
static struct ctrl sd_ctrls_ov2640[GL860_NCTRLS]; sd->vcur.mirror = ctrl->val;
static struct ctrl sd_ctrls_ov9655[GL860_NCTRLS]; break;
case V4L2_CID_VFLIP:
#define SET_MY_CTRL(theid, \ sd->vcur.flip = ctrl->val;
thetype, thelabel, thename) \ break;
if (sd->vmax.thename != 0) {\ case V4L2_CID_POWER_LINE_FREQUENCY:
sd_ctrls[nCtrls].qctrl.id = theid;\ sd->vcur.AC50Hz = ctrl->val;
sd_ctrls[nCtrls].qctrl.type = thetype;\ break;
strcpy(sd_ctrls[nCtrls].qctrl.name, thelabel);\ case V4L2_CID_WHITE_BALANCE_TEMPERATURE:
sd_ctrls[nCtrls].qctrl.minimum = 0;\ sd->vcur.whitebal = ctrl->val;
sd_ctrls[nCtrls].qctrl.maximum = sd->vmax.thename;\ break;
sd_ctrls[nCtrls].qctrl.default_value = sd->vcur.thename;\ case V4L2_CID_SHARPNESS:
sd_ctrls[nCtrls].qctrl.step = \ sd->vcur.sharpness = ctrl->val;
(sd->vmax.thename < 16) ? 1 : sd->vmax.thename/16;\ break;
sd_ctrls[nCtrls].set = sd_set_##thename;\ case V4L2_CID_BACKLIGHT_COMPENSATION:
sd_ctrls[nCtrls].get = sd_get_##thename;\ sd->vcur.backlight = ctrl->val;
nCtrls++;\ break;
default:
return -EINVAL;
} }
static int gl860_build_control_table(struct gspca_dev *gspca_dev) if (gspca_dev->streaming)
sd->waitSet = 1;
return 0;
}
static const struct v4l2_ctrl_ops sd_ctrl_ops = {
.s_ctrl = sd_s_ctrl,
};
static int sd_init_controls(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
struct ctrl *sd_ctrls; struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
int nCtrls = 0;
gspca_dev->vdev.ctrl_handler = hdl;
if (_MI1320_) v4l2_ctrl_handler_init(hdl, 11);
sd_ctrls = sd_ctrls_mi1320;
else if (_MI2020_) if (sd->vmax.brightness)
sd_ctrls = sd_ctrls_mi2020; v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_BRIGHTNESS,
else if (_OV2640_) 0, sd->vmax.brightness, 1,
sd_ctrls = sd_ctrls_ov2640; sd->vcur.brightness);
else if (_OV9655_)
sd_ctrls = sd_ctrls_ov9655; if (sd->vmax.contrast)
else v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_CONTRAST,
return 0; 0, sd->vmax.contrast, 1,
sd->vcur.contrast);
memset(sd_ctrls, 0, GL860_NCTRLS * sizeof(struct ctrl));
if (sd->vmax.saturation)
SET_MY_CTRL(V4L2_CID_BRIGHTNESS, v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_SATURATION,
V4L2_CTRL_TYPE_INTEGER, "Brightness", brightness) 0, sd->vmax.saturation, 1,
SET_MY_CTRL(V4L2_CID_SHARPNESS, sd->vcur.saturation);
V4L2_CTRL_TYPE_INTEGER, "Sharpness", sharpness)
SET_MY_CTRL(V4L2_CID_CONTRAST, if (sd->vmax.hue)
V4L2_CTRL_TYPE_INTEGER, "Contrast", contrast) v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_HUE,
SET_MY_CTRL(V4L2_CID_GAMMA, 0, sd->vmax.hue, 1, sd->vcur.hue);
V4L2_CTRL_TYPE_INTEGER, "Gamma", gamma)
SET_MY_CTRL(V4L2_CID_HUE, if (sd->vmax.gamma)
V4L2_CTRL_TYPE_INTEGER, "Palette", hue) v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_GAMMA,
SET_MY_CTRL(V4L2_CID_SATURATION, 0, sd->vmax.gamma, 1, sd->vcur.gamma);
V4L2_CTRL_TYPE_INTEGER, "Saturation", saturation)
SET_MY_CTRL(V4L2_CID_WHITE_BALANCE_TEMPERATURE, if (sd->vmax.mirror)
V4L2_CTRL_TYPE_INTEGER, "White Bal.", whitebal) v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_HFLIP,
SET_MY_CTRL(V4L2_CID_BACKLIGHT_COMPENSATION, 0, sd->vmax.mirror, 1, sd->vcur.mirror);
V4L2_CTRL_TYPE_INTEGER, "Backlight" , backlight)
if (sd->vmax.flip)
SET_MY_CTRL(V4L2_CID_HFLIP, v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_VFLIP,
V4L2_CTRL_TYPE_BOOLEAN, "Mirror", mirror) 0, sd->vmax.flip, 1, sd->vcur.flip);
SET_MY_CTRL(V4L2_CID_VFLIP,
V4L2_CTRL_TYPE_BOOLEAN, "Flip", flip) if (sd->vmax.AC50Hz)
SET_MY_CTRL(V4L2_CID_POWER_LINE_FREQUENCY, v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
V4L2_CTRL_TYPE_BOOLEAN, "AC power 50Hz", AC50Hz) V4L2_CID_POWER_LINE_FREQUENCY,
sd->vmax.AC50Hz, 0, sd->vcur.AC50Hz);
return nCtrls;
if (sd->vmax.whitebal)
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_WHITE_BALANCE_TEMPERATURE,
0, sd->vmax.whitebal, 1, sd->vcur.whitebal);
if (sd->vmax.sharpness)
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, V4L2_CID_SHARPNESS,
0, sd->vmax.sharpness, 1,
sd->vcur.sharpness);
if (sd->vmax.backlight)
v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_BACKLIGHT_COMPENSATION,
0, sd->vmax.backlight, 1,
sd->vcur.backlight);
if (hdl->error) {
pr_err("Could not initialize controls\n");
return hdl->error;
}
return 0;
} }
/*==================== sud-driver structure initialisation =================*/ /*==================== sud-driver structure initialisation =================*/
static const struct sd_desc sd_desc_mi1320 = { static const struct sd_desc sd_desc_mi1320 = {
.name = MODULE_NAME, .name = MODULE_NAME,
.ctrls = sd_ctrls_mi1320,
.nctrls = GL860_NCTRLS,
.config = sd_config, .config = sd_config,
.init = sd_init, .init = sd_init,
.init_controls = sd_init_controls,
.isoc_init = sd_isoc_init, .isoc_init = sd_isoc_init,
.start = sd_start, .start = sd_start,
.stop0 = sd_stop0, .stop0 = sd_stop0,
...@@ -176,10 +196,9 @@ static const struct sd_desc sd_desc_mi1320 = { ...@@ -176,10 +196,9 @@ static const struct sd_desc sd_desc_mi1320 = {
static const struct sd_desc sd_desc_mi2020 = { static const struct sd_desc sd_desc_mi2020 = {
.name = MODULE_NAME, .name = MODULE_NAME,
.ctrls = sd_ctrls_mi2020,
.nctrls = GL860_NCTRLS,
.config = sd_config, .config = sd_config,
.init = sd_init, .init = sd_init,
.init_controls = sd_init_controls,
.isoc_init = sd_isoc_init, .isoc_init = sd_isoc_init,
.start = sd_start, .start = sd_start,
.stop0 = sd_stop0, .stop0 = sd_stop0,
...@@ -189,10 +208,9 @@ static const struct sd_desc sd_desc_mi2020 = { ...@@ -189,10 +208,9 @@ static const struct sd_desc sd_desc_mi2020 = {
static const struct sd_desc sd_desc_ov2640 = { static const struct sd_desc sd_desc_ov2640 = {
.name = MODULE_NAME, .name = MODULE_NAME,
.ctrls = sd_ctrls_ov2640,
.nctrls = GL860_NCTRLS,
.config = sd_config, .config = sd_config,
.init = sd_init, .init = sd_init,
.init_controls = sd_init_controls,
.isoc_init = sd_isoc_init, .isoc_init = sd_isoc_init,
.start = sd_start, .start = sd_start,
.stop0 = sd_stop0, .stop0 = sd_stop0,
...@@ -202,10 +220,9 @@ static const struct sd_desc sd_desc_ov2640 = { ...@@ -202,10 +220,9 @@ static const struct sd_desc sd_desc_ov2640 = {
static const struct sd_desc sd_desc_ov9655 = { static const struct sd_desc sd_desc_ov9655 = {
.name = MODULE_NAME, .name = MODULE_NAME,
.ctrls = sd_ctrls_ov9655,
.nctrls = GL860_NCTRLS,
.config = sd_config, .config = sd_config,
.init = sd_init, .init = sd_init,
.init_controls = sd_init_controls,
.isoc_init = sd_isoc_init, .isoc_init = sd_isoc_init,
.start = sd_start, .start = sd_start,
.stop0 = sd_stop0, .stop0 = sd_stop0,
...@@ -371,7 +388,6 @@ static int sd_config(struct gspca_dev *gspca_dev, ...@@ -371,7 +388,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
dev_init_settings(gspca_dev); dev_init_settings(gspca_dev);
if (AC50Hz != 0xff) if (AC50Hz != 0xff)
((struct sd *) gspca_dev)->vcur.AC50Hz = AC50Hz; ((struct sd *) gspca_dev)->vcur.AC50Hz = AC50Hz;
gl860_build_control_table(gspca_dev);
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