blob: bf403d3c520ec517dd49c1f4d0db03840cf9703e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +09002
3#include <common.h>
Simon Glassafb02152019-12-28 10:45:01 -07004#include <cpu_func.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +09005#include <asm/processor.h>
Nobuhiro Iwamatsua9273312010-06-16 16:55:26 +09006#include <asm/system.h>
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +09007#include <asm/io.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +09008
9#define WDT_BASE WTCNT
10
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090011#define WDT_WD (1 << 6)
12#define WDT_RST_P (0)
13#define WDT_RST_M (1 << 5)
14#define WDT_ENABLE (1 << 7)
15
16#if defined(CONFIG_WATCHDOG)
17static unsigned char csr_read(void)
18{
19 return inb(WDT_BASE + 0x04);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090020}
21
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090022static void cnt_write(unsigned char value)
23{
24 outl((unsigned short)value | 0x5A00, WDT_BASE + 0x00);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090025}
26
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090027static void csr_write(unsigned char value)
28{
29 outl((unsigned short)value | 0xA500, WDT_BASE + 0x04);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090030}
31
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090032void watchdog_reset(void)
33{
34 outl(0x55000000, WDT_BASE + 0x08);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090035}
36
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090037int watchdog_init(void)
38{
39 /* Set overflow time*/
40 cnt_write(0);
41 /* Power on reset */
42 csr_write(WDT_WD|WDT_RST_P|WDT_ENABLE);
43
44 return 0;
45}
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090046
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090047int watchdog_disable(void)
48{
49 csr_write(csr_read() & ~WDT_ENABLE);
50 return 0;
51}
52#endif
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090053
Harald Seiler6f14d5f2020-12-15 16:47:52 +010054void reset_cpu(void)
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090055{
Nobuhiro Iwamatsua9273312010-06-16 16:55:26 +090056 /* Address error with SR.BL=1 first. */
57 trigger_address_error();
58
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090059 while (1)
60 ;
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090061}