uniphier-sd.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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-sdhc", .data = 0 },
  25. { /* sentinel */ }
  26. };
  27. static int uniphier_sd_probe(struct udevice *dev)
  28. {
  29. struct tmio_sd_priv *priv = dev_get_priv(dev);
  30. #ifndef CONFIG_SPL_BUILD
  31. struct clk clk;
  32. int ret;
  33. ret = clk_get_by_index(dev, 0, &clk);
  34. if (ret < 0) {
  35. dev_err(dev, "failed to get host clock\n");
  36. return ret;
  37. }
  38. /* set to max rate */
  39. priv->mclk = clk_set_rate(&clk, ULONG_MAX);
  40. if (IS_ERR_VALUE(priv->mclk)) {
  41. dev_err(dev, "failed to set rate for host clock\n");
  42. clk_free(&clk);
  43. return priv->mclk;
  44. }
  45. ret = clk_enable(&clk);
  46. clk_free(&clk);
  47. if (ret) {
  48. dev_err(dev, "failed to enable host clock\n");
  49. return ret;
  50. }
  51. #else
  52. priv->mclk = 100000000;
  53. #endif
  54. return tmio_sd_probe(dev, 0);
  55. }
  56. U_BOOT_DRIVER(uniphier_mmc) = {
  57. .name = "uniphier-mmc",
  58. .id = UCLASS_MMC,
  59. .of_match = uniphier_sd_match,
  60. .bind = tmio_sd_bind,
  61. .probe = uniphier_sd_probe,
  62. .priv_auto_alloc_size = sizeof(struct tmio_sd_priv),
  63. .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat),
  64. .ops = &uniphier_sd_ops,
  65. };