Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 2 | |
| 3 | #include <common.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 4 | #include <cpu_func.h> |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 5 | #include <asm/processor.h> |
Nobuhiro Iwamatsu | a927331 | 2010-06-16 16:55:26 +0900 | [diff] [blame] | 6 | #include <asm/system.h> |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 7 | #include <asm/io.h> |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 8 | |
| 9 | #define WDT_BASE WTCNT |
| 10 | |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 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) |
| 17 | static unsigned char csr_read(void) |
| 18 | { |
| 19 | return inb(WDT_BASE + 0x04); |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 20 | } |
| 21 | |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 22 | static void cnt_write(unsigned char value) |
| 23 | { |
| 24 | outl((unsigned short)value | 0x5A00, WDT_BASE + 0x00); |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 25 | } |
| 26 | |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 27 | static void csr_write(unsigned char value) |
| 28 | { |
| 29 | outl((unsigned short)value | 0xA500, WDT_BASE + 0x04); |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 30 | } |
| 31 | |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 32 | void watchdog_reset(void) |
| 33 | { |
| 34 | outl(0x55000000, WDT_BASE + 0x08); |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 35 | } |
| 36 | |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 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 | } |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 46 | |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 47 | int watchdog_disable(void) |
| 48 | { |
| 49 | csr_write(csr_read() & ~WDT_ENABLE); |
| 50 | return 0; |
| 51 | } |
| 52 | #endif |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 53 | |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 54 | void reset_cpu(void) |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 55 | { |
Nobuhiro Iwamatsu | a927331 | 2010-06-16 16:55:26 +0900 | [diff] [blame] | 56 | /* Address error with SR.BL=1 first. */ |
| 57 | trigger_address_error(); |
| 58 | |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 59 | while (1) |
| 60 | ; |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 61 | } |