Index: sys/dev/i2c/dbcool.c =================================================================== RCS file: /cvsroot/src/sys/dev/i2c/dbcool.c,v retrieving revision 1.52 diff -p -u -r1.52 dbcool.c --- sys/dev/i2c/dbcool.c 26 Jun 2018 06:03:57 -0000 1.52 +++ sys/dev/i2c/dbcool.c 1 Feb 2019 01:48:24 -0000 @@ -825,8 +825,13 @@ dbcool_detach(device_t self, int flags) return 0; } -/* On suspend, we save the state of the SHDN bit, then set it */ -bool dbcool_pmf_suspend(device_t dev, const pmf_qual_t *qual) +/* + * On suspend, we save the state of the SHDN bit, then set it + * On resume, we restore the previous state of the SHDN bit (which + * we saved in sc_suspend) + */ +static bool +dbcool_do_pmf(device_t dev, const pmf_qual_t *qual, bool suspend) { struct dbcool_softc *sc = device_private(dev); uint8_t reg, bit, cfg; @@ -842,34 +847,29 @@ bool dbcool_pmf_suspend(device_t dev, co bit = DBCOOL_CFG2_SHDN; } cfg = sc->sc_dc.dc_readreg(&sc->sc_dc, reg); - sc->sc_suspend = cfg & bit; - cfg |= bit; + if (suspend) { + sc->sc_suspend = cfg & bit; + cfg |= bit; + } else { + cfg &= sc->sc_suspend ? bit : 0; + } sc->sc_dc.dc_writereg(&sc->sc_dc, reg, cfg); return true; } -/* On resume, we restore the previous state of the SHDN bit (which - we saved in sc_suspend) */ -bool dbcool_pmf_resume(device_t dev, const pmf_qual_t *qual) +bool +dbcool_pmf_suspend(device_t dev, const pmf_qual_t *qual) { - struct dbcool_softc *sc = device_private(dev); - uint8_t reg, cfg; - if ((sc->sc_dc.dc_chip->flags & DBCFLAG_HAS_SHDN) == 0) - return true; - - if (sc->sc_dc.dc_chip->flags & DBCFLAG_ADT7466) { - reg = DBCOOL_ADT7466_CONFIG2; - } else { - reg = DBCOOL_CONFIG2_REG; - } - cfg = sc->sc_dc.dc_readreg(&sc->sc_dc, reg); - cfg &= ~sc->sc_suspend; - sc->sc_dc.dc_writereg(&sc->sc_dc, reg, cfg); + return dbcool_do_pmf(dev, qual, true); +} - return true; +bool +dbcool_pmf_resume(device_t dev, const pmf_qual_t *qual) +{ + return dbcool_do_pmf(dev, qual, false); } uint8_t