]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - drivers/mmc/zynq_sdhci.c
bf542192cec3eab574108003de2d5a94763ae766
[karo-tx-uboot.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, host, CONFIG_ZYNQ_SDHCI_MAX_FREQ,
44                               CONFIG_ZYNQ_SDHCI_MIN_FREQ);
45         host->mmc = &plat->mmc;
46         if (ret)
47                 return ret;
48         host->mmc->priv = host;
49         host->mmc->dev = dev;
50         upriv->mmc = host->mmc;
51
52         return sdhci_probe(dev);
53 }
54
55 static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev)
56 {
57         struct sdhci_host *host = dev_get_priv(dev);
58
59         host->name = dev->name;
60         host->ioaddr = (void *)dev_get_addr(dev);
61
62         return 0;
63 }
64
65 static int arasan_sdhci_bind(struct udevice *dev)
66 {
67         struct arasan_sdhci_plat *plat = dev_get_platdata(dev);
68         int ret;
69
70         ret = sdhci_bind(dev, &plat->mmc, &plat->cfg);
71         if (ret)
72                 return ret;
73
74         return 0;
75 }
76
77 static const struct udevice_id arasan_sdhci_ids[] = {
78         { .compatible = "arasan,sdhci-8.9a" },
79         { }
80 };
81
82 U_BOOT_DRIVER(arasan_sdhci_drv) = {
83         .name           = "arasan_sdhci",
84         .id             = UCLASS_MMC,
85         .of_match       = arasan_sdhci_ids,
86         .ofdata_to_platdata = arasan_sdhci_ofdata_to_platdata,
87         .ops            = &sdhci_ops,
88         .bind           = arasan_sdhci_bind,
89         .probe          = arasan_sdhci_probe,
90         .priv_auto_alloc_size = sizeof(struct sdhci_host),
91         .platdata_auto_alloc_size = sizeof(struct arasan_sdhci_plat),
92 };