xref: /netbsd-src/sys/arch/arm/gemini/obio_wdt.c (revision 40f7eaaf2596ce16adf343e6680d62b6ed6f12dd)
1 /*	$NetBSD: obio_wdt.c,v 1.8 2019/01/08 19:41:10 jdolecek Exp $	*/
2 
3 /*
4  * Copyright (c) 2007 Microsoft
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *     This product includes software developed by Microsoft
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT,
23  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 /*
33  * obio attachment for GEMINI watchdog timers
34  */
35 #include "opt_gemini.h"
36 #include "locators.h"
37 
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: obio_wdt.c,v 1.8 2019/01/08 19:41:10 jdolecek Exp $");
40 
41 #include <sys/param.h>
42 #include <sys/callout.h>
43 #include <sys/cdefs.h>
44 #include <sys/device.h>
45 #include <sys/kernel.h>
46 #include <sys/systm.h>
47 #include <sys/wdog.h>
48 
49 #include <sys/bus.h>
50 #include <dev/sysmon/sysmonvar.h>
51 
52 #include <arm/gemini/gemini_obiovar.h>
53 #include <arm/gemini/gemini_wdtvar.h>
54 #include <arm/gemini/gemini_reg.h>
55 
56 static int geminiwdt_match(device_t, cfdata_t, void *);
57 static void geminiwdt_attach(device_t, device_t, void *);
58 
59 CFATTACH_DECL_NEW(obiowdt, sizeof(struct geminiwdt_softc),
60     geminiwdt_match, geminiwdt_attach, NULL, NULL);
61 
62 static int
geminiwdt_match(device_t parent,cfdata_t cf,void * aux)63 geminiwdt_match(device_t parent, cfdata_t cf, void *aux)
64 {
65 	struct obio_attach_args *obio = aux;
66 
67 	if (obio->obio_addr == OBIOCF_ADDR_DEFAULT)
68 		panic("geminiwdt must have addr specified in config.");
69 
70 	if (obio->obio_addr == GEMINI_WATCHDOG_BASE)
71 		return 1;
72 
73 	return 0;
74 }
75 
76 static void
geminiwdt_attach(device_t parent,device_t self,void * aux)77 geminiwdt_attach(device_t parent, device_t self, void *aux)
78 {
79 	geminiwdt_softc_t *sc = device_private(self);
80 	struct obio_attach_args *obio = aux;
81 
82 	sc->sc_dev = self;
83 	sc->sc_addr = obio->obio_addr;
84 	sc->sc_size = (obio->obio_size == OBIOCF_SIZE_DEFAULT)
85 		? GEMINI_WDT_WDINTERLEN + 4
86 		: obio->obio_size;
87 
88 	sc->sc_smw.smw_name = device_xname(sc->sc_dev);
89 	sc->sc_smw.smw_cookie = sc;
90 	sc->sc_smw.smw_setmode = geminiwdt_setmode;
91 	sc->sc_smw.smw_tickle = geminiwdt_tickle;
92 	sc->sc_smw.smw_period = 0;
93 	sc->sc_iot = obio->obio_iot;
94 
95 	if (bus_space_map(sc->sc_iot, sc->sc_addr, sc->sc_size, 0, &sc->sc_ioh))
96 		panic("%s: Cannot map registers", device_xname(self));
97 
98 	geminiwdt_sc = sc;
99 
100 	sc->sc_armed = 1;	/* fake armed so can disarm */
101 	geminiwdt_enable(0);	/* disable, stop, disarm */
102 
103 	if (sysmon_wdog_register(&sc->sc_smw) != 0) {
104 		geminiwdt_sc = NULL;
105 		aprint_error("%s: unable to register with sysmon\n",
106 			     device_xname(sc->sc_dev));
107 	}
108 
109 	aprint_normal("\n");
110 	aprint_naive("\n");
111 }
112