memory: stm32-fmc2-ebi: keep power domain on
authorChristophe Kerello <christophe.kerello@foss.st.com>
Mon, 26 Feb 2024 10:14:28 +0000 (11:14 +0100)
committerKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Tue, 27 Feb 2024 09:18:04 +0000 (10:18 +0100)
MP25 FMC2 domain has to be kept on. To handle it throw PSCI OS-initiated,
basic PM for keeping domain on is introduced.

Signed-off-by: Christophe Kerello <christophe.kerello@foss.st.com>
Link: https://lore.kernel.org/r/20240226101428.37791-6-christophe.kerello@foss.st.com
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
drivers/memory/stm32-fmc2-ebi.c

index 45c658af613d2c61aac1b8f554e02223e088d678..1c63eeacd071cc080ce243d4eef9e0945bfe6bc9 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/of_platform.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/regmap.h>
 #include <linux/reset.h>
 
@@ -1649,6 +1650,7 @@ static int stm32_fmc2_ebi_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        ebi->dev = dev;
+       platform_set_drvdata(pdev, ebi);
 
        ebi->data = of_device_get_match_data(dev);
        if (!ebi->data)
@@ -1666,10 +1668,14 @@ static int stm32_fmc2_ebi_probe(struct platform_device *pdev)
        if (PTR_ERR(rstc) == -EPROBE_DEFER)
                return -EPROBE_DEFER;
 
-       ret = clk_prepare_enable(ebi->clk);
+       ret = devm_pm_runtime_enable(dev);
        if (ret)
                return ret;
 
+       ret = pm_runtime_resume_and_get(dev);
+       if (ret < 0)
+               return ret;
+
        if (!IS_ERR(rstc)) {
                reset_control_assert(rstc);
                reset_control_deassert(rstc);
@@ -1705,8 +1711,6 @@ static int stm32_fmc2_ebi_probe(struct platform_device *pdev)
        if (ret)
                goto err_release;
 
-       platform_set_drvdata(pdev, ebi);
-
        return 0;
 
 err_release:
@@ -1714,7 +1718,7 @@ err_release:
        stm32_fmc2_ebi_disable(ebi);
        if (ebi->data->put_sems)
                ebi->data->put_sems(ebi);
-       clk_disable_unprepare(ebi->clk);
+       pm_runtime_put_sync_suspend(dev);
 
        return ret;
 }
@@ -1728,7 +1732,23 @@ static void stm32_fmc2_ebi_remove(struct platform_device *pdev)
        stm32_fmc2_ebi_disable(ebi);
        if (ebi->data->put_sems)
                ebi->data->put_sems(ebi);
+       pm_runtime_put_sync_suspend(&pdev->dev);
+}
+
+static int __maybe_unused stm32_fmc2_ebi_runtime_suspend(struct device *dev)
+{
+       struct stm32_fmc2_ebi *ebi = dev_get_drvdata(dev);
+
        clk_disable_unprepare(ebi->clk);
+
+       return 0;
+}
+
+static int __maybe_unused stm32_fmc2_ebi_runtime_resume(struct device *dev)
+{
+       struct stm32_fmc2_ebi *ebi = dev_get_drvdata(dev);
+
+       return clk_prepare_enable(ebi->clk);
 }
 
 static int __maybe_unused stm32_fmc2_ebi_suspend(struct device *dev)
@@ -1738,7 +1758,7 @@ static int __maybe_unused stm32_fmc2_ebi_suspend(struct device *dev)
        stm32_fmc2_ebi_disable(ebi);
        if (ebi->data->put_sems)
                ebi->data->put_sems(ebi);
-       clk_disable_unprepare(ebi->clk);
+       pm_runtime_put_sync_suspend(dev);
        pinctrl_pm_select_sleep_state(dev);
 
        return 0;
@@ -1751,8 +1771,8 @@ static int __maybe_unused stm32_fmc2_ebi_resume(struct device *dev)
 
        pinctrl_pm_select_default_state(dev);
 
-       ret = clk_prepare_enable(ebi->clk);
-       if (ret)
+       ret = pm_runtime_resume_and_get(dev);
+       if (ret < 0)
                return ret;
 
        if (ebi->data->get_sems)
@@ -1763,8 +1783,11 @@ static int __maybe_unused stm32_fmc2_ebi_resume(struct device *dev)
        return 0;
 }
 
-static SIMPLE_DEV_PM_OPS(stm32_fmc2_ebi_pm_ops, stm32_fmc2_ebi_suspend,
-                        stm32_fmc2_ebi_resume);
+static const struct dev_pm_ops stm32_fmc2_ebi_pm_ops = {
+       SET_RUNTIME_PM_OPS(stm32_fmc2_ebi_runtime_suspend,
+                          stm32_fmc2_ebi_runtime_resume, NULL)
+       SET_SYSTEM_SLEEP_PM_OPS(stm32_fmc2_ebi_suspend, stm32_fmc2_ebi_resume)
+};
 
 static const struct stm32_fmc2_ebi_data stm32_fmc2_ebi_mp1_data = {
        .child_props = stm32_fmc2_child_props,