From patchwork Tue Jul 25 07:37:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 108620 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp260316qge; Tue, 25 Jul 2017 00:41:23 -0700 (PDT) X-Received: by 10.99.43.8 with SMTP id r8mr18362751pgr.313.1500968482922; Tue, 25 Jul 2017 00:41:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500968482; cv=none; d=google.com; s=arc-20160816; b=GTZ3voAjeg3Y+9YxPE+WC6h8xgHRm+f7iWQt50JBRyqmRuj8dhP6KGhiiLvJI7Sx2v ve3Resp1fA8SBBIpusxrblaspZcIR1UgHgHuawdkSLHOMUGApZK351a08JOEAMU0rmZu XhNYhP0NPTF+6aURXgj75WwegOC6NF+oTUmHG6HRNp9ayVZKxDIDyoBRuwRn9caMyrPD sToRjb+zSQZIaKz8geasCdBQsgCK6gAoju8tv7r42GBcNELszPJy/6iCJUPAxv4pMD0i G9I1SD79gjexMIH5nEIRF8D+XAytIfPwNTowTd8drx/EKgCpIeSlNj/TvFeXTMa4xE2l h/kg== 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=CSG9yLNnWfSKUnkymM7P9bSH92tx8EmWIMrNzG8vinc=; b=jTmgSWzMydKj6J1GBSC9bofLrQ0zs43GGbEG5DmC1Y9vYCe4xzZeDpaGdF0q6moBLe hEelqR8A3PwhixokeFXN0vYYWYP/jnEvJaSd39Hi9feZktLI1sU01lsko14QCfyPC2nx ui6frjzlDdokJM573V8yLVow5CSRSOEyzNQUpAV07lmf8VdEWzAjE/p1+ChWmvtEOs8Y AQElXIRkKbiRdcuS40Bx5ell57YVaFgHsEdswseocikp5N4Qc+ngNM3vu/Kw35dYxHl3 KH8YhA+Vygie3kDgaHPs5toJX7F1qS4azBk/K18Lo4VngcsDr15He27ka1TVC8oAAp2o 2RPA== 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 1si7703876pfd.140.2017.07.25.00.41.22; Tue, 25 Jul 2017 00:41:22 -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 S1751590AbdGYHlT (ORCPT + 26 others); Tue, 25 Jul 2017 03:41:19 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:42325 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751517AbdGYHlP (ORCPT ); Tue, 25 Jul 2017 03:41:15 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 5D95B20919; Tue, 25 Jul 2017 09:41:12 +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, URIBL_BLOCKED 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 C5A7320F56; Tue, 25 Jul 2017 09:40:53 +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: 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, Quentin Schulz Subject: [PATCH v4 5/9] clk: at91: clk-generated: create function to find best_diff Date: Tue, 25 Jul 2017 09:37:06 +0200 Message-Id: <8fe980cd3343111a57bd1b099beaaf51b95396d4.1500968090.git-series.quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) -- git-series 0.9.1 diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c index ef4b4e0..7260e49 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;