linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Kaiser <martin@kaiser.cx>
To: Herbert Xu <herbert@gondor.apana.org.au>,
	PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>,
	NXP Linux Team <linux-imx@nxp.com>
Cc: linux-crypto@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Martin Kaiser <martin@kaiser.cx>
Subject: [PATCH 5/6] hwrng: imx-rngc - check the rng type
Date: Tue, 28 Jan 2020 12:01:01 +0100	[thread overview]
Message-ID: <20200128110102.11522-6-martin@kaiser.cx> (raw)
In-Reply-To: <20200128110102.11522-1-martin@kaiser.cx>

Read the rng type and hardware revision during probe. Fail the probe
operation if the type is not one of rngc or rngb.
(There's also an rnga type, which needs a different driver.)

Display the type and revision in a debug print if probe was successful.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/char/hw_random/imx-rngc.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c
index 8222055b9e9b..27d85fced30b 100644
--- a/drivers/char/hw_random/imx-rngc.c
+++ b/drivers/char/hw_random/imx-rngc.c
@@ -18,12 +18,22 @@
 #include <linux/completion.h>
 #include <linux/io.h>
 
+#define RNGC_VER_ID			0x0000
 #define RNGC_COMMAND			0x0004
 #define RNGC_CONTROL			0x0008
 #define RNGC_STATUS			0x000C
 #define RNGC_ERROR			0x0010
 #define RNGC_FIFO			0x0014
 
+/* the fields in the ver id register */
+#define RNGC_TYPE_SHIFT		28
+#define RNGC_VER_MAJ_SHIFT		8
+
+/* the rng_type field */
+#define RNGC_TYPE_RNGB			0x1
+#define RNGC_TYPE_RNGC			0x2
+
+
 #define RNGC_CMD_CLR_ERR		0x00000020
 #define RNGC_CMD_CLR_INT		0x00000010
 #define RNGC_CMD_SEED			0x00000002
@@ -212,6 +222,8 @@ static int imx_rngc_probe(struct platform_device *pdev)
 	struct imx_rngc *rngc;
 	int ret;
 	int irq;
+	u32 ver_id;
+	u8  rng_type;
 
 	rngc = devm_kzalloc(&pdev->dev, sizeof(*rngc), GFP_KERNEL);
 	if (!rngc)
@@ -237,6 +249,17 @@ static int imx_rngc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	ver_id = readl(rngc->base + RNGC_VER_ID);
+	rng_type = ver_id >> RNGC_TYPE_SHIFT;
+	/*
+	 * This driver supports only RNGC and RNGB. (There's a different
+	 * driver for RNGA.)
+	 */
+	if (rng_type != RNGC_TYPE_RNGC && rng_type != RNGC_TYPE_RNGB) {
+		ret = -ENODEV;
+		goto err;
+	}
+
 	ret = devm_request_irq(&pdev->dev,
 			irq, imx_rngc_irq, 0, pdev->name, (void *)rngc);
 	if (ret) {
@@ -269,7 +292,10 @@ static int imx_rngc_probe(struct platform_device *pdev)
 		goto err;
 	}
 
-	dev_info(&pdev->dev, "Freescale RNGC registered.\n");
+	dev_info(&pdev->dev,
+		"Freescale RNG%c registered (HW revision %d.%02d)\n",
+		rng_type == RNGC_TYPE_RNGB ? 'B' : 'C',
+		(ver_id >> RNGC_VER_MAJ_SHIFT) & 0xff, ver_id & 0xff);
 	return 0;
 
 err:
-- 
2.20.1


  parent reply	other threads:[~2020-01-28 11:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-28 11:00 [PATCH 0/6] imx-rngc - several small fixes Martin Kaiser
2020-01-28 11:00 ` [PATCH 1/6] hwrng: imx-rngc - fix an error path Martin Kaiser
2020-02-12 16:22   ` PrasannaKumar Muralidharan
2020-01-28 11:00 ` [PATCH 2/6] hwrng: imx-rngc - use automatic seeding Martin Kaiser
2020-02-12 16:24   ` PrasannaKumar Muralidharan
2020-01-28 11:00 ` [PATCH 3/6] hwrng: imx-rngc - use devres for registration Martin Kaiser
2020-02-12 16:13   ` PrasannaKumar Muralidharan
2020-02-17  9:35     ` Martin Kaiser
2020-01-28 11:01 ` [PATCH 4/6] hwrng: imx-rngc - (trivial) simplify error prints Martin Kaiser
2020-02-12 16:24   ` PrasannaKumar Muralidharan
2020-01-28 11:01 ` Martin Kaiser [this message]
2020-02-12 16:23   ` [PATCH 5/6] hwrng: imx-rngc - check the rng type PrasannaKumar Muralidharan
2020-01-28 11:01 ` [PATCH 6/6] hwrng: imx-rngc - simplify interrupt mask/unmask Martin Kaiser
2020-03-05 20:58 ` [PATCH v2 0/5] imx-rngc - several small fixes Martin Kaiser
2020-03-05 20:58   ` [PATCH v2 1/5] hwrng: imx-rngc - fix an error path Martin Kaiser
2020-03-05 20:58   ` [PATCH v2 2/5] hwrng: imx-rngc - use automatic seeding Martin Kaiser
2020-03-05 20:58   ` [PATCH v2 3/5] hwrng: imx-rngc - (trivial) simplify error prints Martin Kaiser
2020-03-05 20:58   ` [PATCH v2 4/5] hwrng: imx-rngc - check the rng type Martin Kaiser
2020-03-05 20:58   ` [PATCH v2 5/5] hwrng: imx-rngc - simplify interrupt mask/unmask Martin Kaiser
2020-03-12 12:39   ` [PATCH v2 0/5] imx-rngc - several small fixes Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200128110102.11522-6-martin@kaiser.cx \
    --to=martin@kaiser.cx \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=prasannatsmkumar@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).