From mboxrd@z Thu Jan 1 00:00:00 1970 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 1C39523BD1B; Sat, 6 Jun 2026 15:29:15 +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=1780759757; cv=none; b=HgBSDC8AWhQOyLut2et4loqW3j7H7iREX+B9HQPYvrRCzW9+MB/X7C4TxYAtf1rfcMfeFw0pIKlv5zEnJRTLf5pk7dok2HCZXhHBJ8NGdQuk9+uHdqcc15orPMkRktXmOKPsl84XVeCoRnmpk1L4A3yaMLbBxRCjAMpJJO5PABc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780759757; c=relaxed/simple; bh=lAgHSjWrGPCLr+UAktxESvxGWk2CswLVUi2LmW61X8E=; h=Content-Type:MIME-Version:In-Reply-To:References:Subject:From:Cc: To:Date:Message-ID; b=RyWGg1FTYECU52gpahtSDGLZF+ZWBaiurKPs6qCx9QUfkO/wZ+NPRTUN8wli01X1RidCnda5zyUYObTABApqfY3mBQKntFe/OwYnsORqZ9tFMtjMKoGN7afZLl+RgwLBJXJfOELigsXquaJjEpnmxh7rI2e+7cfpx95an23D1zs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (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=knjed57o; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="knjed57o" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c66:476d:c684:fe78:389f:7375]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E791E63C; Sat, 6 Jun 2026 17:28:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1780759727; bh=lAgHSjWrGPCLr+UAktxESvxGWk2CswLVUi2LmW61X8E=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=knjed57ofP+A+RTTM/kzNPJh1UKICtyvtYGtwFaNCpZfNYwAva2zI0k79sDyyEUzj 0ZHO8LjdSZXj1I0nVTLS0APGEwnG6XzuTzoomwf/EAnVEljM/yRBJ9YMQb2LV2dKJc +tyZu586tXSZZway8jUJCpfDmffNz6JwTsGRmj+g= Content-Type: text/plain; charset="utf-8" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: References: <20260605-imx678-v4-0-58e57c67143d@ideasonboard.com> <20260605-imx678-v4-2-58e57c67143d@ideasonboard.com> <178075217188.9570.14789474340505402551@freya> Subject: Re: [PATCH v4 2/2] media: i2c: imx678: Add driver for Sony IMX678 From: Jai Luthra Cc: Lachlan Michael , Ryuichi Tadano , Kengo Hayasaka , "linux-media@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" To: Conor Dooley , Kieran Bingham , Krzysztof Kozlowski , Laurent Pinchart , Mauro Carvalho Chehab , Rob Herring , Sakari Ailus , Tarang Raval Date: Sat, 06 Jun 2026 20:59:08 +0530 Message-ID: <178075974823.9570.15829300390679437100@freya> User-Agent: alot/0.13.dev35+g4a69c46ca Quoting Tarang Raval (2026-06-06 20:15:48) > Hi Jai. >=20 > > Quoting Tarang Raval (2026-06-06 13:47:36) > > > Hi Jai, > > > > > > Sorry, in my first review I missed a few minor issues listed below. > > > > > > > No worries, thank you for the reviews. > > > > > I also noticed one major issue in the driver. Please check the commen= ts below. > > > > > > Other than that, the driver looks perfect. > > > > > > > Add a V4L2 subdev driver for the Sony IMX678 image sensor. > > > > > > > > IMX678 is a diagonal 8.86 mm (Type 1/1.8) CMOS active pixel type > > > > solid-state image sensor with a square pixel array and 8.40 M effec= tive > > > > pixels. > > > > > > > > The following features are supported by this driver: > > > > - MIPI RAW12 output > > > > - Monochrome and Color (Bayer filter) variants > > > > - Multiple input clock frequencies > > > > - Multiple link frequencies > > > > - VBLANK and HBLANK control for variable framerate > > > > - VFLIP and HFLIP control for flipping readout > > > > - Exposure and analogue gain control > > > > - Test pattern control > > > > > > > > Following features are not currently supported: > > > > - MIPI RAW10 output > > > > - Pixel-perfect crop reporting, accounting for the shift-by-1 when > > > > doing HFLIP/VFLIP where the sensor maintains RGGB bayer ordering > > > > > > > > Along with the ones below which depend on the new raw sensor model: > > > > - Embedded data stream > > > > - Freely configurable cropping > > > > - Increased framerate when cropping > > > > - 2x2 binning support > > > > > > > > Signed-off-by: Jai Luthra > > > > > > ... > > > > > > > +static const u32 codes_bayer[] =3D { > > > > + MEDIA_BUS_FMT_SRGGB12_1X12, > > > > +}; > > > > + > > > > +static const u32 codes_monochrome[] =3D { > > > > + MEDIA_BUS_FMT_Y12_1X12, /* 12-bit mono */ > > > > > > Above comment adds no useful information and can be dropped. > > > > > > > +}; > > > > + > > > > +static const struct imx678_model_info imx678_aaqr_info =3D { > > > > + .type =3D IMX678_COLOR, > > > > + .codes =3D codes_bayer, > > > > + .num_codes =3D ARRAY_SIZE(codes_bayer), > > > > +}; > > > > + > > > > +static const struct imx678_model_info imx678_aamr_info =3D { > > > > + .type =3D IMX678_MONOCHROME, > > > > + .codes =3D codes_monochrome, > > > > + .num_codes =3D ARRAY_SIZE(codes_monochrome), > > > > +}; > > > > + > > > > +static const char * const imx678_supply_name[] =3D { > > > > + "avdd", /* Analog (3.3V) supply */ > > > > + "dvdd", /* Digital Core (1.1V) supply */ > > > > + "ovdd", /* IF (1.8V) supply */ > > > > +}; > > > > + > > > > +struct imx678 { > > > > + struct v4l2_subdev sd; > > > > + struct media_pad pad; > > > > + struct regmap *cci; > > > > + > > > > + const struct imx678_model_info *info; > > > > + > > > > + struct clk *xclk; > > > > + u32 xclk_freq; > > > > + > > > > + /* chosen INCK_SEL register value */ > > > > + u8 inck_sel_val; > > > > + > > > > + /* Link configurations */ > > > > + enum imx678_lanemode lane_mode; > > > > + unsigned long link_freq_bitmap; > > > > + > > > > + struct gpio_desc *reset_gpio; > > > > + struct regulator_bulk_data supplies[ARRAY_SIZE(imx678_suppl= y_name)]; > > > > + > > > > + struct v4l2_ctrl_handler ctrl_handler; > > > > + > > > > + /* V4L2 Controls */ > > > > + struct v4l2_ctrl *exposure; > > > > + struct v4l2_ctrl *vblank; > > > > + struct v4l2_ctrl *hblank; > > > > + > > > > + /* Tracking sensor VMAX/HMAX value */ > > > > + u32 vmax; > > > > +}; > > > > + > > > > +static inline struct imx678 *to_imx678(struct v4l2_subdev *_sd) > > > > +{ > > > > + return container_of(_sd, struct imx678, sd); > > > > > > Use container_of_const. > > > > > > > Why is that necessary? >=20 > container_of_const() preserves const and avoids accidentally casting it a= way. > For non-const pointers it behaves the same as container_of(), while for c= onst > pointers it preserves constness. >=20 > > > > > > +} > > > > > > ... > > > > > > > +static int imx678_set_ctrl(struct v4l2_ctrl *ctrl) > > > > +{ > > > > + struct imx678 *imx678 =3D container_of(ctrl->handler, struc= t imx678, > > > > + ctrl_handler); > > > > > > Use container_of_const. > > > > > > > + struct i2c_client *client =3D v4l2_get_subdevdata(&imx678->= sd); > > > > + const struct v4l2_mbus_framefmt *format; > > > > + struct v4l2_subdev_state *state; > > > > + int rpm_in_use; > > > > + int ret =3D 0; > > > > + > > > > + state =3D v4l2_subdev_get_locked_active_state(&imx678->sd); > > > > + format =3D v4l2_subdev_state_get_format(state, IMX678_SOURC= E_PAD); > > > > + > > > > + if (ctrl->id =3D=3D V4L2_CID_VBLANK) { > > > > + u32 current_exposure =3D imx678->exposure->cur.val; > > > > + > > > > + imx678->vmax =3D format->height + ctrl->val; > > > > > > ........(1) > > > > > > > + > > > > + current_exposure =3D clamp_t(u32, current_exposure, > > > > + IMX678_EXPOSURE_MIN, > > > > + imx678->vmax - IMX678_SH= R_MIN); > > > > + ret =3D __v4l2_ctrl_modify_range(imx678->exposure, > > > > + IMX678_EXPOSURE_MIN, > > > > + imx678->vmax - IMX67= 8_SHR_MIN, > > > > + 1, current_exposure); > > > > + if (ret) > > > > + return ret; > > > > + } > > > > + > > > > + /* > > > > + * Applying V4L2 control value only happens when power is u= p for > > > > + * streaming > > > > + */ > > > > + rpm_in_use =3D pm_runtime_get_if_in_use(&client->dev); > > > > + if (!rpm_in_use) > > > > + return 0; > > > > > > As in the last revision, as I suggested before, I will again suggest = using > > > pm_runtime_get_if_active() here instead of pm_runtime_get_if_in_use(). > > > > > > This does not seem to align with the comment above: > > > Applying V4L2 control value only happens when power is up for streami= ng > > > > > > "Power is up" implies that the device is in the runtime PM ACTIVE sta= te, > > > rather than simply having a non-zero usage count. > > > > > > > I agree with the comment being slightly misleading, but same as the last > > revision, I still don't fully buy your argument here :-) > > > > In the case you talk about, where PM is ACTIVE but usage count =3D=3D 0= , we > > anyway know that the count will only increase when .enable_streams is > > called, at which point the driver will anyway write *all* the registers > > including calling set_ctrl for each control with the cached values. > > > > So why should we do (redundant) writes here? >=20 > I think this is mostly a difference in expectations. >=20 > My view is that if the device is runtime PM ACTIVE, the hardware is acces= sible > and register writes can be performed. In that case, I would expect a cont= rol > change to be applied to hardware immediately. >=20 > With pm_runtime_get_if_in_use(), there is a state where the device is sti= ll > ACTIVE but control changes are only cached in software and not written to > hardware until streaming starts again. While the value is not lost, I wou= ld > expect hardware and control state to remain synchronized whenever the dev= ice > is already active. >=20 > So I understand the cached-control argument, but if the hardware is acces= sible, > I would prefer applying the control immediately rather than deferring it. >=20 Why does it matter if some sensor register doesn't match the value in the cached controls for a brief period after streaming stopped and sensor is powered off? We don't have autosuspend timer here like other drivers. I'll update the comment in v5 for future readers/developers in case that changes. > > > I also don't understand why we need to be strict here and require the > > > runtime PM usage count to be greater than zero. What matters before a= ccessing > > > the hardware registers is that the device is powered and accessible, = not > > > whether there is an active user holding a runtime PM reference. > > > > > > Anyway, rpm_in_use does not seem necessary here. The check could be s= implified to: > > > if (pm_runtime_get_if_active(&client->dev) <=3D 0) > > > > The rpm_in_use value is used below in this function to ensure we don't = do > > pm_runtime_put() in case of a negative retval. This is not really handl= ed > > by most drivers today, but I wanted to fix it here given recent discuss= ion > > [1] and annoying Sashiko reports. > > > > [1]: https://lore.kernel.org/all/ahyh0ZlwlZqr7VNa%40kekkonen.localdomain >=20 > Thats my understanding as well. With: > if (pm_runtime_get_if_active(&client->dev) <=3D 0) > return 0; >=20 > both the 0 and negative return paths exit immediately, so neither the swi= tch > statement nor pm_runtime_put() can be reached. If we do that no controls will be written to the hardware if userspace has disabled runtime. >=20 > Best Regards, > Tarang Thanks, Jai