Subject: Re: recommendation for MP box ?
To: Andrew Gillham <gillhaa@ghost.whirlpool.com>
From: Manuel Bouyer <bouyer@antioche.lip6.fr>
List: port-i386
Date: 07/02/2000 13:56:17
--x+6KMIRAuhnl3hBn
Content-Type: text/plain; charset=us-ascii

On Sun, Jul 02, 2000 at 01:10:39AM -0400, Andrew Gillham wrote:
> Manuel Bouyer writes:
> > On Sat, Jul 01, 2000 at 03:17:36PM -0400, Laine Stump wrote:
> > > Ooh! It works! Some more cool (and probably useless ;-) statistics to map
> > > with mrtg!
> > 
> > Not that useless, you should be able to detect a dead fan with this :)
> 
> Exactly, or detect a local AC problem at a hosting center.  So Manuel
> what did you figure out about your 810E sensors?  I just got a CA810EAL
> and need to read the data. :)

On my motherboard, hardware monitor comes from the winbond I/O chip (W83627HF).
It's LM78-compatible but has more sensors. I'll commit my changes tomorow.
In the meantime I attached my sys/dev/ic/nslm7x*, you can play with it :)
This is for 1.5_ALPHA. The sensors are at the standart (0x290) port.

--
Manuel Bouyer <bouyer@antioche.eu.org>
--

--x+6KMIRAuhnl3hBn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="nslm7x.c"

/*	$NetBSD: nslm7x.c,v 1.3 2000/03/09 04:20:58 groo Exp $ */

/*-
 * Copyright (c) 2000 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Bill Squier.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/errno.h>
#include <sys/queue.h>
#include <sys/lock.h>
#include <sys/ioctl.h>
#include <sys/conf.h>
#include <sys/time.h>

#include <sys/envsys.h>

#include <machine/bus.h>

#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>

#include <dev/ic/nslm7xvar.h>

#include <machine/intr.h>
#include <machine/bus.h>

#if defined(LMDEBUG)
#define DPRINTF(x)		do { printf x; } while (0)
#else
#define DPRINTF(x)
#endif

struct envsys_range ranges[] = {	/* sc->sensors sub-intervals */
					/* for each unit type        */
	{ 7, 7,    ENVSYS_STEMP   },
	{ 8, 10,   ENVSYS_SFANRPM },
	{ 1, 0,    ENVSYS_SVOLTS_AC },	/* None */
	{ 0, 6,    ENVSYS_SVOLTS_DC },
	{ 1, 0,    ENVSYS_SOHMS },	/* None */
	{ 1, 0,    ENVSYS_SWATTS },	/* None */
	{ 1, 0,    ENVSYS_SAMPS }	/* None */
};

	
#define SCFLAG_OREAD	0x00000001
#define SCFLAG_OWRITE	0x00000002
#define SCFLAG_OPEN	(SCFLAG_OREAD|SCFLAG_OWRITE)

u_int8_t lm_readreg __P((struct lm_softc *, int));
void lm_writereg __P((struct lm_softc *, int, int));

int lm_match __P((struct lm_softc *));
void lm_refresh_sensor_data __P((struct lm_softc *));

int wb_match __P((struct lm_softc *));
void wb_refresh_sensor_data __P((struct lm_softc *));

int def_match __P((struct lm_softc *));
void lm_common_match __P((struct lm_softc *));

cdev_decl(lm);

extern struct cfdriver lm_cd;

#define LMUNIT(x)	(minor(x))

struct lm_chip {
	int (*chip_match) __P((struct lm_softc *));
};

struct lm_chip lm_chips[] = {
	{ lm_match},
	{ wb_match},
	{ def_match} /* Must be last */
};


u_int8_t
lm_readreg(sc, reg)
	struct lm_softc *sc;
	int reg;
{
	bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
	return (bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA));
}

void
lm_writereg(sc, reg, val)
	struct lm_softc *sc;
	int reg;
	int val;
{
	bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
	bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val);
}


/*
 * bus independent probe
 */
