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

V4L/DVB (10646): vivi: controls are per-device, not global.

Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 5ab6c9af
...@@ -125,8 +125,6 @@ static struct v4l2_queryctrl vivi_qctrl[] = { ...@@ -125,8 +125,6 @@ static struct v4l2_queryctrl vivi_qctrl[] = {
} }
}; };
static int qctl_regs[ARRAY_SIZE(vivi_qctrl)];
#define dprintk(dev, level, fmt, arg...) \ #define dprintk(dev, level, fmt, arg...) \
v4l2_dbg(level, debug, &dev->v4l2_dev, fmt, ## arg) v4l2_dbg(level, debug, &dev->v4l2_dev, fmt, ## arg)
...@@ -239,6 +237,9 @@ struct vivi_dev { ...@@ -239,6 +237,9 @@ struct vivi_dev {
/* Input Number */ /* Input Number */
int input; int input;
/* Control 'registers' */
int qctl_regs[ARRAY_SIZE(vivi_qctrl)];
}; };
struct vivi_fh { struct vivi_fh {
...@@ -1108,12 +1109,14 @@ static int vidioc_queryctrl(struct file *file, void *priv, ...@@ -1108,12 +1109,14 @@ static int vidioc_queryctrl(struct file *file, void *priv,
static int vidioc_g_ctrl(struct file *file, void *priv, static int vidioc_g_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl) struct v4l2_control *ctrl)
{ {
struct vivi_fh *fh = priv;
struct vivi_dev *dev = fh->dev;
int i; int i;
for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
if (ctrl->id == vivi_qctrl[i].id) { if (ctrl->id == vivi_qctrl[i].id) {
ctrl->value = qctl_regs[i]; ctrl->value = dev->qctl_regs[i];
return (0); return 0;
} }
return -EINVAL; return -EINVAL;
...@@ -1121,16 +1124,18 @@ static int vidioc_g_ctrl(struct file *file, void *priv, ...@@ -1121,16 +1124,18 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
static int vidioc_s_ctrl(struct file *file, void *priv, static int vidioc_s_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl) struct v4l2_control *ctrl)
{ {
struct vivi_fh *fh = priv;
struct vivi_dev *dev = fh->dev;
int i; int i;
for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
if (ctrl->id == vivi_qctrl[i].id) { if (ctrl->id == vivi_qctrl[i].id) {
if (ctrl->value < vivi_qctrl[i].minimum if (ctrl->value < vivi_qctrl[i].minimum ||
|| ctrl->value > vivi_qctrl[i].maximum) { ctrl->value > vivi_qctrl[i].maximum) {
return (-ERANGE); return -ERANGE;
} }
qctl_regs[i] = ctrl->value; dev->qctl_regs[i] = ctrl->value;
return (0); return 0;
} }
return -EINVAL; return -EINVAL;
} }
...@@ -1143,7 +1148,6 @@ static int vivi_open(struct file *file) ...@@ -1143,7 +1148,6 @@ static int vivi_open(struct file *file)
{ {
struct vivi_dev *dev = video_drvdata(file); struct vivi_dev *dev = video_drvdata(file);
struct vivi_fh *fh = NULL; struct vivi_fh *fh = NULL;
int i;
int retval = 0; int retval = 0;
mutex_lock(&dev->mutex); mutex_lock(&dev->mutex);
...@@ -1177,10 +1181,6 @@ static int vivi_open(struct file *file) ...@@ -1177,10 +1181,6 @@ static int vivi_open(struct file *file)
fh->width = 640; fh->width = 640;
fh->height = 480; fh->height = 480;
/* Put all controls at a sane state */
for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
qctl_regs[i] = vivi_qctrl[i].default_value;
/* Resets frame counters */ /* Resets frame counters */
dev->h = 0; dev->h = 0;
dev->m = 0; dev->m = 0;
...@@ -1338,18 +1338,18 @@ static int vivi_release(void) ...@@ -1338,18 +1338,18 @@ static int vivi_release(void)
return 0; return 0;
} }
static int __init vivi_create_instance(int i) static int __init vivi_create_instance(int inst)
{ {
struct vivi_dev *dev; struct vivi_dev *dev;
struct video_device *vfd; struct video_device *vfd;
int ret; int ret, i;
dev = kzalloc(sizeof(*dev), GFP_KERNEL); dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) if (!dev)
return -ENOMEM; return -ENOMEM;
snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
"%s-%03d", VIVI_MODULE_NAME, i); "%s-%03d", VIVI_MODULE_NAME, inst);
ret = v4l2_device_register(NULL, &dev->v4l2_dev); ret = v4l2_device_register(NULL, &dev->v4l2_dev);
if (ret) if (ret)
goto free_dev; goto free_dev;
...@@ -1375,6 +1375,10 @@ static int __init vivi_create_instance(int i) ...@@ -1375,6 +1375,10 @@ static int __init vivi_create_instance(int i)
video_set_drvdata(vfd, dev); video_set_drvdata(vfd, dev);
/* Set all controls to their default value. */
for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
dev->qctl_regs[i] = vivi_qctrl[i].default_value;
/* Now that everything is fine, let's add it to device list */ /* Now that everything is fine, let's add it to device list */
list_add_tail(&dev->vivi_devlist, &vivi_devlist); list_add_tail(&dev->vivi_devlist, &vivi_devlist);
......
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