Skip to contentSkip to conversation

add SPI controller driver for Atheros AR7XXX/AR9XXX SoCs

PATCH Applied Antony Pavlov 2 participants 7 messages Apr 7, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover add SPI controller driver for Atheros AR7XXX/AR9XXX SoCs

This patchseries adds the SPI controller driver for Atheros AR7XXX/AR9XXX SoCs. The driver uses bitbang SPI driver infrastructure from linux kernel.

Changes since v1:
* spi: ath79: fix ath79_spi_setup() return error codes

Antony Pavlov (5):
spi: import bitbang txrx utility functions from linux
spi: add controller driver for Atheros AR7XXX/AR9XXX SoCs
MIPS: ar9331.dtsi: add SPI master
MIPS: tplink-mr3020.dts: add S25FL032PIF SPI flash chip
MIPS: tplink-mr3020_defconfig: add SPI support

 arch/mips/configs/tplink-mr3020_defconfig |   7 +-
 arch/mips/dts/ar9331.dtsi                 |   6 +
 arch/mips/dts/tplink-mr3020.dts           |  20 ++
 drivers/spi/Kconfig                       |   4 +
 drivers/spi/Makefile                      |   1 +
 drivers/spi/ath79_spi.c                   | 299 ++++++++++++++++++++++++++++++
 drivers/spi/spi-bitbang-txrx.h            |  95 ++++++++++
 7 files changed, 431 insertions(+), 1 deletion(-)
 create mode 100644 drivers/spi/ath79_spi.c
 create mode 100644 drivers/spi/spi-bitbang-txrx.h
Signature · 7 lines
1.9.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

PATCH v2 4/5 MIPS: tplink-mr3020.dts: add S25FL032PIF SPI flash chip

---
 arch/mips/dts/tplink-mr3020.dts | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
arch/mips/dts/tplink-mr3020.dts +20 -0
index 5d613d8..7aeb740 100644
@@ -14,3 +14,23 @@
 &serial0 {
 	status = "okay";
 };
+
+&spi {
+	num-chipselects = <1>;
+	status = "okay";
+
+	/* Spansion S25FL032PIF SPI flash */
+	spiflash: m25p80@0 {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "m25p80";
+		spi-max-frequency = <104000000>;
+		reg = <0>;
+	};
+};
+
+/ {
+	aliases {
+		spiflash = &spiflash;
+	};
+};
Signature · 7 lines
1.9.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH v2 2/5 spi: add controller driver for Atheros AR7XXX/AR9XXX SoCs

In reply to Antony Pavlov
---
 drivers/spi/Kconfig     |   4 +
 drivers/spi/Makefile    |   1 +
 drivers/spi/ath79_spi.c | 299 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 304 insertions(+)
drivers/spi/Kconfig +4 -0
index 422693c..60eaaaa 100644
@@ -10,6 +10,10 @@ config DRIVER_SPI_ALTERA
 	bool "Altera SPI Master driver"
 	depends on NIOS2
 
+config DRIVER_SPI_ATH79
+	bool "Atheros AR71XX/AR724X/AR913X/AR933X SPI controller driver"
+	depends on MACH_MIPS_ATH79
+
 config DRIVER_SPI_ATMEL
 	bool "Atmel (AT91) SPI Master driver"
 	depends on ARCH_AT91
drivers/spi/Makefile +1 -0
index 1036f8f..7469479 100644
@@ -1,4 +1,5 @@
 obj-$(CONFIG_SPI) += spi.o
+obj-$(CONFIG_DRIVER_SPI_ATH79) += ath79_spi.o
 obj-$(CONFIG_DRIVER_SPI_IMX) += imx_spi.o
 obj-$(CONFIG_DRIVER_SPI_MVEBU) += mvebu_spi.o
 obj-$(CONFIG_DRIVER_SPI_MXS) += mxs_spi.o
drivers/spi/ath79_spi.c new file +299 -0

299 lines not on this page · raw message

Signature · 7 lines
1.9.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH v2 1/5 spi: import bitbang txrx utility functions from linux

In reply to Antony Pavlov
---
 drivers/spi/spi-bitbang-txrx.h | 95 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)
