Skip to contentSkip to conversation

spi: driver for the Synopsys DesignWare SPI controller

PATCH Superseded Baruch Siach 2 participants 3 messages Jun 4, 2009 – Jun 5, 2009 2 messages not in the archive SPI

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 spi: driver for the Synopsys DesignWare SPI controller

---
Changes in v3:
- Address the comments of Linus Walleij

Changes in v2:
- printk -> dev_err
- indentation fix
- documentation file for BSP writers added

 Documentation/spi/designware   |   88 +++++
 drivers/spi/Kconfig            |    6 +
 drivers/spi/Makefile           |    1 +
 drivers/spi/designware_spi.c   |  723 ++++++++++++++++++++++++++++++++++++++++
 include/linux/spi/designware.h |   10 +
 5 files changed, 828 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/spi/designware
 create mode 100644 drivers/spi/designware_spi.c
 create mode 100644 include/linux/spi/designware.h
Documentation/spi/designware new file +88 -0
new file mode 100644
index 0000000..9ca057d
@@ -0,0 +1,88 @@
+Synopsys DesignWare SPI controller driver
+
+Platform Data
+
+In order to use this driver you need to include linux/spi/designware.h in your
+platform code and provide the following information to the driver using the
+designware_platform_data struct:
+
+	ssi_clk: your ssi_clk in Hz.
+
+	tx_fifo_depth: this must be equal to your SSI_TX_FIFO_DEPTH hardware
+	configuration parameter.
+
+	rx_fifo_depth: this must be equal to your SSI_RX_FIFO_DEPTH hardware
+	configuration parameter.
+
+	num_chipselect: this must be equal to (SSI_NUM_SLAVES - 1), where
+	SSI_NUM_SLAVES is your hardware configuration parameter.
+
+Description of the hardware configuration parameters appear in chapter 4 of the
+DesignWare DW_apb_ssi Databook. Put a pointer to designware_platform_data in
+the platform_data member of the platform_device struct, that you pass to
+platform_device_register. Here is an example:
+
+static struct designware_platform_data spi_controller_pdata __initdata = {
+	.ssi_clk = 100000000, /* 100MHz */
+	.tx_fifo_depth = 256,
+	.rx_fifo_depth = 256,
+	.num_chipselect = 15,
+};
+
+static struct platform_device designware_spi_controller __initdata = {
+	.name		= "designware_spi",
+	.dev		= {
+		.coherent_dma_mask = ~0,
+		.platform_data = &spi_controller_pdata,
+	},
+	.id		= -1,
+	.num_resources	= ARRAY_SIZE(designware_spi_controller_resources),
+	.resource	= &designware_spi_controller_resources[0],
+};
+
+void __init myboard_init(void)
+{
+	/* ... */
+	platform_device_register(&designware_spi_controller);
+};
+
+GPIOs Instead of Native Chip Select
+
+The driver supports the use of GPIO pins instead of the native chip select pins
+of the hardware. This is because of the weird design of the hardware as
+described below. The driver uses the generic gpio API as described in
+Documentation/gpio.txt.
+
+To use this support make sure that your architecture supports the gpio API.
+Then set the controller_data member of the spi_board_info struct to the GPIO
+number that is wired to serve as chip select. For example:
+
+static struct spi_board_info my_nic_board_info __initdata = {
+	.modalias	= "enc28j60",
+	.mode   	= SPI_MODE_0,
+	.irq		= IRQ_ETH,
+	.max_speed_hz	= 10000000,
+	.chip_select	= 2,
+	.controller_data = (void *) 14, /* GPIO 14 */
+};
+
+TX FIFO Size Limitation
+
+The Synopsys DesignWare SPI controller suffers from a design bug in that chip
+select is automatically deactivated when the TX FIFO empties. The driver
+configures the hardware to fire an interrupt when the TX FIFO gets half empty,
+and tries to refill the TX FIFO. This way the driver does best effort to
+complete long SPI transactions without deactivating the chip select. But this
+is not always enough. Whether this limitation affects your setup depends on
+many factors including the CPU speed, the SPI bit frequency, the size of the TX
+FIFO, the length of your SPI transactions, and the length of IRQs disabled
+periods in your specific kernel configuration. You may prefer to use GPIOs for
+chip select as described above.
+
+SPI Modes 0 & 2 Weirdness
+
+The hardware is designed to deactivate the chip select between words when CPHA
+= 0 (i.e. SPI modes 0 and 2). Depending on your SPI devices, this may make
+those mode unusable when the hardware SPI controller chip select pin is
+directly connected. The ENC28J60 network interface can't work with CPHA = 1.
+Here again a GPIO comes to the rescue.
drivers/spi/Kconfig +6 -0
index 83a185d..dca6dd1 100644
@@ -116,6 +116,12 @@ config SPI_GPIO
 	  GPIO operations, you should be able to leverage that for better
 	  speed with a custom version of this driver; see the source code.
 
