2 * (C) Copyright 2013 - 2015 Xilinx, Inc.
4 * Xilinx Zynq SD Host Controller Interface
6 * SPDX-License-Identifier: GPL-2.0+
17 DECLARE_GLOBAL_DATA_PTR;
19 #ifndef CONFIG_ZYNQ_SDHCI_MIN_FREQ
20 # define CONFIG_ZYNQ_SDHCI_MIN_FREQ 0
23 struct arasan_sdhci_plat {
24 struct mmc_config cfg;
29 static int arasan_sdhci_probe(struct udevice *dev)
31 struct arasan_sdhci_plat *plat = dev_get_platdata(dev);
32 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
33 struct sdhci_host *host = dev_get_priv(dev);
38 ret = clk_get_by_index(dev, 0, &clk);
40 dev_err(dev, "failed to get clock\n");
44 clock = clk_get_rate(&clk);
45 if (IS_ERR_VALUE(clock)) {
46 dev_err(dev, "failed to get rate\n");
49 debug("%s: CLK %ld\n", __func__, clock);
51 ret = clk_enable(&clk);
52 if (ret && ret != -ENOSYS) {
53 dev_err(dev, "failed to enable clock\n");
57 host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
58 SDHCI_QUIRK_BROKEN_R1B;
60 #ifdef CONFIG_ZYNQ_HISPD_BROKEN
61 host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT;
64 host->max_clk = clock;
66 ret = sdhci_setup_cfg(&plat->cfg, host, plat->f_max,
67 CONFIG_ZYNQ_SDHCI_MIN_FREQ);
68 host->mmc = &plat->mmc;
71 host->mmc->priv = host;
73 upriv->mmc = host->mmc;
75 return sdhci_probe(dev);
78 static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev)
80 struct arasan_sdhci_plat *plat = dev_get_platdata(dev);
81 struct sdhci_host *host = dev_get_priv(dev);
83 host->name = dev->name;
84 host->ioaddr = (void *)dev_get_addr(dev);
86 plat->f_max = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
87 "max-frequency", CONFIG_ZYNQ_SDHCI_MAX_FREQ);
92 static int arasan_sdhci_bind(struct udevice *dev)
94 struct arasan_sdhci_plat *plat = dev_get_platdata(dev);
96 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
99 static const struct udevice_id arasan_sdhci_ids[] = {
100 { .compatible = "arasan,sdhci-8.9a" },
104 U_BOOT_DRIVER(arasan_sdhci_drv) = {
105 .name = "arasan_sdhci",
107 .of_match = arasan_sdhci_ids,
108 .ofdata_to_platdata = arasan_sdhci_ofdata_to_platdata,
110 .bind = arasan_sdhci_bind,
111 .probe = arasan_sdhci_probe,
112 .priv_auto_alloc_size = sizeof(struct sdhci_host),
113 .platdata_auto_alloc_size = sizeof(struct arasan_sdhci_plat),