aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndriy Gapon <avg@FreeBSD.org>2021-11-26 07:30:38 +0000
committerAndriy Gapon <avg@FreeBSD.org>2021-11-26 14:15:43 +0000
commitcb167e1ae95473d836393a07456d8dbcfbb7f758 (patch)
tree48727438c1b859b960a4fde4523c8d35599cb2c1
parentbc02583c4dd65275da89838a723bd3514cb316cf (diff)
downloadsrc-cb167e1ae95473d836393a07456d8dbcfbb7f758.tar.gz
src-cb167e1ae95473d836393a07456d8dbcfbb7f758.zip
twsi: do not attempt transfer if bus is not idle
MFC after: 2 weeks
-rw-r--r--sys/dev/iicbus/twsi/twsi.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/sys/dev/iicbus/twsi/twsi.c b/sys/dev/iicbus/twsi/twsi.c
index 05f67786cad0..5e899313ac45 100644
--- a/sys/dev/iicbus/twsi/twsi.c
+++ b/sys/dev/iicbus/twsi/twsi.c
@@ -484,6 +484,7 @@ static int
twsi_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
{
struct twsi_softc *sc;
+ uint32_t status;
int error;
sc = device_get_softc(dev);
@@ -496,7 +497,15 @@ twsi_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
("starting a transfer while another is active"));
debugf(sc, "transmitting %d messages\n", nmsgs);
- debugf(sc, "status=%x\n", TWSI_READ(sc, sc->reg_status));
+ status = TWSI_READ(sc, sc->reg_status);
+ debugf(sc, "status=0x%x\n", status);
+ if (status != TWSI_STATUS_IDLE) {
+ debugf(sc, "Bad status at start of transfer\n");
+ TWSI_WRITE(sc, sc->reg_control, TWSI_CONTROL_STOP);
+ mtx_unlock(&sc->mutex);
+ return (IIC_ESTATUS);
+ }
+
sc->nmsgs = nmsgs;
sc->msgs = msgs;
sc->msg_idx = 0;