public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2] spi: add altera spi controller support
@ 2010-03-23  3:36 Thomas Chou
  2010-03-23 20:05 ` Scott McNutt
                   ` (8 more replies)
  0 siblings, 9 replies; 12+ messages in thread
From: Thomas Chou @ 2010-03-23  3:36 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
 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

diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index f112ed0..dfcbb8b 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -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
diff --git a/drivers/spi/altera_spi.c b/drivers/spi/altera_spi.c
new file mode 100644
index 0000000..7a021d0
--- /dev/null
+++ b/drivers/spi/altera_spi.c
@@ -0,0 +1,81 @@
+/*
+ * Altera SPI driver
+ *
+ * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * 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;
+}
-- 
1.6.6.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-04-28  2:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-23  3:36 [U-Boot] [PATCH v2] spi: add altera spi controller support Thomas Chou
2010-03-23 20:05 ` Scott McNutt
2010-03-23 21:29 ` Mike Frysinger
2010-03-23 21:43   ` Scott McNutt
2010-03-26  3:23 ` [U-Boot] [PATCH v3] " Thomas Chou
2010-03-26  3:31   ` Mike Frysinger
2010-03-26  5:55 ` [U-Boot] [PATCH v4] " Thomas Chou
2010-03-28  4:08 ` [U-Boot] [PATCH v5 tabify] " Thomas Chou
2010-04-22  4:21 ` [U-Boot] [PATCH v6] " Thomas Chou
2010-04-22  4:39 ` [U-Boot] [PATCH v7] " Thomas Chou
2010-04-27  2:01 ` [U-Boot] [PATCH v8] " Thomas Chou
2010-04-28  2:45 ` [U-Boot] [PATCH v9] " Thomas Chou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox