[RFC PATCH 2/5] clk: Introduce 'clk_round_rate_nearest()'
From: Uwe Kleine-König <hidden>
Date: 2014-05-20 07:52:11
Also in:
linux-pm, lkml
From: Uwe Kleine-König <hidden>
Date: 2014-05-20 07:52:11
Also in:
linux-pm, lkml
Hello, On Mon, May 19, 2014 at 10:29:05AM -0700, S?ren Brinkmann wrote:
With the improvements suggested by you I have this now:
long clk_round_rate_nearest(struct clk *clk, unsigned long rate)
{
unsigned long lower, upper;
lower = clk_round_rate(clk, rate);
if (lower >= rate)
return lower;
upper = clk_round_rate(clk, rate + (rate - lower) - 1);
if (upper == lower)
return upper;
lower = rate + 1;
while (lower < upper) {
unsigned long rounded, mid;
mid = lower + ((upper - lower) >> 1);
rounded = clk_round_rate(clk, mid);
if (rounded < lower)
lower = mid + 1;
else
upper = rounded;
}
return upper;
}This is nearly my version now. I just lacks the overflow check when calculating upper and I skipped the early return if (upper == lower). (Instead the while condition evaluates to false on the first hit and returns with the same result.) Other than that I added a few comments. :-) Something we still should resolve is the return type. It should match clk_round_rate, but should both be signed or unsigned? Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |