1 /* $NetBSD: pld_wdog.c,v 1.6 2008/04/28 20:23:36 martin Exp $ */
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following 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.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/device.h>
34 #include <machine/autoconf.h>
36 #include <dev/ebus/ebusreg.h>
37 #include <dev/ebus/ebusvar.h>
39 #include <dev/sysmon/sysmonvar.h>
41 #define PLD_WDOG1_COUNTER 0x00
42 #define PLD_WDOG1_LIMIT 0x04
43 #define PLD_WDOG1_STATUS 0x08
44 #define PLD_WDOG2_COUNTER 0x10
45 #define PLD_WDOG2_LIMIT 0x14
46 #define PLD_WDOG2_STATUS 0x18
47 #define PLD_WDOG3_COUNTER 0x20
48 #define PLD_WDOG3_LIMIT 0x24
49 #define PLD_WDOG3_STATUS 0x28
51 #define PLD_WDOG_INTR_MASK 0x30
52 #define PLD_WDOG_STATUS 0x34
54 #define PLD_WDOG_PERIOD_DEFAULT 15 /* seconds */
56 /* #define PLD_WDOG_DEBUG 1 */
58 struct pldwdog_softc
{
61 bus_space_tag_t sc_btag
;
62 bus_space_handle_t sc_bh
;
64 struct sysmon_wdog sc_smw
;
68 int pldwdog_match(struct device
*, struct cfdata
*, void *);
69 void pldwdog_attach(struct device
*, struct device
*, void *);
71 CFATTACH_DECL(pldwdog
, sizeof(struct pldwdog_softc
),
72 pldwdog_match
, pldwdog_attach
, NULL
, NULL
);
75 static void pldwdog_regs(struct pldwdog_softc
*);
79 pldwdog_tickle(struct sysmon_wdog
*smw
)
81 struct pldwdog_softc
*sc
= smw
->smw_cookie
;
84 printf("%s: pldwdog_tickle: mode %x, period %d\n",
85 device_xname(&sc
->sc_dev
), smw
->smw_mode
, smw
->smw_period
);
86 /* pldwdog_regs(sc); */
89 bus_space_write_2(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG2_LIMIT
,
90 smw
->smw_period
* 10);
91 bus_space_write_1(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG_INTR_MASK
, 5);
97 pldwdog_setmode(struct sysmon_wdog
*smw
)
99 struct pldwdog_softc
*sc
= smw
->smw_cookie
;
101 #ifdef PLD_WDOG_DEBUG
102 printf("%s:pldwdog_setmode: mode %x\n", device_xname(&sc
->sc_dev
), smw
->smw_mode
);
105 if ((smw
->smw_mode
& WDOG_MODE_MASK
) == WDOG_MODE_DISARMED
) {
106 bus_space_write_1(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG_INTR_MASK
, 7);
108 if (smw
->smw_period
== WDOG_PERIOD_DEFAULT
)
109 smw
->smw_period
= sc
->sc_wdog_period
;
117 static int pldwdog_intr(void);
122 printf("pldwdog_intr:\n");
129 pldwdog_match(struct device
*parent
, struct cfdata
*cf
, void *aux
)
131 struct ebus_attach_args
*ea
= aux
;
133 return (strcmp("watchdog", ea
->ea_name
) == 0);
136 #ifdef PLD_WDOG_DEBUG
138 pldwdog_regs(struct pldwdog_softc
*sc
)
141 printf("%s: status 0x%02x, intr mask 0x%02x\n",
142 device_xname(&sc
->sc_dev
),
143 bus_space_read_1(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG_INTR_MASK
),
144 bus_space_read_1(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG_STATUS
));
146 printf("%s: wdog1: count 0x%04x, limit 0x%04x, status 0x%02x\n",
147 device_xname(&sc
->sc_dev
),
148 bus_space_read_2(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG1_COUNTER
),
149 bus_space_read_2(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG1_LIMIT
),
150 bus_space_read_1(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG1_STATUS
));
152 printf("%s: wdog2: count 0x%04x, limit 0x%04x, status 0x%02x\n",
153 device_xname(&sc
->sc_dev
),
154 bus_space_read_2(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG2_COUNTER
),
155 bus_space_read_2(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG2_LIMIT
),
156 bus_space_read_1(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG2_STATUS
));
158 printf("%s: wdog3: count 0x%04x, limit 0x%04x, status 0x%02x\n",
159 device_xname(&sc
->sc_dev
),
160 bus_space_read_2(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG3_COUNTER
),
161 bus_space_read_2(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG3_LIMIT
),
162 bus_space_read_1(sc
->sc_btag
, sc
->sc_bh
, PLD_WDOG3_STATUS
));
167 pldwdog_attach(struct device
*parent
, struct device
*self
, void *aux
)
169 struct pldwdog_softc
*sc
= (struct pldwdog_softc
*)self
;
170 struct ebus_attach_args
*ea
= aux
;
174 sc
->sc_btag
= ea
->ea_bustag
;
176 if (ea
->ea_nreg
< 1) {
177 printf(": no registers??\n");
182 sparc_promaddr_to_handle(sc
->sc_btag
, ea
->ea_vaddr
[0], &sc
->sc_bh
);
183 else if (bus_space_map(sc
->sc_btag
, EBUS_ADDR_FROM_REG(&ea
->ea_reg
[0]),
184 ea
->ea_reg
[0].size
, 0, &sc
->sc_bh
) != 0) {
185 printf(": can't map register space\n");
189 sc
->sc_wdog_period
= PLD_WDOG_PERIOD_DEFAULT
;
191 sc
->sc_smw
.smw_name
= device_xname(&sc
->sc_dev
);
192 sc
->sc_smw
.smw_cookie
= sc
;
193 sc
->sc_smw
.smw_setmode
= pldwdog_setmode
;
194 sc
->sc_smw
.smw_tickle
= pldwdog_tickle
;
195 sc
->sc_smw
.smw_period
= sc
->sc_wdog_period
;
197 if (sysmon_wdog_register(&sc
->sc_smw
) != 0)
198 aprint_error_dev(&sc
->sc_dev
, "unable to register with sysmon\n");
200 /* pldwdog_regs(sc); */
203 bus_intr_establish(ea
->ea_bustag
, ea
->ea_intr
[0],
204 IPL_TTY
, pldwdog_intr
, sc
);