V4L2 and MIPI CSI2 Virtual Channels: How to separate them into streams?

142 Views Asked by At

For avoidance of doubt, this is question about programming - I'm writing a device driver for a device that's going to stream out on different virtual channels.

What I figured so far is that my receiver device should have a source media pad for each Virtual Channel of the MIPI CSI2 bus, but for example on AM625 there are two drivers:

  • ticsi2rx
  • csi-bridge

each having having 4 source pads with no indication anywhere how they map into Virtual Channels.

During my painful journey of digging for any useful information on the topic, I found people try to use TP2855 with i.MX8QM and one of Jetsons. This device can stream video captured from analog source into separate virtual channels. The driver code for this chip is available on Rockchip's fork of the Linux Kernel:

Digging in this code I found it refers to set up use of virtual channels, by for example using V4L2_MBUS_CSI2_CHANNEL_0 constant... but further search shows, this has been removed from the Linux Kernel:

https://patchwork.kernel.org/project/linux-media/patch/[email protected]/#24738396

What indicates the support for CSI2 Virtual Channels has been removed from the Linux Kernel.

If that's so, how to add support for CSI2 Virtual Channels into own camera driver aiming at more recent kernels?

Am I right thinking that apart i.MX8 chips support for virtual channels is non-existent in the Kernel code?

1

There are 1 best solutions below

1
Cozzmy Cosmin On

The Linux kernel never actually had proper support for virtual channels. What it had were a few flags that described the bus config for CSI2, used only by that Atmel CSI driver to check what VC the connected camera was streaming on.

The driver for these IMX chips hardcode the VC to 0, even if they support VC filtering.

https://github.com/torvalds/linux/blob/master/drivers/media/platform/nxp/imx8mq-mipi-csi2.c#L261 https://github.com/torvalds/linux/blob/master/drivers/media/platform/nxp/imx8-isi/imx8-isi-hw.c#L345

The Jetsons have better support for VC, basically allowing you to receive data for each VC in a separate video device. But the Jetson CSIs aren't in mainline.

Recently, experimental support for multiple streams per pad was added to the Linux kernel, along with v4l-utils (media-ctl, v4l2-ctl), and with support for routing these streams between source and sinks within a V4L2 subdev.

The pieces are almost in place for adding proper support for virtual channels.

I have started implementing support for these for my company.

https://github.com/Demon000/linux/commits/rfc-vc/

https://github.com/Demon000/v4l-utils/commits/master/

I've yet to send an RFC to mainline for these, but you could cherry-pick them to your kernel fork just to get things going until mainline support is added.

Edit: I've sent an RFC to mainline.

https://patchwork.kernel.org/project/linux-media/patch/[email protected]/