From patchwork Mon May 2 16:36:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Heiko_St=C3=BCbner?= X-Patchwork-Id: 8993751 X-Patchwork-Delegate: sboyd@codeaurora.org Return-Path: X-Original-To: patchwork-linux-clk@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B420CBF29F for ; Mon, 2 May 2016 16:36:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 67C4120225 for ; Mon, 2 May 2016 16:36:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED5C020259 for ; Mon, 2 May 2016 16:36:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754505AbcEBQgj (ORCPT ); Mon, 2 May 2016 12:36:39 -0400 Received: from gloria.sntech.de ([95.129.55.99]:58549 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754445AbcEBQgf (ORCPT ); Mon, 2 May 2016 12:36:35 -0400 Received: from ip9234b8f8.dynamic.kabel-deutschland.de ([146.52.184.248] helo=diego.sntech) by gloria.sntech.de with esmtpsa (TLS1.1:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1axGpf-0000Hp-8w; Mon, 02 May 2016 18:36:27 +0200 From: Heiko Stuebner To: mturquette@baylibre.com, sboyd@codeaurora.org Cc: linux-clk@vger.kernel.org, linux-rockchip@lists.infradead.org, zhengxing@rock-chips.com, zhangqing@rock-chips.com, tomeu.vizoso@collabora.com, Heiko Stuebner Subject: [RFC PATCH 1/3] clk: fix inconsistent use of req_rate Date: Mon, 2 May 2016 18:36:20 +0200 Message-Id: <1462206982-10444-2-git-send-email-heiko@sntech.de> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1462206982-10444-1-git-send-email-heiko@sntech.de> References: <1462206982-10444-1-git-send-email-heiko@sntech.de> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The req_rate property seems to be made to hold the rate requested through clk_set_rate. Currently it gets initialized in clk_init to the clocks current rate and then adapted in clk_set_rate calls. Orphan clocks and their children get initialized to a rate of 0 and req_rate never gets re-set when these lose their orphan-status. Initializing req_rate to the clocks rate also is unintuitive as it just copies the value that is already in the rate property and also looses the information if a component actually requested a specific rate. So separate the requested rate and only set it in clk_core_set_rate_nolock when a real rate gets requested. The users of the req_rate __clk_put and clk_set_rate_range that adjust a clock based on that value use req_rate at first and fall back to rate if no rate had been requested now. Signed-off-by: Heiko Stuebner --- drivers/clk/clk.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index f079ea4..65e0aad 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1507,8 +1507,10 @@ static int clk_core_set_rate_nolock(struct clk_core *core, return 0; /* bail early if nothing to do */ - if (rate == clk_core_get_rate_nolock(core)) + if (rate == clk_core_get_rate_nolock(core)) { + core->req_rate = req_rate; return 0; + } if ((core->flags & CLK_SET_RATE_GATE) && core->prepare_count) return -EBUSY; @@ -1599,9 +1601,14 @@ int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max) clk_prepare_lock(); if (min != clk->min_rate || max != clk->max_rate) { + unsigned long rate = clk->core->req_rate; + + if (!rate) + rate = clk->core->rate; + clk->min_rate = min; clk->max_rate = max; - ret = clk_core_set_rate_nolock(clk->core, clk->core->req_rate); + ret = clk_core_set_rate_nolock(clk->core, rate); } clk_prepare_unlock(); @@ -2379,7 +2386,7 @@ static int __clk_core_init(struct clk_core *core) rate = core->parent->rate; else rate = 0; - core->rate = core->req_rate = rate; + core->rate = rate; /* * walk the list of orphan clocks and reparent any that newly finds a @@ -2809,6 +2816,7 @@ int __clk_get(struct clk *clk) void __clk_put(struct clk *clk) { + unsigned long rate; struct module *owner; if (!clk || WARN_ON_ONCE(IS_ERR(clk))) @@ -2817,9 +2825,13 @@ void __clk_put(struct clk *clk) clk_prepare_lock(); hlist_del(&clk->clks_node); - if (clk->min_rate > clk->core->req_rate || - clk->max_rate < clk->core->req_rate) - clk_core_set_rate_nolock(clk->core, clk->core->req_rate); + + rate = clk->core->req_rate; + if (!rate) + rate = clk->core->rate; + + if (clk->min_rate > rate || clk->max_rate < rate) + clk_core_set_rate_nolock(clk->core, rate); owner = clk->core->owner; kref_put(&clk->core->ref, __clk_release);