diff mbox

[11/11] mmc: Add OpenFirmware bindings for SDHCI driver

Message ID 20090316211405.GK9375@oksana.dev.rtsoft.ru (mailing list archive)
State Accepted, archived
Delegated to: Kumar Gala
Headers show

Commit Message

Anton Vorontsov March 16, 2009, 9:14 p.m. UTC
This patch adds a new driver: sdhci-of. The driver is similar to
the sdhci-pci, it contains common probe code, and controller-specific
ops and quirks.

So far there are only Freescale eSDHC ops and quirks.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
---
 MAINTAINERS                 |    7 +
 drivers/mmc/host/Kconfig    |   11 ++
 drivers/mmc/host/Makefile   |    1 +
 drivers/mmc/host/sdhci-of.c |  309 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 328 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mmc/host/sdhci-of.c

Comments

yamazaki March 19, 2009, 11:28 p.m. UTC | #1
Hi all,

I am running the Linux kernel 2.6.28.7 on my PPC8347 BRD.
I have to write the driver of SDHCI driver(using R5C807 RICOH). 
But I could not find it.
Then I found the good sample of this.
I tried to the patch to kernel 2.6.28.7,but I did not succeed.
Please tell me how to get the kernei for this patch.

-Seiji  


>This patch adds a new driver: sdhci-of. The driver is similar to
>the sdhci-pci, it contains common probe code, and controller-specific
>ops and quirks.
>
>So far there are only Freescale eSDHC ops and quirks.
>
>Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
>Acked-by: Arnd Bergmann <arnd@arndb.de>
>---
> MAINTAINERS                 |    7 +
> drivers/mmc/host/Kconfig    |   11 ++
> drivers/mmc/host/Makefile   |    1 +
> drivers/mmc/host/sdhci-of.c |  309 +++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 328 insertions(+), 0 deletions(-)
> create mode 100644 drivers/mmc/host/sdhci-of.c
>
>diff --git a/MAINTAINERS b/MAINTAINERS
>index 4a1cfca..77c3ec0 100644
>--- a/MAINTAINERS
>+++ b/MAINTAINERS
>@@ -3837,6 +3837,13 @@ M:	drzeus-sdhci@drzeus.cx
> L:	sdhci-devel@list.drzeus.cx
> S:	Maintained
> 
>+SECURE DIGITAL HOST CONTROLLER INTERFACE, OPEN FIRMWARE BINDINGS (SDHCI-OF)
>+P:	Anton Vorontsov
>+M:	avorontsov@ru.mvista.com
>+L:	linuxppc-dev@ozlabs.org
>+L:	sdhci-devel@list.drzeus.cx
>+S:	Maintained
>+
> SECURITY SUBSYSTEM
> F:	security/
> P:	James Morris
>diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
>index e032a42..69bd124 100644
>--- a/drivers/mmc/host/Kconfig
>+++ b/drivers/mmc/host/Kconfig
>@@ -72,6 +72,17 @@ config MMC_RICOH_MMC
> 
> 	  If unsure, say Y.
> 
>+config MMC_SDHCI_OF
>+	tristate "SDHCI support on OpenFirmware platforms"
>+	depends on MMC_SDHCI && PPC_OF
>+	select MMC_SDHCI_IO_ACCESSORS
>+	help
>+	  This selects the OF support for Secure Digital Host Controller
>+	  Interfaces. So far, only the Freescale eSDHC controller is known
>+	  to exist on OF platforms.
>+
>+	  If unsure, say N.
>+
> config MMC_OMAP
> 	tristate "TI OMAP Multimedia Card Interface support"
> 	depends on ARCH_OMAP
>diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
>index dedec55..dd512d9 100644
>--- a/drivers/mmc/host/Makefile
>+++ b/drivers/mmc/host/Makefile
>@@ -13,6 +13,7 @@ obj-$(CONFIG_MMC_MXC)		+= mxcmmc.o
> obj-$(CONFIG_MMC_SDHCI)		+= sdhci.o
> obj-$(CONFIG_MMC_SDHCI_PCI)	+= sdhci-pci.o
> obj-$(CONFIG_MMC_RICOH_MMC)	+= ricoh_mmc.o
>+obj-$(CONFIG_MMC_SDHCI_OF)	+= sdhci-of.o
> obj-$(CONFIG_MMC_WBSD)		+= wbsd.o
> obj-$(CONFIG_MMC_AU1X)		+= au1xmmc.o
> obj-$(CONFIG_MMC_OMAP)		+= omap.o
>diff --git a/drivers/mmc/host/sdhci-of.c b/drivers/mmc/host/sdhci-of.c
>new file mode 100644
>index 0000000..3ff4ac3
>--- /dev/null
>+++ b/drivers/mmc/host/sdhci-of.c
>@@ -0,0 +1,309 @@
>+/*
>+ * OpenFirmware bindings for Secure Digital Host Controller Interface.
>+ *
>+ * Copyright (c) 2007 Freescale Semiconductor, Inc.
>+ * Copyright (c) 2009 MontaVista Software, Inc.
>+ *
>+ * Authors: Xiaobo Xie <X.Xie@freescale.com>
>+ *	    Anton Vorontsov <avorontsov@ru.mvista.com>
>+ *
>+ * This program is free software; you can redistribute it and/or modify
>+ * it under the terms of the GNU General Public License as published by
>+ * the Free Software Foundation; either version 2 of the License, or (at
>+ * your option) any later version.
>+ */
>+
>+#include <linux/module.h>
>+#include <linux/init.h>
>+#include <linux/io.h>
>+#include <linux/interrupt.h>
>+#include <linux/delay.h>
>+#include <linux/of.h>
>+#include <linux/of_platform.h>
>+#include <linux/mmc/host.h>
>+#include "sdhci.h"
>+
>+struct sdhci_of_data {
>+	unsigned int quirks;
>+	struct sdhci_ops ops;
>+};
>+
>+struct sdhci_of_host {
>+	unsigned int clock;
>+	u16 xfer_mode_shadow;
>+};
>+
>+/*
>+ * Ops and quirks for the Freescale eSDHC controller.
>+ */
>+
>+#define ESDHC_DMA_SYSCTL	0x40c
>+#define ESDHC_DMA_SNOOP		0x00000040
>+
>+#define ESDHC_SYSTEM_CONTROL	0x2c
>+#define ESDHC_CLOCK_MASK	0x0000fff0
>+#define ESDHC_PREDIV_SHIFT	8
>+#define ESDHC_DIVIDER_SHIFT	4
>+#define ESDHC_CLOCK_PEREN	0x00000004
>+#define ESDHC_CLOCK_HCKEN	0x00000002
>+#define ESDHC_CLOCK_IPGEN	0x00000001
>+
>+static u32 esdhc_readl(struct sdhci_host *host, int reg)
>+{
>+	return in_be32(host->ioaddr + reg);
>+}
>+
>+static u16 esdhc_readw(struct sdhci_host *host, int reg)
>+{
>+	return in_be16(host->ioaddr + (reg ^ 0x2));
>+}
>+
>+static u8 esdhc_readb(struct sdhci_host *host, int reg)
>+{
>+	return in_8(host->ioaddr + (reg ^ 0x3));
>+}
>+
>+static void esdhc_writel(struct sdhci_host *host, u32 val, int reg)
>+{
>+	out_be32(host->ioaddr + reg, val);
>+}
>+
>+static void esdhc_writew(struct sdhci_host *host, u16 val, int reg)
>+{
>+	struct sdhci_of_host *of_host = sdhci_priv(host);
>+	int base = reg & ~0x3;
>+	int shift = (reg & 0x2) * 8;
>+
>+	switch (reg) {
>+	case SDHCI_TRANSFER_MODE:
>+		/*
>+		 * Postpone this write, we must do it together with a
>+		 * command write that is down below.
>+		 */
>+		of_host->xfer_mode_shadow = val;
>+		return;
>+	case SDHCI_COMMAND:
>+		esdhc_writel(host, val << 16 | of_host->xfer_mode_shadow,
>+			     SDHCI_TRANSFER_MODE);
>+		return;
>+	case SDHCI_BLOCK_SIZE:
>+		/*
>+		 * Two last DMA bits are reserved, and first one is used for
>+		 * non-standard blksz of 4096 bytes that we don't support
>+		 * yet. So clear the DMA boundary bits.
>+		 */
>+		val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
>+		/* fall through */
>+	}
>+	clrsetbits_be32(host->ioaddr + base, 0xffff << shift, val << shift);
>+}
>+
>+static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg)
>+{
>+	int base = reg & ~0x3;
>+	int shift = (reg & 0x3) * 8;
>+
>+	clrsetbits_be32(host->ioaddr + base , 0xff << shift, val << shift);
>+}
>+
>+static void esdhc_set_clock(struct sdhci_host *host, unsigned int clock)
>+{
>+	int div;
>+	int pre_div = 2;
>+
>+	clrbits32(host->ioaddr + ESDHC_SYSTEM_CONTROL, ESDHC_CLOCK_IPGEN |
>+		  ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK);
>+
>+	if (clock == 0)
>+		goto out;
>+
>+	if (host->max_clk / 16 > clock) {
>+		for (; pre_div < 256; pre_div *= 2) {
>+			if (host->max_clk / pre_div < clock * 16)
>+				break;
>+		}
>+	}
>+
>+	for (div = 1; div <= 16; div++) {
>+		if (host->max_clk / (div * pre_div) <= clock)
>+			break;
>+	}
>+
>+	pre_div >>= 1;
>+
>+	setbits32(host->ioaddr + ESDHC_SYSTEM_CONTROL, ESDHC_CLOCK_IPGEN |
>+		  ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN |
>+		  div << ESDHC_DIVIDER_SHIFT | pre_div << ESDHC_PREDIV_SHIFT);
>+	mdelay(100);
>+out:
>+	host->clock = clock;
>+}
>+
>+static int esdhc_enable_dma(struct sdhci_host *host)
>+{
>+	setbits32(host->ioaddr + ESDHC_DMA_SYSCTL, ESDHC_DMA_SNOOP);
>+	return 0;
>+}
>+
>+static unsigned int esdhc_get_max_clock(struct sdhci_host *host)
>+{
>+	struct sdhci_of_host *of_host = sdhci_priv(host);
>+
>+	return of_host->clock;
>+}
>+
>+static unsigned int esdhc_get_timeout_clock(struct sdhci_host *host)
>+{
>+	struct sdhci_of_host *of_host = sdhci_priv(host);
>+
>+	return of_host->clock / 1000;
>+}
>+
>+static struct sdhci_of_data sdhci_esdhc = {
>+	.quirks = SDHCI_QUIRK_FORCE_BLK_SZ_2048 |
>+		  SDHCI_QUIRK_BROKEN_CARD_DETECTION |
>+		  SDHCI_QUIRK_INVERTED_WRITE_PROTECT |
>+		  SDHCI_QUIRK_NO_BUSY_IRQ |
>+		  SDHCI_QUIRK_NONSTANDARD_CLOCK |
>+		  SDHCI_QUIRK_PIO_NEEDS_DELAY |
>+		  SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET |
>+		  SDHCI_QUIRK_NO_CARD_NO_RESET,
>+	.ops = {
>+		.readl = esdhc_readl,
>+		.readw = esdhc_readw,
>+		.readb = esdhc_readb,
>+		.writel = esdhc_writel,
>+		.writew = esdhc_writew,
>+		.writeb = esdhc_writeb,
>+		.set_clock = esdhc_set_clock,
>+		.enable_dma = esdhc_enable_dma,
>+		.get_max_clock = esdhc_get_max_clock,
>+		.get_timeout_clock = esdhc_get_timeout_clock,
>+	},
>+};
>+
>+#ifdef CONFIG_PM
>+
>+static int sdhci_of_suspend(struct of_device *ofdev, pm_message_t state)
>+{
>+	struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);
>+
>+	return mmc_suspend_host(host->mmc, state);
>+}
>+
>+static int sdhci_of_resume(struct of_device *ofdev)
>+{
>+	struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);
>+
>+	return mmc_resume_host(host->mmc);
>+}
>+
>+#else
>+
>+#define sdhci_of_suspend NULL
>+#define sdhci_of_resume NULL
>+
>+#endif
>+
>+static int __devinit sdhci_of_probe(struct of_device *ofdev,
>+				 const struct of_device_id *match)
>+{
>+	struct device_node *np = ofdev->node;
>+	struct sdhci_of_data *sdhci_of_data = match->data;
>+	struct sdhci_host *host;
>+	struct sdhci_of_host *of_host;
>+	const u32 *clk;
>+	int size;
>+	int ret;
>+
>+	if (!of_device_is_available(np))
>+		return -ENODEV;
>+
>+	host = sdhci_alloc_host(&ofdev->dev, sizeof(*of_host));
>+	if (!host)
>+		return -ENOMEM;
>+
>+	of_host = sdhci_priv(host);
>+	dev_set_drvdata(&ofdev->dev, host);
>+
>+	host->ioaddr = of_iomap(np, 0);
>+	if (!host->ioaddr) {
>+		ret = -ENOMEM;
>+		goto err_addr_map;
>+	}
>+
>+	host->irq = irq_of_parse_and_map(np, 0);
>+	if (!host->irq) {
>+		ret = -EINVAL;
>+		goto err_no_irq;
>+	}
>+
>+	host->hw_name = dev_name(&ofdev->dev);
>+	if (sdhci_of_data) {
>+		host->quirks = sdhci_of_data->quirks;
>+		host->ops = &sdhci_of_data->ops;
>+	}
>+
>+	clk = of_get_property(np, "clock-frequency", &size);
>+	if (clk && size == sizeof(*clk) && *clk)
>+		of_host->clock = *clk;
>+
>+	ret = sdhci_add_host(host);
>+	if (ret)
>+		goto err_add_host;
>+
>+	return 0;
>+
>+err_add_host:
>+	irq_dispose_mapping(host->irq);
>+err_no_irq:
>+	iounmap(host->ioaddr);
>+err_addr_map:
>+	sdhci_free_host(host);
>+	return ret;
>+}
>+
>+static int __devexit sdhci_of_remove(struct of_device *ofdev)
>+{
>+	struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);
>+
>+	sdhci_remove_host(host, 0);
>+	sdhci_free_host(host);
>+	irq_dispose_mapping(host->irq);
>+	iounmap(host->ioaddr);
>+	return 0;
>+}
>+
>+static const struct of_device_id sdhci_of_match[] = {
>+	{ .compatible = "fsl,mpc8379-esdhc", .data = &sdhci_esdhc, },
>+	{ .compatible = "fsl,mpc8536-esdhc", .data = &sdhci_esdhc, },
>+	{ .compatible = "generic-sdhci", },
>+	{},
>+};
>+MODULE_DEVICE_TABLE(of, sdhci_of_match);
>+
>+static struct of_platform_driver sdhci_of_driver = {
>+	.driver.name = "sdhci-of",
>+	.match_table = sdhci_of_match,
>+	.probe = sdhci_of_probe,
>+	.remove = __devexit_p(sdhci_of_remove),
>+	.suspend = sdhci_of_suspend,
>+	.resume	= sdhci_of_resume,
>+};
>+
>+static int __init sdhci_of_init(void)
>+{
>+	return of_register_platform_driver(&sdhci_of_driver);
>+}
>+module_init(sdhci_of_init);
>+
>+static void __exit sdhci_of_exit(void)
>+{
>+	of_unregister_platform_driver(&sdhci_of_driver);
>+}
>+module_exit(sdhci_of_exit);
>+
>+MODULE_DESCRIPTION("Secure Digital Host Controller Interface OF driver");
>+MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
>+	      "Anton Vorontsov <avorontsov@ru.mvista.com>");
>+MODULE_LICENSE("GPL");
>-- 
>1.5.6.5
>_______________________________________________
>Linuxppc-dev mailing list
>Linuxppc-dev@ozlabs.org
>https://ozlabs.org/mailman/listinfo/linuxppc-dev

