drivers: mmc: add driver for Microchip PIC32 SDHCI controller.
authorAndrei Pistirica <andrei.pistirica@microchip.com>
Thu, 28 Jan 2016 10:00:18 +0000 (15:30 +0530)
committerDaniel Schwierzeck <daniel.schwierzeck@gmail.com>
Mon, 1 Feb 2016 21:14:01 +0000 (22:14 +0100)
This driver implements platform specific glue and fixups for
PIC32 internal SDHCI controller.

Signed-off-by: Andrei Pistirica <andrei.pistirica@microchip.com>
Signed-off-by: Sandeep Sheriker Mallikarjun <sandeepsheriker.mallikarjun@microchip.com>
Signed-off-by: Purna Chandra Mandal <purna.mandal@microchip.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
drivers/mmc/Kconfig
drivers/mmc/Makefile
drivers/mmc/pic32_sdhci.c [new file with mode: 0644]
drivers/mmc/sdhci.c

index ceae7bcaec6a5e3b562348b6bb8ddc2931210233..9f4b766f7a473b5b5b9d744b2c425391cba7894a 100644 (file)
@@ -31,4 +31,10 @@ config SH_SDHI
        help
          Support for the on-chip SDHI host controller on SuperH/Renesas ARM SoCs platform
 
+config PIC32_SDHCI
+       bool "Microchip PIC32 on-chip SDHCI support"
+       depends on DM_MMC && MACH_PIC32
+       help
+         Support for Microchip PIC32 SDHCI controller.
+
 endmenu
index 5d357056ddd1732b6a4f3b7013df6a667eb6588f..c9c3e3e938125aa4ee81b6a69d4a575c2d3080fa 100644 (file)
@@ -48,4 +48,4 @@ obj-$(CONFIG_SPL_MMC_BOOT) += fsl_esdhc_spl.o
 else
 obj-$(CONFIG_GENERIC_MMC) += mmc_write.o
 endif
-
+obj-$(CONFIG_PIC32_SDHCI) += pic32_sdhci.o
diff --git a/drivers/mmc/pic32_sdhci.c b/drivers/mmc/pic32_sdhci.c
new file mode 100644 (file)
index 0000000..28da55d
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Support of SDHCI for Microchip PIC32 SoC.
+ *
+ * Copyright (C) 2015 Microchip Technology Inc.
+ * Andrei Pistirica <andrei.pistirica@microchip.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <dm.h>
+#include <common.h>
+#include <sdhci.h>
+#include <asm/errno.h>
+#include <mach/pic32.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static int pic32_sdhci_probe(struct udevice *dev)
+{
+       struct sdhci_host *host = dev_get_priv(dev);
+       const void *fdt = gd->fdt_blob;
+       u32 f_min_max[2];
+       fdt_addr_t addr;
+       fdt_size_t size;
+       int ret;
+
+       addr = fdtdec_get_addr_size(fdt, dev->of_offset, "reg", &size);
+       if (addr == FDT_ADDR_T_NONE)
+               return -EINVAL;
+
+       host->ioaddr    = ioremap(addr, size);
+       host->name      = (char *)dev->name;
+       host->quirks    = SDHCI_QUIRK_NO_HISPD_BIT | SDHCI_QUIRK_NO_CD;
+       host->bus_width = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+                                       "bus-width", 4);
+
+       ret = fdtdec_get_int_array(gd->fdt_blob, dev->of_offset,
+                                  "clock-freq-min-max", f_min_max, 2);
+       if (ret) {
+               printf("sdhci: clock-freq-min-max not found\n");
+               return ret;
+       }
+
+       return add_sdhci(host, f_min_max[1], f_min_max[0]);
+}
+
+static const struct udevice_id pic32_sdhci_ids[] = {
+       { .compatible = "microchip,pic32mzda-sdhci" },
+       { }
+};
+
+U_BOOT_DRIVER(pic32_sdhci_drv) = {
+       .name                   = "pic32_sdhci",
+       .id                     = UCLASS_MMC,
+       .of_match               = pic32_sdhci_ids,
+       .probe                  = pic32_sdhci_probe,
+       .priv_auto_alloc_size   = sizeof(struct sdhci_host),
+};
index ff770b16e27a6e25c50fa6a23226832865f2e324..8586d898fdded663fb43a4386b07fd73142568d6 100644 (file)
@@ -443,6 +443,12 @@ static int sdhci_init(struct mmc *mmc)
        sdhci_set_power(host, fls(mmc->cfg->voltages) - 1);
 
        if (host->quirks & SDHCI_QUIRK_NO_CD) {
+#if defined(CONFIG_PIC32_SDHCI)
+               /* PIC32 SDHCI CD errata:
+                * - set CD_TEST and clear CD_TEST_INS bit
+                */
+               sdhci_writeb(host, SDHCI_CTRL_CD_TEST, SDHCI_HOST_CONTROL);
+#else
                unsigned int status;
 
                sdhci_writeb(host, SDHCI_CTRL_CD_TEST_INS | SDHCI_CTRL_CD_TEST,
@@ -453,6 +459,7 @@ static int sdhci_init(struct mmc *mmc)
                    (!(status & SDHCI_CARD_STATE_STABLE)) ||
                    (!(status & SDHCI_CARD_DETECT_PIN_LEVEL)))
                        status = sdhci_readl(host, SDHCI_PRESENT_STATE);
+#endif
        }
 
        /* Enable only interrupts served by the SD controller */