public inbox for linux-tegra@vger.kernel.org
 help / color / mirror / Atom feed
From: Colin Cross <ccross@android.com>
To: linux-tegra@vger.kernel.org
Cc: konkers@android.com, olof@lixom.net,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, mike@compulab.co.il,
	Colin Cross <ccross@android.com>,
	Russell King <linux@arm.linux.org.uk>
Subject: [PATCH 2/7] ARM: tegra: clock: Round rate before setting rate
Date: Mon, 21 Feb 2011 18:39:47 -0800	[thread overview]
Message-ID: <1298342392-21236-3-git-send-email-ccross@android.com> (raw)
In-Reply-To: <1298342392-21236-1-git-send-email-ccross@android.com>

Call the clock's round_rate op, if it exists, before calling
the set_rate op.  This will help later when dvfs is added,
dvfs needs to know what the final rate will be before the
frequency changes.

Also requires fixes to the round rate functions to ensure
calling round rate and then set rate will not cause the
frequency to be rounded down twice.  When picking clock
divider values, the clock framework picks the closest
frequency that is lower than the requested frequency.  If
the new frequency calculated from the divider value is
rounded down, and then passed to set_rate, it will get
rounded down again, possibly resulting in a frequency two
steps lower than the original requested frequency.

Fix the problem by rounding up when calculating the frequency
coming out of a clock divider, so if that frequency is
requested again, the same divider value will be picked.

Signed-off-by: Colin Cross <ccross@android.com>
---
 arch/arm/mach-tegra/clock.c         |   12 ++++++++++++
 arch/arm/mach-tegra/tegra2_clocks.c |    8 ++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-tegra/clock.c b/arch/arm/mach-tegra/clock.c
index 165aa9c..e028320 100644
--- a/arch/arm/mach-tegra/clock.c
+++ b/arch/arm/mach-tegra/clock.c
@@ -86,6 +86,7 @@ static unsigned long clk_predict_rate_from_parent(struct clk *c, struct clk *p)
 
 	if (c->mul != 0 && c->div != 0) {
 		rate *= c->mul;
+		rate += c->div - 1; /* round up */
 		do_div(rate, c->div);
 	}
 
@@ -240,12 +241,23 @@ EXPORT_SYMBOL(clk_get_parent);
 
 int clk_set_rate_locked(struct clk *c, unsigned long rate)
 {
+	long new_rate;
+
 	if (!c->ops || !c->ops->set_rate)
 		return -ENOSYS;
 
 	if (rate > c->max_rate)
 		rate = c->max_rate;
 
+	if (c->ops && c->ops->round_rate) {
+		new_rate = c->ops->round_rate(c, rate);
+
+		if (new_rate < 0)
+			return new_rate;
+
+		rate = new_rate;
+	}
+
 	return c->ops->set_rate(c, rate);
 }
 
diff --git a/arch/arm/mach-tegra/tegra2_clocks.c b/arch/arm/mach-tegra/tegra2_clocks.c
index 2ca8b74..73e112f 100644
--- a/arch/arm/mach-tegra/tegra2_clocks.c
+++ b/arch/arm/mach-tegra/tegra2_clocks.c
@@ -898,9 +898,9 @@ static long tegra2_pll_div_clk_round_rate(struct clk *c, unsigned long rate)
 		divider = clk_div71_get_divider(parent_rate, rate);
 		if (divider < 0)
 			return divider;
-		return parent_rate * 2 / (divider + 2);
+		return DIV_ROUND_UP(parent_rate * 2, divider + 2);
 	} else if (c->flags & DIV_2) {
-		return parent_rate / 2;
+		return DIV_ROUND_UP(parent_rate, 2);
 	}
 	return -EINVAL;
 }
@@ -1092,12 +1092,12 @@ static long tegra2_periph_clk_round_rate(struct clk *c,
 		if (divider < 0)
 			return divider;
 
-		return parent_rate * 2 / (divider + 2);
+		return DIV_ROUND_UP(parent_rate * 2, divider + 2);
 	} else if (c->flags & DIV_U16) {
 		divider = clk_div16_get_divider(parent_rate, rate);
 		if (divider < 0)
 			return divider;
-		return parent_rate / (divider + 1);
+		return DIV_ROUND_UP(parent_rate, divider + 1);
 	}
 	return -EINVAL;
 }
-- 
1.7.3.1

  parent reply	other threads:[~2011-02-22  2:39 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-22  2:39 [PATCH 0/7] Second batch of Tegra clock updates for 2.6.39 Colin Cross
2011-02-22  2:39 ` [PATCH 1/7] ARM: tegra: clock: Refcount periph clock enables Colin Cross
     [not found]   ` <1298342392-21236-2-git-send-email-ccross-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org>
2011-02-22  5:25     ` Olof Johansson
2011-02-22  2:39 ` Colin Cross [this message]
     [not found]   ` <1298342392-21236-3-git-send-email-ccross-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org>
2011-02-22  5:26     ` [PATCH 2/7] ARM: tegra: clock: Round rate before setting rate Olof Johansson
2011-02-22  2:39 ` [PATCH 3/7] ARM: tegra: clock: Check for clk_num == 0 Colin Cross
2011-02-22  5:29   ` Olof Johansson
2011-02-22  2:39 ` [PATCH 4/7] ARM: tegra: Move tegra_common_init to tegra_init_early Colin Cross
2011-02-22  5:30   ` Olof Johansson
2011-02-22  2:39 ` [PATCH 5/7] ARM: tegra: timer: Enable timer and rtc clocks Colin Cross
     [not found]   ` <1298342392-21236-6-git-send-email-ccross-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org>
2011-02-22  5:32     ` Olof Johansson
     [not found]       ` <AANLkTim=TZaqZFSJwOAN2gntvu=fiHVPQVn12=WyF9Wi-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-02-22  8:00         ` Colin Cross
     [not found]           ` <AANLkTi=pJw7oTUY2jmaSB=chds0fXFaA3+jrT=y8Jpzv-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-02-22 15:28             ` Olof Johansson
2011-02-22 20:56     ` Russell King - ARM Linux
     [not found]       ` <20110222205634.GF29559-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2011-02-23 17:39         ` Colin Cross
2011-02-22  2:39 ` [PATCH 6/7] ARM: tegra: common: Enable core clocks Colin Cross
     [not found]   ` <1298342392-21236-7-git-send-email-ccross-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org>
2011-02-22  5:32     ` Olof Johansson
2011-02-22  2:39 ` [PATCH 7/7] ARM: tegra: clock: Disable clocks left on by bootloader Colin Cross
     [not found]   ` <1298342392-21236-8-git-send-email-ccross-z5hGa2qSFaRBDgjK7y7TUQ@public.gmane.org>
2011-02-22  5:43     ` Olof Johansson
     [not found]       ` <AANLkTikNSEyjdL0Lchmm-bFxD00omkGLq6Q6Yyjy51Ov-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-02-22  8:05         ` Colin Cross
     [not found]           ` <AANLkTi==wykFCCjamRNh2ngEaubgeLqmZ7Mv9OsH=0cL-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-02-22 15:30             ` Olof Johansson
2011-02-22 19:38 ` [PATCH 0/7] Second batch of Tegra clock updates for 2.6.39 Colin Cross

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=1298342392-21236-3-git-send-email-ccross@android.com \
    --to=ccross@android.com \
    --cc=konkers@android.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=mike@compulab.co.il \
    --cc=olof@lixom.net \
    /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