Commit a17dd1eb authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] nw80x: convert to the control framework

Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 3e0ed009
...@@ -32,22 +32,10 @@ MODULE_LICENSE("GPL"); ...@@ -32,22 +32,10 @@ MODULE_LICENSE("GPL");
static int webcam; static int webcam;
/* controls */
enum e_ctrl {
GAIN,
EXPOSURE,
AUTOGAIN,
NCTRLS /* number of controls */
};
#define AUTOGAIN_DEF 1
/* 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 */
struct gspca_ctrl ctrls[NCTRLS];
u32 ae_res; u32 ae_res;
s8 ag_cnt; s8 ag_cnt;
#define AG_CNT_START 13 #define AG_CNT_START 13
...@@ -1667,17 +1655,13 @@ static int swap_bits(int v) ...@@ -1667,17 +1655,13 @@ static int swap_bits(int v)
return r; return r;
} }
static void setgain(struct gspca_dev *gspca_dev) static void setgain(struct gspca_dev *gspca_dev, u8 val)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
u8 val, v[2]; u8 v[2];
val = sd->ctrls[GAIN].val;
switch (sd->webcam) { switch (sd->webcam) {
case P35u: case P35u:
/* Note the control goes from 0-255 not 0-127, but anything
above 127 just means amplifying noise */
val >>= 1; /* 0 - 255 -> 0 - 127 */
reg_w(gspca_dev, 0x1026, &val, 1); reg_w(gspca_dev, 0x1026, &val, 1);
break; break;
case Kr651us: case Kr651us:
...@@ -1690,13 +1674,11 @@ static void setgain(struct gspca_dev *gspca_dev) ...@@ -1690,13 +1674,11 @@ static void setgain(struct gspca_dev *gspca_dev)
} }
} }
static void setexposure(struct gspca_dev *gspca_dev) static void setexposure(struct gspca_dev *gspca_dev, s32 val)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
s16 val;
u8 v[2]; u8 v[2];
val = sd->ctrls[EXPOSURE].val;
switch (sd->webcam) { switch (sd->webcam) {
case P35u: case P35u:
v[0] = ((9 - val) << 3) | 0x01; v[0] = ((9 - val) << 3) | 0x01;
...@@ -1713,14 +1695,12 @@ static void setexposure(struct gspca_dev *gspca_dev) ...@@ -1713,14 +1695,12 @@ static void setexposure(struct gspca_dev *gspca_dev)
} }
} }
static void setautogain(struct gspca_dev *gspca_dev) static void setautogain(struct gspca_dev *gspca_dev, s32 val)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
int w, h; int w, h;
if (gspca_dev->ctrl_dis & (1 << AUTOGAIN)) if (!val) {
return;
if (!sd->ctrls[AUTOGAIN].val) {
sd->ag_cnt = -1; sd->ag_cnt = -1;
return; return;
} }
...@@ -1763,7 +1743,6 @@ static int sd_config(struct gspca_dev *gspca_dev, ...@@ -1763,7 +1743,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
if ((unsigned) webcam >= NWEBCAMS) if ((unsigned) webcam >= NWEBCAMS)
webcam = 0; webcam = 0;
sd->webcam = webcam; sd->webcam = webcam;
gspca_dev->cam.ctrls = sd->ctrls;
gspca_dev->cam.needs_full_bandwidth = 1; gspca_dev->cam.needs_full_bandwidth = 1;
sd->ag_cnt = -1; sd->ag_cnt = -1;
...@@ -1834,33 +1813,7 @@ static int sd_config(struct gspca_dev *gspca_dev, ...@@ -1834,33 +1813,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
break; break;
} }
} }
switch (sd->webcam) {
case P35u:
/* sd->ctrls[EXPOSURE].max = 9;
* sd->ctrls[EXPOSURE].def = 9; */
/* coarse expo auto gain function gain minimum, to avoid
* a large settings jump the first auto adjustment */
sd->ctrls[GAIN].def = 255 / 5 * 2;
break;
case Cvideopro:
case DvcV6:
case Kritter:
gspca_dev->ctrl_dis = (1 << GAIN) | (1 << AUTOGAIN);
/* fall thru */
case Kr651us:
sd->ctrls[EXPOSURE].max = 315;
sd->ctrls[EXPOSURE].def = 150;
break;
default:
gspca_dev->ctrl_dis = (1 << GAIN) | (1 << EXPOSURE)
| (1 << AUTOGAIN);
break;
}
#if AUTOGAIN_DEF
if (!(gspca_dev->ctrl_dis & (1 << AUTOGAIN)))
gspca_dev->ctrl_inac = (1 << GAIN) | (1 << EXPOSURE);
#endif
return gspca_dev->usb_err; return gspca_dev->usb_err;
} }
...@@ -1925,9 +1878,7 @@ static int sd_start(struct gspca_dev *gspca_dev) ...@@ -1925,9 +1878,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
break; break;
} }
setgain(gspca_dev); v4l2_ctrl_handler_setup(&gspca_dev->ctrl_handler);
setexposure(gspca_dev);
setautogain(gspca_dev);
sd->exp_too_high_cnt = 0; sd->exp_too_high_cnt = 0;
sd->exp_too_low_cnt = 0; sd->exp_too_low_cnt = 0;
return gspca_dev->usb_err; return gspca_dev->usb_err;
...@@ -1987,24 +1938,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, ...@@ -1987,24 +1938,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
} }
} }
static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
{
struct sd *sd = (struct sd *) gspca_dev;
sd->ctrls[AUTOGAIN].val = val;
if (val)
gspca_dev->ctrl_inac = (1 << GAIN) | (1 << EXPOSURE);
else
gspca_dev->ctrl_inac = 0;
if (gspca_dev->streaming)
setautogain(gspca_dev);
return gspca_dev->usb_err;
}
#define WANT_REGULAR_AUTOGAIN
#define WANT_COARSE_EXPO_AUTOGAIN
#include "autogain_functions.h"
static void do_autogain(struct gspca_dev *gspca_dev) static void do_autogain(struct gspca_dev *gspca_dev)
{ {
struct sd *sd = (struct sd *) gspca_dev; struct sd *sd = (struct sd *) gspca_dev;
...@@ -2024,62 +1957,100 @@ static void do_autogain(struct gspca_dev *gspca_dev) ...@@ -2024,62 +1957,100 @@ static void do_autogain(struct gspca_dev *gspca_dev)
switch (sd->webcam) { switch (sd->webcam) {
case P35u: case P35u:
coarse_grained_expo_autogain(gspca_dev, luma, 100, 5); gspca_coarse_grained_expo_autogain(gspca_dev, luma, 100, 5);
break; break;
default: default:
auto_gain_n_exposure(gspca_dev, luma, 100, 5, 230, 0); gspca_expo_autogain(gspca_dev, luma, 100, 5, 230, 0);
break; break;
} }
} }
/* V4L2 controls supported by the driver */
static const struct ctrl sd_ctrls[NCTRLS] = { static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
[GAIN] = { {
{ struct gspca_dev *gspca_dev =
.id = V4L2_CID_GAIN, container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
.type = V4L2_CTRL_TYPE_INTEGER,
.name = "Gain", gspca_dev->usb_err = 0;
.minimum = 0,
.maximum = 253, if (!gspca_dev->streaming)
.step = 1, return 0;
.default_value = 128
}, switch (ctrl->id) {
.set_control = setgain /* autogain/gain/exposure control cluster */
}, case V4L2_CID_AUTOGAIN:
[EXPOSURE] = { if (ctrl->is_new)
{ setautogain(gspca_dev, ctrl->val);
.id = V4L2_CID_EXPOSURE, if (!ctrl->val) {
.type = V4L2_CTRL_TYPE_INTEGER, if (gspca_dev->gain->is_new)
.name = "Exposure", setgain(gspca_dev, gspca_dev->gain->val);
.minimum = 0, if (gspca_dev->exposure->is_new)
.maximum = 9, setexposure(gspca_dev,
.step = 1, gspca_dev->exposure->val);
.default_value = 9 }
}, break;
.set_control = setexposure /* Some webcams only have exposure, so handle that separately from the
}, autogain/gain/exposure cluster in the previous case. */
[AUTOGAIN] = { case V4L2_CID_EXPOSURE:
{ setexposure(gspca_dev, gspca_dev->exposure->val);
.id = V4L2_CID_AUTOGAIN, break;
.type = V4L2_CTRL_TYPE_BOOLEAN, }
.name = "Auto Gain", return gspca_dev->usb_err;
.minimum = 0, }
.maximum = 1,
.step = 1, static const struct v4l2_ctrl_ops sd_ctrl_ops = {
.default_value = AUTOGAIN_DEF, .s_ctrl = sd_s_ctrl,
.flags = V4L2_CTRL_FLAG_UPDATE
},
.set = sd_setautogain
},
}; };
static int sd_init_controls(struct gspca_dev *gspca_dev)
{
struct sd *sd = (struct sd *)gspca_dev;
struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
gspca_dev->vdev.ctrl_handler = hdl;
v4l2_ctrl_handler_init(hdl, 3);
switch (sd->webcam) {
case P35u:
gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
/* For P35u choose coarse expo auto gain function gain minimum,
* to avoid a large settings jump the first auto adjustment */
gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_GAIN, 0, 127, 1, 127 / 5 * 2);
gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_EXPOSURE, 0, 9, 1, 9);
break;
case Kr651us:
gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_GAIN, 0, 253, 1, 128);
/* fall through */
case Cvideopro:
case DvcV6:
case Kritter:
gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
V4L2_CID_EXPOSURE, 0, 315, 1, 150);
break;
default:
break;
}
if (hdl->error) {
pr_err("Could not initialize controls\n");
return hdl->error;
}
if (gspca_dev->autogain)
v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, false);
return 0;
}
/* sub-driver description */ /* sub-driver description */
static const struct sd_desc sd_desc = { static const struct sd_desc sd_desc = {
.name = MODULE_NAME, .name = MODULE_NAME,
.ctrls = sd_ctrls,
.nctrls = ARRAY_SIZE(sd_ctrls),
.config = sd_config, .config = sd_config,
.init = sd_init, .init = sd_init,
.init_controls = sd_init_controls,
.start = sd_start, .start = sd_start,
.stopN = sd_stopN, .stopN = sd_stopN,
.pkt_scan = sd_pkt_scan, .pkt_scan = sd_pkt_scan,
......
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