Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 3 Aug 2023 16:12:04 GMT
From:      Vladimir Kondratyev <wulf@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 4151ac9f1292 - main - hidbus(4): Use generic hid methods to start and stop interrupts
Message-ID:  <202308031612.373GC4Os006125@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=4151ac9f1292b524ae3eeb6f6c9561913bbe444c

commit 4151ac9f1292b524ae3eeb6f6c9561913bbe444c
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2023-08-03 16:10:50 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2023-08-03 16:10:50 +0000

    hidbus(4): Use generic hid methods to start and stop interrupts
---
 sys/dev/hid/bcm5974.c |  4 ++--
 sys/dev/hid/hid.c     | 18 ++++++++++++++++++
 sys/dev/hid/hid.h     |  3 +++
 sys/dev/hid/hidbus.c  | 27 ++++++++++++++-------------
 sys/dev/hid/hidbus.h  |  3 ---
 sys/dev/hid/hidmap.c  |  4 ++--
 sys/dev/hid/hidraw.c  |  4 ++--
 sys/dev/hid/hkbd.c    |  6 +++---
 sys/dev/hid/hmt.c     |  4 ++--
 sys/dev/hid/ietp.c    |  8 ++++----
 10 files changed, 50 insertions(+), 31 deletions(-)

diff --git a/sys/dev/hid/bcm5974.c b/sys/dev/hid/bcm5974.c
index fdfc29e6b678..9a927aaffc5b 100644
--- a/sys/dev/hid/bcm5974.c
+++ b/sys/dev/hid/bcm5974.c
@@ -837,7 +837,7 @@ bcm5974_ev_open(struct evdev_dev *evdev)
 		return (err);
 	}
 
-	return (hidbus_intr_start(sc->sc_dev));
+	return (hid_intr_start(sc->sc_dev));
 }
 
 static int
@@ -846,7 +846,7 @@ bcm5974_ev_close(struct evdev_dev *evdev)
 	struct bcm5974_softc *sc = evdev_get_softc(evdev);
 	int err;
 
-	err = hidbus_intr_stop(sc->sc_dev);
+	err = hid_intr_stop(sc->sc_dev);
 	if (err != 0)
 		return (err);
 
diff --git a/sys/dev/hid/hid.c b/sys/dev/hid/hid.c
index 7fa6e34be22a..6ed72dbe5a00 100644
--- a/sys/dev/hid/hid.c
+++ b/sys/dev/hid/hid.c
@@ -1028,6 +1028,24 @@ hid_quirk_unload(void *arg)
 	pause("WAIT", hz);
 }
 
+int
+hid_intr_start(device_t dev)
+{
+	return (HID_INTR_START(device_get_parent(dev), dev));
+}
+
+int
+hid_intr_stop(device_t dev)
+{
+	return (HID_INTR_STOP(device_get_parent(dev), dev));
+}
+
+void
+hid_intr_poll(device_t dev)
+{
+	HID_INTR_POLL(device_get_parent(dev), dev);
+}
+
 int
 hid_get_rdesc(device_t dev, void *data, hid_size_t len)
 {
diff --git a/sys/dev/hid/hid.h b/sys/dev/hid/hid.h
index 5af470df61d1..a267207e49db 100644
--- a/sys/dev/hid/hid.h
+++ b/sys/dev/hid/hid.h
@@ -333,6 +333,9 @@ int	hid_add_dynamic_quirk(struct hid_device_info *dev_info,
 	    uint16_t quirk);
 void	hid_quirk_unload(void *arg);
 
+int	hid_intr_start(device_t);
+int	hid_intr_stop(device_t);
+void	hid_intr_poll(device_t);
 int	hid_get_rdesc(device_t, void *, hid_size_t);
 int	hid_read(device_t, void *, hid_size_t, hid_size_t *);
 int	hid_write(device_t, const void *, hid_size_t);
diff --git a/sys/dev/hid/hidbus.c b/sys/dev/hid/hidbus.c
index fe6c4df060a3..6dd8ff9b8e6f 100644
--- a/sys/dev/hid/hidbus.c
+++ b/sys/dev/hid/hidbus.c
@@ -604,10 +604,10 @@ hidbus_set_intr(device_t child, hid_intr_t *handler, void *context)
 	tlc->intr_ctx = context;
 }
 
