wdt.h 3.0 KB

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