Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp434628lqp; Mon, 10 Jun 2024 08:26:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU+ZLKCytZ4HwjWvKFO5ysxbJm2e8HsmHyxfqeYLtcSXaSWpjALwEWH5KpFtBYRMBP/XpZOsxNCUck1gnGheMoYQpZDkgjnXWXWG/F9EQ== X-Google-Smtp-Source: AGHT+IEJPTg1eoYS/EVmnn/R1OVOmBbCOW5QKu7+Y3gl8K6GpIvU/N7AN6SkvXvJCBJlIaMAsRPe X-Received: by 2002:a50:aa85:0:b0:57a:2538:7b67 with SMTP id 4fb4d7f45d1cf-57c5085cc48mr8615256a12.3.1718033188472; Mon, 10 Jun 2024 08:26:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718033188; cv=pass; d=google.com; s=arc-20160816; b=q4KHclqcLoUF2oRxZKPEueAxHWKE1fkFK/PO4vnTadgbA7zX5BTKgduOLhbMZuuh66 OMCCoqGcZ1+4CcSEVAYGf1SIedOSfiaQNsmsDAAeyPSfV9hgwjRO81W/5FVWHBZVZS0E 9EDM8ccHpZe07vk3Ur9Uix0Int8EVcEE5xvFOvaT5Fe/QXnJrQP8bmqObo5UD/MYgcE3 AL1/hjiCYBFfKBPdksG2dfAU8zJABhRNUl5gWsXxFB5zj7USv01or3FuWDjtPtPcw5nv mhhwG5KkD8qiEITn1yNuJkZy1DcRIT7GVY01XLaE7gcjoW39KjUIyXsdx2WNbDHWK4jK 4k5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Z+LgFV51NBdhMpQ8CLN3TwsB9A544iQpBtuttJ7O9+c=; fh=AAGR/n8PHcqDzZPHR9w2S3kk7lngwkUMjoDolSCgIOY=; b=sUsLJdAENtytc793CA6OOGEu6vMsOMCWUGgWLYyTKDogmz8lAJsXiRi40NrgJL6LES 2eO7aHrIogfhPU6Dt+4I/yrS6AZ7onEubd2o2LRdR/QuJNBWoZonz0YZRsoZAW23+vxU VCBAaPpw+mPiFGLpEQylLl41ir0Cq7rmSH7eXPOe1LzhCY1NJvpigSzuIvspP1EPOla9 LnihPu1kf3QaGu8BnTPYOnoxmDiIY9jZbBl2bjXmHYgAeDMiaGbgh6xR9/gcg+G04+IU ANdbm3sJ8rk5CupHVdfLW1pcP5x7e95p2bXKtYOANp91QI4NtJCUXohedXyvqdIxZFOX ke4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b="j/XNjI2G"; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-208474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208474-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57c72ede7bfsi2211934a12.400.2024.06.10.08.26.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 08:26:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b="j/XNjI2G"; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-208474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208474-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0DF641F20FF4 for ; Mon, 10 Jun 2024 15:26:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41F5D13DDCE; Mon, 10 Jun 2024 15:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="j/XNjI2G" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EC8E14EC47; Mon, 10 Jun 2024 15:21:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032871; cv=none; b=CysUMU/1OYqtkwmd1SSpFvc5/2xL3rYRXm5hEojTlAfQIf52qHPsrdl0JDvFQnHuPOXwvEChDY/naJ6p2Yru/+dzzc2DskEDPWMClA9enW1gqji37WjENSBWlniQ0T4cFZldW7GpEOxZ/boprVr2Za+/La6Ija9DedpNjgIil08= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718032871; c=relaxed/simple; bh=I95YfeR4z6uaBo8ShVWAd+z5U0ONBdc/Mf/dNEVoGb8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EHlCB1E4b4UaNLXQI9cMZp/hhUZP3iQYxPvh9tp7MqFUhEoCwlJha+f/3GKYFqIxYLfSv7eTeYYfWDRbT3mIopIXF+itqvNFtfR2hukcNyRGIkMUXCZ/B1JNPraKIDBOdv22uN576tlyslF7hYdnrFzB+FCIDJLWB/MsPnLO/eU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=j/XNjI2G; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E1FF239F; Mon, 10 Jun 2024 17:20:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1718032854; bh=I95YfeR4z6uaBo8ShVWAd+z5U0ONBdc/Mf/dNEVoGb8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=j/XNjI2GGs5Z/9LaKhn1e+/ugW9C4MVTBR4qApHE+MgdWHq09l2hJyRxVnbxviE8j uRSrD6FXWV99GtmGdh13jaUrkNlgRvWgcf8mIcMJt4h59gDO3f/YT+wZ+yf9jYrU6z i8XZQBJnOakj1O0KTeWgw2A7ExpTa0pYiDb+YqwM= Date: Mon, 10 Jun 2024 18:20:46 +0300 From: Laurent Pinchart To: Ricardo Ribalda Cc: Mauro Carvalho Chehab , Sergey Senozhatsky , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/5] media: uvcvideo: Refactor Power Line Frequency limit selection Message-ID: <20240610152046.GJ26663@pendragon.ideasonboard.com> References: <20240318-billion-v1-0-2f7bc0ee2030@chromium.org> <20240318-billion-v1-2-2f7bc0ee2030@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240318-billion-v1-2-2f7bc0ee2030@chromium.org> Hi Ricardo, Thank you for the patch. On Mon, Mar 18, 2024 at 11:55:24PM +0000, Ricardo Ribalda wrote: > Move the PLF mapping logic to its own function. This patch does not > introduce any new functionality to the logic, it is just a preparation > patch. > > Signed-off-by: Ricardo Ribalda > --- > drivers/media/usb/uvc/uvc_ctrl.c | 93 ++++++++++++++++++++++++---------------- > 1 file changed, 55 insertions(+), 38 deletions(-) > > diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c > index 3e939b4fbaaaf..67522143c6c85 100644 > --- a/drivers/media/usb/uvc/uvc_ctrl.c > +++ b/drivers/media/usb/uvc/uvc_ctrl.c > @@ -459,6 +459,56 @@ static void uvc_ctrl_set_rel_speed(struct uvc_control_mapping *mapping, > data[first+1] = min_t(int, abs(value), 0xff); > } > > +const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = { > + .id = V4L2_CID_POWER_LINE_FREQUENCY, > + .entity = UVC_GUID_UVC_PROCESSING, > + .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, > + .size = 2, > + .offset = 0, > + .v4l2_type = V4L2_CTRL_TYPE_MENU, > + .data_type = UVC_CTRL_DATA_TYPE_ENUM, > + .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ, > + V4L2_CID_POWER_LINE_FREQUENCY_50HZ), > +}; > + > +const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11 = { > + .id = V4L2_CID_POWER_LINE_FREQUENCY, > + .entity = UVC_GUID_UVC_PROCESSING, > + .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, > + .size = 2, > + .offset = 0, > + .v4l2_type = V4L2_CTRL_TYPE_MENU, > + .data_type = UVC_CTRL_DATA_TYPE_ENUM, > + .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ, > + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), > +}; > + > +static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc15 = { > + .id = V4L2_CID_POWER_LINE_FREQUENCY, > + .entity = UVC_GUID_UVC_PROCESSING, > + .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, > + .size = 2, > + .offset = 0, > + .v4l2_type = V4L2_CTRL_TYPE_MENU, > + .data_type = UVC_CTRL_DATA_TYPE_ENUM, > + .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_AUTO, > + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), > +}; > + > +static int __uvc_ctrl_add_mapping(struct uvc_video_chain *chain, > + struct uvc_control *ctrl, const struct uvc_control_mapping *mapping); I wonder if we could avoid the forward declaration by turning the .add_mapping() operation into a .filter_mapping() (name to be bikshedded) that would return a replacement mapping instead of adding it. The caller (the __uvc_ctrl_add_custom_mapping() function) would then call __uvc_ctrl_add_mapping() unconditionally. You could actually call the new operation directly in __uvc_ctrl_add_custom_mapping() without having to add a new __uvc_ctrl_add_custom_mapping() function. What do you think, would that be simpler and more redable ? > + > +static int uvc_ctrl_add_plf_mapping(struct uvc_video_chain *chain, > + struct uvc_control *ctrl, const struct uvc_control_mapping *mapping) > +{ > + if (chain->dev->uvc_version < 0x150) > + return __uvc_ctrl_add_mapping(chain, ctrl, > + &uvc_ctrl_power_line_mapping_uvc11); > + > + return __uvc_ctrl_add_mapping(chain, ctrl, > + &uvc_ctrl_power_line_mapping_uvc15); > +} > + > static const struct uvc_control_mapping uvc_ctrl_mappings[] = { > { > .id = V4L2_CID_BRIGHTNESS, > @@ -748,51 +798,18 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { > .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, > .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, > }, > -}; > - > -const struct uvc_control_mapping uvc_ctrl_power_line_mapping_limited = { > - .id = V4L2_CID_POWER_LINE_FREQUENCY, > - .entity = UVC_GUID_UVC_PROCESSING, > - .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, > - .size = 2, > - .offset = 0, > - .v4l2_type = V4L2_CTRL_TYPE_MENU, > - .data_type = UVC_CTRL_DATA_TYPE_ENUM, > - .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ, > - V4L2_CID_POWER_LINE_FREQUENCY_50HZ), > -}; > - > -const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc11 = { > - .id = V4L2_CID_POWER_LINE_FREQUENCY, > - .entity = UVC_GUID_UVC_PROCESSING, > - .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, > - .size = 2, > - .offset = 0, > - .v4l2_type = V4L2_CTRL_TYPE_MENU, > - .data_type = UVC_CTRL_DATA_TYPE_ENUM, > - .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_60HZ, > - V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), > + { > + .entity = UVC_GUID_UVC_PROCESSING, > + .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, > + .add_mapping = uvc_ctrl_add_plf_mapping, > + }, > }; > > static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc11[] = { > - &uvc_ctrl_power_line_mapping_uvc11, > NULL, /* Sentinel */ > }; > > -static const struct uvc_control_mapping uvc_ctrl_power_line_mapping_uvc15 = { > - .id = V4L2_CID_POWER_LINE_FREQUENCY, > - .entity = UVC_GUID_UVC_PROCESSING, > - .selector = UVC_PU_POWER_LINE_FREQUENCY_CONTROL, > - .size = 2, > - .offset = 0, > - .v4l2_type = V4L2_CTRL_TYPE_MENU, > - .data_type = UVC_CTRL_DATA_TYPE_ENUM, > - .menu_mask = GENMASK(V4L2_CID_POWER_LINE_FREQUENCY_AUTO, > - V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), > -}; > - > static const struct uvc_control_mapping *uvc_ctrl_mappings_uvc15[] = { > - &uvc_ctrl_power_line_mapping_uvc15, > NULL, /* Sentinel */ > }; > -- Regards, Laurent Pinchart