Skip to contentSkip to conversation

spi: add altera spi controller support

PATCH Superseded Thomas Chou 3 participants 12 messages Mar 23, 2010 – Apr 28, 2010 SPI

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 spi: add altera spi controller support

This patch adds the driver of altera spi controller, which is also used as epcs/spi flash controller.

With the spi_flash driver, they can replace the epcs driver at cpu/nios2/epcs.c.

---
 drivers/spi/Makefile     |    1 +
 drivers/spi/altera_spi.c |   81 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/altera_spi.c
drivers/spi/Makefile +1 -0
index f112ed0..dfcbb8b 100644
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libspi.a
 
+COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o
 COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o
 COBJS-$(CONFIG_BFIN_SPI) += bfin_spi.o
drivers/spi/altera_spi.c new file +81 -0

81 lines not on this page · raw message

Signature · 1 line
1.6.6.1
Applied
#1 lore raw

PATCH v2 1/1 spi: add altera spi controller support

Applied.
Thanks,
--Scott

Quoted 112 lines · Thomas Chou

This patch adds the driver of altera spi controller, which is also used as epcs/spi flash controller.

With the spi_flash driver, they can replace the epcs driver at cpu/nios2/epcs.c.

---
 drivers/spi/Makefile     |    1 +
 drivers/spi/altera_spi.c |   81 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/altera_spi.c
drivers/spi/Makefile +1 -0
index f112ed0..dfcbb8b 100644
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libspi.a
 
+COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o
 COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o
 COBJS-$(CONFIG_BFIN_SPI) += bfin_spi.o
drivers/spi/altera_spi.c new file +81 -0
new file mode 100644
index 0000000..7a021d0
@@ -0,0 +1,81 @@
+/*
+ * Altera SPI driver
+ *
+ * Copyright (C) 2010 Thomas Chou <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <common.h>
+#include <malloc.h>
+#include <spi.h>
+#include <asm/io.h>
+#include <nios2-io.h>
+
+static nios_spi_t *nios_spi = (nios_spi_t *)CONFIG_SYS_SPI_BASE;
+
+void spi_init (void)
+{
+	/* empty read buffer */
+	if (readl (&nios_spi->status) & NIOS_SPI_RRDY)
+		readl (&nios_spi->rxdata);
+	return;
+}
+
+struct spi_slave *spi_setup_slave (unsigned int bus, unsigned int cs,
+				  unsigned int max_hz, unsigned int mode)
+{
+	struct spi_slave *slave;
+
+	slave = malloc (sizeof(struct spi_slave));
+	if (!slave)
+		return NULL;
+
+	slave->bus = bus;
+	slave->cs = cs;
+
+	return slave;
+}
+
+void spi_free_slave (struct spi_slave *slave)
+{
+	free (slave);
+}
+
+int spi_claim_bus (struct spi_slave *slave)
+{
+	return 0;
+}
+
+void spi_release_bus (struct spi_slave *slave)
+{
+	return;
+}
+
+int spi_xfer (struct spi_slave *slave, unsigned int bitlen, const void *dout,
+	     void *din, unsigned long flags)
+{
+	int i, iter = bitlen >> 3;
+	const uchar *txp = dout;
+	uchar *rxp = din;
+	uchar d;
+
+	if (flags & SPI_XFER_BEGIN) {
+		writel (1 << slave->cs, &nios_spi->slaveselect);
+		writel (NIOS_SPI_SSO, &nios_spi->control);
+	}
+
+	for (i = 0; i < iter; i++) {
+		writel (txp ? txp[i] : 0, &nios_spi->txdata);
+		while (!(readl (&nios_spi->status) & NIOS_SPI_RRDY))
+			;
+		d = readl (&nios_spi->rxdata);
+		if (rxp)
+			rxp[i] = d;
+	}
+	if (flags & SPI_XFER_END)
+		writel (0, &nios_spi->control);
+
+	return 0;
+}
#2 lore raw

PATCH v2 1/1 spi: add altera spi controller support

