summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2011-11-29 16:27:17 -0800
committerGerrit <chrome-bot@google.com>2011-11-30 13:01:47 -0800
commite48f5d4d14f2e84593d262063b05797bc328dc83 (patch)
treebd83fa56dd618e920c9d6164d9e9783cee754821
parent4a466bf48a887e3a2eba3e971a3a459b5cbc80be (diff)
fdt: Add function to read a clock rate from fdt
This reads the frequency of a named clock from the fdt. BUG=chromium-os:23496 TEST=build and boot on Seaboard, T33, Kaen Change-Id: Ib35bf7ef749f51862644218b1015057ca4e25203 Reviewed-on: https://gerrit.chromium.org/gerrit/12243 Reviewed-by: Che-Liang Chiou <clchiou@chromium.org> Commit-Ready: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org>
-rw-r--r--common/fdt_decode.c15
-rw-r--r--include/fdt_decode.h15
2 files changed, 30 insertions, 0 deletions
diff --git a/common/fdt_decode.c b/common/fdt_decode.c
index 96807c47c9..3d956c3c16 100644
--- a/common/fdt_decode.c
+++ b/common/fdt_decode.c
@@ -718,3 +718,18 @@ int fdt_decode_region(const void *blob, int node,
debug("%s: size=%zx\n", __func__, *size);
return 0;
}
+
+int fdt_decode_clock_rate(const void *blob, const char *clock_name,
+ ulong default_rate)
+{
+ int node;
+
+ node = fdt_node_offset_by_compatible(blob, 0, "board-clocks");
+ if (node >= 0) {
+ node = lookup_phandle(blob, node, clock_name);
+ if (node >= 0)
+ return get_int(blob, node, "clock-frequency",
+ default_rate);
+ }
+ return default_rate;
+}
diff --git a/include/fdt_decode.h b/include/fdt_decode.h
index 6087c21861..68d31653b5 100644
--- a/include/fdt_decode.h
+++ b/include/fdt_decode.h
@@ -614,3 +614,18 @@ int fdt_decode_nand(const void *blob, int node, struct fdt_nand *config);
*/
int fdt_decode_region(const void *blob, int node,
const char *prop_name, void **ptrp, size_t *size);
+
+/**
+ * Look up the required rate of a particular clock in the FDT.
+ *
+ * These are expected to be in a board-clocks compatible node, with a
+ * property pointing to the phandle of each clock. The clock-frequency
+ * property in that phandle is returned.
+ *
+ * @param blob FDT blob
+ * @param clock_name Name of clock to look up (must name a phandle)
+ * @param default_rate Default clock rate to return if property not found
+ * @return clock rate as found in FDT, or default_rate if not found
+ */
+int fdt_decode_clock_rate(const void *blob, const char *clock_name,
+ ulong default_rate);