Message ID | 1434127598-11719-5-git-send-email-ricardo.ribalda@gmail.com (mailing list archive) |
---|---|
State | Superseded, archived |
Delegated to: | Hans Verkuil |
Headers |
Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from <linux-media-owner@vger.kernel.org>) id 1Z3S6f-0000jJ-Bn; Fri, 12 Jun 2015 18:47:01 +0200 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.76/mailfrontend-8) with esmtp id 1Z3S6d-0004Nb-kA; Fri, 12 Jun 2015 18:47:01 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751850AbbFLQqy (ORCPT <rfc822;mkrufky@linuxtv.org> + 1 other); Fri, 12 Jun 2015 12:46:54 -0400 Received: from mail-la0-f43.google.com ([209.85.215.43]:34533 "EHLO mail-la0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751125AbbFLQqq (ORCPT <rfc822;linux-media@vger.kernel.org>); Fri, 12 Jun 2015 12:46:46 -0400 Received: by laew7 with SMTP id w7so24637572lae.1 for <linux-media@vger.kernel.org>; Fri, 12 Jun 2015 09:46:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pxeKuZCwaryhdjn9zUOqGrm2PvHr32NGG7g+CtfV14c=; b=NqOLGqdYJnzv68qiYKk4DATEycltg5Y/LyY1zFpLDyYWtWkI7ukT5ixHwOgcIGv/aF zMjX+CVOqlJbc5pgNTuIne3SgSXqwRNnczFT6Yuk2003LDYuVTcHgqXkFOP7XRSbyVIa cppHtbFQXWNHixbY+2Y+vpkHyE78POpRTrrV8/f99/PFhTyvZl4Fm+Gxe4Wafm6Ta3xt f5B7T7D2vMcL2QbJOEq1xI9kfSQD6Q6NAb3CSQM5pXVVQzh0TYrLtiWVuXexfxeOF9xU Xir0neM9HELaNFGntBCNTkHIenvI6b5IJytitOc9cnemBmdUWpJlVoj3S29yC+J2iVJn 13bA== X-Received: by 10.112.146.97 with SMTP id tb1mr16429632lbb.12.1434127605541; Fri, 12 Jun 2015 09:46:45 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by mx.google.com with ESMTPSA id s8sm927103las.29.2015.06.12.09.46.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jun 2015 09:46:45 -0700 (PDT) From: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> To: Hans Verkuil <hans.verkuil@cisco.com>, Sakari Ailus <sakari.ailus@linux.intel.com>, Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>, Mauro Carvalho Chehab <mchehab@osg.samsung.com>, Guennadi Liakhovetski <g.liakhovetski@gmx.de>, linux-media@vger.kernel.org Cc: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> Subject: [RFC v3 04/19] media/usb/uvc: Implement vivioc_g_def_ext_ctrls Date: Fri, 12 Jun 2015 18:46:23 +0200 Message-Id: <1434127598-11719-5-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1434127598-11719-1-git-send-email-ricardo.ribalda@gmail.com> References: <1434127598-11719-1-git-send-email-ricardo.ribalda@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2015.6.12.163617 X-PMX-Spam: Gauge=IIIIIIIII, Probability=9%, Report=' FORGED_FROM_GMAIL 0.1, MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODYTEXTP_SIZE_3000_LESS 0, BODY_SIZE_1900_1999 0, BODY_SIZE_2000_LESS 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, DKIM_SIGNATURE 0, FROM_NAME_PHRASE 0, REFERENCES 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __FRAUD_BODY_WEBMAIL 0, __FRAUD_WEBMAIL 0, __FRAUD_WEBMAIL_FROM 0, __FROM_GMAIL 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MULTIPLE_RCPTS_TO_X5 0, __PHISH_SPEAR_STRUCTURE_1 0, __REFERENCES 0, __SANE_MSGID 0, __TO_MALFORMED_2 0, __URI_NO_WWW 0, __URI_NS , __YOUTUBE_RCVD 0' |
Commit Message
Ricardo Ribalda Delgado
June 12, 2015, 4:46 p.m. UTC
Callback needed by ioctl VIDIOC_G_DEF_EXT_CTRLS as this driver does not
use the controller framework.
Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
drivers/media/usb/uvc/uvc_v4l2.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
Comments
Laurent, Can you review/ack this since it touches on uvc? Thanks! Hans On 06/12/2015 06:46 PM, Ricardo Ribalda Delgado wrote: > Callback needed by ioctl VIDIOC_G_DEF_EXT_CTRLS as this driver does not > use the controller framework. > > Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> > --- > drivers/media/usb/uvc/uvc_v4l2.c | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c > index 2764f43607c1..e2698a77138a 100644 > --- a/drivers/media/usb/uvc/uvc_v4l2.c > +++ b/drivers/media/usb/uvc/uvc_v4l2.c > @@ -1001,6 +1001,35 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, > return uvc_ctrl_rollback(handle); > } > > +static int uvc_ioctl_g_def_ext_ctrls(struct file *file, void *fh, > + struct v4l2_ext_controls *ctrls) > +{ > + struct uvc_fh *handle = fh; > + struct uvc_video_chain *chain = handle->chain; > + struct v4l2_ext_control *ctrl = ctrls->controls; > + unsigned int i; > + int ret; > + struct v4l2_queryctrl qc; > + > + ret = uvc_ctrl_begin(chain); > + if (ret < 0) > + return ret; > + > + for (i = 0; i < ctrls->count; ++ctrl, ++i) { > + qc.id = ctrl->id; > + ret = uvc_query_v4l2_ctrl(chain, &qc); > + if (ret < 0) { > + ctrls->error_idx = i; > + return ret; > + } > + ctrl->value = qc.default_value; > + } > + > + ctrls->error_idx = 0; > + > + return 0; > +} > + > static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle, > struct v4l2_ext_controls *ctrls, > bool commit) > @@ -1500,6 +1529,7 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops = { > .vidioc_g_ctrl = uvc_ioctl_g_ctrl, > .vidioc_s_ctrl = uvc_ioctl_s_ctrl, > .vidioc_g_ext_ctrls = uvc_ioctl_g_ext_ctrls, > + .vidioc_g_def_ext_ctrls = uvc_ioctl_g_def_ext_ctrls, > .vidioc_s_ext_ctrls = uvc_ioctl_s_ext_ctrls, > .vidioc_try_ext_ctrls = uvc_ioctl_try_ext_ctrls, > .vidioc_querymenu = uvc_ioctl_querymenu, > -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Ricardo, Thank you for the patch. On Friday 12 June 2015 18:46:23 Ricardo Ribalda Delgado wrote: > Callback needed by ioctl VIDIOC_G_DEF_EXT_CTRLS as this driver does not > use the controller framework. > > Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> > --- > drivers/media/usb/uvc/uvc_v4l2.c | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/drivers/media/usb/uvc/uvc_v4l2.c > b/drivers/media/usb/uvc/uvc_v4l2.c index 2764f43607c1..e2698a77138a 100644 > --- a/drivers/media/usb/uvc/uvc_v4l2.c > +++ b/drivers/media/usb/uvc/uvc_v4l2.c > @@ -1001,6 +1001,35 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, > void *fh, return uvc_ctrl_rollback(handle); > } > > +static int uvc_ioctl_g_def_ext_ctrls(struct file *file, void *fh, > + struct v4l2_ext_controls *ctrls) > +{ > + struct uvc_fh *handle = fh; > + struct uvc_video_chain *chain = handle->chain; > + struct v4l2_ext_control *ctrl = ctrls->controls; > + unsigned int i; > + int ret; > + struct v4l2_queryctrl qc; > + > + ret = uvc_ctrl_begin(chain); There's no need to call uvc_ctrl_begin() here (and if there was, you'd have to call uvc_ctrl_rollback() or uvc_ctrl_commit() before returning). > + if (ret < 0) > + return ret; > + > + for (i = 0; i < ctrls->count; ++ctrl, ++i) { > + qc.id = ctrl->id; > + ret = uvc_query_v4l2_ctrl(chain, &qc); > + if (ret < 0) { > + ctrls->error_idx = i; > + return ret; > + } > + ctrl->value = qc.default_value; > + } > + > + ctrls->error_idx = 0; > + > + return 0; > +} Instead of open-coding this in multiple drivers, how about adding a helper function to the core ? Something like (totally untested) int v4l2_ioctl_g_def_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *ctrls) { struct video_device *vdev = video_devdata(file); unsigned int i; int ret; for (i = 0; i < ctrls->count; ++i) { struct v4l2_queryctrl qc; qc.id = ctrl->id; ret = vdev->ioctl_ops->vidioc_queryctrl(file, fh, &qc); if (ret < 0) { ctrls->error_idx = i; return ret; } ctrls->controls[i].value = qc.default_value; } ctrls->error_idx = 0; return 0; } The function could be called by v4l_g_def_ext_ctrls() when ops- >vidioc_g_def_ext_ctrls is NULL. > static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle, > struct v4l2_ext_controls *ctrls, > bool commit) > @@ -1500,6 +1529,7 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops = { > .vidioc_g_ctrl = uvc_ioctl_g_ctrl, > .vidioc_s_ctrl = uvc_ioctl_s_ctrl, > .vidioc_g_ext_ctrls = uvc_ioctl_g_ext_ctrls, > + .vidioc_g_def_ext_ctrls = uvc_ioctl_g_def_ext_ctrls, > .vidioc_s_ext_ctrls = uvc_ioctl_s_ext_ctrls, > .vidioc_try_ext_ctrls = uvc_ioctl_try_ext_ctrls, > .vidioc_querymenu = uvc_ioctl_querymenu,
On 07/15/15 23:05, Laurent Pinchart wrote: > Hi Ricardo, > > Thank you for the patch. > > On Friday 12 June 2015 18:46:23 Ricardo Ribalda Delgado wrote: >> Callback needed by ioctl VIDIOC_G_DEF_EXT_CTRLS as this driver does not >> use the controller framework. >> >> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> >> --- >> drivers/media/usb/uvc/uvc_v4l2.c | 30 ++++++++++++++++++++++++++++++ >> 1 file changed, 30 insertions(+) >> >> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c >> b/drivers/media/usb/uvc/uvc_v4l2.c index 2764f43607c1..e2698a77138a 100644 >> --- a/drivers/media/usb/uvc/uvc_v4l2.c >> +++ b/drivers/media/usb/uvc/uvc_v4l2.c >> @@ -1001,6 +1001,35 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, >> void *fh, return uvc_ctrl_rollback(handle); >> } >> >> +static int uvc_ioctl_g_def_ext_ctrls(struct file *file, void *fh, >> + struct v4l2_ext_controls *ctrls) >> +{ >> + struct uvc_fh *handle = fh; >> + struct uvc_video_chain *chain = handle->chain; >> + struct v4l2_ext_control *ctrl = ctrls->controls; >> + unsigned int i; >> + int ret; >> + struct v4l2_queryctrl qc; >> + >> + ret = uvc_ctrl_begin(chain); > > There's no need to call uvc_ctrl_begin() here (and if there was, you'd have to > call uvc_ctrl_rollback() or uvc_ctrl_commit() before returning). > >> + if (ret < 0) >> + return ret; >> + >> + for (i = 0; i < ctrls->count; ++ctrl, ++i) { >> + qc.id = ctrl->id; >> + ret = uvc_query_v4l2_ctrl(chain, &qc); >> + if (ret < 0) { >> + ctrls->error_idx = i; >> + return ret; >> + } >> + ctrl->value = qc.default_value; >> + } >> + >> + ctrls->error_idx = 0; >> + >> + return 0; >> +} > > Instead of open-coding this in multiple drivers, how about adding a helper > function to the core ? Something like (totally untested) It's only open-coded in drivers that do not use the control framework. For drivers that use the control framework it is completely transparent. Regards, Hans > > int v4l2_ioctl_g_def_ext_ctrls(struct file *file, void *fh, > struct v4l2_ext_controls *ctrls) > { > struct video_device *vdev = video_devdata(file); > unsigned int i; > int ret; > > for (i = 0; i < ctrls->count; ++i) { > struct v4l2_queryctrl qc; > > qc.id = ctrl->id; > ret = vdev->ioctl_ops->vidioc_queryctrl(file, fh, &qc); > if (ret < 0) { > ctrls->error_idx = i; > return ret; > } > > ctrls->controls[i].value = qc.default_value; > } > > ctrls->error_idx = 0; > > return 0; > } > > The function could be called by v4l_g_def_ext_ctrls() when ops- >> vidioc_g_def_ext_ctrls is NULL. > >> static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle, >> struct v4l2_ext_controls *ctrls, >> bool commit) >> @@ -1500,6 +1529,7 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops = { >> .vidioc_g_ctrl = uvc_ioctl_g_ctrl, >> .vidioc_s_ctrl = uvc_ioctl_s_ctrl, >> .vidioc_g_ext_ctrls = uvc_ioctl_g_ext_ctrls, >> + .vidioc_g_def_ext_ctrls = uvc_ioctl_g_def_ext_ctrls, >> .vidioc_s_ext_ctrls = uvc_ioctl_s_ext_ctrls, >> .vidioc_try_ext_ctrls = uvc_ioctl_try_ext_ctrls, >> .vidioc_querymenu = uvc_ioctl_querymenu, > -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Hans, On Thursday 16 July 2015 09:38:11 Hans Verkuil wrote: > On 07/15/15 23:05, Laurent Pinchart wrote: > > On Friday 12 June 2015 18:46:23 Ricardo Ribalda Delgado wrote: > >> Callback needed by ioctl VIDIOC_G_DEF_EXT_CTRLS as this driver does not > >> use the controller framework. > >> > >> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> > >> --- > >> > >> drivers/media/usb/uvc/uvc_v4l2.c | 30 ++++++++++++++++++++++++++++++ > >> 1 file changed, 30 insertions(+) > >> > >> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c > >> b/drivers/media/usb/uvc/uvc_v4l2.c index 2764f43607c1..e2698a77138a > >> 100644 > >> --- a/drivers/media/usb/uvc/uvc_v4l2.c > >> +++ b/drivers/media/usb/uvc/uvc_v4l2.c > >> @@ -1001,6 +1001,35 @@ static int uvc_ioctl_g_ext_ctrls(struct file > >> *file, void *fh, > >> return uvc_ctrl_rollback(handle); > >> } > >> > >> +static int uvc_ioctl_g_def_ext_ctrls(struct file *file, void *fh, > >> + struct v4l2_ext_controls *ctrls) > >> +{ > >> + struct uvc_fh *handle = fh; > >> + struct uvc_video_chain *chain = handle->chain; > >> + struct v4l2_ext_control *ctrl = ctrls->controls; > >> + unsigned int i; > >> + int ret; > >> + struct v4l2_queryctrl qc; > >> + > >> + ret = uvc_ctrl_begin(chain); > > > > There's no need to call uvc_ctrl_begin() here (and if there was, you'd > > have to call uvc_ctrl_rollback() or uvc_ctrl_commit() before returning). > > > >> + if (ret < 0) > >> + return ret; > >> + > >> + for (i = 0; i < ctrls->count; ++ctrl, ++i) { > >> + qc.id = ctrl->id; > >> + ret = uvc_query_v4l2_ctrl(chain, &qc); > >> + if (ret < 0) { > >> + ctrls->error_idx = i; > >> + return ret; > >> + } > >> + ctrl->value = qc.default_value; > >> + } > >> + > >> + ctrls->error_idx = 0; > >> + > >> + return 0; > >> +} > > > > Instead of open-coding this in multiple drivers, how about adding a helper > > function to the core ? Something like (totally untested) > > It's only open-coded in drivers that do not use the control framework. For > drivers that use the control framework it is completely transparent. Sure, but still, the same function is implemented several times while a single implementation could do. I'd prefer having it in the core until all (or all but one) drivers are converted to the control framework. > > int v4l2_ioctl_g_def_ext_ctrls(struct file *file, void *fh, > > struct v4l2_ext_controls *ctrls) > > { > > struct video_device *vdev = video_devdata(file); > > unsigned int i; > > int ret; > > > > for (i = 0; i < ctrls->count; ++i) { > > struct v4l2_queryctrl qc; > > > > qc.id = ctrl->id; > > ret = vdev->ioctl_ops->vidioc_queryctrl(file, fh, &qc); > > if (ret < 0) { > > ctrls->error_idx = i; > > return ret; > > } > > ctrls->controls[i].value = qc.default_value; > > } > > ctrls->error_idx = 0; > > > > return 0; > > } > > > > The function could be called by v4l_g_def_ext_ctrls() when ops-> > > vidioc_g_def_ext_ctrls is NULL.
On 07/16/15 10:11, Laurent Pinchart wrote: > Hi Hans, > > On Thursday 16 July 2015 09:38:11 Hans Verkuil wrote: >> On 07/15/15 23:05, Laurent Pinchart wrote: >>> On Friday 12 June 2015 18:46:23 Ricardo Ribalda Delgado wrote: >>>> Callback needed by ioctl VIDIOC_G_DEF_EXT_CTRLS as this driver does not >>>> use the controller framework. >>>> >>>> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> >>>> --- >>>> >>>> drivers/media/usb/uvc/uvc_v4l2.c | 30 ++++++++++++++++++++++++++++++ >>>> 1 file changed, 30 insertions(+) >>>> >>>> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c >>>> b/drivers/media/usb/uvc/uvc_v4l2.c index 2764f43607c1..e2698a77138a >>>> 100644 >>>> --- a/drivers/media/usb/uvc/uvc_v4l2.c >>>> +++ b/drivers/media/usb/uvc/uvc_v4l2.c >>>> @@ -1001,6 +1001,35 @@ static int uvc_ioctl_g_ext_ctrls(struct file >>>> *file, void *fh, >>>> return uvc_ctrl_rollback(handle); >>>> } >>>> >>>> +static int uvc_ioctl_g_def_ext_ctrls(struct file *file, void *fh, >>>> + struct v4l2_ext_controls *ctrls) >>>> +{ >>>> + struct uvc_fh *handle = fh; >>>> + struct uvc_video_chain *chain = handle->chain; >>>> + struct v4l2_ext_control *ctrl = ctrls->controls; >>>> + unsigned int i; >>>> + int ret; >>>> + struct v4l2_queryctrl qc; >>>> + >>>> + ret = uvc_ctrl_begin(chain); >>> >>> There's no need to call uvc_ctrl_begin() here (and if there was, you'd >>> have to call uvc_ctrl_rollback() or uvc_ctrl_commit() before returning). >>> >>>> + if (ret < 0) >>>> + return ret; >>>> + >>>> + for (i = 0; i < ctrls->count; ++ctrl, ++i) { >>>> + qc.id = ctrl->id; >>>> + ret = uvc_query_v4l2_ctrl(chain, &qc); >>>> + if (ret < 0) { >>>> + ctrls->error_idx = i; >>>> + return ret; >>>> + } >>>> + ctrl->value = qc.default_value; >>>> + } >>>> + >>>> + ctrls->error_idx = 0; >>>> + >>>> + return 0; >>>> +} >>> >>> Instead of open-coding this in multiple drivers, how about adding a helper >>> function to the core ? Something like (totally untested) >> >> It's only open-coded in drivers that do not use the control framework. For >> drivers that use the control framework it is completely transparent. > > Sure, but still, the same function is implemented several times while a single > implementation could do. I'd prefer having it in the core until all (or all > but one) drivers are converted to the control framework. There are only three drivers that need to implement this manually: uvc, saa7164 and pvrusb2. That's not enough to warrant moving this into the core. One of these days I should sit down and convert saa7164 to the control framework. That shouldn't be too difficult. Regards, Hans > >>> int v4l2_ioctl_g_def_ext_ctrls(struct file *file, void *fh, >>> struct v4l2_ext_controls *ctrls) >>> { >>> struct video_device *vdev = video_devdata(file); >>> unsigned int i; >>> int ret; >>> >>> for (i = 0; i < ctrls->count; ++i) { >>> struct v4l2_queryctrl qc; >>> >>> qc.id = ctrl->id; >>> ret = vdev->ioctl_ops->vidioc_queryctrl(file, fh, &qc); >>> if (ret < 0) { >>> ctrls->error_idx = i; >>> return ret; >>> } >>> ctrls->controls[i].value = qc.default_value; >>> } >>> ctrls->error_idx = 0; >>> >>> return 0; >>> } >>> >>> The function could be called by v4l_g_def_ext_ctrls() when ops-> >>> vidioc_g_def_ext_ctrls is NULL. > -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thursday 16 July 2015 10:23:03 Hans Verkuil wrote: > On 07/16/15 10:11, Laurent Pinchart wrote: > > On Thursday 16 July 2015 09:38:11 Hans Verkuil wrote: > >> On 07/15/15 23:05, Laurent Pinchart wrote: > >>> On Friday 12 June 2015 18:46:23 Ricardo Ribalda Delgado wrote: > >>>> Callback needed by ioctl VIDIOC_G_DEF_EXT_CTRLS as this driver does not > >>>> use the controller framework. > >>>> > >>>> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> > >>>> --- > >>>> > >>>> drivers/media/usb/uvc/uvc_v4l2.c | 30 ++++++++++++++++++++++++++++++ > >>>> 1 file changed, 30 insertions(+) > >>>> > >>>> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c > >>>> b/drivers/media/usb/uvc/uvc_v4l2.c index 2764f43607c1..e2698a77138a > >>>> 100644 > >>>> --- a/drivers/media/usb/uvc/uvc_v4l2.c > >>>> +++ b/drivers/media/usb/uvc/uvc_v4l2.c > >>>> @@ -1001,6 +1001,35 @@ static int uvc_ioctl_g_ext_ctrls(struct file > >>>> *file, void *fh, > >>>> return uvc_ctrl_rollback(handle); > >>>> } > >>>> > >>>> +static int uvc_ioctl_g_def_ext_ctrls(struct file *file, void *fh, > >>>> + struct v4l2_ext_controls *ctrls) > >>>> +{ > >>>> + struct uvc_fh *handle = fh; > >>>> + struct uvc_video_chain *chain = handle->chain; > >>>> + struct v4l2_ext_control *ctrl = ctrls->controls; > >>>> + unsigned int i; > >>>> + int ret; > >>>> + struct v4l2_queryctrl qc; > >>>> + > >>>> + ret = uvc_ctrl_begin(chain); > >>> > >>> There's no need to call uvc_ctrl_begin() here (and if there was, you'd > >>> have to call uvc_ctrl_rollback() or uvc_ctrl_commit() before returning). > >>> > >>>> + if (ret < 0) > >>>> + return ret; > >>>> + > >>>> + for (i = 0; i < ctrls->count; ++ctrl, ++i) { > >>>> + qc.id = ctrl->id; > >>>> + ret = uvc_query_v4l2_ctrl(chain, &qc); > >>>> + if (ret < 0) { > >>>> + ctrls->error_idx = i; > >>>> + return ret; > >>>> + } > >>>> + ctrl->value = qc.default_value; > >>>> + } > >>>> + > >>>> + ctrls->error_idx = 0; > >>>> + > >>>> + return 0; > >>>> +} > >>> > >>> Instead of open-coding this in multiple drivers, how about adding a > >>> helper function to the core ? Something like (totally untested) > >> > >> It's only open-coded in drivers that do not use the control framework. > >> For drivers that use the control framework it is completely transparent. > > > > Sure, but still, the same function is implemented several times while a > > single implementation could do. I'd prefer having it in the core until > > all (or all but one) drivers are converted to the control framework. > > There are only three drivers that need to implement this manually: uvc, > saa7164 and pvrusb2. That's not enough to warrant moving this into the > core. I'd argue that even just two drivers would be enough :-) Especially given that the proposed implementation for uvcvideo is wrong. > One of these days I should sit down and convert saa7164 to the control > framework. That shouldn't be too difficult. How about pvrusb2, is there a good reason not to use the control framework there ?
On 07/16/15 10:27, Laurent Pinchart wrote: > On Thursday 16 July 2015 10:23:03 Hans Verkuil wrote: >> On 07/16/15 10:11, Laurent Pinchart wrote: >>> On Thursday 16 July 2015 09:38:11 Hans Verkuil wrote: >>>> On 07/15/15 23:05, Laurent Pinchart wrote: >>>>> On Friday 12 June 2015 18:46:23 Ricardo Ribalda Delgado wrote: >>>>>> Callback needed by ioctl VIDIOC_G_DEF_EXT_CTRLS as this driver does not >>>>>> use the controller framework. >>>>>> >>>>>> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> >>>>>> --- >>>>>> >>>>>> drivers/media/usb/uvc/uvc_v4l2.c | 30 ++++++++++++++++++++++++++++++ >>>>>> 1 file changed, 30 insertions(+) >>>>>> >>>>>> diff --git a/drivers/media/usb/uvc/uvc_v4l2.c >>>>>> b/drivers/media/usb/uvc/uvc_v4l2.c index 2764f43607c1..e2698a77138a >>>>>> 100644 >>>>>> --- a/drivers/media/usb/uvc/uvc_v4l2.c >>>>>> +++ b/drivers/media/usb/uvc/uvc_v4l2.c >>>>>> @@ -1001,6 +1001,35 @@ static int uvc_ioctl_g_ext_ctrls(struct file >>>>>> *file, void *fh, >>>>>> return uvc_ctrl_rollback(handle); >>>>>> } >>>>>> >>>>>> +static int uvc_ioctl_g_def_ext_ctrls(struct file *file, void *fh, >>>>>> + struct v4l2_ext_controls *ctrls) >>>>>> +{ >>>>>> + struct uvc_fh *handle = fh; >>>>>> + struct uvc_video_chain *chain = handle->chain; >>>>>> + struct v4l2_ext_control *ctrl = ctrls->controls; >>>>>> + unsigned int i; >>>>>> + int ret; >>>>>> + struct v4l2_queryctrl qc; >>>>>> + >>>>>> + ret = uvc_ctrl_begin(chain); >>>>> >>>>> There's no need to call uvc_ctrl_begin() here (and if there was, you'd >>>>> have to call uvc_ctrl_rollback() or uvc_ctrl_commit() before returning). >>>>> >>>>>> + if (ret < 0) >>>>>> + return ret; >>>>>> + >>>>>> + for (i = 0; i < ctrls->count; ++ctrl, ++i) { >>>>>> + qc.id = ctrl->id; >>>>>> + ret = uvc_query_v4l2_ctrl(chain, &qc); >>>>>> + if (ret < 0) { >>>>>> + ctrls->error_idx = i; >>>>>> + return ret; >>>>>> + } >>>>>> + ctrl->value = qc.default_value; >>>>>> + } >>>>>> + >>>>>> + ctrls->error_idx = 0; >>>>>> + >>>>>> + return 0; >>>>>> +} >>>>> >>>>> Instead of open-coding this in multiple drivers, how about adding a >>>>> helper function to the core ? Something like (totally untested) >>>> >>>> It's only open-coded in drivers that do not use the control framework. >>>> For drivers that use the control framework it is completely transparent. >>> >>> Sure, but still, the same function is implemented several times while a >>> single implementation could do. I'd prefer having it in the core until >>> all (or all but one) drivers are converted to the control framework. >> >> There are only three drivers that need to implement this manually: uvc, >> saa7164 and pvrusb2. That's not enough to warrant moving this into the >> core. > > I'd argue that even just two drivers would be enough :-) Especially given that > the proposed implementation for uvcvideo is wrong. I don't want to add code to the core to cater to exceptions. >> One of these days I should sit down and convert saa7164 to the control >> framework. That shouldn't be too difficult. > > How about pvrusb2, is there a good reason not to use the control framework > there ? Brrr. pvrusb2 exports controls (and a bunch of other things) to /sys allowing scripts to get/set controls using cat and echo. I have no idea how to switch pvrusb2 to the control framework while still keeping this non-standard API. I guess one of these days I will need to look at it, but I've been postponing it for years now :-) There are still a few other drivers that do not use the control framework: saa7164, zoran, fsl-viu, omap_vout (although I hope that one can be removed), usbvision and bcm2048 (that's a staging driver, so I can probably ignore that one). pvrusb2 is actually fairly important: v4l2-subdev still has legacy ops for handling controls and as long as pvrusb2 is not converted I cannot remove those ops. Regards, Hans -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hello Laurent On Thu, Jul 16, 2015 at 10:27 AM, Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote: > I'd argue that even just two drivers would be enough :-) Especially given that > the proposed implementation for uvcvideo is wrong. This is why we have the review process :P. I do my best, but you are the expert on your driver. A core implementation cannot be completely correct, as it will not support array controls. I will resend this patch ASAP. Thanks for your comments!
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 2764f43607c1..e2698a77138a 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1001,6 +1001,35 @@ static int uvc_ioctl_g_ext_ctrls(struct file *file, void *fh, return uvc_ctrl_rollback(handle); } +static int uvc_ioctl_g_def_ext_ctrls(struct file *file, void *fh, + struct v4l2_ext_controls *ctrls) +{ + struct uvc_fh *handle = fh; + struct uvc_video_chain *chain = handle->chain; + struct v4l2_ext_control *ctrl = ctrls->controls; + unsigned int i; + int ret; + struct v4l2_queryctrl qc; + + ret = uvc_ctrl_begin(chain); + if (ret < 0) + return ret; + + for (i = 0; i < ctrls->count; ++ctrl, ++i) { + qc.id = ctrl->id; + ret = uvc_query_v4l2_ctrl(chain, &qc); + if (ret < 0) { + ctrls->error_idx = i; + return ret; + } + ctrl->value = qc.default_value; + } + + ctrls->error_idx = 0; + + return 0; +} + static int uvc_ioctl_s_try_ext_ctrls(struct uvc_fh *handle, struct v4l2_ext_controls *ctrls, bool commit) @@ -1500,6 +1529,7 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops = { .vidioc_g_ctrl = uvc_ioctl_g_ctrl, .vidioc_s_ctrl = uvc_ioctl_s_ctrl, .vidioc_g_ext_ctrls = uvc_ioctl_g_ext_ctrls, + .vidioc_g_def_ext_ctrls = uvc_ioctl_g_def_ext_ctrls, .vidioc_s_ext_ctrls = uvc_ioctl_s_ext_ctrls, .vidioc_try_ext_ctrls = uvc_ioctl_try_ext_ctrls, .vidioc_querymenu = uvc_ioctl_querymenu,