1 Index: linux-2.6.26/Documentation/gpiommc.txt
2 ===================================================================
3 --- linux-2.6.26.orig/Documentation/gpiommc.txt 2008-12-12 21:55:07.000000000 +0100
4 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000
6 -GPIOMMC - Driver for an MMC/SD card on a bitbanging GPIO SPI bus
7 -================================================================
9 -The gpiommc module hooks up the mmc_spi and spi_gpio modules for running an
10 -MMC or SD card on GPIO pins.
12 -Two interfaces for registering a new MMC/SD card device are provided:
13 -A static platform-device based mechanism and a dynamic configfs based interface.
16 -Registering devices via platform-device
17 -=======================================
19 -The platform-device interface is used for registering MMC/SD devices that are
20 -part of the hardware platform. This is most useful only for embedded machines
21 -with MMC/SD devices statically connected to the platform GPIO bus.
23 -The data structures are declared in <linux/mmc/gpiommc.h>.
25 -To register a new device, define an instance of struct gpiommc_platform_data.
26 -This structure holds any information about how the device is hooked up to the
27 -GPIO pins and what hardware modes the device supports. See the docbook-style
28 -documentation in the header file for more information on the struct fields.
30 -Then allocate a new instance of a platform device by doing:
32 - pdev = platform_device_alloc(GPIOMMC_PLATDEV_NAME, gpiommc_next_id());
34 -This will allocate the platform device data structures and hook it up to the
36 -Then add the gpiommc_platform_data to the platform device.
38 - err = platform_device_add_data(pdev, pdata, sizeof(struct gpiommc_platform_data));
40 -You may free the local instance of struct gpiommc_platform_data now. (So the
41 -struct may be allocated on the stack, too).
42 -Now simply register the platform device.
44 - err = platform_device_add(pdev);
46 -Done. The gpiommc probe routine will be invoked now and you should see a kernel
47 -log message for the added device.
50 -Registering devices via configfs
51 -================================
53 -MMC/SD cards connected via GPIO often are a pretty dynamic thing, as for example
54 -selfmade hacks for soldering an MMC/SD card to standard GPIO pins on embedded
55 -hardware are a common situation.
56 -So we provide a dynamic interface to conveniently handle adding and removing
57 -devices from userspace, without the need to recompile the kernel.
59 -The "gpiommc" subdirectory at the configfs mountpoint is used for handling
60 -the dynamic configuration.
62 -To create a new device, it must first be allocated with mkdir.
63 -The following command will allocate a device named "my_mmc":
64 - mkdir /config/gpiommc/my_mmc
66 -There are several configuration files available in the new
67 -/config/gpiommc/my_mmc/ directory:
69 -gpio_data_in = The SPI data-IN GPIO pin number.
70 -gpio_data_out = The SPI data-OUT GPIO pin number.
71 -gpio_clock = The SPI Clock GPIO pin number.
72 -gpio_chipselect = The SPI Chipselect GPIO pin number.
73 -gpio_chipselect_activelow = Boolean. If 0, Chipselect is active-HIGH.
74 - If 1, Chipselect is active-LOW.
75 -spi_mode = The SPI data mode. Can be 0-3.
76 -spi_delay = Enable all delays in the lowlevel bitbanging.
77 -max_bus_speed = The maximum SPI bus speed. In Hertz.
79 -register = Not a configuration parameter.
80 - Used to register the configured card
83 -The device must first get configured and then registered by writing "1" to
85 -The configuration parameters "gpio_data_in", "gpio_data_out", "gpio_clock"
86 -and "gpio_chipselect" are essential and _must_ be configured before writing
87 -"1" to the "register" file. The registration will fail, otherwise.
89 -The default values for the other parameters are:
90 -gpio_chipselect_activelow = 1 (CS active-LOW)
91 -spi_mode = 0 (SPI_MODE_0)
92 -spi_delay = 1 (enabled)
93 -max_bus_speed = 5000000 (5 Mhz)
95 -Configuration values can not be changed after registration. To unregister
96 -the device, write a "0" to the "register" file. The configuration can be
97 -changed again after unregistering.
99 -To completely remove the device, simply rmdir the directory
100 -(/config/gpiommc/my_mmc in this example).
101 -There's no need to first unregister the device before removing it. That will
102 -be done automatically.
103 Index: linux-2.6.26/drivers/mmc/host/gpiommc.c
104 ===================================================================
105 --- linux-2.6.26.orig/drivers/mmc/host/gpiommc.c 2008-12-12 21:55:07.000000000 +0100
106 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000
109 - * Driver an MMC/SD card on a bitbanging GPIO SPI bus.
110 - * This module hooks up the mmc_spi and spi_gpio modules and also
111 - * provides a configfs interface.
113 - * Copyright 2008 Michael Buesch <mb@bu3sch.de>
115 - * Licensed under the GNU/GPL. See COPYING for details.
118 -#include <linux/platform_device.h>
119 -#include <linux/list.h>
120 -#include <linux/mutex.h>
121 -#include <linux/mmc/gpiommc.h>
122 -#include <linux/mmc/host.h>
123 -#include <linux/spi/spi_gpio.h>
124 -#include <linux/spi/mmc_spi.h>
125 -#include <linux/configfs.h>
126 -#include <linux/gpio.h>
127 -#include <asm/atomic.h>
130 -#define PFX "gpio-mmc: "
133 -struct gpiommc_device {
134 - struct platform_device *pdev;
135 - struct platform_device *spi_pdev;
136 - struct spi_board_info boardinfo;
137 - struct mmc_spi_platform_data mmc_spi_data;
141 -MODULE_DESCRIPTION("GPIO based MMC driver");
142 -MODULE_AUTHOR("Michael Buesch");
143 -MODULE_LICENSE("GPL");
146 -static int gpiommc_boardinfo_setup(struct spi_board_info *bi,
147 - struct spi_master *master,
150 - struct gpiommc_device *d = data;
151 - struct gpiommc_platform_data *pdata = d->pdev->dev.platform_data;
153 - /* Bind the SPI master to the MMC-SPI host driver. */
154 - strlcpy(bi->modalias, "mmc_spi", sizeof(bi->modalias));
156 - bi->max_speed_hz = pdata->max_bus_speed;
157 - bi->bus_num = master->bus_num;
158 - bi->mode = pdata->mode;
159 - bi->platform_data = &d->mmc_spi_data;
164 -static int gpiommc_probe(struct platform_device *pdev)
166 - struct gpiommc_platform_data *mmc_pdata = pdev->dev.platform_data;
167 - struct spi_gpio_platform_data spi_pdata;
168 - struct gpiommc_device *d;
175 -#ifdef CONFIG_MMC_SPI_MODULE
176 - err = request_module("mmc_spi");
178 - printk(KERN_WARNING PFX
179 - "Failed to request mmc_spi module.\n");
181 -#endif /* CONFIG_MMC_SPI_MODULE */
183 - /* Allocate the GPIO-MMC device */
185 - d = kzalloc(sizeof(*d), GFP_KERNEL);
189 - d->mmc_spi_data.ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34;
191 - /* Create the SPI-GPIO device */
192 - d->spi_pdev = platform_device_alloc(SPI_GPIO_PLATDEV_NAME,
193 - spi_gpio_next_id());
197 - memset(&spi_pdata, 0, sizeof(spi_pdata));
198 - spi_pdata.pin_clk = mmc_pdata->pins.gpio_clk;
199 - spi_pdata.pin_miso = mmc_pdata->pins.gpio_do;
200 - spi_pdata.pin_mosi = mmc_pdata->pins.gpio_di;
201 - spi_pdata.pin_cs = mmc_pdata->pins.gpio_cs;
202 - spi_pdata.cs_activelow = mmc_pdata->pins.cs_activelow;
203 - spi_pdata.no_spi_delay = mmc_pdata->no_spi_delay;
204 - spi_pdata.boardinfo_setup = gpiommc_boardinfo_setup;
205 - spi_pdata.boardinfo_setup_data = d;
207 - err = platform_device_add_data(d->spi_pdev, &spi_pdata,
208 - sizeof(spi_pdata));
210 - goto err_free_pdev;
211 - err = platform_device_add(d->spi_pdev);
213 - goto err_free_pdata;
214 - platform_set_drvdata(pdev, d);
216 - printk(KERN_INFO PFX "MMC-Card \"%s\" "
217 - "attached to GPIO pins di=%u, do=%u, clk=%u, cs=%u\n",
218 - mmc_pdata->name, mmc_pdata->pins.gpio_di,
219 - mmc_pdata->pins.gpio_do,
220 - mmc_pdata->pins.gpio_clk,
221 - mmc_pdata->pins.gpio_cs);
226 - kfree(d->spi_pdev->dev.platform_data);
227 - d->spi_pdev->dev.platform_data = NULL;
229 - platform_device_put(d->spi_pdev);
236 -static int gpiommc_remove(struct platform_device *pdev)
238 - struct gpiommc_device *d = platform_get_drvdata(pdev);
239 - struct gpiommc_platform_data *pdata = d->pdev->dev.platform_data;
241 - platform_device_unregister(d->spi_pdev);
242 - printk(KERN_INFO PFX "GPIO based MMC-Card \"%s\" removed\n",
244 - platform_device_put(d->spi_pdev);
249 -#ifdef CONFIG_GPIOMMC_CONFIGFS
251 -/* A device that was created through configfs */
252 -struct gpiommc_configfs_device {
253 - struct config_item item;
254 - /* The platform device, after registration. */
255 - struct platform_device *pdev;
256 - /* The configuration */
257 - struct gpiommc_platform_data pdata;
258 - /* Mutex to protect this structure */
259 - struct mutex mutex;
262 -#define GPIO_INVALID -1
264 -static inline bool gpiommc_is_registered(struct gpiommc_configfs_device *dev)
266 - return (dev->pdev != NULL);
269 -static inline struct gpiommc_configfs_device *ci_to_gpiommc(struct config_item *item)
271 - return item ? container_of(item, struct gpiommc_configfs_device, item) : NULL;
274 -static struct configfs_attribute gpiommc_attr_DI = {
275 - .ca_owner = THIS_MODULE,
276 - .ca_name = "gpio_data_in",
277 - .ca_mode = S_IRUGO | S_IWUSR,
280 -static struct configfs_attribute gpiommc_attr_DO = {
281 - .ca_owner = THIS_MODULE,
282 - .ca_name = "gpio_data_out",
283 - .ca_mode = S_IRUGO | S_IWUSR,
286 -static struct configfs_attribute gpiommc_attr_CLK = {
287 - .ca_owner = THIS_MODULE,
288 - .ca_name = "gpio_clock",
289 - .ca_mode = S_IRUGO | S_IWUSR,
292 -static struct configfs_attribute gpiommc_attr_CS = {
293 - .ca_owner = THIS_MODULE,
294 - .ca_name = "gpio_chipselect",
295 - .ca_mode = S_IRUGO | S_IWUSR,
298 -static struct configfs_attribute gpiommc_attr_CS_activelow = {
299 - .ca_owner = THIS_MODULE,
300 - .ca_name = "gpio_chipselect_activelow",
301 - .ca_mode = S_IRUGO | S_IWUSR,
304 -static struct configfs_attribute gpiommc_attr_spimode = {
305 - .ca_owner = THIS_MODULE,
306 - .ca_name = "spi_mode",
307 - .ca_mode = S_IRUGO | S_IWUSR,
310 -static struct configfs_attribute gpiommc_attr_spidelay = {
311 - .ca_owner = THIS_MODULE,
312 - .ca_name = "spi_delay",
313 - .ca_mode = S_IRUGO | S_IWUSR,
316 -static struct configfs_attribute gpiommc_attr_max_bus_speed = {
317 - .ca_owner = THIS_MODULE,
318 - .ca_name = "max_bus_speed",
319 - .ca_mode = S_IRUGO | S_IWUSR,
322 -static struct configfs_attribute gpiommc_attr_register = {
323 - .ca_owner = THIS_MODULE,
324 - .ca_name = "register",
325 - .ca_mode = S_IRUGO | S_IWUSR,
328 -static struct configfs_attribute *gpiommc_config_attrs[] = {
333 - &gpiommc_attr_CS_activelow,
334 - &gpiommc_attr_spimode,
335 - &gpiommc_attr_spidelay,
336 - &gpiommc_attr_max_bus_speed,
337 - &gpiommc_attr_register,
341 -static ssize_t gpiommc_config_attr_show(struct config_item *item,
342 - struct configfs_attribute *attr,
345 - struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
350 - mutex_lock(&dev->mutex);
352 - if (attr == &gpiommc_attr_DI) {
353 - gpio = dev->pdata.pins.gpio_di;
354 - if (gpio == GPIO_INVALID)
355 - count = snprintf(page, PAGE_SIZE, "not configured\n");
357 - count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
360 - if (attr == &gpiommc_attr_DO) {
361 - gpio = dev->pdata.pins.gpio_do;
362 - if (gpio == GPIO_INVALID)
363 - count = snprintf(page, PAGE_SIZE, "not configured\n");
365 - count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
368 - if (attr == &gpiommc_attr_CLK) {
369 - gpio = dev->pdata.pins.gpio_clk;
370 - if (gpio == GPIO_INVALID)
371 - count = snprintf(page, PAGE_SIZE, "not configured\n");
373 - count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
376 - if (attr == &gpiommc_attr_CS) {
377 - gpio = dev->pdata.pins.gpio_cs;
378 - if (gpio == GPIO_INVALID)
379 - count = snprintf(page, PAGE_SIZE, "not configured\n");
381 - count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
384 - if (attr == &gpiommc_attr_CS_activelow) {
385 - count = snprintf(page, PAGE_SIZE, "%u\n",
386 - dev->pdata.pins.cs_activelow);
389 - if (attr == &gpiommc_attr_spimode) {
390 - count = snprintf(page, PAGE_SIZE, "%u\n",
394 - if (attr == &gpiommc_attr_spidelay) {
395 - count = snprintf(page, PAGE_SIZE, "%u\n",
396 - !dev->pdata.no_spi_delay);
399 - if (attr == &gpiommc_attr_max_bus_speed) {
400 - count = snprintf(page, PAGE_SIZE, "%u\n",
401 - dev->pdata.max_bus_speed);
404 - if (attr == &gpiommc_attr_register) {
405 - count = snprintf(page, PAGE_SIZE, "%u\n",
406 - gpiommc_is_registered(dev));
412 - mutex_unlock(&dev->mutex);
414 - return err ? err : count;
417 -static int gpiommc_do_register(struct gpiommc_configfs_device *dev,
422 - if (gpiommc_is_registered(dev))
425 - if (!gpio_is_valid(dev->pdata.pins.gpio_di) ||
426 - !gpio_is_valid(dev->pdata.pins.gpio_do) ||
427 - !gpio_is_valid(dev->pdata.pins.gpio_clk) ||
428 - !gpio_is_valid(dev->pdata.pins.gpio_cs)) {
429 - printk(KERN_ERR PFX
430 - "configfs: Invalid GPIO pin number(s)\n");
434 - strlcpy(dev->pdata.name, name,
435 - sizeof(dev->pdata.name));
437 - dev->pdev = platform_device_alloc(GPIOMMC_PLATDEV_NAME,
438 - gpiommc_next_id());
441 - err = platform_device_add_data(dev->pdev, &dev->pdata,
442 - sizeof(dev->pdata));
444 - platform_device_put(dev->pdev);
447 - err = platform_device_add(dev->pdev);
449 - platform_device_put(dev->pdev);
456 -static void gpiommc_do_unregister(struct gpiommc_configfs_device *dev)
458 - if (!gpiommc_is_registered(dev))
461 - platform_device_unregister(dev->pdev);
465 -static ssize_t gpiommc_config_attr_store(struct config_item *item,
466 - struct configfs_attribute *attr,
467 - const char *page, size_t count)
469 - struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
471 - unsigned long data;
473 - mutex_lock(&dev->mutex);
475 - if (attr == &gpiommc_attr_register) {
476 - err = strict_strtoul(page, 10, &data);
481 - err = gpiommc_do_register(dev, item->ci_name);
483 - gpiommc_do_unregister(dev);
489 - if (gpiommc_is_registered(dev)) {
490 - /* The rest of the config parameters can only be set
491 - * as long as the device is not registered, yet. */
496 - if (attr == &gpiommc_attr_DI) {
497 - err = strict_strtoul(page, 10, &data);
501 - if (!gpio_is_valid(data))
503 - dev->pdata.pins.gpio_di = data;
507 - if (attr == &gpiommc_attr_DO) {
508 - err = strict_strtoul(page, 10, &data);
512 - if (!gpio_is_valid(data))
514 - dev->pdata.pins.gpio_do = data;
518 - if (attr == &gpiommc_attr_CLK) {
519 - err = strict_strtoul(page, 10, &data);
523 - if (!gpio_is_valid(data))
525 - dev->pdata.pins.gpio_clk = data;
529 - if (attr == &gpiommc_attr_CS) {
530 - err = strict_strtoul(page, 10, &data);
534 - if (!gpio_is_valid(data))
536 - dev->pdata.pins.gpio_cs = data;
540 - if (attr == &gpiommc_attr_CS_activelow) {
541 - err = strict_strtoul(page, 10, &data);
545 - if (data != 0 && data != 1)
547 - dev->pdata.pins.cs_activelow = data;
551 - if (attr == &gpiommc_attr_spimode) {
552 - err = strict_strtoul(page, 10, &data);
558 - dev->pdata.mode = SPI_MODE_0;
561 - dev->pdata.mode = SPI_MODE_1;
564 - dev->pdata.mode = SPI_MODE_2;
567 - dev->pdata.mode = SPI_MODE_3;
575 - if (attr == &gpiommc_attr_spidelay) {
576 - err = strict_strtoul(page, 10, &data);
580 - if (data != 0 && data != 1)
582 - dev->pdata.no_spi_delay = !data;
586 - if (attr == &gpiommc_attr_max_bus_speed) {
587 - err = strict_strtoul(page, 10, &data);
591 - if (data > UINT_MAX)
593 - dev->pdata.max_bus_speed = data;
600 - mutex_unlock(&dev->mutex);
602 - return err ? err : count;
605 -static void gpiommc_config_item_release(struct config_item *item)
607 - struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
612 -static struct configfs_item_operations gpiommc_config_item_ops = {
613 - .release = gpiommc_config_item_release,
614 - .show_attribute = gpiommc_config_attr_show,
615 - .store_attribute = gpiommc_config_attr_store,
618 -static struct config_item_type gpiommc_dev_ci_type = {
619 - .ct_item_ops = &gpiommc_config_item_ops,
620 - .ct_attrs = gpiommc_config_attrs,
621 - .ct_owner = THIS_MODULE,
624 -static struct config_item *gpiommc_make_item(struct config_group *group,
627 - struct gpiommc_configfs_device *dev;
629 - if (strlen(name) > GPIOMMC_MAX_NAMELEN) {
630 - printk(KERN_ERR PFX "configfs: device name too long\n");
634 - dev = kzalloc(sizeof(*dev), GFP_KERNEL);
638 - mutex_init(&dev->mutex);
639 - config_item_init_type_name(&dev->item, name,
640 - &gpiommc_dev_ci_type);
642 - /* Assign default configuration */
643 - dev->pdata.pins.gpio_di = GPIO_INVALID;
644 - dev->pdata.pins.gpio_do = GPIO_INVALID;
645 - dev->pdata.pins.gpio_clk = GPIO_INVALID;
646 - dev->pdata.pins.gpio_cs = GPIO_INVALID;
647 - dev->pdata.pins.cs_activelow = 1;
648 - dev->pdata.mode = SPI_MODE_0;
649 - dev->pdata.no_spi_delay = 0;
650 - dev->pdata.max_bus_speed = 5000000; /* 5 MHz */
652 - return &(dev->item);
655 -static void gpiommc_drop_item(struct config_group *group,
656 - struct config_item *item)
658 - struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
660 - gpiommc_do_unregister(dev);
664 -static struct configfs_group_operations gpiommc_ct_group_ops = {
665 - .make_item = gpiommc_make_item,
666 - .drop_item = gpiommc_drop_item,
669 -static struct config_item_type gpiommc_ci_type = {
670 - .ct_group_ops = &gpiommc_ct_group_ops,
671 - .ct_owner = THIS_MODULE,
674 -static struct configfs_subsystem gpiommc_subsys = {
677 - .ci_namebuf = GPIOMMC_PLATDEV_NAME,
678 - .ci_type = &gpiommc_ci_type,
681 - .su_mutex = __MUTEX_INITIALIZER(gpiommc_subsys.su_mutex),
684 -#endif /* CONFIG_GPIOMMC_CONFIGFS */
686 -static struct platform_driver gpiommc_plat_driver = {
687 - .probe = gpiommc_probe,
688 - .remove = gpiommc_remove,
690 - .name = GPIOMMC_PLATDEV_NAME,
691 - .owner = THIS_MODULE,
695 -int gpiommc_next_id(void)
697 - static atomic_t counter = ATOMIC_INIT(-1);
699 - return atomic_inc_return(&counter);
701 -EXPORT_SYMBOL(gpiommc_next_id);
703 -static int __init gpiommc_modinit(void)
707 - err = platform_driver_register(&gpiommc_plat_driver);
711 -#ifdef CONFIG_GPIOMMC_CONFIGFS
712 - config_group_init(&gpiommc_subsys.su_group);
713 - err = configfs_register_subsystem(&gpiommc_subsys);
715 - platform_driver_unregister(&gpiommc_plat_driver);
718 -#endif /* CONFIG_GPIOMMC_CONFIGFS */
722 -module_init(gpiommc_modinit);
724 -static void __exit gpiommc_modexit(void)
726 -#ifdef CONFIG_GPIOMMC_CONFIGFS
727 - configfs_unregister_subsystem(&gpiommc_subsys);
729 - platform_driver_unregister(&gpiommc_plat_driver);
731 -module_exit(gpiommc_modexit);
732 Index: linux-2.6.26/drivers/mmc/host/Kconfig
733 ===================================================================
734 --- linux-2.6.26.orig/drivers/mmc/host/Kconfig 2008-12-12 21:55:07.000000000 +0100
735 +++ linux-2.6.26/drivers/mmc/host/Kconfig 2008-12-12 21:55:25.000000000 +0100
736 @@ -130,27 +130,3 @@ config MMC_SPI
738 If unsure, or if your system has no SPI master driver, say N.
741 - tristate "MMC/SD over GPIO-based SPI"
742 - depends on MMC && MMC_SPI && SPI_GPIO
744 - This driver hooks up the mmc_spi and spi_gpio modules so that
745 - MMC/SD cards can be used on a GPIO based bus by bitbanging
746 - the SPI protocol in software.
748 - This driver provides a configfs interface to dynamically create
749 - and destroy GPIO-based MMC/SD card devices. It also provides
750 - a platform device interface API.
751 - See Documentation/gpiommc.txt for details.
753 - The module will be called gpiommc.
757 -config GPIOMMC_CONFIGFS
759 - depends on GPIOMMC && CONFIGFS_FS
762 - This option automatically enables configfs support for gpiommc
763 - if configfs is available.
764 Index: linux-2.6.26/drivers/mmc/host/Makefile
765 ===================================================================
766 --- linux-2.6.26.orig/drivers/mmc/host/Makefile 2008-12-12 21:55:07.000000000 +0100
767 +++ linux-2.6.26/drivers/mmc/host/Makefile 2008-12-12 21:55:25.000000000 +0100
768 @@ -17,4 +17,4 @@ obj-$(CONFIG_MMC_OMAP) += omap.o
769 obj-$(CONFIG_MMC_AT91) += at91_mci.o
770 obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
771 obj-$(CONFIG_MMC_SPI) += mmc_spi.o
772 -obj-$(CONFIG_GPIOMMC) += gpiommc.o
774 Index: linux-2.6.26/drivers/spi/Kconfig
775 ===================================================================
776 --- linux-2.6.26.orig/drivers/spi/Kconfig 2008-12-12 21:55:07.000000000 +0100
777 +++ linux-2.6.26/drivers/spi/Kconfig 2008-12-12 21:55:25.000000000 +0100
778 @@ -100,19 +100,6 @@ config SPI_BUTTERFLY
779 inexpensive battery powered microcontroller evaluation board.
780 This same cable can be used to flash new firmware.
783 - tristate "GPIO API based bitbanging SPI controller"
784 - depends on SPI_MASTER && GENERIC_GPIO
787 - This is a platform driver that can be used for bitbanging
788 - an SPI bus over GPIO pins.
789 - Select this if you have any SPI device that is connected via
791 - The module will be called spi_gpio.
796 tristate "Freescale iMX SPI controller"
797 depends on SPI_MASTER && ARCH_IMX && EXPERIMENTAL
798 Index: linux-2.6.26/drivers/spi/Makefile
799 ===================================================================
800 --- linux-2.6.26.orig/drivers/spi/Makefile 2008-12-12 21:55:07.000000000 +0100
801 +++ linux-2.6.26/drivers/spi/Makefile 2008-12-12 21:55:25.000000000 +0100
802 @@ -16,7 +16,6 @@ obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx.
803 obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o
804 obj-$(CONFIG_SPI_AU1550) += au1550_spi.o
805 obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o
806 -obj-$(CONFIG_SPI_GPIO) += spi_gpio.o
807 obj-$(CONFIG_SPI_IMX) += spi_imx.o
808 obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o
809 obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o
810 Index: linux-2.6.26/drivers/spi/spi_gpio.c
811 ===================================================================
812 --- linux-2.6.26.orig/drivers/spi/spi_gpio.c 2008-12-12 21:55:07.000000000 +0100
813 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000
816 - * Bitbanging SPI bus driver using GPIO API
818 - * Copyright (c) 2008 Piotr Skamruk
819 - * Copyright (c) 2008 Michael Buesch
821 - * based on spi_s3c2410_gpio.c
822 - * Copyright (c) 2006 Ben Dooks
823 - * Copyright (c) 2006 Simtec Electronics
824 - * and on i2c-gpio.c
825 - * Copyright (C) 2007 Atmel Corporation
827 - * This program is free software; you can redistribute it and/or modify
828 - * it under the terms of the GNU General Public License version 2 as
829 - * published by the Free Software Foundation.
832 -#include <linux/kernel.h>
833 -#include <linux/init.h>
834 -#include <linux/delay.h>
835 -#include <linux/spinlock.h>
836 -#include <linux/workqueue.h>
837 -#include <linux/module.h>
838 -#include <linux/platform_device.h>
839 -#include <linux/spi/spi.h>
840 -#include <linux/spi/spi_bitbang.h>
841 -#include <linux/spi/spi_gpio.h>
842 -#include <linux/gpio.h>
843 -#include <asm/atomic.h>
847 - struct spi_bitbang bitbang;
848 - struct spi_gpio_platform_data *info;
849 - struct platform_device *pdev;
850 - struct spi_board_info bi;
854 -static inline struct spi_gpio *spidev_to_sg(struct spi_device *dev)
856 - return dev->controller_data;
859 -static inline void setsck(struct spi_device *dev, int val)
861 - struct spi_gpio *sp = spidev_to_sg(dev);
862 - gpio_set_value(sp->info->pin_clk, val ? 1 : 0);
865 -static inline void setmosi(struct spi_device *dev, int val)
867 - struct spi_gpio *sp = spidev_to_sg(dev);
868 - gpio_set_value(sp->info->pin_mosi, val ? 1 : 0);
871 -static inline u32 getmiso(struct spi_device *dev)
873 - struct spi_gpio *sp = spidev_to_sg(dev);
874 - return gpio_get_value(sp->info->pin_miso) ? 1 : 0;
877 -static inline void do_spidelay(struct spi_device *dev, unsigned nsecs)
879 - struct spi_gpio *sp = spidev_to_sg(dev);
881 - if (!sp->info->no_spi_delay)
885 -#define spidelay(nsecs) do { \
886 - /* Steal the spi_device pointer from our caller. \
887 - * The bitbang-API should probably get fixed here... */ \
888 - do_spidelay(spi, nsecs); \
891 -#define EXPAND_BITBANG_TXRX
892 -#include <linux/spi/spi_bitbang.h>
894 -static u32 spi_gpio_txrx_mode0(struct spi_device *spi,
895 - unsigned nsecs, u32 word, u8 bits)
897 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
900 -static u32 spi_gpio_txrx_mode1(struct spi_device *spi,
901 - unsigned nsecs, u32 word, u8 bits)
903 - return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
906 -static u32 spi_gpio_txrx_mode2(struct spi_device *spi,
907 - unsigned nsecs, u32 word, u8 bits)
909 - return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits);
912 -static u32 spi_gpio_txrx_mode3(struct spi_device *spi,
913 - unsigned nsecs, u32 word, u8 bits)
915 - return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits);
918 -static void spi_gpio_chipselect(struct spi_device *dev, int on)
920 - struct spi_gpio *sp = spidev_to_sg(dev);
922 - if (sp->info->cs_activelow)
924 - gpio_set_value(sp->info->pin_cs, on ? 1 : 0);
927 -static int spi_gpio_probe(struct platform_device *pdev)
929 - struct spi_master *master;
930 - struct spi_gpio_platform_data *pdata;
931 - struct spi_gpio *sp;
932 - struct spi_device *spidev;
935 - pdata = pdev->dev.platform_data;
940 - master = spi_alloc_master(&pdev->dev, sizeof(struct spi_gpio));
942 - goto err_alloc_master;
944 - sp = spi_master_get_devdata(master);
945 - platform_set_drvdata(pdev, sp);
948 - err = gpio_request(pdata->pin_clk, "spi_clock");
950 - goto err_request_clk;
951 - err = gpio_request(pdata->pin_mosi, "spi_mosi");
953 - goto err_request_mosi;
954 - err = gpio_request(pdata->pin_miso, "spi_miso");
956 - goto err_request_miso;
957 - err = gpio_request(pdata->pin_cs, "spi_cs");
959 - goto err_request_cs;
961 - sp->bitbang.master = spi_master_get(master);
962 - sp->bitbang.master->bus_num = -1;
963 - sp->bitbang.master->num_chipselect = 1;
964 - sp->bitbang.chipselect = spi_gpio_chipselect;
965 - sp->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_mode0;
966 - sp->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_mode1;
967 - sp->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_mode2;
968 - sp->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_txrx_mode3;
970 - gpio_direction_output(pdata->pin_clk, 0);
971 - gpio_direction_output(pdata->pin_mosi, 0);
972 - gpio_direction_output(pdata->pin_cs,
973 - pdata->cs_activelow ? 1 : 0);
974 - gpio_direction_input(pdata->pin_miso);
976 - err = spi_bitbang_start(&sp->bitbang);
978 - goto err_no_bitbang;
979 - err = pdata->boardinfo_setup(&sp->bi, master,
980 - pdata->boardinfo_setup_data);
983 - sp->bi.controller_data = sp;
984 - spidev = spi_new_device(master, &sp->bi);
992 - spi_bitbang_stop(&sp->bitbang);
994 - spi_master_put(sp->bitbang.master);
995 - gpio_free(pdata->pin_cs);
997 - gpio_free(pdata->pin_miso);
999 - gpio_free(pdata->pin_mosi);
1001 - gpio_free(pdata->pin_clk);
1009 -static int __devexit spi_gpio_remove(struct platform_device *pdev)
1011 - struct spi_gpio *sp;
1012 - struct spi_gpio_platform_data *pdata;
1014 - pdata = pdev->dev.platform_data;
1015 - sp = platform_get_drvdata(pdev);
1017 - gpio_free(pdata->pin_clk);
1018 - gpio_free(pdata->pin_mosi);
1019 - gpio_free(pdata->pin_miso);
1020 - gpio_free(pdata->pin_cs);
1021 - spi_bitbang_stop(&sp->bitbang);
1022 - spi_master_put(sp->bitbang.master);
1027 -static struct platform_driver spi_gpio_driver = {
1029 - .name = SPI_GPIO_PLATDEV_NAME,
1030 - .owner = THIS_MODULE,
1032 - .probe = spi_gpio_probe,
1033 - .remove = __devexit_p(spi_gpio_remove),
1036 -int spi_gpio_next_id(void)
1038 - static atomic_t counter = ATOMIC_INIT(-1);
1040 - return atomic_inc_return(&counter);
1042 -EXPORT_SYMBOL(spi_gpio_next_id);
1044 -static int __init spi_gpio_init(void)
1048 - err = platform_driver_register(&spi_gpio_driver);
1050 - printk(KERN_ERR "spi-gpio: register failed: %d\n", err);
1054 -module_init(spi_gpio_init);
1056 -static void __exit spi_gpio_exit(void)
1058 - platform_driver_unregister(&spi_gpio_driver);
1060 -module_exit(spi_gpio_exit);
1062 -MODULE_AUTHOR("Piot Skamruk <piotr.skamruk at gmail.com>");
1063 -MODULE_AUTHOR("Michael Buesch");
1064 -MODULE_DESCRIPTION("Platform independent GPIO bitbanging SPI driver");
1065 -MODULE_LICENSE("GPL v2");
1066 Index: linux-2.6.26/include/linux/mmc/gpiommc.h
1067 ===================================================================
1068 --- linux-2.6.26.orig/include/linux/mmc/gpiommc.h 2008-12-12 21:55:07.000000000 +0100
1069 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000
1072 - * Device driver for MMC/SD cards driven over a GPIO bus.
1074 - * Copyright (c) 2008 Michael Buesch
1076 - * Licensed under the GNU/GPL version 2.
1078 -#ifndef LINUX_GPIOMMC_H_
1079 -#define LINUX_GPIOMMC_H_
1081 -#include <linux/types.h>
1084 -#define GPIOMMC_MAX_NAMELEN 15
1085 -#define GPIOMMC_MAX_NAMELEN_STR __stringify(GPIOMMC_MAX_NAMELEN)
1088 - * struct gpiommc_pins - Hardware pin assignments
1090 - * @gpio_di: The GPIO number of the DATA IN pin
1091 - * @gpio_do: The GPIO number of the DATA OUT pin
1092 - * @gpio_clk: The GPIO number of the CLOCK pin
1093 - * @gpio_cs: The GPIO number of the CHIPSELECT pin
1094 - * @cs_activelow: If true, the chip is considered selected if @gpio_cs is low.
1096 -struct gpiommc_pins {
1097 - unsigned int gpio_di;
1098 - unsigned int gpio_do;
1099 - unsigned int gpio_clk;
1100 - unsigned int gpio_cs;
1101 - bool cs_activelow;
1105 - * struct gpiommc_platform_data - Platform data for a MMC-over-SPI-GPIO device.
1107 - * @name: The unique name string of the device.
1108 - * @pins: The hardware pin assignments.
1109 - * @mode: The hardware mode. This is either SPI_MODE_0,
1110 - * SPI_MODE_1, SPI_MODE_2 or SPI_MODE_3. See the SPI documentation.
1111 - * @no_spi_delay: Do not use delays in the lowlevel SPI bitbanging code.
1112 - * This is not standards compliant, but may be required for some
1113 - * embedded machines to gain reasonable speed.
1114 - * @max_bus_speed: The maximum speed of the SPI bus, in Hertz.
1116 -struct gpiommc_platform_data {
1117 - char name[GPIOMMC_MAX_NAMELEN + 1];
1118 - struct gpiommc_pins pins;
1120 - bool no_spi_delay;
1121 - unsigned int max_bus_speed;
1125 - * GPIOMMC_PLATDEV_NAME - The platform device name string.
1127 - * The name string that has to be used for platform_device_alloc
1128 - * when allocating a gpiommc device.
1130 -#define GPIOMMC_PLATDEV_NAME "gpiommc"
1133 - * gpiommc_next_id - Get another platform device ID number.
1135 - * This returns the next platform device ID number that has to be used
1136 - * for platform_device_alloc. The ID is opaque and should not be used for
1139 -int gpiommc_next_id(void);
1141 -#endif /* LINUX_GPIOMMC_H_ */
1142 Index: linux-2.6.26/include/linux/spi/spi_gpio.h
1143 ===================================================================
1144 --- linux-2.6.26.orig/include/linux/spi/spi_gpio.h 2008-12-12 21:55:07.000000000 +0100
1145 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000
1148 - * spi_gpio interface to platform code
1150 - * Copyright (c) 2008 Piotr Skamruk
1151 - * Copyright (c) 2008 Michael Buesch
1153 - * This program is free software; you can redistribute it and/or modify
1154 - * it under the terms of the GNU General Public License version 2 as
1155 - * published by the Free Software Foundation.
1157 -#ifndef _LINUX_SPI_SPI_GPIO
1158 -#define _LINUX_SPI_SPI_GPIO
1160 -#include <linux/types.h>
1161 -#include <linux/spi/spi.h>
1165 - * struct spi_gpio_platform_data - Data definitions for a SPI-GPIO device.
1167 - * This structure holds information about a GPIO-based SPI device.
1169 - * @pin_clk: The GPIO pin number of the CLOCK pin.
1171 - * @pin_miso: The GPIO pin number of the MISO pin.
1173 - * @pin_mosi: The GPIO pin number of the MOSI pin.
1175 - * @pin_cs: The GPIO pin number of the CHIPSELECT pin.
1177 - * @cs_activelow: If true, the chip is selected when the CS line is low.
1179 - * @no_spi_delay: If true, no delay is done in the lowlevel bitbanging.
1180 - * Note that doing no delay is not standards compliant,
1181 - * but it might be needed to speed up transfers on some
1182 - * slow embedded machines.
1184 - * @boardinfo_setup: This callback is called after the
1185 - * SPI master device was registered, but before the
1186 - * device is registered.
1187 - * @boardinfo_setup_data: Data argument passed to boardinfo_setup().
1189 -struct spi_gpio_platform_data {
1190 - unsigned int pin_clk;
1191 - unsigned int pin_miso;
1192 - unsigned int pin_mosi;
1193 - unsigned int pin_cs;
1194 - bool cs_activelow;
1195 - bool no_spi_delay;
1196 - int (*boardinfo_setup)(struct spi_board_info *bi,
1197 - struct spi_master *master,
1199 - void *boardinfo_setup_data;
1203 - * SPI_GPIO_PLATDEV_NAME - The platform device name string.
1205 - * The name string that has to be used for platform_device_alloc
1206 - * when allocating a spi-gpio device.
1208 -#define SPI_GPIO_PLATDEV_NAME "spi-gpio"
1211 - * spi_gpio_next_id - Get another platform device ID number.
1213 - * This returns the next platform device ID number that has to be used
1214 - * for platform_device_alloc. The ID is opaque and should not be used for
1217 -int spi_gpio_next_id(void);
1219 -#endif /* _LINUX_SPI_SPI_GPIO */
1220 Index: linux-2.6.26/MAINTAINERS
1221 ===================================================================
1222 --- linux-2.6.26.orig/MAINTAINERS 2008-12-12 21:55:07.000000000 +0100
1223 +++ linux-2.6.26/MAINTAINERS 2008-12-12 21:55:25.000000000 +0100
1224 @@ -1818,11 +1818,6 @@ L: gigaset307x-common@lists.sourceforge.
1225 W: http://gigaset307x.sourceforge.net/
1235 M: mhoffman@lightlink.com
1236 @@ -3800,11 +3795,6 @@ L: cbe-oss-dev@ozlabs.org
1237 W: http://www.ibm.com/developerworks/power/cell/
1240 -SPI GPIO MASTER DRIVER
1246 P: Greg Kroah-Hartman