mmc: zynq: Add fdt max-frequency support
[platform/kernel/u-boot.git] / drivers / mmc / zynq_sdhci.c
index bf54219..28cedf0 100644 (file)
@@ -6,6 +6,7 @@
  * SPDX-License-Identifier:    GPL-2.0+
  */
 
+#include <clk.h>
 #include <common.h>
 #include <dm.h>
 #include <fdtdec.h>
@@ -13,6 +14,8 @@
 #include <malloc.h>
 #include <sdhci.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 #ifndef CONFIG_ZYNQ_SDHCI_MIN_FREQ
 # define CONFIG_ZYNQ_SDHCI_MIN_FREQ    0
 #endif
@@ -20,6 +23,7 @@
 struct arasan_sdhci_plat {
        struct mmc_config cfg;
        struct mmc mmc;
+       unsigned int f_max;
 };
 
 static int arasan_sdhci_probe(struct udevice *dev)
@@ -27,9 +31,29 @@ static int arasan_sdhci_probe(struct udevice *dev)
        struct arasan_sdhci_plat *plat = dev_get_platdata(dev);
        struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
        struct sdhci_host *host = dev_get_priv(dev);
-       u32 caps;
+       struct clk clk;
+       unsigned long clock;
        int ret;
 
+       ret = clk_get_by_index(dev, 0, &clk);
+       if (ret < 0) {
+               dev_err(dev, "failed to get clock\n");
+               return ret;
+       }
+
+       clock = clk_get_rate(&clk);
+       if (IS_ERR_VALUE(clock)) {
+               dev_err(dev, "failed to get rate\n");
+               return clock;
+       }
+       debug("%s: CLK %ld\n", __func__, clock);
+
+       ret = clk_enable(&clk);
+       if (ret && ret != -ENOSYS) {
+               dev_err(dev, "failed to enable clock\n");
+               return ret;
+       }
+
        host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
                       SDHCI_QUIRK_BROKEN_R1B;
 
@@ -37,10 +61,9 @@ static int arasan_sdhci_probe(struct udevice *dev)
        host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT;
 #endif
 
-       host->version = sdhci_readw(host, SDHCI_HOST_VERSION);
+       host->max_clk = clock;
 
-       caps = sdhci_readl(host, SDHCI_CAPABILITIES);
-       ret = sdhci_setup_cfg(&plat->cfg, host, CONFIG_ZYNQ_SDHCI_MAX_FREQ,
+       ret = sdhci_setup_cfg(&plat->cfg, host, plat->f_max,
                              CONFIG_ZYNQ_SDHCI_MIN_FREQ);
        host->mmc = &plat->mmc;
        if (ret)
@@ -54,24 +77,23 @@ static int arasan_sdhci_probe(struct udevice *dev)
 
 static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev)
 {
+       struct arasan_sdhci_plat *plat = dev_get_platdata(dev);
        struct sdhci_host *host = dev_get_priv(dev);
 
        host->name = dev->name;
        host->ioaddr = (void *)dev_get_addr(dev);
 
+       plat->f_max = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+                               "max-frequency", CONFIG_ZYNQ_SDHCI_MAX_FREQ);
+
        return 0;
 }
 
 static int arasan_sdhci_bind(struct udevice *dev)
 {
        struct arasan_sdhci_plat *plat = dev_get_platdata(dev);
-       int ret;
 
-       ret = sdhci_bind(dev, &plat->mmc, &plat->cfg);
-       if (ret)
-               return ret;
-
-       return 0;
+       return sdhci_bind(dev, &plat->mmc, &plat->cfg);
 }
 
 static const struct udevice_id arasan_sdhci_ids[] = {