blob: 42fa735f316031248ad05a7fba57c75059baaeb9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese207f86e2015-10-01 17:34:41 +02002/*
3 * Marvell SD Host Controller Interface
Stefan Roese207f86e2015-10-01 17:34:41 +02004 */
5
Lei Wen11ebc702011-06-28 21:50:07 +00006#include <common.h>
Pierre Bourdonb9af62d2019-04-11 04:56:58 +02007#include <dm.h>
Lei Wen11ebc702011-06-28 21:50:07 +00008#include <malloc.h>
9#include <sdhci.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Stefan Roese207f86e2015-10-01 17:34:41 +020011#include <linux/mbus.h>
12
Pierre Bourdonb9af62d2019-04-11 04:56:58 +020013#define MVSDH_NAME "mv_sdh"
14
Stefan Roese207f86e2015-10-01 17:34:41 +020015#define SDHCI_WINDOW_CTRL(win) (0x4080 + ((win) << 4))
16#define SDHCI_WINDOW_BASE(win) (0x4084 + ((win) << 4))
17
18static void sdhci_mvebu_mbus_config(void __iomem *base)
19{
20 const struct mbus_dram_target_info *dram;
21 int i;
22
23 dram = mvebu_mbus_dram_info();
24
25 for (i = 0; i < 4; i++) {
26 writel(0, base + SDHCI_WINDOW_CTRL(i));
27 writel(0, base + SDHCI_WINDOW_BASE(i));
28 }
29
30 for (i = 0; i < dram->num_cs; i++) {
31 const struct mbus_dram_window *cs = dram->cs + i;
32
33 /* Write size, attributes and target id to control register */
34 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
35 (dram->mbus_dram_target_id << 4) | 1,
36 base + SDHCI_WINDOW_CTRL(i));
37
38 /* Write base address to base register */
39 writel(cs->base, base + SDHCI_WINDOW_BASE(i));
40 }
41}
Lei Wen11ebc702011-06-28 21:50:07 +000042
Pierre Bourdonb9af62d2019-04-11 04:56:58 +020043#ifndef CONFIG_DM_MMC
44
Rob Herring8d3a2a72015-03-17 15:46:39 -050045int mv_sdh_init(unsigned long regbase, u32 max_clk, u32 min_clk, u32 quirks)
Lei Wen11ebc702011-06-28 21:50:07 +000046{
47 struct sdhci_host *host = NULL;
Matt Pelland3bf0e422018-04-16 10:08:18 -040048 host = calloc(1, sizeof(*host));
Lei Wen11ebc702011-06-28 21:50:07 +000049 if (!host) {
50 printf("sdh_host malloc fail!\n");
Jaehoon Chungfc6c1c62016-09-26 08:10:02 +090051 return -ENOMEM;
Lei Wen11ebc702011-06-28 21:50:07 +000052 }
53
54 host->name = MVSDH_NAME;
55 host->ioaddr = (void *)regbase;
56 host->quirks = quirks;
Stefan Herbrechtsmeierbc47e0e2017-01-17 15:58:48 +010057 host->max_clk = max_clk;
Stefan Roese207f86e2015-10-01 17:34:41 +020058
Stefan Roese99c8d532023-02-10 13:23:50 +010059 /* Configure SDHCI MBUS mbus bridge windows */
60 sdhci_mvebu_mbus_config((void __iomem *)regbase);
Stefan Roese207f86e2015-10-01 17:34:41 +020061
Stefan Herbrechtsmeierbc47e0e2017-01-17 15:58:48 +010062 return add_sdhci(host, 0, min_clk);
Lei Wen11ebc702011-06-28 21:50:07 +000063}
Pierre Bourdonb9af62d2019-04-11 04:56:58 +020064
65#else
66
67DECLARE_GLOBAL_DATA_PTR;
68
69struct mv_sdhci_plat {
70 struct mmc_config cfg;
71 struct mmc mmc;
72};
73
74static int mv_sdhci_probe(struct udevice *dev)
75{
76 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
Simon Glassfa20e932020-12-03 16:55:20 -070077 struct mv_sdhci_plat *plat = dev_get_plat(dev);
Pierre Bourdonb9af62d2019-04-11 04:56:58 +020078 struct sdhci_host *host = dev_get_priv(dev);
79 int ret;
80
81 host->name = MVSDH_NAME;
Masahiro Yamada1096ae12020-07-17 14:36:46 +090082 host->ioaddr = dev_read_addr_ptr(dev);
Pierre Bourdonb9af62d2019-04-11 04:56:58 +020083 host->quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD;
Baruch Siachcddbfd42019-07-22 18:55:35 +030084 host->mmc = &plat->mmc;
85 host->mmc->dev = dev;
86 host->mmc->priv = host;
Pierre Bourdonb9af62d2019-04-11 04:56:58 +020087
Baruch Siach8a9cddd2021-02-02 08:43:04 +020088 ret = mmc_of_parse(dev, &plat->cfg);
89 if (ret)
90 return ret;
91
Pierre Bourdonb9af62d2019-04-11 04:56:58 +020092 ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0);
93 if (ret)
94 return ret;
95
Stefan Roese99c8d532023-02-10 13:23:50 +010096 /* Configure SDHCI MBUS mbus bridge windows */
97 sdhci_mvebu_mbus_config(host->ioaddr);
Pierre Bourdonb9af62d2019-04-11 04:56:58 +020098
Pierre Bourdonb9af62d2019-04-11 04:56:58 +020099 upriv->mmc = host->mmc;
100
101 return sdhci_probe(dev);
102}
103
104static int mv_sdhci_bind(struct udevice *dev)
105{
Simon Glassfa20e932020-12-03 16:55:20 -0700106 struct mv_sdhci_plat *plat = dev_get_plat(dev);
Pierre Bourdonb9af62d2019-04-11 04:56:58 +0200107
108 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
109}
110
111static const struct udevice_id mv_sdhci_ids[] = {
112 { .compatible = "marvell,armada-380-sdhci" },
113 { }
114};
115
116U_BOOT_DRIVER(mv_sdhci_drv) = {
117 .name = MVSDH_NAME,
118 .id = UCLASS_MMC,
119 .of_match = mv_sdhci_ids,
120 .bind = mv_sdhci_bind,
121 .probe = mv_sdhci_probe,
122 .ops = &sdhci_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700123 .priv_auto = sizeof(struct sdhci_host),
Simon Glass71fa5b42020-12-03 16:55:18 -0700124 .plat_auto = sizeof(struct mv_sdhci_plat),
Pierre Bourdonb9af62d2019-04-11 04:56:58 +0200125};
126#endif /* CONFIG_DM_MMC */