1 /* $NetBSD: sbwdog.c,v 1.8 2009/08/12 12:56:29 simonb Exp $ */
4 * Copyright (c) 2002 Wasabi Systems, Inc.
7 * Written by Jason R. Thorpe and Simon Burge for Wasabi Systems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
39 * Watchdog timer support for the Broadcom BCM1250 processor.
42 #include <sys/cdefs.h>
43 __KERNEL_RCSID(0, "$NetBSD: sbwdog.c,v 1.8 2009/08/12 12:56:29 simonb Exp $");
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/device.h>
50 #include <dev/sysmon/sysmonvar.h>
52 #include <machine/locore.h>
54 #include <mips/sibyte/include/sb1250_regs.h>
55 #include <mips/sibyte/include/sb1250_scd.h>
56 #include <mips/sibyte/dev/sbscdvar.h>
58 #define SBWDOG_DEFAULT_PERIOD 5 /* Default to 5 seconds. */
62 struct sysmon_wdog sc_smw
;
68 static int sbwdog_match(struct device
*, struct cfdata
*, void *);
69 static void sbwdog_attach(struct device
*, struct device
*, void *);
70 static int sbwdog_tickle(struct sysmon_wdog
*);
71 static int sbwdog_setmode(struct sysmon_wdog
*);
73 CFATTACH_DECL(sbwdog
, sizeof(struct sbwdog_softc
),
74 sbwdog_match
, sbwdog_attach
, NULL
, NULL
);
76 #define READ_REG(rp) (mips3_ld((volatile uint64_t *)(rp)))
77 #define WRITE_REG(rp, val) (mips3_sd((volatile uint64_t *)(rp), (val)))
80 sbwdog_match(struct device
*parent
, struct cfdata
*cf
, void *aux
)
82 struct sbscd_attach_args
*sa
= aux
;
84 if (sa
->sa_locs
.sa_type
!= SBSCD_DEVTYPE_WDOG
)
91 sbwdog_attach(struct device
*parent
, struct device
*self
, void *aux
)
93 struct sbwdog_softc
*sc
= (void *)self
;
94 struct sbscd_attach_args
*sa
= aux
;
96 sc
->sc_wdog_period
= SBWDOG_DEFAULT_PERIOD
;
97 sc
->sc_addr
= MIPS_PHYS_TO_KSEG1(sa
->sa_locs
.sa_addr
);
99 printf(": %d second period\n", sc
->sc_wdog_period
);
101 sc
->sc_smw
.smw_name
= sc
->sc_dev
.dv_xname
;
102 sc
->sc_smw
.smw_cookie
= sc
;
103 sc
->sc_smw
.smw_setmode
= sbwdog_setmode
;
104 sc
->sc_smw
.smw_tickle
= sbwdog_tickle
;
105 sc
->sc_smw
.smw_period
= sc
->sc_wdog_period
;
107 if (sysmon_wdog_register(&sc
->sc_smw
) != 0)
108 printf("%s: unable to register with sysmon\n",
109 sc
->sc_dev
.dv_xname
);
113 sbwdog_tickle(struct sysmon_wdog
*smw
)
115 struct sbwdog_softc
*sc
= smw
->smw_cookie
;
117 WRITE_REG(sc
->sc_addr
+ R_SCD_WDOG_CFG
, M_SCD_WDOG_ENABLE
);
122 sbwdog_setmode(struct sysmon_wdog
*smw
)
124 struct sbwdog_softc
*sc
= smw
->smw_cookie
;
126 if ((smw
->smw_mode
& WDOG_MODE_MASK
) == WDOG_MODE_DISARMED
) {
127 if (sc
->sc_wdog_armed
)
128 WRITE_REG(sc
->sc_addr
+ R_SCD_WDOG_CFG
, 0);
130 if (smw
->smw_period
== WDOG_PERIOD_DEFAULT
) {
131 sc
->sc_wdog_period
= SBWDOG_DEFAULT_PERIOD
;
132 smw
->smw_period
= SBWDOG_DEFAULT_PERIOD
; /* XXX needed?? */
133 } else if (smw
->smw_period
> 8) {
134 /* Maximum of 2^23 usec watchdog period. */
137 sc
->sc_wdog_period
= smw
->smw_period
;
138 sc
->sc_wdog_armed
= 1;
139 WRITE_REG(sc
->sc_addr
+ R_SCD_WDOG_INIT
,
140 sc
->sc_wdog_period
* V_SCD_WDOG_FREQ
);
142 /* Watchdog is armed by tickling it. */