Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 207f86e | 2015-10-01 17:34:41 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Marvell SD Host Controller Interface |
Stefan Roese | 207f86e | 2015-10-01 17:34:41 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
Pierre Bourdon | b9af62d | 2019-04-11 04:56:58 +0200 | [diff] [blame] | 6 | #include <dm.h> |
Lei Wen | 11ebc70 | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 7 | #include <malloc.h> |
| 8 | #include <sdhci.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 9 | #include <asm/global_data.h> |
Stefan Roese | 207f86e | 2015-10-01 17:34:41 +0200 | [diff] [blame] | 10 | #include <linux/mbus.h> |
| 11 | |
Pierre Bourdon | b9af62d | 2019-04-11 04:56:58 +0200 | [diff] [blame] | 12 | #define MVSDH_NAME "mv_sdh" |
| 13 | |
Stefan Roese | 207f86e | 2015-10-01 17:34:41 +0200 | [diff] [blame] | 14 | #define SDHCI_WINDOW_CTRL(win) (0x4080 + ((win) << 4)) |
| 15 | #define SDHCI_WINDOW_BASE(win) (0x4084 + ((win) << 4)) |
| 16 | |
Stefan Roese | fb0720b | 2023-02-10 13:23:52 +0100 | [diff] [blame] | 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
| 19 | struct mv_sdhci_plat { |
| 20 | struct mmc_config cfg; |
| 21 | struct mmc mmc; |
| 22 | }; |
| 23 | |
Stefan Roese | 207f86e | 2015-10-01 17:34:41 +0200 | [diff] [blame] | 24 | static void sdhci_mvebu_mbus_config(void __iomem *base) |
| 25 | { |
| 26 | const struct mbus_dram_target_info *dram; |
| 27 | int i; |
| 28 | |
| 29 | dram = mvebu_mbus_dram_info(); |
| 30 | |
| 31 | for (i = 0; i < 4; i++) { |
| 32 | writel(0, base + SDHCI_WINDOW_CTRL(i)); |
| 33 | writel(0, base + SDHCI_WINDOW_BASE(i)); |
| 34 | } |
| 35 | |
| 36 | for (i = 0; i < dram->num_cs; i++) { |
| 37 | const struct mbus_dram_window *cs = dram->cs + i; |
| 38 | |
| 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)); |
| 43 | |
| 44 | /* Write base address to base register */ |
| 45 | writel(cs->base, base + SDHCI_WINDOW_BASE(i)); |
| 46 | } |
| 47 | } |
Lei Wen | 11ebc70 | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 48 | |
Pierre Bourdon | b9af62d | 2019-04-11 04:56:58 +0200 | [diff] [blame] | 49 | static int mv_sdhci_probe(struct udevice *dev) |
| 50 | { |
| 51 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 52 | struct mv_sdhci_plat *plat = dev_get_plat(dev); |
Pierre Bourdon | b9af62d | 2019-04-11 04:56:58 +0200 | [diff] [blame] | 53 | struct sdhci_host *host = dev_get_priv(dev); |
| 54 | int ret; |
| 55 | |
| 56 | host->name = MVSDH_NAME; |
Masahiro Yamada | 1096ae1 | 2020-07-17 14:36:46 +0900 | [diff] [blame] | 57 | host->ioaddr = dev_read_addr_ptr(dev); |
Pierre Bourdon | b9af62d | 2019-04-11 04:56:58 +0200 | [diff] [blame] | 58 | host->quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD; |
Baruch Siach | cddbfd4 | 2019-07-22 18:55:35 +0300 | [diff] [blame] | 59 | host->mmc = &plat->mmc; |
| 60 | host->mmc->dev = dev; |
| 61 | host->mmc->priv = host; |
Pierre Bourdon | b9af62d | 2019-04-11 04:56:58 +0200 | [diff] [blame] | 62 | |
Baruch Siach | 8a9cddd | 2021-02-02 08:43:04 +0200 | [diff] [blame] | 63 | ret = mmc_of_parse(dev, &plat->cfg); |
| 64 | if (ret) |
| 65 | return ret; |
| 66 | |
Pierre Bourdon | b9af62d | 2019-04-11 04:56:58 +0200 | [diff] [blame] | 67 | ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0); |
| 68 | if (ret) |
| 69 | return ret; |
| 70 | |
Stefan Roese | 99c8d53 | 2023-02-10 13:23:50 +0100 | [diff] [blame] | 71 | /* Configure SDHCI MBUS mbus bridge windows */ |
| 72 | sdhci_mvebu_mbus_config(host->ioaddr); |
Pierre Bourdon | b9af62d | 2019-04-11 04:56:58 +0200 | [diff] [blame] | 73 | |
Pierre Bourdon | b9af62d | 2019-04-11 04:56:58 +0200 | [diff] [blame] | 74 | upriv->mmc = host->mmc; |
| 75 | |
| 76 | return sdhci_probe(dev); |
| 77 | } |
| 78 | |
| 79 | static int mv_sdhci_bind(struct udevice *dev) |
| 80 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 81 | struct mv_sdhci_plat *plat = dev_get_plat(dev); |
Pierre Bourdon | b9af62d | 2019-04-11 04:56:58 +0200 | [diff] [blame] | 82 | |
| 83 | return sdhci_bind(dev, &plat->mmc, &plat->cfg); |
| 84 | } |
| 85 | |
| 86 | static const struct udevice_id mv_sdhci_ids[] = { |
| 87 | { .compatible = "marvell,armada-380-sdhci" }, |
| 88 | { } |
| 89 | }; |
| 90 | |
| 91 | U_BOOT_DRIVER(mv_sdhci_drv) = { |
| 92 | .name = MVSDH_NAME, |
| 93 | .id = UCLASS_MMC, |
| 94 | .of_match = mv_sdhci_ids, |
| 95 | .bind = mv_sdhci_bind, |
| 96 | .probe = mv_sdhci_probe, |
| 97 | .ops = &sdhci_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 98 | .priv_auto = sizeof(struct sdhci_host), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 99 | .plat_auto = sizeof(struct mv_sdhci_plat), |
Pierre Bourdon | b9af62d | 2019-04-11 04:56:58 +0200 | [diff] [blame] | 100 | }; |