blob: f6924290f00c381916c9ba24c8ba33625cf8351b [file] [log] [blame]
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +09001/*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation; either version 2 of
5 * the License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
15 * MA 02111-1307 USA
16 */
17
18#include <common.h>
19#include <asm/processor.h>
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090020#include <asm/io.h>
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090021
22#define WDT_BASE WTCNT
23
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090024#define WDT_WD (1 << 6)
25#define WDT_RST_P (0)
26#define WDT_RST_M (1 << 5)
27#define WDT_ENABLE (1 << 7)
28
29#if defined(CONFIG_WATCHDOG)
30static unsigned char csr_read(void)
31{
32 return inb(WDT_BASE + 0x04);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090033}
34
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090035static void cnt_write(unsigned char value)
36{
37 outl((unsigned short)value | 0x5A00, WDT_BASE + 0x00);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090038}
39
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090040static void csr_write(unsigned char value)
41{
42 outl((unsigned short)value | 0xA500, WDT_BASE + 0x04);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090043}
44
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090045void watchdog_reset(void)
46{
47 outl(0x55000000, WDT_BASE + 0x08);
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090048}
49
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090050int watchdog_init(void)
51{
52 /* Set overflow time*/
53 cnt_write(0);
54 /* Power on reset */
55 csr_write(WDT_WD|WDT_RST_P|WDT_ENABLE);
56
57 return 0;
58}
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090059
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090060int watchdog_disable(void)
61{
62 csr_write(csr_read() & ~WDT_ENABLE);
63 return 0;
64}
65#endif
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090066
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090067void reset_cpu(unsigned long ignored)
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090068{
Nobuhiro Iwamatsu4c9c1092008-09-18 19:04:26 +090069 while (1)
70 ;
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +090071}