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_count(), which counts the number...
details: https://anonhg.NetBSD.org/src/rev/19d2045a859e
branches: trunk
changeset: 948254:19d2045a859e
user: thorpej <thorpej%NetBSD.org@localhost>
date: Wed Dec 23 04:07:34 2020 +0000
description:
Add fdtbus_gpio_count(), which counts the number of GPIO entries
in a specified property.
diffstat:
sys/dev/fdt/fdt_gpio.c | 28 ++++++++++++++++++++++++++--
sys/dev/fdt/fdtvar.h | 3 ++-
2 files changed, 28 insertions(+), 3 deletions(-)
diffs (66 lines):
diff -r 5ebbf127e6fd -r 19d2045a859e sys/dev/fdt/fdt_gpio.c
--- a/sys/dev/fdt/fdt_gpio.c Wed Dec 23 02:56:11 2020 +0000
+++ b/sys/dev/fdt/fdt_gpio.c Wed Dec 23 04:07:34 2020 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
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)
{
diff -r 5ebbf127e6fd -r 19d2045a859e sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h Wed Dec 23 02:56:11 2020 +0000
+++ b/sys/dev/fdt/fdtvar.h Wed Dec 23 04:07:34 2020 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -331,6 +331,7 @@
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 *);
Home |
Main Index |
Thread Index |
Old Index