aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/zr364xx.c
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2012-06-02 06:57:29 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-06-21 10:26:32 -0400
commit5d317abe7bd1b448efaa4ad0813c19f866aa7a4b (patch)
tree43006be064eafbae4a0d434c1cfc85f6763cf0ab /drivers/media/video/zr364xx.c
parentdf462902ea81de9931ea33c3cb3b50ae819db296 (diff)
[media] zr364xx: add support for control events
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/zr364xx.c')
-rw-r--r--drivers/media/video/zr364xx.c45
1 files changed, 18 insertions, 27 deletions
diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c
index a1729b39a85b..bdf562dbaf02 100644
--- a/drivers/media/video/zr364xx.c
+++ b/drivers/media/video/zr364xx.c
@@ -39,6 +39,8 @@
39#include <media/v4l2-ioctl.h> 39#include <media/v4l2-ioctl.h>
40#include <media/v4l2-device.h> 40#include <media/v4l2-device.h>
41#include <media/v4l2-ctrls.h> 41#include <media/v4l2-ctrls.h>
42#include <media/v4l2-fh.h>
43#include <media/v4l2-event.h>
42#include <media/videobuf-vmalloc.h> 44#include <media/videobuf-vmalloc.h>
43 45
44 46
@@ -195,7 +197,6 @@ struct zr364xx_camera {
195 197
196 const struct zr364xx_fmt *fmt; 198 const struct zr364xx_fmt *fmt;
197 struct videobuf_queue vb_vidq; 199 struct videobuf_queue vb_vidq;
198 enum v4l2_buf_type type;
199}; 200};
200 201
201/* buffer for one video frame */ 202/* buffer for one video frame */
@@ -473,8 +474,7 @@ static ssize_t zr364xx_read(struct file *file, char __user *buf, size_t count,
473 if (mutex_lock_interruptible(&cam->lock)) 474 if (mutex_lock_interruptible(&cam->lock))
474 return -ERESTARTSYS; 475 return -ERESTARTSYS;
475 476
476 if (cam->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && 477 if (zr364xx_vidioc_streamon(file, cam, V4L2_BUF_TYPE_VIDEO_CAPTURE) == 0) {
477 zr364xx_vidioc_streamon(file, cam, cam->type) == 0) {
478 DBG("%s: reading %d bytes at pos %d.\n", __func__, (int) count, 478 DBG("%s: reading %d bytes at pos %d.\n", __func__, (int) count,
479 (int) *ppos); 479 (int) *ppos);
480 480
@@ -1146,14 +1146,8 @@ static int zr364xx_vidioc_streamon(struct file *file, void *priv,
1146 1146
1147 DBG("%s\n", __func__); 1147 DBG("%s\n", __func__);
1148 1148
1149 if (cam->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1149 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1150 dev_err(&cam->udev->dev, "invalid fh type0\n");
1151 return -EINVAL; 1150 return -EINVAL;
1152 }
1153 if (cam->type != type) {
1154 dev_err(&cam->udev->dev, "invalid fh type1\n");
1155 return -EINVAL;
1156 }
1157 1151
1158 if (!res_get(cam)) { 1152 if (!res_get(cam)) {
1159 dev_err(&cam->udev->dev, "stream busy\n"); 1153 dev_err(&cam->udev->dev, "stream busy\n");
@@ -1183,14 +1177,8 @@ static int zr364xx_vidioc_streamoff(struct file *file, void *priv,
1183 struct zr364xx_camera *cam = video_drvdata(file); 1177 struct zr364xx_camera *cam = video_drvdata(file);
1184 1178
1185 DBG("%s\n", __func__); 1179 DBG("%s\n", __func__);
1186 if (cam->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1180 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1187 dev_err(&cam->udev->dev, "invalid fh type0\n");
1188 return -EINVAL; 1181 return -EINVAL;
1189 }
1190 if (cam->type != type) {
1191 dev_err(&cam->udev->dev, "invalid fh type1\n");
1192 return -EINVAL;
1193 }
1194 zr364xx_stop_acquire(cam); 1182 zr364xx_stop_acquire(cam);
1195 res = videobuf_streamoff(&cam->vb_vidq); 1183 res = videobuf_streamoff(&cam->vb_vidq);
1196 if (res < 0) 1184 if (res < 0)
@@ -1203,7 +1191,6 @@ static int zr364xx_vidioc_streamoff(struct file *file, void *priv,
1203/* open the camera */ 1191/* open the camera */
1204static int zr364xx_open(struct file *file) 1192static int zr364xx_open(struct file *file)
1205{ 1193{
1206 struct video_device *vdev = video_devdata(file);
1207 struct zr364xx_camera *cam = video_drvdata(file); 1194 struct zr364xx_camera *cam = video_drvdata(file);
1208 struct usb_device *udev = cam->udev; 1195 struct usb_device *udev = cam->udev;
1209 int i, err; 1196 int i, err;
@@ -1218,6 +1205,10 @@ static int zr364xx_open(struct file *file)
1218 goto out; 1205 goto out;
1219 } 1206 }
1220 1207
1208 err = v4l2_fh_open(file);
1209 if (err)
1210 goto out;
1211
1221 for (i = 0; init[cam->method][i].size != -1; i++) { 1212 for (i = 0; init[cam->method][i].size != -1; i++) {
1222 err = 1213 err =
1223 send_control_msg(udev, 1, init[cam->method][i].value, 1214 send_control_msg(udev, 1, init[cam->method][i].value,
@@ -1226,19 +1217,18 @@ static int zr364xx_open(struct file *file)
1226 if (err < 0) { 1217 if (err < 0) {
1227 dev_err(&cam->udev->dev, 1218 dev_err(&cam->udev->dev,
1228 "error during open sequence: %d\n", i); 1219 "error during open sequence: %d\n", i);
1220 v4l2_fh_release(file);
1229 goto out; 1221 goto out;
1230 } 1222 }
1231 } 1223 }
1232 1224
1233 cam->skip = 2; 1225 cam->skip = 2;
1234 cam->users++; 1226 cam->users++;
1235 file->private_data = vdev;
1236 cam->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1237 cam->fmt = formats; 1227 cam->fmt = formats;
1238 1228
1239 videobuf_queue_vmalloc_init(&cam->vb_vidq, &zr364xx_video_qops, 1229 videobuf_queue_vmalloc_init(&cam->vb_vidq, &zr364xx_video_qops,
1240 NULL, &cam->slock, 1230 NULL, &cam->slock,
1241 cam->type, 1231 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1242 V4L2_FIELD_NONE, 1232 V4L2_FIELD_NONE,
1243 sizeof(struct zr364xx_buffer), cam, &cam->lock); 1233 sizeof(struct zr364xx_buffer), cam, &cam->lock);
1244 1234
@@ -1301,7 +1291,6 @@ static int zr364xx_close(struct file *file)
1301 } 1291 }
1302 1292
1303 cam->users--; 1293 cam->users--;
1304 file->private_data = NULL;
1305 1294
1306 for (i = 0; i < 2; i++) { 1295 for (i = 0; i < 2; i++) {
1307 send_control_msg(udev, 1, init[cam->method][i].value, 1296 send_control_msg(udev, 1, init[cam->method][i].value,
@@ -1314,7 +1303,7 @@ static int zr364xx_close(struct file *file)
1314 */ 1303 */
1315 mdelay(100); 1304 mdelay(100);
1316 mutex_unlock(&cam->lock); 1305 mutex_unlock(&cam->lock);
1317 return 0; 1306 return v4l2_fh_release(file);
1318} 1307}
1319 1308
1320 1309
@@ -1342,12 +1331,11 @@ static unsigned int zr364xx_poll(struct file *file,
1342{ 1331{
1343 struct zr364xx_camera *cam = video_drvdata(file); 1332 struct zr364xx_camera *cam = video_drvdata(file);
1344 struct videobuf_queue *q = &cam->vb_vidq; 1333 struct videobuf_queue *q = &cam->vb_vidq;
1345 _DBG("%s\n", __func__); 1334 unsigned res = v4l2_ctrl_poll(file, wait);
1346 1335
1347 if (cam->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1336 _DBG("%s\n", __func__);
1348 return POLLERR;
1349 1337
1350 return videobuf_poll_stream(file, q, wait); 1338 return res | videobuf_poll_stream(file, q, wait);
1351} 1339}
1352 1340
1353static const struct v4l2_ctrl_ops zr364xx_ctrl_ops = { 1341static const struct v4l2_ctrl_ops zr364xx_ctrl_ops = {
@@ -1379,6 +1367,9 @@ static const struct v4l2_ioctl_ops zr364xx_ioctl_ops = {
1379 .vidioc_querybuf = zr364xx_vidioc_querybuf, 1367 .vidioc_querybuf = zr364xx_vidioc_querybuf,
1380 .vidioc_qbuf = zr364xx_vidioc_qbuf, 1368 .vidioc_qbuf = zr364xx_vidioc_qbuf,
1381 .vidioc_dqbuf = zr364xx_vidioc_dqbuf, 1369 .vidioc_dqbuf = zr364xx_vidioc_dqbuf,
1370 .vidioc_log_status = v4l2_ctrl_log_status,
1371 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1372 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1382}; 1373};
1383 1374
1384static struct video_device zr364xx_template = { 1375static struct video_device zr364xx_template = {