Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp87520rdb; Tue, 31 Oct 2023 01:13:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGe/mim7/aWxPgC9Wym4DPEZ83Rk8vOPirrCsc5a5W4HlWhoAS7IHHm/0XRRzQ/XghydeVr X-Received: by 2002:a05:6a20:4c05:b0:171:8e16:ea83 with SMTP id fm5-20020a056a204c0500b001718e16ea83mr8762829pzb.29.1698740029123; Tue, 31 Oct 2023 01:13:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698740029; cv=none; d=google.com; s=arc-20160816; b=txjqg7+adS+Alk/5jR1/zczYZU91I6nKoaWSBfjxeQr2EXXnChVW6M91uu+eSuyLJW bCxBqd78nsCRQbI1dHs6mE6HSOL55Vv2FmyT9PH7imRj8cUgzvDh7jXp+6VoQpst3geG 20y5W64Cpia7zT50R0gltvKDotblalvy5Bzu0MYfFg2vaabXbi1k1xLYR5eCC37YwKyj veXbvUCU33N6+q4u/2GX9zzpqTYIJTr/sOuRUs3ip2+HsDq0/hG/VIddzbypbvQl3AOS x6mnma0VnCMm+ACb+rmqVRFnaOO/ZUmzE/Y6vfVxBsfFylXS61l/gIj9AqkhJwTMEzFC Lz2g== 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=KUSjPd9JDelxayHLoaKrsl8RYjyIQSTE5q0zW+6XXnI=; fh=3VO8YmEk4Ay7+5Hpl8uGz0JP7nEauoBnls7g5DD/hvk=; b=Iskx2vKP0Dr+bhqPsnd+zOzDRLcvmqdfHjbh28umeCKNFx6Rcs4h6XYLNwKGdQYGYr 8cU2BuBcjdgrFBmWVXiXsgOSPgja9WOx/ExNG71muyhEIuPkoYZpISH8lJAw4VHUfWqC UaXELpPRYBHc/p4UR8IlGEwYKl5l0YaVVDh49hZdiCFigcULHuOEH0rdCvC5U2kpqZg1 e7q8KiqjUJEtsVKiV10fgga4jg62bRrzbx/q3E6XcetiOwhl5NT3UOrQnVGTj6fNSb4s QiRR3y7AmrOS5cRa8k5z0jjO7+2gWJbLAdTKL4GpmWDQbLEcPNgNoYAI4iDqfEqCX1Em 8drw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fpm0K05i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id q9-20020a17090311c900b001cc310cb08dsi692311plh.53.2023.10.31.01.13.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 01:13:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fpm0K05i; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 5F90B803955A; Tue, 31 Oct 2023 01:13:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232480AbjJaINk (ORCPT + 99 others); Tue, 31 Oct 2023 04:13:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbjJaINi (ORCPT ); Tue, 31 Oct 2023 04:13:38 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE426BD; Tue, 31 Oct 2023 01:13:35 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5409bc907edso8310452a12.0; Tue, 31 Oct 2023 01:13:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698740014; x=1699344814; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=KUSjPd9JDelxayHLoaKrsl8RYjyIQSTE5q0zW+6XXnI=; b=fpm0K05iCPS618aAqxTo2tAwsd6N+Rpt3XXNaUMRGd/QX2HucBMQCDBHwjYPUsJykV 9HVfe87q8FrkEa19839mzc0W1sKLUXLPqJ6aB/JRV30p7TXjtTAeeFmMfDlNNSdo5iiF 4m2Zw3gLbvjrr8M6nKlbQFrq3uiiV/DQoXqv+Qw23QNu/n3mY/hVQiARUtz0E6KcGjGs Z/Sj7wt9OJuCiGKxa2vqZQeHdybAIeiV9VJ4cxjUcEsX3g1pdF1PxBsG6v24xk209jiy tiVVDkosfjPEQ7R7PIhLprKry4Z99Zp3t0Rr3p7Of960zHXVKmRWVaO0LdOMBIdwe3md PE1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698740014; x=1699344814; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=KUSjPd9JDelxayHLoaKrsl8RYjyIQSTE5q0zW+6XXnI=; b=evCIg858RMvvlaQzCtWEH7aW33OY4JtgIPlCOkTHWRECqTTeuuAt7Ui3VT4Kevnh6C UubMZz3amtlznEVROJGnGrlrx81HpKdWC7jif9eR3mOdDKidphyKzA2pSGCf50UEJ5E9 rD8XPqaoltLeeC6ulmLDyYDGwHrdmUflS1nkNUadLN9ec5MuCSs/ew2+PUO8/qsuUbo5 QL1bSYSB//VrxFN8MUkkV2NFZSK5+5DlJR+3DJCSxEwk8on3etxccxnpDg1GiLbz+9Bt 0wgctsfKLJ4mNgbirRiec8YVZqx0nXxI8+IxvPn7AFxs/rC5ePgGXPL2MJtyc/4LAGOP xndA== X-Gm-Message-State: AOJu0YzO4323ncSyd/ptwaQNQIBKFVCyYgxkNRNTdnppnZztFr0487qO 0UJddxyXX5qBGQVYJKWnxnI= X-Received: by 2002:a17:907:7f92:b0:9bd:f155:eb54 with SMTP id qk18-20020a1709077f9200b009bdf155eb54mr11872826ejc.6.1698740014038; Tue, 31 Oct 2023 01:13:34 -0700 (PDT) Received: from tom-HP-ZBook-Fury-15-G7-Mobile-Workstation (net-188-217-59-109.cust.vodafonedsl.it. [188.217.59.109]) by smtp.gmail.com with ESMTPSA id rp16-20020a170906d97000b009ae57888718sm530859ejb.207.2023.10.31.01.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 01:13:33 -0700 (PDT) Date: Tue, 31 Oct 2023 09:13:30 +0100 From: Tommaso Merciai To: Sakari Ailus Cc: martin.hecht@avnet.eu, michael.roeder@avnet.eu, mhecht73@gmail.com, linuxfancy@googlegroups.com, Mauro Carvalho Chehab , Liam Girdwood , Mark Brown , Laurent Pinchart , Hans de Goede , Hans Verkuil , Tomi Valkeinen , Marco Felsch , Gerald Loacker , Andy Shevchenko , Daniel Scally , Shawn Tu , Linus Walleij , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: Re: [PATCH v10 3/3] media: i2c: Add support for alvium camera Message-ID: References: <20231020141354.2500602-1-tomm.merciai@gmail.com> <20231020141354.2500602-4-tomm.merciai@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 31 Oct 2023 01:13:46 -0700 (PDT) Hi Sakari, Thanks for your comments. On Mon, Oct 30, 2023 at 10:43:47PM +0000, Sakari Ailus wrote: > Hi Tommaso, > > On Mon, Oct 30, 2023 at 01:26:58PM +0100, Tommaso Merciai wrote: > > ... > > > > > +static int alvium_get_host_supp_csi_lanes(struct alvium_dev *alvium) > > > > +{ > > > > + u64 val; > > > > + int ret = 0; > > > > + > > > > + alvium_read(alvium, REG_BCRM_CSI2_LANE_COUNT_RW, &val, &ret); > > > > > > Missing error checking before the use of the value. The same pattern > > > remains prevalent throughout the driver. > > > > > > I think it'd be easier if you didn't use a temporary variable for reading, > > > but instead had a register width specific access function. You could even > > > introduce a helper macro to read this information as I suggested in an > > > earlier review. > > > > oks. > > We are moving to use the following macros: > > > > #define alvium_read_check(alvium, reg, value) \ > > { \ > > int ret = alvium_read(alvium, reg, value, NULL); \ > > if (ret) \ > > return ret; \ > > } > > > > You could do something like (entirely untested): > > #define ALVIUM_DECLARE_READ(sign, bits) \ > static int > alvium_read_ ## sign ## bits(struct alvium_dev *alvium, u32 reg, \ > sign ## bits *val, int *err) \ > { \ > u64 val64; \ > int ret; \ > \ > if (err && *err < 0) \ > return *err; \ > \ > alvium_read(alvium, reg, &val64, &ret); \ > if (ret < 0) { \ > if (err) \ > *err = ret; \ > return ret; \ > } \ > \ > *val = val64; \ > \ > return 0; \ > } > > ALVIUM_DECLARE_READ(u, 32); > > And then, e.g. instead of (and failing to check ret): > > u64 val; > > alvium_read(alvium, REG_BCRM_CONTRAST_VALUE_RW, &val, &ret); > alvium->dft_contrast = val; > > you'd have a single call: > > alvium_read_u32(alvium, REG_BCRM_CONTRAST_VALUE_RW, > &alvium->dft_contrast, &ret); > > And so on. > > You can drop sign if you don't need signed reads but some of the struct > fields you're writing something appear to be signed. > > It'd be good to check the register size matches with the size of *val, too. > Maybe something like: > > WARN_ON((CCI_REG ## bits(0) && CCI_REG_WIDTH_MASK) >> CCI_REG_WIDTH_SHIFT > != sizeof(sign ## bits)); Laurent suggest me also a good way. I switched to the Laurent suggested implementation in v11. I think now is clear. Thanks to both again. Let me know what do you think about :) > > > > > +static int alvium_get_csi_clk_params(struct alvium_dev *alvium) > > > > +{ > > > > + u64 val; > > > > + int ret = 0; > > > > + > > > > + alvium_read(alvium, REG_BCRM_CSI2_CLOCK_MIN_R, &val, &ret); > > > > + alvium->min_csi_clk = val; > > > > + > > > > + alvium_read(alvium, REG_BCRM_CSI2_CLOCK_MAX_R, &val, &ret); > > > > + alvium->max_csi_clk = val; > > > > + > > > > + return ret; > > > > +} > > > > + > > > > +static int alvium_set_csi_clk(struct alvium_dev *alvium) > > > > +{ > > > > + struct device *dev = &alvium->i2c_client->dev; > > > > + u64 csi_clk; > > > > + int ret; > > > > + > > > > + csi_clk = (u32)alvium->ep.link_frequencies[0]; > > > > > > Why casting to u32? Shouldn't csi_clk be u32 instead? > > > > Ok we fix this in v11. > > Change to use u64 for calculation because type of ep.link_frequencies[0] > > Plan is to clamp csi_clk between min/max instead of returning error. > > I think I would keep it as-is: this isn't V4L2 UAPI. > > > > > > > > > > + > > > > + if (csi_clk < alvium->min_csi_clk || csi_clk > alvium->max_csi_clk) > > > > + return -EINVAL; > > > > + > > > > + ret = alvium_write_hshake(alvium, REG_BCRM_CSI2_CLOCK_RW, csi_clk); > > > > + if (ret) { > > > > + dev_err(dev, "Fail to set csi lanes reg\n"); > > > > + return ret; > > > > + } > > > > + > > > > + alvium->link_freq = alvium->ep.link_frequencies[0]; > > > > + > > > > + return 0; > > > > +} > > ... > > > > > + goto out; > > > > + > > > > + ret = alvium_set_mode(alvium, state); > > > > + if (ret) > > > > + goto out; > > > > + > > > > + fmt = v4l2_subdev_get_pad_format(sd, state, 0); > > > > + ret = alvium_set_framefmt(alvium, fmt); > > > > + if (ret) > > > > + goto out; > > > > + > > > > + ret = alvium_set_stream_mipi(alvium, enable); > > > > + if (ret) > > > > + goto out; > > > > + > > > > + } else { > > > > + alvium_set_stream_mipi(alvium, enable); > > > > + pm_runtime_mark_last_busy(&client->dev); > > > > + pm_runtime_put_autosuspend(&client->dev); > > > > > > pm_runtime_put() here, too. > > > > Here is not needed we already have pm_runtime_put_autosuspend. > > I'm missing something? > > Ah, I missed that while reviewing. Please ignore that comment then. No problem, update in v11. > > > > > > > > > > + } > > > > + > > > > + alvium->streaming = !!enable; > > > > + v4l2_subdev_unlock_state(state); > > > > + > > > > + return 0; > > > > + > > > > +out: > > > > + v4l2_subdev_unlock_state(state); > > > > + return ret; > > > > +} > > > > + > > > > +static int alvium_init_cfg(struct v4l2_subdev *sd, > > > > + struct v4l2_subdev_state *state) > > > > +{ > > > > + struct alvium_dev *alvium = sd_to_alvium(sd); > > > > + struct alvium_mode *mode = &alvium->mode; > > > > > > Init_cfg() is expected to be configuration independent (as much as > > > possible). Therefore you should use defaults here, not current mode. > > > > Defaults alvium mode already used here. > > Ah, indeed. Please ignore. No problem. Thanks & Regards, Tommaso > > -- > Kind regards, > > Sakari Ailus