AnsweredAssumed Answered

Cannot capture video or image for SBGGR12_1X12 format with Pico DCAM20 Camera Module

Question asked by Michael Tong on Jul 7, 2020
Latest reply on Jul 21, 2020 by Wigros Sun

Hi,

Currenty I am working on i.MX8M Nano with Camera module Pico DCAM20 (2 lanes). To add support for this driver, I added the driver file addi903x.c as attachment.

Mark , the addi903x need 2 lanes 135Mhz mipi clk RAW12bit 

 

In our Linux 5.4.3 MIPI driver added support for MEDIA_BUS_FMT_SBGGR12_1X12 like this:

======== drivers/staging/media/imx/imx8-isi-cap.c  =========

struct mxc_isi_fmt mxc_isi_out_formats[] = {
{
.name = "RGB565",
.fourcc = V4L2_PIX_FMT_RGB565,
.depth = { 16 },
.color = MXC_ISI_OUT_FMT_RGB565,
.memplanes = 1,
.colplanes = 1,
.mbus_code = MEDIA_BUS_FMT_RGB565_1X16,
}, {
.name = "RGB24",
.fourcc = V4L2_PIX_FMT_RGB24,
.depth = { 24 },
.color = MXC_ISI_OUT_FMT_BGR32P,
.memplanes = 1,
.colplanes = 1,
.mbus_code = MEDIA_BUS_FMT_RGB888_1X24,
}, {
.name = "BGR24",
.fourcc = V4L2_PIX_FMT_BGR24,
.depth = { 24 },
.color = MXC_ISI_OUT_FMT_RGB32P,
.memplanes = 1,
.colplanes = 1,
.mbus_code = MEDIA_BUS_FMT_BGR888_1X24,
}, {
.name = "YUYV-16",
.fourcc = V4L2_PIX_FMT_YUYV,
.depth = { 16 },
.color = MXC_ISI_OUT_FMT_YUV422_1P8P,
.memplanes = 1,
.colplanes = 1,
.mbus_code = MEDIA_BUS_FMT_YUYV8_1X16,
}, {
.name = "YUV32 (X-Y-U-V)",
.fourcc = V4L2_PIX_FMT_YUV32,
.depth = { 32 },
.color = MXC_ISI_OUT_FMT_YUV444_1P8,
.memplanes = 1,
.colplanes = 1,
.mbus_code = MEDIA_BUS_FMT_AYUV8_1X32,
}, {
.name = "NV12 (YUYV)",
.fourcc = V4L2_PIX_FMT_NV12,
.depth = { 8, 8 },
.color = MXC_ISI_OUT_FMT_YUV420_2P8P,
.memplanes = 2,
.colplanes = 2,
.mbus_code = MEDIA_BUS_FMT_YUYV8_1X16,
}, {
.name = "YUV444M (Y-U-V)",
.fourcc = V4L2_PIX_FMT_YUV444M,
.depth = { 8, 8, 8 },
.color = MXC_ISI_OUT_FMT_YUV444_3P8P,
.memplanes = 3,
.colplanes = 3,
.mbus_code = MEDIA_BUS_FMT_YUV8_1X24,
}, {
.name = "xBGR32",
.fourcc = V4L2_PIX_FMT_XBGR32,
.depth = { 32 },
.color = MXC_ISI_OUT_FMT_XRGB32,
.memplanes = 1,
.colplanes = 1,
.mbus_code = MEDIA_BUS_FMT_RGB888_1X24,
}, {
.name = "RAWRGB12",
//.name = "ABGR32", // modified by ryl
.fourcc = V4L2_PIX_FMT_SBGGR12,
//.fourcc = V4L2_PIX_FMT_ABGR32,
.depth = { 16 },
//.depth = { 32 },
.color = MXC_ISI_OUT_FMT_RAW12,
//.color = MXC_ISI_OUT_FMT_ARGB32,
.memplanes = 1,
.colplanes = 1,
.mbus_code = MEDIA_BUS_FMT_SBGGR12_1X12,
//.mbus_code = MEDIA_BUS_FMT_RGB888_1X24,
}
};

