WRTnode SPI Usage

From WRTnode Wiki
Jump to: navigation, search
This page is a translated version of the page SPI的玩法 and the translation is 100% complete.

Other languages:

WRTnode SPI Usage

Modify spi controller driver to achieve the support of the spi cs1

We assume that $(TOPDIR) for OpenWrt of compiler directory.
open spi-rt2880.c

vim $(TOPDIR)/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620n/linux-3.10.49/drivers/spi/spi-rt2880.c

find struct rt2880_spi_ops then set spi_ops[0].num_cs = 2

static struct rt2880_spi_ops spi_ops[] = {
   {
        .init_hw = rt2880_spi_reset,
        .set_cs = rt2880_spi_set_cs,
        .baudrate_set = rt2880_spi_baudrate_set,
        .write_read = rt2880_spi_write_read,
        .num_cs = 2,  //这里改为 .num_cs = 2,原本是 .num_cs = 1,
    }, {
        .init_hw = rt5350_spi_reset,
        .set_cs = rt2880_spi_set_cs,
        .baudrate_set = rt2880_spi_baudrate_set,
        .write_read = rt2880_spi_write_read,
        .num_cs = 2,
    }, {
        .init_hw = mt7621_spi_reset,
        .set_cs = mt7621_spi_set_cs,
        .baudrate_set = mt7621_spi_baudrate_set,
        .write_read = mt7621_spi_write_read,
        .num_cs = 1,
    },
};

Complete the registration of spi slave device where the dts

--- a/target/linux/ramips/dts/WRTNODE.dts
+++ b/target/linux/ramips/dts/WRTNODE.dts
		spi@b00 {
			status = "okay";

			m25p80@0 {
				#address-cells = <1>;
				#size-cells = <1>;
				compatible = "mx25l12805d";
				reg = <0 0>;
				linux,modalias = "m25p80", "w25q128";
				spi-max-frequency = <10000000>;

				partition@0 {
					label = "u-boot";
					reg = <0x0 0x30000>;
					read-only;
				};

				partition@30000 {
					label = "u-boot-env";
					reg = <0x30000 0x10000>;
					read-only;
				};

				factory: partition@40000 {
					label = "factory";
					reg = <0x40000 0x10000>;
					read-only;
				};

				partition@50000 {
					label = "firmware";
					reg = <0x50000 0xfb0000>;
				};
			};

+			spidev@1 {
+				#address-cells = <1>;
+				#size-cells = <1>;
+				compatible = "spidev";
+				reg = <1 0>;
+				linux,modalias = "spidev", "spidev";
+				spi-max-frequency = <10000000>;
+
+			};
		};

Select spidev kernel driver

make menuconfig
 Kernel modules  --->    SPI Support  --->    <*> kmod-spi-dev

Compile & flash firmware

Check if there is a device name.

ls /dev

Spi6.png

This is a test program,you can use this program to test whether SPI can work.

You can also use the openwrt comes with the test program spidev-test to test whether the SPI can work.

I hope this document ave helped you.