Merge branch 'rmobile' of git://git.denx.de/u-boot-sh
[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         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->version = sdhci_readw(host, SDHCI_HOST_VERSION);
40
41         ret = sdhci_setup_cfg(&plat->cfg, host, CONFIG_ZYNQ_SDHCI_MAX_FREQ,
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         int ret;
67
68         ret = sdhci_bind(dev, &plat->mmc, &plat->cfg);
69         if (ret)
70                 return ret;
71
72         return 0;
73 }
74
75 static const struct udevice_id arasan_sdhci_ids[] = {
76         { .compatible = "arasan,sdhci-8.9a" },
77         { }
78 };
79
80 U_BOOT_DRIVER(arasan_sdhci_drv) = {
81         .name           = "arasan_sdhci",
82         .id             = UCLASS_MMC,
83         .of_match       = arasan_sdhci_ids,
84         .ofdata_to_platdata = arasan_sdhci_ofdata_to_platdata,
85         .ops            = &sdhci_ops,
86         .bind           = arasan_sdhci_bind,
87         .probe          = arasan_sdhci_probe,
88         .priv_auto_alloc_size = sizeof(struct sdhci_host),
89         .platdata_auto_alloc_size = sizeof(struct arasan_sdhci_plat),
90 };