Raspberry Pi camera and Jetson TX2

Hi!
I am working on connecting Raspberry Pi Camera to Jetson TX2 through Auvidea J106 board using CSI E port.

Following Sensor Software Driver Programming Guide I created device tree entry for this camera:

#include "dt-bindings/clock/tegra186-clock.h"
#include <dt-bindings/pinctrl/pinctrl-tegra.h>
#include <dt-bindings/gpio/tegra186-gpio.h>

#define CAM_RST_L TEGRA_MAIN_GPIO(R, 5)

/ {
  gpio@2200000 {
    camera-control-output-high {
      status = "okay";
      gpio-hog;
      output-high;
      gpios = < CAM_RST_L 0>;
      label = "cam-rst";
    };
  };
};

/ {
  host1x {
    vi@15700000 {
      num-channels = <1>;
      ports {
        #address-cells = <1>;
        #size-cells = <0>;
        port@0 {
          status = "okay";
          reg = <0>;
          vi_in4: endpoint {
            status = "okay";
            port-index = <4>;
            bus-width = <2>;
            remote-endpoint = <&imx219_csi_out4>;
          };
        };
      };
    };
  };
};

/ {
  host1x {
    nvcsi@150c0000 {
      status = "okey";
      num-channels = <1>;
      #address-cells = <1>;
      #size-cells = <0>;
      channel@0 {
        reg = <0>;
        status = "okay";
        ports {
          #address-cells = <1>;
          #size-cells = <0>;
          port@0 {
            status = "okay";
            reg = <0>;
            imx219_csi_in4: endpoint@0 {
              status = "okay";
              port-index = <4>;
              bus-width = <2>;
              remote-endpoint = <&imx219_phy_out4>;
            };
          };
          port@1 {
            status = "okay";
            reg = <1>;
            imx219_csi_out4: endpoint@1 {
              status = "okay";
              remote-endpoint = <&vi_in4>;
            };
          };
        };
      };
    };
  };
};

/ {
  i2c@c250000 {
    imx219_e@10 {
      #address-cells = <1>;
      #size-cells = <0>;

      reset-gpios = <&tegra_main_gpio CAM_RST_L GPIO_ACTIVE_LOW>;

      devnode = "video4";
      compatible = "nvidia,imx219";
      reg = <0x10>;

      physical_w = "3.680";
      physical_h = "2.760";

      sensor_model ="imx219";
      use_sensor_mode_id = "true";

      mode0 { // IMX219_MODE_1920X1080
        mclk_khz = "24000";
				num_lanes = "2";
				tegra_sinterface = "serial_e";
				phy_mode = "DPHY";
				discontinuous_clk = "yes";
				dpcm_enable = "false";
				cil_settletime = "0";

				active_w = "1920";
				active_h = "1080";
				pixel_t = "bayer_rggb";
				readout_orientation = "90";
				line_length = "3448";
				inherent_gain = "1";
				mclk_multiplier = "9.33";
				pix_clk_hz = "182400000";

				gain_factor = "16";
				framerate_factor = "1000000";
				exposure_factor = "1000000";
				min_gain_val = "16"; /* 1.00x */
				max_gain_val = "170"; /* 10.66x */
				step_gain_val = "1";
				default_gain = "16"; /* 1.00x */
				min_hdr_ratio = "1";
				max_hdr_ratio = "1";
				min_framerate = "2000000"; /* 2.0 fps */
				max_framerate = "30000000"; /* 30.0 fps */
				step_framerate = "1";
				default_framerate = "30000000"; /* 30.0 fps */
				min_exp_time = "13"; /* us */
				max_exp_time = "683709"; /* us */
				step_exp_time = "1";
				default_exp_time = "2495"; /* us */

				embedded_metadata_height = "2";
      };

      ports {
        #address-cells = <1>;
        #size-cells = <0>;

        port@0 {
          reg = <0>;
          imx219_phy_out4: endpoint {
            port-index = <4>;
            bus-width = <2>;
            remote-endpoint = <&imx219_csi_in4>;
          };
        };
      };
    };
  };
};

