git: 45b6c31a3801 - main - bcm5974(4): set mode again on resume

From: Vladimir Kondratyev <wulf_at_FreeBSD.org>
Date: Tue, 08 Mar 2022 12:52:11 UTC
The branch main has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=45b6c31a3801555cd7d46620b8aadcd9dd3a607d

commit 45b6c31a3801555cd7d46620b8aadcd9dd3a607d
Author:     Greg V <greg@unrelenting.technology>
AuthorDate: 2022-03-08 12:51:07 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2022-03-08 12:51:07 +0000

    bcm5974(4): set mode again on resume
    
    This is necessary to not break SPI devices on suspend-resume.
    
    Reviewed by:    wulf
    MFC with:       5aa839c9e2c373275091b8bf529c1311d0b84d76
    Differential revision:  https://reviews.freebsd.org/D34434
---
 sys/dev/hid/bcm5974.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/sys/dev/hid/bcm5974.c b/sys/dev/hid/bcm5974.c
index c940e022d2f1..cef571ed2f49 100644
--- a/sys/dev/hid/bcm5974.c
+++ b/sys/dev/hid/bcm5974.c
@@ -416,6 +416,7 @@ struct bcm5974_softc {
 	struct evdev_dev *sc_evdev;
 	/* device configuration */
 	const struct bcm5974_dev_params *sc_params;
+	bool sc_saved_mode;
 };
 
 static const uint8_t bcm5974_rdesc[] = {
@@ -549,6 +550,9 @@ bcm5974_set_device_mode(struct bcm5974_softc *sc, bool on)
 		KASSERT(0 == 1, ("Unknown trackpad type"));
 	}
 
+	if (!err)
+		sc->sc_saved_mode = on;
+
 	return (err);
 }
 
@@ -667,6 +671,16 @@ bcm5974_detach(device_t dev)
 	return (0);
 }
 
+static int
+bcm5974_resume(device_t dev)
+{
+	struct bcm5974_softc *sc = device_get_softc(dev);
+
+	bcm5974_set_device_mode(sc, sc->sc_saved_mode);
+
+	return (0);
+}
+
 static void
 bcm5974_intr(void *context, void *data, hid_size_t len)
 {
@@ -779,6 +793,7 @@ static device_method_t bcm5974_methods[] = {
 	DEVMETHOD(device_probe,		bcm5974_probe),
 	DEVMETHOD(device_attach,	bcm5974_attach),
 	DEVMETHOD(device_detach,	bcm5974_detach),
+	DEVMETHOD(device_resume,	bcm5974_resume),
 	DEVMETHOD_END
 };