From patchwork Mon Feb 21 07:59:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 12753213 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9787C433F5 for ; Mon, 21 Feb 2022 07:58:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346619AbiBUH6v (ORCPT ); Mon, 21 Feb 2022 02:58:51 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:47206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346646AbiBUH6s (ORCPT ); Mon, 21 Feb 2022 02:58:48 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD1262182B; Sun, 20 Feb 2022 23:58:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1645430305; x=1676966305; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bqtRma4i+aDRPSPwCrS3g3crpowmv6qvyEHjsN3/F0U=; b=t7kIxk8UyyEDmS2+H1u/S+SSLGjurHYFKn7CPX8eYCkyHzQQx3sT5hFq h4ZmJHSoQhMkSqwdfcEuycLpTTcLDp80OS/4DkevypJiN0EsMFGh64/ak i7dHgF7JapodbIuuzGGJDDNBiISMV6e2JfoaoPbgjxiXOa/os3XxwbjA6 vNY1Sxs6pmlsKW0p+gYxZXghWzkr6nsodUrKAR2zd3NuKma2cCN0lLg3l Gy8xrwq0v1NMrXmlhBJT5HK6e/dOAf8w8o7qkIf7Lh+63lRBfQJDH9V4R /zCZWKMfQH9jr6SFAi6Z/Cj23+lYXTQnw2uq6yCgvOZvDJe/tMk/gjryU Q==; X-IronPort-AV: E=Sophos;i="5.88,385,1635231600"; d="scan'208";a="86422606" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Feb 2022 00:58:24 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 21 Feb 2022 00:58:24 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 21 Feb 2022 00:58:22 -0700 From: Claudiu Beznea To: , , , CC: , , , Claudiu Beznea Subject: [PATCH v2 1/7] hwrng: atmel - add wait for ready support on read Date: Mon, 21 Feb 2022 09:59:22 +0200 Message-ID: <20220221075928.563806-2-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220221075928.563806-1-claudiu.beznea@microchip.com> References: <20220221075928.563806-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Add wait for ready support on read. Signed-off-by: Claudiu Beznea --- drivers/char/hw_random/atmel-rng.c | 43 +++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c index ecb71c4317a5..1a4874668c04 100644 --- a/drivers/char/hw_random/atmel-rng.c +++ b/drivers/char/hw_random/atmel-rng.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,7 @@ #define TRNG_CR 0x00 #define TRNG_MR 0x04 #define TRNG_ISR 0x1c +#define TRNG_ISR_DATRDY BIT(0) #define TRNG_ODATA 0x50 #define TRNG_KEY 0x524e4700 /* RNG */ @@ -36,25 +38,40 @@ struct atmel_trng { struct hwrng rng; }; +static bool atmel_trng_wait_ready(struct atmel_trng *trng, bool wait) +{ + int ready; + + ready = readl(trng->base + TRNG_ISR) & TRNG_ISR_DATRDY; + if (!ready && wait) + readl_poll_timeout(trng->base + TRNG_ISR, ready, + ready & TRNG_ISR_DATRDY, 1000, 20000); + + return !!ready; +} + static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max, bool wait) { struct atmel_trng *trng = container_of(rng, struct atmel_trng, rng); u32 *data = buf; + int ret; + + ret = atmel_trng_wait_ready(trng, wait); + if (!ret) + goto out; - /* data ready? */ - if (readl(trng->base + TRNG_ISR) & 1) { - *data = readl(trng->base + TRNG_ODATA); - /* - ensure data ready is only set again AFTER the next data - word is ready in case it got set between checking ISR - and reading ODATA, so we don't risk re-reading the - same word - */ - readl(trng->base + TRNG_ISR); - return 4; - } else - return 0; + *data = readl(trng->base + TRNG_ODATA); + /* + * ensure data ready is only set again AFTER the next data word is ready + * in case it got set between checking ISR and reading ODATA, so we + * don't risk re-reading the same word + */ + readl(trng->base + TRNG_ISR); + ret = 4; + +out: + return ret; } static void atmel_trng_enable(struct atmel_trng *trng) From patchwork Mon Feb 21 07:59:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 12753215 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63C34C433F5 for ; Mon, 21 Feb 2022 07:58:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346655AbiBUH6z (ORCPT ); Mon, 21 Feb 2022 02:58:55 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346627AbiBUH6w (ORCPT ); Mon, 21 Feb 2022 02:58:52 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17AEF267B; Sun, 20 Feb 2022 23:58:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1645430309; x=1676966309; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=x4B8RAQ+sONeCB93qo7wNP3O6nHHIZlxDecPSenuJqU=; b=cF1S5pW+OZVza5zKHEE9rTVOKKu9FVYBrYS3uF+aQPoeC5fWmG95PJSx Y7jIFQxYLzfHkpsOTEwJ0ngqtnsKBKxviPqIH19HqnnfkSztIF/gcAyAQ Wfa+xGxKEnXp7Y8hS517xvO7EUrlsFk/v86h2CRjjr2fYvJXdCj2pP9f+ +rsRQdCDTBNOO5t/lOPF09lKZx7qcmlCwj+GKAat5TYleQwFUKuNHFMUa JRB2dcAIL8F0YC7wWQxxF9oUmn+M291eHl8rJw+sQtapEA8zHpRzmuWU4 7jqw+UUL8ao50SIvdgs4G0q9AyYMNaCTIzxP5XEi0lKFRJbFRJJ8vw22A Q==; X-IronPort-AV: E=Sophos;i="5.88,385,1635231600"; d="scan'208";a="86422618" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Feb 2022 00:58:27 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 21 Feb 2022 00:58:26 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 21 Feb 2022 00:58:24 -0700 From: Claudiu Beznea To: , , , CC: , , , Claudiu Beznea Subject: [PATCH v2 2/7] hwrng: atmel - disable trng on failure path Date: Mon, 21 Feb 2022 09:59:23 +0200 Message-ID: <20220221075928.563806-3-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220221075928.563806-1-claudiu.beznea@microchip.com> References: <20220221075928.563806-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Call atmel_trng_disable() on failure path of probe. Fixes: a1fa98d8116f ("hwrng: atmel - disable TRNG during suspend") Signed-off-by: Claudiu Beznea --- drivers/char/hw_random/atmel-rng.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c index 1a4874668c04..b7ef951927fb 100644 --- a/drivers/char/hw_random/atmel-rng.c +++ b/drivers/char/hw_random/atmel-rng.c @@ -131,6 +131,7 @@ static int atmel_trng_probe(struct platform_device *pdev) err_register: clk_disable_unprepare(trng->clk); + atmel_trng_disable(trng); return ret; } From patchwork Mon Feb 21 07:59:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 12753216 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0BD5C433EF for ; Mon, 21 Feb 2022 07:58:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346668AbiBUH65 (ORCPT ); Mon, 21 Feb 2022 02:58:57 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346650AbiBUH6z (ORCPT ); Mon, 21 Feb 2022 02:58:55 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 756CB270F; Sun, 20 Feb 2022 23:58:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1645430310; x=1676966310; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jsWxgS54TLuyrZok7rycmGN8GjwhZu+4iH1IkWMXxMw=; b=XPvKKsgvULHqwCyrrQ2vB32IRpfgOjEHuso2rJEBhF/XZZWo4d0QfDlA IM+ChZQNq+lXOP0kwQVKV4sFMFzXbVAcXrYsIvXZwOhlOQXhGGGYUVseh AmLlQ5RqcgJHmTqxxH9RIXx4SAMXNlAR+kJxOLk/cJykLkKHpWDJcWW8g 6PR5njHYjAh+SKh6sF4sfVVmMDv1W6UwrC2sxKnsi5VDmjTXhGTOgomwq fBGdKGdlYpIuOOPXykqO8kapWSb5225S6TV5Lzu3l5C74mVZB0w82Kjsx NUfgjazC4XDYfie9aeggh9O99bdIUg8L4v47dcQVOBvUmlMEjoJIrI63y w==; X-IronPort-AV: E=Sophos;i="5.88,385,1635231600"; d="scan'208";a="149399838" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Feb 2022 00:58:29 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 21 Feb 2022 00:58:29 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 21 Feb 2022 00:58:27 -0700 From: Claudiu Beznea To: , , , CC: , , , Claudiu Beznea Subject: [PATCH v2 3/7] hwrng: atmel - rename enable/disable functions to init/cleanup Date: Mon, 21 Feb 2022 09:59:24 +0200 Message-ID: <20220221075928.563806-4-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220221075928.563806-1-claudiu.beznea@microchip.com> References: <20220221075928.563806-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org s/atmel_trng_disable/atmel_trng_cleanup/g and s/atmel_trng_enable/atmel_trng_init/g to cope with struct hwrng::{init, cleanup} members. Signed-off-by: Claudiu Beznea --- drivers/char/hw_random/atmel-rng.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c index b7ef951927fb..17f02049c112 100644 --- a/drivers/char/hw_random/atmel-rng.c +++ b/drivers/char/hw_random/atmel-rng.c @@ -74,12 +74,12 @@ static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max, return ret; } -static void atmel_trng_enable(struct atmel_trng *trng) +static void atmel_trng_init(struct atmel_trng *trng) { writel(TRNG_KEY | 1, trng->base + TRNG_CR); } -static void atmel_trng_disable(struct atmel_trng *trng) +static void atmel_trng_cleanup(struct atmel_trng *trng) { writel(TRNG_KEY, trng->base + TRNG_CR); } @@ -117,7 +117,7 @@ static int atmel_trng_probe(struct platform_device *pdev) if (ret) return ret; - atmel_trng_enable(trng); + atmel_trng_init(trng); trng->rng.name = pdev->name; trng->rng.read = atmel_trng_read; @@ -131,7 +131,7 @@ static int atmel_trng_probe(struct platform_device *pdev) err_register: clk_disable_unprepare(trng->clk); - atmel_trng_disable(trng); + atmel_trng_cleanup(trng); return ret; } @@ -140,7 +140,7 @@ static int atmel_trng_remove(struct platform_device *pdev) struct atmel_trng *trng = platform_get_drvdata(pdev); - atmel_trng_disable(trng); + atmel_trng_cleanup(trng); clk_disable_unprepare(trng->clk); return 0; @@ -151,7 +151,7 @@ static int atmel_trng_suspend(struct device *dev) { struct atmel_trng *trng = dev_get_drvdata(dev); - atmel_trng_disable(trng); + atmel_trng_cleanup(trng); clk_disable_unprepare(trng->clk); return 0; @@ -166,7 +166,7 @@ static int atmel_trng_resume(struct device *dev) if (ret) return ret; - atmel_trng_enable(trng); + atmel_trng_init(trng); return 0; } From patchwork Mon Feb 21 07:59:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 12753217 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC1D1C433EF for ; Mon, 21 Feb 2022 07:58:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346665AbiBUH7B (ORCPT ); Mon, 21 Feb 2022 02:59:01 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346664AbiBUH64 (ORCPT ); Mon, 21 Feb 2022 02:58:56 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B66A511A2F; Sun, 20 Feb 2022 23:58:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1645430312; x=1676966312; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9DmYH6VExId9ntaWhJNRnc2b1ZNu8Cgo16IxS2usahI=; b=XeiomlDADzcl3jK86uIIsP5NIGqwc/Fa0CYw+1f4MMe0dd2dn8KETV/w 98yWlG0ICrjgPbfAxEt0i4HsaYvH2dMqpNQFjMEUAhoxKluFQGZLN+R8H OQQ1KMMZ2P5mzAc7hgbWfyy96zV4CQnThBJ9K8cRmCBsxNfjiiX7wHwsQ PztUXJ/GwXXTFTCkOhxEfqtjW2iz8OQSTlMTNS2THS0jjEgwDnx/SthNW 82XVeGZdJUNgOfD7UCFJDV94G2Km77aahg7NrtRZBtxLxXIQONCfTxsZh kIUyp2fR7E9rfVPh1paN5nn7YK+9TW6VK5PaI3HKhaOu90f2cBo9qvlNV A==; X-IronPort-AV: E=Sophos;i="5.88,385,1635231600"; d="scan'208";a="86422656" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Feb 2022 00:58:31 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 21 Feb 2022 00:58:31 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 21 Feb 2022 00:58:29 -0700 From: Claudiu Beznea To: , , , CC: , , , Claudiu Beznea Subject: [PATCH v2 4/7] hwrng: atmel - move set of TRNG_HALFR in atmel_trng_init() Date: Mon, 21 Feb 2022 09:59:25 +0200 Message-ID: <20220221075928.563806-5-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220221075928.563806-1-claudiu.beznea@microchip.com> References: <20220221075928.563806-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Move set of TRNG_HALFR in atmel_trng_init() as this function is also called on resume path. In case of SAMA7G5 where backup and self-refresh PM mode is available most of the SoC parts are powered of (including TRNG) when entering suspend. In that case on resuming path TRNG_HALFR should also be re-configured. Signed-off-by: Claudiu Beznea --- drivers/char/hw_random/atmel-rng.c | 49 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c index 17f02049c112..ef49dbe681cf 100644 --- a/drivers/char/hw_random/atmel-rng.c +++ b/drivers/char/hw_random/atmel-rng.c @@ -36,6 +36,7 @@ struct atmel_trng { struct clk *clk; void __iomem *base; struct hwrng rng; + bool has_half_rate; }; static bool atmel_trng_wait_ready(struct atmel_trng *trng, bool wait) @@ -74,14 +75,32 @@ static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max, return ret; } -static void atmel_trng_init(struct atmel_trng *trng) +static int atmel_trng_init(struct atmel_trng *trng) { + unsigned long rate; + int ret; + + ret = clk_prepare_enable(trng->clk); + if (ret) + return ret; + + if (trng->has_half_rate) { + rate = clk_get_rate(trng->clk); + + /* if peripheral clk is above 100MHz, set HALFR */ + if (rate > 100000000) + writel(TRNG_HALFR, trng->base + TRNG_MR); + } + writel(TRNG_KEY | 1, trng->base + TRNG_CR); + + return 0; } static void atmel_trng_cleanup(struct atmel_trng *trng) { writel(TRNG_KEY, trng->base + TRNG_CR); + clk_disable_unprepare(trng->clk); } static int atmel_trng_probe(struct platform_device *pdev) @@ -105,22 +124,14 @@ static int atmel_trng_probe(struct platform_device *pdev) if (!data) return -ENODEV; - if (data->has_half_rate) { - unsigned long rate = clk_get_rate(trng->clk); - - /* if peripheral clk is above 100MHz, set HALFR */ - if (rate > 100000000) - writel(TRNG_HALFR, trng->base + TRNG_MR); - } + trng->has_half_rate = data->has_half_rate; + trng->rng.name = pdev->name; + trng->rng.read = atmel_trng_read; - ret = clk_prepare_enable(trng->clk); + ret = atmel_trng_init(trng); if (ret) return ret; - atmel_trng_init(trng); - trng->rng.name = pdev->name; - trng->rng.read = atmel_trng_read; - ret = devm_hwrng_register(&pdev->dev, &trng->rng); if (ret) goto err_register; @@ -130,7 +141,6 @@ static int atmel_trng_probe(struct platform_device *pdev) return 0; err_register: - clk_disable_unprepare(trng->clk); atmel_trng_cleanup(trng); return ret; } @@ -141,7 +151,6 @@ static int atmel_trng_remove(struct platform_device *pdev) atmel_trng_cleanup(trng); - clk_disable_unprepare(trng->clk); return 0; } @@ -152,7 +161,6 @@ static int atmel_trng_suspend(struct device *dev) struct atmel_trng *trng = dev_get_drvdata(dev); atmel_trng_cleanup(trng); - clk_disable_unprepare(trng->clk); return 0; } @@ -160,15 +168,8 @@ static int atmel_trng_suspend(struct device *dev) static int atmel_trng_resume(struct device *dev) { struct atmel_trng *trng = dev_get_drvdata(dev); - int ret; - ret = clk_prepare_enable(trng->clk); - if (ret) - return ret; - - atmel_trng_init(trng); - - return 0; + return atmel_trng_init(trng); } static const struct dev_pm_ops atmel_trng_pm_ops = { From patchwork Mon Feb 21 07:59:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 12753218 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C53FBC433F5 for ; Mon, 21 Feb 2022 07:58:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346652AbiBUH7C (ORCPT ); Mon, 21 Feb 2022 02:59:02 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346657AbiBUH65 (ORCPT ); Mon, 21 Feb 2022 02:58:57 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1A01270F; Sun, 20 Feb 2022 23:58:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1645430314; x=1676966314; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NZ+azJ3C6NsQmXfKrlNJXfCNh4CtclKSN1p9C0K3pXE=; b=t0IhatE/ypDz1TXZ5rWJUHzB0F72sRlps4/1UeirBrQBn8Ij7nms3Uef zjt6BRKSE7945KR5fa0hHbSM+17ZvwkFH5rDY653Fyd0NKSvctAw1wwgu yo8T0inDEtXQ5aKSEhlHc//jM6yEDieqZzUVM5GK1uwqL2RmqsD7ypj6d yqlOPKDf8pZl7OSs26FwFm6sJ5qUJFnR9kZBVrMDGbT+e7YiPxpv4ho0y vywa/lIo9p+GkSgrw3/DCdsmVqW5g2BqktzBw87PBoLvjYOM1X+S+UAk6 MpA77eyaQWM8xNSKq6qN5E2iPbglF/GLGFOL5pxUReN++I53gTN7Mbz/B w==; X-IronPort-AV: E=Sophos;i="5.88,385,1635231600"; d="scan'208";a="149399845" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Feb 2022 00:58:34 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 21 Feb 2022 00:58:34 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 21 Feb 2022 00:58:32 -0700 From: Claudiu Beznea To: , , , CC: , , , Claudiu Beznea Subject: [PATCH v2 5/7] hwrng: atmel - use __maybe_unused and pm_ptr() for pm ops Date: Mon, 21 Feb 2022 09:59:26 +0200 Message-ID: <20220221075928.563806-6-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220221075928.563806-1-claudiu.beznea@microchip.com> References: <20220221075928.563806-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use __maybe_unused and pm_ptr() for pm ops. Signed-off-by: Claudiu Beznea --- drivers/char/hw_random/atmel-rng.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c index ef49dbe681cf..0fff74808472 100644 --- a/drivers/char/hw_random/atmel-rng.c +++ b/drivers/char/hw_random/atmel-rng.c @@ -155,8 +155,7 @@ static int atmel_trng_remove(struct platform_device *pdev) return 0; } -#ifdef CONFIG_PM -static int atmel_trng_suspend(struct device *dev) +static int __maybe_unused atmel_trng_suspend(struct device *dev) { struct atmel_trng *trng = dev_get_drvdata(dev); @@ -165,18 +164,17 @@ static int atmel_trng_suspend(struct device *dev) return 0; } -static int atmel_trng_resume(struct device *dev) +static int __maybe_unused atmel_trng_resume(struct device *dev) { struct atmel_trng *trng = dev_get_drvdata(dev); return atmel_trng_init(trng); } -static const struct dev_pm_ops atmel_trng_pm_ops = { +static const struct dev_pm_ops __maybe_unused atmel_trng_pm_ops = { .suspend = atmel_trng_suspend, .resume = atmel_trng_resume, }; -#endif /* CONFIG_PM */ static const struct atmel_trng_data at91sam9g45_config = { .has_half_rate = false, @@ -204,9 +202,7 @@ static struct platform_driver atmel_trng_driver = { .remove = atmel_trng_remove, .driver = { .name = "atmel-trng", -#ifdef CONFIG_PM - .pm = &atmel_trng_pm_ops, -#endif /* CONFIG_PM */ + .pm = pm_ptr(&atmel_trng_pm_ops), .of_match_table = atmel_trng_dt_ids, }, }; From patchwork Mon Feb 21 07:59:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 12753219 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C2E4C433F5 for ; Mon, 21 Feb 2022 07:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346650AbiBUH7F (ORCPT ); Mon, 21 Feb 2022 02:59:05 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346679AbiBUH7A (ORCPT ); Mon, 21 Feb 2022 02:59:00 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 793562182A; Sun, 20 Feb 2022 23:58:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1645430317; x=1676966317; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hXm0Jtwri1nLMNu8938lMqvk/Ro4GDt9J9rutPzfAFk=; b=GPj5uK+AEnS4W0nevf/WEMoLxkdK7OdLKd9beuXkyQZlEiGJhP6GFVPU 9J3/nFsOI3WELeiId6/aiwbpbUOr8VdALbQppo2XeZjGuKASR2CnsSrHx cVawkQ3TpM+Vm7rmTGfpc5rqIE9uYmAX5XEXN9Xaubd1S9F5zcCn7Xzex XuVYl7ZcksCWEX4e/xKGBLee0AiTMruX6yUiPC3hvYojuUqEs9Tsuwn5l 2fmSd2Xs6CXcS69AFc1deaq6dHGgLy9797pyDW480DPFE3h6KPl52F9le RTiDHmIaBvCbBQApj7p72TxxW81m0k5MBbCcUdd++8x3gqQweYIkiyf9e g==; X-IronPort-AV: E=Sophos;i="5.88,385,1635231600"; d="scan'208";a="149399849" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Feb 2022 00:58:37 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 21 Feb 2022 00:58:36 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 21 Feb 2022 00:58:34 -0700 From: Claudiu Beznea To: , , , CC: , , , Claudiu Beznea Subject: [PATCH v2 6/7] hwrng: atmel - add runtime pm support Date: Mon, 21 Feb 2022 09:59:27 +0200 Message-ID: <20220221075928.563806-7-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220221075928.563806-1-claudiu.beznea@microchip.com> References: <20220221075928.563806-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Add runtime PM support. Signed-off-by: Claudiu Beznea --- 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 #include #include +#include #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 = { From patchwork Mon Feb 21 07:59:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 12753220 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04FACC433EF for ; Mon, 21 Feb 2022 07:58:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346661AbiBUH7R (ORCPT ); Mon, 21 Feb 2022 02:59:17 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346692AbiBUH7D (ORCPT ); Mon, 21 Feb 2022 02:59:03 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE5E217AAE; Sun, 20 Feb 2022 23:58:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1645430320; x=1676966320; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S+uT64mp+Afl3y2BOOq/0yNH7TCGPfhkbQO12u0O5o8=; b=W6YhCDossGJiPoV2CdpM5i5vLn5AfO0kyNb949mhWoh4SE6HI0tumhrl 78a3jm8RB2psbChpwjf3rWi3hoaBiJcPxjuFbg10tIAFZ6GeQoONy1+6N KesibKxCvTWHI0jFtq0RyUpiEAHgp/jrs2kA+NSOM3/6IcJGncmb5EL+Z Z/ZHdLnyUtyW0hrxs6MbqULOYbSovwQcHP+at7RiGcbYycK02a4JSmN1m h3KAtL8SKWcCHmTm2ud7kl9t4+d4RSa5DutVCpCl7NP2DsONIKtvqZ+R1 euLvg6HbtGu18QfyZdjbWVGhb6vJ2vG0my4x6w7OK0rsXSZhEdD2qBTX7 A==; X-IronPort-AV: E=Sophos;i="5.88,385,1635231600"; d="scan'208";a="86422687" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Feb 2022 00:58:39 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 21 Feb 2022 00:58:39 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 21 Feb 2022 00:58:37 -0700 From: Claudiu Beznea To: , , , CC: , , , Claudiu Beznea Subject: [PATCH v2 7/7] hwrng: atmel - remove extra line Date: Mon, 21 Feb 2022 09:59:28 +0200 Message-ID: <20220221075928.563806-8-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220221075928.563806-1-claudiu.beznea@microchip.com> References: <20220221075928.563806-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Remove extra line. Signed-off-by: Claudiu Beznea --- drivers/char/hw_random/atmel-rng.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c index b662d44a09a6..b8effe77d80f 100644 --- a/drivers/char/hw_random/atmel-rng.c +++ b/drivers/char/hw_random/atmel-rng.c @@ -165,7 +165,6 @@ static int atmel_trng_remove(struct platform_device *pdev) { struct atmel_trng *trng = platform_get_drvdata(pdev); - atmel_trng_cleanup(trng); pm_runtime_disable(&pdev->dev); pm_runtime_set_suspended(&pdev->dev);