From patchwork Thu Aug 10 06:34:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 109785 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp1919188qge; Wed, 9 Aug 2017 23:37:07 -0700 (PDT) X-Received: by 10.223.181.10 with SMTP id a10mr8542327wrd.239.1502347027054; Wed, 09 Aug 2017 23:37:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502347027; cv=none; d=google.com; s=arc-20160816; b=L6PQpTn1Vq3OPfwAfhjAaeIuFcLOXVC10lRpcx1rnTx7B9SuS56JCvviLXv/Xrmofo F46i3Co6Fbdmbyw3uI4cqOZndqRz8wpnXEx5AeN7fZsb6zWJ4msMT3YMi6OMwwaLNNp0 p3td2M2t5mdzXssTieW4jx2JYZSPeusmAkHdKcoywbEnasD65D/xL6uSKGwh6c/QJqUv w7+PzU2+juelXUf1gs84D1ivi39rlEsp9nmb4CkF4GpEd7Ve1N3yjNv0eXFgCrgu9V8p oprWwCARkL7StJObK7D9QWYLxexzAXIDNHAKuRaIbFc6Fl/po6X0wOAuz3IudQAvwXVE aRrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:references :in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=1wJWa9pLly9/cNYGm+cmcVespqlyPv2miT/lEycwstE=; b=kjXWcLQc2DaSuSK1BbMbC4NOXxl3bstt5YuXn0+CuIOuiscKvpbkT9vwGkfEGzj/eO 0GlMk7J4cX96/d2dP4XESDZegM+PlEprxLiBEva6WqMArV94z1t2xhhOyvUGu4u8wV8L Uo2vFZaOMNRVCMhccInW4H81odGziVvwiYhXNfTCyk1NzsLbcekRxQRdQ1Hq3xx5jDgI e9605zqD/AIoxxZLFpmrZh93L5Yd3VVxPHw4eF/zmFtT3Hw3XtGX5xNI0z7I2JxZEbnY gK5DUbmrtaigD+NOUIygPTO8xmION4D1o4qKuQPqs9tllPLRehuckZQB29bTg5rBMm4n 0Lqg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Return-Path: Received: from alsa0.perex.cz (alsa0.perex.cz. [77.48.224.243]) by mx.google.com with ESMTP id 130si4216222wmf.220.2017.08.09.23.37.06; Wed, 09 Aug 2017 23:37:07 -0700 (PDT) Received-SPF: pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) client-ip=77.48.224.243; Authentication-Results: mx.google.com; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 2B2132674D1; Thu, 10 Aug 2017 08:35:17 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 152C22674D1; Thu, 10 Aug 2017 08:35:16 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail1.perex.cz X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RP_MATCHES_RCVD,SPF_PASS autolearn=disabled version=3.4.0 Received: from mail.free-electrons.com (mail.free-electrons.com [62.4.15.54]) by alsa0.perex.cz (Postfix) with ESMTP id F2F0B26748F for ; Thu, 10 Aug 2017 08:35:00 +0200 (CEST) Received: by mail.free-electrons.com (Postfix, from userid 110) id 8E77020967; Thu, 10 Aug 2017 08:34:59 +0200 (CEST) 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 303B520967; Thu, 10 Aug 2017 08:34:59 +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 Date: Thu, 10 Aug 2017 08:34:04 +0200 Message-Id: <4dde07bb3345d569778e7b1b5a8679bded095041.1502346448.git-series.quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Cc: thomas.petazzoni@free-electrons.com, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Quentin Schulz , cyrille.pitchen@wedev4u.fr, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [alsa-devel] [PATCH v5 4/7] clk: at91: clk-generated: create function to find best_diff X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.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 Acked-by: Nicolas Ferre --- drivers/clk/at91/clk-generated.c | 41 +++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-) -- git-series 0.9.1 _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel 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;