----
yamazaki-seiji@jcom.home.ne.jp
Anton Vorontsov March 20, 2009, 10:43 p.m. UTC | #2
Hi!

On Fri, Mar 20, 2009 at 08:28:39AM +0900, yamazaki wrote:
> Hi all,
> 
> I am running the Linux kernel 2.6.28.7 on my PPC8347 BRD.
> I have to write the driver of SDHCI driver(using R5C807 RICOH). 

RICOH? It should be a PCI SD/MMC controller, so you even don't
need any patches to make it work in 2.6.28.7. Just make sure your
.config file has following symbols enabled:

CONFIG_MMC_SDHCI=y
CONFIG_MMC_SDHCI_PCI=y
CONFIG_MMC_RICOH_MMC=y
yamazaki March 21, 2009, 12:15 a.m. UTC | #3
Hi 

Thank you for your reply.
I know RICOH has PCI SD/MMC controller. But R5C807 RICOH is not the PCI device
which is probably new product.

I made the "sdhci-of.c" from patch file,then I compiled it.
But is was not succeeded.
I thought the reason is the format of "the struct sdhci_of_data" is defferent from the 
kernel 2.6.28.7,
That is why I sent this question.

>Hi!
>
>On Fri, Mar 20, 2009 at 08:28:39AM +0900, yamazaki wrote:
>> Hi all,
>> 
>> I am running the Linux kernel 2.6.28.7 on my PPC8347 BRD.
>> I have to write the driver of SDHCI driver(using R5C807 RICOH). 
>
>RICOH? It should be a PCI SD/MMC controller, so you even don't
>need any patches to make it work in 2.6.28.7. Just make sure your
>.config file has following symbols enabled:
>
>CONFIG_MMC_SDHCI=y
>CONFIG_MMC_SDHCI_PCI=y
>CONFIG_MMC_RICOH_MMC=y
>
>-- 
>Anton Vorontsov
>email: cbouatmailru@gmail.com
>irc://irc.freenode.net/bd2
>_______________________________________________
>Linuxppc-dev mailing list
>Linuxppc-dev@ozlabs.org
>https://ozlabs.org/mailman/listinfo/linuxppc-dev

