Subject: Re: Environmental Sensors on A7V333
To: Thomas Runge <coto@core.de>
From: IWAMOTO Toshihiro <toshii@netbsd.org>
List: current-users
Date: 05/28/2003 22:45:44
--Multipart_Wed_May_28_22:45:31_2003-1
Content-Type: text/plain; charset=US-ASCII
At Wed, 28 May 2003 15:13:43 +0200 (CEST),
Thomas Runge wrote:
>
> On Wed, 28 May 2003, Alistair Crooks wrote:
>
> > Try out pkgsrc/sysutils/mbmon and pkgsrc/sysutils/xmbmon - thanks for
> > the nudge.
>
> Any chance we will get that into envsys(4) or any other to-be-
> developed interface (sysctl(8))?
I guess A7V333 has IT8705F, as my A7S333 does.
Then my patch should work.
--
IWAMOTO Toshihiro
--Multipart_Wed_May_28_22:45:31_2003-1
Content-Type: application/octet-stream; type=patch
Content-Disposition: attachment; filename="ite.diff"
Content-Transfer-Encoding: 7bit
Index: nslm7x.c
===================================================================
RCS file: /net/kiku/NetBSD/NetBSD-CVS/src/sys/dev/ic/nslm7x.c,v
retrieving revision 1.17
diff -u -r1.17 nslm7x.c
--- nslm7x.c 15 Nov 2002 14:55:41 -0000 1.17
+++ nslm7x.c 28 Nov 2002 17:03:02 -0000
@@ -88,6 +88,7 @@
int lm_match __P((struct lm_softc *));
int wb_match __P((struct lm_softc *));
+int it_match __P((struct lm_softc *));
int def_match __P((struct lm_softc *));
void lm_common_match __P((struct lm_softc *));
static int lm_generic_banksel __P((struct lm_softc *, int));
@@ -108,6 +109,8 @@
void wb782_refresh_sensor_data __P((struct lm_softc *));
void wb697_refresh_sensor_data __P((struct lm_softc *));
+void it_refresh_sensor_data __P((struct lm_softc *));
+
int lm_gtredata __P((struct sysmon_envsys *, struct envsys_tre_data *));
int generic_streinfo_fan __P((struct lm_softc *, struct envsys_basic_info *,
@@ -115,6 +118,7 @@
int lm_streinfo __P((struct sysmon_envsys *, struct envsys_basic_info *));
int wb781_streinfo __P((struct sysmon_envsys *, struct envsys_basic_info *));
int wb782_streinfo __P((struct sysmon_envsys *, struct envsys_basic_info *));
+int it_streinfo __P((struct sysmon_envsys *, struct envsys_basic_info *));
struct lm_chip {
int (*chip_match) __P((struct lm_softc *));
@@ -122,6 +126,7 @@
struct lm_chip lm_chips[] = {
{ wb_match },
+ { it_match },
{ lm_match },
{ def_match } /* Must be last */
};
@@ -146,6 +151,7 @@
bus_space_tag_t iot;
bus_space_handle_t ioh;
{
+#if 0
u_int8_t cr;
int rv;
@@ -168,6 +174,8 @@
DPRINTF(("lm: rv = %d, cr = %x\n", rv, cr));
return (rv);
+#endif
+ return (1);
}
@@ -189,7 +197,8 @@
break;
/* Start the monitoring loop */
- (*lmsc->lm_writereg)(lmsc, LMD_CONFIG, 0x01);
+ if (lm_chips[i].chip_match != it_match)
+ (*lmsc->lm_writereg)(lmsc, LMD_CONFIG, 0x01);
/* Indicate we have never read the registers */
timerclear(&lmsc->lastread);
@@ -396,6 +405,43 @@
sc->info[8].rfact = 10000;
}
+int
+it_match(sc)
+ struct lm_softc *sc;
+{
+ int i;
+
+ i = (sc->lm_readreg)(sc, 0x58);
+ if (i != 0x90)
+ return 0;
+
+ printf(": IT8705F\n");
+
+ sc->numsensors = IT_NUM_SENSORS;
+ sc->refresh_sensor_data = it_refresh_sensor_data;
+
+ for (i = 0; i < 8; ++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 = 16800;
+ sc->info[4].rfact = 40000;
+ sc->info[5].rfact = 31428;
+ sc->info[6].rfact = 51428;
+ sc->info[7].rfact = (int)(( 90.9 / 60.4) * 10000);
+
+ setup_fan(sc, 8, 3);
+ setup_temp(sc, 11, 3);
+ sc->sc_sysmon.sme_streinfo = it_streinfo;
+
+ return 1;
+}
+
static void
setup_temp(sc, start, n)
struct lm_softc *sc;
@@ -663,6 +709,32 @@
return (0);
}
+int
+it_streinfo(sme, binfo)
+ struct sysmon_envsys *sme;
+ struct envsys_basic_info *binfo;
+{
+ struct lm_softc *sc = sme->sme_cookie;
+
+ if (sc->info[binfo->sensor].units == ENVSYS_SVOLTS_DC)
+ sc->info[binfo->sensor].rfact = binfo->rfact;
+ else {
+#if 0
+ if (sc->info[binfo->sensor].units == ENVSYS_SFANRPM) {
+ it_streinfo_fan(sc, &sc->info[binfo->sensor],
+ binfo->sensor - 8, binfo);
+ }
+#endif
+ memcpy(sc->info[binfo->sensor].desc, binfo->desc,
+ sizeof(sc->info[binfo->sensor].desc));
+ sc->info[binfo->sensor].desc[
+ sizeof(sc->info[binfo->sensor].desc) - 1] = '\0';
+
+ binfo->validflags = ENVSYS_FVALID;
+ }
+ return (0);
+}
+
static void
generic_stemp(sc, sensor)
struct lm_softc *sc;
@@ -894,4 +966,43 @@
wb_svolt(sc);
wb_stemp(sc, &sc->sensors[9], 2);
wb_fanrpm(sc, &sc->sensors[11]);
+}
+
+void
+it_refresh_sensor_data(sc)
+ struct lm_softc *sc;
+{
+ int i, divisor, sdata;
+
+ /* Refresh our stored data for every sensor */
+ for (i = 0; i < 8; i++) {
+ sdata = (*sc->lm_readreg)(sc, IT_VOLTAGEBASE + i);
+
+ sc->sensors[i].cur.data_s = sdata * 16 * sc->info[i].rfact;
+ sc->sensors[i].cur.data_s /= 10;
+ if (i == 5 || i == 6)
+ sc->sensors[i].cur.data_s =
+ 4096000 - sc->sensors[i].cur.data_s;
+ }
+
+ /* XXX It is stupid to read this register every time... */
+ divisor = (*sc->lm_readreg)(sc, IT_FANDIV);
+ for (i = 0; i < 3; i++) {
+ sdata = (*sc->lm_readreg)(sc, IT_FANBASE + i);
+ if (i == 2)
+ sdata *= 2;
+ else
+ sdata <<= (divisor >> (i * 3)) & 7;
+ /* Avoid zero division */
+ if (sdata == 0)
+ sdata = 1;
+ sc->sensors[i + 8].cur.data_us = 1350000 / sdata;
+ }
+
+ for (i = 0; i < 3; i++) {
+ sdata = (*sc->lm_readreg)(sc, IT_TEMPBASE + i);
+ if (sdata > 127)
+ sdata -= 256;
+ sc->sensors[i + 11].cur.data_us = sdata * 1000000 + 273150000;
+ }
}
Index: nslm7xvar.h
===================================================================
RCS file: /net/kiku/NetBSD/NetBSD-CVS/src/sys/dev/ic/nslm7xvar.h,v
retrieving revision 1.10
diff -u -r1.10 nslm7xvar.h
--- nslm7xvar.h 15 Nov 2002 14:55:42 -0000 1.10
+++ nslm7xvar.h 28 Nov 2002 16:50:46 -0000
@@ -116,6 +116,14 @@
#define WB83697_NUM_SENSORS 14
#define WB_NUM_SENSORS 15
+/* registers for IT8705F */
+#define IT_FANBASE 0x0D
+#define IT_VOLTAGEBASE 0x20
+#define IT_TEMPBASE 0x29
+#define IT_FANDIV 0x0B
+
+#define IT_NUM_SENSORS 14
+
struct lm_softc {
struct device sc_dev;
--Multipart_Wed_May_28_22:45:31_2003-1--