From patchwork Mon Sep 15 10:13:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 4904141 Return-Path: X-Original-To: patchwork-dmaengine@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 470D4BEEA5 for ; Mon, 15 Sep 2014 10:16:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A4D6D20166 for ; Mon, 15 Sep 2014 10:16:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F0C292015E for ; Mon, 15 Sep 2014 10:16:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753920AbaIOKPP (ORCPT ); Mon, 15 Sep 2014 06:15:15 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:25369 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753759AbaIOKOk (ORCPT ); Mon, 15 Sep 2014 06:14:40 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NBX005L4TX82470@mailout1.w1.samsung.com>; Mon, 15 Sep 2014 11:17:32 +0100 (BST) X-AuditID: cbfec7f4-b7f156d0000063c7-d5-5416bc0db957 Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id AB.F3.25543.D0CB6145; Mon, 15 Sep 2014 11:14:37 +0100 (BST) Received: from AMDC1943.digital.local ([106.116.151.171]) by eusync2.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NBX000N9TS7T610@eusync2.samsung.com>; Mon, 15 Sep 2014 11:14:37 +0100 (BST) From: Krzysztof Kozlowski To: Russell King , Dan Williams , Vinod Koul , linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org, Ulf Hansson , Grant Likely , Lars-Peter Clausen , Michal Simek , linux-pm@vger.kernel.org Cc: Kyungmin Park , Marek Szyprowski , Bartlomiej Zolnierkiewicz , Krzysztof Kozlowski Subject: [PATCH v3 3/4] amba: Don't unprepare the clocks if device driver wants IRQ safe runtime PM Date: Mon, 15 Sep 2014 12:13:52 +0200 Message-id: <1410776033-22156-4-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1410776033-22156-1-git-send-email-k.kozlowski@samsung.com> References: <1410776033-22156-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrALMWRmVeSWpSXmKPExsVy+t/xK7q8e8RCDGZe1LTYOGM9q8X0qRcY LVZP/ctqceDPDkaL1y8MLc42vWG3WDJ5PqvF5V1z2Cw+9x5htLh9mddi7ZG77BbvXkZYHF8b bvGybz+LA59HS3MPm8fiPS+ZPO5c28PmseTNIVaPvi2rGD0+b5Lz2Pv5N0sAexSXTUpqTmZZ apG+XQJXRs/TNYwF+0Qruh/NZGpgXCHYxcjJISFgInFvw3MmCFtM4sK99WxdjFwcQgJLGSU6 7n6CcvqYJGaceMoIUsUmYCyxefkSsISIwDsmiVvbT7GAOMwCRxklpve+BZslLJAqseXeRaAO Dg4WAVWJaYeEQcK8Au4SHdN/sEGsk5M4eWwyK4jNKeAhse1tAzuILQRU8+nJS8YJjLwLGBlW MYqmliYXFCel5xrqFSfmFpfmpesl5+duYoSE6pcdjIuPWR1iFOBgVOLhZbgiHCLEmlhWXJl7 iFGCg1lJhHfqVrEQId6UxMqq1KL8+KLSnNTiQ4xMHJxSDYzKok7lLr1lob1bWpcWpx39tUC6 WpqB/eg6k2PvpzsvDXsjXna2ymenue0F7xfSmwJnTMvm3rvgo0nOuScfDz4rWVF2okHjochL rX9vvQvMPYpmFfSsl99fmGvOlVjLa/BvTjlTiGYW0w1hR8kcKYu0+wuLnh/vk90n/Vp9Zvgx 55zTeWsuMSmxFGckGmoxFxUnAgD74dbgMwIAAA== Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Spam-Status: No, score=-7.6 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 not unprepare/prepare 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 --- drivers/amba/bus.c | 30 ++++++++++++++++++++++++++---- include/linux/amba/bus.h | 1 + 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 3cf61a127ee5..388ff4481762 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -94,8 +94,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_is_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; } @@ -106,7 +116,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_is_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; @@ -191,8 +210,11 @@ static int amba_probe(struct device *dev) pm_runtime_enable(dev); ret = pcdrv->probe(pcdev, id); - if (ret == 0) + if (ret == 0) { + if (pm_runtime_is_irq_safe(dev)) + pcdev->irq_safe = 1; 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 ad52027a9cbf..ce101e4497d6 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 {