Module Name: src
Committed By: thorpej
Date: Wed Dec 23 04:07:34 UTC 2020
Modified Files:
src/sys/dev/fdt: fdt_gpio.c fdtvar.h
Log Message:
Add fdtbus_gpio_count(), which counts the number of GPIO entries
in a specified property.
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/fdt/fdt_gpio.c
cvs rdiff -u -r1.62 -r1.63 src/sys/dev/fdt/fdtvar.h
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/fdt/fdt_gpio.c
diff -u src/sys/dev/fdt/fdt_gpio.c:1.6 src/sys/dev/fdt/fdt_gpio.c:1.7
--- src/sys/dev/fdt/fdt_gpio.c:1.6 Sat Jun 30 20:34:43 2018
+++ src/sys/dev/fdt/fdt_gpio.c Wed Dec 23 04:07:34 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_gpio.c,v 1.6 2018/06/30 20:34:43 jmcneill Exp $ */
+/* $NetBSD: fdt_gpio.c,v 1.7 2020/12/23 04:07:34 thorpej Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_gpio.c,v 1.6 2018/06/30 20:34:43 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_gpio.c,v 1.7 2020/12/23 04:07:34 thorpej Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -77,6 +77,30 @@ fdtbus_get_gpio_controller(int phandle)
return NULL;
}
+int
+fdtbus_gpio_count(int phandle, const char *prop)
+{
+ const uint32_t *gpios, *p;
+ u_int n, gpio_cells;
+ int len, resid;
+
+ gpios = fdtbus_get_prop(phandle, prop, &len);
+ if (gpios == NULL)
+ return 0;
+
+ 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;
+ resid -= (gpio_cells + 1) * 4;
+ p += gpio_cells + 1;
+ }
+
+ return n;
+}
+
struct fdtbus_gpio_pin *
fdtbus_gpio_acquire(int phandle, const char *prop, int flags)
{
Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.62 src/sys/dev/fdt/fdtvar.h:1.63
--- src/sys/dev/fdt/fdtvar.h:1.62 Fri Dec 11 09:40:28 2020
+++ src/sys/dev/fdt/fdtvar.h Wed Dec 23 04:07:34 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.62 2020/12/11 09:40:28 skrll Exp $ */
+/* $NetBSD: fdtvar.h,v 1.63 2020/12/23 04:07:34 thorpej Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -331,6 +331,7 @@ void fdtbus_intr_unmask(int, void *);
void fdtbus_intr_disestablish(int, void *);
bool fdtbus_intr_str(int, u_int, char *, size_t);
bool fdtbus_intr_str_raw(int, const u_int *, char *, size_t);
+int fdtbus_gpio_count(int, const char *);
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 *);