Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Changes for SMBus/I2C:
details: https://anonhg.NetBSD.org/src/rev/c82e94adddfb
branches: trunk
changeset: 539357:c82e94adddfb
user: ad <ad%NetBSD.org@localhost>
date: Fri Nov 15 14:55:41 2002 +0000
description:
Changes for SMBus/I2C:
- Move lm_readreg/lm_writereg into the front-ends. Add/use function pointers
in the softc.
- Add a bank select function pointer to the softc and provide a generic
version. WinBond chips accessed over serial bus present three addresses,
two of which are used to access bank 1/2 registers.
- Mark TSENS2/3 sensor data as invalid if the the corresponding bank select
fails.
diffstat:
sys/arch/i386/pnpbios/lm_pnpbios.c | 28 ++++++-
sys/dev/ic/nslm7x.c | 154 ++++++++++++++++++------------------
sys/dev/ic/nslm7xvar.h | 7 +-
sys/dev/isa/lm_isa.c | 34 +++++++-
4 files changed, 138 insertions(+), 85 deletions(-)
diffs (truncated from 515 to 300 lines):
diff -r 129814328751 -r c82e94adddfb sys/arch/i386/pnpbios/lm_pnpbios.c
--- a/sys/arch/i386/pnpbios/lm_pnpbios.c Fri Nov 15 14:52:56 2002 +0000
+++ b/sys/arch/i386/pnpbios/lm_pnpbios.c Fri Nov 15 14:55:41 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lm_pnpbios.c,v 1.7 2002/10/02 05:47:16 thorpej Exp $ */
+/* $NetBSD: lm_pnpbios.c,v 1.8 2002/11/15 14:55:45 ad Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lm_pnpbios.c,v 1.7 2002/10/02 05:47:16 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lm_pnpbios.c,v 1.8 2002/11/15 14:55:45 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -62,6 +62,8 @@
int lm_pnpbios_match __P((struct device *, struct cfdata *, void *));
void lm_pnpbios_attach __P((struct device *, struct device *, void *));
int lm_pnpbios_hints_index __P((const char *));
+u_int8_t lm_pnpbios_readreg(struct lm_softc *, int);
+void lm_pnpbios_writereg(struct lm_softc *, int, int);
CFATTACH_DECL(lm_pnpbios, sizeof(struct lm_softc),
@@ -154,6 +156,28 @@
printf("%s", self->dv_xname);
/* Bus-independant attach */
+ sc->lm_writereg = lm_pnpbios_writereg;
+ sc->lm_readreg = lm_pnpbios_readreg;
+
lm_attach(sc);
}
+u_int8_t
+lm_pnpbios_readreg(sc, reg)
+ struct lm_softc *sc;
+ int reg;
+{
+ bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
+ return (bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA));
+}
+
+
+void
+lm_pnpbios_writereg(sc, reg, val)
+ struct lm_softc *sc;
+ int reg;
+ int val;
+{
+ bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
+ bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val);
+}
diff -r 129814328751 -r c82e94adddfb sys/dev/ic/nslm7x.c
--- a/sys/dev/ic/nslm7x.c Fri Nov 15 14:52:56 2002 +0000
+++ b/sys/dev/ic/nslm7x.c Fri Nov 15 14:55:41 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nslm7x.c,v 1.16 2002/11/07 08:08:51 thorpej Exp $ */
+/* $NetBSD: nslm7x.c,v 1.17 2002/11/15 14:55:41 ad Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nslm7x.c,v 1.16 2002/11/07 08:08:51 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nslm7x.c,v 1.17 2002/11/15 14:55:41 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -82,9 +82,6 @@
};
-u_int8_t lm_readreg __P((struct lm_softc *, int));
-void lm_writereg __P((struct lm_softc *, int, int));
-
static void setup_fan __P((struct lm_softc *, int, int));
static void setup_temp __P((struct lm_softc *, int, int));
static void wb_setup_volt __P((struct lm_softc *));
@@ -93,6 +90,7 @@
int wb_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));
static void generic_stemp __P((struct lm_softc *, struct envsys_tre_data *));
static void generic_svolt __P((struct lm_softc *, struct envsys_tre_data *,
@@ -129,23 +127,14 @@
};
-u_int8_t
-lm_readreg(sc, reg)
- struct lm_softc *sc;
- int reg;
+int
+lm_generic_banksel(lmsc, bank)
+ struct lm_softc *lmsc;
+ int bank;
{
- bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
- return (bus_space_read_1(sc->lm_iot, sc->lm_ioh, LMC_DATA));
-}
-void
-lm_writereg(sc, reg, val)
- struct lm_softc *sc;
- int reg;
- int val;
-{
- bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_ADDR, reg);
- bus_space_write_1(sc->lm_iot, sc->lm_ioh, LMC_DATA, val);
+ (*lmsc->lm_writereg)(lmsc, WB_BANKSEL, bank);
+ return (0);
}
@@ -191,12 +180,16 @@
{
u_int i;
+ /* Install default bank selection routine, if none given. */
+ if (lmsc->lm_banksel == NULL)
+ lmsc->lm_banksel = lm_generic_banksel;
+
for (i = 0; i < sizeof(lm_chips) / sizeof(lm_chips[0]); i++)
if (lm_chips[i].chip_match(lmsc))
break;
/* Start the monitoring loop */
- lm_writereg(lmsc, LMD_CONFIG, 0x01);
+ (*lmsc->lm_writereg)(lmsc, LMD_CONFIG, 0x01);
/* Indicate we have never read the registers */
timerclear(&lmsc->lastread);
@@ -234,7 +227,7 @@
int i;
/* See if we have an LM78 or LM79 */
- i = lm_readreg(sc, LMD_CHIPID) & LM_ID_MASK;
+ i = (*sc->lm_readreg)(sc, LMD_CHIPID) & LM_ID_MASK;
switch(i) {
case LM_ID_LM78:
printf(": LM78\n");
@@ -261,8 +254,8 @@
{
int i;
- i = lm_readreg(sc, LMD_CHIPID) & LM_ID_MASK;
- printf(": Unknow chip (ID %d)\n", i);
+ i = (*sc->lm_readreg)(sc, LMD_CHIPID) & LM_ID_MASK;
+ printf(": Unknown chip (ID %d)\n", i);
lm_common_match(sc);
return 1;
}
@@ -302,16 +295,16 @@
{
int i, j;
- lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_HBAC);
- j = lm_readreg(sc, WB_VENDID) << 8;
- lm_writereg(sc, WB_BANKSEL, 0);
- j |= lm_readreg(sc, WB_VENDID);
+ (*sc->lm_writereg)(sc, WB_BANKSEL, WB_BANKSEL_HBAC);
+ j = (*sc->lm_readreg)(sc, WB_VENDID) << 8;
+ (*sc->lm_writereg)(sc, WB_BANKSEL, 0);
+ j |= (*sc->lm_readreg)(sc, WB_VENDID);
DPRINTF(("winbond vend id 0x%x\n", j));
if (j != WB_VENDID_WINBOND)
return 0;
/* read device ID */
- lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_B0);
- j = lm_readreg(sc, WB_BANK0_CHIPID);
+ (*sc->lm_banksel)(sc, 0);
+ j = (*sc->lm_readreg)(sc, WB_BANK0_CHIPID);
DPRINTF(("winbond chip id 0x%x\n", j));
switch(j) {
case WB_CHIPID_83781:
@@ -347,8 +340,7 @@
sc->numsensors = WB83697_NUM_SENSORS;
sc->refresh_sensor_data = wb697_refresh_sensor_data;
sc->sc_sysmon.sme_streinfo = wb782_streinfo;
- return 1;
- break;
+ return 1;
case WB_CHIPID_83782:
printf(": W83782D\n");
break;
@@ -497,7 +489,7 @@
* FAN1 div is in bits <5:4>, FAN2 div is
* in <7:6>
*/
- sdata = lm_readreg(sc, LMD_VIDFAN);
+ sdata = (*sc->lm_readreg)(sc, LMD_VIDFAN);
if ( n == 0 ) { /* FAN1 */
divisor <<= 4;
sdata = (sdata & 0xCF) | divisor;
@@ -506,7 +498,7 @@
sdata = (sdata & 0x3F) | divisor;
}
- lm_writereg(sc, LMD_VIDFAN, sdata);
+ (*sc->lm_writereg)(sc, LMD_VIDFAN, sdata);
}
return (0);
@@ -573,7 +565,7 @@
* FAN1 div is in bits <5:4>, FAN2 div
* is in <7:6>
*/
- sdata = lm_readreg(sc, LMD_VIDFAN);
+ sdata = (*sc->lm_readreg)(sc, LMD_VIDFAN);
if ( binfo->sensor == 10 ) { /* FAN1 */
sdata = (sdata & 0xCF) |
((divisor & 0x3) << 4);
@@ -581,13 +573,13 @@
sdata = (sdata & 0x3F) |
((divisor & 0x3) << 6);
}
- lm_writereg(sc, LMD_VIDFAN, sdata);
+ (*sc->lm_writereg)(sc, LMD_VIDFAN, sdata);
} else {
/* FAN3 is in WB_PIN <7:6> */
- sdata = lm_readreg(sc, WB_PIN);
+ sdata = (*sc->lm_readreg)(sc, WB_PIN);
sdata = (sdata & 0x3F) |
((divisor & 0x3) << 6);
- lm_writereg(sc, WB_PIN, sdata);
+ (*sc->lm_writereg)(sc, WB_PIN, sdata);
}
}
memcpy(sc->info[binfo->sensor].desc, binfo->desc,
@@ -637,7 +629,7 @@
* FAN1 div is in bits <5:4>, FAN2 div
* is in <7:6>
*/
- sdata = lm_readreg(sc, LMD_VIDFAN);
+ sdata = (*sc->lm_readreg)(sc, LMD_VIDFAN);
if ( binfo->sensor == 12 ) { /* FAN1 */
sdata = (sdata & 0xCF) |
((divisor & 0x3) << 4);
@@ -645,20 +637,20 @@
sdata = (sdata & 0x3F) |
((divisor & 0x3) << 6);
}
- lm_writereg(sc, LMD_VIDFAN, sdata);
+ (*sc->lm_writereg)(sc, LMD_VIDFAN, sdata);
} else {
/* FAN3 is in WB_PIN <7:6> */
- sdata = lm_readreg(sc, WB_PIN);
+ sdata = (*sc->lm_readreg)(sc, WB_PIN);
sdata = (sdata & 0x3F) |
((divisor & 0x3) << 6);
- lm_writereg(sc, WB_PIN, sdata);
+ (*sc->lm_writereg)(sc, WB_PIN, sdata);
}
/* Bit 2 of divisor is in WB_BANK0_FANBAT */
- lm_writereg(sc, WB_BANKSEL, WB_BANKSEL_B0);
- sdata = lm_readreg(sc, WB_BANK0_FANBAT);
+ (*sc->lm_banksel)(sc, 0);
+ sdata = (*sc->lm_readreg)(sc, WB_BANK0_FANBAT);
sdata &= ~(0x20 << (binfo->sensor - 12));
sdata |= (divisor & 0x4) << (binfo->sensor - 9);
- lm_writereg(sc, WB_BANK0_FANBAT, sdata);
+ (*sc->lm_writereg)(sc, WB_BANK0_FANBAT, sdata);
}
memcpy(sc->info[binfo->sensor].desc, binfo->desc,
@@ -676,7 +668,7 @@
struct lm_softc *sc;
struct envsys_tre_data *sensor;
{
- int sdata = lm_readreg(sc, LMD_SENSORBASE + 7);
+ int sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + 7);
DPRINTF(("sdata[temp] 0x%x\n", sdata));
/* temp is given in deg. C, we convert to uK */
sensor->cur.data_us = sdata * 1000000 + 273150000;
@@ -691,7 +683,7 @@
int i, sdata;
for (i = 0; i < 7; i++) {
- sdata = lm_readreg(sc, LMD_SENSORBASE + i);
+ sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + i);
DPRINTF(("sdata[volt%d] 0x%x\n", i, sdata));
/* voltage returned as (mV >> 4), we convert to uVDC */
sensors[i].cur.data_s = (sdata << 4);
@@ -713,14 +705,14 @@
{
int i, sdata, divisor;
for (i = 0; i < 3; i++) {
- sdata = lm_readreg(sc, LMD_SENSORBASE + 8 + i);
+ sdata = (*sc->lm_readreg)(sc, LMD_SENSORBASE + 8 + i);
DPRINTF(("sdata[fan%d] 0x%x\n", i, sdata));
if (i == 2)
divisor = 2; /* Fixed divisor for FAN3 */
Home |
Main Index |
Thread Index |
Old Index