Module Name:    src
Committed By:   jmcneill
Date:           Sun Jun 10 13:26:30 UTC 2018

Modified Files:
        src/sys/dev/fdt: fdt_clock.c fdtvar.h

Log Message:
Add fdtbus_clock_byname, which can be used by clock backends to
lookup clocks in other domains by "clock-output-names" property.
Not intended for ordinary driver use.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/fdt/fdt_clock.c
cvs rdiff -u -r1.32 -r1.33 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_clock.c
diff -u src/sys/dev/fdt/fdt_clock.c:1.1 src/sys/dev/fdt/fdt_clock.c:1.2
--- src/sys/dev/fdt/fdt_clock.c:1.1	Tue Dec 22 21:42:11 2015
+++ src/sys/dev/fdt/fdt_clock.c	Sun Jun 10 13:26:29 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_clock.c,v 1.1 2015/12/22 21:42:11 jmcneill Exp $ */
+/* $NetBSD: fdt_clock.c,v 1.2 2018/06/10 13:26:29 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_clock.c,v 1.1 2015/12/22 21:42:11 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_clock.c,v 1.2 2018/06/10 13:26:29 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -156,3 +156,37 @@ fdtbus_clock_get(int phandle, const char
 
 	return clk;
 }
+
+/*
+ * Search the DT for a clock by "clock-output-names" property.
+ *
+ * This should only be used by clk backends. Not for use by ordinary
+ * clock consumers!
+ */
+struct clk *
+fdtbus_clock_byname(const char *clkname)
+{
+	struct fdtbus_clock_controller *cc;
+	u_int len, resid, index, clock_cells;
+	const char *p;
+
+	for (cc = fdtbus_cc; cc; cc = cc->cc_next) {
+		if (!of_hasprop(cc->cc_phandle, "clock-output-names"))
+			continue;
+		p = fdtbus_get_prop(cc->cc_phandle, "clock-output-names", &len);
+		for (index = 0, resid = len; resid > 0; index++) {
+			if (strcmp(p, clkname) == 0) {
+				if (of_getprop_uint32(cc->cc_phandle, "#clock-cells", &clock_cells))
+					break;
+				const u_int index_raw = htobe32(index);
+				return cc->cc_funcs->decode(cc->cc_dev,
+				    clock_cells > 0 ? &index_raw : NULL,
+				    clock_cells > 0 ? 4 : 0);
+			}
+			resid -= strlen(p) + 1;
+			p += strlen(p) + 1;
+		}
+	}
+
+	return NULL;
+}

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.32 src/sys/dev/fdt/fdtvar.h:1.33
--- src/sys/dev/fdt/fdtvar.h:1.32	Tue May 15 10:17:55 2018
+++ src/sys/dev/fdt/fdtvar.h	Sun Jun 10 13:26:29 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.32 2018/05/15 10:17:55 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.33 2018/06/10 13:26:29 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -303,6 +303,7 @@ void		fdtbus_dma_halt(struct fdtbus_dma 
 
 struct clk *	fdtbus_clock_get(int, const char *);
 struct clk *	fdtbus_clock_get_index(int, u_int);
+struct clk *	fdtbus_clock_byname(const char *);
 
 struct fdtbus_reset *fdtbus_reset_get(int, const char *);
 struct fdtbus_reset *fdtbus_reset_get_index(int, u_int);

Reply via email to