From patchwork Sat May 29 14:46:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 103059 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4TEiTkW025649 for ; Sat, 29 May 2010 14:44:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757313Ab0E2Oo1 (ORCPT ); Sat, 29 May 2010 10:44:27 -0400 Received: from smtp-vbr2.xs4all.nl ([194.109.24.22]:2313 "EHLO smtp-vbr2.xs4all.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757126Ab0E2Oo0 (ORCPT ); Sat, 29 May 2010 10:44:26 -0400 Received: from localhost ([84.208.87.21]) by smtp-vbr2.xs4all.nl (8.13.8/8.13.8) with ESMTP id o4TEiGDl076475 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 29 May 2010 16:44:24 +0200 (CEST) (envelope-from hverkuil@xs4all.nl) Message-Id: <82ab009b026cbeaa52473d40b0515c3edda2ef3a.1275143672.git.hverkuil@xs4all.nl> In-Reply-To: References: From: Hans Verkuil Date: Sat, 29 May 2010 16:46:08 +0200 Subject: [PATCH 04/15] [RFCv4] v4l2: hook up the new control framework into the core framework To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com X-Virus-Scanned: by XS4ALL Virus Scanner Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sat, 29 May 2010 14:44:29 +0000 (UTC) diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c index 0ca7ec9..773ffe1 100644 --- a/drivers/media/video/v4l2-dev.c +++ b/drivers/media/video/v4l2-dev.c @@ -447,8 +447,12 @@ static int __video_register_device(struct video_device *vdev, int type, int nr, vdev->vfl_type = type; vdev->cdev = NULL; - if (vdev->v4l2_dev && vdev->v4l2_dev->dev) - vdev->parent = vdev->v4l2_dev->dev; + if (vdev->v4l2_dev) { + if (vdev->v4l2_dev->dev) + vdev->parent = vdev->v4l2_dev->dev; + if (vdev->ctrl_handler == NULL) + vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler; + } /* Part 2: find a free minor, device node number and device index. */ #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c index 5a7dc4a..0b08f96 100644 --- a/drivers/media/video/v4l2-device.c +++ b/drivers/media/video/v4l2-device.c @@ -26,6 +26,7 @@ #endif #include #include +#include int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) { @@ -115,6 +116,8 @@ EXPORT_SYMBOL_GPL(v4l2_device_unregister); int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, struct v4l2_subdev *sd) { + int err; + /* Check for valid input */ if (v4l2_dev == NULL || sd == NULL || !sd->name[0]) return -EINVAL; @@ -122,6 +125,10 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, WARN_ON(sd->v4l2_dev != NULL); if (!try_module_get(sd->owner)) return -ENODEV; + /* This just returns 0 if either of the two args is NULL */ + err = v4l2_ctrl_add_handler(v4l2_dev->ctrl_handler, sd->ctrl_handler); + if (err) + return err; sd->v4l2_dev = v4l2_dev; spin_lock(&v4l2_dev->lock); list_add_tail(&sd->list, &v4l2_dev->subdevs); diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c index 0395b1c..94776c3 100644 --- a/drivers/media/video/v4l2-ioctl.c +++ b/drivers/media/video/v4l2-ioctl.c @@ -25,6 +25,7 @@ #endif #include #include +#include #include #include #include @@ -1258,9 +1259,12 @@ static long __video_do_ioctl(struct file *file, { struct v4l2_queryctrl *p = arg; - if (!ops->vidioc_queryctrl) + if (vfd->ctrl_handler) + ret = v4l2_queryctrl(vfd->ctrl_handler, p); + else if (ops->vidioc_queryctrl) + ret = ops->vidioc_queryctrl(file, fh, p); + else break; - ret = ops->vidioc_queryctrl(file, fh, p); if (!ret) dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, " "step=%d, default=%d, flags=0x%08x\n", @@ -1275,7 +1279,9 @@ static long __video_do_ioctl(struct file *file, { struct v4l2_control *p = arg; - if (ops->vidioc_g_ctrl) + if (vfd->ctrl_handler) + ret = v4l2_g_ctrl(vfd->ctrl_handler, p); + else if (ops->vidioc_g_ctrl) ret = ops->vidioc_g_ctrl(file, fh, p); else if (ops->vidioc_g_ext_ctrls) { struct v4l2_ext_controls ctrls; @@ -1305,11 +1311,16 @@ static long __video_do_ioctl(struct file *file, struct v4l2_ext_controls ctrls; struct v4l2_ext_control ctrl; - if (!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls) + if (!vfd->ctrl_handler && + !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls) break; dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value); + if (vfd->ctrl_handler) { + ret = v4l2_s_ctrl(vfd->ctrl_handler, p); + break; + } if (ops->vidioc_s_ctrl) { ret = ops->vidioc_s_ctrl(file, fh, p); break; @@ -1331,10 +1342,12 @@ static long __video_do_ioctl(struct file *file, struct v4l2_ext_controls *p = arg; p->error_idx = p->count; - if (!ops->vidioc_g_ext_ctrls) - break; - if (check_ext_ctrls(p, 0)) + if (vfd->ctrl_handler) + ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p); + else if (ops->vidioc_g_ext_ctrls && check_ext_ctrls(p, 0)) ret = ops->vidioc_g_ext_ctrls(file, fh, p); + else + break; v4l_print_ext_ctrls(cmd, vfd, p, !ret); break; } @@ -1343,10 +1356,12 @@ static long __video_do_ioctl(struct file *file, struct v4l2_ext_controls *p = arg; p->error_idx = p->count; - if (!ops->vidioc_s_ext_ctrls) + if (!vfd->ctrl_handler && !ops->vidioc_s_ext_ctrls) break; v4l_print_ext_ctrls(cmd, vfd, p, 1); - if (check_ext_ctrls(p, 0)) + if (vfd->ctrl_handler) + ret = v4l2_s_ext_ctrls(vfd->ctrl_handler, p); + else if (check_ext_ctrls(p, 0)) ret = ops->vidioc_s_ext_ctrls(file, fh, p); break; } @@ -1355,10 +1370,12 @@ static long __video_do_ioctl(struct file *file, struct v4l2_ext_controls *p = arg; p->error_idx = p->count; - if (!ops->vidioc_try_ext_ctrls) + if (!vfd->ctrl_handler && !ops->vidioc_try_ext_ctrls) break; v4l_print_ext_ctrls(cmd, vfd, p, 1); - if (check_ext_ctrls(p, 0)) + if (vfd->ctrl_handler) + ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p); + else if (check_ext_ctrls(p, 0)) ret = ops->vidioc_try_ext_ctrls(file, fh, p); break; } @@ -1366,9 +1383,12 @@ static long __video_do_ioctl(struct file *file, { struct v4l2_querymenu *p = arg; - if (!ops->vidioc_querymenu) + if (vfd->ctrl_handler) + ret = v4l2_querymenu(vfd->ctrl_handler, p); + else if (ops->vidioc_querymenu) + ret = ops->vidioc_querymenu(file, fh, p); + else break; - ret = ops->vidioc_querymenu(file, fh, p); if (!ret) dbgarg(cmd, "id=0x%x, index=%d, name=%s\n", p->id, p->index, p->name);