]> git.sur5r.net Git - u-boot/blobdiff - drivers/mmc/exynos_dw_mmc.c
mtd: nand: mxs_nand: use self init
[u-boot] / drivers / mmc / exynos_dw_mmc.c
index cfbe13552aa4f9162deca2b8f52942bfd5c62141..865fdf4dbba025bce4ca8fd81ab902a998e11a60 100644 (file)
@@ -1,21 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2012 SAMSUNG Electronics
  * Jaehoon Chung <jh80.chung@samsung.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <dwmmc.h>
 #include <fdtdec.h>
-#include <libfdt.h>
+#include <linux/libfdt.h>
 #include <malloc.h>
+#include <errno.h>
 #include <asm/arch/dwmmc.h>
 #include <asm/arch/clk.h>
 #include <asm/arch/pinmux.h>
 #include <asm/arch/power.h>
 #include <asm/gpio.h>
-#include <asm-generic/errno.h>
 
 #define        DWMMC_MAX_CH_NUM                4
 #define        DWMMC_MAX_FREQ                  52000000
 #define        DWMMC_MMC0_SDR_TIMING_VAL       0x03030001
 #define        DWMMC_MMC2_SDR_TIMING_VAL       0x03020001
 
+#ifdef CONFIG_DM_MMC
+#include <dm.h>
+DECLARE_GLOBAL_DATA_PTR;
+
+struct exynos_mmc_plat {
+       struct mmc_config cfg;
+       struct mmc mmc;
+};
+#endif
+
 /* Exynos implmentation specific drver private data */
 struct dwmci_exynos_priv_data {
+#ifdef CONFIG_DM_MMC
+       struct dwmci_host host;
+#endif
        u32 sdr_timing;
 };
 
@@ -105,11 +117,15 @@ static int exynos_dwmci_core_init(struct dwmci_host *host)
        host->caps = MMC_MODE_DDR_52MHz;
        host->clksel = exynos_dwmci_clksel;
        host->get_mmc_clk = exynos_dwmci_get_clk;
+
+#ifndef CONFIG_DM_MMC
        /* Add the mmc channel to be registered with mmc core */
        if (add_dwmci(host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ)) {
                printf("DWMMC%d registration failed\n", host->dev_index);
                return -1;
        }
+#endif
+
        return 0;
 }
 
@@ -138,7 +154,7 @@ static int exynos_dwmci_get_config(const void *blob, int node,
 
        priv = malloc(sizeof(struct dwmci_exynos_priv_data));
        if (!priv) {
-               error("dwmci_exynos_priv_data malloc fail!\n");
+               pr_err("dwmci_exynos_priv_data malloc fail!\n");
                return -ENOMEM;
        }
 
@@ -151,20 +167,18 @@ static int exynos_dwmci_get_config(const void *blob, int node,
 
        if (host->dev_index > 4) {
                printf("DWMMC%d: Can't get the dev index\n", host->dev_index);
+               free(priv);
                return -EINVAL;
        }
 
-       /* Get the bus width from the device node */
-       host->buswidth = fdtdec_get_int(blob, node, "samsung,bus-width", 0);
-       if (host->buswidth <= 0) {
-               printf("DWMMC%d: Can't get bus-width\n", host->dev_index);
-               return -EINVAL;
-       }
+       /* Get the bus width from the device node (Default is 4bit buswidth) */
+       host->buswidth = fdtdec_get_int(blob, node, "samsung,bus-width", 4);
 
        /* Set the base address from the device node */
        base = fdtdec_get_addr(blob, node, "reg");
        if (!base) {
                printf("DWMMC%d: Can't get base address\n", host->dev_index);
+               free(priv);
                return -EINVAL;
        }
        host->ioaddr = (void *)base;
@@ -174,6 +188,7 @@ static int exynos_dwmci_get_config(const void *blob, int node,
        if (err) {
                printf("DWMMC%d: Can't get sdr-timings for devider\n",
                                host->dev_index);
+               free(priv);
                return -EINVAL;
        }
 
@@ -241,3 +256,52 @@ int exynos_dwmmc_init(const void *blob)
 
        return err;
 }
+
+#ifdef CONFIG_DM_MMC
+static int exynos_dwmmc_probe(struct udevice *dev)
+{
+       struct exynos_mmc_plat *plat = dev_get_platdata(dev);
+       struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+       struct dwmci_exynos_priv_data *priv = dev_get_priv(dev);
+       struct dwmci_host *host = &priv->host;
+       int err;
+
+       err = exynos_dwmci_get_config(gd->fdt_blob, dev_of_offset(dev), host);
+       if (err)
+               return err;
+       err = do_dwmci_init(host);
+       if (err)
+               return err;
+
+       dwmci_setup_cfg(&plat->cfg, host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ);
+       host->mmc = &plat->mmc;
+       host->mmc->priv = &priv->host;
+       host->priv = dev;
+       upriv->mmc = host->mmc;
+
+       return dwmci_probe(dev);
+}
+
+static int exynos_dwmmc_bind(struct udevice *dev)
+{
+       struct exynos_mmc_plat *plat = dev_get_platdata(dev);
+
+       return dwmci_bind(dev, &plat->mmc, &plat->cfg);
+}
+
+static const struct udevice_id exynos_dwmmc_ids[] = {
+       { .compatible = "samsung,exynos4412-dw-mshc" },
+       { }
+};
+
+U_BOOT_DRIVER(exynos_dwmmc_drv) = {
+       .name           = "exynos_dwmmc",
+       .id             = UCLASS_MMC,
+       .of_match       = exynos_dwmmc_ids,
+       .bind           = exynos_dwmmc_bind,
+       .ops            = &dm_dwmci_ops,
+       .probe          = exynos_dwmmc_probe,
+       .priv_auto_alloc_size   = sizeof(struct dwmci_exynos_priv_data),
+       .platdata_auto_alloc_size = sizeof(struct exynos_mmc_plat),
+};
+#endif