Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 06 Jun 2010 10:02:31 -0500
From:      Nathan Whitehorn <nwhitehorn@freebsd.org>
To:        freebsd-embedded@freebsd.org
Subject:   Review request: iicbus_transfer_gen() repeated start support
Message-ID:  <4C0BB887.5070103@freebsd.org>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.

--Boundary_(ID_Ft8RPkqIzUB3Osaxs5gnOg)
Content-type: text/plain; CHARSET=US-ASCII; format=flowed
Content-transfer-encoding: 7BIT

I committed yesterday some changes to the iicbus_transfer() API that 
allow using that interface to send messages containing repeated starts. 
The attached patch implements this for the iicbus_transfer_gen() case, 
but I don't have any I2C controllers that use this routine, so I can't 
test it. I would much appreciate it if someone could review and test the 
patch for me.
-Nathan

--Boundary_(ID_Ft8RPkqIzUB3Osaxs5gnOg)
Content-type: text/plain; name=iicbus_transfer_gen.diff
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=iicbus_transfer_gen.diff

Index: iiconf.c
===================================================================
--- iiconf.c	(revision 208832)
+++ iiconf.c	(working copy)
@@ -363,7 +363,7 @@
 int
 iicbus_transfer_gen(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
 {
-	int i, error, lenread, lenwrote, nkid;
+	int i, error, lenread, lenwrote, nkid, rpstart, addr;
 	device_t *children, bus;
 
 	if ((error = device_get_children(dev, &children, &nkid)) != 0)
@@ -373,14 +373,38 @@
 		return (EIO);
 	}
 	bus = children[0];
+	rpstart = 0;
 	free(children, M_TEMP);
 	for (i = 0, error = 0; i < nmsgs && error == 0; i++) {
+		addr = msgs[i].slave;
 		if (msgs[i].flags & IIC_M_RD)
-			error = iicbus_block_read(bus, msgs[i].slave,
-			    msgs[i].buf, msgs[i].len, &lenread);
+			addr |= LSB;
 		else
-			error = iicbus_block_write(bus, msgs[i].slave,
-			    msgs[i].buf, msgs[i].len, &lenwrote);
+			addr &= ~LSB;
+
+		if (!(msgs[i].flags & IIC_M_NOSTART)) {
+			if (rpstart)
+				error = iicbus_repeated_start(bus, addr, 0);
+			else
+				error = iicbus_start(bus, addr, 0);
+		}
+
+		if (error)
+			break;
+
+		if (msgs[i].flags & IIC_M_RD)
+			error = iicbus_read(bus, msgs[i].buf, msgs[i].len,
+			    &lenread, IIC_LAST_READ, 0);
+		else
+			error = iicbus_write(bus, msgs[i].buf, msgs[i].len,
+			    &lenwrote, 0);
+
+		if (!(msgs[i].flags & IIC_M_NOSTOP)) {
+			rpstart = 0;
+			iicbus_stop(bus);
+		} else {
+			rpstart = 1;	/* Next message gets repeated start */
+		}
 	}
 	return (error);
 }

--Boundary_(ID_Ft8RPkqIzUB3Osaxs5gnOg)--



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