GT2005 CSI Camera Driver testing for A20-SOM204-EVB board

Started by karibe, April 14, 2019, 07:33:54 AM

Previous topic - Next topic

karibe

I bought the Olimex A20-SOM204-EVB because it is advertised as having the CSI camera interface and comes with the gt2005 2mp camera. I was eager to test this one feature. I have since realized that there is no reference of this camera ever working with this board and no one is working on it. This information is not provided on the product page, rather there is a text file that lists the issues with this board in the ftp folder that states the camera driver doesn't work and there is no workaround available. That is clear enough, at least I know the status, so I put a bit of effort into this.
There is no driver available in the latest kernel sources so I tried to build an server image with kernel 3.4[There is no desktop support for older builds]. It has the sun4i_csi driver folder for the CSI platform. The camera driver is available in there. I thought if I can get this working and do some image captures, then I can try to port the sensor driver to the latest kernel and V4L2 implementation using this as a reference.

Fex files were used for configuration in kernel 3.4 and the a20-som204 fex file in the sources has a problem, the power enable pin is set as PC16 so I changed it to PH07 following the EVB schematic.

I edited the camera driver sources to enable debug so I can see some logs in dmesg. After booting from SD card, I loaded the camera drivers with the following script:

#!/bin/sh

MOD_DIR="/lib/modules/3.4.113-sun7i/kernel/drivers/media/video"

sudo insmod $MOD_DIR/videobuf2-core.ko
sudo insmod $MOD_DIR/videobuf2-memops.ko
sudo insmod $MOD_DIR/videobuf2-vmalloc.ko
sudo insmod $MOD_DIR/videobuf-core.ko
sudo insmod $MOD_DIR/videobuf-dma-contig.ko
sudo insmod $MOD_DIR/videobuf-vmalloc.ko
sudo insmod src/sun4i_csi/device/gt2005.ko
sudo insmod src/sun4i_csi/csi0/sun4i_csi0.ko i2c_addr=0x78 ccm="gt2005"


