Module Name:    src
Committed By:   jdc
Date:           Wed Dec 16 08:04:58 UTC 2015

Modified Files:
        src/sys/dev/ic: pcf8584.c

Log Message:
Allow pcfiic to handle i2c writes using cmdbuf for the register, and buf for
the value to be written.  Prior to this, we would send an empty write command
to the correct i2c address, plus an empty write command to the device at the
i2c address of the first byte of buf.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/ic/pcf8584.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ic/pcf8584.c
diff -u src/sys/dev/ic/pcf8584.c:1.11 src/sys/dev/ic/pcf8584.c:1.12
--- src/sys/dev/ic/pcf8584.c:1.11	Mon Jan 20 22:02:32 2014
+++ src/sys/dev/ic/pcf8584.c	Wed Dec 16 08:04:58 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcf8584.c,v 1.11 2014/01/20 22:02:32 jdc Exp $	*/
+/*	$NetBSD: pcf8584.c,v 1.12 2015/12/16 08:04:58 jdc Exp $	*/
 /*	$OpenBSD: pcf8584.c,v 1.9 2007/10/20 18:46:21 kettenis Exp $ */
 
 /*
@@ -175,14 +175,28 @@ pcfiic_i2c_exec(void *arg, i2c_op_t op, 
 	if (sc->sc_master)
 		pcfiic_choose_bus(sc, addr >> 7);
 
-	if (pcfiic_xmit(sc, addr & 0x7f, cmdbuf, cmdlen) != 0)
-		return (1);
-
-	if (len > 0) {
-		if (I2C_OP_WRITE_P(op))
-			ret = pcfiic_xmit(sc, addr & 0x7f, buf, len);
-		else
-			ret = pcfiic_recv(sc, addr & 0x7f, buf, len);
+	/*
+	 * If we are writing, write address, cmdbuf, buf.
+	 * If we are reading, write address, cmdbuf, then read address, buf.
+	 */
+	if (I2C_OP_WRITE_P(op)) {
+		if (len > 0) {
+			uint8_t *tmp;
+
+			tmp = malloc(cmdlen + len, M_DEVBUF,
+			   flags & I2C_F_POLL ? M_NOWAIT : M_WAITOK);
+			if (tmp == NULL)
+				return (1);
+			memcpy(tmp, cmdbuf, cmdlen);
+			memcpy(tmp + cmdlen, buf, len);
+			ret = pcfiic_xmit(sc, addr & 0x7f, tmp, cmdlen + len);
+			free(tmp, M_DEVBUF);
+		} else
+			ret = pcfiic_xmit(sc, addr & 0x7f, cmdbuf, cmdlen);
+	} else {
+		if (pcfiic_xmit(sc, addr & 0x7f, cmdbuf, cmdlen) != 0)
+			return (1);
+		ret = pcfiic_recv(sc, addr & 0x7f, buf, len);
 	}
 	return (ret);
 }

Reply via email to