Date: Thu, 5 Sep 2019 19:17:54 +0000 (UTC) From: Ian Lepore <ian@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351887 - head/sys/dev/iicbus Message-ID: <201909051917.x85JHs2G088821@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201909051917.x85JHs2G088821>