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