From patchwork Tue Jul 4 11:59:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 106954 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp911069qge; Tue, 4 Jul 2017 04:59:56 -0700 (PDT) X-Received: by 10.99.97.78 with SMTP id v75mr15607628pgb.158.1499169596846; Tue, 04 Jul 2017 04:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499169596; cv=none; d=google.com; s=arc-20160816; b=DlI6NEmMy4vjCw3wur8c/eQanvPDvIJ1gShPv0MjbATlX/F4WBzbMz3BEPrEOIY2rQ 9xWVxZpvfkbkeRbHvS0lOfeN/08Nz69h+LBdsnPnAZ4+zPV/k70NJ9FCe5SWSWigSw6L 70EhtCr6pppZJPmEwN87XL3jQeaBn/SeG5uRHKb+VvE/RBqXYya5mZzWTmfCbtX+AX7X 3Hlg0X/gQrnJ4ZfbwuC+yZksTnV+JdKsZnFXGdhFn6rwkDcIRLpX/JDNq34uuuSTSnfQ mNLENk9t5kkDJJg1hT/w3XlNu3fkRjNkIBVGaqlE5KwvrzLZ5Em9W6CzJmz6G5nILLzY Ipmw== 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:message-id:date :subject:cc:to:from:arc-authentication-results; bh=w4Vktw9XHhsiqNvoGgwO93TLKVRQHN+LAvnjUx4ICWM=; b=qhEMb5Rf55u0hvPKEgGjmRE+PA7Lt75MLo3iuNDVE/nbLsQNcTqDvQvZT/0e+5hDA+ yI6OzyxJbezK1Cz9wLt65ISPNWvw99cVfFqxPuSzM1zdzAUDHhONclln6fpmYnZjLEI4 zLenkLLkdRlizx3jnaqp+GnWda+rnhrX0iVsZyFYCQzuIxn/DMZVy6/d4D8moVxTekzC bmxxfPTMcIiwfXL69yI75jONfB7G3c5mTqAub/QREjF236R43NHH08/rs5y2R9+o5uCk VIhCsRbEfAXze/Ztj5w9Qx9KEyA2dR2hk8ryGYVw/LxfaWOMha0eN3QMbG8uT4tRL+Z0 n86w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 13si10159654pfm.355.2017.07.04.04.59.56; Tue, 04 Jul 2017 04:59:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752180AbdGDL7w (ORCPT + 25 others); Tue, 4 Jul 2017 07:59:52 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:43560 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752143AbdGDL7q (ORCPT ); Tue, 4 Jul 2017 07:59:46 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 7CE0721E0D; Tue, 4 Jul 2017 13:59:43 +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 1ADC321D3F; Tue, 4 Jul 2017 13:59:43 +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: Quentin Schulz , cyrille.pitchen@wedev4u.fr, thomas.petazzoni@free-electrons.com, 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 Subject: [PATCH v2 1/9] clk: at91: clk-generated: remove useless divisor loop Date: Tue, 4 Jul 2017 13:59:19 +0200 Message-Id: <20170704115927.32662-2-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170704115927.32662-1-quentin.schulz@free-electrons.com> References: <20170704115927.32662-1-quentin.schulz@free-electrons.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- drivers/clk/at91/clk-generated.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) -- 2.11.0 diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c index 07c8f701e51c..dab7002937e6 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)