6.4.2. 参数配置

6.4.2.1. 内核配置

DVP驱动依赖dma-buf、CMA、V4L2模块,所以需要提前打开。

6.4.2.1.1. 打开 CMA

参考快速入门 - 编译概述 - Kernel配置,进入kernel的功能配置,按如下选择:

Linux
    Memory Management options
         [*] Contiguous Memory Allocator

还需要设置CMA区域的大小,在内核配置的另外一个地方,如下配置为 16MB:

Linux
    Library routines
        [*] DMA Contiguous Memory Allocator
        (16)  Size in Mega Bytes

6.4.2.1.2. 打开 dma-buf

参考快速入门 - 编译概述 - Kernel配置,进入kernel的功能配置,按如下选择:

Linux
    Device Drivers
        DMABUF options
            [*] Explicit Synchronization Framework
            [*]   Sync File Validation Framework
            [*] userspace dmabuf misc driver
            [*] DMA-BUF Userland Memory Heaps
                [*]   DMA-BUF CMA Heap

6.4.2.1.3. 打开 V4L2

在 kernel 的 menuconfig 中,按如下选择:

Linux
    Device Drivers
         Multimedia support
            Media core support
                <*> Video4Linux core

打开 V4L2 的相关选项:

Linux
    Device Drivers
         Multimedia support
            Video4Linux options
                [*] V4L2 sub-device userspace API
                [*] Enable advanced debug functionality on V4L2 drivers

6.4.2.1.4. 打开 DVP

在 kernel 的 menuconfig 中,按如下选择:

Linux
    Device Drivers
         Multimedia support
            Media drivers
                [*] V4L platform devices
                    <*>   ZX Digital Video Port Support

6.4.2.2. DTS 参数配置

6.4.2.2.1. M4 配置

DTS分别存放在两个目录:common/和board/,board中存放sensor配置、以及和DVP关联的配置。

common/m4.dtsi中的参数配置:

dvp0: dvp@18830000 {
    #address-cells = <1>;
    #size-cells = <0>;
    compatible = "zx,aic-dvp-v1.0";
    reg = <0x0 0x18830000 0x0 0x1000>;
    interrupts-extended = <&plic0 57 IRQ_TYPE_LEVEL_HIGH>;
    clocks = <&cmu CLK_DVP>;
    clock-rate = <200000000>;
    resets = <&rst RESET_DVP>;
};

xxx-board.dts中的配置参数:

&dvp0 {
    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&dvp_pins>;        /* dvp 接口引脚 */

    port@0 {
        reg = <0>;
        dvp0_in: endpoint {
            remote-endpoint = <&ov5640_out>;
/*          bus-type = <6>; /* V4L2_FWNODE_BUS_TYPE_BT656 */
            bus-width = <8>;
            hsync-active = <1>;
            vsync-active = <1>;
            field-even-active = <1>;
            pclk-sample = <1>;
        };
    };
};

小技巧

DVP驱动支持标准的 V4L2参数,如上面的 bus-type、bus-type、hsync-active 等,更完整的参数定义可以见Linux中的代码 drivers/media/v4l2-core/v4l2-fwnode.c,v4l2_fwnode_endpoint_parse_parallel_bus()。