From patchwork Fri Oct 6 10:34:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edgar Thier X-Patchwork-Id: 9988943 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CC12A6029B for ; Fri, 6 Oct 2017 10:34:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFEA428DA5 for ; Fri, 6 Oct 2017 10:34:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE15D28DAC; Fri, 6 Oct 2017 10:34:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 231FC28B2D for ; Fri, 6 Oct 2017 10:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751495AbdJFKeC (ORCPT ); Fri, 6 Oct 2017 06:34:02 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:58885 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751334AbdJFKeB (ORCPT ); Fri, 6 Oct 2017 06:34:01 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4052620D02; Fri, 6 Oct 2017 06:34:01 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Fri, 06 Oct 2017 06:34:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= fm1; bh=BHkb+oMZh2m7tREnatwXZ7eB+chKxySUXiU1eGMHtiQ=; b=Ej7I6lJa bKxvmOMm1AR56CXGSTq5GV+cqXIUsUt0sXzUmJSREyHkcNDc1qlR7+E1ApvABCgw V6AeARjuOFDQIp5UpjhbWKWA/pkuWCgUg2kZTMpiFtvqX2kFDRu7o56Qw6702N74 pRKu33oBsnK5gX70fJsJWAvunIpJ/OKwNw1t9yBh4HPosIJRLlNqak4aCT2sTdz8 FsE6ovr3UuedqdrAu2Vy5BeASeAKH51r9pmC1h3fB6JQaOF+BolppxJY9c2CZ4pC SQCvDPCfeomhoWU0m9C/WrSwFT2ZndisI4A7fkdsILPDxikW+fFv1mTDSegH29Ig cfMo5RX9MokbGw== X-ME-Sender: X-Sasl-enc: wy2niu7Y7wFA++8phfxTqzFc0DnLQT2EYkrh8AAEGAG5 1507286040 Received: from [192.168.0.146] (unknown [31.209.95.242]) by mail.messagingengine.com (Postfix) with ESMTPA id A34DF7E65B; Fri, 6 Oct 2017 06:34:00 -0400 (EDT) Subject: Re: [PATCH] uvcvideo: Apply flags from device to actual properties To: kieran.bingham@ideasonboard.com, Laurent Pinchart Cc: linux-media@vger.kernel.org References: <1516233.pKQSzG3xyp@avalon> <443c86f9-0973-cf52-c0c3-be662a8fee74@ideasonboard.com> From: Edgar Thier Message-ID: Date: Fri, 6 Oct 2017 12:34:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <443c86f9-0973-cf52-c0c3-be662a8fee74@ideasonboard.com> Content-Language: en-US Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use flags the device exposes for UVC controls. This allows the device to define which property flags are set. Since some cameras offer auto-adjustments for properties (e.g. auto-gain), the values of other properties (e.g. gain) can change in the camera. Examining the flags ensures that the driver is aware of such properties. Signed-off-by: Edgar Thier --- drivers/media/usb/uvc/uvc_ctrl.c | 56 +++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 20397ab..5091086 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1630,6 +1630,41 @@ static void uvc_ctrl_fixup_xu_info(struct uvc_device *dev, } /* + * Retrieve flags for a given control + */ +static int uvc_ctrl_get_flags(struct uvc_device *dev, const struct uvc_control *ctrl, + const struct uvc_control_info *info) +{ + u8 *data; + int ret = 0; + int flags = 0; + + data = kmalloc(2, GFP_KERNEL); + if (data == NULL) + return -ENOMEM; + + ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, dev->intfnum, + info->selector, data, 1); + if (ret < 0) { + uvc_trace(UVC_TRACE_CONTROL, + "GET_INFO failed on control %pUl/%u (%d).\n", + info->entity, info->selector, ret); + } else { + flags = UVC_CTRL_FLAG_GET_MIN | UVC_CTRL_FLAG_GET_MAX + | UVC_CTRL_FLAG_GET_RES | UVC_CTRL_FLAG_GET_DEF + | (data[0] & UVC_CONTROL_CAP_GET ? + UVC_CTRL_FLAG_GET_CUR : 0) + | (data[0] & UVC_CONTROL_CAP_SET ? + UVC_CTRL_FLAG_SET_CUR : 0) + | (data[0] & UVC_CONTROL_CAP_AUTOUPDATE ? + UVC_CTRL_FLAG_AUTO_UPDATE : 0); + } + kfree(data); + return flags; +} + + +/* * Query control information (size and flags) for XU controls. */ static int uvc_ctrl_fill_xu_info(struct uvc_device *dev, @@ -1659,24 +1694,7 @@ static int uvc_ctrl_fill_xu_info(struct uvc_device *dev, info->size = le16_to_cpup((__le16 *)data); - /* Query the control information (GET_INFO) */ - ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, dev->intfnum, - info->selector, data, 1); - if (ret < 0) { - uvc_trace(UVC_TRACE_CONTROL, - "GET_INFO failed on control %pUl/%u (%d).\n", - info->entity, info->selector, ret); - goto done; - } - - info->flags = UVC_CTRL_FLAG_GET_MIN | UVC_CTRL_FLAG_GET_MAX - | UVC_CTRL_FLAG_GET_RES | UVC_CTRL_FLAG_GET_DEF - | (data[0] & UVC_CONTROL_CAP_GET ? - UVC_CTRL_FLAG_GET_CUR : 0) - | (data[0] & UVC_CONTROL_CAP_SET ? - UVC_CTRL_FLAG_SET_CUR : 0) - | (data[0] & UVC_CONTROL_CAP_AUTOUPDATE ? - UVC_CTRL_FLAG_AUTO_UPDATE : 0); + info->flags = uvc_ctrl_get_flags(dev, ctrl, info); uvc_ctrl_fixup_xu_info(dev, ctrl, info); @@ -1902,6 +1920,8 @@ static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl, goto done; } + ctrl->info.flags = uvc_ctrl_get_flags(dev, ctrl, info); + ctrl->initialized = 1; uvc_trace(UVC_TRACE_CONTROL, "Added control %pUl/%u to device %s "