I got the following messages:
[74818.131757] [CSI]Welcome to CSI driver
[74818.133361] [CSI]csi_init
[74818.136391] [CSI_DEBUG]csi_probe
[74818.140036] [CSI_DEBUG]dev->ccm_cfg[0] = bf1da088
[74818.143775] [CSI_DEBUG]dev->ccm_cfg[0]->ccm = gt2005
[74818.147897] [CSI_DEBUG]dev->ccm_cfg[0]->twi_id = 1
[74818.151658] [CSI_DEBUG]dev->ccm_cfg[0]->i2c_addr = 78
[74818.155403] [CSI_DEBUG]dev->ccm_cfg[0]->interface = 0
[74818.158927] [CSI_DEBUG]dev->ccm_cfg[0]->vflip = 0
[74818.162355] [CSI_DEBUG]dev->ccm_cfg[0]->hflip = 0
[74818.166794] [CSI_DEBUG]dev->ccm_cfg[0]->iovdd_str = axp20_pll
[74818.170414] [CSI_DEBUG]dev->ccm_cfg[0]->avdd_str =
[74818.173987] [CSI_DEBUG]dev->ccm_cfg[0]->dvdd_str =
[74818.177846] [CSI_DEBUG]dev->ccm_cfg[0]->flash_pol = 0
[74818.189223] [CSI]registered sub device,input_num = 0
[74818.193367] [CSI_DEBUG][GT2005]CSI_SUBDEV_CMD_GET_INFO
[74818.197381] [CSI_DEBUG][GT2005]ccm_info.mclk=16e3600
[74818.197387] 
[74818.200926] [CSI_DEBUG][GT2005]ccm_info.vref=1
[74818.200931] 
[74818.204414] [CSI_DEBUG][GT2005]ccm_info.href=1
[74818.204418] 
[74818.208046] [CSI_DEBUG][GT2005]ccm_info.clock=1
[74818.208050] 
[74818.211619] [CSI_DEBUG][GT2005]ccm_info.iocfg=0
[74818.211623] 
[74818.215711] [CSI_DEBUG][GT2005]CSI_SUBDEV_CMD_SET_INFO
[74818.219756] [CSI_DEBUG][GT2005]ccm_info.mclk=16e3600
[74818.219761] 
[74818.223244] [CSI_DEBUG][GT2005]ccm_info.vref=1
[74818.223247] 
[74818.226729] [CSI_DEBUG][GT2005]ccm_info.href=1
[74818.226733] 
[74818.230352] [CSI_DEBUG][GT2005]ccm_info.clock=1
[74818.230360] 
[74818.233936] [CSI_DEBUG][GT2005]ccm_info.iocfg=0
[74818.233940] 
[74818.238494] axp20_ldo3: Failed to create debugfs directory
[74818.241986] [CSI]power on and power off camera!
[74818.246076] [CSI_DEBUG][GT2005]CSI_SUBDEV_CMD_SET_INFO
[74818.250141] [CSI_DEBUG][GT2005]ccm_info.mclk=16e3600
[74818.250147] 
[74818.253630] [CSI_DEBUG][GT2005]ccm_info.vref=1
[74818.253634] 
[74818.257190] [CSI_DEBUG][GT2005]ccm_info.href=1
[74818.257196] 
[74818.260765] [CSI_DEBUG][GT2005]ccm_info.clock=1
[74818.260770] 
[74818.264337] [CSI_DEBUG][GT2005]ccm_info.iocfg=0
[74818.264341] 
[74818.267949] [CSI_DEBUG][GT2005]CSI_SUBDEV_PWR_ON
[74818.271522] [CSI_DEBUG][GT2005]dev->csi_input: 0
[74818.276134] [CSI_DEBUG][GT2005]dev->csi_module_clk: ee9ca9bc
[74818.279812] [ccu-err] clk_disable: invalid handle
[74818.337215] [ccu-err] clk_enable: invalid handle
[74818.597319] [CSI_DEBUG][GT2005]CSI_SUBDEV_PWR_OFF
[74818.637315] [ccu-err] clk_disable: invalid handle
[74818.641082] [CSI_DEBUG]dev->ccm_cfg[0]->sd = ee74d200
[74818.645363] [CSI_DEBUG]dev->ccm_cfg[0]->ccm_info = bf1da124
[74818.649594] [CSI_DEBUG]dev->ccm_cfg[0]->ccm_info.iocfg = 0
[74818.653697] [CSI_DEBUG]dev->ccm_cfg[0]->ccm_info.vref = 1
[74818.657853] [CSI_DEBUG]dev->ccm_cfg[0]->ccm_info.href = 1
[74818.662059] [CSI_DEBUG]dev->ccm_cfg[0]->ccm_info.clock = 1
[74818.666775] [CSI_DEBUG]dev->ccm_cfg[0]->ccm_info.mclk = 24000000
[74818.670826] [CSI_DEBUG]dev->ccm_cfg[0]->iovdd = ede81180
[74818.674764] [CSI_DEBUG]dev->ccm_cfg[0]->avdd =   (null)
[74818.678767] [CSI_DEBUG]dev->ccm_cfg[0]->dvdd =   (null)
[74818.682877] [CSI_DEBUG][GT2005]CSI_SUBDEV_CMD_SET_INFO
[74818.686897] [CSI_DEBUG][GT2005]ccm_info.mclk=16e3600
[74818.686906] 
[74818.690426] [CSI_DEBUG][GT2005]ccm_info.vref=1
[74818.690435] 
[74818.693949] [CSI_DEBUG][GT2005]ccm_info.href=1
[74818.693953] 
[74818.697544] [CSI_DEBUG][GT2005]ccm_info.clock=1
[74818.697548] 
[74818.701117] [CSI_DEBUG][GT2005]ccm_info.iocfg=0
[74818.701121] 
[74818.707406] [CSI]V4L2 device registered as video0
[74818.714982] [CSI_DEBUG]csi_open
[74818.720683] [CSI_DEBUG][GT2005]CSI_SUBDEV_CMD_SET_INFO
[74818.724855] [CSI_DEBUG][GT2005]ccm_info.mclk=16e3600
[74818.724861] 
[74818.728442] [CSI_DEBUG][GT2005]ccm_info.vref=1
[74818.728447] 
[74818.731930] [CSI_DEBUG][GT2005]ccm_info.href=1
[74818.731934] 
[74818.735503] [CSI_DEBUG][GT2005]ccm_info.clock=1
[74818.735507] 
[74818.739155] [CSI_DEBUG][GT2005]ccm_info.iocfg=0
[74818.739162] 
[74818.742755] [CSI_DEBUG][GT2005]CSI_SUBDEV_PWR_ON
[74818.746334] [CSI_DEBUG][GT2005]dev->csi_input: 0
[74818.751081] [CSI_DEBUG][GT2005]dev->csi_module_clk: ee9ca9bc
[74819.067300] [CSI_DEBUG][GT2005]CSI_SUBDEV_STBY_ON
[74819.547356] [CSI_DEBUG][GT2005]CSI_SUBDEV_STBY_OFF
[74819.716645] [CSI_DEBUG][GT2005]sensor_init
[74819.963827] [CSI]sensor initial success when csi open!
[74820.186319] [CSI_DEBUG]csi_close
[74820.190448] [CSI_DEBUG][GT2005]CSI_SUBDEV_CMD_SET_INFO
[74820.194462] [CSI_DEBUG][GT2005]ccm_info.mclk=16e3600
[74820.194471] 
[74820.198126] [CSI_DEBUG][GT2005]ccm_info.vref=1
[74820.198136] 
[74820.201626] [CSI_DEBUG][GT2005]ccm_info.href=1
[74820.201634] 
[74820.205211] [CSI_DEBUG][GT2005]ccm_info.clock=1
[74820.205219] 
[74820.208852] [CSI_DEBUG][GT2005]ccm_info.iocfg=0
[74820.208861] 
[74820.212526] [CSI_DEBUG][GT2005]CSI_SUBDEV_PWR_OFF