/* camera control gpio definitions */
/ {
  tegra-camera-platform {
    compatible = "nvidia, tegra-camera-platform";
    num_csi_lanes = <2>;
    max_lane_speed = <1500000>;
    max_pixel_rate = <240000>;
    min_bits_per_pixel = <10>;
    vi_peak_byte_per_pixel = <2>;
    vi_bw_margin_pct = <25>;
    isp_peak_byte_per_pixel = <5>;
    isp_bw_margin_pct = <25>;

    modules {
      cam_module0: module0 {
        status = "okay";
        //badge = "imx185_bottom_liimx185";
        //badge = "e3322_bottom_A815P2";
        badge = "e3326_bottom_P5V27C";
        position = "bottom";
        orientation = "0";
        cam_module0_drivernode0: drivernode0 {
          status = "okay";
          pcl_id = "v4l2_sensor";
          devname = "imx219 7-0010";
          proc-device-tree = "/proc/device-tree/i2c@c250000/imx219_e@10";
        };
      };
    };
  };
};

After Jetson start up camera is recognized on i2c bus:

[    1.243627] i2c /dev entries driver
[    1.245379] imx219 7-0010: tegracam sensor driver:imx219_v2.0.6

Also i got this message:

[    1.577188] tegra-vi4 15700000.vi: subdev imx219 7-0010 bound

sudo media-ctl -v -p -d /dev/media0 gives me this output:

Opening media device /dev/media0
Enumerating entities
Found 1 entities
Enumerating pads and links
Media controller API version 0.1.0

Media device information
------------------------
driver          tegra-vi4
model           NVIDIA Tegra Video Input Device
serial          
bus info        
hw revision     0x3
driver version  0.0.0

Device topology
- entity 1: imx219 7-0010 (1 pad, 0 link)
            type V4L2 subdev subtype Sensor flags 0
	pad0: Source
v4l2_subdev_open: Failed to open subdev device node 
v4l2_subdev_open: Failed to open subdev device node 
v4l2_subdev_open: Failed to open subdev device node 

Comparing this output to example given in Driver Programing Guide I am missing nvcsi and vi-output entity.
Does anyone have any idea why those entities are not listed in output from media-ctl and how to fix it?

Any warning/error message in the kernel message?
Dump the device tree from below command to check the context.

sudo dtc -I fs -O dts -o imx219.dts /proc/device-tree

I don’t see any errors in kernel messages.

Attaching dumped device tree and output of dmesg.
dmesg.log (54.5 KB) imx219.dts.log (325.6 KB)

Didn’t find any suspect error.
Can have v4l2-ctl to capture frame data?

sudo v4l2-ctl --all gives output:
Failed to open /dev/video0: No such file or directory

Looks like the imx219 didn’t register successfully.
Could you have trace the imx219 register function to check the failed.

with enabled kernel debug dmesg gives me this:

[    4.036148] imx219 7-0010: probing v4l2 sensor at addr 0x10
[    4.036260] imx219 7-0010: mclk name not present, assume sensor driven externally
[    4.036269] imx219 7-0010: avdd, iovdd and/or dvdd reglrs. not present, assume sensor powered independently
[    4.036353] imx219 7-0010: tegracam sensor driver:imx219_v2.0.6
[    4.042322] imx219 7-0010: imx219_power_on: power on
[    4.066271] imx219 7-0010: imx219_power_off: power off
[    4.066353] imx219 7-0010: detected imx219 sensor

FYI, you have ‘okey’ instead of ‘okay’ in nvcsi

@dmc
Awesome, That’s too detail to find it.

Oh well, unbelievable that this was a problem.

v4l2-compilance looks fine now:

v4l2-compliance SHA   : not available

Driver Info:
	Driver name   : tegra-video
	Card type     : vi-output, imx219 7-0010
	Bus info      : platform:15700000.vi:4
	Driver version: 4.9.140
	Capabilities  : 0x84200001
		Video Capture
		Streaming
		Extended Pix Format
		Device Capabilities
	Device Caps   : 0x04200001
		Video Capture
		Streaming
		Extended Pix Format

Compliance test for device /dev/video0 (not using libv4l2):

Required ioctls:
	test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
	test second video open: OK
	test VIDIOC_QUERYCAP: OK
	test VIDIOC_G/S_PRIORITY: OK
	test for unlimited opens: OK

Debug ioctls:
	test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
	test VIDIOC_LOG_STATUS: OK

Input ioctls:
	test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
	test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
	test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
	test VIDIOC_ENUMAUDIO: OK (Not Supported)
	test VIDIOC_G/S/ENUMINPUT: OK
	test VIDIOC_G/S_AUDIO: OK (Not Supported)
	Inputs: 1 Audio Inputs: 0 Tuners: 0

Output ioctls:
	test VIDIOC_G/S_MODULATOR: OK (Not Supported)
	test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
	test VIDIOC_ENUMAUDOUT: OK (Not Supported)
	test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
	test VIDIOC_G/S_AUDOUT: OK (Not Supported)
	Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
	test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
	test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
	test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
	test VIDIOC_G/S_EDID: OK (Not Supported)

