Add SPI over GPIO driver
PATCH v3 1/1 Add SPI over GPIO driver
This adds a driver that lets you drive an SPI bus over generic GPIO pins.
---
This driver is used in OpenWrt since quite some time, so please consider for inclusion in mainline.
Simple spelling fixes since v2.
include/linux/spi/spi_gpio.h new file +73 -0
@@ -0,0 +1,73 @@ +/* +* spi_gpio interface to platform code +* +* Copyright (c) 2008 Piotr Skamruk +* Copyright (c) 2008 Michael Buesch +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ +#ifndef _LINUX_SPI_SPI_GPIO +#define _LINUX_SPI_SPI_GPIO + +#include <linux/types.h> +#include <linux/spi/spi.h> + + +/** +* struct spi_gpio_platform_data - Data definitions for a SPI-GPIO device. +* +* This structure holds information about a GPIO-based SPI device. +* +* @pin_clk: The GPIO pin number of the CLOCK pin. +* +* @pin_miso: The GPIO pin number of the MISO pin. +* +* @pin_mosi: The GPIO pin number of the MOSI pin. +* +* @pin_cs: The GPIO pin number of the CHIPSELECT pin. +* +* @cs_activelow: If true, the chip is selected when the CS line is low. +* +* @no_spi_delay: If true, no delay is done in the lowlevel bitbanging. +* Note that doing no delay is not standards compliant, +* but it might be needed to speed up transfers on some +* slow embedded machines. +* +* @boardinfo_setup: This callback is called after the +* SPI master device was registered, but before the +* device is registered. +* @boardinfo_setup_data: Data argument passed to boardinfo_setup(). +*/ +struct spi_gpio_platform_data { +unsigned int pin_clk; +unsigned int pin_miso; +unsigned int pin_mosi; +unsigned int pin_cs; +bool cs_activelow; +bool no_spi_delay; +int (*boardinfo_setup)(struct spi_board_info *bi, +struct spi_master *master, +void *data); +void *boardinfo_setup_data; +}; + +/** +* SPI_GPIO_PLATDEV_NAME - The platform device name string. +* +* The name string that has to be used for platform_device_alloc +* when allocating a spi-gpio device. +*/ +#define SPI_GPIO_PLATDEV_NAME "spi-gpio" + +/** +* spi_gpio_next_id - Get another platform device ID number. +* +* This returns the next platform device ID number that has to be used +* for platform_device_alloc. The ID is opaque and should not be used for +* anything else. +*/ +int spi_gpio_next_id (void ); + +#endif /* _LINUX_SPI_SPI_GPIO */
drivers/spi/spi_gpio.c new file +251 -0
251 lines not on this page · raw message
drivers/spi/Kconfig +13 -0
@@ -100,6 +100,19 @@ config SPI_BUTTERFLY inexpensive battery powered microcontroller evaluation board. This same cable can be used to flash new firmware. +config SPI_GPIO + tristate "GPIO API based bitbanging SPI controller" + depends on SPI_MASTER && GENERIC_GPIO + select SPI_BITBANG + help + This is a platform driver that can be used for bitbanging + an SPI bus over GPIO pins. + Select this if you have any SPI device that is connected via + GPIO pins. + The module will be called spi_gpio. + + If unsure, say N. + config SPI_IMX tristate "Freescale iMX SPI controller" depends on SPI_MASTER && ARCH_IMX && EXPERIMENTAL
drivers/spi/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx. 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_LM70_LLP) += spi_lm70llp.o obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o
MAINTAINERS +5 -0
@@ -3884,6 +3884,11 @@ L: [email protected] W: http://www.ibm.com/developerworks/power/cell/ S: Supported +SPI GPIO MASTER DRIVER +P: Michael Buesch +M: [email protected] +S: Maintained + STABLE BRANCH: P: Greg Kroah-Hartman M: [email protected]
Signature · 1 line
Greetings Michael.
Quoted 4 lines · Michael Buesch
This adds a driver that lets you drive an SPI bus over generic GPIO pins.
Signed-off-by Michael Buesch <[email protected]>
Very useful. Fits my shiny new GPIO implementation for SuperH like a glove.
Michael, as you know, I have some SuperH board code that makes use of this driver. Are there any outstanding issues with this driver that I can help resolving?
Andrew, is this driver still in -mm? Any chance of getting it included in 2.6.28?
Cheers,
/ magnus
Quoted 11 lines · On Friday 17 October 2008 05:14:26 Magnus Damm wrote:
Quoted 4 lines · Michael Buesch
This adds a driver that lets you drive an SPI bus over generic GPIO pins.
Signed-off-by Michael Buesch <[email protected]>Very useful. Fits my shiny new GPIO implementation for SuperH like a glove.
Michael, as you know, I have some SuperH board code that makes use of this driver. Are there any outstanding issues with this driver that I can help resolving?
bool cs_activelow should probably be removed from struct spi_gpio_platform_data.
I think cs always is activelow, so we can simply hardcode this in spi_gpio_chipselect()
If you want to do this, please feel free to do so. I currently don't have the time for this. The rest of the driver is fine with me.
Signature · 1 line
Greetings Michael.
[removed closed openwrt-devel list]
Quoted 9 lines · Michael Buesch
Quoted 8 lines · On Friday 17 October 2008 05:14:26 Magnus Damm wrote:
Quoted 4 lines · Michael Buesch
This adds a driver that lets you drive an SPI bus over generic GPIO pins.
Signed-off-by Michael Buesch <[email protected]>Very useful. Fits my shiny new GPIO implementation for SuperH like a glove.
Quoted 7 lines
Quoted 3 lines
Michael, as you know, I have some SuperH board code that makes use of this driver. Are there any outstanding issues with this driver that I can help resolving?
bool
cs_activelowshould probably be removed from structspi_gpio_platform_data.I think cs always is activelow, so we can simply hardcode this in
spi_gpio_chipselect()
Really? There _must_ be chips out there that want active high CS! I'd rather keep the activelow option or maybe turn in into activehigh instead.
Quoted 3 lines
If you want to do this, please feel free to do so. I currently don't have the time for this. The rest of the driver is fine with me.
Ok, thank you.
David or Andrew, any change of getting this merged as-is somehow? Thanks!
/ magnus
Quoted 16 lines · On Friday 17 October 2008 11:52:32 Magnus Damm wrote:
[removed closed openwrt-devel list]
Quoted 13 lines · Michael Buesch
Quoted 11 lines · On Friday 17 October 2008 05:14:26 Magnus Damm wrote:
Quoted 4 lines · Michael Buesch
This adds a driver that lets you drive an SPI bus over generic GPIO pins.
Signed-off-by Michael Buesch <[email protected]>Very useful. Fits my shiny new GPIO implementation for SuperH like a glove.
Michael, as you know, I have some SuperH board code that makes use of this driver. Are there any outstanding issues with this driver that I can help resolving?
Quoted 6 lines
Quoted 3 lines
bool
cs_activelowshould probably be removed from structspi_gpio_platform_data.I think cs always is activelow, so we can simply hardcode this in
spi_gpio_chipselect()Really? There _must_ be chips out there that want active high CS! I'd rather keep the activelow option or maybe turn in into activehigh instead.
Ok, I dunno. I never saw one. All of my SPI stuff is activelow. So well, let's keep it.
Quoted 7 lines
Quoted 3 lines
If you want to do this, please feel free to do so. I currently don't have the time for this. The rest of the driver is fine with me.
Ok, thank you.
David or Andrew, any change of getting this merged as-is somehow? Thanks!
Yes, please merge it.
Signature · 1 line
Greetings Michael.
Quoted 31 lines · On Fri, 17 Oct 2008 13:18:32 +0200 Michael Buesch <[email protected]> wrote:
Quoted 16 lines · On Friday 17 October 2008 11:52:32 Magnus Damm wrote:
[removed closed openwrt-devel list]
Quoted 13 lines · Michael Buesch
Quoted 11 lines · On Friday 17 October 2008 05:14:26 Magnus Damm wrote:
Quoted 4 lines · Michael Buesch
This adds a driver that lets you drive an SPI bus over generic GPIO pins.
Signed-off-by Michael Buesch <[email protected]>Very useful. Fits my shiny new GPIO implementation for SuperH like a glove.
Michael, as you know, I have some SuperH board code that makes use of this driver. Are there any outstanding issues with this driver that I can help resolving?
Quoted 6 lines
Quoted 3 lines
bool
cs_activelowshould probably be removed from structspi_gpio_platform_data.I think cs always is activelow, so we can simply hardcode this in
spi_gpio_chipselect()Really? There _must_ be chips out there that want active high CS! I'd rather keep the activelow option or maybe turn in into activehigh instead.
Ok, I dunno. I never saw one. All of my SPI stuff is activelow. So well, let's keep it.
Quoted 4 lines
Quoted 3 lines
If you want to do this, please feel free to do so. I currently don't have the time for this. The rest of the driver is fine with me.
Quoted 5 lines
Quoted 3 lines
Ok, thank you.
David or Andrew, any change of getting this merged as-is somehow? Thanks!
Yes, please merge it.
This patch has some "issues" a month or so ago. Current status is that I've pinged David to see if he's OK with a 2.6.28 merge and he hasn't yet replied.
Let's not bust a gut to get this into 2.6.28-rc1 - let's get it right rather than fast. If we end up deciding to merge it into, say, 2.6.28-rc2 then that should be OK under the circumstances.
From: Michael Buesch <[email protected]>
This adds a driver that lets you drive an SPI bus over generic GPIO pins.
---
MAINTAINERS | 5 drivers/spi/Kconfig | 13 + drivers/spi/Makefile | 1 drivers/spi/spi_gpio.c | 252 +++++++++++++++++++++++++++++++++ include/linux/spi/spi_gpio.h | 73 +++++++++ 5 files changed, 344 insertions(+)
MAINTAINERS renamed from MAINTAINERS~spi-add-spi-over-gpio-driver +5 -0
@@ -3911,6 +3911,11 @@ M: [email protected] L: [email protected] S: Supported +SPI GPIO MASTER DRIVER +P: Michael Buesch +M: [email protected] +S: Maintained + SPU FILE SYSTEM P: Jeremy Kerr M: [email protected]
drivers/spi/Kconfig renamed from drivers/spi/Kconfig~spi-add-spi-over-gpio-driver +13 -0
@@ -100,6 +100,19 @@ config SPI_BUTTERFLY inexpensive battery powered microcontroller evaluation board. This same cable can be used to flash new firmware. +config SPI_GPIO + tristate "GPIO API based bitbanging SPI controller" + depends on SPI_MASTER && GENERIC_GPIO + select SPI_BITBANG + help + This is a platform driver that can be used for bitbanging + an SPI bus over GPIO pins. + Select this if you have any SPI device that is connected via + GPIO pins. + The module will be called spi_gpio. + + If unsure, say N. + config SPI_IMX tristate "Freescale iMX SPI controller" depends on ARCH_IMX && EXPERIMENTAL
drivers/spi/Makefile renamed from drivers/spi/Makefile~spi-add-spi-over-gpio-driver +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx. 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_LM70_LLP) += spi_lm70llp.o obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o
drivers/spi/spi_gpio.c new file +252 -0
252 lines not on this page · raw message
include/linux/spi/spi_gpio.h new file +73 -0
73 lines not on this page · raw message
_
Quoted 1 line · On Saturday 18 October 2008 06:36:31 Andrew Morton wrote:
This patch has some "issues" a month or so ago. Current status is that
yeah, upstream maintainers don't like these patches. Please drop this one and the "gpiommc" patch now.
Signature · 1 line
Greetings Michael.
2008/10/18 Michael Buesch <[email protected]>:
Quoted 6 lines · On Saturday 18 October 2008 06:36:31 Andrew Morton wrote:
Quoted 1 line
This patch has some "issues" a month or so ago. Current status is that
yeah, upstream maintainers don't like these patches. Please drop this one and the "gpiommc" patch now.
As i remember - David stands that these patches (or even functionality) are not usable for him, so he don't want to see them in mainstream kernel sources. It's his choice, he is maintainer of this subsystem.
You have this on openwrt svn, I have it on my dev gittree - and as You can see on Magnus example - anybody interested can google for it. Maybe if there will be next few peoples - David will change his opinion on this subject...
Quoted 11 lines · Piotr Skamruk
2008/10/18 Michael Buesch <[email protected]>:
Quoted 6 lines · On Saturday 18 October 2008 06:36:31 Andrew Morton wrote:
Quoted 1 line
This patch has some "issues" a month or so ago. Current status is that
yeah, upstream maintainers don't like these patches. Please drop this one and the "gpiommc" patch now.
As i remember - David stands that these patches (or even functionality) are not usable for him, so he don't want to see them in mainstream kernel sources. It's his choice, he is maintainer of this subsystem.
That patch is very limited, and wrong in several respects.
I fully support the idea of SPI over GPIO. It's just that particular patch which is problematic.
Quoted 4 lines
You have this on openwrt svn, I have it on my dev gittree - and as You can see on Magnus example - anybody interested can google for it. Maybe if there will be next few peoples - David will change his opinion on this subject...
I'm sanity testing a refresh of the *original* late-2006 SPI-over-GPIO driver. It's actually usable as a drop-in replacement for a "native" driver.
Unfortunately I goofed and pulled down the current GIT tree and found lots of unrelated breakage (non-SPI) that's keept that sanity test from proceeding apace. And the board on which it's most recently been used is currently broken. I may just send that patch out soon, as an FYI...
- Dave
Quoted 13 lines · David Brownell
Quoted 11 lines · Piotr Skamruk
2008/10/18 Michael Buesch <[email protected]>:
Quoted 6 lines · On Saturday 18 October 2008 06:36:31 Andrew Morton wrote:
Quoted 1 line
This patch has some "issues" a month or so ago. Current status is that
yeah, upstream maintainers don't like these patches. Please drop this one and the "gpiommc" patch now.
As i remember - David stands that these patches (or even functionality) are not usable for him, so he don't want to see them in mainstream kernel sources. It's his choice, he is maintainer of this subsystem.
Quoted 4 lines
That patch is very limited, and wrong in several respects.
I fully support the idea of SPI over GPIO. It's just that particular patch which is problematic.
Ok, let's fix those issues then!
Quoted 8 lines
Quoted 4 lines
You have this on openwrt svn, I have it on my dev gittree - and as You can see on Magnus example - anybody interested can google for it. Maybe if there will be next few peoples - David will change his opinion on this subject...
I'm sanity testing a refresh of the *original* late-2006 SPI-over-GPIO driver. It's actually usable as a drop-in replacement for a "native" driver.
The Openwrt driver by Michael Buesch works just fine for me, but if you prefer to switch driver that's of course ok too.
Quoted 5 lines
Unfortunately I goofed and pulled down the current GIT tree and found lots of unrelated breakage (non-SPI) that's keept that sanity test from proceeding apace. And the board on which it's most recently been used is currently broken. I may just send that patch out soon, as an FYI...
Please CC me and I'll test it on some SuperH boards. Thanks!
/ magnus
PATCH 1/1 spi_gpio driver
From: David Brownell <[email protected]>
Generalize the old at91rm9200 "bootstrap" bitbanging SPI master driver as "spi_gpio", so it works with arbitrary GPIOs and can be configured through platform_data. Such SPI masters support:
- any number of bus instances (bus_num is the platform_device.id)
- any number of chipselects (one GPIO per spi_device)
- all four SPI_MODE values, and SPI_CS_HIGH
- i/o word sizes from 1 to 32 bits;
- devices configured as with any other spi_master controller
When configured using platform_data, this provides relatively low clock rates. On platforms that support inlined GPIO calls, significantly improved transfer speeds are also possible with a semi-custom driver. (It's still painful when accessing flash memory, but less so.)
Sanity checked by using this version to replace both native controllers on a board with six different SPI slaves, relying on three different SPI_MODE_* values and both SPI_CS_HIGH settings for correct operation.
--- drivers/spi/Kconfig | 18 +- drivers/spi/Makefile | 1 drivers/spi/spi_gpio.c | 360 +++++++++++++++++++++++++++++++++++++++++ include/linux/spi/spi_gpio.h | 60 ++++++ 4 files changed, 438 insertions(+), 1 deletion(-)
drivers/spi/Kconfig +17 -1
@@ -78,7 +78,7 @@ config SPI_AU1550 will be called au1550_spi. config SPI_BITBANG - tristate "Bitbanging SPI master" + tristate "Utilities for Bitbanging SPI masters" help With a few GPIO pins, your system can bitbang the SPI protocol. Select this to get SPI support through I/O pins (GPIO, parallel
@@ -100,6 +100,22 @@ config SPI_BUTTERFLY inexpensive battery powered microcontroller evaluation board. This same cable can be used to flash new firmware. +config SPI_GPIO + tristate "GPIO-based bitbanging SPI Master" + depends on GENERIC_GPIO + select SPI_BITBANG + help + This simple GPIO bitbanging SPI master uses the arch-neutral GPIO + interface to manage MOSI, MISO, SCK, and chipselect signals. SPI + slaves connected to a bus using this driver are configured as usual, + except that the spi_board_info.controller_data holds the GPIO number + for the chipselect used by this controller driver. + + Note that this driver often won't achieve even 1 Mbit/sec speeds, + making it unusually slow for SPI. If your platform can inline + 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_IMX tristate "Freescale iMX SPI controller" depends on ARCH_IMX && EXPERIMENTAL
drivers/spi/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx. 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_LM70_LLP) += spi_lm70llp.o obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o
drivers/spi/spi_gpio.c new file +360 -0
360 lines not on this page · raw message
include/linux/spi/spi_gpio.h new file +60 -0
60 lines not on this page · raw message
Re: [spi-devel-general] [patch 2.6.27-git] spi_gpio driver
Quoted 11 lines · David Brownell
From: David Brownell <[email protected]>
Generalize the old at91rm9200 "bootstrap" bitbanging SPI master driver as "
spi_gpio", so it works with arbitrary GPIOs and can be configured throughplatform_data. Such SPI masters support:- any number of bus instances (
bus_numis the platform_device.id)
- any number of chipselects (one GPIO perspi_device)
- all fourSPI_MODEvalues, andSPI_CS_HIGH
- i/o word sizes from 1 to 32 bits;
- devices configured as with any otherspi_mastercontroller
Probably worth looking at removing the s3c24xx gpio specific driver and replacing it with this.
Signature · 4 lines
Ben Q: What's a light-year? A: One-third less calories than a regular year.
Re: [spi-devel-general] [patch 2.6.27-git] spi_gpio driver
Quoted 7 lines · Ben Dooks
Quoted 6 lines · David Brownell
From: David Brownell <[email protected]>
Generalize the old at91rm9200 "bootstrap" bitbanging SPI master driver as "
spi_gpio", so it works with arbitrary GPIOs and can be configured throughplatform_data. Such SPI masters support:
Quoted 8 lines
Quoted 5 lines
- any number of bus instances (
bus_numis the platform_device.id)
- any number of chipselects (one GPIO perspi_device)
- all fourSPI_MODEvalues, andSPI_CS_HIGH
- i/o word sizes from 1 to 32 bits;
- devices configured as with any otherspi_mastercontrollerProbably worth looking at removing the s3c24xx gpio specific driver and replacing it with this.
Good point. Let me know if you see any issues doing that, beyond the need to change some boards' setup code and defconfigs first.
- Dave
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Re: [patch 2.6.27-git] spi_gpio driver
In reply to David BrownellQuoted 17 lines · David Brownell
From: David Brownell <[email protected]>
Generalize the old at91rm9200 "bootstrap" bitbanging SPI master driver as "
spi_gpio", so it works with arbitrary GPIOs and can be configured throughplatform_data. Such SPI masters support:- any number of bus instances (
bus_numis the platform_device.id)
- any number of chipselects (one GPIO perspi_device)
- all fourSPI_MODEvalues, andSPI_CS_HIGH
- i/o word sizes from 1 to 32 bits;
- devices configured as with any otherspi_mastercontrollerWhen configured using
platform_data, this provides relatively low clock rates. On platforms that support inlined GPIO calls, significantly improved transfer speeds are also possible with a semi-custom driver. (It's still painful when accessing flash memory, but less so.)
Quoted 5 lines
Sanity checked by using this version to replace both native controllers on a board with six different SPI slaves, relying on three different SPI_MODE_* values and both
SPI_CS_HIGHsettings for correct operation.Signed-off-by David Brownell <[email protected]>
Works fine on SuperH together with the mmc_spi driver. Thanks!
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Quoted 5 lines · Magnus Damm
Quoted 3 lines
I fully support the idea of SPI over GPIO. It's just that particular patch which is problematic.
Ok, let's fix those issues then!
The issues I identified earlier still haven't been resolved... one of several reasons IMO to just use a different driver.
Quoted 7 lines
Quoted 3 lines
I'm sanity testing a refresh of the *original* late-2006 SPI-over-GPIO driver. It's actually usable as a drop-in replacement for a "native" driver.
The Openwrt driver by Michael Buesch works just fine for me, but if you prefer to switch driver that's of course ok too.
Quoted 7 lines
Quoted 5 lines
Unfortunately I goofed and pulled down the current GIT tree and found lots of unrelated breakage (non-SPI) that's keept that sanity test from proceeding apace. And the board on which it's most recently been used is currently broken. I may just send that patch out soon, as an FYI...
Please CC me and I'll test it on some SuperH boards. Thanks!
Patch follows in a separate message, with trimmed CC list.
- Dave
Quoted 8 lines · On Monday 20 October 2008 06:16:51 David Brownell wrote:
Quoted 5 lines · Magnus Damm
Quoted 3 lines
I fully support the idea of SPI over GPIO. It's just that particular patch which is problematic.
Ok, let's fix those issues then!
The issues I identified earlier still haven't been resolved...
What the hell are you talking about?
I rewrote it several times.
Signature · 1 line
Greetings Michael.