From patchwork Wed Feb 24 08:22:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Rojas?= X-Patchwork-Id: 12101495 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D615CC433E0 for ; Wed, 24 Feb 2021 08:24:20 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6BF9C64ED3 for ; Wed, 24 Feb 2021 08:24:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6BF9C64ED3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe :List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1g9N1TtyujGr3zFBKCsLgOwRbfXwe00DllsaXYp9jkA=; b=kqcf6A6voYGBKD1DeCZoP2HaVs 2UNL8Eug2+oVC/RZvamlweubK+yjkKzm5ANclq5xHIu8/qSYgRiMvvJ95JVrI8MfUIyosmRLKSzc6 TYlRe356ZL/r9tSgSfu7V4PDR5ibYB8BxxEQQ9Rxl8QQqsykYHAJ45qVCmzK7E8Pzh6pF17cLkRpp Omw0iR3u5BB/od+4++Ltae+qQGyix3IL0CaUkzRiw5DD4ldxxLEgsqrMHZmsZw2I4P1LcYMwzc7xo ErCoXZ070dq7wvBfit/pFnZ8u0CRAWa3bXpeg3eEZ/dGstS0om9IntVbye472B/hpor8tdJ6ccI1D xu3o3gbQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lEpRb-0004Et-Gn; Wed, 24 Feb 2021 08:22:51 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lEpRQ-0004DC-RU; Wed, 24 Feb 2021 08:22:42 +0000 Received: by mail-wr1-x434.google.com with SMTP id t15so960913wrx.13; Wed, 24 Feb 2021 00:22:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=BAE1Kf2xIrmHE4CG7BguHd5TjWIGOPY8aBCToqo40i8=; b=ON9GDxXWl4h3rVmqaA5nrpo6rfrokVBk8WnqQJNPuEJChQJMKxHMfMkDO/IPttlRmo CG/KT7FuD0UYCnJMpvrUsAF8aozpxxuI23sH68noZOIHEk/hBeAsY32hfNtnkblkiIKL cvzlrmMBFYpmqWK0nTnJiAy8gyWL59EhlJ/Jp/M0GMtMxEHV0+vDuUbEXPnzcFVe7UNo el6+0Ifm2SWXhDhaqNOMmtm1mMp06Gf58D06eXh8nYdF0+0IFKMm6XAIEHpz1NvfbNkz wQGmdQeW8dGnR/ON+XFCWVn3A46cCQ7y3/bRjqlAJh1uJ2NrtfHdZaOFsaM6WiqRR70V dSLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BAE1Kf2xIrmHE4CG7BguHd5TjWIGOPY8aBCToqo40i8=; b=m+5IpZcyBkza9xmdOE85Vcgr5j+5RYbYnmmT3aXswah6FPRtCA6LcDuPmOAJ8tKmm6 PctVhZicYG6z6L5NWGTu/j0nPk3VpbIjp7gd1Ooau/NEkvWBQUVcT5SJQm3zbnTh6u31 ATZzWr7LIbRO8dmmFKuGTpoCUzsYLbsbnw4tkK5tIXNLdS9Ava4xuvYNJLVQII837mmJ HxJUmlivIdHBeZag6u3E64d2TqTX9I6kHBEsVL1AyokDxEqR6zxOHCkxsQ5tBAvgOimq WfDEbqdyjwpUWMw9LNWSU24iCxeuE1t3q+XQwCWUr9ILD5AcdiUtM+LNo+d8LPjyks1k b7yg== X-Gm-Message-State: AOAM531hOYFsWSbFTOFGw9jKltYVZHQ/mTD5kPGd0fz8+WhGwINV17uU B15dtFpQ9rWGgeYRqnTHZl8= X-Google-Smtp-Source: ABdhPJxch8/aZDZYHTx5t2OcR8JeSykfALOIoALHNOtek/GvbLq3PLOnVPo32xcrsVXe9UlVxg9OcQ== X-Received: by 2002:adf:d0c5:: with SMTP id z5mr8562622wrh.289.1614154959564; Wed, 24 Feb 2021 00:22:39 -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 u19sm1501628wmm.46.2021.02.24.00.22.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Feb 2021 00:22:39 -0800 (PST) From: =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Rojas?= To: Matt Mackall , Herbert Xu , Rob Herring , Nicolas Saenz Julienne , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Philipp Zabel , Mark Brown , =?utf-8?q?=C3=81lvaro_Fern=C3=A1ndez_Rojas?= , Guenter Roeck , Bjorn Andersson , =?utf-8?b?TsOtY29sYXMgRi4g?= =?utf-8?b?Ui4gQS4gUHJhZG8=?= , 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 Subject: [PATCH v4 2/2] hwrng: bcm2835: add reset support Date: Wed, 24 Feb 2021 09:22:30 +0100 Message-Id: <20210224082230.29015-3-noltari@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210224082230.29015-1-noltari@gmail.com> References: <20210223160131.29053-1-noltari@gmail.com> <20210224082230.29015-1-noltari@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210224_032241_281242_ED1BFB4E X-CRM114-Status: GOOD ( 16.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 Signed-off-by: Álvaro Fernández Rojas --- v4: add reset_control_rearm(). v3: no changes. v2: no changes. drivers/char/hw_random/bcm2835-rng.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 1a7c43b43c6b..92658edaff22 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) @@ -94,6 +96,10 @@ static int bcm2835_rng_init(struct hwrng *rng) 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); @@ -115,6 +121,8 @@ static void bcm2835_rng_cleanup(struct hwrng *rng) /* disable rng hardware */ rng_writel(priv, 0, RNG_CTRL); + reset_control_rearm(priv->reset); + if (!IS_ERR(priv->clk)) clk_disable_unprepare(priv->clk); } @@ -159,6 +167,10 @@ static int bcm2835_rng_probe(struct platform_device *pdev) if (PTR_ERR(priv->clk) == -EPROBE_DEFER) return -EPROBE_DEFER; + 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;