-int
-hidbus_intr_start(device_t child)
+static int
+hidbus_intr_start(device_t bus, device_t child)
 {
-	device_t bus = device_get_parent(child);
+	MPASS(bus = device_get_parent(child));
 	struct hidbus_softc *sc = device_get_softc(bus);
 	struct hidbus_ivars *ivar = device_get_ivars(child);
 	struct hidbus_ivars *tlc;
@@ -624,16 +624,16 @@ hidbus_intr_start(device_t child)
 			mtx_unlock(tlc->mtx);
 		}
 	}
-	error = refcnted ? 0 : HID_INTR_START(device_get_parent(bus), bus);
+	error = refcnted ? 0 : hid_intr_start(bus);
 	sx_unlock(&sc->sx);
 
 	return (error);
 }
 
-int
-hidbus_intr_stop(device_t child)
+static int
+hidbus_intr_stop(device_t bus, device_t child)
 {
-	device_t bus = device_get_parent(child);
+	MPASS(bus = device_get_parent(child));
 	struct hidbus_softc *sc = device_get_softc(bus);
 	struct hidbus_ivars *ivar = device_get_ivars(child);
 	struct hidbus_ivars *tlc;
@@ -651,18 +651,16 @@ hidbus_intr_stop(device_t child)
 		}
 		refcnted |= (tlc->refcnt != 0);
 	}
-	error = refcnted ? 0 : HID_INTR_STOP(device_get_parent(bus), bus);
+	error = refcnted ? 0 : hid_intr_stop(bus);
 	sx_unlock(&sc->sx);
 
 	return (error);
 }
 
-void
-hidbus_intr_poll(device_t child)
+static void
+hidbus_intr_poll(device_t bus, device_t child __unused)
 {
-	device_t bus = device_get_parent(child);
-
-	HID_INTR_POLL(device_get_parent(bus), bus);
+	hid_intr_poll(bus);
 }
 
 struct hid_rdesc_info *
@@ -954,6 +952,9 @@ static device_method_t hidbus_methods[] = {
 	DEVMETHOD(bus_child_location,	hidbus_child_location),
 
 	/* hid interface */
+	DEVMETHOD(hid_intr_start,	hidbus_intr_start),
+	DEVMETHOD(hid_intr_stop,	hidbus_intr_stop),
+	DEVMETHOD(hid_intr_poll,	hidbus_intr_poll),
 	DEVMETHOD(hid_get_rdesc,	hidbus_get_rdesc),
 	DEVMETHOD(hid_read,		hidbus_read),
 	DEVMETHOD(hid_write,		hidbus_write),
diff --git a/sys/dev/hid/hidbus.h b/sys/dev/hid/hidbus.h
index b2744add8658..3de4a6291511 100644
--- a/sys/dev/hid/hidbus.h
+++ b/sys/dev/hid/hidbus.h
@@ -160,9 +160,6 @@ struct hid_rdesc_info *hidbus_get_rdesc_info(device_t);
 int		hidbus_lookup_driver_info(device_t,
 		    const struct hid_device_id *, int);
 void		hidbus_set_intr(device_t, hid_intr_t*, void *);
-int		hidbus_intr_start(device_t);
-int		hidbus_intr_stop(device_t);
-void		hidbus_intr_poll(device_t);
 void		hidbus_set_desc(device_t, const char *);
 device_t	hidbus_find_child(device_t, int32_t);
 
diff --git a/sys/dev/hid/hidmap.c b/sys/dev/hid/hidmap.c
index 8951f14a2361..b97558ad33ef 100644
--- a/sys/dev/hid/hidmap.c
+++ b/sys/dev/hid/hidmap.c
@@ -118,13 +118,13 @@ _hidmap_set_debug_var(struct hidmap *hm, int *debug_var)
 static int
 hidmap_ev_close(struct evdev_dev *evdev)
 {
-	return (hidbus_intr_stop(evdev_get_softc(evdev)));
+	return (hid_intr_stop(evdev_get_softc(evdev)));
 }
 
 static int
 hidmap_ev_open(struct evdev_dev *evdev)
 {
-	return (hidbus_intr_start(evdev_get_softc(evdev)));
+	return (hid_intr_start(evdev_get_softc(evdev)));
 }
 
 void
diff --git a/sys/dev/hid/hidraw.c b/sys/dev/hid/hidraw.c
index dd20aba3e588..c18d039286ee 100644
--- a/sys/dev/hid/hidraw.c
+++ b/sys/dev/hid/hidraw.c
@@ -379,7 +379,7 @@ hidraw_open(struct cdev *dev, int flag, int mode, struct thread *td)
 	sc->sc_head = sc->sc_tail = 0;
 	sc->sc_fflags = flag;
 
-	hidbus_intr_start(sc->sc_dev);
+	hid_intr_start(sc->sc_dev);
 
 	return (0);
 }
