• NVIDIA Jeston 相机驱动开发


    环境准备:

    HW:

    • develop board
    • X86 PC

    SOFTWARE:

    • cross compile gcc tools
    • pulic source code
    • your driver code and makefile

    Device tree适配:

    1. iic addr&drivber compatial适配
    ov5640_single_cam0: rbpcv2_ov5640_a@3c {
    				compatible = "nvidia,ov5640";
    				/* I2C device address */
    				reg = <0x3c>;
    
    				/* V4L2 device node location */
    				devnode = "video0";
    
    				/* Physical dimensions of sensor */
    				physical_w = "3.680";
    				physical_h = "2.760";
    
    				sensor_model = "ov5640";
    
    				use_sensor_mode_id = "true";
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    1. 分辨率&参数适配
    mode0 { /* ov5640_MODE_1920x1080_30FPS */
    					mclk_khz = "24000";
    					num_lanes = "2";
    					tegra_sinterface = "serial_a";
    					phy_mode = "DPHY";
    					discontinuous_clk = "no";
    					dpcm_enable = "false";
    					cil_settletime = "0";
    
    					active_w = "1920";
    					active_h = "1080";
    					pixel_t = "bayer_rggb";
    					readout_orientation = "90";
    					line_length = "2200";
    					inherent_gain = "1";
    					mclk_multiplier = "9.33";
    					pix_clk_hz = "84000000";
    
    					gain_factor = "16";
    					framerate_factor = "1000000";
    					exposure_factor = "1000000";
    					min_gain_val = "16"; /* 1.00x */
    					max_gain_val = "170"; /* 10.66x */
    					step_gain_val = "1";
    					default_gain = "16"; /* 1.00x */
    					min_hdr_ratio = "1";
    					max_hdr_ratio = "1";
    					min_framerate = "2000000"; /* 2.0 fps */
    					max_framerate = "30000000"; /* 30.0 fps */
    					step_framerate = "1";
    					default_framerate = "30000000"; /* 30.0 fps */
    					min_exp_time = "13"; /* us */
    					max_exp_time = "683709"; /* us */
    					step_exp_time = "1";
    					default_exp_time = "2495"; /* us */
    
    					embedded_metadata_height = "0";
    				};
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    1. mipi参数适配
    		num_csi_lanes = <2>;
    		max_lane_speed = <1500000>;
    		min_bits_per_pixel = <10>;
    		vi_peak_byte_per_pixel = <2>;
    		vi_bw_margin_pct = <25>;
    		max_pixel_rate = <240000>;
    		isp_peak_byte_per_pixel = <5>;
    		isp_bw_margin_pct = <25>;
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    Driver适配:

    1. probe适配
    	/* Probe sensor model id registers */
    	err = ov5640_read_reg(s_data, ov5640_MODEL_ID_ADDR_MSB, &reg_val[0]);
    	if (err) {
    		dev_err(dev, "%s: error during i2c read probe (%d)\n",
    			__func__, err);
    		goto err_reg_probe;
    	}
    	err = ov5640_read_reg(s_data, ov5640_MODEL_ID_ADDR_LSB, &reg_val[1]);
    	if (err) {
    		dev_err(dev, "%s: error during i2c read probe (%d)\n",
    			__func__, err);
    		goto err_reg_probe;
    	}
    	if (!((reg_val[0] == 0x56) && reg_val[1] == 0x40)) //ov5640
    		dev_err(dev, "%s: invalid sensor model id: %x%x\n",
    			__func__, reg_val[0], reg_val[1]);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    1. 配置表适配
    enum {
    	ov5640_MODE_1920x1080_30FPS,
    	ov5640_MODE_1280x720_60FPS,
    
    	ov5640_MODE_COMMON,
    	ov5640_START_STREAM,
    	ov5640_STOP_STREAM,
    };
    
    static ov5640_reg *mode_table[] = {
    	[ov5640_MODE_1920x1080_30FPS] = ov5640_mode_1920x1080_30fps,
    	[ov5640_MODE_1280x720_60FPS] = ov5640_mode_1280x720_60fps,
    
    	[ov5640_MODE_COMMON]  = ov5640_mode_common,
    	[ov5640_START_STREAM]  = ov5640_start_stream,
    	[ov5640_STOP_STREAM]  = ov5640_stop_stream,
    };
    
    static const int ov5640_30fps[] = {
    	30,
    };
    
    static const int ov5640_60fps[] = {
    	60,
    };
    
    /*
     * WARNING: frmfmt ordering need to match mode definition in
     * device tree!
     */
    static const struct camera_common_frmfmt ov5640_frmfmt[] = {
    	{{1920, 1080},	ov5640_30fps, 1, 0, ov5640_MODE_1920x1080_30FPS},
    	{{1280, 720},	ov5640_60fps, 1, 0, ov5640_MODE_1280x720_60FPS},
    };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    1. 曝光增益适配
    static struct tegracam_ctrl_ops ov5640_ctrl_ops = {
    	.numctrls = ARRAY_SIZE(ctrl_cid_list),
    	.ctrl_cid_list = ctrl_cid_list,
    	.set_gain = ov5640_set_gain,
    	.set_exposure = ov5640_set_exposure,
    	//.set_frame_rate = ov5640_set_frame_rate,
    	.set_group_hold = ov5640_set_group_hold,
    };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    vi如果报错timeout,首先示波器看是否有mipi输出,如果没有有则查看驱动配置是否正确,参数等,如下:

    [   99.405759] video4linux video0: frame start syncpt timeout!0
    [   99.613754] video4linux video0: frame start syncpt timeout!0
    [   99.821732] video4linux video0: frame start syncpt timeout!0
    [  100.029746] video4linux video0: frame start syncpt timeout!0
    [  100.237742] video4linux video0: frame start syncpt timeout!0
    [  100.445745] video4linux video0: frame start syncpt timeout!0
    [  100.653729] video4linux video0: frame start syncpt timeout!0
    [  100.861730] video4linux video0: frame start syncpt timeout!0
    [  101.069737] video4linux video0: frame start syncpt timeout!0
    [  101.277768] video4linux video0: frame start syncpt timeout!0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    测试

    查看内核log

    dmesg | grep ov5640
    
    • 1

    输出:

    [  103.352239] ov5640: loading out-of-tree module taints kernel.
    [  103.359115] ov5640 6-003c: tegracam sensor driver:ov5640_v2.0.6
    [  103.362288] vi 54080000.vi: subdev ov5640 6-003c bound
    
    • 1
    • 2
    • 3

    使用v4l2查看信息

    v4l2-ctl -d  /dev/video0 --all
    
    • 1

    输出:

    Driver Info (not using libv4l2):
            Driver name   : tegra-video
            Card type     : vi-output, ov5640 6-003c
            Bus info      : platform:54080000.vi:0
            Driver version: 4.9.253
            Capabilities  : 0x84200001
                    Video Capture
                    Streaming
                    Extended Pix Format
                    Device Capabilities
            Device Caps   : 0x04200001
                    Video Capture
                    Streaming
                    Extended Pix Format
    Priority: 2
    Video input : 0 (Camera 0: no power)
    Format Video Capture:
            Width/Height      : 1920/1080
            Pixel Format      : 'RG10'
            Field             : None
            Bytes per Line    : 3840
            Size Image        : 4147200
            Colorspace        : sRGB
            Transfer Function : Default (maps to sRGB)
            YCbCr/HSV Encoding: Default (maps to ITU-R 601)
            Quantization      : Default (maps to Full Range)
            Flags             :
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    使用v4l2-ctl保存raw图测试:

     v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=RG10 --stream-mmap --stream-count=1 -d /dev/video0 --stream-to=ov5640.raw 
    
    • 1

    正常在当前目录下面会保存一张格式化好的raw图

  • 相关阅读:
    ALevel课程组合建议
    07-网络篇-抓包分析TCP
    【网络服务&数据库教程】11 MySQL 集群
    基于SSM框架的《超市订单管理系统》Web项目开发(第四天)用户管理,增删改查(日期插件的使用)
    GIT使用需知,哪些操作会导致本地代码变动
    难顶,面试官问我G1垃圾收集器
    外汇天眼:晚上可以炒外汇吗?什么时候炒外汇比较合适?
    Java测试(11) --- selenium
    面试:Android应用编译打包流程
    流动舞台车改装设计(说明书+任务书+开题报告+评分表+cad图纸)
  • 原文地址:https://blog.csdn.net/weixin_43873379/article/details/128178939