hidbus(4): Use generic hid methods to start and stop interrupts

This commit is contained in:
Vladimir Kondratyev
2023-08-03 19:10:50 +03:00
parent 4b1712817e
commit 4151ac9f12
10 changed files with 50 additions and 31 deletions
+2 -2
View File
@@ -837,7 +837,7 @@ bcm5974_ev_open(struct evdev_dev *evdev)
return (err); return (err);
} }
return (hidbus_intr_start(sc->sc_dev)); return (hid_intr_start(sc->sc_dev));
} }
static int static int
@@ -846,7 +846,7 @@ bcm5974_ev_close(struct evdev_dev *evdev)
struct bcm5974_softc *sc = evdev_get_softc(evdev); struct bcm5974_softc *sc = evdev_get_softc(evdev);
int err; int err;
err = hidbus_intr_stop(sc->sc_dev); err = hid_intr_stop(sc->sc_dev);
if (err != 0) if (err != 0)
return (err); return (err);
+18
View File
@@ -1028,6 +1028,24 @@ hid_quirk_unload(void *arg)
pause("WAIT", hz); 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 int
hid_get_rdesc(device_t dev, void *data, hid_size_t len) hid_get_rdesc(device_t dev, void *data, hid_size_t len)
{ {
+3
View File
@@ -333,6 +333,9 @@ int hid_add_dynamic_quirk(struct hid_device_info *dev_info,
uint16_t quirk); uint16_t quirk);
void hid_quirk_unload(void *arg); 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_get_rdesc(device_t, void *, hid_size_t);
int hid_read(device_t, void *, hid_size_t, 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); int hid_write(device_t, const void *, hid_size_t);
+14 -13
View File
@@ -604,10 +604,10 @@ hidbus_set_intr(device_t child, hid_intr_t *handler, void *context)
tlc->intr_ctx = context; tlc->intr_ctx = context;
} }
int static int
hidbus_intr_start(device_t child) 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_softc *sc = device_get_softc(bus);
struct hidbus_ivars *ivar = device_get_ivars(child); struct hidbus_ivars *ivar = device_get_ivars(child);
struct hidbus_ivars *tlc; struct hidbus_ivars *tlc;
@@ -624,16 +624,16 @@ hidbus_intr_start(device_t child)
mtx_unlock(tlc->mtx); 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); sx_unlock(&sc->sx);
return (error); return (error);
} }
int static int
hidbus_intr_stop(device_t child) 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_softc *sc = device_get_softc(bus);
struct hidbus_ivars *ivar = device_get_ivars(child); struct hidbus_ivars *ivar = device_get_ivars(child);
struct hidbus_ivars *tlc; struct hidbus_ivars *tlc;
@@ -651,18 +651,16 @@ hidbus_intr_stop(device_t child)
} }
refcnted |= (tlc->refcnt != 0); 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); sx_unlock(&sc->sx);
return (error); return (error);
} }
void static void
hidbus_intr_poll(device_t child) hidbus_intr_poll(device_t bus, device_t child __unused)
{ {
device_t bus = device_get_parent(child); hid_intr_poll(bus);
HID_INTR_POLL(device_get_parent(bus), bus);
} }
struct hid_rdesc_info * struct hid_rdesc_info *
@@ -954,6 +952,9 @@ static device_method_t hidbus_methods[] = {
DEVMETHOD(bus_child_location, hidbus_child_location), DEVMETHOD(bus_child_location, hidbus_child_location),
/* hid interface */ /* 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_get_rdesc, hidbus_get_rdesc),
DEVMETHOD(hid_read, hidbus_read), DEVMETHOD(hid_read, hidbus_read),
DEVMETHOD(hid_write, hidbus_write), DEVMETHOD(hid_write, hidbus_write),
-3
View File
@@ -160,9 +160,6 @@ struct hid_rdesc_info *hidbus_get_rdesc_info(device_t);
int hidbus_lookup_driver_info(device_t, int hidbus_lookup_driver_info(device_t,
const struct hid_device_id *, int); const struct hid_device_id *, int);
void hidbus_set_intr(device_t, hid_intr_t*, void *); 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 *); void hidbus_set_desc(device_t, const char *);
device_t hidbus_find_child(device_t, int32_t); device_t hidbus_find_child(device_t, int32_t);
+2 -2
View File
@@ -118,13 +118,13 @@ _hidmap_set_debug_var(struct hidmap *hm, int *debug_var)
static int static int
hidmap_ev_close(struct evdev_dev *evdev) 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 static int
hidmap_ev_open(struct evdev_dev *evdev) hidmap_ev_open(struct evdev_dev *evdev)
{ {
return (hidbus_intr_start(evdev_get_softc(evdev))); return (hid_intr_start(evdev_get_softc(evdev)));
} }
void void
+2 -2
View File
@@ -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_head = sc->sc_tail = 0;
sc->sc_fflags = flag; sc->sc_fflags = flag;
hidbus_intr_start(sc->sc_dev); hid_intr_start(sc->sc_dev);
return (0); return (0);
} }
@@ -392,7 +392,7 @@ hidraw_dtor(void *data)
DPRINTF("sc=%p\n", sc); DPRINTF("sc=%p\n", sc);
/* Disable interrupts. */ /* Disable interrupts. */
hidbus_intr_stop(sc->sc_dev); hid_intr_stop(sc->sc_dev);
sc->sc_tail = sc->sc_head = 0; sc->sc_tail = sc->sc_head = 0;
sc->sc_async = 0; sc->sc_async = 0;
+3 -3
View File
@@ -435,7 +435,7 @@ hkbd_do_poll(struct hkbd_softc *sc, uint8_t wait)
} }
while (sc->sc_inputhead == sc->sc_inputtail) { 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 */ /* Delay-optimised support for repetition of keys */
if (hkbd_any_key_pressed(sc)) { if (hkbd_any_key_pressed(sc)) {
@@ -1004,7 +1004,7 @@ hkbd_attach(device_t dev)
} }
/* start the keyboard */ /* start the keyboard */
hidbus_intr_start(dev); hid_intr_start(dev);
return (0); /* success */ return (0); /* success */
@@ -1035,7 +1035,7 @@ hkbd_detach(device_t dev)
/* kill any stuck keys */ /* kill any stuck keys */
if (sc->sc_flags & HKBD_FLAG_ATTACHED) { if (sc->sc_flags & HKBD_FLAG_ATTACHED) {
/* stop receiving events from the USB keyboard */ /* stop receiving events from the USB keyboard */
hidbus_intr_stop(dev); hid_intr_stop(dev);
/* release all leftover keys, if any */ /* release all leftover keys, if any */
memset(&sc->sc_ndata, 0, bitstr_size(HKBD_NKEYCODE)); memset(&sc->sc_ndata, 0, bitstr_size(HKBD_NKEYCODE));
+2 -2
View File
@@ -252,13 +252,13 @@ static const struct hid_device_id hmt_devs[] = {
static int static int
hmt_ev_close(struct evdev_dev *evdev) 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 static int
hmt_ev_open(struct evdev_dev *evdev) 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 static int
+4 -4
View File
@@ -220,13 +220,13 @@ static const struct evdev_methods ietp_evdev_methods = {
static int static int
ietp_ev_open(struct evdev_dev *evdev) 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 static int
ietp_ev_close(struct evdev_dev *evdev) 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 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"); device_printf(dev, "failed writing poweron command\n");
return (EIO); return (EIO);
} }
@@ -606,7 +606,7 @@ ietp_iic_set_absolute_mode(device_t dev, bool enable)
error = EIO; 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"); device_printf(dev, "failed writing poweroff command\n");
error = EIO; error = EIO;
} }