Linux-Media Archive on lore.kernel.org
 help / color / Atom feed
From: Dave Stevenson <dave.stevenson@raspberrypi.com>
To: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
Cc: Jacopo Mondi <jacopo@jmondi.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	Hans Verkuil <hverkuil@xs4all.nl>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>,
	Dave Stevenson <dave.stevenson@raspberrypi.org>,
	Naushir Patuck <naush@raspberrypi.com>,
	andrew_gabbasov@mentor.com, mrodin@de.adit-jv.com,
	Maxime Ripard <mripard@kernel.org>,
	libcamera-devel@lists.libcamera.org, sudipi@jp.adit-jv.com,
	hugues.fruchet@st.com, erosca@de.adit-jv.com, aford173@gmail.com,
	Linux Media Mailing List <linux-media@vger.kernel.org>
Subject: Re: [libcamera-devel] [PATCH 22/25] media: ov5647: Support V4L2_CID_PIXEL_RATE
Date: Mon, 29 Jun 2020 22:25:12 +0100
Message-ID: <CAPY8ntBq6Lzo2qPNX6ke608SOQYVxsdjfXj2GTS6uZQMmi23JQ@mail.gmail.com> (raw)
In-Reply-To: <3aab9b3d-0156-e83c-9a63-026ded395af6@collabora.com>

Hi Dafna

