diff mbox

[v10,01/15] clk: sunxi: factors: automatic reparenting support

Message ID 1399046249-19472-2-git-send-email-hdegoede@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Hans de Goede May 2, 2014, 3:57 p.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>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 drivers/clk/sunxi/clk-factors.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Comments

Maxime Ripard May 6, 2014, 6:51 p.m. UTC | #1
Hi Emilio,

On Fri, May 02, 2014 at 05:57:15PM +0200, Hans de Goede 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>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Any chance you merge this? Since it's pretty consensual, needed by
other drivers, and that you are the author, I can it can go in.

Thanks,
Maxime
Emilio López May 6, 2014, 8:24 p.m. UTC | #2
Hi,

El 06/05/14 15:51, Maxime Ripard escribió:
> Hi Emilio,
>
> On Fri, May 02, 2014 at 05:57:15PM +0200, Hans de Goede 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>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
>
> Any chance you merge this? Since it's pretty consensual, needed by
> other drivers, and that you are the author, I can it can go in.

I merged it on my tree for Mike on April 22nd

http://lists.infradead.org/pipermail/linux-arm-kernel/2014-April/249259.html

It seems Mike has taken another copy for 3.16 though

http://lists.infradead.org/pipermail/linux-arm-kernel/2014-May/253661.html

Mike, do you want to drop the patches and have me take both of them, or 
would you prefer it if I dropped my copy?

Cheers,

Emilio
--
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
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,