summaryrefslogtreecommitdiff
path: root/sys/dev/ic/dwiic.c
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2020-01-11 20:07:41 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2020-01-11 20:07:41 +0000
commitbacb90c0ce9e1b43e210fa6400ea8faadfc2a5e1 (patch)
treef3ff28d82aef97ecaf5500e1be79c82b4c86c67f /sys/dev/ic/dwiic.c
parent6bc25e07e8eafe6955260c77cdeac3da96ba529b (diff)
Implement block mode. Tweak an error message while there.
ok claudio@
Diffstat (limited to 'sys/dev/ic/dwiic.c')
-rw-r--r--sys/dev/ic/dwiic.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/sys/dev/ic/dwiic.c b/sys/dev/ic/dwiic.c
index bae04efa0fa..5bae719330c 100644
--- a/sys/dev/ic/dwiic.c
+++ b/sys/dev/ic/dwiic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dwiic.c,v 1.8 2019/08/18 15:52:45 kettenis Exp $ */
+/* $OpenBSD: dwiic.c,v 1.9 2020/01/11 20:07:40 kettenis Exp $ */
/*
* Synopsys DesignWare I2C controller
*
@@ -338,6 +338,13 @@ dwiic_i2c_exec(void *cookie, i2c_op_t op, i2c_addr_t addr, const void *cmdbuf,
dwiic_write(sc, DW_IC_DATA_CMD, cmd);
+ /*
+ * For a block read, get the byte count before
+ * continuing to read the data bytes.
+ */
+ if (I2C_OP_READ_P(op) && I2C_OP_BLKMODE_P(op) && readpos == 0)
+ tx_limit = 1;
+
tx_limit--;
x++;
@@ -374,8 +381,7 @@ dwiic_i2c_exec(void *cookie, i2c_op_t op, i2c_addr_t addr, const void *cmdbuf,
if (rx_avail == 0) {
printf("%s: timed out reading remaining %d\n",
- sc->sc_dev.dv_xname,
- (int)(len - 1 - readpos));
+ sc->sc_dev.dv_xname, (int)(len - readpos));
sc->sc_i2c_xfer.error = 1;
sc->sc_busy = 0;
@@ -395,6 +401,13 @@ dwiic_i2c_exec(void *cookie, i2c_op_t op, i2c_addr_t addr, const void *cmdbuf,
rx_avail--;
}
+ /*
+ * Update the transfer length when doing a
+ * block read.
+ */
+ if (I2C_OP_BLKMODE_P(op) && readpos > 0 && len > b[0])
+ len = b[0] + 1;
+
if (readpos >= len)
break;