From patchwork Fri Jan 17 07:44:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 3502311 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4761AC02DC for ; Fri, 17 Jan 2014 07:45:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7DBE620170 for ; Fri, 17 Jan 2014 07:45:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9738C20165 for ; Fri, 17 Jan 2014 07:45:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752064AbaAQHpi (ORCPT ); Fri, 17 Jan 2014 02:45:38 -0500 Received: from bear.ext.ti.com ([192.94.94.41]:46873 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751993AbaAQHph (ORCPT ); Fri, 17 Jan 2014 02:45:37 -0500 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s0H7jCCK005676; Fri, 17 Jan 2014 01:45:12 -0600 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s0H7jCe6013827; Fri, 17 Jan 2014 01:45:12 -0600 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.2.342.3; Fri, 17 Jan 2014 01:45:11 -0600 Received: from deskari.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s0H7j50n022162; Fri, 17 Jan 2014 01:45:10 -0600 From: Tomi Valkeinen To: Tero Kristo , Tony Lindgren , , , Mike Turquette , Paul Walmsley CC: Tomi Valkeinen Subject: [PATCH 2/2] ARM: OMAP2+: fix dpll round_rate() to actually round Date: Fri, 17 Jan 2014 09:44:59 +0200 Message-ID: <1389944699-27962-3-git-send-email-tomi.valkeinen@ti.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1389944699-27962-1-git-send-email-tomi.valkeinen@ti.com> References: <1389944699-27962-1-git-send-email-tomi.valkeinen@ti.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP omap2_dpll_round_rate() doesn't actually round the given rate, even if the name and the description so hints. Instead it only tries to find an exact rate match, or if that fails, return ~0 as an error. What this basically means is that the user of the clock needs to know what rates the dpll can support, which obviously isn't right. This patch adds a simple method of rounding: during the iteration, the code keeps track of the closest rate match. If no exact match is found, the closest is returned. Signed-off-by: Tomi Valkeinen --- arch/arm/mach-omap2/clkt_dpll.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/arch/arm/mach-omap2/clkt_dpll.c b/arch/arm/mach-omap2/clkt_dpll.c index 1f1708ef77bb..1b4e68dfb713 100644 --- a/arch/arm/mach-omap2/clkt_dpll.c +++ b/arch/arm/mach-omap2/clkt_dpll.c @@ -298,6 +298,7 @@ long omap2_dpll_round_rate(struct clk_hw *hw, unsigned long target_rate, struct dpll_data *dd; unsigned long ref_rate; const char *clk_name; + unsigned long diff, closest_diff = ~0; if (!clk || !clk->dpll_data) return ~0; @@ -345,20 +346,26 @@ long omap2_dpll_round_rate(struct clk_hw *hw, unsigned long target_rate, pr_debug("clock: %s: m = %d: n = %d: new_rate = %lu\n", clk_name, m, n, new_rate); - if (target_rate == new_rate) { + diff = max(target_rate, new_rate) - min(target_rate, new_rate); + + if (diff < closest_diff) { + closest_diff = diff; + dd->last_rounded_m = m; dd->last_rounded_n = n; - dd->last_rounded_rate = target_rate; - break; + dd->last_rounded_rate = new_rate; + + if (diff == 0) + break; } } - if (target_rate != new_rate) { + if (closest_diff == ~0) { pr_debug("clock: %s: cannot round to rate %lu\n", clk_name, target_rate); return ~0; } - return target_rate; + return dd->last_rounded_rate; }