int
lm_probe(iot, ioh)
	bus_space_tag_t iot;
	bus_space_handle_t ioh;
{
	u_int8_t cr;
	int rv;

	/* Check for some power-on defaults */
	bus_space_write_1(iot, ioh, LMC_ADDR, LMD_CONFIG);

	/* Perform LM78 reset */
	bus_space_write_1(iot, ioh, LMC_DATA, 0x80);

	/* XXX - Why do I have to reselect the register? */
	bus_space_write_1(iot, ioh, LMC_ADDR, LMD_CONFIG);
	cr = bus_space_read_1(iot, ioh, LMC_DATA);

	/* XXX - spec says *only* 0x08! */
	if ((cr == 0x08) || (cr == 0x01))
		rv = 1;
	else
		rv = 0;

	DPRINTF(("lm: rv = %d, cr = %x\n", rv, cr));

	return (rv);
}


/*
 * pre:  lmsc contains valid busspace tag and handle
 */
void
lm_attach(lmsc)
	struct lm_softc *lmsc;
{
	int i;

	for (i = 0; i < sizeof(lm_chips) / sizeof(lm_chips[0]); i++) 
		if (lm_chips[i].chip_match(lmsc))
			break;

	/* Start the monitoring loop */
	lm_writereg(lmsc, LMD_CONFIG, 0x01);

	/* Indicate we have never read the registers */
	timerclear(&lmsc->lastread);

	/* Initialize sensors */
	for (i = 0; i < lmsc->numsensors; ++i) {
		lmsc->sensors[i].sensor = lmsc->info[i].sensor = i;
		lmsc->sensors[i].validflags = (ENVSYS_FVALID|ENVSYS_FCURVALID);
		lmsc->info[i].validflags = ENVSYS_FVALID;
		lmsc->sensors[i].warnflags = ENVSYS_WARN_OK;
	}
}

int
lm_match(sc)
	struct lm_softc *sc;
{
	int i;

	/* See if we have an LM78 or LM79 */
	i = lm_readreg(sc, LMD_CHIPID) & LM_ID_MASK;
	switch(i) {
	case LM_ID_LM78:
		printf(": LM78\n");
		break;
	case LM_ID_LM78J:
		printf(": LM78J\n");
		break;
	case LM_ID_LM79:
		printf(": LM79\n");
		break;
	default:
		return 0;
	}
	lm_common_match(sc);
	return 1;
}

int
def_match(sc)
	struct lm_softc *sc;
{
	int i;

	i = lm_readreg(sc, LMD_CHIPID) & LM_ID_MASK;
	printf(": Unknow chip (ID %d)\n", i);
	lm_common_match(sc);
	return 1;
}

void
lm_common_match(sc)
	struct lm_softc *sc;
{
	int i;
	sc->numsensors = LM_NUM_SENSORS;
	sc->refresh_sensor_data = lm_refresh_sensor_data;

	for (i = 0; i < 7; ++i) {
		sc->sensors[i].units = sc->info[i].units =
		    ENVSYS_SVOLTS_DC;
		sprintf(sc->info[i].desc, "IN %d", i);
	}

	/* default correction factors for resistors on higher voltage inputs */
	sc->info[0].rfact = sc->info[1].rfact = 
	    sc->info[2].rfact = 10000;
	sc->info[3].rfact = (int)(( 90.9 / 60.4) * 10000);
	sc->info[4].rfact = (int)(( 38.0 / 10.0) * 10000);
	sc->info[5].rfact = (int)((210.0 / 60.4) * 10000);
	sc->info[6].rfact = (int)(( 90.9 / 60.4) * 10000);

	sc->sensors[7].units = ENVSYS_STEMP;
	strcpy(sc->info[7].desc, "Temp");

	for (i = 8; i < 11; ++i) {
		sc->sensors[i].units = sc->info[i].units = ENVSYS_SFANRPM;
		sprintf(sc->info[i].desc, "Fan %d", i - 7);
	}
}

int
wb_match(sc)
	struct lm_softc *sc;
{
	int i, j;

