From: Claudiu Beznea <claudiu.beznea@microchip.com>
To: <mpm@selenic.com>, <herbert@gondor.apana.org.au>,
<nicolas.ferre@microchip.com>, <alexandre.belloni@bootlin.com>
Cc: <linux-arm-kernel@lists.infradead.org>,
<linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Claudiu Beznea <claudiu.beznea@microchip.com>
Subject: [PATCH v2 6/7] hwrng: atmel - add runtime pm support
Date: Mon, 21 Feb 2022 09:59:27 +0200 [thread overview]
Message-ID: <20220221075928.563806-7-claudiu.beznea@microchip.com> (raw)
In-Reply-To: <20220221075928.563806-1-claudiu.beznea@microchip.com>
Add runtime PM support.
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---
drivers/char/hw_random/atmel-rng.c | 44 ++++++++++++++++++++++--------
1 file changed, 32 insertions(+), 12 deletions(-)
diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c
index 0fff74808472..b662d44a09a6 100644
--- a/drivers/char/hw_random/atmel-rng.c
+++ b/drivers/char/hw_random/atmel-rng.c
@@ -17,6 +17,7 @@
#include <linux/hw_random.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
#define TRNG_CR 0x00
#define TRNG_MR 0x04
@@ -58,6 +59,12 @@ static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max,
u32 *data = buf;
int ret;
+ ret = pm_runtime_get_sync((struct device *)trng->rng.priv);
+ if (ret < 0) {
+ pm_runtime_put_sync((struct device *)trng->rng.priv);
+ return ret;
+ }
+
ret = atmel_trng_wait_ready(trng, wait);
if (!ret)
goto out;
@@ -72,6 +79,8 @@ static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max,
ret = 4;
out:
+ pm_runtime_mark_last_busy((struct device *)trng->rng.priv);
+ pm_runtime_put_sync_autosuspend((struct device *)trng->rng.priv);
return ret;
}
@@ -127,21 +136,28 @@ static int atmel_trng_probe(struct platform_device *pdev)
trng->has_half_rate = data->has_half_rate;
trng->rng.name = pdev->name;
trng->rng.read = atmel_trng_read;
+ trng->rng.priv = (unsigned long)&pdev->dev;
+ platform_set_drvdata(pdev, trng);
+#ifndef CONFIG_PM
ret = atmel_trng_init(trng);
if (ret)
return ret;
+#endif
- ret = devm_hwrng_register(&pdev->dev, &trng->rng);
- if (ret)
- goto err_register;
-
- platform_set_drvdata(pdev, trng);
+ pm_runtime_set_autosuspend_delay(&pdev->dev, 100);
+ pm_runtime_use_autosuspend(&pdev->dev);
+ pm_runtime_enable(&pdev->dev);
- return 0;
+ ret = devm_hwrng_register(&pdev->dev, &trng->rng);
+ if (ret) {
+ pm_runtime_disable(&pdev->dev);
+ pm_runtime_set_suspended(&pdev->dev);
+#ifndef CONFIG_PM
+ atmel_trng_cleanup(trng);
+#endif
+ }
-err_register:
- atmel_trng_cleanup(trng);
return ret;
}
@@ -151,11 +167,13 @@ static int atmel_trng_remove(struct platform_device *pdev)
atmel_trng_cleanup(trng);
+ pm_runtime_disable(&pdev->dev);
+ pm_runtime_set_suspended(&pdev->dev);
return 0;
}
-static int __maybe_unused atmel_trng_suspend(struct device *dev)
+static int __maybe_unused atmel_trng_runtime_suspend(struct device *dev)
{
struct atmel_trng *trng = dev_get_drvdata(dev);
@@ -164,7 +182,7 @@ static int __maybe_unused atmel_trng_suspend(struct device *dev)
return 0;
}
-static int __maybe_unused atmel_trng_resume(struct device *dev)
+static int __maybe_unused atmel_trng_runtime_resume(struct device *dev)
{
struct atmel_trng *trng = dev_get_drvdata(dev);
@@ -172,8 +190,10 @@ static int __maybe_unused atmel_trng_resume(struct device *dev)
}
static const struct dev_pm_ops __maybe_unused atmel_trng_pm_ops = {
- .suspend = atmel_trng_suspend,
- .resume = atmel_trng_resume,
+ SET_RUNTIME_PM_OPS(atmel_trng_runtime_suspend,
+ atmel_trng_runtime_resume, NULL)
+ SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
+ pm_runtime_force_resume)
};
static const struct atmel_trng_data at91sam9g45_config = {
--
2.32.0
next prev parent reply other threads:[~2022-02-21 7:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-21 7:59 [PATCH v2 0/7] hwrng: atmel - add runtime pm support Claudiu Beznea
2022-02-21 7:59 ` [PATCH v2 1/7] hwrng: atmel - add wait for ready support on read Claudiu Beznea
2022-02-21 7:59 ` [PATCH v2 2/7] hwrng: atmel - disable trng on failure path Claudiu Beznea
2022-02-21 7:59 ` [PATCH v2 3/7] hwrng: atmel - rename enable/disable functions to init/cleanup Claudiu Beznea
2022-02-21 7:59 ` [PATCH v2 4/7] hwrng: atmel - move set of TRNG_HALFR in atmel_trng_init() Claudiu Beznea
2022-02-21 7:59 ` [PATCH v2 5/7] hwrng: atmel - use __maybe_unused and pm_ptr() for pm ops Claudiu Beznea
2022-02-21 7:59 ` Claudiu Beznea [this message]
2022-02-21 7:59 ` [PATCH v2 7/7] hwrng: atmel - remove extra line Claudiu Beznea
2022-02-21 10:50 ` [PATCH v2 0/7] hwrng: atmel - add runtime pm support Claudiu.Beznea
2022-03-02 22:57 ` Herbert Xu
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=20220221075928.563806-7-claudiu.beznea@microchip.com \
--to=claudiu.beznea@microchip.com \
--cc=alexandre.belloni@bootlin.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mpm@selenic.com \
--cc=nicolas.ferre@microchip.com \
/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).