From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Jacopo Mondi <jacopo@jmondi.org>
Cc: linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
"Jacopo Mondi" <jacopo+renesas@jmondi.org>,
"Kieran Bingham" <kieran.bingham+renesas@ideasonboard.com>,
"Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>,
"Thomas Nizan" <tnizan@witekio.com>
Subject: Re: [PATCH 3/3] media: i2c: max9286: Support manual framesync operation
Date: Fri, 17 Dec 2021 18:05:01 +0200 [thread overview]
Message-ID: <Yby1LUfI9fmuUneJ@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20211217111403.3hgb67bwuor5ysiq@uno.localdomain>
Hi Jacopo,
On Fri, Dec 17, 2021 at 12:14:03PM +0100, Jacopo Mondi wrote:
> On Fri, Dec 17, 2021 at 12:09:46AM +0200, Laurent Pinchart wrote:
> > From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >
> > The MAX9286 can generate a framesync signal to synchronize the cameras,
> > using an internal timer. Support this mode of operation and configure it
> > through the .s_frameinterval() operation. If the frame interval is not
> > 0, framesync is switched to manual mode with the specified interval,
> > otherwise automatic mode is used.
> >
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> > drivers/media/i2c/max9286.c | 66 +++++++++++++++++++++++++++++++++++--
> > 1 file changed, 63 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
> > index fa2f6a823fe6..dce1146635d2 100644
> > --- a/drivers/media/i2c/max9286.c
> > +++ b/drivers/media/i2c/max9286.c
> > @@ -174,6 +174,7 @@ struct max9286_priv {
> > struct v4l2_ctrl *pixelrate;
> >
> > struct v4l2_mbus_framefmt fmt[MAX9286_N_SINKS];
> > + struct v4l2_fract interval;
> >
> > /* Protects controls and fmt structures */
> > struct mutex mutex;
> > @@ -474,6 +475,37 @@ static int max9286_check_config_link(struct max9286_priv *priv,
> > return 0;
> > }
> >
> > +static void max9286_set_fsync_period(struct max9286_priv *priv)
> > +{
> > + u32 fsync;
> > +
> > + if (!priv->interval.numerator || !priv->interval.denominator) {
> > + /*
> > + * Special case, a null interval enables automatic FRAMESYNC
> > + * mode. FRAMESYNC is taken from the slowest link.
> > + */
> > + max9286_write(priv, 0x01, MAX9286_FSYNCMODE_INT_HIZ |
> > + MAX9286_FSYNCMETH_AUTO);
> > + return;
> > + }
> > +
> > + /*
> > + * Manual FRAMESYNC
> > + *
> > + * The FRAMESYNC generator is configured with a period expressed as a
> > + * number of PCLK periods, which runs at 75MHz.
> > + */
> > + fsync = div_u64(75000000ULL * priv->interval.numerator,
> > + priv->interval.denominator);
>
> Don't we calculate the pixel rate dynamically based on the number of
> enabled sources ?
That's a good point, this hardcodes operation for 4 cameras. I'll see
how I can fix that.
> > +
> > + max9286_write(priv, 0x01, MAX9286_FSYNCMODE_INT_OUT |
> > + MAX9286_FSYNCMETH_MANUAL);
> > +
> > + max9286_write(priv, 0x06, (fsync >> 0) & 0xff);
> > + max9286_write(priv, 0x07, (fsync >> 8) & 0xff);
> > + max9286_write(priv, 0x08, (fsync >> 16) & 0xff);
> > +}
> > +
> > /* -----------------------------------------------------------------------------
> > * V4L2 Subdev
> > */
> > @@ -656,6 +688,8 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
> > int ret;
> >
> > if (enable) {
> > + max9286_set_fsync_period(priv);
> > +
> > /*
> > * The frame sync between cameras is transmitted across the
> > * reverse channel as GPIO. We must open all channels while
> > @@ -715,6 +749,32 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
> > return 0;
> > }
> >
> > +static int max9286_g_frame_interval(struct v4l2_subdev *sd,
> > + struct v4l2_subdev_frame_interval *interval)
> > +{
> > + struct max9286_priv *priv = sd_to_max9286(sd);
> > +
> > + if (interval->pad == MAX9286_SRC_PAD)
>
> Ah!
>
> I would have expected, as this setting applies to all cameras, and
> consequentially to the output image stream frame rate, that the
> operation should have been done on the single source pad... Why is
> this not the case ?
I went back and forth between the two, I think it would work fine on the
source pad as well. I'll give it a try.
> > + return -EINVAL;
> > +
> > + interval->interval = priv->interval;
> > +
> > + return 0;
> > +}
> > +
> > +static int max9286_s_frame_interval(struct v4l2_subdev *sd,
> > + struct v4l2_subdev_frame_interval *interval)
> > +{
> > + struct max9286_priv *priv = sd_to_max9286(sd);
> > +
> > + if (interval->pad == MAX9286_SRC_PAD)
> > + return -EINVAL;
> > +
> > + priv->interval = interval->interval;
> > +
> > + return 0;
> > +}
> > +
> > static int max9286_enum_mbus_code(struct v4l2_subdev *sd,
> > struct v4l2_subdev_state *sd_state,
> > struct v4l2_subdev_mbus_code_enum *code)
> > @@ -806,6 +866,8 @@ static int max9286_get_fmt(struct v4l2_subdev *sd,
> >
> > static const struct v4l2_subdev_video_ops max9286_video_ops = {
> > .s_stream = max9286_s_stream,
> > + .g_frame_interval = max9286_g_frame_interval,
> > + .s_frame_interval = max9286_s_frame_interval,
> > };
> >
> > static const struct v4l2_subdev_pad_ops max9286_pad_ops = {
> > @@ -998,9 +1060,7 @@ static int max9286_setup(struct max9286_priv *priv)
> > MAX9286_CSILANECNT(priv->csi2_data_lanes) |
> > MAX9286_DATATYPE_YUV422_8BIT);
> >
> > - /* Automatic: FRAMESYNC taken from the slowest Link. */
> > - max9286_write(priv, 0x01, MAX9286_FSYNCMODE_INT_HIZ |
> > - MAX9286_FSYNCMETH_AUTO);
> > + max9286_set_fsync_period(priv);
> >
> > /* Enable HS/VS encoding, use D14/15 for HS/VS, invert VS. */
> > max9286_write(priv, 0x0c, MAX9286_HVEN | MAX9286_INVVS |
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2021-12-17 16:05 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-16 22:09 [PATCH 0/3] media: i2c: max9286: Small new features Laurent Pinchart
2021-12-16 22:09 ` [PATCH 1/3] dt-bindings: media: i2c: max9286: Add support for per-port supplies Laurent Pinchart
2021-12-17 10:47 ` Jacopo Mondi
2021-12-17 15:58 ` Laurent Pinchart
2021-12-17 14:18 ` Rob Herring
2021-12-17 15:59 ` Laurent Pinchart
2021-12-16 22:09 ` [PATCH 2/3] media: i2c: max9286: Add support for port regulators Laurent Pinchart
2021-12-17 11:08 ` Jacopo Mondi
2021-12-17 16:41 ` Laurent Pinchart
2021-12-17 14:00 ` Jacopo Mondi
2021-12-20 15:06 ` Thomas Nizan
2021-12-20 15:25 ` Laurent Pinchart
2021-12-16 22:09 ` [PATCH 3/3] media: i2c: max9286: Support manual framesync operation Laurent Pinchart
2021-12-17 11:14 ` Jacopo Mondi
2021-12-17 16:05 ` Laurent Pinchart [this message]
2021-12-17 17:49 ` Laurent Pinchart
2021-12-20 8:43 ` Jacopo Mondi
2021-12-20 8:45 ` Laurent Pinchart
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=Yby1LUfI9fmuUneJ@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=jacopo+renesas@jmondi.org \
--cc=jacopo@jmondi.org \
--cc=kieran.bingham+renesas@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=niklas.soderlund+renesas@ragnatech.se \
--cc=tnizan@witekio.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