diff --git a/sys/dev/iicbus/iichid.c b/sys/dev/iicbus/iichid.c --- a/sys/dev/iicbus/iichid.c +++ b/sys/dev/iicbus/iichid.c @@ -98,6 +98,8 @@ #define I2C_HID_POWER_ON 0x0 #define I2C_HID_POWER_OFF 0x1 +#define IICHID_RESET_TIMEOUT 5 /* seconds */ + /* * Since interrupt resource acquisition is not always possible (in case of GPIO * interrupts) iichid now supports a sampling_mode. @@ -190,6 +192,7 @@ bool open; /* iicbus lock */ bool suspend; /* iicbus lock */ bool power_on; /* iicbus lock */ + bool reset_acked; /* bus_topo_mtx */ }; static device_probe_t iichid_probe; @@ -295,6 +298,12 @@ { sc->addr, IIC_M_RD | IIC_M_NOSTART, le16toh(sc->desc.wMaxInputLength) - 2, sc->intr_buf }; actlen = 0; + if (!sc->reset_acked) { + bus_topo_lock(); + sc->reset_acked = true; + wakeup(&sc->reset_acked); + bus_topo_unlock(); + } #ifdef IICHID_SAMPLING } else if ((actlen <= 2 || actlen == 0xFFFF) && sc->sampling_rate_slow >= 0) { @@ -1136,19 +1145,6 @@ device_printf(dev, "failed to power on: %d\n", error); return (ENXIO); } - /* - * Windows driver sleeps for 1ms between the SET_POWER and RESET - * commands. So we too as some devices may depend on this. - */ - pause("iichid", (hz + 999) / 1000); - - error = iichid_reset(sc); - if (error) { - device_printf(dev, "failed to reset hardware: %d\n", error); - error = ENXIO; - goto done; - } - sc->power_on = true; sc->intr_bufsize = le16toh(sc->desc.wMaxInputLength) - 2; @@ -1209,12 +1205,35 @@ &sc->sampling_hysteresis, 0, "number of missing samples before enabling of slow mode"); hid_add_dynamic_quirk(&sc->hw, HQ_IICHID_SAMPLING); +#endif /* IICHID_SAMPLING */ + + /* + * Windows driver sleeps for 1ms between the SET_POWER and RESET + * commands. So we too as some devices may depend on this. + */ + pause("iichid", (hz + 999) / 1000); + error = iichid_reset(sc); + if (error) { + device_printf(dev, "failed to reset hardware: %d\n", error); + iichid_detach(dev); + error = ENXIO; + goto done; + } + + /* Wait for RESET response */ +#ifdef IICHID_SAMPLING if (sc->sampling_rate_slow >= 0) { pause("iichid", (hz + 999) / 1000); (void)iichid_cmd_read(sc, sc->intr_buf, 0, NULL); - } + } else #endif /* IICHID_SAMPLING */ + if (!sc->reset_acked && !cold) { + error = mtx_sleep(&sc->reset_acked, bus_topo_mtx(), 0, + "iichid_reset", hz * IICHID_RESET_TIMEOUT); + if (error != 0) + device_printf(sc->dev, "Reset timeout expired\n"); + } child = device_add_child(dev, "hidbus", DEVICE_UNIT_ANY); if (child == NULL) {