Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ic Allow pcfiic to handle i2c writes using cmdbuf fo...



details:   https://anonhg.NetBSD.org/src/rev/2eb4a525a327
branches:  trunk
changeset: 812454:2eb4a525a327
user:      jdc <jdc%NetBSD.org@localhost>
date:      Wed Dec 16 08:04:58 2015 +0000

description:
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.

diffstat:

 sys/dev/ic/pcf8584.c |  30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)

diffs (45 lines):

diff -r d785799ab9be -r 2eb4a525a327 sys/dev/ic/pcf8584.c
--- a/sys/dev/ic/pcf8584.c      Wed Dec 16 08:01:19 2015 +0000
+++ b/sys/dev/ic/pcf8584.c      Wed Dec 16 08:04:58 2015 +0000
@@ -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 @@
        if (sc->sc_master)
                pcfiic_choose_bus(sc, addr >> 7);
 
-       if (pcfiic_xmit(sc, addr & 0x7f, cmdbuf, cmdlen) != 0)
-               return (1);
+       /*
+        * 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;
 
-       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);
+                       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);
 }



Home | Main Index | Thread Index | Old Index