Test input 0:

	Control ioctls:
		test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
		test VIDIOC_QUERYCTRL: OK
		test VIDIOC_G/S_CTRL: OK
		test VIDIOC_G/S/TRY_EXT_CTRLS: OK
		test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
		test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
		Standard Controls: 1 Private Controls: 16

	Format ioctls:
		test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
		fail: v4l2-test-formats.cpp(1184): ret && node->has_frmintervals
		test VIDIOC_G/S_PARM: FAIL
		test VIDIOC_G_FBUF: OK (Not Supported)
		test VIDIOC_G_FMT: OK
		test VIDIOC_TRY_FMT: OK
		test VIDIOC_S_FMT: OK
		test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
		test Cropping: OK (Not Supported)
		test Composing: OK (Not Supported)
		test Scaling: OK (Not Supported)

	Codec ioctls:
		test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
		test VIDIOC_G_ENC_INDEX: OK (Not Supported)
		test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

	Buffer ioctls:
		test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
		test VIDIOC_EXPBUF: OK

Test input 0:


Total: 43, Succeeded: 42, Failed: 1, Warnings: 0

After some changes to device tree:

  i2c@c250000 {
    imx219_e@10 {
      #address-cells = <1>;
      #size-cells = <0>;

      reset-gpios = <&tegra_main_gpio CAM_RST_L GPIO_ACTIVE_LOW>;
      //ADDED
      //dovdd-supply = <&en_vdd_cam>;
      //avdd-reg = "vana";                                                                                                                                                                              
      //dvdd-reg = "vdig";                                                                                                                                                                              
      //iovdd-reg = "dovdd";         

      mclk = "extperiph1";

      devnode = "video4";
      compatible = "nvidia,imx219";
      reg = <0x10>;

      physical_w = "3.680";
      physical_h = "2.760";

      sensor_model ="imx219";
      use_sensor_mode_id = "true";

      mode0 { 
        mclk_khz = "24000";
				num_lanes = "2";
				tegra_sinterface = "serial_e";
				phy_mode = "DPHY";
				discontinuous_clk = "yes";
				dpcm_enable = "false";
				cil_settletime = "0";

				active_w = "3264";
				active_h = "2464";
        mode_type = "bayer";
        pixel_phase = "rggb";
        csi_pixel_bit_depth = "10";
				pixel_t = "bayer_rggb";
				readout_orientation = "90";
				line_length = "3448";
				inherent_gain = "1";
				mclk_multiplier = "18.67";
				pix_clk_hz = "182400000";

				gain_factor = "16";
				framerate_factor = "1000000";
				exposure_factor = "1000000";
				min_gain_val = "16"; /* 1.00x */
				max_gain_val = "170"; /* 10.66x */
				step_gain_val = "1";
				default_gain = "16"; /* 1.00x */
				min_hdr_ratio = "1";
				max_hdr_ratio = "1";
				min_framerate = "2000000"; /* 2.0 fps */
				max_framerate = "30000000"; /* 30.0 fps */
				step_framerate = "1";
				default_framerate = "21000000"; /* 21.0 fps */
				min_exp_time = "13"; /* us */
				max_exp_time = "683709"; /* us */
				step_exp_time = "1";
				default_exp_time = "2495"; /* us */

				embedded_metadata_height = "2";
      };

      ports {
        #address-cells = <1>;
        #size-cells = <0>;

        port@0 {
          reg = <0>;
          imx219_phy_out4: endpoint {
            port-index = <4>;
            bus-width = <2>;
            remote-endpoint = <&imx219_csi_in4>;
          };
        };
      };
    };
  };

I was able to capture image with v4l2-ctl -d /dev/video0 --set-fmt-video=width=3280,height=2464,pixelformat=RG10 --set-ctrl bypass_mode=0 --stream-mmap --stream-count=1 --stream-to=test_3280x2464.bayer and then convert it with gst-launch-1.0 -v filesrc location=test_3280x2464.bayer blocksize=16400384 ! "video/x-bayer,format=rggb,width=3280,height=2464,framerate=1/1" ! bayer2rgb ! videoconvert ! avenc_mjpeg ! filesink location=frame.jpeg -v but output image looks very bad(attached in post).

Any idea what is the cause of this?

Possible using v4l2-ctl to capture that won’t set to the suitable gain/expourse.
Have you try the argus_camera or nvgstcapture-1.0?