From: kettenis Date: Sat, 12 Aug 2023 10:03:05 +0000 (+0000) Subject: Don't power down if the device is already opened. This happens when an X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b9d12f9e4bb9a2a18a466a8a8ed1884a1f82608d;p=openbsd Don't power down if the device is already opened. This happens when an ikbd(4) attaches and becomes the console keyboard. We would power down the device but never power it on again when userland opened ikbd(4) as an input device since that is only done on the first open. The result was a non-functioning keyboard if the hardware actually implemented the power down command. A lot of hardware actually doesn't (which is why this wasn't noticed for some time) but the ASUS X205T does. ok miod@ --- diff --git a/sys/dev/i2c/ihidev.c b/sys/dev/i2c/ihidev.c index 233739404d1..d028930347a 100644 --- a/sys/dev/i2c/ihidev.c +++ b/sys/dev/i2c/ihidev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ihidev.c,v 1.28 2022/08/31 15:14:01 kettenis Exp $ */ +/* $OpenBSD: ihidev.c,v 1.29 2023/08/12 10:03:05 kettenis Exp $ */ /* * HID-over-i2c driver * @@ -198,6 +198,9 @@ ihidev_attach(struct device *parent, struct device *self, void *aux) sc->sc_subdevs[repid] = (struct ihidev *)dev; } + if (sc->sc_refcnt > 0) + return; + /* power down until we're opened */ if (ihidev_hid_command(sc, I2C_HID_CMD_SET_POWER, &I2C_HID_POWER_OFF)) { printf("%s: failed to power down\n", sc->sc_dev.dv_xname);