Skip to contentSkip to conversation

SPI S3C64XX: SPI Controller driver for S3C64XX

PATCH New Jassi Brar 3 participants 3 messages Nov 26, 2009

Subsystems (3)
lore
Share & tools
lore

Jassi Brar

author
#0 lore raw

PATCH 5/5 SPI S3C64XX: SPI Controller driver for S3C64XX

Added S3C64XX SPI controller driver.

Each SPI controller has exactly one CS line and as such doesn't provide for multi-cs. We implement a workaround to support multi-cs by _not_ configuring the mux'ed CS pin for each SPI controller. The CS mechanism is assumed to be fully machine specific - the driver doesn't even assume some GPIO pin is used to control the CS.

The driver selects between DMA and POLLING mode depending upon the xfer size - DMA mode for xfers bigger than FIFO size, POLLING mode otherwise.

The driver has been designed to be capable of running SoCs since s3c64xx and till date, for that reason some of the register fields have been passed via, SoC specific, platform data.

---
 drivers/spi/Kconfig       |    7 +
 drivers/spi/Makefile      |    1 +
 drivers/spi/spi_s3c64xx.c | 1033 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/spi/spi_s3c64xx.h |  189 +++++++++
 4 files changed, 1230 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/spi_s3c64xx.c
 create mode 100644 drivers/spi/spi_s3c64xx.h
drivers/spi/Kconfig +7 -0
index 2c733c2..5c67e1e 100644
@@ -204,6 +204,13 @@ config SPI_S3C24XX_GPIO
 	  the inbuilt hardware cannot provide the transfer mode, or
 	  where the board is using non hardware connected pins.
 
+config SPI_S3C64XX
+	tristate "Samsung S3C64XX series type SPI"
+	depends on ARCH_S3C64XX && EXPERIMENTAL
+	select S3C64XX_DMA
+	help
+	  SPI driver for Samsung S3C64XX and newer SoCs.
+
 config SPI_SH_SCI
 	tristate "SuperH SCI SPI controller"
 	depends on SUPERH
drivers/spi/Makefile +1 -0
index 3de408d..53452b2 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_SPI_S3C24XX)		+= spi_s3c24xx.o
 obj-$(CONFIG_SPI_TXX9)			+= spi_txx9.o
 obj-$(CONFIG_SPI_XILINX)		+= xilinx_spi.o
 obj-$(CONFIG_SPI_SH_SCI)		+= spi_sh_sci.o
+obj-$(CONFIG_SPI_S3C64XX)		+= spi_s3c64xx.o
 # 	... add above this line ...
 
 # SPI protocol drivers (device/link on bus)
drivers/spi/spi_s3c64xx.c new file +1033 -0

1,033 lines not on this page · raw message

drivers/spi/spi_s3c64xx.h new file +189 -0

189 lines not on this page · raw message

Signature · 1 line
1.6.2.5
#1 lore raw

PATCH 5/5 SPI S3C64XX: SPI Controller driver for S3C64XX

Quoted 17 lines · Jassi Brar

Added S3C64XX SPI controller driver.

Each SPI controller has exactly one CS line and as such doesn't provide for multi-cs. We implement a workaround to support multi-cs by _not_ configuring the mux'ed CS pin for each SPI controller. The CS mechanism is assumed to be fully machine specific - the driver doesn't even assume some GPIO pin is used to control the CS.

The driver selects between DMA and POLLING mode depending upon the xfer size - DMA mode for xfers bigger than FIFO size, POLLING mode otherwise.

The driver has been designed to be capable of running SoCs since s3c64xx and till date, for that reason some of the register fields have been passed via, SoC specific, platform data.

Quoted 6 lines

---

?drivers/spi/Kconfig ? ? ? | ? ?7 +
?drivers/spi/Makefile ? ? ?| ? ?1 +
?drivers/spi/spi_s3c64xx.c | 1033 +++++++++++++++++++++++++++++++++++++++++++++
?drivers/spi/spi_s3c64xx.h | ?189 +++++++++

This is in the drivers/spi tree, but depends on the arch/arm stuff from the first 4 patches. Will need to decide which tree to merge this driver though.

I won't review patches 1-4, but I've got a few comments for this patch. Mostly minor stuff. I don't seen anything on quick review that jumps out at me as bad.

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+#include "spi_s3c64xx.h"

First, why the separate header file? It doesn't look like there are any external users of the header file data. Please merge it into the top of the .c file.

