Skip to contentSkip to conversation

SPI ThunderX driver

PATCH Superseded Jan Glauber 3 participants 10 messages Jul 28, 2016 – Aug 2, 2016 SPI

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover SPI ThunderX driver

This series adds support for SPI on Cavium's ThunderX (arm64). The SPI hardware is the same as on MIPS Octeon, the only difference is that the device appears as a PCI device. To avoid copy and paste of the Octeon driver I've moved the common parts into a shared file.

The series was tested on MIPS (Edge Router PRO and cn71xx) and ThunderX.

Changes to v1:
- Changed Kconfig depencency for ThunderX
- Merged clock setup functions with main probe/remove
- Fail if SPI DT entry misses clock reference
- Removed debug prints at end of probe
- Removed unneeded includes from spi-cavium.c
- Dropped merged patches

thanks,
Jan

--------------

Jan Glauber (2):
spi: octeon: Split driver into Octeon specific and common parts
spi: octeon: Add thunderx driver

 drivers/spi/Kconfig                        |   7 ++
 drivers/spi/Makefile                       |   3 +
 drivers/spi/spi-cavium-octeon.c            | 102 +++++++++++++++++++++
 drivers/spi/spi-cavium-thunderx.c          | 140 +++++++++++++++++++++++++++++
 drivers/spi/{spi-octeon.c => spi-cavium.c} | 122 +------------------------
 drivers/spi/spi-cavium.h                   |  34 +++++++
 6 files changed, 288 insertions(+), 120 deletions(-)
 create mode 100644 drivers/spi/spi-cavium-octeon.c
 create mode 100644 drivers/spi/spi-cavium-thunderx.c
 rename drivers/spi/{spi-octeon.c => spi-cavium.c} (54%)
Signature · 6 lines
2.9.0.rc0.21.g7777322

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH v2 1/2 spi: octeon: Split driver into Octeon specific and common parts

Separate driver probing from SPI transfer functions.

---
 drivers/spi/Makefile                       |   1 +
 drivers/spi/spi-cavium-octeon.c            | 102 ++++++++++++++++++++++++
 drivers/spi/{spi-octeon.c => spi-cavium.c} | 122 +----------------------------
 drivers/spi/spi-cavium.h                   |  31 ++++++++
 4 files changed, 136 insertions(+), 120 deletions(-)
 create mode 100644 drivers/spi/spi-cavium-octeon.c
 rename drivers/spi/{spi-octeon.c => spi-cavium.c} (54%)
drivers/spi/Makefile +1 -0
index 3c74d00..185367e 100644
@@ -56,6 +56,7 @@ obj-$(CONFIG_SPI_MT65XX)                += spi-mt65xx.o
 obj-$(CONFIG_SPI_MXS)			+= spi-mxs.o
 obj-$(CONFIG_SPI_NUC900)		+= spi-nuc900.o
 obj-$(CONFIG_SPI_OC_TINY)		+= spi-oc-tiny.o
+spi-octeon-objs				:= spi-cavium.o spi-cavium-octeon.o
 obj-$(CONFIG_SPI_OCTEON)		+= spi-octeon.o
 obj-$(CONFIG_SPI_OMAP_UWIRE)		+= spi-omap-uwire.o
 obj-$(CONFIG_SPI_OMAP_100K)		+= spi-omap-100k.o
drivers/spi/spi-cavium-octeon.c new file +102 -0

102 lines not on this page · raw message

drivers/spi/spi-cavium.c renamed from drivers/spi/spi-octeon.c +2 -120

142 lines not on this page · raw message

drivers/spi/spi-cavium.h +31 -0
index d41dba5..88c5f36 100644
@@ -1,3 +1,32 @@
+#ifndef __SPI_CAVIUM_H
+#define __SPI_CAVIUM_H
+
+#define OCTEON_SPI_MAX_BYTES 9
+#define OCTEON_SPI_MAX_CLOCK_HZ 16000000
+
+struct octeon_spi_regs {
+	int config;
+	int status;
+	int tx;
+	int data;
+};
+
+struct octeon_spi {
+	void __iomem *register_base;
+	u64 last_cfg;
+	u64 cs_enax;
+	int sys_freq;
+	struct octeon_spi_regs regs;
+};
+
+#define OCTEON_SPI_CFG(x)	(x->regs.config)
+#define OCTEON_SPI_STS(x)	(x->regs.status)
+#define OCTEON_SPI_TX(x)	(x->regs.tx)
+#define OCTEON_SPI_DAT0(x)	(x->regs.data)
+
+int octeon_spi_transfer_one_message(struct spi_master *master,
+				    struct spi_message *msg);
+
 /* MPI register descriptions */
 
 #define CVMX_MPI_CFG (CVMX_ADD_IO_SEG(0x0001070000001000ull))
@@ -296,3 +325,5 @@ union cvmx_mpi_tx {
 	struct cvmx_mpi_tx_s cn66xx;
 	struct cvmx_mpi_tx_cn61xx cnf71xx;
 };
+
+#endif /* __SPI_CAVIUM_H */
Signature · 1 line
2.9.0.rc0.21.g7777322
maintainer
#2 lore raw

