WRTnode add spi cs1

From WRTnode Wiki Site
Jump to: navigation, search
Other languages:
English 100% • ‎中文(中国大陆)‎ 100%

Select the drive and test program

make menuconfig
-*- kmod-spi-dev................................. User mode SPI device driver 
<*> spidev-test.......................................... SPI testing utility 

Modify the driver code
patch:

wget https://raw.githubusercontent.com/WRTnode/openwrt-patches/master/R45620/0402-WRTndoe-spi-add-cs1.patch
cd ./build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620n/linux-3.10.49
patch -p1 < 0402-WRTndoe-spi-add-cs1.patch

0402-WRTndoe-spi-add-cs1.patch:

 
--- a/drivers/spi/spi-rt2880.c	2015-01-26 14:49:36.269930576 +0000
+++ b/drivers/spi/spi-rt2880.c	2015-07-30 10:33:42.193259659 +0000
@@ -34,6 +34,8 @@
 
 #define RAMIPS_SPI_DEV_OFFSET		0x40
 
+#define RAMIPS_SPI_GPIO     0x60
+
 #define RAMIPS_SPI_STAT(cs)		(0x00 + (cs * RAMIPS_SPI_DEV_OFFSET))
 #define RAMIPS_SPI_CFG(cs)		(0x10 + (cs * RAMIPS_SPI_DEV_OFFSET))
 #define RAMIPS_SPI_CTL(cs)		(0x14 + (cs * RAMIPS_SPI_DEV_OFFSET))
@@ -553,6 +555,8 @@
 static void rt5350_spi_reset(struct rt2880_spi *rs)
 {
 	int cs;
+	void __iomem *base_gpio;
+	u32 val_gpio;
 
 	rt2880_spi_write(rs, RAMIPS_SPI_ARBITER,
 			 SPICTL_ARB_EN);
@@ -563,6 +567,12 @@
 				 SPICFG_SPICLK_DIV16 | SPICFG_SPICLKPOL);
 		rt2880_spi_write(rs, RAMIPS_SPI_CTL(cs), SPICTL_HIZSDO | SPICTL_SPIENA);
 	}
+
+	base_gpio = rs->base - 0xb00;
+	val_gpio = ioread32(base_gpio + RAMIPS_SPI_GPIO);
+	val_gpio &= ~(3 << 11);
+	iowrite32(val_gpio,base_gpio + RAMIPS_SPI_GPIO);
+
 }
 
 static void mt7621_spi_reset(struct rt2880_spi *rs)

Register spi equipment

wget https://raw.githubusercontent.com/WRTnode/openwrt-patches/master/R45620/wrtnode_spidev_dts.patch
patch -p1 < wrtnode_spidev_dts.patch

wrtnode_spidev_dts.patch:

--- a/target/linux/ramips/dts/WRTNODE.dts	2015-07-23 14:48:30.402882723 +0000
+++ b/target/linux/ramips/dts/WRTNODE.dts	2015-07-29 12:06:40.000000000 +0000
@@ -53,6 +53,17 @@
 					reg = <0x50000 0xfb0000>;
 				};
 			};
+
+			spidev@40 {
+						#address-cells = <1>;
+						#size-cells = <1>;
+						compatible = "spidev";
+						reg = <1 0>;
+						linux,modalias = "spidev", "spidev";
+						spi-max-frequency = <10000000>;
+				
+			};
+
 		};
 	};
 
@@ -79,14 +90,10 @@
 				ralink,group = "ephy", "wled", "pa", "i2c", "wdt", "uartf";
 				ralink,function = "gpio";
 			};
-		};
-	};
-
-	gpio-leds {
-		compatible = "gpio-leds";
-		indicator {
-			label = "wrtnode:blue:indicator";
-			gpios = <&gpio1 14 0>;
+			spi_cs {
+				ralink,group = "spi refclk";
+				ralink,funtion = "spi refclk";
+			};
 		};
 	};

compile

make V=s

Flash firmware

ls /dev

File:范例.jpg