1 THIS CODE IS DEPRECATED.
3 Please use the new mainline SPI-GPIO driver, as of 2.6.29.
10 +++ b/include/linux/spi/spi_gpio_old.h
13 + * spi_gpio interface to platform code
15 + * Copyright (c) 2008 Piotr Skamruk
16 + * Copyright (c) 2008 Michael Buesch
18 + * This program is free software; you can redistribute it and/or modify
19 + * it under the terms of the GNU General Public License version 2 as
20 + * published by the Free Software Foundation.
22 +#ifndef _LINUX_SPI_SPI_GPIO
23 +#define _LINUX_SPI_SPI_GPIO
25 +#include <linux/types.h>
26 +#include <linux/spi/spi.h>
30 + * struct spi_gpio_platform_data - Data definitions for a SPI-GPIO device.
32 + * This structure holds information about a GPIO-based SPI device.
34 + * @pin_clk: The GPIO pin number of the CLOCK pin.
36 + * @pin_miso: The GPIO pin number of the MISO pin.
38 + * @pin_mosi: The GPIO pin number of the MOSI pin.
40 + * @pin_cs: The GPIO pin number of the CHIPSELECT pin.
42 + * @cs_activelow: If true, the chip is selected when the CS line is low.
44 + * @no_spi_delay: If true, no delay is done in the lowlevel bitbanging.
45 + * Note that doing no delay is not standards compliant,
46 + * but it might be needed to speed up transfers on some
47 + * slow embedded machines.
49 + * @boardinfo_setup: This callback is called after the
50 + * SPI master device was registered, but before the
51 + * device is registered.
52 + * @boardinfo_setup_data: Data argument passed to boardinfo_setup().
54 +struct spi_gpio_platform_data {
55 + unsigned int pin_clk;
56 + unsigned int pin_miso;
57 + unsigned int pin_mosi;
58 + unsigned int pin_cs;
61 + int (*boardinfo_setup)(struct spi_board_info *bi,
62 + struct spi_master *master,
64 + void *boardinfo_setup_data;
68 + * SPI_GPIO_PLATDEV_NAME - The platform device name string.
70 + * The name string that has to be used for platform_device_alloc
71 + * when allocating a spi-gpio device.
73 +#define SPI_GPIO_PLATDEV_NAME "spi-gpio"
76 + * spi_gpio_next_id - Get another platform device ID number.
78 + * This returns the next platform device ID number that has to be used
79 + * for platform_device_alloc. The ID is opaque and should not be used for
82 +int spi_gpio_next_id(void);
84 +#endif /* _LINUX_SPI_SPI_GPIO */
86 +++ b/drivers/spi/spi_gpio_old.c
89 + * Bitbanging SPI bus driver using GPIO API
91 + * Copyright (c) 2008 Piotr Skamruk
92 + * Copyright (c) 2008 Michael Buesch
94 + * based on spi_s3c2410_gpio.c
95 + * Copyright (c) 2006 Ben Dooks
96 + * Copyright (c) 2006 Simtec Electronics
98 + * Copyright (C) 2007 Atmel Corporation
100 + * This program is free software; you can redistribute it and/or modify
101 + * it under the terms of the GNU General Public License version 2 as
102 + * published by the Free Software Foundation.
105 +#include <linux/kernel.h>
106 +#include <linux/init.h>
107 +#include <linux/delay.h>
108 +#include <linux/spinlock.h>
109 +#include <linux/workqueue.h>
110 +#include <linux/module.h>
111 +#include <linux/platform_device.h>
112 +#include <linux/spi/spi.h>
113 +#include <linux/spi/spi_bitbang.h>
114 +#include <linux/spi/spi_gpio_old.h>
115 +#include <linux/gpio.h>
116 +#include <asm/atomic.h>
120 + struct spi_bitbang bitbang;
121 + struct spi_gpio_platform_data *info;
122 + struct platform_device *pdev;
123 + struct spi_board_info bi;
127 +static inline struct spi_gpio *spidev_to_sg(struct spi_device *dev)
129 + return dev->controller_data;
132 +static inline void setsck(struct spi_device *dev, int val)
134 + struct spi_gpio *sp = spidev_to_sg(dev);
135 + gpio_set_value(sp->info->pin_clk, val ? 1 : 0);
138 +static inline void setmosi(struct spi_device *dev, int val)
140 + struct spi_gpio *sp = spidev_to_sg(dev);
141 + gpio_set_value(sp->info->pin_mosi, val ? 1 : 0);
144 +static inline u32 getmiso(struct spi_device *dev)
146 + struct spi_gpio *sp = spidev_to_sg(dev);
147 + return gpio_get_value(sp->info->pin_miso) ? 1 : 0;
150 +static inline void do_spidelay(struct spi_device *dev, unsigned nsecs)
152 + struct spi_gpio *sp = spidev_to_sg(dev);
154 + if (!sp->info->no_spi_delay)
158 +#define spidelay(nsecs) do { \
159 + /* Steal the spi_device pointer from our caller. \
160 + * The bitbang-API should probably get fixed here... */ \
161 + do_spidelay(spi, nsecs); \
164 +#define EXPAND_BITBANG_TXRX
165 +#include <linux/spi/spi_bitbang.h>
167 +static u32 spi_gpio_txrx_mode0(struct spi_device *spi,
168 + unsigned nsecs, u32 word, u8 bits)
170 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
173 +static u32 spi_gpio_txrx_mode1(struct spi_device *spi,
174 + unsigned nsecs, u32 word, u8 bits)
176 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
179 +static u32 spi_gpio_txrx_mode2(struct spi_device *spi,
180 + unsigned nsecs, u32 word, u8 bits)
182 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
185 +static u32 spi_gpio_txrx_mode3(struct spi_device *spi,
186 + unsigned nsecs, u32 word, u8 bits)
188 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
191 +static void spi_gpio_chipselect(struct spi_device *dev, int on)
193 + struct spi_gpio *sp = spidev_to_sg(dev);
195 + if (sp->info->cs_activelow)
197 + gpio_set_value(sp->info->pin_cs, on ? 1 : 0);
200 +static int spi_gpio_probe(struct platform_device *pdev)
202 + struct spi_master *master;
203 + struct spi_gpio_platform_data *pdata;
204 + struct spi_gpio *sp;
205 + struct spi_device *spidev;
208 + pdata = pdev->dev.platform_data;
213 + master = spi_alloc_master(&pdev->dev, sizeof(struct spi_gpio));
215 + goto err_alloc_master;
217 + sp = spi_master_get_devdata(master);
218 + platform_set_drvdata(pdev, sp);
221 + err = gpio_request(pdata->pin_clk, "spi_clock");
223 + goto err_request_clk;
224 + err = gpio_request(pdata->pin_mosi, "spi_mosi");
226 + goto err_request_mosi;
227 + err = gpio_request(pdata->pin_miso, "spi_miso");
229 + goto err_request_miso;
230 + err = gpio_request(pdata->pin_cs, "spi_cs");
232 + goto err_request_cs;
234 + sp->bitbang.master = spi_master_get(master);
235 + sp->bitbang.master->bus_num = -1;
236 + sp->bitbang.master->num_chipselect = 1;
237 + sp->bitbang.chipselect = spi_gpio_chipselect;
238 + sp->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_mode0;
239 + sp->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_mode1;
240 + sp->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_mode2;
241 + sp->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_txrx_mode3;
243 + gpio_direction_output(pdata->pin_clk, 0);
244 + gpio_direction_output(pdata->pin_mosi, 0);
245 + gpio_direction_output(pdata->pin_cs,
246 + pdata->cs_activelow ? 1 : 0);
247 + gpio_direction_input(pdata->pin_miso);
249 + err = spi_bitbang_start(&sp->bitbang);
251 + goto err_no_bitbang;
252 + err = pdata->boardinfo_setup(&sp->bi, master,
253 + pdata->boardinfo_setup_data);
256 + sp->bi.controller_data = sp;
257 + spidev = spi_new_device(master, &sp->bi);
265 + spi_bitbang_stop(&sp->bitbang);
267 + spi_master_put(sp->bitbang.master);
268 + gpio_free(pdata->pin_cs);
270 + gpio_free(pdata->pin_miso);
272 + gpio_free(pdata->pin_mosi);
274 + gpio_free(pdata->pin_clk);
282 +static int __devexit spi_gpio_remove(struct platform_device *pdev)
284 + struct spi_gpio *sp;
285 + struct spi_gpio_platform_data *pdata;
287 + pdata = pdev->dev.platform_data;
288 + sp = platform_get_drvdata(pdev);
290 + gpio_free(pdata->pin_clk);
291 + gpio_free(pdata->pin_mosi);
292 + gpio_free(pdata->pin_miso);
293 + gpio_free(pdata->pin_cs);
294 + spi_bitbang_stop(&sp->bitbang);
295 + spi_master_put(sp->bitbang.master);
300 +static struct platform_driver spi_gpio_driver = {
302 + .name = SPI_GPIO_PLATDEV_NAME,
303 + .owner = THIS_MODULE,
305 + .probe = spi_gpio_probe,
306 + .remove = __devexit_p(spi_gpio_remove),
309 +int spi_gpio_next_id(void)
311 + static atomic_t counter = ATOMIC_INIT(-1);
313 + return atomic_inc_return(&counter);
315 +EXPORT_SYMBOL(spi_gpio_next_id);
317 +static int __init spi_gpio_init(void)
321 + err = platform_driver_register(&spi_gpio_driver);
323 + printk(KERN_ERR "spi-gpio: register failed: %d\n", err);
327 +module_init(spi_gpio_init);
329 +static void __exit spi_gpio_exit(void)
331 + platform_driver_unregister(&spi_gpio_driver);
333 +module_exit(spi_gpio_exit);
335 +MODULE_AUTHOR("Piot Skamruk <piotr.skamruk at gmail.com>");
336 +MODULE_AUTHOR("Michael Buesch");
337 +MODULE_DESCRIPTION("Platform independent GPIO bitbanging SPI driver");
338 +MODULE_LICENSE("GPL v2");
339 --- a/drivers/spi/Kconfig
340 +++ b/drivers/spi/Kconfig
341 @@ -116,6 +116,15 @@ config SPI_GPIO
342 GPIO operations, you should be able to leverage that for better
343 speed with a custom version of this driver; see the source code.
346 + tristate "Old GPIO API based bitbanging SPI controller (DEPRECATED)"
347 + depends on SPI_MASTER && GENERIC_GPIO
350 + This code is deprecated. Please use the new mainline SPI-GPIO driver.
355 tristate "Freescale i.MX SPI controllers"
357 --- a/drivers/spi/Makefile
358 +++ b/drivers/spi/Makefile
359 @@ -17,6 +17,7 @@ obj-$(CONFIG_SPI_BITBANG) += spi_bitban
360 obj-$(CONFIG_SPI_AU1550) += au1550_spi.o
361 obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o
362 obj-$(CONFIG_SPI_GPIO) += spi_gpio.o
363 +obj-$(CONFIG_SPI_GPIO_OLD) += spi_gpio_old.o
364 obj-$(CONFIG_SPI_IMX) += spi_imx.o
365 obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o
366 obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o