Stefan Roese | 5b37212 | 2015-10-01 17:34:41 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Marvell SD Host Controller Interface |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 7 | #include <common.h> |
| 8 | #include <malloc.h> |
| 9 | #include <sdhci.h> |
Stefan Roese | 5b37212 | 2015-10-01 17:34:41 +0200 | [diff] [blame] | 10 | #include <linux/mbus.h> |
| 11 | |
| 12 | #define SDHCI_WINDOW_CTRL(win) (0x4080 + ((win) << 4)) |
| 13 | #define SDHCI_WINDOW_BASE(win) (0x4084 + ((win) << 4)) |
| 14 | |
| 15 | static void sdhci_mvebu_mbus_config(void __iomem *base) |
| 16 | { |
| 17 | const struct mbus_dram_target_info *dram; |
| 18 | int i; |
| 19 | |
| 20 | dram = mvebu_mbus_dram_info(); |
| 21 | |
| 22 | for (i = 0; i < 4; i++) { |
| 23 | writel(0, base + SDHCI_WINDOW_CTRL(i)); |
| 24 | writel(0, base + SDHCI_WINDOW_BASE(i)); |
| 25 | } |
| 26 | |
| 27 | for (i = 0; i < dram->num_cs; i++) { |
| 28 | const struct mbus_dram_window *cs = dram->cs + i; |
| 29 | |
| 30 | /* Write size, attributes and target id to control register */ |
| 31 | writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) | |
| 32 | (dram->mbus_dram_target_id << 4) | 1, |
| 33 | base + SDHCI_WINDOW_CTRL(i)); |
| 34 | |
| 35 | /* Write base address to base register */ |
| 36 | writel(cs->base, base + SDHCI_WINDOW_BASE(i)); |
| 37 | } |
| 38 | } |
Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 39 | |
Lei Wen | 02d3ad3 | 2011-10-03 20:33:44 +0000 | [diff] [blame] | 40 | #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS |
| 41 | static struct sdhci_ops mv_ops; |
| 42 | |
| 43 | #if defined(CONFIG_SHEEVA_88SV331xV5) |
| 44 | #define SD_CE_ATA_2 0xEA |
| 45 | #define MMC_CARD 0x1000 |
| 46 | #define MMC_WIDTH 0x0100 |
| 47 | static inline void mv_sdhci_writeb(struct sdhci_host *host, u8 val, int reg) |
| 48 | { |
| 49 | struct mmc *mmc = host->mmc; |
Rob Herring | 3a48944 | 2015-03-17 15:46:39 -0500 | [diff] [blame] | 50 | u32 ata = (unsigned long)host->ioaddr + SD_CE_ATA_2; |
Lei Wen | 02d3ad3 | 2011-10-03 20:33:44 +0000 | [diff] [blame] | 51 | |
| 52 | if (!IS_SD(mmc) && reg == SDHCI_HOST_CONTROL) { |
| 53 | if (mmc->bus_width == 8) |
| 54 | writew(readw(ata) | (MMC_CARD | MMC_WIDTH), ata); |
| 55 | else |
| 56 | writew(readw(ata) & ~(MMC_CARD | MMC_WIDTH), ata); |
| 57 | } |
| 58 | |
| 59 | writeb(val, host->ioaddr + reg); |
| 60 | } |
| 61 | |
| 62 | #else |
| 63 | #define mv_sdhci_writeb NULL |
| 64 | #endif /* CONFIG_SHEEVA_88SV331xV5 */ |
| 65 | #endif /* CONFIG_MMC_SDHCI_IO_ACCESSORS */ |
| 66 | |
Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 67 | static char *MVSDH_NAME = "mv_sdh"; |
Rob Herring | 3a48944 | 2015-03-17 15:46:39 -0500 | [diff] [blame] | 68 | 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] | 69 | { |
| 70 | struct sdhci_host *host = NULL; |
| 71 | host = (struct sdhci_host *)malloc(sizeof(struct sdhci_host)); |
| 72 | if (!host) { |
| 73 | printf("sdh_host malloc fail!\n"); |
| 74 | return 1; |
| 75 | } |
| 76 | |
| 77 | host->name = MVSDH_NAME; |
| 78 | host->ioaddr = (void *)regbase; |
| 79 | host->quirks = quirks; |
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 | |
Ajay Bhargav | 5af9a56 | 2011-11-13 23:43:12 +0000 | [diff] [blame] | 91 | if (quirks & SDHCI_QUIRK_REG32_RW) |
| 92 | host->version = sdhci_readl(host, SDHCI_HOST_VERSION - 2) >> 16; |
| 93 | else |
| 94 | host->version = sdhci_readw(host, SDHCI_HOST_VERSION); |
Jaehoon Chung | a68aac4 | 2012-12-13 20:07:12 +0000 | [diff] [blame] | 95 | return add_sdhci(host, max_clk, min_clk); |
Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 96 | } |