summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2007-01-07 21:24:29 +0000
committerkettenis <kettenis@openbsd.org>2007-01-07 21:24:29 +0000
commit1240d9412811ecda996de459323897dd76cf616c (patch)
tree37fe3ab6692264a633422177d577305c222fd363
parentadd the temporary file we create to the temp_files worklist (diff)
downloadwireguard-openbsd-1240d9412811ecda996de459323897dd76cf616c.tar.xz
wireguard-openbsd-1240d9412811ecda996de459323897dd76cf616c.zip
Fix VCore voltage detection on w83637hf.
Based on a diff from Constantine A. Murenin
-rw-r--r--sys/dev/ic/lm78.c29
-rw-r--r--sys/dev/ic/lm78var.h10
2 files changed, 35 insertions, 4 deletions
diff --git a/sys/dev/ic/lm78.c b/sys/dev/ic/lm78.c
index db4075a266c..79cfd382fe0 100644
--- a/sys/dev/ic/lm78.c
+++ b/sys/dev/ic/lm78.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lm78.c,v 1.11 2006/12/23 17:46:39 deraadt Exp $ */
+/* $OpenBSD: lm78.c,v 1.12 2007/01/07 21:24:29 kettenis Exp $ */
/*
* Copyright (c) 2005, 2006 Mark Kettenis
@@ -60,6 +60,7 @@ void lm_refresh_temp(struct lm_softc *, int);
void lm_refresh_fanrpm(struct lm_softc *, int);
void wb_refresh_sensor_data(struct lm_softc *);
+void wb_w83637hf_refresh_vcore(struct lm_softc *, int);
void wb_refresh_nvolt(struct lm_softc *, int);
void wb_refresh_temp(struct lm_softc *, int);
void wb_refresh_fanrpm(struct lm_softc *, int);
@@ -125,7 +126,7 @@ struct lm_sensor w83627hf_sensors[] = {
struct lm_sensor w83637hf_sensors[] = {
/* Voltage */
- { "VCore", SENSOR_VOLTS_DC, 0, 0x20, lm_refresh_volt, RFACT_NONE },
+ { "VCore", SENSOR_VOLTS_DC, 0, 0x20, wb_w83637hf_refresh_vcore },
{ "+12V", SENSOR_VOLTS_DC, 0, 0x21, lm_refresh_volt, RFACT(28, 10) },
{ "+3.3V", SENSOR_VOLTS_DC, 0, 0x22, lm_refresh_volt, RFACT_NONE },
{ "+5V", SENSOR_VOLTS_DC, 0, 0x23, lm_refresh_volt, RFACT(34, 51) },
@@ -441,6 +442,10 @@ wb_match(struct lm_softc *sc)
break;
case WB_CHIPID_W83637HF:
printf(": W83637HF\n");
+ sc->lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_B0);
+ if (sc->lm_readreg(sc, WB_BANK0_CONFIG) & WB_CONFIG_VMR9)
+ sc->vrm9 = 1;
+ sc->lm_writereg(sc, WB_BANKSEL, banksel);
lm_setup_sensors(sc, w83637hf_sensors);
break;
case WB_CHIPID_W83697HF:
@@ -616,6 +621,26 @@ wb_refresh_sensor_data(struct lm_softc *sc)
}
void
+wb_w83637hf_refresh_vcore(struct lm_softc *sc, int n)
+{
+ struct sensor *sensor = &sc->sensors[n];
+ int data;
+
+ data = sc->lm_readreg(sc, sc->lm_sensors[n].reg);
+
+ /*
+ * Depending on the voltage detection method,
+ * one of the following formulas is used:
+ * VRM8 method: value = raw * 0.016V
+ * VRM9 method: value = raw * 0.00488V + 0.70V
+ */
+ if (sc->vrm9)
+ sensor->value = (data * 4880) + 700000;
+ else
+ sensor->value = (data * 16000);
+}
+
+void
wb_refresh_nvolt(struct lm_softc *sc, int n)
{
struct sensor *sensor = &sc->sensors[n];
diff --git a/sys/dev/ic/lm78var.h b/sys/dev/ic/lm78var.h
index 2d446100747..4613163da07 100644
--- a/sys/dev/ic/lm78var.h
+++ b/sys/dev/ic/lm78var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: lm78var.h,v 1.7 2006/12/23 17:46:39 deraadt Exp $ */
+/* $OpenBSD: lm78var.h,v 1.8 2007/01/07 21:24:29 kettenis Exp $ */
/*
* Copyright (c) 2005, 2006 Mark Kettenis
@@ -67,6 +67,8 @@
#define WB_BANK0_FAN4 0xba /* Fan 4 reading (W83791D only) */
#define WB_BANK0_FAN5 0xbb /* Fan 5 reading (W83791D only) */
+#define WB_BANK0_CONFIG 0x18 /* VRM & OVT Configuration (W83637HF only) */
+
/* Bank 1 registers */
#define WB_BANK1_T2H 0x50 /* Temperature 2 High Byte */
#define WB_BANK1_T2L 0x51 /* Temperature 2 Low Byte */
@@ -91,7 +93,7 @@
#define WB_BANKSEL_B3 0x03 /* Bank 3 */
#define WB_BANKSEL_B4 0x04 /* Bank 4 */
#define WB_BANKSEL_B5 0x05 /* Bank 5 */
-#define WB_BANKSEL_HBAC 0x80 /* Register 0x4f Hight Byte Access */
+#define WB_BANKSEL_HBAC 0x80 /* Register 0x4f High Byte Access */
/* Vendor IDs */
#define WB_VENDID_WINBOND 0x5ca3 /* Winbond */
@@ -111,6 +113,9 @@
#define WB_CHIPID_W83637HF 0x80
#define WB_CHIPID_W83627THF 0x90
+/* Config bits */
+#define WB_CONFIG_VMR9 0x01
+
/* Reference voltage (mV) */
#define WB_VREF 3600
@@ -141,6 +146,7 @@ struct lm_softc {
u_int8_t sbusaddr;
u_int8_t chipid;
+ u_int8_t vrm9;
};
void lm_attach(struct lm_softc *);