reset-scmi.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2019-2020 Linaro Limited
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <errno.h>
  8. #include <reset-uclass.h>
  9. #include <scmi_agent.h>
  10. #include <scmi_protocols.h>
  11. #include <asm/types.h>
  12. static int scmi_reset_set_level(struct reset_ctl *rst, bool assert_not_deassert)
  13. {
  14. struct scmi_rd_reset_in in = {
  15. .domain_id = rst->id,
  16. .flags = assert_not_deassert ? SCMI_RD_RESET_FLAG_ASSERT : 0,
  17. .reset_state = 0,
  18. };
  19. struct scmi_rd_reset_out out;
  20. struct scmi_msg msg = SCMI_MSG_IN(SCMI_PROTOCOL_ID_RESET_DOMAIN,
  21. SCMI_RESET_DOMAIN_RESET,
  22. in, out);
  23. int ret;
  24. ret = devm_scmi_process_msg(rst->dev->parent, &msg);
  25. if (ret)
  26. return ret;
  27. return scmi_to_linux_errno(out.status);
  28. }
  29. static int scmi_reset_assert(struct reset_ctl *rst)
  30. {
  31. return scmi_reset_set_level(rst, true);
  32. }
  33. static int scmi_reset_deassert(struct reset_ctl *rst)
  34. {
  35. return scmi_reset_set_level(rst, false);
  36. }
  37. static int scmi_reset_request(struct reset_ctl *rst)
  38. {
  39. struct scmi_rd_attr_in in = {
  40. .domain_id = rst->id,
  41. };
  42. struct scmi_rd_attr_out out;
  43. struct scmi_msg msg = SCMI_MSG_IN(SCMI_PROTOCOL_ID_RESET_DOMAIN,
  44. SCMI_RESET_DOMAIN_ATTRIBUTES,
  45. in, out);
  46. int ret;
  47. /*
  48. * We don't really care about the attribute, just check
  49. * the reset domain exists.
  50. */
  51. ret = devm_scmi_process_msg(rst->dev->parent, &msg);
  52. if (ret)
  53. return ret;
  54. return scmi_to_linux_errno(out.status);
  55. }
  56. static int scmi_reset_rfree(struct reset_ctl *rst)
  57. {
  58. return 0;
  59. }
  60. static const struct reset_ops scmi_reset_domain_ops = {
  61. .request = scmi_reset_request,
  62. .rfree = scmi_reset_rfree,
  63. .rst_assert = scmi_reset_assert,
  64. .rst_deassert = scmi_reset_deassert,
  65. };
  66. U_BOOT_DRIVER(scmi_reset_domain) = {
  67. .name = "scmi_reset_domain",
  68. .id = UCLASS_RESET,
  69. .ops = &scmi_reset_domain_ops,
  70. };