blob: 7c157bc035d20dcf91a4b8e2a2a52fbf54453950 [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>
4#include <asm/processor.h>
Nobuhiro Iwamatsua9273312010-06-16 16:55:26 +09005#include <asm/system.h>
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +09006#include <asm/io.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +09007
8#define WDT_BASE WTCNT
9
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090010#define WDT_WD (1 << 6)
11#define WDT_RST_P (0)
12#define WDT_RST_M (1 << 5)
13#define WDT_ENABLE (1 << 7)
14
15#if defined(CONFIG_WATCHDOG)
16static unsigned char csr_read(void)
17{
18 return inb(WDT_BASE + 0x04);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090019}
20
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090021static void cnt_write(unsigned char value)
22{
23 outl((unsigned short)value | 0x5A00, WDT_BASE + 0x00);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090024}
25
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090026static void csr_write(unsigned char value)
27{
28 outl((unsigned short)value | 0xA500, WDT_BASE + 0x04);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090029}
30
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090031void watchdog_reset(void)
32{
33 outl(0x55000000, WDT_BASE + 0x08);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090034}
35
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090036int watchdog_init(void)
37{
38 /* Set overflow time*/
39 cnt_write(0);
40 /* Power on reset */
41 csr_write(WDT_WD|WDT_RST_P|WDT_ENABLE);
42
43 return 0;
44}
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090045
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090046int watchdog_disable(void)
47{
48 csr_write(csr_read() & ~WDT_ENABLE);
49 return 0;
50}
51#endif
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090052
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090053void reset_cpu(unsigned long ignored)
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090054{
Nobuhiro Iwamatsua9273312010-06-16 16:55:26 +090055 /* Address error with SR.BL=1 first. */
56 trigger_address_error();
57
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090058 while (1)
59 ;
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090060}