From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Marc Kleine-Budde <mkl@pengutronix.de>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Cc: linux-can@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH v2 03/11] can: rcar_can: Convert to Runtime PM
Date: Fri, 22 Aug 2025 12:17:04 +0200 [thread overview]
Message-ID: <68bfa5480a79c17c6ceec4fb073f33872e7ff5d0.1755857536.git.geert+renesas@glider.be> (raw)
In-Reply-To: <cover.1755857536.git.geert+renesas@glider.be>
The R-Car CAN module is part of a Clock Domain on all supported SoCs.
Hence convert its driver from explicit clock management to Runtime PM.
While at it, use %pe to format error codes.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v2:
- Convert to %pe.
---
drivers/net/can/rcar/rcar_can.c | 48 ++++++++++++++++-----------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/drivers/net/can/rcar/rcar_can.c b/drivers/net/can/rcar/rcar_can.c
index 57030992141cc523..15dbaa52a7b135d9 100644
--- a/drivers/net/can/rcar/rcar_can.c
+++ b/drivers/net/can/rcar/rcar_can.c
@@ -16,6 +16,7 @@
#include <linux/can/dev.h>
#include <linux/clk.h>
#include <linux/of.h>
+#include <linux/pm_runtime.h>
#define RCAR_CAN_DRV_NAME "rcar_can"
@@ -92,7 +93,6 @@ struct rcar_can_priv {
struct net_device *ndev;
struct napi_struct napi;
struct rcar_can_regs __iomem *regs;
- struct clk *clk;
struct clk *can_clk;
u32 tx_head;
u32 tx_tail;
@@ -506,18 +506,17 @@ static int rcar_can_open(struct net_device *ndev)
struct rcar_can_priv *priv = netdev_priv(ndev);
int err;
- err = clk_prepare_enable(priv->clk);
+ err = pm_runtime_resume_and_get(ndev->dev.parent);
if (err) {
- netdev_err(ndev,
- "failed to enable peripheral clock, error %d\n",
- err);
+ netdev_err(ndev, "pm_runtime_resume_and_get() failed %pe\n",
+ ERR_PTR(err));
goto out;
}
err = clk_prepare_enable(priv->can_clk);
if (err) {
netdev_err(ndev, "failed to enable CAN clock, error %d\n",
err);
- goto out_clock;
+ goto out_rpm;
}
err = open_candev(ndev);
if (err) {
@@ -539,8 +538,8 @@ static int rcar_can_open(struct net_device *ndev)
close_candev(ndev);
out_can_clock:
clk_disable_unprepare(priv->can_clk);
-out_clock:
- clk_disable_unprepare(priv->clk);
+out_rpm:
+ pm_runtime_put(ndev->dev.parent);
out:
return err;
}
@@ -578,7 +577,7 @@ static int rcar_can_close(struct net_device *ndev)
free_irq(ndev->irq, ndev);
napi_disable(&priv->napi);
clk_disable_unprepare(priv->can_clk);
- clk_disable_unprepare(priv->clk);
+ pm_runtime_put(ndev->dev.parent);
close_candev(ndev);
return 0;
}
@@ -721,12 +720,15 @@ static int rcar_can_get_berr_counter(const struct net_device *ndev,
struct rcar_can_priv *priv = netdev_priv(ndev);
int err;
- err = clk_prepare_enable(priv->clk);
+ err = pm_runtime_resume_and_get(ndev->dev.parent);
if (err)
return err;
+
bec->txerr = readb(&priv->regs->tecr);
bec->rxerr = readb(&priv->regs->recr);
- clk_disable_unprepare(priv->clk);
+
+ pm_runtime_put(ndev->dev.parent);
+
return 0;
}
@@ -770,13 +772,6 @@ static int rcar_can_probe(struct platform_device *pdev)
priv = netdev_priv(ndev);
- priv->clk = devm_clk_get(dev, "clkp1");
- if (IS_ERR(priv->clk)) {
- err = PTR_ERR(priv->clk);
- dev_err(dev, "cannot get peripheral clock, error %d\n", err);
- goto fail_clk;
- }
-
if (!(BIT(clock_select) & RCAR_SUPPORTED_CLOCKS)) {
err = -EINVAL;
dev_err(dev, "invalid CAN clock selected\n");
@@ -806,16 +801,20 @@ static int rcar_can_probe(struct platform_device *pdev)
netif_napi_add_weight(ndev, &priv->napi, rcar_can_rx_poll,
RCAR_CAN_NAPI_WEIGHT);
+
+ pm_runtime_enable(dev);
+
err = register_candev(ndev);
if (err) {
dev_err(dev, "register_candev() failed, error %d\n", err);
- goto fail_candev;
+ goto fail_rpm;
}
dev_info(dev, "device registered (IRQ%d)\n", ndev->irq);
return 0;
-fail_candev:
+fail_rpm:
+ pm_runtime_disable(dev);
netif_napi_del(&priv->napi);
fail_clk:
free_candev(ndev);
@@ -829,6 +828,7 @@ static void rcar_can_remove(struct platform_device *pdev)
struct rcar_can_priv *priv = netdev_priv(ndev);
unregister_candev(ndev);
+ pm_runtime_disable(&pdev->dev);
netif_napi_del(&priv->napi);
free_candev(ndev);
}
@@ -852,22 +852,22 @@ static int rcar_can_suspend(struct device *dev)
writew(ctlr, &priv->regs->ctlr);
priv->can.state = CAN_STATE_SLEEPING;
- clk_disable(priv->clk);
+ pm_runtime_put(dev);
return 0;
}
static int rcar_can_resume(struct device *dev)
{
struct net_device *ndev = dev_get_drvdata(dev);
- struct rcar_can_priv *priv = netdev_priv(ndev);
int err;
if (!netif_running(ndev))
return 0;
- err = clk_enable(priv->clk);
+ err = pm_runtime_resume_and_get(dev);
if (err) {
- netdev_err(ndev, "clk_enable() failed, error %d\n", err);
+ netdev_err(ndev, "pm_runtime_resume_and_get() failed %pe\n",
+ ERR_PTR(err));
return err;
}
--
2.43.0
next prev parent reply other threads:[~2025-08-22 10:17 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-22 10:17 [PATCH v2 00/11] can: rcar_can: Miscellaneous cleanups and improvements Geert Uytterhoeven
2025-08-22 10:17 ` [PATCH v2 01/11] can: rcar_can: Consistently use ndev for net_device pointers Geert Uytterhoeven
2025-08-22 14:28 ` Biju Das
2025-08-22 10:17 ` [PATCH v2 02/11] can: rcar_can: Add helper variable dev to rcar_can_probe() Geert Uytterhoeven
2025-08-22 14:29 ` Biju Das
2025-08-22 10:17 ` Geert Uytterhoeven [this message]
2025-08-22 10:17 ` [PATCH v2 04/11] can: rcar_can: Convert to BIT() Geert Uytterhoeven
2025-08-22 10:17 ` [PATCH v2 05/11] can: rcar_can: Convert to GENMASK() Geert Uytterhoeven
2025-08-22 10:17 ` [PATCH v2 06/11] can: rcar_can: CTLR bitfield conversion Geert Uytterhoeven
2025-08-22 10:17 ` [PATCH v2 07/11] can: rcar_can: TFCR " Geert Uytterhoeven
2025-08-22 10:17 ` [PATCH v2 08/11] can: rcar_can: BCR " Geert Uytterhoeven
2025-08-22 14:38 ` Biju Das
2025-08-22 10:17 ` [PATCH v2 09/11] can: rcar_can: Mailbox " Geert Uytterhoeven
2025-08-22 10:17 ` [PATCH v2 10/11] can: rcar_can: Do not print alloc_candev() failures Geert Uytterhoeven
2025-08-22 14:42 ` Biju Das
2025-08-22 10:17 ` [PATCH v2 11/11] can: rcar_can: Convert to %pe Geert Uytterhoeven
2025-08-22 14:43 ` Biju Das
2025-09-19 17:26 ` [PATCH v2 00/11] can: rcar_can: Miscellaneous cleanups and improvements Marc Kleine-Budde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=68bfa5480a79c17c6ceec4fb073f33872e7ff5d0.1755857536.git.geert+renesas@glider.be \
--to=geert+renesas@glider.be \
--cc=linux-can@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=mkl@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).