Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/fdt Add fdtbus_gpio_acquire_index for accessing mult...



details:   https://anonhg.NetBSD.org/src/rev/93a8224ed392
branches:  trunk
changeset: 355768:93a8224ed392
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Aug 13 18:27:11 2017 +0000

description:
Add fdtbus_gpio_acquire_index for accessing multi-xref gpios properties.

diffstat:

 sys/dev/fdt/fdt_gpio.c |  68 +++++++++++++++++++++++++++----------------------
 sys/dev/fdt/fdtvar.h   |   3 +-
 2 files changed, 39 insertions(+), 32 deletions(-)

diffs (110 lines):

diff -r bc56ae1b4f92 -r 93a8224ed392 sys/dev/fdt/fdt_gpio.c
--- a/sys/dev/fdt/fdt_gpio.c    Sun Aug 13 18:19:44 2017 +0000
+++ b/sys/dev/fdt/fdt_gpio.c    Sun Aug 13 18:27:11 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_gpio.c,v 1.4 2016/10/15 08:30:42 maxv Exp $ */
+/* $NetBSD: fdt_gpio.c,v 1.5 2017/08/13 18:27:11 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_gpio.c,v 1.4 2016/10/15 08:30:42 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_gpio.c,v 1.5 2017/08/13 18:27:11 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -80,39 +80,45 @@
 struct fdtbus_gpio_pin *
 fdtbus_gpio_acquire(int phandle, const char *prop, int flags)
 {
-       struct fdtbus_gpio_controller *gc;
-       struct fdtbus_gpio_pin *gp;
-       int gpio_phandle, len;
-       u_int *data;
+       return fdtbus_gpio_acquire_index(phandle, prop, 0, flags);
+}
 
-       gpio_phandle = fdtbus_get_phandle(phandle, prop);
-       if (gpio_phandle == -1) {
-               return NULL;
-       }
+struct fdtbus_gpio_pin *
+fdtbus_gpio_acquire_index(int phandle, const char *prop,
+    int index, int flags)
+{
+       struct fdtbus_gpio_controller *gc;
+       struct fdtbus_gpio_pin *gp = NULL;
+       const uint32_t *gpios, *p;
+       u_int n, gpio_cells;
+       int len, resid;
 
-       gc = fdtbus_get_gpio_controller(gpio_phandle);
-       if (gc == NULL) {
+       gpios = fdtbus_get_prop(phandle, prop, &len);
+       if (gpios == NULL)
                return NULL;
-       }
 
-       len = OF_getproplen(phandle, prop);
-       if (len < 4) {
-               return NULL;
-       }
-
-       data = kmem_alloc(len, KM_SLEEP);
-       if (OF_getprop(phandle, prop, data, len) != len) {
-               kmem_free(data, len);
-               return NULL;
-       }
-
-       gp = kmem_alloc(sizeof(*gp), KM_SLEEP);
-       gp->gp_gc = gc;
-       gp->gp_priv = gc->gc_funcs->acquire(gc->gc_dev, data, len, flags);
-       if (gp->gp_priv == NULL) {
-               kmem_free(data, len);
-               kmem_free(gp, sizeof(*gp));
-               return NULL;
+       p = gpios;
+       for (n = 0, resid = len; resid > 0; n++) {
+               const int gc_phandle =
+                   fdtbus_get_phandle_from_native(be32toh(p[0]));
+               if (of_getprop_uint32(gc_phandle, "#gpio-cells", &gpio_cells))
+                       break;
+               if (n == index) {
+                       gc = fdtbus_get_gpio_controller(gc_phandle);
+                       if (gc == NULL)
+                               return NULL;
+                       gp = kmem_alloc(sizeof(*gp), KM_SLEEP);
+                       gp->gp_gc = gc;
+                       gp->gp_priv = gc->gc_funcs->acquire(gc->gc_dev,
+                           &p[0], (gpio_cells + 1) * 4, flags);
+                       if (gp->gp_priv == NULL) {
+                               kmem_free(gp, sizeof(*gp));
+                               return NULL;
+                       }
+                       break;
+               }
+               resid -= (gpio_cells + 1) * 4;
+               p += gpio_cells + 1;
        }
 
        return gp;
diff -r bc56ae1b4f92 -r 93a8224ed392 sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h      Sun Aug 13 18:19:44 2017 +0000
+++ b/sys/dev/fdt/fdtvar.h      Sun Aug 13 18:27:11 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.24 2017/07/08 12:36:51 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.25 2017/08/13 18:27:11 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -236,6 +236,7 @@
 void           fdtbus_intr_disestablish(int, void *);
 bool           fdtbus_intr_str(int, u_int, char *, size_t);
 struct fdtbus_gpio_pin *fdtbus_gpio_acquire(int, const char *, int);
+struct fdtbus_gpio_pin *fdtbus_gpio_acquire_index(int, const char *, int, int);
 void           fdtbus_gpio_release(struct fdtbus_gpio_pin *);
 int            fdtbus_gpio_read(struct fdtbus_gpio_pin *);
 void           fdtbus_gpio_write(struct fdtbus_gpio_pin *, int);



Home | Main Index | Thread Index | Old Index