Jetson Xavier平台 MIPI接口采集FPGA 图像视频 (1)驱动移植

free-jdx 2021-02-19 16:56:03 11989
1. 前言

这里需要通过Xilinx FGPA将一路CSI视频通过MIPI接口传输到xavier平台

硬件平台: Jetson AGX Xavier
软件版本: L4T 32.4.4
视频: 1920 x 1080, 30fps, YUV444

2. 硬件检验

使用官方自带的ov5693相机模块,出图正常;
说明硬件接收平台是没问题的

3. 根据官方自带模块移植

(1)按照官方的imx185的驱动进行移植修改
按照这个驱动进行修改,无法生成video0设备,I2C检测也异常

(2)按照官方的ov5693的驱动进行移植修改
可以出现设备

具体修改如下

4. 移植如下

(1)修改 tegra194-camera-e3326-a00.dtsi.

这里只使用了一个模式 1920*1080

/ {
    host1x {
        vi@15c10000 {
            num-channels = <1>;
            ports {
                #address-cells = <1>;
                #size-cells = <0>;
                port@0 {
                    reg = <0>;
                    e3326_vi_in0: endpoint {
                        port-index = <2>;
                        bus-width = <4>;
                        remote-endpoint = <&e3326_csi_out0>;
                    };
                };
            };
        };

        nvcsi@15a00000 {
            num-channels = <1>;
            #address-cells = <1>;
            #size-cells = <0>;
            status = "okay";
            channel@0 {
                reg = <0>;
                ports {
                    #address-cells = <1>;
                    #size-cells = <0>;
                    port@0 {
                        reg = <0>;
                        e3326_csi_in0: endpoint@0 {
                            port-index = <2>;
                            bus-width = <4>;
                            remote-endpoint = <&e3326_ov5693_out0>;
                        };
                    };
                    port@1 {
                        reg = <1>;
                        e3326_csi_out0: endpoint@1 {
                            remote-endpoint = <&e3326_vi_in0>;
                        };
                    };
                };
            };
        };
    };

    i2c@3180000 {
        ov5693_c@36 {
            compatible = "nvidia,ov5693";
            /* I2C device address */
            reg = <0x36>;

            /* V4L2 device node location */
            devnode = "video0";

            /* Physical dimensions of sensor */
            physical_w = "3.674";
            physical_h = "2.738";

            /* Define any required hw resources needed by driver */
            /* ie. clocks, io pins, power sources */
            avdd-reg = "vana";
            iovdd-reg = "vif";

            /* Sensor output flip settings */
            vertical-flip = "true";

            mode0 { // OV5693_MODE_2592X1944
                mclk_khz = "24000";
                num_lanes = "4";
                tegra_sinterface = "serial_c";
                phy_mode = "DPHY";
                discontinuous_clk = "yes";
                dpcm_enable = "false";
                cil_settletime = "0";

                active_w = "1920";
                active_h = "1080";
                mode_type = "bayer";
                pixel_phase = "rggb";
                csi_pixel_bit_depth = "8";
                readout_orientation = "0";
                line_length = "2688";
                inherent_gain = "1";
                mclk_multiplier = "6.67";
                pix_clk_hz = "160000000";

                gain_factor = "10";
                min_gain_val = "10";/* 1DB*/
                max_gain_val = "160";/* 16DB*/
                step_gain_val = "1";
                default_gain = "10";
                min_hdr_ratio = "1";
                max_hdr_ratio = "1";
                framerate_factor = "1000000";
                min_framerate = "1816577";/*1.816577 */
                max_framerate = "30000000";/*30*/
                step_framerate = "1";
                default_framerate = "30000000";
                exposure_factor = "1000000";
                min_exp_time = "34";/* us */
                max_exp_time = "550385";/* us */
                step_exp_time = "1";
                default_exp_time = "33334";/* us */
                embedded_metadata_height = "0";
            };

//          mode1 { //OV5693_MODE_2592X1458
//              mclk_khz = "24000";
//              num_lanes = "2";
//              tegra_sinterface = "serial_c";
//              phy_mode = "DPHY";
//              discontinuous_clk = "yes";
//              dpcm_enable = "false";
//              cil_settletime = "0";
//
//              active_w = "2592";
//              active_h = "1458";
//              mode_type = "bayer";
//              pixel_phase = "bggr";
//              csi_pixel_bit_depth = "10";
//              readout_orientation = "0";
//              line_length = "2688";
//              inherent_gain = "1";
//              mclk_multiplier = "6.67";
//              pix_clk_hz = "160000000";
//
//              gain_factor = "10";
//              min_gain_val = "10";/* 1DB*/
//              max_gain_val = "160";/* 16DB*/
//              step_gain_val = "1";
//              default_gain = "10";
//              min_hdr_ratio = "1";
//              max_hdr_ratio = "1";
//              framerate_factor = "1000000";
//              min_framerate = "1816577";/*1.816577 */
//              max_framerate = "30000000";/*30*/
//              step_framerate = "1";
//              default_framerate = "30000000";
//              exposure_factor = "1000000";
//              min_exp_time = "34";/* us */
//              max_exp_time = "550385";/* us */
//              step_exp_time = "1";
//              default_exp_time = "33334";/* us */
//              embedded_metadata_height = "0";
//          };
//
//          mode2 { //OV5693_MODE_1280X720
//              mclk_khz = "24000";
//              num_lanes = "2";
//              tegra_sinterface = "serial_c";
//              phy_mode = "DPHY";
//              discontinuous_clk = "yes";
//              dpcm_enable = "false";
//              cil_settletime = "0";
//
//              active_w = "1280";
//              active_h = "720";
//              mode_type = "bayer";
//              pixel_phase = "bggr";
//              csi_pixel_bit_depth = "10";
//              readout_orientation = "0";
//              line_length = "1752";
//              inherent_gain = "1";
//              mclk_multiplier = "6.67";
//              pix_clk_hz = "160000000";
//
//              gain_factor = "10";
//              min_gain_val = "10";/* 1DB*/
//              max_gain_val = "160";/* 16DB*/
//              step_gain_val = "1";
//              default_gain = "10";
//              min_hdr_ratio = "1";
//              max_hdr_ratio = "1";
//              framerate_factor = "1000000";
//              min_framerate = "2787078";/* 2.787078 */
//              max_framerate = "120000000";/* 120*/
//              step_framerate = "1";
//              default_framerate = "120000000";
//              exposure_factor = "1000000";
//              min_exp_time = "22";/* us */
//              max_exp_time = "358733";/* us */
//              step_exp_time = "1";
//              default_exp_time = "8334";/* us */
//              embedded_metadata_height = "0";
//          };

            ports {
                #address-cells = <1>;
                #size-cells = <0>;

                port@0 {
                    reg = <0>;
                    e3326_ov5693_out0: endpoint {
                        port-index = <2>;
                        bus-width = <4>;
                        remote-endpoint = <&e3326_csi_in0>;
                    };
                };
            };
        };
    };

    e3326_lens_ov5693@P5V27C {
        min_focus_distance = "0.0";
        hyper_focal = "0.0";
        focal_length = "2.67";
        f_number = "2.0";
        aperture = "2.0";
    };

    tegra-camera-platform {
        compatible = "nvidia, tegra-camera-platform";

        num_csi_lanes = <4>;
        max_lane_speed = <1500000>;
        min_bits_per_pixel = <8>;
        vi_peak_byte_per_pixel = <2>;
        vi_bw_margin_pct = <25>;
        max_pixel_rate = <160000>;
        isp_peak_byte_per_pixel = <5>;
        isp_bw_margin_pct = <25>;

        modules {
            module0 {
                badge = "e3326_front_P5V27C";
                position = "rear";
                orientation = "1";
                drivernode0 {
                    /* Declare PCL support driver (classically known as guid)  */
                    pcl_id = "v4l2_sensor";
                    /* Driver v4l2 device name */
                    devname = "ov5693 2-0036";
                    /* Declare the device-tree hierarchy to driver instance */
                    proc-device-tree = "/proc/device-tree/i2c@3180000/ov5693_c@36";
                };
                drivernode1 {
                    /* Declare PCL support driver (classically known as guid)  */
                    pcl_id = "v4l2_lens";
                    proc-device-tree = "/proc/device-tree/e3326_lens_ov5693@P5V27C/";
                };
            };
        };
    };
};