So the camera driver loads, probes and finds the sensor. The I2C interface works well. In the logs, there are messages of invalid clock handle the first time the CSI sub-device is powered on and off but I guess it tries again after populating some fields in the sub-device structure and finally succeeds.

I then tried to capture a frame in the RAW format using a simple V4L2 application and I got the following messages:
david@olimex:~/src/capturev4l$ ./capture
Driver Caps:
  Driver: "sun4i_csi"
  Card: "sun4i_csi"
  Bus: "platform:sun4i_csi sun4i_csi.0"
  Version: 1.0
  Capabilities: 05000001
  FMT : CE Desc
--------------------
  422P:    planar YUV 422
  YU12:    planar YUV 420
  NV16:    planar YUV 422 UV combined
  NV12:    planar YUV 420 UV combined
  NV61:    planar YUV 422 VU combined
  NV21:    planar YUV 420 VU combined
  HM12:    MB YUV420
  BA81:    RAW Bayer
  YUYV:    YUV422 YUYV
  YVYU:    YUV422 YVYU
  UYVY:    YUV422 UYVY
  VYUY:    YUV422 VYUY
Selected Camera Mode:
  Width: 640
  Height: 480
  PixFmt: BA81
  Field: 1
Length: 307200
Address: 0xb6e57000
Image Length: 0
performing v4l2 select with 10s timeout


