Custom ov5640 csi camera

Dear All,
I have custom csi camera properly working under apalis T30 and currently switching to imx6. I have camera reset procedure for apalis T30 as you can see below

#power down
echo out > /sys/class/gpio/gpio146/direction
sleep 3
#reset
echo out > /sys/class/gpio/gpio149/direction
sleep 3
echo 1 > /sys/class/gpio/gpio146/value
sleep 3
echo 1 > /sys/class/gpio/gpio149/value
sleep 3
echo 0 > /sys/class/gpio/gpio149/value
sleep 3
echo 0 > /sys/class/gpio/gpio146/value
sleep 3
echo 1 > /sys/class/gpio/gpio149/value
sleep 3
modprobe videobuf2-memops
sleep 3
modprobe videobuf2-dma-nvmap
sleep 3
modprobe ov5640
sleep 3
modprobe tegra_v4l2_camera
sleep 3

as you can see I’m using different gpios comparing to csi camera connected to eval board, so I have edited device tree for imx6 as below:

diff --git a/arch/arm/boot/dts/imx6qdl-apalis-eval.dtsi b/arch/arm/boot/dts/imx6qdl-apalis-eval.dtsi
index c061717..1e082e2 100644
--- a/arch/arm/boot/dts/imx6qdl-apalis-eval.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-apalis-eval.dtsi
@@ -251,8 +251,10 @@
                DOVDD-supply = <&reg_1p8v>;
                AVDD-supply = <&reg_2p5v>;
                DVDD-supply = <&reg_1p8v>;
-               pwn-gpios = <&gpio2 5 GPIO_ACTIVE_HIGH>;
-               rst-gpios = <&gpio2 4 GPIO_ACTIVE_LOW>;
+       //      pwn-gpios = <&gpio2 5 GPIO_ACTIVE_HIGH>;
+       //      rst-gpios = <&gpio2 4 GPIO_ACTIVE_LOW>;
+               pwn-gpios = <&gpio2 4 GPIO_ACTIVE_HIGH>;
+               rst-gpios = <&gpio2 7 GPIO_ACTIVE_LOW>;
                ipu_id = <0>;
                csi_id = <1>;
                mclk = <22000000>;

but I’m facing an error:

[    7.176006] ov564x_mipi 3-003c: request of ov5640_mipi_reset failed
[    7.201054] ov564x_mipi: probe of 3-003c failed with error -16

so my question is how to make gpio2 7 available for camera driver?

You may want to remove the pinctrl_apalis_gpio4 which is defined here from e.g. here.

BTW: Either one should be using BSP 2.7b4 based on Linux kernel 4.1 or BSP 2.8b3 based on 4.9 as explained e.g. here.

So I have changed image to: Apalis-iMX6_LXDE-Image_2.8.3#, commented gpio 39 in /usr/bin/gpio-export.sh, looks like camera is found, but still not working:

root@apalis-imx6:~# dmesg | grep -ni csi
80:[    0.120597] SCSI subsystem initialized
99:[    0.280557] mxc_mipi_csi2 21dc000.mipi_csi: i.MX MIPI CSI2 driver probed ipu0 csi1
100:[    0.280606] mxc_mipi_csi2 21dc000.mipi_csi: i.MX MIPI CSI2 dphy version is 0x3130302a
101:[    0.280721] MIPI CSI2 driver module loaded
171:[    1.769310] scsi host0: ahci-imx
349:[    7.342874] mxc_v4l2_master_attach: ipu0:/csi1 parallel attached ov564x_mipi:mxc_v4l2_cap2
root@apalis-imx6:~#
root@apalis-imx6:~#
root@apalis-imx6:~# dmesg | grep -ni v4l
223:[    2.398540] mxc_v4l2_output v4l2_out: V4L2 device registered as video16
224:[    2.410376] mxc_v4l2_output v4l2_out: V4L2 device registered as video17
349:[    7.342874] mxc_v4l2_master_attach: ipu0:/csi1 parallel attached ov564x_mipi:mxc_v4l2_cap2
353:[    7.749997] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
354:[    7.753753] ERROR: v4l2 capture: slave not found! V4L2_CID_HUE
root@apalis-imx6:~# dmesg | grep -ni mipi
99:[    0.280557] mxc_mipi_csi2 21dc000.mipi_csi: i.MX MIPI CSI2 driver probed ipu0 csi1
100:[    0.280606] mxc_mipi_csi2 21dc000.mipi_csi: i.MX MIPI CSI2 dphy version is 0x3130302a
101:[    0.280721] MIPI CSI2 driver module loaded
348:[    6.943413] ov564x_mipi 3-003c: found pwm2, period=0
349:[    7.342874] mxc_v4l2_master_attach: ipu0:/csi1 parallel attached ov564x_mipi:mxc_v4l2_cap2
350:[    7.358425] camera ov5640_mipi is found

