diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2025-01-09 22:03:39 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2025-01-09 22:03:39 +0000 |
commit | 58869385e0cf6e9ed2f8b84fe0cf6bdc71867ef1 (patch) | |
tree | 7c736a5e9c49d6e98aa9a42e2153bc4f98a38705 /sys | |
parent | dcc66fb4a0ddcc22142e48316348b923057f6fe3 (diff) |
Make gpiokeys(4) interrupt-driven if we have interrupts.
ok kn@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/fdt/gpiokeys.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/sys/dev/fdt/gpiokeys.c b/sys/dev/fdt/gpiokeys.c index cd878423668..d06628f8e70 100644 --- a/sys/dev/fdt/gpiokeys.c +++ b/sys/dev/fdt/gpiokeys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpiokeys.c,v 1.4 2025/01/09 20:11:20 kettenis Exp $ */ +/* $OpenBSD: gpiokeys.c,v 1.5 2025/01/09 22:03:38 kettenis Exp $ */ /* * Copyright (c) 2021 Klemens Nanni <kn@openbsd.org> * @@ -55,6 +55,8 @@ struct gpiokeys_key { uint32_t key_code; struct ksensor key_sensor; SLIST_ENTRY(gpiokeys_key) key_next; + void (*key_func)(void *); + void *key_ih; }; struct gpiokeys_softc { @@ -75,6 +77,7 @@ struct cfdriver gpiokeys_cd = { }; void gpiokeys_update_key(void *); +int gpiokeys_intr(void *); int gpiokeys_match(struct device *parent, void *match, void *aux) @@ -132,8 +135,7 @@ gpiokeys_attach(struct device *parent, struct device *self, void *aux) key->key_sensor.type = SENSOR_INDICATOR; sensor_attach(&sc->sc_sensordev, &key->key_sensor); - sensor_task_register(key, - gpiokeys_update_key, 1); + key->key_func = gpiokeys_update_key; have_sensors = 1; break; } @@ -149,6 +151,20 @@ gpiokeys_attach(struct device *parent, struct device *self, void *aux) SLIST_INSERT_HEAD(&sc->sc_keys, key, key_next); } + SLIST_FOREACH(key, &sc->sc_keys, key_next) { + if (!key->key_func) + continue; + + if (OF_is_compatible(faa->fa_node, "gpio-keys")) { + key->key_ih = gpio_controller_intr_establish(key->key_pin, + IPL_BIO, NULL, gpiokeys_intr, key, DEVNAME(sc)); + } + if (key->key_ih == NULL) + sensor_task_register(key, gpiokeys_update_key, 1); + else + gpiokeys_update_key(key); + } + if (have_sensors) { strlcpy(sc->sc_sensordev.xname, DEVNAME(sc), sizeof(sc->sc_sensordev.xname)); @@ -182,3 +198,12 @@ gpiokeys_update_key(void *arg) break; } } + +int +gpiokeys_intr(void *arg) +{ + struct gpiokeys_key *key = arg; + + key->key_func(key); + return 1; +} |