uniphier-sd.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016 Socionext Inc.
  4. * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
  5. */
  6. #include <common.h>
  7. #include <clk.h>
  8. #include <fdtdec.h>
  9. #include <malloc.h>
  10. #include <mmc.h>
  11. #include <dm.h>
  12. #include <dm/device_compat.h>
  13. #include <linux/compat.h>
  14. #include <linux/dma-direction.h>
  15. #include <linux/io.h>
  16. #include <linux/sizes.h>
  17. #include <power/regulator.h>
  18. #include <asm/unaligned.h>
  19. #include "tmio-common.h"
  20. static const struct dm_mmc_ops uniphier_sd_ops = {
  21. .send_cmd = tmio_sd_send_cmd,
  22. .set_ios = tmio_sd_set_ios,
  23. .get_cd = tmio_sd_get_cd,
  24. };
  25. static const struct udevice_id uniphier_sd_match[] = {
  26. { .compatible = "socionext,uniphier-sd-v2.91" },
  27. { .compatible = "socionext,uniphier-sd-v3.1" },
  28. { .compatible = "socionext,uniphier-sd-v3.1.1" },
  29. { /* sentinel */ }
  30. };
  31. static ulong uniphier_sd_clk_get_rate(struct tmio_sd_priv *priv)
  32. {
  33. #if CONFIG_IS_ENABLED(CLK)
  34. return clk_get_rate(&priv->clk);
  35. #elif CONFIG_SPL_BUILD
  36. return 100000000;
  37. #else
  38. return 0;
  39. #endif
  40. }
  41. static int uniphier_sd_probe(struct udevice *dev)
  42. {
  43. struct tmio_sd_priv *priv = dev_get_priv(dev);
  44. priv->clk_get_rate = uniphier_sd_clk_get_rate;
  45. priv->read_poll_flag = TMIO_SD_DMA_INFO1_END_RD2;
  46. #ifndef CONFIG_SPL_BUILD
  47. int ret;
  48. ret = clk_get_by_index(dev, 0, &priv->clk);
  49. if (ret < 0) {
  50. dev_err(dev, "failed to get host clock\n");
  51. return ret;
  52. }
  53. /* set to max rate */
  54. ret = clk_set_rate(&priv->clk, ULONG_MAX);
  55. if (ret < 0) {
  56. dev_err(dev, "failed to set rate for host clock\n");
  57. clk_free(&priv->clk);
  58. return ret;
  59. }
  60. ret = clk_enable(&priv->clk);
  61. if (ret) {
  62. dev_err(dev, "failed to enable host clock\n");
  63. return ret;
  64. }
  65. #endif
  66. return tmio_sd_probe(dev, 0);
  67. }
  68. U_BOOT_DRIVER(uniphier_mmc) = {
  69. .name = "uniphier-mmc",
  70. .id = UCLASS_MMC,
  71. .of_match = uniphier_sd_match,
  72. .bind = tmio_sd_bind,
  73. .probe = uniphier_sd_probe,
  74. .priv_auto_alloc_size = sizeof(struct tmio_sd_priv),
  75. .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat),
  76. .ops = &uniphier_sd_ops,
  77. };