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