uniphier-sd.c 1.7 KB

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