diff --git a/sys/dev/iicbus/controller/vybrid/vf_i2c.c b/sys/dev/iicbus/controller/vybrid/vf_i2c.c --- a/sys/dev/iicbus/controller/vybrid/vf_i2c.c +++ b/sys/dev/iicbus/controller/vybrid/vf_i2c.c @@ -207,13 +207,6 @@ sc = device_get_softc(dev); vf_i2c_dbg(sc, "i2c detach\n"); - mtx_lock(&sc->mutex); - - if (sc->freq == 0) { - vf_i2c_dbg(sc, "Writing 0x00 to clock divider register\n"); - WRITE1(sc, I2C_IBFD, 0x00); - } - error = bus_generic_detach(dev); if (error != 0) { device_printf(dev, "cannot detach child devices.\n"); @@ -226,6 +219,13 @@ return (error); } + mtx_lock(&sc->mutex); + + if (sc->freq == 0) { + vf_i2c_dbg(sc, "Writing 0x00 to clock divider register\n"); + WRITE1(sc, I2C_IBFD, 0x00); + } + bus_release_resources(dev, i2c_spec, sc->res); mtx_unlock(&sc->mutex);