Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3513804pxb; Mon, 4 Apr 2022 19:27:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwr2JyFFV8NJq8IplXlJkwJoyL1UhavJqqmZkzYPzA8BeduK9OL9eR7CiTIO5DTZubKxBIz X-Received: by 2002:a17:90a:fe7:b0:1ca:c439:7241 with SMTP id 94-20020a17090a0fe700b001cac4397241mr1454060pjz.36.1649125640319; Mon, 04 Apr 2022 19:27:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649125640; cv=none; d=google.com; s=arc-20160816; b=WG4C+7ma7bKAKsoAmpTpfFnEJP5RbtqSbxRfhY123cPu32+IlWnBM79a8gpV8aUAXH UKu1nYeJ4rQ871EK8V/cdgjtsUhIw1N616giWxEYkdXbI2o2teNXYpezhAdPVFRTSw6W rzXZSKbItAHkbizmadUtL+bj3N0zJ6E43keCgHRe2prnbt4QJiLOM1Pov5OSCxTr+lHV 65WoWYmxBP8AOrDZH59DZFfhG/x+rT88oi3H+MkYF/lODJl+bHFAai1/ez7ne3eZFnMu z1K5nEvdr5fANbK6sRE+HzQKpqE1E53mWlYhhe8Y/fISQmlaViiVxFS6/B5BTYAq3Y1H GKMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xTqOlfauoDMfSsktjhcUkKoseBz3IdfqxDYnQJsUj0Y=; b=U0OzJ0+X9V2JXaLu9voSCpAEvyDth6p8PoVJCG5OdoED52oItt644R3jjcXo+2ZOTU +6ae5ViOLDFauj7hIpSgNBBybvnaiO0LyBbWj0+5c8iMAfZNm0JXOCmhUUt4KdSynhZP cHei1nmxbtgTC+fbGqhrOkc58e/L5sRjf000Lcie/cT6tDqsQK6Ulik9bQ/eVSn0Glga O53HnvMvlFq+HOOOvl4U83GWKukCt/K4TuU/DzOHfqJxWbX9uex5zBYvrv0m0IGAE2A3 rAkgSu8NBwnn7UA/WF/qIOQFSyF+teAQ3leGkBDyxqDs4TmdJyQcC5lyquWQNvndva/v TGjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=NFofBZET; spf=softfail (google.com: domain of transitioning linux-crypto-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y30-20020a056a001c9e00b004fa9a8cc0ccsi10286370pfw.100.2022.04.04.19.27.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 19:27:20 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-crypto-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=NFofBZET; spf=softfail (google.com: domain of transitioning linux-crypto-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E7781E0AF7; Mon, 4 Apr 2022 17:49:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352191AbiDAUUu (ORCPT + 99 others); Fri, 1 Apr 2022 16:20:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352068AbiDAUUY (ORCPT ); Fri, 1 Apr 2022 16:20:24 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51CA133E3C for ; Fri, 1 Apr 2022 13:18:21 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id u3so5810404wrg.3 for ; Fri, 01 Apr 2022 13:18:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xTqOlfauoDMfSsktjhcUkKoseBz3IdfqxDYnQJsUj0Y=; b=NFofBZETD7/ZI9ttHOYpu+qqFBIbShpTrhOQ11HMIMfxdQnROA3rRrkhL/41hBJW6g zdBVT+H62fWpENNc5sbPhFO9gHCAaFd1l3k87TU1Wur5TgRN67LQ6rNsNQad5GMewQAT RFAvyhFVA3cCUAjhQOG/XRbvXKdd7Vv4jM+ZnDy2iPDnEzmHIRWqYefVqlLzHHTAKctb jc+ZNXRxt+gi/OKWXuurr5CXlJD2z7+9OG3CUPSv29EcXwFkVJBOH8sy3SZlgxRpjhy7 SlJXJppHbSZe8r9WcsmlUpAbO35z8vfw8wszQcHBGR1AhhVvvqh6Oz8WFbMJ49uv2IpG QqCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xTqOlfauoDMfSsktjhcUkKoseBz3IdfqxDYnQJsUj0Y=; b=JfZKd55g2H72nY3C8CNy2lm5Mpi9AepmUjqouVSEqtLxND0DF7ftR2T5dkigxYcX7T wyR20QTihnOEiOYrTWWO4JWZ7D0vV8h62dzEehKw2vIe+gIwh+qYROAfBqEYnod5wJvz A8wb5CTfA8NiSUa2zz+7VPi9wZoZQTsnHmxFZO/DxQLUcJyOUb5mQq+tdYGFqDVlZul0 LvnVGCsDGjvjnl5qTpUi2UPIrM0zxq2yPkIJMf0531Yhc7vaa+8HtFnNBXBVZWXXzcH/ XosjsUfRsCbga8ITGSuYQ7tV1EogkcIHaAhioL2JxlaCpxcTGOFFNxUQ24g9PvT5XZvL y66Q== X-Gm-Message-State: AOAM531wqZtnb7UuRGKUhDXbcCiVkN8Vm8rm8o/+KMDIT1TZhKen8ziF 3tjMOWRHSGRgy8H1Vb+KdbEHmg== X-Received: by 2002:adf:eb88:0:b0:205:e113:dcb5 with SMTP id t8-20020adfeb88000000b00205e113dcb5mr8747955wrn.598.1648844300425; Fri, 01 Apr 2022 13:18:20 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id j16-20020a05600c191000b0038ca3500494sm17823838wmq.27.2022.04.01.13.18.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 13:18:20 -0700 (PDT) From: Corentin Labbe To: heiko@sntech.de, herbert@gondor.apana.org.au, krzk+dt@kernel.org, robh+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Corentin Labbe Subject: [PATCH v4 13/33] crypto: rockchip: introduce PM Date: Fri, 1 Apr 2022 20:17:44 +0000 Message-Id: <20220401201804.2867154-14-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220401201804.2867154-1-clabbe@baylibre.com> References: <20220401201804.2867154-1-clabbe@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Add runtime PM support for rockchip crypto. Signed-off-by: Corentin Labbe --- drivers/crypto/rockchip/rk3288_crypto.c | 51 ++++++++++++++++++- drivers/crypto/rockchip/rk3288_crypto.h | 1 + drivers/crypto/rockchip/rk3288_crypto_ahash.c | 10 ++++ .../crypto/rockchip/rk3288_crypto_skcipher.c | 9 ++++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/rockchip/rk3288_crypto.c b/drivers/crypto/rockchip/rk3288_crypto.c index 3e1b4f3b2422..d9258b9e71b3 100644 --- a/drivers/crypto/rockchip/rk3288_crypto.c +++ b/drivers/crypto/rockchip/rk3288_crypto.c @@ -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, }, }; diff --git a/drivers/crypto/rockchip/rk3288_crypto.h b/drivers/crypto/rockchip/rk3288_crypto.h index f85144e3d124..6a1f09d409bf 100644 --- a/drivers/crypto/rockchip/rk3288_crypto.h +++ b/drivers/crypto/rockchip/rk3288_crypto.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/crypto/rockchip/rk3288_crypto_ahash.c b/drivers/crypto/rockchip/rk3288_crypto_ahash.c index 8856c6226be6..137013bd4410 100644 --- a/drivers/crypto/rockchip/rk3288_crypto_ahash.c +++ b/drivers/crypto/rockchip/rk3288_crypto_ahash.c @@ -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 = { diff --git a/drivers/crypto/rockchip/rk3288_crypto_skcipher.c b/drivers/crypto/rockchip/rk3288_crypto_skcipher.c index 4ff08238156b..8d3a60db0cf6 100644 --- a/drivers/crypto/rockchip/rk3288_crypto_skcipher.c +++ b/drivers/crypto/rockchip/rk3288_crypto_skcipher.c @@ -466,6 +466,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); @@ -483,7 +484,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) @@ -492,6 +500,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 = { -- 2.35.1