reset-scmi.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * ARM System Control and Management Interface (ARM SCMI) reset driver
  4. *
  5. * Copyright (C) 2019-2020 ARM Ltd.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/of.h>
  9. #include <linux/device.h>
  10. #include <linux/reset-controller.h>
  11. #include <linux/scmi_protocol.h>
  12. static const struct scmi_reset_proto_ops *reset_ops;
  13. /**
  14. * struct scmi_reset_data - reset controller information structure
  15. * @rcdev: reset controller entity
  16. * @ph: ARM SCMI protocol handle used for communication with system controller
  17. */
  18. struct scmi_reset_data {
  19. struct reset_controller_dev rcdev;
  20. const struct scmi_protocol_handle *ph;
  21. };
  22. #define to_scmi_reset_data(p) container_of((p), struct scmi_reset_data, rcdev)
  23. #define to_scmi_handle(p) (to_scmi_reset_data(p)->ph)
  24. /**
  25. * scmi_reset_assert() - assert device reset
  26. * @rcdev: reset controller entity
  27. * @id: ID of the reset to be asserted
  28. *
  29. * This function implements the reset driver op to assert a device's reset
  30. * using the ARM SCMI protocol.
  31. *
  32. * Return: 0 for successful request, else a corresponding error value
  33. */
  34. static int
  35. scmi_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
  36. {
  37. const struct scmi_protocol_handle *ph = to_scmi_handle(rcdev);
  38. return reset_ops->assert(ph, id);
  39. }
  40. /**
  41. * scmi_reset_deassert() - deassert device reset
  42. * @rcdev: reset controller entity
  43. * @id: ID of the reset to be deasserted
  44. *
  45. * This function implements the reset driver op to deassert a device's reset
  46. * using the ARM SCMI protocol.
  47. *
  48. * Return: 0 for successful request, else a corresponding error value
  49. */
  50. static int
  51. scmi_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id)
  52. {
  53. const struct scmi_protocol_handle *ph = to_scmi_handle(rcdev);
  54. return reset_ops->deassert(ph, id);
  55. }
  56. /**
  57. * scmi_reset_reset() - reset the device
  58. * @rcdev: reset controller entity
  59. * @id: ID of the reset signal to be reset(assert + deassert)
  60. *
  61. * This function implements the reset driver op to trigger a device's
  62. * reset signal using the ARM SCMI protocol.
  63. *
  64. * Return: 0 for successful request, else a corresponding error value
  65. */
  66. static int
  67. scmi_reset_reset(struct reset_controller_dev *rcdev, unsigned long id)
  68. {
  69. const struct scmi_protocol_handle *ph = to_scmi_handle(rcdev);
  70. return reset_ops->reset(ph, id);
  71. }
  72. static const struct reset_control_ops scmi_reset_ops = {
  73. .assert = scmi_reset_assert,
  74. .deassert = scmi_reset_deassert,
  75. .reset = scmi_reset_reset,
  76. };
  77. static int scmi_reset_probe(struct scmi_device *sdev)
  78. {
  79. struct scmi_reset_data *data;
  80. struct device *dev = &sdev->dev;
  81. struct device_node *np = dev->of_node;
  82. const struct scmi_handle *handle = sdev->handle;
  83. struct scmi_protocol_handle *ph;
  84. if (!handle)
  85. return -ENODEV;
  86. reset_ops = handle->devm_get_protocol(sdev, SCMI_PROTOCOL_RESET, &ph);
  87. if (IS_ERR(reset_ops))
  88. return PTR_ERR(reset_ops);
  89. data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
  90. if (!data)
  91. return -ENOMEM;
  92. data->rcdev.ops = &scmi_reset_ops;
  93. data->rcdev.owner = THIS_MODULE;
  94. data->rcdev.of_node = np;
  95. data->rcdev.nr_resets = reset_ops->num_domains_get(ph);
  96. data->ph = ph;
  97. return devm_reset_controller_register(dev, &data->rcdev);
  98. }
  99. static const struct scmi_device_id scmi_id_table[] = {
  100. { SCMI_PROTOCOL_RESET, "reset" },
  101. { },
  102. };
  103. MODULE_DEVICE_TABLE(scmi, scmi_id_table);
  104. static struct scmi_driver scmi_reset_driver = {
  105. .name = "scmi-reset",
  106. .probe = scmi_reset_probe,
  107. .id_table = scmi_id_table,
  108. };
  109. module_scmi_driver(scmi_reset_driver);
  110. MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
  111. MODULE_DESCRIPTION("ARM SCMI reset controller driver");
  112. MODULE_LICENSE("GPL v2");