(2)修改 tegra194-p2822-0000-camera-e3326-a00.dts

这里修改不多;
主要是使用的RST & PWDN 等GPIO管脚;
以及时钟电源等

#include <t19x-common-modules/tegra194-camera-e3326-a00.dtsi>
#include "dt-bindings/clock/tegra194-clock.h"

#define CAM0_RST_L  TEGRA194_MAIN_GPIO(H, 3)
#define CAM0_PWDN   TEGRA194_MAIN_GPIO(H, 6)

/* camera control gpio definitions */

/ {
    i2c@3180000 {
        ov5693_c@36 {
            /* Define any required hw resources needed by driver */
            /* ie. clocks, io pins, power sources */
            /* mclk-index indicates the index of the */
            /* mclk-name with in the clock-names array */

            clocks = <&bpmp_clks TEGRA194_CLK_EXTPERIPH1>,
                     <&bpmp_clks TEGRA194_CLK_PLLP_OUT0>;
            clock-names = "extperiph1", "pllp_grtba";
            mclk = "extperiph1";
            clock-frequency = <24000000>;
            reset-gpios = <&tegra_main_gpio CAM0_RST_L GPIO_ACTIVE_HIGH>;
            pwdn-gpios = <&tegra_main_gpio CAM0_PWDN GPIO_ACTIVE_HIGH>;
            vana-supply = <&p2822_avdd_cam_2v8>;
            vif-supply = <&p2822_vdd_1v8_cvb>;

            status = "okay";
        };
    };

    gpio@2200000 {
        camera-control-output-low {
            gpio-hog;
            output-low;
            gpios = <CAM0_RST_L 0 CAM0_PWDN 0>;
            label = "cam0-rst", "cam0-pwdn";
        };
    };
};