	/* See if we have a winbond */
	i = lm_readreg(sc, LMD_CHIPID) & LM_ID_MASK;
	lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_HBAC);
	j = lm_readreg(sc, WB_VENDID) << 8;
	lm_writereg(sc, WB_BANKSEL, 0);
	j |= lm_readreg(sc, WB_VENDID);
	DPRINTF(("winbond vend id %d\n", j));
	if (j != WB_VENDID_WINBOND)
		return 0;
	printf(": W83627HF (device ID %d)\n", i);
	sc->numsensors = WB_NUM_SENSORS;
	sc->refresh_sensor_data = wb_refresh_sensor_data;

	sc->sensors[0].units = sc->info[0].units = ENVSYS_SVOLTS_DC;
	sprintf(sc->info[0].desc, "VCORE A");
	sc->info[0].rfact = 10000;
	sc->sensors[1].units = sc->info[1].units = ENVSYS_SVOLTS_DC;
	sprintf(sc->info[1].desc, "VCORE B");
	sc->info[1].rfact = 10000;
	sc->sensors[2].units = sc->info[2].units = ENVSYS_SVOLTS_DC;
	sprintf(sc->info[2].desc, "+3.3V");
	sc->info[2].rfact = 10000;
	sc->sensors[3].units = sc->info[3].units = ENVSYS_SVOLTS_DC;
	sprintf(sc->info[3].desc, "+5V");
	sc->info[3].rfact = 16778;
	sc->sensors[4].units = sc->info[4].units = ENVSYS_SVOLTS_DC;
	sprintf(sc->info[4].desc, "+12V");
	sc->info[4].rfact = 38000;
	sc->sensors[5].units = sc->info[5].units = ENVSYS_SVOLTS_DC;
	sprintf(sc->info[5].desc, "-12V");
	sc->info[5].rfact = 10000;
	sc->sensors[6].units = sc->info[6].units = ENVSYS_SVOLTS_DC;
	sprintf(sc->info[6].desc, "-5V");
	sc->info[6].rfact = 10000;
	sc->sensors[7].units = sc->info[7].units = ENVSYS_SVOLTS_DC;
	sprintf(sc->info[7].desc, "+5VSB");
	sc->info[7].rfact = 15151;
	sc->sensors[8].units = sc->info[8].units = ENVSYS_SVOLTS_DC;
	sprintf(sc->info[8].desc, "VBAT");
	sc->info[8].rfact = 10000;

	sc->sensors[9].units = ENVSYS_STEMP;
	strcpy(sc->info[9].desc, "Temp 1");
	sc->sensors[10].units = ENVSYS_STEMP;
	strcpy(sc->info[10].desc, "Temp 2");
	sc->sensors[11].units = ENVSYS_STEMP;
	strcpy(sc->info[11].desc, "Temp 3");

	for (i = 12; i < 15; ++i) {
		sc->sensors[i].units = sc->info[i].units = ENVSYS_SFANRPM;
		sprintf(sc->info[i].desc, "Fan %d", i - 11);
	}
	return 1;
}

int	
lmopen(dev, flag, mode, p)
	dev_t dev;
	int flag, mode;
	struct proc *p;
{
	int unit = LMUNIT(dev);
	struct lm_softc *sc;
	
	if (unit >= lm_cd.cd_ndevs)
		return (ENXIO);
	sc = lm_cd.cd_devs[unit];
	if (sc == 0)
		return (ENXIO);

	/* XXX - add spinlocks instead! */
	if (sc->sc_flags & SCFLAG_OPEN)
		return (EBUSY);

	sc->sc_flags |= SCFLAG_OPEN;

	return 0;
}


int
lmclose(dev, flag, mode, p)
	dev_t dev;
	int flag, mode;
	struct proc *p;
{
	struct lm_softc *sc = lm_cd.cd_devs[LMUNIT(dev)];

	DPRINTF(("lmclose: pid %d flag %x mode %x\n", p->p_pid, flag, mode));

	sc->sc_flags &= ~SCFLAG_OPEN;

	return 0;
}


int
lmioctl(dev, cmd, data, flag, p)
	dev_t dev;
	u_long cmd;
	caddr_t data;
	int flag;
	struct proc *p;
{
	struct lm_softc *sc = lm_cd.cd_devs[LMUNIT(dev)];
	struct envsys_range *rng;
	struct envsys_tre_data *tred;
	struct envsys_basic_info *binfo;
	struct timeval t, onepointfive = { 1, 500000 };
	u_int8_t sdata;
	int32_t *vers;
	int i, s;
	int divisor;

