sysreset.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #ifndef __SYSRESET_H
  7. #define __SYSRESET_H
  8. struct udevice;
  9. enum sysreset_t {
  10. SYSRESET_WARM, /* Reset CPU, keep GPIOs active */
  11. SYSRESET_COLD, /* Reset CPU and GPIOs */
  12. SYSRESET_POWER, /* Reset PMIC (remove and restore power) */
  13. SYSRESET_POWER_OFF, /* Turn off power */
  14. SYSRESET_COUNT,
  15. };
  16. struct sysreset_ops {
  17. /**
  18. * request() - request a sysreset of the given type
  19. *
  20. * Note that this function may return before the reset takes effect.
  21. *
  22. * @type: Reset type to request
  23. * @return -EINPROGRESS if the reset has been started and
  24. * will complete soon, -EPROTONOSUPPORT if not supported
  25. * by this device, 0 if the reset has already happened
  26. * (in which case this method will not actually return)
  27. */
  28. int (*request)(struct udevice *dev, enum sysreset_t type);
  29. /**
  30. * get_status() - get printable reset status information
  31. *
  32. * @dev: Device to check
  33. * @buf: Buffer to receive the textual reset information
  34. * @size: Size of the passed buffer
  35. * @return 0 if OK, -ve on error
  36. */
  37. int (*get_status)(struct udevice *dev, char *buf, int size);
  38. /**
  39. * get_last() - get information on the last reset
  40. *
  41. * @dev: Device to check
  42. * @return last reset state (enum sysreset_t) or -ve error
  43. */
  44. int (*get_last)(struct udevice *dev);
  45. };
  46. #define sysreset_get_ops(dev) ((struct sysreset_ops *)(dev)->driver->ops)
  47. /**
  48. * sysreset_request() - request a sysreset
  49. *
  50. * @type: Reset type to request
  51. * @return 0 if OK, -EPROTONOSUPPORT if not supported by this device
  52. */
  53. int sysreset_request(struct udevice *dev, enum sysreset_t type);
  54. /**
  55. * sysreset_get_status() - get printable reset status information
  56. *
  57. * @dev: Device to check
  58. * @buf: Buffer to receive the textual reset information
  59. * @size: Size of the passed buffer
  60. * @return 0 if OK, -ve on error
  61. */
  62. int sysreset_get_status(struct udevice *dev, char *buf, int size);
  63. /**
  64. * sysreset_get_last() - get information on the last reset
  65. *
  66. * @dev: Device to check
  67. * @return last reset state (enum sysreset_t) or -ve error
  68. */
  69. int sysreset_get_last(struct udevice *dev);
  70. /**
  71. * sysreset_walk() - cause a system reset
  72. *
  73. * This works through the available sysreset devices until it finds one that can
  74. * perform a reset. If the provided sysreset type is not available, the next one
  75. * will be tried.
  76. *
  77. * If this function fails to reset, it will display a message and halt
  78. *
  79. * @type: Reset type to request
  80. * @return -EINPROGRESS if a reset is in progress, -ENOSYS if not available
  81. */
  82. int sysreset_walk(enum sysreset_t type);
  83. /**
  84. * sysreset_get_last_walk() - get information on the last reset
  85. *
  86. * This works through the available sysreset devices until it finds one that can
  87. * perform a reset. If the provided sysreset type is not available, the next one
  88. * will be tried.
  89. *
  90. * If no device prives the information, this function returns -ENOENT
  91. *
  92. * @return last reset state (enum sysreset_t) or -ve error
  93. */
  94. int sysreset_get_last_walk(void);
  95. /**
  96. * sysreset_walk_halt() - try to reset, otherwise halt
  97. *
  98. * This calls sysreset_walk(). If it returns, indicating that reset is not
  99. * supported, it prints a message and halts.
  100. */
  101. void sysreset_walk_halt(enum sysreset_t type);
  102. /**
  103. * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
  104. */
  105. void reset_cpu(void);
  106. #endif