From patchwork Fri Dec 1 21:51:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 120398 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1679824qgn; Fri, 1 Dec 2017 13:54:19 -0800 (PST) X-Google-Smtp-Source: AGs4zMa2/01BxvqWNTAcr9DvUZlZJe8VJMdRbJ8zCi+f8xWXcGyzRtCM2n1q41NviURl7C8fU7Hi X-Received: by 10.84.129.193 with SMTP id b59mr7426236plb.361.1512165259194; Fri, 01 Dec 2017 13:54:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512165259; cv=none; d=google.com; s=arc-20160816; b=FJ9EZq+15uJa7ImiTyOLylVTcgyvrMkZTkeKPq7v0bQhiNH9QWs0eWMSA+G1hqhDPG Q846Y5vUaN3IvsBabdLD/Vs7CEZHAhb9FGLrGPt3XmW1Y5T+N3DqtaQqdIijhvVfpBdm bDc1wlJ74Qzy9XdTU1PYyRiGOcsbj70PM/eIsqKZ7L2yBDIufjhGFCFSoVvDCzTSDGPr gpVHfi7DXxpkabL7HMtDp8zQu6M4XhqGsoXX52ESIuBOv+GiSA37wvjK0zW0D1RY39uC 64vhjwvSajZ7u/XFSdGbzgumtWPV+Mw+oM3Mfqu/TwM4rjbXvKuA7PJ0qDC9y+NiYUBL uy5w== 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:dkim-signature:arc-authentication-results; bh=PKgH4SvPhRiksHOdphmjG6SkWE4hUDKWP16hEgziMdo=; b=zgrrAwaKtmp7hBsv1P7FCan2F85DORavJbRLoWKCl3M3KaK6XHbbBeMrsfMg2nZeXq 8vA2/5IGB/yvOBhwd2dBOJmH9jBh/VV2LudL/jvES7HulxwMw+xUXQ6uXZb0iiwhd359 Rwa0uJz2d+GeyXdmV5cVKwd9Z0rzJx9Vpu0CgqoVjbZc7hpVQJRroUgQj21+KQ9ERTu7 E/PVMqqWLKUFmaeAKl2fMz6an3iOpprkwstpAPwJfzYDtFKbUpnL+ZTvJcCUIZKeC8ft Y0/b0EUaMAS+lwJnIMIMeib0KY9biym3XU+hVMXY5zS8f4w3sOcRM0o21XrvCMh0ZJnW g25w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=ktr3Kj0P; 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 r1si569301pgp.308.2017.12.01.13.54.18; Fri, 01 Dec 2017 13:54:19 -0800 (PST) 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; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=ktr3Kj0P; 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 S1752119AbdLAVyD (ORCPT + 28 others); Fri, 1 Dec 2017 16:54:03 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:45681 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751560AbdLAVwN (ORCPT ); Fri, 1 Dec 2017 16:52:13 -0500 Received: by mail-wm0-f68.google.com with SMTP id 9so5863922wme.4 for ; Fri, 01 Dec 2017 13:52:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PKgH4SvPhRiksHOdphmjG6SkWE4hUDKWP16hEgziMdo=; b=ktr3Kj0P/1xSxnSPfBJgI73O549P0KvnpbZLoL92yeVltcsk4v1UuwfCwbZm4mefeM nx5a6QakrXNbd0w7klcjX5vd6gkEvuxTO7b53ph4d5mlAo/4i0P7TOYISHSetO3E6JJM HlcfA1Ccg4ktddm1pUSLCHeRZXe9b1ezqbbp8KTAtdSFpRynS+8fzkNnQgPyMnjoq2MZ ewukXESt+PDPmlLKit5JDFIBdt+jqoBBwNu8dLEyAXlwhTrLnWOcSsg4yrvBiB+8t9Yo djQqvny+tHZEZdGB7b0EHbL5mFEk+JJJe3oPZgqxceWMtYuV1q9mB0dP39pYOi07rU5H gVAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PKgH4SvPhRiksHOdphmjG6SkWE4hUDKWP16hEgziMdo=; b=oqT/4UlncDEvUawlf4FtsoBlirp8ap+tAUb8NbeWsTQhsYjrnaal4O8i6HXOyqhr9G ykfBYA/8F5PCOCtf6PVCQJpE00OS6pQ1LPwql5GYE/jHbqqjF1o6c0iTkPDlP5xkXFIg Vo2A84p71MZ+1YiZYEB8cyt4ICVIISON34Ar0McdotxzV4xkwi/i0YchiSvcxJW8jrZ+ ceQWntjyqEDQe0klLEZGHbH3mZx31SJb4ON9RetczIhHg6tgHCTm0b6sCgaGdrWRMQQR fFLSGXgauaF/nR670YIpPNa3e6i4jDEJSmpzfRdp2jeJcfaFbnVlbrRNd2dvSMmDftWa 8S1w== X-Gm-Message-State: AJaThX6CG7sXGH3kZXK1AqHvDfYQyl0ic/ZTPwNrKjCuDMsp4F8pSb/j 2FQNZ5+Bht179oaMRJlyruvEEEO5 X-Received: by 10.28.88.137 with SMTP id m131mr2237624wmb.48.1512165132296; Fri, 01 Dec 2017 13:52:12 -0800 (PST) Received: from localhost.localdomain (cag06-3-82-243-161-21.fbx.proxad.net. [82.243.161.21]) by smtp.googlemail.com with ESMTPSA id m134sm2078804wmg.6.2017.12.01.13.52.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Dec 2017 13:52:11 -0800 (PST) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Russell King , Linus Walleij , Quentin Schulz , Kevin Hilman , Maxime Ripard Subject: [PATCH v5 04/10] clk: rework calls to round and determine rate callbacks Date: Fri, 1 Dec 2017 22:51:54 +0100 Message-Id: <20171201215200.23523-5-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171201215200.23523-1-jbrunet@baylibre.com> References: <20171201215200.23523-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rework the way the callbacks round_rate() and determine_rate() are called. The goal is to do this at a single point and make it easier to add conditions before calling them. Because of this factorization, rate returned by determine_rate() is also checked against the min and max rate values This rework is done to ease the integration of "protected" clock functionality. Acked-by: Linus Walleij Tested-by: Quentin Schulz Tested-by: Maxime Ripard Acked-by: Michael Turquette Signed-off-by: Jerome Brunet --- drivers/clk/clk.c | 82 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 30 deletions(-) -- 2.14.3 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 7946a069ba2e..322d9ba7e5cd 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -905,10 +905,9 @@ static int clk_disable_unused(void) } late_initcall_sync(clk_disable_unused); -static int clk_core_round_rate_nolock(struct clk_core *core, - struct clk_rate_request *req) +static int clk_core_determine_round_nolock(struct clk_core *core, + struct clk_rate_request *req) { - struct clk_core *parent; long rate; lockdep_assert_held(&prepare_lock); @@ -916,15 +915,6 @@ static int clk_core_round_rate_nolock(struct clk_core *core, if (!core) return 0; - parent = core->parent; - if (parent) { - req->best_parent_hw = parent->hw; - req->best_parent_rate = parent->rate; - } else { - req->best_parent_hw = NULL; - req->best_parent_rate = 0; - } - if (core->ops->determine_rate) { return core->ops->determine_rate(core->hw, req); } else if (core->ops->round_rate) { @@ -934,15 +924,58 @@ static int clk_core_round_rate_nolock(struct clk_core *core, return rate; req->rate = rate; - } else if (core->flags & CLK_SET_RATE_PARENT) { - return clk_core_round_rate_nolock(parent, req); } else { - req->rate = core->rate; + return -EINVAL; } return 0; } +static void clk_core_init_rate_req(struct clk_core * const core, + struct clk_rate_request *req) +{ + struct clk_core *parent; + + if (WARN_ON(!core || !req)) + return; + + parent = core->parent; + if (parent) { + req->best_parent_hw = parent->hw; + req->best_parent_rate = parent->rate; + } else { + req->best_parent_hw = NULL; + req->best_parent_rate = 0; + } +} + +static bool clk_core_can_round(struct clk_core * const core) +{ + if (core->ops->determine_rate || core->ops->round_rate) + return true; + + return false; +} + +static int clk_core_round_rate_nolock(struct clk_core *core, + struct clk_rate_request *req) +{ + lockdep_assert_held(&prepare_lock); + + if (!core) + return 0; + + clk_core_init_rate_req(core, req); + + if (clk_core_can_round(core)) + return clk_core_determine_round_nolock(core, req); + else if (core->flags & CLK_SET_RATE_PARENT) + return clk_core_round_rate_nolock(core->parent, req); + + req->rate = core->rate; + return 0; +} + /** * __clk_determine_rate - get the closest rate actually supported by a clock * @hw: determine the rate of this clock @@ -1432,34 +1465,23 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core, clk_core_get_boundaries(core, &min_rate, &max_rate); /* find the closest rate and parent clk/rate */ - if (core->ops->determine_rate) { + if (clk_core_can_round(core)) { struct clk_rate_request req; req.rate = rate; req.min_rate = min_rate; req.max_rate = max_rate; - if (parent) { - req.best_parent_hw = parent->hw; - req.best_parent_rate = parent->rate; - } else { - req.best_parent_hw = NULL; - req.best_parent_rate = 0; - } - ret = core->ops->determine_rate(core->hw, &req); + clk_core_init_rate_req(core, &req); + + ret = clk_core_determine_round_nolock(core, &req); if (ret < 0) return NULL; best_parent_rate = req.best_parent_rate; new_rate = req.rate; parent = req.best_parent_hw ? req.best_parent_hw->core : NULL; - } else if (core->ops->round_rate) { - ret = core->ops->round_rate(core->hw, rate, - &best_parent_rate); - if (ret < 0) - return NULL; - new_rate = ret; if (new_rate < min_rate || new_rate > max_rate) return NULL; } else if (!parent || !(core->flags & CLK_SET_RATE_PARENT)) {