	switch (cmd) {
	case ENVSYS_VERSION:
		vers = (int32_t *)data;
		*vers = 1000;

		return (0);

	case ENVSYS_GRANGE:
		rng = (struct envsys_range *)data;
		if ((rng->units < ENVSYS_STEMP) ||
		    (rng->units > ENVSYS_SAMPS) ) {
			/* Return empty range for unsupp sensor types */
			rng->low = 1;
			rng->high = 0;
		} else {
			rng->low  = ranges[rng->units].low;
			rng->high = ranges[rng->units].high;
		}

		return (0);

	case ENVSYS_GTREDATA:
		tred = (struct envsys_tre_data *)data;
		tred->validflags = 0;

		if (tred->sensor < sc->numsensors) {
			/* read new values at most once every 1.5 seconds */
			s = splclock();

			timeradd(&sc->lastread, &onepointfive, &t);

			i = timercmp(&mono_time, &t, >);
			if (i) {
				sc->lastread.tv_sec  = mono_time.tv_sec;
				sc->lastread.tv_usec = mono_time.tv_usec; 
			}
			splx(s);
		   
			if (i) {
				sc->refresh_sensor_data(sc);
			}

			bcopy(&sc->sensors[tred->sensor], tred,
			      sizeof(struct envsys_tre_data));
		}

		return (0);

	case ENVSYS_GTREINFO:
		binfo = (struct envsys_basic_info *)data;

		if (binfo->sensor >=  sc->numsensors)
			binfo->validflags = 0;
		else
			bcopy(&sc->info[binfo->sensor], binfo,
			      sizeof(struct envsys_basic_info));

		return (0);

	case ENVSYS_STREINFO:
		binfo = (struct envsys_basic_info *)data;

		if (binfo->sensor >=  sc->numsensors)
			binfo->validflags = 0;
		else if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
			sc->info[binfo->sensor].rfact = binfo->rfact;
		else {
			/* FAN1 and FAN2 can have divisors set, but not FAN3 */
			if ((sc->info[binfo->sensor].units == ENVSYS_SFANRPM)
			    && (binfo->sensor != 10)) {

				if (binfo->rpms == 0) {
					binfo->validflags = 0;
					return (0);
				}

				/* 153 is the nominal FAN speed value */
				divisor = 1350000 / (binfo->rpms * 153);

				/* ...but we need lg(divisor) */
				if (divisor <= 1)
					divisor = 0;
				else if (divisor <= 2)
					divisor = 1;
				else if (divisor <= 4)
					divisor = 2;
				else
					divisor = 3;

				/*
				 * FAN1 div is in bits <5:4>, FAN2 div is
				 * in <7:6>
				 */
				sdata = lm_readreg(sc, LMD_VIDFAN);
				if ( binfo->sensor == 8 ) {  /* FAN1 */
					divisor <<= 4;
					sdata = (sdata & 0xCF) | divisor;
				} else { /* FAN2 */
					divisor <<= 6;
					sdata = (sdata & 0x3F) | divisor;
				}

				lm_writereg(sc, LMD_VIDFAN, sdata);
			}

			bcopy(binfo->desc, sc->info[binfo->sensor].desc, 33);
			sc->info[binfo->sensor].desc[32] = 0;

			binfo->validflags = ENVSYS_FVALID;
		}

		return (0);

	default:
		return (ENOTTY);
	}
}


/*
 * pre:  last read occured >= 1.5 seconds ago
 * post: sensors[] current data are the latest from the chip
 */
void
lm_refresh_sensor_data(sc)
	struct lm_softc *sc;
{
	u_int16_t sdata;
	int i, divisor;

