aspeed_sdhci.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2019 IBM Corp.
  4. * Eddie James <eajames@linux.ibm.com>
  5. */
  6. #include <common.h>
  7. #include <clk.h>
  8. #include <dm.h>
  9. #include <malloc.h>
  10. #include <sdhci.h>
  11. #include <linux/err.h>
  12. #include <dm/lists.h>
  13. struct aspeed_sdhci_plat {
  14. struct mmc_config cfg;
  15. struct mmc mmc;
  16. };
  17. static int aspeed_sdhci_probe(struct udevice *dev)
  18. {
  19. struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  20. struct aspeed_sdhci_plat *plat = dev_get_plat(dev);
  21. struct sdhci_host *host = dev_get_priv(dev);
  22. u32 max_clk;
  23. struct clk clk;
  24. int ret;
  25. ret = clk_get_by_index(dev, 0, &clk);
  26. if (ret) {
  27. debug("%s: clock get failed %d\n", __func__, ret);
  28. return ret;
  29. }
  30. ret = clk_enable(&clk);
  31. if (ret) {
  32. debug("%s: clock enable failed %d\n", __func__, ret);
  33. goto free;
  34. }
  35. host->name = dev->name;
  36. host->ioaddr = dev_read_addr_ptr(dev);
  37. max_clk = clk_get_rate(&clk);
  38. if (IS_ERR_VALUE(max_clk)) {
  39. ret = max_clk;
  40. debug("%s: clock rate get failed %d\n", __func__, ret);
  41. goto err;
  42. }
  43. host->max_clk = max_clk;
  44. host->mmc = &plat->mmc;
  45. host->mmc->dev = dev;
  46. host->mmc->priv = host;
  47. upriv->mmc = host->mmc;
  48. ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0);
  49. if (ret)
  50. goto err;
  51. ret = sdhci_probe(dev);
  52. if (ret)
  53. goto err;
  54. return 0;
  55. err:
  56. clk_disable(&clk);
  57. free:
  58. clk_free(&clk);
  59. return ret;
  60. }
  61. static int aspeed_sdhci_bind(struct udevice *dev)
  62. {
  63. struct aspeed_sdhci_plat *plat = dev_get_plat(dev);
  64. return sdhci_bind(dev, &plat->mmc, &plat->cfg);
  65. }
  66. static const struct udevice_id aspeed_sdhci_ids[] = {
  67. { .compatible = "aspeed,ast2400-sdhci" },
  68. { .compatible = "aspeed,ast2500-sdhci" },
  69. { .compatible = "aspeed,ast2600-sdhci" },
  70. { }
  71. };
  72. U_BOOT_DRIVER(aspeed_sdhci_drv) = {
  73. .name = "aspeed_sdhci",
  74. .id = UCLASS_MMC,
  75. .of_match = aspeed_sdhci_ids,
  76. .ops = &sdhci_ops,
  77. .bind = aspeed_sdhci_bind,
  78. .probe = aspeed_sdhci_probe,
  79. .priv_auto = sizeof(struct sdhci_host),
  80. .plat_auto = sizeof(struct aspeed_sdhci_plat),
  81. };
  82. static int aspeed_sdc_probe(struct udevice *parent)
  83. {
  84. struct clk clk;
  85. int ret;
  86. ret = clk_get_by_index(parent, 0, &clk);
  87. if (ret) {
  88. debug("%s: clock get failed %d\n", __func__, ret);
  89. return ret;
  90. }
  91. ret = clk_enable(&clk);
  92. if (ret) {
  93. debug("%s: clock enable failed %d\n", __func__, ret);
  94. return ret;
  95. }
  96. return 0;
  97. }
  98. static const struct udevice_id aspeed_sdc_ids[] = {
  99. { .compatible = "aspeed,ast2400-sd-controller" },
  100. { .compatible = "aspeed,ast2500-sd-controller" },
  101. { .compatible = "aspeed,ast2600-sd-controller" },
  102. { }
  103. };
  104. U_BOOT_DRIVER(aspeed_sdc_drv) = {
  105. .name = "aspeed_sdc",
  106. .id = UCLASS_MISC,
  107. .of_match = aspeed_sdc_ids,
  108. .probe = aspeed_sdc_probe,
  109. };