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