	/* Refresh our stored data for every sensor */
	for (i = 0; i < LM_NUM_SENSORS; ++i) {
		sdata = lm_readreg(sc, LMD_SENSORBASE + i);
		
		switch (sc->sensors[i].units) {
		case ENVSYS_STEMP:
			/* temp is given in deg. C, we convert to uK */
			sc->sensors[i].cur.data_us = sdata * 1000000 +
			    273150000;
			break;
			
		case ENVSYS_SVOLTS_DC:
			/* voltage returned as (mV >> 4), we convert to uVDC */
			sc->sensors[i].cur.data_s = (sdata << 4);
			/* rfact is (factor * 10^4) */
			sc->sensors[i].cur.data_s *= sc->info[i].rfact;
			/* division by 10 gets us back to uVDC */
			sc->sensors[i].cur.data_s /= 10;
			
			/* these two are negative voltages */
			if ( (i == 5) || (i == 6) )
				sc->sensors[i].cur.data_s *= -1;

			break;
			
		case ENVSYS_SFANRPM:
			if (i == 10)
				divisor = 2;	/* Fixed divisor for FAN3 */
			else if (i == 9)	/* Bits 7 & 6 of VID/FAN  */
				divisor = (lm_readreg(sc, LMD_VIDFAN) >> 6) &
				    0x3;
			else
				divisor = (lm_readreg(sc, LMD_VIDFAN) >> 4) &
				    0x3;
			
			sc->sensors[i].cur.data_us = 1350000 /
			    (sdata << divisor);
			
			break;
			
		default:
			/* XXX - debug log something? */
			sc->sensors[i].validflags = 0;
			
			break;
		}
	}
}

void
wb_refresh_sensor_data(sc)
	struct lm_softc *sc;
{
	int sdata;
	int i, divisor;

	/* Refresh our stored data for every sensor */
	/* first voltage sensors */
	for (i = 0; i < 9; ++i) {
		if (i < 7) {
			sdata = lm_readreg(sc, LMD_SENSORBASE + i);
		} else {
			/* from bank5 */
			lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_B5);
			sdata = lm_readreg(sc, (i == 7) ?
			    WB_BANK5_5VSB : WB_BANK5_VBAT);
		}
		DPRINTF(("sdata[%d] 0x%x\n", i, sdata));
		/* voltage returned as (mV >> 4), we convert to uV */
		sdata =  sdata << 4;
		/* special case for negative voltages */
		if (i == 5) {
			/*
			 * -12Vdc, assume Winbond recommended values for
			 * resistors
			 */
			sdata = ((sdata * 1000) - (3600 * 805)) / 195;
		} else if (i == 6) {
			/*
			 * -5Vdc, assume Winbond recommended values for
			 * resistors
			 */
			sdata = ((sdata * 1000) - (3600 * 682)) / 318;
		}
		/* rfact is (factor * 10^4) */
		sc->sensors[i].cur.data_s = sdata * sc->info[i].rfact;
		/* division by 10 gets us back to uVDC */
		sc->sensors[i].cur.data_s /= 10;
	}
	/* temperatures. Given in dC, we convert to uK */
	sdata = lm_readreg(sc, LMD_SENSORBASE + 7);
	DPRINTF(("sdata[%d] 0x%x\n", 9, sdata));
	sc->sensors[9].cur.data_us = sdata * 1000000 + 273150000;
	/* from bank1 */
	lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_B1);
	sdata = lm_readreg(sc, WB_BANK1_T2H) << 1;
	sdata |=  (lm_readreg(sc, WB_BANK1_T2L) & 0x80) >> 7;
	DPRINTF(("sdata[%d] 0x%x\n", 10, sdata));
	sc->sensors[10].cur.data_us = (sdata * 1000000) / 2 + 273150000;
	/* from bank2 */
	lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_B2);
	sdata = lm_readreg(sc, WB_BANK2_T3H) << 1;
	sdata |=  (lm_readreg(sc, WB_BANK2_T3L) & 0x80) >> 7;
	DPRINTF(("sdata[%d] 0x%x\n", 11, sdata));
	sc->sensors[11].cur.data_us = (sdata * 1000000) / 2 + 273150000;

	/* Fans */
	lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_B0);
	for (i = 12; i < 15; i++) {
	    	sdata = lm_readreg(sc, LMD_SENSORBASE + i - 4);
		if (i == 12)
			divisor = (lm_readreg(sc, LMD_VIDFAN) >> 4) & 0x3;
		else if (i == 13)
			divisor = (lm_readreg(sc, LMD_VIDFAN) >> 6) & 0x3;
		else
			divisor = (lm_readreg(sc, WB_PIN) >> 6) & 0x3;
		divisor |= (lm_readreg(sc, WB_BANK0_FANBAT) >> (i - 9)) & 0x4;
		
		DPRINTF(("sdata[%d] 0x%x div 0x%x\n", i, sdata, divisor));
		sc->sensors[i].cur.data_us = 1350000 /
		    (sdata << divisor);
		
	}
}