On Mon, 29 Jun 2020 at 18:01, Dafna Hirschfeld
<dafna.hirschfeld@collabora.com> wrote:
>
>
>
> On 23.06.20 18:55, Jacopo Mondi wrote:
> > From: Dave Stevenson <dave.stevenson@raspberrypi.com>
> >
> > Clients need to know the pixel rate in order to compute exposure
> > and frame rate values. Advertise it.
> >
> > Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> > ---
> >   drivers/media/i2c/ov5647.c | 40 +++++++++++++++++++++++++++++++-------
> >   1 file changed, 33 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
> > index 35865e56de5f9..218576a05e66b 100644
> > --- a/drivers/media/i2c/ov5647.c
> > +++ b/drivers/media/i2c/ov5647.c
> > @@ -76,6 +76,7 @@ struct regval_list {
> >   struct ov5647_mode {
> >       struct v4l2_mbus_framefmt       format;
> >       struct v4l2_rect                crop;
> > +     u64                             pixel_rate;
> >       struct regval_list              *reg_list;
> >       unsigned int                    num_regs;
> >   };
> > @@ -97,6 +98,7 @@ struct ov5647 {
> >       struct v4l2_ctrl_handler        ctrls;
> >       struct ov5647_mode              *mode;
> >       struct ov5647_mode              *current_mode;
> > +     struct v4l2_ctrl                *pixel_rate;
> >   };
> >
> >   static inline struct ov5647 *to_sensor(struct v4l2_subdev *sd)
> > @@ -583,6 +585,7 @@ static struct ov5647_mode ov5647_sbggr8_modes[] = {
> >                       .width          = 1280,
> >                       .height         = 960,
> >               },
> > +             .pixel_rate     = 77291670,
> >               .reg_list       = ov5647_640x480_sbggr8,
> >               .num_regs       = ARRAY_SIZE(ov5647_640x480_sbggr8)
> >       },
> > @@ -604,6 +607,7 @@ static struct ov5647_mode ov5647_sbggr10_modes[] = {
> >                       .width          = 2592,
> >                       .height         = 1944
> >               },
> > +             .pixel_rate     = 87500000,
> >               .reg_list       = ov5647_2592x1944_sbggr10,
> >               .num_regs       = ARRAY_SIZE(ov5647_2592x1944_sbggr10)
> >       },
> > @@ -622,6 +626,7 @@ static struct ov5647_mode ov5647_sbggr10_modes[] = {
> >                       .width          = 1928,
> >                       .height         = 1080,
> >               },
> > +             .pixel_rate     = 81666700,
> >               .reg_list       = ov5647_1080p30_sbggr10,
> >               .num_regs       = ARRAY_SIZE(ov5647_1080p30_sbggr10)
> >       },
> > @@ -640,6 +645,7 @@ static struct ov5647_mode ov5647_sbggr10_modes[] = {
> >                       .width          = 2592,
> >                       .height         = 1944,
> >               },
> > +             .pixel_rate     = 81666700,
> >               .reg_list       = ov5647_2x2binned_sbggr10,
> >               .num_regs       = ARRAY_SIZE(ov5647_2x2binned_sbggr10)
> >       },
> > @@ -658,6 +664,7 @@ static struct ov5647_mode ov5647_sbggr10_modes[] = {
> >                       .width          = 2560,
> >                       .height         = 1920,
> >               },
> > +             .pixel_rate     = 55000000,
> >               .reg_list       = ov5647_640x480_sbggr10,
> >               .num_regs       = ARRAY_SIZE(ov5647_640x480_sbggr10)
> >       },
> > @@ -1094,6 +1101,10 @@ static int ov5647_set_pad_fmt(struct v4l2_subdev *sd,
> >       /* Update the sensor mode and apply at it at streamon time. */
> >       mutex_lock(&sensor->lock);
> >       sensor->mode = mode;
> > +
> > +     __v4l2_ctrl_modify_range(sensor->pixel_rate, mode->pixel_rate,
> > +                              mode->pixel_rate, 1, mode->pixel_rate);
> > +
> >       *fmt = mode->format;
> >       mutex_unlock(&sensor->lock);
> >
> > @@ -1295,6 +1306,9 @@ static int ov5647_s_ctrl(struct v4l2_ctrl *ctrl)
> >               return  ov5647_s_analogue_gain(sd, ctrl->val);
> >       case V4L2_CID_EXPOSURE:
> >               return ov5647_s_exposure(sd, ctrl->val);
> > +     case V4L2_CID_PIXEL_RATE:
> > +             /* Read-only, but we adjust it based on mode. */
>
> Looking at other drivers, I see they don't handle read only controls
> in s_ctrl cb. Also the docs (vidioc-queryctrl.rst) says that trying to set a read only control should
> return EINVAL

It was a while ago that I looked at this, but my memory says that
without a handler here then the call to __v4l2_ctrl_modify_range to
update the value failed. The ranges and default were changed, but the
current value wasn't.

Checking now, yes, without returning 0 here,  __v4l2_ctrl_modify_range
returns -22 (-EINVAL) and v4l2-ctl --list-ctrls afterwards shows
Image Processing Controls

                     pixel_rate 0x009f0902 (int64)  : min=87500000
max=87500000 step=1 default=87500000 value=81666700 flags=read-only

A failure of the framework then and needs fixing there, or is it
correct for the driver to have to implement a set hander if it needs
to update the ranges?
A quick grep implies that ov5647 is the first driver that needs to
update V4L2_CID_PIXEL_RATE based on mode. I'll check in the morning if
things like V4L2_CID_HBLANK behave the same - it may be a control type
issue with 64 bit values.


Interesting that the docs say EINVAL as at least one path in the
framework appears to return -EACCES [1]
Checking it:
pi@raspberrypi:~ $ v4l2-ctl --set-ctrl pixel_rate=42
VIDIOC_S_EXT_CTRLS: failed: Permission denied
Error setting controls: Permission denied
which would imply -EACCES

I am testing on a 5.4 kernel rather than media_tree.git, but there
don't appear to be any significant differences in this area between
the two.

Cheers.
  Dave

[1] https://git.linuxtv.org/media_tree.git/tree/drivers/media/v4l2-core/v4l2-ctrls.c#n4224

> Thanks,
> Dafna
>
> > +             return 0;
> >       default:
> >               dev_info(&client->dev,
> >                        "Control (id:0x%x, val:0x%x) not supported\n",
> > @@ -1313,7 +1327,7 @@ static int ov5647_init_controls(struct ov5647 *sensor)
> >   {
> >       struct i2c_client *client = v4l2_get_subdevdata(&sensor->sd);
> >
> > -     v4l2_ctrl_handler_init(&sensor->ctrls, 5);
> > +     v4l2_ctrl_handler_init(&sensor->ctrls, 6);
> >
> >       v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
> >                         V4L2_CID_AUTOGAIN, 0, 1, 1, 0);
> > @@ -1333,17 +1347,29 @@ static int ov5647_init_controls(struct ov5647 *sensor)
> >       v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
> >                         V4L2_CID_ANALOGUE_GAIN, 16, 1023, 1, 32);
> >
> > -     if (sensor->ctrls.error) {
> > -             dev_err(&client->dev, "%s Controls initialization failed (%d)\n",
> > -                     __func__, sensor->ctrls.error);
> > -             v4l2_ctrl_handler_free(&sensor->ctrls);
> > +     /* By default, PIXEL_RATE is read only, but it does change per mode */
> > +     sensor->pixel_rate = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
> > +                                            V4L2_CID_PIXEL_RATE,
> > +                                            sensor->mode->pixel_rate,
> > +                                            sensor->mode->pixel_rate, 1,
> > +                                            sensor->mode->pixel_rate);
> > +     if (!sensor->pixel_rate)
> > +             goto handler_free;
> > +     sensor->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY;
> >
> > -             return sensor->ctrls.error;
> > -     }
> > +     if (sensor->ctrls.error)
> > +             goto handler_free;
> >
> >       sensor->sd.ctrl_handler = &sensor->ctrls;
> >
> >       return 0;
> > +
> > +handler_free:
> > +     dev_err(&client->dev, "%s Controls initialization failed (%d)\n",
> > +             __func__, sensor->ctrls.error);
> > +     v4l2_ctrl_handler_free(&sensor->ctrls);
> > +
> > +     return sensor->ctrls.error;
> >   }
> >
> >   static int ov5647_parse_dt(struct ov5647 *sensor, struct device_node *np)
> >
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

  reply index

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-23 10:07 [PATCH 00/25] media: ov5647: Support RaspberryPi Camera Module v1 Jacopo Mondi
2020-06-23 10:07 ` [PATCH 01/25] dt-bindings: media: ov5647: Document pwdn-gpios Jacopo Mondi
2020-06-23 10:07 ` [PATCH 02/25] dt-bindings: media: ov5647: Document clock-noncontinuous Jacopo Mondi
2020-06-23 10:07 ` [PATCH 03/25] media: ov5647: Add support for PWDN GPIO Jacopo Mondi
2020-07-09 20:04   ` [libcamera-devel] " Dafna Hirschfeld
2020-07-14 12:45     ` Jacopo Mondi
2020-06-23 10:07 ` [PATCH 04/25] media: ov5647: Add support for non-continuous clock mode Jacopo Mondi
2020-06-23 10:07 ` [PATCH 05/25] media: ov5647: Add set_fmt and get_fmt calls Jacopo Mondi
2020-06-23 10:07 ` [PATCH 06/25] media: ov5647: Fix format initialization Jacopo Mondi
2020-06-23 10:07 ` [PATCH 07/25] media: ov5647: Fix style issues Jacopo Mondi
2020-06-23 10:07 ` [PATCH 08/25] media: ov5647: Replace license with SPDX identifier Jacopo Mondi
2020-06-23 10:07 ` [PATCH 09/25] media: ov5647: Fix return value from read/write Jacopo Mondi
2020-06-23 10:08 ` [PATCH 10/25] media: ov5647: Program mode at s_stream(1) time Jacopo Mondi
2020-06-23 16:42 ` [PATCH 11/25] media: ov5647: Implement enum_frame_size() Jacopo Mondi
2020-08-18  7:33   ` Sakari Ailus
2020-08-18  7:38     ` Sakari Ailus
2020-06-23 16:42 ` [PATCH 12/25] media: ov5647: Protect s_stream() with mutex Jacopo Mondi
2020-06-23 16:42 ` [PATCH 13/25] media: ov5647: Support gain, exposure and AWB controls Jacopo Mondi
2020-06-23 16:42 ` [PATCH 14/25] media: ov5647: Rationalize driver structure name Jacopo Mondi
2020-06-23 16:42 ` [PATCH 15/25] media: ov5647: Break out format handling Jacopo Mondi
2020-07-31 11:44   ` Sakari Ailus
2020-06-23 16:49 ` [PATCH 16/25] media: ov5647: Add support for get_selection() Jacopo Mondi
2020-07-09 19:56   ` [libcamera-devel] " Dafna Hirschfeld
2020-06-23 16:49 ` [PATCH 17/25] media: ov5647: Rename SBGGR8 VGA mode Jacopo Mondi
2020-06-23 16:49 ` [PATCH 18/25] media: ov5647: Add SGGBR10_1X10 modes Jacopo Mondi
2020-06-23 16:49 ` [PATCH 19/25] media: ov5647: Implement set_fmt pad operation Jacopo Mondi
2020-06-29 16:54   ` [libcamera-devel] " Dafna Hirschfeld
2020-06-30 10:13     ` Jacopo Mondi
2020-06-30 11:09       ` Dafna Hirschfeld
2020-06-23 16:55 ` [PATCH 20/25] media: ov5647: Program mode only if it has changed Jacopo Mondi
2020-06-29 17:48   ` Dafna Hirschfeld
2020-06-30  7:43     ` Jacopo Mondi
2020-06-30  9:32       ` Dafna Hirschfeld
2020-06-30 10:06         ` Jacopo Mondi
2020-06-30 10:56           ` Dafna Hirschfeld
2020-06-30 12:05             ` Jacopo Mondi
2020-06-30 13:01               ` Dafna Hirschfeld
2020-06-30 14:53                 ` [libcamera-devel] " Dave Stevenson
2020-06-30 15:11                   ` Dafna Hirschfeld
2020-07-01  7:25                 ` Laurent Pinchart
2020-07-03 12:21                   ` Jacopo Mondi
2020-07-03 16:33                     ` Laurent Pinchart
2020-06-23 16:55 ` [PATCH 21/25] media: ov5647: Set V4L2_SUBDEV_FL_HAS_EVENTS flag Jacopo Mondi
2020-06-23 16:55 ` [PATCH 22/25] media: ov5647: Support V4L2_CID_PIXEL_RATE Jacopo Mondi
2020-06-29 17:01   ` [libcamera-devel] " Dafna Hirschfeld
2020-06-29 21:25     ` Dave Stevenson [this message]
2020-06-30 15:13       ` Dave Stevenson
2020-07-01  7:21         ` Laurent Pinchart
2020-06-23 16:55 ` [PATCH 23/25] media: ov5647: Support V4L2_CID_HBLANK control Jacopo Mondi
2020-06-23 16:55 ` [PATCH 24/25] media: ov5647: Support V4L2_CID_VBLANK control Jacopo Mondi
2020-06-23 16:55 ` [PATCH 25/25] media: ov5647: Advertise the correct exposure range Jacopo Mondi
2020-06-29 17:33 ` [PATCH 00/25] media: ov5647: Support RaspberryPi Camera Module v1 Dafna Hirschfeld
2020-06-29 18:08   ` Dafna Hirschfeld
2020-07-10 15:59 ` Dafna Hirschfeld
2020-07-14 12:48   ` Jacopo Mondi

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=CAPY8ntBq6Lzo2qPNX6ke608SOQYVxsdjfXj2GTS6uZQMmi23JQ@mail.gmail.com \
    --to=dave.stevenson@raspberrypi.com \
    --cc=aford173@gmail.com \
    --cc=andrew_gabbasov@mentor.com \
    --cc=dafna.hirschfeld@collabora.com \
    --cc=dave.stevenson@raspberrypi.org \
    --cc=erosca@de.adit-jv.com \
    --cc=hugues.fruchet@st.com \
    --cc=hverkuil@xs4all.nl \
    --cc=jacopo@jmondi.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=libcamera-devel@lists.libcamera.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=mripard@kernel.org \
    --cc=mrodin@de.adit-jv.com \
    --cc=naush@raspberrypi.com \
    --cc=roman.kovalivskyi@globallogic.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=sudipi@jp.adit-jv.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

Linux-Media Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-media/0 linux-media/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-media linux-media/ https://lore.kernel.org/linux-media \
		linux-media@vger.kernel.org
	public-inbox-index linux-media

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-media


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git