1 // SPDX-License-Identifier: GPL-2.0+
3 * Marvell SD Host Controller Interface
9 #include <asm/global_data.h>
10 #include <linux/mbus.h>
12 #define MVSDH_NAME "mv_sdh"
14 #define SDHCI_WINDOW_CTRL(win) (0x4080 + ((win) << 4))
15 #define SDHCI_WINDOW_BASE(win) (0x4084 + ((win) << 4))
17 DECLARE_GLOBAL_DATA_PTR;
19 struct mv_sdhci_plat {
20 struct mmc_config cfg;
24 static void sdhci_mvebu_mbus_config(void __iomem *base)
26 const struct mbus_dram_target_info *dram;
29 dram = mvebu_mbus_dram_info();
31 for (i = 0; i < 4; i++) {
32 writel(0, base + SDHCI_WINDOW_CTRL(i));
33 writel(0, base + SDHCI_WINDOW_BASE(i));
36 for (i = 0; i < dram->num_cs; i++) {
37 const struct mbus_dram_window *cs = dram->cs + i;
39 /* Write size, attributes and target id to control register */
40 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
41 (dram->mbus_dram_target_id << 4) | 1,
42 base + SDHCI_WINDOW_CTRL(i));
44 /* Write base address to base register */
45 writel(cs->base, base + SDHCI_WINDOW_BASE(i));
49 static int mv_sdhci_probe(struct udevice *dev)
51 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
52 struct mv_sdhci_plat *plat = dev_get_plat(dev);
53 struct sdhci_host *host = dev_get_priv(dev);
56 host->name = MVSDH_NAME;
57 host->ioaddr = dev_read_addr_ptr(dev);
58 host->quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD;
59 host->mmc = &plat->mmc;
61 host->mmc->priv = host;
63 ret = mmc_of_parse(dev, &plat->cfg);
67 ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0);
71 /* Configure SDHCI MBUS mbus bridge windows */
72 sdhci_mvebu_mbus_config(host->ioaddr);
74 upriv->mmc = host->mmc;
76 return sdhci_probe(dev);
79 static int mv_sdhci_bind(struct udevice *dev)
81 struct mv_sdhci_plat *plat = dev_get_plat(dev);
83 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
86 static const struct udevice_id mv_sdhci_ids[] = {
87 { .compatible = "marvell,armada-380-sdhci" },
91 U_BOOT_DRIVER(mv_sdhci_drv) = {
94 .of_match = mv_sdhci_ids,
95 .bind = mv_sdhci_bind,
96 .probe = mv_sdhci_probe,
98 .priv_auto = sizeof(struct sdhci_host),
99 .plat_auto = sizeof(struct mv_sdhci_plat),