1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */ 20753bc2dSmaxims@google.com /* 30753bc2dSmaxims@google.com * Copyright 2017 Google, Inc 40753bc2dSmaxims@google.com */ 50753bc2dSmaxims@google.com 60753bc2dSmaxims@google.com #ifndef _WDT_H_ 70753bc2dSmaxims@google.com #define _WDT_H_ 80753bc2dSmaxims@google.com 90753bc2dSmaxims@google.com /* 100753bc2dSmaxims@google.com * Implement a simple watchdog uclass. Watchdog is basically a timer that 110753bc2dSmaxims@google.com * is used to detect or recover from malfunction. During normal operation 120753bc2dSmaxims@google.com * the watchdog would be regularly reset to prevent it from timing out. 130753bc2dSmaxims@google.com * If, due to a hardware fault or program error, the computer fails to reset 140753bc2dSmaxims@google.com * the watchdog, the timer will elapse and generate a timeout signal. 150753bc2dSmaxims@google.com * The timeout signal is used to initiate corrective action or actions, 160753bc2dSmaxims@google.com * which typically include placing the system in a safe, known state. 170753bc2dSmaxims@google.com */ 180753bc2dSmaxims@google.com 190753bc2dSmaxims@google.com /* 200753bc2dSmaxims@google.com * Start the timer 210753bc2dSmaxims@google.com * 220753bc2dSmaxims@google.com * @dev: WDT Device 23ffdec300SAndy Shevchenko * @timeout_ms: Number of ticks (milliseconds) before timer expires 240753bc2dSmaxims@google.com * @flags: Driver specific flags. This might be used to specify 250753bc2dSmaxims@google.com * which action needs to be executed when the timer expires 260753bc2dSmaxims@google.com * @return: 0 if OK, -ve on error 270753bc2dSmaxims@google.com */ 28ffdec300SAndy Shevchenko int wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags); 290753bc2dSmaxims@google.com 300753bc2dSmaxims@google.com /* 310753bc2dSmaxims@google.com * Stop the timer, thus disabling the Watchdog. Use wdt_start to start it again. 320753bc2dSmaxims@google.com * 330753bc2dSmaxims@google.com * @dev: WDT Device 340753bc2dSmaxims@google.com * @return: 0 if OK, -ve on error 350753bc2dSmaxims@google.com */ 360753bc2dSmaxims@google.com int wdt_stop(struct udevice *dev); 370753bc2dSmaxims@google.com 380753bc2dSmaxims@google.com /* 390753bc2dSmaxims@google.com * Reset the timer, typically restoring the counter to 400753bc2dSmaxims@google.com * the value configured by start() 410753bc2dSmaxims@google.com * 420753bc2dSmaxims@google.com * @dev: WDT Device 430753bc2dSmaxims@google.com * @return: 0 if OK, -ve on error 440753bc2dSmaxims@google.com */ 450753bc2dSmaxims@google.com int wdt_reset(struct udevice *dev); 460753bc2dSmaxims@google.com 470753bc2dSmaxims@google.com /* 480753bc2dSmaxims@google.com * Expire the timer, thus executing its action immediately. 490753bc2dSmaxims@google.com * This is typically used to reset the board or peripherals. 500753bc2dSmaxims@google.com * 510753bc2dSmaxims@google.com * @dev: WDT Device 520753bc2dSmaxims@google.com * @flags: Driver specific flags 530753bc2dSmaxims@google.com * @return 0 if OK -ve on error. If wdt action is system reset, 540753bc2dSmaxims@google.com * this function may never return. 550753bc2dSmaxims@google.com */ 560753bc2dSmaxims@google.com int wdt_expire_now(struct udevice *dev, ulong flags); 570753bc2dSmaxims@google.com 580753bc2dSmaxims@google.com /* 590753bc2dSmaxims@google.com * struct wdt_ops - Driver model wdt operations 600753bc2dSmaxims@google.com * 610753bc2dSmaxims@google.com * The uclass interface is implemented by all wdt devices which use 620753bc2dSmaxims@google.com * driver model. 630753bc2dSmaxims@google.com */ 640753bc2dSmaxims@google.com struct wdt_ops { 650753bc2dSmaxims@google.com /* 660753bc2dSmaxims@google.com * Start the timer 670753bc2dSmaxims@google.com * 680753bc2dSmaxims@google.com * @dev: WDT Device 69ffdec300SAndy Shevchenko * @timeout_ms: Number of ticks (milliseconds) before the timer expires 700753bc2dSmaxims@google.com * @flags: Driver specific flags. This might be used to specify 710753bc2dSmaxims@google.com * which action needs to be executed when the timer expires 720753bc2dSmaxims@google.com * @return: 0 if OK, -ve on error 730753bc2dSmaxims@google.com */ 74ffdec300SAndy Shevchenko int (*start)(struct udevice *dev, u64 timeout_ms, ulong flags); 750753bc2dSmaxims@google.com /* 760753bc2dSmaxims@google.com * Stop the timer 770753bc2dSmaxims@google.com * 780753bc2dSmaxims@google.com * @dev: WDT Device 790753bc2dSmaxims@google.com * @return: 0 if OK, -ve on error 800753bc2dSmaxims@google.com */ 810753bc2dSmaxims@google.com int (*stop)(struct udevice *dev); 820753bc2dSmaxims@google.com /* 830753bc2dSmaxims@google.com * Reset the timer, typically restoring the counter to 840753bc2dSmaxims@google.com * the value configured by start() 850753bc2dSmaxims@google.com * 860753bc2dSmaxims@google.com * @dev: WDT Device 870753bc2dSmaxims@google.com * @return: 0 if OK, -ve on error 880753bc2dSmaxims@google.com */ 890753bc2dSmaxims@google.com int (*reset)(struct udevice *dev); 900753bc2dSmaxims@google.com /* 910753bc2dSmaxims@google.com * Expire the timer, thus executing the action immediately (optional) 920753bc2dSmaxims@google.com * 930753bc2dSmaxims@google.com * If this function is not provided, a default implementation 940753bc2dSmaxims@google.com * will be used, which sets the counter to 1 950753bc2dSmaxims@google.com * and waits forever. This is good enough for system level 960753bc2dSmaxims@google.com * reset, where the function is not expected to return, but might not be 970753bc2dSmaxims@google.com * good enough for other use cases. 980753bc2dSmaxims@google.com * 990753bc2dSmaxims@google.com * @dev: WDT Device 1000753bc2dSmaxims@google.com * @flags: Driver specific flags 1010753bc2dSmaxims@google.com * @return 0 if OK -ve on error. May not return. 1020753bc2dSmaxims@google.com */ 1030753bc2dSmaxims@google.com int (*expire_now)(struct udevice *dev, ulong flags); 1040753bc2dSmaxims@google.com }; 1050753bc2dSmaxims@google.com 1060753bc2dSmaxims@google.com #endif /* _WDT_H_ */ 107