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

View file

@ -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);

View file

@ -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)
{

View file

@ -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);

View file

@ -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),

View file

@ -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);

View file

@ -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

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_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;

View file

@ -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));

View file

@ -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

View file

@ -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;
}