Merge git://git.denx.de/u-boot-dm
[platform/kernel/u-boot.git] / drivers / mmc / zynq_sdhci.c
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         u32 caps;
31         int ret;
32
33         host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
34                        SDHCI_QUIRK_BROKEN_R1B;
35
36 #ifdef CONFIG_ZYNQ_HISPD_BROKEN
37         host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT;
38 #endif
39
40         host->version = sdhci_readw(host, SDHCI_HOST_VERSION);
41
42         caps = sdhci_readl(host, SDHCI_CAPABILITIES);
43         ret = sdhci_setup_cfg(&plat->cfg, dev->name, host->bus_width,
44                               caps, CONFIG_ZYNQ_SDHCI_MAX_FREQ,
45                               CONFIG_ZYNQ_SDHCI_MIN_FREQ, host->version,
46                               host->quirks, 0);
47         host->mmc = &plat->mmc;
48         if (ret)
49                 return ret;
50         host->mmc->priv = host;
51         host->mmc->dev = dev;
52         upriv->mmc = host->mmc;
53
54         return sdhci_probe(dev);
55 }
56
57 static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev)
58 {
59         struct sdhci_host *host = dev_get_priv(dev);
60
61         host->name = dev->name;
62         host->ioaddr = (void *)dev_get_addr(dev);
63
64         return 0;
65 }
66
67 static int arasan_sdhci_bind(struct udevice *dev)
68 {
69         struct arasan_sdhci_plat *plat = dev_get_platdata(dev);
70         int ret;
71
72         ret = sdhci_bind(dev, &plat->mmc, &plat->cfg);
73         if (ret)
74                 return ret;
75
76         return 0;
77 }
78
79 static const struct udevice_id arasan_sdhci_ids[] = {
80         { .compatible = "arasan,sdhci-8.9a" },
81         { }
82 };
83
84 U_BOOT_DRIVER(arasan_sdhci_drv) = {
85         .name           = "arasan_sdhci",
86         .id             = UCLASS_MMC,
87         .of_match       = arasan_sdhci_ids,
88         .ofdata_to_platdata = arasan_sdhci_ofdata_to_platdata,
89         .ops            = &sdhci_ops,
90         .bind           = arasan_sdhci_bind,
91         .probe          = arasan_sdhci_probe,
92         .priv_auto_alloc_size = sizeof(struct sdhci_host),
93         .platdata_auto_alloc_size = sizeof(struct arasan_sdhci_plat),
94 };