From patchwork Tue Jul 4 17:32:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 115877 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp1379665vqx; Tue, 4 Jul 2023 10:54:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5gUR3IeIAENEnTfCsHqcX6do7qkn5YH08dhWn0uG6tc+s5aqWgck+6ddI3hPrzyVEDiNfX X-Received: by 2002:a05:6a00:1388:b0:668:93e7:6800 with SMTP id t8-20020a056a00138800b0066893e76800mr29719147pfg.14.1688493265740; Tue, 04 Jul 2023 10:54:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688493265; cv=none; d=google.com; s=arc-20160816; b=dqIQ0crkQ92k1hsHNuqs5ElabXXaQnJqsnpisihyZsrl3zAtjHANenMlClC8O3KE5f DB/izeMH5ifzwE1eg8F76ccR6G0slQ4BcUNzAfDj5TmrWEpkQJsafSDAeQwMXefqDOtX 5b2GMMAbRRIhxHKOoDJh3i3EN2aX5BmmolnHYtxVSOyrtScqNKe0DO3IE3fsSQVznnYZ GhY8yjsWUwgwIh4wlyGAhMFLmf+ZSb+wcrzv9Gaa3EfWEEmXIeVgLgzCvMCjIs+Se6gZ DR1LxuLif9Nf9rAZYEPObABzp0Y0+R0z0VbqCV5d6Na2K98FhJHGFxg1AB2q84re/EVC r8Sw== 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; bh=OpZ3Py3qQKJXTft05nBa8mtwwAmFX1FhU4euydippNk=; fh=lO4wmMQhvm8y/jaHDv9dt1CS5yb5ZTFKyt5xlt/d/d8=; b=wybdEhOlml2fSOd9eI1Cnz0yuL9NQ9aH3bQE8iziGzp16ka0iYt/58SqXwoNMIM0yN aE0XO//xL2+zUGmnm9yttzkusnnk0UQr+WhA5gnL6SN2zMKm/CFwBig0TrSht1a6BUFh b5/CDoLuffK6taYS3GPjku8bDgYr/CkgCWOfUuewEw2sYFSke9vcbc0qMwqRYlKwmc/u uVch1rwxYYOCeFisSALPLLnm2GXdU7XpYzadzI1veokJCWKmPrMeoUDmcay+mBym6pTZ DmvGaoaWrM6BVDbS/hZLgmCEQayiMx+79iUJiDgFFF5l2X8r7NuOnjqagI5N/bKtVBXk lemw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m18-20020a056a00081200b006829f1e5164si3593177pfk.118.2023.07.04.10.54.11; Tue, 04 Jul 2023 10:54:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231688AbjGDRdx (ORCPT + 99 others); Tue, 4 Jul 2023 13:33:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231453AbjGDRdv (ORCPT ); Tue, 4 Jul 2023 13:33:51 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DF6D10D7; Tue, 4 Jul 2023 10:33:50 -0700 (PDT) Received: from ipservice-092-217-072-126.092.217.pools.vodafone-ip.de ([92.217.72.126] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1qGjuN-0000yT-KH; Tue, 04 Jul 2023 19:33:47 +0200 From: Martin Kaiser To: Herbert Xu Cc: Joshua Henderson , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH 1/4] hwrng: pic32 - enable compile-testing Date: Tue, 4 Jul 2023 19:32:00 +0200 Message-Id: <20230704173203.70706-2-martin@kaiser.cx> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230704173203.70706-1-martin@kaiser.cx> References: <20230704173203.70706-1-martin@kaiser.cx> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770513514757711623?= X-GMAIL-MSGID: =?utf-8?q?1770513514757711623?= Enable compile testing for the pic32 driver. Remove the dependency on HW_RANDOM. The pic32 config section is under "if HW_RANDOM". Signed-off-by: Martin Kaiser --- drivers/char/hw_random/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index e0b3786ca51b..1aeba12391a1 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig @@ -385,7 +385,7 @@ config HW_RANDOM_STM32 config HW_RANDOM_PIC32 tristate "Microchip PIC32 Random Number Generator support" - depends on HW_RANDOM && MACH_PIC32 + depends on MACH_PIC32 || COMPILE_TEST default y help This driver provides kernel-side support for the Random Number From patchwork Tue Jul 4 17:32:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 115881 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp1386989vqx; Tue, 4 Jul 2023 11:07:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlGeSH109UcciejAlZ943qAi0HAKJKq77Uv51T9IaU9CLeSK21TWdiyQhvb5d4dk2qEq8cpL X-Received: by 2002:a17:902:da92:b0:1b3:b3c5:1d1f with SMTP id j18-20020a170902da9200b001b3b3c51d1fmr12817625plx.8.1688494076052; Tue, 04 Jul 2023 11:07:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688494076; cv=none; d=google.com; s=arc-20160816; b=x0/3mmEfnbkTrF7cbfv/eC5i2Fjffc4rngIbZxdtn1HOlezte3l59GJKfy6LxiW1Hy EI8QPc9avmSLoxi22kdf+pn1TL8PDmZ+4KylMJrZ4T7RZPyP80viC8UCpYeSRPDBfESp WpvtorWyeuEq9rxuKKBOKN1tVJWnT6CvFDsa43apGOKf9YdARbLdd6cQtnELTni2TAFI KxMpCDYKGsA5vdxmvs5FSFNak7uujdy81JQezULNy9ExOZkY9tQCHQNGAfffKOC7/UHL POoR7Tv9QH8GXWVsyeqvNd3AuJfTsoBD0RPr4e7vTqwKRbufaaKIxW/qyXj7Vufb4G3V q/lQ== 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; bh=yW1T5aVd81nPIOIoHH4RxZnIfjzCSw0xd9QOOcaTaBg=; fh=lO4wmMQhvm8y/jaHDv9dt1CS5yb5ZTFKyt5xlt/d/d8=; b=GJOtsdMcWq2izEOdkgkMNRtwPknC1PJsJHR3sC/2fpK9x9M1RXE2B7ySxK+q1WM0l1 nvQQhdckpSjYAyWVLOfsPPutco0dds8vg80dulLKvCHEQYEKqE/Uvbh4o2Y3AKtKOGgz Sg5Ns8c25lwWayzO5aoFgVAOZLi+UjPpnaPZTA4Ip8YRNe2ztd8r3+5ttbZy1B4nIzDB kWdrqTRkQnfO8h7/3lxoFghrxEMYOTP7Zw1kgLzcWhkg+yx5SddKa1J78a/ojVa74B/t yaSl/kRM71uVSA61iUtGDh30ONHPH6Gag5hkMBVE+GvMNA4VRo4JaY77SETQOtntkBbB 7JVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jj13-20020a170903048d00b001b89baba4f6si4079238plb.408.2023.07.04.11.07.42; Tue, 04 Jul 2023 11:07:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231731AbjGDRdz (ORCPT + 99 others); Tue, 4 Jul 2023 13:33:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231642AbjGDRdw (ORCPT ); Tue, 4 Jul 2023 13:33:52 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A34910D5; Tue, 4 Jul 2023 10:33:51 -0700 (PDT) Received: from ipservice-092-217-072-126.092.217.pools.vodafone-ip.de ([92.217.72.126] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1qGjuO-0000yT-DV; Tue, 04 Jul 2023 19:33:48 +0200 From: Martin Kaiser To: Herbert Xu Cc: Joshua Henderson , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH 2/4] hwrng: pic32 - use devm_clk_get_enabled Date: Tue, 4 Jul 2023 19:32:01 +0200 Message-Id: <20230704173203.70706-3-martin@kaiser.cx> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230704173203.70706-1-martin@kaiser.cx> References: <20230704173203.70706-1-martin@kaiser.cx> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770514364301189332?= X-GMAIL-MSGID: =?utf-8?q?1770514364301189332?= Use devm_clk_get_enabled in the pic32 driver. Ensure that the clock is enabled as long as the driver is registered with the hwrng core. Fixes: 7ea39973d1e5 ("hwrng: pic32 - Use device-managed registration API") Signed-off-by: Martin Kaiser --- drivers/char/hw_random/pic32-rng.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/drivers/char/hw_random/pic32-rng.c b/drivers/char/hw_random/pic32-rng.c index 99c8bd0859a1..e04a054e8930 100644 --- a/drivers/char/hw_random/pic32-rng.c +++ b/drivers/char/hw_random/pic32-rng.c @@ -36,7 +36,6 @@ struct pic32_rng { void __iomem *base; struct hwrng rng; - struct clk *clk; }; /* @@ -70,6 +69,7 @@ static int pic32_rng_read(struct hwrng *rng, void *buf, size_t max, static int pic32_rng_probe(struct platform_device *pdev) { struct pic32_rng *priv; + struct clk *clk; u32 v; int ret; @@ -81,13 +81,9 @@ static int pic32_rng_probe(struct platform_device *pdev) if (IS_ERR(priv->base)) return PTR_ERR(priv->base); - priv->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(priv->clk)) - return PTR_ERR(priv->clk); - - ret = clk_prepare_enable(priv->clk); - if (ret) - return ret; + clk = devm_clk_get_enabled(&pdev->dev, NULL); + if (IS_ERR(clk)) + return PTR_ERR(clk); /* enable TRNG in enhanced mode */ v = TRNGEN | TRNGMOD; @@ -98,15 +94,11 @@ static int pic32_rng_probe(struct platform_device *pdev) ret = devm_hwrng_register(&pdev->dev, &priv->rng); if (ret) - goto err_register; + return ret; platform_set_drvdata(pdev, priv); return 0; - -err_register: - clk_disable_unprepare(priv->clk); - return ret; } static int pic32_rng_remove(struct platform_device *pdev) @@ -114,7 +106,6 @@ static int pic32_rng_remove(struct platform_device *pdev) struct pic32_rng *rng = platform_get_drvdata(pdev); writel(0, rng->base + RNGCON); - clk_disable_unprepare(rng->clk); return 0; } From patchwork Tue Jul 4 17:32:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 115875 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp1379056vqx; Tue, 4 Jul 2023 10:52:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6104ckdWxhO4HakZx3SZEMjeVYvDnC0Q4Eiwdi9eHsjDQZ6ADvNWBt7hySFdnSom1kMenh X-Received: by 2002:a05:6a20:4ca0:b0:115:a2f4:6284 with SMTP id fq32-20020a056a204ca000b00115a2f46284mr10717249pzb.16.1688493162786; Tue, 04 Jul 2023 10:52:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688493162; cv=none; d=google.com; s=arc-20160816; b=sL4XkyTsle/MRFv0jYZVvZf55V2BGYWQzReT/HTjvUKY/z8rSDtWqq5c+exu/Ki34B LemwP3jKxnIry4zLBsi/OsIo31bJRIBynPlSfkRhmGLv+VhtToI23BS/ZlzHDuOcuYuY PmJvjncj9JNBGB53kPKP2X5EaFomqMcUmip707jhMXznPIfOZC4XTndJtU7dX3v38ZEP Anex7wUnLgHAfJKC07UWmErV7ldEApnNDcepxHccXbzqlVOnLqbw5P08LYJL4gw1NB8W aQL0VrbvY7YrJlL/9OGRpy7sVn6dWPYgC1hrpfRimdS/WsjFo36qP+9fZgB7EflS3fxg wCZw== 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; bh=H/cf/sp15qlImwkGLw1T/iqtr/YAZNSZRwX4x9CCJWs=; fh=lO4wmMQhvm8y/jaHDv9dt1CS5yb5ZTFKyt5xlt/d/d8=; b=GwIrmaS9fb3r3NFFAhRcgRGae5f+JYNAuDJeki50LI0q/7yrdZiwFqjg5fgg2Doyg9 KHw4zEanOyEnmOhMDBI5X8batBYOV9aL+O8334wwjRx/eYWCv/aEgFdEnpGNsCE+FyCm UbsO33dA9MkAIzCc6qpBGvirRHrqsh5rrHvAioq4zpEdBYaDov0yXCxd0m36TQwu1fZI Gk4fL6GR0T/rZOSVsunTxrrFAoLRvxErDdAME8AArtYYqEebuLjuh3x8NSN99ZzCdCaG vyJhkfimzP9OcwCTye4+BCf9zsNcNUtYXKmQ3+YRmGL+Py7tjX7dLp2jY0VznNpNWsrs cgJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d128-20020a633686000000b0055bc21ceb5asi2640285pga.548.2023.07.04.10.52.27; Tue, 04 Jul 2023 10:52:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231733AbjGDRd7 (ORCPT + 99 others); Tue, 4 Jul 2023 13:33:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231658AbjGDRdx (ORCPT ); Tue, 4 Jul 2023 13:33:53 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F4C710D9; Tue, 4 Jul 2023 10:33:52 -0700 (PDT) Received: from ipservice-092-217-072-126.092.217.pools.vodafone-ip.de ([92.217.72.126] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1qGjuP-0000yT-52; Tue, 04 Jul 2023 19:33:49 +0200 From: Martin Kaiser To: Herbert Xu Cc: Joshua Henderson , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH 3/4] hwrng: pic32 - remove unused defines Date: Tue, 4 Jul 2023 19:32:02 +0200 Message-Id: <20230704173203.70706-4-martin@kaiser.cx> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230704173203.70706-1-martin@kaiser.cx> References: <20230704173203.70706-1-martin@kaiser.cx> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770513406666436370?= X-GMAIL-MSGID: =?utf-8?q?1770513406666436370?= Remove some unused defines and fix the indentation. Signed-off-by: Martin Kaiser --- drivers/char/hw_random/pic32-rng.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/char/hw_random/pic32-rng.c b/drivers/char/hw_random/pic32-rng.c index e04a054e8930..c1b3f5915f03 100644 --- a/drivers/char/hw_random/pic32-rng.c +++ b/drivers/char/hw_random/pic32-rng.c @@ -19,19 +19,12 @@ #include #define RNGCON 0x04 -#define TRNGEN BIT(8) -#define PRNGEN BIT(9) -#define PRNGCONT BIT(10) -#define TRNGMOD BIT(11) -#define SEEDLOAD BIT(12) -#define RNGPOLY1 0x08 -#define RNGPOLY2 0x0C -#define RNGNUMGEN1 0x10 -#define RNGNUMGEN2 0x14 +#define TRNGEN BIT(8) +#define TRNGMOD BIT(11) #define RNGSEED1 0x18 #define RNGSEED2 0x1C #define RNGRCNT 0x20 -#define RCNT_MASK 0x7F +#define RCNT_MASK 0x7F struct pic32_rng { void __iomem *base; From patchwork Tue Jul 4 17:32:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kaiser X-Patchwork-Id: 115878 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp1379809vqx; Tue, 4 Jul 2023 10:54:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Wb0w2t8Hp4PoRyEhrGdXcFMwgFNbwyaEF8PIC0o2JqpAD9YyLau2E7gFssKY9m2gFWKcB X-Received: by 2002:a05:6808:2214:b0:3a2:a96d:19c3 with SMTP id bd20-20020a056808221400b003a2a96d19c3mr21273306oib.41.1688493286422; Tue, 04 Jul 2023 10:54:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688493286; cv=none; d=google.com; s=arc-20160816; b=Mh48vNF9Ock+Qjuo4fh8s9RMICII0jFKeMobg2/HVishihHnKzrlFs1REUMM+zQGjO tswnU0DX7vbC13svQ6YEYil6+2F15Pymd3QCycUwsf1R8n8v28hov2KOxWuk0PCyBHl4 EU7qxzDbOl9Zv07br+2NWyJLThclAqxwrDV2pdxO3EkXp5C8YfIou1R3f7hoGf9BSWA9 61CHVVkqbK+KY6xU4/k44vTE+wIphee1etSp7SVva3a4bXqGu7HaAlQdjE9nohGrKLJe 9bnk9lZZdvBkq0uXsXe0HU1tbaW7kmQCwLoFUv1Niva1S/HIPAJufViqUxB7VKujZWck 6v2A== 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; bh=L0mlBbI5UB7EJYxVbUVi/DPMd4wx2nWfxdmLFKK5fP4=; fh=lO4wmMQhvm8y/jaHDv9dt1CS5yb5ZTFKyt5xlt/d/d8=; b=UP6QrQoL4rzadh7FV8yyO1mWaAd6Ho2865PymTCmTyVC/Qk56TaE+KjmpUxQN46pez 0DJ/AqhbpXaZsb+eNLIY7QQaswk8wWqS2FccM2fM9c3Xa2MJrczulrOdiqodTy/F0NHI YCfREvPx5QVc9TG0qF0hoiZh7DqZC9Fg7R3NRM1i6V+4KG3nbV6j2GlYfwqd0AlJCIQ2 oSOphliXc01s6G35OgnKz92I4X5ewq7rkb8XBhCYil2e8nM1jZrIPEnSb0jt4LkgK1JY l1NW7ckY5PpvOzXRAm0mtIzWeJVa7UU9rTH+WtPsq1cbQrOTmyvwlIcrZkL3em9GJn07 exeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o14-20020a635d4e000000b0053ff2ca1b24si21232316pgm.843.2023.07.04.10.54.31; Tue, 04 Jul 2023 10:54:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231739AbjGDReB (ORCPT + 99 others); Tue, 4 Jul 2023 13:34:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231455AbjGDRdy (ORCPT ); Tue, 4 Jul 2023 13:33:54 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9C94DA; Tue, 4 Jul 2023 10:33:52 -0700 (PDT) Received: from ipservice-092-217-072-126.092.217.pools.vodafone-ip.de ([92.217.72.126] helo=martin-debian-2.paytec.ch) by viti.kaiser.cx with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1qGjuP-0000yT-Uj; Tue, 04 Jul 2023 19:33:50 +0200 From: Martin Kaiser To: Herbert Xu Cc: Joshua Henderson , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Kaiser Subject: [PATCH 4/4] hwrng: pic32 - enable TRNG only while it's used Date: Tue, 4 Jul 2023 19:32:03 +0200 Message-Id: <20230704173203.70706-5-martin@kaiser.cx> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230704173203.70706-1-martin@kaiser.cx> References: <20230704173203.70706-1-martin@kaiser.cx> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770513536146635285?= X-GMAIL-MSGID: =?utf-8?q?1770513536146635285?= The probe function enables the TRNG hardware before registering the driver. If registration fails, probe returns an error, but the TRNG remains enabled. Define init and cleanup functions, enable and disable the hardware there. Signed-off-by: Martin Kaiser --- drivers/char/hw_random/pic32-rng.c | 41 ++++++++++++++---------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/drivers/char/hw_random/pic32-rng.c b/drivers/char/hw_random/pic32-rng.c index c1b3f5915f03..1902f4389a3f 100644 --- a/drivers/char/hw_random/pic32-rng.c +++ b/drivers/char/hw_random/pic32-rng.c @@ -38,6 +38,15 @@ struct pic32_rng { */ #define RNG_TIMEOUT 500 +static int pic32_rng_init(struct hwrng *rng) +{ + struct pic32_rng *priv = container_of(rng, struct pic32_rng, rng); + + /* enable TRNG in enhanced mode */ + writel(TRNGEN | TRNGMOD, priv->base + RNGCON); + return 0; +} + static int pic32_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) { @@ -59,12 +68,17 @@ static int pic32_rng_read(struct hwrng *rng, void *buf, size_t max, return -EIO; } +static void pic32_rng_cleanup(struct hwrng *rng) +{ + struct pic32_rng *priv = container_of(rng, struct pic32_rng, rng); + + writel(0, priv->base + RNGCON); +} + static int pic32_rng_probe(struct platform_device *pdev) { struct pic32_rng *priv; struct clk *clk; - u32 v; - int ret; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -78,28 +92,12 @@ static int pic32_rng_probe(struct platform_device *pdev) if (IS_ERR(clk)) return PTR_ERR(clk); - /* enable TRNG in enhanced mode */ - v = TRNGEN | TRNGMOD; - writel(v, priv->base + RNGCON); - priv->rng.name = pdev->name; + priv->rng.init = pic32_rng_init; priv->rng.read = pic32_rng_read; + priv->rng.cleanup = pic32_rng_cleanup; - ret = devm_hwrng_register(&pdev->dev, &priv->rng); - if (ret) - return ret; - - platform_set_drvdata(pdev, priv); - - return 0; -} - -static int pic32_rng_remove(struct platform_device *pdev) -{ - struct pic32_rng *rng = platform_get_drvdata(pdev); - - writel(0, rng->base + RNGCON); - return 0; + return devm_hwrng_register(&pdev->dev, &priv->rng); } static const struct of_device_id pic32_rng_of_match[] __maybe_unused = { @@ -110,7 +108,6 @@ MODULE_DEVICE_TABLE(of, pic32_rng_of_match); static struct platform_driver pic32_rng_driver = { .probe = pic32_rng_probe, - .remove = pic32_rng_remove, .driver = { .name = "pic32-rng", .of_match_table = of_match_ptr(pic32_rng_of_match),