mv_sdhci.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Marvell SD Host Controller Interface
  4. */
  5. #include <common.h>
  6. #include <malloc.h>
  7. #include <sdhci.h>
  8. #include <linux/mbus.h>
  9. #define SDHCI_WINDOW_CTRL(win) (0x4080 + ((win) << 4))
  10. #define SDHCI_WINDOW_BASE(win) (0x4084 + ((win) << 4))
  11. static void sdhci_mvebu_mbus_config(void __iomem *base)
  12. {
  13. const struct mbus_dram_target_info *dram;
  14. int i;
  15. dram = mvebu_mbus_dram_info();
  16. for (i = 0; i < 4; i++) {
  17. writel(0, base + SDHCI_WINDOW_CTRL(i));
  18. writel(0, base + SDHCI_WINDOW_BASE(i));
  19. }
  20. for (i = 0; i < dram->num_cs; i++) {
  21. const struct mbus_dram_window *cs = dram->cs + i;
  22. /* Write size, attributes and target id to control register */
  23. writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
  24. (dram->mbus_dram_target_id << 4) | 1,
  25. base + SDHCI_WINDOW_CTRL(i));
  26. /* Write base address to base register */
  27. writel(cs->base, base + SDHCI_WINDOW_BASE(i));
  28. }
  29. }
  30. #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  31. static struct sdhci_ops mv_ops;
  32. #if defined(CONFIG_SHEEVA_88SV331xV5)
  33. #define SD_CE_ATA_2 0xEA
  34. #define MMC_CARD 0x1000
  35. #define MMC_WIDTH 0x0100
  36. static inline void mv_sdhci_writeb(struct sdhci_host *host, u8 val, int reg)
  37. {
  38. struct mmc *mmc = host->mmc;
  39. u32 ata = (unsigned long)host->ioaddr + SD_CE_ATA_2;
  40. if (!IS_SD(mmc) && reg == SDHCI_HOST_CONTROL) {
  41. if (mmc->bus_width == 8)
  42. writew(readw(ata) | (MMC_CARD | MMC_WIDTH), ata);
  43. else
  44. writew(readw(ata) & ~(MMC_CARD | MMC_WIDTH), ata);
  45. }
  46. writeb(val, host->ioaddr + reg);
  47. }
  48. #else
  49. #define mv_sdhci_writeb NULL
  50. #endif /* CONFIG_SHEEVA_88SV331xV5 */
  51. #endif /* CONFIG_MMC_SDHCI_IO_ACCESSORS */
  52. static char *MVSDH_NAME = "mv_sdh";
  53. int mv_sdh_init(unsigned long regbase, u32 max_clk, u32 min_clk, u32 quirks)
  54. {
  55. struct sdhci_host *host = NULL;
  56. host = calloc(1, sizeof(*host));
  57. if (!host) {
  58. printf("sdh_host malloc fail!\n");
  59. return -ENOMEM;
  60. }
  61. host->name = MVSDH_NAME;
  62. host->ioaddr = (void *)regbase;
  63. host->quirks = quirks;
  64. host->max_clk = max_clk;
  65. #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  66. memset(&mv_ops, 0, sizeof(struct sdhci_ops));
  67. mv_ops.write_b = mv_sdhci_writeb;
  68. host->ops = &mv_ops;
  69. #endif
  70. if (CONFIG_IS_ENABLED(ARCH_MVEBU)) {
  71. /* Configure SDHCI MBUS mbus bridge windows */
  72. sdhci_mvebu_mbus_config((void __iomem *)regbase);
  73. }
  74. return add_sdhci(host, 0, min_clk);
  75. }