Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp5096685imm; Tue, 26 Jun 2018 05:58:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeu21NUpcgM00ccWW/AGYhBsnDUDgASIO0jtyLW9vVa3pZ40DBtlNbVBfSdcUUtYguf3ghE X-Received: by 2002:a63:9a52:: with SMTP id e18-v6mr403937pgo.188.1530017884845; Tue, 26 Jun 2018 05:58:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530017884; cv=none; d=google.com; s=arc-20160816; b=BSxgzvD/DhwTQlvEjVjAxg00RsDq30q5b44pgi3wWcJL6bgNIEwwqu3vFq6b0c2gxA vYyJL4ixmgV8N9aHPgSGAq4qvo/EVyCCg1nOAWPH2eL+JttqSlf3aquXH1tBrK3HBM+w wiPvSMugaTCaNDgvnPBZyvGex9XYdC8gLpqj8fWDbk9ZykPbirzpPX2Goi+DQ9wAXjf+ h9PGL5hfFvC6TFQzMZ1vHBzbQOe9PPOQsHZovHsb0DqddHgtK+n+yz7sVZwyXybWjHfW 91N9klwEcggmg5bdApeo47ck/rwBXFT2EhyXip6GvXZMGRv48OzgeN9Wr/v/MfQjJvQl 2w4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=tA5BxMzrXKCBA0xGkU3uWRTfjlIoN9DKqLcb3bzd8hM=; b=BtVTiTNMPObrqFym/V+/cFSLMUf706zPVujIfbrGAoyIeqPoDLwRulca3l5Z7TO/az EB1ggjG735OS9IMJenL5INBbgUBbAl09hy/7/Yd6Ruw90anZ7QmMvO2Jw1BCRjD2wP4Z 2UQ7SK6UuPrs3I/wvg14X8za7wyb6dCmfR2ST/9qESsTUiqjWGPvrAXoOlBAT7Kw8MpX u9ENBhUC8cWlfDboo6lzXmuLHit6qCqBP9hI5UwFefL0UMIfAUlewZz0QIYSVbCTnniS pOllNPMlUA9GOzJZrNSM3iWsL5AvlmgCy0dKDugKVc6c81B9DXIzdoWwjJzU5BeycmCW yXLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a26-v6si1433085pfn.281.2018.06.26.05.57.50; Tue, 26 Jun 2018 05:58:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965242AbeFZMzo (ORCPT + 99 others); Tue, 26 Jun 2018 08:55:44 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:55453 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965028AbeFZMzD (ORCPT ); Tue, 26 Jun 2018 08:55:03 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w5QCsQvb005725; Tue, 26 Jun 2018 14:54:31 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2jumuy8bvk-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 26 Jun 2018 14:54:31 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7CC1731; Tue, 26 Jun 2018 12:54:30 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 587C52A30; Tue, 26 Jun 2018 12:54:30 +0000 (GMT) Received: from SAFEX1HUBCAS22.st.com (10.75.90.93) by SAFEX1HUBCAS21.st.com (10.75.90.44) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 26 Jun 2018 14:54:30 +0200 Received: from localhost (10.201.23.65) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 26 Jun 2018 14:54:28 +0200 From: Lionel Debieve To: Herbert Xu , "David S . Miller" , Maxime Coquelin , "Alexandre Torgue" , , , CC: Benjamin Gaignard , Fabien Dessenne , Ludovic Barre Subject: [PATCH 1/3] crypto: stm32/cryp - Add power management support Date: Tue, 26 Jun 2018 14:52:44 +0200 Message-ID: <1530017566-14779-2-git-send-email-lionel.debieve@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530017566-14779-1-git-send-email-lionel.debieve@st.com> References: <1530017566-14779-1-git-send-email-lionel.debieve@st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.201.23.65] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-26_07:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding pm and pm_runtime support to STM32 CRYP. Signed-off-by: Lionel Debieve --- drivers/crypto/stm32/stm32-cryp.c | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/crypto/stm32/stm32-cryp.c b/drivers/crypto/stm32/stm32-cryp.c index c5d3efc..23b0b7b 100644 --- a/drivers/crypto/stm32/stm32-cryp.c +++ b/drivers/crypto/stm32/stm32-cryp.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -105,6 +106,7 @@ #define GCM_CTR_INIT 2 #define _walked_in (cryp->in_walk.offset - cryp->in_sg->offset) #define _walked_out (cryp->out_walk.offset - cryp->out_sg->offset) +#define CRYP_AUTOSUSPEND_DELAY 50 struct stm32_cryp_caps { bool swap_final; @@ -519,6 +521,8 @@ static int stm32_cryp_hw_init(struct stm32_cryp *cryp) int ret; u32 cfg, hw_mode; + pm_runtime_get_sync(cryp->dev); + /* Disable interrupt */ stm32_cryp_write(cryp, CRYP_IMSCR, 0); @@ -638,6 +642,9 @@ static void stm32_cryp_finish_req(struct stm32_cryp *cryp, int err) free_pages((unsigned long)buf_out, pages); } + pm_runtime_mark_last_busy(cryp->dev); + pm_runtime_put_autosuspend(cryp->dev); + if (is_gcm(cryp) || is_ccm(cryp)) { crypto_finalize_aead_request(cryp->engine, cryp->areq, err); cryp->areq = NULL; @@ -1969,6 +1976,13 @@ static int stm32_cryp_probe(struct platform_device *pdev) return ret; } + pm_runtime_set_autosuspend_delay(dev, CRYP_AUTOSUSPEND_DELAY); + pm_runtime_use_autosuspend(dev); + + pm_runtime_get_noresume(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + rst = devm_reset_control_get(dev, NULL); if (!IS_ERR(rst)) { reset_control_assert(rst); @@ -2008,6 +2022,8 @@ static int stm32_cryp_probe(struct platform_device *pdev) dev_info(dev, "Initialized\n"); + pm_runtime_put_sync(dev); + return 0; err_aead_algs: @@ -2020,6 +2036,11 @@ static int stm32_cryp_probe(struct platform_device *pdev) list_del(&cryp->list); spin_unlock(&cryp_list.lock); + pm_runtime_disable(dev); + pm_runtime_put_noidle(dev); + pm_runtime_disable(dev); + pm_runtime_put_noidle(dev); + clk_disable_unprepare(cryp->clk); return ret; @@ -2028,10 +2049,15 @@ static int stm32_cryp_probe(struct platform_device *pdev) static int stm32_cryp_remove(struct platform_device *pdev) { struct stm32_cryp *cryp = platform_get_drvdata(pdev); + int ret; if (!cryp) return -ENODEV; + ret = pm_runtime_get_sync(cryp->dev); + if (ret < 0) + return ret; + crypto_unregister_aeads(aead_algs, ARRAY_SIZE(aead_algs)); crypto_unregister_algs(crypto_algs, ARRAY_SIZE(crypto_algs)); @@ -2041,16 +2067,52 @@ static int stm32_cryp_remove(struct platform_device *pdev) list_del(&cryp->list); spin_unlock(&cryp_list.lock); + pm_runtime_disable(cryp->dev); + pm_runtime_put_noidle(cryp->dev); + + clk_disable_unprepare(cryp->clk); + + return 0; +} + +#ifdef CONFIG_PM +static int stm32_cryp_runtime_suspend(struct device *dev) +{ + struct stm32_cryp *cryp = dev_get_drvdata(dev); + clk_disable_unprepare(cryp->clk); return 0; } +static int stm32_cryp_runtime_resume(struct device *dev) +{ + struct stm32_cryp *cryp = dev_get_drvdata(dev); + int ret; + + ret = clk_prepare_enable(cryp->clk); + if (ret) { + dev_err(cryp->dev, "Failed to prepare_enable clock\n"); + return ret; + } + + return 0; +} +#endif + +static const struct dev_pm_ops stm32_cryp_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) + SET_RUNTIME_PM_OPS(stm32_cryp_runtime_suspend, + stm32_cryp_runtime_resume, NULL) +}; + static struct platform_driver stm32_cryp_driver = { .probe = stm32_cryp_probe, .remove = stm32_cryp_remove, .driver = { .name = DRIVER_NAME, + .pm = &stm32_cryp_pm_ops, .of_match_table = stm32_dt_ids, }, }; -- 2.7.4