This driver provides a sysfs interface to dynamically create
and destroy GPIO-based MMC/SD card interfaces. It also provides
a platform device interface API.
See Documentation/gpiommc.txt for details.
Signed-off-by: Michael Buesch <m...@bu3sch.de>
---
This driver is used in OpenWrt since quite some time, so please
consider for inclusion in mainline.
Index: linux-next/drivers/mmc/host/gpiommc.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-next/drivers/mmc/host/gpiommc.c 2008-07-18 21:54:05.000000000 +0200
@@ -0,0 +1,328 @@
+/*
+ * Driver an MMC/SD card on a bitbanging GPIO SPI bus.
+ * This module hooks up the mmc_spi and spi_gpio modules and also
+ * provides a sysfs interface.
+ *
+ * Copyright 2008 Michael Buesch <m...@bu3sch.de>
+ *
+ * Licensed under the GNU/GPL. See COPYING for details.
+ */
+
+#include <linux/mmc/gpiommc.h>
+#include <linux/platform_device.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/spi/spi_gpio.h>
+
+
+#define PFX "gpio-mmc: "
+#define GPIOMMC_MAX_NAMELEN_STR __stringify(GPIOMMC_MAX_NAMELEN)
+
+struct gpiommc_device {
+ struct platform_device *pdev;
+ struct platform_device *spi_pdev;
+ struct spi_board_info boardinfo;
+};
+
+
+MODULE_DESCRIPTION("GPIO based MMC driver");
+MODULE_AUTHOR("Michael Buesch");
+MODULE_LICENSE("GPL");
+
+
+static int gpiommc_boardinfo_setup(struct spi_board_info *bi,
+ struct spi_master *master,
+ void *data)
+{
+ struct gpiommc_device *d = data;
+ struct gpiommc_platform_data *pdata = d->pdev->dev.platform_data;
+
+ /* Bind the SPI master to the MMC-SPI host driver. */
+ strlcpy(bi->modalias, "mmc_spi", sizeof(bi->modalias));
+
+ bi->max_speed_hz = pdata->max_bus_speed;
+ bi->bus_num = master->bus_num;
+ bi->mode = pdata->mode;
+
+ return 0;
+}
+
+static int gpiommc_probe(struct platform_device *pdev)
+{
+ struct gpiommc_platform_data *mmc_pdata = pdev->dev.platform_data;
+ struct spi_gpio_platform_data spi_pdata;
+ struct gpiommc_device *d;
+ int err;
+
+ err = -ENXIO;
+ if (!mmc_pdata)
+ goto error;
+
+ /* Allocate the GPIO-MMC device */
+ err = -ENOMEM;
+ d = kzalloc(sizeof(*d), GFP_KERNEL);
+ if (!d)
+ goto error;
+ d->pdev = pdev;
+
+ /* Create the SPI-GPIO device */
+ d->spi_pdev = platform_device_alloc(SPI_GPIO_PLATDEV_NAME,
+ spi_gpio_next_id());
+ if (!d->spi_pdev)
+ goto err_free_d;
+
+ memset(&spi_pdata, 0, sizeof(spi_pdata));
+ spi_pdata.pin_clk = mmc_pdata->pins.gpio_clk;
+ spi_pdata.pin_miso = mmc_pdata->pins.gpio_do;
+ spi_pdata.pin_mosi = mmc_pdata->pins.gpio_di;
+ spi_pdata.pin_cs = mmc_pdata->pins.gpio_cs;
+ spi_pdata.cs_activelow = mmc_pdata->pins.cs_activelow;
+ spi_pdata.no_spi_delay = mmc_pdata->no_spi_delay;
+ spi_pdata.boardinfo_setup = gpiommc_boardinfo_setup;
+ spi_pdata.boardinfo_setup_data = d;
+
+ err = platform_device_add_data(d->spi_pdev, &spi_pdata,
+ sizeof(spi_pdata));
+ if (err)
+ goto err_free_pdev;
+ err = platform_device_add(d->spi_pdev);
+ if (err)
+ goto err_free_pdata;
+ platform_set_drvdata(pdev, d);
+
+ printk(KERN_INFO PFX "MMC-Card \"%s\" "
+ "attached to GPIO pins di=%u, do=%u, clk=%u, cs=%u\n",
+ mmc_pdata->name, mmc_pdata->pins.gpio_di,
+ mmc_pdata->pins.gpio_do,
+ mmc_pdata->pins.gpio_clk,
+ mmc_pdata->pins.gpio_cs);
+
+ return 0;
+
+err_free_pdata:
+ kfree(d->spi_pdev->dev.platform_data);
+ d->spi_pdev->dev.platform_data = NULL;
+err_free_pdev:
+ platform_device_put(d->spi_pdev);
+err_free_d:
+ kfree(d);
+error:
+ return err;
+}
+
+static int gpiommc_remove(struct platform_device *pdev)
+{
+ struct gpiommc_device *d = platform_get_drvdata(pdev);
+ struct gpiommc_platform_data *pdata = d->pdev->dev.platform_data;
+
+ platform_device_unregister(d->spi_pdev);
+ printk(KERN_INFO PFX "GPIO based MMC-Card \"%s\" removed\n", pdata->name);
+ platform_device_put(d->spi_pdev);
+
+ return 0;
+}
+
+/* Wrapper for the platform data with context data for the sysfs interface. */
+struct gpiommc_sysfs_platform_data {
+ struct gpiommc_platform_data p; /* Keep as first element */
+
+ /* The platform device that we allocated. */
+ struct platform_device *pdev;
+ /* gpiommc_sysfs_list */
+ struct list_head list;
+};
+
+static LIST_HEAD(gpiommc_sysfs_list);
+static DEFINE_MUTEX(gpiommc_sysfs_mutex);
+
+static struct gpiommc_sysfs_platform_data *gpiommc_sysfs_find_dev(const char *name)
+{
+ struct gpiommc_sysfs_platform_data *pdata;
+
+ list_for_each_entry(pdata, &gpiommc_sysfs_list, list) {
+ if (strcmp(pdata->p.name, name) == 0)
+ return pdata;
+ }
+
+ return NULL;
+}
+
+static ssize_t gpiommc_add_store(struct device_driver *drv,
+ const char *buf, size_t count)
+{
+ int res, err;
+ struct gpiommc_sysfs_platform_data pdata_local, *pdata;
+ struct platform_device *pdev;
+ unsigned int no_spi_delay = 0, mode = 0, csactivelow = 0;
+
+ mutex_lock(&gpiommc_sysfs_mutex);
+
+ pdata = &pdata_local;
+ memset(pdata, 0, sizeof(*pdata));
+
+ err = -EINVAL;
+ res = sscanf(buf, "%" GPIOMMC_MAX_NAMELEN_STR "s %u %u %u %u %u %u %u %u",
+ pdata->p.name,
+ &pdata->p.pins.gpio_di,
+ &pdata->p.pins.gpio_do,
+ &pdata->p.pins.gpio_clk,
+ &pdata->p.pins.gpio_cs,
+ &mode,
+ &pdata->p.max_bus_speed,
+ &no_spi_delay,
+ &csactivelow);
+ pdata->p.mode = mode;
+ pdata->p.no_spi_delay = !!no_spi_delay;
+ pdata->p.pins.cs_activelow = !!csactivelow;
+ if (res < 9)
+ pdata->p.pins.cs_activelow = 1; /* Default: CS = activelow */
+ if (res < 8)
+ pdata->p.no_spi_delay = 0; /* Default: Delay turned on */
+ if (res < 7)
+ pdata->p.max_bus_speed = 5000000; /* Default: 5Mhz */
+ if (res < 6)
+ pdata->p.mode = 0; /* Default: SPI mode 0 */
+ if (res < 5 || res > 9)
+ goto out; /* First 5 args are mandatory. */
+
+ /* Convert mode so that the SPI subsystem does understand it. */
+ switch (pdata->p.mode) {
+ case 0:
+ pdata->p.mode = SPI_MODE_0;
+ break;
+ case 1:
+ pdata->p.mode = SPI_MODE_1;
+ break;
+ case 2:
+ pdata->p.mode = SPI_MODE_2;
+ break;
+ case 3:
+ pdata->p.mode = SPI_MODE_3;
+ break;
+ default:
+ goto out; /* Invalid mode */
+ }
+
+ err = -EEXIST;
+ if (gpiommc_sysfs_find_dev(pdata->p.name))
+ goto out;
+
+ err = -ENOMEM;
+ pdev = platform_device_alloc(GPIOMMC_PLATDEV_NAME, gpiommc_next_id());
+ if (!pdev)
+ goto out;
+
+ err = platform_device_add_data(pdev, pdata, sizeof(*pdata));
+ if (err)
+ goto err_free_pdev;
+ pdata = pdev->dev.platform_data;
+
+ err = platform_device_add(pdev);
+ if (err)
+ goto err_free_pdev;
+
+ pdata->pdev = pdev;
+ INIT_LIST_HEAD(&pdata->list);
+ list_add(&pdata->list, &gpiommc_sysfs_list);
+
+ err = 0;
+out:
+ mutex_unlock(&gpiommc_sysfs_mutex);
+
+ return err ? err : count;
+
+err_free_pdev:
+ platform_device_put(pdev);
+ goto out;
+}
+
+static ssize_t gpiommc_remove_store(struct device_driver *drv,
+ const char *buf, size_t count)
+{
+ struct gpiommc_sysfs_platform_data *pdata;
+ int err;
+
+ mutex_lock(&gpiommc_sysfs_mutex);
+
+ err = -ENODEV;
+ pdata = gpiommc_sysfs_find_dev(buf);
+ if (!pdata)
+ goto out;
+
+ list_del(&pdata->list);
+ platform_device_unregister(pdata->pdev);
+
+out:
+ mutex_unlock(&gpiommc_sysfs_mutex);
+
+ return err ? err : count;
+}
+
+static DRIVER_ATTR(add, 0200,
+ NULL, gpiommc_add_store);
+static DRIVER_ATTR(remove, 0200,
+ NULL, gpiommc_remove_store);
+
+static struct platform_driver gpiommc_plat_driver = {
+ .probe = gpiommc_probe,
+ .remove = gpiommc_remove,
+ .driver = {
+ .name = GPIOMMC_PLATDEV_NAME,
+ .owner = THIS_MODULE,
+ },
+};
+
+int gpiommc_next_id(void)
+{
+ static atomic_t counter = ATOMIC_INIT(-1);
+
+ return atomic_inc_return(&counter);
+}
+EXPORT_SYMBOL(gpiommc_next_id);
+
+static int __init gpiommc_modinit(void)
+{
+ int err;
+
+ err = platform_driver_register(&gpiommc_plat_driver);
+ if (err)
+ return err;
+ err = driver_create_file(&gpiommc_plat_driver.driver,
+ &driver_attr_add);
+ if (err)
+ goto err_drv_unreg;
+ err = driver_create_file(&gpiommc_plat_driver.driver,
+ &driver_attr_remove);
+ if (err)
+ goto err_remove_add;
+
+ return 0;
+
+err_remove_add:
+ driver_remove_file(&gpiommc_plat_driver.driver,
+ &driver_attr_add);
+err_drv_unreg:
+ platform_driver_unregister(&gpiommc_plat_driver);
+ return err;
+}
+module_init(gpiommc_modinit);
+
+static void __exit gpiommc_modexit(void)
+{
+ struct gpiommc_sysfs_platform_data *pdata, *pdata_tmp;
+
+ driver_remove_file(&gpiommc_plat_driver.driver,
+ &driver_attr_remove);
+ driver_remove_file(&gpiommc_plat_driver.driver,
+ &driver_attr_add);
+
+ mutex_lock(&gpiommc_sysfs_mutex);
+ list_for_each_entry_safe(pdata, pdata_tmp, &gpiommc_sysfs_list, list) {
+ list_del(&pdata->list);
+ platform_device_unregister(pdata->pdev);
+ }
+ mutex_unlock(&gpiommc_sysfs_mutex);
+
+ platform_driver_unregister(&gpiommc_plat_driver);
+}
+module_exit(gpiommc_modexit);
Index: linux-next/drivers/mmc/host/Kconfig
===================================================================
--- linux-next.orig/drivers/mmc/host/Kconfig 2008-07-18 21:52:46.000000000 +0200
+++ linux-next/drivers/mmc/host/Kconfig 2008-07-18 21:57:08.000000000 +0200
@@ -164,3 +164,23 @@ config MMC_S3C
If unsure, say N.
+config GPIOMMC
+ tristate "MMC/SD over GPIO-based SPI"
+ depends on MMC && MMC_SPI && SPI_GPIO
+ help
+ This driver hooks up the mmc_spi and spi_gpio modules so that
+ MMC/SD cards can be used on a GPIO based bus by bitbanging
+ the SPI protocol in software.
+
+ This driver provides a sysfs interface to dynamically create
+ and destroy GPIO-based MMC/SD card interfaces. It also provides
+ a platform device interface API.
+ See Documentation/gpiommc.txt for details.
+
+ The module will be called gpiommc.
+
+ If unsure, say N.
+
+config MMC_S3C
+ tristate "Samsung S3C SD/MMC Card Interface support"
+ depends on ARCH_S3C2410 && MMC
Index: linux-next/drivers/mmc/host/Makefile
===================================================================
--- linux-next.orig/drivers/mmc/host/Makefile 2008-07-18 21:52:46.000000000 +0200
+++ linux-next/drivers/mmc/host/Makefile 2008-07-18 21:54:19.000000000 +0200
@@ -20,3 +20,4 @@ obj-$(CONFIG_MMC_ATMELMCI) += atmel-mci.
obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
obj-$(CONFIG_MMC_SPI) += mmc_spi.o
obj-$(CONFIG_MMC_S3C) += s3cmci.o
+obj-$(CONFIG_GPIOMMC) += gpiommc.o
Index: linux-next/include/linux/mmc/gpiommc.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-next/include/linux/mmc/gpiommc.h 2008-07-18 21:54:05.000000000 +0200
@@ -0,0 +1,62 @@
+/*
+ * Device driver for MMC/SD cards driven over a GPIO bus.
+ *
+ * Copyright (c) 2008 Michael Buesch
+ *
+ * Licensed under the GNU/GPL version 2.
+ */
+#ifndef LINUX_GPIOMMC_H_
+#define LINUX_GPIOMMC_H_
+
+#include <linux/types.h>
+
+
+#define GPIOMMC_MAX_NAMELEN 15
+
+/** struct gpiommc_pins - Hardware pin assignments
+ * @gpio_di: The GPIO number of the DATA IN pin
+ * @gpio_do: The GPIO number of the DATA OUT pin
+ * @gpio_clk: The GPIO number of the CLOCK pin
+ * @gpio_cs: The GPIO number of the CHIPSELECT pin
+ * @cs_activelow: If true, the chip is considered selected if @gpio_cs is low.
+ */
+struct gpiommc_pins {
+ unsigned int gpio_di;
+ unsigned int gpio_do;
+ unsigned int gpio_clk;
+ unsigned int gpio_cs;
+ bool cs_activelow;
+};
+
+/** struct gpiommc_platform_data - Platform data for a MMC-over-SPI-GPIO device.
+ * @name: The unique name string of the device.
+ * @pins: The hardware pin assignments.
+ * @mode: The hardware mode. This is either SPI_MODE_0,
+ * SPI_MODE_1, SPI_MODE_2 or SPI_MODE_3. See the SPI documentation.
+ * @no_spi_delay: Do not use delays in the lowlevel SPI bitbanging code.
+ * This is not standards compliant, but may be required for some
+ * embedded machines to gain reasonable speed.
+ * @max_bus_speed: The maximum speed of the SPI bus, in Hertz.
+ */
+struct gpiommc_platform_data {
+ char name[GPIOMMC_MAX_NAMELEN + 1];
+ struct gpiommc_pins pins;
+ u8 mode;
+ bool no_spi_delay;
+ unsigned int max_bus_speed;
+};
+
+/** GPIOMMC_PLATDEV_NAME - The platform device name string.
+ * The name string that has to be used for platform_device_alloc
+ * when allocating a gpiommc device.
+ */
+#define GPIOMMC_PLATDEV_NAME "gpiommc"
+
+/** gpiommc_next_id - Get another platform device ID number.
+ * This returns the next platform device ID number that has to be used
+ * for platform_device_alloc. The ID is opaque and should not be used for
+ * anything else.
+ */
+int gpiommc_next_id(void);
+
+#endif /* LINUX_GPIOMMC_H_ */
Index: linux-next/Documentation/gpiommc.txt
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-next/Documentation/gpiommc.txt 2008-07-18 21:54:05.000000000 +0200
@@ -0,0 +1,96 @@
+GPIOMMC - Driver for an MMC/SD card on a bitbanging GPIO SPI bus
+================================================================
+
+The gpiommc module hooks up the mmc_spi and spi_gpio modules for running an
+MMC or SD card on GPIO pins.
+
+Two interfaces for registering a new MMC/SD card device are provided.
+A static platform-device based mechanism and a dynamic sysfs based interface.
+
+
+Registering devices via platform-device
+=======================================
+
+The platform-device interface is used for registering MMC/SD devices that are
+part of the hardware platform. This is most useful only for embedded machines
+with MMC/SD devices statically connected to the platform GPIO bus.
+
+The data structures are declared in <linux/mmc/gpiommc.h>
+
+To register a new device, define an instance of struct gpiommc_platform_data.
+This structure holds any information about how the device is hooked up to the
+GPIO pins and what hardware modes the device supports. See the docbook-style
+documentation in the header file for more information on the struct fields.
+
+Then allocate a new instance of a platform device by doing:
+
+ pdev = platform_device_alloc(GPIOMMC_PLATDEV_NAME, gpiommc_next_id());
+
+This will allocate the platform device data structures and hook it up to the
+gpiommc driver.
+Then add the gpiommc_platform_data to the platform device.
+
+ err = platform_device_add_data(pdev, pdata, sizeof(struct gpiommc_platform_data));
+
+You may free the local instance of struct gpiommc_platform_data now.
+Now simply register the platform device.
+
+ err = platform_device_add(pdev);
+
+Done. The gpiommc probe routine should be called and you should see a dmesg
+message for the added device.
+
+
+Registering devices via sysfs
+=============================
+
+MMC/SD cards connected via GPIO often are a pretty dynamic thing. For example
+selfmade hacks for soldering an MMC/SD card to standard GPIO pins on embedded
+hardware are a common situation.
+So we provide a dynamic interface to conveniently handle adding and removing
+devices from userspace, without the need to recompile the kernel.
+
+There are two sysfs files responsible for that:
+export ADD=/sys/bus/platform/drivers/gpiommc/add
+export REMOVE=/sys/bus/platform/drivers/gpiommc/remove
+
+To add a new device, simply echo the configuration string to the "add" file.
+The config string is composed out of the following elements:
+
+DEVNAME DIpin DOpin CLKpin CSpin SPIMODE MAXBUSSPEED NO_SPI_DELAY CSACTIVELOW
+
+DEVNAME is a unique name string for the device.
+DIpin is the SPI DI GPIO pin.
+DOpin is the SPI DO GPIO pin.
+CLKpin is the SPI CLOCK GPIO pin.
+CSpin is the SPI CHIPSELECT GPIO pin.
+SPIMODE is the hardware mode the device will run at. Can be 0-3.
+MAXBUSSPEED is the maximum bus speed in Hertz.
+NO_SPI_DELAY can be 1 or 0. If it is 1, then the lowlevel SPI delay
+will not be performed. This is not standards compliant, but may be required
+to gain reasonable speeds on embedded hardware.
+CSACTIVELOW can be 1 or 0. If it is 1, the chip is considered to be selected, if CS
+is at a logical 0.
+
+Note that the elements SPIMODE, MAXBUSSPEED and NO_SPI_DELAY are optional
+and can be omitted.
+SPIMODE will default to 0.
+MAXBUSSSPEED will default to 5Mhz.
+NO_SPI_DELAY will default to 0.
+CSACTIVELOW will default to 1.
+
+Example:
+
+ echo -n "my_device 5 4 3 7 0 1000000 1" > $ADD
+
+This will add a new device called "my_device" with the GPIO pins assigned as
+DI=5, DO=4, CLK=3, CS=7
+The hardware mode will be SPI_MODE_0.
+The maximum bus speed will be 1000000 Hz (1Mhz)
+And the explicit SPI delay at the lowlevel bitbang loop will be switched off.
+
+To remove a device, simply echo the device name string to the "remove" file.
+
+Example:
+
+ echo -n "my_device" > $REMOVE
Index: linux-next/MAINTAINERS
===================================================================
--- linux-next.orig/MAINTAINERS 2008-07-18 21:54:00.000000000 +0200
+++ linux-next/MAINTAINERS 2008-07-18 21:54:05.000000000 +0200
@@ -1875,6 +1875,11 @@ L: gigaset30...@lists.sourceforge.
W: http://gigaset307x.sourceforge.net/
S: Maintained
+GPIOMMC DRIVER
+P: Michael Buesch
+M: m...@bu3sch.de
+S: Maintained
+
HARDWARE MONITORING
P: Mark M. Hoffman
M: mhof...@lightlink.com
--
Greetings Michael.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
> This driver hooks up the mmc_spi and spi_gpio modules so that
> MMC/SD cards can be used on a GPIO based bus by bitbanging
> the SPI protocol in software.
>
> This driver provides a sysfs interface to dynamically create
> and destroy GPIO-based MMC/SD card interfaces. It also provides
> a platform device interface API.
> See Documentation/gpiommc.txt for details.
>
> Signed-off-by: Michael Buesch <m...@bu3sch.de>
>
> ---
>
> This driver is used in OpenWrt since quite some time, so please
> consider for inclusion in mainline.
Full diffstat here would be Good.
Use defined symbols instead of inline constants (for 0200).
> Index: linux-next/include/linux/mmc/gpiommc.h
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ linux-next/include/linux/mmc/gpiommc.h 2008-07-18 21:54:05.000000000 +0200
> @@ -0,0 +1,62 @@
> +/*
> + * Device driver for MMC/SD cards driven over a GPIO bus.
> + *
> + * Copyright (c) 2008 Michael Buesch
> + *
> + * Licensed under the GNU/GPL version 2.
> + */
> +#ifndef LINUX_GPIOMMC_H_
> +#define LINUX_GPIOMMC_H_
> +
> +#include <linux/types.h>
> +
> +
> +#define GPIOMMC_MAX_NAMELEN 15
> +
> +/** struct gpiommc_pins - Hardware pin assignments
All of these kernel-doc blocks should be like:
/**
* struct gpiommc_pines - Hardware pin assignments
are provided:
a static
> +A static platform-device based mechanism and a dynamic sysfs based interface.
> +
> +
> +Registering devices via platform-device
> +=======================================
> +
> +The platform-device interface is used for registering MMC/SD devices that are
> +part of the hardware platform. This is most useful only for embedded machines
> +with MMC/SD devices statically connected to the platform GPIO bus.
> +
> +The data structures are declared in <linux/mmc/gpiommc.h>
end sentence with '.'
> +
> +To register a new device, define an instance of struct gpiommc_platform_data.
> +This structure holds any information about how the device is hooked up to the
> +GPIO pins and what hardware modes the device supports. See the docbook-style
> +documentation in the header file for more information on the struct fields.
> +
> +Then allocate a new instance of a platform device by doing:
> +
> + pdev = platform_device_alloc(GPIOMMC_PLATDEV_NAME, gpiommc_next_id());
> +
> +This will allocate the platform device data structures and hook it up to the
> +gpiommc driver.
> +Then add the gpiommc_platform_data to the platform device.
> +
> + err = platform_device_add_data(pdev, pdata, sizeof(struct gpiommc_platform_data));
> +
> +You may free the local instance of struct gpiommc_platform_data now.
> +Now simply register the platform device.
> +
> + err = platform_device_add(pdev);
> +
> +Done. The gpiommc probe routine should be called and you should see a dmesg
s/dmesg/kernel log/ (?)
> +message for the added device.
> +
> +
> +Registering devices via sysfs
> +=============================
> +
> +MMC/SD cards connected via GPIO often are a pretty dynamic thing. For example
> +selfmade hacks for soldering an MMC/SD card to standard GPIO pins on embedded
> +hardware are a common situation.
I think that the two sentences above/below would be better if joined with a comma...
Would this be better done via configfs? sysfs files are supposed to be
single-value files.
> +Note that the elements SPIMODE, MAXBUSSPEED and NO_SPI_DELAY are optional
> +and can be omitted.
> +SPIMODE will default to 0.
> +MAXBUSSSPEED will default to 5Mhz.
> +NO_SPI_DELAY will default to 0.
> +CSACTIVELOW will default to 1.
> +
> +Example:
> +
> + echo -n "my_device 5 4 3 7 0 1000000 1" > $ADD
> +
> +This will add a new device called "my_device" with the GPIO pins assigned as
> +DI=5, DO=4, CLK=3, CS=7
end sentence with '.'
> +The hardware mode will be SPI_MODE_0.
> +The maximum bus speed will be 1000000 Hz (1Mhz)
ditto
> +And the explicit SPI delay at the lowlevel bitbang loop will be switched off.
> +
> +To remove a device, simply echo the device name string to the "remove" file.
> +
> +Example:
> +
> + echo -n "my_device" > $REMOVE
---
~Randy
Linux Plumbers Conference, 17-19 September 2008, Portland, Oregon USA
http://linuxplumbersconf.org/
On Saturday 19 July 2008 00:10:37 Randy Dunlap wrote:
> > +To add a new device, simply echo the configuration string to the "add" file.
> > +The config string is composed out of the following elements:
> > +
> > +DEVNAME DIpin DOpin CLKpin CSpin SPIMODE MAXBUSSPEED NO_SPI_DELAY CSACTIVELOW
> > +
> > +DEVNAME is a unique name string for the device.
> > +DIpin is the SPI DI GPIO pin.
> > +DOpin is the SPI DO GPIO pin.
> > +CLKpin is the SPI CLOCK GPIO pin.
> > +CSpin is the SPI CHIPSELECT GPIO pin.
> > +SPIMODE is the hardware mode the device will run at. Can be 0-3.
> > +MAXBUSSPEED is the maximum bus speed in Hertz.
> > +NO_SPI_DELAY can be 1 or 0. If it is 1, then the lowlevel SPI delay
> > +will not be performed. This is not standards compliant, but may be required
> > +to gain reasonable speeds on embedded hardware.
> > +CSACTIVELOW can be 1 or 0. If it is 1, the chip is considered to be selected, if CS
> > +is at a logical 0.
> > +
>
> Would this be better done via configfs? sysfs files are supposed to be
> single-value files.
Well, I really want to avoid over-engineering this thing.
I thought about using configfs, but that would require to keep lots of state
information across the operations.
So one would have to allocate a device with mkdir. Then configure the parameters.
And then somehow tell the kernel to register it. State has to be maintained over
this time and I'm not sure how that "register" operation would look like.
Writing a "1" to a "register" file? So why not write all config parameters
to an "add" file and be done with all the stuff. ;)
It all depends on how you define "one thing per file", IMO.
This "add" file does one thing. It creates a device. We must, of course, pass
some configuration parameters, too.
--
Greetings Michael.
We have precidence with this for the device id being "added" to a driver
at run time in PCI and USB. Not that I really like this, I do think
configfs would be better to do this with here instead of sysfs.
That being said, as this is a new sysfs file, please break this
documentation up into a file in the Documentation/ABI directory instead
of here.
thanks,
greg k-h
Ok, let us keep this stuff some time in the experimental -mm tree
and I will think about configfs again. I don't really like that sysfs "add"
file, too. But I can't say if I like configfs more.
I probably need to play with configfs a little bit to find out what's best.
One advantage is that you can easily add more config stuff later without
the risk of breaking stuff. That's quite an advantage, too...
But that "how do we register the device after allocating it?" does worry
me a little bit. Any ideas on how to implement allocate/config/register
in configfs?
--
Greetings Michael.
This driver provides a configfs interface to dynamically create
and destroy GPIO-based MMC/SD card interfaces. It also provides
a platform device interface API.
See Documentation/gpiommc.txt for details.
Signed-off-by: Michael Buesch <m...@bu3sch.de>
---
This driver is used in OpenWrt since quite some time, so please
consider for inclusion in mainline.
Changes since v2: The sysfs interface has been replaced by a configfs interface.
Although I don't really like the bloat this adds (this is a driver for embedded
machines), I do like the much cleaner interface and I think it's worth the bloat.
Index: linux-next/drivers/mmc/host/gpiommc.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-next/drivers/mmc/host/gpiommc.c 2008-07-20 21:40:47.000000000 +0200
@@ -0,0 +1,608 @@
+/*
+ * Driver an MMC/SD card on a bitbanging GPIO SPI bus.
+ * This module hooks up the mmc_spi and spi_gpio modules and also
+ * provides a configfs interface.
+ *
+ * Copyright 2008 Michael Buesch <m...@bu3sch.de>
+ *
+ * Licensed under the GNU/GPL. See COPYING for details.
+ */
+
+#include <linux/mmc/gpiommc.h>
+#include <linux/platform_device.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/spi/spi_gpio.h>
+#include <linux/configfs.h>
+#include <linux/gpio.h>
+#include <asm/atomic.h>
+
+
+#define PFX "gpio-mmc: "
+
+#ifdef CONFIG_MMC_SPI_MODULE
+ err = request_module("mmc_spi");
+ if (err) {
+ printk(KERN_WARNING PFX
+ "Failed to request mmc_spi module.\n");
+ }
+#endif /* CONFIG_MMC_SPI_MODULE */
+ pdata->name);
+ platform_device_put(d->spi_pdev);
+
+ return 0;
+}
+
+#ifdef CONFIG_GPIOMMC_CONFIGFS
+
+/* A device that was created through configfs */
+struct gpiommc_configfs_device {
+ struct config_item item;
+ /* The platform device, after registration. */
+ struct platform_device *pdev;
+ /* The configuration */
+ struct gpiommc_platform_data pdata;
+};
+
+#define GPIO_INVALID -1
+
+static inline bool gpiommc_is_registered(struct gpiommc_configfs_device *dev)
+{
+ return (dev->pdev != NULL);
+}
+
+static inline struct gpiommc_configfs_device *ci_to_gpiommc(struct config_item *item)
+{
+ return item ? container_of(item, struct gpiommc_configfs_device, item) : NULL;
+}
+
+static struct configfs_attribute gpiommc_attr_DI = {
+ .ca_owner = THIS_MODULE,
+ .ca_name = "gpio_data_in",
+ .ca_mode = S_IRUGO | S_IWUSR,
+};
+
+static struct configfs_attribute gpiommc_attr_DO = {
+ .ca_owner = THIS_MODULE,
+ .ca_name = "gpio_data_out",
+ .ca_mode = S_IRUGO | S_IWUSR,
+};
+
+static struct configfs_attribute gpiommc_attr_CLK = {
+ .ca_owner = THIS_MODULE,
+ .ca_name = "gpio_clock",
+ .ca_mode = S_IRUGO | S_IWUSR,
+};
+
+static struct configfs_attribute gpiommc_attr_CS = {
+ .ca_owner = THIS_MODULE,
+ .ca_name = "gpio_chipselect",
+ .ca_mode = S_IRUGO | S_IWUSR,
+};
+
+static struct configfs_attribute gpiommc_attr_CS_activelow = {
+ .ca_owner = THIS_MODULE,
+ .ca_name = "gpio_chipselect_activelow",
+ .ca_mode = S_IRUGO | S_IWUSR,
+};
+
+static struct configfs_attribute gpiommc_attr_spimode = {
+ .ca_owner = THIS_MODULE,
+ .ca_name = "spi_mode",
+ .ca_mode = S_IRUGO | S_IWUSR,
+};
+
+static struct configfs_attribute gpiommc_attr_spidelay = {
+ .ca_owner = THIS_MODULE,
+ .ca_name = "spi_delay",
+ .ca_mode = S_IRUGO | S_IWUSR,
+};
+
+static struct configfs_attribute gpiommc_attr_max_bus_speed = {
+ .ca_owner = THIS_MODULE,
+ .ca_name = "max_bus_speed",
+ .ca_mode = S_IRUGO | S_IWUSR,
+};
+
+static struct configfs_attribute gpiommc_attr_register = {
+ .ca_owner = THIS_MODULE,
+ .ca_name = "register",
+ .ca_mode = S_IRUGO | S_IWUSR,
+};
+
+static struct configfs_attribute *gpiommc_config_attrs[] = {
+ &gpiommc_attr_DI,
+ &gpiommc_attr_DO,
+ &gpiommc_attr_CLK,
+ &gpiommc_attr_CS,
+ &gpiommc_attr_CS_activelow,
+ &gpiommc_attr_spimode,
+ &gpiommc_attr_spidelay,
+ &gpiommc_attr_max_bus_speed,
+ &gpiommc_attr_register,
+ NULL,
+};
+
+static ssize_t gpiommc_config_attr_show(struct config_item *item,
+ struct configfs_attribute *attr,
+ char *page)
+{
+ struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
+ ssize_t count = 0;
+ unsigned int gpio;
+ int err = 0;
+
+ if (attr == &gpiommc_attr_DI) {
+ gpio = dev->pdata.pins.gpio_di;
+ if (gpio == GPIO_INVALID)
+ count = snprintf(page, PAGE_SIZE, "not configured\n");
+ else
+ count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
+ goto out;
+ }
+ if (attr == &gpiommc_attr_DO) {
+ gpio = dev->pdata.pins.gpio_do;
+ if (gpio == GPIO_INVALID)
+ count = snprintf(page, PAGE_SIZE, "not configured\n");
+ else
+ count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
+ goto out;
+ }
+ if (attr == &gpiommc_attr_CLK) {
+ gpio = dev->pdata.pins.gpio_clk;
+ if (gpio == GPIO_INVALID)
+ count = snprintf(page, PAGE_SIZE, "not configured\n");
+ else
+ count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
+ goto out;
+ }
+ if (attr == &gpiommc_attr_CS) {
+ gpio = dev->pdata.pins.gpio_cs;
+ if (gpio == GPIO_INVALID)
+ count = snprintf(page, PAGE_SIZE, "not configured\n");
+ else
+ count = snprintf(page, PAGE_SIZE, "%u\n", gpio);
+ goto out;
+ }
+ if (attr == &gpiommc_attr_CS_activelow) {
+ count = snprintf(page, PAGE_SIZE, "%u\n",
+ dev->pdata.pins.cs_activelow);
+ goto out;
+ }
+ if (attr == &gpiommc_attr_spimode) {
+ count = snprintf(page, PAGE_SIZE, "%u\n",
+ dev->pdata.mode);
+ goto out;
+ }
+ if (attr == &gpiommc_attr_spidelay) {
+ count = snprintf(page, PAGE_SIZE, "%u\n",
+ !dev->pdata.no_spi_delay);
+ goto out;
+ }
+ if (attr == &gpiommc_attr_max_bus_speed) {
+ count = snprintf(page, PAGE_SIZE, "%u\n",
+ dev->pdata.max_bus_speed);
+ goto out;
+ }
+ if (attr == &gpiommc_attr_register) {
+ count = snprintf(page, PAGE_SIZE, "%u\n",
+ gpiommc_is_registered(dev));
+ goto out;
+ }
+ WARN_ON(1);
+ err = -ENOSYS;
+out:
+ return err ? err : count;
+}
+
+static int gpiommc_do_register(struct gpiommc_configfs_device *dev,
+ const char *name)
+{
+ int err;
+
+ if (gpiommc_is_registered(dev))
+ return 0;
+
+ if (!gpio_is_valid(dev->pdata.pins.gpio_di) ||
+ !gpio_is_valid(dev->pdata.pins.gpio_do) ||
+ !gpio_is_valid(dev->pdata.pins.gpio_clk) ||
+ !gpio_is_valid(dev->pdata.pins.gpio_cs)) {
+ printk(KERN_ERR PFX
+ "configfs: Invalid GPIO pin number(s)\n");
+ return -EINVAL;
+ }
+
+ strlcpy(dev->pdata.name, name,
+ sizeof(dev->pdata.name));
+
+ dev->pdev = platform_device_alloc(GPIOMMC_PLATDEV_NAME,
+ gpiommc_next_id());
+ if (!dev->pdev)
+ return -ENOMEM;
+ err = platform_device_add_data(dev->pdev, &dev->pdata,
+ sizeof(dev->pdata));
+ if (err) {
+ platform_device_put(dev->pdev);
+ return err;
+ }
+ err = platform_device_add(dev->pdev);
+ if (err) {
+ platform_device_put(dev->pdev);
+ return err;
+ }
+
+ return 0;
+}
+
+static void gpiommc_do_unregister(struct gpiommc_configfs_device *dev)
+{
+ if (!gpiommc_is_registered(dev))
+ return;
+
+ platform_device_unregister(dev->pdev);
+ dev->pdev = NULL;
+}
+
+static ssize_t gpiommc_config_attr_store(struct config_item *item,
+ struct configfs_attribute *attr,
+ const char *page, size_t count)
+{
+ struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
+ int err = -EINVAL;
+ unsigned long data;
+
+ if (attr == &gpiommc_attr_register) {
+ err = strict_strtoul(page, 10, &data);
+ if (err)
+ goto out;
+ err = -EINVAL;
+ if (data == 1)
+ err = gpiommc_do_register(dev, item->ci_name);
+ if (data == 0) {
+ gpiommc_do_unregister(dev);
+ err = 0;
+ }
+ goto out;
+ }
+
+ if (gpiommc_is_registered(dev)) {
+ /* The rest of the config parameters can only be set
+ * as long as the device is not registered, yet. */
+ err = -EBUSY;
+ goto out;
+ }
+
+ if (attr == &gpiommc_attr_DI) {
+ err = strict_strtoul(page, 10, &data);
+ if (err)
+ goto out;
+ err = -EINVAL;
+ if (!gpio_is_valid(data))
+ goto out;
+ dev->pdata.pins.gpio_di = data;
+ err = 0;
+ goto out;
+ }
+ if (attr == &gpiommc_attr_DO) {
+ err = strict_strtoul(page, 10, &data);
+ if (err)
+ goto out;
+ err = -EINVAL;
+ if (!gpio_is_valid(data))
+ goto out;
+ dev->pdata.pins.gpio_do = data;
+ err = 0;
+ goto out;
+ }
+ if (attr == &gpiommc_attr_CLK) {
+ err = strict_strtoul(page, 10, &data);
+ if (err)
+ goto out;
+ err = -EINVAL;
+ if (!gpio_is_valid(data))
+ goto out;
+ dev->pdata.pins.gpio_clk = data;
+ err = 0;
+ goto out;
+ }
+ if (attr == &gpiommc_attr_CS) {
+ err = strict_strtoul(page, 10, &data);
+ if (err)
+ goto out;
+ err = -EINVAL;
+ if (!gpio_is_valid(data))
+ goto out;
+ dev->pdata.pins.gpio_cs = data;
+ err = 0;
+ goto out;
+ }
+ if (attr == &gpiommc_attr_CS_activelow) {
+ err = strict_strtoul(page, 10, &data);
+ if (err)
+ goto out;
+ err = -EINVAL;
+ if (data != 0 && data != 1)
+ goto out;
+ dev->pdata.pins.cs_activelow = data;
+ err = 0;
+ goto out;
+ }
+ if (attr == &gpiommc_attr_spimode) {
+ err = strict_strtoul(page, 10, &data);
+ if (err)
+ goto out;
+ err = -EINVAL;
+ switch (data) {
+ case 0:
+ dev->pdata.mode = SPI_MODE_0;
+ break;
+ case 1:
+ dev->pdata.mode = SPI_MODE_1;
+ break;
+ case 2:
+ dev->pdata.mode = SPI_MODE_2;
+ break;
+ case 3:
+ dev->pdata.mode = SPI_MODE_3;
+ break;
+ default:
+ goto out;
+ }
+ err = 0;
+ goto out;
+ }
+ if (attr == &gpiommc_attr_spidelay) {
+ err = strict_strtoul(page, 10, &data);
+ if (err)
+ goto out;
+ err = -EINVAL;
+ if (data != 0 && data != 1)
+ goto out;
+ dev->pdata.no_spi_delay = !data;
+ err = 0;
+ goto out;
+ }
+ if (attr == &gpiommc_attr_max_bus_speed) {
+ err = strict_strtoul(page, 10, &data);
+ if (err)
+ goto out;
+ err = -EINVAL;
+ if (data > UINT_MAX)
+ goto out;
+ dev->pdata.max_bus_speed = data;
+ err = 0;
+ goto out;
+ }
+ WARN_ON(1);
+ err = -ENOSYS;
+out:
+ return err ? err : count;
+}
+
+static void gpiommc_config_item_release(struct config_item *item)
+{
+ struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
+
+ kfree(dev);
+}
+
+static struct configfs_item_operations gpiommc_config_item_ops = {
+ .release = gpiommc_config_item_release,
+ .show_attribute = gpiommc_config_attr_show,
+ .store_attribute = gpiommc_config_attr_store,
+};
+
+static struct config_item_type gpiommc_dev_ci_type = {
+ .ct_item_ops = &gpiommc_config_item_ops,
+ .ct_attrs = gpiommc_config_attrs,
+ .ct_owner = THIS_MODULE,
+};
+
+static struct config_item *gpiommc_make_item(struct config_group *group,
+ const char *name)
+{
+ struct gpiommc_configfs_device *dev;
+
+ if (strlen(name) > GPIOMMC_MAX_NAMELEN) {
+ printk(KERN_ERR PFX "configfs: device name too long\n");
+ return NULL;
+ }
+
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ if (!dev)
+ return NULL;
+
+ config_item_init_type_name(&dev->item, name,
+ &gpiommc_dev_ci_type);
+
+ /* Assign default configuration */
+ dev->pdata.pins.gpio_di = GPIO_INVALID;
+ dev->pdata.pins.gpio_do = GPIO_INVALID;
+ dev->pdata.pins.gpio_clk = GPIO_INVALID;
+ dev->pdata.pins.gpio_cs = GPIO_INVALID;
+ dev->pdata.pins.cs_activelow = 1;
+ dev->pdata.mode = SPI_MODE_0;
+ dev->pdata.no_spi_delay = 0;
+ dev->pdata.max_bus_speed = 5000000; /* 5 MHz */
+
+ return &(dev->item);
+}
+
+static void gpiommc_drop_item(struct config_group *group,
+ struct config_item *item)
+{
+ struct gpiommc_configfs_device *dev = ci_to_gpiommc(item);
+
+ gpiommc_do_unregister(dev);
+ kfree(dev);
+}
+
+static struct configfs_group_operations gpiommc_ct_group_ops = {
+ .make_item = gpiommc_make_item,
+ .drop_item = gpiommc_drop_item,
+};
+
+static struct config_item_type gpiommc_ci_type = {
+ .ct_group_ops = &gpiommc_ct_group_ops,
+ .ct_owner = THIS_MODULE,
+};
+
+static struct configfs_subsystem gpiommc_subsys = {
+ .su_group = {
+ .cg_item = {
+ .ci_namebuf = GPIOMMC_PLATDEV_NAME,
+ .ci_type = &gpiommc_ci_type,
+ },
+ },
+ .su_mutex = __MUTEX_INITIALIZER(gpiommc_subsys.su_mutex),
+};
+
+#endif /* CONFIG_GPIOMMC_CONFIGFS */
+#ifdef CONFIG_GPIOMMC_CONFIGFS
+ config_group_init(&gpiommc_subsys.su_group);
+ err = configfs_register_subsystem(&gpiommc_subsys);
+ if (err) {
+ platform_driver_unregister(&gpiommc_plat_driver);
+ return err;
+ }
+#endif /* CONFIG_GPIOMMC_CONFIGFS */
+
+ return 0;
+}
+module_init(gpiommc_modinit);
+
+static void __exit gpiommc_modexit(void)
+{
+#ifdef CONFIG_GPIOMMC_CONFIGFS
+ configfs_unregister_subsystem(&gpiommc_subsys);
+#endif
+ platform_driver_unregister(&gpiommc_plat_driver);
+}
+module_exit(gpiommc_modexit);
Index: linux-next/drivers/mmc/host/Kconfig
===================================================================
--- linux-next.orig/drivers/mmc/host/Kconfig 2008-07-20 21:39:09.000000000 +0200
+++ linux-next/drivers/mmc/host/Kconfig 2008-07-20 21:40:47.000000000 +0200
@@ -174,3 +174,27 @@ config MMC_SDRICOH_CS
To compile this driver as a module, choose M here: the
module will be called sdricoh_cs.
+config GPIOMMC
+ tristate "MMC/SD over GPIO-based SPI"
+ depends on MMC && MMC_SPI && SPI_GPIO
+ help
+ This driver hooks up the mmc_spi and spi_gpio modules so that
+ MMC/SD cards can be used on a GPIO based bus by bitbanging
+ the SPI protocol in software.
+
+ This driver provides a configfs interface to dynamically create
+ and destroy GPIO-based MMC/SD card devices. It also provides
+ a platform device interface API.
+ See Documentation/gpiommc.txt for details.
+
+ The module will be called gpiommc.
+
+ If unsure, say N.
+
+config GPIOMMC_CONFIGFS
+ bool
+ depends on GPIOMMC && CONFIGFS_FS
+ default y
+ help
+ This option automatically enables configfs support for gpiommc
+ if configfs is available.
Index: linux-next/drivers/mmc/host/Makefile
===================================================================
--- linux-next.orig/drivers/mmc/host/Makefile 2008-07-20 21:39:09.000000000 +0200
+++ linux-next/drivers/mmc/host/Makefile 2008-07-20 21:41:26.000000000 +0200
@@ -21,4 +21,4 @@ obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
obj-$(CONFIG_MMC_SPI) += mmc_spi.o
obj-$(CONFIG_MMC_S3C) += s3cmci.o
obj-$(CONFIG_MMC_SDRICOH_CS) += sdricoh_cs.o
-
+obj-$(CONFIG_GPIOMMC) += gpiommc.o
Index: linux-next/include/linux/mmc/gpiommc.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-next/include/linux/mmc/gpiommc.h 2008-07-20 21:40:47.000000000 +0200
@@ -0,0 +1,71 @@
+/*
+ * Device driver for MMC/SD cards driven over a GPIO bus.
+ *
+ * Copyright (c) 2008 Michael Buesch
+ *
+ * Licensed under the GNU/GPL version 2.
+ */
+#ifndef LINUX_GPIOMMC_H_
+#define LINUX_GPIOMMC_H_
+
+#include <linux/types.h>
+
+
+#define GPIOMMC_MAX_NAMELEN 15
+#define GPIOMMC_MAX_NAMELEN_STR __stringify(GPIOMMC_MAX_NAMELEN)
+
+/**
+ * struct gpiommc_pins - Hardware pin assignments
+ *
+ * @gpio_di: The GPIO number of the DATA IN pin
+ * @gpio_do: The GPIO number of the DATA OUT pin
+ * @gpio_clk: The GPIO number of the CLOCK pin
+ * @gpio_cs: The GPIO number of the CHIPSELECT pin
+ * @cs_activelow: If true, the chip is considered selected if @gpio_cs is low.
+ */
+struct gpiommc_pins {
+ unsigned int gpio_di;
+ unsigned int gpio_do;
+ unsigned int gpio_clk;
+ unsigned int gpio_cs;
+ bool cs_activelow;
+};
+
+/**
+ * struct gpiommc_platform_data - Platform data for a MMC-over-SPI-GPIO device.
+ *
+ * @name: The unique name string of the device.
+ * @pins: The hardware pin assignments.
+ * @mode: The hardware mode. This is either SPI_MODE_0,
+ * SPI_MODE_1, SPI_MODE_2 or SPI_MODE_3. See the SPI documentation.
+ * @no_spi_delay: Do not use delays in the lowlevel SPI bitbanging code.
+ * This is not standards compliant, but may be required for some
+ * embedded machines to gain reasonable speed.
+ * @max_bus_speed: The maximum speed of the SPI bus, in Hertz.
+ */
+struct gpiommc_platform_data {
+ char name[GPIOMMC_MAX_NAMELEN + 1];
+ struct gpiommc_pins pins;
+ u8 mode;
+ bool no_spi_delay;
+ unsigned int max_bus_speed;
+};
+
+/**
+ * GPIOMMC_PLATDEV_NAME - The platform device name string.
+ *
+ * The name string that has to be used for platform_device_alloc
+ * when allocating a gpiommc device.
+ */
+#define GPIOMMC_PLATDEV_NAME "gpiommc"
+
+/**
+ * gpiommc_next_id - Get another platform device ID number.
+ *
+ * This returns the next platform device ID number that has to be used
+ * for platform_device_alloc. The ID is opaque and should not be used for
+ * anything else.
+ */
+int gpiommc_next_id(void);
+
+#endif /* LINUX_GPIOMMC_H_ */
Index: linux-next/Documentation/gpiommc.txt
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-next/Documentation/gpiommc.txt 2008-07-20 21:40:47.000000000 +0200
@@ -0,0 +1,97 @@
+GPIOMMC - Driver for an MMC/SD card on a bitbanging GPIO SPI bus
+================================================================
+
+The gpiommc module hooks up the mmc_spi and spi_gpio modules for running an
+MMC or SD card on GPIO pins.
+
+Two interfaces for registering a new MMC/SD card device are provided:
+A static platform-device based mechanism and a dynamic configfs based interface.
+
+
+Registering devices via platform-device
+=======================================
+
+The platform-device interface is used for registering MMC/SD devices that are
+part of the hardware platform. This is most useful only for embedded machines
+with MMC/SD devices statically connected to the platform GPIO bus.
+
+The data structures are declared in <linux/mmc/gpiommc.h>.
+
+To register a new device, define an instance of struct gpiommc_platform_data.
+This structure holds any information about how the device is hooked up to the
+GPIO pins and what hardware modes the device supports. See the docbook-style
+documentation in the header file for more information on the struct fields.
+
+Then allocate a new instance of a platform device by doing:
+
+ pdev = platform_device_alloc(GPIOMMC_PLATDEV_NAME, gpiommc_next_id());
+
+This will allocate the platform device data structures and hook it up to the
+gpiommc driver.
+Then add the gpiommc_platform_data to the platform device.
+
+ err = platform_device_add_data(pdev, pdata, sizeof(struct gpiommc_platform_data));
+
+You may free the local instance of struct gpiommc_platform_data now. (So the
+struct may be allocated on the stack, too).
+Now simply register the platform device.
+
+ err = platform_device_add(pdev);
+
+Done. The gpiommc probe routine will be invoked now and you should see a kernel
+log message for the added device.
+
+
+Registering devices via configfs
+================================
+
+MMC/SD cards connected via GPIO often are a pretty dynamic thing, as for example
+selfmade hacks for soldering an MMC/SD card to standard GPIO pins on embedded
+hardware are a common situation.
+So we provide a dynamic interface to conveniently handle adding and removing
+devices from userspace, without the need to recompile the kernel.
+
+The "gpiommc" subdirectory at the configfs mountpoint is used for handling
+the dynamic configuration.
+
+To create a new device, it must first be allocated with mkdir.
+The following command will allocate a device named "my_mmc":
+ mkdir /config/gpiommc/my_mmc
+
+There are several configuration files available in the new
+/config/gpiommc/my_mmc/ directory:
+
+gpio_data_in = The SPI data-IN GPIO pin number.
+gpio_data_out = The SPI data-OUT GPIO pin number.
+gpio_clock = The SPI Clock GPIO pin number.
+gpio_chipselect = The SPI Chipselect GPIO pin number.
+gpio_chipselect_activelow = Boolean. If 0, Chipselect is active-HIGH.
+ If 1, Chipselect is active-LOW.
+spi_mode = The SPI data mode. Can be 0-3.
+spi_delay = Enable all delays in the lowlevel bitbanging.
+max_bus_speed = The maximum SPI bus speed. In Hertz.
+
+register = Not a configuration parameter.
+ Used to register the configured card
+ with the kernel.
+
+The device must first get configured and then registered by writing "1" to
+the "register" file.
+The configuration parameters "gpio_data_in", "gpio_data_out", "gpio_clock"
+and "gpio_chipselect" are essential and _must_ be configured before writing
+"1" to the "register" file. The registration will fail, otherwise.
+
+The default values for the other parameters are:
+gpio_chipselect_activelow = 1 (CS active-LOW)
+spi_mode = 0 (SPI_MODE_0)
+spi_delay = 1 (enabled)
+max_bus_speed = 5000000 (5 Mhz)
+
+Configuration values can not be changed after registration. To unregister
+the device, write a "0" to the "register" file. The configuration can be
+changed again after unregistering.
+
+To completely remove the device, simply rmdir the directory
+(/config/gpiommc/my_mmc in this example).
+There's no need to first unregister the device before removing it. That will
+be done automatically.
Index: linux-next/MAINTAINERS
===================================================================
--- linux-next.orig/MAINTAINERS 2008-07-20 21:40:38.000000000 +0200
+++ linux-next/MAINTAINERS 2008-07-20 21:40:47.000000000 +0200
@@ -1880,6 +1880,11 @@ L: gigaset30...@lists.sourceforge.
W: http://gigaset307x.sourceforge.net/
S: Maintained
+GPIOMMC DRIVER
+P: Michael Buesch
+M: m...@bu3sch.de
+S: Maintained
+
HARDWARE MONITORING
P: Mark M. Hoffman
M: mhof...@lightlink.com
--
> This driver hooks up the mmc_spi and spi_gpio modules so that
> MMC/SD cards can be used on a GPIO based bus by bitbanging
> the SPI protocol in software.
>
> This driver provides a configfs interface to dynamically create
> and destroy GPIO-based MMC/SD card interfaces. It also provides
> a platform device interface API.
> See Documentation/gpiommc.txt for details.
>
> Signed-off-by: Michael Buesch <m...@bu3sch.de>
>
> ---
>
> This driver is used in OpenWrt since quite some time, so please
> consider for inclusion in mainline.
>
> Changes since v2: The sysfs interface has been replaced by a configfs interface.
> Although I don't really like the bloat this adds (this is a driver for embedded
> machines), I do like the much cleaner interface and I think it's worth the bloat.
> Index: linux-next/Documentation/gpiommc.txt
> ===================================================================
> --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> +++ linux-next/Documentation/gpiommc.txt 2008-07-20 21:40:47.000000000 +0200
> @@ -0,0 +1,97 @@
...
One minor nit below, otherwise looks good to me.
Thanks.
cannot
> +the device, write a "0" to the "register" file. The configuration can be
> +changed again after unregistering.
---
~Randy
Linux Plumbers Conference, 17-19 September 2008, Portland, Oregon USA
http://linuxplumbersconf.org/
configfs stuff should still go in Documentation/ABI as it is a
userspace/kernelspace interface.
thanks,
greg k-h
On Friday 18 July 2008, Randy Dunlap wrote:
> On Fri, 18 Jul 2008 22:01:33 +0200 Michael Buesch wrote:
>
> > --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> > +++ linux-next/drivers/mmc/host/gpiommc.c 2008-07-18 21:54:05.000000000 +0200
> > @@ -0,0 +1,328 @@
> > +/*
> > + * Driver an MMC/SD card on a bitbanging GPIO SPI bus.
Driver "for" an MMC/SD card ...
> > + * This module hooks up the mmc_spi and spi_gpio modules and also
> > + * provides a sysfs interface.
I'm not quite following things here. The mmc_spi driver has
no particular issues running over any correct implementation
of SPI, whether it uses GPIO or anything else.
In fact, I did doing a bunch of early mmc_spi work using a
SPI-over-GPIO bitbanger. (Also some tuning for the GPIO
interfaces, making sure those calls inlined transparently
to get more usable speeds.) So I know that already works
just fine ...
So what this driver adds is mostly a userspace interface, yes?
The reason to select THIS feature is to get the userspace
configuration ... not to get the MMC/SD-over-GPIO, since
that can already be done without this code.
If so, please refocus the descriptions a bit more on that;
it's not actually a "GPIO based MMC/SD driver"; it's really
a "Configfs creation interface for GPIO based MMC/SD".
> > + res = sscanf(buf, "%" GPIOMMC_MAX_NAMELEN_STR "s %u %u %u %u %u %u %u %u",
Kind of ugly, yes? ;)
> > + pdata->p.name,
> > + &pdata->p.pins.gpio_di,
> > + &pdata->p.pins.gpio_do,
Can we avoid that DI/DO convention? The master DI is the slave DO,
and vice versa. Your documentation doesn't say which is which; and
for such ambiguous names, that's critical. Since these GPIOs are
on the master side, I'd expect these labels are for the master
side not the slave side.
Please switch to the more conventional "MOSI" (Master Out, Slave In)
and "MISO" (Master In, Slave Out). That's unambiguous. If you want
to be a bit more clear you could say that MOSI goes to the MMC/SD
card pin 2 (card data in), and MISO goes to MMC/SD card pin 7 (card
data out).
> > + &pdata->p.pins.gpio_clk,
> > + &pdata->p.pins.gpio_cs,
> > + &mode,
> > + &pdata->p.max_bus_speed,
> > + &no_spi_delay,
> > + &csactivelow);
> > + pdata->p.mode = mode;
> > + pdata->p.no_spi_delay = !!no_spi_delay;
> > + pdata->p.pins.cs_activelow = !!csactivelow;
> > + if (res < 9)
> > + pdata->p.pins.cs_activelow = 1; /* Default: CS = activelow */
Do you actually need this? If so, why? The MMC (and SD) specs
say that pin 1 (chipselect) is active low, and that's normal
for all SPI interfaces. This may need a comment that it's never
needed unless there's an inverter in that signal path.
> > + if (res < 8)
> > + pdata->p.no_spi_delay = 0; /* Default: Delay turned on */
> > + if (res < 7)
> > + pdata->p.max_bus_speed = 5000000; /* Default: 5Mhz */
Maybe it's just the hardware I've used, but I've had a hard time
getting bitbanged SPI to run that fast ... more like 2.5 MHz unless
you're using big word sizes (and MMC is stuck at 8-bit words), and
that speed assumes inlined gpio code not subroutine-call-per-bit.
So I'd default to leaving the delay off, and wouldn't bother trying
to place a ceiling on the speeds which is lower than the 25 MHz that
SD cards allow.
> > + if (res < 6)
> > + pdata->p.mode = 0; /* Default: SPI mode 0 */
Don't need to do this. The mmc_spi driver forces mode 0 in
any case...
> > --- linux-next.orig/drivers/mmc/host/Kconfig 2008-07-18 21:52:46.000000000 +0200
> > +++ linux-next/drivers/mmc/host/Kconfig 2008-07-18 21:57:08.000000000 +0200
> > @@ -164,3 +164,23 @@ config MMC_S3C
> >
> > If unsure, say N.
> >
> > +config GPIOMMC
> > + tristate "MMC/SD over GPIO-based SPI"
"Sysfs interface for ..."
Because we can already do MMC/SD over GPIO-SPI,
without using this code.
> > + depends on MMC && MMC_SPI && SPI_GPIO
> > + help
> > + This driver hooks up the mmc_spi and spi_gpio modules so that
> > + MMC/SD cards can be used on a GPIO based bus by bitbanging
> > + the SPI protocol in software.
> > +
> > + This driver provides a sysfs interface to dynamically create
> > + and destroy GPIO-based MMC/SD card interfaces. It also provides
> > + a platform device interface API.
Probably best to just switch those two paragraphs around,
and highlight that this SPI bus can't be used for anything
except that MMC/SD slot even if we someday extend the SPI
interfaces with exclusive access primitives.
The platform device interface API is not actually needed
to implement MMC/SD-over-bitbanged-SPI; it's only really
needed to implement this driver. So I'd not mention the
presence of such a module-internal interface.
Now, if you were to implement the MMC protocol directly
over GPIOs, rather than indirectly through SPI-over-GPIO,
that would be worth packaging for general use. (Such a
thing would be worth doing. The latest JEDEC versions
of the "embedded MMC" specs -- parallel 8 bit data paths,
used for SMT chips not just cards -- omit SPI support.
Using platform-specific parallel GPIO support to support
4 or 8 bit data widths would give a big speedup too.)
> > + See Documentation/gpiommc.txt for details.
> > +
> > + The module will be called gpiommc.
> > +
> > + If unsure, say N.
> > +
> > +config MMC_S3C
> > + tristate "Samsung S3C SD/MMC Card Interface support"
> > + depends on ARCH_S3C2410 && MMC
MMC_S3C doesn't belong in this patch...
> > + * @no_spi_delay: Do not use delays in the lowlevel SPI bitbanging code.
> > + * This is not standards compliant, but may be required for some
> > + * embedded machines to gain reasonable speed.
Rather than emphasize "not standards compliant", I'd instead emphasize that
bitbanged SPI is so slow that you probably don't want to slow it down any
more by additional delays between per-bit operations!
> > Index: linux-next/Documentation/gpiommc.txt
> > ===================================================================
> > --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> > +++ linux-next/Documentation/gpiommc.txt 2008-07-18 21:54:05.000000000 +0200
Should there be a Documentation/mmc/... for such stuff, instead?
The toplevel Documentation directory is getting unmanageable.
> > @@ -0,0 +1,96 @@
> > +GPIOMMC - Driver for an MMC/SD card on a bitbanging GPIO SPI bus
> > +================================================================
> > +
> > +The gpiommc module hooks up the mmc_spi and spi_gpio modules for running an
> > +MMC or SD card on GPIO pins.
> > +
> > +Two interfaces for registering a new MMC/SD card device are provided.
>
> are provided:
> a static
>
> > +A static platform-device based mechanism and a dynamic sysfs based interface.
Again, please don't promote a *SECOND* platform-device based mechanism
for this. The current one works just fine: standard definition of
a SPI bus (in this case using GPIO bitbanging), combined with standard
definition of an mmc-over-spi card slot.
(I notice you don't support card detect and writeprotect detect GPIOs
in your configfs interface. Such omissions are easy to address through
the standard mmc-over-spi card slot mechanism ...)
> > +
> > +
> > +Registering devices via platform-device
> > +=======================================
> > +
> > +The platform-device interface is used for registering MMC/SD devices that are
> > +part of the hardware platform. This is most useful only for embedded machines
> > +with MMC/SD devices statically connected to the platform GPIO bus.
There is no "platform GPIO bus" ...
This is the interface I'd rather just not see exposed ...
> > +The data structures are declared in <linux/mmc/gpiommc.h>
... and just see internal to this driver, without a new header
duplicating existing mechanisms.
> > +Registering devices via sysfs
> > +=============================
This is the interface I don't have any particular issues with.
> > +
> > +MMC/SD cards connected via GPIO often are a pretty dynamic thing. For example
> > +selfmade hacks for soldering an MMC/SD card to standard GPIO pins on embedded
> > +hardware are a common situation.
>
> I think that the two sentences above/below would be better if joined with a comma...
I certainly wouldn't say "often", even though I've done it!
How about: "... via GPIO may be easier to configure through
sysfs than through the normal platform device declaration
mechanisms. For example, selfmade ... situation, and using
sysfs to verify the pin assignments may save a few iterations
of a kernel modify/build/install/test cycle."
> [ I see "v3" switches to configfs ... same comments apply. ]
> > > Index: linux-next/Documentation/gpiommc.txt
> > > ===================================================================
> > > --- /dev/null 1970-01-01 00:00:00.000000000 +0000
> > > +++ linux-next/Documentation/gpiommc.txt 2008-07-18 21:54:05.000000000 +0200
>
> Should there be a Documentation/mmc/... for such stuff, instead?
What other files could be moved into that subdir?
> The toplevel Documentation directory is getting unmanageable.
Yes, it is.
---
~Randy
Linux Plumbers Conference, 17-19 September 2008, Portland, Oregon USA
http://linuxplumbersconf.org/
Mostly. It also provides a simple platform device.
> If so, please refocus the descriptions a bit more on that;
> it's not actually a "GPIO based MMC/SD driver"; it's really
> a "Configfs creation interface for GPIO based MMC/SD".
>
>
> > > + res = sscanf(buf, "%" GPIOMMC_MAX_NAMELEN_STR "s %u %u %u %u %u %u %u %u",
>
> Kind of ugly, yes? ;)
This is already gone.
> Please switch to the more conventional "MOSI" (Master Out, Slave In)
> and "MISO" (Master In, Slave Out). That's unambiguous. If you want
> to be a bit more clear you could say that MOSI goes to the MMC/SD
> card pin 2 (card data in), and MISO goes to MMC/SD card pin 7 (card
> data out).
Maybe.
> > > + if (res < 8)
> > > + pdata->p.no_spi_delay = 0; /* Default: Delay turned on */
> > > + if (res < 7)
> > > + pdata->p.max_bus_speed = 5000000; /* Default: 5Mhz */
>
> So I'd default to leaving the delay off
How to?
> > > + if (res < 6)
> > > + pdata->p.mode = 0; /* Default: SPI mode 0 */
>
> Don't need to do this. The mmc_spi driver forces mode 0 in
> any case...
Where's that documented?
> > > +config GPIOMMC
> > > + tristate "MMC/SD over GPIO-based SPI"
>
> "Sysfs interface for ..."
>
> Because we can already do MMC/SD over GPIO-SPI,
> without using this code.
This also adds a platform device interface for convenience
(as it also uses that internally).
> > > +config MMC_S3C
> > > + tristate "Samsung S3C SD/MMC Card Interface support"
> > > + depends on ARCH_S3C2410 && MMC
>
> MMC_S3C doesn't belong in this patch...
Yeah that was a mismerge. You are commenting on an obsolete patch.
> > > + * @no_spi_delay: Do not use delays in the lowlevel SPI bitbanging code.
> > > + * This is not standards compliant, but may be required for some
> > > + * embedded machines to gain reasonable speed.
>
> Rather than emphasize "not standards compliant", I'd instead emphasize that
> bitbanged SPI is so slow that you probably don't want to slow it down any
> more by additional delays between per-bit operations!
I'd say you cannot tell how fast the GPIOs are. They can be pretty fast
on a huge machine.
> Again, please don't promote a *SECOND* platform-device based mechanism
It is not a second mechanism, it is a mechanism on top of the first two
mechanisms.
> > > +Registering devices via platform-device
> > > +=======================================
> > > +
> > > +The platform-device interface is used for registering MMC/SD devices that are
> > > +part of the hardware platform. This is most useful only for embedded machines
> > > +with MMC/SD devices statically connected to the platform GPIO bus.
>
> There is no "platform GPIO bus" ...
hm??
> This is the interface I'd rather just not see exposed ...
People asked me to expose it. It was hidden in the first patch that
I submitted. I'm not going to change this just to see the next one
yelling "I want to see this interface in public" again.
> > > +Registering devices via sysfs
> > > +=============================
>
> This is the interface I don't have any particular issues with.
Yeah, but it's gone. See updated patches.
--
Greetings Michael.
> On Monday 21 July 2008 22:41:35 David Brownell wrote:
> > So what this driver adds is mostly a userspace interface, yes?
>
> Mostly. It also provides a simple platform device.
Yeah but I don't like interfaces like that ... which provide
less functional clones of existing interfaces. If the goal is
convenience, then just wrap the existing ones together to give
the "one stop shopping" experience.
> > Please switch to the more conventional "MOSI" (Master Out, Slave In)
> > and "MISO" (Master In, Slave Out). That's unambiguous. If you want
> > to be a bit more clear you could say that MOSI goes to the MMC/SD
> > card pin 2 (card data in), and MISO goes to MMC/SD card pin 7 (card
> > data out).
>
> Maybe.
Not clear what you mean. You are using "DI" and "DO", which is quite
ambiguous (data in to card? or data in to host?). And you don't say
which direction is meant. So that's ambigious ... just like "maybe".
>
> > > > + if (res < 8)
> > > > + pdata->p.no_spi_delay = 0; /* Default: Delay turned on */
> > > > + if (res < 7)
> > > > + pdata->p.max_bus_speed = 5000000; /* Default: 5Mhz */
> >
>
> > So I'd default to leaving the delay off
>
> How to?
Simplest to just rip out the support for using one! And in any case:
as a rule, any delay should be a function of the target bus speed.
If you wanted to get fancy you could measure how long it takes to issue a
non-inlined GPIO call, and solve for the delay:
cycle time = 1/max_speed_hz
cycle_time = 4 * call_cost + 2 * delay_len
One way to measure would be wrapping ktime_get_ts() calls around a loop that
toggles the SPI clock a few hundred times.
> > > > + if (res < 6)
> > > > + pdata->p.mode = 0; /* Default: SPI mode 0 */
> >
> > Don't need to do this. The mmc_spi driver forces mode 0 in
> > any case...
>
> Where's that documented?
UTSL ... mmc_spi_probe(), first thing. :)
> > > > +config GPIOMMC
> > > > + tristate "MMC/SD over GPIO-based SPI"
> >
> > "Sysfs interface for ..."
> >
> > Because we can already do MMC/SD over GPIO-SPI,
> > without using this code.
>
> This also adds a platform device interface for convenience
> (as it also uses that internally).
Don't export that. It's a (less expressive) subset of the standard
way to do that.
> > > > + * @no_spi_delay: Do not use delays in the lowlevel SPI bitbanging code.
> > > > + * This is not standards compliant, but may be required for some
> > > > + * embedded machines to gain reasonable speed.
> >
> > Rather than emphasize "not standards compliant", I'd instead emphasize that
> > bitbanged SPI is so slow that you probably don't want to slow it down any
> > more by additional delays between per-bit operations!
>
> I'd say you cannot tell how fast the GPIOs are. They can be pretty fast
> on a huge machine.
Huge machine tends to mean lots of busses to traverse before getting to
where the actual I/O gets performed. Like a PCI posted write, followed
by a read to make sure the write completed and the I/O was performed.
Regardless, the point isn't standards, it's platform performance ... which
is, in all cases I've used bitbanged SPI, at most 1 MHz when non-inlined
GPIO calls are used. And many times faster with inlined calls that go
directly to the GPIO controller...
> > Again, please don't promote a *SECOND* platform-device based mechanism
>
> It is not a second mechanism, it is a mechanism on top of the first two
> mechanisms.
There's already a way to define an MMC-over-SPI device. This is another
one. In what way would that not be a "second" mechanism??
> > > > +Registering devices via platform-device
> > > > +=======================================
> > > > +
> > > > +The platform-device interface is used for registering MMC/SD devices that are
> > > > +part of the hardware platform. This is most useful only for embedded machines
> > > > +with MMC/SD devices statically connected to the platform GPIO bus.
> >
> > There is no "platform GPIO bus" ...
>
> hm??
If you look in /sys/bus you won't see GPIO. It's not a bus.
> > This is the interface I'd rather just not see exposed ...
>
> People asked me to expose it. It was hidden in the first patch that
> I submitted. I'm not going to change this just to see the next one
> yelling "I want to see this interface in public" again.
Could you send me some URLs for that feedback? Again, I'm not keen
on adding a second (and less functional) way to do this.
>
> > > > +Registering devices via sysfs
> > > > +=============================
> >
> > This is the interface I don't have any particular issues with.
>
> Yeah, but it's gone. See updated patches.
I meant "the userspace interface". I did see the update patch
that changed it to use about configfs.
> You are not allowed to post to this mailing list, and your message has
> been automatically rejected. If you think that your messages are
> being rejected in error, contact the mailing list owner at
> openwrt-d...@lists.openwrt.org.
Well, that wasn't exactly an answer to my question. ;)
So setting boardinfo->max_speed_hz to zero will do?
> > Where's that documented?
>
> UTSL ... mmc_spi_probe(), first thing. :)
Well, the code of a function isn't really a documentation for its API. ;)
But well, thanks for the hint.
> Don't export that. It's a (less expressive) subset of the standard
> way to do that.
Well, if we have that code in one place, why would we want to reinvent the
wheel over and over again? We can just export this API and let users use
it instead of requireing them to reinvent it.
I'm really really not too sure where your problem is with exporting
that API. If you don't want to use it, simply don't do so and reinvent
the wheel in your code. I'm prefectly fine with that. But IMO that's not
a good reason to hide the code from everybody else who wants to use it.
> > >
> > > There is no "platform GPIO bus" ...
> >
> > hm??
>
> If you look in /sys/bus you won't see GPIO. It's not a bus.
Oh well... This is getting boring...
Then call it "platform GPIO pins" or "platform GPIO controller" or whatever.
That's really just splitting the hair into 16 parts.
> > People asked me to expose it. It was hidden in the first patch that
> > I submitted. I'm not going to change this just to see the next one
> > yelling "I want to see this interface in public" again.
>
> Could you send me some URLs for that feedback?
It was private. One of the OpenWRT guys requested that to have a
convenient way to define a hardwired MMC card in the platform code
by just defining a simple data structure.
--
Greetings Michael.
>> > Where's that documented?
>>
>> UTSL ... mmc_spi_probe(), first thing. :)
:)
> [...]
>> > > There is no "platform GPIO bus" ...
>> >
>> > hm??
>>
>> If you look in /sys/bus you won't see GPIO. It's not a bus.
>
> Oh well... This is getting boring...
> Then call it "platform GPIO pins" or "platform GPIO controller" or whatever.
> That's really just splitting the hair into 16 parts.
Michael - ok, change this to "platform GPIO lines" :)
>> > People asked me to expose it. It was hidden in the first patch that
>> > I submitted. I'm not going to change this just to see the next one
>> > yelling "I want to see this interface in public" again.
>>
>> Could you send me some URLs for that feedback?
>
> It was private. One of the OpenWRT guys requested that to have a
> convenient way to define a hardwired MMC card in the platform code
> by just defining a simple data structure.
Maybe I was this one, ore one of them. I wanted some method to
experiment with MMC/SD connected to GPIO. Not some determined lines,
but in some way configurable. There was several ugly patches on net
(mostly around OpenWRT, and mostly tested by users of OpenWRT), but
all of them was ugly hacks, dependent on some particular architecture
(ARM as i remember).
So, in that time, simply I started writing something more general,
less architecture dependent, something, what could be more easy to
configure (in kernel/module loading time).
I started this, and Michael did the rest...