In reply to Thomas Chou

drivers/spi/altera_spi.c line 14

Quoted 5 lines · On Monday 22 March 2010 23:36:19 Thomas Chou wrote:
drivers/spi/altera_spi.c new file +5 -0
+#include <common.h>
+#include <malloc.h>
+#include <spi.h>
+#include <asm/io.h>
+#include <nios2-io.h>

side note, but am i the only one who thinks nios headers in include/ is bad mojo ?

Quoted 1 line

+static nios_spi_t *nios_spi = (nios_spi_t *)CONFIG_SYS_SPI_BASE;

shouldnt this be based on the bus # so that you can support multiple ones at runtime ? i.e. you add a regs member to the spi slave struct and operate off that at runtime.

Quoted 1 line

+void spi_init (void)

i think the spaces should be consumed before the paren per LKML style

drivers/spi/altera_spi.c line 24

Quoted 6 lines
drivers/spi/altera_spi.c new file +6 -0
+{
+	/* empty read buffer */
+	if (readl (&nios_spi->status) & NIOS_SPI_RRDY)
+		readl (&nios_spi->rxdata);
+	return;
+}

useless return ...

drivers/spi/altera_spi.c line 31

Quoted 6 lines
drivers/spi/altera_spi.c new file +6 -0
+struct spi_slave *spi_setup_slave (unsigned int bus, unsigned int cs,
+				  unsigned int max_hz, unsigned int mode)
+{
+	struct spi_slave *slave;
+
+	slave = malloc (sizeof(struct spi_slave));

sizeof(*slave)

drivers/spi/altera_spi.c line 39

Quoted 8 lines
drivers/spi/altera_spi.c new file +8 -0
+	if (!slave)
+		return NULL;
+
+	slave->bus = bus;
+	slave->cs = cs;
+
+	return slave;
+}

shouldnt you be validating the bus/cs values here ? presumably you only have 1 bus atm, so bus != 0 is an error. and the cs is being used to write to an "unsigned slaveselect", so the range of values is at most 0...31 inclusive (assuming your hardware can actually support 32 CS's).

drivers/spi/altera_spi.c line 54

Quoted 9 lines
drivers/spi/altera_spi.c new file +9 -0
+int spi_claim_bus (struct spi_slave *slave)
+{
+	return 0;
+}
+
+void spi_release_bus (struct spi_slave *slave)
+{
+	return;
+}

i'm pretty sure you should be programming either nios_spi->slaveselect or nios_spi->control here rather than in the spi_xfer func ...

Quoted 16 lines

+int spi_xfer (struct spi_slave *slave, unsigned int bitlen, const void
*dout, + void *din, unsigned long flags)

drivers/spi/altera_spi.c new file +14 -0
+{
+	int i, iter = bitlen >> 3;
+	const uchar *txp = dout;
+	uchar *rxp = din;
+	uchar d;
+
+	if (flags & SPI_XFER_BEGIN) {
+		writel (1 << slave->cs, &nios_spi->slaveselect);
+		writel (NIOS_SPI_SSO, &nios_spi->control);
+	}
+
+	for (i = 0; i < iter; i++) {
+		writel (txp ? txp[i] : 0, &nios_spi->txdata);
+		while (!(readl (&nios_spi->status) & NIOS_SPI_RRDY))

drivers/spi/altera_spi.c line 81

Quoted 10 lines
drivers/spi/altera_spi.c new file +10 -0
+			;
+		d = readl (&nios_spi->rxdata);
+		if (rxp)
+			rxp[i] = d;
+	}
+	if (flags & SPI_XFER_END)
+		writel (0, &nios_spi->control);
+
+	return 0;
+}

since you only support multiples of 8 bytes here, your code should return an error when (bitlen & 0x7)

your XFER_END should force the CS to go low ... is that what the control does, or is it the slaveselect ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20100323/c7acb0fe/attachment.pgp

#3 lore raw

PATCH v2 1/1 spi: add altera spi controller support

Quoted 9 lines · On Monday 22 March 2010 23:36:19 Thomas Chou wrote:

drivers/spi/altera_spi.c line 14

Quoted 5 lines
drivers/spi/altera_spi.c new file +5 -0
+#include <common.h>
+#include <malloc.h>
+#include <spi.h>
+#include <asm/io.h>
+#include <nios2-io.h>

side note, but am i the only one who thinks nios headers in include/ is bad mojo ?

No. It's definitely bad mojo ... and has been for years (along with many other headers). We will be moving the nios headers soon. In the meantime, just don't drink any more kool-aid. ;-)

