Date: Tue, 28 Nov 2006 21:45:45 GMT From: Warner Losh <imp@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 110636 for review Message-ID: <200611282145.kASLjjXv096334@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=110636 Change 110636 by imp@imp_lighthouse on 2006/11/28 21:45:33 Make write work reliably. Better optimizations Affected files ... .. //depot/projects/arm/src/sys/dev/iicbus/icee.c#5 edit Differences ... ==== //depot/projects/arm/src/sys/dev/iicbus/icee.c#5 (text+ko) ==== @@ -154,19 +154,21 @@ struct icee_softc *sc; uint8_t addr[2]; uint8_t data[MAX_RD_SZ]; - int error, i, len; + int error, i, len, slave; struct iic_msg msgs[2] = { { 0, IIC_M_WR, 1, addr }, { 0, IIC_M_RD, 0, data }, }; sc = CDEV2SOFTC(dev); - if (uio->uio_offset >= sc->size) + if (uio->uio_offset == sc->size) + return (0); + if (uio->uio_offset > sc->size) return (EIO); if (sc->type != 8 && sc->type != 16) return (EINVAL); ICEE_LOCK(sc); - error = 0; + slave = error = 0; while (uio->uio_resid > 0) { if (uio->uio_offset >= sc->size) break; @@ -174,22 +176,21 @@ uio->uio_resid); switch (sc->type) { case 8: - for (i = 0; i < 2; i++) - msgs[i].slave = uio->uio_offset >> 8 | sc->addr; + slave = (uio->uio_offset >> 8) | sc->addr; msgs[0].len = 1; msgs[1].len = len; addr[0] = uio->uio_offset & 0xff; break; case 16: - for (i = 0; i < 2; i++) - msgs[i].slave = sc->addr | - uio->uio_offset >> 16; + slave = sc->addr | (uio->uio_offset >> 16); msgs[0].len = 2; msgs[1].len = len; addr[0] = (uio->uio_offset >> 8) & 0xff; addr[1] = uio->uio_offset & 0xff; break; } + for (i = 0; i < 2; i++) + msgs[i].slave = slave; error = iicbus_transfer(sc->sc_dev, msgs, 2); if (error) break; @@ -211,7 +212,7 @@ icee_write(struct cdev *dev, struct uio *uio, int ioflag) { struct icee_softc *sc; - int error, len, i; + int error, len, i, slave; uint8_t data[MAX_WR_SZ + 2]; struct iic_msg msgs[3] = { { 0, IIC_M_WR, 0, data }, @@ -219,38 +220,37 @@ }; sc = CDEV2SOFTC(dev); + if (uio->uio_offset == sc->size) + return (0); if (uio->uio_offset > sc->size) return (EIO); if (sc->type != 8 && sc->type != 16) return (EINVAL); ICEE_LOCK(sc); - error = 0; + slave = error = 0; while (uio->uio_resid > 0) { if (uio->uio_offset >= sc->size) break; len = MIN(sc->wr_sz - (uio->uio_offset & (sc->wr_sz - 1)), uio->uio_resid); - error = uiomove(data + sc->type / 8, len, uio); - if (error) - break; switch (sc->type) { case 8: - for (i = 0; i < 2; i++) - msgs[i].slave = uio->uio_offset >> 8 | sc->addr; + slave = (uio->uio_offset >> 8) | sc->addr; msgs[0].len = 1 + len; - msgs[1].len = 0; data[0] = uio->uio_offset & 0xff; break; case 16: - for (i = 0; i < 2; i++) - msgs[i].slave = sc->addr | - uio->uio_offset >> 16; + slave = sc->addr | (uio->uio_offset >> 16); msgs[0].len = 2 + len; - msgs[1].len = 0; data[0] = (uio->uio_offset >> 8) & 0xff; data[1] = uio->uio_offset & 0xff; break; } + for (i = 0; i < 2; i++) + msgs[i].slave = slave; + error = uiomove(data + sc->type / 8, len, uio); + if (error) + break; error = iicbus_transfer(sc->sc_dev, msgs, 2); if (error) break;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200611282145.kASLjjXv096334>