----
yamazaki-seiji@jcom.home.ne.jp
Anton Vorontsov March 21, 2009, 12:45 a.m. UTC | #4
On Sat, Mar 21, 2009 at 09:15:25AM +0900, yamazaki wrote:
> Hi 
> 
> Thank you for your reply.
> I know RICOH has PCI SD/MMC controller. But R5C807 RICOH is not the PCI device
> which is probably new product.

Ah, then it must be connected via MPC8347's localbus.

Well, then you need 2.6.29-rcX kernels, for example
http://www.kernel.org/pub/linux/kernel/v2.6/testing/linux-2.6.29-rc8.tar.bz2
is suitable.

Untar it and apply the patches (they'll apply fine on that
kernel). Then you'll need some device tree additions for
your MPC8347 board, something like this:

        localbus@e0005000 {
                #address-cells = <2>;
                #size-cells = <1>;
                compatible = "fsl,mpc8347-localbus",
                             "fsl,pq2pro-localbus";
                reg = <0xe0005000 0xd8>;
                ranges = <0x1 0x0 0xf0000000 0x1000>;
		// ^^ change the 0xf0000000 to the actual address
                sdhci@1,0 {
                        compatible = "ricoh,r5c807", "generic-sdhci";
                        reg = <0x1 0x0 0x1000>;
                        interrupts = <ricoh-interrupt-here 0x8>;
                        interrupt-parent = <&ipic>;
                        // if needed, clock-frequency = <freq-in-HZ-here>;
                };
        };

Note that I'm not sure what endiannes you'll get when connecting
the ricoh chip to the big-endinan host...
yamazaki March 21, 2009, 7:47 a.m. UTC | #5
Hi 

Thank you for your reply again.

>Ah, then it must be connected via MPC8347's localbus.

That's right.

I will try it,and I inform them of the result. 

