From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755212AbaBKTde (ORCPT ); Tue, 11 Feb 2014 14:33:34 -0500 Received: from kolab.o2s.ch ([77.109.136.180]:60092 "EHLO kolab.o2s.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753128AbaBKTda (ORCPT ); Tue, 11 Feb 2014 14:33:30 -0500 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.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, From mboxrd@z Thu Jan 1 00:00:00 1970 From: David =?utf-8?q?Lanzend=C3=B6rfer?= Subject: [PATCH v5 1/8] clk: sunxi: factors: automatic reparenting support Date: Tue, 11 Feb 2014 20:33:20 +0100 Message-ID: <20140211193319.4568.81780.stgit@dizzy-6.o2s.ch> References: <20140211190543.4568.83517.stgit@dizzy-6.o2s.ch> Reply-To: linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20140211190543.4568.83517.stgit-GPtPHOohwllnsqa/0SyWJQ@public.gmane.org> List-Post: , List-Help: , List-Archive: Sender: linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-Subscribe: , List-Unsubscribe: , To: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Ulf Hansson , Laurent Pinchart , Mike Turquette , Simon Baatz , Hans de Goede , Emilio =?utf-8?b?TMOzcGV6?= , linux-mmc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Chris Ball , linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, H Hartley Sweeten , linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org, Tejun Heo , Maxime Ripard , Guennadi Liakhovetski , linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org List-Id: devicetree@vger.kernel.org From: Emilio L=C3=B3pez This commit implements .determine_rate, so that our factor clocks can be reparented when needed. Signed-off-by: Emilio L=C3=B3pez --- 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-factor= s.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, un= signed long rate, return rate; } =20 +static long clk_factors_determine_rate(struct clk_hw *hw, unsigned long ra= te, + unsigned long *best_parent_rate, + struct clk **best_parent_p) +{ + struct clk *clk =3D hw->clk, *parent, *best_parent =3D NULL; + int i, num_parents; + unsigned long parent_rate, best =3D 0, child_rate, best_child_rate =3D 0; + + /* find the parent that can help provide the fastest rate <=3D rate */ + num_parents =3D __clk_get_num_parents(clk); + for (i =3D 0; i < num_parents; i++) { + parent =3D clk_get_parent_by_index(clk, i); + if (!parent) + continue; + if (__clk_get_flags(clk) & CLK_SET_RATE_PARENT) + parent_rate =3D __clk_round_rate(parent, rate); + else + parent_rate =3D __clk_get_rate(parent); + + child_rate =3D clk_factors_round_rate(hw, rate, &parent_rate); + + if (child_rate <=3D rate && child_rate > best_child_rate) { + best_parent =3D parent; + best =3D parent_rate; + best_child_rate =3D child_rate; + } + } + + if (best_parent) + *best_parent_p =3D best_parent; + *best_parent_rate =3D 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, unsi= gned long rate, } =20 const struct clk_ops clk_factors_ops =3D { + .determine_rate =3D clk_factors_determine_rate, .recalc_rate =3D clk_factors_recalc_rate, .round_rate =3D clk_factors_round_rate, .set_rate =3D clk_factors_set_rate, --=20 You received this message because you are subscribed to the Google Groups "= linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an e= mail to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out. From mboxrd@z Thu Jan 1 00:00:00 1970 From: david.lanzendoerfer@o2s.ch (David =?utf-8?q?Lanzend=C3=B6rfer?=) Date: Tue, 11 Feb 2014 20:33:20 +0100 Subject: [PATCH v5 1/8] clk: sunxi: factors: automatic reparenting support In-Reply-To: <20140211190543.4568.83517.stgit@dizzy-6.o2s.ch> References: <20140211190543.4568.83517.stgit@dizzy-6.o2s.ch> Message-ID: <20140211193319.4568.81780.stgit@dizzy-6.o2s.ch> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.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,