@@ -392,7 +392,7 @@ hidraw_dtor(void *data)
 	DPRINTF("sc=%p\n", sc);
 
 	/* Disable interrupts. */
-	hidbus_intr_stop(sc->sc_dev);
+	hid_intr_stop(sc->sc_dev);
 
 	sc->sc_tail = sc->sc_head = 0;
 	sc->sc_async = 0;
diff --git a/sys/dev/hid/hkbd.c b/sys/dev/hid/hkbd.c
index 922256a8f23b..b0aa5be11a1e 100644
--- a/sys/dev/hid/hkbd.c
+++ b/sys/dev/hid/hkbd.c
@@ -435,7 +435,7 @@ hkbd_do_poll(struct hkbd_softc *sc, uint8_t wait)
 	}
 
 	while (sc->sc_inputhead == sc->sc_inputtail) {
-		hidbus_intr_poll(sc->sc_dev);
+		hid_intr_poll(sc->sc_dev);
 
 		/* Delay-optimised support for repetition of keys */
 		if (hkbd_any_key_pressed(sc)) {
@@ -1004,7 +1004,7 @@ hkbd_attach(device_t dev)
 	}
 
 	/* start the keyboard */
-	hidbus_intr_start(dev);
+	hid_intr_start(dev);
 
 	return (0);			/* success */
 
@@ -1035,7 +1035,7 @@ hkbd_detach(device_t dev)
 	/* kill any stuck keys */
 	if (sc->sc_flags & HKBD_FLAG_ATTACHED) {
 		/* stop receiving events from the USB keyboard */
-		hidbus_intr_stop(dev);
+		hid_intr_stop(dev);
 
 		/* release all leftover keys, if any */
 		memset(&sc->sc_ndata, 0, bitstr_size(HKBD_NKEYCODE));
diff --git a/sys/dev/hid/hmt.c b/sys/dev/hid/hmt.c
index cb9de6f24f88..b190772e2498 100644
--- a/sys/dev/hid/hmt.c
+++ b/sys/dev/hid/hmt.c
@@ -252,13 +252,13 @@ static const struct hid_device_id hmt_devs[] = {
 static int
 hmt_ev_close(struct evdev_dev *evdev)
 {
-	return (hidbus_intr_stop(evdev_get_softc(evdev)));
+	return (hid_intr_stop(evdev_get_softc(evdev)));
 }
 
 static int
 hmt_ev_open(struct evdev_dev *evdev)
 {
-	return (hidbus_intr_start(evdev_get_softc(evdev)));
+	return (hid_intr_start(evdev_get_softc(evdev)));
 }
 
 static int
diff --git a/sys/dev/hid/ietp.c b/sys/dev/hid/ietp.c
index cdc5491b2c6d..1eaf95f17364 100644
--- a/sys/dev/hid/ietp.c
+++ b/sys/dev/hid/ietp.c
@@ -220,13 +220,13 @@ static const struct evdev_methods ietp_evdev_methods = {
 static int
 ietp_ev_open(struct evdev_dev *evdev)
 {
-	return (hidbus_intr_start(evdev_get_softc(evdev)));
+	return (hid_intr_start(evdev_get_softc(evdev)));
 }
 
 static int
 ietp_ev_close(struct evdev_dev *evdev)
 {
-	return (hidbus_intr_stop(evdev_get_softc(evdev)));
+	return (hid_intr_stop(evdev_get_softc(evdev)));
 }
 
 static int
@@ -595,7 +595,7 @@ ietp_iic_set_absolute_mode(device_t dev, bool enable)
 		}
 	}
 
-	if (require_wakeup && hidbus_intr_start(dev) != 0) {
+	if (require_wakeup && hid_intr_start(dev) != 0) {
 		device_printf(dev, "failed writing poweron command\n");
 		return (EIO);
 	}
@@ -606,7 +606,7 @@ ietp_iic_set_absolute_mode(device_t dev, bool enable)
 		error = EIO;
 	}
 
-	if (require_wakeup && hidbus_intr_stop(dev) != 0) {
+	if (require_wakeup && hid_intr_stop(dev) != 0) {
 		device_printf(dev, "failed writing poweroff command\n");
 		error = EIO;
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202308031612.373GC4Os006125>