Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 5b37212 | 2015-10-01 17:34:41 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Marvell SD Host Controller Interface |
Stefan Roese | 5b37212 | 2015-10-01 17:34:41 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 6 | #include <common.h> |
| 7 | #include <malloc.h> |
| 8 | #include <sdhci.h> |
Stefan Roese | 5b37212 | 2015-10-01 17:34:41 +0200 | [diff] [blame] | 9 | #include <linux/mbus.h> |
| 10 | |
| 11 | #define SDHCI_WINDOW_CTRL(win) (0x4080 + ((win) << 4)) |
| 12 | #define SDHCI_WINDOW_BASE(win) (0x4084 + ((win) << 4)) |
| 13 | |
| 14 | static void sdhci_mvebu_mbus_config(void __iomem *base) |
| 15 | { |
| 16 | const struct mbus_dram_target_info *dram; |
| 17 | int i; |
| 18 | |
| 19 | dram = mvebu_mbus_dram_info(); |
| 20 | |
| 21 | for (i = 0; i < 4; i++) { |
| 22 | writel(0, base + SDHCI_WINDOW_CTRL(i)); |
| 23 | writel(0, base + SDHCI_WINDOW_BASE(i)); |
| 24 | } |
| 25 | |
| 26 | for (i = 0; i < dram->num_cs; i++) { |
| 27 | const struct mbus_dram_window *cs = dram->cs + i; |
| 28 | |
| 29 | /* Write size, attributes and target id to control register */ |
| 30 | writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) | |
| 31 | (dram->mbus_dram_target_id << 4) | 1, |
| 32 | base + SDHCI_WINDOW_CTRL(i)); |
| 33 | |
| 34 | /* Write base address to base register */ |
| 35 | writel(cs->base, base + SDHCI_WINDOW_BASE(i)); |
| 36 | } |
| 37 | } |
Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 38 | |
Lei Wen | 02d3ad3 | 2011-10-03 20:33:44 +0000 | [diff] [blame] | 39 | #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS |
| 40 | static struct sdhci_ops mv_ops; |
| 41 | |
| 42 | #if defined(CONFIG_SHEEVA_88SV331xV5) |
| 43 | #define SD_CE_ATA_2 0xEA |
| 44 | #define MMC_CARD 0x1000 |
| 45 | #define MMC_WIDTH 0x0100 |
| 46 | static inline void mv_sdhci_writeb(struct sdhci_host *host, u8 val, int reg) |
| 47 | { |
| 48 | struct mmc *mmc = host->mmc; |
Rob Herring | 3a48944 | 2015-03-17 15:46:39 -0500 | [diff] [blame] | 49 | u32 ata = (unsigned long)host->ioaddr + SD_CE_ATA_2; |
Lei Wen | 02d3ad3 | 2011-10-03 20:33:44 +0000 | [diff] [blame] | 50 | |
| 51 | if (!IS_SD(mmc) && reg == SDHCI_HOST_CONTROL) { |
| 52 | if (mmc->bus_width == 8) |
| 53 | writew(readw(ata) | (MMC_CARD | MMC_WIDTH), ata); |
| 54 | else |
| 55 | writew(readw(ata) & ~(MMC_CARD | MMC_WIDTH), ata); |
| 56 | } |
| 57 | |
| 58 | writeb(val, host->ioaddr + reg); |
| 59 | } |
| 60 | |
| 61 | #else |
| 62 | #define mv_sdhci_writeb NULL |
| 63 | #endif /* CONFIG_SHEEVA_88SV331xV5 */ |
| 64 | #endif /* CONFIG_MMC_SDHCI_IO_ACCESSORS */ |
| 65 | |
Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 66 | static char *MVSDH_NAME = "mv_sdh"; |
Rob Herring | 3a48944 | 2015-03-17 15:46:39 -0500 | [diff] [blame] | 67 | int mv_sdh_init(unsigned long regbase, u32 max_clk, u32 min_clk, u32 quirks) |
Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 68 | { |
| 69 | struct sdhci_host *host = NULL; |
Matt Pelland | ca4e7d6 | 2018-04-16 10:08:18 -0400 | [diff] [blame] | 70 | host = calloc(1, sizeof(*host)); |
Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 71 | if (!host) { |
| 72 | printf("sdh_host malloc fail!\n"); |
Jaehoon Chung | 2cb5d67 | 2016-09-26 08:10:02 +0900 | [diff] [blame] | 73 | return -ENOMEM; |
Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | host->name = MVSDH_NAME; |
| 77 | host->ioaddr = (void *)regbase; |
| 78 | host->quirks = quirks; |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 79 | host->max_clk = max_clk; |
Lei Wen | 02d3ad3 | 2011-10-03 20:33:44 +0000 | [diff] [blame] | 80 | #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS |
| 81 | memset(&mv_ops, 0, sizeof(struct sdhci_ops)); |
Anatolij Gustschin | bfe6f62 | 2011-12-07 11:47:48 +0000 | [diff] [blame] | 82 | mv_ops.write_b = mv_sdhci_writeb; |
Lei Wen | 02d3ad3 | 2011-10-03 20:33:44 +0000 | [diff] [blame] | 83 | host->ops = &mv_ops; |
| 84 | #endif |
Stefan Roese | 5b37212 | 2015-10-01 17:34:41 +0200 | [diff] [blame] | 85 | |
| 86 | if (CONFIG_IS_ENABLED(ARCH_MVEBU)) { |
| 87 | /* Configure SDHCI MBUS mbus bridge windows */ |
| 88 | sdhci_mvebu_mbus_config((void __iomem *)regbase); |
| 89 | } |
| 90 | |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 91 | return add_sdhci(host, 0, min_clk); |
Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 92 | } |