Skip to contentSkip to conversation

SPI: Add SPI driver support for Marvell Armada100

PATCH Superseded Ajay Bhargav 3 participants 5 messages Sep 19, 2011

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 SPI: Add SPI driver support for Marvell Armada100

This patch provides support for SPI emulated over SSP for Marvell Armada100 SOC.

---
 arch/arm/include/asm/arch-armada100/spi.h |  111 ++++++++++++++++
 drivers/spi/Makefile                      |    1 +
 drivers/spi/armada100_spi.c               |  205 +++++++++++++++++++++++++++++
 3 files changed, 317 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-armada100/spi.h
 create mode 100644 drivers/spi/armada100_spi.c
arch/arm/include/asm/arch-armada100/spi.h new file +111 -0
new file mode 100644
index 0000000..85c2ccf
@@ -0,0 +1,111 @@
+/*
+ * (C) Copyright 2011
+ * eInfochips Ltd. <www.einfochips.com>
+ * Written-by: Ajay Bhargav <[email protected]>
+ *
+ * (C) Copyright 2010
+ * Marvell Semiconductor <www.marvell.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+
+#ifndef __ARMADA100_SPI_H_
+#define __ARMADA100_SPI_H_
+
+#include <asm/arch/armada100.h>
+
+#define CAT_BASE_ADDR(x)	ARMD1_SSP ## x ## _BASE
+#define SSP_REG_BASE(x)		CAT_BASE_ADDR(x)
+
+/*
+ * SSP Serial Port Registers
+ * refer Appendix A.26
+ */
+struct ssp_reg {
+	u32 sscr0;	/* SSP Control Register 0 - 0x000 */
+	u32 sscr1;	/* SSP Control Register 1 - 0x004 */
+	u32 sssr;	/* SSP Status Register - 0x008 */
+	u32 ssitr;	/* SSP Interrupt Test Register - 0x00C */
+	u32 ssdr;	/* SSP Data Register - 0x010 */
+	u32 pad1[5];
+	u32 ssto;	/* SSP Timeout Register - 0x028 */
+	u32 sspsp;	/* SSP Programmable Serial Protocol Register - 0x02C */
+	u32 sstsa;	/* SSP TX Timeslot Active Register - 0x030 */
+	u32 ssrsa;	/* SSP RX Timeslot Active Register - 0x034 */
+	u32 sstss;	/* SSP Timeslot Status Register - 0x038 */
+};
+
+struct armd_spi_slave {
+	struct spi_slave slave;
+	struct ssp_reg *spi_reg;
+	u32 cr0, cr1;
+	u32 int_cr1;
+	u32 clear_sr;
+	const void *tx;
+	void *rx;
+	int gpio_cs_inverted;
+
+	void (*write)(struct armd_spi_slave *pss);
+	void (*read)(struct armd_spi_slave *pss);
+};
+
+#define to_armd_spi_slave(s)	container_of(s, struct armd_spi_slave, slave)
+
+#define DEFAULT_WORD_LEN	8
+#define SSP_FLUSH_NUM		0x2000
+#define RX_THRESH_DEF		8
+#define TX_THRESH_DEF		8
+#define TIMEOUT_DEF		1000
+
+#define SSCR1_RIE	(1 << 0)	/* Receive FIFO Interrupt Enable */
+#define SSCR1_TIE	(1 << 1)	/* Transmit FIFO Interrupt Enable */
+#define SSCR1_LBM	(1 << 2)	/* Loop-Back Mode */
+#define SSCR1_SPO	(1 << 3)	/* Motorola SPI SSPSCLK polarity
+					   setting */
+#define SSCR1_SPH	(1 << 4)	/* Motorola SPI SSPSCLK phase setting */
+#define SSCR1_MWDS	(1 << 5)	/* Microwire Transmit Data Size */
+#define SSCR1_TFT	0x03c0		/* Transmit FIFO Threshold (mask) */
+#define SSCR1_RFT	0x3c00		/* Receive FIFO Threshold (mask) */
+
+#define SSCR1_TXTRESH(x)	((x - 1) << 6)	/* level [1..16] */
+#define SSCR1_RXTRESH(x)	((x - 1) << 10)	/* level [1..16] */
+#define SSCR1_TINTE		(1 << 19)	/* Receiver Time-out
+						   Interrupt enable */
+
+#define SSCR0_DSS		0x0f		/* Data Size Select (mask) */
+#define SSCR0_DATASIZE(x)	(x - 1)		/* Data Size Select [4..16] */
+#define SSCR0_FRF		0x30		/* FRame Format (mask) */
+#define SSCR0_MOTO		(0x0 << 4)	/* Motorola's Serial
+						   Peripheral Interface */
+#define SSCR0_TI		(0x1 << 4)	/* TI's Synchronous
+						   Serial Protocol (SSP) */
+#define SSCR0_NATIONAL		(0x2 << 4)	/* National Microwire */
+#define SSCR0_ECS		(1 << 6)	/* External clock select */
+#define SSCR0_SSE		(1 << 7)	/* Synchronous Serial Port
+						   Enable */
+
+#define SSSR_TNF	(1 << 2)	/* Transmit FIFO Not Full */
+#define SSSR_RNE	(1 << 3)	/* Receive FIFO Not Empty */
+#define SSSR_BSY	(1 << 4)	/* SSP Busy */
+#define SSSR_TFS	(1 << 5)	/* Transmit FIFO Service Request */
+#define SSSR_RFS	(1 << 6)	/* Receive FIFO Service Request */
+#define SSSR_ROR	(1 << 7)	/* Receive FIFO Overrun */
+#define SSSR_TINT	(1 << 19)	/* Receiver Time-out Interrupt */
+
+#endif /* __ARMADA100_SPI_H_ */
drivers/spi/Makefile +1 -0
index 96c9642..84ad6fa 100644
@@ -27,6 +27,7 @@ LIB	:= $(obj)libspi.o
 
 COBJS-$(CONFIG_ALTERA_SPI) += altera_spi.o
 COBJS-$(CONFIG_ANDES_SPI) += andes_spi.o
