linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: david.lanzendoerfer@o2s.ch (David Lanzendörfer)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 1/7] clk: sunxi: factors: automatic reparenting support
Date: Wed, 05 Feb 2014 14:53:45 +0100	[thread overview]
Message-ID: <20140205135344.3027.57728.stgit@dizzy-6.o2s.ch> (raw)
In-Reply-To: <20140205134741.3027.50207.stgit@dizzy-6.o2s.ch>

From: Emilio L?pez <emilio@elopez.com.ar>

This commit implements .determine_rate, so that our factor clocks can be
reparented when needed.

Signed-off-by: Emilio L?pez <emilio@elopez.com.ar>
---
 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,

  reply	other threads:[~2014-02-05 13:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-05 13:53 [PATCH v3 0/7] ARM: sunxi: Add driver for SD/MMC hosts found on allwinner sunxi SOCs David Lanzendörfer
2014-02-05 13:53 ` David Lanzendörfer [this message]
2014-02-05 13:53 ` [PATCH v3 2/7] clk: sunxi: Implement MMC phase control David Lanzendörfer
2014-02-05 13:54 ` [PATCH v3 3/7] ARM: sunxi: clk: export clk_sunxi_mmc_phase_control David Lanzendörfer
2014-02-05 13:54 ` [PATCH v3 4/7] ARM: sunxi: Add driver for SD/MMC hosts found on Allwinner sunxi SoCs David Lanzendörfer
2014-02-05 13:54 ` [PATCH v3 5/7] ARM: dts: sun7i: Add support for mmc David Lanzendörfer
2014-02-05 13:54 ` [PATCH v3 6/7] ARM: dts: sun4i: " David Lanzendörfer
2014-02-05 13:55 ` [PATCH v3 7/7] ARM: dts: sun5i: " David Lanzendörfer
2014-02-05 17:17 ` [PATCH v3 0/7] ARM: sunxi: Add driver for SD/MMC hosts found on allwinner sunxi SOCs David Lanzendörfer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140205135344.3027.57728.stgit@dizzy-6.o2s.ch \
    --to=david.lanzendoerfer@o2s.ch \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).