1 /* $NetBSD: wdog.c,v 1.15 2007/03/04 06:00:40 christos Exp $ */
4 * Copyright (C) 2000 SAITOH Masanobu. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: wdog.c,v 1.15 2007/03/04 06:00:40 christos Exp $");
32 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
37 #include <sys/device.h>
38 #include <sys/fcntl.h>
39 #include <sys/ioctl.h>
40 #include <sys/malloc.h>
42 #include <sys/syslog.h>
45 #include <machine/cpu.h>
46 #include <machine/intr.h>
48 #include <sh3/frame.h>
49 #include <sh3/wdtreg.h>
50 #include <sh3/wdogvar.h>
51 #include <sh3/exception.h>
58 static int wdogmatch(device_t
, cfdata_t
, void *);
59 static void wdogattach(device_t
, device_t
, void *);
60 static int wdogintr(void *);
62 CFATTACH_DECL_NEW(wdog
, sizeof(struct wdog_softc
),
63 wdogmatch
, wdogattach
, NULL
, NULL
);
65 extern struct cfdriver wdog_cd
;
67 dev_type_open(wdogopen
);
68 dev_type_close(wdogclose
);
69 dev_type_ioctl(wdogioctl
);
71 const struct cdevsw wdog_cdevsw
= {
72 wdogopen
, wdogclose
, noread
, nowrite
, wdogioctl
,
73 nostop
, notty
, nopoll
, nommap
, nokqfilter
,
77 wdog_wr_cnt(unsigned char x
)
80 SHREG_WTCNT_W
= WTCNT_W_M
| (unsigned short) x
;
84 wdog_wr_csr(unsigned char x
)
87 SHREG_WTCSR_W
= WTCSR_W_M
| (unsigned short) x
;
91 wdogmatch(device_t parent
, cfdata_t cfp
, void *aux
)
94 if (strcmp(cfp
->cf_name
, "wdog"))
101 * functions for probeing.
105 wdogattach(device_t parent
, device_t self
, void *aux
)
107 struct wdog_softc
*sc
;
109 sc
= device_private(self
);
113 aprint_normal(": internal watchdog timer\n");
115 wdog_wr_csr(WTCSR_WT
| WTCSR_CKS_4096
); /* default to wt mode */
117 intc_intr_establish(SH_INTEVT_WDT_ITI
, IST_LEVEL
, IPL_SOFTCLOCK
,
123 wdogopen(dev_t dev
, int flag
, int mode
, struct lwp
*l
)
125 struct wdog_softc
*sc
;
127 sc
= device_lookup_private(&wdog_cd
, minor(dev
));
131 if (sc
->flags
& WDOGF_OPEN
)
133 sc
->flags
|= WDOGF_OPEN
;
139 wdogclose(dev_t dev
, int flag
, int mode
, struct lwp
*l
)
141 struct wdog_softc
*sc
;
143 sc
= device_lookup_private(&wdog_cd
, minor(dev
));
145 if (sc
->flags
& WDOGF_OPEN
)
151 extern unsigned int maxwdog
;
155 wdogioctl(dev_t dev
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
162 request
= *(int *)data
;
166 wdog_wr_csr(SHREG_WTCSR_R
| WTCSR_WT
);
169 wdog_wr_csr(SHREG_WTCSR_R
& ~WTCSR_WT
);
177 wdog_wr_cnt(0); /* reset to zero */
180 wdog_wr_csr(WTCSR_WT
| WTCSR_CKS_4096
);
181 wdog_wr_cnt(0); /* reset to zero */
182 wdog_wr_csr(SHREG_WTCSR_R
| WTCSR_TME
); /* start!!! */
185 wdog_wr_csr(SHREG_WTCSR_R
& ~WTCSR_TME
); /* stop */
188 request
= *(int *)data
;
206 struct trapframe
*frame
= arg
;
208 wdog_wr_csr(SHREG_WTCSR_R
& ~WTCSR_IOVF
); /* clear overflow bit */
209 wdog_wr_cnt(0); /* reset to zero */
210 printf("wdog trapped: spc = %x\n", frame
->tf_spc
);