+config SPI_DESIGNWARE
+	tristate "Synopsys DesignWare SPI controller"
+	  depends on SPI_MASTER
+	  help
+	    SPI controller driver for the Synopsys DesignWare DW_apb_ssi.
+
 config SPI_IMX
 	tristate "Freescale iMX SPI controller"
 	depends on ARCH_IMX && EXPERIMENTAL
drivers/spi/Makefile +1 -0
index 5d04519..bf51c5a 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_SPI_BITBANG)		+= spi_bitbang.o
 obj-$(CONFIG_SPI_AU1550)		+= au1550_spi.o
 obj-$(CONFIG_SPI_BUTTERFLY)		+= spi_butterfly.o
 obj-$(CONFIG_SPI_GPIO)			+= spi_gpio.o
+obj-$(CONFIG_SPI_DESIGNWARE)		+= designware_spi.o
 obj-$(CONFIG_SPI_IMX)			+= spi_imx.o
 obj-$(CONFIG_SPI_LM70_LLP)		+= spi_lm70llp.o
 obj-$(CONFIG_SPI_PXA2XX)		+= pxa2xx_spi.o
drivers/spi/designware_spi.c new file +723 -0

723 lines not on this page · raw message

include/linux/spi/designware.h new file +10 -0
new file mode 100644
index 0000000..26427cd
@@ -0,0 +1,10 @@
+/*
+ * designware.h - platform glue for the Synopsys DesignWare SPI controller
+ */
+
+struct designware_platform_data {
+	unsigned int	ssi_clk;	/* clock in Hz */
+	unsigned int	tx_fifo_depth;	/* bytes in TX FIFO */
+	unsigned int	rx_fifo_depth;	/* bytes in RX FIFO */
+	u16		num_chipselect;	/* number of CSs */
+};
Signature · 9 lines
1.6.3.1


------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get

A message that is not in the archive (sent off-list or not yet received): 1244087418-10889-1-git-send-email-baruch-NswTu9S1W3P6gbPvEgmw2w@public.gmane.org

#2 lore raw

2009/6/4 Baruch Siach <[email protected]>:

drivers/spi/designware_spi.c line 688

Quoted 10 lines
drivers/spi/designware_spi.c new file +10 -0
+static int __devexit designware_spi_remove(struct platform_device *dev)
+{
+       struct designware_spi *dwspi;
+       struct spi_master *master;
+
+       master = platform_get_drvdata(dev);
+       dwspi = spi_master_get_devdata(master);
+
+       free_irq(dwspi->irq, dwspi);
+       iounmap(dwspi->regs);

release_mem_region()?

drivers/spi/designware_spi.c line 197

Quoted 7 lines

+       destroy_workqueue(dwspi->workqueue);
+       tasklet_kill(&dwspi->pump_transfers);
+       platform_set_drvdata(dev, 0);
+       spi_master_put(master);

drivers/spi/designware_spi.c new file +3 -0
+
+       return 0;
+}

Then it's good :-)

Linus

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises looking to deploy the next generation of Solaris that includes the latest innovations from Sun and the OpenSource community. Download a copy and enjoy capabilities such as Networking, Storage and Virtualization. Go to: http://p.sf.net/sfu/opensolaris-get

A message that is not in the archive (sent off-list or not yet received): 63386a3d0906040130h322028d3ocbd3e31719bac8c9-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#4 lore raw

Hi Linus,

Quoted 14 lines · Linus Walleij

2009/6/4 Baruch Siach <[email protected]>:

drivers/spi/designware_spi.c line 688

Quoted 10 lines
drivers/spi/designware_spi.c new file +10 -0
+static int __devexit designware_spi_remove(struct platform_device *dev)
+{
+       struct designware_spi *dwspi;
+       struct spi_master *master;
+
+       master = platform_get_drvdata(dev);
+       dwspi = spi_master_get_devdata(master);
+
+       free_irq(dwspi->irq, dwspi);
+       iounmap(dwspi->regs);

release_mem_region()?

OK.

Quoted 10 lines

drivers/spi/designware_spi.c line 197

Quoted 7 lines

+       destroy_workqueue(dwspi->workqueue);
+       tasklet_kill(&dwspi->pump_transfers);
+       platform_set_drvdata(dev, 0);
+       spi_master_put(master);

drivers/spi/designware_spi.c new file +3 -0
+
+       return 0;
+}

Then it's good :-)

Thanks.

baruch

Signature · 10 lines
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - [email protected] - tel: +972.2.679.5364, http://www.tkos.co.il -

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get