any ideas?

more debug:
root@apalis-imx6:~# v4l2-ctl --list-devices
():
/dev/video2
/dev/video16
/dev/video17

Failed to open /dev/video0: Resource temporarily unavailable
root@apalis-imx6:~#
login as: root
Last login: Fri Jul 13 09:11:52 2018 from 10.215.121.1
root@apalis-imx6:~# v4l2-ctl --list-devices
 ():
        /dev/video2
        /dev/video16
        /dev/video17

Failed to open /dev/video0: Resource temporarily unavailable
root@apalis-imx6:~# v4l2-ctl -V --device=/dev/video2
Format Video Capture:
        Width/Height      : 288/352
        Pixel Format      : 'YU12'
        Field             : Any
        Bytes per Line    : 432
        Size Image        : 152064
        Colorspace        : Default
        Transfer Function : Default
        YCbCr/HSV Encoding: Default
        Quantization      : Default
root@apalis-imx6:~# v4l2-ctl -V --device=/dev/video16
VIDIOC_G_FMT: failed: Invalid argument
root@apalis-imx6:~# v4l2-ctl -V --device=/dev/video17
VIDIOC_G_FMT: failed: Invalid argument

Could you please attach a complete full boot log as text file. Plus your custom device tree hopefully with removed pinctrl_apalis_gpio4 as previously suggested.

root@kamil-VirtualBox:/home/kamil/apalis/imx6/linux-toradex# git diff .
diff --git a/arch/arm/boot/dts/imx6qdl-apalis-eval.dtsi b/arch/arm/boot/dts/imx6qdl-apalis-eval.dtsi
index c061717..2547806 100644
--- a/arch/arm/boot/dts/imx6qdl-apalis-eval.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-apalis-eval.dtsi
@@ -251,8 +251,10 @@
                DOVDD-supply = <&reg_1p8v>;
                AVDD-supply = <&reg_2p5v>;
                DVDD-supply = <&reg_1p8v>;
-               pwn-gpios = <&gpio2 5 GPIO_ACTIVE_HIGH>;
-               rst-gpios = <&gpio2 4 GPIO_ACTIVE_LOW>;
+       //      pwn-gpios = <&gpio2 5 GPIO_ACTIVE_HIGH>;
+       //      rst-gpios = <&gpio2 4 GPIO_ACTIVE_LOW>;
+               pwn-gpios = <&gpio2 4 GPIO_ACTIVE_HIGH>;
+               rst-gpios = <&gpio2 7 GPIO_ACTIVE_LOW>;
                ipu_id = <0>;
                csi_id = <1>;
                mclk = <22000000>;
@@ -283,7 +285,7 @@
         */
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_apalis_gpio1 &pinctrl_apalis_gpio2
-                    &pinctrl_apalis_gpio3 &pinctrl_apalis_gpio4
+                     &pinctrl_apalis_gpio3
                     &pinctrl_apalis_gpio5 &pinctrl_apalis_gpio6
                     &pinctrl_apalis_gpio7 &pinctrl_apalis_gpio8>;
 };
