From patchwork Thu Nov 22 21:22:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 10694865 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DFCB5A4 for ; Thu, 22 Nov 2018 21:22:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1F162CE43 for ; Thu, 22 Nov 2018 21:22:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E671F2CE4E; Thu, 22 Nov 2018 21:22:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A435E2CE43 for ; Thu, 22 Nov 2018 21:22:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sCOu16FdPYOsNOZCCkUlLJgtrqaf1CcN/EHOzV4VAbk=; b=E+IPbE5jpWH/97 7hlYJC4/f1ojm7O6fVrH6O5ssj5bl6KGCu/6VU50WXctlZBVF8dIImjNrcXzv0soRghhFAu8ymj5l nwCG1v6YcFrvqy5wDKANh4Ncqn8L8FkAOehuXa6Kdzakp2hhFl1GL6WV2Qen7AY9axNVvSqTArxnD xUSHMtEpsZMmhP+EZ7DDJ2yf0cyW0+xdJZwjbp/T49RbPOblS1PriayVowZUtx5mGlmq82i1edsaL tu3NwhguCmb8ihJDRui8EId3P1e9QKCji/n4RNCHzSfVrdD3KW1HUuH3/cmGY3n6VwvL10IgskfeY 9gdULzuo2GY/4cE+PHcA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPwQs-0007qW-7Q; Thu, 22 Nov 2018 21:22:42 +0000 Received: from mail.bootlin.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPwQi-0007dM-OM for linux-arm-kernel@lists.infradead.org; Thu, 22 Nov 2018 21:22:34 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 7760120DB0; Thu, 22 Nov 2018 22:22:22 +0100 (CET) Received: from localhost.localdomain (unknown [91.224.148.103]) by mail.bootlin.com (Postfix) with ESMTPSA id C531D207A8; Thu, 22 Nov 2018 22:22:21 +0100 (CET) From: Miquel Raynal To: Michael Turquette , Stephen Boyd , Russell King Subject: [PATCH 1/2] clk: core: clarify the check for runtime PM Date: Thu, 22 Nov 2018 22:22:11 +0100 Message-Id: <20181122212212.16039-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181122212212.16039-1-miquel.raynal@bootlin.com> References: <20181122212212.16039-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181122_132232_930478_59BC72D9 X-CRM114-Status: GOOD ( 17.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Antoine Tenart , Gregory Clement , linux-kernel@vger.kernel.org, Maxime Chevallier , Nadav Haklai , Thomas Petazzoni , Miquel Raynal , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, the core->dev entry is populated only if runtime PM is enabled. Doing so prevents accessing the device structure in any case. Keep the same logic but instead of using the presence of core->dev as the only condition, also check the status of pm_runtime_enabled(). Then, we can set the core->dev pointer at any time as long as a device structure is available. This change will help supporting device links in the clock subsystem. Signed-off-by: Miquel Raynal --- drivers/clk/clk.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index af011974d4ec..b799347c5fd6 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -97,7 +97,7 @@ static int clk_pm_runtime_get(struct clk_core *core) { int ret = 0; - if (!core->dev) + if (!core->dev || !pm_runtime_enabled(core->dev)) return 0; ret = pm_runtime_get_sync(core->dev); @@ -106,7 +106,7 @@ static int clk_pm_runtime_get(struct clk_core *core) static void clk_pm_runtime_put(struct clk_core *core) { - if (!core->dev) + if (!core->dev || !pm_runtime_enabled(core->dev)) return; pm_runtime_put_sync(core->dev); @@ -226,7 +226,7 @@ static bool clk_core_is_enabled(struct clk_core *core) * taking enable spinlock, but the below check is needed if one tries * to call it from other places. */ - if (core->dev) { + if (core->dev && pm_runtime_enabled(core->dev)) { pm_runtime_get_noresume(core->dev); if (!pm_runtime_active(core->dev)) { ret = false; @@ -236,7 +236,7 @@ static bool clk_core_is_enabled(struct clk_core *core) ret = core->ops->is_enabled(core->hw); done: - if (core->dev) + if (core->dev && pm_runtime_enabled(core->dev)) pm_runtime_put(core->dev); return ret; @@ -3272,8 +3272,7 @@ struct clk *clk_register(struct device *dev, struct clk_hw *hw) } core->ops = hw->init->ops; - if (dev && pm_runtime_enabled(dev)) - core->dev = dev; + core->dev = dev; if (dev && dev->driver) core->owner = dev->driver->owner; core->hw = hw; From patchwork Thu Nov 22 21:22:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 10694867 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B692F5A4 for ; Thu, 22 Nov 2018 21:30:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4AB72C770 for ; Thu, 22 Nov 2018 21:30:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 984902CE23; Thu, 22 Nov 2018 21:30:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1B6432C770 for ; Thu, 22 Nov 2018 21:30:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UwHACVLZEXiUhaTNaoMNS6pToO82hES4TEq1hBu3qjc=; b=QG2jL4NosHL2ES hPMAL/O1jsijvSJsgcLFzuji6tXwl0Wp07gMnLRmx/VQJoXzrOeVHu4liRZj1OVn2eIQpJ8/cAJ5C cHzdlZaW1dtmf+WEp8vM1n+tKs5M9c2lfgE0Rl04xNIeDWw28OyyXoA7e6WxZEfkEd7OmTZG9pOfp iBTKn5jTZfvSUL1rgx4pP7zYsIRvi5WFT3GugarLkKwuxY0D7O57+jgZgHfbNx4wWauH4ze57xNyi 226HDtrM4BW+M8VhFTsqwqOAEfRJQ2t1U88nUgDkh/QmWHutwrsXMUYppRWVejGbpatZy0yoUlV7I pmVwh66RxJe9zwJTfwmw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPwYA-0002lD-U9; Thu, 22 Nov 2018 21:30:14 +0000 Received: from mail.bootlin.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gPwQi-0007dN-OK for linux-arm-kernel@lists.infradead.org; Thu, 22 Nov 2018 21:22:35 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 3AD9C20DBE; Thu, 22 Nov 2018 22:22:23 +0100 (CET) Received: from localhost.localdomain (unknown [91.224.148.103]) by mail.bootlin.com (Postfix) with ESMTPSA id 7D87C2072F; Thu, 22 Nov 2018 22:22:22 +0100 (CET) From: Miquel Raynal To: Michael Turquette , Stephen Boyd , Russell King Subject: [PATCH 2/2] clk: core: link consumer with clock driver Date: Thu, 22 Nov 2018 22:22:12 +0100 Message-Id: <20181122212212.16039-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181122212212.16039-1-miquel.raynal@bootlin.com> References: <20181122212212.16039-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181122_132233_109287_ADDF3F69 X-CRM114-Status: GOOD ( 16.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Antoine Tenart , Gregory Clement , linux-kernel@vger.kernel.org, Maxime Chevallier , Nadav Haklai , Thomas Petazzoni , Miquel Raynal , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP One major concern when, for instance, suspending/resuming a platform is to never access registers before the underlying clock has been resumed, otherwise most of the time the kernel will just crash. One solution is to use syscore operations when registering clock drivers suspend/resume callbacks. One problem of using syscore_ops is that the suspend/resume scheduling will depend on the order of the registrations, which brings (unacceptable) randomness in the process. A feature called device links has been introduced to handle such situation. It creates dependencies between consumers and providers, enforcing e.g. the suspend/resume order when needed. Such feature is already in use for regulators. Add device links support in the clock subsystem by creating/deleting the links at get/put time. Example of a boot (ESPRESSObin, A3700 SoC) with devices linked to clocks: ahci-mvebu d00e0000.sata: Linked as a consumer to d0013000.nb-periph-clk mvneta d0030000.ethernet: Linked as a consumer to d0018000.sb-periph-clk xhci-hcd d0058000.usb: Linked as a consumer to d0018000.sb-periph-clk xenon-sdhci d00d0000.sdhci: Linked as a consumer to d0013000.nb-periph-clk xenon-sdhci d00d0000.sdhci: Dropping the link to d0013000.nb-periph-clk advk-pcie d0070000.pcie: Linked as a consumer to d0018000.sb-periph-clk xenon-sdhci d00d0000.sdhci: Linked as a consumer to d0013000.nb-periph-clk xenon-sdhci d00d0000.sdhci: Linked as a consumer to regulator.1 cpu cpu0: Linked as a consumer to d0013000.nb-periph-clk cpu cpu0: Dropping the link to d0013000.nb-periph-clk cpu cpu0: Linked as a consumer to d0013000.nb-periph-clk Signed-off-by: Miquel Raynal --- drivers/clk/clk.c | 20 ++++++++++++++++++++ drivers/clk/clkdev.c | 13 ++++++++++--- include/linux/clk-provider.h | 2 ++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index b799347c5fd6..33a0f2b0533a 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -90,6 +90,7 @@ struct clk { unsigned long max_rate; unsigned int exclusive_count; struct hlist_node clks_node; + struct device_link *link; }; /*** runtime pm ***/ @@ -262,6 +263,25 @@ struct clk_hw *__clk_get_hw(struct clk *clk) } EXPORT_SYMBOL_GPL(__clk_get_hw); +void __clk_device_link(struct device *consumer, struct clk *clk) +{ + if (!consumer || !clk || !clk->core) + return; + + clk->link = device_link_add(consumer, clk->core->dev, + DL_FLAG_STATELESS); +} +EXPORT_SYMBOL_GPL(__clk_device_link); + +void __clk_device_unlink(struct clk *clk) +{ + if (!clk || !clk->link) + return; + + device_link_del(clk->link); +} +EXPORT_SYMBOL_GPL(__clk_device_unlink); + unsigned int clk_hw_get_num_parents(const struct clk_hw *hw) { return hw->core->num_parents; diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c index 9ab3db8b3988..fccfd4c01457 100644 --- a/drivers/clk/clkdev.c +++ b/drivers/clk/clkdev.c @@ -194,20 +194,27 @@ EXPORT_SYMBOL(clk_get_sys); struct clk *clk_get(struct device *dev, const char *con_id) { const char *dev_id = dev ? dev_name(dev) : NULL; - struct clk *clk; + struct clk *clk = NULL; if (dev && dev->of_node) { clk = __of_clk_get_by_name(dev->of_node, dev_id, con_id); - if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER) + if (PTR_ERR(clk) == -EPROBE_DEFER) return clk; } - return clk_get_sys(dev_id, con_id); + if (IS_ERR_OR_NULL(clk)) + clk = clk_get_sys(dev_id, con_id); + + if (!IS_ERR(clk)) + __clk_device_link(dev, clk); + + return clk; } EXPORT_SYMBOL(clk_get); void clk_put(struct clk *clk) { + __clk_device_unlink(clk); __clk_put(clk); } EXPORT_SYMBOL(clk_put); diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 60c51871b04b..c7ba8098f854 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -781,6 +781,8 @@ void devm_clk_hw_unregister(struct device *dev, struct clk_hw *hw); const char *__clk_get_name(const struct clk *clk); const char *clk_hw_get_name(const struct clk_hw *hw); struct clk_hw *__clk_get_hw(struct clk *clk); +void __clk_device_link(struct device *consumer, struct clk *clk); +void __clk_device_unlink(struct clk *clk); unsigned int clk_hw_get_num_parents(const struct clk_hw *hw); struct clk_hw *clk_hw_get_parent(const struct clk_hw *hw); struct clk_hw *clk_hw_get_parent_by_index(const struct clk_hw *hw,