drivers/spi/spi-bitbang-txrx.h new file +95 -0
new file mode 100644
index 0000000..4c74d4e
@@ -0,0 +1,95 @@
+/*
+ * Mix this utility code with some glue code to get one of several types of
+ * simple SPI master driver.  Two do polled word-at-a-time I/O:
+ *
+ *   -	GPIO/parport bitbangers.  Provide chipselect() and txrx_word[](),
+ *	expanding the per-word routines from the inline templates below.
+ *
+ *   -	Drivers for controllers resembling bare shift registers.  Provide
+ *	chipselect() and txrx_word[](), with custom setup()/cleanup() methods
+ *	that use your controller's clock and chipselect registers.
+ *
+ * Some hardware works well with requests at spi_transfer scope:
+ *
+ *   -	Drivers leveraging smarter hardware, with fifos or DMA; or for half
+ *	duplex (MicroWire) controllers.  Provide chipselect() and txrx_bufs(),
+ *	and custom setup()/cleanup() methods.
+ */
+
+/*
+ * The code that knows what GPIO pins do what should have declared four
+ * functions, ideally as inlines, before including this header:
+ *
+ *  void setsck(struct spi_device *, int is_on);
+ *  void setmosi(struct spi_device *, int is_on);
+ *  int getmiso(struct spi_device *);
+ *  void spidelay(unsigned);
+ *
+ * setsck()'s is_on parameter is a zero/nonzero boolean.
+ *
+ * setmosi()'s is_on parameter is a zero/nonzero boolean.
+ *
+ * getmiso() is required to return 0 or 1 only. Any other value is invalid
+ * and will result in improper operation.
+ *
+ * A non-inlined routine would call bitbang_txrx_*() routines.  The
+ * main loop could easily compile down to a handful of instructions,
+ * especially if the delay is a NOP (to run at peak speed).
+ *
+ * Since this is software, the timings may not be exactly what your board's
+ * chips need ... there may be several reasons you'd need to tweak timings
+ * in these routines, not just to make it faster or slower to match a
+ * particular CPU clock rate.
+ */
+
+#define spidelay(nsecs) udelay(nsecs/1000)
+
+static inline u32
+bitbang_txrx_be_cpha0(struct spi_device *spi,
+		unsigned nsecs, unsigned cpol,
+		u32 word, u8 bits)
+{
+	/* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */
+
+	/* clock starts at inactive polarity */
+	for (word <<= (32 - bits); likely(bits); bits--) {
+
+		/* setup MSB (to slave) on trailing edge */
+		setmosi(spi, word & (1 << 31));
+		spidelay(nsecs);	/* T(setup) */
+
+		setsck(spi, !cpol);
+		spidelay(nsecs);
+
+		/* sample MSB (from slave) on leading edge */
+		word <<= 1;
+		word |= getmiso(spi);
+		setsck(spi, cpol);
+	}
+	return word;
+}
+
+static inline u32
+bitbang_txrx_be_cpha1(struct spi_device *spi,
+		unsigned nsecs, unsigned cpol,
+		u32 word, u8 bits)
+{
+	/* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */
+
+	/* clock starts at inactive polarity */
+	for (word <<= (32 - bits); likely(bits); bits--) {
+
+		/* setup MSB (to slave) on leading edge */
+		setsck(spi, !cpol);
+		setmosi(spi, word & (1 << 31));
+		spidelay(nsecs); /* T(setup) */
+
+		setsck(spi, cpol);
+		spidelay(nsecs);
+
+		/* sample MSB (from slave) on trailing edge */
+		word <<= 1;
+		word |= getmiso(spi);
+	}
+	return word;
+}
Signature · 7 lines
1.9.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

PATCH v2 3/5 MIPS: ar9331.dtsi: add SPI master

In reply to Antony Pavlov
---
 arch/mips/dts/ar9331.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)
arch/mips/dts/ar9331.dtsi +6 -0
index 890fda8..9485fbf 100644
@@ -22,5 +22,11 @@
 			reg = <0xb8050000 0x48>;
 			#clock-cells = <1>;
 		};
+
+		spi: spi@bf000000{
+			compatible = "qca,ath79-spi";
+			reg = <0xbf000000 0x01000000>;
+			status = "disabled";
+		};
 	};
 };
Signature · 7 lines
1.9.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH v2 5/5 MIPS: tplink-mr3020_defconfig: add SPI support

In reply to Antony Pavlov
---
 arch/mips/configs/tplink-mr3020_defconfig | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/mips/configs/tplink-mr3020_defconfig +6 -1
index 2e925d9..d249919 100644
@@ -14,16 +14,21 @@ CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_IOMEM=y
 CONFIG_CMD_MM=y
 CONFIG_CMD_SHA1SUM=y
+CONFIG_CMD_FLASH=y
 # CONFIG_CMD_BOOTM is not set
 CONFIG_CMD_RESET=y
 CONFIG_CMD_GO=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_OF_PROPERTY=y
 CONFIG_CMD_OF_NODE=y
+CONFIG_CMD_SPI=y
 CONFIG_CMD_CLK=y
 CONFIG_OFDEVICE=y
 CONFIG_DRIVER_SERIAL_AR933X=y
-# CONFIG_SPI is not set
+CONFIG_DRIVER_SPI_ATH79=y
+CONFIG_MTD=y
+# CONFIG_MTD_OOB_DEVICE is not set
+CONFIG_MTD_M25P80=y
 CONFIG_MD5=y
 CONFIG_SHA224=y
 CONFIG_SHA256=y
Signature · 7 lines
1.9.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#6 lore raw
In reply to Antony Pavlov
Quoted 5 lines · Antony Pavlov

This patchseries adds the SPI controller driver for Atheros AR7XXX/AR9XXX SoCs. The driver uses bitbang SPI driver infrastructure from linux kernel.

Changes since v1:
* spi: ath79: fix ath79_spi_setup() return error codes

Applied, thanks

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox