wdt.h 3.1 KB

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