(3)关闭 plugin manager.

因为xavier平台默认是使用插件模式进行设备管理的;
相机模块也是通过插件管理的;
所以这里单独配置某个相机模块时,需要将插件管理关闭

#include "common/tegra194-p2888-0001-p2822-0000-common.dtsi"
//#include "common/tegra194-p2822-camera-modules.dtsi"
//#include "t19x-common-modules/tegra194-camera-plugin-manager.dtsi"
#include "common/tegra194-p2822-0000-camera-e3326-a00.dtsi"

(4)编辑ov5693.c

这里主要修改图像分辨率和帧率

#ifndef __OV5693_TABLES__
#define __OV5693_TABLES__

#include <media/camera_common.h>

#define OV5693_TABLE_WAIT_MS    0
#define OV5693_TABLE_END    1
#define OV5693_MAX_RETRIES  3
#define OV5693_WAIT_MS      10

#define ov5693_reg struct reg_8

static const ov5693_reg ov5693_start[] = {
    {0x0100, 0x01}, /* mode select streaming on */
    {OV5693_TABLE_END, 0x00}
};

static const ov5693_reg ov5693_stop[] = {
    {0x0100, 0x00}, /* mode select streaming on */
    {OV5693_TABLE_END, 0x00}
};

static const ov5693_reg tp_colorbars[] = {
    {0x0600, 0x00},
    {0x0601, 0x02},

    {OV5693_TABLE_WAIT_MS, OV5693_WAIT_MS},
    {OV5693_TABLE_END, 0x00}
};

static const ov5693_reg mode_2592x1944[] = {
    {OV5693_TABLE_WAIT_MS, OV5693_WAIT_MS},
    {OV5693_TABLE_END, 0x0000}
};

enum {
    OV5693_MODE_2592X1944,

    OV5693_MODE_START_STREAM,
    OV5693_MODE_STOP_STREAM,
    OV5693_MODE_TEST_PATTERN
};

static const ov5693_reg *mode_table[] = {
    [OV5693_MODE_2592X1944]         = mode_2592x1944,

    [OV5693_MODE_START_STREAM]      = ov5693_start,
    [OV5693_MODE_STOP_STREAM]       = ov5693_stop,
    [OV5693_MODE_TEST_PATTERN]      = tp_colorbars,
};

static const int ov5693_30fps[] = {
    30,
};

static const struct camera_common_frmfmt ov5693_frmfmt[] = {
    {{1920, 1080},  ov5693_30fps,   1, 0,   OV5693_MODE_2592X1944},
};
#endif  /* __OV5693_TABLES__ */

(5)内核配置

开启ov5693的驱动配置
kernel/kernel-4.9/arch/arm64/configs/tegra_defconfig.
CONFIG_VIDEO_OV5693=y

(6)编译内核

(7)刷写内核
$ sudo ./flash.sh -k kernel-dtb jetson-xavier mmcblk0p1

声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
free-jdx
红包 96 8 评论 打赏
评论
6个
内容存在敏感词
手气红包
  • jackwei 2022-12-15 16:58:11
    回复
    你好,我这里也想用个FPGA替代输入摄像头,想借用ov5693的驱动让Jeston 识别出来,方便加个QQ171808966请教下吗?另外不知道你这边需不需要禁用 CSI中的I2C,我没看到你在驱动ov5693.c让 寄存器的读写 return 0
  • 冯炜 2021-07-15 14:04:05
    回复

    你好,我有问题想请教你,可以加我qq 376495350.

  • free-jdx 2021-07-12 09:01:33
    回复

    好的

  • 钟斌 2021-07-09 16:48:16
    回复

    我这里有个没有驱动的mipi摄像头,也想借ov5693的驱动识别出来,方便加个QQ66760505,请教一下吗?

  • free-jdx 2021-07-09 15:13:39
    回复

    有驱动的啊

  • 钟斌 2021-07-09 09:27:39
    回复

    大侠你好,请问你的mipi输入设备是没有驱动的吗?

相关专栏
置顶时间设置
结束时间
删除原因
  • 广告/SPAM
  • 恶意灌水
  • 违规内容
  • 文不对题
  • 重复发帖
打赏作者
易百纳技术社区
free-jdx
您的支持将鼓励我继续创作!
打赏金额:
¥1易百纳技术社区
¥5易百纳技术社区
¥10易百纳技术社区
¥50易百纳技术社区
¥100易百纳技术社区
支付方式:
微信支付
支付宝支付
易百纳技术社区微信支付
易百纳技术社区
打赏成功!

感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

审核成功

发布时间设置
发布时间:
是否关联周任务-专栏模块

审核失败

失败原因
备注
拼手气红包 红包规则
祝福语
恭喜发财,大吉大利!
红包金额
红包最小金额不能低于5元
红包数量
红包数量范围10~50个
余额支付
当前余额:
可前往问答、专栏板块获取收益 去获取
取 消 确 定

小包子的红包

恭喜发财,大吉大利

已领取20/40,共1.6元 红包规则

    易百纳技术社区