blob: 14cc618074bd84f312b502c16cc01389d8095b42 [file] [log] [blame]
Troy Kiskyabbab702012-10-22 15:19:01 +00001/*
2 * watchdog.c - driver for i.mx on-chip watchdog
3 *
4 * Licensed under the GPL-2 or later.
5 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <watchdog.h>
10#include <asm/arch/imx-regs.h>
Xiaoliang Yang005c1cf2018-10-18 18:27:45 +080011#ifdef CONFIG_FSL_LSCH2
12#include <asm/arch/immap_lsch2.h>
13#endif
Fabio Estevamf5327272015-10-03 14:20:59 -030014#include <fsl_wdog.h>
Troy Kiskyabbab702012-10-22 15:19:01 +000015
16#ifdef CONFIG_IMX_WATCHDOG
17void hw_watchdog_reset(void)
18{
Xiaoliang Yangda4918a2018-10-18 18:27:46 +080019#ifndef CONFIG_WATCHDOG_RESET_DISABLE
Troy Kiskyabbab702012-10-22 15:19:01 +000020 struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
21
22 writew(0x5555, &wdog->wsr);
23 writew(0xaaaa, &wdog->wsr);
Xiaoliang Yangda4918a2018-10-18 18:27:46 +080024#endif /* CONFIG_WATCHDOG_RESET_DISABLE*/
Troy Kiskyabbab702012-10-22 15:19:01 +000025}
26
27void hw_watchdog_init(void)
28{
29 struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
30 u16 timeout;
31
32 /*
33 * The timer watchdog can be set between
34 * 0.5 and 128 Seconds. If not defined
35 * in configuration file, sets 128 Seconds
36 */
37#ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
38#define CONFIG_WATCHDOG_TIMEOUT_MSECS 128000
39#endif
40 timeout = (CONFIG_WATCHDOG_TIMEOUT_MSECS / 500) - 1;
Xiaoliang Yang005c1cf2018-10-18 18:27:45 +080041#ifdef CONFIG_FSL_LSCH2
42 writew((WCR_WDA | WCR_SRS | WCR_WDE) << 8 | timeout, &wdog->wcr);
43#else
Anatolij Gustschin723ec692013-09-30 12:52:38 +020044 writew(WCR_WDZST | WCR_WDBG | WCR_WDE | WCR_WDT | WCR_SRS |
Ross Parker9eeab572016-08-02 08:08:07 +000045 WCR_WDA | SET_WCR_WT(timeout), &wdog->wcr);
Xiaoliang Yang005c1cf2018-10-18 18:27:45 +080046#endif /* CONFIG_FSL_LSCH2*/
Troy Kiskyabbab702012-10-22 15:19:01 +000047 hw_watchdog_reset();
48}
49#endif
50
Stefan Agner8b248c82016-07-13 00:25:42 -070051void __attribute__((weak)) reset_cpu(ulong addr)
Troy Kiskyabbab702012-10-22 15:19:01 +000052{
53 struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
54
Andrey Skvortsov587c3f82015-12-20 21:09:58 +030055 clrsetbits_le16(&wdog->wcr, WCR_WT_MSK, WCR_WDE);
Peng Fan623d96e2015-09-14 13:34:44 +080056
Troy Kiskyabbab702012-10-22 15:19:01 +000057 writew(0x5555, &wdog->wsr);
58 writew(0xaaaa, &wdog->wsr); /* load minimum 1/2 second timeout */
59 while (1) {
60 /*
61 * spin for .5 seconds before reset
62 */
63 }
64}