From patchwork Mon Oct 20 09:04:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 5103411 Return-Path: X-Original-To: patchwork-dmaengine@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 024739F374 for ; Mon, 20 Oct 2014 09:05:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0A2FB20172 for ; Mon, 20 Oct 2014 09:05:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DDDE820179 for ; Mon, 20 Oct 2014 09:05:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753264AbaJTJFc (ORCPT ); Mon, 20 Oct 2014 05:05:32 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:9537 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753195AbaJTJFY (ORCPT ); Mon, 20 Oct 2014 05:05:24 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NDQ00F0KK1ME7A0@mailout2.w1.samsung.com>; Mon, 20 Oct 2014 10:08:10 +0100 (BST) X-AuditID: cbfec7f5-b7f956d000005ed7-54-5444d051bdb7 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 41.1D.24279.150D4445; Mon, 20 Oct 2014 10:05:21 +0100 (BST) Received: from AMDC1943.digital.local ([106.116.151.171]) by eusync4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NDQ008ZEJWR1P90@eusync4.samsung.com>; Mon, 20 Oct 2014 10:05:21 +0100 (BST) From: Krzysztof Kozlowski To: "Rafael J. Wysocki" , Len Brown , Pavel Machek , Jonathan Corbet , Russell King , Dan Williams , Vinod Koul , Ulf Hansson , Alan Stern , Krzysztof Kozlowski , linux-pm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org, Lars-Peter Clausen , Michal Simek Cc: Kyungmin Park , Marek Szyprowski , Bartlomiej Zolnierkiewicz Subject: [PATCH v8 3/5] amba: Don't unprepare the clocks if device driver wants IRQ safe runtime PM Date: Mon, 20 Oct 2014 11:04:46 +0200 Message-id: <1413795888-18559-4-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1413795888-18559-1-git-send-email-k.kozlowski@samsung.com> References: <1413795888-18559-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrLLMWRmVeSWpSXmKPExsVy+t/xa7qBF1xCDJa/4LXYOGM9q8WTA+2M FtOnXmC0WD31L6vF6xeGFmeb3rBbLJk8n9Vi1pS9TBYL25awWFzeNYfN4nPvEUaL25d5LdYe uctu8e5lhMXdU0fZLM6cvsRqMeH3BTaL42vDLV727WdxEPZoae5h81i85yWTx51re4Csvsms HkveHGL12HK1ncVj9t0fjB59W1YxeqxY/Z3d4/MmOY+9n3+zBHBHcdmkpOZklqUW6dslcGXc mHGOreC2aMXuE30sDYzHBbsYOTkkBEwkHiz4wAhhi0lcuLeeDcQWEljKKHHsSWUXIxeQ3cck sevmYlaQBJuAscTm5UvYQBIiAsdZJBb3XABzmAWmMEo0T1rKBFIlLJAq8XjfU2YQm0VAVWLV xVtgK3gF3CWmz9gNtU5O4uSxyWBTOQU8JKa3PGaEWO0u0b1wFdMERt4FjAyrGEVTS5MLipPS c430ihNzi0vz0vWS83M3MUKi4OsOxqXHrA4xCnAwKvHw7jBzCRFiTSwrrsw9xCjBwawkwst0 FCjEm5JYWZValB9fVJqTWnyIkYmDU6qB8eZGjns8bScTos2j1vd+kn13SXbu8jPasmknV5gd OmGodNHtlbnGqr+H723c0C6jF7G8/I9j2Ps5mwtPnwvndY9zsAmUP3hN/n+GTla0QLEPn1CT sWbh9Xv1nnu33Zly8/O9149Ort6Yfr1v6ymr/INW62eGmzmxK52Ru75TqN0p5sOt33ceWimx FGckGmoxFxUnAgA+LO62YAIAAA== Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 The AMBA bus driver defines runtime Power Management functions which disable and unprepare AMBA bus clock. This is problematic for runtime PM because unpreparing a clock might sleep so it is not interrupt safe. However some drivers may want to implement runtime PM functions in interrupt-safe way (see pm_runtime_irq_safe()). In such case the AMBA bus driver should only disable/enable the clock in runtime suspend and resume callbacks. Detect the device driver behavior after calling its probe function and store it. During runtime suspend/resume deal with clocks according to stored value. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Ulf Hansson --- drivers/amba/bus.c | 29 +++++++++++++++++++++++++---- include/linux/amba/bus.h | 1 + 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 47bbdc1b5be3..474434e1b1b9 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -95,8 +95,18 @@ static int amba_pm_runtime_suspend(struct device *dev) struct amba_device *pcdev = to_amba_device(dev); int ret = pm_generic_runtime_suspend(dev); - if (ret == 0 && dev->driver) - clk_disable_unprepare(pcdev->pclk); + if (ret == 0 && dev->driver) { + /* + * Drivers should not change pm_runtime_irq_safe() + * after probe. + */ + WARN_ON(pcdev->irq_safe != pm_runtime_is_irq_safe(dev)); + + if (pcdev->irq_safe) + clk_disable(pcdev->pclk); + else + clk_disable_unprepare(pcdev->pclk); + } return ret; } @@ -107,7 +117,16 @@ static int amba_pm_runtime_resume(struct device *dev) int ret; if (dev->driver) { - ret = clk_prepare_enable(pcdev->pclk); + /* + * Drivers should not change pm_runtime_irq_safe() + * after probe. + */ + WARN_ON(pcdev->irq_safe != pm_runtime_is_irq_safe(dev)); + + if (pcdev->irq_safe) + ret = clk_enable(pcdev->pclk); + else + ret = clk_prepare_enable(pcdev->pclk); /* Failure is probably fatal to the system, but... */ if (ret) return ret; @@ -198,8 +217,10 @@ static int amba_probe(struct device *dev) pm_runtime_enable(dev); ret = pcdrv->probe(pcdev, id); - if (ret == 0) + if (ret == 0) { + pcdev->irq_safe = pm_runtime_is_irq_safe(dev); break; + } pm_runtime_disable(dev); pm_runtime_set_suspended(dev); diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h index ac02f9bd63dc..c4bae79851fb 100644 --- a/include/linux/amba/bus.h +++ b/include/linux/amba/bus.h @@ -32,6 +32,7 @@ struct amba_device { struct clk *pclk; unsigned int periphid; unsigned int irq[AMBA_NR_IRQS]; + unsigned int irq_safe:1; }; struct amba_driver {