diff mbox

[04/10] UBUNTU: SAUCE: dt/clock: add function to get parent clock name

Message ID 1339140922-10301-1-git-send-email-ike.pan@canonical.com
State New
Headers show

Commit Message

Ike Panhc June 8, 2012, 7:35 a.m. UTC
From: Rob Herring <rob.herring@calxeda.com>

BugLink: http://launchpad.net/bugs/1008345

Signed-off-by: Rob Herring <rob.herring@calxeda.com>
Signed-off-by: Ike Panhc <ike.pan@canonical.com>
---
 drivers/of/clock.c     |   26 +++++++++++++++++++++++++-
 include/linux/of_clk.h |    2 ++
 2 files changed, 27 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/drivers/of/clock.c b/drivers/of/clock.c
index 7546c94..d6c41d3 100644
--- a/drivers/of/clock.c
+++ b/drivers/of/clock.c
@@ -128,6 +128,30 @@  struct clk *of_clk_get(struct device_node *np, int index)
 	return clk;
 }
 
+const char *of_clk_get_parent_name(struct device_node *np, int index)
+{
+	struct of_phandle_args clkspec;
+	const char *clk_name;
+	int rc;
+
+	if (index < 0)
+		return NULL;
+
+	rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index,
+					&clkspec);
+	if (rc)
+		return NULL;
+
+	if (of_property_read_string_index(clkspec.np, "clock-output-names",
+					  clkspec.args_count ? clkspec.args[0] : 0,
+					  &clk_name) < 0)
+		clk_name = clkspec.np->name;
+
+	of_node_put(clkspec.np);
+	return clk_name;
+}
+
+
 /**
  * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
  * @np: pointer to clock consumer node
@@ -210,4 +234,4 @@  void __init of_fixed_clk_setup(struct device_node *node)
 	clk = clk_register_fixed_rate(NULL, clk_name, NULL, CLK_IS_ROOT, rate);
 	if (clk)
 		of_clk_add_provider(node, NULL, clk);
-}
\ No newline at end of file
+}
diff --git a/include/linux/of_clk.h b/include/linux/of_clk.h
index 02ecc98..6a07071 100644
--- a/include/linux/of_clk.h
+++ b/include/linux/of_clk.h
@@ -22,6 +22,8 @@  void of_clk_del_provider(struct device_node *np);
 struct clk *of_clk_get(struct device_node *np, int index);
 struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
 
+const char *of_clk_get_parent_name(struct device_node *np, int index);
+
 void of_clk_init(const struct of_device_id *matches);
 extern void of_fixed_clk_setup(struct device_node *np);