Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp590350iog; Wed, 15 Jun 2022 08:16:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1udZXz0OnDwizQpVbh6UDjsBEu+Ie2H+U/tjkCdcWik5XNyM+FtdNDErQka1KJPWBRHcfq1 X-Received: by 2002:aa7:93b0:0:b0:520:7113:4187 with SMTP id x16-20020aa793b0000000b0052071134187mr10252111pff.35.1655306191043; Wed, 15 Jun 2022 08:16:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655306191; cv=none; d=google.com; s=arc-20160816; b=Ki2exJUK0uH2lJf3TE3gEvqKVrImYGsZvXsx/2l9uT2OL4pVsykamgA2S/YgBGpakR YfzW3H/2tTcjTK4SvrrCuYhMfMeAE5vyWF/SESAOjOp1KQV0vw9HZZ9r3ALxLrVkHuJS ZXvWciH1RiO7VCnzh+85xh1HiS1GuqxwjI3Pqi+um00xJNwaVFPJzNjw4ZJkz9HGKtm7 3IH4MJmj21jkuBp9pcI0zEZozn9bSTo1E28Zsog0LeaMmJcdbQJ/eYILPsnqz/Z+5Aex gG5hJHMNVa37xwqOgnKD2rI5cSUmwRtwA6mIa+2mD3JxZqcXRswjewRVeuvg8iX93ppO EMHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WEnoe5l63wIa1jNma1QDgL58B8nnhb1HJqhp7b+Nz/Q=; b=S6I0nFCF1KLrCgQRwFg+UxdCZbJ3PLpUx1mHaOvLHVcNmsu20PIden2dhLqGt78cDg C3iDygVdGt19iX1DP7hZtwka1iRjwfuo5qsMTPZmLbSj7H/xspqwp2zLQv6FVMsKhVEs zW4ZY+abJI7G0n1XoHlELGg+CSu+ruQmQNGuifHL3ABOPY8+ADuXI0ohidHpY12Ws9zO hi+sI4VDwd2Q9dPXSYqdtzsSfa7NcNU0vvg2O4d+uMDKf3pTD+K93Laxip4lZfeg2Tfm VqO1PIzTeiCYQcxrc4rBy5MrVWwxuMDGAwFmBbIVdlDgY2T4P2MB/iebJIDEZm5hn+bt H2Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FH7EXpJo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jj5-20020a170903048500b00163b777cbfbsi15295100plb.184.2022.06.15.08.16.17; Wed, 15 Jun 2022 08:16:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FH7EXpJo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346810AbiFOPNX (ORCPT + 99 others); Wed, 15 Jun 2022 11:13:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242574AbiFOPNJ (ORCPT ); Wed, 15 Jun 2022 11:13:09 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA29FDFFD for ; Wed, 15 Jun 2022 08:13:04 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id o10so16643607edi.1 for ; Wed, 15 Jun 2022 08:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WEnoe5l63wIa1jNma1QDgL58B8nnhb1HJqhp7b+Nz/Q=; b=FH7EXpJoAkW3xkPL4zmOwg5JDBAmgGMx7bZjVJv8Krq1NYGjUbKI5Uf6uLb+ddzIO1 fEc6cv6G+rdgItSTPGQYTZRNbGx62/NnxTrZVe47JqArS8MAa/xOQof9kJjPWt0LSS0D wLdm1yWSUh2u681JQNrKbvPIr+3iYK7TVwBJI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WEnoe5l63wIa1jNma1QDgL58B8nnhb1HJqhp7b+Nz/Q=; b=gbRSwkurz9I4Q3cwwYc2xL7jJhkTMt7GT2uHXpvgajBAytUNQWRm1ruAAPe/rLb6S1 7P9RRquaTMi3rpsYX8tABwlcZsz08SzHvxw+sj0rKul/OiX2x6bPJT/h+ZluGd9k8W/T EMaERnVJCEbMY6OY5ACBYAHFvojgGoIRaWSLOXVqfya326eA3ro1e3WrYg3+NiTEjXOu cunD9RmQBsjxc5FSnjrB8FVhfySaZt24b1ohyfGRq4JWGWUhOLZ1ujQNCdJfK6IXyfSu ZaZUkw7kZNu8gvim7xKmFptWhE7NUgcUDQTFElLB+xn9YYxYJqFu7EKCbgnhe9onXFpp ZxpA== X-Gm-Message-State: AJIora884LMA8D1YdHjE2QHzEjuF3o0AD+xgJOm9HYGi3hDOh5b1Z9vY gXu80iStwR93oU9jmkzMqFUY6g== X-Received: by 2002:a05:6402:3592:b0:42d:fb03:319c with SMTP id y18-20020a056402359200b0042dfb03319cmr226511edc.137.1655305983493; Wed, 15 Jun 2022 08:13:03 -0700 (PDT) Received: from alco.lan (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id b25-20020aa7cd19000000b0042bd2012196sm9610264edw.85.2022.06.15.08.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 08:13:03 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, tfiga@chromium.org, senozhatsky@chromium.org, yunkec@google.com Cc: Ricardo Ribalda Subject: [PATCH v6 2/8] media: uvcvideo: Add support for per-device control mapping overrides Date: Wed, 15 Jun 2022 17:12:53 +0200 Message-Id: <20220615151259.77825-3-ribalda@chromium.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615151259.77825-1-ribalda@chromium.org> References: <20220615151259.77825-1-ribalda@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Some devices do not implement all their controls in a way that complies with the UVC specification. This is for instance the case for several devices that do not support the disabled mode for the power line frequency control. Add a mechanism to allow per-device control mapping overrides to avoid errors when accessing non-compliant controls. Signed-off-by: Ricardo Ribalda Signed-off-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_ctrl.c | 35 ++++++++++++++++++++++++++------ drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index a709ebbb4d69..092decfdaa62 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -2403,9 +2403,8 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, { const struct uvc_control_info *info = uvc_ctrls; const struct uvc_control_info *iend = info + ARRAY_SIZE(uvc_ctrls); - const struct uvc_control_mapping *mapping = uvc_ctrl_mappings; - const struct uvc_control_mapping *mend = - mapping + ARRAY_SIZE(uvc_ctrl_mappings); + const struct uvc_control_mapping *mapping; + const struct uvc_control_mapping *mend; /* XU controls initialization requires querying the device for control * information. As some buggy UVC devices will crash when queried @@ -2433,14 +2432,38 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, if (!ctrl->initialized) return; - /* Process common mappings first. */ - for (; mapping < mend; ++mapping) { + /* + * First check if the device provides a custom mapping for this control, + * used to override standard mappings for non-conformant devices. Don't + * process standard mappings if a custom mapping is found. This + * mechanism doesn't support combining standard and custom mappings for + * a single control. + */ + if (chain->dev->info->mappings) { + bool custom = false; + unsigned int i; + + for (i = 0; (mapping = chain->dev->info->mappings[i]); ++i) { + if (uvc_entity_match_guid(ctrl->entity, mapping->entity) && + ctrl->info.selector == mapping->selector) { + __uvc_ctrl_add_mapping(chain, ctrl, mapping); + custom = true; + } + } + + if (custom) + return; + } + + /* Process common mappings next. */ + mend = mapping + ARRAY_SIZE(uvc_ctrl_mappings); + for (mapping = uvc_ctrl_mappings; mapping < mend; ++mapping) { if (uvc_entity_match_guid(ctrl->entity, mapping->entity) && ctrl->info.selector == mapping->selector) __uvc_ctrl_add_mapping(chain, ctrl, mapping); } - /* And then version-specific mappings. */ + /* Finally process version-specific mappings. */ if (chain->dev->uvc_version < 0x0150) { mapping = uvc_ctrl_mappings_uvc11; mend = mapping + ARRAY_SIZE(uvc_ctrl_mappings_uvc11); diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index c5b4febd2d94..fff5c5c99a3d 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -667,6 +667,7 @@ struct uvc_device_info { u32 quirks; u32 meta_format; u16 uvc_version; + const struct uvc_control_mapping **mappings; }; struct uvc_device { -- 2.36.1.476.g0c4daa206d-goog