Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 1 | #include <common.h> |
| 2 | #include <malloc.h> |
| 3 | #include <sdhci.h> |
| 4 | |
Lei Wen | 02d3ad3 | 2011-10-03 20:33:44 +0000 | [diff] [blame] | 5 | #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS |
| 6 | static struct sdhci_ops mv_ops; |
| 7 | |
| 8 | #if defined(CONFIG_SHEEVA_88SV331xV5) |
| 9 | #define SD_CE_ATA_2 0xEA |
| 10 | #define MMC_CARD 0x1000 |
| 11 | #define MMC_WIDTH 0x0100 |
| 12 | static inline void mv_sdhci_writeb(struct sdhci_host *host, u8 val, int reg) |
| 13 | { |
| 14 | struct mmc *mmc = host->mmc; |
Rob Herring | 3a48944 | 2015-03-17 15:46:39 -0500 | [diff] [blame] | 15 | u32 ata = (unsigned long)host->ioaddr + SD_CE_ATA_2; |
Lei Wen | 02d3ad3 | 2011-10-03 20:33:44 +0000 | [diff] [blame] | 16 | |
| 17 | if (!IS_SD(mmc) && reg == SDHCI_HOST_CONTROL) { |
| 18 | if (mmc->bus_width == 8) |
| 19 | writew(readw(ata) | (MMC_CARD | MMC_WIDTH), ata); |
| 20 | else |
| 21 | writew(readw(ata) & ~(MMC_CARD | MMC_WIDTH), ata); |
| 22 | } |
| 23 | |
| 24 | writeb(val, host->ioaddr + reg); |
| 25 | } |
| 26 | |
| 27 | #else |
| 28 | #define mv_sdhci_writeb NULL |
| 29 | #endif /* CONFIG_SHEEVA_88SV331xV5 */ |
| 30 | #endif /* CONFIG_MMC_SDHCI_IO_ACCESSORS */ |
| 31 | |
Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 32 | static char *MVSDH_NAME = "mv_sdh"; |
Rob Herring | 3a48944 | 2015-03-17 15:46:39 -0500 | [diff] [blame] | 33 | 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] | 34 | { |
| 35 | struct sdhci_host *host = NULL; |
| 36 | host = (struct sdhci_host *)malloc(sizeof(struct sdhci_host)); |
| 37 | if (!host) { |
| 38 | printf("sdh_host malloc fail!\n"); |
| 39 | return 1; |
| 40 | } |
| 41 | |
| 42 | host->name = MVSDH_NAME; |
| 43 | host->ioaddr = (void *)regbase; |
| 44 | host->quirks = quirks; |
Lei Wen | 02d3ad3 | 2011-10-03 20:33:44 +0000 | [diff] [blame] | 45 | #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS |
| 46 | memset(&mv_ops, 0, sizeof(struct sdhci_ops)); |
Anatolij Gustschin | bfe6f62 | 2011-12-07 11:47:48 +0000 | [diff] [blame] | 47 | mv_ops.write_b = mv_sdhci_writeb; |
Lei Wen | 02d3ad3 | 2011-10-03 20:33:44 +0000 | [diff] [blame] | 48 | host->ops = &mv_ops; |
| 49 | #endif |
Ajay Bhargav | 5af9a56 | 2011-11-13 23:43:12 +0000 | [diff] [blame] | 50 | if (quirks & SDHCI_QUIRK_REG32_RW) |
| 51 | host->version = sdhci_readl(host, SDHCI_HOST_VERSION - 2) >> 16; |
| 52 | else |
| 53 | host->version = sdhci_readw(host, SDHCI_HOST_VERSION); |
Jaehoon Chung | a68aac4 | 2012-12-13 20:07:12 +0000 | [diff] [blame] | 54 | return add_sdhci(host, max_clk, min_clk); |
Lei Wen | e75787d | 2011-06-28 21:50:07 +0000 | [diff] [blame] | 55 | } |