uniphier-sd.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (C) 2016 Socionext Inc.
  3. * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <clk.h>
  9. #include <fdtdec.h>
  10. #include <mmc.h>
  11. #include <dm.h>
  12. #include <linux/compat.h>
  13. #include <linux/dma-direction.h>
  14. #include <linux/io.h>
  15. #include <linux/sizes.h>
  16. #include <power/regulator.h>
  17. #include <asm/unaligned.h>
  18. #include "tmio-common.h"
  19. static const struct dm_mmc_ops uniphier_sd_ops = {
  20. .send_cmd = tmio_sd_send_cmd,
  21. .set_ios = tmio_sd_set_ios,
  22. .get_cd = tmio_sd_get_cd,
  23. };
  24. static const struct udevice_id uniphier_sd_match[] = {
  25. { .compatible = "socionext,uniphier-sdhc", .data = 0 },
  26. { /* sentinel */ }
  27. };
  28. static int uniphier_sd_probe(struct udevice *dev)
  29. {
  30. struct tmio_sd_priv *priv = dev_get_priv(dev);
  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. return tmio_sd_probe(dev, 0);
  52. }
  53. U_BOOT_DRIVER(uniphier_mmc) = {
  54. .name = "uniphier-mmc",
  55. .id = UCLASS_MMC,
  56. .of_match = uniphier_sd_match,
  57. .bind = tmio_sd_bind,
  58. .probe = uniphier_sd_probe,
  59. .priv_auto_alloc_size = sizeof(struct tmio_sd_priv),
  60. .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat),
  61. .ops = &uniphier_sd_ops,
  62. };