NVP6158简介
NVP6158C是一款4通道通用RX,提供高质量图像的芯片。它接受来自摄像机和其他视频信号的独立4通道通用输入来源。它将4通道通用1M至8M 7.5P视频格式数字化并解码为代表8位ITU-R BT.656/1120 4:2:2格式的数字分量视频,并将单独的BT.601格式与27/36/37.125MHz同步,54/72/74.25MHz和108/144/148.5/297MHz多路复用。54/72/74.25/108/144/148.5/297MHz复用功能可用,因为它在时钟范围内锁相环NVP6158C包括4通道模拟处理电路,包括抗混叠滤波器、ADC、钳位和均衡器滤波器。采用自适应高性能梳状滤波器和垂直峰值滤波器,获得了最佳的图像质量。它还支持可编程的饱和度、色调、亮度、对比度以及CTI、可编程峰值滤波器和各种补偿滤波器等多种功能。
RK DVP简介:
DVP(Digital Video Port) 是传统的sensor输出接口,采用并行输出方式,d数据位宽有8bit、10bit、12bit、16bit,是CMOS电平信号(重点是非差分信号),PCLK最大速率为96MHz,接口如下图:
PCLK:pixel clock ,像素时钟,每个时钟对应一个像素数据;
HSYNC:horizonal synchronization,行同步信号
VSYNC:vertical synchronization,帧同步信号;
DATA:像素数据,视频数据,具体位宽要看ISP是否支持;
XCLK:或者MCLK,ISP芯片输出给驱动sensor的时钟;
SCL,SDA:IIC用来读写sensor的寄存器,配置sensor。
NVP6158 与 RK3568 DVP连接相关原理图:
设备树配置:
&rkcif { status = "okay"; memory-region = <&cif_reserved>; };
&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>; }; }; };
};
nvp6158: nvp6158@30 { compatible = "nvp6158-v4l2"; status = "okay";reg = <0x30>; clocks = <&cru CLK_CIF_OUT>; clock-names = "xvclk"; power-domains = <&power RK3568_PD_VI>; pinctrl-names = "default"; pinctrl-0 = <&cif_clk &cif_dvp_clk &cif_dvp_bus16>; //pinctrl-0 = <&cif_dvp_clk &cif_dvp_bus8 &cif_dvp_bus16>;pwr-gpios = <&gpio0 RK_PC4 GPIO_ACTIVE_HIGH>; //pwr2-gpios = <&gpio4 RK_PC7 GPIO_ACTIVE_HIGH>;/* 360 camera */ rst-gpios = <&gpio4 RK_PA6 GPIO_ACTIVE_HIGH>; /*rst2-gpios = <&gpio2 RK_PC5 GPIO_ACTIVE_HIGH>;*/ /*pwdn-gpios = <&gpio4 RK_PA6 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 = <0>; // pclk dual edge, 0/1 rockchip,default_rect= <1920 1080>; // default resolution port {nvp6158_out: endpoint { remote-endpoint = <&dvp_in_bcam1>; }; }; };
clocks = <&cru CLK_CIF_OUT>; //走GPIO CIF时钟 配置为是27M
clock-names = "xvclk";
nvp6158->xvclk = devm_clk_get(dev, "xvclk");if (IS_ERR(nvp6158->xvclk)) {dev_err(dev, "Failed to get xvclk\n");return -EINVAL;}if (ret < 0) {#define NVP6158_XVCLK_FREQ 27000000ret = clk_set_rate(nvp6158->xvclk, NVP6158_XVCLK_FREQ);dev_err(dev, "Failed to set xvclk rate (24MHz)\n");return ret;}
rockchip,dvp_mode = "BT1120" :走BT1120模式
rockchip,channel_nums = <4>;//并口的数据lane ,只有一条lane 可配置1 参数:1/2/4
rockchip,default_rect= <1280 720>;摄像头分辨率。 rkcif会从nvp6158驱动里获取
rockchip,dual_edge :pclk的边沿有效 一般用于配置分辨率 720p:0 1080P:1 如下
rkcif 会获取对应的pclk dual_edge
static int nvp6158_g_mbus_config(struct v4l2_subdev *sd,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关注的代码:
初始化热拔插工作队列:
INIT_DELAYED_WORK(&nvp6158->plug_state_check.d_work, nvp6158_plug_state_check_work);nvp6158->plug_state_check.state_check_wq =create_singlethread_workqueue("nvp6158_work_queue");if (nvp6158->plug_state_check.state_check_wq == NULL) {dev_err(dev, "%s(%d): %s create failed.\n", __func__, __LINE__,"nvp6158_work_queue");}
热拔插队列:打开DVP摄像头后 nvp6158_no_signal 读取nvp6158 0xa8地址,判断摄像头有无接入
#ifdef WORK_QUEUE
static void nvp6158_plug_state_check_work(struct work_struct *work)
{struct sensor_state_check_work *params_check =container_of(work, struct sensor_state_check_work, d_work.work);struct nvp6158 *nvp6158 =container_of(params_check, struct nvp6158, plug_state_check);struct i2c_client *client = nvp6158->client;struct v4l2_subdev *sd = &nvp6158->subdev;u8 novid_status = 0x00;u8 sync_status = 0x00;nvp6158_no_signal(sd, &novid_status);nvp6158_sync(sd, &sync_status);nvp6158->cur_detect_status = novid_status;/* detect state change to determine is there has plug motion */novid_status = nvp6158->cur_detect_status ^ nvp6158->last_detect_status;if (novid_status)nvp6158->hot_plug = true;elsenvp6158->hot_plug = false;nvp6158->last_detect_status = nvp6158->cur_detect_status;dev_info(&client->dev, "%s has plug motion? (%s)", __func__,nvp6158->hot_plug ? "true" : "false");if (nvp6158->hot_plug) {dev_info(&client->dev, "queue_delayed_work 1500ms, if has hot plug motion.");queue_delayed_work(nvp6158->plug_state_check.state_check_wq,&nvp6158->plug_state_check.d_work, msecs_to_jiffies(1500));nvp6158_write(client, 0xFF, 0x20);nvp6158_write(client, 0x00, (sync_status << 4) | sync_status);usleep_range(3000, 5000);nvp6158_write(client, 0x00, 0xFF);} else {dev_info(&client->dev, "queue_delayed_work 100ms, if no hot plug motion.");queue_delayed_work(nvp6158->plug_state_check.state_check_wq,&nvp6158->plug_state_check.d_work, msecs_to_jiffies(100));}
}
#endif
调试:
I2C无法读取写入:
1.确认电源电压
2.确认时钟脚有无27M CLK信号
3.排查是否其他器件影响
无图像:1.确认时钟脚有无27M CLK信号
2.确认下发的分辨率与接入的摄像头是否对应得上