Collecting knowlege about CSI cameras and the device tree

I’m just writing my understanding of how it works and maybe somebody can tell me if I’m wrong somewhere and post some expansions of it.

The Orin NX has four CSI interfaces that are exposed on the edge connector, named CSI_0-CSI_3. They correspond to the Verilog names CSI_A-CSI_D. (CSI_E to H exist, probably because the AGX uses the same silicon). Each of those has two lanes, D0 and D1. Those can be configured into four (15-pin) 2 lane socket, or two (22-pin) 4-lane socket (A+B and C+D).

The DevKit connects CSI_B on socket CSI0 (2-lanes) and CSI_C+CSI_D on socket CSI1(4-lanes).

For some reason there is a pin crossover in CSI_0_D1 and CSI_1_D0, so you have to do the lane polarity configuration, unless your carrier board is fixing that. Depending on that and what CSI port you use you will have to set lane polarity. See Design Guide Figure 10-1.

 Based on the camera connector pin.
							* CSIx_D0 | CSIx_D1 | CSI(X+1)_D0 | CSI(X+1)CSIx_D1
							*    LSB  |   BIT1  |     BIT2    |      MSB
							* if there is a polarity swap on any lane, the bit corrsponding
							* to the lane should be set
							* e.g. polarity swap on CSIx_D0 only -> lane_polarity = "1"; 0001
							* e.g. polarity swap on CSIx_D1 and CSI(X+1)_D0 -> lane_polarity = "6"; 0110

So in a CAM that is using only CSI_0 you need to set bit 1 aka polarity=2, in one that us using only CSI_1 you need to set bit 0 aka polarity=1 and in one that uses both you need bits 1 and 2, so polarity=6, or your carrier board has fixed that for you, look at the layout you are using. Apparently it should be set to 6 for all cameras that use CSI_A and/or CSI_B.

In the device tree entry of the camera you have to specify in the mode node what serial interface you are using, serial_a to serial_d. Those correspond to CSI_A to CSI_D.

What serial you have to use for a two lane camera on a 4 lane port depends on how the sockets are connected to the camera.

The device tree for the camera also needs a ports node with an endpoint, the data out for the camera. In this endpoint you set the number of lanes your camera needs in the bus-width property, a port index that corresponds to the used CSI port and a remote-endpoint that points to the nvcsi input node.

If you go by this graphic the relation ship between them is quite clear, at least the BSP uses serial_b->port-index =1 and serial_c->port-index=2.

Again, all this means what serial and port-index is used depends on your specific hardware, maybe your board use two lane sockets, they could be connected to any of the CSI lanes.

The last property of this endpoint is a reference to the CSI input endpoint in the nvcsi component.

The nvcsi node has multiple channels. I’m not sure if the index of the channel (channel@0, channel@1) does anything besides make them unique). Each channel node has two ports, one input and one output. Each of them has an endpoint node. The input node must have the same port-index and bus-width as the output endpoint of the camera and remote-endpoint that points to the output node of the camera. The output port has an endpoint node with a remote-endpoint that points to the corresponding node in tegra-capture-vi.

In tegra-capture-vi you have to specify the number of channels you want to capture. It has a ports node with a number of port sub-nodes. In each of them resides an endpoint that again has port-index, bus-width like before and a remote-endpoint that points to the output node of nvcsi.

The last part that has to be configured is the tegra-camera-platform. It has modules, every module representing a camera. It has a badge, position and orientation property, that have to be set according to this (the documentation specifies cases for 2, 3 and 6 cameras, the BSP device tree with 4 cameras uses bottomleft, bottomright, centerleft, centerright and orientation=1 for all of them) and a drivernode(s). drivernode0 corresponds with the camera. Here you set pcl_id = “v4l2_sensor” and sysfs-device-tree to wherever your camera is in /sys/firmware/devicetree/base/, usually something like /sys/firmware/devicetree/base/bus@0/i2c@3180000/rbpcv2_imx219_a@10, maybe with an mux in between the I2c and the camera. You can also have other drivernodes that reference other components, like a lens.

hello t.mehr,

let me have some reply as below, I hope these address all your questions.

you’ll need to configure lane polarity (i.e. lane_polarity) since CSI0_D1 and CSI1_D0 P/N will always been swizzled for P/N.

for the Jetson Orin NX developer kit.
you may refer to Jetson Orin Nano Developer Kit Carrier Board Reference Design Files,
that’s due to carrier board design,
J20/CAM0 uses CSI1_CLK, only a x2 camera interface is supported.
only J21/CAM1 which uses CSI2_CLK can support both x2 or x4 camera interfaces.
please check [P3768_A04_Concept_schematics.pdf] for page-18 [CSI CAM CONNECTORS] section for more details.

you may see-also Topic 69753 for the NVCSI/VI mappings,
please aware that the last two bricks, each CSI-E/F and CSI-G/H share a single PixelParser.
but.. Orin Nano/NX modules doesn’t have last two CSI bricks anyways.

please refer to developer guide, Camera Modules and the Device Tree.
badge property to have unique names for loading sensor specific ISP settings.
Argus checks position property to assign camera index.

Thank you for correcting and confirming my suspicions about the DevKit. I corrected my post in the part about the DevKit.

Just to confirm about lane polarity, I posted the comment from your device trees, but you set lane_polarity=6 for the 2-channel imx219 on CSI-B. Shouldn’t that switch polarities on B and C?
Or do I have to set it to lane_polarity=6 for any CAM that is using CSI_A or CSI_B?

hello t.mehr,

lane_polarity = "6"; 0110 to have polarity swap both on CSI0_D1 and CSI1_D0.

So, I would have to set lane_polarity = "6"; 0110 even if the camera is using 2-lanes on CSI_B? According to the comment in the DT shouldn’t that influence the lanes of CSI_C?

Based on the camera connector pin.
							* CSIx_D0 | CSIx_D1 | CSI(X+1)_D0 | CSI(X+1)CSIx_D1
							*    LSB  |   BIT1  |     BIT2    |      MSB
							* if there is a polarity swap on any lane, the bit corrsponding
							* to the lane should be set
							* e.g. polarity swap on CSIx_D0 only -> lane_polarity = "1"; 0001
							* e.g. polarity swap on CSIx_D1 and CSI(X+1)_D0 -> lane_polarity = "6"; 0110

If I had two cameras connected to CSI_A and CSI_B, I would expect that I set it to 2 for the camera connected to CSI_A and 4 for the camera on CSI_B, and 6 for one that is using CSI_A and CSI_B in 4-channel mode.

Do I set it to 6 with both cameras?

hello t.mehr,

that’s okay, we’ve the same configuration on reference imx219 camera driver
for instance, $public_sources/kernel_src/hardware/nvidia/t23x/nv-public/overlay/tegra234-camera-rbpcv2-imx219.dtsi

no, you should set lane_polarity = "6"; two 2-lane cameras on CSI-A and CSI-B that may stream simultaneously.
although using lane_polarity = "2"; for CSI-A and lane_polarity = "4"; for CSI-B could work individually, simultaneous startup might present mismatching configurations or report failures with RCE firmware.