From patchwork Fri Jun 23 09:00:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 106241 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp103818qgd; Fri, 23 Jun 2017 02:01:23 -0700 (PDT) X-Received: by 10.99.122.18 with SMTP id v18mr7029648pgc.142.1498208483744; Fri, 23 Jun 2017 02:01:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498208483; cv=none; d=google.com; s=arc-20160816; b=Xse70SprEes/X8apc/CDYp1MBkVRRaGeTYKDc+Crc8ft6WnJme/eBE4jazmZpG4Ek+ 7AviVJGVmBFl2XEaBV5hDl4Yv2Q/UDpgbhMbFrn99xAGK5VMPU+qjacFVfTinaNAzh3W d2aiTWxnfoyc+9y43g54ENgowteYb54Di5jfZQQUQVHv4hpOwQ5phdQPKug3OBnkeoVX 1BQWm9Jxp4EnE1W7WEFl79n7diQwA6aupco12PW+G4aInKpCeFaCGQrgaeRRbbgPLMEh scsWhqhdfHRIwuyhRNe8E0iOGcq0ZG4Mb6tv1vphpMdyGkDrF/B8KRndBb5cmq0PzYyA lkyw== 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=GA4kxFt2Rggv5f0EPPtaWI6EY/+owSPFgdSQFaCBgyI=; b=DKgvEb4qkKA6tlcswgI+UNskURp4sKJZbwsMau8qvgO98/DaMUCULGBVzXgtNyZaQe Pd9RUMXkCFN9CFyhTAs/JYiaC4jzCNuEExNt1cOp1F20wnrxCfs6bf0pxqEFXqZa5TWQ kKGd1pV3yasEwqZRebJFh/C+oha74b9PPU2MjCQARHbqvipZpgx8hMQQnLHNyrv7Ole0 nvobiK/HHUV3MiKRz0qgA6jswBQ/rLHTkgy9yrXqupkWUTe7fzJyV1yEWJo/TIzR0UxK PlyFPVfjJgjo1lHDR8jXjw64TWCMP+eqtWQKI+Ohijim6Fu3fyXVZI9WCX6AT0dy7JKi xRsw== 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 3si3196379pli.313.2017.06.23.02.01.23; Fri, 23 Jun 2017 02:01:23 -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 S1754112AbdFWJBW (ORCPT + 7 others); Fri, 23 Jun 2017 05:01:22 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:36193 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753847AbdFWJBU (ORCPT ); Fri, 23 Jun 2017 05:01:20 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id ECA9F20923; Fri, 23 Jun 2017 11:01:17 +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 8EDA220922; Fri, 23 Jun 2017 11:01:17 +0200 (CEST) From: Quentin Schulz To: mturquette@baylibre.com, sboyd@codeaurora.org, robh+dt@kernel.org, mark.rutland@arm.com, nicolas.ferre@microchip.com, alexandre.belloni@free-electrons.com, linux@armlinux.org.uk, boris.brezillon@free-electrons.com, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com Cc: Quentin Schulz , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, alsa-devel@alsa-project.org, thomas.petazzoni@free-electrons.com Subject: [PATCH 1/6] clk: at91: clk-generated: remove useless divisor loop Date: Fri, 23 Jun 2017 11:00:54 +0200 Message-Id: <20170623090059.8371-2-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170623090059.8371-1-quentin.schulz@free-electrons.com> References: <20170623090059.8371-1-quentin.schulz@free-electrons.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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 --- drivers/clk/at91/clk-generated.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 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 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) From patchwork Fri Jun 23 09:00:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Schulz X-Patchwork-Id: 106244 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp104395qgd; Fri, 23 Jun 2017 02:02:34 -0700 (PDT) X-Received: by 10.84.218.71 with SMTP id f7mr7615027plm.282.1498208554194; Fri, 23 Jun 2017 02:02:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498208554; cv=none; d=google.com; s=arc-20160816; b=aXjHpFyaEQFmWICCK4dZVs9vHsIVlf9bkyR/kKTqR2XoV3y0ag9o8h3pf9tTnrvHSP +d/bZoAWWCJljzTqQ2TAR6Zyd1JV3wZld/A9goEc1qDKJ+ouV3o78DL9IjB8WAg7UCGh 8FjKq152WOPZLxPrr+mC2KAKMcHY3wF8STsokjoG55UyWGSeublDyPSpIcd5tyw/Iabi S+VGi/fJglik9CCva/UWfvEJfwjvi0twLV4Cq2Wl5hrvWAYZXBwi0WZBA95tVIDYYrLz k+ouiBRIASSwlOOcfPI2LOV20Kt339mBGuZTjgpirzPu9bjTyULf2oHEPy6G0BND9p8w uJkA== 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=uKIE81CLtM5rLY1tB2jDLxOv0tVw65mfSxqO4O+LbNY=; b=sXaWp0C8jQkkBHvFxvkucSU9lsR97tkUx0AnDxaZjibcSIR89LU564b7h6kPribLYl CpKBVK9gW0MX8Mtm25wOmkiJxotq5ynDz3Ts1O1+rBi3/ekWXN3fGuBl562mmw3Og3Mk oIF4jug4cQNAexIi4FfmqqodM6KNR+kuVCb5mQIbkCGmb2S3tF4mzipj5L+6m2c25jLV S44vVmCzd2cZDWkrEd13PmVEFZ2lRf2h5KTucLSvvyJYln6RGxhwnwxj/UZspSvlIvhb Ecs6T9BMdUQtqaqbuXFpMcnSIV1829O/+5SAK7v5OgGzj4I7356fhb9nL21sbNzDpyfR A9ow== 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 p10si3252046pli.267.2017.06.23.02.02.33; Fri, 23 Jun 2017 02:02:34 -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 S1754524AbdFWJCb (ORCPT + 7 others); Fri, 23 Jun 2017 05:02:31 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:36244 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754111AbdFWJBU (ORCPT ); Fri, 23 Jun 2017 05:01:20 -0400 Received: by mail.free-electrons.com (Postfix, from userid 110) id 1FF932095F; Fri, 23 Jun 2017 11:01:19 +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 BD27720904; Fri, 23 Jun 2017 11:01:18 +0200 (CEST) From: Quentin Schulz To: mturquette@baylibre.com, sboyd@codeaurora.org, robh+dt@kernel.org, mark.rutland@arm.com, nicolas.ferre@microchip.com, alexandre.belloni@free-electrons.com, linux@armlinux.org.uk, boris.brezillon@free-electrons.com, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com Cc: Quentin Schulz , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, alsa-devel@alsa-project.org, thomas.petazzoni@free-electrons.com Subject: [PATCH 4/6] clk: at91: clk-generated: create function to find best_diff Date: Fri, 23 Jun 2017 11:00:57 +0200 Message-Id: <20170623090059.8371-5-quentin.schulz@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170623090059.8371-1-quentin.schulz@free-electrons.com> References: <20170623090059.8371-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 --- 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;