wdt.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright 2017 Google, Inc
  4. */
  5. #ifndef _WDT_H_
  6. #define _WDT_H_
  7. #include <dm.h>
  8. #include <log.h>
  9. #include <dm/read.h>
  10. /*
  11. * Implement a simple watchdog uclass. Watchdog is basically a timer that
  12. * is used to detect or recover from malfunction. During normal operation
  13. * the watchdog would be regularly reset to prevent it from timing out.
  14. * If, due to a hardware fault or program error, the computer fails to reset
  15. * the watchdog, the timer will elapse and generate a timeout signal.
  16. * The timeout signal is used to initiate corrective action or actions,
  17. * which typically include placing the system in a safe, known state.
  18. */
  19. /*
  20. * Start the timer
  21. *
  22. * @dev: WDT Device
  23. * @timeout_ms: Number of ticks (milliseconds) before timer expires
  24. * @flags: Driver specific flags. This might be used to specify
  25. * which action needs to be executed when the timer expires
  26. * @return: 0 if OK, -ve on error
  27. */
  28. int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags);
  29. /*
  30. * Stop the timer, thus disabling the Watchdog. Use wdt_start to start it again.
  31. *
  32. * @dev: WDT Device
  33. * @return: 0 if OK, -ve on error
  34. */
  35. int wdt_stop(struct udevice *dev);
  36. /*
  37. * Reset the timer, typically restoring the counter to
  38. * the value configured by start()
  39. *
  40. * @dev: WDT Device
  41. * @return: 0 if OK, -ve on error
  42. */
  43. int wdt_reset(struct udevice *dev);
  44. /*
  45. * Expire the timer, thus executing its action immediately.
  46. * This is typically used to reset the board or peripherals.
  47. *
  48. * @dev: WDT Device
  49. * @flags: Driver specific flags
  50. * @return 0 if OK -ve on error. If wdt action is system reset,
  51. * this function may never return.
  52. */
  53. int wdt_expire_now(struct udevice *dev, ulong flags);
  54. /*
  55. * struct wdt_ops - Driver model wdt operations
  56. *
  57. * The uclass interface is implemented by all wdt devices which use
  58. * driver model.
  59. */
  60. struct wdt_ops {
  61. /*
  62. * Start the timer
  63. *
  64. * @dev: WDT Device
  65. * @timeout_ms: Number of ticks (milliseconds) before the timer expires
  66. * @flags: Driver specific flags. This might be used to specify
  67. * which action needs to be executed when the timer expires
  68. * @return: 0 if OK, -ve on error
  69. */
  70. int (*start)(struct udevice *dev, u64 timeout_ms, ulong flags);
  71. /*
  72. * Stop the timer
  73. *
  74. * @dev: WDT Device
  75. * @return: 0 if OK, -ve on error
  76. */
  77. int (*stop)(struct udevice *dev);
  78. /*
  79. * Reset the timer, typically restoring the counter to
  80. * the value configured by start()
  81. *
  82. * @dev: WDT Device
  83. * @return: 0 if OK, -ve on error
  84. */
  85. int (*reset)(struct udevice *dev);
  86. /*
  87. * Expire the timer, thus executing the action immediately (optional)
  88. *
  89. * If this function is not provided, a default implementation
  90. * will be used, which sets the counter to 1
  91. * and waits forever. This is good enough for system level
  92. * reset, where the function is not expected to return, but might not be
  93. * good enough for other use cases.
  94. *
  95. * @dev: WDT Device
  96. * @flags: Driver specific flags
  97. * @return 0 if OK -ve on error. May not return.
  98. */
  99. int (*expire_now)(struct udevice *dev, ulong flags);
  100. };
  101. int initr_watchdog(void);
  102. #endif /* _WDT_H_ */