This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

J722SXH01EVM: Adding support for a new v4l2 sub-device driver

Part Number: J722SXH01EVM

Tool/software:

Hi Ti experts,

I am working on interfacing a new OnSemi ToF sensor over MIPI/SCI2.

Using a sample driver from the TISDK (imx219.c) I was able to load my driver an probe successfully my device over i2c.

I modified /opt/edgeai-gst-apps/scripts/setup_cameras.sh script in order to setup the media pipeline for my device.

Pegasus ToF Camera 1 detected
    device = /dev/video-pegasustof-cam0
    name = Pegasus ToF
    format = [fmt:SRGGB12_1X12/1280x960]
    subdev_id = /dev/v4l-pegasustof-subdev0
    isp_required = yes

Output from media-ctl -d 1 -p below:

media-ctl -d 1 -p
Media controller API version 6.6.44

Media device information
------------------------
driver          j721e-csi2rx
model           TI-CSI2RX
serial
bus info        platform:30122000.ticsi2rx
hw revision     0x1
driver version  6.6.44

Device topology
- entity 1: 30122000.ticsi2rx (5 pads, 5 links, 1 route)
            type V4L2 subdev subtype Unknown flags 0
            device node name /dev/v4l-subdev0
        routes:
                0/0 -> 1/0 [ACTIVE]
        pad0: Sink
                [stream:0 fmt:SRGGB12_1X12/1280x960 field:none]
                <- "cdns_csi2rx.30121000.csi-bridge":1 [ENABLED,IMMUTABLE]
        pad1: Source
                [stream:0 fmt:SRGGB12_1X12/1280x960 field:none]
                -> "30122000.ticsi2rx context 0":0 [ENABLED,IMMUTABLE]
        pad2: Source
                -> "30122000.ticsi2rx context 1":0 [ENABLED,IMMUTABLE]
        pad3: Source
                -> "30122000.ticsi2rx context 2":0 [ENABLED,IMMUTABLE]
        pad4: Source
                -> "30122000.ticsi2rx context 3":0 [ENABLED,IMMUTABLE]

- entity 7: cdns_csi2rx.30121000.csi-bridge (5 pads, 2 links, 1 route)
            type V4L2 subdev subtype Unknown flags 0
            device node name /dev/v4l-subdev1
        routes:
                0/0 -> 1/0 [ACTIVE]
        pad0: Sink
                [stream:0 fmt:SRGGB12_1X12/1280x960 field:none]
                <- "pegasustof 6-003c":0 [ENABLED,IMMUTABLE]
        pad1: Source
                [stream:0 fmt:SRGGB12_1X12/1280x960 field:none]
                -> "30122000.ticsi2rx":0 [ENABLED,IMMUTABLE]
        pad2: Source
        pad3: Source
        pad4: Source

- entity 13: pegasustof 6-003c (1 pad, 1 link, 0 routes)
             type V4L2 subdev subtype Sensor flags 0
             device node name /dev/v4l-subdev2
        pad0: Source
                [stream:0 fmt:SRGGB12_1X12/1280x960 field:none colorspace:raw xfer:none quantization:full-range
                 crop.bounds:(64,44)/1280x960
                 crop:(64,44)/1280x960]
                -> "cdns_csi2rx.30121000.csi-bridge":0 [ENABLED,IMMUTABLE]

- entity 19: 30122000.ticsi2rx context 0 (1 pad, 1 link)
             type Node subtype V4L flags 0
             device node name /dev/video2
        pad0: Sink
                <- "30122000.ticsi2rx":1 [ENABLED,IMMUTABLE]

- entity 25: 30122000.ticsi2rx context 1 (1 pad, 1 link)
             type Node subtype V4L flags 0
             device node name /dev/video3
        pad0: Sink
                <- "30122000.ticsi2rx":2 [ENABLED,IMMUTABLE]

- entity 31: 30122000.ticsi2rx context 2 (1 pad, 1 link)
             type Node subtype V4L flags 0
             device node name /dev/video4
        pad0: Sink
                <- "30122000.ticsi2rx":3 [ENABLED,IMMUTABLE]

