From mboxrd@z Thu Jan 1 00:00:00 1970 From: David =?utf-8?q?Lanzend=C3=B6rfer?= Subject: [PATCH v7 1/8] clk: sunxi: factors: automatic reparenting support Date: Mon, 17 Feb 2014 11:02:15 +0100 Message-ID: <20140217100215.15040.63745.stgit@pagira.o2s.ch> References: <20140217095907.15040.81893.stgit@pagira.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: <20140217095907.15040.81893.stgit-pgFh0Jf6HD9Xzn/AsuzBOg@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.