sysreset.h 3.3 KB

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