devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tero Kristo <t-kristo@ti.com>
To: linux-omap@vger.kernel.org, mturquette@linaro.org
Cc: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org
Subject: [PATCH 2/4] clk: add support for default-rate
Date: Thu, 13 Feb 2014 11:00:46 +0200	[thread overview]
Message-ID: <1392282048-6284-3-git-send-email-t-kristo@ti.com> (raw)
In-Reply-To: <1392282048-6284-1-git-send-email-t-kristo@ti.com>

default-rate property can now be used to set initial rates for clocks.
This is added by default for all clocks which get initialized through
of_clk_init().

Signed-off-by: Tero Kristo <t-kristo@ti.com>
---
 .../devicetree/bindings/clock/clock-bindings.txt   |    9 ++
 drivers/clk/clk.c                                  |   86 ++++++++++++++++++++
 include/linux/clk-provider.h                       |    2 +
 3 files changed, 97 insertions(+)

diff --git a/Documentation/devicetree/bindings/clock/clock-bindings.txt b/Documentation/devicetree/bindings/clock/clock-bindings.txt
index 7c52c29..d676112 100644
--- a/Documentation/devicetree/bindings/clock/clock-bindings.txt
+++ b/Documentation/devicetree/bindings/clock/clock-bindings.txt
@@ -44,6 +44,15 @@ For example:
   clocks by index. The names should reflect the clock output signal
   names for the device.
 
+default-rate:	Sets the rate of the clock during boot to the provided
+		rate.
+
+For example:
+
+    clk-divider {
+        default-rate = <1000000>;
+    };
+
 ==Clock consumers==
 
 Required properties:
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 5517944..cb144e4 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2526,6 +2526,89 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
 }
 EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
 
+static LIST_HEAD(clk_init_info_list);
+
+struct clk_init_info {
+	struct device_node *node;
+	struct clk *clk;
+	u32 rate;
+	struct list_head link;
+	struct list_head sort_link;
+};
+
+int __init of_clk_parse_init_rate(struct device_node *node, struct clk *clk)
+{
+	u32 rate;
+	struct clk_init_info *cinfo;
+
+	if (of_property_read_u32(node, "default-rate", &rate))
+		return 0;
+
+	cinfo = kzalloc(sizeof(*cinfo), GFP_KERNEL);
+	if (!cinfo)
+		return -ENOMEM;
+
+	cinfo->node = node;
+	cinfo->clk = clk;
+	cinfo->rate = rate;
+	list_add(&cinfo->link, &clk_init_info_list);
+	INIT_LIST_HEAD(&cinfo->sort_link);
+
+	return 0;
+}
+
+int __init of_clk_set_init_rates(void)
+{
+	struct clk_init_info *cinfo, *tmp;
+	struct of_phandle_args clkspec;
+	int ret = 0;
+	struct list_head sorted_list;
+	struct clk *clk;
+
+	INIT_LIST_HEAD(&sorted_list);
+
+	list_for_each_entry(cinfo, &clk_init_info_list, link) {
+		/* Get missing clk pointers */
+		if (!cinfo->clk) {
+			clkspec.np = cinfo->node;
+			cinfo->clk = of_clk_get_from_provider(&clkspec);
+		}
+
+		/* Check if we are the parent of any of the sorted clocks */
+		list_for_each_entry(tmp, &sorted_list, sort_link) {
+			clk = tmp->clk;
+			while (clk && clk != cinfo->clk)
+				clk = clk->parent;
+
+			if (clk == cinfo->clk) {
+				/* Add us before this node in the list */
+				list_add_tail(&cinfo->sort_link,
+					      &tmp->sort_link);
+				break;
+			}
+		}
+
+		if (list_empty(&cinfo->sort_link))
+			list_add_tail(&cinfo->sort_link, &sorted_list);
+	}
+
+	/* Process sorted list and set clk rates */
+	list_for_each_entry_safe(cinfo, tmp, &sorted_list, sort_link) {
+		int r = clk_set_rate(cinfo->clk, cinfo->rate);
+		if (r) {
+			pr_err("%s: clk_set_rate for %s failed: %d\n", __func__,
+			       cinfo->node->name, ret);
+			ret = r;
+		}
+
+		/* Clean up the static list */
+		list_del(&cinfo->link);
+		kfree(cinfo);
+	}
+
+	return ret;
+}
+
 /**
  * of_clk_init() - Scan and init clock providers from the DT
  * @matches: array of compatible values and init functions for providers.
@@ -2544,6 +2627,9 @@ void __init of_clk_init(const struct of_device_id *matches)
 	for_each_matching_node_and_match(np, matches, &match) {
 		of_clk_init_cb_t clk_init_cb = match->data;
 		clk_init_cb(np);
+		of_clk_parse_init_rate(np, NULL);
 	}
+
+	of_clk_set_init_rates();
 }
 #endif
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 939533d..1bbd194 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -506,6 +506,8 @@ struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
 struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
 int of_clk_get_parent_count(struct device_node *np);
 const char *of_clk_get_parent_name(struct device_node *np, int index);
+int of_clk_parse_init_rate(struct device_node *node, struct clk *clk);
+int of_clk_set_init_rates(void);
 
 void of_clk_init(const struct of_device_id *matches);
 
-- 
1.7.9.5


  parent reply	other threads:[~2014-02-13  9:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-13  9:00 [PATCH 0/4] clk: dt: add support for default rate/parent Tero Kristo
2014-02-13  9:00 ` [PATCH 1/4] clk: ti: mux: add support for default-parenting Tero Kristo
2014-02-13  9:00 ` Tero Kristo [this message]
2014-02-13  9:00 ` [PATCH 3/4] clk: ti: add support for default-rate property from DT Tero Kristo
2014-02-28 22:51   ` Tony Lindgren
2014-02-13  9:00 ` [PATCH 4/4] clk: ti: omap4: set default-parents and default-rates using DT Tero Kristo
2014-03-05 13:10 ` [PATCH 0/4] clk: dt: add support for default rate/parent Tero Kristo
2014-03-20 21:23   ` Mike Turquette
2014-03-21  8:02     ` Tero Kristo
2014-03-21  8:12     ` Peter De Schrijver
2014-03-25  0:38       ` Mike Turquette
2014-03-25  7:28         ` Peter De Schrijver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1392282048-6284-3-git-send-email-t-kristo@ti.com \
    --to=t-kristo@ti.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=mturquette@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).