Quoted 13 lines
(quoted diff) +13 -0
+
+static struct s3c2410_dma_client s3c64xx_spi_dma_client = {
+ ? ? ? .name = "s3c64xx-spi-dma",
+};
+
+#define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
+
+static void flush_fifo(struct s3c64xx_spi_driver_data *sdd)
+{
+ ? ? ? struct s3c64xx_spi_cntrlr_info *sci = sdd->cntrlr_info;
+ ? ? ? unsigned long loops;
+ ? ? ? u32 val;
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+ ? ? ? val = readl(sdd->regs + S3C64XX_SPI_CH_CFG);
+ ? ? ? val |= S3C64XX_SPI_CH_SW_RST;
+ ? ? ? val &= ~S3C64XX_SPI_CH_HS_EN;
+ ? ? ? writel(val, sdd->regs + S3C64XX_SPI_CH_CFG);
+
+ ? ? ? /* Flush TxFIFO*/
+ ? ? ? loops = msecs_to_loops(1);
+ ? ? ? do {
+ ? ? ? ? ? ? ? val = readl(sdd->regs + S3C64XX_SPI_STATUS);
+ ? ? ? } while (TX_FIFO_LVL(val, sci) && loops--);

nasty spin. Can you sleep here instead? How much time do you project is needed to flush the fifo. It is a worthwhile question to ask on the other spin loops through this file.

Quoted 12 lines
(quoted diff) +12 -0
+static inline void enable_cs(struct s3c64xx_spi_driver_data *sdd,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? struct spi_device *spi)
+{
+ ? ? ? struct s3c64xx_spi_csinfo *cs;
+
+ ? ? ? if (sdd->tgl_spi != NULL) { /* If last device toggled after mssg */
+ ? ? ? ? ? ? ? if (sdd->tgl_spi != spi) { /* if last mssg on diff device */
+ ? ? ? ? ? ? ? ? ? ? ? /* Deselect the last toggled device */
+ ? ? ? ? ? ? ? ? ? ? ? cs = sdd->tgl_spi->controller_data;
+ ? ? ? ? ? ? ? ? ? ? ? if (sdd->tgl_spi->mode & SPI_CS_HIGH)
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cs->set_level(0);
+ ? ? ? ? ? ? ? ? ? ? ? else

Review

Quoted 10 lines
(quoted diff) +10 -0
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cs->set_level(1);
+ ? ? ? ? ? ? ? }
+ ? ? ? ? ? ? ? sdd->tgl_spi = NULL;
+ ? ? ? }
+
+ ? ? ? cs = spi->controller_data;
+ ? ? ? if (spi->mode & SPI_CS_HIGH)
+ ? ? ? ? ? ? ? cs->set_level(1);
+ ? ? ? else
+ ? ? ? ? ? ? ? cs->set_level(0);

cs->set_level(spi->mode & SPI_CS_HIGH ? 1 : 0) perhaps?

Quoted 3 lines
drivers/spi/spi_s3c64xx.c new file +3 -0
+
+ ? ? ? S3C64XX_SPI_ACT(sdd);
+}

[...]

Quoted 5 lines
(quoted diff) +5 -0
+static inline void disable_cs(struct s3c64xx_spi_driver_data *sdd,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? struct spi_device *spi)
+{
+ ? ? ? struct s3c64xx_spi_csinfo *cs;
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+ ? ? ? S3C64XX_SPI_DEACT(sdd);
+
+ ? ? ? if (sdd->tgl_spi == spi)
+ ? ? ? ? ? ? ? sdd->tgl_spi = NULL;
+
+ ? ? ? cs = spi->controller_data;
+ ? ? ? if (spi->mode & SPI_CS_HIGH)
+ ? ? ? ? ? ? ? cs->set_level(0);
+ ? ? ? else
+ ? ? ? ? ? ? ? cs->set_level(1);

ditto here.

g.

#2 lore raw

PATCH 5/5 SPI S3C64XX: SPI Controller driver for S3C64XX

Quoted 33 lines · Grant Likely
Quoted 17 lines · Jassi Brar

Added S3C64XX SPI controller driver.

Each SPI controller has exactly one CS line and as such doesn't provide for multi-cs. We implement a workaround to support multi-cs by _not_ configuring the mux'ed CS pin for each SPI controller. The CS mechanism is assumed to be fully machine specific - the driver doesn't even assume some GPIO pin is used to control the CS.

The driver selects between DMA and POLLING mode depending upon the xfer size - DMA mode for xfers bigger than FIFO size, POLLING mode otherwise.

The driver has been designed to be capable of running SoCs since s3c64xx and till date, for that reason some of the register fields have been passed via, SoC specific, platform data.

Quoted 6 lines

---
 drivers/spi/Kconfig       |    7 +
 drivers/spi/Makefile      |    1 +
 drivers/spi/spi_s3c64xx.c | 1033 +++++++++++++++++++++++++++++++++++++++++++++ drivers/spi/spi_s3c64xx.h |  189 +++++++++

This is in the drivers/spi tree, but depends on the arch/arm stuff from the first 4 patches.  Will need to decide which tree to merge this driver though.

I won't review patches 1-4, but I've got a few comments for this patch.  Mostly minor stuff.  I don't seen anything on quick review that jumps out at me as bad.

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+#include "spi_s3c64xx.h"

First, why the separate header file?  It doesn't look like there are any external users of the header file data.  Please merge it into the top of the .c file.

there is no user other than spi_s3c64xx.c
okay, I will merge the header in code.

Quoted 19 lines
Quoted 19 lines
drivers/spi/spi_s3c64xx.c new file +19 -0
+
+static struct s3c2410_dma_client s3c64xx_spi_dma_client = {
+       .name = "s3c64xx-spi-dma",
+};
+
+#define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
+
+static void flush_fifo(struct s3c64xx_spi_driver_data *sdd)
+{
+       struct s3c64xx_spi_cntrlr_info *sci = sdd->cntrlr_info;
+       unsigned long loops;
+       u32 val;
+
+       val = readl(sdd->regs + S3C64XX_SPI_CH_CFG);
+       val |= S3C64XX_SPI_CH_SW_RST;
+       val &= ~S3C64XX_SPI_CH_HS_EN;
+       writel(val, sdd->regs + S3C64XX_SPI_CH_CFG);
+
+       /* Flush TxFIFO*/
Quoted 8 lines
Quoted 4 lines

+       loops = msecs_to_loops(1);
+       do {
+               val = readl(sdd->regs + S3C64XX_SPI_STATUS);
+       } while (TX_FIFO_LVL(val, sci) && loops--);

nasty spin.  Can you sleep here instead?  How much time do you project is needed to flush the fifo.  It is a worthwhile question to ask on the other spin loops through this file.

Since this is called from between two xfers of a message, sleeping isn't an option. Besides, the loops shudn't take more than a few counts if everything is working fine.
FIFO needs to be flushed before setting the PACKET_CNT register. The real flushing is done by the S3C64XX_SPI_CH_SW_RST bit, these loops are just to 'confirm' flushing. So, ideally, it shudn't loop even second counter. Practically, a few microseconds shud be enough waiting for correct status. Btw, if it waits 1ms full, its pretty much the controller malfunctioned and subsequent xfers will fail too(so we don't catch the error here).
This function is called after every xfer so we can not sleep, even one slice,
when the FIFO is flushed but the status register doesn't yet reflect that.

The same holds for the other loop.

Quoted 16 lines
Quoted 16 lines
drivers/spi/spi_s3c64xx.c new file +16 -0
+static inline void enable_cs(struct s3c64xx_spi_driver_data *sdd,
+                                               struct spi_device *spi)
+{
+       struct s3c64xx_spi_csinfo *cs;
+
+       if (sdd->tgl_spi != NULL) { /* If last device toggled after mssg */
+               if (sdd->tgl_spi != spi) { /* if last mssg on diff device */
+                       /* Deselect the last toggled device */
+                       cs = sdd->tgl_spi->controller_data;
+                       if (sdd->tgl_spi->mode & SPI_CS_HIGH)
+                               cs->set_level(0);
+                       else
+                               cs->set_level(1);
+               }
+               sdd->tgl_spi = NULL;
+       }
Quoted 8 lines
Quoted 6 lines

+
+       cs = spi->controller_data;
+       if (spi->mode & SPI_CS_HIGH)
+               cs->set_level(1);
+       else
+               cs->set_level(0);

cs->set_level(spi->mode & SPI_CS_HIGH ? 1 : 0) perhaps?

yes, that wud be better.

Quoted 13 lines
Quoted 3 lines
drivers/spi/spi_s3c64xx.c new file +3 -0
+
+       S3C64XX_SPI_ACT(sdd);
+}

[...]

Quoted 9 lines
drivers/spi/spi_s3c64xx.c new file +9 -0
+static inline void disable_cs(struct s3c64xx_spi_driver_data *sdd,
+                                               struct spi_device *spi)
+{
+       struct s3c64xx_spi_csinfo *cs;
+
+       S3C64XX_SPI_DEACT(sdd);
+
+       if (sdd->tgl_spi == spi)
+               sdd->tgl_spi = NULL;
Quoted 8 lines
Quoted 6 lines

+
+       cs = spi->controller_data;
+       if (spi->mode & SPI_CS_HIGH)
+               cs->set_level(0);
+       else
+               cs->set_level(1);

ditto here.

yes sure.
Thanks.