Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751561AbbBUKkp (ORCPT ); Sat, 21 Feb 2015 05:40:45 -0500 Received: from metis.ext.pengutronix.de ([92.198.50.35]:53429 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751172AbbBUKkl (ORCPT ); Sat, 21 Feb 2015 05:40:41 -0500 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Mike Turquette , Stephen Boyd Cc: kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, =?UTF-8?q?S=C3=B6ren=20Brinkmann?= Subject: [PATCH 3/3] clk: divider: fix calculation of initial best divider when rounding to closest Date: Sat, 21 Feb 2015 11:40:25 +0100 Message-Id: <1424515225-6929-4-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1424515225-6929-1-git-send-email-u.kleine-koenig@pengutronix.de> References: <20150221085620.GV19388@pengutronix.de> <1424515225-6929-1-git-send-email-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1988 Lines: 55 Similar to the reasoning for the previous commit DIV_ROUND_CLOSEST(parent_rate, rate) might not be the best integer divisor to get a good approximation for rate from parent_rate (given the metric for CLK_DIVIDER_ROUND_CLOSEST). For example assume a parent rate of 1000 Hz and a target rate of 700. Using DIV_ROUND_CLOSEST the suggested divisor gets calculated to 1 resulting in a target rate of 1000 with a delta of 300 to the desired rate. With choosing 2 as divisor however the resulting rate is 500 which is nearer to 700. Signed-off-by: Uwe Kleine-König --- drivers/clk/clk-divider.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index 66a6211b8834..202a17e9a38b 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -201,17 +201,18 @@ static int _div_round_up(struct clk_divider *divider, static int _div_round_closest(struct clk_divider *divider, unsigned long parent_rate, unsigned long rate) { - int up, down, div; + int up, down; unsigned long up_rate, down_rate; - up = down = div = DIV_ROUND_CLOSEST(parent_rate, rate); + up = DIV_ROUND_UP(parent_rate, rate); + down = parent_rate / rate; if (divider->flags & CLK_DIVIDER_POWER_OF_TWO) { - up = __roundup_pow_of_two(div); - down = __rounddown_pow_of_two(div); + up = __roundup_pow_of_two(up); + down = __rounddown_pow_of_two(down); } else if (divider->table) { - up = _round_up_table(divider->table, div); - down = _round_down_table(divider->table, div); + up = _round_up_table(divider->table, up); + down = _round_down_table(divider->table, down); } up_rate = DIV_ROUND_UP(parent_rate, up); -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/