uniphier-sd.c 1.9 KB

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