From: Jai Luthra <jai.luthra@ideasonboard.com>
To: Conor Dooley <conor+dt@kernel.org>,
Kieran Bingham <kieran.bingham@ideasonboard.com>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Rob Herring <robh@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Tarang Raval <tarang.raval@siliconsignals.io>
Cc: Lachlan Michael <Lachlan.Michael@sony.com>,
Ryuichi Tadano <Ryuichi.Tadano@sony.com>,
Kengo Hayasaka <Kengo.Hayasaka@sony.com>,
"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 2/2] media: i2c: imx678: Add driver for Sony IMX678
Date: Sat, 06 Jun 2026 20:59:08 +0530 [thread overview]
Message-ID: <178075974823.9570.15829300390679437100@freya> (raw)
In-Reply-To: <PN3P287MB18292FBAEABB556C051434848B1E2@PN3P287MB1829.INDP287.PROD.OUTLOOK.COM>
Quoting Tarang Raval (2026-06-06 20:15:48)
> Hi Jai.
>
> > 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 comments 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 effective
> > > > 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 <jai.luthra@ideasonboard.com>
> > >
> > > ...
> > >
> > > > +static const u32 codes_bayer[] = {
> > > > + MEDIA_BUS_FMT_SRGGB12_1X12,
> > > > +};
> > > > +
> > > > +static const u32 codes_monochrome[] = {
> > > > + 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 = {
> > > > + .type = IMX678_COLOR,
> > > > + .codes = codes_bayer,
> > > > + .num_codes = ARRAY_SIZE(codes_bayer),
> > > > +};
> > > > +
> > > > +static const struct imx678_model_info imx678_aamr_info = {
> > > > + .type = IMX678_MONOCHROME,
> > > > + .codes = codes_monochrome,
> > > > + .num_codes = ARRAY_SIZE(codes_monochrome),
> > > > +};
> > > > +
> > > > +static const char * const imx678_supply_name[] = {
> > > > + "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_supply_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?
>
> container_of_const() preserves const and avoids accidentally casting it away.
> For non-const pointers it behaves the same as container_of(), while for const
> pointers it preserves constness.
>
> >
> > > > +}
> > >
> > > ...
> > >
> > > > +static int imx678_set_ctrl(struct v4l2_ctrl *ctrl)
> > > > +{
> > > > + struct imx678 *imx678 = container_of(ctrl->handler, struct imx678,
> > > > + ctrl_handler);
> > >
> > > Use container_of_const.
> > >
> > > > + struct i2c_client *client = v4l2_get_subdevdata(&imx678->sd);
> > > > + const struct v4l2_mbus_framefmt *format;
> > > > + struct v4l2_subdev_state *state;
> > > > + int rpm_in_use;
> > > > + int ret = 0;
> > > > +
> > > > + state = v4l2_subdev_get_locked_active_state(&imx678->sd);
> > > > + format = v4l2_subdev_state_get_format(state, IMX678_SOURCE_PAD);
> > > > +
> > > > + if (ctrl->id == V4L2_CID_VBLANK) {
> > > > + u32 current_exposure = imx678->exposure->cur.val;
> > > > +
> > > > + imx678->vmax = format->height + ctrl->val;
> > >
> > > ........(1)
> > >
> > > > +
> > > > + current_exposure = clamp_t(u32, current_exposure,
> > > > + IMX678_EXPOSURE_MIN,
> > > > + imx678->vmax - IMX678_SHR_MIN);
> > > > + ret = __v4l2_ctrl_modify_range(imx678->exposure,
> > > > + IMX678_EXPOSURE_MIN,
> > > > + imx678->vmax - IMX678_SHR_MIN,
> > > > + 1, current_exposure);
> > > > + if (ret)
> > > > + return ret;
> > > > + }
> > > > +
> > > > + /*
> > > > + * Applying V4L2 control value only happens when power is up for
> > > > + * streaming
> > > > + */
> > > > + rpm_in_use = 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 streaming
> > >
> > > "Power is up" implies that the device is in the runtime PM ACTIVE state,
> > > 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 == 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?
>
> I think this is mostly a difference in expectations.
>
> My view is that if the device is runtime PM ACTIVE, the hardware is accessible
> and register writes can be performed. In that case, I would expect a control
> change to be applied to hardware immediately.
>
> With pm_runtime_get_if_in_use(), there is a state where the device is still
> 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 would
> expect hardware and control state to remain synchronized whenever the device
> is already active.
>
> So I understand the cached-control argument, but if the hardware is accessible,
> I would prefer applying the control immediately rather than deferring it.
>
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 accessing
> > > 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 simplified to:
> > > if (pm_runtime_get_if_active(&client->dev) <= 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 handled
> > by most drivers today, but I wanted to fix it here given recent discussion
> > [1] and annoying Sashiko reports.
> >
> > [1]: https://lore.kernel.org/all/ahyh0ZlwlZqr7VNa%40kekkonen.localdomain
>
> Thats my understanding as well. With:
> if (pm_runtime_get_if_active(&client->dev) <= 0)
> return 0;
>
> both the 0 and negative return paths exit immediately, so neither the switch
> 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.
>
> Best Regards,
> Tarang
Thanks,
Jai
next prev parent reply other threads:[~2026-06-06 15:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 15:26 [PATCH v4 0/2] media: Add bindings and " Jai Luthra
2026-06-05 15:26 ` [PATCH v4 1/2] dt-bindings: media: i2c: Add " Jai Luthra
2026-06-05 15:57 ` Conor Dooley
2026-06-05 15:26 ` [PATCH v4 2/2] media: i2c: imx678: Add driver for " Jai Luthra
2026-06-06 8:17 ` Tarang Raval
2026-06-06 13:22 ` Jai Luthra
2026-06-06 14:45 ` Tarang Raval
2026-06-06 15:29 ` Jai Luthra [this message]
2026-06-06 16:21 ` Tarang Raval
2026-06-07 3:34 ` Jai Luthra
2026-06-07 7:21 ` Tarang Raval
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=178075974823.9570.15829300390679437100@freya \
--to=jai.luthra@ideasonboard.com \
--cc=Kengo.Hayasaka@sony.com \
--cc=Lachlan.Michael@sony.com \
--cc=Ryuichi.Tadano@sony.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=kieran.bingham@ideasonboard.com \
--cc=krzk+dt@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=robh@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=tarang.raval@siliconsignals.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®