blob: 8823ed12f436355d87a35522addc441d78b81574 [file] [log] [blame]
wdenke28cf632004-03-14 15:20:55 +00001/*
2 * (C) Copyright 2004, Li-Pro.Net <www.li-pro.net>
3 * Stephan Linz <linz@li-pro.net>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <command.h>
26#include <nios.h>
27#include <nios-io.h>
28
29#if defined(CONFIG_HW_WATCHDOG)
30
31#if !defined(CONFIG_HW_WDENA_BASE)
32#error "*** CONFIG_HW_WDENA_BASE not defined ***"
33#if !defined(CONFIG_HW_WDENA_BIT)
34#error "*** CONFIG_HW_WDENA_BIT not defined ***"
35#endif
36#endif
37
38#if !defined(CONFIG_HW_WDTOG_BASE)
39#error "*** CONFIG_HW_WDTOG_BASE not defined ***"
40#if !defined(CONFIG_HW_WDTOG_BIT)
41#error "*** CONFIG_HW_WDTOG_BIT not defined ***"
42#endif
43#endif
44
45#ifdef CONFIG_HW_WDPORT_WRONLY /* emulate read access */
46static unsigned __wd_ena_pio_portval = 0;
47#endif
48
49#define WD_PIO_INIT_DONE(V) ((V) & (1 << CONFIG_HW_WDENA_BIT))
50
51void ssv_wd_pio_init(void)
52{
53 nios_pio_t *ena_piop = (nios_pio_t*)CONFIG_HW_WDENA_BASE;
54 nios_pio_t *trg_piop = (nios_pio_t*)CONFIG_HW_WDTOG_BASE;
55
56 trg_piop->data &= ~(1 << CONFIG_HW_WDTOG_BIT);
57
58#ifdef CONFIG_HW_WDPORT_WRONLY /* emulate read access */
59
60 __wd_ena_pio_portval |= (1 << CONFIG_HW_WDENA_BIT);
61 ena_piop->data = __wd_ena_pio_portval;
62
63#else /* !CONFIG_HW_WDPORT_WRONLY */
64
65 trg_piop->direction |= (1 << CONFIG_HW_WDTOG_BIT);
66
67 ena_piop->data |= (1 << CONFIG_HW_WDENA_BIT);
68 ena_piop->direction |= (1 << CONFIG_HW_WDENA_BIT);
69
70#endif /* CONFIG_HW_WDPORT_WRONLY */
71}
72
73void ssv_wd_pio_done(void)
74{
75 nios_pio_t *piop = (nios_pio_t*)CONFIG_HW_WDENA_BASE;
76
77#ifdef CONFIG_HW_WDPORT_WRONLY /* emulate read access */
78
79 __wd_ena_pio_portval &= ~(1 << CONFIG_HW_WDENA_BIT);
80 piop->data = __wd_ena_pio_portval;
81
82#else /* !CONFIG_HW_WDPORT_WRONLY */
83
84 piop->data &= ~(1 << CONFIG_HW_WDENA_BIT);
85
86#endif /* CONFIG_HW_WDPORT_WRONLY */
87}
88
89void ssv_wd_pio_reset(void)
90{
91 nios_pio_t *trg_piop = (nios_pio_t*)CONFIG_HW_WDTOG_BASE;
92
93#ifdef CONFIG_HW_WDPORT_WRONLY
94 if (WD_PIO_INIT_DONE(__wd_ena_pio_portval))
95#else
96 nios_pio_t *ena_piop = (nios_pio_t*)CONFIG_HW_WDENA_BASE;
97
98 if (WD_PIO_INIT_DONE(ena_piop->data))
99#endif
100 {
101 trg_piop->data |= (1 << CONFIG_HW_WDTOG_BIT);
102 trg_piop->data &= ~(1 << CONFIG_HW_WDTOG_BIT);
103 }
104}
105
106void hw_watchdog_reset(void)
107{
108 int re_enable = disable_interrupts ();
109
110 ssv_wd_pio_reset();
111 if (re_enable)
112 enable_interrupts ();
113}
114
Jon Loeligere11c1232007-07-09 18:45:16 -0500115#if defined(CONFIG_CMD_BSP)
wdenke28cf632004-03-14 15:20:55 +0000116int do_wd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
117{
118 nios_pio_t *ena_piop = (nios_pio_t*)CONFIG_HW_WDENA_BASE;
119
120 switch (argc)
121 {
122 case 1:
123 printf ("Watchdog timer status is %s\n",
124#ifdef CONFIG_HW_WDPORT_WRONLY
125 WD_PIO_INIT_DONE(__wd_ena_pio_portval)
126#else
127 WD_PIO_INIT_DONE(ena_piop->data)
128#endif
129 ? "on" : "off");
130 return 0;
131 case 2:
132 if (!strcmp(argv[1],"on"))
133 {
134 ssv_wd_pio_init();
135 printf("Watchdog timer now is on\n");
136 return 0;
137 }
138 else if (!strcmp(argv[1],"off"))
139 {
140 ssv_wd_pio_done();
141 printf("Watchdog timer now is off\n");
142 return 0;
143 }
144 break;
145 default:
146 break;
147 }
Peter Tyserddb3af92009-01-27 18:03:10 -0600148 cmd_usage(cmdtp);
wdenke28cf632004-03-14 15:20:55 +0000149 return 1;
150}
151
152U_BOOT_CMD(
153 wd, 2, 1, do_wd,
154 "wd - check and set watchdog\n",
155 "on - switch watchDog on\n"
156 "wd off - switch watchdog off\n"
157 "wd - print current status\n"
158);
Jon Loeliger761ea742007-07-10 10:48:22 -0500159#endif
wdenke28cf632004-03-14 15:20:55 +0000160#endif /* CONFIG_HW_WATCHDOG */