Skip to content

Commit

Permalink
twsi: use twsi_error() to handle wrong bus status when starting
Browse files Browse the repository at this point in the history
(cherry picked from commit 46e0c03)
  • Loading branch information
avg-I committed Dec 26, 2021
1 parent 468043b commit fe3c037
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions sys/dev/iicbus/twsi/twsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down

0 comments on commit fe3c037

Please sign in to comment.