From patchwork Wed Jun 6 12:28:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ike Panhc X-Patchwork-Id: 163343 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id E311EB6F13 for ; Wed, 6 Jun 2012 22:28:18 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1ScFLO-0002oY-NS; Wed, 06 Jun 2012 12:28:10 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1ScFLL-0002ns-6r for kernel-team@lists.ubuntu.com; Wed, 06 Jun 2012 12:28:07 +0000 Received: from [210.242.151.101] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ScFLK-00063o-J7 for kernel-team@lists.ubuntu.com; Wed, 06 Jun 2012 12:28:07 +0000 From: Ike Panhc To: kernel-team@lists.ubuntu.com Subject: [PATCH 09/21] UBUNTU: SAUCE: dt/clock: Add handling for fixed clocks and a clock node setup iterator Date: Wed, 6 Jun 2012 20:28:03 +0800 Message-Id: <1338985683-26242-1-git-send-email-ike.pan@canonical.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1338985555-25924-1-git-send-email-ike.pan@canonical.com> References: <1338985555-25924-1-git-send-email-ike.pan@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: kernel-team-bounces@lists.ubuntu.com Errors-To: kernel-team-bounces@lists.ubuntu.com From: Grant Likely BugLink: http://launchpad.net/bugs/1008345 Signed-off-by: Grant Likely [Rob Herring] Rework to use common clock infrastructure Signed-off-by: Rob Herring Signed-off-by: Ike Panhc --- drivers/of/clock.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- include/linux/of_clk.h | 4 ++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/of/clock.c b/drivers/of/clock.c index f09a5f7..6ebfc26 100644 --- a/drivers/of/clock.c +++ b/drivers/of/clock.c @@ -2,7 +2,8 @@ * Clock infrastructure for device tree platforms */ -#include +#include +#include #include #include #include @@ -164,3 +165,45 @@ struct clk *of_clk_get_by_name(struct device_node *np, const char *name) return clk; } EXPORT_SYMBOL_GPL(of_clk_get_by_name); + +/** + * of_clk_init() - Scan and init clock providers from the DT + * @matches: array of compatible values and init functions for providers. + * + * This function scans the device tree for matching clock providers and + * calls their initialization functions + */ +void __init of_clk_init(const struct of_device_id *matches) +{ + struct device_node *np; + + for_each_matching_node(np, matches) { + const struct of_device_id *match = of_match_node(matches, np); + of_clk_init_cb_t clk_init_cb = match->data; + clk_init_cb(np); + } +} + +static struct clk *of_fixed_clk_get(struct of_phandle_args *a, void *data) +{ + return data; +} + +/** + * of_fixed_clk_setup() - Setup function for simple fixed rate clock + */ +void __init of_fixed_clk_setup(struct device_node *node) +{ + struct clk *clk; + const char *clk_name = node->name; + u32 rate; + + if (of_property_read_u32(node, "clock-frequency", &rate)) + return; + + of_property_read_string(node, "clock-output-names", &clk_name); + + clk = clk_register_fixed_rate(NULL, clk_name, NULL, CLK_IS_ROOT, rate); + if (clk) + of_clk_add_provider(node, of_fixed_clk_get, clk); +} \ No newline at end of file diff --git a/include/linux/of_clk.h b/include/linux/of_clk.h index dcbd27b..02ecc98 100644 --- a/include/linux/of_clk.h +++ b/include/linux/of_clk.h @@ -10,6 +10,7 @@ struct clk; #ifdef CONFIG_OF_CLOCK struct device_node; +typedef void (*of_clk_init_cb_t)(struct device_node *); int of_clk_add_provider(struct device_node *np, struct clk *(*clk_src_get)(struct of_phandle_args *args, @@ -21,6 +22,9 @@ 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); +void of_clk_init(const struct of_device_id *matches); +extern void of_fixed_clk_setup(struct device_node *np); + #else static struct clk *of_clk_get(struct device_node *np, int index) {