Linux Media Controller development
 help / color / mirror / Atom feed
From: Jai Luthra <jai.luthra@ideasonboard.com>
To: Alexander Shiyan <eagle.alexander923@gmail.com>,
	Dave Stevenson <dave.stevenson@raspberrypi.com>
Cc: linux-media@vger.kernel.org, devicetree@vger.kernel.org,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Hans Verkuil <hverkuil@kernel.org>,
	Hans de Goede <hansg@kernel.org>,
	Tetsuya Nomura <tetsuya.nomura@soho-enterprise.com>,
	Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Subject: Re: [PATCH 2/2] media: i2c: Add driver for Sony IMX662 sensor
Date: Mon, 20 Jul 2026 20:14:21 +0530	[thread overview]
Message-ID: <178455866124.1426769.18237320419273419942@freya> (raw)
In-Reply-To: <CAPY8ntAf9TjgW-E6WeJuMdsHy8pV8-CvqQJriWEFpgLB-brD5A@mail.gmail.com>

Hi Dave, Alexander,

Quoting Dave Stevenson (2026-03-13 01:20:15)
> Hi Alexander
> 
> On Thu, 12 Mar 2026 at 15:11, Alexander Shiyan
> <eagle.alexander923@gmail.com> wrote:
> >
> > This patch adds a V4L2 subdevice driver for the Sony IMX662 CMOS image
> > sensor. The sensor has a native resolution of 1936x1100 (effective
> > 1920x1080) and can achieve up to 90 frames per second depending on
> > the configuration. The driver supports:
> > - MIPI CSI-2 with 2 or 4 data lanes.
> > - RAW10 and RAW12 formats (both colour and monochrome).
> > - Controls: exposure, analogue gain, horizontal/vertical blanking,
> >   horizontal/vertical flip, brightness.
> > - A placeholder V4L2_CID_HDR_SENSOR_MODE control for future Clear HDR
> >   support (the actual HDR modes are not yet implemented).
> > - Runtime PM.
> > - Cropping via the selection API.
> > - Multiple link frequencies selectable via device tree.
> >
> > Tested on ARM64 Rockchip RK3568 platform with a 24 MHz external clock
> > and various link frequencies.
> 
> Interesting timing as I've been looking at IMX662 too, but on a Raspberry Pi.
> FWIW my driver is at
> https://github.com/6by9/linux/blob/rpi-6.12.y-imx662/drivers/media/i2c/imx662.c
> 

I saw libcamera patches for IMX676, does the below branch have the latest
driver you plan to post as v2?

https://github.com/6by9/linux/blob/rpi-6.18.y-imx662-mainline-clean/drivers/media/i2c/imx662.c 

> Comments are based on brief testing and reading of the code. This is
> not a full review.
> 
> > Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>

[...]

> > +static int imx662_set_selection(struct v4l2_subdev *sd,
> > +                               struct v4l2_subdev_state *sd_state,
> > +                               struct v4l2_subdev_selection *sel)
> > +{

Can we keep cropping and binning out of the initial driver, and implement
it using the common raw sensor model directly?

I did it for IMX678 [1] on Sakari's suggestion [2]. The two sensors are
quite similar, so I'm happy to help in whatever way I can on getting this
working with the new model too :-)

[1]: https://lore.kernel.org/all/20260703-imx678-meta-v1-0-7c4924a0df05@ideasonboard.com/
[2]: https://lore.kernel.org/all/ag7oq5jO5G0rwvzb@kekkonen.localdomain/

Thanks,
    Jai