--x+6KMIRAuhnl3hBn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="nslm7xvar.h"

/*	$NetBSD: nslm7xvar.h,v 1.2 2000/03/07 18:39:14 groo Exp $ */

/*-
 * Copyright (c) 2000 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Bill Squier.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *        This product includes software developed by the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _DEV_ISA_NSLM7XVAR_H_
#define _DEV_ISA_NSLM7XVAR_H_

/* ctl registers */

#define LMC_ADDR	0x05
#define LMC_DATA	0x06

/* data registers */

#define LMD_SENSORBASE	0x20	/* Sensors occupy 0x20 -- 0x2a */

#define LMD_CONFIG	0x40	/* Configuration */ 
#define LMD_ISR1	0x41	/* Interrupt Status 1 */
#define LMD_ISR2	0x42	/* Interrupt Status 2 */
#define LMD_SMI1	0x43	/* SMI Mask 1 */
#define LMD_SMI2	0x44	/* SMI Mask 2 */
#define LMD_NMI1	0x45	/* NMI Mask 1 */
#define LMD_NMI2	0x46	/* NMI Mask 2 */
#define LMD_VIDFAN	0x47	/* VID/Fan Divisor */
#define LMD_SBUSADDR	0x48	/* Serial Bus Address */
#define LMD_CHIPID	0x49	/* Chip Reset/ID */

/* misc constants */

#define LM_NUM_SENSORS	11
#define LM_ID_LM78	0x00
#define LM_ID_LM78J	0x40
#define LM_ID_LM79	0xC0
#define LM_ID_MASK	0xFE

/* additionnal registers for the Winbond W83627HF */
#define WB_PIN		0x4B	/* pin & fan3 divider */
#define WB_BANKSEL	0x4E	/* banck select register */
#define WB_BANKSEL_B0	0x00	/* select bank 0 */
#define WB_BANKSEL_B1	0x01	/* select bank 1 */
#define WB_BANKSEL_B2	0x02	/* select bank 2 */
#define WB_BANKSEL_B3	0x03	/* select bank 3 */
#define WB_BANKSEL_B4	0x04	/* select bank 4 */
#define WB_BANKSEL_B5	0x05	/* select bank 5 */
#define WB_BANKSEL_HBAC	0x80	/* hight byte access */

#define WB_VENDID	0x4F	/* vendor ID register */
#define WB_VENDID_WINBOND 0x5CA3
/* Bank0 regs */
#define WB_BANK0_FANBAT	0x5D
/* Bank1 regs */
#define WB_BANK1_T2H	0x50
#define WB_BANK1_T2L	0x51

/* Bank2 regs */
#define WB_BANK2_T3H	0x50
#define WB_BANK2_T3L	0x51

/* Bank4 regs */
#define WB_BANK4_T1OFF	0x54
#define WB_BANK4_T2OFF	0x55
#define WB_BANK4_T3OFF	0x56

/* Bank5 regs */
#define WB_BANK5_5VSB	0x50
#define WB_BANK5_VBAT	0x51

#define WB_NUM_SENSORS	15

struct lm_softc {
	struct	device sc_dev;

	int	lm_iobase;
	bus_space_tag_t lm_iot;
	bus_space_handle_t lm_ioh;

	int	sc_flags;
	struct	timeval lastread; /* only allow reads every 1.5 seconds */
	struct	envsys_tre_data sensors[WB_NUM_SENSORS];
	struct	envsys_basic_info info[WB_NUM_SENSORS];
	int numsensors;
	void (*refresh_sensor_data) __P((struct lm_softc *));
};

void lm_attach __P((struct lm_softc *));
int lm_probe __P((bus_space_tag_t, bus_space_handle_t));

#endif /* _DEV_ISA_NSLM7XVAR_H_ */

--x+6KMIRAuhnl3hBn--