aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2012-06-02 06:44:15 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-06-21 10:25:19 -0400
commit1fc21a1979fc799b9e7b3ac35e9864ebc593524b (patch)
tree07f9c56896e3c11675226c84054a8b30481cba93 /drivers
parenta906f62f5779e7b290ecb0d3bfeac27fc8d7c080 (diff)
[media] zr364xx: convert to the control framework
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/zr364xx.c111
1 files changed, 36 insertions, 75 deletions
diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c
index 95fd9906b1ce..974515dd19d6 100644
--- a/drivers/media/video/zr364xx.c
+++ b/drivers/media/video/zr364xx.c
@@ -38,6 +38,7 @@
38#include <media/v4l2-common.h> 38#include <media/v4l2-common.h>
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/videobuf-vmalloc.h> 42#include <media/videobuf-vmalloc.h>
42 43
43 44
@@ -121,11 +122,6 @@ static struct usb_device_id device_table[] = {
121 122
122MODULE_DEVICE_TABLE(usb, device_table); 123MODULE_DEVICE_TABLE(usb, device_table);
123 124
124struct zr364xx_mode {
125 u32 color; /* output video color format */
126 u32 brightness; /* brightness */
127};
128
129/* frame structure */ 125/* frame structure */
130struct zr364xx_framei { 126struct zr364xx_framei {
131 unsigned long ulState; /* ulState:ZR364XX_READ_IDLE, 127 unsigned long ulState; /* ulState:ZR364XX_READ_IDLE,
@@ -175,6 +171,7 @@ struct zr364xx_camera {
175 struct usb_device *udev; /* save off the usb device pointer */ 171 struct usb_device *udev; /* save off the usb device pointer */
176 struct usb_interface *interface;/* the interface for this device */ 172 struct usb_interface *interface;/* the interface for this device */
177 struct v4l2_device v4l2_dev; 173 struct v4l2_device v4l2_dev;
174 struct v4l2_ctrl_handler ctrl_handler;
178 struct video_device vdev; /* v4l video device */ 175 struct video_device vdev; /* v4l video device */
179 int nb; 176 int nb;
180 struct zr364xx_bufferi buffer; 177 struct zr364xx_bufferi buffer;
@@ -199,7 +196,6 @@ struct zr364xx_camera {
199 const struct zr364xx_fmt *fmt; 196 const struct zr364xx_fmt *fmt;
200 struct videobuf_queue vb_vidq; 197 struct videobuf_queue vb_vidq;
201 enum v4l2_buf_type type; 198 enum v4l2_buf_type type;
202 struct zr364xx_mode mode;
203}; 199};
204 200
205/* buffer for one video frame */ 201/* buffer for one video frame */
@@ -767,47 +763,17 @@ static int zr364xx_vidioc_s_input(struct file *file, void *priv,
767 return 0; 763 return 0;
768} 764}
769 765
770static int zr364xx_vidioc_queryctrl(struct file *file, void *priv, 766static int zr364xx_s_ctrl(struct v4l2_ctrl *ctrl)
771 struct v4l2_queryctrl *c)
772{ 767{
773 struct zr364xx_camera *cam; 768 struct zr364xx_camera *cam =
774 769 container_of(ctrl->handler, struct zr364xx_camera, ctrl_handler);
775 if (file == NULL)
776 return -ENODEV;
777 cam = video_drvdata(file);
778
779 switch (c->id) {
780 case V4L2_CID_BRIGHTNESS:
781 c->type = V4L2_CTRL_TYPE_INTEGER;
782 strcpy(c->name, "Brightness");
783 c->minimum = 0;
784 c->maximum = 127;
785 c->step = 1;
786 c->default_value = cam->mode.brightness;
787 c->flags = 0;
788 break;
789 default:
790 return -EINVAL;
791 }
792 return 0;
793}
794
795static int zr364xx_vidioc_s_ctrl(struct file *file, void *priv,
796 struct v4l2_control *c)
797{
798 struct zr364xx_camera *cam;
799 int temp; 770 int temp;
800 771
801 if (file == NULL) 772 switch (ctrl->id) {
802 return -ENODEV;
803 cam = video_drvdata(file);
804
805 switch (c->id) {
806 case V4L2_CID_BRIGHTNESS: 773 case V4L2_CID_BRIGHTNESS:
807 cam->mode.brightness = c->value;
808 /* hardware brightness */ 774 /* hardware brightness */
809 send_control_msg(cam->udev, 1, 0x2001, 0, NULL, 0); 775 send_control_msg(cam->udev, 1, 0x2001, 0, NULL, 0);
810 temp = (0x60 << 8) + 127 - cam->mode.brightness; 776 temp = (0x60 << 8) + 127 - ctrl->val;
811 send_control_msg(cam->udev, 1, temp, 0, NULL, 0); 777 send_control_msg(cam->udev, 1, temp, 0, NULL, 0);
812 break; 778 break;
813 default: 779 default:
@@ -817,25 +783,6 @@ static int zr364xx_vidioc_s_ctrl(struct file *file, void *priv,
817 return 0; 783 return 0;
818} 784}
819 785
820static int zr364xx_vidioc_g_ctrl(struct file *file, void *priv,
821 struct v4l2_control *c)
822{
823 struct zr364xx_camera *cam;
824
825 if (file == NULL)
826 return -ENODEV;
827 cam = video_drvdata(file);
828
829 switch (c->id) {
830 case V4L2_CID_BRIGHTNESS:
831 c->value = cam->mode.brightness;
832 break;
833 default:
834 return -EINVAL;
835 }
836 return 0;
837}
838
839static int zr364xx_vidioc_enum_fmt_vid_cap(struct file *file, 786static int zr364xx_vidioc_enum_fmt_vid_cap(struct file *file,
840 void *priv, struct v4l2_fmtdesc *f) 787 void *priv, struct v4l2_fmtdesc *f)
841{ 788{
@@ -944,7 +891,6 @@ static int zr364xx_vidioc_s_fmt_vid_cap(struct file *file, void *priv,
944 f->fmt.pix.colorspace = 0; 891 f->fmt.pix.colorspace = 0;
945 f->fmt.pix.priv = 0; 892 f->fmt.pix.priv = 0;
946 cam->vb_vidq.field = f->fmt.pix.field; 893 cam->vb_vidq.field = f->fmt.pix.field;
947 cam->mode.color = V4L2_PIX_FMT_JPEG;
948 894
949 if (f->fmt.pix.width == 160 && f->fmt.pix.height == 120) 895 if (f->fmt.pix.width == 160 && f->fmt.pix.height == 120)
950 mode = 1; 896 mode = 1;
@@ -1326,6 +1272,7 @@ static void zr364xx_release(struct v4l2_device *v4l2_dev)
1326 cam->buffer.frame[i].lpvbits = NULL; 1272 cam->buffer.frame[i].lpvbits = NULL;
1327 } 1273 }
1328 1274
1275 v4l2_ctrl_handler_free(&cam->ctrl_handler);
1329 /* release transfer buffer */ 1276 /* release transfer buffer */
1330 kfree(cam->pipe->transfer_buffer); 1277 kfree(cam->pipe->transfer_buffer);
1331 kfree(cam); 1278 kfree(cam);
@@ -1402,6 +1349,10 @@ static unsigned int zr364xx_poll(struct file *file,
1402 return videobuf_poll_stream(file, q, wait); 1349 return videobuf_poll_stream(file, q, wait);
1403} 1350}
1404 1351
1352static const struct v4l2_ctrl_ops zr364xx_ctrl_ops = {
1353 .s_ctrl = zr364xx_s_ctrl,
1354};
1355
1405static const struct v4l2_file_operations zr364xx_fops = { 1356static const struct v4l2_file_operations zr364xx_fops = {
1406 .owner = THIS_MODULE, 1357 .owner = THIS_MODULE,
1407 .open = zr364xx_open, 1358 .open = zr364xx_open,
@@ -1423,9 +1374,6 @@ static const struct v4l2_ioctl_ops zr364xx_ioctl_ops = {
1423 .vidioc_s_input = zr364xx_vidioc_s_input, 1374 .vidioc_s_input = zr364xx_vidioc_s_input,
1424 .vidioc_streamon = zr364xx_vidioc_streamon, 1375 .vidioc_streamon = zr364xx_vidioc_streamon,
1425 .vidioc_streamoff = zr364xx_vidioc_streamoff, 1376 .vidioc_streamoff = zr364xx_vidioc_streamoff,
1426 .vidioc_queryctrl = zr364xx_vidioc_queryctrl,
1427 .vidioc_g_ctrl = zr364xx_vidioc_g_ctrl,
1428 .vidioc_s_ctrl = zr364xx_vidioc_s_ctrl,
1429 .vidioc_reqbufs = zr364xx_vidioc_reqbufs, 1377 .vidioc_reqbufs = zr364xx_vidioc_reqbufs,
1430 .vidioc_querybuf = zr364xx_vidioc_querybuf, 1378 .vidioc_querybuf = zr364xx_vidioc_querybuf,
1431 .vidioc_qbuf = zr364xx_vidioc_qbuf, 1379 .vidioc_qbuf = zr364xx_vidioc_qbuf,
@@ -1510,6 +1458,7 @@ static int zr364xx_probe(struct usb_interface *intf,
1510 struct zr364xx_camera *cam = NULL; 1458 struct zr364xx_camera *cam = NULL;
1511 struct usb_host_interface *iface_desc; 1459 struct usb_host_interface *iface_desc;
1512 struct usb_endpoint_descriptor *endpoint; 1460 struct usb_endpoint_descriptor *endpoint;
1461 struct v4l2_ctrl_handler *hdl;
1513 int err; 1462 int err;
1514 int i; 1463 int i;
1515 1464
@@ -1533,12 +1482,22 @@ static int zr364xx_probe(struct usb_interface *intf,
1533 kfree(cam); 1482 kfree(cam);
1534 return err; 1483 return err;
1535 } 1484 }
1485 hdl = &cam->ctrl_handler;
1486 v4l2_ctrl_handler_init(hdl, 1);
1487 v4l2_ctrl_new_std(hdl, &zr364xx_ctrl_ops,
1488 V4L2_CID_BRIGHTNESS, 0, 127, 1, 64);
1489 if (hdl->error) {
1490 err = hdl->error;
1491 dev_err(&udev->dev, "couldn't register control\n");
1492 goto fail;
1493 }
1536 /* save the init method used by this camera */ 1494 /* save the init method used by this camera */
1537 cam->method = id->driver_info; 1495 cam->method = id->driver_info;
1538 mutex_init(&cam->lock); 1496 mutex_init(&cam->lock);
1539 cam->vdev = zr364xx_template; 1497 cam->vdev = zr364xx_template;
1540 cam->vdev.lock = &cam->lock; 1498 cam->vdev.lock = &cam->lock;
1541 cam->vdev.v4l2_dev = &cam->v4l2_dev; 1499 cam->vdev.v4l2_dev = &cam->v4l2_dev;
1500 cam->vdev.ctrl_handler = &cam->ctrl_handler;
1542 video_set_drvdata(&cam->vdev, cam); 1501 video_set_drvdata(&cam->vdev, cam);
1543 if (debug) 1502 if (debug)
1544 cam->vdev.debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG; 1503 cam->vdev.debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
@@ -1589,7 +1548,6 @@ static int zr364xx_probe(struct usb_interface *intf,
1589 1548
1590 cam->users = 0; 1549 cam->users = 0;
1591 cam->nb = 0; 1550 cam->nb = 0;
1592 cam->mode.brightness = 64;
1593 1551
1594 DBG("dev: %p, udev %p interface %p\n", cam, cam->udev, intf); 1552 DBG("dev: %p, udev %p interface %p\n", cam, cam->udev, intf);
1595 1553
@@ -1605,10 +1563,9 @@ static int zr364xx_probe(struct usb_interface *intf,
1605 } 1563 }
1606 1564
1607 if (!cam->read_endpoint) { 1565 if (!cam->read_endpoint) {
1566 err = -ENOMEM;
1608 dev_err(&intf->dev, "Could not find bulk-in endpoint\n"); 1567 dev_err(&intf->dev, "Could not find bulk-in endpoint\n");
1609 v4l2_device_unregister(&cam->v4l2_dev); 1568 goto fail;
1610 kfree(cam);
1611 return -ENOMEM;
1612 } 1569 }
1613 1570
1614 /* v4l */ 1571 /* v4l */
@@ -1619,24 +1576,28 @@ static int zr364xx_probe(struct usb_interface *intf,
1619 1576
1620 /* load zr364xx board specific */ 1577 /* load zr364xx board specific */
1621 err = zr364xx_board_init(cam); 1578 err = zr364xx_board_init(cam);
1622 if (err) { 1579 if (!err)
1623 kfree(cam); 1580 err = v4l2_ctrl_handler_setup(hdl);
1624 return err; 1581 if (err)
1625 } 1582 goto fail;
1626 1583
1627 spin_lock_init(&cam->slock); 1584 spin_lock_init(&cam->slock);
1628 1585
1629 err = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1); 1586 err = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1);
1630 if (err) { 1587 if (err) {
1631 dev_err(&udev->dev, "video_register_device failed\n"); 1588 dev_err(&udev->dev, "video_register_device failed\n");
1632 v4l2_device_unregister(&cam->v4l2_dev); 1589 goto fail;
1633 kfree(cam);
1634 return err;
1635 } 1590 }
1636 1591
1637 dev_info(&udev->dev, DRIVER_DESC " controlling device %s\n", 1592 dev_info(&udev->dev, DRIVER_DESC " controlling device %s\n",
1638 video_device_node_name(&cam->vdev)); 1593 video_device_node_name(&cam->vdev));
1639 return 0; 1594 return 0;
1595
1596fail:
1597 v4l2_ctrl_handler_free(hdl);
1598 v4l2_device_unregister(&cam->v4l2_dev);
1599 kfree(cam);
1600 return err;
1640} 1601}
1641 1602
1642 1603