> > +       struct imx662 *imx662 = to_imx662(sd);
> > +       struct v4l2_rect rect = sel->r;
> > +       struct v4l2_rect *try_crop;
> > +       struct v4l2_mbus_framefmt *try_fmt;
> > +       u32 max_left, max_top;
> > +
> > +       if (sel->target != V4L2_SEL_TGT_CROP)
> > +               return -EINVAL;
> > +
> > +       max_left = IMX662_PIXEL_ARRAY_LEFT + IMX662_PIXEL_ARRAY_WIDTH -
> > +                  IMX662_MIN_CROP_WIDTH;
> > +       max_top = IMX662_PIXEL_ARRAY_TOP + IMX662_PIXEL_ARRAY_HEIGHT -
> > +                 IMX662_MIN_CROP_HEIGHT;
> > +
> > +       rect.left = clamp_t(u32, rect.left, IMX662_PIXEL_ARRAY_LEFT, max_left);
> > +       rect.top = clamp_t(u32, rect.top, IMX662_PIXEL_ARRAY_TOP, max_top);
> > +
> > +       rect.width =
> > +               clamp_t(u32,
> > +                       round_down(rect.width, IMX662_CROP_WIDTH_STEP),
> > +                       IMX662_MIN_CROP_WIDTH, IMX662_PIXEL_ARRAY_WIDTH);
> > +       rect.height =
> > +               clamp_t(u32,
> > +                       round_down(rect.height, IMX662_CROP_HEIGHT_STEP),
> > +                       IMX662_MIN_CROP_HEIGHT, IMX662_PIXEL_ARRAY_HEIGHT);
> > +
> > +       if (rect.left + rect.width - 1 >
> > +           IMX662_PIXEL_ARRAY_LEFT + IMX662_PIXEL_ARRAY_WIDTH - 1)
> > +               rect.left =
> > +                       IMX662_PIXEL_ARRAY_LEFT + IMX662_PIXEL_ARRAY_WIDTH -
> > +                       rect.width;
> > +       if (rect.top + rect.height - 1 >
> > +           IMX662_PIXEL_ARRAY_TOP + IMX662_PIXEL_ARRAY_HEIGHT - 1)
> > +               rect.top =
> > +                       IMX662_PIXEL_ARRAY_TOP + IMX662_PIXEL_ARRAY_HEIGHT -
> > +                       rect.height;
> > +
> > +       if (sel->flags & V4L2_SEL_FLAG_GE) {
> > +               if (rect.width < sel->r.width) {
> > +                       u32 new_width = rect.width + IMX662_CROP_WIDTH_STEP;
> > +
> > +                       if (new_width <= IMX662_PIXEL_ARRAY_WIDTH)
> > +                               rect.width = new_width;
> > +               }
> > +               if (rect.height < sel->r.height) {
> > +                       u32 new_height = rect.height + IMX662_CROP_HEIGHT_STEP;
> > +
> > +                       if (new_height <= IMX662_PIXEL_ARRAY_HEIGHT)
> > +                               rect.height = new_height;
> > +               }
> > +       }
> > +
> > +       if (sel->flags & V4L2_SEL_FLAG_LE) {
> > +               if (rect.width > sel->r.width &&
> > +                   rect.width >= IMX662_MIN_CROP_WIDTH +
> > +                                 IMX662_CROP_WIDTH_STEP)
> > +                       rect.width -= IMX662_CROP_WIDTH_STEP;
> > +               if (rect.height > sel->r.height &&
> > +                   rect.height >= IMX662_MIN_CROP_HEIGHT +
> > +                                  IMX662_CROP_HEIGHT_STEP)
> > +                       rect.height -= IMX662_CROP_HEIGHT_STEP;
> > +       }
> > +
> > +       if (rect.width < IMX662_MIN_CROP_WIDTH ||
> > +           rect.height < IMX662_MIN_CROP_HEIGHT)
> > +               return -EINVAL;
> > +
> > +       if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
> > +               try_crop = v4l2_subdev_state_get_crop(sd_state, sel->pad);
> > +               *try_crop = rect;
> > +
> > +               try_fmt = v4l2_subdev_state_get_format(sd_state, sel->pad);
> > +               if (try_fmt) {
> > +                       try_fmt->width = rect.width;
> > +                       try_fmt->height = rect.height;
> > +               }
> > +       } else {
> > +               if (imx662->streaming)
> > +                       return -EBUSY;
> > +
> > +               if (imx662->crop.left == rect.left &&
> > +                   imx662->crop.top == rect.top &&
> > +                   imx662->crop.width == rect.width &&
> > +                   imx662->crop.height == rect.height) {
> > +                       sel->r = rect;
> > +                       return 0;
> > +               }
> > +
> > +               imx662->crop = rect;
> > +
> > +               try_fmt = v4l2_subdev_state_get_format(sd_state, sel->pad);
> > +               if (try_fmt) {
> > +                       try_fmt->width = rect.width;
> > +                       try_fmt->height = rect.height;
> > +               }
> > +
> > +               imx662_set_framing_limits(imx662);
> > +       }
> > +
> > +       sel->r = rect;
> > +
> > +       return 0;
> > +}

[...]

  parent reply	other threads:[~2026-07-20 14:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 15:04 [PATCH 0/2] media: i2c: Add support for Sony IMX662 sensor Alexander Shiyan
2026-03-12 15:04 ` [PATCH 1/2] dt-bindings: media: i2c: Add " Alexander Shiyan
2026-03-12 16:30   ` Rob Herring (Arm)
2026-03-13 13:52   ` Krzysztof Kozlowski
2026-03-12 15:04 ` [PATCH 2/2] media: i2c: Add driver for " Alexander Shiyan
2026-03-12 19:50   ` Dave Stevenson
2026-03-13  1:15     ` tetsuya.nomura
2026-03-13  7:55     ` Alexander Shiyan
2026-03-17 15:52       ` Dave Stevenson
2026-03-13 12:26     ` Alexander Shiyan
2026-07-20 14:44     ` Jai Luthra [this message]
2026-07-20 17:39       ` Dave Stevenson
2026-07-20 22:03         ` Sakari Ailus
2026-03-13 13:46   ` Krzysztof Kozlowski

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=178455866124.1426769.18237320419273419942@freya \
    --to=jai.luthra@ideasonboard.com \
    --cc=conor+dt@kernel.org \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=devicetree@vger.kernel.org \
    --cc=eagle.alexander923@gmail.com \
    --cc=hansg@kernel.org \
    --cc=hverkuil@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=mchehab@kernel.org \
    --cc=robh@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tetsuya.nomura@soho-enterprise.com \
    /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