From patchwork Thu Apr 2 15:34:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Stuebner X-Patchwork-Id: 6150351 Return-Path: X-Original-To: patchwork-linux-rockchip@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 CFBEFBFFA8 for ; Thu, 2 Apr 2015 15:36:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EF5BC20306 for ; Thu, 2 Apr 2015 15:36:58 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AE6B0203AD for ; Thu, 2 Apr 2015 15:36:57 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YdhAu-0000IR-VL; Thu, 02 Apr 2015 15:36:56 +0000 Received: from gloria.sntech.de ([95.129.55.99]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ydh8l-0006Te-Um; Thu, 02 Apr 2015 15:34:46 +0000 Received: from ip92344031.dynamic.kabel-deutschland.de ([146.52.64.49] helo=diego.lan) by gloria.sntech.de with esmtpsa (TLS1.1:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1Ydh8M-0000Sn-MD; Thu, 02 Apr 2015 17:34:18 +0200 From: Heiko Stuebner To: mturquette@linaro.org Subject: [PATCH 1/4] clk: Propagate prepare and enable when reparenting orphans Date: Thu, 2 Apr 2015 17:34:10 +0200 Message-Id: <1427988853-9549-2-git-send-email-heiko@sntech.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1427988853-9549-1-git-send-email-heiko@sntech.de> References: <1427988853-9549-1-git-send-email-heiko@sntech.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150402_083444_224392_32D10FA8 X-CRM114-Status: GOOD ( 14.94 ) X-Spam-Score: -0.0 (/) Cc: linux@arm.linux.org.uk, Heiko Stuebner , linux-kernel@vger.kernel.org, dianders@chromium.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 From: Doug Anderson With the existing code, if you find a parent for an orhpan that has already been prepared / enabled, you won't enable the parent. That can cause later problems since the clock tree isn't in a consistent state. Fix by propagating the prepare and enable. NOTE: this does bring up the question about whether the enable of the orphan actually made sense. If the orphan's parent wasn't enabled by default (by the bootloader or the default state of the hardware) then the original enable of the orphan probably didn't do what the caller though it would. Some users of the orphan might have preferred an EPROBE_DEFER be returned until we had a full path to a root clock. This patch doesn't address those concerns and really just syncs up the state. Tested on rk3288-evb-rk808 by temporarily considering "sclk_tsadc" as a critical clock (to simulate a driver enabling it at bootup). Before: clock enable_cnt prepare_cnt rate accuracy phase ---------------------------------------------------------------------------------------- xin32k 0 0 32768 0 0 sclk_hdmi_cec 0 0 32768 0 0 sclk_otg_adp 0 0 32768 0 0 sclk_tsadc 1 1 993 0 0 After: clock enable_cnt prepare_cnt rate accuracy phase ---------------------------------------------------------------------------------------- xin32k 1 1 32768 0 0 sclk_hdmi_cec 0 0 32768 0 0 sclk_otg_adp 0 0 32768 0 0 sclk_tsadc 1 1 993 0 0 Note that xin32k on rk808 is a clock that cannot be disabled in hardware (it's an always on clock), so really all we needed to do was to sync up the state. Signed-off-by: Doug Anderson Adapted to recent clk->clk_core changes and move orphan handling to a separate function as the main clk_core_reparent function is already also used in other contexts. Signed-off-by: Heiko Stuebner --- drivers/clk/clk.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index f85c8e2..512323f 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2011,6 +2011,27 @@ static void clk_core_reparent(struct clk_core *clk, __clk_recalc_rates(clk, POST_RATE_CHANGE); } +static void clk_core_reparent_orphan(struct clk_core *clk, + struct clk_core *new_parent) +{ + clk_core_reparent(clk, new_parent); + + if (clk->prepare_count) { + unsigned long flags; + + if (clk_core_prepare(new_parent)) { + pr_err("%s: could not prepare new parent %s\n", + __func__, clk->name); + return; + } + + flags = clk_enable_lock(); + if (clk->enable_count) + clk_core_enable(new_parent); + clk_enable_unlock(flags); + } +} + void clk_hw_reparent(struct clk_hw *hw, struct clk_hw *new_parent) { if (!hw) @@ -2404,13 +2425,13 @@ static int __clk_init(struct device *dev, struct clk *clk_user) if (orphan->num_parents && orphan->ops->get_parent) { i = orphan->ops->get_parent(orphan->hw); if (!strcmp(clk->name, orphan->parent_names[i])) - clk_core_reparent(orphan, clk); + clk_core_reparent_orphan(orphan, clk); continue; } for (i = 0; i < orphan->num_parents; i++) if (!strcmp(clk->name, orphan->parent_names[i])) { - clk_core_reparent(orphan, clk); + clk_core_reparent_orphan(orphan, clk); break; } }