From: Stephen Boyd <sboyd@codeaurora.org>
To: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
Mike Turquette <mturquette@linaro.org>,
Saravana Kannan <skannan@codeaurora.org>
Subject: [RFC/PATCH 03/13] clk: Add of_clk_match() for device drivers
Date: Wed, 12 Jun 2013 18:48:59 -0700 [thread overview]
Message-ID: <1371088149-22562-4-git-send-email-sboyd@codeaurora.org> (raw)
In-Reply-To: <1371088149-22562-1-git-send-email-sboyd@codeaurora.org>
In similar fashion as of_regulator_match() add an of_clk_match()
function that finds an initializes clock init_data structs from
devicetree. Drivers should use this API to find clocks that their
device is providing and then iterate over their match table
registering the clocks with the init data parsed.
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
---
drivers/clk/clk.c | 64 ++++++++++++++++++++++++++++++++++++++++++++
include/linux/clk-provider.h | 10 +++++++
2 files changed, 74 insertions(+)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 282b10e..f40ce9b 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2282,4 +2282,68 @@ err:
return -ENOMEM;
}
EXPORT_SYMBOL_GPL(of_init_clk_data);
+
+/**
+ * of_clk_match() - Scan and match clock providers from the DT node of a device
+ * @dev: device initializing clock providers
+ * @matches: match table of clocks
+ * @num_matches: number of entries in @matches
+ *
+ * This function uses a match table specified by the clock driver to parse
+ * clock init data from the device tree. @dev is expected to be a device with
+ * a 'clocks' child node containing a set of child nodes, each providing the
+ * init data for one clock. The data parsed from a child node will be matched
+ * to a clock based on the child node's name. Note that the match table is
+ * modified in place.
+ *
+ * Returns the number of matches found or a negative error code on failure.
+ */
+int of_clk_match(struct device *dev, struct of_clk_match *matches,
+ int num_matches)
+{
+ int count = 0;
+ int err, i;
+ struct device_node *np, *clocks;
+ struct clk_init_data *init;
+
+ clocks = of_find_node_by_name(dev->of_node, "clocks");
+ if (!clocks)
+ return -EINVAL;
+
+ for (i = 0; i < num_matches; i++) {
+ struct of_clk_match *match = &matches[i];
+ match->init_data = NULL;
+ match->of_node = NULL;
+ }
+
+ for_each_available_child_of_node(clocks, np) {
+ for (i = 0; i < num_matches; i++) {
+ struct of_clk_match *match = &matches[i];
+ if (match->of_node)
+ continue;
+
+ if (strcmp(match->name, np->name))
+ continue;
+
+ init = devm_kzalloc(dev, sizeof(*init), GFP_KERNEL);
+ if (!init)
+ return -ENOMEM;
+
+ err = of_init_clk_data(np, init);
+ if (err) {
+ dev_err(dev,
+ "failed to parse DT for clock %s\n",
+ np->name);
+ return err;
+ }
+ match->of_node = np;
+ match->init_data = init;
+ count++;
+ break;
+ }
+ }
+
+ return count;
+}
+EXPORT_SYMBOL_GPL(of_clk_match);
#endif
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index bdcc655..3668a76 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -454,6 +454,16 @@ void of_clk_init(const struct of_device_id *matches);
int of_init_clk_data(struct device_node *np, struct clk_init_data *init);
+struct of_clk_match {
+ const char *name;
+ void *driver_data;
+ struct clk_init_data *init_data;
+ struct device_node *of_node;
+};
+
+int of_clk_match(struct device *dev, struct of_clk_match *matches,
+ int num_matches);
+
#define CLK_OF_DECLARE(name, compat, fn) \
static const struct of_device_id __clk_of_table_##name \
__used __section(__clk_of_table) \
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
next prev parent reply other threads:[~2013-06-13 1:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-13 1:48 [RFC/PATCH 00/13] Add support for MSM's mmio clocks Stephen Boyd
2013-06-13 1:48 ` [RFC/PATCH 01/13] clk: fixed-rate: Export clk_fixed_rate_register() Stephen Boyd
2013-06-13 1:48 ` [RFC/PATCH 02/13] clk: Add of_init_clk_data() to parse common clock bindings Stephen Boyd
2013-06-13 1:48 ` Stephen Boyd [this message]
2013-06-13 1:49 ` [RFC/PATCH 04/13] clk: Add set_rate_and_parent() op Stephen Boyd
[not found] ` <1371088149-22562-1-git-send-email-sboyd-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2013-06-13 1:49 ` [RFC/PATCH 05/13] clk: msm: Add support for phase locked loops (PLLs) Stephen Boyd
2013-06-13 1:49 ` [RFC/PATCH 06/13] clk: msm: Add support for root clock generators (RCGs) Stephen Boyd
2013-06-13 1:49 ` [RFC/PATCH 07/13] clk: msm: Add support for branches/gate clocks Stephen Boyd
2013-06-13 1:49 ` [RFC/PATCH 08/13] clk: msm: Add MSM clock driver Stephen Boyd
2013-06-13 1:49 ` [RFC/PATCH 09/13] clk: msm: Add support for MSM8960's global clock controller (GCC) Stephen Boyd
2013-06-13 1:49 ` [RFC/PATCH 10/13] clk: msm: Add support for MSM8960's multimedia clock controller (MMCC) Stephen Boyd
2013-06-13 1:49 ` [RFC/PATCH 11/13] ARM: dts: msm: Add MSM8960 GCC DT nodes Stephen Boyd
2013-06-13 1:49 ` [RFC/PATCH 12/13] ARM: dts: msm: Add MSM8960 MMCC " Stephen Boyd
2013-06-13 1:49 ` [RFC/PATCH 13/13] ARM: dts: msm: Add clock entries for MSM8960 uart device Stephen Boyd
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=1371088149-22562-4-git-send-email-sboyd@codeaurora.org \
--to=sboyd@codeaurora.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@linaro.org \
--cc=skannan@codeaurora.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).