Skip to contentSkip to conversation

arm: sunxi: Allwinner SPI driver

RFC PATCH New S.J.R. van Schaik 1 participant 5 messages Feb 10, 2017

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

cover arm: sunxi: Allwinner SPI driver

Hi,

The following patches implement a working SPI driver based on driver model for Allwinner (sunxi) devices. We have tested the driver on the A20 OLinuXino LIME 2 (sun7i) with a Winbond w25q128bv chip loading and booting a FIT image from the chip. The sun6i/sun8i/sun9i/sun50i code also builds properly, but still has to be tested on actual devices.

The additional SPI controllers (SPI1, SPI2, SPI3) are not yet supported by this driver because the clock gating code only sets up the clock for SPI0. We are going to implement this in the near future. It might make sense to migrate the clock code to a separate driver or at least to mach-sunxi.

We would like to hear some feedback to further improve these patches for mainline integration.

Yours sincerely,
Stephan.

S.J.R. van Schaik (4):
arch-sunxi: added missing AHB_GATE_OFFSET_SPIx defines for sun6i/sun9i
arch-sunxi: added SPI register definitions for sun4i/sun7i
arch-sunxi: added SPI register definitions for

    sun6i/sun8i/sun9i/sun50i

sunxi-spi: added SPI driver for Allwinner devices (sunxi)

 arch/arm/include/asm/arch-sunxi/clock_sun6i.h |   2 +
 arch/arm/include/asm/arch-sunxi/clock_sun9i.h |   4 +
 arch/arm/include/asm/arch-sunxi/spi.h         |  29 +++
 arch/arm/include/asm/arch-sunxi/spi_sun4i.h   |  53 +++++
 arch/arm/include/asm/arch-sunxi/spi_sun6i.h   |  56 +++++
 drivers/spi/Kconfig                           |   5 +
 drivers/spi/Makefile                          |   1 +
 drivers/spi/sunxi_spi.c                       | 329 ++++++++++++++++++++++++++
 8 files changed, 479 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-sunxi/spi.h
 create mode 100644 arch/arm/include/asm/arch-sunxi/spi_sun4i.h
 create mode 100644 arch/arm/include/asm/arch-sunxi/spi_sun6i.h
 create mode 100644 drivers/spi/sunxi_spi.c
Signature · 1 line
2.11.0
#1 lore raw

RFC PATCH 1/4 arm: sunxi: added missing AHB_GATE_OFFSET_SPIx defines for sun6i/sun9i

Added missing AHB_GATE_OFFSET_SPIx defines to enable/disable clock gating for SPI on the sun6i and sun9i platforms.

---
 arch/arm/include/asm/arch-sunxi/clock_sun6i.h | 2 ++
 arch/arm/include/asm/arch-sunxi/clock_sun9i.h | 4 ++++
 2 files changed, 6 insertions(+)
