mv_sdhci.c 2.3 KB

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