Skip to contentSkip to conversation

SPI: Add SPI driver for most known i.MX SoCs

PATCH Sascha Hauer 2 participants 4 messages May 4, 2009 – Jun 21, 2009 3 messages not in the archive

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

While there already is a SPI driver for i.MX1 in the tree there are good reasons to replace it:

- The inkernel driver implements a full blown SPI driver, but the hardware can be fully supported using a bitbang driver. This greatly reduces the size and complexity of the driver.
- The inkernel driver only works on i.MX1 SoCs. Unfortunately Freescale decided to randomly mix the register bits for each new SoC, This is quite hard to handle with the current driver since it has register accesses in many places.
- The DMA API of the durrent driver is broken for arch-mx1 (as opposed to arch-imx) and nobody cared to fix it yet.

This driver has been tested on i.MX1/i.MX27 with an AT25 type EEPROM and on i.MX27/i.MX31 with a Freescale MC13783 PMIC. Though untested it should also work on i.MX35.

---
 arch/arm/plat-mxc/include/mach/spi.h |   27 ++
 drivers/spi/Kconfig                  |    7 +-
 drivers/spi/Makefile                 |    2 +-
 drivers/spi/mxc_spi.c                |  667 ++++++++++++++++++++++++++++++++++
 4 files changed, 699 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/plat-mxc/include/mach/spi.h
 create mode 100644 drivers/spi/mxc_spi.c
arch/arm/plat-mxc/include/mach/spi.h new file +27 -0
new file mode 100644
index 0000000..08be445
@@ -0,0 +1,27 @@
+
+#ifndef __MACH_SPI_H_
+#define __MACH_SPI_H_
+
+/*
+ * struct spi_imx_master - device.platform_data for SPI controller devices.
+ * @chipselect: Array of chipselects for this master. Numbers >= 0 mean gpio
+ *              pins, numbers < 0 mean internal CSPI chipselects according
+ *              to MXC_SPI_CS(). Normally you want to use gpio based chip
+ *              selects as the CSPI module tries to be intelligent about
+ *              when to assert the chipselect: The CSPI module deasserts the
+ *              chipselect once it runs out of input data. The other problem
+ *              is that it is not possible to mix between high active and low
+ *              active chipselects on one single bus using the internal
+ *              chipselects. Unfortunately Freescale decided to put some
+ *              chipselects on dedicated pins which are not usable as gpios,
+ *              so we have to support the internal chipselects.
+ * @num_chipselect: ARRAY_SIZE(chipselect)
+ */
+struct spi_imx_master {
+	int	*chipselect;
+	int	num_chipselect;
+};
+
+#define MXC_SPI_CS(no)	((no) - 32)
+
+#endif /* __MACH_SPI_H_*/
drivers/spi/Kconfig +4 -3
index 7c61251..6bb8e12 100644
@@ -117,10 +117,11 @@ config SPI_GPIO
 	  speed with a custom version of this driver; see the source code.
 
 config SPI_IMX
-	tristate "Freescale iMX SPI controller"
-	depends on ARCH_MX1 && EXPERIMENTAL
+	tristate "Freescale iMX SPI controllers"
+	depends on ARCH_MXC
+	select SPI_BITBANG
 	help
-	  This enables using the Freescale iMX SPI controller in master
+	  This enables using the Freescale iMX SPI controllers in master
 	  mode.
 
 config SPI_LM70_LLP
drivers/spi/Makefile +1 -1
index 5d04519..73b508b 100644
@@ -17,7 +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_IMX)			+= spi_imx.o
+obj-$(CONFIG_SPI_IMX)			+= mxc_spi.o
 obj-$(CONFIG_SPI_LM70_LLP)		+= spi_lm70llp.o
 obj-$(CONFIG_SPI_PXA2XX)		+= pxa2xx_spi.o
 obj-$(CONFIG_SPI_OMAP_UWIRE)		+= omap_uwire.o
drivers/spi/mxc_spi.c new file +667 -0

667 lines not on this page · raw message

