wdt.h 3.0 KB

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