+COBJS-$(CONFIG_ARMADA100_SPI) += armada100_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/armada100_spi.c new file +205 -0

205 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 1/4 SPI: Add SPI driver support for Marvell Armada100

Quoted 13 lines · Ajay Bhargav

This patch provides support for SPI emulated over SSP for Marvell Armada100 SOC.

---
 arch/arm/include/asm/arch-armada100/spi.h |  111 ++++++++++++++++
 drivers/spi/Makefile                      |    1 +
 drivers/spi/armada100_spi.c               |  205
+++++++++++++++++++++++++++++ 3 files changed, 317 insertions(+), 0
deletions(-)
 create mode 100644 arch/arm/include/asm/arch-armada100/spi.h
 create mode 100644 drivers/spi/armada100_spi.c

[...]

arch/arm/include/asm/arch-armada100/spi.h line 87

Quoted 3 lines
arch/arm/include/asm/arch-armada100/spi.h new file +3 -0
+
+#define SSCR1_TXTRESH(x)	((x - 1) << 6)	/* level [1..16] */
+#define SSCR1_RXTRESH(x)	((x - 1) << 10)	/* level [1..16] */

((x) - 1), missing parenthesis, please fix globally.

Quoted 22 lines
arch/arm/include/asm/arch-armada100/spi.h new file +22 -0
+#define SSCR1_TINTE		(1 << 19)	/* Receiver Time-out
+						   Interrupt enable */
+
+#define SSCR0_DSS		0x0f		/* Data Size Select (mask) */
+#define SSCR0_DATASIZE(x)	(x - 1)		/* Data Size Select [4..16] */
+#define SSCR0_FRF		0x30		/* FRame Format (mask) */
+#define SSCR0_MOTO		(0x0 << 4)	/* Motorola's Serial
+						   Peripheral Interface */
+#define SSCR0_TI		(0x1 << 4)	/* TI's Synchronous
+						   Serial Protocol (SSP) */
+#define SSCR0_NATIONAL		(0x2 << 4)	/* National Microwire */
+#define SSCR0_ECS		(1 << 6)	/* External clock select */
+#define SSCR0_SSE		(1 << 7)	/* Synchronous Serial Port
+						   Enable */
+
+#define SSSR_TNF	(1 << 2)	/* Transmit FIFO Not Full */
+#define SSSR_RNE	(1 << 3)	/* Receive FIFO Not Empty */
+#define SSSR_BSY	(1 << 4)	/* SSP Busy */
+#define SSSR_TFS	(1 << 5)	/* Transmit FIFO Service Request */
+#define SSSR_RFS	(1 << 6)	/* Receive FIFO Service Request */
+#define SSSR_ROR	(1 << 7)	/* Receive FIFO Overrun */
+#define SSSR_TINT	(1 << 19)	/* Receiver Time-out Interrupt */

[...]

drivers/spi/armada100_spi.c line 56

