1 THIS CODE IS DEPRECATED.
3 Please use the new mainline SPI-GPIO driver, as of 2.6.29.
10 drivers/spi/Kconfig | 9 +
11 drivers/spi/Makefile | 1
12 drivers/spi/spi_gpio_old.c | 251 +++++++++++++++++++++++++++++++++++++++
13 include/linux/spi/spi_gpio_old.h | 73 +++++++++++
14 4 files changed, 334 insertions(+)
17 +++ b/include/linux/spi/spi_gpio_old.h
20 + * spi_gpio interface to platform code
22 + * Copyright (c) 2008 Piotr Skamruk
23 + * Copyright (c) 2008 Michael Buesch
25 + * This program is free software; you can redistribute it and/or modify
26 + * it under the terms of the GNU General Public License version 2 as
27 + * published by the Free Software Foundation.
29 +#ifndef _LINUX_SPI_SPI_GPIO
30 +#define _LINUX_SPI_SPI_GPIO
32 +#include <linux/types.h>
33 +#include <linux/spi/spi.h>
37 + * struct spi_gpio_platform_data - Data definitions for a SPI-GPIO device.
39 + * This structure holds information about a GPIO-based SPI device.
41 + * @pin_clk: The GPIO pin number of the CLOCK pin.
43 + * @pin_miso: The GPIO pin number of the MISO pin.
45 + * @pin_mosi: The GPIO pin number of the MOSI pin.
47 + * @pin_cs: The GPIO pin number of the CHIPSELECT pin.
49 + * @cs_activelow: If true, the chip is selected when the CS line is low.
51 + * @no_spi_delay: If true, no delay is done in the lowlevel bitbanging.
52 + * Note that doing no delay is not standards compliant,
53 + * but it might be needed to speed up transfers on some
54 + * slow embedded machines.
56 + * @boardinfo_setup: This callback is called after the
57 + * SPI master device was registered, but before the
58 + * device is registered.
59 + * @boardinfo_setup_data: Data argument passed to boardinfo_setup().
61 +struct spi_gpio_platform_data {
62 + unsigned int pin_clk;
63 + unsigned int pin_miso;
64 + unsigned int pin_mosi;
65 + unsigned int pin_cs;
68 + int (*boardinfo_setup)(struct spi_board_info *bi,
69 + struct spi_master *master,
71 + void *boardinfo_setup_data;
75 + * SPI_GPIO_PLATDEV_NAME - The platform device name string.
77 + * The name string that has to be used for platform_device_alloc
78 + * when allocating a spi-gpio device.
80 +#define SPI_GPIO_PLATDEV_NAME "spi-gpio"
83 + * spi_gpio_next_id - Get another platform device ID number.
85 + * This returns the next platform device ID number that has to be used
86 + * for platform_device_alloc. The ID is opaque and should not be used for
89 +int spi_gpio_next_id(void);
91 +#endif /* _LINUX_SPI_SPI_GPIO */
93 +++ b/drivers/spi/spi_gpio_old.c
96 + * Bitbanging SPI bus driver using GPIO API
98 + * Copyright (c) 2008 Piotr Skamruk
99 + * Copyright (c) 2008 Michael Buesch
101 + * based on spi_s3c2410_gpio.c
102 + * Copyright (c) 2006 Ben Dooks
103 + * Copyright (c) 2006 Simtec Electronics
104 + * and on i2c-gpio.c
105 + * Copyright (C) 2007 Atmel Corporation
107 + * This program is free software; you can redistribute it and/or modify
108 + * it under the terms of the GNU General Public License version 2 as
109 + * published by the Free Software Foundation.
112 +#include <linux/kernel.h>
113 +#include <linux/init.h>
114 +#include <linux/delay.h>
115 +#include <linux/spinlock.h>
116 +#include <linux/workqueue.h>
117 +#include <linux/module.h>
118 +#include <linux/platform_device.h>
119 +#include <linux/spi/spi.h>
120 +#include <linux/spi/spi_bitbang.h>
121 +#include <linux/spi/spi_gpio_old.h>
122 +#include <linux/gpio.h>
123 +#include <asm/atomic.h>
127 + struct spi_bitbang bitbang;
128 + struct spi_gpio_platform_data *info;
129 + struct platform_device *pdev;
130 + struct spi_board_info bi;
134 +static inline struct spi_gpio *spidev_to_sg(struct spi_device *dev)
136 + return dev->controller_data;
139 +static inline void setsck(struct spi_device *dev, int val)
141 + struct spi_gpio *sp = spidev_to_sg(dev);
142 + gpio_set_value(sp->info->pin_clk, val ? 1 : 0);
145 +static inline void setmosi(struct spi_device *dev, int val)
147 + struct spi_gpio *sp = spidev_to_sg(dev);
148 + gpio_set_value(sp->info->pin_mosi, val ? 1 : 0);
151 +static inline u32 getmiso(struct spi_device *dev)
153 + struct spi_gpio *sp = spidev_to_sg(dev);
154 + return gpio_get_value(sp->info->pin_miso) ? 1 : 0;
157 +static inline void do_spidelay(struct spi_device *dev, unsigned nsecs)
159 + struct spi_gpio *sp = spidev_to_sg(dev);
161 + if (!sp->info->no_spi_delay)
165 +#define spidelay(nsecs) do { \
166 + /* Steal the spi_device pointer from our caller. \
167 + * The bitbang-API should probably get fixed here... */ \
168 + do_spidelay(spi, nsecs); \
171 +#define EXPAND_BITBANG_TXRX
172 +#include "spi_bitbang_txrx.h"
174 +static u32 spi_gpio_txrx_mode0(struct spi_device *spi,
175 + unsigned nsecs, u32 word, u8 bits)
177 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
180 +static u32 spi_gpio_txrx_mode1(struct spi_device *spi,
181 + unsigned nsecs, u32 word, u8 bits)
183 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
186 +static u32 spi_gpio_txrx_mode2(struct spi_device *spi,
187 + unsigned nsecs, u32 word, u8 bits)
189 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
192 +static u32 spi_gpio_txrx_mode3(struct spi_device *spi,
193 + unsigned nsecs, u32 word, u8 bits)
195 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
198 +static void spi_gpio_chipselect(struct spi_device *dev, int on)
200 + struct spi_gpio *sp = spidev_to_sg(dev);
202 + if (sp->info->cs_activelow)
204 + gpio_set_value(sp->info->pin_cs, on ? 1 : 0);
207 +static int spi_gpio_probe(struct platform_device *pdev)
209 + struct spi_master *master;
210 + struct spi_gpio_platform_data *pdata;
211 + struct spi_gpio *sp;
212 + struct spi_device *spidev;
215 + pdata = pdev->dev.platform_data;
220 + master = spi_alloc_master(&pdev->dev, sizeof(struct spi_gpio));
222 + goto err_alloc_master;
224 + sp = spi_master_get_devdata(master);
225 + platform_set_drvdata(pdev, sp);
228 + err = gpio_request(pdata->pin_clk, "spi_clock");
230 + goto err_request_clk;
231 + err = gpio_request(pdata->pin_mosi, "spi_mosi");
233 + goto err_request_mosi;
234 + err = gpio_request(pdata->pin_miso, "spi_miso");
236 + goto err_request_miso;
237 + err = gpio_request(pdata->pin_cs, "spi_cs");
239 + goto err_request_cs;
241 + sp->bitbang.master = spi_master_get(master);
242 + sp->bitbang.master->bus_num = -1;
243 + sp->bitbang.master->num_chipselect = 1;
244 + sp->bitbang.chipselect = spi_gpio_chipselect;
245 + sp->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_mode0;
246 + sp->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_mode1;
247 + sp->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_mode2;
248 + sp->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_txrx_mode3;
250 + gpio_direction_output(pdata->pin_clk, 0);
251 + gpio_direction_output(pdata->pin_mosi, 0);
252 + gpio_direction_output(pdata->pin_cs,
253 + pdata->cs_activelow ? 1 : 0);
254 + gpio_direction_input(pdata->pin_miso);
256 + err = spi_bitbang_start(&sp->bitbang);
258 + goto err_no_bitbang;
259 + err = pdata->boardinfo_setup(&sp->bi, master,
260 + pdata->boardinfo_setup_data);
263 + sp->bi.controller_data = sp;
264 + spidev = spi_new_device(master, &sp->bi);
272 + spi_bitbang_stop(&sp->bitbang);
274 + spi_master_put(sp->bitbang.master);
275 + gpio_free(pdata->pin_cs);
277 + gpio_free(pdata->pin_miso);
279 + gpio_free(pdata->pin_mosi);
281 + gpio_free(pdata->pin_clk);
289 +static int __devexit spi_gpio_remove(struct platform_device *pdev)
291 + struct spi_gpio *sp;
292 + struct spi_gpio_platform_data *pdata;
294 + pdata = pdev->dev.platform_data;
295 + sp = platform_get_drvdata(pdev);
297 + gpio_free(pdata->pin_clk);
298 + gpio_free(pdata->pin_mosi);
299 + gpio_free(pdata->pin_miso);
300 + gpio_free(pdata->pin_cs);
301 + spi_bitbang_stop(&sp->bitbang);
302 + spi_master_put(sp->bitbang.master);
307 +static struct platform_driver spi_gpio_driver = {
309 + .name = SPI_GPIO_PLATDEV_NAME,
310 + .owner = THIS_MODULE,
312 + .probe = spi_gpio_probe,
313 + .remove = __devexit_p(spi_gpio_remove),
316 +int spi_gpio_next_id(void)
318 + static atomic_t counter = ATOMIC_INIT(-1);
320 + return atomic_inc_return(&counter);
322 +EXPORT_SYMBOL(spi_gpio_next_id);
324 +static int __init spi_gpio_init(void)
328 + err = platform_driver_register(&spi_gpio_driver);
330 + printk(KERN_ERR "spi-gpio: register failed: %d\n", err);
334 +module_init(spi_gpio_init);
336 +static void __exit spi_gpio_exit(void)
338 + platform_driver_unregister(&spi_gpio_driver);
340 +module_exit(spi_gpio_exit);
342 +MODULE_AUTHOR("Piot Skamruk <piotr.skamruk at gmail.com>");
343 +MODULE_AUTHOR("Michael Buesch");
344 +MODULE_DESCRIPTION("Platform independent GPIO bitbanging SPI driver");
345 +MODULE_LICENSE("GPL v2");
346 --- a/drivers/spi/Kconfig
347 +++ b/drivers/spi/Kconfig
348 @@ -169,6 +169,15 @@ config SPI_IMX_VER_0_7
349 config SPI_IMX_VER_2_3
350 def_bool y if ARCH_MX51 || ARCH_MX53
353 + tristate "Old GPIO API based bitbanging SPI controller (DEPRECATED)"
354 + depends on SPI_MASTER && GENERIC_GPIO
357 + This code is deprecated. Please use the new mainline SPI-GPIO driver.
362 tristate "Freescale i.MX SPI controllers"
364 --- a/drivers/spi/Makefile
365 +++ b/drivers/spi/Makefile
366 @@ -23,6 +23,7 @@ dw_spi_midpci-objs := dw_spi_pci.o dw_
367 obj-$(CONFIG_SPI_DW_MMIO) += dw_spi_mmio.o
368 obj-$(CONFIG_SPI_EP93XX) += ep93xx_spi.o
369 obj-$(CONFIG_SPI_GPIO) += spi_gpio.o
370 +obj-$(CONFIG_SPI_GPIO_OLD) += spi_gpio_old.o
371 obj-$(CONFIG_SPI_IMX) += spi_imx.o
372 obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o
373 obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o