linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: damien.riegel.ext@parrot.com (Damien Riegel)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] clk: clk-divider: round divider to a valid value when a table is used
Date: Mon, 13 Jan 2014 10:03:30 +0100	[thread overview]
Message-ID: <52D3ABE2.10701@parrot.com> (raw)
In-Reply-To: <1389277515-26444-1-git-send-email-damien.riegel.ext@parrot.com>

clk_divider_bestdiv computes the bestdiv without taking into account if
it is a valid value when CLK_SET_RATE_PARENT is not set, and it may not
be if a table is used. round_rate then returns a rate that is not
reachable by the clock, leading to a set_rate that does nothing but
reports no error.
This patch makes round_rate return a valid rate.

Signed-off-by: Damien Riegel <damien.riegel.ext@parrot.com>
---
The previous version of this patch luckily worked with the clk_div_table
I had. It might return a divider that was less than the computed div. This
patch should now work in every case.
---
 drivers/clk/clk-divider.c |   19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index 8d3009e44fba..658afbc39964 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -144,6 +144,22 @@ static bool _is_valid_div(struct clk_divider *divider, unsigned int div)
 	return true;
 }
 
+static int _round_to_valid_div(struct clk_divider *divider, int div, int maxdiv)
+{
+	const struct clk_div_table *clkt = divider->table;
+	int bestdiv = maxdiv;
+
+	if (!clkt)
+		return div;
+
+	for (; clkt->div; clkt++) {
+		if (clkt->div >= div && bestdiv > clkt->div)
+			bestdiv = clkt->div;
+	}
+
+	return bestdiv;
+}
+
 static int clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate,
 		unsigned long *best_parent_rate)
 {
@@ -161,7 +177,8 @@ static int clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate,
 		parent_rate = *best_parent_rate;
 		bestdiv = DIV_ROUND_UP(parent_rate, rate);
 		bestdiv = bestdiv == 0 ? 1 : bestdiv;
-		bestdiv = bestdiv > maxdiv ? maxdiv : bestdiv;
+		bestdiv = bestdiv > maxdiv ? maxdiv :
+			_round_to_valid_div(divider, bestdiv, maxdiv);
 		return bestdiv;
 	}
 
-- 
1.7.10.4

      reply	other threads:[~2014-01-13  9:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-09 14:25 [PATCH] clk: clk-divider: round divider to a valid value when a table is used Damien Riegel
2014-01-13  9:03 ` Damien Riegel [this message]

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=52D3ABE2.10701@parrot.com \
    --to=damien.riegel.ext@parrot.com \
    --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).