diff --git a/arch/arm/boot/dts/imx6qdl-apalis.dtsi b/arch/arm/boot/dts/imx6qdl-apalis.dtsi
index 26c94bd..11658c2 100644
--- a/arch/arm/boot/dts/imx6qdl-apalis.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-apalis.dtsi
@@ -514,7 +514,7 @@
        lvds-channel@0 {
                reg = <0>;
                fsl,data-mapping = "spwg"; /* "jeida"; */
-               fsl,data-width = <18>;
+               fsl,data-width = <24>;
                crtc = "ipu2-di1";
                primary;
                status = "okay";
@@ -601,7 +601,7 @@
        lvds-channel@1 {
                reg = <1>;
                fsl,data-mapping = "spwg";
-               fsl,data-width = <18>;
+               fsl,data-width = <24>;
                crtc = "ipu1-di0";
                status = "okay";

Bootlog

Thanks for the files. Did you remove the pinctrl_apalis_gpio4?

Hi jaski, as you can see in diff

-                    &pinctrl_apalis_gpio3 &pinctrl_apalis_gpio4
+                     &pinctrl_apalis_gpio3

I have removed it, or maybe should I remove it somewhere else?

yeah, this looks good. So the pinctrl_apalis_gpio4 is disabled and camera is found.

Could you try out the commands on this page and share the output? Thanks.

here you have:

 gst-launch-1.0 -v imxv4l2src device=/dev/video1 ! capsfilter caps="video/x-raw, width=1280, height=720, framerate=30/1" ! queue ! imxv4l2sink
    ====== IMXV4L2SRC: 4.3.4 build on Jun 26 2018 19:17:38. ======
    ====== IMXV4L2SINK: 4.3.4 build on Jun 26 2018 19:17:38. ======
    Setting pipeline to PAUSED ...
    display(/dev/fb0) resolution is (1920x1080).
    ERROR: Pipeline doesn't want to pause.
    ERROR: from element /GstPipeline:pipeline0/GstImxV4l2Src:imxv4l2src0: GStreamer error: state change failed and some element failed to post a proper error message with the reason for the failure.
    Additional debug info:
    ../../../../git/libs/gst/base/gstbasesrc.c(3345): gst_base_src_start (): /GstPipeline:pipeline0/GstImxV4l2Src:imxv4l2src0:
    Failed to start
    Setting pipeline to NULL ...
    Freeing pipeline ...

and more detailed gstreamer log with debug level = 7gstreamer log

thanks for the log. Do you have a device defined as /dev/video1? I think in your case this should be /dev/video2.

I was trying video2 as well, but gstreamer stack with

gst-launch-1.0 -v imxv4l2src device=/dev/video2 ! capsfilter caps="video/x-raw, width=640, height=480, framerate=30/1" ! queue ! imxv4l2sink
====== IMXV4L2SRC: 4.3.4 build on Jun 26 2018 19:17:38. ======
====== IMXV4L2SINK: 4.3.4 build on Jun 26 2018 19:17:38. ======
Setting pipeline to PAUSED ...
display(/dev/fb0) resolution is (1920x1080).
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
/GstPipeline:pipeline0/GstImxV4l2Src:imxv4l2src0.GstPad:src: caps = video/x-raw, format=(string)I420, width=(int)640, height=(int)480, framerate=(fraction)30/1
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = video/x-raw, format=(string)I420, width=(int)640, height=(int)480, framerate=(fraction)30/1
/GstPipeline:pipeline0/GstQueue:queue0.GstPad:src: caps = video/x-raw, format=(string)I420, width=(int)640, height=(int)480, framerate=(fraction)30/1
/GstPipeline:pipeline0/GstImxV4l2Sink:imxv4l2sink0.GstPad:sink: caps = video/x-raw, format=(string)I420, width=(int)640, height=(int)480, framerate=(fraction)30/1
/GstPipeline:pipeline0/GstQueue:queue0.GstPad:sink: caps = video/x-raw, format=(string)I420, width=(int)640, height=(int)480, framerate=(fraction)30/1
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps = video/x-raw, format=(string)I420, width=(int)640, height=(int)480, framerate=(fraction)30/1
v4l2sink need allocate 3 buffers.

nothing happens later. By the way I have video devices as bellow:

crw-rw----    1 root     video      81,   2 Jul 18 10:17 /dev/video0
crw-rw----    1 root     video      81,   3 Jul 18 10:17 /dev/video1
crw-rw----    1 root     video      81,   0 Jul 18 10:17 /dev/video16
crw-rw----    1 root     video      81,   1 Jul 18 10:17 /dev/video17
crw-rw----    1 root     video      81,   4 Jul 18 10:17 /dev/video2

unfortunately, driver doesn’t show which device is linked with ov5640

Ok I have managed to make a pic with /dev/video2 and command:

gst-launch-1.0 -vv -e imxv4l2src device=/dev/video2 ! capsfilter caps="video/x-raw, width=1280, height=720, framerate=30/1" ! queue ! jpegenc ! multifilesink location=snapshot-%05d.jpg. 

Looks like there is some problem with imxv4l2sink which is not showing window with picture from camera.

So this means you can make a picture but you don’t see a video. I tried capturing a video with our regular BSP and It is working fine.