diff options
| author | jdc <jdc@NetBSD.org> | 2015-12-16 08:04:58 +0000 |
|---|---|---|
| committer | jdc <jdc@NetBSD.org> | 2015-12-16 08:04:58 +0000 |
| commit | 7f9787d3ae5a72fb38347cbfac2dac59be683073 (patch) | |
| tree | a7d76fcd1bccfdb7dd30e402ab65e6facb5e2bf9 /sys/dev | |
| parent | e202c69a9c31102c8a3fade954f3026c79918be9 (diff) | |
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 (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/ic/pcf8584.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/sys/dev/ic/pcf8584.c b/sys/dev/ic/pcf8584.c index f61e126c202..966361d583b 100644 --- a/sys/dev/ic/pcf8584.c +++ b/sys/dev/ic/pcf8584.c @@ -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, i2c_addr_t addr, 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); } |
