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