From patchwork Mon Mar 3 18:22:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sylwester Nawrocki/Kernel \\(PLT\\) /SRPOL/Staff Engineer/Samsung Electronics" X-Patchwork-Id: 3756231 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D299FBF13A for ; Mon, 3 Mar 2014 18:24:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C8E6E203E6 for ; Mon, 3 Mar 2014 18:24:00 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A8BB2203DF for ; Mon, 3 Mar 2014 18:23:59 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WKXWs-0002G6-Ao; Mon, 03 Mar 2014 18:23:54 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WKXWp-0000Uw-RH; Mon, 03 Mar 2014 18:23:51 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WKXWl-0000Ts-UR for linux-arm-kernel@lists.infradead.org; Mon, 03 Mar 2014 18:23:49 +0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N1V00G59HQZOY20@mailout3.samsung.com> for linux-arm-kernel@lists.infradead.org; Tue, 04 Mar 2014 03:23:23 +0900 (KST) X-AuditID: cbfee61b-b7f456d000006dfd-2d-5314c89a1a7f Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 52.64.28157.A98C4135; Tue, 04 Mar 2014 03:23:23 +0900 (KST) Received: from amdc1344.digital.local ([106.116.147.32]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N1V001I7HQB1780@mmp2.samsung.com>; Tue, 04 Mar 2014 03:23:22 +0900 (KST) From: Sylwester Nawrocki To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Subject: [RFC PATCH v2 2/2] clk: Add handling of clk parent and rate assigned from DT Date: Mon, 03 Mar 2014 19:22:55 +0100 Message-id: <1393870975-21020-1-git-send-email-s.nawrocki@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1393870533-20845-1-git-send-email-s.nawrocki@samsung.com> References: <1393870533-20845-1-git-send-email-s.nawrocki@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFLMWRmVeSWpSXmKPExsVy+t9jQd3ZJ0SCDb5+ZbGYf+Qcq0X/m4Ws Fgf+7GC0aF68ns3ibNMbdotNj6+xWlzeNYfN4vZlXou1R+6yWyy9fpHJ4umEi2wWrXuPsFsc ftPOajFj8ks2i/UzXrM48HusmbeG0aOluYfN43JfL5PHplWdbB53ru1h89g/dw27x+Yl9R59 W1YxenzeJBfAGcVlk5Kak1mWWqRvl8CVcWntY8aCv4YVF1qXsjcwHlbvYuTgkBAwkZi6zquL kRPIFJO4cG89G4gtJDCdUeLJ31wIu4NJYke7EojNJmAo0Xu0jxHEFhFwkeh8sI4FxGYWuMUk MeWkFIgtLBAusWvFCmYQm0VAVeLbrzawel4BN4k5nx4zQqxVkJgzyQYkzCngLjH7aCczxCo3 iZczL7JPYORdwMiwilE0tSC5oDgpPddIrzgxt7g0L10vOT93EyM4hJ9J72Bc1WBxiFGAg1GJ h9dhikiwEGtiWXFl7iFGCQ5mJRHeiBqgEG9KYmVValF+fFFpTmrxIUZpDhYlcd6DrdaBQgLp iSWp2ampBalFMFkmDk6pBsawbzILjJu+vTHtPjvVQOnK+318hTqq/3wT5aPOTJkRdz1wn1ZZ p9iS3OgLjRunbLh99l5Gatxl64q/b7or3KSeOJUuCdj1PU2uXjBQ/+DyOWv8Mpd8zOpzNZx7 MWF5bumTqj2Ssv0ms+a62+unNSXyvmnUObDv4PniDcs7730wmhapsGzKnnVKLMUZiYZazEXF iQB8r3SlXQIAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140303_132348_276449_1249B217 X-CRM114-Status: GOOD ( 17.32 ) X-Spam-Score: -3.9 (---) Cc: mark.rutland@arm.com, mturquette@linaro.org, gregkh@linuxfoundation.org, t.figa@samsung.com, sw0312.kim@samsung.com, linux-kernel@vger.kernel.org, kyungmin.park@samsung.com, robh+dt@kernel.org, Sylwester Nawrocki , galak@codeaurora.org, grant.likely@linaro.org, linux@arm.linux.org.uk, m.szyprowski@samsung.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,KHOP_BIG_TO_CC, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This function adds a notifier callback run before a driver is bound to a device. It will configure any parent clocks and clock frequencies according to values of 'clock-parents' and 'clock-rates' DT properties respectively. Signed-off-by: Sylwester Nawrocki Acked-by: Kyungmin Park --- Changes since v1: - the helper function to parse and set assigned clock parents and rates made public so it is available to clock providers to call directly; - dropped the platform bus notification and call of_clk_device_setup() is is now called from the driver core, rather than from the notification callback; - s/of_clk_get_list_entry/of_clk_get_by_property. --- .../devicetree/bindings/clock/clock-bindings.txt | 23 ++++++ drivers/base/dd.c | 5 ++ drivers/clk/clk.c | 77 ++++++++++++++++++++ include/linux/clk-provider.h | 6 ++ 4 files changed, 111 insertions(+) diff --git a/Documentation/devicetree/bindings/clock/clock-bindings.txt b/Documentation/devicetree/bindings/clock/clock-bindings.txt index 7c52c29..eb8d547 100644 --- a/Documentation/devicetree/bindings/clock/clock-bindings.txt +++ b/Documentation/devicetree/bindings/clock/clock-bindings.txt @@ -115,3 +115,26 @@ clock signal, and a UART. ("pll" and "pll-switched"). * The UART has its baud clock connected the external oscillator and its register clock connected to the PLL clock (the "pll-switched" signal) + +==Assigned clock parents and rates== + +Some platforms require static configuration of (parts of) the clock controller +often determined by the board design. Such a configuration can be specified in +a clock consumer node through clock-parents and clock-rates DT properties. +The former should contain list of parent clocks in form of phandle and clock +specifier pairs, the latter the list of assigned clock frequency values +(one cell each). + + uart@a000 { + compatible = "fsl,imx-uart"; + reg = <0xa000 0x1000>; + ... + clocks = <&clkcon 0>, <&clkcon 3>; + clock-names = "baud", "mux"; + + clock-parents = <0>, <&pll 1>; + clock-rates = <460800>; + }; + +In this example the pll is set as parent of "mux" clock and frequency of "baud" +clock is specified as 460800 Hz. diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 0605176..f0cbac1 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "base.h" #include "power/power.h" @@ -278,6 +279,10 @@ static int really_probe(struct device *dev, struct device_driver *drv) if (ret) goto probe_failed; + ret = of_clk_device_setup(dev); + if (ret) + goto probe_failed; + if (driver_sysfs_add(dev)) { printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n", __func__, dev_name(dev)); diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 19f6f3f..6fdc49b 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2528,6 +2528,83 @@ const char *of_clk_get_parent_name(struct device_node *np, int index) EXPORT_SYMBOL_GPL(of_clk_get_parent_name); /** + * of_clk_device_setup() - parse and set clk configuration assigned to a device + * @node: device node to apply the configuration for + * + * This function parses 'clock-parents' and 'clock-rates' properties and sets + * any specified clock parents and rates. + */ +int of_clk_device_setup(struct device *dev) +{ + struct device_node *node = dev->of_node; + struct property *prop; + const __be32 *cur; + int rc, index, num_parents; + struct clk *clk, *pclk; + u32 rate; + + if (!node) + return 0; + + num_parents = of_count_phandle_with_args(node, "clock-parents", + "#clock-cells"); + if (num_parents == -EINVAL) + pr_err("clk: Invalid value of clock-parents property at %s\n", + node->full_name); + + for (index = 0; index < num_parents; index++) { + pclk = of_clk_get_by_property(node, "clock-parents", index); + if (IS_ERR(pclk)) { + /* skip empty (null) phandles */ + if (PTR_ERR(pclk) == -ENOENT) + continue; + + pr_warn("clk: couldn't get parent clock %d for %s\n", + index, node->full_name); + return PTR_ERR(pclk); + } + + clk = of_clk_get(node, index); + if (IS_ERR(clk)) { + pr_warn("clk: couldn't get clock %d for %s\n", + index, node->full_name); + return PTR_ERR(clk); + } + + rc = clk_set_parent(clk, pclk); + if (rc < 0) + pr_err("clk: failed to reparent %s to %s: %d\n", + __clk_get_name(clk), __clk_get_name(pclk), rc); + else + pr_debug("clk: set %s as parent of %s\n", + __clk_get_name(pclk), __clk_get_name(clk)); + } + + index = 0; + of_property_for_each_u32(node, "clock-rates", prop, cur, rate) { + if (rate) { + clk = of_clk_get(node, index); + if (IS_ERR(clk)) { + pr_warn("clk: couldn't get clock %d for %s\n", + index, node->full_name); + return PTR_ERR(clk); + } + + rc = clk_set_rate(clk, rate); + if (rc < 0) + pr_err("clk: couldn't set %s clock rate: %d\n", + __clk_get_name(clk), rc); + else + pr_debug("clk: set rate of clock %s to %lu\n", + __clk_get_name(clk), clk_get_rate(clk)); + } + index++; + } + + return 0; +} + +/** * of_clk_init() - Scan and init clock providers from the DT * @matches: array of compatible values and init functions for providers. * diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 939533d..2cd0fbb 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -509,6 +509,7 @@ const char *of_clk_get_parent_name(struct device_node *np, int index); void of_clk_init(const struct of_device_id *matches); +int of_clk_device_setup(struct device *dev); #else /* !CONFIG_OF */ static inline int of_clk_add_provider(struct device_node *np, @@ -537,6 +538,11 @@ static inline const char *of_clk_get_parent_name(struct device_node *np, } #define of_clk_init(matches) \ { while (0); } + +int of_clk_device_setup(struct device *dev) +{ + return 0; +} #endif /* CONFIG_OF */ /*