Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/i2c don't pull a 1.5K softc on the stack to do a chi...
details: https://anonhg.NetBSD.org/src/rev/0c17983e6501
branches: trunk
changeset: 748710:0c17983e6501
user: christos <christos%NetBSD.org@localhost>
date: Mon Nov 02 21:37:44 2009 +0000
description:
don't pull a 1.5K softc on the stack to do a chip ident. Idea from mrg.
diffstat:
sys/dev/i2c/dbcool.c | 299 +++++++++++++++++++++++-----------------------
sys/dev/i2c/dbcool_var.h | 24 ++-
2 files changed, 163 insertions(+), 160 deletions(-)
diffs (truncated from 866 to 300 lines):
diff -r 4d4894a931b1 -r 0c17983e6501 sys/dev/i2c/dbcool.c
--- a/sys/dev/i2c/dbcool.c Mon Nov 02 20:52:39 2009 +0000
+++ b/sys/dev/i2c/dbcool.c Mon Nov 02 21:37:44 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dbcool.c,v 1.12 2009/06/01 20:08:44 pgoyette Exp $ */
+/* $NetBSD: dbcool.c,v 1.13 2009/11/02 21:37:44 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.12 2009/06/01 20:08:44 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.13 2009/11/02 21:37:44 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -588,17 +588,17 @@
dbcool_match(device_t parent, cfdata_t cf, void *aux)
{
struct i2c_attach_args *ia = aux;
- struct dbcool_softc sc;
- sc.sc_tag = ia->ia_tag;
- sc.sc_addr = ia->ia_addr;
- sc.sc_chip = NULL;
- sc.sc_readreg = dbcool_readreg;
- sc.sc_writereg = dbcool_writereg;
+ struct dbcool_chipset dc;
+ dc.dc_tag = ia->ia_tag;
+ dc.dc_addr = ia->ia_addr;
+ dc.dc_chip = NULL;
+ dc.dc_readreg = dbcool_readreg;
+ dc.dc_writereg = dbcool_writereg;
/* no probing if we attach to iic, but verify chip id and address */
if ((ia->ia_addr & DBCOOL_ADDRMASK) != DBCOOL_ADDR)
return 0;
- if (dbcool_chip_ident(&sc) >= 0)
+ if (dbcool_chip_ident(&dc) >= 0)
return 1;
return 0;
@@ -611,25 +611,25 @@
struct i2c_attach_args *args = aux;
uint8_t ver;
- sc->sc_addr = args->ia_addr;
- sc->sc_tag = args->ia_tag;
+ sc->sc_dc.dc_addr = args->ia_addr;
+ sc->sc_dc.dc_tag = args->ia_tag;
+ sc->sc_dc.dc_chip = NULL;
+ sc->sc_dc.dc_readreg = dbcool_readreg;
+ sc->sc_dc.dc_writereg = dbcool_writereg;
+ (void)dbcool_chip_ident(&sc->sc_dc);
sc->sc_dev = self;
- sc->sc_readreg = dbcool_readreg;
- sc->sc_writereg = dbcool_writereg;
- sc->sc_chip = NULL;
- (void)dbcool_chip_ident(sc);
aprint_naive("\n");
aprint_normal("\n");
- ver = sc->sc_readreg(sc, DBCOOL_REVISION_REG);
- if (sc->sc_chip->flags & DBCFLAG_4BIT_VER)
+ ver = sc->sc_dc.dc_readreg(&sc->sc_dc, DBCOOL_REVISION_REG);
+ if (sc->sc_dc.dc_chip->flags & DBCFLAG_4BIT_VER)
aprint_normal_dev(self, "%s dBCool(tm) Controller "
- "(rev 0x%02x, stepping 0x%02x)\n", sc->sc_chip->name,
+ "(rev 0x%02x, stepping 0x%02x)\n", sc->sc_dc.dc_chip->name,
ver >> 4, ver & 0x0f);
else
aprint_normal_dev(self, "%s dBCool(tm) Controller "
- "(rev 0x%04x)\n", sc->sc_chip->name, ver);
+ "(rev 0x%04x)\n", sc->sc_dc.dc_chip->name, ver);
dbcool_setup(self);
@@ -653,20 +653,20 @@
struct dbcool_softc *sc = device_private(dev);
uint8_t reg, bit, cfg;
- if ((sc->sc_chip->flags && DBCFLAG_HAS_SHDN) == 0)
+ if ((sc->sc_dc.dc_chip->flags && DBCFLAG_HAS_SHDN) == 0)
return true;
- if (sc->sc_chip->flags && DBCFLAG_ADT7466) {
+ if (sc->sc_dc.dc_chip->flags && DBCFLAG_ADT7466) {
reg = DBCOOL_ADT7466_CONFIG2;
bit = DBCOOL_ADT7466_CFG2_SHDN;
} else {
reg = DBCOOL_CONFIG2_REG;
bit = DBCOOL_CFG2_SHDN;
}
- cfg = sc->sc_readreg(sc, reg);
+ cfg = sc->sc_dc.dc_readreg(&sc->sc_dc, reg);
sc->sc_suspend = cfg & bit;
cfg |= bit;
- sc->sc_writereg(sc, reg, cfg);
+ sc->sc_dc.dc_writereg(&sc->sc_dc, reg, cfg);
return true;
}
@@ -677,56 +677,55 @@
struct dbcool_softc *sc = device_private(dev);
uint8_t reg, bit, cfg;
- if ((sc->sc_chip->flags && DBCFLAG_HAS_SHDN) == 0)
+ if ((sc->sc_dc.dc_chip->flags && DBCFLAG_HAS_SHDN) == 0)
return true;
- if (sc->sc_chip->flags && DBCFLAG_ADT7466) {
+ if (sc->sc_dc.dc_chip->flags && DBCFLAG_ADT7466) {
reg = DBCOOL_ADT7466_CONFIG2;
bit = DBCOOL_ADT7466_CFG2_SHDN;
} else {
reg = DBCOOL_CONFIG2_REG;
bit = DBCOOL_CFG2_SHDN;
}
- cfg = sc->sc_readreg(sc, reg);
+ cfg = sc->sc_dc.dc_readreg(&sc->sc_dc, reg);
cfg &= ~sc->sc_suspend;
- sc->sc_writereg(sc, reg, cfg);
+ sc->sc_dc.dc_writereg(&sc->sc_dc, reg, cfg);
return true;
}
uint8_t
-dbcool_readreg(struct dbcool_softc *sc, uint8_t reg)
+dbcool_readreg(struct dbcool_chipset *dc, uint8_t reg)
{
uint8_t data = 0;
- if (iic_acquire_bus(sc->sc_tag, 0) != 0)
+ if (iic_acquire_bus(dc->dc_tag, 0) != 0)
return data;
- if ( sc->sc_chip == NULL || sc->sc_chip->flags & DBCFLAG_ADM1027) {
+ if (dc->dc_chip == NULL || dc->dc_chip->flags & DBCFLAG_ADM1027) {
/* ADM1027 doesn't support i2c read_byte protocol */
- if (iic_smbus_send_byte(sc->sc_tag, sc->sc_addr, reg, 0) != 0)
+ if (iic_smbus_send_byte(dc->dc_tag, dc->dc_addr, reg, 0) != 0)
goto bad;
- (void)iic_smbus_receive_byte(sc->sc_tag, sc->sc_addr, &data, 0);
+ (void)iic_smbus_receive_byte(dc->dc_tag, dc->dc_addr, &data, 0);
} else
- (void)iic_smbus_read_byte(sc->sc_tag, sc->sc_addr, reg, &data,
+ (void)iic_smbus_read_byte(dc->dc_tag, dc->dc_addr, reg, &data,
0);
bad:
- iic_release_bus(sc->sc_tag, 0);
+ iic_release_bus(dc->dc_tag, 0);
return data;
}
void
-dbcool_writereg(struct dbcool_softc *sc, uint8_t reg, uint8_t val)
+dbcool_writereg(struct dbcool_chipset *dc, uint8_t reg, uint8_t val)
{
- if (iic_acquire_bus(sc->sc_tag, 0) != 0)
+ if (iic_acquire_bus(dc->dc_tag, 0) != 0)
return;
- (void)iic_smbus_write_byte(sc->sc_tag, sc->sc_addr, reg, val, 0);
+ (void)iic_smbus_write_byte(dc->dc_tag, dc->dc_addr, reg, val, 0);
- iic_release_bus(sc->sc_tag, 0);
- return;
+ iic_release_bus(dc->dc_tag, 0);
}
static bool
@@ -734,15 +733,15 @@
{
uint8_t cfg_reg;
- if (sc->sc_chip->flags & DBCFLAG_ADM1030)
+ if (sc->sc_dc.dc_chip->flags & DBCFLAG_ADM1030)
return 0;
- if (sc->sc_chip->flags & DBCFLAG_ADT7466)
+ if (sc->sc_dc.dc_chip->flags & DBCFLAG_ADT7466)
cfg_reg = DBCOOL_ADT7466_CONFIG1;
else
cfg_reg = DBCOOL_CONFIG1_REG;
- if (sc->sc_readreg(sc, cfg_reg) & DBCOOL_CFG1_LOCK)
+ if (sc->sc_dc.dc_readreg(&sc->sc_dc, cfg_reg) & DBCOOL_CFG1_LOCK)
return 1;
else
return 0;
@@ -754,35 +753,35 @@
uint8_t t1, t2, t3, val, ext = 0;
int temp;
- if (sc->sc_chip->flags & DBCFLAG_ADT7466) {
+ if (sc->sc_dc.dc_chip->flags & DBCFLAG_ADT7466) {
/*
* ADT7466 temps are in strange location
*/
- ext = sc->sc_readreg(sc, DBCOOL_ADT7466_CONFIG1);
- val = sc->sc_readreg(sc, reg);
+ ext = sc->sc_dc.dc_readreg(&sc->sc_dc, DBCOOL_ADT7466_CONFIG1);
+ val = sc->sc_dc.dc_readreg(&sc->sc_dc, reg);
if (extres)
- ext = sc->sc_readreg(sc, reg + 1);
- } else if (sc->sc_chip->flags & DBCFLAG_ADM1030) {
+ ext = sc->sc_dc.dc_readreg(&sc->sc_dc, reg + 1);
+ } else if (sc->sc_dc.dc_chip->flags & DBCFLAG_ADM1030) {
/*
* ADM1030 temps are in their own special place, too
*/
if (extres) {
- ext = sc->sc_readreg(sc, DBCOOL_ADM1030_TEMP_EXTRES);
+ ext = sc->sc_dc.dc_readreg(&sc->sc_dc, DBCOOL_ADM1030_TEMP_EXTRES);
if (reg == DBCOOL_ADM1030_L_TEMP)
ext >>= 6;
else
ext >>= 1;
ext &= 0x03;
}
- val = sc->sc_readreg(sc, reg);
+ val = sc->sc_dc.dc_readreg(&sc->sc_dc, reg);
} else if (extres) {
- ext = sc->sc_readreg(sc, DBCOOL_EXTRES2_REG);
+ ext = sc->sc_dc.dc_readreg(&sc->sc_dc, DBCOOL_EXTRES2_REG);
/* Read all msb regs to unlatch them */
- t1 = sc->sc_readreg(sc, DBCOOL_12VIN);
- t1 = sc->sc_readreg(sc, DBCOOL_REMOTE1_TEMP);
- t2 = sc->sc_readreg(sc, DBCOOL_REMOTE2_TEMP);
- t3 = sc->sc_readreg(sc, DBCOOL_LOCAL_TEMP);
+ t1 = sc->sc_dc.dc_readreg(&sc->sc_dc, DBCOOL_12VIN);
+ t1 = sc->sc_dc.dc_readreg(&sc->sc_dc, DBCOOL_REMOTE1_TEMP);
+ t2 = sc->sc_dc.dc_readreg(&sc->sc_dc, DBCOOL_REMOTE2_TEMP);
+ t3 = sc->sc_dc.dc_readreg(&sc->sc_dc, DBCOOL_LOCAL_TEMP);
switch (reg) {
case DBCOOL_REMOTE1_TEMP:
val = t1;
@@ -803,7 +802,7 @@
ext &= 0x03;
}
else
- val = sc->sc_readreg(sc, reg);
+ val = sc->sc_dc.dc_readreg(&sc->sc_dc, reg);
/* Check for invalid temp values */
if ((sc->sc_temp_offset == 0 && val == 0x80) ||
@@ -831,30 +830,30 @@
int rpm;
uint8_t rpm_lo, rpm_hi;
- rpm_lo = sc->sc_readreg(sc, reg);
- if (sc->sc_chip->flags & DBCFLAG_ADM1030)
+ rpm_lo = sc->sc_dc.dc_readreg(&sc->sc_dc, reg);
+ if (sc->sc_dc.dc_chip->flags & DBCFLAG_ADM1030)
rpm_hi = (rpm_lo == 0xff)?0xff:0x0;
else
- rpm_hi = sc->sc_readreg(sc, reg + 1);
+ rpm_hi = sc->sc_dc.dc_readreg(&sc->sc_dc, reg + 1);
rpm = (rpm_hi << 8) | rpm_lo;
if (rpm == 0xffff)
return 0; /* 0xffff indicates stalled/failed fan */
- return (sc->sc_chip->rpm_dividend / rpm);
+ return (sc->sc_dc.dc_chip->rpm_dividend / rpm);
}
/* Provide chip's supply voltage, in microvolts */
static int
dbcool_supply_voltage(struct dbcool_softc *sc)
{
- if (sc->sc_chip->flags & DBCFLAG_MULTI_VCC) {
- if (sc->sc_readreg(sc, DBCOOL_CONFIG1_REG) & DBCOOL_CFG1_Vcc)
+ if (sc->sc_dc.dc_chip->flags & DBCFLAG_MULTI_VCC) {
+ if (sc->sc_dc.dc_readreg(&sc->sc_dc, DBCOOL_CONFIG1_REG) & DBCOOL_CFG1_Vcc)
return 5002500;
else
return 3300000;
- } else if (sc->sc_chip->flags & DBCFLAG_ADT7466) {
- if (sc->sc_readreg(sc, DBCOOL_ADT7466_CONFIG1) &
+ } else if (sc->sc_dc.dc_chip->flags & DBCFLAG_ADT7466) {
+ if (sc->sc_dc.dc_readreg(&sc->sc_dc, DBCOOL_ADT7466_CONFIG1) &
DBCOOL_ADT7466_CFG1_Vcc)
return 5000000;
else
@@ -878,8 +877,8 @@
nom = sc->sc_supply_voltage;
/* ADT7466 voltages are in strange locations with only 8-bits */
- if (sc->sc_chip->flags & DBCFLAG_ADT7466)
- val = sc->sc_readreg(sc, reg);
+ if (sc->sc_dc.dc_chip->flags & DBCFLAG_ADT7466)
+ val = sc->sc_dc.dc_readreg(&sc->sc_dc, reg);
else
Home |
Main Index |
Thread Index |
Old Index