xref: /openbmc/u-boot/drivers/mmc/zynq_sdhci.c (revision 8aea45a7)
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 	ret = sdhci_setup_cfg(&plat->cfg, host, CONFIG_ZYNQ_SDHCI_MAX_FREQ,
40 			      CONFIG_ZYNQ_SDHCI_MIN_FREQ);
41 	host->mmc = &plat->mmc;
42 	if (ret)
43 		return ret;
44 	host->mmc->priv = host;
45 	host->mmc->dev = dev;
46 	upriv->mmc = host->mmc;
47 
48 	return sdhci_probe(dev);
49 }
50 
51 static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev)
52 {
53 	struct sdhci_host *host = dev_get_priv(dev);
54 
55 	host->name = dev->name;
56 	host->ioaddr = (void *)dev_get_addr(dev);
57 
58 	return 0;
59 }
60 
61 static int arasan_sdhci_bind(struct udevice *dev)
62 {
63 	struct arasan_sdhci_plat *plat = dev_get_platdata(dev);
64 
65 	return sdhci_bind(dev, &plat->mmc, &plat->cfg);
66 }
67 
68 static const struct udevice_id arasan_sdhci_ids[] = {
69 	{ .compatible = "arasan,sdhci-8.9a" },
70 	{ }
71 };
72 
73 U_BOOT_DRIVER(arasan_sdhci_drv) = {
74 	.name		= "arasan_sdhci",
75 	.id		= UCLASS_MMC,
76 	.of_match	= arasan_sdhci_ids,
77 	.ofdata_to_platdata = arasan_sdhci_ofdata_to_platdata,
78 	.ops		= &sdhci_ops,
79 	.bind		= arasan_sdhci_bind,
80 	.probe		= arasan_sdhci_probe,
81 	.priv_auto_alloc_size = sizeof(struct sdhci_host),
82 	.platdata_auto_alloc_size = sizeof(struct arasan_sdhci_plat),
83 };
84