From: "Niklas Söderlund" <niklas.soderlund@ragnatech.se>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Andrey Konovalov <andrey.konovalov@linaro.org>,
linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com,
mchehab@kernel.org, bparrot@ti.com, mickael.guene@st.com
Subject: Re: [RFC PATCH 1/4] media: rcar-vin: use v4l2_get_link_freq() to calculate phypll frequency
Date: Tue, 23 Mar 2021 14:57:05 +0100 [thread overview]
Message-ID: <YFnzsVjSoUsOtY/O@oden.dyn.berto.se> (raw)
In-Reply-To: <20210323131041.GB3@paasikivi.fi.intel.com>
Hi Sakari,
On 2021-03-23 15:10:41 +0200, Sakari Ailus wrote:
> Hi Niklas,
>
> On Mon, Mar 08, 2021 at 02:46:52PM +0100, Niklas Söderlund wrote:
> > Hi Andrey,
> >
> > Thanks for your patch.
> >
> > On 2021-03-03 21:08:14 +0300, Andrey Konovalov wrote:
> > > To get the link frequency value, or to calculate a parameter depending on
> > > it the receiver driver should use V4L2_CID_LINK_FREQ. If V4L2_CID_LINK_FREQ
> > > control is not implemented in the remote subdevice, the link frequency
> > > can be calculated from V4L2_CID_PIXEL_RATE control value. But the latter
> > > may not give the correct link frequency, and should only be used as the
> > > last resort. v4l2_get_link_freq() does exactly that, so use it instead
> > > of reading V4L2_CID_PIXEL_RATE directly.
> >
> > I like the direction this patch is taking, but I'm a bit concerned about
> > that V4L2_CID_LINK_FREQ is not able to replace V4L2_CID_PIXEL_RATE as it
> > is designed today. Maybe my concern is unfounded and only reflects my
> > own misunderstanding of the API.
> >
> > When I wrote this code I tried to first do it using V4L2_CID_LINK_FREQ
> > but I found no way to be able to express the wide rang of values needed
> > for my use-case given that V4L2_CID_LINK_FREQ is a menu control. I had
>
> I think we could make it alternatively a 64-bit integer control if that
> helps. The helper needs to be adjusted accordingly.
That would solve my concern.
>
> > to use V4L2_CID_PIXEL_RATE as it allowed me to at runtime calculate and
> > report the link speed based on input formats. The Use-cases I need to
> > address are where CSI-2 transmitter themself are a bridge in the video
> > pipeline, for example
>
> Is the actual bus frequency changed based on this?
Yes
>
> Depending on the system where this chip is being used, only certain
> frequencies may be allowed on that bus. It would be most straightforward to
> use only those, but on the other hand, if any frequency can be used and
> that is certain, then I have no objections to allowing that either. We
> simply would make the link-frequencies property optional.
The transmitter is a ADV748x and depending on the video input source
(HDMI or CVBS) the output frequency changes. Failing to negotiate this
of course results in the CSI-2 receiver never detecting LP-11.
>
> >
> > * Case 1 - HDMI video source
> >
> > HDMI source -> ADV748x (HDMI-to-CSI-2) ->[CSI-2 bus]-> R-Car CSI-2 receiver
> >
> > The R-Car CSI-2 receiver needs to know the CSI-2 link frequency and
> > queries the ADV748x using V4L2_CID_PIXEL_RATE. The ADV748x reports the
> > pixel rate based on the HDMI format detected on its sink pad.
> >
> > This could be done using V4L2_CID_LINK_FREQ, but as it's a menu control
> > it becomes rather tricky to populate it with all possible values, but I
> > guess it could be doable?
> >
> > * Case 2 - Multiple video streams over a CSI-2 bus (GMSL)
> >
> > Camera 1 -|
> > Camera 2 -|
> > Camera 3 -|---> MAX9286 (GMSL-to CSI-2) ->[CSI-2 bus]-> R-Car CSI-2 receiver
> > Camera 4 -|
> >
> > The MAX9286 has 4 sink pads each connected to an independent camera and
> > a single CSI-2 source pad. When streaming starts the MAX9286 computes
> > the total CSI-2 link speed as V4L2_CID_PIXEL_RATE based on the format on
> > each of it's 4 sink pads.
> >
> > As in case 1 this could be reported by V4L2_CID_LINK_FREQ but I don't
> > see it as feasible to populate the menu control with all possible
> > frequencies before hand.
> >
> > Hopefully this is all easily solvable and I have only misunderstood how
> > menu controls work. If not I think this needs to be considered as part
> > of this series as otherwise it could leave the CSI-2 bridge drivers
> > without a path forward.
> >
> > >
> > > Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
> >
> > I tested this and it works as expected. Also as expected it prints lots
> > of warnings about the usage of V4L2_CID_PIXEL_RATE :-) Once I understand
> > how I can fix the CSI-2 transmitters used as bridges in the R-Car boards
> > I will be happy to add my tag to this series as well as fix the bridge
> > drivers.
> >
> > > ---
> > > drivers/media/platform/rcar-vin/rcar-csi2.c | 18 +++++++-----------
> > > 1 file changed, 7 insertions(+), 11 deletions(-)
> > >
> > > diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> > > index e06cd512aba2..eec8f9dd9060 100644
> > > --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> > > +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> > > @@ -455,29 +455,25 @@ static int rcsi2_calc_mbps(struct rcar_csi2 *priv, unsigned int bpp,
> > > unsigned int lanes)
> > > {
> > > struct v4l2_subdev *source;
> > > - struct v4l2_ctrl *ctrl;
> > > - u64 mbps;
> > > + s64 mbps;
> > >
> > > if (!priv->remote)
> > > return -ENODEV;
> > >
> > > source = priv->remote;
> > >
> > > - /* Read the pixel rate control from remote. */
> > > - ctrl = v4l2_ctrl_find(source->ctrl_handler, V4L2_CID_PIXEL_RATE);
> > > - if (!ctrl) {
> > > - dev_err(priv->dev, "no pixel rate control in subdev %s\n",
> > > + /* Read the link frequency from the remote subdev. */
> > > + mbps = v4l2_get_link_freq(source->ctrl_handler, bpp, 2 * lanes);
> > > + if (mbps < 0) {
> > > + dev_err(priv->dev, "failed to get link rate from subdev %s\n",
> > > source->name);
> > > - return -EINVAL;
> > > + return mbps;
> > > }
> > > -
> > > /*
> > > * Calculate the phypll in mbps.
> > > - * link_freq = (pixel_rate * bits_per_sample) / (2 * nr_of_lanes)
> > > * bps = link_freq * 2
> > > */
> > > - mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * bpp;
> > > - do_div(mbps, lanes * 1000000);
> > > + do_div(mbps, 1000000 / 2);
> > >
> > > return mbps;
> > > }
> > > --
> > > 2.17.1
> > >
>
> --
> Kind regards,
>
> Sakari Ailus
--
Regards,
Niklas Söderlund
next prev parent reply other threads:[~2021-03-23 13:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-03 18:08 [RFC PATCH 0/4] use v4l2_get_link_freq() in CSI receiver drivers Andrey Konovalov
2021-03-03 18:08 ` [RFC PATCH 1/4] media: rcar-vin: use v4l2_get_link_freq() to calculate phypll frequency Andrey Konovalov
2021-03-08 13:46 ` Niklas Söderlund
2021-03-23 13:10 ` Sakari Ailus
2021-03-23 13:57 ` Niklas Söderlund [this message]
2021-03-23 21:24 ` Laurent Pinchart
2021-03-25 9:39 ` Niklas Söderlund
2021-03-30 17:53 ` Andrey Konovalov
2021-03-03 18:08 ` [RFC PATCH 2/4] media: ti-vpe: cal: use v4l2_get_link_freq() for DPHY timing configuration Andrey Konovalov
2021-03-03 18:08 ` [RFC PATCH 3/4] media: st-mipid02: use v4l2_get_link_freq() instead of the custom code Andrey Konovalov
2021-03-03 18:08 ` [RFC PATCH 4/4] staging: media: omap4iss: use v4l2_get_link_freq() to get the external rate Andrey Konovalov
2021-03-05 15:41 ` Sakari Ailus
2021-03-09 11:24 ` Andrey Konovalov
2021-03-23 12:54 ` Sakari Ailus
2021-03-05 15:42 ` [RFC PATCH 0/4] use v4l2_get_link_freq() in CSI receiver drivers Sakari Ailus
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=YFnzsVjSoUsOtY/O@oden.dyn.berto.se \
--to=niklas.soderlund@ragnatech.se \
--cc=andrey.konovalov@linaro.org \
--cc=bparrot@ti.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=mickael.guene@st.com \
--cc=sakari.ailus@linux.intel.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;
as well as URLs for NNTP newsgroup(s).