1 /* 2 * (C) Copyright 2013 - 2015 Xilinx, Inc. 3 * 4 * Xilinx Zynq SD Host Controller Interface 5 * 6 * SPDX-License-Identifier: GPL-2.0+ 7 */ 8 9 #include <common.h> 10 #include <dm.h> 11 #include <fdtdec.h> 12 #include <libfdt.h> 13 #include <malloc.h> 14 #include <sdhci.h> 15 16 #ifndef CONFIG_ZYNQ_SDHCI_MIN_FREQ 17 # define CONFIG_ZYNQ_SDHCI_MIN_FREQ 0 18 #endif 19 20 struct arasan_sdhci_plat { 21 struct mmc_config cfg; 22 struct mmc mmc; 23 }; 24 25 static int arasan_sdhci_probe(struct udevice *dev) 26 { 27 struct arasan_sdhci_plat *plat = dev_get_platdata(dev); 28 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); 29 struct sdhci_host *host = dev_get_priv(dev); 30 int ret; 31 32 host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD | 33 SDHCI_QUIRK_BROKEN_R1B; 34 35 #ifdef CONFIG_ZYNQ_HISPD_BROKEN 36 host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT; 37 #endif 38 39 host->max_clk = CONFIG_ZYNQ_SDHCI_MAX_FREQ; 40 41 ret = sdhci_setup_cfg(&plat->cfg, host, 0, 42 CONFIG_ZYNQ_SDHCI_MIN_FREQ); 43 host->mmc = &plat->mmc; 44 if (ret) 45 return ret; 46 host->mmc->priv = host; 47 host->mmc->dev = dev; 48 upriv->mmc = host->mmc; 49 50 return sdhci_probe(dev); 51 } 52 53 static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev) 54 { 55 struct sdhci_host *host = dev_get_priv(dev); 56 57 host->name = dev->name; 58 host->ioaddr = (void *)dev_get_addr(dev); 59 60 return 0; 61 } 62 63 static int arasan_sdhci_bind(struct udevice *dev) 64 { 65 struct arasan_sdhci_plat *plat = dev_get_platdata(dev); 66 67 return sdhci_bind(dev, &plat->mmc, &plat->cfg); 68 } 69 70 static const struct udevice_id arasan_sdhci_ids[] = { 71 { .compatible = "arasan,sdhci-8.9a" }, 72 { } 73 }; 74 75 U_BOOT_DRIVER(arasan_sdhci_drv) = { 76 .name = "arasan_sdhci", 77 .id = UCLASS_MMC, 78 .of_match = arasan_sdhci_ids, 79 .ofdata_to_platdata = arasan_sdhci_ofdata_to_platdata, 80 .ops = &sdhci_ops, 81 .bind = arasan_sdhci_bind, 82 .probe = arasan_sdhci_probe, 83 .priv_auto_alloc_size = sizeof(struct sdhci_host), 84 .platdata_auto_alloc_size = sizeof(struct arasan_sdhci_plat), 85 }; 86