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