Module Name: src
Committed By: thorpej
Date: Mon Jan 17 19:33:00 UTC 2022
Modified Files:
src/sys/dev/gpio: gpio.c
Log Message:
When initializing pins, try to get the default pin name from the
"gpio-line-names" property. If not present, then fall back on the
default name for the pin from the parent, if there is one.
To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/dev/gpio/gpio.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/gpio/gpio.c
diff -u src/sys/dev/gpio/gpio.c:1.68 src/sys/dev/gpio/gpio.c:1.69
--- src/sys/dev/gpio/gpio.c:1.68 Tue Sep 21 14:38:51 2021
+++ src/sys/dev/gpio/gpio.c Mon Jan 17 19:33:00 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: gpio.c,v 1.68 2021/09/21 14:38:51 christos Exp $ */
+/* $NetBSD: gpio.c,v 1.69 2022/01/17 19:33:00 thorpej Exp $ */
/* $OpenBSD: gpio.c,v 1.6 2006/01/14 12:33:49 grange Exp $ */
/*
@@ -18,8 +18,12 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifdef _KERNEL_OPT
+#include "opt_fdt.h"
+#endif
+
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gpio.c,v 1.68 2021/09/21 14:38:51 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gpio.c,v 1.69 2022/01/17 19:33:00 thorpej Exp $");
/*
* General Purpose Input/Output framework.
@@ -41,8 +45,13 @@ __KERNEL_RCSID(0, "$NetBSD: gpio.c,v 1.6
#include <sys/queue.h>
#include <sys/kauth.h>
#include <sys/module.h>
+
#include <dev/gpio/gpiovar.h>
+#ifdef FDT
+#include <dev/fdt/fdtvar.h>
+#endif
+
#include "ioconf.h"
#include "locators.h"
@@ -196,6 +205,23 @@ gpio_rescan(device_t self, const char *i
return 0;
}
+static const char *
+gpio_pin_defname(struct gpio_softc *sc, int pin)
+{
+ KASSERT(pin >= 0);
+
+#ifdef FDT
+ devhandle_t devhandle = device_handle(sc->sc_dev);
+
+ if (devhandle_type(devhandle) == DEVHANDLE_TYPE_OF) {
+ return fdtbus_get_string_index(devhandle_to_of(devhandle),
+ "gpio-line-names", pin);
+ }
+#endif /* FDT */
+
+ return NULL;
+}
+
static void
gpio_attach(device_t parent, device_t self, void *aux)
{
@@ -214,11 +240,18 @@ gpio_attach(device_t parent, device_t se
/* Configure default pin names */
for (pin = 0; pin < sc->sc_npins; pin++) {
- if (sc->sc_pins[pin].pin_defname[0] == '\0')
+ const char *defname;
+
+ defname = gpio_pin_defname(sc, pin);
+ if (defname == NULL &&
+ sc->sc_pins[pin].pin_defname[0] != '\0') {
+ defname = sc->sc_pins[pin].pin_defname;
+ }
+ if (defname == NULL) {
continue;
+ }
nm = kmem_alloc(sizeof(*nm), KM_SLEEP);
- strlcpy(nm->gp_name, sc->sc_pins[pin].pin_defname,
- sizeof(nm->gp_name));
+ strlcpy(nm->gp_name, defname, sizeof(nm->gp_name));
nm->gp_pin = pin;
LIST_INSERT_HEAD(&sc->sc_names, nm, gp_next);
}