Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Apr 2006 17:42:45 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 94619 for review
Message-ID:  <200604041742.k34HgjOc079454@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=94619

Change 94619 by imp@imp_Speedy on 2006/04/04 17:41:55

	Can only enable the TXRDY, RXRDY and TXCOMP interrupts while the
	bus isn't idle...

Affected files ...

.. //depot/projects/arm/src/sys/arm/at91/at91_twi.c#13 edit

Differences ...

==== //depot/projects/arm/src/sys/arm/at91/at91_twi.c#13 (text+ko) ====

@@ -54,7 +54,6 @@
 	struct mtx sc_mtx;		/* basically a perimeter lock */
 	int flags;
 #define RXRDY		4
-#define STOP_DONE	8
 #define TXRDY		0x10
 	uint32_t cwgr;
 	int	sc_started;
@@ -134,8 +133,8 @@
 	WR4(sc, TWI_CR, TWI_CR_MSEN | TWI_CR_SVDIS);
 	WR4(sc, TWI_CWGR, sc->cwgr);
 
-	WR4(sc, TWI_IER, TWI_SR_TXCOMP | TWI_SR_RXRDY | TWI_SR_TXRDY |
-	  TWI_SR_OVRE | TWI_SR_UNRE | TWI_SR_NACK);
+	WR4(sc, TWI_IER, TWI_SR_RXRDY | TWI_SR_OVRE | TWI_SR_UNRE |
+	    TWI_SR_NACK);
 
 	if ((sc->iicbus = device_add_child(dev, "iicbus", -1)) == NULL)
 		device_printf(dev, "could not allocate iicbus instance\n");
@@ -215,13 +214,12 @@
 
 	/* Reading the status also clears the interrupt */
 	status = RD4(sc, TWI_SR);
+	printf("status %x\n", status);
 	if (status == 0)
 		return;
 	AT91_TWI_LOCK(sc);
 	if (status & TWI_SR_RXRDY)
 		sc->flags |= RXRDY;
-	if (status & TWI_SR_TXCOMP)
-		sc->flags |= STOP_DONE;
 	if (status & TWI_SR_TXRDY)
 		sc->flags |= TXRDY;
 	AT91_TWI_UNLOCK(sc);
@@ -234,12 +232,8 @@
 {
 	int err = 0;
 
-	while (!(sc->flags & STOP_DONE)) {
-		err = msleep(sc, &sc->sc_mtx, PZERO | PCATCH, "twiwsd", 0);
-		if (err)
-			break;
-	}
-	sc->flags &= ~STOP_DONE;
+	while (!(RD4(sc, TWI_SR) & TWI_SR_TXCOMP))
+		continue;
 	return (err);
 }
 
@@ -305,6 +299,7 @@
 	sc = device_get_softc(dev);
 	WR4(sc, TWI_MMR, TWI_MMR_MWRITE | RD4(sc, TWI_MMR));
 	AT91_TWI_LOCK(sc);
+	WR4(sc, TWI_IER, TWI_SR_TXRDY);
 	while (len--) {
 		WR4(sc, TWI_THR, *walker++);
 		while (!(sc->flags & TXRDY)) {
@@ -315,6 +310,7 @@
 		}
 	}
 errout:;
+	WR4(sc, TWI_IDR, TWI_SR_TXRDY);
 	AT91_TWI_UNLOCK(sc);
 	return (err);
 }
@@ -331,6 +327,7 @@
 	sc = device_get_softc(dev);
 	AT91_TWI_LOCK(sc);
 	WR4(sc, TWI_MMR, ~TWI_MMR_MWRITE & RD4(sc, TWI_MMR));
+	WR4(sc, TWI_IER, TWI_SR_RXRDY);
 	while (len-- > 0) {
 		err = 0;
 		while (!(sc->flags & RXRDY)) {
@@ -353,6 +350,7 @@
 		*read = walker - buf;
 	sc->sc_started = 0;
 errout:;
+	WR4(sc, TWI_IDR, TWI_SR_RXRDY);
 	AT91_TWI_UNLOCK(sc);
 	return (err);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604041742.k34HgjOc079454>