Home | History | Annotate | Line # | Download | only in ep93xx
epwdog.c revision 1.2
      1 /*	$NetBSD: epwdog.c,v 1.2 2006/03/26 04:38:52 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2005 HAMAJIMA Katsuomi. All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  * SUCH DAMAGE.
     26  */
     27 
     28 #include <sys/cdefs.h>
     29 __KERNEL_RCSID(0, "$NetBSD: epwdog.c,v 1.2 2006/03/26 04:38:52 thorpej Exp $");
     30 
     31 #include <sys/param.h>
     32 #include <sys/systm.h>
     33 #include <sys/kernel.h>
     34 #include <sys/device.h>
     35 #include <machine/bus.h>
     36 #include <arm/ep93xx/ep93xxvar.h>
     37 #include <arm/ep93xx/epsocvar.h>
     38 #include <arm/ep93xx/epwdogreg.h>
     39 #include <arm/ep93xx/epwdogvar.h>
     40 
     41 struct epwdog_softc {
     42 	struct device		sc_dev;
     43 	bus_space_tag_t		sc_iot;
     44 	bus_space_handle_t	sc_ioh;
     45 };
     46 
     47 static int epwdog_match(struct device *, struct cfdata *, void *);
     48 static void epwdog_attach(struct device *, struct device *, void *);
     49 
     50 CFATTACH_DECL(epwdog, sizeof(struct epwdog_softc),
     51 	      epwdog_match, epwdog_attach, NULL, NULL);
     52 
     53 static struct epwdog_softc *the_epwdog_sc = 0;
     54 
     55 static int
     56 epwdog_match(struct device *parent, struct cfdata *match, void *aux)
     57 {
     58 	return 1;
     59 }
     60 
     61 static void
     62 epwdog_attach(struct device *parent, struct device *self, void *aux)
     63 {
     64 	struct epwdog_softc *sc = (struct epwdog_softc*)self;
     65 	struct epsoc_attach_args *sa = aux;
     66 
     67 	printf("\n");
     68 	sc->sc_iot = sa->sa_iot;
     69 
     70 	if (bus_space_map(sa->sa_iot, sa->sa_addr,
     71 			  sa->sa_size, 0, &sc->sc_ioh)){
     72 		printf("%s: Cannot map registers", self->dv_xname);
     73 		return;
     74 	}
     75 
     76 	if (!the_epwdog_sc)
     77 		the_epwdog_sc = sc;
     78 #ifdef DIAGNOSTIC
     79 	else
     80 		printf("%s is already configured\n", sc->sc_dev.dv_xname);
     81 
     82 int
     83 epwdog_reset(void)
     84 {
     85 	struct epwdog_softc *sc = the_epwdog_sc;
     86 
     87 #ifdef DIAGNOSTIC
     88 	if (!sc) {
     89 		printf("epwdog not configured\n");
     90 		return (ENXIO);
     91 	}
     92 #endif
     93 
     94 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,
     95 			  EP93XX_WDOG_Ctrl, EP93XX_WDOG_DISABLE);
     96 	splhigh();
     97 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,
     98 			  EP93XX_WDOG_Ctrl, EP93XX_WDOG_ENABLE);
     99 	while (1);
    100 
    101 	return 0; /* not reached */
    102 }
    103