- entity 37: 30122000.ticsi2rx context 3 (1 pad, 1 link)
             type Node subtype V4L flags 0
             device node name /dev/video5
        pad0: Sink
                <- "30122000.ticsi2rx":4 [ENABLED,IMMUTABLE]

Everything up to this point seems ok (as far as I can tell).

My device reports one source pad SRGGB12_1X12/1280X960 and all other devices in the media pipeline are setup using this format.

Now when I call: v4l2-ctl -d /dev/video-pegasustof-cam0 --get-fmt-video

I get 640x480 UYVY 4:2:2 instead of the expected 1280x960 SRGGB12.

v4l2-ctl -d /dev/video-pegasustof-cam0 --get-fmt-video
Format Video Capture:
        Width/Height      : 640/480
        Pixel Format      : 'UYVY' (UYVY 4:2:2)
        Field             : None
        Bytes per Line    : 1280
        Size Image        : 614400
        Colorspace        : sRGB
        Transfer Function : sRGB
        YCbCr/HSV Encoding: ITU-R 601
        Quantization      : Limited Range
        Flags             :

Somehow my sub-device format is not propagated to the video device driver.

If I try and run a user-space application (like app_tiovx_v4l2_capture_moddule_test.c) that opens /dev/video-pegasustof-cam0 I see that starting the stream succeeds in the application but my driver's s_stream routine is never called.

int v4l2_capture_start(v4l2CaptureHandle *handle)
{
    int status = 0;
    enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

    if (-1 == xioctl(handle->fd, VIDIOC_STREAMON, &type))
    {
        TIOVX_MODULE_ERROR("[V4L2_CAPTURE] VIDIOC_STREAMON failed\n");
        status = -1;
    }

    sleep(V4L2_CAPTURE_STREAMON_DELAY);

    return status;
}

When I do the same using a imx219 sensor I can see that the s_stream routime of the imx219.c driver is invoked.

Since my driver is based on imx219.c I expect my s_stream routine to be invoked but unfortunately it is not.

It seem the link between /dev/video-pegasustof-cam0 and /dev/v4l-pegasustof-subdev0 is not complete as indicated by the fact that /dev/video-pegasustof-cam0 format is not that of /dev/v4l-pegasustof-subdev0 and the fact that my s_stream routine is never called.

