xref: /netbsd/sys/dev/isa/itesio_isa.c (revision 6550d01e)
1 /*	$NetBSD: itesio_isa.c,v 1.21 2010/08/13 19:28:26 jakllsch Exp $ */
2 /*	Derived from $OpenBSD: it.c,v 1.19 2006/04/10 00:57:54 deraadt Exp $	*/
3 
4 /*
5  * Copyright (c) 2006-2007 Juan Romero Pardines <xtraeme@netbsd.org>
6  * Copyright (c) 2003 Julien Bordet <zejames@greyhats.org>
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
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  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITD TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITD TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /*
31  * Driver for the iTE IT87xxF Super I/O. Currently supporting
32  * the Environmental Controller to monitor the sensors and the
33  * Watchdog Timer.
34  */
35 
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: itesio_isa.c,v 1.21 2010/08/13 19:28:26 jakllsch Exp $");
38 
39 #include <sys/param.h>
40 #include <sys/kernel.h>
41 #include <sys/device.h>
42 
43 #include <sys/bus.h>
44 
45 #include <dev/isa/isareg.h>
46 #include <dev/isa/isavar.h>
47 
48 #include <dev/sysmon/sysmonvar.h>
49 
50 #include <dev/isa/itesio_isavar.h>
51 
52 #define IT_VOLTSTART_IDX 	3 	/* voltage start index */
53 #define IT_FANSTART_IDX 	12 	/* fan start index */
54 
55 #if defined(ITESIO_DEBUG)
56 #define DPRINTF(x)		do { printf x; } while (0)
57 #else
58 #define DPRINTF(x)
59 #endif
60 
61 /*
62  * IT87-compatible chips can typically measure voltages up to 4.096 V.
63  * To measure higher voltages the input is attenuated with (external)
64  * resistors.  Negative voltages are measured using a reference
65  * voltage.  So we have to convert the sensor values back to real
66  * voltages by applying the appropriate resistor factor.
67  */
68 #define RFACT_NONE	10000
69 #define RFACT(x, y)	(RFACT_NONE * ((x) + (y)) / (y))
70 
71 /* autoconf(9) functions */
72 static int	itesio_isa_match(device_t, cfdata_t, void *);
73 static void	itesio_isa_attach(device_t, device_t, void *);
74 static int	itesio_isa_detach(device_t, int);
75 
76 CFATTACH_DECL_NEW(itesio, sizeof(struct itesio_softc),
77     itesio_isa_match, itesio_isa_attach, itesio_isa_detach, NULL);
78 
79 /* driver functions */
80 static uint8_t	itesio_ecreadreg(struct itesio_softc *, int);
81 static void	itesio_ecwritereg(struct itesio_softc *, int, int);
82 static uint8_t	itesio_readreg(bus_space_tag_t, bus_space_handle_t, int);
83 static void	itesio_writereg(bus_space_tag_t, bus_space_handle_t, int, int);
84 static void	itesio_enter(bus_space_tag_t, bus_space_handle_t);
85 static void	itesio_exit(bus_space_tag_t, bus_space_handle_t);
86 
87 /* sysmon_envsys(9) glue */
88 static void	itesio_setup_sensors(struct itesio_softc *);
89 static void	itesio_refresh_temp(struct itesio_softc *, envsys_data_t *);
90 static void	itesio_refresh_volts(struct itesio_softc *, envsys_data_t *);
91 static void	itesio_refresh_fans(struct itesio_softc *, envsys_data_t *);
92 static void	itesio_refresh(struct sysmon_envsys *, envsys_data_t *);
93 
94 /* sysmon_wdog glue */
95 static bool	itesio_wdt_suspend(device_t, const pmf_qual_t *);
96 static int	itesio_wdt_setmode(struct sysmon_wdog *);
97 static int 	itesio_wdt_tickle(struct sysmon_wdog *);
98 
99 /* rfact values for voltage sensors */
100 static const int itesio_vrfact[] = {
101 	RFACT_NONE,	/* VCORE_A	*/
102 	RFACT_NONE,	/* VCORE_B	*/
103 	RFACT_NONE,	/* +3.3V	*/
104 	RFACT(68, 100),	/* +5V 		*/
105 	RFACT(30, 10),	/* +12V 	*/
106 	RFACT(21, 10),	/* -5V 		*/
107 	RFACT(83, 20),	/* -12V 	*/
108 	RFACT(68, 100),	/* STANDBY	*/
109 	RFACT_NONE	/* VBAT		*/
110 };
111 
112 static int
113 itesio_isa_match(device_t parent, cfdata_t match, void *aux)
114 {
115 	struct isa_attach_args *ia = aux;
116 	bus_space_handle_t ioh;
117 	uint16_t cr;
118 
119 	/* Must supply an address */
120 	if (ia->ia_nio < 1)
121 		return 0;
122 
123 	if (ISA_DIRECT_CONFIG(ia))
124 		return 0;
125 
126 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
127 		return 0;
128 
129 	if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 2, 0, &ioh))
130 		return 0;
131 
132 	itesio_enter(ia->ia_iot, ioh);
133 	cr = (itesio_readreg(ia->ia_iot, ioh, ITESIO_CHIPID1) << 8);
134 	cr |= itesio_readreg(ia->ia_iot, ioh, ITESIO_CHIPID2);
135 	itesio_exit(ia->ia_iot, ioh);
136 	bus_space_unmap(ia->ia_iot, ioh, 2);
137 
138 	switch (cr) {
139 	case ITESIO_ID8705:
140 	case ITESIO_ID8712:
141 	case ITESIO_ID8716:
142 	case ITESIO_ID8718:
143 	case ITESIO_ID8721:
144 	case ITESIO_ID8726:
145 		ia->ia_nio = 1;
146 		ia->ia_io[0].ir_size = 2;
147 		ia->ia_niomem = 0;
148 		ia->ia_nirq = 0;
149 		ia->ia_ndrq = 0;
150 		return 1;
151 	default:
152 		return 0;
153 	}
154 }
155 
156 static void
157 itesio_isa_attach(device_t parent, device_t self, void *aux)
158 {
159 	struct itesio_softc *sc = device_private(self);
160 	struct isa_attach_args *ia = aux;
161 	int i;
162 	uint8_t cr;
163 
164 	sc->sc_iot = ia->ia_iot;
165 
166 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, 2, 0,
167 			  &sc->sc_pnp_ioh)) {
168 		aprint_error(": can't map pnp i/o space\n");
169 		return;
170 	}
171 
172 	aprint_naive("\n");
173 
174 	/*
175 	 * Enter to the Super I/O MB PNP mode.
176 	 */
177 	itesio_enter(sc->sc_iot, sc->sc_pnp_ioh);
178 	/*
179 	 * Get info from the Super I/O Global Configuration Registers:
180 	 * Chip IDs and Device Revision.
181 	 */
182 	sc->sc_chipid = (itesio_readreg(sc->sc_iot, sc->sc_pnp_ioh,
183 	    ITESIO_CHIPID1) << 8);
184 	sc->sc_chipid |= itesio_readreg(sc->sc_iot, sc->sc_pnp_ioh,
185 	    ITESIO_CHIPID2);
186 	sc->sc_devrev = (itesio_readreg(sc->sc_iot, sc->sc_pnp_ioh,
187 	    ITESIO_DEVREV) & 0x0f);
188 	/*
189 	 * Select the EC LDN to get the Base Address.
190 	 */
191 	itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_LDNSEL,
192 	    ITESIO_EC_LDN);
193 	sc->sc_hwmon_baseaddr =
194 	    (itesio_readreg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_EC_MSB) << 8);
195 	sc->sc_hwmon_baseaddr |= itesio_readreg(sc->sc_iot, sc->sc_pnp_ioh,
196 	    ITESIO_EC_LSB);
197 	/*
198 	 * We are done, exit MB PNP mode.
199 	 */
200 	itesio_exit(sc->sc_iot, sc->sc_pnp_ioh);
201 
202 	aprint_normal(": iTE IT%4xF Super I/O (rev %d)\n",
203 	    sc->sc_chipid, sc->sc_devrev);
204 	aprint_normal_dev(self, "Hardware Monitor registers at 0x%x\n",
205 	    sc->sc_hwmon_baseaddr);
206 
207 	if (bus_space_map(sc->sc_iot, sc->sc_hwmon_baseaddr, 8, 0,
208 	    &sc->sc_ec_ioh)) {
209 		aprint_error_dev(self, "cannot map hwmon i/o space\n");
210 		goto out2;
211 	}
212 
213 	sc->sc_hwmon_mapped = true;
214 
215 	/* Activate monitoring */
216 	cr = itesio_ecreadreg(sc, ITESIO_EC_CONFIG);
217 	SET(cr, 0x01);
218 	itesio_ecwritereg(sc, ITESIO_EC_CONFIG, cr);
219 
220 #ifdef notyet
221 	/* Enable beep alarms */
222 	cr = itesio_ecreadreg(sc, ITESIO_EC_BEEPEER);
223 	SET(cr, 0x02);	/* Voltage exceeds limit */
224 	SET(cr, 0x04);	/* Temperature exceeds limit */
225 	itesio_ecwritereg(sc, ITESIO_EC_BEEPEER, cr);
226 #endif
227 
228 	/*
229 	 * Initialize and attach sensors.
230 	 */
231 	itesio_setup_sensors(sc);
232 	sc->sc_sme = sysmon_envsys_create();
233 	for (i = 0; i < IT_NUM_SENSORS; i++) {
234 		if (sysmon_envsys_sensor_attach(sc->sc_sme,
235 						&sc->sc_sensor[i])) {
236 			sysmon_envsys_destroy(sc->sc_sme);
237 			goto out;
238 		}
239 	}
240 	/*
241 	 * Hook into the system monitor.
242 	 */
243 	sc->sc_sme->sme_name = device_xname(self);
244 	sc->sc_sme->sme_cookie = sc;
245 	sc->sc_sme->sme_refresh = itesio_refresh;
246 
247 	if ((i = sysmon_envsys_register(sc->sc_sme))) {
248 		aprint_error_dev(self,
249 		    "unable to register with sysmon (%d)\n", i);
250 		sysmon_envsys_destroy(sc->sc_sme);
251 		goto out;
252 	}
253 	sc->sc_hwmon_enabled = true;
254 
255 	if (!pmf_device_register(self, NULL, NULL))
256 		aprint_error_dev(self, "couldn't establish power handler\n");
257 
258 	/* The IT8705 doesn't support the WDT */
259 	if (sc->sc_chipid == ITESIO_ID8705)
260 		goto out2;
261 
262 	/*
263 	 * Initialize the watchdog timer.
264 	 */
265 	sc->sc_smw.smw_name = device_xname(self);
266 	sc->sc_smw.smw_cookie = sc;
267 	sc->sc_smw.smw_setmode = itesio_wdt_setmode;
268 	sc->sc_smw.smw_tickle = itesio_wdt_tickle;
269 	sc->sc_smw.smw_period = 60;
270 
271 	if (sysmon_wdog_register(&sc->sc_smw)) {
272 		aprint_error_dev(self, "unable to register watchdog timer\n");
273 		goto out2;
274 	}
275 	sc->sc_wdt_enabled = true;
276 	aprint_normal_dev(self, "Watchdog Timer present\n");
277 
278 	pmf_device_deregister(self);
279 	if (!pmf_device_register(self, itesio_wdt_suspend, NULL))
280 		aprint_error_dev(self, "couldn't establish power handler\n");
281 
282 	return;
283 
284 out:
285 	bus_space_unmap(sc->sc_iot, sc->sc_ec_ioh, 8);
286 out2:
287 	bus_space_unmap(sc->sc_iot, sc->sc_pnp_ioh, 2);
288 }
289 
290 static int
291 itesio_isa_detach(device_t self, int flags)
292 {
293 	struct itesio_softc *sc = device_private(self);
294 
295 	if (sc->sc_hwmon_enabled)
296 		sysmon_envsys_unregister(sc->sc_sme);
297 	if (sc->sc_hwmon_mapped)
298 		bus_space_unmap(sc->sc_iot, sc->sc_ec_ioh, 8);
299 	if (sc->sc_wdt_enabled) {
300 		sysmon_wdog_unregister(&sc->sc_smw);
301 		bus_space_unmap(sc->sc_iot, sc->sc_pnp_ioh, 2);
302 	}
303 
304 	return 0;
305 }
306 
307 static bool
308 itesio_wdt_suspend(device_t dev, const pmf_qual_t *qual)
309 {
310 	struct itesio_softc *sc = device_private(dev);
311 
312 	/* Don't allow suspend if watchdog is armed */
313 	if ((sc->sc_smw.smw_mode & WDOG_MODE_MASK) != WDOG_MODE_DISARMED)
314 		return false;
315 	return true;
316 }
317 
318 /*
319  * Functions to read/write to the Environmental Controller.
320  */
321 static uint8_t
322 itesio_ecreadreg(struct itesio_softc *sc, int reg)
323 {
324 	bus_space_write_1(sc->sc_iot, sc->sc_ec_ioh, ITESIO_EC_ADDR, reg);
325 	return bus_space_read_1(sc->sc_iot, sc->sc_ec_ioh, ITESIO_EC_DATA);
326 }
327 
328 static void
329 itesio_ecwritereg(struct itesio_softc *sc, int reg, int val)
330 {
331 	bus_space_write_1(sc->sc_iot, sc->sc_ec_ioh, ITESIO_EC_ADDR, reg);
332 	bus_space_write_1(sc->sc_iot, sc->sc_ec_ioh, ITESIO_EC_DATA, val);
333 }
334 
335 /*
336  * Functions to enter/exit/read/write to the Super I/O.
337  */
338 static uint8_t
339 itesio_readreg(bus_space_tag_t iot, bus_space_handle_t ioh, int reg)
340 {
341 	bus_space_write_1(iot, ioh, ITESIO_ADDR, reg);
342 	return bus_space_read_1(iot, ioh, ITESIO_DATA);
343 }
344 
345 static void
346 itesio_writereg(bus_space_tag_t iot, bus_space_handle_t ioh, int reg, int val)
347 {
348 	bus_space_write_1(iot, ioh, ITESIO_ADDR, reg);
349 	bus_space_write_1(iot, ioh, ITESIO_DATA, val);
350 }
351 
352 static void
353 itesio_enter(bus_space_tag_t iot, bus_space_handle_t ioh)
354 {
355 	bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x87);
356 	bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x01);
357 	bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x55);
358 	bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x55);
359 }
360 
361 static void
362 itesio_exit(bus_space_tag_t iot, bus_space_handle_t ioh)
363 {
364 	bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x02);
365 	bus_space_write_1(iot, ioh, ITESIO_DATA, 0x02);
366 }
367 
368 
369 #define COPYDESCR(x, y)				\
370 	do {					\
371 		strlcpy((x), (y), sizeof(x));	\
372 	} while (0)
373 /*
374  * sysmon_envsys(9) glue.
375  */
376 static void
377 itesio_setup_sensors(struct itesio_softc *sc)
378 {
379 	int i;
380 
381 	/* temperatures */
382 	for (i = 0; i < IT_VOLTSTART_IDX; i++)
383 		sc->sc_sensor[i].units = ENVSYS_STEMP;
384 
385 	COPYDESCR(sc->sc_sensor[0].desc, "CPU Temp");
386 	COPYDESCR(sc->sc_sensor[1].desc, "System Temp");
387 	COPYDESCR(sc->sc_sensor[2].desc, "Aux Temp");
388 
389 	/* voltages */
390 	for (i = IT_VOLTSTART_IDX; i < IT_FANSTART_IDX; i++) {
391 		sc->sc_sensor[i].units = ENVSYS_SVOLTS_DC;
392 		sc->sc_sensor[i].flags = ENVSYS_FCHANGERFACT;
393 	}
394 
395 	COPYDESCR(sc->sc_sensor[3].desc, "VCORE_A");
396 	COPYDESCR(sc->sc_sensor[4].desc, "VCORE_B");
397 	COPYDESCR(sc->sc_sensor[5].desc, "+3.3V");
398 	COPYDESCR(sc->sc_sensor[6].desc, "+5V");
399 	COPYDESCR(sc->sc_sensor[7].desc, "+12V");
400 	COPYDESCR(sc->sc_sensor[8].desc, "-5V");
401 	COPYDESCR(sc->sc_sensor[9].desc, "-12V");
402 	COPYDESCR(sc->sc_sensor[10].desc, "STANDBY");
403 	COPYDESCR(sc->sc_sensor[11].desc, "VBAT");
404 
405 	/* fans */
406 	for (i = IT_FANSTART_IDX; i < IT_NUM_SENSORS; i++)
407 		sc->sc_sensor[i].units = ENVSYS_SFANRPM;
408 
409 	COPYDESCR(sc->sc_sensor[12].desc, "CPU Fan");
410 	COPYDESCR(sc->sc_sensor[13].desc, "System Fan");
411 	COPYDESCR(sc->sc_sensor[14].desc, "Aux Fan");
412 }
413 #undef COPYDESCR
414 
415 static void
416 itesio_refresh_temp(struct itesio_softc *sc, envsys_data_t *edata)
417 {
418 	int sdata;
419 
420 	sdata = itesio_ecreadreg(sc, ITESIO_EC_SENSORTEMPBASE + edata->sensor);
421 	/* sensor is not connected or reporting invalid data */
422 	if (sdata == 0 || sdata >= 0xfa) {
423 		edata->state = ENVSYS_SINVALID;
424 		return;
425 	}
426 
427 	DPRINTF(("%s: sdata[temp%d] 0x%x\n", __func__, edata->sensor, sdata));
428 	/* Convert temperature to uK */
429 	edata->value_cur = sdata * 1000000 + 273150000;
430 	edata->state = ENVSYS_SVALID;
431 }
432 
433 static void
434 itesio_refresh_volts(struct itesio_softc *sc, envsys_data_t *edata)
435 {
436 	uint8_t vbatcr = 0;
437 	int i, sdata;
438 
439 	i = edata->sensor - IT_VOLTSTART_IDX;
440 
441 	sdata = itesio_ecreadreg(sc, ITESIO_EC_SENSORVOLTBASE + i);
442 	/* not connected */
443 	if (sdata == 0 || sdata == 0xff) {
444 		edata->state = ENVSYS_SINVALID;
445 		return;
446 	}
447 
448 	/*
449 	 * update VBAT voltage reading every time we read it, to get
450 	 * latest value.
451 	 */
452 	if (i == 8) {
453 		vbatcr = itesio_ecreadreg(sc, ITESIO_EC_CONFIG);
454 		SET(vbatcr, ITESIO_EC_UPDATEVBAT);
455 		itesio_ecwritereg(sc, ITESIO_EC_CONFIG, vbatcr);
456 	}
457 
458 	DPRINTF(("%s: sdata[volt%d] 0x%x\n", __func__, i, sdata));
459 
460 	/* voltage returned as (mV << 4) */
461 	edata->value_cur = (sdata << 4);
462 	/* negative values */
463 	if (i == 5 || i == 6)
464 		edata->value_cur -= ITESIO_EC_VREF;
465 	/* rfact is (factor * 10^4) */
466 	if (edata->rfact)
467 		edata->value_cur *= edata->rfact;
468 	else
469 		edata->value_cur *= itesio_vrfact[i];
470 	/* division by 10 gets us back to uVDC */
471 	edata->value_cur /= 10;
472 	if (i == 5 || i == 6)
473 		edata->value_cur += ITESIO_EC_VREF * 1000;
474 
475 	edata->state = ENVSYS_SVALID;
476 }
477 
478 static void
479 itesio_refresh_fans(struct itesio_softc *sc, envsys_data_t *edata)
480 {
481 	uint8_t mode = 0;
482 	uint16_t sdata = 0;
483 	int i, divisor, odivisor, ndivisor;
484 
485 	i = edata->sensor - IT_FANSTART_IDX;
486 	divisor = odivisor = ndivisor = 0;
487 
488 	if (sc->sc_chipid == ITESIO_ID8705 || sc->sc_chipid == ITESIO_ID8712) {
489 		/*
490 		 * Use the Fan Tachometer Divisor Register for
491 		 * IT8705F and IT8712F.
492 		 */
493 		divisor = odivisor = ndivisor =
494 		    itesio_ecreadreg(sc, ITESIO_EC_FAN_TDR);
495 		sdata = itesio_ecreadreg(sc, ITESIO_EC_SENSORFANBASE + i);
496 		if (sdata == 0xff) {
497 			edata->state = ENVSYS_SINVALID;
498 			if (i == 2)
499 				ndivisor |= 0x40;
500 			else {
501 				ndivisor &= ~(7 << (i * 3));
502 				ndivisor |= ((divisor + 1) & 7) << (i * 3);
503 			}
504 		} else {
505 			if (i == 2)
506 				divisor = divisor & 1 ? 3 : 1;
507 
508 			if ((sdata << (divisor & 7)) == 0)
509 				edata->state = ENVSYS_SINVALID;
510 			else {
511 				edata->value_cur =
512 				    1350000 / (sdata << (divisor & 7));
513 				edata->state = ENVSYS_SVALID;
514 			}
515 		}
516 		DPRINTF(("%s: 8bit sdata[fan%d] 0x%x div: 0x%x\n", __func__,
517 		    i, sdata, divisor));
518 		if (ndivisor != odivisor)
519 			itesio_ecwritereg(sc, ITESIO_EC_FAN_TDR, ndivisor);
520 	} else {
521 		mode = itesio_ecreadreg(sc, ITESIO_EC_FAN16_CER);
522 		sdata = itesio_ecreadreg(sc, ITESIO_EC_SENSORFANBASE + i);
523 		if (mode & (1 << i))
524 			sdata += (itesio_ecreadreg(sc,
525 			    ITESIO_EC_SENSORFANEXTBASE + i) << 8);
526 		edata->state = ENVSYS_SVALID;
527 		if (sdata == 0 ||
528 		    sdata == ((mode & (1 << i)) ? 0xffff : 0xff))
529 			edata->state = ENVSYS_SINVALID;
530 		else {
531 			edata->value_cur = 1350000 / 2 / sdata;
532 			edata->state = ENVSYS_SVALID;
533 		}
534 		DPRINTF(("%s: 16bit sdata[fan%d] 0x%x\n", __func__, i, sdata));
535 	}
536 }
537 
538 static void
539 itesio_refresh(struct sysmon_envsys *sme, struct envsys_data *edata)
540 {
541 	struct itesio_softc *sc = sme->sme_cookie;
542 
543 	if (edata->sensor < IT_VOLTSTART_IDX)
544 		itesio_refresh_temp(sc, edata);
545 	else if (edata->sensor >= IT_VOLTSTART_IDX &&
546 	         edata->sensor < IT_FANSTART_IDX)
547 		itesio_refresh_volts(sc, edata);
548 	else
549 		itesio_refresh_fans(sc, edata);
550 }
551 
552 static int
553 itesio_wdt_setmode(struct sysmon_wdog *smw)
554 {
555 	struct itesio_softc *sc = smw->smw_cookie;
556 	int period = smw->smw_period;
557 
558 	/* Enter MB PNP mode and select the WDT LDN */
559 	itesio_enter(sc->sc_iot, sc->sc_pnp_ioh);
560 	itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_LDNSEL,
561 	    ITESIO_WDT_LDN);
562 
563 	if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
564 		/* Disable the watchdog */
565 		itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_CTL, 0);
566 		itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_CNF, 0);
567 		itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_TMO_MSB, 0);
568 		itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_TMO_LSB, 0);
569 	} else {
570 		/* Enable the watchdog */
571 		if (period > ITESIO_WDT_MAXTIMO || period < 1)
572 			period = smw->smw_period = ITESIO_WDT_MAXTIMO;
573 
574 		period *= 2;
575 
576 		/* set the timeout and start the watchdog */
577 		itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_TMO_MSB,
578 		    period >> 8);
579 		itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_TMO_LSB,
580 		    period & 0xff);
581 		itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_CNF,
582 		    ITESIO_WDT_CNF_SECS | ITESIO_WDT_CNF_KRST |
583 		    ITESIO_WDT_CNF_PWROK);
584 	}
585 	/* we are done, exit MB PNP mode */
586 	itesio_exit(sc->sc_iot, sc->sc_pnp_ioh);
587 
588 	return 0;
589 }
590 
591 static int
592 itesio_wdt_tickle(struct sysmon_wdog *smw)
593 {
594 	struct itesio_softc *sc = smw->smw_cookie;
595 	int period = smw->smw_period * 2;
596 
597 	/* refresh timeout value and exit */
598 	itesio_enter(sc->sc_iot, sc->sc_pnp_ioh);
599 	itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_LDNSEL,
600 	    ITESIO_WDT_LDN);
601 	itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_TMO_MSB,
602 	    period >> 8);
603 	itesio_writereg(sc->sc_iot, sc->sc_pnp_ioh, ITESIO_WDT_TMO_LSB,
604 	    period & 0xff);
605 	itesio_exit(sc->sc_iot, sc->sc_pnp_ioh);
606 
607 	return 0;
608 }
609