Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / evbmips / atheros / wdog.c
blobf2f25c017068408b469daa20f43ae66652f907a5
1 /* $NetBSD: wdog.c,v 1.4 2006/09/04 05:17:26 gdamore Exp $ */
2 /*-
3 * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
4 * Copyright (c) 2006 Garrett D'Amore.
5 * All rights reserved.
7 * Portions of this code were written by Garrett D'Amore for the
8 * Champaign-Urbana Community Wireless Network Project.
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgements:
21 * This product includes software developed by the Urbana-Champaign
22 * Independent Media Center.
23 * This product includes software developed by Garrett D'Amore.
24 * 4. Urbana-Champaign Independent Media Center's name and Garrett
25 * D'Amore's name may not be used to endorse or promote products
26 * derived from this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
29 * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
30 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
33 * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
40 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 * Copyright (c) 2002 Wasabi Systems, Inc.
44 * All rights reserved.
46 * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
50 * are met:
51 * 1. Redistributions of source code must retain the above copyright
52 * notice, this list of conditions and the following disclaimer.
53 * 2. Redistributions in binary form must reproduce the above copyright
54 * notice, this list of conditions and the following disclaimer in the
55 * documentation and/or other materials provided with the distribution.
56 * 3. All advertising materials mentioning features or use of this software
57 * must display the following acknowledgement:
58 * This product includes software developed for the NetBSD Project by
59 * Wasabi Systems, Inc.
60 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
61 * or promote products derived from this software without specific prior
62 * written permission.
64 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
65 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
66 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
67 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
68 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
69 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
70 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
71 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
72 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
73 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
74 * POSSIBILITY OF SUCH DAMAGE.
78 * Watchdog timer support for the AR531x.
81 #include <sys/cdefs.h>
82 __KERNEL_RCSID(0, "$NetBSD: wdog.c,v 1.4 2006/09/04 05:17:26 gdamore Exp $");
84 #include <sys/param.h>
85 #include <sys/systm.h>
86 #include <sys/device.h>
87 #include <sys/wdog.h>
89 #include <machine/cpu.h>
91 #include <mips/atheros/include/ar531xvar.h>
93 #include <dev/sysmon/sysmonvar.h>
95 #ifndef WDOG_DEFAULT_PERIOD
96 #define WDOG_DEFAULT_PERIOD 5
97 #endif
99 static int wdog_match(device_t, struct cfdata *, void *);
100 static void wdog_attach(device_t, device_t, void *);
101 static int wdog_tickle(struct sysmon_wdog *);
102 static int wdog_setmode(struct sysmon_wdog *);
104 struct wdog_softc {
105 struct sysmon_wdog sc_smw;
106 int sc_wdog_period;
107 int sc_wdog_max;
108 uint32_t sc_wdog_reload;
109 uint32_t sc_mult;
112 CFATTACH_DECL_NEW(wdog, sizeof(struct wdog_softc),
113 wdog_match, wdog_attach, NULL, NULL);
115 static int
116 wdog_match(device_t parent, struct cfdata *cf, void *aux)
119 return (1);
122 static void
123 wdog_attach(device_t parent, device_t self, void *aux)
125 struct wdog_softc *sc = device_private(self);
127 sc->sc_mult = ar531x_bus_freq();
128 sc->sc_wdog_period = WDOG_DEFAULT_PERIOD;
129 sc->sc_wdog_max = 0xffffffffU / sc->sc_mult;
130 sc->sc_wdog_reload = sc->sc_wdog_period * sc->sc_mult;
131 aprint_normal(": %d second period\n", sc->sc_wdog_period);
133 sc->sc_smw.smw_name = device_xname(self);
134 sc->sc_smw.smw_cookie = sc;
135 sc->sc_smw.smw_setmode = wdog_setmode;
136 sc->sc_smw.smw_tickle = wdog_tickle;
137 sc->sc_smw.smw_period = sc->sc_wdog_period;
139 if (sysmon_wdog_register(&sc->sc_smw) != 0) {
140 aprint_error_dev(self,
141 "unable to register with sysmon\n");
145 static int
146 wdog_tickle(struct sysmon_wdog *smw)
148 struct wdog_softc *sc = smw->smw_cookie;
150 ar531x_wdog(sc->sc_wdog_reload);
151 return (0);
154 static int
155 wdog_setmode(struct sysmon_wdog *smw)
157 struct wdog_softc *sc = smw->smw_cookie;
159 if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
160 ar531x_wdog(0);
161 } else {
163 if (smw->smw_period == WDOG_PERIOD_DEFAULT)
164 smw->smw_period = sc->sc_wdog_period;
165 else if (smw->smw_period != sc->sc_wdog_period) {
167 * we can't set watchdog periods in excess of
168 * the processor maximum.
170 if (smw->smw_period > sc->sc_wdog_max) {
171 return EOPNOTSUPP;
173 sc->sc_wdog_period = smw->smw_period;
174 sc->sc_wdog_reload = sc->sc_wdog_period * sc->sc_mult;
177 ar531x_wdog(sc->sc_wdog_reload);
180 return (0);