From patchwork Thu Jul 13 07:49: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: 107567 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1884361qge; Thu, 13 Jul 2017 00:51:42 -0700 (PDT) X-Received: by 10.98.193.197 with SMTP id i188mr59336208pfg.215.1499932302728; Thu, 13 Jul 2017 00:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499932302; cv=none; d=google.com; s=arc-20160816; b=YhYBciUtpfiDFFdu14qheheK5LK4Lycg8ZTaaTL4EXYK2VKRGKyoNusm82TNxURfRA 8/Mqv2txHL7+yL3o077245/I2zz5T8TtLnOyQWkm7zLbI9UaQ0jlBEyCCQvq8hOVssBp B6LyWDqPFjBEbXfvq0SmRmjZVyAd3RL+fnwuWtSpS7hAiVdipxBocrBzVR6Wi5tE4U3P BbgxOhBwG5NLrds94G2Tdee0ijawzlQ2wb/DE1ZId8rJnxz7jsMaM4iIsw/LqZR/Pp2L 6oUuxL1ca+81mgGuVS02CbuxMd/nGuIBaCL+NXFgGndDJx97raok1LNaxSnF9uJcBhLU swnw== 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=QWlocnlB4hUKXEIz1S2f8aJ9BDe9Ytif4MgMUIO3pUk=; b=Ets3TM5/yN6q6I222/WGZZsCz6ZTtsDNZ6KpLU80r8P4P//x4b2a9FD/z6dO6IGyib p6jdXbGN96EvAv4QEjXG3OAUvkkleSj0XpMyPkc/1TIoUIchns5/iVhjHnrouBhzV5W3 n54hZbXMqLnLyzXOgl8BMF6wSfzYy45V25WyYSh/BNmWeHK+JtOgchQXi/crBVNITRI7 xMKTtZaDSQFBGdBF+PgBpnCi5ZF03EUr1qK62LeDoYh/AmxpMOcw2OHu8En+B981O982 jURM0u3HNWc4Rf+L0k74FhrzuAy5Q+XA/yi/xhti2GsIvmYrNYGfl8K2ochiOdmz0byL tjvA== 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 92si3898192plw.105.2017.07.13.00.51.42; Thu, 13 Jul 2017 00:51:42 -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 S1751915AbdGMHvj (ORCPT + 25 others); Thu, 13 Jul 2017 03:51:39 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:48056 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751237AbdGMHto (ORCPT ); Thu, 13 Jul 2017 03:49:44 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 830F521FE1; Thu, 13 Jul 2017 09:49:40 +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 2009821FBC; Thu, 13 Jul 2017 09:49:40 +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 v3 5/9] clk: at91: clk-generated: create function to find best_diff Date: Thu, 13 Jul 2017 09:49:23 +0200 Message-Id: <20170713074927.10882-6-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170713074927.10882-1-quentin.schulz@free-electrons.com> References: <20170713074927.10882-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 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 diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c index ef4b4e03de04..7260e498e059 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;