1 diff -ruN linux-2.6.26.orig/Documentation/gpiommc.txt linux-2.6.26/Documentation/gpiommc.txt
2 --- linux-2.6.26.orig/Documentation/gpiommc.txt 2008-10-24 21:04:46.000000000 +0200
3 +++ linux-2.6.26/Documentation/gpiommc.txt 1970-01-01 01:00:00.000000000 +0100
5 -GPIOMMC - Driver for an MMC/SD card on a bitbanging GPIO SPI bus
6 -================================================================
8 -The gpiommc module hooks up the mmc_spi and spi_gpio modules for running an
9 -MMC or SD card on GPIO pins.
11 -Two interfaces for registering a new MMC/SD card device are provided:
12 -A static platform-device based mechanism and a dynamic configfs based interface.
15 -Registering devices via platform-device
16 -=======================================
18 -The platform-device interface is used for registering MMC/SD devices that are
19 -part of the hardware platform. This is most useful only for embedded machines
20 -with MMC/SD devices statically connected to the platform GPIO bus.
22 -The data structures are declared in <linux/mmc/gpiommc.h>.
24 -To register a new device, define an instance of struct gpiommc_platform_data.
25 -This structure holds any information about how the device is hooked up to the
26 -GPIO pins and what hardware modes the device supports. See the docbook-style
27 -documentation in the header file for more information on the struct fields.
29 -Then allocate a new instance of a platform device by doing:
31 - pdev = platform_device_alloc(GPIOMMC_PLATDEV_NAME, gpiommc_next_id());
33 -This will allocate the platform device data structures and hook it up to the
35 -Then add the gpiommc_platform_data to the platform device.
37 - err = platform_device_add_data(pdev, pdata, sizeof(struct gpiommc_platform_data));
39 -You may free the local instance of struct gpiommc_platform_data now. (So the
40 -struct may be allocated on the stack, too).
41 -Now simply register the platform device.
43 - err = platform_device_add(pdev);
45 -Done. The gpiommc probe routine will be invoked now and you should see a kernel
46 -log message for the added device.
49 -Registering devices via configfs
50 -================================
52 -MMC/SD cards connected via GPIO often are a pretty dynamic thing, as for example
53 -selfmade hacks for soldering an MMC/SD card to standard GPIO pins on embedded
54 -hardware are a common situation.
55 -So we provide a dynamic interface to conveniently handle adding and removing
56 -devices from userspace, without the need to recompile the kernel.
58 -The "gpiommc" subdirectory at the configfs mountpoint is used for handling
59 -the dynamic configuration.
61 -To create a new device, it must first be allocated with mkdir.
62 -The following command will allocate a device named "my_mmc":
63 - mkdir /config/gpiommc/my_mmc
65 -There are several configuration files available in the new
66 -/config/gpiommc/my_mmc/ directory:
68 -gpio_data_in = The SPI data-IN GPIO pin number.
69 -gpio_data_out = The SPI data-OUT GPIO pin number.
70 -gpio_clock = The SPI Clock GPIO pin number.
71 -gpio_chipselect = The SPI Chipselect GPIO pin number.
72 -gpio_chipselect_activelow = Boolean. If 0, Chipselect is active-HIGH.
73 - If 1, Chipselect is active-LOW.
74 -spi_mode = The SPI data mode. Can be 0-3.
75 -spi_delay = Enable all delays in the lowlevel bitbanging.
76 -max_bus_speed = The maximum SPI bus speed. In Hertz.
78 -register = Not a configuration parameter.
79 - Used to register the configured card
82 -The device must first get configured and then registered by writing "1" to
84 -The configuration parameters "gpio_data_in", "gpio_data_out", "gpio_clock"
85 -and "gpio_chipselect" are essential and _must_ be configured before writing
86 -"1" to the "register" file. The registration will fail, otherwise.
88 -The default values for the other parameters are:
89 -gpio_chipselect_activelow = 1 (CS active-LOW)
90 -spi_mode = 0 (SPI_MODE_0)
91 -spi_delay = 1 (enabled)
92 -max_bus_speed = 5000000 (5 Mhz)
94 -Configuration values can not be changed after registration. To unregister
95 -the device, write a "0" to the "register" file. The configuration can be
96 -changed again after unregistering.
98 -To completely remove the device, simply rmdir the directory
99 -(/config/gpiommc/my_mmc in this example).
100 -There's no need to first unregister the device before removing it. That will
101 -be done automatically.
102 diff -ruN linux-2.6.26.orig/drivers/mmc/host/gpiommc.c linux-2.6.26/drivers/mmc/host/gpiommc.c
103 --- linux-2.6.26.orig/drivers/mmc/host/gpiommc.c 2008-10-24 21:04:46.000000000 +0200
104 +++ linux-2.6.26/drivers/mmc/host/gpiommc.c 1970-01-01 01:00:00.000000000 +0100
107 - * Driver an MMC/SD card on a bitbanging GPIO SPI bus.
108 - * This module hooks up the mmc_spi and spi_gpio modules and also
109 - * provides a configfs interface.
111 - * Copyright 2008 Michael Buesch <mb@bu3sch.de>
113 - * Licensed under the GNU/GPL. See COPYING for details.
116 -#include <linux/mmc/gpiommc.h>
117 -#include <linux/platform_device.h>
118 -#include <linux/list.h>
119 -#include <linux/mutex.h>
120 -#include <linux/spi/spi_gpio.h>
121 -#include <linux/configfs.h>
122 -#include <linux/gpio.h>
123 -#include <asm/atomic.h>
126 -#define PFX "gpio-mmc: "
129 -struct gpiommc_device {
130 - struct platform_device *pdev;
131 - struct platform_device *spi_pdev;
132 - struct spi_board_info boardinfo;
136 -MODULE_DESCRIPTION("GPIO based MMC driver");
137 -MODULE_AUTHOR("Michael Buesch");
138 -MODULE_LICENSE("GPL");
141 -static int gpiommc_boardinfo_setup(struct spi_board_info *bi,
142 - struct spi_master *master,
145 - struct gpiommc_device *d = data;
146 - struct gpiommc_platform_data *pdata = d->pdev->dev.platform_data;
148 - /* Bind the SPI master to the MMC-SPI host driver. */
149 - strlcpy(bi->modalias, "mmc_spi", sizeof(bi->modalias));
151 - bi->max_speed_hz = pdata->max_bus_speed;
152 - bi->bus_num = master->bus_num;
153 - bi->mode = pdata->mode;
158 -static int gpiommc_probe(struct platform_device *pdev)
160 - struct gpiommc_platform_data *mmc_pdata = pdev->dev.platform_data;
161 - struct spi_gpio_platform_data spi_pdata;
162 - struct gpiommc_device *d;
169 -#ifdef CONFIG_MMC_SPI_MODULE
170 - err = request_module("mmc_spi");
172 - printk(KERN_WARNING PFX
173 - "Failed to request mmc_spi module.\n");
175 -#endif /* CONFIG_MMC_SPI_MODULE */
177 - /* Allocate the GPIO-MMC device */
179 - d = kzalloc(sizeof(*d), GFP_KERNEL);
184 - /* Create the SPI-GPIO device */
185 - d->spi_pdev = platform_device_alloc(SPI_GPIO_PLATDEV_NAME,
186 - spi_gpio_next_id());
190 - memset(&spi_pdata, 0, sizeof(spi_pdata));
191 - spi_pdata.pin_clk = mmc_pdata->pins.gpio_clk;
192 - spi_pdata.pin_miso = mmc_pdata->pins.gpio_do;
193 - spi_pdata.pin_mosi = mmc_pdata->pins.gpio_di;
194 - spi_pdata.pin_cs = mmc_pdata->pins.gpio_cs;
195 - spi_pdata.cs_activelow = mmc_pdata->pins.cs_activelow;
196 - spi_pdata.no_spi_delay = mmc_pdata->no_spi_delay;
197 - spi_pdata.boardinfo_setup = gpiommc_boardinfo_setup;
198 - spi_pdata.boardinfo_setup_data = d;
200 - err = platform_device_add_data(d->spi_pdev, &spi_pdata,
201 - sizeof(spi_pdata));
203 - goto err_free_pdev;
204 - err = platform_device_add(d->spi_pdev);
206 - goto err_free_pdata;
207 - platform_set_drvdata(pdev, d);
209 - printk(KERN_INFO PFX "MMC-Card \"%s\" "
210 - "attached to GPIO pins di=%u, do=%u, clk=%u, cs=%u\n",
211 - mmc_pdata->name, mmc_pdata->pins.gpio_di,
212 - mmc_pdata->pins.gpio_do,
213 - mmc_pdata->pins.gpio_clk,
214 - mmc_pdata->pins.gpio_cs);
219 - kfree(d->spi_pdev->dev.platform_data);
220 - d->spi_pdev->dev.platform_data = NULL;
222 - platform_device_put(d->spi_pdev);
229 -static int gpiommc_remove(struct platform_device *pdev)
231 - struct gpiommc_device *d = platform_get_drvdata(pdev);
232 - struct gpiommc_platform_data *pdata = d->pdev->dev.platform_data;
234 - platform_device_unregister(d->spi_pdev);
235 - printk(KERN_INFO PFX "GPIO based MMC-Card \"%s\" removed\n",
237 - platform_device_put(d->spi_pdev);
242 -#ifdef CONFIG_GPIOMMC_CONFIGFS
244 -/* A device that was created through configfs */
245 -struct gpiommc_configfs_device {
246 - struct config_item item;
247 - /* The platform device, after registration. */
248 - struct platform_device *pdev;
249 - /* The configuration */
250 - struct gpiommc_platform_data pdata;
251 - /* Mutex to protect this structure */
252 - struct mutex mutex;
255 -#define GPIO_INVALID -1
257 -static inline bool gpiommc_is_registered(struct gpiommc_configfs_device *dev)
259 - return (dev->pdev != NULL);
262 -static inline struct gpiommc_configfs_device *ci_to_gpiommc(struct config_item *item)
264 - return item ? container_of(item, struct gpiommc_configfs_device, item) : NULL;
267 -static struct configfs_attribute gpiommc_attr_DI = {
268 - .ca_owner = THIS_MODULE,
269 - .ca_name = "gpio_data_in",
270 - .ca_mode = S_IRUGO | S_IWUSR,
273 -static struct configfs_attribute gpiommc_attr_DO = {
274 - .ca_owner = THIS_MODULE,
275 - .ca_name = "gpio_data_out",
276 - .ca_mode = S_IRUGO | S_IWUSR,
279 -static struct configfs_attribute gpiommc_attr_CLK = {
280 - .ca_owner = THIS_MODULE,
281 - .ca_name = "gpio_clock",
282 - .ca_mode = S_IRUGO | S_IWUSR,
285 -static struct configfs_attribute gpiommc_attr_CS = {
286 - .ca_owner = THIS_MODULE,
287 - .ca_name = "gpio_chipselect",
288 - .ca_mode = S_IRUGO | S_IWUSR,
291 -static struct configfs_attribute gpiommc_attr_CS_activelow = {
292 - .ca_owner = THIS_MODULE,
293 - .ca_name = "gpio_chipselect_activelow",
294 - .ca_mode = S_IRUGO | S_IWUSR,
297 -static struct configfs_attribute gpiommc_attr_spimode = {
298 - .ca_owner = THIS_MODULE,
299 - .ca_name = "spi_mode",
300 - .ca_mode = S_IRUGO | S_IWUSR,
303 -static struct configfs_attribute gpiommc_attr_spidelay = {
304 - .ca_owner = THIS_MODULE,
305 - .ca_name = "spi_delay",
306 - .ca_mode = S_IRUGO | S_IWUSR,
309 -static struct configfs_attribute gpiommc_attr_max_bus_speed = {
310 - .ca_owner = THIS_MODULE,
311 - .ca_name = "max_bus_speed",
312 - .ca_mode = S_IRUGO | S_IWUSR,
315 -static struct configfs_attribute gpiommc_attr_register = {
316 - .ca_owner = THIS_MODULE,
317 - .ca_name = "register",
318 - .ca_mode = S_IRUGO | S_IWUSR,
321 -static struct configfs_attribute *gpiommc_config_attrs[] = {
326 - &gpiommc_attr_CS_activelow,
327 - &gpiommc_attr_spimode,
328 - &gpiommc_attr_spidelay,
329 - &gpiommc_attr_max_bus_speed,
330 - &gpiommc_attr_register,
334 -static ssize_t gpiommc_config_attr_show(struct config_item *item,
335 - struct configfs_attribute *attr,
338 - struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
343 - mutex_lock(&dev->mutex);
345 - if (attr == &gpiommc_attr_DI) {
346 - gpio = dev->pdata.pins.gpio_di;
347 - if (gpio == GPIO_INVALID)
348 - count = snprintf(page, PAGE_SIZE, "not configured\n");
350 - count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
353 - if (attr == &gpiommc_attr_DO) {
354 - gpio = dev->pdata.pins.gpio_do;
355 - if (gpio == GPIO_INVALID)
356 - count = snprintf(page, PAGE_SIZE, "not configured\n");
358 - count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
361 - if (attr == &gpiommc_attr_CLK) {
362 - gpio = dev->pdata.pins.gpio_clk;
363 - if (gpio == GPIO_INVALID)
364 - count = snprintf(page, PAGE_SIZE, "not configured\n");
366 - count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
369 - if (attr == &gpiommc_attr_CS) {
370 - gpio = dev->pdata.pins.gpio_cs;
371 - if (gpio == GPIO_INVALID)
372 - count = snprintf(page, PAGE_SIZE, "not configured\n");
374 - count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
377 - if (attr == &gpiommc_attr_CS_activelow) {
378 - count = snprintf(page, PAGE_SIZE, "%u\n",
379 - dev->pdata.pins.cs_activelow);
382 - if (attr == &gpiommc_attr_spimode) {
383 - count = snprintf(page, PAGE_SIZE, "%u\n",
387 - if (attr == &gpiommc_attr_spidelay) {
388 - count = snprintf(page, PAGE_SIZE, "%u\n",
389 - !dev->pdata.no_spi_delay);
392 - if (attr == &gpiommc_attr_max_bus_speed) {
393 - count = snprintf(page, PAGE_SIZE, "%u\n",
394 - dev->pdata.max_bus_speed);
397 - if (attr == &gpiommc_attr_register) {
398 - count = snprintf(page, PAGE_SIZE, "%u\n",
399 - gpiommc_is_registered(dev));
405 - mutex_unlock(&dev->mutex);
407 - return err ? err : count;
410 -static int gpiommc_do_register(struct gpiommc_configfs_device *dev,
415 - if (gpiommc_is_registered(dev))
418 - if (!gpio_is_valid(dev->pdata.pins.gpio_di) ||
419 - !gpio_is_valid(dev->pdata.pins.gpio_do) ||
420 - !gpio_is_valid(dev->pdata.pins.gpio_clk) ||
421 - !gpio_is_valid(dev->pdata.pins.gpio_cs)) {
422 - printk(KERN_ERR PFX
423 - "configfs: Invalid GPIO pin number(s)\n");
427 - strlcpy(dev->pdata.name, name,
428 - sizeof(dev->pdata.name));
430 - dev->pdev = platform_device_alloc(GPIOMMC_PLATDEV_NAME,
431 - gpiommc_next_id());
434 - err = platform_device_add_data(dev->pdev, &dev->pdata,
435 - sizeof(dev->pdata));
437 - platform_device_put(dev->pdev);
440 - err = platform_device_add(dev->pdev);
442 - platform_device_put(dev->pdev);
449 -static void gpiommc_do_unregister(struct gpiommc_configfs_device *dev)
451 - if (!gpiommc_is_registered(dev))
454 - platform_device_unregister(dev->pdev);
458 -static ssize_t gpiommc_config_attr_store(struct config_item *item,
459 - struct configfs_attribute *attr,
460 - const char *page, size_t count)
462 - struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
464 - unsigned long data;
466 - mutex_lock(&dev->mutex);
468 - if (attr == &gpiommc_attr_register) {
469 - err = strict_strtoul(page, 10, &data);
474 - err = gpiommc_do_register(dev, item->ci_name);
476 - gpiommc_do_unregister(dev);
482 - if (gpiommc_is_registered(dev)) {
483 - /* The rest of the config parameters can only be set
484 - * as long as the device is not registered, yet. */
489 - if (attr == &gpiommc_attr_DI) {
490 - err = strict_strtoul(page, 10, &data);
494 - if (!gpio_is_valid(data))
496 - dev->pdata.pins.gpio_di = data;
500 - if (attr == &gpiommc_attr_DO) {
501 - err = strict_strtoul(page, 10, &data);
505 - if (!gpio_is_valid(data))
507 - dev->pdata.pins.gpio_do = data;
511 - if (attr == &gpiommc_attr_CLK) {
512 - err = strict_strtoul(page, 10, &data);
516 - if (!gpio_is_valid(data))
518 - dev->pdata.pins.gpio_clk = data;
522 - if (attr == &gpiommc_attr_CS) {
523 - err = strict_strtoul(page, 10, &data);
527 - if (!gpio_is_valid(data))
529 - dev->pdata.pins.gpio_cs = data;
533 - if (attr == &gpiommc_attr_CS_activelow) {
534 - err = strict_strtoul(page, 10, &data);
538 - if (data != 0 && data != 1)
540 - dev->pdata.pins.cs_activelow = data;
544 - if (attr == &gpiommc_attr_spimode) {
545 - err = strict_strtoul(page, 10, &data);
551 - dev->pdata.mode = SPI_MODE_0;
554 - dev->pdata.mode = SPI_MODE_1;
557 - dev->pdata.mode = SPI_MODE_2;
560 - dev->pdata.mode = SPI_MODE_3;
568 - if (attr == &gpiommc_attr_spidelay) {
569 - err = strict_strtoul(page, 10, &data);
573 - if (data != 0 && data != 1)
575 - dev->pdata.no_spi_delay = !data;
579 - if (attr == &gpiommc_attr_max_bus_speed) {
580 - err = strict_strtoul(page, 10, &data);
584 - if (data > UINT_MAX)
586 - dev->pdata.max_bus_speed = data;
593 - mutex_unlock(&dev->mutex);
595 - return err ? err : count;
598 -static void gpiommc_config_item_release(struct config_item *item)
600 - struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
605 -static struct configfs_item_operations gpiommc_config_item_ops = {
606 - .release = gpiommc_config_item_release,
607 - .show_attribute = gpiommc_config_attr_show,
608 - .store_attribute = gpiommc_config_attr_store,
611 -static struct config_item_type gpiommc_dev_ci_type = {
612 - .ct_item_ops = &gpiommc_config_item_ops,
613 - .ct_attrs = gpiommc_config_attrs,
614 - .ct_owner = THIS_MODULE,
617 -static struct config_item *gpiommc_make_item(struct config_group *group,
620 - struct gpiommc_configfs_device *dev;
622 - if (strlen(name) > GPIOMMC_MAX_NAMELEN) {
623 - printk(KERN_ERR PFX "configfs: device name too long\n");
627 - dev = kzalloc(sizeof(*dev), GFP_KERNEL);
631 - mutex_init(&dev->mutex);
632 - config_item_init_type_name(&dev->item, name,
633 - &gpiommc_dev_ci_type);
635 - /* Assign default configuration */
636 - dev->pdata.pins.gpio_di = GPIO_INVALID;
637 - dev->pdata.pins.gpio_do = GPIO_INVALID;
638 - dev->pdata.pins.gpio_clk = GPIO_INVALID;
639 - dev->pdata.pins.gpio_cs = GPIO_INVALID;
640 - dev->pdata.pins.cs_activelow = 1;
641 - dev->pdata.mode = SPI_MODE_0;
642 - dev->pdata.no_spi_delay = 0;
643 - dev->pdata.max_bus_speed = 5000000; /* 5 MHz */
645 - return &(dev->item);
648 -static void gpiommc_drop_item(struct config_group *group,
649 - struct config_item *item)
651 - struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
653 - gpiommc_do_unregister(dev);
657 -static struct configfs_group_operations gpiommc_ct_group_ops = {
658 - .make_item = gpiommc_make_item,
659 - .drop_item = gpiommc_drop_item,
662 -static struct config_item_type gpiommc_ci_type = {
663 - .ct_group_ops = &gpiommc_ct_group_ops,
664 - .ct_owner = THIS_MODULE,
667 -static struct configfs_subsystem gpiommc_subsys = {
670 - .ci_namebuf = GPIOMMC_PLATDEV_NAME,
671 - .ci_type = &gpiommc_ci_type,
674 - .su_mutex = __MUTEX_INITIALIZER(gpiommc_subsys.su_mutex),
677 -#endif /* CONFIG_GPIOMMC_CONFIGFS */
679 -static struct platform_driver gpiommc_plat_driver = {
680 - .probe = gpiommc_probe,
681 - .remove = gpiommc_remove,
683 - .name = GPIOMMC_PLATDEV_NAME,
684 - .owner = THIS_MODULE,
688 -int gpiommc_next_id(void)
690 - static atomic_t counter = ATOMIC_INIT(-1);
692 - return atomic_inc_return(&counter);
694 -EXPORT_SYMBOL(gpiommc_next_id);
696 -static int __init gpiommc_modinit(void)
700 - err = platform_driver_register(&gpiommc_plat_driver);
704 -#ifdef CONFIG_GPIOMMC_CONFIGFS
705 - config_group_init(&gpiommc_subsys.su_group);
706 - err = configfs_register_subsystem(&gpiommc_subsys);
708 - platform_driver_unregister(&gpiommc_plat_driver);
711 -#endif /* CONFIG_GPIOMMC_CONFIGFS */
715 -module_init(gpiommc_modinit);
717 -static void __exit gpiommc_modexit(void)
719 -#ifdef CONFIG_GPIOMMC_CONFIGFS
720 - configfs_unregister_subsystem(&gpiommc_subsys);
722 - platform_driver_unregister(&gpiommc_plat_driver);
724 -module_exit(gpiommc_modexit);
725 diff -ruN linux-2.6.26.orig/drivers/mmc/host/Kconfig linux-2.6.26/drivers/mmc/host/Kconfig
726 --- linux-2.6.26.orig/drivers/mmc/host/Kconfig 2008-10-24 21:04:46.000000000 +0200
727 +++ linux-2.6.26/drivers/mmc/host/Kconfig 2008-10-24 21:03:47.000000000 +0200
730 If unsure, or if your system has no SPI master driver, say N.
733 - tristate "MMC/SD over GPIO-based SPI"
734 - depends on MMC && MMC_SPI && SPI_GPIO
736 - This driver hooks up the mmc_spi and spi_gpio modules so that
737 - MMC/SD cards can be used on a GPIO based bus by bitbanging
738 - the SPI protocol in software.
740 - This driver provides a configfs interface to dynamically create
741 - and destroy GPIO-based MMC/SD card devices. It also provides
742 - a platform device interface API.
743 - See Documentation/gpiommc.txt for details.
745 - The module will be called gpiommc.
749 -config GPIOMMC_CONFIGFS
751 - depends on GPIOMMC && CONFIGFS_FS
754 - This option automatically enables configfs support for gpiommc
755 - if configfs is available.
756 diff -ruN linux-2.6.26.orig/drivers/mmc/host/Makefile linux-2.6.26/drivers/mmc/host/Makefile
757 --- linux-2.6.26.orig/drivers/mmc/host/Makefile 2008-10-24 21:04:46.000000000 +0200
758 +++ linux-2.6.26/drivers/mmc/host/Makefile 2008-10-24 21:03:47.000000000 +0200
760 obj-$(CONFIG_MMC_AT91) += at91_mci.o
761 obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
762 obj-$(CONFIG_MMC_SPI) += mmc_spi.o
763 -obj-$(CONFIG_GPIOMMC) += gpiommc.o
765 diff -ruN linux-2.6.26.orig/drivers/spi/Kconfig linux-2.6.26/drivers/spi/Kconfig
766 --- linux-2.6.26.orig/drivers/spi/Kconfig 2008-10-24 21:04:46.000000000 +0200
767 +++ linux-2.6.26/drivers/spi/Kconfig 2008-10-24 21:03:47.000000000 +0200
769 inexpensive battery powered microcontroller evaluation board.
770 This same cable can be used to flash new firmware.
773 - tristate "GPIO API based bitbanging SPI controller"
774 - depends on SPI_MASTER && GENERIC_GPIO
777 - This is a platform driver that can be used for bitbanging
778 - an SPI bus over GPIO pins.
779 - Select this if you have any SPI device that is connected via
781 - The module will be called spi_gpio.
786 tristate "Freescale iMX SPI controller"
787 depends on SPI_MASTER && ARCH_IMX && EXPERIMENTAL
788 diff -ruN linux-2.6.26.orig/drivers/spi/Makefile linux-2.6.26/drivers/spi/Makefile
789 --- linux-2.6.26.orig/drivers/spi/Makefile 2008-10-24 21:04:46.000000000 +0200
790 +++ linux-2.6.26/drivers/spi/Makefile 2008-10-24 21:03:47.000000000 +0200
792 obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o
793 obj-$(CONFIG_SPI_AU1550) += au1550_spi.o
794 obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o
795 -obj-$(CONFIG_SPI_GPIO) += spi_gpio.o
796 obj-$(CONFIG_SPI_IMX) += spi_imx.o
797 obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o
798 obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o
799 diff -ruN linux-2.6.26.orig/drivers/spi/spi_gpio.c linux-2.6.26/drivers/spi/spi_gpio.c
800 --- linux-2.6.26.orig/drivers/spi/spi_gpio.c 2008-10-24 21:04:46.000000000 +0200
801 +++ linux-2.6.26/drivers/spi/spi_gpio.c 1970-01-01 01:00:00.000000000 +0100
804 - * Bitbanging SPI bus driver using GPIO API
806 - * Copyright (c) 2008 Piotr Skamruk
807 - * Copyright (c) 2008 Michael Buesch
809 - * based on spi_s3c2410_gpio.c
810 - * Copyright (c) 2006 Ben Dooks
811 - * Copyright (c) 2006 Simtec Electronics
812 - * and on i2c-gpio.c
813 - * Copyright (C) 2007 Atmel Corporation
815 - * This program is free software; you can redistribute it and/or modify
816 - * it under the terms of the GNU General Public License version 2 as
817 - * published by the Free Software Foundation.
820 -#include <linux/kernel.h>
821 -#include <linux/init.h>
822 -#include <linux/delay.h>
823 -#include <linux/spinlock.h>
824 -#include <linux/workqueue.h>
825 -#include <linux/module.h>
826 -#include <linux/platform_device.h>
827 -#include <linux/spi/spi.h>
828 -#include <linux/spi/spi_bitbang.h>
829 -#include <linux/spi/spi_gpio.h>
830 -#include <linux/gpio.h>
831 -#include <asm/atomic.h>
835 - struct spi_bitbang bitbang;
836 - struct spi_gpio_platform_data *info;
837 - struct platform_device *pdev;
838 - struct spi_board_info bi;
842 -static inline struct spi_gpio *spidev_to_sg(struct spi_device *dev)
844 - return dev->controller_data;
847 -static inline void setsck(struct spi_device *dev, int val)
849 - struct spi_gpio *sp = spidev_to_sg(dev);
850 - gpio_set_value(sp->info->pin_clk, val ? 1 : 0);
853 -static inline void setmosi(struct spi_device *dev, int val)
855 - struct spi_gpio *sp = spidev_to_sg(dev);
856 - gpio_set_value(sp->info->pin_mosi, val ? 1 : 0);
859 -static inline u32 getmiso(struct spi_device *dev)
861 - struct spi_gpio *sp = spidev_to_sg(dev);
862 - return gpio_get_value(sp->info->pin_miso) ? 1 : 0;
865 -static inline void do_spidelay(struct spi_device *dev, unsigned nsecs)
867 - struct spi_gpio *sp = spidev_to_sg(dev);
869 - if (!sp->info->no_spi_delay)
873 -#define spidelay(nsecs) do { \
874 - /* Steal the spi_device pointer from our caller. \
875 - * The bitbang-API should probably get fixed here... */ \
876 - do_spidelay(spi, nsecs); \
879 -#define EXPAND_BITBANG_TXRX
880 -#include <linux/spi/spi_bitbang.h>
882 -static u32 spi_gpio_txrx_mode0(struct spi_device *spi,
883 - unsigned nsecs, u32 word, u8 bits)
885 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
888 -static u32 spi_gpio_txrx_mode1(struct spi_device *spi,
889 - unsigned nsecs, u32 word, u8 bits)
891 - return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
894 -static u32 spi_gpio_txrx_mode2(struct spi_device *spi,
895 - unsigned nsecs, u32 word, u8 bits)
897 - return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
900 -static u32 spi_gpio_txrx_mode3(struct spi_device *spi,
901 - unsigned nsecs, u32 word, u8 bits)
903 - return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
906 -static void spi_gpio_chipselect(struct spi_device *dev, int on)
908 - struct spi_gpio *sp = spidev_to_sg(dev);
910 - if (sp->info->cs_activelow)
912 - gpio_set_value(sp->info->pin_cs, on ? 1 : 0);
915 -static int spi_gpio_probe(struct platform_device *pdev)
917 - struct spi_master *master;
918 - struct spi_gpio_platform_data *pdata;
919 - struct spi_gpio *sp;
920 - struct spi_device *spidev;
923 - pdata = pdev->dev.platform_data;
928 - master = spi_alloc_master(&pdev->dev, sizeof(struct spi_gpio));
930 - goto err_alloc_master;
932 - sp = spi_master_get_devdata(master);
933 - platform_set_drvdata(pdev, sp);
936 - err = gpio_request(pdata->pin_clk, "spi_clock");
938 - goto err_request_clk;
939 - err = gpio_request(pdata->pin_mosi, "spi_mosi");
941 - goto err_request_mosi;
942 - err = gpio_request(pdata->pin_miso, "spi_miso");
944 - goto err_request_miso;
945 - err = gpio_request(pdata->pin_cs, "spi_cs");
947 - goto err_request_cs;
949 - sp->bitbang.master = spi_master_get(master);
950 - sp->bitbang.master->bus_num = -1;
951 - sp->bitbang.master->num_chipselect = 1;
952 - sp->bitbang.chipselect = spi_gpio_chipselect;
953 - sp->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_mode0;
954 - sp->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_mode1;
955 - sp->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_mode2;
956 - sp->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_txrx_mode3;
958 - gpio_direction_output(pdata->pin_clk, 0);
959 - gpio_direction_output(pdata->pin_mosi, 0);
960 - gpio_direction_output(pdata->pin_cs,
961 - pdata->cs_activelow ? 1 : 0);
962 - gpio_direction_input(pdata->pin_miso);
964 - err = spi_bitbang_start(&sp->bitbang);
966 - goto err_no_bitbang;
967 - err = pdata->boardinfo_setup(&sp->bi, master,
968 - pdata->boardinfo_setup_data);
971 - sp->bi.controller_data = sp;
972 - spidev = spi_new_device(master, &sp->bi);
980 - spi_bitbang_stop(&sp->bitbang);
982 - spi_master_put(sp->bitbang.master);
983 - gpio_free(pdata->pin_cs);
985 - gpio_free(pdata->pin_miso);
987 - gpio_free(pdata->pin_mosi);
989 - gpio_free(pdata->pin_clk);
997 -static int __devexit spi_gpio_remove(struct platform_device *pdev)
999 - struct spi_gpio *sp;
1000 - struct spi_gpio_platform_data *pdata;
1002 - pdata = pdev->dev.platform_data;
1003 - sp = platform_get_drvdata(pdev);
1005 - gpio_free(pdata->pin_clk);
1006 - gpio_free(pdata->pin_mosi);
1007 - gpio_free(pdata->pin_miso);
1008 - gpio_free(pdata->pin_cs);
1009 - spi_bitbang_stop(&sp->bitbang);
1010 - spi_master_put(sp->bitbang.master);
1015 -static struct platform_driver spi_gpio_driver = {
1017 - .name = SPI_GPIO_PLATDEV_NAME,
1018 - .owner = THIS_MODULE,
1020 - .probe = spi_gpio_probe,
1021 - .remove = __devexit_p(spi_gpio_remove),
1024 -int spi_gpio_next_id(void)
1026 - static atomic_t counter = ATOMIC_INIT(-1);
1028 - return atomic_inc_return(&counter);
1030 -EXPORT_SYMBOL(spi_gpio_next_id);
1032 -static int __init spi_gpio_init(void)
1036 - err = platform_driver_register(&spi_gpio_driver);
1038 - printk(KERN_ERR "spi-gpio: register failed: %d\n", err);
1042 -module_init(spi_gpio_init);
1044 -static void __exit spi_gpio_exit(void)
1046 - platform_driver_unregister(&spi_gpio_driver);
1048 -module_exit(spi_gpio_exit);
1050 -MODULE_AUTHOR("Piot Skamruk <piotr.skamruk at gmail.com>");
1051 -MODULE_AUTHOR("Michael Buesch");
1052 -MODULE_DESCRIPTION("Platform independent GPIO bitbanging SPI driver");
1053 -MODULE_LICENSE("GPL v2");
1054 diff -ruN linux-2.6.26.orig/include/linux/mmc/gpiommc.h linux-2.6.26/include/linux/mmc/gpiommc.h
1055 --- linux-2.6.26.orig/include/linux/mmc/gpiommc.h 2008-10-24 21:04:46.000000000 +0200
1056 +++ linux-2.6.26/include/linux/mmc/gpiommc.h 1970-01-01 01:00:00.000000000 +0100
1059 - * Device driver for MMC/SD cards driven over a GPIO bus.
1061 - * Copyright (c) 2008 Michael Buesch
1063 - * Licensed under the GNU/GPL version 2.
1065 -#ifndef LINUX_GPIOMMC_H_
1066 -#define LINUX_GPIOMMC_H_
1068 -#include <linux/types.h>
1071 -#define GPIOMMC_MAX_NAMELEN 15
1072 -#define GPIOMMC_MAX_NAMELEN_STR __stringify(GPIOMMC_MAX_NAMELEN)
1075 - * struct gpiommc_pins - Hardware pin assignments
1077 - * @gpio_di: The GPIO number of the DATA IN pin
1078 - * @gpio_do: The GPIO number of the DATA OUT pin
1079 - * @gpio_clk: The GPIO number of the CLOCK pin
1080 - * @gpio_cs: The GPIO number of the CHIPSELECT pin
1081 - * @cs_activelow: If true, the chip is considered selected if @gpio_cs is low.
1083 -struct gpiommc_pins {
1084 - unsigned int gpio_di;
1085 - unsigned int gpio_do;
1086 - unsigned int gpio_clk;
1087 - unsigned int gpio_cs;
1088 - bool cs_activelow;
1092 - * struct gpiommc_platform_data - Platform data for a MMC-over-SPI-GPIO device.
1094 - * @name: The unique name string of the device.
1095 - * @pins: The hardware pin assignments.
1096 - * @mode: The hardware mode. This is either SPI_MODE_0,
1097 - * SPI_MODE_1, SPI_MODE_2 or SPI_MODE_3. See the SPI documentation.
1098 - * @no_spi_delay: Do not use delays in the lowlevel SPI bitbanging code.
1099 - * This is not standards compliant, but may be required for some
1100 - * embedded machines to gain reasonable speed.
1101 - * @max_bus_speed: The maximum speed of the SPI bus, in Hertz.
1103 -struct gpiommc_platform_data {
1104 - char name[GPIOMMC_MAX_NAMELEN + 1];
1105 - struct gpiommc_pins pins;
1107 - bool no_spi_delay;
1108 - unsigned int max_bus_speed;
1112 - * GPIOMMC_PLATDEV_NAME - The platform device name string.
1114 - * The name string that has to be used for platform_device_alloc
1115 - * when allocating a gpiommc device.
1117 -#define GPIOMMC_PLATDEV_NAME "gpiommc"
1120 - * gpiommc_next_id - Get another platform device ID number.
1122 - * This returns the next platform device ID number that has to be used
1123 - * for platform_device_alloc. The ID is opaque and should not be used for
1126 -int gpiommc_next_id(void);
1128 -#endif /* LINUX_GPIOMMC_H_ */
1129 diff -ruN linux-2.6.26.orig/include/linux/spi/spi_gpio.h linux-2.6.26/include/linux/spi/spi_gpio.h
1130 --- linux-2.6.26.orig/include/linux/spi/spi_gpio.h 2008-10-24 21:04:46.000000000 +0200
1131 +++ linux-2.6.26/include/linux/spi/spi_gpio.h 1970-01-01 01:00:00.000000000 +0100
1134 - * spi_gpio interface to platform code
1136 - * Copyright (c) 2008 Piotr Skamruk
1137 - * Copyright (c) 2008 Michael Buesch
1139 - * This program is free software; you can redistribute it and/or modify
1140 - * it under the terms of the GNU General Public License version 2 as
1141 - * published by the Free Software Foundation.
1143 -#ifndef _LINUX_SPI_SPI_GPIO
1144 -#define _LINUX_SPI_SPI_GPIO
1146 -#include <linux/types.h>
1147 -#include <linux/spi/spi.h>
1151 - * struct spi_gpio_platform_data - Data definitions for a SPI-GPIO device.
1153 - * This structure holds information about a GPIO-based SPI device.
1155 - * @pin_clk: The GPIO pin number of the CLOCK pin.
1157 - * @pin_miso: The GPIO pin number of the MISO pin.
1159 - * @pin_mosi: The GPIO pin number of the MOSI pin.
1161 - * @pin_cs: The GPIO pin number of the CHIPSELECT pin.
1163 - * @cs_activelow: If true, the chip is selected when the CS line is low.
1165 - * @no_spi_delay: If true, no delay is done in the lowlevel bitbanging.
1166 - * Note that doing no delay is not standards compliant,
1167 - * but it might be needed to speed up transfers on some
1168 - * slow embedded machines.
1170 - * @boardinfo_setup: This callback is called after the
1171 - * SPI master device was registered, but before the
1172 - * device is registered.
1173 - * @boardinfo_setup_data: Data argument passed to boardinfo_setup().
1175 -struct spi_gpio_platform_data {
1176 - unsigned int pin_clk;
1177 - unsigned int pin_miso;
1178 - unsigned int pin_mosi;
1179 - unsigned int pin_cs;
1180 - bool cs_activelow;
1181 - bool no_spi_delay;
1182 - int (*boardinfo_setup)(struct spi_board_info *bi,
1183 - struct spi_master *master,
1185 - void *boardinfo_setup_data;
1189 - * SPI_GPIO_PLATDEV_NAME - The platform device name string.
1191 - * The name string that has to be used for platform_device_alloc
1192 - * when allocating a spi-gpio device.
1194 -#define SPI_GPIO_PLATDEV_NAME "spi-gpio"
1197 - * spi_gpio_next_id - Get another platform device ID number.
1199 - * This returns the next platform device ID number that has to be used
1200 - * for platform_device_alloc. The ID is opaque and should not be used for
1203 -int spi_gpio_next_id(void);
1205 -#endif /* _LINUX_SPI_SPI_GPIO */
1206 diff -ruN linux-2.6.26.orig/MAINTAINERS linux-2.6.26/MAINTAINERS
1207 --- linux-2.6.26.orig/MAINTAINERS 2008-10-24 21:04:46.000000000 +0200
1208 +++ linux-2.6.26/MAINTAINERS 2008-10-24 21:04:02.000000000 +0200
1209 @@ -1818,11 +1818,6 @@
1210 W: http://gigaset307x.sourceforge.net/
1220 M: mhoffman@lightlink.com
1221 @@ -3800,11 +3795,6 @@
1222 W: http://www.ibm.com/developerworks/power/cell/
1225 -SPI GPIO MASTER DRIVER
1231 P: Greg Kroah-Hartman