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