The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/mips/atheros/ar531x/ar5315_wdog.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2016, Hiroki Mori
    3  * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org>
    4  * 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 unmodified, this list of conditions, and the following
   11  *    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 AND CONTRIBUTORS ``AS IS'' AND
   17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22  * OR 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  * Watchdog driver for AR5315
   31  */
   32 
   33 #include <sys/cdefs.h>
   34 __FBSDID("$FreeBSD: releng/12.0/sys/mips/atheros/ar531x/ar5315_wdog.c 306675 2016-10-04 16:27:36Z adrian $");
   35 
   36 #include <sys/param.h>
   37 #include <sys/systm.h>
   38 #include <sys/watchdog.h>
   39 #include <sys/bus.h>
   40 #include <sys/kernel.h>
   41 #include <sys/module.h>
   42 #include <sys/sysctl.h>
   43 
   44 #include <mips/atheros/ar531x/ar5315reg.h>
   45 #include <mips/atheros/ar531x/ar5315_cpudef.h>
   46 
   47 struct ar5315_wdog_softc {
   48         device_t dev;
   49         int armed;
   50         int reboot_from_watchdog;
   51         int debug;
   52 };
   53 
   54 static void
   55 ar5315_wdog_watchdog_fn(void *private, u_int cmd, int *error)
   56 {
   57         struct ar5315_wdog_softc *sc = private;
   58         uint64_t timer_val;
   59 
   60         cmd &= WD_INTERVAL;
   61         if (sc->debug)
   62                 device_printf(sc->dev, "ar5315_wdog_watchdog_fn: cmd: %x\n", cmd);
   63         if (cmd > 0) {
   64                 timer_val = (uint64_t)(1ULL << cmd) * ar531x_ahb_freq() /
   65                     1000000000;
   66                 if (sc->debug)
   67                         device_printf(sc->dev, "ar5315_wdog_watchdog_fn: programming timer: %jx\n", (uintmax_t) timer_val);
   68                 /*
   69                  * Load timer with large enough value to prevent spurious
   70                  * reset
   71                  */
   72                 ATH_WRITE_REG(ar531x_wdog_timer(), 
   73                     ar531x_ahb_freq() * 10);
   74                 ATH_WRITE_REG(ar531x_wdog_ctl(), 
   75                     AR5315_WDOG_CTL_RESET);
   76                 ATH_WRITE_REG(ar531x_wdog_timer(), 
   77                     (timer_val & 0xffffffff));
   78                 sc->armed = 1;
   79                 *error = 0;
   80         } else {
   81                 if (sc->debug)
   82                         device_printf(sc->dev, "ar5315_wdog_watchdog_fn: disarming\n");
   83                 if (sc->armed) {
   84                         ATH_WRITE_REG(ar531x_wdog_ctl(),
   85                             AR5315_WDOG_CTL_IGNORE);
   86                         sc->armed = 0;
   87                 }
   88         }
   89 }
   90 
   91 static int
   92 ar5315_wdog_probe(device_t dev)
   93 {
   94 
   95         device_set_desc(dev, "Atheros AR531x watchdog timer");
   96         return (0);
   97 }
   98 
   99 static void
  100 ar5315_wdog_sysctl(device_t dev)
  101 {
  102         struct ar5315_wdog_softc *sc = device_get_softc(dev);
  103 
  104         struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->dev);
  105         struct sysctl_oid *tree = device_get_sysctl_tree(sc->dev);
  106 
  107         SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
  108                 "debug", CTLFLAG_RW, &sc->debug, 0,
  109                 "enable watchdog debugging");
  110         SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
  111                 "armed", CTLFLAG_RD, &sc->armed, 0,
  112                 "whether the watchdog is armed");
  113         SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
  114                 "reboot_from_watchdog", CTLFLAG_RD, &sc->reboot_from_watchdog, 0,
  115                 "whether the system rebooted from the watchdog");
  116 }
  117 
  118 
  119 static int
  120 ar5315_wdog_attach(device_t dev)
  121 {
  122         struct ar5315_wdog_softc *sc = device_get_softc(dev);
  123         
  124         /* Initialise */
  125         sc->reboot_from_watchdog = 0;
  126         sc->armed = 0;
  127         sc->debug = 0;
  128         ATH_WRITE_REG(ar531x_wdog_ctl(), AR5315_WDOG_CTL_IGNORE);
  129 
  130         sc->dev = dev;
  131         EVENTHANDLER_REGISTER(watchdog_list, ar5315_wdog_watchdog_fn, sc, 0);
  132         ar5315_wdog_sysctl(dev);
  133 
  134         return (0);
  135 }
  136 
  137 static device_method_t ar5315_wdog_methods[] = {
  138         DEVMETHOD(device_probe, ar5315_wdog_probe),
  139         DEVMETHOD(device_attach, ar5315_wdog_attach),
  140         DEVMETHOD_END
  141 };
  142 
  143 static driver_t ar5315_wdog_driver = {
  144         "ar5315_wdog",
  145         ar5315_wdog_methods,
  146         sizeof(struct ar5315_wdog_softc),
  147 };
  148 static devclass_t ar5315_wdog_devclass;
  149 
  150 DRIVER_MODULE(ar5315_wdog, apb, ar5315_wdog_driver, ar5315_wdog_devclass, 0, 0);

Cache object: ea5938ee70d73e1e8588ac5c19b734ff


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.