1/* $NetBSD: epwdog.c,v 1.3 2006/08/21 15:01:54 hamajima 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.3 2006/08/21 15:01:54 hamajima Exp $"); 30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/kernel.h> 34#include <sys/device.h> 35#include <sys/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 41struct epwdog_softc { 42 struct device sc_dev; 43 bus_space_tag_t sc_iot; 44 bus_space_handle_t sc_ioh; 45}; 46 47static int epwdog_match(struct device *, struct cfdata *, void *); 48static void epwdog_attach(struct device *, struct device *, void *); 49 50CFATTACH_DECL(epwdog, sizeof(struct epwdog_softc), 51 epwdog_match, epwdog_attach, NULL, NULL); 52 53static struct epwdog_softc *the_epwdog_sc = 0; 54 55static int 56epwdog_match(struct device *parent, struct cfdata *match, void *aux) 57{ 58 return 1; 59} 60 61static void 62epwdog_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#endif 82} 83 84int 85epwdog_reset(void) 86{ 87 struct epwdog_softc *sc = the_epwdog_sc; 88 89#ifdef DIAGNOSTIC 90 if (!sc) { 91 printf("epwdog not configured\n"); 92 return (ENXIO); 93 } 94#endif 95 96 bus_space_write_2(sc->sc_iot, sc->sc_ioh, 97 EP93XX_WDOG_Ctrl, EP93XX_WDOG_DISABLE); 98 splhigh(); 99 bus_space_write_2(sc->sc_iot, sc->sc_ioh, 100 EP93XX_WDOG_Ctrl, EP93XX_WDOG_ENABLE); 101 while (1); 102 103 return 0; /* not reached */ 104} 105