Remove me from the gpio-spi related stuff
[openwrt/staging/yousong.git] / target / linux / generic-2.6 / patches-2.6.25 / 922-gpiommc.patch
1 Index: linux-2.6.25.17/drivers/mmc/host/gpiommc.c
2 ===================================================================
3 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
4 +++ linux-2.6.25.17/drivers/mmc/host/gpiommc.c 2008-10-18 23:33:54.000000000 +0200
5 @@ -0,0 +1,605 @@
6 +/*
7 + * Driver an MMC/SD card on a bitbanging GPIO SPI bus.
8 + * This module hooks up the mmc_spi and spi_gpio modules and also
9 + * provides a configfs interface.
10 + *
11 + * Licensed under the GNU/GPL. See COPYING for details.
12 + */
13 +
14 +#include <linux/mmc/gpiommc.h>
15 +#include <linux/platform_device.h>
16 +#include <linux/list.h>
17 +#include <linux/mutex.h>
18 +#include <linux/spi/spi_gpio.h>
19 +#include <linux/configfs.h>
20 +#include <linux/gpio.h>
21 +#include <asm/atomic.h>
22 +
23 +
24 +#define PFX "gpio-mmc: "
25 +
26 +
27 +struct gpiommc_device {
28 + struct platform_device *pdev;
29 + struct platform_device *spi_pdev;
30 + struct spi_board_info boardinfo;
31 +};
32 +
33 +
34 +MODULE_DESCRIPTION("GPIO based MMC driver");
35 +MODULE_LICENSE("GPL");
36 +
37 +
38 +static int gpiommc_boardinfo_setup(struct spi_board_info *bi,
39 + struct spi_master *master,
40 + void *data)
41 +{
42 + struct gpiommc_device *d = data;
43 + struct gpiommc_platform_data *pdata = d->pdev->dev.platform_data;
44 +
45 + /* Bind the SPI master to the MMC-SPI host driver. */
46 + strlcpy(bi->modalias, "mmc_spi", sizeof(bi->modalias));
47 +
48 + bi->max_speed_hz = pdata->max_bus_speed;
49 + bi->bus_num = master->bus_num;
50 + bi->mode = pdata->mode;
51 +
52 + return 0;
53 +}
54 +
55 +static int gpiommc_probe(struct platform_device *pdev)
56 +{
57 + struct gpiommc_platform_data *mmc_pdata = pdev->dev.platform_data;
58 + struct spi_gpio_platform_data spi_pdata;
59 + struct gpiommc_device *d;
60 + int err;
61 +
62 + err = -ENXIO;
63 + if (!mmc_pdata)
64 + goto error;
65 +
66 +#ifdef CONFIG_MMC_SPI_MODULE
67 + err = request_module("mmc_spi");
68 + if (err) {
69 + printk(KERN_WARNING PFX
70 + "Failed to request mmc_spi module.\n");
71 + }
72 +#endif /* CONFIG_MMC_SPI_MODULE */
73 +
74 + /* Allocate the GPIO-MMC device */
75 + err = -ENOMEM;
76 + d = kzalloc(sizeof(*d), GFP_KERNEL);
77 + if (!d)
78 + goto error;
79 + d->pdev = pdev;
80 +
81 + /* Create the SPI-GPIO device */
82 + d->spi_pdev = platform_device_alloc(SPI_GPIO_PLATDEV_NAME,
83 + spi_gpio_next_id());
84 + if (!d->spi_pdev)
85 + goto err_free_d;
86 +
87 + memset(&spi_pdata, 0, sizeof(spi_pdata));
88 + spi_pdata.pin_clk = mmc_pdata->pins.gpio_clk;
89 + spi_pdata.pin_miso = mmc_pdata->pins.gpio_do;
90 + spi_pdata.pin_mosi = mmc_pdata->pins.gpio_di;
91 + spi_pdata.pin_cs = mmc_pdata->pins.gpio_cs;
92 + spi_pdata.cs_activelow = mmc_pdata->pins.cs_activelow;
93 + spi_pdata.no_spi_delay = mmc_pdata->no_spi_delay;
94 + spi_pdata.boardinfo_setup = gpiommc_boardinfo_setup;
95 + spi_pdata.boardinfo_setup_data = d;
96 +
97 + err = platform_device_add_data(d->spi_pdev, &spi_pdata,
98 + sizeof(spi_pdata));
99 + if (err)
100 + goto err_free_pdev;
101 + err = platform_device_add(d->spi_pdev);
102 + if (err)
103 + goto err_free_pdata;
104 + platform_set_drvdata(pdev, d);
105 +
106 + printk(KERN_INFO PFX "MMC-Card \"%s\" "
107 + "attached to GPIO pins di=%u, do=%u, clk=%u, cs=%u\n",
108 + mmc_pdata->name, mmc_pdata->pins.gpio_di,
109 + mmc_pdata->pins.gpio_do,
110 + mmc_pdata->pins.gpio_clk,
111 + mmc_pdata->pins.gpio_cs);
112 +
113 + return 0;
114 +
115 +err_free_pdata:
116 + kfree(d->spi_pdev->dev.platform_data);
117 + d->spi_pdev->dev.platform_data = NULL;
118 +err_free_pdev:
119 + platform_device_put(d->spi_pdev);
120 +err_free_d:
121 + kfree(d);
122 +error:
123 + return err;
124 +}
125 +
126 +static int gpiommc_remove(struct platform_device *pdev)
127 +{
128 + struct gpiommc_device *d = platform_get_drvdata(pdev);
129 + struct gpiommc_platform_data *pdata = d->pdev->dev.platform_data;
130 +
131 + platform_device_unregister(d->spi_pdev);
132 + printk(KERN_INFO PFX "GPIO based MMC-Card \"%s\" removed\n",
133 + pdata->name);
134 + platform_device_put(d->spi_pdev);
135 +
136 + return 0;
137 +}
138 +
139 +#ifdef CONFIG_GPIOMMC_CONFIGFS
140 +
141 +/* A device that was created through configfs */
142 +struct gpiommc_configfs_device {
143 + struct config_item item;
144 + /* The platform device, after registration. */
145 + struct platform_device *pdev;
146 + /* The configuration */
147 + struct gpiommc_platform_data pdata;
148 +};
149 +
150 +#define GPIO_INVALID -1
151 +
152 +static inline bool gpiommc_is_registered(struct gpiommc_configfs_device *dev)
153 +{
154 + return (dev->pdev != NULL);
155 +}
156 +
157 +static inline struct gpiommc_configfs_device *ci_to_gpiommc(struct config_item *item)
158 +{
159 + return item ? container_of(item, struct gpiommc_configfs_device, item) : NULL;
160 +}
161 +
162 +static struct configfs_attribute gpiommc_attr_DI = {
163 + .ca_owner = THIS_MODULE,
164 + .ca_name = "gpio_data_in",
165 + .ca_mode = S_IRUGO | S_IWUSR,
166 +};
167 +
168 +static struct configfs_attribute gpiommc_attr_DO = {
169 + .ca_owner = THIS_MODULE,
170 + .ca_name = "gpio_data_out",
171 + .ca_mode = S_IRUGO | S_IWUSR,
172 +};
173 +
174 +static struct configfs_attribute gpiommc_attr_CLK = {
175 + .ca_owner = THIS_MODULE,
176 + .ca_name = "gpio_clock",
177 + .ca_mode = S_IRUGO | S_IWUSR,
178 +};
179 +
180 +static struct configfs_attribute gpiommc_attr_CS = {
181 + .ca_owner = THIS_MODULE,
182 + .ca_name = "gpio_chipselect",
183 + .ca_mode = S_IRUGO | S_IWUSR,
184 +};
185 +
186 +static struct configfs_attribute gpiommc_attr_CS_activelow = {
187 + .ca_owner = THIS_MODULE,
188 + .ca_name = "gpio_chipselect_activelow",
189 + .ca_mode = S_IRUGO | S_IWUSR,
190 +};
191 +
192 +static struct configfs_attribute gpiommc_attr_spimode = {
193 + .ca_owner = THIS_MODULE,
194 + .ca_name = "spi_mode",
195 + .ca_mode = S_IRUGO | S_IWUSR,
196 +};
197 +
198 +static struct configfs_attribute gpiommc_attr_spidelay = {
199 + .ca_owner = THIS_MODULE,
200 + .ca_name = "spi_delay",
201 + .ca_mode = S_IRUGO | S_IWUSR,
202 +};
203 +
204 +static struct configfs_attribute gpiommc_attr_max_bus_speed = {
205 + .ca_owner = THIS_MODULE,
206 + .ca_name = "max_bus_speed",
207 + .ca_mode = S_IRUGO | S_IWUSR,
208 +};
209 +
210 +static struct configfs_attribute gpiommc_attr_register = {
211 + .ca_owner = THIS_MODULE,
212 + .ca_name = "register",
213 + .ca_mode = S_IRUGO | S_IWUSR,
214 +};
215 +
216 +static struct configfs_attribute *gpiommc_config_attrs[] = {
217 + &gpiommc_attr_DI,
218 + &gpiommc_attr_DO,
219 + &gpiommc_attr_CLK,
220 + &gpiommc_attr_CS,
221 + &gpiommc_attr_CS_activelow,
222 + &gpiommc_attr_spimode,
223 + &gpiommc_attr_spidelay,
224 + &gpiommc_attr_max_bus_speed,
225 + &gpiommc_attr_register,
226 + NULL,
227 +};
228 +
229 +static ssize_t gpiommc_config_attr_show(struct config_item *item,
230 + struct configfs_attribute *attr,
231 + char *page)
232 +{
233 + struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
234 + ssize_t count = 0;
235 + unsigned int gpio;
236 + int err = 0;
237 +
238 + if (attr == &gpiommc_attr_DI) {
239 + gpio = dev->pdata.pins.gpio_di;
240 + if (gpio == GPIO_INVALID)
241 + count = snprintf(page, PAGE_SIZE, "not configured\n");
242 + else
243 + count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
244 + goto out;
245 + }
246 + if (attr == &gpiommc_attr_DO) {
247 + gpio = dev->pdata.pins.gpio_do;
248 + if (gpio == GPIO_INVALID)
249 + count = snprintf(page, PAGE_SIZE, "not configured\n");
250 + else
251 + count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
252 + goto out;
253 + }
254 + if (attr == &gpiommc_attr_CLK) {
255 + gpio = dev->pdata.pins.gpio_clk;
256 + if (gpio == GPIO_INVALID)
257 + count = snprintf(page, PAGE_SIZE, "not configured\n");
258 + else
259 + count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
260 + goto out;
261 + }
262 + if (attr == &gpiommc_attr_CS) {
263 + gpio = dev->pdata.pins.gpio_cs;
264 + if (gpio == GPIO_INVALID)
265 + count = snprintf(page, PAGE_SIZE, "not configured\n");
266 + else
267 + count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
268 + goto out;
269 + }
270 + if (attr == &gpiommc_attr_CS_activelow) {
271 + count = snprintf(page, PAGE_SIZE, "%u\n",
272 + dev->pdata.pins.cs_activelow);
273 + goto out;
274 + }
275 + if (attr == &gpiommc_attr_spimode) {
276 + count = snprintf(page, PAGE_SIZE, "%u\n",
277 + dev->pdata.mode);
278 + goto out;
279 + }
280 + if (attr == &gpiommc_attr_spidelay) {
281 + count = snprintf(page, PAGE_SIZE, "%u\n",
282 + !dev->pdata.no_spi_delay);
283 + goto out;
284 + }
285 + if (attr == &gpiommc_attr_max_bus_speed) {
286 + count = snprintf(page, PAGE_SIZE, "%u\n",
287 + dev->pdata.max_bus_speed);
288 + goto out;
289 + }
290 + if (attr == &gpiommc_attr_register) {
291 + count = snprintf(page, PAGE_SIZE, "%u\n",
292 + gpiommc_is_registered(dev));
293 + goto out;
294 + }
295 + WARN_ON(1);
296 + err = -ENOSYS;
297 +out:
298 + return err ? err : count;
299 +}
300 +
301 +static int gpiommc_do_register(struct gpiommc_configfs_device *dev,
302 + const char *name)
303 +{
304 + int err;
305 +
306 + if (gpiommc_is_registered(dev))
307 + return 0;
308 +
309 + if (!gpio_is_valid(dev->pdata.pins.gpio_di) ||
310 + !gpio_is_valid(dev->pdata.pins.gpio_do) ||
311 + !gpio_is_valid(dev->pdata.pins.gpio_clk) ||
312 + !gpio_is_valid(dev->pdata.pins.gpio_cs)) {
313 + printk(KERN_ERR PFX
314 + "configfs: Invalid GPIO pin number(s)\n");
315 + return -EINVAL;
316 + }
317 +
318 + strlcpy(dev->pdata.name, name,
319 + sizeof(dev->pdata.name));
320 +
321 + dev->pdev = platform_device_alloc(GPIOMMC_PLATDEV_NAME,
322 + gpiommc_next_id());
323 + if (!dev->pdev)
324 + return -ENOMEM;
325 + err = platform_device_add_data(dev->pdev, &dev->pdata,
326 + sizeof(dev->pdata));
327 + if (err) {
328 + platform_device_put(dev->pdev);
329 + return err;
330 + }
331 + err = platform_device_add(dev->pdev);
332 + if (err) {
333 + platform_device_put(dev->pdev);
334 + return err;
335 + }
336 +
337 + return 0;
338 +}
339 +
340 +static void gpiommc_do_unregister(struct gpiommc_configfs_device *dev)
341 +{
342 + if (!gpiommc_is_registered(dev))
343 + return;
344 +
345 + platform_device_unregister(dev->pdev);
346 + dev->pdev = NULL;
347 +}
348 +
349 +static ssize_t gpiommc_config_attr_store(struct config_item *item,
350 + struct configfs_attribute *attr,
351 + const char *page, size_t count)
352 +{
353 + struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
354 + int err = -EINVAL;
355 + unsigned long data;
356 +
357 + if (attr == &gpiommc_attr_register) {
358 + err = strict_strtoul(page, 10, &data);
359 + if (err)
360 + goto out;
361 + err = -EINVAL;
362 + if (data == 1)
363 + err = gpiommc_do_register(dev, item->ci_name);
364 + if (data == 0) {
365 + gpiommc_do_unregister(dev);
366 + err = 0;
367 + }
368 + goto out;
369 + }
370 +
371 + if (gpiommc_is_registered(dev)) {
372 + /* The rest of the config parameters can only be set
373 + * as long as the device is not registered, yet. */
374 + err = -EBUSY;
375 + goto out;
376 + }
377 +
378 + if (attr == &gpiommc_attr_DI) {
379 + err = strict_strtoul(page, 10, &data);
380 + if (err)
381 + goto out;
382 + err = -EINVAL;
383 + if (!gpio_is_valid(data))
384 + goto out;
385 + dev->pdata.pins.gpio_di = data;
386 + err = 0;
387 + goto out;
388 + }
389 + if (attr == &gpiommc_attr_DO) {
390 + err = strict_strtoul(page, 10, &data);
391 + if (err)
392 + goto out;
393 + err = -EINVAL;
394 + if (!gpio_is_valid(data))
395 + goto out;
396 + dev->pdata.pins.gpio_do = data;
397 + err = 0;
398 + goto out;
399 + }
400 + if (attr == &gpiommc_attr_CLK) {
401 + err = strict_strtoul(page, 10, &data);
402 + if (err)
403 + goto out;
404 + err = -EINVAL;
405 + if (!gpio_is_valid(data))
406 + goto out;
407 + dev->pdata.pins.gpio_clk = data;
408 + err = 0;
409 + goto out;
410 + }
411 + if (attr == &gpiommc_attr_CS) {
412 + err = strict_strtoul(page, 10, &data);
413 + if (err)
414 + goto out;
415 + err = -EINVAL;
416 + if (!gpio_is_valid(data))
417 + goto out;
418 + dev->pdata.pins.gpio_cs = data;
419 + err = 0;
420 + goto out;
421 + }
422 + if (attr == &gpiommc_attr_CS_activelow) {
423 + err = strict_strtoul(page, 10, &data);
424 + if (err)
425 + goto out;
426 + err = -EINVAL;
427 + if (data != 0 && data != 1)
428 + goto out;
429 + dev->pdata.pins.cs_activelow = data;
430 + err = 0;
431 + goto out;
432 + }
433 + if (attr == &gpiommc_attr_spimode) {
434 + err = strict_strtoul(page, 10, &data);
435 + if (err)
436 + goto out;
437 + err = -EINVAL;
438 + switch (data) {
439 + case 0:
440 + dev->pdata.mode = SPI_MODE_0;
441 + break;
442 + case 1:
443 + dev->pdata.mode = SPI_MODE_1;
444 + break;
445 + case 2:
446 + dev->pdata.mode = SPI_MODE_2;
447 + break;
448 + case 3:
449 + dev->pdata.mode = SPI_MODE_3;
450 + break;
451 + default:
452 + goto out;
453 + }
454 + err = 0;
455 + goto out;
456 + }
457 + if (attr == &gpiommc_attr_spidelay) {
458 + err = strict_strtoul(page, 10, &data);
459 + if (err)
460 + goto out;
461 + err = -EINVAL;
462 + if (data != 0 && data != 1)
463 + goto out;
464 + dev->pdata.no_spi_delay = !data;
465 + err = 0;
466 + goto out;
467 + }
468 + if (attr == &gpiommc_attr_max_bus_speed) {
469 + err = strict_strtoul(page, 10, &data);
470 + if (err)
471 + goto out;
472 + err = -EINVAL;
473 + if (data > UINT_MAX)
474 + goto out;
475 + dev->pdata.max_bus_speed = data;
476 + err = 0;
477 + goto out;
478 + }
479 + WARN_ON(1);
480 + err = -ENOSYS;
481 +out:
482 + return err ? err : count;
483 +}
484 +
485 +static void gpiommc_config_item_release(struct config_item *item)
486 +{
487 + struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
488 +
489 + kfree(dev);
490 +}
491 +
492 +static struct configfs_item_operations gpiommc_config_item_ops = {
493 + .release = gpiommc_config_item_release,
494 + .show_attribute = gpiommc_config_attr_show,
495 + .store_attribute = gpiommc_config_attr_store,
496 +};
497 +
498 +static struct config_item_type gpiommc_dev_ci_type = {
499 + .ct_item_ops = &gpiommc_config_item_ops,
500 + .ct_attrs = gpiommc_config_attrs,
501 + .ct_owner = THIS_MODULE,
502 +};
503 +
504 +static struct config_item *gpiommc_make_item(struct config_group *group,
505 + const char *name)
506 +{
507 + struct gpiommc_configfs_device *dev;
508 +
509 + if (strlen(name) > GPIOMMC_MAX_NAMELEN) {
510 + printk(KERN_ERR PFX "configfs: device name too long\n");
511 + return NULL;
512 + }
513 +
514 + dev = kzalloc(sizeof(*dev), GFP_KERNEL);
515 + if (!dev)
516 + return NULL;
517 +
518 + config_item_init_type_name(&dev->item, name,
519 + &gpiommc_dev_ci_type);
520 +
521 + /* Assign default configuration */
522 + dev->pdata.pins.gpio_di = GPIO_INVALID;
523 + dev->pdata.pins.gpio_do = GPIO_INVALID;
524 + dev->pdata.pins.gpio_clk = GPIO_INVALID;
525 + dev->pdata.pins.gpio_cs = GPIO_INVALID;
526 + dev->pdata.pins.cs_activelow = 1;
527 + dev->pdata.mode = SPI_MODE_0;
528 + dev->pdata.no_spi_delay = 0;
529 + dev->pdata.max_bus_speed = 5000000; /* 5 MHz */
530 +
531 + return &(dev->item);
532 +}
533 +
534 +static void gpiommc_drop_item(struct config_group *group,
535 + struct config_item *item)
536 +{
537 + struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
538 +
539 + gpiommc_do_unregister(dev);
540 + kfree(dev);
541 +}
542 +
543 +static struct configfs_group_operations gpiommc_ct_group_ops = {
544 + .make_item = gpiommc_make_item,
545 + .drop_item = gpiommc_drop_item,
546 +};
547 +
548 +static struct config_item_type gpiommc_ci_type = {
549 + .ct_group_ops = &gpiommc_ct_group_ops,
550 + .ct_owner = THIS_MODULE,
551 +};
552 +
553 +static struct configfs_subsystem gpiommc_subsys = {
554 + .su_group = {
555 + .cg_item = {
556 + .ci_namebuf = GPIOMMC_PLATDEV_NAME,
557 + .ci_type = &gpiommc_ci_type,
558 + },
559 + },
560 + .su_mutex = __MUTEX_INITIALIZER(gpiommc_subsys.su_mutex),
561 +};
562 +
563 +#endif /* CONFIG_GPIOMMC_CONFIGFS */
564 +
565 +static struct platform_driver gpiommc_plat_driver = {
566 + .probe = gpiommc_probe,
567 + .remove = gpiommc_remove,
568 + .driver = {
569 + .name = GPIOMMC_PLATDEV_NAME,
570 + .owner = THIS_MODULE,
571 + },
572 +};
573 +
574 +int gpiommc_next_id(void)
575 +{
576 + static atomic_t counter = ATOMIC_INIT(-1);
577 +
578 + return atomic_inc_return(&counter);
579 +}
580 +EXPORT_SYMBOL(gpiommc_next_id);
581 +
582 +static int __init gpiommc_modinit(void)
583 +{
584 + int err;
585 +
586 + err = platform_driver_register(&gpiommc_plat_driver);
587 + if (err)
588 + return err;
589 +
590 +#ifdef CONFIG_GPIOMMC_CONFIGFS
591 + config_group_init(&gpiommc_subsys.su_group);
592 + err = configfs_register_subsystem(&gpiommc_subsys);
593 + if (err) {
594 + platform_driver_unregister(&gpiommc_plat_driver);
595 + return err;
596 + }
597 +#endif /* CONFIG_GPIOMMC_CONFIGFS */
598 +
599 + return 0;
600 +}
601 +module_init(gpiommc_modinit);
602 +
603 +static void __exit gpiommc_modexit(void)
604 +{
605 +#ifdef CONFIG_GPIOMMC_CONFIGFS
606 + configfs_unregister_subsystem(&gpiommc_subsys);
607 +#endif
608 + platform_driver_unregister(&gpiommc_plat_driver);
609 +}
610 +module_exit(gpiommc_modexit);
611 Index: linux-2.6.25.17/drivers/mmc/host/Kconfig
612 ===================================================================
613 --- linux-2.6.25.17.orig/drivers/mmc/host/Kconfig 2008-10-18 23:30:41.000000000 +0200
614 +++ linux-2.6.25.17/drivers/mmc/host/Kconfig 2008-10-18 23:32:54.000000000 +0200
615 @@ -130,3 +130,27 @@ config MMC_SPI
616
617 If unsure, or if your system has no SPI master driver, say N.
618
619 +config GPIOMMC
620 + tristate "MMC/SD over GPIO-based SPI"
621 + depends on MMC && MMC_SPI && SPI_GPIO
622 + help
623 + This driver hooks up the mmc_spi and spi_gpio modules so that
624 + MMC/SD cards can be used on a GPIO based bus by bitbanging
625 + the SPI protocol in software.
626 +
627 + This driver provides a configfs interface to dynamically create
628 + and destroy GPIO-based MMC/SD card devices. It also provides
629 + a platform device interface API.
630 + See Documentation/gpiommc.txt for details.
631 +
632 + The module will be called gpiommc.
633 +
634 + If unsure, say N.
635 +
636 +config GPIOMMC_CONFIGFS
637 + bool
638 + depends on GPIOMMC && CONFIGFS_FS
639 + default y
640 + help
641 + This option automatically enables configfs support for gpiommc
642 + if configfs is available.
643 Index: linux-2.6.25.17/drivers/mmc/host/Makefile
644 ===================================================================
645 --- linux-2.6.25.17.orig/drivers/mmc/host/Makefile 2008-10-18 23:30:41.000000000 +0200
646 +++ linux-2.6.25.17/drivers/mmc/host/Makefile 2008-10-18 23:32:54.000000000 +0200
647 @@ -17,4 +17,4 @@ obj-$(CONFIG_MMC_OMAP) += omap.o
648 obj-$(CONFIG_MMC_AT91) += at91_mci.o
649 obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
650 obj-$(CONFIG_MMC_SPI) += mmc_spi.o
651 -
652 +obj-$(CONFIG_GPIOMMC) += gpiommc.o
653 Index: linux-2.6.25.17/include/linux/mmc/gpiommc.h
654 ===================================================================
655 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
656 +++ linux-2.6.25.17/include/linux/mmc/gpiommc.h 2008-10-18 23:34:21.000000000 +0200
657 @@ -0,0 +1,69 @@
658 +/*
659 + * Device driver for MMC/SD cards driven over a GPIO bus.
660 + *
661 + * Licensed under the GNU/GPL version 2.
662 + */
663 +#ifndef LINUX_GPIOMMC_H_
664 +#define LINUX_GPIOMMC_H_
665 +
666 +#include <linux/types.h>
667 +
668 +
669 +#define GPIOMMC_MAX_NAMELEN 15
670 +#define GPIOMMC_MAX_NAMELEN_STR __stringify(GPIOMMC_MAX_NAMELEN)
671 +
672 +/**
673 + * struct gpiommc_pins - Hardware pin assignments
674 + *
675 + * @gpio_di: The GPIO number of the DATA IN pin
676 + * @gpio_do: The GPIO number of the DATA OUT pin
677 + * @gpio_clk: The GPIO number of the CLOCK pin
678 + * @gpio_cs: The GPIO number of the CHIPSELECT pin
679 + * @cs_activelow: If true, the chip is considered selected if @gpio_cs is low.
680 + */
681 +struct gpiommc_pins {
682 + unsigned int gpio_di;
683 + unsigned int gpio_do;
684 + unsigned int gpio_clk;
685 + unsigned int gpio_cs;
686 + bool cs_activelow;
687 +};
688 +
689 +/**
690 + * struct gpiommc_platform_data - Platform data for a MMC-over-SPI-GPIO device.
691 + *
692 + * @name: The unique name string of the device.
693 + * @pins: The hardware pin assignments.
694 + * @mode: The hardware mode. This is either SPI_MODE_0,
695 + * SPI_MODE_1, SPI_MODE_2 or SPI_MODE_3. See the SPI documentation.
696 + * @no_spi_delay: Do not use delays in the lowlevel SPI bitbanging code.
697 + * This is not standards compliant, but may be required for some
698 + * embedded machines to gain reasonable speed.
699 + * @max_bus_speed: The maximum speed of the SPI bus, in Hertz.
700 + */
701 +struct gpiommc_platform_data {
702 + char name[GPIOMMC_MAX_NAMELEN + 1];
703 + struct gpiommc_pins pins;
704 + u8 mode;
705 + bool no_spi_delay;
706 + unsigned int max_bus_speed;
707 +};
708 +
709 +/**
710 + * GPIOMMC_PLATDEV_NAME - The platform device name string.
711 + *
712 + * The name string that has to be used for platform_device_alloc
713 + * when allocating a gpiommc device.
714 + */
715 +#define GPIOMMC_PLATDEV_NAME "gpiommc"
716 +
717 +/**
718 + * gpiommc_next_id - Get another platform device ID number.
719 + *
720 + * This returns the next platform device ID number that has to be used
721 + * for platform_device_alloc. The ID is opaque and should not be used for
722 + * anything else.
723 + */
724 +int gpiommc_next_id(void);
725 +
726 +#endif /* LINUX_GPIOMMC_H_ */
727 Index: linux-2.6.25.17/Documentation/gpiommc.txt
728 ===================================================================
729 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
730 +++ linux-2.6.25.17/Documentation/gpiommc.txt 2008-10-18 23:32:54.000000000 +0200
731 @@ -0,0 +1,97 @@
732 +GPIOMMC - Driver for an MMC/SD card on a bitbanging GPIO SPI bus
733 +================================================================
734 +
735 +The gpiommc module hooks up the mmc_spi and spi_gpio modules for running an
736 +MMC or SD card on GPIO pins.
737 +
738 +Two interfaces for registering a new MMC/SD card device are provided:
739 +A static platform-device based mechanism and a dynamic configfs based interface.
740 +
741 +
742 +Registering devices via platform-device
743 +=======================================
744 +
745 +The platform-device interface is used for registering MMC/SD devices that are
746 +part of the hardware platform. This is most useful only for embedded machines
747 +with MMC/SD devices statically connected to the platform GPIO bus.
748 +
749 +The data structures are declared in <linux/mmc/gpiommc.h>.
750 +
751 +To register a new device, define an instance of struct gpiommc_platform_data.
752 +This structure holds any information about how the device is hooked up to the
753 +GPIO pins and what hardware modes the device supports. See the docbook-style
754 +documentation in the header file for more information on the struct fields.
755 +
756 +Then allocate a new instance of a platform device by doing:
757 +
758 + pdev = platform_device_alloc(GPIOMMC_PLATDEV_NAME, gpiommc_next_id());
759 +
760 +This will allocate the platform device data structures and hook it up to the
761 +gpiommc driver.
762 +Then add the gpiommc_platform_data to the platform device.
763 +
764 + err = platform_device_add_data(pdev, pdata, sizeof(struct gpiommc_platform_data));
765 +
766 +You may free the local instance of struct gpiommc_platform_data now. (So the
767 +struct may be allocated on the stack, too).
768 +Now simply register the platform device.
769 +
770 + err = platform_device_add(pdev);
771 +
772 +Done. The gpiommc probe routine will be invoked now and you should see a kernel
773 +log message for the added device.
774 +
775 +
776 +Registering devices via configfs
777 +================================
778 +
779 +MMC/SD cards connected via GPIO often are a pretty dynamic thing, as for example
780 +selfmade hacks for soldering an MMC/SD card to standard GPIO pins on embedded
781 +hardware are a common situation.
782 +So we provide a dynamic interface to conveniently handle adding and removing
783 +devices from userspace, without the need to recompile the kernel.
784 +
785 +The "gpiommc" subdirectory at the configfs mountpoint is used for handling
786 +the dynamic configuration.
787 +
788 +To create a new device, it must first be allocated with mkdir.
789 +The following command will allocate a device named "my_mmc":
790 + mkdir /config/gpiommc/my_mmc
791 +
792 +There are several configuration files available in the new
793 +/config/gpiommc/my_mmc/ directory:
794 +
795 +gpio_data_in = The SPI data-IN GPIO pin number.
796 +gpio_data_out = The SPI data-OUT GPIO pin number.
797 +gpio_clock = The SPI Clock GPIO pin number.
798 +gpio_chipselect = The SPI Chipselect GPIO pin number.
799 +gpio_chipselect_activelow = Boolean. If 0, Chipselect is active-HIGH.
800 + If 1, Chipselect is active-LOW.
801 +spi_mode = The SPI data mode. Can be 0-3.
802 +spi_delay = Enable all delays in the lowlevel bitbanging.
803 +max_bus_speed = The maximum SPI bus speed. In Hertz.
804 +
805 +register = Not a configuration parameter.
806 + Used to register the configured card
807 + with the kernel.
808 +
809 +The device must first get configured and then registered by writing "1" to
810 +the "register" file.
811 +The configuration parameters "gpio_data_in", "gpio_data_out", "gpio_clock"
812 +and "gpio_chipselect" are essential and _must_ be configured before writing
813 +"1" to the "register" file. The registration will fail, otherwise.
814 +
815 +The default values for the other parameters are:
816 +gpio_chipselect_activelow = 1 (CS active-LOW)
817 +spi_mode = 0 (SPI_MODE_0)
818 +spi_delay = 1 (enabled)
819 +max_bus_speed = 5000000 (5 Mhz)
820 +
821 +Configuration values can not be changed after registration. To unregister
822 +the device, write a "0" to the "register" file. The configuration can be
823 +changed again after unregistering.
824 +
825 +To completely remove the device, simply rmdir the directory
826 +(/config/gpiommc/my_mmc in this example).
827 +There's no need to first unregister the device before removing it. That will
828 +be done automatically.