Skip to contentSkip to conversation

spi: Driver cleanup series

PATCH New Jagannadha Sutradharudu Teki 3 participants 14 messages Apr 21, 2015 – Apr 27, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover spi: Driver cleanup series

Driver cleanup series list
- Minor code cleanups - tab space, comments etc
- Zapping unneeded drivers
- Moving header code into driver .c files for easy accessing
- Arranged the driver code format to [1] for more readable
[1] http://lists.denx.de/pipermail/u-boot/2013-August/160473.html

thanks!
--
Jagan.

Jagannadha Sutradharudu Teki (8):
sf: Adjust tab space's
spi: Zap andes_spi driver
spi: Zap ftssp010_spi driver
spi: Zap oc_tiny_spi driver
spi: xilinx_spi: Move header code to driver
spi: xilinx_spi: Driver clean-up
spi: davinci_spi: Move header code to driver
spi: davinci_spi: Driver cleanup

 drivers/mtd/spi/sf_internal.h |  20 +-
 drivers/spi/Makefile          |   3 -
 drivers/spi/andes_spi.c       | 284 ------------------------
 drivers/spi/andes_spi.h       | 115 ----------
 drivers/spi/davinci_spi.c     | 369 ++++++++++++++++++++-----------
 drivers/spi/davinci_spi.h     | 121 ----------
 drivers/spi/ftssp010_spi.c    | 498 ------------------------------------------
 drivers/spi/oc_tiny_spi.c     | 245 ---------------------
 drivers/spi/xilinx_spi.c      | 153 +++++++++----
 drivers/spi/xilinx_spi.h      | 138 ------------
 include/spi.h                 |  12 +-
 include/spi_flash.h           |   8 +-
 12 files changed, 367 insertions(+), 1599 deletions(-)
 delete mode 100644 drivers/spi/andes_spi.c
 delete mode 100644 drivers/spi/andes_spi.h
 delete mode 100644 drivers/spi/davinci_spi.h
 delete mode 100644 drivers/spi/ftssp010_spi.c
 delete mode 100644 drivers/spi/oc_tiny_spi.c
 delete mode 100644 drivers/spi/xilinx_spi.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/8 sf: Adjust tab space's

Tab space's got adjusted on relevent files.

---
 drivers/mtd/spi/sf_internal.h | 20 ++++++++++----------
 include/spi.h                 | 12 ++++++------
 include/spi_flash.h           |  8 ++++----
 3 files changed, 20 insertions(+), 20 deletions(-)
drivers/mtd/spi/sf_internal.h +10 -10
index 785f7a9..58007de 100644
@@ -31,9 +31,9 @@ enum spi_read_cmds {
 };
 
 /* Normal - Extended - Full command set */
