Home | History | Annotate | Line # | Download | only in gemini
      1 /*	$NetBSD: obio_wdt.c,v 1.9 2025/12/19 13:03:51 nia 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  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT,
     20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 /*
     30  * obio attachment for GEMINI watchdog timers
     31  */
     32 #include "opt_gemini.h"
     33 #include "locators.h"
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(0, "$NetBSD: obio_wdt.c,v 1.9 2025/12/19 13:03:51 nia Exp $");
     37 
     38 #include <sys/param.h>
     39 #include <sys/callout.h>
     40 #include <sys/cdefs.h>
     41 #include <sys/device.h>
     42 #include <sys/kernel.h>
     43 #include <sys/systm.h>
     44 #include <sys/wdog.h>
     45 
     46 #include <sys/bus.h>
     47 #include <dev/sysmon/sysmonvar.h>
     48 
     49 #include <arm/gemini/gemini_obiovar.h>
     50 #include <arm/gemini/gemini_wdtvar.h>
     51 #include <arm/gemini/gemini_reg.h>
     52 
     53 static int geminiwdt_match(device_t, cfdata_t, void *);
     54 static void geminiwdt_attach(device_t, device_t, void *);
     55 
     56 CFATTACH_DECL_NEW(obiowdt, sizeof(struct geminiwdt_softc),
     57     geminiwdt_match, geminiwdt_attach, NULL, NULL);
     58 
     59 static int
     60 geminiwdt_match(device_t parent, cfdata_t cf, void *aux)
     61 {
     62 	struct obio_attach_args *obio = aux;
     63 
     64 	if (obio->obio_addr == OBIOCF_ADDR_DEFAULT)
     65 		panic("geminiwdt must have addr specified in config.");
     66 
     67 	if (obio->obio_addr == GEMINI_WATCHDOG_BASE)
     68 		return 1;
     69 
     70 	return 0;
     71 }
     72 
     73 static void
     74 geminiwdt_attach(device_t parent, device_t self, void *aux)
     75 {
     76 	geminiwdt_softc_t *sc = device_private(self);
     77 	struct obio_attach_args *obio = aux;
     78 
     79 	sc->sc_dev = self;
     80 	sc->sc_addr = obio->obio_addr;
     81 	sc->sc_size = (obio->obio_size == OBIOCF_SIZE_DEFAULT)
     82 		? GEMINI_WDT_WDINTERLEN + 4
     83 		: obio->obio_size;
     84 
     85 	sc->sc_smw.smw_name = device_xname(sc->sc_dev);
     86 	sc->sc_smw.smw_cookie = sc;
     87 	sc->sc_smw.smw_setmode = geminiwdt_setmode;
     88 	sc->sc_smw.smw_tickle = geminiwdt_tickle;
     89 	sc->sc_smw.smw_period = 0;
     90 	sc->sc_iot = obio->obio_iot;
     91 
     92 	if (bus_space_map(sc->sc_iot, sc->sc_addr, sc->sc_size, 0, &sc->sc_ioh))
     93 		panic("%s: Cannot map registers", device_xname(self));
     94 
     95 	geminiwdt_sc = sc;
     96 
     97 	sc->sc_armed = 1;	/* fake armed so can disarm */
     98 	geminiwdt_enable(0);	/* disable, stop, disarm */
     99 
    100 	if (sysmon_wdog_register(&sc->sc_smw) != 0) {
    101 		geminiwdt_sc = NULL;
    102 		aprint_error("%s: unable to register with sysmon\n",
    103 			     device_xname(sc->sc_dev));
    104 	}
    105 
    106 	aprint_normal("\n");
    107 	aprint_naive("\n");
    108 }
    109