Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp434982rdb; Wed, 20 Dec 2023 01:13:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFh57ceEuC0fR/Kl9br4PFWK9F/w8NIwwmc+8YaHsRDHD7gNmLpIrIx6weiliRXg/IO9aEj X-Received: by 2002:a05:6808:2381:b0:3b8:9582:f2b6 with SMTP id bp1-20020a056808238100b003b89582f2b6mr14359031oib.50.1703063605221; Wed, 20 Dec 2023 01:13:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703063605; cv=none; d=google.com; s=arc-20160816; b=PtcOnbpYRD6zrGvZuJibbzIKt0jGHUbTgXUMLyvSSF2vInJk97sC8hjHxJlIU+YmAm F6RqRNXboijvSO8R75jbvhfTkf0JynjnmxCO3EJkMC1IE849VCzUUaenTGrjAdxaqKr1 K5BzXsKWo4O4kK9iwiZMxIb4lz7/qtsQqMwIGoR+Wi4FcSjK3Z4Y4pYkRgoXRbgjAW2j cyJH8nfqNJiy+FJ5cdpqdhvcSSx2wP85uhK/kILtyJ21UTcveTjkU9p6XopvB+tGmhju 5hry3UQTxUFG2yn8ugcsT/0P8FEzlMO5LbOWN1/5n3w8SwMtyZYI5K8uPflrRVw82tF2 osuA== ARC-Message-Signature: i=1; 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=Ptmh6GkNZT4UqT6aYNICdcCHPvxm41SBFtFPfOJ1Dig=; fh=yFFfmksCYrZx9KBlBazuNGjXI8fgCRbzhjFy6n9sUxM=; b=FvazmkCWx0I15JqE4Zshm64S25BL57Q1P4u3/GD0832waWJhJa4bMe03UmhhV26N+f n44kK+O0S/YIcFY646xaEpQeXR0ToPRMGO05F8pMdOepQlVD2iu32kOPJFS8YV1/z4Bp PUbrvOh49ciY15U7rknn0dLm45rG37sagltwxRP+ggkagKTMEfdipEuNLKSK7ThUpm8V 1PpFPDc2/WTcadCsA2jITh5gyyUe1imDjxQuiUVNPuJoJvKYGj9gegzwdNVb+jX5jU9N EyHuLYf+ogqVwORLQPttVfE2AVlNfgb3lYLay2jt6GA00EsBR+17cm5mXpOxPSwovEad g5Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=STB0JfoR; spf=pass (google.com: domain of linux-kernel+bounces-6626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6626-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id qb6-20020ad44706000000b0067a19d399f3si27246584qvb.590.2023.12.20.01.13.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 01:13:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=STB0JfoR; spf=pass (google.com: domain of linux-kernel+bounces-6626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6626-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E1B3C1C25871 for ; Wed, 20 Dec 2023 09:13:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DDAF1DA33; Wed, 20 Dec 2023 09:13:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="STB0JfoR" X-Original-To: linux-kernel@vger.kernel.org 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 E65AB1F616; Wed, 20 Dec 2023 09:13:04 +0000 (UTC) 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 (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AB248833; Wed, 20 Dec 2023 10:12:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1703063532; bh=WgLzJmW7ZuiIWg/L2+8ccDzkqR7myiMRk7A+gkf87SE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=STB0JfoRGfqo/3OMWPHSwQFzOiHU1a1Sf/rpi4U5yBcl4syzgkDQs1gXb0yJYa5Xw BAbBPdd1QXgi9ActRCwOe0qfS6K/nMsZGCw4lw6whpOJNuKSnjfL9/Kut0978ncQcB IHjXMLd8r/76zfoVMVXuleUFUqNqCEQRbX8lRV8Y= Date: Wed, 20 Dec 2023 11:13:09 +0200 From: Laurent Pinchart To: Tommaso Merciai Cc: linuxfancy@googlegroups.com, martin.hecht@avnet.eu, Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/4] media: i2c: alvium: removal of fr field Message-ID: <20231220091309.GG29638@pendragon.ideasonboard.com> References: <20231220085609.2595732-1-tomm.merciai@gmail.com> <20231220085609.2595732-3-tomm.merciai@gmail.com> 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: <20231220085609.2595732-3-tomm.merciai@gmail.com> Hi Tommaso, Thank you for the patch. Use the imperative in the subject line: media: i2c: alvium: Remove the fr field of the alvium_dev structure On Wed, Dec 20, 2023 at 09:56:07AM +0100, Tommaso Merciai wrote: > The fr (frame rate) field of the alvium_dev structure is > only used to pass result from alvium_set_frame_interval() to > alvium_set_frame_rate() that writes this info into the hw reg. > Replace them with function parameter. Replace it with a function parameter. > > Signed-off-by: Tommaso Merciai > --- > drivers/media/i2c/alvium-csi2.c | 24 ++++++++++++------------ > drivers/media/i2c/alvium-csi2.h | 1 - > 2 files changed, 12 insertions(+), 13 deletions(-) > > diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c > index 0dcd69bf9f92..a9ff6cc97cff 100644 > --- a/drivers/media/i2c/alvium-csi2.c > +++ b/drivers/media/i2c/alvium-csi2.c > @@ -1185,19 +1185,19 @@ static int alvium_get_frame_interval(struct alvium_dev *alvium, > return ret; > } > > -static int alvium_set_frame_rate(struct alvium_dev *alvium) > +static int alvium_set_frame_rate(struct alvium_dev *alvium, u64 fr) > { > struct device *dev = &alvium->i2c_client->dev; > int ret; > > ret = alvium_write_hshake(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW, > - alvium->fr); > + fr); > if (ret) { > dev_err(dev, "Fail to set frame rate lanes reg\n"); > return ret; > } > > - dev_dbg(dev, "set frame rate: %llu us\n", alvium->fr); > + dev_dbg(dev, "set frame rate: %llu us\n", fr); > > return 0; > } > @@ -1661,10 +1661,11 @@ static int alvium_g_frame_interval(struct v4l2_subdev *sd, > } > > static int alvium_set_frame_interval(struct alvium_dev *alvium, > - struct v4l2_subdev_frame_interval *fi) > + struct v4l2_subdev_frame_interval *fi, > + u64 *req_fr) > { > struct device *dev = &alvium->i2c_client->dev; > - u64 req_fr, dft_fr, min_fr, max_fr; > + u64 dft_fr, min_fr, max_fr; > int ret; > > if (fi->interval.denominator == 0) > @@ -1681,13 +1682,12 @@ static int alvium_set_frame_interval(struct alvium_dev *alvium, > dev_dbg(dev, "fi->interval.denominator = %d\n", > fi->interval.denominator); > > - req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) / > + *req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) / > fi->interval.numerator); > > - if (req_fr >= max_fr && req_fr <= min_fr) > - req_fr = dft_fr; > + if (*req_fr >= max_fr && *req_fr <= min_fr) > + *req_fr = dft_fr; Shouldn't we clamp the value to [min, max] instead of using the default if it's out of range ? Something like *req_fr = clamp(*req_fr, min_fr, max_fr) This makes me realize that the current code is wrong, req_fr can't be >= max and <= min at the same time. You probably meant || instead of &&. This should be fixed in a separate patch. > > - alvium->fr = req_fr; > alvium->frame_interval.numerator = fi->interval.numerator; > alvium->frame_interval.denominator = fi->interval.denominator; > > @@ -1699,6 +1699,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd, > struct v4l2_subdev_frame_interval *fi) > { > struct alvium_dev *alvium = sd_to_alvium(sd); > + u64 req_fr = ALVIUM_DEFAULT_FR_HZ; Do you need to initialize the variable ? It doesn't seem to be required. With these small issues fixed, Reviewed-by: Laurent Pinchart > int ret; > > /* > @@ -1711,9 +1712,9 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd, > if (alvium->streaming) > return -EBUSY; > > - ret = alvium_set_frame_interval(alvium, fi); > + ret = alvium_set_frame_interval(alvium, fi, &req_fr); > if (!ret) > - ret = alvium_set_frame_rate(alvium); > + ret = alvium_set_frame_rate(alvium, req_fr); > > return ret; > } > @@ -2273,7 +2274,6 @@ static int alvium_subdev_init(struct alvium_dev *alvium) > /* Setup initial frame interval*/ > alvium->frame_interval.numerator = 1; > alvium->frame_interval.denominator = ALVIUM_DEFAULT_FR_HZ; > - alvium->fr = ALVIUM_DEFAULT_FR_HZ; > > /* Setup the initial mode */ > alvium->mode.fmt = alvium_csi2_default_fmt; > diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h > index 17f0bbbd1839..80066ac25047 100644 > --- a/drivers/media/i2c/alvium-csi2.h > +++ b/drivers/media/i2c/alvium-csi2.h > @@ -443,7 +443,6 @@ struct alvium_dev { > > struct alvium_mode mode; > struct v4l2_fract frame_interval; > - u64 fr; > > u8 h_sup_csi_lanes; > u64 link_freq; -- Regards, Laurent Pinchart