Deprecate the old SPI-GPIO driver.
[openwrt/staging/florian.git] / target / linux / generic-2.6 / patches-2.6.28 / 921-gpio_spi_driver.patch
1 THIS CODE IS DEPRECATED.
2
3 Please use the new mainline SPI-GPIO driver, as of 2.6.29.
4
5 --mb
6
7
8
9 Index: linux-2.6.28.2/include/linux/spi/spi_gpio_old.h
10 ===================================================================
11 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
12 +++ linux-2.6.28.2/include/linux/spi/spi_gpio_old.h 2009-02-10 17:14:33.000000000 +0100
13 @@ -0,0 +1,73 @@
14 +/*
15 + * spi_gpio interface to platform code
16 + *
17 + * Copyright (c) 2008 Piotr Skamruk
18 + * Copyright (c) 2008 Michael Buesch
19 + *
20 + * This program is free software; you can redistribute it and/or modify
21 + * it under the terms of the GNU General Public License version 2 as
22 + * published by the Free Software Foundation.
23 + */
24 +#ifndef _LINUX_SPI_SPI_GPIO
25 +#define _LINUX_SPI_SPI_GPIO
26 +
27 +#include <linux/types.h>
28 +#include <linux/spi/spi.h>
29 +
30 +
31 +/**
32 + * struct spi_gpio_platform_data - Data definitions for a SPI-GPIO device.
33 + *
34 + * This structure holds information about a GPIO-based SPI device.
35 + *
36 + * @pin_clk: The GPIO pin number of the CLOCK pin.
37 + *
38 + * @pin_miso: The GPIO pin number of the MISO pin.
39 + *
40 + * @pin_mosi: The GPIO pin number of the MOSI pin.
41 + *
42 + * @pin_cs: The GPIO pin number of the CHIPSELECT pin.
43 + *
44 + * @cs_activelow: If true, the chip is selected when the CS line is low.
45 + *
46 + * @no_spi_delay: If true, no delay is done in the lowlevel bitbanging.
47 + * Note that doing no delay is not standards compliant,
48 + * but it might be needed to speed up transfers on some
49 + * slow embedded machines.
50 + *
51 + * @boardinfo_setup: This callback is called after the
52 + * SPI master device was registered, but before the
53 + * device is registered.
54 + * @boardinfo_setup_data: Data argument passed to boardinfo_setup().
55 + */
56 +struct spi_gpio_platform_data {
57 + unsigned int pin_clk;
58 + unsigned int pin_miso;
59 + unsigned int pin_mosi;
60 + unsigned int pin_cs;
61 + bool cs_activelow;
62 + bool no_spi_delay;
63 + int (*boardinfo_setup)(struct spi_board_info *bi,
64 + struct spi_master *master,
65 + void *data);
66 + void *boardinfo_setup_data;
67 +};
68 +
69 +/**
70 + * SPI_GPIO_PLATDEV_NAME - The platform device name string.
71 + *
72 + * The name string that has to be used for platform_device_alloc
73 + * when allocating a spi-gpio device.
74 + */
75 +#define SPI_GPIO_PLATDEV_NAME "spi-gpio"
76 +
77 +/**
78 + * spi_gpio_next_id - Get another platform device ID number.
79 + *
80 + * This returns the next platform device ID number that has to be used
81 + * for platform_device_alloc. The ID is opaque and should not be used for
82 + * anything else.
83 + */
84 +int spi_gpio_next_id(void);
85 +
86 +#endif /* _LINUX_SPI_SPI_GPIO */
87 Index: linux-2.6.28.2/drivers/spi/spi_gpio_old.c
88 ===================================================================
89 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
90 +++ linux-2.6.28.2/drivers/spi/spi_gpio_old.c 2009-02-10 17:15:01.000000000 +0100
91 @@ -0,0 +1,251 @@
92 +/*
93 + * Bitbanging SPI bus driver using GPIO API
94 + *
95 + * Copyright (c) 2008 Piotr Skamruk
96 + * Copyright (c) 2008 Michael Buesch
97 + *
98 + * based on spi_s3c2410_gpio.c
99 + * Copyright (c) 2006 Ben Dooks
100 + * Copyright (c) 2006 Simtec Electronics
101 + * and on i2c-gpio.c
102 + * Copyright (C) 2007 Atmel Corporation
103 + *
104 + * This program is free software; you can redistribute it and/or modify
105 + * it under the terms of the GNU General Public License version 2 as
106 + * published by the Free Software Foundation.
107 + */
108 +
109 +#include <linux/kernel.h>
110 +#include <linux/init.h>
111 +#include <linux/delay.h>
112 +#include <linux/spinlock.h>
113 +#include <linux/workqueue.h>
114 +#include <linux/module.h>
115 +#include <linux/platform_device.h>
116 +#include <linux/spi/spi.h>
117 +#include <linux/spi/spi_bitbang.h>
118 +#include <linux/spi/spi_gpio_old.h>
119 +#include <linux/gpio.h>
120 +#include <asm/atomic.h>
121 +
122 +
123 +struct spi_gpio {
124 + struct spi_bitbang bitbang;
125 + struct spi_gpio_platform_data *info;
126 + struct platform_device *pdev;
127 + struct spi_board_info bi;
128 +};
129 +
130 +
131 +static inline struct spi_gpio *spidev_to_sg(struct spi_device *dev)
132 +{
133 + return dev->controller_data;
134 +}
135 +
136 +static inline void setsck(struct spi_device *dev, int val)
137 +{
138 + struct spi_gpio *sp = spidev_to_sg(dev);
139 + gpio_set_value(sp->info->pin_clk, val ? 1 : 0);
140 +}
141 +
142 +static inline void setmosi(struct spi_device *dev, int val)
143 +{
144 + struct spi_gpio *sp = spidev_to_sg(dev);
145 + gpio_set_value(sp->info->pin_mosi, val ? 1 : 0);
146 +}
147 +
148 +static inline u32 getmiso(struct spi_device *dev)
149 +{
150 + struct spi_gpio *sp = spidev_to_sg(dev);
151 + return gpio_get_value(sp->info->pin_miso) ? 1 : 0;
152 +}
153 +
154 +static inline void do_spidelay(struct spi_device *dev, unsigned nsecs)
155 +{
156 + struct spi_gpio *sp = spidev_to_sg(dev);
157 +
158 + if (!sp->info->no_spi_delay)
159 + ndelay(nsecs);
160 +}
161 +
162 +#define spidelay(nsecs) do { \
163 + /* Steal the spi_device pointer from our caller. \
164 + * The bitbang-API should probably get fixed here... */ \
165 + do_spidelay(spi, nsecs); \
166 + } while (0)
167 +
168 +#define EXPAND_BITBANG_TXRX
169 +#include <linux/spi/spi_bitbang.h>
170 +
171 +static u32 spi_gpio_txrx_mode0(struct spi_device *spi,
172 + unsigned nsecs, u32 word, u8 bits)
173 +{
174 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
175 +}
176 +
177 +static u32 spi_gpio_txrx_mode1(struct spi_device *spi,
178 + unsigned nsecs, u32 word, u8 bits)
179 +{
180 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
181 +}
182 +
183 +static u32 spi_gpio_txrx_mode2(struct spi_device *spi,
184 + unsigned nsecs, u32 word, u8 bits)
185 +{
186 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
187 +}
188 +
189 +static u32 spi_gpio_txrx_mode3(struct spi_device *spi,
190 + unsigned nsecs, u32 word, u8 bits)
191 +{
192 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
193 +}
194 +
195 +static void spi_gpio_chipselect(struct spi_device *dev, int on)
196 +{
197 + struct spi_gpio *sp = spidev_to_sg(dev);
198 +
199 + if (sp->info->cs_activelow)
200 + on = !on;
201 + gpio_set_value(sp->info->pin_cs, on ? 1 : 0);
202 +}
203 +
204 +static int spi_gpio_probe(struct platform_device *pdev)
205 +{
206 + struct spi_master *master;
207 + struct spi_gpio_platform_data *pdata;
208 + struct spi_gpio *sp;
209 + struct spi_device *spidev;
210 + int err;
211 +
212 + pdata = pdev->dev.platform_data;
213 + if (!pdata)
214 + return -ENXIO;
215 +
216 + err = -ENOMEM;
217 + master = spi_alloc_master(&pdev->dev, sizeof(struct spi_gpio));
218 + if (!master)
219 + goto err_alloc_master;
220 +
221 + sp = spi_master_get_devdata(master);
222 + platform_set_drvdata(pdev, sp);
223 + sp->info = pdata;
224 +
225 + err = gpio_request(pdata->pin_clk, "spi_clock");
226 + if (err)
227 + goto err_request_clk;
228 + err = gpio_request(pdata->pin_mosi, "spi_mosi");
229 + if (err)
230 + goto err_request_mosi;
231 + err = gpio_request(pdata->pin_miso, "spi_miso");
232 + if (err)
233 + goto err_request_miso;
234 + err = gpio_request(pdata->pin_cs, "spi_cs");
235 + if (err)
236 + goto err_request_cs;
237 +
238 + sp->bitbang.master = spi_master_get(master);
239 + sp->bitbang.master->bus_num = -1;
240 + sp->bitbang.master->num_chipselect = 1;
241 + sp->bitbang.chipselect = spi_gpio_chipselect;
242 + sp->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_mode0;
243 + sp->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_mode1;
244 + sp->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_mode2;
245 + sp->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_txrx_mode3;
246 +
247 + gpio_direction_output(pdata->pin_clk, 0);
248 + gpio_direction_output(pdata->pin_mosi, 0);
249 + gpio_direction_output(pdata->pin_cs,
250 + pdata->cs_activelow ? 1 : 0);
251 + gpio_direction_input(pdata->pin_miso);
252 +
253 + err = spi_bitbang_start(&sp->bitbang);
254 + if (err)
255 + goto err_no_bitbang;
256 + err = pdata->boardinfo_setup(&sp->bi, master,
257 + pdata->boardinfo_setup_data);
258 + if (err)
259 + goto err_bi_setup;
260 + sp->bi.controller_data = sp;
261 + spidev = spi_new_device(master, &sp->bi);
262 + if (!spidev)
263 + goto err_new_dev;
264 +
265 + return 0;
266 +
267 +err_new_dev:
268 +err_bi_setup:
269 + spi_bitbang_stop(&sp->bitbang);
270 +err_no_bitbang:
271 + spi_master_put(sp->bitbang.master);
272 + gpio_free(pdata->pin_cs);
273 +err_request_cs:
274 + gpio_free(pdata->pin_miso);
275 +err_request_miso:
276 + gpio_free(pdata->pin_mosi);
277 +err_request_mosi:
278 + gpio_free(pdata->pin_clk);
279 +err_request_clk:
280 + kfree(master);
281 +
282 +err_alloc_master:
283 + return err;
284 +}
285 +
286 +static int __devexit spi_gpio_remove(struct platform_device *pdev)
287 +{
288 + struct spi_gpio *sp;
289 + struct spi_gpio_platform_data *pdata;
290 +
291 + pdata = pdev->dev.platform_data;
292 + sp = platform_get_drvdata(pdev);
293 +
294 + gpio_free(pdata->pin_clk);
295 + gpio_free(pdata->pin_mosi);
296 + gpio_free(pdata->pin_miso);
297 + gpio_free(pdata->pin_cs);
298 + spi_bitbang_stop(&sp->bitbang);
299 + spi_master_put(sp->bitbang.master);
300 +
301 + return 0;
302 +}
303 +
304 +static struct platform_driver spi_gpio_driver = {
305 + .driver = {
306 + .name = SPI_GPIO_PLATDEV_NAME,
307 + .owner = THIS_MODULE,
308 + },
309 + .probe = spi_gpio_probe,
310 + .remove = __devexit_p(spi_gpio_remove),
311 +};
312 +
313 +int spi_gpio_next_id(void)
314 +{
315 + static atomic_t counter = ATOMIC_INIT(-1);
316 +
317 + return atomic_inc_return(&counter);
318 +}
319 +EXPORT_SYMBOL(spi_gpio_next_id);
320 +
321 +static int __init spi_gpio_init(void)
322 +{
323 + int err;
324 +
325 + err = platform_driver_register(&spi_gpio_driver);
326 + if (err)
327 + printk(KERN_ERR "spi-gpio: register failed: %d\n", err);
328 +
329 + return err;
330 +}
331 +module_init(spi_gpio_init);
332 +
333 +static void __exit spi_gpio_exit(void)
334 +{
335 + platform_driver_unregister(&spi_gpio_driver);
336 +}
337 +module_exit(spi_gpio_exit);
338 +
339 +MODULE_AUTHOR("Piot Skamruk <piotr.skamruk at gmail.com>");
340 +MODULE_AUTHOR("Michael Buesch");
341 +MODULE_DESCRIPTION("Platform independent GPIO bitbanging SPI driver");
342 +MODULE_LICENSE("GPL v2");
343 Index: linux-2.6.28.2/drivers/spi/Kconfig
344 ===================================================================
345 --- linux-2.6.28.2.orig/drivers/spi/Kconfig 2009-02-10 17:13:57.000000000 +0100
346 +++ linux-2.6.28.2/drivers/spi/Kconfig 2009-02-10 17:14:33.000000000 +0100
347 @@ -100,6 +100,15 @@ config SPI_BUTTERFLY
348 inexpensive battery powered microcontroller evaluation board.
349 This same cable can be used to flash new firmware.
350
351 +config SPI_GPIO_OLD
352 + tristate "Old GPIO API based bitbanging SPI controller (DEPRECATED)"
353 + depends on SPI_MASTER && GENERIC_GPIO
354 + select SPI_BITBANG
355 + help
356 + This code is deprecated. Please use the new mainline SPI-GPIO driver.
357 +
358 + If unsure, say N.
359 +
360 config SPI_IMX
361 tristate "Freescale iMX SPI controller"
362 depends on ARCH_IMX && EXPERIMENTAL
363 Index: linux-2.6.28.2/drivers/spi/Makefile
364 ===================================================================
365 --- linux-2.6.28.2.orig/drivers/spi/Makefile 2009-02-10 17:13:57.000000000 +0100
366 +++ linux-2.6.28.2/drivers/spi/Makefile 2009-02-10 17:14:33.000000000 +0100
367 @@ -16,6 +16,7 @@ obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx.
368 obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o
369 obj-$(CONFIG_SPI_AU1550) += au1550_spi.o
370 obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o
371 +obj-$(CONFIG_SPI_GPIO_OLD) += spi_gpio_old.o
372 obj-$(CONFIG_SPI_IMX) += spi_imx.o
373 obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o
374 obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o