sti_sdhci.c 3.7 KB

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