Re: [PATCH v2 1/2] spi: octeon: Split driver into Octeon specific and common parts

Quoted 1 line · Jan Glauber

Separate driver probing from SPI transfer functions.

This doesn't apply against current code as an earlier version of it was already applied. Please don't resubmit already applied code, please send incremental updates against current code for any changes that are needed.

#3 lore raw

PATCH v2 2/2 spi: octeon: Add thunderx driver

In reply to Jan Glauber

Add ThunderX SPI driver using the shared part from the Octeon driver. The main difference of the ThunderX driver is that it is a PCI device so probing is different. The system clock settings can be specified in device tree.

---
 drivers/spi/Kconfig               |   7 ++
 drivers/spi/Makefile              |   2 +
 drivers/spi/spi-cavium-thunderx.c | 140 ++++++++++++++++++++++++++++++++++++++
 drivers/spi/spi-cavium.h          |   3 +
 4 files changed, 152 insertions(+)
 create mode 100644 drivers/spi/spi-cavium-thunderx.c
drivers/spi/Kconfig +7 -0
index 4b931ec..e0ee112 100644
@@ -630,6 +630,13 @@ config SPI_TEGRA20_SLINK
 	help
 	  SPI driver for Nvidia Tegra20/Tegra30 SLINK Controller interface.
 
+config SPI_THUNDERX
+	tristate "Cavium ThunderX SPI controller"
+	depends on (ARM64 || CONFIG_TEST) && 64BIT && PCI
+	help
+	  SPI host driver for the hardware found on Cavium ThunderX
+	  SOCs.
+
 config SPI_TOPCLIFF_PCH
 	tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) SPI"
 	depends on PCI && (X86_32 || MIPS || COMPILE_TEST)
drivers/spi/Makefile +2 -0
index 185367e..133364b 100644
@@ -91,6 +91,8 @@ obj-$(CONFIG_SPI_TEGRA114)		+= spi-tegra114.o
 obj-$(CONFIG_SPI_TEGRA20_SFLASH)	+= spi-tegra20-sflash.o
 obj-$(CONFIG_SPI_TEGRA20_SLINK)		+= spi-tegra20-slink.o
 obj-$(CONFIG_SPI_TLE62X0)		+= spi-tle62x0.o
+spi-thunderx-objs			:= spi-cavium.o spi-cavium-thunderx.o
+obj-$(CONFIG_SPI_THUNDERX)		+= spi-thunderx.o
 obj-$(CONFIG_SPI_TOPCLIFF_PCH)		+= spi-topcliff-pch.o
 obj-$(CONFIG_SPI_TXX9)			+= spi-txx9.o
 obj-$(CONFIG_SPI_XCOMM)		+= spi-xcomm.o
drivers/spi/spi-cavium-thunderx.c new file +140 -0

140 lines not on this page · raw message

drivers/spi/spi-cavium.h +3 -0
index 88c5f36..1f91d61 100644
@@ -1,6 +1,8 @@
 #ifndef __SPI_CAVIUM_H
 #define __SPI_CAVIUM_H
 
+#include <linux/clk.h>
+
 #define OCTEON_SPI_MAX_BYTES 9
 #define OCTEON_SPI_MAX_CLOCK_HZ 16000000
 
@@ -17,6 +19,7 @@ struct octeon_spi {
 	u64 cs_enax;
 	int sys_freq;
 	struct octeon_spi_regs regs;
+	struct clk *clk;
 };
 
 #define OCTEON_SPI_CFG(x)	(x->regs.config)
Signature · 6 lines
2.9.0.rc0.21.g7777322

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#4 lore raw

Re: [PATCH v2 2/2] spi: octeon: Add thunderx driver

drivers/spi/Kconfig config SPI_TEGRA20_SLINK · line 635

Quoted 3 lines · Jan Glauber
drivers/spi/Kconfig +3 -0
+config SPI_THUNDERX
+	tristate "Cavium ThunderX SPI controller"
+	depends on (ARM64 || CONFIG_TEST) && 64BIT && PCI

You mean COMPILE_TEST.

drivers/spi/spi-cavium-thunderx.c line 59

Quoted 3 lines
drivers/spi/spi-cavium-thunderx.c new file +3 -0
+	p->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(p->clk))
+		goto out_unmap;

We're now just using the normal clock API which is good but I'm now unclear what is going to ensure that the clock is there - is there some other change elsewhere that I'm not aware of? We're also not passing the resulting error code back to the caller which will break deferred probe.

drivers/spi/spi-cavium-thunderx.c line 90

Quoted 4 lines
drivers/spi/spi-cavium-thunderx.c new file +4 -0
+out_clock:
+	clk_disable_unprepare(p->clk);
+out_clock_devm:
+	devm_clk_put(dev, p->clk);

There's no point in using managed allocations if you're going to manually free things...

#5 lore raw

Re: [PATCH v2 2/2] spi: octeon: Add thunderx driver

Quoted 7 lines · Mark Brown

drivers/spi/Kconfig config SPI_TEGRA20_SLINK · line 635

