Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/gpio When initializing pins, try to get the default ...



details:   https://anonhg.NetBSD.org/src/rev/b44fd7f353ee
branches:  trunk
changeset: 359698:b44fd7f353ee
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Jan 17 19:33:00 2022 +0000

description:
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.

diffstat:

 sys/dev/gpio/gpio.c |  43 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 38 insertions(+), 5 deletions(-)

diffs (83 lines):

diff -r 5c7255d18dde -r b44fd7f353ee sys/dev/gpio/gpio.c
--- a/sys/dev/gpio/gpio.c       Mon Jan 17 19:12:31 2022 +0000
+++ b/sys/dev/gpio/gpio.c       Mon Jan 17 19:33:00 2022 +0000
@@ -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 @@
 #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 @@
        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 @@
 
        /* 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);
        }



Home | Main Index | Thread Index | Old Index