Home | History | Annotate | Line # | Download | only in gemini
obio_wdt.c revision 1.7.38.1
      1  1.7.38.1  christos /*	$NetBSD: obio_wdt.c,v 1.7.38.1 2019/06/10 22:05:53 christos 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.7.38.1  christos __KERNEL_RCSID(0, "$NetBSD: obio_wdt.c,v 1.7.38.1 2019/06/10 22:05:53 christos 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.6    dyoung #include <sys/bus.h>
     50       1.1      matt #include <dev/sysmon/sysmonvar.h>
     51       1.1      matt 
     52       1.1      matt #include <arm/gemini/gemini_obiovar.h>
     53       1.1      matt #include <arm/gemini/gemini_wdtvar.h>
     54       1.1      matt #include <arm/gemini/gemini_reg.h>
     55       1.1      matt 
     56       1.7       chs static int geminiwdt_match(device_t, cfdata_t, void *);
     57       1.7       chs static void geminiwdt_attach(device_t, device_t, void *);
     58       1.1      matt 
     59       1.5     cliff CFATTACH_DECL_NEW(obiowdt, sizeof(struct geminiwdt_softc),
     60       1.1      matt     geminiwdt_match, geminiwdt_attach, NULL, NULL);
     61       1.1      matt 
     62       1.1      matt static int
     63       1.7       chs geminiwdt_match(device_t parent, cfdata_t cf, void *aux)
     64       1.1      matt {
     65       1.1      matt 	struct obio_attach_args *obio = aux;
     66       1.1      matt 
     67       1.4     cliff 	if (obio->obio_addr == OBIOCF_ADDR_DEFAULT)
     68       1.1      matt 		panic("geminiwdt must have addr specified in config.");
     69       1.1      matt 
     70       1.1      matt 	if (obio->obio_addr == GEMINI_WATCHDOG_BASE)
     71       1.1      matt 		return 1;
     72       1.1      matt 
     73       1.1      matt 	return 0;
     74       1.1      matt }
     75       1.1      matt 
     76       1.1      matt static void
     77       1.7       chs geminiwdt_attach(device_t parent, device_t self, void *aux)
     78       1.1      matt {
     79       1.3     cliff 	geminiwdt_softc_t *sc = device_private(self);
     80       1.1      matt 	struct obio_attach_args *obio = aux;
     81       1.1      matt 
     82       1.5     cliff 	sc->sc_dev = self;
     83       1.1      matt 	sc->sc_addr = obio->obio_addr;
     84       1.4     cliff 	sc->sc_size = (obio->obio_size == OBIOCF_SIZE_DEFAULT)
     85       1.1      matt 		? GEMINI_WDT_WDINTERLEN + 4
     86       1.1      matt 		: obio->obio_size;
     87       1.1      matt 
     88       1.5     cliff 	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.5     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