From patchwork Thu Aug 10 06:34:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 109780 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp1917536qge; Wed, 9 Aug 2017 23:35:06 -0700 (PDT) X-Received: by 10.98.75.218 with SMTP id d87mr10664612pfj.135.1502346906728; Wed, 09 Aug 2017 23:35:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502346906; cv=none; d=google.com; s=arc-20160816; b=JgCyutX58EdcLptW8S7gUTj+8lBev0dWYbcUq/FWVwbw4vzHuw7kz28s2JcUU8XR0A f/A2ZQgQHxHLNf+M9AmxWv7aDnHNy7d/TKGqMQF/Q+PHND4k4OM72lHyRrTPQh+rVrkB CcclWEvvIDGlOV/e7L6pJPaDzbN+bYfED9zHE9Joot7S/Bdhtf7ben7SfTbMaxHHzSxp WePOGmedEyFqSBh6H4yoF7BGvkQnEfQ098oIQe5jpvSYBpg3N9RdgYitbHNML1obFREY GGBf5oWpAnJ0IVYBXvraKCfB6iS3kUw7eATGLuXouQ/lXnBoW/c0MB0HuA0MsC2vjv7n LEFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=TjWrxjG0ruLb55g9ZznPVGKjy7sOIhqqD3Sm8HncPMM=; b=1GB0b2gPSeXMDa1b/1ejGO84UJOj/uQC6hI7s8SgNGKTPZwHjtSd0UoYISD0sdt9xh 649A+t8o+6WEFZuQqunlWHXALB9FA0AGPaZTuGuKRzAHBJ4W1VCAVndLuQGKKAAPEXoI ttlQdgQX4wmCEj4EflSXfIge643vfVmVvs2H121Hp6Vq3RoJyKnMm2iQVxUK5HJ7C06f WaBKENk/edZ+4mii1wH+2K5K3QdGCJAR/DqRj7boPGd3uJg9e4d1sL/gwOABKS9zHPdX X/5d9EnqZmCXv+JGfz8k1WFxK+dw+aC493XT/CDc9Hblvg1KAyMSnhsZl0Vj3rdhEGwH AuvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m12si3571670pga.895.2017.08.09.23.35.06; Wed, 09 Aug 2017 23:35:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751418AbdHJGfD (ORCPT + 6 others); Thu, 10 Aug 2017 02:35:03 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:42391 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751440AbdHJGfA (ORCPT ); Thu, 10 Aug 2017 02:35:00 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 6FBDA2096A; Thu, 10 Aug 2017 08:34:58 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 0CDCA20936; Thu, 10 Aug 2017 08:34:58 +0200 (CEST) From: Quentin Schulz To: mturquette@baylibre.com, sboyd@codeaurora.org, robh+dt@kernel.org, mark.rutland@arm.com, lgirdwood@gmail.com, broonie@kernel.org, nicolas.ferre@microchip.com, alexandre.belloni@free-electrons.com, linux@armlinux.org.uk, boris.brezillon@free-electrons.com, perex@perex.cz, tiwai@suse.com Cc: linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, cyrille.pitchen@wedev4u.fr, thomas.petazzoni@free-electrons.com, Quentin Schulz Subject: [PATCH v5 1/7] clk: at91: clk-generated: remove useless divisor loop Date: Thu, 10 Aug 2017 08:34:01 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The driver requests the current clk rate of each of its parent clocks to decide whether a clock rate is suitable or not. It does not request determine_rate from a parent clock which could request a rate change in parent clock (i.e. there is no parent rate propagation). We know the rate we want (passed along req argument of the function) and the parent clock rate, thus we know the closest rounded divisor, we don't need to iterate over the available divisors to find the best one for a given clock. Signed-off-by: Quentin Schulz Acked-by: Boris Brezillon Acked-by: Nicolas Ferre --- drivers/clk/at91/clk-generated.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) -- git-series 0.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c index f0b7ae9..ef4b4e0 100644 --- a/drivers/clk/at91/clk-generated.c +++ b/drivers/clk/at91/clk-generated.c @@ -124,19 +124,18 @@ static int clk_generated_determine_rate(struct clk_hw *hw, (gck->range.max && min_rate > gck->range.max)) continue; - for (div = 1; div < GENERATED_MAX_DIV + 2; div++) { - tmp_rate = DIV_ROUND_CLOSEST(parent_rate, div); - tmp_diff = abs(req->rate - tmp_rate); - - if (best_diff < 0 || best_diff > tmp_diff) { - best_rate = tmp_rate; - best_diff = tmp_diff; - req->best_parent_rate = parent_rate; - req->best_parent_hw = parent; - } - - if (!best_diff || tmp_rate < req->rate) - break; + div = DIV_ROUND_CLOSEST(parent_rate, req->rate); + if (!div) + tmp_rate = parent_rate; + else + tmp_rate = parent_rate / div; + tmp_diff = abs(req->rate - tmp_rate); + + if (best_diff < 0 || best_diff > tmp_diff) { + best_rate = tmp_rate; + best_diff = tmp_diff; + req->best_parent_rate = parent_rate; + req->best_parent_hw = parent; } if (!best_diff)