How to enable multiple video devices per driver

Hi all,

I’m actually working on a driver that needs 2 video devices on a single device driver, the camera provides 2 videos with virtual channel on the same CSI port.

From previous experiences working on Jetson boards I have seen that one device driver enables 1 video device and the Device-tree follows the next structure:

/ {
    i2c@xxxx{
        device@xx {
...
            ports {
                #address-cells = <1>;
                #size-cells = <0>;
                port@0 {
                    reg = <0>;
                    dev_out: endpoint {
                        port-index = <0>;
                        bus-width = <2>;
                        vc-id = <1>;
                        remote-endpoint = <&csi_in0>;
                    };
                };
            };
        };
    };
    host1x {
        csi_base: nvcsi@15a00000 {
            #address-cells = <0x1>;
            #size-cells = <0x0>;
            num-channels = <6>;
            channel@0 {
                reg = <0x0>;
                status = "okay";
                ports {
                    #address-cells = <0x1>;
                    #size-cells = <0x0>;
                    port@0 {
                        reg = <0>;
                        status = "okay";
                        endpoint@0 {
                            status = "okay";
                            port-index = <0>;
                            bus-width = <2>;
                            remote-endpoint = <&dev_out>;
                        };
                    };
                    port@1 {
                        reg = <1>;
                        status = "okay";
                        endpoint@1 {
                            status = "okay";
                            remote-endpoint = <&vi_in0>;
                        };
                    };
                };
            };
        };
        vi_base: vi@15c10000 {
            num-channels = <6>;
            ports {
                #address-cells = <0x1>;
                #size-cells = <0x0>;
                port@0 {
                    reg = <0>;
                    status = "okay";
                    vi_in0: endpoint {
                        status = "okay";
                        port-index = <0>;
                        bus-width = <2>;
                        vc-id = <1>;
                        remote-endpoint = <&csi_out0>;
                    };
                };
            };
        };
    };
};

So I can seen in the system the following connection using media-ctl:

device-driver <-> nvcsi <-> vi (video0)

At the end of a driver’s initial configuration I have seen the call v4l2_async_register_subdev(&priv->subdev);
This enables the video node for the device driver.

So, my questions are:

  • Is it possible to use v4l2_async_register_subdev with different subdevices to enable multiple video nodes?

  • If so, could you please indicate to a sample code in kernel’s sources?

  • Since the device driver commonly enables only one video node per driver, what other changes are needed in the device tree to specify the second video node connection to nvcsi and vi nodes?

  • Is there a limitation to enable 2 video devices per driver? as example, the kernel only expects one v4l2_async_register_subdev per driver. I have seen that the file nvidia/drivers/media/platform/tegra/camera/vi/graph.c in the kernel parses the nvcsi and vi nodes and also links t subdevice in the device driver to create the video node but it isn’t clear to me if this only works with one subdevice (in one device driver) per camera.

Any clarification here will be appreciated.

Just in case, I’m working with Jetpack 4.5.1 on Xavier AGX.

Thanks.

Update:

I created 2 subdevices in the driver but only the first registered subdevice in bounded to the videoX node, only one video node created. So, it seems that the device-driver expects one subdevice to be registered pero device driver, the second or more are omitted.

I may be missing something to enable multiple video nodes according to the sub-devices created within a device driver, Any clarification here will be appreciated

It’s depend on the physical device instead of driver.
How many physical devices like i2c instances?

The hw uses 2 I2C devices but we handle both I2C devices within a single device driver, so, for the system’s point of view we set a single device node (in device tree) and one device driver but the device driver must handle 2 video streams simultaneously with different virtual channel.

If I set 2 sub-devices in the device driver (trying to enable 2 videoX nodes) and use the call v4l2_async_register_subdev to register the subdevices, only one sudbevice is bounded (the first registered device).

  • Is it possible to handle 2 V4L2 subdevices within a single device-driver in the current support?

From previous experiences I have seen similar cases - 2 I2C devices in single HW- then each I2C device uses a different (and separate) device driver with a single V4L2 sub-device but the current case requires 2 V4L2 sub-devices in a single device driver.

Checking the sources in the kernel, the camera drivers as example. use a single V4L2 sub-device per device driver, so i’m interested in possible limitations in enabling multiple V4L2 subdevices within a single device driver.