>On Sat, Mar 21, 2009 at 09:15:25AM +0900, yamazaki wrote:
>> Hi 
>> 
>> Thank you for your reply.
>> I know RICOH has PCI SD/MMC controller. But R5C807 RICOH is not the PCI device
>> which is probably new product.
>
>Ah, then it must be connected via MPC8347's localbus.
>
>Well, then you need 2.6.29-rcX kernels, for example
>http://www.kernel.org/pub/linux/kernel/v2.6/testing/linux-2.6.29-rc8.tar.bz2
>is suitable.
>
>Untar it and apply the patches (they'll apply fine on that
>kernel). Then you'll need some device tree additions for
>your MPC8347 board, something like this:
>
>        localbus@e0005000 {
>                #address-cells = <2>;
>                #size-cells = <1>;
>                compatible = "fsl,mpc8347-localbus",
>                             "fsl,pq2pro-localbus";
>                reg = <0xe0005000 0xd8>;
>                ranges = <0x1 0x0 0xf0000000 0x1000>;
>		// ^^ change the 0xf0000000 to the actual address
>                sdhci@1,0 {
>                        compatible = "ricoh,r5c807", "generic-sdhci";
>                        reg = <0x1 0x0 0x1000>;
>                        interrupts = <ricoh-interrupt-here 0x8>;
>                        interrupt-parent = <&ipic>;
>                        // if needed, clock-frequency = <freq-in-HZ-here>;
>                };
>        };
>
>Note that I'm not sure what endiannes you'll get when connecting
>the ricoh chip to the big-endinan host...
>
>-- 
>Anton Vorontsov
>email: cbouatmailru@gmail.com
>irc://irc.freenode.net/bd2

----
yamazaki-seiji@jcom.home.ne.jp
山崎 精二 March 23, 2009, 6:34 a.m. UTC | #6
Hi 

I downloaded linux-2.6.29-rc8.tar.bz2,and I patched .
I was succeeded. Thank you very match.
But I have the other problem.

Compile was not succeeded.

Message is ...

 CALL    arch/powerpc/kernel/prom_init_check.sh
  CC      drivers/mmc/host/sdhci-of.o
drivers/mmc/host/sdhci-of.c:163: error: 'SDHCI_QUIRK_FORCE_BLK_SZ_2048' undeclared here (not in a function)
drivers/mmc/host/sdhci-of.c:164: error: 'SDHCI_QUIRK_BROKEN_CARD_DETECTION' undeclared here (not in a function)
drivers/mmc/host/sdhci-of.c:165: error: 'SDHCI_QUIRK_INVERTED_WRITE_PROTECT' undeclared here (not in a function)
drivers/mmc/host/sdhci-of.c:167: error: 'SDHCI_QUIRK_NONSTANDARD_CLOCK' undeclared here (not in a function)
drivers/mmc/host/sdhci-of.c:168: error: 'SDHCI_QUIRK_PIO_NEEDS_DELAY' undeclared here (not in a function)
drivers/mmc/host/sdhci-of.c:169: error: 'SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET' undeclared here (not in a function)
drivers/mmc/host/sdhci-of.c:172: error: unknown field 'readl' specified in initializer
drivers/mmc/host/sdhci-of.c:172: warning: initialization from incompatible pointer type
drivers/mmc/host/sdhci-of.c:173: error: unknown field 'readw' specified in initializer
drivers/mmc/host/sdhci-of.c:173: warning: excess elements in struct initializer
drivers/mmc/host/sdhci-of.c:173: warning: (near initialization for 'sdhci_esdhc.ops')
drivers/mmc/host/sdhci-of.c:174: error: unknown field 'readb' specified in initializer
drivers/mmc/host/sdhci-of.c:174: warning: excess elements in struct initializer
drivers/mmc/host/sdhci-of.c:174: warning: (near initialization for 'sdhci_esdhc.ops')
drivers/mmc/host/sdhci-of.c:175: error: unknown field 'writel' specified in initializer
drivers/mmc/host/sdhci-of.c:175: warning: excess elements in struct initializer
drivers/mmc/host/sdhci-of.c:175: warning: (near initialization for 'sdhci_esdhc.ops')
drivers/mmc/host/sdhci-of.c:176: error: unknown field 'writew' specified in initializer
drivers/mmc/host/sdhci-of.c:176: warning: excess elements in struct initializer
drivers/mmc/host/sdhci-of.c:176: warning: (near initialization for 'sdhci_esdhc.ops')
drivers/mmc/host/sdhci-of.c:177: error: unknown field 'writeb' specified in initializer
drivers/mmc/host/sdhci-of.c:177: warning: excess elements in struct initializer
drivers/mmc/host/sdhci-of.c:177: warning: (near initialization for 'sdhci_esdhc.ops')
drivers/mmc/host/sdhci-of.c:178: error: unknown field 'set_clock' specified in initializer
drivers/mmc/host/sdhci-of.c:178: warning: excess elements in struct initializer
drivers/mmc/host/sdhci-of.c:178: warning: (near initialization for 'sdhci_esdhc.ops')
drivers/mmc/host/sdhci-of.c:180: error: unknown field 'get_max_clock' specified in initializer
drivers/mmc/host/sdhci-of.c:180: warning: excess elements in struct initializer
drivers/mmc/host/sdhci-of.c:180: warning: (near initialization for 'sdhci_esdhc.ops')
drivers/mmc/host/sdhci-of.c:181: error: unknown field 'get_timeout_clock' specified in initializer
drivers/mmc/host/sdhci-of.c:181: warning: excess elements in struct initializer
drivers/mmc/host/sdhci-of.c:181: warning: (near initialization for 'sdhci_esdhc.ops')
make[3]: *** [drivers/mmc/host/sdhci-of.o] Error 1
make[2]: *** [drivers/mmc/host] Error 2
make[1]: *** [drivers/mmc] Error 2
make: *** [drivers] Error 2

I do not know why. Could you please tell us why.
Thanks.

On Sat, 21 Mar 2009 03:45:06 +0300
Anton Vorontsov <avorontsov@ru.mvista.com> wrote:

