1 /* $NetBSD: obio_wdt.c,v 1.6 2011/07/01 19:32:28 dyoung 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.6 2011/07/01 19:32:28 dyoung 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 <machine/param.h> 50 #include <sys/bus.h> 51 #include <dev/sysmon/sysmonvar.h> 52 53 #include <arm/gemini/gemini_obiovar.h> 54 #include <arm/gemini/gemini_wdtvar.h> 55 #include <arm/gemini/gemini_reg.h> 56 57 static int geminiwdt_match(struct device *, struct cfdata *, void *); 58 static void geminiwdt_attach(struct device *, struct device *, void *); 59 60 CFATTACH_DECL_NEW(obiowdt, sizeof(struct geminiwdt_softc), 61 geminiwdt_match, geminiwdt_attach, NULL, NULL); 62 63 static int 64 geminiwdt_match(struct device *parent, struct cfdata *cf, void *aux) 65 { 66 struct obio_attach_args *obio = aux; 67 68 if (obio->obio_addr == OBIOCF_ADDR_DEFAULT) 69 panic("geminiwdt must have addr specified in config."); 70 71 if (obio->obio_addr == GEMINI_WATCHDOG_BASE) 72 return 1; 73 74 return 0; 75 } 76 77 static void 78 geminiwdt_attach(struct device *parent, struct device *self, void *aux) 79 { 80 geminiwdt_softc_t *sc = device_private(self); 81 struct obio_attach_args *obio = aux; 82 83 sc->sc_dev = self; 84 sc->sc_addr = obio->obio_addr; 85 sc->sc_size = (obio->obio_size == OBIOCF_SIZE_DEFAULT) 86 ? GEMINI_WDT_WDINTERLEN + 4 87 : obio->obio_size; 88 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; 95 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)); 98 99 geminiwdt_sc = sc; 100 101 sc->sc_armed = 1; /* fake armed so can disarm */ 102 geminiwdt_enable(0); /* disable, stop, disarm */ 103 104 if (sysmon_wdog_register(&sc->sc_smw) != 0) { 105 geminiwdt_sc = NULL; 106 aprint_error("%s: unable to register with sysmon\n", 107 device_xname(sc->sc_dev)); 108 } 109 110 aprint_normal("\n"); 111 aprint_naive("\n"); 112 } 113