1 /* $NetBSD: weasel_isa.c,v 1.4 2007/10/19 12:00:24 ad Exp $ */
4 * Copyright (c) 2000 Zembu Labs, Inc.
7 * Author: Jason R. Thorpe <thorpej@zembu.com>
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 by Zembu Labs, Inc.
20 * 4. Neither the name of Zembu Labs nor the names of its employees may
21 * be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY ZEMBU LABS, INC. ``AS IS'' AND ANY EXPRESS
25 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAR-
26 * RANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DIS-
27 * CLAIMED. IN NO EVENT SHALL ZEMBU LABS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Device driver for the Middle Digital, Inc. PC-Weasel serial
40 * We're glued into the MDA display driver (`pcdisplay'), and
41 * handle things like the watchdog timer.
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: weasel_isa.c,v 1.4 2007/10/19 12:00:24 ad Exp $");
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/device.h>
54 #include <dev/isa/weaselreg.h>
55 #include <dev/isa/weaselvar.h>
57 #include <dev/sysmon/sysmonvar.h>
59 int weasel_isa_wdog_setmode(struct sysmon_wdog
*);
60 int weasel_isa_wdog_tickle(struct sysmon_wdog
*);
61 int weasel_isa_wdog_arm_disarm(struct weasel_handle
*, u_int8_t
);
62 int weasel_isa_wdog_query_state(struct weasel_handle
*);
65 void pcweaselattach(int);
69 pcweaselattach(int count
)
72 /* Nothing to do; pseudo-device glue. */
76 weasel_isa_init(struct weasel_handle
*wh
)
78 struct weasel_config_block cfg
;
81 const char *vers
, *mode
;
84 * Write a NOP to the command register and see if it
85 * reverts back to READY within 1.5 seconds.
87 bus_space_write_1(wh
->wh_st
, wh
->wh_sh
, WEASEL_MISC_COMMAND
, OS_NOP
);
88 for (i
= 0; i
< 1500; i
++) {
90 sum
= bus_space_read_1(wh
->wh_st
, wh
->wh_sh
,
95 if (sum
!= OS_READY
) {
96 /* This is not a Weasel. */
101 * It can take a while for the config block to be copied
102 * into the offscreen area, as the Weasel may be busy
103 * sending data to the terminal. Wait up to 3 seconds,
104 * reading the block each time, and breaking out of the
105 * loop once the checksum passes.
108 bus_space_write_1(wh
->wh_st
, wh
->wh_sh
, WEASEL_MISC_COMMAND
,
111 /* ...one second to get it started... */
114 /* ...two seconds to let it finish... */
115 for (i
= 0; i
< 2000; i
++) {
117 bus_space_read_region_1(wh
->wh_st
, wh
->wh_sh
,
118 WEASEL_CONFIG_BLOCK
, &cfg
, sizeof(cfg
));
120 * Compute the checksum of the config block.
122 for (cp
= (u_int8_t
*)&cfg
, j
= 0, sum
= 1;
123 j
< (sizeof(cfg
) - 1); j
++)
125 if (sum
== cfg
.cksum
)
129 if (sum
!= cfg
.cksum
) {
131 * Checksum doesn't match; either it's not a Weasel,
132 * or something is wrong with it.
134 printf("%s: PC-Weasel config block checksum mismatch "
135 "0x%02x != 0x%02x\n", device_xname(wh
->wh_parent
),
140 switch (cfg
.cfg_version
) {
141 case CFG_VERSION_1_0
:
143 switch (cfg
.enable_duart_switching
) {
157 case CFG_VERSION_1_1
:
159 switch (cfg
.enable_duart_switching
) {
181 printf("%s: PC-Weasel, ", device_xname(wh
->wh_parent
));
183 printf("version %s, %s mode", vers
, mode
);
185 printf("unknown version 0x%x", cfg
.cfg_version
);
188 printf("%s: break passthrough %s", device_xname(wh
->wh_parent
),
189 cfg
.break_passthru
? "enabled" : "disabled");
190 if (cfg
.wdt_msec
== 0) {
192 * Old firmware -- these Weasels have
193 * a 3000ms watchdog period.
198 if ((wh
->wh_wdog_armed
= weasel_isa_wdog_query_state(wh
)) == -1)
199 wh
->wh_wdog_armed
= 0;
200 wh
->wh_wdog_period
= cfg
.wdt_msec
/ 1000;
202 printf(", watchdog interval %d sec.\n", wh
->wh_wdog_period
);
205 * Always register the Weasel watchdog timer in case user decides
206 * to set 'allow watchdog' to 'YES' after the machine has booted.
208 wh
->wh_smw
.smw_name
= "weasel";
209 wh
->wh_smw
.smw_cookie
= wh
;
210 wh
->wh_smw
.smw_setmode
= weasel_isa_wdog_setmode
;
211 wh
->wh_smw
.smw_tickle
= weasel_isa_wdog_tickle
;
212 wh
->wh_smw
.smw_period
= wh
->wh_wdog_period
;
214 if (sysmon_wdog_register(&wh
->wh_smw
) != 0)
215 aprint_error_dev(wh
->wh_parent
, "unable to register PC-Weasel watchdog "
220 weasel_isa_wdog_setmode(struct sysmon_wdog
*smw
)
222 struct weasel_handle
*wh
= smw
->smw_cookie
;
225 if ((smw
->smw_mode
& WDOG_MODE_MASK
) == WDOG_MODE_DISARMED
) {
226 error
= weasel_isa_wdog_arm_disarm(wh
, WDT_DISABLE
);
228 if (smw
->smw_period
== WDOG_PERIOD_DEFAULT
)
229 smw
->smw_period
= wh
->wh_wdog_period
;
230 else if (smw
->smw_period
!= wh
->wh_wdog_period
) {
231 /* Can't change the period on the Weasel. */
234 error
= weasel_isa_wdog_arm_disarm(wh
, WDT_ENABLE
);
235 weasel_isa_wdog_tickle(smw
);
242 weasel_isa_wdog_tickle(struct sysmon_wdog
*smw
)
244 struct weasel_handle
*wh
= smw
->smw_cookie
;
252 * first we tickle the watchdog
254 reg
= bus_space_read_1(wh
->wh_st
, wh
->wh_sh
, WEASEL_WDT_TICKLE
);
255 bus_space_write_1(wh
->wh_st
, wh
->wh_sh
, WEASEL_WDT_TICKLE
, ~reg
);
258 * then we check to make sure the weasel is still armed. If someone
259 * has rebooted the weasel for whatever reason (firmware update),
260 * then the watchdog timer would no longer be armed and we'd be
261 * servicing nothing. Let the user know that the machine is no
262 * longer being monitored by the weasel.
264 if((x
= weasel_isa_wdog_query_state(wh
)) == -1)
269 aprint_error_dev(wh
->wh_parent
, "Watchdog timer disabled on PC/Weasel! Disarming wdog.\n");
270 wh
->wh_wdog_armed
= 0;
279 weasel_isa_wdog_arm_disarm(struct weasel_handle
*wh
, u_int8_t mode
)
288 bus_space_write_1(wh
->wh_st
, wh
->wh_sh
, WEASEL_WDT_SEMAPHORE
,
290 for (timeout
= 5000; timeout
; timeout
--) {
292 reg
= bus_space_read_1(wh
->wh_st
, wh
->wh_sh
,
293 WEASEL_WDT_SEMAPHORE
);
301 bus_space_write_1(wh
->wh_st
, wh
->wh_sh
, WEASEL_WDT_SEMAPHORE
, mode
);
302 for (timeout
= 500 ; timeout
; timeout
--) {
304 reg
= bus_space_read_1(wh
->wh_st
, wh
->wh_sh
,
305 WEASEL_WDT_SEMAPHORE
);
313 bus_space_write_1(wh
->wh_st
, wh
->wh_sh
, WEASEL_WDT_SEMAPHORE
, ~reg
);
314 for (timeout
= 500; timeout
; timeout
--) {
316 reg
= bus_space_read_1(wh
->wh_st
, wh
->wh_sh
,
317 WEASEL_WDT_SEMAPHORE
);
323 * Ensure that the Weasel thinks it's in the same mode we want it to
326 x
= weasel_isa_wdog_query_state(wh
);
332 if (mode
== WDT_DISABLE
) {
333 wh
->wh_wdog_armed
= 0;
339 if (mode
== WDT_ENABLE
) {
340 wh
->wh_wdog_armed
= 1;
352 weasel_isa_wdog_query_state(struct weasel_handle
*wh
)
356 bus_space_write_1(wh
->wh_st
, wh
->wh_sh
,
357 WEASEL_MISC_COMMAND
, OS_WDT_QUERY
);
358 for (timeout
= 0; timeout
< 1500; timeout
++) {
360 reg
= bus_space_read_1(wh
->wh_st
, wh
->wh_sh
,
361 WEASEL_MISC_COMMAND
);
365 return(bus_space_read_1(wh
->wh_st
, wh
->wh_sh
, WEASEL_MISC_RESPONSE
));