> On Sat, Mar 21, 2009 at 09:15:25AM +0900, yamazaki wrote:
> > Hi 
> > 
> > Thank you for your reply.
> > I know RICOH has PCI SD/MMC controller. But R5C807 RICOH is not the PCI device
> > which is probably new product.
> 
> Ah, then it must be connected via MPC8347's localbus.
> 
> Well, then you need 2.6.29-rcX kernels, for example
> http://www.kernel.org/pub/linux/kernel/v2.6/testing/linux-2.6.29-rc8.tar.bz2
> is suitable.
> 
> Untar it and apply the patches (they'll apply fine on that
> kernel). Then you'll need some device tree additions for
> your MPC8347 board, something like this:
> 
>         localbus@e0005000 {
>                 #address-cells = <2>;
>                 #size-cells = <1>;
>                 compatible = "fsl,mpc8347-localbus",
>                              "fsl,pq2pro-localbus";
>                 reg = <0xe0005000 0xd8>;
>                 ranges = <0x1 0x0 0xf0000000 0x1000>;
> 		// ^^ change the 0xf0000000 to the actual address
>                 sdhci@1,0 {
>                         compatible = "ricoh,r5c807", "generic-sdhci";
>                         reg = <0x1 0x0 0x1000>;
>                         interrupts = <ricoh-interrupt-here 0x8>;
>                         interrupt-parent = <&ipic>;
>                         // if needed, clock-frequency = <freq-in-HZ-here>;
>                 };
>         };
> 
> Note that I'm not sure what endiannes you'll get when connecting
> the ricoh chip to the big-endinan host...
> 
> -- 
> Anton Vorontsov
> email: cbouatmailru@gmail.com
> irc://irc.freenode.net/bd2
山崎 精二 March 23, 2009, 9:24 a.m. UTC | #7
Hi

> The patch might be fine, but are you receiving this without the patch?

Befor patch,no sdhci-of.c found.
After patch,found sdhci-of.c.

> if you receive this with the patch then well there you go, but if this
> happens as a result with a clean fresh .tar.ball(vanilla kernel) then this 
> is something
> else.
> 

I got the kernel from
Well, then you need 2.6.29-rcX kernels, for example
http://www.kernel.org/pub/linux/kernel/v2.6/testing/linux-2.6.29-rc8.tar.bz2

I do not know why so many errors when compile.

regards,

-- Seiji Yamazaki


On Mon, 23 Mar 2009 01:43:38 -0700 (PDT)
justinmattock@gmail.com wrote:

> On Mon, 23 Mar 2009, ????? wrote:
> 
> > Hi
> >
> > I tried again form first.
> >
> > I patched like this.
> >
> > [yama@localhost Ippf]$ cd linux-2.6.29-rc8
> > [yama@localhost linux-2.6.29-rc8]$ patch -p 1 <patch.txt
> > (Stripping trailing CRs from patch.)
> > patching file MAINTAINERS
> > Hunk #1 succeeded at 3839 (offset 2 lines).
> > (Stripping trailing CRs from patch.)
> > patching file drivers/mmc/host/Kconfig
> > Hunk #1 succeeded at 65 (offset -7 lines).
> > (Stripping trailing CRs from patch.)
> > patching file drivers/mmc/host/Makefile
> > (Stripping trailing CRs from patch.)
> > patching file drivers/mmc/host/sdhci-of.c
> > [yama@localhost linux-2.6.29-rc8]$
> 
> The patch might be fine, but are you receiving this without the patch?
> 
> >
> > I Believe patch is OK.
> > And I got linux-2.6.29-rc8 kernel from kernel.org
> >
> >> What are the outcomes when not applying a patch?
> >>
> > Before applying a patch,sdhci-of.c was not exist in it.
> >
> > I attach the patch file?
> >
> > regards,
> >
> > -- Seiji Yamazaki
> >
> > On Mon, 23 Mar 2009 01:05:07 -0700 (PDT)
> > justinmattock@gmail.com wrote:
> >
> >> On Mon, 23 Mar 2009, ????? wrote:
> >>
> >>> Hi
> >>>
> >>> Sorry about it.
> >>>
> >>>> On Mon, 23 Mar 2009, ????? wrote:
> >>>
> >>> ????? is Japanese language.
> >>>
> >>>> my guess is one of the header files has a changed definition
> >>>> and/or you're missing the file completely.
> >>>> (but could be wrong);
> >>>
> >>> I tried to grep SDHCI_QUIRK_FORCE_BLK_SZ_2048 on linux-2.6.29-rc8.
> >>> But no found execpt sdhci-of.c.
> >>> Does anybody know why?
> >>
> >> well I guess this is where you have to work from.
> >> (but then after contemplating you did add a patch right?)
> >>
> >>
> >>>
> >>> regards,
> >>>
> >>> -- Seiji Yamazaki
> >>>
> >>> On Mon, 23 Mar 2009 00:14:23 -0700 (PDT)
> >>> justinmattock@gmail.com wrote:
> >>>
> >>>> On Mon, 23 Mar 2009, ????? wrote:
> >>>>
> >>>>> Hi
> >>>>>
> >>>>> I downloaded linux-2.6.29-rc8.tar.bz2,and I patched .
> >>>>> I was succeeded. Thank you very match.
> >>>>> But I have the other problem.
> >>>>>
> >>>>> Compile was not succeeded.
> >>>>>
> >>>>> Message is ...
> >>>>>
> >>>>> CALL    arch/powerpc/kernel/prom_init_check.sh
> >>>>>  CC      drivers/mmc/host/sdhci-of.o
> >>>>> drivers/mmc/host/sdhci-of.c:163: error: 'SDHCI_QUIRK_FORCE_BLK_SZ_2048' undeclared here (not in a function)
> >>>>> drivers/mmc/host/sdhci-of.c:164: error: 'SDHCI_QUIRK_BROKEN_CARD_DETECTION' undeclared here (not in a function)
> >>>>> drivers/mmc/host/sdhci-of.c:165: error: 'SDHCI_QUIRK_INVERTED_WRITE_PROTECT' undeclared here (not in a function)
> >>>>> drivers/mmc/host/sdhci-of.c:167: error: 'SDHCI_QUIRK_NONSTANDARD_CLOCK' undeclared here (not in a function)
> >>>>> drivers/mmc/host/sdhci-of.c:168: error: 'SDHCI_QUIRK_PIO_NEEDS_DELAY' undeclared here (not in a function)
> >>>>> drivers/mmc/host/sdhci-of.c:169: error: 'SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET' undeclared here (not in a function)
> >>>>> drivers/mmc/host/sdhci-of.c:172: error: unknown field 'readl' specified in initializer
> >>>>> drivers/mmc/host/sdhci-of.c:172: warning: initialization from incompatible pointer type
> >>>>> drivers/mmc/host/sdhci-of.c:173: error: unknown field 'readw' specified in initializer
> >>>>> drivers/mmc/host/sdhci-of.c:173: warning: excess elements in struct initializer
> >>>>> drivers/mmc/host/sdhci-of.c:173: warning: (near initialization for 'sdhci_esdhc.ops')
> >>>>> drivers/mmc/host/sdhci-of.c:174: error: unknown field 'readb' specified in initializer
> >>>>> drivers/mmc/host/sdhci-of.c:174: warning: excess elements in struct initializer
> >>>>> drivers/mmc/host/sdhci-of.c:174: warning: (near initialization for 'sdhci_esdhc.ops')
> >>>>> drivers/mmc/host/sdhci-of.c:175: error: unknown field 'writel' specified in initializer
> >>>>> drivers/mmc/host/sdhci-of.c:175: warning: excess elements in struct initializer
> >>>>> drivers/mmc/host/sdhci-of.c:175: warning: (near initialization for 'sdhci_esdhc.ops')
> >>>>> drivers/mmc/host/sdhci-of.c:176: error: unknown field 'writew' specified in initializer
> >>>>> drivers/mmc/host/sdhci-of.c:176: warning: excess elements in struct initializer
> >>>>> drivers/mmc/host/sdhci-of.c:176: warning: (near initialization for 'sdhci_esdhc.ops')
> >>>>> drivers/mmc/host/sdhci-of.c:177: error: unknown field 'writeb' specified in initializer
> >>>>> drivers/mmc/host/sdhci-of.c:177: warning: excess elements in struct initializer
> >>>>> drivers/mmc/host/sdhci-of.c:177: warning: (near initialization for 'sdhci_esdhc.ops')
> >>>>> drivers/mmc/host/sdhci-of.c:178: error: unknown field 'set_clock' specified in initializer
> >>>>> drivers/mmc/host/sdhci-of.c:178: warning: excess elements in struct initializer
> >>>>> drivers/mmc/host/sdhci-of.c:178: warning: (near initialization for 'sdhci_esdhc.ops')
> >>>>> drivers/mmc/host/sdhci-of.c:180: error: unknown field 'get_max_clock' specified in initializer
> >>>>> drivers/mmc/host/sdhci-of.c:180: warning: excess elements in struct initializer
> >>>>> drivers/mmc/host/sdhci-of.c:180: warning: (near initialization for 'sdhci_esdhc.ops')
> >>>>> drivers/mmc/host/sdhci-of.c:181: error: unknown field 'get_timeout_clock' specified in initializer
> >>>>> drivers/mmc/host/sdhci-of.c:181: warning: excess elements in struct initializer
> >>>>> drivers/mmc/host/sdhci-of.c:181: warning: (near initialization for 'sdhci_esdhc.ops')
> >>>>> make[3]: *** [drivers/mmc/host/sdhci-of.o] Error 1
> >>>>> make[2]: *** [drivers/mmc/host] Error 2
> >>>>> make[1]: *** [drivers/mmc] Error 2
> >>>>> make: *** [drivers] Error 2
> >>>>>
> >>>>> I do not know why. Could you please tell us why.
> >>>>> Thanks.
> >>>>>
> >>>>> On Sat, 21 Mar 2009 03:45:06 +0300
> >>>>> Anton Vorontsov <avorontsov@ru.mvista.com> wrote:
> >>>>>
> >>>>>> On Sat, Mar 21, 2009 at 09:15:25AM +0900, yamazaki wrote:
> >>>>>>> Hi
> >>>>>>>
> >>>>>>> Thank you for your reply.
> >>>>>>> I know RICOH has PCI SD/MMC controller. But R5C807 RICOH is not the PCI device
> >>>>>>> which is probably new product.
> >>>>>>
> >>>>>> Ah, then it must be connected via MPC8347's localbus.
> >>>>>>
> >>>>>> Well, then you need 2.6.29-rcX kernels, for example
> >>>>>> http://www.kernel.org/pub/linux/kernel/v2.6/testing/linux-2.6.29-rc8.tar.bz2
> >>>>>> is suitable.
> >>>>>>
> >>>>>> Untar it and apply the patches (they'll apply fine on that
> >>>>>> kernel). Then you'll need some device tree additions for
> >>>>>> your MPC8347 board, something like this:
> >>>>>>
> >>>>>>         localbus@e0005000 {
> >>>>>>                 #address-cells = <2>;
> >>>>>>                 #size-cells = <1>;
> >>>>>>                 compatible = "fsl,mpc8347-localbus",
> >>>>>>                              "fsl,pq2pro-localbus";
> >>>>>>                 reg = <0xe0005000 0xd8>;
> >>>>>>                 ranges = <0x1 0x0 0xf0000000 0x1000>;
> >>>>>> 		// ^^ change the 0xf0000000 to the actual address
> >>>>>>                 sdhci@1,0 {
> >>>>>>                         compatible = "ricoh,r5c807", "generic-sdhci";
> >>>>>>                         reg = <0x1 0x0 0x1000>;
> >>>>>>                         interrupts = <ricoh-interrupt-here 0x8>;
> >>>>>>                         interrupt-parent = <&ipic>;
> >>>>>>                         // if needed, clock-frequency = <freq-in-HZ-here>;
> >>>>>>                 };
> >>>>>>         };
> >>>>>>
> >>>>>> Note that I'm not sure what endiannes you'll get when connecting
> >>>>>> the ricoh chip to the big-endinan host...
> >>>>>>
> >>>>>> --
> >>>>>> Anton Vorontsov
> >>>>>> email: cbouatmailru@gmail.com
> >>>>>> irc://irc.freenode.net/bd2
> >>>>>
> >>>>> --
> >>>>> ????? <yamazaki.seiji@kk.jp.panasonic.com>
> >>>>>
> >>>>> --
> >>>>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> >>>>> the body of a message to majordomo@vger.kernel.org
> >>>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >>>>> Please read the FAQ at  http://www.tux.org/lkml/
> >>>>>
> >>>>
> >>>> my guess is one of the header files has a changed definition
> >>>> and/or you're missing the file completely.
> >>>> (but could be wrong);
> >>>>
> >>>> regards,
> >>>>
> >>>> -- Justin P. Mattock
> >>>
> >>> --
> >>> ????? <yamazaki.seiji@kk.jp.panasonic.com>
> >>>
> >>>
> >>
> >> What are the outcomes when not applying a patch?
> >>
> >> regards,
> >>
> >>
> >> -- Justin P. Mattock
> >
> > -- 
> > ????? <yamazaki.seiji@kk.jp.panasonic.com>
> >
> 
> if you receive this with the patch then well there you go, but if this
> happens as a result with a clean fresh .tar.ball(vanilla kernel) then this 
> is something
> else.
> 
> regards,
> 
> -- Justin P. Mattock
Anton Vorontsov March 23, 2009, 4:16 p.m. UTC | #8
On Mon, Mar 23, 2009 at 03:34:45PM +0900, 山崎 精二 wrote:
> Hi 
> 
> I downloaded linux-2.6.29-rc8.tar.bz2,and I patched .
> I was succeeded. Thank you very match.
> But I have the other problem.
> 
> Compile was not succeeded.
> 
> Message is ...
> 
>  CALL    arch/powerpc/kernel/prom_init_check.sh
>   CC      drivers/mmc/host/sdhci-of.o
> drivers/mmc/host/sdhci-of.c:163: error: 'SDHCI_QUIRK_FORCE_BLK_SZ_2048' undeclared here (not in a function)
> drivers/mmc/host/sdhci-of.c:164: error: 'SDHCI_QUIRK_BROKEN_CARD_DETECTION' undeclared here (not in a function)
> drivers/mmc/host/sdhci-of.c:165: error: 'SDHCI_QUIRK_INVERTED_WRITE_PROTECT' undeclared here (not in a function)
> drivers/mmc/host/sdhci-of.c:167: error: 'SDHCI_QUIRK_NONSTANDARD_CLOCK' undeclared here (not in a function)
> drivers/mmc/host/sdhci-of.c:168: error: 'SDHCI_QUIRK_PIO_NEEDS_DELAY' undeclared here (not in a function)
> drivers/mmc/host/sdhci-of.c:169: error: 'SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET' undeclared here (not in a function)
[...]
> drivers/mmc/host/sdhci-of.c:181: warning: excess elements in struct initializer
> drivers/mmc/host/sdhci-of.c:181: warning: (near initialization for 'sdhci_esdhc.ops')
> make[3]: *** [drivers/mmc/host/sdhci-of.o] Error 1
> make[2]: *** [drivers/mmc/host] Error 2
> make[1]: *** [drivers/mmc] Error 2

