aspeed_sdhci.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. struct aspeed_sdhci_plat {
  13. struct mmc_config cfg;
  14. struct mmc mmc;
  15. };
  16. static int aspeed_sdhci_probe(struct udevice *dev)
  17. {
  18. struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  19. struct aspeed_sdhci_plat *plat = dev_get_platdata(dev);
  20. struct sdhci_host *host = dev_get_priv(dev);
  21. u32 max_clk;
  22. struct clk clk;
  23. int ret;
  24. ret = clk_get_by_index(dev, 0, &clk);
  25. if (ret)
  26. return ret;
  27. ret = clk_enable(&clk);
  28. if (ret)
  29. goto free;
  30. host->name = dev->name;
  31. host->ioaddr = dev_read_addr_ptr(dev);
  32. max_clk = clk_get_rate(&clk);
  33. if (IS_ERR_VALUE(max_clk)) {
  34. ret = max_clk;
  35. goto err;
  36. }
  37. host->max_clk = max_clk;
  38. host->mmc = &plat->mmc;
  39. host->mmc->dev = dev;
  40. host->mmc->priv = host;
  41. upriv->mmc = host->mmc;
  42. ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0);
  43. if (ret)
  44. goto err;
  45. ret = sdhci_probe(dev);
  46. if (ret)
  47. goto err;
  48. return 0;
  49. err:
  50. clk_disable(&clk);
  51. free:
  52. clk_free(&clk);
  53. return ret;
  54. }
  55. static int aspeed_sdhci_bind(struct udevice *dev)
  56. {
  57. struct aspeed_sdhci_plat *plat = dev_get_platdata(dev);
  58. return sdhci_bind(dev, &plat->mmc, &plat->cfg);
  59. }
  60. static const struct udevice_id aspeed_sdhci_ids[] = {
  61. { .compatible = "aspeed,ast2400-sdhci" },
  62. { .compatible = "aspeed,ast2500-sdhci" },
  63. { .compatible = "aspeed,ast2600-sdhci" },
  64. { }
  65. };
  66. U_BOOT_DRIVER(aspeed_sdhci_drv) = {
  67. .name = "aspeed_sdhci",
  68. .id = UCLASS_MMC,
  69. .of_match = aspeed_sdhci_ids,
  70. .ops = &sdhci_ops,
  71. .bind = aspeed_sdhci_bind,
  72. .probe = aspeed_sdhci_probe,
  73. .priv_auto_alloc_size = sizeof(struct sdhci_host),
  74. .platdata_auto_alloc_size = sizeof(struct aspeed_sdhci_plat),
  75. };