From owner-p4-projects@FreeBSD.ORG Tue Nov 28 23:29:00 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 C953316A416; Tue, 28 Nov 2006 23:29:00 +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 8208D16A412 for ; Tue, 28 Nov 2006 23:29:00 +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 1EC8E43CA0 for ; Tue, 28 Nov 2006 23:28:55 +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 kASNT0M7018232 for ; Tue, 28 Nov 2006 23:29:00 GMT (envelope-from imp@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id kASNSxlU018227 for perforce@freebsd.org; Tue, 28 Nov 2006 23:28:59 GMT (envelope-from imp@freebsd.org) Date: Tue, 28 Nov 2006 23:28:59 GMT Message-Id: <200611282328.kASNSxlU018227@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 110643 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: Tue, 28 Nov 2006 23:29:01 -0000 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; }