There is no need to use a kthread to read the VIA environment

sensors.
This commit is contained in:
thorpej 2002-03-25 21:29:58 +00:00
parent 6d5da55a5a
commit 7c7c319cb3
2 changed files with 73 additions and 84 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: viaenv.c,v 1.5 2001/11/13 07:48:49 lukem Exp $ */ /* $NetBSD: viaenv.c,v 1.6 2002/03/25 21:29:58 thorpej Exp $ */
/* /*
* Copyright (c) 2000 Johan Danielsson * Copyright (c) 2000 Johan Danielsson
@ -35,7 +35,7 @@
/* driver for the hardware monitoring part of the VIA VT82C686A */ /* driver for the hardware monitoring part of the VIA VT82C686A */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: viaenv.c,v 1.5 2001/11/13 07:48:49 lukem Exp $"); __KERNEL_RCSID(0, "$NetBSD: viaenv.c,v 1.6 2002/03/25 21:29:58 thorpej Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -72,9 +72,8 @@ struct viaenv_softc {
struct envsys_tre_data sc_data[VIANUMSENSORS]; struct envsys_tre_data sc_data[VIANUMSENSORS];
struct envsys_basic_info sc_info[VIANUMSENSORS]; struct envsys_basic_info sc_info[VIANUMSENSORS];
struct proc *sc_thread; struct simplelock sc_slock;
struct timeval sc_lastread;
struct lock sc_lock;
struct sysmon_envsys sc_sysmon; struct sysmon_envsys sc_sysmon;
}; };
@ -207,74 +206,68 @@ val_to_uV(unsigned int val, int index)
static void static void
viaenv_thread(void *arg) viaenv_refresh_sensor_data(struct viaenv_softc *sc)
{ {
struct viaenv_softc *sc = arg; static const struct timeval onepointfive = { 1, 500000 };
struct timeval t;
u_int8_t v, v2; u_int8_t v, v2;
int i; int i, s;
while (1) { /* Read new values at most once every 1.5 seconds. */
lockmgr(&sc->sc_lock, LK_EXCLUSIVE, NULL); timeradd(&sc->sc_lastread, &onepointfive, &t);
s = splclock();
i = timercmp(&mono_time, &t, >);
if (i)
sc->sc_lastread = mono_time;
splx(s);
/* temperature */ if (i == 0)
v = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAENV_TIRQ); return;
v2 = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAENV_TSENS1);
DPRINTF(("TSENS1 = %d\n", (v2 << 2) | (v >> 6)));
sc->sc_data[0].cur.data_us = val_to_uK((v2 << 2) | (v >> 6));
sc->sc_data[0].validflags = ENVSYS_FVALID | ENVSYS_FCURVALID;
v = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAENV_TLOW); /* temperature */
v2 = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAENV_TSENS2); v = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAENV_TIRQ);
DPRINTF(("TSENS2 = %d\n", (v2 << 2) | ((v >> 4) & 0x3))); v2 = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAENV_TSENS1);
sc->sc_data[1].cur.data_us = DPRINTF(("TSENS1 = %d\n", (v2 << 2) | (v >> 6)));
val_to_uK((v2 << 2) | ((v >> 4) & 0x3)); sc->sc_data[0].cur.data_us = val_to_uK((v2 << 2) | (v >> 6));
sc->sc_data[1].validflags = ENVSYS_FVALID | ENVSYS_FCURVALID; sc->sc_data[0].validflags = ENVSYS_FVALID | ENVSYS_FCURVALID;
v2 = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAENV_TSENS3); v = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAENV_TLOW);
DPRINTF(("TSENS3 = %d\n", (v2 << 2) | (v >> 6))); v2 = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAENV_TSENS2);
sc->sc_data[2].cur.data_us = val_to_uK((v2 << 2) | (v >> 6)); DPRINTF(("TSENS2 = %d\n", (v2 << 2) | ((v >> 4) & 0x3)));
sc->sc_data[2].validflags = ENVSYS_FVALID | ENVSYS_FCURVALID; sc->sc_data[1].cur.data_us =
val_to_uK((v2 << 2) | ((v >> 4) & 0x3));
sc->sc_data[1].validflags = ENVSYS_FVALID | ENVSYS_FCURVALID;
v = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAENV_FANCONF); v2 = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAENV_TSENS3);
DPRINTF(("TSENS3 = %d\n", (v2 << 2) | (v >> 6)));
sc->sc_data[2].cur.data_us = val_to_uK((v2 << 2) | (v >> 6));
sc->sc_data[2].validflags = ENVSYS_FVALID | ENVSYS_FCURVALID;
sc->sc_fan_div[0] = 1 << ((v >> 4) & 0x3); v = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAENV_FANCONF);
sc->sc_fan_div[1] = 1 << ((v >> 6) & 0x3);
/* fan */ sc->sc_fan_div[0] = 1 << ((v >> 4) & 0x3);
for (i = 3; i <= 4; i++) { sc->sc_fan_div[1] = 1 << ((v >> 6) & 0x3);
v = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
VIAENV_FAN1 + i - 3);
DPRINTF(("FAN%d = %d / %d\n", i - 3, v,
sc->sc_fan_div[i - 3]));
sc->sc_data[i].cur.data_us = val_to_rpm(v,
sc->sc_fan_div[i - 3]);
sc->sc_data[i].validflags =
ENVSYS_FVALID | ENVSYS_FCURVALID;
}
/* voltage */ /* fan */
for (i = 5; i <= 9; i++) { for (i = 3; i <= 4; i++) {
v = bus_space_read_1(sc->sc_iot, sc->sc_ioh, v = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
VIAENV_VSENS1 + i - 5); VIAENV_FAN1 + i - 3);
DPRINTF(("V%d = %d\n", i - 5, v)); DPRINTF(("FAN%d = %d / %d\n", i - 3, v,
sc->sc_data[i].cur.data_us = val_to_uV(v, i - 5); sc->sc_fan_div[i - 3]));
sc->sc_data[i].validflags = sc->sc_data[i].cur.data_us = val_to_rpm(v,
ENVSYS_FVALID | ENVSYS_FCURVALID; sc->sc_fan_div[i - 3]);
} sc->sc_data[i].validflags =
ENVSYS_FVALID | ENVSYS_FCURVALID;
lockmgr(&sc->sc_lock, LK_RELEASE, NULL);
tsleep(sc, PWAIT, "viaenv", 3 * hz / 2);
} }
}
static void /* voltage */
viaenv_thread_create(void *arg) for (i = 5; i <= 9; i++) {
{ v = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
struct viaenv_softc *sc = arg; VIAENV_VSENS1 + i - 5);
DPRINTF(("V%d = %d\n", i - 5, v));
if (kthread_create1(viaenv_thread, sc, &sc->sc_thread, "%s", sc->sc_data[i].cur.data_us = val_to_uV(v, i - 5);
sc->sc_dev.dv_xname)) { sc->sc_data[i].validflags =
printf("%s: failed to create thread\n", sc->sc_dev.dv_xname); ENVSYS_FVALID | ENVSYS_FCURVALID;
} }
} }
@ -299,7 +292,7 @@ viaenv_attach(struct device * parent, struct device * self, void *aux)
} }
printf("\n"); printf("\n");
lockinit(&sc->sc_lock, PWAIT, "viaenv", 0, 0); simple_lock_init(&sc->sc_slock);
/* Initialize sensors */ /* Initialize sensors */
for (i = 0; i < VIANUMSENSORS; ++i) { for (i = 0; i < VIANUMSENSORS; ++i) {
@ -333,7 +326,8 @@ viaenv_attach(struct device * parent, struct device * self, void *aux)
strcpy(sc->sc_info[8].desc, "VSENS3"); /* VSENS3 (5V) */ strcpy(sc->sc_info[8].desc, "VSENS3"); /* VSENS3 (5V) */
strcpy(sc->sc_info[9].desc, "VSENS4"); /* VSENS4 (12V) */ strcpy(sc->sc_info[9].desc, "VSENS4"); /* VSENS4 (12V) */
kthread_create(viaenv_thread_create, sc); /* Get initial set of sensor values. */
viaenv_refresh_sensor_data(sc);
/* /*
* Hook into the System Monitor. * Hook into the System Monitor.
@ -359,9 +353,12 @@ viaenv_gtredata(struct sysmon_envsys *sme, struct envsys_tre_data *tred)
{ {
struct viaenv_softc *sc = sme->sme_cookie; struct viaenv_softc *sc = sme->sme_cookie;
(void) lockmgr(&sc->sc_lock, LK_SHARED, NULL); simple_lock(&sc->sc_slock);
viaenv_refresh_sensor_data(sc);
*tred = sc->sc_data[tred->sensor]; *tred = sc->sc_data[tred->sensor];
(void) lockmgr(&sc->sc_lock, LK_RELEASE, NULL);
simple_unlock(&sc->sc_slock);
return (0); return (0);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: viapm.c,v 1.3 2001/11/13 07:48:49 lukem Exp $ */ /* $NetBSD: viapm.c,v 1.4 2002/03/25 21:29:58 thorpej Exp $ */
/* /*
* Copyright (c) 2000 Johan Danielsson * Copyright (c) 2000 Johan Danielsson
@ -40,7 +40,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: viapm.c,v 1.3 2001/11/13 07:48:49 lukem Exp $"); __KERNEL_RCSID(0, "$NetBSD: viapm.c,v 1.4 2002/03/25 21:29:58 thorpej Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -77,7 +77,7 @@ viapm_device_name(enum vapm_devtype type)
{ {
switch (type) { switch (type) {
case VIAPM_POWER: case VIAPM_POWER:
return "power management"; return "power management";
case VIAPM_HWMON: case VIAPM_HWMON:
return "hardware monitor"; return "hardware monitor";
@ -106,11 +106,18 @@ viapm_submatch(struct device * parent, struct cfdata * cf, void *aux)
} }
static void static void
viapm_config_defer(struct device * self) viapm_attach(struct device * parent, struct device * self, void *aux)
{ {
struct viapm_softc *sc = (struct viapm_softc *) self; struct viapm_softc *sc = (struct viapm_softc *) self;
struct pci_attach_args *pa = aux;
struct viapm_attach_args vaa; struct viapm_attach_args vaa;
printf("\n");
sc->sc_pc = pa->pa_pc;
sc->sc_tag = pa->pa_tag;
sc->sc_iot = pa->pa_iot;
vaa.va_pc = sc->sc_pc; vaa.va_pc = sc->sc_pc;
vaa.va_tag = sc->sc_tag; vaa.va_tag = sc->sc_tag;
vaa.va_iot = sc->sc_iot; vaa.va_iot = sc->sc_iot;
@ -136,21 +143,6 @@ viapm_config_defer(struct device * self)
#endif #endif
} }
static void
viapm_attach(struct device * parent, struct device * self, void *aux)
{
struct viapm_softc *sc = (struct viapm_softc *) self;
struct pci_attach_args *pa = aux;
printf("\n");
sc->sc_pc = pa->pa_pc;
sc->sc_tag = pa->pa_tag;
sc->sc_iot = pa->pa_iot;
config_defer(self, viapm_config_defer);
}
struct cfattach viapm_ca = { struct cfattach viapm_ca = {
sizeof(struct viapm_softc), viapm_match, viapm_attach sizeof(struct viapm_softc), viapm_match, viapm_attach
}; };