Add SPI over GPIO driver
PATCH v2 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.
include/linux/spi/spi_gpio.h new file +67 -0
@@ -0,0 +1,67 @@ +/* +* 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
@@ -3857,6 +3857,11 @@ M: [email protected] L: [email protected] S: Maintained +SPI GPIO MASTER DRIVER +P: Michael Buesch +M: [email protected] +S: Maintained + SPU FILE SYSTEM P: Jeremy Kerr M: [email protected]
Signature · 1 line
Greetings Michael.
Quoted 9 lines · On Fri, 18 Jul 2008 21:59:03 +0200 Michael Buesch wrote:
This adds a driver that lets you drive an SPI bus over generic GPIO pins.
Signed-off-by Michael Buesch <[email protected]>---
This driver is used in OpenWrt since quite some time, so please consider for inclusion in mainline.
diffstat here, please.
Quoted 14 lines
Index:
linux-next/include/linux/spi/spi_gpio.h
===================================================================include/linux/spi/spi_gpio.h new file +9
-0@@ -0,0 +1,67 @@ +/* +* 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.
include/linux/spi/spi_gpio.h line 19
Quoted 10 lines
include/linux/spi/spi_gpio.h new file +10
-0+*/ +#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.
kernel-doc blocks begin with /** on a line by itself. E.g.:
/**
* struct spi_gpio_platform_data - blah
Quoted 55 lines
include/linux/spi/spi_gpio.h new file +48
-0+* +* @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 */ Index: linux-next/drivers/spi/Kconfig
===================================================================drivers/spi/Kconfig +0
-0@@ -100,6 +100,19 @@ config SPI_BUTTERFLY inexpensive battery powered microcontroller evaluation board.
drivers/spi/Kconfig config SPI_BUTTERFLY · line 110
Quoted 10 lines
drivers/spi/Kconfig +8
-0This 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
No comma.
drivers/spi/Kconfig config SPI_BUTTERFLY · line 118
Quoted 8 lines
drivers/spi/Kconfig +5
-0+ 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
---
~Randy
Linux Plumbers Conference, 17-19 September 2008, Portland, Oregon USA
http://linuxplumbersconf.org/