From owner-svn-src-head@FreeBSD.ORG Tue Dec 20 02:49:02 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 14CEF106566C; Tue, 20 Dec 2011 02:49:02 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 03AC68FC17; Tue, 20 Dec 2011 02:49:02 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id pBK2n1HS087716; Tue, 20 Dec 2011 02:49:01 GMT (envelope-from adrian@svn.freebsd.org) Received: (from adrian@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id pBK2n1oR087714; Tue, 20 Dec 2011 02:49:01 GMT (envelope-from adrian@svn.freebsd.org) Message-Id: <201112200249.pBK2n1oR087714@svn.freebsd.org> From: Adrian Chadd Date: Tue, 20 Dec 2011 02:49:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r228728 - head/sys/dev/iicbus X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Dec 2011 02:49:02 -0000 Author: adrian Date: Tue Dec 20 02:49:01 2011 New Revision: 228728 URL: http://svn.freebsd.org/changeset/base/228728 Log: IIC bitbang changes - prepare to make the bit delay configurable; debug print changes. * Right now the delay is hard coded at 10uS. This is a bit long when doing lots of periodic i2c transactions. So create a 'udelay' parameter and initialise it to 10. This can be tuned later. * Add a newline after a transaction finishes, so the debugging output isn't so horrible. Modified: head/sys/dev/iicbus/iicbb.c Modified: head/sys/dev/iicbus/iicbb.c ============================================================================== --- head/sys/dev/iicbus/iicbb.c Tue Dec 20 02:42:53 2011 (r228727) +++ head/sys/dev/iicbus/iicbb.c Tue Dec 20 02:49:01 2011 (r228728) @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); struct iicbb_softc { device_t iicbus; + int udelay; /* signal toggle delay in usec */ }; static int iicbb_attach(device_t); @@ -123,6 +124,7 @@ iicbb_attach(device_t dev) sc->iicbus = device_add_child(dev, "iicbus", -1); if (!sc->iicbus) return (ENXIO); + sc->udelay = 10; /* 10 uS default */ bus_generic_attach(dev); return (0); @@ -184,20 +186,18 @@ iicbb_print_child(device_t bus, device_t return (retval); } -#define IIC_DELAY 10 - -#define I2C_SETSDA(dev,val) do { \ +#define I2C_SETSDA(sc,dev,val) do { \ IICBB_SETSDA(device_get_parent(dev), val); \ - DELAY(IIC_DELAY); \ + DELAY(sc->udelay); \ } while (0) #define I2C_SETSCL(dev,val) do { \ iicbb_setscl(dev, val, 100); \ } while (0) -#define I2C_SET(dev,ctrl,data) do { \ +#define I2C_SET(sc,dev,ctrl,data) do { \ I2C_SETSCL(dev, ctrl); \ - I2C_SETSDA(dev, data); \ + I2C_SETSDA(sc, dev, data); \ } while (0) #define I2C_GETSDA(dev) (IICBB_GETSDA(device_get_parent(dev))) @@ -216,34 +216,39 @@ static int i2c_debug = 0; static void iicbb_setscl(device_t dev, int val, int timeout) { + struct iicbb_softc *sc = device_get_softc(dev); int k = 0; IICBB_SETSCL(device_get_parent(dev), val); - DELAY(IIC_DELAY); + DELAY(sc->udelay); while (val && !I2C_GETSCL(dev) && k++ < timeout) { IICBB_SETSCL(device_get_parent(dev), val); - DELAY(IIC_DELAY); + DELAY(sc->udelay); } - + return; } static void iicbb_one(device_t dev, int timeout) { - I2C_SET(dev,0,1); - I2C_SET(dev,1,1); - I2C_SET(dev,0,1); + struct iicbb_softc *sc = device_get_softc(dev); + + I2C_SET(sc,dev,0,1); + I2C_SET(sc,dev,1,1); + I2C_SET(sc,dev,0,1); return; } static void iicbb_zero(device_t dev, int timeout) { - I2C_SET(dev,0,0); - I2C_SET(dev,1,0); - I2C_SET(dev,0,0); + struct iicbb_softc *sc = device_get_softc(dev); + + I2C_SET(sc,dev,0,0); + I2C_SET(sc,dev,1,0); + I2C_SET(sc,dev,0,0); return; } @@ -264,20 +269,21 @@ iicbb_zero(device_t dev, int timeout) static int iicbb_ack(device_t dev, int timeout) { + struct iicbb_softc *sc = device_get_softc(dev); int noack; int k = 0; - - I2C_SET(dev,0,1); - I2C_SET(dev,1,1); + + I2C_SET(sc,dev,0,1); + I2C_SET(sc,dev,1,1); do { noack = I2C_GETSDA(dev); if (!noack) break; - DELAY(10); - k += 10; + DELAY(1); + k++; } while (k < timeout); - I2C_SET(dev,0,1); + I2C_SET(sc,dev,0,1); I2C_DEBUG(printf("%c ",noack?'-':'+')); return (noack); @@ -302,16 +308,17 @@ iicbb_sendbyte(device_t dev, u_char data static u_char iicbb_readbyte(device_t dev, int last, int timeout) { + struct iicbb_softc *sc = device_get_softc(dev); int i; unsigned char data=0; - - I2C_SET(dev,0,1); + + I2C_SET(sc,dev,0,1); for (i=7; i>=0; i--) { - I2C_SET(dev,1,1); + I2C_SET(sc,dev,1,1); if (I2C_GETSDA(dev)) data |= (1<")); + I2C_DEBUG(printf("\n")); return (0); }