Skip to contentSkip to conversation

spi: add support for ARM PL022 SPI controller

PATCH New Quentin Schulz 3 participants 7 messages Aug 31, 2018 – Sep 26, 2018

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

PATCH v2 1/3 spi: add support for ARM PL022 SPI controller

This adds support for the ARM PL022 SPI controller for the standard variant (0x00041022) which has a 16bit wide and 8 locations deep TX/RX FIFO.

A few parts were borrowed from the Linux kernel driver.

Cc Armando Visconti <[email protected]>
Cc Vipin Kumar <[email protected]>

---

v2:
- move header file to include/dm/platform_data,
- replace REGA(x) by x + REGA,
- surround DT specific code with #define !defined(CONFIG_OF_PLATDATA),
- fix tmp speed being stored in a u16 which overflowed and returned the minimum possible rate,
- fix speed computation to be the closest to the requested value, not only the closest *below* this value,
- init best_* values so that they can safely be used even if no best value is found,
- flush FIFO RX queue after the controller is enabled makes more sense to me,

 drivers/spi/Kconfig                  |   8 +-
 drivers/spi/Makefile                 |   1 +-
 drivers/spi/pl022_spi.c              | 338 ++++++++++++++++++++++++++++-
 include/dm/platform_data/pl022_spi.h |  28 ++-
 4 files changed, 375 insertions(+)
 create mode 100644 drivers/spi/pl022_spi.c
 create mode 100644 include/dm/platform_data/pl022_spi.h
drivers/spi/Kconfig +8 -0
index dcd719f..7d4d47d 100644
@@ -125,6 +125,14 @@ config PIC32_SPI
 	  to access the SPI NOR flash, MMC-over-SPI on platforms based on
 	  Microchip PIC32 family devices.
 
+config PL022_SPI
+	bool "ARM AMBA PL022 SSP controller driver"
+	depends on ARM
+	help
+	  This selects the ARM(R) AMBA(R) PrimeCell PL022 SSP
+	  controller. If you have an embedded system with an AMBA(R)
+	  bus and a PL022 controller, say Y or M here.
+
 config RENESAS_RPC_SPI
 	bool "Renesas RPC SPI driver"
 	depends on RCAR_GEN3
drivers/spi/Makefile +1 -0
index 728e30c..6679987 100644
@@ -38,6 +38,7 @@ obj-$(CONFIG_MXS_SPI) += mxs_spi.o
 obj-$(CONFIG_ATCSPI200_SPI) += atcspi200_spi.o
 obj-$(CONFIG_OMAP3_SPI) += omap3_spi.o
 obj-$(CONFIG_PIC32_SPI) += pic32_spi.o
+obj-$(CONFIG_PL022_SPI) += pl022_spi.o
 obj-$(CONFIG_RENESAS_RPC_SPI) += renesas_rpc_spi.o
 obj-$(CONFIG_ROCKCHIP_SPI) += rk_spi.o
 obj-$(CONFIG_SANDBOX_SPI) += sandbox_spi.o
drivers/spi/pl022_spi.c new file +338 -0

338 lines not on this page · raw message

include/dm/platform_data/pl022_spi.h new file +28 -0
new file mode 100644
index 0000000..77fe6da
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2018
+ * Quentin Schulz, Bootlin, quentin.schulz at bootlin.com
+ *
+ * Structure for use with U_BOOT_DEVICE for pl022 SPI devices or to use
+ * in ofdata_to_platdata.
+ */
+
+#ifndef __PL022_SPI_H__
+#define __PL022_SPI_H__
+
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+#include <clk.h>
+#endif
+#include <fdtdec.h>
+
+struct pl022_spi_pdata {
+	fdt_addr_t addr;
+	fdt_size_t size;
+#if !CONFIG_IS_ENABLED(OF_PLATDATA)
+	struct clk clk;
+#else
+	unsigned int freq;
+#endif
+};
+
+#endif

base-commit: b3e29c65aa7bda80cba063433878ebfcd3bb7601

Signature · 1 line
git-series 0.9.1
#1 lore raw

PATCH v2 2/3 arm: spear: enable SSP1, 2 and 3 clocks when SPI controller driver is built

SPI controllers SSP1, 2 and 3 require to enable their respective clocks. Let's enable them only when the SPI controller driver is built.

---

v2:
- define and use constants for enabling SSP1/2/3 clocks when the controller is built

 arch/arm/cpu/arm926ejs/spear/cpu.c         | 3 +++
 arch/arm/include/asm/arch-spear/spr_misc.h | 2 ++
 2 files changed, 5 insertions(+)