Any help would be appreciated at this point.

  • Hi Stéphane,

    Before diving into the TIOVX capture applications, could you first validate that the sensor has been enabled successfully by capturing data with v4l2-ctl or yavta?

    My device reports one source pad SRGGB12_1X12/1280X960 and all other devices in the media pipeline are setup using this format.

    Now when I call: v4l2-ctl -d /dev/video-pegasustof-cam0 --get-fmt-video

    I get 640x480 UYVY 4:2:2 instead of the expected 1280x960 SRGGB12.

    This is the expected output if you have not captured from the video device after booting the EVM. If you capture from the video device with GStreamer (gst-launch-1.0) then check the format using v4l2-ctl afterwards, you will find the format that you have set using media-ctl (setup_cameras.sh). See the example using imx219 below.

    IMX219 Camera 0 detected
        device = /dev/video-imx219-cam0
        name = imx219
        format = [fmt:SRGGB8_1X8/1920x1080]
        subdev_id = /dev/v4l-imx219-subdev0
        isp_required = yes
    root@j722s-evm:/opt/edgeai-gst-apps# v4l2-ctl -d /dev/video-imx219-cam0 --get-fmt-video
    Format Video Capture:
            Width/Height      : 640/480
            Pixel Format      : 'UYVY' (UYVY 4:2:2)
            Field             : None
            Bytes per Line    : 1280
            Size Image        : 614400
            Colorspace        : sRGB
            Transfer Function : sRGB
            YCbCr/HSV Encoding: ITU-R 601
            Quantization      : Limited Range
            Flags             :
    root@j722s-evm:/opt/edgeai-gst-apps# gst-launch-1.0 v4l2src device=/dev/video-imx219-cam0 io-mode=5 ! queue leaky=2 ! video/x-bayer, width=1920, height=1080, framerate=30/1, format=rggb ! tiovxisp sink_0::device=/dev/v4l-subdev2 sensor-name="SENSOR_SONY_IMX219_RPI" dcc-isp-file=/opt/imaging/imx219/linear/dcc_viss_1920x1080.bin sink_0::dcc-2a-file=/opt/imaging/imx219/linear/dcc_2a_1920x1080.bin format-msb=7 ! video/x-raw, format=NV12, width=1920, height=1080, framerate=30/1 ! kmssink driver-name=tidss sync=false
    APP: Init ... !!!
       179.744986 s: MEM: Init ... !!!
       179.745058 s: MEM: Initialized DMA HEAP (fd=8) !!!
       179.745260 s: MEM: Init ... Done !!!
       179.745276 s: IPC: Init ... !!!
       179.813538 s: IPC: Init ... Done !!!
    REMOTE_SERVICE: Init ... !!!
    REMOTE_SERVICE: Init ... Done !!!
       179.825794 s: GTC Frequency = 200 MHz
    APP: Init ... Done !!!
       179.830015 s:  VX_ZONE_INFO: Globally Enabled VX_ZONE_ERROR
       179.830073 s:  VX_ZONE_INFO: Globally Enabled VX_ZONE_WARNING
       179.830085 s:  VX_ZONE_INFO: Globally Enabled VX_ZONE_INFO
       179.831857 s:  VX_ZONE_INFO: [tivxPlatformCreateTargetId:134] Added target MPU-0
       179.832075 s:  VX_ZONE_INFO: [tivxPlatformCreateTargetId:134] Added target MPU-1
       179.832204 s:  VX_ZONE_INFO: [tivxPlatformCreateTargetId:134] Added target MPU-2
       179.832317 s:  VX_ZONE_INFO: [tivxPlatformCreateTargetId:134] Added target MPU-3
       179.832334 s:  VX_ZONE_INFO: [tivxInitLocal:126] Initialization Done !!!
       179.832349 s:  VX_ZONE_INFO: Globally Disabled VX_ZONE_INFO
    Setting pipeline to PAUSED ...
    Pipeline is live and does not need PREROLL ...
    Pipeline is PREROLLED ...
    Setting pipeline to PLAYING ...
    New clock: GstSystemClock
    Redistribute latency...
    handling interrupt.:99.
    Interrupt: Stopping pipeline ...
    Execution ended after 0:00:02.834775715
    Setting pipeline to NULL ...
    Freeing pipeline ...
    APP: Deinit ... !!!
    REMOTE_SERVICE: Deinit ... !!!
    REMOTE_SERVICE: Deinit ... Done !!!
       182.916727 s: IPC: Deinit ... !!!
       182.919655 s: IPC: DeInit ... Done !!!
       182.919722 s: MEM: Deinit ... !!!
       182.919832 s: DDR_SHARED_MEM: Alloc's: 25 alloc's of 24308559 bytes
       182.919850 s: DDR_SHARED_MEM: Free's : 25 free's  of 24308559 bytes
       182.919861 s: DDR_SHARED_MEM: Open's : 0 allocs  of 0 bytes
       182.919877 s: MEM: Deinit ... Done !!!
    APP: Deinit ... Done !!!
    root@j722s-evm:/opt/edgeai-gst-apps# v4l2-ctl -d /dev/video-imx219-cam0 --get-fmt-video
    Format Video Capture:
            Width/Height      : 1920/1080
            Pixel Format      : 'RGGB' (8-bit Bayer RGRG/GBGB)
            Field             : None
            Bytes per Line    : 1920
            Size Image        : 2073600
            Colorspace        : Default
            Transfer Function : Default (maps to Rec. 709)
            YCbCr/HSV Encoding: Default (maps to ITU-R 601)
            Quantization      : Default (maps to Full Range)
            Flags             :
    

    Here are some FAQs that may help:

    Thank you,

    Fabiana 

  • Hi Fabiana, sorry for the late reply. I was finally able to make it work and acquire images from my ToF sensor. I fixed the problem by setting the format of the video device (/dev/video-pegasustof-cam0) to the correct format using v4l2-ctl -v 'width=1280,height=960,pixelformat=RG12'.

    Thank you,

    Stephane