sysreset-ti-sci.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 <sysreset.h>
  12. #include <linux/soc/ti/ti_sci_protocol.h>
  13. /**
  14. * struct ti_sci_sysreset_data - sysreset controller information structure
  15. * @sci: TI SCI handle used for communication with system controller
  16. */
  17. struct ti_sci_sysreset_data {
  18. const struct ti_sci_handle *sci;
  19. };
  20. static int ti_sci_sysreset_probe(struct udevice *dev)
  21. {
  22. struct ti_sci_sysreset_data *data = dev_get_priv(dev);
  23. debug("%s(dev=%p)\n", __func__, dev);
  24. if (!data)
  25. return -ENOMEM;
  26. /* Store handle for communication with the system controller */
  27. data->sci = ti_sci_get_handle(dev);
  28. if (IS_ERR(data->sci))
  29. return PTR_ERR(data->sci);
  30. return 0;
  31. }
  32. static int ti_sci_sysreset_request(struct udevice *dev, enum sysreset_t type)
  33. {
  34. struct ti_sci_sysreset_data *data = dev_get_priv(dev);
  35. const struct ti_sci_handle *sci = data->sci;
  36. const struct ti_sci_core_ops *cops = &sci->ops.core_ops;
  37. int ret;
  38. debug("%s(dev=%p, type=%d)\n", __func__, dev, type);
  39. ret = cops->reboot_device(sci);
  40. if (ret)
  41. dev_err(rst->dev, "%s: reboot_device failed (%d)\n",
  42. __func__, ret);
  43. return ret;
  44. }
  45. static struct sysreset_ops ti_sci_sysreset_ops = {
  46. .request = ti_sci_sysreset_request,
  47. };
  48. static const struct udevice_id ti_sci_sysreset_of_match[] = {
  49. { .compatible = "ti,sci-sysreset", },
  50. { /* sentinel */ },
  51. };
  52. U_BOOT_DRIVER(ti_sci_sysreset) = {
  53. .name = "ti-sci-sysreset",
  54. .id = UCLASS_SYSRESET,
  55. .of_match = ti_sci_sysreset_of_match,
  56. .probe = ti_sci_sysreset_probe,
  57. .priv_auto_alloc_size = sizeof(struct ti_sci_sysreset_data),
  58. .ops = &ti_sci_sysreset_ops,
  59. };