Signature · 14 lines
1.6.2.1

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations 
Conference from O'Reilly Media. Velocity features a full day of 
expert-led, hands-on workshops and two days of sessions from industry 
leaders in dedicated Performance & Operations tracks. Use code vel09scf 
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hi Sascha,

I finally had some time to test your new unified SPI driver on my i.MX27 platform...
It's a good idea to have a common SPI driver for all MXs but I have two remarks:

Quoted 7 lines · Sascha Hauer

While there already is a SPI driver for i.MX1 in the tree there are good reasons to replace it:

- The inkernel driver implements a full blown SPI driver, but the hardware can be fully supported using a bitbang driver. This greatly reduces the size and complexity of the driver.

I don't know yet if it's related to bitbang but I would say that your driver is 2x slowier that current inkernel one. We (armadeus) have i.MXL and i.MX27 boards with ADC, Touchscreen and CAN bus on SPI and saw a lost of performance with your driver (when fast successive SPI transfers are needed). You probably won't notice it if you only have a Freescale's power chip or an EEPROM connected to your SPI bus.

Sorry but I didn't had time yet to investigate more :-(.

I know that I can't have the official Linux kernel suited for my particular needs (;-) ), so what would be the things to do to improve your driver performances ?

Quoted 3 lines

- The DMA API of the durrent driver is broken for arch-mx1 (as opposed to arch-imx) and nobody cared to fix it yet.

Will your driver use DMA in a near future ?

Regards,
Julien

------------------------------------------------------------------------------
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): [email protected]

#4 lore raw

Hi Julien.

Quoted 11 lines · Julien Boibessot

Hi Sascha,

I finally had some time to test your new unified SPI driver on my i.MX27 platform...
It's a good idea to have a common SPI driver for all MXs but I have two remarks:

Quoted 3 lines · Sascha Hauer

While there already is a SPI driver for i.MX1 in the tree there are good reasons to replace it:

Quoted 6 lines
Quoted 4 lines

- The inkernel driver implements a full blown SPI driver, but the hardware can be fully supported using a bitbang driver. This greatly reduces the size and complexity of the driver.

I don't know yet if it's related to bitbang but I would say that your driver is 2x slowier that current inkernel one.

Have you checked that the driver gets the baudrate correct? If it is maybe my driver produces more interrupts than the in kernel driver. Maybe you could produce a defined workload with both drivers and compare the outputs of /proc/interrupts afterwards.

Quoted 8 lines

We (armadeus) have i.MXL
and i.MX27 boards with ADC, Touchscreen and CAN bus on SPI and saw a lost of performance with your driver (when fast successive SPI transfers are needed). You probably won't notice it if you only have a Freescale's power chip or an EEPROM connected to your SPI bus.

Sorry but I didn't had time yet to investigate more :-(.

Quoted 7 lines

I know that I can't have the official Linux kernel suited for my particular needs (;-) ), so what would be the things to do to improve your driver performances ?

Quoted 3 lines

- The DMA API of the durrent driver is broken for arch-mx1 (as opposed to arch-imx) and nobody cared to fix it yet.

Will your driver use DMA in a near future ?

I haven't planned it yet, but it shouldn't be hard to implement.

Sascha

Signature · 11 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

------------------------------------------------------------------------------
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): [email protected]

#6 lore raw

Hi Sascha,

Quoted 11 lines · Sascha Hauer
Quoted 3 lines · Julien Boibessot

I don't know yet if it's related to bitbang but I would say that your driver is 2x slowier that current inkernel one.

Have you checked that the driver gets the baudrate correct? If it is maybe my driver produces more interrupts than the in kernel driver. Maybe you could produce a defined workload with both drivers and compare the outputs of /proc/interrupts afterwards.

Clock seems ok. The problem is the "setup" time between 2 transfers. We use an ADC (MAX1027) from which we try to get the data as fast as possible (successive SPI read transfers of 16 bytes) and the time between 2 transfers was quite doubled when switching to your new driver.

I will try to spend more time to check that after the summer holidays ;-).

Regards,
Julien

------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference! Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250. Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org