sysreset-ti-sci.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Texas Instruments System Control Interface (TI SCI) system reset driver
  4. *
  5. * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
  6. * Andreas Dannenberg <dannenberg@ti.com>
  7. */
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <errno.h>
  11. #include <log.h>
  12. #include <sysreset.h>
  13. #include <dm/device_compat.h>
  14. #include <linux/err.h>
  15. #include <linux/soc/ti/ti_sci_protocol.h>
  16. /**
  17. * struct ti_sci_sysreset_data - sysreset controller information structure
  18. * @sci: TI SCI handle used for communication with system controller
  19. */
  20. struct ti_sci_sysreset_data {
  21. const struct ti_sci_handle *sci;
  22. };
  23. static int ti_sci_sysreset_probe(struct udevice *dev)
  24. {
  25. struct ti_sci_sysreset_data *data = dev_get_priv(dev);
  26. debug("%s(dev=%p)\n", __func__, dev);
  27. if (!data)
  28. return -ENOMEM;
  29. /* Store handle for communication with the system controller */
  30. data->sci = ti_sci_get_handle(dev);
  31. if (IS_ERR(data->sci))
  32. return PTR_ERR(data->sci);
  33. return 0;
  34. }
  35. static int ti_sci_sysreset_request(struct udevice *dev, enum sysreset_t type)
  36. {
  37. struct ti_sci_sysreset_data *data = dev_get_priv(dev);
  38. const struct ti_sci_handle *sci = data->sci;
  39. const struct ti_sci_core_ops *cops = &sci->ops.core_ops;
  40. int ret;
  41. debug("%s(dev=%p, type=%d)\n", __func__, dev, type);
  42. ret = cops->reboot_device(sci);
  43. if (ret)
  44. dev_err(dev, "%s: reboot_device failed (%d)\n", __func__, ret);
  45. return ret;
  46. }
  47. static struct sysreset_ops ti_sci_sysreset_ops = {
  48. .request = ti_sci_sysreset_request,
  49. };
  50. static const struct udevice_id ti_sci_sysreset_of_match[] = {
  51. { .compatible = "ti,sci-sysreset", },
  52. { /* sentinel */ },
  53. };
  54. U_BOOT_DRIVER(ti_sci_sysreset) = {
  55. .name = "ti-sci-sysreset",
  56. .id = UCLASS_SYSRESET,
  57. .of_match = ti_sci_sysreset_of_match,
  58. .probe = ti_sci_sysreset_probe,
  59. .priv_auto_alloc_size = sizeof(struct ti_sci_sysreset_data),
  60. .ops = &ti_sci_sysreset_ops,
  61. };