blob: d4c11e39a0538e0c59410e11a21f0a2e0dbdf7ce [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Macpaul Lin90969632011-01-26 18:46:28 +08002/*
3 * Watchdog driver for the FTWDT010 Watch Dog Driver
4 *
5 * (c) Copyright 2004 Faraday Technology Corp. (www.faraday-tech.com)
6 * Based on sa1100_wdt.c by Oleg Drokin <green@crimea.edu>
7 * Based on SoftDog driver by Alan Cox <alan@redhat.com>
8 *
9 * Copyright (C) 2011 Andes Technology Corporation
10 * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
11 *
Macpaul Lin90969632011-01-26 18:46:28 +080012 * 27/11/2004 Initial release, Faraday.
13 * 12/01/2011 Port to u-boot, Macpaul Lin.
14 */
15
16#ifndef __FTWDT010_H
17#define __FTWDT010_H
18
Tom Rini2f8a6db2021-12-14 13:36:40 -050019#include <clock_legacy.h>
20
Macpaul Lin90969632011-01-26 18:46:28 +080021struct ftwdt010_wdt {
22 unsigned int wdcounter; /* Counter Reg - 0x00 */
23 unsigned int wdload; /* Counter Auto Reload Reg - 0x04 */
24 unsigned int wdrestart; /* Counter Restart Reg - 0x08 */
25 unsigned int wdcr; /* Control Reg - 0x0c */
26 unsigned int wdstatus; /* Status Reg - 0x10 */
27 unsigned int wdclear; /* Timer Clear - 0x14 */
28 unsigned int wdintrlen; /* Interrupt Length - 0x18 */
29};
30
31/*
32 * WDLOAD - Counter Auto Reload Register
33 * The Auto Reload Register is set to 0x03EF1480 (66Mhz) by default.
34 * Which means in a 66MHz system, the period of Watch Dog timer reset is
35 * one second.
36 */
37#define FTWDT010_WDLOAD(x) ((x) & 0xffffffff)
38
39/*
40 * WDRESTART - Watch Dog Timer Counter Restart Register
41 * If writing 0x5AB9 to WDRESTART register, Watch Dog timer will
42 * automatically reload WDLOAD to WDCOUNTER and restart counting.
43 */
44#define FTWDT010_WDRESTART_MAGIC 0x5AB9
45
46/* WDCR - Watch Dog Timer Control Register */
47#define FTWDT010_WDCR_ENABLE (1 << 0)
48#define FTWDT010_WDCR_RST (1 << 1)
49#define FTWDT010_WDCR_INTR (1 << 2)
50/* FTWDT010_WDCR_EXT bit: Watch Dog Timer External Signal Enable */
51#define FTWDT010_WDCR_EXT (1 << 3)
52/* FTWDT010_WDCR_CLOCK bit: Clock Source: 0: PCLK, 1: EXTCLK.
53 * The clock source PCLK cannot be gated when system sleeps, even if
54 * WDCLOCK bit is turned on.
55 *
56 * Faraday's Watch Dog timer can be driven by an external clock. The
57 * programmer just needs to write one to WdCR[WdClock] bit.
58 *
59 * Note: There is a limitation between EXTCLK and PCLK:
60 * EXTCLK cycle time / PCLK cycle time > 2.
61 * If the system does not need an external clock,
62 * just keep WdCR[WdClock] bit in its default value.
63 */
64#define FTWDT010_WDCR_CLOCK (1 << 4)
65
66/*
67 * WDSTATUS - Watch Dog Timer Status Register
68 * This bit is set when the counter reaches Zero
69 */
70#define FTWDT010_WDSTATUS(x) ((x) & 0x1)
71
72/*
73 * WDCLEAR - Watch Dog Timer Clear Register
74 * Writing one to this register will clear WDSTATUS.
75 */
76#define FTWDT010_WDCLEAR (1 << 0)
77
78/*
79 * WDINTRLEN - Watch Dog Timer Interrupt Length
80 * This register controls the duration length of wd_rst, wd_intr and wd_ext.
81 * The default value is 0xFF.
82 */
83#define FTWDT010_WDINTRLEN(x) ((x) & 0xff)
84
85/*
86 * Variable timeout should be set in ms.
Tom Rini2f8a6db2021-12-14 13:36:40 -050087 * (get_board_sys_clk()/1000) equals 1 ms.
Macpaul Lin90969632011-01-26 18:46:28 +080088 * WDLOAD = timeout * TIMEOUT_FACTOR.
89 */
Tom Rini2f8a6db2021-12-14 13:36:40 -050090#define FTWDT010_TIMEOUT_FACTOR (get_board_sys_clk() / 1000) /* 1 ms */
Macpaul Lin90969632011-01-26 18:46:28 +080091
Macpaul Lin90969632011-01-26 18:46:28 +080092#endif /* __FTWDT010_H */