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_clock_byname, which can be used by cl...



details:   https://anonhg.NetBSD.org/src/rev/8e02a21465a6
branches:  trunk
changeset: 323323:8e02a21465a6
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Jun 10 13:26:29 2018 +0000

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

diffstat:

 sys/dev/fdt/fdt_clock.c |  38 ++++++++++++++++++++++++++++++++++++--
 sys/dev/fdt/fdtvar.h    |   3 ++-
 2 files changed, 38 insertions(+), 3 deletions(-)

diffs (73 lines):

diff -r 18051dbc654f -r 8e02a21465a6 sys/dev/fdt/fdt_clock.c
--- a/sys/dev/fdt/fdt_clock.c   Sun Jun 10 07:52:05 2018 +0000
+++ b/sys/dev/fdt/fdt_clock.c   Sun Jun 10 13:26:29 2018 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
 
        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;
+}
diff -r 18051dbc654f -r 8e02a21465a6 sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h      Sun Jun 10 07:52:05 2018 +0000
+++ b/sys/dev/fdt/fdtvar.h      Sun Jun 10 13:26:29 2018 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -303,6 +303,7 @@
 
 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);



Home | Main Index | Thread Index | Old Index