Updates for I2C devices on XLR engg boards.
- ds1374u : use multi-byte write. - at24co2n, max6657: remove mutex, iicbus has the necessary locking. Submitted by: Sreekanth M. S. (kanthms at netlogicmicro com)
This commit is contained in:
parent
cab6e6e1fb
commit
d0beb2c412
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=216410
@ -60,7 +60,6 @@ __FBSDID("$FreeBSD$");
|
||||
struct at24co2n_softc {
|
||||
uint32_t sc_addr;
|
||||
device_t sc_dev;
|
||||
struct mtx sc_mtx;
|
||||
uint8_t sc_mac_addr[6];
|
||||
};
|
||||
|
||||
@ -103,8 +102,6 @@ at24co2n_attach(device_t dev)
|
||||
sc->sc_dev = dev;
|
||||
sc->sc_addr = iicbus_get_addr(dev);
|
||||
|
||||
mtx_init(&sc->sc_mtx, "eeprom", "eeprom", MTX_DEF);
|
||||
|
||||
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
|
||||
"eeprom-mac", CTLTYPE_STRING | CTLFLAG_RD, sc, 0,
|
||||
at24co2n_mac_sysctl, "A", "mac address");
|
||||
@ -121,9 +118,7 @@ at24co2n_read_mac(struct at24co2n_softc *sc)
|
||||
{ sc->sc_addr, IIC_M_RD, 6, sc->sc_mac_addr},
|
||||
};
|
||||
|
||||
mtx_lock(&sc->sc_mtx);
|
||||
iicbus_transfer(sc->sc_dev, msgs, 2);
|
||||
mtx_unlock(&sc->sc_mtx);
|
||||
}
|
||||
|
||||
static device_method_t at24co2n_methods[] = {
|
||||
|
@ -85,36 +85,22 @@ ds1374u_attach(device_t dev)
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
ds1374u_write(device_t dev, int reg, uint8_t val)
|
||||
{
|
||||
uint8_t data[2];
|
||||
struct ds1374u_softc *sc = device_get_softc(dev);
|
||||
struct iic_msg msgs[1] = {
|
||||
{ sc->sc_addr, IIC_M_WR, 2, data },
|
||||
};
|
||||
|
||||
data[0] = reg;
|
||||
data[1] = val;
|
||||
if (iicbus_transfer(dev, msgs, 1) == 0)
|
||||
return (0);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static int
|
||||
ds1374u_settime(device_t dev, struct timespec *ts)
|
||||
{
|
||||
int i;
|
||||
int temp = 0;
|
||||
/* NB: register pointer precedes actual data */
|
||||
uint8_t data[5] = { DS1374_RTC_COUNTER };
|
||||
struct ds1374u_softc *sc = device_get_softc(dev);
|
||||
struct iic_msg msgs[1] = {
|
||||
{ sc->sc_addr, IIC_M_WR, 5, data },
|
||||
};
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
temp = (ts->tv_sec >> (8*i)) & 0xff;
|
||||
if (ds1374u_write(dev, DS1374_RTC_COUNTER+i, temp)!=0)
|
||||
return (-1);
|
||||
}
|
||||
return 0;
|
||||
data[1] = (ts->tv_sec >> 0) & 0xff;
|
||||
data[2] = (ts->tv_sec >> 8) & 0xff;
|
||||
data[3] = (ts->tv_sec >> 16) & 0xff;
|
||||
data[4] = (ts->tv_sec >> 24) & 0xff;
|
||||
|
||||
return iicbus_transfer(dev, msgs, 1);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -137,7 +123,6 @@ ds1374u_gettime(device_t dev, struct timespec *ts)
|
||||
ts->tv_nsec = 0;
|
||||
}
|
||||
return error;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static device_method_t ds1374u_methods[] = {
|
||||
|
@ -62,7 +62,6 @@ __FBSDID("$FreeBSD$");
|
||||
struct max6657_softc {
|
||||
uint32_t sc_addr;
|
||||
device_t sc_dev;
|
||||
struct mtx sc_mtx;
|
||||
int sc_curtemp;
|
||||
int sc_lastupdate; /* in ticks */
|
||||
};
|
||||
@ -101,7 +100,6 @@ max6657_attach(device_t dev)
|
||||
}
|
||||
sc->sc_dev = dev;
|
||||
sc->sc_addr = iicbus_get_addr(dev);
|
||||
mtx_init(&sc->sc_mtx, "max6657", "max6657", MTX_DEF);
|
||||
|
||||
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
|
||||
"temp", CTLTYPE_INT | CTLFLAG_RD, sc, 0,
|
||||
@ -132,7 +130,6 @@ max6657_update(struct max6657_softc *sc)
|
||||
{
|
||||
int v;
|
||||
|
||||
mtx_lock(&sc->sc_mtx);
|
||||
/* NB: no point in updating any faster than the chip */
|
||||
if (ticks - sc->sc_lastupdate > hz) {
|
||||
v = max6657_read(sc->sc_dev, sc->sc_addr, MAX6657_EXT_TEMP);
|
||||
@ -140,7 +137,6 @@ max6657_update(struct max6657_softc *sc)
|
||||
sc->sc_curtemp = v;
|
||||
sc->sc_lastupdate = ticks;
|
||||
}
|
||||
mtx_unlock(&sc->sc_mtx);
|
||||
}
|
||||
|
||||
static device_method_t max6657_methods[] = {
|
||||
|
Loading…
Reference in New Issue
Block a user