diff mbox

[v7,1/8] clk: sunxi: factors: automatic reparenting support

Message ID 20140217100215.15040.63745.stgit@pagira.o2s.ch (mailing list archive)
State New, archived
Headers show

Commit Message

David Lanzendörfer Feb. 17, 2014, 10:02 a.m. UTC
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(+)


--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Maxime Ripard Feb. 18, 2014, 2:05 p.m. UTC | #1
On Mon, Feb 17, 2014 at 11:02:15AM +0100, David Lanzendörfer wrote:
> 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>

Your signed-off-by is missing here.

Once you added it, you can add my Acked-by

Maxime
Maxime Ripard March 20, 2014, 9:47 a.m. UTC | #2
On Wed, Mar 19, 2014 at 04:39:45PM -0700, Mike Turquette wrote:
> Quoting Maxime Ripard (2014-02-18 06:05:16)
> > On Mon, Feb 17, 2014 at 11:02:15AM +0100, David Lanzendörfer wrote:
> > > 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>
> > 
> > Your signed-off-by is missing here.
> > 
> > Once you added it, you can add my Acked-by
> 
> Yes the patch looks good to me as well. Am I correct in thinking that it
> is independent of the MMC clock phase discussion? If it is resubmitted
> with a proper SoB then I can pick it.

Yes, it's completely independant of the MMC phase stuff.

Emilio, or David, could you resend it?

Maxime
diff mbox

Patch

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,