-#define RD_NORM	(ARRAY_SLOW | ARRAY_FAST)
-#define RD_EXTN	(RD_NORM | DUAL_OUTPUT_FAST | DUAL_IO_FAST)
-#define RD_FULL	(RD_EXTN | QUAD_OUTPUT_FAST | QUAD_IO_FAST)
+#define RD_NORM		(ARRAY_SLOW | ARRAY_FAST)
+#define RD_EXTN		(RD_NORM | DUAL_OUTPUT_FAST | DUAL_IO_FAST)
+#define RD_FULL		(RD_EXTN | QUAD_OUTPUT_FAST | QUAD_IO_FAST)
 
 /* sf param flags */
 enum {
@@ -67,12 +67,12 @@ enum {
 #define CMD_WRITE_STATUS		0x01
 #define CMD_PAGE_PROGRAM		0x02
 #define CMD_WRITE_DISABLE		0x04
-#define CMD_READ_STATUS		0x05
+#define CMD_READ_STATUS			0x05
 #define CMD_QUAD_PAGE_PROGRAM		0x32
 #define CMD_READ_STATUS1		0x35
 #define CMD_WRITE_ENABLE		0x06
-#define CMD_READ_CONFIG		0x35
-#define CMD_FLAG_STATUS		0x70
+#define CMD_READ_CONFIG			0x35
+#define CMD_FLAG_STATUS			0x70
 
 /* Read commands */
 #define CMD_READ_ARRAY_SLOW		0x03
@@ -94,7 +94,7 @@ enum {
 /* Common status */
 #define STATUS_WIP			(1 << 0)
 #define STATUS_QEB_WINSPAN		(1 << 1)
-#define STATUS_QEB_MXIC		(1 << 6)
+#define STATUS_QEB_MXIC			(1 << 6)
 #define STATUS_PEC			(1 << 7)
 
 #ifdef CONFIG_SYS_SPI_ST_ENABLE_WP_PIN
@@ -103,13 +103,13 @@ enum {
 
 /* Flash timeout values */
 #define SPI_FLASH_PROG_TIMEOUT		(2 * CONFIG_SYS_HZ)
-#define SPI_FLASH_PAGE_ERASE_TIMEOUT		(5 * CONFIG_SYS_HZ)
+#define SPI_FLASH_PAGE_ERASE_TIMEOUT	(5 * CONFIG_SYS_HZ)
 #define SPI_FLASH_SECTOR_ERASE_TIMEOUT	(10 * CONFIG_SYS_HZ)
 
 /* SST specific */
 #ifdef CONFIG_SPI_FLASH_SST
 # define CMD_SST_BP		0x02    /* Byte Program */
-# define CMD_SST_AAI_WP	0xAD	/* Auto Address Incr Word Program */
+# define CMD_SST_AAI_WP		0xAD	/* Auto Address Incr Word Program */
 
 int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len,
 		const void *buf);
@@ -124,7 +124,7 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len,
  * @jedec:		Device jedec ID (0x[1byte_manuf_id][2byte_dev_id])
  * @ext_jedec:		Device ext_jedec ID
  * @sector_size:	Sector size of this device
- * @nr_sectors:	No.of sectors on this device
+ * @nr_sectors:		No.of sectors on this device
  * @e_rd_cmd:		Enum list for read commands
  * @flags:		Important param, for flash specific behaviour
  */
include/spi.h +6 -6
index 7829063..44abe68 100644
@@ -30,7 +30,7 @@
 #define SPI_XFER_MMAP		0x08	/* Memory Mapped start */
 #define SPI_XFER_MMAP_END	0x10	/* Memory Mapped End */
 #define SPI_XFER_ONCE		(SPI_XFER_BEGIN | SPI_XFER_END)
-#define SPI_XFER_U_PAGE	(1 << 5)
+#define SPI_XFER_U_PAGE         (1 << 5)
 
 /* SPI TX operation modes */
 #define SPI_OPM_TX_QPP		(1 << 0)
@@ -43,18 +43,18 @@
 #define SPI_OPM_RX_DIO		(1 << 3)
 #define SPI_OPM_RX_QOF		(1 << 4)
 #define SPI_OPM_RX_QIOF		(1 << 5)
-#define SPI_OPM_RX_EXTN	(SPI_OPM_RX_AS | SPI_OPM_RX_AF | SPI_OPM_RX_DOUT | \
-				SPI_OPM_RX_DIO | SPI_OPM_RX_QOF | \
-				SPI_OPM_RX_QIOF)
+#define SPI_OPM_RX_EXTN		(SPI_OPM_RX_AS | SPI_OPM_RX_AF | \
+				SPI_OPM_RX_DOUT | SPI_OPM_RX_DIO | \
+				SPI_OPM_RX_QOF | SPI_OPM_RX_QIOF)
 
 /* SPI bus connection options - see enum spi_dual_flash */
 #define SPI_CONN_DUAL_SHARED		(1 << 0)
-#define SPI_CONN_DUAL_SEPARATED	(1 << 1)
+#define SPI_CONN_DUAL_SEPARATED         (1 << 1)
 
 /* Header byte that marks the start of the message */
 #define SPI_PREAMBLE_END_BYTE	0xec
 
-#define SPI_DEFAULT_WORDLEN 8
+#define SPI_DEFAULT_WORDLEN     8
 
 #ifdef CONFIG_DM_SPI
 /* TODO(sjg at chromium.org): Remove this and use max_hz from struct spi_slave */
include/spi_flash.h +4 -4
index 4791b94..481b4dd 100644
@@ -38,12 +38,12 @@ struct spi_slave;
  *
  * @spi:		SPI slave
  * @name:		Name of SPI flash
- * @dual_flash:	Indicates dual flash memories - dual stacked, parallel
+ * @dual_flash:	        Indicates dual flash memories - dual stacked, parallel
  * @shift:		Flash shift useful in dual parallel
  * @size:		Total flash size
  * @page_size:		Write (page) size
  * @sector_size:	Sector size
- * @erase_size:	Erase size
+ * @erase_size:         Erase size
  * @bank_read_cmd:	Bank read cmd
  * @bank_write_cmd:	Bank write cmd
  * @bank_curr:		Current flash bank
@@ -51,8 +51,8 @@ struct spi_slave;
  * @erase_cmd:		Erase cmd 4K, 32K, 64K
  * @read_cmd:		Read cmd - Array Fast, Extn read and quad read.
  * @write_cmd:		Write cmd - page and quad program.
- * @dummy_byte:	Dummy cycles for read operation.
- * @memory_map:	Address of read-only SPI flash access
+ * @dummy_byte:         Dummy cycles for read operation.
+ * @memory_map:         Address of read-only SPI flash access
  * @read:		Flash read ops: Read len bytes@offset into buf
  *			Supported cmds: Fast Array Read
  * @write:		Flash write ops: Write len bytes from buf into offset
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/8 spi: Zap andes_spi driver

In reply to Jagannadha Sutradharudu Teki

Zap andes_spi driver since the boards used this driver is no longer been active.

---
 drivers/spi/Makefile    |   1 -
 drivers/spi/andes_spi.c | 284 ------------------------------------------------
 drivers/spi/andes_spi.h | 115 --------------------
 3 files changed, 400 deletions(-)
 delete mode 100644 drivers/spi/andes_spi.c
 delete mode 100644 drivers/spi/andes_spi.h
drivers/spi/Makefile +0 -1
index e288692..93065b7 100644
@@ -17,7 +17,6 @@ endif
 
 obj-$(CONFIG_EP93XX_SPI) += ep93xx_spi.o
 obj-$(CONFIG_ALTERA_SPI) += altera_spi.o
-obj-$(CONFIG_ANDES_SPI) += andes_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
drivers/spi/andes_spi.c deleted +0 -284

284 lines not on this page · raw message

drivers/spi/andes_spi.h deleted +0 -115

115 lines not on this page · raw message

Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/8 spi: Zap ftssp010_spi driver

In reply to Jagannadha Sutradharudu Teki

Zap ftssp010_spi driver since the boards used this driver is no longer been active.

---
 drivers/spi/Makefile       |   1 -
 drivers/spi/ftssp010_spi.c | 498 ---------------------------------------------
 2 files changed, 499 deletions(-)
 delete mode 100644 drivers/spi/ftssp010_spi.c
drivers/spi/Makefile +0 -1
index 93065b7..1e3611d 100644
@@ -28,7 +28,6 @@ obj-$(CONFIG_CF_QSPI) += cf_qspi.o
 obj-$(CONFIG_DAVINCI_SPI) += davinci_spi.o
 obj-$(CONFIG_DESIGNWARE_SPI) += designware_spi.o
 obj-$(CONFIG_EXYNOS_SPI) += exynos_spi.o
-obj-$(CONFIG_FTSSP010_SPI) += ftssp010_spi.o
 obj-$(CONFIG_ICH_SPI) +=  ich.o
 obj-$(CONFIG_KIRKWOOD_SPI) += kirkwood_spi.o
 obj-$(CONFIG_LPC32XX_SSP) += lpc32xx_ssp.o
drivers/spi/ftssp010_spi.c deleted +0 -498

498 lines not on this page · raw message

Signature · 1 line
1.9.1
#4 lore raw

PATCH 3/8 spi: Zap ftssp010_spi driver

2015-04-22 2:26 GMT+08:00 Jagannadha Sutradharudu Teki <[email protected]>:

Quoted 2 lines

Zap ftssp010_spi driver since the boards used this driver is no longer been active.

I'm not sure if this is correct thing to do...
It's fine to drop unmaintained boards, but a driver can/may be used by different boards. So If someday the boards(or new boards) that need this driver becomes active, it needs to add back this(and all required) driver(s).

Regards,
Axel

author
#5 lore raw

PATCH 3/8 spi: Zap ftssp010_spi driver

Hi Axel,

Quoted 9 lines · Axel Lin

2015-04-22 2:26 GMT+08:00 Jagannadha Sutradharudu Teki <[email protected]>:

Quoted 2 lines

Zap ftssp010_spi driver since the boards used this driver is no longer been active.

I'm not sure if this is correct thing to do...
It's fine to drop unmaintained boards, but a driver can/may be used by different boards. So If someday the boards(or new boards) that need this driver becomes active, it needs to add back this(and all required) driver(s).

I understand your point, but if none of the sw using these drivers will make orphan driver and to reduce the code size atleast some thing is not used now.

Ok, if any boards require these may be they will write or reuse it from past that
depends on the future decision.

Any comments from ML?

thanks!

Signature · 1 line
Jagan.
#6 lore raw

PATCH 4/8 spi: Zap oc_tiny_spi driver

In reply to Jagannadha Sutradharudu Teki

Zap oc_tiny_spi driver since the boards used this driver is no longer been active.

---
 drivers/spi/Makefile      |   1 -
 drivers/spi/oc_tiny_spi.c | 245 ----------------------------------------------
 2 files changed, 246 deletions(-)
 delete mode 100644 drivers/spi/oc_tiny_spi.c
drivers/spi/Makefile +0 -1
index 1e3611d..507c315 100644
@@ -35,7 +35,6 @@ obj-$(CONFIG_MPC52XX_SPI) += mpc52xx_spi.o
 obj-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o
 obj-$(CONFIG_MXC_SPI) += mxc_spi.o
 obj-$(CONFIG_MXS_SPI) += mxs_spi.o
-obj-$(CONFIG_OC_TINY_SPI) += oc_tiny_spi.o
 obj-$(CONFIG_OMAP3_SPI) += omap3_spi.o
 obj-$(CONFIG_SANDBOX_SPI) += sandbox_spi.o
 obj-$(CONFIG_SH_SPI) += sh_spi.o
drivers/spi/oc_tiny_spi.c deleted +0 -245

245 lines not on this page · raw message

Signature · 1 line
1.9.1
#7 lore raw

PATCH 5/8 spi: xilinx_spi: Move header code to driver

In reply to Jagannadha Sutradharudu Teki

Move the header code into driver for more readable and easy to access it.

---
 drivers/spi/xilinx_spi.c | 113 +++++++++++++++++++++++++++++++++++++-
 drivers/spi/xilinx_spi.h | 138 -----------------------------------------------
 2 files changed, 112 insertions(+), 139 deletions(-)
 delete mode 100644 drivers/spi/xilinx_spi.h
drivers/spi/xilinx_spi.c +112 -1
index 56d99d1..8073edc 100644
@@ -21,7 +21,118 @@
 #include <malloc.h>
 #include <spi.h>
 
-#include "xilinx_spi.h"
+/*
+ * Xilinx SPI Register Definition
+ *
+ * [1]:	[0]/ip_documentation/xps_spi.pdf
+ *	page 8, Register Descriptions
+ * [2]:	[0]/ip_documentation/axi_spi_ds742.pdf
+ *	page 7, Register Overview Table
+ */
+struct xilinx_spi_reg {
+	u32 __space0__[7];
+	u32 dgier;	/* Device Global Interrupt Enable Register (DGIER) */
+	u32 ipisr;	/* IP Interrupt Status Register (IPISR) */
+	u32 __space1__;
+	u32 ipier;	/* IP Interrupt Enable Register (IPIER) */
+	u32 __space2__[5];
+	u32 srr;	/* Softare Reset Register (SRR) */
+	u32 __space3__[7];
+	u32 spicr;	/* SPI Control Register (SPICR) */
+	u32 spisr;	/* SPI Status Register (SPISR) */
+	u32 spidtr;	/* SPI Data Transmit Register (SPIDTR) */
+	u32 spidrr;	/* SPI Data Receive Register (SPIDRR) */
+	u32 spissr;	/* SPI Slave Select Register (SPISSR) */
+	u32 spitfor;	/* SPI Transmit FIFO Occupancy Register (SPITFOR) */
+	u32 spirfor;	/* SPI Receive FIFO Occupancy Register (SPIRFOR) */
+};
+
+/* Device Global Interrupt Enable Register (dgier), [1] p15, [2] p15 */
+#define DGIER_GIE		(1 << 31)
+
+/* IP Interrupt Status Register (ipisr), [1] p15, [2] p15 */
+#define IPISR_DRR_NOT_EMPTY	(1 << 8)
+#define IPISR_SLAVE_SELECT	(1 << 7)
+#define IPISR_TXF_HALF_EMPTY	(1 << 6)
+#define IPISR_DRR_OVERRUN	(1 << 5)
+#define IPISR_DRR_FULL		(1 << 4)
+#define IPISR_DTR_UNDERRUN	(1 << 3)
+#define IPISR_DTR_EMPTY		(1 << 2)
+#define IPISR_SLAVE_MODF	(1 << 1)
+#define IPISR_MODF		(1 << 0)
+
+/* IP Interrupt Enable Register (ipier), [1] p17, [2] p18 */
+#define IPIER_DRR_NOT_EMPTY	(1 << 8)
+#define IPIER_SLAVE_SELECT	(1 << 7)
+#define IPIER_TXF_HALF_EMPTY	(1 << 6)
+#define IPIER_DRR_OVERRUN	(1 << 5)
+#define IPIER_DRR_FULL		(1 << 4)
+#define IPIER_DTR_UNDERRUN	(1 << 3)
+#define IPIER_DTR_EMPTY		(1 << 2)
+#define IPIER_SLAVE_MODF	(1 << 1)
+#define IPIER_MODF		(1 << 0)
+
+/* Softare Reset Register (srr), [1] p9, [2] p8 */
+#define SRR_RESET_CODE		0x0000000A
+
+/* SPI Control Register (spicr), [1] p9, [2] p8 */
+#define SPICR_LSB_FIRST		(1 << 9)
+#define SPICR_MASTER_INHIBIT	(1 << 8)
+#define SPICR_MANUAL_SS		(1 << 7)
+#define SPICR_RXFIFO_RESEST	(1 << 6)
+#define SPICR_TXFIFO_RESEST	(1 << 5)
+#define SPICR_CPHA		(1 << 4)
+#define SPICR_CPOL		(1 << 3)
+#define SPICR_MASTER_MODE	(1 << 2)
+#define SPICR_SPE		(1 << 1)
+#define SPICR_LOOP		(1 << 0)
+
+/* SPI Status Register (spisr), [1] p11, [2] p10 */
+#define SPISR_SLAVE_MODE_SELECT	(1 << 5)
+#define SPISR_MODF		(1 << 4)
+#define SPISR_TX_FULL		(1 << 3)
+#define SPISR_TX_EMPTY		(1 << 2)
+#define SPISR_RX_FULL		(1 << 1)
+#define SPISR_RX_EMPTY		(1 << 0)
+
+/* SPI Data Transmit Register (spidtr), [1] p12, [2] p12 */
+#define SPIDTR_8BIT_MASK	(0xff << 0)
+#define SPIDTR_16BIT_MASK	(0xffff << 0)
+#define SPIDTR_32BIT_MASK	(0xffffffff << 0)
+
+/* SPI Data Receive Register (spidrr), [1] p12, [2] p12 */
+#define SPIDRR_8BIT_MASK	(0xff << 0)
+#define SPIDRR_16BIT_MASK	(0xffff << 0)
+#define SPIDRR_32BIT_MASK	(0xffffffff << 0)
+
+/* SPI Slave Select Register (spissr), [1] p13, [2] p13 */
+#define SPISSR_MASK(cs)		(1 << (cs))
+#define SPISSR_ACT(cs)		~SPISSR_MASK(cs)
+#define SPISSR_OFF		~0UL
+
+/* SPI Transmit FIFO Occupancy Register (spitfor), [1] p13, [2] p14 */
+#define SPITFOR_OCYVAL_POS	0
+#define SPITFOR_OCYVAL_MASK	(0xf << SPITFOR_OCYVAL_POS)
+
+/* SPI Receive FIFO Occupancy Register (spirfor), [1] p14, [2] p14 */
+#define SPIRFOR_OCYVAL_POS	0
+#define SPIRFOR_OCYVAL_MASK	(0xf << SPIRFOR_OCYVAL_POS)
+
+/* SPI Software Reset Register (ssr) */
+#define SPISSR_RESET_VALUE	0x0a
+
+struct xilinx_spi_slave {
+	struct spi_slave slave;
+	struct xilinx_spi_reg *regs;
+	unsigned int freq;
+	unsigned int mode;
+};
+
+static inline struct xilinx_spi_slave *to_xilinx_spi_slave(
+					struct spi_slave *slave)
+{
+	return container_of(slave, struct xilinx_spi_slave, slave);
+}
 
 #ifndef CONFIG_SYS_XILINX_SPI_LIST
 #define CONFIG_SYS_XILINX_SPI_LIST	{ CONFIG_SYS_SPI_BASE }
drivers/spi/xilinx_spi.h deleted +0 -138

138 lines not on this page · raw message

Signature · 1 line
1.9.1
#8 lore raw

PATCH 5/8 spi: xilinx_spi: Move header code to driver

Quoted 270 lines · Jagannadha Sutradharudu Teki

Move the header code into driver for more readable and easy to access it.

---
 drivers/spi/xilinx_spi.c | 113 +++++++++++++++++++++++++++++++++++++-
 drivers/spi/xilinx_spi.h | 138 -----------------------------------------------
 2 files changed, 112 insertions(+), 139 deletions(-)
 delete mode 100644 drivers/spi/xilinx_spi.h
drivers/spi/xilinx_spi.c +112 -1
index 56d99d1..8073edc 100644
@@ -21,7 +21,118 @@
 #include <malloc.h>
 #include <spi.h>
 
-#include "xilinx_spi.h"
+/*
+ * Xilinx SPI Register Definition
+ *
+ * [1]:	[0]/ip_documentation/xps_spi.pdf
+ *	page 8, Register Descriptions
+ * [2]:	[0]/ip_documentation/axi_spi_ds742.pdf
+ *	page 7, Register Overview Table
+ */
+struct xilinx_spi_reg {
+	u32 __space0__[7];
+	u32 dgier;	/* Device Global Interrupt Enable Register (DGIER) */
+	u32 ipisr;	/* IP Interrupt Status Register (IPISR) */
+	u32 __space1__;
+	u32 ipier;	/* IP Interrupt Enable Register (IPIER) */
+	u32 __space2__[5];
+	u32 srr;	/* Softare Reset Register (SRR) */
+	u32 __space3__[7];
+	u32 spicr;	/* SPI Control Register (SPICR) */
+	u32 spisr;	/* SPI Status Register (SPISR) */
+	u32 spidtr;	/* SPI Data Transmit Register (SPIDTR) */
+	u32 spidrr;	/* SPI Data Receive Register (SPIDRR) */
+	u32 spissr;	/* SPI Slave Select Register (SPISSR) */
+	u32 spitfor;	/* SPI Transmit FIFO Occupancy Register (SPITFOR) */
+	u32 spirfor;	/* SPI Receive FIFO Occupancy Register (SPIRFOR) */
+};
+
+/* Device Global Interrupt Enable Register (dgier), [1] p15, [2] p15 */
+#define DGIER_GIE		(1 << 31)
+
+/* IP Interrupt Status Register (ipisr), [1] p15, [2] p15 */
+#define IPISR_DRR_NOT_EMPTY	(1 << 8)
+#define IPISR_SLAVE_SELECT	(1 << 7)
+#define IPISR_TXF_HALF_EMPTY	(1 << 6)
+#define IPISR_DRR_OVERRUN	(1 << 5)
+#define IPISR_DRR_FULL		(1 << 4)
+#define IPISR_DTR_UNDERRUN	(1 << 3)
+#define IPISR_DTR_EMPTY		(1 << 2)
+#define IPISR_SLAVE_MODF	(1 << 1)
+#define IPISR_MODF		(1 << 0)
+
+/* IP Interrupt Enable Register (ipier), [1] p17, [2] p18 */
+#define IPIER_DRR_NOT_EMPTY	(1 << 8)
+#define IPIER_SLAVE_SELECT	(1 << 7)
+#define IPIER_TXF_HALF_EMPTY	(1 << 6)
+#define IPIER_DRR_OVERRUN	(1 << 5)
+#define IPIER_DRR_FULL		(1 << 4)
+#define IPIER_DTR_UNDERRUN	(1 << 3)
+#define IPIER_DTR_EMPTY		(1 << 2)
+#define IPIER_SLAVE_MODF	(1 << 1)
+#define IPIER_MODF		(1 << 0)
+
+/* Softare Reset Register (srr), [1] p9, [2] p8 */
+#define SRR_RESET_CODE		0x0000000A
+
+/* SPI Control Register (spicr), [1] p9, [2] p8 */
+#define SPICR_LSB_FIRST		(1 << 9)
+#define SPICR_MASTER_INHIBIT	(1 << 8)
+#define SPICR_MANUAL_SS		(1 << 7)
+#define SPICR_RXFIFO_RESEST	(1 << 6)
+#define SPICR_TXFIFO_RESEST	(1 << 5)
+#define SPICR_CPHA		(1 << 4)
+#define SPICR_CPOL		(1 << 3)
+#define SPICR_MASTER_MODE	(1 << 2)
+#define SPICR_SPE		(1 << 1)
+#define SPICR_LOOP		(1 << 0)
+
+/* SPI Status Register (spisr), [1] p11, [2] p10 */
+#define SPISR_SLAVE_MODE_SELECT	(1 << 5)
+#define SPISR_MODF		(1 << 4)
+#define SPISR_TX_FULL		(1 << 3)
+#define SPISR_TX_EMPTY		(1 << 2)
+#define SPISR_RX_FULL		(1 << 1)
+#define SPISR_RX_EMPTY		(1 << 0)
+
+/* SPI Data Transmit Register (spidtr), [1] p12, [2] p12 */
+#define SPIDTR_8BIT_MASK	(0xff << 0)
+#define SPIDTR_16BIT_MASK	(0xffff << 0)
+#define SPIDTR_32BIT_MASK	(0xffffffff << 0)
+
+/* SPI Data Receive Register (spidrr), [1] p12, [2] p12 */
+#define SPIDRR_8BIT_MASK	(0xff << 0)
+#define SPIDRR_16BIT_MASK	(0xffff << 0)
+#define SPIDRR_32BIT_MASK	(0xffffffff << 0)
+
+/* SPI Slave Select Register (spissr), [1] p13, [2] p13 */
+#define SPISSR_MASK(cs)		(1 << (cs))
+#define SPISSR_ACT(cs)		~SPISSR_MASK(cs)
+#define SPISSR_OFF		~0UL
+
+/* SPI Transmit FIFO Occupancy Register (spitfor), [1] p13, [2] p14 */
+#define SPITFOR_OCYVAL_POS	0
+#define SPITFOR_OCYVAL_MASK	(0xf << SPITFOR_OCYVAL_POS)
+
+/* SPI Receive FIFO Occupancy Register (spirfor), [1] p14, [2] p14 */
+#define SPIRFOR_OCYVAL_POS	0
+#define SPIRFOR_OCYVAL_MASK	(0xf << SPIRFOR_OCYVAL_POS)
+
+/* SPI Software Reset Register (ssr) */
+#define SPISSR_RESET_VALUE	0x0a
+
+struct xilinx_spi_slave {
+	struct spi_slave slave;
+	struct xilinx_spi_reg *regs;
+	unsigned int freq;
+	unsigned int mode;
+};
+
+static inline struct xilinx_spi_slave *to_xilinx_spi_slave(
+					struct spi_slave *slave)
+{
+	return container_of(slave, struct xilinx_spi_slave, slave);
+}
 
 #ifndef CONFIG_SYS_XILINX_SPI_LIST
 #define CONFIG_SYS_XILINX_SPI_LIST	{ CONFIG_SYS_SPI_BASE }
drivers/spi/xilinx_spi.h deleted +0 -128
deleted file mode 100644
index ce7d82c..0000000
@@ -1,138 +0,0 @@
-/*
- * Xilinx SPI driver
- *
- * XPS/AXI bus interface
- *
- * based on bfin_spi.c, by way of altera_spi.c
- * Copyright (c) 2005-2008 Analog Devices Inc.
- * Copyright (c) 2010 Thomas Chou <[email protected]>
- * Copyright (c) 2010 Graeme Smecher <[email protected]>
- * Copyright (c) 2012 Stephan Linz <[email protected]>
- *
- * SPDX-License-Identifier:	GPL-2.0+
- *
- * [0]: http://www.xilinx.com/support/documentation
- *
- * [S]:	[0]/ip_documentation/xps_spi.pdf
- *	[0]/ip_documentation/axi_spi_ds742.pdf
- */
-#ifndef _XILINX_SPI_
-#define _XILINX_SPI_
-
-#include <asm/types.h>
-#include <asm/io.h>
-
-/*
- * Xilinx SPI Register Definition
- *
- * [1]:	[0]/ip_documentation/xps_spi.pdf
- *	page 8, Register Descriptions
- * [2]:	[0]/ip_documentation/axi_spi_ds742.pdf
- *	page 7, Register Overview Table
- */
-struct xilinx_spi_reg {
-	u32 __space0__[7];
-	u32 dgier;	/* Device Global Interrupt Enable Register (DGIER) */
-	u32 ipisr;	/* IP Interrupt Status Register (IPISR) */
-	u32 __space1__;
-	u32 ipier;	/* IP Interrupt Enable Register (IPIER) */
-	u32 __space2__[5];
-	u32 srr;	/* Softare Reset Register (SRR) */
-	u32 __space3__[7];
-	u32 spicr;	/* SPI Control Register (SPICR) */
-	u32 spisr;	/* SPI Status Register (SPISR) */
-	u32 spidtr;	/* SPI Data Transmit Register (SPIDTR) */
-	u32 spidrr;	/* SPI Data Receive Register (SPIDRR) */
-	u32 spissr;	/* SPI Slave Select Register (SPISSR) */
-	u32 spitfor;	/* SPI Transmit FIFO Occupancy Register (SPITFOR) */
-	u32 spirfor;	/* SPI Receive FIFO Occupancy Register (SPIRFOR) */
-};
-
-/* Device Global Interrupt Enable Register (dgier), [1] p15, [2] p15 */
-#define DGIER_GIE		(1 << 31)
-
-/* IP Interrupt Status Register (ipisr), [1] p15, [2] p15 */
-#define IPISR_DRR_NOT_EMPTY	(1 << 8)
-#define IPISR_SLAVE_SELECT	(1 << 7)
-#define IPISR_TXF_HALF_EMPTY	(1 << 6)
-#define IPISR_DRR_OVERRUN	(1 << 5)
-#define IPISR_DRR_FULL		(1 << 4)
-#define IPISR_DTR_UNDERRUN	(1 << 3)
-#define IPISR_DTR_EMPTY		(1 << 2)
-#define IPISR_SLAVE_MODF	(1 << 1)
-#define IPISR_MODF		(1 << 0)
-
-/* IP Interrupt Enable Register (ipier), [1] p17, [2] p18 */
-#define IPIER_DRR_NOT_EMPTY	(1 << 8)
-#define IPIER_SLAVE_SELECT	(1 << 7)
-#define IPIER_TXF_HALF_EMPTY	(1 << 6)
-#define IPIER_DRR_OVERRUN	(1 << 5)
-#define IPIER_DRR_FULL		(1 << 4)
-#define IPIER_DTR_UNDERRUN	(1 << 3)
-#define IPIER_DTR_EMPTY		(1 << 2)
-#define IPIER_SLAVE_MODF	(1 << 1)
-#define IPIER_MODF		(1 << 0)
-
-/* Softare Reset Register (srr), [1] p9, [2] p8 */
-#define SRR_RESET_CODE		0x0000000A
-
-/* SPI Control Register (spicr), [1] p9, [2] p8 */
-#define SPICR_LSB_FIRST		(1 << 9)
-#define SPICR_MASTER_INHIBIT	(1 << 8)
-#define SPICR_MANUAL_SS		(1 << 7)
-#define SPICR_RXFIFO_RESEST	(1 << 6)
-#define SPICR_TXFIFO_RESEST	(1 << 5)
-#define SPICR_CPHA		(1 << 4)
-#define SPICR_CPOL		(1 << 3)
-#define SPICR_MASTER_MODE	(1 << 2)
-#define SPICR_SPE		(1 << 1)
-#define SPICR_LOOP		(1 << 0)
-
-/* SPI Status Register (spisr), [1] p11, [2] p10 */
-#define SPISR_SLAVE_MODE_SELECT	(1 << 5)
-#define SPISR_MODF		(1 << 4)
-#define SPISR_TX_FULL		(1 << 3)
-#define SPISR_TX_EMPTY		(1 << 2)
-#define SPISR_RX_FULL		(1 << 1)
-#define SPISR_RX_EMPTY		(1 << 0)
-
-/* SPI Data Transmit Register (spidtr), [1] p12, [2] p12 */
-#define SPIDTR_8BIT_MASK	(0xff << 0)
-#define SPIDTR_16BIT_MASK	(0xffff << 0)
-#define SPIDTR_32BIT_MASK	(0xffffffff << 0)
-
-/* SPI Data Receive Register (spidrr), [1] p12, [2] p12 */
-#define SPIDRR_8BIT_MASK	(0xff << 0)
-#define SPIDRR_16BIT_MASK	(0xffff << 0)
-#define SPIDRR_32BIT_MASK	(0xffffffff << 0)
-
-/* SPI Slave Select Register (spissr), [1] p13, [2] p13 */
-#define SPISSR_MASK(cs)		(1 << (cs))
-#define SPISSR_ACT(cs)		~SPISSR_MASK(cs)
-#define SPISSR_OFF		~0UL
-
-/* SPI Transmit FIFO Occupancy Register (spitfor), [1] p13, [2] p14 */
-#define SPITFOR_OCYVAL_POS	0
-#define SPITFOR_OCYVAL_MASK	(0xf << SPITFOR_OCYVAL_POS)
-
-/* SPI Receive FIFO Occupancy Register (spirfor), [1] p14, [2] p14 */
-#define SPIRFOR_OCYVAL_POS	0
-#define SPIRFOR_OCYVAL_MASK	(0xf << SPIRFOR_OCYVAL_POS)
-
-/* SPI Software Reset Register (ssr) */
-#define SPISSR_RESET_VALUE	0x0a
-
-struct xilinx_spi_slave {
-	struct spi_slave slave;
-	struct xilinx_spi_reg *regs;
-	unsigned int freq;

drivers/spi/xilinx_spi.h line 138

Quoted 10 lines
drivers/spi/xilinx_spi.h deleted +0 -10
-	unsigned int mode;
-};
-
-static inline struct xilinx_spi_slave *to_xilinx_spi_slave(
-					struct spi_slave *slave)
-{
-	return container_of(slave, struct xilinx_spi_slave, slave);
-}
-
-#endif /* _XILINX_SPI_ */

Thanks,
Michal

#9 lore raw

PATCH 6/8 spi: xilinx_spi: Driver clean-up

In reply to Jagannadha Sutradharudu Teki

- Zap unneeded macros
- Re-arrange the code
- Removed __attribute__((weak))
- Replace __func__ macro with func names to save macro transition.
- Re-arranged comment lines.
- Arrange driver code in more readable format[1]

[1] http://lists.denx.de/pipermail/u-boot/2013-August/160473.html

---
 drivers/spi/xilinx_spi.c | 164 ++++++++++++++++-------------------------------
 1 file changed, 57 insertions(+), 107 deletions(-)
drivers/spi/xilinx_spi.c +57 -107
index 8073edc..650e494 100644
@@ -1,79 +1,31 @@
 /*
  * Xilinx SPI driver
  *
- * supports 8 bit SPI transfers only, with or w/o FIFO
+ * Supports 8 bit SPI transfers only, with or w/o FIFO
  *
- * based on bfin_spi.c, by way of altera_spi.c
- * Copyright (c) 2005-2008 Analog Devices Inc.
- * Copyright (c) 2010 Thomas Chou <[email protected]>
- * Copyright (c) 2010 Graeme Smecher <[email protected]>
+ * Based on bfin_spi.c, by way of altera_spi.c
  * Copyright (c) 2012 Stephan Linz <[email protected]>
+ * Copyright (c) 2010 Graeme Smecher <[email protected]>
+ * Copyright (c) 2010 Thomas Chou <[email protected]>
+ * Copyright (c) 2005-2008 Analog Devices Inc.
  *
  * SPDX-License-Identifier:	GPL-2.0+
- *
- * [0]: http://www.xilinx.com/support/documentation
- *
- * [S]:	[0]/ip_documentation/xps_spi.pdf
- *	[0]/ip_documentation/axi_spi_ds742.pdf
  */
+
 #include <config.h>
 #include <common.h>
 #include <malloc.h>
 #include <spi.h>
 
 /*
- * Xilinx SPI Register Definition
+ * [0]: http://www.xilinx.com/support/documentation
  *
+ * Xilinx SPI Register Definitions
  * [1]:	[0]/ip_documentation/xps_spi.pdf
  *	page 8, Register Descriptions
  * [2]:	[0]/ip_documentation/axi_spi_ds742.pdf
  *	page 7, Register Overview Table
  */
-struct xilinx_spi_reg {
-	u32 __space0__[7];
-	u32 dgier;	/* Device Global Interrupt Enable Register (DGIER) */
-	u32 ipisr;	/* IP Interrupt Status Register (IPISR) */
-	u32 __space1__;
-	u32 ipier;	/* IP Interrupt Enable Register (IPIER) */
-	u32 __space2__[5];
-	u32 srr;	/* Softare Reset Register (SRR) */
-	u32 __space3__[7];
-	u32 spicr;	/* SPI Control Register (SPICR) */
-	u32 spisr;	/* SPI Status Register (SPISR) */
-	u32 spidtr;	/* SPI Data Transmit Register (SPIDTR) */
-	u32 spidrr;	/* SPI Data Receive Register (SPIDRR) */
-	u32 spissr;	/* SPI Slave Select Register (SPISSR) */
-	u32 spitfor;	/* SPI Transmit FIFO Occupancy Register (SPITFOR) */
-	u32 spirfor;	/* SPI Receive FIFO Occupancy Register (SPIRFOR) */
-};
-
-/* Device Global Interrupt Enable Register (dgier), [1] p15, [2] p15 */
-#define DGIER_GIE		(1 << 31)
-
-/* IP Interrupt Status Register (ipisr), [1] p15, [2] p15 */
-#define IPISR_DRR_NOT_EMPTY	(1 << 8)
-#define IPISR_SLAVE_SELECT	(1 << 7)
-#define IPISR_TXF_HALF_EMPTY	(1 << 6)
-#define IPISR_DRR_OVERRUN	(1 << 5)
-#define IPISR_DRR_FULL		(1 << 4)
-#define IPISR_DTR_UNDERRUN	(1 << 3)
-#define IPISR_DTR_EMPTY		(1 << 2)
-#define IPISR_SLAVE_MODF	(1 << 1)
-#define IPISR_MODF		(1 << 0)
-
-/* IP Interrupt Enable Register (ipier), [1] p17, [2] p18 */
-#define IPIER_DRR_NOT_EMPTY	(1 << 8)
-#define IPIER_SLAVE_SELECT	(1 << 7)
-#define IPIER_TXF_HALF_EMPTY	(1 << 6)
-#define IPIER_DRR_OVERRUN	(1 << 5)
-#define IPIER_DRR_FULL		(1 << 4)
-#define IPIER_DTR_UNDERRUN	(1 << 3)
-#define IPIER_DTR_EMPTY		(1 << 2)
-#define IPIER_SLAVE_MODF	(1 << 1)
-#define IPIER_MODF		(1 << 0)
-
-/* Softare Reset Register (srr), [1] p9, [2] p8 */
-#define SRR_RESET_CODE		0x0000000A
 
 /* SPI Control Register (spicr), [1] p9, [2] p8 */
 #define SPICR_LSB_FIRST		(1 << 9)
@@ -110,17 +62,42 @@ struct xilinx_spi_reg {
 #define SPISSR_ACT(cs)		~SPISSR_MASK(cs)
 #define SPISSR_OFF		~0UL
 
-/* SPI Transmit FIFO Occupancy Register (spitfor), [1] p13, [2] p14 */
-#define SPITFOR_OCYVAL_POS	0
-#define SPITFOR_OCYVAL_MASK	(0xf << SPITFOR_OCYVAL_POS)
-
-/* SPI Receive FIFO Occupancy Register (spirfor), [1] p14, [2] p14 */
-#define SPIRFOR_OCYVAL_POS	0
-#define SPIRFOR_OCYVAL_MASK	(0xf << SPIRFOR_OCYVAL_POS)
-
 /* SPI Software Reset Register (ssr) */
 #define SPISSR_RESET_VALUE	0x0a
 
+#define XILSPI_MAX_XFER_BITS	8
+#define XILSPI_SPICR_DFLT_ON	(SPICR_MANUAL_SS | SPICR_MASTER_MODE | \
+				SPICR_SPE)
+#define XILSPI_SPICR_DFLT_OFF	(SPICR_MASTER_INHIBIT | SPICR_MANUAL_SS)
+
+#ifndef CONFIG_XILINX_SPI_IDLE_VAL
+#define CONFIG_XILINX_SPI_IDLE_VAL	0xff
+#endif
+
+#ifndef CONFIG_SYS_XILINX_SPI_LIST
+#define CONFIG_SYS_XILINX_SPI_LIST	{ CONFIG_SYS_SPI_BASE }
+#endif
+
+/* xilinx spi register set */
+struct xilinx_spi_reg {
+	u32 __space0__[7];
+	u32 dgier;	/* Device Global Interrupt Enable Register (DGIER) */
+	u32 ipisr;	/* IP Interrupt Status Register (IPISR) */
+	u32 __space1__;
+	u32 ipier;	/* IP Interrupt Enable Register (IPIER) */
+	u32 __space2__[5];
+	u32 srr;	/* Softare Reset Register (SRR) */
+	u32 __space3__[7];
+	u32 spicr;	/* SPI Control Register (SPICR) */
+	u32 spisr;	/* SPI Status Register (SPISR) */
+	u32 spidtr;	/* SPI Data Transmit Register (SPIDTR) */
+	u32 spidrr;	/* SPI Data Receive Register (SPIDRR) */
+	u32 spissr;	/* SPI Slave Select Register (SPISSR) */
+	u32 spitfor;	/* SPI Transmit FIFO Occupancy Register (SPITFOR) */
+	u32 spirfor;	/* SPI Receive FIFO Occupancy Register (SPIRFOR) */
+};
+
+/* xilinx spi slave */
 struct xilinx_spi_slave {
 	struct spi_slave slave;
 	struct xilinx_spi_reg *regs;
@@ -129,37 +106,17 @@ struct xilinx_spi_slave {
 };
 
 static inline struct xilinx_spi_slave *to_xilinx_spi_slave(
-					struct spi_slave *slave)
+			struct spi_slave *slave)
 {
 	return container_of(slave, struct xilinx_spi_slave, slave);
 }
 
-#ifndef CONFIG_SYS_XILINX_SPI_LIST
-#define CONFIG_SYS_XILINX_SPI_LIST	{ CONFIG_SYS_SPI_BASE }
-#endif
-
-#ifndef CONFIG_XILINX_SPI_IDLE_VAL
-#define CONFIG_XILINX_SPI_IDLE_VAL	0xff
-#endif
-
-#define XILSPI_SPICR_DFLT_ON		(SPICR_MANUAL_SS | \
-					 SPICR_MASTER_MODE | \
-					 SPICR_SPE)
-
-#define XILSPI_SPICR_DFLT_OFF		(SPICR_MASTER_INHIBIT | \
-					 SPICR_MANUAL_SS)
-
-#define XILSPI_MAX_XFER_BITS		8
-
 static unsigned long xilinx_spi_base_list[] = CONFIG_SYS_XILINX_SPI_LIST;
-
-__attribute__((weak))
 int spi_cs_is_valid(unsigned int bus, unsigned int cs)
 {
 	return bus < ARRAY_SIZE(xilinx_spi_base_list) && cs < 32;
 }
 
-__attribute__((weak))
 void spi_cs_activate(struct spi_slave *slave)
 {
 	struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
@@ -167,7 +124,6 @@ void spi_cs_activate(struct spi_slave *slave)
 	writel(SPISSR_ACT(slave->cs), &xilspi->regs->spissr);
 }
 
-__attribute__((weak))
 void spi_cs_deactivate(struct spi_slave *slave)
 {
 	struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
@@ -180,33 +136,26 @@ void spi_init(void)
 	/* do nothing */
 }
 
-void spi_set_speed(struct spi_slave *slave, uint hz)
-{
-	/* xilinx spi core does not support programmable speed */
-}
-
 struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 				  unsigned int max_hz, unsigned int mode)
 {
 	struct xilinx_spi_slave *xilspi;
 
 	if (!spi_cs_is_valid(bus, cs)) {
-		printf("XILSPI error: %s: unsupported bus %d / cs %d\n",
-				__func__, bus, cs);
+		printf("XILSPI error: unsupported bus %d / cs %d\n", bus, cs);
 		return NULL;
 	}
 
 	xilspi = spi_alloc_slave(struct xilinx_spi_slave, bus, cs);
 	if (!xilspi) {
-		printf("XILSPI error: %s: malloc of SPI structure failed\n",
-				__func__);
+		printf("XILSPI error: malloc of SPI structure failed\n");
 		return NULL;
 	}
 	xilspi->regs = (struct xilinx_spi_reg *)xilinx_spi_base_list[bus];
 	xilspi->freq = max_hz;
 	xilspi->mode = mode;
-	debug("%s: bus:%i cs:%i base:%p mode:%x max_hz:%d\n", __func__,
-		bus, cs, xilspi->regs, xilspi->mode, xilspi->freq);
+	debug("spi_setup_slave: bus:%i cs:%i base:%p mode:%x max_hz:%d\n",
+	      bus, cs, xilspi->regs, xilspi->mode, xilspi->freq);
 
 	writel(SPISSR_RESET_VALUE, &xilspi->regs->srr);
 
@@ -225,7 +174,7 @@ int spi_claim_bus(struct spi_slave *slave)
 	struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
 	u32 spicr;
 
-	debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs);
+	debug("spi_claim_bus: bus:%i cs:%i\n", slave->bus, slave->cs);
 	writel(SPISSR_OFF, &xilspi->regs->spissr);
 
 	spicr = XILSPI_SPICR_DFLT_ON;
@@ -246,7 +195,7 @@ void spi_release_bus(struct spi_slave *slave)
 {
 	struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
 
-	debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs);
+	debug("spi_release_bus: bus:%i cs:%i\n", slave->bus, slave->cs);
 	writel(SPISSR_OFF, &xilspi->regs->spissr);
 	writel(XILSPI_SPICR_DFLT_OFF, &xilspi->regs->spicr);
 }
@@ -262,14 +211,15 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 	unsigned rxecount = 17;	/* max. 16 elements in FIFO, leftover 1 */
 	unsigned global_timeout;
 
-	debug("%s: bus:%i cs:%i bitlen:%i bytes:%i flags:%lx\n", __func__,
-		slave->bus, slave->cs, bitlen, bytes, flags);
+	debug("spi_xfer: bus:%i cs:%i bitlen:%i bytes:%i flags:%lx\n",
+	      slave->bus, slave->cs, bitlen, bytes, flags);
+
 	if (bitlen == 0)
 		goto done;
 
 	if (bitlen % XILSPI_MAX_XFER_BITS) {
-		printf("XILSPI warning: %s: Not a multiple of %d bits\n",
-				__func__, XILSPI_MAX_XFER_BITS);
+		printf("XILSPI warning: Not a multiple of %d bits\n",
+		       XILSPI_MAX_XFER_BITS);
 		flags |= SPI_XFER_END;
 		goto done;
 	}
@@ -281,7 +231,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 	}
 
 	if (!rxecount) {
-		printf("XILSPI error: %s: Rx buffer not empty\n", __func__);
+		printf("XILSPI error: Rx buffer not empty\n");
 		return -1;
 	}
 
@@ -296,7 +246,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 		unsigned timeout = global_timeout;
 		/* get Tx element from data out buffer and count up */
 		unsigned char d = txp ? *txp++ : CONFIG_XILINX_SPI_IDLE_VAL;
-		debug("%s: tx:%x ", __func__, d);
+		debug("spi_xfer: tx:%x ", d);
 
 		/* write out and wait for processing (receive data) */
 		writel(d & SPIDTR_8BIT_MASK, &xilspi->regs->spidtr);
@@ -307,7 +257,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 		}
 
 		if (!timeout) {
-			printf("XILSPI error: %s: Xfer timeout\n", __func__);
+			printf("XILSPI error: Xfer timeout\n");
 			return -1;
 		}
 
@@ -315,7 +265,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 		d = readl(&xilspi->regs->spidrr) & SPIDRR_8BIT_MASK;
 		if (rxp)
 			*rxp++ = d;
-		debug("rx:%x\n", d);
+		debug("spi_xfer: rx:%x\n", d);
 	}
 
  done:
Signature · 1 line
1.9.1
#10 lore raw

PATCH 6/8 spi: xilinx_spi: Driver clean-up

Quoted 310 lines · Jagannadha Sutradharudu Teki

- Zap unneeded macros
- Re-arrange the code
- Removed __attribute__((weak))
- Replace __func__ macro with func names to save macro transition.
- Re-arranged comment lines.
- Arrange driver code in more readable format[1]

[1] http://lists.denx.de/pipermail/u-boot/2013-August/160473.html

---
 drivers/spi/xilinx_spi.c | 164 ++++++++++++++++-------------------------------
 1 file changed, 57 insertions(+), 107 deletions(-)
drivers/spi/xilinx_spi.c +56 -106
index 8073edc..650e494 100644
@@ -1,79 +1,31 @@
 /*
  * Xilinx SPI driver
  *
- * supports 8 bit SPI transfers only, with or w/o FIFO
+ * Supports 8 bit SPI transfers only, with or w/o FIFO
  *
- * based on bfin_spi.c, by way of altera_spi.c
- * Copyright (c) 2005-2008 Analog Devices Inc.
- * Copyright (c) 2010 Thomas Chou <[email protected]>
- * Copyright (c) 2010 Graeme Smecher <[email protected]>
+ * Based on bfin_spi.c, by way of altera_spi.c
  * Copyright (c) 2012 Stephan Linz <[email protected]>
+ * Copyright (c) 2010 Graeme Smecher <[email protected]>
+ * Copyright (c) 2010 Thomas Chou <[email protected]>
+ * Copyright (c) 2005-2008 Analog Devices Inc.
  *
  * SPDX-License-Identifier:	GPL-2.0+
- *
- * [0]: http://www.xilinx.com/support/documentation
- *
- * [S]:	[0]/ip_documentation/xps_spi.pdf
- *	[0]/ip_documentation/axi_spi_ds742.pdf
  */
+
 #include <config.h>
 #include <common.h>
 #include <malloc.h>
 #include <spi.h>
 
 /*
- * Xilinx SPI Register Definition
+ * [0]: http://www.xilinx.com/support/documentation
  *
+ * Xilinx SPI Register Definitions
  * [1]:	[0]/ip_documentation/xps_spi.pdf
  *	page 8, Register Descriptions
  * [2]:	[0]/ip_documentation/axi_spi_ds742.pdf
  *	page 7, Register Overview Table
  */
-struct xilinx_spi_reg {
-	u32 __space0__[7];
-	u32 dgier;	/* Device Global Interrupt Enable Register (DGIER) */
-	u32 ipisr;	/* IP Interrupt Status Register (IPISR) */
-	u32 __space1__;
-	u32 ipier;	/* IP Interrupt Enable Register (IPIER) */
-	u32 __space2__[5];
-	u32 srr;	/* Softare Reset Register (SRR) */
-	u32 __space3__[7];
-	u32 spicr;	/* SPI Control Register (SPICR) */
-	u32 spisr;	/* SPI Status Register (SPISR) */
-	u32 spidtr;	/* SPI Data Transmit Register (SPIDTR) */
-	u32 spidrr;	/* SPI Data Receive Register (SPIDRR) */
-	u32 spissr;	/* SPI Slave Select Register (SPISSR) */
-	u32 spitfor;	/* SPI Transmit FIFO Occupancy Register (SPITFOR) */
-	u32 spirfor;	/* SPI Receive FIFO Occupancy Register (SPIRFOR) */
-};
-
-/* Device Global Interrupt Enable Register (dgier), [1] p15, [2] p15 */
-#define DGIER_GIE		(1 << 31)
-
-/* IP Interrupt Status Register (ipisr), [1] p15, [2] p15 */
-#define IPISR_DRR_NOT_EMPTY	(1 << 8)
-#define IPISR_SLAVE_SELECT	(1 << 7)
-#define IPISR_TXF_HALF_EMPTY	(1 << 6)
-#define IPISR_DRR_OVERRUN	(1 << 5)
-#define IPISR_DRR_FULL		(1 << 4)
-#define IPISR_DTR_UNDERRUN	(1 << 3)
-#define IPISR_DTR_EMPTY		(1 << 2)
-#define IPISR_SLAVE_MODF	(1 << 1)
-#define IPISR_MODF		(1 << 0)
-
-/* IP Interrupt Enable Register (ipier), [1] p17, [2] p18 */
-#define IPIER_DRR_NOT_EMPTY	(1 << 8)
-#define IPIER_SLAVE_SELECT	(1 << 7)
-#define IPIER_TXF_HALF_EMPTY	(1 << 6)
-#define IPIER_DRR_OVERRUN	(1 << 5)
-#define IPIER_DRR_FULL		(1 << 4)
-#define IPIER_DTR_UNDERRUN	(1 << 3)
-#define IPIER_DTR_EMPTY		(1 << 2)
-#define IPIER_SLAVE_MODF	(1 << 1)
-#define IPIER_MODF		(1 << 0)
-
-/* Softare Reset Register (srr), [1] p9, [2] p8 */
-#define SRR_RESET_CODE		0x0000000A
 
 /* SPI Control Register (spicr), [1] p9, [2] p8 */
 #define SPICR_LSB_FIRST		(1 << 9)
@@ -110,17 +62,42 @@ struct xilinx_spi_reg {
 #define SPISSR_ACT(cs)		~SPISSR_MASK(cs)
 #define SPISSR_OFF		~0UL
 
-/* SPI Transmit FIFO Occupancy Register (spitfor), [1] p13, [2] p14 */
-#define SPITFOR_OCYVAL_POS	0
-#define SPITFOR_OCYVAL_MASK	(0xf << SPITFOR_OCYVAL_POS)
-
-/* SPI Receive FIFO Occupancy Register (spirfor), [1] p14, [2] p14 */
-#define SPIRFOR_OCYVAL_POS	0
-#define SPIRFOR_OCYVAL_MASK	(0xf << SPIRFOR_OCYVAL_POS)
-
 /* SPI Software Reset Register (ssr) */
 #define SPISSR_RESET_VALUE	0x0a
 
+#define XILSPI_MAX_XFER_BITS	8
+#define XILSPI_SPICR_DFLT_ON	(SPICR_MANUAL_SS | SPICR_MASTER_MODE | \
+				SPICR_SPE)
+#define XILSPI_SPICR_DFLT_OFF	(SPICR_MASTER_INHIBIT | SPICR_MANUAL_SS)
+
+#ifndef CONFIG_XILINX_SPI_IDLE_VAL
+#define CONFIG_XILINX_SPI_IDLE_VAL	0xff
+#endif
+
+#ifndef CONFIG_SYS_XILINX_SPI_LIST
+#define CONFIG_SYS_XILINX_SPI_LIST	{ CONFIG_SYS_SPI_BASE }
+#endif
+
+/* xilinx spi register set */
+struct xilinx_spi_reg {
+	u32 __space0__[7];
+	u32 dgier;	/* Device Global Interrupt Enable Register (DGIER) */
+	u32 ipisr;	/* IP Interrupt Status Register (IPISR) */
+	u32 __space1__;
+	u32 ipier;	/* IP Interrupt Enable Register (IPIER) */
+	u32 __space2__[5];
+	u32 srr;	/* Softare Reset Register (SRR) */
+	u32 __space3__[7];
+	u32 spicr;	/* SPI Control Register (SPICR) */
+	u32 spisr;	/* SPI Status Register (SPISR) */
+	u32 spidtr;	/* SPI Data Transmit Register (SPIDTR) */
+	u32 spidrr;	/* SPI Data Receive Register (SPIDRR) */
+	u32 spissr;	/* SPI Slave Select Register (SPISSR) */
+	u32 spitfor;	/* SPI Transmit FIFO Occupancy Register (SPITFOR) */
+	u32 spirfor;	/* SPI Receive FIFO Occupancy Register (SPIRFOR) */
+};
+
+/* xilinx spi slave */
 struct xilinx_spi_slave {
 	struct spi_slave slave;
 	struct xilinx_spi_reg *regs;
@@ -129,37 +106,17 @@ struct xilinx_spi_slave {
 };
 
 static inline struct xilinx_spi_slave *to_xilinx_spi_slave(
-					struct spi_slave *slave)
+			struct spi_slave *slave)
 {
 	return container_of(slave, struct xilinx_spi_slave, slave);
 }
 
-#ifndef CONFIG_SYS_XILINX_SPI_LIST
-#define CONFIG_SYS_XILINX_SPI_LIST	{ CONFIG_SYS_SPI_BASE }
-#endif
-
-#ifndef CONFIG_XILINX_SPI_IDLE_VAL
-#define CONFIG_XILINX_SPI_IDLE_VAL	0xff
-#endif
-
-#define XILSPI_SPICR_DFLT_ON		(SPICR_MANUAL_SS | \
-					 SPICR_MASTER_MODE | \
-					 SPICR_SPE)
-
-#define XILSPI_SPICR_DFLT_OFF		(SPICR_MASTER_INHIBIT | \
-					 SPICR_MANUAL_SS)
-
-#define XILSPI_MAX_XFER_BITS		8
-
 static unsigned long xilinx_spi_base_list[] = CONFIG_SYS_XILINX_SPI_LIST;
-
-__attribute__((weak))
 int spi_cs_is_valid(unsigned int bus, unsigned int cs)
 {
 	return bus < ARRAY_SIZE(xilinx_spi_base_list) && cs < 32;
 }
 
-__attribute__((weak))
 void spi_cs_activate(struct spi_slave *slave)
 {
 	struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
@@ -167,7 +124,6 @@ void spi_cs_activate(struct spi_slave *slave)
 	writel(SPISSR_ACT(slave->cs), &xilspi->regs->spissr);
 }
 
-__attribute__((weak))
 void spi_cs_deactivate(struct spi_slave *slave)
 {
 	struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
@@ -180,33 +136,26 @@ void spi_init(void)
 	/* do nothing */
 }
 
-void spi_set_speed(struct spi_slave *slave, uint hz)
-{
-	/* xilinx spi core does not support programmable speed */
-}
-
 struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 				  unsigned int max_hz, unsigned int mode)
 {
 	struct xilinx_spi_slave *xilspi;
 
 	if (!spi_cs_is_valid(bus, cs)) {
-		printf("XILSPI error: %s: unsupported bus %d / cs %d\n",
-				__func__, bus, cs);
+		printf("XILSPI error: unsupported bus %d / cs %d\n", bus, cs);
 		return NULL;
 	}
 
 	xilspi = spi_alloc_slave(struct xilinx_spi_slave, bus, cs);
 	if (!xilspi) {
-		printf("XILSPI error: %s: malloc of SPI structure failed\n",
-				__func__);
+		printf("XILSPI error: malloc of SPI structure failed\n");
 		return NULL;
 	}
 	xilspi->regs = (struct xilinx_spi_reg *)xilinx_spi_base_list[bus];
 	xilspi->freq = max_hz;
 	xilspi->mode = mode;
-	debug("%s: bus:%i cs:%i base:%p mode:%x max_hz:%d\n", __func__,
-		bus, cs, xilspi->regs, xilspi->mode, xilspi->freq);
+	debug("spi_setup_slave: bus:%i cs:%i base:%p mode:%x max_hz:%d\n",
+	      bus, cs, xilspi->regs, xilspi->mode, xilspi->freq);
 
 	writel(SPISSR_RESET_VALUE, &xilspi->regs->srr);
 
@@ -225,7 +174,7 @@ int spi_claim_bus(struct spi_slave *slave)
 	struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
 	u32 spicr;
 
-	debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs);
+	debug("spi_claim_bus: bus:%i cs:%i\n", slave->bus, slave->cs);
 	writel(SPISSR_OFF, &xilspi->regs->spissr);
 
 	spicr = XILSPI_SPICR_DFLT_ON;
@@ -246,7 +195,7 @@ void spi_release_bus(struct spi_slave *slave)
 {
 	struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
 
-	debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs);
+	debug("spi_release_bus: bus:%i cs:%i\n", slave->bus, slave->cs);
 	writel(SPISSR_OFF, &xilspi->regs->spissr);
 	writel(XILSPI_SPICR_DFLT_OFF, &xilspi->regs->spicr);
 }
@@ -262,14 +211,15 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 	unsigned rxecount = 17;	/* max. 16 elements in FIFO, leftover 1 */
 	unsigned global_timeout;
 
-	debug("%s: bus:%i cs:%i bitlen:%i bytes:%i flags:%lx\n", __func__,
-		slave->bus, slave->cs, bitlen, bytes, flags);
+	debug("spi_xfer: bus:%i cs:%i bitlen:%i bytes:%i flags:%lx\n",
+	      slave->bus, slave->cs, bitlen, bytes, flags);
+
 	if (bitlen == 0)
 		goto done;
 
 	if (bitlen % XILSPI_MAX_XFER_BITS) {
-		printf("XILSPI warning: %s: Not a multiple of %d bits\n",
-				__func__, XILSPI_MAX_XFER_BITS);
+		printf("XILSPI warning: Not a multiple of %d bits\n",
+		       XILSPI_MAX_XFER_BITS);
 		flags |= SPI_XFER_END;
 		goto done;
 	}
@@ -281,7 +231,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 	}
 
 	if (!rxecount) {
-		printf("XILSPI error: %s: Rx buffer not empty\n", __func__);
+		printf("XILSPI error: Rx buffer not empty\n");
 		return -1;
 	}
 
@@ -296,7 +246,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 		unsigned timeout = global_timeout;
 		/* get Tx element from data out buffer and count up */
 		unsigned char d = txp ? *txp++ : CONFIG_XILINX_SPI_IDLE_VAL;
-		debug("%s: tx:%x ", __func__, d);
+		debug("spi_xfer: tx:%x ", d);
 
 		/* write out and wait for processing (receive data) */
 		writel(d & SPIDTR_8BIT_MASK, &xilspi->regs->spidtr);
@@ -307,7 +257,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 		}
 
 		if (!timeout) {
-			printf("XILSPI error: %s: Xfer timeout\n", __func__);
+			printf("XILSPI error: Xfer timeout\n");
 			return -1;
 		}
 

drivers/spi/xilinx_spi.c int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, · line 271

Quoted 8 lines
drivers/spi/xilinx_spi.c +1 -1
@@ -315,7 +265,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 		d = readl(&xilspi->regs->spidrr) & SPIDRR_8BIT_MASK;
 		if (rxp)
 			*rxp++ = d;
-		debug("rx:%x\n", d);
+		debug("spi_xfer: rx:%x\n", d);
 	}
 
  done:

Hopefully there is functional change there.

Thanks,
Michal

author
#11 lore raw

PATCH 6/8 spi: xilinx_spi: Driver clean-up

Quoted 317 lines · Michal Simek
Quoted 316 lines · Jagannadha Sutradharudu Teki

- Zap unneeded macros
- Re-arrange the code
- Removed __attribute__((weak))
- Replace __func__ macro with func names to save macro transition.
- Re-arranged comment lines.
- Arrange driver code in more readable format[1]

[1] http://lists.denx.de/pipermail/u-boot/2013-August/160473.html

---
 drivers/spi/xilinx_spi.c | 164 ++++++++++++++++-------------------------------
 1 file changed, 57 insertions(+), 107 deletions(-)
drivers/spi/xilinx_spi.c +57 -107
index 8073edc..650e494 100644
@@ -1,79 +1,31 @@
 /*
  * Xilinx SPI driver
  *
- * supports 8 bit SPI transfers only, with or w/o FIFO
+ * Supports 8 bit SPI transfers only, with or w/o FIFO
  *
- * based on bfin_spi.c, by way of altera_spi.c
- * Copyright (c) 2005-2008 Analog Devices Inc.
- * Copyright (c) 2010 Thomas Chou <[email protected]>
- * Copyright (c) 2010 Graeme Smecher <[email protected]>
+ * Based on bfin_spi.c, by way of altera_spi.c
  * Copyright (c) 2012 Stephan Linz <[email protected]>
+ * Copyright (c) 2010 Graeme Smecher <[email protected]>
+ * Copyright (c) 2010 Thomas Chou <[email protected]>
+ * Copyright (c) 2005-2008 Analog Devices Inc.
  *
  * SPDX-License-Identifier:  GPL-2.0+
- *
- * [0]: http://www.xilinx.com/support/documentation
- *
- * [S]:      [0]/ip_documentation/xps_spi.pdf
- *   [0]/ip_documentation/axi_spi_ds742.pdf
  */
+
 #include <config.h>
 #include <common.h>
 #include <malloc.h>
 #include <spi.h>
 
 /*
- * Xilinx SPI Register Definition
+ * [0]: http://www.xilinx.com/support/documentation
  *
+ * Xilinx SPI Register Definitions
  * [1]:      [0]/ip_documentation/xps_spi.pdf
  *   page 8, Register Descriptions
  * [2]:      [0]/ip_documentation/axi_spi_ds742.pdf
  *   page 7, Register Overview Table
  */
-struct xilinx_spi_reg {
-     u32 __space0__[7];
-     u32 dgier;      /* Device Global Interrupt Enable Register (DGIER) */
-     u32 ipisr;      /* IP Interrupt Status Register (IPISR) */
-     u32 __space1__;
-     u32 ipier;      /* IP Interrupt Enable Register (IPIER) */
-     u32 __space2__[5];
-     u32 srr;        /* Softare Reset Register (SRR) */
-     u32 __space3__[7];
-     u32 spicr;      /* SPI Control Register (SPICR) */
-     u32 spisr;      /* SPI Status Register (SPISR) */
-     u32 spidtr;     /* SPI Data Transmit Register (SPIDTR) */
-     u32 spidrr;     /* SPI Data Receive Register (SPIDRR) */
-     u32 spissr;     /* SPI Slave Select Register (SPISSR) */
-     u32 spitfor;    /* SPI Transmit FIFO Occupancy Register (SPITFOR) */
-     u32 spirfor;    /* SPI Receive FIFO Occupancy Register (SPIRFOR) */
-};
-
-/* Device Global Interrupt Enable Register (dgier), [1] p15, [2] p15 */
-#define DGIER_GIE            (1 << 31)
-
-/* IP Interrupt Status Register (ipisr), [1] p15, [2] p15 */
-#define IPISR_DRR_NOT_EMPTY  (1 << 8)
-#define IPISR_SLAVE_SELECT   (1 << 7)
-#define IPISR_TXF_HALF_EMPTY (1 << 6)
-#define IPISR_DRR_OVERRUN    (1 << 5)
-#define IPISR_DRR_FULL               (1 << 4)
-#define IPISR_DTR_UNDERRUN   (1 << 3)
-#define IPISR_DTR_EMPTY              (1 << 2)
-#define IPISR_SLAVE_MODF     (1 << 1)
-#define IPISR_MODF           (1 << 0)
-
-/* IP Interrupt Enable Register (ipier), [1] p17, [2] p18 */
-#define IPIER_DRR_NOT_EMPTY  (1 << 8)
-#define IPIER_SLAVE_SELECT   (1 << 7)
-#define IPIER_TXF_HALF_EMPTY (1 << 6)
-#define IPIER_DRR_OVERRUN    (1 << 5)
-#define IPIER_DRR_FULL               (1 << 4)
-#define IPIER_DTR_UNDERRUN   (1 << 3)
-#define IPIER_DTR_EMPTY              (1 << 2)
-#define IPIER_SLAVE_MODF     (1 << 1)
-#define IPIER_MODF           (1 << 0)
-
-/* Softare Reset Register (srr), [1] p9, [2] p8 */
-#define SRR_RESET_CODE               0x0000000A
 
 /* SPI Control Register (spicr), [1] p9, [2] p8 */
 #define SPICR_LSB_FIRST              (1 << 9)
@@ -110,17 +62,42 @@ struct xilinx_spi_reg {
 #define SPISSR_ACT(cs)               ~SPISSR_MASK(cs)
 #define SPISSR_OFF           ~0UL
 
-/* SPI Transmit FIFO Occupancy Register (spitfor), [1] p13, [2] p14 */
-#define SPITFOR_OCYVAL_POS   0
-#define SPITFOR_OCYVAL_MASK  (0xf << SPITFOR_OCYVAL_POS)
-
-/* SPI Receive FIFO Occupancy Register (spirfor), [1] p14, [2] p14 */
-#define SPIRFOR_OCYVAL_POS   0
-#define SPIRFOR_OCYVAL_MASK  (0xf << SPIRFOR_OCYVAL_POS)
-
 /* SPI Software Reset Register (ssr) */
 #define SPISSR_RESET_VALUE   0x0a
 
+#define XILSPI_MAX_XFER_BITS 8
+#define XILSPI_SPICR_DFLT_ON (SPICR_MANUAL_SS | SPICR_MASTER_MODE | \
+                             SPICR_SPE)
+#define XILSPI_SPICR_DFLT_OFF        (SPICR_MASTER_INHIBIT | SPICR_MANUAL_SS)
+
+#ifndef CONFIG_XILINX_SPI_IDLE_VAL
+#define CONFIG_XILINX_SPI_IDLE_VAL   0xff
+#endif
+
+#ifndef CONFIG_SYS_XILINX_SPI_LIST
+#define CONFIG_SYS_XILINX_SPI_LIST   { CONFIG_SYS_SPI_BASE }
+#endif
+
+/* xilinx spi register set */
+struct xilinx_spi_reg {
+     u32 __space0__[7];
+     u32 dgier;      /* Device Global Interrupt Enable Register (DGIER) */
+     u32 ipisr;      /* IP Interrupt Status Register (IPISR) */
+     u32 __space1__;
+     u32 ipier;      /* IP Interrupt Enable Register (IPIER) */
+     u32 __space2__[5];
+     u32 srr;        /* Softare Reset Register (SRR) */
+     u32 __space3__[7];
+     u32 spicr;      /* SPI Control Register (SPICR) */
+     u32 spisr;      /* SPI Status Register (SPISR) */
+     u32 spidtr;     /* SPI Data Transmit Register (SPIDTR) */
+     u32 spidrr;     /* SPI Data Receive Register (SPIDRR) */
+     u32 spissr;     /* SPI Slave Select Register (SPISSR) */
+     u32 spitfor;    /* SPI Transmit FIFO Occupancy Register (SPITFOR) */
+     u32 spirfor;    /* SPI Receive FIFO Occupancy Register (SPIRFOR) */
+};
+
+/* xilinx spi slave */
 struct xilinx_spi_slave {
      struct spi_slave slave;
      struct xilinx_spi_reg *regs;
@@ -129,37 +106,17 @@ struct xilinx_spi_slave {
 };
 
 static inline struct xilinx_spi_slave *to_xilinx_spi_slave(
-                                     struct spi_slave *slave)
+                     struct spi_slave *slave)
 {
      return container_of(slave, struct xilinx_spi_slave, slave);
 }
 
-#ifndef CONFIG_SYS_XILINX_SPI_LIST
-#define CONFIG_SYS_XILINX_SPI_LIST   { CONFIG_SYS_SPI_BASE }
-#endif
-
-#ifndef CONFIG_XILINX_SPI_IDLE_VAL
-#define CONFIG_XILINX_SPI_IDLE_VAL   0xff
-#endif
-
-#define XILSPI_SPICR_DFLT_ON         (SPICR_MANUAL_SS | \
-                                      SPICR_MASTER_MODE | \
-                                      SPICR_SPE)
-
-#define XILSPI_SPICR_DFLT_OFF                (SPICR_MASTER_INHIBIT | \
-                                      SPICR_MANUAL_SS)
-
-#define XILSPI_MAX_XFER_BITS         8
-
 static unsigned long xilinx_spi_base_list[] = CONFIG_SYS_XILINX_SPI_LIST;
-
-__attribute__((weak))
 int spi_cs_is_valid(unsigned int bus, unsigned int cs)
 {
      return bus < ARRAY_SIZE(xilinx_spi_base_list) && cs < 32;
 }
 
-__attribute__((weak))
 void spi_cs_activate(struct spi_slave *slave)
 {
      struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
@@ -167,7 +124,6 @@ void spi_cs_activate(struct spi_slave *slave)
      writel(SPISSR_ACT(slave->cs), &xilspi->regs->spissr);
 }
 
-__attribute__((weak))
 void spi_cs_deactivate(struct spi_slave *slave)
 {
      struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
@@ -180,33 +136,26 @@ void spi_init(void)
      /* do nothing */
 }
 
-void spi_set_speed(struct spi_slave *slave, uint hz)
-{
-     /* xilinx spi core does not support programmable speed */
-}
-
 struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
                                unsigned int max_hz, unsigned int mode)
 {
      struct xilinx_spi_slave *xilspi;
 
      if (!spi_cs_is_valid(bus, cs)) {
-             printf("XILSPI error: %s: unsupported bus %d / cs %d\n",
-                             __func__, bus, cs);
+             printf("XILSPI error: unsupported bus %d / cs %d\n", bus, cs);
              return NULL;
      }
 
      xilspi = spi_alloc_slave(struct xilinx_spi_slave, bus, cs);
      if (!xilspi) {
-             printf("XILSPI error: %s: malloc of SPI structure failed\n",
-                             __func__);
+             printf("XILSPI error: malloc of SPI structure failed\n");
              return NULL;
      }
      xilspi->regs = (struct xilinx_spi_reg *)xilinx_spi_base_list[bus];
      xilspi->freq = max_hz;
      xilspi->mode = mode;
-     debug("%s: bus:%i cs:%i base:%p mode:%x max_hz:%d\n", __func__,
-             bus, cs, xilspi->regs, xilspi->mode, xilspi->freq);
+     debug("spi_setup_slave: bus:%i cs:%i base:%p mode:%x max_hz:%d\n",
+           bus, cs, xilspi->regs, xilspi->mode, xilspi->freq);
 
      writel(SPISSR_RESET_VALUE, &xilspi->regs->srr);
 
@@ -225,7 +174,7 @@ int spi_claim_bus(struct spi_slave *slave)
      struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
      u32 spicr;
 
-     debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs);
+     debug("spi_claim_bus: bus:%i cs:%i\n", slave->bus, slave->cs);
      writel(SPISSR_OFF, &xilspi->regs->spissr);
 
      spicr = XILSPI_SPICR_DFLT_ON;
@@ -246,7 +195,7 @@ void spi_release_bus(struct spi_slave *slave)
 {
      struct xilinx_spi_slave *xilspi = to_xilinx_spi_slave(slave);
 
-     debug("%s: bus:%i cs:%i\n", __func__, slave->bus, slave->cs);
+     debug("spi_release_bus: bus:%i cs:%i\n", slave->bus, slave->cs);
      writel(SPISSR_OFF, &xilspi->regs->spissr);
      writel(XILSPI_SPICR_DFLT_OFF, &xilspi->regs->spicr);
 }
@@ -262,14 +211,15 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
      unsigned rxecount = 17; /* max. 16 elements in FIFO, leftover 1 */
      unsigned global_timeout;
 
-     debug("%s: bus:%i cs:%i bitlen:%i bytes:%i flags:%lx\n", __func__,
-             slave->bus, slave->cs, bitlen, bytes, flags);
+     debug("spi_xfer: bus:%i cs:%i bitlen:%i bytes:%i flags:%lx\n",
+           slave->bus, slave->cs, bitlen, bytes, flags);
+
      if (bitlen == 0)
              goto done;
 
      if (bitlen % XILSPI_MAX_XFER_BITS) {
-             printf("XILSPI warning: %s: Not a multiple of %d bits\n",
-                             __func__, XILSPI_MAX_XFER_BITS);
+             printf("XILSPI warning: Not a multiple of %d bits\n",
+                    XILSPI_MAX_XFER_BITS);
              flags |= SPI_XFER_END;
              goto done;
      }
@@ -281,7 +231,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
      }
 
      if (!rxecount) {
-             printf("XILSPI error: %s: Rx buffer not empty\n", __func__);
+             printf("XILSPI error: Rx buffer not empty\n");
              return -1;
      }
 
@@ -296,7 +246,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
              unsigned timeout = global_timeout;
              /* get Tx element from data out buffer and count up */
              unsigned char d = txp ? *txp++ : CONFIG_XILINX_SPI_IDLE_VAL;
-             debug("%s: tx:%x ", __func__, d);
+             debug("spi_xfer: tx:%x ", d);
 
              /* write out and wait for processing (receive data) */
              writel(d & SPIDTR_8BIT_MASK, &xilspi->regs->spidtr);
@@ -307,7 +257,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
              }
 
              if (!timeout) {
-                     printf("XILSPI error: %s: Xfer timeout\n", __func__);
+                     printf("XILSPI error: Xfer timeout\n");
                      return -1;
              }
 
@@ -315,7 +265,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
              d = readl(&xilspi->regs->spidrr) & SPIDRR_8BIT_MASK;
              if (rxp)
                      *rxp++ = d;
-             debug("rx:%x\n", d);
+             debug("spi_xfer: rx:%x\n", d);
      }
 
Quoted 4 lines

drivers/spi/xilinx_spi.c int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, · line 271

Quoted 2 lines
drivers/spi/xilinx_spi.c +0 -0
  done:

Hopefully there is functional change there.

It's debug print update similar to tx, may be I will add note on commit message.

Quoted 2 lines

thanks!

Signature · 1 line
Jagan.
#12 lore raw

PATCH 7/8 spi: davinci_spi: Move header code to driver

In reply to Jagannadha Sutradharudu Teki

Move the header code into driver for more readable and easy to access it.

---
 drivers/spi/davinci_spi.c | 110 ++++++++++++++++++++++++++++++++++++++++-
 drivers/spi/davinci_spi.h | 121 ----------------------------------------------
 2 files changed, 109 insertions(+), 122 deletions(-)
 delete mode 100644 drivers/spi/davinci_spi.h
