Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1264863pxb; Thu, 4 Mar 2021 07:20:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMAuloCB9kcUUcMIloHjL46phinwnyns41+DolmdZjtGjHavmJd0WxjsbFAUi/Gt/bih3l X-Received: by 2002:aa7:c550:: with SMTP id s16mr4946035edr.98.1614871248459; Thu, 04 Mar 2021 07:20:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614871248; cv=none; d=google.com; s=arc-20160816; b=upKzS2ncJ0dr4bpbo3dTkOIbs0tcg9FGzGXVwktF63b4qiNU/M1UbL536tllxcJTfg gaXr8UyjaV11LN99uwDDLikdce5QMH8QP01xw2/OuXO2NBYeopWlEq1hNXsbolX0b9WU Y6vTAVl00EnkjkokTqasJOwWsws/kBWiy/9fao91ldJe7fO9HMMECWiR+WVrhEl00VJ/ cxRJ0MGYiVIQGomVJ1rBn3khrJGy2sCz2NSYs15iMGdPrLCouQHBvaOEI8xdpJA2XOUp beEyzcBM+jrJb3IHy7iCZZiPFY56W+yyOPNnQVapPHepwE8ZtA+q/St6x79J8k+TzX5r qvWA== 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=nKsLCh+6twuWj2QnD4IJjKFGoE1CDwaYbrWfJko6FQg=; b=pkN/1YRC9m/jjhzJ9s8lp7uOzyF+zFTDVJEG9o+BslaoU3GSsmxvvEtb1LnpArMZUN klpWbcT9xkhI6CPO5Mzx7SpylJVRsYOorjC7GJud93HbjJrMHwiEULu08dojItbfHCw8 qMYg3lkz9oSWF4qIY/RiuF4i1KlhQoqGUQ6qYoLOykjV0j/SJCKi8HCkptpZtQ+Z3Thh iSQv2F9YAgiKyeiv087k5Cmid5Iu31VAzPAXkymhCZoZioxAHm82L7BrvQ8qPMWxwClw 8KuiY4pS2e40QDQgFvoOejk94wybrEriUDr9PfzlltVBYdDtyGjTS28PWirfzVEOEEF5 twgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PM7DH0DC; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d23si16395228eje.107.2021.03.04.07.20.25; Thu, 04 Mar 2021 07:20:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PM7DH0DC; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231781AbhCDHeX (ORCPT + 99 others); Thu, 4 Mar 2021 02:34:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231636AbhCDHdy (ORCPT ); Thu, 4 Mar 2021 02:33:54 -0500 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 47AC9C06175F; Wed, 3 Mar 2021 23:33:14 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id v15so26485454wrx.4; Wed, 03 Mar 2021 23:33:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nKsLCh+6twuWj2QnD4IJjKFGoE1CDwaYbrWfJko6FQg=; b=PM7DH0DCgsIy5KSnYy4NPGqpPLALl4pHepSUZZp+7gOWJK/nz8Cz3HaJfTuSI0XoDj 7W6ocLN/+Ck53cPaHif72uqdFR8IiKtjfe8ZzgHHNZ1zEw+4iNtm+im5JY0byoAfaanA yTZSJK/DA5FsOdDzB0svKlw5k5Y4rfUPR46dUY89crhuOIdq9vSRSKke3o1tazJSV1sv kP6vDEogVfnhL8SMMwesYUuAv8T1j3EyIJRwWqsT6RYdQ63KyXMi7maXcIhXTrxD7dh9 D9UElGzyGEqZ8eEciUuFBUautAbwuNulbr2Vh8bZVL1wnWpXLZqxoOUSwcGOJoDZ1I81 By0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nKsLCh+6twuWj2QnD4IJjKFGoE1CDwaYbrWfJko6FQg=; b=rjPhipiA2RT73TihznkBWeSgsMLkdS6TTGYRPt1JrSUdqQqwQDNsc6gWFhpZQVvoui flDo+YbG/6RcU6A9yjhgdfJC2zUBa2bhB5hd1qMcCWV4564oWG27vmw1QXbYeq0FN1UE kFWRFvqbwhfjCwCdCJaZs74BkezTuyuwktWKyRPenyJ0UDuhAL8G0EqKJ41USiiGRgoU cmynDfRhYIFKawGBH1rJpdBrFM1GPz8zBuiMfJU7pt4LgCMpPTOCVdC8+6l9SzyWOwV0 s818y0SpzhFtnNgmQpv4KEUEu0t4UHR4751yrz3+PbtuEExBJ0U8gBkVR2XFgSuS2v2O nZ9Q== X-Gm-Message-State: AOAM530394qZCV8BoQe9/uVOnTaL6ePiK9dcS6mPtw5EtQipooBcMx0m plvVmOglPe/aoKrQFsFhXdo= X-Received: by 2002:a5d:5051:: with SMTP id h17mr2538503wrt.80.1614843193036; Wed, 03 Mar 2021 23:33:13 -0800 (PST) Received: from skynet.lan (170.red-88-1-105.dynamicip.rima-tde.net. [88.1.105.170]) by smtp.gmail.com with ESMTPSA id j30sm18328811wrj.62.2021.03.03.23.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Mar 2021 23:33:12 -0800 (PST) From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= To: Matt Mackall , Herbert Xu , Rob Herring , Nicolas Saenz Julienne , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Philipp Zabel , Neil Armstrong , Alexandru Ardelean , Bjorn Andersson , Guenter Roeck , Rikard Falkeborn , Stefan Wahren , linux-crypto@vger.kernel.org, devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Subject: [PATCH v5 2/2] hwrng: bcm2835: add reset support Date: Thu, 4 Mar 2021 08:33:08 +0100 Message-Id: <20210304073308.25906-3-noltari@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210304073308.25906-1-noltari@gmail.com> References: <20210304073308.25906-1-noltari@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org BCM6368 devices need to reset the in order to generate true random numbers. This is what BCM6368 produces without a reset: root@OpenWrt:/# cat /dev/hwrng | rngtest -c 1000 rngtest 6.10 Copyright (c) 2004 by Henrique de Moraes Holschuh This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. rngtest: starting FIPS tests... rngtest: bits received from input: 20000032 rngtest: FIPS 140-2 successes: 0 rngtest: FIPS 140-2 failures: 1000 rngtest: FIPS 140-2(2001-10-10) Monobit: 2 rngtest: FIPS 140-2(2001-10-10) Poker: 1000 rngtest: FIPS 140-2(2001-10-10) Runs: 1000 rngtest: FIPS 140-2(2001-10-10) Long run: 30 rngtest: FIPS 140-2(2001-10-10) Continuous run: 0 rngtest: input channel speed: (min=37.253; avg=320.827; max=635.783)Mibits/s rngtest: FIPS tests speed: (min=12.141; avg=15.034; max=16.428)Mibits/s rngtest: Program run time: 1336176 microseconds cat: write error: Broken pipe Signed-off-by: Álvaro Fernández Rojas --- v5: remove reset_control_rearm(). v4: add reset_control_rearm(). v3: no changes. v2: no changes. drivers/char/hw_random/bcm2835-rng.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index be5be395b341..e7dd457e9b22 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -13,6 +13,7 @@ #include #include #include +#include #define RNG_CTRL 0x0 #define RNG_STATUS 0x4 @@ -32,6 +33,7 @@ struct bcm2835_rng_priv { void __iomem *base; bool mask_interrupts; struct clk *clk; + struct reset_control *reset; }; static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) @@ -92,6 +94,10 @@ static int bcm2835_rng_init(struct hwrng *rng) if (ret) return ret; + ret = reset_control_reset(priv->reset); + if (ret) + return ret; + if (priv->mask_interrupts) { /* mask the interrupt */ val = rng_readl(priv, RNG_INT_MASK); @@ -156,6 +162,10 @@ static int bcm2835_rng_probe(struct platform_device *pdev) if (IS_ERR(priv->clk)) return PTR_ERR(priv->clk); + priv->reset = devm_reset_control_get_optional_exclusive(dev, NULL); + if (IS_ERR(priv->reset)) + return PTR_ERR(priv->reset); + priv->rng.name = pdev->name; priv->rng.init = bcm2835_rng_init; priv->rng.read = bcm2835_rng_read; -- 2.20.1