[PATCH v7 29/37] memory: tegra30-emc: Add minimal runtime PM support

Dmitry Osipenko
2021-07-01T23:29:59Z

EMC is always enabled, mark it as enabled. This makes the OPP and GENPD
API usage more consistent since otherwise we're changing performance state
of a power domain for the device that doesn't support power management.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
drivers/memory/tegra/tegra30-emc.c | 31 ++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)

diff --git a/drivers/memory/tegra/tegra30-emc.c b/drivers/memory/tegra/tegra30-emc.c
index 7e21a852f2e1..5a311feb5c20 100644
--- a/drivers/memory/tegra/tegra30-emc.c
+++ b/drivers/memory/tegra/tegra30-emc.c
@@ -24,6 +24,7 @@
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/pm_opp.h>
+#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <linux/sort.h>
#include <linux/types.h>
@@ -1519,6 +1520,32 @@ static int tegra_emc_init_clk(struct tegra_emc *emc)
return 0;
}

+static void devm_tegra_emc_disable_runtime_pm(void *dev)
+{
+ pm_runtime_put(dev);
+ pm_runtime_disable(dev);
+}
+
+static int tegra_emc_init_pm(struct tegra_emc *emc)
+{
+ int err;
+
+ pm_runtime_enable(emc->dev);
+ err = pm_runtime_resume_and_get(emc->dev);
+ if (err) {
+ pm_runtime_disable(emc->dev);
+ return err;
+ }
+
+ err = devm_add_action_or_reset(emc->dev,
+ devm_tegra_emc_disable_runtime_pm,
+ emc->dev);
+ if (err)
+ return err;
+
+ return 0;
+}
+
static int tegra_emc_probe(struct platform_device *pdev)
{
struct tegra_core_opp_params opp_params = {};
@@ -1571,6 +1598,10 @@ static int tegra_emc_probe(struct platform_device *pdev)
if (err)
return err;

+ err = tegra_emc_init_pm(emc);
+ if (err)
+ return err;
+
opp_params.init_state = true;

err = devm_tegra_core_dev_init_opp_table(&pdev->dev, &opp_params);
--
2.30.2