From patchwork Tue Jul 4 11:59:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 106953 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp911008qge; Tue, 4 Jul 2017 04:59:53 -0700 (PDT) X-Received: by 10.84.141.164 with SMTP id 33mr16067556plv.75.1499169593495; Tue, 04 Jul 2017 04:59:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499169593; cv=none; d=google.com; s=arc-20160816; b=R/jitpYi5FDrPNl0Ubi0cu/nSyU4sV2pRho2Q/Fk9wGTbOgpUwOQJqY1ZHPmN01/23 p39qHhvglAM4lfeyrfR4yAClhloSTms/+IgJnSwcv81tbjtLPmmxTR3lqZooTcrF+WKj QI5dxpfdYQz8AFnNEv4l14OtWreSNcusI/R5AIHUMujzW1duwDU1qbC5E+Clk/V0bH2t O5177i1+/6+/uiN8WD1DwM21ybK3+buoo86gIOYhHoYf5UGyY7aCFzf2JpT7MFCKkguG T9m381kD7T3vt2dDWuzOhngDUzlC2ScTkK5OogNMHxzr6/NpxU+GjA2GB6Wdd6PNqFdM bWYQ== 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=bGNSCpQ2Y2NFBFQK1UU9RdaJMlSLPYXUdjsv1yV4MNg=; b=df8j09cDYntMNmk4k1VspUub3DRryFMbVeAH7JkSlYtgTOSDH/zbJ5m1MLCKDmGe3i oL17Q3ioxZA/66lJ4ob+XlAwueRFmfAwQ0abBsSV2rIKFXeXICqIJf/SwT1bp2JZ6wjm +nm0T/a6Ne16LE08fStszuzGQOqINAUJitJfrB0bW/Jv5IUlMticcNYK/g/1eICR1MKT AKnt6AQXhapUfirc0ppvQ1ESK3nbJp1HyTvq3rqCpeB9Bn8cIZw5vD6S0JSTLs+ign0C fJaOJoqBDPI/1yM5ntXSraKiixqA6Sp0lPiini0Cy3mnZuVo+JmBnAOXF9L13XaGBCq8 Dj5A== 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 z11si14273070pgo.248.2017.07.04.04.59.53; Tue, 04 Jul 2017 04:59:53 -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 S1752262AbdGDL7v (ORCPT + 7 others); Tue, 4 Jul 2017 07:59:51 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:43622 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752192AbdGDL7s (ORCPT ); Tue, 4 Jul 2017 07:59:48 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 03FF821FC0; Tue, 4 Jul 2017 13:59:45 +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 98DE721D3F; Tue, 4 Jul 2017 13:59:44 +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 5/9] clk: at91: clk-generated: create function to find best_diff Date: Tue, 4 Jul 2017 13:59:23 +0200 Message-Id: <20170704115927.32662-6-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: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The way to find the best_diff and do the appropriate process afterwards can be re-used. This patch prepares the driver for an upcoming patch that will allow clk_generated to determine the rate of the audio_pll. Signed-off-by: Quentin Schulz Acked-by: Boris Brezillon --- drivers/clk/at91/clk-generated.c | 41 ++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) -- 2.11.0 -- 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 dab7002937e6..6530a2e7e84d 100644 --- a/drivers/clk/at91/clk-generated.c +++ b/drivers/clk/at91/clk-generated.c @@ -99,15 +99,36 @@ clk_generated_recalc_rate(struct clk_hw *hw, return DIV_ROUND_CLOSEST(parent_rate, gck->gckdiv + 1); } +static void clk_generated_best_diff(struct clk_rate_request *req, + struct clk_hw *parent, + unsigned long parent_rate, u32 div, + int *best_diff, long *best_rate) +{ + unsigned long tmp_rate; + int tmp_diff; + + 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; + } +} + static int clk_generated_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { struct clk_generated *gck = to_clk_generated(hw); struct clk_hw *parent = NULL; long best_rate = -EINVAL; - unsigned long tmp_rate, min_rate; + unsigned long min_rate; int best_diff = -1; - int tmp_diff; int i; for (i = 0; i < clk_hw_get_num_parents(hw); i++) { @@ -125,18 +146,10 @@ static int clk_generated_determine_rate(struct clk_hw *hw, continue; 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; - } + + clk_generated_best_diff(req, parent, parent_rate, div, + &best_diff, &best_rate); + if (!best_diff) break;