sti_sdhci.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c) 2017
  3. * Patrice Chotard <patrice.chotard@st.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <mmc.h>
  10. #include <sdhci.h>
  11. #include <asm/arch/sdhci.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. struct sti_sdhci_plat {
  14. struct mmc_config cfg;
  15. struct mmc mmc;
  16. };
  17. /*
  18. * used to get access to MMC1 reset,
  19. * will be removed when STi reset driver will be available
  20. */
  21. #define STIH410_SYSCONF5_BASE 0x092b0000
  22. /**
  23. * sti_mmc_core_config: configure the Arasan HC
  24. * @regbase: base address
  25. * @mmc_instance: mmc instance id
  26. * Description: this function is to configure the Arasan MMC HC.
  27. * This should be called when the system starts in case of, on the SoC,
  28. * it is needed to configure the host controller.
  29. * This happens on some SoCs, i.e. StiH410, where the MMC0 inside the flashSS
  30. * needs to be configured as MMC 4.5 to have full capabilities.
  31. * W/o these settings the SDHCI could configure and use the embedded controller
  32. * with limited features.
  33. */
  34. static void sti_mmc_core_config(const u32 regbase, int mmc_instance)
  35. {
  36. unsigned long *sysconf;
  37. /* only MMC1 has a reset line */
  38. if (mmc_instance) {
  39. sysconf = (unsigned long *)(STIH410_SYSCONF5_BASE +
  40. ST_MMC_CCONFIG_REG_5);
  41. generic_set_bit(SYSCONF_MMC1_ENABLE_BIT, sysconf);
  42. }
  43. writel(STI_FLASHSS_MMC_CORE_CONFIG_1,
  44. regbase + FLASHSS_MMC_CORE_CONFIG_1);
  45. if (mmc_instance) {
  46. writel(STI_FLASHSS_MMC_CORE_CONFIG2,
  47. regbase + FLASHSS_MMC_CORE_CONFIG_2);
  48. writel(STI_FLASHSS_MMC_CORE_CONFIG3,
  49. regbase + FLASHSS_MMC_CORE_CONFIG_3);
  50. } else {
  51. writel(STI_FLASHSS_SDCARD_CORE_CONFIG2,
  52. regbase + FLASHSS_MMC_CORE_CONFIG_2);
  53. writel(STI_FLASHSS_SDCARD_CORE_CONFIG3,
  54. regbase + FLASHSS_MMC_CORE_CONFIG_3);
  55. }
  56. writel(STI_FLASHSS_MMC_CORE_CONFIG4,
  57. regbase + FLASHSS_MMC_CORE_CONFIG_4);
  58. }
  59. static int sti_sdhci_probe(struct udevice *dev)
  60. {
  61. struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  62. struct sti_sdhci_plat *plat = dev_get_platdata(dev);
  63. struct sdhci_host *host = dev_get_priv(dev);
  64. int ret, mmc_instance;
  65. /*
  66. * identify current mmc instance, mmc1 has a reset, not mmc0
  67. * MMC0 is wired to the SD slot,
  68. * MMC1 is wired on the high speed connector
  69. */
  70. if (fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "resets", NULL))
  71. mmc_instance = 1;
  72. else
  73. mmc_instance = 0;
  74. sti_mmc_core_config((const u32) host->ioaddr, mmc_instance);
  75. host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
  76. SDHCI_QUIRK_32BIT_DMA_ADDR |
  77. SDHCI_QUIRK_NO_HISPD_BIT;
  78. host->host_caps = MMC_MODE_DDR_52MHz;
  79. ret = sdhci_setup_cfg(&plat->cfg, host, 50000000, 400000);
  80. if (ret)
  81. return ret;
  82. host->mmc = &plat->mmc;
  83. host->mmc->priv = host;
  84. host->mmc->dev = dev;
  85. upriv->mmc = host->mmc;
  86. return sdhci_probe(dev);
  87. }
  88. static int sti_sdhci_ofdata_to_platdata(struct udevice *dev)
  89. {
  90. struct sdhci_host *host = dev_get_priv(dev);
  91. host->name = strdup(dev->name);
  92. host->ioaddr = (void *)devfdt_get_addr(dev);
  93. host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
  94. "bus-width", 4);
  95. return 0;
  96. }
  97. static int sti_sdhci_bind(struct udevice *dev)
  98. {
  99. struct sti_sdhci_plat *plat = dev_get_platdata(dev);
  100. return sdhci_bind(dev, &plat->mmc, &plat->cfg);
  101. }
  102. static const struct udevice_id sti_sdhci_ids[] = {
  103. { .compatible = "st,sdhci" },
  104. { }
  105. };
  106. U_BOOT_DRIVER(sti_mmc) = {
  107. .name = "sti_sdhci",
  108. .id = UCLASS_MMC,
  109. .of_match = sti_sdhci_ids,
  110. .bind = sti_sdhci_bind,
  111. .ops = &sdhci_ops,
  112. .ofdata_to_platdata = sti_sdhci_ofdata_to_platdata,
  113. .probe = sti_sdhci_probe,
  114. .priv_auto_alloc_size = sizeof(struct sdhci_host),
  115. .platdata_auto_alloc_size = sizeof(struct sti_sdhci_plat),
  116. };