All these errors indicate that you didn't apply all the patches.
You'll need all 11 patches from this series, not only the last
one.
diff mbox

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index 4a1cfca..77c3ec0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3837,6 +3837,13 @@  M:	drzeus-sdhci@drzeus.cx
 L:	sdhci-devel@list.drzeus.cx
 S:	Maintained
 
+SECURE DIGITAL HOST CONTROLLER INTERFACE, OPEN FIRMWARE BINDINGS (SDHCI-OF)
+P:	Anton Vorontsov
+M:	avorontsov@ru.mvista.com
+L:	linuxppc-dev@ozlabs.org
+L:	sdhci-devel@list.drzeus.cx
+S:	Maintained
+
 SECURITY SUBSYSTEM
 F:	security/
 P:	James Morris
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index e032a42..69bd124 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -72,6 +72,17 @@  config MMC_RICOH_MMC
 
 	  If unsure, say Y.
 
+config MMC_SDHCI_OF
+	tristate "SDHCI support on OpenFirmware platforms"
+	depends on MMC_SDHCI && PPC_OF
+	select MMC_SDHCI_IO_ACCESSORS
+	help
+	  This selects the OF support for Secure Digital Host Controller
+	  Interfaces. So far, only the Freescale eSDHC controller is known
+	  to exist on OF platforms.
+
+	  If unsure, say N.
+
 config MMC_OMAP
 	tristate "TI OMAP Multimedia Card Interface support"
 	depends on ARCH_OMAP
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index dedec55..dd512d9 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -13,6 +13,7 @@  obj-$(CONFIG_MMC_MXC)		+= mxcmmc.o
 obj-$(CONFIG_MMC_SDHCI)		+= sdhci.o
 obj-$(CONFIG_MMC_SDHCI_PCI)	+= sdhci-pci.o
 obj-$(CONFIG_MMC_RICOH_MMC)	+= ricoh_mmc.o
+obj-$(CONFIG_MMC_SDHCI_OF)	+= sdhci-of.o
 obj-$(CONFIG_MMC_WBSD)		+= wbsd.o
 obj-$(CONFIG_MMC_AU1X)		+= au1xmmc.o
 obj-$(CONFIG_MMC_OMAP)		+= omap.o
