Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2293472iof; Wed, 8 Jun 2022 01:39:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8GN8Q7ULggIAQAqaVtkrKtW3daigOWkCZN/8AOu9MxoICjNYyHVUv36+WhHzn9HTJozzl X-Received: by 2002:a05:6a00:996:b0:505:b6d2:abc8 with SMTP id u22-20020a056a00099600b00505b6d2abc8mr100761440pfg.11.1654677593091; Wed, 08 Jun 2022 01:39:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654677593; cv=none; d=google.com; s=arc-20160816; b=YqHzXAjVXwmCYphsmHboWToagPCA4aOaoZ/tSRY4ZRUC4Furr08CGRdmKoIPRcz2bM fxda/iUJwWVPI8/5n43NZkDhQubokFG0NgKcQ/LJKgDXXQTOuSpoVv/4LGM7ed4vz49h 3lur3xXijJMjh2DiWimWs73v2EB9bi4pEeRB06g3HJb8EhYl1i0xVbv03W2he6ib7UrD +gjPtKPbqCUGKd/zbCWakj5RrOqoA0Ao/yYGVKnhEFdduxAVvwSezeQTxm/LBomGzkm2 Jw4WKwVFDONKtasm+zDLan1v9GGrE7YVQ9BlKWz8DakgUggtEPxS/Fo0LlwdaQsWSBEK yNCA== 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=NraHR4vspkg9TaNY8f5pF7FUyfordAnlZqYDDvCR4ys=; b=gpMpoLDTxnr3Am13Uf0ey2IGSELRrLSqXbFl2+hHObiJUaZTlkg/SMbsf9JFwAMbLH 3Y+EmfMEG+0FvM8mUPfu2ClMl9Hg12FhYIao6zdT2bRB16kDZ4cLO4y7Mk3qkyJ4PYmp BGkThDuoFNxaVfCnRVw0C6viZuFcKBSKg9FqoBsx2F2VtQeP0KZ2lflr368LcCHESeTZ Ci70cu115SMYoTYAQLXPVMARgju5ONosR2ehJdlQZCV6gWLOdsQaMUnCnrPFKEBRGAlE i/jzUOHhSrEPZwQu+P5iC74tNT0x3CNZKkGc+ns59RTzdLiWXXFbH8s9zsPHdEpNAtMG HGGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=mnFfN1Jo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u11-20020a170902e80b00b0015d2ca1afcfsi31359620plg.89.2022.06.08.01.39.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 01:39:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=mnFfN1Jo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 A7D5C234698; Wed, 8 Jun 2022 01:03:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232431AbiFHHax (ORCPT + 99 others); Wed, 8 Jun 2022 03:30:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238583AbiFHH0C (ORCPT ); Wed, 8 Jun 2022 03:26:02 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14FCA1E6F82; Tue, 7 Jun 2022 23:57:05 -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 8BBD380A; Wed, 8 Jun 2022 08:56:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1654671390; bh=x9REXVP2Zsl5mDhiMiXfmICxPUpmNWGsk0CwsHnbLpo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mnFfN1Jol/zeM7/cVePA4ZDabkTrP6IO/6LNmZZRDAAQx9AHbfMawsCCg336NK0+r /hs7+FWItCQrVFddTV6HCqASlYkrS7r6zZG4Aw+rVPLPaC19ZdfQjpmSTeMLntTgVu aRPSCUsnhY6pqHtdzof4WPtyKB5vc2kSnh5McZLE= Date: Wed, 8 Jun 2022 09:56:26 +0300 From: Laurent Pinchart To: Ricardo Ribalda Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomasz Figa , Sergey Senozhatsky , Yunke Cao Subject: Re: [PATCH v3 1/7] media: uvcvideo: Add missing value for power_line_frequency Message-ID: References: <20220607134405.166704-1-ribalda@chromium.org> <20220607134405.166704-2-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 Tue, Jun 07, 2022 at 11:50:15PM +0200, Ricardo Ribalda wrote: > On Tue, 7 Jun 2022 at 21:04, Laurent Pinchart wrote: > > On Tue, Jun 07, 2022 at 03:43:58PM +0200, Ricardo Ribalda wrote: > > > UVC 1.5 class defines 4 values for this control on: > > > 4.2.2.3.6 Power Line Frequency Control > > > > > > Add the missing value when the uvc version is 1.5. > > > > > > Signed-off-by: Ricardo Ribalda > > > --- > > > drivers/media/usb/uvc/uvc_ctrl.c | 67 ++++++++++++++++++++++++++------ > > > 1 file changed, 55 insertions(+), 12 deletions(-) > > > > > > diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c > > > index 0e78233fc8a0..f9d4ac81e62f 100644 > > > --- a/drivers/media/usb/uvc/uvc_ctrl.c > > > +++ b/drivers/media/usb/uvc/uvc_ctrl.c > > > @@ -362,12 +362,19 @@ static const u32 uvc_control_classes[] = { > > > V4L2_CID_USER_CLASS, > > > }; > > > > > > -static const struct uvc_menu_info power_line_frequency_controls[] = { > > > +static const struct uvc_menu_info power_line_frequency_controls_uvc11[] = { > > > { 0, "Disabled" }, > > > { 1, "50 Hz" }, > > > { 2, "60 Hz" }, > > > }; > > > > Let's drop this, and ... > > > > > > > > +static const struct uvc_menu_info power_line_frequency_controls_uvc15[] = { > > > > ... rename this to power_line_frequency_controls, and ... > > > > > + { 0, "Disabled" }, > > > + { 1, "50 Hz" }, > > > + { 2, "60 Hz" }, > > > + { 3, "Auto" }, > > > +}; > > > + > > > static const struct uvc_menu_info exposure_auto_controls[] = { > > > { 2, "Auto Mode" }, > > > { 1, "Manual Mode" }, > > > @@ -504,17 +511,6 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { > > > .v4l2_type = V4L2_CTRL_TYPE_INTEGER, > > > .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED, > > > }, > > > - { > > > - .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_info = power_line_frequency_controls, > > > - .menu_count = ARRAY_SIZE(power_line_frequency_controls), > > > - }, > > > { > > > .id = V4L2_CID_HUE_AUTO, > > > .entity = UVC_GUID_UVC_PROCESSING, > > > @@ -730,6 +726,32 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { > > > }, > > > }; > > > > > > +static const > > > +struct uvc_control_mapping 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_info = power_line_frequency_controls_uvc11, > > > + .menu_count = ARRAY_SIZE(power_line_frequency_controls_uvc11), > > > > ... use > > > > .menu_count = ARRAY_SIZE(power_line_frequency_controls) - 1, > > > > here. It will avoid duplicating the common menu items. > > > > > +}; > > > + > > > +static const > > > +struct uvc_control_mapping power_line_mapping_uvc15 = { > > > > This holds on a single line (and same for 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_info = power_line_frequency_controls_uvc15, > > > + .menu_count = ARRAY_SIZE(power_line_frequency_controls_uvc15), > > > +}; > > > > How about turning those two into arrays (named uvc_ctrl_mappings_uvc11 > > and uvc_ctrl_mappings_uvc15) ? uvc_ctrl_init_ctrl() would first loop > > over uvc_ctrl_mappings, and then over the version-specific arrays. This > > would ease support of further version-specific controls. > > I like the idea, but in this particular case, we have to add a third > value for limited_powerline, which defeats the purpose :(. > > What about something like this: > https://git.kernel.org/pub/scm/linux/kernel/git/ribalda/linux.git/commit/?h=uvc-powerline-v4&id=f1ad7c4d8552843c785d4a22bba233d21f3aed45 > > Basically, leave an array with all the powerline definitions > (Disabled, 50, 60 and auto), and then hack around the index and > sizes. That's also an option. I have however sent a v4/RFC with a more generic approach than a quirk, could you have a look at it ? Testing would be appreciated too. > > > + > > > /* ------------------------------------------------------------------------ > > > * Utility functions > > > */ > > > @@ -2376,6 +2398,22 @@ static void uvc_ctrl_prune_entity(struct uvc_device *dev, > > > } > > > } > > > > > > +/* > > > + * The powerline control has different valid values depending on the > > > + * uvc version. > > > + */ > > > +static void uvc_ctrl_init_powerline(struct uvc_video_chain *chain, > > > + struct uvc_control *ctrl) > > > +{ > > > + if (chain->dev->uvc_version < 0x0150) { > > > + __uvc_ctrl_add_mapping(chain, ctrl, > > > + &power_line_mapping_uvc11); > > > + return; > > > + } > > > + > > > + __uvc_ctrl_add_mapping(chain, ctrl, &power_line_mapping_uvc15); > > > +} > > > + > > > /* > > > * Add control information and hardcoded stock control mappings to the given > > > * device. > > > @@ -2385,6 +2423,7 @@ 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); > > > + static const u8 uvc_processing_guid[16] = UVC_GUID_UVC_PROCESSING; > > > > Please move this first, the driver declares static variables before the > > non-static ones. > > Ack > > > > const struct uvc_control_mapping *mapping = uvc_ctrl_mappings; > > > const struct uvc_control_mapping *mend = > > > mapping + ARRAY_SIZE(uvc_ctrl_mappings); > > > @@ -2415,6 +2454,10 @@ static void uvc_ctrl_init_ctrl(struct uvc_video_chain *chain, > > > if (!ctrl->initialized) > > > return; > > > > > > + if (uvc_entity_match_guid(ctrl->entity, uvc_processing_guid) && > > > + ctrl->info.selector == UVC_PU_POWER_LINE_FREQUENCY_CONTROL) > > > + return uvc_ctrl_init_powerline(chain, ctrl); > > > + > > > for (; mapping < mend; ++mapping) { > > > if (uvc_entity_match_guid(ctrl->entity, mapping->entity) && > > > ctrl->info.selector == mapping->selector) -- Regards, Laurent Pinchart