Home | History | Annotate | Line # | Download | only in isa
itesio_isa.c revision 1.13
      1 /*	$NetBSD: itesio_isa.c,v 1.13 2008/03/04 11:31:16 xtraeme 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 (at) netbsd.org>
      6  * Copyright (c) 2003 Julien Bordet <zejames (at) 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.13 2008/03/04 11:31:16 xtraeme 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, struct cfdata *, 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 int	itesio_wdt_setmode(struct sysmon_wdog *);
     96 static int 	itesio_wdt_tickle(struct sysmon_wdog *);
     97 
     98 /* rfact values for voltage sensors */
     99 static const int itesio_vrfact[] = {
    100 	RFACT_NONE,	/* VCORE_A	*/
    101 	RFACT_NONE,	/* VCORE_B	*/
    102 	RFACT_NONE,	/* +3.3V	*/
    103 	RFACT(68, 100),	/* +5V 		*/
    104 	RFACT(30, 10),	/* +12V 	*/
    105 	RFACT(21, 10),	/* -12V 	*/
    106 	RFACT(83, 20),	/* -5V 		*/
    107 	RFACT(68, 100),	/* STANDBY	*/
    108 	RFACT_NONE	/* VBAT		*/
    109 };
    110 
    111 static int
    112 itesio_isa_match(device_t parent, struct cfdata *match, void *aux)
    113 {
    114 	struct isa_attach_args *ia = aux;
    115 	bus_space_handle_t ioh;
    116 	uint16_t cr;
    117 
    118 	/* Must supply an address */
    119 	if (ia->ia_nio < 1)
    120 		return 0;
    121 
    122 	if (ISA_DIRECT_CONFIG(ia))
    123 		return 0;
    124 
    125 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
    126 		return 0;
    127 
    128 	if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, 2, 0, &ioh))
    129 		return 0;
    130 
    131 	itesio_enter(ia->ia_iot, ioh);
    132 	cr = (itesio_readreg(ia->ia_iot, ioh, ITESIO_CHIPID1) << 8);
    133 	cr |= itesio_readreg(ia->ia_iot, ioh, ITESIO_CHIPID2);
    134 	itesio_exit(ia->ia_iot, ioh);
    135 	bus_space_unmap(ia->ia_iot, ioh, 2);
    136 
    137 	switch (cr) {
    138 	case ITESIO_ID8705:
    139 	case ITESIO_ID8712:
    140 	case ITESIO_ID8716:
    141 	case ITESIO_ID8718:
    142 		ia->ia_nio = 1;
    143 		ia->ia_io[0].ir_size = 2;
    144 		ia->ia_niomem = 0;
    145 		ia->ia_nirq = 0;
    146 		ia->ia_ndrq = 0;
    147 		return 1;
    148 	default:
    149 		return 0;
    150 	}
    151 }
    152 
    153 static void
    154 itesio_isa_attach(device_t parent, device_t self, void *aux)
    155 {
    156 	struct itesio_softc *sc = device_private(self);
    157 	struct isa_attach_args *ia = aux;
    158 	int i;
    159 	uint8_t cr;
    160 
    161 	sc->sc_iot = ia->ia_iot;
    162 
    163 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, 2, 0,
    164 			  &sc->sc_ioh)) {
    165 		aprint_error(": can't map i/o space\n");
    166 		return;
    167 	}
    168 
    169 	aprint_naive("\n");
    170 
    171 	/*
    172 	 * Enter to the Super I/O MB PNP mode.
    173 	 */
    174 	itesio_enter(sc->sc_iot, sc->sc_ioh);
    175 	/*
    176 	 * Get info from the Super I/O Global Configuration Registers:
    177 	 * Chip IDs and Device Revision.
    178 	 */
    179 	sc->sc_chipid = (itesio_readreg(sc->sc_iot, sc->sc_ioh,
    180 	    ITESIO_CHIPID1) << 8);
    181 	sc->sc_chipid |= itesio_readreg(sc->sc_iot, sc->sc_ioh,
    182 	    ITESIO_CHIPID2);
    183 	sc->sc_devrev = (itesio_readreg(sc->sc_iot, sc->sc_ioh,
    184 	    ITESIO_DEVREV) & 0x0f);
    185 	/*
    186 	 * Select the EC LDN to get the Base Address.
    187 	 */
    188 	itesio_writereg(sc->sc_iot, sc->sc_ioh, ITESIO_LDNSEL, ITESIO_EC_LDN);
    189 	sc->sc_hwmon_baseaddr =
    190 	    (itesio_readreg(sc->sc_iot, sc->sc_ioh, ITESIO_EC_MSB) << 8);
    191 	sc->sc_hwmon_baseaddr |= itesio_readreg(sc->sc_iot, sc->sc_ioh,
    192 	    ITESIO_EC_LSB);
    193 	/*
    194 	 * We are done, exit MB PNP mode.
    195 	 */
    196 	itesio_exit(sc->sc_iot, sc->sc_ioh);
    197 
    198 	aprint_normal(": iTE IT%4xF Super I/O (rev %d)\n",
    199 	    sc->sc_chipid, sc->sc_devrev);
    200 	aprint_normal_dev(self, "Hardware Monitor registers at 0x%x\n",
    201 	    sc->sc_hwmon_baseaddr);
    202 
    203 	if (bus_space_map(sc->sc_ec_iot, sc->sc_hwmon_baseaddr, 8, 0,
    204 	    &sc->sc_ec_ioh)) {
    205 		aprint_error_dev(self, "cannot map hwmon i/o space\n");
    206 		return;
    207 	}
    208 
    209 	sc->sc_hwmon_mapped = true;
    210 
    211 	/* Activate monitoring */
    212 	cr = itesio_ecreadreg(sc, ITESIO_EC_CONFIG);
    213 	SET(cr, 0x01);
    214 	itesio_ecwritereg(sc, ITESIO_EC_CONFIG, cr);
    215 
    216 #ifdef notyet
    217 	/* Enable beep alarms */
    218 	cr = itesio_ecreadreg(sc, ITESIO_EC_BEEPEER);
    219 	SET(cr, 0x02);	/* Voltage exceeds limit */
    220 	SET(cr, 0x04);	/* Temperature exceeds limit */
    221 	itesio_ecwritereg(sc, ITESIO_EC_BEEPEER, cr);
    222 #endif
    223 
    224 	/*
    225 	 * Initialize and attach sensors.
    226 	 */
    227 	itesio_setup_sensors(sc);
    228 	sc->sc_sme = sysmon_envsys_create();
    229 	for (i = 0; i < IT_NUM_SENSORS; i++) {
    230 		if (sysmon_envsys_sensor_attach(sc->sc_sme,
    231 						&sc->sc_sensor[i])) {
    232 			sysmon_envsys_destroy(sc->sc_sme);
    233 			return;
    234 		}
    235 	}
    236 	/*
    237 	 * Hook into the system monitor.
    238 	 */
    239 	sc->sc_sme->sme_name = device_xname(self);
    240 	sc->sc_sme->sme_cookie = sc;
    241 	sc->sc_sme->sme_refresh = itesio_refresh;
    242 
    243 	if ((i = sysmon_envsys_register(sc->sc_sme))) {
    244 		aprint_error_dev(self,
    245 		    "unable to register with sysmon (%d)\n", i);
    246 		sysmon_envsys_destroy(sc->sc_sme);
    247 		bus_space_unmap(sc->sc_ec_iot, sc->sc_ec_ioh, 8);
    248 		return;
    249 	}
    250 	sc->sc_hwmon_enabled = true;
    251 
    252 	if (!pmf_device_register(self, NULL, NULL))
    253 		aprint_error_dev(self, "couldn't establish power handler\n");
    254 
    255 	/* The IT8705 doesn't support a WDT */
    256 	if (sc->sc_chipid == ITESIO_ID8705) {
    257 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, 2);
    258 		return;
    259 	}
    260 
    261 	/*
    262 	 * Initialize the watchdog timer.
    263 	 */
    264 	sc->sc_smw.smw_name = device_xname(self);
    265 	sc->sc_smw.smw_cookie = sc;
    266 	sc->sc_smw.smw_setmode = itesio_wdt_setmode;
    267 	sc->sc_smw.smw_tickle = itesio_wdt_tickle;
    268 	sc->sc_smw.smw_period = 60;
    269 
    270 	if (sysmon_wdog_register(&sc->sc_smw)) {
    271 		aprint_error_dev(self, "unable to register watchdog timer\n");
    272 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, 2);
    273 		return;
    274 	}
    275 	sc->sc_wdt_enabled = true;
    276 	aprint_normal_dev(self, "Watchdog Timer present\n");
    277 }
    278 
    279 static int
    280 itesio_isa_detach(device_t self, int flags)
    281 {
    282 	struct itesio_softc *sc = device_private(self);
    283 
    284 	if (sc->sc_hwmon_enabled)
    285 		sysmon_envsys_unregister(sc->sc_sme);
    286 	if (sc->sc_hwmon_mapped)
    287 		bus_space_unmap(sc->sc_ec_iot, sc->sc_ec_ioh, 8);
    288 	if (sc->sc_wdt_enabled) {
    289 		sysmon_wdog_unregister(&sc->sc_smw);
    290 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, 2);
    291 	}
    292 
    293 	return 0;
    294 }
    295 
    296 /*
    297  * Functions to read/write to the Environmental Controller.
    298  */
    299 static uint8_t
    300 itesio_ecreadreg(struct itesio_softc *sc, int reg)
    301 {
    302 	bus_space_write_1(sc->sc_ec_iot, sc->sc_ec_ioh, ITESIO_EC_ADDR, reg);
    303 	return bus_space_read_1(sc->sc_ec_iot, sc->sc_ec_ioh, ITESIO_EC_DATA);
    304 }
    305 
    306 static void
    307 itesio_ecwritereg(struct itesio_softc *sc, int reg, int val)
    308 {
    309 	bus_space_write_1(sc->sc_ec_iot, sc->sc_ec_ioh, ITESIO_EC_ADDR, reg);
    310 	bus_space_write_1(sc->sc_ec_iot, sc->sc_ec_ioh, ITESIO_EC_DATA, val);
    311 }
    312 
    313 /*
    314  * Functions to enter/exit/read/write to the Super I/O.
    315  */
    316 static uint8_t
    317 itesio_readreg(bus_space_tag_t iot, bus_space_handle_t ioh, int reg)
    318 {
    319 	bus_space_write_1(iot, ioh, ITESIO_ADDR, reg);
    320 	return bus_space_read_1(iot, ioh, ITESIO_DATA);
    321 }
    322 
    323 static void
    324 itesio_writereg(bus_space_tag_t iot, bus_space_handle_t ioh, int reg, int val)
    325 {
    326 	bus_space_write_1(iot, ioh, ITESIO_ADDR, reg);
    327 	bus_space_write_1(iot, ioh, ITESIO_DATA, val);
    328 }
    329 
    330 static void
    331 itesio_enter(bus_space_tag_t iot, bus_space_handle_t ioh)
    332 {
    333 	bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x87);
    334 	bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x01);
    335 	bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x55);
    336 	bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x55);
    337 }
    338 
    339 static void
    340 itesio_exit(bus_space_tag_t iot, bus_space_handle_t ioh)
    341 {
    342 	bus_space_write_1(iot, ioh, ITESIO_ADDR, 0x02);
    343 	bus_space_write_1(iot, ioh, ITESIO_DATA, 0x02);
    344 }
    345 
    346 
    347 #define COPYDESCR(x, y)				\
    348 	do {					\
    349 		strlcpy((x), (y), sizeof(x));	\
    350 	} while (0)
    351 /*
    352  * sysmon_envsys(9) glue.
    353  */
    354 static void
    355 itesio_setup_sensors(struct itesio_softc *sc)
    356 {
    357 	int i;
    358 
    359 	/* temperatures */
    360 	for (i = 0; i < IT_VOLTSTART_IDX; i++)
    361 		sc->sc_sensor[i].units = ENVSYS_STEMP;
    362 
    363 	COPYDESCR(sc->sc_sensor[0].desc, "CPU Temp");
    364 	COPYDESCR(sc->sc_sensor[1].desc, "System Temp");
    365 	COPYDESCR(sc->sc_sensor[2].desc, "Aux Temp");
    366 
    367 	/* voltages */
    368 	for (i = IT_VOLTSTART_IDX; i < IT_FANSTART_IDX; i++) {
    369 		sc->sc_sensor[i].units = ENVSYS_SVOLTS_DC;
    370 		sc->sc_sensor[i].flags = ENVSYS_FCHANGERFACT;
    371 	}
    372 
    373 	COPYDESCR(sc->sc_sensor[3].desc, "VCORE_A");
    374 	COPYDESCR(sc->sc_sensor[4].desc, "VCORE_B");
    375 	COPYDESCR(sc->sc_sensor[5].desc, "+3.3V");
    376 	COPYDESCR(sc->sc_sensor[6].desc, "+5V");
    377 	COPYDESCR(sc->sc_sensor[7].desc, "+12V");
    378 	COPYDESCR(sc->sc_sensor[8].desc, "-12V");
    379 	COPYDESCR(sc->sc_sensor[9].desc, "-5V");
    380 	COPYDESCR(sc->sc_sensor[10].desc, "STANDBY");
    381 	COPYDESCR(sc->sc_sensor[11].desc, "VBAT");
    382 
    383 	/* fans */
    384 	for (i = IT_FANSTART_IDX; i < IT_NUM_SENSORS; i++)
    385 		sc->sc_sensor[i].units = ENVSYS_SFANRPM;
    386 
    387 	COPYDESCR(sc->sc_sensor[12].desc, "CPU Fan");
    388 	COPYDESCR(sc->sc_sensor[13].desc, "System Fan");
    389 	COPYDESCR(sc->sc_sensor[14].desc, "Aux Fan");
    390 }
    391 #undef COPYDESCR
    392 
    393 static void
    394 itesio_refresh_temp(struct itesio_softc *sc, envsys_data_t *edata)
    395 {
    396 	int sdata;
    397 
    398 	sdata = itesio_ecreadreg(sc, ITESIO_EC_SENSORTEMPBASE + edata->sensor);
    399 	/* sensor is not connected or reporting invalid data */
    400 	if (sdata == 0 || sdata >= 0xfa) {
    401 		edata->state = ENVSYS_SINVALID;
    402 		return;
    403 	}
    404 
    405 	DPRINTF(("%s: sdata[temp%d] 0x%x\n", __func__, edata->sensor, sdata));
    406 	/* Convert temperature to uK */
    407 	edata->value_cur = sdata * 1000000 + 273150000;
    408 	edata->state = ENVSYS_SVALID;
    409 }
    410 
    411 static void
    412 itesio_refresh_volts(struct itesio_softc *sc, envsys_data_t *edata)
    413 {
    414 	uint8_t vbatcr = 0;
    415 	int i, sdata;
    416 
    417 	i = edata->sensor - IT_VOLTSTART_IDX;
    418 
    419 	sdata = itesio_ecreadreg(sc, ITESIO_EC_SENSORVOLTBASE + i);
    420 	/* not connected */
    421 	if (sdata == 0 || sdata == 0xff) {
    422 		edata->state = ENVSYS_SINVALID;
    423 		return;
    424 	}
    425 
    426 	/*
    427 	 * update VBAT voltage reading every time we read it, to get
    428 	 * latest value.
    429 	 */
    430 	if (i == 8) {
    431 		vbatcr = itesio_ecreadreg(sc, ITESIO_EC_CONFIG);
    432 		SET(vbatcr, ITESIO_EC_UPDATEVBAT);
    433 		itesio_ecwritereg(sc, ITESIO_EC_CONFIG, vbatcr);
    434 	}
    435 
    436 	DPRINTF(("%s: sdata[volt%d] 0x%x\n", __func__, i, sdata));
    437 
    438 	/* voltage returned as (mV << 4) */
    439 	edata->value_cur = (sdata << 4);
    440 	/* rfact is (factor * 10^4) */
    441 	edata->value_cur *= itesio_vrfact[i];
    442 
    443 	if (edata->rfact)
    444 		edata->value_cur += edata->rfact;
    445 	else
    446 		edata->rfact = itesio_vrfact[i];
    447 
    448 	/* division by 10 gets us back to uVDC */
    449 	edata->value_cur /= 10;
    450 	edata->state = ENVSYS_SVALID;
    451 }
    452 
    453 static void
    454 itesio_refresh_fans(struct itesio_softc *sc, envsys_data_t *edata)
    455 {
    456 	uint8_t mode = 0;
    457 	uint16_t sdata = 0;
    458 	int i, divisor, odivisor, ndivisor;
    459 
    460 	i = edata->sensor - IT_FANSTART_IDX;
    461 	divisor = odivisor = ndivisor = 0;
    462 
    463 	if (sc->sc_chipid == ITESIO_ID8705 || sc->sc_chipid == ITESIO_ID8712) {
    464 		/*
    465 		 * Use the Fan Tachometer Divisor Register for
    466 		 * IT8705F and IT8712F.
    467 		 */
    468 		divisor = odivisor = ndivisor =
    469 		    itesio_ecreadreg(sc, ITESIO_EC_FAN_TDR);
    470 		sdata = itesio_ecreadreg(sc, ITESIO_EC_SENSORFANBASE + i);
    471 		if (sdata == 0xff) {
    472 			edata->state = ENVSYS_SINVALID;
    473 			if (i == 2)
    474 				ndivisor |= 0x40;
    475 			else {
    476 				ndivisor &= ~(7 << (i * 3));
    477 				ndivisor |= ((divisor + 1) & 7) << (i * 3);
    478 			}
    479 		} else {
    480 			if (i == 2)
    481 				divisor = divisor & 1 ? 3 : 1;
    482 
    483 			if ((sdata << (divisor & 7)) == 0)
    484 				edata->state = ENVSYS_SINVALID;
    485 			else {
    486 				edata->value_cur =
    487 				    1350000 / (sdata << (divisor & 7));
    488 				edata->state = ENVSYS_SVALID;
    489 			}
    490 		}
    491 		DPRINTF(("%s: 8bit sdata[fan%d] 0x%x div: 0x%x\n", __func__,
    492 		    i, sdata, divisor));
    493 		if (ndivisor != odivisor)
    494 			itesio_ecwritereg(sc, ITESIO_EC_FAN_TDR, ndivisor);
    495 	} else {
    496 		mode = itesio_ecreadreg(sc, ITESIO_EC_FAN16_CER);
    497 		sdata = itesio_ecreadreg(sc, ITESIO_EC_SENSORFANBASE + i);
    498 		if (mode & (1 << i))
    499 			sdata += (itesio_ecreadreg(sc,
    500 			    ITESIO_EC_SENSORFANEXTBASE + i) << 8);
    501 		edata->state = ENVSYS_SVALID;
    502 		if (sdata == 0 ||
    503 		    sdata == ((mode & (1 << i)) ? 0xffff : 0xff))
    504 			edata->state = ENVSYS_SINVALID;
    505 		else {
    506 			edata->value_cur = 1350000 / 2 / sdata;
    507 			edata->state = ENVSYS_SVALID;
    508 		}
    509 		DPRINTF(("%s: 16bit sdata[fan%d] 0x%x\n", __func__, i, sdata));
    510 	}
    511 }
    512 
    513 static void
    514 itesio_refresh(struct sysmon_envsys *sme, struct envsys_data *edata)
    515 {
    516 	struct itesio_softc *sc = sme->sme_cookie;
    517 
    518 	if (edata->sensor < IT_VOLTSTART_IDX)
    519 		itesio_refresh_temp(sc, edata);
    520 	else if (edata->sensor >= IT_VOLTSTART_IDX &&
    521 	         edata->sensor < IT_FANSTART_IDX)
    522 		itesio_refresh_volts(sc, edata);
    523 	else
    524 		itesio_refresh_fans(sc, edata);
    525 }
    526 
    527 static int
    528 itesio_wdt_setmode(struct sysmon_wdog *smw)
    529 {
    530 	struct itesio_softc *sc = smw->smw_cookie;
    531 	int period = smw->smw_period;
    532 
    533 	/* Enter MB PNP mode and select the WDT LDN */
    534 	itesio_enter(sc->sc_iot, sc->sc_ioh);
    535 	itesio_writereg(sc->sc_iot, sc->sc_ioh, ITESIO_LDNSEL, ITESIO_WDT_LDN);
    536 
    537 	if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
    538 		/* Disable the watchdog */
    539 		itesio_writereg(sc->sc_iot, sc->sc_ioh, ITESIO_WDT_CTL, 0);
    540 		itesio_writereg(sc->sc_iot, sc->sc_ioh, ITESIO_WDT_CNF, 0);
    541 		itesio_writereg(sc->sc_iot, sc->sc_ioh, ITESIO_WDT_TMO_MSB, 0);
    542 		itesio_writereg(sc->sc_iot, sc->sc_ioh, ITESIO_WDT_TMO_LSB, 0);
    543 	} else {
    544 		/* Enable the watchdog */
    545 		if (period > ITESIO_WDT_MAXTIMO || period < 1)
    546 			period = smw->smw_period = ITESIO_WDT_MAXTIMO;
    547 
    548 		period *= 2;
    549 
    550 		/* set the timeout and start the watchdog */
    551 		itesio_writereg(sc->sc_iot, sc->sc_ioh, ITESIO_WDT_TMO_MSB,
    552 		    period >> 8);
    553 		itesio_writereg(sc->sc_iot, sc->sc_ioh, ITESIO_WDT_TMO_LSB,
    554 		    period & 0xff);
    555 		itesio_writereg(sc->sc_iot, sc->sc_ioh, ITESIO_WDT_CNF,
    556 		    ITESIO_WDT_CNF_SECS | ITESIO_WDT_CNF_KRST |
    557 		    ITESIO_WDT_CNF_PWROK);
    558 	}
    559 	/* we are done, exit MB PNP mode */
    560 	itesio_exit(sc->sc_iot, sc->sc_ioh);
    561 
    562 	return 0;
    563 }
    564 
    565 static int
    566 itesio_wdt_tickle(struct sysmon_wdog *smw)
    567 {
    568 	struct itesio_softc *sc = smw->smw_cookie;
    569 	int period = smw->smw_period * 2;
    570 
    571 	/* refresh timeout value and exit */
    572 	itesio_enter(sc->sc_iot, sc->sc_ioh);
    573 	itesio_writereg(sc->sc_iot, sc->sc_ioh, ITESIO_LDNSEL, ITESIO_WDT_LDN);
    574 	itesio_writereg(sc->sc_iot, sc->sc_ioh, ITESIO_WDT_TMO_MSB,
    575 	    period >> 8);
    576 	itesio_writereg(sc->sc_iot, sc->sc_ioh, ITESIO_WDT_TMO_LSB,
    577 	    period & 0xff);
    578 	itesio_exit(sc->sc_iot, sc->sc_ioh);
    579 
    580 	return 0;
    581 }
    582