Home | History | Annotate | Line # | Download | only in ic
nslm7x.c revision 1.27
      1  1.27   hannken /*	$NetBSD: nslm7x.c,v 1.27 2006/06/08 10:56:49 hannken Exp $ */
      2   1.1      groo 
      3   1.1      groo /*-
      4   1.1      groo  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5   1.1      groo  * All rights reserved.
      6   1.1      groo  *
      7   1.1      groo  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1      groo  * by Bill Squier.
      9   1.1      groo  *
     10   1.1      groo  * Redistribution and use in source and binary forms, with or without
     11   1.1      groo  * modification, are permitted provided that the following conditions
     12   1.1      groo  * are met:
     13   1.1      groo  * 1. Redistributions of source code must retain the above copyright
     14   1.1      groo  *    notice, this list of conditions and the following disclaimer.
     15   1.1      groo  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1      groo  *    notice, this list of conditions and the following disclaimer in the
     17   1.1      groo  *    documentation and/or other materials provided with the distribution.
     18   1.1      groo  * 3. All advertising materials mentioning features or use of this software
     19   1.1      groo  *    must display the following acknowledgement:
     20   1.1      groo  *        This product includes software developed by the NetBSD
     21   1.1      groo  *        Foundation, Inc. and its contributors.
     22   1.1      groo  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1      groo  *    contributors may be used to endorse or promote products derived
     24   1.1      groo  *    from this software without specific prior written permission.
     25   1.1      groo  *
     26   1.1      groo  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1      groo  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1      groo  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1      groo  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1      groo  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1      groo  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1      groo  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1      groo  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1      groo  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1      groo  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1      groo  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1      groo  */
     38  1.13     lukem 
     39  1.13     lukem #include <sys/cdefs.h>
     40  1.27   hannken __KERNEL_RCSID(0, "$NetBSD: nslm7x.c,v 1.27 2006/06/08 10:56:49 hannken Exp $");
     41   1.1      groo 
     42   1.1      groo #include <sys/param.h>
     43   1.1      groo #include <sys/systm.h>
     44   1.1      groo #include <sys/kernel.h>
     45   1.1      groo #include <sys/proc.h>
     46   1.1      groo #include <sys/device.h>
     47   1.1      groo #include <sys/malloc.h>
     48   1.1      groo #include <sys/errno.h>
     49   1.1      groo #include <sys/queue.h>
     50   1.1      groo #include <sys/lock.h>
     51   1.1      groo #include <sys/ioctl.h>
     52   1.1      groo #include <sys/conf.h>
     53   1.1      groo #include <sys/time.h>
     54   1.1      groo 
     55   1.1      groo #include <machine/bus.h>
     56   1.1      groo 
     57   1.1      groo #include <dev/isa/isareg.h>
     58   1.1      groo #include <dev/isa/isavar.h>
     59   1.1      groo 
     60   1.4   thorpej #include <dev/sysmon/sysmonvar.h>
     61   1.4   thorpej 
     62   1.1      groo #include <dev/ic/nslm7xvar.h>
     63   1.1      groo 
     64   1.1      groo #include <machine/intr.h>
     65   1.1      groo #include <machine/bus.h>
     66   1.1      groo 
     67   1.1      groo #if defined(LMDEBUG)
     68  1.19  christos #define DPRINTF(x)		printf x
     69   1.1      groo #else
     70   1.1      groo #define DPRINTF(x)
     71   1.1      groo #endif
     72   1.1      groo 
     73   1.4   thorpej const struct envsys_range lm_ranges[] = {	/* sc->sensors sub-intervals */
     74   1.5    bouyer 					/* for each unit type */
     75   1.1      groo 	{ 7, 7,    ENVSYS_STEMP   },
     76   1.1      groo 	{ 8, 10,   ENVSYS_SFANRPM },
     77   1.1      groo 	{ 1, 0,    ENVSYS_SVOLTS_AC },	/* None */
     78   1.1      groo 	{ 0, 6,    ENVSYS_SVOLTS_DC },
     79   1.1      groo 	{ 1, 0,    ENVSYS_SOHMS },	/* None */
     80   1.1      groo 	{ 1, 0,    ENVSYS_SWATTS },	/* None */
     81   1.1      groo 	{ 1, 0,    ENVSYS_SAMPS }	/* None */
     82   1.1      groo };
     83   1.1      groo 
     84   1.5    bouyer 
     85  1.20     perry static void setup_fan(struct lm_softc *, int, int);
     86  1.20     perry static void setup_temp(struct lm_softc *, int, int);
     87  1.20     perry static void wb_setup_volt(struct lm_softc *);
     88  1.20     perry 
     89  1.20     perry int lm_match(struct lm_softc *);
     90  1.20     perry int wb_match(struct lm_softc *);
     91  1.20     perry int def_match(struct lm_softc *);
     92  1.20     perry void lm_common_match(struct lm_softc *);
     93  1.20     perry static int lm_generic_banksel(struct lm_softc *, int);
     94  1.20     perry 
     95  1.20     perry static void generic_stemp(struct lm_softc *, struct envsys_tre_data *);
     96  1.20     perry static void generic_svolt(struct lm_softc *, struct envsys_tre_data *,
     97  1.20     perry     struct envsys_basic_info *);
     98  1.20     perry static void generic_fanrpm(struct lm_softc *, struct envsys_tre_data *);
     99  1.20     perry 
    100  1.20     perry void lm_refresh_sensor_data(struct lm_softc *);
    101  1.20     perry 
    102  1.20     perry static void wb_svolt(struct lm_softc *);
    103  1.20     perry static void wb_stemp(struct lm_softc *, struct envsys_tre_data *, int);
    104  1.20     perry static void wb781_fanrpm(struct lm_softc *, struct envsys_tre_data *);
    105  1.20     perry static void wb_fanrpm(struct lm_softc *, struct envsys_tre_data *);
    106  1.20     perry 
    107  1.20     perry void wb781_refresh_sensor_data(struct lm_softc *);
    108  1.20     perry void wb782_refresh_sensor_data(struct lm_softc *);
    109  1.20     perry void wb697_refresh_sensor_data(struct lm_softc *);
    110  1.20     perry 
    111  1.20     perry int lm_gtredata(struct sysmon_envsys *, struct envsys_tre_data *);
    112  1.20     perry 
    113  1.20     perry int generic_streinfo_fan(struct lm_softc *, struct envsys_basic_info *,
    114  1.20     perry            int, struct envsys_basic_info *);
    115  1.20     perry int lm_streinfo(struct sysmon_envsys *, struct envsys_basic_info *);
    116  1.20     perry int wb781_streinfo(struct sysmon_envsys *, struct envsys_basic_info *);
    117  1.20     perry int wb782_streinfo(struct sysmon_envsys *, struct envsys_basic_info *);
    118   1.5    bouyer 
    119   1.5    bouyer struct lm_chip {
    120  1.20     perry 	int (*chip_match)(struct lm_softc *);
    121   1.5    bouyer };
    122   1.5    bouyer 
    123   1.5    bouyer struct lm_chip lm_chips[] = {
    124   1.8    bouyer 	{ wb_match },
    125   1.8    bouyer 	{ lm_match },
    126   1.8    bouyer 	{ def_match } /* Must be last */
    127   1.5    bouyer };
    128   1.5    bouyer 
    129   1.1      groo 
    130  1.17        ad int
    131  1.17        ad lm_generic_banksel(lmsc, bank)
    132  1.17        ad 	struct lm_softc *lmsc;
    133  1.17        ad 	int bank;
    134   1.1      groo {
    135   1.1      groo 
    136  1.17        ad 	(*lmsc->lm_writereg)(lmsc, WB_BANKSEL, bank);
    137  1.19  christos 	return 0;
    138   1.1      groo }
    139   1.1      groo 
    140   1.1      groo 
    141   1.1      groo /*
    142   1.2      groo  * bus independent probe
    143   1.2      groo  */
    144   1.2      groo int
    145   1.2      groo lm_probe(iot, ioh)
    146   1.2      groo 	bus_space_tag_t iot;
    147   1.2      groo 	bus_space_handle_t ioh;
    148   1.2      groo {
    149   1.2      groo 	u_int8_t cr;
    150   1.2      groo 	int rv;
    151   1.2      groo 
    152   1.2      groo 	/* Check for some power-on defaults */
    153   1.2      groo 	bus_space_write_1(iot, ioh, LMC_ADDR, LMD_CONFIG);
    154   1.2      groo 
    155   1.2      groo 	/* Perform LM78 reset */
    156   1.2      groo 	bus_space_write_1(iot, ioh, LMC_DATA, 0x80);
    157   1.2      groo 
    158   1.2      groo 	/* XXX - Why do I have to reselect the register? */
    159   1.2      groo 	bus_space_write_1(iot, ioh, LMC_ADDR, LMD_CONFIG);
    160   1.2      groo 	cr = bus_space_read_1(iot, ioh, LMC_DATA);
    161   1.2      groo 
    162   1.2      groo 	/* XXX - spec says *only* 0x08! */
    163  1.23   xtraeme 	if ((cr == 0x08) || (cr == 0x01) || (cr == 0x03))
    164   1.2      groo 		rv = 1;
    165   1.2      groo 	else
    166   1.2      groo 		rv = 0;
    167   1.2      groo 
    168   1.2      groo 	DPRINTF(("lm: rv = %d, cr = %x\n", rv, cr));
    169   1.2      groo 
    170   1.2      groo 	return (rv);
    171   1.2      groo }
    172   1.2      groo 
    173   1.2      groo 
    174   1.2      groo /*
    175   1.1      groo  * pre:  lmsc contains valid busspace tag and handle
    176   1.1      groo  */
    177   1.1      groo void
    178   1.1      groo lm_attach(lmsc)
    179   1.1      groo 	struct lm_softc *lmsc;
    180   1.1      groo {
    181  1.16   thorpej 	u_int i;
    182   1.1      groo 
    183  1.17        ad 	/* Install default bank selection routine, if none given. */
    184  1.17        ad 	if (lmsc->lm_banksel == NULL)
    185  1.17        ad 		lmsc->lm_banksel = lm_generic_banksel;
    186  1.17        ad 
    187   1.5    bouyer 	for (i = 0; i < sizeof(lm_chips) / sizeof(lm_chips[0]); i++)
    188   1.5    bouyer 		if (lm_chips[i].chip_match(lmsc))
    189   1.5    bouyer 			break;
    190   1.1      groo 
    191   1.1      groo 	/* Start the monitoring loop */
    192  1.17        ad 	(*lmsc->lm_writereg)(lmsc, LMD_CONFIG, 0x01);
    193   1.1      groo 
    194   1.1      groo 	/* Indicate we have never read the registers */
    195   1.1      groo 	timerclear(&lmsc->lastread);
    196   1.1      groo 
    197   1.1      groo 	/* Initialize sensors */
    198   1.5    bouyer 	for (i = 0; i < lmsc->numsensors; ++i) {
    199   1.1      groo 		lmsc->sensors[i].sensor = lmsc->info[i].sensor = i;
    200   1.1      groo 		lmsc->sensors[i].validflags = (ENVSYS_FVALID|ENVSYS_FCURVALID);
    201   1.1      groo 		lmsc->info[i].validflags = ENVSYS_FVALID;
    202   1.1      groo 		lmsc->sensors[i].warnflags = ENVSYS_WARN_OK;
    203   1.1      groo 	}
    204   1.4   thorpej 	/*
    205   1.4   thorpej 	 * Hook into the System Monitor.
    206   1.4   thorpej 	 */
    207   1.4   thorpej 	lmsc->sc_sysmon.sme_ranges = lm_ranges;
    208   1.4   thorpej 	lmsc->sc_sysmon.sme_sensor_info = lmsc->info;
    209   1.4   thorpej 	lmsc->sc_sysmon.sme_sensor_data = lmsc->sensors;
    210   1.4   thorpej 	lmsc->sc_sysmon.sme_cookie = lmsc;
    211   1.4   thorpej 
    212   1.4   thorpej 	lmsc->sc_sysmon.sme_gtredata = lm_gtredata;
    213   1.5    bouyer 	/* sme_streinfo set in chip-specific attach */
    214   1.4   thorpej 
    215   1.5    bouyer 	lmsc->sc_sysmon.sme_nsensors = lmsc->numsensors;
    216   1.4   thorpej 	lmsc->sc_sysmon.sme_envsys_version = 1000;
    217   1.4   thorpej 
    218   1.4   thorpej 	if (sysmon_envsys_register(&lmsc->sc_sysmon))
    219   1.4   thorpej 		printf("%s: unable to register with sysmon\n",
    220   1.4   thorpej 		    lmsc->sc_dev.dv_xname);
    221   1.1      groo }
    222   1.1      groo 
    223   1.5    bouyer int
    224   1.5    bouyer lm_match(sc)
    225   1.5    bouyer 	struct lm_softc *sc;
    226   1.5    bouyer {
    227   1.5    bouyer 	int i;
    228   1.5    bouyer 
    229   1.5    bouyer 	/* See if we have an LM78 or LM79 */
    230  1.17        ad 	i = (*sc->lm_readreg)(sc, LMD_CHIPID) & LM_ID_MASK;
    231   1.5    bouyer 	switch(i) {
    232   1.5    bouyer 	case LM_ID_LM78:
    233   1.5    bouyer 		printf(": LM78\n");
    234   1.5    bouyer 		break;
    235   1.5    bouyer 	case LM_ID_LM78J:
    236   1.5    bouyer 		printf(": LM78J\n");
    237   1.5    bouyer 		break;
    238   1.5    bouyer 	case LM_ID_LM79:
    239   1.5    bouyer 		printf(": LM79\n");
    240  1.15    bouyer 		break;
    241  1.15    bouyer 	case LM_ID_LM81:
    242  1.15    bouyer 		printf(": LM81\n");
    243   1.5    bouyer 		break;
    244   1.5    bouyer 	default:
    245   1.5    bouyer 		return 0;
    246   1.5    bouyer 	}
    247   1.5    bouyer 	lm_common_match(sc);
    248   1.5    bouyer 	return 1;
    249   1.5    bouyer }
    250   1.1      groo 
    251   1.1      groo int
    252   1.5    bouyer def_match(sc)
    253   1.5    bouyer 	struct lm_softc *sc;
    254   1.5    bouyer {
    255   1.5    bouyer 	int i;
    256   1.5    bouyer 
    257  1.17        ad 	i = (*sc->lm_readreg)(sc, LMD_CHIPID) & LM_ID_MASK;
    258  1.17        ad 	printf(": Unknown chip (ID %d)\n", i);
    259   1.5    bouyer 	lm_common_match(sc);
    260   1.5    bouyer 	return 1;
    261   1.5    bouyer }
    262   1.5    bouyer 
    263   1.5    bouyer void
    264   1.5    bouyer lm_common_match(sc)
    265   1.5    bouyer 	struct lm_softc *sc;
    266   1.1      groo {
    267   1.5    bouyer 	int i;
    268   1.5    bouyer 	sc->numsensors = LM_NUM_SENSORS;
    269   1.5    bouyer 	sc->refresh_sensor_data = lm_refresh_sensor_data;
    270   1.5    bouyer 
    271   1.5    bouyer 	for (i = 0; i < 7; ++i) {
    272   1.5    bouyer 		sc->sensors[i].units = sc->info[i].units =
    273   1.5    bouyer 		    ENVSYS_SVOLTS_DC;
    274  1.18    itojun 		snprintf(sc->info[i].desc, sizeof(sc->info[i].desc),
    275  1.18    itojun 		    "IN %d", i);
    276   1.5    bouyer 	}
    277   1.5    bouyer 
    278   1.5    bouyer 	/* default correction factors for resistors on higher voltage inputs */
    279   1.5    bouyer 	sc->info[0].rfact = sc->info[1].rfact =
    280   1.5    bouyer 	    sc->info[2].rfact = 10000;
    281   1.5    bouyer 	sc->info[3].rfact = (int)(( 90.9 / 60.4) * 10000);
    282   1.5    bouyer 	sc->info[4].rfact = (int)(( 38.0 / 10.0) * 10000);
    283   1.5    bouyer 	sc->info[5].rfact = (int)((210.0 / 60.4) * 10000);
    284   1.5    bouyer 	sc->info[6].rfact = (int)(( 90.9 / 60.4) * 10000);
    285   1.5    bouyer 
    286   1.5    bouyer 	sc->sensors[7].units = ENVSYS_STEMP;
    287   1.5    bouyer 	strcpy(sc->info[7].desc, "Temp");
    288   1.5    bouyer 
    289   1.8    bouyer 	setup_fan(sc, 8, 3);
    290   1.5    bouyer 	sc->sc_sysmon.sme_streinfo = lm_streinfo;
    291   1.5    bouyer }
    292   1.1      groo 
    293   1.5    bouyer int
    294   1.5    bouyer wb_match(sc)
    295   1.5    bouyer 	struct lm_softc *sc;
    296   1.5    bouyer {
    297   1.5    bouyer 	int i, j;
    298   1.1      groo 
    299  1.17        ad 	(*sc->lm_writereg)(sc, WB_BANKSEL, WB_BANKSEL_HBAC);
    300  1.17        ad 	j = (*sc->lm_readreg)(sc, WB_VENDID) << 8;
    301  1.17        ad 	(*sc->lm_writereg)(sc, WB_BANKSEL, 0);
    302  1.17        ad 	j |= (*sc->lm_readreg)(sc, WB_VENDID);
    303  1.11     veego 	DPRINTF(("winbond vend id 0x%x\n", j));
    304   1.5    bouyer 	if (j != WB_VENDID_WINBOND)
    305   1.5    bouyer 		return 0;
    306   1.7    bouyer 	/* read device ID */
    307  1.17        ad 	(*sc->lm_banksel)(sc, 0);
    308  1.17        ad 	j = (*sc->lm_readreg)(sc, WB_BANK0_CHIPID);
    309  1.11     veego 	DPRINTF(("winbond chip id 0x%x\n", j));
    310   1.7    bouyer 	switch(j) {
    311   1.7    bouyer 	case WB_CHIPID_83781:
    312  1.10    bouyer 	case WB_CHIPID_83781_2:
    313   1.7    bouyer 		printf(": W83781D\n");
    314   1.7    bouyer 
    315   1.7    bouyer 		for (i = 0; i < 7; ++i) {
    316   1.7    bouyer 			sc->sensors[i].units = sc->info[i].units =
    317   1.7    bouyer 			    ENVSYS_SVOLTS_DC;
    318  1.18    itojun 			snprintf(sc->info[i].desc, sizeof(sc->info[i].desc),
    319  1.18    itojun 			    "IN %d", i);
    320   1.7    bouyer 		}
    321   1.7    bouyer 
    322   1.7    bouyer 		/* default correction factors for higher voltage inputs */
    323   1.7    bouyer 		sc->info[0].rfact = sc->info[1].rfact =
    324   1.7    bouyer 		    sc->info[2].rfact = 10000;
    325   1.7    bouyer 		sc->info[3].rfact = (int)(( 90.9 / 60.4) * 10000);
    326   1.7    bouyer 		sc->info[4].rfact = (int)(( 38.0 / 10.0) * 10000);
    327   1.7    bouyer 		sc->info[5].rfact = (int)((210.0 / 60.4) * 10000);
    328   1.7    bouyer 		sc->info[6].rfact = (int)(( 90.9 / 60.4) * 10000);
    329   1.7    bouyer 
    330   1.9    bouyer 		setup_temp(sc, 7, 3);
    331   1.9    bouyer 		setup_fan(sc, 10, 3);
    332   1.7    bouyer 
    333   1.9    bouyer 		sc->numsensors = WB83781_NUM_SENSORS;
    334   1.9    bouyer 		sc->refresh_sensor_data = wb781_refresh_sensor_data;
    335   1.7    bouyer 		sc->sc_sysmon.sme_streinfo = wb781_streinfo;
    336   1.7    bouyer 		return 1;
    337   1.8    bouyer 	case WB_CHIPID_83697:
    338   1.8    bouyer 		printf(": W83697HF\n");
    339   1.8    bouyer 		wb_setup_volt(sc);
    340   1.8    bouyer 		setup_temp(sc, 9, 2);
    341   1.8    bouyer 		setup_fan(sc, 11, 3);
    342   1.8    bouyer 		sc->numsensors = WB83697_NUM_SENSORS;
    343   1.8    bouyer 		sc->refresh_sensor_data = wb697_refresh_sensor_data;
    344   1.8    bouyer 		sc->sc_sysmon.sme_streinfo = wb782_streinfo;
    345  1.17        ad 		return 1;
    346   1.7    bouyer 	case WB_CHIPID_83782:
    347   1.7    bouyer 		printf(": W83782D\n");
    348   1.7    bouyer 		break;
    349   1.7    bouyer 	case WB_CHIPID_83627:
    350   1.7    bouyer 		printf(": W83627HF\n");
    351   1.7    bouyer 		break;
    352  1.23   xtraeme 	case WB_CHIPID_83627THF:
    353  1.23   xtraeme 		printf(": W83627THF\n");
    354  1.23   xtraeme 		break;
    355   1.7    bouyer 	default:
    356   1.7    bouyer 		printf(": unknow winbond chip ID 0x%x\n", j);
    357   1.7    bouyer 		/* handle as a standart lm7x */
    358   1.7    bouyer 		lm_common_match(sc);
    359   1.7    bouyer 		return 1;
    360   1.7    bouyer 	}
    361   1.8    bouyer 	/* common code for the W83782D and W83627HF */
    362   1.8    bouyer 	wb_setup_volt(sc);
    363   1.8    bouyer 	setup_temp(sc, 9, 3);
    364   1.8    bouyer 	setup_fan(sc, 12, 3);
    365   1.5    bouyer 	sc->numsensors = WB_NUM_SENSORS;
    366   1.7    bouyer 	sc->refresh_sensor_data = wb782_refresh_sensor_data;
    367   1.8    bouyer 	sc->sc_sysmon.sme_streinfo = wb782_streinfo;
    368   1.8    bouyer 	return 1;
    369   1.8    bouyer }
    370   1.5    bouyer 
    371   1.8    bouyer static void
    372   1.8    bouyer wb_setup_volt(sc)
    373   1.8    bouyer 	struct lm_softc *sc;
    374   1.8    bouyer {
    375   1.5    bouyer 	sc->sensors[0].units = sc->info[0].units = ENVSYS_SVOLTS_DC;
    376  1.18    itojun 	snprintf(sc->info[0].desc, sizeof(sc->info[0].desc), "VCORE A");
    377   1.5    bouyer 	sc->info[0].rfact = 10000;
    378   1.5    bouyer 	sc->sensors[1].units = sc->info[1].units = ENVSYS_SVOLTS_DC;
    379  1.18    itojun 	snprintf(sc->info[1].desc, sizeof(sc->info[1].desc), "VCORE B");
    380   1.5    bouyer 	sc->info[1].rfact = 10000;
    381   1.5    bouyer 	sc->sensors[2].units = sc->info[2].units = ENVSYS_SVOLTS_DC;
    382  1.18    itojun 	snprintf(sc->info[2].desc, sizeof(sc->info[2].desc), "+3.3V");
    383   1.5    bouyer 	sc->info[2].rfact = 10000;
    384   1.5    bouyer 	sc->sensors[3].units = sc->info[3].units = ENVSYS_SVOLTS_DC;
    385  1.18    itojun 	snprintf(sc->info[3].desc, sizeof(sc->info[3].desc), "+5V");
    386   1.5    bouyer 	sc->info[3].rfact = 16778;
    387   1.5    bouyer 	sc->sensors[4].units = sc->info[4].units = ENVSYS_SVOLTS_DC;
    388  1.18    itojun 	snprintf(sc->info[4].desc, sizeof(sc->info[4].desc), "+12V");
    389   1.5    bouyer 	sc->info[4].rfact = 38000;
    390   1.5    bouyer 	sc->sensors[5].units = sc->info[5].units = ENVSYS_SVOLTS_DC;
    391  1.18    itojun 	snprintf(sc->info[5].desc, sizeof(sc->info[5].desc), "-12V");
    392   1.5    bouyer 	sc->info[5].rfact = 10000;
    393   1.5    bouyer 	sc->sensors[6].units = sc->info[6].units = ENVSYS_SVOLTS_DC;
    394  1.18    itojun 	snprintf(sc->info[6].desc, sizeof(sc->info[6].desc), "-5V");
    395   1.5    bouyer 	sc->info[6].rfact = 10000;
    396   1.5    bouyer 	sc->sensors[7].units = sc->info[7].units = ENVSYS_SVOLTS_DC;
    397  1.18    itojun 	snprintf(sc->info[7].desc, sizeof(sc->info[7].desc), "+5VSB");
    398   1.5    bouyer 	sc->info[7].rfact = 15151;
    399   1.5    bouyer 	sc->sensors[8].units = sc->info[8].units = ENVSYS_SVOLTS_DC;
    400  1.18    itojun 	snprintf(sc->info[8].desc, sizeof(sc->info[8].desc), "VBAT");
    401   1.5    bouyer 	sc->info[8].rfact = 10000;
    402   1.8    bouyer }
    403   1.8    bouyer 
    404   1.8    bouyer static void
    405   1.8    bouyer setup_temp(sc, start, n)
    406   1.8    bouyer 	struct lm_softc *sc;
    407   1.8    bouyer 	int start, n;
    408   1.8    bouyer {
    409   1.8    bouyer 	int i;
    410   1.5    bouyer 
    411   1.8    bouyer 	for (i = 0; i < n; i++) {
    412   1.8    bouyer 		sc->sensors[start + i].units = ENVSYS_STEMP;
    413  1.18    itojun 		snprintf(sc->info[start + i].desc,
    414  1.18    itojun 		    sizeof(sc->info[start + i].desc), "Temp %d", i + 1);
    415   1.8    bouyer 	}
    416   1.8    bouyer }
    417   1.8    bouyer 
    418   1.8    bouyer 
    419   1.8    bouyer static void
    420   1.8    bouyer setup_fan(sc, start, n)
    421   1.8    bouyer 	struct lm_softc *sc;
    422   1.8    bouyer 	int start, n;
    423   1.8    bouyer {
    424   1.8    bouyer 	int i;
    425   1.8    bouyer 	for (i = 0; i < n; ++i) {
    426   1.8    bouyer 		sc->sensors[start + i].units = ENVSYS_SFANRPM;
    427   1.8    bouyer 		sc->info[start + i].units = ENVSYS_SFANRPM;
    428  1.18    itojun 		snprintf(sc->info[start + i].desc,
    429  1.18    itojun 		    sizeof(sc->info[start + i].desc), "Fan %d", i + 1);
    430   1.5    bouyer 	}
    431   1.1      groo }
    432   1.1      groo 
    433   1.5    bouyer int
    434   1.5    bouyer lm_gtredata(sme, tred)
    435   1.5    bouyer 	 struct sysmon_envsys *sme;
    436   1.5    bouyer 	 struct envsys_tre_data *tred;
    437   1.5    bouyer {
    438  1.26    kardel 	static const struct timeval onepointfive = { 1, 500000 };
    439  1.26    kardel 	struct timeval t, utv;
    440  1.26    kardel 	struct lm_softc *sc = sme->sme_cookie;
    441  1.26    kardel 
    442  1.26    kardel 	/* read new values at most once every 1.5 seconds */
    443  1.26    kardel 	getmicrouptime(&utv);
    444  1.26    kardel 	timeradd(&sc->lastread, &onepointfive, &t);
    445  1.26    kardel 	if (timercmp(&utv, &t, >)) {
    446  1.26    kardel 		sc->lastread = utv;
    447  1.26    kardel 		sc->refresh_sensor_data(sc);
    448  1.27   hannken 	}
    449   1.5    bouyer 
    450  1.26    kardel 	*tred = sc->sensors[tred->sensor];
    451   1.5    bouyer 
    452  1.26    kardel 	return 0;
    453   1.5    bouyer }
    454   1.1      groo 
    455   1.1      groo int
    456   1.7    bouyer generic_streinfo_fan(sc, info, n, binfo)
    457   1.7    bouyer 	struct lm_softc *sc;
    458   1.7    bouyer 	struct envsys_basic_info *info;
    459   1.7    bouyer 	int n;
    460   1.7    bouyer 	struct envsys_basic_info *binfo;
    461   1.7    bouyer {
    462   1.7    bouyer 	u_int8_t sdata;
    463   1.7    bouyer 	int divisor;
    464   1.7    bouyer 
    465   1.7    bouyer 	/* FAN1 and FAN2 can have divisors set, but not FAN3 */
    466   1.7    bouyer 	if ((sc->info[binfo->sensor].units == ENVSYS_SFANRPM)
    467  1.14      tron 	    && (n < 2)) {
    468   1.7    bouyer 		if (binfo->rpms == 0) {
    469   1.7    bouyer 			binfo->validflags = 0;
    470  1.19  christos 			return 0;
    471   1.7    bouyer 		}
    472   1.7    bouyer 
    473  1.14      tron 		/* write back the nominal FAN speed  */
    474  1.14      tron 		info->rpms = binfo->rpms;
    475  1.14      tron 
    476   1.7    bouyer 		/* 153 is the nominal FAN speed value */
    477   1.7    bouyer 		divisor = 1350000 / (binfo->rpms * 153);
    478   1.7    bouyer 
    479   1.7    bouyer 		/* ...but we need lg(divisor) */
    480   1.7    bouyer 		if (divisor <= 1)
    481   1.7    bouyer 		    divisor = 0;
    482   1.7    bouyer 		else if (divisor <= 2)
    483   1.7    bouyer 		    divisor = 1;
    484   1.7    bouyer 		else if (divisor <= 4)
    485   1.7    bouyer 		    divisor = 2;
    486   1.7    bouyer 		else
    487   1.7    bouyer 		    divisor = 3;
    488   1.7    bouyer 
    489   1.7    bouyer 		/*
    490   1.7    bouyer 		 * FAN1 div is in bits <5:4>, FAN2 div is
    491   1.7    bouyer 		 * in <7:6>
    492   1.7    bouyer 		 */
    493  1.17        ad 		sdata = (*sc->lm_readreg)(sc, LMD_VIDFAN);
    494  1.14      tron 		if ( n == 0 ) {  /* FAN1 */
    495   1.7    bouyer 		    divisor <<= 4;
    496   1.7    bouyer 		    sdata = (sdata & 0xCF) | divisor;
    497   1.7    bouyer 		} else { /* FAN2 */
    498   1.7    bouyer 		    divisor <<= 6;
    499   1.7    bouyer 		    sdata = (sdata & 0x3F) | divisor;
    500   1.7    bouyer 		}
    501   1.7    bouyer 
    502  1.17        ad 		(*sc->lm_writereg)(sc, LMD_VIDFAN, sdata);
    503   1.7    bouyer 	}
    504  1.19  christos 	return 0;
    505   1.7    bouyer 
    506   1.7    bouyer }
    507   1.7    bouyer 
    508   1.7    bouyer int
    509   1.4   thorpej lm_streinfo(sme, binfo)
    510   1.5    bouyer 	 struct sysmon_envsys *sme;
    511   1.5    bouyer 	 struct envsys_basic_info *binfo;
    512   1.1      groo {
    513   1.5    bouyer 	 struct lm_softc *sc = sme->sme_cookie;
    514   1.5    bouyer 
    515   1.5    bouyer 	 if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
    516   1.5    bouyer 		  sc->info[binfo->sensor].rfact = binfo->rfact;
    517   1.5    bouyer 	 else {
    518   1.7    bouyer 		if (sc->info[binfo->sensor].units == ENVSYS_SFANRPM) {
    519   1.7    bouyer 			generic_streinfo_fan(sc, &sc->info[binfo->sensor],
    520   1.7    bouyer 			    binfo->sensor - 8, binfo);
    521   1.7    bouyer 		}
    522  1.19  christos 		strlcpy(sc->info[binfo->sensor].desc, binfo->desc,
    523   1.7    bouyer 		    sizeof(sc->info[binfo->sensor].desc));
    524   1.7    bouyer 		binfo->validflags = ENVSYS_FVALID;
    525   1.7    bouyer 	 }
    526  1.19  christos 	 return 0;
    527   1.7    bouyer }
    528   1.5    bouyer 
    529   1.7    bouyer int
    530   1.7    bouyer wb781_streinfo(sme, binfo)
    531   1.7    bouyer 	 struct sysmon_envsys *sme;
    532   1.7    bouyer 	 struct envsys_basic_info *binfo;
    533   1.7    bouyer {
    534   1.7    bouyer 	 struct lm_softc *sc = sme->sme_cookie;
    535  1.14      tron 	 int divisor;
    536  1.14      tron 	 u_int8_t sdata;
    537  1.14      tron 	 int i;
    538   1.5    bouyer 
    539   1.7    bouyer 	 if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
    540   1.7    bouyer 		  sc->info[binfo->sensor].rfact = binfo->rfact;
    541   1.7    bouyer 	 else {
    542   1.7    bouyer 		if (sc->info[binfo->sensor].units == ENVSYS_SFANRPM) {
    543  1.14      tron 			if (binfo->rpms == 0) {
    544  1.14      tron 				binfo->validflags = 0;
    545  1.19  christos 				return 0;
    546  1.14      tron 			}
    547  1.14      tron 
    548  1.14      tron 			/* write back the nominal FAN speed  */
    549  1.14      tron 			sc->info[binfo->sensor].rpms = binfo->rpms;
    550  1.14      tron 
    551  1.14      tron 			/* 153 is the nominal FAN speed value */
    552  1.14      tron 			divisor = 1350000 / (binfo->rpms * 153);
    553  1.14      tron 
    554  1.14      tron 			/* ...but we need lg(divisor) */
    555  1.14      tron 			for (i = 0; i < 7; i++) {
    556  1.14      tron 				if (divisor <= (1 << i))
    557  1.14      tron 				 	break;
    558  1.14      tron 			}
    559  1.14      tron 			divisor = i;
    560  1.14      tron 
    561  1.14      tron 			if (binfo->sensor == 10 || binfo->sensor == 11) {
    562  1.14      tron 				/*
    563  1.14      tron 				 * FAN1 div is in bits <5:4>, FAN2 div
    564  1.14      tron 				 * is in <7:6>
    565  1.14      tron 				 */
    566  1.17        ad 				sdata = (*sc->lm_readreg)(sc, LMD_VIDFAN);
    567  1.14      tron 				if ( binfo->sensor == 10 ) {  /* FAN1 */
    568  1.14      tron 					 sdata = (sdata & 0xCF) |
    569  1.14      tron 					     ((divisor & 0x3) << 4);
    570  1.14      tron 				} else { /* FAN2 */
    571  1.14      tron 					 sdata = (sdata & 0x3F) |
    572  1.14      tron 					     ((divisor & 0x3) << 6);
    573  1.14      tron 				}
    574  1.17        ad 				(*sc->lm_writereg)(sc, LMD_VIDFAN, sdata);
    575  1.14      tron 			} else {
    576  1.14      tron 				/* FAN3 is in WB_PIN <7:6> */
    577  1.17        ad 				sdata = (*sc->lm_readreg)(sc, WB_PIN);
    578  1.14      tron 				sdata = (sdata & 0x3F) |
    579  1.14      tron 				     ((divisor & 0x3) << 6);
    580  1.17        ad 				(*sc->lm_writereg)(sc, WB_PIN, sdata);
    581  1.14      tron 			}
    582   1.7    bouyer 		}
    583  1.19  christos 		strlcpy(sc->info[binfo->sensor].desc, binfo->desc,
    584   1.7    bouyer 		    sizeof(sc->info[binfo->sensor].desc));
    585   1.7    bouyer 		binfo->validflags = ENVSYS_FVALID;
    586   1.5    bouyer 	 }
    587  1.19  christos 	 return 0;
    588   1.5    bouyer }
    589   1.5    bouyer 
    590   1.5    bouyer int
    591   1.7    bouyer wb782_streinfo(sme, binfo)
    592   1.5    bouyer 	 struct sysmon_envsys *sme;
    593   1.5    bouyer 	 struct envsys_basic_info *binfo;
    594   1.5    bouyer {
    595   1.5    bouyer 	 struct lm_softc *sc = sme->sme_cookie;
    596   1.5    bouyer 	 int divisor;
    597   1.5    bouyer 	 u_int8_t sdata;
    598   1.5    bouyer 	 int i;
    599   1.5    bouyer 
    600   1.5    bouyer 	 if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
    601   1.5    bouyer 		  sc->info[binfo->sensor].rfact = binfo->rfact;
    602   1.5    bouyer 	 else {
    603   1.5    bouyer 	 	if (sc->info[binfo->sensor].units == ENVSYS_SFANRPM) {
    604   1.4   thorpej 			if (binfo->rpms == 0) {
    605   1.4   thorpej 				binfo->validflags = 0;
    606  1.19  christos 				return 0;
    607   1.1      groo 			}
    608   1.1      groo 
    609  1.14      tron 			/* write back the nominal FAN speed  */
    610  1.14      tron 			sc->info[binfo->sensor].rpms = binfo->rpms;
    611  1.14      tron 
    612   1.4   thorpej 			/* 153 is the nominal FAN speed value */
    613   1.4   thorpej 			divisor = 1350000 / (binfo->rpms * 153);
    614   1.1      groo 
    615   1.4   thorpej 			/* ...but we need lg(divisor) */
    616   1.5    bouyer 			for (i = 0; i < 7; i++) {
    617   1.5    bouyer 				if (divisor <= (1 << i))
    618   1.5    bouyer 				 	break;
    619   1.5    bouyer 			}
    620   1.5    bouyer 			divisor = i;
    621   1.4   thorpej 
    622   1.5    bouyer 			if (binfo->sensor == 12 || binfo->sensor == 13) {
    623   1.5    bouyer 				/*
    624   1.5    bouyer 				 * FAN1 div is in bits <5:4>, FAN2 div
    625   1.5    bouyer 				 * is in <7:6>
    626   1.5    bouyer 				 */
    627  1.17        ad 				sdata = (*sc->lm_readreg)(sc, LMD_VIDFAN);
    628   1.5    bouyer 				if ( binfo->sensor == 12 ) {  /* FAN1 */
    629   1.5    bouyer 					 sdata = (sdata & 0xCF) |
    630   1.5    bouyer 					     ((divisor & 0x3) << 4);
    631   1.5    bouyer 				} else { /* FAN2 */
    632   1.5    bouyer 					 sdata = (sdata & 0x3F) |
    633   1.5    bouyer 					     ((divisor & 0x3) << 6);
    634   1.5    bouyer 				}
    635  1.17        ad 				(*sc->lm_writereg)(sc, LMD_VIDFAN, sdata);
    636   1.5    bouyer 			} else {
    637   1.5    bouyer 				/* FAN3 is in WB_PIN <7:6> */
    638  1.17        ad 				sdata = (*sc->lm_readreg)(sc, WB_PIN);
    639   1.5    bouyer 				sdata = (sdata & 0x3F) |
    640   1.5    bouyer 				     ((divisor & 0x3) << 6);
    641  1.17        ad 				(*sc->lm_writereg)(sc, WB_PIN, sdata);
    642   1.1      groo 			}
    643   1.5    bouyer 			/* Bit 2 of divisor is in WB_BANK0_FANBAT */
    644  1.17        ad 			(*sc->lm_banksel)(sc, 0);
    645  1.17        ad 			sdata = (*sc->lm_readreg)(sc, WB_BANK0_FANBAT);
    646   1.5    bouyer 			sdata &= ~(0x20 << (binfo->sensor - 12));
    647   1.5    bouyer 			sdata |= (divisor & 0x4) << (binfo->sensor - 9);
    648  1.17        ad 			(*sc->lm_writereg)(sc, WB_BANK0_FANBAT, sdata);
    649   1.1      groo 		}
    650   1.1      groo 
    651  1.19  christos 		strlcpy(sc->info[binfo->sensor].desc, binfo->desc,
    652   1.4   thorpej 		    sizeof(sc->info[binfo->sensor].desc));
    653  1.19  christos 		binfo->validflags = ENVSYS_FVALID;
    654  1.19  christos 	}
    655  1.19  christos 	return 0;
    656  1.19  christos }
    657  1.19  christos 
    658   1.8    bouyer static void
    659   1.7    bouyer generic_stemp(sc, sensor)
    660   1.7    bouyer 	struct lm_softc *sc;
    661   1.7    bouyer 	struct envsys_tre_data *sensor;
    662   1.7    bouyer {
    663  1.17        ad 	int sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + 7);
    664  1.10    bouyer 	DPRINTF(("sdata[temp] 0x%x\n", sdata));
    665   1.7    bouyer 	/* temp is given in deg. C, we convert to uK */
    666   1.7    bouyer 	sensor->cur.data_us = sdata * 1000000 + 273150000;
    667   1.7    bouyer }
    668   1.7    bouyer 
    669   1.8    bouyer static void
    670   1.7    bouyer generic_svolt(sc, sensors, infos)
    671   1.7    bouyer 	struct lm_softc *sc;
    672   1.7    bouyer 	struct envsys_tre_data *sensors;
    673   1.7    bouyer 	struct envsys_basic_info *infos;
    674   1.7    bouyer {
    675   1.7    bouyer 	int i, sdata;
    676   1.7    bouyer 
    677   1.7    bouyer 	for (i = 0; i < 7; i++) {
    678  1.17        ad 		sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + i);
    679  1.10    bouyer 		DPRINTF(("sdata[volt%d] 0x%x\n", i, sdata));
    680   1.7    bouyer 		/* voltage returned as (mV >> 4), we convert to uVDC */
    681   1.7    bouyer 		sensors[i].cur.data_s = (sdata << 4);
    682   1.7    bouyer 		/* rfact is (factor * 10^4) */
    683   1.7    bouyer 		sensors[i].cur.data_s *= infos[i].rfact;
    684   1.7    bouyer 		/* division by 10 gets us back to uVDC */
    685   1.7    bouyer 		sensors[i].cur.data_s /= 10;
    686   1.7    bouyer 
    687   1.7    bouyer 		/* these two are negative voltages */
    688   1.7    bouyer 		if ( (i == 5) || (i == 6) )
    689   1.7    bouyer 			sensors[i].cur.data_s *= -1;
    690   1.7    bouyer 	}
    691   1.7    bouyer }
    692   1.7    bouyer 
    693   1.8    bouyer static void
    694   1.7    bouyer generic_fanrpm(sc, sensors)
    695   1.7    bouyer 	struct lm_softc *sc;
    696   1.7    bouyer 	struct envsys_tre_data *sensors;
    697   1.7    bouyer {
    698   1.7    bouyer 	int i, sdata, divisor;
    699   1.7    bouyer 	for (i = 0; i < 3; i++) {
    700  1.17        ad 		sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + 8 + i);
    701  1.10    bouyer 		DPRINTF(("sdata[fan%d] 0x%x\n", i, sdata));
    702   1.7    bouyer 		if (i == 2)
    703   1.7    bouyer 			divisor = 2;	/* Fixed divisor for FAN3 */
    704   1.7    bouyer 		else if (i == 1)	/* Bits 7 & 6 of VID/FAN  */
    705  1.17        ad 			divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 6) & 0x3;
    706   1.7    bouyer 		else
    707  1.17        ad 			divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 4) & 0x3;
    708   1.7    bouyer 
    709   1.7    bouyer 		if (sdata == 0xff || sdata == 0x00) {
    710   1.7    bouyer 			sensors[i].cur.data_us = 0;
    711   1.7    bouyer 		} else {
    712   1.7    bouyer 			sensors[i].cur.data_us = 1350000 / (sdata << divisor);
    713   1.7    bouyer 		}
    714   1.7    bouyer 	}
    715   1.7    bouyer }
    716   1.7    bouyer 
    717   1.1      groo /*
    718  1.12       wiz  * pre:  last read occurred >= 1.5 seconds ago
    719   1.1      groo  * post: sensors[] current data are the latest from the chip
    720   1.1      groo  */
    721   1.1      groo void
    722   1.1      groo lm_refresh_sensor_data(sc)
    723   1.1      groo 	struct lm_softc *sc;
    724   1.1      groo {
    725   1.7    bouyer 	/* Refresh our stored data for every sensor */
    726   1.7    bouyer 	generic_stemp(sc, &sc->sensors[7]);
    727   1.7    bouyer 	generic_svolt(sc, &sc->sensors[0], &sc->info[0]);
    728   1.7    bouyer 	generic_fanrpm(sc, &sc->sensors[8]);
    729   1.7    bouyer }
    730   1.7    bouyer 
    731   1.8    bouyer static void
    732   1.8    bouyer wb_svolt(sc)
    733   1.7    bouyer 	struct lm_softc *sc;
    734   1.7    bouyer {
    735   1.8    bouyer 	int i, sdata;
    736   1.5    bouyer 	for (i = 0; i < 9; ++i) {
    737   1.5    bouyer 		if (i < 7) {
    738  1.17        ad 			sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + i);
    739   1.5    bouyer 		} else {
    740   1.5    bouyer 			/* from bank5 */
    741  1.17        ad 			(*sc->lm_banksel)(sc, 5);
    742  1.17        ad 			sdata = (*sc->lm_readreg)(sc, (i == 7) ?
    743   1.5    bouyer 			    WB_BANK5_5VSB : WB_BANK5_VBAT);
    744   1.5    bouyer 		}
    745  1.10    bouyer 		DPRINTF(("sdata[volt%d] 0x%x\n", i, sdata));
    746   1.5    bouyer 		/* voltage returned as (mV >> 4), we convert to uV */
    747   1.5    bouyer 		sdata =  sdata << 4;
    748   1.5    bouyer 		/* special case for negative voltages */
    749   1.5    bouyer 		if (i == 5) {
    750   1.5    bouyer 			/*
    751   1.5    bouyer 			 * -12Vdc, assume Winbond recommended values for
    752   1.5    bouyer 			 * resistors
    753   1.5    bouyer 			 */
    754   1.5    bouyer 			sdata = ((sdata * 1000) - (3600 * 805)) / 195;
    755   1.5    bouyer 		} else if (i == 6) {
    756   1.5    bouyer 			/*
    757   1.5    bouyer 			 * -5Vdc, assume Winbond recommended values for
    758   1.5    bouyer 			 * resistors
    759   1.5    bouyer 			 */
    760   1.5    bouyer 			sdata = ((sdata * 1000) - (3600 * 682)) / 318;
    761   1.5    bouyer 		}
    762   1.5    bouyer 		/* rfact is (factor * 10^4) */
    763   1.5    bouyer 		sc->sensors[i].cur.data_s = sdata * sc->info[i].rfact;
    764   1.5    bouyer 		/* division by 10 gets us back to uVDC */
    765   1.5    bouyer 		sc->sensors[i].cur.data_s /= 10;
    766   1.5    bouyer 	}
    767   1.8    bouyer }
    768   1.5    bouyer 
    769   1.8    bouyer static void
    770   1.8    bouyer wb_stemp(sc, sensors, n)
    771   1.8    bouyer 	struct lm_softc *sc;
    772   1.8    bouyer 	struct  envsys_tre_data *sensors;
    773   1.8    bouyer 	int n;
    774   1.8    bouyer {
    775   1.8    bouyer 	int sdata;
    776   1.8    bouyer 	/* temperatures. Given in dC, we convert to uK */
    777  1.17        ad 	sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + 7);
    778  1.10    bouyer 	DPRINTF(("sdata[temp0] 0x%x\n", sdata));
    779   1.8    bouyer 	sensors[0].cur.data_us = sdata * 1000000 + 273150000;
    780   1.8    bouyer 	/* from bank1 */
    781  1.17        ad 	if ((*sc->lm_banksel)(sc, 1))
    782  1.17        ad 		sensors[1].validflags &= ~ENVSYS_FCURVALID;
    783  1.17        ad 	else {
    784  1.17        ad 		sdata = (*sc->lm_readreg)(sc, WB_BANK1_T2H) << 1;
    785  1.17        ad 		sdata |=  ((*sc->lm_readreg)(sc, WB_BANK1_T2L) & 0x80) >> 7;
    786  1.17        ad 		DPRINTF(("sdata[temp1] 0x%x\n", sdata));
    787  1.17        ad 		sensors[1].cur.data_us = (sdata * 1000000) / 2 + 273150000;
    788  1.17        ad 	}
    789   1.8    bouyer 	if (n < 3)
    790   1.8    bouyer 		return;
    791   1.8    bouyer 	/* from bank2 */
    792  1.17        ad 	if ((*sc->lm_banksel)(sc, 2))
    793  1.17        ad 		sensors[2].validflags &= ~ENVSYS_FCURVALID;
    794  1.17        ad 	else {
    795  1.17        ad 		sdata = (*sc->lm_readreg)(sc, WB_BANK2_T3H) << 1;
    796  1.17        ad 		sdata |=  ((*sc->lm_readreg)(sc, WB_BANK2_T3L) & 0x80) >> 7;
    797  1.17        ad 		DPRINTF(("sdata[temp2] 0x%x\n", sdata));
    798  1.17        ad 		sensors[2].cur.data_us = (sdata * 1000000) / 2 + 273150000;
    799  1.17        ad 	}
    800   1.8    bouyer }
    801   1.8    bouyer 
    802   1.8    bouyer static void
    803  1.14      tron wb781_fanrpm(sc, sensors)
    804  1.14      tron 	struct lm_softc *sc;
    805  1.14      tron 	struct envsys_tre_data *sensors;
    806  1.14      tron {
    807  1.14      tron 	int i, divisor, sdata;
    808  1.17        ad 	(*sc->lm_banksel)(sc, 0);
    809  1.14      tron 	for (i = 0; i < 3; i++) {
    810  1.17        ad 		sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + i + 8);
    811  1.14      tron 		DPRINTF(("sdata[fan%d] 0x%x\n", i, sdata));
    812  1.14      tron 		if (i == 0)
    813  1.17        ad 			divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 4) & 0x3;
    814  1.14      tron 		else if (i == 1)
    815  1.17        ad 			divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 6) & 0x3;
    816  1.14      tron 		else
    817  1.17        ad 			divisor = ((*sc->lm_readreg)(sc, WB_PIN) >> 6) & 0x3;
    818  1.14      tron 
    819  1.14      tron 		DPRINTF(("sdata[%d] 0x%x div 0x%x\n", i, sdata, divisor));
    820  1.14      tron 		if (sdata == 0xff || sdata == 0x00) {
    821  1.14      tron 			sensors[i].cur.data_us = 0;
    822  1.14      tron 		} else {
    823  1.14      tron 			sensors[i].cur.data_us = 1350000 /
    824  1.14      tron 			    (sdata << divisor);
    825  1.14      tron 		}
    826  1.14      tron 	}
    827  1.14      tron }
    828  1.14      tron 
    829  1.14      tron static void
    830   1.8    bouyer wb_fanrpm(sc, sensors)
    831   1.8    bouyer 	struct lm_softc *sc;
    832   1.8    bouyer 	struct envsys_tre_data *sensors;
    833   1.8    bouyer {
    834   1.8    bouyer 	int i, divisor, sdata;
    835  1.17        ad 	(*sc->lm_banksel)(sc, 0);
    836   1.8    bouyer 	for (i = 0; i < 3; i++) {
    837  1.17        ad 		sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + i + 8);
    838  1.10    bouyer 		DPRINTF(("sdata[fan%d] 0x%x\n", i, sdata));
    839   1.8    bouyer 		if (i == 0)
    840  1.17        ad 			divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 4) & 0x3;
    841   1.8    bouyer 		else if (i == 1)
    842  1.17        ad 			divisor = ((*sc->lm_readreg)(sc, LMD_VIDFAN) >> 6) & 0x3;
    843   1.5    bouyer 		else
    844  1.17        ad 			divisor = ((*sc->lm_readreg)(sc, WB_PIN) >> 6) & 0x3;
    845  1.17        ad 		divisor |= ((*sc->lm_readreg)(sc, WB_BANK0_FANBAT) >> (i + 3)) & 0x4;
    846   1.5    bouyer 
    847   1.5    bouyer 		DPRINTF(("sdata[%d] 0x%x div 0x%x\n", i, sdata, divisor));
    848   1.5    bouyer 		if (sdata == 0xff || sdata == 0x00) {
    849   1.8    bouyer 			sensors[i].cur.data_us = 0;
    850   1.5    bouyer 		} else {
    851   1.8    bouyer 			sensors[i].cur.data_us = 1350000 /
    852   1.5    bouyer 			    (sdata << divisor);
    853   1.1      groo 		}
    854   1.1      groo 	}
    855   1.8    bouyer }
    856   1.8    bouyer 
    857   1.8    bouyer void
    858   1.8    bouyer wb781_refresh_sensor_data(sc)
    859   1.8    bouyer 	struct lm_softc *sc;
    860   1.8    bouyer {
    861   1.8    bouyer 	/* Refresh our stored data for every sensor */
    862   1.9    bouyer 	/* we need to reselect bank0 to access common registers */
    863  1.17        ad 	(*sc->lm_banksel)(sc, 0);
    864   1.8    bouyer 	generic_svolt(sc, &sc->sensors[0], &sc->info[0]);
    865  1.17        ad 	(*sc->lm_banksel)(sc, 0);
    866   1.8    bouyer 	wb_stemp(sc, &sc->sensors[7], 3);
    867  1.17        ad 	(*sc->lm_banksel)(sc, 0);
    868  1.14      tron 	wb781_fanrpm(sc, &sc->sensors[10]);
    869   1.8    bouyer }
    870   1.8    bouyer 
    871   1.8    bouyer void
    872   1.8    bouyer wb782_refresh_sensor_data(sc)
    873   1.8    bouyer 	struct lm_softc *sc;
    874   1.8    bouyer {
    875   1.8    bouyer 	/* Refresh our stored data for every sensor */
    876   1.8    bouyer 	wb_svolt(sc);
    877   1.8    bouyer 	wb_stemp(sc, &sc->sensors[9], 3);
    878   1.8    bouyer 	wb_fanrpm(sc, &sc->sensors[12]);
    879   1.8    bouyer }
    880   1.8    bouyer 
    881   1.8    bouyer void
    882   1.8    bouyer wb697_refresh_sensor_data(sc)
    883   1.8    bouyer 	struct lm_softc *sc;
    884   1.8    bouyer {
    885   1.8    bouyer 	/* Refresh our stored data for every sensor */
    886   1.8    bouyer 	wb_svolt(sc);
    887   1.8    bouyer 	wb_stemp(sc, &sc->sensors[9], 2);
    888   1.8    bouyer 	wb_fanrpm(sc, &sc->sensors[11]);
    889   1.1      groo }
    890