linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@iki.fi>
To: Francesco Dolcini <francesco@dolcini.it>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
	Aishwarya Kothari <aishwaryakothari75@gmail.com>,
	linux-media@vger.kernel.org, francesco.dolcini@toradex.com,
	marcel.ziswiler@toradex.com
Subject: Re: Issue with ov5640 camera sensor on apalis imx6
Date: Thu, 12 Jan 2023 15:16:52 +0200	[thread overview]
Message-ID: <Y8AIRPd4RFYmssal@valkosipuli.retiisi.eu> (raw)
In-Reply-To: <Y7/sVZNTf2sGHwbo@francesco-nb.int.toradex.com>

Hi Francesco,

On Thu, Jan 12, 2023 at 12:17:41PM +0100, Francesco Dolcini wrote:
> On Thu, Jan 12, 2023 at 12:12:04PM +0200, Laurent Pinchart wrote:
> > On Wed, Jan 11, 2023 at 12:50:38PM +0100, Jacopo Mondi wrote:
> > > On Thu, Jan 05, 2023 at 03:35:42PM +0100, Aishwarya Kothari wrote:
> > > > Thanks
> > > > Reverting the commit 1f391df4 (media: v4l2-async: Use endpoints in
> > > > __v4l2_async_nf_add_fwnode_remote()) and setting the format as below works
> > > > fine when tested on v6.0 and v6.1
> > > > root@apalis-imx6-10774951:~# cat ov5640.sh
> > > > media-ctl -l "'ov5640 1-003c':0 -> 'imx6-mipi-csi2':0[1]"
> > > > media-ctl -l "'imx6-mipi-csi2':2 -> 'ipu1_csi1':0[1]"
> > > > media-ctl -l "'ipu1_csi1':2 -> 'ipu1_csi1 capture':0[1]"
> > > > # Configure pads
> > > > media-ctl -V "'ov5640 1-003c':0 [fmt:UYVY8_1X16/1920x1080 field:none]"
> > > > media-ctl -V "'imx6-mipi-csi2':2 [fmt:UYVY8_1X16/1920x1080 field:none]"
> > > > media-ctl -V "'ipu1_csi1':2 [fmt:UYVY8_1X16/1920x1080 field:none]"
> > > 
> > > I reproduced the issue by booting the most recent media tree master on
> > > an i.MX6Q board with an ov5640 sensor connected.
> > > 
> > > Looking at the list of pending async subdevices at the end of the boot
> > > sequence (thanks Laurent for letting me know such sysfs attribute
> > > existed :)
> > > 
> > > # cat /sys/kernel/debug/v4l2-async/pending_async_subdevices
> > > ipu2_csi1_mux:
> > >  [fwnode] dev=21dc000.mipi, node=/soc/bus@2100000/mipi@21dc000/port@4/endpoint
> > > ipu1_csi0_mux:
> > >  [fwnode] dev=21dc000.mipi, node=/soc/bus@2100000/mipi@21dc000/port@1/endpoint
> > > imx6-mipi-csi2:
> > > ipu2_csi1:
> > > ipu2_csi0:
> > > ipu1_csi1:
> > >  [fwnode] dev=21dc000.mipi, node=/soc/bus@2100000/mipi@21dc000/port@2/endpoint
> > > ipu1_csi0:
> > > imx-media:
> > > ov5640 2-003c:
> > > 
> > > it is clear that there are unsatisfied dependencies on subdevices that
> > > should be registered by the mipi-csi2 driver.
> > > 
> > > The mipi-csi2 DTS layout is the following
> > > https://elixir.bootlin.com/linux/latest/source/arch/arm/boot/dts/imx6q.dtsi#L486
> > > with 1 source port connected to the sensor and 4 sink ports with an
> > > endpoint each connected to the 2 muxes and the 2 IPU[1,2] CSI[0,1] (see
> > > "Figure 19-1. CSI2IPU gasket connectivity" of the IMX6DQRM TRM).
> > > 
> > > The CSI-2 driver registers one subdevice only
> > > https://elixir.bootlin.com/linux/latest/source/drivers/staging/media/imx/imx6-mipi-csi2.c#L629
> > > and with the logic implemented in v4l2_async for heterogeneous
> > > matching
> > > https://elixir.bootlin.com/linux/latest/source/drivers/media/v4l2-core/v4l2-async.c#L79
> > > the first driver that probes and that searches from an endpoint in
> > > the mipi-csi2 device node gets satisfied while the other 3 will be
> > > left pending. That's why you see "ipu2_csi0:" above having no pending
> > > subdevs, while "ipu1_csi1:", "ipu1_csi0_mux:" and "ipu2_csi1_mux:"
> > > have pending subdevices.
> > > 
> > > Before commit 1f391df4 (media: v4l2-async: Use endpoints in
> > > __v4l2_async_nf_add_fwnode_remote())" all the notifiers in ipu1_csi1,
> > > ipu1_csi0_mux, ipu2_csi0 and ipu2_csi1_mux pointed to the same device
> > > node "imx6-mipi-csi2". In order to register multiple notifiers with
> > > an asd that point the same device node you can see that both the
> > > imx-media-csi and video-mux implement a workaround in the form of:
> > > 
> > > 		asd = v4l2_async_nf_add_fwnode_remote(&vmux->notifier, ep,
> > > 						      struct v4l2_async_subdev);
> > > 
> > > 		fwnode_handle_put(ep);
> > > 
> > > 		if (IS_ERR(asd)) {
> > > 			ret = PTR_ERR(asd);
> > > 			/* OK if asd already exists */
> > > 			if (ret != -EEXIST)
> > > 				return ret;
> > > 		}
> > > 
> > > https://elixir.bootlin.com/linux/latest/source/drivers/staging/media/imx/imx-media-csi.c#L1925
> > > https://elixir.bootlin.com/linux/latest/source/drivers/media/platform/video-mux.c#L382
> > > 
> > > as registering multiple asd with on the same fwnode fails when adding
> > > the asd at:
> > > https://elixir.bootlin.com/linux/latest/source/drivers/media/v4l2-core/v4l2-async.c#L459
> > > (thanks again Laurent for spotting this 'workaround')
> > > 
> > > This can also be seen in the kernel logs when running with 1f391df4
> > > reverted and debug enabled on v4l2-async:
> > > 
> > > [    3.735368] (NULL device *): subdev descriptor already listed in this or other notifiers
> > > [    4.242167] (NULL device *): subdev descriptor already listed in this or other notifiers
> > > [    4.245655] (NULL device *): subdev descriptor already listed in this or other notifiers
> > > 
> > > The end result is that a single notifier that points to the mipi_csi2
> > > device node is registered instead of 4 notifiers as it happens when
> > > matching on endpoints. When the single notifier binds it registers
> > > links for all its sink pads (see the _bound callbacks in imx-media-csi
> > > and video-mux that call v4l2_create_fwnode_links() and
> > > v4l2_create_fwnode_links_to_pad() respectively) and you have a working
> > > media-device. Fragile at best as a design, but that's what we'll have
> > > to live with I'm afraid.
> > > 
> > > Now, how to fix this. I tried to think of a way to let the remote
> > > subdev decide if it has to be matched on endpoints or device node so
> > > that the decision is up to the mipi-csi2 driver. The alternative would
> > > be to manually add to the notifier an asd that points to the device
> > > node instead of using v4l2_async_nf_add_fwnode_remote(). This would be
> > > fine for the imx-mipi-csi component, as it is always paired the
> > > mipi-csi2 device so it can safely assume the remote has to be matched
> > > on device node.  However the video-mux would have to be modified in
> > > the same way, and as it is a generic component we cannot make any
> > > assumption on the remote there...
> > > 
> > > Any ideas ?
> > 
> > Not any easy one :-S
> 
> Wouldn't be the case that we should revert that change till we have a
> proper solution in place given that is not going to be an easy fix?
> In the end no matter the reason it was working before, this is just a
> regression.

