1 /* $NetBSD: obio_wdt.c,v 1.4 2008/11/08 09:37:13 cliff Exp $ */
4 * Copyright (c) 2007 Microsoft
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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
33 * obio attachment for GEMINI watchdog timers
35 #include "opt_gemini.h"
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: obio_wdt.c,v 1.4 2008/11/08 09:37:13 cliff Exp $");
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>
49 #include <machine/param.h>
50 #include <machine/bus.h>
51 #include <dev/sysmon/sysmonvar.h>
53 #include <arm/gemini/gemini_obiovar.h>
54 #include <arm/gemini/gemini_wdtvar.h>
55 #include <arm/gemini/gemini_reg.h>
57 static int geminiwdt_match(struct device
*, struct cfdata
*, void *);
58 static void geminiwdt_attach(struct device
*, struct device
*, void *);
60 CFATTACH_DECL_NEW(obiowdt
, sizeof(struct geminiwdt_softc
),
61 geminiwdt_match
, geminiwdt_attach
, NULL
, NULL
);
64 geminiwdt_match(struct device
*parent
, struct cfdata
*cf
, void *aux
)
66 struct obio_attach_args
*obio
= aux
;
68 if (obio
->obio_addr
== OBIOCF_ADDR_DEFAULT
)
69 panic("geminiwdt must have addr specified in config.");
71 if (obio
->obio_addr
== GEMINI_WATCHDOG_BASE
)
78 geminiwdt_attach(struct device
*parent
, struct device
*self
, void *aux
)
80 geminiwdt_softc_t
*sc
= device_private(self
);
81 struct obio_attach_args
*obio
= aux
;
84 sc
->sc_addr
= obio
->obio_addr
;
85 sc
->sc_size
= (obio
->obio_size
== OBIOCF_SIZE_DEFAULT
)
86 ? GEMINI_WDT_WDINTERLEN
+ 4
89 sc
->sc_smw
.smw_name
= device_xname(sc
->sc_dev
);
90 sc
->sc_smw
.smw_cookie
= sc
;
91 sc
->sc_smw
.smw_setmode
= geminiwdt_setmode
;
92 sc
->sc_smw
.smw_tickle
= geminiwdt_tickle
;
93 sc
->sc_smw
.smw_period
= 0;
94 sc
->sc_iot
= obio
->obio_iot
;
96 if (bus_space_map(sc
->sc_iot
, sc
->sc_addr
, sc
->sc_size
, 0, &sc
->sc_ioh
))
97 panic("%s: Cannot map registers", device_xname(self
));
101 sc
->sc_armed
= 1; /* fake armed so can disarm */
102 geminiwdt_enable(0); /* disable, stop, disarm */
104 if (sysmon_wdog_register(&sc
->sc_smw
) != 0) {
106 aprint_error("%s: unable to register with sysmon\n",
107 device_xname(sc
->sc_dev
));