Quoted 3 lines · Jan Glauber
drivers/spi/Kconfig +3 -0
+config SPI_THUNDERX
+	tristate "Cavium ThunderX SPI controller"
+	depends on (ARM64 || CONFIG_TEST) && 64BIT && PCI

You mean COMPILE_TEST.

Yes, we will fix that typo.

Quoted 8 lines

drivers/spi/spi-cavium-thunderx.c line 59

Quoted 4 lines
drivers/spi/spi-cavium-thunderx.c new file +3 -0
+	p->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(p->clk))
+		goto out_unmap;

We're now just using the normal clock API which is good but I'm now unclear what is going to ensure that the clock is there - is there some other change elsewhere that I'm not aware of?

The clock is an integral part of the SoC and is always running, so it will always be there. All we want to know is the frequency, which is supplied by the device tree clock-bindings framework

Quoted 4 lines

We're also not passing
the resulting error code back to the caller which will break deferred probe.

Yes, we should do that.

Quoted 7 lines

drivers/spi/spi-cavium-thunderx.c line 90

Quoted 4 lines
drivers/spi/spi-cavium-thunderx.c new file +4 -0
+out_clock:
+	clk_disable_unprepare(p->clk);
+out_clock_devm:
+	devm_clk_put(dev, p->clk);

There's no point in using managed allocations if you're going to manually free things...

Yes, we should let the automatic cleanup do its work here.

Probably we should consider using pcim_iomap(...) as well

Quoted 1 line
maintainer
#6 lore raw

Re: [PATCH v2 2/2] spi: octeon: Add thunderx driver

Quoted 11 lines · David Daney
Quoted 9 lines · Mark Brown

drivers/spi/spi-cavium-thunderx.c line 59

Quoted 3 lines · Jan Glauber
drivers/spi/spi-cavium-thunderx.c new file +3 -0
+	p->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(p->clk))
+		goto out_unmap;

We're now just using the normal clock API which is good but I'm now unclear what is going to ensure that the clock is there - is there some other change elsewhere that I'm not aware of?

Quoted 3 lines

The clock is an integral part of the SoC and is always running, so it will always be there. All we want to know is the frequency, which is supplied by the device tree clock-bindings framework

So there's something there that registers the clock? What is that thing on ACPI systems?

#7 lore raw

Re: [PATCH v2 2/2] spi: octeon: Add thunderx driver

Quoted 12 lines · Mark Brown
Quoted 10 lines · David Daney
Quoted 9 lines · Mark Brown

drivers/spi/spi-cavium-thunderx.c line 59

Quoted 3 lines · Jan Glauber
drivers/spi/spi-cavium-thunderx.c new file +3 -0
+	p->clk = devm_clk_get(dev, NULL);
+	if (IS_ERR(p->clk))
+		goto out_unmap;

We're now just using the normal clock API which is good but I'm now unclear what is going to ensure that the clock is there - is there some other change elsewhere that I'm not aware of?

Quoted 5 lines
Quoted 3 lines

The clock is an integral part of the SoC and is always running, so it will always be there. All we want to know is the frequency, which is supplied by the device tree clock-bindings framework

So there's something there that registers the clock?

Yes, when using OF device tree, standard device probing registers the clock.

Quoted 1 line

What is that thing on ACPI systems?

I don't know if it works ACPI, or if ACPI even has support for the clock framework. But does it matter? We are not currently using ACPI on systems where this driver is used.

In the future, if we ever need ACPI support, we will add support for it.

David.

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#8 lore raw

Re: [PATCH v2 2/2] spi: octeon: Add thunderx driver

Quoted 9 lines · David Daney
Quoted 1 line · Mark Brown

What is that thing on ACPI systems?

I don't know if it works ACPI, or if ACPI even has support for the clock framework. But does it matter? We are not currently using ACPI on systems where this driver is used.

In the future, if we ever need ACPI support, we will add support for it.

Oh, that's surprising - I thought these were server systems. With ACPI you need to use DMI data or something to instantiate the clock. In any case if you've got it working that should be OK.

#9 lore raw

Re: [PATCH v2 2/2] spi: octeon: Add thunderx driver

Quoted 5 lines · Mark Brown
Quoted 3 lines · David Daney
Quoted 1 line · Mark Brown

What is that thing on ACPI systems?

Quoted 7 lines
Quoted 5 lines

I don't know if it works ACPI, or if ACPI even has support for the clock framework. But does it matter? We are not currently using ACPI on systems where this driver is used.

In the future, if we ever need ACPI support, we will add support for it.

Oh, that's surprising - I thought these were server systems.

There are two broad classes of systems targeted by Cavium's arm64 based SoCs:

1) 2-node NUMA servers with 96 CPUs running UEFI firmware and ACPI. For these, any SPI buses are managed by the firmware and we don't need Kernel support.

2) Embedded controllers with 4 - 32 CPUs, typically running u-boot and OF device tree firmware descriptions. For these configurations, SPI buses managed by the kernel must be supported.

Quoted 4 lines

With ACPI
you need to use DMI data or something to instantiate the clock. In any case if you've got it working that should be OK.