drivers/memory/renesas-rpc-if.c | 57 ++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 8 deletions(-)
From: Biju Das <biju.das.jz@bp.renesas.com>
On RZ/G3E using PSCI, s2ram powers down the SoC. Add suspend/resume
callbacks to control spi/spix2 clocks.
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v1->v2:
* Updated error messages in rpcif_resume().
---
drivers/memory/renesas-rpc-if.c | 57 ++++++++++++++++++++++++++++-----
1 file changed, 49 insertions(+), 8 deletions(-)
diff --git a/drivers/memory/renesas-rpc-if.c b/drivers/memory/renesas-rpc-if.c
index 4a417b693080..2bcb05559ccb 100644
--- a/drivers/memory/renesas-rpc-if.c
+++ b/drivers/memory/renesas-rpc-if.c
@@ -67,6 +67,8 @@ struct rpcif_priv {
void __iomem *dirmap;
struct regmap *regmap;
struct reset_control *rstc;
+ struct clk *spi_clk;
+ struct clk *spix2_clk;
struct platform_device *vdev;
size_t size;
const struct rpcif_info *info;
@@ -1025,16 +1027,14 @@ static int rpcif_probe(struct platform_device *pdev)
* disable it in remove().
*/
if (rpc->info->type == XSPI_RZ_G3E) {
- struct clk *spi_clk;
-
- spi_clk = devm_clk_get_enabled(dev, "spix2");
- if (IS_ERR(spi_clk))
- return dev_err_probe(dev, PTR_ERR(spi_clk),
+ rpc->spix2_clk = devm_clk_get_enabled(dev, "spix2");
+ if (IS_ERR(rpc->spix2_clk))
+ return dev_err_probe(dev, PTR_ERR(rpc->spix2_clk),
"cannot get enabled spix2 clk\n");
- spi_clk = devm_clk_get_enabled(dev, "spi");
- if (IS_ERR(spi_clk))
- return dev_err_probe(dev, PTR_ERR(spi_clk),
+ rpc->spi_clk = devm_clk_get_enabled(dev, "spi");
+ if (IS_ERR(rpc->spi_clk))
+ return dev_err_probe(dev, PTR_ERR(rpc->spi_clk),
"cannot get enabled spi clk\n");
}
@@ -1063,6 +1063,44 @@ static void rpcif_remove(struct platform_device *pdev)
platform_device_unregister(rpc->vdev);
}
+static int rpcif_suspend(struct device *dev)
+{
+ struct rpcif_priv *rpc = dev_get_drvdata(dev);
+
+ if (rpc->info->type == XSPI_RZ_G3E) {
+ clk_disable_unprepare(rpc->spi_clk);
+ clk_disable_unprepare(rpc->spix2_clk);
+ }
+
+ return 0;
+}
+
+static int rpcif_resume(struct device *dev)
+{
+ struct rpcif_priv *rpc = dev_get_drvdata(dev);
+
+ if (rpc->info->type == XSPI_RZ_G3E) {
+ int ret;
+
+ ret = clk_prepare_enable(rpc->spix2_clk);
+ if (ret) {
+ dev_err(dev, "failed to enable spix2 clock: %pe\n",
+ ERR_PTR(ret));
+ return ret;
+ }
+
+ ret = clk_prepare_enable(rpc->spi_clk);
+ if (ret) {
+ clk_disable_unprepare(rpc->spix2_clk);
+ dev_err(dev, "failed to enable spi clock: %pe\n",
+ ERR_PTR(ret));
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
static const struct rpcif_impl rpcif_impl = {
.hw_init = rpcif_hw_init_impl,
.prepare = rpcif_prepare_impl,
@@ -1125,12 +1163,15 @@ static const struct of_device_id rpcif_of_match[] = {
};
MODULE_DEVICE_TABLE(of, rpcif_of_match);
+static DEFINE_SIMPLE_DEV_PM_OPS(rpcif_pm_ops, rpcif_suspend, rpcif_resume);
+
static struct platform_driver rpcif_driver = {
.probe = rpcif_probe,
.remove = rpcif_remove,
.driver = {
.name = "rpc-if",
.of_match_table = rpcif_of_match,
+ .pm = pm_sleep_ptr(&rpcif_pm_ops),
},
};
module_platform_driver(rpcif_driver);
--
2.43.0
On 23/09/2025 17:14, Biju wrote:
> if (rpc->info->type == XSPI_RZ_G3E) {
> - struct clk *spi_clk;
> -
> - spi_clk = devm_clk_get_enabled(dev, "spix2");
> - if (IS_ERR(spi_clk))
> - return dev_err_probe(dev, PTR_ERR(spi_clk),
> + rpc->spix2_clk = devm_clk_get_enabled(dev, "spix2");
> + if (IS_ERR(rpc->spix2_clk))
> + return dev_err_probe(dev, PTR_ERR(rpc->spix2_clk),
> "cannot get enabled spix2 clk\n");
>
> - spi_clk = devm_clk_get_enabled(dev, "spi");
> - if (IS_ERR(spi_clk))
> - return dev_err_probe(dev, PTR_ERR(spi_clk),
> + rpc->spi_clk = devm_clk_get_enabled(dev, "spi");
> + if (IS_ERR(rpc->spi_clk))
> + return dev_err_probe(dev, PTR_ERR(rpc->spi_clk),
> "cannot get enabled spi clk\n");
> }
>
> @@ -1063,6 +1063,44 @@ static void rpcif_remove(struct platform_device *pdev)
> platform_device_unregister(rpc->vdev);
> }
>
> +static int rpcif_suspend(struct device *dev)
> +{
> + struct rpcif_priv *rpc = dev_get_drvdata(dev);
> +
> + if (rpc->info->type == XSPI_RZ_G3E) {
clk are null in other case, so you can simplify it by dropping this if().
> + clk_disable_unprepare(rpc->spi_clk);
> + clk_disable_unprepare(rpc->spix2_clk);
> + }
> +
> + return 0;
> +}
> +
> +static int rpcif_resume(struct device *dev)
> +{
> + struct rpcif_priv *rpc = dev_get_drvdata(dev);
> +
> + if (rpc->info->type == XSPI_RZ_G3E) {
... which would save you one indentation here making it a bit more readable.
> + int ret;
> +
> + ret = clk_prepare_enable(rpc->spix2_clk);
> + if (ret) {
> + dev_err(dev, "failed to enable spix2 clock: %pe\n",
> + ERR_PTR(ret));
> + return ret;
Best regards,
Krzysztof
© 2016 - 2026 Red Hat, Inc.