arch/arm/include/asm/arch-sunxi/clock_sun6i.h +2 -0
index 3f87672c62..fd778ddd50 100644
@@ -255,6 +255,8 @@ struct sunxi_ccm_reg {
 #define AHB_GATE_OFFSET_USB_EHCI0	26
 #endif
 #define AHB_GATE_OFFSET_USB0		24
+#define AHB_GATE_OFFSET_SPI1		21
+#define AHB_GATE_OFFSET_SPI0		20
 #define AHB_GATE_OFFSET_MCTL		14
 #define AHB_GATE_OFFSET_GMAC		17
 #define AHB_GATE_OFFSET_NAND0		13
arch/arm/include/asm/arch-sunxi/clock_sun9i.h +4 -0
index 0aeb6408d8..224fc47798 100644
@@ -195,6 +195,10 @@ struct sunxi_ccm_reg {
 
 /* ahb gate1 field */
 #define AHB_GATE_OFFSET_DMA		24
+#define AHB_GATE_OFFSET_SPI3		23
+#define AHB_GATE_OFFSET_SPI2		22
+#define AHB_GATE_OFFSET_SPI1		21
+#define AHB_GATE_OFFSET_SPI0		20
 
 /* apb1_gate fields */
 #define APB1_GATE_UART_SHIFT		16
Signature · 1 line
2.11.0
#2 lore raw

RFC PATCH 2/4 arm: sunxi: added SPI register definitions for sun4i/sun7i

In reply to S.J.R. van Schaik

Introduces SPI registers for sun4i/sun7i by adding struct sunxi_spi_regs and flags.

---
 arch/arm/include/asm/arch-sunxi/spi.h       | 29 ++++++++++++++++
 arch/arm/include/asm/arch-sunxi/spi_sun4i.h | 53 +++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-sunxi/spi.h
 create mode 100644 arch/arm/include/asm/arch-sunxi/spi_sun4i.h
arch/arm/include/asm/arch-sunxi/spi.h new file +29 -0
new file mode 100644
index 0000000000..bbc0ee1550
@@ -0,0 +1,29 @@
+/*
+ * (C) Copyright 2017 Whitebox Systems / Northend Systems B.V.
+ * Stephan van Schaik <[email protected]>
+ * Merlijn Wajer <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _SUNXI_SPI_H
+#define _SUNXI_SPI_H
+
+#if defined(CONFIG_MACH_SUN6I) || defined(CONFIG_MACH_SUN8I) || \
+	defined(CONFIG_MACH_SUN9I) || defined(CONFIG_MACH_SUN50I)
+#include <asm/arch/spi_sun6i.h>
+#else
+#include <asm/arch/spi_sun4i.h>
+#endif
+
+#define SUNXI_SPI_BURST_CNT(cnt)	((cnt) & 0xffffff)
+#define SUNXI_SPI_XMIT_CNT(cnt)		((cnt) & 0xffffff)
+
+#define SUNXI_SPI_CLK_CTL_CDR2_MASK	0xff
+#define SUNXI_SPI_CLK_CTL_CDR2(div)	((div) & SUNXI_SPI_CLK_CTL_CDR2_MASK)
+#define SUNXI_SPI_CLK_CTL_CDR1_MASK	0xf
+#define SUNXI_SPI_CLK_CTL_CDR1(div)		\
+	(((div) & SUNXI_SPI_CLK_CTL_CDR1_MASK) << 8)
+#define SUNXI_SPI_CLK_CTL_DRS		BIT(12)
+
+#endif /* _SUNXI_SPI_H */
arch/arm/include/asm/arch-sunxi/spi_sun4i.h new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.11.0
#3 lore raw

RFC PATCH 3/4 arm: sunxi: added SPI register definitions for sun6i/sun8i/sun9i/sun50i

In reply to S.J.R. van Schaik

Introduces SPI registers for sun6i/sun8i/sun9i/sun50i by adding struct sunxi_spi_regs and flags.

---
 arch/arm/include/asm/arch-sunxi/spi_sun6i.h | 56 +++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-sunxi/spi_sun6i.h
arch/arm/include/asm/arch-sunxi/spi_sun6i.h new file +56 -0
new file mode 100644
index 0000000000..379561d021
@@ -0,0 +1,56 @@
+/*
+ * (C) Copyright 2017 Whitebox Systems / Northend Systems B.V.
+ * Stephan van Schaik <[email protected]>
+ * Merlijn Wajer <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _SUNXI_SPI_SUN6I_H
+#define _SUNXI_SPI_SUN6I_H
+
+struct sunxi_spi_regs {
+	uint32_t unused0[1];
+	uint32_t glb_ctl;	/* 0x04 */
+	uint32_t xfer_ctl;	/* 0x08 */
+	uint32_t unused1[1];
+	uint32_t int_ctl;	/* 0x10 */
+	uint32_t int_sta;	/* 0x14 */
+	uint32_t fifo_ctl;	/* 0x18 */
+	uint32_t fifo_sta;	/* 0x1c */
+	uint32_t wait;		/* 0x20 */
+	uint32_t clk_ctl;	/* 0x24 */
+	uint32_t unused2[2];
+	uint32_t burst_cnt;	/* 0x30 */
+	uint32_t xmit_cnt;	/* 0x34 */
+	uint32_t burst_ctl;	/* 0x38 */
+	uint32_t unused3[113];
+	uint32_t tx_data;	/* 0x200 */
+	uint32_t unused4[63];
+	uint32_t rx_data;	/* 0x300 */
+};
+
+#define SUNXI_SPI_CTL_ENABLE		BIT(0)
+#define SUNXI_SPI_CTL_MASTER		BIT(1)
+#define SUNXI_SPI_CTL_TP		BIT(7)
+#define SUNXI_SPI_CTL_SRST		BIT(31)
+
+#define SUNXI_SPI_CTL_CPHA		BIT(0)
+#define SUNXI_SPI_CTL_CPOL		BIT(1)
+#define SUNXI_SPI_CTL_CS_ACTIVE_LOW	BIT(2)
+#define SUNXI_SPI_CTL_CS_MASK		0x30
+#define SUNXI_SPI_CTL_CS(cs)		(((cs) << 4) & SUNXI_SPI_CTL_CS_MASK)
+#define SUNXI_SPI_CTL_CS_MANUAL		BIT(6)
+#define SUNXI_SPI_CTL_CS_LEVEL		BIT(7)
+#define SUNXI_SPI_CTL_DHB		BIT(8)
+#define SUNXI_SPI_CTL_XCH		BIT(31)
+
+#define SUNXI_SPI_CTL_RF_RST		BIT(15)
+#define SUNXI_SPI_CTL_TF_RST		BIT(31)
+
+#define SUNXI_SPI_FIFO_RF_CNT_MASK	0xff
+#define SUNXI_SPI_FIFO_RF_CNT_BITS	0
+#define SUNXI_SPI_FIFO_TF_CNT_MASK	0xff
+#define SUNXI_SPI_FIFO_TF_CNT_BITS	16
+
+#endif /* _SUNXI_SPI_SUN6I_H */
Signature · 1 line
2.11.0
#4 lore raw

RFC PATCH 4/4 arm: sunxi: added SPI driver for Allwinner devices

In reply to S.J.R. van Schaik

Implements a driver model SPI driver for Allwinner devices (sunxi).

---
 drivers/spi/Kconfig     |   5 +
 drivers/spi/Makefile    |   1 +
 drivers/spi/sunxi_spi.c | 329 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 335 insertions(+)
 create mode 100644 drivers/spi/sunxi_spi.c
drivers/spi/Kconfig +5 -0
index f3f7dbe089..d243e69a3c 100644
@@ -132,6 +132,11 @@ config STM32_QSPI
 	  used to access the SPI NOR flash chips on platforms embedding
 	  this ST IP core.
 
+config SUNXI_SPI
+	bool "Allwinner SPI driver"
+	help
+	  Enable the Allwinner SPI driver.
+
 config TEGRA114_SPI
 	bool "nVidia Tegra114 SPI driver"
 	help
drivers/spi/Makefile +1 -0
index fa9a1d2496..b2011f4da3 100644
@@ -43,6 +43,7 @@ obj-$(CONFIG_SANDBOX_SPI) += sandbox_spi.o
 obj-$(CONFIG_SH_SPI) += sh_spi.o
 obj-$(CONFIG_SH_QSPI) += sh_qspi.o
 obj-$(CONFIG_STM32_QSPI) += stm32_qspi.o
+obj-$(CONFIG_SUNXI_SPI) += sunxi_spi.o
 obj-$(CONFIG_TEGRA114_SPI) += tegra114_spi.o
 obj-$(CONFIG_TEGRA20_SFLASH) += tegra20_sflash.o
 obj-$(CONFIG_TEGRA20_SLINK) += tegra20_slink.o
drivers/spi/sunxi_spi.c new file +329 -0

329 lines not on this page · raw message

Signature · 1 line
2.11.0