7.10.2. 参数配置

7.10.2.1. 内核配置

使能 SPI 相关的内核驱动,可在通过下列命令进行配置(参考:快速入门 - 编译概述 - Kernel配置):

make menuconfig

在内核的配置界面中,进行下列的选择:

Device Drivers  --->
    [*] SPI support  --->
        <*>   ZX SPI controller
        ......
    [*] DMA Engine support  --->
        <*>   ZX SoCs DMA support

进行如上的配置之后,内核 SPI 驱动使能,并且 SPI 可使用 DMA 进行数据传输。

7.10.2.2. DTS 配置

芯片级的 DTS:

spi0: spi@10400000 {
    compatible = "zx,aic-spi-v1.0";
    reg = <0x0 0x10400000 0x0 0x1000>;
    interrupts-extended = <&plic0 44 IRQ_TYPE_LEVEL_HIGH>;
    clocks = <&cmu CLK_SPI0>;
    resets = <&rst RESET_SPI0>;
    dmas = <&dma DMA_SPI0>, <&dma DMA_SPI0>;
    dma-names = "rx", "tx";
    #address-cells = <1>;
    #size-cells = <0>;
    spi-max-frequency = <24000000>;
};

spi1: spi@10410000 {
    compatible = "zx,aic-spi-v1.0";
    reg = <0x0 0x10410000 0x0 0x1000>;
    interrupts-extended = <&plic0 45 IRQ_TYPE_LEVEL_HIGH>;
    clocks = <&cmu CLK_SPI1>;
    resets = <&rst RESET_SPI1>;
    dmas = <&dma DMA_SPI1>, <&dma DMA_SPI1>;
    dma-names = "rx", "tx";
    #address-cells = <1>;
    #size-cells = <0>;
    spi-max-frequency = <24000000>;
};

其中板级的配置 board.dts 中需要使能该模块,并且根据实际情况,配置最大工作频率:

&spi0 {
    pinctrl-names = "default";
    pinctrl-0 = <&spi0_pins_a>;
    spi-max-frequency = <100000000>;
    status = "okay";
};

&spi1 {
    pinctrl-names = "default";
    pinctrl-0 = <&spi1_pins_a>;
    spi-max-frequency = <100000000>;
    status = "okay";
};

board-u-boot.dtsi 需要设置 u-boot,dm-pre-reloc ,只有设置了该标记,SPL 中才可以使用 SPI:

&spi0 {
    u-boot,dm-pre-reloc;
};

&spi1 {
    u-boot,dm-pre-reloc;
};