AN 923: Routing Intel® Stratix® 10 HPS Peripherals to FPGA Fabric

ID 683838
Date 10/12/2020
Public

1.2.9. Building Linux

  1. Clone the Linux git tree and get the LTSI branch:
    cd ~/ s10_spim_fpga/
    git clone https://github.com/altera-opensource/linux-socfpga\
     linux-socfpga.a53
    cd linux-socfpga.a53
    git checkout -b test-kernel -t origin/socfpga-5.4.44-lts
    make clean && make mrproper
    
  2. Change the kernel configuration by editing arch/arm64/configs/defconfig as follows:
    CONFIG_SPI_SPIDEV=y
    CONFIG_GPIO_ALTERA=y
    CONFIG_SPI_DESIGNWARE=y
    CONFIG_SPI_DW_MMIO=y
    
  3. Edit the device tree file: arch/arm64/boot/dts/altera/socfpga_stratix10_socdk.dts as follows:
    Add the FPGA clock that is used by the FPGA fabric:
    clk_100: clk_100 {
       compatible = "fixed-clock";
       clock-frequency = <100000000>;	
       clock-output-names = "clk_100-out_clk";
    };
    
    Add the PIO module which controls the SPI CS signal:
    spi_cs_pio: gpio@0xf9010000 {
       compatible = "altr,pio-19.1", "altr,pio-1.0";
       reg = <0xf9010000 0x00000020>;
       clocks = <&clk_100>;
       altr,gpio-bank-width = <1>;	
       resetvalue = <1>;
       #gpio-cells = <2>;
       gpio-controller;
       status = "okay";
    };
    
    Enable SPIM0, make it use the soft IP PIO as chip select, and enable it to be used by the spidev driver:
    &spi0 {
       num-cs = <1>;
       cs-gpios = <&spi_cs_pio 0 0>;
       status = "okay";
       spidev@0 {
          compatible = "custom,spidev";
          reg = <0x0>;
          spi-max-frequency = <0x5F5E10>;
          enable-dma = <0x1>;
       };
    };
    
  4. Edit the spidev driver source file: (drivers/spi/spidev.c) for the "compatible" property to match the created device tree entry.
    { .compatible = "lineartechnology,ltc2488" },
     	{ .compatible = "ge,achc" },
     	{ .compatible = "semtech,sx1301" },
    	{ .compatible = "custom,spidev" },
     	{},
    
  5. Build Linux kernel and device trees.
    make clean && make mrproper
    # enable JFFS2 and disable 4K sectors for booting from QSPI
    echo "CONFIG_JFFS2_FS=y" >> arch/arm64/configs/defconfig
    echo "CONFIG_MTD_SPI_NOR_USE_4K_SECTORS=n" >> arch/arm64/configs/defconfig
    # reduce QSPI clock to work on early boards
    sed -i 's/spi-max-frequency = <100000000>;/\
    spi-max-frequency = <50000000>;/g'\
     arch/arm64/boot/dts/altera/socfpga_stratix10_socdk.dts
    make defconfig
    make -j 48 Image dtbs modules
    make modules_install INSTALL_MOD_PATH=modules_install
    rm -rf modules_install/lib/modules/*/build
    rm -rf modules_install/lib/modules/*/source
    cd ..