If you have 2 i2c instance you can register two video with the same kernel driver.
You should be able saw the probe message from the driver with different i2c address like e3333 have 6 video nodes.

[    3.605276] ov5693 30-0036: probing v4l2 sensor.
[    3.631031] ov5693 30-0036: tegracam sensor driver:ov5693_v2.0.6
[    5.002989] tegra-vi4 15700000.vi: subdev ov5693 30-0036 bound
[    5.011660] ov5693 31-0036: probing v4l2 sensor.
[    5.012311] ov5693 31-0036: tegracam sensor driver:ov5693_v2.0.6
[    6.101725] tegra-vi4 15700000.vi: subdev ov5693 31-0036 bound
[    6.102474] ov5693 32-0036: probing v4l2 sensor.
[    6.103399] ov5693 32-0036: tegracam sensor driver:ov5693_v2.0.6
[    7.105178] tegra-vi4 15700000.vi: subdev ov5693 32-0036 bound
[    7.105927] ov5693 33-0036: probing v4l2 sensor.
[    7.109123] ov5693 33-0036: tegracam sensor driver:ov5693_v2.0.6
[    7.977620] tegra-vi4 15700000.vi: subdev ov5693 33-0036 bound
[    7.979359] ov5693 34-0036: probing v4l2 sensor.
[    7.980337] ov5693 34-0036: tegracam sensor driver:ov5693_v2.0.6
[    8.926651] tegra-vi4 15700000.vi: subdev ov5693 34-0036 bound
[    8.931777] ov5693 35-0036: probing v4l2 sensor.
[    8.946329] ov5693 35-0036: tegracam sensor driver:ov5693_v2.0.6
[   10.022412] tegra-vi4 15700000.vi: subdev ov5693 35-0036 bound

Hi @ShaneCCC , thanks for the reply.

I understand that case, It has a single V4L2 sub-device in a single device driver, then using multiple instances of the device driver we can get multiple videoX nodes.

Using the same log as example, I will explain what I’m looking to implement:

ov5693 30-0036: probing v4l2 sensor.
ov5693 30-0036: tegracam sensor driver:ov5693_v2.0.6
tegra-vi4 15700000.vi: subdev ov5693 30-0036 bound
tegra-vi4 15700000.vi: subdev other_cam_in_hw bound
ov5693 31-0036: probing v4l2 sensor.
ov5693 31-0036: tegracam sensor driver:ov5693_v2.0.6
tegra-vi4 15700000.vi: subdev ov5693 31-0036 bound
tegra-vi4 15700000.vi: subdev other_cam_in_hw bound
ov5693 32-0036: probing v4l2 sensor.
ov5693 32-0036: tegracam sensor driver:ov5693_v2.0.6
tegra-vi4 15700000.vi: subdev ov5693 32-0036 bound
tegra-vi4 15700000.vi: subdev other_cam_in_hw bound
ov5693 33-0036: probing v4l2 sensor.
ov5693 33-0036: tegracam sensor driver:ov5693_v2.0.6
tegra-vi4 15700000.vi: subdev ov5693 33-0036 bound
tegra-vi4 15700000.vi: subdev other_cam_in_hw bound
ov5693 34-0036: probing v4l2 sensor.
ov5693 34-0036: tegracam sensor driver:ov5693_v2.0.6
tegra-vi4 15700000.vi: subdev ov5693 34-0036 bound
tegra-vi4 15700000.vi: subdev other_cam_in_hw bound
ov5693 35-0036: probing v4l2 sensor.
ov5693 35-0036: tegracam sensor driver:ov5693_v2.0.6
tegra-vi4 15700000.vi: subdev ov5693 35-0036 bound
tegra-vi4 15700000.vi: subdev other_cam_in_hw bound

So, I’m looking for 2 subdev xxxxx bound messages per probing V4L2 sensor.

  • Is this possible?

Do you mean one slave address register twice subdev? Suppose no support by v4l framework.

Correct, that’s the case I’m looking for.

Using 2 V4L2 sub-devices and 2 register calls withing a single probing function, the second one is not being registered.

So the missing support is on the V4L2 framework side, right?

Suppose yes, maybe the name of string duplicate case the failed.