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