No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / arm / ep93xx / epwdog.c
blob58a682855c1f5caf98591ea9c5bf5aa153994d8d
1 /* $NetBSD: epwdog.c,v 1.2 2006/03/26 04:38:52 thorpej Exp $ */
3 /*
4 * Copyright (c) 2005 HAMAJIMA Katsuomi. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: epwdog.c,v 1.2 2006/03/26 04:38:52 thorpej Exp $");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/device.h>
35 #include <machine/bus.h>
36 #include <arm/ep93xx/ep93xxvar.h>
37 #include <arm/ep93xx/epsocvar.h>
38 #include <arm/ep93xx/epwdogreg.h>
39 #include <arm/ep93xx/epwdogvar.h>
41 struct epwdog_softc {
42 struct device sc_dev;
43 bus_space_tag_t sc_iot;
44 bus_space_handle_t sc_ioh;
47 static int epwdog_match(struct device *, struct cfdata *, void *);
48 static void epwdog_attach(struct device *, struct device *, void *);
50 CFATTACH_DECL(epwdog, sizeof(struct epwdog_softc),
51 epwdog_match, epwdog_attach, NULL, NULL);
53 static struct epwdog_softc *the_epwdog_sc = 0;
55 static int
56 epwdog_match(struct device *parent, struct cfdata *match, void *aux)
58 return 1;
61 static void
62 epwdog_attach(struct device *parent, struct device *self, void *aux)
64 struct epwdog_softc *sc = (struct epwdog_softc*)self;
65 struct epsoc_attach_args *sa = aux;
67 printf("\n");
68 sc->sc_iot = sa->sa_iot;
70 if (bus_space_map(sa->sa_iot, sa->sa_addr,
71 sa->sa_size, 0, &sc->sc_ioh)){
72 printf("%s: Cannot map registers", self->dv_xname);
73 return;
76 if (!the_epwdog_sc)
77 the_epwdog_sc = sc;
78 #ifdef DIAGNOSTIC
79 else
80 printf("%s is already configured\n", sc->sc_dev.dv_xname);
81 #endif
84 int
85 epwdog_reset(void)
87 struct epwdog_softc *sc = the_epwdog_sc;
89 #ifdef DIAGNOSTIC
90 if (!sc) {
91 printf("epwdog not configured\n");
92 return (ENXIO);
94 #endif
96 bus_space_write_2(sc->sc_iot, sc->sc_ioh,
97 EP93XX_WDOG_Ctrl, EP93XX_WDOG_DISABLE);
98 splhigh();
99 bus_space_write_2(sc->sc_iot, sc->sc_ioh,
100 EP93XX_WDOG_Ctrl, EP93XX_WDOG_ENABLE);
101 while (1);
103 return 0; /* not reached */