From patchwork Tue Feb 11 19:33:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?David_Lanzend=C3=B6rfer?= X-Patchwork-Id: 319392 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6F1012C00B0 for ; Wed, 12 Feb 2014 06:40:38 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WDJAd-00043B-Pt; Tue, 11 Feb 2014 19:39:04 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WDJ5k-0008Ub-Qt; Tue, 11 Feb 2014 19:34:00 +0000 Received: from kolab.o2s.ch ([2001:1620:2081::4]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WDJ5W-0008Qy-Vz for linux-arm-kernel@lists.infradead.org; Tue, 11 Feb 2014 19:33:47 +0000 Received: from localhost (localhost [127.0.0.1]) by kolab.o2s.ch (Postfix) with ESMTP id 39DEE77347; Tue, 11 Feb 2014 20:36:50 +0100 (CET) X-Virus-Scanned: amavisd-new at example.com Received: from kolab.o2s.ch ([127.0.0.1]) by localhost (kolab.o2s.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Q24joQjhA3U3; Tue, 11 Feb 2014 20:36:49 +0100 (CET) Received: from dizzy-6.o2s.ch (unknown [IPv6:2001:470:26:484:6ef0:49ff:fee6:8dca]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by kolab.o2s.ch (Postfix) with ESMTPSA id E018A7732F; Tue, 11 Feb 2014 20:36:47 +0100 (CET) Subject: [PATCH v5 1/8] clk: sunxi: factors: automatic reparenting support To: devicetree@vger.kernel.org, Ulf Hansson , Laurent Pinchart , Mike Turquette , Simon Baatz , Hans de Goede , Emilio =?utf-8?b?TMOzcGV6?= , linux-mmc@vger.kernel.org, Chris Ball , linux-kernel@vger.kernel.org, H Hartley Sweeten , linux-sunxi@googlegroups.com, Tejun Heo , Maxime Ripard , Guennadi Liakhovetski , linux-arm-kernel@lists.infradead.org From: David =?utf-8?q?Lanzend=C3=B6rfer?= Date: Tue, 11 Feb 2014 20:33:20 +0100 Message-ID: <20140211193319.4568.81780.stgit@dizzy-6.o2s.ch> In-Reply-To: <20140211190543.4568.83517.stgit@dizzy-6.o2s.ch> References: <20140211190543.4568.83517.stgit@dizzy-6.o2s.ch> User-Agent: StGit/0.16 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140211_143347_154875_5AEE1812 X-CRM114-Status: GOOD ( 12.74 ) X-Spam-Score: 0.5 (/) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (0.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- 3.0 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list -0.6 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org From: Emilio López This commit implements .determine_rate, so that our factor clocks can be reparented when needed. Signed-off-by: Emilio López --- drivers/clk/sunxi/clk-factors.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/clk/sunxi/clk-factors.c b/drivers/clk/sunxi/clk-factors.c index 9e23264..3806d97 100644 --- a/drivers/clk/sunxi/clk-factors.c +++ b/drivers/clk/sunxi/clk-factors.c @@ -77,6 +77,41 @@ static long clk_factors_round_rate(struct clk_hw *hw, unsigned long rate, return rate; } +static long clk_factors_determine_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *best_parent_rate, + struct clk **best_parent_p) +{ + struct clk *clk = hw->clk, *parent, *best_parent = NULL; + int i, num_parents; + unsigned long parent_rate, best = 0, child_rate, best_child_rate = 0; + + /* find the parent that can help provide the fastest rate <= rate */ + num_parents = __clk_get_num_parents(clk); + for (i = 0; i < num_parents; i++) { + parent = clk_get_parent_by_index(clk, i); + if (!parent) + continue; + if (__clk_get_flags(clk) & CLK_SET_RATE_PARENT) + parent_rate = __clk_round_rate(parent, rate); + else + parent_rate = __clk_get_rate(parent); + + child_rate = clk_factors_round_rate(hw, rate, &parent_rate); + + if (child_rate <= rate && child_rate > best_child_rate) { + best_parent = parent; + best = parent_rate; + best_child_rate = child_rate; + } + } + + if (best_parent) + *best_parent_p = best_parent; + *best_parent_rate = best; + + return best_child_rate; +} + static int clk_factors_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { @@ -113,6 +148,7 @@ static int clk_factors_set_rate(struct clk_hw *hw, unsigned long rate, } const struct clk_ops clk_factors_ops = { + .determine_rate = clk_factors_determine_rate, .recalc_rate = clk_factors_recalc_rate, .round_rate = clk_factors_round_rate, .set_rate = clk_factors_set_rate,