rockchip_sdhci.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * (C) Copyright 2016 Fuzhou Rockchip Electronics Co., Ltd
  3. *
  4. * Rockchip SD Host Controller Interface
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <fdtdec.h>
  11. #include <libfdt.h>
  12. #include <malloc.h>
  13. #include <sdhci.h>
  14. #include <clk.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. /* 400KHz is max freq for card ID etc. Use that as min */
  17. #define EMMC_MIN_FREQ 400000
  18. struct rockchip_sdhc_plat {
  19. struct mmc_config cfg;
  20. struct mmc mmc;
  21. };
  22. struct rockchip_sdhc {
  23. struct sdhci_host host;
  24. void *base;
  25. };
  26. static int arasan_sdhci_probe(struct udevice *dev)
  27. {
  28. struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  29. struct rockchip_sdhc_plat *plat = dev_get_platdata(dev);
  30. struct rockchip_sdhc *prv = dev_get_priv(dev);
  31. struct sdhci_host *host = &prv->host;
  32. int max_frequency, ret;
  33. struct clk clk;
  34. max_frequency = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
  35. "max-frequency", 0);
  36. ret = clk_get_by_index(dev, 0, &clk);
  37. if (!ret) {
  38. ret = clk_set_rate(&clk, max_frequency);
  39. if (IS_ERR_VALUE(ret))
  40. printf("%s clk set rate fail!\n", __func__);
  41. } else {
  42. printf("%s fail to get clk\n", __func__);
  43. }
  44. host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD;
  45. host->max_clk = max_frequency;
  46. ret = sdhci_setup_cfg(&plat->cfg, host, 0, EMMC_MIN_FREQ);
  47. host->mmc = &plat->mmc;
  48. if (ret)
  49. return ret;
  50. host->mmc->priv = &prv->host;
  51. host->mmc->dev = dev;
  52. upriv->mmc = host->mmc;
  53. return sdhci_probe(dev);
  54. }
  55. static int arasan_sdhci_ofdata_to_platdata(struct udevice *dev)
  56. {
  57. struct sdhci_host *host = dev_get_priv(dev);
  58. host->name = dev->name;
  59. host->ioaddr = dev_get_addr_ptr(dev);
  60. return 0;
  61. }
  62. static int rockchip_sdhci_bind(struct udevice *dev)
  63. {
  64. struct rockchip_sdhc_plat *plat = dev_get_platdata(dev);
  65. return sdhci_bind(dev, &plat->mmc, &plat->cfg);
  66. }
  67. static const struct udevice_id arasan_sdhci_ids[] = {
  68. { .compatible = "arasan,sdhci-5.1" },
  69. { }
  70. };
  71. U_BOOT_DRIVER(arasan_sdhci_drv) = {
  72. .name = "arasan_sdhci",
  73. .id = UCLASS_MMC,
  74. .of_match = arasan_sdhci_ids,
  75. .ofdata_to_platdata = arasan_sdhci_ofdata_to_platdata,
  76. .ops = &sdhci_ops,
  77. .bind = rockchip_sdhci_bind,
  78. .probe = arasan_sdhci_probe,
  79. .priv_auto_alloc_size = sizeof(struct rockchip_sdhc),
  80. .platdata_auto_alloc_size = sizeof(struct rockchip_sdhc_plat),
  81. };