reset-scmi.c 2.3 KB

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