svn commit: r308298 - head/sys/dev/extres/clk
Emmanuel Vadot
manu at FreeBSD.org
Fri Nov 4 17:04:46 UTC 2016
Author: manu
Date: Fri Nov 4 17:04:45 2016
New Revision: 308298
URL: https://svnweb.freebsd.org/changeset/base/308298
Log:
Add clk_set_assigned
assigned-clock-parents are DT properties used to configure
some default parent clocks on one node.
Reviewed by: mmel
MFC after: 2 weeks
Modified:
head/sys/dev/extres/clk/clk.c
head/sys/dev/extres/clk/clk.h
Modified: head/sys/dev/extres/clk/clk.c
==============================================================================
--- head/sys/dev/extres/clk/clk.c Fri Nov 4 17:02:42 2016 (r308297)
+++ head/sys/dev/extres/clk/clk.c Fri Nov 4 17:04:45 2016 (r308298)
@@ -1196,7 +1196,47 @@ clk_get_by_id(device_t dev, struct clkdo
#ifdef FDT
int
-clk_get_by_ofw_index(device_t dev, phandle_t cnode, int idx, clk_t *clk)
+clk_set_assigned(device_t dev, phandle_t node)
+{
+ clk_t clk, clk_parent;
+ int error, nclocks, i;
+
+ error = ofw_bus_parse_xref_list_get_length(node,
+ "assigned-clock-parents", "#clock-cells", &nclocks);
+
+ if (error != 0) {
+ device_printf(dev, "cannot parse assigned-clock-parents property\n");
+ return (error);
+ }
+
+ for (i = 0; i < nclocks; i++) {
+ error = clk_get_by_ofw_index_prop(dev, 0,
+ "assigned-clock-parents", i, &clk_parent);
+ if (error != 0) {
+ device_printf(dev, "cannot get parent %d\n", i);
+ return (error);
+ }
+
+ error = clk_get_by_ofw_index_prop(dev, 0, "assigned-clocks",
+ i, &clk);
+ if (error != 0) {
+ device_printf(dev, "cannot get assigned clock %d\n", i);
+ clk_release(clk_parent);
+ return (error);
+ }
+
+ error = clk_set_parent_by_clk(clk, clk_parent);
+ clk_release(clk_parent);
+ clk_release(clk);
+ if (error != 0)
+ return (error);
+ }
+
+ return (0);
+}
+
+int
+clk_get_by_ofw_index_prop(device_t dev, phandle_t cnode, const char *prop, int idx, clk_t *clk)
{
phandle_t parent, *cells;
device_t clockdev;
@@ -1214,7 +1254,7 @@ clk_get_by_ofw_index(device_t dev, phand
}
- rv = ofw_bus_parse_xref_list_alloc(cnode, "clocks", "#clock-cells", idx,
+ rv = ofw_bus_parse_xref_list_alloc(cnode, prop, "#clock-cells", idx,
&parent, &ncells, &cells);
if (rv != 0) {
return (rv);
@@ -1247,6 +1287,12 @@ done:
}
int
+clk_get_by_ofw_index(device_t dev, phandle_t cnode, int idx, clk_t *clk)
+{
+ return (clk_get_by_ofw_index_prop(dev, cnode, "clocks", idx, clk));
+}
+
+int
clk_get_by_ofw_name(device_t dev, phandle_t cnode, const char *name, clk_t *clk)
{
int rv, idx;
Modified: head/sys/dev/extres/clk/clk.h
==============================================================================
--- head/sys/dev/extres/clk/clk.h Fri Nov 4 17:02:42 2016 (r308297)
+++ head/sys/dev/extres/clk/clk.h Fri Nov 4 17:04:45 2016 (r308298)
@@ -129,7 +129,9 @@ int clk_set_parent_by_clk(clk_t clk, clk
const char *clk_get_name(clk_t clk);
#ifdef FDT
+int clk_set_assigned(device_t dev, phandle_t node);
int clk_get_by_ofw_index(device_t dev, phandle_t node, int idx, clk_t *clk);
+int clk_get_by_ofw_index_prop(device_t dev, phandle_t cnode, const char *prop, int idx, clk_t *clk);
int clk_get_by_ofw_name(device_t dev, phandle_t node, const char *name,
clk_t *clk);
int clk_parse_ofw_out_names(device_t dev, phandle_t node,
More information about the svn-src-head
mailing list