diff mbox

[RFC,v2,1/2] amba: Allow AMBA drivers to use their own runtime PM

Message ID 1410533779-3310-2-git-send-email-k.kozlowski@samsung.com (mailing list archive)
State Superseded
Headers show

Commit Message

Krzysztof Kozlowski Sept. 12, 2014, 2:56 p.m. UTC
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()). If such driver
implements its own runtime PM functions then assume it will handle the
runtime PM completely and it will replace our clock handling.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
 drivers/amba/bus.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

Russell King - ARM Linux Sept. 12, 2014, 3:13 p.m. UTC | #1
On Fri, Sep 12, 2014 at 04:56:18PM +0200, Krzysztof Kozlowski wrote:
> 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()). If such driver
> implements its own runtime PM functions then assume it will handle the
> runtime PM completely and it will replace our clock handling.
> 
> Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Actually, I'd rather just revert 5303c0f46c8708fff4148ebcc491f78710356952
which is clearly the wrong thing to do when we have non-IRQ safe runtime
PM.

What we /could/ do instead is to check whether irq_safe is set after
probe, record that, and then select whether to use the prepare/unprepare
methods based on that.  (Drivers should never dynamically change this.)
Krzysztof Kozlowski Sept. 15, 2014, 7:07 a.m. UTC | #2
On pi?, 2014-09-12 at 16:13 +0100, Russell King - ARM Linux wrote:
> On Fri, Sep 12, 2014 at 04:56:18PM +0200, Krzysztof Kozlowski wrote:
> > 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()). If such driver
> > implements its own runtime PM functions then assume it will handle the
> > runtime PM completely and it will replace our clock handling.
> > 
> > Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> 
> Actually, I'd rather just revert 5303c0f46c8708fff4148ebcc491f78710356952
> which is clearly the wrong thing to do when we have non-IRQ safe runtime
> PM.
> 
> What we /could/ do instead is to check whether irq_safe is set after
> probe, record that, and then select whether to use the prepare/unprepare
> methods based on that.  (Drivers should never dynamically change this.)

I'll try this approach.

Thank you for feedback,
Krzysztof

--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 3cf61a127ee5..38461430b7cf 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -94,9 +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)
+	if (ret == 0 && dev->driver) {
+		/*
+		 * If driver handles runtime suspend don't duplicate
+		 * the work here.
+		 */
+		if (dev->driver->pm && dev->driver->pm->runtime_suspend)
+			goto out;
+
 		clk_disable_unprepare(pcdev->pclk);
+	}
 
+out:
 	return ret;
 }
 
@@ -106,12 +115,16 @@  static int amba_pm_runtime_resume(struct device *dev)
 	int ret;
 
 	if (dev->driver) {
+		if (dev->driver->pm && dev->driver->pm->runtime_resume)
+			goto out;
+
 		ret = clk_prepare_enable(pcdev->pclk);
 		/* Failure is probably fatal to the system, but... */
 		if (ret)
 			return ret;
 	}
 
+out:
 	return pm_generic_runtime_resume(dev);
 }
 #endif