sdhci-pltfm: add support for CNS3xxx SoC devices
authorAnton Vorontsov <avorontsov@mvista.com>
Wed, 11 Aug 2010 01:01:49 +0000 (18:01 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 11 Aug 2010 15:59:03 +0000 (08:59 -0700)
There's nothing special, just SoC-specific ops and quirks.

Signed-off-by: Anton Vorontsov <avorontsov@mvista.com>
Cc: Ben Dooks <ben@simtec.co.uk>
Cc: Richard R?jfors <richard.rojfors@pelagicore.com>
Cc: <linux-mmc@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/mmc/host/Kconfig
drivers/mmc/host/Makefile
drivers/mmc/host/sdhci-cns3xxx.c [new file with mode: 0644]
drivers/mmc/host/sdhci-pltfm.c
drivers/mmc/host/sdhci-pltfm.h

index d25e22cee4c41c921a00bbbef584083d1862a2a4..c997474c649f3cafd3477a1a86e86c1e000f2ab8 100644 (file)
@@ -121,6 +121,15 @@ config MMC_SDHCI_PLTFM
 
          If unsure, say N.
 
+config MMC_SDHCI_CNS3XXX
+       bool "SDHCI support on the Cavium Networks CNS3xxx SoC"
+       depends on ARCH_CNS3XXX
+       depends on MMC_SDHCI_PLTFM
+       help
+         This selects the SDHCI support for CNS3xxx System-on-Chip devices.
+
+         If unsure, say N.
+
 config MMC_SDHCI_S3C
        tristate "SDHCI support on Samsung S3C SoC"
        depends on MMC_SDHCI && (PLAT_S3C24XX || PLAT_S3C64XX)
index c6955d7b0eca44551ff9ffd319715c10fba58076..fe0ba4e2b8b01b1255bc64b1dd6e1548b855ed8c 100644 (file)
@@ -39,6 +39,7 @@ obj-$(CONFIG_MMC_JZ4740)      += jz4740_mmc.o
 
 obj-$(CONFIG_MMC_SDHCI_PLTFM)                  += sdhci-platform.o
 sdhci-platform-y                               := sdhci-pltfm.o
+sdhci-platform-$(CONFIG_MMC_SDHCI_CNS3XXX)     += sdhci-cns3xxx.o
 
 obj-$(CONFIG_MMC_SDHCI_OF)     += sdhci-of.o
 sdhci-of-y                             := sdhci-of-core.o
diff --git a/drivers/mmc/host/sdhci-cns3xxx.c b/drivers/mmc/host/sdhci-cns3xxx.c
new file mode 100644 (file)
index 0000000..b7050b3
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * SDHCI support for CNS3xxx SoC
+ *
+ * Copyright 2008 Cavium Networks
+ * Copyright 2010 MontaVista Software, LLC.
+ *
+ * Authors: Scott Shu
+ *         Anton Vorontsov <avorontsov@mvista.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/mmc/host.h>
+#include <linux/sdhci-pltfm.h>
+#include <mach/cns3xxx.h>
+#include "sdhci.h"
+#include "sdhci-pltfm.h"
+
+static unsigned int sdhci_cns3xxx_get_max_clk(struct sdhci_host *host)
+{
+       return 150000000;
+}
+
+static void sdhci_cns3xxx_set_clock(struct sdhci_host *host, unsigned int clock)
+{
+       struct device *dev = mmc_dev(host->mmc);
+       int div = 1;
+       u16 clk;
+       unsigned long timeout;
+
+       if (clock == host->clock)
+               return;
+
+       sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
+
+       if (clock == 0)
+               goto out;
+
+       while (host->max_clk / div > clock) {
+               /*
+                * On CNS3xxx divider grows linearly up to 4, and then
+                * exponentially up to 256.
+                */
+               if (div < 4)
+                       div += 1;
+               else if (div < 256)
+                       div *= 2;
+               else
+                       break;
+       }
+
+       dev_dbg(dev, "desired SD clock: %d, actual: %d\n",
+               clock, host->max_clk / div);
+
+       /* Divide by 3 is special. */
+       if (div != 3)
+               div >>= 1;
+
+       clk = div << SDHCI_DIVIDER_SHIFT;
+       clk |= SDHCI_CLOCK_INT_EN;
+       sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+
+       timeout = 20;
+       while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
+                       & SDHCI_CLOCK_INT_STABLE)) {
+               if (timeout == 0) {
+                       dev_warn(dev, "clock is unstable");
+                       break;
+               }
+               timeout--;
+               mdelay(1);
+       }
+
+       clk |= SDHCI_CLOCK_CARD_EN;
+       sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
+out:
+       host->clock = clock;
+}
+
+static struct sdhci_ops sdhci_cns3xxx_ops = {
+       .get_max_clock  = sdhci_cns3xxx_get_max_clk,
+       .set_clock      = sdhci_cns3xxx_set_clock,
+};
+
+struct sdhci_pltfm_data sdhci_cns3xxx_pdata = {
+       .ops = &sdhci_cns3xxx_ops,
+       .quirks = SDHCI_QUIRK_BROKEN_DMA |
+                 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
+                 SDHCI_QUIRK_INVERTED_WRITE_PROTECT |
+                 SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN |
+                 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
+                 SDHCI_QUIRK_NONSTANDARD_CLOCK,
+};
index 4c043bb9ff1214fd7c7e9c1ba0eab6d6fe204d09..e045e3c61dde6c24f871f51c72084924bf087d62 100644 (file)
@@ -158,6 +158,9 @@ static int __devexit sdhci_pltfm_remove(struct platform_device *pdev)
 
 static const struct platform_device_id sdhci_pltfm_ids[] = {
        { "sdhci", },
+#ifdef CONFIG_MMC_SDHCI_CNS3XXX
+       { "sdhci-cns3xxx", (kernel_ulong_t)&sdhci_cns3xxx_pdata },
+#endif
        { },
 };
 MODULE_DEVICE_TABLE(platform, sdhci_pltfm_ids);
index 4aa07a918b6232687b25a0e65b8675e6106aaa8d..900f32902f7309098775d152adbbb8cfcb40ac21 100644 (file)
@@ -11,4 +11,8 @@
 #ifndef _DRIVERS_MMC_SDHCI_PLTFM_H
 #define _DRIVERS_MMC_SDHCI_PLTFM_H
 
+#include <linux/sdhci-pltfm.h>
+
+extern struct sdhci_pltfm_data sdhci_cns3xxx_pdata;
+
 #endif /* _DRIVERS_MMC_SDHCI_PLTFM_H */