[U-Boot] [PATCH RFC 2/7] MIPS: AR7240: SPI drivers for ar7240
Nikolaos Pasaloukos
Nikolaos.Pasaloukos at imgtec.com
Fri Nov 29 10:48:03 CET 2013
Add SPI drivers for ar7240 SoC
Signed-off-by: Nikolaos Pasaloukos <Nikolaos.Pasaloukos at imgtec.com>
Cc: Jagannadha Sutradharudu Teki <jagannadh.teki at gmail.com>
---
drivers/spi/Makefile | 1 +
drivers/spi/ar7240_spi.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 98 insertions(+)
create mode 100644 drivers/spi/ar7240_spi.c
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 27902fe..61fb58d 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -10,6 +10,7 @@ obj-y += spi.o
obj-$(CONFIG_ALTERA_SPI) += altera_spi.o
obj-$(CONFIG_ANDES_SPI) += andes_spi.o
+obj-$(CONFIG_AR7240_SPI) += ar7240_spi.o
obj-$(CONFIG_ARMADA100_SPI) += armada100_spi.o
obj-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
obj-$(CONFIG_ATMEL_SPI) += atmel_spi.o
diff --git a/drivers/spi/ar7240_spi.c b/drivers/spi/ar7240_spi.c
new file mode 100644
index 0000000..0b59bd2
--- /dev/null
+++ b/drivers/spi/ar7240_spi.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2013 Imagination Technologies
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ */
+#include <common.h>
+#include <spi.h>
+#include <malloc.h>
+#include <asm/io.h>
+#include <asm/ar7240_addrspace.h>
+
+#define AR_SPI_CLK_L 0x0000
+#define AR_SPI_CLK_H 0x0100
+
+#define ar_be_msb(_val, _i) ((_val) >> (7 - _i) & 0x01)
+
+void spi_init()
+{
+}
+
+struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
+ unsigned int max_hz, unsigned int mode)
+{
+ struct spi_slave *ar_slave;
+
+ if (!spi_cs_is_valid(bus, cs))
+ return NULL;
+
+ ar_slave = spi_alloc_slave_base(bus, cs);
+ if (!ar_slave)
+ return NULL;
+
+ debug("%s: bus:%i cs:%i\n", __func__, bus, cs);
+
+ return ar_slave;
+}
+
+void spi_free_slave(struct spi_slave *slave)
+{
+ debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs);
+ free(slave);
+}
+
+int spi_claim_bus(struct spi_slave *slave)
+{
+ ar_reg_wr(&ar7240_spi->function_select, 1);
+ while (ar_reg_rd(&ar7240_spi->function_select) != 1)
+ ;
+ return 0;
+}
+
+void spi_release_bus(struct spi_slave *slave)
+{
+ ar_reg_wr(&ar7240_spi->function_select, 0);
+ while (ar_reg_rd(&ar7240_spi->function_select) == 1)
+ ;
+}
+
+int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
+ const void *dout, void *din, unsigned long flags)
+{
+ unsigned int len;
+ const uint8_t *txp = dout;
+ uint8_t *rxp = din;
+ uint8_t value;
+ uint32_t ctl;
+ int i;
+
+ len = bitlen / 8;
+
+ if (flags & SPI_XFER_BEGIN)
+ spi_cs_activate(slave);
+
+ ctl = ar_reg_rd(&ar7240_spi->io_control) & 0x70000;
+ for (; len != 0; len--) {
+ if (txp)
+ value = *txp++;
+ else
+ value = 0;
+ for (i = 0; i < 8; i++) {
+ ar_reg_wr(&ar7240_spi->io_control, ctl | AR_SPI_CLK_L |
+ ar_be_msb(value, i));
+ ar_reg_wr(&ar7240_spi->io_control, ctl | AR_SPI_CLK_H |
+ ar_be_msb(value, i));
+ }
+ if (rxp) {
+ value = ar_reg_rd(&ar7240_spi->read_data);
+ *rxp++ = value;
+ }
+ }
+ ar_reg_wr(&ar7240_spi->io_control, ctl | AR_SPI_CLK_L);
+
+ if (flags & SPI_XFER_END)
+ spi_cs_deactivate(slave);
+
+ return 0;
+}
--
1.8.3.2
More information about the U-Boot
mailing list