一.硬件原理图
mipi摄像头硬件确认点:
1.供电:5V,2.8V,1.2V,1.8V,reset脚(硬拉3.3,上电的时候从低到高),pwron脚外接
3.3V。
2,时钟:MCLKOUT是24兆时钟。
3.4组差分mipi线。mipi的data线的波形为方波。
二.驱动移植
RK提供的默认sdk里面已经将支持的所有摄像头驱动都添加到了内核,所以不需要移植该驱动了。
需确认下移植驱动对应的一些信息
源程序
kernel/drivers/media/i2c/imx586.c
kernel/drivers/media/i2c/Makefile
kernel/drivers/media/i2c/Kconfig
kernel/arch/arm64/configs/rockchip_linxu_defconfig
Makefile脚本
obj-$(CONFIG_VIDEO_IMX415) += imx586.oconfig VIDEO_IMX586tristate "Sony IMX586 sensor support"depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_APIdepends on MEDIA_CAMERA_SUPPORThelpThis is a Video4Linux2 sensor driver for the SonyIMX415 camera.To compile this driver as a module, choose M here: themodule will be called imx586.
- 驱动对应的宏开关
CONFIG_VIDEO_IMX586=y
添加设备树文件:
&i2c5 {status = "okay";pinctrl-names = "default";pinctrl-0 = <&i2c5m0_xfer>;imx586: imx586@1a {compatible = "sony,imx586";reg = <0x10>; //插摄像头看iic5上出现的新设备后填入clocks = <&cru CLK_MIPI_CAMARAOUT_M1>;clock-names = "xvclk";pinctrl-names = "default";pinctrl-0 = <&mipim0_camera3_clk>;//需要和硬件确认是复用的哪个时钟,确认可以量到波形power-domains = <&power RK3588_PD_VI>;//reset-gpios = <&gpio3 RK_PC7 GPIO_ACTIVE_HIGH>;//现在硬件上是直接拉高,所以不用配//avdd-supply = <&vcc_mipidphy0>;//供电也是直接供电,所以不用配rockchip,camera-module-index = <0>;rockchip,camera-module-facing = "back";rockchip,camera-module-name = "default";rockchip,camera-module-lens-name = "default";port {imx586_out0: endpoint {remote-endpoint = <&mipidphy0_in_ucam0>;data-lanes = <1 2 3 4>;};};};
};&csi2_dphy0 {status = "okay";ports {#address-cells = <1>;#size-cells = <0>;port@0 {reg = <0>;#address-cells = <1>;#size-cells = <0>;mipidphy0_in_ucam0: endpoint@1 {reg = <1>;remote-endpoint = <&imx586_out0>;data-lanes = <1 2 3 4>;};};port@1 {reg = <1>;#address-cells = <1>;#size-cells = <0>;csidphy0_out: endpoint@0 {reg = <0>;remote-endpoint = <&mipi2_csi2_input>;};};};
};&csi2_dphy0_hw {status = "okay";
};&mipi2_csi2 {status = "okay";ports {#address-cells = <1>;#size-cells = <0>;port@0 {reg = <0>;#address-cells = <1>;#size-cells = <0>;mipi2_csi2_input: endpoint@1 {reg = <1>;remote-endpoint = <&csidphy0_out>;};};port@1 {reg = <1>;#address-cells = <1>;#size-cells = <0>;mipi2_csi2_output: endpoint@0 {reg = <0>;remote-endpoint = <&cif_mipi2_in0>;};};};
};&rkcif {status = "okay";
};&rkcif_mipi_lvds2 {status = "okay";port {cif_mipi2_in0: endpoint {remote-endpoint = <&mipi2_csi2_output>;};};
};&rkcif_mipi_lvds2_sditf {status = "okay";port {mipi_lvds2_sditf: endpoint {remote-endpoint = <&isp0_vir0>;};};
};&rkcif_mmu {status = "okay";
};&rkisp_unite {status = "okay";
};&rkisp_unite_mmu {status = "okay";
};&rkisp0_vir0 {status = "okay";/* dual isp process image case* other rkisp hw and virtual nodes should disabled*/rockchip,hw = <&rkisp_unite>;port {#address-cells = <1>;#size-cells = <0>;isp0_vir0: endpoint@0 {reg = <0>;remote-endpoint = <&mipi_lvds2_sditf>;};};
};
三.驱动调试
把驱动代码和设备树文件添加进去后就可以开始调试了。
使用i2ctool工具查看i2c5,发现有2个新的设别:0x10,0x50,猜测其中一个是senser,另一个可能是sensor的马达地址,尝试修改sensor的地址为0x10或者0x50看imx586能不能进probe函数。
当修改imx586的地址为ox10的时候,看imx586已经进了probe函数了。
从log可以看出imx586已经进了probe函数,但是并没有识别到sensor。
这时候,需要确认mipi摄像头上的供电是否正常,时钟是否正常。
经确认是sensor的一路供电没有,供电正常后可以设别到sensor。
到了这一步,可以确认,iic设备已经可以设别到sensor了,并挂载在iic5上面。
四.查看拓扑
rk3588_t:/ # media-ctl -d /dev/media0 -p
Opening media device /dev/media0
Enumerating entities
Found 14 entities
Enumerating pads and links
Media controller API version 0.0.177Media device information
------------------------
driver rkcif
model rkcif-mipi-lvds2
serial
bus info
hw revision 0x0
driver version 0.0.177Device topology
- entity 1: stream_cif_mipi_id0 (1 pad, 11 links)type Node subtype V4Ldevice node name /dev/video0pad0: Sink<- "rockchip-mipi-csi2":1 [ENABLED]<- "rockchip-mipi-csi2":2 []<- "rockchip-mipi-csi2":3 []<- "rockchip-mipi-csi2":4 []<- "rockchip-mipi-csi2":5 []<- "rockchip-mipi-csi2":6 []<- "rockchip-mipi-csi2":7 []<- "rockchip-mipi-csi2":8 []<- "rockchip-mipi-csi2":9 []<- "rockchip-mipi-csi2":10 []<- "rockchip-mipi-csi2":11 []- entity 5: stream_cif_mipi_id1 (1 pad, 11 links)type Node subtype V4Ldevice node name /dev/video1pad0: Sink<- "rockchip-mipi-csi2":1 []<- "rockchip-mipi-csi2":2 [ENABLED]<- "rockchip-mipi-csi2":3 []<- "rockchip-mipi-csi2":4 []<- "rockchip-mipi-csi2":5 []<- "rockchip-mipi-csi2":6 []<- "rockchip-mipi-csi2":7 []<- "rockchip-mipi-csi2":8 []<- "rockchip-mipi-csi2":9 []<- "rockchip-mipi-csi2":10 []<- "rockchip-mipi-csi2":11 []- entity 9: stream_cif_mipi_id2 (1 pad, 11 links)type Node subtype V4Ldevice node name /dev/video2pad0: Sink<- "rockchip-mipi-csi2":1 []<- "rockchip-mipi-csi2":2 []<- "rockchip-mipi-csi2":3 [ENABLED]<- "rockchip-mipi-csi2":4 []<- "rockchip-mipi-csi2":5 []<- "rockchip-mipi-csi2":6 []<- "rockchip-mipi-csi2":7 []<- "rockchip-mipi-csi2":8 []<- "rockchip-mipi-csi2":9 []<- "rockchip-mipi-csi2":10 []<- "rockchip-mipi-csi2":11 []- entity 13: stream_cif_mipi_id3 (1 pad, 11 links)type Node subtype V4Ldevice node name /dev/video3pad0: Sink<- "rockchip-mipi-csi2":1 []<- "rockchip-mipi-csi2":2 []<- "rockchip-mipi-csi2":3 []<- "rockchip-mipi-csi2":4 [ENABLED]<- "rockchip-mipi-csi2":5 []<- "rockchip-mipi-csi2":6 []<- "rockchip-mipi-csi2":7 []<- "rockchip-mipi-csi2":8 []<- "rockchip-mipi-csi2":9 []<- "rockchip-mipi-csi2":10 []<- "rockchip-mipi-csi2":11 []- entity 17: rkcif_scale_ch0 (1 pad, 11 links)type Node subtype V4Ldevice node name /dev/video4pad0: Sink<- "rockchip-mipi-csi2":1 []<- "rockchip-mipi-csi2":2 []<- "rockchip-mipi-csi2":3 []<- "rockchip-mipi-csi2":4 []<- "rockchip-mipi-csi2":5 [ENABLED]<- "rockchip-mipi-csi2":6 []<- "rockchip-mipi-csi2":7 []<- "rockchip-mipi-csi2":8 []<- "rockchip-mipi-csi2":9 []<- "rockchip-mipi-csi2":10 []<- "rockchip-mipi-csi2":11 []- entity 21: rkcif_scale_ch1 (1 pad, 11 links)type Node subtype V4Ldevice node name /dev/video5pad0: Sink<- "rockchip-mipi-csi2":1 []<- "rockchip-mipi-csi2":2 []<- "rockchip-mipi-csi2":3 []<- "rockchip-mipi-csi2":4 []<- "rockchip-mipi-csi2":5 []<- "rockchip-mipi-csi2":6 [ENABLED]<- "rockchip-mipi-csi2":7 []<- "rockchip-mipi-csi2":8 []<- "rockchip-mipi-csi2":9 []<- "rockchip-mipi-csi2":10 []<- "rockchip-mipi-csi2":11 []- entity 25: rkcif_scale_ch2 (1 pad, 11 links)type Node subtype V4Ldevice node name /dev/video6pad0: Sink<- "rockchip-mipi-csi2":1 []<- "rockchip-mipi-csi2":2 []<- "rockchip-mipi-csi2":3 []<- "rockchip-mipi-csi2":4 []<- "rockchip-mipi-csi2":5 []<- "rockchip-mipi-csi2":6 []<- "rockchip-mipi-csi2":7 [ENABLED]<- "rockchip-mipi-csi2":8 []<- "rockchip-mipi-csi2":9 []<- "rockchip-mipi-csi2":10 []<- "rockchip-mipi-csi2":11 []- entity 29: rkcif_scale_ch3 (1 pad, 11 links)type Node subtype V4Ldevice node name /dev/video7pad0: Sink<- "rockchip-mipi-csi2":1 []<- "rockchip-mipi-csi2":2 []<- "rockchip-mipi-csi2":3 []<- "rockchip-mipi-csi2":4 []<- "rockchip-mipi-csi2":5 []<- "rockchip-mipi-csi2":6 []<- "rockchip-mipi-csi2":7 []<- "rockchip-mipi-csi2":8 [ENABLED]<- "rockchip-mipi-csi2":9 []<- "rockchip-mipi-csi2":10 []<- "rockchip-mipi-csi2":11 []- entity 33: rkcif_tools_id0 (1 pad, 11 links)type Node subtype V4Ldevice node name /dev/video8pad0: Sink<- "rockchip-mipi-csi2":1 []<- "rockchip-mipi-csi2":2 []<- "rockchip-mipi-csi2":3 []<- "rockchip-mipi-csi2":4 []<- "rockchip-mipi-csi2":5 []<- "rockchip-mipi-csi2":6 []<- "rockchip-mipi-csi2":7 []<- "rockchip-mipi-csi2":8 []<- "rockchip-mipi-csi2":9 [ENABLED]<- "rockchip-mipi-csi2":10 []<- "rockchip-mipi-csi2":11 []- entity 37: rkcif_tools_id1 (1 pad, 11 links)type Node subtype V4Ldevice node name /dev/video9pad0: Sink<- "rockchip-mipi-csi2":1 []<- "rockchip-mipi-csi2":2 []<- "rockchip-mipi-csi2":3 []<- "rockchip-mipi-csi2":4 []<- "rockchip-mipi-csi2":5 []<- "rockchip-mipi-csi2":6 []<- "rockchip-mipi-csi2":7 []<- "rockchip-mipi-csi2":8 []<- "rockchip-mipi-csi2":9 []<- "rockchip-mipi-csi2":10 [ENABLED]<- "rockchip-mipi-csi2":11 []- entity 41: rkcif_tools_id2 (1 pad, 11 links)type Node subtype V4Ldevice node name /dev/video10pad0: Sink<- "rockchip-mipi-csi2":1 []<- "rockchip-mipi-csi2":2 []<- "rockchip-mipi-csi2":3 []<- "rockchip-mipi-csi2":4 []<- "rockchip-mipi-csi2":5 []<- "rockchip-mipi-csi2":6 []<- "rockchip-mipi-csi2":7 []<- "rockchip-mipi-csi2":8 []<- "rockchip-mipi-csi2":9 []<- "rockchip-mipi-csi2":10 []<- "rockchip-mipi-csi2":11 [ENABLED]- entity 45: rockchip-mipi-csi2 (12 pads, 122 links)type V4L2 subdev subtype Unknowndevice node name /dev/v4l-subdev0pad0: Sink[fmt:SRGGB10/4000x3000crop.bounds:(0,0)/4000x3000crop:(0,0)/4000x3000]<- "rockchip-csi2-dphy0":1 [ENABLED]pad1: Source-> "stream_cif_mipi_id0":0 [ENABLED]-> "stream_cif_mipi_id1":0 []-> "stream_cif_mipi_id2":0 []-> "stream_cif_mipi_id3":0 []-> "rkcif_scale_ch0":0 []-> "rkcif_scale_ch1":0 []-> "rkcif_scale_ch2":0 []-> "rkcif_scale_ch3":0 []-> "rkcif_tools_id0":0 []-> "rkcif_tools_id1":0 []-> "rkcif_tools_id2":0 []pad2: Source-> "stream_cif_mipi_id0":0 []-> "stream_cif_mipi_id1":0 [ENABLED]-> "stream_cif_mipi_id2":0 []-> "stream_cif_mipi_id3":0 []-> "rkcif_scale_ch0":0 []-> "rkcif_scale_ch1":0 []-> "rkcif_scale_ch2":0 []-> "rkcif_scale_ch3":0 []-> "rkcif_tools_id0":0 []-> "rkcif_tools_id1":0 []-> "rkcif_tools_id2":0 []pad3: Source-> "stream_cif_mipi_id0":0 []-> "stream_cif_mipi_id1":0 []-> "stream_cif_mipi_id2":0 [ENABLED]-> "stream_cif_mipi_id3":0 []-> "rkcif_scale_ch0":0 []-> "rkcif_scale_ch1":0 []-> "rkcif_scale_ch2":0 []-> "rkcif_scale_ch3":0 []-> "rkcif_tools_id0":0 []-> "rkcif_tools_id1":0 []-> "rkcif_tools_id2":0 []pad4: Source-> "stream_cif_mipi_id0":0 []-> "stream_cif_mipi_id1":0 []-> "stream_cif_mipi_id2":0 []-> "stream_cif_mipi_id3":0 [ENABLED]-> "rkcif_scale_ch0":0 []-> "rkcif_scale_ch1":0 []-> "rkcif_scale_ch2":0 []-> "rkcif_scale_ch3":0 []-> "rkcif_tools_id0":0 []-> "rkcif_tools_id1":0 []-> "rkcif_tools_id2":0 []pad5: Source-> "stream_cif_mipi_id0":0 []-> "stream_cif_mipi_id1":0 []-> "stream_cif_mipi_id2":0 []-> "stream_cif_mipi_id3":0 []-> "rkcif_scale_ch0":0 [ENABLED]-> "rkcif_scale_ch1":0 []-> "rkcif_scale_ch2":0 []-> "rkcif_scale_ch3":0 []-> "rkcif_tools_id0":0 []-> "rkcif_tools_id1":0 []-> "rkcif_tools_id2":0 []pad6: Source-> "stream_cif_mipi_id0":0 []-> "stream_cif_mipi_id1":0 []-> "stream_cif_mipi_id2":0 []-> "stream_cif_mipi_id3":0 []-> "rkcif_scale_ch0":0 []-> "rkcif_scale_ch1":0 [ENABLED]-> "rkcif_scale_ch2":0 []-> "rkcif_scale_ch3":0 []-> "rkcif_tools_id0":0 []-> "rkcif_tools_id1":0 []-> "rkcif_tools_id2":0 []pad7: Source-> "stream_cif_mipi_id0":0 []-> "stream_cif_mipi_id1":0 []-> "stream_cif_mipi_id2":0 []-> "stream_cif_mipi_id3":0 []-> "rkcif_scale_ch0":0 []-> "rkcif_scale_ch1":0 []-> "rkcif_scale_ch2":0 [ENABLED]-> "rkcif_scale_ch3":0 []-> "rkcif_tools_id0":0 []-> "rkcif_tools_id1":0 []-> "rkcif_tools_id2":0 []pad8: Source-> "stream_cif_mipi_id0":0 []-> "stream_cif_mipi_id1":0 []-> "stream_cif_mipi_id2":0 []-> "stream_cif_mipi_id3":0 []-> "rkcif_scale_ch0":0 []-> "rkcif_scale_ch1":0 []-> "rkcif_scale_ch2":0 []-> "rkcif_scale_ch3":0 [ENABLED]-> "rkcif_tools_id0":0 []-> "rkcif_tools_id1":0 []-> "rkcif_tools_id2":0 []pad9: Source-> "stream_cif_mipi_id0":0 []-> "stream_cif_mipi_id1":0 []-> "stream_cif_mipi_id2":0 []-> "stream_cif_mipi_id3":0 []-> "rkcif_scale_ch0":0 []-> "rkcif_scale_ch1":0 []-> "rkcif_scale_ch2":0 []-> "rkcif_scale_ch3":0 []-> "rkcif_tools_id0":0 [ENABLED]-> "rkcif_tools_id1":0 []-> "rkcif_tools_id2":0 []pad10: Source-> "stream_cif_mipi_id0":0 []-> "stream_cif_mipi_id1":0 []-> "stream_cif_mipi_id2":0 []-> "stream_cif_mipi_id3":0 []-> "rkcif_scale_ch0":0 []-> "rkcif_scale_ch1":0 []-> "rkcif_scale_ch2":0 []-> "rkcif_scale_ch3":0 []-> "rkcif_tools_id0":0 []-> "rkcif_tools_id1":0 [ENABLED]-> "rkcif_tools_id2":0 []pad11: Source-> "stream_cif_mipi_id0":0 []-> "stream_cif_mipi_id1":0 []-> "stream_cif_mipi_id2":0 []-> "stream_cif_mipi_id3":0 []-> "rkcif_scale_ch0":0 []-> "rkcif_scale_ch1":0 []-> "rkcif_scale_ch2":0 []-> "rkcif_scale_ch3":0 []-> "rkcif_tools_id0":0 []-> "rkcif_tools_id1":0 []-> "rkcif_tools_id2":0 [ENABLED]- entity 58: rockchip-csi2-dphy0 (2 pads, 2 links)type V4L2 subdev subtype Unknowndevice node name /dev/v4l-subdev1pad0: Sink[fmt:SRGGB10/4000x3000]<- "m00_b_imx586 5-0010":0 [ENABLED]pad1: Source-> "rockchip-mipi-csi2":0 [ENABLED]- entity 63: m00_b_imx586 5-0010 (1 pad, 1 link)type V4L2 subdev subtype Sensordevice node name /dev/v4l-subdev2pad0: Source[fmt:SRGGB10/4000x3000]-> "rockchip-csi2-dphy0":0 [ENABLED]
m00_b_imx586 5-0010 (1 pad, 1 link):表示imx586实在mipi0上,挂载在iic5,。
fmt:SRGGB10/4000x3000 表示格式为GB10,分辨率为4000*3000.
拓扑通路为:
m00_b_imx586 -> rockchip-csi2-dphy0 -> rockchip-mipi-csi2 -> stream_cif_mipi_id0 -> video0
五.抓取图像
命令:
v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=BG10 \--stream-mmap=3 \--stream-skip=3 \--stream-to=/tmp/cif888.out \--stream-count=1 \--stream-poll
[ 370.297011] mipi2-csi2 ERR1:0x10000000 (ecc2)
[ 370.297022] mipi2-csi2 ERR1:0x10000000 (ecc2)
[ 370.297033] mipi2-csi2 ERR1:0x10000000 (ecc2)
[ 370.297043] mipi2-csi2 ERR1:0x10000000 (ecc2)
[ 370.297054] mipi2-csi2 ERR1:0x10000000 (ecc2)
[ 370.297065] mipi2-csi2 ERR1:0x10000000 (ecc2)
[ 370.297075] mipi2-csi2 ERR1:0x10000000 (ecc2)
[ 370.297086] mipi2-csi2 ERR1:0x10000000 (ecc2)
[ 370.297097] mipi2-csi2 ERR1:0x10000000 (ecc2)
[ 370.297108] mipi2-csi2 ERR1:0x10000000 (ecc2)
[ 370.297119] mipi2-csi2 ERR1:0x10000000 (ecc2)
[ 370.297130] mipi2-csi2 ERR1:0x10000000 (ecc2)
[ 370.297141] mipi2-csi2 ERR1:0x10000000 (ecc2)
[ 370.297154] mipi2-csi2 ERR1:0x10000000 (ecc2)
发现一直报mipi2-csi2 ERR。
原因:一般报这种错误为物理层解析不到mipi协议。
排查:可能mipi4组差分线出现虚焊假焊,可能mipi插线没有整理好,也可能mipi波形不对。
mipi data波形:为方波