2021-01-17 20:52:19 +01:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2020-12-13 09:12:54 +01:00
|
|
|
From: Samuel Holland <samuel@sholland.org>
|
|
|
|
Date: Wed, 1 Jan 2020 00:10:40 -0600
|
2021-01-17 20:52:19 +01:00
|
|
|
Subject: [PATCH] bus: sunxi-rsb: Implement runtime power management
|
|
|
|
|
|
|
|
Gate the clock to save power while the controller is idle.
|
2020-12-13 09:12:54 +01:00
|
|
|
|
|
|
|
Signed-off-by: Samuel Holland <samuel@sholland.org>
|
|
|
|
---
|
2021-01-17 20:52:19 +01:00
|
|
|
drivers/bus/sunxi-rsb.c | 44 +++++++++++++++++++++++++++++++++++++++++
|
|
|
|
1 file changed, 44 insertions(+)
|
2020-12-13 09:12:54 +01:00
|
|
|
|
|
|
|
--- a/drivers/bus/sunxi-rsb.c
|
|
|
|
+++ b/drivers/bus/sunxi-rsb.c
|
|
|
|
@@ -46,6 +46,7 @@
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/pm.h>
|
|
|
|
+#include <linux/pm_runtime.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/reset.h>
|
|
|
|
#include <linux/slab.h>
|
2021-01-17 20:52:19 +01:00
|
|
|
@@ -337,6 +338,10 @@ static int sunxi_rsb_read(struct sunxi_r
|
2020-12-13 09:12:54 +01:00
|
|
|
return -EINVAL;
|
2021-01-17 20:52:19 +01:00
|
|
|
}
|
2020-12-13 09:12:54 +01:00
|
|
|
|
2021-01-17 20:52:19 +01:00
|
|
|
+ ret = pm_runtime_resume_and_get(rsb->dev);
|
|
|
|
+ if (ret)
|
|
|
|
+ return ret;
|
|
|
|
+
|
2020-12-13 09:12:54 +01:00
|
|
|
mutex_lock(&rsb->lock);
|
|
|
|
|
2021-01-17 20:52:19 +01:00
|
|
|
writel(addr, rsb->regs + RSB_ADDR);
|
|
|
|
@@ -352,6 +357,9 @@ static int sunxi_rsb_read(struct sunxi_r
|
2020-12-13 09:12:54 +01:00
|
|
|
unlock:
|
|
|
|
mutex_unlock(&rsb->lock);
|
2021-01-17 20:52:19 +01:00
|
|
|
|
2020-12-13 09:12:54 +01:00
|
|
|
+ pm_runtime_mark_last_busy(rsb->dev);
|
|
|
|
+ pm_runtime_put_autosuspend(rsb->dev);
|
2021-01-17 20:52:19 +01:00
|
|
|
+
|
2020-12-13 09:12:54 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2021-01-17 20:52:19 +01:00
|
|
|
|
|
|
|
@@ -379,6 +387,10 @@ static int sunxi_rsb_write(struct sunxi_
|
2020-12-13 09:12:54 +01:00
|
|
|
return -EINVAL;
|
2021-01-17 20:52:19 +01:00
|
|
|
}
|
2020-12-13 09:12:54 +01:00
|
|
|
|
2021-01-17 20:52:19 +01:00
|
|
|
+ ret = pm_runtime_resume_and_get(rsb->dev);
|
|
|
|
+ if (ret)
|
|
|
|
+ return ret;
|
|
|
|
+
|
2020-12-13 09:12:54 +01:00
|
|
|
mutex_lock(&rsb->lock);
|
|
|
|
|
2021-01-17 20:52:19 +01:00
|
|
|
writel(addr, rsb->regs + RSB_ADDR);
|
|
|
|
@@ -389,6 +401,9 @@ static int sunxi_rsb_write(struct sunxi_
|
2020-12-13 09:12:54 +01:00
|
|
|
|
|
|
|
mutex_unlock(&rsb->lock);
|
2021-01-17 20:52:19 +01:00
|
|
|
|
2020-12-13 09:12:54 +01:00
|
|
|
+ pm_runtime_mark_last_busy(rsb->dev);
|
|
|
|
+ pm_runtime_put_autosuspend(rsb->dev);
|
2021-01-17 20:52:19 +01:00
|
|
|
+
|
2020-12-13 09:12:54 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2021-01-17 20:52:19 +01:00
|
|
|
|
|
|
|
@@ -672,10 +687,29 @@ err_clk_disable:
|
|
|
|
|
|
|
|
static void sunxi_rsb_hw_exit(struct sunxi_rsb *rsb)
|
|
|
|
{
|
|
|
|
+ /* Keep the clock and PM reference counts consistent. */
|
|
|
|
+ if (pm_runtime_status_suspended(rsb->dev))
|
|
|
|
+ pm_runtime_resume(rsb->dev);
|
|
|
|
reset_control_assert(rsb->rstc);
|
|
|
|
clk_disable_unprepare(rsb->clk);
|
2020-12-13 09:12:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+static int __maybe_unused sunxi_rsb_runtime_suspend(struct device *dev)
|
|
|
|
+{
|
|
|
|
+ struct sunxi_rsb *rsb = dev_get_drvdata(dev);
|
|
|
|
+
|
|
|
|
+ clk_disable_unprepare(rsb->clk);
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int __maybe_unused sunxi_rsb_runtime_resume(struct device *dev)
|
|
|
|
+{
|
|
|
|
+ struct sunxi_rsb *rsb = dev_get_drvdata(dev);
|
|
|
|
+
|
|
|
|
+ return clk_prepare_enable(rsb->clk);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
static int __maybe_unused sunxi_rsb_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct sunxi_rsb *rsb = dev_get_drvdata(dev);
|
2021-01-17 20:52:19 +01:00
|
|
|
@@ -758,6 +792,12 @@ static int sunxi_rsb_probe(struct platfo
|
|
|
|
if (ret)
|
|
|
|
dev_warn(dev, "Initialize device mode failed: %d\n", ret);
|
2020-12-13 09:12:54 +01:00
|
|
|
|
|
|
|
+ pm_suspend_ignore_children(dev, true);
|
|
|
|
+ pm_runtime_set_active(dev);
|
2021-01-17 20:52:19 +01:00
|
|
|
+ pm_runtime_set_autosuspend_delay(dev, MSEC_PER_SEC);
|
|
|
|
+ pm_runtime_use_autosuspend(dev);
|
2020-12-13 09:12:54 +01:00
|
|
|
+ pm_runtime_enable(dev);
|
|
|
|
+
|
2021-01-17 20:52:19 +01:00
|
|
|
of_rsb_register_devices(rsb);
|
2020-12-13 09:12:54 +01:00
|
|
|
|
2021-01-17 20:52:19 +01:00
|
|
|
return 0;
|
|
|
|
@@ -768,6 +808,7 @@ static int sunxi_rsb_remove(struct platf
|
2020-12-13 09:12:54 +01:00
|
|
|
struct sunxi_rsb *rsb = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
device_for_each_child(rsb->dev, NULL, sunxi_rsb_remove_devices);
|
|
|
|
+ pm_runtime_disable(&pdev->dev);
|
2021-01-17 20:52:19 +01:00
|
|
|
sunxi_rsb_hw_exit(rsb);
|
|
|
|
|
2020-12-13 09:12:54 +01:00
|
|
|
return 0;
|
2021-01-17 20:52:19 +01:00
|
|
|
@@ -777,10 +818,13 @@ static void sunxi_rsb_shutdown(struct pl
|
|
|
|
{
|
|
|
|
struct sunxi_rsb *rsb = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
+ pm_runtime_disable(&pdev->dev);
|
|
|
|
sunxi_rsb_hw_exit(rsb);
|
2020-12-13 09:12:54 +01:00
|
|
|
}
|
|
|
|
|
2021-01-17 20:52:19 +01:00
|
|
|
static const struct dev_pm_ops sunxi_rsb_dev_pm_ops = {
|
|
|
|
+ SET_RUNTIME_PM_OPS(sunxi_rsb_runtime_suspend,
|
|
|
|
+ sunxi_rsb_runtime_resume, NULL)
|
|
|
|
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sunxi_rsb_suspend, sunxi_rsb_resume)
|
|
|
|
};
|
|
|
|
|