1 // SPDX-License-Identifier: GPL-2.0+
2 
3 #include <common.h>
4 #include <cpu_func.h>
5 #include <asm/processor.h>
6 #include <asm/system.h>
7 #include <asm/io.h>
8 
9 #define WDT_BASE	WTCNT
10 
11 #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)
csr_read(void)17 static unsigned char csr_read(void)
18 {
19 	return inb(WDT_BASE + 0x04);
20 }
21 
cnt_write(unsigned char value)22 static void cnt_write(unsigned char value)
23 {
24 	outl((unsigned short)value | 0x5A00, WDT_BASE + 0x00);
25 }
26 
csr_write(unsigned char value)27 static void csr_write(unsigned char value)
28 {
29 	outl((unsigned short)value | 0xA500, WDT_BASE + 0x04);
30 }
31 
watchdog_reset(void)32 void watchdog_reset(void)
33 {
34 	outl(0x55000000, WDT_BASE + 0x08);
35 }
36 
watchdog_init(void)37 int 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 }
46 
watchdog_disable(void)47 int watchdog_disable(void)
48 {
49 	csr_write(csr_read() & ~WDT_ENABLE);
50 	return 0;
51 }
52 #endif
53 
reset_cpu(unsigned long ignored)54 void reset_cpu(unsigned long ignored)
55 {
56 	/* Address error with SR.BL=1 first. */
57 	trigger_address_error();
58 
59 	while (1)
60 		;
61 }
62