diff --git a/drivers/mmc/host/sdhci-of.c b/drivers/mmc/host/sdhci-of.c
new file mode 100644
index 0000000..3ff4ac3
--- /dev/null
+++ b/drivers/mmc/host/sdhci-of.c
@@ -0,0 +1,309 @@ 
+/*
+ * OpenFirmware bindings for Secure Digital Host Controller Interface.
+ *
+ * Copyright (c) 2007 Freescale Semiconductor, Inc.
+ * Copyright (c) 2009 MontaVista Software, Inc.
+ *
+ * Authors: Xiaobo Xie <X.Xie@freescale.com>
+ *	    Anton Vorontsov <avorontsov@ru.mvista.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/mmc/host.h>
+#include "sdhci.h"
+
+struct sdhci_of_data {
+	unsigned int quirks;
+	struct sdhci_ops ops;
+};
+
+struct sdhci_of_host {
+	unsigned int clock;
+	u16 xfer_mode_shadow;
+};
+
+/*
+ * Ops and quirks for the Freescale eSDHC controller.
+ */
+
+#define ESDHC_DMA_SYSCTL	0x40c
+#define ESDHC_DMA_SNOOP		0x00000040
+
+#define ESDHC_SYSTEM_CONTROL	0x2c
+#define ESDHC_CLOCK_MASK	0x0000fff0
+#define ESDHC_PREDIV_SHIFT	8
+#define ESDHC_DIVIDER_SHIFT	4
+#define ESDHC_CLOCK_PEREN	0x00000004
+#define ESDHC_CLOCK_HCKEN	0x00000002
+#define ESDHC_CLOCK_IPGEN	0x00000001
+
+static u32 esdhc_readl(struct sdhci_host *host, int reg)
+{
+	return in_be32(host->ioaddr + reg);
+}
+
+static u16 esdhc_readw(struct sdhci_host *host, int reg)
+{
+	return in_be16(host->ioaddr + (reg ^ 0x2));
+}
+
+static u8 esdhc_readb(struct sdhci_host *host, int reg)
+{
+	return in_8(host->ioaddr + (reg ^ 0x3));
+}
+
+static void esdhc_writel(struct sdhci_host *host, u32 val, int reg)
+{
+	out_be32(host->ioaddr + reg, val);
+}
+
+static void esdhc_writew(struct sdhci_host *host, u16 val, int reg)
+{
+	struct sdhci_of_host *of_host = sdhci_priv(host);
+	int base = reg & ~0x3;
+	int shift = (reg & 0x2) * 8;
+
+	switch (reg) {
+	case SDHCI_TRANSFER_MODE:
+		/*
+		 * Postpone this write, we must do it together with a
+		 * command write that is down below.
+		 */
+		of_host->xfer_mode_shadow = val;
+		return;
+	case SDHCI_COMMAND:
+		esdhc_writel(host, val << 16 | of_host->xfer_mode_shadow,
+			     SDHCI_TRANSFER_MODE);
+		return;
+	case SDHCI_BLOCK_SIZE:
+		/*
+		 * Two last DMA bits are reserved, and first one is used for
+		 * non-standard blksz of 4096 bytes that we don't support
+		 * yet. So clear the DMA boundary bits.
+		 */
+		val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
+		/* fall through */
+	}
+	clrsetbits_be32(host->ioaddr + base, 0xffff << shift, val << shift);
+}
+
+static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg)
+{
+	int base = reg & ~0x3;
+	int shift = (reg & 0x3) * 8;
+
+	clrsetbits_be32(host->ioaddr + base , 0xff << shift, val << shift);
+}
+
+static void esdhc_set_clock(struct sdhci_host *host, unsigned int clock)
+{
+	int div;
+	int pre_div = 2;
+
+	clrbits32(host->ioaddr + ESDHC_SYSTEM_CONTROL, ESDHC_CLOCK_IPGEN |
+		  ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK);
+
+	if (clock == 0)
+		goto out;
+
+	if (host->max_clk / 16 > clock) {
+		for (; pre_div < 256; pre_div *= 2) {
+			if (host->max_clk / pre_div < clock * 16)
+				break;
+		}
+	}
+
+	for (div = 1; div <= 16; div++) {
+		if (host->max_clk / (div * pre_div) <= clock)
+			break;
+	}
+
+	pre_div >>= 1;
+
+	setbits32(host->ioaddr + ESDHC_SYSTEM_CONTROL, ESDHC_CLOCK_IPGEN |
+		  ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN |
+		  div << ESDHC_DIVIDER_SHIFT | pre_div << ESDHC_PREDIV_SHIFT);
+	mdelay(100);
+out:
+	host->clock = clock;
+}
+
+static int esdhc_enable_dma(struct sdhci_host *host)
+{
+	setbits32(host->ioaddr + ESDHC_DMA_SYSCTL, ESDHC_DMA_SNOOP);
+	return 0;
+}
+
+static unsigned int esdhc_get_max_clock(struct sdhci_host *host)
+{
+	struct sdhci_of_host *of_host = sdhci_priv(host);
+
+	return of_host->clock;
+}
+
+static unsigned int esdhc_get_timeout_clock(struct sdhci_host *host)
+{
+	struct sdhci_of_host *of_host = sdhci_priv(host);
+
+	return of_host->clock / 1000;
+}
+
+static struct sdhci_of_data sdhci_esdhc = {
+	.quirks = SDHCI_QUIRK_FORCE_BLK_SZ_2048 |
+		  SDHCI_QUIRK_BROKEN_CARD_DETECTION |
+		  SDHCI_QUIRK_INVERTED_WRITE_PROTECT |
+		  SDHCI_QUIRK_NO_BUSY_IRQ |
+		  SDHCI_QUIRK_NONSTANDARD_CLOCK |
+		  SDHCI_QUIRK_PIO_NEEDS_DELAY |
+		  SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET |
+		  SDHCI_QUIRK_NO_CARD_NO_RESET,
+	.ops = {
+		.readl = esdhc_readl,
+		.readw = esdhc_readw,
+		.readb = esdhc_readb,
+		.writel = esdhc_writel,
+		.writew = esdhc_writew,
+		.writeb = esdhc_writeb,
+		.set_clock = esdhc_set_clock,
+		.enable_dma = esdhc_enable_dma,
+		.get_max_clock = esdhc_get_max_clock,
+		.get_timeout_clock = esdhc_get_timeout_clock,
+	},
+};
+
+#ifdef CONFIG_PM
+
+static int sdhci_of_suspend(struct of_device *ofdev, pm_message_t state)
+{
+	struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);
+
+	return mmc_suspend_host(host->mmc, state);
+}
+
+static int sdhci_of_resume(struct of_device *ofdev)
+{
+	struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);
+
+	return mmc_resume_host(host->mmc);
+}
+
+#else
+
+#define sdhci_of_suspend NULL
+#define sdhci_of_resume NULL
+
+#endif
+
+static int __devinit sdhci_of_probe(struct of_device *ofdev,
+				 const struct of_device_id *match)
+{
+	struct device_node *np = ofdev->node;
+	struct sdhci_of_data *sdhci_of_data = match->data;
+	struct sdhci_host *host;
+	struct sdhci_of_host *of_host;
+	const u32 *clk;
+	int size;
+	int ret;
+
+	if (!of_device_is_available(np))
+		return -ENODEV;
+
+	host = sdhci_alloc_host(&ofdev->dev, sizeof(*of_host));
+	if (!host)
+		return -ENOMEM;
+
+	of_host = sdhci_priv(host);
+	dev_set_drvdata(&ofdev->dev, host);
+
+	host->ioaddr = of_iomap(np, 0);
+	if (!host->ioaddr) {
+		ret = -ENOMEM;
+		goto err_addr_map;
+	}
+
+	host->irq = irq_of_parse_and_map(np, 0);
+	if (!host->irq) {
+		ret = -EINVAL;
+		goto err_no_irq;
+	}
+
+	host->hw_name = dev_name(&ofdev->dev);
+	if (sdhci_of_data) {
+		host->quirks = sdhci_of_data->quirks;
+		host->ops = &sdhci_of_data->ops;
+	}
+
+	clk = of_get_property(np, "clock-frequency", &size);
+	if (clk && size == sizeof(*clk) && *clk)
+		of_host->clock = *clk;
+
+	ret = sdhci_add_host(host);
+	if (ret)
+		goto err_add_host;
+
+	return 0;
+
+err_add_host:
+	irq_dispose_mapping(host->irq);
+err_no_irq:
+	iounmap(host->ioaddr);
+err_addr_map:
+	sdhci_free_host(host);
+	return ret;
+}
+
+static int __devexit sdhci_of_remove(struct of_device *ofdev)
+{
+	struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);
+
+	sdhci_remove_host(host, 0);
+	sdhci_free_host(host);
+	irq_dispose_mapping(host->irq);
+	iounmap(host->ioaddr);
+	return 0;
+}
+
+static const struct of_device_id sdhci_of_match[] = {
+	{ .compatible = "fsl,mpc8379-esdhc", .data = &sdhci_esdhc, },
+	{ .compatible = "fsl,mpc8536-esdhc", .data = &sdhci_esdhc, },
+	{ .compatible = "generic-sdhci", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, sdhci_of_match);
+
+static struct of_platform_driver sdhci_of_driver = {
+	.driver.name = "sdhci-of",
+	.match_table = sdhci_of_match,
+	.probe = sdhci_of_probe,
+	.remove = __devexit_p(sdhci_of_remove),
+	.suspend = sdhci_of_suspend,
+	.resume	= sdhci_of_resume,
+};
+
+static int __init sdhci_of_init(void)
+{
+	return of_register_platform_driver(&sdhci_of_driver);
+}
+module_init(sdhci_of_init);
+
+static void __exit sdhci_of_exit(void)
+{
+	of_unregister_platform_driver(&sdhci_of_driver);
+}
+module_exit(sdhci_of_exit);
+
+MODULE_DESCRIPTION("Secure Digital Host Controller Interface OF driver");
+MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
+	      "Anton Vorontsov <avorontsov@ru.mvista.com>");
+MODULE_LICENSE("GPL");