我们常见的摄像头接口一般有MIPI、USB、DVP等等,但是MIPI摄像头受限于高速信号的传输距离问题,导致走线不能太长,这样在安防监控领域、车载等领域,使用就很受限,因此会引入一些技术延长摄像头的数据传输距离,例如之前文章所提到的serdes,本文主要介绍一下AHD摄像头对接RK3588的调试。
目录
(1)AHD摄像头
(2)转接芯片
(3)AHD转MIPI调试
①nvp6188_g_mbus_config接口
②bus fmt配置
③DTS配置
(4)AHD转BT1120
①驱动nvp6158_g_mbus_config配置
②nvp6158_querystd接口配置
③DTS配置
④pinctrl的配置
(5)APK预览
(6)抓图指令调试
(1)AHD摄像头
网上有很多关于AHD摄像头的介绍,这里不再赘述,这里提一下,AHD摄像头跟我前文介绍的serdes有一点类似,有一个目的是提高了传输的距离。常用于车载、安防等领域。
AHD是模拟摄像头,因此需要AD转换芯片来转换,输出数字信号给到主控进行接收。
(2)转接芯片
上述AHD摄像头需要转接芯片转成数字信号输出,一般是AHD转MIPI或者AHD转BT656/BT1120并口输出。前级摄像头有的厂家也会兼容TVI、CVBS等信号。
CVBS可以参考前一篇文章的介绍。
这篇文章主要给大家分享一下,AHD摄像头转MIPI或者BT1120转接芯片的调试。
常见的转接芯片有:NVP系列的NVP6188/NVP6324/NVP6158C
TP系列的:TP2815/TP9950/TP9930/TP2825等
RN系列的:RN6854/RN6752等等
这里我们以介绍调试N6为例。
(3)AHD转MIPI调试
同样的转接芯片的驱动也是基于V4l2框架的,因为主要介绍一下相关接口的配置即可。
①nvp6188_g_mbus_config接口
该接口配置主要配置了MIPI接口,4lane模式,以及4路虚拟通道的类型。如果需要接多路摄像头的话,需要配置这个。
static int nvp6188_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
struct v4l2_mbus_config *cfg)
{
cfg->type = V4L2_MBUS_CSI2_DPHY;
cfg->flags = V4L2_MBUS_CSI2_4_LANE |
V4L2_MBUS_CSI2_CHANNELS;
return 0;
}
②bus fmt配置
图像格式一般都是YUV422的类型。配置如下:
.bus_fmt = MEDIA_BUS_FMT_UYVY8_2X8,
其他的配置其他文章也都有描述,这里不再赘述。
③DTS配置
dts配置基本与camera配置相差无几,这里直接贴一下:
&csi2_dphy0_hw {
status = "okay";
};
&csi2_dphy0 {
status = "okay";
ports {
#address-cells = <1>;
#size-cells = <0>;
port@0 {
reg = <0>;
#address-cells = <1>;
#size-cells = <0>;
mipi_dphy0_in_nvp6188: endpoint@1 {
reg = <1>;
remote-endpoint = <&nvp6188_out>;
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>;
};
};
};
};
&i2c7 {
status = "okay";
nvp6188: nvp6188@31 {
compatible = "nvp6188";
status = "okay";
reg = <0x31>;
clocks = <&cru CLK_MIPI_CAMARAOUT_M2>;
clock-names = "xvclk";
power-domains = <&power RK3588_PD_VI>;
pinctrl-names = "default";
pinctrl-0 = <&mipim1_camera1_clk>;
rockchip,grf = <&sys_grf>;
/*power-gpios = <&gpio3 RK_PC6 GPIO_ACTIVE_HIGH>;*/
reset-gpios = <&gpio3 RK_PB3 GPIO_ACTIVE_HIGH>;
rockchip,camera-module-index = <0>;
rockchip,camera-module-facing = "back";
rockchip,camera-module-name = "nvp6188";
rockchip,camera-module-lens-name = "nvp6188";
port {
nvp6188_out: endpoint {
remote-endpoint = <&mipi_dphy0_in_nvp6188>;
data-lanes = <1 2 3 4>;
};
};
};
};
&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_in>;
};
};
};
};
&rkcif_mipi_lvds2 {
status = "okay";
/* parameters for do cif reset detecting:
* index0: monitor mode,
0 for idle,
1 for continue,
2 for trigger,
3 for hotplug (for nextchip)
* index1: the frame id to start timer,
min is 2
* index2: frame num of monitoring cycle
* index3: err time for keep monitoring
after finding out err (ms)
* index4: csi2 err reference val for resetting
*/
rockchip,cif-monitor = <3 2 1 1000 5>;
port {
cif_mipi2_in: endpoint {
remote-endpoint = <&mipi2_csi2_output>;
};
};
};
&rkcif {
status = "okay";
rockchip,android-usb-camerahal-enable;
// memory-region = <&cif_reserved>;
};
&rkcif_mmu {
status = "okay";
};
需要注意的只有rockchip,android-usb-camerahal-enable;这个配置,该配置是在多路摄像头的时候使用,可以让应用注册4路摄像头,从而apk可以同时预览4路。如果是自行开发应用,使用v4l2从video节点直接取数据流的话,那么可以不用。
(4)AHD转BT1120
AHD 转BT1120的调试,这里介绍一下NVP6158C的调试
①驱动nvp6158_g_mbus_config配置
这个配置与MIPI的配置略有不同,需要注意区分,其中极性一定需要配置。
static int nvp6158_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad,
struct v4l2_mbus_config *cfg)
{
struct nvp6158 *nvp6158 = to_nvp6158(sd);
cfg->type = V4L2_MBUS_BT656;
if (nvp6158->dual_edge == 1) {
cfg->flags = RKMODULE_CAMERA_BT656_CHANNELS |
V4L2_MBUS_PCLK_SAMPLE_RISING |
V4L2_MBUS_PCLK_SAMPLE_FALLING;
} else {
cfg->flags = RKMODULE_CAMERA_BT656_CHANNELS |
V4L2_MBUS_PCLK_SAMPLE_RISING;
}
return 0;
}
②nvp6158_querystd接口配置
该接口一定需要配置,其中BT1120需要声明为V4L2_STD_ATSC
static int nvp6158_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
{
struct nvp6158 *nvp6158 = to_nvp6158(sd);
if ((nvp6158->mode > BT656I_TEST_MODES) &&
(nvp6158->mode < NVP6158_DVP_MODES_END)) {
/* for vicap detect bt1120 */
*std = V4L2_STD_ATSC;
} else {
*std = V4L2_STD_PAL;
}
return 0;
}
③DTS配置
dts配置参考如下:
&i2c2 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&i2c2m4_xfer>;
nvp6158: nvp6158@30 {
compatible = "nvp6158-v4l2";
status = "okay";
reg = <0x30>;
clocks = <&cru CLK_CIFOUT_OUT>;
clock-names = "xvclk";
power-domains = <&power RK3588_PD_VI>;
pinctrl-names = "default";
pinctrl-0 = <&cif_clk &cif_dvp_clk &cif_dvp_bus8 &cif_dvp_bus16>;
// pwr-gpios = <&gpio1 RK_PA6 GPIO_ACTIVE_HIGH>;
pwr2-gpios = <&gpio1 RK_PA5 GPIO_ACTIVE_HIGH>;
rst-gpios = <&gpio1 RK_PA3 GPIO_ACTIVE_HIGH>;
// rst2-gpios = <&gpio3 RK_PC1 GPIO_ACTIVE_HIGH>;
// pwdn-gpios = <&gpio1 RK_PA4 GPIO_ACTIVE_HIGH>;
// pwdn2-gpios = <&gpio4 RK_PA6 GPIO_ACTIVE_HIGH>;
rockchip,camera-module-index = <0>;
rockchip,camera-module-facing = "back";
rockchip,camera-module-name = "default";
rockchip,camera-module-lens-name = "default";
rockchip,dvp_mode = "BT1120"; //BT656 or BT1120 or BT656_TEST
rockchip,channel_nums = <4>; //channel nums, 1/2/4
rockchip,dual_edge = <1>; // pclk dual edge, 0/1
rockchip,default_rect= <1920 1080>; // default resolution
port {
nvp6158_out: endpoint {
remote-endpoint = <&dvp_in_bcam1>;
};
};
};
};
&rkcif {
status = "okay";
};
&rkcif_dvp {
status = "okay";
ports {
#address-cells = <1>;
#size-cells = <0>;
port@0 {
#address-cells = <1>;
#size-cells = <0>;
/* Parallel bus endpoint */
dvp_in_bcam1: endpoint@1 {
reg = <1>;
remote-endpoint = <&nvp6158_out>;
bus-width = <16>;
};
};
};
};
&rkcif_mmu {
status = "okay";
};
④pinctrl的配置
这里需要特别注意的是,pinctrl的引用一定需要正确。这里引用的是并口的16条总线以及相关的clk。
pinctrl-0 = <&cif_clk &cif_dvp_clk &cif_dvp_bus8 &cif_dvp_bus16>;
(5)APK预览
如果是走官方的USBCAMERAHAL的话,可以打开上述DTS的配置:rockchip,android-usb-camerahal-enable就会注册4路,之后就可以使用多摄的APK进行预览。
(6)抓图指令调试
开数据流
v4l2-ctl --verbose -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat='NV12' --stream-mmap=4
抓图:
v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat='NV12' --stream-mmap=3 --stream-skip=4 --stream-to=/data/1920x1080p60_nv12.yuv --stream-count=5 --stream-poll