arch/arm/cpu/arm926ejs/spear/cpu.c +3 -0
index 6fc29e7..c572785 100644
@@ -52,6 +52,9 @@ int arch_cpu_init(void)
 #if defined(CONFIG_SPEAR_GPIO)
 	periph1_clken |= MISC_GPIO3ENB | MISC_GPIO4ENB;
 #endif
+#if defined(CONFIG_PL022_SPI)
+	periph1_clken |= MISC_SSP1ENB | MISC_SSP2ENB | MISC_SSP3ENB;
+#endif
 
 	writel(periph1_clken, &misc_p->periph1_clken);
 
arch/arm/include/asm/arch-spear/spr_misc.h +2 -0
index 65063fc..01b4b2b 100644
@@ -146,11 +146,13 @@ struct misc_regs {
 #define MISC_SMIENB			0x00200000
 #define MISC_GPIO3ENB			0x00040000
 #define MISC_GPT3ENB			0x00010000
+#define MISC_SSP3ENB			0x00004000
 #define MISC_GPIO4ENB			0x00002000
 #define MISC_GPT2ENB			0x00000800
 #define MISC_FSMCENB			0x00000200
 #define MISC_I2CENB			0x00000080
 #define MISC_SSP2ENB			0x00000070
+#define MISC_SSP1ENB			0x00000020
 #define MISC_UART0ENB			0x00000008
 
 /*   PERIPH_CLK_CFG   */
Signature · 1 line
git-series 0.9.1
#2 lore raw

PATCH v2 2/3 arm: spear: enable SSP1, 2 and 3 clocks when SPI controller driver is built

Quoted 4 lines · Quentin Schulz

SPI controllers SSP1, 2 and 3 require to enable their respective clocks. Let's enable them only when the SPI controller driver is built.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180926/e965ad9c/attachment.sig>
#3 lore raw

PATCH v2 3/3 arm: spear: fix enabling of SSP2 clock

In reply to Quentin Schulz

The SSP2 clock is at bit 6 in the register, so the value is 0x40 unlike the current 0x70 which enables the clock of UART2, SSP1 and SSP2.

---

added in v2

@Stefan: I think you'd want to test the FPGA on x600 again as it's using this constant. Having worked on a system close to the x600, I'm guessing that it'll work as fine as on my platform with this patch but better be sure than sorry.

 arch/arm/include/asm/arch-spear/spr_misc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/include/asm/arch-spear/spr_misc.h +1 -1
index 01b4b2b..0171119 100644
@@ -151,7 +151,7 @@ struct misc_regs {
 #define MISC_GPT2ENB			0x00000800
 #define MISC_FSMCENB			0x00000200
 #define MISC_I2CENB			0x00000080
-#define MISC_SSP2ENB			0x00000070
+#define MISC_SSP2ENB			0x00000040
 #define MISC_SSP1ENB			0x00000020
 #define MISC_UART0ENB			0x00000008
 
Signature · 1 line
git-series 0.9.1
#4 lore raw

PATCH v2 3/3 arm: spear: fix enabling of SSP2 clock

Quoted 4 lines · Quentin Schulz

The SSP2 clock is at bit 6 in the register, so the value is 0x40 unlike the current 0x70 which enables the clock of UART2, SSP1 and SSP2.

Quoted 8 lines

---

added in v2

@Stefan: I think you'd want to test the FPGA on x600 again as it's using this constant. Having worked on a system close to the x600, I'm guessing that it'll work as fine as on my platform with this patch but better be sure than sorry.

I don't have easily access to the x600 board right now. Please go ahead with this patch. I'm now informed about this change and will make some tests, if I get this board on my desk again.

Thanks,
Stefan

#5 lore raw

PATCH v2 3/3 arm: spear: fix enabling of SSP2 clock

In reply to Quentin Schulz
Quoted 5 lines · Quentin Schulz

The SSP2 clock is at bit 6 in the register, so the value is 0x40 unlike the current 0x70 which enables the clock of UART2, SSP1 and SSP2.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180926/a54d6f02/attachment.sig>
#6 lore raw

PATCH v2 1/3 spi: add support for ARM PL022 SPI controller

In reply to Quentin Schulz
Quoted 9 lines · Quentin Schulz

This adds support for the ARM PL022 SPI controller for the standard variant (0x00041022) which has a 16bit wide and 8 locations deep TX/RX FIFO.

A few parts were borrowed from the Linux kernel driver.

Cc Armando Visconti <[email protected]>
Cc Vipin Kumar <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180926/263ec0c3/attachment.sig>