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. Francesco