V4L2 async has never supported

1. multiple links from an async sub-device or

2. cases where a sub-notifier is a child of more than one parent notifier.

Device dependencies that exist in this hardware would seem to require
adding support for these in V4L2 async.

-- 
Kind regards,

Sakari Ailus

      parent reply	other threads:[~2023-01-12 13:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-07 11:14 Issue with ov5640 camera sensor on apalis imx6 Aishwarya Kothari
2022-12-07 18:44 ` Laurent Pinchart
2022-12-07 19:05   ` Jacopo Mondi
2022-12-22 13:19     ` Aishwarya Kothari
2022-12-22 13:28       ` Jacopo Mondi
2023-01-05 14:35         ` Aishwarya Kothari
2023-01-08  7:10           ` Laurent Pinchart
2023-01-11 11:50           ` Jacopo Mondi
2023-01-12 10:12             ` Laurent Pinchart
2023-01-12 11:17               ` Francesco Dolcini
2023-01-12 11:53                 ` Laurent Pinchart
2023-01-12 13:16                 ` Sakari Ailus [this message]

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=Y8AIRPd4RFYmssal@valkosipuli.retiisi.eu \
    --to=sakari.ailus@iki.fi \
    --cc=aishwaryakothari75@gmail.com \
    --cc=francesco.dolcini@toradex.com \
    --cc=francesco@dolcini.it \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=marcel.ziswiler@toradex.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).