From owner-p4-projects@FreeBSD.ORG Wed Nov 22 02:12:31 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 0DCD616A416; Wed, 22 Nov 2006 02:12:31 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CABA116A407 for ; Wed, 22 Nov 2006 02:12:30 +0000 (UTC) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.FreeBSD.org (Postfix) with ESMTP id F0E6143D45 for ; Wed, 22 Nov 2006 02:12:04 +0000 (GMT) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id kAM2CU3Y000169 for ; Wed, 22 Nov 2006 02:12:30 GMT (envelope-from imp@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id kAM2CTvW000166 for perforce@freebsd.org; Wed, 22 Nov 2006 02:12:29 GMT (envelope-from imp@freebsd.org) Date: Wed, 22 Nov 2006 02:12:29 GMT Message-Id: <200611220212.kAM2CTvW000166@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to imp@freebsd.org using -f From: Warner Losh To: Perforce Change Reviews Cc: Subject: PERFORCE change 110355 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Nov 2006 02:12:31 -0000 http://perforce.freebsd.org/chv.cgi?CH=110355 Change 110355 by imp@imp_lighthouse on 2006/11/22 02:12:22 Remove useless junk that doesn't work. calculate clock divisors correctly. remove debugging busy wait faster. Affected files ... .. //depot/projects/arm/src/sys/arm/at91/at91_twi.c#28 edit Differences ... ==== //depot/projects/arm/src/sys/arm/at91/at91_twi.c#28 (text+ko) ==== @@ -227,133 +227,15 @@ at91_twi_wait(struct at91_twi_softc *sc, uint32_t bit) { int err = 0; - int counter = 10000; + int counter = 100000; while (!(RD4(sc, TWI_SR) & bit) && counter-- >= 0) - DELAY(10); + continue; if (counter <= 0) err = EIO; return (err); } -/* - * Stop the transfer by entering a STOP state on the iic bus. For read - * operations, we've already entered the STOP state, since we need to do - * that to read the last character. For write operations, we need to - * wait for the TXCOMP bit to turn on before returning. - */ -static int -at91_twi_stop(device_t dev) -{ - struct at91_twi_softc *sc; - int err = 0; - - sc = device_get_softc(dev); - if (sc->sc_started) { - WR4(sc, TWI_CR, TWI_CR_STOP); - err = at91_twi_wait(sc, TWI_SR_TXCOMP); - } - return (err); -} - -/* - * enter a START condition without requiring the device to be in a STOP - * state. - */ -static int -at91_twi_repeated_start(device_t dev, u_char slave, int timeout) -{ - struct at91_twi_softc *sc; - - sc = device_get_softc(dev); - WR4(sc, TWI_MMR, TWI_MMR_DADR(slave)); - return (0); -} - -/* - * enter a START condition from an idle state. - */ -static int -at91_twi_start(device_t dev, u_char slave, int timeout) -{ - struct at91_twi_softc *sc; - - sc = device_get_softc(dev); - WR4(sc, TWI_MMR, TWI_MMR_DADR(slave)); - sc->sc_started = 1; - return (0); -} - -static int -at91_twi_write(device_t dev, char *buf, int len, int *sent, int timeout /* us */) -{ - struct at91_twi_softc *sc; - uint8_t *walker; - int err = 0; - - walker = buf; - sc = device_get_softc(dev); - AT91_TWI_LOCK(sc); - WR4(sc, TWI_MMR, ~TWI_MMR_MREAD & RD4(sc, TWI_MMR)); - WR4(sc, TWI_CR, TWI_CR_START); - sc->sc_started = 1; -// WR4(sc, TWI_IER, TWI_SR_TXRDY); - while (len--) { - WR4(sc, TWI_THR, *walker++); - while (!(sc->flags & TXRDY)) { - err = msleep(sc, &sc->sc_mtx, PZERO | PCATCH, "twiwr", - 0); - if (err) - goto errout; - } - } -errout:; - WR4(sc, TWI_IDR, TWI_SR_TXRDY); - AT91_TWI_UNLOCK(sc); - return (err); -} - -static int -at91_twi_read(device_t dev, char *buf, int len, int *read, int last, - int delay /* us */) -{ - struct at91_twi_softc *sc; - char *walker; - int err = 0; - - walker = buf; - sc = device_get_softc(dev); - AT91_TWI_LOCK(sc); - WR4(sc, TWI_MMR, TWI_MMR_MREAD | RD4(sc, TWI_MMR)); - WR4(sc, TWI_CR, TWI_CR_START); - sc->sc_started = 1; -// WR4(sc, TWI_IER, TWI_SR_RXRDY); - while (len-- > 0) { - err = 0; - while (!(sc->flags & RXRDY)) { - err = msleep(sc, &sc->sc_mtx, PZERO | PCATCH, "twird", - 0); - if (err) - goto errout; - } - sc->flags &= ~RXRDY; - *walker++ = RD4(sc, TWI_RHR) & 0xff; - if (len == 1 && last) - break; - } - if (!last) - goto errout; - WR4(sc, TWI_CR, TWI_CR_STOP); - err = at91_twi_wait(sc, TWI_SR_TXCOMP); - *walker = RD4(sc, TWI_RHR) & 0xff; - if (read) - *read = walker - buf; -errout:; - WR4(sc, TWI_IDR, TWI_SR_RXRDY); - AT91_TWI_UNLOCK(sc); - return (err); -} - static int at91_twi_rst_card(device_t dev, u_char speed, u_char addr, u_char *oldaddr) { @@ -371,22 +253,21 @@ rate = 1; /* - * 8 * is because "rate == 1" -> 4 clocks down, 4 clocks up. The * speeds are for 1.5kb/s, 45kb/s and 90kb/s. */ switch (speed) { case IIC_SLOW: - ckdiv = 8 * AT91C_MASTER_CLOCK / 1500; + ckdiv = AT91C_MASTER_CLOCK / (1500 * 4) - 2; break; case IIC_FAST: - ckdiv = 8 * AT91C_MASTER_CLOCK / 45000; + ckdiv = AT91C_MASTER_CLOCK / (45000 * 4) - 2; break; case IIC_UNKNOWN: case IIC_FASTEST: default: - ckdiv = 8 * AT91C_MASTER_CLOCK / 90000; + ckdiv = AT91C_MASTER_CLOCK / (90000 * 4) - 2; break; } @@ -435,8 +316,6 @@ * See http://lists.arm.linux.org.uk/pipermail/linux-arm-kernel/2004-September/024411.html * for details. */ - printf("%d: flags %#x len %d buf %p\n", i, msgs[i].flags, - msgs[i].len, msgs[i].buf); rdwr = (msgs[i].flags & IIC_M_RD) ? TWI_MMR_MREAD : 0; WR4(sc, TWI_MMR, TWI_MMR_DADR(msgs[i].slave) | rdwr); len = msgs[i].len; @@ -448,10 +327,8 @@ while (len--) { if (len == 0) WR4(sc, TWI_CR, TWI_CR_STOP); - if (at91_twi_wait(sc, TWI_SR_RXRDY)) { - printf("1\n"); + if (at91_twi_wait(sc, TWI_SR_RXRDY)) return (EIO); - } *buf++ = RD4(sc, TWI_RHR) & 0xff; } } else { @@ -459,16 +336,12 @@ WR4(sc, TWI_THR, *buf++); if (len == 0) WR4(sc, TWI_CR, TWI_CR_STOP); - if (at91_twi_wait(sc, TWI_SR_TXRDY)) { - printf("3\n"); + if (at91_twi_wait(sc, TWI_SR_TXRDY)) return (EIO); - } } } - if (at91_twi_wait(sc, TWI_SR_TXCOMP)) { - printf("2\n"); + if (at91_twi_wait(sc, TWI_SR_TXCOMP)) return (EIO); - } } return (0); } @@ -481,11 +354,6 @@ /* iicbus interface */ DEVMETHOD(iicbus_callback, at91_twi_callback), - DEVMETHOD(iicbus_repeated_start, at91_twi_repeated_start), - DEVMETHOD(iicbus_start, at91_twi_start), - DEVMETHOD(iicbus_stop, at91_twi_stop), - DEVMETHOD(iicbus_write, at91_twi_write), - DEVMETHOD(iicbus_read, at91_twi_read), DEVMETHOD(iicbus_reset, at91_twi_rst_card), DEVMETHOD(iicbus_transfer, at91_twi_transfer), { 0, 0 }