Commit a216be39 authored by Corentin Labbe's avatar Corentin Labbe Committed by Herbert Xu

crypto: rockchip - introduce PM

Add runtime PM support for rockchip crypto.
Reviewed-by: default avatarJohn Keeping <john@metanate.com>
Signed-off-by: default avatarCorentin Labbe <clabbe@baylibre.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 48d904d4
......@@ -65,6 +65,48 @@ static void rk_crypto_disable_clk(struct rk_crypto_info *dev)
clk_disable_unprepare(dev->sclk);
}
/*
* Power management strategy: The device is suspended unless a TFM exists for
* one of the algorithms proposed by this driver.
*/
static int rk_crypto_pm_suspend(struct device *dev)
{
struct rk_crypto_info *rkdev = dev_get_drvdata(dev);
rk_crypto_disable_clk(rkdev);
return 0;
}
static int rk_crypto_pm_resume(struct device *dev)
{
struct rk_crypto_info *rkdev = dev_get_drvdata(dev);
return rk_crypto_enable_clk(rkdev);
}
static const struct dev_pm_ops rk_crypto_pm_ops = {
SET_RUNTIME_PM_OPS(rk_crypto_pm_suspend, rk_crypto_pm_resume, NULL)
};
static int rk_crypto_pm_init(struct rk_crypto_info *rkdev)
{
int err;
pm_runtime_use_autosuspend(rkdev->dev);
pm_runtime_set_autosuspend_delay(rkdev->dev, 2000);
err = pm_runtime_set_suspended(rkdev->dev);
if (err)
return err;
pm_runtime_enable(rkdev->dev);
return err;
}
static void rk_crypto_pm_exit(struct rk_crypto_info *rkdev)
{
pm_runtime_disable(rkdev->dev);
}
static irqreturn_t rk_crypto_irq_handle(int irq, void *dev_id)
{
struct rk_crypto_info *dev = platform_get_drvdata(dev_id);
......@@ -273,7 +315,9 @@ static int rk_crypto_probe(struct platform_device *pdev)
crypto_engine_start(crypto_info->engine);
init_completion(&crypto_info->complete);
rk_crypto_enable_clk(crypto_info);
err = rk_crypto_pm_init(crypto_info);
if (err)
goto err_pm;
err = rk_crypto_register(crypto_info);
if (err) {
......@@ -294,6 +338,8 @@ static int rk_crypto_probe(struct platform_device *pdev)
return 0;
err_register_alg:
rk_crypto_pm_exit(crypto_info);
err_pm:
crypto_engine_exit(crypto_info->engine);
err_crypto:
dev_err(dev, "Crypto Accelerator not successfully registered\n");
......@@ -308,7 +354,7 @@ static int rk_crypto_remove(struct platform_device *pdev)
debugfs_remove_recursive(crypto_tmp->dbgfs_dir);
#endif
rk_crypto_unregister();
rk_crypto_disable_clk(crypto_tmp);
rk_crypto_pm_exit(crypto_tmp);
crypto_engine_exit(crypto_tmp->engine);
return 0;
}
......@@ -318,6 +364,7 @@ static struct platform_driver crypto_driver = {
.remove = rk_crypto_remove,
.driver = {
.name = "rk3288-crypto",
.pm = &rk_crypto_pm_ops,
.of_match_table = crypto_of_id_table,
},
};
......
......@@ -9,6 +9,7 @@
#include <linux/interrupt.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/pm_runtime.h>
#include <linux/scatterlist.h>
#include <crypto/engine.h>
#include <crypto/internal/hash.h>
......
......@@ -328,6 +328,7 @@ static int rk_cra_hash_init(struct crypto_tfm *tfm)
struct ahash_alg *alg = __crypto_ahash_alg(tfm->__crt_alg);
const char *alg_name = crypto_tfm_alg_name(tfm);
int err;
algt = container_of(alg, struct rk_crypto_tmp, alg.hash);
......@@ -349,7 +350,15 @@ static int rk_cra_hash_init(struct crypto_tfm *tfm)
tctx->enginectx.op.prepare_request = rk_hash_prepare;
tctx->enginectx.op.unprepare_request = rk_hash_unprepare;
err = pm_runtime_resume_and_get(tctx->dev->dev);
if (err < 0)
goto error_pm;
return 0;
error_pm:
crypto_free_ahash(tctx->fallback_tfm);
return err;
}
static void rk_cra_hash_exit(struct crypto_tfm *tfm)
......@@ -357,6 +366,7 @@ static void rk_cra_hash_exit(struct crypto_tfm *tfm)
struct rk_ahash_ctx *tctx = crypto_tfm_ctx(tfm);
crypto_free_ahash(tctx->fallback_tfm);
pm_runtime_put_autosuspend(tctx->dev->dev);
}
struct rk_crypto_tmp rk_ahash_sha1 = {
......
......@@ -454,6 +454,7 @@ static int rk_ablk_init_tfm(struct crypto_skcipher *tfm)
struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
const char *name = crypto_tfm_alg_name(&tfm->base);
struct rk_crypto_tmp *algt;
int err;
algt = container_of(alg, struct rk_crypto_tmp, alg.skcipher);
......@@ -471,7 +472,14 @@ static int rk_ablk_init_tfm(struct crypto_skcipher *tfm)
ctx->enginectx.op.do_one_request = rk_cipher_run;
err = pm_runtime_resume_and_get(ctx->dev->dev);
if (err < 0)
goto error_pm;
return 0;
error_pm:
crypto_free_skcipher(ctx->fallback_tfm);
return err;
}
static void rk_ablk_exit_tfm(struct crypto_skcipher *tfm)
......@@ -480,6 +488,7 @@ static void rk_ablk_exit_tfm(struct crypto_skcipher *tfm)
memzero_explicit(ctx->key, ctx->keylen);
crypto_free_skcipher(ctx->fallback_tfm);
pm_runtime_put_autosuspend(ctx->dev->dev);
}
struct rk_crypto_tmp rk_ecb_aes_alg = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment