1 /* $NetBSD: admwdog.c,v 1.1 2007/03/20 08:52:02 dyoung Exp $ */
4 * Copyright (c) 2007 David Young. All rights reserved.
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
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
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials provided
14 * with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: admwdog.c,v 1.1 2007/03/20 08:52:02 dyoung Exp $");
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
38 #include <sys/kernel.h> /* for hz */
40 #include <machine/bus.h>
42 #include <dev/sysmon/sysmonvar.h>
44 #include <mips/adm5120/include/adm5120reg.h>
45 #include <mips/adm5120/include/adm5120var.h>
46 #include <mips/adm5120/include/adm5120_obiovar.h>
47 #include <mips/adm5120/dev/if_admswvar.h>
49 /* maximum watchdog period, seconds */
50 #define ADMWDOG_MAX_PERIOD (__SHIFTOUT_MASK(ADM5120_WDOG_WTS_MASK) / 100)
52 static int admwdog_setmode(struct sysmon_wdog
*smw
);
53 static int admwdog_tickle(struct sysmon_wdog
*smw
);
55 static inline uint32_t
56 admwdog_read(struct admsw_softc
*sc
)
58 return bus_space_read_4(sc
->sc_st
, sc
->sc_ioh
, ADM5120_WDOG0
);
62 admwdog_write(struct admsw_softc
*sc
, uint32_t val
)
64 bus_space_write_4(sc
->sc_st
, sc
->sc_ioh
, ADM5120_WDOG0
, val
);
68 admwdog_reset(struct admsw_softc
*sc
)
73 wdog0
= __SHIFTIN(sc
->sc_smw
.smw_period
* 100, ADM5120_WDOG_WTS_MASK
) |
74 __SHIFTIN(1, ADM5120_WDOG_WT_MASK
);
78 admwdog_write(sc
, wdog0
);
79 (void)admwdog_read(sc
);
80 admwdog_write(sc
, ADM5120_WDOG0_WTTR
| wdog0
);
86 admwdog_setmode(struct sysmon_wdog
*smw
)
88 struct admsw_softc
*sc
= smw
->smw_cookie
;
90 if ((smw
->smw_mode
& WDOG_MODE_MASK
) == WDOG_MODE_DISARMED
) {
95 if (smw
->smw_period
== WDOG_PERIOD_DEFAULT
)
97 else if (smw
->smw_period
> ADMWDOG_MAX_PERIOD
)
106 admwdog_tickle(struct sysmon_wdog
*smw
)
108 struct admsw_softc
*sc
= smw
->smw_cookie
;
110 (void)admwdog_read(sc
);
115 admwdog_attach(struct admsw_softc
*sc
)
117 struct sysmon_wdog
*smw
= &sc
->sc_smw
;
119 /* deactivate watchdog */
120 admwdog_write(sc
, 0);
122 smw
->smw_name
= device_xname(&sc
->sc_dev
);
123 smw
->smw_cookie
= sc
;
124 smw
->smw_setmode
= admwdog_setmode
;
125 smw
->smw_tickle
= admwdog_tickle
;
126 smw
->smw_period
= ADMWDOG_MAX_PERIOD
;
128 sysmon_wdog_register(&sc
->sc_smw
);