svn commit: r351887 - head/sys/dev/iicbus
Ian Lepore
ian at FreeBSD.org
Thu Sep 5 19:17:54 UTC 2019
Author: ian
Date: Thu Sep 5 19:17:53 2019
New Revision: 351887
URL: https://svnweb.freebsd.org/changeset/base/351887
Log:
Use a single write of 3 bytes instead of iicdev_writeto() in ads111x.
The iicdev_writeto() function basically does scatter-gather IO by filling
in a pair of iic_msg structs to write the register address then the data
from different locations but with a single bus START/xfer/STOP sequence.
It turns out several low-level i2c controller drivers do not honor the
IIC_NOSTART flag, so the second piece of the write gets a new START on
the bus, and that confuses the ads111x chips which expect a continuous
write of 3 bytes to set a register.
A proper fix for this is to track down all the misbehaving controllers
drivers and fix them. For now this change makes this driver work again.
Modified:
head/sys/dev/iicbus/ads111x.c
Modified: head/sys/dev/iicbus/ads111x.c
==============================================================================
--- head/sys/dev/iicbus/ads111x.c Thu Sep 5 19:17:17 2019 (r351886)
+++ head/sys/dev/iicbus/ads111x.c Thu Sep 5 19:17:53 2019 (r351887)
@@ -167,11 +167,21 @@ struct ads111x_softc {
static int
ads111x_write_2(struct ads111x_softc *sc, int reg, int val)
{
- uint8_t data[2];
+ uint8_t data[3];
+ struct iic_msg msgs[1];
+ uint8_t slaveaddr;
- be16enc(data, val);
+ slaveaddr = iicbus_get_addr(sc->dev);
- return (iic2errno(iicdev_writeto(sc->dev, reg, data, 2, IIC_WAIT)));
+ data[0] = reg;
+ be16enc(&data[1], val);
+
+ msgs[0].slave = slaveaddr;
+ msgs[0].flags = IIC_M_WR;
+ msgs[0].len = sizeof(data);
+ msgs[0].buf = data;
+
+ return (iicbus_transfer_excl(sc->dev, msgs, nitems(msgs), IIC_WAIT));
}
static int
More information about the svn-src-head
mailing list