From mboxrd@z Thu Jan 1 00:00:00 1970 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= Subject: Re: [RFC PATCH 2/5] clk: Introduce 'clk_round_rate_nearest()' Date: Tue, 20 May 2014 09:51:58 +0200 Message-ID: <20140520075158.GK16662@pengutronix.de> References: <1400106655-22465-1-git-send-email-soren.brinkmann@xilinx.com> <1400106655-22465-3-git-send-email-soren.brinkmann@xilinx.com> <20140515073816.GI16662@pengutronix.de> <91822600-39d0-4e71-b0f5-9eda35b76ec0@BN1AFFO11FD016.protection.gbl> <20140519161949.GG16662@pengutronix.de> Mime-Version: 1.0 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="iso-8859-1" To: =?iso-8859-1?Q?S=F6ren?= Brinkmann Cc: Mike Turquette , "Rafael J. Wysocki" , Viresh Kumar , Russell King , Michal Simek , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, cpufreq@vger.kernel.org, linux-arm-kernel@lists.infradead.org Hello, On Mon, May 19, 2014 at 10:29:05AM -0700, S=F6ren Brinkmann wrote: > With the improvements suggested by you I have this now: >=20 > long clk_round_rate_nearest(struct clk *clk, unsigned long rate) > { > unsigned long lower, upper; >=20 > lower =3D clk_round_rate(clk, rate); > if (lower >=3D rate) > return lower; >=20 > upper =3D clk_round_rate(clk, rate + (rate - lower) - 1); > if (upper =3D=3D lower) > return upper; >=20 > lower =3D rate + 1; > while (lower < upper) { > unsigned long rounded, mid; >=20 > mid =3D lower + ((upper - lower) >> 1); > rounded =3D clk_round_rate(clk, mid); > if (rounded < lower) > lower =3D mid + 1; > else > upper =3D rounded; > } >=20 > 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 =3D=3D 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?=20 Uwe --=20 Pengutronix e.K. | Uwe Kleine-K=F6nig = | Industrial Linux Solutions | http://www.pengutronix.de/= |