/*
* Pixel link input format
*/
struct mxc_isi_fmt mxc_isi_src_formats[] = {
{
.name = "RGB32",
.fourcc = V4L2_PIX_FMT_RGB32,
.depth = { 32 },
.memplanes = 1,
.colplanes = 1,
}, {
.name = "YUV32 (X-Y-U-V)",
.fourcc = V4L2_PIX_FMT_YUV32,
.depth = { 32 },
.memplanes = 1,
.colplanes = 1,
}, {
.name = "RAWRGB12 (SBGGR12)",
.fourcc = V4L2_PIX_FMT_SBGGR12,
.depth = { 16 },
.memplanes = 1,
.colplanes = 1,
}

};

static int mxc_isi_source_fmt_init(struct mxc_isi_cap_dev *isi_cap)
{

.....

src_fmt.format.code = MEDIA_BUS_FMT_SBGGR12_1X12;

...

 

========== drivers/staging/media/imx/imx8-mipi-csi2-sam.c ========

//#define DEFAULT_SCLK_CSIS_FREQ 166000000UL
#define DEFAULT_SCLK_CSIS_FREQ 135000000UL

static const struct csis_pix_format mipi_csis_formats[] = {
{
.code = MEDIA_BUS_FMT_YUYV8_2X8,
.fmt_reg = MIPI_CSIS_ISPCFG_FMT_YCBCR422_8BIT,
.data_alignment = 16,
}, {
.code = MEDIA_BUS_FMT_RGB888_1X24,
.fmt_reg = MIPI_CSIS_ISPCFG_FMT_RGB888,
.data_alignment = 24,
}, {
.code = MEDIA_BUS_FMT_UYVY8_2X8,
.code = MEDIA_BUS_FMT_YUYV8_2X8,
.fmt_reg = MIPI_CSIS_ISPCFG_FMT_YCBCR422_8BIT,
.data_alignment = 16,
}, {
.code = MEDIA_BUS_FMT_VYUY8_2X8,
.fmt_reg = MIPI_CSIS_ISPCFG_FMT_YCBCR422_8BIT,
.data_alignment = 16,
}, {
.code = MEDIA_BUS_FMT_SBGGR8_1X8,
.fmt_reg = MIPI_CSIS_ISPCFG_FMT_RAW8,
.data_alignment = 8,
}, {
.code = MEDIA_BUS_FMT_SBGGR12_1X12,
.fmt_reg = MIPI_CSIS_ISPCFG_FMT_RAW12,
.data_alignment = 16,
}
};

 

static void disp_mix_gasket_config(struct csi_state *state)
{...

case MEDIA_BUS_FMT_SBGGR12_1X12: 
case MEDIA_BUS_FMT_SGBRG12_1X12:
case MEDIA_BUS_FMT_SGRBG12_1X12:
case MEDIA_BUS_FMT_SRGGB12_1X12:
fmt_val = GASKET_0_CTRL_DATA_TYPE_RAW12;
printk(" disp_mix_gasket_config raw12 func:%s line:%d \n",__func__,__LINE__);
break;  

...

 

static int mipi_csis_subdev_init(struct v4l2_subdev *mipi_sd,
struct platform_device *pdev,
const struct v4l2_subdev_ops *ops)
{...

state->csis_fmt = &mipi_csis_formats[5];
state->format.code = mipi_csis_formats[5].code;

...

=============== Below is the content of dts file: ===============

---arch/arm64/boot/dts/freescale/imx8mn.dtsi

mipi_csi_1: csi@32e30000 {
compatible = "fsl,imx8mn-mipi-csi";
reg = <0x0 0x32e30000 0x0 0x10000>;
interrupts = <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
//clock-frequency = <333000000>;
clock-frequency = <135000000>;

.........

 

----------arch/arm64/boot/dts/freescale/imx8mn-ddr4-evk.dts

&i2c3 {
clock-frequency = <100000>;
pinctrl-names = "default", "gpio";
pinctrl-0 = <&pinctrl_i2c3>;
pinctrl-1 = <&pinctrl_i2c3_gpio>;
scl-gpios = <&gpio5 18 GPIO_ACTIVE_HIGH>;
sda-gpios = <&gpio5 19 GPIO_ACTIVE_HIGH>;
status = "okay";

 

addi903x_mipi_0: addi903x_mipi@64 {
compatible = "adi,addi903x";
reg = <0x64>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_csi_pwn>, <&pinctrl_csi_rst>;
clocks = <&clk IMX8MN_CLK_CLKO1>;
clock-names = "xclk";
assigned-clocks = <&clk IMX8MN_CLK_CLKO1>;
assigned-clock-parents = <&clk IMX8MN_CLK_24M>;
assigned-clock-rates = <135000000>; 
clock-frequency = <135000000>;
csi_id = <0>;
powerdown-gpios = <&gpio1 7 GPIO_ACTIVE_HIGH>;
reset-gpios = <&gpio1 6 GPIO_ACTIVE_LOW>;
mclk = <135000000>;
mclk_source = <0>;
mipi_csi;
status = "okay";
port {
addi903x_ep: endpoint {
remote-endpoint = <&mipi1_sensor_ep>;
data-lanes = <1 2>;
clocks-lanes = <0>;
//clocks-lanes = <1>;
};
};
};

 

&mipi_csi_1 {
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
port@0 {
reg = <0>;
mipi1_sensor_ep: endpoint {
remote-endpoint = <&addi903x_ep>;
data-lanes = <2>;
csis-hs-settle = <13>; 
csis-clk-settle = <2>;
csis-wclk; 
};
};
};

 

 

=========================================================

 

After boot, driver is initialized and DCAM20  is detected, /dev/video0 and /dev/media0 nodes are also created.

 

root@imx8mnevk:~# v4l2-ctl --list-formats
[ 3092.996443] in s power func:addi903x_s_power line:503
[ 3093.001759] addi903x 2-0064: s_power 1
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture Multiplanar

[0]: 'RGBP' (16-bit RGB[ 3093.011318] in s power func:addi903x_s_power line:503
5-6-5)
[1]: 'RGB3' (24-bit RGB[ 3093.018534] addi903x 2-0064: s_power 0
8-8-8)
[2]: 'BGR3' (24-bit BGR 8-8-8)
[3]: 'YUYV' (YUYV 4:2:2)
[4]: 'YUV4' (32-bit A/XYUV 8-8-8-8)
[5]: 'NV12' (Y/CbCr 4:2:0)
[6]: 'YM24' (Planar YUV 4:4:4 (N-C))
[7]: 'XR24' (32-bit BGRX 8-8-8-8)
[8]: 'BG12' (12-bit Bayer BGBG/GRGR)

 

root@imx8mnevk:~# v4l2-ctl --device /dev/video0 --list-formats-ext
[ 3169.480848] in s power func:addi903x_s_power line:503
[ 3169.486013] addi903x 2-0064: s_power 1
ioctl: VIDIOC_ENUM_FMT
Type: Vi[ 3169.490068] addi903x 2-0064: Mbus fs code 4119 index 0
[ 3169.498158] addi903x 2-0064: Mbus fs code 4106 index 0
[ 3169.503349] addi903x 2-0064: Mbus fs code 4115 index 0
[ 3169.508590] addi903x 2-0064: Mbus fs code 8209 index 0
deo Capture Multiplanar

[0]: [ 3169.513795] addi903x 2-0064: Mbus fs code 8215 index 0
'RGBP' (16-bit RGB 5-6-5)
[1]: [ 3169.521812] addi903x 2-0064: Mbus fs code 8209 index 0
'RGB3' (24-bit RGB 8-8-8)
[2]: [ 3169.529816] addi903x 2-0064: Mbus fs code 8229 index 0
'BGR3' (24-bit BGR 8-8-8)
[3]: [ 3169.537789] addi903x 2-0064: Mbus fs code 4106 index 0
'YUYV' (YUYV 4:2:2)
[4]: 'YUV4'[ 3169.545812] addi903x 2-0064: Mbus fs code 12296 index 0
(32-bit A/XYUV 8-8-8-8)
[5]: '[ 3169.553900] addi903x 2-0064: Mbus fs code 12296 index 1
NV12' (Y/CbCr 4:2:0)
[6]: 'YM24[ 3169.561982] addi903x 2-0064: Mbus fs code 12296 index 2
' (Planar YUV 4:4:4 (N-C))
[7]: 'XR24' (32-bit BGRX 8-8-8-8)
[ 3169.575055] in s power func:addi903x_s_power line:503
[8]: 'BG12' (12-bit Bayer BGBG/G[ 3169.580713] addi903x 2-0064: s_power 0
RGR)
Size: Discrete 640x480
Size: Discrete 668x750

 

root@imx8mnevk:~# v4l2-ctl -d /dev/video0 --all
[ 4260.569505] in s power func:addi903x_s_power line:503
[ 4260.574667] addi903x 2-0064: s_power 1
Driver Info:
Driver name : mxc-isi-cap
Card type : mxc-isi-cap[ 4260.584309] in s power func:addi903x_s_power line:503

Bus info : platform:32[ 4260.590847] addi903x 2-0064: s_power 0
e20000.isi:cap_devic
Driver version : 5.4.3
Capabilities : 0x84201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Media Driver Info:
Driver name : mxc-md
Model : FSL Capture Media Device
Serial :
Bus info :
Media version : 5.4.3
Hardware revision: 0x00000000 (0)
Driver version : 5.4.3
Interface Info:
ID : 0x03000014
Type : V4L Video
Entity Info:
ID : 0x00000012 (18)
Name : mxc_isi.0.capture
Function : V4L2 I/O
Pad 0x01000013 : 0: Sink
Link 0x02000021: from remote pad 0x100000e of entity 'mxc_isi.0': Data, Enabled
Priority: 2
Format Video Capture Multiplanar:
Width/Height : 640/480
Pixel Format : 'BG12' (12-bit Bayer BGBG/GRGR)
Field : None
Number of planes : 1
Flags :
Colorspace : JPEG
Transfer Function : Default
YCbCr/HSV Encoding: Default
Quantization : Default
Plane 0 :
Bytes per Line : 1280
Size Image : 614400

User Controls

horizontal_flip 0x00980914 (bool) : default=0 value=0
vertical_flip 0x00980915 (bool) : default=0 value=0
alpha_component 0x00980929 (int) : min=0 max=255 step=1 default=0 value=0
root@imx8mnevk:~#

root@imx8mnevk:~# media-ctl -d /dev/media0 -p
Media controller API version 5.4.[ 4313.850366] mxc_isi.0: mxc_isi_subdev_get_fmt, Pad is not support now!
[ 4313.858993] addi903x 2-0064: addi903x_open: Enter
[ 4313.863880] entity_init_cfg fun:addi903x_entity_init_cfg line:786
3

Media device information
--[ 4313.870142] addi903x 2-0064: addi903x_entity_init_cfg: Enter
----------------------
driver [ 4313.878614] addi903x 2-0064: set_fmt: 0 640x480
[ 4313.885996] after entity init cfg ret=0, func:addi903x_open, line:846
mxc-md
model FS[ 4313.892558] addi903x 2-0064: get_fmt which 1
L Capture Media Device
serial [ 4313.899695] addi903x 2-0064: get_fmt: 3008 640x480

bus info
hw rev[ 4313.907402] addi903x 2-0064: get_selection 2
ision 0x0
driver version 5.[ 4313.914494] addi903x 2-0064: get_selection 0
4.3

Device topology
- entity [ 4313.921617] addi903x 2-0064: get_selection 258
1: mxc_isi.0 (16 pads, 2 links)
[ 4313.928897] addi903x 2-0064: get_selection 256
type V4L2 subdev subtype Unknown flags 0
device node name /dev/v4l-subdev0
pad0: Sink
[fmt:unknown/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
<- "mxc-mipi-csi2.0":4 [ENABLED]
pad1: Sink
[fmt:unknown/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
pad2: Sink
[fmt:unknown/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
pad3: Sink
[fmt:unknown/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
pad4: Sink
[fmt:unknown/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
pad5: Sink
[fmt:unknown/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
pad6: Sink
[fmt:unknown/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
pad7: Sink
[fmt:unknown/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
pad8: Sink
[fmt:unknown/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
pad9: Sink
[fmt:unknown/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
pad10: Sink
[fmt:unknown/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
pad11: Sink
[fmt:unknown/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
pad12: Source
[fmt:SBGGR12_1X12/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
-> "mxc_isi.0.capture":0 [ENABLED]
pad13: Source
[fmt:SBGGR12_1X12/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
pad14: Source
[fmt:SBGGR12_1X12/640x480 colorspace:jpeg
crop.bounds:(0,0)/640x480
crop:(0,0)/640x480
compose.bounds:(0,0)/640x480
compose:(0,0)/640x480]
pad15: Sink

- entity 18: mxc_isi.0.capture (1 pad, 1 link)
type Node subtype V4L flags 0
device node name /dev/video0
pad0: Sink
<- "mxc_isi.0":12 [ENABLED]

- entity 22: mxc-mipi-csi2.0 (8 pads, 2 links)
type Node subtype V4L flags 0
device node name /dev/v4l-subdev1
pad0: Sink
<- "addi903x 2-0064":0 [ENABLED,IMMUTABLE]
pad1: Sink
pad2: Sink
pad3: Sink
pad4: Source
-> "mxc_isi.0":0 [ENABLED]
pad5: Source
pad6: Source
pad7: Source

- entity 31: addi903x 2-0064 (1 pad, 1 link)
type V4L2 subdev subtype Sensor flags 0
device node name /dev/v4l-subdev2
pad0: Source
[fmt:SBGGR12_1X12/640x480 field:none colorspace:srgb xfer:srgb ycbcr:601 quantization:full-range
crop:(0,0)/640x480]
-> "mxc-mipi-csi2.0":0 [ENABLED,IMMUTABLE]

root@imx8mnevk:~#

 

It is stuck after I try to capture one frame and create raw file as below:

root@imx8mnevk:~# v4l2-ctl -d /dev/video0 --verbose --set-fmt-video=width=640,height=480,pixelformat=BG12 --stream-mmap --stream-count=1 --stream-to=raw12_640x480.raw
[ 3337.077267] in s power func:addi903x_s_power line:503
[ 3337.082444] addi903x 2-0064: s_power 1
VIDIOC_QUERYCAP: ok
VIDIOC_G_FMT[ 3337.089132] addi903x 2-0064: set_fmt: 3008 640x480
[ 3337.094290] King mipi_csis_set_fmt MEDIA_BUS_FMT_SBGGR12_1X12 mipi_csis_set_fmt 992
[ 3337.102180] addi903x 2-0064: get_fmt which 1
[ 3337.106495] addi903x 2-0064: get_fmt: 3008 640x480
: ok
VIDIOC_S_FMT: ok
Format Video Capture Multiplanar:
Widt[ 3337.116327] bypass csc
h/Height : 640/480
Pixel F[ 3337.119209] input fmt BG12
ormat : 'BG12' (12-bit Bayer[ 3337.124791] output fmt BG12
BGBG/GRGR)
Field : None
Number of planes : 1
Flags :
Colorspace : JPEG
Transfer Function : Default
YCbCr/HSV Encoding: Default
Quantization : Default
Plane 0 :
Bytes per Line : 1280
Size Image : 614400
[ 3337.458148] addi903x 2-0064: stream 1
[ 3337.461830] mipi_csis start stream began func;mipi_csis_start_stream line:857
[ 3337.469032] disp_mix_gasket_config raw12 func:disp_mix_gasket_config line:820
[ 3337.476489] mipi_csis start stream before sleep func;mipi_csis_start_stream line:866
[ 3337.497463] mipi_csis start stream end sleep func;mipi_csis_start_stream line:869

 

-----------  drivers/staging/media/imx/imx8-mipi-csi2-sam.c -----

static void mipi_csis_start_stream(struct csi_state *state)
856 {
857 printk("mipi_csis start stream began func;%s line:%d\n",__func__,__LINE__);
858 mipi_csis_sw_reset(state);
859
860 disp_mix_gasket_config(state);
861 mipi_csis_set_params(state);
862
863 mipi_csis_system_enable(state, true);
864 disp_mix_gasket_enable(state, true);
865 mipi_csis_enable_interrupts(state, true);
866 printk("mipi_csis start stream before sleep func;%s line:%d\n",__func__,__LINE__);
867
868 msleep(5);
869 printk("mipi_csis start stream end sleep func;%s line:%d\n",__func__,__LINE__);
870
871 }

-------------------

 

 

Anything I missed or configured wrong? Can somebody give me some advice? 

Should I modify the mipi csi clk in the i.mx8mn.dtsi file? 

Why it hang ? 

Thanks & Best Regards,

Michael

Attachments

Outcomes