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