[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140520075158.GK16662@pengutronix.de>
Date: Tue, 20 May 2014 09:51:58 +0200
From: Uwe Kleine-König
<u.kleine-koenig@...gutronix.de>
To: Sören Brinkmann <soren.brinkmann@...inx.com>
Cc: Mike Turquette <mturquette@...aro.org>,
"Rafael J. Wysocki" <rjw@...ysocki.net>,
Viresh Kumar <viresh.kumar@...aro.org>,
Russell King <linux@....linux.org.uk>,
Michal Simek <michal.simek@...inx.com>,
linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org,
cpufreq@...r.kernel.org, linux-arm-kernel@...ts.infradead.org
Subject: Re: [RFC PATCH 2/5] clk: Introduce 'clk_round_rate_nearest()'
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/ |
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists