twsi: use twsi_error() to handle wrong bus status when starting

MFC after:	1 week
This commit is contained in:
Andriy Gapon 2021-12-19 11:28:02 +02:00
parent e5268c3d43
commit 46e0c03795

View File

@ -480,6 +480,19 @@ twsi_write(device_t dev, const char *buf, int len, int *sent, int timeout)
return (rv);
}
static void
twsi_error(struct twsi_softc *sc, int err)
{
/*
* Must send stop condition to abort the current transfer.
*/
debugf(sc, "Sending STOP condition for error %d\n", err);
sc->transfer = 0;
sc->error = err;
sc->control_val = 0;
TWSI_WRITE(sc, sc->reg_control, sc->control_val | TWSI_CONTROL_STOP);
}
static int
twsi_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
{
@ -501,9 +514,8 @@ twsi_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
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);
twsi_error(sc, IIC_ESTATUS);
goto end;
}
sc->nmsgs = nmsgs;
@ -531,6 +543,7 @@ twsi_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
if (sc->error != 0)
debugf(sc, "Error: %d\n", sc->error);
end:
/* Disable module and interrupts */
debugf(sc, "status=0x%x\n", TWSI_READ(sc, sc->reg_status));
TWSI_WRITE(sc, sc->reg_control, 0);
@ -541,19 +554,6 @@ twsi_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
return (error);
}
static void
twsi_error(struct twsi_softc *sc, int err)
{
/*
* Must send stop condition to abort the current transfer.
*/
debugf(sc, "Sending STOP condition for error %d\n", err);
sc->transfer = 0;
sc->error = err;
sc->control_val = 0;
TWSI_WRITE(sc, sc->reg_control, sc->control_val | TWSI_CONTROL_STOP);
}
static void
twsi_intr(void *arg)
{