Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/sparc64/dev Add sysmon support to display the fan-s...
details: https://anonhg.NetBSD.org/src/rev/33faad2d5a32
branches: trunk
changeset: 784585:33faad2d5a32
user: jdc <jdc%NetBSD.org@localhost>
date: Sat Feb 02 21:54:51 2013 +0000
description:
Add sysmon support to display the fan-speed related values for the CPU and
system fans.
Fix a bug where the system fan was always set to full speed (63), which was
noticed when viewing the values reported by `envstat`.
diffstat:
sys/arch/sparc64/dev/tda.c | 73 ++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 68 insertions(+), 5 deletions(-)
diffs (129 lines):
diff -r 5d71f676080a -r 33faad2d5a32 sys/arch/sparc64/dev/tda.c
--- a/sys/arch/sparc64/dev/tda.c Sat Feb 02 21:38:24 2013 +0000
+++ b/sys/arch/sparc64/dev/tda.c Sat Feb 02 21:54:51 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tda.c,v 1.6 2012/10/27 17:18:12 chs Exp $ */
+/* $NetBSD: tda.c,v 1.7 2013/02/02 21:54:51 jdc Exp $ */
/* $OpenBSD: tda.c,v 1.4 2008/02/27 17:25:00 robert Exp $ */
/*
@@ -19,7 +19,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tda.c,v 1.6 2012/10/27 17:18:12 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tda.c,v 1.7 2013/02/02 21:54:51 jdc Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -44,10 +44,14 @@
#define TDA_PSFAN_ON 0x1f
#define TDA_PSFAN_OFF 0x00
-/* Internal and External temperature senor numbers */
+/* Internal and External temperature sensor numbers */
#define SENSOR_TEMP_EXT 0
#define SENSOR_TEMP_INT 1
+/* Fan sensor numbers */
+#define SENSOR_FAN_CPU 0
+#define SENSOR_FAN_SYS 1
+
#define CPU_TEMP_MAX (67 * 1000000 + 273150000)
#define CPU_TEMP_MIN (57 * 1000000 + 273150000)
#define SYS_TEMP_MAX (30 * 1000000 + 273150000)
@@ -61,11 +65,15 @@
u_int16_t sc_cfan_speed; /* current CPU fan speed */
u_int16_t sc_sfan_speed; /* current SYS fan speed */
+ struct sysmon_envsys *sc_sme;
+ envsys_data_t sc_sensor[2];
+
callout_t sc_timer;
};
int tda_match(device_t, cfdata_t, void *);
void tda_attach(device_t, device_t, void *);
+void tda_refresh(struct sysmon_envsys *, envsys_data_t *);
void tda_setspeed(struct tda_softc *);
static void tda_adjust(void *);
@@ -115,9 +123,45 @@
*/
sc->sc_cfan_speed = sc->sc_sfan_speed = (TDA_FANSPEED_MAX+TDA_FANSPEED_MIN)/2;
tda_setspeed(sc);
-
+
callout_init(&sc->sc_timer, CALLOUT_MPSAFE);
callout_reset(&sc->sc_timer, hz*20, tda_timeout, sc);
+
+ /* Initialise sensor data */
+ sc->sc_sensor[SENSOR_FAN_CPU].state = ENVSYS_SINVALID;
+ sc->sc_sensor[SENSOR_FAN_CPU].units = ENVSYS_INTEGER;
+ sc->sc_sensor[SENSOR_FAN_CPU].flags = ENVSYS_FMONNOTSUPP;
+ strlcpy(sc->sc_sensor[SENSOR_FAN_CPU].desc,
+ "fan.cpu",sizeof("fan.cpu"));
+ sc->sc_sensor[SENSOR_FAN_SYS].state = ENVSYS_SINVALID;
+ sc->sc_sensor[SENSOR_FAN_SYS].units = ENVSYS_INTEGER;
+ sc->sc_sensor[SENSOR_FAN_SYS].flags = ENVSYS_FMONNOTSUPP;
+ strlcpy(sc->sc_sensor[SENSOR_FAN_SYS].desc,
+ "fan.sys",sizeof("fan.sys"));
+ sc->sc_sme = sysmon_envsys_create();
+ if (sysmon_envsys_sensor_attach(
+ sc->sc_sme, &sc->sc_sensor[SENSOR_FAN_CPU])) {
+ sysmon_envsys_destroy(sc->sc_sme);
+ aprint_error_dev(self,
+ "unable to attach cpu fan at sysmon\n");
+ return;
+ }
+ if (sysmon_envsys_sensor_attach(
+ sc->sc_sme, &sc->sc_sensor[SENSOR_FAN_SYS])) {
+ sysmon_envsys_destroy(sc->sc_sme);
+ aprint_error_dev(self,
+ "unable to attach sys fan at sysmon\n");
+ return;
+ }
+ sc->sc_sme->sme_name = device_xname(self);
+ sc->sc_sme->sme_cookie = sc;
+ sc->sc_sme->sme_refresh = tda_refresh;
+ if (sysmon_envsys_register(sc->sc_sme)) {
+ aprint_error_dev(self,
+ "unable to register with sysmon\n");
+ sysmon_envsys_destroy(sc->sc_sme);
+ return;
+ }
}
static void
@@ -221,7 +265,7 @@
if (stemp < SYS_TEMP_MIN)
sspeed = TDA_FANSPEED_MIN;
else if (stemp < SYS_TEMP_MAX)
- sc->sc_sfan_speed = TDA_FANSPEED_MIN +
+ sspeed = TDA_FANSPEED_MIN +
(stemp - SYS_TEMP_MIN) *
(TDA_FANSPEED_MAX - TDA_FANSPEED_MIN) /
(SYS_TEMP_MAX - SYS_TEMP_MIN);
@@ -233,3 +277,22 @@
sc->sc_cfan_speed = cspeed;
tda_setspeed(sc);
}
+
+void
+tda_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
+{
+ struct tda_softc *sc = sme->sme_cookie;
+ u_int16_t speed;
+
+ if (edata->sensor == SENSOR_FAN_CPU)
+ speed = sc->sc_cfan_speed;
+ else
+ speed = sc->sc_sfan_speed;
+ if (!speed)
+ edata->state = ENVSYS_SINVALID;
+ else {
+ edata->value_cur = speed;
+ edata->state = ENVSYS_SVALID;
+ }
+}
+
Home |
Main Index |
Thread Index |
Old Index