Everything seems to work, upto the point where v4l2_select returns with a timeout value. No image data is coming from the sensor.
The dmesg logs for this capture were as follows:
david@olimex:~/src/capturev4l$ dmesg
[  217.655020] [CSI_DEBUG]csi_open
[  217.659152] [CSI_DEBUG][GT2005]CSI_SUBDEV_CMD_SET_INFO
[  217.668406] [CSI_DEBUG][GT2005]ccm_info.mclk=16e3600
[  217.668418] 
[  217.671977] [CSI_DEBUG][GT2005]ccm_info.vref=1
[  217.671987] 
[  217.675478] [CSI_DEBUG][GT2005]ccm_info.href=1
[  217.675486] 
[  217.679062] [CSI_DEBUG][GT2005]ccm_info.clock=1
[  217.679070] 
[  217.682726] [CSI_DEBUG][GT2005]ccm_info.iocfg=0
[  217.682731] 
[  217.686309] [CSI_DEBUG][GT2005]CSI_SUBDEV_PWR_ON
[  218.010049] [CSI_DEBUG][GT2005]CSI_SUBDEV_STBY_ON
[  218.489946] [CSI_DEBUG][GT2005]CSI_SUBDEV_STBY_OFF
[  218.659171] [CSI_DEBUG][GT2005]sensor_init
[  218.905901] [CSI]sensor initial success when csi open!
[  219.128492] [CSI_DEBUG]vidioc_reqbufs
[  219.130706] [CSI_DEBUG]buffer_setup
[  219.135158] [CSI]buffer_setup, buffer count=4, size=460800
[  219.139218] [CSI_DEBUG]mmap called, vma=0xee637c60
[  219.144017] [CSI_DEBUG]vma start=0xb6e1e000, size=462848, ret=0
[  219.147565] [CSI_DEBUG]mmap called, vma=0xee6372c0
[  219.152763] [CSI_DEBUG]vma start=0xb6dad000, size=462848, ret=0
[  219.157893] [CSI_DEBUG]mmap called, vma=0xee637160
[  219.162587] [CSI_DEBUG]vma start=0xb6d3c000, size=462848, ret=0
[  219.166104] [CSI_DEBUG]mmap called, vma=0xee6379a0
[  219.170801] [CSI_DEBUG]vma start=0xb6ccb000, size=462848, ret=0
[  219.173180] [CSI_DEBUG]buffer_prepare
[  219.175546] [CSI_DEBUG]buffer_prepare
[  219.177908] [CSI_DEBUG]buffer_prepare
[  219.180339] [CSI_DEBUG]buffer_prepare
[  219.182797] [CSI_DEBUG]video stream on
[  219.188360] [CSI_DEBUG]csi_start_generating
[  219.190592] [CSI_DEBUG]buffer_queue
[  219.192777] [CSI_DEBUG]buffer_queue
[  219.194958] [CSI_DEBUG]buffer_queue
[  219.197140] [CSI_DEBUG]buffer_queue
[  219.199693] [CSI_DEBUG]buf ptr=edcabb00
[  219.202747] [CSI_DEBUG]csi_buf_addr_y=3800000
[  219.205884] [CSI_DEBUG]csi_buf_addr_cb=384b000
[  219.209041] [CSI_DEBUG]csi_buf_addr_cr=384b000
[  219.214660] [CSI_DEBUG]csi_start_generating
[  224.217899] [CSI_DEBUG]csi_start_generating
[  224.222005] [CSI_DEBUG]buffer_release
[  224.225250] [CSI_DEBUG]free_buffer, state: 5
[  224.228058] [CSI_DEBUG]free_buffer: freed
[  224.230440] [CSI_DEBUG]buffer_release
[  224.233415] [CSI_DEBUG]free_buffer, state: 5
[  224.236125] [CSI_DEBUG]free_buffer: freed
[  224.238855] [CSI_DEBUG]buffer_release
[  224.241859] [CSI_DEBUG]free_buffer, state: 5
[  224.244577] [CSI_DEBUG]free_buffer: freed
[  224.247170] [CSI_DEBUG]buffer_release
[  224.250156] [CSI_DEBUG]free_buffer, state: 5
[  224.252873] [CSI_DEBUG]free_buffer: freed
[  224.256463] [CSI_DEBUG]csi_close
[  224.258838] [CSI_DEBUG]buffer_release
[  224.261802] [CSI_DEBUG]free_buffer, state: 0
[  224.264504] [CSI_DEBUG]free_buffer: freed
[  224.271925] [CSI_DEBUG]buffer_release
[  224.274894] [CSI_DEBUG]free_buffer, state: 0
[  224.277651] [CSI_DEBUG]free_buffer: freed
[  224.280011] [CSI_DEBUG]buffer_release
[  224.282976] [CSI_DEBUG]free_buffer, state: 0
[  224.285678] [CSI_DEBUG]free_buffer: freed
[  224.288049] [CSI_DEBUG]buffer_release
[  224.291014] [CSI_DEBUG]free_buffer, state: 0
[  224.293717] [CSI_DEBUG]free_buffer: freed
[  224.297810] [CSI_DEBUG][GT2005]CSI_SUBDEV_CMD_SET_INFO
[  224.301843] [CSI_DEBUG][GT2005]ccm_info.mclk=16e3600
[  224.301847] 
[  224.305330] [CSI_DEBUG][GT2005]ccm_info.vref=1
[  224.305334] 
[  224.308828] [CSI_DEBUG][GT2005]ccm_info.href=1
[  224.308831] 
[  224.312401] [CSI_DEBUG][GT2005]ccm_info.clock=1
[  224.312405] 
[  224.315973] [CSI_DEBUG][GT2005]ccm_info.iocfg=0
[  224.315977] 
[  224.319654] [CSI_DEBUG][GT2005]CSI_SUBDEV_PWR_OFF


It seems like it succeeds in detecting the sensor and sending controls via I2C, creating mmap buffers, setting stream on, sensor driver calls start generating several times and when V4L doesn't get any action in the buffers, releases the buffers and powers off the sub-device. So that's it, V4L2_select times out. No data from the sensor.
I will have to verify the p_clk amd m_clk signals with an oscilloscope[I don't have one at my disposal right now] to see if the data interface works or not. If anyone could help with this?