From: anton Date: Wed, 28 Jul 2021 09:55:58 +0000 (+0000) Subject: Delay installation of sensors until a device with battery support is X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=798992452ee0c9bffee6de483b2b88340c7cfd85;p=openbsd Delay installation of sensors until a device with battery support is connected. Allows sensorsd(8) to pick up hotplugged devices. Thanks to Laurence Tratt for the report. --- diff --git a/sys/dev/usb/uhidpp.c b/sys/dev/usb/uhidpp.c index ba56e313ddc..d2748330f95 100644 --- a/sys/dev/usb/uhidpp.c +++ b/sys/dev/usb/uhidpp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uhidpp.c,v 1.14 2021/05/11 16:40:57 anton Exp $ */ +/* $OpenBSD: uhidpp.c,v 1.15 2021/07/28 09:55:58 anton Exp $ */ /* * Copyright (c) 2021 Anton Lindqvist @@ -247,6 +247,8 @@ struct uhidpp_notification *uhidpp_claim_notification(struct uhidpp_softc *); int uhidpp_consume_notification(struct uhidpp_softc *, struct uhidpp_report *); int uhidpp_is_notification(struct uhidpp_softc *, struct uhidpp_report *); +static int uhidpp_has_sensors(struct uhidpp_softc *); + int hidpp_get_protocol_version(struct uhidpp_softc *, uint8_t, uint8_t *, uint8_t *); @@ -399,10 +401,6 @@ uhidpp_attach(struct device *parent, struct device *self, void *aux) if (error) printf(" error %d", error); - strlcpy(sc->sc_sensdev.xname, sc->sc_hdev.sc_dev.dv_xname, - sizeof(sc->sc_sensdev.xname)); - sensordev_install(&sc->sc_sensdev); - out: mtx_leave(&sc->sc_mtx); printf("\n"); @@ -421,7 +419,7 @@ uhidpp_detach(struct device *self, int flags) KASSERT(sc->sc_resp_state == UHIDPP_RESP_NONE); - if (sc->sc_sensdev.xname[0] != '\0') + if (uhidpp_has_sensors(sc)) sensordev_deinstall(&sc->sc_sensdev); for (i = 0; i < UHIDPP_NDEVICES; i++) { @@ -607,6 +605,16 @@ uhidpp_device_connect(struct uhidpp_softc *sc, struct uhidpp_device *dev) dev->d_connected = 1; + /* + * Delay installation of sensors until a device with battery support is + * connected. Allows sensorsd(8) to pick up hotplugged devices. + */ + if (!uhidpp_has_sensors(sc)) { + strlcpy(sc->sc_sensdev.xname, sc->sc_hdev.sc_dev.dv_xname, + sizeof(sc->sc_sensdev.xname)); + sensordev_install(&sc->sc_sensdev); + } + sens = &dev->d_battery.b_sens[0]; strlcpy(sens->desc, "battery level", sizeof(sens->desc)); sens->type = SENSOR_PERCENT; @@ -814,6 +822,12 @@ uhidpp_is_notification(struct uhidpp_softc *sc, struct uhidpp_report *rep) return 1; } +static int +uhidpp_has_sensors(struct uhidpp_softc *sc) +{ + return sc->sc_sensdev.xname[0] != '\0'; +} + int hidpp_get_protocol_version(struct uhidpp_softc *sc, uint8_t device_id, uint8_t *major, uint8_t *minor)