xref: /netbsd-src/sys/arch/arm/ep93xx/epwdog.c (revision 7804a487ed1c65ca40d4dd472f0ab80f0e4d1b02)
1 /*	$NetBSD: epwdog.c,v 1.6 2021/11/21 08:25:26 skrll Exp $	*/
2 
3 /*
4  * Copyright (c) 2005 HAMAJIMA Katsuomi. All rights reserved.
5  *
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.
14  *
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.
26  */
27 
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: epwdog.c,v 1.6 2021/11/21 08:25:26 skrll Exp $");
30 
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/device.h>
35 #include <sys/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>
40 
41 struct epwdog_softc {
42 	bus_space_tag_t		sc_iot;
43 	bus_space_handle_t	sc_ioh;
44 };
45 
46 static int epwdog_match(device_t, cfdata_t, void *);
47 static void epwdog_attach(device_t, device_t, void *);
48 
49 CFATTACH_DECL_NEW(epwdog, sizeof(struct epwdog_softc),
50 	      epwdog_match, epwdog_attach, NULL, NULL);
51 
52 static struct epwdog_softc *the_epwdog_sc = 0;
53 
54 static int
epwdog_match(device_t parent,cfdata_t match,void * aux)55 epwdog_match(device_t parent, cfdata_t match, void *aux)
56 {
57 	return 1;
58 }
59 
60 static void
epwdog_attach(device_t parent,device_t self,void * aux)61 epwdog_attach(device_t parent, device_t self, void *aux)
62 {
63 	struct epwdog_softc *sc = device_private(self);
64 	struct epsoc_attach_args *sa = aux;
65 
66 	printf("\n");
67 	sc->sc_iot = sa->sa_iot;
68 
69 	if (bus_space_map(sa->sa_iot, sa->sa_addr,
70 			  sa->sa_size, 0, &sc->sc_ioh)) {
71 		printf("%s: Cannot map registers", device_xname(self));
72 		return;
73 	}
74 
75 	if (!the_epwdog_sc)
76 		the_epwdog_sc = sc;
77 #ifdef DIAGNOSTIC
78 	else
79 		printf("%s is already configured\n", device_xname(self));
80 #endif
81 }
82 
83 int
epwdog_reset(void)84 epwdog_reset(void)
85 {
86 	struct epwdog_softc *sc = the_epwdog_sc;
87 
88 #ifdef DIAGNOSTIC
89 	if (!sc) {
90 		printf("epwdog not configured\n");
91 		return (ENXIO);
92 	}
93 #endif
94 
95 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,
96 			  EP93XX_WDOG_Ctrl, EP93XX_WDOG_DISABLE);
97 	splhigh();
98 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,
99 			  EP93XX_WDOG_Ctrl, EP93XX_WDOG_ENABLE);
100 	while (1);
101 
102 	return 0; /* not reached */
103 }
104