Quoted 5 lines
drivers/spi/armada100_spi.c new file +5 -0
+
+static void null_writer(struct armd_spi_slave *pss)
+{
+	while (!(readl(&pss->spi_reg->sssr) & SSSR_TNF))
+		;

Please avoid endless loops, please fix globally.

Cheers

#2 lore raw

PATCH 1/4 SPI: Add SPI driver support for Marvell Armada100

Quoted 57 lines · ----- "Marek Vasut
Quoted 13 lines · Ajay Bhargav

This patch provides support for SPI emulated over SSP for Marvell Armada100 SOC.

---
 arch/arm/include/asm/arch-armada100/spi.h |  111 ++++++++++++++++
 drivers/spi/Makefile                      |    1 +
 drivers/spi/armada100_spi.c               |  205
+++++++++++++++++++++++++++++ 3 files changed, 317 insertions(+), 0
deletions(-)
 create mode 100644 arch/arm/include/asm/arch-armada100/spi.h
 create mode 100644 drivers/spi/armada100_spi.c

[...]

arch/arm/include/asm/arch-armada100/spi.h line 87

Quoted 3 lines
arch/arm/include/asm/arch-armada100/spi.h new file +3 -0
+
+#define SSCR1_TXTRESH(x)	((x - 1) << 6)	/* level [1..16] */
+#define SSCR1_RXTRESH(x)	((x - 1) << 10)	/* level [1..16] */

((x) - 1), missing parenthesis, please fix globally.

Quoted 22 lines
arch/arm/include/asm/arch-armada100/spi.h new file +22 -0
+#define SSCR1_TINTE		(1 << 19)	/* Receiver Time-out
+						   Interrupt enable */
+
+#define SSCR0_DSS		0x0f		/* Data Size Select (mask) */
+#define SSCR0_DATASIZE(x)	(x - 1)		/* Data Size Select [4..16] */
+#define SSCR0_FRF		0x30		/* FRame Format (mask) */
+#define SSCR0_MOTO		(0x0 << 4)	/* Motorola's Serial
+						   Peripheral Interface */
+#define SSCR0_TI		(0x1 << 4)	/* TI's Synchronous
+						   Serial Protocol (SSP) */
+#define SSCR0_NATIONAL		(0x2 << 4)	/* National Microwire */
+#define SSCR0_ECS		(1 << 6)	/* External clock select */
+#define SSCR0_SSE		(1 << 7)	/* Synchronous Serial Port
+						   Enable */
+
+#define SSSR_TNF	(1 << 2)	/* Transmit FIFO Not Full */
+#define SSSR_RNE	(1 << 3)	/* Receive FIFO Not Empty */
+#define SSSR_BSY	(1 << 4)	/* SSP Busy */
+#define SSSR_TFS	(1 << 5)	/* Transmit FIFO Service Request */
+#define SSSR_RFS	(1 << 6)	/* Receive FIFO Service Request */
+#define SSSR_ROR	(1 << 7)	/* Receive FIFO Overrun */
+#define SSSR_TINT	(1 << 19)	/* Receiver Time-out Interrupt */

[...]

drivers/spi/armada100_spi.c line 56

Quoted 5 lines
drivers/spi/armada100_spi.c new file +5 -0
+
+static void null_writer(struct armd_spi_slave *pss)
+{
+	while (!(readl(&pss->spi_reg->sssr) & SSSR_TNF))
+		;

Please avoid endless loops, please fix globally.

Quoted 2 lines

Cheers

Hi Marek,

I will fix that :) any more comments?

Regards,
Ajay Bhargav

#3 lore raw

PATCH 1/4 SPI: Add SPI driver support for Marvell Armada100

[..]

Quoted 3 lines

Hi Marek,

I will fix that :) any more comments?

Hi,

Naw, looks good otherwise.

Cheers

Quoted 3 lines

Regards,
Ajay Bhargav

#4 lore raw

PATCH 1/4 SPI: Add SPI driver support for Marvell Armada100

In reply to Ajay Bhargav
Quoted 8 lines · On Monday, September 19, 2011 06:47:07 Ajay Bhargav wrote:
arch/arm/include/asm/arch-armada100/spi.h new file +5 -0
 
+struct armd_spi_slave {
+	struct spi_slave slave;
+	struct ssp_reg *spi_reg;
+	u32 cr0, cr1;
+	u32 int_cr1;

arch/arm/include/asm/arch-armada100/spi.h line 68

Quoted 10 lines
arch/arm/include/asm/arch-armada100/spi.h new file +10 -0
+	u32 clear_sr;
+	const void *tx;
+	void *rx;
+	int gpio_cs_inverted;
+
+	void (*write)(struct armd_spi_slave *pss);
+	void (*read)(struct armd_spi_slave *pss);
+};
+
+#define to_armd_spi_slave(s)	container_of(s, struct armd_spi_slave, slave)

i dont think internal driver details should be in a header. these should be moved to armada100_spi.c.

drivers/spi/armada100_spi.c line 83

Quoted 8 lines
drivers/spi/armada100_spi.c new file +5 -0
 
+static void null_writer(struct armd_spi_slave *pss)
+static void null_reader(struct armd_spi_slave *pss)
+static void u8_writer(struct armd_spi_slave *pss)
+static void u8_reader(struct armd_spi_slave *pss)
+static int flush(struct armd_spi_slave *pss)

please prefix these with something like "spi_armd_". generic names like this are often hard to trace back when debugging.
-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/20110919/76c98fca/attachment.pgp