drivers/spi/davinci_spi.c +109 -1
index bf18362..e0ecf99 100644
@@ -13,7 +13,115 @@
 #include <malloc.h>
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
-#include "davinci_spi.h"
+
+struct davinci_spi_regs {
+	dv_reg	gcr0;		/* 0x00 */
+	dv_reg	gcr1;		/* 0x04 */
+	dv_reg	int0;		/* 0x08 */
+	dv_reg	lvl;		/* 0x0c */
+	dv_reg	flg;		/* 0x10 */
+	dv_reg	pc0;		/* 0x14 */
+	dv_reg	pc1;		/* 0x18 */
+	dv_reg	pc2;		/* 0x1c */
+	dv_reg	pc3;		/* 0x20 */
+	dv_reg	pc4;		/* 0x24 */
+	dv_reg	pc5;		/* 0x28 */
+	dv_reg	rsvd[3];
+	dv_reg	dat0;		/* 0x38 */
+	dv_reg	dat1;		/* 0x3c */
+	dv_reg	buf;		/* 0x40 */
+	dv_reg	emu;		/* 0x44 */
+	dv_reg	delay;		/* 0x48 */
+	dv_reg	def;		/* 0x4c */
+	dv_reg	fmt0;		/* 0x50 */
+	dv_reg	fmt1;		/* 0x54 */
+	dv_reg	fmt2;		/* 0x58 */
+	dv_reg	fmt3;		/* 0x5c */
+	dv_reg	intvec0;	/* 0x60 */
+	dv_reg	intvec1;	/* 0x64 */
+};
+
+#define BIT(x)			(1 << (x))
+
+/* SPIGCR0 */
+#define SPIGCR0_SPIENA_MASK	0x1
+#define SPIGCR0_SPIRST_MASK	0x0
+
+/* SPIGCR0 */
+#define SPIGCR1_CLKMOD_MASK	BIT(1)
+#define SPIGCR1_MASTER_MASK	BIT(0)
+#define SPIGCR1_SPIENA_MASK	BIT(24)
+
+/* SPIPC0 */
+#define SPIPC0_DIFUN_MASK	BIT(11)		/* SIMO */
+#define SPIPC0_DOFUN_MASK	BIT(10)		/* SOMI */
+#define SPIPC0_CLKFUN_MASK	BIT(9)		/* CLK */
+#define SPIPC0_EN0FUN_MASK	BIT(0)
+
+/* SPIFMT0 */
+#define SPIFMT_SHIFTDIR_SHIFT	20
+#define SPIFMT_POLARITY_SHIFT	17
+#define SPIFMT_PHASE_SHIFT	16
+#define SPIFMT_PRESCALE_SHIFT	8
+
+/* SPIDAT1 */
+#define SPIDAT1_CSHOLD_SHIFT	28
+#define SPIDAT1_CSNR_SHIFT	16
+
+/* SPIDELAY */
+#define SPI_C2TDELAY_SHIFT	24
+#define SPI_T2CDELAY_SHIFT	16
+
+/* SPIBUF */
+#define SPIBUF_RXEMPTY_MASK	BIT(31)
+#define SPIBUF_TXFULL_MASK	BIT(29)
+
+/* SPIDEF */
+#define SPIDEF_CSDEF0_MASK	BIT(0)
+
+#define SPI0_BUS		0
+#define SPI0_BASE		CONFIG_SYS_SPI_BASE
+/*
+ * Define default SPI0_NUM_CS as 1 for existing platforms that uses this
+ * driver. Platform can configure number of CS using CONFIG_SYS_SPI0_NUM_CS
+ * if more than one CS is supported and by defining CONFIG_SYS_SPI0.
+ */
+#ifndef CONFIG_SYS_SPI0
+#define SPI0_NUM_CS		1
+#else
+#define SPI0_NUM_CS		CONFIG_SYS_SPI0_NUM_CS
+#endif
+
+/*
+ * define CONFIG_SYS_SPI1 when platform has spi-1 device (bus #1) and
+ * CONFIG_SYS_SPI1_NUM_CS defines number of CS on this bus
+ */
+#ifdef CONFIG_SYS_SPI1
+#define SPI1_BUS		1
+#define SPI1_NUM_CS		CONFIG_SYS_SPI1_NUM_CS
+#define SPI1_BASE		CONFIG_SYS_SPI1_BASE
+#endif
+
+/*
+ * define CONFIG_SYS_SPI2 when platform has spi-2 device (bus #2) and
+ * CONFIG_SYS_SPI2_NUM_CS defines number of CS on this bus
+ */
+#ifdef CONFIG_SYS_SPI2
+#define SPI2_BUS		2
+#define SPI2_NUM_CS		CONFIG_SYS_SPI2_NUM_CS
+#define SPI2_BASE		CONFIG_SYS_SPI2_BASE
+#endif
+
+struct davinci_spi_slave {
+	struct spi_slave slave;
+	struct davinci_spi_regs *regs;
+	unsigned int freq;
+};
+
+static inline struct davinci_spi_slave *to_davinci_spi(struct spi_slave *slave)
+{
+	return container_of(slave, struct davinci_spi_slave, slave);
+}
 
 void spi_init()
 {
drivers/spi/davinci_spi.h deleted +0 -121

121 lines not on this page · raw message

Signature · 1 line
1.9.1
#13 lore raw

PATCH 8/8 spi: davinci_spi: Driver cleanup

In reply to Jagannadha Sutradharudu Teki

Arrange driver code in more readable format[1] for easy accessing and readable.
[1] http://lists.denx.de/pipermail/u-boot/2013-August/160473.html

---
 drivers/spi/davinci_spi.c | 343 +++++++++++++++++++++++-----------------------
 1 file changed, 173 insertions(+), 170 deletions(-)
drivers/spi/davinci_spi.c +173 -170
index e0ecf99..0a036cc 100644
@@ -8,39 +8,13 @@
  *
  * SPDX-License-Identifier:	GPL-2.0+
  */
+
 #include <common.h>
 #include <spi.h>
 #include <malloc.h>
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
 
-struct davinci_spi_regs {
-	dv_reg	gcr0;		/* 0x00 */
-	dv_reg	gcr1;		/* 0x04 */
-	dv_reg	int0;		/* 0x08 */
-	dv_reg	lvl;		/* 0x0c */
-	dv_reg	flg;		/* 0x10 */
-	dv_reg	pc0;		/* 0x14 */
-	dv_reg	pc1;		/* 0x18 */
-	dv_reg	pc2;		/* 0x1c */
-	dv_reg	pc3;		/* 0x20 */
-	dv_reg	pc4;		/* 0x24 */
-	dv_reg	pc5;		/* 0x28 */
-	dv_reg	rsvd[3];
-	dv_reg	dat0;		/* 0x38 */
-	dv_reg	dat1;		/* 0x3c */
-	dv_reg	buf;		/* 0x40 */
-	dv_reg	emu;		/* 0x44 */
-	dv_reg	delay;		/* 0x48 */
-	dv_reg	def;		/* 0x4c */
-	dv_reg	fmt0;		/* 0x50 */
-	dv_reg	fmt1;		/* 0x54 */
-	dv_reg	fmt2;		/* 0x58 */
-	dv_reg	fmt3;		/* 0x5c */
-	dv_reg	intvec0;	/* 0x60 */
-	dv_reg	intvec1;	/* 0x64 */
-};
-
 #define BIT(x)			(1 << (x))
 
 /* SPIGCR0 */
@@ -112,6 +86,35 @@ struct davinci_spi_regs {
 #define SPI2_BASE		CONFIG_SYS_SPI2_BASE
 #endif
 
+/* davinci spi register set */
+struct davinci_spi_regs {
+	dv_reg	gcr0;		/* 0x00 */
+	dv_reg	gcr1;		/* 0x04 */
+	dv_reg	int0;		/* 0x08 */
+	dv_reg	lvl;		/* 0x0c */
+	dv_reg	flg;		/* 0x10 */
+	dv_reg	pc0;		/* 0x14 */
+	dv_reg	pc1;		/* 0x18 */
+	dv_reg	pc2;		/* 0x1c */
+	dv_reg	pc3;		/* 0x20 */
+	dv_reg	pc4;		/* 0x24 */
+	dv_reg	pc5;		/* 0x28 */
+	dv_reg	rsvd[3];
+	dv_reg	dat0;		/* 0x38 */
+	dv_reg	dat1;		/* 0x3c */
+	dv_reg	buf;		/* 0x40 */
+	dv_reg	emu;		/* 0x44 */
+	dv_reg	delay;		/* 0x48 */
+	dv_reg	def;		/* 0x4c */
+	dv_reg	fmt0;		/* 0x50 */
+	dv_reg	fmt1;		/* 0x54 */
+	dv_reg	fmt2;		/* 0x58 */
+	dv_reg	fmt3;		/* 0x5c */
+	dv_reg	intvec0;	/* 0x60 */
+	dv_reg	intvec1;	/* 0x64 */
+};
+
+/* davinci spi slave */
 struct davinci_spi_slave {
 	struct spi_slave slave;
 	struct davinci_spi_regs *regs;
@@ -123,111 +126,6 @@ static inline struct davinci_spi_slave *to_davinci_spi(struct spi_slave *slave)
 	return container_of(slave, struct davinci_spi_slave, slave);
 }
 
-void spi_init()
-{
-	/* do nothing */
-}
-
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
-			unsigned int max_hz, unsigned int mode)
-{
-	struct davinci_spi_slave	*ds;
-
-	if (!spi_cs_is_valid(bus, cs))
-		return NULL;
-
-	ds = spi_alloc_slave(struct davinci_spi_slave, bus, cs);
-	if (!ds)
-		return NULL;
-
-	switch (bus) {
-	case SPI0_BUS:
-		ds->regs = (struct davinci_spi_regs *)SPI0_BASE;
-		break;
-#ifdef CONFIG_SYS_SPI1
-	case SPI1_BUS:
-		ds->regs = (struct davinci_spi_regs *)SPI1_BASE;
-		break;
-#endif
-#ifdef CONFIG_SYS_SPI2
-	case SPI2_BUS:
-		ds->regs = (struct davinci_spi_regs *)SPI2_BASE;
-		break;
-#endif
-	default: /* Invalid bus number */
-		return NULL;
-	}
-
-	ds->freq = max_hz;
-
-	return &ds->slave;
-}
-
-void spi_free_slave(struct spi_slave *slave)
-{
-	struct davinci_spi_slave *ds = to_davinci_spi(slave);
-
-	free(ds);
-}
-
-int spi_claim_bus(struct spi_slave *slave)
-{
-	struct davinci_spi_slave *ds = to_davinci_spi(slave);
-	unsigned int scalar;
-
-	/* Enable the SPI hardware */
-	writel(SPIGCR0_SPIRST_MASK, &ds->regs->gcr0);
-	udelay(1000);
-	writel(SPIGCR0_SPIENA_MASK, &ds->regs->gcr0);
-
-	/* Set master mode, powered up and not activated */
-	writel(SPIGCR1_MASTER_MASK | SPIGCR1_CLKMOD_MASK, &ds->regs->gcr1);
-
-	/* CS, CLK, SIMO and SOMI are functional pins */
-	writel(((1 << slave->cs) | SPIPC0_CLKFUN_MASK |
-		SPIPC0_DOFUN_MASK | SPIPC0_DIFUN_MASK), &ds->regs->pc0);
-
-	/* setup format */
-	scalar = ((CONFIG_SYS_SPI_CLK / ds->freq) - 1) & 0xFF;
-
-	/*
-	 * Use following format:
-	 *   character length = 8,
-	 *   clock signal delayed by half clk cycle,
-	 *   clock low in idle state - Mode 0,
-	 *   MSB shifted out first
-	 */
-	writel(8 | (scalar << SPIFMT_PRESCALE_SHIFT) |
-		(1 << SPIFMT_PHASE_SHIFT), &ds->regs->fmt0);
-
-	/*
-	 * Including a minor delay. No science here. Should be good even with
-	 * no delay
-	 */
-	writel((50 << SPI_C2TDELAY_SHIFT) |
-		(50 << SPI_T2CDELAY_SHIFT), &ds->regs->delay);
-
-	/* default chip select register */
-	writel(SPIDEF_CSDEF0_MASK, &ds->regs->def);
-
-	/* no interrupts */
-	writel(0, &ds->regs->int0);
-	writel(0, &ds->regs->lvl);
-
-	/* enable SPI */
-	writel((readl(&ds->regs->gcr1) | SPIGCR1_SPIENA_MASK), &ds->regs->gcr1);
-
-	return 0;
-}
-
-void spi_release_bus(struct spi_slave *slave)
-{
-	struct davinci_spi_slave *ds = to_davinci_spi(slave);
-
-	/* Disable the SPI hardware */
-	writel(SPIGCR0_SPIRST_MASK, &ds->regs->gcr0);
-}
-
 /*
  * This functions needs to act like a macro to avoid pipeline reloads in the
  * loops below. Use always_inline. This gains us about 160KiB/s and the bloat
@@ -343,6 +241,149 @@ static int davinci_spi_read_write(struct spi_slave *slave, unsigned int len,
 }
 #endif
 
+int spi_cs_is_valid(unsigned int bus, unsigned int cs)
+{
+	int ret = 0;
+
+	switch (bus) {
+	case SPI0_BUS:
+		if (cs < SPI0_NUM_CS)
+			ret = 1;
+		break;
+#ifdef CONFIG_SYS_SPI1
+	case SPI1_BUS:
+		if (cs < SPI1_NUM_CS)
+			ret = 1;
+		break;
+#endif
+#ifdef CONFIG_SYS_SPI2
+	case SPI2_BUS:
+		if (cs < SPI2_NUM_CS)
+			ret = 1;
+		break;
+#endif
+	default:
+		/* Invalid bus number. Do nothing */
+		break;
+	}
+	return ret;
+}
+
+void spi_cs_activate(struct spi_slave *slave)
+{
+	/* do nothing */
+}
+
+void spi_cs_deactivate(struct spi_slave *slave)
+{
+	/* do nothing */
+}
+
+void spi_init(void)
+{
+	/* do nothing */
+}
+
+struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
+			unsigned int max_hz, unsigned int mode)
+{
+	struct davinci_spi_slave	*ds;
+
+	if (!spi_cs_is_valid(bus, cs))
+		return NULL;
+
+	ds = spi_alloc_slave(struct davinci_spi_slave, bus, cs);
+	if (!ds)
+		return NULL;
+
+	switch (bus) {
+	case SPI0_BUS:
+		ds->regs = (struct davinci_spi_regs *)SPI0_BASE;
+		break;
+#ifdef CONFIG_SYS_SPI1
+	case SPI1_BUS:
+		ds->regs = (struct davinci_spi_regs *)SPI1_BASE;
+		break;
+#endif
+#ifdef CONFIG_SYS_SPI2
+	case SPI2_BUS:
+		ds->regs = (struct davinci_spi_regs *)SPI2_BASE;
+		break;
+#endif
+	default: /* Invalid bus number */
+		return NULL;
+	}
+
+	ds->freq = max_hz;
+
+	return &ds->slave;
+}
+
+void spi_free_slave(struct spi_slave *slave)
+{
+	struct davinci_spi_slave *ds = to_davinci_spi(slave);
+
+	free(ds);
+}
+
+int spi_claim_bus(struct spi_slave *slave)
+{
+	struct davinci_spi_slave *ds = to_davinci_spi(slave);
+	unsigned int scalar;
+
+	/* Enable the SPI hardware */
+	writel(SPIGCR0_SPIRST_MASK, &ds->regs->gcr0);
+	udelay(1000);
+	writel(SPIGCR0_SPIENA_MASK, &ds->regs->gcr0);
+
+	/* Set master mode, powered up and not activated */
+	writel(SPIGCR1_MASTER_MASK | SPIGCR1_CLKMOD_MASK, &ds->regs->gcr1);
+
+	/* CS, CLK, SIMO and SOMI are functional pins */
+	writel(((1 << slave->cs) | SPIPC0_CLKFUN_MASK |
+		SPIPC0_DOFUN_MASK | SPIPC0_DIFUN_MASK), &ds->regs->pc0);
+
+	/* setup format */
+	scalar = ((CONFIG_SYS_SPI_CLK / ds->freq) - 1) & 0xFF;
+
+	/*
+	 * Use following format:
+	 *   character length = 8,
+	 *   clock signal delayed by half clk cycle,
+	 *   clock low in idle state - Mode 0,
+	 *   MSB shifted out first
+	 */
+	writel(8 | (scalar << SPIFMT_PRESCALE_SHIFT) |
+		(1 << SPIFMT_PHASE_SHIFT), &ds->regs->fmt0);
+
+	/*
+	 * Including a minor delay. No science here. Should be good even with
+	 * no delay
+	 */
+	writel((50 << SPI_C2TDELAY_SHIFT) |
+		(50 << SPI_T2CDELAY_SHIFT), &ds->regs->delay);
+
+	/* default chip select register */
+	writel(SPIDEF_CSDEF0_MASK, &ds->regs->def);
+
+	/* no interrupts */
+	writel(0, &ds->regs->int0);
+	writel(0, &ds->regs->lvl);
+
+	/* enable SPI */
+	writel((readl(&ds->regs->gcr1) | SPIGCR1_SPIENA_MASK), &ds->regs->gcr1);
+
+	return 0;
+}
+
+void spi_release_bus(struct spi_slave *slave)
+{
+	struct davinci_spi_slave *ds = to_davinci_spi(slave);
+
+	/* Disable the SPI hardware */
+	writel(SPIGCR0_SPIRST_MASK, &ds->regs->gcr0);
+}
+
 int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
 	     const void *dout, void *din, unsigned long flags)
 {
@@ -386,41 +427,3 @@ out:
 	}
 	return 0;
 }
-
-int spi_cs_is_valid(unsigned int bus, unsigned int cs)
-{
-	int ret = 0;
-
-	switch (bus) {
-	case SPI0_BUS:
-		if (cs < SPI0_NUM_CS)
-			ret = 1;
-		break;
-#ifdef CONFIG_SYS_SPI1
-	case SPI1_BUS:
-		if (cs < SPI1_NUM_CS)
-			ret = 1;
-		break;
-#endif
-#ifdef CONFIG_SYS_SPI2
-	case SPI2_BUS:
-		if (cs < SPI2_NUM_CS)
-			ret = 1;
-		break;
-#endif
-	default:
-		/* Invalid bus number. Do nothing */
-		break;
-	}
-	return ret;
-}
-
-void spi_cs_activate(struct spi_slave *slave)
-{
-	/* do nothing */
-}
-
-void spi_cs_deactivate(struct spi_slave *slave)
-{
-	/* do nothing */
-}
Signature · 1 line
1.9.1