blob: fc938e6b8c1b99a3003fdd546d10b8713b7cf999 [file] [log] [blame]
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +09001/*
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02002 * SPDX-License-Identifier: GPL-2.0+
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +09003 */
4
5#include <common.h>
6#include <asm/processor.h>
Nobuhiro Iwamatsua9273312010-06-16 16:55:26 +09007#include <asm/system.h>
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +09008#include <asm/io.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +09009
10#define WDT_BASE WTCNT
11
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090012#define WDT_WD (1 << 6)
13#define WDT_RST_P (0)
14#define WDT_RST_M (1 << 5)
15#define WDT_ENABLE (1 << 7)
16
17#if defined(CONFIG_WATCHDOG)
18static unsigned char csr_read(void)
19{
20 return inb(WDT_BASE + 0x04);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090021}
22
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090023static void cnt_write(unsigned char value)
24{
25 outl((unsigned short)value | 0x5A00, WDT_BASE + 0x00);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090026}
27
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090028static void csr_write(unsigned char value)
29{
30 outl((unsigned short)value | 0xA500, WDT_BASE + 0x04);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090031}
32
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090033void watchdog_reset(void)
34{
35 outl(0x55000000, WDT_BASE + 0x08);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090036}
37
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090038int watchdog_init(void)
39{
40 /* Set overflow time*/
41 cnt_write(0);
42 /* Power on reset */
43 csr_write(WDT_WD|WDT_RST_P|WDT_ENABLE);
44
45 return 0;
46}
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090047
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090048int watchdog_disable(void)
49{
50 csr_write(csr_read() & ~WDT_ENABLE);
51 return 0;
52}
53#endif
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090054
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090055void reset_cpu(unsigned long ignored)
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090056{
Nobuhiro Iwamatsua9273312010-06-16 16:55:26 +090057 /* Address error with SR.BL=1 first. */
58 trigger_address_error();
59
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090060 while (1)
61 ;
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090062}