Regards,
--Scott

#4 lore raw

PATCH v3 1/1 spi: add altera spi controller support

In reply to Thomas Chou

This patch adds the driver of altera spi controller, which is also used as epcs/spi flash controller.

This driver support more than one spi bus, with base list declared #define CONFIG_SYS_ALTERA_SPI_LIST { BASE_0,BASE_1,... }

With the spi_flash driver, they can replace the epcs driver at cpu/nios2/epcs.c.

---
 drivers/spi/Makefile     |    1 +
 drivers/spi/altera_spi.c |  152 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/altera_spi.c
drivers/spi/Makefile +1 -0
index f112ed0..dfcbb8b 100644
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libspi.a
 
+COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o
 COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o
 COBJS-$(CONFIG_BFIN_SPI) += bfin_spi.o
drivers/spi/altera_spi.c new file +152 -0

152 lines not on this page · raw message

Signature · 1 line
1.6.6.1
#5 lore raw

PATCH v3 1/1 spi: add altera spi controller support

Review

Quoted 2 lines · On Thursday 25 March 2010 23:23:03 Thomas Chou wrote:
(quoted diff) +2 -0
+	if (bus >= (sizeof(altera_spi_base_list) / sizeof(ulong)))
+		return NULL;

ARRAY_SIZE(altera_spi_base_list) ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20100325/cd6f54de/attachment.pgp

#6 lore raw

PATCH v4 1/1 spi: add altera spi controller support

In reply to Thomas Chou

This patch adds the driver of altera spi controller, which is also used as epcs/spi flash controller.

This driver support more than one spi bus, with base list declared #define CONFIG_SYS_ALTERA_SPI_LIST { BASE_0,BASE_1,... }

With the spi_flash driver, they can replace the epcs driver at cpu/nios2/epcs.c.

---
 drivers/spi/Makefile     |    1 +
 drivers/spi/altera_spi.c |  152 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/altera_spi.c
drivers/spi/Makefile +1 -0
index f112ed0..dfcbb8b 100644
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libspi.a
 
+COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o
 COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o
 COBJS-$(CONFIG_BFIN_SPI) += bfin_spi.o
drivers/spi/altera_spi.c new file +152 -0

152 lines not on this page · raw message

Signature · 1 line
1.6.6.1
#7 lore raw

PATCH v5 1/1 spi: add altera spi controller support

In reply to Thomas Chou

This patch adds the driver of altera spi controller, which is also used as epcs/spi flash controller.

This driver support more than one spi bus, with base list declared #define CONFIG_SYS_ALTERA_SPI_LIST { BASE_0,BASE_1,... }

With the spi_flash driver, they can replace the epcs driver at cpu/nios2/epcs.c.

---
 drivers/spi/Makefile     |    1 +
 drivers/spi/altera_spi.c |  152 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/altera_spi.c
drivers/spi/Makefile +1 -0
index f112ed0..dfcbb8b 100644
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libspi.a
 
+COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o
 COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o
 COBJS-$(CONFIG_BFIN_SPI) += bfin_spi.o
drivers/spi/altera_spi.c new file +152 -0

152 lines not on this page · raw message

Signature · 1 line
1.6.6.1
#8 lore raw

PATCH v6 1/1 spi: add altera spi controller support

In reply to Thomas Chou

This patch adds the driver of altera spi controller, which is also used as epcs/spi flash controller.

