Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2099836pxb; Fri, 25 Mar 2022 11:04:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw++DodVPPOTqWoXVjZffX4Ztc18ShvhMyksJfyZ3hq93VFqd6CQz2PiHvSLo+ThO1DV0RB X-Received: by 2002:a63:e545:0:b0:382:8dd9:a870 with SMTP id z5-20020a63e545000000b003828dd9a870mr586756pgj.621.1648231486208; Fri, 25 Mar 2022 11:04:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648231486; cv=none; d=google.com; s=arc-20160816; b=AfAzMNDk2g8J1B2fSIyiQTkWLDYsRf8krZa7rkXdvRYbno6WMRpEwBQ/EV77OjOd6S 7c4wICs6WJv7MsKik39Jv7xduWY7KbgbqRpUfVhuHMNhPGmoRAyTheGwgSwv2p/v1tdI b/BABO8UaqwftEEpjPS/hPgyXwCjDPX3iXdJVgJws/qoN1aycB9HgHGHbXEv/U9DOCIX vl+6D+cWsgN/Muzza1mQNiIt09Br9uoVPwle2XFU0qtmyXQG7145gApsQ0c6Hi99J3xF NQqjGsMLHArgYybcPFwJDdFf8V0p3tOHhAjvdX5Fo2JphmXjp5VptQlSyf5JimAA1Egr x22Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Zi9VdJsyYjKyA02TEOfHHFYfOMABJqJ4zPrsI+QEIU4=; b=k0d49+dxvNEN+GTI4HHIJZRxTjV6JTHm/M/5PMaOiHC416p/7mKf+Ene4OH8M6P8VP n2i8hmcLm0giHwCuZ2OjJ9H2KXDyYeW7Cc8FlaNR0BqxO0yDYotqcFwF1j53vJinp0kM 5+v920Li2Im1bZe4H6xp0EPFsIkBUSHld+B4/Y4ePTxN6OohfHKfovMg5f9U/p4GGMci vGlWDvZLh9lZsMAlsPVXRngMRbeI2ZB1+LLbl4vsV/TJVe5xDY8KAespaROBIMVi0/MT 4r4JZE/VPIYSIDowCHyiumyiQhrL8GHqFJMFJRfy9GMEtb9xXRKZLjkKpMAqnexmFuYJ KQow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=B12opEd9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id w22-20020a170902d71600b00153b2d1665csi2696869ply.612.2022.03.25.11.04.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 11:04:46 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=B12opEd9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E11CF12D0B1; Fri, 25 Mar 2022 10:39:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355300AbiCXWU2 (ORCPT + 99 others); Thu, 24 Mar 2022 18:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230169AbiCXWU1 (ORCPT ); Thu, 24 Mar 2022 18:20:27 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA80B58E6E; Thu, 24 Mar 2022 15:18:54 -0700 (PDT) Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B07E49E5; Thu, 24 Mar 2022 23:18:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648160332; bh=D71LPmt6Gw6pFQpooYuC8OWiu/2/Rw/0iXmNjtonBBA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=B12opEd9Wbfy5u7paKQUSxdFkVQjXoNd3KUdIJPh6gDYKrjONdmaQhp+5k7KJ5dxp BkKqOTjOnxuN8Se2fSrLfxzG0Kq1EIfNBY6zxYhi1nTc7hLdHnYJodVivoifi0ptt8 g/IfRqzb/sBdZ49tUu8JWSh3XaeMzF5vjSId27pE= Date: Fri, 25 Mar 2022 00:18:51 +0200 From: Laurent Pinchart To: Ricardo Ribalda Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Hans Verkuil Subject: Re: [PATCH v2] media: uvcvideo: Fix handling on Bitmask controls Message-ID: References: <20220215184228.2531386-1-ribalda@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ricardo, On Thu, Mar 24, 2022 at 10:56:37PM +0100, Ricardo Ribalda wrote: > On Thu, 24 Mar 2022 at 21:25, Laurent Pinchart wrote: > > On Tue, Feb 15, 2022 at 06:42:28PM +0000, Ricardo Ribalda wrote: > > > Minimum and step values for V4L2_CTRL_TYPE_BITMASK controls should be 0. > > > There is no need to query the camera firmware about this and maybe get > > > invalid results. > > > > > > Also value should be clamped to the min/max value advertised by the > > > hardware. > > > > > > Fixes v4l2-compliane: > > > Control ioctls (Input 0): > > > fail: v4l2-test-controls.cpp(97): minimum must be 0 for a bitmask control > > > test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: FAIL > > > > What bitmask control do you have ? The driver has no standard control > > that use the V4L2_CTRL_TYPE_BITMASK type. > > > > UVC doesn't formally define bitmask control type > > (UVC_CTRL_DATA_TYPE_BITMASK). In UVC 1.1 only the UVC_CT_AE_MODE_CONTROL > > control has a bitmap type, and only one bit can be set at a type. It > > thus maps to a V4L2 menu control. > > > > In UVC 1.5 there are other controls documented as bitmap controls, > > which could map to the V4L2 bitmask control type. Those don't support > > GET_MIN and GET_MAX, but use GET_RES to report the list of bits that can > > be set. This should be mapped to the V4L2 control maximum value, which > > isn't handled by this patch. The last hunk is also incorrect, as it > > clamps the value to what is reported by GET_MIN and GET_MAX, instead of > > [0, GET_RES], but more than that, it should not just clamp the value, > > but check that all bits are valid. > > I am particularly looking at bmAutoControls from CT_REGION_OF_INTEREST_CONTROL > > The doc says that: > """ > To detect if a device supports a particular Auto Control, use GET_MAX > which returns a mask indicating all supported Auto Controls. > """ But if you look at CT_AE_MODE_CONTROL, "A GET_RES request issued to this control will return a bitmap of the modes supported by this control. A valid request to this control would have only one bit set (a single mode selected)." GET_MIN and GET_MAX are not listed as supported. Maybe we need two types of UVC bitmap controls ? :-( > GET_RES does not seem to return the max_value accoring to the uvc > class spec, but I will try to validate tomorrow with real hardware, > maybe we are lucky. > > And I definitely have to fix the clamp, thanks for pointing that out :) > > > > Signed-off-by: Ricardo Ribalda > > > --- > > > drivers/media/usb/uvc/uvc_ctrl.c | 7 +++++-- > > > 1 file changed, 5 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c > > > index b4f6edf968bc0..d8b9ab5b7fb85 100644 > > > --- a/drivers/media/usb/uvc/uvc_ctrl.c > > > +++ b/drivers/media/usb/uvc/uvc_ctrl.c > > > @@ -1156,7 +1156,8 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, > > > break; > > > } > > > > > > - if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) > > > + if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN && > > > + mapping->v4l2_type != V4L2_CTRL_TYPE_BITMASK) > > > v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN, > > > uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN)); > > > > > > @@ -1164,7 +1165,8 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, > > > v4l2_ctrl->maximum = mapping->get(mapping, UVC_GET_MAX, > > > uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX)); > > > > > > - if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES) > > > + if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES && > > > + mapping->v4l2_type != V4L2_CTRL_TYPE_BITMASK) > > > v4l2_ctrl->step = mapping->get(mapping, UVC_GET_RES, > > > uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES)); > > > > > > @@ -1721,6 +1723,7 @@ int uvc_ctrl_set(struct uvc_fh *handle, > > > /* Clamp out of range values. */ > > > switch (mapping->v4l2_type) { > > > case V4L2_CTRL_TYPE_INTEGER: > > > + case V4L2_CTRL_TYPE_BITMASK: > > > if (!ctrl->cached) { > > > ret = uvc_ctrl_populate_cache(chain, ctrl); > > > if (ret < 0) -- Regards, Laurent Pinchart