Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Nov 2006 23:28:59 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 110643 for review
Message-ID:  <200611282328.kASNSxlU018227@repoman.freebsd.org>

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

Change 110643 by imp@imp_lighthouse on 2006/11/28 23:28:36

	calculate the cwgr more correctly.  I believe what I'm doing is
	mathematically the same as the linux driver w/o the bugs and
	obfuscation.
	
	Go back to busy waiting.  IT doesn't cost much, and actually
	works.  The interrupt version happened too slowly.

Affected files ...

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

Differences ...

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

@@ -222,16 +222,12 @@
 static int
 at91_twi_wait(struct at91_twi_softc *sc, uint32_t bit)
 {
-	int err;
+	int err = 0;
+	int counter = 100000;
 
-	sc->flags = 0;
-	WR4(sc, TWI_IER, bit);
-	err = msleep(sc, &sc->sc_mtx, PZERO | PCATCH, "iic", MAX(1,hz/10));
-	if (sc->flags & ~bit)
-		err = EIO;
-	else if (sc->flags & bit)
-		err = 0;
-	else if (err == 0)
+	while (!(RD4(sc, TWI_SR) & bit) && counter-- > 0)
+		continue;
+	if (counter <= 0)
 		err = EBUSY;
 	return (err);
 }
@@ -240,7 +236,7 @@
 at91_twi_rst_card(device_t dev, u_char speed, u_char addr, u_char *oldaddr)
 {
 	struct at91_twi_softc *sc;
-	int ckdiv, rate;
+	int clk;
 
 	sc = device_get_softc(dev);
 	if (oldaddr)
@@ -250,32 +246,30 @@
 	else
 		sc->twi_addr = addr;
 
-	rate = 1;
-	
 	/*
 	 * speeds are for 1.5kb/s, 45kb/s and 90kb/s.
 	 */
 	switch (speed) {
 	case IIC_SLOW:
-		ckdiv = AT91C_MASTER_CLOCK / (1500 * 4) - 2;
+		clk = 1500;
 		break;
 
 	case IIC_FAST:
-		ckdiv = AT91C_MASTER_CLOCK / (45000 * 4) - 2;
+		clk = 45000;
 		break;
 
 	case IIC_UNKNOWN:
 	case IIC_FASTEST:
 	default:
-		ckdiv = AT91C_MASTER_CLOCK / (90000 * 4) - 2;
+		clk = 90000;
 		break;
 	}
-
-	sc->cwgr = TWI_CWGR_CKDIV(ckdiv) | TWI_CWGR_CHDIV(TWI_CWGR_DIV(rate)) |
-	    TWI_CWGR_CLDIV(TWI_CWGR_DIV(rate));
+	sc->cwgr = TWI_CWGR_CKDIV(1) | TWI_CWGR_CHDIV(TWI_CWGR_DIV(clk)) |
+	    TWI_CWGR_CLDIV(TWI_CWGR_DIV(clk));
 	WR4(sc, TWI_CR, TWI_CR_SWRST);
 	WR4(sc, TWI_CR, TWI_CR_MSEN | TWI_CR_SVDIS);
 	WR4(sc, TWI_CWGR, sc->cwgr);
+	printf("setting cwgr to %#x\n", sc->cwgr);
 
 	return 0;
 }



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