This driver support more than one spi bus, with base list declared #define CONFIG_SYS_ALTERA_SPI_LIST { BASE_0,BASE_1,... }

With the spi_flash driver, they can replace the epcs driver at cpu/nios2/epcs.c.

---
v6 add cs activate deactive to work with legacy spi_mmc driver. v5 tabify.

 drivers/spi/Makefile     |    1 +
 drivers/spi/altera_spi.c |  152 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/altera_spi.c
drivers/spi/Makefile +1 -0
index f112ed0..dfcbb8b 100644
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libspi.a
 
+COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o
 COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o
 COBJS-$(CONFIG_BFIN_SPI) += bfin_spi.o
drivers/spi/altera_spi.c new file +152 -0

152 lines not on this page · raw message

Signature · 1 line
1.6.6.1
#9 lore raw

PATCH v7 1/1 spi: add altera spi controller support

In reply to Thomas Chou

This patch adds the driver of altera spi controller, which is also used as epcs/spi flash controller.

This driver support more than one spi bus, with base list declared #define CONFIG_SYS_ALTERA_SPI_LIST { BASE_0,BASE_1,... }

With the spi_flash driver, they can replace the epcs driver at cpu/nios2/epcs.c.

---
v7 add cs activate deactive to work with legacy spi_mmc driver. v6 wrong patch, same as v5.
v5 tabify.

 drivers/spi/Makefile     |    1 +
 drivers/spi/altera_spi.c |  168 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 169 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/altera_spi.c
drivers/spi/Makefile +1 -0
index f112ed0..dfcbb8b 100644
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libspi.a
 
+COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o
 COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o
 COBJS-$(CONFIG_BFIN_SPI) += bfin_spi.o
drivers/spi/altera_spi.c new file +168 -0

168 lines not on this page · raw message

Signature · 1 line
1.6.6.1
#10 lore raw

PATCH v8 1/1 spi: add altera spi controller support

In reply to Thomas Chou

This patch adds the driver of altera spi controller, which is also used as epcs/spi flash controller. It also works with mmc_spi driver.

This driver support more than one spi bus, with base list declared #define CONFIG_SYS_ALTERA_SPI_LIST { BASE_0,BASE_1,... }

---
v8 fix cs activate timing.
v7 add cs activate deactive to work with legacy spi_mmc driver. v6 wrong patch, same as v5.
v5 tabify.

 drivers/spi/Makefile     |    1 +
 drivers/spi/altera_spi.c |  169 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 170 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/altera_spi.c
drivers/spi/Makefile +1 -0
index f112ed0..dfcbb8b 100644
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libspi.a
 
+COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o
 COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o
 COBJS-$(CONFIG_BFIN_SPI) += bfin_spi.o
drivers/spi/altera_spi.c new file +169 -0

169 lines not on this page · raw message

Signature · 1 line
1.6.6.1
#11 lore raw

PATCH v9 1/1 spi: add altera spi controller support

In reply to Thomas Chou

This patch adds the driver of altera spi controller, which is also used as epcs/spi flash controller. It also works with mmc_spi driver.

This driver support more than one spi bus, with base list declared #define CONFIG_SYS_ALTERA_SPI_LIST { BASE_0,BASE_1,... }

---
v9 check bus in spi_cs_is_valid().
v8 fix cs activate timing.
v7 add cs activate deactive to work with legacy spi_mmc driver. v6 wrong patch, same as v5.
v5 tabify.

 drivers/spi/Makefile     |    1 +
 drivers/spi/altera_spi.c |  169 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 170 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/altera_spi.c
drivers/spi/Makefile +1 -0
index f112ed0..dfcbb8b 100644
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libspi.a
 
+COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o
 COBJS-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 COBJS-$(CONFIG_ATMEL_SPI) += atmel_spi.o
 COBJS-$(CONFIG_BFIN_SPI) += bfin_spi.o
drivers/spi/altera_spi.c new file +169 -0

169 lines not on this page · raw message

Signature · 1 line
1.6.6.1